using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using InABox.Core;
using InABox.WPF;
using Syncfusion.UI.Xaml.Grid;

namespace InABox.DynamicGrid;

public class DynamicGridCheckBoxColumn<TEntity> : DynamicGridEditorColumn<TEntity,CheckBoxEditor,GridTemplateColumn>
    where TEntity : BaseObject
{
    private readonly BitmapSource tick = Wpf.Resources.tick.AsBitmapImage();
    
    protected override void Configure(GridTemplateColumn column, CheckBoxEditor editor)
    {
        column.CellTemplate = TemplateGenerator.CreateDataTemplate
        (
            () =>
            {
                var result = new Image() { Source = tick, Margin = new Thickness(2) };
                var binding = new Binding() { Path = new PropertyPath(MappingName), Converter = new BooleanToVisibilityConverter() };
                result.SetBinding(UIElement.VisibilityProperty, binding);
                return result;
            }
        );
        
        column.EditTemplate = TemplateGenerator.CreateDataTemplate
        (
            () =>
            {
                var result = new CheckBox() { IsThreeState = false };
                var binding = new Binding() { Path = new PropertyPath(MappingName) };
                result.SetBinding(ToggleButton.IsCheckedProperty, binding);
                result.HorizontalAlignment = HorizontalAlignment.Center;
                result.VerticalAlignment = VerticalAlignment.Center;
                return result;
            }
            
        );
        column.SetCellBoundValue = false;
 
    }

    public override bool Filtered => false;
    public override bool VariableWidth => false;

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