@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">
            <div class="row gx-3">
                @if (Auth::user()->role === 'pemilik')
                    <div class="col-6 col-lg-3 col-md-6">
                        <div class="card mb-0">
                            <div class="card-body px-3 py-4">

                                <div class="stat-header">
                                    <h6 class="stat-label">Pendapatan Bulan Ini</h6>
                                    <i class="bi bi-info-circle menu-dots" data-bs-toggle="tooltip" data-bs-placement="top"
                                        title="Total pendapatan dari pesanan buket dan foto dalam bulan ini"></i>
                                </div>

                                <div class="stat-body">
                                    <div class="stat-icon">
                                        <i class="bi bi-bank"></i>
                                    </div>
                                    <div>
                                        <h6 class="stat-count">Rp {{ number_format($stat['pendapatan'], 0, ',', '.') }}</h6>
                                        <span
                                            class="stat-percent {{ $stat['pendapatan_grow'] >= 0 ? 'text-success' : 'text-danger' }} fw-bold">
                                            <i
                                                class="bi {{ $stat['pendapatan_grow'] >= 0 ? 'bi-arrow-up' : 'bi-arrow-down' }}"></i>
                                            {{ abs($stat['pendapatan_grow']) }}%
                                        </span>

                                        <small class="stat-month">dari bulan lalu</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-6 col-lg-3 col-md-6">
                        <div class="card mb-0">
                            <div class="card-body px-3 py-4">

                                <div class="stat-header">
                                    <h6 class="stat-label">Total Pesanan Masuk</h6>
                                    <i class="bi bi-info-circle menu-dots" data-bs-toggle="tooltip" data-bs-placement="top"
                                        title="Total pesanan buket dan foto yang masuk dalam bulan ini"></i>
                                </div>

                                <div class="stat-body">
                                    <div class="stat-icon">
                                        <i class="bi bi-cart-fill"></i>
                                    </div>
                                    <div>
                                        <h6 class="stat-count">{{ $stat['masuk_count'] }} Pesanan</h6>
                                        <span
                                            class="stat-percent {{ $stat['masuk_grow'] >= 0 ? 'text-success' : 'text-danger' }} fw-bold">
                                            <i
                                                class="bi {{ $stat['masuk_grow'] >= 0 ? 'bi-arrow-up' : 'bi-arrow-down' }}"></i>
                                            {{ abs($stat['masuk_grow']) }}%
                                        </span>

                                        <small class="stat-month">dari bulan lalu</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-6 col-lg-3 col-md-6">
                        <div class="card mb-0">
                            <div class="card-body px-3 py-4">

                                <div class="stat-header">
                                    <h6 class="stat-label">Pesanan Selesai</h6>
                                    <i class="bi bi-info-circle menu-dots" data-bs-toggle="tooltip" data-bs-placement="top"
                                        title="Total pesanan buket dan foto yang selesai dalam bulan ini"></i>
                                </div>

                                <div class="stat-body">
                                    <div class="stat-icon">
                                        <i class="bi bi-cart-check-fill"></i>
                                    </div>
                                    <div>
                                        <h6 class="stat-count">{{ $stat['selesai_count'] }} Pesanan</h6>
                                        <span
                                            class="stat-percent {{ $stat['selesai_grow'] >= 0 ? 'text-success' : 'text-danger' }} fw-bold">
                                            <i
                                                class="bi {{ $stat['selesai_grow'] >= 0 ? 'bi-arrow-up' : 'bi-arrow-down' }}"></i>{{ abs($stat['selesai_grow']) }}%
                                        </span>

                                        <small class="stat-month">dari bulan lalu</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-6 col-lg-3 col-md-6">
                        <div class="card mb-0">
                            <div class="card-body px-3 py-4">

                                <div class="stat-header">
                                    <h6 class="stat-label">Pesanan Ditolak</h6>
                                    <i class="bi bi-info-circle menu-dots" data-bs-toggle="tooltip" data-bs-placement="top"
                                        title="Total pesanan buket dan foto yang ditolak dalam bulan ini"></i>
                                </div>

                                <div class="stat-body">
                                    <div class="stat-icon">
                                        <i class="bi bi-cart-x-fill"></i>
                                    </div>
                                    <div>
                                        <h6 class="stat-count">{{ $stat['batal_count'] }} Pesanan</h6>
                                        <span
                                            class="stat-percent {{ $stat['batal_grow'] <= 0 ? 'text-success' : 'text-danger' }} fw-bold">
                                            <i
                                                class="bi {{ $stat['batal_grow'] >= 0 ? 'bi-arrow-up' : 'bi-arrow-down' }}"></i>
                                            {{ abs($stat['batal_grow']) }}%
                                        </span>

                                        <small class="stat-month">dari bulan lalu</small>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                @endif
            </div>

        </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>Bunga 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
