using Remontor.Connector;
using Remontor.Setting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Remontor.History
{
    [Serializable]
    internal static class HistoryList
    {
        static public List<HistoryItem> Hitem = new List<HistoryItem>();
        //static private FormHistory formHistory;

        public delegate void UpdateMethod(List<HistoryItem> items);
        static public event UpdateMethod Update;
        static public HistoryItem Add(Connect connect)
        {

            HistoryItem historyItem = new HistoryItem(connect);
            Hitem.Insert(0, historyItem);
            ClearFirst();
            Update(Hitem);
            
            return historyItem;
           
        }
        static public void Updated()
        {
            Update(Hitem);
        }
        static public void Clear()
        {
            Hitem.Clear();
            Update(Hitem);
        }

        static public void ClearFirst()
        {
            if(Hitem.Count > SGlobalSetting.settingApp.sizeHistoryItem) 
            {
                Hitem.RemoveAt(Hitem.Count() - 1);
                ClearFirst();
            }
            
            
        }
    }
}
