{% extends '@MauticCore/Default/content.html.twig' %}

{% block headerTitle 'Deal Pipelines' %}

{% block actions %}
    {% if canEditSettings %}
        {% set actionReturnUrl = path('mautic_dealflow_pipeline_settings_index') %}
        <a
            class="btn btn-primary"
            href="{{ path('mautic_dealflow_pipeline_settings_new', {'returnUrl': actionReturnUrl}) }}"
            data-toggle="ajaxmodal"
            data-target="#MauticSharedModal"
            data-header="New Pipeline"
            data-href="{{ path('mautic_dealflow_pipeline_settings_new', {'modal': 1, 'contentOnly': 1, 'returnUrl': actionReturnUrl}) }}"
        >
            <i class="ri-add-line"></i>
            New Pipeline
        </a>
    {% endif %}
{% endblock %}

{% block content %}
    {{ include('@DealFlow/_styles.html.twig') }}
    {{ include('@DealFlow/Deal/_nav.html.twig') }}

    <table class="table table-hover dealflow-admin-table">
        <thead>
        <tr>
            <th>Name</th>
            <th>Default</th>
            <th>Active</th>
            <th>Stages</th>
            <th>Deals</th>
            <th></th>
        </tr>
        </thead>
        <tbody>
        {% for item in items %}
            {% set itemId = item.getId() %}
            <tr>
                <td>{{ item.getName() }}</td>
                <td>{{ item.isDefault() ? 'Yes' : 'No' }}</td>
                <td>{{ item.isPublished() ? 'Yes' : 'No' }}</td>
                <td>{{ stageCounts[itemId] ?? 0 }}</td>
                <td>{{ dealCounts[itemId] ?? 0 }}</td>
                <td>
                    {% if canEditSettings %}
                        <a href="{{ path('mautic_dealflow_pipeline_settings_edit', {'objectId': itemId}) }}">Edit</a>
                        <span class="text-muted">|</span>
                        <a href="{{ path('mautic_dealflow_stage_index', {'pipelineId': itemId}) }}">Stages</a>
                        <span class="text-muted">|</span>
                        <a href="{{ path('mautic_dealflow_pipeline_settings_delete', {'objectId': itemId}) }}" onclick="return confirm('Are you sure you want to delete this item? This action cannot be undone.')">Delete</a>
                    {% endif %}
                </td>
            </tr>
        {% else %}
            <tr>
                <td colspan="6" class="text-muted">No pipelines configured.</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}
