using CineBook.Models; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace CineBook.Views; public partial class SeatSelectionDialog : Window { private readonly Screening _screening; private readonly List _seats; private Seat? _selectedSeat; public int SelectedSeatId => _selectedSeat?.SeatID ?? 0; public int SelectedScreeningId => _screening.ScreeningID; public decimal TotalPrice => _screening.PricePerSeat; public string SeatDisplay => _selectedSeat?.Display ?? ""; public SeatSelectionDialog(Screening screening, List seats, User user) { InitializeComponent(); _screening = screening; _seats = seats; MovieInfoText.Text = screening.MovieTitle; ScreeningInfoText.Text = $"{screening.DateTimeDisplay} | {screening.Hall} | {screening.PriceDisplay} pro Sitz"; BuildSeatGrid(); UpdateSelection(); } private void BuildSeatGrid() { var rows = _seats.GroupBy(s => s.Row).OrderBy(g => g.Key); var panel = new StackPanel(); foreach (var row in rows) { var rowPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 2, 0, 2) }; rowPanel.Children.Add(new TextBlock { Text = row.Key, Width = 24, Foreground = Brushes.Gray, FontFamily = new FontFamily("Courier New"), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }); foreach (var seat in row.OrderBy(s => s.SeatNumber)) { var btn = new Button { Content = seat.SeatNumber.ToString(), Width = 34, Height = 30, Margin = new Thickness(2), FontFamily = new FontFamily("Courier New"), FontSize = 11, Tag = seat, IsEnabled = !seat.IsBooked, Background = seat.IsBooked ? new SolidColorBrush(Color.FromRgb(0x44, 0x22, 0x22)) : new SolidColorBrush(Color.FromRgb(0x1B, 0x4D, 0x2A)), Foreground = seat.IsBooked ? Brushes.DarkRed : Brushes.LightGreen, BorderBrush = seat.IsBooked ? new SolidColorBrush(Color.FromRgb(0x80, 0x20, 0x20)) : new SolidColorBrush(Color.FromRgb(0x27, 0xAE, 0x60)), BorderThickness = new Thickness(1), Cursor = seat.IsBooked ? System.Windows.Input.Cursors.No : System.Windows.Input.Cursors.Hand }; btn.ToolTip = $"Reihe {seat.Row}, Sitz {seat.SeatNumber} ({seat.Category})"; btn.Click += SeatClick; rowPanel.Children.Add(btn); } panel.Children.Add(rowPanel); } SeatsPanel.ItemsSource = new[] { new ContentControl { Content = panel } }; } private void SeatClick(object sender, RoutedEventArgs e) { if (sender is not Button btn || btn.Tag is not Seat seat) return; _selectedSeat = seat; UpdateSelection(); foreach (var child in FindVisualChildren