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

[ExecuteAlways]
public class PageManager : MonoBehaviour
{
    [SerializeField] private List<PageController> Pages;
    [SerializeField] private RectTransform Sidebar;
    private RectTransform RectTransform;

    public static PageManager Instance;

    private void Awake()
    {
        Instance = this;
        RectTransform = GetComponent<RectTransform>();
    }

    float previous = 0;
    private void LateUpdate()
    {
        if(previous != Sidebar.rect.width)
        {
            RectTransform.offsetMin = new Vector2(Sidebar.rect.width, RectTransform.offsetMin.y);
            previous = Sidebar.rect.width;
        }
    }

    public void DisplayPage(Transform page)
    {
        Pages.FirstOrDefault(z => z.transform == page).Display();
        Pages.Where(z => z.transform != page).ToList().ForEach(z => z.Hide());
    }
}