import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { BridgeWizard } from '../actions/bridge/wizard/BridgeWizard.js';
import { DeployCreate2Wizard } from '../actions/deploy-create2/wizard/DeployCreate2Wizard.js';
import { Select } from '@inkjs/ui';
import { Box, Text } from 'ink';
import { useState } from 'react';
import Gradient from 'ink-gradient';
import BigText from 'ink-big-text';
import { useUserContext } from '../queries/userContext.js';
import { actionDescriptionByWizardId } from '../models/userContext.js';
import { useBridgeWizardStore } from '../actions/bridge/wizard/bridgeWizardStore.js';
import { useDeployCreate2WizardStore } from '../actions/deploy-create2/wizard/deployCreate2WizardStore.js';
import { z } from 'zod';
import { option } from 'pastel';
const actions = [
    { label: '🚀 Deploy a contract', value: 'deploy' },
    { label: '🌉 Bridge assets', value: 'bridge' },
    // {label: '✅ Verify a contract', value: 'verify'},
];
const zodOptions = z.object({
    prepare: z
        .boolean()
        .optional()
        .describe(option({
        description: 'Print the command without executing it',
        alias: 'p',
    })),
});
export const options = zodOptions;
export default function DefaultEntrypoint({ options, }) {
    const [selectedOption, setSelectedOption] = useState(null);
    const { data: userContext, isLoading: isUserContextLoading } = useUserContext();
    if (isUserContextLoading || !userContext) {
        return null;
    }
    const { lastWizardId, lastWizardState } = userContext;
    const optionsWithLastAction = lastWizardId
        ? [
            {
                label: `🔄 Pick up where you left off: ${actionDescriptionByWizardId[lastWizardId]}`,
                value: 'continue',
            },
            ...actions,
        ]
        : actions;
    if (!selectedOption) {
        return (_jsxs(Box, { flexDirection: "column", padding: 1, children: [_jsx(Gradient, { name: "passion", children: _jsx(BigText, { text: "SUP", font: "3d" }) }), _jsxs(Box, { marginBottom: 1, flexDirection: "column", gap: 1, children: [options.prepare && (_jsx(Box, { children: _jsxs(Text, { children: [_jsx(Text, { children: "Prepare mode:" }), " Command will be displayed but not executed"] }) })), _jsx(Text, { bold: true, children: "Sup, what would you like to do on the Superchain today? \u2728" })] }), _jsx(Select, { options: optionsWithLastAction, onChange: value => {
                        if (value === 'continue') {
                            if (lastWizardId === 'deployCreate2') {
                                useDeployCreate2WizardStore
                                    .getState()
                                    .setWizardState(lastWizardState);
                                setSelectedOption('deploy');
                                return;
                            }
                            else if (lastWizardId === 'bridge') {
                                useBridgeWizardStore
                                    .getState()
                                    .setWizardState(lastWizardState);
                                setSelectedOption('bridge');
                                return;
                            }
                        }
                        setSelectedOption(value);
                    } })] }));
    }
    if (selectedOption === 'deploy') {
        return _jsx(DeployCreate2Wizard, { isPrepareMode: options.prepare });
    }
    else if (selectedOption === 'bridge') {
        return _jsx(BridgeWizard, { isPrepareMode: options.prepare });
    }
    return null;
}
