import { Meta, StoryObj } from '@storybook/nextjs-vite'
import { Search } from '@/payload-types'
import { SearchPage } from './SearchPage'

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

type Story = StoryObj<typeof SearchPage>
export default meta

const makeResult = (
  id: string,
  title: string,
  doc: Search['doc'],
): Search => ({
  id,
  title,
  doc,
  updatedAt: '2026-03-01T00:00:00.000Z',
  createdAt: '2026-03-01T00:00:00.000Z',
})

export const WithResults: Story = {
  args: {
    query: 'Gottesdienst',
    results: [
      makeResult('1', 'Sonntagsgottesdienst', {
        relationTo: 'pages',
        value: { id: 'p1', slug: 'gottesdienst' },
      } as unknown as Search['doc']),
      makeResult('2', 'Ostern 2026 – Liturgische Feier', {
        relationTo: 'event',
        value: { id: 'e1' },
      } as unknown as Search['doc']),
      makeResult('3', 'Ministrantengruppe', {
        relationTo: 'group',
        value: { id: 'g1', slug: 'ministranten' },
      } as unknown as Search['doc']),
      makeResult('4', 'Rundbrief Januar', {
        relationTo: 'blog',
        value: { id: 'b1' },
      } as unknown as Search['doc']),
    ],
  },
}

export const NoResults: Story = {
  args: {
    query: 'xyzunbekannt',
    results: [],
  },
}

export const EmptyQuery: Story = {
  args: {
    query: '',
    results: [],
  },
}
