import { getHandleSetService } from "../../components/addServiceVariant/utils.js";
import { getHandleSetClient } from "../../../booking/info2/cartClientCard/utils.js";
import { locales } from "@pisell/utils";
import { useToast } from "@pisell/materials";
//#region src/components/ticketBooking/hooks/pisellos/useScanGlobalHandle.ts
const useScanGlobalHandle = () => {
	const Toast = useToast();
	const walletHandle = (data) => {
		const handleSetClient = getHandleSetClient();
		if (!data.data) {
			Toast.fail(locales.getText("pisell2.text.scan-global-failed"));
			return;
		}
		if (handleSetClient && data.data) handleSetClient(data.data);
	};
	const walletPassHandle = (data) => {
		const handleSetClient = getHandleSetClient();
		if (!data.data) {
			Toast.fail(locales.getText("pisell2.text.scan-global-failed"));
			return;
		}
		if (handleSetClient && data.data) handleSetClient(data.data, { fullData: data });
	};
	const productHandle = (data) => {
		var _data$data, _data$data2;
		const handleSetService = getHandleSetService();
		if (!((_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.list)) {
			Toast.fail(locales.getText("pisell2.text.scan-global-failed"));
			return;
		}
		if (handleSetService && (data === null || data === void 0 || (_data$data2 = data.data) === null || _data$data2 === void 0 ? void 0 : _data$data2.list)) handleSetService(data.data.list, data.scanCode);
	};
	const handleScan = (data) => {
		if (data.searchType === "wallet") walletHandle(data);
		else if (data.searchType === "walletPass") walletPassHandle(data);
		else if (data.searchType === "product" || data.searchType === "local_product") productHandle(data);
	};
	return handleScan;
};
//#endregion
export { useScanGlobalHandle as default };
