import React from 'react'; import { Button } from '@/components/ui/button'; import { Icon } from '@/components/icon/Icon'; import { copyTextToClipboard } from '@/lib/clipboard'; import { useI18n } from '@/lib/i18n'; import type { GeneratedResult } from './generatedJsonResult'; export const GeneratedJsonResultCard: React.FC<{ result: GeneratedResult }> = ({ result }) => { const { t } = useI18n(); const [copied, setCopied] = React.useState(false); const copiedResetTimerRef = React.useRef(null); React.useEffect(() => { return () => { if (copiedResetTimerRef.current !== null) { window.clearTimeout(copiedResetTimerRef.current); } }; }, []); const copyText = React.useMemo(() => { if (result.kind === 'commit') { return [result.subject, ...result.highlights.map((highlight) => `- ${highlight}`)].join('\n'); } return [result.title, result.body].filter(Boolean).join('\n\n'); }, [result]); const handleCopy = React.useCallback(async () => { const copyResult = await copyTextToClipboard(copyText || result.raw); if (!copyResult.ok) return; if (copiedResetTimerRef.current !== null) { window.clearTimeout(copiedResetTimerRef.current); } setCopied(true); copiedResetTimerRef.current = window.setTimeout(() => { copiedResetTimerRef.current = null; setCopied(false); }, 2000); }, [copyText, result.raw]); return (
{result.kind === 'commit' ? t('chat.generatedResult.commit.title') : t('chat.generatedResult.pullRequest.title')}
{result.kind === 'commit' ? ( <>
{result.subject}
{result.highlights.length > 0 ? (
    {result.highlights.map((highlight, index) => (
  • - {highlight}
  • ))}
) : null} ) : ( <> {result.title ? (
{t('chat.generatedResult.pullRequest.titleLabel')}
{result.title}
) : null} {result.body ? (
{t('chat.generatedResult.pullRequest.bodyLabel')}
{result.body}
) : null} )}
); };