;
(function () {
    'use strict';

    const apiService = require('app-service');

    angular
        .module("app.router")
        .config(['$stateProvider', '$urlRouterProvider', '$compileProvider','$qProvider', config]);

    return;

    function config($stateProvider, $urlRouterProvider, $compileProvider,$qProvider) {
        whitelist($compileProvider);
        bindRouter($stateProvider, $urlRouterProvider);
        $qProvider.errorOnUnhandledRejections(false);
    }

    function whitelist($compileProvider) {
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
        $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|mailto|chrome-extension):/);
    }

    function bindRouter($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('login', {
                url: "/login"
            })
            .state('storage', {
                controller: 'main_Controller',
                url: "/storage/main",
                templateUrl: './app/storage/main.html'
            })
            .state('storage.index', {
                controller: 'index_Controller',
                url: "/storage/index?ext",
                templateUrl: './app/storage/index.html',
                resolve: {
                    files: () => {
                        return apiService.page_list('0').then((d) => { return d.data; });
                    }
                }
            })
            .state('storage.detail', {
                url: "/storage/detail",
                templateUrl: './app/storage/detail.html'
            })
            .state('storage.share', {
                controller: 'myShareListController',
                url: "/storage/share",
                templateUrl: './app/storage/share.html'  ,
                resolve: {
                    files: () => {
                        return  apiService.user_share_files().then((d) => d.data);
                    }
                }
            })
            .state('share', {
                url: "/share/main",
                controller: 'share_main_Controller',
                templateUrl: './app/share/main.html',
                resolve: {
                    files: () => {
                        return apiService.share_to_me('all').then((d) => d.data);
                    }
                }
            })
            .state('share_detail', {
                url: "/share/detail",
                params: {
                    file: null
                },
                controller: 'share_detail_Controller',
                templateUrl: './app/share/detail.html'
            })
            .state('task', {
                url: "/task",
                controller: 'task_index_Controller',
                templateUrl: './app/task/index.html'
            })
            .state('task.uploadList', {
                url: "/task/uploadList",
                controller: 'task_upload_Controller',
                templateUrl: './app/task/uploadList.html'
            })
            .state('task.downList', {
                url: "/task/downList",
                controller: 'task_down_Controller',
                templateUrl: './app/task/downList.html'

            })
            .state('task.complete', {
                url: "/task/complete",
                controller: 'task_complete_Controller',
                templateUrl: './app/task/complete.html'
            })

            .state('recycleBin', {
                url: "/recycle/index",
                controller: 'recycle_main_Controller',
                templateUrl: './app/recycleBin/main.html'
            })
            .state('setting', {
                url: "/setting",
                controller: 'settingCtr',
                templateUrl: './app/setting/index.html'
            })

        $urlRouterProvider.otherwise('storage.index');
    }

})();