using Avalonia.Layout;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InABox.Avalonia.Components;

public partial class OptionSelectorViewModel : BasePopupViewModel<string>, IAlignedPopup
{
    [ObservableProperty]
    private string _title = "Select Option";

    [ObservableProperty]
    private ObservableCollection<string> _options = new();

    public HorizontalAlignment HorizontalAlignment => HorizontalAlignment.Stretch;

    public VerticalAlignment VerticalAlignment => VerticalAlignment.Center;

    [RelayCommand]
    private void Cancel()
    {
        Close(null);
    }

    [RelayCommand]
    private void Select(string option)
    {
        Close(option);
    }
}

public static class OptionSelector
{
    public static async Task<string?> Execute(string title, params string[] options)
    {
        return await Navigation.Popup<OptionSelectorViewModel, string?>(model =>
        {
            model.Title = title;
            model.Options = new(options);
        });
    }
}
