{{--
    Komponen Toast Notification.
    Dipanggil sekali di akhir setiap view: <x-admin.toast />
    Menerima event Livewire: $this->dispatch('notify', type: 'success'|'error', message: '...')
--}}
<div
    x-data="{
        toasts: [],
        add(type, message) {
            const id = Date.now();
            this.toasts.push({ id, type, message });
            setTimeout(() => this.remove(id), 4000);
        },
        remove(id) {
            this.toasts = this.toasts.filter(t => t.id !== id);
        }
    }"
    x-on:notify.window="add($event.detail.type, $event.detail.message)"
    class="fixed bottom-5 right-5 z-50 space-y-2 pointer-events-none"
    style="min-width: 280px; max-width: 380px;"
>
    <template x-for="toast in toasts" :key="toast.id">
        <div
            x-show="true"
            x-transition:enter="transition ease-out duration-300"
            x-transition:enter-start="opacity-0 translate-y-3 scale-95"
            x-transition:enter-end="opacity-100 translate-y-0 scale-100"
            x-transition:leave="transition ease-in duration-200"
            x-transition:leave-start="opacity-100"
            x-transition:leave-end="opacity-0"
            class="flex items-start gap-3 bg-white border shadow-lg rounded-xl px-4 py-3 pointer-events-auto cursor-pointer"
            :class="{
                'border-green-200 shadow-green-100': toast.type === 'success',
                'border-red-200 shadow-red-100':     toast.type === 'error',
                'border-blue-200 shadow-blue-100':   toast.type === 'info',
            }"
            x-on:click="remove(toast.id)"
        >
            {{-- Icon --}}
            <div class="shrink-0 mt-0.5">
                <template x-if="toast.type === 'success'">
                    <svg class="w-5 h-5 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                </template>
                <template x-if="toast.type === 'error'">
                    <svg class="w-5 h-5 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                </template>
                <template x-if="toast.type === 'info'">
                    <svg class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                </template>
            </div>
            {{-- Pesan --}}
            <p class="text-sm text-slate-700 flex-1" x-text="toast.message"></p>
        </div>
    </template>
</div>
