<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:ClaudeDo.Ui.ViewModels.Modals"
        xmlns:ctl="using:ClaudeDo.Ui.Views.Controls"
        xmlns:loc="using:ClaudeDo.Ui.Localization"
        x:Class="ClaudeDo.Ui.Views.Modals.RepoImportModalView"
        x:DataType="vm:RepoImportModalViewModel"
        Title="{loc:Tr modals.repoImport.windowTitle}"
        Width="560" Height="480" MinWidth="420" MinHeight="320"
        CanResize="True"
        WindowDecorations="BorderOnly"
        ExtendClientAreaToDecorationsHint="True"
        ExtendClientAreaTitleBarHeightHint="-1"
        WindowStartupLocation="CenterOwner"
        Background="{DynamicResource SurfaceBrush}">
  <Window.KeyBindings>
    <KeyBinding Gesture="Escape" Command="{Binding CancelCommand}"/>
  </Window.KeyBindings>

  <ctl:ModalShell Title="{loc:Tr modals.repoImport.title}" CloseCommand="{Binding CancelCommand}">
    <ctl:ModalShell.Footer>
      <StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right"
                  VerticalAlignment="Center">
        <Button Classes="btn" Content="{loc:Tr modals.repoImport.cancel}" Command="{Binding CancelCommand}" MinWidth="90"/>
        <Button Content="{Binding CreateButtonText}" Command="{Binding CreateCommand}"
                IsEnabled="{Binding CanCreate}" MinWidth="120" Classes="primary"/>
      </StackPanel>
    </ctl:ModalShell.Footer>

    <!-- Body: toolbar + checklist -->
    <DockPanel>
      <!-- Toolbar: search + folder actions -->
      <StackPanel DockPanel.Dock="Top" Spacing="8" Margin="20,12,20,6">
        <TextBox Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                 PlaceholderText="{loc:Tr modals.repoImport.searchPlaceholder}"/>
        <Grid ColumnDefinitions="Auto,*,Auto">
          <Button Classes="btn" Grid.Column="0" Content="{loc:Tr modals.repoImport.addFolder}" Click="AddFolderClicked"/>
          <Button Classes="btn" Grid.Column="2" Content="{loc:Tr modals.repoImport.forgetFolders}"
                  Command="{Binding ForgetFoldersCommand}"
                  IsVisible="{Binding HasFolders}"/>
        </Grid>
      </StackPanel>

      <!-- Repo checklist -->
      <ScrollViewer Padding="20,2,20,8">
        <ItemsControl ItemsSource="{Binding Repos}">
          <ItemsControl.ItemTemplate>
            <DataTemplate DataType="vm:RepoImportItemViewModel">
              <Grid ColumnDefinitions="Auto,Auto,*,Auto" Margin="0,1"
                    IsVisible="{Binding IsVisible}">
                <CheckBox Grid.Column="0" MinWidth="0"
                          IsChecked="{Binding IsChecked, Mode=TwoWay}"
                          IsEnabled="{Binding CanToggle}"
                          VerticalAlignment="Center"/>
                <TextBlock Classes="body" Grid.Column="1" Text="{Binding Name}"
                           VerticalAlignment="Center" Margin="4,0,0,0"/>
                <TextBlock Classes="path-mono" Grid.Column="2" Text="{Binding FullPath}"
                           VerticalAlignment="Center" Margin="8,0,0,0"/>
                <TextBlock Classes="meta" Grid.Column="3" Text="{loc:Tr modals.repoImport.alreadyAdded}"
                           VerticalAlignment="Center" Margin="8,0,0,0"
                           IsVisible="{Binding AlreadyAdded}"/>
              </Grid>
            </DataTemplate>
          </ItemsControl.ItemTemplate>
        </ItemsControl>
      </ScrollViewer>
    </DockPanel>

  </ctl:ModalShell>
</Window>
