{% extends "base.html" %}
{% block head %}
{% endblock %}
{% block body %}
    <div class="jumbotron">
        <div class="container">
            {% if editsuccess == 'True' %}
                <div class="alert alert-success alert-dismissible" role="alert">
                <i class="nav-item fas fa-check-circle"></i>
                ID successfully edited (see below)
                </div>
            {% endif %}
            {% if result is not none %}
                <table class="table table-striped table-hover">
                    <thead class="thead-dark">
                        <tr>
                            <th>Namespace</th>
                            <th>Keyword</th>
                            <th>ID</th>
                            <th>URL</th>
                            <th>Hits</th>
                            <th>Created</th>
                            <th>Last Hit</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for result in results %}
                        <tr>
                            <td>
                                {% if result['namespace_name'] == 'global' %}
                                    {% set urlpath = '' %}
                                {% elif result['namespace_name'] == 'user' %}
                                    {% set urlpath = '/~' + username %}
                                {% else %}
                                    {% set urlpath = '/' + result['namespace_name'] %}
                                {% endif %}
                                <i class="fas {{ result['icon'] }}"></i> {{ result['namespace_name'] }}
                            </td>
                            <td>
                                {% if result['keyword'] %}
                                    <a href="{{ urlpath }}/{{ result['keyword'] }}" target="_blank">
                                  {{ result['keyword'] }}
                                    </a>
                                {% endif %}
                            </td>
                            <td>
                                <a href="/{{ result['id']|shortcode }}" target="_blank">{{ result['id']|shortcode }}
                            </a>
                            <td><a href="{{ result['url'] }}" title="{{ result['url'] }}" target="_blank">{{ result['url']|elipses(50) }}</a></td>
                            <td>{{ result['hit'] }}</td>
                            <td>{{ result['createTime']|humantime }}</td>
                            <td>{{ result['lastUsed']|humantime }}</td>
                            <td>
                                <a class="text-dark" href="/_edit?id={{ result['id']|shortcode }}"><i class="nav-item fas fa-edit"></i></a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>

<!-- Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="deleteModalLabel">Delete Shortcut?</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          This will delete the shortcut to:
          This operation is final and cannot be undone.
      </div>
      <div class="modal-footer">
          Are you sure?
          <button type="button" class="btn btn-danger">Yes</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
      </div>
    </div>
  </div>
</div>
            {% else %}
                <p> You don't have any shortcuts created.  You can add them from <a href="/">home</a></p>
            {% endif %}
        </div>
    </div>
    <script>
        $( document ).ready(function() {
            $('#exampleModal').on('show.bs.modal', function (event) {
                var button = $(event.relatedTarget)
                var shortid = button.data('whatever')
                var modal = $(this)
                modal.find('.modal-title').text('Delete' + shortid)
            })
        });
    </script>
{% endblock %}
