/**
 * Copyright IBM Corp. 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import "../../globals/settings.js";
import { carbonElement } from "../../globals/decorators/carbon-element.js";
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/decorate.js";
import modal_default from "./modal.scss.js";
import { LitElement, html } from "lit";
//#region src/components/modal/modal-body.ts
/**
* Copyright IBM Corp. 2019, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Modal body.
*
* @element cds-modal-body
*/
let CDSModalBody = class CDSModalBody extends LitElement {
	constructor(..._args) {
		super(..._args);
		this.userDefinedTabindex = null;
	}
	connectedCallback() {
		super.connectedCallback?.();
		if (this.hasAttribute("tabindex")) this.userDefinedTabindex = this.getAttribute("tabindex");
		this._resizeObserver = new ResizeObserver(() => this.checkScroll());
		this._resizeObserver.observe(this);
	}
	disconnectedCallback() {
		this._resizeObserver?.disconnect();
		super.disconnectedCallback?.();
	}
	_getAriaLabelledBy() {
		const modal = this.closest(`cds-modal`);
		if (!modal) return null;
		const labelEl = modal.querySelector(`cds-modal-label`);
		if (labelEl?.id) return labelEl.id;
		const headingEl = modal.querySelector(`cds-modal-heading`);
		if (headingEl?.id) return headingEl.id;
		return null;
	}
	_parentHasScrollingContent() {
		return this.closest(`cds-modal`)?.hasAttribute("has-scrolling-content") ?? false;
	}
	checkScroll() {
		const hasScroll = this.scrollHeight > this.clientHeight;
		const hasScrollingContent = this._parentHasScrollingContent();
		const hasAutoAlign = this.querySelector("[autoalign]") !== null;
		if (this.clientHeight <= 300 || hasAutoAlign) this.setAttribute("no-fade", "");
		else this.removeAttribute("no-fade");
		if (hasScrollingContent || hasScroll) {
			if (this.userDefinedTabindex === null) this.setAttribute("tabindex", "0");
			this.setAttribute("is-scrollable", "");
			this.setAttribute("role", "region");
			const ariaLabelledBy = this._getAriaLabelledBy();
			if (ariaLabelledBy) this.setAttribute("aria-labelledby", ariaLabelledBy);
		} else if (!hasScrollingContent) {
			if (this.userDefinedTabindex === null) this.removeAttribute("tabindex");
			this.removeAttribute("is-scrollable");
			this.removeAttribute("role");
			this.removeAttribute("aria-labelledby");
		}
	}
	render() {
		return html` <slot @slotchange=${this.checkScroll}></slot> `;
	}
	static {
		this.styles = modal_default;
	}
};
CDSModalBody = __decorate([carbonElement(`cds-modal-body`)], CDSModalBody);
var modal_body_default = CDSModalBody;
//#endregion
export { modal_body_default as default };

//# sourceMappingURL=modal-body.js.map