Object.defineProperty(exports, "__esModule", { value: true });
exports.ZoomOSC_ConnectionOnly = void 0;
var node_osc_1 = require("node-osc");
exports.ZoomOSC_ConnectionOnly = {
    handleAction: function (oscAction) {
        return function (ActionAPI) {
            ActionAPI.onExecute(function (properties, status, deck) {
                return exports.ZoomOSC_ConnectionOnly.onExecute(ActionAPI, oscAction, properties, status, deck);
            });
            ActionAPI.onOpenEditor(exports.ZoomOSC_ConnectionOnly.onOpenEditor);
        };
    },
    onExecute: function (ActionAPI, oscAction, properties, status, deck) {
        if (properties.connectionID != undefined && properties.connectionID.length > 0) {
            var connection = ActionAPI.getConnection('zoomosc', properties.connectionID);
            if (connection) {
                var ip = connection.properties.ip;
                var port = connection.properties.port;
                var header = connection.properties.header;
                var client = new node_osc_1.Client(ip, port);
                client.send("/".concat(header, "/").concat(oscAction), [], function () {
                    status("OSC Action ".concat(oscAction, " has been called"), 'info');
                    client.close();
                });
            }
            else
                status('Connection does not exist', 'error');
        }
        else
            status('No connectionID specified', 'error');
    },
    onOpenEditor: function (EditorAPI, properties) {
        var connectionID = properties.connectionID != undefined ? properties.connectionID : 'none';
        var connectionField = {
            id: 'connectionID',
            name: 'Connection',
            type: 'connection',
            connectionType: 'zoomosc',
            value: connectionID
        };
        EditorAPI.onFieldChanges(function (fields) {
            var fieldObject = EditorAPI.tools.objectifyFieldsValues(fields);
            EditorAPI.saveProperties({
                connectionID: fieldObject.connectionID,
                target: fieldObject.target,
                targetValue: fieldObject.targetValue
            });
        });
        EditorAPI.setFields([
            connectionField
        ]);
    }
};
//# sourceMappingURL=connectionOnly.js.map