import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { styled } from "@mui/material/styles";
import apollo_core from "@uipath/apollo-core";
import react from "react";
import { useChatService } from "../../providers/chat-service.provider.js";
import { useChatState } from "../../providers/chat-state-provider.js";
import { AutopilotChatInternalEvent, CHAT_CONTAINER_ANIMATION_DURATION, CHAT_DRAWER_WIDTH_FULL_SCREEN, CHAT_WIDTH_FULL_SCREEN_MAX_WIDTH } from "../../service/index.js";
import { AutopilotChatHeader } from "../header/header.js";
import { AutopilotChatHistory } from "../history/chat-history.js";
import { AutopilotChatInput } from "../input/chat-input.js";
import { ChatScrollContainer } from "../message/chat-scroll-container.js";
import chat_settings from "../settings/chat-settings.js";
const ContentContainer = styled('div')(()=>({
        display: 'flex',
        flex: 1,
        overflow: 'hidden',
        minWidth: '0'
    }));
const MainContainer = styled('div')(({ historyOpen })=>({
        flex: 1,
        display: 'flex',
        flexDirection: 'column',
        height: '100%',
        maxHeight: '100%',
        margin: `0 ${apollo_core.Spacing.SpacingL}`,
        ...historyOpen && {
            width: `calc(100% - ${CHAT_DRAWER_WIDTH_FULL_SCREEN}px - 2 * ${apollo_core.Spacing.SpacingBase})`
        }
    }));
const HeaderContainer = styled('div')(({ padding })=>({
        flexShrink: 0,
        padding
    }));
const InputBackground = styled('div')(()=>({
        flexShrink: 0,
        paddingBottom: apollo_core.Spacing.SpacingXs
    }));
const InputContainer = styled('div')(()=>({
        maxWidth: CHAT_WIDTH_FULL_SCREEN_MAX_WIDTH,
        margin: '0 auto',
        width: '100%'
    }));
const FullScreenLayout = ({ historyOpen, settingsOpen, historyDisabled, settingsDisabled, mode, headerSeparatorDisabled, readOnly })=>{
    const { setFullScreenContainer } = useChatState();
    const chatInternalService = useChatService().__internalService__;
    const mainContainerRef = react.useRef(null);
    react.useEffect(()=>{
        if (!chatInternalService || !mainContainerRef.current) return;
        const timeout = setTimeout(()=>{
            chatInternalService.publish(AutopilotChatInternalEvent.ChatResize, mainContainerRef.current?.offsetWidth);
        }, CHAT_CONTAINER_ANIMATION_DURATION);
        return ()=>clearTimeout(timeout);
    }, [
        historyOpen,
        chatInternalService,
        mainContainerRef
    ]);
    return /*#__PURE__*/ jsxs(Fragment, {
        children: [
            /*#__PURE__*/ jsx(HeaderContainer, {
                padding: headerSeparatorDisabled ? `${apollo_core.Spacing.SpacingBase} ${apollo_core.Spacing.SpacingL}` : `${apollo_core.Spacing.SpacingXs} ${apollo_core.Spacing.SpacingL} ${apollo_core.Spacing.SpacingBase}`,
                children: /*#__PURE__*/ jsx(AutopilotChatHeader, {})
            }),
            /*#__PURE__*/ jsxs(ContentContainer, {
                ref: setFullScreenContainer,
                children: [
                    /*#__PURE__*/ jsxs(MainContainer, {
                        ref: mainContainerRef,
                        historyOpen: historyOpen,
                        children: [
                            /*#__PURE__*/ jsx(ChatScrollContainer, {
                                mode: mode
                            }),
                            !readOnly && /*#__PURE__*/ jsx(InputBackground, {
                                children: /*#__PURE__*/ jsx(InputContainer, {
                                    children: /*#__PURE__*/ jsx(AutopilotChatInput, {})
                                })
                            })
                        ]
                    }),
                    !historyDisabled && /*#__PURE__*/ jsx(AutopilotChatHistory, {
                        open: historyOpen,
                        isFullScreen: true
                    }),
                    !settingsDisabled && /*#__PURE__*/ jsx(chat_settings, {
                        open: settingsOpen,
                        isFullScreen: true
                    })
                ]
            })
        ]
    });
};
export { FullScreenLayout };
