using parkMonitor.model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace parkMonitor.view.util {
	/// <summary>Device To Image Binding</summary>
	public class DevImgBind : Binding {
		public DevImgBind() {
			Converter = DevImgCvt.ins;
		}

		public DevImgBind(string path) : base(path) {
			Converter = DevImgCvt.ins;
		}
	}

	/// <summary>Device To Image Converter</summary>
	public class DevImgCvt : IValueConverter {
		public static DevImgCvt ins = new DevImgCvt();
		public string rootPath = @"pack://application:,,,/parkMonitor;component/resource/image/";

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			DeviceType? imgType = value as DeviceType?;
			if(imgType == null) {
				return null;
			}

			string path = rootPath;
			switch(imgType) {
			case DeviceType.WebServer: path += "map/monitor.png"; break;
			case DeviceType.Central: path += "map/monitor.png"; break;
			case DeviceType.NumMachine: path += "map/numMachine.png"; break;
			case DeviceType.Laser: path += "map/laser.png"; break;
			case DeviceType.Tray: path += "map/tray.png"; break;
			case DeviceType.Robot: path += "map/robot.png"; break;
			case DeviceType.Raster: path += "map/raster.png"; break;
			case DeviceType.Ultrasonic: path += "map/ultrasonic.png"; break;
			case DeviceType.Sensor: path += "map/sensor.png"; break;
			case DeviceType.Garage: path += "map/garage.png"; break;
			case DeviceType.Car: path += "map/car.png"; break;
			default:path = "";break;
			}

			if(path == "") {
				return null;
			}

			try {
				ImageSource source = new BitmapImage(new Uri(path));
				source.Freeze();
				return source;
			} catch(Exception) {

			}
			return null;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
			throw new NotImplementedException();
		}
	}

}
