using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

using BeWo.ServiceProxy;

using BS.Shared.DataContracts;
using BS.Shared.Extensions;

namespace BeWo.View.Report.Finance
{
    public partial class OutstandingReceivablesView : BeWoView
    {
        public OutstandingReceivablesView(List<FinanceOverviewItemDC> pFinanceOverviewItems)
        {
            this.InitializeComponent();
            this.chkShowOnlyOutstandingReceivables.IsChecked = true;

            // if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll))
            // chkShowOnlyMySupportConcepts.IsEnabled = false;
            this.DataContext = pFinanceOverviewItems;
            this.Loaded += this.OutstandingReceivablesView_Loaded;
        }

        private void OutstandingReceivablesView_Loaded(object sender, RoutedEventArgs e)
        {
            this.textbox_search.Focus();
        }

        private void buttonRefresh_Click(object sender, RoutedEventArgs e)
        {
            bool showOnlyOutstanding = this.chkShowOnlyOutstandingReceivables.IsChecked.Value;
            bool showOnlyArchivedSCs = this.chkShowArchived.IsChecked.Value;

            ServiceFacade.DoAnalysisServiceAsync(s => s.GetOutstandingReceivables(showOnlyOutstanding, showOnlyArchivedSCs), list => { this.Dispatch(delegate { this.DataContext = list; }); });
        }

        private void listview_list_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.listview_list.SelectedItem != null)
            {
                (this.listview_list.ItemContainerGenerator.ContainerFromItem(this.listview_list.SelectedItem) as ListViewItem).IsSelected = false;
            }
        }
    }
}