@extends('layouts.user')

@section('title', 'Formulir Pemesanan Buket - Florist dan Self Photo Studio Nganjuk')

@section('content')
    <section class="section-formulirbuket">
        <div class="container">

            <div class="row mb-5 text-center">
                <div class="col-12">
                    <h2 class="formulirbuket-page-title">Formulir Pemesanan</h2>
                </div>
            </div>

            <form action="{{ route('transaksi.buket.store') }}" method="POST" enctype="multipart/form-data">
                @csrf
                <div class="row g-4">

                    <div class="col-lg-6 mb-5 mb-lg-0">

                        <div class="formulirbuket-section mb-3">
                            <h4 class="formulirbuket-section-title mb-3">Rincian Pesanan</h4>
                            <div class="formulirbuket-card d-flex flex-column gap-2">
                                <div class="formulirbuket-product-summary d-flex align-items-center gap-3">
                                    <img src="{{ asset($buket->foto) }}" alt="{{ $buket->nama }}" class="rounded-3">
                                    <div>
                                        <h6 class=" mb-1">{{ $buket->nama }}</h6>
                                        <p class="text-teal  mb-0">Rp {{ number_format($buket->harga, 0, ',', '.') }}</p>
                                        <input type="hidden" name="id_buket" value="{{ $buket->id_buket }}">
                                    </div>
                                </div>
                                <div>
                                    <label class="form-label small">Request Khusus</label>
                                    <input type="text" name="request_khusus"
                                        class="form-control formulirbuket-input @error('request_khusus') is-invalid @enderror"
                                        placeholder="Masukkan Request Anda (Warna pita, dll)"
                                        value="{{ old('request_khusus') }}">
                                    @error('request_khusus')
                                        <div class="invalid-feedback d-block">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div>
                                    <label class="form-label  small">Kartu Ucapan</label>
                                    <textarea class="form-control formulirbuket-input @error('ucapan') is-invalid @enderror" name="ucapan" rows="2"
                                        placeholder="Masukkan Teks untuk Kartu Ucapan">{{ old('ucapan') }}</textarea>
                                    @error('ucapan')
                                        <div class="invalid-feedback d-block">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>
                        <div class="formulirbuket-section">
                            <h4 class="formulirbuket-section-title mb-3">Informasi Pemesan</h4>
                            <div class="formulirbuket-card d-flex flex-column gap-3">
                                <div>
                                    <label class="form-label small">Nama Lengkap</label>
                                    <input type="text" name="nama"
                                        class="form-control formulirbuket-input @error('nama') is-invalid @enderror"
                                        placeholder="Masukkan Nama Lengkap" value="{{ old('nama') }}">

                                    @error('nama')
                                        <div class="invalid-feedback d-block">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div>
                                    <label class="form-label  small">Nomor WhatsApp</label>
                                    <input type="number" name="no_wa"
                                        class="form-control formulirbuket-input @error('no_wa') is-invalid @enderror"
                                        placeholder="Masukkan Nomor WhatsApp" value="{{ old('no_wa') }}">
                                    @error('no_wa')
                                        <div class="invalid-feedback d-block">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div class="row g-3">
                                    <div class="col-md-6">
                                        <label class="form-label  small">Tanggal Pengambilan</label>
                                        <input type="date" name="tgl_ambil"
                                            class="form-control formulirbuket-input @error('tgl_ambil') is-invalid @enderror"
                                            value="{{ old('tgl_ambil') }}">
                                        @error('tgl_ambil')
                                            <div class="invalid-feedback d-block">{{ $message }}</div>
                                        @enderror
                                    </div>
                                    <div class="col-md-6">
                                        <label class="form-label  small">Waktu Pengambilan</label>
                                        <input type="time" name="waktu_ambil"
                                            class="form-control formulirbuket-input @error('waktu_ambil') is-invalid @enderror"
                                            min="09:00" max="21:00" value="{{ old('waktu_ambil') }}">
                                        <small class="text-muted">Jam operasional: 09.00 - 21.00 WIB</small>
                                        @error('waktu_ambil')
                                            <div class="invalid-feedback d-block">{{ $message }}</div>
                                        @enderror
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-6">
                        <h4 class="formulirbuket-section-title mb-3">Informasi Pembayaran</h4>
                        <div class="formulirbuket-payment-box">
                            <div class="d-flex justify-content-between align-items-center mb-4">
                                <span class="text-muted">Total Pembayaran</span>
                                <h5 class=" mb-0">Rp {{ number_format($buket->harga, 0, ',', '.') }}</h5>
                            </div>

                            <p class="small  mb-2">Transfer ke Rekening Berikut:</p>
                            <div class="row g-2 mb-4">
                                <div class="col-6">
                                    <div class="formulirbuket-bank-card">
                                        <div class="d-flex align-items-center gap-2 mb-2">
                                            <i class="bi bi-bank text-secondary"></i> <span class="small ">BCA</span>
                                        </div>
                                        <div class="d-flex justify-content-between align-items-end">
                                            <div>
                                                <p class="mb-0  small bank-num">6860305231</p>
                                                <p class="mb-0 x-small bank-name">a.n Deborah Febryana</p>
                                            </div>
                                            <button type="button"
                                                class="btn btn-sm btn-outline-secondary py-1 px-2 btn-copy"
                                                data-clipboard-text="6860305231" style="font-size: 12px">salin</button>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="formulirbuket-bank-card">
                                        <div class="d-flex align-items-center gap-2 mb-2">
                                            <i class="bi bi-bank text-secondary"></i> <span class="small ">BRI</span>
                                        </div>
                                        <div class="d-flex justify-content-between align-items-end">
                                            <div>
                                                <p class="mb-0  small bank-num">005601002337563</p>
                                                <p class="mb-0 x-small bank-name">a.n Deborah Febryana</p>
                                            </div>
                                            <button type="button"
                                                class="btn btn-sm btn-outline-secondary py-1 px-2 btn-copy"
                                                data-clipboard-text="005601002337563"
                                                style="font-size: 12px">salin</button>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="formulirbuket-bank-card">
                                        <div class="d-flex align-items-center gap-2 mb-2">
                                            <i class="bi bi-bank text-secondary"></i> <span
                                                class="small ">ShopeePay</span>
                                        </div>
                                        <div class="d-flex justify-content-between align-items-end">
                                            <div>
                                                <p class="mb-0  small bank-num">082133958469</p>
                                                <p class="mb-0 x-small bank-name">a.n Deborah Febryana</p>
                                            </div>
                                            <button type="button"
                                                class="btn btn-sm btn-outline-secondary py-1 px-2 btn-copy"
                                                data-clipboard-text="082133958469" style="font-size: 12px">salin</button>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="formulirbuket-bank-card">
                                        <div class="d-flex align-items-center gap-2 mb-2">
                                            <i class="bi bi-bank text-secondary"></i> <span class="small ">Dana</span>
                                        </div>
                                        <div class="d-flex justify-content-between align-items-end">
                                            <div>
                                                <p class="mb-0  small bank-num">082133958469</p>
                                                <p class="mb-0 x-small bank-name">a.n Deborah Febryana</p>
                                            </div>
                                            <button type="button"
                                                class="btn btn-sm btn-outline-secondary py-1 px-2 btn-copy"
                                                data-clipboard-text="082133958469" style="font-size: 12px">salin</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <p class="small  mb-2">Upload Bukti Pembayaran</p>
                            <div class="formulirbuket-upload-area mb-2 text-center position-relative">
                                <input type="file" name="bukti_bayar" accept="image/*"
                                    class="position-absolute w-100 h-100 opacity-0 start-0 top-0 cursor-pointer @error('bukti_bayar') is-invalid @enderror"
                                    id="fileUpload" value="{{ old('bukti_bayar') }}">
                                <div class="py-4" id="uploadPlaceholder">
                                    <i class="bi bi-file-earmark-arrow-up fs-3 text-secondary"></i>
                                    <p class="mb-0 small text-muted">Upload Bukti Pembayaran</p>
                                    <p class="mb-0 x-small text-muted">Max. 2 MB</p>
                                </div>
                            </div>
                            @error('bukti_bayar')
                                <div class="invalid-feedback d-block">{{ $message }}</div>
                            @enderror
                            <p class="x-small text-muted mb-4">
                                *Note: Pastikan pembayaran sudah dilakukan sebelum mengunggah bukti, ya!
                            </p>

                            <div class="d-flex gap-3">
                                <a href="{{ route('detail.buket', $buket->id_buket) }}"
                                    class="btn formulirbuket-btn-cancel flex-fill">Batalkan</a>
                                <button type="submit" class="btn formulirbuket-btn-submit flex-fill">Kirim
                                    Pesanan</button>
                            </div>

                        </div>
                    </div>

                </div>
            </form>
        </div>
    </section>

    <script>
        document.querySelectorAll('.btn-copy').forEach(btn => {
            btn.addEventListener('click', function() {
                navigator.clipboard.writeText(this.getAttribute('data-clipboard-text'));
                let originalText = this.innerText;
                this.innerText = 'Disalin!';
                setTimeout(() => {
                    this.innerText = originalText;
                }, 1500);
            });
        });
    </script>
    <script>
        // Preview Nama File setelah Upload
        document.getElementById('fileUpload').addEventListener('change', function() {
            const file = this.files[0];
            const placeholder = document.getElementById('uploadPlaceholder');

            if (file) {
                placeholder.innerHTML = `
                <i class="bi bi-check-circle-fill fs-3 text-success"></i>
                <p class="mb-0 small text-success">${file.name}</p>
                <p class="mb-0 x-small text-muted">Klik lagi untuk ganti file</p>
            `;
            }
        });
    </script>



@endsection
