using UnityEngine;
using System.Collections.Generic;

public class MorphPanel : MonoBehaviour
{
    [SerializeField] private MorphPanelCategory _morphPanelCategoryPfb;
    [SerializeField] private Transform _categoryPanels;
    public Dictionary<string, MorphPanelCategory> Categories = new Dictionary<string, MorphPanelCategory>();

    public static MorphPanel Create(List<string> categories)
    {
        var panel = Instantiate(SharedResources.Instance.MorphPanel, ModelViewerInterface.GetInstance().DynamicPanels.transform);
        panel.Init(categories);
        return panel;
    }

    public void Init(List<string> categories)
    {
        for(int i = _categoryPanels.childCount-1; i >= 0; i--)
        {
            Destroy(_categoryPanels.GetChild(i).gameObject);
        }

        Categories.Clear();
        foreach (var category in categories)
        {
            var categoryPanel = Instantiate(_morphPanelCategoryPfb, _categoryPanels);
            categoryPanel.Label.text = category;
            Categories[category] = categoryPanel;
        }
    }

    public SliderPanel CreateMorph(string category, ObjectContainer container, SkinnedMeshRenderer meshRenderer, int index, string displayName)
    {
        return SliderPanel.CreateMorph(container, meshRenderer, index, displayName, this.Categories[category].Content);
    }
}
