import { Box } from '../atoms/box.js'
import { Heading } from '../atoms/heading.js'
import { Link } from '../atoms/link.js'
import { RichText } from '../atoms/rich-text.js'
import { Time } from '../atoms/time.js'
import { ValidationError } from '../routing/error-handler.js'
import h from '../shared/h.js'

export function PressRelease ({ _model, _variant, ...props }) {
  const { links, date, title, text } = _model
  if (!title || links.length === 0) {
    throw new ValidationError()
  }

  const firstLink = links[0]

  return h(Box, { ...props, className: 'bg-bga text-txa rounded-2xl h-full' },
    h(Heading, { _level: 3 },
      h(Link, { _model: { value: firstLink.value, name: title, icon: null }, _variant: 'full' })
    ),
    date && h(Time, { _time: date }),
    _variant !== 'short' && h(RichText, text)
  )
}
