angular.module("app").directive("variablesSettings", function($rootScope, $timeout, UniqueIdGenerator) {
    return {
        restrict: 'E',
        replace: true,
        templateUrl: "../app/directives/variablesSettings/variablesSettings.html",
        scope: {
            config: '=',
            instance: '=',
            showIcon: '@',
            onChange: '&' 
        },
        link: function (scope, element, attrs) {
            
            scope.$on('$destroy', function(){
                UniqueIdGenerator.removeId(scope.menuId);
            })

            if(scope.instance){
                scope.instance.toggleMenu = function(){
                    $('#' + scope.menuId + " > i").dropdown('toggle');
                }
            }

            function isSet(value){
                return value === true || value === "true";
            }

            scope.config.periodParams = valueFilled(scope.config.periodParams) ? isSet(scope.config.periodParams) : true;
            scope.config.shiftParams = valueFilled(scope.config.shiftParams) ? isSet(scope.config.shiftParams) : true;
            scope.config.exitParamsUsed = valueFilled(scope.config.exitParamsUsed) ? isSet(scope.config.exitParamsUsed) : true;
            scope.config.constantsParams = valueFilled(scope.config.constantsParams) ? isSet(scope.config.constantsParams) : true;
            scope.config.otherParams = valueFilled(scope.config.otherParams) ? isSet(scope.config.otherParams) : true;
            scope.config.entryParams = valueFilled(scope.config.entryParams) ? isSet(scope.config.entryParams) : true;
            scope.config.entryLogic = valueFilled(scope.config.entryLogic) ? isSet(scope.config.entryLogic) : true;
            scope.config.exitParamsUnused = valueFilled(scope.config.exitParamsUnused) ? isSet(scope.config.exitParamsUnused) : true;
            scope.config.booleanParams = valueFilled(scope.config.booleanParams) ? isSet(scope.config.booleanParams) : true;
            scope.config.symmetricVariables = valueFilled(scope.config.symmetricVariables) ? isSet(scope.config.symmetricVariables) : true;

            scope.menuId = UniqueIdGenerator.generateId();

        }
    };
});