<?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">


  <notheme css:if-not-content="#visual-portal-wrapper" />

  <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="title" css:content="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']" />
    <drop css:content="head link[rel='shortcut icon']" />

    <!-- drop the theme stylesheets -->
    <!-- drop theme="/html/head/link[rel='stylesheet']" / -->

    <!-- CSS -->
    <drop css:content="head link[data-bundle='diazo']" />
    <before css:theme-children="head" css:content="head link" />
    <before css:theme-children="head" css:content="head style" />
    <!-- Script -->
    <drop css:content="head script[data-bundle='diazo']" />
    <before css:theme-children="head" css:content="head script" />
  </rules>

  <drop css:content="#portal-column-two" css:if-content="body.template-tile_view" />
  <before css:theme-children="#content-core" css:if-content="body.template-newsitem_view" css:content=".leadImage" />

  <!-- 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" />

  <!-- Need to rewrite entire portal-header to wrap social, search and burgy-->
  <replace css:content="#portal-header">
    <div id="portal-header">
      <xsl:copy-of select="//*[@id='portal-logo']"/>
      <xsl:variable name="headerWrapper">
        <xsl:if test="not(//div[@id='header-social'])"> no-social-links</xsl:if>
      </xsl:variable>
      <xsl:variable name="hasNavigation">
        <xsl:if test="not(//nav[@class='globalnavWrapper'])"> empty-navigation</xsl:if>
      </xsl:variable>

      <div class="search-social-wrapper{$headerWrapper}">
        <xsl:copy-of select="//*[@id='header-social']"/>
        <xsl:copy-of select="//*[@id='portal-searchbox']"/>

        <button id="search-toggle"
                aria-controls="portal-searchbox"
                aria-label="Apri/chiudi ricerca"
                title="Apri/chiudi ricerca">
          <i class="fas fa-search"></i>
          <span class="close-icon"></span>
          <span class="sr-only">SEARCH</span>
        </button>
        <div class="plone-navbar-header{$hasNavigation}">
          <button type="button"
                  class="plone-navbar-toggle"
                  aria-controls="portal-mainnavigation"
                  aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <i class="fas fa-bars"></i>
          </button>
        </div>
      </div>
    </div>
  </replace>
  <drop css:content="#portal-languageselector" />

  <replace content="//*[@class[contains(., 'portalMessage')]]">
    <xsl:variable name="status">
      <xsl:if test="@class[contains(., 'info')]">status</xsl:if>
      <xsl:if test="@class[contains(., 'success')]">status</xsl:if>
      <xsl:if test="@class[contains(., 'warning')]">alert</xsl:if>
      <xsl:if test="@class[contains(., 'error')]">alert</xsl:if>
    </xsl:variable>
    <div role="{$status}"><xsl:copy-of select="attribute::*" />
      <xsl:apply-templates select="./node()" />
    </div>
  </replace>

  <!-- sposto le colonne dentro ad un container -->
  <replace css:content="#portal-column-content">
    <xsl:variable name="wrapper">
      <xsl:if test="//aside[@id='portal-column-one']">with-column-one </xsl:if>
      <xsl:if test="//aside[@id='portal-column-two']">with-column-two</xsl:if>
      <xsl:if test="not(//aside[@id='portal-column-one']) and not(//aside[@id='portal-column-two'])">with-no-columns</xsl:if>
    </xsl:variable>
    <div id="column-wrapper" class="{$wrapper}">

      <!-- contenuto centrale -->
      <xsl:copy-of select="//*[@id='portal-column-content']"/>

      <!-- colonna 1 -->
      <xsl:copy-of select="//*[@id='portal-column-one']"/>

      <!-- colonna 2 -->
      <xsl:copy-of select="//*[@id='portal-column-two']"/>

    </div>
  </replace>

  <!-- cancello le colonne originali -->
  <drop css:content="body > aside#portal-column-one" />
  <drop css:content="body > aside#portal-column-two" />


  <!-- aggiungo la freccia per il mobile -->
  <after css:content="#portal-footer-wrapper">
    <a href="javascript:" aria-hidden="true" id="return-to-top" title="Return to top" style="display: none">
      <i class="fas fa-chevron-up"></i>
    </a>
  </after>

  <replace css:theme="body" css:content="body" />

</rules>
