<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:VeloeMinecraftLauncher.ViewModels"
		xmlns:m="using:VeloeMinecraftLauncher.Models"
		xmlns:entity="using:VeloeMinecraftLauncher.Models.Entity"
		xmlns:utils="using:VeloeMinecraftLauncher.Utils"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		xmlns:titlebars="using:VeloeMinecraftLauncher.Views.TitleBar"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
		Width="800" Height="450"
		MaxWidth="800" MaxHeight="450"
        x:Class="VeloeMinecraftLauncher.Views.MainWindow"
        Icon="/Assets/avalonia-logo.ico"
        Title="VeloeMinecraftLauncher"
		TransparencyLevelHint="AcrylicBlur"
		Background="Black"
		CanResize="False"
		ExtendClientAreaToDecorationsHint="True"
		ExtendClientAreaChromeHints="NoChrome"
		ExtendClientAreaTitleBarHeightHint="-1"
		Closing="MainWindow_Closing">

	<Window.Background>
		<ImageBrush
				Source="avares://VeloeMinecraftLauncher/Assets/background.png"
				Stretch="Fill"
				Opacity="0.9"
				/>
	</Window.Background>
	
    <Design.DataContext>
        <vm:MainWindowViewModel/>
    </Design.DataContext>
	
	<Panel>
		<DockPanel>			
			<titlebars:TitleBarWindow
			  IsSeamless="False"
			  IsIconVisible="False"
			  IsMaximizeVisible="False"
			  TitleText="Veloe Minecraft Launcher"
			  DockPanel.Dock="Top"
			  ZIndex="997">
			</titlebars:TitleBarWindow>

			<Grid DockPanel.Dock="Left">
				<Grid.RowDefinitions>
					<RowDefinition Height="0"></RowDefinition>
					<RowDefinition Height="*"></RowDefinition>
					<RowDefinition Height="40" ></RowDefinition>
					<RowDefinition Height="0"></RowDefinition>
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="*"></ColumnDefinition>
				</Grid.ColumnDefinitions>
				<Button
					ZIndex="999"
					Grid.Row="1"
					HorizontalAlignment="Right"
					VerticalAlignment="Top"
					Command="{Binding DownloadUpdate}"
					IsVisible="{Binding IsUpdateAvailable}">
					Update Available
				</Button>
				<TextBlock
					ZIndex="998"
					Grid.Row="1"
					HorizontalAlignment="Right"
					VerticalAlignment="Bottom"
					Text="{Binding StartButtonOutput}"
					Margin="5">
				</TextBlock>
				<TabControl
					Grid.Row="1"
					HorizontalAlignment="Stretch">
					<TabItem
						Header="Servers"
						VerticalContentAlignment="Center">
						<ItemsControl 
							ItemsSource="{Binding ServerPanels}">
							<ItemsControl.ItemsPanel>
								<ItemsPanelTemplate>
									<UniformGrid Columns="5" Rows="4"/>
								</ItemsPanelTemplate>
							</ItemsControl.ItemsPanel>
							<ItemsControl.ItemTemplate>
								<DataTemplate DataType="m:ServerPanelModel">
									<Panel
										VerticalAlignment="Top"
										HorizontalAlignment="Stretch"
										Height="75"
										Width="150"
										Margin="0 0 10 10">
										<Border
											Background="Black"
											Opacity="0.2"
											CornerRadius="15"/>
										<ToolTip.Tip>
											<TextBlock 
												Text="{Binding Tip}"
												TextWrapping="Wrap"/>
										</ToolTip.Tip>
										<UniformGrid
											Columns="1"
											Rows="2"
											VerticalAlignment="Center"
											HorizontalAlignment="Center">
											<TextBlock
												VerticalAlignment="Center"
												HorizontalAlignment="Center"
												Text="{Binding Status}"/>
											<TextBlock
												VerticalAlignment="Center"
												HorizontalAlignment="Center"
												FontSize="20"
												Text="{Binding Players}"/>
										</UniformGrid>
									</Panel>
								</DataTemplate>
							</ItemsControl.ItemTemplate>			
						</ItemsControl>
					</TabItem>
					<TabItem>
						<TabItem.Header>
							<TextBlock VerticalAlignment="Center">Console</TextBlock>
						</TabItem.Header>
						<Panel
							VerticalAlignment="Stretch"
							HorizontalAlignment="Stretch"								
							Margin="0 0 0 5">
							<Border Background="Black" Opacity="0.2" CornerRadius="5" />
							<ScrollViewer
								Name="ConsoleScroll"
								HorizontalScrollBarVisibility="Auto"
								VerticalAlignment="Stretch"
								HorizontalAlignment="Stretch">
								<TextBlock
									Text="{Binding ConsoleText}"
									VerticalAlignment="Stretch"
									Width="760"
									Margin="5,5,5,5"
									TextWrapping="Wrap"
									ScrollViewer.VerticalScrollBarVisibility="Visible"
									MaxLines="99999">
								</TextBlock>
							</ScrollViewer>
						</Panel>
					</TabItem>
					<TabItem>
						<TabItem.Header>
							<TextBlock VerticalAlignment="Center">Changelog</TextBlock>
						</TabItem.Header>
						<Panel
							VerticalAlignment="Stretch"
							HorizontalAlignment="Stretch"
							Margin="0 0 0 5">
							<Border Background="Black" Opacity="0.2" CornerRadius="5" />
							<ScrollViewer
								HorizontalScrollBarVisibility="Auto"
								VerticalAlignment="Stretch"
								HorizontalAlignment="Stretch">
								<ItemsControl ItemsSource="{Binding Changelogs}">
									<ItemsControl.ItemsPanel>
										<ItemsPanelTemplate>
											<StackPanel
												Width="760"
												Margin="5,5,5,5"/>
										</ItemsPanelTemplate>
									</ItemsControl.ItemsPanel>
									<ItemsControl.ItemTemplate>
										<utils:ChangelogDataTemplate>
											<DataTemplate DataType="entity:Changelog" x:Key="True">
												<TextBlock 
													Text="{Binding Text}"
													VerticalAlignment="Stretch"
													TextWrapping="Wrap"/>
											</DataTemplate>
											<DataTemplate DataType="entity:Changelog" x:Key="False">
												<StackPanel>
													<TextBlock
														Text="{Binding Title}"
														VerticalAlignment="Stretch"
														TextWrapping="Wrap"
														FontSize="16"/>
													<TextBlock 
														Text="{Binding Text}"
														VerticalAlignment="Stretch"
														TextWrapping="Wrap"/>
												</StackPanel>
											</DataTemplate>
										</utils:ChangelogDataTemplate>
									</ItemsControl.ItemTemplate>
								</ItemsControl>
							</ScrollViewer>
						</Panel>
					</TabItem>
				</TabControl>
				<StackPanel
					Grid.Row="2"
					Orientation="Horizontal"
					HorizontalAlignment="Center">
					<Button
						Content="{Binding DownloadButton}"
						Command="{Binding OnClickCommand}">
					</Button>
					<Button
						Content="{Binding SettingsButton}"
						Command="{Binding OpenSettings}">
					</Button>
					<TextBlock
						Margin="3">
					</TextBlock>
					<ComboBox
						ItemsSource="{Binding DownloadedVersions}"
						PlaceholderText="Select version"
						SelectedItem="Binding DownloadedVersion"
						SelectedIndex="{Binding DownloadedIndex}"
						Width="220"
						VerticalAlignment="Center"
						HorizontalAlignment="Center">
					</ComboBox>
					<TextBlock
						Margin="3">
					</TextBlock>
					<TextBox
						Text="{Binding Username}"
						Watermark="Username"
						MinWidth="190"
						MaxWidth="220"
						VerticalAlignment="Center"
						HorizontalAlignment="Center">
						<TextBox.Styles>
							<Style Selector="DataValidationErrors">
								<Setter Property="Template">
									<ControlTemplate>
										<DockPanel LastChildFill="True" MaxWidth="220">
											<ContentControl DockPanel.Dock="Right"
															ContentTemplate="{TemplateBinding ErrorTemplate}"
															DataContext="{TemplateBinding Owner}"
															Content="{Binding (DataValidationErrors.Errors)}"
															IsVisible="{Binding (DataValidationErrors.HasErrors)}"/>
											<ContentPresenter Name="PART_ContentPresenter"
															  Background="{TemplateBinding Background}"
															  BorderBrush="{TemplateBinding BorderBrush}"
															  BorderThickness="{TemplateBinding BorderThickness}"
															  CornerRadius="{TemplateBinding CornerRadius}"
															  ContentTemplate="{TemplateBinding ContentTemplate}"
															  Content="{TemplateBinding Content}"
															  Padding="{TemplateBinding Padding}"/>
										</DockPanel>
									</ControlTemplate>
								</Setter>
								<Setter Property="ErrorTemplate">
									<DataTemplate>
										<Canvas Width="14" Height="14" Margin="4 0 1 0"
												Background="Transparent">
											<Path Data="M14,7 A7,7 0 0,0 0,7 M0,7 A7,7 0 1,0 14,7 M7,3l0,5 M7,9l0,2"
												  Stroke="Yellow"
												  StrokeThickness="2"/>
										</Canvas>
									</DataTemplate>
								</Setter>
							</Style>
						</TextBox.Styles>
					</TextBox>
					<TextBlock
						Margin="3">
					</TextBlock>
					<Button
						Content="{Binding StartButton}"
						Command="{Binding StartMinecraft}"
						IsEnabled="{Binding IsStartButtonEnabled}">
					</Button>
				</StackPanel>
				<StackPanel Orientation="Horizontal" Grid.Row="2">
					<TextBox Text="{Binding ArgumentsBox}" TextWrapping="Wrap" Width="680" Height="200" IsVisible="false"></TextBox>
					<Button Content="{Binding StartButton}" Command="{Binding StartMinecraftCustom}" IsVisible="false"></Button>
				</StackPanel>
			</Grid>
		</DockPanel>
	</Panel>	
</Window>
