import { Asset } from '../molecules/asset.js'
import { PromoText } from '../molecules/promo-text.js'
import { ValidationError } from '../routing/error-handler.js'
import h from '../shared/h.js'

export function PromoSimple ({ _model, ...props }) {
  const { title, text, links, asset } = _model
  if (!title && !text && links.length === 0) {
    throw new ValidationError()
  }

  const titleOnly = !text && links.length === 0
  const titleSize = asset.src ? '2xl' : '4xl'

  return h('div', { ...props, className: 'bg-bga text-txa h-full rounded-2xl overflow-hidden' },
    asset.src && h('div',
      h(Asset, { _model })
    ),
    titleOnly
      ? h('p', { className: `p-6 font-custom font-bold text-txc text-${titleSize}` }, title)
      : h(PromoText, { _model })
  )
}
