using LSFE.MobApp.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace LSFE.MobApp.ViewModels.Coverage
{
    public class ConfirmSelectionVM
    {
        public string DoctorName { get; }
        public string Specialization { get; }
        public List<ProductMaterial> Materials { get; }
        public List<SamplingItem> Samplings { get; }

        public bool HasMaterials => Materials?.Any() == true;
        public bool HasSamplings => Samplings?.Any() == true;

        public Command CancelCommand { get; }
        public Command ProceedCommand { get; }

        private readonly Action _onProceed;
        private bool _isLoading;
        public bool IsLoading
        {
            get => _isLoading;
            set
            {
                _isLoading = value;
                OnPropertyChanged();
            }
        }
        public ConfirmSelectionVM(string doctorName, string specialization,
                                  List<ProductMaterial> materials,
                                  List<SamplingItem> samplings,
                                  Action onProceed)
        {
            DoctorName = doctorName;
            Specialization = specialization;
            Materials = materials;
            Samplings = samplings;
            _onProceed = onProceed;

            CancelCommand = new Command(async () =>
            {
                IsLoading = true;
                await Application.Current.MainPage.Navigation.PopModalAsync();
                IsLoading = false;
            });

            ProceedCommand = new Command(async () =>
            {
                IsLoading = true;
                await Application.Current.MainPage.Navigation.PopModalAsync();
                _onProceed?.Invoke();
                IsLoading = false;
            });
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}