import { jsx as _jsx } from "react/jsx-runtime";
/**
 * @copyright Sister Software
 * @license AGPL-3.0
 * @author Teffen Ellis, et al.
 */
import { Spinner } from "@inkjs/ui";
import { Text } from "ink";
import { createAddressParser, createDiagnosticReport } from "mailwoman";
import { useEffect, useState } from "react";
import zod from "zod";
const ArgumentsSchema = zod.array(zod.string().describe("A formatted postal address"));
export { ArgumentsSchema as args, ParseConfigSchema as options };
const ParseConfigSchema = zod.object({
    debug: zod.boolean().optional().default(false).describe("Enable verbose debugging output"),
});
const ParseCommand = ({ options, args }) => {
    const [output, setOutput] = useState();
    const [error, setError] = useState();
    useEffect(() => {
        const parser = createAddressParser();
        const input = args[0];
        if (options.debug) {
            parser
                .parse(input, { verbose: true })
                .then(createDiagnosticReport)
                .then(setOutput)
                .catch((err) => setError(err.message));
        }
        else {
            parser
                .parse(input)
                .then((results) => setOutput(JSON.stringify(results, null, 2)))
                .catch((err) => setError(err.message));
        }
    }, [args, options.debug]);
    if (error) {
        return _jsx(Text, { color: "red", children: error });
    }
    if (!output) {
        return _jsx(Spinner, {});
    }
    return _jsx(Text, { children: output });
};
export default ParseCommand;
//# sourceMappingURL=parse.js.map