"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__, {
    AtomicCommerceRecommendationInterface: ()=>AtomicCommerceRecommendationInterface
});
const commerce_namespaceObject = require("@coveo/headless/commerce");
const context_namespaceObject = require("@lit/context");
const external_i18next_namespaceObject = require("i18next");
var external_i18next_default = /*#__PURE__*/ __webpack_require__.n(external_i18next_namespaceObject);
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const boolean_converter_cjs_namespaceObject = require("../../../converters/boolean-converter.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const watch_cjs_namespaceObject = require("../../../decorators/watch.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 init_queue_cjs_namespaceObject = require("../../../utils/init-queue.cjs");
const initialization_common_utils_cjs_namespaceObject = require("../../../utils/initialization-common-utils.cjs");
const bindings_context_cjs_namespaceObject = require("../../common/context/bindings-context.cjs");
const analytics_config_cjs_namespaceObject = require("../../common/interface/analytics-config.cjs");
const interface_controller_cjs_namespaceObject = require("../../common/interface/interface-controller.cjs");
const external_store_cjs_namespaceObject = require("./store.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 AtomicCommerceRecommendationInterface extends (0, children_update_complete_mixin_cjs_namespaceObject.ChildrenUpdateCompleteMixin)(external_lit_namespaceObject.LitElement) {
    connectedCallback() {
        super.connectedCallback();
        this.addEventListener('atomic/initializeComponent', this.handleInitialization);
        this.addEventListener('atomic/scrollToTop', this.scrollToTop);
    }
    initializeWithEngine(engine) {
        engine.dispatch((0, commerce_namespaceObject.loadConfigurationActions)(engine).updateAnalyticsConfiguration({
            trackingId: engine.configuration.analytics.trackingId,
            ...(0, analytics_config_cjs_namespaceObject.augmentAnalyticsConfigWithAtomicVersion)()
        }));
        return this.internalInitialization(()=>{
            this.engine = engine;
        });
    }
    updateLocale(language, country, currency) {
        if (!this.interfaceController.engineIsCreated(this.engine) || !this.context) return;
        language && this.interfaceController.onLanguageChange(language);
        if (this.isNewLocale(language, country, currency)) {
            const { setContext } = (0, commerce_namespaceObject.loadContextActions)(this.engine);
            this.engine.dispatch(setContext({
                ...this.context.state,
                ...language && {
                    language
                },
                ...country && {
                    country
                },
                ...currency && {
                    currency
                }
            }));
        }
    }
    toggleAnalytics() {
        this.interfaceController.onAnalyticsChange();
    }
    updateIconAssetsPath() {
        this.store.state.iconAssetsPath = this.iconAssetsPath;
    }
    async updateLanguage() {
        if (!this.interfaceController.engineIsCreated(this.engine) || !this.language || !this.context) return;
        this.engine.logger.warn('The `language` property will be removed in the next major version of Atomic (v4). Rather than using this property, set the initial language through the engine configuration when calling `initializeWithEngine`, and update the language as needed using the `updateLocale` method.');
        this.context.setLanguage(this.language);
        return this.interfaceController.onLanguageChange();
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.removeEventListener('atomic/initializeComponent', this.handleInitialization);
        this.removeEventListener('atomic/scrollToTop', this.scrollToTop);
    }
    render() {
        return (0, external_lit_namespaceObject.html)`<slot></slot>`;
    }
    scrollToTop() {
        const scrollContainerElement = document.querySelector(this.scrollContainer);
        if (!scrollContainerElement) return void this.bindings.engine.logger.warn(`Could not find the scroll container with the selector "${this.scrollContainer}". This will prevent UX interactions that require a scroll from working correctly. Please review the CSS selector in the scrollContainer option`);
        scrollContainerElement.scrollIntoView({
            behavior: 'smooth'
        });
    }
    async internalInitialization(initEngine) {
        await Promise.all([
            this.interfaceController.onInitialization(initEngine),
            this.i18Initialized
        ]);
        this.initContext();
        this.updateLanguage();
        this.bindings = this.getBindings();
        (0, init_queue_cjs_namespaceObject.markParentAsReady)(this);
        this.initLanguage();
        await (0, initialization_common_utils_cjs_namespaceObject.waitForAtomicChildrenToBeDefined)(this);
        await this.getUpdateComplete();
    }
    initContext() {
        this.context = (0, commerce_namespaceObject.buildContext)(this.engine);
    }
    getBindings() {
        return {
            engine: this.engine,
            i18n: this.i18n,
            store: this.store,
            interfaceElement: this
        };
    }
    initLanguage() {
        if (!this.context || this.language) return;
        this.interfaceController.onLanguageChange(this.context.state.language);
    }
    isNewLocale(language, country, currency) {
        if (!this.context) return false;
        return language && language !== this.context.state.language || country && country !== this.context.state.country || currency && currency !== this.context.state.currency;
    }
    constructor(){
        super(), this.bindings = {}, this.interfaceController = new interface_controller_cjs_namespaceObject.InterfaceController(this, 'CoveoAtomic', commerce_namespaceObject.VERSION), this.scrollContainer = 'atomic-commerce-recommendation-interface', this.languageAssetsPath = './lang', this.iconAssetsPath = './assets', this.analytics = true, this.handleInitialization = (event)=>{
            this.interfaceController.onComponentInitializing(event);
        };
        this.store = (0, external_store_cjs_namespaceObject.createCommerceRecommendationStore)();
        const { promise, resolve } = Promise.withResolvers();
        this.i18Initialized = promise;
        this.i18n = external_i18next_default().createInstance(void 0, resolve);
    }
}
AtomicCommerceRecommendationInterface.styles = [
    (0, external_lit_namespaceObject.css)`
      :host {
        display: block;
        height: inherit;
        width: inherit;
        & > slot {
          height: inherit;
        }
      }
    `
];
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    (0, context_namespaceObject.provide)({
        context: bindings_context_cjs_namespaceObject.bindingsContext
    }),
    _ts_metadata("design:type", "u" < typeof CommerceBindings ? Object : CommerceBindings)
], AtomicCommerceRecommendationInterface.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicCommerceRecommendationInterface.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: false
    }),
    _ts_metadata("design:type", "u" < typeof i18n ? Object : i18n)
], AtomicCommerceRecommendationInterface.prototype, "i18n", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: false
    }),
    _ts_metadata("design:type", "u" < typeof CommerceEngine ? Object : CommerceEngine)
], AtomicCommerceRecommendationInterface.prototype, "engine", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'scroll-container',
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicCommerceRecommendationInterface.prototype, "scrollContainer", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'language-assets-path',
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicCommerceRecommendationInterface.prototype, "languageAssetsPath", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'icon-assets-path',
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicCommerceRecommendationInterface.prototype, "iconAssetsPath", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicCommerceRecommendationInterface.prototype, "language", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        reflect: true
    }),
    _ts_metadata("design:type", Boolean)
], AtomicCommerceRecommendationInterface.prototype, "analytics", void 0);
_ts_decorate([
    (0, watch_cjs_namespaceObject.watch)('analytics'),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicCommerceRecommendationInterface.prototype, "toggleAnalytics", null);
_ts_decorate([
    (0, watch_cjs_namespaceObject.watch)('iconAssetsPath'),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicCommerceRecommendationInterface.prototype, "updateIconAssetsPath", null);
_ts_decorate([
    (0, watch_cjs_namespaceObject.watch)('language'),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", Promise)
], AtomicCommerceRecommendationInterface.prototype, "updateLanguage", null);
_ts_decorate([
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicCommerceRecommendationInterface.prototype, "render", null);
AtomicCommerceRecommendationInterface = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-commerce-recommendation-interface'),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicCommerceRecommendationInterface);
exports.AtomicCommerceRecommendationInterface = __webpack_exports__.AtomicCommerceRecommendationInterface;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicCommerceRecommendationInterface"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
