"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__, {
    buildStringTemplateFromProduct: ()=>buildStringTemplateFromProduct,
    getStringValueFromProductOrNull: ()=>getStringValueFromProductOrNull,
    parseValue: ()=>parseValue
});
const commerce_namespaceObject = require("@coveo/headless/commerce");
const object_utils_cjs_namespaceObject = require("../../../utils/object-utils.cjs");
const external_error_cjs_namespaceObject = require("./error.cjs");
function parseValue(product, field) {
    const value = commerce_namespaceObject.ProductTemplatesHelpers.getProductProperty(product, field);
    if (null === value) return null;
    const valueAsNumber = parseFloat(`${value}`);
    if (Number.isNaN(valueAsNumber)) throw new external_error_cjs_namespaceObject.FieldValueIsNaNError(field, value);
    return valueAsNumber;
}
function getStringValueFromProductOrNull(product, field) {
    const value = commerce_namespaceObject.ProductTemplatesHelpers.getProductProperty(product, field);
    if ('string' != typeof value || '' === value.trim()) return null;
    return value;
}
function buildStringTemplateFromProduct(template, product, bindings) {
    return template.replace(/\${(.*?)}/g, (value)=>{
        const key = value.substring(2, value.length - 1);
        let newValue = (0, object_utils_cjs_namespaceObject.readFromObject)(product, key);
        if (!newValue && "u" > typeof window) newValue = (0, object_utils_cjs_namespaceObject.readFromObject)(window, key);
        if (!newValue) {
            bindings.engine.logger.warn(`${key} used in the href template is undefined for this product: ${product.permanentid} and could not be found in the window object.`);
            return '';
        }
        return newValue;
    });
}
exports.buildStringTemplateFromProduct = __webpack_exports__.buildStringTemplateFromProduct;
exports.getStringValueFromProductOrNull = __webpack_exports__.getStringValueFromProductOrNull;
exports.parseValue = __webpack_exports__.parseValue;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "buildStringTemplateFromProduct",
    "getStringValueFromProductOrNull",
    "parseValue"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
