"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    renderTableData: ()=>renderTableData,
    renderTableLayout: ()=>renderTableLayout,
    renderTableRow: ()=>renderTableRow
});
require("../../search/atomic-text/atomic-text.cjs");
const external_lit_namespaceObject = require("lit");
const keyed_js_namespaceObject = require("lit/directives/keyed.js");
const map_js_namespaceObject = require("lit/directives/map.js");
const ref_js_namespaceObject = require("lit/directives/ref.js");
const external_table_element_utils_cjs_namespaceObject = require("../table-element-utils.cjs");
const renderTableLayout = ({ props })=>{
    const { host, listClasses, logger, label } = props;
    const fieldColumns = getFieldTableColumns(props);
    if (!fieldColumns.length) logger.error('atomic-table-element elements missing in the template to display columns.', host);
    return (children)=>(0, external_lit_namespaceObject.html)`<table
      class="list-root ${listClasses}"
      part="result-table"
      aria-label=${label}
    >
      <thead part="result-table-heading">
        <tr part="result-table-heading-row">
          ${(0, map_js_namespaceObject.map)(fieldColumns, (column)=>(0, external_lit_namespaceObject.html)`<th part="result-table-heading-cell">
              <atomic-text
                .value=${column.getAttribute('label')}
              ></atomic-text>
            </th>`)}
        </tr>
      </thead>
      <tbody part="result-table-body">
        ${children}
      </tbody>
    </table>`;
};
const renderTableRow = ({ props })=>{
    const { key, rowIndex, setRef } = props;
    return (children)=>(0, external_lit_namespaceObject.html)`${(0, keyed_js_namespaceObject.keyed)(key, (0, external_lit_namespaceObject.html)`<tr
        .part="result-table-row${rowIndex % 2 === 1 ? ' result-table-row-even' : ' result-table-row-odd'}"
        ${(0, ref_js_namespaceObject.ref)((element)=>setRef(element))}
      >
        ${children}
      </tr>`)}`;
};
const renderTableData = ({ props })=>{
    const { renderItem, firstItem, itemRenderingFunction } = props;
    const fieldColumns = getFieldTableColumns(props);
    let currentItemColumns = fieldColumns;
    if (itemRenderingFunction && firstItem) {
        const contentDiv = document.createElement('div');
        const renderedHTML = itemRenderingFunction(firstItem, document.createElement('div'));
        contentDiv.innerHTML = renderedHTML;
        currentItemColumns = Array.from(contentDiv.querySelectorAll(external_table_element_utils_cjs_namespaceObject.tableElementTagName));
    }
    return (0, external_lit_namespaceObject.html)`${(0, map_js_namespaceObject.map)(currentItemColumns, (column, index)=>{
        const label = fieldColumns[index]?.getAttribute('label') || column.getAttribute('label');
        return (0, external_lit_namespaceObject.html)`${(0, keyed_js_namespaceObject.keyed)(`${label}${props.key}`, (0, external_lit_namespaceObject.html)`<td part="result-table-cell">${renderItem(column)}</td>`)}`;
    })}`;
};
const getFieldTableColumns = (props)=>{
    if (props.itemRenderingFunction) return getFieldTableColumnsFromRenderingFunction(props);
    return getFieldTableColumnsFromHTMLTemplate(props);
};
const getFieldTableColumnsFromRenderingFunction = (props)=>{
    const { firstItem, itemRenderingFunction } = props;
    const contentOfRenderingFunction = document.createElement('div');
    const contentOfRenderingFunctionAsString = itemRenderingFunction(firstItem, document.createElement('div'));
    contentOfRenderingFunction.innerHTML = contentOfRenderingFunctionAsString;
    return Array.from(contentOfRenderingFunction.querySelectorAll(external_table_element_utils_cjs_namespaceObject.tableElementTagName));
};
const getFieldTableColumnsFromHTMLTemplate = (props)=>{
    if (!props.templateContentForFirstItem) return [];
    return Array.from(props.templateContentForFirstItem.querySelectorAll(external_table_element_utils_cjs_namespaceObject.tableElementTagName));
};
exports.renderTableData = __webpack_exports__.renderTableData;
exports.renderTableLayout = __webpack_exports__.renderTableLayout;
exports.renderTableRow = __webpack_exports__.renderTableRow;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "renderTableData",
    "renderTableLayout",
    "renderTableRow"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
