{#
  Variables
    - item
#}
{% set now = dateTimeGetUtcDateTime() %}
{% set hoursSinceLastBuilt = null %}
{% if item.lastBuiltDate is not null %}
    {% set lastBuiltDate = date(item.lastBuiltDate.timestamp) %}
    {% set now = date() %}
    {% set diffInSeconds = now.timestamp - lastBuiltDate.timestamp %}
    {% set hoursSinceLastBuilt = diffInSeconds / 3600 | round %}
{% endif %}
{% set mauticTemplateVars = _context|merge([{'item': item}]) %}
<tr>
    <td>
        {{ include('@MauticCore/Helper/list_actions.html.twig', {
                'item': item,
                'templateButtons': {
                    'edit': securityHasEntityAccess(permissions[constant('Mautic\\LeadBundle\\Security\\Permissions\\LeadPermissions::LISTS_EDIT_OWN')], permissions[constant('Mautic\\LeadBundle\\Security\\Permissions\\LeadPermissions::LISTS_EDIT_OTHER')], item.createdBy),
                    'clone': permissions[constant('Mautic\\LeadBundle\\Security\\Permissions\\LeadPermissions::LISTS_CREATE')] and securityHasEntityAccess(permissions[constant('Mautic\\LeadBundle\\Security\\Permissions\\LeadPermissions::LISTS_VIEW_OWN')], permissions[constant('Mautic\\LeadBundle\\Security\\Permissions\\LeadPermissions::LISTS_VIEW_OTHER')], item.createdBy),
                    'delete': securityHasEntityAccess(permissions[constant('Mautic\\LeadBundle\\Security\\Permissions\\LeadPermissions::LISTS_DELETE_OWN')], permissions[constant('Mautic\\LeadBundle\\Security\\Permissions\\LeadPermissions::LISTS_DELETE_OTHER')], item.createdBy),
                },
                'routeBase': 'segment',
                'langVar': 'lead.list',
                'customButtons': {
                    'viewcontacts': {
                        'attr': {
                            'data-toggle': 'ajax',
                            'href': path('mautic_contact_index', {'search': listCommand ~ ':' ~ item.alias}),
                        },
                        'iconClass': 'ri-team-line',
                        'btnText': 'mautic.lead.list.view_contacts'|trans,
                        'priority': 100
                    }
                },
        }) }}
    </td>
    <td>
        <div>
            {{ include('@MauticCore/Helper/publishstatus_icon.html.twig', {'item': item, 'model': 'lead.list'}) }}
            {% if securityHasEntityAccess(true, permissions['lead:lists:editother'], item.createdBy) %}
                <a href="{{ path('mautic_segment_action', {'objectAction': 'view', 'objectId': item.id}) }}" data-toggle="ajax">
                  {{ item.name }} ({{ item.alias }})
                </a>
            {% else %}
                {{ item.name }} ({{ item.alias }})
            {% endif %}
            {{ include('@MauticProject/Modules/projects.html.twig') }}
            {% if not item.isGlobal and app.user.id != item.createdBy %}
                <br/>
                <span class="small">({{ item.createdByUser }})</span>
            {% endif %}
            {% if item.isGlobal %}<i title="{{ 'mautic.lead.list.form.isglobal'|trans }}" class="ri-group-2-fill fs-14"></i>{% endif %}
            {% if item.getFilters() is not empty %}<i title="{{ 'mautic.core.filters'|trans }}" class="ri-fw ri-filter-2-fill fs-14"></i>{% endif %}
            {% if hoursSinceLastBuilt >= segmentRebuildWarningThreshold %}
                <label class="control-label" data-toggle="tooltip"
                       data-container="body" data-placement="top" title=""
                       data-original-title="{{ 'mautic.lead.list.form.config.segment_rebuild_time.message'|trans({'%count%': hoursSinceLastBuilt  | number_format(2)}) }}">
                    <i class="text-danger ri-error-warning-line fs-14"></i></label>
            {% endif %}
            {% if item.lastBuiltTime >= segmentBuildWarningThreshold %}
                <label class="control-label" data-toggle="tooltip"
                       data-container="body" data-placement="top" title=""
                       data-original-title="{{ 'mautic.lead.list.form.config.segment_build_time.message'|trans({'%count%': item.lastBuiltTime}) }}">
                    <i class="text-danger ri-time-line fs-14"></i></label>
            {% endif %}
            {{ customContent('segment.name', mauticTemplateVars) }}
        </div>
        {{ include('@MauticCore/Helper/description--inline.html.twig', {
            'description': item.description
        }) }}
    </td>
    <td class="visible-md visible-lg">
        <span size="sm" class="label {{ item.needsRebuild() ? 'label-info' : 'label-gray' }} col-count" data-id="{{ item.id }}">
            <a href="{{ path('mautic_contact_index', {'search': 'mautic.lead.lead.searchcommand.list'|trans ~ ':' ~ item.alias}) }}"
                data-toggle="ajax">{{ (item.needsRebuild() ? 'mautic.lead.list.building' : 'mautic.lead.list.viewleads_count')|trans({'%count%': leadCounts[item.id]}) }}</a>
        </span>
    </td>
    <td class="visible-md visible-lg" title="{% if item.dateAdded %}{{ dateToFullConcat(item.dateAdded) }}{% endif %}">
        {% if item.getDateAdded %}{{ dateToDate(item.dateAdded) }}{% endif %}
    </td>
    <td class="visible-md visible-lg" title="{% if item.dateModified %}{{ dateToFullConcat(item.dateModified) }}{% endif %}">
        {% if item.getDateModified %}{{ dateToDate(item.dateModified) }}{% endif %}
    </td>
    <td class="visible-md visible-lg">{{ item.createdByUser|purify }}</td>
    <td class="visible-md visible-lg">{{ item.id }}</td>
</tr>
