import { componentName } from '../src/components/descope-passcode';
import {
  toggleDefaultErrorMessagePatternMismatchDecorator,
  toggleDefaultErrorMessageValueMissingDecorator,
  withForm,
} from './helpers';
import {
  labelControl,
  loadingControl,
  sizeControl,
  fullWidthControl,
  directionControl,
  disabledControl,
  readOnlyControl,
  requiredControl,
  borderedControl,
  errorMissingValueControl,
  errorPatternMismatchControl,
  errorMessageIconControl,
  errorMessageIconAttrs,
  defaultValueMissingControl,
  defaultPatternMismatchControl,
} from './commonControls';

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

export default {
  component: componentName,
  title: 'descope-passcode',
  decorators: [
    toggleDefaultErrorMessageValueMissingDecorator,
    toggleDefaultErrorMessagePatternMismatchDecorator,
    withForm,
  ],
  argTypes: {
    ...labelControl,
    ...sizeControl,
    ...fullWidthControl,
    ...disabledControl,
    ...readOnlyControl,
    ...requiredControl,
    ...loadingControl,
    ...borderedControl,
    ...errorMissingValueControl,
    ...errorPatternMismatchControl,
    ...directionControl,
    ...errorMessageIconControl,
    ...defaultValueMissingControl,
    ...defaultPatternMismatchControl,
  },
};

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

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