#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) {
    if(auto sp = gui.get_if<guecs::Icon>(gui_id)) {
      sprite = sp->sprite;
    } else if(auto sp = gui.get_if<guecs::Sprite>(gui_id)) {
      sprite = sp->sprite;
    } else {
      dbc::sentinel("GrabSource given sprite gui_id that doesn't exist");
    }
  }

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