/**
 * Copyright IBM Corp. 2020, 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.
 */

const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
const require_index = require('../../../node_modules/classnames/index.js');
const require_useIsomorphicEffect = require('../../../global/js/hooks/useIsomorphicEffect.js');
const require_PageHeaderUtils = require('../PageHeaderUtils.js');
const require_context = require('./context.js');
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");

//#region src/components/PageHeader/next/PageHeaderContent.tsx
/**
* 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.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const PageHeaderContent = react.default.forwardRef(function PageHeaderContent({ className, children, title, renderIcon: IconElement, contextualActions, pageActions, ...other }, ref) {
	const contentRef = (0, react.useRef)(null);
	const componentRef = ref ?? contentRef;
	const { setRefs, setPageActionsInstance, observerState } = require_context.usePageHeader();
	const classNames = (0, import_classnames.default)({ [`${require_PageHeaderUtils.blockClass}__content`]: true }, className);
	const titleRef = (0, react.useRef)(null);
	const resolvedPageActions = (0, react.useMemo)(() => typeof pageActions === "function" ? pageActions(observerState) : pageActions, [pageActions, observerState]);
	(0, react.useEffect)(() => {
		if (componentRef?.current) setRefs((prev) => ({
			...prev,
			contentRef: componentRef,
			titleRef
		}));
	}, []);
	(0, react.useEffect)(() => {
		if (resolvedPageActions) setPageActionsInstance(resolvedPageActions);
	}, [resolvedPageActions]);
	const [isEllipsisApplied, setIsEllipsisApplied] = (0, react.useState)(false);
	const isEllipsisActive = (element) => {
		setIsEllipsisApplied(element.offsetHeight < element.scrollHeight);
		return element.offsetHeight < element.scrollHeight;
	};
	require_useIsomorphicEffect.useIsomorphicEffect(() => {
		titleRef.current && isEllipsisActive(titleRef.current);
	}, [title]);
	return /* @__PURE__ */ react.default.createElement(_carbon_react.Section, {
		as: "div",
		className: classNames,
		ref: componentRef,
		...other
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.Grid, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Column, {
		lg: 16,
		md: 8,
		sm: 4
	}, /* @__PURE__ */ react.default.createElement("div", { className: `${require_PageHeaderUtils.blockClass}__content__title-wrapper` }, /* @__PURE__ */ react.default.createElement("div", { className: `${require_PageHeaderUtils.blockClass}__content__start` }, /* @__PURE__ */ react.default.createElement("div", { className: `${require_PageHeaderUtils.blockClass}__content__title-container` }, IconElement && /* @__PURE__ */ react.default.createElement("div", { className: `${require_PageHeaderUtils.blockClass}__content__icon` }, /* @__PURE__ */ react.default.createElement(IconElement, null)), isEllipsisApplied ? /* @__PURE__ */ react.default.createElement(_carbon_react.DefinitionTooltip, { definition: title }, /* @__PURE__ */ react.default.createElement(_carbon_react.unstable_Text, {
		ref: titleRef,
		as: _carbon_react.Heading,
		className: `${require_PageHeaderUtils.blockClass}__content__title`
	}, title)) : /* @__PURE__ */ react.default.createElement(_carbon_react.unstable_Text, {
		ref: titleRef,
		as: _carbon_react.Heading,
		className: `${require_PageHeaderUtils.blockClass}__content__title`
	}, title)), contextualActions && /* @__PURE__ */ react.default.createElement("div", { className: `${require_PageHeaderUtils.blockClass}__content__contextual-actions` }, contextualActions)), resolvedPageActions), children)));
});
PageHeaderContent.displayName = "PageHeaderContent";
PageHeaderContent.propTypes = {
	children: prop_types.default.node,
	className: prop_types.default.string,
	contextualActions: prop_types.default.node,
	pageActions: prop_types.default.node,
	renderIcon: prop_types.default.oneOfType([prop_types.default.func, prop_types.default.object]),
	subtitle: prop_types.default.string,
	title: prop_types.default.string.isRequired
};

//#endregion
exports.PageHeaderContent = PageHeaderContent;