/*
<copyright file="BGGCAddRow.cs" company="BansheeGz">
    Copyright (c) 2018-2021 All Rights Reserved
</copyright>
*/


using GameCreator.Core;
using GameCreator.Variables;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace BansheeGz.BGDatabase
{
    public abstract class BGGCAction : IAction
    {

        // +--------------------------------------------------------------------------------------+
        // | EDITOR                                                                               |
        // +--------------------------------------------------------------------------------------+

#if UNITY_EDITOR

        protected abstract string Title { get; }
        public override string GetNodeTitle() => Title;

        protected SerializedProperty Prop(string name) => serializedObject.FindProperty(name);

        public override void OnInspectorGUI()
        {
            if (!BGRepo.DefaultRepoLoaded) BGRepo.Load();
            if (!BGRepo.Ok)
            {
                EditorGUILayout.HelpBox("Database is not loaded!", MessageType.Error);
                return;
            }

            serializedObject.Update();
            try
            {
                EditorGui();
                serializedObject.ApplyModifiedProperties();
            }
            catch (ExitGUIException)
            {
                serializedObject.ApplyModifiedProperties();
                throw;
            }
        }

        public virtual void EditorGui()
        {
            
        }
#endif
    }
}