import { batchRequest } from "@/lib/graphql/batchRequest"
import {
  GetDaDeEnUrlsCurrentBlocksPage,
  GetFiNoSvUrlsCurrentBlocksPage,
} 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, UIDParams, UriParams } from "@/types/params"
import { LanguageSwitcherData } from "@/types/requests/languageSwitcher"

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

  const variables = {
    uid: searchParams.uid,
  }

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

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