---
import type * as interfaces from '../lib/interfaces.ts'
import Bookmark from './notion/Bookmark.astro'
import BulletedListItems from './notion/BulletedListItems.astro'
import Callout from './notion/Callout.astro'
import Code from './notion/Code.astro'
import ColumnList from './notion/ColumnList.astro'
import Divider from './notion/Divider.astro'
import Embed from './notion/Embed.astro'
import Equation from './notion/Equation.astro'
import File from './notion/File.astro'
import Heading1 from './notion/Heading1.astro'
import Heading2 from './notion/Heading2.astro'
import Heading3 from './notion/Heading3.astro'
import Image from './notion/Image.astro'
import LinkToPage from './notion/LinkToPage.astro'
import NumberedListItems from './notion/NumberedListItems.astro'
import Paragraph from './notion/Paragraph.astro'
import Quote from './notion/Quote.astro'
import SyncedBlock from './notion/SyncedBlock.astro'
import Table from './notion/Table.astro'
import TableOfContents from './notion/TableOfContents.astro'
import ToDo from './notion/ToDo.astro'
import Toggle from './notion/Toggle.astro'
import Video from './notion/Video.astro'

export interface Props {
  blocks: interfaces.Block[]
  level?: number
  urlMap?: { [key: string]: string }
  headings?: interfaces.Block[]
}

const {
  blocks = [],
  level = 0,
  urlMap = {},
  headings = [],
}: Props = Astro.props
---

{
  blocks.map((block) => {
    switch (block.Type) {
      case 'paragraph':
        return <Paragraph block={block} headings={headings} />
      case 'heading_1':
        return <Heading1 block={block} headings={headings} />
      case 'heading_2':
        return <Heading2 block={block} headings={headings} />
      case 'heading_3':
        return <Heading3 block={block} headings={headings} />
      case 'bulleted_list':
        return (
          <BulletedListItems block={block} level={level} headings={headings} />
        )
      case 'numbered_list':
        return (
          <NumberedListItems block={block} level={level} headings={headings} />
        )
      case 'to_do':
        return <ToDo block={block} headings={headings} />
      case 'code':
        return <Code block={block} />
      case 'quote':
        return <Quote block={block} headings={headings} />
      case 'callout':
        return <Callout block={block} headings={headings} />
      case 'image':
        return <Image block={block} />
      case 'file':
        return <File block={block} />
      case 'embed':
        return <Embed block={block} urlMap={urlMap} />
      case 'bookmark':
      case 'link_preview':
        return <Bookmark block={block} urlMap={urlMap} />
      case 'video':
        return <Video block={block} />
      case 'divider':
        return <Divider />
      case 'table':
        return <Table block={block} />
      case 'equation':
        return <Equation block={block} />
      case 'column_list':
        return <ColumnList block={block} headings={headings} />
      case 'synced_block':
        return <SyncedBlock block={block} headings={headings} />
      case 'toggle':
        return <Toggle block={block} headings={headings} />
      case 'table_of_contents':
        return <TableOfContents block={block} headings={headings} />
      case 'link_to_page':
        return <LinkToPage block={block} />
      default:
        return null
    }
  })
}
