using Igdc;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;

namespace Editor
{
    public partial class ToolSelector : UserControl
    {
        public event EventHandler<Point> Selected;

        private BitmapSource _bitmap;

        private const int TileSize = 16;
        private const int MaxX = 1;
        private const int MaxY = 3;

        public ToolSelector()
        {
            InitializeComponent();
            _bitmap = BitmapLoader<AssemblyPointer>.Load("MapBackground1");
            var image = new Image
            {
                Source = _bitmap
            };
            TileCanvas.Children.Add(image);
        }

        private void Root_MouseUp(object sender, MouseButtonEventArgs e)
        {
            var p = e.GetPosition(Root);
            var x = (int)(p.X / TileSize);
            var y = (int)(p.Y / TileSize);
            if (x > MaxX || y > MaxY) return; 
            Selected?.Invoke(this, new Point(x, y));
        }
    }
}