import { c as E } from "../../chunks/runtime.js";
import { css as k, html as s } from "lit";
import b from "@arcgis/core/Color.js";
import { LitElement as L, safeClassMap as l, safeStyleMap as u, nothing as _ } from "@arcgis/lumina";
import { classes as n } from "@arcgis/toolkit/dom";
import { H as w } from "../../chunks/heading.js";
import { g as $ } from "../../chunks/globalCss.js";
import { b as C, s as f, i as z, a as v, g as x } from "../../chunks/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 F = k`.esri-widget__heading{color:var(--calcite-color-text-2);margin:0 0 .5rem;font-weight:var(--calcite-font-weight-semibold)}h1.esri-widget__heading{font-size:var(--calcite-font-size-xl)}h2.esri-widget__heading{font-size:var(--calcite-font-size-md)}h3.esri-widget__heading,h4.esri-widget__heading,h5.esri-widget__heading,h6.esri-widget__heading{font-size:var(--calcite-font-size)}.arcgis-legend--card__section{word-break:break-word;word-wrap:break-word;padding:var(--calcite-spacing-sm) var(--calcite-spacing-md);min-width:250px;max-width:500px;height:100%;height:-moz-available;height:-webkit-fill-available;height:fill-available;overflow:auto;font-size:var(--calcite-font-size-sm)}.arcgis-legend--card__carousel-title-container{margin-bottom:var(--calcite-spacing-sm)}.arcgis-legend--card__carousel-title{margin:0}.arcgis-legend--card__section-title{font-weight:var(--calcite-font-weight-normal)}.arcgis-legend--card__layer-caption{padding:var(--calcite-spacing-xs) 0;margin:0;font-weight:var(--calcite-font-weight-normal)}.arcgis-legend--card__imagery-layer-image--stretched{display:block;margin-bottom:-2px}.arcgis-legend--card__image-label{padding-right:var(--calcite-spacing-xs);padding-left:var(--calcite-spacing-xs)}.arcgis-legend--card__label-element{margin:.1em;padding:.5em 1em;min-width:2em;min-height:1em;text-align:center;display:flex;align-items:center;justify-content:center;flex:1}.arcgis-legend--card__layer-row{display:flex;align-items:center}.arcgis-legend--card__symbol{display:block;margin:auto}.arcgis-legend--card__pie-chart-ramp-preview{display:flex;justify-content:center}.arcgis-legend--card__relationship-container{display:flex;flex-direction:column}.arcgis-legend--card__relationship-container .arcgis-legend--card__layer-row{padding-bottom:.5em}.arcgis-legend--card__relationship-container .arcgis-legend--card__layer-row:last-child{padding-bottom:0}.arcgis-legend--card__container{display:flex;gap:var(--calcite-spacing-sm);flex-wrap:wrap}.arcgis-legend--card__background-styles-container{display:flex;flex-wrap:wrap}:host([stacked]) .arcgis-legend--card__container{display:table}:host([stacked]) .arcgis-legend--card__symbol-row{display:table-row;width:100%}:host([stacked]) .arcgis-legend--card__label-cell{display:table-cell;vertical-align:middle;padding:var(--calcite-spacing-xxs)}:host([stacked]) .arcgis-legend--card__symbol-cell{display:table-cell;vertical-align:middle;text-align:center;padding:var(--calcite-spacing-xxs)}:host([stacked]) .arcgis-legend--card__symbol-cell div{display:flex;align-items:center;justify-content:center}`, a = {
  carouselTitleContainer: "arcgis-legend--card__carousel-title-container",
  carouselTitle: "arcgis-legend--card__carousel-title",
  sectionTitle: "arcgis-legend--card__section-title",
  imageryLayerStretchedImage: "arcgis-legend--card__imagery-layer-image--stretched",
  imageLabel: "arcgis-legend--card__image-label",
  layerCaption: "arcgis-legend--card__layer-caption",
  labelElement: "arcgis-legend--card__label-element",
  layerRow: "arcgis-legend--card__layer-row",
  labelCell: "arcgis-legend--card__label-cell",
  section: "arcgis-legend--card__section",
  symbol: "arcgis-legend--card__symbol",
  symbolRow: "arcgis-legend--card__symbol-row",
  symbolCell: "arcgis-legend--card__symbol-cell",
  pieChartRampPreview: "arcgis-legend--card__pie-chart-ramp-preview",
  relationshipContainer: "arcgis-legend--card__relationship-container",
  backgroundStylesContainer: "arcgis-legend--card__background-styles-container",
  container: "arcgis-legend--card__container"
};
function S(p) {
  return p ? p.r * 0.299 + p.g * 0.587 + p.b * 0.114 >= 127 : void 0;
}
class R extends L {
  constructor() {
    super(...arguments), this.stacked = !1, this.headingLevel = 3;
  }
  static {
    this.properties = { cssEffectFilter: 1, stacked: 7, activeLayerInfo: 0, headingLevel: 9, layer: 0, legendElement: 0, messages: 0 };
  }
  static {
    this.styles = F;
  }
  _getBackgroundStyles(e) {
    const t = e.symbol, i = t.color, d = !!i?.a, c = "outline" in t ? t.outline : null, r = !!c?.color?.a, o = d && i ? new b([i.r, i.g, i.b, i.a * this.layer.opacity]) : new b([255, 255, 255, 0]), g = r && c.color ? new b([c.color.r, c.color.g, c.color.b, c.color.a * this.layer.opacity]) : new b([255, 255, 255, 0]), h = S(e.symbol.color) ?? !0, m = h ? "black" : "white", y = h ? "rgba(255, 255, 255, .6)" : "rgba(0, 0, 0, .6)";
    return {
      background: d ? o.toCss(!0) : "none",
      color: m,
      textShadow: `-1px -1px 0 ${y},
                  1px -1px 0 ${y},
                  -1px 1px 0 ${y},
                  1px 1px 0 ${y}`,
      border: r ? `1px solid ${g.toCss(!0)}` : "none",
      filter: this.cssEffectFilter ?? ""
    };
  }
  render() {
    const e = this._renderLegendElement(), t = C(this.legendElement, this.messages), i = this.stacked ? s`<div class=${l(a.carouselTitleContainer)}>${w({ class: n(a.carouselTitle, $.heading), level: this.headingLevel, children: this.activeLayerInfo.title })}${t ? s`<p class=${l(a.layerCaption)}>${t}</p>` : null}</div>` : t ? w({ class: n(a.sectionTitle, $.heading), level: this.headingLevel, children: t }) : null;
    return s`<section class=${l(a.section)} role=tabpanel tabindex=0>${i}${e}</section>`;
  }
  _renderLegendElement() {
    switch (this.legendElement.type) {
      case "symbol-table":
        return this._renderSymbolTable(this.legendElement);
      case "size-ramp":
        return s`<arcgis-legend-card-size-ramp .hasIndicators=${this.stacked} .legendElement=${this.legendElement} .messages=${this.messages} .opacity=${this.layer.opacity}></arcgis-legend-card-size-ramp>`;
      case "color-ramp":
      case "opacity-ramp":
      case "heatmap-ramp":
      case "stretch-ramp":
        return s`<arcgis-legend-card-color-ramp .cssEffectFilter=${this.cssEffectFilter} .legendElement=${this.legendElement} .messages=${this.messages} .opacity=${this.layer.opacity}></arcgis-legend-card-color-ramp>`;
      case "relationship-ramp":
        return s`<arcgis-legend-relationship-ramp .cssEffectFilter=${this.cssEffectFilter} .legendElement=${this.legendElement} .opacity=${this.layer.opacity} .messages=${this.messages}></arcgis-legend-relationship-ramp>`;
      case "pie-chart-ramp": {
        const { preview: e } = this.legendElement;
        return f(e, this.messages.previewPieChartAriaLabel), s`<div class=${l(a.pieChartRampPreview)}>${e}</div>`;
      }
      case "univariate-above-and-below-ramp":
        return s`<arcgis-legend-card-univariate-above-and-below-ramp .cssEffectFilter=${this.cssEffectFilter} .legendElement=${this.legendElement} .messages=${this.messages} .opacity=${this.layer.opacity}></arcgis-legend-card-univariate-above-and-below-ramp>`;
      case "univariate-color-size-ramp":
        return s`<arcgis-legend-card-univariate-color-size-ramp .cssEffectFilter=${this.cssEffectFilter} .legendElement=${this.legendElement} .messages=${this.messages} .opacity=${this.layer.opacity}></arcgis-legend-card-univariate-color-size-ramp>`;
      default:
        return null;
    }
  }
  _renderSymbolTable(e) {
    const t = e.infos.map((r) => this._renderElementInfo(r, e.legendType)).filter(Boolean);
    if (!t.length)
      return null;
    const i = e.infos.some((r) => "symbol" in r && r.symbol?.type.includes("simple-fill")), c = this.activeLayerInfo.legendElements.some(({ type: r }) => r === "relationship-ramp") ? a.relationshipContainer : i ? a.backgroundStylesContainer : a.container;
    return s`<div class=${l(c)}>${t}</div>`;
  }
  _renderElementInfo(e, t) {
    const { layer: i } = this, d = "label" in e ? e.label : null;
    if ("type" in e && e.type)
      return s`<arcgis-legend-card-element .activeLayerInfo=${this.activeLayerInfo} .cssEffectFilter=${this.cssEffectFilter} .stacked=${this.stacked} .headingLevel=${this.headingLevel} .layer=${i} .legendElement=${e} .messages=${this.messages}></arcgis-legend-card-element>`;
    if (!("preview" in e && e.preview) && !("src" in e && e.src))
      return null;
    const c = z(i, t), r = v(this.messages, d, !1) || "";
    if ("src" in e && e.src) {
      const o = {
        [a.symbolCell]: this.stacked
      };
      return s`<div class=${l(n(a.layerRow, { [a.symbolRow]: this.stacked }))}><div class=${l(n(o))}>${this._renderImage(e, i, c)}</div><div class=${l(n(a.imageLabel, { [a.labelCell]: this.stacked }))}>${r}</div></div>`;
    }
    if ("symbol" in e && e.preview) {
      if (!e.symbol?.type.includes("simple-fill")) {
        if (!e.label)
          return s`<div>${e.preview}</div>`;
        const o = {
          [a.symbolCell]: this.stacked
        }, { preview: g } = e, h = "previewAriaLabel" in e ? e.previewAriaLabel : null, m = "label" in e ? v(this.messages, e.label, !1) : null;
        return f(g, x(this.messages, h || m)), s`<div class=${l(n(a.layerRow, { [a.symbolRow]: this.stacked }))}><div class=${l(n(o))}>${g}</div><div class=${l(n(a.imageLabel, { [a.labelCell]: this.stacked }))}>${r}</div></div>`;
      }
      return s`<div class=${l(a.layerRow)}><div class=${l(a.labelElement)} style=${u(this._getBackgroundStyles(e))}>${r}</div></div>`;
    }
    return null;
  }
  _renderImage(e, t, i) {
    const { previewAriaLabel: d, src: c, opacity: r } = e, o = v(this.messages, e.label, !1), g = {
      [a.imageryLayerStretchedImage]: i,
      [a.symbol]: !i
    }, h = {
      opacity: `${r ?? t.opacity}`
    }, m = x(this.messages, d || o);
    return s`<img alt=${m ?? _} .ariaLabel=${m} class=${l(n(g))} height=${e.height ?? void 0 ?? _} src=${c ?? _} style=${u(h)} width=${e.width ?? void 0 ?? _}>`;
  }
}
E("arcgis-legend-card-element", R);
export {
  R as ArcgisLegendCardElement
};
