using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using System.Net.Http;
using Newtonsoft.Json;
using System.Collections.ObjectModel;
using MobileApp.ViewModels;
using MobileApp.Model;


namespace MobileApp.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Countries : ContentPage
    {
        public Countries()
        {
            InitializeComponent();
            BindingContext = new CountryViewModel();
            GetCountries();
        }

        public async void GetCountries()
        {
            var client = new System.Net.Http.HttpClient();
            var response = await client.GetAsync(Functions._DataAPI("AllCountries"));
            string returnArray = response.Content.ReadAsStringAsync().Result;
            CountryModel resultParse = new CountryModel();
            if (returnArray != "")
            {
                resultParse = JsonConvert.DeserializeObject<CountryModel>(returnArray);
            }
            ListViewCountries.ItemsSource = resultParse.Records;
        }
        async void CountryButtonClicked(object sender, EventArgs args)
        {
            Button button = (Button)sender;
            App._RefCountryId = button.CommandParameter.ToString();
            await Navigation.PushAsync(new Destinations());
        }

    }
}