#include "TransformComponent.hpp"

TransformComponent::TransformComponent(int _x, int _y) {
    Vec2D v = Vec2D(_x, _y);
    position = v;
}

void TransformComponent::SetTransform(Vec2D _pos) {
    // printf("Position: X: %f, Y: %f", position.x, position.y);
    position = _pos;
    // printf("After Position: X: %f, Y: %f \n", position.x, position.y);
}

void TransformComponent::SetTransform(int _x, int _y) {
    Vec2D v = Vec2D(_x, _y);
    position = v;
}

Vec2D TransformComponent::getPos() const {
    return position;
}

TransformComponent::~TransformComponent() {
}

bool operator==(const TransformComponent &c1, const TransformComponent &c2) {
    Vec2D cV1 = c1.getPos();
    Vec2D cV2 = c2.getPos();

    if (fabs(cV1.x - cV2.x) > 0.00001 || fabs(cV1.y - cV2.y) > 0.00001 || fabs(cV1.w - cV2.w) > 0.00001) {
        return true;
    }

    return false;
}

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

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

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

    if(ImGui::Begin("Editing Transform Component", showEditor, window_flags)){
        ImGui::InputFloat("X Position", &position.x);
        ImGui::InputFloat("Y Position", &position.y);
        ImGui::End();
    }
}