﻿using Hub.Client.Windows.UserInterface.Uploader.List;
using Hub.Domain.FileAntModule.Aggregate;
using System.Linq;
using System.Windows.Controls;

namespace Hub.Client.Windows.UserInterface.Uploader
{
    /// <summary>
    /// Interaction logic for UC_Weight.xaml
    /// </summary>
    public partial class UcUpload : UserControl
    {
        private readonly IUploadContainerViewModel _viewModel;
        public UcUpload(IUploadContainerViewModel viewModel)
        {
            DataContext = viewModel;
            _viewModel = viewModel;
            _viewModel.OnListChange += ViewModel_OnListChange;
            InitializeComponent();
            LoadList();
        }

        private int ViewModel_OnListChange()
        {
            LoadList();
            return 0;
        }

        private void LoadList()
        {
            GridWeightList.Children.Add(new UcUploadList(_viewModel.ShowOnlyNew ?
                _viewModel.DataList.Where(b => (b.Value.Status != FileStatus.ReadyToDownload) && b.Value.IsActive).ToList() :
                _viewModel.DataList.Where(b => b.Value.IsActive).ToList()));

        }

    }


}
