var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/eftpos/surcharge/index.tsx
var surcharge_exports = {};
__export(surcharge_exports, {
  default: () => surcharge_default,
  getCommDefaultVal: () => getCommDefaultVal,
  getCommName: () => getCommName
});
module.exports = __toCommonJS(surcharge_exports);
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_index = require("./index.css");
var 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;
};
var 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
  };
};
var surcharge_default = (props) => {
  var _a, _b, _c, _d;
  const { origin, top, left, right } = props;
  const leftRef = (0, import_react.useRef)(left.input.default || 0);
  const rightRef = (0, import_react.useRef)(right.input.default || 0);
  const [statusOrigin, setStatusOrigin] = (0, import_react.useState)(origin.input.defaultValue);
  const [status, setStatus] = (0, import_react.useState)(top.input.defaultValue);
  const context = (0, import_useEngineContext.default)();
  const { store } = ((_a = context.appHelper) == null ? void 0 : _a.utils) || {};
  const symbol = ((_d = (_c = (_b = store == null ? void 0 : store.getState) == null ? void 0 : _b.call(store)) == null ? void 0 : _c.global) == null ? void 0 : _d.symbol) || "$";
  const onValueChange = (e) => {
    setStatus(e.target.value);
  };
  const onChangeRate = (val) => {
    leftRef.current = val;
  };
  const onChangeMoney = (val) => {
    rightRef.current = val;
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__pos_sur_box" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      label: origin.label,
      name: origin.name,
      rules: origin.rules || [],
      style: origin.style || {}
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Radio.Group,
      {
        value: origin.input.defaultValue,
        onChange: (e) => {
          setStatusOrigin(e.target.value);
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { direction: "vertical" }, origin.input.options.map((item) => {
        if (typeof item === "object") {
          const { label, value, ...other } = item;
          return /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { ...other, value, key: `${item.value}` }, label);
        }
      }))
    )
  ), /* @__PURE__ */ import_react.default.createElement("div", { style: { display: statusOrigin ? "none" : "contents" } }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { label: top.label, name: top.name, rules: top.rules || [], style: top.style || {} }, /* @__PURE__ */ import_react.default.createElement(import_antd.Radio.Group, { value: top.input.defaultValue, onChange: onValueChange }, /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { direction: "vertical" }, top.input.options.map((item) => {
    if (typeof item === "object") {
      const { label, value, ...other } = item;
      return /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { ...other, value, key: `${item.value}` }, label);
    }
  })))), status ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__pos_row" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      label: left.label,
      name: left.name,
      rules: left.rules || [],
      style: left.style || {}
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.InputNumber,
      {
        min: 0,
        max: 100,
        precision: 2,
        addonAfter: "%",
        controls: false,
        defaultValue: leftRef.current,
        onChange: onChangeRate
      }
    )
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__pos_sur" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      label: right.label,
      name: right.name,
      rules: right.rules || [],
      style: right.style || {}
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.InputNumber,
      {
        min: 0,
        max: 1e5,
        precision: 2,
        addonBefore: symbol,
        controls: false,
        defaultValue: rightRef.current,
        onChange: onChangeMoney
      }
    )
  ))) : null));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getCommDefaultVal,
  getCommName
});
