/**
 * @dyna-grid/core - Advanced Data Grid / Data Table supporting Javascript / Web Components
 * @version v1.1.0
 * @link 
 * @license 
 */
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var generic_1 = require("../../utils/generic");
var array_1 = require("../../utils/array");
var context_1 = require("../../context/context");
/**
 * Common logic for RowComp and AutoHeightCalculator
 */
var RowCssClassCalculator = /** @class */ (function () {
    function RowCssClassCalculator() {
    }
    RowCssClassCalculator.prototype.getInitialRowClasses = function (params) {
        var classes = [];
        if (generic_1.exists(params.extraCssClass)) {
            classes.push(params.extraCssClass);
        }
        classes.push('dy-row');
        classes.push(params.rowFocused ? 'dy-row-focus' : 'dy-row-no-focus');
        if (params.fadeRowIn) {
            classes.push('dy-opacity-zero');
        }
        classes.push(params.rowIsEven ? 'dy-row-even' : 'dy-row-odd');
        if (params.rowNode.isRowPinned()) {
            classes.push('dy-row-pinned');
        }
        if (params.rowNode.isSelected()) {
            classes.push('dy-row-selected');
        }
        if (params.rowNode.footer) {
            classes.push('dy-row-footer');
        }
        classes.push('dy-row-level-' + params.rowLevel);
        if (params.rowNode.stub) {
            classes.push('dy-row-loading');
        }
        if (params.fullWidthRow) {
            classes.push('dy-full-width-row');
        }
        if (params.expandable) {
            classes.push('dy-row-group');
            classes.push(params.rowNode.expanded ? 'dy-row-group-expanded' : 'dy-row-group-contracted');
        }
        if (params.rowNode.dragging) {
            classes.push('dy-row-dragging');
        }
        array_1.pushAll(classes, this.processClassesFromGridOptions(params.rowNode, params.scope));
        array_1.pushAll(classes, this.preProcessRowClassRules(params.rowNode, params.scope));
        // we use absolute position unless we are doing print layout
        classes.push(params.printLayout ? 'dy-row-position-relative' : 'dy-row-position-absolute');
        if (params.firstRowOnPage) {
            classes.push('dy-row-first');
        }
        if (params.lastRowOnPage) {
            classes.push('dy-row-last');
        }
        return classes;
    };
    RowCssClassCalculator.prototype.processClassesFromGridOptions = function (rowNode, scope) {
        var res = [];
        var process = function (rowCls) {
            if (typeof rowCls === 'string') {
                res.push(rowCls);
            }
            else if (Array.isArray(rowCls)) {
                rowCls.forEach(function (e) { return res.push(e); });
            }
        };
        // part 1 - rowClass
        var rowClass = this.gridOptionsWrapper.getRowClass();
        if (rowClass) {
            if (typeof rowClass === 'function') {
                console.warn('DYNA Grid: rowClass should not be a function, please use getRowClass instead');
                return [];
            }
            process(rowClass);
        }
        // part 2 - rowClassFunc
        var rowClassFunc = this.gridOptionsWrapper.getRowClassFunc();
        if (rowClassFunc) {
            var params = {
                data: rowNode.data,
                node: rowNode,
                rowIndex: rowNode.rowIndex,
                $scope: scope,
                api: this.gridOptionsWrapper.getApi(),
                columnApi: this.gridOptionsWrapper.getColumnApi(),
                context: this.gridOptionsWrapper.getContext()
            };
            var rowClassFuncResult = rowClassFunc(params);
            process(rowClassFuncResult);
        }
        return res;
    };
    RowCssClassCalculator.prototype.preProcessRowClassRules = function (rowNode, scope) {
        var res = [];
        this.processRowClassRules(rowNode, scope, function (className) {
            res.push(className);
        }, function (className) {
            // not catered for, if creating, no need
            // to remove class as it was never there
        });
        return res;
    };
    RowCssClassCalculator.prototype.processRowClassRules = function (rowNode, scope, onApplicableClass, onNotApplicableClass) {
        var rowClassParams = {
            data: rowNode.data,
            node: rowNode,
            rowIndex: rowNode.rowIndex,
            api: this.gridOptionsWrapper.getApi(),
            columnApi: this.gridOptionsWrapper.getColumnApi(),
            $scope: scope,
            context: this.gridOptionsWrapper.getContext()
        };
        this.stylingService.processClassRules(this.gridOptionsWrapper.rowClassRules(), rowClassParams, onApplicableClass, onNotApplicableClass);
    };
    RowCssClassCalculator.prototype.calculateRowLevel = function (rowNode) {
        if (rowNode.group) {
            return rowNode.level;
        }
        // if a leaf, and a parent exists, put a level of the parent, else put level of 0 for top level item
        return rowNode.parent ? (rowNode.parent.level + 1) : 0;
    };
    __decorate([
        context_1.Autowired('stylingService')
    ], RowCssClassCalculator.prototype, "stylingService", void 0);
    __decorate([
        context_1.Autowired('gridOptionsWrapper')
    ], RowCssClassCalculator.prototype, "gridOptionsWrapper", void 0);
    RowCssClassCalculator = __decorate([
        context_1.Bean('rowCssClassCalculator')
    ], RowCssClassCalculator);
    return RowCssClassCalculator;
}());
exports.RowCssClassCalculator = RowCssClassCalculator;

//# sourceMappingURL=rowCssClassCalculator.js.map
