11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ciimport {FocusEvent} from '../events.mjs';
51cb0ef41Sopenharmony_ciimport {ExpandableText} from '../helper.mjs';
61cb0ef41Sopenharmony_ciimport {DOM, V8CustomElement} from '../helper.mjs';
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciDOM.defineCustomElement(
91cb0ef41Sopenharmony_ci    './view/map-panel/map-details',
101cb0ef41Sopenharmony_ci    (templateText) => class MapDetails extends V8CustomElement {
111cb0ef41Sopenharmony_ci      _map;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci      constructor() {
141cb0ef41Sopenharmony_ci        super(templateText);
151cb0ef41Sopenharmony_ci      }
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci      get _mapDetails() {
181cb0ef41Sopenharmony_ci        return this.$('#mapDetails');
191cb0ef41Sopenharmony_ci      }
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci      get _mapProperties() {
221cb0ef41Sopenharmony_ci        return this.$('#mapProperties');
231cb0ef41Sopenharmony_ci      }
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci      set map(map) {
261cb0ef41Sopenharmony_ci        if (this._map === map) return;
271cb0ef41Sopenharmony_ci        this._map = map;
281cb0ef41Sopenharmony_ci        this.requestUpdate();
291cb0ef41Sopenharmony_ci      }
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci      _update() {
321cb0ef41Sopenharmony_ci        this._mapProperties.innerText = '';
331cb0ef41Sopenharmony_ci        if (this._map) {
341cb0ef41Sopenharmony_ci          let clickableDetailsTable = DOM.table('properties');
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci          {
371cb0ef41Sopenharmony_ci            const row = clickableDetailsTable.insertRow();
381cb0ef41Sopenharmony_ci            row.insertCell().innerText = 'ID';
391cb0ef41Sopenharmony_ci            row.insertCell().innerText = `${this._map.id}`;
401cb0ef41Sopenharmony_ci          }
411cb0ef41Sopenharmony_ci          {
421cb0ef41Sopenharmony_ci            const row = clickableDetailsTable.insertRow();
431cb0ef41Sopenharmony_ci            row.insertCell().innerText = 'Source location';
441cb0ef41Sopenharmony_ci            const sourceLocation = row.insertCell();
451cb0ef41Sopenharmony_ci            new ExpandableText(sourceLocation, `${this._map.sourcePosition}`);
461cb0ef41Sopenharmony_ci            sourceLocation.className = 'clickable';
471cb0ef41Sopenharmony_ci            sourceLocation.onclick = e => this._handleSourcePositionClick(e);
481cb0ef41Sopenharmony_ci          }
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci          this._mapProperties.appendChild(clickableDetailsTable);
511cb0ef41Sopenharmony_ci          this._mapDetails.innerText = this._map.description;
521cb0ef41Sopenharmony_ci        } else {
531cb0ef41Sopenharmony_ci          this._mapDetails.innerText = '';
541cb0ef41Sopenharmony_ci        }
551cb0ef41Sopenharmony_ci      }
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci      _handleSourcePositionClick(event) {
581cb0ef41Sopenharmony_ci        this.dispatchEvent(new FocusEvent(this._map.sourcePosition));
591cb0ef41Sopenharmony_ci      }
601cb0ef41Sopenharmony_ci    });
61