using LibraryMangementSystem.BookManage;
using LibraryMangementSystem.BookRead;
using LibraryMangementSystem.StatisticData;
using LibraryMangementSystem.SystemSet;
using LibraryMangementSystem.UI;
using LibraryMangementSystem.UI.BookManage;
using LibraryMangementSystem.UI.CertManages;
using LibraryMangementSystem.UI.LoanManage;
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;

namespace LibraryMangementSystem
{
    public partial class UI_Index : Form
    {
        int PanelWidth;
        bool isCollapsed;
        bool isButton;
        public UI_Index()
        {
            InitializeComponent();
            PanelWidth = panelLeft.Width;
            isCollapsed = false;
            timerTime.Start();
            UI_Home home = new UI_Home();
            AddControlsToPanel(home);
            StartPosition = FormStartPosition.CenterScreen;
            isButton = true;

        }

        private void button11_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (isCollapsed)
            {
                panelLeft.Width=panelLeft.Width + 5;
                if (panelLeft.Width>=PanelWidth) {
                    timer1.Stop();
                    isCollapsed = false;
                    this.Refresh();
                }
                
            }
            else
            {
                panelLeft.Width = panelLeft.Width - 5;
                if (panelLeft.Width <=66 )
                {
                    timer1.Stop();
                    isCollapsed = true;
                    this.Refresh();
                }
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }
        private void moveSidePanel(Control but) {
            panelSide.Top = but.Top;
            panelSide.Height = but.Height;
        }
        private void AddControlsToPanel(Control c)
        {
            c.Dock = DockStyle.Fill;
            panelDisplay.Controls.Clear();
            panelDisplay.Controls.Add(c);

        }
        private void AddFormToPanel(Form f)
        {
            f.MdiParent = this;
            f.WindowState = FormWindowState.Maximized;
            f.TopLevel = false;
            f.FormBorderStyle = FormBorderStyle.None;
            f.Dock = DockStyle.Fill;
            panelDisplay.Controls.Clear();
            panelDisplay.Controls.Add(f);
            f.Show();

        }

        private void buttonHome_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonHome);
            UI_Home home = new UI_Home();
            AddControlsToPanel(home);
        }

        private void buttonBookManage_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonBookManage);
            BooksManage b = new BooksManage(sender,e);
            AddControlsToPanel(b);
        }

        private void buttonBookQuery_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonBookQuery);
            PublisherInfoForm publisher =new PublisherInfoForm();
            AddFormToPanel(publisher);
        }

        private void buttonRental_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonRental);
            LoanManages loanManages=new LoanManages(sender,e);
            AddControlsToPanel(loanManages);
        }

        private void buttonCertManage_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonCertManage);
            CertManages c = new CertManages(sender, e);
            AddControlsToPanel(c);

        }

        private void buttonStatisticData_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonStatisticData);
            StatisticCount statistic=new StatisticCount();
            AddFormToPanel(statistic);
        }

        private void buttonBookScan_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonBookScan);
            BookAbstract book=new BookAbstract(sender,e);
            AddFormToPanel(book);
        }

        private void buttonSystemSet_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonSystemSet);
            timer2.Start();
        }

        private void buttonHelp_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonHelp);
            UI_Help c = new UI_Help();
            AddControlsToPanel(c);

        }

        private void timerTime_Tick(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;
            labelTime.Text = dt.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (isButton)
            {
                //展开
                panelSubMenu.Height = panelSubMenu.Height + 5;
                if (86 <= panelSubMenu.Height)
                {
                    timer2.Stop();
                    isButton = false;
                    this.Refresh();
                }

            }
            else
            {
                //收回
                panelSubMenu.Height = panelSubMenu.Height - 5;
                if (panelSubMenu.Height <= 0)
                {
                    timer2.Stop();
                    isButton = true;
                    this.Refresh();
                }
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonSystemSet);
            SysSet sysSet = new SysSet();
            AddFormToPanel(sysSet);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            moveSidePanel(buttonSystemSet);
            UI_UpdateDays UpdateDays = new UI_UpdateDays();
            AddFormToPanel(UpdateDays);
        }


    }
}
