/** @file JSMOMComponentCustom.cpp
 *
 * Copyright (C) Espial Limited 2014 - Company confidential - All rights reserved.
 *
 */

#include "config.h"

#if ENABLE(RMAI)

#include "MOMComponent.h"
#include "JSMOMComponent.h"
#include "JSMOMVideoComponent.h"
#include "JSMOMSubtitleComponent.h"
#include "JSMOMAudioComponent.h"

using namespace JSC;

namespace WebCore {

JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, MOMComponent* comp)
{
    if (!comp)
        return jsNull();

    JSObject* wrapper = getCachedWrapper(globalObject->world(), comp);
    if (wrapper)
        return wrapper;

    unsigned int type;
    mom_component_get_type(comp->component(), &type);
    switch (type)
    {
    case MOM_AUDIO_COMPONENT:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMAudioComponent, comp);
        break;
    case MOM_VIDEO_COMPONENT:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMVideoComponent, comp);
        break;
    case MOM_SUBTITLE_COMPONENT:
        wrapper = CREATE_DOM_WRAPPER(globalObject, MOMSubtitleComponent, comp);
        break;
    default:
    	wrapper = CREATE_DOM_WRAPPER(globalObject, MOMComponent, comp);
        break;
    }
    return wrapper;
}

} // namespace WebCore

#endif // ENABLE(RMAI)
