/**
 * 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_settings = require("../../settings.js");
const require_devtools = require("../../global/js/utils/devtools.js");
const require_useTruncatedText = require("./useTruncatedText.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _carbon_react = require("@carbon/react");
//#region src/components/TruncatedText/TruncatedText.tsx
/**
* Copyright IBM Corp. 2025
*
* 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 blockClass = `${require_settings.pkg.prefix}--truncated-text`;
const componentName = "TruncatedText";
const TruncatedText = (0, react.forwardRef)((props, ref) => {
	const { align = "top", autoAlign = false, className, collapseLabel, expandLabel, id = `${blockClass}-default-id`, lines = 2, value, type = "tooltip", ...rest } = props;
	const [expanded, setExpanded] = (0, react.useState)(false);
	const { ref: contentRef, truncated } = require_useTruncatedText.default({
		lines,
		value,
		expanded
	});
	const textContentStyles = { WebkitLineClamp: type === "expand" && !expanded || type === "tooltip" ? lines : "none" };
	const textContentClasses = (0, import_classnames.default)(`${blockClass}__text-content`, { [`${blockClass}__text-content--expanded`]: expanded });
	const handleExpand = () => {
		setExpanded(!expanded);
	};
	const handleExpandKey = (evt) => {
		const { key } = evt;
		if (key === "Enter" || key === " ") handleExpand();
	};
	const valueBody = /* @__PURE__ */ react.default.createElement("span", {
		ref: contentRef,
		className: textContentClasses,
		id,
		style: textContentStyles
	}, value);
	const tooltipVariant = truncated ? /* @__PURE__ */ react.default.createElement(_carbon_react.Tooltip, {
		align,
		autoAlign,
		label: value
	}, /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		className: `${blockClass}__tooltip-trigger`,
		"aria-label": value
	}, valueBody)) : valueBody;
	const expandVariant = /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, valueBody, /* @__PURE__ */ react.default.createElement("span", {
		"aria-controls": id,
		"aria-expanded": expanded,
		className: `${blockClass}__expand-toggle`,
		onClick: handleExpand,
		onKeyDown: handleExpandKey,
		role: "button",
		tabIndex: 0
	}, expanded ? collapseLabel : expandLabel));
	const truncatedBody = type === "expand" ? expandVariant : tooltipVariant;
	return /* @__PURE__ */ react.default.createElement("div", {
		...rest,
		className: (0, import_classnames.default)(blockClass, className),
		ref,
		...require_devtools.getDevtoolsProps(componentName)
	}, truncated ? truncatedBody : valueBody);
});
TruncatedText.displayName = componentName;
//#endregion
exports.TruncatedText = TruncatedText;
