File size: 2,230 Bytes
f6213fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
export function buildRecommendationBody(payload, onApply) {
  const container = SF.el('div', { className: 'deliveries-modal-list' });
  if (!payload.candidates.length) {
    container.appendChild(SF.el('div', { className: 'deliveries-empty' }, 'No valid insertions.'));
    return container;
  }

  payload.candidates.forEach((candidate) => {
    const row = SF.el('div', { className: 'deliveries-list__row' });
    const top = SF.el('div', { className: 'deliveries-list__top' });
    top.appendChild(SF.el('strong', null, `${candidate.vehicleName} · position ${candidate.insertIndex + 1}`));
    top.appendChild(SF.el('span', { className: 'deliveries-tag' }, candidate.score));
    row.appendChild(top);

    const meta = SF.el('div', { className: 'deliveries-list__meta' });
    meta.appendChild(SF.el('span', null, `Δ hard ${candidate.deltaHard}`));
    meta.appendChild(SF.el('span', null, `Δ soft ${candidate.deltaSoft}`));
    row.appendChild(meta);

    const applyButton = SF.createButton({ text: 'Apply', variant: 'success' });
    applyButton.addEventListener('click', () => onApply(candidate.previewPlan));
    row.appendChild(SF.el('div', { className: 'deliveries-list__actions' }, applyButton));
    container.appendChild(row);
  });

  return container;
}

export function buildAnalysisBody(analysis) {
  const container = SF.el('div');
  container.appendChild(SF.el('p', null, `Score: ${analysis.analysis.score}`));
  const table = SF.el('table', { className: 'deliveries-table' });
  table.appendChild(
    SF.el(
      'thead',
      null,
      SF.el(
        'tr',
        null,
        SF.el('th', null, 'Constraint'),
        SF.el('th', null, 'Weight'),
        SF.el('th', null, 'Score'),
        SF.el('th', null, 'Matches'),
      ),
    ),
  );
  const body = SF.el('tbody');
  (analysis.analysis.constraints || []).forEach((constraint) => {
    body.appendChild(
      SF.el(
        'tr',
        null,
        SF.el('td', null, constraint.name),
        SF.el('td', null, constraint.weight),
        SF.el('td', null, constraint.score),
        SF.el('td', null, String(constraint.matchCount)),
      ),
    );
  });
  table.appendChild(body);
  container.appendChild(table);
  return container;
}