import TrendIcon from "./TrendIcon.js";
import { formatMetricValue } from "../utils/formatMetricValue.js";
import { calculateTrend } from "../utils/calculateTrend.js";
import React, { useMemo } from "react";
//#region src/components/pisellMetricCard/components/MetricComparison.tsx
/**
* MetricComparison 环比信息组件
* 
* 负责渲染环比数值和趋势箭头
* - 自动根据正负值显示不同颜色
* - 支持格式化环比数值
* - 集成趋势箭头组件
* 
* @param props 组件属性
*/
const MetricComparison = ({ comparison, comparisonText = "v.s. pre", showTrendIcon = true, positiveColor = "#52c41a", negativeColor = "#ff4d4f", comparisonSize = 14, precision, showCurrencySymbol, currencySymbol }) => {
	const trend = useMemo(() => {
		return calculateTrend(comparison);
	}, [comparison]);
	const formattedComparison = useMemo(() => {
		if (comparison === null || comparison === void 0) return null;
		const numComparison = typeof comparison === "string" ? parseFloat(comparison) : comparison;
		if (isNaN(numComparison)) return null;
		return formatMetricValue(Math.abs(numComparison), {
			precision,
			showCurrencySymbol,
			currencySymbol,
			useGrouping: false
		});
	}, [
		comparison,
		precision,
		showCurrencySymbol,
		currencySymbol
	]);
	if (formattedComparison === null || trend === "neutral") return null;
	const color = trend === "up" ? positiveColor : negativeColor;
	const sign = trend === "up" ? "+" : "-";
	return /* @__PURE__ */ React.createElement("div", {
		className: "pisell-metric-card-comparison",
		style: {
			fontSize: typeof comparisonSize === "number" ? `${comparisonSize}px` : comparisonSize,
			color
		}
	}, /* @__PURE__ */ React.createElement("span", null, comparisonText), /* @__PURE__ */ React.createElement("span", null, sign, formattedComparison), showTrendIcon && /* @__PURE__ */ React.createElement(TrendIcon, {
		trend,
		color
	}));
};
//#endregion
export { MetricComparison as default };
