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

const Template = ({
  label,
  placeholder,
  size,
  bordered,
  direction,
  required,
  'full-width': fullWidth,
  disabled,
  readonly,
  'external-input': externalInput,
  'manual-visibility-toggle': manualVisibilityToggle,
  'data-errormessage-value-missing': customErrorMissingValue,
  'label-type': labelType,
  errorMsgIcon,
}) =>
  `
    <descope-password
      size="${size}"
      bordered="${bordered}"
      label="${label || ''}"
      placeholder="${placeholder || ''}"
      required="${required || false}"
      full-width="${fullWidth || false}"
      disabled="${disabled || false}"
      readonly="${readonly || false}"
      data-errormessage-value-missing="${customErrorMissingValue || ''}"
      st-host-direction="${direction ?? ''}"
      label-type="${labelType || ''}"
      manual-visibility-toggle="${manualVisibilityToggle}"
      external-input="${externalInput || false}"
      ${errorMsgIcon ? errorMessageIconAttrs : ''}
    ></descope-password>
  `;

export default {
  component: componentName,
  title: 'descope-password',
  decorators: [toggleDefaultErrorMessageValueMissingDecorator, withForm],
  argTypes: {
    ...labelControl,
    ...placeholderControl,
    ...inputLabelTypeControl,
    ...sizeControl,
    ...fullWidthControl,
    ...disabledControl,
    ...readOnlyControl,
    ...requiredControl,
    ...borderedControl,
    ...errorMissingValueControl,
    ...directionControl,
    ...errorMessageIconControl,
    ...defaultValueMissingControl,
    'manual-visibility-toggle': {
      name: 'Manual Visibility Toggle',
      control: { type: 'boolean' },
    },
    'external-input': {
      control: { type: 'boolean' },
    },
  },
};

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

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