<table class="table table-hover sortable">
    <thead>
    <tr>
        <th class="hidden-sm hidden-xs" data-defaultsort="disabled">&nbsp;</th>
        <th>{{ trans('list.name') }}</th>
        <th data-defaultsign="az" class="hidden-sm hidden-md hidden-xs">{{ trans('list.matchesOn') }}</th>
        <th data-defaultsign="_19" colspan="2">{{ trans('list.matchingAmount') }}</th>
        <th data-defaultsign="month" class="hidden-sm hidden-xs">{{ trans('list.paid_current_period') }}</th>
        <th data-defaultsign="month" class="hidden-sm hidden-xs">{{ trans('list.next_expected_match') }}</th>
        <th class="hidden-sm hidden-xs hidden-md">{{ trans('list.active') }}</th>
        <th class="hidden-sm hidden-xs hidden-md">{{ trans('list.automatch') }}</th>
        <th data-defaultsign="az" class="hidden-sm hidden-xs">{{ trans('list.repeat_freq') }}</th>
    </tr>
    </thead>
    <tbody>
    {% for entry in bills %}
        <tr>
            <td class="hidden-sm hidden-xs">
                <div class="btn-group btn-group-xs">
                    <a href="{{ route('bills.edit',entry.id) }}" class="btn btn-default btn-xs"><i class="fa fa-fw fa-pencil"></i></a>
                    <a href="{{ route('bills.delete',entry.id) }}" class="btn btn-danger btn-xs"><i class="fa fa-fw fa-trash-o"></i></a>
                </div>
            </td>
            <td data-value="{{ entry.name }}">
                <a href="{{ route('bills.show',entry.id) }}" title="{{ entry.name }}">{{ entry.name }}</a>
            </td>
            <td class="hidden-sm hidden-md hidden-xs" data-value="{{ entry.match }}">
                {% for match in entry.match|split(',') %}
                    <span class="label label-info">{{ match }}</span>
                {% endfor %}
            </td>
            <td data-value="{{ entry.amount_min }}" style="text-align: right;">
                <span style="margin-right:5px;">
                {{ entry.amount_min|formatAmount }}
                </span>
            </td>
            <td data-value="{{ entry.amount_max }}" style="text-align: right;">
                <span style="margin-right:5px;">
                {{ entry.amount_max|formatAmount }}
                </span>
            </td>

            <!--
            Some debug data:
            entry.paidDates.count(): {{ entry.paidDates.count() }}
            entry.paidDates set:
            entry.payDates.count(): {{ entry.payDates.count() }}
            active: {% if entry.active %}true{% else %}false{% endif %}
            -->

            {#
            paidDates = 0 (bill not paid in period)
            payDates  = 0 (bill not expected to be paid in this period)
            bill is active.
            #}
            {% if entry.paidDates.count() == 0 and entry.payDates.count() == 0 and entry.active %}
                <td class="text-muted" data-value="0001-00-00 00-00-00">
                    {{ 'not_expected_period'|_ }}
                </td>
                <td class="hidden-sm hidden-xs" data-value="{{ entry.nextExpectedMatch.format('Y-m-d H-i-s') }}">
                    {{ entry.nextExpectedMatch.formatLocalized(monthAndDayFormat) }}
                </td>
            {% endif %}

            {#
            paidDates = 0 (bill not paid in period)
            payDates  > 0 (bill IS expected to be paid in this period)
            bill is active
            #}
            {% if entry.paidDates.count() == 0 and entry.payDates.count() > 0 and entry.active %}
                <td class="text-danger" data-value="0002-00-00 00-00-00">
                    {{ 'not_or_not_yet'|_ }}
                </td>
                <td class=" hidden-sm hidden-xs" data-value="{{ entry.nextExpectedMatch.format('Y-m-d H-i-s') }}">
                    {{ entry.nextExpectedMatch.formatLocalized(monthAndDayFormat) }}
                </td>
            {% endif %}

            {#
            paidDates >= 0 (bill is paid X times).
            Don't care about payDates.
            #}
            {% if entry.paidDates.count() > 0 and entry.active %}
                <td class="text-success" data-value="{{ entry.paidDates.first.format('Y-m-d H-i-s') }}">
                    {% for date in entry.paidDates %}
                        {{ date.formatLocalized(monthAndDayFormat) }}<br/>
                    {% endfor %}
                </td>
                <td class=" hidden-sm hidden-xs" data-value="{{ entry.nextExpectedMatch.format('Y-m-d H-i-s') }}">
                    {{ entry.nextExpectedMatch.formatLocalized(monthAndDayFormat) }}
                </td>
            {% endif %}
            {# bill is not active #}
            {% if not entry.active %}
                <td class="text-muted" data-value="0000-00-00 00-00-00">
                    ~
                </td>
                <td class="text-muted hidden-sm hidden-xs" data-value="0">
                    ~
                </td>
            {% endif %}
            <td class="hidden-sm hidden-xs hidden-md" data-value="{{ entry.active }}">
                {% if entry.active %}
                    <i class="fa fa-fw fa-check"></i>
                {% else %}
                    <i class="fa fa-fw fa-ban"></i>
                {% endif %}
            </td>
            <td class="hidden-sm hidden-xs hidden-md" data-value="{{ entry.automatch }}">
                {% if entry.automatch %}
                    <i class="fa fa-fw fa-check"></i>
                {% else %}
                    <i class="fa fa-fw fa-ban"></i>
                {% endif %}
            </td>
            <td class="hidden-sm hidden-xs" data-value="{{ entry.repeat_freq }}{{ entry.skip }}">
                {{ entry.repeat_freq|_ }}
                {% if entry.skip > 0 %}
                    skips over {{ entry.skip }}
                {% endif %}
            </td>
        </tr>

    {% endfor %}
    </tbody>
</table>
