// @bun
import {
  ConfigurableShortcutHint,
  Select,
  fetchEnvironments,
  init_ConfigurableShortcutHint,
  init_environments,
  init_select
} from "./chunk-4vz571bb.js";
import"./chunk-14p6wvsq.js";
import"./chunk-8hseq8b1.js";
import"./chunk-ddtxq6k5.js";
import"./chunk-28jd8qjx.js";
import"./chunk-djt39ze3.js";
import"./chunk-ptxteaeh.js";
import"./chunk-wd53a7m4.js";
import"./chunk-hms8ge0k.js";
import"./chunk-whpphypt.js";
import"./chunk-pht800m5.js";
import"./chunk-pjkqh1kq.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-qn6me9n1.js";
import"./chunk-qd3r2s2n.js";
import"./chunk-djzd7tef.js";
import"./chunk-gyhnpbkx.js";
import"./chunk-71sdcaq6.js";
import"./chunk-60gf7p5s.js";
import"./chunk-sj3d0nqx.js";
import"./chunk-9pk9rk2w.js";
import"./chunk-javpza6a.js";
import"./chunk-6v7bre98.js";
import"./chunk-24kv69g3.js";
import"./chunk-fcqebw9m.js";
import"./chunk-dnfd3c9s.js";
import"./chunk-15ezj4ww.js";
import"./chunk-1h284c6e.js";
import"./chunk-582g9yce.js";
import {
  init_useKeybinding
} from "./chunk-y3ztgztb.js";
import"./chunk-4spgkgr3.js";
import"./chunk-n8kbhswc.js";
import"./chunk-60fkafk2.js";
import"./chunk-fgbkrbk3.js";
import"./chunk-ssw61jfd.js";
import"./chunk-093ej2sf.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-nde5ym6a.js";
import"./chunk-k8wq4qsj.js";
import"./chunk-g7d3xx1p.js";
import"./chunk-3wrx2943.js";
import"./chunk-7p9kkh0f.js";
import"./chunk-qp8cgz66.js";
import"./chunk-1mg610h2.js";
import"./chunk-93hc149s.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-nnat9jw5.js";
import"./chunk-hqxp6b72.js";
import"./chunk-4jzkqgf1.js";
import"./chunk-33rd41ng.js";
import"./chunk-f257kqw9.js";
import"./chunk-w5hnghah.js";
import"./chunk-36twraxy.js";
import"./chunk-1bkvnj0y.js";
import"./chunk-akdpcc5p.js";
import {
  SETTING_SOURCES,
  getSettingSourceName,
  getSettingsForSource,
  getSettings_DEPRECATED,
  init_constants,
  init_settings1 as init_settings,
  updateSettingsForSource
} from "./chunk-7rrkrej7.js";
import"./chunk-6r0bxrh6.js";
import"./chunk-d6500tvx.js";
import"./chunk-jg4bw4hp.js";
import"./chunk-epvbnq43.js";
import"./chunk-tn2sx7j6.js";
import"./chunk-6tzyv21c.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-ch4pgvwq.js";
import"./chunk-99jc4tcw.js";
import"./chunk-fghczfqt.js";
import"./chunk-vwenx8ke.js";
import"./chunk-f86mwfyd.js";
import"./chunk-v4ypszbb.js";
import"./chunk-bk6ck5c2.js";
import"./chunk-ym6j0wv1.js";
import"./chunk-hjmatcgt.js";
import"./chunk-6mdh70q0.js";
import"./chunk-ch92ycde.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-nt5dmk8q.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import"./chunk-0gp4q8aq.js";
import"./chunk-hn4w9pkj.js";
import {
  Byline,
  Dialog,
  KeyboardShortcutHint,
  LoadingState,
  ThemedText,
  init_source,
  init_src,
  require_react,
  source_default,
  useKeybinding
} from "./chunk-0r6npc3t.js";
import {
  require_jsx_runtime
} from "./chunk-gxyx8b8w.js";
import"./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-t0450ma3.js";
import"./chunk-0cqw3y8h.js";
import"./chunk-k1sw7km0.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-sc9ycxra.js";
import"./chunk-hhta0nge.js";
import {
  init_log,
  logError
} from "./chunk-8wsj9fff.js";
import"./chunk-m28vg9w4.js";
import"./chunk-f8prtxs3.js";
import"./chunk-41a6f2kv.js";
import"./chunk-c1yc761e.js";
import {
  figures_default,
  init_figures
} from "./chunk-c5g9shkw.js";
import {
  init_errors,
  toError
} from "./chunk-byd20vdq.js";
import"./chunk-kb3758f7.js";
import"./chunk-3j8w0rq8.js";
import"./chunk-tj0dzck2.js";
import"./chunk-aeysytks.js";
import"./chunk-ns1htxgd.js";
import"./chunk-ztqzmfx1.js";
import"./chunk-6k1rsk85.js";
import"./chunk-nxzx0ey9.js";
import"./chunk-yes1my80.js";
import"./chunk-pecy49yr.js";
import"./chunk-azbab59e.js";
import"./chunk-3nk9q8dr.js";
import {
  __esm,
  __toESM
} from "./chunk-hhsxm2yr.js";

// src/utils/teleport/environmentSelection.ts
async function getEnvironmentSelectionInfo() {
  const environments = await fetchEnvironments();
  if (environments.length === 0) {
    return {
      availableEnvironments: [],
      selectedEnvironment: null,
      selectedEnvironmentSource: null
    };
  }
  const mergedSettings = getSettings_DEPRECATED();
  const defaultEnvironmentId = mergedSettings?.remote?.defaultEnvironmentId;
  let selectedEnvironment = environments.find((env) => env.kind !== "bridge") ?? environments[0];
  let selectedEnvironmentSource = null;
  if (defaultEnvironmentId) {
    const matchingEnvironment = environments.find((env) => env.environment_id === defaultEnvironmentId);
    if (matchingEnvironment) {
      selectedEnvironment = matchingEnvironment;
      for (let i = SETTING_SOURCES.length - 1;i >= 0; i--) {
        const source = SETTING_SOURCES[i];
        if (!source || source === "flagSettings") {
          continue;
        }
        const sourceSettings = getSettingsForSource(source);
        if (sourceSettings?.remote?.defaultEnvironmentId === defaultEnvironmentId) {
          selectedEnvironmentSource = source;
          break;
        }
      }
    }
  }
  return {
    availableEnvironments: environments,
    selectedEnvironment,
    selectedEnvironmentSource
  };
}
var init_environmentSelection = __esm(() => {
  init_constants();
  init_settings();
  init_environments();
});

// src/components/RemoteEnvironmentDialog.tsx
function RemoteEnvironmentDialog({ onDone }) {
  const [loadingState, setLoadingState] = import_react.useState("loading");
  const [environments, setEnvironments] = import_react.useState([]);
  const [selectedEnvironment, setSelectedEnvironment] = import_react.useState(null);
  const [selectedEnvironmentSource, setSelectedEnvironmentSource] = import_react.useState(null);
  const [error, setError] = import_react.useState(null);
  import_react.useEffect(() => {
    let cancelled = false;
    async function fetchInfo() {
      try {
        const result = await getEnvironmentSelectionInfo();
        if (cancelled)
          return;
        setEnvironments(result.availableEnvironments);
        setSelectedEnvironment(result.selectedEnvironment);
        setSelectedEnvironmentSource(result.selectedEnvironmentSource);
        setLoadingState(null);
      } catch (err) {
        if (cancelled)
          return;
        const fetchError = toError(err);
        logError(fetchError);
        setError(fetchError.message);
        setLoadingState(null);
      }
    }
    fetchInfo();
    return () => {
      cancelled = true;
    };
  }, []);
  function handleSelect(value) {
    if (value === "cancel") {
      onDone();
      return;
    }
    setLoadingState("updating");
    const selectedEnv = environments.find((env) => env.environment_id === value);
    if (!selectedEnv) {
      onDone("Error: Selected environment not found");
      return;
    }
    updateSettingsForSource("localSettings", {
      remote: {
        defaultEnvironmentId: selectedEnv.environment_id
      }
    });
    onDone(`Set default remote environment to ${source_default.bold(selectedEnv.name)} (${selectedEnv.environment_id})`);
  }
  if (loadingState === "loading") {
    return /* @__PURE__ */ jsx_runtime.jsx(Dialog, {
      title: DIALOG_TITLE,
      onCancel: onDone,
      hideInputGuide: true,
      children: /* @__PURE__ */ jsx_runtime.jsx(LoadingState, {
        message: "Loading environments\u2026"
      })
    });
  }
  if (error) {
    return /* @__PURE__ */ jsx_runtime.jsx(Dialog, {
      title: DIALOG_TITLE,
      onCancel: onDone,
      children: /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
        color: "error",
        children: [
          "Error: ",
          error
        ]
      })
    });
  }
  if (!selectedEnvironment) {
    return /* @__PURE__ */ jsx_runtime.jsx(Dialog, {
      title: DIALOG_TITLE,
      subtitle: SETUP_HINT,
      onCancel: onDone,
      children: /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
        children: "No remote environments available."
      })
    });
  }
  if (environments.length === 1) {
    return /* @__PURE__ */ jsx_runtime.jsx(SingleEnvironmentContent, {
      environment: selectedEnvironment,
      onDone
    });
  }
  return /* @__PURE__ */ jsx_runtime.jsx(MultipleEnvironmentsContent, {
    environments,
    selectedEnvironment,
    selectedEnvironmentSource,
    loadingState,
    onSelect: handleSelect,
    onCancel: onDone
  });
}
function EnvironmentLabel({ environment }) {
  return /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
    children: [
      figures_default.tick,
      " Using ",
      /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
        bold: true,
        children: environment.name
      }),
      " ",
      /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
        dimColor: true,
        children: [
          "(",
          environment.environment_id,
          ")"
        ]
      })
    ]
  });
}
function SingleEnvironmentContent({
  environment,
  onDone
}) {
  useKeybinding("confirm:yes", onDone, { context: "Confirmation" });
  return /* @__PURE__ */ jsx_runtime.jsx(Dialog, {
    title: DIALOG_TITLE,
    subtitle: SETUP_HINT,
    onCancel: onDone,
    children: /* @__PURE__ */ jsx_runtime.jsx(EnvironmentLabel, {
      environment
    })
  });
}
function MultipleEnvironmentsContent({
  environments,
  selectedEnvironment,
  selectedEnvironmentSource,
  loadingState,
  onSelect,
  onCancel
}) {
  const sourceSuffix = selectedEnvironmentSource && selectedEnvironmentSource !== "localSettings" ? ` (from ${getSettingSourceName(selectedEnvironmentSource)} settings)` : "";
  const subtitle = /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
    children: [
      "Currently using: ",
      /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
        bold: true,
        children: selectedEnvironment.name
      }),
      sourceSuffix
    ]
  });
  return /* @__PURE__ */ jsx_runtime.jsxs(Dialog, {
    title: DIALOG_TITLE,
    subtitle,
    onCancel,
    hideInputGuide: true,
    children: [
      /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
        dimColor: true,
        children: SETUP_HINT
      }),
      loadingState === "updating" ? /* @__PURE__ */ jsx_runtime.jsx(LoadingState, {
        message: "Updating\u2026"
      }) : /* @__PURE__ */ jsx_runtime.jsx(Select, {
        options: environments.map((env) => ({
          label: /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
            children: [
              env.name,
              " ",
              /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
                dimColor: true,
                children: [
                  "(",
                  env.environment_id,
                  ")"
                ]
              })
            ]
          }),
          value: env.environment_id
        })),
        defaultValue: selectedEnvironment.environment_id,
        onChange: onSelect,
        onCancel: () => onSelect("cancel"),
        layout: "compact-vertical"
      }),
      /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
        dimColor: true,
        children: /* @__PURE__ */ jsx_runtime.jsxs(Byline, {
          children: [
            /* @__PURE__ */ jsx_runtime.jsx(KeyboardShortcutHint, {
              shortcut: "Enter",
              action: "select"
            }),
            /* @__PURE__ */ jsx_runtime.jsx(ConfigurableShortcutHint, {
              action: "confirm:no",
              context: "Confirmation",
              fallback: "Esc",
              description: "cancel"
            })
          ]
        })
      })
    ]
  });
}
var import_react, jsx_runtime, DIALOG_TITLE = "Select Remote Environment", SETUP_HINT = `Configure environments at: https://claude.ai/code`;
var init_RemoteEnvironmentDialog = __esm(() => {
  init_source();
  init_figures();
  init_src();
  init_useKeybinding();
  init_errors();
  init_log();
  init_constants();
  init_settings();
  init_environmentSelection();
  init_ConfigurableShortcutHint();
  init_select();
  init_src();
  import_react = __toESM(require_react(), 1);
  jsx_runtime = __toESM(require_jsx_runtime(), 1);
});

// src/commands/remote-env/remote-env.tsx
async function call(onDone) {
  return /* @__PURE__ */ jsx_runtime2.jsx(RemoteEnvironmentDialog, {
    onDone
  });
}
var jsx_runtime2;
var init_remote_env = __esm(() => {
  init_RemoteEnvironmentDialog();
  jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
});
init_remote_env();

export {
  call
};

//# debugId=DEA5BF6AC8FEA8FE64756E2164756E21
//# sourceMappingURL=chunk-zs46ywvj.js.map
