﻿using System.Collections.Generic;
using UnityEngine;
using System.Collections;

public class Sample : MonoBehaviour
{
    public GameObject infoPanel;
    public GameObject basePanel;
    public GameObject authPanel;
    public GameObject authUIPanel;
    public GameObject iapPanel;
    public GameObject logPanel;
    public GameObject pushPanel;
    public GameObject viewPanel;

    private List<GameObject> panels;
    // Start is called before the first frame update
    void Start()
    {
        panels = new List<GameObject>();
        panels.Add(infoPanel);
        panels.Add(basePanel);
        panels.Add(authPanel);
        panels.Add(authUIPanel);
        panels.Add(iapPanel);
        panels.Add(logPanel);
        panels.Add(pushPanel);
        panels.Add(viewPanel);

        onClick(0);

        Application.logMessageReceived += (condition, stackTrace, type) =>
        {
            DebugLogViewDialog.AddLog(condition);
        };
#if UNITY_ANDROID
        AndroidJavaObject wrapper = new AndroidJavaObject("com.stove.unity.UnitySampleWrapper");
        wrapper.CallStatic("setWebContentsDebuggingEnabled");
#endif
    }

    int click = 0;
    void Update()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                SSTools.ShowMessage("Please click BACK again to exit.", SSTools.Position.bottom, SSTools.Time.oneSecond);
                click++;
                StartCoroutine(ClickTime());

                if (click > 1)
                {
                    Application.Quit();
                }
            }
        }
    }
    IEnumerator ClickTime()
    {
        yield return new WaitForSeconds(1f);
        click = 0;
    }

    public void onClick(int tag)
    {
        for (int i = 0; i < panels.Count; i++)
        {
            if (i == tag)
            {
                panels[i].SetActive(true);
            }
            else
            {
                panels[i].SetActive(false);
            }
        }

        if (tag == 0)
        {
            InfoSample.Print();
        }
    }

    public void OnClickDebug()
    {
        DebugLogViewDialog.Show();
    }
}
