import type { Meta, StoryObj } from '@storybook/react-vite'
import { expect, within } from 'storybook/test'

import { ToastRegion } from './toast'
import { toastManager } from '../../toast/toast-manager'

const meta = {
  component: ToastRegion,
  tags: ['ai-generated'],
} satisfies Meta<typeof ToastRegion>

export default meta
type Story = StoryObj<typeof meta>

export const Success: Story = {
  args: { children: null },
  play: async () => {
    toastManager.add({ type: 'success', description: 'Saved' })
    await expect(await within(document.body).findByText('Saved')).toBeInTheDocument()
  },
}

export const Error: Story = {
  args: { children: null },
  play: async () => {
    toastManager.add({ type: 'error', description: 'Something went wrong' })
    await expect(
      await within(document.body).findByText('Something went wrong'),
    ).toBeInTheDocument()
  },
}
