import { _ as y, v as u } from "../vendor-preact-DThS2ZQ_.js";
import { a as isTerminalModuleState, c as useManager, o as useModuleTerminalCallbacks } from "../hooks-Da_yP_Dr.js";
import { t as IncodeComponent } from "../incodeComponent-CCP7GTMj.js";
import { t as TransitionSpinner } from "../transitionSpinner-dYLkc7PO.js";
import { t as Processing } from "../processing-Tr7W8nuX.js";
import { n as Capture, r as Permissions, t as Tutorial } from "../tutorial-D3BW5BZn.js";
import { t as registerIncodeModuleElement } from "../incodeModule-M8DszCee.js";
import { createSelfieManager } from "@incodetech/core/selfie";
//#region src/modules/selfie/preloadTutorialAssets.ts
var started = false;
function preloadSelfieTutorialAssets() {
	if (started) return;
	started = true;
	import("../selfieTutorial-CYa8bq6B.js");
}
//#endregion
//#region src/modules/selfie/selfie.tsx
var SelfieContent = ({ config, manager: externalManager, onFinish, onError }) => {
	y(() => {
		preloadSelfieTutorialAssets();
	}, []);
	const [state, manager] = useManager(() => {
		if (externalManager) return externalManager;
		if (!config) throw new Error("Selfie config is required when no manager is provided");
		return createSelfieManager({ config });
	}, { manageLifecycle: !externalManager });
	useModuleTerminalCallbacks({
		status: state.status,
		onFinish,
		onError,
		error: state.status === "error" ? state.error : void 0
	});
	if (state.status === "idle" || state.status === "loading") return /* @__PURE__ */ u(TransitionSpinner, { hideText: true });
	if (state.status === "tutorial") return /* @__PURE__ */ u(Tutorial, {
		manager,
		ageAssurance: state.ageAssurance
	});
	if (state.status === "permissions") return /* @__PURE__ */ u(Permissions, {
		manager,
		permissionStatus: state.permissionStatus
	});
	if (state.status === "capture") return /* @__PURE__ */ u(Capture, {
		manager,
		state
	});
	if (state.status === "processing") return /* @__PURE__ */ u(Processing, {});
	if (isTerminalModuleState(state)) return null;
	return null;
};
var Selfie = ({ config, manager, onFinish, onError }) => {
	return /* @__PURE__ */ u(IncodeComponent, { children: config || manager ? /* @__PURE__ */ u(SelfieContent, {
		config,
		manager,
		onFinish,
		onError
	}) : null });
};
registerIncodeModuleElement(Selfie, "incode-selfie");
//#endregion
export { Selfie };
