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: [_jsxs(Box, { children: [_jsx(Text, { children: "Enter the path to your " }), _jsx(Text, { color: "cyan", bold: true, children: "Foundry" }), _jsx(Text, { children: " project " }), _jsx(Text, { children: "(press " }), _jsx(Text, { bold: true, children: "Tab" }), _jsx(Text, { children: " for autocomplete, " }), _jsx(Text, { bold: true, children: "Ctrl+U" }), _jsx(Text, { children: " to clear, default: " }), _jsx(Text, { color: "green", bold: true, children: "." }), _jsx(Text, { children: ")" }), _jsx(Text, { children: ":" })] }), _jsx(PathInput, { defaultValue: userContext.forgeProjectPath ?? '', onSubmit: foundryProjectPath => {
                    const projectPath = foundryProjectPath.trim();
                    if (projectPath !== '') {
                        updateUserContext({
                            forgeProjectPath: projectPath,
                        });
                    }
                    submitEnterFoundryProjectPath({
                        foundryProjectPath: projectPath === '' ? '.' : projectPath,
                    });
                } })] }));
};
