/*!
 * Built by Revolist OU ❤️
 */
'use strict';

var index = require('./index-Dq8Xzj5l.js');
var dimension_helpers = require('./dimension.helpers-B9HgANnM.js');
var column_service = require('./column.service-BNWNiJW3.js');

/**
 * Renders sorting direction and optional additive sorting rank.
 */
const SortingSign = ({ column }) => {
    var _a;
    const indicatorAttrs = { class: 'sort-indicator' };
    const iconAttrs = { class: (_a = column === null || column === void 0 ? void 0 : column.order) !== null && _a !== void 0 ? _a : 'sort-off' };
    const orderIndexAttrs = { class: 'sort-order-index' };
    return (index.h("span", Object.assign({}, indicatorAttrs), index.h("i", Object.assign({}, iconAttrs)), (column === null || column === void 0 ? void 0 : column.sortIndex) ? (index.h("sup", Object.assign({}, orderIndexAttrs), column.sortIndex)) : null));
};

var __rest = (undefined && undefined.__rest) || function (s, e) {
    var t = {};
    for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
const PADDING_DEPTH = 10;
const RowRenderer = (_a, cells) => {
    var { rowClass, index: index$1, size, start, depth, groupingLevel } = _a, attrs = __rest(_a, ["rowClass", "index", "size", "start", "depth", "groupingLevel"]);
    const props = Object.assign(Object.assign(Object.assign({}, attrs), { [dimension_helpers.DATA_ROW]: index$1 }), (typeof groupingLevel === 'number'
        ? { 'data-level': groupingLevel }
        : {}));
    return (index.h("div", Object.assign({}, props, { class: `rgRow ${rowClass || ''}`, style: {
            height: `${size}px`,
            transform: `translateY(${start}px)`,
            paddingLeft: depth ? `${PADDING_DEPTH * depth}px` : undefined,
        } }), cells));
};

function expandEvent(e, model, virtualIndex) {
    var _a;
    const event = new CustomEvent(column_service.GROUP_EXPAND_EVENT, {
        detail: {
            model,
            virtualIndex,
        },
        cancelable: true,
        bubbles: true,
    });
    (_a = e.target) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
}
const GroupingRowRenderer = (props) => {
    const { model, itemIndex, hasExpand, groupingCustomRenderer } = props;
    const name = model[column_service.PSEUDO_GROUP_ITEM];
    const expanded = model[column_service.GROUP_EXPANDED];
    const depth = parseInt(model[column_service.GROUP_DEPTH], 10) || 0;
    const groupRowAttrs = {
        rowClass: 'groupingRow',
        depth,
        expanded,
    };
    if (groupingCustomRenderer) {
        return (index.h(RowRenderer, Object.assign({}, props, groupRowAttrs), index.h("div", { onClick: e => expandEvent(e, model, itemIndex) }, groupingCustomRenderer(index.h, Object.assign(Object.assign({}, props), { colType: props.providers.colType, name,
            expanded,
            depth })))));
    }
    return (index.h(RowRenderer, Object.assign({}, props, groupRowAttrs), hasExpand && [
        index.h("button", { class: { [column_service.GROUP_EXPAND_BTN]: true }, onClick: e => expandEvent(e, model, itemIndex) }, expandSvgIconVNode(expanded)),
        name,
    ]));
};
const expandSvgIconVNode = (expanded = false) => {
    return (index.h("svg", { "aria-hidden": "true", style: { transform: `rotate(${!expanded ? -90 : 0}deg)` }, focusable: "false", viewBox: "0 0 448 512" }, index.h("path", { fill: "currentColor", d: "M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z" })));
};

function renderCell(v) {
    var _a;
    const els = [];
    // #region Custom cell
    const template = (_a = v.schemaModel.column) === null || _a === void 0 ? void 0 : _a.cellTemplate;
    if (template) {
        els.push(template(index.h, v.schemaModel, v.additionalData));
    }
    // #endregion
    // #region Regular cell
    else {
        if (!v.schemaModel.column) {
            // something is wrong with data
            if (index.Build === null || index.Build === void 0 ? void 0 : index.Build.isDev) {
                console.error('Investigate column problem.', v.schemaModel);
            }
            return '';
        }
        // Row drag
        if (v.schemaModel.column.rowDrag &&
            column_service.isRowDragService(v.schemaModel.column.rowDrag, v.schemaModel)) {
            els.push(index.h("span", { class: dimension_helpers.DRAGGABLE_CLASS, onMouseDown: originalEvent => {
                    var _a;
                    return (_a = v.dragStartCell) === null || _a === void 0 ? void 0 : _a.emit({
                        originalEvent,
                        model: v.schemaModel,
                    });
                } }, index.h("span", { class: dimension_helpers.DRAG_ICON_CLASS })));
        }
        els.push(`${column_service.getCellDataParsed(v.schemaModel.model, v.schemaModel.column)}`);
    }
    return els;
}
const CellRenderer = ({ renderProps, cellProps, }) => {
    const render = renderCell.bind(null, renderProps);
    return (index.h("div", Object.assign({}, cellProps, { redraw: render }), render()));
};

exports.CellRenderer = CellRenderer;
exports.GroupingRowRenderer = GroupingRowRenderer;
exports.PADDING_DEPTH = PADDING_DEPTH;
exports.RowRenderer = RowRenderer;
exports.SortingSign = SortingSign;
exports.expandEvent = expandEvent;
exports.expandSvgIconVNode = expandSvgIconVNode;
