import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import useEngineContext from "../../../hooks/useEngineContext.js";
import React, { useRef, useState } from "react";
import { Form, InputNumber, Radio, Space } from "antd";
import "./index.css";
//#region src/components/eftpos/surcharge/index.tsx
const _excluded = ["label", "value"], _excluded2 = ["label", "value"];
/**
* @title: 自定义组件设置
* @description: 自定义组件设置
* @param {any} commConfig 当前组件配置
* @param {string} name 上游name(用于嵌套 xxx:{yyy:''})
* @return {*}
* @Author: hongbing.wang
* @Date: 2024-08-20 11:10
*/
const 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 ? [...name, commConfig.origin.name] : commConfig.origin.name;
	commConfig.top.name = name.length > 0 ? [...name, commConfig.top.name] : commConfig.top.name;
	commConfig.left.name = name.length > 0 ? [...name, commConfig.left.name] : commConfig.left.name;
	commConfig.right.name = name.length > 0 ? [...name, commConfig.right.name] : commConfig.right.name;
	return commConfig;
};
/**
* @title: 自定义组件结果设置
* @description: 自定义组件结果设置
* @param {any} commConfig 当前组件配置
* @return {*}
* @Author: hongbing.wang
* @Date: 2024-08-20 11:11
*/
const getCommDefaultVal = (commConfig) => {
	const top = commConfig.top.input.defaultValue;
	const origin = commConfig.origin.input.defaultValue;
	return {
		[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
*/
var surcharge_default = (props) => {
	var _context$appHelper, _store$getState;
	const { origin, top, left, right } = props;
	const leftRef = useRef(left.input.default || 0);
	const rightRef = useRef(right.input.default || 0);
	const [statusOrigin, setStatusOrigin] = useState(origin.input.defaultValue);
	const [status, setStatus] = useState(top.input.defaultValue);
	const { store } = ((_context$appHelper = useEngineContext().appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	const 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
	*/
	const onValueChange = (e) => {
		setStatus(e.target.value);
	};
	/**
	* @title: 设置比例手续费
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:13
	*/
	const onChangeRate = (val) => {
		leftRef.current = val;
	};
	/**
	* @title:  设置固定金额手续费
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:13
	*/
	const onChangeMoney = (val) => {
		rightRef.current = val;
	};
	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: (e) => {
			setStatusOrigin(e.target.value);
		}
	}, /* @__PURE__ */ React.createElement(Space, { direction: "vertical" }, origin.input.options.map((item) => {
		if (typeof item === "object") {
			const { label, value } = item, other = _objectWithoutProperties(item, _excluded);
			return /* @__PURE__ */ React.createElement(Radio, _objectSpread2(_objectSpread2({}, other), {}, {
				value,
				key: `${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((item) => {
		if (typeof item === "object") {
			const { label, value } = item, other = _objectWithoutProperties(item, _excluded2);
			return /* @__PURE__ */ React.createElement(Radio, _objectSpread2(_objectSpread2({}, other), {}, {
				value,
				key: `${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: 1e5,
		precision: 2,
		addonBefore: symbol,
		controls: false,
		defaultValue: rightRef.current,
		onChange: onChangeMoney
	})))) : null));
};
//#endregion
export { surcharge_default as default, getCommDefaultVal, getCommName };
