#include "UIMLFuelState.h"

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

UIMLFuelStateElement::UIMLFuelStateElement()
    : UIMLElement()
{}

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

Framework::Drawable* UIMLFuelStateElement::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,
            0,
            2,
            "Fuel: ",
            "");
    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 UIMLFuelStateElement::updateElement(Framework::XML::Element& element,
    Framework::Drawable& z,
    Framework::UIMLContainer& generalFactory)
{
    return false; // No update needed for this element
}