using System.Drawing;
using System.Windows.Media.Imaging;
using InABox.Core;
using InABox.WPF;

namespace InABox.DynamicGrid;

public class DynamicImageColumn : DynamicActionColumn
{
    private static readonly BitmapImage empty = new Bitmap(32, 32).ToBitmapImage();

    public delegate BitmapImage? GetImageDelegate(CoreRow? row);

    protected DynamicImageColumn()
    {
    }

    public DynamicImageColumn(GetImageDelegate image, ActionDelegate? action = null)
    {
        Image = image;
        Action = action;
        VerticalHeader = true;
    }

    public DynamicImageColumn(BitmapImage image, ActionDelegate? action = null)
    {
        Image = r => image;
        Action = action;
    }

    public GetImageDelegate Image { get; protected set; }


    public bool AllowHeaderClick { get; set; } = false;
        
    public override object? Data(CoreRow? row) => Image?.Invoke(row) ?? empty;
}