<UserControl
    x:Class="AppFramework.Views.DynamicPropertyView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:extensions="clr-namespace:AppFramework.Extensions"
    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:perm="clr-namespace:AppFramework.Common;assembly=AppFramework.Common"
    xmlns:sync="http://schemas.syncfusion.com/wpf"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <sync:SfBusyIndicator AnimationType="DualRing" IsBusy="{Binding IsBusy}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Border Style="{StaticResource HeaderBorderStyle}" />

            <DockPanel Margin="20" LastChildFill="False">
                <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                    <TextBlock
                        FontSize="18"
                        FontWeight="Bold"
                        Text="{extensions:Translate DynamicPropertyManagement}" />
                </StackPanel>
            </DockPanel>

            <Border
                Grid.Row="1"
                Margin="20"
                Style="{StaticResource BorderStyle}" />

            <TabControl Grid.Row="1" Margin="30">
                <TabItem Background="Transparent" Header="{extensions:Translate DynamicProperty}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                            <RowDefinition />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>

                        <Button
                            Margin="0,5"
                            Padding="5"
                            HorizontalAlignment="Right"
                            Command="{Binding AddCommand}"
                            Content="{extensions:Translate AddNewDynamicPropertyValue}"
                            Style="{StaticResource SimpleButton}"
                            Visibility="{extensions:HasPermission Text={x:Static perm:Permkeys.DynamicEntityPropertiesCreate}}" />

                        <sync:SfDataGrid
                            Grid.Row="1"
                            ItemsSource="{Binding dataPager.GridModelList}"
                            SelectedItem="{Binding dataPager.SelectedItem}"
                            Style="{StaticResource SimpleDataGridStyle}">
                            <sync:SfDataGrid.Columns>
                                <sync:GridTemplateColumn
                                    Width="120"
                                    AllowFiltering="False"
                                    AllowSorting="False"
                                    HeaderText="{extensions:Translate Actions}">
                                    <sync:GridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <sync:DropDownButtonAdv Label="{extensions:Translate Actions}" Style="{StaticResource OperationButtonStyle}">
                                                <ItemsControl ItemsSource="{Binding DataContext.proxyService.Permissions, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sync:SfDataGrid}}">
                                                    <ItemsControl.ItemTemplate>
                                                        <DataTemplate>
                                                            <Button
                                                                Margin="5"
                                                                Padding="3"
                                                                Background="Transparent"
                                                                Command="{Binding DataContext.ExecuteCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sync:SfDataGrid}}"
                                                                CommandParameter="{Binding Key}"
                                                                Content="{Binding Name}"
                                                                Foreground="White" />
                                                        </DataTemplate>
                                                    </ItemsControl.ItemTemplate>
                                                </ItemsControl>
                                            </sync:DropDownButtonAdv>
                                        </DataTemplate>
                                    </sync:GridTemplateColumn.CellTemplate>
                                </sync:GridTemplateColumn>
                                <sync:GridTextColumn HeaderText="{extensions:Translate PropertyName}" MappingName="PropertyName" />
                                <sync:GridTextColumn HeaderText="{extensions:Translate DisplayName}" MappingName="DisplayName" />
                                <sync:GridTextColumn HeaderText="{extensions:Translate InputType}" MappingName="InputType" />
                            </sync:SfDataGrid.Columns>
                        </sync:SfDataGrid>

                        <sync:SfDataPager
                            Grid.Row="2"
                            HorizontalAlignment="Right"
                            NumericButtonCount="{Binding dataPager.NumericButtonCount}"
                            PageCount="{Binding dataPager.PageCount, Mode=TwoWay}"
                            PageSize="{Binding dataPager.PageSize, Mode=TwoWay}"
                            UseOnDemandPaging="True"
                            PageIndex="{Binding dataPager.PageIndex, Mode=TwoWay}" />
                    </Grid>
                </TabItem>

                <TabItem Background="Transparent" Header="{extensions:Translate DynamicEntityProperties}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <Button
                            Padding="5"
                            HorizontalAlignment="Right"
                            Command="{Binding AddEntityPropertyCommand}"
                            Content="{extensions:Translate AddNewDynamicEntityProperty}" />

                        <sync:SfDataGrid
                            Grid.Row="1"
                            ItemsSource="{Binding entitydataPager.GridModelList}"
                            SelectedItem="{Binding entitydataPager.SelectedItem}"
                            Style="{StaticResource SimpleDataGridStyle}">
                            <sync:SfDataGrid.Columns>
                                <sync:GridTemplateColumn
                                    Width="120"
                                    AllowFiltering="False"
                                    AllowSorting="False"
                                    HeaderText="{extensions:Translate Actions}">
                                    <sync:GridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Button
                                                Margin="5"
                                                Padding="3"
                                                Background="#1E90FF"
                                                Command="{Binding DataContext.DetailCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=sync:SfDataGrid}}"
                                                CommandParameter="{Binding}"
                                                Content="{extensions:Translate Detail}"
                                                Foreground="White" />
                                        </DataTemplate>
                                    </sync:GridTemplateColumn.CellTemplate>
                                </sync:GridTemplateColumn>
                                <sync:GridTextColumn HeaderText="{extensions:Translate EntityFullName}" MappingName="EntityFullName" />
                            </sync:SfDataGrid.Columns>
                        </sync:SfDataGrid>
                    </Grid>
                </TabItem>
            </TabControl>
        </Grid>
    </sync:SfBusyIndicator>
</UserControl>
