"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__, {
    ItemListCommon: ()=>ItemListCommon,
    resultComponentClass: ()=>resultComponentClass
});
const accessibility_utils_cjs_namespaceObject = require("../../../utils/accessibility-utils.cjs");
const utils_cjs_namespaceObject = require("../../../utils/utils.cjs");
const replace_breakpoint_utils_cjs_namespaceObject = require("../../../utils/replace-breakpoint-utils.cjs");
const resultComponentClass = 'result-component';
class ItemListCommon {
    updateBreakpoints() {
        this.updateBreakpointsOnce();
    }
    getResultId(uniqueIdOnResult, searchResponseId, density, imageSize) {
        return `${uniqueIdOnResult}${searchResponseId}${density}${imageSize}`;
    }
    setNewResultRef(element, resultIndex) {
        if (0 === resultIndex) this.firstResultEl = element;
        if (resultIndex !== this.indexOfResultToFocus) return;
        if (!element.children.length && !element.shadowRoot?.children.length) return;
        this.indexOfResultToFocus = void 0;
        const elementToFocus = (0, accessibility_utils_cjs_namespaceObject.getFirstFocusableDescendant)(element) ?? element;
        this.props.nextNewItemTarget.setTarget(elementToFocus);
    }
    focusOnNextNewResult() {
        this.indexOfResultToFocus = this.props.getCurrentNumberOfItems();
        this.props.nextNewItemTarget.focusOnNextTarget();
    }
    async focusOnFirstResultAfterNextSearch() {
        await (0, utils_cjs_namespaceObject.defer)();
        return new Promise((resolve)=>{
            if (this.props.getIsLoading()) this.firstResultEl = void 0;
            const unsub = this.props.engineSubscribe(async ()=>{
                await (0, utils_cjs_namespaceObject.defer)();
                if (!this.props.getIsLoading() && this.firstResultEl) {
                    const elementToFocus = (0, accessibility_utils_cjs_namespaceObject.getFirstFocusableDescendant)(this.firstResultEl) ?? this.firstResultEl;
                    this.props.nextNewItemTarget.setTarget(elementToFocus);
                    this.props.nextNewItemTarget.focus();
                    this.firstResultEl = void 0;
                    unsub();
                    resolve();
                }
            });
        });
    }
    constructor(props){
        this.props = props;
        this.props.store.setLoadingFlag(this.props.loadingFlag);
        this.props.store.state.resultList = this;
        this.updateBreakpointsOnce = (0, utils_cjs_namespaceObject.once)(()=>(0, replace_breakpoint_utils_cjs_namespaceObject.updateBreakpoints)(this.props.host));
        this.props.nextNewItemTarget.registerFocusCallback(()=>{
            this.indexOfResultToFocus = void 0;
        });
    }
}
exports.ItemListCommon = __webpack_exports__.ItemListCommon;
exports.resultComponentClass = __webpack_exports__.resultComponentClass;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ItemListCommon",
    "resultComponentClass"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
