// (C) 2025-2026 GoodData Corporation
import { objRefToString } from "@gooddata/sdk-model";
import { ASYNC_TABLE_ID_PREFIX, CHECKBOX_COLUMN_WIDTH, MENU_COLUMN_WIDTH, MENU_COLUMN_WIDTH_LARGE, } from "./constants.js";
export const getColumnWidth = (renderMenu, isLarge, widthProp) => {
    return renderMenu ? (isLarge ? MENU_COLUMN_WIDTH_LARGE : MENU_COLUMN_WIDTH) : widthProp;
};
export const getItemKey = (item) => {
    if ("id" in item) {
        return item.id;
    }
    return objRefToString(item.ref);
};
export const getColumnWidths = (columns, hasCheckbox, isLargeRow) => {
    const columnWidths = columns.map((col) => getColumnWidth(!!col.renderMenu, isLargeRow, col.width));
    return hasCheckbox ? [CHECKBOX_COLUMN_WIDTH, ...columnWidths] : columnWidths;
};
export const getFilterOptionsMap = (options) => {
    return new Map(options.map((item) => [item.value, item]));
};
export const getColumnHeaderId = (key) => {
    return `${ASYNC_TABLE_ID_PREFIX}column-header-${key}`;
};
export const getRowLabelId = (key) => {
    return `${ASYNC_TABLE_ID_PREFIX}label-cell-row-${key}`;
};
export const getRowId = (itemId) => {
    return `${ASYNC_TABLE_ID_PREFIX}row-${itemId}`;
};
export const getCellId = (itemId, columnIndex) => {
    return `${ASYNC_TABLE_ID_PREFIX}cell-${itemId}-${columnIndex}`;
};
export const getFilterDropdownId = (label) => {
    return `${ASYNC_TABLE_ID_PREFIX}filter-dropdown-${label}`;
};
export const stopPropagationCallback = (event, callback) => {
    event.stopPropagation();
    callback?.();
};
export const computeProportionalWidth = (originalColumnWidth, availableWidth, columnsWidthSum) => {
    if (columnsWidthSum === 0) {
        return originalColumnWidth;
    }
    const ratio = originalColumnWidth / columnsWidthSum;
    return Math.floor(availableWidth * ratio);
};
