import { normalizeWorkpulseApiBase } from "~/utils/workpulse-api-base";

/** URL file upload WorkPulse (avatar, lampiran laporan, dll.) untuk `<img src>`. */
export function resolveWorkpulseUploadUrl(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}`;
}
