using InABox.Core;
using InABox.DynamicGrid;
using InABox.Wpf;
using InABox.WPF;
using NPOI.POIFS.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace InABox.DynamicGrid;

public class StandardDynamicGridColumnFilter(IBaseDynamicGrid grid, DynamicColumnBase column) : CheckBoxDynamicGridColumnFilter
{
    public IBaseDynamicGrid Grid { get; set; } = grid;
    public DynamicColumnBase Column { get; set; } = column;

    protected override FilterItem[] GetData()
    {
        var items = (this as IDynamicGridColumnFilter).GetRowsToFilter(Grid)
            .Select(x => Grid.GetData(x, Column))
            .Distinct()
            .Select(x => new FilterItem(x, x?.ToString() ?? "", this))
            .ToArray();
        Array.Sort(items, (a, b) => a.Display.CompareTo(b.Display));
        return items;
    }

    public override bool FilterRow(CoreRow row)
    {
        var data = Grid.GetData(row, Column);
        return SelectedFilters is null || SelectedFilters.Contains(data);
    }
}
