#include "UIMLCraftingProgress.h"

#include "Globals.h"
#include "UIMLProgressAndStateView.h"
#include "UIMLUtils.h"

UIMLCraftingProgressElement::UIMLCraftingProgressElement()
    : UIMLElement()
{}

bool UIMLCraftingProgressElement::isApplicableFor(
    Framework::XML::Element& element)
{
    return element.getName().isEqual("craftingProgress");
}

Framework::Drawable* UIMLCraftingProgressElement::parseElement(
    Framework::XML::Element& element, Framework::UIMLContainer& generalFactory)
{
    int addressLength = 0;
    int* address = getUIMLTargetAddress(
        element.getAttributeValue("target"), addressLength);
    UIMLProgressAndStateView* view
        = new UIMLProgressAndStateView(element.getAttributeValue("id"),
            element.getAttributeValue("backgroundImagePath"),
            element.getAttributeValue("foregroundImagePath"),
            address,
            addressLength,
            1,
            3,
            "Progress: ",
            " ticks");
    Framework::Text direction = element.getAttributeValue("direction");
    view->setStyle(UIMLProgressAndStateView::Style::Visible
                   | UIMLProgressAndStateView::Style::Allowed);
    if (direction.isEqual("TOP") || direction.isEqual("BOTTOM"))
    {
        view->addStyle(UIMLProgressAndStateView::Style::Vertical);
    }
    if (direction.isEqual("TOP") || direction.isEqual("LEFT"))
    {
        view->addStyle(UIMLProgressAndStateView::Style::Reversed);
    }
    return view;
}

bool UIMLCraftingProgressElement::updateElement(
    Framework::XML::Element& element,
    Framework::Drawable& z,
    Framework::UIMLContainer& generalFactory)
{
    return false; // No update needed for this element
}