import { j as hasValue } from './utils-3aef1637.js';
var ALL_ROWS_KEY = 'all-rows';
var EditControl;
(function (EditControl) {
    EditControl["save"] = "save";
    EditControl["cancel"] = "cancel";
})(EditControl || (EditControl = {}));
var EditControls = Object.values(EditControl);
var RowControl;
(function (RowControl) {
    RowControl["update"] = "update";
    RowControl["delete"] = "delete";
})(RowControl || (RowControl = {}));
var RowControls = Object.values(RowControl);
var TableClasses;
(function (TableClasses) {
    TableClasses["body"] = "anj-table-body";
    TableClasses["caption"] = "anj-column-caption";
    TableClasses["detail"] = "anj-row-detail";
    TableClasses["detailCell"] = "anj-row-detail-cell";
    TableClasses["detailRow"] = "anj-detail-row";
    TableClasses["detailWrapper"] = "anj-row-detail-wrapper";
    TableClasses["editCell"] = "anj-form-cell";
    TableClasses["header"] = "anj-table-head";
    TableClasses["row"] = "anj-row";
    TableClasses["rowGroupHeader"] = "anj-row-group-header";
    TableClasses["table"] = "anj-table";
})(TableClasses || (TableClasses = {}));
var calculateOffsets = function (cols) {
    var offsets = {};
    cols.forEach(function (col, index) {
        var offset;
        switch (col.pinned) {
            case 'left':
                offset = columnOffset(cols.slice(0, index));
                break;
            case 'right':
                offset = columnOffset(cols.slice(index + 1, cols.length).reverse());
                break;
            default:
                offset = undefined;
        }
        offsets[index] = !isNaN(offset) ? offset + "px" : '';
    });
    return offsets;
};
var columnOffset = function (cols) {
    if (cols.length === 0) {
        return 0;
    }
    return cols.map(function (col) { return parseInt(col.width, 10); }).reduce(function (total, width) {
        if (total === void 0) { total = 0; }
        return total + width;
    });
};
var calculatePinBoundaries = function (leftCount, rightCount, scrollCount) {
    return {
        lastLeftPinned: leftCount > 0 ? leftCount - 1 : undefined,
        firstRightPinned: rightCount > 0 ? leftCount + scrollCount : undefined
    };
};
var keyFromData = function (key) {
    return typeof key === 'string' && !isNaN(key) ? parseInt(key, 10) : key;
};
var colCellsFromCell = function (el) {
    var colClass = el.classList.value.split(' ').find(function (c) { return c.includes('anj-col-'); });
    return Array.from(el.closest('table').querySelectorAll("." + colClass));
};
var columnFromCell = function (columns, cell) {
    var index = cell.dataset.columnIndex;
    return columns[index];
};
var implicitColumnFactory = function (fields, data) {
    return fields.map(function (field) {
        var firstWithValue = data.find(function (d) { return hasValue(d[field]); });
        return {
            field: field,
            dataType: inferDataType(firstWithValue[field])
        };
    });
};
var inferDataType = function (value) {
    if (typeof value === 'boolean') {
        return 'boolean';
    }
    if (typeof value === 'number') {
        return 'number';
    }
    if (new Date(value).valueOf()) {
        return 'date';
    }
    return 'string';
};
var persistColumn = function (column) {
    var whitelist = ['filter', 'groupIndex', 'groupKeys', 'index', 'name', 'pinned', 'sortIndex', 'sortOrder', 'visible', 'width'];
    var persistent = {};
    whitelist.forEach(function (k) {
        persistent[k] = column[k];
    });
    return persistent;
};
export { ALL_ROWS_KEY as A, EditControl as E, RowControl as R, TableClasses as T, EditControls as a, RowControls as b, columnFromCell as c, calculatePinBoundaries as d, calculateOffsets as e, colCellsFromCell as f, implicitColumnFactory as i, keyFromData as k, persistColumn as p };
