using System.Linq;
using Valg.EVA.Skanning.Contracts.CommonEnums;
using Valg.EVA.Skanning.UserInterfaceElements.Counting;
using Valg.EVA.Skanning.UserInterfaceElements;

namespace Valg.EVA.Skanning.Verify.Startup.StartPage
{
    public class MiniBoxCountingInformationViewModel : ViewModelBase
    {
        private string areaDescription;
        private string boxDescription;
        private string countingDescription;
        private bool showAreaDescription;
        private string votingCategory;
        private bool isVisible;

        public string VotingCategory
        {
            get { return votingCategory; }
            private set
            {
                votingCategory = value;
                OnPropertyChanged();
            }
        }

        public bool ShowAreaDescription
        {
            get { return showAreaDescription; }
            private set
            {
                showAreaDescription = value;
                OnPropertyChanged();
            }
        }

        public string BoxDescription
        {
            get { return boxDescription; }
            private set
            {
                boxDescription = value;
                OnPropertyChanged();
            }
        }

        public string CountingDescription
        {
            get { return countingDescription; }
            private set
            {
                countingDescription = value;
                OnPropertyChanged();
            }
        }

        public string AreaDescription
        {
            get { return areaDescription; }
            private set
            {
                areaDescription = value;
                OnPropertyChanged();
            }
        }

        public bool IsVisible
        {
            get { return isVisible; }
            set
            {
                isVisible = value;
                OnPropertyChanged();
            }
        }

        public void SetValues(string votingCategoryName, int boxNumber, string originatingLocation, CountingType countingType, int countingNumber)
        {
            IsVisible = true;
            VotingCategory = votingCategoryName;
            BoxDescription = string.Format("{0} {1}", Valg.EVA.Skanning.Resources.Language.VerifyLanguageString.Box, boxNumber);
            AreaDescription = originatingLocation;
            ShowAreaDescription = !string.IsNullOrWhiteSpace(originatingLocation);
            CountingDescription = countingType.GetCountingDescription(countingNumber, shortDescription: true);
        }

        public bool ShouldHide(string filter)
        {
            string[] filterParts = filter.ToUpperInvariant().Split(' ');
            return filterParts.Any(part => 
                !string.IsNullOrWhiteSpace(part) &&
                !AreaDescription.ToUpperInvariant().Contains(part) &&
                !CountingDescription.ToUpperInvariant().Contains(part) &&
                !BoxDescription.ToUpperInvariant().Contains(part) &&
                !VotingCategory.ToUpperInvariant().Contains(part));
        }
    }
}
