using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using System; using System.Collections.Generic; using System.Linq; using Avalonia.Interactivity; using Avalonia.Layout; using SukiUI.Enums; using Avalonia.Controls.Templates; namespace SukiUI.Controls; public class SukiSideMenu : SelectingItemsControl { public static readonly StyledProperty SearchTextProperty = AvaloniaProperty.Register(nameof(SearchText)); public static readonly StyledProperty IsSearchEnabledProperty = AvaloniaProperty.Register(nameof(IsSearchEnabled), defaultValue: false); public static readonly StyledProperty SidebarToggleEnabledProperty = AvaloniaProperty.Register(nameof(SidebarToggleEnabled), defaultValue: true); public bool SidebarToggleEnabled { get => GetValue(SidebarToggleEnabledProperty); set => SetValue(SidebarToggleEnabledProperty, value); } public string? SearchText { get => GetValue(SearchTextProperty); set => SetValue(SearchTextProperty, value); } public bool IsSearchEnabled { get => GetValue(IsSearchEnabledProperty); set => SetValue(IsSearchEnabledProperty, value); } public static readonly StyledProperty IsToggleButtonVisibleProperty = AvaloniaProperty.Register(nameof(IsToggleButtonVisible), defaultValue: true); public bool IsToggleButtonVisible { get => GetValue(IsToggleButtonVisibleProperty); set => SetValue(IsToggleButtonVisibleProperty, value); } public static readonly StyledProperty IsMenuExpandedProperty = AvaloniaProperty.Register(nameof(IsMenuExpanded), defaultValue: true); public bool IsMenuExpanded { get => GetValue(IsMenuExpandedProperty); set => SetValue(IsMenuExpandedProperty, value); } public static readonly StyledProperty OpenPaneLengthProperty = AvaloniaProperty.Register(nameof(OpenPaneLength), defaultValue: 220); public int OpenPaneLength { get => GetValue(OpenPaneLengthProperty); set => SetValue(OpenPaneLengthProperty, value switch { >= 200 => value, _ => throw new ArgumentOutOfRangeException($"OpenPaneLength must be greater than or equal to 200, but was {value}") }); } public static readonly StyledProperty TogglePaneButtonPositionProperty = AvaloniaProperty.Register(nameof(TogglePaneButtonPosition), defaultValue: HorizontalAlignment.Right); public SideMenuTogglePaneButtonPositionOptions TogglePaneButtonPosition { get => GetValue(TogglePaneButtonPositionProperty) switch { HorizontalAlignment.Right => SideMenuTogglePaneButtonPositionOptions.Right, HorizontalAlignment.Left => SideMenuTogglePaneButtonPositionOptions.Left, _ => SideMenuTogglePaneButtonPositionOptions.Right }; set => SetValue(TogglePaneButtonPositionProperty, value switch { SideMenuTogglePaneButtonPositionOptions.Right => HorizontalAlignment.Right, SideMenuTogglePaneButtonPositionOptions.Left => HorizontalAlignment.Left, _ => HorizontalAlignment.Right }); } public static readonly StyledProperty IsSelectedItemContentMovableProperty = AvaloniaProperty.Register(nameof(IsSelectedItemContentMovable), defaultValue: true); public bool IsSelectedItemContentMovable { get => GetValue(IsSelectedItemContentMovableProperty); set => SetValue(IsSelectedItemContentMovableProperty, value); } public static readonly StyledProperty HeaderMinHeightProperty = AvaloniaProperty.Register(nameof(HeaderMinHeight)); public double HeaderMinHeight { get => GetValue(HeaderMinHeightProperty); set => SetValue(HeaderMinHeightProperty, value); } public static readonly StyledProperty HeaderContentProperty = AvaloniaProperty.Register(nameof(HeaderContent)); public object? HeaderContent { get => GetValue(HeaderContentProperty); set => SetValue(HeaderContentProperty, value); } public static readonly StyledProperty FooterContentProperty = AvaloniaProperty.Register(nameof(FooterContent)); public object? FooterContent { get => GetValue(FooterContentProperty); set => SetValue(FooterContentProperty, value); } private bool IsSpacerVisible => !IsMenuExpanded; private SukiTransitioningContentControl? _contentControl; private Grid? _spacer; public SukiSideMenu() { SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected; } private void MenuExpandedClicked() { IsMenuExpanded = !IsMenuExpanded; if(_sideMenuItems.Any()) foreach (var item in _sideMenuItems) item.IsTopMenuExpanded = IsMenuExpanded; else if(Items.FirstOrDefault() is SukiSideMenuItem) foreach (SukiSideMenuItem? item in Items) item!.IsTopMenuExpanded = IsMenuExpanded; } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); if (Items.Any()) { SelectedItem = Items.First(); } e.NameScope.Get