"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__, {
    AutopilotChatHeaderActions: ()=>AutopilotChatHeaderActions
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_namespaceObject = require("@lingui/react");
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 attachements_provider_cjs_namespaceObject = require("../../providers/attachements-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 picker_provider_cjs_namespaceObject = require("../../providers/picker-provider.cjs");
const index_cjs_namespaceObject = require("../../service/index.cjs");
const action_button_cjs_namespaceObject = require("../common/action-button.cjs");
const external_header_action_menu_cjs_namespaceObject = require("./header-action-menu.cjs");
const StyledActions = (0, styles_namespaceObject.styled)('div')(()=>({
        display: 'flex',
        alignItems: 'center',
        gap: apollo_core_default().Spacing.SpacingMicro
    }));
function AutopilotChatHeaderActionsComponent() {
    const { _ } = (0, react_namespaceObject.useLingui)();
    const chatService = (0, chat_service_provider_cjs_namespaceObject.useChatService)();
    const { disabledFeatures, chatMode, historyOpen, settingsOpen, setHistoryAnchorElement, readOnly } = (0, chat_state_provider_cjs_namespaceObject.useChatState)();
    const { clearAttachments } = (0, attachements_provider_cjs_namespaceObject.useAttachments)();
    const { customHeaderActions, handleCustomHeaderAction } = (0, picker_provider_cjs_namespaceObject.usePicker)();
    const [actionMenuAnchorEl, setActionMenuAnchorEl] = external_react_default().useState(null);
    const handleOpenActionMenu = external_react_default().useCallback((event)=>{
        setActionMenuAnchorEl(event.currentTarget);
    }, [
        setActionMenuAnchorEl
    ]);
    const handleCloseActionMenu = external_react_default().useCallback(()=>{
        setActionMenuAnchorEl(null);
    }, [
        setActionMenuAnchorEl
    ]);
    const handleActionMenuItemClick = external_react_default().useCallback((action)=>{
        handleCustomHeaderAction(action);
        setActionMenuAnchorEl(null);
    }, [
        handleCustomHeaderAction,
        setActionMenuAnchorEl
    ]);
    const handleClose = external_react_default().useCallback(()=>{
        if (!chatService) return;
        chatService.getPreHook(index_cjs_namespaceObject.AutopilotChatPreHookAction.CloseChat)().then((proceed)=>{
            if (!proceed) return;
            chatService?.close();
        });
    }, [
        chatService
    ]);
    const handleToggleChat = external_react_default().useCallback(()=>{
        if (!chatService) return;
        chatService.getPreHook(index_cjs_namespaceObject.AutopilotChatPreHookAction.ToggleChat)({
            chatMode
        }).then((proceed)=>{
            if (!proceed) return;
            chatService?.setChatMode(chatMode === index_cjs_namespaceObject.AutopilotChatMode.FullScreen ? index_cjs_namespaceObject.AutopilotChatMode.SideBySide : index_cjs_namespaceObject.AutopilotChatMode.FullScreen);
        });
    }, [
        chatService,
        chatMode
    ]);
    const handleNewChat = external_react_default().useCallback(()=>{
        if (!chatService) return;
        chatService.getPreHook(index_cjs_namespaceObject.AutopilotChatPreHookAction.NewChat)().then((proceed)=>{
            if (!proceed) return;
            chatService.newChat();
            chatService.stopResponse();
            chatService.setPrompt('');
            clearAttachments();
        });
    }, [
        clearAttachments,
        chatService
    ]);
    const toggleHistory = external_react_default().useCallback(()=>{
        if (!chatService) return;
        chatService.getPreHook(index_cjs_namespaceObject.AutopilotChatPreHookAction.ToggleHistory)({
            historyOpen
        }).then((proceed)=>{
            if (!proceed) return;
            chatService?.toggleHistory();
        });
    }, [
        chatService,
        historyOpen
    ]);
    const toggleSettings = external_react_default().useCallback(()=>{
        if (!chatService) return;
        chatService.getPreHook(index_cjs_namespaceObject.AutopilotChatPreHookAction.ToggleSettings)({
            settingsOpen
        }).then((proceed)=>{
            if (!proceed) return;
            chatService?.toggleSettings();
        });
    }, [
        chatService,
        settingsOpen
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(StyledActions, {
        children: [
            !readOnly && !disabledFeatures.newChat && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                iconName: "new_chat",
                variant: "custom",
                tooltip: _({
                    id: 'autopilot-chat.header.actions.new-chat'
                }),
                ariaLabel: _({
                    id: 'autopilot-chat.header.actions.new-chat'
                }),
                onClick: handleNewChat,
                "data-testid": "autopilot-chat-new-chat"
            }),
            !readOnly && !disabledFeatures.settings && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                iconName: "settings",
                tooltip: _({
                    id: 'autopilot-chat.header.actions.settings'
                }),
                ariaLabel: _({
                    id: 'autopilot-chat.header.actions.settings'
                }),
                onClick: toggleSettings,
                "data-testid": "autopilot-chat-settings"
            }),
            !readOnly && !disabledFeatures.history && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                ref: setHistoryAnchorElement,
                iconName: "history",
                variant: "custom",
                tooltip: _({
                    id: 'autopilot-chat.header.actions.history'
                }),
                ariaLabel: _({
                    id: 'autopilot-chat.header.actions.history'
                }),
                onClick: toggleHistory,
                "data-testid": "autopilot-chat-history"
            }),
            !disabledFeatures.fullScreen && chatMode !== index_cjs_namespaceObject.AutopilotChatMode.Embedded && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                iconName: chatMode !== index_cjs_namespaceObject.AutopilotChatMode.FullScreen ? 'open_in_full' : 'close_fullscreen',
                tooltip: chatMode !== index_cjs_namespaceObject.AutopilotChatMode.FullScreen ? _({
                    id: 'autopilot-chat.header.actions.expand'
                }) : _({
                    id: 'autopilot-chat.header.actions.collapse'
                }),
                ariaLabel: chatMode !== index_cjs_namespaceObject.AutopilotChatMode.FullScreen ? _({
                    id: 'autopilot-chat.header.actions.expand'
                }) : _({
                    id: 'autopilot-chat.header.actions.collapse'
                }),
                onClick: handleToggleChat,
                "data-testid": "autopilot-chat-toggle-fullscreen"
            }),
            !readOnly && customHeaderActions.length > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                        iconName: "more_vert",
                        variant: "outlined",
                        tooltip: _({
                            id: 'autopilot-chat.header.actions.custom-actions'
                        }),
                        onClick: handleOpenActionMenu,
                        "data-testid": "autopilot-chat-action-menu"
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_header_action_menu_cjs_namespaceObject.AutopilotChatHeaderActionMenu, {
                        actions: customHeaderActions,
                        onActionClick: handleActionMenuItemClick,
                        anchorEl: actionMenuAnchorEl,
                        open: !!actionMenuAnchorEl,
                        onClose: handleCloseActionMenu
                    })
                ]
            }),
            (chatMode !== index_cjs_namespaceObject.AutopilotChatMode.Embedded && !disabledFeatures.close || chatMode === index_cjs_namespaceObject.AutopilotChatMode.Embedded && false === disabledFeatures.close) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                iconName: "remove",
                onClick: handleClose,
                tooltip: _({
                    id: 'autopilot-chat.header.actions.close'
                }),
                ariaLabel: _({
                    id: 'autopilot-chat.header.actions.close'
                }),
                "data-testid": "autopilot-chat-close"
            })
        ]
    });
}
const AutopilotChatHeaderActions = /*#__PURE__*/ external_react_default().memo(AutopilotChatHeaderActionsComponent);
exports.AutopilotChatHeaderActions = __webpack_exports__.AutopilotChatHeaderActions;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AutopilotChatHeaderActions"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
