export const formatAccountLabel = (account) => {
  if (!account) return "—";
  const base = account.phone || account.user_id || String(account.id);
  const username = account.username ? `@${account.username}` : "";
  return username ? `${base} (${username})` : base;
};

export const formatAccountStatus = (status) => {
  if (status === "limited") return "В спаме";
  if (status === "error") return "Ошибка";
  if (status === "ok") return "ОК";
  return status || "Неизвестно";
};

export const formatTimestamp = (value) => {
  if (!value) return "—";
  const date = value instanceof Date ? value : new Date(value);
  if (Number.isNaN(date.getTime())) return "—";
  return date.toLocaleString("ru-RU");
};

export const formatCountdown = (target, now) => {
  if (!target) return "—";
  const targetTime = new Date(target).getTime();
  if (!Number.isFinite(targetTime)) return "—";
  const diff = Math.max(0, Math.floor((targetTime - now) / 1000));
  const minutes = Math.floor(diff / 60);
  const seconds = diff % 60;
  return `${minutes}:${String(seconds).padStart(2, "0")}`;
};

export const formatTargetType = (value) => {
  if (!value) return "";
  if (value === "channel") return "канал";
  if (value === "megagroup") return "супергруппа";
  if (value === "group") return "группа";
  return value;
};
