try {
	let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
	n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "2d1f53a3-ebf5-446c-b3e2-116ad9d6a093", e._sentryDebugIdIdentifier = "sentry-dbid-2d1f53a3-ebf5-446c-b3e2-116ad9d6a093");
} catch (e) {}
import { a as Icon } from "./translation-Br5wIPO-.js";
import { n as IconButton, t as Button } from "./Button-BDEdGXnd.js";
import { t as ToastContext } from "./ToastContext-CeB1t7kx.js";
import { useEffect, useMemo, useState } from "preact/hooks";
import cx from "classnames";
import { jsx, jsxs } from "preact/jsx-runtime";
var Toast_module_default = {
	toast: "adyen-kyc-toast",
	"present-toast": "adyen-kyc-present-toast",
	presentToast: "adyen-kyc-present-toast",
	"toast-image": "adyen-kyc-toast-image",
	toastImage: "adyen-kyc-toast-image",
	"toast-image-success": "adyen-kyc-toast-image-success",
	toastImageSuccess: "adyen-kyc-toast-image-success",
	"toast-image-error": "adyen-kyc-toast-image-error",
	toastImageError: "adyen-kyc-toast-image-error",
	"toast-label": "adyen-kyc-toast-label",
	toastLabel: "adyen-kyc-toast-label",
	"toast-actions": "adyen-kyc-toast-actions",
	toastActions: "adyen-kyc-toast-actions",
	"toast-action-close": "adyen-kyc-toast-action-close",
	toastActionClose: "adyen-kyc-toast-action-close"
};
//#endregion
//#region src/components/ui/molecules/Toast/Toast.tsx
var Toast = ({ action, duration = 1e4, label, onDismiss, variant = "info" }) => {
	const hasIcon = variant === "success" || variant === "error";
	const hasAction = action !== void 0;
	const role = hasAction ? "alertdialog" : "alert";
	const iconNames = {
		error: "field-error",
		success: "checkmark"
	};
	const imageClassname = cx(Toast_module_default.toastImage, {
		[Toast_module_default.toastImageSuccess]: variant === "success",
		[Toast_module_default.toastImageError]: variant === "error"
	});
	useEffect(() => {
		let dismissToastTimer;
		if (duration !== "indefinite") dismissToastTimer = setTimeout(() => {
			onDismiss();
		}, duration);
		return () => {
			clearTimeout(dismissToastTimer);
		};
	}, [duration, onDismiss]);
	return /* @__PURE__ */ jsxs("div", {
		"aria-label": label,
		className: Toast_module_default.toast,
		role,
		children: [/* @__PURE__ */ jsxs("div", {
			className: Toast_module_default.toastLabel,
			children: [hasIcon && /* @__PURE__ */ jsx("div", {
				className: imageClassname,
				"data-testId": iconNames[variant],
				children: /* @__PURE__ */ jsx(Icon, { name: iconNames[variant] })
			}), label]
		}), /* @__PURE__ */ jsxs("div", {
			className: Toast_module_default.toastActions,
			children: [hasAction && /* @__PURE__ */ jsx(Button, {
				onClick: action.onClick,
				children: action.label
			}), /* @__PURE__ */ jsx("div", {
				className: Toast_module_default.toastActionClose,
				children: /* @__PURE__ */ jsx(IconButton, {
					icon: "cross",
					ariaLabel: "Close",
					onClick: onDismiss
				})
			})]
		})]
	});
};
//#endregion
//#region src/context/ToastContext/ToastContextProvider.tsx
function ToastContextProvider({ children }) {
	const [toastOptions, setToastOptions] = useState();
	const clearToasts = () => {
		setToastOptions(void 0);
	};
	const contextValue = useMemo(() => ({
		showToast: (options) => {
			setToastOptions(options);
		},
		clearToasts
	}), []);
	return /* @__PURE__ */ jsxs(ToastContext.Provider, {
		value: contextValue,
		children: [!!toastOptions && /* @__PURE__ */ jsx(Toast, {
			label: toastOptions.label,
			variant: toastOptions.variant,
			action: toastOptions.action,
			duration: toastOptions.duration,
			onDismiss: clearToasts
		}), children]
	});
}
//#endregion
export { ToastContextProvider as t };
