import React from 'react';

// 导入独立的对话框组件
import ApiKeyDialog, { type ApiKeyFormData, type ApiKeyDialogProps } from './Dialog/ApiKeyDialog';
import OllamaDialog, { type OllamaFormData, type OllamaDialogProps } from './Dialog/OllamaDialog';
import SystemModelDialog, { type SystemModelFormData, type SystemModelDialogProps, type ModelOption, type ModelGroup } from './Dialog/SystemModelDialog';
import ConfigurationDialog, { type ConfigurationFormData, type ConfigurationDialogProps, type ConfigFormItem, type DocLinkConfig } from './Dialog/ConfigurationDialog';



// 基础对话框 Props 接口
export interface BaseDialogProps {
  open: boolean;
  onClose: () => void;
  loading: boolean;
  editMode?: boolean;
}

// 导出所有表单数据接口
export type { ApiKeyFormData, OllamaFormData, SystemModelFormData, ConfigurationFormData };

// 导出所有对话框 Props 接口
export type { ApiKeyDialogProps, OllamaDialogProps, SystemModelDialogProps, ConfigurationDialogProps };

// 导出其他相关接口和常量
export type { ModelOption, ModelGroup };

// 模型对话框整合组件的 Props 接口
export interface ModelDialogsProps {
  apiKeyDialog: {
    open: boolean;
    closeDialog: () => void;
    submitApiKey: (data: ApiKeyFormData) => void;
    loading: boolean;
    factoryName: string;
    initialData?: ApiKeyFormData;
    editMode?: boolean;
  };
  ollamaDialog: {
    open: boolean;
    closeDialog: () => void;
    submitOllama: (data: OllamaFormData) => void;
    loading: boolean;
    initialData?: OllamaFormData;
    editMode?: boolean;
  };
  configurationDialog: {
    open: boolean;
    closeDialog: () => void;
    submitConfiguration: (data: Partial<ConfigurationFormData>) => void;
    loading: boolean;
    editMode?: boolean;
    llmFactory: string;
    config: {
      formItems: ConfigFormItem[];
      docLink: DocLinkConfig;
      title: string;
      defaultValues: Record<string, any>;
    } | null;
  };
  systemDialog: {
    open: boolean;
    closeDialog: () => void;
    submitSystemModelSetting: (data: SystemModelFormData) => Promise<void>;
    loading: boolean;
    initialData?: SystemModelFormData;
    editMode?: boolean;
    allModelOptions: any;
  };
}

/**
 * 模型对话框整合组件
 */
export const ModelDialogs: React.FC<ModelDialogsProps> = ({
  apiKeyDialog,
  ollamaDialog,
  configurationDialog,
  systemDialog,
}) => {
  return (
    <>
      {/* API Key 对话框 */}
      <ApiKeyDialog
        open={apiKeyDialog.open}
        onClose={apiKeyDialog.closeDialog}
        onSubmit={apiKeyDialog.submitApiKey}
        loading={apiKeyDialog.loading}
        factoryName={apiKeyDialog.factoryName}
        initialData={apiKeyDialog.initialData}
        editMode={apiKeyDialog!.editMode}
      />

      {/* Ollama 对话框 */}
      <OllamaDialog
        open={ollamaDialog.open}
        onClose={ollamaDialog.closeDialog}
        onSubmit={ollamaDialog.submitOllama}
        loading={ollamaDialog.loading}
        initialData={ollamaDialog.initialData}
        editMode={ollamaDialog.editMode}
      />

      {/* 通用配置对话框 */}
      <ConfigurationDialog
        open={configurationDialog.open}
        onClose={configurationDialog.closeDialog}
        onSubmit={configurationDialog.submitConfiguration}
        loading={configurationDialog.loading}
        editMode={configurationDialog.editMode}
        formItems={configurationDialog.config?.formItems || []}
        docLink={configurationDialog.config?.docLink}
        title={configurationDialog.config?.title || configurationDialog.llmFactory}
      />

      {/* 系统默认模型设置对话框 */}
      <SystemModelDialog
        open={systemDialog.open}
        onClose={systemDialog.closeDialog}
        onSubmit={systemDialog.submitSystemModelSetting}
        loading={systemDialog.loading}
        initialData={systemDialog.initialData}
        editMode={systemDialog.editMode}
        allModelOptions={systemDialog.allModelOptions}
      />
    </>
  );
};