{% extends 'wagtailadmin/shared/side_panels/includes/action_list_item.html' %}
{% load wagtailadmin_tags i18n %}

{% comment %}
    This template is used to show Live, Draft, Live and Draft, In Moderation or Live and In Moderation.
    Sometimes {{ block.super }} will be called two times in the instances where the object is in multiple states e.g. Live + Draft
{% endcomment %}

{% block content %}
    <div class="w-space-y-3">
        {% if page %}
            {% trans 'Page status: ' as screen_reader_title_prefix %}
        {% else %}
            {% trans 'Status: ' as screen_reader_title_prefix %}
        {% endif %}

        {% with workflow_state=object.current_workflow_state draft_revision=object.get_latest_revision live_revision=object.live_revision %}

            {# Live section #}
            {% if object.live %}
                {% trans 'Live' as title %}
                {% if live_revision %}
                    {% timesince_last_update live_revision.created_at user_display_name=live_revision.user|user_display_name use_shorthand=True as help_text %}
                {% endif %}

                {% with icon_name='doc-full-inverse' %}
                    {% if object.has_unpublished_changes or workflow_state %}
                        {% with hide_action=True %}
                            {{ block.super }}
                        {% endwith %}
                    {% else %}
                        {{ block.super }}
                    {% endif %}
                {% endwith %}

            {% endif %}

            {# Draft and In moderation settings #}
            {% if workflow_state %}

                {# In Moderation Settings #}
                {% trans 'In Moderation' as title %}
                {% if workflow_state.created_at %}
                    {% timesince_last_update workflow_state.created_at user_display_name=workflow_state.requested_by|user_display_name use_shorthand=True as help_text %}
                {% endif %}
                {% trans 'View details' as action_text %}

                {# Icon #}
                {% with icon_name='draft' hide_action=False %}
                    {{ block.super }}
                {% endwith %}

                {# Draft Settings #}
            {% elif object.has_unpublished_changes %}
                {% trans 'Draft' as title %}
                {% if draft_revision.created_at %}
                    {% timesince_last_update draft_revision.created_at user_display_name=draft_revision.user|user_display_name use_shorthand=True as help_text %}
                {% endif %}

                {# Icon #}
                {% with icon_name='draft' %}
                    {{ block.super }}
                {% endwith %}
            {% endif %}
        {% endwith %}
    </div>
{% endblock %}

{% block action %}
    {% if workflow_state and not hide_action %}
        {% trans 'Moderators approval' as workflow_dialog_title %}
        {% dialog_toggle class_name='w-bg-transparent w-text-14 w-p-0 w-text-secondary hover:w-text-secondary-600 w-inline-flex w-justify-center w-transition' dialog_id="workflow-status-dialog" text=action_text %}

        {# info subtitle #}
        {% if object.get_latest_revision %}
            {% workflow_status_with_date workflow_state as message_heading %}
            {% if workflow_state.requested_by %}
                {% blocktrans trimmed with user=workflow_state.requested_by|user_display_name asvar modified_by %}by {{ user }}{% endblocktrans %}
            {% endif %}
            {% dialog id="workflow-status-dialog" icon_name="list-ul" title=workflow_dialog_title message_status='info' message_heading=message_heading|add:' '|add:modified_by %}
                {% include 'wagtailadmin/workflows/workflow_status.html' %}
            {% enddialog %}
        {% else %}
            {% dialog id="workflow-status-dialog" icon_name="list-ul" title=workflow_dialog_title %}
                {% include 'wagtailadmin/workflows/workflow_status.html' %}
            {% enddialog %}
        {% endif %}
    {% elif history_url %}
        {% with action_url=history_url %}
            {% trans 'View history' as action_text %}
            {{ block.super }}
        {% endwith %}
    {% endif %}
{% endblock %}

{% block bottom %}
    {# Workflow Status #}
    {% with workflow_state=object.current_workflow_state draft_revision=object.get_latest_revision %}
        {% if workflow_state %}
            <div class="w-flex w-space-x-3 w-mt-3">
                {% icon name='info-circle' class_name='w-w-4 w-h-4 w-text-info-100 w-shrink-0' %}
                <div class="w-label-3 w-flex-1">
                    {% workflow_status_with_date workflow_state %}
                </div>
            </div>
        {% endif %}

        {# Scheduled publishing #}
        {% if draft_revision and draft_revision.approved_go_live_at %}
            <div class="w-flex w-space-x-3">
                {% icon name='info-circle' class_name='w-w-4 w-h-4 w-text-info-100 w-shrink-0' %}
                <div class="w-label-3 w-flex-1">
                    {% trans 'This will publish at ' %}{{ draft_revision.approved_go_live_at }}
                </div>
            </div>
        {% endif %}
    {% endwith %}
{% endblock %}
