import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useFoundryProjectSolidityFiles } from '../queries/listFoundryProjectSolidityFiles.js';
import { useDeployCreate2WizardStore } from './deployCreate2WizardStore.js';
import { Select, Spinner } from '@inkjs/ui';
import { Box, Text } from 'ink';
export const SelectContract = () => {
    const { wizardState, submitSelectContract } = useDeployCreate2WizardStore();
    if (wizardState.stepId !== 'select-contract') {
        throw new Error('Invalid state');
    }
    const { data: contractFileNames, isLoading, error, } = useFoundryProjectSolidityFiles(wizardState.foundryProjectPath);
    if (isLoading) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(Spinner, { label: "Loading contracts..." }) }));
    }
    if (error || !contractFileNames) {
        return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "red", children: "\u274C Failed to load contracts" }), error && _jsx(Text, { children: error.toString() })] }));
    }
    if (contractFileNames.length === 0) {
        return (_jsx(Box, { flexDirection: "column", children: _jsx(Text, { color: "yellow", children: "\u26A0\uFE0F No contracts found in project" }) }));
    }
    return (_jsxs(Box, { flexDirection: "column", gap: 1, paddingX: 1, children: [_jsx(Text, { children: "Select which contract you want to deploy" }), _jsx(Select, { options: contractFileNames.map(contractFileName => ({
                    label: contractFileName,
                    value: contractFileName,
                })), onChange: value => submitSelectContract({ selectedContract: value }) })] }));
};
