using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LSFE.MobApp.ViewModels.Coverage
{
    public class ReasonModalVM
    {
        public string Title { get; }
        public List<string> ReasonOptions { get; } = new()
        {
            "Doctor not available",
            "Appointment conflict",
            "Traffic / Delay",
            "Clinic closed",
            "Emergency",
            "Calamity",      
        };

        public string SelectedReason { get; set; }
        public string CustomReason { get; set; }

        private readonly Action<string> _onSubmit;

        public Command CancelCommand { get; }
        public Command SubmitCommand { get; }

        public ReasonModalVM(string title, Action<string> onSubmit)
        {
            Title = title;
            _onSubmit = onSubmit;

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

            SubmitCommand = new Command(async () =>
            {
                string final = !string.IsNullOrWhiteSpace(CustomReason)
                             ? CustomReason
                             : SelectedReason;

                await Application.Current.MainPage.Navigation.PopModalAsync();
                _onSubmit?.Invoke(final);
            });
        }
    }
}
