// @bun
import {
  ConfigurableShortcutHint,
  Select,
  fetchEnvironments,
  init_ConfigurableShortcutHint,
  init_environments,
  init_select
} from "./chunk-kjxnr94g.js";
import"./chunk-k60b56gr.js";
import"./chunk-14p6wvsq.js";
import"./chunk-azxvgxxj.js";
import"./chunk-28jd8qjx.js";
import"./chunk-djt39ze3.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-ptxteaeh.js";
import"./chunk-fkj2br21.js";
import"./chunk-shphk01c.js";
import"./chunk-p6k95sgc.js";
import"./chunk-4m3923rb.js";
import"./chunk-y0v4hy3w.js";
import"./chunk-kq5sj40w.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-qn6me9n1.js";
import"./chunk-wngdrp47.js";
import"./chunk-k16xn6nh.js";
import"./chunk-71sdcaq6.js";
import"./chunk-a3d92pmr.js";
import"./chunk-tj8te4np.js";
import"./chunk-vsrmbjkt.js";
import"./chunk-dr2x4ze7.js";
import"./chunk-8ad8jmrf.js";
import"./chunk-24kv69g3.js";
import"./chunk-7epwkzgh.js";
import"./chunk-ecexf828.js";
import"./chunk-4gyjc4jm.js";
import"./chunk-4spgkgr3.js";
import"./chunk-e8dhxycp.js";
import"./chunk-hf0jvnz1.js";
import {
  init_useKeybinding
} from "./chunk-9pygs2bc.js";
import"./chunk-60fkafk2.js";
import"./chunk-gaazk5m4.js";
import"./chunk-syy6c7sf.js";
import"./chunk-093ej2sf.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-nde5ym6a.js";
import"./chunk-071s9he9.js";
import"./chunk-zbbc88qa.js";
import"./chunk-tar6yn24.js";
import"./chunk-ye27avgv.js";
import"./chunk-31evwxsk.js";
import"./chunk-4nctdw69.js";
import"./chunk-vhghhw4q.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-08snmmg4.js";
import"./chunk-hqxp6b72.js";
import"./chunk-z01behwa.js";
import"./chunk-6wnn50vj.js";
import"./chunk-w5hnghah.js";
import"./chunk-j75as8e6.js";
import"./chunk-x59e8cv0.js";
import"./chunk-s76nvx50.js";
import"./chunk-7jyr5758.js";
import {
  SETTING_SOURCES,
  getSettingSourceName,
  getSettingsForSource,
  getSettings_DEPRECATED,
  init_constants,
  init_settings1 as init_settings,
  updateSettingsForSource
} from "./chunk-33xsdkzq.js";
import"./chunk-nkg1b3qw.js";
import"./chunk-c1kx8bry.js";
import"./chunk-epvbnq43.js";
import"./chunk-swgt1px0.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-swz6krys.js";
import"./chunk-7eywm3ed.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-25w7rxtr.js";
import"./chunk-5xfj4jkd.js";
import"./chunk-c1t99xmt.js";
import"./chunk-vwenx8ke.js";
import"./chunk-8thwr7p8.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-rt34thxn.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import"./chunk-kgkdmr0x.js";
import"./chunk-hn4w9pkj.js";
import {
  Byline,
  Dialog,
  KeyboardShortcutHint,
  LoadingState,
  ThemedText,
  init_source,
  init_src,
  require_react,
  source_default,
  useKeybinding
} from "./chunk-cswpvb8x.js";
import {
  require_jsx_runtime
} from "./chunk-gxyx8b8w.js";
import"./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-ddaxg4xh.js";
import"./chunk-vvh31np8.js";
import"./chunk-tywrrc1m.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-4p0hxk2c.js";
import"./chunk-c4dyxsat.js";
import {
  init_log,
  logError
} from "./chunk-34rn09za.js";
import"./chunk-m28vg9w4.js";
import"./chunk-rk9fgqmg.js";
import"./chunk-nw4zt0y4.js";
import"./chunk-c1yc761e.js";
import {
  figures_default,
  init_figures
} from "./chunk-c5g9shkw.js";
import {
  init_errors,
  toError
} from "./chunk-k9jzhhww.js";
import"./chunk-kb3758f7.js";
import"./chunk-xqs9r7pg.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=418E05CF773604A664756E2164756E21
//# sourceMappingURL=chunk-4c1b8h9c.js.map
