"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__, {
    DEFAULT_MOBILE_BREAKPOINT: ()=>DEFAULT_MOBILE_BREAKPOINT,
    updateBreakpoints: ()=>updateBreakpoints
});
const external_dom_utils_cjs_namespaceObject = require("./dom-utils.cjs");
const DEFAULT_MOBILE_BREAKPOINT = '1024px';
function replaceMediaQuery(style, mobileBreakpoint) {
    const regex = new RegExp(`\\(min-width: ${DEFAULT_MOBILE_BREAKPOINT}\\)|\\(width >= ${DEFAULT_MOBILE_BREAKPOINT}\\)`, 'g');
    return style.replace(regex, `(width >= ${mobileBreakpoint})`);
}
function replaceStyleSheet(element, mobileBreakpoint) {
    const stylesheets = element.shadowRoot?.adoptedStyleSheets;
    if (!stylesheets || !stylesheets.length) return;
    const stylesheet = stylesheets[0];
    const style = Object.values(stylesheet.cssRules).map((rule)=>rule.cssText).join('');
    stylesheet.replaceSync(replaceMediaQuery(style, mobileBreakpoint));
}
function replateStyleContent(element, breakpoint) {
    const styleTag = element.shadowRoot?.querySelector('style');
    if (!styleTag) return;
    styleTag.textContent = replaceMediaQuery(styleTag.textContent, breakpoint);
}
const layouts = [
    'atomic-search-layout',
    'atomic-insight-layout'
];
function updateBreakpoints(element) {
    const layout = (0, external_dom_utils_cjs_namespaceObject.closest)(element, layouts.join(', '));
    if (!layout?.mobileBreakpoint) return;
    if (layout.mobileBreakpoint === DEFAULT_MOBILE_BREAKPOINT) return;
    replaceStyleSheet(element, layout.mobileBreakpoint);
    replateStyleContent(element, layout.mobileBreakpoint);
}
exports.DEFAULT_MOBILE_BREAKPOINT = __webpack_exports__.DEFAULT_MOBILE_BREAKPOINT;
exports.updateBreakpoints = __webpack_exports__.updateBreakpoints;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "DEFAULT_MOBILE_BREAKPOINT",
    "updateBreakpoints"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
