import snippets from "./snippets";

const genMinMaxProps = (key: "minInputNumberProps" | "maxInputNumberProps") => {
  return [
    {
      name: `${key}.autoFocus`,
      title: { label: "自动聚焦", tip: "自动获取焦点" },
      propType: "bool",
      defaultValue: false,
      setter: "BoolSetter",
    },
    {
      name: `${key}.disabled`,
      title: { label: "是否禁用", tip: "是否为禁用状态" },
      propType: "bool",
      defaultValue: false,
      setter: "BoolSetter",
    },
    {
      name: `${key}.placeholder`,
      title: { label: "占位提示", tip: "占位提示" },
      propType: "string",
      defaultValue: "请输入",
      setter: "PisellI18nSetter",
    },
    {
      name: `${key}.controls`,
      title: { label: "是否显示增减按钮", tip: "是否显示增减按钮" },
      propType: "bool",
      defaultValue: true,
      setter: "BoolSetter",
    },
    {
      name: `${key}.bordered`,
      title: { label: "显示边框", tip: "是否有边框" },
      propType: "bool",
      defaultValue: true,
      setter: "BoolSetter",
    },
    {
      name: `${key}.addonAfter`,
      title: { label: "后置标签", tip: "后置标签" },
      propType: { type: "oneOfType", value: ["string", "node"] },
      setter: ["PisellI18nSetter", "SlotSetter"],
    },
    {
      name: `${key}.addonBefore`,
      title: { label: "前置标签", tip: "前置标签" },
      propType: { type: "oneOfType", value: ["string", "node"] },
      setter: ["PisellI18nSetter", "SlotSetter"],
    },
    // {
    //   name: 'formatter',
    //   title: {
    //     label: '指定输入框展示值的格式',
    //     tip: '指定输入框展示值的格式',
    //   },
    //   propType: 'func',
    // },
    {
      name: `${key}.max`,
      title: { label: "最大值", tip: "最大值" },
      propType: "number",
      setter: "NumberSetter",
    },
    {
      name: `${key}.min`,
      title: { label: "最小值", tip: "最小值" },
      propType: "number",
      setter: "NumberSetter",
    },
    {
      name: `${key}.precision`,
      title: { label: "数值精度", tip: "数值精度" },
      propType: "number",
      setter: "NumberSetter",
    },
    // {
    //   name: 'decimalSeparator',
    //   title: { label: '小数点', tip: '小数点' },
    //   propType: 'string',
    // },
    {
      name: `${key}.size`,
      title: { label: "尺寸", tip: "输入框大小" },
      propType: { type: "oneOf", value: ["large", "middle", "small"] },
      setter: {
        componentName: "RadioGroupSetter",
        props: {
          options: [
            {
              title: "大",
              value: "large",
            },
            {
              title: "中",
              value: "middle",
            },
            {
              title: "小",
              value: "small",
            },
          ],
        },
      },
      defaultValue: "middle",
    },
    {
      name: `${key}.step`,
      title: { label: "单步长", tip: "每次改变步数" },
      propType: "number",
      setter: "NumberSetter",
    },
    {
      name: `${key}.onPressEnter`,
      title: { label: "按下回车的回调", tip: "按下回车的回调" },
      propType: "func",
    },
    {
      name: `${key}.onFocus`,
      title: { label: "获取焦点回调", tip: "获取焦点回调" },
      propType: "func",
    },
    {
      name: `${key}.onKeyDown`,
      title: { label: "按键按下时的回调", tip: "按键按下时的回调" },
      propType: "func",
    },
    {
      name: `${key}.onKeyPress`,
      title: { label: "按键按下后的回调", tip: "按键按下之后释放之前的回调" },
      propType: "func",
    },
    {
      name: `${key}.onKeyUp`,
      title: { label: "按键释放回调", tip: "按键释放之后的回调" },
      propType: "func",
    },
    {
      name: `${key}.onBlur`,
      title: { label: "失去焦点回调", tip: "失去焦点回调" },
      propType: "func",
    },
  ];
};

export default {
  snippets,
  componentName: "InputNumberRange",
  title: "数字范围输入框",
  category: "表单",
  docUrl: "",
  screenshot: "",
  devMode: "proCode",
  npm: {
    package: "@pisell/materials",
    version: "1.0.1",
    exportName: "InputNumberRange",
    main: "src/index.tsx",
    destructuring: true,
    subName: "",
  },
  props: [
    {
      name: "defaultValue",
      title: { label: "默认值", tip: "默认值" },
      propType: "object",
      setter: "ObjectSetter",
    },
    {
      name: "value",
      title: { label: "当前值", tip: "当前值" },
      propType: "object",
      setter: "ObjectSetter",
    },
    {
      name: "separator",
      title: { label: "分隔符自定义", tip: "分隔符自定义" },
      propType: { type: "oneOfType", value: ["string", "node"] },
      setter: [
        "PisellI18nSetter",
        {
          componentName: "SlotSetter",
          initialValue: {
            type: "JSSlot",
            value: [],
          },
        },
        "VariableSetter",
      ],
    },
    {
      title: "最小值InputNumber props",
      display: "block",
      type: "group",
      items: [...genMinMaxProps("minInputNumberProps")],
    },
    {
      title: "最大值InputNumber props",
      display: "block",
      type: "group",
      items: [...genMinMaxProps("maxInputNumberProps")],
    },
  ],
  configure: {
    supports: {
      style: true,
      events: [
        {
          name: "onChange",
          template:
            "onChange(value,${extParams}){\n// 变化回调\nconsole.log('onChange',value);}",
        },
      ],
    },
  },
};
