import * as moment from "moment";
export const unixToDate = (unix: number) => {
  return moment.unix(unix).format("YYYY/MM/DD");
};
export const msToDate = (ms: number) => {
  return moment.default(ms).format("YYYY/MM/DD");
};

export const getStatusColor = <T>(status: T) => {
  switch (status) {
    case "active":
      return "bg-green text-white";
    case "expired":
      return "bg-orange-light text-white";
    case "cancelled":
      return "bg-error-dark text-white";
    case "awarded":
      return "bg-blue-light-3";
    case "draft":
      return "bg-gray-3";
  }
};
export const formatPhoneNumber = (input?: string) => {
  if (!input) return "";

  let cleaned = input.replace(/[^\d+]/g, "");

  const hasPlus = cleaned.startsWith("+");
  if (hasPlus) {
    cleaned = cleaned.slice(1);
  }

  const groups = [];
  let i = 0;
  while (i < cleaned.length) {
    const size = i === 0 ? 3 : 4;
    groups.push(cleaned.slice(i, i + size));
    i += size;
  }

  return (hasPlus ? "+" : "") + groups.join(" ");
};
export const capitalize = (text: string) => {
  return text
    .split(" ")
    .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
    .join(" ")
    .trim();
};
