import { jsx } from "react/jsx-runtime";
import react from "react";
import { AutopilotChatMode, CHAT_WIDTH_KEY, CHAT_WIDTH_SIDE_BY_SIDE_MIN, StorageService } from "../service/index.js";
import { useChatService } from "./chat-service.provider.js";
import { useChatState } from "./chat-state-provider.js";
const AutopilotChatWidthContext = /*#__PURE__*/ react.createContext(null);
function AutopilotChatWidthProvider({ children }) {
    const storage = StorageService.Instance;
    const chatService = useChatService();
    const { chatMode } = useChatState();
    const [width, setWidth] = react.useState(()=>{
        const savedWidth = storage.get(CHAT_WIDTH_KEY);
        return savedWidth ? parseInt(savedWidth, 10) : CHAT_WIDTH_SIDE_BY_SIDE_MIN;
    });
    const [shouldAnimate, setShouldAnimate] = react.useState(false);
    react.useEffect(()=>{
        if (chatMode === AutopilotChatMode.Embedded) {
            const config = chatService.getConfig();
            if (config.embeddedContainer) setWidth(config.embeddedContainer.clientWidth);
        }
    }, [
        chatService,
        chatMode
    ]);
    const value = react.useMemo(()=>({
            width,
            setWidth,
            shouldAnimate,
            setShouldAnimate
        }), [
        width,
        shouldAnimate
    ]);
    return /*#__PURE__*/ jsx(AutopilotChatWidthContext.Provider, {
        value: value,
        children: children
    });
}
function useChatWidth() {
    const context = react.useContext(AutopilotChatWidthContext);
    if (!context) throw new Error('useChatWidth must be used within a AutopilotChatWidthProvider');
    return context;
}
export { AutopilotChatWidthContext, AutopilotChatWidthProvider, useChatWidth };
