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

<?php
/** @var \App\Assets $assets */
$assets
    ->load('bootgrid')
    ->load('moment')
    ->addInlineJs($this->fetch('stations/reports/requests.js'), 99);
?>

<div class="card">
    <div class="card-header bg-primary-dark">
        <h2 class="card-title"><?=__('Song Requests')?></h2>
    </div>
    <div class="card-actions">
        <a class="btn btn-outline-danger" role="button" data-confirm-title="<?=$this->e(__('Clear all pending requests?'))?>"
           href="<?=$router->fromHere('stations:reports:requests:clear', ['csrf' => $csrf])?>">
            <i class="material-icons" aria-hidden="true">remove</i>
            <?=__('Clear Pending Requests')?>
        </a>
    </div>
    <table class="data-table table-responsive-md table table-striped mb-0">
        <thead>
        <tr>
            <th style="width: 20%;" data-column-id="timestamp"><?=__('Date Requested')?></th>
            <th style="width: 20%;" data-column-id="played_at"><?=__('Date Played')?></th>
            <th style="width: 30%;" data-column-id="song"><?=__('Song Title')?></th>
            <th style="width: 15%;" data-column-id="ip"><?=__('Requester IP')?></th>
            <th style="width: 15%;" data-column-id="actions"><?=__('Actions')?></th>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($requests as $request_row): ?>
            <tr class="align-middle" id="request_<?=$request_row['id']?>">
                <td>
                    <time data-original="<?=(int)$request_row['timestamp']?>"><?=date('F j, Y g:ia',
                            $request_row['timestamp'])?></time>
                </td>
                <td>
                    <?php if ($request_row['played_at'] > 0): ?>
                        <time data-original="<?=(int)$request_row['played_at']?>"><?=date('F j, Y g:ia',
                                $request_row['played_at'])?></time>
                    <?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" data-confirm-title="<?=$this->e(__('Delete request?'))?>"
                           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>
