import Preamble from "@/components/TempDesignSystem/Text/Preamble"
import Title from "@/components/TempDesignSystem/Text/Title"

import SectionLink from "../Link"

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

import type { HeadingProps } from "@/components/TempDesignSystem/Text/Title/title"

export type HeaderProps = {
  link?: {
    href: string
    text: string
  }
  preamble?: string | null
  textTransform?: HeadingProps["textTransform"]
  title?: string | null
  headingLevel?: HeadingProps["level"]
  headingAs?: HeadingProps["as"]
}

export default function SectionHeader({
  link,
  preamble,
  title,
  textTransform,
  headingAs = "h4",
  headingLevel = "h2",
}: HeaderProps) {
  if (!title && !preamble && !link) {
    return null
  }

  return (
    <header className={styles.header}>
      <Title
        as={headingAs}
        className={styles.title}
        level={headingLevel}
        textTransform={textTransform}
      >
        {title}
      </Title>
      {preamble && <Preamble className={styles.preamble}>{preamble}</Preamble>}
      <SectionLink link={link} variant="desktop" />
    </header>
  )
}
