import { c as _c } from "react/compiler-runtime";
import React, { useState } from 'react';
import { type OptionWithDescription, Select } from '../../components/CustomSelect/select.js';
import { Dialog } from '../../components/design-system/Dialog.js';
import { Box, Text } from '../../ink.js';
import { useAppState } from '../../state/AppState.js';
import { isClaudeAISubscriber } from '../../utils/auth.js';
import { openBrowser } from '../../utils/browser.js';
import { CLAUDE_IN_CHROME_MCP_SERVER_NAME, openInChrome } from '../../utils/claudeInChrome/common.js';
import { isChromeExtensionInstalled } from '../../utils/claudeInChrome/setup.js';
import { getGlobalConfig, saveGlobalConfig } from '../../utils/config.js';
import { env } from '../../utils/env.js';
import { isRunningOnHomespace } from '../../utils/envUtils.js';
const CHROME_EXTENSION_URL = 'https://claude.ai/chrome';
const CHROME_PERMISSIONS_URL = 'https://clau.de/chrome/permissions';
const CHROME_RECONNECT_URL = 'https://clau.de/chrome/reconnect';
type MenuAction = 'install-extension' | 'reconnect' | 'manage-permissions' | 'toggle-default';
type Props = {
  onDone: (result?: string) => void;
  isExtensionInstalled: boolean;
  configEnabled: boolean | undefined;
  isClaudeAISubscriber: boolean;
  isWSL: boolean;
};
function ClaudeInChromeMenu(t0) {
  const $ = _c(41);
  const {
    onDone,
    isExtensionInstalled: installed,
    configEnabled,
    isClaudeAISubscriber,
    isWSL
  } = t0;
  const mcpClients = useAppState(_temp);
  const [selectKey, setSelectKey] = useState(0);
  const [enabledByDefault, setEnabledByDefault] = useState(configEnabled ?? false);
  const [showInstallHint, setShowInstallHint] = useState(false);
  const [isExtensionInstalled, setIsExtensionInstalled] = useState(installed);
  let t1;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = false && isRunningOnHomespace();
    $[0] = t1;
  } else {
    t1 = $[0];
  }
  const isHomespace = t1;
  let t2;
  if ($[1] !== mcpClients) {
    t2 = mcpClients.find(_temp2);
    $[1] = mcpClients;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  const chromeClient = t2;
  const isConnected = chromeClient?.type === "connected";
  let t3;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t3 = function openUrl(url) {
      if (isHomespace) {
        openBrowser(url);
      } else {
        openInChrome(url);
      }
    };
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  const openUrl = t3;
  let t4;
  if ($[4] !== enabledByDefault) {
    t4 = function handleAction(action) {
      bb22: switch (action) {
        case "install-extension":
          {
            setSelectKey(_temp3);
            setShowInstallHint(true);
            openUrl(CHROME_EXTENSION_URL);
            break bb22;
          }
        case "reconnect":
          {
            setSelectKey(_temp4);
            isChromeExtensionInstalled().then(installed_0 => {
              setIsExtensionInstalled(installed_0);
              if (installed_0) {
                setShowInstallHint(false);
              }
            });
            openUrl(CHROME_RECONNECT_URL);
            break bb22;
          }
        case "manage-permissions":
          {
            setSelectKey(_temp5);
            openUrl(CHROME_PERMISSIONS_URL);
            break bb22;
          }
        case "toggle-default":
          {
            const newValue = !enabledByDefault;
            saveGlobalConfig(current => ({
              ...current,
              claudeInChromeDefaultEnabled: newValue
            }));
            setEnabledByDefault(newValue);
          }
      }
    };
    $[4] = enabledByDefault;
    $[5] = t4;
  } else {
    t4 = $[5];
  }
  const handleAction = t4;
  let options;
  if ($[6] !== enabledByDefault || $[7] !== isExtensionInstalled) {
    options = [];
    const requiresExtensionSuffix = isExtensionInstalled ? "" : " （需要扩展）";
    if (!isExtensionInstalled && !isHomespace) {
      let t5;
      if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
        t5 = {
          label: "安装 Chrome 扩展",
          value: "install-extension"
        };
        $[9] = t5;
      } else {
        t5 = $[9];
      }
      options.push(t5);
    }
    let t5;
    if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
      t5 = <Text>管理权限</Text>;
      $[10] = t5;
    } else {
      t5 = $[10];
    }
    let t6;
    if ($[11] !== requiresExtensionSuffix) {
      t6 = {
        label: <>{t5}<Text dimColor={true}>{requiresExtensionSuffix}</Text></>,
        value: "manage-permissions"
      };
      $[11] = requiresExtensionSuffix;
      $[12] = t6;
    } else {
      t6 = $[12];
    }
    let t7;
    if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
      t7 = <Text>重新连接扩展</Text>;
      $[13] = t7;
    } else {
      t7 = $[13];
    }
    let t8;
    if ($[14] !== requiresExtensionSuffix) {
      t8 = {
        label: <>{t7}<Text dimColor={true}>{requiresExtensionSuffix}</Text></>,
        value: "reconnect"
      };
      $[14] = requiresExtensionSuffix;
      $[15] = t8;
    } else {
      t8 = $[15];
    }
    const t9 = `默认启用：${enabledByDefault ? "是" : "否"}`;
    let t10;
    if ($[16] !== t9) {
      t10 = {
        label: t9,
        value: "toggle-default"
      };
      $[16] = t9;
      $[17] = t10;
    } else {
      t10 = $[17];
    }
    options.push(t6, t8, t10);
    $[6] = enabledByDefault;
    $[7] = isExtensionInstalled;
    $[8] = options;
  } else {
    options = $[8];
  }
  const isDisabled = isWSL || true && !isClaudeAISubscriber;
  let t5;
  if ($[18] !== onDone) {
    t5 = () => onDone();
    $[18] = onDone;
    $[19] = t5;
  } else {
    t5 = $[19];
  }
  let t6;
  if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
    t6 = <Text>Chrome 中的 Claude 与 Chrome 扩展配合使用，让您可以直接从 Claude Code 控制浏览器。导航网站、填写表单、捕获屏幕截图、录制 GIF，以及使用控制台日志和网络请求进行调试。</Text>;
    $[20] = t6;
  } else {
    t6 = $[20];
  }
  let t7;
  if ($[21] !== isWSL) {
    t7 = isWSL && <Text color="error">Chrome 中的 Claude 目前不支持 WSL。</Text>;
    $[21] = isWSL;
    $[22] = t7;
  } else {
    t7 = $[22];
  }
  let t8;
  if ($[23] !== isClaudeAISubscriber) {
    t8 = true && !isClaudeAISubscriber && <Text color="error">Chrome 中的 Claude 需要 claude.ai 订阅。</Text>;
    $[23] = isClaudeAISubscriber;
    $[24] = t8;
  } else {
    t8 = $[24];
  }
  let t9;
  if ($[25] !== handleAction || $[26] !== isConnected || $[27] !== isDisabled || $[28] !== isExtensionInstalled || $[29] !== options || $[30] !== selectKey || $[31] !== showInstallHint) {
    t9 = !isDisabled && <>{!isHomespace && <Box flexDirection="column"><Text>状态：{" "}{isConnected ? <Text color="success">已启用</Text> : <Text color="inactive">已禁用</Text>}</Text><Text>扩展：{" "}{isExtensionInstalled ? <Text color="success">已安装</Text> : <Text color="warning">未检测到</Text>}</Text></Box>}<Select key={selectKey} options={options} onChange={handleAction} hideIndexes={true} />{showInstallHint && <Text color="warning">安装后，选择{"\"重新连接扩展\""}以连接。</Text>}<Text><Text dimColor={true}>用法：</Text><Text>claude --chrome</Text><Text dimColor={true}> 或 </Text><Text>claude --no-chrome</Text></Text><Text dimColor={true}>站点级权限继承自 Chrome 扩展。在 Chrome 扩展设置中管理权限，以控制 Claude 可以浏览、点击和输入的站点。</Text></>;
    $[25] = handleAction;
    $[26] = isConnected;
    $[27] = isDisabled;
    $[28] = isExtensionInstalled;
    $[29] = options;
    $[30] = selectKey;
    $[31] = showInstallHint;
    $[32] = t9;
  } else {
    t9 = $[32];
  }
  let t10;
  if ($[33] === Symbol.for("react.memo_cache_sentinel")) {
    t10 = <Text dimColor={true}>了解更多：https://code.claude.com/docs/en/chrome</Text>;
    $[33] = t10;
  } else {
    t10 = $[33];
  }
  let t11;
  if ($[34] !== t7 || $[35] !== t8 || $[36] !== t9) {
    t11 = <Box flexDirection="column" gap={1}>{t6}{t7}{t8}{t9}{t10}</Box>;
    $[34] = t7;
    $[35] = t8;
    $[36] = t9;
    $[37] = t11;
  } else {
    t11 = $[37];
  }
  let t12;
  if ($[38] !== t11 || $[39] !== t5) {
    t12 = <Dialog title="Chrome 中的 Claude（测试版）" onCancel={t5} color="chromeYellow">{t11}</Dialog>;
    $[38] = t11;
    $[39] = t5;
    $[40] = t12;
  } else {
    t12 = $[40];
  }
  return t12;
}
function _temp5(k) {
  return k + 1;
}
function _temp4(k_0) {
  return k_0 + 1;
}
function _temp3(k_1) {
  return k_1 + 1;
}
function _temp2(c) {
  return c.name === CLAUDE_IN_CHROME_MCP_SERVER_NAME;
}
function _temp(s) {
  return s.mcp.clients;
}
export const call = async function (onDone: (result?: string) => void): Promise<React.ReactNode> {
  const isExtensionInstalled = await isChromeExtensionInstalled();
  const config = getGlobalConfig();
  const isSubscriber = isClaudeAISubscriber();
  const isWSL = env.isWslEnvironment();
  return <ClaudeInChromeMenu onDone={onDone} isExtensionInstalled={isExtensionInstalled} configEnabled={config.claudeInChromeDefaultEnabled} isClaudeAISubscriber={isSubscriber} isWSL={isWSL} />;
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 22608 characters]