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

{% block headerTitle 'Inbound Webhooks' %}

{% block actions %}
    {% if canEditSettings %}
        <a class="btn btn-primary" href="{{ path('mautic_dealflow_inbound_webhook_new') }}">
            <i class="ri-add-line"></i>
            New Inbound Source
        </a>
    {% endif %}
{% endblock %}

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

    <div class="panel panel-default">
        <div class="panel-body">
            <p class="text-muted mb-lg">
                Create per-source inbound webhook credentials here. Each source gets its own endpoint key and secret, while outbound Deal Flow events continue to use Mautic's native Webhooks feature.
            </p>

            <table class="table table-hover dealflow-admin-table">
                <thead>
                <tr>
                    <th>Name</th>
                    <th>Endpoint</th>
                    <th>Status</th>
                    <th>Last Used</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {% for item in items %}
                    <tr>
                        <td>{{ item.getName() }}</td>
                        <td><code>{{ path('mautic_public_dealflow_webhook_source', {'sourceKey': item.getSourceKey()}) }}</code></td>
                        <td>{{ item.isActive() ? 'Active' : 'Disabled' }}</td>
                        <td>{{ item.getLastUsedAt() ? item.getLastUsedAt()|date('Y-m-d H:i:s') : 'Never' }}</td>
                        <td>
                            {% if canEditSettings %}
                                <a href="{{ path('mautic_dealflow_inbound_webhook_edit', {'objectId': item.getId()}) }}">Edit</a>
                                <span class="text-muted">|</span>
                                <a href="{{ path('mautic_dealflow_inbound_webhook_delete', {'objectId': item.getId()}) }}" 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="5" class="text-muted">No inbound webhook sources configured.</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}
