import*as Common from"../common/common.js";import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";const UIStrings={showInternalLayers:"Show internal layers"},str_=i18n.i18n.registerUIStrings("layer_viewer/LayerViewHost.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class LayerView{}export class Selection{constructor(e,t){this._type=e,this._layer=t}static isEqual(e,t){return e&&t?e._isEqual(t):e===t}type(){return this._type}layer(){return this._layer}_isEqual(e){return!1}}export class LayerSelection extends Selection{constructor(e){console.assert(Boolean(e),"LayerSelection with empty layer"),super("Layer",e)}_isEqual(e){return"Layer"===e._type&&e.layer().id()===this.layer().id()}}export class ScrollRectSelection extends Selection{constructor(e,t){super("ScrollRect",e),this.scrollRectIndex=t}_isEqual(e){return"ScrollRect"===e._type&&this.layer().id()===e.layer().id()&&this.scrollRectIndex===e.scrollRectIndex}}export class SnapshotSelection extends Selection{constructor(e,t){super("Snapshot",e),this._snapshot=t}_isEqual(e){return"Snapshot"===e._type&&this.layer().id()===e.layer().id()&&this._snapshot===e._snapshot}snapshot(){return this._snapshot}}export class LayerViewHost{constructor(){this._views=[],this._selectedObject=null,this._hoveredObject=null,this._showInternalLayersSetting=Common.Settings.Settings.instance().createSetting("layersShowInternalLayers",!1),this._snapshotLayers=new Map}registerView(e){this._views.push(e)}setLayerSnapshotMap(e){this._snapshotLayers=e}getLayerSnapshotMap(){return this._snapshotLayers}setLayerTree(e){if(!e)return;this._target=e.target();const t=this._selectedObject&&this._selectedObject.layer();!t||e&&e.layerById(t.id())||this.selectObject(null);const s=this._hoveredObject&&this._hoveredObject.layer();!s||e&&e.layerById(s.id())||this.hoverObject(null);for(const r of this._views)r.setLayerTree(e)}hoverObject(e){if(Selection.isEqual(this._hoveredObject,e))return;this._hoveredObject=e;const t=e&&e.layer();this._toggleNodeHighlight(t?t.nodeForSelfOrAncestor():null);for(const s of this._views)s.hoverObject(e)}selectObject(e){if(!Selection.isEqual(this._selectedObject,e)){this._selectedObject=e;for(const t of this._views)t.selectObject(e)}}selection(){return this._selectedObject}showContextMenu(e,t){e.defaultSection().appendCheckboxItem(i18nString(UIStrings.showInternalLayers),this._toggleShowInternalLayers.bind(this),this._showInternalLayersSetting.get());const s=t&&t.layer()&&t.layer().nodeForSelfOrAncestor();s&&e.appendApplicableItems(s),e.show()}showInternalLayersSetting(){return this._showInternalLayersSetting}_toggleShowInternalLayers(){this._showInternalLayersSetting.set(!this._showInternalLayersSetting.get())}_toggleNodeHighlight(e){e?e.highlightForTwoSeconds():SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight()}}