<#macro showRubrics>
	<#assign currentRubrics = propertyGroups.pullProperty("https://iph.ras.ru/relationships#belongsTo")!>
	<#if currentRubrics?? && currentRubrics?has_content>
	   <div class="label collapsible">${i18n().metadata_relates_to_rubrics} <@p.addLink currentRubrics editable /> <@p.verboseDisplay currentRubrics /></div>
	    <#if rubrics?? && rubrics?has_content>
	     <#list rubrics as rubric>
	       <li role="listitem" style="list-style:none;">
	        <a href="${urls.base}/individual?uri=${rubric.rubricID?url}">${rubric.rubricName}</a>
	       </li>
	     </#list>
	    </#if>
	   <br/>
	</#if>
</#macro>

<#macro showIssue>
  <#assign issue = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#issue")!>
  <#if issue.statements?has_content && issue.type == "data">
    <div class="issue" style="list-style:none;">
      <div class="label">${i18n().metadata_relates_to_issue}</div>
        <@p.dataPropertyList issue editable />
      </div>
  </#if>
</#macro>

<#macro showYear>
  <#assign year = propertyGroups.pullProperty("https://litvinovg.pro/text_structures#year")!>
  <#if year.statements?has_content && year.type == "data">
    <div class="year" style="list-style:none;">
      <div class="label">${i18n().metadata_year}</div>
        <@p.dataPropertyList year editable />
      </div>
  </#if>
</#macro>

<#macro documentRubrics >
	<#assign docRubrics = propertyGroups.pullProperty("https://iph.ras.ru/relationships#belongsTo")!>
	<#if ( docRubrics?? && docRubrics?has_content ) || (rubrics?? && rubrics?has_content)>
	   <div class="<#if rubrics?? && rubrics?has_content>collapsible collapsed</#if>" ><div class="collapsibleLink" style="display:inline;">${i18n().metadata_relates_to_rubrics}</div> 
	     <#if docRubrics?? && docRubrics?has_content >
	       <@p.addLink docRubrics editable /> <@p.verboseDisplay docRubrics /><br/>
	     </#if> 
	   </div>  
	</#if>
	<#if rubrics?? && rubrics?has_content>
	  <div class="expandedContent autoMetadataExpand" style="display:none;">
	    <#list rubrics as rubric>
	      <li role="listitem" style="list-style:none;">
	        <a href="${urls.base}/individual?uri=${rubric.rubricID?url}"">${rubric.rubricName}</a>
	      </li>
	    </#list>
	  </div>
	</#if>
</#macro>
 
<#macro arrangeDocumentParts >
	<div id="complexDocument" class="complexDocument articleParts" style="display:block;">
	<#assign lastLevel = 0 >
	 <#list paths as order>
	   <#-- ${order.path} -->
	   <#list excerpts as excerptProperties>
	     <#if order.elenphExcerpt?has_content &&  excerptProperties.elenphExcerpt == order.elenphExcerpt>
	        <#assign excerptText = excerptProperties.htmlContent >
	        <#assign excerptTextName = excerptProperties.htmlLabel >
	        <#assign worksCounter = excerptProperties.worksCounter >
	        <#assign bibliographyCounter = excerptProperties.bibliographyCounter >
	     </#if>
	   </#list>
   	    <@startDocumentPart order.level?number order.path lastLevel/>
	    <#if excerptText?? && excerptTextName?? && excerptTextName?has_content && excerptText?has_content>  
	      <div class="htmlExcerpt" style="list-style:none;">
	        ${excerptText}
	      </div>
	        <@arrangeSources works worksCounter?number order.path order.elenphExcerpt />
	     	<@arrangeLiterature bibliography bibliographyCounter?number order.path order.elenphExcerpt />
	    </#if> 
	   <#assign lastLevel = order.level?number >
	 </#list>
	 <@endDocumentPart lastLevel  />
	 <@arrangeSources works works?size "anchor-all-sources" />
	 <@arrangeLiterature bibliography bibliography?size "anchor-all-literature" />
	</div>
	
</#macro>

<#macro startDocumentPart newLevel path lastLevel=0 >
	<#assign depth = newLevel - lastLevel >
	<#if depth == 0>
	  <@closeDocPart 1 />
	  <@openDocPart 1 path />
	<#elseif depth &gt; 0>
	  <@openDocPart depth path />
	<#else >
	  <@closeDocPart -depth+1 />
	  <@openDocPart 1 path />
	</#if>
</#macro>

<#macro endDocumentPart lastLevel newLevel=0>
	<#assign depth = lastLevel - newLevel >
	<#if depth &gt; 0>
		<@closeDocPart depth />
	</#if>
</#macro>

<#macro closeDocPart count>
  <#list 1..count as x>
	</div>    
  </#list>
</#macro>

<#macro openDocPart count path >
  <#if excerptTextName??>
   	<#assign buttonText = excerptTextName >
  <#else>
    <#assign buttonText = "No text" >
  </#if>
  <#list 1..count as x>
    <button type="button" style="border:none;width: 100%; text-align:left;" class="collapsible">${buttonText}</button>
	<div class="documentPart autoExpand articleExcerpt" id="anchor-${path}" style="display:block;">
  </#list>
</#macro>

<#macro arrangeSources sources counter identifier filter="none">
	<#if sources?? && sources?has_content && counter &gt; 0>
      <@compress single_line=true>
	  <button type="button" class="collapsible" style="border: none; color: #8B4513;width: 100%;text-align:left; background-color: #ffffff; background-image: url(${urls.base}/themes/iph/images/book_icon.png); background-repeat: no-repeat; background-position: left center;">
		  <#if filter="none">
		  	${i18n().sources_all_button_text}
		  <#else>
		  	${i18n().sources_excerpt_button_text}
		  </#if>
	  </button>
	  </@compress>
	    <div class="autoExpand documentPart works" id="anchor-${identifier}-sources" style="display:block;">
	      <#assign lastSource = ""/>
	      <#list sources as source>
	        <#if filter == "none" && lastSource != source.works || source.excerpt == filter >
	          <#assign lastSource = source.works/>
	          <div class="work" style="display:list-item;list-style-image:url(${urls.base}/themes/iph/images/bullet_icon.png); font-style: italic; font-family: PT Serif;">
	            <p> ${source.works} </p>
	          </div>
	        </#if>
	      </#list>
	    </div>
	</#if>
</#macro>

<#macro arrangeLiterature literature counter identifier filter="none">

	<#if literature?? && literature?has_content && counter &gt; 0>
	  <@compress single_line=true>
	  <button type="button" class="collapsible" style="border:none; color: #8B4513;width: 100%; text-align: left; background-color: #ffffff; background-image: url(${urls.base}/themes/iph/images/book_icon.png); background-repeat: no-repeat; background-position: left center;">
	  <#if filter="none">
	  	${i18n().literature_all_button_text}
	  <#else>
	  	${i18n().literature_excerpt_button_text}
	  </#if>
	  </button>
	  </@compress>
	    <div class="autoExpand documentPart bibliography" id="anchor-${identifier}-literature" style="display:block;">
	      <#assign lastLiterature = ""/>
	      <#list literature as literatureItem>
   	        <#if filter == "none" && lastLiterature != literatureItem.bibliography  || literatureItem.excerpt == filter >
	          <#assign lastLiterature = literatureItem.bibliography/>
			  <div class="bibliography_entry" style="display:list-item;list-style-image:url(${urls.base}/themes/iph/images/bullet_icon.png); font-style: italic; font-family: PT Serif;">
	            <p> ${literatureItem.bibliography} </p>
	          </div>
	        </#if>
	      </#list>
	    </div>
	</#if>
</#macro>


<#macro authors_metadata>
  <#if authors?? && authors?has_content>
    <div class="collapsible collapsed">
  	  <div class="collapsibleLink" style="display:inline;">${i18n().metadata_authors}</div>	
 	</div>  
	 <div class="expandedAuthors autoMetadataExpand" style="display:none;">
	  <#list authors as author>   
	      <div class="affilation">
	       	<b><#if author.authorFamily??>${author.authorFamily}&nbsp;</#if><#if author.authorGivenName??>${author.authorGivenName}</#if></b>  
	        <#if author.orgName??>
	          <span class="authorOrgName">${author.orgName}</span>
	        </#if>
	        <#if author.orgAddress??>
	          <br>
	          <span class="authorOrgAdress">${i18n().metadata_org_address}<#if author.orgPostalCode??>${author.orgPostalCode},&nbsp;</#if>${author.orgAddress}&nbsp;</span>
	          <br>
	        </#if>
		  </div>
	  </#list>
	 </div> 
   </#if>	  			
</#macro>


<#macro authors_underline>
	<#if authors?? && authors?has_content>
	  <div class="authors" style="display:block;float:right; margin:15px;">
	    <#list authors as author>
	      <#if author.authorFamily??>${author.authorFamily?trim}<#if author.authorInitials??>&nbsp;${author.authorInitials?trim}</#if></#if><#sep>, </#sep>
	    </#list>
	  </div>
	</#if>
</#macro>

<#macro expandMetadataSwitch>
    <div class="expandSwitch">
      <label class="switch">
        <div class="expandTextControl">${i18n().expand_metadata_switch}<img src="${urls.base}/themes/iph/images/arrow-down.svg"/></div>
        <div class="collapseTextControl">${i18n().collapse_metadata_switch}<img src="${urls.base}/themes/iph/images/arrow-top.svg"/></div>
        <input id="metadataExpandCB" type="checkbox" onclick="switchExpand('metadataExpandCB','.autoMetadataExpand');">
      </label>
    </div>
</#macro>

<#macro expandSwitch>
	<div class="expandSwitch">
	  <label class="switch">
	    <div class="expandTextControl">${i18n().expand_doc_switch}<img src="${urls.base}/themes/iph/images/arrow-down.svg"/></div>
	    <div class="collapseTextControl">${i18n().collapse_doc_switch}<img src="${urls.base}/themes/iph/images/arrow-top.svg"/></div>
	    <input id="expandCB" type="checkbox" onclick="switchExpand('expandCB','.autoExpand');">
	  </label>
	</div>
</#macro>

<#macro userSettingsModal>
 	<button id="userViewSettings">
	  <img onclick="javascript:showUserSettingsModal();" src="${urls.base}/themes/iph/images/settings.svg">
	</button>
	<div id="userSettingsModal" class="modal" style="display:none;">
	  <div class="modal-content">
	  	<div class="modalWrapper">
		  <div id="titleSettings">${i18n().user_settings_label}</div>
		  <span id="closeModalWindow">&times;</span>
		</div>
		<label>
		  <div>${i18n().user_settings_always_open_full_doc}</div>
          <input id="expandSettingsCB" type="checkbox" onclick="switchExpandSettings('expandSettingsCB','switchExpand');">
		</label>
		<label>
		  <div>${i18n().user_settings_always_open_metadata}</div>
          <input id="metadataExpandSettingsCB" type="checkbox" onclick="switchExpandSettings('metadataExpandSettingsCB','metadataExpandSetting');">
        </label>
      </div>
    </div>
				
</#macro>



