import { html as b } from "lit";
/*! 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.10 */
const m = [
  "popup",
  "popup-element",
  "visualization",
  "labeling",
  "aggregate-field",
  "popup-feature-reduction",
  "popup-voxel"
], w = (e) => {
  const s = m.includes(e);
  return s || console.warn(`Profile "${e}" is not supported by the Arcade Coding Assistant.`), s;
}, A = (e) => {
  const { aiAssistantsEnabled: s } = e;
  return s === void 0 ? (console.warn("areAiAssistantsEnabled is not defined in the organizations settings."), !1) : !!s;
}, v = () => typeof globalThis < "u" && "$arcgis" in globalThis && typeof globalThis.$arcgis == "object" && "import" in globalThis.$arcgis && !("forceESM" in globalThis.$arcgis), T = async (e) => v() ? (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 E({ portalUrl: e, profileId: s, feedbackServiceUrl: n, appVersion: o, panelName: r }) {
  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 T(e), c = `${e}/sharing/rest/portals/self?f=json&token=${i}`, l = `${e}/sharing/rest/portals/self/settings?f=json&token=${i}`, [a, d] = await Promise.all([
    fetch(c, { credentials: "include" }).then((t) => t.json()),
    fetch(l, { credentials: "include" }).then((t) => t.json())
  ]), g = a?.helperServices?.aiAssistantServices?.url, p = a.helpBase, u = A(d);
  return {
    enabled: w(s),
    id: "arcade-assistant",
    name: r,
    icon: "effects",
    useFlows: !0,
    location: "sidebar",
    renderer: ({ closePanel: t, insertText: f, closed: h, editorRef: $ }) => b`
      <arcgis-arcade-coding-assistant
        .portalUrl=${e}
        .serviceUrl=${g}
        .feedbackServiceUrl=${n}
        .closePanel=${t}
        .insertText=${f}
        .closed=${h}
        .editorRef=${$}
        .appVersion=${o}
        .helpBase=${p}
        ?assistants-enabled=${u}
      ></arcgis-arcade-coding-assistant>
    `
  };
}
export {
  E as useArcadeAssistant
};
