import { Meta, StoryObj } from '@storybook/react';
import { userEvent, within } from '@storybook/test';

import { lorem10, storyConfig } from '../test-utils';

import Info, { InfoPresentation } from '.';

const meta = {
  component: Info,
  title: 'Dialogs/Info',
  args: {
    'aria-label': 'Click here for more details',
    title: 'Fast transfer hint',
    content: lorem10,
  },
  render: (args) => (
    <p>
      <span>Fast transfer</span> <Info {...args} />
    </p>
  ),
} satisfies Meta<typeof Info>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic = storyConfig<typeof meta>(
  {},
  {
    variants: ['default', 'dark', 'rtl'],
  },
);

export const OpenedPopover = {
  parameters: {
    chromatic: {
      delay: 1000,
    },
  },
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    await userEvent.click(canvas.getByRole('button'));
  },
} satisfies Story;

export const OpenedPopoverMobile = storyConfig(OpenedPopover, {
  variants: ['mobile'],
});

export const OpenedModal = {
  ...OpenedPopover,
  args: {
    presentation: InfoPresentation.MODAL,
  },
} satisfies Story;

export const OpenedModalMobile = storyConfig(OpenedModal, {
  variants: ['mobile'],
});
