﻿#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")]
    public IEnumerator I2LocTest_CallbacksAndParameters()
    {
        SceneManager.LoadScene("I2Localization    features Callbacks and Parameters");
        yield return null;

        var pText = I2Utils.FindObject( "Canvas/Localized Examples/Text").GetComponent<Text>();
        var pTextCallback = I2Utils.FindObject( "Canvas/Localized Examples/Text with Callback").GetComponent<Text>();
        var pTextLocalParmas = I2Utils.FindObject( "Canvas/Localized Examples/Text with Local Parameters").GetComponent<Text>();
        var pTextGlobalParams = I2Utils.FindObject( "Canvas/Localized Examples/Text with Globall Parameters").GetComponent<Text>();


        I2Utils.FindObject( "Canvas/Buttons/Spanish").GetComponent<SetLanguage>().ApplyLanguage();
        yield return null;

        Assert.IsTrue(pText.text == "Se trata de un texto Unidad de interfaz de usuario localizada");
        Assert.IsTrue(pTextCallback.text == "El ganador es el jugador Rojo");
        Assert.IsTrue(pTextLocalParmas.text == "Frank es el primero de los 3 jugadores.");
        Assert.IsTrue(pTextGlobalParams.text == "Javier es el primero de los 5 jugadores.");

        I2Utils.FindObject( "Canvas/Buttons/English").GetComponent<SetLanguage>().ApplyLanguage();
        yield return null;

        Assert.IsTrue(pText.text == "This is a localized Unity UI Text");
        Assert.IsTrue(pTextCallback.text == "The winner is the Red player");
        Assert.IsTrue(pTextLocalParmas.text == "Frank is the first of 3 players.");
        Assert.IsTrue(pTextGlobalParams.text == "Javier is the first of 5 players.");

        I2Utils.FindObject( "Canvas/Buttons/French").GetComponent<SetLanguage>().ApplyLanguage();
        yield return null;

        Assert.IsTrue(pText.text == "Ceci est une unité localisée UI texte");
        Assert.IsTrue(pTextCallback.text == "Le gagnant est le joueur Rouge");
        Assert.IsTrue(pTextLocalParmas.text == "Frank est la première de 3 joueurs.");
        Assert.IsTrue(pTextGlobalParams.text == "Javier est la première de 5 joueurs.");

        var translation = "This <tag1=test>is{[Param1]}{[Parame2]} {[Paramet3]} [tag]{[Paramet3]} {[Paramete4]}[/tag]</tag1>{[Parameter5]}";
        LocalizationManager.ApplyLocalizationParams(ref translation, (p) => ("value"+p.Length), true);
        Assert.IsTrue(translation== "This <tag1=test>isvalue6value7 value8 [tag]value8 value9[/tag]</tag1>value10");
    }

    [TearDown]
    public void CleanUp()
    {    
        TestLogger.Disable();
    }
}

#endif