{% load i18n %}

<div class="course-widgets">
    {% if can_edit %}
        <a href="{% url 'publisher:publisher_course_runs_edit' pk=object.id %}" class="btn btn-neutral btn-courserun-edit">
            {% trans "EDIT" %}
        </a>
        <div class="clearfix"></div>
    {% endif %}
    <div class="approval-widget {% if not publisher_approval_widget_feature %}hidden{% endif %}">
        {% include 'publisher/_approval_widget.html' %}

        <div class="preview-widget">
            <div class="preview-container">
                <div class="layout-1q3q layout-reversed">
                    <div class="layout-col layout-col-a">
                    {% if object.preview_url %}
                        {% if object.preview_url and object.course.course_team_admin == request.user and object.course_run_state.is_approved and not object.course_run_state.is_preview_accepted %}
                            <button class="btn btn-neutral btn-preview btn-preview-decline" type="button">
                                {% trans "Decline" %}
                            </button>
                            <button class="btn btn-neutral btn-preview btn-preview-accept" type="button">
                                {% trans "Accept" %}
                            </button>
                        {% elif preview_accepted_date %}
                            <span class="state-status">
                                <span class="icon fa fa-check" aria-hidden="true"></span>
                                {% trans "Approved" %}<br>
                                {{ preview_accepted_date|date:'m/d/y H:i a' }}
                            </span>
                            {% if object.course_run_state.is_ready_to_publish and object.course.publisher == request.user %}
                                <button class="btn-brand btn-base btn-publish" data-change-state-url="{% url 'publisher:api:change_course_run_state' object.course_run_state.id %}" data-state-name="{{ publish_state_name }}" type="button">
                                    {% trans "Publish" %}
                                </button>
                            {% endif %}
                        {% elif object.course.publisher == request.user %}
                            <span class="preview-status">{% trans "Submitted for review" %}</span>
                                <button data-url="{% url 'publisher:api:update_course_run' object.id %}" class="btn btn-neutral btn-edit-preview-url">{% trans "Edit" %}</button>
                        {% endif %}
                    {% elif object.course.publisher == request.user %}
                        <button data-url="{% url 'publisher:api:update_course_run' object.id %}" class="btn btn-neutral btn-save-preview-url">{% trans "Save" %}</button>
                    {% endif %}
                    </div>
                    <div class="layout-col layout-col-b">
                        <span class="preview-heading">
                            <strong>{% trans "COURSE PREVIEW" %}</strong>
                        </span>
                        <div class="preview-url">
                            {% if object.preview_url %}
                                <span class="preview-url-heading">{% trans "Preview URL" %} - </span>
                                <a href="{{ object.preview_url }}" target="_blank">{% trans "View course preview live" %}</a>
                            {% else %}
                                {% if object.course.publisher == request.user %}
                                    <input id="id-review-url" type="text">
                                    <span class="error-message"></span>
                                {% else %}
                                    <span>{% trans "Not available" %}</span>
                                {% endif %}
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <hr>
        <div id="decline-comment" class="hidden clearfix">
            {% trans 'Reason for declining preview' as decline_reason %}
            {% trans 'Submit' as submit %}
            {% include 'comments/add_auth_comments.html' with comment_type='decline_preview' box_label=decline_reason btn_label=submit %}
        </div>
        {% include 'publisher/course_run_detail/_preview_accept_popup.html' %}
    </div>
</div>
