"use client";
import { ark } from "../factory.js";
import { useEnvironmentContext } from "../../providers/environment/use-environment-context.js";
import { useLocaleContext } from "../../providers/locale/use-locale-context.js";
import { ToastProvider } from "./use-toast-context.js";
import * as toast from "@zag-js/toast";
import { forwardRef, useId } from "react";
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
import { jsx } from "react/jsx-runtime";
//#region src/components/toast/toaster.tsx
var Toaster = forwardRef((props, ref) => {
	const { toaster, children, ...localProps } = props;
	const locale = useLocaleContext();
	const env = useEnvironmentContext();
	const service = useMachine(toast.group.machine, {
		store: toaster,
		id: useId(),
		dir: locale?.dir,
		getRootNode: env?.getRootNode
	});
	const api = toast.group.connect(service, normalizeProps);
	const mergedProps = mergeProps(api.getGroupProps(), localProps);
	return /* @__PURE__ */ jsx(ark.div, {
		...mergedProps,
		ref,
		children: api.getToasts().map((toast, index) => /* @__PURE__ */ jsx(ToastActor, {
			value: toast,
			parent: service,
			index,
			children: (ctx) => children(ctx)
		}, toast.id))
	});
});
Toaster.displayName = "Toaster";
var ToastActor = (props) => {
	const env = useEnvironmentContext();
	const localProps = {
		...props.value,
		parent: props.parent,
		index: props.index,
		getRootNode: env.getRootNode
	};
	const service = useMachine(toast.machine, { ...localProps });
	return /* @__PURE__ */ jsx(ToastProvider, {
		value: toast.connect(service, normalizeProps),
		children: props.children(props.value)
	});
};
ToastActor.displayName = "ToastActor";
//#endregion
export { Toaster };
