import*as Common from"../common/common.js";import*as Components from"../components/components.js";import*as i18n from"../i18n/i18n.js";import*as Platform from"../platform/platform.js";import*as UI from"../ui/ui.js";import*as Workspace from"../workspace/workspace.js";import{FileSystemWorkspaceBinding}from"./FileSystemWorkspaceBinding.js";import{NetworkPersistenceManager}from"./NetworkPersistenceManager.js";import{Events,PersistenceImpl}from"./PersistenceImpl.js";const UIStrings={linkedToSourceMapS:"Linked to source map: {PH1}",linkedToS:"Linked to {PH1}"},str_=i18n.i18n.registerUIStrings("persistence/PersistenceUtils.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class PersistenceUtils{static tooltipForUISourceCode(e){const t=PersistenceImpl.instance().binding(e);return t?e===t.network?FileSystemWorkspaceBinding.tooltipForUISourceCode(t.fileSystem):t.network.contentType().isFromSourceMap()?i18nString(UIStrings.linkedToSourceMapS,{PH1:Platform.StringUtilities.trimMiddle(t.network.url(),150)}):i18nString(UIStrings.linkedToS,{PH1:Platform.StringUtilities.trimMiddle(t.network.url(),150)}):""}static iconForUISourceCode(e){const t=PersistenceImpl.instance().binding(e);if(t){if(!t.fileSystem.url().startsWith("file://"))return null;const e=UI.Icon.Icon.create("mediumicon-file-sync");return UI.Tooltip.Tooltip.install(e,PersistenceUtils.tooltipForUISourceCode(t.network)),NetworkPersistenceManager.instance().project()===t.fileSystem.project()&&(e.style.filter="hue-rotate(160deg)"),e}if(e.project().type()!==Workspace.Workspace.projectTypes.FileSystem||!e.url().startsWith("file://"))return null;const i=UI.Icon.Icon.create("mediumicon-file");return UI.Tooltip.Tooltip.install(i,PersistenceUtils.tooltipForUISourceCode(e)),i}}export class LinkDecorator extends Common.ObjectWrapper.ObjectWrapper{constructor(e){super(),e.addEventListener(Events.BindingCreated,this._bindingChanged,this),e.addEventListener(Events.BindingRemoved,this._bindingChanged,this)}_bindingChanged(e){const t=e.data;this.dispatchEventToListeners(Components.Linkifier.LinkDecorator.Events.LinkIconChanged,t.network)}linkIcon(e){return PersistenceUtils.iconForUISourceCode(e)}}