{# -*- coding: utf-8 -*-

  This file is part of Invenio.
  Copyright (C) 2016-2018 CERN.

  Invenio is free software; you can redistribute it and/or modify it
  under the terms of the MIT License; see LICENSE file for more details.
#}

{%- import 'invenio_theme/admin_layout.html' as layout_overwrite with context -%}
{%- import 'admin/layout.html' as layout with context -%}
{%- import 'admin/static.html' as admin_static with context -%}

<!DOCTYPE html>
<html{% if html_css_classes %} class="{{ html_css_classes|join(' ') }}"{% endif %}{%- if g.ln %}
                               lang="{{ g.ln|safe }}"{% endif %} dir="{{ current_i18n.locale.text_direction }}">
  <head>
    {%- block head %}
      {%- block head_meta %}
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        {%- if description %}
          <meta name="description" content="{{ description }}"/>{% endif %}
        {%- if keywords %}
          <meta name="keywords" content="{{ keywords }}"/>{% endif %}
        {%- if config.get('THEME_GOOGLE_SITE_VERIFICATION', None) %}
          {%- for google_id in config.THEME_GOOGLE_SITE_VERIFICATION %}
            <meta name="google-site-verification" content="{{ google_id }}"/>
          {%- endfor %}
        {%- endif %}
      {%- endblock head_meta %}
      {%- block head_title %}
        {%- set title = title or _(config.THEME_SITENAME) or _('Invenio') %}
        <title>{{ title }}</title>
      {%- endblock head_title %}

      {%- block head_links %}
        <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}"/>
        {%- if keywords %}
          <link rel="canonical" href="{{ canonical_url }}"/>{% endif %}
        {%- block head_links_langs %}
          {%- if alternate_urls %}
            {%- for alt_ln, alternate_url in alternate_urls.items() %}
              <link rel="alternate" hreflang="{{ alt_ln }}" href="{{ alternate_url }}"/>
            {%- endfor %}
          {%- endif %}
        {%- endblock head_links_langs %}

        {%- block head_apple_icons %}
          {%- for size in [144, 114, 72, 57] %}
            {%- set icon_name = 'apple-touch-icon-%d-precomposed.png' | format(size) %}
              <link rel="apple-touch-icon-precomposed" sizes="{{ size }}x{{ size }}"
                  href="{{ url_for('static', filename=icon_name) }}"/>
          {%- endfor %}
        {%- endblock head_apple_icons %}

      {%- endblock head_links %}

      {%- block header %}{% endblock header %}
      {%- block css %}
        {{ webpack['theme.css'] }}
        {{ webpack['theme-admin.css'] }}
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
        <link href="{{ admin_static.url(filename='admin/css/bootstrap3/admin.css', v='1.1.1') }}" rel="stylesheet">
      {%- endblock css %}
    {%- endblock head %}
  </head>

  <body{% if body_css_classes %} class="{{ body_css_classes|join(' ') }}"{% endif %}{% if g.ln %}
                                 lang="{{ g.ln.split('_', 1)[0]|safe }}"{% if rtl_direction %} {{ rtl_direction|safe }}
      {% endif %}{% endif %} itemscope itemtype="http://schema.org/WebPage" data-spy="scroll"
                                 data-target=".scrollspy-target">
  {%- block browserupgrade %}
    <!--[if lt IE 8]>
      <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
  {%- endblock browserupgrade %}

  <div class="wrapper {{ config.get('ADMIN_UI_SKIN') }}" data-sidebar="sidebar-collapse">
    {% include 'invenio_theme/admin_header.html' %}

    <aside class="main-sidebar">
      <section class="sidebar">
        <ul data-widget="tree" class="sidebar-menu">
          {{ layout_overwrite.menu_overwrite() }}
        </ul>
      </section>
    </aside>
    <div class="content-wrapper">
      {% if admin_view.name %}
        <section class="content-header">
          {{ layout.messages() }}
          <h4>{{ admin_view.name }}</h4>
        </section>
      {% endif %}
      <section class="content">
        {% set render_ctx = h.resolve_ctx() %}
        {% block body %}{% endblock %}
      </section>
    </div>
    {%- include config.THEME_FOOTER_TEMPLATE -%}
  </div>

  {%- block javascript %}
    {{ webpack['manifest.js'] }}
    {{ webpack['vendor.js'] }}
    {{ webpack['adminlte.js'] }}
     <script language="javascript">
      jQuery = $;

      // Manually register select2 as a jQuery plugin, since it doesn't work
      // with Webpack + ES6 imports.
      $.fn.select2 = function (options) {
        options = options || {};
        if (typeof options === 'object') {
          this.each(function () {
            var instanceOptions = $.extend(true, {}, options);
            var instance = new select2($(this), instanceOptions);
          });
          return this;
        } else if (typeof options === 'string') {
          var ret;
          var args = Array.prototype.slice.call(arguments, 1);
          this.each(function () {
            var instance = $(this).data('select2');
            ret = instance[options].apply(instance, args);
          });
          if ($.inArray(options, ['open', 'close', 'destroy']) > -1) { return this; }
          return ret;
        } else { throw new Error('Invalid arguments for Select2: ' + options); }
      };

      $.fn.select2.defaults = {
        closeOnSelect: true,
        debug: false,
        dropdownAutoWidth: false,
        minimumInputLength: 0,
        maximumInputLength: 0,
        maximumSelectionLength: 0,
        minimumResultsForSearch: 0,
        selectOnClose: false,
        sorter: function (data) { return data; },
        templateResult: function (result) { return result.text; },
        templateSelection: function (selection) { return selection.text; },
        theme: 'default',
        width: 'resolve'
      };
     </script>
  {%- endblock javascript %}

  {%- block trackingcode %}
    {% include config.THEME_TRACKINGCODE_TEMPLATE %}
  {%- endblock %}

  {% block tail %}{% endblock %}
  </body>
</html>
