import { type GitHubPrFileDiffLine, type ReactNode, useMemo, buildGitHubPrFileDiffPreview, resolveMobileSyntaxLanguage, highlightMobileDiffLines, Text, View, MobileSyntaxSegments, TextInput, colors, Pressable } from './mobile-tasks-dependencies' import { MAX_RENDERED_PR_DIFF_LINES } from './mobile-tasks-options' import type { GitHubPRFileContents } from './mobile-tasks-provider-detail-types' import { styles } from './mobile-tasks-legacy-styles' export function formatDiffLineNumber(value: number | undefined): string { return value === undefined ? ' ' : value.toString().padStart(4, ' ') } export function diffLinePrefix(kind: GitHubPrFileDiffLine['kind']): string { if (kind === 'added') { return '+' } if (kind === 'removed') { return '-' } return ' ' } export function GitHubPrFileDiff({ filePath, contents, commentDrafts, disabled, onCommentDraftChange, onSubmitComment }: { filePath: string contents: GitHubPRFileContents commentDrafts: Record disabled: boolean onCommentDraftChange: (key: string, value: string) => void onSubmitComment: (line: number) => void }): ReactNode { const diffPreview = useMemo( () => buildGitHubPrFileDiffPreview( contents.original, contents.modified, MAX_RENDERED_PR_DIFF_LINES ), [contents.modified, contents.original] ) const syntaxLanguage = useMemo(() => resolveMobileSyntaxLanguage(filePath), [filePath]) const visibleDiffLines = useMemo( () => highlightMobileDiffLines(diffPreview.lines, syntaxLanguage), [diffPreview.lines, syntaxLanguage] ) const hiddenDiffLineCount = Math.max(0, diffPreview.totalLineCount - visibleDiffLines.length) if (diffPreview.totalLineCount === 0) { return No text changes found. } return ( {hiddenDiffLineCount > 0 ? ( Showing first {MAX_RENDERED_PR_DIFF_LINES} of {diffPreview.totalLineCount} diff lines. ) : null} {visibleDiffLines.map((line) => { const commentLine = line.kind === 'removed' ? undefined : line.newLineNumber const draftKey = commentLine === undefined ? '' : `${filePath}:${commentLine}` return ( {formatDiffLineNumber(line.oldLineNumber)}{' '} {formatDiffLineNumber(line.newLineNumber)} {diffLinePrefix(line.kind)} {line.text ? null : ' '} {commentLine !== undefined ? ( <> onCommentDraftChange(draftKey, next)} placeholder="Add review comment" placeholderTextColor={colors.textMuted} multiline textAlignVertical="top" /> onSubmitComment(commentLine)} > Comment on line {commentLine} ) : null} ) })} ) }