import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { Box, Text } from 'ink';
import { useCallback } from 'react';
import { IdeIntegrationNudge } from '../IdeIntegrationNudge.js';
// import { LoopDetectionConfirmation } from './LoopDetectionConfirmation.js'; // TODO: Not yet ported from upstream
import { FolderTrustDialog } from './FolderTrustDialog.js';
import { ShellConfirmationDialog } from './ShellConfirmationDialog.js';
import { ConsentPrompt } from './ConsentPrompt.js';
import { ThemeDialog } from './ThemeDialog.js';
import { SettingsDialog } from './SettingsDialog.js';
import { AuthInProgress } from './AuthInProgress.js';
import { AuthDialog } from './AuthDialog.js';
import { OAuthCodeDialog } from './OAuthCodeDialog.js';
import { EditorSettingsDialog } from './EditorSettingsDialog.js';
import { ProviderDialog } from './ProviderDialog.js';
import { ProviderModelDialog } from './ProviderModelDialog.js';
import { LoadProfileDialog } from './LoadProfileDialog.js';
import { ToolsDialog } from './ToolsDialog.js';
import { PrivacyNotice } from '../privacy/PrivacyNotice.js';
import { WorkspaceMigrationDialog } from './WorkspaceMigrationDialog.js';
// import { ProQuotaDialog } from './ProQuotaDialog.js'; // TODO: Not yet ported from upstream
import { PermissionsModifyTrustDialog } from './PermissionsModifyTrustDialog.js';
// import { ModelDialog } from './ModelDialog.js'; // TODO: Not yet ported from upstream
import { LoggingDialog } from './LoggingDialog.js';
import { theme } from '../semantic-colors.js';
import { useUIState } from '../contexts/UIStateContext.js';
import { useUIActions } from '../contexts/UIActionsContext.js';
// Props for DialogManager
export const DialogManager = ({ addItem, terminalWidth, config, settings, }) => {
    const uiState = useUIState();
    const uiActions = useUIActions();
    const { constrainHeight, terminalHeight, mainAreaWidth } = uiState;
    // staticExtraHeight not yet implemented in LLxprt
    const staticExtraHeight = 0;
    const handlePrivacyNoticeExit = useCallback(() => {
        uiActions.handlePrivacyNoticeExit();
    }, [uiActions]);
    // TODO: IdeTrustChangeDialog not yet ported from upstream
    // if (uiState.showIdeRestartPrompt) {
    //   return <IdeTrustChangeDialog reason={uiState.ideTrustRestartReason} />;
    // }
    if (uiState.showWorkspaceMigrationDialog) {
        return (_jsx(WorkspaceMigrationDialog, { workspaceExtensions: uiState.workspaceExtensions, onOpen: uiActions.onWorkspaceMigrationDialogOpen, onClose: uiActions.onWorkspaceMigrationDialogClose }));
    }
    // TODO: ProQuotaDialog not yet ported from upstream
    // if (uiState.proQuotaRequest) {
    //   return (
    //     <ProQuotaDialog
    //       failedModel={uiState.proQuotaRequest.failedModel}
    //       fallbackModel={uiState.proQuotaRequest.fallbackModel}
    //       onChoice={uiActions.handleProQuotaChoice}
    //     />
    //   );
    // }
    if (uiState.shouldShowIdePrompt) {
        return (_jsx(IdeIntegrationNudge, { ide: uiState.currentIDE, onComplete: uiActions.handleIdePromptComplete }));
    }
    if (uiState.isFolderTrustDialogOpen) {
        return (_jsx(FolderTrustDialog, { onSelect: uiActions.handleFolderTrustSelect, isRestarting: uiState.isRestarting }));
    }
    if (uiState.shellConfirmationRequest) {
        return (_jsx(ShellConfirmationDialog, { request: uiState.shellConfirmationRequest }));
    }
    // TODO: LoopDetectionConfirmation not yet ported from upstream
    // if (uiState.loopDetectionConfirmationRequest) {
    //   return (
    //     <LoopDetectionConfirmation
    //       onComplete={uiState.loopDetectionConfirmationRequest.onComplete}
    //     />
    //   );
    // }
    if (uiState.confirmationRequest) {
        return (_jsx(ConsentPrompt, { prompt: uiState.confirmationRequest.prompt, onConfirm: uiState.confirmationRequest.onConfirm, terminalWidth: terminalWidth }));
    }
    if (uiState.confirmUpdateExtensionRequests.length > 0) {
        const request = uiState.confirmUpdateExtensionRequests[0];
        return (_jsx(ConsentPrompt, { prompt: request.prompt, onConfirm: request.onConfirm, terminalWidth: terminalWidth }));
    }
    if (uiState.isThemeDialogOpen) {
        return (_jsxs(Box, { flexDirection: "column", children: [uiState.themeError && (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: theme.status.error, children: uiState.themeError }) })), _jsx(ThemeDialog, { onSelect: uiActions.handleThemeSelect, onHighlight: uiActions.handleThemeHighlight, settings: settings, availableTerminalHeight: constrainHeight ? terminalHeight - staticExtraHeight : undefined, terminalWidth: mainAreaWidth })] }));
    }
    if (uiState.isSettingsDialogOpen) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(SettingsDialog, { settings: settings, onSelect: uiActions.closeSettingsDialog, onRestartRequest: uiActions.handleSettingsRestart, config: config }) }));
    }
    // TODO: ModelDialog not yet ported from upstream
    // if (uiState.isModelDialogOpen) {
    //   return <ModelDialog onClose={uiActions.closeModelDialog} />;
    // }
    if (uiState.isAuthenticating) {
        return _jsx(AuthInProgress, { onTimeout: uiActions.handleAuthTimeout });
    }
    if (uiState.isAuthDialogOpen) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(AuthDialog, { onSelect: uiActions.handleAuthSelect, settings: settings, initialErrorMessage: uiState.authError }) }));
    }
    if (uiState.isOAuthCodeDialogOpen) {
        const provider = global.__oauth_provider ||
            'unknown';
        return (_jsx(OAuthCodeDialog, { provider: provider, onClose: uiActions.handleOAuthCodeDialogClose, onSubmit: uiActions.handleOAuthCodeSubmit }));
    }
    if (uiState.isEditorDialogOpen) {
        return (_jsxs(Box, { flexDirection: "column", children: [uiState.editorError && (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { color: theme.status.error, children: uiState.editorError }) })), _jsx(EditorSettingsDialog, { onSelect: uiActions.handleEditorSelect, settings: settings, onExit: uiActions.exitEditorDialog })] }));
    }
    if (uiState.isProviderDialogOpen) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(ProviderDialog, { providers: uiState.providerOptions, currentProvider: uiState.selectedProvider, onSelect: uiActions.handleProviderSelect, onClose: uiActions.exitProviderDialog }) }));
    }
    if (uiState.isProviderModelDialogOpen) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(ProviderModelDialog, { models: uiState.providerModels, currentModel: uiState.currentModel, onSelect: uiActions.handleProviderModelChange, onClose: uiActions.exitProviderModelDialog }) }));
    }
    if (uiState.isLoadProfileDialogOpen) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(LoadProfileDialog, { profiles: uiState.profiles, onSelect: uiActions.handleProfileSelect, onClose: uiActions.exitLoadProfileDialog }) }));
    }
    if (uiState.isToolsDialogOpen) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(ToolsDialog, { tools: uiState.toolsDialogTools, action: uiState.toolsDialogAction, disabledTools: uiState.toolsDialogDisabledTools, onSelect: uiActions.handleToolsSelect, onClose: uiActions.exitToolsDialog }) }));
    }
    if (uiState.showPrivacyNotice) {
        return _jsx(PrivacyNotice, { onExit: handlePrivacyNoticeExit, config: config });
    }
    if (uiState.isPermissionsDialogOpen) {
        return (_jsx(PermissionsModifyTrustDialog, { onExit: uiActions.closePermissionsDialog, addItem: addItem }));
    }
    if (uiState.isLoggingDialogOpen) {
        return (_jsx(LoggingDialog, { entries: (uiState.loggingDialogData?.entries || []), onClose: uiActions.closeLoggingDialog }));
    }
    return null;
};
//# sourceMappingURL=DialogManager.js.map