using System;
using UniRx;
using UnityEngine;

namespace Hazards
{
    public class FireExtinguisher : Hazard
    {
        public GameObject extinguish_PS;
        public GameObject fire;
        
        private void Update()
        {
            if (extinguish_PS.activeSelf)
            {
                extinguish_PS.transform.LookAt(fire.transform);
            }
        }

        private void OnTriggerStay2D(Collider2D other)
        {
            
            if (onMouseDown)
            {
                if (other.CompareTag("Fire"))
                {
                    extinguish_PS.SetActive(true);
                    fire = other.gameObject;
                    extinguish_PS.transform.LookAt(fire.transform);
                    if (PlayerInteraction.Instance != null)
                    {
                        PlayerInteraction.Instance.StartInteraction();
                    }
                }    
            }
            else
            {
                extinguish_PS.SetActive(false);
                if (PlayerInteraction.Instance != null)
                {
                    PlayerInteraction.Instance.StopInteraction();
                }
            }
            
        }

        private void OnTriggerExit2D(Collider2D other)
        {
            if (other.CompareTag("Fire"))
            {
                extinguish_PS.SetActive(false);
                if (PlayerInteraction.Instance != null)
                {
                    PlayerInteraction.Instance.StopInteraction();
                }
            }
        }

        public override void OnDragEnd()
        {
            extinguish_PS.SetActive(false);
            if (PlayerInteraction.Instance != null)
            {
                PlayerInteraction.Instance.StopInteraction();
            }
        }
    }
}
