import { r } from "./icons-mWh87_oB-BtdirGvB.js";
import { r as rd, s as ft, O as Oe, p as Sr, f, U as Ua, y, l as le, A as Ad, D as Dd, S, u as eu, k as br, w as qe, o as ot, N as Nd, T as Td, a as Oa } from "./indexhtml-Kdz6Ae66.js";
import { a } from "./state-BH_9RcTJ-BDdTIKhq.js";
import { V as V$1 } from "./base-panel-Cxtbncvf-7hwIhbHy.js";
import "./commonjsHelpers-CUmg6egw.js";
var V = Object.defineProperty, O = Object.getOwnPropertyDescriptor, h = (e, t, a2, i) => {
  for (var o = i > 1 ? void 0 : i ? O(t, a2) : t, l = e.length - 1, d; l >= 0; l--)
    (d = e[l]) && (o = (i ? d(t, a2, o) : d(o)) || o);
  return i && o && V(t, a2, o), o;
};
const C = "https://github.com/JetBrains/JetBrainsRuntime/releases";
function U(e, t) {
  if (!t)
    return true;
  const [a2, i, o] = t.split(".").map((m) => parseInt(m)), [l, d, v] = e.split(".").map((m) => parseInt(m));
  if (a2 < l)
    return true;
  if (a2 === l) {
    if (i < d)
      return true;
    if (i === d)
      return o < v;
  }
  return false;
}
const $ = "Download complete";
let u = class extends V$1 {
  constructor() {
    super(), this.javaPluginSectionOpened = false, this.hotswapSectionOpened = false, this.hotswapTab = "hotswapagent", this.downloadStatusMessages = [], this.downloadProgress = 0, this.onDownloadStatusUpdate = this.downloadStatusUpdate.bind(this), this.handleESC = (e) => {
      ft().appInteractable || e.key === "Escape" && Oe.openPanel(w.tag);
    }, this.reaction(
      () => [Sr.jdkInfo, f.idePluginState],
      () => {
        f.idePluginState && (!f.idePluginState.ide || !f.idePluginState.active ? this.javaPluginSectionOpened = true : (!(/* @__PURE__ */ new Set(["vscode", "intellij"])).has(f.idePluginState.ide) || !f.idePluginState.active) && (this.javaPluginSectionOpened = false)), Sr.jdkInfo && Ua() !== "success" && (this.hotswapSectionOpened = true);
      },
      { fireImmediately: true }
    );
  }
  createRenderRoot() {
    return this;
  }
  connectedCallback() {
    super.connectedCallback(), y.on("set-up-vs-code-hotswap-status", this.onDownloadStatusUpdate);
  }
  disconnectedCallback() {
    super.disconnectedCallback(), y.off("set-up-vs-code-hotswap-status", this.onDownloadStatusUpdate);
  }
  render() {
    const e = {
      intellij: f.idePluginState?.ide === "intellij",
      vscode: f.idePluginState?.ide === "vscode",
      eclipse: f.idePluginState?.ide === "eclipse",
      idePluginInstalled: !!f.idePluginState?.active
    };
    return le`
      <div part="container">${this.renderPluginSection(e)} ${this.renderHotswapSection(e)}</div>
      <div part="footer">
        <vaadin-button
          id="close"
          @click="${() => Oe.closePanel(w.tag)}"
          >Close
        </vaadin-button>
      </div>
    `;
  }
  renderPluginSection(e) {
    let t = "";
    e.intellij ? t = "IntelliJ" : e.vscode ? t = "VS Code" : e.eclipse && (t = "Eclipse");
    let a2, i;
    e.vscode || e.intellij ? e.idePluginInstalled ? (a2 = `Plugin for ${t} installed`, i = this.renderPluginInstalledContent()) : (a2 = `Plugin for ${t} not installed`, i = this.renderPluginIsNotInstalledContent(e)) : e.eclipse ? (a2 = e.idePluginInstalled ? "Eclipse plugin installed" : "Eclipse plugin not installed", i = e.idePluginInstalled ? this.renderPluginInstalledContent() : this.renderEclipsePluginContent()) : (a2 = "No IDE found", i = this.renderNoIdePluginContent());
    const o = e.idePluginInstalled ? r.checkCircle : r.alertTriangle;
    return le`
      <details
        part="panel"
        .open=${this.javaPluginSectionOpened}
        @toggle=${(l) => {
      Ad(() => {
        this.javaPluginSectionOpened = l.target.open;
      }), this.requestLayoutUpdate();
    }}>
        <summary part="header">
          <span class="icon ${e.idePluginInstalled ? "success" : "warning"}">${o}</span>
          <div>${a2}</div>
        </summary>
        <div part="content">${i}</div>
      </details>
    `;
  }
  renderNoIdePluginContent() {
    return le`
      <div>
        <div>We could not detect an IDE</div>
        ${this.recommendSupportedPlugin()}
      </div>
    `;
  }
  renderEclipsePluginContent() {
    return le`
      <div>
        <div>Install the Vaadin Eclipse Plugin to ensure a smooth development workflow</div>
        <p>
          Installing the plugin is not required, but strongly recommended.<br />Some Vaadin Copilot functionality, such
          as undo, will not function optimally without the plugin.
        </p>
        <div>
          <vaadin-button
            @click="${() => {
      window.open(Dd, "_blank");
    }}"
            >Install from Eclipse Marketplace
            <vaadin-icon slot="suffix" icon="vaadin:external-link"></vaadin-icon>
          </vaadin-button>
        </div>
      </div>
    `;
  }
  recommendSupportedPlugin() {
    return le`<div>
      Please use <a href="https://code.visualstudio.com">Visual Studio Code</a> or
      <a href="https://www.jetbrains.com/idea">IntelliJ IDEA</a> for better development experience
    </div>`;
  }
  renderPluginInstalledContent() {
    return le` <div>You have a running plugin. Enjoy your awesome development workflow!</div> `;
  }
  renderPluginIsNotInstalledContent(e) {
    let t = null, a2 = "Install from Marketplace";
    return e.intellij ? (t = Nd, a2 = "Install from JetBrains Marketplace") : e.vscode ? (t = Td, a2 = "Install from VSCode Marketplace") : e.eclipse && (t = Dd, a2 = "Install from Eclipse Marketplace"), le`
      <div>
        <div>Install the Vaadin IDE Plugin to ensure a smooth development workflow</div>
        <p>
          Installing the plugin is not required, but strongly recommended.<br />Some Vaadin Copilot functionality, such
          as undo, will not function optimally without the plugin.
        </p>
        ${t ? le` <div>
              <vaadin-button
                @click="${() => {
      window.open(t, "_blank");
    }}"
                >${a2}
                <vaadin-icon slot="suffix" icon="vaadin:external-link"></vaadin-icon>
              </vaadin-button>
            </div>` : S}
      </div>
    `;
  }
  renderHotswapSection(e) {
    const { jdkInfo: t } = Sr;
    if (!t)
      return S;
    const a2 = Ua(), i = eu();
    let o, l, d;
    return a2 === "success" ? (o = r.checkCircle, d = "Java Hotswap is enabled") : a2 === "warning" ? (o = r.alertTriangle, d = "Java Hotswap is not enabled") : a2 === "error" && (o = r.alertTriangle, d = "Java Hotswap is partially enabled"), this.hotswapTab === "jrebel" ? t.jrebel ? l = this.renderJRebelInstalledContent() : l = this.renderJRebelNotInstalledContent() : e.intellij ? l = this.renderHotswapAgentPluginContent(this.renderIntelliJHotswapHint) : e.vscode ? l = this.renderHotswapAgentPluginContent(this.renderVSCodeHotswapHint) : l = this.renderHotswapAgentNotInstalledContent(e), le` <details
      part="panel"
      .open=${this.hotswapSectionOpened}
      @toggle=${(v) => {
      Ad(() => {
        this.hotswapSectionOpened = v.target.open;
      }), this.requestLayoutUpdate();
    }}>
      <summary part="header">
        <span class="icon ${a2}">${o}</span>
        <div>${d}</div>
      </summary>
      <div part="content">
        ${i !== "none" ? le`${i === "jrebel" ? this.renderJRebelInstalledContent() : this.renderHotswapAgentInstalledContent()}` : le`
            <div class="tabs" role="tablist">
              <button
                aria-selected="${this.hotswapTab === "hotswapagent" ? "true" : "false"}"
                class="tab"
                role="tab"
                @click=${() => {
      this.hotswapTab = "hotswapagent";
    }}>
                Hotswap Agent
              </button>
              <button
                aria-selected="${this.hotswapTab === "jrebel" ? "true" : "false"}"
                class="tab"
                role="tab"
                @click=${() => {
      this.hotswapTab = "jrebel";
    }}>
                JRebel
              </button>
            </div>
            <div part="content">${l}</div>
            </div>
            </details>
          `}
      </div>
    </details>`;
  }
  renderJRebelNotInstalledContent() {
    return le`
      <div>
        <a href="https://www.jrebel.com">JRebel ${r.arrowOutward}</a> is a commercial hotswap solution. Vaadin
        detects the JRebel Agent and automatically reloads the application in the browser after the Java changes have
        been hotpatched.
        <p>
          Go to
          <a href="https://www.jrebel.com/products/jrebel/learn" target="_blank" rel="noopener noreferrer">
            https://www.jrebel.com/products/jrebel/learn ${r.arrowOutward}</a
          >
          to get started
        </p>
      </div>
    `;
  }
  renderHotswapAgentNotInstalledContent(e) {
    const t = [
      this.renderJavaRunningInDebugModeSection(),
      this.renderHotswapAgentJdkSection(e),
      this.renderInstallHotswapAgentJdkSection(e),
      this.renderHotswapAgentVersionSection(),
      this.renderHotswapAgentMissingArgParam(e)
    ];
    return le` <div part="hotswap-agent-section-container">${t}</div> `;
  }
  renderHotswapAgentPluginContent(e) {
    const a2 = Ua() === "success";
    return le`
      <div part="hotswap-agent-section-container">
        <div class="inner-section">
          <span class="hotswap icon ${a2 ? "success" : "warning"}"
            >${a2 ? r.checkCircle : r.alertTriangle}</span
          >
          ${e()}
        </div>
      </div>
    `;
  }
  renderIntelliJHotswapHint() {
    return le` <div class="hint">
      <h3>Use 'Debug using Hotswap Agent' launch configuration</h3>
      Vaadin IntelliJ plugin offers launch mode that does not require any manual configuration!
      <p>
        In order to run recommended launch configuration, you should click three dots right next to Debug button and
        select <code>Debug using Hotswap Agent</code> option.
      </p>
    </div>`;
  }
  renderVSCodeHotswapHint() {
    return le` <div class="hint">
      <h3>Use 'Debug (hotswap)'</h3>
      With Vaadin Visual Studio Code extension you can run Hotswap Agent without any manual configuration required!
      <p>Click <code>Debug (hotswap)</code> within your main class to debug application using Hotswap Agent.</p>
    </div>`;
  }
  renderJavaRunningInDebugModeSection() {
    const e = Sr.jdkInfo?.runningInJavaDebugMode;
    return le`
      <div class="inner-section">
        <details class="inner" .open="${!e}">
          <summary>
            <span class="icon ${e ? "success" : "warning"}"
              >${e ? r.checkCircle : r.alertTriangle}</span
            >
            <div>Run Java in debug mode</div>
          </summary>
          <div class="hint">Start the application in debug mode in the IDE</div>
        </details>
      </div>
    `;
  }
  renderHotswapAgentMissingArgParam(e) {
    const t = Sr.jdkInfo?.runningWitHotswap && Sr.jdkInfo?.runningWithExtendClassDef;
    return le`
      <div class="inner-section">
        <details class="inner" .open="${!t}">
          <summary>
            <span class="icon ${t ? "success" : "warning"}"
              >${t ? r.checkCircle : r.alertTriangle}</span
            >
            <div>Enable HotswapAgent</div>
          </summary>
          <div class="hint">
            <ul>
              ${e.intellij ? le`<li>Launch as mentioned in the previous step</li>` : S}
              ${e.intellij ? le`<li>
                    To manually configure IntelliJ, add the
                    <code>-XX:HotswapAgent=fatjar -XX:+AllowEnhancedClassRedefinition -XX:+UpdateClasses</code> JVM
                    arguments when launching the application
                  </li>` : le`<li>
                    Add the
                    <code>-XX:HotswapAgent=fatjar -XX:+AllowEnhancedClassRedefinition -XX:+UpdateClasses</code> JVM
                    arguments when launching the application
                  </li>`}
            </ul>
          </div>
        </details>
      </div>
    `;
  }
  renderHotswapAgentJdkSection(e) {
    const t = Sr.jdkInfo?.extendedClassDefCapable, a2 = this.downloadStatusMessages?.[this.downloadStatusMessages.length - 1] === $;
    return le`
      <div class="inner-section">
        <details class="inner" .open="${!t}">
          <summary>
            <span class="icon ${t ? "success" : "warning"}"
              >${t ? r.checkCircle : r.alertTriangle}</span
            >
            <div>Run using JetBrains Runtime JDK</div>
          </summary>
          <div class="hint">
            JetBrains Runtime provides much better hotswapping compared to other JDKs.
            <ul>
              ${e.intellij && U("1.3.0", f.idePluginState?.version) ? le` <li>Upgrade to the latest IntelliJ plugin</li>` : S}
              ${e.intellij ? le` <li>Launch the application in IntelliJ using "Debug using Hotswap Agent"</li>` : S}
              ${e.vscode ? le` <li>
                    <a href @click="${(i) => this.downloadJetbrainsRuntime(i)}"
                      >Let Copilot download and set up JetBrains Runtime for VS Code</a
                    >
                    ${this.downloadProgress > 0 ? le`<vaadin-progress-bar
                          .value="${this.downloadProgress}"
                          min="0"
                          max="1"></vaadin-progress-bar>` : S}
                    <ul>
                      ${this.downloadStatusMessages.map((i) => le`<li>${i}</li>`)}
                      ${a2 ? le`<h3>Go to VS Code and launch the 'Debug using Hotswap Agent' configuration</h3>` : S}
                    </ul>
                  </li>` : S}
              <li>
                ${e.intellij || e.vscode ? le`If there is a problem, you can manually
                      <a target="_blank" href="${C}">download JetBrains Runtime JDK</a> and set up
                      your debug configuration to use it.` : le`<a target="_blank" href="${C}">Download JetBrains Runtime JDK</a> and set up
                      your debug configuration to use it.`}
              </li>
            </ul>
          </div>
        </details>
      </div>
    `;
  }
  renderInstallHotswapAgentJdkSection(e) {
    const t = Sr.jdkInfo?.hotswapAgentFound, a2 = Sr.jdkInfo?.extendedClassDefCapable;
    return le`
      <div class="inner-section">
        <details class="inner" .open="${!t}">
          <summary>
            <span class="icon ${t ? "success" : "warning"}"
              >${t ? r.checkCircle : r.alertTriangle}</span
            >
            <div>Install HotswapAgent</div>
          </summary>
          <div class="hint">
            Hotswap Agent provides application level support for hot reloading, such as reinitalizing Vaadin @Route or
            @BrowserCallable classes when they are updated
            <ul>
              ${e.intellij ? le`<li>Launch as mentioned in the previous step</li>` : S}
              ${!e.intellij && !a2 ? le`<li>First install JetBrains Runtime as mentioned in the step above.</li>` : S}
              ${e.intellij ? le`<li>
                    To manually configure IntelliJ, download HotswapAgent and install the jar file as
                    <code>[JAVA_HOME]/lib/hotswap/hotswap-agent.jar</code> in the JetBrains Runtime JDK. Note that the
                    file must be renamed to exactly match this path.
                  </li>` : le`<li>
                    Download HotswapAgent and install the jar file as
                    <code>[JAVA_HOME]/lib/hotswap/hotswap-agent.jar</code> in the JetBrains Runtime JDK. Note that the
                    file must be renamed to exactly match this path.
                  </li>`}
            </ul>
          </div>
        </details>
      </div>
    `;
  }
  renderHotswapAgentVersionSection() {
    if (!Sr.jdkInfo?.hotswapAgentFound)
      return S;
    const e = Sr.jdkInfo?.hotswapVersionOk, t = Sr.jdkInfo?.hotswapVersion, a2 = Sr.jdkInfo?.hotswapAgentLocation;
    return le`
      <div class="inner-section">
        <details class="inner" .open="${!e}">
          <summary>
            <span class="icon ${e ? "success" : "warning"}"
              >${e ? r.checkCircle : r.alertTriangle}</span
            >
            <div>Hotswap version requires update</div>
          </summary>
          <div class="hint">
            HotswapAgent version ${t} is in use
            <a target="_blank" href="https://github.com/HotswapProjects/HotswapAgent/releases"
              >Download the latest HotswapAgent</a
            >
            and place it in <code>${a2}</code>
          </div>
        </details>
      </div>
    `;
  }
  renderJRebelInstalledContent() {
    return le` <div>JRebel is in use. Enjoy your awesome development workflow!</div> `;
  }
  renderHotswapAgentInstalledContent() {
    return le` <div>Hotswap agent is in use. Enjoy your awesome development workflow!</div> `;
  }
  async downloadJetbrainsRuntime(e) {
    return e.target.disabled = true, e.preventDefault(), this.downloadStatusMessages = [], br(`${ot}set-up-vs-code-hotswap`, {}, (t) => {
      t.data.error ? (qe("Error downloading JetBrains runtime", t.data.error), this.downloadStatusMessages = [...this.downloadStatusMessages, "Download failed"]) : this.downloadStatusMessages = [...this.downloadStatusMessages, $];
    });
  }
  downloadStatusUpdate(e) {
    const t = e.detail.progress;
    t ? this.downloadProgress = t : this.downloadStatusMessages = [...this.downloadStatusMessages, e.detail.message];
  }
};
u.NAME = "copilot-development-setup-user-guide";
h([
  a()
], u.prototype, "javaPluginSectionOpened", 2);
h([
  a()
], u.prototype, "hotswapSectionOpened", 2);
h([
  a()
], u.prototype, "hotswapTab", 2);
h([
  a()
], u.prototype, "downloadStatusMessages", 2);
h([
  a()
], u.prototype, "downloadProgress", 2);
u = h([
  Oa(u.NAME)
], u);
const w = {
  header: "Development Workflow",
  tag: rd,
  individual: true
}, _ = {
  init(e) {
    e.addPanel(w);
  }
};
window.Vaadin.copilot.plugins.push(_);
Oe.addPanel(w);
export {
  u as CopilotDevelopmentSetupUserGuide,
  w as copilotDevelopmentSetupPanelConfig
};
