<v:ChromelessWindow xmlns="https://github.com/avaloniaui"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:m="using:SourceGit.Models"
                    xmlns:vm="using:SourceGit.ViewModels"
                    xmlns:v="using:SourceGit.Views"
                    mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
                    x:Class="SourceGit.Views.Statistics"
                    x:DataType="vm:Statistics"
                    Title="{DynamicResource Text.Statistics}"
                    Width="800" Height="450"
                    WindowStartupLocation="CenterOwner"
                    CanResize="False">
  <Grid RowDefinitions="Auto,Auto,*">
    <!-- Title bar -->
    <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30">
      <Border Grid.Column="0" Grid.ColumnSpan="3"
              Background="{DynamicResource Brush.TitleBar}"
              BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
              PointerPressed="BeginMoveWindow"/>

      <Path Grid.Column="0"
            Width="14" Height="14"
            Margin="10,0,0,0"
            Data="{StaticResource Icons.Statistics}"
            IsVisible="{OnPlatform True, macOS=False}"/>

      <Grid Grid.Column="0" Classes="caption_button_box" Margin="2,4,0,0" IsVisible="{OnPlatform False, macOS=True}">
        <Button Classes="caption_button_macos" Click="CloseWindow">
          <Grid>
            <Ellipse Fill="{DynamicResource Brush.MacOS.Close}"/>
            <Path Height="6" Width="6" Stretch="Fill" Fill="#505050" Data="{StaticResource Icons.MacOS.Close}"/>
          </Grid>
        </Button>
      </Grid>

      <TextBlock Grid.Column="0" Grid.ColumnSpan="3"
                 Classes="bold"
                 Text="{DynamicResource Text.Statistics}"
                 HorizontalAlignment="Center" VerticalAlignment="Center"
                 IsHitTestVisible="False"/>

      <Button Grid.Column="2"
              Classes="caption_button"
              Click="CloseWindow"
              IsVisible="{OnPlatform True, macOS=False}">
        <Path Data="{StaticResource Icons.Window.Close}"/>
      </Button>
    </Grid>

    <!-- View mode switcher -->
    <ListBox Grid.Row="1"
             Margin="0,8"
             SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
             HorizontalAlignment="Center"
             VerticalAlignment="Center"
             Background="Transparent">
      <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
          <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
      </ListBox.ItemsPanel>

      <ListBox.Styles>
        <Style Selector="ListBoxItem">
          <Setter Property="Padding" Value="0"/>
          <Setter Property="Background" Value="Transparent"/>
        </Style>

        <Style Selector="ListBoxItem:pointerover /template/ ContentPresenter#PART_ContentPresenter">
          <Setter Property="Background" Value="Transparent"/>
        </Style>

        <Style Selector="ListBoxItem:selected /template/ ContentPresenter#PART_ContentPresenter">
          <Setter Property="Background" Value="Transparent"/>
        </Style>

        <Style Selector="ListBoxItem Border.switcher_bg">
          <Setter Property="BorderBrush" Value="{DynamicResource Brush.Border2}"/>
        </Style>

        <Style Selector="ListBoxItem:selected Border.switcher_bg">
          <Setter Property="Background" Value="{DynamicResource Brush.Accent}"/>
          <Setter Property="BorderBrush" Value="{DynamicResource Brush.Accent}"/>
        </Style>

        <Style Selector="TextBlock.view_mode_switcher">
          <Setter Property="FontWeight" Value="Bold"/>
          <Setter Property="Foreground" Value="{DynamicResource Brush.FG2}"/>
        </Style>

        <Style Selector="ListBoxItem:selected TextBlock.view_mode_switcher">
          <Setter Property="Foreground" Value="White"/>
        </Style>
      </ListBox.Styles>

      <ListBoxItem>
        <Border Classes="switcher_bg" Height="28" Padding="16,0" BorderThickness="1,1,0,1" CornerRadius="14,0,0,14">
          <TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.ThisYear}"/>
        </Border>
      </ListBoxItem>

      <ListBoxItem>
        <Border Classes="switcher_bg" Height="28" Padding="16,0" BorderThickness="1">
          <TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.ThisMonth}"/>
        </Border>
      </ListBoxItem>

      <ListBoxItem>
        <Border Classes="switcher_bg" Height="28" Padding="16,0" BorderThickness="0,1,1,1" CornerRadius="0,14,14,0">
          <TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.ThisWeek}"/>
        </Border>
      </ListBoxItem>
    </ListBox>

    <!-- Contents -->
    <ContentControl Grid.Row="2" Content="{Binding SelectedReport, Mode=OneWay}">
      <ContentControl.DataTemplates>
        <DataTemplate DataType="m:StatisticsReport">
          <Grid ColumnDefinitions="256,*" Margin="8,8,8,16">
            <Grid Grid.Column="0" RowDefinitions="*,16">
              <!-- Table By Committer -->
              <DataGrid Grid.Row="0"
                        ItemsSource="{Binding ByCommitter}"
                        SelectionMode="Single"
                        CanUserReorderColumns="False"
                        CanUserResizeColumns="False"
                        CanUserSortColumns="False"
                        HeadersVisibility="Column"
                        GridLinesVisibility="All"
                        BorderThickness="1"
                        BorderBrush="{DynamicResource Brush.Border2}"
                        Background="{DynamicResource Brush.Contents}"
                        HorizontalGridLinesBrush="{DynamicResource Brush.Border2}"
                        VerticalGridLinesBrush="{DynamicResource Brush.Border2}"
                        IsReadOnly="True"
                        RowHeight="26"
                        HorizontalScrollBarVisibility="Disabled"
                        VerticalScrollBarVisibility="Auto">
                <DataGrid.Styles>
                  <Style Selector="DataGridColumnHeader">
                    <Setter Property="Background" Value="{DynamicResource Brush.Window}"/>
                    <Setter Property="Padding" Value="8,0,0,0"/>
                    <Setter Property="BorderThickness" Value="0,0,0,1"/>
                    <Setter Property="BorderBrush" Value="{DynamicResource Brush.Border2}"/>
                    <Setter Property="SeparatorBrush" Value="{DynamicResource Brush.Border2}" />

                    <Style Selector="^:pointerover /template/ Grid#PART_ColumnHeaderRoot">
                      <Setter Property="Background" Value="{DynamicResource Brush.Window}"/>
                    </Style>

                    <Style Selector="^:pressed /template/ Grid#PART_ColumnHeaderRoot">
                      <Setter Property="Background" Value="{DynamicResource Brush.Window}"/>
                    </Style>
                  </Style>
                </DataGrid.Styles>
                
                <DataGrid.Columns>
                  <DataGridTextColumn Width="150" Header="{DynamicResource Text.Statistics.Committer}" Binding="{Binding Name}"/>
                  <DataGridTextColumn Width="*" Header="{DynamicResource Text.Statistics.CommitAmount}" Binding="{Binding Count}"/>
                </DataGrid.Columns>
              </DataGrid>

              <!-- Summary -->
              <Grid Grid.Row="1" ColumnDefinitions="*,*">
                <!-- Total Committers -->
                <StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Bottom">
                  <TextBlock Classes="monospace" Text="{DynamicResource Text.Statistics.TotalCommitters}" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
                  <TextBlock Classes="monospace" Text="{Binding ByCommitter.Count}" FontSize="11" Margin="4,0,0,0"/>
                </StackPanel>

                <!-- Total Commits -->
                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                  <TextBlock Classes="monospace" Text="{DynamicResource Text.Statistics.TotalCommits}" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
                  <TextBlock Classes="monospace" Text="{Binding Total}" FontSize="11" Margin="4,0,0,0"/>
                </StackPanel>
              </Grid>
            </Grid>

            <!-- Graph -->
            <v:Chart Grid.Column="1"
                     Margin="16,0,0,0"
                     LabelBrush="{DynamicResource Brush.FG1}"
                     LineBrush="{DynamicResource Brush.Border2}"
                     ShapeBrush="{DynamicResource Brush.Accent}"
                     Samples="{Binding Samples}"/>
          </Grid>
        </DataTemplate>
      </ContentControl.DataTemplates>
    </ContentControl>

    <!-- Loading Mask -->
    <v:LoadingIcon Grid.Row="2"
                   Width="48" Height="48"
                   HorizontalAlignment="Center" VerticalAlignment="Center"
                   IsVisible="{Binding IsLoading}"/>
  </Grid>
</v:ChromelessWindow>
