<?xml version="1.0" encoding="utf-8"?>
<Page
    x:Class="Sonex.Client.Pages.Administrator.Accounts.Groups"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Layouts="using:Sonex.Client.Layouts"
    xmlns:controls="using:Sonex.Client.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    mc:Ignorable="d">

    <Layouts:ItemsAndContentLayout
        x:Name="_Layout"
        Loaded="Layout_Loaded"
        Background="{ThemeResource SolidBackgroundFillColorSenaryBrush}"
        ItemsSource="{x:Bind RecordItems, Mode=OneWay}"
        SelectedItemChanged="Layout_SelectedItemChanged"
        AddClicked="Layout_AddClicked"
        DeleteClicked="Layout_DeleteClicked"
        SearchPlaceholder="Search..."
        ShowPicture="True"
        PictureSize="48"
        ShowSubtitle="False"
        ShowDescription="True"
        ShowDeleteButton="True"
        ShowAddButton="True"
        AddToolTip="Create new group"
        DeleteToolTip="Delete group"
        SortToolTip="Sort"
        SortBy="Title"
        SortByTitleMenuText="Name"
        ShowSortByTitleOption="True"

        ShowSortByIsEnabledOption="False"
        ShowSortByDescriptionOption="False"
        ShowSortByIdOption="False"
        ShowSortByKeyOption="False"
        ShowSortBySubtitleOption="False"
        >
        <Layouts:ItemsAndContentLayout.DetailContent>
            <ScrollViewer VerticalScrollBarVisibility="Auto" Padding="8,18,8,8" Visibility="{x:Bind IsRecordSelected, Mode=OneTime}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Grid Grid.Row="0" Margin="0,0,0,0" MaxWidth="1000">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <PersonPicture Grid.Column="0"
                                      DisplayName="{x:Bind SelectedRecord.DisplayName}"
                                      VerticalAlignment="Center"
                                      Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                                      Margin="0,18,18,18" />

                        <StackPanel Grid.Column="1" Spacing="2" VerticalAlignment="Center" Padding="8">
                            <TextBlock VerticalAlignment="Center"
                                      Text="{x:Bind SelectedRecord.DisplayName}"
                                      Style="{ThemeResource BodyLargeTextBlockStyle}"
                                      Foreground="{ThemeResource TextFillColorPrimaryBrush}" />
                            
                            <TextBlock VerticalAlignment="Center"
                                      Text="{x:Bind SelectedRecord.Description}"
                                      Style="{ThemeResource BodyTextBlockStyle}"
                                      Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                       TextWrapping="Wrap"/>

                            <TextBlock VerticalAlignment="Center"
                                      Style="{ThemeResource BodyTextBlockStyle}"
                                      Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                      TextWrapping="Wrap">
                               <Run Text="Group id: " />
                               <Run Text="{x:Bind SelectedRecord.Id}" />
                            </TextBlock>

                        </StackPanel>
                    </Grid>
                    

                    <controls:PropertyBoxItemsExpander Grid.Row="1"
                                                       Title="Group information"
                                                       Description="Name and description of the permission group assigned to users">
                        <controls:PropertyBoxItemsExpander.Icon>
                            <FontIcon Glyph="&#xE779;" />
                        </controls:PropertyBoxItemsExpander.Icon>
                        <controls:PropertyBoxItemsExpander.Footer>
                            <Button HorizontalAlignment="Right"
                                    Style="{ThemeResource AccentButtonStyle}"
                                    Click="SaveBasicInformation_Click">Save</Button>
                        </controls:PropertyBoxItemsExpander.Footer>

                        <TextBox MinWidth="200"
                                 MaxWidth="200"
                                 HorizontalAlignment="Stretch"
                                 Header="Name"
                                 PlaceholderText="Group name"
                                 Text="{x:Bind SelectedRecordDisplayName, Mode=TwoWay}" />
                        <TextBox AcceptsReturn="True"
                                 MinWidth="200"
                                 HorizontalAlignment="Stretch"
                                 Header="Description"
                                 PlaceholderText="Description"
                                 Text="{x:Bind SelectedRecord.Description, Mode=TwoWay}" />

                    </controls:PropertyBoxItemsExpander>

                    <controls:PropertyBoxContentExpander Grid.Row="2"
                                                         VerticalAlignment="Stretch"
                                                       Title="Group permissions"
                                                         BodyHorizontalAlignment="Stretch"
                                                       Description="Select the permissions assigned to this group. Any changes are applied immediately, even for currently active sessions.">
                        <controls:PropertyBoxContentExpander.Icon>
                            <FontIcon Glyph="&#xEA18;" />
                        </controls:PropertyBoxContentExpander.Icon>
                        <controls:PropertyBoxContentExpander.Body>
                            <controls:CheckListControl x:Name="PermissionsControl"
                                                          HorizontalAlignment="Stretch"
                                                          Height="320"
                                                          ShowKeyValueText="False"
                                                          ItemChecked="PermissionsControl_ItemChecked"
                                                          ItemUnchecked="PermissionsControl_ItemUnchecked" />
                        </controls:PropertyBoxContentExpander.Body>
                    </controls:PropertyBoxContentExpander>

                    <controls:PropertyBox Grid.Row="3"
                      Title="Delete group"
                      Description="Delete this permission group. Users assigned to it will lose all permissions granted by this group.">
                        <controls:PropertyBox.Icon>
                            <FontIcon Glyph="&#xE74D;" />
                        </controls:PropertyBox.Icon>
                        <Button Style="{ThemeResource AccentButtonStyle}" Click="Layout_DeleteClicked">Delete group</Button>
                    </controls:PropertyBox>
                </Grid>
            </ScrollViewer>
        </Layouts:ItemsAndContentLayout.DetailContent>
    </Layouts:ItemsAndContentLayout>
</Page>
