"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    usePicker: ()=>usePicker,
    AutopilotPickerProvider: ()=>AutopilotPickerProvider
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const index_cjs_namespaceObject = require("../service/index.cjs");
const external_chat_service_provider_cjs_namespaceObject = require("./chat-service.provider.cjs");
const PickerContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)({
    models: [],
    selectedModel: void 0,
    handleModelChange: ()=>{},
    agentModes: [],
    selectedAgentMode: void 0,
    handleAgentModeChange: ()=>{},
    customHeaderActions: [],
    handleCustomHeaderAction: ()=>{}
});
const AutopilotPickerProvider = ({ children })=>{
    const chatService = (0, external_chat_service_provider_cjs_namespaceObject.useChatService)();
    const [models, setModels] = (0, external_react_namespaceObject.useState)([]);
    const [selectedModel, setSelectedModel] = (0, external_react_namespaceObject.useState)();
    const [agentModes, setAgentModes] = (0, external_react_namespaceObject.useState)([]);
    const [selectedAgentMode, setSelectedAgentMode] = (0, external_react_namespaceObject.useState)();
    const [customHeaderActions, setCustomHeaderActions] = (0, external_react_namespaceObject.useState)([]);
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (!chatService) return;
        const unsubscribeModels = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetModels, (newModels)=>{
            setModels(newModels);
        });
        const unsubscribeSelectedModel = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetSelectedModel, (model)=>{
            setSelectedModel(model);
        });
        const unsubscribeAgentModes = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetAgentModes, (modes)=>{
            setAgentModes(modes);
        });
        const unsubscribeSelectedAgentMode = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetSelectedAgentMode, (mode)=>{
            setSelectedAgentMode(mode);
        });
        const unsubscribeCustomHeaderActions = chatService.on(index_cjs_namespaceObject.AutopilotChatEvent.SetCustomHeaderActions, (actions)=>{
            setCustomHeaderActions(actions);
        });
        if (chatService.getModels) setModels(chatService.getModels() ?? []);
        if (chatService.getSelectedModel) setSelectedModel(chatService.getSelectedModel());
        if (chatService.getAgentModes) setAgentModes(chatService.getAgentModes() ?? []);
        if (chatService.getAgentMode) setSelectedAgentMode(chatService.getAgentMode());
        if (chatService.getCustomHeaderActions) setCustomHeaderActions(chatService.getCustomHeaderActions() ?? []);
        return ()=>{
            unsubscribeModels();
            unsubscribeSelectedModel();
            unsubscribeAgentModes();
            unsubscribeSelectedAgentMode();
            unsubscribeCustomHeaderActions();
        };
    }, [
        chatService
    ]);
    const handleModelChange = (0, external_react_namespaceObject.useCallback)((modelId)=>{
        chatService?.setSelectedModel(modelId);
    }, [
        chatService
    ]);
    const handleAgentModeChange = (0, external_react_namespaceObject.useCallback)((modeId)=>{
        chatService?.setAgentMode(modeId);
    }, [
        chatService
    ]);
    const handleCustomHeaderAction = (0, external_react_namespaceObject.useCallback)((action)=>{
        chatService?._eventBus.publish(index_cjs_namespaceObject.AutopilotChatEvent.CustomHeaderActionClicked, action);
    }, [
        chatService
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PickerContext.Provider, {
        value: {
            models,
            selectedModel,
            handleModelChange,
            agentModes,
            selectedAgentMode,
            handleAgentModeChange,
            customHeaderActions,
            handleCustomHeaderAction
        },
        children: children
    });
};
const usePicker = ()=>(0, external_react_namespaceObject.useContext)(PickerContext);
exports.AutopilotPickerProvider = __webpack_exports__.AutopilotPickerProvider;
exports.usePicker = __webpack_exports__.usePicker;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AutopilotPickerProvider",
    "usePicker"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
