"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__, {
    AtomicProductPrice: ()=>AtomicProductPrice
});
const commerce_namespaceObject = require("@coveo/headless/commerce");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const product_context_controller_cjs_namespaceObject = require("../product-template-component-utils/context/product-context-controller.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 multi_class_map_cjs_namespaceObject = require("../../../directives/multi-class-map.cjs");
const light_dom_cjs_namespaceObject = require("../../../mixins/light-dom.cjs");
const format_common_cjs_namespaceObject = require("../../common/formats/format-common.cjs");
const product_utils_cjs_namespaceObject = require("../product-template-component-utils/product-utils.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 AtomicProductPrice extends (0, light_dom_cjs_namespaceObject.LightDomMixin)(external_lit_namespaceObject.LitElement) {
    initialize() {
        this.context = (0, commerce_namespaceObject.buildContext)(this.bindings.engine);
    }
    get product() {
        return this.productController.item;
    }
    formatValue(value) {
        try {
            const { currency } = this.contextState;
            const formatter = (0, format_common_cjs_namespaceObject.defaultCurrencyFormatter)(currency);
            return formatter(value, this.bindings.i18n.languages);
        } catch (error) {
            this.error = error;
            return value.toString();
        }
    }
    getFormattedValue(field) {
        const value = (0, product_utils_cjs_namespaceObject.parseValue)(this.product, field);
        if (null !== value) return this.formatValue(value);
    }
    get hasPromotionalPrice() {
        return this.product && null !== this.product.ec_promo_price && null !== this.product.ec_price && this.product.ec_promo_price < this.product.ec_price;
    }
    render() {
        const hasPromo = this.hasPromotionalPrice;
        const priceClasses = (0, multi_class_map_cjs_namespaceObject.tw)({
            'truncate break-keep text-2xl leading-[1.5]': true,
            'text-error': hasPromo
        });
        const promoClasses = (0, multi_class_map_cjs_namespaceObject.tw)({
            'original-price content-center truncate text-xl break-keep line-through leading-none': true,
            invisible: !hasPromo
        });
        return (0, external_lit_namespaceObject.html)`
      <div class="flex flex-wrap gap-1">
        <div class=${(0, multi_class_map_cjs_namespaceObject.multiClassMap)(priceClasses)}>
          ${this.getFormattedValue(hasPromo ? 'ec_promo_price' : 'ec_price')}
        </div>
        <div class=${(0, multi_class_map_cjs_namespaceObject.multiClassMap)(promoClasses)}>
          ${hasPromo ? this.getFormattedValue('ec_price') : '\u200B'}
        </div>
      </div>
    `;
    }
    constructor(...args){
        super(...args), this.productController = (0, product_context_controller_cjs_namespaceObject.createProductContextController)(this);
    }
}
AtomicProductPrice.styles = (0, external_lit_namespaceObject.css)`
    atomic-product-price.display-grid div {
      flex-direction: column;
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof CommerceBindings ? Object : CommerceBindings)
], AtomicProductPrice.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicProductPrice.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('context'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof ContextState ? Object : ContextState)
], AtomicProductPrice.prototype, "contextState", void 0);
_ts_decorate([
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicProductPrice.prototype, "render", null);
AtomicProductPrice = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-product-price'),
    (0, bindings_cjs_namespaceObject.bindings)()
], AtomicProductPrice);
exports.AtomicProductPrice = __webpack_exports__.AtomicProductPrice;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicProductPrice"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
