{#
 # For the full copyright and license information, please view the
 # docs/licenses/LICENSE.txt file that was distributed with this source code.
 #}

{% set actions = column.options.actions %}

{% if actions is not empty %}
    {% set inlineActions = [] %}
    {% set regularActions = [] %}

    {% for action in actions %}
      {% if action.isApplicable(record) %}
        {% if action.options['use_inline_display'] == true %}
            {% set inlineActions = inlineActions|merge([action]) %}
          {% else %}
            {% set regularActions = regularActions|merge([action]) %}
        {% endif %}
      {% endif %}
    {% endfor %}

    <div class="btn-group-action text-right">
      {% if inlineActions is not empty %}
        <div class="btn-group btn-group-inline d-flex justify-content-start">
          {% for inlineAction in inlineActions -%}
              {% set class = 'dropdown-item inline-dropdown-item ' ~ inlineAction.options.attr.class|default('') %}

              {{ include('@PrestaShop/Admin/Common/Grid/Actions/Row/' ~ inlineAction.type ~ '.html.twig', {
                grid: grid,
                column: column,
                attributes: {class: class|trim, tooltip_name: true},
                record: record,
                action: inlineAction,
              }) }}
          {% endfor %}
        </div>
      {% endif %}

      {% if regularActions is not empty %}
        <div class="btn-group">
          {% set skippedActions, isFirstRendered = 0, false %}

          {# Render first item that is not in dropwdown #}
          {% for action in regularActions %}
            {% if not isFirstRendered %}
              {% set skippedActions = skippedActions + 1 %}
            {% endif %}

            {% if not isFirstRendered %}
              {% set class = 'dropdown-item ' ~ action.options.attr.class|default('') %}

              {{ include('@PrestaShop/Admin/Common/Grid/Actions/Row/' ~ action.type ~ '.html.twig', {
                grid: grid,
                column: column,
                attributes: {class: class|trim, tooltip_name: true},
                record: record,
                action: action,
              }) }}

              {% set isFirstRendered = true %}
            {% endif %}
          {% endfor %}

          {# Render remaining items in dropdown #}
          {% if regularActions|length > skippedActions %}
            <a class="btn btn-link dropdown-toggle dropdown-toggle-dots dropdown-toggle-split no-rotate"
               data-toggle="dropdown"
               aria-haspopup="true"
               aria-expanded="false"
            >
            </a>

            <div class="dropdown-menu dropdown-menu-right">
              {% for action in regularActions|slice(skippedActions) %}
                {{ include('@PrestaShop/Admin/Common/Grid/Actions/Row/' ~ action.type ~ '.html.twig', {
                  grid: grid,
                  column: column,
                  attributes: {class: 'dropdown-item', tooltip_name: false},
                  record: record,
                  action: action,
                }) }}
              {% endfor %}
            </div>
          {% endif %}
        </div>
      {% endif %}
    </div>
{% endif %}
