"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__, {
    AutopilotChatScrollToBottomButton: ()=>AutopilotChatScrollToBottomButton
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_namespaceObject = require("@lingui/react");
const material_namespaceObject = require("@mui/material");
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 chat_scroll_provider_cjs_namespaceObject = require("../../providers/chat-scroll-provider.cjs");
const chat_service_provider_cjs_namespaceObject = require("../../providers/chat-service.provider.cjs");
const index_cjs_namespaceObject = require("../../service/index.cjs");
const action_button_cjs_namespaceObject = require("../common/action-button.cjs");
const ScrollButtonContainer = (0, material_namespaceObject.styled)('div')(({ visible, bottom, left })=>({
        position: 'fixed',
        bottom,
        left,
        zIndex: 1,
        transitionProperty: 'opacity',
        transitionDuration: '0.3s',
        transitionTimingFunction: 'ease-in-out',
        opacity: visible ? 1 : 0,
        pointerEvents: visible ? 'auto' : 'none',
        '& .MuiIconButton-root': {
            backgroundColor: 'var(--color-background)',
            boxShadow: '0px 2px 4px rgba(0, 0, 0, 0.1)',
            '&:hover,&:focus': {
                backgroundColor: "var(--color-hover) !important",
                boxShadow: '0px 2px 4px rgba(0, 0, 0, 0.2)'
            },
            '&:active': {
                backgroundColor: "var(--color-hover) !important"
            }
        }
    }));
const ScrollButtonWrapper = (0, material_namespaceObject.styled)('div')(()=>({
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        width: apollo_core_default().Spacing.SpacingXxl,
        height: apollo_core_default().Spacing.SpacingXxl,
        backgroundColor: 'transparent'
    }));
function AutopilotChatScrollToBottomButtonComponent({ overflowContainer }) {
    const { _ } = (0, react_namespaceObject.useLingui)();
    const [bottom, setBottom] = external_react_default().useState(0);
    const [left, setLeft] = external_react_default().useState(0);
    const { autoScroll, scrollToBottom } = (0, chat_scroll_provider_cjs_namespaceObject.useChatScroll)();
    const chatService = (0, chat_service_provider_cjs_namespaceObject.useChatService)();
    const chatInternalService = chatService.__internalService__;
    external_react_default().useEffect(()=>{
        if (!chatService || !chatInternalService) return;
        let animationFrameRef = null;
        const updatePosition = ()=>{
            animationFrameRef = requestAnimationFrame(()=>{
                if (overflowContainer) {
                    const rect = overflowContainer.getBoundingClientRect();
                    setBottom(Math.round(window.innerHeight - rect.bottom));
                    setLeft(Math.round(rect.left + rect.width / 2 - parseInt(apollo_core_default().Spacing.SpacingM, 10)));
                }
            });
        };
        const timeout = setTimeout(()=>{
            updatePosition();
        }, 200);
        window.addEventListener('resize', updatePosition);
        const unsubscribeResize = chatInternalService.on(index_cjs_namespaceObject.AutopilotChatInternalEvent.ChatResize, updatePosition);
        const unsubscribeModeChange = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.ModeChange, updatePosition);
        return ()=>{
            window.removeEventListener('resize', updatePosition);
            unsubscribeResize();
            unsubscribeModeChange();
            if (animationFrameRef) cancelAnimationFrame(animationFrameRef);
            if (timeout) clearTimeout(timeout);
        };
    }, [
        overflowContainer,
        chatInternalService,
        chatService,
        bottom
    ]);
    const isVisible = !autoScroll;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ScrollButtonContainer, {
        visible: isVisible,
        bottom: bottom,
        left: left,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ScrollButtonWrapper, {
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                iconName: "arrow_downward",
                onClick: ()=>scrollToBottom({
                        force: true
                    }),
                ariaLabel: _({
                    id: 'autopilot-chat.message.scroll-to-bottom'
                }),
                tooltip: isVisible ? _({
                    id: 'autopilot-chat.message.scroll-to-bottom'
                }) : void 0,
                tabIndex: isVisible ? 0 : -1,
                "data-testid": "autopilot-chat-scroll-to-bottom"
            })
        })
    });
}
const AutopilotChatScrollToBottomButton = /*#__PURE__*/ external_react_default().memo(AutopilotChatScrollToBottomButtonComponent);
exports.AutopilotChatScrollToBottomButton = __webpack_exports__.AutopilotChatScrollToBottomButton;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AutopilotChatScrollToBottomButton"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
