@extends('layouts.admin')

@section('title', 'Beranda')

@section('content')
    <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 Dibatalkan</h6>
                                    <i class="bi bi-info-circle menu-dots" data-bs-toggle="tooltip" data-bs-placement="top"
                                        title="Total pesanan buket dan foto yang dibatalkan 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 $rb)
                                            <tr>
                                                <td>{{ \Carbon\Carbon::parse($rb->tgl_ambil)->format('H:i') }} WIB</td>
                                                <td>{{ $rb->pelanggan->nama }}</td>
                                                <td>{{ $rb->buket->nama }}</td>
                                                <td class="col-auto">
                                                    <a href="#" class="btn icon btn-primary btn-action"
                                                        data-bs-toggle="modal"
                                                        data-bs-target="#riwayatBuket{{ $rb->id_transaksi }}">
                                                        <i class="bi bi-eye"></i>
                                                    </a>
                                                </td>
                                            </tr>
                                            @include('admin.pesanan.partials.modal-riwayat-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 $rf)
                                            <tr>
                                                <td>{{ \Carbon\Carbon::parse($rf->jam_mulai)->format('H:i') }} -
                                                    {{ \Carbon\Carbon::parse($rf->jam_selesai)->format('H:i') }}</td>
                                                <td>{{ $rf->pelanggan->nama }}</td>
                                                <td>{{ $rf->paketFoto->nama }}</td>
                                                <td class="col-auto">
                                                    <a href="#" class="btn icon btn-primary btn-action"
                                                        data-bs-toggle="modal"
                                                        data-bs-target="#riwayatFoto{{ $rf->id_booking }}">
                                                        <i class="bi bi-eye"></i>
                                                    </a>
                                                </td>
                                            </tr>
                                            @include('admin.pesanan.partials.modal-riwayat-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>Total</th>
                                        <th>Status</th>
                                        <th>Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse ($riwayatBuket as $rb)
                                        <tr>
                                            <td>{{ $rb->no_invoice }}</td>
                                            <td>{{ $rb->pelanggan->nama }}</td>
                                            <td>{{ $rb->buket->nama }}</td>
                                            <td>{{ \Carbon\Carbon::parse($rb->tgl_ambil)->translatedFormat('d M Y') }}</td>
                                            <td>Rp {{ number_format($rb->total_bayar, 0, ',', '.') }}</td>
                                            <td>
                                                <span class="badge {{ $rb->status_label->class }}">
                                                    {{ $rb->status_label->text }}
                                                </span>
                                            </td>
                                            <td class="col-auto">
                                                <a href="#" class="btn icon btn-primary btn-action"
                                                    data-bs-toggle="modal"
                                                    data-bs-target="#riwayatBuket{{ $rb->id_transaksi }}">
                                                    <i class="bi bi-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        @include('admin.pesanan.partials.modal-riwayat-buket')
                                    @empty
                                        <tr>
                                            <td colspan="7" class="text-center text-muted">Tidak ada riwayat buket.
                                            </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>Total</th>
                                        <th>Status</th>
                                        <th>Aksi</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @forelse ($riwayatFoto as $rf)
                                        <tr>
                                            <td>{{ $rf->no_invoice }}</td>
                                            <td>{{ $rf->pelanggan->nama }}</td>
                                            <td>{{ $rf->paketFoto->nama }}</td>
                                            <td>{{ \Carbon\Carbon::parse($rf->tgl_booking)->translatedFormat('d M Y') }}
                                            </td>
                                            <td>Rp {{ number_format($rf->total_bayar, 0, ',', '.') }}</td>
                                            <td>
                                                <span class="badge {{ $rf->status_label->class }}">
                                                    {{ $rf->status_label->text }}
                                                </span>
                                            </td>
                                            <td class="col-auto">
                                                <a href="#" class="btn icon btn-primary btn-action"
                                                    data-bs-toggle="modal"
                                                    data-bs-target="#riwayatFoto{{ $rf->id_booking }}">
                                                    <i class="bi bi-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                        @include('admin.pesanan.partials.modal-riwayat-foto')
                                    @empty
                                        <tr>
                                            <td colspan="7" class="text-center text-muted">Tidak ada riwayat pesanan
                                                foto.</td>
                                        </tr>
                                    @endforelse
                                </tbody>
                            </table>
                        </div>

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