<template>
    <div class="confirm-modal-overlay" :class="{ 'is-open': isOpen }" @click.self="cancel">
        <div class="confirm-modal-card" :class="{ 'is-open': isOpen, 'is-destructive': isDestructive, 'is-confirm-hovered': isConfirmHovered }">
            <!-- Top Close Icon Button (Micro-interaction) -->
            <button class="confirm-modal-close-btn" @click="cancel" aria-label="Close">
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
                </svg>
            </button>

            <div class="confirm-modal-body">
                <!-- Icon container with glowing gradient and drop-shadow -->
                <div class="confirm-icon-wrapper" :class="isDestructive ? 'is-danger' : 'is-info'">
                    <div class="confirm-icon-glow"></div>
                    <div class="confirm-icon-circle">
                        <!-- Custom animated SVG trash can -->
                        <svg v-if="isDestructive" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="currentColor" class="icon-svg trash-icon">
                            <!-- Trash Lid Group -->
                            <g class="trash-lid-group">
                                <path d="M 28 3 C 25.791 3 24 4.791 24 7 L 24 9 L 23.599609 9 L 7 11 L 7 14 L 57 14 L 57 11 L 40.400391 9 L 40 9 L 40 7 C 40 4.791 38.209 3 36 3 L 28 3 z M 28 7 L 36 7 L 36 9 L 28 9 L 28 7 z" />
                            </g>
                            <!-- Trash Body -->
                            <path class="trash-body" d="M 10 16 L 14 58 L 50 58 L 53.923828 17 L 10 16 z M 32 23 C 33.333 23 34 24 34 24 L 34 53 L 30 53 L 30 24 C 30 24 30.667 23 32 23 z M 18.976562 23.070312 C 20.306563 22.977313 21.042969 23.929688 21.042969 23.929688 L 23.007812 53 L 18.996094 53 L 17.052734 24.207031 C 17.052734 24.207031 17.646563 23.163313 18.976562 23.070312 z M 44.978516 23.070312 C 46.308516 23.163312 46.904297 24.207031 46.904297 24.207031 L 44.960938 53 L 40.949219 53 L 42.914062 23.929688 C 42.914062 23.929688 43.648516 22.977312 44.978516 23.070312 z" />
                        </svg>
                        <svg v-else xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="icon-svg">
                            <path stroke-linecap="round" stroke-linejoin="round" d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9 5.25h.008v.008H12v-.008z" />
                        </svg>
                    </div>
                </div>

                <!-- Text Header & Content -->
                <div class="confirm-text-container">
                    <h3 class="confirm-modal-title">{{ title }}</h3>
                    <p class="confirm-modal-message">{{ message }}</p>
                </div>
            </div>

            <!-- Action buttons with custom styles and animations -->
            <div class="confirm-modal-footer">
                <button class="confirm-btn confirm-btn-secondary" @click="cancel">Cancel</button>
                <button 
                    class="confirm-btn" 
                    :class="isDestructive ? 'confirm-btn-danger' : 'confirm-btn-primary'" 
                    @click="confirm"
                    @mouseenter="isConfirmHovered = true"
                    @mouseleave="isConfirmHovered = false"
                >
                    {{ confirmText }}
                </button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        message: {
            type: String,
            required: true
        },
        title: {
            type: String,
            default: 'Confirm Action'
        },
        confirmText: {
            type: String,
            default: 'Confirm'
        },
        isDestructive: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            isOpen: false,
            isConfirmHovered: false
        };
    },
    mounted() {
        setTimeout(() => {
            this.isOpen = true;
        }, 10);
    },
    methods: {
        confirm() {
            this.isOpen = false;
            setTimeout(() => {
                this.$emit('resolve', true);
            }, 250);
        },
        cancel() {
            this.isOpen = false;
            setTimeout(() => {
                this.$emit('resolve', false);
            }, 250);
        }
    }
}
</script>

<style scoped>
/* ─────────────────────────────────────────────
   Modal Overlay (Backdrop)
   ───────────────────────────────────────────── */
.confirm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.confirm-modal-overlay.is-open {
    opacity: 1;
    pointer-events: all;
}

/* ─────────────────────────────────────────────
   Modal Card
   ───────────────────────────────────────────── */
.confirm-modal-card {
    background: var(--bg-surface, #ffffff);
    border: 1px solid var(--border-color, rgba(0, 0, 0, 0.06));
    border-radius: 20px;
    box-shadow: 
        0 10px 15px -3px rgba(0, 0, 0, 0.05),
        0 25px 40px -12px rgba(0, 0, 0, 0.12),
        0 0 0 1px rgba(0, 0, 0, 0.02);
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    position: relative;
    transform: translateY(24px) scale(0.95);
    opacity: 0;
    transition: 
        transform 0.4s cubic-bezier(0.16, 1, 0.3, 1),
        opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
    padding: 32px 28px 24px;
}

.confirm-modal-card.is-open {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* Dark Mode Overrides */
:global(.dark) .confirm-modal-card {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: 
        0 20px 25px -5px rgba(0, 0, 0, 0.3),
        0 35px 60px -15px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ─────────────────────────────────────────────
   Close Button
   ───────────────────────────────────────────── */
.confirm-modal-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-muted, #94a3b8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.confirm-modal-close-btn:hover {
    background: var(--bg-hover, rgba(0, 0, 0, 0.04));
    color: var(--text-primary, #1e293b);
    transform: rotate(90deg);
}

:global(.dark) .confirm-modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #f8fafc;
}

.confirm-modal-close-btn svg {
    width: 16px;
    height: 16px;
}

/* ─────────────────────────────────────────────
   Body Content
   ───────────────────────────────────────────── */
.confirm-modal-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
    margin-bottom: 24px;
}

/* ─────────────────────────────────────────────
   Glowing Icon Styles
   ───────────────────────────────────────────── */
.confirm-icon-wrapper {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-icon-circle {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: transform 0.3s ease;
}

.confirm-icon-wrapper:hover .confirm-icon-circle {
    transform: scale(1.08);
}

.confirm-icon-glow {
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    /* filter: blur(12px); */
    opacity: 0.5;
    z-index: 1;
    transition: opacity 0.3s ease;
}

.confirm-icon-wrapper:hover .confirm-icon-glow {
    opacity: 0.8;
}

/* Info Icon Palette */
.confirm-icon-wrapper.is-info .confirm-icon-circle {
    background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
    color: #0284c7;
    border: 1px solid rgba(186, 230, 253, 0.4);
}

.confirm-icon-wrapper.is-info .confirm-icon-glow {
    background: #0284c7;
}

:global(.dark) .confirm-icon-wrapper.is-info .confirm-icon-circle {
    background: linear-gradient(135deg, rgba(2, 132, 199, 0.15) 0%, rgba(2, 132, 199, 0.3) 100%);
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.2);
}

/* Danger/Destructive Icon Palette */
.confirm-icon-wrapper.is-danger .confirm-icon-circle {
    /* background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%); */
    color: #dc2626;
    /* border: 1px solid rgba(254, 202, 202, 0.4); */
}

.confirm-icon-wrapper.is-danger .confirm-icon-glow {
    /* background: #ef4444; */
}

:global(.dark) .confirm-icon-wrapper.is-danger .confirm-icon-circle {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.15) 0%, rgba(220, 38, 38, 0.3) 100%);
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.2);
}

.icon-svg {
    width: 44px;
    height: 44px;
}

/* Trash Icon Animations & Transitions */
.trash-icon {
    overflow: visible;
}

.trash-lid-group {
    transform-origin: 32px 14px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Playful lid pop-up entrance animation when open */
.confirm-modal-card.is-open .trash-lid-group {
    animation: trash-lid-pop 0.8s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes trash-lid-pop {
    0% {
        transform: translateY(0) rotate(0deg);
    }
    30% {
        transform: translateY(-8px) rotate(-12deg);
    }
    50% {
        transform: translateY(-10px) rotate(-15deg);
    }
    75% {
        transform: translateY(0) rotate(-3deg);
    }
    90% {
        transform: translateY(0) rotate(1deg);
    }
    100% {
        transform: translateY(0) rotate(0deg);
    }
}

/* Lift and tilt trash lid on wrapper hover or confirm button hover */
.confirm-icon-wrapper:hover .trash-lid-group,
.is-confirm-hovered .trash-lid-group {
    transform: translateY(-10px) rotate(-15deg);
}

/* Shake trash body when confirm button is hovered */
.trash-body {
    transform-origin: 32px 58px;
    transition: transform 0.25s ease;
}

.is-confirm-hovered .trash-body {
    animation: trash-body-shake 0.15s ease-in-out infinite;
}

@keyframes trash-body-shake {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-2.5deg);
    }
    75% {
        transform: rotate(2.5deg);
    }
}

/* ─────────────────────────────────────────────
   Text Styles
   ───────────────────────────────────────────── */
.confirm-text-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.confirm-modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
    margin: 0;
    letter-spacing: -0.02em;
}

:global(.dark) .confirm-modal-title {
    color: #f8fafc;
}

.confirm-modal-message {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary, #64748b);
    margin: 0;
    padding: 0 10px;
    word-break: break-word;
    white-space: pre-wrap;
}

:global(.dark) .confirm-modal-message {
    color: #94a3b8;
}

/* ─────────────────────────────────────────────
   Footer & Buttons
   ───────────────────────────────────────────── */
.confirm-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.confirm-btn {
    flex: 1;
    height: 42px;
    border-radius: 12px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    border: none;
    outline: none;
}

.confirm-btn:hover {
    transform: translateY(-2px);
}

.confirm-btn:active {
    transform: translateY(0) scale(0.97);
}

/* Cancel Button Styling */
.confirm-btn-secondary {
    background: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.confirm-btn-secondary:hover {
    background: #e2e8f0;
    color: #1e293b;
}

:global(.dark) .confirm-btn-secondary {
    background: #334155;
    color: #cbd5e1;
    border-color: #475569;
}

:global(.dark) .confirm-btn-secondary:hover {
    background: #475569;
    color: #f8fafc;
}

/* Primary Confirm Button (Blue Gradient) */
.confirm-btn-primary {
    background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.confirm-btn-primary:hover {
    background: linear-gradient(135deg, #4338ca 0%, #2563eb 100%);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}

/* Danger Confirm Button (Crimson Gradient) */
.confirm-btn-danger {
    background: linear-gradient(135deg, #e11d48 0%, #f43f5e 100%);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25);
}

.confirm-btn-danger:hover {
    background: linear-gradient(135deg, #be123c 0%, #e11d48 100%);
    box-shadow: 0 6px 16px rgba(225, 29, 72, 0.35);
}
</style>
