{% load i18n %}

{% trans "Resolution" %}

{% if complaint.status == 'resolved' or complaint.status == 'closed' %}

{% trans "Complaint Resolved" %}

{% if complaint.resolution %}

{{ complaint.resolution|linebreaks }}

{% endif %} {% if complaint.resolution_outcome %}

{% trans "Resolution Outcome" %}

{% if complaint.resolution_outcome == 'patient' %} {% trans "Patient" %} {% elif complaint.resolution_outcome == 'hospital' %} {% trans "Hospital" %} {% else %} {% trans "Other" %} {% endif %} {% if complaint.resolution_outcome == 'other' and complaint.resolution_outcome_other %} ({{ complaint.resolution_outcome_other }}) {% endif %}
{% endif %}

{% trans "Resolved by:" %} {{ complaint.resolved_by.get_full_name|default:"-" }}

{% trans "Resolved at:" %} {{ complaint.resolved_at|date:"M d, Y H:i"|default:"-" }}

{% if complaint.pending_external_set_at %}

{% trans "Pending External since:" %} {{ complaint.pending_external_set_at|date:"M d, Y H:i" }}

{% endif %}

{% trans "Patient Satisfaction" %}

{% if complaint.satisfaction %}
{% if complaint.satisfaction == 'satisfied' %} {% elif complaint.satisfaction == 'neutral' %} {% elif complaint.satisfaction == 'dissatisfied' %} {% else %} {% endif %} {{ complaint.get_satisfaction_display }} {% if complaint.satisfaction_set_at %} {% if complaint.satisfaction_set_by %}{% trans "by" %} {{ complaint.satisfaction_set_by.get_full_name }} · {% endif %}{{ complaint.satisfaction_set_at|date:"Y-m-d H:i" }} {% endif %}
{% endif %} {% if complaint.satisfaction_locked_by_patient %}

{% trans "Locked by patient submission" %}

{% if complaint.satisfaction_locked_at %}

{% trans "Patient submitted on" %} {{ complaint.satisfaction_locked_at|date:"Y-m-d H:i" }}

{% endif %}
{% elif complaint.satisfaction_window_expired %}

{% trans "Satisfaction window expired" %}

{% trans "Satisfaction can only be set within 5 days of resolution." %}

{% elif complaint.satisfaction_change_count >= 3 and can_edit %}

{% trans "No more PX-team changes allowed" %}

{% trans "Satisfaction has been changed 3 times. Only the patient can override via the tracking page." %}

{% csrf_token %}
{% elif can_edit %}
{% csrf_token %}

{% trans "Set satisfaction based on patient follow-up call:" %}

{% if complaint.satisfaction_change_count > 0 %}

{{ complaint.satisfaction_change_count }}/3 {% trans "changes used" %} · {{ satisfaction_changes_remaining }} {% trans "remaining" %} ({% trans "No Response doesn't count" %})

{% endif %}
{% elif not complaint.satisfaction %}

{% trans "No satisfaction feedback recorded yet." %}

{% endif %} {% if satisfaction_history and satisfaction_history|length > 0 %}

{% trans "Change History" %}

{% for entry in satisfaction_history %}
{{ entry.message }} · {{ entry.created_at|date:"M d, H:i" }}
{% endfor %}
{% endif %}
{% else %} {% if can_manage_actions and complaint.is_active_status %} {% if complaint.assigned_to == current_user or can_manage_actions %}
{% csrf_token %} {% if explanations %} {% endif %}

{% trans "Response Suggestions" %}

{% if complaint.ai_response_suggestions_at %} {{ complaint.ai_response_suggestions_at|date:"Y-m-d H:i" }} {% endif %}
{% if complaint.ai_response_suggestions %}
{% for s in complaint.ai_response_suggestions.suggestions %}
{{ forloop.counter }}

{% if LANG == 'ar' and s.title_ar %}{{ s.title_ar }}{% else %}{{ s.title_en }}{% endif %}

{% if LANG == 'ar' and s.description_ar %}{{ s.description_ar }}{% else %}{{ s.description_en }}{% endif %}

{% endfor %}
{% if complaint.ai_response_suggestions.recommended_actions_en or complaint.ai_response_suggestions.recommended_actions_ar %}
{% trans "Recommended Next Steps" %}
    {% if LANG == 'ar' and complaint.ai_response_suggestions.recommended_actions_ar %} {% for a in complaint.ai_response_suggestions.recommended_actions_ar %}
  • {{ a }}
  • {% endfor %} {% else %} {% for a in complaint.ai_response_suggestions.recommended_actions_en %}
  • {{ a }}
  • {% endfor %} {% endif %}
{% endif %} {% if complaint.ai_response_suggestions.communication_tip_en or complaint.ai_response_suggestions.communication_tip_ar %}
{% trans "Communication Tip" %}

{% if LANG == 'ar' and complaint.ai_response_suggestions.communication_tip_ar %}{{ complaint.ai_response_suggestions.communication_tip_ar }}{% else %}{{ complaint.ai_response_suggestions.communication_tip_en }}{% endif %}

{% endif %}
{% else %}

{% trans "Get suggestions on how to respond to the patient." %}

{% endif %}
{% trans "This resolution will be sent to the patient via SMS and Email upon complaint closure." %}

{% trans "who was in right?" %}

{% if explanations %} {% endif %}
{% if explanations %} {% endif %}
{% else %}

{% trans "Activate this complaint to resolve it" %}

{% endif %} {% endif %} {% endif %}