import { convertToPercent } from "./rangeConverter.js";
import { formatNumber } from "@pisell/utils";
//#region src/components/pisellPercent/utils/percentFormatter.ts
/**
* 格式化百分比数值
* 
* @param value 数值
* @param options 格式化选项
* @returns 格式化后的百分比字符串
* 
* @example
* formatPercent(85.5, { showPercentSymbol: true, precision: 1, range: [0, 100] })
* // 返回: '85.5%'
* 
* @example
* formatPercent(0.855, { showPercentSymbol: true, precision: 1, range: [0, 1] })
* // 返回: '85.5%'
*/
function formatPercent(value, options) {
	if (value === null || value === void 0) return null;
	const { showPercentSymbol, precision, range } = options;
	const percentValue = convertToPercent(value, range);
	if (percentValue === null) return null;
	const formatted = formatNumber(percentValue, { precision });
	if (!formatted) return null;
	if (showPercentSymbol) return `${formatted}%`;
	return formatted;
}
//#endregion
export { formatPercent };
