import React from 'react';
interface Props {
original: string;
updated: string;
onApply: () => void;
onDiscard: () => void;
}
function highlightDiff(a: string, b: string) {
// Simple common prefix/suffix highlighting
let i = 0;
while (i < a.length && i < b.length && a[i] === b[i]) i++;
let j = 0;
while (j < a.length - i && j < b.length - i && a[a.length - 1 - j] === b[b.length - 1 - j]) j++;
const aMid = a.substring(i, a.length - j);
const bMid = b.substring(i, b.length - j);
const aHtml = `${escapeHtml(a.substring(0, i))}${escapeHtml(aMid)}${escapeHtml(a.substring(a.length - j))}`;
const bHtml = `${escapeHtml(b.substring(0, i))}${escapeHtml(bMid)}${escapeHtml(b.substring(b.length - j))}`;
return { aHtml, bHtml };
}
function escapeHtml(s: string) {
return s
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
const DiffPreview: React.FC = ({ original, updated, onApply, onDiscard }) => {
const { aHtml, bHtml } = highlightDiff(original, updated);
return (
Preview Changes
);
};
export default DiffPreview;