{% from "./partials/tags.html" import tags %}
{% from "./partials/message.html" import message %}
{% from "./partials/example.html" import example %}
{% from "./partials/schema-prop.html" import schemaProp %}


{% macro operation(operation, operationType, channelName, channel) %}

<a name="operation-{{operationType}}-{{channelName}}"></a>
<div class="center-block p-8">
  <div class="operation pt-8 pb-8">
    <h3 class="font-mono text-base">
      {% if operationType == 'publish' %}
      <span class="font-mono border border-blue text-blue uppercase p-1 rounded" title="Publish">Pub</span>
      {% endif %}
      {% if operationType == 'subscribe' %}
      <span class="font-mono border border-green-dark text-green-dark uppercase p-1 rounded"
        title="Subscribe">Sub</span>
      {% endif %}
      {{ channelName }}
    </h3>

    {% if channel.description() is not none %}
      <div class="mt-4 mb-4 markdown">{{ channel.description() | markdown2html | safe }}</div>
    {% endif %}

    {% if operation.summary() is not none %}
      <p class="text-grey text-sm">{{operation.summary()}}</p>
    {% endif %}

    {% if operation.description() is not none %}
      <div class="mt-4 mb-4 markdown">{{ operation.description() | markdown2html | safe }}</div>
    {% endif %}



    {% if channel.parameters() is not none %}
      {% if channel.parameters() | length %}
      <div class="mt-2">
          <div class="is-open">
            <div class="js-prop cursor-pointer py-2 flex property">
              <div class="pr-4" style="margin-top:-2px; min-width: 25%;">
                <span class="text" style="word-break: break-word;">Parameters</span>
                <svg class="expand" version="1.1" viewBox="0 0 24 24" x="0" xmlns="http://www.w3.org/2000/svg" y="0">
                  <polygon points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "></polygon>
                </svg>
              </div>
            </div>
            <div class="children bg-grey-lighter p-4 rounded">
              <div class="bg-grey-lightest pl-8 pr-8 rounded">
                {% for parameterName, parameter in channel.parameters() %}
                  {{ schemaProp(parameter.schema(), parameterName, odd=false, specialName=false, required=true) }}
                {% endfor %}
              </div>
            </div>
          </div>
        </div>
      {% endif %}
    {% endif %}


    {% if operation.hasMultipleMessages() %}
    <p>Accepts <strong>one of</strong> the following messages:</p>
    {% for msg in operation.messages() %}
    {{ message(msg, showIndex=true, index=loop.index, open=false) }}
    {% endfor %}
    {% else %}
    <p>Accepts the following message:</p>
    {{ message(operation.message(), showIndex=false, open=true) }}
    {% endif %}

    {{ tags(operation.tags()) }}
  </div>
</div>

<div class="right-block p-8">
  <h4 class="text-lg text-white mb-4">Examples</h4>

  {% if operation.hasMultipleMessages() %}
  {% for msg in operation.messages() %}
  {{ example(msg, channelName) }}
  {% endfor %}
  {% else %}
  {{ example(operation.message(), channelName) }}
  {% endif %}
</div>


{% endmacro %}
