import { createContext, useContext, useState } from 'react'
import type { ReactNode } from 'react'

type Lang = 'fa' | 'en'
type LangCtx = { lang: Lang; toggle: () => void }

const LangContext = createContext<LangCtx>({ lang: 'fa', toggle: () => {} })

export function LangProvider({ children }: { children: ReactNode }) {
  const [lang, setLang] = useState<Lang>('fa')
  const toggle = () => setLang(l => (l === 'fa' ? 'en' : 'fa'))
  return <LangContext.Provider value={{ lang, toggle }}>{children}</LangContext.Provider>
}

export function useLang() {
  return useContext(LangContext)
}
