import { c as cc, f, S as S$1, g as go, X as Xc, l as le, b as ve, v as vo, M as Ma, Z as Ze, j as jc, W as Wa, a as Oa } from "./indexhtml-CLy7FRUS.js";
import { a } from "./state-BH_9RcTJ-CvW2iyyW.js";
import { V } from "./base-panel-Cxtbncvf-BogkDcI4.js";
import { r } from "./icons-mWh87_oB-DYgYHgmE.js";
import "./commonjsHelpers-CUmg6egw.js";
const n = (a2) => f.userInfo?.copilotExperimentalFeatureFlag === true && ve.isExperimentalFeatureEnabled(a2), F = {
  id: "theme-from-image",
  name: "Theme from Image",
  description: "Generate a custom theme based on an image you provide.",
  enabled: () => n(F),
  available: () => f.appTheme === "lumo",
  requiresReload: false
}, R = {
  id: "ai-docs-assistant",
  name: "AI Docs Assistant",
  description: "AI-powered Vaadin documentation assistant.",
  enabled: () => n(R),
  available: () => true,
  requiresReload: false
}, $ = {
  id: "testbench-test-recorder",
  name: "TestBench Test Recorder",
  description: "Record user interactions to generate end-to-end Vaadin TestBench tests automatically.",
  enabled: () => n($),
  available: () => true,
  requiresReload: true
}, E = {
  id: "i18n",
  name: "Internationalization",
  description: "Edit and manage translations for your application.",
  enabled: () => n(E),
  available: () => true,
  requiresReload: true
}, M = [
  F,
  R,
  $,
  E
];
var S = Object.defineProperty, D = Object.getOwnPropertyDescriptor, d = (a2, e, t, r2) => {
  for (var s = r2 > 1 ? void 0 : r2 ? D(e, t) : e, c = a2.length - 1, p; c >= 0; c--)
    (p = a2[c]) && (s = (r2 ? p(e, t, s) : p(s)) || s);
  return r2 && s && S(e, t, s), s;
};
const g = window.Vaadin.devTools;
let m = class extends V {
  constructor() {
    super(...arguments), this.toggledFeaturesThatAreRequiresServerRestart = [];
  }
  connectedCallback() {
    super.connectedCallback(), this.classList.add("contents");
  }
  render() {
    const a2 = f.userInfo?.copilotExperimentalFeatureFlag;
    return le`
      <div class="flex flex-col gap-6 px-4 py-0.5">
        <div class="border-dashed flex flex-col divide-y">
          ${f.featureFlags.slice().sort((e, t) => e.title.localeCompare(t.title)).map(
      (e) => le`
                <div class="flex gap-2 justify-between py-3.5">
                  <div class="flex flex-col">
                    <label id="${e.id}-label">${e.title}</label>
                    <a
                      class="flex gap-0.5 text-xs"
                      href="${e.moreInfoLink}"
                      id="${e.id}-desc"
                      target="_blank"
                      rel="noopener noreferrer"
                      >More info<vaadin-icon class="icon-sm" .svg="${r.arrowOutward}"></vaadin-icon
                    ></a>
                  </div>
                  <copilot-toggle-button
                    .ariaLabelledby="${e.id}-label"
                    .ariaDescribedby="${e.id}-desc"
                    ?checked=${e.enabled}
                    @on-change=${(t) => this.toggleFeatureFlag(t, e)}>
                  </copilot-toggle-button>
                </div>
              `
    )}
        </div>
        <div class="flex flex-col gap-1">
          ${a2 ? le`<h3 class="font-semibold my-0 text-sm">Copilot Experimental Features</h3>
                <div class="border-dashed flex flex-col divide-y">
                  ${M.filter((e) => e.available()).slice().sort((e, t) => e.name.localeCompare(t.name)).map(
      (e) => le`
                        <div class="flex gap-2 justify-between py-3.5">
                          <div class="flex flex-col">
                            <label id="${e.id}-label">${e.description}</label>
                          </div>
                          <copilot-toggle-button
                            .ariaLabelledby="${e.id}-label"
                            ?checked=${ve.isExperimentalFeatureEnabled(e)}
                            @on-change=${(t) => this.toggleExperimentalFeatureFlag(t, e)}>
                          </copilot-toggle-button>
                        </div>
                      `
    )}
                </div>` : S$1}
        </div>
      </div>
    `;
  }
  toggleFeatureFlag(a2, e) {
    const t = a2.target.checked;
    vo("use-feature", { source: "toggle", enabled: t, id: e.id }), g.frontendConnection ? (g.frontendConnection.send("setFeature", { featureId: e.id, enabled: t }), e.requiresServerRestart && f.toggleServerRequiringFeatureFlag(e), Ma({
      type: Ze.INFORMATION,
      message: `“${e.title}” ${t ? "enabled" : "disabled"}`,
      details: e.requiresServerRestart ? jc() : void 0,
      dismissId: `feature${e.id}${t ? "Enabled" : "Disabled"}`
    }), Wa()) : g.log("error", `Unable to toggle feature ${e.title}: No server connection available`);
  }
  toggleExperimentalFeatureFlag(a2, e) {
    const t = a2.target.checked;
    vo("use-experimental-feature", { source: "toggle", enabled: t, id: e.id });
    const r2 = ve.isExperimentalFeatureEnabled(e);
    ve.setExperimentalFeatureEnabled(e, t), e.requiresReload && t && !r2 && window.location.reload();
  }
};
d([
  a()
], m.prototype, "toggledFeaturesThatAreRequiresServerRestart", 2);
m = d([
  Oa("copilot-features-panel")
], m);
let b = class extends cc {
  constructor() {
    super(...arguments), this.serverRestarting = false;
  }
  createRenderRoot() {
    return this;
  }
  render() {
    if (f.serverRestartRequiringToggledFeatureFlags.length === 0)
      return S$1;
    if (!go())
      return S$1;
    const a2 = this.serverRestarting ? "Restarting..." : "Click to restart server";
    return le`
      <button
        ?disabled="${this.serverRestarting}"
        id="restart-server-btn"
        class="icon ${this.serverRestarting ? "" : "fade-in-out"}"
        @click=${() => {
      this.serverRestarting = true, Xc();
    }}>
        <span>${r.refresh}</span>
      </button>
      <vaadin-tooltip for="restart-server-btn" text=${a2}></vaadin-tooltip>
    `;
  }
};
d([
  a()
], b.prototype, "serverRestarting", 2);
b = d([
  Oa("copilot-features-actions")
], b);
const P = {
  header: "Features",
  tag: "copilot-features-panel",
  helpUrl: "https://vaadin.com/docs/latest/flow/configuration/feature-flags",
  actionsTag: "copilot-features-actions",
  toolbarOptions: {
    allowedModesWithOrder: {
      common: 0
    },
    iconKey: "listAlt"
  }
}, _ = {
  init(a2) {
    a2.addPanel(P);
  }
};
window.Vaadin.copilot.plugins.push(_);
export {
  b as CopilotFeaturesActions,
  m as CopilotFeaturesPanel
};
