using System.Windows;
using Valg.EVA.Skanning.ContainerExtensions;
using Valg.EVA.Skanning.UserInterfaceElements.LightBox;
using Valg.EVA.Skanning.UserInterfaceElements.MessageBox;
using Prism.Events;

namespace Valg.EVA.Skanning.JobManagement.Startup.UI.Counting
{
    public class CountingPopups : ICountingPopups
    {
        private readonly IEventAggregator eventAggregator;
        private readonly ITypedFactory typedFactory;

        public CountingPopups(IEventAggregator eventAggregator, ITypedFactory typedFactory)
        {
            this.eventAggregator = eventAggregator;
            this.typedFactory = typedFactory;
        }

        public void ShowBoxCouldNotBeResetInformation()
        {
            var resultDialog = typedFactory.Create<IMessageBox>();

            resultDialog.Initialize(
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_BoxCouldNotBeResetTitle,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_BoxCouldNotBeResetDetails,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_BoxCouldNotBeResetSolution,
                MessageBoxType.Information);

            var eventArgs = new LightBoxEventArgs(resultDialog as Window);
            eventAggregator.GetEvent<ShowLightBoxEvent>().Publish(eventArgs);
        }

        public void ShowCountingCouldNotBeDeletedInformation()
        {
            var resultDialog = typedFactory.Create<IMessageBox>();

            resultDialog.Initialize(
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_CountingCouldNotBeDeletedTitle,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_CountingCouldNotBeDeletedDetails,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_CountingCouldNotBeDeletedSolution,
                MessageBoxType.Information);

            var eventArgs = new LightBoxEventArgs(resultDialog as Window);
            eventAggregator.GetEvent<ShowLightBoxEvent>().Publish(eventArgs);
        }

        public void ShowBoxCouldNotBeSetToEmptyInformation()
        {
            var resultDialog = typedFactory.Create<IMessageBox>();

            resultDialog.Initialize(
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_BoxCouldNotBeSetToEmptyTitle,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_BoxCouldNotBeSetToEmptyDetails,
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.Warning_BoxCouldNotBeSetToEmptySolution,
                MessageBoxType.Information);

            var eventArgs = new LightBoxEventArgs(resultDialog as Window);
            eventAggregator.GetEvent<ShowLightBoxEvent>().Publish(eventArgs);
        }

        public void ShowBallotsUnlockedInformation(int numberOfUnlockedBallots)
        {
            var resultDialog = typedFactory.Create<IMessageBox>();

            resultDialog.Initialize(
                Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.BallotsUnlockedPopup_Title,
                string.Format(Valg.EVA.Skanning.Resources.Language.JobManagementLanguageString.BallotsUnlockedPopup_Text, numberOfUnlockedBallots),
                MessageBoxType.Information);

            var eventArgs = new LightBoxEventArgs(resultDialog as Window);
            eventAggregator.GetEvent<ShowLightBoxEvent>().Publish(eventArgs);
        }
    }
}
