angular.module('app.layout', ['ui.router', 'ui.bootstrap'])

.config(function ($stateProvider, $urlRouterProvider, $locationProvider, SQEventsProvider) {
    
    SQEventsProvider.add("SKIN_CHANGED", "skin-changed");
    SQEventsProvider.add("SHOW_INSTRUMENT", 'show-instrument');
    SQEventsProvider.add("OPEN_ABOUT_DIALOG", "open-about-dialog");
    
    $stateProvider
        .state('app', {
            abstract: false,
            url: '/',
            views: {
                root: {
                    templateUrl: '../SQMANAGER/layout/views/layout.html',
                    controller: 'LayoutCtrl'
                }
            },
            resolve: {
                tryLoadData: function(SQConstants){
                    if(!mainAppExists()){
                        return SQConstants.loadAll();
                    }
                },
                loadSkins: function(SkinService){
                    return SkinService.loadSkins();
                },
                connectWebSocket: function(SQWebSocketService){
                    return SQWebSocketService.connectWebSocket(location.port);
                }
            }
        });
        
    $urlRouterProvider.otherwise(window.appConfig.defaultURL);

})