/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import * as s from "@esri/solution-common";
const T = 250, F = /* @__PURE__ */ new Set([
  "add",
  "all",
  "alter",
  "and",
  "any",
  "as",
  "asc",
  "backup",
  "between",
  "by",
  "case",
  "check",
  "column",
  "constraint",
  "create",
  "database",
  "date",
  "default",
  "delete",
  "desc",
  "distinct",
  "drop",
  "exec",
  "exists",
  "foreign",
  "from",
  "full",
  "group",
  "having",
  "in",
  "index",
  "inner",
  "insert",
  "into",
  "is",
  "join",
  "key",
  "left",
  "like",
  "limit",
  "not",
  "null",
  "on",
  "or",
  "order",
  "outer",
  "primary",
  "procedure",
  "right",
  "rownum",
  "select",
  "set",
  "shape",
  "subtype",
  "table",
  "top",
  "truncate",
  "union",
  "unique",
  "update",
  "values",
  "view",
  "where"
]), g = /* @__PURE__ */ new Set([
  "objectid",
  "globalid",
  "created_date",
  "created_user",
  "last_edited_date",
  "last_edited_user",
  "fid",
  "shape",
  "shape_length",
  "shape_area"
]), V = /[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F1E0}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F900}-\u{1F9FF}\u{1F018}-\u{1F270}\u{238C}-\u{2454}\u{20D0}-\u{20FF}\u{FE0F}]/u;
function n(e) {
  return !e || e.trim().length === 0;
}
function u(e) {
  return e.length > T;
}
function l(e, r) {
  return V.test(e) ? !0 : r === "item" ? /[><~`$^+=|\\]/u.test(e) : /[/<>\\]/u.test(e);
}
async function w(e, r) {
  const t = r, a = await t.getUsername(), f = {
    q: new s.SearchQueryBuilder().match(e).in("title").and().match(a).in("owner"),
    filter: "type:Solution",
    authentication: t
  }, d = (await s.searchAllItems(f)).results.map((i) => i.title), { folders: p } = await s.getFoldersAndGroups(t), y = p.map((i) => i.title), o = [...d, ...y].map((i) => i.trim().toLowerCase()), c = e.toLowerCase(), h = o.filter((i) => i === c), m = o.filter((i) => i.startsWith(c));
  return { conflictingNames: h, similiarNames: m };
}
async function v(e, r, t = !1) {
  return n(e) ? { isValid: !1, errorType: "empty" } : u(e) ? { isValid: !1, errorType: "exceed-length" } : l(e, "folder") || l(e, "item") ? { isValid: !1, errorType: "special-character" } : !t && r && (await w(e.trim(), r)).conflictingNames.length > 0 ? { isValid: !1, errorType: "not-unique" } : { isValid: !0, errorType: null };
}
function x(e) {
  return n(e) ? { isValid: !1, errorType: "empty" } : u(e) ? { isValid: !1, errorType: "exceed-length" } : l(e, "item") ? { isValid: !1, errorType: "special-character" } : { isValid: !0, errorType: null };
}
function L(e, r, t = !1) {
  if (e.length > r)
    return { isValid: !1, errorType: "exceed-length" };
  const a = [];
  return e.includes("<") && a.push("<"), e.includes(">") && a.push(">"), !t && e.includes("/") && a.push("/"), a.length > 0 ? { isValid: !1, errorType: "special-character" } : { isValid: !0, errorType: null };
}
function C(e) {
  return n(e) ? { isValid: !1, errorType: "empty" } : u(e) ? { isValid: !1, errorType: "exceed-length" } : { isValid: !0, errorType: null };
}
function S(e, r = []) {
  return n(e) ? { isValid: !1, errorType: "empty" } : /^[\p{L}][\p{L}\p{N}\p{M}_]*$/u.test(e) ? e.length > 31 ? { isValid: !1, errorType: "exceed-length" } : F.has(e.toLowerCase()) ? { isValid: !1, errorType: "sql-keyword" } : g.has(e.toLowerCase()) ? { isValid: !1, errorType: "system-field" } : r.includes(e.toLowerCase()) ? { isValid: !1, errorType: "duplicate-field" } : { isValid: !0, errorType: null } : { isValid: !1, errorType: "invalid-format" };
}
function b(e) {
  return e < 1 || e > 4e3 ? { isValid: !1, errorType: "out-of-range" } : { isValid: !0, errorType: null };
}
function I(e, r, t = !1) {
  return t ? { isValid: !0, errorType: null } : e.trim().length === 0 ? { isValid: !1, errorType: "empty" } : e.length > r ? { isValid: !1, errorType: "exceed-length" } : { isValid: !0, errorType: null };
}
export {
  F as S,
  v as a,
  L as b,
  w as c,
  C as d,
  S as e,
  I as f,
  b as g,
  x as v
};
