---
import AnchorHeading from '@astrojs/starlight/components/AnchorHeading.astro'
import starlightConfig from 'virtual:starlight/user-config'

export interface Props {
  id: string
  level: number
}

const { id, level } = Astro.props
const headingLevel = Math.min(Math.max(level, 1), 6) as 1 | 2 | 3 | 4 | 5 | 6
const Element = `h${headingLevel}` as const
---

{
  starlightConfig.markdown.headingLinks ? (
    <AnchorHeading class="sl-openapi-heading" {id} level={headingLevel}>
      <slot />
    </AnchorHeading>
  ) : (
    <Element class="sl-openapi-heading" {id}>
      <slot />
    </Element>
  )
}
