"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const react = require("../../../_vendor/@legendapp/state/react.cjs");
const React = require("react");
const modelStore = require("../../../stores/model-store.cjs");
function useModelSelection(enableModalSelection = true) {
  const availableModels = react.use$(modelStore.modelStore$.models);
  const currentModel = react.use$(modelStore.modelStore$.selectedModel);
  const isLoading = react.use$(modelStore.modelStore$.isLoading);
  const error = react.use$(modelStore.modelStore$.error);
  const hasRequestedRef = React.useRef(false);
  React.useEffect(() => {
    if (!enableModalSelection) return;
    if (hasRequestedRef.current) return;
    if (availableModels.length === 0 && !isLoading && !error) {
      hasRequestedRef.current = true;
      modelStore.modelActions.fetchAvailableModels();
    }
  }, [availableModels.length, isLoading, error, enableModalSelection]);
  const selectModel = (model) => {
    modelStore.modelActions.selectModel(model);
  };
  const selectModelById = (modelId) => {
    modelStore.modelActions.selectModelById(modelId);
  };
  const getCurrentModelDisplayName = () => {
    if (isLoading) return "Loading...";
    if (error) return "Error";
    return currentModel?.name || "Claude 3.5 Sonnet";
  };
  const getCurrentModelId = () => {
    return currentModel?.id || "anthropic/claude-3.5-sonnet";
  };
  const getAvailableModels = () => {
    return availableModels;
  };
  const refreshModels = () => {
    hasRequestedRef.current = false;
    modelStore.modelActions.fetchAvailableModels();
  };
  const clearError = () => {
    modelStore.modelActions.clearError();
  };
  return {
    // 状态
    availableModels: getAvailableModels(),
    currentModel,
    isLoading,
    error,
    // 方法
    selectModel,
    selectModelById,
    getCurrentModelDisplayName,
    getCurrentModelId,
    refreshModels,
    clearError
  };
}
exports.useModelSelection = useModelSelection;
//# sourceMappingURL=use-model-selection.cjs.map
