/**
 * 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 { getComponentText } from "./utils.js";
import React, { useEffect, useMemo, useRef, useState } from "react";
import PropTypes from "prop-types";
import { Button, Heading, IconButton, Section } from "@carbon/react";
import { Close, Crossroads, Idea } from "@carbon/react/icons";

//#region src/components/InlineTip/InlineTip.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}--inline-tip`;
const componentName = "InlineTip";
const defaults = {
	closeIconDescription: "Close",
	collapsible: false,
	collapseButtonLabel: "Read less",
	expandButtonLabel: "Read more",
	narrow: false,
	withLeftGutter: false,
	onClick: () => {},
	onClose: () => {},
	title: "Use case-specific heading"
};
/**
* Inline tips are messages embedded within other components that
* provide an ambient way to deliver learning content without
* distracting the user from their flow.
*/
const InlineTip = React.forwardRef(({ action, children, className, closeIconDescription = defaults.closeIconDescription, collapsible = defaults.collapsible, collapseButtonLabel = defaults.collapseButtonLabel, expandButtonLabel = defaults.expandButtonLabel, renderMedia, narrow = defaults.narrow, onClick, onClose, tertiaryButtonLabel, title = defaults.title, withLeftGutter = defaults.withLeftGutter, ...rest }, ref) => {
	const [isCollapsed, setIsCollapsed] = useState(collapsible);
	const labelId = useRef(uuidv4()).current;
	const previewText = useMemo(() => getComponentText(React.Children.toArray(children)), [children]);
	let childrenToRender = children;
	if (!renderMedia && collapsible && isCollapsed) childrenToRender = /* @__PURE__ */ React.createElement("p", { className: `${blockClass}__preview-text` }, previewText);
	useEffect(() => {
		setIsCollapsed(collapsible);
	}, [collapsible]);
	return /* @__PURE__ */ React.createElement(Section, {
		...rest,
		"aria-labelledby": labelId,
		className: (0, import_classnames.default)(blockClass, className, collapsible && `${blockClass}__collapsible`, isCollapsed && `${blockClass}__collapsible-collapsed`, renderMedia && `${blockClass}__has-media`, [narrow ? `${blockClass}__narrow` : `${blockClass}__wide`], withLeftGutter && !narrow && `${blockClass}__with-left-gutter`),
		ref,
		role: "complementary",
		...getDevtoolsProps(componentName)
	}, /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__close-icon-wrapper` }, /* @__PURE__ */ React.createElement(IconButton, {
		className: `${blockClass}__close-icon`,
		kind: "ghost",
		label: closeIconDescription,
		onClick: onClose,
		size: "lg"
	}, /* @__PURE__ */ React.createElement(Close, { size: 16 }))), (!renderMedia && narrow || !narrow) && /* @__PURE__ */ React.createElement("div", {
		className: `${blockClass}__icon-idea`,
		tabIndex: -1
	}, /* @__PURE__ */ React.createElement(Idea, { size: 16 })), /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__content` }, /* @__PURE__ */ React.createElement(Heading, {
		id: labelId,
		className: `${blockClass}__title`
	}, title), /* @__PURE__ */ React.createElement("section", { className: `${blockClass}__body` }, childrenToRender, action && (!collapsible || collapsible && !isCollapsed) && /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__secondary-btn` }, action)), (collapsible || tertiaryButtonLabel) && /* @__PURE__ */ React.createElement("footer", { className: `${blockClass}__footer` }, collapsible && !renderMedia && /* @__PURE__ */ React.createElement(Button, {
		className: `${blockClass}__toggle-btn`,
		kind: "ghost",
		size: "md",
		onClick: () => {
			setIsCollapsed((prevState) => !prevState);
		}
	}, isCollapsed ? expandButtonLabel : collapseButtonLabel), tertiaryButtonLabel && /* @__PURE__ */ React.createElement(Button, {
		className: `${blockClass}__close-btn`,
		size: "md",
		onClick,
		kind: "tertiary",
		renderIcon: () => /* @__PURE__ */ React.createElement(Crossroads, { size: 16 })
	}, tertiaryButtonLabel))), renderMedia && /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__media` }, renderMedia()));
});
InlineTip.displayName = componentName;
InlineTip.propTypes = {
	action: PropTypes.node,
	children: PropTypes.node.isRequired,
	className: PropTypes.string,
	closeIconDescription: PropTypes.string,
	collapseButtonLabel: PropTypes.string,
	collapsible: PropTypes.bool,
	expandButtonLabel: PropTypes.string,
	narrow: PropTypes.bool,
	onClick: PropTypes.func,
	onClose: PropTypes.func,
	renderMedia: PropTypes.func,
	tertiaryButtonLabel: PropTypes.string,
	title: PropTypes.string.isRequired,
	withLeftGutter: PropTypes.bool
};

//#endregion
export { InlineTip };