import { html as h, svg as b } from "lit";
import { renderColorRampPreviewHTML as C } from "@arcgis/core/symbols/support/symbolUtils.js";
import { renderElement as E, safeClassMap as $, safeStyleMap as p } from "@arcgis/lumina";
import { p as d, s as I, g as M } from "./utils2.js";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
const w = 10, z = 20, u = 10, g = 20, S = {
  // univariate above-and-below
  univariateAboveAndBelowSymbol: "arcgis-univariate-above-and-below-ramp__symbol",
  colorRamp: "arcgis-legend__color-ramp"
};
function v(o) {
  return typeof o == "number";
}
function P(o = "vertical") {
  const e = "stroke:rgb(200, 200, 200);stroke-width:1";
  return o === "vertical" ? h`<svg height=4 width=10>${b`<line style=${p(e)} x1=0 x2=10 y1=2 y2=2 />`}</svg>` : h`<svg height=10 width=10>${b`<line style=${p(e)} x1=5 x2=5 y1=0 y2=10 />`}</svg>`;
}
function L(o, e = "vertical") {
  const s = {
    height: `${z}px`,
    opacity: o?.toString()
  };
  return h`<div class=${$(S.univariateAboveAndBelowSymbol)} style=${p(s)}>${P(e)}</div>`;
}
function y(o, e, s, a = "vertical", t) {
  o.infos.forEach((i, n) => {
    if (t && n === 2) {
      i.preview = E(L(s, a));
      return;
    } else {
      const l = (v(i.size) ? d(i.size) : 0) + (a === "horizontal" ? g : u), f = i.preview, c = f?.tagName.toLowerCase() === "div", r = c ? f : document.createElement("div");
      r.className = S.univariateAboveAndBelowSymbol, a === "horizontal" ? r.style.width = `${l}px` : r.style.height = `${l}px`, !c && f && r.appendChild(f), I(r, M(e, i.label)), i.preview = r;
    }
  });
}
function H(o, e = "classic") {
  const s = o.infos, a = s.at(0), t = s.at(-1), i = v(a.size) ? d(a.size) : 0, n = v(t.size) ? d(t.size) : 0;
  return e === "classic" ? (i + u) / 2 : (i - n) / 2;
}
function k(o, e) {
  if (!o)
    return null;
  const s = o.infos.map((t) => t.color), a = C(
    e.type === "full" ? s : e.type === "above" ? s.slice(0, 3) : s.slice(2, 5),
    // Last 3 colors
    {
      width: e.width ?? void 0,
      height: e.height ?? void 0,
      align: e.rampAlignment,
      cssEffectFilter: e.cssEffectFilter,
      ariaLabel: e.ariaLabel ?? void 0
    }
  );
  return a.className = S.colorRamp, e.opacity != null && (a.style.opacity = e.opacity.toString()), a;
}
function U(o, e, s, a = "vertical") {
  let t = 0;
  const i = o.infos, n = Math.floor(i.length / 2), l = e === "full" || e === "above" ? 0 : n, f = e === "full" || e === "below" ? i.length - 1 : n;
  for (let c = l; c <= f; c++)
    if (s && c === n)
      t += a === "horizontal" ? w : z;
    else {
      const r = i[c].size, m = (v(r) ? d(r) : 0) + (a === "horizontal" ? g : u);
      t += m;
    }
  return Math.round(t);
}
function D(o, e, s, a = "vertical") {
  const t = U(o, e, s, a), i = o.infos, n = Math.floor(i.length / 2), l = e === "full" || e === "above" ? 0 : n, f = e === "full" || e === "below" ? i.length - 1 : n, c = v(i[l].size) ? i[l].size : 0, r = v(i[f].size) ? i[f].size : 0, m = e === "full" ? c + r : e === "above" ? c : r, x = s ? a === "vertical" ? z : w : 0, R = a === "vertical" ? u * (e === "full" ? 2 : 1) : g * (e === "full" ? 2 : 1);
  return Math.round(t - (d(m) / 2 + x / 2 + R / 2));
}
function F(o, e, s, a = "vertical") {
  const t = o.infos;
  let i = t.find(({ type: l }) => l === "size-ramp"), n = t.find(({ type: l }) => l === "color-ramp");
  return i && (i = { ...i }, i.infos = [...i.infos], y(i, e, s, a, !0)), n && (n = { ...n }, n.infos = [...n.infos]), a === "horizontal" && (i?.infos.reverse(), n?.infos.reverse()), { sizeRampElement: i, colorRampElement: n };
}
function T(o, e, s = "vertical") {
  const a = o.infos;
  let t = a.find(({ type: n }) => n === "size-ramp"), i = a.find(({ type: n }) => n === "color-ramp");
  return t && (t = { ...t }, t.infos = [...t.infos], y(t, e, null, s, !1)), i && (i = { ...i }, i.infos = [...i.infos]), s === "horizontal" && (t?.infos.reverse(), i?.infos.reverse()), { sizeRampElement: t, colorRampElement: i };
}
const W = { marginLeft: "3px" }, j = {
  display: "table-cell",
  verticalAlign: "middle"
}, q = {
  display: "flex",
  alignItems: "flex-start"
};
export {
  H as a,
  D as b,
  k as c,
  W as d,
  j as e,
  F as f,
  T as g,
  U as h,
  q as u
};
