<template>
  <button
    :class="[
      'btn-custom', 
      `btn-${variant}`, 
      `btn-${size}`,
      { 'is-loading': loading, 'is-disabled': disabled || loading }
    ]"
    :id="id"
    :style="buttonStyle"
    :disabled="disabled || loading"
    @click="$emit('click', $event)"
  >
    <div class="btn-content">
      <LoadingSpinner v-if="loading" size="sm" color="currentColor" class="me-2" />
      <slot>
        {{ text }}
      </slot>
    </div>
  </button>
</template>

<script setup>
import LoadingSpinner from '@/Components/LoadingSpinner.vue'

defineProps({
  text:        { type: String, default: '' },
  variant:     { type: String, default: 'primary', validator: (v) => ['primary', 'secondary', 'outline', 'danger', 'glass', 'text'].includes(v) },
  id:          { type: String, default: '' },
  buttonStyle: { type: String, default: '' },
  loading:     { type: Boolean, default: false },
  size:        { type: String, default: 'md', validator: (v) => ['sm', 'md', 'lg'].includes(v) },
  disabled:    { type: Boolean, default: false },
})

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

<style scoped>
.btn-custom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  border-radius: 12px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  gap: 0.5rem;
}

.btn-content {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* Sizes */
.btn-sm { padding: 0.5rem 1rem; font-size: 0.875rem; }
.btn-md { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-lg { padding: 1rem 2rem; font-size: 1.125rem; }

/* Variants */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-color, #4f46e5) 0%, #3730a3 100%);
  color: white;
  box-shadow: 0 4px 6px -1px var(--accent-soft, rgba(79, 70, 229, 0.4));
}
.btn-primary:hover:not(.is-disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px var(--accent-soft, rgba(79, 70, 229, 0.5));
}

.btn-secondary {
  background: var(--bg-tertiary, #f0f2f5);
  color: var(--text-primary, #1e1e1e);
}
:global(.dark-mode) .btn-secondary {
  background: var(--bg-tertiary, #2d3748);
  color: white;
}
.btn-secondary:hover:not(.is-disabled) {
  background: var(--border-color, #e2e8f0);
}
:global(.dark-mode) .btn-secondary:hover:not(.is-disabled) {
  background: #3d4a5d;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color, rgba(0, 0, 0, 0.1));
  color: var(--text-primary, #1e1e1e);
}
:global(.dark-mode) .btn-outline {
  border-color: rgba(255, 255, 255, 0.2);
  color: white;
}
.btn-outline:hover:not(.is-disabled) {
  background: var(--accent-soft, rgba(0, 0, 0, 0.05));
  border-color: var(--accent-color, rgba(0, 0, 0, 0.4));
}
:global(.dark-mode) .btn-outline:hover:not(.is-disabled) {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.4);
}

.btn-danger {
  background: #ef4444;
  color: white;
}
.btn-danger:hover:not(.is-disabled) {
  background: #dc2626;
}

.btn-glass {
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-primary, #1e1e1e);
}
:global(.dark-mode) .btn-glass {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
}
.btn-glass:hover:not(.is-disabled) {
  background: rgba(255, 255, 255, 0.5);
}
:global(.dark-mode) .btn-glass:hover:not(.is-disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.btn-text {
  background: transparent;
  color: var(--text-secondary, #717171);
}
.btn-text:hover:not(.is-disabled) {
  color: var(--text-primary, #1e1e1e);
}
:global(.dark-mode) .btn-text:hover:not(.is-disabled) {
  color: white;
}

/* States */
.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.is-loading {
  cursor: wait;
}

.btn-custom:active:not(.is-disabled) {
  transform: scale(0.98);
}
</style>
