{#
/**
 * @file
 * Theme override to display a block.
 *
 * Available variables:
 * - plugin_id: The ID of the block implementation.
 * - label: The configured label of the block if visible.
 * - configuration: A list of the block's configuration values.
 *   - label: The configured label for the block.
 *   - label_display: The display settings for the label.
 *   - provider: The module or other provider that provided this block plugin.
 *   - Block plugin specific settings will also be stored here.
 * - content: The content of this block.
 * - attributes: array of HTML attributes populated by modules, intended to
 *   be added to the main container tag of this template.
 *   - id: A valid HTML ID and guaranteed unique.
 * - title_attributes: Same as attributes, except applied to the main title
 *   tag that appears in the template.
 * - title_prefix: Additional output populated by modules, intended to be
 *   displayed in front of the main title tag that appears in the template.
 * - title_suffix: Additional output populated by modules, intended to be
 *   displayed after the main title tag that appears in the template.
 *
 * @see template_preprocess_block()
 */
#}

{# Include UH Access Gate library. #}
{{ attach_library('commerce_2_demo/uh-access-gate') }}
{# / Include UH Access Gate library. #}

{% block content %}

  {# Set block content variable to access raw data. #}
  {% set block_entity = content['#block_content'] %}

  {# Create gate_sources variable. #}
  {% set gate_sources = '' %}

  {# If gate sources exist, add them to variable and split with pipe. #}
  {# If no gate sources exist, change variable to fullgate. #}
  {% if block_entity.field_gate_source|length %}
    {% for source in block_entity.field_gate_source %}
      {# Separate multiple sources with ',' so that we can parse them our with jQuery. #}
      {% if loop.last %}
        {% set gate_sources = gate_sources ~ source.value %}
      {% else %}
        {% set gate_sources = gate_sources ~ source.value ~ ',' %}
      {% endif %}
    {% endfor %}
  {% else %}
    {% set gate_sources = 'fullgate' %}
  {% endif %}

  <div class="modal fade access-gate" data-gate-sources="{{ gate_sources }}" tabindex="-1" role="dialog" aria-label="{{ 'Access the Drupal Commerce demo'|t }}">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-body">

          {{ content }}

        </div>
        <div class="modal-footer">
          <button type="button" id="footerClose" class="btn btn-primary disabled" tabindex="-1" data-dismiss="modal">{{ 'Close'|t }}</button>
        </div>
      </div>
    </div>
  </div>
{% endblock %}
