import { faker } from '@faker-js/faker';
import { Meta, StoryObj } from '@storybook/react';
import React from 'react';
import { createGroups } from '../../../helpers/storybook';
import {
  formatDateTime,
  formatFileSize,
  formatSecondsToTimestamp,
  sortArray,
} from '../../Utils';
import { ReadOnlyTextField } from './ReadOnlyTextField';

const groups = createGroups({
  Behavior: ['inlineMode', 'id', 'hideCopyButton', 'transform'],
  Content: ['label', 'tooltipContent', 'value'],
  Styling: ['className'],
});

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

export const Main: StoryObj<typeof ReadOnlyTextField> = {
  args: {
    label: 'Name',
    value: 'Axinom',
    tooltipContent: faker.lorem.paragraph(2),
  },
};

export const Array: StoryObj<typeof ReadOnlyTextField> = {
  argTypes: {
    value: { control: { type: 'array' } },
  },
  args: {
    label: 'Name',
    value: ['Navy', 'Axinom'],
  },
};

export const Transform: StoryObj<typeof ReadOnlyTextField> = {
  parameters: {
    controls: {
      hideNoControlsWarning: true,
      exclude: /.*/g,
    },
  },
  render: (_args) => {
    return (
      <div style={{ display: 'grid', gridGap: 20 }}>
        <ReadOnlyTextField<string>
          label="formatDateTime"
          value="2020-09-09T00:00:00.000+00:00"
          transform={formatDateTime}
        />
        <ReadOnlyTextField<number>
          label="formatSecondsToTimestamp"
          value={10000}
          transform={formatSecondsToTimestamp}
        />
        <ReadOnlyTextField<number>
          label="formatFileSize"
          value={10000}
          transform={formatFileSize}
        />

        <ReadOnlyTextField<string[]>
          label="sortArray"
          value={['zh', 'en', 'ee', 'fr', 'ar', 'ja', 'ru']}
          transform={sortArray}
        />
      </div>
    );
  },
};
