#include "angelscript.h"
#include "DeerStudio/EditorEngine.h"
#include "DeerStudio/EditorEngine/DockPanelObject.h"
#include "DeerStudio/EditorEngine/ErrorHandle.h"

namespace Deer {
    void EditorEngine::registerDockPanel() {
        AS_RET_CHECK(scriptEngine->RegisterInterface("DockPanel"));

        AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("DockPanel", "void onRender()"));
    }

    void EditorEngine::extractDockPanels() {
        size_t nScripts = scriptModule->GetObjectTypeCount();

        asITypeInfo* dockPanelType = scriptEngine->GetTypeInfoByName("DockPanel");
        if (!dockPanelType) {
            DEER_UI_ENGINE_ERROR("Could not load DockPanel interface type");
            return;
        }

        for (size_t i = 0; i < nScripts; i++) {
            asITypeInfo* info = scriptModule->GetObjectTypeByIndex(i);

            // If it does not implement dock panel we are not interested int it
            if (!info->Implements(dockPanelType))
                continue;

            dockPanels.push_back({info});
        }
    }
}