function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { PisellNumber } from "./PisellNumber";
import { useState } from 'react';
import { Form } from 'antd';
import React from 'react';

/**
 * PisellNumber 组件 Storybook
 * 
 * 用于展示和测试组件的各种状态和配置
 */
var meta = {
  title: '表单/表单组件/PisellNumber',
  component: PisellNumber,
  tags: ['autodocs'],
  argTypes: {
    mode: {
      control: 'radio',
      options: ['read', 'edit'],
      description: '显示模式'
    },
    disabled: {
      control: 'boolean',
      description: '是否禁用'
    },
    value: {
      control: 'number',
      description: '当前值'
    },
    min: {
      control: 'number',
      description: '最小值'
    },
    max: {
      control: 'number',
      description: '最大值'
    },
    step: {
      control: 'number',
      description: '步进值'
    },
    precision: {
      control: 'number',
      description: '小数精度'
    },
    useGrouping: {
      control: 'boolean',
      description: '是否使用千分位分隔符'
    }
  }
};
export default meta;
/**
 * 基础示例 - 编辑态
 */
export var Basic = {
  args: {
    value: 10,
    placeholder: '请输入数字'
  },
  render: function render(args) {
    var _useState = useState(args.value),
      _useState2 = _slicedToArray(_useState, 2),
      value = _useState2[0],
      setValue = _useState2[1];
    return /*#__PURE__*/React.createElement(PisellNumber, _extends({}, args, {
      value: value,
      onChange: setValue
    }));
  }
};

/**
 * 只读态展示
 */
export var ReadOnly = {
  args: {
    mode: 'read',
    value: 1234.567,
    precision: 2
  }
};

/**
 * 禁用态
 */
export var Disabled = {
  args: {
    disabled: true,
    value: 100
  }
};

/**
 * 带范围限制
 */
export var WithRange = {
  args: {
    value: 50,
    min: 0,
    max: 100,
    step: 10
  },
  render: function render(args) {
    var _useState3 = useState(args.value),
      _useState4 = _slicedToArray(_useState3, 2),
      value = _useState4[0],
      setValue = _useState4[1];
    return /*#__PURE__*/React.createElement(PisellNumber, _extends({}, args, {
      value: value,
      onChange: setValue
    }));
  }
};

/**
 * 带精度控制
 */
export var WithPrecision = {
  args: {
    value: 3.1415926,
    precision: 2,
    step: 0.01
  },
  render: function render(args) {
    var _useState5 = useState(args.value),
      _useState6 = _slicedToArray(_useState5, 2),
      value = _useState6[0],
      setValue = _useState6[1];
    return /*#__PURE__*/React.createElement(PisellNumber, _extends({}, args, {
      value: value,
      onChange: setValue
    }));
  }
};

/**
 * 千分位分隔符
 */
export var WithGrouping = {
  args: {
    mode: 'read',
    value: 1234567.89,
    precision: 2,
    useGrouping: true
  }
};

/**
 * 带前后缀
 */
export var WithAddon = {
  args: {
    value: 100,
    addonBefore: '￥',
    addonAfter: '元'
  },
  render: function render(args) {
    var _useState7 = useState(args.value),
      _useState8 = _slicedToArray(_useState7, 2),
      value = _useState8[0],
      setValue = _useState8[1];
    return /*#__PURE__*/React.createElement(PisellNumber, _extends({}, args, {
      value: value,
      onChange: setValue
    }));
  }
};

/**
 * 带校验 - 必填
 */
export var WithValidationRequired = {
  render: function render() {
    var _useState9 = useState(null),
      _useState10 = _slicedToArray(_useState9, 2),
      value = _useState10[0],
      setValue = _useState10[1];
    return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Form.Item, {
      label: "\u6570\u91CF\uFF08\u5FC5\u586B\uFF09"
    }, /*#__PURE__*/React.createElement(PisellNumber, {
      value: value,
      onChange: setValue,
      required: true,
      validateTrigger: "both",
      onValidate: function onValidate(isValid, errors) {
        console.log('校验结果:', isValid, errors);
      }
    })));
  }
};

/**
 * 带校验 - 范围校验
 */
export var WithValidationRange = {
  render: function render() {
    var _useState11 = useState(50),
      _useState12 = _slicedToArray(_useState11, 2),
      value = _useState12[0],
      setValue = _useState12[1];
    return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Form.Item, {
      label: "\u5E74\u9F84\uFF080-150\uFF09"
    }, /*#__PURE__*/React.createElement(PisellNumber, {
      value: value,
      onChange: setValue,
      min: 0,
      max: 150,
      required: true,
      validateTrigger: "both"
    })));
  }
};

/**
 * 带校验 - 自定义校验
 */
export var WithCustomValidation = {
  render: function render() {
    var _useState13 = useState(null),
      _useState14 = _slicedToArray(_useState13, 2),
      value = _useState14[0],
      setValue = _useState14[1];
    return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Form.Item, {
      label: "\u5076\u6570\u6821\u9A8C"
    }, /*#__PURE__*/React.createElement(PisellNumber, {
      value: value,
      onChange: setValue,
      validator: function validator(v) {
        if (v === null) return true;
        return v % 2 === 0 || '请输入偶数';
      },
      validateTrigger: "both"
    })));
  }
};

/**
 * 不同尺寸
 */
export var Sizes = {
  render: function render() {
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 16
      }
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "Large:"), /*#__PURE__*/React.createElement(PisellNumber, {
      value: 100,
      size: "large"
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "Middle:"), /*#__PURE__*/React.createElement(PisellNumber, {
      value: 100,
      size: "middle"
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "Small:"), /*#__PURE__*/React.createElement(PisellNumber, {
      value: 100,
      size: "small"
    })));
  }
};

/**
 * 只读态样式配置
 */
export var ReadOnlyStyles = {
  render: function render() {
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 16
      }
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "\u9ED8\u8BA4:"), /*#__PURE__*/React.createElement(PisellNumber, {
      mode: "read",
      value: 1234.56,
      precision: 2
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "\u52A0\u7C97:"), /*#__PURE__*/React.createElement(PisellNumber, {
      mode: "read",
      value: 1234.56,
      precision: 2,
      fontWeight: "bold"
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "\u7EA2\u8272:"), /*#__PURE__*/React.createElement(PisellNumber, {
      mode: "read",
      value: 1234.56,
      precision: 2,
      color: "#ff4d4f"
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "\u5927\u5B57\u53F7:"), /*#__PURE__*/React.createElement(PisellNumber, {
      mode: "read",
      value: 1234.56,
      precision: 2,
      fontSize: 20
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "\u5C45\u4E2D\u5BF9\u9F50:"), /*#__PURE__*/React.createElement(PisellNumber, {
      mode: "read",
      value: 1234.56,
      precision: 2,
      textAlign: "center",
      style: {
        width: 200,
        border: '1px solid #d9d9d9',
        padding: 8
      }
    })));
  }
};

/**
 * 表单场景
 */
export var InForm = {
  render: function render() {
    var _useState15 = useState(1),
      _useState16 = _slicedToArray(_useState15, 2),
      quantity = _useState16[0],
      setQuantity = _useState16[1];
    var _useState17 = useState(0),
      _useState18 = _slicedToArray(_useState17, 2),
      price = _useState18[0],
      setPrice = _useState18[1];
    var _useState19 = useState(0),
      _useState20 = _slicedToArray(_useState19, 2),
      weight = _useState20[0],
      setWeight = _useState20[1];
    return /*#__PURE__*/React.createElement(Form, {
      layout: "vertical",
      style: {
        maxWidth: 400
      }
    }, /*#__PURE__*/React.createElement(Form.Item, {
      label: "\u8D2D\u4E70\u6570\u91CF"
    }, /*#__PURE__*/React.createElement(PisellNumber, {
      value: quantity,
      onChange: setQuantity,
      min: 1,
      max: 100,
      step: 1,
      precision: 0,
      required: true,
      validateTrigger: "both"
    })), /*#__PURE__*/React.createElement(Form.Item, {
      label: "\u5546\u54C1\u4EF7\u683C"
    }, /*#__PURE__*/React.createElement(PisellNumber, {
      value: price,
      onChange: setPrice,
      min: 0,
      precision: 2,
      addonBefore: "\uFFE5",
      required: true,
      validateTrigger: "both"
    })), /*#__PURE__*/React.createElement(Form.Item, {
      label: "\u5546\u54C1\u91CD\u91CF"
    }, /*#__PURE__*/React.createElement(PisellNumber, {
      value: weight,
      onChange: setWeight,
      min: 0,
      precision: 3,
      addonAfter: "kg"
    })));
  }
};

/**
 * 空值处理
 */
export var EmptyValue = {
  render: function render() {
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        gap: 16
      }
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "\u9ED8\u8BA4\u7A7A\u503C\u663E\u793A:"), /*#__PURE__*/React.createElement(PisellNumber, {
      mode: "read",
      value: null
    })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      style: {
        marginRight: 8
      }
    }, "\u81EA\u5B9A\u4E49\u7A7A\u503C\u6587\u672C:"), /*#__PURE__*/React.createElement(PisellNumber, {
      mode: "read",
      value: null,
      emptyText: "\u6682\u65E0\u6570\u636E"
    })));
  }
};