File size: 2,361 Bytes
7f237a3
808ab9a
 
7f237a3
 
 
 
808ab9a
 
 
7f237a3
808ab9a
 
7f237a3
 
 
 
 
808ab9a
 
 
 
7f237a3
 
 
808ab9a
 
 
 
 
7f237a3
808ab9a
 
 
 
 
 
 
 
 
 
 
7f237a3
808ab9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f237a3
808ab9a
 
7f237a3
808ab9a
 
 
 
 
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
import React from 'react';
import { Activity, Play } from 'lucide-react';

export default function SensorInputForm({
  sensors, channel, value, onChannelChange, onValueChange,
  pending, onQueue, onRun, running,
}) {
  const handleQueue = (e) => {
    e.preventDefault();
    if (!channel || value === '') return;
    onQueue();
  };

  const canRun = !running && (pending.length > 0 || (channel && value !== ''));
  const runLabel = pending.length > 0
    ? `Run Simulation (${pending.length} queued)`
    : 'Run Simulation';

  return (
    <div className="decidron-panel">
      <h2>Sensor Input</h2>
      <p className="panel-hint">
        A reading is pre-filled — just press <strong>Run Simulation</strong>
        to see the network react. Use <strong>Queue</strong> to stack
        several inputs before running.
      </p>
      <form onSubmit={handleQueue}>
        <div className="decidron-row">
          <div className="decidron-field" style={{ flex: 1 }}>
            <label>Channel</label>
            <select value={channel} onChange={(e) => onChannelChange(e.target.value)}>
              {sensors.map((s) => (
                <option key={s.id} value={s.id}>{s.label}</option>
              ))}
            </select>
          </div>
          <div className="decidron-field" style={{ flex: 1 }}>
            <label>Value</label>
            <input
              type="text"
              value={value}
              placeholder="e.g. 97"
              onChange={(e) => onValueChange(e.target.value)}
            />
          </div>
          <button type="submit" className="decidron-btn secondary">
            <Activity size={14} style={{ marginRight: 4, verticalAlign: 'middle' }} />
            Queue
          </button>
        </div>
      </form>

      {pending.length > 0 && (
        <ul className="decidron-pending">
          {pending.map((p, i) => (
            <li key={i}>{p.channel}: {p.value}</li>
          ))}
        </ul>
      )}

      <div className="decidron-row" style={{ marginTop: '0.5rem' }}>
        <button
          type="button"
          className="decidron-btn"
          onClick={onRun}
          disabled={!canRun}
        >
          <Play size={14} style={{ marginRight: 4, verticalAlign: 'middle' }} />
          {running ? 'Running…' : runLabel}
        </button>
      </div>
    </div>
  );
}