"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bindTaskManEvents = bindTaskManEvents;
exports.isStartEvent = isStartEvent;
exports.isResolveTaskEvent = isResolveTaskEvent;
exports.getTaskEventsByType = getTaskEventsByType;
exports.createTaskManager = createTaskManager;
var interface_1 = require("../interface");
var interface_2 = require("./interface");
var task_manager_1 = require("./task-manager");
function bindTaskManEvents(taskMan, eventList) {
    var _this = this;
    eventList.forEach(function (event) {
        taskMan.on(event, function (evt) {
            switch (evt.type) {
                case interface_1.LoaderEventName.LOAD:
                case interface_1.LoaderEventName.UNLOAD:
                    _this._status = interface_1.LoaderStatus.WORKING;
                    break;
                case interface_1.LoaderEventName.LOAD_COMPLETE:
                case interface_1.LoaderEventName.UNLOAD_COMPLETE:
                    _this._status = interface_1.LoaderStatus.IDLE;
                    break;
            }
            _this.emit(event, evt);
        });
    });
}
function isStartEvent(event) {
    var bool = false;
    switch (event) {
        case interface_1.LoaderEventName.LOAD:
        case interface_1.LoaderEventName.UNLOAD:
            bool = true;
            break;
    }
    return bool;
}
function isResolveTaskEvent(event) {
    var bool = true;
    switch (event) {
        case interface_1.LoaderEventName.LOAD:
        case interface_1.LoaderEventName.UNLOAD:
            bool = false;
            break;
    }
    return bool;
}
function getTaskEventsByType(type) {
    return type === interface_2.LoaderTaskType.LOAD
        ? [
            interface_1.LoaderEventName.LOAD,
            interface_1.LoaderEventName.LOADED,
            interface_1.LoaderEventName.LOAD_REJECT,
            interface_1.LoaderEventName.LOAD_FAILED,
            interface_1.LoaderEventName.LOAD_COMPLETE,
        ]
        : [
            interface_1.LoaderEventName.UNLOAD,
            interface_1.LoaderEventName.UNLOADED,
            interface_1.LoaderEventName.UNLOAD_REJECT,
            interface_1.LoaderEventName.UNLOAD_FAILED,
            interface_1.LoaderEventName.UNLOAD_COMPLETE,
        ];
}
function createTaskManager(type, options) {
    var taskMan = new task_manager_1.LoaderTaskManager(type, options);
    var events = getTaskEventsByType(type);
    bindTaskManEvents.apply(this, [taskMan, events]);
    return taskMan;
}
//# sourceMappingURL=utils.js.map