"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __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__, {
    AtomicResultList: ()=>AtomicResultList
});
const bueno_namespaceObject = require("@coveo/bueno");
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
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 when_js_namespaceObject = require("lit/directives/when.js");
const item_placeholders_cjs_namespaceObject = require("../../common/atomic-result-placeholder/item-placeholders.cjs");
const store_cjs_namespaceObject = require("../../common/interface/store.cjs");
const display_wrapper_cjs_namespaceObject = require("../../common/item-list/display-wrapper.cjs");
const grid_layout_cjs_namespaceObject = require("../../common/item-list/grid-layout.cjs");
const item_list_cjs_namespaceObject = require("../../common/item-list/item-list.cjs");
const item_list_common_cjs_namespaceObject = require("../../common/item-list/item-list-common.cjs");
const result_template_provider_cjs_namespaceObject = require("../../common/item-list/result-template-provider.cjs");
const grid_display_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/grid-display.tw.css.cjs");
var grid_display_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(grid_display_tw_css_cjs_namespaceObject);
const list_display_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/list-display.tw.css.cjs");
var list_display_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(list_display_tw_css_cjs_namespaceObject);
const placeholders_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/placeholders.tw.css.cjs");
var placeholders_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(placeholders_tw_css_cjs_namespaceObject);
const table_display_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/table-display.tw.css.cjs");
var table_display_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(table_display_tw_css_cjs_namespaceObject);
const table_layout_cjs_namespaceObject = require("../../common/item-list/table-layout.cjs");
const item_layout_utils_cjs_namespaceObject = require("../../common/layout/item-layout-utils.cjs");
const tab_wrapper_cjs_namespaceObject = require("../../common/tabs/tab-wrapper.cjs");
const validate_props_controller_cjs_namespaceObject = require("../../common/validate-props-controller/validate-props-controller.cjs");
const array_converter_cjs_namespaceObject = require("../../../converters/array-converter.cjs");
const bind_state_cjs_namespaceObject = require("../../../decorators/bind-state.cjs");
const binding_guard_cjs_namespaceObject = require("../../../decorators/binding-guard.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const children_update_complete_mixin_cjs_namespaceObject = require("../../../mixins/children-update-complete-mixin.cjs");
const accessibility_utils_cjs_namespaceObject = require("../../../utils/accessibility-utils.cjs");
const utils_cjs_namespaceObject = require("../../../utils/utils.cjs");
require("../atomic-result-template/atomic-result-template.cjs");
require("../atomic-result/atomic-result.cjs");
function _ts_decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
    else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function _ts_metadata(k, v) {
    if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
}
class AtomicResultList extends (0, children_update_complete_mixin_cjs_namespaceObject.ChildrenUpdateCompleteMixin)(external_lit_namespaceObject.LitElement) {
    async setRenderFunction(resultRenderingFunction) {
        this.itemRenderingFunction = resultRenderingFunction;
    }
    initialize() {
        if (this.innerHTML.includes('<atomic-result-children')) console.warn('Folded results will not render any children for the "atomic-result-list". Please use "atomic-folded-result-list" instead.');
        this.resultList = (0, headless_namespaceObject.buildResultList)(this.bindings.engine);
        this.resultsPerPage = (0, headless_namespaceObject.buildResultsPerPage)(this.bindings.engine);
        this.tabManager = (0, headless_namespaceObject.buildTabManager)(this.bindings.engine);
        this.initResultTemplateProvider();
        this.initResultListCommon();
        (0, store_cjs_namespaceObject.createAppLoadedListener)(this.bindings.store, (isAppLoaded)=>{
            this.isAppLoaded = isAppLoaded;
        });
    }
    async willUpdate(changedProperties) {
        super.willUpdate(changedProperties);
        if (changedProperties.has('tabManagerState')) {
            const oldValue = changedProperties.get('tabManagerState');
            if (this.tabManagerState?.activeTab !== oldValue?.activeTab && void 0 !== oldValue) this.bindings.store.unsetLoadingFlag(this.loadingFlag);
        }
        if (changedProperties.has('resultListState')) {
            const oldState = changedProperties.get('resultListState');
            if (this.resultListState.firstSearchExecuted) this.bindings.store.unsetLoadingFlag(this.loadingFlag);
            if (!oldState?.isLoading && this.resultListState.isLoading) this.isEveryResultReady = false;
        }
        await this.updateResultReadyState();
    }
    async updateResultReadyState() {
        if (this.isAppLoaded && !this.isEveryResultReady && this.resultListState?.firstSearchExecuted && this.resultListState?.results?.length > 0) {
            await this.getUpdateComplete();
            this.isEveryResultReady = true;
        }
    }
    render() {
        return (0, external_lit_namespaceObject.html)`${(0, tab_wrapper_cjs_namespaceObject.renderTabWrapper)({
            props: {
                tabsIncluded: this.tabsIncluded,
                tabsExcluded: this.tabsExcluded,
                activeTab: this.tabManagerState?.activeTab
            }
        })((0, item_list_cjs_namespaceObject.renderItemList)({
            props: {
                hasError: this.resultListState.hasError,
                hasItems: this.resultListState.hasResults,
                hasTemplate: this.resultTemplateRegistered,
                firstRequestExecuted: this.resultListState.firstSearchExecuted,
                templateHasError: this.templateHasError
            }
        })((0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(this.templateHasError, ()=>(0, external_lit_namespaceObject.html)`<slot></slot>`, ()=>{
            const listClasses = this.computeListDisplayClasses();
            const resultClasses = `${listClasses} ${!this.isEveryResultReady && 'hidden'}`;
            return (0, external_lit_namespaceObject.html)`
              ${(0, when_js_namespaceObject.when)(this.isAppLoaded, ()=>(0, display_wrapper_cjs_namespaceObject.renderDisplayWrapper)({
                    props: {
                        listClasses: resultClasses,
                        display: this.display
                    }
                })((0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)('grid' === this.display, ()=>this.renderGrid(), ()=>(0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)('table' === this.display, ()=>this.renderTable(), ()=>this.renderList())}`)}`))}
              ${(0, when_js_namespaceObject.when)(!this.isEveryResultReady, ()=>(0, display_wrapper_cjs_namespaceObject.renderDisplayWrapper)({
                    props: {
                        listClasses,
                        display: this.display
                    }
                })((0, item_placeholders_cjs_namespaceObject.renderItemPlaceholders)({
                    props: {
                        density: this.density,
                        display: this.display,
                        imageSize: this.imageSize,
                        numberOfPlaceholders: this.resultsPerPageState.numberOfResults || 10
                    }
                })))}
            `;
        })}`))}`;
    }
    initResultTemplateProvider() {
        this.resultTemplateProvider = new result_template_provider_cjs_namespaceObject.ResultTemplateProvider({
            includeDefaultTemplate: true,
            templateElements: Array.from(this.querySelectorAll('atomic-result-template')),
            getResultTemplateRegistered: ()=>this.resultTemplateRegistered,
            getTemplateHasError: ()=>this.templateHasError,
            setResultTemplateRegistered: (value)=>{
                this.resultTemplateRegistered = value;
            },
            setTemplateHasError: (value)=>{
                this.templateHasError = value;
            },
            bindings: this.bindings
        });
    }
    initResultListCommon() {
        this.resultListCommon = new item_list_common_cjs_namespaceObject.ItemListCommon({
            engineSubscribe: this.bindings.engine.subscribe,
            getCurrentNumberOfItems: ()=>this.resultListState.results.length,
            getIsLoading: ()=>this.resultListState.isLoading,
            host: this,
            loadingFlag: this.loadingFlag,
            nextNewItemTarget: this.focusTarget,
            store: this.bindings.store
        });
    }
    computeListDisplayClasses() {
        const displayPlaceholders = !(this.isAppLoaded && this.isEveryResultReady);
        return (0, item_layout_utils_cjs_namespaceObject.getItemListDisplayClasses)(this.display, this.density, this.imageSize, this.resultListState?.isLoading, displayPlaceholders);
    }
    renderGrid() {
        return (0, external_lit_namespaceObject.html)`${(0, map_js_namespaceObject.map)(this.resultListState.results, (result, index)=>(0, grid_layout_cjs_namespaceObject.renderGridLayout)({
                props: {
                    item: {
                        ...result,
                        title: result.title ?? ''
                    },
                    selectorForItem: 'atomic-result',
                    setRef: (element)=>{
                        element instanceof HTMLElement && this.resultListCommon.setNewResultRef(element, index);
                    }
                }
            })((0, external_lit_namespaceObject.html)`${(0, keyed_js_namespaceObject.keyed)(this.getResultId(result), (0, external_lit_namespaceObject.html)`<atomic-result
            .content=${this.getContent(result)}
            .density=${this.density}
            .display=${this.display}
            .imageSize=${this.imageSize}
            .interactiveResult=${this.getInteractiveResult(result)}
            .linkContent=${this.getLinkContent(result)}
            .loadingFlag=${this.loadingFlag}
            .result=${result}
            .renderingFunction=${this.itemRenderingFunction}
            .store=${this.bindings.store}
          ></atomic-result>`)}`))}`;
    }
    renderList() {
        return (0, external_lit_namespaceObject.html)`${(0, map_js_namespaceObject.map)(this.resultListState.results, (result, index)=>(0, external_lit_namespaceObject.html)`${(0, keyed_js_namespaceObject.keyed)(this.getResultId(result), (0, external_lit_namespaceObject.html)`<atomic-result
          part="outline"
          ${(0, ref_js_namespaceObject.ref)((element)=>element instanceof HTMLElement && this.resultListCommon.setNewResultRef(element, index))}
          .content=${this.getContent(result)}
          .density=${this.density}
          .display=${this.display}
          .imageSize=${this.imageSize}
          .interactiveResult=${this.getInteractiveResult(result)}
          .linkContent=${this.getLinkContent(result)}
          .loadingFlag=${this.loadingFlag}
          .result=${result}
          .renderingFunction=${this.itemRenderingFunction}
          .store=${this.bindings.store}
        ></atomic-result>`)}`)}`;
    }
    renderTable() {
        return (0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(this.resultListState.hasResults, ()=>{
            const firstItem = this.resultListState.results[0];
            const listClasses = this.computeListDisplayClasses();
            const templateContentForFirstItem = this.resultTemplateProvider.getTemplateContent(firstItem);
            return (0, table_layout_cjs_namespaceObject.renderTableLayout)({
                props: {
                    firstItem,
                    host: this,
                    itemRenderingFunction: this.itemRenderingFunction,
                    label: this.bindings.i18n.t('view-results'),
                    listClasses,
                    logger: this.bindings.engine.logger,
                    templateContentForFirstItem
                }
            })((0, external_lit_namespaceObject.html)`${(0, map_js_namespaceObject.map)(this.resultListState.results, (result, index)=>(0, table_layout_cjs_namespaceObject.renderTableRow)({
                    props: {
                        key: this.getResultId(result),
                        rowIndex: index,
                        setRef: (element)=>{
                            element instanceof HTMLElement && this.resultListCommon.setNewResultRef(element, index);
                        }
                    }
                })((0, table_layout_cjs_namespaceObject.renderTableData)({
                    props: {
                        firstItem,
                        templateContentForFirstItem,
                        itemRenderingFunction: this.itemRenderingFunction,
                        key: this.getResultId(result),
                        renderItem: (content)=>(0, external_lit_namespaceObject.html)`<atomic-result
                      .content=${content}
                      .density=${this.density}
                      .display=${this.display}
                      .imageSize=${this.imageSize}
                      .interactiveResult=${this.getInteractiveResult(result)}
                      .linkContent=${this.getLinkContent(result)}
                      .loadingFlag=${this.loadingFlag}
                      .result=${result}
                      .renderingFunction=${this.itemRenderingFunction}
                      .store=${this.bindings.store}
                    ></atomic-result>`
                    }
                })))}`);
        }, ()=>external_lit_namespaceObject.nothing)}`;
    }
    get focusTarget() {
        if (!this.nextNewResultTarget) this.nextNewResultTarget = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        return this.nextNewResultTarget;
    }
    getLinkContent(result) {
        return 'grid' === this.display ? this.resultTemplateProvider.getLinkTemplateContent(result) : this.resultTemplateProvider.getEmptyLinkTemplateContent();
    }
    getContent(result) {
        return this.resultTemplateProvider.getTemplateContent(result);
    }
    getInteractiveResult(result) {
        return (0, headless_namespaceObject.buildInteractiveResult)(this.bindings.engine, {
            options: {
                result
            }
        });
    }
    getResultId(result) {
        return this.resultListCommon.getResultId(result.uniqueId, this.resultListState.searchResponseId, this.density, this.imageSize);
    }
    constructor(){
        super(), this.loadingFlag = (0, utils_cjs_namespaceObject.randomID)('firstResultLoaded-'), this.isAppLoaded = false, this.isEveryResultReady = false, this.resultTemplateRegistered = false, this.templateHasError = false, this.density = 'normal', this.display = 'list', this.imageSize = 'icon', this.tabsIncluded = [], this.tabsExcluded = [];
        new validate_props_controller_cjs_namespaceObject.ValidatePropsController(this, ()=>({
                density: this.density,
                display: this.display,
                imageSize: this.imageSize,
                tabsIncluded: this.tabsIncluded,
                tabsExcluded: this.tabsExcluded
            }), AtomicResultList.propsSchema, false);
    }
}
AtomicResultList.styles = [
    placeholders_tw_css_cjs_default(),
    table_display_tw_css_cjs_default(),
    list_display_tw_css_cjs_default(),
    grid_display_tw_css_cjs_default()
];
AtomicResultList.propsSchema = new bueno_namespaceObject.Schema({
    density: new bueno_namespaceObject.StringValue({
        constrainTo: [
            'normal',
            'comfortable',
            'compact'
        ]
    }),
    display: new bueno_namespaceObject.StringValue({
        constrainTo: [
            'grid',
            'list',
            'table'
        ]
    }),
    imageSize: new bueno_namespaceObject.StringValue({
        constrainTo: [
            'small',
            'large',
            'icon',
            'none'
        ]
    }),
    tabsIncluded: new bueno_namespaceObject.ArrayValue({
        each: new bueno_namespaceObject.StringValue({}),
        required: false
    }),
    tabsExcluded: new bueno_namespaceObject.ArrayValue({
        each: new bueno_namespaceObject.StringValue({}),
        required: false
    })
});
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicResultList.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicResultList.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicResultList.prototype, "isAppLoaded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicResultList.prototype, "isEveryResultReady", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicResultList.prototype, "resultTemplateRegistered", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicResultList.prototype, "templateHasError", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('resultList'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof ResultListState ? Object : ResultListState)
], AtomicResultList.prototype, "resultListState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('resultsPerPage'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof ResultsPerPageState ? Object : ResultsPerPageState)
], AtomicResultList.prototype, "resultsPerPageState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('tabManager'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof TabManagerState ? Object : TabManagerState)
], AtomicResultList.prototype, "tabManagerState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayDensity ? Object : ItemDisplayDensity)
], AtomicResultList.prototype, "density", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayLayout ? Object : ItemDisplayLayout)
], AtomicResultList.prototype, "display", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'image-size',
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayImageSize ? Object : ItemDisplayImageSize)
], AtomicResultList.prototype, "imageSize", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: 'tabs-included',
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        type: Array
    }),
    _ts_metadata("design:type", Array)
], AtomicResultList.prototype, "tabsIncluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: 'tabs-excluded',
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        type: Array
    }),
    _ts_metadata("design:type", Array)
], AtomicResultList.prototype, "tabsExcluded", void 0);
_ts_decorate([
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicResultList.prototype, "render", null);
AtomicResultList = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-result-list'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicResultList);
exports.AtomicResultList = __webpack_exports__.AtomicResultList;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicResultList"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
