import { type MarkdownComponent } from '@defra/forms-model'

import { ComponentBase } from './ComponentBase.js'

export class Markdown extends ComponentBase {
  declare options: MarkdownComponent['options']
  content: MarkdownComponent['content']
  headerStartLevel: number

  constructor(
    def: MarkdownComponent,
    props: ConstructorParameters<typeof ComponentBase>[1]
  ) {
    super(def, props)

    const { content, options } = def

    this.content = content
    this.options = options
    this.headerStartLevel = 2
  }

  getViewModel() {
    const { content, viewModel } = this

    return {
      ...viewModel,
      content,
      headerStartLevel: this.headerStartLevel
    }
  }
}
