using InABox.Core;
using InABox.Database;
using InABox.DynamicGrid;
using InABox.Wpf;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
namespace PRSServer.Forms
{
///
/// Interaction logic for ViewDeletionWindow.xaml
///
public partial class ViewDeletionWindow : ThemableWindow
{
private Deletion Deletion { get; set; }
private DeletionData DeletionData { get; set; }
private HashSet _loaded = new();
public ViewDeletionWindow(Deletion deletion)
{
InitializeComponent();
Deletion = deletion;
DeletionData = Serialization.Deserialize(deletion.Data) ?? new();
Pages.SelectionChanged += PagesSelectionChanged;
LoadPages();
}
private void PagesSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var tab = Pages.SelectedItem as DynamicTabItem;
if (!_loaded.Contains(tab))
{
var grid = tab.Content as IDynamicGrid;
grid.Refresh(true, true);
_loaded.Add(tab);
}
}
private void LoadPages()
{
foreach(var (entityName, cascade) in DeletionData.Cascades)
{
if (!CoreUtils.TryGetEntity(entityName, out var entityType)) continue;
var title = new Inflector.Inflector(new CultureInfo("en")).Pluralize(CoreUtils.GetCaption(entityType));
var tab = new DynamicTabItem() { Header = title };
var grid = Activator.CreateInstance(typeof(DeletedEntityGrid<>).MakeGenericType(entityType), cascade) as IDynamicGrid;
grid.Refresh(true, true);
tab.Content = grid;
Pages.Items.Add(tab);
}
}
}
}