{{!--
  Original work Copyright (c) 2015 Nils Knappmeier
  https://github.com/bootprint/bootprint-openapi

  Renders the responses section of an operation
  @param {Response[]} responses a list of Swagger-Response definitions
  @param {string[]} produces a list of response content types produced by the operation
  @api public
--}}

{{#if responses}}
  <div class="doc-row">
    <div class="doc-copy">
      <section class="swagger-responses">
        {{!--
          {{#if produces}}
            <p>{{>swagger/list-of-labels values=produces}}</p>
          {{else if @root.produces}}
            <p>
              <!-- <a href="#swagger-default-produces">Uses default content-types: </a> -->
              {{>swagger/list-of-labels values=@root.produces}}
            </p>
          {{/if}}
        --}}

        {{#each responses}}
          {{!-- {{#schemaReferenceContext $ref}} --}}
            <div class="prop-row prop-group">
              <div class="prop-name">
                {{! Use response-code and http-name as text}}
                <div class="prop-title">{{@key}} {{httpResponseCode @key}}</div>
                {{!-- {{#if schema}}
                  <div class="prop-ref">{{>json-schema/reference schema}}</div>
                  <!-- <span class="swagger-global"></span> <span class="json-schema-reference"><a href="{{$ref}}">{{$ref}}</a></span> -->
                {{/if}} --}}
              </div>
              <div class="prop-value">
                {{md description}}
              </div>
            </div>
            {{#if schema}}
              <div class="prop-row prop-inner">
                <div class="prop-name">type</div>
                <div class="prop-value">{{>json-schema/datatype schema}}</div>
              </div>
            {{/if}}
          {{!-- {{/schemaReferenceContext}} --}}
        {{/each}}
      </section>
    </div>

    {{! Print examples without whitespace. }}
    <div class="doc-examples">
      {{#if produces}}
        <h5>Response Content-Types:
          <span>{{#each produces}}{{.}}{{#unless @last}}, {{/unless}}{{/each}}</span>
        </h5>
      {{/if}}

      {{#each responses}}
        {{#schemaReferenceContext $ref}}          
          <section>
            <h5>Response Example <span>({{@key}} {{httpResponseCode @key}})</span></h5>
            {{>swagger/print-example schema.example}}
          </section>          
          {{#if headers}}
            <section>
              <h5>Response Headers <span>({{@key}} {{httpResponseCode @key}})</span></h5>
              <section class="swagger-response-headers">
                <table class="table">
                  <thead>
                  <tr>
                    <th class="swagger-response-header-name"></th>
                    <th class="swagger-response-header-description"></th>
                    <th class="swagger-response-header-data-type"></th>
                  </tr>
                  </thead>
                  <tbody>
                  {{#each headers}}
                    {{#if $ref}}
                      {{> swagger/responseHeaderRow header=(json-schema-resolve-ref $ref) name=@key}}
                    {{else}}
                      {{> swagger/responseHeaderRow header=. name=@key}}
                    {{/if}}
                  {{/each}}
                  </tbody>
                </table>
              </section>
            </section>
          {{/if}}
        {{/schemaReferenceContext}}
      {{/each}}
    </div>
  </div>
{{/if}}
