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

<div class="card">
    <div class="card-header ch-alt">
        <h2><?=__('Web Hooks') ?></h2>

        <a class="btn bgm-blue btn-float" role="button" title="<?=__('Add %s', __('Web Hook')) ?>" href="<?=$router->named('stations:webhooks:add', ['station' => $station->getId()]) ?>">
            <span class="sr-only"><?=__('Add %s', __('Web Hook')) ?></span>
            <i class="zmdi zmdi-plus"></i>
        </a>
    </div>
    <div class="card-body card-padding p-b-0">
        <p><?=__('Web hooks let you connect to external web services and broadcast changes to your station to them.') ?></p>
    </div>
    <div class="table-responsive">
        <table class="table table-striped">
            <colgroup>
                <col width="30%">
                <col width="35%">
                <col width="35%">
            </colgroup>
            <thead>
            <tr>
                <th><?=__('Actions') ?></th>
                <th><?=__('Name') ?> / <?=__('Type') ?></th>
                <th><?=__('Triggers') ?></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($webhooks as $row): ?>
                <?php /** @var \App\Entity\StationWebhook $row */ ?>
                <tr class="vertical-align-middle">
                    <td>
                        <a class="btn btn-sm btn-primary" href="<?=$router->fromHere('stations:webhooks:edit', ['id' => $row->getId()]) ?>"><?=__('Edit') ?></a>
                        <a class="btn btn-sm <?=($row->isEnabled() ? 'btn-warning' : 'btn-success') ?>" href="<?=$router->fromHere('stations:webhooks:toggle',['id' => $row->getId(), 'csrf' => $csrf]) ?>"><?=($row->isEnabled() ? __('Disable') : __('Enable')) ?></a>
                        <a class="btn btn-sm btn-default" href="<?=$router->fromHere('stations:webhooks:test', ['id' => $row->getId(), 'csrf' => $csrf]) ?>" title="<?=__('Trigger the web hook manually and view the raw response.') ?>"><?=__('Test') ?></a>
                        <a class="btn btn-sm btn-danger" href="<?=$router->fromHere('stations:webhooks:delete', ['id' => $row->getId(), 'csrf' => $csrf]) ?>"><?=__('Delete') ?></a>
                    </td>
                    <td>
                        <big><?=$this->e($row->getName()) ?></big><br>
                        <?=$webhook_config['webhooks'][$row->getType()]['name'] ?><?php if (!$row->isEnabled()): ?> <span class="label label-danger"><?=__('Disabled') ?></span><?php endif; ?>
                    </td>
                    <td>
                        <?php
                        $trigger_names = [];
                        foreach((array)$row->getTriggers() as $trigger) {
                            $trigger_names[] = $webhook_config['triggers'][$trigger];
                        }
                        echo implode(', ', $trigger_names);
                        ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
