import*as Common from"../common/common.js";import*as Platform from"../platform/platform.js";import*as SDK from"../sdk/sdk.js";import*as Workspace from"../workspace/workspace.js";export function resourceForURL(e){for(const r of SDK.SDKModel.TargetManager.instance().models(SDK.ResourceTreeModel.ResourceTreeModel)){const o=r.resourceForURL(e);if(o)return o}return null}export function displayNameForURL(e){if(!e)return"";const r=resourceForURL(e);if(r)return r.displayName;const o=Workspace.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e);if(o)return o.displayName();const t=SDK.SDKModel.TargetManager.instance().mainTarget(),n=t&&t.inspectedURL();if(!n)return Platform.StringUtilities.trimURL(e,"");const s=Common.ParsedURL.ParsedURL.fromString(n);if(!s)return e;const a=s.lastPathComponent,i=n.indexOf(a);if(-1!==i&&i+a.length===n.length){const r=n.substring(0,i);if(e.startsWith(r))return e.substring(i)}const c=Platform.StringUtilities.trimURL(e,s.host);return"/"===c?s.host+"/":c}export function metadataForURL(e,r,o){const t=e.model(SDK.ResourceTreeModel.ResourceTreeModel);if(!t)return null;const n=t.frameForId(r);return n?resourceMetadata(n.resourceForURL(o)):null}export function resourceMetadata(e){return!e||"number"!==typeof e.contentSize()&&!e.lastModified()?null:new Workspace.UISourceCode.UISourceCodeMetadata(e.lastModified(),e.contentSize())}