using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace NotepadEnhanced.GUI.Controls.Panels
{
    public partial class DockedPanel : UserControl
    {
        private readonly Color _borderColor = Color.FromKnownColor(KnownColor.ActiveBorder);

        protected DockedPanel()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.ResizeRedraw, true);
        }

        protected override void OnLoad(EventArgs e)
        {
            if (DesignMode) this.Dock = DockStyle.None;
            base.OnLoad(e);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, _borderColor, ButtonBorderStyle.Solid);
        }

        private void _relatedMenuItem_CheckedChanged(object sender, EventArgs e)
        {
            if (_tsmiRelated != null && !_tsmiRelated.Checked)
            {
                this.Visible = _tsmiRelated.Checked;
            }
        }

        private ToolStripMenuItem _tsmiRelated;
        /// <summary>
        /// Gets or sets the tool strip menu item that is (un)checked to open this panel
        /// The panel needs control of this item so it may uncheck and chack apropriately
        /// </summary>
        [Browsable(false)]
        public ToolStripMenuItem RelatedMenuItem
        {
            get { return _tsmiRelated; }
            set
            {
                _tsmiRelated = value;

                if (_tsmiRelated != null)
                _tsmiRelated.CheckedChanged += _relatedMenuItem_CheckedChanged;
            }
        }
    }
}
