using System.Collections.Generic;
using System.Drawing;
using TeslaConsole.Properties;

namespace TeslaConsole;

internal class ImageCache
{
	private static readonly Bitmap mPodBad16;

	private static readonly Bitmap mPodGo16;

	private static readonly Bitmap mPodOffline16;

	private static readonly Bitmap mPodOnline16;

	private static readonly Bitmap mPodQuestion16;

	private static readonly Bitmap mPodRun16;

	private static Dictionary<string, Image> mCache;

	public static Bitmap PodBad16 => mPodBad16;

	public static Bitmap PodGo16 => mPodGo16;

	public static Bitmap PodOffline16 => mPodOffline16;

	public static Bitmap PodOnline16 => mPodOnline16;

	public static Bitmap PodQuestion16 => mPodQuestion16;

	public static Bitmap PodRun16 => mPodRun16;

	static ImageCache()
	{
		mCache = new Dictionary<string, Image>();
		mPodBad16 = Resources.PodBad16;
		mPodGo16 = Resources.PodGo16;
		mPodOffline16 = Resources.PodOffline16;
		mPodOnline16 = Resources.PodOnline16;
		mPodQuestion16 = Resources.PodQuestion16;
		mPodRun16 = Resources.PodRun16;
	}

	public static Image GetImage(string path)
	{
		lock (mCache)
		{
			if (!mCache.ContainsKey(path))
			{
				try
				{
					mCache.Add(path, Image.FromFile(path));
				}
				catch
				{
				}
			}
			return mCache.ContainsKey(path) ? mCache[path] : null;
		}
	}
}
