/**
 * 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_utils = require("./utils.js");
const require_DecoratorIcon = require("./DecoratorIcon.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
//#region src/components/DecoratorBase/DecoratorBase.jsx
/**
* Copyright IBM Corp. 2024, 2024
*
* 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}--decorator`;
const componentName = "DecoratorBase";
const defaults = {
	onClick: () => {},
	onClickLabel: () => {},
	onClickValue: () => {},
	onContextMenu: () => {},
	onContextMenuLabel: () => {},
	onContextMenuValue: () => {},
	scoreThresholds: [
		0,
		4,
		7,
		10
	]
};
/**
* The DecoratorBase groups a key/value pair to look and behave like a single UI element.
*
* DecoratorBase is for internal use only. Refer to the other Decorator types as components for your app.
*/
let DecoratorBase = react.default.forwardRef(({ className, disabled, hideIcon, href, kind, label, setLabelTitle, onClick = defaults.onClick, onClickLabel = defaults.onClickLabel, onClickValue = defaults.onClickValue, onContextMenu = defaults.onContextMenu, onContextMenuLabel = defaults.onContextMenuLabel, onContextMenuValue = defaults.onContextMenuValue, score, scoreThresholds = defaults.scoreThresholds, small, theme, truncateValue, value, valueTitle, ...rest }, ref) => {
	const magnitude = require_utils.getMagnitude(score, scoreThresholds);
	const _labelTitle = setLabelTitle && setLabelTitle(score, scoreThresholds, magnitude);
	const _value = require_utils.truncate(value, truncateValue);
	const classNames = (0, import_classnames.default)(blockClass, className, {
		[`${blockClass}--${theme}`]: theme,
		[`${blockClass}--sm`]: small,
		[`${blockClass}--truncate-end`]: truncateValue === "end",
		[`${blockClass}--truncate-start`]: truncateValue === "start",
		[`${blockClass}--truncate-midline`]: truncateValue?.maxLength
	});
	const decoratorIconsProps = {
		className: `${blockClass}__icon`,
		magnitude: magnitude.toLowerCase(),
		small
	};
	const handleOnClick = (event) => {
		onClick(event, {
			score,
			label,
			value,
			magnitude
		});
	};
	const handleOnContextMenu = (event) => {
		onContextMenu(event, {
			score,
			label,
			value,
			magnitude
		});
	};
	if (kind === "dual-button") {
		const handleOnClickLabel = (event) => {
			onClickLabel(event, {
				score,
				label,
				value,
				magnitude
			});
		};
		const handleOnClickValue = (event) => {
			onClickValue(event, {
				score,
				label,
				value,
				magnitude
			});
		};
		const handleOnContextMenuLabel = (event) => {
			onContextMenuLabel(event, {
				score,
				label,
				value,
				magnitude
			});
		};
		const handleOnContextMenuValue = (event) => {
			onContextMenuValue(event, {
				score,
				label,
				value,
				magnitude
			});
		};
		return /* @__PURE__ */ react.default.createElement("span", {
			...rest,
			className: (0, import_classnames.default)(classNames, `${blockClass}--dual-button`, { [`${blockClass}-disabled`]: disabled }),
			ref
		}, /* @__PURE__ */ react.default.createElement("button", {
			className: `${blockClass}__label`,
			disabled,
			onClick: !disabled && handleOnClickLabel,
			onContextMenu: !disabled && handleOnContextMenuLabel,
			title: _labelTitle || label,
			type: "button"
		}, !hideIcon && /* @__PURE__ */ react.default.createElement(require_DecoratorIcon.DecoratorIcon, decoratorIconsProps), !!label && label), /* @__PURE__ */ react.default.createElement("button", {
			className: `${blockClass}__value`,
			disabled,
			onClick: !disabled && handleOnClickValue,
			onContextMenu: !disabled && handleOnContextMenuValue,
			title: valueTitle || value,
			type: "button"
		}, _value));
	}
	if (kind === "single-button") return /* @__PURE__ */ react.default.createElement("button", {
		...rest,
		className: (0, import_classnames.default)(classNames, `${blockClass}--single-button`, { [`${blockClass}-disabled`]: disabled }),
		disabled,
		onClick: !disabled && handleOnClick,
		onContextMenu: !disabled && handleOnContextMenu,
		ref,
		type: "button"
	}, /* @__PURE__ */ react.default.createElement("span", {
		className: `${blockClass}__label`,
		title: _labelTitle || label
	}, !hideIcon && /* @__PURE__ */ react.default.createElement(require_DecoratorIcon.DecoratorIcon, decoratorIconsProps), !!label && label), /* @__PURE__ */ react.default.createElement("span", {
		className: `${blockClass}__value`,
		title: valueTitle || value
	}, _value));
	if (kind === "link") return /* @__PURE__ */ react.default.createElement("a", {
		...rest,
		href,
		className: (0, import_classnames.default)(classNames, `${blockClass}--link`),
		onClick: handleOnClick,
		onContextMenu: handleOnContextMenu,
		ref
	}, /* @__PURE__ */ react.default.createElement("span", {
		className: `${blockClass}__label`,
		title: _labelTitle || label
	}, !hideIcon && /* @__PURE__ */ react.default.createElement(require_DecoratorIcon.DecoratorIcon, decoratorIconsProps), !!label && label), /* @__PURE__ */ react.default.createElement("span", {
		className: `${blockClass}__value`,
		title: valueTitle || value
	}, _value));
	return /* @__PURE__ */ react.default.createElement("span", {
		...rest,
		className: (0, import_classnames.default)(classNames, `${blockClass}--default`),
		ref
	}, /* @__PURE__ */ react.default.createElement("span", {
		className: `${blockClass}__label`,
		title: _labelTitle || label
	}, !hideIcon && /* @__PURE__ */ react.default.createElement(require_DecoratorIcon.DecoratorIcon, decoratorIconsProps), !!label && label), /* @__PURE__ */ react.default.createElement("span", {
		className: `${blockClass}__value`,
		title: valueTitle || value
	}, _value));
});
DecoratorBase.displayName = componentName;
DecoratorBase.propTypes = {
	className: prop_types.default.string,
	disabled: prop_types.default.bool,
	hideIcon: prop_types.default.bool,
	href: prop_types.default.string,
	/**
	* `kind` differentiates between each type of Decorator, and is for internal use only.
	*/
	kind: prop_types.default.oneOf([
		"default",
		"link",
		"single-button",
		"dual-button"
	]),
	label: prop_types.default.string,
	onClick: prop_types.default.func,
	onClickLabel: prop_types.default.func,
	onClickValue: prop_types.default.func,
	onContextMenu: prop_types.default.func,
	onContextMenuLabel: prop_types.default.func,
	onContextMenuValue: prop_types.default.func,
	score: prop_types.default.number,
	scoreThresholds: prop_types.default.arrayOf(prop_types.default.number),
	setLabelTitle: prop_types.default.func,
	small: prop_types.default.bool,
	theme: prop_types.default.oneOf(["light", "dark"]),
	truncateValue: prop_types.default.oneOfType([prop_types.default.oneOf(["end", "start"]), prop_types.default.shape({
		maxLength: prop_types.default.number,
		front: prop_types.default.number,
		back: prop_types.default.number
	})]),
	value: prop_types.default.string.isRequired,
	valueTitle: prop_types.default.string
};
//#endregion
exports.DecoratorBase = DecoratorBase;
