"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { createElement as _createElement } from "react";
import { forwardRef } from "react";
import { Portal } from "../portal/Portal.js";
import { useEnsuredId } from "../useEnsuredId.js";
import { DefaultToastRenderer } from "./DefaultToastRenderer.js";
import { useToastQueue } from "./ToastManagerProvider.js";
import { snackbar } from "./snackbarStyles.js";
/**
 * **Client Component**
 *
 * @example Super Simple Example
 * ```tsx
 * import { Button } from "@react-md/core/button/Button";
 * import { Snackbar } from "@react-md/core/snackbar/Snackbar";
 * import { addToast } from "@react-md/core/snackbar/ToastManager";
 * import type { ReactElement } from "react";
 *
 * function Example(): ReactElement {
 *   return (
 *     <>
 *       <Button
 *         onClick={() => {
 *           addToast({ children: "A new toast!" });
 *         }}
 *       >
 *         Toast!
 *       </Button>
 *       <Snackbar />
 *     </>
 *   );
 * }
 * ```
 *
 * @see {@link https://react-md.dev/components/snackbar | Snackbar Demos}
 * @see {@link SnackbarProps.renderToast} for creating a custom toast
 * implementation.
 * @since 6.0.0 Rewritten to use a new API that supports adding toasts
 * outside of React components and rendering multiple toasts at once.
 */ export const Snackbar = /*#__PURE__*/ forwardRef(function Snackbar(props, ref) {
    const { id: propId, className, limit = 1, absolute, position = "bottom", renderToast: RenderToast = DefaultToastRenderer, disablePortal, toastDefaults, ...remaining } = props;
    const id = useEnsuredId(propId, "snackbar");
    const queue = useToastQueue(limit);
    return /*#__PURE__*/ _jsx(Portal, {
        disabled: disablePortal,
        children: queue.length > 0 && /*#__PURE__*/ _jsx("div", {
            ...remaining,
            id: id,
            ref: ref,
            className: snackbar({
                absolute,
                position,
                className
            }),
            children: queue.map((toast)=>/*#__PURE__*/ _createElement(RenderToast, {
                    ...toast,
                    key: toast.toastId,
                    toastDefaults: toastDefaults
                }))
        })
    });
});

//# sourceMappingURL=Snackbar.js.map