{% extends 'admin/layout.html.twig' %}

{% set menu = 'admin_reward_point_logs' %}

{% set script_controller = 'log/list' %}

{% block main %}

  {{ web_macro.flash_messages() }}

  <form class="well well-sm form-inline">

    <div class="form-group">
      <input type="text" id="startDateTime" value="{{ app.request.query.get('startDateTime') }}" name="startDateTime"
             class="form-control" placeholder="{{ 'form.placeholder.start_date'|trans }}" style="width:150px;">
    </div>

    <div class="form-group">
      <input type="text" id="endDateTime" value="{{ app.request.query.get('endDateTime') }}" name="endDateTime"
             class="form-control" placeholder="{{ 'form.placeholder.end_date'|trans }}" style="width:150px;">
    </div>

    <div class="form-group">
      <input type="text" id="nickname" name="nickname" value="{{ app.request.query.get('nickname') }}"
             class="form-control" placeholder="{{ 'user.fields.username_label'|trans }}" style="width:120px;">
    </div>

    <button class="btn btn-primary">{{ 'form.btn.search'|trans }}</button>

  </form>

  <table class="table table-hover" id="log-table">
    <tr>
      <th width="15%">{{ 'admin.system_log.username'|trans }}</th>
      <th width="55%">{{ 'admin.system_log.operation'|trans }}</th>
      <th width="20%">{{ 'admin.system_log.time_and_ip'|trans }}</th>
    </tr>
    {% for log in logs %}
      {% set operator = operators[log.userId]|default(null) %}
      <tr>
        <td>
          {% if operator and log.module != 'crontab' %}
            {{ admin_macro.user_link(operator) }}
          {% else %}
            --
          {% endif %}
        <td>
          <div style="word-break: break-all;word-wrap: break-word;">
            {% if log.data %}
              {% set user = users[log.data['userId']]|default(null) %}
              {% if log.data['type']=='inflow' %}
                {{ 'admin.reward_point_account.log_grant'|trans({'%amount%':log.data['amount']|default(0),'%name%':setting('reward_point').name|default('admin.reward_point'|trans)}) }}{{ admin_macro.user_link(user) }}{{ 'admin.reward_point_account'|trans }}
              {% elseif log.data['type']=='outflow' %}
                {{ 'admin.reward_point_account.log_deduction_by'|trans }}{{ admin_macro.user_link(user) }}{{ 'admin.reward_point_account.log_deduction'|trans({'%amount%':log.data['amount']|default(0),'%name%':setting('reward_point').name|default('admin.reward_point'|trans)}) }}
              {% endif %}
              {{ 'reward_point_account.note'|trans}}：{% if log.data['note'] %}{{ log.data['note'] }}{% else %}{{ 'admin.reward_point_account.note_empty'|trans }}{% endif %}
            {% endif %}
          </div>
        </td>
        <td>
          <span class="">{{ log.createdTime|date("Y-m-d H:i:s") }}</span>
          <br/>
          <a class="text-muted text-sm" href="http://www.baidu.com/s?wd={{ log.ip }}" target="_blank">{{ convert_ip(log.ip) }}</a>
        </td>
      </tr>
    {% else %}
      <tr><td class="empty" colspan="20">{{ 'user.account.empty'|trans }}</tr>
    {% endfor %}
  </table>

  {{ admin_macro.paginator(paginator) }}

{% endblock %}