'use strict';

const index = require('./index-75aef097.js');
const constants = require('./constants-1fb674a5.js');
const helpers = require('./helpers-bb6622f5.js');
const helpers$1 = require('./helpers-08ee1e78.js');
const config = require('./config-3bb95f39.js');

// stencil
const BUTTON_ACTION_SELECTOR = "button-action-custom-selector";
const COLUMNS_IDS = {
    action: "action",
    description: "description",
    lastSynchronized: "lastSynchronized",
    localState: "localState",
    modifiedOn: "modifiedOn",
    module: "module",
    name: "name",
    status: "status",
    type: "type"
};
const renderStateCellContent = (action, componentLocale) => {
    let icon;
    let caption;
    let iconColor;
    if (action === "deleted") {
        icon = constants.ICONS.substract;
        caption = componentLocale.states.deleted;
        iconColor = "--color-icon-error-default";
    }
    else if (action === "inserted") {
        icon = constants.ICONS.add;
        caption = componentLocale.states.inserted;
        iconColor = "--color-icon-success-default";
    }
    else if (action === "modified") {
        icon = constants.ICONS.edit;
        caption = componentLocale.states.modified;
        iconColor = "--color-icon-warning-default";
    }
    else if (action === "conflicted") {
        icon = constants.ICONS.warning;
        caption = componentLocale.states.conflicted;
        iconColor = "--color-icon-warning-default";
    }
    else if (!action) {
        // proably is "ignored"
        return null;
    }
    return (index.h("span", { class: "custom-icon-text-wrapper" },
        index.h("ch-image", { type: "mask", class: "icon-s", src: icon, style: { backgroundColor: `var(${iconColor})` } }),
        `${caption}`));
};
const renderObjectStatus = (objectId, objectsStatusMap, updatePillAsButton, commitSingleObject, componentLocale) => {
    const status = objectsStatusMap.get(objectId);
    const caption = status === "pending" && updatePillAsButton
        ? componentLocale.status.commit
        : componentLocale.status[status];
    if (status === "committing") {
        return index.h("span", { class: "spinner-caption" }, caption);
    }
    const classes = `pill pill--${status}`;
    if (updatePillAsButton && status === "pending") {
        return (index.h("button", { class: {
                "button-secondary": true,
                "button-icon-and-text": true,
                "pill": true,
                "pill--update": true,
                [BUTTON_ACTION_SELECTOR]: true
            }, onClick: commitSingleObject(objectId) }, caption));
    }
    else {
        return index.h("span", { class: classes }, caption);
    }
};
const renderTabularGridRows = (type, pendingObjectsAfterFilter, ignoredObjectsAfterFilter, alreadyUpdatedObjectsIdsSet, markedObjectsSet, objectsMessagesDataMap, updatePillAsButton, commitSingleObject, objectsStatusMap, searchValue, componentLocale) => {
    let objects;
    if (type === "pending") {
        objects = pendingObjectsAfterFilter;
    }
    else if (type === "ignored") {
        objects = ignoredObjectsAfterFilter;
    }
    searchValue = searchValue.toLowerCase();
    const filteredRows = objects.map(object => {
        const alreadyUpdated = alreadyUpdatedObjectsIdsSet.has(object.id);
        const hideCheckbox = alreadyUpdated || type === "ignored";
        const marked = markedObjectsSet.has(object.id);
        const messages = objectsMessagesDataMap.get(object.id);
        return (index.h("ch-tabular-grid-row", { class: "tabular-grid-row", key: object.id, rowid: object.id, ref: (el) => marked && (el === null || el === void 0 ? void 0 : el.setAttribute("marked", "true")) },
            index.h("ch-tabular-grid-cell", { "cell-type": "rich", "row-selector": "true", class: {
                    "tabular-grid-cell": true,
                    "no-checkbox-custom-selector": hideCheckbox
                }, size: "max-content" },
                index.h("div", null, helpers$1.hiChar(object.name, searchValue))),
            index.h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, constants.renderObjectTypeWithIcon(object.type)),
            index.h("ch-tabular-grid-cell", { class: {
                    "tabular-grid-cell": true,
                    [constants.CSS_SELECTORS.GRID_CELL_DESCRIPTION]: true
                } },
                index.h("div", null, helpers$1.hiChar(object.description, searchValue))),
            index.h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, helpers.formatDate(object.modifiedOn)),
            index.h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, object.module),
            index.h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, renderStateCellContent(object.state, componentLocale)),
            index.h("ch-tabular-grid-cell", { class: "tabular-grid-cell" }, helpers.formatDate(object.lastSynchronized)),
            index.h("ch-tabular-grid-cell", { class: "tabular-grid-cell tabular-grid-cell--for-pill" }, renderObjectStatus(object.id, objectsStatusMap, updatePillAsButton, commitSingleObject, componentLocale)),
            (messages === null || messages === void 0 ? void 0 : messages.length) && (index.h("ch-tabular-grid-rowset", { class: "tabular-grid-rowset" },
                index.h("ch-tabular-grid-rowset-empty", { class: {
                        "tabular-grid-rowset-empty": true
                    } },
                    index.h("ul", { class: "messages-list" }, messages.map(message => {
                        let MESSAGE_ICON;
                        if (message.type === "error") {
                            MESSAGE_ICON = constants.ICONS.error;
                        }
                        else if (message.type === "warning") {
                            MESSAGE_ICON = constants.ICONS.warning;
                        }
                        else if (message.type === "success") {
                            MESSAGE_ICON = constants.ICONS.success;
                        }
                        else {
                            // info
                            MESSAGE_ICON = constants.ICONS.info;
                        }
                        return (index.h("li", { class: "message-description" },
                            index.h("ch-image", { class: "icon-s message-icon", src: MESSAGE_ICON }),
                            message.text));
                    })))))));
    });
    return filteredRows;
};
const renderTabularGridColumns = (ignoredGridColumns, gridIsEmpty = false, sortTabularGridColumnCallback, columnSelectorClickedCallback, componentLocale, showRichRowSelector) => {
    const colSize = gridIsEmpty
        ? config.config.tabularGrid.colSize.auto
        : config.config.tabularGrid.colSize.maxContent;
    return (index.h("ch-tabular-grid-columnset", { class: "tabular-grid-column-set" },
        !ignoredGridColumns.includes("name") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.name, columnName: componentLocale.objects.name, columnType: "rich", richRowSelector: showRichRowSelector, richRowSelectorMode: "mark", settingable: false, sortable: true, onColumnSortChanged: sortTabularGridColumnCallback, onColumnSelectorClicked: columnSelectorClickedCallback, size: colSize })),
        !ignoredGridColumns.includes("type") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.type, columnName: componentLocale.objects.type, settingable: false, sortable: true, onColumnSortChanged: sortTabularGridColumnCallback, size: colSize })),
        !ignoredGridColumns.includes("description") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.description, columnName: componentLocale.objects.description, settingable: false, sortable: true, onColumnSortChanged: sortTabularGridColumnCallback, size: config.config.tabularGrid.colSize.description })),
        !ignoredGridColumns.includes("modifiedOn") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.modifiedOn, columnName: componentLocale.objects.modifiedOn, sortable: true, onColumnSortChanged: sortTabularGridColumnCallback, settingable: false, size: colSize })),
        !ignoredGridColumns.includes("module") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.module, columnName: componentLocale.objects.module, sortable: true, onColumnSortChanged: sortTabularGridColumnCallback, settingable: false, size: colSize })),
        !ignoredGridColumns.includes("localState") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.localState, columnName: componentLocale.objects.localState, sortable: false, settingable: false, size: colSize })),
        !ignoredGridColumns.includes("lastSynchronized") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.lastSynchronized, columnName: componentLocale.objects.lastSynchronized, settingable: false, sortable: true, onColumnSortChanged: sortTabularGridColumnCallback, size: colSize })),
        !ignoredGridColumns.includes("action") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.action, columnName: componentLocale.objects.action, sortable: false, settingable: false, size: colSize })),
        !ignoredGridColumns.includes("status") && (index.h("ch-tabular-grid-column", { class: "tabular-grid-column", columnId: COLUMNS_IDS.status, columnName: componentLocale.objects.status, sortable: false, settingable: false, size: gridIsEmpty ? "auto" : "100px" }))));
};

exports.COLUMNS_IDS = COLUMNS_IDS;
exports.renderTabularGridColumns = renderTabularGridColumns;
exports.renderTabularGridRows = renderTabularGridRows;

//# sourceMappingURL=tabular-grid-render-96542933.js.map