<?php $this->SetLayout('account'); ?>
<?php $playlistService = $this->getService('Playlist'); ?>

<h1><?=Language::GetText('playlists_header')?></h1>

<?php if ($message): ?>
    <div class="message <?=$message_type?>"><?=$message?></div>
<?php endif; ?>


<div class="playlist-list">

    <!-- Begin Favorites -->
    <div class="playlist <?=(empty($favoritesList->entries)) ? 'playlist-empty' : ''?>">
        <?php if (!empty($favoritesList->entries)): ?>
            <a href="<?=$playlistService->getUrl($favoritesList)?>" title="<?=Language::GetText('favorites')?>">
                <img width="165" height="92" src="<?=getPlaylistThumbnail($favoritesList)?>" />
                <span class="video-count"><?=count($favoritesList->entries)?><br><?=Language::GetText('videos')?></span>
                <span class="watch-all">Watch<br>All</span>
            </a>
            <p class="title"><a href="<?=$playlistService->getUrl($favoritesList)?>" title="<?=Language::GetText('favorites')?>"><?=Language::GetText('favorites')?></a></p>
        <?php else: ?>
            <img src="<?=$this->options->themeUrl?>/images/playlist_placeholder.png" />
            <span class="video-count"><?=count($favoritesList->entries)?><br><?=Language::GetText('videos')?></span>
            <p class="title"><?=Language::GetText('favorites')?></p>
        <?php endif; ?>
        <p class="actions small">
            <a href="<?=HOST?>/account/playlists/edit/<?=$favoritesList->playlistId?>/" title="<?=Language::GetText('edit_playlist')?>"><?=Language::GetText('edit_playlist')?></a>
        </p>
    </div>

    <!-- Begin Watch Later -->
    <div class="playlist <?=(empty($watchLaterList->entries)) ? 'playlist-empty' : ''?>">
        <?php if (!empty($watchLaterList->entries)): ?>
            <a href="<?=$playlistService->getUrl($watchLaterList)?>" title="<?=Language::GetText('watch_later')?>">
                <img width="165" height="92" src="<?=getPlaylistThumbnail($watchLaterList)?>" />
                <span class="video-count"><?=count($watchLaterList->entries)?><br><?=Language::GetText('videos')?></span>
                <span class="watch-all">Watch<br>All</span>
            </a>
            <p class="title"><a href="<?=$playlistService->getUrl($watchLaterList)?>" title="<?=Language::GetText('watch_later')?>"><?=Language::GetText('watch_later')?></a></p>
        <?php else: ?>
            <img src="<?=$this->options->themeUrl?>/images/playlist_placeholder.png" />
            <span class="video-count"><?=count($watchLaterList->entries)?><br><?=Language::GetText('videos')?></span>
            <p class="title"><?=Language::GetText('watch_later')?></p>
        <?php endif; ?>
        <p class="actions small">
            <a href="<?=HOST?>/account/playlists/edit/<?=$watchLaterList->playlistId?>/" title="<?=Language::GetText('edit_playlist')?>"><?=Language::GetText('edit_playlist')?></a>
        </p>
    </div>
</div>

<h2><?=Language::GetText('playlists')?></h2>
<p><a class="showhide" data-block="createNewPlaylist" href=""><?=Language::GetText('create_new_playlist')?></a></p>

<!-- BEGIN CREATE PLAYLIST FORM -->
<div id="createNewPlaylist">
    <h2><?=Language::GetText('create_new_playlist')?></h2>
    <div class="form playlists_form">
        <form method="POST">
            <div class="field">
                <label><?=Language::GetText('playlist_name')?>:</label>
                <input class="text" type="text" name="name" />
            </div>
            <div class="field">
                <label><?=Language::GetText('visibility')?>:</label>
                <select name="visibility">
                    <option value="public"><?=Language::GetText('public')?></option>
                    <option value="private"><?=Language::GetText('private')?></option>
                </select>
            </div>
            <input class="button" type="submit" value="<?=Language::GetText('create_playlist_button')?>" />
            <input type="hidden" name="submitted" value="true" />
            <input type="hidden" name="nonce" value="<?php echo $formNonce; ?>" />
        </form>
    </div>
</div>
<!-- END CREATE PLAYLIST FORM -->

<?php if (count($userPlaylists) > 0): ?>

    <div class="playlist-list">
    <?php foreach ($userPlaylists as $playlist): ?>
        <div class="playlist <?=(empty($playlist->entries)) ? 'playlist-empty' : ''?>">
            <?php if (!empty($playlist->entries)): ?>
                <a href="<?=$playlistService->getUrl($playlist)?>" title="<?php echo htmlspecialchars($playlist->name); ?>">
                    <img width="165" height="92" src="<?=getPlaylistThumbnail($playlist)?>" />
                    <span class="video-count"><?=count($playlist->entries)?><br><?=Language::GetText('videos')?></span>
                    <span class="watch-all">Watch<br>All</span>
                </a>
                <p class="title"><a href="<?=$playlistService->getUrl($playlist)?>" title="<?php echo htmlspecialchars($playlist->name); ?>"><?php echo htmlspecialchars($playlist->name); ?></a></p>
            <?php else: ?>
                <img src="<?=$this->options->themeUrl?>/images/playlist_placeholder.png" />
                <span class="video-count"><?=count($playlist->entries)?><br><?=Language::GetText('videos')?></span>
                <p class="title"><?php echo htmlspecialchars($playlist->name); ?></p>
            <?php endif; ?>
            <p class="actions small">
                <a href="<?=HOST?>/account/playlists/edit/<?=$playlist->playlistId?>/" title="<?=Language::GetText('edit_playlist')?>"><?=Language::GetText('edit_playlist')?></a>
                <a class="right confirm" data-node="confirm_delete_playlist" href="<?=HOST?>/account/playlists/?remove=<?=$playlist->playlistId?>" title="<?=Language::GetText('delete_playlist')?>"><?=Language::GetText('delete_playlist')?></a>
            </p>
        </div>
    <?php endforeach; ?>
    </div>

<?php else: ?>
    <p><strong><?=Language::GetText('no_playlists')?></strong></p>
<?php endif; ?>