// @bun
import {
  WelcomeV2
} from "./chunk-whvapg7g.js";
import {
  ApproveApiKey
} from "./chunk-bt2drxqy.js";
import {
  ThemePicker,
  init_ThemePicker
} from "./chunk-cfxbrweb.js";
import {
  PressEnterToContinue,
  init_PressEnterToContinue
} from "./chunk-yv36ctvm.js";
import {
  ConsoleOAuthFlow,
  Select,
  Spinner,
  init_ConsoleOAuthFlow,
  init_Spinner,
  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 {
  init_useExitOnCtrlCDWithKeybindings,
  useExitOnCtrlCDWithKeybindings
} from "./chunk-fcqebw9m.js";
import {
  init_terminalSetup,
  setupTerminal,
  shouldOfferTerminalSetup
} from "./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 {
  getCustomApiKeyStatus,
  init_auth,
  init_authPortable,
  init_config1 as init_config,
  isAnthropicAuthEnabled,
  normalizeApiKeyForConfig
} 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 {
  env,
  init_env
} from "./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 {
  Link,
  Newline,
  ThemedBox_default,
  ThemedText,
  init_src,
  require_react,
  useKeybindings,
  useTheme,
  useTimeout
} from "./chunk-0r6npc3t.js";
import {
  require_jsx_runtime
} from "./chunk-gxyx8b8w.js";
import {
  init_analytics,
  logEvent
} from "./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"./chunk-8wsj9fff.js";
import"./chunk-m28vg9w4.js";
import"./chunk-f8prtxs3.js";
import"./chunk-41a6f2kv.js";
import"./chunk-c1yc761e.js";
import"./chunk-c5g9shkw.js";
import"./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 {
  init_envUtils,
  isRunningOnHomespace
} from "./chunk-6k1rsk85.js";
import"./chunk-nxzx0ey9.js";
import"./chunk-yes1my80.js";
import"./chunk-pecy49yr.js";
import"./chunk-azbab59e.js";
import"./chunk-3nk9q8dr.js";
import {
  __toESM
} from "./chunk-hhsxm2yr.js";

// src/components/Onboarding.tsx
init_analytics();
init_terminalSetup();
init_useExitOnCtrlCDWithKeybindings();
init_src();
init_useKeybinding();
init_auth();
init_authPortable();
init_config();
init_env();
init_envUtils();
var import_react4 = __toESM(require_react(), 1);

// src/utils/preflightChecks.tsx
var import_react = __toESM(require_react(), 1);

// src/hooks/useTimeout.ts
init_src();

// src/utils/preflightChecks.tsx
init_src();
init_Spinner();
var jsx_runtime = __toESM(require_jsx_runtime(), 1);
async function checkEndpoints() {
  return { success: true };
}
function PreflightStep({ onSuccess }) {
  const [result, setResult] = import_react.useState(null);
  const [isChecking, setIsChecking] = import_react.useState(true);
  const showSpinner = useTimeout(1000) && isChecking;
  import_react.useEffect(() => {
    async function run() {
      const checkResult = await checkEndpoints();
      setResult(checkResult);
      setIsChecking(false);
    }
    run();
  }, []);
  import_react.useEffect(() => {
    if (result?.success) {
      onSuccess();
    }
  }, [result, onSuccess]);
  return /* @__PURE__ */ jsx_runtime.jsx(ThemedBox_default, {
    flexDirection: "column",
    gap: 1,
    paddingLeft: 1,
    children: isChecking && showSpinner ? /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      paddingLeft: 1,
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(Spinner, {}),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          children: "Checking connectivity..."
        })
      ]
    }) : !result?.success && !isChecking && /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
      flexDirection: "column",
      gap: 1,
      children: [
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          color: "error",
          children: "Unable to connect to Anthropic services"
        }),
        /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
          color: "error",
          children: result?.error
        })
      ]
    })
  });
}

// src/components/Onboarding.tsx
init_ConsoleOAuthFlow();
init_select();
init_PressEnterToContinue();
init_ThemePicker();

// src/components/ui/OrderedList.tsx
init_src();
var import_react3 = __toESM(require_react(), 1);

// src/components/ui/OrderedListItem.tsx
init_src();
var import_react2 = __toESM(require_react(), 1);
var jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
var OrderedListItemContext = import_react2.createContext({ marker: "" });
function OrderedListItem({ children }) {
  const { marker } = import_react2.useContext(OrderedListItemContext);
  return /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
    gap: 1,
    children: [
      /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
        dimColor: true,
        children: marker
      }),
      /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
        flexDirection: "column",
        children
      })
    ]
  });
}

// src/components/ui/OrderedList.tsx
var jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
var OrderedListContext = import_react3.createContext({ marker: "" });
function OrderedListComponent({ children }) {
  const { marker: parentMarker } = import_react3.useContext(OrderedListContext);
  let numberOfItems = 0;
  for (const child of import_react3.default.Children.toArray(children)) {
    if (!import_react3.isValidElement(child) || child.type !== OrderedListItem) {
      continue;
    }
    numberOfItems++;
  }
  const maxMarkerWidth = String(numberOfItems).length;
  return /* @__PURE__ */ jsx_runtime3.jsx(ThemedBox_default, {
    flexDirection: "column",
    children: import_react3.default.Children.map(children, (child, index) => {
      if (!import_react3.isValidElement(child) || child.type !== OrderedListItem) {
        return child;
      }
      const paddedMarker = `${String(index + 1).padStart(maxMarkerWidth)}.`;
      const marker = `${parentMarker}${paddedMarker}`;
      return /* @__PURE__ */ jsx_runtime3.jsx(OrderedListContext.Provider, {
        value: { marker },
        children: /* @__PURE__ */ jsx_runtime3.jsx(OrderedListItemContext.Provider, {
          value: { marker },
          children: child
        })
      });
    })
  });
}
OrderedListComponent.Item = OrderedListItem;
var OrderedList = OrderedListComponent;

// src/components/Onboarding.tsx
var jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
function Onboarding({ onDone }) {
  const [currentStepIndex, setCurrentStepIndex] = import_react4.useState(0);
  const [skipOAuth, setSkipOAuth] = import_react4.useState(false);
  const [oauthEnabled] = import_react4.useState(() => isAnthropicAuthEnabled());
  const [theme, setTheme] = useTheme();
  import_react4.useEffect(() => {
    logEvent("tengu_began_setup", {
      oauthEnabled
    });
  }, [oauthEnabled]);
  function goToNextStep() {
    if (currentStepIndex < steps.length - 1) {
      const nextIndex = currentStepIndex + 1;
      setCurrentStepIndex(nextIndex);
      logEvent("tengu_onboarding_step", {
        oauthEnabled,
        stepId: steps[nextIndex]?.id
      });
    } else {
      onDone();
    }
  }
  function handleThemeSelection(newTheme) {
    setTheme(newTheme);
    goToNextStep();
  }
  const exitState = useExitOnCtrlCDWithKeybindings();
  const themeStep = /* @__PURE__ */ jsx_runtime4.jsx(ThemedBox_default, {
    marginX: 1,
    children: /* @__PURE__ */ jsx_runtime4.jsx(ThemePicker, {
      onThemeSelect: handleThemeSelection,
      showIntroText: true,
      helpText: "To change this later, run /theme",
      hideEscToCancel: true,
      skipExitHandling: true
    })
  });
  const securityStep = /* @__PURE__ */ jsx_runtime4.jsxs(ThemedBox_default, {
    flexDirection: "column",
    gap: 1,
    paddingLeft: 1,
    children: [
      /* @__PURE__ */ jsx_runtime4.jsx(ThemedText, {
        bold: true,
        children: "Before you start, keep in mind:"
      }),
      /* @__PURE__ */ jsx_runtime4.jsx(ThemedBox_default, {
        flexDirection: "column",
        width: 70,
        children: /* @__PURE__ */ jsx_runtime4.jsxs(OrderedList, {
          children: [
            /* @__PURE__ */ jsx_runtime4.jsxs(OrderedList.Item, {
              children: [
                /* @__PURE__ */ jsx_runtime4.jsx(ThemedText, {
                  children: "Always review changes before accepting"
                }),
                /* @__PURE__ */ jsx_runtime4.jsxs(ThemedText, {
                  dimColor: true,
                  wrap: "wrap",
                  children: [
                    "Claude can make mistakes \u2014 especially when running commands",
                    /* @__PURE__ */ jsx_runtime4.jsx(Newline, {}),
                    "or editing files. You stay in control of every action.",
                    /* @__PURE__ */ jsx_runtime4.jsx(Newline, {})
                  ]
                })
              ]
            }),
            /* @__PURE__ */ jsx_runtime4.jsxs(OrderedList.Item, {
              children: [
                /* @__PURE__ */ jsx_runtime4.jsx(ThemedText, {
                  children: "Only use Chris Code on projects you trust"
                }),
                /* @__PURE__ */ jsx_runtime4.jsxs(ThemedText, {
                  dimColor: true,
                  wrap: "wrap",
                  children: [
                    "Untrusted code could contain prompt injection attacks.",
                    /* @__PURE__ */ jsx_runtime4.jsx(Newline, {}),
                    /* @__PURE__ */ jsx_runtime4.jsx(Link, {
                      url: "https://code.claude.com/docs/en/security"
                    })
                  ]
                })
              ]
            })
          ]
        })
      }),
      /* @__PURE__ */ jsx_runtime4.jsx(PressEnterToContinue, {})
    ]
  });
  const _preflightStep = /* @__PURE__ */ jsx_runtime4.jsx(PreflightStep, {
    onSuccess: goToNextStep
  });
  const apiKeyNeedingApproval = import_react4.useMemo(() => {
    if (!process.env.ANTHROPIC_API_KEY || isRunningOnHomespace()) {
      return "";
    }
    const customApiKeyTruncated = normalizeApiKeyForConfig(process.env.ANTHROPIC_API_KEY);
    if (getCustomApiKeyStatus(customApiKeyTruncated) === "new") {
      return customApiKeyTruncated;
    }
  }, []);
  function handleApiKeyDone(approved) {
    if (approved) {
      setSkipOAuth(true);
    }
    goToNextStep();
  }
  const steps = [];
  steps.push({ id: "theme", component: themeStep });
  if (apiKeyNeedingApproval) {
    steps.push({
      id: "api-key",
      component: /* @__PURE__ */ jsx_runtime4.jsx(ApproveApiKey, {
        customApiKeyTruncated: apiKeyNeedingApproval,
        onDone: handleApiKeyDone
      })
    });
  }
  if (oauthEnabled) {
    steps.push({
      id: "oauth",
      component: /* @__PURE__ */ jsx_runtime4.jsx(SkippableStep, {
        skip: skipOAuth,
        onSkip: goToNextStep,
        children: /* @__PURE__ */ jsx_runtime4.jsx(ConsoleOAuthFlow, {
          onDone: goToNextStep
        })
      })
    });
  }
  steps.push({ id: "security", component: securityStep });
  if (shouldOfferTerminalSetup()) {
    steps.push({
      id: "terminal-setup",
      component: /* @__PURE__ */ jsx_runtime4.jsxs(ThemedBox_default, {
        flexDirection: "column",
        gap: 1,
        paddingLeft: 1,
        children: [
          /* @__PURE__ */ jsx_runtime4.jsx(ThemedText, {
            bold: true,
            children: "Use Chris Code's terminal setup?"
          }),
          /* @__PURE__ */ jsx_runtime4.jsxs(ThemedBox_default, {
            flexDirection: "column",
            width: 70,
            gap: 1,
            children: [
              /* @__PURE__ */ jsx_runtime4.jsxs(ThemedText, {
                children: [
                  "For the optimal coding experience, enable the recommended settings",
                  /* @__PURE__ */ jsx_runtime4.jsx(Newline, {}),
                  "for your terminal:",
                  " ",
                  env.terminal === "Apple_Terminal" ? "Option+Enter for newlines and visual bell" : "Shift+Enter for newlines"
                ]
              }),
              /* @__PURE__ */ jsx_runtime4.jsx(Select, {
                options: [
                  {
                    label: "Yes, use recommended settings",
                    value: "install"
                  },
                  {
                    label: "No, maybe later with /terminal-setup",
                    value: "no"
                  }
                ],
                onChange: (value) => {
                  if (value === "install") {
                    setupTerminal(theme).catch(() => {}).finally(goToNextStep);
                  } else {
                    goToNextStep();
                  }
                },
                onCancel: () => goToNextStep()
              }),
              /* @__PURE__ */ jsx_runtime4.jsx(ThemedText, {
                dimColor: true,
                children: exitState.pending ? /* @__PURE__ */ jsx_runtime4.jsxs(jsx_runtime4.Fragment, {
                  children: [
                    "Press ",
                    exitState.keyName,
                    " again to exit"
                  ]
                }) : /* @__PURE__ */ jsx_runtime4.jsx(jsx_runtime4.Fragment, {
                  children: "Enter to confirm \xB7 Esc to skip"
                })
              })
            ]
          })
        ]
      })
    });
  }
  const currentStep = steps[currentStepIndex];
  const handleSecurityContinue = import_react4.useCallback(() => {
    if (currentStepIndex === steps.length - 1) {
      onDone();
    } else {
      goToNextStep();
    }
  }, [currentStepIndex, steps.length, oauthEnabled, onDone]);
  const handleTerminalSetupSkip = import_react4.useCallback(() => {
    goToNextStep();
  }, [currentStepIndex, steps.length, oauthEnabled, onDone]);
  useKeybindings({
    "confirm:yes": handleSecurityContinue
  }, {
    context: "Confirmation",
    isActive: currentStep?.id === "security"
  });
  useKeybindings({
    "confirm:no": handleTerminalSetupSkip
  }, {
    context: "Confirmation",
    isActive: currentStep?.id === "terminal-setup"
  });
  return /* @__PURE__ */ jsx_runtime4.jsxs(ThemedBox_default, {
    flexDirection: "column",
    children: [
      /* @__PURE__ */ jsx_runtime4.jsx(WelcomeV2, {}),
      /* @__PURE__ */ jsx_runtime4.jsxs(ThemedBox_default, {
        flexDirection: "column",
        marginTop: 1,
        children: [
          currentStep?.component,
          exitState.pending && /* @__PURE__ */ jsx_runtime4.jsx(ThemedBox_default, {
            padding: 1,
            children: /* @__PURE__ */ jsx_runtime4.jsxs(ThemedText, {
              dimColor: true,
              children: [
                "Press ",
                exitState.keyName,
                " again to exit"
              ]
            })
          })
        ]
      })
    ]
  });
}
function SkippableStep({
  skip,
  onSkip,
  children
}) {
  import_react4.useEffect(() => {
    if (skip) {
      onSkip();
    }
  }, [skip, onSkip]);
  if (skip) {
    return null;
  }
  return children;
}
export {
  SkippableStep,
  Onboarding
};

//# debugId=D21F6081867C85E164756E2164756E21
//# sourceMappingURL=chunk-w4qmjnq9.js.map
