﻿#if !NETFX_CORE
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using UnityEngine.SceneManagement;
using I2.Loc;
using UnityEngine.UI;
using System;
#pragma warning disable 618


public partial class I2Loc_PlayTest_Features
{
    [UnityTest, Category("Features"), Description("Support for several Localize components in the same GameObject")]
    public IEnumerator I2LocTest_MultipleLocalizeTarget()
    {
        SceneManager.LoadScene("I2LocTest Multiple Localize In GameObject");
        yield return null;

        var go1_target1 = I2Utils.FindObject("Canvas/Localized Examples/Text").GetComponent<Text>();
        var go1_target2 = I2Utils.FindObject("Canvas/Localized Examples/Text").GetComponent<TextMesh>();
        var go2_target1 = I2Utils.FindObject("Canvas/Localized Examples/Text").GetComponent<Text>();
        var go2_target2chil0 = I2Utils.FindObject("Canvas/Localized Examples/Text1/Capsule");
        var go2_target2chil1 = I2Utils.FindObject("Canvas/Localized Examples/Text1/Cube");
        var go2_target2chil2 = I2Utils.FindObject("Canvas/Localized Examples/Text1/Cylinder");

        var onlySecondaryTerm = I2Utils.FindObject("Canvas/Localized Examples/OnlySecondaryTerm").GetComponent<Text>();

        var prefab = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>("Test_MultipleLoc"), I2Utils.FindObject("Canvas/Localized Examples"));
        var go3_target1 = prefab.GetComponent<Text>();
        var go3_target2 = prefab.GetComponent<TextMesh>();

 
        #region Test

        I2Utils.FindObject("Canvas/Buttons/French").GetComponent<Button>().onClick.Invoke();
        yield return null;
        Assert.IsTrue(go1_target1.text == "Il s'agit d'un texte localise Unity UI");
        Assert.IsTrue(go1_target2.text == "Un Choix");
        Assert.IsTrue(go2_target1.text == "Il s'agit d'un texte localise Unity UI");
        Assert.IsTrue(!go2_target2chil0.gameObject.activeInHierarchy);
        Assert.IsTrue(!go2_target2chil1.gameObject.activeInHierarchy);
        Assert.IsTrue(go2_target2chil2.gameObject.activeInHierarchy);
        Assert.IsTrue(go3_target1.text == "Il s'agit d'un texte localise Unity UI");
        Assert.IsTrue(go3_target2.text == "Un Choix");
        Assert.IsTrue(!string.IsNullOrEmpty(onlySecondaryTerm.text));
        Assert.IsTrue(onlySecondaryTerm.font.name == "Arial");


        I2Utils.FindObject("Canvas/Buttons/Spanish").GetComponent<Button>().onClick.Invoke();
        yield return null;
        Assert.IsTrue(go1_target1.text == "Este es un Texto del Unity UI");
        Assert.IsTrue(go1_target2.text == "Opción A");
        Assert.IsTrue(go2_target1.text == "Este es un Texto del Unity UI");
        Assert.IsTrue( go2_target2chil0.gameObject.activeInHierarchy);
        Assert.IsTrue(!go2_target2chil1.gameObject.activeInHierarchy);
        Assert.IsTrue(!go2_target2chil2.gameObject.activeInHierarchy);
        Assert.IsTrue(go3_target1.text == "Este es un Texto del Unity UI");
        Assert.IsTrue(go3_target2.text == "Opción A");
        Assert.IsTrue(!string.IsNullOrEmpty(onlySecondaryTerm.text));
        Assert.IsTrue(onlySecondaryTerm.font.name == "COMIC");

        I2Utils.FindObject("Canvas/Buttons/English").GetComponent<Button>().onClick.Invoke();
        yield return null;
        Assert.IsTrue(go1_target1.text == "This is a localized Unity UI Text");
        Assert.IsTrue(go1_target2.text == "Option A");
        Assert.IsTrue(go2_target1.text == "This is a localized Unity UI Text");
        Assert.IsTrue(!go2_target2chil0.gameObject.activeInHierarchy);
        Assert.IsTrue( go2_target2chil1.gameObject.activeInHierarchy);
        Assert.IsTrue(!go2_target2chil2.gameObject.activeInHierarchy);
        Assert.IsTrue(go3_target1.text == "This is a localized Unity UI Text");
        Assert.IsTrue(go3_target2.text == "Option A");
        Assert.IsTrue(!string.IsNullOrEmpty(onlySecondaryTerm.text));
        Assert.IsTrue(onlySecondaryTerm.font.name == "Arial");

        #endregion


    }
}

#endif