<?php
$options  = (array)$block['options'];
$items    = (array)$block['items'];
$ellipsis = empty($options['max_rows'])
    ? 'pi-ellipsis'
    : 'pi-ellipsis pi-ellipsis-' . intval($options['max_rows']);
?>
<div class="widget-video-list">
    <?php foreach ($items as $item) { ?>
        <?php if (!empty($item['link'])) { ?>
            <div class="widget-video-single clearfix">
                <div class="pi-player">
                    <?php
                    // Get extension
                    $extension = pathinfo($item['link'], PATHINFO_EXTENSION);
                    switch ($extension) {
                        case 'mp4':
                            $type     = 'mp4';
                            $mimeType = '';
                            break;

                        case 'm3u8':
                            $type     = 'hls';
                            $mimeType = $options['hls_mime_type'];
                            break;

                        default:
                            $type     = '';
                            $mimeType = '';
                            break;
                    }
                    // Check and set player
                    if (!empty($type)) {
                        echo $mimeType;
                        echo $this->video(
                            [
                                'type'     => $type,
                                'mimetype' => $mimeType,
                                'source'   => [
                                    [
                                        'url'   => $item['link'],
                                        'title' => $item['caption'],
                                    ],
                                ],
                                'layout'   => [
                                    'title'       => $item['caption'],
                                    'posterImage' => $item['image'],
                                ],
                            ]
                        );
                    } ?>
                </div>
                <h3><?php echo _escape($item['caption']); ?></h3>
                <div class="<?php echo $ellipsis; ?>">
                    <?php echo $item['summary']; ?>
                </div>
            </div>
        <?php } ?>
    <?php } ?>
</div>