import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import classNames from 'classnames';
import { useCallback, useEffect, useState } from 'react';
import { CheckGreenIcon } from '../../../lib/icons/CheckGreen.js';
import { CloseWhiteIcon } from '../../../lib/icons/CloseWhite.js';
import { ExclamationCircleIcon } from '../../../lib/icons/ExclamationCircle.js';
export function Snackbar({ message, variant, visible, action, autoDismiss = false, dismissAfterMs = 5000, disableCloseButton = false, automaticVisibility = false, onClose = () => { }, }) {
    const [hidden, setHidden] = useState(visible);
    useEffect(() => {
        setHidden(!visible);
    }, [visible, setHidden]);
    const { label: actionLabel, onClick: handleActionClick } = action ?? {};
    const handleClose = useCallback(() => {
        setHidden(true);
        onClose();
    }, [onClose, setHidden]);
    useEffect(() => {
        if (!autoDismiss) {
            return () => { };
        }
        const timeout = globalThis.setTimeout(() => {
            handleClose();
        }, dismissAfterMs);
        return () => {
            globalThis.clearTimeout(timeout);
        };
    }, [autoDismiss, dismissAfterMs, handleClose]);
    return (_jsx("div", { className: 'seam-snackbar-wrap', children: _jsxs("div", { className: classNames('seam-snackbar', {
                'seam-snackbar-visible': automaticVisibility ? !hidden : visible,
            }), children: [_jsx("span", { className: 'seam-snackbar-icon-wrap', children: _jsx(SnackbarIcon, { variant: variant }) }), _jsx("div", { className: 'seam-snackbar-message-wrap', children: _jsx("p", { className: 'seam-snackbar-message', children: message }) }), _jsxs("div", { className: 'seam-snackbar-actions-wrap', children: [action != null && (_jsx("button", { type: 'button', className: 'seam-snackbar-action', onClick: handleActionClick, children: _jsx("span", { className: 'seam-snackbar-action-label', children: actionLabel }) })), !disableCloseButton && (_jsx("button", { type: 'button', className: 'seam-snackbar-close-button', onClick: () => {
                                handleClose();
                            }, children: _jsx(CloseWhiteIcon, {}) }))] })] }) }));
}
function SnackbarIcon(props) {
    switch (props.variant) {
        case 'success':
            return _jsx(CheckGreenIcon, {});
        case 'error':
            return _jsx(ExclamationCircleIcon, {});
    }
}
//# sourceMappingURL=Snackbar.js.map