import { jsx as _jsx } from "react/jsx-runtime";
import React, { createContext, useContext, useState, useCallback, useMemo, } from "react";
const SnackbarStateContext = createContext(undefined);
const SnackbarActionsContext = createContext(undefined);
export const SnackbarProvider = ({ children, }) => {
    const [snackbars, setSnackbars] = useState([]);
    const showSnackbar = useCallback((message, variant = "info", options) => {
        const id = `snackbar-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
        const newSnackbar = {
            id,
            message,
            variant,
            duration: options?.duration ?? 3000,
            icon: options?.icon,
            iconLabel: options?.iconLabel,
        };
        setSnackbars((prev) => [...prev, newSnackbar]);
    }, []);
    const removeSnackbar = useCallback((id) => {
        setSnackbars((prev) => prev.filter((snackbar) => snackbar.id !== id));
    }, []);
    const actions = useMemo(() => ({
        showSnackbar,
        removeSnackbar,
    }), [showSnackbar, removeSnackbar]);
    return (_jsx(SnackbarActionsContext.Provider, { value: actions, children: _jsx(SnackbarStateContext.Provider, { value: snackbars, children: children }) }));
};
export const useSnackbar = () => {
    const context = useContext(SnackbarActionsContext);
    if (context === undefined) {
        throw new Error("useSnackbar must be used within a SnackbarProvider");
    }
    return context;
};
export const useSnackbarState = () => {
    const context = useContext(SnackbarStateContext);
    if (context === undefined) {
        throw new Error("useSnackbarState must be used within a SnackbarProvider");
    }
    return context;
};
