<?xml version="1.0" encoding="utf-8"?>
<rules xmlns="http://namespaces.plone.org/diazo"
       xmlns:css="http://namespaces.plone.org/diazo/css"
       xmlns:xhtml="http://www.w3.org/1999/xhtml"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:xi="http://www.w3.org/2001/XInclude">

  <!-- <xi:include href="++theme++barceloneta/grid-col-marker.xml"/> -->

  <theme href="index.html" />
  <notheme css:if-not-content="#visual-portal-wrapper" />
  <notheme css:if-content=".template-manage-viewlets" />

  <rules css:if-content="#portal-top">
    <!-- Attributes -->
    <copy attributes="*" css:theme="html" css:content="html" />
    <!-- Base tag -->
    <before css:theme="title" css:content="base" />
    <!-- Title -->
    <replace css:theme="head title" css:content="head title" />
    <!-- Pull in Plone Meta -->
    <after css:theme-children="head" css:content="head meta" />
    <!-- Don't use Plone icons, use the theme's -->
    <drop css:content="head link[rel='apple-touch-icon']" />
    <!-- CSS -->
    <after css:theme-children="head" css:content="head link" />
    <after css:theme-children="head" css:content="head style" />
    <!-- Script -->
    <after css:theme-children="head" css:content="head script" />
  </rules>

  <!-- Copy over the id/class attributes on the body tag. This is important for per-section styling -->
  <copy attributes="*" css:content="body" css:theme="body" />
  <merge attributes="class" css:content="body" css:theme="body" />

  <!-- move global nav and livesearch -->
  <replace css:theme-children="#portal-globalnav" css:content-children="#portal-globalnav" />
  <!-- set aria-label for toggler button -->
  <copy attributes="aria-label" css:theme=".navbar-toggler" css:content=".navbar-toggler" />
  <!-- move searchbox into place -->
  <replace css:theme="#portal-searchbox" css:content="#portal-searchbox" mode="raw" />
  <drop css:content="#portal-header #portal-searchbox" />

  <!-- Content header -->
  <replace css:theme="#portal-logo" css:content="#portal-logo" mode="raw" />
   <drop css:content="#portal-logo"  />

  <replace css:theme-children="#portal-top" css:content-children="#portal-header" />

  <!-- full-width breadcrumb -->
  <replace css:theme="#above-content" css:content="#viewlet-above-content" />

  <!-- Central column -->
  <replace css:theme-children="#portal-column-content" css:content-children="#portal-column-content"></replace>

  <!-- Alert message -->
  <replace css:theme-children="#global_statusmessage" css:content-children="#global_statusmessage" />

  <!-- Left column -->
  <after css:theme-children="#portal-column-one" css:content-children="#portal-column-one"></after>
  <drop css:theme="#portal-column-one" css:if-not-content="#portal-column-one" />

  <!-- Right column -->
  <after css:theme-children="#portal-column-two" css:content-children="#portal-column-two"></after>
  <drop css:theme="#portal-column-two" css:if-not-content="#portal-column-two" />

  <!-- manage-portlets Footer portlets -->
  <after css:theme-children="#portal-footer-wrapper" css:content-children="#portal-footer-wrapper" css:if-content="#portal-footer-wrapper #portletmanager-plone-footerportlets"></after>

  <!-- Footer -->
  <xsl:variable name="footer_portlets" select="//footer[@id='portal-footer-wrapper']//div[@class='portletWrapper']/*[not(contains(@id,'portal-colophon')) and not(contains(@id,'portal-footer-signature')) and not(contains(@class,'portletActions'))]"></xsl:variable>
  <xsl:variable name="footer_portlets_count" select="count($footer_portlets)"></xsl:variable>

  <!-- Replace footer information with Plone version. -->
  <replace
      css:theme-children="#portal-footer .copyright > div"
      css:content-children="#portal-footer-wrapper #portal-footer-signature .card-body"
      />
  <drop css:theme="#portal-footer .copyright" css:if-not-content="#portal-footer-wrapper #portal-footer-signature" />

  <!-- Replace colophon information with Plone version. -->
  <replace
      css:theme-children="#portal-footer .colophon > div"
      css:content-children="#portal-footer-wrapper #portal-colophon .card-body"
      />
  <drop css:theme="#portal-footer .colophon" css:if-not-content="#portal-footer-wrapper #portal-colophon" />

  <!-- Replace site-actions with Plone version. -->
  <replace
      css:theme-children="#portal-footer .site-actions > div"
      css:content="#portal-footer-wrapper .actions-site_actions"
      />
  <drop css:theme="#portal-footer .site-actions" css:if-not-content="#portal-footer-wrapper .actions-site_actions" />

  <!-- Move all other footer portlets into doormat area. -->
  <replace css:theme-children="#portal-footer .doormat">
    <xsl:variable name="columns">
      <xsl:if test="$footer_portlets_count=1">col-md-12</xsl:if>
      <xsl:if test="$footer_portlets_count=2">col-md-6</xsl:if>
      <xsl:if test="$footer_portlets_count=3">col-md-4</xsl:if>
      <xsl:if test="$footer_portlets_count=4">col-md-3</xsl:if>
      <xsl:if test="$footer_portlets_count>4">col-md-4</xsl:if>
    </xsl:variable>
    <xsl:for-each select="$footer_portlets">
      <div class="col-xs-12 {$columns}">
        <xsl:for-each select=".">
          <xsl:choose>
            <xsl:when css:test=".card">
              <xsl:choose>
                <xsl:when css:test=".card-header:not(.titleless)">
                  <div class="headline"><h2><xsl:apply-templates select="./node()[@class='card-header']/node()" /></h2></div>
                </xsl:when>
              </xsl:choose>
              <xsl:choose>
                <xsl:when css:test=".portletCollection">
                  <ul>
                    <xsl:for-each css:select=".portletItem">
                      <li>
                        <a><xsl:copy-of select="a/attribute::*" /><xsl:apply-templates select="./a/text()" /></a>
                        <small><xsl:value-of css:select=".portletItemDetails" /></small>
                      </li>
                    </xsl:for-each>
                  </ul>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:apply-templates css:select=".card-body" />
                </xsl:otherwise>
              </xsl:choose>
              <xsl:if css:test=".card-footer">
                <p><xsl:apply-templates select="./node()[@class='card-footer']/node()" /></p>
              </xsl:if>
            </xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="./node()" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </div>
    </xsl:for-each>
  </replace>

  <!-- Add additional footer content, like script tags (from site settings). -->
  <after
      css:theme-children="html body"
      content="//footer[@id='portal-footer-wrapper']/*[not(@class='row')]"
      />

  <!-- toolbar -->
  <replace css:theme="#portal-toolbar" css:content="#edit-bar" css:if-not-content=".ajax_load" css:if-content=".userrole-authenticated" />
  <drop css:theme="#portal-toolbar" css:if-content=".userrole-anonymous" />
  <!-- <replace css:theme="#anonymous-actions" css:content-children="#portal-personaltools-wrapper" css:if-not-content=".ajax_load" css:if-content=".userrole-anonymous" /> -->

</rules>