import { jsx as _jsx } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { useState, useCallback } from 'react';
import { Box } from 'ink';
import { RadioButtonSelect, } from '../shared/RadioButtonSelect.js';
export const NavigationMenu = ({ onContinue, onBack, onCancel, continueDisabled = false, continueLabel = 'Continue', showBack = true, isFocused = true, }) => {
    const [showCancelConfirm, setShowCancelConfirm] = useState(false);
    const handleSelect = useCallback((value) => {
        if (value === 'continue' && onContinue && !continueDisabled) {
            onContinue();
        }
        else if (value === 'back' && onBack) {
            onBack();
        }
        else if (value === 'cancel') {
            setShowCancelConfirm(true);
        }
    }, [onContinue, onBack, continueDisabled]);
    const handleCancelConfirm = useCallback((value) => {
        if (value === 'yes') {
            onCancel();
        }
        else {
            setShowCancelConfirm(false);
        }
    }, [onCancel]);
    if (showCancelConfirm) {
        const confirmItems = [
            { label: 'No, continue editing', value: 'no', key: 'no' },
            { label: 'Yes, discard and exit', value: 'yes', key: 'yes' },
        ];
        return (_jsx(Box, { marginTop: 1, children: _jsx(RadioButtonSelect, { items: confirmItems, onSelect: handleCancelConfirm, isFocused: isFocused }) }));
    }
    const items = [];
    if (onContinue) {
        items.push({
            label: continueDisabled ? `${continueLabel} (disabled)` : continueLabel,
            value: 'continue',
            key: 'continue',
        });
    }
    if (onBack && showBack) {
        items.push({ label: 'Back', value: 'back', key: 'back' });
    }
    items.push({ label: 'Cancel', value: 'cancel', key: 'cancel' });
    return (_jsx(Box, { marginTop: 1, children: _jsx(RadioButtonSelect, { items: items, onSelect: handleSelect, isFocused: isFocused }) }));
};
//# sourceMappingURL=NavigationMenu.js.map