{% extends "base.html" %}

{% block title %}{{ namespace.name }}.{{ struct.name }}{% endblock %}

{% block meta_other %}
  <meta property="og:title" content="{{ namespace.name }}.{{ struct.name }}"/>
  <meta property="og:description" content="Reference for {{ namespace.name }}.{{ struct.name }}"/>
  <meta name="twitter:title" content="{{ namespace.name }}.{{ struct.name }}"/>
  <meta name="twitter:description" content="Reference for {{ namespace.name }}.{{ struct.name }}"/>
{% endblock %}

{% macro sidebar_block(elements, struct_name, section_title, section_class, section_fragment) -%}
{% if elements|length > 0 %}
<div class="section">
  <h5>{{ section_title }}</h5>
  <div class="links">
  {% for m in elements %}
    <a class="{{ section_class }}" href="{{ section_fragment }}.{{ struct_name }}.{{ m.name }}.html">{{ m.name }}</a>
  {% endfor %}
  </div>
</div>
{% endif %}
{% endmacro %}

{% block sidebar %}
<div class="section">
  <h5>Type</h5>
  <div class="links">
    <a class="current" href="struct.{{ struct.name }}.html#description">{{ struct.name }}</a>
  </div>
</div>

{{ sidebar_block(struct.ctors, struct.name, "Constructors", "ctor", "ctor") }}
{{ sidebar_block(struct.type_funcs, struct.name, "Functions", "func", "type_func") }}
{{ sidebar_block(struct.methods, struct.name, "Instance methods", "method", "method") }}
{% endblock %}

{% macro navbar_block(elements, section_title, section_link) -%}
{% if elements|length > 0 %}
<li class="toc-list-item"><a href="{{ section_link }}"><span class="link-text">{{ section_title }}</span></a></li>
{% endif %}
{% endmacro %}

{% block navbar %}
<div id="toc" class="toc">
  <nav aria-labelledby="toc-title">
    <p id="toc-title">Content</p>
    <ul class="toc-list">
      <li class="toc-list-item"><a href="#description"><span class="link-text">Description</span></a></li>
      {% if struct.description_toc %}
      <ul class="toc-list">
      {% if struct.description_toc|length == 1 %}
      {% for header in struct.description_toc[0].children %}
        <li class="toc-list-item"><a href="#{{ header.id }}"><span class="link-text">{{ header.name }}</span></a></li>
      {% endfor %}
      {% else %}
      {% for header in struct.description_toc %}
        <li class="toc-list-item"><a href="#{{ header.id }}"><span class="link-text">{{ header.name }}</span></a></li>
      {% endfor %}
      {% endif %}
      </ul>
      {% endif %}
      {{ navbar_block(struct.ctors, "Constructors", "#constructors") }}
      {{ navbar_block(struct.type_funcs, "Functions", "#type-functions") }}
      {{ navbar_block(struct.methods, "Methods", "#methods") }}
    </ul>
  </nav>
</div>
{% endblock %}

{% block content %}
<section id="main" class="content">
  <header>
    <h3>Struct</h3>
    <h1><a href="index.html">{{ namespace.name }}</a><span class="sep"></span>{{ struct.name }}</h1>
  </header>

  <section>
    <summary>
      <div class="docblock">
        <p>
        {%- if CONFIG.is_unstable(struct.available_since) -%}
        <span class="emblem available-next" title="This type will be available in the next stable release">unstable</span>&nbsp;
        {%- endif %}
        {%- if struct.deprecated_since -%}
        <span class="emblem deprecated">deprecated: {{ struct.deprecated_since.version }}</span>&nbsp;
        {%- endif -%}
        {%- if struct.available_since -%}
        <span class="emblem available">since: {{ struct.available_since }}</span>
        {%- endif -%}
        </p>
      </div>
      <div class="toggle-wrapper">
        <h4 style="display:flex;" id="description">
          Description
          <a href="#description" class="anchor"></a>
          {% if CONFIG.source_location_url and struct.docs_location %}
          <a class="srclink" title="go to source location" href="{{ CONFIG.source_link(struct.docs_location) }}">[src]</a>
          {% endif %}
        </h4>

        <pre><code>{{ struct.c_decl }}</code></pre>

        <div class="docblock">
          {{ struct.description }}
        </div>

        {% if struct.fields %}
        <div class="toggle-wrapper">
          <h6 style="display:flex;">
            Structure members
            {% if CONFIG.source_location_url and struct.source_location %}
            <a class="srclink" title="go to source location" href="{{ CONFIG.source_link(struct.source_location) }}">[src]</a>
            {% endif %}
          </h6>

          <div class="docblock">
            <dl>
            {% for field in struct.fields %}
              <dt><code>{{ field.name }}</code></dt>
              <dd>{{ field.description }}</dd>
            {% endfor %}
            </dl>
          </div>
        </div>
        {% endif %}

        <div class="docblock">
          {% if struct.stability %}
          <p>Stability: {{ struct.stability }}</p>
          {% endif %}
          {% if struct.available_since %}
          <p>Available since: {{ struct.available_since }}</p>
          {% endif %}
          {% if struct.deprecated_since %}
          {%- if struct.deprecated_since.message -%}
          <div>
            <p>Deprecated since: {{ struct.deprecated_since.version }}</p>
            {{ struct.deprecated_since.message }}
          </div>
          {%- else -%}
          <p>Deprecated since: {{ struct.deprecated_since.version }}. Do not use in newly written code.</p>
          {%- endif -%}
          {% endif %}
        </div>

        {% if struct.attributes %}
        <div class="docblock">
          <table class="attributes">
          {% for (key, value) in struct.attributes.items() %}
            <tr><td>{{ key|escape }}</td><td>{{ value|escape }}</td></tr>
          {% endfor %}
          </table>
        </div>
        {% endif %}
      </div>
    </summary>

    {% if struct.ctors %}
    <div class="toggle-wrapper constructors">
      <h4 id="constructors">
        Constructors
        <a href="#constructors" class="anchor"></a>
      </h4>

      <div class="docblock">
      {% for ctor in struct.ctors %}
        <div class="{% if ctor.deprecated_since %}deprecated{% endif %}">
          <h6><a href="ctor.{{ struct.name }}.{{ ctor.name }}.html">{{ ctor.identifier }}</a></h6>
          <div class="docblock">
            {{ ctor.summary }}
          </div>
          <div class="docblock">
            <p>
            {%- if CONFIG.is_unstable(ctor.available_since) -%}
            <span class="emblem available-next" title="This constructor will be available in the next stable release">unstable</span>&nbsp;
            {%- endif %}
            {%- if ctor.deprecated_since -%}
            <span class="emblem deprecated">deprecated: {{ ctor.deprecated_since }}</span>&nbsp;
            {%- endif -%}
            {%- if ctor.available_since -%}
            <span class="emblem available">since: {{ ctor.available_since }}</span>
            {%- endif -%}
            </p>
          </div>
        </div>
      {% endfor %}
      </div>
    </div>
    {% endif %}

    {% if struct.type_funcs %}
    <div class="toggle-wrapper methods">
      <h4 id="type-functions">
        Functions
        <a href="#type-functions" class="anchor"></a>
      </h4>

      <div class="docblock">
      {% for func in struct.type_funcs %}
      <div class="{% if func.deprecated_since %}deprecated{% endif %}">
        <h6><a href="type_func.{{ struct.name }}.{{ func.name }}.html">{{ func.identifier }}</a></h6>
        <div class="docblock">
          {{ func.summary }}
        </div>
        <div class="docblock">
          <p>
          {%- if CONFIG.is_unstable(func.available_since) -%}
          <span class="emblem available-next" title="This function will be available in the next stable release">unstable</span>&nbsp;
          {%- endif %}
          {%- if func.deprecated_since -%}
          <span class="emblem deprecated">deprecated: {{ func.deprecated_since }}</span>&nbsp;
          {%- endif -%}
          {%- if func.available_since -%}
          <span class="emblem available">since: {{ func.available_since }}</span>
          {%- endif -%}
          </p>
        </div>
      </div>
      {% endfor %}
      </div>
    </div>
    {% endif %}

    {% if struct.methods %}
    <div class="toggle-wrapper methods">
      <h4 id="methods">
        Instance methods
        <a href="#methods" class="anchor"></a>
      </h4>

      <div class="docblock">
      {% for method in struct.methods %}
        <div class="{% if method.deprecated_since %}deprecated{% endif %}">
          <h6><a href="method.{{ struct.name}}.{{ method.name }}.html">{{ method.identifier }}</a></h6>
          <div class="docblock">
            {{ method.summary }}
          </div>
          <div class="docblock">
            <p>
            {%- if CONFIG.is_unstable(method.available_since) -%}
            <span class="emblem available-next" title="This method will be available in the next stable release">unstable</span>&nbsp;
            {%- endif %}
            {%- if method.deprecated_since -%}
            <span class="emblem deprecated">deprecated: {{ method.deprecated_since }}</span>&nbsp;
            {%- endif -%}
            {%- if method.available_since -%}
            <span class="emblem available">since: {{ method.available_since }}</span>
            {%- endif -%}
            </p>
          </div>
        </div>
      {% endfor %}
      </div>

    </div>
    {% endif %}

  </section>
</section>
{% endblock %}
