import exec from "../../../utils/load.js";
import { useEffect, useMemo, useRef, useState } from "react";
//#region src/components/eftposPay/tyro/hooks.tsx
/**
* @title: 获取 Tyro 资源
* @description:
* @param {Eftpos} type 类型
* @param {string} url 链接
* @return {*}
* @Author: hongbing.wang
* @Date: 2024-08-19 18:36
*/
const useTyro = (params) => {
	const ref = useRef();
	const [load, setLoad] = useState(false);
	const url = useMemo(() => {
		return params && params.url && params.version ? `${params.url}/${params.version}` : "https://iclientsimulator.test.tyro.com/iclient-v1.js";
	}, [params]);
	useEffect(() => {
		exec(url, document.head).then(() => {
			var _window;
			return (_window = window) === null || _window === void 0 ? void 0 : _window.TYRO;
		}).then((res) => {
			setLoad(true);
			ref.current = res;
		}, () => {
			setLoad(true);
		});
	}, [url]);
	return [ref, load];
};
//#endregion
export { useTyro };
