#include "timePlayedWidget.h"

TimePlayedWidget::TimePlayedWidget(QWidget* parent)
    : QWidget(parent)
{
    label_ = new QLabel("00:00 / 00:00", this);
    label_->setAlignment(Qt::AlignCenter);
    label_->setStyleSheet("font-size: 12px; color: #666;");

    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(label_);
}

QString TimePlayedWidget::formatTime(qint64 ms) const
{
    int sec = ms / 1000;
    int min = sec / 60;
    int s = sec % 60;

    return QString("%1:%2")
        .arg(min, 2, 10, QChar('0'))
        .arg(s, 2, 10, QChar('0'));
}

void TimePlayedWidget::setDuration(qint64 ms)
{
    duration_ = ms;
}

void TimePlayedWidget::setPosition(qint64 ms)
{
    if (duration_ > 0)
    {
        label_->setText(
            QString("%1 / %2")
                .arg(formatTime(ms))
                .arg(formatTime(duration_))
            );
    }
}

void TimePlayedWidget::reset()
{
    duration_ = 0;
    label_->setText("00:00 / 00:00");
}
