'use client' import type { GitStatus, StatusFileEntry } from '@devframes/service-git' import type { ReactNode } from 'react' import { cn } from '../../lib/utils' import { Badge } from '../ui/badge' import { Button, IconButton } from '../ui/button' import { FileIcon } from '../ui/file-icon' import { Icon } from '../ui/icon' import { ScrollArea } from '../ui/scroll-area' import { Skeleton } from '../ui/skeleton' import { StatusMark } from '../ui/status-mark' import { Textarea } from '../ui/textarea' export interface StatusPanelViewProps { data: GitStatus | null loading: boolean busy: boolean canWrite: boolean message: string note: string | null /** `${staged}:${path}` of the file whose diff is shown, or `null`. */ selectedKey?: string | null onRefresh: () => void | Promise onStage: (paths: string[]) => void | Promise onUnstage: (paths: string[]) => void | Promise onCommit: () => void | Promise onMessageChange: (value: string) => void /** Reveal a file's diff. `staged` picks the index-vs-HEAD diff. */ onSelectFile?: (path: string, staged: boolean) => void /** The selected file's diff viewer, rendered below the file list. */ patchSlot?: ReactNode } function fileKey(path: string, staged: boolean): string { return `${staged}:${path}` } function FileRow({ entry, staged, selected, action, onSelect }: { entry: StatusFileEntry staged: boolean selected: boolean action?: ReactNode onSelect?: (path: string, staged: boolean) => void }) { const label = entry.from ? `${entry.from} → ${entry.path}` : entry.path return (
  • {action}
  • ) } function Section({ title, count, headerAction, children, }: { title: string count: number headerAction?: ReactNode children: ReactNode }) { if (count === 0) return null return (
    {title} {count}
    {headerAction}
      {children}
    ) } export function StatusPanelView(props: StatusPanelViewProps) { const { data, loading, busy, canWrite, message, note, selectedKey, onRefresh, onStage, onUnstage, onCommit, onMessageChange, onSelectFile, patchSlot } = props const stageBtn = (paths: string[], label: string) => ( onStage(paths)}> ) const unstageBtn = (paths: string[], label: string) => ( onUnstage(paths)}> ) return (

    Changes

    {data?.isRepo && !data.clean && ( {data.staged.length + data.unstaged.length + data.untracked.length} {' '} changed )}
    {data?.isRepo && (data.ahead > 0 || data.behind > 0) && ( {data.ahead > 0 && ( {data.ahead} )} {data.behind > 0 && ( {data.behind} )} )}
    {!data && (
    {Array.from({ length: 4 }).map((_, i) => )}
    )} {data && !data.isRepo && (

    The working directory is not a git repository.

    )} {data?.isRepo && data.clean && (

    Nothing to commit. The working tree is clean.

    )} {data?.isRepo && !data.clean && (
    0 ? : undefined} > {data.staged.map(entry => ( ))}
    0 ? : undefined} > {data.unstaged.map(entry => ( ))}
    0 ? : undefined} > {data.untracked.map(path => ( ))}
    {patchSlot && (
    {patchSlot}
    )} {canWrite && data.staged.length > 0 && (