<?php
if (Auth('admin')->User()->dashboard_style == 'light') {
    $text = 'dark';
    $bg = 'light';
} else {
    $bg = 'dark';
    $text = 'light';
}
?>
@extends('layouts.app')

@section('title', $title ?? 'Flight Booking Details')

@section('content')
    @include('admin.topmenu')
    @include('admin.sidebar')
    <div class="main-panel">
        <div class="content">
            <div class="page-inner">
                <div class="mt-2 mb-4">
                    <h1 class="title1 text-{{ $text }}">{{ $title ?? 'Flight Booking Details' }}</h1>
                    <p class="text-muted mt-1">
                        Booking ID: FB-{{ str_pad($booking->id, 6, '0', STR_PAD_LEFT) }} |
                        Submitted {{ $booking->formatted_created_at }}
                    </p>
                </div>

                <x-danger-alert />
                <x-success-alert />

                <!-- Navigation Buttons -->
                <div class="mb-4">
                    <a href="{{ route('admin.flight-bookings.index') }}" class="btn btn-secondary">
                        <i class="fas fa-arrow-left mr-2"></i>Back to Flight Bookings
                    </a>

                    @if($booking->status === 'unread')
                        <form method="POST" action="{{ route('admin.flight-bookings.update-status', $booking) }}" class="d-inline ml-2">
                            @csrf
                            @method('PATCH')
                            <input type="hidden" name="status" value="read">
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-envelope-open mr-2"></i>Mark as Read
                            </button>
                        </form>
                    @endif

                    @if($booking->status !== 'replied')
                        <form method="POST" action="{{ route('admin.flight-bookings.update-status', $booking) }}" class="d-inline ml-2">
                            @csrf
                            @method('PATCH')
                            <input type="hidden" name="status" value="replied">
                            <button type="submit" class="btn btn-success">
                                <i class="fas fa-reply mr-2"></i>Mark as Replied
                            </button>
                        </form>
                    @endif

                    <form method="POST" action="{{ route('admin.flight-bookings.destroy', $booking) }}" class="d-inline ml-2">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn btn-danger"
                                onclick="return confirm('Are you sure you want to delete this flight booking? This action cannot be undone.')">
                            <i class="fas fa-trash mr-2"></i>Delete Booking
                        </button>
                    </form>
                </div>

                <!-- Status Badge -->
                <div class="mb-4">
                    @if($booking->status === 'unread')
                        <span class="badge badge-warning badge-lg">
                            <i class="fas fa-envelope mr-1"></i>Unread - New Booking
                        </span>
                    @elseif($booking->status === 'read')
                        <span class="badge badge-info badge-lg">
                            <i class="fas fa-envelope-open mr-1"></i>Read - Under Review
                        </span>
                    @elseif($booking->status === 'replied')
                        <span class="badge badge-success badge-lg">
                            <i class="fas fa-reply mr-1"></i>Replied - Processed
                        </span>
                    @elseif($booking->status === 'archived')
                        <span class="badge badge-secondary badge-lg">
                            <i class="fas fa-archive mr-1"></i>Archived
                        </span>
                    @endif
                </div>

                <!-- Main Content Row -->
                <div class="row">
                    <!-- Passenger Information -->
                    <div class="col-md-6 mb-4">
                        <div class="card h-100">
                            <div class="card-header bg-primary text-white">
                                <h5 class="mb-0">
                                    <i class="fas fa-user mr-2"></i>Passenger Information
                                </h5>
                            </div>
                            <div class="card-body">
                                <div class="row mb-3">
                                    <div class="col-sm-4 font-weight-bold text-{{ $text }}">Name:</div>
                                    <div class="col-sm-8 text-{{ $text }}">{{ $booking->fname }}</div>
                                </div>
                                <div class="row mb-3">
                                    <div class="col-sm-4 font-weight-bold text-{{ $text }}">Email:</div>
                                    <div class="col-sm-8">
                                        <a href="mailto:{{ $booking->email }}" class="text-primary">{{ $booking->email }}</a>
                                    </div>
                                </div>
                                <div class="row mb-3">
                                    <div class="col-sm-4 font-weight-bold text-{{ $text }}">Phone:</div>
                                    <div class="col-sm-8">
                                        <a href="tel:{{ $booking->phone }}" class="text-primary">{{ $booking->phone }}</a>
                                    </div>
                                </div>
                                @if($booking->passengers)
                                    <div class="row mb-3">
                                        <div class="col-sm-4 font-weight-bold text-{{ $text }}">Passengers:</div>
                                        <div class="col-sm-8 text-{{ $text }}">{{ $booking->passengers }}</div>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>

                    <!-- Military Information -->
                    <div class="col-md-6 mb-4">
                        <div class="card h-100">
                            <div class="card-header bg-success text-white">
                                <h5 class="mb-0">
                                    <i class="fas fa-medal mr-2"></i>Military Information
                                </h5>
                            </div>
                            <div class="card-body">
                                @if($booking->rank)
                                    <div class="row mb-3">
                                        <div class="col-sm-4 font-weight-bold text-{{ $text }}">Rank:</div>
                                        <div class="col-sm-8">
                                            <span class="badge badge-secondary">{{ $booking->rank }}</span>
                                        </div>
                                    </div>
                                @endif
                                @if($booking->service_branch)
                                    <div class="row mb-3">
                                        <div class="col-sm-4 font-weight-bold text-{{ $text }}">Branch:</div>
                                        <div class="col-sm-8 text-{{ $text }}">{{ $booking->service_branch }}</div>
                                    </div>
                                @endif
                                @if($booking->unit)
                                    <div class="row mb-3">
                                        <div class="col-sm-4 font-weight-bold text-{{ $text }}">Unit:</div>
                                        <div class="col-sm-8 text-{{ $text }}">{{ $booking->unit }}</div>
                                    </div>
                                @endif
                                @if($booking->military_status)
                                    <div class="row mb-3">
                                        <div class="col-sm-4 font-weight-bold text-{{ $text }}">Status:</div>
                                        <div class="col-sm-8 text-{{ $text }}">{{ $booking->military_status }}</div>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Flight Details -->
                <div class="row">
                    <div class="col-md-12 mb-4">
                        <div class="card">
                            <div class="card-header bg-info text-white">
                                <h5 class="mb-0">
                                    <i class="fas fa-plane mr-2"></i>Flight Details
                                </h5>
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    @if($booking->departure_city)
                                        <div class="col-md-3 mb-3">
                                            <div class="font-weight-bold text-{{ $text }} mb-1">Departure City:</div>
                                            <span class="badge badge-info badge-lg">{{ $booking->departure_city }}</span>
                                        </div>
                                    @endif
                                    @if($booking->destination_city)
                                        <div class="col-md-3 mb-3">
                                            <div class="font-weight-bold text-{{ $text }} mb-1">Destination City:</div>
                                            <span class="badge badge-success badge-lg">{{ $booking->destination_city }}</span>
                                        </div>
                                    @endif
                                    @if($booking->departure_date)
                                        <div class="col-md-3 mb-3">
                                            <div class="font-weight-bold text-{{ $text }} mb-1">Departure Date:</div>
                                            <div class="text-{{ $text }}">
                                                <i class="fas fa-calendar mr-1"></i>
                                                {{ date('M d, Y', strtotime($booking->departure_date)) }}
                                            </div>
                                        </div>
                                    @endif
                                    @if($booking->return_date)
                                        <div class="col-md-3 mb-3">
                                            <div class="font-weight-bold text-{{ $text }} mb-1">Return Date:</div>
                                            <div class="text-{{ $text }}">
                                                <i class="fas fa-calendar mr-1"></i>
                                                {{ date('M d, Y', strtotime($booking->return_date)) }}
                                            </div>
                                        </div>
                                    @endif
                                </div>

                                @if($booking->trip_type)
                                    <div class="row mt-3">
                                        <div class="col-md-6">
                                            <div class="font-weight-bold text-{{ $text }} mb-1">Trip Type:</div>
                                            <span class="badge badge-primary">{{ ucfirst($booking->trip_type) }}</span>
                                        </div>
                                        @if($booking->payment_preference)
                                            <div class="col-md-6">
                                                <div class="font-weight-bold text-{{ $text }} mb-1">Payment Preference:</div>
                                                <span class="badge badge-warning">{{ ucfirst($booking->payment_preference) }}</span>
                                            </div>
                                        @endif
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Message/Special Requests -->
                @if($booking->message)
                    <div class="row">
                        <div class="col-md-12 mb-4">
                            <div class="card">
                                <div class="card-header bg-warning text-dark">
                                    <h5 class="mb-0">
                                        <i class="fas fa-comment mr-2"></i>Special Requests / Additional Information
                                    </h5>
                                </div>
                                <div class="card-body">
                                    <div class="text-{{ $text }}" style="white-space: pre-wrap;">{{ $booking->message }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                @endif

                <!-- Submission Details -->
                <div class="row">
                    <div class="col-md-12 mb-4">
                        <div class="card">
                            <div class="card-header bg-secondary text-white">
                                <h5 class="mb-0">
                                    <i class="fas fa-clock mr-2"></i>Submission Details
                                </h5>
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-4 mb-3">
                                        <div class="font-weight-bold text-{{ $text }} mb-1">Submitted:</div>
                                        <div class="text-{{ $text }}">
                                            <i class="fas fa-calendar-plus mr-1"></i>
                                            {{ $booking->created_at->format('M d, Y g:i A') }}
                                        </div>
                                    </div>
                                    <div class="col-md-4 mb-3">
                                        <div class="font-weight-bold text-{{ $text }} mb-1">Last Updated:</div>
                                        <div class="text-{{ $text }}">
                                            <i class="fas fa-calendar-check mr-1"></i>
                                            {{ $booking->updated_at->format('M d, Y g:i A') }}
                                        </div>
                                    </div>
                                    <div class="col-md-4 mb-3">
                                        <div class="font-weight-bold text-{{ $text }} mb-1">Booking ID:</div>
                                        <div class="text-{{ $text }}">
                                            <i class="fas fa-id-badge mr-1"></i>
                                            FB-{{ str_pad($booking->id, 6, '0', STR_PAD_LEFT) }}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Action Buttons at Bottom -->
                <div class="text-center mb-4">
                    <a href="{{ route('admin.flight-bookings.index') }}" class="btn btn-secondary btn-lg">
                        <i class="fas fa-arrow-left mr-2"></i>Back to Flight Bookings
                    </a>
                    <a href="mailto:{{ $booking->email }}" class="btn btn-primary btn-lg ml-2">
                        <i class="fas fa-envelope mr-2"></i>Reply to Request
                    </a>
                </div>
            </div>
        </div>
    </div>

@if(session('success'))
    <script>
        Swal.fire({
            icon: 'success',
            title: 'Success!',
            text: '{{ session('success') }}',
            confirmButtonColor: '#28a745'
        });
    </script>
@endif

@if(session('error'))
    <script>
        Swal.fire({
            icon: 'error',
            title: 'Error!',
            text: '{{ session('error') }}',
            confirmButtonColor: '#dc3545'
        });
    </script>
@endif
@endsection
