using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

namespace TFramework
{
    public class ReorderableListRef:IReference
    {
        public ReorderableList m_reorderableList;
        public bool m_isExpansion;

        public SerializedObject m_serializedObject;
        public SerializedProperty m_elements;
        public IList m_list;
        public Type m_elementType;

        public ReorderableListRef Init(SerializedObject serializedObject, SerializedProperty elements)
        {
            m_serializedObject = serializedObject;
            m_elements = elements;
            if(m_reorderableList!=null)
            {
                m_reorderableList.serializedProperty = elements;
            }
            else
            {
                m_reorderableList = new ReorderableList(serializedObject, elements);
            }
            return this;
        }

        public ReorderableListRef Init(IList elements, Type elementType)
        {
            m_list = elements;
            m_elementType = elementType;
            if (m_reorderableList != null)
            {
                m_reorderableList.list = elements;
            }
            else
            {
                m_reorderableList = new ReorderableList(elements, elementType);
            }
            return this;
        }

        public ReorderableListRef Init(SerializedObject serializedObject, SerializedProperty elements, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton)
        {
            m_serializedObject = serializedObject;
            m_elements = elements;
            if (m_reorderableList != null)
            {
                m_reorderableList.serializedProperty = elements;
                m_reorderableList.draggable = draggable;
                m_reorderableList.displayAdd = displayAddButton;
                m_reorderableList.displayRemove = displayRemoveButton;
            }
            else
            {
                m_reorderableList = new ReorderableList(serializedObject, elements, draggable, displayHeader, displayAddButton, displayRemoveButton);
            }
            return this;
        }

        public ReorderableListRef Init(IList elements, Type elementType, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton)
        {
            m_list = elements;
            m_elementType = elementType;
            if (m_reorderableList != null)
            {
                m_reorderableList.list = elements;
                m_reorderableList.draggable = draggable;
                m_reorderableList.displayAdd = displayAddButton;
                m_reorderableList.displayRemove = displayRemoveButton;
            }
            else
            {
                m_reorderableList = new ReorderableList(elements, elementType, draggable, displayHeader, displayAddButton, displayRemoveButton);
            }
            return this;
        }

        public void Reset()
        {
            m_reorderableList.list = null;
            m_isExpansion = false;
        }
    }
}
