using UnityEditor;
using UnityEngine;
namespace Adplay.View
{
    [CustomEditor(typeof(AdPlayTemplate))]
    public class AdPlayTemplateEditor : Editor
    {
        SerializedProperty rectTransform;
        SerializedProperty image;
        SerializedProperty clickButton;
        SerializedProperty titleText;
        SerializedProperty descriptionText;
        SerializedProperty clickButtonText;

        private void OnEnable()
        {
            rectTransform = serializedObject.FindProperty("rectTransform");
            image = serializedObject.FindProperty("image");
            clickButton = serializedObject.FindProperty("clickButton");
            titleText = serializedObject.FindProperty("titleText");
            descriptionText = serializedObject.FindProperty("descriptionText");
            clickButtonText = serializedObject.FindProperty("clickButtonText");
        }

        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            DrawField(rectTransform, "Important: RectTransform is used to set the ad full size to parent. Method FullSizeToParent will not work correctly without it.", MessageType.Error);
            DrawField(image, "REQUIRED: This Image component is used to display the ad. The SDK will not work correctly without it.", MessageType.Error);
            DrawField(clickButton, "REQUIRED: This Button is used to handle ad clicks. PopUp and PopUpButton will not work correctly without it.", MessageType.Error);

            DrawField(titleText, "IMPORTANT: Text component used for the PopUp and PopUpButton title.", MessageType.Info);
            DrawField(descriptionText, "IMPORTANT: Text component used for the PopUp description.", MessageType.Info);
            DrawField(clickButtonText, "IMPORTANT: Text component used for the PopUpButton text.", MessageType.Info);

            serializedObject.ApplyModifiedProperties();
        }

        private void DrawField(SerializedProperty property, string message, MessageType type)
        {
            if (property.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox(message, type);
            }

            EditorGUILayout.PropertyField(property);

            EditorGUILayout.Space();
        }
    }



}
