import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { bridgeWizardIndexByStepId, useBridgeWizardStore, } from './bridgeWizardStore.js';
import { EnterAmount } from './EnterAmount.js';
import { SelectChains } from './SelectChains.js';
import { SelectNetwork } from './SelectNetwork.js';
import { useSaveWizardProgress } from '../hooks/useSaveWizardProgress.js';
import { Box, Text } from 'ink';
const useStepProgress = ({ stepId, }) => {
    const { steps, wizardState } = useBridgeWizardStore();
    const currentIndex = bridgeWizardIndexByStepId[wizardState.stepId];
    const stepIndex = bridgeWizardIndexByStepId[stepId];
    const step = steps[stepIndex];
    if (stepIndex < currentIndex) {
        return {
            status: 'done',
            title: step.title,
            summary: step.getSummary
                ? step.getSummary(wizardState)
                : undefined,
        };
    }
    if (stepIndex === currentIndex) {
        return {
            status: 'current',
            title: step.title,
        };
    }
    return {
        status: 'upcoming',
        title: step.title,
    };
};
const WizardProgressForStep = ({ stepId }) => {
    const { status, title, summary } = useStepProgress({ stepId });
    return (_jsxs(Box, { gap: 1, paddingX: 1, children: [_jsx(Text, { color: status === 'done' ? 'green' : status === 'current' ? 'blue' : 'gray', children: status === 'done' ? '✓' : status === 'current' ? '>' : '○' }), _jsxs(Text, { color: status === 'current' ? 'blue' : 'white', children: [" ", title] }), status === 'done' && summary && _jsx(Text, { color: "yellow", children: summary })] }));
};
const WizardProgress = () => {
    const { steps, wizardState } = useBridgeWizardStore();
    if (wizardState.stepId === 'completed') {
        return (_jsx(Box, { children: _jsx(Text, { children: "Completed" }) }));
    }
    return (_jsx(Box, { flexDirection: "column", children: steps
            .filter(({ id }) => id !== 'completed')
            .map(({ id }) => {
            return _jsx(WizardProgressForStep, { stepId: id }, id);
        }) }));
};
export const BridgeWizard = () => {
    const { wizardState } = useBridgeWizardStore();
    // TODO: update before alpha release, remove private key step entirely from wizard
    useSaveWizardProgress('bridge', wizardState, [
        'completed',
        'enter-private-key',
    ]);
    const stepId = wizardState.stepId;
    return (_jsxs(Box, { flexDirection: "column", gap: 1, children: [_jsx(Text, { bold: true, color: "blue", children: "\uD83C\uDF09 Bridge Wizard" }), _jsx(WizardProgress, {}), _jsxs(Box, { flexDirection: "column", children: [stepId === 'select-network' && _jsx(SelectNetwork, {}), stepId === 'select-chains' && _jsx(SelectChains, {}), stepId === 'enter-amount' && _jsx(EnterAmount, {})] })] }));
};
