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 PromoImage ({ _model, ...props }) {
  const { title, asset } = _model
  if (!title || !asset.src) {
    throw new ValidationError()
  }

  return h('div', { ...props, className: 'relative h-full rounded-2xl overflow-hidden grid' },
    h('div', { className: 'row-start-1 col-start-1 h-full' },
      h(Asset, { _model, _tall: true })
    ),
    h('div', { className: 'row-start-1 col-start-1 h-full flex items-end' },
      h('div', { className: 'bg-bga text-txa relative w-full' },
        h(PromoText, { _model })
      )
    )
  )
}
