File size: 5,725 Bytes
f1c3c6d
 
 
 
 
 
 
 
 
 
1e24842
 
 
 
f1c3c6d
 
1e24842
 
f1c3c6d
 
 
 
 
 
1e24842
 
 
f1c3c6d
1e24842
f1c3c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e24842
f1c3c6d
1e24842
f1c3c6d
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React, { useState } from 'react';
import { Layers, X, Code, KeyRound } from 'lucide-react';

export default function SelectionModal({ selectionPrompt, onSelect, onConfirm, onCancel }) {
  const [inputValues, setInputValues] = useState({});

  const type = selectionPrompt.type || 'selection';
  const missingKeys = selectionPrompt.missingKeys || [];

  const allFilled = missingKeys.every(k => inputValues[k]?.trim());

  return (
    <div style={{ position: 'fixed', inset: 0, zIndex: 50, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'rgba(0,0,0,0.7)', backdropFilter: 'blur(8px)', padding: 16 }}>
      <div style={{ background: 'var(--bg-1)', border: '1px solid var(--line-3)', borderRadius: 10, width: '100%', maxWidth: 480, maxHeight: '80vh', overflow: 'hidden', display: 'flex', flexDirection: 'column', boxShadow: 'var(--shadow-md)' }}>

        {/* Header */}
        <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 }}>
            {type === 'manual_input'
              ? <KeyRound size={14} style={{ color: 'var(--accent)' }}/>
              : <Layers size={14} style={{ color: 'var(--accent)' }}/>}
            <span style={{ fontSize: 13, fontWeight: 600, color: 'var(--fg-0)' }}>
              {type === 'manual_input' ? 'Provide Missing IDs' : 'Choose an Option'}
            </span>
          </div>
          <button onClick={onCancel} className="ico-btn"><X size={14}/></button>
        </div>

        <div style={{ padding: 20, overflowY: 'auto' }}>

          {/* ── Manual input mode ── */}
          {type === 'manual_input' && (
            <>
              <p style={{ fontSize: 12, color: 'var(--fg-2)', marginBottom: 16, lineHeight: 1.6 }}>
                This step requires real IDs that could not be determined automatically.
                Enter the correct values from your system or database.
              </p>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginBottom: 20 }}>
                {missingKeys.map(key => (
                  <div key={key}>
                    <label style={{ display: 'block', fontSize: 11, fontWeight: 600, color: 'var(--fg-2)', marginBottom: 5, textTransform: 'uppercase', letterSpacing: '0.06em' }}>
                      {key}
                    </label>
                    <input
                      type="text"
                      className="input"
                      placeholder={`Enter real value for ${key}`}
                      value={inputValues[key] || ''}
                      onChange={e => setInputValues(prev => ({ ...prev, [key]: e.target.value }))}
                      style={{ width: '100%', boxSizing: 'border-box' }}
                    />
                  </div>
                ))}
              </div>
              <div style={{ display: 'flex', gap: 8 }}>
                <button
                  className="btn-primary"
                  disabled={!allFilled}
                  onClick={() => onConfirm(inputValues)}
                  style={{ flex: 1, justifyContent: 'center', opacity: allFilled ? 1 : 0.45 }}
                >
                  Save &amp; Execute
                </button>
                <button onClick={onCancel} className="btn" style={{ flex: 1, justifyContent: 'center' }}>
                  Cancel
                </button>
              </div>
            </>
          )}

          {/* ── Selection mode (existing behaviour) ── */}
          {type === 'selection' && (
            <>
              <p style={{ fontSize: 12, color: 'var(--fg-2)', marginBottom: 14, lineHeight: 1.6 }}>
                Select one to save as <code style={{ color: 'var(--accent)' }}>{selectionPrompt.fieldName}</code>.
              </p>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 6, marginBottom: 14 }}>
                {(selectionPrompt.options || []).map((opt, idx) => (
                  <button
                    key={idx}
                    onClick={() => onSelect(opt)}
                    className="col-card"
                    style={{ textAlign: 'left', padding: '10px 14px', borderRadius: 6, cursor: 'pointer' }}
                  >
                    <div style={{ fontSize: 13, color: 'var(--fg-0)', fontWeight: 500, marginBottom: 2 }}>{opt.label || 'Option'}</div>
                    <div style={{ fontSize: 10.5, color: 'var(--fg-3)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
                      {typeof opt.value === 'object' ? JSON.stringify(opt.value) : String(opt.value)}
                    </div>
                  </button>
                ))}
              </div>
              {selectionPrompt.responseBody && (
                <details style={{ cursor: 'pointer' }}>
                  <summary style={{ fontSize: 11, color: 'var(--fg-3)', display: 'flex', alignItems: 'center', gap: 6, marginBottom: 6 }}>
                    <Code size={12}/> Raw response
                  </summary>
                  <pre className="code" style={{ maxHeight: 160 }}>
                    {(() => { try { return JSON.stringify(JSON.parse(selectionPrompt.responseBody), null, 2); } catch { return selectionPrompt.responseBody; } })()}
                  </pre>
                </details>
              )}
              <button onClick={onCancel} className="btn" style={{ width: '100%', justifyContent: 'center', marginTop: 8 }}>
                Cancel
              </button>
            </>
          )}

        </div>
      </div>
    </div>
  );
}