import { PublicAppInfo , AppNavLinkStatus , AppStatus , PublicAppDeepLinkInfo , } from '../../application' ; import { IBasePath } from '../../http' ; import { NavLinkWrapper } from './nav_link' ; import { appendAppPath } from '../../application/utils' ; export function toNavLink ( app , basePath , deepLink ? ) { const relativeBaseUrl = basePath . prepend ( app . appRoute ! ) ; const url = appendAppPath ( relativeBaseUrl , deepLink ?. path || app . defaultPath ) ; const href = relativeToAbsolute ( url ) ; const baseUrl = relativeToAbsolute ( relativeBaseUrl ) ; return new NavLinkWrapper ( { ... ( deepLink || app ) , ... ( app . category ? { category : app . category } : { } ) , hidden : deepLink ? isDeepNavLinkHidden ( deepLink ) : isAppNavLinkHidden ( app ) , disabled : ( deepLink ?. navLinkStatus ?? app . navLinkStatus ) === AppNavLinkStatus . disabled , baseUrl , href , url , } ) ; } function isAppNavLinkHidden ( app ) { return app . navLinkStatus === AppNavLinkStatus . default ? app . status === AppStatus . inaccessible : app . navLinkStatus === AppNavLinkStatus . hidden ; } function isDeepNavLinkHidden ( deepLink ) { return ( deepLink . navLinkStatus === AppNavLinkStatus . default || deepLink . navLinkStatus === AppNavLinkStatus . hidden ) ; } param { string } url return { string } export function relativeToAbsolute ( url ) { const a = document . createElement ( 'a' ) ; a . setAttribute ( 'href' , url ) ; return a . href ; }