import { t } from "../../src/locale";
import { CDefaultValueSetter, CNoDisplayConditionSetter, CStringOnlySetter } from "../_setters";
import snippets from "./snippets";
import { uuid } from "../_utils/utils";
import componentName from "../_com-props/componentName";
import loopData from "../_com-props/loopData";
export default {
  snippets: snippets,
  componentName: 'Form.Item',
  "group": t('formItem.key_lpSbMQByYO1R'),
  title: t('formItem.key_CcOvR3aFkDTf'),
  category: t('formItem.key_Hl0WLqRZMVFV'),
  props: [loopData, {
    name: 'name',
    title: {
      label: t('formItem.key_Odcxqiaf4C31'),
      tip: t('formItem.key_qIdTU37MzrIg')
    },
    isRequired: true,
    propType: 'string',
    setter: CStringOnlySetter,
    defaultValue: function defaultValue() {
      return "cr_" + uuid();
    },
    supportVariable: false,
    extraProps: {
      setValue: function setValue(target, value) {
        if (value !== undefined && value !== '') {
          target.parent.setPropValue('componentName', value);
        }
      }
    }
  }, componentName, {
    name: 'label',
    title: {
      label: t('formItem.key_1qHMf0XRLPRD'),
      tip: t('formItem.key_jWLS8S0VdBxb')
    },
    propType: {
      type: 'oneOfType',
      value: ['string', 'node']
    }
  }, {
    name: 'decimals',
    title: {
      label: t('formItem.key_1qHMf0XRCPRD'),
      tip: t('formItem.key_1qHMf0XREPRD')
    },
    propType: 'string',
    display: 'accordion',
    setter: CDefaultValueSetter
  }, {
    name: 'encryption',
    title: {
      label: t('formItem.key_1qHMf0XRCPRF'),
      tip: t('formItem.key_1qHMf0XRCPRF')
    },
    setter: {
      componentName: 'SelectSetter',
      props: {
        options: [{
          title: t('formItem.key_1qHMf0XRCPR1'),
          value: 'default'
        }, {
          title: t('formItem.key_1qHMf0XRCPR2'),
          value: 'md5'
        }]
      }
    },
    defaultValue: 'default'
  }, {
    name: 'defaultObj',
    title: {
      label: t('formItem.key_QSI1IwdCZBNz'),
      tip: t('formItem.key_Jw5lrxi2aV9s')
    },
    propType: 'string',
    display: 'accordion',
    setter: CDefaultValueSetter
  }, {
    name: 'labelAlign',
    title: {
      label: t('formItem.key_EVwjI6Z7MLHa'),
      tip: t('formItem.key_lhWe58vjcH1e')
    },
    propType: {
      type: 'oneOf',
      value: ['left', 'right']
    },
    setter: {
      componentName: 'RadioGroupSetter',
      props: {
        options: [{
          title: t('formItem.key_t2OZ0G7KRVYb'),
          value: 'left'
        }, {
          title: t('formItem.key_Eb4jHUeqnSYf'),
          value: 'right'
        }]
      }
    },
    defaultValue: 'right'
  }, {
    name: 'colon',
    title: {
      label: t('formItem.key_Vh1JLTD3MNXQ'),
      tip: t('formItem.key_pxjlbfeRz5gU')
    },
    propType: 'bool',
    defaultValue: true,
    setter: 'BoolSetter',
    supportVariable: true
  }, {
    name: 'extra',
    title: {
      label: t('formItem.key_RzMp0gLz45YY'),
      tip: t('formItem.key_NWeDRDnpuVAO')
    },
    propType: {
      type: 'oneOfType',
      value: ['string', 'node']
    }
  }, {
    name: 'tooltip',
    title: {
      label: t('formItem.key_OFLBFVQal42s'),
      tip: t('formItem.key_y3B36jbGVA0H')
    },
    propType: {
      type: 'oneOfType',
      value: ['string', 'node']
    }
  }, {
    name: 'required',
    title: {
      label: t('formItem.key_NGs7BG6dntxm'),
      tip: t('formItem.key_inGoLT98lksN')
    },
    propType: 'bool',
    defaultValue: false,
    setter: 'BoolSetter',
    supportVariable: true
  },
  // {
  //   name: 'initialValue',
  //   title: {
  //     label: t('formItem.key_tvyW2FVSGFsx'),
  //     tip: t('formItem.key_cuCBcRzwYdSn'),
  //   },
  //   propType: 'string',
  //   setter: 'StringSetter',
  //   supportVariable: true
  // },
  {
    name: 'noStyle',
    title: {
      label: t('formItem.key_OS3LNtZISRn8'),
      tip: t('formItem.key_arZtcshspFm1')
    },
    propType: 'bool',
    defaultValue: false,
    setter: 'BoolSetter',
    supportVariable: true
  }, {
    name: 'valuePropName',
    title: {
      label: t('formItem.key_7ETdKPYXMRLS'),
      tip: "\u5B50\u8282\u70B9\u7684\u503C\u7684\u5B57\u6BB5\uFF0C\u5982 Switch \u7684\u662F 'checked'"
    },
    propType: 'string',
    defaultValue: 'value',
    setter: 'StringSetter',
    supportVariable: true,
    condition: function condition() {
      return false;
    }
  }, {
    name: 'getValueFromEvent',
    title: {
      label: t('formItem.key_jQcHRpPdZCOw'),
      tip: "\u8BBE\u7F6E\u5982\u4F55\u5C06 event \u7684\u503C\u8F6C\u6362\u6210\u5B57\u6BB5\u503C\uFF0C\u5982\u5C06\u4E0A\u4F20\u7EC4\u4EF6\u7684fileList\u4F5C\u4E3Avalue\u503C\u4F20\u51FA"
    },
    propType: 'func',
    condition: function condition() {
      return false;
    }
  }, {
    name: 'noDisplayCondition',
    title: {
      label: t('formItem.key_1ToJQ4QMi7fX'),
      tip: t('formItem.key_OeBMlQ6rWQtt')
    },
    setter: CNoDisplayConditionSetter
  },
  // {
  //   type: 'group',
  //   title: t('formItem.key_d9bG4Iw7D9hj'),
  //   display: 'accordion',
  //   items: [
  //     {
  //       name: 'labelCol',
  //       title: t('formItem.key_N1FyEfsgjHt9'),
  //       display: 'inline',
  //       setter: {
  //         componentName: 'ObjectSetter',
  //         props: {
  //           config: {
  //             items: [
  //               {
  //                 name: 'span',
  //                 title: t('formItem.key_qiySUxIKmp5D'),
  //                 setter: {
  //                   componentName: 'NumberSetter',
  //                   props: {
  //                     min: 0,
  //                     max: 24,
  //                   },
  //                 },
  //               },
  //               {
  //                 name: 'offset',
  //                 title: t('formItem.key_SkMUImHUj1lr'),
  //                 setter: {
  //                   componentName: 'NumberSetter',
  //                   props: {
  //                     min: 0,
  //                     max: 24,
  //                   },
  //                 },
  //               },
  //             ],
  //           },
  //         },
  //       },
  //       description:
  //         t('formItem.key_9KMnPPlkDwol'),
  //     },
  //     {
  //       name: 'wrapperCol',
  //       title: t('formItem.key_7369hcFiGGEQ'),
  //       display: 'inline',
  //       setter: {
  //         componentName: 'ObjectSetter',
  //         props: {
  //           config: {
  //             items: [
  //               {
  //                 name: 'span',
  //                 title: t('formItem.key_MX1fGyaEK6wI'),
  //                 setter: {
  //                   componentName: 'NumberSetter',
  //                   props: {
  //                     min: 0,
  //                     max: 24,
  //                   },
  //                 },
  //               },
  //               {
  //                 name: 'offset',
  //                 title: t('formItem.key_Qc1jsTNt0QUi'),
  //                 setter: {
  //                   componentName: 'NumberSetter',
  //                   props: {
  //                     min: 0,
  //                     max: 24,
  //                   },
  //                 },
  //               },
  //             ],
  //           },
  //         },
  //       },
  //       description: t('formItem.key_aTTuMWgUYo0w'),
  //     },
  //   ],
  // },
  // {
  //   name: 'requiredobj',
  //   title: { label: t('formItem.key_SSsDLMifKOvf'), tip: t('formItem.key_uIrTi90sPgzW') },
  //   propType: {
  //     type: 'shape',
  //     value: [
  //       {
  //         name: 'required',
  //         title: t('formItem.key_SGQXongielsQ'),
  //         propType: 'bool',
  //         setter: 'BoolSetter',
  //         supportVariable: true,
  //         extraProps: {
  //           setValue(target: any, value: boolean) {
  //             // 同步 必填标记
  //             target.parent.parent.setPropValue('required', value);
  //           }
  //         }
  //       },
  //       {
  //         name: 'message',
  //         title: t('formItem.key_nmywLqM4jBId'),
  //         propType: 'string',
  //         setter: 'StringSetter',
  //         supportVariable: true
  //       },
  //     ],
  //   },
  // },
  {
    name: 'typeObj',
    title: {
      label: t('formItem.key_wbs3ymuUH0Bk'),
      tip: t('formItem.key_TytYzP0ar1LZ')
    },
    display: 'accordion',
    setter: {
      componentName: 'ObjectSetter',
      props: {
        config: {
          items: [{
            name: 'type',
            title: t('formItem.key_jQ46I8cUYLev'),
            defaultValue: function defaultValue() {
              return 'text';
            },
            setter: {
              componentName: 'SelectSetter',
              props: {
                options: [{
                  title: t('formItem.key_fqp7frPT2taT'),
                  value: 'text'
                }, {
                  title: t('formItem.key_EBfpKZqzM7Zt'),
                  value: 'email'
                }, {
                  title: t('formItem.key_qjth4cP2bdDh'),
                  value: 'url'
                }, {
                  title: t('formItem.key_qjth4cP2bnum'),
                  value: 'number'
                }, {
                  title: t('formItem.key_qjth4cP2pass'),
                  value: 'password'
                }]
              },
              initialValue: 'text'
            }
          }, {
            name: 'message',
            title: t('formItem.key_R9rE0kvqZCXz'),
            setter: 'DictionarySetter',
            propType: 'string',
            defaultValue: ''
          }]
        }
      }
    }
  }
  // {
  //   name: 'lenobj',
  //   title: { label: t('formItem.key_WDsiK19ME0Yl'), tip: t('formItem.key_byOFrSvcWJ1H') },
  //   propType: {
  //     type: 'shape',
  //     value: [
  //       // { name: 'len', title: t('formItem.key_VEUOUPRU7vDz'), propType: 'string' },
  //       { name: 'max', title: t('formItem.key_iVbNBx7s1Tf6'), propType: 'number' },
  //       { name: 'min', title: t('formItem.key_fgflprQmA5hs'), propType: 'number' },
  //       { name: 'message', title: t('formItem.key_cRchMPELM8su'), propType: 'string' },
  //     ],
  //   },
  // },
  // {
  //   name: 'patternobj',
  //   title: { label: t('formItem.key_zQ91xrkRUJIB'), tip: t('formItem.key_ls9kg1rtOS6g') },
  //   propType: {
  //     type: 'shape',
  //     value: [
  //       { name: 'pattern', title: t('formItem.key_d2fYCU4fB4T6'), propType: 'string' },
  //       { name: 'message', title: t('formItem.key_wceRdFeKJY8I'), propType: 'string' },
  //     ],
  //   },
  // },
  // {
  //   name: 'validator',
  //   title: {
  //     label: t('formItem.key_3ju24RQdEy9r'),
  //     tip: t('formItem.key_8CfvpgMqIsa7'),
  //   },
  //   propType: 'func',
  // },
  ],
  configure: {
    component: {
      isContainer: true,
      nestingRule: {
        childWhitelist: ['Input', "Input.Password", "InputNumber", "Input.Search", "Input.TextArea"],
        parentWhitelist: []
      }
    },
    supports: {
      events: false,
      style: true,
      "loop": false,
      "condition": false
    },
    advanced: {
      callbacks: {
        onNodeRemove: function onNodeRemove(removedNode, currentNode) {
          if (!removedNode || !currentNode) {
            return;
          }
          var children = currentNode.children;
          // 若无children,则说明当前P组件内已为空,需要删除P组件本身
          if (children && children.length === 0) {
            currentNode.remove();
          }
        }
      }
    }
  }
};