using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Media;

using BeWo.ServiceProxy;
using BeWo.Core.Service;

using BS.Shared.DataContracts.Compact;

namespace BeWo.View.Search
{
    public class EmployeeSearchView : GenericSearchView<CompactEmployeeDC>
    {
        public EmployeeSearchView()
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                ThemeColor = FindResource("EmployeeContentBrush") as Brush;
            }
        }

        public bool ShowArchived { get; set; }

        public new SearchMode SearchMode { get; set; }

        protected override void GetAll(Action<List<CompactEmployeeDC>> pCallBack)
        {
            if (ShowArchived)
            {
                ServiceFacade.DoEmployeeServiceAsync(
                    s => s.GetAllActiveAndArchivedEmployeesCompact(),
                   r =>
                   {
                       r.Sort((x, y) => (x.LastName + ", " + x.FirstName).CompareTo(y.LastName + ", " + y.FirstName));
                       pCallBack(r);
                   });
            }
            else
            {
                if (SearchMode == SearchMode.OnlyTeamMember)
                {
                    Cache.GetInstance().GetAllTeamMemberForEmployee(BeWoApp.LoggedOnUser.Employee, pCallBack);
                }
                else
                {
                    Cache.GetInstance().GetAllActiveEmployeesCompact(pCallBack);
                }
            }
        }
    }
}