using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Markup.Xaml;

namespace SessionZero.Pages;

public partial class SettingsPage : UserControl, IPageBase
{
    public string PageName { get; set; } = "Settings";
    
    private Slider? _consoleTrimSlider;
    private TextBlock? _consoleTrimSliderLabel;
    
    public SettingsPage()
    {
        InitializeComponent();
        
        _consoleTrimSlider = this.FindControl<Slider>("ConsoleTrimSlider");
        _consoleTrimSliderLabel = this.FindControl<TextBlock>("ConsoleTrimSliderValue");
        
        _consoleTrimSlider?.ValueChanged += ConsoleTrimSliderOnValueChanged;
    }

    private void ConsoleTrimSliderOnValueChanged(object? sender, RangeBaseValueChangedEventArgs e)
    {
        AppManager.ConsoleControl.OutputTrimSize = (int)e.NewValue;
        _consoleTrimSliderLabel?.Text = AppManager.ConsoleControl.OutputTrimSize.ToString();
    }

    public void Refresh()
    {
        _consoleTrimSlider?.Value = AppManager.ConsoleControl.OutputTrimSize;
        _consoleTrimSliderLabel?.Text = AppManager.ConsoleControl.OutputTrimSize.ToString(); 
    }
}