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

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

import Info, { InfoPresentation } from '.';
import { withVariantConfig } from '../../.storybook/helpers';

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: Story = {
  ...withVariantConfig(['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: Story = {
  ...OpenedPopover,
  ...withVariantConfig(['mobile'], OpenedPopover),
};

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

export const OpenedModalMobile: Story = {
  ...OpenedModal,
  ...withVariantConfig(['mobile'], OpenedModal),
};
