"use client";

import type { ReactElement, ReactNode } from "react";

import { AdminMoneyDisplay } from "@/components/admin/admin-money-display";
import type { AdminMoneyDisplaySize } from "@/lib/admin-money-display";
import { cn } from "@/lib/utils";

/** 表格/列表内金额：自适应字号 + 换行，配合 TableCell 的 admin-money-cell */
export function AdminTableMoney({
  children,
  className,
  size = "sm",
  emphasize = true,
}: {
  children: ReactNode;
  className?: string;
  size?: AdminMoneyDisplaySize;
  emphasize?: boolean;
}): ReactElement {
  if (typeof children === "string" || typeof children === "number") {
    const text = String(children);
    return (
      <AdminMoneyDisplay
        as="span"
        value={text}
        size={size}
        emphasize={emphasize}
        className={cn("inline-block max-w-full", className)}
      >
        {text}
      </AdminMoneyDisplay>
    );
  }

  return (
    <span className={cn("admin-money-value inline-block max-w-full", className)}>
      {children}
    </span>
  );
}

/** TableCell 金额列常用 className */
export function adminMoneyCellClassName(className?: string): string {
  return cn("admin-money-cell min-w-0 whitespace-normal align-top leading-snug", className);
}
