using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using InABox.Core;
using Microsoft.Xaml.Behaviors.Core;

namespace InABox.DynamicGrid;

public class ConstantNode : ComboBox
{
    
    public delegate void ConstantChangedHandler(FilterConstant? constant);

    public event ConstantChangedHandler? ConstantChanged;
    
    public ConstantNode()
    {
        SetResourceReference(StyleProperty, typeof(ComboBox));

        VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
        VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
        MinWidth = 50;
        SelectionChanged += ComboBox_SelectionChanged;
    }

    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ConstantChanged?.Invoke(SelectedConstant);
    }
    
    public FilterConstant? SelectedConstant {
        get => (SelectedItem != null) ? ((KeyValuePair<String,FilterConstant?>)SelectedItem).Value : null;
        set => SelectedValue = value;
    }
}