using Remontor.Connector;
using Remontor.Picter;
using Remontor.Seacher;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Remontor.History
{
    internal partial class HistoryControl : UserControl
    {
        public Color BackCustum;
        private HistoryItem historyItem;
        bool OpenMenu = false;
        public HistoryControl()
        {
            InitializeComponent();
            BackCustum = this.BackColor;
        }
        
        public HistoryControl(HistoryItem hitem)
        {
            InitializeComponent();
            string output = string.Format("{0,17: HH:mm:ss dd.MM.yy}", hitem.GetStart());
            TimeLB.Text = output;
            PCLB.Text = hitem.NameNode();
            FIOLB.Text = hitem.GetComp().GetDescription();
            BackCustum = this.BackColor;
            SPicManager.PictureSet(Photo, hitem.GetComp());
            historyItem = hitem;

        }

        private void HistoryControl_MouseEnter(object sender, EventArgs e)
        {
            this.BackColor = SystemColors.ControlLight;
            
        }

        private void HistoryControl_MouseLeave(object sender, EventArgs e)
        {
            if (!OpenMenu)
            {
                this.BackColor = BackCustum;
                //System.Console.WriteLine("out");
            }
            
        }

        private void HistoryControl_DoubleClick(object sender, EventArgs e)
        {
            SConnector.NewConnect(historyItem.GetComp());
        }

        private void CloseMenu()
        {
            OpenMenu = false;
            this.BackColor = BackCustum;
        }

        private void label3_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (sender is Control)

                {
                    OpenMenu = true;
                    //System.Console.WriteLine("in");
                    this.BackColor = SystemColors.ActiveCaption;
                    Control control = (Control)sender;
                    SConnector.FormMain.MenuStripCommand.ShowMenu(historyItem.GetComp(), control.PointToScreen(e.Location), CloseMenu);
                }
               
              

            }
        }
    }
}
