#include "DebrisContent.h"

#include <QVBoxLayout>

#include "DebrisScrap.h"
#include "Simulation.h"
#include "StatRow.h"

DebrisContent::DebrisContent(const SelectionContext& context,
                             const SelectionRequest& request, QWidget* parent)
    : SelectionContent(context, std::nullopt, parent)
    , m_debris(request.debris)
{
    m_scrapRow = new StatRow(tr("Scrap remaining"), this);
    m_scrapRow->setValueEmphasized(true);
    getRuntimeLayout()->addWidget(m_scrapRow);

    setIdentity(QPixmap(), tr("Debris"));
    if (m_debris.size() > 1)
    {
        setCountSlot(static_cast<int>(m_debris.size()));
    }
}

void DebrisContent::refreshRuntime()
{
    // The value falls as the debris is collected and as pieces despawn
    // (REQ-UI-DEBRIS-CLICK-SELECT), so it is re-summed rather than remembered. With
    // several pieces selected it is their sum (REQ-UI-SELECTION-AGGREGATE).
    m_scrapRow->setValue(QString::number(
        sumDebrisScrap(getContext().sim->getAdmin(), m_debris)));
}
