@extends('layouts.admin')

@section('title', 'Beranda')

@section('content')
    {{-- ALERT SUKSES --}}
    @if (session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif

    {{-- ALERT ERROR UMUM (Jika ada error selain validasi modal) --}}
    @if (session('error'))
        <div class="alert alert-danger alert-dismissible fade show" role="alert">
            {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif
    <section class="row gy-3">
        <div class="col-12">
            @if (Auth::user()->role === 'pemilik')
                <div class="row">
                    @include('admin.components._stat_card', [
                        'label' => 'Pendapatan',
                        'icon' => 'bi-bank',
                        'value' => 'Rp ' . number_format($stat['pendapatan'], 0, ',', '.'),
                        'grow' => $stat['pendapatan_grow'],
                        'tooltip' => 'Total pendapatan dari pesanan buket dan foto bulan ini',
                    ])
                    @include('admin.components._stat_card', [
                        'label' => 'Pesanan Masuk',
                        'icon' => 'bi-cart-fill',
                        'value' => $stat['masuk_count'] . ' Pesanan',
                        'grow' => $stat['masuk_grow'],
                        'tooltip' => 'Total pesanan buket dan foto yang masuk bulan ini',
                    ])
                    @include('admin.components._stat_card', [
                        'label' => 'Pesanan Selesai',
                        'icon' => 'bi-cart-check-fill',
                        'value' => $stat['selesai_count'] . ' Pesanan',
                        'grow' => $stat['selesai_grow'],
                        'tooltip' => 'Total pesanan buket dan foto yang selesai bulan ini',
                    ])
                    @include('admin.components._stat_card', [
                        'label' => 'Pesanan Ditolak',
                        'icon' => 'bi-cart-x-fill',
                        'value' => $stat['batal_count'] . ' Pesanan',
                        'grow' => $stat['batal_grow'],
                        'tooltip' => 'Total pesanan buket dan foto yang ditolak bulan ini',
                        'is_negative_metric' => true,
                    ])
                </div>
            @endif
        </div>
        <div class="col-12">
            <div class="row gx-3">
                <div class="col-12 col-xl-6">
                    <div class="card mb-0">
                        <div class="card-header">
                            <h4>Buket Diambil Hari Ini</h4>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-hover table-lg">
                                    <thead>
                                        <tr>
                                            <th>Waktu</th>
                                            <th>Nama Pelanggan</th>
                                            <th>Nama Buket</th>
                                            <th>Aksi</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse ($buketToday as $p)
                                            <tr>
                                                <td>{{ \Carbon\Carbon::parse($p->tgl_ambil)->format('H:i') }} WIB</td>
                                                <td>{{ $p->pelanggan->nama }}</td>
                                                <td>{{ $p->buket->nama }}</td>
                                                <td class="col-auto">
                                                    <a href="#" class="btn icon btn-primary btn-action"
                                                        data-bs-toggle="modal"
                                                        data-bs-target="#buket{{ $p->id_transaksi }}">
                                                        <i class="bi bi-eye"></i>
                                                    </a>
                                                </td>
                                            </tr>
                                            @include('admin.pesanan.partials.modal-buket')
                                        @empty
                                            <tr>
                                                <td colspan="4" class="text-center text-muted">Tidak ada buket diambil
                                                    hari ini.</td>
                                            </tr>
                                        @endforelse
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-12 col-xl-6">
                    <div class="card mb-0">
                        <div class="card-header">
                            <h4>Jadwal Foto Hari Ini</h4>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-hover table-lg">
                                    <thead>
                                        <tr>
                                            <th>Waktu</th>
                                            <th>Nama Pelanggan</th>
                                            <th>Nama Paket</th>
                                            <th>Aksi</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @forelse ($fotoToday as $p)
                                            <tr>
                                                <td>{{ \Carbon\Carbon::parse($p->jam_mulai)->format('H:i') }} -
                                                    {{ \Carbon\Carbon::parse($p->jam_selesai)->format('H:i') }}</td>
                                                <td>{{ $p->pelanggan->nama }}</td>
                                                <td>{{ $p->paketFoto->nama }}</td>
                                                <td class="col-auto">
                                                    <a href="#" class="btn icon btn-primary btn-action"
                                                        data-bs-toggle="modal" data-bs-target="#foto{{ $p->id_booking }}">
                                                        <i class="bi bi-eye"></i>
                                                    </a>
                                                </td>
                                            </tr>
                                            @include('admin.pesanan.partials.modal-foto')
                                        @empty
                                            <tr>
                                                <td colspan="4" class="text-center text-muted">Tidak ada jadwal foto
                                                    hari ini.</td>
                                            </tr>
                                        @endforelse
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-12 col-xl-12">
            <div class="card mb-0">
                <div class="card-header">
                    <h4>Pesanan Pending</h4>
                </div>
                <div class="card-body">

                    <div class="nav nav-pills nav-fill mb-4" id="v-pills-tab" role="tablist" aria-orientation="horizontal">
                        <a class="nav-link active" id="v-pills-home-tab" data-bs-toggle="pill" href="#v-pills-home"
                            role="tab" aria-controls="v-pills-home" aria-selected="true">
                            Buket
                        </a>
                        <a class="nav-link" id="v-pills-profile-tab" data-bs-toggle="pill" href="#v-pills-profile"
                            role="tab" aria-controls="v-pills-profile" aria-selected="false">
                            Foto
                        </a>
                    </div>

                    <div class="tab-content" id="v-pills-tabContent">

                        <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel"
                            aria-labelledby="v-pills-home-tab">
                            <table class="table table-striped" id="riwayat-buket">
                                <thead>
                                    <tr>
                                        <th>No. Invoice</th>
                                        <th>Nama Pelanggan</th>
                                        <th>Nama Buket</th>
                                        <th>Tanggal Ambil</th>
                                        <th>Jam Ambil</th>
                                        <th>Total</th>
                                        <th>Status</th>
                                        <th>Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse ($pesananBuket as $p)
                                        <tr>
                                            <td>{{ $p->no_invoice }}</td>
                                            <td>{{ $p->pelanggan->nama }}</td>
                                            <td>{{ $p->buket->nama }}</td>
                                            <td>
                                                {{ \Carbon\Carbon::parse($p->tgl_ambil)->locale('id')->translatedFormat('d F Y') }}
                                            </td>
                                            <td>
                                                {{ \Carbon\Carbon::parse($p->tgl_ambil)->format('H:i') }} WIB
                                            </td>
                                            <td>Rp {{ number_format($p->total_bayar, 0, ',', '.') }}</td>
                                            <td>
                                                <span class="badge {{ $p->status_label->class }}">
                                                    {{ $p->status_label->text }}
                                                </span>
                                            </td>
                                            <td class="text-center col-auto"><a href="#"
                                                    class="btn icon btn-primary btn-action" data-bs-toggle="modal"
                                                    data-bs-target="#buket{{ $p->id_transaksi }}">
                                                    <i class="bi bi-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        @include('admin.pesanan.partials.modal-buket')
                                    @empty
                                        <tr>
                                            <td colspan="8" class="text-center text-muted">Tidak ada pesanan buket yang
                                                pending.
                                            </td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>

                        <div class="tab-pane fade" id="v-pills-profile" role="tabpanel"
                            aria-labelledby="v-pills-profile-tab">
                            <table class="table table-striped" id="riwayat-foto">
                                <thead>
                                    <tr>
                                        <th>No. Invoice</th>
                                        <th>Nama Pelanggan</th>
                                        <th>Nama Paket</th>
                                        <th>Tanggal Booking</th>
                                        <th>Waktu</th>
                                        <th>Total</th>
                                        <th>Status</th>
                                        <th>Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse ($pesananFoto as $p)
                                        <tr>
                                            <td>{{ $p->no_invoice }}</td>
                                            <td>{{ $p->pelanggan->nama }}</td>
                                            <td>{{ $p->paketFoto->nama }}</td>
                                            <td>
                                                {{ \Carbon\Carbon::parse($p->tgl_booking)->locale('id')->translatedFormat('d F Y') }}
                                            </td>
                                            <td>
                                                {{ \Carbon\Carbon::parse($p->jam_mulai)->format('H:i') }} -
                                                {{ \Carbon\Carbon::parse($p->jam_selesai)->format('H:i') }}
                                            </td>
                                            <td>Rp {{ number_format($p->total_bayar, 0, ',', '.') }}</td>
                                            <td>
                                                <span class="badge {{ $p->status_label->class }}">
                                                    {{ $p->status_label->text }}
                                                </span>
                                            </td>
                                            <td class="text-center col-auto"><a href="#"
                                                    class="btn icon btn-primary btn-action" data-bs-toggle="modal"
                                                    data-bs-target="#foto{{ $p->id_booking }}">
                                                    <i class="bi bi-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        @include('admin.pesanan.partials.modal-foto')
                                    @empty
                                        <tr>
                                            <td colspan="8" class="text-center text-muted">Tidak ada pesanan
                                                foto yang pending.</td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </section>
@endsection
