import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import useEngineContext from "../../hooks/useEngineContext.js";
import { request } from "../../utils/index.js";
import locales_default from "./locales.js";
import { usePin } from "./hooks.js";
import React, { forwardRef, useImperativeHandle, useRef, useState } from "react";
import { locales } from "@pisell/utils";
import { PisellModal } from "@pisell/materials";
import "./index.less";
//#region src/components/pinModal/index.tsx
const PinModal = (props, ref) => {
	var _context$engine, _context$appHelper;
	const context = useEngineContext();
	locales.init(locales_default, (context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.locale) || "en");
	request.setRequest(context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.request);
	const [visible, setVisible] = useState(false);
	const { pin, lastUpdateTime, getPin, resetPin, resetPinLoading } = usePin();
	const walletDetailIdRef = 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 = function() {
		var _ref = _asyncToGenerator(function* () {
			if (!walletDetailIdRef.current || resetPinLoading) return;
			resetPin(walletDetailIdRef.current);
		});
		return function onResetPin() {
			return _ref.apply(this, arguments);
		};
	}();
	useImperativeHandle(ref, () => ({
		open: onOpen,
		hide: onHide
	}));
	return /* @__PURE__ */ React.createElement(PisellModal, {
		title: locales.getText("pisell2.pin.modal.title"),
		open: visible,
		okText: locales.getText("pisell2.pin.modal.reset.pin"),
		onOk: onResetPin,
		cancelText: locales.getText("pisell2.pin.modal.cancel"),
		onCancel: onHide,
		okButtonProps: { loading: resetPinLoading },
		destroyOnClose: true,
		mobileModalHeight: "auto"
	}, /* @__PURE__ */ React.createElement("div", { className: "pin-modal" }, /* @__PURE__ */ React.createElement("div", { className: "pin-modal-content" }, /* @__PURE__ */ React.createElement("span", { className: "pin-modal-content-label" }, locales.getText("pisell2.pin.modal.label")), /* @__PURE__ */ React.createElement("span", { className: "pin-modal-content-code" }, pin)), /* @__PURE__ */ React.createElement("span", { className: "pin-modal-content-desc" }, locales.getText("pisell2.pin.modal.desc")), /* @__PURE__ */ React.createElement("span", { className: "pin-modal-content-time" }, locales.getText("pisell2.pin.modal.time"), lastUpdateTime)));
};
var pinModal_default = forwardRef(PinModal);
//#endregion
export { pinModal_default as default };
