import { faker } from '@faker-js/faker';
import { action } from '@storybook/addon-actions';
import { Meta, StoryObj } from '@storybook/react';
import React, { useState } from 'react';
import { createGroups } from '../../../helpers/storybook';
import { Checkbox } from './Checkbox';

const groups = createGroups({
  Behavior: [
    'autoFocus',
    'disabled',
    'inlineMode',
    'name',
    'id',
    'confirmationMode',
    'confirmationConfig',
  ],
  Content: ['label', 'error', 'tooltipContent', 'value'],
  Styling: ['className'],
  Events: ['onChange', 'onBlur', 'onFocus'],
});

const meta: Meta<typeof Checkbox> = {
  title: 'Primary Components/Form Elements/Checkbox',
  component: Checkbox,
  argTypes: {
    ...groups,
  },
};
export default meta;

export const Main: StoryObj<typeof Checkbox> = {
  args: {
    label: 'Is Active?',
    tooltipContent: faker.lorem.paragraph(2),
    name: 'isActive',
  },
  render: (args) =>
    React.createElement(() => {
      const [value, setValue] = useState(args.value);

      return (
        <Checkbox
          {...args}
          value={value}
          onChange={(e) => {
            action('onChange')({ args: e });
            setValue(e);
          }}
        />
      );
    }),
};
