##################################
##          SPACE MENU
##################################s
#set ($isAdminAppInstalled = $xwiki.exists('XWiki.AdminSheet'))
#set ($displaySpaceSubmenu = $hasWatch || $hasSpaceAdmin || $xwiki.exists('Main.SpaceIndex'))
#xwikitopmenuseparator()
#set($spaceURL = $xwiki.getURL($services.model.resolveDocument('', 'default', $doc.documentReference.extractReference('SPACE'))))
#if (!$displaySpaceSubmenu)
  #xwikitopmenuentry($spaceURL "$services.localization.render('core.menu.type.space')__SEPARATOR__$!{escapetool.xml($doc.space)}" 'tmSpace' '' 'folder-open')
#else
  #xwikitopmenuentrystart($spaceURL "$services.localization.render('core.menu.type.space')__SEPARATOR__$!{escapetool.xml($doc.space)}" 'tmSpace' '' 'folder-open')
    ## GO TO
    #submenuitem($spaceURL $services.localization.render('core.menu.goto.space') '', '', 'arrow-right')
    ## WATCH / UNWATCH
    #if ($hasWatch)
      #set ($watchClasses = '')
      #set ($unwatchClasses = 'hidden')
      #if ($xwiki.watchlist.isSpaceWatched())
        #set ($watchClasses = 'hidden')
        #set ($unwatchClasses = '')
      #end
      #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=addspace')&amp;xredirect=$escapetool.url($doc.getURL())" $services.localization.render('core.menu.watchlist.add.space') 'tmWatchSpace', $watchClasses, 'eye-open')
      #submenuitem("$doc.getURL('view', 'xpage=watch&amp;do=removespace')&amp;xredirect=$escapetool.url($doc.getURL())" $services.localization.render('core.menu.watchlist.remove.space') 'tmUnwatchSpace', $unwatchClasses, 'eye-close')
    #end
    ## ADMIN
    #if ($hasSpaceAdmin && $isAdminAppInstalled)
      #set ($spaceAdminDocRef = $services.model.createDocumentReference($doc.wiki, $doc.space, 'WebPreferences'))
      #set ($adminspaceaction = $xwiki.getURL($spaceAdminDocRef, 'admin'))
      #submenuitem($adminspaceaction $services.localization.render('core.menu.admin.space', [$escapetool.xml($doc.space)]) 'tmAdminSpace', '', 'wrench')
      #set ($hasPreviousMenuSection = true)
    #end
    ## DOCUMENT INDEX
    #if ($xwiki.exists('Main.SpaceIndex'))
      #submenuseparator()
      #set ($spaceIndexUrl = $xwiki.getURL('Main.SpaceIndex', 'view',"space=${escapetool.url($doc.space)}"))
      #submenuitem($spaceIndexUrl $services.localization.render('core.menu.space.documentindex') 'tmSpaceDocumentIndex' '' 'book')
      #set ($hasPreviousMenuSection = true)
    #end
    ## DELETE
    #if ($hasSpaceAdmin)
      #if ($hasPreviousMenuSection)
        #submenuseparator()
      #end
      #set ($spaceDeleteUrl = $!xwiki.getURL($services.model.resolveDocument('', 'default', $doc.documentReference.extractReference('SPACE')), 'deletespace'))
      #submenuitem($spaceDeleteUrl $services.localization.render('core.menu.space.delete') 'tmSpaceDelete' '' 'remove')
      #set ($hasPreviousMenuSection = true)
    #end
  #xwikitopmenuentryend()
#end
