@namespace Lumeo
@typeparam TItem

@code {
    [CascadingParameter] private DataGrid<TItem>? ParentGrid { get; set; }

    [Parameter] public string? Title { get; set; }
    [Parameter] public string? Field { get; set; }
    [Parameter] public Func<TItem, object?>? FieldSelector { get; set; }
    [Parameter] public double? Width { get; set; }
    [Parameter] public bool Sortable { get; set; }
    [Parameter] public bool Filterable { get; set; }
    [Parameter] public bool Resizable { get; set; } = true;
    [Parameter] public DataGridFilterType FilterType { get; set; } = DataGridFilterType.Text;
    [Parameter] public AggregateType Aggregate { get; set; } = AggregateType.None;
    [Parameter] public string? Format { get; set; }
    [Parameter] public PinDirection Pin { get; set; } = PinDirection.None;
    [Parameter] public RenderFragment<TItem>? CellTemplate { get; set; }
    [Parameter] public RenderFragment? HeaderTemplate { get; set; }
    [Parameter] public RenderFragment<CellEditContext<TItem>>? EditTemplate { get; set; }
    [Parameter] public double? MinWidth { get; set; }
    [Parameter] public double? MaxWidth { get; set; }
    [Parameter] public bool Pinnable { get; set; }
    [Parameter] public bool Groupable { get; set; }
    [Parameter] public bool Reorderable { get; set; } = true;
    [Parameter] public Func<TItem, string>? CellClass { get; set; }
    [Parameter] public string? HeaderCssClass { get; set; }
    [Parameter] public Comparison<object?>? CustomSort { get; set; }
    [Parameter] public List<FilterOption>? FilterOptions { get; set; }
    [Parameter] public List<FilterOperator>? Operators { get; set; }
    [Parameter] public RenderFragment<DataGridFilterTemplateContext>? FilterTemplate { get; set; }
    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    protected override void OnInitialized()
    {
        ParentGrid?.AddColumnDef(new DataGridColumn<TItem>
        {
            Title = Title,
            Field = Field,
            FieldSelector = FieldSelector,
            Width = Width,
            Sortable = Sortable,
            Filterable = Filterable,
            Resizable = Resizable,
            FilterType = FilterType,
            Aggregate = Aggregate,
            Format = Format,
            Pin = Pin,
            CellTemplate = CellTemplate,
            HeaderTemplate = HeaderTemplate,
            EditTemplate = EditTemplate,
            FilterOptions = FilterOptions,
            Operators = Operators,
            FilterTemplate = FilterTemplate,
            MinWidth = MinWidth,
            MaxWidth = MaxWidth,
            Pinnable = Pinnable,
            Groupable = Groupable,
            Reorderable = Reorderable,
            CellClass = CellClass,
            HeaderCssClass = HeaderCssClass,
            CustomSort = CustomSort,
            CssClass = Class
        });
    }
}
