var page = "customers.html";
var customerApp = angular.module('customerApp', ['menuController', 'customersService', 'customerController', 'customeraddressesService', //
    'chatApp', 'leadsourcesService', 'customertypesService', 'reviewsService', 'flagsService', 'jobsitesService', 'customereviewsService', //
    'ivh.treeview', 'reviewsService', 'AppointmentsController', 'appointmentsService', 'appointmentstatusesService', 'callaheadsService',
    'flexiblecustomersService', 'listviewusersService', 'opportunitiesService', 'groupsService', 'tasksService', 'ordertypesService', 'ordersService', 'orderstatusesService', //
    'checklistController', 'checklistsService','dynamicNumber', 'servicesService', 'appointmentchecklistsService', 'customerfilesService', 'customerfilesService','LocationServiceModulues','ngTagsInput','chatController'
]).config(['$compileProvider',
    function ($compileProvider) {
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|tel|mailto):/);
    }
]);
customerApp.filter('propsFilter', function () {
    return function (items, props) {
        var out = [];
        if (angular.isArray(items)) {
            var keys = Object.keys(props);
            items.forEach(function (item) {
                var itemMatches = false;
                for (var i = 0; i < keys.length; i++) {
                    var prop = keys[i];
                    var text = props[prop].toLowerCase();
                    if (item[prop] && item[prop].toString().toLowerCase().indexOf(text) !== -1) {
                        itemMatches = true;
                        break;
                    }
                }
                if (itemMatches) {
                    out.push(item);
                }
            });
        } else {
            // Let the output be the input untouched
            out = items;
        }
        return out;
    };
});

customerApp.run(function ($ionicPlatform, $ionicLoading) {
    $ionicLoading.show({ template: templateLoading });
    $ionicPlatform.ready(function () {
        var devicePlatform = "";
        try {
            devicePlatform = device.platform;
        } catch (err) {
            console.log(err)
        }
        if (devicePlatform != "iPhone" && devicePlatform != "iOS") {
            // $scope.deviceLoading = "ios";
            isiOs = false;
        }
        //StatusBar.hide();
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(false);
            cordova.plugins.Keyboard.disableScroll(true);
        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            // StatusBar.styleDefault();
            StatusBar.show();
            StatusBar.backgroundColorByHexString("#327EBB");
            StatusBar.styleLightContent();
            //StatusBar.hide();
            StatusBar.overlaysWebView(false);
        }
    });
});

customerApp.config(function ($stateProvider, $urlRouterProvider) {

    $stateProvider

            /*/////////////////////// USERS ///////////////////////////*/
            .state('dashboard', {
                url: '/board',
                abstract: true,
                templateUrl: 'templates/dashboard/general/menu.html',
                controller: 'menuCtrl'
            })
            .state('dashboard.customers', {
                url: '/customers',
                views: {
                    'menuContent': {
                        templateUrl: 'templates/dashboard/customers/customers/customers.tpl',
                        controller: 'customerCtrl'
                    }
                }
            })
            .state('dashboard.appid', {
                url: '/appid/:param',
                views: {
                    'menuContent': {
                        templateUrl: 'templates/dashboard/customers/customers/customers.tpl',
                        controller: 'customerCtrl'
                    }
                }
            })

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/board/customers');
});
