(function () {
    'use strict';

    angular
    .module('controleApp')
    .directive('iconSelect', iconSelect);

    function iconSelect() {
        var directive = {
            restrict: 'A',
            replace: true,
            link: link,
        };

        return directive;

        function link(scope, element, attr, ctrl) {
            element.on('click', function () {
                var iconClass = $(this).children().first().attr('class');
                var icone = $(this).children().first().attr('icone');

                $(this).addClass('selected');
                $(this).siblings().removeClass('selected');
                $('#icon-selected').removeClass();
                $('#icon-selected').addClass(iconClass);
                $('#nome-icone').val(iconClass).keyup().blur();

                scope.iconClass = iconClass;
                scope.Icone = icone;
            })

        }
    }
})();
