import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useDeployCreate2WizardStore } from './deployCreate2WizardStore.js';
import { Box, Text } from 'ink';
import { Spinner } from '@inkjs/ui';
import { useUpdateUserContext, useUserContext } from '../queries/userContext.js';
import { PathInput } from '../components/path-input/PathInput.js';
export const EnterFoundryProjectPath = () => {
    const { wizardState, submitEnterFoundryProjectPath } = useDeployCreate2WizardStore();
    const { data: userContext, isLoading: isUserContextLoading } = useUserContext();
    const { mutate: updateUserContext } = useUpdateUserContext();
    if (wizardState.stepId !== 'enter-foundry-project-path') {
        throw new Error('Invalid state');
    }
    if (isUserContextLoading || !userContext) {
        return _jsx(Spinner, {});
    }
    return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { children: _jsx(Text, { children: "Enter the path to your foundry project (default: \".\"):" }) }), _jsx(PathInput, { defaultValue: userContext.forgeProjectPath ?? '', onSubmit: foundryProjectPath => {
                    const projectPath = foundryProjectPath.trim();
                    if (projectPath !== '') {
                        updateUserContext({
                            forgeProjectPath: projectPath,
                        });
                    }
                    submitEnterFoundryProjectPath({
                        foundryProjectPath: projectPath === '' ? '.' : projectPath,
                    });
                } })] }));
};
