(function(){
    'use strict';

    function toolBar() {
        var directive = {
            restrict: 'E',
            replace: true,
            templateUrl: 'angular/Controle/app/scripts/components/tool-bar-index/tool-bar-index.directive.html',
            scope: false,
            link: link
        };

        function link(scope, element, attr, ctrl) {
            scope.toggleTool = function ($event) {
                var trigger = $event.target;
                element.find('.tool.active').removeClass('active');
                $(trigger).parent().addClass('active');

                if($(trigger).hasClass('no-content')){
                    scope.callOtherActionExample();
                }

                if($(trigger).hasClass('set-cursor')){
                    scope.setCursor($(trigger).data('setcursor'))
                }
            };

            scope.closeTool = function ($event) {
                $event.stopPropagation();
                var trigger = $event.target;
                $(trigger).closest('.tool').removeClass('active');
            };

            scope.toggleToolItem = function (trigger) {
                $(trigger).siblings().removeClass('active','open');
                $(trigger).addClass('active','open');
            };

            scope.setCursor = function (cursor) {
                $('.map-canvas').attr('data-cursor', cursor)
            }

            scope.callOtherActionExample = function () {

            };

            $(document).on('click', '.tool-content .default-list li', function () {
                var trigger = $(this);
                scope.toggleToolItem(trigger);
            });
        }

        return directive;

    }

    angular
        .module('controleApp')
        .directive('toolBarIndex', toolBar);
})();
