using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CtrEditor.ObjetosSim;
using System.Collections.ObjectModel;
using System.Windows;
using CtrEditor.ObjetosSim.Extraccion_Datos;
namespace CtrEditor.PopUps
{
///
/// Interaction logic for AssignImagesWindow.xaml
///
public partial class AssignImagesWindow : Window
{
public AssignImagesWindow()
{
InitializeComponent();
}
}
public partial class AssignImagesViewModel : ObservableObject
{
private MainViewModel _mainViewModel;
private Window _window;
private bool _closeOK;
[ObservableProperty]
private ObservableCollection objetosSimulables;
[ObservableProperty]
private ObservableCollection listaImagenes;
[ObservableProperty]
private ObservableCollection selectedObjetosSimulables;
[ObservableProperty]
private ObservableCollection selectedImagenes;
public AssignImagesViewModel()
{
SelectedImagenes = new ObservableCollection();
ListaImagenes = new ObservableCollection();
ObjetosSimulables = new ObservableCollection();
SelectedObjetosSimulables = new ObservableCollection();
SelectedObjetosSimulables.CollectionChanged += SelectedObjetosSimulables_CollectionChanged;
}
public void Initialize(MainViewModel mainViewModel, Window window)
{
_mainViewModel = mainViewModel;
_window = window;
ObjetosSimulables = new ObservableCollection(_mainViewModel.ObjetosSimulables.Where(
o => o.Enable_On_All_Pages && ((o is osExtraccionTag ex && !ex.Cloned) || (o is osBuscarCoincidencias))));
ListaImagenes = _mainViewModel.ListaImagenes;
}
private void SelectedObjetosSimulables_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
UpdateSelectedImages();
}
private void UpdateSelectedImages()
{
var selectedImages = new HashSet();
foreach (var objeto in SelectedObjetosSimulables)
{
foreach (var image in objeto.ShowOnThisPagesList)
{
selectedImages.Add(image);
}
}
SelectedImagenes = new ObservableCollection(selectedImages);
}
[RelayCommand]
private void AssignImages()
{
foreach (var objeto in SelectedObjetosSimulables)
{
objeto.ShowOnThisPagesList = new List(SelectedImagenes);
objeto.Show_On_This_Page = objeto.Show_On_This_Page;
}
_closeOK = true;
_window.Close();
}
[RelayCommand]
private void TBSelectAll()
{
SelectedObjetosSimulables.Clear();
foreach (var obj in ObjetosSimulables)
{
SelectedObjetosSimulables.Add(obj);
}
}
[RelayCommand]
private void TBUnSelectAll()
{
SelectedObjetosSimulables.Clear();
}
[RelayCommand]
private void TBSelectAllIamges()
{
SelectedImagenes.Clear();
foreach (var img in ListaImagenes)
{
SelectedImagenes.Add(img);
}
}
[RelayCommand]
private void TBUnSelectAllImages()
{
SelectedImagenes.Clear();
}
public bool CloseOK => _closeOK;
}
}