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

{% import '@PrestaShop/Admin/macros.html.twig' as ps %}

{% set messagesToShow = 4 %}

<div class="card mt-2" data-role="message-card" >
  <div class="card-header">
    <div class="row">
      <div class="col-md-6">
        <h3 class="card-header-title">
          <i class="material-icons">message</i> {{ 'Messages'|trans({}, 'Admin.Global') }} ({{ orderForViewing.messages.total }})
        </h3>
      </div>
      {% if orderForViewing.messages.total > messagesToShow %}
        <div class="col-md-6 text-right">
          <a
            href="#"
            data-toggle="modal"
            data-target="#view_all_messages_modal"
            class="d-print-none js-open-all-messages-btn"
          >
            {{ 'View full conversation'|trans({}, 'Admin.Orderscustomers.Feature') }}
          </a>
        </div>
      {% endif %}
    </div>
  </div>

  {% if orderForViewing.messages.messages is not empty %}
    <ul class="list-unstyled messages-block">
      {% for message in orderForViewing.messages.messages|slice(0, messagesToShow)|reverse %}
        {{ include('@PrestaShop/Admin/Sell/Order/Order/Blocks/View/msg_list_item.html.twig') }}
      {% endfor %}
    </ul>
  {% endif %}

  <div class="card-body d-print-none">
    {{ form_start(orderMessageForm, {
      action: path('admin_orders_send_message', {orderId: orderForViewing.id}),
    }) }}

    {{ ps.form_group_row(orderMessageForm.order_message, {}, {
      label: 'Choose your order message'|trans({}, 'Admin.Orderscustomers.Feature'),
      label_on_top: true,
      class: 'mb-0',
    }) }}

    <div class="js-order-messages-container d-none">
      <div class="js-message-change-warning">{{ 'Do you want to overwrite your existing message?'|trans({}, 'Admin.Orderscustomers.Notification') }}</div>
      {% for id, message in orderMessageForm.vars['messages'] %}
        <div data-id="{{ id }}">
          {{ message }}
        </div>
      {% endfor %}
    </div>

    <div class="form-group row configure">
      <div class="col-sm">
        <a href="{{ path('admin_order_messages_index') }}" class="configure-link">
          {{ 'Configure predefined messages'|trans({}, 'Admin.Orderscustomers.Feature') }}
          <i class="material-icons rtl-flip">arrow_right_alt</i>
        </a>
      </div>
    </div>

    {{ ps.form_group_row(orderMessageForm.is_displayed_to_customer, {material_design: true}) }}

    {{ ps.form_group_row(orderMessageForm.message, {attr: {cols: 30, rows: 3}}, {
      label: 'Message'|trans({}, 'Admin.Global'),
      label_on_top: true,
      class: 'js-text-with-length-counter',
    }) }}

    {% block order_message_form_rest %}
      {{ form_rest(orderMessageForm) }}
    {% endblock %}

    <div class="text-right">
      <button type="submit" class="btn btn-primary">{{ 'Send message'|trans({}, 'Admin.Orderscustomers.Feature') }}</button>
    </div>

    {{ form_end(orderMessageForm) }}
  </div>
</div>
