{% extends "base.html" %}


  {% if project == 'SQL 99' %}
  {% set extra_script_files = [
    '_static/language_data.js',
    '_static/searchtools.js',
    ]
  %}
  {% else %}
  {% set extra_script_files = [
    '_static/language_data.js',
    ]
  %}
  {% endif %}


  {% if page_source_suffix %}
  {% set suffix = page_source_suffix %}
  {% else %}
  {% set suffix = source_suffix %}
  {% endif %}

  {%- block doctype -%}
  <!DOCTYPE html>
  {%- endblock %}

  {%- block extra_head %}
  <meta charset='utf-8'>
  <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <meta name="apple-mobile-web-app-capable" content="yes">

  <noscript>
      <style>
          .cr-nojs-hide { display: none; }
      </style>
  </noscript>

  {% endblock %}

  {# Silence the sidebar's, relbar's #}
  {% block header %}{% endblock %}
  {% block relbar1 %}{% endblock %}
  {% block relbar2 %}{% endblock %}
  {% block sidebarsourcelink %}{% endblock %}

  {%- block content %}
  {% include "navbar.html" %}

  <div class="w-canvas">
    {% if project == 'SQL 99' %}
    <div class="container margin-bottom-32">
      <div class="section cr-sql-99-bg-color" style="margin: 0px;">
        <div class="cr-sql-99-header">
          <div class="cr-sql-99-headline">
            <p>The book <span style="font-weight: 600;">SQL-99 Complete, Really</span> is brought to you by</p>
            <a href="https://crate.io" title="Crate.io">
              <img class="cr-sql-99-logo" src="{{ pathto('_static', 1) }}/images/crate-logo-white.svg" width="150" height="20" alt="Crate.io Logo White">
            </a>
          </div>

          <div class="cr-sql-99-cta">
            <a href="https://crate.io/lp-free-trial" target="_blank" class="btn btn-primary btn-cr-sql-99">Try CrateDB Cloud for free</a>
            <p><a href="https://crate.io/products/cratedb/" target="_blank" class="cr-sql-99-link">Learn more about CrateDB</a></p>
          </div>
        </div>
      </div>
    </div>

    {% endif %}

    <div class="w-container w-hidden-main margin-bottom-32">
      <div class="section" style="margin: 0px">
        <a href="#" id="mobile-menu-toggler" class="w-button">Toggle Doc Menu</a>
      </div>
    </div>
    <div class="container" >
      <div class="row" id="main-content">
        <div class="col-md-4 col-lg-3" id="sidebar">
          <aside class="wrapper-navleft  sidebar__inner" >
            {%- block sidebar1 %}
            {%- for sidebartemplate in sidebars %}
            {%- include sidebartemplate %}
            {%- endfor %}
            {% endblock %}
          </aside>
        </div>
        <div class="col-md-8 col-lg-9" role="main">
          <div class="wrapper-content-right">
            {%- if current_version %}
            <div class="version-select-container">
              <div data-delay="0" class="w-dropdown">
                <div class="w-dropdown-toggle toggle">
                  <div><a href="{{ pathto(master_doc) }}">v:{{ current_version }}</a></div>
                  <div class="w-icon-dropdown-toggle toggle-icon"></div>
                </div>
                {%- if versions %}
                <nav class="w-dropdown-list dropdown-list">
                  {% for slug, url in versions %}
                  <a href="https://crate.io/{{ theme_canonical_url_path|replace('en/latest/', '') }}{{ rtd_language }}/{{ slug }}/" class="w-dropdown-link">{{ slug }}</a>
                  {% endfor %}
                </nav>
                {%- endif %}
              </div>
            </div>
            {%- endif %}
            {% block body %}{% endblock %}
          </div>

          {% if display_github %}
          <div class="view-on-github">
            <div id="cr-docs-feedback" class="cr-docs-feedback-container">
              <div class="cr-docs-feedback-header">
                <div class="cr-docs-feedback-headline">
                    <h2>Feedback</h2>
                </div>
              </div>

               <div id="cr-docs-rating" class="cr-docs-rating-container cr-nojs-hide">
                  <div class="cr-rating-content">
                      <div class="cr-rating">
                        <form id="ratingForm">
                          <span class="cr-ratingtext">How helpful was this page?</span>
                          <fieldset class="rating">
                            <input type="radio" id="star5" name="rating" value="5" /><label for="star5" title="Great!"><span class="cr-stars-label">5 stars</span></label>
                            <input type="radio" id="star4" name="rating" value="4" /><label for="star4" title="Pretty good"><span class="cr-stars-label">4 stars</span></label>
                            <input type="radio" id="star3" name="rating" value="3" /><label for="star3" title="Meh"><span class="cr-stars-label">3 stars</span></span></label>
                            <input type="radio" id="star2" name="rating" value="2" /><label for="star2" title="Bad"><span class="cr-stars-label">2 stars</span></label>
                            <input type="radio" id="star1" name="rating" value="1" /><label for="star1" title="Ugh..."><span class="cr-stars-label">1 star</span></label>
                          </fieldset>
                          <div id="ratingStatus"></div>
                          <button id="ratingVote" class="submit">Submit</button>
                        </form>
                    </div>
                  </div>
                </div>

                <div id="cr-feedback-content">

                </div>

                <div class="cr-docs-feedback-meta">
                  <a id="docs-feedback-open-issue" rel="noopener" href="https://{{ github_host|default('github.com') }}/{{ github_user }}/{{ github_repo }}/issues/new?labels=team:%20tech%20writing,triage&body={{
                    '###  Documentation feedback'|urlencode }}{{ '%0A'
                  }}{{ '%0A'
                  }}{{
                    '<!--Please do not edit or remove the following information -->'|urlencode }}{{ '%0A '
                  }}{{ '%0A'
                  }}{{
                    '- Page title: '|urlencode }}{{ title|striptags|urlencode }}{{ '%0A'
                  }}{{
                    '- Page URL: https://crate.io/'|urlencode }}{{ theme_canonical_url_path|urlencode }}{{ pagename|urlencode }}.html{{ '%0A'
                  }}{{
                    '- Source: https://'|urlencode }}{{ github_host|default('github.com') }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode|default('blob') }}/{{ github_version }}{{ conf_py_path|urlencode }}{{ pagename|urlencode }}{{ suffix }}{{ '%0A'
                  }}{{ '%0A'
                  }}---{{ '%0A'
                  }}{{ '%0A'
                  }}{{
                    '<!-- Please add your comments here -->'|urlencode }}{{ '%0A'
                  }}{{ '%0A'
                  }}" target="_blank" title="New issue">New&nbsp;issue</a>
                  <a id="docs-feedback-edit-document" href="https://{{ github_host|default('github.com') }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode|default('edit') }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ suffix }}" rel="noopener" target="_blank" title="Edit on GitHub">Edit&nbsp;on&nbsp;GitHub</a>

                  <a id="docs-feedback-open-github" href="https://{{ github_host|default('github.com') }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode|default('blob') }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ suffix }}" rel="noopener" target="_blank" title="View on GitHub">View&nbsp;on&nbsp;GitHub</a>
                </div>
              </div>
            </div>
          </div>
          {% endif %}

        </div>
      </div>
    </div>
  </div>
  {%- include "footer.html" %}

  {%- endblock %}

  {%- block custom_footer %}

  {% if display_github %}
  <script>
    document.addEventListener('keydown', (event) => {
      if (event.key === 'g' && event.ctrlKey) {
        {% if check_meta and 'github_url' in meta %}
          location.href = "{{ meta['github_url'] }}";
        {% else %}
          location.href = "https://{{ github_host|default('github.com') }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode|default('edit') }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ suffix }}";
        {% endif %}
      }
    });
  </script>
  {% endif %}

  <script>
    var sidebar = new StickySidebar('#sidebar', {
        containerSelector: '#main-content',
        innerWrapperSelector: '.sidebar__inner',
        topSpacing: 20,
        bottomSpacing: 20,
        minWidth: 992
    });

    // Desktop only
    if( !$('#mobile-menu-toggler').is(':visible') ) {

    } else {

      $('#mobile-menu-toggler').click(function() {
        $('#mobile-menu-toggler').toggleClass('w-active');
        $('.wrapper-navleft').toggleClass('shownav');
      });

    }
  </script>

  {% if theme_tracking_segment_id %}
  <!-- Segment -->
  <script>
    !function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","setAnonymousId"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0";
      analytics.load("{{ theme_tracking_segment_id }}");
      analytics.setAnonymousId(Cookies.get('uid'));
      analytics.page('{{ title|striptags }} - {{ docstitle|striptags }}', {
        project: '{{ theme_tracking_project }}',
        version: '{{ current_version }}'
      });
    }}();
  </script>
  {% endif %}

  {% if theme_tracking_hubspot_id %}
  <!-- Start of HubSpot Embed Code -->
  <script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/{{ theme_tracking_hubspot_id }}.js"></script>
  <!-- End of HubSpot Embed Code -->
  {% endif %}

  {% if display_github %}
  <!-- GitHub feedback section -->
  <script>
    var feedbackLoaded = false;
        // check if feedback section is in viewport
        function isInViewport(elem) {
          var bounding = elem.getBoundingClientRect();
          return (
            bounding.top >= 0 &&
            bounding.left >= 0 &&
            bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
            bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
            );
        };

        var feedbackbox = document.querySelector('#cr-docs-feedback');
        if (isInViewport(feedbackbox)) {
          renderIssues();
          feedbackLoaded = true;
        }

        $(window).scroll(function () {
          if (!feedbackLoaded ){
            if (isInViewport(feedbackbox)) {
              renderIssues();
              feedbackLoaded = true;
            }
          }
        });

        function renderIssues() {

          function makeIssueHeader(open, closed) {
            var html = "<div class='cr-docs-feedback-nav'><ul> \
            <li><a id='issues-open' class='cr-fb-link cr-fb-active' title='View Open issues'>Open (";

                      // if more than 30 issues, add "Last"
                      if (open.length >= 30) { html += `Last `; }
                      html += open.length + ")</a></li> \
                      <li><a id='issues-closed' class='cr-fb-link' title='View Closed issues'>Closed (";
                      if (closed.length >= 30) { html += `Last `; }
                      html += closed.length + ")</a></li> \
                      </ul></div>";

                      return html;
          };

          function listIssues(issues, isClosed) {
            var divId;
            var display;
            if (!isClosed) {
              divId = "cr-docs-issues-open-list";
              display = 'block';
            } else {
              divId = "cr-docs-issues-closed-list";
              display = 'none';
            }
            var html = `<div style='display: ${display};' id='${divId}' class='cr-docs-feedback-issues'><ul>`;

            // if no issues are found, post this
            if (issues.length == 0) { html += `<li>Currently there is no feedback for this document.</li>` }

              else {
                issues.forEach((issue) => {
                  html += `<li><div class='cr-docs-feedback-entry'><div class='cr-docs-feedback-title'><strong><a href='${issue.html_url}' rel='noopener' class='cr-docs-link' title='View issue on GitHub' target='blank'>${issue.title}</a></strong></div>`;

                    // show PR if applicable
                    if (issue.pull_request != undefined) {
                      html += `<div class='cr-docs-feedback-pr'><svg viewBox='0 0 12 16' version='1.1' width='12' height='16' aria-hidden='true'><path fill-rule='evenodd' d='M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0010 15a1.993 1.993 0 001-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 00-1 3.72v6.56A1.993 1.993 0 002 15a1.993 1.993 0 001-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z'><title>Pull Request</title></path></svg></div>`;
                    }
                    // show # of comments
                    if (issue.comments != 0) {
                      html += `<div class='cr-docs-feedback-comments'><a href='${issue.html_url}' rel='noopener' class='cr-docs-link' title='View issue on GitHub' target='blank'><svg viewBox='0 0 16 16' version='1.1' width='16' height='16' aria-hidden='true'><path fill-rule='evenodd' d='M14 1H2c-.55 0-1 .45-1 1v8c0 .55.45 1 1 1h2v3.5L7.5 11H14c.55 0 1-.45 1-1V2c0-.55-.45-1-1-1zm0 9H7l-2 2v-2H2V2h12v8z'><title>Comment</title></path></svg> ${issue.comments}</a></div>`;
                    }
                    // show issue number + link to it
                    html += `</div><div class='cr-docs-feedback-details'><a href='${issue.html_url}' rel='noopener' class='cr-docs-link' title='View issue on GitHub' target='blank'>#${issue.number}</a> `;

                    var date = new Date(issue.created_at);

                    const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
                    var formatted_date = date.getDate() + " "
                    + months[date.getMonth()] + " "
                    + date.getFullYear();

                    html += `opened on ${formatted_date} by <a href='${issue.user.html_url}' rel='noopener' class='cr-docs-link' title='View ${issue.user.login} on GitHub' `;
                    html += ` target='blank'>${issue.user.login}</a></br>`;
                    html += "</div></li>";
                  });
              }

              html += "</ul></div>";
              return html;
            }

            async function fetchIssues(url) {
              const data = await fetch(url).then((response) => response.json());
              return data;
            }

            const content = document.getElementById('cr-feedback-content');
            content.innerHTML = '<p>Loading data...</p>';
            fetchIssues("https://api.{{ github_host|default('github.com') }}/search/issues?q=repo:{{ github_user }}/{{ github_repo }}+label%3A\"area%3A+docs\"+\"{{ title|striptags|urlencode }}\"+\"{{ pagename|urlencode }}.html\"")
                .then(function (issues) {
                  const openIssues = issues.items.filter(x => x.state == 'open');
                  const closedIssues = issues.items.filter(x => x.state == 'closed');
                  var html = makeIssueHeader(openIssues, closedIssues);
                  html += listIssues(openIssues);
                  html += listIssues(closedIssues, true);
                  content.innerHTML = html;
                  const openButton = document.getElementById('issues-open');
                  const closedButton = document.getElementById('issues-closed');
                  const openList = document.getElementById('cr-docs-issues-open-list');
                  const closedList = document.getElementById('cr-docs-issues-closed-list');
                  openButton.addEventListener('click', function (e) {
                    openButton.classList.add('cr-fb-active');
                    closedButton.classList.remove('cr-fb-active');
                    openList.style.display = 'block';
                    closedList.style.display = 'none';
                  });
                  closedButton.addEventListener('click', function (e) {
                    openButton.classList.remove('cr-fb-active');
                    closedButton.classList.add('cr-fb-active');
                    openList.style.display = 'none';
                    closedList.style.display = 'block';
                  });

                {% if theme_tracking_segment_id %}
                analytics.track('Feedback Opened');
                {% endif %}
                }).catch(function() {
                // if rate limit exceeded, throw this error
                content.innerHTML = '<p>Error loading data, limit exceeded. Please try again later.</p>';
                {% if theme_tracking_segment_id %}
                analytics.track('DOCS RATE LIMIT', {
                  location: 'Center',
                  text: 'Error loading data, limit exceeded. Please try again later.',
                  category: 'Docs',
                  type: 'Text',
                  pageTitle: document.title
               });
               {% endif %}
        });
    }
  </script>
  {% endif %}

  {% if pagename == "search" %}
  {% if theme_google_search_api_key %}
  <script type="text/javascript" src="{{ pathto('_static/js/search.js', 1) }}?ver={{ theme_ver }}"></script>
  {% endif %}
  {% endif %} 
  
{%- endblock %}
