"use client"
import { createContext, type PropsWithChildren, useContext } from "react"

export type PageTypeContextType = PageTypeProviderProps["value"]

const PageTypeContext = createContext<PageTypeContextType>(null)

export const usePageType = () => {
  const context = useContext(PageTypeContext)
  if (!context) {
    throw new Error("usePageType must be used within PageTypeProvider")
  }
  return context
}

export type PageTypeProviderProps = {
  value: "city" | "country" | "overview" | null
}

export function PageTypeProvider({
  value,
  children,
}: PropsWithChildren<PageTypeProviderProps>) {
  return (
    <PageTypeContext.Provider value={value}>
      {children}
    </PageTypeContext.Provider>
  )
}
