import Preamble from "@scandic-hotels/design-system/Preamble"
import Title, { type HeadingProps } from "@scandic-hotels/design-system/Title"

import SectionLink from "../Link"

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

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>
  )
}
