using System.Collections.Generic;
using System.Windows.Forms;

namespace Turbo.Plugins.Enhanced
{
    /// <summary>
    /// Example: Hud.GetPlugin<UiElementClickBlockerPlugin>().Add(Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetCampaign_main.LayoutRoot.Slot1.LayoutRoot.SwitchHero", null, null));
    /// </summary>
    public class UiElementClickBlockerPlugin : BasePlugin, IMouseClickBlocker
    {
        private readonly List<IUiElement> _elements = new List<IUiElement>();

        public UiElementClickBlockerPlugin()
        {
            Enabled = true;
        }

        public override void Load(IController hud)
        {
            base.Load(hud);
        }

        public void Add(IUiElement element)
        {
            lock (_elements)
            {
                _elements.Add(element);
            }
        }

        public void Remove(IUiElement element)
        {
            lock (_elements)
            {
                _elements.Remove(element);
            }
        }

        public bool MouseClickShouldBeBlocked(MouseButtons button, int x, int y)
        {
            lock (_elements)
            {
                foreach (var element in _elements)
                {
                    if (element.Visible && element.CoordinateInsideRectangle(x, y))
                        return true;
                }
            }

            return false;
        }
    }
}