import API from "../../Utils/API/API";
import ModelAPI from "../../Utils/ModelAPI/ModelAPI";
import Card from "../Card/Card";
import ComponentLoader from "../ComponentLoader/ComponentLoader";
import ErrorMessage from "../ErrorMessage/ErrorMessage";
import ProgressBar from "../ProgressBar/ProgressBar";
import React, { useEffect, useState } from "react";
const ModelProgress = (props) => {
    const [isLoading, setIsLoading] = useState(true);
    const [error, setError] = useState("");
    const [count, setCount] = useState(0);
    const fetchCount = async () => {
        setError("");
        setIsLoading(true);
        try {
            const count = await ModelAPI.count({
                modelType: props.modelType,
                query: props.countQuery,
            });
            setCount(count);
        }
        catch (err) {
            setError(API.getFriendlyMessage(err));
        }
        setIsLoading(false);
    };
    useEffect(() => {
        fetchCount().catch((err) => {
            setError(API.getFriendlyMessage(err));
        });
    }, []);
    return (React.createElement(Card, { title: props.title, description: props.description },
        React.createElement("div", { className: "w-full -mt-6" },
            !error && (React.createElement("div", null,
                React.createElement(ErrorMessage, { message: error }))),
            isLoading && React.createElement(ComponentLoader, null),
            !error && !isLoading && (React.createElement(ProgressBar, { totalCount: props.totalCount, count: count, suffix: props.title })))));
};
export default ModelProgress;
//# sourceMappingURL=ModelProgress.js.map