import snippets from './snippets';

export default {
  snippets,
  componentName: 'PisellUrl',
  title: 'URL 地址',
  category: '表单',
  docUrl: '',
  screenshot: '',
  devMode: 'proCode',
  npm: {
    package: '@pisell/materials',
    version: '1.0.1',
    exportName: 'PisellUrl',
    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: 'URL 地址',
              tip: 'value | 当前 URL 地址值',
            },
            propType: 'string',
            setter: ['StringSetter', 'VariableSetter'],
          },
          {
            name: 'defaultValue',
            title: {
              label: '默认值',
              tip: 'defaultValue | 默认 URL 地址',
            },
            propType: 'string',
            setter: ['StringSetter'],
          },
          {
            name: 'placeholder',
            title: {
              label: '占位文本',
              tip: 'placeholder | 输入框占位文本',
            },
            propType: 'string',
            setter: ['PisellI18nSetter', 'StringSetter'],
            defaultValue: '请输入 URL 地址',
          },
          {
            name: 'disabled',
            title: {
              label: '是否禁用',
              tip: 'disabled | 是否禁用状态',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Validation',
            'zh-CN': 'URL 校验',
          },
          tip: 'URL 格式校验和协议限制',
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'strictValidation',
            title: {
              label: '严格校验',
              tip: 'strictValidation | 是否使用严格校验',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'requireProtocol',
            title: {
              label: '要求协议',
              tip: 'requireProtocol | 是否要求必须有协议',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
          {
            name: 'allowedProtocols',
            title: {
              label: '允许的协议',
              tip: 'allowedProtocols | 允许的协议列表',
            },
            propType: 'object',
            setter: ['JsonSetter', 'VariableSetter'],
          },
          {
            name: 'required',
            title: {
              label: '是否必填',
              tip: 'required | 是否为必填项',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
          {
            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': 'Protocol',
            'zh-CN': '协议配置',
          },
          tip: '协议自动补全配置',
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'autoCompleteProtocol',
            title: {
              label: '自动补全协议',
              tip: 'autoCompleteProtocol | 是否自动补全协议',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'defaultProtocol',
            title: {
              label: '默认协议',
              tip: 'defaultProtocol | 默认协议',
            },
            propType: { type: 'oneOf', value: ['http://', 'https://'] },
            setter: [
              {
                componentName: 'RadioGroupSetter',
                props: {
                  options: [
                    { title: 'HTTP', value: 'http://' },
                    { title: 'HTTPS', value: 'https://' },
                  ],
                },
              },
              'VariableSetter',
            ],
            defaultValue: 'https://',
            condition: {
              type: 'JSFunction',
              value: "target => target.getProps().getPropValue('autoCompleteProtocol') !== false",
            },
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Link',
            'zh-CN': '链接跳转',
          },
          tip: '链接跳转配置（只读态）',
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'enableLinkClick',
            title: {
              label: '启用链接跳转',
              tip: 'enableLinkClick | 是否启用链接跳转（只读态）',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'openInNewWindow',
            title: {
              label: '新窗口打开',
              tip: 'openInNewWindow | 是否新窗口打开',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'showLinkIcon',
            title: {
              label: '显示链接图标',
              tip: 'showLinkIcon | 是否显示链接图标',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Display',
            'zh-CN': '显示控制',
          },
          tip: '协议/路径显示控制（只读态）',
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'displayFormat',
            title: {
              label: '显示格式',
              tip: 'displayFormat | 显示格式',
            },
            propType: { type: 'oneOf', value: ['full', 'domain', 'custom'] },
            setter: [
              {
                componentName: 'RadioGroupSetter',
                props: {
                  options: [
                    { title: '完整 URL', value: 'full' },
                    { title: '仅域名', value: 'domain' },
                    { title: '自定义', value: 'custom' },
                  ],
                },
              },
              'VariableSetter',
            ],
            defaultValue: 'full',
          },
          {
            name: 'showProtocol',
            title: {
              label: '显示协议',
              tip: 'showProtocol | 是否显示协议（只读态）',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
            condition: {
              type: 'JSFunction',
              value: "target => target.getProps().getPropValue('displayFormat') === 'full'",
            },
          },
          {
            name: 'showWww',
            title: {
              label: '显示 www',
              tip: 'showWww | 是否显示 www 前缀（只读态）',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
            condition: {
              type: 'JSFunction',
              value: "target => target.getProps().getPropValue('displayFormat') === 'full'",
            },
          },
          {
            name: 'showPathname',
            title: {
              label: '显示路径',
              tip: 'showPathname | 是否显示路径（只读态）',
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
            condition: {
              type: 'JSFunction',
              value: "target => target.getProps().getPropValue('displayFormat') === 'full'",
            },
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Style',
            'zh-CN': '样式配置',
          },
          tip: '字体和颜色配置（只读态）',
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'fontSize',
            title: {
              label: '字号',
              tip: 'fontSize | 文本字号，如 14 或 "14px"',
            },
            propType: { type: 'oneOfType', value: ['string', 'number'] },
            setter: ['StringSetter', 'NumberSetter', 'VariableSetter'],
            defaultValue: 16,
          },
          {
            name: 'fontWeight',
            title: {
              label: '字重',
              tip: 'fontWeight | 文本字重，如 600 或 "bold"',
            },
            propType: { type: 'oneOfType', value: ['string', 'number'] },
            setter: ['StringSetter', 'NumberSetter', 'VariableSetter'],
            defaultValue: 500,
          },
          {
            name: 'color',
            title: {
              label: '文本颜色',
              tip: 'color | 文本颜色',
            },
            propType: 'string',
            setter: ['ColorSetter', 'VariableSetter'],
            defaultValue: '#101828',
          },
          {
            name: 'linkColor',
            title: {
              label: '链接颜色',
              tip: 'linkColor | 链接颜色（只读态）',
            },
            propType: 'string',
            setter: ['ColorSetter', 'VariableSetter'],
            defaultValue: '#7F56DA',
          },
        ],
      },
      {
        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'],
            defaultValue: 2048,
          },
          {
            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': 'Advanced',
            '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// URL 变化时的回调\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: 'onLinkClick',
          template:
            "onLinkClick(url,${extParams}){\n// 链接点击回调\nconsole.log('onLinkClick', url);}",
        },
        {
          name: 'onProtocolComplete',
          template:
            "onProtocolComplete(url,${extParams}){\n// 协议补全回调\nconsole.log('onProtocolComplete', url);}",
        },
        {
          name: 'onValidate',
          template:
            "onValidate(isValid, errors,${extParams}){\n// 校验回调\nconsole.log('onValidate', isValid, errors);}",
        },
      ],
    },
    component: {},
  },
};
