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/pay/toC/WalletPassBlock/index.tsx
var WalletPassBlock_exports = {};
__export(WalletPassBlock_exports, {
  default: () => WalletPassBlock_default
});
module.exports = __toCommonJS(WalletPassBlock_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_WalletPass = __toESM(require("../PaymentMethods/WalletPass"));
var import_WalletAvailable = __toESM(require("./components/WalletAvailable"));
var import_WalletBestValueFound = __toESM(require("./components/WalletBestValueFound"));
var import_WalletUseList = __toESM(require("./components/WalletUseList"));
var import_index = require("./index.less");
var import_icons = require("@ant-design/icons");
var WalletPassBlock = (props, ref) => {
  var _a, _b, _c, _d, _e;
  const {
    className,
    payGroup,
    onWalletPassChange,
    customer_id,
    walletSetting,
    ...others
  } = props;
  const walletPassRef = (0, import_react.useRef)(null);
  const walletAvailableRef = (0, import_react.useRef)(null);
  const walletBestValueFoundRef = (0, import_react.useRef)(null);
  const [isViewDetail, setIsViewDetail] = (0, import_react.useState)(false);
  const contentRef = (0, import_react.useRef)(null);
  const [contentHeight, setContentHeight] = (0, import_react.useState)(0);
  (0, import_react.useEffect)(() => {
    if (contentRef.current) {
      const scrollHeight = contentRef.current.scrollHeight;
      setContentHeight(isViewDetail ? scrollHeight : 0);
    }
  }, [isViewDetail, (_a = payGroup == null ? void 0 : payGroup.walletPass) == null ? void 0 : _a.cards]);
  const handleClick = () => {
    var _a2;
    setIsViewDetail(false);
    (_a2 = walletPassRef.current) == null ? void 0 : _a2.init({ ...payGroup, customer_id });
  };
  const hasNoWalletPassAmount = (0, import_react.useMemo)(() => {
    var _a2, _b2;
    return !((_a2 = payGroup == null ? void 0 : payGroup.walletPass) == null ? void 0 : _a2.amount) || ((_b2 = payGroup == null ? void 0 : payGroup.walletPass) == null ? void 0 : _b2.amount) == 0;
  }, [(_b = payGroup == null ? void 0 : payGroup.walletPass) == null ? void 0 : _b.amount]);
  (0, import_react.useImperativeHandle)(ref, () => ({
    open: () => {
      var _a2, _b2;
      if (hasNoWalletPassAmount) {
        (_a2 = walletAvailableRef.current) == null ? void 0 : _a2.open();
      } else {
        (_b2 = walletBestValueFoundRef.current) == null ? void 0 : _b2.open();
      }
    }
  }));
  const handleViewDetail = (e) => {
    e.stopPropagation();
    setIsViewDetail(!isViewDetail);
  };
  const handleUnused = () => {
    onWalletPassChange == null ? void 0 : onWalletPassChange({
      cards: [],
      amount: 0
    });
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { ...others, className: (0, import_classnames.default)("wallet-pass-wrap", className) }, /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-title" }, import_utils.locales.getText("tocPay.text.howToPay")), /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellRow,
    {
      className: "wallet-pass-card",
      centerContent: /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-title" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-title-left" }, /* @__PURE__ */ import_react.default.createElement(
        import_materials.Icon,
        {
          type: "pisell2-a-wallet-021",
          className: "wallet-pass-card-title-left-icon"
        }
      ), walletSetting.name), walletSetting.popup_status === 1 && /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-title-right" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "wallet-pass-card-title-right-amount" }, "-", /* @__PURE__ */ import_react.default.createElement(import_materials.PisellText.Amount, { value: (_c = payGroup == null ? void 0 : payGroup.walletPass) == null ? void 0 : _c.amount })), /* @__PURE__ */ import_react.default.createElement(import_icons.CaretRightOutlined, { className: "wallet-pass-card-title-right-icon" }))), walletSetting.popup_status === 0 && /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-desc-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-desc" }, hasNoWalletPassAmount ? import_utils.locales.getText(
        "tocPay.text.hasNoWalletPassAmount"
      ) : import_utils.locales.getText("tocPay.text.bestValueFound")), !hasNoWalletPassAmount && /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-total-savings" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-total-savings-title" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "wallet-pass-card-total-savings-title-left" }, import_utils.locales.getText("tocPay.text.totalSavings"), ":", /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellText.Amount,
        {
          value: (_d = payGroup == null ? void 0 : payGroup.walletPass) == null ? void 0 : _d.amount
        }
      )), /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: "wallet-pass-card-total-savings-title-right",
          onClick: handleViewDetail
        },
        import_utils.locales.getText("tocPay.text.viewDetail"),
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.Icon,
          {
            type: "pisell2-chevron-down",
            className: (0, import_classnames.default)(
              "wallet-pass-card-total-savings-title-right-icon",
              {
                "is-rotate": isViewDetail
              }
            )
          }
        )
      )), /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          ref: contentRef,
          className: "wallet-pass-card-total-savings-desc",
          style: { height: contentHeight }
        },
        /* @__PURE__ */ import_react.default.createElement(import_WalletUseList.default, { walletPass: ((_e = payGroup == null ? void 0 : payGroup.walletPass) == null ? void 0 : _e.cards) || [] })
      ))), /* @__PURE__ */ import_react.default.createElement(
        import_materials.Button,
        {
          size: "large",
          className: "wallet-pass-card-to-use",
          type: "primary",
          block: true,
          rightIcon: /* @__PURE__ */ import_react.default.createElement(
            import_materials.Iconfont,
            {
              type: "pisell2-arrow-right",
              className: "wallet-pass-card-icon"
            }
          )
        },
        import_utils.locales.getText(
          hasNoWalletPassAmount ? "tocPay.text.useWalletPass" : "tocPay.text.editWalletPass"
        )(walletSetting.name)
      ))),
      padding: 16,
      gap: 4,
      onClick: handleClick
    }
  ), ((payGroup == null ? void 0 : payGroup.wait_amount) || 0) == 0 && /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-complete-title" }, import_utils.locales.getText("tocPay.text.walletPassCompleteTitle")), /* @__PURE__ */ import_react.default.createElement("div", { className: "wallet-pass-card-complete-no-extre-pay" }, import_utils.locales.getText("tocPay.text.walletPassNoExtraPay")))), /* @__PURE__ */ import_react.default.createElement(
    import_WalletPass.default,
    {
      ref: walletPassRef,
      walletSetting,
      onWalletPassChange,
      walletPass: payGroup == null ? void 0 : payGroup.walletPass,
      orderDetail: payGroup == null ? void 0 : payGroup.orderDetail,
      total_amount: payGroup == null ? void 0 : payGroup.total_amount
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_WalletAvailable.default,
    {
      ref: walletAvailableRef,
      walletSetting,
      payGroup,
      onOk: handleClick
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_WalletBestValueFound.default,
    {
      ref: walletBestValueFoundRef,
      walletSetting,
      payGroup,
      onEdit: handleClick,
      onUnused: handleUnused
    }
  ));
};
var WalletPassBlock_default = (0, import_react.forwardRef)(WalletPassBlock);
