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

  <xsl:template match="//*[contains(@id, 'portal-globalnav')]/li">
     <xsl:copy>
        <xsl:attribute name="class"><xsl:if test="contains(@class,'selected')">active</xsl:if></xsl:attribute>
        <xsl:apply-templates />
     </xsl:copy>
  </xsl:template>


  <!-- The default theme, used for standard Plone web pages -->
  <theme href="search.html" css:if-content=".template-search" />
  <theme href="page.html" css:if-content="#visual-portal-wrapper" />

  <!-- Rules applying to a standard Plone web page -->

  <rules css:if-content="#visual-portal-wrapper">



    <!-- Add meta tags -->
    <drop theme="/html/head/meta[not(@name='viewport')]" />
    <after content="/html/head/meta" theme-children="/html/head" />

    <!-- Copy style, script and link tags in the order they appear in the content -->
    <after
        content="/html/head/style | /html/head/script | /html/head/link"
        theme-children="/html/head"
        />

    <drop theme="/html/head/style" />
    <drop theme="/html/head/script" />
    <drop css:theme="head link[rel='stylesheet']" />

    <!-- use plone given title -->
    <replace css:content="head title" css:theme="head title" />

    <!-- drop plone favicon and viewport -->
    <drop css:content="head link[rel='shortcut icon']" />
    <drop css:content="head meta[name='viewport']" />

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

    <!-- Logo (link target) -->
    <!--<copy attributes="href" css:content="#portal-logo" css:theme="#portal-logo" />-->
    <replace css:content="#portal-logo" css:theme="#portal-logo" />

    <!--Nav-->
    <!-- nav gets active from xsl template rewrite on top -->
    <replace css:theme-children=".navbar-nav" css:content-children="#portal-globalnav" />

    <!-- navbar search -->
    <copy attributes="action" css:content="#portal-searchbox form" css:theme=".navbar-form" />
    <copy attributes="name" css:content="#portal-searchbox form .searchField" css:theme=".navbar-form input[type='search']" />

    <!-- footer -->
    <replace
        css:content-children="#FooterPortletManager .portletStaticText:nth-child(2)"
        css:theme-children=".doormat .sitemap" />
    <replace
        css:content-children="#FooterPortletManager .portletStaticText:nth-child(3)"
        css:theme-children=".doormat .opdrachtgevers" />
    <replace
        css:content-children="#FooterPortletManager .portletStaticText:nth-child(4)"
        css:theme-children=".doormat .socialemedia" />

    <!-- footer nieuwsbrief -->
    <replace css:content-children=".portletMailChimp-Nieuwsbrief .portletHeader" css:theme-children=".doormat .nieuwsbrief .portletHeader" />
    <copy attributes="action" css:content=".portletMailChimp-Nieuwsbrief form" css:theme=".doormat .nieuwsbrief form" />
    <copy attributes="name" css:content=".portletMailChimp-Nieuwsbrief .textType" css:theme=".doormat .nieuwsbrief form input" />
    <append css:content=".portletMailChimp-Nieuwsbrief input[type=hidden]" css:theme=".doormat .nieuwsbrief form" />
    <rules css:if-content=".portletMailChimp-Nieuwsbrief dd.portletItem.odd p">
      <replace css:content=".portletMailChimp-Nieuwsbrief dd.portletItem.odd p" css:theme="#formfield-form-email" />
    </rules>

    <!-- Header / footer -->
    <!--<append css:content="#portal-personaltools-wrapper" css:theme="#portal-header" />-->
    <!--<append css:content="#portal-languageselector" css:theme="#portal-header" />-->
    <!--<append css:content="#portal-searchbox" css:theme="#portal-header" />-->
    <!--<append css:content="#portal-globalnav" css:theme="#portal-header" />-->


    <!-- Columns -->

    <rules css:if-content=".template-gov_folder_view, .template-tagnavigator_view">

      <!-- gov views are the overview pages, they need col rearrange for mobile block order -->
      <before css:theme-children="#visual-portal-wrapper > .container > .row">
        <div id="portal-column-two" class="col-md-4 col-md-push-8">
          <div class="row">
            <xsl:apply-templates css:select="#portal-column-two > *" mode="raw" />
          </div>
          <div class="endline visible-xs visible-sm"></div>
        </div>
        <div id="portal-column-content" class="col-md-8 col-md-pull-4">
          <xsl:apply-templates css:select="#portal-column-content > *" mode="raw" />
        </div>
      </before>

      <drop css:theme="#portal-column-two" />
      <drop css:theme="#portal-column-content" />

    </rules>

    <rules css:if-content=".portaltype-portlet-page">

      <!--
      <prepend css:theme="#visual-portal-wrapper">
        <div class="container">
          <xsl:copy-of css:select="#edit-bar" />
        </div>
      </prepend>

      <rules css:if-content="body[class|='edit'], body[class^='template-wmowonen-theme-portlet']">
        <prepend css:theme="#visual-portal-wrapper">
          <div class="container" id="#portal-column-content">
            <xsl:copy-of css:select="#content" />
          </div>
        </prepend>
      </rules>-->

      <drop css:content="#portletPageTopRow > div:not(.portlets-manager)" />
      <drop css:content="#portletPageSecondColumn" />
      <drop css:content="#portletPageFirstColumn" />
      <drop css:content="#portletPageBottomRow" />
      <drop css:content=".documentFirstHeading" />
      <drop css:content="#plone-document-byline" />
      <drop css:content="#parent-fieldname-description" />


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

      <drop css:theme="#visual-portal-wrapper #portal-column-two" />
      <!--<drop css:theme=".navbar" />-->

      <rules css:if-content=".section-homepage">
      <before css:theme="#visual-portal-wrapper">

        <div class="herounit"><xsl:attribute name="style">background-image:url(<xsl:value-of select="substring-before(//*[contains(@id, 'column-collective-portletpage-toprow-portlet-herounit')]//img/@src, '_preview')"/>);</xsl:attribute>

          <xsl:for-each select="//*[contains(@id, 'column-collective-portletpage-toprow-portlet-herounit')]">
            <div class="event">
              <div class="container">
                <div class="title">
                  <!--<xsl:copy-of select="//*[contains(@id, 'column-collective-portletpage-toprow-portlet-herounit')]//*[contains(@class, 'news-date')]/span/text()" />:-->
                  <xsl:copy-of select="//*[contains(@id, 'column-collective-portletpage-toprow-portlet-herounit')]//h2/text()" />
                </div>
                <div class="desc">
                  <xsl:copy-of css:select="#column-collective-portletpage-toprow-portlet-herounit .description" />
                </div>
                <div class="cta">
                  <a class="btn btn-lg btn-link"><xsl:attribute name="href"><xsl:value-of select="//*[contains(@id, 'column-collective-portletpage-toprow-portlet-herounit')]//dd/a/@href"/></xsl:attribute>
                    Lees meer <span class="fa fa-chevron-right"></span>
                  </a>
                </div>
              </div>
            </div>
          </xsl:for-each>

        </div>

      </before>
      </rules>

      <after css:theme-children="#visual-portal-wrapper">

        <xsl:for-each css:select="#portletPageTopRow > div:not(.portlets-manager)">
        <xsl:if test="not(contains(@id, 'column-collective-portletpage-toprow-portlet-herounit'))">


          <div><xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute><xsl:attribute name="class"><xsl:value-of select="div/@class"/><xsl:value-of select="div/dl/@class"/><xsl:if test="not(contains(@id, 'column-collective-portletpage-toprow-portlet-herounit'))"> portlet-position-<xsl:value-of select="position()"/></xsl:if></xsl:attribute>
            <div class="container">


              <xsl:choose>

                <xsl:when test="contains(div/dl/@class, 'portletMailChimp')">
                  <dl><xsl:attribute name="class"><xsl:value-of select="div/dl/@class"/></xsl:attribute>

                    <xsl:copy-of select="div/dl/dt"/>

                    <dd class="portletItem odd">

                    <p>Blijf op de hoogte! Vul uw e-mailadres in en ontvang<br />
                    de digitale Nieuwsbrief Wmo en Wonen.</p>

                    <form id="searchform" class="form-inline" role="form" method="post"><xsl:attribute name="action"><xsl:value-of select="div/dl/dd/form/@action"/></xsl:attribute>
                      <div class="input-group">
                        <input type="search" class="form-control input-lg" placeholder="Vul uw e-mail adres in"><xsl:attribute name="name"><xsl:value-of select="//*[contains(@class, 'textType')]/@name"/></xsl:attribute></input>
                        <span class="input-group-btn">
                          <button class="btn btn-primary btn-lg" role="submit" type="submit">
                            <span class="title">Aanmelden</span>
                            <span class="fa fa-chevron-right"></span>
                          </button>
                        </span>
                      </div>
                      <xsl:copy-of select="div/dl//input[contains(@type, 'hidden')]"/>
                    </form>
                    </dd>

                  </dl>
                </xsl:when>

                <xsl:when test="contains(div/dl/@class, 'extendedCollectionPortlet')">

                  <dl><xsl:attribute name="class"><xsl:value-of select="div/dl/@class"/></xsl:attribute>
                    <xsl:copy-of select="div/dl/dt"/>
                    <xsl:for-each select="div/dl/dd[contains(@class, 'portletItem')]">
                      <dd class="portletItem">
                        <a><xsl:attribute name="title"><xsl:value-of select="a/@title"/></xsl:attribute><xsl:attribute name="class"><xsl:value-of select="a//*[contains(@class, 'thema-tag')]/span/@class"/></xsl:attribute><xsl:attribute name="title"><xsl:value-of select="a/@title"/></xsl:attribute><xsl:attribute name="href"><xsl:value-of select="a/@href"/></xsl:attribute>

                          <xsl:copy-of select="a/node()"/>
                        </a>
                      </dd>
                    </xsl:for-each>
                  </dl>

                </xsl:when>

                <xsl:otherwise>

                  <xsl:copy-of select="div/node()"/>

                </xsl:otherwise>

              </xsl:choose>

            </div>
          </div>

        </xsl:if>
        </xsl:for-each>


      </after>

    </rules>

    <rules css:if-not-content="
      .template-gov_folder_view,
      .template-tagnavigator_view,
      .template-search, .portaltype-portlet-page">

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

    </rules>

  </rules> <!-- #visual-portal-wrapper -->

  <!-- SEARCH PAGE RULES -->
  
  <rules css:if-content=".template-search">
    
    <!-- search page -->
    <before css:theme-children=".harcodedResultTypes">
      <ul>
        <xsl:apply-templates css:select=".harcodedResultTypes li" mode="raw" />
      </ul>
    </before>
    <before css:theme-children=".harcodedThemas">
      <ul>
        <xsl:apply-templates css:select=".harcodedThemas li" mode="raw" />
      </ul>
    </before>
    <!--<drop css:content=".harcodedResultTypes" />-->
    
    <before css:theme-children=".searchResults">
      
        <xsl:for-each css:select=".searchResults > div">
          <dl><xsl:attribute name="class"><xsl:value-of select="@class"/></xsl:attribute>
            
            <xsl:copy-of select="node()"/>
            
          </dl>
        </xsl:for-each>

    </before>
    <!--<drop css:content=".searchResults" />-->
    
    
    <replace css:theme-children=".searchResults" css:content-children=".searchResults" />
    <replace css:theme=".listingBar" css:content=".listingBar" />
    <replace css:theme=".searchPage"  css:content="form[name=searchform]" />
    
    <!--copy attributes="action" css:content="form[name=searchform]" css:theme="#searchform" />
    <copy attributes="name" css:content="form[name=searchform] input[type=text]" css:theme="#searchform input" / -->
    
    
  
  </rules>


</rules>
