using System.Collections.Generic;
using System.Windows;

namespace XLAB
{
    internal interface IEkzDirectoryDialogService
    {
        EkzDirectoryItem ShowEkzEditDialog(EkzDirectoryItem seed, bool isNew, IReadOnlyList<EkzDirectoryItem> existingItems, EkzDirectoryService service);

        bool Confirm(string message);

        void ShowError(string message);

        void ShowInfo(string message);

        void ShowWarning(string message);
    }

    internal sealed class EkzDirectoryDialogService : IEkzDirectoryDialogService
    {
        private readonly Window _owner;

        public EkzDirectoryDialogService(Window owner)
        {
            _owner = owner;
        }

        public bool Confirm(string message)
        {
            return MessageBox.Show(_owner, message, "ПСВ", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
        }

        public EkzDirectoryItem ShowEkzEditDialog(EkzDirectoryItem seed, bool isNew, IReadOnlyList<EkzDirectoryItem> existingItems, EkzDirectoryService service)
        {
            var viewModel = new EkzEditWindowViewModel(seed, isNew, existingItems, service);
            var window = new EkzEditWindow(viewModel);
            window.Owner = _owner;

            var result = window.ShowDialog();
            return result.HasValue && result.Value ? viewModel.ToResult() : null;
        }

        public void ShowError(string message)
        {
            MessageBox.Show(_owner, message, "ПСВ", MessageBoxButton.OK, MessageBoxImage.Error);
        }

        public void ShowInfo(string message)
        {
            MessageBox.Show(_owner, message, "ПСВ", MessageBoxButton.OK, MessageBoxImage.Information);
        }

        public void ShowWarning(string message)
        {
            MessageBox.Show(_owner, message, "ПСВ", MessageBoxButton.OK, MessageBoxImage.Warning);
        }
    }
}
