using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using ClaudeDo.Ui.ViewModels.Modals;

namespace ClaudeDo.Ui.Views.Modals;

public partial class RepoImportModalView : Window
{
    public RepoImportModalView()
    {
        InitializeComponent();
    }

    private async void AddFolderClicked(object? sender, RoutedEventArgs e)
    {
        if (DataContext is not RepoImportModalViewModel vm) return;
        var top = TopLevel.GetTopLevel(this);
        if (top is null) return;

        var folders = await top.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
        {
            Title = "Choose folders containing repos",
            AllowMultiple = true,
        });
        if (folders.Count == 0) return;

        await vm.AddFoldersAsync(folders.Select(f => f.Path.LocalPath));
    }
}
