var _excluded = ["label", "value"],
  _excluded2 = ["label", "value"];
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 _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; }
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import { Form, Space, Radio, InputNumber } from 'antd';
import React, { useState, useRef } from 'react';
import useEngineContext from "../../../hooks/useEngineContext";
import "./index.css";

/**
 * @title: 自定义组件设置
 * @description: 自定义组件设置
 * @param {any} commConfig 当前组件配置
 * @param {string} name 上游name(用于嵌套 xxx:{yyy:''})
 * @return {*}
 * @Author: hongbing.wang
 * @Date: 2024-08-20 11:10
 */
export var getCommName = function getCommName(commConfig, name) {
  commConfig.origin.__sourceName = commConfig.origin.name;
  commConfig.top.__sourceName = commConfig.top.name;
  commConfig.left.__sourceName = commConfig.left.name;
  commConfig.right.__sourceName = commConfig.right.name;
  commConfig.origin.name = name.length > 0 ? [].concat(_toConsumableArray(name), [commConfig.origin.name]) : commConfig.origin.name;
  commConfig.top.name = name.length > 0 ? [].concat(_toConsumableArray(name), [commConfig.top.name]) : commConfig.top.name;
  commConfig.left.name = name.length > 0 ? [].concat(_toConsumableArray(name), [commConfig.left.name]) : commConfig.left.name;
  commConfig.right.name = name.length > 0 ? [].concat(_toConsumableArray(name), [commConfig.right.name]) : commConfig.right.name;
  return commConfig;
};

/**
 * @title: 自定义组件结果设置
 * @description: 自定义组件结果设置
 * @param {any} commConfig 当前组件配置
 * @return {*}
 * @Author: hongbing.wang
 * @Date: 2024-08-20 11:11
 */
export var getCommDefaultVal = function getCommDefaultVal(commConfig) {
  var top = commConfig.top.input.defaultValue;
  var origin = commConfig.origin.input.defaultValue;
  return _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, commConfig.origin.__sourceName, typeof origin === 'undefined' ? false : origin), commConfig.top.__sourceName, typeof top === 'undefined' ? true : top), commConfig.left.__sourceName, commConfig.left.input.defaultValue || 0), commConfig.right.__sourceName, commConfig.right.input.defaultValue || 0);
};

/**
 * @title: 自定义表单
 * @description: 若干 antd 组件不能满足需求 则可以创建自定义组件
 * @Author: hongbing.wang
 * @Date: 2024-08-20 13:22
 */
export default (function (props) {
  var _context$appHelper, _store$getState;
  var origin = props.origin,
    top = props.top,
    left = props.left,
    right = props.right;
  var leftRef = useRef(left.input.default || 0);
  var rightRef = useRef(right.input.default || 0);
  var _useState = useState(origin.input.defaultValue),
    _useState2 = _slicedToArray(_useState, 2),
    statusOrigin = _useState2[0],
    setStatusOrigin = _useState2[1];
  var _useState3 = useState(top.input.defaultValue),
    _useState4 = _slicedToArray(_useState3, 2),
    status = _useState4[0],
    setStatus = _useState4[1];
  var context = useEngineContext();
  var _ref2 = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {},
    store = _ref2.store;
  var symbol = (store === null || store === void 0 || (_store$getState = store.getState) === null || _store$getState === void 0 || (_store$getState = _store$getState.call(store)) === null || _store$getState === void 0 || (_store$getState = _store$getState.global) === null || _store$getState === void 0 ? void 0 : _store$getState.symbol) || '$';

  /**
   * @title: 是否设置手续费
   * @Author: hongbing.wang
   * @Date: 2024-08-20 11:12
   */
  var onValueChange = function onValueChange(e) {
    setStatus(e.target.value);
  };

  /**
   * @title: 设置比例手续费
   * @Author: hongbing.wang
   * @Date: 2024-08-20 11:13
   */
  var onChangeRate = function onChangeRate(val) {
    leftRef.current = val;
  };

  /**
   * @title:  设置固定金额手续费
   * @Author: hongbing.wang
   * @Date: 2024-08-20 11:13
   */
  var onChangeMoney = function onChangeMoney(val) {
    rightRef.current = val;
  };

  // status : true 使用手续费 展示 手续费 组件; false 不是用手续费 不是展示 手续费 组件
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__pos_sur_box"
  }, /*#__PURE__*/React.createElement(Form.Item, {
    label: origin.label,
    name: origin.name,
    rules: origin.rules || [],
    style: origin.style || {}
  }, /*#__PURE__*/React.createElement(Radio.Group, {
    value: origin.input.defaultValue,
    onChange: function onChange(e) {
      setStatusOrigin(e.target.value);
    }
  }, /*#__PURE__*/React.createElement(Space, {
    direction: "vertical"
  }, origin.input.options.map(function (item) {
    if (_typeof(item) === 'object') {
      var label = item.label,
        value = item.value,
        other = _objectWithoutProperties(item, _excluded);
      return /*#__PURE__*/React.createElement(Radio, _extends({}, other, {
        value: value,
        key: "".concat(item.value)
      }), label);
    }
  })))), /*#__PURE__*/React.createElement("div", {
    style: {
      display: statusOrigin ? 'none' : 'contents'
    }
  }, /*#__PURE__*/React.createElement(Form.Item, {
    label: top.label,
    name: top.name,
    rules: top.rules || [],
    style: top.style || {}
  }, /*#__PURE__*/React.createElement(Radio.Group, {
    value: top.input.defaultValue,
    onChange: onValueChange
  }, /*#__PURE__*/React.createElement(Space, {
    direction: "vertical"
  }, top.input.options.map(function (item) {
    if (_typeof(item) === 'object') {
      var label = item.label,
        value = item.value,
        other = _objectWithoutProperties(item, _excluded2);
      return /*#__PURE__*/React.createElement(Radio, _extends({}, other, {
        value: value,
        key: "".concat(item.value)
      }), label);
    }
  })))), status ? /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__pos_row"
  }, /*#__PURE__*/React.createElement(Form.Item, {
    label: left.label,
    name: left.name,
    rules: left.rules || [],
    style: left.style || {}
  }, /*#__PURE__*/React.createElement(InputNumber, {
    min: 0,
    max: 100,
    precision: 2,
    addonAfter: '%',
    controls: false,
    defaultValue: leftRef.current,
    onChange: onChangeRate
  })), /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__pos_sur"
  }, /*#__PURE__*/React.createElement(Form.Item, {
    label: right.label,
    name: right.name,
    rules: right.rules || [],
    style: right.style || {}
  }, /*#__PURE__*/React.createElement(InputNumber, {
    min: 0,
    max: 100000,
    precision: 2,
    addonBefore: symbol,
    controls: false,
    defaultValue: rightRef.current,
    onChange: onChangeMoney
  })))) : null));
});