using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Markup.Xaml.Templates;
using Avalonia.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InABox.Avalonia.Components;

public class AvaloniaDataGridImageColumn<TEntity> : AvaloniaDataGridColumn<TEntity, IImage?>
{
    public override bool Searchable => false;

    public double Margin { get; set; }

    public IImage? Header { get; set; }

    public Stretch Stretch { get; set; } = Stretch.Uniform;

    public override DataGridColumn CreateColumn()
    {
        var column = CreateColumn<DataGridTemplateColumn>();
        column.CellTemplate = new FuncDataTemplate<object?>((value, scope) =>
        {
            var image = new Image();
            image.Bind(Image.SourceProperty, new Binding(ColumnName));
            image.Margin = new(Margin);
            image.Stretch = Stretch;
            return image;
        });
        if(Header is not null)
        {
            column.HeaderTemplate = new FuncDataTemplate<object?>((value, scope) =>
            {
                var image = new Image();
                image.Source = Header;
                image.Stretch = Stretch;
                image.Margin = new(Margin);
                return image;
            });
        }
        return column;
    }

    public override bool Filter(TEntity item, string filter)
    {
        return false;
    }
}
