import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { Box, Text } from 'ink';
import { useState } from 'react';
import { Colors } from '../colors.js';
import { theme } from '../semantic-colors.js';
import { RadioButtonSelect, } from './shared/RadioButtonSelect.js';
import { useKeypress } from '../hooks/useKeypress.js';
import * as process from 'node:process';
import * as path from 'node:path';
import { ExitCodes } from '@vybestack/llxprt-code-core';
export var FolderTrustChoice;
(function (FolderTrustChoice) {
    FolderTrustChoice["TRUST_FOLDER"] = "trust_folder";
    FolderTrustChoice["TRUST_PARENT"] = "trust_parent";
    FolderTrustChoice["DO_NOT_TRUST"] = "do_not_trust";
})(FolderTrustChoice || (FolderTrustChoice = {}));
export const FolderTrustDialog = ({ onSelect, isRestarting, }) => {
    const [exiting, setExiting] = useState(false);
    useKeypress((key) => {
        if (key.name === 'escape') {
            setExiting(true);
            setTimeout(() => {
                process.exit(ExitCodes.FATAL_CONFIG_ERROR);
            }, 100);
        }
    }, { isActive: !isRestarting });
    useKeypress((key) => {
        if (key.name === 'r') {
            process.exit(ExitCodes.SUCCESS);
        }
    }, { isActive: !!isRestarting });
    const currentFolder = path.basename(process.cwd());
    const parentFolder = path.basename(path.dirname(process.cwd()));
    const options = [
        {
            label: 'Trust folder',
            value: FolderTrustChoice.TRUST_FOLDER,
            key: `Trust folder (${currentFolder})`,
        },
        {
            label: `Trust parent folder (${parentFolder})`,
            value: FolderTrustChoice.TRUST_PARENT,
            key: `Trust parent folder (${parentFolder})`,
        },
        {
            label: "Don't trust",
            value: FolderTrustChoice.DO_NOT_TRUST,
            key: "Don't trust",
        },
    ];
    return (_jsxs(Box, { flexDirection: "column", width: "100%", children: [_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: Colors.AccentYellow, padding: 1, marginLeft: 1, marginRight: 1, children: [_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { bold: true, color: Colors.Foreground, children: "Do you trust this folder?" }), _jsx(Text, { color: Colors.DimComment, children: "Trusting a folder allows llxprt to execute commands it suggests. This is a security feature to prevent accidental execution in untrusted directories." })] }), _jsx(RadioButtonSelect, { items: options, onSelect: onSelect, isFocused: !isRestarting })] }), isRestarting && (_jsx(Box, { marginLeft: 1, marginTop: 1, children: _jsx(Text, { color: Colors.AccentYellow, children: "To see changes, llxprt must be restarted. Press r to exit and apply changes now." }) })), exiting && (_jsx(Box, { marginLeft: 1, marginTop: 1, children: _jsx(Text, { color: theme.status.warning, children: "A folder trust level must be selected to continue. Exiting since escape was pressed." }) }))] }));
};
//# sourceMappingURL=FolderTrustDialog.js.map