---
import { Icon } from 'astro-icon/components';
import { Picture } from '@astrojs/image/components';
import type { Content } from '~/types';
import Headline from '../ui/Headline.astro';
import WidgetWrapper from '../ui/WidgetWrapper.astro';

const {
  title = await Astro.slots.render('title'),
  subtitle = await Astro.slots.render('subtitle'),
  tagline,
  content = await Astro.slots.render('content'),
  items = [],
  image = await Astro.slots.render('image'),
  isReversed = false,
  isAfterContent = false,

  id,
  isDark = false,
  classes = {},
  bg = await Astro.slots.render('bg'),
} = Astro.props as Content;
---

<WidgetWrapper
  id={id}
  isDark={isDark}
  containerClass={`max-w-screen-xl mx-auto ${isAfterContent ? 'pt-0 md:pt-0 lg:pt-0' : ''} ${classes?.container ?? ''}`}
  bg={bg}
>
  <Headline
    title={title}
    subtitle={subtitle}
    tagline={tagline}
    classes={{
      container: 'max-w-xl sm:mx-auto lg:max-w-2xl',
      title: 'text-4xl md:text-5xl font-bold leading-tighter tracking-tighter mb-4 font-heading',
      subtitle: 'max-w-3xl mx-auto sm:text-center text-xl text-muted dark:text-slate-400',
    }}
  />
  <div class="mx-auto max-w-7xl p-4 md:px-8">
    <div class={`md:flex ${isReversed ? 'md:flex-row-reverse' : ''} md:gap-16`}>
      <div class="md:basis-1/2 self-center">
        {content && <div class="mb-12 text-lg dark:text-slate-400" set:html={content} />}

        {
          items && (
            <div class="space-y-8">
              {items.map(({ title: title2, description, icon }) => (
                <div class="flex">
                  <div class="flex-shrink-0">
                    <div class="flex h-7 w-7 items-center justify-center rounded-full bg-primary text-gray-50">
                      <Icon name={icon ? icon : 'tabler:check'} class="w-5 h-5" />
                    </div>
                  </div>
                  <div class="ml-4 rtl:ml-0 rtl:mr-4">
                    {title2 && <h3 class="text-lg font-medium leading-6 dark:text-white">{title2}</h3>}
                    {description && <p class="mt-2 text-muted dark:text-slate-400" set:html={description} />}
                  </div>
                </div>
              ))}
            </div>
          )
        }
      </div>
      <div aria-hidden="true" class="mt-10 md:mt-0 md:basis-1/2">
        {
          image && (
            <div class="relative m-auto max-w-4xl">
              {typeof image === 'string' ? (
                <Fragment set:html={image} />
              ) : (
                <Picture
                  class="mx-auto w-full rounded-lg bg-gray-500 shadow-lg"
                  width={500}
                  height={500}
                  widths={[400, 768]}
                  sizes="(max-width: 768px) 100vw, 432px"
                  aspectRatio="500:500"
                  {...(image as any)}
                />
              )}
            </div>
          )
        }
      </div>
    </div>
  </div>
</WidgetWrapper>
