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/pinVerifyModal/hooks.ts
var hooks_exports = {};
__export(hooks_exports, {
  usePinVerify: () => usePinVerify
});
module.exports = __toCommonJS(hooks_exports);
var import_react = require("react");
var import_ahooks = require("ahooks");
var import_materials = require("@pisell/materials");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_utils = require("../../utils");
var usePinVerify = () => {
  var _a, _b;
  const context = (0, import_useEngineContext.default)();
  const apiPrefix = (_b = (_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.constants) == null ? void 0 : _b.apiPrefix;
  const [verifyInfo, setVerifyInfo] = (0, import_react.useState)(null);
  const verifySuccessRef = (0, import_react.useRef)(
    () => {
    }
  );
  const _setVerifyInfo = (data) => {
    const { failed_count, check_max_count } = data || {};
    if (!check_max_count) {
      setVerifyInfo(null);
      return;
    }
    setVerifyInfo({
      check_max_count,
      remaining_count: check_max_count - (failed_count || 0)
    });
  };
  const verifyPinApi = (data) => {
    return import_utils.request.getRequest().post(`${apiPrefix}/wallet/detail/pin/validate`, data, {
      fullResult: true
    });
  };
  const _verifyPin = (0, import_ahooks.useRequest)(verifyPinApi, {
    manual: true,
    onSuccess: (res) => {
      var _a2;
      if ((res == null ? void 0 : res.code) === 200) {
        const { status, msg, failed_count, check_max_count } = (res == null ? void 0 : res.data) || {};
        _setVerifyInfo({ failed_count, check_max_count });
        (0, import_materials.PisellToast)({ content: msg, duration: 2 });
        if (status === "success") {
          (_a2 = verifySuccessRef.current) == null ? void 0 : _a2.call(verifySuccessRef, res == null ? void 0 : res.data);
        }
      }
    }
  });
  const verifyPin = (data, onSuccess) => {
    verifySuccessRef.current = onSuccess;
    _verifyPin.run(data);
  };
  return {
    verifyPin,
    loading: _verifyPin.loading,
    verifyInfo,
    setVerifyInfo: _setVerifyInfo
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  usePinVerify
});
