import { Meta, StoryObj } from '@storybook/nextjs-vite'
import { SerializedEditorState } from 'lexical'
import { Classifieds } from './Classifieds'

const meta: Meta<typeof Classifieds> = {
  component: Classifieds,
}

type Story = StoryObj<typeof Classifieds>
export default meta

const makeAdText = (text: string): SerializedEditorState =>
  ({
    root: {
      type: 'root',
      format: '',
      indent: 0,
      version: 1,
      direction: 'ltr',
      children: [
        {
          type: 'paragraph',
          format: '',
          indent: 0,
          version: 1,
          direction: 'ltr',
          textFormat: 0,
          textStyle: '',
          children: [
            {
              type: 'text',
              format: 0,
              mode: 'normal',
              style: '',
              text,
              detail: 0,
              version: 1,
            },
          ],
        },
      ],
    },
  }) as unknown as SerializedEditorState

export const Default: Story = {
  args: {
    ads: [
      {
        id: '1',
        text: makeAdText(
          'Suche Helfer für unseren Gemeindegarten. Wir treffen uns jeden Samstag um 10 Uhr.',
        ),
        email: 'gemeinde@drei-koenige-berlin.de',
      },
      {
        id: '2',
        text: makeAdText(
          'Biete Klavierunterricht für Anfänger und Fortgeschrittene.',
        ),
        email: 'klavier@example.com',
      },
      {
        id: '3',
        text: makeAdText('Verschenke Kinderfahrrad, gut erhalten.'),
        email: 'fahrrad@example.com',
      },
    ],
  },
}

export const Empty: Story = {
  args: {
    ads: [],
  },
}
