1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4import {FocusEvent} from '../events.mjs';
5import {ExpandableText} from '../helper.mjs';
6import {DOM, V8CustomElement} from '../helper.mjs';
7
8DOM.defineCustomElement(
9    './view/map-panel/map-details',
10    (templateText) => class MapDetails extends V8CustomElement {
11      _map;
12
13      constructor() {
14        super(templateText);
15      }
16
17      get _mapDetails() {
18        return this.$('#mapDetails');
19      }
20
21      get _mapProperties() {
22        return this.$('#mapProperties');
23      }
24
25      set map(map) {
26        if (this._map === map) return;
27        this._map = map;
28        this.requestUpdate();
29      }
30
31      _update() {
32        this._mapProperties.innerText = '';
33        if (this._map) {
34          let clickableDetailsTable = DOM.table('properties');
35
36          {
37            const row = clickableDetailsTable.insertRow();
38            row.insertCell().innerText = 'ID';
39            row.insertCell().innerText = `${this._map.id}`;
40          }
41          {
42            const row = clickableDetailsTable.insertRow();
43            row.insertCell().innerText = 'Source location';
44            const sourceLocation = row.insertCell();
45            new ExpandableText(sourceLocation, `${this._map.sourcePosition}`);
46            sourceLocation.className = 'clickable';
47            sourceLocation.onclick = e => this._handleSourcePositionClick(e);
48          }
49
50          this._mapProperties.appendChild(clickableDetailsTable);
51          this._mapDetails.innerText = this._map.description;
52        } else {
53          this._mapDetails.innerText = '';
54        }
55      }
56
57      _handleSourcePositionClick(event) {
58        this.dispatchEvent(new FocusEvent(this._map.sourcePosition));
59      }
60    });
61