{% extends "FOSUserBundle::layout.html.twig" %}

{% import "PackagistWebBundle::macros.html.twig" as macros %}

{% block fos_user_content %}
<section class="col-md-9">
    {%- if app.user.apiToken %}
        <h3 class="font-normal profile-title">{{ 'profile.your_api_token'|trans }}</h3>

        <div class="input-group api-token-group clearfix">
            <input id="api-token" type="text" class="form-control" value="" data-api-token="{{ app.user.apiToken }}" readonly="readonly">
            <span class="input-group-btn">
                <button class="btn btn-success btn-show-api-token" type="button">{{ 'profile.show_api_token'|trans }}</button>
            </span>
        </div>

        <p>{{ 'profile.api_token_explain'|trans({ '%path_about%':path('about') })|raw }}</p>

        <hr>
    {%- endif %}

    {% if githubSync is not null and githubSync.createdAt|date('YmdHis') > '-2 days'|date('YmdHis') %}
        <h3 class="font-normal">GitHub Hook Sync</h3>
        {% if githubSync.completedAt is null %}
            <p>Still running... <a href="{{ path('fos_user_profile_show') }}">Refresh</a></p>
        {% elseif githubSync.status == 'errored' %}
            <p>An unexpected error occurred during sync.</p>
        {% else %}
            <p>Completed at {{ githubSync.completedAt|date('Y-m-d H:i:s') }} UTC, <a href="{{ path('user_github_sync') }}">retry hook sync</a>.</p>
            {% if githubSync.result.results is defined %}
                <h4>{{ githubSync.result.results.hooks_setup }} hooks setup/updated</h4>
                <h4>{{ githubSync.result.results.hooks_ok_unchanged }} hooks already setup and left unchanged</h4>
                {% if githubSync.result.results.hooks_failed|length > 0 %}
                    <h4>Hooks setup failures</h4>
                    {% for fail in githubSync.result.results.hooks_failed %}
                        <p><a href="{{ path('view_package', {name: fail.package}) }}">{{ fail.package }}</a> {{ fail.reason|raw }}</p>
                    {% endfor %}
                {% endif %}
            {% endif %}
        {% endif %}
    {% endif %}

    {% embed "PackagistWebBundle:web:list.html.twig" with {noLayout: 'true', showAutoUpdateWarning: true} %}
        {% block content_title %}
            <h3 class="font-normal">{{ 'packages.yours'|trans }}</h3>
        {% endblock %}
    {% endembed %}

    {%- if deleteForm is defined %}
        <form class="delete action" action="{{ path('user_delete', {name: user.username}) }}" method="POST">
            {{ form_widget(deleteForm._token) }}
            <input class="btn btn-danger" type="submit" value="Delete Account Permanently" onclick="return confirm('Are you sure? There is no way back..');" />
        </form>
    {%- endif %}
</section>
{% endblock %}
