/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import * as c from "@esri/solution-common";
import "@arcgis/core/intl.js";
import "@arcgis/core/geometry/Extent.js";
import u from "@arcgis/core/geometry/SpatialReference.js";
import { isLoaded as d, load as l, execute as f } from "@arcgis/core/geometry/operators/projectOperator.js";
import * as o from "@arcgis/core/geometry/operators/support/geographicTransformationUtils.js";
function y(e) {
  let t = "", r = "?";
  return e.forEach((n) => {
    n.k && n.v && (t += r + n.k + "=" + n.v, r = "&");
  }), t;
}
function v(e) {
  return e ? c.getVelocityUrlBase(e, {}).then((t) => Promise.resolve(!!t)) : Promise.resolve(!1);
}
function S(e) {
  if (e) {
    const t = e.trim();
    return t ? "<div>" + t + "</div>" : "";
  } else
    return "";
}
function m(e) {
  let t = "", r = "?";
  return e.forEach((n) => {
    n.k && n.v && (t += r + n.k + "=" + n.v, r = "&");
  }), t;
}
function I(e, t, r) {
  try {
    const n = new URL(e);
    if (n.searchParams.get(t) === r)
      return n.searchParams.delete(t), n.toString();
  } catch {
  }
  return e;
}
function k(e, t, r, n) {
  let i = "";
  return t ? i = n + "/sharing/rest/content/items/" + e + "/info/" + t + m([{ k: "w", v: "400" }]) : i = r, i;
}
function A(e) {
  const t = e ? e.replace("https://", "").replace("www.", "") : "";
  return t.endsWith("devext.arcgis.com") || t.endsWith("mapsqa.arcgis.com") || t.endsWith("qaext.arcgis.com") ? e ?? "https://www.arcgis.com" : "https://www.arcgis.com";
}
function b(e) {
  return e?.authentication?.PortalSubset?.isReadOnly === !0;
}
async function T(e, t) {
  if (t.spatialReference?.wkid === e)
    return t;
  d() || await l(), o.isLoaded() || await o.load();
  try {
    const r = new u({ wkid: e }), n = o.getTransformation(
      t.spatialReference,
      r,
      t
    );
    return f(
      t,
      r,
      { geographicTransformation: n, areaOfInterestExtent: t }
    ) ?? t;
  } catch {
    return t;
  }
}
function W(e, t) {
  return a(t || e);
}
function R(e, t = "en") {
  return new Intl.DateTimeFormat(t, {
    year: "numeric",
    month: "long",
    day: "numeric"
  }).format(e);
}
function U(e, t) {
  let r = "";
  return e.some((n) => n.startsWith(t) ? (r = n.substring(t.length), !0) : !1), r;
}
function q(e) {
  return !e || !Array.isArray(e) ? "" : e.includes("AIAssistant") ? "AI Assistant" : e.includes("ArcGIS Solution") ? "Esri Provided" : "";
}
function a(e) {
  const t = e.replace("www.", "");
  return t.endsWith("devext.arcgis.com") ? "dev" : t.endsWith("mapsqa.arcgis.com") || t.endsWith("qaext.arcgis.com") ? "qa" : t === "arcgis.com" || t.endsWith(".arcgis.com") ? "prod" : "dev";
}
function L(e, t) {
  let r = e?.reduce((n, i) => (n.indexOf(i.id) < 0 && n.push(i.id), n), []) || [];
  return t ? r.sort((n, i) => t.indexOf(n) - t.indexOf(i)) : r;
}
function O(e) {
  return e.charAt(0).toUpperCase() + e.slice(1);
}
function D(e) {
  return {
    relevance: "Relevance",
    title: "Title",
    new: "New",
    created: "Date deployed",
    updated: "Updated",
    suggested: "Suggested for you"
  }[e] || e;
}
function E(e) {
  if (!e)
    return "Unknown error";
  if (e.message)
    return e.message;
  try {
    const t = JSON.stringify(e);
    return t && t !== "{}" ? t : e.toString();
  } catch {
    return e.toString();
  }
}
function V(e) {
  return e ? parseFloat(((Date.now() - e) / 1e3).toFixed(2)) : 0;
}
function j(e, t) {
  (e.key === "Enter" || e.code === "NumpadEnter" || e.key === " ") && (e.preventDefault(), e.stopPropagation(), t());
}
function x(e) {
  window.dispatchEvent(new CustomEvent("showGlobalAlert", {
    detail: e
  }));
}
function C(e, t) {
  const r = new Set(
    e.filter((n) => n.dependencyItemId !== t).map((n) => `${n.controlItemId}|${n.dependencyItemId}`)
  );
  return Array.from(r).map((n) => {
    const [i, s] = n.split("|");
    return { controlItemId: i, dependencyItemId: s };
  });
}
function P(e) {
  return e.sort((t, r) => {
    const n = t.typeKeywords?.find((s) => s.startsWith("solutionversion-"))?.split("-")[1] || "unknown", i = r.typeKeywords?.find((s) => s.startsWith("solutionversion-"))?.split("-")[1] || "unknown";
    return n === "unknown" || i === "unknown" ? n === "unknown" ? 1 : -1 : i.localeCompare(n, void 0, { numeric: !0 });
  });
}
export {
  A as a,
  R as b,
  S as c,
  k as d,
  m as e,
  L as f,
  U as g,
  C as h,
  b as i,
  q as j,
  x as k,
  j as l,
  V as m,
  E as n,
  D as o,
  v as p,
  T as q,
  I as r,
  P as s,
  O as t,
  W as u,
  y as v
};
