import { componentName } from '../src/components/descope-text-area';
import { toggleDefaultErrorMessageValueMissingDecorator, withForm } from './helpers';
import {
  labelControl,
  placeholderControl,
  sizeControl,
  fullWidthControl,
  directionControl,
  disabledControl,
  readOnlyControl,
  requiredControl,
  borderedControl,
  textAlignControl,
  errorMissingValueControl,
  errorMessageIconControl,
  errorMessageIconAttrs,
  defaultValueMissingControl,
} from './commonControls';

const Template = ({
  label,
  placeholder,
  size,
  bordered,
  direction,
  required,
  disabled,
  readonly,
  'full-width': fullWidth,
  'text-align': textAlign,
  'data-errormessage-value-missing': customErrorMissingValue,
  errorMsgIcon,
}) => `
    <descope-text-area
      size="${size}"
      bordered="${bordered}"
      label="${label || ''}"
      placeholder="${placeholder || ''}"
      required="${required || false}"
      full-width="${fullWidth || false}"
      readonly="${readonly || false}"
      disabled="${disabled || false}"
      text-align="${textAlign || ''}"
      data-errormessage-value-missing="${customErrorMissingValue || ''}"
      st-host-direction="${direction ?? ''}"
      ${errorMsgIcon ? errorMessageIconAttrs : ''}
    ></descope-text-area>
  `;

export default {
  component: componentName,
  title: 'descope-text-area',
  decorators: [toggleDefaultErrorMessageValueMissingDecorator, withForm],
  argTypes: {
    ...labelControl,
    ...placeholderControl,
    ...sizeControl,
    ...fullWidthControl,
    ...disabledControl,
    ...readOnlyControl,
    ...requiredControl,
    ...borderedControl,
    ...errorMissingValueControl,
    ...directionControl,
    ...textAlignControl,
    ...errorMessageIconControl,
    ...defaultValueMissingControl,
  },
};

export const Default = Template.bind({});

Default.args = {
  size: 'md',
  bordered: true,
  'data-errormessage-value-missing': 'Please fill out this field.',
};
