<div class="init-block w-popup-stream-select
            {%- if widget.classname %} {{ widget.classname }}{% endif %}"
     id="{{ widget.id }}"
     {%- block block_name %} data-block-name="popup-stream-select"{% endblock %}
     {%- if widget.multiple %} data-multiple="multiple"{%- endif -%}
     {%- if widget.unshift %} data-unshift="true"{%- endif -%}
     {%- if readonly %} data-readonly="true"{% endif %}
     data-config="{{ widget.js_config() }}">

  {% macro option(id='', title='', index=None) %}
      <label for="{{ widget.id }}-input{% if widget.multiple %}-{{ index }}{% endif %}">
        {%- if title is defined -%}
            {{ title }}
        {% endif -%}
      </label>
    <input type="checkbox"
           checked="checked"
           id="{{ widget.id }}-input{% if widget.multiple %}-{{ index }}{% endif %}"
           name="{{ widget.input_name }}"
           value="{{ id }}" />
  {% endmacro %}

  <div style="display: none" class="input-place">
    {% for v in options %}
      {%- if v.existing is not defined or v.existing %}
        {{ option(v.id, v.title, loop.index) }}
      {% else %}
          {# Option is deleted, so we should render empty input #}
          {{ option() }}
      {%- endif -%}
    {% endfor %}
    {% if not widget.multiple and not options %}{{ option() }}{% endif %}
  </div>

  <div>
    <table class="w-popup-stream-select-items">
      <tbody id="{{ widget.id }}-div">
        {% for v in options %}
          {%- if v.existing is not defined or v.existing %}
            {{ widget.item_row(v, loop.cycle('odd', 'even')) }}
          {%- endif -%}
        {% endfor %}
      </tbody>
    </table>
  </div>
  {%- if not readonly -%}
  <div class="w-buttons">
    {% if widget.allow_select %}
    <a class="button hide" id="{{ widget.id }}-btn" href="#select">
      {{ widget.open_btn_text }}
    </a>
    {% endif %}
    {% if widget.show_create_button %}
      <a class="button hide"
         rel="create"
         id="{{ widget.id }}-create"
         href="{{ widget.create_url }}"
         target="{{ widget.id }}_create_window">
        {{ widget.create_btn_text }}
      </a>
    {% endif %}
    {% block extra_buttons %}{% endblock %}
  </div>
  {%- endif %}
</div>
