import { get as m } from "es-toolkit/compat";
import { isNil as d } from "es-toolkit";
import { isEqual as A } from "es-toolkit";
import { SortDirection as l } from "./SortUtils.js";
const g = (t) => t === l.DESCENDING ? "-" : "", $ = (t) => t?.sortBy ? `${g(t.sortDir)}${t.sortBy}` : null, D = (t) => t ? t.startsWith("-") ? {
  sortBy: t.substring(1),
  // remove '-'
  sortDir: l.DESCENDING
} : t.startsWith("+") ? {
  sortBy: t.substring(1).trim(),
  // remove '+' and potential space
  sortDir: l.ASCENDING
} : {
  sortBy: t.trim(),
  sortDir: l.ASCENDING
} : null, w = ({
  columnOrder: t = [],
  hiddenColumns: e = [],
  columnsDetails: s = {}
}) => t.map((r) => {
  const i = m(s[r], "width"), o = m(s[r], "defaultWidth"), c = i !== 0 && i !== o ? `:${i}` : "";
  return `${e.includes(r) ? "-" : ""}${r}${c}`;
}), W = (t, e) => {
  const s = {
    columnOrder: [],
    hiddenColumns: [],
    columnsDetails: { ...e }
  };
  return t.forEach((n) => {
    const [r, i] = n.split(":"), o = r.startsWith("-") ? r.substr(1) : r;
    if (s.columnOrder = [...s.columnOrder, o], i) {
      const c = Number.parseInt(i, 10);
      Number.isFinite(c) && (s.columnsDetails[o] = { ...s.columnsDetails[o], width: c });
    } else
      s.columnsDetails[o] = { ...e[o] };
    r.startsWith("-") && (s.hiddenColumns = [...s.hiddenColumns, o]);
  }), s;
}, E = (t, e = []) => {
  const s = new Map(e.map((n) => [n.key, n]));
  return t.map((n) => {
    const r = s.get(n.key), i = !d(n.width) && n.width !== r?.width ? `:${n.width}` : "";
    return `${n.visible === !1 ? "-" : ""}${n.key}${i}`;
  });
}, h = (t, e) => d(t) || t === "" ? e : /^-?\d+(\.\d+)?$/.test(t) ? Number(t) : t, j = (t, e) => {
  const s = new Map(e.map((i) => [i.key, i])), n = /* @__PURE__ */ new Set(), r = [];
  return t.forEach((i) => {
    const [o, c] = i.split(":"), u = o.startsWith("-") ? o.substring(1) : o, a = s.get(u);
    a && (n.add(u), r.push({
      ...a,
      visible: !o.startsWith("-"),
      width: h(c, a.width)
    }));
  }), [...r, ...e.filter((i) => !n.has(i.key))];
}, p = (t) => encodeURIComponent(String(t)), f = (t) => decodeURIComponent(t), B = (t, e) => {
  const s = new Map(e.map((r) => [r.key, r])), n = [];
  return t.forEach((r, i) => {
    const o = s.get(i), c = encodeURIComponent(i), u = encodeURIComponent(r);
    if (o && ["array", "array-number", "object"].includes(o.type ?? "string")) {
      const y = u.replace(/%2C/g, ",").replace(/%3A/g, ":");
      n.push(`${c}=${y}`);
    } else
      n.push(`${c}=${u}`);
  }), n.join("&");
}, k = (t, e) => {
  if (d(t) || t === "")
    return null;
  switch (e) {
    case "string":
    case "number":
      return String(t);
    case "boolean":
      return t ? "true" : "false";
    case "array":
    case "array-number":
      return !Array.isArray(t) || t.length === 0 ? null : t.map(String).join(",");
    case "object":
      return typeof t != "object" || Object.keys(t).length === 0 ? null : Object.entries(t).map(([s, n]) => `${p(s)}:${p(String(n))}`).join(",");
    default:
      return String(t);
  }
}, C = {
  string: (t) => t,
  number: (t) => {
    const e = Number(t);
    return Number.isNaN(e) ? null : e;
  },
  boolean: (t) => {
    const e = t.toLowerCase();
    return e === "true" || e === "1" || e === "yes" || e === "on";
  },
  array: (t) => t.split(",").filter(Boolean),
  "array-number": (t) => t.split(",").map(Number).filter((e) => !Number.isNaN(e)),
  object: (t) => {
    const e = {};
    return t.split(",").forEach((s) => {
      const [n, r] = s.split(":");
      n && r && (e[f(n)] = f(r));
    }), e;
  }
}, z = (t, e) => d(t) ? null : C[e](t);
export {
  j as deserializeColumnsConfig,
  z as deserializeValue,
  g as getSortDirShort,
  A as isEqual,
  w as mapColumnsSettingsToStrings,
  W as parseColumnsSettingsStrings,
  D as parseSorting,
  E as serializeColumnsConfig,
  $ as serializeSorting,
  k as serializeValue,
  B as toQueryString
};
//# sourceMappingURL=routeUtils.js.map
