/**
 * @ngdoc directive
 * @name uiGridStActions
 * @restrict A
 * @element ANY
 * @scope
 * @priority 1000
 * @description
 * Used to disable the button while the grid is doing actions, like saving, querying, deleting, etc 
 * @example
 * <span ui-grid-actions ng-click="saveGridData()">Save</span>
 * 
 * saveGridData(){
 *    return myGrid.setDataBackApi(myApi, myOptions);
 * }
**/
/* @ngInject */
export function uiGridStActionsDirective($compile){
    return {
        priority: 1000,
        terminal: true,
        restrict: 'A',
        compile: () => {
            return {
                pre: function(scope, el, attrs){
                    el.removeAttr('ui-grid-st-actions');
                    el.attr('uib-tooltip', `{{'${attrs.uiGridStActions}Pop' | translate}}`);
                    el.attr('tooltip-popup-delay', '400');
                    if (attrs.ngClick){
                        let ngClick = attrs.ngClick;
                        attrs.$set('ngClick', '');
                        el.on('click', function(){
                            let func = scope.$eval(ngClick);
                            if (func && angular.isFunction(func.then)){
                                el.addClass('no-click');
                                func.finally(() => el.removeClass('no-click'));
                            }
                        });
                    }
                    $compile(el)(scope);
                }
            }
        }
    };
}