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

public class salaScene_bottom : MonoBehaviour
{
    private int oldIdx = -1;
    public int OldIdx
    {
        get
        {
            return oldIdx;
        }
        set
        {
            if (value >=0 && value < gameObject.transform.childCount)
            {
                if (oldIdx >= 0)
                {
                    Button button = transform.GetChild(oldIdx).gameObject.GetComponent<Button>();
                    button.interactable = true;
                    utilsTools.sendEventObjectParams("switchPage", transform.GetChild(OldIdx).name,false);
                }
                oldIdx = value;
                Button button1 = transform.GetChild(oldIdx).gameObject.GetComponent<Button>();
                button1.interactable = false;
                utilsTools.sendEventObjectParams("switchPage", transform.GetChild(OldIdx).name,true);

            }
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        utilsTools.addTimer_Update(gameObject, "next", (string name) =>
        {
            int count = gameObject.transform.childCount;
            List<System.Object> objects = new List<System.Object> { "", false };
            for (int i = 0; i < count; i++)
            {
                var gobjectItem = this.gameObject.transform.GetChild(i);
                objects[0] = gobjectItem.name;
                Button button = gobjectItem.GetComponent<Button>();
                var btn = new UnityEngine.UI.Button.ButtonClickedEvent();


                utilsTools.sendEventObjectParams("switchPage", gobjectItem.gameObject, "zhang", i);
                btn.AddListener(() => {
                    Int32 i2 = -1;
                    System.Object i3 = i2;
                    if (utilsTools.getUserData<Int32>(gobjectItem.gameObject, "zhang", out i3, 100000) == true)
                    {
                        this.selectByIdx((Int32)i3);
                    }
                });
                button.onClick = btn;
            }
            OldIdx = 0;
            return false;
        }, 1);
        
    }
    private void selectByIdx(int i)
    {
        OldIdx = i;
        
    }
    
    // Update is called once per frame
    void Update()
    {
    }
}
