/**
 * 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.
 */

import { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import { getDevtoolsProps } from "../../global/js/utils/devtools.js";
import uuidv4 from "../../global/js/utils/uuidv4.js";
import React, { useRef, useState } from "react";
import PropTypes from "prop-types";
import { ChevronDown } from "@carbon/react/icons";
//#region src/components/NonLinearReading/NonLinearReading.tsx
/**
* Copyright IBM Corp. 2023, 2023
*
* 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__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--non-linear-reading`;
const componentName = "NonLinearReading";
/**
* Use non-linear reading when space is limited to share a
* brief, at-a-glance, summary of a concept that may require
* more explanation for some users.
*/
const NonLinearReading = React.forwardRef(({ children, className, definition, theme = "light", ...rest }, ref) => {
	const [isOpen, setOpen] = useState(false);
	const contentId = useRef(uuidv4()).current;
	const handleToggle = () => {
		setOpen((prevState) => !prevState);
	};
	return /* @__PURE__ */ React.createElement("span", {
		...rest,
		className: (0, import_classnames.default)(blockClass, `${blockClass}__${theme}`, className),
		ref,
		...getDevtoolsProps(componentName)
	}, " ", /* @__PURE__ */ React.createElement("button", {
		type: "button",
		"aria-controls": contentId,
		"aria-expanded": isOpen,
		className: (0, import_classnames.default)(`${blockClass}__keyword`, [isOpen ? [`${blockClass}__keyword-open`] : [`${blockClass}__keyword-closed`]]),
		onClick: handleToggle
	}, children, /* @__PURE__ */ React.createElement(ChevronDown, { size: 16 })), " ", /* @__PURE__ */ React.createElement("span", {
		id: contentId,
		className: `${blockClass}__body`,
		hidden: !isOpen
	}, isOpen && definition), " ");
});
NonLinearReading.displayName = componentName;
NonLinearReading.propTypes = {
	/**
	* The keyword of the component appears as a pill.
	*/
	children: PropTypes.node.isRequired,
	/**
	* Provide an optional class to be applied to the containing node.
	*/
	className: PropTypes.string,
	/**
	* The content that appears when the keyword is toggled open.
	*/
	definition: PropTypes.node.isRequired,
	/**
	* Determines the theme of the component.
	*/
	theme: PropTypes.oneOf(["light", "dark"])
};
//#endregion
export { NonLinearReading };
