import { 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 { n as Capture, r as Permissions, t as Tutorial } from "../tutorial-D3BW5BZn.js";
import { t as registerIncodeModuleElement } from "../incodeModule-M8DszCee.js";
import { createAuthenticationManager } from "@incodetech/core/authentication";
//#region src/modules/authentication/authentication.tsx
var AuthenticationContent = ({ config, authHint, manager: externalManager, onFinish, onError }) => {
	const [state, manager] = useManager(() => externalManager ?? createAuthenticationManager({
		config,
		authHint
	}), { manageLifecycle: !externalManager });
	useModuleTerminalCallbacks({
		status: state.status,
		onFinish,
		onError,
		error: state.status === "error" ? state.error : void 0,
		moduleErrorCode: state.status === "error" ? state.moduleErrorCode : void 0
	});
	if (state.status === "idle" || state.status === "loading") return null;
	if (state.status === "tutorial") return /* @__PURE__ */ u(Tutorial, { manager });
	if (state.status === "permissions") return /* @__PURE__ */ u(Permissions, {
		manager,
		permissionStatus: state.permissionStatus
	});
	if (state.status === "capture") return /* @__PURE__ */ u(Capture, {
		manager,
		state
	});
	if (isTerminalModuleState(state)) return null;
	return null;
};
var Authentication = ({ config, manager, onFinish, onError }) => {
	return /* @__PURE__ */ u(IncodeComponent, { children: config ? /* @__PURE__ */ u(AuthenticationContent, {
		config,
		authHint: config.authHint,
		manager,
		onFinish,
		onError
	}) : null });
};
registerIncodeModuleElement(Authentication, "incode-authentication");
//#endregion
export { Authentication };
