<UserControl
    x:Class="FileTime.GuiApp.App.Views.ItemView"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:appcore="using:FileTime.App.Core.ViewModels"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:guiappvm="using:FileTime.GuiApp.App.ViewModels"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:traits="clr-namespace:FileTime.Core.Traits;assembly=FileTime.Core.Abstraction"
    x:Name="ItemRoot"
    HorizontalAlignment="Stretch"
    HorizontalContentAlignment="Stretch"
    d:DesignHeight="450"
    d:DesignWidth="800"
    x:CompileBindings="True"
    x:DataType="appcore:IItemViewModel"
    Background="{Binding ViewMode.Value, Converter={StaticResource ItemViewModeToBackgroundConverter}}"
    mc:Ignorable="d">
    <Grid
        x:Name="RootGrid"
        Margin="3"
        ColumnDefinitions="20,*,Auto">
        <Grid.Styles>
            <Style Selector="TextBlock">
                <Setter x:CompileBindings="False" Property="Foreground" Value="{Binding DataContext.ViewMode.Value, Converter={StaticResource ItemViewModeToForegroundConverter}, ElementName=ItemRoot}" />
            </Style>
        </Grid.Styles>
        <Image
            Width="18"
            Height="18"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Source="{Binding Converter={StaticResource ItemToImageConverter}}" />

        <ItemsControl
            Grid.Column="1"
            Margin="5,0,0,0"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Center">
            <ItemsControl.ItemsSource>
                <MultiBinding Converter="{StaticResource NamePartShrinkerConverter}">
                    <MultiBinding.Bindings>
                        <Binding Path="DisplayName^" />
                        <Binding
                            ElementName="RootGrid"
                            Path="Bounds.Width" />
                        <Binding
                            ElementName="ItemRoot"
                            Path="ShowAttributes" />
                    </MultiBinding.Bindings>
                </MultiBinding>
            </ItemsControl.ItemsSource>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate x:DataType="guiappvm:ItemNamePartViewModel">
                    <Grid>
                        <TextBlock
                            Text="{Binding Text}"
                            TextDecorations="{Binding TextDecorations}" />
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

        <Grid
            Grid.Column="2"
            IsVisible="{Binding ShowAttributes, ElementName=ItemRoot}">
            <StackPanel
                HorizontalAlignment="Right"
                Orientation="Horizontal">
                <TextBlock
                    Width="50"
                    Classes="SmallText"
                    IsVisible="{Binding Converter={StaticResource IsTypeConverter}, ConverterParameter={x:Type appcore:IElementViewModel}}"
                    Text="{Binding BaseItem.DisplayName, Converter={StaticResource GetFileExtensionConverter}}" />
                <Grid
                    DataContext="{Binding BaseItem}"
                    IsVisible="{Binding Converter={StaticResource IsTypeConverter}, ConverterParameter={x:Type traits:ISizeProvider}}">
                    <TextBlock
                        Width="60"
                        x:DataType="traits:ISizeProvider"
                        Classes="SmallText"
                        Text="{Binding Size.Value, Converter={StaticResource FormatSizeConverter}}"
                        TextAlignment="Right" />
                </Grid>
                <TextBlock
                    Width="95"
                    Classes="SmallText"
                    Text="{Binding ModifiedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=yyyy-MM-dd}"
                    TextAlignment="Right" />
                <TextBlock
                    Width="35"
                    Classes="SmallText"
                    Text="{Binding ModifiedAt, Converter={StaticResource DateTimeConverter}, ConverterParameter=hh:mm}"
                    TextAlignment="Right" />
                <TextBlock
                    Width="45"
                    Classes="SmallText"
                    Text="{Binding BaseItem.Attributes}"
                    TextAlignment="Right" />

            </StackPanel>

        </Grid>
    </Grid>
</UserControl>