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/checkout/components/PaymentOptionsModule/PaymentMethodItem.tsx
var PaymentMethodItem_exports = {};
__export(PaymentMethodItem_exports, {
  default: () => PaymentMethodItem_default
});
module.exports = __toCommonJS(PaymentMethodItem_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_antd = require("antd");
var import_priceKeyboard = require("../../../../pro/priceKeyboard");
var import_index = require("./index.less");
var PaymentMethodItem = ({
  method,
  amountSymbol,
  customAmount,
  disabled = false,
  onClick,
  getText,
  size = "default"
}) => {
  const [isKeyboardVisible, setIsKeyboardVisible] = (0, import_react.useState)(false);
  const calculateSurcharge = (method2) => {
    if (!(method2 == null ? void 0 : method2.is_surcharge)) return 0;
    const baseAmount = Number(customAmount) || 0;
    if (Number(method2.percentage)) {
      return baseAmount * Number(method2.percentage) + Number(method2.fixed || 0);
    }
    return Number(method2.fixed || 0);
  };
  const calculateTotalAmount = (method2) => {
    const baseAmount = Number(customAmount) || 0;
    const surcharge = calculateSurcharge(method2);
    return baseAmount + surcharge;
  };
  const handleRightButtonClick = (e) => {
    if (!isEftpos) return;
    e.preventDefault();
    if (disabled || !onClick) {
      return;
    }
    onClick({
      ...method,
      surcharge: String((0, import_utils.formatAmount)(calculateSurcharge(method), 2, amountSymbol))
    });
  };
  const renderPaymentIcon = (method2) => {
    if (method2.code === "EFTPOS") {
      return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-icon-container"), style: { background: "#FE8279" } }, /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-credit", style: { fontSize: "26px", color: "#ffffff" } }));
    }
    switch (String(method2.type)) {
      case "credit-card":
      case "eftpos":
        return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-icon-container"), style: { background: "#FE8279" } }, /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-credit", style: { fontSize: "26px", color: "#ffffff" } }));
      default:
        return /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-icon-container"), style: { background: "#D277E4" } }, /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-custom", style: { fontSize: "26px", color: "#ffffff" } }));
    }
  };
  const isEftpos = method.code === "EFTPOS" || method.type === "eftpos";
  const showKeyboard = () => {
    if (isEftpos) return;
    setIsKeyboardVisible(true);
  };
  const renderLeftContent = () => /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-payment-method-left") }, /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-icon-container") }, renderPaymentIcon(method)), /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-payment-info") }, /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-payment-info-inner") }, /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-payment-name") }, method.name), /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-payment-info-inner-surcharge") }, !!(method == null ? void 0 : method.is_surcharge) && calculateSurcharge(method) !== 0 && /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-surcharge-text") }, (getText == null ? void 0 : getText("pisell2.payment-options.surcharge-label", "Surcharge")) || "Surcharge", ":", (0, import_utils.formatAmount)(calculateSurcharge(method), 2, amountSymbol)), false))));
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      className: (0, import_classnames.default)(
        "payment-options-module-payment-method-item",
        {
          "payment-options-module-pointer": !disabled,
          "payment-options-module-disabled": disabled
        }
      ),
      style: {
        height: size === "large" ? "82px" : "62px"
      },
      onClick: showKeyboard,
      type: "button",
      disabled
    },
    renderLeftContent(),
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      { className: (0, import_classnames.default)("payment-options-module-payment-method-right"), onClick: handleRightButtonClick },
      // 右侧按钮，如果是eftpos，则显示Pay按钮
      isEftpos ? /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "primary", className: (0, import_classnames.default)("payment-options-module-pay-button"), disabled }, getText == null ? void 0 : getText("pay", "Pay")) : /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)(
            "payment-options-module-selection-button"
          )
        },
        /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-a-arrow-circle-right2", style: { fontSize: "30px", color: disabled ? "#D0D5DD" : "#7F56DA" } })
      )
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    import_priceKeyboard.PaymentKeyboard,
    {
      containerProps: {
        renderType: "modal",
        open: isKeyboardVisible,
        onCancel: () => setIsKeyboardVisible(false)
      },
      paymentOriginalValue: String(customAmount || 0),
      paymentDefaultValue: String(customAmount || 0),
      enableExceedMaxAmount: !isEftpos,
      payment: {
        enable: true
      },
      surcharge: {
        enable: !!(method == null ? void 0 : method.is_surcharge) && calculateSurcharge(method) !== 0
      },
      surchargeDefaultValue: {
        percent: method.percentage ? String(Number(method.percentage) * 100) : "",
        fixed: method.fixed ? String(method.fixed) : ""
      },
      selectType: "dark",
      onChange: (value) => {
        console.log(value);
      },
      onPay: (args) => {
        var _a, _b;
        console.log(args);
        setIsKeyboardVisible(false);
        if (onClick) {
          onClick({
            ...method,
            fixed: Number(((_a = args.surcharge) == null ? void 0 : _a.fixed) || 0),
            percentage: ((_b = args.surcharge) == null ? void 0 : _b.percent) ? Number(args.surcharge.percent) / 100 : 0,
            totalAmount: String((0, import_utils.formatAmount)(args.amount, 2))
          });
        }
      }
    }
  ));
};
var PaymentMethodItem_default = PaymentMethodItem;
