diff --git a/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightSearchForm.tsx b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightSearchForm.tsx new file mode 100644 index 0000000..3993770 --- /dev/null +++ b/src/app/(client-components)/(HeroSearchForm)/(flight-search-form)/FlightSearchForm.tsx @@ -0,0 +1,246 @@ +"use client"; + +import React, { FC, useState } from "react"; +import LocationInput from "../LocationInput"; +import { Popover, Transition } from "@headlessui/react"; +import { ChevronDownIcon } from "@heroicons/react/24/solid"; +import { Fragment } from "react"; +import NcInputNumber from "@/components/NcInputNumber"; +import FlightDateRangeInput from "./FlightDateRangeInput"; +import { GuestsObject } from "../../type"; + +export interface FlightSearchFormProps {} + +const flightClass = [ + { + name: "Economy", + href: "##", + }, + { + name: "Business", + href: "##", + }, + { + name: "Multiple", + href: "##", + }, +]; + +export type TypeDropOffLocationType = "roundTrip" | "oneWay" | ""; + +const FlightSearchForm: FC = ({}) => { + const [dropOffLocationType, setDropOffLocationType] = + useState("roundTrip"); + const [flightClassState, setFlightClassState] = useState("Economy"); + + const [guestAdultsInputValue, setGuestAdultsInputValue] = useState(2); + const [guestChildrenInputValue, setGuestChildrenInputValue] = useState(1); + const [guestInfantsInputValue, setGuestInfantsInputValue] = useState(1); + + const handleChangeData = (value: number, type: keyof GuestsObject) => { + let newValue = { + guestAdults: guestAdultsInputValue, + guestChildren: guestChildrenInputValue, + guestInfants: guestInfantsInputValue, + }; + if (type === "guestAdults") { + setGuestAdultsInputValue(value); + newValue.guestAdults = value; + } + if (type === "guestChildren") { + setGuestChildrenInputValue(value); + newValue.guestChildren = value; + } + if (type === "guestInfants") { + setGuestInfantsInputValue(value); + newValue.guestInfants = value; + } + }; + + const totalGuests = + guestChildrenInputValue + guestAdultsInputValue + guestInfantsInputValue; + + const renderGuest = () => { + return ( + + {({ open }) => ( + <> + + {`${totalGuests || ""} Guests`} + + + + handleChangeData(value, "guestAdults")} + max={10} + min={1} + label="Adults" + desc="Ages 13 or above" + /> + handleChangeData(value, "guestChildren")} + max={4} + label="Children" + desc="Ages 2–12" + /> + + handleChangeData(value, "guestInfants")} + max={4} + label="Infants" + desc="Ages 0–2" + /> + + + + )} + + ); + }; + + const renderSelectClass = () => { + return ( + + {({ open, close }) => ( + <> + + {`${flightClassState}`} + + + + + + + + )} + + ); + }; + + const renderRadioBtn = () => { + return ( +
+
setDropOffLocationType("roundTrip")} + > + Round-trip +
+
setDropOffLocationType("oneWay")} + > + One-way +
+ +
+ +
+ {renderSelectClass()} +
+
+ {renderGuest()} +
+
+ ); + }; + + const renderForm = () => { + return ( +
+ {renderRadioBtn()} +
+ +
+ +
+ +
+
+ ); + }; + + return renderForm(); +}; + +export default FlightSearchForm;