"use client";

import { Search } from "lucide-react";
import { useRouter } from "next/navigation";
import { useState } from "react";

export default function BookingLookupPage() {
  const router = useRouter();
  const [bookingRef, setBookingRef] = useState("");
  const [error, setError] = useState("");

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault();
    const trimmed = bookingRef.trim().toUpperCase();
    if (!trimmed) {
      setError("Please enter a booking reference");
      return;
    }
    router.push(`/booking/detail?ref=${trimmed}`);
  };

  return (
    <div className="min-h-[calc(100vh-4rem)] flex items-center justify-center p-4 bg-gray-50 dark:bg-gray-900">
      <div className="w-full max-w-md">
        <div className="bg-white dark:bg-gray-800 rounded-lg shadow-lg p-8">
          <div className="text-center mb-6">
            <div className="inline-flex items-center justify-center w-16 h-16 bg-[rgb(20,113,76)] bg-opacity-10 rounded-full mb-4">
              <Search className="w-8 h-8 text-[rgb(20,113,76)]" />
            </div>
            <h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-2">
              Find Your Booking
            </h1>
            <p className="text-gray-600 dark:text-gray-400">
              Enter your booking reference (PNR) to view details
            </p>
          </div>

          <form onSubmit={handleSubmit}>
            <div className="mb-6">
              <label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                Booking Reference (PNR)
              </label>
              <input
                type="text"
                value={bookingRef}
                onChange={(e) => {
                  setBookingRef(e.target.value.toUpperCase());
                  setError("");
                }}
                placeholder="Enter your PNR"
                className="w-full px-4 py-3 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-[rgb(20,113,76)] focus:border-transparent dark:bg-gray-700 dark:text-white text-lg font-mono"
              />
              {error && (
                <p className="mt-2 text-sm text-red-600 dark:text-red-400">{error}</p>
              )}
            </div>

            <button
              type="submit"
              className="w-full bg-[rgb(20,113,76)] hover:bg-[rgb(16,89,60)] text-white font-medium py-3 px-4 rounded-lg transition-colors flex items-center justify-center gap-2"
            >
              <Search className="w-5 h-5" />
              Search Booking
            </button>
          </form>
        </div>
      </div>
    </div>
  );
}
