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/hooks.ts
var hooks_exports = {};
__export(hooks_exports, {
  usePin: () => usePin
});
module.exports = __toCommonJS(hooks_exports);
var import_react = require("react");
var import_ahooks = require("ahooks");
var import_dayjs = __toESM(require("dayjs"));
var import_serve = require("./serve");
var usePin = () => {
  const [pin, setPin] = (0, import_react.useState)("");
  const [lastUpdateTime, setLastUpdateTime] = (0, import_react.useState)("");
  const _getPinRequest = (0, import_ahooks.useRequest)(import_serve.getPinApi, {
    manual: true,
    loadingDelay: 100,
    onSuccess: (res) => {
      const { code, data } = res;
      if (code === 200 && (data == null ? void 0 : data.pin)) {
        setPin(data.pin);
        setLastUpdateTime(getTime((data == null ? void 0 : data.generated_at) || ""));
      }
    }
  });
  const getTime = (time) => {
    if (!time) return "";
    return (0, import_dayjs.default)(time).format("YYYY-MM-DD HH:mm");
  };
  const _resetPinRequest = (0, import_ahooks.useRequest)(import_serve.resetPinApi, {
    manual: true,
    loadingDelay: 100,
    onSuccess: (res) => {
      const { code, data } = res;
      if (code === 200 && (data == null ? void 0 : data.pin)) {
        setPin(data.pin);
        setLastUpdateTime(getTime((data == null ? void 0 : data.generated_at) || ""));
      }
    }
  });
  const getPin = (id) => {
    _getPinRequest.run({ wallet_detail_id: id });
  };
  const resetPin = (id) => {
    _resetPinRequest.run({ wallet_detail_id: id });
  };
  return {
    pin,
    lastUpdateTime,
    getPin,
    resetPin,
    resetPinLoading: _resetPinRequest.loading
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  usePin
});
