using Remontor.Pinger;
using Remontor.Setting;
using Remontor.Words;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Remontor.Picter
{
    internal static class SPicManager
    {
        private static Dictionary<string, PicBase> PicList = new Dictionary<string, PicBase>();
        public static void PictureSet(PictureBox image, IComp comp)
        {
            IComp Comp = WordsList.FindCompName(comp.GetNetName());
            if(Comp != null)
            {
                if (Comp.GetImage() != 9)
                {
                    image.Image = PicBaseWords.GetImageMax(Comp.GetImage());
                    return;
                }
                
            }
            else
            {
                
                if (comp.GetName() != null)
                {


                    if (PicList.ContainsKey(comp.GetName()))
                    {
                        image.Image = PicList[comp.GetName()].ImageGet;
                    }
                    else
                    {
                        new PicLoaderTask(comp.GetName(), image);
                    }
                }
            }
        }

        static public void WriteResult(PicBase picBase)
        {
            try
            {
                if (PicList.ContainsKey(picBase.LoginGet))
                {
                    PicList.Add(picBase.LoginGet, picBase);
                    System.Console.WriteLine("add " + picBase.LoginGet + " all " + PicList.Count);
                }
                
                while (PicList.Count > SGlobalSetting.settingApp.sizePhotoItem)
                {
                    System.Console.WriteLine("delete " + PicList.First().Key);
                    PicList.Remove(PicList.First().Key);
                    
                }
            }
            catch
            {

            }


        }
    }
}
