"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__, {
    AtomicAriaLive: ()=>AtomicAriaLive
});
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const style_map_js_namespaceObject = require("lit/directives/style-map.js");
const light_dom_cjs_namespaceObject = require("../../../mixins/light-dom.cjs");
const debounce_utils_cjs_namespaceObject = require("../../../utils/debounce-utils.cjs");
const utils_cjs_namespaceObject = require("../../../utils/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 AtomicAriaLive extends (0, light_dom_cjs_namespaceObject.LightDomMixin)(external_lit_namespaceObject.LitElement) {
    connectedCallback() {
        super.connectedCallback();
        this.ariaLiveId = (0, utils_cjs_namespaceObject.randomID)('atomic-aria-live-');
        document.addEventListener('atomic/accessibility/findAriaLive', this.onFindAriaLive);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.messagesQueue.clear();
        document.removeEventListener('atomic/accessibility/findAriaLive', this.onFindAriaLive);
    }
    updateMessage(region, message, assertive) {
        const updateRegion = ()=>{
            this.regions = {
                ...this.regions,
                [region]: {
                    assertive,
                    message
                }
            };
        };
        if (message) this.messagesQueue.enqueue(updateRegion, region);
        else {
            this.messagesQueue.cancelActionIfQueued(region);
            updateRegion();
        }
    }
    registerRegion(region, assertive) {
        if (region in this.regions) return;
        this.regions = {
            ...this.regions,
            [region]: {
                assertive,
                message: ''
            }
        };
    }
    render() {
        const hostStyles = {
            position: 'absolute',
            display: 'block',
            height: '0',
            overflow: 'hidden',
            margin: '0'
        };
        return (0, external_lit_namespaceObject.html)`
      <div style=${(0, style_map_js_namespaceObject.styleMap)(hostStyles)}>
        ${Object.entries(this.regions).map(([regionName, { assertive, message }])=>(0, external_lit_namespaceObject.html)`
            <div
              id="${this.ariaLiveId}-${regionName}"
              aria-live="${assertive ? 'assertive' : 'polite'}"
              role="status"
            >
              ${message}
            </div>
          `)}
      </div>
    `;
    }
    constructor(...args){
        super(...args), this.regions = {}, this.messagesQueue = (0, debounce_utils_cjs_namespaceObject.buildDebouncedQueue)({
            delay: 500
        }), this.onFindAriaLive = (event)=>{
            const customEvent = event;
            customEvent.detail.element = this;
        };
    }
}
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Readonly ? Object : Readonly)
], AtomicAriaLive.prototype, "regions", void 0);
AtomicAriaLive = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-aria-live')
], AtomicAriaLive);
exports.AtomicAriaLive = __webpack_exports__.AtomicAriaLive;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicAriaLive"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
