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/pinModal/index.tsx
var pinModal_exports = {};
__export(pinModal_exports, {
  default: () => pinModal_default
});
module.exports = __toCommonJS(pinModal_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_locales = __toESM(require("./locales"));
var import_hooks = require("./hooks");
var import_utils2 = require("../../utils");
var import_index = require("./index.less");
var PinModal = (props, ref) => {
  var _a, _b, _c, _d;
  const context = (0, import_useEngineContext.default)();
  import_utils.locales.init(import_locales.default, ((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en");
  import_utils2.request.setRequest((_d = (_c = context == null ? void 0 : context.appHelper) == null ? void 0 : _c.utils) == null ? void 0 : _d.request);
  const [visible, setVisible] = (0, import_react.useState)(false);
  const { pin, lastUpdateTime, getPin, resetPin, resetPinLoading } = (0, import_hooks.usePin)();
  const walletDetailIdRef = (0, import_react.useRef)();
  const onOpen = (wallet_detail_id) => {
    walletDetailIdRef.current = wallet_detail_id;
    getPin(wallet_detail_id);
    setVisible(true);
  };
  const onHide = () => {
    walletDetailIdRef.current = void 0;
    setVisible(false);
  };
  const onResetPin = async () => {
    if (!walletDetailIdRef.current || resetPinLoading) {
      return;
    }
    resetPin(walletDetailIdRef.current);
  };
  (0, import_react.useImperativeHandle)(ref, () => ({
    open: onOpen,
    hide: onHide
  }));
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      title: import_utils.locales.getText("pisell2.pin.modal.title"),
      open: visible,
      okText: import_utils.locales.getText("pisell2.pin.modal.reset.pin"),
      onOk: onResetPin,
      cancelText: import_utils.locales.getText("pisell2.pin.modal.cancel"),
      onCancel: onHide,
      okButtonProps: {
        loading: resetPinLoading
      },
      destroyOnClose: true,
      mobileModalHeight: "auto"
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pin-modal" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pin-modal-content" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pin-modal-content-label" }, import_utils.locales.getText("pisell2.pin.modal.label")), /* @__PURE__ */ import_react.default.createElement("span", { className: "pin-modal-content-code" }, pin)), /* @__PURE__ */ import_react.default.createElement("span", { className: "pin-modal-content-desc" }, import_utils.locales.getText("pisell2.pin.modal.desc")), /* @__PURE__ */ import_react.default.createElement("span", { className: "pin-modal-content-time" }, import_utils.locales.getText("pisell2.pin.modal.time"), lastUpdateTime))
  );
};
var pinModal_default = (0, import_react.forwardRef)(PinModal);
