var _excluded = ["__sourceName", "Component"],
  _excluded2 = ["input"],
  _excluded3 = ["input"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import { Input, InputNumber, Checkbox, Radio, Cascader, DatePicker, Select, Slider, Switch, TimePicker, Transfer, TreeSelect, Upload, Form } from 'antd';
import { CheckboxGroup, RadioGroup } from "../group";
import Surcharge, { getCommName, getCommDefaultVal } from "../surcharge";
import Receipt, { getCommName as getCommNameReceipt, getCommDefaultVal as getCommDefaultValReceipt } from "../receipt";
import DeviceList from "../deviceList";

// 通用表单配置
var Mapping = {
  Input: Input,
  InputNumber: InputNumber,
  Checkbox: Checkbox,
  'Checkbox.Group': CheckboxGroup,
  Radio: Radio,
  'Radio.Group': RadioGroup,
  'Radio.Button': Radio.Button,
  Cascader: Cascader,
  DatePicker: DatePicker,
  Select: Select,
  Slider: Slider,
  Switch: Switch,
  TimePicker: TimePicker,
  Transfer: Transfer,
  TreeSelect: TreeSelect,
  Upload: Upload
};
var CustomMapping = {
  Surcharge: Surcharge,
  DeviceList: DeviceList,
  Receipt: Receipt
};

/**
 * @title: 递归循环表单数据
 * @Author: hongbing.wang
 * @Date: 2024-08-20 13:21
 */
var CustomFormItem = function CustomFormItem(_ref) {
  var formItemList = _ref.formItemList,
    _ref$level = _ref.level,
    level = _ref$level === void 0 ? 0 : _ref$level,
    onChange = _ref.onChange;
  return /*#__PURE__*/React.createElement(React.Fragment, null, formItemList.map(function (_ref2, index) {
    var __sourceName = _ref2.__sourceName,
      Component = _ref2.Component,
      item = _objectWithoutProperties(_ref2, _excluded);
    if (Array.isArray(item.children)) {
      return /*#__PURE__*/React.createElement(CustomFormItem, {
        formItemList: item.children,
        onChange: onChange,
        key: item.name ? "".concat(item.name).concat(level) : "".concat(Component).concat(index).concat(level),
        level: level + 1
      });
    }
    if (_typeof(Component) === 'object') {
      return /*#__PURE__*/React.createElement(Component, _extends({}, item, {
        key: "".concat(item.name).concat(level)
      }));
    }
    if (Mapping[Component]) {
      var Comm = Mapping[Component];
      var input = item.input,
        formItemProps = _objectWithoutProperties(item, _excluded2);
      return /*#__PURE__*/React.createElement(Form.Item, _extends({}, formItemProps, {
        key: "".concat(item.name).concat(level)
      }), /*#__PURE__*/React.createElement(Comm, input));
    }
    if (Mapping[Component]) {
      var _Comm = Mapping[Component];
      var _input = item.input,
        _formItemProps = _objectWithoutProperties(item, _excluded3);
      return /*#__PURE__*/React.createElement(Form.Item, _extends({}, _formItemProps, {
        key: "".concat(item.name).concat(level)
      }), /*#__PURE__*/React.createElement(_Comm, _input));
    }
    if (CustomMapping[Component]) {
      var _Comm2 = CustomMapping[Component];
      return /*#__PURE__*/React.createElement(_Comm2, _extends({}, item, {
        key: "".concat(item.name).concat(level)
      }));
    }
    throw TypeError("pos\u7269\u6599\u5E93 \u8F93\u5165\u7EC4\u4EF6\u7C7B\u578B ".concat(Component, " \u65E0\u6CD5\u6620\u5C04,\u8BF7\u6B63\u786E\u4F20\u5165\u7EC4\u4EF6\u7C7B\u578B"));
  }));
};
export default CustomFormItem;
export var helpMapping = {
  Surcharge: {
    getCommName: getCommName,
    getCommDefaultVal: getCommDefaultVal
  },
  Receipt: {
    getCommName: getCommNameReceipt,
    getCommDefaultVal: getCommDefaultValReceipt
  }
};