"use client";

import { useState } from "react";
import { useRouter } from "next/navigation";
import { MapPin, Search } from "lucide-react";
import { Button } from "@/components/ui/button";

export function HeroSearch() {
  const router = useRouter();
  const [query, setQuery] = useState("");

  const handleSearch = (e: React.FormEvent) => {
    e.preventDefault();
    
    if (query.trim()) {
      // Redirect to tours page with search query
      router.push(`/tours?q=${encodeURIComponent(query.trim())}`);
    } else {
      // If empty, just go to tours page
      router.push("/tours");
    }
  };

  return (
    <form onSubmit={handleSearch} className="bg-white rounded-lg shadow-2xl p-2 flex flex-col md:flex-row gap-2 items-stretch">
      <div className="flex items-center gap-3 px-4 py-3 border-2 border-transparent hover:border-blue-500 rounded-md transition-colors flex-1">
        <MapPin className="h-5 w-5 text-gray-400 shrink-0" />
        <input
          type="text"
          placeholder="What do you want to experience?"
          value={query}
          onChange={(e) => setQuery(e.target.value)}
          className="flex-1 outline-none text-gray-700 placeholder:text-gray-400"
        />
      </div>
      
      <Button 
        type="submit"
        size="lg" 
        className="w-full md:w-auto px-8 bg-blue-600 hover:bg-blue-700"
      >
        <Search className="h-5 w-5 mr-2" />
        Search
      </Button>
    </form>
  );
}
