using System;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Valg.EVA.Skanning.UserInterfaceElements;
using Valg.EVA.Skanning.UserInterfaceElements.BallotPaperImage;
using Valg.EVA.Skanning.UserInterfaceElements.Commands;

namespace Valg.EVA.Skanning.Sample.Startup.Preview
{
    public class PreviewViewModel : ViewModelBase, IPreviewViewModel
    {
        private readonly IBallotPaperImageWindowProvider ballotPaperImageWindowProvider;
        private int currentBallotPaperImagePageIndex;

        private readonly RelayCommand showBallotPaperImageCommand;
        private readonly RelayCommand showBallotPaperPlacementInBoxCommand;

        public PreviewViewModel(IBallotPaperImageViewModel ballotPaperImageViewModel, IBallotPaperImageWindowProvider ballotPaperImageWindowProvider)
        {
            BallotPaperImageViewModel = ballotPaperImageViewModel;
            this.ballotPaperImageWindowProvider = ballotPaperImageWindowProvider;
            showBallotPaperPlacementInBoxCommand = new RelayCommand(c => ShowBallotPaperPlacementInBox());
            showBallotPaperImageCommand = new RelayCommand(c => ShowBallotPaperImage());
        }

        public void SetModel(BallotPaperImageInformation bitmapInfo, int ballotPaperId, int boxCountingId)
        {
            BallotPaperImageViewModel.BallotPaperId = ballotPaperId;
            BallotPaperImageViewModel.BoxCountingId = boxCountingId;
            BallotPaperImageViewModel.Front = bitmapInfo.Front;
            BallotPaperImageViewModel.Back = bitmapInfo.Back;
            BallotPaperImageViewModel.Selected = bitmapInfo.Front;
            BallotPaperImageViewModel.ShowZoomPanelMiniMap = true;
        }

        public void AddPreviewImageViewModel(PreviewBallotPaperImageViewModel previewViewModel)
        {
            ImageViewModels.Add(previewViewModel);
        }

        protected override void SubscribeToViewModelSpecificEvents()
        {
        }

        private void ShowBallotPaperPlacementInBox()
        {
            throw new NotSupportedException();
        }

        private void ShowBallotPaperImage()
        {
            ballotPaperImageWindowProvider.Show(BallotPaperImageViewModel);
        }

        private void OnPageChanged(object eventArgs)
        {
            throw new NotImplementedException();
        }

        public int CurrentBallotPaperImagePageIndex
        {
            get => currentBallotPaperImagePageIndex;
            set
            {
                currentBallotPaperImagePageIndex = value;
                OnPropertyChanged();
            }
        }

        public ObservableCollection<PreviewBallotPaperImageViewModel> ImageViewModels { get; } = new ObservableCollection<PreviewBallotPaperImageViewModel>();

        public ICommand ShowBallotPaperImageCommand => showBallotPaperImageCommand;
        public ICommand ShowBallotPaperPlacementInBoxCommand => showBallotPaperPlacementInBoxCommand;

        public IBallotPaperImageViewModel BallotPaperImageViewModel { get; set; }

    }
}
