import { useCallback, useMemo, useRef, useState } from "react"; import { withUnistyles } from "react-native-unistyles"; import { RenderProfile } from "@/utils/render-profiler"; import { createDiffPalette, retainDiffPalette } from "./palette"; import { DiffSurface } from "./surface"; import type { DiffDocumentProps, DiffPalette } from "./types"; export type { DiffDocumentProps, WorkingDiffMode } from "./types"; type ThemedDiffDocumentProps = DiffDocumentProps & { palette: DiffPalette; }; const EMPTY_PATHS: string[] = []; function ThemedDiffDocument(props: ThemedDiffDocumentProps) { const [selectedPath, setSelectedPath] = useState(null); const paletteRef = useRef(props.palette); paletteRef.current = retainDiffPalette(paletteRef.current, props.palette); const palette = paletteRef.current; const collapseState = props.mode.kind === "working" ? props.collapseState : null; const paths = collapseState?.paths ?? EMPTY_PATHS; const collapsedFilePaths = useMemo(() => new Set(paths), [paths]); const toggleFile = useCallback( (path: string) => { if (!collapseState) return; const next = collapsedFilePaths.has(path) ? paths.filter((entry) => entry !== path) : [...paths, path]; collapseState.onChange(next); }, [collapseState, collapsedFilePaths, paths], ); return ( ); } const StyledDiffDocument = withUnistyles(ThemedDiffDocument, (theme) => ({ palette: createDiffPalette(theme), })); export function DiffDocument(props: DiffDocumentProps) { return ( ); }