using System.Windows;
using Prism.Events;

namespace Valg.EVA.Skanning.Scan.Startup.SelectScannerModel
{
    public partial class ScannerModelSelectorWindow 
    {
        public ScannerModelSelectorWindow()
        {
            InitializeComponent();

            Loaded += (sender, args) => Activate();

            var languageInitiator = new LanguageResourceInitializer();
            languageInitiator.SetCurrentCulture();

            var eventAggregator = new EventAggregator();
            eventAggregator.GetEvent<RequestCloseScannerSelectorWindowEvent>().Subscribe(Succeed);
            eventAggregator.GetEvent<BeforeShowSubDialogEvent>().Subscribe(SetOwner);
            DataContext = new ScannerModelSelectorWindowViewModelNyt(eventAggregator);
        }

        private void SetOwner(Window obj)
        {
            obj.Owner = this;
        }

        private void OnButtonOkClick(object sender, RoutedEventArgs e)
        {
            Succeed();
        }

        private void OnButtonCancelClick(object sender, RoutedEventArgs e)
        {
            Fail();
        }

        private void Succeed()
        {
            DialogResult = true;
            Close();
        }
        private void Fail()
        {
            DialogResult = false;
            Close();
        }
    }
}

