{% extends 'Admin/layout.html.twig' %}

{% trans_default_domain 'form' %}

{% block body %}
    {{ knp_menu_render('actions_companies') }}

    {# Search form #}
    <form action="{{ path('company_index') }}" class="search-admin" method="get">
        <fieldset>
            <div class="search-fields">
                <p>
                    <label for="form_search_name">{{ 'form.name.label'|transchoice(1, []) }}</label>
                    <input id="form_search_name" name="name" type="search" value="{{ app.request.query.get('name', '') }}"/>
                </p>
            </div>
        </fieldset>
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}"/>
        </p>
    </form>

    <table class="tableBo">
        <thead>
            <tr>
                <th>{{ 'form.logo.label'|trans }}</th>
                <th>{{ 'form.name.label'|trans }}</th>
                <th>{{ 'form.description.label'|trans }}</th>
                <th>{{ 'form.website.label'|trans }}</th>
                <th>{{ 'form.availableForUsers.label'|trans }}</th>
                <th colspan="2">{{ 'word.actions'|trans({}, 'word') }}</th>
            </tr>
        </thead>
        <tbody>
        {% for company in companies %}
            <tr class="delete-element-container">
                <td class="center">
                {% if vich_uploader_asset(company, 'logoFile') is null %}
                   
                {% else %}
                     <a href="{{ path('company_edit', {id:company.id}) }}">
                        <img alt="" src="{{ vich_uploader_asset(company, 'logoFile')|imagine_filter('30H') }}"/>
                    </a>
                {% endif %}

                   
                </td>
                <td><a href="{{ path('company_edit', {id:company.id}) }}">{{ company.name }}</a></td>
                <td>{{ company.description|truncate(100, '…') }}</td>
                <td>
                    <a
                        href="{{ company.website }}" target="_blank"
                        title="{{ 'action.goto.website'|trans({}, 'action') }}"
                    >
                        {{ company.website }}
                    </a>
                </td>
                <td class="center">
                    <input
                        {% if company.availableForUsers %} checked{% endif %}
                        {% if company.users|length > 0 %}
                            disabled
                        {% else %}
                            class="input-active"
                            data-type="is_active"
                            data-url="{{ path('company_enable', {id:company.id})}}"
                            id="user-{{ company.id }}-active"
                            value="{{ company.id }}"
                        {% endif %}
                        type="checkbox"
                    />
                    <span
                        class="checkbox"
                        {% if company.users|length > 0 %}
                            title= "{{ 'notice.company.disabled.failure'|trans({}, 'notice') }}"
                        {% endif %}
                    ></span>
                </td>
                <td class="action">
                    <a
                        class="edit"
                        href="{{ path('company_edit', {id:company.id}) }}"
                        title="{{ 'action.edit.label'|trans({}, 'action') }} : {{ company.name }}"
                    >
                        <span>{{ 'action.edit.label'|trans({}, 'action') }}</span>
                    </a>
                </td>
                <td class="action">
                    {% if company.isDeletable() %}
                        <a
                            class="delete-element "
                            href="{{ path('company_delete', {id:company.id}) }}"
                            title="{{ 'action.delete.label'|trans({}, 'action') }} : {{ company.name }}"
                        >
                            <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                        </a>
                    {% else %}
                        <button
                            class="delete-element"
                            disabled
                            title= "{{ 'notice.company.removed.failure'|trans({}, 'notice') }}"
                        >
                            <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                        </button>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    {{ include('Admin/Paginator/pagination.html.twig', {pages:nb_pages}) }}
{% endblock %}
