import React, { useMemo } from "react";
import Anchor from "../../../../components/anchor";
import { Text } from "@netdata/netdata-ui";
import { useLocalStorage } from "react-use";
export var MigrationModalPromos;
(function (MigrationModalPromos) {
    MigrationModalPromos["PROMO_SIGN_IN_CLOUD"] = "PROMO_SIGN_IN_CLOUD";
    MigrationModalPromos["PROMO_SIGN_UP_CLOUD"] = "PROMO_SIGN_UP_CLOUD";
    MigrationModalPromos["PROMO_IVNITED_TO_SPACE"] = "PROMO_IVNITED_TO_SPACE";
    MigrationModalPromos["PROMO_CLAIM_NODE"] = "PROMO_CLAIM_NODE";
    MigrationModalPromos["PROMO_TO_USE_NEW_DASHBAORD"] = "PROMO_TO_USE_NEW_DASHBAORD";
    MigrationModalPromos["FALLBACK_TO_AGENT"] = "FALLBACK_TO_AGENT";
    MigrationModalPromos["NO_INFO_FALLBACK_TO_AGENT"] = "NO_INFO_FALLBACK_TO_AGENT";
})(MigrationModalPromos || (MigrationModalPromos = {}));
export const migrationmodalInfo = {
    [MigrationModalPromos.PROMO_SIGN_UP_CLOUD]: {
        title: "Learn about Netdata Cloud!",
        text: {
            header: () => (React.createElement(Text, { strong: true }, "Netdata Cloud is a FREE service that complements the Netdata Agent, to provide:")),
            bullets: [
                "Infrastructure level dashboards (each chart aggregates data from multiple nodes)",
                "Central dispatch of alert notifications",
                "Custom dashboards editor",
                "Intelligence assisted troubleshooting, to help surface the root cause of issues",
            ],
            footer: "Have a look, you will be surprised!",
        },
        tickBoxOption: {
            text: "Remember my choice",
            prefrenceID: MigrationModalPromos.PROMO_SIGN_UP_CLOUD,
        },
        CTA1: {
            text: "Wow! Let’s go to Netdata Cloud",
            toPath: "path/signup/cloud",
            action: "NAVIGATE",
            userPreference: "CLOUD",
        },
        CTA2: {
            text: "Later, stay at the agent dashboard",
            action: "NAVIGATE",
            toPath: "path/agent-dashboard",
            userPreference: "AGENT",
        },
    },
    [MigrationModalPromos.PROMO_SIGN_IN_CLOUD]: {
        title: "Sign-in to Netdata Cloud or get an invitation!",
        text: {
            header: () => (React.createElement(React.Fragment, null,
                React.createElement(Text, { strong: true }, "This node is connected to Netdata Cloud but you are not. If you have a Netdata Cloud account sign-in, if not ask for an invitation to it."),
                React.createElement(Text, null, "Netdata Cloud is a FREE service that complements the Netdata Agent, to provide:"))),
            bullets: [
                "Infrastructure level dashboards (each chart aggregates data from multiple nodes)",
                "Central dispatch of alert notifications",
                "Custom dashboards editor",
                "Intelligence assisted troubleshooting, to help surface the root cause of issues",
            ],
            footer: "Have a look, you will be surprised!",
        },
        tickBoxOption: {
            text: "Remember my choice",
            prefrenceID: MigrationModalPromos.PROMO_SIGN_IN_CLOUD,
        },
        CTA1: {
            text: "Sign-in or get a Netdata Cloud account",
            action: "NAVIGATE",
            toPath: "path/signin/cloud",
            userPreference: "CLOUD",
        },
        CTA2: {
            text: "Later, stay at the Agent dashboard",
            toPath: "path/agent-dashboard",
            action: "NAVIGATE",
            userPreference: "AGENT",
        },
    },
    [MigrationModalPromos.PROMO_IVNITED_TO_SPACE]: {
        title: "Get an invitation to this Node’s Space!",
        text: {
            header: () => (React.createElement(Text, { strong: true }, "This node is connected to Netdata Cloud but it isnt available on one of your Spaces.")),
            bullets: [],
            footer: "Ask for an invitation to this Space!",
        },
        tickBoxOption: {
            text: "Don't remind me of this again",
            prefrenceID: MigrationModalPromos.PROMO_IVNITED_TO_SPACE,
        },
        CTA1: {
            text: "Thanks, go to Agent dashboard for now",
            toPath: "agent",
            action: "NAVIGATE",
            userPreference: "AGENT",
        },
    },
    [MigrationModalPromos.PROMO_CLAIM_NODE]: {
        title: "This node isn’t connected to Netada Cloud",
        text: {
            header: () => (React.createElement(Text, { strong: true }, "For you to be able to see this node on Netdata Cloud you will either need to:")),
            footer: "Have a look, you will be surprised!",
            bullets: [
                () => {
                    return (React.createElement(Text, null,
                        " ",
                        "Connect this node directly ( documentation on",
                        " ",
                        React.createElement(Anchor, { target: "_blank", rel: "noopener noreferrer", href: "https://learn.netdata.cloud/docs/agent/claim#how-to-connect-a-node" }, "how to connect a node"),
                        ") , or"));
                },
                () => {
                    return (React.createElement(Text, null,
                        "\u0391ctivate streaming to a parent node that is already connected (documentation on",
                        " ",
                        React.createElement(Anchor, { target: "_blank", rel: "noopener noreferrer", href: "https://learn.netdata.cloud/docs/agent/claim#how-to-connect-a-node" }, "how to configure streaming"),
                        ")"));
                },
            ],
        },
        tickBoxOption: {
            text: "Remember my choice.",
            prefrenceID: MigrationModalPromos.PROMO_CLAIM_NODE,
        },
        CTA1: {
            text: "Wow! Let’s go to Netdata Cloud",
            action: "NAVIGATE",
            toPath: "path/node/cloud",
            userPreference: "CLOUD",
        },
        CTA2: {
            text: "Later, stay at the Agent dashboard",
            action: "NAVIGATE",
            toPath: "path/agent-dashboard",
            userPreference: "AGENT",
        },
    },
    [MigrationModalPromos.PROMO_TO_USE_NEW_DASHBAORD]: {
        title: "Use the Old or the New dashboard?",
        text: {
            header: () => (React.createElement(Text, { strong: true }, "This node is available in your Netdata Cloud account. So, you have full access to the NEW dashboards, charts, intelligence-assisted troubleshooting and many more!")),
            bullets: [],
        },
        tickBoxOption: {
            text: "Remember my choice",
            prefrenceID: MigrationModalPromos.PROMO_TO_USE_NEW_DASHBAORD,
        },
        CTA1: {
            text: "Wow! Let’s go to Netdata Cloud ",
            action: "NAVIGATE",
            toPath: "path/dashboard/cloud",
            userPreference: "CLOUD",
        },
        CTA2: {
            text: "Later, stay at the Agent dashboard",
            action: "NAVIGATE",
            toPath: "path/agent-dashboard",
            userPreference: "AGENT",
        },
    },
    [MigrationModalPromos.FALLBACK_TO_AGENT]: {
        title: "Oops! This node has lost connection to Netdata Cloud!",
        text: {
            header: ({ date = "" }) => {
                return (React.createElement(React.Fragment, null,
                    React.createElement(Text, { strong: true }, "Unfortunately, it seems that this node is not currently connected to Netdata Cloud. So, the old agent dashboard is the only option available."),
                    React.createElement(Text, null,
                        "To troubleshoot Netdata Cloud connection issues, please follow this",
                        " ",
                        React.createElement(Anchor, { target: "_blank", rel: "noopener noreferrer", href: "https://learn.netdata.cloud/docs/agent/claim#troubleshooting" }, "this guide."))));
            },
            bullets: [],
        },
        tickBoxOption: {
            text: "Don't show this again",
            prefrenceID: MigrationModalPromos.FALLBACK_TO_AGENT,
        },
        CTA1: {
            text: "Check again please",
            action: "REFRESH",
            userPreference: undefined,
        },
        CTA2: {
            text: "Thanks, go to Agent dashboard",
            toPath: "path/agent",
            action: "NAVIGATE",
            userPreference: "AGENT",
        },
    },
    [MigrationModalPromos.NO_INFO_FALLBACK_TO_AGENT]: {
        title: "Oops! We aren't able to get information of this node in regards to Netdata Cloud!",
        text: {
            header: () => {
                return (React.createElement(React.Fragment, null,
                    React.createElement(Text, { strong: true }, "Unfortunately, it seems we aren't able to get information on this node in regards to Netdata Cloud."),
                    React.createElement(Text, null, "This could be from internet connectivity issues from your end or some temporary issue with our services. So, the old agent dashboard is the only option available.")));
            },
            bullets: [],
        },
        tickBoxOption: {
            text: "Don't show this again",
            prefrenceID: MigrationModalPromos.NO_INFO_FALLBACK_TO_AGENT,
        },
        CTA1: {
            text: "Check again please",
            action: "REFRESH",
            userPreference: undefined,
        },
        CTA2: {
            text: "Thanks, go to Agent dashboard",
            toPath: "path/agent-dashboard",
            action: "NAVIGATE",
            userPreference: "AGENT",
        },
    },
};
const isPromoSignUp = ({ userSavedPreference, userStatus, nodeClaimedStatus, }) => userSavedPreference !== "AGENT" && userStatus === "UNKNOWN" && nodeClaimedStatus === "NOT_CLAIMED";
const isPromoSignIn = ({ userSavedPreference, userStatus, nodeClaimedStatus, }) => userSavedPreference !== "AGENT" && userStatus === "UNKNOWN" && nodeClaimedStatus === "CLAIMED";
const isPromoInvitedToSpace = ({ userSavedPreference, userStatus, nodeClaimedStatus, userNodeAccess, }) => userSavedPreference !== "AGENT" &&
    (userStatus === "LOGGED_IN" || userStatus === "EXPIRED_LOGIN") &&
    nodeClaimedStatus === "CLAIMED" &&
    userNodeAccess === "NO_ACCESS";
const isPromoToClaimThisNode = ({ userSavedPreference, userStatus, nodeClaimedStatus, }) => userSavedPreference !== "AGENT" &&
    (userStatus === "LOGGED_IN" || userStatus === "EXPIRED_LOGIN") &&
    nodeClaimedStatus === "NOT_CLAIMED";
const isPromoToNewDasboardOnCloud = ({ userSavedPreference, userStatus, nodeLiveness, userNodeAccess, }) => !userSavedPreference &&
    (userStatus === "LOGGED_IN" || userStatus === "EXPIRED_LOGIN") &&
    nodeLiveness === "LIVE" &&
    userNodeAccess === "ACCESS_OK";
const isNoInfoFallbackToAgent = ({ userSavedPreference, userStatus, nodeClaimedStatus, nodeLiveness, userNodeAccess, }) => userSavedPreference === "CLOUD" &&
    !userStatus &&
    !nodeClaimedStatus &&
    !nodeLiveness &&
    !userNodeAccess;
const isFallbackToAgent = ({ userSavedPreference, userStatus, nodeClaimedStatus, nodeLiveness, userNodeAccess, }) => userSavedPreference !== "AGENT" &&
    (userStatus === "LOGGED_IN" || userStatus === "EXPIRED_LOGIN") &&
    nodeClaimedStatus === "CLAIMED" &&
    nodeLiveness === "NOT_LIVE" &&
    userNodeAccess === "ACCESS_OK";
export const goToAgentDashboard = ({ userSavedPreference }) => userSavedPreference === "AGENT";
export const goToCloud = ({ userSavedPreference, userStatus, nodeLiveness, userNodeAccess, }) => userSavedPreference === "CLOUD" &&
    (userStatus === "LOGGED_IN" || userStatus === "EXPIRED_LOGIN") &&
    nodeLiveness === "LIVE" &&
    userNodeAccess === "ACCESS_OK";
const modalStatusWithPromoFunctions = {
    [MigrationModalPromos.FALLBACK_TO_AGENT]: isFallbackToAgent,
    [MigrationModalPromos.NO_INFO_FALLBACK_TO_AGENT]: isNoInfoFallbackToAgent,
    [MigrationModalPromos.PROMO_TO_USE_NEW_DASHBAORD]: isPromoToNewDasboardOnCloud,
    [MigrationModalPromos.PROMO_CLAIM_NODE]: isPromoToClaimThisNode,
    [MigrationModalPromos.PROMO_IVNITED_TO_SPACE]: isPromoInvitedToSpace,
    [MigrationModalPromos.PROMO_SIGN_IN_CLOUD]: isPromoSignIn,
    [MigrationModalPromos.PROMO_SIGN_UP_CLOUD]: isPromoSignUp,
};
const useMigrationModal = ({ userStatus, nodeClaimedStatus, userNodeAccess, nodeLiveness, }) => {
    const [userSavedPreference, setUserPrefrence] = useLocalStorage("USER_SAVED_PREFERENCE");
    const migrationModalPromo = useMemo(() => {
        return Object.keys(modalStatusWithPromoFunctions).find(modalStatus => {
            return modalStatusWithPromoFunctions[modalStatus]({
                userStatus,
                nodeClaimedStatus,
                userNodeAccess,
                userSavedPreference,
                nodeLiveness,
            });
        });
    }, [userStatus, nodeClaimedStatus, userNodeAccess, nodeLiveness, userSavedPreference]);
    return {
        migrationModalPromoInfo: migrationmodalInfo[migrationModalPromo],
        migrationModalPromo,
        setUserPrefrence,
        userSavedPreference,
    };
};
export default useMigrationModal;
//# sourceMappingURL=use-migration-modal.js.map