using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GFATask
{
    [
        Browsable(false),
        ToolboxItem(false)
    ]
    public partial class AppListButton : AnimationButton
    {
        internal string[] _activedirectorygroups = new string[] { };
        /// <summary>
        /// Sollte die App einer Gruppe zugeordnet sein, wird der Name hier angezeigt
        /// </summary>
        [
            Description("Sollte die App einer Gruppe zugeordnet sein, wird der Name hier angezeigt"),
            DefaultValue(typeof(string[]), "")
        ]
        public string[] ActiveDirectoryGroups
        {
            get => _activedirectorygroups;
            set => _activedirectorygroups = value;
        }


        private AppType _apptype = AppType.None;
        /// <summary>
        /// Definiert den Apptypen des AppButtons
        /// </summary>
        [Description("Definiert den Apptypen des AppButtons")]
        virtual public AppType AppType
        {
            get => _apptype;
            set
            {
                _apptype = value;
                //this.AllowDrop = _apptype == AppType.Favorites;
            }
        }

        

        private Prevalencia _prevelance = new Prevalencia();
        /// <summary>
        /// Erfasst die Häufigkeit der Klicks um die App nach Beliebtheit anzuordnen
        /// </summary>
        [
           Description("Erfasst die Häufigkeit der Klicks um die App nach Beliebtheit anzuordnen"),
           DefaultValue(true)
        ]
        virtual public Prevalencia Prevalence 
        { 
            get => _prevelance; 
            set => _prevelance = value; 
        }


        private bool _imageonly = false;
        virtual public bool ImageOnly { 
            get => _imageonly;
            set
            {
                _imageonly = value;
                OnImageOnlyChanged(new EventArgs());
                this.Invalidate();
            }
        }

        public virtual void OnImageOnlyChanged(EventArgs e)
        {
            if (this.ImageOnly)
            {
                this.Width = this.Height;
            }
            else
            {
                this.Width = _actualwidth;
            }
        }


        private int _actualwidth = 0;
        public int ActualWidth 
        { 
            get => _actualwidth;
            set
            {
                _actualwidth = value;
                OnImageOnlyChanged(new EventArgs());
            }
        }


        public AppListButton()
        {
            InitializeComponent();
        }

         
        protected override void OnMouseHover(EventArgs e)
        {
            if (this.ContextMenuStrip != null && this.ContextMenuStrip.Items.Count > 0)
            {
                int menusize = (int)(this.BorderBounds.Height * 72 / this.CreateGraphics().DpiX / 2);
            }
                
            base.OnMouseHover(e);
        }


        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if(e.Button == MouseButtons.Right)
            {
                if (this.ContextMenuStrip != null && this.ContextMenuStrip.Items.Count > 0)
                    this.ContextMenuStrip.Show(this, new Point(this.Padding.Left, this.ClientRectangle.Bottom));
            }
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            ToolTip.ShowAlways = true;
            if(Config.User.NecessaryClick)
                ToolTip.SetToolTip(this, this.ToolTipText);
            else
                ToolTip.SetToolTip(this, this.ToolTipText);
                //ToolTip.Show(this.ToolTipText, this, new Point(0, this.Height));
            base.OnMouseEnter(e);
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            this.ImageSize = new Size(this.BorderBounds.Height - this.Padding.Vertical - this.Margin.Vertical, this.BorderBounds.Height - this.Padding.Vertical - this.Margin.Vertical);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (e.Button == MouseButtons.Left && !this.ClientRectangle.Contains(e.Location))
            {
                this.DoDragDrop(this, DragDropEffects.Copy);
            }
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            if (_imageonly)
            {
                //pe.Graphics.SetClip(new Rectangle(TextBounds.X + 3, TextBounds.Y, TextBounds.Width - 3, TextBounds.Height));
                //pe.Graphics.Clear(this.BackColor);
            }
        }
    }
}
