{% import "common/data-dict-macro.html.twig" as dict_macro %}
{% import "macro.html.twig" as web_macro %}
{% extends 'admin/layout.html.twig' %}

{% set script_controller = 'order/refunds' %}
{% set menu = 'admin_order_refunds_manage' %}

{% block main %}
  {{ web_macro.flash_messages() }}
  <form id="user-search-form" class="form-inline well well-sm" action="" method="get" novalidate>
    <div class="mbm">
      <div class="form-group">
        <label class="ptm">{{ 'admin.order.screen_condition'|trans }}</label>
        <select class="form-control" name="refundItemType">
          {{ select_options(dict('refundItemType'), app.request.get('refundItemType'), 'order.refund.item_type'|trans) }}
        </select>
        <select class="form-control" name="status">
          {{ select_options(dict('refundDisplayStatus'), app.request.get('status'), 'admin.order_refund.status.default'|trans) }}
        </select>
      </div>
    </div>

    <div class="mbm">
      <div class="form-group">
        <label class="ptm">{{ 'form.placeholder.keyword'|trans }}：</label>
        <input class="form-control" type="text" name="nickname" value="{{ app.request.get('nickname') }}" placeholder="{{'admin.order_refund.nickname.input_placeholder'|trans}}">
        <input class="form-control" type="text" name="titleLike" value="{{ app.request.get('titleLike') }}"
               placeholder="{{ 'admin.order_refund.title.placeholder'|trans }}"
        >
        <input class="form-control" type="text" name="orderSn" value="{{ app.request.get('orderSn') }}" placeholder="{{'order.id'|trans}}">
        <input class="form-control" type="text" name="orderRefundSn" value="{{ app.request.get('orderRefundSn') }}" placeholder="{{'admin.order_refund.sn'|trans}}">
        <button class="btn btn-primary">{{'form.btn.search'|trans}}</button>

      </div>

    </div>


  </form>

  <table class="table table-striped table-hover" id="refunds-table">
    <thead>
      <tr>
        <th width="30%">{{'admin.order_refund.title'|trans}}</th>
        <th>{{'admin.order_refund.order_amount'|trans}}</th>
        <th>{{'admin.order_refund.refund_person'|trans}}</th>
        <th>{{'admin.order_refund.refund_created_time'|trans}}</th>
        <th>{{'admin.order_refund.refund_status'|trans}}</th>
        <th>{{'admin.order_refund.operator'|trans}}</th>
        <th>{{'admin.order_refund.operation'|trans}}</th>
      </tr>
    </thead>
    <tbody>
      {% if refunds %}
        {% for refund in refunds %}
          {% set order = orders[refund.order_id] %}
          {% set user = users[refund.created_user_id] %}
          <tr>
            <td>
              <a href="javascript:" data-url="{{ path('admin_order_detail', {id:refund.order_id}) }}" data-toggle="modal" data-target="#modal">{{ refund.title }}</a>
              <div class="text-muted text-sm">{{'order.id'|trans}}：{{ order.sn }}</div>
              {#<div class="text-muted text-sm">#}
              {#{{'admin.order_refund.reason'|trans}}：{{ refund.reason }} #}
              {#</div>#}
              <div class="text-muted text-sm">
                {{ 'admin.order_refund.sn'|trans }}：{{ refund.sn }}
              </div>
            </td>
            <td>{{ refund.amount|to_cash(0) }}</td>
            <td>
              {% if has_permission('admin_user_manage') %}
                <a href="javascript:" class="" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_user_show', {id:user.id}) }}">{{ user.nickname|default('--') }}</a>
              {% else %}
                <span><a target="_blank" href="{{ path('user_show', {id: user.id}) }}">{{ user.nickname|default('--') }}</a></span>
              {% endif %}
            </td>
            <td>
              {{ refund.created_time|date('Y-n-d H:i') }}
            </td>
            <td>
              {{ dict_macro.adminRefundStatus(refund.status) }}
            </td>
            <td>
              {% if refund.deal_user_id != 0 %}
                {% if has_permission('admin_user_manage') %}
                  <a href="javascript:" class="" data-toggle="modal" data-target="#modal" data-url="{{ path('admin_user_show', {id:refund.deal_user_id}) }}">{{ users[refund.deal_user_id].nickname|default('--') }}</a>
                {% else %}
                  <span><a target="_blank" href="{{ path('user_show', {id: refund.deal_user_id}) }}">{{ users[refund.deal_user_id].nickname|default('--') }}</a></span>
                {% endif %}
              {% else %}
                --
              {% endif %}
            </td>
            <td>
              {% if refund.status == 'auditing' %}
                <button class="btn btn-sm btn-primary confirm-refund" aria-hidden="true" data-backdrop="static" type="button" data-target="#modal" data-toggle="modal" data-url="{{ path('admin_order_audit_refund', {refundId:refund.id}) }}">{{'admin.order_refund.audit_refund_btn'|trans}}</button>
              {% else %}
                <a href="javascript:" data-url="{{ path('admin_order_refund_detail', {id : refund.id}) }}" data-toggle="modal" data-target="#modal" >{{ 'order.refund.detail'|trans }}</a>
              {% endif %}
            </td>
          </tr> 
        {% endfor %}
      {% else %}
        <tr><td colspan="20"><div class="empty">{{'admin.order_refund.empty_hint'|trans}}</div></td></tr>
      {% endif %}
    </tbody>
  </table>

  <div class="paginator">
    {{ admin_macro.paginator(paginator) }} 
  </div>
{% endblock %}
