@extends('layouts.app')

@push('head')
<style>
    .notif-shell {
        position: relative;
        display: flex;
        flex-direction: column;
        gap: 28px;
        padding: 38px 38px 32px;
        border-radius: 30px;
        background: linear-gradient(150deg, rgba(12, 24, 52, 0.95), rgba(7, 15, 36, 0.9));
        border: 1px solid rgba(148, 163, 184, 0.22);
        box-shadow: 0 36px 62px rgba(3, 7, 18, 0.58);
        overflow: hidden;
    }
    .notif-shell::before,
    .notif-shell::after {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
    }
    .notif-shell::before {
        background:
            radial-gradient(circle at 16% 18%, rgba(59, 130, 246, 0.28), transparent 55%),
            radial-gradient(circle at 84% -6%, rgba(14, 165, 233, 0.32), transparent 60%);
        opacity: 0.8;
    }
    .notif-shell::after {
        background: linear-gradient(140deg, transparent 40%, rgba(129, 140, 248, 0.18));
        opacity: 0.72;
    }
    .notif-shell > * { position: relative; z-index: 1; }

    .notif-hero {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 20px;
    }
    .notif-hero__info {
        display: flex;
        flex-direction: column;
        gap: 10px;
        max-width: 560px;
    }
    .notif-hero__tagline {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 6px 14px;
        border-radius: 999px;
        background: rgba(129, 140, 248, 0.22);
        border: 1px solid rgba(129, 140, 248, 0.4);
        color: #e0e7ff;
        font-size: 12px;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        font-weight: 600;
    }
    .notif-hero__info h2 {
        margin: 0;
        font-size: 30px;
        font-weight: 700;
        letter-spacing: -0.02em;
        color: #f8fafc;
    }
    .notif-hero__info p {
        margin: 0;
        color: rgba(226, 232, 240, 0.76);
        font-size: 15px;
        line-height: 1.6;
    }
    .notif-hero__meta {
        display: flex;
        flex-direction: column;
        gap: 10px;
        align-items: flex-end;
        min-width: 220px;
    }
    .notif-meta-chip {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 8px 16px;
        border-radius: 14px;
        background: rgba(37, 99, 235, 0.18);
        border: 1px solid rgba(37, 99, 235, 0.38);
        color: #bfdbfe;
        font-size: 12px;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        font-weight: 600;
    }
    .notif-meta-text {
        color: rgba(148, 163, 184, 0.82);
        font-size: 12px;
    }

    .notif-tabs {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px;
        border-radius: 18px;
        background: rgba(15, 23, 42, 0.82);
        border: 1px solid rgba(148, 163, 184, 0.24);
        box-shadow: inset 0 1px 0 rgba(148, 163, 184, 0.12);
    }
    .notif-tab {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 10px 18px;
        border-radius: 12px;
        border: none;
        background: transparent;
        color: #94a3b8;
        font-weight: 600;
        font-size: 13px;
        letter-spacing: 0.02em;
        cursor: pointer;
        transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
    }
    .notif-tab svg {
        width: 16px;
        height: 16px;
    }
    .notif-tab:hover {
        color: #e2e8f0;
        transform: translateY(-1px);
    }
    .notif-tab.is-active {
        background: linear-gradient(135deg, rgba(59,130,246,0.24), rgba(14,165,233,0.24));
        color: #f8fafc;
        box-shadow: 0 12px 24px rgba(14, 165, 233, 0.25);
    }

    .notif-wrapper {
        display: flex;
        flex-direction: column;
        gap: 18px;
    }
    .notif-section {
        animation: fadeIn 0.25s ease;
    }
    .notif-section.is-hidden {
        display: none;
    }

    .notif-card {
        display: grid;
        grid-template-columns: minmax(200px, 280px) 1fr;
        gap: 18px;
        padding: 22px 24px;
        border-radius: 20px;
        background: rgba(13, 22, 42, 0.82);
        border: 1px solid rgba(148, 163, 184, 0.22);
        box-shadow: 0 26px 44px rgba(5, 10, 24, 0.5);
        transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    }
    .notif-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 30px 50px rgba(13, 42, 94, 0.3);
        border-color: rgba(96, 165, 250, 0.32);
    }
    .notif-card.unread {
        border-left: 4px solid rgba(59, 130, 246, 0.9);
        box-shadow: 0 30px 54px rgba(37, 99, 235, 0.32);
    }
    .notif-image {
        border-radius: 16px;
        border: 1px dashed rgba(148, 163, 184, 0.28);
        background: rgba(15, 23, 42, 0.65);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px;
        color: rgba(148, 163, 184, 0.72);
        font-weight: 600;
        letter-spacing: 0.02em;
    }
    .notif-image img {
        width: 100%;
        max-height: 220px;
        object-fit: cover;
        border-radius: 12px;
        border: none;
    }

    .notif-content {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    .notif-title {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 19px;
        font-weight: 700;
        color: #e0f2fe;
        letter-spacing: -0.015em;
    }
    .notif-status {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        border-radius: 999px;
        background: rgba(34, 211, 238, 0.18);
        border: 1px solid rgba(14, 165, 233, 0.32);
        color: #bae6fd;
        font-size: 11px;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }
    .notif-message {
        color: #e2e8f0;
        line-height: 1.6;
    }
    .notif-meta {
        color: rgba(148, 163, 184, 0.8);
        font-size: 12px;
        letter-spacing: 0.04em;
    }
    .notif-actions {
        margin-top: 12px;
    }
    .notif-actions form {
        display: inline-flex;
    }
    .notif-actions button {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        background: linear-gradient(135deg, #2563eb, #1d4ed8);
        color: #f8fafc;
        border: none;
        border-radius: 14px;
        padding: 10px 20px;
        font-weight: 600;
        letter-spacing: 0.05em;
        cursor: pointer;
        transition: transform 0.18s ease, box-shadow 0.18s ease;
        box-shadow: 0 18px 32px rgba(37, 99, 235, 0.28);
    }
    .notif-actions button:hover {
        transform: translateY(-2px);
        box-shadow: 0 22px 36px rgba(37, 99, 235, 0.32);
    }

    .notif-empty {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 12px;
        padding: 32px 24px;
        border-radius: 20px;
        border: 1px dashed rgba(148, 163, 184, 0.32);
        background: rgba(15, 23, 42, 0.65);
        color: rgba(148, 163, 184, 0.85);
        font-weight: 600;
        text-align: center;
    }
    .notif-empty svg {
        width: 40px;
        height: 40px;
        color: rgba(59, 130, 246, 0.6);
    }

    @media (max-width: 900px) {
        .notif-card {
            grid-template-columns: 1fr;
        }
        .notif-image {
            max-width: 100%;
        }
    }
    @media (max-width: 640px) {
        .notif-shell {
            padding: 30px 24px 26px;
            border-radius: 26px;
        }
        .notif-hero__meta {
            align-items: flex-start;
        }
        .notif-tabs {
            width: 100%;
            justify-content: center;
        }
        .notif-tab {
            flex: 1;
            justify-content: center;
        }
    }
</style>
@endpush

@section('content')
<div class="notif-shell">
    <div class="notif-hero">
        <div class="notif-hero__info">
            <span class="notif-hero__tagline">Informasi Terbaru</span>
            <h2>Pemberitahuan</h2>
            <p>Pantau update absensi dan catatan admin melalui panel notifikasi yang lebih dinamis dan mudah dipindai.</p>
        </div>
        <div class="notif-hero__meta">
            <span class="notif-meta-chip">
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" width="16" height="16">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 6v6l3 3" />
                </svg>
                {{ now()->timezone(config('app.timezone'))->format('d M Y H:i') }}
            </span>
            <span class="notif-meta-text">Jumlah notifikasi: {{ $absensiNotifications->count() + $adminNotifications->count() }}</span>
        </div>
    </div>

    <div class="notif-tabs" role="tablist">
        <button class="notif-tab is-active" data-target="absensi" role="tab" aria-selected="true">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m21 15-1.434-1.435A2.1 2.1 0 0 1 19 12.116V9a7 7 0 1 0-14 0v3.116c0 .556-.221 1.09-.566 1.45L3 15m9 6.5a2.5 2.5 0 0 0 2.5-2.5H9.5A2.5 2.5 0 0 0 12 21.5Z" />
            </svg>
            Absensi
        </button>
        <button class="notif-tab" data-target="admin" role="tab" aria-selected="false">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M15 12a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm-6.5 1.5a4.5 4.5 0 0 0-4.5 4.5H9m6 0h5a4.5 4.5 0 0 0-4.5-4.5h-1m-2.25 4.5 1.5-3m0 0 1.5 3m-1.5-3v3" />
            </svg>
            Admin
        </button>
    </div>

    <div class="notif-section" data-section="absensi">
        @if($absensiNotifications->isEmpty())
            <div class="notif-empty">
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0 1 18 14.158V11a6 6 0 1 0-12 0v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0a3 3 0 1 1-6 0m6 0H9" />
                </svg>
                Tidak ada pemberitahuan dari absensi.
            </div>
        @else
            <div class="notif-wrapper">
                @foreach($absensiNotifications as $notif)
                    <div class="notif-card {{ $notif->is_read ? '' : 'unread' }}">
                        @if($notif->image)
                            <div class="notif-image">
                                <img src="{{ asset('storage/'.$notif->image) }}" alt="{{ $notif->title }}">
                            </div>
                        @else
                            <div class="notif-image">Tidak ada gambar</div>
                        @endif
                        <div class="notif-content">
                            <div class="notif-title">
                                {{ $notif->title }}
                                @unless($notif->is_read)
                                    <span class="notif-status">
                                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" width="14" height="14">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 6v6l2.5 2.5" />
                                        </svg>
                                        Baru
                                    </span>
                                @endunless
                            </div>
                            <div class="notif-message">{{ $notif->message }}</div>
                            <div class="notif-meta">{{ $notif->created_at->format('d/m/Y H:i') }}</div>
                        </div>
                    </div>
                @endforeach
            </div>
        @endif
    </div>

    <div class="notif-section is-hidden" data-section="admin">
        @if($adminNotifications->isEmpty())
            <div class="notif-empty">
                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M3 13.5c0 2 1.5 3.5 3.5 3.5h.379l1.447 1.447a.75.75 0 0 0 1.274-.53V17h4.9c1.933 0 3.5-1.567 3.5-3.5v-6A1.5 1.5 0 0 0 16.5 6H6.5C4.567 6 3 7.567 3 9.5v4Z" />
                </svg>
                Tidak ada pemberitahuan dari admin.
            </div>
        @else
            <div class="notif-wrapper">
                @foreach($adminNotifications as $notif)
                    <div class="notif-card {{ $notif->is_read ? '' : 'unread' }}">
                        @if($notif->image)
                            <div class="notif-image">
                                <img src="{{ asset('storage/'.$notif->image) }}" alt="{{ $notif->title }}">
                            </div>
                        @else
                            <div class="notif-image">Tidak ada gambar</div>
                        @endif
                        <div class="notif-content">
                            <div class="notif-title">
                                {{ $notif->title }}
                                @unless($notif->is_read)
                                    <span class="notif-status">
                                        <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" width="14" height="14">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 6v6l2.5 2.5" />
                                        </svg>
                                        Baru
                                    </span>
                                @endunless
                            </div>
                            <div class="notif-message">{{ $notif->message }}</div>
                            <div class="notif-meta">{{ $notif->created_at->format('d/m/Y H:i') }}</div>
                            @if(!$notif->is_read)
                                <div class="notif-actions">
                                    <form method="POST" action="{{ route('notifications.read', $notif->id) }}">
                                        @csrf
                                        <button type="submit">
                                            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" width="16" height="16">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m4.5 12.75 6 6 9-13.5" />
                                            </svg>
                                            Tandai sudah dibaca
                                        </button>
                                    </form>
                                </div>
                            @endif
                        </div>
                    </div>
                @endforeach
            </div>
        @endif
    </div>
</div>
<script>
    document.addEventListener('DOMContentLoaded', () => {
        const tabs = document.querySelectorAll('.notif-tab');
        const sections = document.querySelectorAll('.notif-section');

        tabs.forEach(tab => {
            tab.addEventListener('click', () => {
                const target = tab.dataset.target;

                tabs.forEach(btn => {
                    const isActive = btn === tab;
                    btn.classList.toggle('is-active', isActive);
                    btn.setAttribute('aria-selected', isActive ? 'true' : 'false');
                });

                sections.forEach(section => {
                    section.classList.toggle('is-hidden', section.dataset.section !== target);
                });
            });
        });
    });
</script>
@endsection
