using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using TeamsISO.App.WinUI.Models;
using TeamsISO.App.WinUI.Services;
using Windows.Graphics;
using Windows.UI;
namespace TeamsISO.App.WinUI.Views;
public sealed partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Title = "TeamsISO";
// ── Custom title bar wiring ───────────────────────────────────────
// ExtendsContentIntoTitleBar=true tells WindowsAppSDK to draw the
// window chrome over our content instead of reserving a Windows-default
// caption strip. SetTitleBar marks AppTitleBar as the drag region —
// clicks on it route to the system drag handler, everything else stays
// hit-testable as a normal XAML element. The system min/max/close
// buttons render on top of the right edge regardless; we just provide
// their colors so they match our palette.
ExtendsContentIntoTitleBar = true;
SetTitleBar(AppTitleBar);
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonHoverForegroundColor = Colors.White;
// ── Initial size & position ───────────────────────────────────────
// 1280x780 matches the WPF host's default — fits comfortably on a
// 14-inch laptop while giving the participants table 600+ pixels
// of vertical breathing room.
AppWindow.Resize(new SizeInt32(1280, 780));
// ── Mock data wiring (interim) ────────────────────────────────────
// Until ParticipantViewModel binds in the engine wiring commit, the
// table is populated from a static sample list so the visual design
// can be validated end-to-end against representative data.
ParticipantsRepeater.ItemsSource = MockParticipant.Sample();
// ── Theme system ──────────────────────────────────────────────────
// Subscribe to ThemeManager so picker changes from anywhere
// (settings drawer, title-bar toggle, system color change) reach
// the title-bar buttons and the visual tree consistently. Apply
// once at construction so the initial state matches the preference
// before the first frame.
ThemeManager.Current.Themed += (_, theme) => ApplyResolvedTheme(theme);
ApplyResolvedTheme(ThemeManager.Current.ResolveTheme());
}
///
/// Cycle the active theme between Dark and Light from the title-bar
/// toggle. The actual swap lives in ; this
/// handler just calls Toggle() and lets the subscription propagate.
///
private void OnThemeToggleClick(object sender, RoutedEventArgs e)
{
ThemeManager.Current.Toggle();
}
private bool _drawerOpen;
///
/// Toggle the settings drawer with a slide animation. The drawer is
/// pre-translated 400px off the right edge in XAML; the storyboard
/// animates X back to 0 to slide it in. Hit-testing is gated so the
/// off-screen drawer doesn't intercept clicks on the participants list.
///
private void OnSettingsClick(object sender, RoutedEventArgs e)
{
if (_drawerOpen)
{
CloseDrawer();
}
else
{
OpenDrawer();
}
}
private void OpenDrawer()
{
if (_drawerOpen) return;
_drawerOpen = true;
SettingsDrawerHost.IsHitTestVisible = true;
var sb = (Microsoft.UI.Xaml.Media.Animation.Storyboard)((Microsoft.UI.Xaml.Controls.Grid)Content)
.Resources["DrawerSlideIn"];
sb.Begin();
SettingsDrawerHost.CloseRequested -= OnDrawerCloseRequested;
SettingsDrawerHost.CloseRequested += OnDrawerCloseRequested;
}
private void CloseDrawer()
{
if (!_drawerOpen) return;
_drawerOpen = false;
var sb = (Microsoft.UI.Xaml.Media.Animation.Storyboard)((Microsoft.UI.Xaml.Controls.Grid)Content)
.Resources["DrawerSlideOut"];
sb.Completed += (_, _) => SettingsDrawerHost.IsHitTestVisible = false;
sb.Begin();
}
private void OnDrawerCloseRequested(object? sender, System.EventArgs e) => CloseDrawer();
///
/// Push a resolved theme to the visual tree and to the AppWindow
/// title-bar buttons. Called on every
/// event and once at construction.
///
private void ApplyResolvedTheme(ElementTheme theme)
{
if (Content is FrameworkElement root)
{
root.RequestedTheme = theme;
}
AppWindow.TitleBar.ButtonForegroundColor = ThemeManager.TitleBarForegroundFor(theme);
AppWindow.TitleBar.ButtonHoverBackgroundColor = ThemeManager.TitleBarHoverBgFor(theme);
AppWindow.TitleBar.ButtonPressedBackgroundColor = ThemeManager.TitleBarHoverBgFor(theme);
// Glyph cue: sun () means current is Light, click moves to Dark;
// moon () means current is Dark, click moves to Light.
ThemeToggleIcon.Glyph = theme == ElementTheme.Light ? "" : "";
}
}