using System;
using iElection.Models;
using iElection.Models.Entities;
using iElection.ViewModels;
using Xamarin.Forms;
using SelectionChangedEventArgs = Syncfusion.SfAutoComplete.XForms.SelectionChangedEventArgs;

namespace iElection.Views
{
    public partial class AddContactPage : ContentPage
    {
        public AddContactPage()
        {
            InitializeComponent();
        }

        private void Button_OnClicked(object sender, EventArgs e)
        {
            if (BindingContext is AddContactPageViewModel viewModel)
                viewModel.SelectContactCommand.Execute(null);
        }

        private void GenderPicker_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            if (sender is Picker picker && picker.SelectedItem is GenderItemModel model && BindingContext is AddContactPageViewModel viewModel)
                viewModel.PageDto.Gender = model.GenderType;

        }
        

        private void JobSfAutoComplete_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.Value is Job job && BindingContext is AddContactPageViewModel viewModel)
                viewModel.PageDto.JobId = job.Id;
        }

        private void DistrictSfAutoComplete_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.Value is District model && BindingContext is AddContactPageViewModel viewModel)
                viewModel.PageDto.DistrictId = model.Id;
        }
    }
}
