import ky from "ky";

function str(v: unknown): string {
  return typeof v === "string" ? v.trim() : "";
}

const raw = str(import.meta.env.VITE_API_URL);
const base = raw ? raw.replace(/\/?$/, "/") : "";

export const hasApiConfigured = base.length > 0;

export const api = ky.create({
  prefixUrl: base || undefined,
  credentials: "include",
});
