{% load i18n %}

{% trans "Involved Departments" %}

{% if can_edit and complaint.is_active_status %} {% trans "Add Department" %} {% endif %}
{% if can_edit and complaint.is_active_status and ai_department_suggested %}

{{ complaint.department.name }}

{% trans "AI Suggestion" %}

{% trans "AI suggested this department based on the complaint analysis." %}

{% csrf_token %}
{% endif %} {% if complaint.involved_departments.exists %}
{% for dept in complaint.involved_departments.all %}

{{ dept.department.name }}

{% if dept.is_primary %} {% trans "PRIMARY" %} {% endif %} {{ dept.get_role_display }}
{% if dept.assigned_to %}
{% trans "Assigned to:" %} {{ dept.assigned_to.get_full_name }} {% if dept.assigned_at %} ({{ dept.assigned_at|date:"M d, Y" }}) {% endif %}
{% endif %} {% if dept.notes %}

{{ dept.notes }}

{% endif %} {% if dept.response_submitted %} {% if dept.manager_review_status == 'rejected' %}
{% trans "Rejected by Manager" %}

{% trans "Champion needs to re-submit." %}

{% elif dept.manager_review_status == 'pending' %}
{% trans "Pending Manager Review" %}

{% trans "Awaiting department manager approval." %}

{% elif dept.acceptance_status == 'acceptable' %}
{% trans "Accepted" %} {{ dept.response_submitted_at|date:"M d, Y H:i" }} {% if dept.accepted_by %} — {% trans "Reviewed by" %} {{ dept.accepted_by.get_full_name }} {% endif %}
{% if dept.response_notes_en %}

{{ dept.response_notes_en }}

{% endif %} {% if dept.response_notes_ar %}

{{ dept.response_notes_ar }}

{% endif %} {% if dept.acceptance_notes %}

{% trans "Review notes:" %} {{ dept.acceptance_notes }}

{% endif %}
{% elif dept.acceptance_status == 'not_acceptable' %}
{% trans "Rejected by PX Admin" %}
{% if dept.acceptance_notes %}

{% trans "Reason:" %} {{ dept.acceptance_notes }}

{% endif %}
{% elif dept.acceptance_status == 'pending' and dept.manager_review_status == 'approved' %}
{% trans "Manager Approved" %} {{ dept.response_submitted_at|date:"M d, Y H:i" }}
{% if dept.response_notes_en %}

{{ dept.response_notes_en }}

{% endif %} {% if dept.response_notes_ar %}

{{ dept.response_notes_ar }}

{% endif %} {% if can_review_dept_response %}
{% csrf_token %}
{% csrf_token %}
{% endif %}
{% else %}
{% trans "Pending Review" %} {{ dept.response_submitted_at|date:"M d, Y H:i" }}
{% if dept.response_notes_en %}

{{ dept.response_notes_en }}

{% endif %}
{% endif %} {% endif %}
{% if can_edit and complaint.is_active_status %}
{% if not dept.response_submitted %} {% endif %}
{% csrf_token %}
{% endif %}
{% endfor %}
{% else %}

{% trans "No departments involved yet" %}

{% if can_edit and complaint.is_active_status %} {% trans "Add First Department" %} {% endif %}
{% endif %}