import { normalizeWorkpulseApiBase } from "~/utils/workpulse-api-base";

/** URL foto profil yang bisa dipakai di `<img src>`. */
export function resolveWorkpulseAvatarUrl(url: string | null | undefined): string | null {
  const u = (url ?? "").trim();
  if (!u) return null;
  if (/^(https?:|data:|blob:)/i.test(u)) return u;
  const base = normalizeWorkpulseApiBase(String(useRuntimeConfig().public.workpulseApiBase || ""));
  if (!base) return u.startsWith("/") ? u : `/${u}`;
  const path = u.startsWith("/") ? u : `/${u}`;
  return `${base}${path}`;
}
