function normalizeSlashes(value) {
  return String(value || "").replace(/\/+$/, "");
}

export function getWindowSettings() {
  return window.settings || {};
}

export function getBaseUrl() {
  const baseUrl = getWindowSettings().base_url || "/";
  return normalizeSlashes(baseUrl) || "";
}

export function getApiBaseUrl() {
  const baseUrl = getBaseUrl();
  return baseUrl ? `${baseUrl}/api/v2` : "/api/v2";
}

export function getSecurePath() {
  return getWindowSettings().secure_path || "";
}

export function getAppMeta() {
  const settings = getWindowSettings();
  return {
    title: settings.title || "Admin",
    version: settings.version || "",
    logo: settings.logo || "",
    baseUrl: getBaseUrl(),
    apiBaseUrl: getApiBaseUrl(),
    securePath: getSecurePath(),
  };
}
