namespace inutralia.Views.Question
{
    using inutralia.Models.Questions;
    using inutralia.ViewModels;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;

    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class PendingReadView : ContentPage
    {
        protected PendingReadViewModel ViewModel => BindingContext as PendingReadViewModel;

        public Message Message { private set; get; }

        public PendingReadView()
        {
            InitializeComponent();
            BindingContext = new PendingReadViewModel();
        }

        protected async void ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var pdte = (BindingContext as PendingReadViewModel);
            if (pdte.State == PendingReadViewModel.Estatus.Cerrado)
            {
                await DisplayAlert("ERROR", "La pregunta ya está cerrada", "Entendido");
            }

            else
            {
                await Navigation.PushAsync(new NewConsultationView()
                {
                    BindingContext = ViewModel.Message
                });
            }

            ((ListView)sender).SelectedItem = null;
        }

        protected override async void OnAppearing()
        {
            base.OnAppearing();
            await ViewModel.RefresData();
        }
    }
}