const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_serve = require("./serve.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
let ahooks = require("ahooks");
//#region src/components/pinModal/hooks.ts
const usePin = () => {
	const [pin, setPin] = (0, react.useState)("");
	const [lastUpdateTime, setLastUpdateTime] = (0, react.useState)("");
	const _getPinRequest = (0, ahooks.useRequest)(require_serve.getPinApi, {
		manual: true,
		loadingDelay: 100,
		onSuccess: (res) => {
			const { code, data } = res;
			if (code === 200 && (data === null || data === void 0 ? void 0 : data.pin)) {
				setPin(data.pin);
				setLastUpdateTime(getTime((data === null || data === void 0 ? void 0 : data.generated_at) || ""));
			}
		}
	});
	const getTime = (time) => {
		if (!time) return "";
		return (0, dayjs.default)(time).format("YYYY-MM-DD HH:mm");
	};
	const _resetPinRequest = (0, ahooks.useRequest)(require_serve.resetPinApi, {
		manual: true,
		loadingDelay: 100,
		onSuccess: (res) => {
			const { code, data } = res;
			if (code === 200 && (data === null || data === void 0 ? void 0 : data.pin)) {
				setPin(data.pin);
				setLastUpdateTime(getTime((data === null || data === void 0 ? 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
	};
};
//#endregion
exports.usePin = usePin;
