using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class ModuleGrid {

	public static GameObject modulesUI;
	public static GameObject[] modulesPanels; //where to clone the modules' UI, depending on their tab

	public static void constructModules(Class unitClass) {
		float width = modulesPanels[0].GetComponent<RectTransform>().rect.width;
		float height = modulesPanels[0].GetComponent<RectTransform>().rect.height;

		foreach (ModuleUI moduleUI in unitClass.getModulesUI()) {
			GameObject clone = GameObject.Instantiate(modulesUI.transform.FindChild(moduleUI.getName()).gameObject, modulesPanels[moduleUI.getTab()].transform);

			RectTransform transform = clone.GetComponent<RectTransform>();

			transform.localPosition = new Vector3(moduleUI.getX() * width / Constants.MODULE_GRID_WIDTH, moduleUI.getY() * height / Constants.MODULE_GRID_HEIGHT, 0);
			transform.sizeDelta = new Vector2(moduleUI.getWidth() * width / Constants.MODULE_GRID_WIDTH, moduleUI.getHeight() * height / Constants.MODULE_GRID_HEIGHT);

			clone.name = moduleUI.getName();
		}
	}

	public static void updateModules(DeployedUnit selectedUnit) {
		foreach(GameObject tab in modulesPanels) {
			foreach (Transform child in tab.transform) {
				string name = child.gameObject.name;

				if (name == "ArleighMk-41") {
					updateModuleArleighMk_41(selectedUnit, child.gameObject);
				}
			}
		}
	}

	private static void updateModuleArleighMk_41(DeployedUnit selectedUnit, GameObject moduleUIElement) {
		
	}
}
