/**
 * 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 { carbonElement } from "../../globals/decorators/carbon-element.js";
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.126.0/helpers/decorate.js";
import { FeatureFlags, createScope } from "../../packages/feature-flags/es/index.js";
import { LitElement, html } from "lit";
//#region src/components/feature-flags/index.ts
/**
* Copyright IBM Corp. 2025, 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.
*/
/**
* <feature-flags> provides scoped feature flags to child components.
*
* Usage:
* Wrap any child components inside <feature-flags> to provide scoped feature flags like this:
* <feature-flags enable-dialog-element="true">
*   <component></component>
* </feature-flags>
*
* Available flags:
* - enable-dialog-element
* - enable-treeview-controllable
* - ... (and others listed in observedAttributes)
*
* How to check a Flag in your component:
*   import { isFeatureFlagEnabled } from './feature-flags';
*   isFeatureFlagEnabled('enable-dialog-element', this)
*   Returns true if the flag is enabled in the nearest <feature-flags> ancestor
*/
var _FeatureFlagsElement;
const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
let FeatureFlagsElement = class FeatureFlagsElement extends LitElement {
	static {
		_FeatureFlagsElement = this;
	}
	static {
		this.flagComponentMap = {
			"enable-v12-tile-default-icons": "CDS-TILE",
			"enable-v12-tile-radio-icons": "CDS-TILE",
			"enable-v12-overflowmenu": "CDS-OVERFLOW-MENU",
			"enable-treeview-controllable": "CDS-TREEVIEW",
			"enable-experimental-focus-wrap-without-sentinels": "CDS-FOCUS-WRAP",
			"enable-focus-wrap-without-sentinels": "CDS-FOCUS-WRAP",
			"enable-dialog-element": "CDS-DIALOG",
			"enable-v12-dynamic-floating-styles": "CDS-FLOATING",
			"enable-v12-toggle-reduced-label-spacing": "CDS-TOGGLE"
		};
	}
	static get observedAttributes() {
		return Object.keys(_FeatureFlagsElement.flagComponentMap);
	}
	constructor() {
		super();
		this.scope = FeatureFlags;
		this.flags = {};
		this.attachShadow({ mode: "open" });
	}
	connectedCallback() {
		super.connectedCallback();
		this.updateScope();
	}
	attributeChangedCallback(name, _oldVal, newVal) {
		const value = newVal === "true";
		this.flags[name] = value;
		const relatedComponent = hasOwn(_FeatureFlagsElement.flagComponentMap, name) ? _FeatureFlagsElement.flagComponentMap[name] : "unknown";
		if (this.firstElementChild?.tagName === relatedComponent) this.firstElementChild.setAttribute(name, "");
		this.updateScope();
	}
	getParentScope() {
		let parent = this.parentNode;
		while (parent) {
			if (parent instanceof _FeatureFlagsElement) return parent.getScope();
			parent = parent.parentNode;
		}
		return null;
	}
	updateScope() {
		const newScope = createScope(this.flags);
		const parentScope = this.getParentScope() || FeatureFlags;
		if (parentScope) newScope.mergeWithScope(parentScope);
		this.scope = newScope;
	}
	render() {
		return html` <slot></slot> `;
	}
	isFeatureFlagEnabled(flag) {
		return this.scope.enabled(flag);
	}
	getScope() {
		return this.scope;
	}
};
FeatureFlagsElement = _FeatureFlagsElement = __decorate([carbonElement("feature-flags")], FeatureFlagsElement);
var feature_flags_default = FeatureFlagsElement;
function findParentFeatureFlags(el) {
	let parent = el.parentNode;
	while (parent) {
		if (parent instanceof FeatureFlagsElement) return parent;
		parent = parent.parentNode;
	}
	return null;
}
function isFeatureFlagEnabled(flag, context) {
	return findParentFeatureFlags(context)?.isFeatureFlagEnabled(flag) ?? false;
}
//#endregion
export { feature_flags_default as default, findParentFeatureFlags, isFeatureFlagEnabled };

//# sourceMappingURL=index.js.map