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/huifu/Action.tsx
var Action_exports = {};
__export(Action_exports, {
  NativeDeviceStatus: () => NativeDeviceStatus,
  ScanAction: () => ScanAction
});
module.exports = __toCommonJS(Action_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_index = require("./index.less");
var import_hooks = require("./hooks");
var NativeDeviceStatus = ({
  type,
  status
}) => {
  const iconType = type === "scanner" ? "pisell2-Scanner" : "pisell2-camera";
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-status" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: iconType, style: { fontSize: "40px" } }), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-status-wrapper" }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Iconfont,
    {
      style: {
        borderRadius: "50%",
        background: status ? "#17B26A" : "#F04438",
        color: "#fff"
      },
      type: status ? "pisell2-check" : "pisell2-x-close"
    }
  )));
};
var DEFAULT_SCANNER_CLASS = "pisell-eftpos-pay-huifu-scan-content-scanner";
var ScanAction = ({
  isNativeApp,
  onClose,
  onPayClick,
  onScanCallback
}) => {
  const { scannerStatus } = (0, import_hooks.useScannerDevice)();
  const { cameraStatus, activeCamera } = (0, import_hooks.useCameraDevice)();
  const { scanResult } = (0, import_hooks.useScanListener)();
  const [inputValue, setInputValue] = (0, import_react.useState)("");
  (0, import_react.useEffect)(() => {
    if (!!(scanResult == null ? void 0 : scanResult.value)) {
      onScanCallback(scanResult.value);
    }
  }, [scanResult]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan" }, !isNativeApp ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-header" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-eftpos-pay-huifu-scan-header-title" }, import_utils.locales.getText("page.eftpos-pay.text.huifu.scan.title")), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-eftpos-pay-huifu-scan-header-close",
      onClick: onClose
    },
    /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-x-close", style: { fontSize: "24px" } })
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-header-divider" })) : null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-eftpos-pay-huifu-scan-content",
      style: { paddingTop: isNativeApp ? "0" : "24px" }
    },
    !!isNativeApp && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-content-title" }, import_utils.locales.getText("page.eftpos-pay.text.huifu.scan.title")),
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: `${DEFAULT_SCANNER_CLASS} ${DEFAULT_SCANNER_CLASS}-${scannerStatus ? "active" : "unactive"}`
      },
      /* @__PURE__ */ import_react.default.createElement(NativeDeviceStatus, { type: "scanner", status: scannerStatus }),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-content-scanner-right" }, /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `${DEFAULT_SCANNER_CLASS}-${scannerStatus ? "active" : "unactive"}-title`
        },
        scannerStatus ? import_utils.locales.getText(
          "page.eftpos-pay.text.huifu.scan.gun.connected"
        ) : import_utils.locales.getText(
          "page.eftpos-pay.text.huifu.scan.gun.not-connected"
        )
      ), /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `${DEFAULT_SCANNER_CLASS}-${scannerStatus ? "active" : "unactive"}-desc`
        },
        scannerStatus ? import_utils.locales.getText(
          "page.eftpos-pay.text.huifu.scan.gun.connected-desc"
        ) : import_utils.locales.getText(
          "page.eftpos-pay.text.huifu.scan.gun.not-connected-desc"
        )
      ))
    ),
    cameraStatus && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-eftpos-pay-huifu-scan-content-camera",
        onClick: activeCamera
      },
      /* @__PURE__ */ import_react.default.createElement(NativeDeviceStatus, { type: "camera", status: cameraStatus }),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-content-camera-right" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-eftpos-pay-huifu-scan-content-camera-title" }, import_utils.locales.getText(
        "page.eftpos-pay.text.huifu.scan.camera-title"
      )), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-eftpos-pay-huifu-scan-content-camera-desc" }, import_utils.locales.getText("page.eftpos-pay.text.huifu.scan.camera-desc")))
    ),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-content-input-wrapper" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-content-input-wrapper-title" }, import_utils.locales.getText("page.eftpos-pay.text.huifu.scan.input-title")), /* @__PURE__ */ import_react.default.createElement(
      import_materials.Input,
      {
        placeholder: import_utils.locales.getText(
          "page.eftpos-pay.text.huifu.scan.input-placeholder"
        ),
        maxLength: 18,
        style: { width: "100%", fontSize: "16px" },
        size: "large",
        value: inputValue,
        onChange: (e) => {
          var _a;
          const value = ((_a = e == null ? void 0 : e.target) == null ? void 0 : _a.value) || "";
          const regex = /^[0-9]*$/;
          if (regex.test(value) && (value == null ? void 0 : value.length) <= 18) {
            setInputValue(value);
          }
        }
      }
    ), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-content-input-wrapper-tip" }, "💡", import_utils.locales.getText("page.eftpos-pay.text.huifu.scan.input-tip")))
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-footer" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-eftpos-pay-huifu-scan-footer-divider" }), /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      type: "default",
      block: true,
      size: "large",
      className: "pisell-eftpos-pay-huifu-scan-footer-button",
      onClick: onClose
    },
    import_utils.locales.getText("page.eftpos-pay.text.huifu.scan.cancel")
  ), /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      type: "primary",
      block: true,
      size: "large",
      disabled: !inputValue || (inputValue == null ? void 0 : inputValue.length) < 18,
      onClick: () => onPayClick(inputValue),
      className: "pisell-eftpos-pay-huifu-scan-footer-button"
    },
    import_utils.locales.getText("page.eftpos-pay.text.huifu.scan.confirm")
  )));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  NativeDeviceStatus,
  ScanAction
});
