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

namespace QC.QTMApplication;

[Serializable]
public class WPFGridSettings
{
	private List<GridRowDefinitionSettings> rowDefinitionSettings = new List<GridRowDefinitionSettings>();

	private List<GridColumnDefinitionSettings> columnDefinitionSettings = new List<GridColumnDefinitionSettings>();

	public List<GridRowDefinitionSettings> RowDefinitionSettings
	{
		get
		{
			return rowDefinitionSettings;
		}
		set
		{
			rowDefinitionSettings = value;
		}
	}

	public List<GridColumnDefinitionSettings> ColumnDefinitionSettings
	{
		get
		{
			return columnDefinitionSettings;
		}
		set
		{
			columnDefinitionSettings = value;
		}
	}

	public void SaveGridSettings(Grid wpfGrid)
	{
		rowDefinitionSettings.Clear();
		columnDefinitionSettings.Clear();
		GridLengthConverter gridLengthConverter = new GridLengthConverter();
		for (int i = 0; i < wpfGrid.RowDefinitions.Count; i++)
		{
			rowDefinitionSettings.Add(new GridRowDefinitionSettings
			{
				Height = gridLengthConverter.ConvertToString(wpfGrid.RowDefinitions[i].Height)
			});
		}
		for (int j = 0; j < wpfGrid.ColumnDefinitions.Count; j++)
		{
			columnDefinitionSettings.Add(new GridColumnDefinitionSettings
			{
				Width = gridLengthConverter.ConvertToString(wpfGrid.ColumnDefinitions[j].Width)
			});
		}
	}

	public void LoadGridSettings(Grid wpfGrid)
	{
		GridLengthConverter gridLengthConverter = new GridLengthConverter();
		for (int i = 0; i < rowDefinitionSettings.Count; i++)
		{
			wpfGrid.RowDefinitions[i].Height = (GridLength)gridLengthConverter.ConvertFromString(rowDefinitionSettings[i].Height);
		}
		for (int j = 0; j < columnDefinitionSettings.Count; j++)
		{
			wpfGrid.ColumnDefinitions[j].Width = (GridLength)gridLengthConverter.ConvertFromString(columnDefinitionSettings[j].Width);
		}
	}

	public void ClearDefinitionSettings()
	{
		rowDefinitionSettings.Clear();
		columnDefinitionSettings.Clear();
	}
}
