var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.simpleCommandEditor = exports.simpleCommandHandle = void 0;
function simpleCommandHandle(actionAPI, command, properties, status) {
    var connectionID = properties.connectionID != undefined ? properties.connectionID : 'none';
    if (connectionID != 'none') {
        var connection = actionAPI.getConnection('viscaOverIpCamera', connectionID);
        if (connection.instance != undefined) {
            var camera = connection.instance.camera;
            status('Sending command', 'info');
            command.on('ack', function () {
                // status('Command acknowledged', 'info');
            });
            command.on('complete', function () {
                status('Command complete', 'info');
            });
            command.on('error', function (error) {
                status("Command error: ".concat(error.message), 'info');
            });
            camera.sendCommand(command);
        }
    }
    else
        status('No connection specified', 'error');
}
exports.simpleCommandHandle = simpleCommandHandle;
function simpleCommandEditor(editorAPI, properties, additionalFields) {
    if (additionalFields === void 0) { additionalFields = []; }
    var connectionID = properties.connectionID != undefined ? properties.connectionID : 'none';
    var connectionField = {
        id: 'connectionID',
        name: 'Connection',
        type: 'connection',
        connectionType: 'viscaOverIpCamera',
        value: connectionID
    };
    editorAPI.onFieldChanges(function (fields) {
        var fieldObject = editorAPI.tools.objectifyFieldsValues(fields);
        var saveObject = { connectionID: fieldObject.connectionID };
        for (var i = 0; i < additionalFields.length; i++)
            saveObject[additionalFields[i].id] = fieldObject[additionalFields[i].id];
        editorAPI.saveProperties(saveObject);
    });
    editorAPI.setFields(__spreadArray([
        connectionField
    ], additionalFields, true));
}
exports.simpleCommandEditor = simpleCommandEditor;
//# sourceMappingURL=simpleCommandHandler.js.map