@extends('admin.layouts.app')

@section('title', 'Booking Details #' . $booking->id)

@section('content')
<div class="mb-6">
    <a href="{{ route('admin.bookings') }}" class="text-primary-600 hover:text-primary-700 font-medium mb-4 inline-block">
        ← Back to Bookings
    </a>
    <h1 class="text-3xl font-display font-bold text-gray-900">Booking #{{ $booking->id }}</h1>
</div>

<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
    <!-- Main Details -->
    <div class="lg:col-span-2 space-y-6">
        <!-- Guest Information -->
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="text-xl font-bold text-gray-900 mb-4">Guest Information</h2>
            <div class="grid grid-cols-2 gap-4">
                <div>
                    <p class="text-sm text-gray-600 mb-1">Full Name</p>
                    <p class="text-gray-900 font-medium">{{ $booking->guest_name }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Email Address</p>
                    <p class="text-gray-900">{{ $booking->guest_email }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Phone Number</p>
                    <p class="text-gray-900">{{ $booking->guest_phone }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Number of Guests</p>
                    <p class="text-gray-900">
                        {{ $booking->adults }} Adults
                        @if($booking->children > 0)
                        , {{ $booking->children }} Children
                        @endif
                    </p>
                </div>
            </div>
        </div>

        <!-- Booking Details -->
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="text-xl font-bold text-gray-900 mb-4">Booking Details</h2>
            <div class="grid grid-cols-2 gap-4">
                <div>
                    <p class="text-sm text-gray-600 mb-1">Room Type</p>
                    <p class="text-gray-900 font-medium">{{ $booking->room->name }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Price per Night</p>
                    <p class="text-gray-900">NPR {{ number_format($booking->room->price_per_night) }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Check-In Date</p>
                    <p class="text-gray-900">{{ $booking->check_in->format('l, F j, Y') }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Check-Out Date</p>
                    <p class="text-gray-900">{{ $booking->check_out->format('l, F j, Y') }}</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Number of Nights</p>
                    <p class="text-gray-900 font-medium">{{ $booking->check_in->diffInDays($booking->check_out) }} nights</p>
                </div>
                <div>
                    <p class="text-sm text-gray-600 mb-1">Estimated Total</p>
                    <p class="text-gray-900 font-bold text-lg">
                        NPR {{ number_format($booking->room->price_per_night * $booking->check_in->diffInDays($booking->check_out)) }}
                    </p>
                </div>
            </div>
        </div>

        <!-- Special Requests -->
        @if($booking->special_requests)
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="text-xl font-bold text-gray-900 mb-4">Special Requests</h2>
            <p class="text-gray-700 whitespace-pre-line">{{ $booking->special_requests }}</p>
        </div>
        @endif

        <!-- Booking Timeline -->
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h2 class="text-xl font-bold text-gray-900 mb-4">Booking Timeline</h2>
            <div class="space-y-3">
                <div class="flex items-center gap-3">
                    <div class="w-2 h-2 bg-primary-600 rounded-full"></div>
                    <p class="text-sm text-gray-600">Booking Created: <span class="text-gray-900 font-medium">{{ $booking->created_at->format('M d, Y H:i') }}</span></p>
                </div>
                <div class="flex items-center gap-3">
                    <div class="w-2 h-2 bg-gray-400 rounded-full"></div>
                    <p class="text-sm text-gray-600">Last Updated: <span class="text-gray-900 font-medium">{{ $booking->updated_at->format('M d, Y H:i') }}</span></p>
                </div>
            </div>
        </div>
    </div>

    <!-- Sidebar Actions -->
    <div class="lg:col-span-1">
        <!-- Status Card -->
        <div class="bg-white rounded-xl shadow-sm p-6 mb-6">
            <h3 class="text-lg font-bold text-gray-900 mb-4">Booking Status</h3>
            
            @php
                $statusColors = [
                    'pending' => 'bg-yellow-100 text-yellow-800 border-yellow-200',
                    'confirmed' => 'bg-green-100 text-green-800 border-green-200',
                    'checked_in' => 'bg-blue-100 text-blue-800 border-blue-200',
                    'checked_out' => 'bg-gray-100 text-gray-800 border-gray-200',
                    'cancelled' => 'bg-red-100 text-red-800 border-red-200',
                ];
            @endphp
            
            <div class="mb-4">
                <span class="inline-block px-4 py-2 text-sm font-semibold rounded-lg border-2 {{ $statusColors[$booking->status] ?? 'bg-gray-100 text-gray-800' }}">
                    {{ ucfirst(str_replace('_', ' ', $booking->status)) }}
                </span>
            </div>

            <form method="POST" action="{{ route('admin.bookings.update-status', $booking->id) }}">
                @csrf
                <label class="text-sm font-medium text-gray-700 mb-2 block">Update Status</label>
                <select name="status" class="form-input mb-4">
                    <option value="pending" {{ $booking->status == 'pending' ? 'selected' : '' }}>Pending</option>
                    <option value="confirmed" {{ $booking->status == 'confirmed' ? 'selected' : '' }}>Confirmed</option>
                    <option value="checked_in" {{ $booking->status == 'checked_in' ? 'selected' : '' }}>Checked In</option>
                    <option value="checked_out" {{ $booking->status == 'checked_out' ? 'selected' : '' }}>Checked Out</option>
                    <option value="cancelled" {{ $booking->status == 'cancelled' ? 'selected' : '' }}>Cancelled</option>
                </select>
                <button type="submit" class="btn btn-primary w-full">Update Status</button>
            </form>
        </div>

        <!-- Actions Card -->
        <div class="bg-white rounded-xl shadow-sm p-6">
            <h3 class="text-lg font-bold text-gray-900 mb-4">Actions</h3>
            <div class="space-y-3">
                <a href="mailto:{{ $booking->guest_email }}" class="btn btn-outline w-full flex items-center justify-center gap-2">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
                    </svg>
                    Email Guest
                </a>

                <a href="tel:{{ $booking->guest_phone }}" class="btn btn-outline w-full flex items-center justify-center gap-2">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"/>
                    </svg>
                    Call Guest
                </a>

                <form method="POST" action="{{ route('admin.bookings.delete', $booking->id) }}" onsubmit="return confirm('Are you sure you want to delete this booking?');">
                    @csrf
                    @method('DELETE')
                    <button type="submit" class="btn bg-red-50 text-red-600 hover:bg-red-100 w-full flex items-center justify-center gap-2">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
                        </svg>
                        Delete Booking
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection

