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

namespace SimplifyXR
{


    public class PagingNav : MonoBehaviour
    {
        public GameObject pagingPrefab;

        [HideInInspector]
        public List<PageButton> pageButtons;

        public void ResetPagingButtons()
        {
            pageButtons = new List<PageButton>();
            var buttons = this.GetComponentsInChildren<Button>();

            buttons.ToList().ForEach(b =>
            {
                Destroy(b.gameObject);
            });
        }

        public void SetActivePage(int id)
        {
            pageButtons.ForEach(pb =>
            {
                pb.selected = id == pb.pageID;
                pb.UpdateState();
            });
        }


        public void AddPageButton(int id, Action buttonAction)
        {
            var go = Instantiate(pagingPrefab, this.transform);
            var pageButton = go.GetComponent<PageButton>();
            pageButton.SetupPageButton(id, buttonAction);
            pageButtons.Add(pageButton);
        }

    }

}