<script setup>
import Modal from '@Holos/Modal.vue';
import GoogleIcon from '@Shared/GoogleIcon.vue';

/** Props */
const props = defineProps({
    show: {
        type: Boolean,
        default: false
    },
    category: {
        type: Object,
        default: null
    }
});

/** Emits */
const emit = defineEmits(['close', 'confirm']);

/** Métodos */
const handleConfirm = () => {
    emit('confirm', props.category.id);
};

const handleClose = () => {
    emit('close');
};
</script>

<template>
    <Modal :show="show" max-width="md" @close="handleClose">
        <div class="p-6">
            <!-- Header -->
            <div class="flex items-center justify-between mb-6">
                <div class="flex items-center gap-3">
                    <div class="flex items-center justify-center w-12 h-12 rounded-full bg-red-100 dark:bg-red-900/30">
                        <GoogleIcon name="delete_forever" class="text-2xl text-red-600 dark:text-red-400" />
                    </div>
                    <h3 class="text-lg font-bold text-gray-900 dark:text-gray-100">
                        Eliminar Categoría
                    </h3>
                </div>
                <button
                    @click="handleClose"
                    class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"
                >
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                    </svg>
                </button>
            </div>

            <!-- Content -->
            <div class="space-y-5">
                <p class="text-gray-700 dark:text-gray-300 text-base">
                    ¿Estás seguro de que deseas eliminar esta categoría?
                </p>

                <div v-if="category" class="bg-linear-to-br from-gray-50 to-gray-100 dark:from-gray-800 dark:to-gray-900 border border-gray-200 dark:border-gray-700 rounded-xl p-5 space-y-2">
                    <div class="flex items-center gap-3">
                        <div class="flex items-center justify-center w-10 h-10 rounded-lg bg-indigo-100 dark:bg-indigo-900/30">
                            <GoogleIcon name="category" class="text-xl text-indigo-600 dark:text-indigo-400" />
                        </div>
                        <div class="flex-1">
                            <p class="text-base font-bold text-gray-900 dark:text-gray-100">
                                {{ category.name }}
                            </p>
                            <p v-if="category.description" class="text-sm text-gray-600 dark:text-gray-400 mt-0.5">
                                {{ category.description }}
                            </p>
                            <p v-else class="text-sm text-gray-500 dark:text-gray-500 italic mt-0.5">
                                Sin descripción
                            </p>
                        </div>
                        <div v-if="category.is_active !== undefined">
                            <span
                                class="inline-flex px-3 py-1 text-xs font-semibold rounded-full"
                                :class="{
                                    'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400': category.is_active,
                                    'bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400': !category.is_active
                                }"
                            >
                                {{ category.is_active ? 'Activo' : 'Inactivo' }}
                            </span>
                        </div>
                    </div>
                </div>

                <div class="flex items-start gap-2 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4">
                    <GoogleIcon name="info" class="text-red-600 dark:text-red-400 text-xl shrink-0 mt-0.5" />
                    <p class="text-sm text-red-800 dark:text-red-300 font-medium">
                        Esta acción es permanente y no se puede deshacer. Los productos asociados a esta categoría perderán su categorización.
                    </p>
                </div>
            </div>

            <!-- Footer -->
            <div class="flex items-center justify-end gap-3 mt-8 pt-6 border-t border-gray-200 dark:border-gray-700">
                <button
                    type="button"
                    @click="handleClose"
                    class="px-5 py-2.5 text-sm font-semibold text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 transition-colors"
                >
                    Cancelar
                </button>
                <button
                    type="button"
                    @click="handleConfirm"
                    class="flex items-center gap-2 px-5 py-2.5 bg-red-600 hover:bg-red-700 text-white text-sm font-semibold rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-600 shadow-lg shadow-red-600/30 transition-all"
                >
                    <GoogleIcon name="delete" class="text-xl" />
                    Eliminar Categoría
                </button>
            </div>
        </div>
    </Modal>
</template>
