import { batchRequest } from "@/lib/graphql/batchRequest"
import {
  GetDaDeEnUrls,
  GetFiNoSvUrls,
} from "@/lib/graphql/Query/LanguageSwitcherCurrent.graphql"

import Desktop from "@/components/Current/Header/LanguageSwitcher/Desktop"
import Mobile from "@/components/Current/Header/LanguageSwitcher/Mobile"

import styles from "./page.module.css"

import { LangParams, PageArgs } from "@/types/params"
import { LanguageSwitcherData } from "@/types/requests/languageSwitcher"

export default async function LanguageSwitcher({
  params,
  searchParams,
}: PageArgs<
  LangParams,
  {
    uid: string
    uri: string
  }
>) {
  if (!searchParams.uid) {
    return null
  }

  const variables = {
    uid: searchParams.uid,
  }

  const { data: urls } = await batchRequest<LanguageSwitcherData>([
    {
      document: GetDaDeEnUrls,
      variables,
    },
    {
      document: GetFiNoSvUrls,
      variables,
    },
  ])

  return (
    <>
      <section className={styles.desktop}>
        <Desktop currentLanguage={params.lang} urls={urls} />
      </section>
      <section className={styles.mobile}>
        <Mobile currentLanguage={params.lang} urls={urls} />
      </section>
    </>
  )
}
