using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using InABox.Core;
using Syncfusion.UI.Xaml.Grid;

namespace InABox.DynamicGrid;

public class DynamicGridColorColumn<TEntity> : DynamicGridEditorColumn<TEntity,ColorEditor,GridImageColumn>
    where TEntity : BaseObject
{
    private readonly int _height;
    private readonly int _width;

    
    protected override void UpdateBinding(GridImageColumn column)
    {
        column.ValueBinding = new Binding
        {
            Path = new PropertyPath(MappingName),
            Converter = new StringToColorImageConverter(Math.Max(25,_width) - 8, Math.Max(25,_height) - 8)
        };
    }

    protected override void Configure(GridImageColumn column, ColorEditor editor)
    {
        column.ImageHeight = Math.Max(25,_height) - 8;
        column.ImageWidth = Math.Max(25,_width) - 8;
        column.Padding = new Thickness(4);
    }
    
    public override bool Filtered => false;
    public override bool VariableWidth => false;

    public DynamicGridColorColumn(DynamicGridColumn definition, int width, int height) : base(definition)
    {
        _width = Math.Max(25,width);
        _height = Math.Max(25,height);
    }
}