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

    <!--
    You can include this rules file in your own theme as follows:

    <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/backend.xml" />
        <rules css:if-content="body.viewpermission-view, body.viewpermission-none">
           <theme href="index.html" />
           ... your rules
        </rules>
    </rules>

    This will include the toolbar in your theme and use Barceloneta to theme
    all your backend pages such as site setup and edit.
    -->

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

  <!-- We don't want overlays -->
  <drop attributes="class" css:content="#edit-bar a.pat-plone-modal" />

  <!-- Cut down barceloneta without just for backend UI -->
  <rules css:if-not-content="body.viewpermission-view, body.viewpermission-none">

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

    <!-- We can't control the bundle from here due to include. Just hard code -->
    <after css:theme-children="head">
      <link rel="shortcut icon" type="image/x-icon"
            href="{$portal_url}/++theme++design.plone.theme/favicon.ico" />
      <link rel="stylesheet" href="{$portal_url}/++theme++design.plone.theme/barceloneta/barceloneta-backend.css" />

      <link href="{$portal_url}/++theme++design.plone.theme/css/fonts.css" rel="stylesheet"/>
    </after>

    <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']" />
    </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" />

    <!-- CSS -->
    <after css:theme-children="head" css:content="head link" />

    <!-- Script -->
    <after css:theme-children="head" css:content="head script" />

    <!-- We don't need global nav -->
    <drop css:theme="#mainnavigation-wrapper" />

    <!-- Hero unit on homepage only -->
    <drop css:theme="div.principal" css:if-not-content="body.template-document_view.section-front-page" />

    <!-- Full-width breadcrumb -->
    <replace css:theme="#above-content" css:content="#viewlet-above-content" />
    <after css:theme-children="head">
        <style>.plone-breadcrumb {margin-top: 0;}</style>
    </after>

    <!-- Central column -->
    <replace css:theme="#content-container" method="raw">
      <xsl:variable name="central">
        <xsl:if test="//aside[@id='portal-column-one'] and //aside[@id='portal-column-two']">col-xs-12 col-sm-6</xsl:if>
        <xsl:if test="//aside[@id='portal-column-two'] and not(//aside[@id='portal-column-one'])">col-xs-12 col-sm-9</xsl:if>
        <xsl:if test="//aside[@id='portal-column-one'] and not(//aside[@id='portal-column-two'])">col-xs-12 col-sm-9</xsl:if>
        <xsl:if test="not(//aside[@id='portal-column-one']) and not(//aside[@id='portal-column-two'])">col-xs-12 col-sm-12</xsl:if>
      </xsl:variable>
      <div class="{$central}">
        <p class="pull-right visible-xs">
          <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle nav</button>
        </p>
        <div class="row">
          <div class="col-xs-12 col-sm-12">
             <xsl:apply-templates css:select="#content" />
          </div>
        </div>
        <footer class="row">
          <div class="col-xs-12 col-sm-12">
           <xsl:copy-of css:select="#viewlet-below-content" />
          </div>
        </footer>
      </div><!--/row-->
    </replace>

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

    <!-- Left column -->
    <rules css:if-content="#portal-column-one">
      <replace css:theme="#column1-container">
          <div id="sidebar" class="col-xs-6 col-sm-3 sidebar-offcanvas">
            <aside id="portal-column-one">
              <xsl:copy-of css:select="#portal-column-one > *" />
            </aside>
          </div>
      </replace>
    </rules>

    <!-- Right column -->
    <rules css:if-content="#portal-column-two">
      <replace css:theme="#column2-container">
          <div id="sidebar" class="col-xs-6 col-sm-3 sidebar-offcanvas" role="complementary">
            <aside id="portal-column-two">
              <xsl:copy-of css:select="#portal-column-two > *" />
            </aside>
          </div>
      </replace>
    </rules>

    <!-- Content header -->
    <drop css:theme="#portal-top" />
    <!--<drop css:theme="#portal-footer-wrapper" />-->

    <!-- Add site header -->
    <after css:theme-children="#content-header" css:content="#portal-top" />
    <after css:theme-children="#content-header" css:content="#portal-mainnavigation" />

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

        <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">
            <span class="icon"></span>
            <span class="sr-only">SEARCH</span>
          </button>
          <div class="plone-navbar-header">
            <button type="button"
                    class="plone-navbar-toggle"
                    aria-controls="portal-globalnav-collapse"
                    aria-expanded="false">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
          </div>
        </div>
      </div>
    </replace>

    <!-- Add site footer -->
    <replace css:theme="#portal-footer-wrapper" css:content="#portal-footer-wrapper" />

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

  </rules>

  <!-- se la portlet "valuta il sito" e' nel footer la sposto fuori dal wrapper -->
  <before css:content="#portal-footer-wrapper" css:if-content=".portal-footer .rerPortletAdvancedStatic.valuta-sito">
    <xsl:copy-of css:select=".portal-footer .rerPortletAdvancedStatic.valuta-sito"/>
  </before>
  <drop css:content=".portal-footer .rerPortletAdvancedStatic.valuta-sito" />

  <!-- sposto portalMessage sotto le breadcrumbs -->
  <!-- before css:content="#content" css:if-content="#content .portalMessage">
    <xsl:copy-of css:select="#content .portalMessage" />
  </before>
  <drop css:content="#content .portalMessage" / -->

  <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>
</rules>
