#include "HtmlParagraphElement.h"

std::string HtmlParagraphElement::toString(unsigned depth, bool keepInline) const
{
    const auto prefix = std::string(2*depth, ' ');

    auto content = prefix + "<" + getTagName();
    for (std::size_t idx=0; idx< getNumAttributes(); idx++)
    {
        auto attribute = getAttribute(idx);
        content += " " + attribute->getName() + "=\"" + attribute->getValue() + "\"";
    }

    const auto num_children = getNumChildren();
    if (num_children == 0 && getText().empty())
    {
        content += "/>\n";
        return content;
    }
    else
    {
        content += ">";
    }

    if (!getText().empty())
    {
        content += getText();
    }

    if (num_children>0)
    {
        content += "\n";
    }
    for (std::size_t idx=0; idx< getNumChildren(); idx++)
    {
        auto child = getChild(idx);
        content += child->toString(depth+1, true);
    }
    if (num_children>0)
    {
        content += prefix;
    }

    content += "</" + getTagName() + ">\n";
    return content;
}
