﻿import React from 'react';
import { Head, Link } from '@inertiajs/react';
import { PublicLayout } from '@/Layouts/PublicLayout';
import { CurrencyPrice } from '@/Components/CurrencyPrice';
import { 
    CheckCircle, Calendar, Users, MapPin, 
    Printer, ArrowRight, ShieldCheck, Phone, Sparkles 
} from 'lucide-react';

interface Props {
    booking: any;
}

export default function Confirmation({ booking }: Props) {
    const isPaid = booking.payment_status === 'Paid';

    return (
        <PublicLayout>
            <Head title={`Booking Confirmed — ${booking.booking_reference}`} />

            <section className="py-28 bg-[#1A1A1A] text-[#FBF9F5] border-b border-[#C5A880]/20 text-center">
                <div className="max-w-3xl mx-auto px-4 sm:px-6 lg:px-8 space-y-4">
                    <div className="w-16 h-16 rounded-full bg-[#C5A880]/20 border border-[#C5A880] text-[#C5A880] flex items-center justify-center mx-auto mb-2">
                        <CheckCircle className="h-8 w-8" />
                    </div>
                    <span className="text-xs uppercase tracking-[0.3em] text-[#C5A880] font-semibold">
                        Reservation Confirmed
                    </span>
                    <h1 className="font-serif text-3xl sm:text-5xl font-light text-white">
                        We Look Forward to Welcoming You.
                    </h1>
                    <p className="text-sm text-gray-300 font-light max-w-xl mx-auto leading-relaxed">
                        A booking confirmation voucher has been generated. Your reservation is securely registered with the Primon front desk in Naalya.
                    </p>
                </div>
            </section>

            <section className="py-16 bg-[#FBF9F5]">
                <div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 space-y-10">
                    {/* Booking Card */}
                    <div className="bg-[#F3EFEA] rounded-3xl p-8 sm:p-12 border border-[#C5A880]/20 shadow-xl space-y-8">
                        <div className="flex flex-col sm:flex-row sm:items-center justify-between pb-6 border-b border-gray-300 gap-4">
                            <div>
                                <span className="text-[10px] uppercase tracking-wider text-gray-500 font-semibold block">
                                    Reservation Code
                                </span>
                                <h3 className="font-serif text-3xl font-bold text-[#1A1A1A] tracking-wider">
                                    {booking.booking_reference}
                                </h3>
                            </div>
                            <div className="flex items-center gap-3">
                                <span className={`px-4 py-1.5 rounded-full text-xs font-bold uppercase tracking-wider ${
                                    isPaid ? 'bg-green-100 text-green-800 border border-green-300' : 'bg-amber-100 text-amber-800 border border-amber-300'
                                }`}>
                                    {isPaid ? '✓ Paid & Guaranteed' : 'Payment Due at Check-In'}
                                </span>
                            </div>
                        </div>

                        {/* Stay Specs */}
                        <div className="grid grid-cols-1 sm:grid-cols-3 gap-6 text-xs sm:text-sm text-gray-800">
                            <div>
                                <strong className="text-gray-500 font-normal uppercase text-[10px] block mb-1">Room & Suite</strong>
                                <span className="font-semibold text-base text-[#1A1A1A] block">{booking.room_type?.name}</span>
                                <span className="text-xs text-gray-600">{booking.room_type?.bed_type}</span>
                            </div>
                            <div>
                                <strong className="text-gray-500 font-normal uppercase text-[10px] block mb-1">Stay Dates</strong>
                                <span className="font-semibold text-base text-[#1A1A1A] block">{booking.check_in_date}</span>
                                <span className="text-xs text-gray-600">to {booking.check_out_date} (Check-in 14:00)</span>
                            </div>
                            <div>
                                <strong className="text-gray-500 font-normal uppercase text-[10px] block mb-1">Guest Information</strong>
                                <span className="font-semibold text-base text-[#1A1A1A] block">{booking.guest?.full_name}</span>
                                <span className="text-xs text-gray-600">{booking.guest?.email}</span>
                            </div>
                        </div>

                        {/* Add-ons if any */}
                        {booking.add_ons && booking.add_ons.length > 0 && (
                            <div className="p-4 rounded-2xl bg-white border border-[#C5A880]/30 space-y-2">
                                <span className="text-[10px] uppercase tracking-wider text-gray-500 font-semibold block">
                                    Reserved Add-On Extras:
                                </span>
                                <div className="space-y-1 text-xs text-gray-700">
                                    {booking.add_ons.map((ao: any) => (
                                        <div key={ao.id} className="flex justify-between">
                                            <span>• {ao.name} (x{ao.quantity})</span>
                                            <span className="font-semibold"><CurrencyPrice amountUsd={ao.total_price_usd} /></span>
                                        </div>
                                    ))}
                                </div>
                            </div>
                        )}

                        {/* Grand Total */}
                        <div className="pt-6 border-t border-gray-300 flex items-baseline justify-between">
                            <div>
                                <span className="text-xs text-gray-500 block">Total Amount (Taxes & Fees Included)</span>
                                <span className="text-xs text-gray-500">Paid: <CurrencyPrice amountUsd={booking.paid_total} /> • Balance: <CurrencyPrice amountUsd={booking.balance_due} /></span>
                            </div>
                            <span className="font-serif text-3xl font-bold text-[#C5A880]">
                                <CurrencyPrice amountUsd={booking.grand_total} />
                            </span>
                        </div>

                        {/* Action Buttons */}
                        <div className="pt-6 border-t border-gray-300 flex flex-col sm:flex-row items-center justify-between gap-4">
                            <a
                                href={`/booking/voucher/${booking.booking_reference}`}
                                target="_blank"
                                rel="noopener noreferrer"
                                className="w-full sm:w-auto border border-[#1A1A1A] hover:bg-[#1A1A1A] hover:text-[#FBF9F5] text-[#1A1A1A] px-6 py-3 rounded-full text-xs font-bold uppercase tracking-widest transition-all flex items-center justify-center gap-2"
                            >
                                <Printer className="h-4 w-4" />
                                <span>Print / Download Voucher</span>
                            </a>

                            <Link
                                href={`/account?reference=${booking.booking_reference}`}
                                className="w-full sm:w-auto bg-[#C5A880] hover:bg-[#DFC7A5] text-[#1A1A1A] px-8 py-3 rounded-full text-xs font-bold uppercase tracking-widest transition-all text-center shadow-md"
                            >
                                Manage Pre-Arrival in Guest Portal →
                            </Link>
                        </div>
                    </div>
                </div>
            </section>
        </PublicLayout>
    );
}
