{% load i18n %}

<div class="daiquiri-table-pane">
    <table class="table">
        <thead>
            <tr>
                <th class="daiquiri-table-check" ng-if="service.table.checkboxes">
                    <input type="checkbox" ng-model="service.table.checked_all" ng-click="service.table.check_all()" />
                </th>

                <th ng-repeat="column in service.table.columns"
                    ng-if="!column.hidden" data-column-index="{$ $index $}">
                    <div class="daiquiri-table-cell">
                        <div class="name">
                            <span ng-show="column.label">{$ column.label $}</span>
                            <span ng-hide="column.label">{$ column.name $}</span>
                        </div>
                        <div class="info" ng-show="service.table.tooltips">
                            <i class="fa fa-question-circle" aria-hidden="true"></i>
                        </div>
                        <div class="order" ng-click="service.table.order(column.name)">
                            <i ng-class="{
                                'fa fa-chevron-down': !service.table.params.ordering.endsWith(column.name),
                                'ordered fa fa-chevron-down': service.table.params.ordering == column.name,
                                'ordered fa fa-chevron-up': service.table.params.ordering == '-' + column.name
                            }" aria-hidden="true"></i>
                        </div>
                        <div ng-if="!$last" class="handle" ng-mousedown="service.table.resize($index)"></div>
                    </div>
                </th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="row in service.table.rows" ng-init="row_index = $index"
                ng-class="{'selected': row_index == service.table.active.row_index}">

                <td class="daiquiri-table-check" ng-if="service.table.checkboxes">
                    <input type="checkbox"
                        ng-click="service.table.update_checked_all()"
                        ng-model="service.table.checked[service.table.getter.id(row)]" />
                </td>

                <td ng-repeat="column in service.table.columns"
                    ng-if="!column.hidden"
                    ng-init="column_index = $index"
                    ng-class="{'selected': column_index == service.table.active.column_index}">

                    <div class="daiquiri-table-cell" ng-click="service.table.activate(column_index, row_index)">
                        <div ng-if="column.meta == 'note'">
                            <a href="{$ service.table.getter.file_url(row, column_index) $}"
                                ng-click="service.table.modal_open($event, column_index, row_index)">
                                {$ row[column_index]|basename $}
                            </a>
                        </div>
                        <div ng-if="column.meta == 'image'">
                            <a href="{$ service.table.getter.file_url(row, column_index) $}"
                                ng-click="service.table.modal_open($event, column_index, row_index)">
                                {$ row[column_index]|basename $}
                            </a>
                        </div>
                        <div ng-if="column.meta == 'file'">
                            <a href="{$ service.table.getter.file_url(row, column_index) $}">
                                {$ row[column_index]|basename $}
                            </a>
                        </div>
                        <div ng-if="column.meta == 'link'">
                            <a href="{$ service.table.getter.link_url(row, column_index) $}" target="_blank">
                                {$ row[column_index] $}
                            </a>
                        </div>
                        <div ng-if="column.meta == 'reference'">
                            <a href="{$ service.table.getter.reference_url(row, column_index) $}" target="_blank">
                                {$ row[column_index] $}
                            </a>
                        </div>
                        <div ng-if="column.meta == 'datalink'">
                            <a href="{$ service.table.getter.datalink_url(row, column_index) $}" target="_blank">
                                {$ row[column_index] $}
                            </a>
                        </div>
                        <div ng-if="column.meta == 'text'">
                            <div ng-if="service.table.column_round[column_index]">
                                {$ row[column_index] | number : service.table.column_round[column_index] $}
                            </div>
                            <div ng-if="!service.table.column_round[column_index]">
                                {$ row[column_index] $}
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            <tr class="daiquiri-table-pane-empty" ng-hide="service.table.rows.length">
                <td>
                    <div class="daiquiri-table-cell">
                        {% trans 'No rows were retrieved.' %}
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>
