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

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

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

export const Main: StoryObj<typeof TextArea> = {
  args: {
    name: 'name',
    label: 'Name',
    placeholder: 'Enter Name...',
    rows: 5,
    tooltipContent: faker.lorem.paragraph(2),
  },
  render: (args) =>
    React.createElement(() => {
      const [value, setValue] = useState(args.value);

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