<%! from django.utils.translation import ugettext as _ %>
<%page args="section_data"/>
<div class="certificates-wrapper">

    <div class="example-certificates">
        <h2>${_('Example Certificates')}</h2>

        <div class="generate-example-certificates-wrapper">
            <p>${_('Generate example certificates for the course.')}</p>

            <form id="generate-example-certificates-form" method="post" action="${section_data['urls']['generate_example_certificates']}">
                <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
                <input type="submit" id="generate-example-certificates-submit" value="${_('Generate Example Certificates')}"/>
            </form>
        </div>

        % if section_data['example_certificate_status'] is not None:
        <div class="example-certificate-status-wrapper">
            <p>${_("Status:")}</p>
            <ul>
            % for cert_status in section_data['example_certificate_status']:
                % if cert_status['status'] == 'started':
                    <li>${_('Generating example {name} certificate').format(name=cert_status['description'])}</li>
                % elif cert_status['status'] == 'error':
                    <li>${_('Error generating example {name} certificate: {error}').format(name=cert_status['description'], error=cert_status['error_reason'])}</li>
                % elif cert_status['status'] == 'success':
                    <li><a href="${cert_status['download_url']}">${_('View {name} certificate').format(name=cert_status['description'])}</a></li>
                </li>
                % endif
            % endfor
            </ul>
            <button id="refresh-example-certificate-status">${_("Refresh Status")}</button>
        </div>
        % endif
    </div>

    <hr />

    <div class="enable-certificates">
        <h2>${_("Student-Generated Certificates")}</h2>
        % if section_data['enabled_for_course']:
            <form id="enable-certificates-form" method="post" action="${section_data['urls']['enable_certificate_generation']}">
                <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
                <input type="hidden" id="certificates-enabled" name="certificates-enabled" value="false" />
                <input type="submit" id="disable-certificates-submit" value="${_('Disable Student-Generated Certificates')}"/>
            </form>
        % elif section_data['can_enable_for_course']:
            <form id="enable-certificates-form" method="post" action="${section_data['urls']['enable_certificate_generation']}">
                <input type="hidden" name="csrfmiddlewaretoken" value="${csrf_token}">
                <input type="hidden" id="certificates-enabled" name="certificates-enabled" value="true" />
                <input type="submit" id="enable-certificates-submit" value="${_('Enable Student-Generated Certificates')}"/>
            </form>
        % else:
            <p>${_("You must successfully generate example certificates before you enable student-generated certificates.")}</p>
            <button class="is-disabled" disabled>${_('Enable Student-Generated Certificates')}</button>
        % endif
    </div>
</div>
