<?php
$this->css($this->assetModule('script/admin.css'));
$this->jQuery();
?>
<div id="pi-js-list">
    <table class="table table-striped">
        <tbody>
        <tr>
            <th style="width: 50px"><?php echo _a('Image'); ?></th>
            <th style="width: 250px"><?php echo _a('Title'); ?></th>
            <th><?php echo _a('Description'); ?></th>
        </tr>
        <?php foreach ($categories as $category) {
            if ('root' == $category['slug']) {
                continue;
            }
            // Generate url
            $addUrl    = $this->url('', [
                'action' => 'add',
                'parent' => $category['id'],
            ]);
            $editUrl   = $this->url('', [
                'action' => 'edit',
                'id'     => $category['id'],
            ]);
            $deleteUrl = $this->url('', [
                'action' => 'delete',
                'id'     => $category['id'],
            ]);
            $mergeUrl  = $this->url('', [
                'action' => 'merge',
                'from'   => $category['id'],
            ]);
            $moveUrl   = $this->url('', [
                'action' => 'move',
                'from'   => $category['id'],
            ]);
            $sortUrl   = $this->url('', [
                'action' => 'sort',
                'from'   => $category['id'],
            ]);
            ?>
            <tr>
                <td><?php
                    if ($category['image']) {
                        $image = Pi::url($category['image']);
                        ?>
                        <div class="list-image">
                            <img src="<?php echo $this->escape($image); ?>"
                                 alt="<?php echo $this->escape($category['title']); ?>">
                        </div>
                        <?php
                    } else {
                        ?>
                        <div class="list-image"><span class="fas fa-list"><i></i></span></div>
                        <?php
                    }
                    ?>
                </td>
                <td><?php echo $this->escape(str_repeat('-', $category['depth']) . ' ' . $category['title']); ?>
                    <div class="row-actions">
                        <a href="<?php echo $this->escape($addUrl); ?>"><?php echo _a('Add'); ?></a> |
                        <a href="<?php echo $this->escape($editUrl); ?>"><?php echo _a('Edit'); ?></a> |
                        <a href="<?php echo $this->escape($deleteUrl); ?>"
                           onclick="return window.confirm('Really delete it?');"><?php echo _a('Delete'); ?></a> |
                        <a href="<?php echo $this->escape($mergeUrl); ?>"><?php echo _a('Merge'); ?></a> |
                        <a href="<?php echo $this->escape($moveUrl); ?>"><?php echo _a('Move'); ?></a> |
                        <a href="<?php echo $this->escape($sortUrl); ?>"><?php echo _a('Sort'); ?></a>
                    </div>
                </td>
                <td><?php echo $this->escape($category['description']); ?></td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
</div>
