using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Windows;
using InABox.Core;
using InABox.WPF;
using Syncfusion.Data;
using Syncfusion.UI.Xaml.Grid;
using Syncfusion.UI.Xaml.Grid.Cells;

namespace InABox.DynamicGrid;


public abstract class DynamicGridNumericColumn<TEntity, TEditor, TColumn> : DynamicGridEditorColumn<TEntity, TEditor, TColumn>, IDynamicGridNumericColumn 
    where TEntity : BaseObject
    where TEditor : NumericEditor, new()
    where TColumn : GridColumn, new()
{
    
    public abstract int Digits { get; }
    
    protected int GetDigits(TEditor editor)
    {
        int digits = editor.Digits;
        if (!string.IsNullOrWhiteSpace(Definition?.Format))
        {
            var formatted = 0.ToString(Definition.Format);
            var separator = formatted.IndexOf(".", StringComparison.InvariantCulture);
            digits = separator == -1
                ? 0
                : formatted.Length - (separator + 1);
        }
        return digits;
    }

    

    protected DynamicGridNumericColumn(DynamicGridColumn definition) : base(definition)
    {
    }
}