/**
 * 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 { TooltipTrigger } from "../TooltipTrigger/TooltipTrigger.js";
import { getSupportedLocale } from "../../global/js/utils/getSupportedLocale.js";
import { Characters, DefaultLocale, formatValue, getIconSize } from "./constants.js";
import { BigNumberSkeleton } from "./BigNumberSkeleton.js";
import React, { forwardRef } from "react";
import PropTypes from "prop-types";
import { Tooltip } from "@carbon/react";
import { ArrowUp, Information } from "@carbon/react/icons";

//#region src/components/BigNumber/BigNumber.tsx
/**
* Copyright IBM Corp. 2024, 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__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--big-number`;
const componentName = "BigNumber";
/**
* BigNumber is used to display large values in a small area. The display of
* values can be the value itself, or grouped in a `numerator/denominator` fashion.
* Control over the total fraction decimals displayed as well as how the
* values/totals are displayed are done via a locale prop. Other optional props
* allow control over size, truncation, if the value is a percentage, the addition
* of a button as well as tool tip functionality.
* The default locale is English (`en-US`) if one is not provided or if the provided one is not supported.
*/
const BigNumber = forwardRef(({ className, forceShowTotal = false, fractionDigits = 1, iconButton, loading = false, label, locale = DefaultLocale, percentage = false, size = "default", tooltipDescription, total, trending = false, truncate = true, value, ...rest }, ref) => {
	const bigNumberClasses = (0, import_classnames.default)(className, {
		[`${blockClass}--lg`]: size === "lg",
		[`${blockClass}--xl`]: size === "xl"
	});
	const supportedLocale = getSupportedLocale(locale, DefaultLocale);
	const truncatedValue = formatValue(supportedLocale, value, fractionDigits, truncate) ?? Characters.Dash;
	const truncatedTotal = formatValue(supportedLocale, total, fractionDigits, truncate) ?? "Unknown";
	const shouldDisplayDenominator = forceShowTotal || !percentage && total && value && total > value && truncatedValue !== truncatedTotal;
	if (loading) return /* @__PURE__ */ React.createElement(BigNumberSkeleton, {
		...rest,
		ref,
		className,
		size,
		...getDevtoolsProps(componentName)
	});
	return /* @__PURE__ */ React.createElement("div", {
		...rest,
		className: (0, import_classnames.default)(blockClass, bigNumberClasses, className),
		ref,
		...getDevtoolsProps(componentName)
	}, /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__row` }, /* @__PURE__ */ React.createElement("h4", { className: `${blockClass}__label` }, label), tooltipDescription && /* @__PURE__ */ React.createElement(Tooltip, {
		description: tooltipDescription,
		align: "right",
		className: `${blockClass}__info`
	}, /* @__PURE__ */ React.createElement(TooltipTrigger, { className: `${blockClass}__tooltip-trigger` }, /* @__PURE__ */ React.createElement(Information, { size: 16 })))), /* @__PURE__ */ React.createElement("span", {
		className: `${blockClass}__row`,
		role: "math"
	}, trending && /* @__PURE__ */ React.createElement(ArrowUp, {
		className: `${blockClass}__trend`,
		size: getIconSize(size)
	}), /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__value` }, percentage ? /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__percentage` }, truncatedValue, /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__percentage-mark` }, "%")) : truncatedValue), shouldDisplayDenominator && /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__total` }, /* @__PURE__ */ React.createElement("span", null, `${Characters.Slash}${truncatedTotal}`)), /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__icon-button` }, iconButton)));
});
BigNumber.displayName = componentName;
BigNumber.propTypes = {
	className: PropTypes.string,
	forceShowTotal: PropTypes.bool,
	fractionDigits: PropTypes.number,
	iconButton: PropTypes.node,
	label: PropTypes.string.isRequired,
	loading: PropTypes.bool,
	locale: PropTypes.string,
	percentage: PropTypes.bool,
	size: PropTypes.oneOf([
		"default",
		"lg",
		"xl"
	]),
	tooltipDescription: PropTypes.string,
	total: PropTypes.number,
	trending: PropTypes.bool,
	truncate: PropTypes.bool,
	value: PropTypes.number
};

//#endregion
export { BigNumber };