﻿var $SIGIfind = function() { return SIGI.Application.findComponent.apply(SIGI.Application, arguments); }

// == SIGI.EventHandlerList Class ==
function _SIGI_EventHandlerListClass() {

    this._eventsArray = Array();

}

_SIGI_EventHandlerListClass.prototype.addHandler = function(eventName, handler) {


    this._eventsArray[eventName] = handler;

}

_SIGI_EventHandlerListClass.prototype.getHandler = function(eventName) {


    return this._eventsArray[eventName];

}

_SIGI_EventHandlerListClass.prototype.removeHandler = function(eventName, handler) {

    //TODO:
}

SIGI.EventHandlerList = _SIGI_EventHandlerListClass;


// == SIGI.Component Class ==
function _SIGIComponentClass() {
    this._id = null;
    this._events = null;
    this._properties = null;
    this._parentCell = null;
}

_SIGIComponentClass.inherits(SIGI.Type);

_SIGIComponentClass.prototype.get_id = function() {
    return this._id;
}

_SIGIComponentClass.prototype.set_id = function(id) {
    this._id = id;
}

_SIGIComponentClass.prototype.get_properties = function() {
    return this._properties;
}

_SIGIComponentClass.prototype.set_properties = function(properties) {
    this._properties = properties;
}

_SIGIComponentClass.prototype.get_events = function() {
    return this._events;
}


_SIGIComponentClass.prototype.get_parentCell = function() {
    return this._parentCell;
}

_SIGIComponentClass.prototype.set_parentCell = function(parentCell) {
    this._parentCell = parentCell;
}

_SIGIComponentClass.prototype.create = function(type, properties, events, references, element, componentId) {

    //check for null element to skip out - needed for ListView paging
    if (element == null) {
        return;
    }

    var newComp = new type;
    // todo: call component constructor

    // todo: if SIGI.UI.Control
    newComp.set_element(element);

    if (componentId == null) {
        newComp.set_id(element.id);
    }
    else {
        newComp.set_id(componentId);
    }

    if (properties) {
        newComp.set_properties(properties);
    }

    //TODO: move to Component Class contructor once base initialize is working
    newComp._events = new SIGI.EventHandlerList();
    this._eventsArray = Array();

    newComp.initialize();

    // register component with SIGI.Application
    SIGI.Application.addComponent(newComp);

    return newComp;
}

_SIGIComponentClass.prototype.context = function(method) {
    var self = this;
    return function() { return method.apply(self, arguments) };
};

SIGI.Component = new _SIGIComponentClass();
//$SIGIcreate = SIGI.Component.create;
var $SIGIcreate = function() { return SIGI.Component.create.apply(SIGI.Component, arguments); }


