import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import { useUIState } from '../../contexts/UIStateContext.js';
import { ExtensionUpdateState } from '../../state/extensions.js';
import { Colors } from '../../colors.js';
export const ExtensionsList = ({ extensions, }) => {
    const { commandContext } = useUIState();
    const extensionsUpdateState = commandContext.ui.extensionsUpdateState;
    if (extensions.length === 0) {
        return _jsx(Text, { color: Colors.Foreground, children: "No extensions installed." });
    }
    return (_jsxs(Box, { flexDirection: "column", marginTop: 1, marginBottom: 1, children: [_jsx(Text, { color: Colors.Foreground, children: "Installed extensions:" }), _jsx(Box, { flexDirection: "column", paddingLeft: 2, children: extensions.map((ext) => {
                    const state = extensionsUpdateState.get(ext.name);
                    const isActive = ext.isActive;
                    const activeString = isActive ? 'active' : 'disabled';
                    const activeColor = isActive ? Colors.AccentGreen : Colors.DimComment;
                    let stateColor = Colors.DimComment;
                    const stateText = state || 'unknown state';
                    switch (state) {
                        case ExtensionUpdateState.CHECKING_FOR_UPDATES:
                        case ExtensionUpdateState.UPDATING:
                            stateColor = Colors.AccentCyan;
                            break;
                        case ExtensionUpdateState.UPDATE_AVAILABLE:
                        case ExtensionUpdateState.UPDATED_NEEDS_RESTART:
                            stateColor = Colors.AccentYellow;
                            break;
                        case ExtensionUpdateState.ERROR:
                            stateColor = Colors.AccentRed;
                            break;
                        case ExtensionUpdateState.UP_TO_DATE:
                        case ExtensionUpdateState.NOT_UPDATABLE:
                        case ExtensionUpdateState.UPDATED:
                            stateColor = Colors.AccentGreen;
                            break;
                        case undefined:
                            break;
                        default:
                            // No need to log error for undefined state - we show 'unknown state'
                            break;
                    }
                    return (_jsx(Box, { children: _jsxs(Text, { color: Colors.Foreground, children: [_jsx(Text, { color: Colors.AccentCyan, children: `${ext.name} (v${ext.version})` }), _jsx(Text, { color: activeColor, children: ` - ${activeString}` }), _jsx(Text, { color: stateColor, children: ` (${stateText})` })] }) }, ext.name));
                }) })] }));
};
//# sourceMappingURL=ExtensionsList.js.map