import snippets from './snippets';
import { IPublicTypeComponentMetadata } from '@alilc/lowcode-types';

const PisellFilterMeta: IPublicTypeComponentMetadata = {
  componentName: 'PisellFilter',
  title: 'PisellFilter',
  category: '数据展示',
  docUrl: '',
  screenshot: '',
  devMode: 'proCode',
  npm: {
    package: '@pisell/materials',
    version: '1.0.3',
    exportName: 'PisellFilter',
    main: 'src/index.tsx',
    destructuring: true,
    subName: '',
  },
  configure: {
    props: [
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Basic',
            'zh-CN': '基础',
          },
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'value',
            title: {
              label: {
                type: 'i18n',
                'en-US': 'Filter Value',
                'zh-CN': '筛选值',
              },
              tip: {
                type: 'i18n',
                'en-US': 'value | Filter value object containing quickFilter and otherFilter',
                'zh-CN': 'value | 筛选值对象，包含 quickFilter 和 otherFilter',
              },
            },
            propType: 'object',
            setter: {
              componentName: 'ObjectSetter',
              props: {
                config: {
                  items: [
                    {
                      name: 'quickFilter',
                      title: {
                        label: {
                          type: 'i18n',
                          'en-US': 'Quick Filter',
                          'zh-CN': '快速筛选',
                        },
                        tip: '快速筛选项数组',
                      },
                      propType: {
                        type: 'arrayOf',
                        value: 'object',
                      },
                      setter: {
                        componentName: 'ArraySetter',
                        props: {
                          itemSetter: {
                            componentName: 'ObjectSetter',
                            props: {
                              config: {
                                items: [
                                  {
                                    name: 'type',
                                    title: {
                                      label: '筛选类型',
                                      tip: '筛选组件的类型',
                                    },
                                    propType: {
                                      type: 'oneOf',
                                      value: ['single', 'input', 'datePicker', 'rangePicker', 'search'],
                                    },
                                    setter: {
                                      componentName: 'SelectSetter',
                                      props: {
                                        options: [
                                          { title: '单选', value: 'single' },
                                          { title: '输入框', value: 'input' },
                                          { title: '日期选择', value: 'datePicker' },
                                          { title: '日期范围', value: 'rangePicker' },
                                          { title: '搜索框', value: 'search' },
                                        ],
                                      },
                                    },
                                    isRequired: true,
                                  },
                                  {
                                    name: 'key',
                                    title: {
                                      label: '唯一标识',
                                      tip: '筛选项的唯一标识',
                                    },
                                    propType: 'string',
                                    setter: ['StringSetter', 'VariableSetter'],
                                    isRequired: true,
                                  },
                                  {
                                    name: 'label',
                                    title: {
                                      label: '显示标签',
                                      tip: '筛选项的显示文案',
                                    },
                                    propType: 'string',
                                    setter: ['PisellI18nSetter', 'StringSetter', 'VariableSetter'],
                                  },
                                  {
                                    name: 'name',
                                    title: {
                                      label: '字段名称',
                                      tip: '筛选字段的名称，rangePicker 时为数组',
                                    },
                                    propType: {
                                      type: 'oneOfType',
                                      value: ['string', 'array'],
                                    },
                                    setter: ['StringSetter', 'JsonSetter', 'VariableSetter'],
                                  },
                                  {
                                    name: 'props',
                                    title: {
                                      label: '组件属性',
                                      tip: '传递给筛选组件的属性',
                                    },
                                    propType: 'object',
                                    setter: ['JsonSetter', 'VariableSetter'],
                                  },
                                  {
                                    name: 'localFilter',
                                    title: {
                                      label: '本地筛选',
                                      tip: '是否使用本地筛选',
                                    },
                                    propType: 'bool',
                                    setter: ['BoolSetter', 'VariableSetter'],
                                    defaultValue: false,
                                  },
                                  {
                                    name: 'isHidden',
                                    title: {
                                      label: '是否隐藏',
                                      tip: '是否隐藏该筛选项',
                                    },
                                    propType: 'bool',
                                    setter: ['BoolSetter', 'VariableSetter'],
                                    defaultValue: false,
                                  },
                                  {
                                    name: 'other',
                                    title: {
                                      label: '其他配置',
                                      tip: '其他扩展配置',
                                    },
                                    propType: 'object',
                                    setter: ['JsonSetter', 'VariableSetter'],
                                  },
                                ],
                              },
                            },
                            initialValue: {
                              type: 'single',
                              key: 'filter_item',
                              label: '筛选项',
                              name: 'filter_field',
                              props: {},
                              other: {},
                            },
                          },
                        },
                      },
                    },
                    {
                      name: 'otherFilter',
                      title: {
                        label: {
                          type: 'i18n',
                          'en-US': 'Other Filter',
                          'zh-CN': '高级筛选',
                        },
                        tip: '高级筛选项数组',
                      },
                      propType: {
                        type: 'arrayOf',
                        value: 'object',
                      },
                      setter: {
                        componentName: 'ArraySetter',
                        props: {
                          itemSetter: {
                            componentName: 'ObjectSetter',
                            props: {
                              config: {
                                items: [
                                  {
                                    name: 'type',
                                    title: {
                                      label: '筛选类型',
                                      tip: '筛选组件的类型',
                                    },
                                    propType: {
                                      type: 'oneOf',
                                      value: ['single', 'input', 'datePicker', 'rangePicker', 'search'],
                                    },
                                    setter: {
                                      componentName: 'SelectSetter',
                                      props: {
                                        options: [
                                          { title: '单选', value: 'single' },
                                          { title: '输入框', value: 'input' },
                                          { title: '日期选择', value: 'datePicker' },
                                          { title: '日期范围', value: 'rangePicker' },
                                          { title: '搜索框', value: 'search' },
                                        ],
                                      },
                                    },
                                    isRequired: true,
                                  },
                                  {
                                    name: 'key',
                                    title: {
                                      label: '唯一标识',
                                      tip: '筛选项的唯一标识',
                                    },
                                    propType: 'string',
                                    setter: ['StringSetter', 'VariableSetter'],
                                    isRequired: true,
                                  },
                                  {
                                    name: 'label',
                                    title: {
                                      label: '显示标签',
                                      tip: '筛选项的显示文案',
                                    },
                                    propType: 'string',
                                    setter: ['PisellI18nSetter', 'StringSetter', 'VariableSetter'],
                                  },
                                  {
                                    name: 'name',
                                    title: {
                                      label: '字段名称',
                                      tip: '筛选字段的名称，rangePicker 时为数组',
                                    },
                                    propType: {
                                      type: 'oneOfType',
                                      value: ['string', 'array'],
                                    },
                                    setter: ['StringSetter', 'JsonSetter', 'VariableSetter'],
                                  },
                                  {
                                    name: 'props',
                                    title: {
                                      label: '组件属性',
                                      tip: '传递给筛选组件的属性',
                                    },
                                    propType: 'object',
                                    setter: ['JsonSetter', 'VariableSetter'],
                                  },
                                  {
                                    name: 'localFilter',
                                    title: {
                                      label: '本地筛选',
                                      tip: '是否使用本地筛选',
                                    },
                                    propType: 'bool',
                                    setter: ['BoolSetter', 'VariableSetter'],
                                    defaultValue: false,
                                  },
                                  {
                                    name: 'isHidden',
                                    title: {
                                      label: '是否隐藏',
                                      tip: '是否隐藏该筛选项',
                                    },
                                    propType: 'bool',
                                    setter: ['BoolSetter', 'VariableSetter'],
                                    defaultValue: false,
                                  },
                                  {
                                    name: 'other',
                                    title: {
                                      label: '其他配置',
                                      tip: '其他扩展配置',
                                    },
                                    propType: 'object',
                                    setter: ['JsonSetter', 'VariableSetter'],
                                  },
                                ],
                              },
                            },
                            initialValue: {
                              type: 'input',
                              key: 'filter_item',
                              label: '筛选项',
                              name: 'filter_field',
                              props: {},
                              other: {},
                            },
                          },
                        },
                      },
                    },
                  ],
                },
              },
            },
          },
          {
            name: 'quickFilterMaxLength',
            title: {
              label: {
                type: 'i18n',
                'en-US': 'Quick Filter Max Length',
                'zh-CN': '快速筛选最大数量',
              },
              tip: {
                type: 'i18n',
                'en-US': 'quickFilterMaxLength | Maximum number of quick filter items to display',
                'zh-CN': 'quickFilterMaxLength | 快速筛选最大显示数量',
              },
            },
            propType: 'number',
            setter: ['NumberSetter', 'VariableSetter'],
            defaultValue: 100,
          },
          {
            name: 'formFiltersPrefix',
            title: {
              label: {
                type: 'i18n',
                'en-US': 'Form Filters Prefix',
                'zh-CN': '表单字段前缀',
              },
              tip: {
                type: 'i18n',
                'en-US': 'formFiltersPrefix | Prefix for form field names',
                'zh-CN': 'formFiltersPrefix | 表单字段名称前缀',
              },
            },
            propType: 'string',
            setter: ['StringSetter', 'VariableSetter'],
            defaultValue: '',
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Display',
            'zh-CN': '显示',
          },
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'hiddenQuickFilter',
            title: {
              label: {
                type: 'i18n',
                'en-US': 'Hidden Quick Filter',
                'zh-CN': '隐藏快速筛选',
              },
              tip: {
                type: 'i18n',
                'en-US': 'hiddenQuickFilter | Whether to hide quick filter area',
                'zh-CN': 'hiddenQuickFilter | 是否隐藏快速筛选区域',
              },
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: true,
          },
          {
            name: 'hiddenOtherFilter',
            title: {
              label: {
                type: 'i18n',
                'en-US': 'Hidden Other Filter',
                'zh-CN': '隐藏高级筛选',
              },
              tip: {
                type: 'i18n',
                'en-US': 'hiddenOtherFilter | Whether to hide advanced filter area',
                'zh-CN': 'hiddenOtherFilter | 是否隐藏高级筛选区域',
              },
            },
            propType: 'bool',
            setter: ['BoolSetter', 'VariableSetter'],
            defaultValue: false,
          },
        ],
      },
      {
        title: {
          label: {
            type: 'i18n',
            'en-US': 'Advanced',
            'zh-CN': '高级',
          },
        },
        display: 'block',
        type: 'group',
        items: [
          {
            name: 'renderItem',
            title: {
              label: {
                type: 'i18n',
                'en-US': 'Custom Render',
                'zh-CN': '自定义渲染',
              },
              tip: {
                type: 'i18n',
                'en-US': 'renderItem | Custom render function for filter items',
                'zh-CN': 'renderItem | 自定义筛选项渲染函数',
              },
            },
            propType: 'func',
            setter: {
              componentName: 'FunctionSetter',
              props: {
                template:
                  'renderItem(item, otherProps, ${extParams}){\n// 自定义渲染筛选项\nreturn null;\n}',
              },
            },
          },
        ],
      },
    ],
    supports: {
      style: true,
      className: true,
      events: [
        {
          name: 'onChange',
          template:
            "onChange(value, ${extParams}){\n// 筛选值改变时的回调\nconsole.log('onChange', value);}",
        },
      ],
    },
    component: {},
  },
};

export default {
  ...PisellFilterMeta,
  snippets,
};
