"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__, {
    AtomicRecsResult: ()=>AtomicRecsResult
});
const bueno_namespaceObject = require("@coveo/bueno");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const ref_js_namespaceObject = require("lit/directives/ref.js");
const item_list_common_cjs_namespaceObject = require("../../common/item-list/item-list-common.cjs");
const custom_render_controller_cjs_namespaceObject = require("../../common/layout/custom-render-controller.cjs");
const item_layout_controller_cjs_namespaceObject = require("../../common/layout/item-layout-controller.cjs");
const validate_props_controller_cjs_namespaceObject = require("../../common/validate-props-controller/validate-props-controller.cjs");
const boolean_converter_cjs_namespaceObject = require("../../../converters/boolean-converter.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 dom_utils_cjs_namespaceObject = require("../../../utils/dom-utils.cjs");
require("../../search/atomic-result-link/atomic-result-link.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 AtomicRecsResult extends (0, children_update_complete_mixin_cjs_namespaceObject.ChildrenUpdateCompleteMixin)(external_lit_namespaceObject.LitElement) {
    async connectedCallback() {
        super.connectedCallback();
        new custom_render_controller_cjs_namespaceObject.CustomRenderController(this, {
            renderingFunction: ()=>this.renderingFunction,
            itemData: ()=>this.result,
            rootElementRef: ()=>this.resultRootRef,
            linkContainerRef: ()=>this.linkContainerRef,
            onRenderComplete: (element, output)=>{
                this.itemLayoutController.applyLayoutClassesToElement(element, output);
            }
        });
        this.itemLayoutController = new item_layout_controller_cjs_namespaceObject.ItemLayoutController(this, {
            elementPrefix: 'atomic-recs-result',
            renderingFunction: ()=>this.renderingFunction,
            content: ()=>this.content,
            layoutConfig: ()=>({
                    display: this.display,
                    density: this.density,
                    imageSize: this.imageSize
                }),
            itemClasses: ()=>this.classes
        });
        this.addEventListener('atomic/resolveResult', this.resolveResult);
        this.addEventListener('atomic/resolveInteractiveResult', this.resolveInteractiveResult);
        this.addEventListener('atomic/resolveStopPropagation', this.resolveStopPropagation);
        this.addEventListener('atomic/resolveResultDisplayConfig', this.resolveResultDisplayConfig);
        this.addEventListener('click', this.handleClick);
        await this.getUpdateComplete();
        this.classList.add('hydrated');
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('atomic/resolveResult', this.resolveResult);
        this.removeEventListener('atomic/resolveInteractiveResult', this.resolveInteractiveResult);
        this.removeEventListener('atomic/resolveStopPropagation', this.resolveStopPropagation);
        this.removeEventListener('atomic/resolveResultDisplayConfig', this.resolveResultDisplayConfig);
        this.removeEventListener('click', this.handleClick);
    }
    getContentHTML() {
        if (!this.content) {
            console.warn('atomic-recs-result: content property is undefined. Cannot get content HTML.', this);
            return '';
        }
        return (0, dom_utils_cjs_namespaceObject.parentNodeToString)(this.content);
    }
    getLinkHTML() {
        return (0, dom_utils_cjs_namespaceObject.parentNodeToString)(this.linkContent ?? new HTMLElement());
    }
    render() {
        if (void 0 !== this.renderingFunction) return (0, external_lit_namespaceObject.html)`
        <div class=${item_list_common_cjs_namespaceObject.resultComponentClass}>
          <div
            class="result-root"
            ${(0, ref_js_namespaceObject.ref)((el)=>{
            this.resultRootRef = el;
        })}
          ></div>
          <div
            class="link-container"
            ${(0, ref_js_namespaceObject.ref)((el)=>{
            this.linkContainerRef = el;
        })}
          ></div>
        </div>
      `;
        if (!this.itemLayoutController.getLayout()) return (0, external_lit_namespaceObject.html)`<div class=${item_list_common_cjs_namespaceObject.resultComponentClass}></div>`;
        return (0, external_lit_namespaceObject.html)`
      <div class=${item_list_common_cjs_namespaceObject.resultComponentClass}>
        <div
          class="result-root ${this.itemLayoutController.getCombinedClasses().join(' ')}"
          .innerHTML=${this.getContentHTML()}
        ></div>
        <div class="link-container" .innerHTML=${this.getLinkHTML()}></div>
      </div>
    `;
    }
    firstUpdated(_changedProperties) {
        if (this.loadingFlag && this.store) this.store.unsetLoadingFlag(this.loadingFlag);
    }
    constructor(){
        super(), this.linkContent = new DocumentFragment(), this.display = 'list', this.density = 'normal', this.imageSize = 'icon', this.classes = '', this.resolveResult = (event)=>{
            event.preventDefault();
            event.stopPropagation();
            event.detail(this.result);
        }, this.resolveInteractiveResult = (event)=>{
            event.preventDefault();
            event.stopPropagation();
            if (this.interactiveResult) event.detail(this.interactiveResult);
        }, this.resolveStopPropagation = (event)=>{
            event.detail(this.stopPropagation);
        }, this.resolveResultDisplayConfig = (event)=>{
            event.preventDefault();
            event.stopPropagation();
            event.detail({
                density: this.density,
                imageSize: this.imageSize
            });
        }, this.clickLinkContainer = ()=>{
            this.shadowRoot?.querySelector('.link-container > atomic-result-link a:not([slot])')?.click();
        }, this.handleClick = (event)=>{
            if (this.stopPropagation) event.stopPropagation();
            this.clickLinkContainer();
        };
        new validate_props_controller_cjs_namespaceObject.ValidatePropsController(this, ()=>({
                display: this.display,
                density: this.density,
                imageSize: this.imageSize
            }), new bueno_namespaceObject.Schema({
            display: new bueno_namespaceObject.StringValue({
                constrainTo: [
                    'grid',
                    'list',
                    'table'
                ]
            }),
            density: new bueno_namespaceObject.StringValue({
                constrainTo: [
                    'normal',
                    'comfortable',
                    'compact'
                ]
            }),
            imageSize: new bueno_namespaceObject.StringValue({
                constrainTo: [
                    'small',
                    'large',
                    'icon',
                    'none'
                ]
            })
        }));
    }
}
AtomicRecsResult.styles = (0, external_lit_namespaceObject.css)`
    @import '../../common/template-system/legacy-template-system.css';

    :host {
      @apply atomic-template-system;
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicRecsResult.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: 'stop-propagation',
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        reflect: true
    }),
    _ts_metadata("design:type", Boolean)
], AtomicRecsResult.prototype, "stopPropagation", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof RecsResult ? Object : RecsResult)
], AtomicRecsResult.prototype, "result", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: 'interactive-result'
    }),
    _ts_metadata("design:type", "u" < typeof RecsInteractiveResult ? Object : RecsInteractiveResult)
], AtomicRecsResult.prototype, "interactiveResult", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof RecsStore ? Object : RecsStore)
], AtomicRecsResult.prototype, "store", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof ParentNode ? Object : ParentNode)
], AtomicRecsResult.prototype, "content", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: 'link-content'
    }),
    _ts_metadata("design:type", "u" < typeof ParentNode ? Object : ParentNode)
], AtomicRecsResult.prototype, "linkContent", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayLayout ? Object : ItemDisplayLayout)
], AtomicRecsResult.prototype, "display", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayDensity ? Object : ItemDisplayDensity)
], AtomicRecsResult.prototype, "density", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String,
        attribute: 'image-size'
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayImageSize ? Object : ItemDisplayImageSize)
], AtomicRecsResult.prototype, "imageSize", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    })
], AtomicRecsResult.prototype, "classes", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'loading-flag'
    }),
    _ts_metadata("design:type", String)
], AtomicRecsResult.prototype, "loadingFlag", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: 'rendering-function'
    }),
    _ts_metadata("design:type", "u" < typeof ItemRenderingFunction ? Object : ItemRenderingFunction)
], AtomicRecsResult.prototype, "renderingFunction", void 0);
AtomicRecsResult = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-recs-result'),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicRecsResult);
exports.AtomicRecsResult = __webpack_exports__.AtomicRecsResult;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicRecsResult"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
