/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import { cloneDeep as w } from "lodash-es";
import { bM as V } from "./index.js";
import { f as D, c as y, a as p, R as $ } from "./rest-js-object-literals.js";
function L(i) {
  let r;
  switch (i.length) {
    case 4: {
      const e = i.match(/^#?([\da-f]{1})([\da-f]{1})([\da-f]{1})$/iu);
      e && (r = [
        Number.parseInt(`${e[1]}${e[1]}`, 16),
        Number.parseInt(`${e[2]}${e[2]}`, 16),
        Number.parseInt(`${e[3]}${e[3]}`, 16),
        255
      ]);
      break;
    }
    case 5: {
      const e = i.match(/^#?([\da-f]{1})([\da-f]{1})([\da-f]{1})([\da-f]{1})$/iu);
      e && (r = [
        Number.parseInt(`${e[1]}${e[1]}`, 16),
        Number.parseInt(`${e[2]}${e[2]}`, 16),
        Number.parseInt(`${e[3]}${e[3]}`, 16),
        Number.parseInt(`${e[4]}${e[4]}`, 16)
      ]);
      break;
    }
    case 7: {
      const e = i.match(/^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})$/iu);
      e && (r = [
        Number.parseInt(e[1], 16),
        Number.parseInt(e[2], 16),
        Number.parseInt(e[3], 16),
        255
      ]);
      break;
    }
    case 9: {
      const e = i.match(/^#?([\da-f]{2})([\da-f]{2})([\da-f]{2})([\da-f]{2})$/iu);
      e && (r = [
        Number.parseInt(e[1], 16),
        Number.parseInt(e[2], 16),
        Number.parseInt(e[3], 16),
        Number.parseInt(e[4], 16)
      ]);
      break;
    }
  }
  return r;
}
function N(i) {
  let r;
  if (typeof i == "string" && i.startsWith("#")) {
    const e = L(i);
    e && (r = e);
  } else Array.isArray(i) && i.every((e) => typeof e == "number") && (i.length === 4 ? r = i : i.length === 3 && (r = [...i, 255]));
  return r;
}
function R(i) {
  return i === y.BackwardDiagonal || i === y.Cross || i === y.DiagonalCross || i === y.ForwardDiagonal || i === y.Horizontal || i === y.Null || i === y.Solid || i === y.Vertical;
}
function I(i) {
  return i === p.Dash || i === p.DashDot || i === p.DashDotDot || i === p.Dot || i === p.Null || i === p.Solid;
}
function W(i) {
  const { categoryField: r, numericFields: e, configFields: n, inlineData: s } = i;
  let u = {};
  return n && Object.keys(n).length > 0 && "dataItems" in s && (u = {
    type: "uniqueValue",
    field1: r,
    uniqueValueInfos: []
  }, s.dataItems.forEach((l) => {
    const a = l[r];
    if (a != null) {
      let t = { value: a };
      e.forEach((o) => {
        const c = N(l[`${n.fillColor}_${o}`]), b = l[`${n.fillOpacity}_${o}`], S = l[`${n.fillStyle}_${o}`], m = l[`${n.markerSize}_${o}`], F = N(l[`${n.outlineColor}_${o}`]), O = l[`${n.outlineOpacity}_${o}`], h = l[`${n.outlineWidth}_${o}`], k = l[`${n.outlineStyle}_${o}`], g = N(l[`${n.lineColor}_${o}`]), v = l[`${n.lineOpacity}_${o}`], d = l[`${n.lineWidth}_${o}`], _ = l[`${n.lineStyle}_${o}`], C = l[`${n.displayLabel}_${o}`];
        if (typeof C == "string" && (t = {
          ...t,
          label: C
        }), m != null) {
          const f = { type: D.SMS };
          m && typeof m == "number" && (f.size = m), t.symbol = f;
        }
        if (c || R(S)) {
          const f = t.symbol && t.symbol.type === D.SMS ? t.symbol : {
            type: D.SFS
          };
          if (c && (b && typeof b == "number" && (c[3] = b), f.color = c), R(S) && (f.style = S), t.symbol = f, F || h != null || I(k)) {
            const T = { type: D.SLS };
            F && (O && typeof O == "number" && (F[3] = O), T.color = F), I(k) && (T.style = k), h && typeof h == "number" && (T.width = h), t.symbol.outline = T;
          }
        } else if (g || d != null || I(_)) {
          const f = { type: D.SLS };
          g && (v && typeof v == "number" && (g[3] = v), f.color = g), I(_) && (f.style = _), d != null && typeof d == "number" && (f.width = d), t.symbol = f;
        }
      }), (t.label || t.symbol) && u.uniqueValueInfos.push(t);
    }
  })), u;
}
function E(i) {
  const { numericFields: r, configFields: e, inlineData: n } = i, s = n;
  return "dataItems" in n && Object.entries(e).forEach(([u, l]) => {
    r.forEach((a) => {
      const t = `${l}_${a}`;
      n.dataItems.forEach((o) => {
        t in o && delete o[t];
      });
    });
  }), s;
}
function j(i) {
  const { categoryField: r, categoryType: e, numericFields: n, inlineData: s } = i;
  let u;
  if ("dataItems" in s) {
    const { dataItems: l } = s, a = [];
    let t = "OBJECTID";
    const o = l.map((b, S) => {
      const m = { ...b };
      return "FID" in b ? t = "FID" : "ObjectId" in b && (t = "ObjectId"), m[t] || (m[t] = S), { attributes: m };
    });
    a.push({ type: "esriFieldTypeOID", name: t });
    let c;
    switch (e) {
      case "dateOnly":
        c = $.DateOnly;
        break;
      case "timeStampOffset":
        c = $.TimestampOffset;
        break;
      case "date":
        c = $.Date;
        break;
      case "number":
        c = $.Double;
        break;
      case "string":
      default:
        c = $.String;
        break;
    }
    a.push({ type: c, name: r }), n.forEach((b) => {
      a.push({ type: $.Double, name: b });
    }), u = {
      id: "",
      layerType: "ArcGISFeatureLayer",
      featureCollection: {
        layers: [{ layerDefinition: { fields: a }, featureSet: { features: o } }]
      }
    };
  }
  return u;
}
async function A(i) {
  const { categoryField: r, categoryType: e, numericFields: n, configFields: s, inlineData: u } = i;
  let l, a, t = w(u);
  s && (l = W({
    categoryField: r,
    numericFields: n,
    configFields: s,
    inlineData: t
  }), t = E({
    numericFields: n,
    configFields: s,
    inlineData: t
  }));
  const o = j({
    categoryField: r,
    categoryType: e,
    numericFields: n,
    inlineData: t
  });
  return o && (a = await V(o)), { chartRenderer: l, iLayer: o, layer: a };
}
const B = {
  hexToRGB: L,
  convertColor: N,
  removeConfigFieldsFromData: E
};
export {
  j as a,
  A as b,
  W as c,
  B as i
};
