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

{% block html_title %}{{ customTitle(t('External Account management')) }}{% endblock %}

{% block content_header %}
<div class="header-wrap">
  <header id="page-header">
    <h1 id="admin-title" class="title">{{ t('User management') }}/{{ t('External Account management') }}</h1>
  </header>
</div>
{% endblock %}

{% block content_main %}
<div class="content-main">
  {% set wmessage = req.flash('warningMessage') %}
  {% if wmessage.length %}
  <div class="alert alert-warning">
    {{ wmessage }}
  </div>
  {% endif %}

  {% set smessage = req.flash('successMessage') %}
  {% if smessage.length %}
  <div class="alert alert-success">
    {{ smessage }}
  </div>
  {% endif %}

  {% set emessage = req.flash('errorMessage') %}
  {% if emessage.length %}
  <div class="alert alert-danger">
    {{ emessage }}
  </div>
  {% endif %}

  <div class="row">
    <div class="col-md-3">
      {% include './widget/menu.html' with {current: 'external-account'} %}
    </div>

    <div class="col-md-9">
      <p>
        <a class="btn btn-default" href="/admin/users">
          <i class="icon-fw ti-arrow-left" aria-hidden="true"></i>
          ユーザー管理に戻る
        </a>
      </p>

      <h2>外部アカウント一覧</h2>

      <table class="table table-bordered table-user-list">
        <thead>
          <tr>
            <th width="120px">Authentication Provider</th>
            <th><code>accountId</code></th>
            <th>関連付けられているユーザーの <code>username</code></th>
            <th>
              パスワード設定
              <a class="text-muted"
                  data-toggle="popover" data-placement="top"
                  data-trigger="hover focus" tabindex="0" role="button" {# dismiss settings #}
                  data-animation="false" data-html="true"
                  data-content="<small>関連付けられているユーザーがパスワードを設定しているかどうかを表示します</small>">
                <small>
                  <i class="icon-question" aria-hidden="true"></i>
                </small>
              </a>
            </th>
            <th width="100px">{{ t('user_management.Date created') }}</th>
            <th width="70px"></th>
          </tr>
        </thead>
        <tbody>
          {% for account in accounts %}
          <tr>
            <td>{{ account.providerType }}</td>
            <td>
              <strong>{{ account.accountId }}</strong>
            </td>
            <td>
              <strong>{{ account.user.username }}</strong>
            </td>
            <td>
              {% if account.user.password != null %}
              <span class="label label-info">
                設定済み
              </span>
              {% else %}
              <span class="label label-warning">
                未設定
              </span>
              {% endif %}
            </td>
            <td>{{ account.createdAt|date('Y-m-d', account.createdAt.getTimezoneOffset()) }}</td>
            <td>
              <div class="btn-group admin-user-menu">

                <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                  <i class="icon-settings"></i> <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu">
                  <li class="dropdown-header">{{ t('user_management.Edit menu') }}</li>
                  <form id="form_remove_{{ loop.index }}" action="/admin/users/external-accounts/{{ account._id.toString() }}/remove" method="post">
                    <input type="hidden" name="_csrf" value="{{ csrf() }}">
                  </form>
                  <li>
                    <a href="javascript:form_remove_{{ loop.index }}.submit()">
                      <i class="icon-fw icon-fire text-danger"></i>
                      削除する
                    </a>
                  </li>
                </ul>{# end of .dropdown-menu #}



              </div>{# end of .btn-group #}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>

      {% include '../widget/pager.html' with {path: "/admin/users/external-accounts", pager: pager} %}

    </div>
  </div>
</div>
{% endblock content_main %}

{% block content_footer %}
{% endblock content_footer %}


