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/eftposPay/mx51/Action.tsx
var Action_exports = {};
__export(Action_exports, {
  default: () => Action_default
});
module.exports = __toCommonJS(Action_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_types = require("./types");
var Action = (props) => {
  var _a, _b;
  const { data, cancelDisabled = false, isLoading = false } = props;
  const [inputValues, setInputValues] = (0, import_react.useState)({});
  const inputValuesRef = (0, import_react.useRef)(inputValues);
  (0, import_react.useEffect)(() => {
    var _a2;
    if (!data) return;
    const inputObj = {};
    (_a2 = data == null ? void 0 : data.layouts) == null ? void 0 : _a2.forEach((item) => {
      var _a3;
      (_a3 = item == null ? void 0 : item.elements) == null ? void 0 : _a3.forEach((element) => {
        if ((element == null ? void 0 : element.type) === "input" && (element == null ? void 0 : element.name)) {
          inputObj[element == null ? void 0 : element.name] = inputValuesRef.current[element == null ? void 0 : element.name] || "";
        }
      });
    });
    setInputValues(inputObj);
  }, [data]);
  (0, import_react.useEffect)(() => {
    inputValuesRef.current = inputValues;
  }, [inputValues]);
  const handleInputChange = (key, value) => {
    setInputValues((prev) => ({ ...prev, [key]: value }));
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, isLoading && (data == null ? void 0 : data.message) && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item pisell-lowcode__eft-pay-step-item-tip" }, data == null ? void 0 : data.message), ((_a = data == null ? void 0 : data.layouts) == null ? void 0 : _a.length) > 0 ? /* @__PURE__ */ import_react.default.createElement("div", { style: { maxWidth: "100%", width: "100%" } }, (_b = data == null ? void 0 : data.layouts) == null ? void 0 : _b.map((item, index) => {
    var _a2;
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: index,
        className: "pisell-lowcode__eft-pay-step-item-btns",
        style: {
          marginTop: "20px",
          width: "100%",
          display: "flex",
          justifyContent: "center"
        }
      },
      (_a2 = item == null ? void 0 : item.elements) == null ? void 0 : _a2.map((element) => {
        const { key, label, type, text, name } = element;
        if (type === "button") {
          return /* @__PURE__ */ import_react.default.createElement(
            import_antd.Button,
            {
              key: key + label,
              block: true,
              className: "pisell-lowcode__eft-pay-step-item-btn",
              onClick: () => {
                var _a3;
                return (_a3 = props == null ? void 0 : props.onClick) == null ? void 0 : _a3.call(props, element, { inputValues });
              },
              disabled: key === import_types.EButtonKeyType.CancelTransaction ? cancelDisabled : false
            },
            element.label
          );
        } else if (type === "text") {
          return /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              key: key + label,
              className: "pisell-lowcode__eft-pay-step-item-tip"
            },
            label ? `${label}: ` : "",
            text || ""
          );
        } else if (type === "image") {
          const { name: name2, data: data2, encoding } = (element == null ? void 0 : element.image) || {};
          const imageUrl = data2 ? `data:${name2 || "image/png"};${encoding || "base64"},${data2}` : "";
          return /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              style: {
                width: "100%",
                display: "flex",
                justifyContent: "center"
              }
            },
            /* @__PURE__ */ import_react.default.createElement("img", { key: key + label, src: imageUrl, alt: label })
          );
        } else if (type === "input") {
          return /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              style: {
                width: "100%",
                display: "flex",
                alignItems: "center",
                flexWrap: "wrap"
              }
            },
            /* @__PURE__ */ import_react.default.createElement("span", { style: { marginRight: "10px" } }, `${label ? `${label} ` : ""}`),
            /* @__PURE__ */ import_react.default.createElement(
              import_antd.Input,
              {
                key: key + label,
                alt: label,
                style: { flex: 1, minWidth: "200px" },
                value: inputValues[name] || "",
                onChange: (e) => handleInputChange(name, e.target.value)
              }
            )
          );
        }
        return null;
      })
    );
  })) : null, (data == null ? void 0 : data.detailsText) && /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-lowcode__eft-pay-step-item pisell-lowcode__eft-pay-step-item-tip",
      style: { marginTop: "24px" }
    },
    data == null ? void 0 : data.detailsText
  ));
};
var Action_default = Action;
