@extends('navbar')

@section('content')

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Booking Pemotretan</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- Moment.js harus di-load sebelum FullCalendar -->
    <script src="https://cdn.jsdelivr.net/npm/moment@2.29.1/moment.min.js"></script>
    <!-- FullCalendar -->
    <script src="https://cdn.jsdelivr.net/npm/fullcalendar@3.2.0/dist/fullcalendar.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/fullcalendar@3.2.0/dist/fullcalendar.min.css" rel="stylesheet" />
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="{{ asset('css/booking.css') }}" />
</head>
<body>
    
    <div class="card border-danger mt-4 shadow-sm">
        <div class="card-body">
            <h5 class="card-title fw-bold text-danger">Informasi Pembayaran Transfer</h5>
            <p class="card-text">Silakan lakukan pembayaran ke salah satu rekening berikut:</p>
            <ul class="list-unstyled text-dark">
                <li class="mb-3">
                    <strong>Bank BCA</strong><br />
                    <span>No. Rekening: <strong class="text-danger">0744281350</strong></span><br />
                    <span>a.n. <strong>Skyrent Photo</strong></span>
                </li>
                <li>
                    <strong>Bank BRI</strong><br />
                    <span>No. Rekening: <strong class="text-danger">0007 0110 9333 508</strong></span><br />
                    <span>a.n. <strong>Maulidewanta Akbar Hariyanto</strong></span>
                </li>
            </ul>
            <p class="mt-3 text-muted"><small>Upload bukti transfer pada bagian <strong>Daftar Booking Anda</strong> setelah
                    melakukan pembayaran.</small></p>

            <i class="bi bi-exclamation-triangle-fill me-1"></i>
            Harap diperhatikan bahwa untuk mengamankan jadwal pemotretan, pelanggan diwajibkan melakukan pembayaran uang
            muka (DP) minimal sebesar Rp 50.000. Sisa biaya dapat dibayarkan di hari pemotretan atau sesuai metode pembayaran
            yang dipilih.
        </div>
    </div>

   
<div class="container py-4">
        @if(Auth::check())
        <div class="mb-4">
            <h4 class="fw-bold">Daftar Booking Anda</h4>
            @if($bookings->isEmpty())
            <p class="text-muted">Belum ada booking yang dilakukan.</p>
            @else
            <div class="table-responsive">
                <table class="table table-bordered table-hover align-middle">
                    <thead class="table-light">
                        <tr>
                            <th>No</th>
                            <th>Tanggal</th>
                            <th>Produk</th>
                            <th>Paket</th>
                            <th>Total Harga</th>
                            <th>Metode</th>
                            <th>Status</th>
                            <th>Keterangan</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($bookings as $index => $b)
                        <tr>
                            <td>{{ $index + 1 }}</td>
                            <td>{{ \Carbon\Carbon::parse($b->tanggal_pemotretan)->translatedFormat('d M Y') }}</td>
                            <td>{{ ucfirst($b->produk) }}</td>
                            <td>{{ $b->paket }}</td>
                            <td>Rp {{ number_format($b->total_harga, 0, ',', '.') }}</td>
                            <td>{{ ucfirst($b->payment_method) }}</td>
                            <td>
                                @if($b->status == 'pending')
                                <span class="badge bg-warning text-dark">Menunggu</span>
                                @php
                                $dpMinimal = 50000;
                                $dpKurang = !$b->bukti_transfer || $b->total_harga < $dpMinimal;
                                @endphp

                                @if($dpKurang)
                                <div class="text-danger small mt-1">
                                    {{ !$b->bukti_transfer ? 'Belum upload bukti transfer' : 'Jumlah DP belum mencukupi (minimal Rp 50.000)' }}
                                </div>
                                @else
                                <div class="text-success small mt-1">Bukti sudah diupload</div>
                                <a href="{{ asset('images/' . $b->bukti_transfer) }}" target="_blank">Lihat Bukti</a>

                                @endif

                                <!-- Form upload bukti transfer hanya untuk status pending -->
                                <form action="{{ route('booking.uploadBukti', $b->id) }}" method="POST"
                                    enctype="multipart/form-data" class="mt-2 d-flex gap-2">
                                    @csrf
                                    <input type="file" name="bukti_transfer" accept="image/*"
                                        class="form-control form-control-sm" required />
                                    <button type="submit" class="btn btn-sm btn-primary">Upload Bukti</button>
                                </form>
                                @elseif($b->status == 'approved')
                                <span class="badge bg-success">Diterima</span>
                                @if($b->bukti_transfer)
                                <div class="mt-2">
                                    <a href="{{ asset('images/' . $b->bukti_transfer) }}" target="_blank"
                                        class="btn btn-sm btn-outline-primary">Lihat Bukti</a>
                                </div>
                                @endif
                                @elseif($b->status == 'declined')
                                <span class="badge bg-danger">Ditolak</span>
                                @if($b->bukti_transfer)
                                <div class="mt-2">
                                    <a href="{{ asset('images/' . $b->bukti_transfer) }}" target="_blank"
                                        class="btn btn-sm btn-outline-primary">Lihat Bukti</a>
                                </div>
                                @endif
                                @else
                                <span class="badge bg-secondary">Status Tidak Diketahui</span>
                                @endif
                            </td>
                            <td>{{ $b->keterangan ?? '-' }}</td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            @endif
        </div>
        @endif
    </div>
    </body>
    @endsection