import { componentName } from '../src/components/boolean-fields/descope-switch-toggle';
import { toggleDefaultErrorMessageValueMissingDecorator, withForm } from './helpers';
import {
  labelControl,
  sizeControl,
  fullWidthControl,
  directionControl,
  disabledControl,
  requiredControl,
  borderedControl,
  checkboxValueControl,
  errorMissingValueControl,
  readOnlyControl,
  errorMessageIconControl,
  errorMessageIconAttrs,
  defaultValueMissingControl,
} from './commonControls';

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

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

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

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