<template>
  <button 
    class="icon-btn" 
    :class="[`icon-btn--${variant}`, { 'icon-btn--small': small }]"
    :title="title"
    :disabled="disabled"
    @click="$emit('click', $event)"
  >
    <span v-if="loading" class="icon-btn-loader"></span>
    <i v-else :data-lucide="icon"></i>
    <span v-if="label" class="icon-btn-label">{{ label }}</span>
  </button>
</template>

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

useLucideIcons()

defineProps({
  icon: {
    type: String,
    required: true
  },
  title: {
    type: String,
    default: ''
  },
  label: {
    type: String,
    default: ''
  },
  variant: {
    type: String,
    default: 'default',
    validator: (v) => ['default', 'danger', 'warning', 'primary', 'ghost'].includes(v)
  },
  small: {
    type: Boolean,
    default: false
  },
  disabled: {
    type: Boolean,
    default: false
  },
  loading: {
    type: Boolean,
    default: false
  }
})

defineEmits(['click'])
</script>

<style scoped>
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 42px;
  height: 42px;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  font-size: 13px;
}

.icon-btn i {
  width: 18px;
  height: 18px;
}

.icon-btn-label {
  white-space: nowrap;
}

/* Если есть лейбл — растягиваем кнопку */
.icon-btn:has(.icon-btn-label) {
  width: auto;
  padding: 0 16px;
}

/* Small */
.icon-btn--small {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.icon-btn--small i {
  width: 14px;
  height: 14px;
}

.icon-btn--small:has(.icon-btn-label) {
  padding: 0 10px;
}

/* Variants */
.icon-btn--default {
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}

.icon-btn--default:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

.icon-btn--danger {
  border: 1px solid var(--red);
  color: var(--red);
}

.icon-btn--danger:hover {
  background: var(--red);
  color: #000;
}

.icon-btn--warning {
  border: 1px solid var(--orange);
  color: var(--orange);
}

.icon-btn--warning:hover {
  background: var(--orange);
  color: #000;
}

.icon-btn--primary {
  border: 1px solid var(--accent);
  color: var(--accent);
}

.icon-btn--primary:hover {
  background: var(--accent);
  color: #000;
}

.icon-btn--ghost {
  border: 1px solid transparent;
  color: var(--text-muted);
}

.icon-btn--ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

/* Disabled */
.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loader */
.icon-btn-loader {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
</style>
