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

import Button from '../button';
import { storyConfig } from '../test-utils';

import Tooltip from './Tooltip';

export default {
  component: Tooltip,
  title: 'Dialogs/Tooltip',
  args: {
    label: 'This is the content',
    position: 'bottom',
  },
  render: (args) => (
    <div className="text-xs-center" style={{ flexBasis: '150px' }}>
      <Tooltip {...args}>
        <Button>Hover me</Button>
      </Tooltip>
    </div>
  ),
  tags: ['autodocs'],
} satisfies Meta<typeof Tooltip>;

type Story = StoryObj<typeof Tooltip>;

export const Basic: Story = {};

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

export const OpenedTooltipDark: Story = storyConfig(OpenedTooltip, { variants: ['dark'] });
