/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import * as a from "@esri/solution-common";
import "@arcgis/core/intl.js";
import { I as p } from "./interfaces.js";
function L(e) {
  let t = "", r = "?";
  return e.forEach((n) => {
    n.k && n.v && (t += r + n.k + "=" + n.v, r = "&");
  }), t;
}
function N(e) {
  return e ? a.getVelocityUrlBase(e, {}).then((t) => Promise.resolve(!!t)) : Promise.resolve(!1);
}
async function w(e, t) {
  const r = t, n = await r.getUsername(), l = {
    q: new a.SearchQueryBuilder().match(e).in("title").and().match(n).in("owner"),
    filter: "type:Solution",
    authentication: r
  }, f = (await a.searchAllItems(l)).results.map((i) => i.title), { folders: m } = await a.getFoldersAndGroups(r), g = m.map((i) => i.title), o = [...f, ...g].map((i) => i.trim().toLowerCase()), c = e.toLowerCase(), d = o.filter((i) => i === c), h = o.filter((i) => i.startsWith(c));
  return { conflictingNames: d, similiarNames: h };
}
async function W(e, t) {
  return y(e) ? { status: !1, type: "empty" } : v(e) ? { status: !1, type: "exceed length" } : x(e, "folder") ? { status: !1, type: "special character" } : (await w(e.trim(), t)).conflictingNames.length > 0 ? { status: !1, type: "not unique" } : { status: !0, type: "" };
}
function y(e) {
  return e.length <= 0;
}
function v(e) {
  return e.length > p;
}
function x(e, t) {
  return (t === "item" ? /[><~`$^+=|]/u : /[/<>]/u).test(e);
}
function k(e) {
  if (e) {
    const t = e.trim();
    return t ? "<div>" + t + "</div>" : "";
  } else
    return "";
}
function E(e) {
  let t = "", r = "?";
  return e.forEach((n) => {
    n.k && n.v && (t += r + n.k + "=" + n.v, r = "&");
  }), t;
}
function D(e, t, r, n) {
  let s = "";
  return t ? s = n + "/sharing/rest/content/items/" + e + "/info/" + t + E([{ k: "w", v: "400" }]) : s = r, s;
}
function I(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 C(e, t, r) {
  return t.some((n) => n.wkid === e ? (r = n.defaultExtent, !0) : !1), r;
}
function U(e, t) {
  return u(t || e);
}
function b(e, t = "en") {
  return new Intl.DateTimeFormat(t, {
    year: "numeric",
    month: "long",
    day: "numeric"
  }).format(e);
}
function A(e, t) {
  let r = "";
  return e.some((n) => n.startsWith(t) ? (r = n.substring(t.length), !0) : !1), r;
}
function u(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 M(e, t) {
  let r = e?.reduce((n, s) => (n.indexOf(s.id) < 0 && n.push(s.id), n), []) || [];
  return t ? r.sort((n, s) => t.indexOf(n) - t.indexOf(s)) : r;
}
function B(e) {
  return e.charAt(0).toUpperCase() + e.slice(1);
}
function F(e) {
  return {
    relevance: "Relevance",
    title: "Title",
    new: "New",
    created: "Date deployed",
    updated: "Updated",
    suggested: "Suggested for you"
  }[e] || e;
}
function O(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 _(e) {
  return e ? parseFloat(((Date.now() - e) / 1e3).toFixed(2)) : 0;
}
export {
  L as a,
  M as b,
  F as c,
  I as d,
  k as e,
  b as f,
  A as g,
  x as h,
  D as i,
  E as j,
  N as k,
  _ as l,
  O as m,
  U as n,
  C as o,
  w as p,
  B as t,
  W as v
};
