#include "gui/guecstra.hpp"

namespace guecs {

  Clickable make_action(GameLevel& target, Events::GUI event) {
    return {[&, event](auto gui_id, auto data){
      // BUG: either get rid of gui_id or also send a reference the the $gui that is sending the event
      target.world->send<Events::GUI>(event, gui_id, data);
    }};
  }

  Clickable make_action(GameLevel& target, Events::GUI event, std::any data) {
    return {[&, event, data](auto gui_id, auto){
      target.world->send<Events::GUI>(event, gui_id, data);
    }};
  }

  DinkyECS::Entity GrabSource::grab() {
    fmt::println("> Grab entity {}", world_entity);
    return world_entity;
  }

  void GrabSource::setSprite(guecs::UI& gui, guecs::Entity gui_id) {
    dbc::check(gui.has<guecs::Sprite>(gui_id), "GrabSource given sprite gui_id that doesn't exist");

    fmt::println("> Grabsource Set sprite entity {}", world_entity);

    auto& sp = gui.get<guecs::Sprite>(gui_id);
    sprite = sp.sprite;
  }

  void GrabSource::move(sf::Vector2f pos) {
    if(sprite) {
      sprite->setPosition(pos);
    }
  }
}
