import { toString as qrToString } from 'qrcode'; import * as React from 'react'; import { useCallback, useEffect, useState } from 'react'; import { Pane } from '@anthropic/ink'; import { type KeyboardEvent, Box, Text } from '@anthropic/ink'; import { useKeybinding } from '../../keybindings/useKeybinding.js'; import type { LocalJSXCommandOnDone } from '../../types/command.js'; type Platform = 'ios' | 'android'; type Props = { onDone: () => void; }; const PLATFORMS: Record = { ios: { url: 'https://apps.apple.com/app/claude-by-anthropic/id6473753684', }, android: { url: 'https://play.google.com/store/apps/details?id=com.anthropic.claude', }, }; function MobileQRCode({ onDone }: Props): React.ReactNode { const [platform, setPlatform] = useState('ios'); const [qrCodes, setQrCodes] = useState>({ ios: '', android: '', }); const { url } = PLATFORMS[platform]; const qrCode = qrCodes[platform]; // Generate both QR codes upfront to avoid flicker when switching useEffect(() => { async function generateQRCodes(): Promise { const [ios, android] = await Promise.all([ qrToString(PLATFORMS.ios.url, { type: 'utf8', errorCorrectionLevel: 'L', }), qrToString(PLATFORMS.android.url, { type: 'utf8', errorCorrectionLevel: 'L', }), ]); setQrCodes({ ios, android }); } generateQRCodes().catch(() => { // QR generation failed, leave empty }); }, []); const handleClose = useCallback(() => { onDone(); }, [onDone]); useKeybinding('confirm:no', handleClose, { context: 'Confirmation' }); function handleKeyDown(e: KeyboardEvent): void { if (e.key === 'q' || (e.ctrl && e.key === 'c')) { e.preventDefault(); onDone(); return; } if (e.key === 'tab' || e.key === 'left' || e.key === 'right') { e.preventDefault(); setPlatform(prev => (prev === 'ios' ? 'android' : 'ios')); } } const lines = qrCode.split('\n').filter(line => line.length > 0); return ( {lines.map((line, i) => ( {line} ))} {/* Controls */} iOS {' / '} Android (tab to switch, esc to close) {url} ); } export async function call(onDone: LocalJSXCommandOnDone): Promise { return ; }