import { useEffect, useState } from "react"
import { invokeWebApiWrapperAsync } from "../../../components/factory"
import LoaderPortal from "../../../components/LoaderPortal";
import { WellOperationStatService } from "../../../services/api";
import ClusterWells from "../../Cluster/ClusterWells";

export const WellCompositeInfo = ({idWell, selectedIdWells}) => {
    const [showLoader, setShowLoader] = useState(false);
    const [statsWells, setStatsWells] = useState([]);

    useEffect(() => invokeWebApiWrapperAsync(
        async () => {
            const operations = await WellOperationStatService.getWellsStat(selectedIdWells)
            setStatsWells(operations)
        },
        setShowLoader,
        'Не удалось загрузить список операции по скважинам'
    ), [selectedIdWells])

    return (
        <LoaderPortal show={showLoader}>
            <ClusterWells statsWells={statsWells}/>
        </LoaderPortal>
    )
}
