<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 Icon="Play" 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="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="Door and wall electricity leaks use two clicks: choose the source cell, then the adjacent floor face."
                        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="Global Systems" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <TextBlock x:Name="GlobalText" Foreground="#CCD4DA" TextWrapping="Wrap" />

                    <TextBlock Text="Selected Cell" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <TextBlock x:Name="CellText" Foreground="#CCD4DA" TextWrapping="Wrap" />

                    <TextBlock Text="Editor Workflow" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <TextBlock x:Name="WorkflowText" Foreground="#CCD4DA" TextWrapping="Wrap" />

                    <TextBlock Text="Reactor Binding" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <TextBlock x:Name="ReactorBindingText" Foreground="#CCD4DA" TextWrapping="Wrap" />
                    <Grid ColumnSpacing="8" RowSpacing="8">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Button Content="Fuel" Click="BindFuel_Click" HorizontalAlignment="Stretch" />
                        <Button Grid.Column="1" Content="Coolant" Click="BindCoolant_Click" HorizontalAlignment="Stretch" />
                        <Button Grid.Column="2" Content="Electric" Click="BindElectricity_Click" HorizontalAlignment="Stretch" />
                    </Grid>

                    <TextBlock Text="Rule Events" FontSize="16" FontWeight="SemiBold" Foreground="#F4F1E8" />
                    <TextBlock x:Name="RuleEventText" Foreground="#CCD4DA" TextWrapping="Wrap" />
                    <Grid ColumnSpacing="8" RowSpacing="8">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Button Content="Warn Next Turn" Click="AddWarningRule_Click" HorizontalAlignment="Stretch" />
                        <Button Grid.Column="1" Content="Leak Next Turn" Click="AddLeakRule_Click" HorizontalAlignment="Stretch" />
                    </Grid>
                    <Button Content="Remove Last Rule" Click="RemoveLastRule_Click" HorizontalAlignment="Stretch" />

                    <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>
