using Minesweeper.Commands;
using Minesweeper.Presentation.Views;

namespace Minesweeper.Presentation.Presenters
{
    public sealed class MainMenuPresenter : IPresenter
    {
        private readonly IGameCommandDispatcher commandDispatcher;
        private readonly IMainMenuView view;

        public MainMenuPresenter(IGameCommandDispatcher commandDispatcher, IMainMenuView view = null)
        {
            this.commandDispatcher = commandDispatcher;
            this.view = view;
        }

        public void Initialize()
        {
            if (view != null)
            {
                view.StartClicked += OnStartClicked;
            }
        }

        public void Dispose()
        {
            if (view != null)
            {
                view.StartClicked -= OnStartClicked;
            }
        }

        private void OnStartClicked()
        {
            commandDispatcher.Dispatch(new StartGameCommand());
        }
    }
}
