using System.Diagnostics;
using System.IO;
using UnityEditor;
using UnityEngine;

namespace JohnsonUtils.SaveSystem
{
    [CustomEditor(typeof(SaveManager), true)]
    public class SaveManagerInspector : UnityEditor.Editor
    {
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            SaveManager saveManager = (SaveManager) target;
            GUI.enabled = EditorApplication.isPlaying;
            EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Save", EditorStyles.miniButtonLeft))
            {
                saveManager.Save();
            }
            
            if (GUILayout.Button("Load", EditorStyles.miniButtonRight))
            {
                saveManager.Load();
            }
            EditorGUILayout.EndHorizontal();
            
            if (GUILayout.Button("Save to Json"))
            {
                saveManager.SaveExplicit();
            }

            GUI.enabled = true;
            if (GUILayout.Button("Open explicit save in notepad++"))
            {
                Process.Start("notepad++.exe", Path.Combine(Application.dataPath, "../") + "saveData01.json");
            }
            EditorGUI.EndDisabledGroup();
        }
    }
}