import { html as w } from "lit";
import { log as o } from "@arcgis/toolkit/log";
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
v5.0.0-next.112 */
const A = [
  "popup",
  "popup-element",
  "visualization",
  "labeling",
  "aggregate-field",
  "popup-feature-reduction",
  "popup-voxel"
], r = "Arcade Coding Assistant", v = (e) => {
  const s = A.includes(e);
  return s || o("warn", r, `Profile "${e}" is not supported.`), s;
}, T = (e) => {
  const { aiAssistantsEnabled: s } = e;
  return s === void 0 ? (o("warn", r, "`areAiAssistantsEnabled` is not defined in the organization's settings."), !1) : !!s;
}, k = () => typeof globalThis < "u" && "$arcgis" in globalThis && typeof globalThis.$arcgis == "object" && "import" in globalThis.$arcgis && !("forceESM" in globalThis.$arcgis), E = async (e) => k() ? (await (await globalThis.$arcgis.import("@arcgis/core/identity/IdentityManager.js")).getCredential(e))?.token || "" : (await (await import("@arcgis/core/identity/IdentityManager.js")).default.getCredential(e)).token || "";
async function y({ portalUrl: e, profileId: s, feedbackServiceUrl: n, appVersion: c, panelName: l }) {
  if (!customElements.get("arcgis-arcade-coding-assistant"))
    throw new Error("arcgis-arcade-coding-assistant component is not registered. Please ensure the component is imported from @arcgis/coding-components.");
  const i = await E(e), d = `${e}/sharing/rest/portals/self?f=json&token=${i}`, g = `${e}/sharing/rest/portals/self/settings?f=json&token=${i}`, [a, p] = await Promise.all([
    fetch(d, { credentials: "include" }).then((t) => t.json()),
    fetch(g, { credentials: "include" }).then((t) => t.json())
  ]), f = a?.helperServices?.aiAssistantServices?.url, u = a.helpBase, h = T(p);
  return {
    enabled: v(s),
    id: "arcade-assistant",
    name: l,
    icon: "effects",
    useFlows: !0,
    location: "sidebar",
    renderer: ({ closePanel: t, insertText: $, closed: m, editorRef: b }) => w`
      <arcgis-arcade-coding-assistant
        .portalUrl=${e}
        .serviceUrl=${f}
        .feedbackServiceUrl=${n}
        .closePanel=${t}
        .insertText=${$}
        .closed=${m}
        .editorRef=${b}
        .appVersion=${c}
        .helpBase=${u}
        ?assistants-enabled=${h}
      ></arcgis-arcade-coding-assistant>
    `
  };
}
export {
  y as useArcadeAssistant
};
