import { ViscaCommand } from 'visca-over-ip';
import { ActionAPI, ActionAPI_StatusTypes } from '../../../ActionAPI';
import { simpleCommandEditor, simpleCommandHandle } from '../simpleCommandHandler';

module.exports = (actionAPI: ActionAPI) => {
	actionAPI.handle((properties, status: (text: string, type: ActionAPI_StatusTypes) => void) => {
		var connection = actionAPI.getConnection('viscaOverIpCamera', properties.connectionID);
		if (connection) {
			if (connection.instance != undefined) {
				var speed =
					connection.instance.internal != undefined && connection.instance.internal.pantiltSpeed != undefined
						? connection.instance.internal.pantiltSpeed
						: 10;

				var command = ViscaCommand.cameraPanTilt(-1 * speed, 0);
				simpleCommandHandle(actionAPI, command, properties, status);
			}
		}
	});

	actionAPI.onOpenEditor(simpleCommandEditor);
};
