{% load i18n %}
{% load rules %}
{% load content_filters %}
{% load poi_filters %}

<tr class="border-t border-solid border-gray-200 hover:bg-gray-100 text-gray-800">
    <td class="py-3 pl-4 pr-2">
        <input type="checkbox" name="selected_ids[]" value="{{ event.id }}" form="bulk-action-form" class="bulk-select-item">
    </td>
    <td>
        <a title="{% if event_translation %} {{ event_translation.title }} {% endif %}"
           href="{% url 'edit_event' event_id=event.id region_slug=request.region.slug language_slug=language.slug%}" 
           class="py-3 pr-2 text-gray-800">
            {% if event_translation %}
                {{ event_translation.title|truncatechars:35 }}
            {% else %}
                <i>{% trans 'Translation not available' %}</i>
            {% endif %}
        </a>
    </td>
    {% get_current_language as LANGUAGE_CODE %}
    {% get_language LANGUAGE_CODE as backend_language %}
    {% if backend_language and backend_language != language %}
        <td class="py-3 pr-2 text-gray-800">
            <a title="{% if event.backend_translation %} {{ event.backend_translation.title }} {% endif %}"
               href="{% url 'edit_event' event_id=event.id region_slug=request.region.slug language_slug=LANGUAGE_CODE %}" 
               class="py-3 pr-2 text-gray-800">
                {% if event.backend_translation %}
                    {{ event.backend_translation.title|truncatechars:35 }}
                {% else %}
                    <i>{% trans 'Translation not available' %}</i>
                {% endif %}
            </a>
        </td>
    {% endif %}
    <td class="py-3 pl-2 text-gray-800 lang-grid">
        {% spaceless %}
            {% for other_language in languages %}
                <a href="{% url 'edit_event' event_id=event.id region_slug=request.region.slug language_slug=other_language.slug %}">
                    {% get_translation event other_language.slug as other_translation %}
                    {% if other_translation %}
                        {% if other_translation.currently_in_translation %}
                            <span title="{% trans 'Currently in translation' %}">
                                <i data-feather="clock" class="{% if other_language == language %}text-blue-500{% endif %}"></i>
                            </span>
                        {% elif other_translation.is_outdated %}
                            <span title="{% trans 'Translation outdated' %}">
                                <i data-feather="alert-triangle" class="{% if other_language == language %}text-yellow-500{% endif %}"></i>
                            </span>
                        {% else %}
                            <span title="{% trans 'Translation up-to-date' %}">
                                <i data-feather="check" class="{% if other_language == language %}text-green-500{% endif %}"></i>
                            </span>
                        {% endif %}
                    {% else %}
                        <span title="{% trans 'Translation missing' %}">
                            <i data-feather="x" class="{% if other_language == language %}text-red-500{% endif %}"></i>
                        </span>
                    {% endif %}
                </a>
            {% endfor %}
        {% endspaceless %}
    </td>
    <td class="py-3 pr-2">
        {{ event_translation.get_status_display }}
    </td>
    <td class="py-3 pr-2">
        {% if event.location %}
            {% get_language LANGUAGE_CODE as current_language %}
            {{ event.location|poi_translation_title:current_language }}
        {% else %}
            {% trans 'Not specified' %}
        {% endif %}
    </td>
    <td class="py-3 pr-2">
        <i data-feather="calendar"></i> {{ event.start_date|date:'d.m.Y'}}{% if not event.is_all_day %} <i data-feather="clock" class="ml-2"></i> {{ event.start_time|time:'H:i' }}{% endif %}
    </td>
    <td class="py-3 pr-2">
        <i data-feather="calendar"></i> {{ event.end_date|date:'d.m.Y'}}{% if not event.is_all_day %} <i data-feather="clock" class="ml-2"></i> {{ event.end_time|time:'H:i' }}{% endif %}
    </td>
    <td class="py-3 pr-2">
        {% if event.recurrence_rule %}
        <i data-feather="repeat"></i> {{ event.recurrence_rule.get_frequency_display }}
        {% else %}
        <i data-feather="calendar"></i> {% trans 'One-time' %}
        {% endif %}
    </td>
    <td class="pr-4 py-3 flex flex-nowrap justify-end gap-2">
        {% has_perm 'cms.change_event' request.user as can_edit_event %}
        {% if can_edit_event %}
            <button title="{% trans 'Restore event' %}" class="confirmation-button btn-icon"
                data-confirmation-title="{{ restore_dialog_title }}"
                data-confirmation-text="{{ restore_dialog_text }}"
                data-confirmation-subject="{{ event_translation.title }}"
                data-action="{% url 'restore_event' event_id=event.id region_slug=request.region.slug language_slug=language.slug %}">
                <i data-feather="refresh-ccw"></i>
            </button>
        {% endif %}
        {% if perms.cms.delete_event %}
            <button title="{% trans 'Delete event' %}" class="confirmation-button btn-icon"
                data-confirmation-title="{{ delete_dialog_title }}"
                data-confirmation-text="{{ delete_dialog_text }}"
                data-confirmation-subject="{{ event_translation.title }}"
                data-action="{% url 'delete_event' event_id=event.id region_slug=request.region.slug language_slug=language.slug %}">
                <i data-feather="trash-2"></i>
            </button>
        {% endif %}
    </td>
</tr>