import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { Box, Text, useInput } from 'ink';
import { performWorkspaceExtensionMigration } from '../../config/extension.js';
import { RadioButtonSelect } from './shared/RadioButtonSelect.js';
import { theme } from '../semantic-colors.js';
import { useState } from 'react';
export function WorkspaceMigrationDialog(props) {
    const { workspaceExtensions, onOpen, onClose } = props;
    const [migrationComplete, setMigrationComplete] = useState(false);
    const [failedExtensions, setFailedExtensions] = useState([]);
    onOpen();
    const onMigrate = async () => {
        const failed = await performWorkspaceExtensionMigration(workspaceExtensions, 
        // We aren't updating extensions, just moving them around, don't need to ask for consent.
        async (_) => true);
        setFailedExtensions(failed);
        setMigrationComplete(true);
    };
    useInput((input) => {
        if (migrationComplete && input === 'q') {
            process.exit(0);
        }
    });
    if (migrationComplete) {
        return (_jsx(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.border.default, padding: 1, children: failedExtensions.length > 0 ? (_jsxs(_Fragment, { children: [_jsx(Text, { color: theme.text.primary, children: "The following extensions failed to migrate. Please try installing them manually. To see other changes, Gemini CLI must be restarted. Press 'q' to quit." }), _jsx(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2, children: failedExtensions.map((failed) => (_jsxs(Text, { children: ["- ", failed] }, failed))) })] })) : (_jsx(Text, { color: theme.text.primary, children: "Migration complete. To see changes, Gemini CLI must be restarted. Press 'q' to quit." })) }));
    }
    return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: theme.border.default, padding: 1, children: [_jsxs(Text, { bold: true, color: theme.text.primary, children: ["Workspace-level extensions are deprecated", '\n'] }), _jsx(Text, { color: theme.text.primary, children: "Would you like to install them at the user level?" }), _jsx(Text, { color: theme.text.primary, children: "The extension definition will remain in your workspace directory." }), _jsx(Text, { color: theme.text.primary, children: "If you opt to skip, you can install them manually using the extensions install command." }), _jsx(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2, children: workspaceExtensions.map((extension) => (_jsxs(Text, { children: ["- ", extension.name] }, extension.name))) }), _jsx(Box, { marginTop: 1, children: _jsx(RadioButtonSelect, { items: [
                        { label: 'Install all', value: 'migrate', key: 'migrate' },
                        { label: 'Skip', value: 'skip', key: 'skip' },
                    ], onSelect: (value) => {
                        if (value === 'migrate') {
                            onMigrate();
                        }
                        else {
                            onClose();
                        }
                    } }) })] }));
}
//# sourceMappingURL=WorkspaceMigrationDialog.js.map