{% extends '@ChillMain/layout.html.twig' %}

{% import '@ChillMain/Workflow/macro_breadcrumb.html.twig' as macro %}

{% block title %}
    {{ 'workflow.My workflows'|trans }}
{% endblock %}

{% block content %}
<div class="col-12 workflow">

    <h1 class="mb-5">{{ block('title') }}</h1>


    <ul class="nav nav-pills justify-content-center">
        <li class="nav-item">
            <a href="{{ path('chill_main_workflow_list_subscribed') }}"
                class="nav-link {% if step == 'subscribed' %}active{% endif %}">
                {{ 'workflow.subscribed'|trans }}
            </a>
        </li>
        <li class="nav-item">
            <a href="{{ path('chill_main_workflow_list_dest') }}"
                class="nav-link {% if step == 'dest' %}active{% endif %}">
                {{ 'workflow.dest'|trans }}
            </a>
        </li>
        <li class="nav-item">
            <a href="{{ path('chill_main_workflow_list_cc') }}"
                class="nav-link {% if step == 'cc' %}active{% endif %}">
                {{ 'workflow.cc'|trans }}
            </a>
        </li>
        <li class="nav-item">
            <a href="{{ path('chill_main_workflow_list_previous_without_reaction') }}"
               class="nav-link {% if step == 'previous_without_reaction' %}active{% endif %}">
                {{ 'workflow.Previous dest without reaction'|trans }}
            </a>
        </li>
        <li class="nav-item">
            <a href="{{ path('chill_main_workflow_list_previous_transitionned') }}"
               class="nav-link {% if step == 'previous_transitionned' %}active{% endif %}">
                {{ 'workflow.Previous transitionned'|trans }}
            </a>
        </li>
    </ul>

    {% if help is defined %}
        <p style="margin-top: 2rem;">{{ help|trans }}</p>
    {% endif %}

    {% if workflows|length == 0 %}
        <p class="chill-no-data-statement">{{ 'workflow.No workflow'|trans }}</p>
    {% else %}
        <div class="flex-table accordion accordion-flush" id="workflow-fold">
        {% for l in workflows %}
            <div class="item-bloc">
                <div class="accordion-header" id="flush-heading-{{ l.entity_workflow.id }}">
                    <button type="button" class="accordion-button collapsed"
                        data-bs-toggle="collapse" data-bs-target="#flush-collapse-{{ l.entity_workflow.id }}"
                        aria-expanded="false" aria-controls="flush-collapse-{{ l.entity_workflow.id }}">

                        <div class="item-row col">
                            <h2>
                                {{ l.handler.entityTitle(l.entity_workflow) }}
                            </h2>
                        </div>

                    </button>
                    <div>
                        {{ macro.breadcrumb(l.entity_workflow) }}
                        {% if l.entity_workflow.isOnHoldAtCurrentStep %}
                            <span class="badge bg-success rounded-pill" title="{{ 'workflow.On hold'|trans|escape('html_attr') }}">{{ 'workflow.On hold'|trans }}</span>
                        {% endif %}
                    </div>

                </div>
                <div id="flush-collapse-{{ l.entity_workflow.id }}"
                    class="accordion-collapse collapse"
                    aria-labelledby="flush-heading-{{ l.entity_workflow.id }}"
                    data-bs-parent="#workflow-fold">

                    <div class="item-row flex-column">
                        {% include l.handler.template(l.entity_workflow) with l.handler.templateData(l.entity_workflow)|merge({
                            'display_action': false
                        }) %}
                    </div>
                    <div class="item-row">
                        <div class="item-col flex-grow-1">
                            <p>
                                {% if l.entity_workflow.isUserSubscribedToStep(app.user) %}
                                    <i class="fa fa-check fa-fw"></i>
                                    {{ 'workflow.you subscribed to all steps'|trans }}
                                {% endif %}
                            </p>
                            <p>
                                {% if l.entity_workflow.isUserSubscribedToFinal(app.user) %}
                                    <i class="fa fa-check fa-fw"></i>
                                    {{ 'workflow.you subscribed to final step'|trans }}
                                {% endif %}
                            </p>
                        </div>
                        <div class="item-col">
                            <ul class="record_actions">
                                {% if is_granted('CHILL_MAIN_WORKFLOW_DELETE', l.entity_workflow) %}
                                    <li>
                                        <a class="btn btn-delete"
                                           href="{{ chill_path_add_return_path('chill_main_workflow_delete', {'id': l.entity_workflow.id}) }}"
                                        ></a>
                                    </li>
                                {% endif %}
                                <li>
                                    <a href="{{ path('chill_main_workflow_show', {'id': l.entity_workflow.id}) }}"
                                        class="btn btn-show">
                                        {{ 'Show'|trans }}
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>

                </div>
            </div>
        {% endfor %}
        </div>
    {% endif %}
    {{ chill_pagination(paginator) }}
</div>
{% endblock %}
