<Window
    x:Class="ReactorMaintenance.Win2D.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
    Title="Reactor Maintenance">
    <Grid Background="#16191D">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <CommandBar Grid.Row="0" DefaultLabelPosition="Right" Background="#20252A">
            <AppBarButton Icon="Add" Label="New" Click="New_Click" />
            <AppBarButton Icon="OpenFile" Label="Open" Click="Open_Click" />
            <AppBarButton Icon="Save" Label="Save" Click="Save_Click" />
            <AppBarSeparator />
            <AppBarButton x:Name="PlayPauseButton" Icon="Play" Label="Play" Click="PlayPause_Click" />
            <AppBarButton Icon="Forward" Label="End Turn" Click="EndTurn_Click" />
            <AppBarButton Label="Interact" Click="Interact_Click" />
            <AppBarButton Label="Heat Shield" Click="HeatShield_Click" />
            <AppBarButton Icon="Accept" Label="Activate" Click="Activate_Click" />
        </CommandBar>

        <Grid Grid.Row="1" ColumnSpacing="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="260" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="300" />
            </Grid.ColumnDefinitions>

            <ScrollViewer Grid.Column="0" Background="#1C2126">
                <StackPanel Padding="12" Spacing="10">
                    <TextBlock Text="Layer" FontSize="18" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ComboBox x:Name="LayerPicker"
                              SelectionChanged="LayerPicker_SelectionChanged"
                              HorizontalAlignment="Stretch" />
                    <TextBlock Text="Tools" FontSize="18" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="ToolPicker">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="2" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <ToggleButton IsChecked="{Binding IsSelected, Mode=TwoWay}"
                                              Checked="ToolToggle_Checked" ToolTipService.ToolTip="{Binding Label}"
                                              Width="112" MinHeight="46" Padding="6" Margin="0,0,8,8">
                                    <TextBlock Text="{Binding Label}" TextWrapping="WrapWholeWords"
                                               TextAlignment="Center"
                                               FontSize="12" />
                                </ToggleButton>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <TextBlock Text="Left click selects or paints. Right click clears surface prop and hazards."
                               Foreground="#9EA7AE" TextWrapping="Wrap" />
                    <TextBlock Text="Shift+left drag pans. Cursor drag moves the robot or a prop."
                               Foreground="#9EA7AE"
                               TextWrapping="Wrap" />
                </StackPanel>
            </ScrollViewer>

            <Grid Grid.Column="1" Background="#101215">
                <canvas:CanvasControl
                    x:Name="LevelCanvas"
                    ClearColor="#101215"
                    CreateResources="LevelCanvas_CreateResources"
                    Draw="LevelCanvas_Draw"
                    PointerPressed="LevelCanvas_PointerPressed"
                    PointerMoved="LevelCanvas_PointerMoved"
                    PointerReleased="LevelCanvas_PointerReleased"
                    PointerExited="LevelCanvas_PointerExited"
                    PointerWheelChanged="LevelCanvas_PointerWheelChanged" />
            </Grid>

            <ScrollViewer Grid.Column="2" Background="#1C2126">
                <StackPanel Padding="14" Spacing="12">
                    <TextBlock x:Name="LevelNameText" FontSize="20" FontWeight="SemiBold" Foreground="#F4F1E8"
                               TextWrapping="Wrap" />
                    <Grid ColumnSpacing="8">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <StackPanel>
                            <TextBlock Text="Turn" Foreground="#9EA7AE" />
                            <TextBlock x:Name="TurnText" FontSize="22" Foreground="#F4F1E8" />
                        </StackPanel>
                        <StackPanel Grid.Column="1">
                            <TextBlock Text="Status" Foreground="#9EA7AE" />
                            <TextBlock x:Name="StatusText" FontSize="16" Foreground="#F4F1E8" TextWrapping="Wrap" />
                        </StackPanel>
                    </Grid>

                    <TextBlock Text="Inventory" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="InventoryGrid">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid MinWidth="55" Margin="0,0,4,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" />
                                    <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="18" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock Text="Required" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="RequiredGrid">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="84" Margin="0,0,4,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11" />
                                    <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8"
                                               FontSize="18" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock x:Name="HoveredCellText" Text="Hovered Cell:" FontSize="16" FontWeight="SemiBold"
                               Foreground="#F4F1E8" />
                    <TextBlock x:Name="SelectedCellText" Text="Selected Cell:" FontSize="16" FontWeight="SemiBold"
                               Foreground="#F4F1E8" />
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Grid.Row="0" Text="Terrain" Foreground="#9EA7AE" FontSize="11" />
                        <TextBlock Grid.Column="0" Grid.Row="1" x:Name="TerrainText" Foreground="#F4F1E8" FontSize="16"
                                   Margin="0,0,10,0" />
                        <TextBlock Grid.Column="1" Grid.Row="0" Text="Prop" Foreground="#9EA7AE" FontSize="11" />
                        <TextBlock Grid.Column="1" Grid.Row="1" x:Name="PropText" Foreground="#F4F1E8" FontSize="16" />
                    </Grid>

                    <TextBlock Text="Consumers:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="ConsumersGrid">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="96" Margin="0,0,4,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11"
                                               TextWrapping="NoWrap" />
                                    <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="16" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock Text="Services:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="ServicesGrid">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="96" Margin="0,0,4,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11"
                                               TextWrapping="NoWrap" />
                                    <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="16" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock Text="Leaks:" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="LeaksGrid">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,0,4,0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{Binding Label}" Foreground="#F4F1E8" FontSize="16"
                                               Margin="0,0,10,0" />
                                    <TextBlock Grid.Column="1" Text="{Binding Value}" Foreground="#F4F1E8"
                                               FontSize="16" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock Text="Surface" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="SurfaceGrid">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="64" Margin="0,0,4,0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding Label}" Foreground="#9EA7AE" FontSize="11"
                                               TextWrapping="NoWrap" />
                                    <TextBlock Grid.Row="1" Text="{Binding Value}" Foreground="#F4F1E8" FontSize="16" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock Text="Network" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <Grid ColumnSpacing="6">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="64" />
                            <ColumnDefinition Width="60" />
                            <ColumnDefinition Width="34" />
                            <ColumnDefinition Width="34" />
                            <ColumnDefinition Width="34" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Carrier" Foreground="#9EA7AE" FontSize="11" />
                        <TextBlock Grid.Column="1" Text="State" Foreground="#9EA7AE" FontSize="11" />
                        <TextBlock Grid.Column="2" Text="Amt" Foreground="#9EA7AE" FontSize="11" />
                        <TextBlock Grid.Column="3" Text="Int" Foreground="#9EA7AE" FontSize="11" />
                        <TextBlock Grid.Column="4" Text="HP" Foreground="#9EA7AE" FontSize="11" />
                    </Grid>
                    <ItemsControl x:Name="NetworkGrid">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,0,0,8" ColumnSpacing="6">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="64" />
                                        <ColumnDefinition Width="60" />
                                        <ColumnDefinition Width="34" />
                                        <ColumnDefinition Width="34" />
                                        <ColumnDefinition Width="34" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{Binding Carrier}" Foreground="#F4F1E8" FontSize="12"
                                               TextWrapping="Wrap" />
                                    <TextBlock Grid.Column="1" Text="{Binding State}" Foreground="#9EA7AE"
                                               FontSize="12" TextWrapping="Wrap" />
                                    <TextBlock Grid.Column="2" Text="{Binding Amount}" Foreground="#F4F1E8"
                                               FontSize="12" />
                                    <TextBlock Grid.Column="3" Text="{Binding Intensity}" Foreground="#F4F1E8"
                                               FontSize="12" />
                                    <TextBlock Grid.Column="4" Text="{Binding Integrity}" Foreground="#F4F1E8"
                                               FontSize="12" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <TextBlock Text="Forecasts" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <ItemsControl x:Name="ForecastList">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="#46515A" BorderThickness="1" Padding="8" Margin="0,0,0,8"
                                        CornerRadius="3">
                                    <TextBlock Text="{Binding Message}" Foreground="#F4F1E8" TextWrapping="Wrap" />
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </Grid>
</Window>