<Page
    x:Class="YJMPD_UWP.Views.GameView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:YJMPD_UWP.Views"
    xmlns:convert="using:YJMPD_UWP.Helpers.Converter"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <convert:BoolToVisibilityConverter x:Key="BoolToVisConverter" />
    </Page.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ScrollViewer Grid.Row="0">
            <StackPanel Style="{StaticResource BaseStackPanel}" >
                <StackPanel>
                    <TextBlock Text="Start a Game" Style="{StaticResource Header}" />
                    <Button Content="Start Game" Style="{StaticResource Green}" Click="StartGameButton_Click" IsEnabled="{Binding GameAvailable}" Visibility="{Binding StartGame, Converter={StaticResource BoolToVisConverter}}" />
                    <Button Content="Leave Game" Style="{StaticResource Red}" Click="StopGameButton_Click" Visibility="{Binding StopGame, Converter={StaticResource BoolToVisConverter}}" />
                </StackPanel>

                <StackPanel Visibility="{Binding StopGame, Converter={StaticResource BoolToVisConverter}}" Margin="0,10,0,0">
                    <TextBlock Text="Current players in game" Style="{StaticResource Header}" />

                    <TextBlock Text="{Binding PlayersCount}" />

                    <ListView x:Name="PlayersList" ItemsSource="{Binding Players}" SelectionMode="None" IsTapEnabled="False">
                        <ListView.ItemTemplate>
                            <DataTemplate x:Name="ListViewDataTemplate">
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Username}" />
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

                </StackPanel>
            </StackPanel>
        </ScrollViewer>

        <StackPanel Orientation="Horizontal" Grid.Row="1" Visibility="{Binding ServerAvailable, Converter={StaticResource BoolToVisConverter}}" Padding="20" Background="Gray">
            <ProgressRing Width="20" Height="20" IsActive="True" Margin="0,0,10,0" Foreground="White"/>
            <TextBlock Text="{Binding ServerMessage}" Foreground="White" />
        </StackPanel>
    </Grid>
</Page>
