@extends('layouts.app')

@section('title', 'Form Pemesanan - INUFA')
@section('header', 'Form Pemesanan')

@section('content')
<div class="container mx-auto px-4 py-8">
    <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
        <!-- Informasi Paket -->
        <div class="bg-white rounded-lg shadow-lg overflow-hidden">
            <!-- Image Section -->
            <div class="h-64 bg-gray-200 relative">
                @if($paket->image)
                    <img src="{{ Storage::url($paket->image) }}" 
                         alt="{{ $paket->nama_paket }}" 
                         class="w-full h-full object-cover">
                @else
                    <div class="w-full h-full flex items-center justify-center">
                        <i class="fas fa-image text-4xl text-gray-400"></i>
                    </div>
                @endif
            </div>

            <!-- Info Section -->
            <div class="p-6">
                <h2 class="text-2xl font-bold mb-4">Informasi Paket</h2>
                <div class="space-y-4">
                    <div>
                        <h3 class="text-xl font-bold text-gray-800">{{ $paket->nama_paket }}</h3>
                        <p class="text-gray-600">{{ $paket->keterangan }}</p>
                    </div>

                    <div class="flex justify-between items-center">
                        <span class="font-semibold">Harga per Hari:</span>
                        <span class="text-blue-600 font-bold text-lg">Rp {{ number_format($paket->harga, 0, ',', '.') }}</span>
                    </div>

                    <div class="flex justify-between items-center">
                        <span class="font-semibold">Minimum Order:</span>
                        <span class="bg-blue-100 text-blue-800 px-3 py-1 rounded-full text-sm font-medium">
                            {{ $paket->minimum_order ?? 1 }} hari
                        </span>
                    </div>

                    <div class="flex justify-between items-center">
                        <span class="font-semibold">Stok Tersedia:</span>
                        <span class="bg-green-100 text-green-800 px-3 py-1 rounded-full text-sm font-medium">
                            {{ $paket->stok }} unit
                        </span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Form Pemesanan -->
        <div class="bg-white rounded-lg shadow-lg p-6">
            <h2 class="text-2xl font-bold mb-6">Form Pemesanan</h2>
            
            <form action="{{ route('sewa.store') }}" method="POST" class="space-y-6">
                @csrf
                <input type="hidden" name="paket_id" value="{{ $paket->id }}">

                <!-- Tanggal Mulai -->
                <div>
                    <label for="tanggal_mulai" class="block text-sm font-medium text-gray-700 mb-2">Tanggal Mulai</label>
                    <input type="date" id="tanggal_mulai" name="tanggal_mulai" 
                           class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200"
                           required min="{{ date('Y-m-d') }}">
                </div>

                <!-- Tanggal Selesai -->
                <div>
                    <label for="tanggal_selesai" class="block text-sm font-medium text-gray-700 mb-2">Tanggal Selesai</label>
                    <input type="date" id="tanggal_selesai" name="tanggal_selesai" 
                           class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200"
                           required min="{{ date('Y-m-d') }}">
                </div>

                <!-- Kota Tujuan -->
                <div>
                    <label for="kota_id" class="block text-sm font-medium text-gray-700 mb-2">Kota Tujuan</label>
                    <select id="kota_id" name="kota_id" 
                            class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200"
                            required>
                        <option value="">Pilih Kota</option>
                        @foreach($paket->ongkirKota as $kota)
                            <option value="{{ $kota->id }}" data-ongkir="{{ $kota->biaya_ongkir }}">
                                {{ $kota->nama_kota }} - Rp {{ number_format($kota->biaya_ongkir, 0, ',', '.') }}
                            </option>
                        @endforeach
                    </select>
                </div>

                <!-- Alamat Lengkap -->
                <div>
                    <label for="lokasi" class="block text-sm font-medium text-gray-700 mb-2">Alamat Lengkap</label>
                    <textarea id="lokasi" name="lokasi" rows="3" 
                              class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200"
                              placeholder="Masukkan alamat lengkap lokasi acara" required></textarea>
                </div>

                <!-- Catatan -->
                <div>
                    <label for="catatan" class="block text-sm font-medium text-gray-700 mb-2">Catatan (Opsional)</label>
                    <textarea id="catatan" name="catatan" rows="3" 
                              class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200"
                              placeholder="Tambahkan catatan jika ada"></textarea>
                </div>

                <!-- Informasi Biaya -->
                <div class="border-t pt-4">
                    <div class="flex justify-between items-center mb-2">
                        <span class="font-semibold">Harga Sewa per Hari:</span>
                        <span class="text-lg font-bold" id="hargaPerHari">Rp {{ number_format($paket->harga, 0, ',', '.') }}</span>
                    </div>
                    <div class="flex justify-between items-center mb-2">
                        <span class="font-semibold">Durasi Sewa:</span>
                        <span class="font-bold" id="durasiSewa">0 hari</span>
                    </div>
                </div>

                <!-- Submit Button -->
                <div class="flex justify-end">
                    <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-lg">
                        Lanjutkan Pemesanan
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

@push('scripts')
<script>
document.addEventListener('DOMContentLoaded', function() {
    const tanggalMulai = document.getElementById('tanggal_mulai');
    const tanggalSelesai = document.getElementById('tanggal_selesai');
    const durasiSewa = document.getElementById('durasiSewa');
    
    function hitungDurasi() {
        if (tanggalMulai.value && tanggalSelesai.value) {
            const start = new Date(tanggalMulai.value);
            const end = new Date(tanggalSelesai.value);
            const diffTime = Math.abs(end - start);
            const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + 1;
            durasiSewa.textContent = diffDays + ' hari';
        }
    }

    tanggalMulai.addEventListener('change', function() {
        tanggalSelesai.min = this.value;
        hitungDurasi();
    });

    tanggalSelesai.addEventListener('change', hitungDurasi);
});
</script>
@endpush

@endsection 