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

public class CardProgramaHandler : MonoBehaviour {

    float tamanhoHora = 25.2f;

    Color progLight = new Color(84f / 255, 242f / 255, 25f / 255);
    Color progMedium = new Color(88f / 255, 184f / 255, 53f / 255);
    Color progDark = new Color(33f / 255, 99f / 255, 8f / 255);

    Color adsLight = new Color(255f / 255, 206f / 255, 0f);
    Color adsMedium = new Color(242f / 255, 199f / 255, 20f / 255);
    Color adsDark = new Color(189f / 255, 154f / 255, 6f / 255);

    public Programa programa;
    public Radio radio;

    RectTransform rectTransform;
    Image image;
    
	// Update is called once per frame
	void FixedUpdate () {
        if (rectTransform == null) {
            rectTransform = gameObject.GetComponent<RectTransform>();
        }
        if (image == null) {
            image = gameObject.GetComponent<Image>();
        }
        if (programa != null && !programa.played) {
            //se for menor que 6 (prefab) aumenta
            if (rectTransform.rect.width <= 5f) {
                rectTransform.sizeDelta = new Vector2(tamanhoHora * programa.duracao, 68f);
            }
            
            if (radio.hora > programa.horaInicial + programa.duracao) {
                if (programa.ad) {
                    image.color = adsDark;
                } else {
                    image.color = progDark;
                }
            } else if (radio.hora > programa.horaInicial) {
                if (programa.ad) {
                    image.color = adsLight;
                } else {
                    image.color = progLight;
                }
            } else {
                programa.played = true;
                if (programa.ad) {
                    image.color = adsMedium;
                } else {
                    image.color = progMedium;
                }
            }
        }
	}

    public void Remove() {
        if (!radio.tocando) {
            radio.RemovePrograma(gameObject);
        }
    }
}
