"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__, {
    AtomicProduct: ()=>AtomicProduct
});
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 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");
const external_atomic_product_tw_css_cjs_namespaceObject = require("./atomic-product.tw.css.cjs");
var external_atomic_product_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(external_atomic_product_tw_css_cjs_namespaceObject);
require("../atomic-product-text/atomic-product-text.cjs");
require("../atomic-product-link/atomic-product-link.cjs");
require("../atomic-product-image/atomic-product-image.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 AtomicProduct 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.product,
            rootElementRef: ()=>this.productRootRef,
            linkContainerRef: ()=>this.linkContainerRef,
            onRenderComplete: (element, output)=>{
                this.itemLayoutController.applyLayoutClassesToElement(element, output);
            }
        });
        this.itemLayoutController = new item_layout_controller_cjs_namespaceObject.ItemLayoutController(this, {
            elementPrefix: 'atomic-product',
            renderingFunction: ()=>this.renderingFunction,
            content: ()=>this.content,
            layoutConfig: ()=>({
                    display: this.display,
                    density: this.density,
                    imageSize: this.imageSize
                }),
            itemClasses: ()=>this.classes
        });
        this.addEventListener('atomic/resolveResult', this.resolveProduct);
        this.addEventListener('atomic/resolveInteractiveResult', this.resolveInteractiveProduct);
        this.addEventListener('atomic/resolveStopPropagation', this.resolveStopPropagation);
        this.addEventListener('atomic/resolveResultDisplayConfig', this.resolveProductDisplayConfig);
        this.addEventListener('click', this.handleClick);
        await this.getUpdateComplete();
        this.classList.add('hydrated');
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('atomic/resolveResult', this.resolveProduct);
        this.removeEventListener('atomic/resolveInteractiveResult', this.resolveInteractiveProduct);
        this.removeEventListener('atomic/resolveStopPropagation', this.resolveStopPropagation);
        this.removeEventListener('atomic/resolveResultDisplayConfig', this.resolveProductDisplayConfig);
        this.removeEventListener('click', this.handleClick);
    }
    getContentHTML() {
        if (!this.content) {
            console.warn('atomic-product: 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.productRootRef = 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(...args){
        super(...args), this.linkContent = new DocumentFragment(), this.display = 'list', this.density = 'normal', this.imageSize = 'icon', this.classes = '', this.resolveProduct = (event)=>{
            event.preventDefault();
            event.stopPropagation();
            event.detail(this.product);
        }, this.resolveInteractiveProduct = (event)=>{
            event.preventDefault();
            event.stopPropagation();
            if (this.interactiveProduct) event.detail(this.interactiveProduct);
        }, this.resolveStopPropagation = (event)=>{
            event.detail(this.stopPropagation);
        }, this.resolveProductDisplayConfig = (event)=>{
            event.preventDefault();
            event.stopPropagation();
            event.detail({
                density: this.density,
                imageSize: this.imageSize
            });
        }, this.handleClick = (event)=>{
            if (this.stopPropagation) event.stopPropagation();
            if ('grid' === this.display) this.clickLinkContainer();
        }, this.clickLinkContainer = ()=>{
            this.shadowRoot?.querySelector('.link-container > atomic-product-link a:not([slot])')?.click();
        };
    }
}
AtomicProduct.styles = external_atomic_product_tw_css_cjs_default();
_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)
], AtomicProduct.prototype, "stopPropagation", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof Product ? Object : Product)
], AtomicProduct.prototype, "product", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: 'interactive-product'
    }),
    _ts_metadata("design:type", "u" < typeof InteractiveProduct ? Object : InteractiveProduct)
], AtomicProduct.prototype, "interactiveProduct", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", Object)
], AtomicProduct.prototype, "store", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof ParentNode ? Object : ParentNode)
], AtomicProduct.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)
], AtomicProduct.prototype, "linkContent", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayLayout ? Object : ItemDisplayLayout)
], AtomicProduct.prototype, "display", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayDensity ? Object : ItemDisplayDensity)
], AtomicProduct.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)
], AtomicProduct.prototype, "imageSize", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String
    })
], AtomicProduct.prototype, "classes", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'loading-flag'
    }),
    _ts_metadata("design:type", String)
], AtomicProduct.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)
], AtomicProduct.prototype, "renderingFunction", void 0);
AtomicProduct = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-product'),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicProduct);
exports.AtomicProduct = __webpack_exports__.AtomicProduct;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicProduct"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
