using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DrawAbilityDescription : MonoBehaviour
{
    public Controller controller;
    public string text;

    public Text textCost01, textCost02, textCost03, textCost04,
                textCost05, textCost06, textCost07, textCost08;

    public Image spriteOn, spriteOff;


    void Awake() 
    {   

        DrawInfo(false);
        
        if (gameObject.name == "HotBar")
        {
            ChangeCost(controller.costAbilities,"Ability01",controller.costAbilities["Ability01"],textCost01);
            ChangeCost(controller.costAbilities,"Ability02",controller.costAbilities["Ability02"],textCost02);
            ChangeCost(controller.costAbilities,"Ability03",controller.costAbilities["Ability03"],textCost03);
            ChangeCost(controller.costAbilities,"Ability04",controller.costAbilities["Ability04"],textCost04);
            ChangeCost(controller.costAbilities,"Ability05",controller.costAbilities["Ability05"],textCost05);
            ChangeCost(controller.costAbilities,"Ability06",controller.costAbilities["Ability06"],textCost06);
            ChangeCost(controller.costAbilities,"Scan",controller.costAbilities["Scan"],textCost07);
        }
        else
        {
            ChangeCost(controller.costUpAbility,"Ability01",controller.costUpAbility["Ability01"],textCost01);
            ChangeCost(controller.costUpAbility,"Ability02",controller.costUpAbility["Ability02"],textCost02);
            ChangeCost(controller.costUpAbility,"Ability03",controller.costUpAbility["Ability03"],textCost03);
            ChangeCost(controller.costUpAbility,"Ability04",controller.costUpAbility["Ability04"],textCost04);
            ChangeCost(controller.costUpAbility,"Ability05",controller.costUpAbility["Ability05"],textCost05);
            ChangeCost(controller.costUpAbility,"Ability06",controller.costUpAbility["Ability06"],textCost06);
            ChangeCost(controller.costUpAbility,"Scan",controller.costUpAbility["Scan"],textCost07);
            ChangeCost(controller.costUpAbility,"Income",controller.costUpAbility["Income"],textCost08);               
            }
    }
    public void ChangeCost(Dictionary<string,float> dic, string keyDic, float value, Text text)
    {
        dic[keyDic] = (int)Mathf.Round(value);
        text.text = dic[keyDic].ToString();
    }

    public void DrawInfo(bool active, GameObject obj = null)
    {
        controller.textDescription.enabled = active;
        controller.imageDescription.enabled = active;
        
        if (obj != null)
        {
            string descriptionFull;

            if (gameObject.name == "HotBar")
            {
                //если абилка прокачана
                if (obj.GetComponent<SetVarToDrawDescription>().status == true)
                {
                    descriptionFull = string.Format(controller.descriptionOfAbilities[obj.name],controller.impactAbility[obj.name],controller.impactAbility["Ability01"]);

                    if (obj.name != "Development")
                    {text = $"<color=#75FF33>{controller.nameOfAbilities[obj.name] }</color> <color=yellow>( {(controller.costAbilities[obj.name].ToString())} игдкоинс )</color>\n{descriptionFull}";}
                    else
                    {text = $"<color=#75FF33>{controller.nameOfAbilities[obj.name] }</color>\n{descriptionFull}";}
                }
                // если абилка НЕ прокачана
                else
                {
                    descriptionFull = string.Format(controller.descriptionCloseAbility[obj.name],controller.impactAbility[obj.name]);
                    text = $"{descriptionFull}";
                }
            }
            else
            {
                if (obj.GetComponent<SetVarToDrawDescription>().sameButton.GetComponent<SetVarToDrawDescription>().status == true)
                {
                    descriptionFull = string.Format(controller.descriptionOfUpAbilities[obj.name], float.Parse((controller.impactAbility[obj.name] * controller.qImpact[obj.name]).ToString("f2")), controller.impactAbility["Ability01"]);

                    if (obj.name != "Cancel")
                    {text = $"<color=#75FF33>{controller.nameOfUpAbilities[obj.name] }</color> <color=yellow>( {(controller.costUpAbility[obj.name].ToString())} игдкоинс )</color>\n{descriptionFull}";}
                    else
                    {text = $"<color=#75FF33>{controller.nameOfUpAbilities[obj.name] }</color>\n{descriptionFull}";}
                }
                // если абилка НЕ прокачана
                else
                {
                    descriptionFull = string.Format(controller.descriptionCloseUpAbility[obj.name],controller.impactAbility[obj.name], controller.impactAbility["Ability01"]);
                    text = $"{descriptionFull}";
                }
            }
        }
    }

    void OnGUI() 
    {
        controller.textDescription.text = text;
    }
}
