import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from 'ink';
import uniqBy from 'lodash/uniqBy.js';
import { DiffPatchBlock } from './DiffPatchBlock.js';
const actionLabels = {
    create: 'created',
    delete: 'deleted',
    replace: 'edited',
    update: 'edited',
};
export function RecentEditDiffPanel({ diffs, review, running }) {
    if (diffs.length === 0) {
        return null;
    }
    if (review.mode === 'review' && review.selectedDiff) {
        return _jsx(RecentEditDiffReviewPanel, { diffs: diffs, review: review });
    }
    return _jsx(RecentEditDiffSummary, { diffs: diffs, running: running });
}
function RecentEditDiffSummary({ diffs, running, }) {
    return (_jsxs(Box, { marginTop: 1, children: [_jsx(Text, { dimColor: true, children: "Recent edits: " }), _jsx(Text, { children: formatDiffScope(diffs) }), _jsx(Text, { dimColor: true, children: running ? ' · run active' : ' · run done' }), _jsx(Text, { dimColor: true, children: " \u00B7 type " }), _jsx(Text, { color: "cyan", children: "/d" }), _jsx(Text, { dimColor: true, children: " to review" })] }));
}
function RecentEditDiffReviewPanel({ diffs, review, }) {
    const diff = review.selectedDiff;
    if (!diff) {
        return null;
    }
    return (_jsxs(Box, { flexDirection: "column", borderStyle: "single", borderColor: "gray", paddingX: 1, marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { bold: true, children: "Diff review" }), _jsxs(Text, { dimColor: true, children: [" \u00B7 ", formatDiffScope(diffs)] }), _jsx(Text, { dimColor: true, children: " \u00B7 Esc close" })] }), _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsxs(Text, { dimColor: true, children: ["[", review.selectedIndex + 1, "/", diffs.length, "] "] }), _jsx(Text, { color: "cyan", children: diff.path }), _jsx(Text, { dimColor: true, children: formatEditMeta(diff) })] }), _jsx(DiffPatchBlock, { id: diff.id, patch: diff.patch, truncated: diff.truncated })] }), _jsx(Text, { dimColor: true, children: "j/k or arrows move \u00B7 n/p file \u00B7 esc back" })] }));
}
function formatDiffScope(diffs) {
    const editCount = diffs.length;
    const fileCount = uniqBy(diffs, 'path').length;
    return `${editCount} ${editCount === 1 ? 'edit' : 'edits'} across ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`;
}
function formatEditMeta(diff) {
    const action = diff.action ? actionLabels[diff.action] ?? diff.action : undefined;
    const step = typeof diff.step === 'number' ? `step ${diff.step}` : undefined;
    return [action, step].filter(Boolean).map((value) => ` · ${value}`).join('');
}
//# sourceMappingURL=RecentEditDiffPanel.js.map