import { useEffect } from "react"
import useStore from "../utils/store"
import { checkParams } from "../utils/lib"
import { useTranslation } from "react-i18next"

export const ParamsChecker = () => {
  const { i18n } = useTranslation()
  const setMode = useStore((state) => state.setMode)

  useEffect(() => {
    const params = checkParams(["mode", "language"])
    const mode = params.mode
    if (mode && ["teacher", "student"].includes(mode.toLowerCase())) {
      setMode(mode.toLowerCase() as "teacher" | "student")
    }
    if (
      params.language &&
      ["en", "es"].includes(params.language.toLowerCase())
    ) {
      i18n.changeLanguage(params.language.toLowerCase())
    }
  }, [])

  return <></>
}
