<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="Jellyfin2Samsung.Views.MainWindow"
		x:DataType="viewModels:MainWindowViewModel"
        xmlns:viewModels="clr-namespace:Jellyfin2Samsung.ViewModels"
		xmlns:helpers="clr-namespace:Jellyfin2Samsung.Helpers.Converters"
		xmlns:fa="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
        Width="580"
        Height="410"
        WindowStartupLocation="CenterScreen"
        Title="Jellyfin2Samsung">
	<Window.Resources>
		<helpers:TvLogStatusToBrushConverter x:Key="TvLogStatusToBrushConverter"/>
		<helpers:StringEqualsConverter x:Key="StringEquals"/>
		<helpers:StringNotEqualsConverter x:Key="StringNotEquals"/>
	</Window.Resources>

	<Window.Styles>
		<StyleInclude Source="avares://Avalonia.Themes.Fluent/FluentTheme.xaml"/>
		<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
		<StyleInclude Source="avares://Jellyfin2Samsung/Styles/Buttons.axaml"/>
		<StyleInclude Source="avares://Jellyfin2Samsung/Styles/TextBlocks.axaml"/>
		<StyleInclude Source="avares://Jellyfin2Samsung/Styles/ComboBoxes.axaml"/>
	</Window.Styles>

	<Border Background="{DynamicResource CardBackgroundFillColorDefaultBrush}"
        Padding="16"
        CornerRadius="8"
        Margin="6"
        BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}"
        BorderThickness="1">

		<Border.Effect>
			<DropShadowEffect BlurRadius="15" OffsetX="2" OffsetY="2" Color="#00000020" Opacity="0.15"/>
		</Border.Effect>

		<StackPanel Spacing="14">
			<Border Background="#2C3E50"
                    Padding="24,20"
                    CornerRadius="8">
				<StackPanel Spacing="12" HorizontalAlignment="Center">
					<TextBlock
                               Text="Jellyfin Installer for Samsung (Tizen)"
								HorizontalAlignment="Center"
								Foreground="White"
								FontWeight="Medium"/>
				</StackPanel>
			</Border>

			<!-- Form fields - side by side layout -->
			<StackPanel Spacing="18">

				<!-- Release -->
				<Grid ColumnDefinitions="100,*,Auto" ColumnSpacing="8">
					<TextBlock Classes="label"
							   Text="{Binding LblRelease}"
							   VerticalAlignment="Center"
							   Grid.Column="0"/>
					<ComboBox Classes="clean"
							  SelectedItem="{Binding SelectedRelease}"
							  Grid.Column="1"
							  HorizontalAlignment="Stretch"
							  ItemsSource="{Binding Releases}">
						<ComboBox.ItemTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Name}"/>
							</DataTemplate>
						</ComboBox.ItemTemplate>
					</ComboBox>
					<!-- Spacer removed -->
				</Grid>

				<!-- Version -->
				<Grid ColumnDefinitions="100,*,40" ColumnSpacing="8" IsVisible="{Binding SelectedRelease, Converter={StaticResource StringNotEquals}, ConverterParameter=Custom WGT File}">
					<TextBlock Classes="label"
							   Text="{Binding LblVersion}"
							   VerticalAlignment="Center"
							   Grid.Column="0"/>

					<ComboBox Classes="clean"
							  Grid.Column="1"
							  HorizontalAlignment="Stretch"
							  ItemsSource="{Binding AvailableAssets}"
							  SelectedItem="{Binding SelectedAsset, Mode=TwoWay}">
						<ComboBox.ItemTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding DisplayText}"/>
							</DataTemplate>
						</ComboBox.ItemTemplate>
					</ComboBox>

					
					<Button Classes="icon" Grid.Column="2" Command="{Binding ShowBuildInfoCommand}">
						<fa:SymbolIcon Symbol="Help" Width="20" Height="20"/>
					</Button>
				</Grid>
				<!-- Custom WGT File -->
				<Grid ColumnDefinitions="100,*,40" ColumnSpacing="8" IsVisible="{Binding SelectedRelease, Converter={StaticResource StringEquals}, ConverterParameter=Custom WGT File, FallbackValue=False}">
					<TextBlock Classes="label"
							   Text="{Binding lblCustomWgt}"
							   VerticalAlignment="Center"
							   Grid.Column="0"/>

					<TextBox Grid.Column="1"
								Classes="clean"
								Text="{Binding CustomWgtPath, Mode=TwoWay}"
								IsReadOnly="True"
								HorizontalAlignment="Stretch"
								Watermark="{Binding SelectWGT}"/>

					<!-- Info Button -->
					<Button Grid.Column="2"
                                Classes="icon"
                                Command="{Binding BrowseWgtCommand}">
						<fa:SymbolIcon Symbol="Folder" Width="20" Height="20"/>
					</Button>
				</Grid>

				<!-- TV Selection -->
				<Grid ColumnDefinitions="100,*,40" ColumnSpacing="8">
					<TextBlock Classes="label"
							   Text="{Binding LblSelectTv}"
							   VerticalAlignment="Center"
							   Grid.Column="0"/>
					<ComboBox Classes="clean"
							  Grid.Column="1"
							  HorizontalAlignment="Stretch"
							  ItemsSource="{Binding AvailableDevices}"
							  SelectedItem="{Binding SelectedDevice, Mode=TwoWay}">
						<ComboBox.ItemTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding DisplayText}"/>
							</DataTemplate>
						</ComboBox.ItemTemplate>
					</ComboBox>
					<Button Classes="icon" Grid.Column="2" Command="{Binding RefreshDevicesCommand}">
						<fa:SymbolIcon Symbol="Refresh" Width="20" Height="20"/>
					</Button>
				</Grid>

			</StackPanel>

			<!-- Status - Clean and simple -->
			<Border Background="#2C3E50"
                    Padding="16"
                    CornerRadius="6">
				<TextBlock Text="{Binding StatusBar}"
                           HorizontalAlignment="Center"
                           Foreground="White"
                           FontWeight="Medium"/>
			</Border>

			<!-- Action Buttons -->
			<StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Center"
                        Spacing="12">
				<Button Classes="primary"
                        Content="{Binding DownloadAndInstall}"
						Command="{Binding DownloadAndInstallCommand} "/>
				<Button Classes="icon" Command="{Binding OpenSettingsCommand}">
					<fa:SymbolIcon Symbol="Settings"  Width="20" Height="20"/>
				</Button>
				<ToggleButton IsChecked="{Binding DarkMode}"
							  Classes="primary"
							  Background="Transparent"
							  BorderThickness="0"
							  Width="40"
							  Height="40"
							  CornerRadius="20"
							  Padding="0">
					<ToggleButton.Styles>
						<Style Selector="ToggleButton:checked">
							<Setter Property="Background" Value="Transparent"/>
						</Style>
						<Style Selector="ToggleButton:pointerover">
							<Setter Property="Background" Value="{DynamicResource SystemControlBackgroundBaseLowBrush}"/>
						</Style>
					</ToggleButton.Styles>
					<Panel>
						<TextBlock Text="&#x2600;" FontSize="18" IsVisible="{Binding DarkMode}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
						<TextBlock Text="&#x1F319;" FontSize="16" IsVisible="{Binding !DarkMode}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
					</Panel>
				</ToggleButton>
				<Button Classes="icon"
						IsVisible="{Binding IsSamsungLoginActive}"
						Command="{Binding CancelSamsungLoginCommand}">
					<fa:SymbolIcon Symbol="Cancel"
								   Width="20"
								   Height="20"/>
				</Button>
			</StackPanel>

			<!-- Clean footer -->
			<TextBlock HorizontalAlignment="Center"
                       FontSize="11"
                       Opacity="0.6"
                       Text="{Binding FooterText}"/>

		</StackPanel>
	</Border>
</Window>