using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using wispro.sp.entity;
using wispro.sp.web.Services;

namespace wispro.sp.web.Components
{
    public partial class StaffSelect
    {
        private List<Staff> _Staffs;
        private Staff _SelectedItem;
        private List<Staff> _ShowStaffs;

        [Parameter]
        public int? StaffId { get; set; }


        [Parameter]
        public EventCallback<int?> StaffIdChanged { get; set; }

        [Inject] IUserService _UserService { get; set; }


        protected override async System.Threading.Tasks.Task OnInitializedAsync()
        {
            base.OnInitialized();

            _Staffs = await _UserService.GetAll();
            _ShowStaffs = _Staffs;
        }

        private void OnSelectedItemChangedHandler(Staff value)
        {
            _SelectedItem = value;
            StaffIdChanged.InvokeAsync(_SelectedItem.Id);
        }

        private void OnSearch(string value)
        {
            _ShowStaffs = _Staffs.Where<Staff>(p => p.Name.Contains(value)).ToList();
            StateHasChanged();
        }
    }
}
