<?php $this->layout('main', ['title' => __('Song Requests'), 'manual' => true]) ?>

<?php
/** @var \App\Assets $assets */
$assets
    ->load('bootgrid');
?>

<div class="card">
    <div class="card-header ch-alt">
        <h2><?=__('Song Requests') ?></h2>
    </div>
    <div class="table-responsive">
        <table class="data-table table table-striped">
            <colgroup>
                <col width="20%">
                <col width="20%">
                <col width="30%">
                <col width="15%">
                <col width="15%">
            </colgroup>
            <thead>
            <tr>
                <th data-column-id="timestamp"><?=__('Date Requested') ?></th>
                <th data-column-id="played_at"><?=__('Date Played') ?></th>
                <th data-column-id="song"><?=__('Song Title') ?></th>
                <th data-column-id="ip"><?=__('Requester IP') ?></th>
                <th data-column-id="actions"><?=__('Actions') ?></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($requests as $request_row): ?>
                <tr class="input" id="request_<?=$request_row['id'] ?>">
                    <td class="text-center"><?=date('F j, Y g:ia', $request_row['timestamp']) ?></td>
                    <td class="text-center">
                    <?php if ($request_row['played_at'] > 0): ?>
                        <?=date('F j, Y g:ia', $request_row['played_at']) ?>
                    <?php else: ?>
                        <?=__('Not Played') ?>
                    <?php endif; ?>
                    </td>
                    <td>
                        <?php if ($request_row['track']['title']): ?>
                            <b><?=$this->e($request_row['track']['title']) ?></b><br>
                            <?=$this->e($request_row['track']['artist']) ?>
                        <?php else: ?>
                            <?=$this->e($request_row['track']['text']) ?>
                        <?php endif; ?>
                    </td>
                    <td><?=$this->e($request_row['ip']) ?></td>
                    <td>
                    <?php if ($request_row['played_at'] == 0): ?>
                        <a class="btn btn-sm btn-danger" href="<?=$router->fromHere('stations:reports:requests:delete', ['request_id' => $request_row['id'], 'csrf' => $csrf]) ?>"><?=__('Delete') ?></a>
                    <?php else: ?>

                    <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<script type="text/javascript">
    $(function() {
        $(".data-table").bootgrid({
            caseSensitive: false,
            sorting: false,
            css: {
                icon: 'zmdi icon',
                iconColumns: 'zmdi-view-module',
                iconDown: 'zmdi-sort-amount-desc',
                iconRefresh: 'zmdi-refresh',
                iconUp: 'zmdi-sort-amount-asc'
            }
        });
    });
</script>
