/* Copyright (C) Itseez3D, Inc. - All Rights Reserved
* You may not use this file except in compliance with an authorized license
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* UNLESS REQUIRED BY APPLICABLE LAW OR AGREED BY ITSEEZ3D, INC. IN WRITING, SOFTWARE DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED
* See the License for the specific language governing permissions and limitations under the License.
* Written by Itseez3D, Inc. <support@avatarsdk.com>, August 2026
*/

using UnityEditor;
using UnityEngine;

namespace AvatarSDKMove.Editor
{
	public class AboutWindow : EditorWindow
	{
		private const string Copyright = "© Itseez3D, Inc. All rights reserved.";

		private GUIStyle titleStyle;

		[MenuItem("Avatar SDK Move/About", priority = 11)]
		public static void ShowWindow()
		{
			AboutWindow window = GetWindow<AboutWindow>("About");
			window.minSize = new Vector2(420, 320);
			window.Show();
		}

		private void OnGUI()
		{
			if (titleStyle == null)
			{
				titleStyle = new GUIStyle(EditorStyles.boldLabel)
				{
					fontSize = 18
				};
			}

			GUILayout.Space(10);
			GUILayout.Label("Avatar SDK Move", titleStyle);

			EditorGUILayout.LabelField("Version " + AvatarSDKMoveSettings.Version);
			EditorGUILayout.LabelField(Copyright);

			GUILayout.Space(10);
			EditorGUILayout.HelpBox(AvatarSDKMoveSettings.BetaNotice, MessageType.Info);
			GUILayout.Space(15);

			if (GUILayout.Button("Samples", GUILayout.Height(24)))
				PingAsset(AvatarSDKMoveSettings.SamplesFolderGuid, "samples");

			if (GUILayout.Button("Documentation", GUILayout.Height(24)))
				OpenDocument(AvatarSDKMoveSettings.ReadmeGuid, "documentation");

			if (GUILayout.Button("Contact Us: " + AvatarSDKMoveSettings.SupportEmail, GUILayout.Height(24)))
				Application.OpenURL("mailto:" + AvatarSDKMoveSettings.SupportEmail);
		}

		private static Object PingAsset(string guid, string description)
		{
			string path = AssetDatabase.GUIDToAssetPath(guid);
			Object asset = string.IsNullOrEmpty(path) ? null : AssetDatabase.LoadMainAssetAtPath(path);

			if (asset == null)
			{
				Debug.LogWarningFormat("Could not find the Avatar SDK Move {0} in this project.", description);
				return null;
			}

			Selection.activeObject = asset;
			EditorGUIUtility.PingObject(asset);
			return asset;
		}

		private static void OpenDocument(string guid, string description)
		{
			Object document = PingAsset(guid, description);
			if (document != null)
				AssetDatabase.OpenAsset(document);
		}
	}
}
