import snippets from './snippets';

export default {
  snippets,
  componentName: 'PisellInformationEntry',
  title: '信息录入',
  category: '表单',
  docUrl: '',
  screenshot: '',
  devMode: 'proCode',
  npm: {
    package: '@pisell/materials',
    version: '1.0.1',
    exportName: 'PisellInformationEntry',
    main: 'src/index.tsx',
    destructuring: true,
    subName: '',
  },
  props: [
    {
      name: 'entryModes',
      title: { label: '录入方式', tip: '录入方式' },
      propType: {
        type: 'arrayOf',
        value: {
          type: 'shape',
          value: [
            {
              name: 'type',
              title: { label: '录入类型', tip: '录入类型' },
              propType: {
                type: 'oneOf',
                value: ['scanCode', 'input', 'scanner', 'nfc'],
              },
            },
            {
              name: 'name',
              propType: ['string', 'number'],
              description: '文案',
              defaultValue: '选项值',
            },
            {
              name: 'disabled',
              propType: 'bool',
              description: '是否禁用',
              defaultValue: false,
            },
          ],
        },
      },
      setter: {
        componentName: 'ArraySetter',
        props: {
          itemSetter: {
            componentName: 'ObjectSetter',
            props: {
              config: {
                items: [
                  {
                    name: 'type',
                    title: '录入类型',
                    isRequired: true,
                    setter: [
                      {
                        componentName: 'SelectSetter',
                        mode: 'single',
                        props: (target) => {
                          // console.log(target,'targettarget',target.parent.parent.parent.getPropValue("entryModes"));
                          const typeValues = target.parent.parent.parent
                            .getPropValue('entryModes')
                            .filter(Boolean)
                            .map((item) => item?.type);
                          console.log(typeValues, 'typeValues');
                          return {
                            options: [
                              {
                                title: '扫码',
                                value: 'scanCode',
                                disabled: typeValues.includes('scanCode'),
                              },
                              {
                                title: '手动输入',
                                value: 'input',
                                disabled: typeValues.includes('input'),
                              },
                              {
                                title: '扫描枪（外设）',
                                value: 'scanner',
                                disabled: typeValues.includes('scanner'),
                              },
                              {
                                title: 'NFC（外设）',
                                value: 'nfc',
                                disabled: typeValues.includes('nfc'),
                              },
                            ],
                          };
                        },
                      },
                      'VariableSetter',
                    ],
                  },
                  {
                    name: 'name',
                    title: '文案',
                    setter: ['StringSetter', 'NumberSetter', 'VariableSetter'],
                    isRequired: true,
                  },
                ],
              },
            },
            initialValue: {
              type: '',
              name: '',
            },
          },
        },
      },
    },
    {
      name: 'title',
      title: { label: '标题文案', tip: '标题文案' },
      propType: { type: 'oneOfType', value: ['string', 'node'] },
      setter: ['PisellI18nSetter', 'SlotSetter'],
    },
    {
      name: 'searchDescribe',
      title: { label: '搜索框描述文案', tip: '搜索框描述文案' },
      propType: { type: 'oneOfType', value: ['string', 'node'] },
      setter: ['PisellI18nSetter', 'SlotSetter'],
    },
  ],

  configure: {
    supports: {
      style: true,
      events: [
        {
          name: 'onChange',
          template:
            "onChange(event,${extParams}){\n// 输入框内容变化时的回调\nconsole.log('onChange',event);}",
        },
      ],
    },
  },
};
