<UserControl x:Class="Artemis.UI.Screens.Settings.Debug.Tabs.DataModelDebugView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Debug.Tabs"
             xmlns:s="https://github.com/canton7/Stylet"
             xmlns:wpf="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:dataModel="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800" 
             d:DataContext="{d:DesignInstance local:DataModelDebugViewModel}">
    <UserControl.Resources>
        <dataModel:TypeToStringConverter x:Key="TypeToStringConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Margin="0 0 0 5">
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="0.5*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="0.5*" />
            </Grid.ColumnDefinitions>
            <!-- Property searching (nyi) -->
            <wpf:PackIcon Grid.Column="0" Kind="Search" VerticalAlignment="Center" />
            <TextBox Grid.Row="0" Grid.Column="1" wpf:HintAssist.Hint="Search property" VerticalAlignment="Center" Margin="5 0" IsEnabled="False" />

            <!-- Module filtering -->
            <TextBlock Grid.Row="0" Grid.Column="3" VerticalAlignment="Center">Filter module</TextBlock>
            <ToggleButton Grid.Row="0"
                          Grid.Column="4"
                          VerticalAlignment="Center"
                          Margin="5 0"
                          Style="{StaticResource MaterialDesignSwitchToggleButton}"
                          IsChecked="{Binding IsModuleFilterEnabled}" />
            <ComboBox Grid.Row="0"
                      Grid.Column="5"
                      VerticalAlignment="Center"
                      wpf:HintAssist.Hint="Select a module"
                      IsEditable="True"
                      TextSearch.TextPath="DisplayName"
                      DisplayMemberPath="DisplayName"
                      Margin="5 0 0 0"
                      IsEnabled="{Binding IsModuleFilterEnabled}"
                      SelectedItem="{Binding SelectedModule}"
                      ItemsSource="{Binding Modules}" />

            <StackPanel Grid.Row="1"
                        Grid.Column="0"
                        Grid.ColumnSpan="2"
                        Orientation="Horizontal"
                        Margin="0 10 0 0"
                        ToolTip="Check to update values every half second instead of realtime">
                <TextBlock VerticalAlignment="Center">Slow updates</TextBlock>
                <ToggleButton VerticalAlignment="Center" Margin="5 0" Style="{StaticResource MaterialDesignSwitchToggleButton}" IsChecked="{Binding SlowUpdates}" />
            </StackPanel>

        </Grid>
        <TreeView Grid.Row="1" 
                  ItemsSource="{Binding MainDataModel.Children}"
                  HorizontalContentAlignment="Stretch"
                  VirtualizingStackPanel.IsVirtualizing="True">
            <TreeView.Resources>
                <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource MaterialDesignTreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsVisualizationExpanded, Mode=TwoWay}" />
                </Style>

                <HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelPropertiesViewModel}" ItemsSource="{Binding Children}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
                            <Run>[</Run><Run Text="{Binding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" /><Run>]</Run>
                        </TextBlock>
                        <TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
                        <TextBlock Grid.Column="2"
                                   Text="{Binding DisplayValue}"
                                   FontFamily="Consolas"
                                   HorizontalAlignment="Right" />
                    </Grid>

                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListViewModel}" ItemsSource="{Binding ListChildren}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
                            <Run>[</Run><Run Text="{Binding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" /><Run>]</Run>
                        </TextBlock>
                        <TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
                        <TextBlock Grid.Column="2"
                                   Text="{Binding CountDisplay, Mode=OneWay}"
                                   FontFamily="Consolas"
                                   HorizontalAlignment="Right" />
                    </Grid>
                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelPropertyViewModel}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <!-- Value description -->
                        <TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
                            <Run>[</Run><Run Text="{Binding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" /><Run>]</Run>
                        </TextBlock>
                        <TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />

                        <!-- Value display -->
                        <ContentControl Grid.Column="2" s:View.Model="{Binding DisplayViewModel}" FontFamily="Consolas" />
                    </Grid>
                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertyViewModel}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <!-- Value description -->
                        <TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
                            <Run>[</Run><Run Text="{Binding ListType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" /><Run>]</Run>
                        </TextBlock>
                        <TextBlock Grid.Column="1" ToolTip="{Binding PropertyDescription.Description}">
                            <Run>List item [</Run><Run Text="{Binding Index, Mode=OneWay}" /><Run>]</Run>
                        </TextBlock>

                        <!-- Value display -->
                        <ContentControl Grid.Column="2" s:View.Model="{Binding DisplayViewModel}" FontFamily="Consolas" />
                    </Grid>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelEventViewModel}" ItemsSource="{Binding Children}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Margin="0 0 5 0" FontWeight="Bold">
                            <Run>[</Run><Run Text="{Binding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" /><Run>]</Run>
                        </TextBlock>
                        <TextBlock Grid.Column="1" Text="{Binding PropertyDescription.Name}" ToolTip="{Binding PropertyDescription.Description}" />
                        <TextBlock Grid.Column="2"
                                   Text="{Binding CountDisplay, Mode=OneWay}"
                                   FontFamily="Consolas"
                                   HorizontalAlignment="Right" />
                    </Grid>
                </HierarchicalDataTemplate>

                <HierarchicalDataTemplate DataType="{x:Type dataModel:DataModelListPropertiesViewModel}" ItemsSource="{Binding DisplayViewModel.Children}">
                    <TextBlock>
                        <Run>List item [</Run><Run Text="{Binding Index, Mode=OneWay}" /><Run>]</Run>
                    </TextBlock>
                </HierarchicalDataTemplate>
            </TreeView.Resources>
        </TreeView>
    </Grid>
</UserControl>