/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import "@esri/solution-common";
import { g as a } from "./helpers.js";
function g(o, t) {
  const n = [];
  return o.forEach((e) => {
    t.has(e.id) && n.push(e);
  }), n;
}
function p(o, t, n) {
  if (t < 1 || o.length < t)
    return {
      cards: [],
      paging: {
        start: t,
        num: 0,
        nextStart: -1,
        total: o.length
      }
    };
  const e = Math.min(t + n, o.length + 1), r = e < o.length ? e : -1;
  return {
    cards: o.slice(t - 1, e - 1),
    paging: {
      start: t,
      num: e - t,
      nextStart: r,
      total: o.length
    }
  };
}
function y(o, t) {
  const n = c(o);
  return d(n, t);
}
function d(o, t) {
  let n = [];
  return t.forEach(
    (e) => {
      const r = l(e);
      r && o.indexOf(r) >= 0 && e.relatedSolutions && (n = n.concat(e.relatedSolutions));
    }
  ), new Set(n);
}
function l(o) {
  const t = "solutionid-", n = o.typeKeywords.filter(
    (r) => r.startsWith(t)
  );
  let e = null;
  return Array.isArray(n) && n.length > 0 && (e = n[0].substring(t.length)), e;
}
function c(o) {
  let t = [];
  return o ? (o.forEach(
    (n) => {
      const e = l(n);
      e && t.push(e);
    }
  ), t = Array.from(new Set(t)), t) : [];
}
function m(o) {
  const t = "solutionversion-", n = (o.typeKeywords || []).reduce((e, r) => (r.startsWith(t) && (e = Number(r.replace(t, ""))), e), -1);
  return isNaN(n) ? -1 : n;
}
function w(o, t, n) {
  let e;
  const r = n === "asc" ? 1 : -1;
  switch (t) {
    case "created":
      e = (i, s) => r * (i.createdMs < s.createdMs ? -1 : i.createdMs > s.createdMs ? 1 : 0);
      break;
    case "numviews":
      e = (i, s) => r * (i.numViews < s.numViews ? -1 : i.numViews > s.numViews ? 1 : 0);
      break;
    case "title":
      e = (i, s) => r * (i.title.toLowerCase() < s.title.toLowerCase() ? -1 : i.title.toLowerCase() > s.title.toLowerCase() ? 1 : 0);
      break;
    default:
      e = () => 0;
      break;
  }
  return o.sort(e), o;
}
function u(o) {
  return o.toLowerCase().replace(/\s+/g, "-");
}
function h(o, t) {
  return o.find((n) => u(n.title) === t || t === n.id);
}
function I(o, t) {
  const n = "solutionid-";
  return o.find((e) => a(e.typeKeywords, n) === t);
}
function b(o, t) {
  const n = o.find((e) => t === e.deployCommonId);
  return u(n.title);
}
export {
  I as a,
  m as b,
  g as c,
  u as d,
  p as e,
  b as f,
  y as g,
  h,
  w as s
};
