using System;
using UnityEngine;
using UnityEngine.UI;

public sealed class ControlPanel : MonoBehaviour
{
    [SerializeField]
    private Text baseStatus = null;
    [SerializeField]
    private BuildButton[] buttons = null;

    private Action<ProjectBlueprint> onBlueprintSelected = null;


    public void UpdateProperties(string properties = null)
    {
        baseStatus.text = properties ?? string.Empty;
    }

    public void Show(ProjectBlueprint[] structures = null, Action<ProjectBlueprint> result = null)
    {
        onBlueprintSelected = result;
        for (int i = 0; i < buttons.Length; i++) {
            if (structures != null && i < structures.Length)
            {
                var structure = structures[i];
                buttons[i].Show(structure.ID, structure.Cost, () => {
                    BuildStructure(structure);
                });
            }
            else
            {
                buttons[i].Hide();
            }
        }
    }

    private void BuildStructure(ProjectBlueprint project)
    {
        onBlueprintSelected?.Invoke(project);
    }
}
