import snippets from './snippets';

export default {
  snippets,
  componentName: 'PisellPhone',
  title: '电话号码',
  category: '表单',
  docUrl: '',
  screenshot: '',
  devMode: 'proCode',
  npm: {
    package: '@pisell/materials',
    version: '1.0.1',
    exportName: 'PisellPhone',
    main: 'src/index.tsx',
    destructuring: true,
    subName: '',
  },
  configure: {
    props: [
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Basic',
            'zh-CN': '基础配置',
          },
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'mode',
            title: {
              label: '状态模式',
              tip: 'mode | 组件的状态模式',
            },
            propType: { type: 'oneOf', value: ['read', 'edit'] },
            setter: [
              {
                componentName: 'RadioGroupSetter',
                props: {
                  options: [
                    { title: '只读', value: 'read' },
                    { title: '编辑', value: 'edit' },
                  ],
                },
              },
              'VariableSetter',
            ],
            defaultValue: 'edit',
          },
          {
            name: 'value',
            title: {
              label: '电话号码',
              tip: 'value | 电话号码（不含国家码）',
            },
            propType: 'string',
            setter: ['StringSetter', 'VariableSetter'],
          },
          {
            name: 'defaultValue',
            title: {
              label: '默认值',
              tip: 'defaultValue | 默认电话号码',
            },
            propType: 'string',
            setter: ['StringSetter'],
          },
          {
            name: 'placeholder',
            title: {
              label: '占位文本',
              tip: 'placeholder | 输入框占位文本',
            },
            propType: 'string',
            setter: ['PisellI18nSetter', 'StringSetter'],
            defaultValue: '请输入电话号码',
          },
          {
            name: 'disabled',
            title: {
              label: '是否禁用',
              tip: 'disabled | 是否禁用状态',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Country Code',
            'zh-CN': '国家码配置',
          },
          tip: '国家码和格式化相关配置',
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'countryCode',
            title: {
              label: '国家码',
              tip: 'countryCode | 当前选中的国家码',
            },
            propType: 'string',
            setter: ['StringSetter', 'VariableSetter'],
            defaultValue: '+86',
          },
          {
            name: 'showCountrySelector',
            title: {
              label: '显示国家码选择器',
              tip: 'showCountrySelector | 是否显示国家码选择器',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'autoFormat',
            title: {
              label: '自动格式化',
              tip: 'autoFormat | 是否自动格式化电话号码',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'showFlag',
            title: {
              label: '显示国旗',
              tip: 'showFlag | 是否显示国旗图标（只读态）',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Dial & Masking',
            'zh-CN': '拨号和脱敏',
          },
          tip: '拨号和脱敏相关配置（只读态）',
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'enableDial',
            title: {
              label: '启用拨号',
              tip: 'enableDial | 是否启用拨号功能（移动端）',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'showDialIcon',
            title: {
              label: '显示拨号图标',
              tip: 'showDialIcon | 是否显示拨号图标',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
          {
            name: 'enableMasking',
            title: {
              label: '启用脱敏',
              tip: 'enableMasking | 是否脱敏显示（只读态）',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
          {
            name: 'maskPattern',
            title: {
              label: '脱敏模式',
              tip: 'maskPattern | 脱敏模式',
            },
            propType: { type: 'oneOf', value: ['middle', 'last', 'custom'] },
            setter: [
              {
                componentName: 'RadioGroupSetter',
                props: {
                  options: [
                    { title: '中间脱敏', value: 'middle' },
                    { title: '末尾脱敏', value: 'last' },
                    { title: '自定义', value: 'custom' },
                  ],
                },
              },
              'VariableSetter',
            ],
            defaultValue: 'middle',
            condition: {
              type: 'JSFunction',
              value: "target => target.getProps().getPropValue('enableMasking') === true",
            },
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Edit',
            'zh-CN': '编辑配置',
          },
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'maxLength',
            title: {
              label: '最大长度',
              tip: 'maxLength | 最大长度（根据国家码自动设置）',
            },
            propType: 'number',
            setter: ['NumberSetter', 'VariableSetter'],
          },
          {
            name: 'allowClear',
            title: {
              label: '显示清除',
              tip: 'allowClear | 是否显示清空按钮',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
          {
            name: 'autoFocus',
            title: {
              label: '自动聚焦',
              tip: 'autoFocus | 是否自动聚焦',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Validation',
            'zh-CN': '校验配置',
          },
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'required',
            title: {
              label: '是否必填',
              tip: 'required | 是否为必填项',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
          {
            name: 'validateFormat',
            title: {
              label: '校验格式',
              tip: 'validateFormat | 是否校验电话号码格式',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'errorMessage',
            title: {
              label: '错误提示',
              tip: 'errorMessage | 自定义错误提示信息',
            },
            propType: 'string',
            setter: ['PisellI18nSetter', 'StringSetter', 'VariableSetter'],
          },
          {
            name: 'validateTrigger',
            title: {
              label: '校验时机',
              tip: 'validateTrigger | 校验触发时机',
            },
            propType: { type: 'oneOf', value: ['onChange', 'onBlur', 'both'] },
            setter: [
              {
                componentName: 'RadioGroupSetter',
                props: {
                  options: [
                    { title: '输入时', value: 'onChange' },
                    { title: '失焦时', value: 'onBlur' },
                    { title: '两者都', value: 'both' },
                  ],
                },
              },
              'VariableSetter',
            ],
            defaultValue: 'onBlur',
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Style',
            'zh-CN': '样式',
          },
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'className',
            title: {
              label: '样式类名',
              tip: 'className | 自定义样式类名',
            },
            propType: 'string',
            setter: 'StringSetter',
          },
          {
            name: 'style',
            title: {
              label: '自定义样式',
              tip: 'style | 自定义样式对象',
            },
            propType: 'object',
            setter: 'StyleSetter',
          },
        ],
      },
    ],
    supports: {
      style: true,
      events: [
        {
          name: 'onChange',
          template:
            "onChange(value,${extParams}){\n// 电话号码变化时的回调\nconsole.log('onChange', value);}",
        },
        {
          name: 'onBlur',
          template: "onBlur(value,${extParams}){\n// 失焦回调\nconsole.log('onBlur', value);}",
        },
        {
          name: 'onFocus',
          template: "onFocus(${extParams}){\n// 聚焦回调\nconsole.log('onFocus');}",
        },
        {
          name: 'onCountryCodeChange',
          template:
            "onCountryCodeChange(code,${extParams}){\n// 国家码变更回调\nconsole.log('onCountryCodeChange', code);}",
        },
        {
          name: 'onDial',
          template: "onDial(phone,${extParams}){\n// 拨号回调\nconsole.log('onDial', phone);}",
        },
        {
          name: 'onValidate',
          template:
            "onValidate(isValid, errors,${extParams}){\n// 校验回调\nconsole.log('onValidate', isValid, errors);}",
        },
      ],
    },
    component: {},
  },
};
