import React, { useState, useEffect } from "react";
import { render, Text, Box } from "ink";
import Spinner from "ink-spinner";
import * as fs from "fs";
import * as path from "path";
import { parseConfig } from "@specific/config";
function CheckUI() {
    const [state, setState] = useState({ status: "loading" });
    useEffect(() => {
        async function load() {
            const configPath = path.join(process.cwd(), "specific.hcl");
            if (!fs.existsSync(configPath)) {
                setState({
                    status: "error",
                    error: "No specific.hcl found in current directory",
                });
                return;
            }
            try {
                const hcl = fs.readFileSync(configPath, "utf-8");
                const config = await parseConfig(hcl);
                setState({ status: "success", config });
            }
            catch (err) {
                setState({
                    status: "error",
                    error: err instanceof Error ? err.message : String(err),
                });
            }
        }
        load();
    }, []);
    if (state.status === "loading") {
        return (React.createElement(Box, null,
            React.createElement(Text, { color: "blue" },
                React.createElement(Spinner, { type: "dots" })),
            React.createElement(Text, null, " Checking configuration...")));
    }
    if (state.status === "error") {
        return (React.createElement(Box, { flexDirection: "column" },
            React.createElement(Text, { color: "red" },
                "Error: ",
                state.error)));
    }
    const { config } = state;
    if (!config) {
        return null;
    }
    return (React.createElement(Box, { flexDirection: "column", gap: 1 },
        React.createElement(Text, { color: "green" }, "Configuration is valid"),
        config.builds.length > 0 && (React.createElement(Box, { flexDirection: "column" },
            React.createElement(Text, { bold: true },
                "Builds (",
                config.builds.length,
                "):"),
            config.builds.map((b) => (React.createElement(Text, { key: b.name },
                "  ",
                "- ",
                b.name))))),
        config.services.length > 0 && (React.createElement(Box, { flexDirection: "column" },
            React.createElement(Text, { bold: true },
                "Services (",
                config.services.length,
                "):"),
            config.services.map((s) => (React.createElement(Text, { key: s.name },
                "  ",
                "- ",
                s.name))))),
        config.databases.length > 0 && (React.createElement(Box, { flexDirection: "column" },
            React.createElement(Text, { bold: true },
                "Databases (",
                config.databases.length,
                "):"),
            config.databases.map((d) => (React.createElement(Text, { key: d.name },
                "  ",
                "- ",
                d.name,
                " (",
                d.engine,
                ")"))))),
        config.configs.length > 0 && (React.createElement(Box, { flexDirection: "column" },
            React.createElement(Text, { bold: true },
                "Config (",
                config.configs.length,
                "):"),
            config.configs.map((c) => (React.createElement(Text, { key: c.name },
                "  ",
                "- ",
                c.name,
                c.default ? ` (default: ${c.default})` : ""))))),
        config.environments.length > 0 && (React.createElement(Box, { flexDirection: "column" },
            React.createElement(Text, { bold: true },
                "Environments (",
                config.environments.length,
                "):"),
            config.environments.map((e) => (React.createElement(Text, { key: e.name },
                "  ",
                "- ",
                e.name)))))));
}
export function checkCommand() {
    render(React.createElement(CheckUI, null));
}
//# sourceMappingURL=check.js.map