export const PROPERTY_TYPE_LABELS: Record<string, string> = {
  OFFICE: "Office",
  INDUSTRIAL: "Industrial",
  RETAIL: "Retail",
};

export const LISTING_TYPE_LABELS: Record<string, string> = {
  TO_LET: "To Let",
  FOR_SALE: "For Sale",
  SERVICED: "Serviced",
};

/** Listing types staff can pick and visitors can filter by. Richland does not list serviced space. */
export const SELECTABLE_LISTING_TYPES = ["TO_LET", "FOR_SALE"] as const;

export const GRADE_LABELS: Record<string, string> = {
  A_PLUS: "A+",
  A: "A",
  B: "B",
  C: "C",
};

export const VAT_LABELS: Record<string, string> = {
  EXCLUSIVE: "excl. VAT",
  INCLUSIVE: "incl. VAT",
};

export const STATUS_LABELS: Record<string, string> = {
  DRAFT: "Draft",
  ACTIVE: "Active",
  UNDER_OFFER: "Under Offer",
  LET: "Let",
  SOLD: "Sold",
};

export function formatRand(amount: number) {
  return "R" + Math.round(amount).toLocaleString("en-ZA");
}

/** Headline figure: total monthly rent for a letting, or the asking price for a sale. */
export function formatHeadlinePrice(p: {
  listingType: string;
  ratePerM2: number | null;
  monthlyRent: number | null;
  salePrice: number | null;
  sizeM2: number;
  vatStatus: string;
}) {
  const vat = VAT_LABELS[p.vatStatus];
  if (p.listingType === "FOR_SALE") return p.salePrice ? `${formatRand(p.salePrice)} ${vat}` : "POA";
  const monthly = p.monthlyRent ?? (p.ratePerM2 ? p.ratePerM2 * p.sizeM2 : null);
  return monthly ? `${formatRand(monthly)} ${vat} /mo` : "POA";
}

/** Secondary figure: the per-m² rate, derived from the monthly rent when not captured directly. */
export function formatRate(p: { listingType: string; ratePerM2: number | null; monthlyRent: number | null; sizeM2: number }) {
  if (p.listingType === "FOR_SALE") return null;
  const rate = p.ratePerM2 ?? (p.monthlyRent && p.sizeM2 ? p.monthlyRent / p.sizeM2 : null);
  return rate ? `${formatRand(rate)} /m²` : null;
}

export function formatPriceLine(p: { listingType: string; ratePerM2: number | null; monthlyRent: number | null; salePrice: number | null; vatStatus: string }) {
  const vat = VAT_LABELS[p.vatStatus];
  if (p.listingType === "FOR_SALE" && p.salePrice) return `${formatRand(p.salePrice)} ${vat}`;
  if (p.ratePerM2) return `${formatRand(p.ratePerM2)}/m² ${vat}`;
  if (p.monthlyRent) return `${formatRand(p.monthlyRent)}/month ${vat}`;
  return "POA";
}
