File size: 4,905 Bytes
1e24842
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React from 'react';
import { Edit3, X, Check } from 'lucide-react';

function DiffRow({ label, original, modified }) {
  const changed = JSON.stringify(original) !== JSON.stringify(modified);
  return (
    <div style={{ marginBottom: 10 }}>
      <span style={{ fontSize: 10, textTransform: 'uppercase', letterSpacing: '0.08em', color: 'var(--fg-3)', fontWeight: 700 }}>{label}</span>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, marginTop: 4 }}>
        <div style={{ background: 'var(--bg-0)', border: `1px solid ${changed ? '#ef44442a' : 'var(--line-1)'}`, borderRadius: 5, padding: 8 }}>
          <div style={{ fontSize: 9, color: '#ef4444', fontWeight: 700, marginBottom: 4, textTransform: 'uppercase', letterSpacing: '0.08em' }}>Before</div>
          <pre style={{ fontSize: 11, color: 'var(--fg-2)', margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}>
            {original == null ? '(none)' : (typeof original === 'object' ? JSON.stringify(original, null, 2) : String(original))}
          </pre>
        </div>
        <div style={{ background: 'var(--bg-0)', border: `1px solid ${changed ? '#22c55e2a' : 'var(--line-1)'}`, borderRadius: 5, padding: 8 }}>
          <div style={{ fontSize: 9, color: '#22c55e', fontWeight: 700, marginBottom: 4, textTransform: 'uppercase', letterSpacing: '0.08em' }}>After</div>
          <pre style={{ fontSize: 11, color: 'var(--fg-2)', margin: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-all' }}>
            {modified == null ? '(none)' : (typeof modified === 'object' ? JSON.stringify(modified, null, 2) : String(modified))}
          </pre>
        </div>
      </div>
    </div>
  );
}

export default function ModifyDiffModal({ original, changes, onConfirm, onCancel }) {
  const modified = {
    ...original,
    body: changes.body !== undefined ? { ...(original.body || {}), ...changes.body } : original.body,
    query_params: changes.query_params !== undefined ? { ...(original.query_params || {}), ...changes.query_params } : original.query_params,
    headers: changes.headers !== undefined ? { ...(original.headers || {}), ...changes.headers } : original.headers,
    path_params: changes.path_params !== undefined ? { ...(original.path_params || {}), ...changes.path_params } : original.path_params,
    ...Object.fromEntries(Object.entries(changes).filter(([k]) => !['body', 'query_params', 'headers', 'path_params'].includes(k))),
  };

  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 60, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'rgba(0,0,0,0.75)', backdropFilter: 'blur(8px)', padding: 16 }}>
      <div style={{ background: 'var(--bg-1)', border: '1px solid var(--line-3)', borderRadius: 10, width: '100%', maxWidth: 680, maxHeight: '85vh', overflow: 'hidden', display: 'flex', flexDirection: 'column', boxShadow: 'var(--shadow-md)' }}>
        <div style={{ padding: '12px 16px', borderBottom: '1px solid var(--line-1)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexShrink: 0 }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
            <Edit3 size={14} style={{ color: 'var(--accent)' }}/>
            <span style={{ fontSize: 13, fontWeight: 600, color: 'var(--fg-0)' }}>Review AI Modifications</span>
            <span style={{ fontSize: 11, color: 'var(--fg-3)' }}>Step {original.step}: {original.endpoint}</span>
          </div>
          <button onClick={onCancel} className="ico-btn"><X size={14}/></button>
        </div>

        <div style={{ flex: 1, overflowY: 'auto', padding: 20 }}>
          <p style={{ fontSize: 12, color: 'var(--fg-2)', marginBottom: 16, lineHeight: 1.6 }}>
            The AI proposed the following changes. Review the diff below before executing.
          </p>

          {['body', 'query_params', 'headers', 'path_params'].map(key =>
            (changes[key] !== undefined || original[key]) ? (
              <DiffRow
                key={key}
                label={key.replace('_', ' ')}
                original={original[key]}
                modified={modified[key]}
              />
            ) : null
          )}

          {Object.entries(changes)
            .filter(([k]) => !['body', 'query_params', 'headers', 'path_params'].includes(k))
            .map(([k, v]) => (
              <DiffRow key={k} label={k} original={original[k]} modified={v}/>
            ))}
        </div>

        <div style={{ padding: '12px 20px', borderTop: '1px solid var(--line-1)', display: 'flex', gap: 8, justifyContent: 'flex-end', flexShrink: 0 }}>
          <button onClick={onCancel} className="btn">Cancel</button>
          <button onClick={() => onConfirm(modified)} className="btn btn-primary" style={{ gap: 6 }}>
            <Check size={13}/> Apply & Execute
          </button>
        </div>
      </div>
    </div>
  );
}