#pragma once

#include <QColor>
#include <QPixmap>
#include <QString>
#include <QWidget>

class QLabel;

// One label/value line: the name on the left, the value hard right
// (REQ-UI-SELECTION-CARD). The panel's plainest part, shared by the ship and station
// stats, the debris scrap, the HQ block stock, and the multi-selection's total cost.
//
// Like the other card parts it knows nothing about the simulation: it is given the two
// strings and lays them out.
class StatRow : public QWidget
{
    Q_OBJECT

public:
    explicit StatRow(const QString& label, QWidget* parent = nullptr);

    void setLabel(const QString& label);
    void setValue(const QString& value);
    // Draws an item icon after the value, bare and without its colored square: the icon
    // stands in for the item's name beside the number rather than displaying the item
    // (REQ-UI-ITEM-ICON), which is how a debris card states its scrap
    // (REQ-UI-DEBRIS-PANEL). A null pixmap -- what a missing icon file yields -- leaves
    // the value plain text, and the caller names the item in the label instead.
    void setValueIcon(const QPixmap& icon);
    // Draws the value in the palette's highlight color rather than its text color, for
    // the one value a card is really about.
    void setValueEmphasized(bool emphasized);
    // Indents the row, so it reads as belonging to the row above it -- the scrap total
    // under a debris count (REQ-UI-FIELD-MULTI-SELECTION).
    void setIndented(bool indented);
    // The widget the value is drawn in, number and item icon together, for a caller that
    // gives it the tooltip of the item it names (REQ-UI-ITEM-VALUE-TOOLTIP). Exposed
    // rather than attached here: this row knows nothing of the simulation, which is what
    // lets it serve the balancing tool as well as the panel.
    QWidget& getValueWidget();

private:
    // Re-states the value in whichever form it currently takes. Needed because the icon
    // form is one composed pixmap, which has to be built anew whenever the text or the
    // color it is drawn in changes.
    void   updateValue();
    QColor getValueColor() const;

    QLabel* m_labelLabel;
    QLabel* m_valueLabel;
    QString m_value;
    QPixmap m_valueIcon;
    bool    m_valueEmphasized;
};
