"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__, {
    AtomicResultFieldsList: ()=>AtomicResultFieldsList
});
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const result_context_controller_cjs_namespaceObject = require("../result-template-component-utils/context/result-context-controller.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const light_dom_cjs_namespaceObject = require("../../../mixins/light-dom.cjs");
const slots_for_no_shadow_dom_mixin_cjs_namespaceObject = require("../../../mixins/slots-for-no-shadow-dom-mixin.cjs");
require("../atomic-result-text/atomic-result-text.cjs");
const binding_guard_cjs_namespaceObject = require("../../../decorators/binding-guard.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.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 AtomicResultFieldsList extends (0, light_dom_cjs_namespaceObject.LightDomMixin)((0, slots_for_no_shadow_dom_mixin_cjs_namespaceObject.SlotsForNoShadowDOMMixin)(external_lit_namespaceObject.LitElement)) {
    connectedCallback() {
        super.connectedCallback();
        if (window.ResizeObserver && this.parentElement) {
            this.resizeObserver = new ResizeObserver(()=>this.updateLayout());
            this.resizeObserver.observe(this.parentElement);
        }
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.resizeObserver?.disconnect();
    }
    initialize() {
        if (!this.result && this.resultController.item) {
            const item = this.resultController.item;
            if ('result' in item) this.result = item.result;
            else this.result = item;
        }
    }
    updated(_changedProperties) {
        super.updated(_changedProperties);
        this.updateLayout();
    }
    updateLayout() {
        if (this.updatingChildren) return;
        this.updatingChildren = true;
        this.showDividers();
        this.showChildren();
        this.hideChildrenToFit();
        this.hideDividersAtEndOfRows();
        this.updatingChildren = false;
    }
    get hostChildren() {
        return Array.from(this.children);
    }
    get isOverflowing() {
        return this.scrollWidth > this.clientWidth || this.scrollHeight > this.clientHeight;
    }
    getSortedChildrenBySize() {
        return this.hostChildren.sort((a, b)=>a.offsetWidth - b.offsetWidth);
    }
    hide(element) {
        element.style.display = 'none';
    }
    show(element) {
        element.style.display = '';
    }
    isChildHidden(element) {
        return 'none' === element.style.display;
    }
    setHideDivider(element, hideDivider) {
        element.classList.toggle('hide-divider', hideDivider);
    }
    showChildren() {
        this.hostChildren.forEach((child)=>this.show(child));
    }
    showDividers() {
        this.hostChildren.forEach((child)=>this.setHideDivider(child, false));
    }
    hideChildrenToFit() {
        const children = this.getSortedChildrenBySize();
        for(let i = children.length - 1; this.isOverflowing && i >= 0; i--)this.hide(children[i]);
    }
    hideDividersAtEndOfRows() {
        this.rows = [];
        let previousChild = null;
        this.hostChildren.filter((child)=>!this.isChildHidden(child)).forEach((child)=>{
            const row = child.offsetTop;
            if (-1 === this.rows.indexOf(row)) {
                this.rows.push(row);
                if (previousChild) this.setHideDivider(previousChild, true);
            }
            previousChild = child;
        });
        if (previousChild) this.setHideDivider(previousChild, true);
    }
    render() {
        return (0, external_lit_namespaceObject.html)`${this.renderDefaultSlotContent()}`;
    }
    constructor(...args){
        super(...args), this.resultController = (0, result_context_controller_cjs_namespaceObject.createResultContextController)(this), this.updatingChildren = false, this.rows = [];
    }
}
AtomicResultFieldsList.styles = (0, external_lit_namespaceObject.css)`
    atomic-result-fields-list {
      display: flex;
      flex-wrap: wrap;
      width: 100%;
      height: 100%;
    }

    atomic-result-fields-list > *::after {
      display: block;
      content: ' ';
      width: 1px;
      height: 1rem;
      margin: 0 1rem;
      background-color: var(--atomic-neutral);
      vertical-align: middle;
    }

    atomic-result-fields-list > *.hide-divider::after {
      visibility: hidden;
    }
  `;
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicResultFieldsList.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicResultFieldsList.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Object)
], AtomicResultFieldsList.prototype, "result", void 0);
_ts_decorate([
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicResultFieldsList.prototype, "render", null);
AtomicResultFieldsList = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-result-fields-list'),
    (0, bindings_cjs_namespaceObject.bindings)()
], AtomicResultFieldsList);
exports.AtomicResultFieldsList = __webpack_exports__.AtomicResultFieldsList;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicResultFieldsList"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
