//
// Created by sasha on 01.12.2025.
//

#include "record_line.h"

#include <format>

#include <SDL3/SDL_pixels.h>

RecordLine::RecordLine(IWidget *parent, float x, float y, bool first) : IWidget (parent,x,y,288,55) {
    this->first = first;

    if (first) {
        background = new Image(this, x, y, 288, 55, "record_record_first.png");
    }else{
        background = new Image(this, x, y, 288, 55, "record_record.png");
    }

    txtNumber = new Text(this, background->getFRect().x+20,background->getFRect().y+16);
    txtTime = new Text(this, background->getFRect().x+139,background->getFRect().y+16);
    txtTurn = new Text(this, background->getFRect().x+218,background->getFRect().y+16);

}

RecordLine::~RecordLine() {
    delete background;
    delete txtNumber;
    delete txtTime;
    delete txtTurn;
}

void RecordLine::setScore(int number, int turn, int time) {
    SDL_Color color = {255,255,255};
    if (first) color = {0xAF,0x87,0x05};

    int h = time/3600;
    int m = (time - h*3600)/60;
    int s = time - h*3600 - m*60;

    std::string str_time = std::format("{:02}:{:02}:{:02}", h, m, s);

    txtNumber->setText(std::to_string(number),"inter.ttf",20,color);
    txtTurn->setText(std::to_string(turn),"inter.ttf",20,color);
    txtTime->setText(str_time,"inter.ttf",20,color);


    txtTurn->move(background->getFRect().x+background->getFRect().w-txtTurn->getFRect().w-146,txtTurn->getFRect().y);
    txtTime->move(background->getFRect().x+background->getFRect().w-txtTime->getFRect().w-22,txtTime->getFRect().y);
}
