import { c as h } from "../../chunks/runtime.js";
import { css as b, html as p } from "lit";
import { renderingSanitizer as c } from "@arcgis/core/applications/Components/sanitizerUtils.js";
import { LitElement as $, safeClassMap as f } from "@arcgis/lumina";
import { addLtrMark as v } from "@arcgis/toolkit/string";
import { h as _, k as I, l as w, m as F } from "../../chunks/feature-utils.js";
import { replace as g } from "@arcgis/core/applications/Components/stringUtils.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 N = [
  {
    pattern: /^\s*(https?:\/\/([^\s]+))\s*$/iu,
    target: "_blank",
    label: "{messages.view}"
  },
  {
    pattern: /^\s*(tel:([^\s]+))\s*$/iu,
    label: "{hierPart}"
  },
  {
    pattern: /^\s*(mailto:([^\s]+))\s*$/iu,
    label: "{hierPart}"
  },
  // ArcGIS Apps
  {
    pattern: /^\s*(arcgis-appstudio-player:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "App Studio Player"
  },
  {
    pattern: /^\s*(arcgis-collector:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Collector"
  },
  {
    pattern: /^\s*(arcgis-explorer:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Explorer"
  },
  {
    pattern: /^\s*(arcgis-navigator:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Navigator"
  },
  {
    pattern: /^\s*(arcgis-survey123:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Survey123"
  },
  {
    pattern: /^\s*(arcgis-trek2there:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Trek2There"
  },
  {
    pattern: /^\s*(arcgis-workforce:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Workforce"
  },
  // Third-Party Apps
  {
    pattern: /^\s*(iform:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "iForm"
  },
  {
    pattern: /^\s*(flow:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "FlowFinity"
  },
  {
    pattern: /^\s*(lfmobile:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Laserfische"
  },
  {
    pattern: /^\s*(mspbi:\/\/([^\s]+))\s*$/iu,
    label: "{messages.openInApp}",
    appName: "Microsoft Power Bi"
  }
];
function y(d, t) {
  const e = N.find((n) => n.pattern.test(t));
  if (!e)
    return t;
  const i = t.match(e.pattern)?.[2], s = g(
    g(e.label, {
      messages: d,
      hierPart: i
    }),
    {
      appName: e.appName
    }
  ), l = e.target ? ` target="${e.target}"` : "", r = e.target === "_blank" ? ' rel="noreferrer"' : "";
  return c.sanitizeUrl(new URL(t, window.location.origin).toString()).replace(e.pattern, `<a${l} href="$1"${r}>${s}</a>`);
}
const A = b`.arcgis-feature-fields__table{border:none;width:100%;border-collapse:collapse;color:var(--calcite-color-text-2)}.arcgis-feature-fields__table caption{clip:rect(0 0 0 0);clip-path:inset(50%);height:1px;overflow:hidden;position:absolute;white-space:nowrap;width:1px}.arcgis-feature-fields__table tr:nth-child(odd){background-color:var(--calcite-color-foreground-1)}.arcgis-feature-fields__table tr:nth-child(2n){background-color:var(--calcite-color-foreground-2)}.arcgis-feature-fields__table tr a{color:var(--calcite-color-text-link)}.arcgis-feature-fields__table tr a:hover,.arcgis-feature-fields__table tr a:focus{color:var(--calcite-color-brand-hover)}.arcgis-feature-fields__table tr td,.arcgis-feature-fields__table tr th{padding:var(--calcite-spacing-xs) var(--calcite-spacing-sm);vertical-align:top;word-break:break-word;font-size:var(--calcite-font-size-sm);font-weight:var(--calcite-font-weight-regular);line-height:var(--calcite-font-line-height-relative-normal)}.arcgis-feature-fields__table tr th{border-inline-end:var(--calcite-border-width-md) solid var(--calcite-color-border-3);width:50%;text-align:start}.arcgis-feature-fields__table tr td{width:50%}`, m = "arcgis-feature-fields", u = {
  base: m,
  table: `${m}__table`
};
class k extends $ {
  constructor() {
    super(...arguments), this.headingLevel = 2;
  }
  static {
    this.properties = { values: 0, description: 1, expressionInfos: 0, fieldInfos: 0, heading: 1, isContentFieldInfos: 5, graphic: 0, layer: 0, headingLevel: 9, messages: 0 };
  }
  static {
    this.styles = A;
  }
  get formattedFieldInfos() {
    const { expressionInfos: t, fieldInfos: e, layer: a, graphic: i, isContentFieldInfos: s } = this, l = [];
    return e?.forEach((r) => {
      if (!("visible" in r ? r.visible : !0))
        return;
      const o = r.clone();
      o.label = _({ fieldInfo: o, expressionInfos: t, layer: a, graphic: i, isContentFieldInfos: s }), I(a) && w({ fieldInfo: r, graphic: i }) && (o.fieldFormat = F({
        fieldInfo: o,
        isContentFieldInfos: s,
        layer: a
      })), l.push(o);
    }), l;
  }
  render() {
    return p`<div class=${f(u.base)}><arcgis-feature-element-info .heading=${this.heading} .description=${this.description} .headingLevel=${this.headingLevel}></arcgis-feature-element-info>${this._renderFields()}</div>`;
  }
  _renderFieldInfo(t) {
    const { values: e } = this, a = t.fieldName || "", i = t.label || a, s = e ? e[a] == null ? "" : e[a] : "", l = t?.fieldFormat?.type === "date-time", r = {
      openInApp: this.messages?.openInApp ?? "",
      view: this.messages?.view ?? ""
    }, n = typeof s == "number" && !l ? v(`${s}`) : typeof s == "string" ? y(r, s) : `${s}`;
    return p`<tr><th .innerHTML=${c.sanitize(i) ?? ""}></th><td .innerHTML=${c.sanitize(n) ?? ""}></td></tr>`;
  }
  _renderFields() {
    const { formattedFieldInfos: t } = this;
    return t?.length ? p`<table class=${f(u.table)}><caption>${this.messages?.fieldsSummary}</caption><tbody>${t.map((e) => this._renderFieldInfo(e))}</tbody></table>` : null;
  }
}
h("arcgis-feature-fields", k);
export {
  k as ArcgisFeatureFields
};
