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

public class SUIPanelMobile : SUIObjectBase
{
    GameObject _panelMobile;

    //Panel_Control
    GameObject _panelControl;
    GameObject _buttonVOD;
    GameObject _buttonList;

    //Panel_Content
    GameObject _panelContent;
    GameObject _panelVOD;
    GameObject _inputField;
    GameObject _buttonPlay;
    // GameObject _panelList;

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

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

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

        _buttonVOD = _panelControl.transform.Find("Button_VOD").gameObject;
        Debug.Assert(_buttonVOD != null);

        _buttonList = _panelControl.transform.Find("Button_List").gameObject;
        Debug.Assert(_buttonList != null);

        _panelContent = _rootPanel.transform.Find("Panel_Content").gameObject;
        Debug.Assert(_panelContent != null);

        _panelVOD = _panelContent.transform.Find("Panel_VOD").gameObject;
        Debug.Assert(_panelVOD != null);

        _inputField = _panelVOD.transform.Find("InputField").gameObject;
        Debug.Assert(_inputField != null);

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

    public override void UI_BindTouchEvent()
    {
        BindButtonClick("Panel_Control/Button_VOD", onClickButtonVOD);
        BindButtonClick("Panel_Control/Button_List", onClickButtonList);
        BindButtonClick("Panel_Content/Panel_VOD/Button_Play", onClickButtonPlay);
    }

    private void onClickButtonVOD(GameObject buttonObject)
    {
        Debug.Log("SUIPanelMobile -> onClickButtonVOD");
    }

    private void onClickButtonList(GameObject buttonObject)
    {
        Debug.Log("SUIPanelMobile -> onClickButtonList");

    }

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

        string url = _inputField.GetComponent<InputField>().text;
        Debug.Log("url---->" + url);
        SLogicManager logicManager = GetComponent<SLogicManager>();
        logicManager.setVideoUrl(url);

        UnityEngine.SceneManagement.SceneManager.LoadScene("Mobile_Video");


        //IList result = logicManager.AddOfflineTask(url);
        //int resultCode = (int)result[0];
        //Debug.Log("--> resultCode <--" + resultCode);
        //switch (resultCode)
        //{
        //    case 0:
        //        logicManager.setVideoUrl(url);
        //        _panelVOD.SetActive(false);
        //        _panelVideo.SetActive(true);
        //        break;
        //    default:
        //        SUtils utils = GetComponent<SUtils>();
        //        utils.showNoticeDialog("播放失败");
        //        break;
        //}
    }
}
