
namespace uniflash {

    'use strict';

    angular.module('uniflash', ['ui.router', 'ui.bootstrap', 'ti_common', 'xml', 'ngFileUpload', 'cgBusy', 'angularResizable']);


    // Setting HTML5 Location Mode
    angular.module('uniflash').config(['$locationProvider',
        function ($locationProvider) {
            $locationProvider.hashPrefix('!');
        }
    ]);

    /** Stop angular parsing responses**/
    angular.module('uniflash').config(['$httpProvider',
        function ($httpProvider) {
            $httpProvider.defaults.transformResponse = angular.identity;
        }
    ]);

    angular.module('uniflash').config(['$logProvider',
        function ($logProvider) {
            $logProvider.debugEnabled(true);
        }
    ]);

    angular.module('uniflash').config(['x2jsProvider',
        function (x2jsProvider) {
            x2jsProvider.config = {
                escapeMode: false,
                useDoubleQuotes : true
                 /*
      escapeMode               : true|false - Escaping XML characters. Default is true from v1.1.0+
      attributePrefix          : "<string>" - Prefix for XML attributes in JSon model. Default is "_"
      arrayAccessForm          : "none"|"property" - The array access form (none|property). Use this property if you want X2JS generates an additional property <element>_asArray to access in array form for any XML element. Default is none from v1.1.0+
      emptyNodeForm            : "text"|"object" - Handling empty nodes (text|object) mode. When X2JS found empty node like <test></test> it will be transformed to test : '' for 'text' mode, or to Object for 'object' mode. Default is 'text'
      enableToStringFunc       : true|false - Enable/disable an auxiliary function in generated JSON objects to print text nodes with text/cdata. Default is true
      arrayAccessFormPaths     : [] - Array access paths. Use this option to configure paths to XML elements always in "array form". You can configure beforehand paths to all your array elements based on XSD or your knowledge. Every path could be a simple string (like 'parent.child1.child2'), a regex (like /.*\.child2/), or a custom function. Default is empty
      skipEmptyTextNodesForObj : true|false - Skip empty text tags for nodes with children. Default is true.
      stripWhitespaces         : true|false - Strip whitespaces (trimming text nodes). Default is true.
      datetimeAccessFormPaths  : [] - Datetime access paths. Use this option to configure paths to XML elements for "datetime form". You can configure beforehand paths to all your array elements based on XSD or your knowledge. Every path could be a simple string (like 'parent.child1.child2'), a regex (like /.*\.child2/), or a custom function. Default is empty
      */
            };
        }
    ]);

    //Then define the init function for starting up the application
    angular.element(document).ready(function () {
        //Then init the app
        angular.bootstrap(document, ['uniflash']);
    });


    angular.module('uniflash').config(configFileStorage);

    configFileStorage.$inject = ['ticPlatformConfigProvider'];
    function configFileStorage(ticPlatformConfig: ti_common.IPlatformConfig) {
        if (ticPlatformConfig.setWorkSpaceServer) {
            ticPlatformConfig.setWorkSpaceServer('/workspaceserver/uniflash/default');
        }
    }

    //register views
    export enum RegisteredViews {
        Program,
        UtilitiesAndSettings,
        Memory,
        Downloads
    }

    angular.module('uniflash').config(viewsConfig);
    viewsConfig.$inject = ['ufMainViewProvider'];

    function viewsConfig(ufMainViewProvider: uniflash.views.MainViewProvider) {
        let stateProvider = ufMainViewProvider.mainViewStateProvider;
        stateProvider.addViewState(
            {
                name: 'Program',
                templateUrl: 'programs/programs.html',
                isCoreSensitive: true,
                title: 'Select and Load Images',
                viewType: RegisteredViews.Program
            });

        stateProvider.addViewState(
            {
                name: 'Settings & Utilities',
                templateUrl: 'flash_properties/settings_main.html',
                isCoreSensitive: true,
                title: 'Find and Configure Settings and Utilities',
                viewType: RegisteredViews.UtilitiesAndSettings
            });

        stateProvider.addViewState(
            {
                name: 'Memory',
                templateUrl: 'memory/memory_browser.html',
                isCoreSensitive: true,
                title: 'Memory Browser',
                viewType: RegisteredViews.Memory
            });

        stateProvider.addViewState(
            {
                name: 'Standalone Command Line',
                templateUrl: 'standalone_dl/standalone_dl.html',
                isCoreSensitive: false,
                title: 'Generate Standalone Command Line Package',
                viewType: RegisteredViews.Downloads
            });

    }
}
