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 { Radio } from './Radio';

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

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

export const Main: StoryObj<typeof Radio> = {
  args: {
    value: 3,
    name: 'number',
    label: 'Number',
    options: [
      { value: '1', label: 'One' },
      { value: '2', label: 'Two' },
      { value: '3', label: 'Three' },
    ],
    tooltipContent: faker.lorem.paragraph(2),
  },
  render: (args) =>
    React.createElement(() => {
      const [value, setValue] = useState(args.value);

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