/**
 * @author a.demeshko
 * created on 21.01.2016
 */
(function () {
    'use strict';

    angular.module('Monitour.pages.profile')
        .controller('editCtrl', editCtrl);

    /** @ngInject */
    function editCtrl($scope, ProfileService,  $localStorage, fileReader, $filter, $uibModal) {
        ProfileService.GetAll().then(function(response) {
            vm.details = response;
            vm.selectedd = response.image;
            vm.selectedid = response.image;
            console.log(response);

            $localStorage.currentUserCompany = response.owner;


        }, function(error) {
            $scope.status = 'Unable to load customer data: ' + error.message;
        });


        vm.upload = function(size) {
            var modalInstance = $uibModal.open({
                templateUrl: 'app/pages/profile/gallery/upload.html',
                controller: 'UploadController',
                controllerAs: 'vm',
                size: size,
                resolve: {
                    selected: function() {
                        return vm.selected;
                    }
                }
            });
            modalInstance.result.then(function(selected) {
                vm.selected = selected.Url;
                vm.selectedd = selected;
                vm.selectedid = selected.Id;
                console.log(vm.selectedd);
            }, function() {
                $log.info('Modal dismissed at: ' + new Date());
            });
        };

        vm.open = function(size) {
            var modalInstance = $uibModal.open({
                templateUrl: 'app/pages/profile/gallery/gallery.html',
                controller: 'ImageController',
                controllerAs: 'vm',
                size: size,
                resolve: {
                    selected: function() {
                        return vm.selected;
                    }
                }
            });
            modalInstance.result.then(function(selected) {
                vm.selected = selected.Url;
                vm.selectedd = selected;
                vm.selectedid = selected.Id;
                console.log(vm.selectedd);
            }, function() {
                $log.info('Modal dismissed at: ' + new Date());
            });
        };


        var owner = $localStorage.currentUserid;

        $scope.onCategoryChange = function () {
            console.log(vm.itemSelected);


        };
        $scope.picture = $filter('profilePicture')('Nasta');

        $scope.removePicture = function () {
            $scope.picture = $filter('appImage')('theme/no-photo.png');
            $scope.noPicture = true;
        };

        $scope.uploadPicture = function () {
            var fileInput = document.getElementById('uploadFile');
            fileInput.click();

        };

        $scope.socialProfiles = [
            {
                name: 'Facebook',
                href: 'https://www.facebook.com/akveo/',
                icon: 'socicon-facebook'
            },
            {
                name: 'Twitter',
                href: 'https://twitter.com/akveo_inc',
                icon: 'socicon-twitter'
            },
            {
                name: 'Google',
                icon: 'socicon-google'
            },
            {
                name: 'LinkedIn',
                href: 'https://www.linkedin.com/company/akveo',
                icon: 'socicon-linkedin'
            },
            {
                name: 'GitHub',
                href: 'https://github.com/akveo',
                icon: 'socicon-github'
            },
            {
                name: 'StackOverflow',
                icon: 'socicon-stackoverflow'
            },
            {
                name: 'Dribbble',
                icon: 'socicon-dribble'
            },
            {
                name: 'Behance',
                icon: 'socicon-behace'
            }
        ];

        $scope.unconnect = function (item) {
            item.href = undefined;
        };

        $scope.showModal = function (item) {
            $uibModal.open({
                animation: false,
                controller: 'ProfileModalCtrl',
                templateUrl: 'app/pages/profile/profileModal.html'
            }).result.then(function (link) {
                item.href = link;
            });
        };

        $scope.getFile = function () {
            fileReader.readAsDataUrl($scope.file, $scope)
                .then(function (result) {
                    $scope.picture = result;
                });
        };

        $scope.switches = [true, true, false, true, true, false];
    }

})();