using System.Windows;
using System.Windows.Media;
using InABox.Core;
using Syncfusion.Data;
using Syncfusion.UI.Xaml.Grid;
using Syncfusion.UI.Xaml.Grid.Cells;

namespace InABox.DynamicGrid;

public class DynamicGridDoubleColumn<TEntity> : DynamicGridNumericColumn<TEntity, DoubleEditor, GridNumericColumn> where TEntity : BaseObject
{

    protected override void Configure(GridNumericColumn column, DoubleEditor editor)
    {
        column.NumberDecimalDigits = GetDigits(editor);
        column.NumberGroupSeparator = ",";
        column.NumberGroupSizes = new Int32Collection(new[] { 3, 3, 3, 3, 3, 3 });
    }
    
    public override int Digits => Column.NumberDecimalDigits;
    
    public override GridSummaryColumn? Summary()
    {
        if (Definition == null || Definition.Editor.Summary == Core.Summary.None)
            return null;
        
        var format = Definition.Editor.Summary == Core.Summary.Count
            ? "N0"
            : $"N{Digits}";
                            
        var summary = new GridSummaryColumn
        {
            Name = MappingName,
            Format = "{" + (Definition.Editor.Summary == Core.Summary.Sum ? "Sum" : "Count") + ":" + format + "}",
            MappingName = MappingName,
            SummaryType = Definition.Editor.Summary == Core.Summary.Sum
                ? SummaryType.DoubleAggregate
                : SummaryType.CountAggregate,
            CustomAggregate = new DynamicGridDoubleAggregate()
        };
        return summary;
    }

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