#include "Component.hpp"
#include <iostream>
#include <algorithm>

Component::Component() {
}

Component::~Component() {
}

bool operator==(const Component &c1, const Component &c2) {
    return true;
}

void Component::Update(SDL_Event e, int frame, std::vector<std::string> broadcastList) {}

void Component::Render(SDL_Renderer *ren) {}

void Component::ShowComponentEditor(bool* showEditor){
    ImGuiWindowFlags window_flags = 0;
    window_flags |= ImGuiWindowFlags_MenuBar;
    window_flags |= ImGuiWindowFlags_NoCollapse;

    if(ImGui::Begin("Editing Default Component", showEditor, window_flags)){
        ImGui::Text("You shouldn't be seeing this!");
        ImGui::End();
    }
}

bool Component::HasTag(ComponentTag t){
    for(int i = 0; i < tags.size(); ++i){
        if(tags[i] == t) return true;
    }
    return false;
}

void Component::ParseAndUpdateBroadcast(std::vector<std::string> broadcastList){
    // Delete any messages in broadcastList that came back around
    for(int ii = 0; ii < previousBroadcasts.size(); ii++) {
        auto it = std::find(broadcastList.begin(), broadcastList.end(), previousBroadcasts[ii]);
        if (it != broadcastList.end()) {
            broadcastList.erase(it);
        }
    }

    // Insert pending broadcasts to the broadcast list
    broadcastList.insert(broadcastList.begin(), pendingBroadcasts.begin(), pendingBroadcasts.end());
    previousBroadcasts = pendingBroadcasts;
    pendingBroadcasts.clear();
}
