#include <iostream>
#include <ostream>
#include <DangerousRacers/Label.h>

Label::Label(const std::string &labelString, const sf::Vector2f position, const bool _center, const bool _outline) {
    center = _center;
    outline = _outline;

    static bool fontLoaded = false;
    static sf::Font font;

    if (!fontLoaded) {
        std::cout << "Loading font..." << std::endl;
        fontLoaded = true;
        font.loadFromFile("assets/jersey.ttf");
        font.setSmooth(false);
    }

    labelText.setFont(font);
    // labelText.setString(labelString);
    // labelText.setPosition(position);

    labelText.setCharacterSize(32);
    labelText.setFillColor(darkMode ? sf::Color::Black : sf::Color::White);
    if (outline) {
        labelText.setOutlineColor(darkMode ? sf::Color::White : sf::Color::Black);
        labelText.setOutlineThickness(2);
    }

    setText(labelString);
    setPosition(position);
}

void Label::setText(const std::string &labelString) {
    labelText.setString(labelString);
    if (center) labelText.setOrigin(labelText.getLocalBounds().width / 2, labelText.getLocalBounds().height / 2);
}

void Label::setPosition(const sf::Vector2f position) {
    if (center) labelText.setOrigin(labelText.getLocalBounds().width / 2, labelText.getLocalBounds().height / 2);
    labelText.setPosition(position);
}

void Label::render(sf::RenderWindow &window) const {
    window.draw(labelText);
}
