export function getHeadGainSightScript(domain: string | undefined) {
    const getGainSightKey = () => {
        let gainsightKey = "AP-BRSDBWJG4SFJ-2";

        if (!domain) {
            return gainsightKey;
        }

        if (
            domain.includes("localhost") ||
            domain.includes("commerce.local.com") ||
            domain.includes(".insitesoftqa.com")
        ) {
            // QA environment in gainsight
            gainsightKey = "AP-BRSDBWJG4SFJ-2-3";
        } else if (domain.includes("insitesandbox.com") || domain.includes("insitetestbox.com")) {
            // STAGING environment in gainsight
            gainsightKey = "AP-BRSDBWJG4SFJ-2-2";
        }

        return gainsightKey;
    };

    return `
    (function(n,t,a,e,co){var i="aptrinsic";n[i]=n[i]||function(){
        (n[i].q=n[i].q||[]).push(arguments)},n[i].p=e;n[i].c=co;
        var r=t.createElement("script");r.async=!0,r.src=a+"?a="+e;
        var c=t.getElementsByTagName("script")[0];c.parentNode.insertBefore(r,c)
    })(window,document,"https://web-sdk-eu.aptrinsic.com/api/aptrinsic.js", '${getGainSightKey()}');
    `;
}
