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

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

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

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.',
};
