// com.tts.initial.html5.quiz.ddsource.autoform
define( function() {

    "use strict";

    function TargetRegistry( context, metadata ){

        var	variableNamespace = 'com.tts.dragAndDrop',
            stepId = metadata.page.getId(),
            targets = {};

        function register( target ){
            getTargets();
            targets[stepId][target.getId()] = target;
            setTargets();
        }

        function deregister( target ){
            getTargets();
            if( typeof(targets[stepId]) !== "undefined" ) {
                targets[stepId][target.getId()] = null;
                setTargets();
            }
        }

        function getTargets(){
            targets = context.stage.variable.get('DragAndDropTargetRegistry', variableNamespace ) || {};
            if( typeof(targets[stepId]) === "undefined" ) {
                targets[stepId] = {};
            }
            return targets;
        }

        function setTargets(){
            context.stage.variable.set('DragAndDropTargetRegistry', targets, variableNamespace );
        }

        return {
            register : register,
            deregister : deregister
        };
    }
    return TargetRegistry;
});
