#include "RecipeTooltip.h"

#include <QObject>
#include <QStringList>

#include "DisplayName.h"
#include "RecipesConfig.h"

namespace
{

QString itemLine(const std::string& itemId, int amount)
{
    return QStringLiteral("  ")
        + QString::fromStdString(toDisplayName(itemId))
        + QStringLiteral(" x ") + QString::number(amount);
}

}  // namespace

QString buildRecipeTooltip(const RecipeDef& recipe)
{
    QStringList lines;
    lines << QObject::tr("Recipe: %1")
        .arg(QString::fromStdString(toDisplayName(recipe.id)));

    if (recipe.inputs.empty())
    {
        lines << QObject::tr("Inputs: none");
    }
    else
    {
        lines << QObject::tr("Inputs:");
        for (const RecipeIngredient& ingredient : recipe.inputs)
        {
            lines << itemLine(ingredient.item, ingredient.amount);
        }
    }

    lines << QObject::tr("Completion time: %1 s").arg(recipe.durationSeconds);

    if (!recipe.outputs.empty())
    {
        lines << QObject::tr("Produces:");
        for (const RecipeOutput& output : recipe.outputs)
        {
            lines << itemLine(output.item, output.amount);
        }
    }

    return lines.join('\n');
}
