import type { BookingWidgetType } from "@/types/components/bookingWidget"
import type { Location, Locations } from "@/types/trpc/routers/hotel/locations"

export interface BookingWidgetFormProps {
  locations: Locations
  type?: BookingWidgetType
  setIsOpen: (isOpen: boolean) => void
}

export interface BookingWidgetFormContentProps {
  locations: Locations
  formId: string
}

export enum ActionType {
  CLEAR_HISTORY_LOCATIONS = "CLEAR_HISTORY_LOCATIONS",
  CLEAR_SEARCH_LOCATIONS = "CLEAR_SEARCH_LOCATIONS",
  SEARCH_LOCATIONS = "SEARCH_LOCATIONS",
  SELECT_ITEM = "SELECT_ITEM",
  SET_STORAGE_DATA = "SET_STORAGE_DATA",
}

interface ClearHistoryLocationsAction {
  type: ActionType.CLEAR_HISTORY_LOCATIONS
}

interface ClearSearchLocationsAction {
  type: ActionType.CLEAR_SEARCH_LOCATIONS
}

interface SearchLocationsAction {
  payload: {
    search: string
  }
  type: ActionType.SEARCH_LOCATIONS
}

interface SetItemAction {
  payload: {
    location: Location
    searchHistory: Locations
  }
  type: ActionType.SELECT_ITEM
}

interface SetStorageData {
  payload: {
    searchData: Location
    searchHistory: Locations
  }
  type: ActionType.SET_STORAGE_DATA
}

export type Action =
  | ClearHistoryLocationsAction
  | ClearSearchLocationsAction
  | SearchLocationsAction
  | SetItemAction
  | SetStorageData

export interface State {
  defaultLocations: Locations
  locations: Locations
  search: string
  searchData: Location | undefined
  searchHistory: Locations | null
}

export interface InitState extends Pick<State, "defaultLocations"> {}
