import { t as e } from "../utils-B7XIe3qq.js";
import { t } from "../toast-DRNPdj-R.js";
import * as n from "react";
import { jsx as r, jsxs as i } from "react/jsx-runtime";
//#region src/services/toast-react.tsx
function a(e) {
	switch (e) {
		case "destructive": return "error";
		case "success": return "success";
		case "warning": return "warning";
		case "info": return "info";
		case "default":
		case void 0:
		default: return "info";
	}
}
function o(e) {
	if (e == null || typeof e == "boolean") return "";
	if (typeof e == "string") return e;
	if (typeof e == "number") return String(e);
	if (Array.isArray(e)) return e.map(o).join("");
	if (n.isValidElement(e)) {
		let t = e.props;
		return o(t?.children);
	}
	return "";
}
function s(e, t) {
	let n = {
		id: e,
		level: a(t.variant),
		title: o(t.title)
	}, r = t.description;
	return r != null && r !== !1 && (n.description = o(r)), t.action !== void 0 && (n.action = t.action), t.duration !== void 0 && (n.duration = t.duration), n;
}
var c = n.createContext(null);
function l() {
	let e = n.useContext(c);
	if (!e) throw Error("useToast must be used within a <ToastProvider> from @countermeasure-platform/web-components/services/toast-react");
	return e;
}
var u = 0;
function d({ children: e, duration: t = 5e3, swipeDirection: a = "right", viewportClassName: o }) {
	let [s, l] = n.useState([]), d = n.useCallback((e) => {
		l((t) => e === void 0 ? [] : t.filter((t) => t.id !== e));
	}, []), p = n.useCallback((e, t) => {
		l((n) => n.map((n) => n.id === e ? {
			...n,
			...t
		} : n));
	}, []), m = n.useCallback((e) => {
		u += 1;
		let t = `cmm-toast-${String(u)}`, n = {
			...e,
			id: t,
			open: !0
		};
		return l((e) => [...e, n]), {
			id: t,
			dismiss: () => {
				d(t);
			},
			update: (e) => {
				p(t, e);
			}
		};
	}, [d, p]), h = n.useMemo(() => ({
		toast: m,
		dismiss: d,
		toasts: s
	}), [
		m,
		d,
		s
	]);
	return /* @__PURE__ */ i(c.Provider, {
		value: h,
		children: [e, /* @__PURE__ */ r(f, {
			toasts: s,
			dismiss: d,
			defaultDuration: t,
			swipeDirection: a,
			...o === void 0 ? {} : { className: o }
		})]
	});
}
function f({ toasts: n, dismiss: i, defaultDuration: a, swipeDirection: o, className: c }) {
	return /* @__PURE__ */ r("div", {
		"data-slot": "toast-viewport",
		"data-swipe-direction": o,
		role: "region",
		"aria-label": "Notifications",
		"aria-live": "polite",
		className: e("fixed z-[9999] flex flex-col gap-2 pointer-events-none w-full max-w-sm bottom-4 right-4", c),
		children: n.map((e) => /* @__PURE__ */ r(t, {
			data: s(e.id, e),
			onDismiss: () => {
				i(e.id);
			},
			defaultDuration: a
		}, e.id))
	});
}
//#endregion
export { d as ToastProvider, l as useToast };

//# sourceMappingURL=toast-react.js.map