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

{% block headerTitle 'Deal Fields' %}

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

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

    <div class="alert alert-info">
        Mautic's native Custom Fields apply to contacts and companies. Deal Flow manages <strong>deal fields</strong> here because deals are a separate object.
    </div>

    <table class="table table-hover dealflow-admin-table">
        <thead>
        <tr>
            <th>Label</th>
            <th>API Alias</th>
            <th>Type</th>
            <th>Required</th>
            <th>In List</th>
            <th>Status</th>
            <th>Sort</th>
            {% if canEditSettings %}
                <th class="text-right">Actions</th>
            {% endif %}
        </tr>
        </thead>
        <tbody>
        {% for item in items %}
            <tr>
                <td>
                    <strong>{{ item.getLabel() }}</strong>
                    {% if item.supportsOptions() and item.getOptions() is not empty %}
                        <div class="small text-muted">{{ item.getOptions()|join(', ') }}</div>
                    {% endif %}
                </td>
                <td><code>{{ item.getAlias() }}</code></td>
                <td>{{ item.getFieldType()|replace({'_': ' '})|title }}</td>
                <td>{{ item.isRequired() ? 'Yes' : 'No' }}</td>
                <td>{{ item.showInList() ? 'Yes' : 'No' }}</td>
                <td>{{ item.isActive() ? 'Active' : 'Inactive' }}</td>
                <td>{{ item.getSortOrder() }}</td>
                {% if canEditSettings %}
                    <td class="text-right">
                        <div class="btn-group">
                            <a class="btn btn-default btn-sm" href="{{ path('mautic_dealflow_field_edit', {'objectId': item.getId()}) }}" data-toggle="ajax">Edit</a>
                            <a class="btn btn-danger btn-sm" href="{{ path('mautic_dealflow_field_delete', {'objectId': item.getId()}) }}" data-toggle="ajax" onclick="return confirm('Are you sure you want to delete this item? This action cannot be undone.')">Delete</a>
                        </div>
                    </td>
                {% endif %}
            </tr>
        {% else %}
            <tr>
                <td colspan="{{ canEditSettings ? 8 : 7 }}" class="text-muted">No deal fields configured yet.</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endblock %}
