<%page args="credit_status" />
<%!
    import datetime
    import pytz
    from django.utils.translation import ugettext as _
    from util.date_utils import get_default_time_display
%>
<%namespace name='static' file='../static_content.html'/>
% if credit_status["provider_name"]:
    <% provider_link='<a href="{}" target="_blank">{}</a>'.format(credit_status["provider_status_url"],credit_status["provider_name"]) %>
% endif

% if credit_status["eligible"]:
    <div class="message message-status is-shown credit-message">
        <p class="message-copy is-hidden credit-error-msg" data-credit-error="${credit_status['error']}">
            ${_("An error occurred with this transaction. For help, contact {support_email}.").format(
                support_email=u'<a href="mailto:{address}">{address}</a>'.format(
                    address=settings.DEFAULT_FEEDBACK_EMAIL
                )
            )}
        </p>
    % if not credit_status["purchased"] and not credit_status["error"] :
        <p class="message-copy credit-eligibility-msg">
            ${_("You are now eligible for credit. {congrats}").format(
                    congrats="<b>Congratulations</b>",
                )
            }
        </p>
        <div class="purchase_credit">
            <a class="btn credit-btn purchase-credit-btn" href="${settings.ECOMMERCE_PUBLIC_URL_ROOT}/credit/checkout/${credit_status['course_key']}" target="_blank" data-course-key="${credit_status['course_key']}">${_("Get credit")}</a>
        </div>
    % elif credit_status["request_status"] in [None, "pending"] and not credit_status["error"] :
        % if credit_status["request_status"] == "pending":
            <p class="message-copy credit-request-pending-msg">
                ${_("Thank you. Your credit is processing. Please see {link} for more information.").format(
                        link=provider_link,
                    )
                }
            </p>
            <button class="btn credit-btn pending-credit-btn" data-course-key="${credit_status['course_key']}" data-user="${user.username}" data-provider="${credit_status['provider_id']}">${_("Learn more")}</button>
        % elif credit_status["request_status"] is None:
            <p class="message-copy credit-request-pending-msg">
                ${_("Thank you for your purchase. Please proceed to {link} to finalize your credit.").format(
                        link=provider_link,
                    )
                }
            </p>
            <button class="btn credit-btn pending-credit-btn" data-course-key="${credit_status['course_key']}" data-user="${user.username}" data-provider="${credit_status['provider_id']}">${_("Finalize credit")}</button>
        % endif

        <form id="credit-pending-form"> </form>
    % elif credit_status["request_status"] == "approved" and not credit_status["error"] :
        <p class="message-copy credit-request-approved-msg">
            ${_("Your credit has been processed and approved. {congrats}. Please see {link} for more information.").format(
                    congrats="<b>Congratulations</b>",
                    link=provider_link,
                )
            }
        </p>
        <a class="btn credit-btn" href="${credit_status['provider_status_url']}" target="_blank">${_("Access credit")}</a>
    % elif credit_status["request_status"] == "rejected" and not credit_status["error"] :
        <p class="message-copy credit-request-rejected-msg">
            ${_("Your credit has been processed but denied. Please contact {link} for more information.").format(
                    link=provider_link,
                )
            }
        </p>
        <a class="btn credit-btn denied-credit-btn" href="${credit_status['provider_status_url']}" target="_blank">
            ${_("Contact {provider}").format(provider=u'credit_status["provider_name"]')
        }
        </a>
    % endif
    </div>
% endif
