<div id='entityEditContainer' class="entityTableContainer"
     piwik-content-block
     content-title="{{ title|e('html_attr') }}"
     help-url="https://matomo.org/docs/email-reports/"
     feature="true"
     ng-show="manageScheduledReport.showReportsList">

    <table piwik-content-table>
        <thead>
        <tr>
            <th class="first">{{ 'General_Description'|translate }}</th>
            <th>{{ 'ScheduledReports_EmailSchedule'|translate }}</th>
            <th>{{ 'ScheduledReports_ReportFormat'|translate }}</th>
            <th>{{ 'ScheduledReports_SendReportTo'|translate }}</th>
            <th>{{ 'General_Download'|translate }}</th>
            <th>{{ 'General_Edit'|translate }}</th>
            <th>{{ 'General_Delete'|translate }}</th>
        </tr>
        </thead>

    {% if userLogin == 'anonymous' %}
        <tr>
            <td colspan='7'>
                <br/>
                {{ 'ScheduledReports_MustBeLoggedIn'|translate }}
                <br/>&rsaquo; <a href='index.php?module={{ loginModule }}'>{{ 'Login_LogIn'|translate }}</a>
                <br/><br/>
            </td>
        </tr>
    {% elseif reports is empty %}
        <tr>

            <td colspan='7'>
                <br/>
                {{ 'ScheduledReports_ThereIsNoReportToManage'|translate(siteName)|rawSafeDecoded }}.
                <br/><br/>
            </td>
        </tr>
    {% else %}
    {% for report in reports %}
        <tr>
            <td class="first">
                {{ report.description|rawSafeDecoded }}
                {% if segmentEditorActivated and report.idsegment %}
                    <div class="entityInlineHelp" style="font-size: 9pt;">
                        {% if savedSegmentsById[report.idsegment] is defined %}
                            {{ savedSegmentsById[report.idsegment] }}
                        {% else %}
                            {{ 'ScheduledReports_SegmentDeleted'|translate }}
                        {% endif %}
                    </div>
                {% endif %}
            </td>
            <td>{{ periods[report.period] }}
                <!-- Last sent on {{ report.ts_last_sent }} -->
            </td>
            <td>
                {% if report.format is not empty %}
                    {{ report.format|upper }}
                {% endif %}
            </td>
            <td>
                {# report recipients #}
                {% if report.recipients|length == 0 %}
                    {{ 'ScheduledReports_NoRecipients'|translate }}
                {% else %}
                    {% for recipient in report.recipients %}
                        {{ recipient }}
                        <br/>
                    {% endfor %}
                    {# send now link #}
                    <a href="#"
                       ng-click="manageScheduledReport.sendReportNow({{ report.idreport }})"
                       name="linkSendNow" class="link_but withIcon" style="margin-top:3px;">
                        <img border=0 src='{{ reportTypes[report.type] }}'/>
                        {{ 'ScheduledReports_SendReportNow'|translate }}
                    </a>
                {% endif %}
            </td>
            <td>
                {# download link #}
                <form action="{{ linkTo({ 'module':'API', 'segment': null,
                    'method':'ScheduledReports.generateReport', 'idReport':report.idreport,
                    'outputType':downloadOutputType, 'language':language,
                    'format': (report.format in ['html', 'csv']) ? report.format : false }) }}"
                      method="POST"
                      target="_blank"
                      id="downloadReportForm_{{ report.idreport|e('html_attr') }}"
                >
                    <input type="hidden" name="token_auth" value="{{ token_auth|e('html_attr') }}">
                    <input type="hidden" name="force_api_session" value="1">
                </form>
                <a href="javascript:void(0)"
                   ng-click="manageScheduledReport.displayReport({{ report.idreport|json_encode }})"
                   rel="noreferrer noopener" name="linkDownloadReport" id="{{ report.idreport|e('html_attr') }}" class="link_but withIcon">
                    <img src='{{ reportFormatsByReportType[report.type][report.format] }}' border="0" width="16px" height="16px"/>
                    {{ 'General_Download'|translate }}
                </a>
            </td>
            <td style="text-align: center;padding-top:2px;">
                <button ng-click="manageScheduledReport.editReport({{ report.idreport|json_encode }})"
                        class="table-action" title="{{ 'General_Edit'|translate|e('html_attr') }}">
                    <span class="icon-edit"></span>
                </button>
            </td>
            <td style="text-align: center;padding-top:2px;">
                <button ng-click="manageScheduledReport.deleteReport({{ report.idreport|json_encode }})"
                        class="table-action" title="{{ 'General_Delete'|translate|e('html_attr') }}">
                    <span class="icon-delete"></span>
                </button>
            </td>
        </tr>
    {% endfor %}
    {% endif %}
    </table>

    <div class="tableActionBar">
        {% if userLogin != 'anonymous' %}
            <button id="add-report" ng-click="manageScheduledReport.createReport()" >
                <span class="icon-add"></span>
                {{ 'ScheduledReports_CreateAndScheduleReport'|translate }}
            </button>
        {% endif %}
    </div>

</div>
