import { PaymentTerm } from "@/redux/api/paymentTermApi";
import { paymentPlans, paymentStages } from "./Constant";

// Get stage name
export const getStageName = (stageId: string) => {
  const stage = paymentStages.find((s) => s.id === stageId);
  return stage ? stage.name : stageId;
};

// Get trigger display text
export const getTriggerDisplay = (type: string, value: string | number) => {
  if (type === "percentage") {
    return value === "100" ? "100% (Full Payment)" : `${value}%`;
  } else if (type === "amount") {
    return value === "any" ? "Any Amount" : `₹${value}`;
  }
  return value;
};

// Get payment plans text
export const getPaymentPlansText = (
  plans: PaymentTerm["paymentPlans"]
): string => {
  if (!plans || plans.length === 0) return "None";

  const names = plans
    .map((p) => (typeof p === "string" ? p : p.name))
    .filter(Boolean);

  return names.join(", ");
};
