/**
 * Order display utilities
 * Re-exports domain logic for backward compatibility in the frontend
 */

import type { OrderDisplayItem } from "@customer-portal/domain/orders";

export {
  buildOrderDisplayItems,
  categorizeOrderItem,
} from "@customer-portal/domain/orders";

export type {
  OrderDisplayItem,
  OrderDisplayItemCategory,
  OrderDisplayItemCharge,
  OrderDisplayItemChargeKind,
} from "@customer-portal/domain/orders";

/**
 * Summarize order display items for compact display
 */
export function summarizeOrderDisplayItems(
  items: OrderDisplayItem[],
  fallback: string
): string {
  if (items.length === 0) {
    return fallback;
  }

  const [primary, ...rest] = items;
  if (rest.length === 0) {
    return primary.name;
  }

  return `${primary.name} +${rest.length} more`;
}
