﻿using UnityEngine;

public class BrandingScript : MonoBehaviour
{
    public void Start()
    {
#if !UNITY_EDITOR && UNITY_WEBGL
        Idnet.I.Protection(protectionException =>
        {
            if (protectionException == null)
            {
                Idnet.I.Log("IsSponsered " + Idnet.I.IsSponsor);
                Idnet.I.Log("isBlacklisted " + Idnet.I.IsBlacklisted);
                Idnet.I.GetExclusiveStatus((isDistributionBlocked, exception) =>
                {
                    if(isDistributionBlocked && !Idnet.I.IsSponsor)
                        Idnet.I.EnableExclusiveMenu();
                });
            }
        });
#else
        Idnet.I.IsLogoClickable = true;
        Idnet.I.IsSponsor = false;
        Idnet.I.RefererDomain = Idnet.I.DomainName = "unity_editor";
#endif
    }


    public static void ClickedPreLoader()
    {
        if (Idnet.I.IsSponsor) return;
        Application.OpenURL("http://www.y8.com/?utm_source=" + Idnet.I.DomainName +
                            "&utm_medium=g_prelogo&utm_campaign=" + GetGameSlug(Idnet.I.GameName));
    }

    /// <summary>
    ///     Method must be called on OnMouseDown,and never be used in OnMouseUp.
    /// </summary>
    public static void ClickedPreLoader_NewTab()
    {
        if (Idnet.I.IsSponsor) return;
        var url = "http://www.y8.com/?utm_source=" + Idnet.I.DomainName + "&utm_medium=g_prelogo&utm_campaign=" +
                  GetGameSlug(Idnet.I.GameName);
#if UNITY_EDITOR || UNITY_WEBPLAYER
        Application.OpenURL(url);
#else
		Idnet.I.OpenLink(url);
#endif
    }

    public static void ClickedMoreGames()
    {
        if (Idnet.I.IsSponsor) return;
        Application.OpenURL("http://www.y8.com/?utm_source=" + Idnet.I.DomainName +
                            "&utm_medium=g_moregames&utm_campaign=" + GetGameSlug(Idnet.I.GameName));
    }

    /// <summary>
    ///     Method must be called on OnMouseDown,and never be used in OnMouseUp.
    /// </summary>
    public static void ClickedMoreGames_NewTab()
    {
        if (Idnet.I.IsSponsor) return;
        var url = "http://www.y8.com/?utm_source=" + Idnet.I.DomainName + "&utm_medium=g_moregames&utm_campaign=" +
                  GetGameSlug(Idnet.I.GameName);
#if UNITY_EDITOR || UNITY_WEBPLAYER
        Application.OpenURL(url);
#else
		Idnet.I.OpenLink(url);
		#endif
    }

    public static void ClickedLogo()
    {
        if (Idnet.I.IsSponsor) return;
        Application.OpenURL("http://www.y8.com/?utm_source=" + Idnet.I.DomainName +
                            "&utm_medium=g_menulogo&utm_campaign=" + GetGameSlug(Idnet.I.GameName));
    }

    /// <summary>
    ///     Method must be called on OnMouseDown,and never be used in OnMouseUp.
    /// </summary>
    public static void ClickedLogo_NewTab()
    {
        if (Idnet.I.IsSponsor) return;
        var url = "http://www.y8.com/?utm_source=" + Idnet.I.DomainName + "&utm_medium=g_menulogo&utm_campaign=" +
                  GetGameSlug(Idnet.I.GameName);
#if UNITY_EDITOR || UNITY_WEBPLAYER
        Application.OpenURL(url);
#else
		Idnet.I.OpenLink(url);
		#endif
    }

    public static void IdnetLink()
    {
        Application.OpenURL("http://www.id.net");
    }

    //Method must be called on OnMouseDown,and never be used in OnMouseUp.
    public static void Y8Account_NewTab()
    {
		var url = "https://account.y8.com";
#if UNITY_EDITOR || UNITY_WEBPLAYER
        Application.OpenURL(url);
#else
		Idnet.I.OpenLink(url);
		#endif
    }

	//Method must be called on OnMouseDown,and never be used in OnMouseUp.
	public static void IdnetLink_NewTab()
	{
		var url = "http://www.id.net";
		#if UNITY_EDITOR || UNITY_WEBPLAYER
		Application.OpenURL(url);
		#else
		Idnet.I.OpenLink(url);
		#endif
	}

    private static string GetGameSlug(string gameName)
    {
        var lowercase = gameName.ToLower();
        return lowercase.Replace(" ", "_");
    }
}