import ComponentLoader from "../ComponentLoader/ComponentLoader";
import ErrorMessage from "../ErrorMessage/ErrorMessage";
import DayUptimeGraph from "../Graphs/DayUptimeGraph";
import UptimeUtil from "./UptimeUtil";
import React, { useEffect, useState, } from "react";
const MonitorUptimeGraph = (props) => {
    var _a;
    const [events, setEvents] = useState([]);
    const [barColorRules, setBarColorRules] = useState([]);
    useEffect(() => {
        const eventList = UptimeUtil.getNonOverlappingMonitorEvents(props.items);
        setEvents(eventList);
    }, [props.items]);
    useEffect(() => {
        if (props.barColorRules) {
            setBarColorRules(props.barColorRules.map((rule) => {
                return {
                    barColor: rule.barColor,
                    uptimePercentGreaterThanOrEqualTo: rule.uptimePercentGreaterThanOrEqualTo,
                };
            }));
        }
    }, [props.barColorRules]);
    if (props.isLoading) {
        return React.createElement(ComponentLoader, null);
    }
    if (props.error) {
        return (React.createElement(ErrorMessage, { message: props.error, onRefreshClick: props.onRefreshClick ? props.onRefreshClick : undefined }));
    }
    return (React.createElement(DayUptimeGraph, { startDate: props.startDate, endDate: props.endDate, events: events, defaultBarColor: props.defaultBarColor, height: props.height, barColorRules: barColorRules, downtimeEventStatusIds: ((_a = props.downtimeMonitorStatuses) === null || _a === void 0 ? void 0 : _a.map((status) => {
            return status.id;
        })) || [], incidents: props.incidents, onBarClick: props.onBarClick, onIncidentClick: props.onIncidentClick }));
};
export default MonitorUptimeGraph;
//# sourceMappingURL=Uptime.js.map