;
(function () {
    'use strict';
    const EventEmitter = require('myevents');

    angular
        .module('app.widgets')
        .directive('storageMenu', storageMenu);

    function storageMenu() {
        var directive = {
            controller: link,
            template: `<div class="">
                            <li  ng-repeat="menu in menus"  >
                                <a class="any"  ui-sref="{{menu.url}}" id="{{menu.id}}" 
                                 ng-class="{'current':menu.id==curid,'current1':menu.id==hover_id}" 
                                 ng-click="checked(menu.id,-1)">
                                    <i class="icon {{::menu.icon}}"></i>
                                    <span class="text">{{::menu.text}}<span>
                                </a>
                                <ul style="height:auto;padding-left:15px" class="nav" ng-if="menu.child&&menu.child.length>0">
                                    <li class="sm" 
                                        ng-repeat=" menuChild in menu.child "
                                        id="{{menuChild.id}}"  
                                        ng-click="checked(menuChild.id ,menuChild.ext,menuChild.text)"  
                                        ng-class="{'current':menuChild.id==curid,'current1':menuChild.id==hover_id}"
                                     >
                                        <a  ui-sref="{{menu.url}}"  style="padding-left: 50px;">
                                            <i class="icon {{::menuChild.icon}}" style="top:4px; left:20px; "></i>
                                            <span class="text">{{::menuChild.text}}</span>
                                        </a>
                                    </li>
                                </ul>
                            </li>
                        </div>
                        `,
            restrict: 'EA',
            replace: true,
            scope: {
                'curid': '='
            }

        };
        link.$inject = ['$scope', '$element', '$attrs', '$timeout'];

        return directive;

        function link($scope, $element, $attrs, $timeout) {
            var vm = $scope;
            vm.curid = vm.curid || 'storage';
            vm.hover_id = '';
            vm.menus = [{
                url: 'storage.index',
                icon: 'icon-allFile',
                id: 'storage',
                text: '所有文件',
                child: [{
                    icon: 'icon-document',
                    id: 'video',
                    text: '文档',
                    ext: 1
                }, {
                    icon: 'icon-picture',
                    id: 'file',
                    text: '图片',
                    ext: 0
                }, {
                    icon: 'icon-music',
                    id: 'music',
                    text: '音乐',
                    ext: 2
                }, {
                    icon: 'icon-video',
                    id: 'application',
                    text: '视频',
                    ext: 3
                },{
                    icon: 'icon-others-menu',
                    id: 'others',
                    text: '其他',
                    ext: 4
                }
                ]
            }, {
                url: 'storage.share',
                id: 'storage_share',
                icon: 'icon-myShare',
                text: '我的分享',
                isChild: false
            }];

            vm.checked = (id, ext, text) => {
                vm.curid = id;
                if (ext >= 0) {
                    $timeout(() => {
                        EventEmitter.emit('crumbClk', 0, '', ext, text, id);
                    });

                } else if (ext === -1) {
                    $timeout(() => {
                        EventEmitter.emit('crumbClk', 0);
                    });
                }
                //$state.transitionTo('storage.index',{ext:ext});
            };



        }

    }
})();
