<template>
  <div 
    class="notification-card" 
    :class="{ processing, [type]: true }"
  >
    <div class="notification-info">
      <!-- Аватар -->
      <div class="notification-avatar" :style="avatarStyle">
        <img v-if="avatarUrl" :src="avatarUrl" :alt="title">
        <span v-else class="avatar-initials">{{ avatarInitial }}</span>
      </div>
      
      <!-- Детали -->
      <div class="notification-details">
        <span class="notification-title">{{ title }}</span>
        <span v-if="subtitle" class="notification-subtitle">{{ subtitle }}</span>
      </div>
      
      <!-- Бейдж -->
      <span v-if="badge" class="notification-badge">{{ badge }}</span>
    </div>
    
    <!-- Действия -->
    <div v-if="showActions" class="notification-actions">
      <button 
        class="btn-action btn-decline" 
        @click="$emit('decline')"
        :disabled="processing"
        title="Отклонить"
      >
        <i data-lucide="x"></i>
      </button>
      <button 
        class="btn-action btn-accept" 
        @click="$emit('accept')"
        :disabled="processing"
        title="Принять"
      >
        <i data-lucide="check"></i>
      </button>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useLucideIcons } from '../../composables/useLucideIcons'

useLucideIcons()

const props = defineProps({
  // Основные данные
  title: {
    type: String,
    required: true
  },
  subtitle: {
    type: String,
    default: ''
  },
  badge: {
    type: String,
    default: ''
  },
  
  // Аватар
  avatarUrl: {
    type: String,
    default: ''
  },
  avatarName: {
    type: String,
    default: ''
  },
  avatarColor: {
    type: String,
    default: ''
  },
  
  // Тип уведомления (для стилизации)
  type: {
    type: String,
    default: 'default', // default, invite, warning, info
    validator: (v) => ['default', 'invite', 'warning', 'info'].includes(v)
  },
  
  // Состояние
  processing: {
    type: Boolean,
    default: false
  },
  showActions: {
    type: Boolean,
    default: true
  }
})

defineEmits(['accept', 'decline'])

// Первая буква для аватара
const avatarInitial = computed(() => {
  return (props.avatarName || props.title || '?')[0].toUpperCase()
})

// Стиль аватара
const avatarStyle = computed(() => {
  if (props.avatarColor) {
    return { background: props.avatarColor }
  }
  return {}
})
</script>

<style scoped>
.notification-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  transition: background 0.15s;
}

.notification-card:hover {
  background: rgba(255, 255, 255, 0.05);
}

.notification-card.processing {
  opacity: 0.5;
  pointer-events: none;
}

/* Инфо */
.notification-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

/* Аватар */
.notification-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--blue, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notification-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-initials {
  font-size: 14px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
}

/* Детали */
.notification-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.notification-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notification-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* Бейдж */
.notification-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 3px 6px;
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Действия */
.notification-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-action {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-action i {
  width: 16px;
  height: 16px;
}

.btn-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-decline {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.btn-decline:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.btn-accept {
  background: var(--accent);
  color: #000;
}

.btn-accept:hover:not(:disabled) {
  background: #00e6b8;
}

/* ========== ТИПЫ ========== */
/* Invite (зелёный акцент) */
.notification-card.invite .btn-accept {
  background: var(--accent);
}

/* Warning (оранжевый) */
.notification-card.warning .notification-badge {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

/* Info (синий) */
.notification-card.info .notification-badge {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}
</style>
