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/adyenScan/Action.tsx
var Action_exports = {};
__export(Action_exports, {
  AdyenScanQrcode: () => AdyenScanQrcode
});
module.exports = __toCommonJS(Action_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_index = require("./index.less");
var import_usePrefix = __toESM(require("../../../hooks/usePrefix"));
var AdyenScanQrcode = ({
  loading,
  qrCode,
  payMethodType,
  isPay,
  message,
  onCancelPay
}) => {
  const prefix = (0, import_usePrefix.default)();
  const [cancelModalOpen, setCancelModalOpen] = (0, import_react.useState)(false);
  const countdownDuration = 5 * 60;
  const [remainingSeconds, setRemainingSeconds] = (0, import_react.useState)(countdownDuration);
  const timerRef = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    if (!qrCode) {
      setRemainingSeconds(countdownDuration);
      return;
    }
    setRemainingSeconds(countdownDuration);
    timerRef.current = setInterval(() => {
      setRemainingSeconds((prev) => {
        if (prev <= 1) {
          timerRef.current && clearInterval(timerRef.current);
          return 0;
        }
        return prev - 1;
      });
    }, 1e3);
    return () => {
      timerRef.current && clearInterval(timerRef.current);
    };
  }, [qrCode]);
  const formattedCountdown = (0, import_react.useMemo)(() => {
    return (0, import_dayjs.default)().startOf("day").add(remainingSeconds, "second").format("mm:ss");
  }, [remainingSeconds]);
  const onCancel = () => {
    setCancelModalOpen(true);
  };
  const onModalCancel = () => {
    setCancelModalOpen(false);
  };
  const onModalOk = () => {
    onCancelPay();
    timerRef.current && clearInterval(timerRef.current);
    setCancelModalOpen(false);
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-adyen-scan-qrcode-container" }, loading ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-adyen-scan-methods-loading-container" }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: { backgroundImage: `url(${prefix}/loading.png)` },
      className: "pisell-lowcode__eft-pay-img pisell-lowcode__eft-pay-load"
    }
  ), /* @__PURE__ */ import_react.default.createElement("span", null, isPay ? import_utils.locales.getText("page.eftpos-pay.adyen.scan.qrcode.processing") : message || "")) : null, qrCode ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-eftpos-pay-adyen-scan-qrcode-title" }, import_utils.locales.getText("page.eftpos-pay.adyen.scan.qrcode.title")(
    payMethodType
  )), /* @__PURE__ */ import_react.default.createElement(import_materials.QRCode, { value: qrCode, size: 240 }), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-adyen-scan-qrcode-timeout" }, import_utils.locales.getText("page.eftpos-pay.adyen.scan.qrcode.timeout")(
    formattedCountdown
  ))) : null, isPay ? /* @__PURE__ */ import_react.default.createElement("div", { style: { width: "100%" } }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      className: "pisell-lowcode__eft-pay-step-item-btn",
      block: true,
      onClick: onCancel
    },
    import_utils.locales.getText("page.eftpos-pay.adyen.scan.cancel-btn")
  )) : null, cancelModalOpen && /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal.Information,
    {
      open: cancelModalOpen,
      title: import_utils.locales.getText(
        "page.eftpos-pay.adyen.scan.cancel-confirm.title"
      ),
      describe: import_utils.locales.getText(
        "page.eftpos-pay.adyen.scan.cancel-confirm.content"
      ),
      okText: import_utils.locales.getText(
        "page.eftpos-pay.adyen.scan.cancel-confirm.ok"
      ),
      cancelText: import_utils.locales.getText(
        "page.eftpos-pay.adyen.scan.cancel-confirm.cancel"
      ),
      okButtonProps: { danger: true },
      onOk: onModalOk,
      onCancel: onModalCancel
    }
  ));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  AdyenScanQrcode
});
