<UserControl
    x:Class="AppFramework.Views.RoleView"
    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: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,15" LastChildFill="False">
                <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                    <TextBlock
                        FontSize="18"
                        FontWeight="Bold"
                        Text="{extensions:Translate Roles}" />
                    <TextBlock
                        Margin="10,0,0,0"
                        VerticalAlignment="Center"
                        Text="{extensions:Translate RolesHeaderInfo}" />
                </StackPanel>

                <Button
                    VerticalAlignment="Center"
                    Command="{Binding AddCommand}"
                    Content="{extensions:Translate AddRole}"
                    DockPanel.Dock="Right"
                    Style="{StaticResource SimpleButton}"
                    Visibility="{extensions:HasPermission Text={x:Static perm:Permkeys.RoleCreate}}" />
            </DockPanel>

            <Grid Grid.Row="1" Margin="20">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>

                <Border Grid.RowSpan="3" Style="{StaticResource BorderStyle}" />

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <Button
                        Margin="10"
                        Padding="5"
                        Command="{Binding SelectedCommand}"
                        Content="{Binding SelectPermissions}" />
                </Grid>

                <sync:SfDataGrid
                    x:Name="SfDataGrid"
                    Grid.Row="1"
                    Margin="15,0"
                    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
                            Width="120"
                            HeaderText="{extensions:Translate RoleName}"
                            MappingName="DisplayName" />
                        <sync:GridDateTimeColumn HeaderText="{extensions:Translate CreationTime}" MappingName="CreationTime" />
                    </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>
        </Grid>
    </sync:SfBusyIndicator>
</UserControl>