<ui:ContentDialog
    CloseButtonText="Close"
    Title="{Binding CivitModel.Name}"
    d:DataContext="{d:DesignInstance Type=designData:MockModelVersionDialogViewModel,
                                     IsDesignTimeCreatable=True}"
    d:DesignHeight="512"
    d:DesignWidth="700"
    mc:Ignorable="d"
    ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
    ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
    x:Class="StabilityMatrix.SelectModelVersionDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:converters="clr-namespace:StabilityMatrix.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:StabilityMatrix"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:designData="clr-namespace:StabilityMatrix.DesignData"
    xmlns:api="clr-namespace:StabilityMatrix.Core.Models.Api;assembly=StabilityMatrix.Core">

    <ui:ContentDialog.Resources>
        <!--  ReSharper disable once Xaml.StaticResourceNotResolved  -->
        <Style BasedOn="{StaticResource {x:Type ui:ContentDialog}}"
               TargetType="{x:Type local:SelectModelVersionDialog}" />

        <converters:BoolNegationConverter x:Key="BoolNegationConverter" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <converters:ValueConverterGroup x:Key="InvertAndVisibilitate">
            <converters:BoolNegationConverter />
            <BooleanToVisibilityConverter />
        </converters:ValueConverterGroup>
    </ui:ContentDialog.Resources>

    <Grid
        Margin="8"
        MinHeight="450"
        MinWidth="700">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ui:Image Grid.Column="0" Grid.Row="0" Margin="8"
                  VerticalAlignment="Top"
                  MaxHeight="400"
                  HorizontalAlignment="Left"
                  Source="{Binding PreviewImage}" />


        <ListView Grid.Row="0" Grid.Column="1"
                  Margin="8"
                  MaxHeight="450"
                  ItemsSource="{Binding Versions}"
                  SelectedItem="{Binding SelectedVersion}">
            <ListView.ItemTemplate>
                <DataTemplate DataType="{x:Type api:CivitModelVersion}">
                    <StackPanel Margin="4" VerticalAlignment="Top">
                        <TextBlock Margin="0,5,0,5"
                                   MinWidth="128"
                                   Text="{Binding Name}" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <ListView Grid.Row="0" Grid.Column="2"
                  Margin="8"
                  PreviewMouseWheel="ListView_PreviewMouseWheel"
                  ItemsSource="{Binding SelectedVersion.Files}"
                  SelectedItem="{Binding SelectedFile}">
            <ListView.ItemTemplate>
                <DataTemplate DataType="{x:Type api:CivitFile}">
                    <StackPanel Margin="4" VerticalAlignment="Top">
                        <TextBlock Margin="0,4,0,4" Text="{Binding Name}" />
                        <TextBlock Margin="0,0,0,4" FontSize="11">
                            <Run Text="{Binding Metadata.Size}" />
                            <Run Text="{Binding Metadata.Fp}" />
                            <Run Text="-" />
                            <Run Text="{Binding FullFilesSize, Mode=OneWay}" />
                        </TextBlock>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <StackPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="1" 
                    Orientation="Horizontal"
                    HorizontalAlignment="Center">
            <ui:Button
                Content="Cancel"
                HorizontalAlignment="Center"
                Margin="8, 0"
                Click="Cancel_Click" />
            
            <ui:Button
                Margin="8, 0"
                Content="Import"
                IsEnabled="{Binding IsImportEnabled}"
                Appearance="Primary"
                Click="Import_OnClick"/>
        </StackPanel>

    </Grid>

</ui:ContentDialog>
