angular.module("Starkey")
    // ProgressionTabs controller AND custom directive
    .directive('progressionTabs', function(){
        return {
            restrict: 'EA',
            controller: function($scope, $http){
                var JsonPath = '/Sites/Starkey2015/Views/Tools/HearingAidApps/translatedVerbiage/' + StarkeyHearingTestGlobal.language + '/ProgressionTabs.json';
                $http.get(JsonPath).then(successCallback, errorCallback);
                function successCallback(response) {
                    //success code
                    $scope.ProgressionTabsData = response;
                    tabNames = StarkeyAppConfig.locationPaths;

                    tabNamesDisplay = [];
                    // iterate over array as defined in config file
                    for(var i=0; i < tabNames.length ; i++) {

                        // Check if mobileFeatures is true
                        if(StarkeyHearingTestGlobal.mobileFeatures){
                            // Check if this array exists
                            if( $scope.ProgressionTabsData.data.ProgressionTabsMobile[tabNames[i]]) {
                                // build a new array with the correct tab names so the html can ng-repeat over them
                                tabNameArrayItem = $scope.ProgressionTabsData.data.ProgressionTabsMobile[tabNames[i]];
                                tabNamesDisplay.push(tabNameArrayItem);
                            }
                        } else {
                            if( $scope.ProgressionTabsData.data.ProgressionTabs[tabNames[i]]) {
                                // build a new array with the correct tab names so the html can ng-repeat over them
                                tabNameArrayItem = $scope.ProgressionTabsData.data.ProgressionTabs[tabNames[i]];
                                tabNamesDisplay.push(tabNameArrayItem);
                            }
                        }
                        // Allow access from the html template
                        $scope.tabNamesDisplay = tabNamesDisplay;
                    }
                }
                function errorCallback(error) {
                    //error code
                }       
            },
            templateUrl: '/Sites/Starkey2015/Views/Tools/HearingAidApps/htmlForModule/progressionTabs.html'
        }
    }
);
angular.module("Starkey").service('dataGetSetService', function(){
    // To use this service, it must be injected into the controller that needs it. 
    // This service allows you to save or get an object at any point in the application between controllers

    var appData;

    return {
        getAppData: getAppData,
        setAppData: setAppData
    };

    // .................

    function getAppData() {
        return appData;
    }

    function setAppData(value) {
        appData = value;
    }
  

});