namespace HistoryView.ViewModels.MessageBoxs;

internal partial class ThemeMessageBoxViewModel : ObservableObject, IDialogAware
{
    public DialogCloseListener RequestClose { get; set; }

    public bool CanCloseDialog()
    {

        return true;
    }

    public void OnDialogClosed()
    {

    }

    [ObservableProperty]
    private string? _Message;

    [ObservableProperty]
    private Visibility _Info = Visibility.Collapsed;
    [ObservableProperty]
    private Visibility _ask = Visibility.Collapsed;
    [ObservableProperty]
    private Visibility _Warning = Visibility.Collapsed;
    [ObservableProperty]
    private Visibility _Error = Visibility.Collapsed;



    [ObservableProperty]
    private Visibility _OK = Visibility.Collapsed;
    [ObservableProperty]
    private Visibility _OKCancel = Visibility.Collapsed;
    [ObservableProperty]
    private Visibility _YesNo = Visibility.Collapsed;
    [ObservableProperty]
    private Visibility _YesNoCancel = Visibility.Collapsed;

    public void OnDialogOpened(IDialogParameters parameters)
    {
        if (parameters["Message"] is string message)
            this.Message = message;

        if (parameters["Button"] is MessageBoxButton button)
        {
            switch (button)
            {
                case MessageBoxButton.OK:
                    this.OK = Visibility.Visible;
                    break;
                case MessageBoxButton.OKCancel:
                    this.OKCancel = Visibility.Visible;
                    break;
                case MessageBoxButton.YesNoCancel:
                    this.YesNoCancel = Visibility.Visible;
                    break;
                case MessageBoxButton.YesNo:
                    this.YesNo = Visibility.Visible;
                    break;
                default:
                    break;
            }
        }

        if (parameters["Icon"] is MessageBoxImage icon)
        {
            switch (icon)
            {
                case MessageBoxImage.Error:
                    this.Error = Visibility.Visible;
                    break;
                case MessageBoxImage.Question:
                    this.Ask = Visibility.Visible;
                    break;
                case MessageBoxImage.Warning:
                    this.Warning = Visibility.Visible;
                    break;
                case MessageBoxImage.Information:
                    this.Info = Visibility.Visible;
                    break;
                default:
                    break;
            }
        }

    }

    [RelayCommand]
    private void Exit(string para)
    {
        switch (para)
        {
            case "OK":
                this.RequestClose.Invoke(ButtonResult.OK);
                break;
            case "Cancel":
                this.RequestClose.Invoke(ButtonResult.Cancel);
                break;
            case "Yes":
                this.RequestClose.Invoke(ButtonResult.Yes);
                break;
            case "No":
                this.RequestClose.Invoke(ButtonResult.No);
                break;
            default:
                this.RequestClose.Invoke();
                break;
        }

    }
}
