@extends('dashboard.user.layouts.app')
@section('content')
    <div class="page-container">

        <div class="page-title-head d-flex align-items-sm-center flex-sm-row flex-column gap-2">
            <div class="flex-grow-1">
                <h4 class="fs-18 fw-semibold mb-0">{{ $title }}</h4>
            </div>

            <div class="text-end">
                <x-dashboard.user.breadcrumbs :breadcrumbs="$breadcrumbs" />
            </div>
        </div>

        <div class="row">
            <div class="col-xl-12 col-lg-12">
                <x-dashboard.user.card>

                    @slot('header')
                        <a onclick="return confirm('Are you sure?')" href="{{ route('user.notification.read_all') }}"
                            class="btn btn-primary btn-sm d-inline-flex align-items-center gap-1">
                            <i class="fa-solid fa-eye"></i> Read All
                        </a>
                    @endslot

                    {{-- ── DESKTOP TABLE (lg and above) ── --}}
                    <div class="table-responsive d-none d-lg-block">
                        <table id="myTable" class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Title</th>
                                    <th>Message</th>
                                    <th>Status</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($notifications as $notification)
                                    <tr>
                                        <td>{{ $loop->iteration }}</td>
                                        <td>{{ $notification->title }}</td>
                                        <td>{{ $notification->description }}</td>
                                        <td>
                                            @if ($notification->read)
                                                <span class="badge bg-success-subtle text-success fs-12 p-1">Read</span>
                                            @else
                                                <span class="badge bg-warning-subtle text-warning fs-12 p-1">Unread</span>
                                            @endif
                                        </td>
                                        <td>
                                            <a href="{{ route('user.notification.show', $notification->uuid) }}"
                                                class="btn btn-warning btn-sm">
                                                <i class="ti ti-eye me-1"></i> View
                                            </a>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>

                    {{-- ── MOBILE / TABLET CARDS (below lg) ── --}}
                    <div class="d-lg-none">
                        @foreach ($notifications as $notification)
                            <div
                                class="notif-card border rounded-3 p-3 mb-3 {{ $notification->read ? '' : 'notif-card--unread' }}">

                                {{-- Top row: index + status --}}
                                <div class="d-flex justify-content-between align-items-center mb-2">
                                    <span class="txn-index-badge">#{{ $loop->iteration }}</span>
                                    @if ($notification->read)
                                        <span class="badge bg-success-subtle text-success rounded-pill px-3 py-1"
                                            style="font-size:.7rem;">Read</span>
                                    @else
                                        <span class="badge bg-warning-subtle text-warning rounded-pill px-3 py-1"
                                            style="font-size:.7rem;">Unread</span>
                                    @endif
                                </div>

                                {{-- Title --}}
                                <p class="fw-semibold mb-1" style="font-size:.9rem;">{{ $notification->title }}</p>

                                {{-- Message --}}
                                <p class="text-muted mb-3" style="font-size:.82rem;line-height:1.6;">
                                    {{ $notification->description }}
                                </p>

                                {{-- Action --}}
                                <a href="{{ route('user.notification.show', $notification->uuid) }}"
                                    class="btn btn-warning btn-sm w-100 d-inline-flex align-items-center justify-content-center gap-1">
                                    <i class="ti ti-eye"></i> View Notification
                                </a>

                            </div>
                        @endforeach
                    </div>

                </x-dashboard.user.card>

                <style>
                    .notif-card {
                        /* background: #fff; */
                        transition: box-shadow .15s;
                    }

                    .notif-card:hover {
                        box-shadow: 0 4px 16px rgba(0, 0, 0, .08);
                    }

                    .notif-card--unread {
                        border-left: 3px solid #ffc107 !important;
                    }

                    .txn-index-badge {
                        font-size: .72rem;
                        font-weight: 700;
                        background: #f1f3f5;
                        color: #6c757d;
                        border-radius: 6px;
                        padding: 2px 7px;
                    }
                </style>
            </div>
        </div>
    </div>
@endsection
