<UserControl
    x:Class="AppFramework.Views.DynamicEntityDetailsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:const="clr-namespace:AppFramework.Common;assembly=AppFramework.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:extensions="clr-namespace:AppFramework.Extensions"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sync="http://schemas.syncfusion.com/wpf"
    xmlns:win="clr-namespace:AppFramework.WindowHost"
    Width="700"
    Height="500"
    mc:Ignorable="d">
    <win:DialogHost Identifier="{x:Static const:AppCommonConsts.DialogIdentifier}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <Border
                Grid.RowSpan="3"
                CornerRadius="0"
                Opacity="1"
                Style="{StaticResource BorderStyle}" />

            <TextBlock
                Margin="15"
                FontSize="18"
                FontWeight="Bold"
                Text="{extensions:Translate AddNewDynamicPropertyValue}" />

            <StackPanel Grid.Row="1" Margin="15">
                <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                    <Button
                        Margin="5,0"
                        Padding="8"
                        Command="{Binding ShowAddCommand}"
                        Content="{extensions:Translate AddNewDynamicEntityProperty}" />
                </StackPanel>

                <StackPanel Visibility="{Binding IsAdd, Converter={StaticResource inverseBoolToVisibility}}">
                    <TextBlock Text="{extensions:Translate Value}" />
                    <DockPanel Margin="0,0,0,10">
                        <Button
                            Margin="5,0"
                            Padding="10,5"
                            Command="{Binding AddValueCommand}"
                            Content="{extensions:Translate Save}"
                            DockPanel.Dock="Right" />
                        <ComboBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}">
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding PropertyName}" />
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                    </DockPanel>
                </StackPanel>

                <TextBlock Text="{extensions:Translate Values}" />
                <ScrollViewer Height="300" VerticalScrollBarVisibility="Auto">
                    <ItemsControl Margin="8" ItemsSource="{Binding dataPager.GridModelList}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <DockPanel Margin="0,5" LastChildFill="False">
                                    <TextBlock Text="{Binding DynamicPropertyName}" />
                                    <Button
                                        Margin="10,0,0,0"
                                        Padding="10,5"
                                        Background="#FF6347"
                                        Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
                                        CommandParameter="{Binding}"
                                        Content="{extensions:Translate Delete}"
                                        DockPanel.Dock="Right" />
                                </DockPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </ScrollViewer>
            </StackPanel>

            <StackPanel
                Grid.Row="2"
                Margin="15"
                HorizontalAlignment="Right"
                Orientation="Horizontal">
                <Button
                    Padding="10,5"
                    Command="{Binding CancelCommand}"
                    Content="{extensions:Translate Close}" />
            </StackPanel>
        </Grid>
    </win:DialogHost>
</UserControl>
