<div class="row">
    <div class="col-lg-6">
        <table class="table table-sm table-striped">
            <tr>
                <th>Source</th>
                <td>
                    {{ contest.externalSourceType.readable }}
                    at
                    <code>{{ contest.externalSourceSource }}</code>
                </td>
            </tr>
            <tr>
                <th>Use external judgements</th>
                <td>{{ contest.externalSourceUseJudgements | printYesNo }}</td>
            </tr>
            {% if contest.externalSourceUsername %}
                <tr>
                    <th>Username</th>
                    <td><code>{{ contest.externalSourceUsername }}</code></td>
                </tr>
            {% endif %}
            {% if contest.externalSourcePassword %}
                <tr>
                    <th>Password</th>
                    <td>
                        <code data-password-hidden>
                            ••••••••
                        </code>
                        <code data-password class="d-none">
                            {{ contest.externalSourcePassword }}
                        </code>
                    </td>
                </tr>
            {% endif %}
            <tr>
                <th>Command</th>
                <td>
                    <code>{{ webappDir }}/bin/console import:eventfeed {{ contest.externalid }}</code>
                </td>
            </tr>
            <tr>
                <th>Status</th>
                <td>
                    {% if not contest.externalSourceLastPollTime %}
                        Event feed reader never checked in.
                    {% elseif contest.externalSourceLastHttpCode is not same as(200) %}
                        Received {{ contest.externalSourceLastHttpCode }} HTTP code.
                    {% else %}
                        {{ status }}, last checked in {{ contest.externalSourceLastPollTime | printHumanTimeDiff }}.
                    {% endif %}
                </td>
            </tr>
            <tr>
                <th>Last event ID</th>
                <td>
                    {{ contest.externalSourceLastEventId | default('-') }}
                </td>
            </tr>
            {% if sourceService.validContestSource and sourceService.apiVersion %}
                <tr>
                    <th>External provider information</th>
                    <td>
                        Version:
                        {% if sourceService.apiVersionUrl %}
                            <a href="{{ sourceService.apiVersionUrl }}" target="_blank">
                                {{ sourceService.apiVersion }}
                            </a>
                        {% else %}
                            {{ sourceService.apiVersion }}
                        {% endif %}
                        <br/>
                        {% if sourceService.apiProviderName %}
                            Provider name: {{ sourceService.apiProviderName }}<br/>
                        {% endif %}
                        {% if sourceService.apiProviderVersion %}
                            Provider version: {{ sourceService.apiProviderVersion }}<br/>
                        {% endif %}
                        {% if sourceService.apiProviderBuildDate %}
                            Provider build date: {{ sourceService.apiProviderBuildDate }}<br/>
                        {% endif %}
                    </td>
                </tr>
            {% endif %}
            <tr>
                <th>External contest information</th>
                <td>
                    Valid: {{ sourceService.validContestSource | printYesNo }}<br/>
                    {% if not sourceService.validContestSource %}
                        Error: {{ sourceService.loadingError }}
                    {% else %}
                        ID: {{ sourceService.contestId }}<br/>
                        Name: {{ sourceService.contestName }}<br/>
                        Start time: {{ sourceService.contestStartTime | printtime('Y-m-d H:i:s (T)') }}<br/>
                        Duration: {{ sourceService.contestDuration }}<br/>
                        Scoreboard type: {{ sourceService.scoreboardType.value }}
                    {% endif %}
                </td>
            </tr>
        </table>
    </div>
</div>

<style>
    code[data-password], code[data-password-hidden] {
        cursor: pointer;
    }
</style>

<script>
    $(function() {
        var $password = $('code[data-password]');
        var $passwordHidden = $('code[data-password-hidden]');
        $password.on('click', function() {
            $password.addClass('d-none');
            $passwordHidden.removeClass('d-none');
        });
        $passwordHidden.on('click', function() {
            $passwordHidden.addClass('d-none');
            $password.removeClass('d-none');
        });
    });
</script>
