{% extends "base.html" %}
{% block main %}
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <h2>Welcome to Timesketch</h2>
                    {% if last_sketch %}
                        <p>
                            The last sketch that you worked on was <a href="{{ url_for('sketch_views.explore', sketch_id=last_sketch.sketch.id) }}">{{ last_sketch.sketch.name }}</a>.
                        </p>
                    {% endif %}
                    <br>
                    <div class="btn-group">
                        <div class="pull-left" style="margin-right:10px;margin-top: -6px;">
                            <form action="{{ url_for('home_views.home') }}" method="post">
                                {{ form.name }}
                                {{ form.description }}
                                <button type="submit" class="btn btn-success"><i class="fa fa-plus"></i> Create new sketch</button>
                                {{ form.csrf_token }}
                            </form>
                        </div>
                        {% if upload_enabled %}
                            <ts-core-upload class="pull-left" style="margin-left:5px;margin-top: -6px;"></ts-core-upload>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        {% if upload_enabled %}
            <ts-core-upload-queue></ts-core-upload-queue>
        {%  endif %}

        <div class="card">
            <form class="form form-inline" method="get" action="{{ url_for('home_views.home') }}">
                <input type="search" id="q" name="q" class="search-input" placeholder="Search sketches" value="{{ query }}" autofocus>
            </form>
            <br>
            {% if not sketches.all() %}
                <form action="{{ url_for('home_views.home') }}" method="post">
                    No sketches found
                </form>
            {% else %}
                <table class="table table-hover table-striped">
                    <thead>
                    <tr>
                        <th>Sketch</th>
                        <th width="110">Created by</th>
                        <th width="60">Status</th>
                        <th width="80">Timelines</th>
                        <th width="100">Saved views</th>
                        <th width="130px">Last activity</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for sketch in sketches.all() %}
                        <tr>
                            <td><a href="{{ url_for('sketch_views.overview', sketch_id=sketch.id) }}">{{ sketch.name }}</a></td>
                            <td>{{ sketch.user.name }}</td>
                            <td>{{ sketch.get_status.status }}</td>
                            <td style="text-align: center;"><a href="{{ url_for('sketch_views.timelines', sketch_id=sketch.id) }}">{{ sketch.timelines|count }}</a></td>
                            <td style="text-align: center;"><a href="{{ url_for('sketch_views.views', sketch_id=sketch.id) }}">{{ sketch.get_named_views|count }}</a></td>
                            <td>{{ sketch.updated_at.strftime('%Y-%m-%d %H:%M') }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            {% endif %}
        </div>
    </div>
{% endblock %}