<Window x:Class="Ehwrj.App.MainWindow"
        xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:rendering="using:Ehwrj.App.Rendering"
        Title="Ehwrj"
        Width="1280"
        Height="780"
        MinWidth="980"
        MinHeight="640"
        Background="#0B0F14"
        WindowStartupLocation="CenterScreen">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="320" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Border Grid.Column="0" Background="#121A22" Padding="24">
      <ScrollViewer VerticalScrollBarVisibility="Auto">
        <StackPanel>
          <TextBlock Text="Ehwrj" FontSize="32" FontWeight="SemiBold" />
          <TextBlock Text="{Binding Ui.Subtitle}" Foreground="#93A4B3" Margin="0,4,0,18" />

          <TextBlock Text="{Binding Ui.Language}" FontSize="13" Foreground="#93A4B3" />
          <ComboBox ItemsSource="{Binding LanguageOptions}"
                    SelectedItem="{Binding SelectedLanguageOption}"
                    Margin="0,4,0,20">
            <ComboBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding DisplayName}" />
              </DataTemplate>
            </ComboBox.ItemTemplate>
          </ComboBox>

          <StackPanel Orientation="Horizontal" Margin="0,0,0,20">
            <Button Content="{Binding Ui.Start}" Command="{Binding StartCommand}" Margin="0,0,8,0" />
            <Button Content="{Binding Ui.Stop}" Classes="secondary" Command="{Binding StopCommand}" />
          </StackPanel>

          <TextBlock Text="{Binding Ui.Connection}" FontSize="13" Foreground="#93A4B3" />
          <TextBlock Text="{Binding Status}" TextWrapping="Wrap" Margin="0,4,0,18" />

          <Expander Header="{Binding Ui.Diagnostics}" IsExpanded="False" Margin="0,0,0,6">
            <ItemsControl ItemsSource="{Binding EndpointHealthEntries}">
              <ItemsControl.ItemTemplate>
                <DataTemplate>
                  <TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="#C9D3DD" FontSize="12" Margin="0,0,0,6" />
                </DataTemplate>
              </ItemsControl.ItemTemplate>
            </ItemsControl>
          </Expander>

          <Expander Header="{Binding Ui.Map}" IsExpanded="True" Margin="0,0,0,6">
            <StackPanel>
              <CheckBox Content="{Binding Ui.ShowLabels}" IsChecked="{Binding Settings.Map.ShowLabels}" />
              <CheckBox Content="{Binding Ui.ShowAircraftMach}" IsChecked="{Binding Settings.Map.ShowAircraftMach}" />
              <CheckBox Content="{Binding Ui.FollowPlayer}" IsChecked="{Binding Settings.Map.FollowPlayer}" />
              <CheckBox Content="{Binding Ui.RotateWithPlayer}" IsChecked="{Binding Settings.Map.RotateWithPlayer}" />
              <CheckBox Content="{Binding Ui.ShowRangeRings}" IsChecked="{Binding Settings.Map.ShowRangeRings}" />
              <CheckBox Content="{Binding Ui.ShowBattleLog}" IsChecked="{Binding Settings.Map.ShowBattleLog}" />
              <CheckBox Content="{Binding Ui.DeliveryTracker}" IsChecked="{Binding Settings.Map.ShowDeliveryTracker}" />

              <TextBlock Text="{Binding Ui.DeliveryTrackerAngle}" Foreground="#93A4B3" />
              <Slider Minimum="0.1" Maximum="1" Value="{Binding Settings.Map.DeliveryTrackerAngle}" />
            </StackPanel>
          </Expander>

          <CheckBox Content="{Binding Ui.ShowOverlay}" IsChecked="{Binding IsOverlayEnabled}" />
          <CheckBox Content="{Binding Ui.ShowMinimap}" IsChecked="{Binding Settings.Overlay.ShowMiniMap}" />
          <CheckBox Content="{Binding Ui.ShowMachLabels}" IsChecked="{Binding Settings.Overlay.ShowMach}" />
          <CheckBox Content="{Binding Ui.ShowSpotRadar}" IsChecked="{Binding Settings.Overlay.ShowSpotRadar}" />

          <TextBlock Text="{Binding Ui.OverlaySize}" Foreground="#93A4B3" />
          <Slider Minimum="160" Maximum="2000" Value="{Binding Settings.Overlay.Size}" />

          <TextBlock Text="{Binding Ui.TopOffset}" Foreground="#93A4B3" />
          <Slider Minimum="0" Maximum="500" Value="{Binding Settings.Overlay.Top}" />

          <TextBlock Text="{Binding Ui.RightOffset}" Foreground="#93A4B3" />
          <Slider Minimum="0" Maximum="2000" Value="{Binding Settings.Overlay.Right}" />

          <TextBlock Text="{Binding Ui.Zoom}" Foreground="#93A4B3" />
          <Slider Minimum="25" Maximum="400" Value="{Binding Settings.Overlay.ZoomPercent}" />

          <Expander Header="{Binding Ui.Minimap}" IsExpanded="True" Margin="0,6,0,0">
            <StackPanel>
              <TextBlock Text="{Binding Ui.AircraftScale}" Foreground="#93A4B3" />
              <Slider Minimum="50" Maximum="200" Value="{Binding Settings.Overlay.MiniMapAircraftScale}" />

              <TextBlock Text="{Binding Ui.MinimumMach}" Foreground="#93A4B3" />
              <Slider Minimum="0" Maximum="2" TickFrequency="0.1" Value="{Binding Settings.Overlay.MiniMapMinimumMach}" />
            </StackPanel>
          </Expander>

          <Expander Header="{Binding Ui.SpotRadar}" IsExpanded="True" Margin="0,4,0,0">
            <StackPanel>
              <CheckBox Content="{Binding Ui.ShowDistance}" IsChecked="{Binding Settings.Overlay.SpotShowDistance}" />
              <CheckBox Content="{Binding Ui.ShowMach}" IsChecked="{Binding Settings.Overlay.SpotShowMach}" />
              <CheckBox Content="{Binding Ui.ShowClosureSpeed}" IsChecked="{Binding Settings.Overlay.SpotShowRelativeSpeed}" />

              <TextBlock Text="{Binding Ui.RadarRangeKm}" Foreground="#93A4B3" />
              <Slider Minimum="0" Maximum="30" Value="{Binding Settings.Overlay.SpotDetectDistanceKm}" />

              <TextBlock Text="{Binding Ui.RadarSpread}" Foreground="#93A4B3" />
              <Slider Minimum="40" Maximum="600" Value="{Binding Settings.Overlay.SpotDistance}" />

              <TextBlock Text="{Binding Ui.MinimumMach}" Foreground="#93A4B3" />
              <Slider Minimum="0" Maximum="2" TickFrequency="0.1" Value="{Binding Settings.Overlay.SpotMinimumMach}" />

              <TextBlock Text="{Binding Ui.MarkerOpacity}" Foreground="#93A4B3" />
              <Slider Minimum="0" Maximum="100" Value="{Binding Settings.Overlay.SpotOpacity}" />

              <TextBlock Text="{Binding Ui.FontOpacity}" Foreground="#93A4B3" />
              <Slider Minimum="0" Maximum="100" Value="{Binding Settings.Overlay.SpotFontOpacity}" />

              <TextBlock Text="{Binding Ui.VerticalScale}" Foreground="#93A4B3" />
              <Slider Minimum="40" Maximum="140" Value="{Binding Settings.Overlay.SpotVerticalScale}" />

              <TextBlock Text="{Binding Ui.VerticalOffset}" Foreground="#93A4B3" />
              <Slider Minimum="-500" Maximum="500" Value="{Binding Settings.Overlay.SpotVerticalOffset}" />

              <TextBlock Text="{Binding Ui.ArrowScale}" Foreground="#93A4B3" />
              <Slider Minimum="50" Maximum="200" Value="{Binding Settings.Overlay.SpotArrowScale}" />

              <TextBlock Text="{Binding Ui.ArrowOutline}" Foreground="#93A4B3" />
              <Slider Minimum="0" Maximum="10" Value="{Binding Settings.Overlay.SpotOutlineWidth}" />

              <TextBlock Text="{Binding Ui.DistanceFontSize}" Foreground="#93A4B3" />
              <Slider Minimum="10" Maximum="60" Value="{Binding Settings.Overlay.DistanceFontSize}" />

              <TextBlock Text="{Binding Ui.MachFontSize}" Foreground="#93A4B3" />
              <Slider Minimum="10" Maximum="60" Value="{Binding Settings.Overlay.MachFontSize}" />

              <TextBlock Text="{Binding Ui.ClosureFontSize}" Foreground="#93A4B3" />
              <Slider Minimum="10" Maximum="60" Value="{Binding Settings.Overlay.RelativeFontSize}" />

              <TextBlock Text="{Binding Ui.ArrowColor}" Foreground="#93A4B3" />
              <TextBox Text="{Binding Settings.Overlay.SpotArrowColor}" Watermark="#ff1e1e" Margin="0,4,0,10" />

              <TextBlock Text="{Binding Ui.DistanceColor}" Foreground="#93A4B3" />
              <TextBox Text="{Binding Settings.Overlay.DistanceTextColor}" Watermark="#ff1e1e" Margin="0,4,0,10" />

              <TextBlock Text="{Binding Ui.MachColor}" Foreground="#93A4B3" />
              <TextBox Text="{Binding Settings.Overlay.MachTextColor}" Watermark="#57c7f2" Margin="0,4,0,10" />

              <TextBlock Text="{Binding Ui.ClosureColor}" Foreground="#93A4B3" />
              <TextBox Text="{Binding Settings.Overlay.RelativeTextColor}" Watermark="#19f24f" Margin="0,4,0,10" />
            </StackPanel>
          </Expander>

          <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
            <Button Content="{Binding Ui.Save}" Command="{Binding SaveCommand}" Margin="0,0,8,0" />
            <Button Content="{Binding Ui.Reset}" Classes="secondary" Command="{Binding ResetSettingsCommand}" />
          </StackPanel>
        </StackPanel>
      </ScrollViewer>
    </Border>

    <Grid Grid.Column="1" Margin="24">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Grid Grid.Row="0" Margin="0,0,0,18">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <StackPanel>
          <TextBlock Text="{Binding Ui.LiveMap}" FontSize="24" FontWeight="SemiBold" />
          <TextBlock Text="{Binding Ui.LocalApiScope}" Foreground="#93A4B3" />
          <TextBlock Text="{Binding PlayerInfo}" Foreground="#C9D3DD" Margin="0,6,0,0" />
        </StackPanel>
        <StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Bottom" Spacing="16">
          <TextBlock Text="{Binding AllySummary}" Foreground="#4CC9A7" />
          <TextBlock Text="{Binding EnemySummary}" Foreground="#FF5252" />
          <TextBlock Text="{Binding BattleTimerText}" Foreground="#F6C85F" />
          <TextBlock Text="{Binding SnapshotSummary}" Foreground="#93A4B3" />
        </StackPanel>
      </Grid>

      <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="280" />
        </Grid.ColumnDefinitions>

        <Border Grid.Column="0" Background="#071014" ClipToBounds="True">
          <rendering:MapCanvas Snapshot="{Binding Snapshot}"
                               MapSettings="{Binding Settings.Map}"
                               OverlaySettings="{Binding Settings.Overlay}"
                               Ui="{Binding Ui}" />
        </Border>

        <Border Grid.Column="1" Background="#121A22" Padding="16" Margin="18,0,0,0" IsVisible="{Binding Settings.Map.ShowBattleLog}">
          <Grid>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Text="{Binding Ui.BattleLog}" FontSize="16" FontWeight="SemiBold" Margin="0,0,0,12" />
            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
              <ItemsControl ItemsSource="{Binding BattleLogEntries}">
                <ItemsControl.ItemTemplate>
                  <DataTemplate>
                    <TextBlock Text="{Binding}" TextWrapping="Wrap" Foreground="#C9D3DD" Margin="0,0,0,8" />
                  </DataTemplate>
                </ItemsControl.ItemTemplate>
              </ItemsControl>
            </ScrollViewer>
          </Grid>
        </Border>
      </Grid>

      <Grid Grid.Row="2" Margin="0,18,0,0">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <TextBlock Text="{Binding ProcessStatus}" Foreground="#93A4B3" />
        <TextBlock Grid.Column="1" Text="{Binding LastUpdatedText}" Foreground="#93A4B3" />
      </Grid>
    </Grid>
  </Grid>
</Window>
