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 DynamicGridMemoColumn<TEntity> : DynamicGridEditorColumn<TEntity,MemoEditor,GridTextColumn>
    where TEntity : BaseObject
{
    protected override void UpdateBinding(GridTextColumn column)
    {
        base.UpdateBinding(column);
        var prop = CoreUtils.GetProperty<TEntity>(Definition.ColumnName);
        var binding = new Binding
        {
            Path = new PropertyPath(MappingName), 
            Converter = prop.PropertyType == typeof(string[]) 
                ? new StringArrayConverter() 
                : null
        };
        column.DisplayBinding = binding;
        column.ValueBinding = binding;

    }

    protected override void Configure(GridTextColumn column, MemoEditor editor)
    {
        column.TextWrapping = TextWrapping.NoWrap;
        column.UpdateTrigger = UpdateSourceTrigger.PropertyChanged;
    }
    
    public override bool VariableHeight => true;

    public DynamicGridMemoColumn(DynamicGridColumn definition) : base(definition)
    {
    }
}