using System.Collections;
using System.Collections.Generic;
using Camera;
using UnityEngine;
using Game;

namespace InteractiveModules
{
    public class GreenHouse : InteractiveModule
    {
        [SerializeField] private GameScreenAsset nextScreen;
        [SerializeField] private ColorManager colorManager;
        private int totalLeaves;
        private int currentLeaves;

        public override void Activate(ScreenController screenController)
        {
            base.Activate(screenController);
            screenController.SetBackgroundColor(ColorType.Yellow);
        }

        // Start is called before the first frame update
        void Start()
        {
            totalLeaves = transform.Find("FlowerGroup").childCount;
            currentLeaves = totalLeaves;
        }

        // Update is called once per frame
        void Update()
        {

        }

        public void OnMouseDown()
        {
            currentScreenController.LoadScreen(nextScreen);
        }

        public void LeaveLeft()
        {
            currentLeaves--;
            //LeanTween.color(transform.Find("Background").gameObject, new Color(1f, 1f, 1f, (float)currentLeaves / totalLeaves), 1f);
            float a = (float)currentLeaves / totalLeaves;
            Color x = colorManager.GetColor(ColorType.Yellow) * a + colorManager.GetColor(ColorType.Grey) * (1 - a);
            currentScreenController.SetBackgroundColor(x, 1f);
            if (currentLeaves == 0)
            {
                Invoke("DelayedExit", 1f);
            }
        }

        public void DelayedExit()
        {
            GetComponent<BoxCollider2D>().enabled = true;
        }
    }
}