<UserControl x:Class="SharepointToolbox.Views.Tabs.PermissionsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:loc="clr-namespace:SharepointToolbox.Localization">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="290" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <!-- Left panel: Scan configuration -->
    <DockPanel Grid.Column="0" Grid.Row="0" Margin="8">

      <!-- Scan Options GroupBox -->
      <GroupBox Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[grp.scan.opts]}"
                DockPanel.Dock="Top" Margin="0,0,0,8" Padding="8">
        <StackPanel>

          <!-- Site URL -->
          <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[perm.site.url]}"
                     Margin="0,0,0,2" />
          <TextBox Text="{Binding SiteUrl, UpdateSourceTrigger=PropertyChanged}"
                   Margin="0,0,0,6" />

          <!-- View Sites + selected label -->
          <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[perm.or.select]}"
                     Margin="0,0,0,2" />
          <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[btn.view.sites]}"
                  Command="{Binding OpenSitePickerCommand}"
                  HorizontalAlignment="Left" Padding="8,2" Margin="0,0,0,4" />
          <TextBlock Text="{Binding SitesSelectedLabel}"
                     FontStyle="Italic" Foreground="Gray" Margin="0,0,0,8" />

          <!-- Checkboxes -->
          <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.scan.folders]}"
                    IsChecked="{Binding ScanFolders}" Margin="0,0,0,4" />
          <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.inherited.perms]}"
                    IsChecked="{Binding IncludeInherited}" Margin="0,0,0,4" />
          <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.recursive]}"
                    IsChecked="{Binding IncludeSubsites}" Margin="0,0,0,8" />

          <!-- Folder depth -->
          <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[lbl.folder.depth]}"
                     Margin="0,0,0,2" />
          <TextBox Text="{Binding FolderDepth, UpdateSourceTrigger=PropertyChanged}"
                   Width="60" HorizontalAlignment="Left" Margin="0,0,0,4" />
          <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[chk.max.depth]}"
                    IsChecked="{Binding IsMaxDepth, Mode=TwoWay}"
                    Margin="0,0,0,0" />

        </StackPanel>
      </GroupBox>

      <!-- Action buttons -->
      <StackPanel DockPanel.Dock="Top" Margin="0,0,0,4">
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
          </Grid.ColumnDefinitions>
          <Button Grid.Column="0"
                  Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[btn.gen.perms]}"
                  Command="{Binding RunCommand}"
                  Margin="0,0,4,4" Padding="6,3" />
          <Button Grid.Column="1"
                  Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[btn.cancel]}"
                  Command="{Binding CancelCommand}"
                  Margin="0,0,0,4" Padding="6,3" />
        </Grid>
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
          </Grid.ColumnDefinitions>
          <Button Grid.Column="0"
                  Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[rad.csv.perms]}"
                  Command="{Binding ExportCsvCommand}"
                  Margin="0,0,4,0" Padding="6,3" />
          <Button Grid.Column="1"
                  Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[rad.html.perms]}"
                  Command="{Binding ExportHtmlCommand}"
                  Margin="0,0,0,0" Padding="6,3" />
        </Grid>
      </StackPanel>

    </DockPanel>

    <!-- Right panel: Results DataGrid -->
    <DataGrid Grid.Column="1" Grid.Row="0"
              ItemsSource="{Binding Results}"
              AutoGenerateColumns="False"
              IsReadOnly="True"
              VirtualizingPanel.IsVirtualizing="True"
              EnableRowVirtualization="True"
              Margin="0,8,8,8">
      <DataGrid.Columns>
        <DataGridTextColumn Header="Object Type" Binding="{Binding ObjectType}" Width="100" />
        <DataGridTextColumn Header="Title" Binding="{Binding Title}" Width="140" />
        <DataGridTextColumn Header="URL" Binding="{Binding Url}" Width="200" />
        <DataGridTextColumn Header="Unique Perms" Binding="{Binding HasUniquePermissions}" Width="90" />
        <DataGridTextColumn Header="Users" Binding="{Binding Users}" Width="140" />
        <DataGridTextColumn Header="Permission Levels" Binding="{Binding PermissionLevels}" Width="140" />
        <DataGridTextColumn Header="Granted Through" Binding="{Binding GrantedThrough}" Width="140" />
        <DataGridTextColumn Header="Principal Type" Binding="{Binding PrincipalType}" Width="110" />
      </DataGrid.Columns>
    </DataGrid>

    <!-- Bottom: status bar spanning both columns -->
    <StatusBar Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1">
      <StatusBarItem>
        <ProgressBar Width="150" Height="14"
                     Value="{Binding ProgressValue}"
                     Minimum="0" Maximum="100" />
      </StatusBarItem>
      <StatusBarItem Content="{Binding StatusMessage}" />
    </StatusBar>

  </Grid>
</UserControl>
