<script lang="ts">
  import MarkdownBlock from "./blocks/MarkdownBlock.svelte";
  import HeadlineBlock from "./blocks/HeadlineBlock.svelte";
  import HtmlBlock from "./blocks/HtmlBlock.svelte";
  import IframeBlock from "./blocks/IframeBlock.svelte";
  import ImageBlock from "./blocks/ImageBlock.svelte";
  import ImageGalleryBlock from "./blocks/ImageGalleryBlock.svelte";
  import FilesBlock from "./blocks/FilesBlock.svelte";
  import YoutubeVideoBlock from "./blocks/YoutubeVideoBlock.svelte";
  import YoutubeVideoGalleryBlock from "./blocks/YoutubeVideoGalleryBlock.svelte";
  import QuoteBlock from "./blocks/QuoteBlock.svelte";
  import QuoteCarouselBlock from "./blocks/QuoteCarouselBlock.svelte";
  import LinkListBlock from "./blocks/LinkListBlock.svelte";
  import PostOverviewBlock from "./blocks/PostOverviewBlock.svelte";
  import SearchableTextBlock from "./blocks/SearchableTextBlock.svelte";
  import CalendarBlock from "./blocks/CalendarBlock.svelte";
  import OrganisationsBlock from "./blocks/OrganisationsBlock.svelte";
  import OpnFormBlock from "./blocks/OpnFormBlock.svelte";
  import DeadlineBannerBlock from "./blocks/DeadlineBannerBlock.svelte";
  import StrommixBlock from "./blocks/StrommixBlock.svelte";
  import WindkarteBlock from "./blocks/WindkarteBlock.svelte";
  import type { Translations } from "$lib/translations";
  import type {
    ResolvedBlock,
    MarkdownBlockData,
    HeadlineBlockData,
    HtmlBlockData,
    IframeBlockData,
    ImageBlockData,
    ImageGalleryBlockData,
    FilesBlockData,
    YoutubeVideoBlockData,
    YoutubeVideoGalleryBlockData,
    QuoteBlockData,
    QuoteCarouselBlockData,
    LinkListBlockData,
    PostOverviewBlockData,
    SearchableTextBlockData,
    CalendarBlockData,
    OrganisationsBlockData,
    OpnFormBlockData,
    DeadlineBannerBlockData,
    LiveStrommixBlockData,
    WindMapBlockData,
  } from "$lib/block-types";

  let {
    block,
    translations = {},
  }: { block: ResolvedBlock; translations?: Translations | null } = $props();

  const type = $derived((block._type as string) ?? "unknown");
</script>

{#if type === "markdown"}
  <MarkdownBlock block={block as MarkdownBlockData} />
{:else if type === "headline"}
  <HeadlineBlock block={block as HeadlineBlockData} />
{:else if type === "html"}
  <HtmlBlock block={block as HtmlBlockData} />
{:else if type === "iframe"}
  <IframeBlock block={block as IframeBlockData} translations={translations} />
{:else if type === "image"}
  <ImageBlock block={block as ImageBlockData} />
{:else if type === "image_gallery"}
  <ImageGalleryBlock block={block as ImageGalleryBlockData} />
{:else if type === "files"}
  <FilesBlock block={block as FilesBlockData} />
{:else if type === "youtube_video"}
  <YoutubeVideoBlock block={block as YoutubeVideoBlockData} />
{:else if type === "youtube_video_gallery"}
  <YoutubeVideoGalleryBlock block={block as YoutubeVideoGalleryBlockData} />
{:else if type === "quote"}
  <QuoteBlock block={block as QuoteBlockData} />
{:else if type === "quote_carousel"}
  <QuoteCarouselBlock block={block as QuoteCarouselBlockData} />
{:else if type === "link_list"}
  <LinkListBlock block={block as LinkListBlockData} />
{:else if type === "post_overview"}
  <PostOverviewBlock block={block as PostOverviewBlockData} />
{:else if type === "searchable_text"}
  <SearchableTextBlock block={block as SearchableTextBlockData} translations={translations} />
{:else if type === "calendar"}
  <CalendarBlock block={block as CalendarBlockData} translations={translations} />
{:else if type === "organisations"}
  <OrganisationsBlock block={block as OrganisationsBlockData} />
{:else if type === "opnform"}
  <OpnFormBlock block={block as OpnFormBlockData} />
{:else if type === "deadline_banner"}
  <DeadlineBannerBlock block={block as DeadlineBannerBlockData} />
{:else if type === "live_strommix"}
  <StrommixBlock block={block as LiveStrommixBlockData} />
{:else if type === "wind_map"}
  <WindkarteBlock block={block as WindMapBlockData} />
{:else}
  <div class="rounded border border-erde-200 bg-erde-50 px-3 py-2 text-sm text-erde-800">
    Unbekannter Block: <code>{type}</code>
  </div>
{/if}
