import { jsx, jsxs } from "react/jsx-runtime";
import CheckCircle from "@mui/icons-material/CheckCircle";
import Close from "@mui/icons-material/Close";
import Error from "@mui/icons-material/Error";
import Info from "@mui/icons-material/Info";
import Warning from "@mui/icons-material/Warning";
import { IconButton, styled } from "@mui/material";
import apollo_core, { FontVariantToken } from "@uipath/apollo-core";
import react, { useCallback, useState } from "react";
import { StatusTypes } from "../../../types/statusTypes.js";
import { ApTypography } from "../ap-typography/index.js";
const statusIconMap = {
    [StatusTypes.INFO]: Info,
    [StatusTypes.WARNING]: Warning,
    [StatusTypes.ERROR]: Error,
    [StatusTypes.SUCCESS]: CheckCircle
};
const AlertBarContainer = styled('div')(({ status })=>{
    let borderColor;
    let backgroundColor;
    let iconColor;
    switch(status){
        case StatusTypes.INFO:
            borderColor = 'var(--color-info-icon)';
            backgroundColor = 'var(--color-info-background)';
            iconColor = 'var(--color-info-icon)';
            break;
        case StatusTypes.WARNING:
            borderColor = 'var(--color-warning-icon)';
            backgroundColor = 'var(--color-warning-background)';
            iconColor = 'var(--color-warning-icon)';
            break;
        case StatusTypes.ERROR:
            borderColor = 'var(--color-error-icon)';
            backgroundColor = 'var(--color-error-background)';
            iconColor = 'var(--color-error-icon)';
            break;
        case StatusTypes.SUCCESS:
            borderColor = 'var(--color-success-icon)';
            backgroundColor = 'var(--color-success-background)';
            iconColor = 'var(--color-success-icon)';
            break;
        default:
            borderColor = 'var(--color-info-icon)';
            backgroundColor = 'var(--color-info-background)';
            iconColor = 'var(--color-info-icon)';
    }
    return {
        minHeight: '40px',
        display: 'flex',
        border: `1px solid ${borderColor}`,
        backgroundColor,
        '--icon-color': iconColor
    };
});
const IconContainer = styled('div')({
    padding: `11px ${apollo_core.Padding.PadL} 0`,
    color: 'var(--icon-color)',
    '& .MuiSvgIcon-root': {
        width: apollo_core.Icon.IconS,
        height: apollo_core.Icon.IconS
    }
});
const TextContent = styled('div')({
    padding: `${apollo_core.Padding.PadXl} ${apollo_core.Spacing.SpacingL} ${apollo_core.Padding.PadXl} 0`,
    width: '100%'
});
const CancelButton = styled('div')({
    padding: `${apollo_core.Padding.PadL} ${apollo_core.Padding.PadL} ${apollo_core.Padding.PadL} 0`,
    height: apollo_core.Icon.IconM,
    '& .MuiIconButton-root': {
        padding: 0,
        width: apollo_core.Icon.IconM,
        height: apollo_core.Icon.IconM
    }
});
const ApAlertBar = /*#__PURE__*/ react.forwardRef(({ status = StatusTypes.INFO, cancelable = true, onCancel, children, className, sx }, ref)=>{
    const [visible, setVisible] = useState(true);
    const onDismiss = useCallback(()=>{
        setVisible(false);
        onCancel?.();
    }, [
        onCancel
    ]);
    const StatusIcon = statusIconMap[status];
    if (!visible) return null;
    return /*#__PURE__*/ jsxs(AlertBarContainer, {
        ref: ref,
        status: status,
        className: className,
        sx: sx,
        children: [
            /*#__PURE__*/ jsx(IconContainer, {
                children: /*#__PURE__*/ jsx(StatusIcon, {})
            }),
            /*#__PURE__*/ jsx(TextContent, {
                children: /*#__PURE__*/ jsx(ApTypography, {
                    variant: FontVariantToken.fontSizeM,
                    color: "var(--color-foreground)",
                    children: children
                })
            }),
            cancelable && /*#__PURE__*/ jsx(CancelButton, {
                children: /*#__PURE__*/ jsx(IconButton, {
                    size: "small",
                    onClick: onDismiss,
                    "aria-label": "Dismiss",
                    children: /*#__PURE__*/ jsx(Close, {})
                })
            })
        ]
    });
});
ApAlertBar.displayName = 'ApAlertBar';
export { ApAlertBar };
