<UserControl 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:dataModel="clr-namespace:Artemis.UI.Shared.DataModelVisualization.Shared;assembly=Artemis.UI.Shared"
             xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
             xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
             xmlns:local="clr-namespace:Artemis.UI.Screens.Debugger.DataModel"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:DataType="local:DataModelDebugViewModel"
             x:Class="Artemis.UI.Screens.Debugger.DataModel.DataModelDebugView">
    <UserControl.Resources>
        <converters:TypeToStringConverter x:Key="TypeToStringConverter" />
    </UserControl.Resources>
    <Grid RowDefinitions="Auto,*">
        <StackPanel Grid.Row="0">
            <TextBlock Classes="h3">Data Model</TextBlock>
            <TextBlock TextWrapping="Wrap">
                On this page you can view the contents of the Artemis data model.
            </TextBlock>
            <TextBlock TextWrapping="Wrap" Classes="subtitle" Margin="0 10">
                Please note that having this window open can have a performance impact on your system.
            </TextBlock>
        </StackPanel>

        <TreeView Grid.Row="1" ItemsSource="{CompiledBinding MainDataModel.Children}">
            <TreeView.Styles>
                <Style Selector="TreeViewItem">
                    <Setter Property="IsExpanded" Value="{CompiledBinding IsVisualizationExpanded, Mode=TwoWay,DataType=dataModel:DataModelVisualizationViewModel}" />
                    <Setter Property="ContextFlyout">
                        <Setter.Value>
                            <MenuFlyout>
                                <MenuItem Header="Copy path" Command="{CompiledBinding CopyPath, DataType=dataModel:DataModelVisualizationViewModel}">
                                    <MenuItem.Icon>
                                        <avalonia:MaterialIcon Kind="ContentCopy" />
                                    </MenuItem.Icon>
                                </MenuItem>
                            </MenuFlyout>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TreeView.Styles>
            <TreeView.DataTemplates>
                <TreeDataTemplate DataType="{x:Type dataModel:DataModelPropertiesViewModel}" ItemsSource="{CompiledBinding Children}">
                    <Grid ColumnDefinitions="Auto,Auto,*">
                        <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="0 0 5 0">
                            <TextBlock FontWeight="Bold">[</TextBlock>
                            <TextBlock FontWeight="Bold" Text="{CompiledBinding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" />
                            <TextBlock FontWeight="Bold">]</TextBlock>
                        </StackPanel>

                        <TextBlock Grid.Column="1" Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />
                        <TextBlock Grid.Column="2"
                                   Text="{CompiledBinding DisplayValue}"
                                   FontFamily="Consolas"
                                   HorizontalAlignment="Right" />
                    </Grid>

                </TreeDataTemplate>
                <TreeDataTemplate DataType="{x:Type dataModel:DataModelListViewModel}" ItemsSource="{CompiledBinding ListChildren}">
                    <Grid ColumnDefinitions="Auto,Auto,*">
                        <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="0 0 5 0">
                            <TextBlock FontWeight="Bold">[</TextBlock>
                            <TextBlock FontWeight="Bold" Text="{CompiledBinding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" />
                            <TextBlock FontWeight="Bold">]</TextBlock>
                        </StackPanel>
                        <TextBlock Grid.Column="1" Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />
                        <TextBlock Grid.Column="2"
                                   Text="{CompiledBinding CountDisplay, Mode=OneWay}"
                                   FontFamily="Consolas"
                                   HorizontalAlignment="Right" />
                    </Grid>
                </TreeDataTemplate>
                <TreeDataTemplate DataType="{x:Type dataModel:DataModelPropertyViewModel}">
                    <Grid ColumnDefinitions="Auto,Auto,*">
                        <!-- Value description -->
                        <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="0 0 5 0">
                            <TextBlock FontWeight="Bold">[</TextBlock>
                            <TextBlock FontWeight="Bold" Text="{CompiledBinding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" />
                            <TextBlock FontWeight="Bold">]</TextBlock>
                        </StackPanel>
                        <TextBlock Grid.Column="1" Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />

                        <!-- Value display -->
                        <ContentControl Grid.Column="2" Content="{CompiledBinding DisplayViewModel}" FontFamily="Consolas" />
                    </Grid>
                </TreeDataTemplate>
                <TreeDataTemplate DataType="{x:Type dataModel:DataModelListItemViewModel}">
                    <Grid ColumnDefinitions="Auto,Auto,*">
                        <!-- Value description -->
                        <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="0 0 5 0">
                            <TextBlock FontWeight="Bold">[</TextBlock>
                            <TextBlock FontWeight="Bold" Text="{CompiledBinding ListType, Converter={StaticResource TypeToStringConverter}}" />
                            <TextBlock FontWeight="Bold">]</TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="0 0 5 0">
                            <TextBlock>List item #</TextBlock>
                            <TextBlock Text="{CompiledBinding Index, Mode=OneWay}" />
                        </StackPanel>

                        <!-- Value display -->
                        <ContentControl Grid.Column="2" Content="{CompiledBinding DisplayViewModel}" FontFamily="Consolas" />
                    </Grid>
                </TreeDataTemplate>

                <TreeDataTemplate DataType="{x:Type dataModel:DataModelEventViewModel}" ItemsSource="{CompiledBinding Children}">
                    <Grid ColumnDefinitions="Auto,Auto,*">
                        <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="0 0 5 0">
                            <TextBlock FontWeight="Bold">[</TextBlock>
                            <TextBlock FontWeight="Bold" Text="{CompiledBinding DisplayValueType, Converter={StaticResource TypeToStringConverter}, Mode=OneWay}" />
                            <TextBlock FontWeight="Bold">]</TextBlock>
                        </StackPanel>
                        <TextBlock Grid.Column="1" Text="{CompiledBinding PropertyDescription.Name}" ToolTip.Tip="{CompiledBinding PropertyDescription.Description}" />
                        <TextBlock Grid.Column="2"
                                   Text="{CompiledBinding Path=CountDisplay, DataType=dataModel:DataModelListViewModel ,Mode=OneWay}"
                                   FontFamily="Consolas"
                                   HorizontalAlignment="Right" />
                    </Grid>
                </TreeDataTemplate>
            </TreeView.DataTemplates>
        </TreeView>
    </Grid>

</UserControl>