import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { styled } from "@mui/material";
import apollo_core from "@uipath/apollo-core";
import react from "react";
import { useChatScroll } from "../../providers/chat-scroll-provider.js";
import { useChatState } from "../../providers/chat-state-provider.js";
import { AutopilotChatMode, CHAT_WIDTH_FULL_SCREEN_MAX_WIDTH } from "../../service/index.js";
import { AutopilotChatMessages } from "./chat-message.js";
import { AutopilotChatScrollToBottomButton } from "./chat-scroll-to-bottom.js";
const OverflowContainer = styled('div')(({ isOverflow, isContainerWide, scrollBarTheming })=>{
    const baseStyles = {
        flex: '1 1 100%',
        minHeight: 0,
        overflowY: 'auto',
        overflowX: 'hidden',
        position: 'relative',
        outline: 'none',
        margin: `0 -${apollo_core.Spacing.SpacingL}`,
        padding: `0 ${apollo_core.Spacing.SpacingL}`,
        ...isOverflow && !isContainerWide && {
            paddingRight: apollo_core.Spacing.SpacingXs
        }
    };
    const scrollBarStyles = {};
    if (scrollBarTheming?.scrollSize) scrollBarStyles['&::-webkit-scrollbar'] = {
        width: scrollBarTheming.scrollSize,
        height: scrollBarTheming.scrollSize
    };
    if (scrollBarTheming?.scrollThumbColor) scrollBarStyles['&::-webkit-scrollbar-thumb'] = {
        backgroundColor: scrollBarTheming.scrollThumbColor
    };
    if (scrollBarTheming?.scrollHoverColor) scrollBarStyles['&::-webkit-scrollbar-thumb']['&:hover'] = {
        backgroundColor: scrollBarTheming.scrollHoverColor
    };
    if (scrollBarTheming?.scrollBorderRadius) scrollBarStyles['&::-webkit-scrollbar-thumb']['borderRadius'] = scrollBarTheming.scrollBorderRadius;
    return {
        ...baseStyles,
        ...scrollBarStyles
    };
});
const MessagesContainer = styled('div')(({ mode, paddingTop })=>({
        ...paddingTop && {
            paddingTop
        },
        ...(mode === AutopilotChatMode.FullScreen || mode === AutopilotChatMode.Embedded) && {
            maxWidth: CHAT_WIDTH_FULL_SCREEN_MAX_WIDTH,
            margin: '0 auto',
            width: '100%'
        }
    }));
const StyledGradientContainer = styled('div')(()=>({
        position: 'sticky',
        zIndex: 1,
        bottom: 0,
        left: apollo_core.Spacing.SpacingBase,
        width: '100%',
        height: apollo_core.Spacing.SpacingBase,
        background: `linear-gradient(
        to bottom,
            var(--color-background)25 0%,
            var(--color-background)50 25%,
            var(--color-background) 50%
        )`
    }));
const GradientContainer = /*#__PURE__*/ react.memo(()=>{
    const { hasMessages } = useChatState();
    if (!hasMessages) return null;
    return /*#__PURE__*/ jsx(StyledGradientContainer, {});
});
function ChatScrollContainerComponent({ mode }) {
    const { setOverflowContainer, contentRef, overflowContainer, isOverflow, isContainerWide } = useChatScroll();
    const { disabledFeatures, theming } = useChatState();
    return /*#__PURE__*/ jsxs(Fragment, {
        children: [
            /*#__PURE__*/ jsxs(OverflowContainer, {
                tabIndex: 0,
                id: "overflow-container",
                isOverflow: isOverflow,
                scrollBarTheming: theming?.scrollBar,
                isContainerWide: isContainerWide,
                ref: setOverflowContainer,
                children: [
                    /*#__PURE__*/ jsx(MessagesContainer, {
                        id: "content-ref",
                        ref: contentRef,
                        mode: mode,
                        paddingTop: disabledFeatures.headerSeparator ? void 0 : apollo_core.Spacing.SpacingXs,
                        children: /*#__PURE__*/ jsx(AutopilotChatMessages, {
                            isOverflow: isOverflow,
                            isContainerWide: isContainerWide
                        })
                    }),
                    /*#__PURE__*/ jsx(GradientContainer, {})
                ]
            }),
            /*#__PURE__*/ jsx(AutopilotChatScrollToBottomButton, {
                overflowContainer: overflowContainer
            })
        ]
    });
}
const ChatScrollContainer = /*#__PURE__*/ react.memo(ChatScrollContainerComponent);
export { ChatScrollContainer };
