import { GetHeader } from "@/lib/graphql/Query/Header.graphql"
import { request } from "@/lib/graphql/request"

import Logo from "./Logo"

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

import type { LangParams } from "@/types/params"
import { HeaderQueryData } from "@/types/requests/header"

export default async function Header({ lang }: LangParams) {
  const { data } = await request<HeaderQueryData>(GetHeader, {
    locale: lang,
  })

  if (
    !data.all_header.items.length ||
    !data.all_header.items?.[0].logoConnection.totalCount
  ) {
    return null
  }

  const logo = data.all_header.items[0].logoConnection.edges[0]

  return (
    <header className={styles.header}>
      <Logo
        title={logo.node.title}
        height={logo.node.dimension.height}
        width={logo.node.dimension.width}
        src={logo.node.url}
      />
    </header>
  )
}
