﻿using UnityEngine;
using UnityEditor;

namespace nanoSDK
{
    [InitializeOnLoad]
    public class nanoSDK_Info : EditorWindow
    {

        static nanoSDK_Info()
        {
            EditorApplication.update -= DoSplashScreen;
            EditorApplication.update += DoSplashScreen;
        }

        private static void DoSplashScreen()
        {
            EditorApplication.update -= DoSplashScreen;
            if (!EditorPrefs.HasKey("nanoSDK_ShowInfoPanel"))
            {
                EditorPrefs.SetBool("nanoSDK_ShowInfoPanel", true);
            }
            if (EditorPrefs.GetBool("nanoSDK_ShowInfoPanel"))
                OpenSplashScreen();
        }

        private static Vector2 changeLogScroll;
        private static GUIStyle vrcSdkHeader;
        [MenuItem("nanoSDK/Info", false, 500)]
        public static void OpenSplashScreen()
        {
            GetWindow<nanoSDK_Info>(true);
        }
        
        public static void Open()
        {
            OpenSplashScreen();
        }

        public void OnEnable()
        {
            titleContent = new GUIContent("nanoSDK Info");
            
            minSize = new Vector2(400, 700);;

            vrcSdkHeader = new GUIStyle
            {
                normal =
                    {
                       background = Resources.Load("nanoSdkHeader") as Texture2D,
                       textColor = Color.white
                    },
                fixedHeight = 200
            };
        }

        public void OnGUI()
        {
            GUILayout.Box("", vrcSdkHeader);
            GUILayout.Space(4);
            GUI.backgroundColor = Color.gray;
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("SDK made by lyze and zLucPlayZ"))
            {
                Application.OpenURL("https://nanosdk.net/header");
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("nanoSDK Discord"))
            {
                Application.OpenURL("https://nanosdk.net/discord");
            }
            if (GUILayout.Button("nanoSDK Website"))
            {
                Application.OpenURL("https://nanoSDK.net/");
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(4);
            GUILayout.Label("nanoSDK Version 1.0");
            GUILayout.Space(2);
            GUILayout.Label("Please check out the nanoSDK Settings menu :3");
            GUILayout.Label("Instructions for built in features and changelog");
            changeLogScroll = GUILayout.BeginScrollView(changeLogScroll, GUILayout.Width(390));

            GUILayout.Label(
@"
== V1.0 ==

Import panel:
- Import panel reworked. Assets are now hosted on the
nanoSDK Server to make sure you always download the newst
version.
- Besides that you can now look for an update of the asset list.
It also looks for updates automatically from time to time.
This means we have the ability to ship new assets without
requiring an update of the SDK.
- Added Settings options. Defines the asset download folder.
This Setting is for every project.
- Added a download progressbar.

Overall:
- Fixes
- Optimization

== V0.9 ==

Visemes auto assign:
- To use it, select 'Viseme Blend Shape' and assign the
Skinned Mesh Renderer in the VRC_AvatarDescriptor as you
used to. To auto assign the the blendshapes right-click
the VRC_AvatarDescriptor and select 'Auto assign visemes'.

Import panel:
To import an asset, just click a button to import it.
Larger assets need to be downloaded first, thats why it
says 'Download' and not 'Import' on some buttons. After
you clicked the 'Download' button the button text should
change and you should be able to import your asset like
the other. Make sure you wait for the asset to download
completely, you can check this by opening the console and
look for the message that says
'Download of file [AssetName] completed!'
");
            GUILayout.EndScrollView();

            GUILayout.BeginHorizontal();
            EditorPrefs.SetBool("nanoSDK_ShowInfoPanel", GUILayout.Toggle(EditorPrefs.GetBool("nanoSDK_ShowInfoPanel"), "Show at startup"));
            GUILayout.EndHorizontal();
        }

    }
}