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

public class colorItem : MonoBehaviour
{
    [SerializeField]
    private bool isSelect = false;
    [SerializeField]
    private float nowProgress = 0;
    [SerializeField]
    private string idName = "";
    [SerializeField]
    private Color useColor = new Color();
    public int index = 0;
    public float selectLang = 0.05f;
    private gameGroupEffect effectImg = null;
    private Vector3 normalScale = Vector3.one;
    void initMember()
    {
        if(effectImg == null)
        {
            effectImg = transform.Find("circle").GetComponent<gameGroupEffect>();
            normalScale = transform.localScale;
        }
    }
    public bool IsSelect
    {
        set {
            initMember();
            isSelect = value;
            
            effectImg.LangValue = isSelect ? selectLang : 0;
            effectImg.pause = !isSelect;
            //transform.Find("finish").gameObject.SetActive(!value);
            //transform.Find("minBar").gameObject.SetActive(value);
            transform.Find("nowSelectFlg").gameObject.SetActive(isSelect);
            
        }
        get
        {
            return isSelect;
        }
    }
    public void switchPlayAnimation()
    {
        if (transform == null) return;
        if(isSelect)
        {
            transform.localScale = normalScale;
            ActionManages.addMoveByScale(gameObject, normalScale * 1.2f, 0.25f);
        }
        else
        {
            transform.localScale = normalScale * 1.2f;
            ActionManages.addMoveByScale(gameObject, normalScale, 0.25f);
        }
    }
    public float NowProgress
    {
        set {
            initMember();
            if (value <= 0) 
                value = 0f; 
            else if (value >= 0.99999998) 
                value = 1.0f;
            if (utilsTools.isEqualByValue(value, 1, 0.000001f))
            {
                value = 1.0f;
            }
            nowProgress = value;
            bool isend = this.isFinish();
            effectImg.Height = 1.0f - nowProgress;
            transform.Find("idname").gameObject.SetActive(!isend);
            if (isend)
            {
                effectImg.gameObject.SetActive(false);
            }
            else
            {
            }
        }
        get
        {
            return nowProgress;
        }
    }
    public string IdName
    {
        set { 
            idName = value;

            transform.Find("idname").GetComponent<TextMeshProUGUI>().text = value;
        }
        get { return idName; }
    }
    public Color UseColor
    {
        set
        {
            initMember();
            useColor = value;
            float h;
            float s;
            float v;
            Color.RGBToHSV(useColor, out h, out s, out v);
            if (v > 0.6)
            {
                v = v - 0.5f;
                
            }
            else if(v < 0.45f)
            {
                v = v + 0.5f;
            }
            else
            {
                v = v - v / 3;
            }
            Color color1 = Color.HSVToRGB(h, s, v);
            effectImg.color2 = color1;
            effectImg.color1 = useColor;
        }
        get
        {
            return useColor;
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        initMember();
        //IsSelect = isSelect;
        //IdName = idName;
        //UseColor = useColor;
        //NowProgress = nowProgress;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
    public bool isFinish()
    {
        return utilsTools.isEqualByValue(nowProgress,1.0f,0.0000002f);
    }
    public void onClickAreaGroup()
    {
        if (isSelect == false && isFinish() == false)
        {
            utilsTools.sendEventObjectParams("switchGameAreaGroupId", index);
        }
    }
    public void updateOneUI()
    {
        effectImg.updateTexture();
    }
    public void resetSize(float x,float y)
    {
        RectTransform rectTransform = GetComponent<RectTransform>();
        rectTransform.localScale = new Vector3 (100f/x,100f/y, 1);
    }
}
