;
(function () {
    'use strict';
    const
        apiService = require('app-service'),
        lodash = require('lodash'),
        EventEmitter = require('myevents');
    angular
        .module('app.widgets')
        .directive('fileItemList', header);
    header.$inject = ['$timeout', '$rootScope', 'fileTool', '$mdDialog'];

    function header($timeout, $rootScope, fileTool, $mdDialog) {
        var directive = {
            link: link,
            templateUrl: './app/widgets/fileitem/table.list.html',
            restrict: 'EA',
            replace: true,
            scope: {
                files: '=',
                itemClick: '=',
                sortClick: '='
            }
        };

        return directive;
        function link(scope, element, attrs) {
            let vm = scope;
            vm.desc = 0;
            vm.curSort = '';//desc
            vm.shareCtr = false;

            vm.fileClick = function (item, event) {
                if (!item.isdir) return;
                vm.itemClick(item);
            };
            scope.$watch('files', function () {
                 vm.curSort = '';
                 vm.desc = 0;
                $('.chk-all').hasClass('active') ? $('.chk-all').click() : $('.tr-file').removeClass('active');
            });
            scope.sort = (sortName) => {
                if (!scope.sortClick)
                    return false;
                
                if (vm.curSort !== sortName) {
                    vm.desc = 1;
                }
                scope.sortClick(sortName, vm.desc);
                vm.curSort = sortName;
                vm.desc = vm.desc == 1 ? 0 : 1;
            }

        }
    }


})();
