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

{% block scripts %}
    <script src="{{ asset('bundles/packagistweb/js/view.js?v=2')}}"></script>
{% endblock %}

{% block content %}
    <div class="box">
        <div class="package">
            <h1>
                <a href="{{ path("view_vendor", {"vendor": package.vendor}) }}">{{ package.vendor }}/</a>{{ package.packageName }}
            </h1>
            {% if package.versions|length and package.versions[0].tags|length %}
                <p class="tags">
                    {%- for tag in package.versions[0].tags -%}
                        <a href="{{ url("browse", { "tag" : tag.name }) }}">{{ tag.name }}</a>
                    {%- endfor -%}
                </p>
            {% endif %}

            <p class="description">{{ package.description }}</p>
            <p class="details">
                <span>Maintainer{{ package.maintainers|length > 1 ? 's' : '' }}:</span>
                {% for maintainer in package.maintainers %}
                    <a href="{{ path('user_profile', {'name': maintainer.username}) }}">{{ maintainer.username }}</a>{{ loop.last ? '' : ', ' }}
                {% endfor %}
                {% if form is defined %}(<a id="add-maintainer" href="{{ path('add_maintainer', {'name': package.name}) }}">add maintainer</a>){% endif %}
                <br />
                {% if package.versions|length and package.versions[0].homepage %}
                    <span>Homepage:</span> <a href="{{ package.versions[0].homepage }}">{{ package.versions[0].homepage|replace({'http://': ''}) }}</a><br />
                {% endif %}
                <span>Repository:</span> <a href="{{ package.repository }}">{{ package.repository }}</a>
            </p>

            {% if form is defined %}
                <div>
                    <form id="add-maintainer-form" class="{{ show_maintainer_form|default(false) ? '': 'hidden' }}" action="{{ path('add_maintainer', {'name': package.name}) }}" method="POST" {{ form_enctype(form) }}>
                        <div>
                            <h2>Add Maintainer</h2>
                            <p>
                                {{ form_label(form.user, "Username") }}
                                {{ form_errors(form.user) }}
                                {{ form_widget(form.user) }}
                            </p>
                            {{ form_rest(form) }}
                            <input id="submit" type="submit" value="Submit" />
                        </div>
                    </form>
                </div>
            {% endif %}

            {% if package.versions|length %}
                <ul class="versions">
                    {% for version in package.versions %}
                        <li class="version{% if loop.last %} last{% endif %}">
                            <section>
                                <h1>
                                    {{ version.version }}
                                    <span class="release-date">{{ version.releasedAt|date("Y-m-d") }}</span>
                                    <span class="license">{{ version.license ? version.license|join(', ') : '' }}</span>
                                </h1>

                                <div class="details {% if loop.index0 == 0 %} open{% endif %}">
                                    <h2 class="authors">Author{{ version.authors|length > 1 ? 's' : '' }}</h2>
                                    <ul>
                                        {% for author in version.authors %}
                                            <li>
                                                {%- if author.homepage -%}
                                                    <a href="{{ author.homepage }}">{{ author.name }}</a>
                                                {%- else -%}
                                                    {{ author.name }}
                                                {%- endif -%}
                                                {% if author.email %} &lt;<a href="mailto:{{ author.email }}">{{ author.email }}</a>&gt;{% endif -%}
                                            </li>
                                        {% endfor %}
                                    </ul>
                                    <div class="clearfix package-links">
                                        <div class="requires">
                                            <h2>Requires</h2>
                                            {% if version.require|length %}
                                                <ul>
                                                    {%- for req in version.require -%}
                                                        <li>{{ req.packageName }}: {{ req.packageVersion }}</li>
                                                    {%- endfor -%}
                                                </ul>
                                            {% else %}
                                                None
                                            {% endif %}
                                        </div>
                                        <div class="recommends">
                                            <h2>Recommends</h2>
                                            {% if version.recommend|length %}
                                                <ul>
                                                    {%- for req in version.recommend -%}
                                                        <li>{{ req.packageName }}: {{ req.packageVersion }}</li>
                                                    {%- endfor -%}
                                                </ul>
                                            {% else %}
                                                None
                                            {% endif %}
                                        </div>
                                        <div class="suggests">
                                            <h2>Suggests</h2>
                                            {% if version.suggest|length %}
                                                <ul>
                                                    {%- for req in version.suggest -%}
                                                        <li>{{ req.packageName }}: {{ req.packageVersion }}</li>
                                                    {%- endfor -%}
                                                </ul>
                                            {% else %}
                                                None
                                            {% endif %}
                                        </div>
                                        <div class="provides">
                                            <h2>Provides</h2>
                                            {% if version.provide|length %}
                                                <ul>
                                                    {%- for req in version.provide -%}
                                                        <li>{{ req.packageName }}: {{ req.packageVersion }}</li>
                                                    {%- endfor -%}
                                                </ul>
                                            {% else %}
                                                None
                                            {% endif %}
                                        </div>
                                        <div class="conflicts">
                                            <h2>Conflicts</h2>
                                            {% if version.conflict|length %}
                                                <ul>
                                                    {%- for req in version.conflict -%}
                                                        <li>{{ req.packageName }}: {{ req.packageVersion }}</li>
                                                    {%- endfor -%}
                                                </ul>
                                            {% else %}
                                                None
                                            {% endif %}
                                        </div>
                                        <div class="replaces">
                                            <h2>Replaces</h2>
                                            {% if version.replace|length %}
                                                <ul>
                                                    {%- for req in version.replace -%}
                                                        <li>{{ req.packageName }}: {{ req.packageVersion }}</li>
                                                    {%- endfor -%}
                                                </ul>
                                            {% else %}
                                                None
                                            {% endif %}
                                        </div>
                                    </div>
                                </div>
                                <div class="details-toggler{% if loop.index0 == 0 %} open{% endif %}"></div>
                            </section>
                        </li>
                    {% endfor %}
                </ul>
            {% elseif package.crawledAt is null %}
                <p>This package has not been crawled yet, some information is missing.</p>
            {% else %}
                <p>This package has no released version yet, and little information is available.</p>
            {% endif %}
        </div>
    </div>
{% endblock %}