@extends('layouts.app')

@section('title', 'Detail Pemesanan - INUFA')

@section('header', 'Detail Pemesanan')

@section('content')
<div class="bg-white rounded-lg shadow-lg overflow-hidden">
    <!-- Header Detail -->
    <div class="bg-blue-800 text-white p-4">
        <div class="flex justify-between items-center">
            <h2 class="text-lg font-bold">Kode Pemesanan: #{{ $sewa->id }}</h2>
            <span class="px-3 py-1 rounded-full text-sm font-semibold 
            {{ $sewa->status == 'pending' ? 'bg-yellow-200 text-yellow-800' : 
               ($sewa->status == 'confirmed' ? 'bg-blue-200 text-blue-800' : 
               ($sewa->status == 'ongoing' ? 'bg-purple-200 text-purple-800' : 
               ($sewa->status == 'completed' ? 'bg-green-200 text-green-800' : 
               'bg-red-200 text-red-800'))) }}">
                {{ ucfirst($sewa->status) }}
            </span>
        </div>
        <p class="text-sm opacity-80 mt-1">Tanggal Pemesanan: {{ $sewa->created_at->format('d F Y, H:i') }}</p>
    </div>
    
    <!-- Informasi Paket -->
    <div class="p-6 border-b border-gray-200">
        <h3 class="text-lg font-semibold mb-3">Informasi Paket</h3>
        <div class="flex flex-col md:flex-row">
            <div class="md:w-1/4">
                <img src="{{ asset('storage/' . $sewa->paket->gambar) }}" 
                     alt="{{ $sewa->paket->nama }}" 
                     class="w-full h-48 object-cover rounded-lg" 
                     onerror="this.src='https://via.placeholder.com/300x150?text=Paket+Sound+System'">
            </div>
            <div class="md:w-3/4 md:pl-6 mt-4 md:mt-0">
                <h4 class="text-xl font-bold">{{ $sewa->paket->nama }}</h4>
                <p class="text-gray-600 mt-2">{{ $sewa->paket->deskripsi }}</p>
                <div class="mt-4 grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <p class="text-sm text-gray-500">Tanggal Mulai</p>
                        <p class="font-medium">{{ date('d F Y', strtotime($sewa->tanggal_mulai)) }}</p>
                    </div>
                    <div>
                        <p class="text-sm text-gray-500">Tanggal Selesai</p>
                        <p class="font-medium">{{ date('d F Y', strtotime($sewa->tanggal_selesai)) }}</p>
                    </div>
                    <div>
                        <p class="text-sm text-gray-500">Lokasi Acara</p>
                        <p class="font-medium">{{ $sewa->lokasi }}</p>
                    </div>
                    <div>
                        <p class="text-sm text-gray-500">Durasi</p>
                        <p class="font-medium">
                            <?php
                                $tglMulai = new DateTime($sewa->tanggal_mulai);
                                $tglSelesai = new DateTime($sewa->tanggal_selesai);
                                $selisih = $tglMulai->diff($tglSelesai);
                                echo ($selisih->days + 1) . ' hari';
                            ?>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Detail Biaya -->
    <div class="p-6 border-b border-gray-200">
        <h3 class="text-lg font-semibold mb-3">Detail Biaya</h3>
        <div class="space-y-2">
            <div class="flex justify-between">
                <span>Harga Paket (per hari)</span>
                <span>Rp {{ number_format($sewa->paket->harga, 0, ',', '.') }}</span>
            </div>
            <div class="flex justify-between">
                <span>Durasi</span>
                <span>
                    <?php
                        $tglMulai = new DateTime($sewa->tanggal_mulai);
                        $tglSelesai = new DateTime($sewa->tanggal_selesai);
                        $selisih = $tglMulai->diff($tglSelesai);
                        echo ($selisih->days + 1) . ' hari';
                    ?>
                </span>
            </div>
            <div class="flex justify-between font-bold text-lg pt-2 border-t border-gray-200 mt-2">
                <span>Total</span>
                <span>Rp {{ number_format($sewa->total_harga, 0, ',', '.') }}</span>
            </div>
        </div>
    </div>
    
    <!-- Tombol Aksi -->
    <div class="p-6 flex justify-between">
        <a href="{{ route('riwayat') }}" class="bg-gray-300 text-gray-800 py-2 px-4 rounded hover:bg-gray-400 transition-colors">
            Kembali
        </a>
        @if($sewa->status == 'pending')
        <form action="{{ route('riwayat.cancel', $sewa->id) }}" method="POST" onsubmit="return confirm('Apakah Anda yakin ingin membatalkan pesanan ini?')">
            @csrf
            @method('PUT')
            <button type="submit" class="bg-red-600 text-white py-2 px-4 rounded hover:bg-red-700 transition-colors">
                Batalkan Pesanan
            </button>
        </form>
        @endif
    </div>
</div>
@endsection 