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

public class SUIPanelMobileVideo : SUIObjectBase
{
    public Sprite playIcon;
    public Sprite pauseIcon;

    public bool isPlay = false;

    GameObject _panelControl;
    GameObject _textName;
    GameObject _buttonPlay;
    GameObject _buttonBack;

    public override void UI_Awake()
    {
        GameObject rootCanvas;
        rootCanvas = GameObject.Find("Canvas");
        Debug.Assert(rootCanvas != null);

        _rootPanel = rootCanvas.transform.Find("Panel_Mobile_Video").gameObject;
        Debug.Assert(_rootPanel != null);

        _panelControl = _rootPanel.transform.Find("Panel_Control").gameObject;
        Debug.Assert(_panelControl != null);

        _buttonPlay = _panelControl.transform.Find("Button_Play").gameObject;
        Debug.Assert(_buttonPlay != null);

        _buttonBack = _panelControl.transform.Find("Button_Back").gameObject;
        Debug.Assert(_buttonBack != null);

        //_textName = _panelControl.transform.Find("Text_Name").gameObject;
        //Debug.Assert(_textName != null);
    }

    public override void UI_RefreshInfo()
    {
        //_panelAddUrl.SetActive(true);
        _buttonPlay.GetComponent<Image>().sprite = pauseIcon;
    }

    public override void UI_BindTouchEvent()
    {
        BindButtonClick("Panel_Control/Button_Play", onClickButtonPlay);
        BindButtonClick("Panel_Control/Button_Back", onClickButtonBack);
    }

    private void onClickButtonPlay(GameObject buttonObject)
    {
        Debug.Log("SUIPanelMobileVideo --> onClickButtonPlay");

        SLogicManagerVideo logicManagerVideo = GetComponent<SLogicManagerVideo>();

        if (isPlay == false)
        {
            logicManagerVideo.OnPauseButton();
            _buttonPlay.GetComponent<Image>().sprite = playIcon;
        }
        else
        {
            logicManagerVideo.OnPlayButton();
            _buttonPlay.GetComponent<Image>().sprite = pauseIcon;
        }

        isPlay = !isPlay;
    }

    private void onClickButtonBack(GameObject buttonObject)
    {
        Debug.Log("SUIPanelMobileVideo --> onClickButtonBack");

        UnityEngine.SceneManagement.SceneManager.LoadScene("Mobile");
    }
}
