"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__, {
    useChatState: ()=>useChatState,
    AutopilotChatStateProvider: ()=>AutopilotChatStateProvider
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
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 index_cjs_namespaceObject = require("../service/index.cjs");
const external_chat_service_provider_cjs_namespaceObject = require("./chat-service.provider.cjs");
const AutopilotChatStateContext = /*#__PURE__*/ external_react_default().createContext(null);
const calculateSpacing = (chatSpacing)=>{
    const compactMode = chatSpacing?.compactMode ?? false;
    const markdownTokens = {
        li: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        p: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        h1: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeH4Bold : apollo_core_namespaceObject.FontVariantToken.fontSizeH3Bold,
        h2: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeH4Bold : apollo_core_namespaceObject.FontVariantToken.fontSizeH3Bold,
        h3: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeH4Bold : apollo_core_namespaceObject.FontVariantToken.fontSizeH3Bold,
        h4: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeMBold : apollo_core_namespaceObject.FontVariantToken.fontSizeLBold,
        h5: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeMBold : apollo_core_namespaceObject.FontVariantToken.fontSizeLBold,
        h6: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeMBold : apollo_core_namespaceObject.FontVariantToken.fontSizeLBold,
        th: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        td: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        em: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        del: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        strong: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        link: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM,
        citation: compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeXs : apollo_core_namespaceObject.FontVariantToken.fontSizeM
    };
    const promptBox = {
        minRows: compactMode ? index_cjs_namespaceObject.CHAT_COMPACT_MODE_INPUT_MIN_ROWS : index_cjs_namespaceObject.CHAT_INPUT_MIN_ROWS,
        maxRows: compactMode ? index_cjs_namespaceObject.CHAT_COMPACT_MODE_INPUT_MAX_ROWS : index_cjs_namespaceObject.CHAT_INPUT_MAX_ROWS
    };
    const messageSpacing = compactMode ? index_cjs_namespaceObject.CHAT_COMPACT_MODE_MESSAGE_SPACING : index_cjs_namespaceObject.CHAT_MESSAGE_SPACING;
    const messageGroupGap = compactMode ? index_cjs_namespaceObject.CHAT_COMPACT_MODE_MESSAGE_GROUP_GAP : index_cjs_namespaceObject.CHAT_MESSAGE_GROUP_GAP;
    const primaryFontToken = compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM;
    const primaryBoldFontToken = compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeSBold : apollo_core_namespaceObject.FontVariantToken.fontSizeMBold;
    const titleFontToken = apollo_core_namespaceObject.FontVariantToken.fontSizeH4;
    const suggestionSpacing = index_cjs_namespaceObject.CHAT_SUGGESTION_SPACING;
    const suggestionFontToken = compactMode ? apollo_core_namespaceObject.FontVariantToken.fontSizeS : apollo_core_namespaceObject.FontVariantToken.fontSizeM;
    const suggestionPadding = compactMode ? `${apollo_core_default().Spacing.SpacingMicro} ${apollo_core_default().Spacing.SpacingXs}` : `${apollo_core_default().Spacing.SpacingXs} ${apollo_core_default().Spacing.SpacingBase}`;
    return {
        compactMode,
        promptBox: {
            minRows: chatSpacing?.promptBox?.minRows ?? promptBox.minRows,
            maxRows: chatSpacing?.promptBox?.maxRows ?? promptBox.maxRows
        },
        primaryFontToken: chatSpacing?.primaryFontToken ?? primaryFontToken,
        primaryBoldFontToken: chatSpacing?.primaryBoldFontToken ?? primaryBoldFontToken,
        titleFontToken: chatSpacing?.titleFontToken ?? titleFontToken,
        suggestionSpacing: chatSpacing?.suggestionSpacing ?? suggestionSpacing,
        suggestionFontToken: chatSpacing?.suggestionFontToken ?? suggestionFontToken,
        suggestionPadding: chatSpacing?.suggestionPadding ?? suggestionPadding,
        messageSpacing: chatSpacing?.messageSpacing ?? messageSpacing,
        messageGroupGap: chatSpacing?.messageGroupGap ?? messageGroupGap,
        markdownTokens: {
            li: chatSpacing?.markdownTokens?.li ?? markdownTokens.li,
            p: chatSpacing?.markdownTokens?.p ?? markdownTokens.p,
            h1: chatSpacing?.markdownTokens?.h1 ?? markdownTokens.h1,
            h2: chatSpacing?.markdownTokens?.h2 ?? markdownTokens.h2,
            h3: chatSpacing?.markdownTokens?.h3 ?? markdownTokens.h3,
            h4: chatSpacing?.markdownTokens?.h4 ?? markdownTokens.h4,
            h5: chatSpacing?.markdownTokens?.h5 ?? markdownTokens.h5,
            h6: chatSpacing?.markdownTokens?.h6 ?? markdownTokens.h6,
            th: chatSpacing?.markdownTokens?.th ?? markdownTokens.th,
            td: chatSpacing?.markdownTokens?.td ?? markdownTokens.td,
            em: chatSpacing?.markdownTokens?.em ?? markdownTokens.em,
            del: chatSpacing?.markdownTokens?.del ?? markdownTokens.del,
            strong: chatSpacing?.markdownTokens?.strong ?? markdownTokens.strong,
            link: chatSpacing?.markdownTokens?.link ?? markdownTokens.link,
            citation: chatSpacing?.markdownTokens?.citation ?? markdownTokens.citation
        }
    };
};
const AutopilotChatStateProvider = ({ children, portalContainer })=>{
    const chatService = (0, external_chat_service_provider_cjs_namespaceObject.useChatService)();
    const chatInternalService = chatService.__internalService__;
    const [allowedAttachments, setAllowedAttachments] = external_react_default().useState(chatService?.getConfig()?.allowedAttachments ?? {
        multiple: false,
        types: {},
        maxSize: 0,
        maxCount: 0
    });
    const [historyAnchorElement, setHistoryAnchorElement] = external_react_default().useState(null);
    const [fullScreenContainer, setFullScreenContainer] = external_react_default().useState(null);
    const [historyOpen, setHistoryOpen] = external_react_default().useState(chatService?.historyOpen ?? false);
    const [settingsOpen, setSettingsOpen] = external_react_default().useState(chatService?.settingsOpen ?? false);
    const [chatMode, setChatMode] = external_react_default().useState(chatService?.getConfig()?.mode ?? index_cjs_namespaceObject.AutopilotChatMode.SideBySide);
    const [disabledFeatures, setDisabledFeatures] = external_react_default().useState(chatService?.getConfig()?.disabledFeatures ?? {});
    const [overrideLabels, setOverrideLabels] = external_react_default().useState(chatService?.getConfig()?.overrideLabels ?? {});
    const [firstRunExperience, setFirstRunExperience] = external_react_default().useState(chatService?.getConfig()?.firstRunExperience ?? {
        title: '',
        description: '',
        suggestions: []
    });
    const [hasMessages, setHasMessages] = external_react_default().useState(false);
    const [readOnly, setReadOnly] = external_react_default().useState(chatService?.getReadOnly() ?? false);
    const [spacing, setSpacing] = external_react_default().useState(calculateSpacing(chatService?.getConfig()?.spacing));
    const [theming, setTheming] = external_react_default().useState(chatService?.getConfig()?.theming);
    external_react_default().useEffect(()=>{
        if (!chatService) return;
        const unsubscribeHistoryToggle = chatInternalService.on(index_cjs_namespaceObject.AutopilotChatInternalEvent.ToggleHistory, (isOpen)=>{
            setHistoryOpen(isOpen);
        });
        const unsubscribeSettingsToggle = chatInternalService.on(index_cjs_namespaceObject.AutopilotChatInternalEvent.ToggleSettings, (isOpen)=>{
            setSettingsOpen(isOpen);
        });
        const unsubscribeModeChange = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.ModeChange, (mode)=>{
            setChatMode(mode);
        });
        const unsubscribeDisabledFeatures = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetDisabledFeatures, (features)=>{
            setDisabledFeatures(features);
        });
        const unsubscribeOverrideLabels = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetOverrideLabels, (labels)=>{
            setOverrideLabels(labels);
        });
        const unsubscribeFirstRunExperience = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetFirstRunExperience, (experience)=>{
            setFirstRunExperience(experience);
        });
        const unsubscribeAllowedAttachments = chatInternalService.on(index_cjs_namespaceObject.AutopilotChatInternalEvent.SetAllowedAttachments, (allowed)=>{
            setAllowedAttachments(allowed);
        });
        const unsubscribeReadOnly = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetReadOnly, (isReadOnly)=>{
            setReadOnly(isReadOnly);
        });
        const unsubscribeSpacing = chatInternalService.on(index_cjs_namespaceObject.AutopilotChatInternalEvent.SetSpacing, (spacingConfig)=>{
            setSpacing(calculateSpacing(spacingConfig));
        });
        const unsubscribeTheming = chatInternalService.on(index_cjs_namespaceObject.AutopilotChatInternalEvent.SetTheming, (themingConfig)=>{
            setTheming(themingConfig);
        });
        return ()=>{
            unsubscribeHistoryToggle();
            unsubscribeSettingsToggle();
            unsubscribeModeChange();
            unsubscribeDisabledFeatures();
            unsubscribeOverrideLabels();
            unsubscribeFirstRunExperience();
            unsubscribeReadOnly();
            unsubscribeAllowedAttachments();
            unsubscribeSpacing();
            unsubscribeTheming();
        };
    }, [
        chatService,
        chatInternalService
    ]);
    const value = external_react_default().useMemo(()=>({
            historyOpen,
            settingsOpen,
            chatMode,
            disabledFeatures,
            overrideLabels,
            firstRunExperience,
            allowedAttachments,
            historyAnchorElement,
            setHistoryAnchorElement,
            fullScreenContainer,
            setFullScreenContainer,
            hasMessages,
            setHasMessages,
            spacing,
            theming,
            portalContainer,
            readOnly
        }), [
        historyOpen,
        settingsOpen,
        chatMode,
        disabledFeatures,
        overrideLabels,
        firstRunExperience,
        allowedAttachments,
        historyAnchorElement,
        setHistoryAnchorElement,
        fullScreenContainer,
        setFullScreenContainer,
        hasMessages,
        setHasMessages,
        spacing,
        theming,
        portalContainer,
        readOnly
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(AutopilotChatStateContext.Provider, {
        value: value,
        children: children
    });
};
const useChatState = ()=>{
    const context = external_react_default().useContext(AutopilotChatStateContext);
    if (!context) throw new Error('useChatState must be used within a AutopilotChatStateProvider');
    return context;
};
exports.AutopilotChatStateProvider = __webpack_exports__.AutopilotChatStateProvider;
exports.useChatState = __webpack_exports__.useChatState;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AutopilotChatStateProvider",
    "useChatState"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
