"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    ApChat: ()=>ApChat
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const styles_namespaceObject = require("@mui/material/styles");
const apollo_core_namespaceObject = require("@uipath/apollo-core");
var apollo_core_default = /*#__PURE__*/ __webpack_require__.n(apollo_core_namespaceObject);
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const external_react_dom_namespaceObject = require("react-dom");
const index_cjs_namespaceObject = require("../../../i18n/index.cjs");
const external_theme_index_cjs_namespaceObject = require("../../theme/index.cjs");
const drag_handle_cjs_namespaceObject = require("./components/common/drag-handle.cjs");
const dropzone_cjs_namespaceObject = require("./components/dropzone/dropzone.cjs");
const layout_index_cjs_namespaceObject = require("./components/layout/index.cjs");
const attachements_provider_cjs_namespaceObject = require("./providers/attachements-provider.cjs");
const chat_scroll_provider_cjs_namespaceObject = require("./providers/chat-scroll-provider.cjs");
const chat_service_provider_cjs_namespaceObject = require("./providers/chat-service.provider.cjs");
const chat_state_provider_cjs_namespaceObject = require("./providers/chat-state-provider.cjs");
const chat_width_provider_cjs_namespaceObject = require("./providers/chat-width-provider.cjs");
const error_provider_cjs_namespaceObject = require("./providers/error-provider.cjs");
const loading_provider_cjs_namespaceObject = require("./providers/loading-provider.cjs");
const locale_provider_cjs_namespaceObject = require("./providers/locale-provider.cjs");
const picker_provider_cjs_namespaceObject = require("./providers/picker-provider.cjs");
const resource_data_provider_cjs_namespaceObject = require("./providers/resource-data-provider.cjs");
const streaming_provider_cjs_namespaceObject = require("./providers/streaming-provider.cjs");
const theme_provider_cjs_namespaceObject = require("./providers/theme-provider.cjs");
const external_service_index_cjs_namespaceObject = require("./service/index.cjs");
const MUI_THEME_MAP = {
    light: external_theme_index_cjs_namespaceObject.apolloMaterialUiThemeLight,
    dark: external_theme_index_cjs_namespaceObject.apolloMaterialUiThemeDark,
    'light-hc': external_theme_index_cjs_namespaceObject.apolloMaterialUiThemeLightHC,
    'dark-hc': external_theme_index_cjs_namespaceObject.apolloMaterialUiThemeDarkHC
};
const ChatContainer = (0, styles_namespaceObject.styled)('div')(({ shouldAnimate, mode, width, fullHeight })=>({
        width: mode === external_service_index_cjs_namespaceObject.AutopilotChatMode.FullScreen ? external_service_index_cjs_namespaceObject.CHAT_WIDTH_FULL_SCREEN : width,
        display: 'flex',
        flexDirection: mode === external_service_index_cjs_namespaceObject.AutopilotChatMode.FullScreen ? 'column' : 'row',
        height: fullHeight ? '100vh' : 'calc(100vh - 48px)',
        position: 'relative',
        boxSizing: 'border-box',
        border: `${apollo_core_default().Border.BorderThickS} solid var(--color-border-de-emp)`,
        borderTop: 'none',
        borderLeft: 'none',
        ...shouldAnimate && {
            transition: `width ${external_service_index_cjs_namespaceObject.CHAT_CONTAINER_ANIMATION_DURATION}ms ease`
        },
        ...mode === external_service_index_cjs_namespaceObject.AutopilotChatMode.Closed && {
            display: 'none'
        },
        ...mode === external_service_index_cjs_namespaceObject.AutopilotChatMode.Embedded && {
            width: '100%',
            height: '100%',
            position: 'absolute',
            border: 'none'
        }
    }));
const ApI18nWithLocale = /*#__PURE__*/ external_react_default().memo(({ children })=>{
    const { locale } = (0, locale_provider_cjs_namespaceObject.useLocale)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApI18nProvider, {
        component: "material/components/ap-chat",
        locale: locale,
        children: children
    });
});
const AutopilotChatContent = /*#__PURE__*/ external_react_default().memo(()=>{
    const { width, shouldAnimate } = (0, chat_width_provider_cjs_namespaceObject.useChatWidth)();
    const { historyOpen, settingsOpen, disabledFeatures, chatMode, readOnly } = (0, chat_state_provider_cjs_namespaceObject.useChatState)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(ChatContainer, {
        shouldAnimate: shouldAnimate,
        mode: chatMode,
        width: width,
        fullHeight: false === disabledFeatures.fullHeight,
        children: [
            chatMode === external_service_index_cjs_namespaceObject.AutopilotChatMode.SideBySide && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(drag_handle_cjs_namespaceObject.DragHandle, {}),
            chatMode === external_service_index_cjs_namespaceObject.AutopilotChatMode.FullScreen ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(layout_index_cjs_namespaceObject.FullScreenLayout, {
                historyOpen: historyOpen,
                settingsOpen: settingsOpen,
                historyDisabled: disabledFeatures.history ?? false,
                settingsDisabled: disabledFeatures.settings ?? false,
                headerSeparatorDisabled: disabledFeatures.headerSeparator ?? false,
                mode: chatMode,
                readOnly: readOnly
            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(layout_index_cjs_namespaceObject.StandardLayout, {
                historyOpen: historyOpen,
                settingsOpen: settingsOpen,
                historyDisabled: disabledFeatures.history ?? false,
                settingsDisabled: disabledFeatures.settings ?? false,
                headerDisabled: disabledFeatures.header ?? false,
                headerSeparatorDisabled: disabledFeatures.headerSeparator ?? false,
                mode: chatMode,
                readOnly: readOnly
            })
        ]
    });
});
function ApChat({ chatServiceInstance, locale: initialLocale = 'en', theme: initialTheme = 'light', portalContainer, enableInternalThemeProvider = false, disableEmbeddedPortal = false }) {
    const [embeddedContainer, setEmbeddedContainer] = external_react_default().useState(null);
    const [currentTheme, setCurrentTheme] = external_react_default().useState(initialTheme);
    external_react_default().useEffect(()=>{
        chatServiceInstance.setLocale(initialLocale);
    }, [
        initialLocale,
        chatServiceInstance
    ]);
    external_react_default().useEffect(()=>{
        chatServiceInstance.setTheme(initialTheme);
        setCurrentTheme(initialTheme);
    }, [
        initialTheme,
        chatServiceInstance
    ]);
    external_react_default().useEffect(()=>{
        const updateEmbeddedContainer = ()=>{
            const config = chatServiceInstance.getConfig();
            config.mode === external_service_index_cjs_namespaceObject.AutopilotChatMode.Embedded && config.embeddedContainer ? setEmbeddedContainer(config.embeddedContainer) : setEmbeddedContainer(null);
        };
        updateEmbeddedContainer();
        const unsubscribe = chatServiceInstance.on(external_service_index_cjs_namespaceObject.AutopilotChatEvent.ModeChange, ()=>{
            updateEmbeddedContainer();
        });
        return ()=>{
            unsubscribe();
        };
    }, [
        chatServiceInstance
    ]);
    const muiTheme = enableInternalThemeProvider ? MUI_THEME_MAP[currentTheme] : null;
    const chatProviders = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_service_provider_cjs_namespaceObject.AutopilotChatServiceProvider, {
        chatServiceInstance: chatServiceInstance,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(theme_provider_cjs_namespaceObject.ThemeProvider, {
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(locale_provider_cjs_namespaceObject.LocaleProvider, {
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ApI18nWithLocale, {
                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(streaming_provider_cjs_namespaceObject.AutopilotStreamingProvider, {
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_scroll_provider_cjs_namespaceObject.AutopilotChatScrollProvider, {
                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_state_provider_cjs_namespaceObject.AutopilotChatStateProvider, {
                                portalContainer: portalContainer,
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(error_provider_cjs_namespaceObject.AutopilotErrorProvider, {
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(loading_provider_cjs_namespaceObject.AutopilotLoadingProvider, {
                                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(attachements_provider_cjs_namespaceObject.AutopilotAttachmentsProvider, {
                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(picker_provider_cjs_namespaceObject.AutopilotPickerProvider, {
                                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(resource_data_provider_cjs_namespaceObject.AutopilotResourceDataProvider, {
                                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_width_provider_cjs_namespaceObject.AutopilotChatWidthProvider, {
                                                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(dropzone_cjs_namespaceObject.AutopilotChatDropzone, {
                                                            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AutopilotChatContent, {})
                                                        })
                                                    })
                                                })
                                            })
                                        })
                                    })
                                })
                            })
                        })
                    })
                })
            })
        })
    });
    const chatContent = enableInternalThemeProvider && muiTheme ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(styles_namespaceObject.ThemeProvider, {
        theme: muiTheme,
        children: chatProviders
    }) : chatProviders;
    if (embeddedContainer && !disableEmbeddedPortal) return /*#__PURE__*/ (0, external_react_dom_namespaceObject.createPortal)(chatContent, embeddedContainer);
    return chatContent;
}
exports.ApChat = __webpack_exports__.ApChat;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ApChat"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
