import React, { useState, useCallback } from "react";
import useCloudConnectionStatus from "./use-cloud-connection-status";
import CloudConnectionStatusModal from "./cloud-connection-status-modal";
import { Pill, Flex } from "@netdata/netdata-ui";
import { useSelector } from "react-redux";
import { useRequestRefreshOfAccessMessage } from "../../../hooks/use-user-node-access";
import { selectUserNodeAccess } from "../../../domains/global/selectors";
import { selectIsCloudEnabled } from "../../../domains/global/selectors";
const CloudConnectionStatus = () => {
    var _a, _b, _c;
    const userNodeAccess = useSelector(selectUserNodeAccess);
    const cloudEnabled = useSelector(selectIsCloudEnabled);
    const [isModalOpen, setModalOpen] = useState(false);
    const cloudConnectionStatusInfo = useCloudConnectionStatus({
        userStatus: ((_a = userNodeAccess) === null || _a === void 0 ? void 0 : _a.userStatus) || "UNKNOWN",
        nodeStatus: ((_b = userNodeAccess) === null || _b === void 0 ? void 0 : _b.nodeLiveness) || "NOT_LIVE",
        date: "",
    });
    const openModal = useCallback(() => {
        setModalOpen(true);
    }, []);
    const closeModal = useCallback(() => {
        setModalOpen(false);
    }, []);
    const onRefresh = useRequestRefreshOfAccessMessage();
    if (!cloudEnabled)
        return null;
    return (React.createElement(Flex, { column: true },
        React.createElement(Pill, { "data-ga": `connection-to-cloud::click-pill::ad`, "data-testid": "header-connection-to-cloud-button", onClick: openModal, flavour: "neutral" }, "Connection to Cloud"),
        isModalOpen && (React.createElement(CloudConnectionStatusModal, Object.assign({}, cloudConnectionStatusInfo, { isCTA1Disabled: ((_c = userNodeAccess) === null || _c === void 0 ? void 0 : _c.nodeLiveness) !== "LIVE", closeModal: closeModal, onRefresh: onRefresh })))));
};
export default CloudConnectionStatus;
//# sourceMappingURL=cloud-connection-status.js.map