Object.defineProperty(exports, "__esModule", { value: true });
module.exports = function (ActionAPI) {
    ActionAPI.handle(function (properties, status, deck) {
        var connectionID = properties.connectionID != undefined && properties.connectionID.length > 0
            ? properties.connectionID
            : 'none';
        var state = properties.state != undefined && properties.state.length > 0 ? properties.state : 'off';
        if (connectionID != 'none') {
            var connection = ActionAPI.getConnection('wirecast-bridge', connectionID);
            if (connection && connection.instance) {
                connection.instance
                    .setAutoLive(state == 'on')
                    .then(function () { return status("Autolive state has been set to ".concat(state)); })
                    .catch(function (error) { return status(error, 'error'); });
            }
        }
        else
            status('No connection specfied', 'error');
    });
    ActionAPI.onOpenEditor(function (EditorAPI, properties) {
        var connectionID = properties.connectionID != undefined && properties.connectionID.length > 0
            ? properties.connectionID
            : 'none';
        var state = properties.state != undefined && properties.state.length > 0 ? properties.state : 'off';
        var connectionField = {
            id: 'connectionID',
            name: 'Connection',
            value: connectionID,
            type: 'connection',
            connectionType: 'wirecast-bridge'
        };
        var stateField = {
            id: 'state',
            name: 'State',
            type: 'select',
            value: state,
            values: []
        };
        if (connectionID != 'none')
            stateField.values = [
                { id: 'on', text: 'AutoLive On' },
                { id: 'off', text: 'AutoLive Off' }
            ];
        EditorAPI.setFields([
            connectionField,
            stateField
        ]);
        EditorAPI.onFieldChanges(function (fields) {
            var fieldObject = EditorAPI.tools.objectifyFieldsValues(fields);
            connectionField.value = fieldObject.connectionID;
            stateField.value = fieldObject.state;
            if (connectionID != fieldObject.connectionID) {
                connectionID = fieldObject.connectionID;
                stateField.values =
                    connectionID != 'none'
                        ? [
                            { id: 'on', text: 'On' },
                            { id: 'off', text: 'Off' }
                        ]
                        : [];
                EditorAPI.setFields([
                    connectionField,
                    stateField
                ]);
            }
            EditorAPI.saveProperties({ connectionID: fieldObject.connectionID, state: fieldObject.state });
        });
    });
};
//# sourceMappingURL=setAutoLive.js.map