<?php
/* Smarty version 4.5.6, created on 2026-01-23 23:21:04
  from '/var/www/html/tivi/panel/templates/playlists/list.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_6973f450a57091_29772262',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '5f3a80c9532c8500bb9f0cf4e9c717272090820e' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/playlists/list.tpl',
      1 => 1769206803,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_6973f450a57091_29772262 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, true);
?>


<?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_4660858156973f450a37482_43287216', "content");
?>


<?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_18753080096973f450a54667_63658618', "scripts");
?>

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_4660858156973f450a37482_43287216 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_4660858156973f450a37482_43287216',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_checkPlugins(array(0=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.truncate.php','function'=>'smarty_modifier_truncate',),1=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.date_format.php','function'=>'smarty_modifier_date_format',),));
?>

<div class="container-fluid">
    <!-- Header -->
    <div class="d-flex flex-wrap justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1">Playlisty</h4>
            <p class="text-muted mb-0">
                <?php if ($_smarty_tpl->tpl_vars['filterDeviceId']->value && $_smarty_tpl->tpl_vars['filterDeviceName']->value) {?>
                    Playlisty urządzenia: <strong><?php echo $_smarty_tpl->tpl_vars['filterDeviceName']->value;?>
</strong>
                    <?php if ($_smarty_tpl->tpl_vars['filterDeviceOwner']->value) {?> (właściciel: <?php echo $_smarty_tpl->tpl_vars['filterDeviceOwner']->value;?>
)<?php }?>
                <?php } elseif ($_smarty_tpl->tpl_vars['filterUserId']->value && $_smarty_tpl->tpl_vars['filterUserId']->value != 'all' && $_smarty_tpl->tpl_vars['filterUserName']->value) {?>
                    Playlisty użytkownika: <strong><?php echo $_smarty_tpl->tpl_vars['filterUserName']->value;?>
</strong>
                <?php } elseif ($_smarty_tpl->tpl_vars['filterUserId']->value == 'all') {?>
                    Wszystkie playlisty
                <?php } elseif (!$_smarty_tpl->tpl_vars['isAdmin']->value && !$_smarty_tpl->tpl_vars['isReseller']->value) {?>
                    Twoje playlisty
                <?php } else { ?>
                    Twoje playlisty
                <?php }?>
            </p>
        </div>
        <?php if ($_smarty_tpl->tpl_vars['filterDeviceId']->value) {?>
        <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists/add?device_id=<?php echo $_smarty_tpl->tpl_vars['filterDeviceId']->value;?>
" class="btn btn-primary">
            <i class="bi bi-plus-lg me-1"></i>Dodaj playlistę
        </a>
        <?php }?>
    </div>

    <!-- Filters -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" class="row g-3 align-items-end" id="filterForm">
                <div class="col-md-3">
                    <label class="form-label small text-muted">Szukaj</label>
                    <div class="input-group">
                        <span class="input-group-text"><i class="bi bi-search"></i></span>
                        <input type="text" name="search" class="form-control" placeholder="Nazwa playlisty..." value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['search']->value ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
">
                    </div>
                </div>
                
                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) {?>
                <div class="col-md-3">
                    <label class="form-label small text-muted">Użytkownik</label>
                    <select name="user_id" class="form-select auto-submit" id="userFilter">
                        <option value="">-- Moje --</option>
                        <option value="all" <?php if ($_smarty_tpl->tpl_vars['filterUserId']->value == 'all') {?>selected<?php }?>>Wszyscy</option>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['users']->value, 'user');
$_smarty_tpl->tpl_vars['user']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['user']->value) {
$_smarty_tpl->tpl_vars['user']->do_else = false;
?>
                        <option value="<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
" <?php if ($_smarty_tpl->tpl_vars['filterUserId']->value == $_smarty_tpl->tpl_vars['user']->value['id']) {?>selected<?php }?>><?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>
</option>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </select>
                </div>
                <?php }?>
                
                <div class="col-md-3">
                    <label class="form-label small text-muted">Urządzenie</label>
                    <select name="device_id" class="form-select auto-submit" id="deviceFilter">
                        <option value="">Wszystkie</option>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['filteredDevices']->value, 'device');
$_smarty_tpl->tpl_vars['device']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['device']->value) {
$_smarty_tpl->tpl_vars['device']->do_else = false;
?>
                        <option value="<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
" <?php if ($_smarty_tpl->tpl_vars['filterDeviceId']->value == $_smarty_tpl->tpl_vars['device']->value['id']) {?>selected<?php }?>>
                            <?php echo (($tmp = $_smarty_tpl->tpl_vars['device']->value['name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['device']->value['mac'] ?? null : $tmp);
if ($_smarty_tpl->tpl_vars['filterUserId']->value == 'all' && $_smarty_tpl->tpl_vars['device']->value['username']) {?> - <?php echo $_smarty_tpl->tpl_vars['device']->value['username'];
}?>
                        </option>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </select>
                </div>
                
                <div class="col-md-2">
                    <button type="submit" class="btn btn-secondary w-100">
                        <i class="bi bi-filter me-1"></i>Filtruj
                    </button>
                </div>
                
                <?php if ($_smarty_tpl->tpl_vars['search']->value || $_smarty_tpl->tpl_vars['filterDeviceId']->value || $_smarty_tpl->tpl_vars['filterUserId']->value) {?>
                <div class="col-auto">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists" class="btn btn-outline-secondary">
                        <i class="bi bi-x-lg"></i>
                    </a>
                </div>
                <?php }?>
            </form>
        </div>
    </div>

    <!-- Bulk Actions Bar -->
    <div class="card mb-3 bulk-actions-bar" style="display: none;">
        <div class="card-body py-2">
            <div class="d-flex flex-wrap align-items-center gap-2">
                <span class="text-muted me-2">
                    <strong id="selectedCount">0</strong> zaznaczonych
                </span>
                <div class="vr d-none d-md-block"></div>
                <button type="button" class="btn btn-sm btn-outline-success bulk-btn" data-action="activate" title="Aktywuj zaznaczone">
                    <i class="bi bi-check-circle me-1"></i>Aktywuj
                </button>
                <button type="button" class="btn btn-sm btn-outline-secondary bulk-btn" data-action="deactivate" title="Dezaktywuj zaznaczone">
                    <i class="bi bi-x-circle me-1"></i>Dezaktywuj
                </button>
                <button type="button" class="btn btn-sm btn-outline-info bulk-btn" data-action="touch" title="Odśwież update_date">
                    <i class="bi bi-arrow-clockwise me-1"></i>Odśwież
                </button>
                <div class="vr d-none d-md-block"></div>
                <button type="button" class="btn btn-sm btn-outline-primary bulk-btn" data-action="copy" title="Kopiuj do innego urządzenia">
                    <i class="bi bi-copy me-1"></i>Kopiuj
                </button>
                <button type="button" class="btn btn-sm btn-outline-warning bulk-btn" data-action="move" title="Przenieś do innego urządzenia">
                    <i class="bi bi-arrow-right-circle me-1"></i>Przenieś
                </button>
                <div class="vr d-none d-md-block"></div>
                <button type="button" class="btn btn-sm btn-outline-danger bulk-btn" data-action="delete" title="Usuń zaznaczone">
                    <i class="bi bi-trash me-1"></i>Usuń
                </button>
            </div>
        </div>
    </div>

    <!-- Playlists Table -->
    <div class="card">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead>
                        <tr>
                            <th style="width: 40px;">
                                <input type="checkbox" class="form-check-input" id="selectAll" title="Zaznacz wszystkie">
                            </th>
                            <th>Nazwa</th>
                            <th>Typ</th>
                            <th>Urządzenie</th>
                            <?php if (($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) && $_smarty_tpl->tpl_vars['filterUserId']->value == 'all' && !$_smarty_tpl->tpl_vars['filterDeviceId']->value) {?><th>Użytkownik</th><?php }?>
                            <th>Update Date</th>
                            <th>Notatki</th>
                            <th>Status</th>
                            <th class="text-end">Akcje</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['playlists']->value, 'playlist');
$_smarty_tpl->tpl_vars['playlist']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['playlist']->value) {
$_smarty_tpl->tpl_vars['playlist']->do_else = false;
?>
                        <tr data-playlist-id="<?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
">
                            <td>
                                <input type="checkbox" class="form-check-input playlist-checkbox" 
                                       value="<?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
" 
                                       data-name="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['playlist']->value['name'], ENT_QUOTES, 'UTF-8', true);?>
"
                                       data-device-id="<?php echo $_smarty_tpl->tpl_vars['playlist']->value['device_id'];?>
">
                            </td>
                            <td>
                                <strong><?php echo $_smarty_tpl->tpl_vars['playlist']->value['name'];?>
</strong>
                                <?php if ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'xtream') {?>
                                <br><small class="text-muted"><?php echo (($tmp = $_smarty_tpl->tpl_vars['playlist']->value['config']['host'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
</small>
                                <?php } elseif ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'm3u') {?>
                                <br><small class="text-muted"><?php echo smarty_modifier_truncate((($tmp = $_smarty_tpl->tpl_vars['playlist']->value['config']['url'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp),50);?>
</small>
                                <?php } elseif ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'stalker') {?>
                                <br><small class="text-muted"><?php echo (($tmp = $_smarty_tpl->tpl_vars['playlist']->value['config']['server_url'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
</small>
                                <?php }?>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'xtream') {?>
                                <span class="badge bg-primary"><i class="bi bi-broadcast me-1"></i>Xtream</span>
                                <?php } elseif ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'm3u') {?>
                                <span class="badge bg-success"><i class="bi bi-link-45deg me-1"></i>M3U</span>
                                <?php } elseif ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'stalker') {?>
                                <span class="badge bg-warning text-dark"><i class="bi bi-hdd-network me-1"></i>Stalker</span>
                                <?php }?>
                            </td>
                            <td>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists?device_id=<?php echo $_smarty_tpl->tpl_vars['playlist']->value['device_id'];?>
">
                                    <?php echo (($tmp = $_smarty_tpl->tpl_vars['playlist']->value['device_name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['playlist']->value['mac'] ?? null : $tmp);?>

                                </a>
                                <br><small class="text-muted"><?php echo $_smarty_tpl->tpl_vars['playlist']->value['mac'];?>
</small>
                            </td>
                            <?php if (($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) && $_smarty_tpl->tpl_vars['filterUserId']->value == 'all' && !$_smarty_tpl->tpl_vars['filterDeviceId']->value) {?>
                            <td>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists?user_id=<?php echo (($tmp = $_smarty_tpl->tpl_vars['playlist']->value['owner_id'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"><?php echo $_smarty_tpl->tpl_vars['playlist']->value['username'];?>
</a>
                            </td>
                            <?php }?>
                            <td>
                                <span title="<?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['playlist']->value['update_date'],'%d.%m.%Y %H:%M:%S');?>
">
                                    <?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['playlist']->value['update_date'],"%d.%m.%Y %H:%M");?>

                                </span>
                            </td>
                            <td>
                                <span class="badge bg-secondary notes-badge" 
                                      style="cursor:pointer;"
                                      data-entity-type="playlist" 
                                      data-entity-id="<?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
"
                                      onclick="NotesManager.open('playlist', <?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
, '<?php echo strtr((string)$_smarty_tpl->tpl_vars['playlist']->value['name'], array("\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\r" => "\\r", 
                       "\n" => "\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S",
                       "`" => "\\`", "\${" => "\\\$\{"));?>
')"
                                      title="Pokaż notatki">
                                    <i class="bi bi-sticky"></i> <span class="notes-count"><?php echo (($tmp = $_smarty_tpl->tpl_vars['playlist']->value['notes_count'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
</span>
                                </span>
                            </td>
                            <td>
                                <?php if ($_smarty_tpl->tpl_vars['playlist']->value['is_active']) {?>
                                <span class="badge bg-success">Aktywna</span>
                                <?php } else { ?>
                                <span class="badge bg-secondary">Nieaktywna</span>
                                <?php }?>
                            </td>
                            <td class="text-end">
                                <div class="btn-group">
                                    <?php if ($_smarty_tpl->tpl_vars['playlist']->value['type'] == 'xtream') {?>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/xtream-check?server=<?php echo rawurlencode((string)$_smarty_tpl->tpl_vars['playlist']->value['config']['host']);?>
&user=<?php echo rawurlencode((string)$_smarty_tpl->tpl_vars['playlist']->value['config']['username']);?>
&pass=<?php echo rawurlencode((string)$_smarty_tpl->tpl_vars['playlist']->value['config']['password']);?>
" 
                                       class="btn btn-sm btn-outline-info" 
                                       title="Sprawdź w Xtream Check">
                                        <i class="bi bi-search"></i>
                                    </a>
                                    <?php }?>
                                    <button type="button" class="btn btn-sm btn-outline-secondary" 
                                            title="Dodaj notatkę"
                                            onclick="NotesManager.quickAdd('playlist', <?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
, '<?php echo strtr((string)$_smarty_tpl->tpl_vars['playlist']->value['name'], array("\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\r" => "\\r", 
                       "\n" => "\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S",
                       "`" => "\\`", "\${" => "\\\$\{"));?>
')">
                                        <i class="bi bi-sticky"></i>
                                    </button>
                                    <button type="button" 
                                            class="btn btn-sm btn-outline-<?php if ($_smarty_tpl->tpl_vars['playlist']->value['is_active']) {?>secondary<?php } else { ?>success<?php }?> toggle-active-btn" 
                                            title="<?php if ($_smarty_tpl->tpl_vars['playlist']->value['is_active']) {?>Dezaktywuj<?php } else { ?>Aktywuj<?php }?>"
                                            data-id="<?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
"
                                            data-name="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['playlist']->value['name'], ENT_QUOTES, 'UTF-8', true);?>
"
                                            data-active="<?php echo $_smarty_tpl->tpl_vars['playlist']->value['is_active'];?>
">
                                        <i class="bi bi-<?php if ($_smarty_tpl->tpl_vars['playlist']->value['is_active']) {?>pause-circle<?php } else { ?>play-circle<?php }?>"></i>
                                    </button>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists/clone?id=<?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
" class="btn btn-sm btn-outline-secondary" title="Sklonuj do innego urządzenia">
                                        <i class="bi bi-copy"></i>
                                    </a>
                                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists/edit?id=<?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
" class="btn btn-sm btn-outline-primary" title="Edytuj">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <button type="button" class="btn btn-sm btn-outline-danger delete-btn" 
                                            title="Usuń"
                                            data-id="<?php echo $_smarty_tpl->tpl_vars['playlist']->value['id'];?>
"
                                            data-name="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['playlist']->value['name'], ENT_QUOTES, 'UTF-8', true);?>
">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <?php
}
if ($_smarty_tpl->tpl_vars['playlist']->do_else) {
?>
                        <tr>
                            <td colspan="<?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>9<?php } else { ?>8<?php }?>" class="text-center py-5">
                                <div class="text-muted mb-3">
                                    <i class="bi bi-list-ul" style="font-size: 3rem;"></i>
                                </div>
                                <p class="mb-3">Brak playlist</p>
                                <?php if ($_smarty_tpl->tpl_vars['filterDeviceId']->value) {?>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists/add?device_id=<?php echo $_smarty_tpl->tpl_vars['filterDeviceId']->value;?>
" class="btn btn-primary">
                                    <i class="bi bi-plus-lg me-1"></i>Dodaj pierwszą playlistę
                                </a>
                                <?php } else { ?>
                                <p class="text-muted">Wybierz urządzenie aby dodać playlistę</p>
                                <?php }?>
                            </td>
                        </tr>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </tbody>
                </table>
            </div>
        </div>

        <?php if ($_smarty_tpl->tpl_vars['pagination']->value['total_pages'] > 1) {?>
        <div class="card-footer">
            <nav>
                                <?php $_smarty_tpl->_assignInScope('paginationParams', '');?>
                <?php if ($_smarty_tpl->tpl_vars['filterDeviceId']->value) {
$_smarty_tpl->_assignInScope('paginationParams', ((string)$_smarty_tpl->tpl_vars['paginationParams']->value)."&device_id=".((string)$_smarty_tpl->tpl_vars['filterDeviceId']->value));
}?>
                <?php if ($_smarty_tpl->tpl_vars['filterUserId']->value) {
$_smarty_tpl->_assignInScope('paginationParams', ((string)$_smarty_tpl->tpl_vars['paginationParams']->value)."&user_id=".((string)$_smarty_tpl->tpl_vars['filterUserId']->value));
}?>
                <?php if ($_smarty_tpl->tpl_vars['search']->value) {
ob_start();
echo rawurlencode((string)$_smarty_tpl->tpl_vars['search']->value);
$_prefixVariable1=ob_get_clean();
$_smarty_tpl->_assignInScope('paginationParams', ((string)$_smarty_tpl->tpl_vars['paginationParams']->value)."&search=".$_prefixVariable1);
}?>
                
                <ul class="pagination pagination-sm mb-0 justify-content-center">
                    <li class="page-item<?php if (!$_smarty_tpl->tpl_vars['pagination']->value['has_prev']) {?> disabled<?php }?>">
                        <a class="page-link" href="?page=<?php echo $_smarty_tpl->tpl_vars['pagination']->value['current_page']-1;
echo $_smarty_tpl->tpl_vars['paginationParams']->value;?>
">
                            <i class="bi bi-chevron-left"></i>
                        </a>
                    </li>
                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['pagination']->value['pages'], 'page');
$_smarty_tpl->tpl_vars['page']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['page']->value) {
$_smarty_tpl->tpl_vars['page']->do_else = false;
?>
                        <?php if ($_smarty_tpl->tpl_vars['page']->value === '...') {?>
                        <li class="page-item disabled"><span class="page-link">...</span></li>
                        <?php } else { ?>
                        <li class="page-item<?php if ($_smarty_tpl->tpl_vars['page']->value == $_smarty_tpl->tpl_vars['pagination']->value['current_page']) {?> active<?php }?>">
                            <a class="page-link" href="?page=<?php echo $_smarty_tpl->tpl_vars['page']->value;
echo $_smarty_tpl->tpl_vars['paginationParams']->value;?>
"><?php echo $_smarty_tpl->tpl_vars['page']->value;?>
</a>
                        </li>
                        <?php }?>
                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    <li class="page-item<?php if (!$_smarty_tpl->tpl_vars['pagination']->value['has_next']) {?> disabled<?php }?>">
                        <a class="page-link" href="?page=<?php echo $_smarty_tpl->tpl_vars['pagination']->value['current_page']+1;
echo $_smarty_tpl->tpl_vars['paginationParams']->value;?>
">
                            <i class="bi bi-chevron-right"></i>
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
        <?php }?>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_18753080096973f450a54667_63658618 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_18753080096973f450a54667_63658618',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>
var playlistConfig = {
    csrfToken: '<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
',
    baseUrl: '<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
',
    currentUserId: '<?php echo $_smarty_tpl->tpl_vars['currentUser']->value['id'];?>
',
    deviceOptions: '<?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['devices']->value, 'device');
$_smarty_tpl->tpl_vars['device']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['device']->value) {
$_smarty_tpl->tpl_vars['device']->do_else = false;
?><option value="<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
"><?php echo strtr((string)(($tmp = $_smarty_tpl->tpl_vars['device']->value['name'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['device']->value['mac'] ?? null : $tmp), array("\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\r" => "\\r", 
                       "\n" => "\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S",
                       "`" => "\\`", "\${" => "\\\$\{"));?>
 (<?php echo $_smarty_tpl->tpl_vars['device']->value['mac'];?>
)<?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?> - <?php echo $_smarty_tpl->tpl_vars['device']->value['username'];
}?></option><?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>'
};
<?php echo '</script'; ?>
>

<?php echo '<script'; ?>
>
(function() {
    const csrfToken = playlistConfig.csrfToken;
    const baseUrl = playlistConfig.baseUrl;
    const currentUserId = playlistConfig.currentUserId;
    const deviceOptions = playlistConfig.deviceOptions;
    const selectAll = document.getElementById('selectAll');
    const checkboxes = document.querySelectorAll('.playlist-checkbox');
    const bulkBar = document.querySelector('.bulk-actions-bar');
    const selectedCountEl = document.getElementById('selectedCount');

    const swalConfig = {
        background: '#1a1d21',
        color: '#e1e1e1',
        confirmButtonColor: '#0d6efd',
        cancelButtonColor: '#6c757d'
    };

    function updateBulkBar() {
        const checked = document.querySelectorAll('.playlist-checkbox:checked');
        const count = checked.length;
        selectedCountEl.textContent = count;
        bulkBar.style.display = count > 0 ? 'block' : 'none';
        selectAll.checked = count > 0 && count === checkboxes.length;
        selectAll.indeterminate = count > 0 && count < checkboxes.length;
    }

    function getSelectedIds() {
        return Array.from(document.querySelectorAll('.playlist-checkbox:checked')).map(cb => cb.value);
    }

    function submitForm(action, ids, extraData) {
        extraData = extraData || {};
        const form = document.createElement('form');
        form.method = 'POST';
        form.action = baseUrl + '/playlists/bulk';
        
        const fields = Object.assign({ csrf_token: csrfToken, action: action, ids: ids.join(',') }, extraData);
        for (const key in fields) {
            const input = document.createElement('input');
            input.type = 'hidden';
            input.name = key;
            input.value = fields[key];
            form.appendChild(input);
        }
        
        document.body.appendChild(form);
        form.submit();
    }

    if (selectAll) {
        selectAll.addEventListener('change', function() {
            checkboxes.forEach(function(cb) { cb.checked = selectAll.checked; });
            updateBulkBar();
        });
    }

    checkboxes.forEach(function(cb) { cb.addEventListener('change', updateBulkBar); });

    document.querySelectorAll('.bulk-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            const action = this.dataset.action;
            const ids = getSelectedIds();
            if (ids.length === 0) return;

            switch(action) {
                case 'delete':
                    Swal.fire({
                        title: 'Potwierdź usunięcie',
                        html: 'Czy na pewno chcesz usunąć <strong>' + ids.length + '</strong> zaznaczonych playlist?<br><br><span class="text-danger">Tej operacji nie można cofnąć!</span>',
                        icon: 'warning',
                        showCancelButton: true,
                        confirmButtonText: 'Usuń',
                        cancelButtonText: 'Anuluj',
                        confirmButtonColor: '#dc3545',
                        background: swalConfig.background,
                        color: swalConfig.color
                    }).then(function(result) {
                        if (result.isConfirmed) submitForm('delete', ids);
                    });
                    break;

                case 'activate':
                    Swal.fire({
                        title: 'Aktywacja playlist',
                        html: 'Czy aktywować <strong>' + ids.length + '</strong> zaznaczonych playlist?',
                        icon: 'question',
                        showCancelButton: true,
                        confirmButtonText: 'Aktywuj',
                        cancelButtonText: 'Anuluj',
                        confirmButtonColor: '#198754',
                        background: swalConfig.background,
                        color: swalConfig.color
                    }).then(function(result) {
                        if (result.isConfirmed) submitForm('activate', ids);
                    });
                    break;

                case 'deactivate':
                    Swal.fire({
                        title: 'Dezaktywacja playlist',
                        html: 'Czy dezaktywować <strong>' + ids.length + '</strong> zaznaczonych playlist?',
                        icon: 'question',
                        showCancelButton: true,
                        confirmButtonText: 'Dezaktywuj',
                        cancelButtonText: 'Anuluj',
                        background: swalConfig.background,
                        color: swalConfig.color,
                        cancelButtonColor: swalConfig.cancelButtonColor
                    }).then(function(result) {
                        if (result.isConfirmed) submitForm('deactivate', ids);
                    });
                    break;

                case 'touch':
                    Swal.fire({
                        title: 'Odświeżenie playlist',
                        html: 'Czy odświeżyć update_date dla <strong>' + ids.length + '</strong> zaznaczonych playlist?<br><br><small class="text-muted">Wymusi to ponowne pobranie playlist przez urządzenia.</small>',
                        icon: 'question',
                        showCancelButton: true,
                        confirmButtonText: 'Odśwież',
                        cancelButtonText: 'Anuluj',
                        confirmButtonColor: '#0dcaf0',
                        background: swalConfig.background,
                        color: swalConfig.color
                    }).then(function(result) {
                        if (result.isConfirmed) submitForm('touch', ids);
                    });
                    break;

                case 'copy':
                case 'move':
                    var isMove = action === 'move';
                    Swal.fire({
                        title: isMove ? 'Przenieś playlisty' : 'Kopiuj playlisty',
                        html: '<p><strong>' + ids.length + '</strong> playlist zostanie ' + (isMove ? 'przeniesionych' : 'skopiowanych') + '.</p>' +
                            '<div class="mb-3 text-start">' +
                            '<label class="form-label">Urządzenie docelowe</label>' +
                            '<select id="swal-device" class="form-select">' +
                            '<option value="">Wybierz urządzenie...</option>' +
                            deviceOptions +
                            '</select>' +
                            '</div>' +
                            '<small class="text-muted">Duplikaty zostaną pominięte. Nazwy będą automatycznie ponumerowane.</small>',
                        icon: 'question',
                        showCancelButton: true,
                        confirmButtonText: isMove ? 'Przenieś' : 'Kopiuj',
                        cancelButtonText: 'Anuluj',
                        confirmButtonColor: isMove ? '#ffc107' : '#0d6efd',
                        background: swalConfig.background,
                        color: swalConfig.color,
                        preConfirm: function() {
                            var deviceId = document.getElementById('swal-device').value;
                            if (!deviceId) {
                                Swal.showValidationMessage('Wybierz urządzenie docelowe');
                                return false;
                            }
                            return deviceId;
                        }
                    }).then(function(result) {
                        if (result.isConfirmed) {
                            submitForm(action, ids, { target_device_id: result.value });
                        }
                    });
                    break;
            }
        });
    });

    // Single toggle active button
    document.querySelectorAll('.toggle-active-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var id = this.dataset.id;
            var name = this.dataset.name;
            var isActive = this.dataset.active === '1';
            var actionText = isActive ? 'dezaktywować' : 'aktywować';

            Swal.fire({
                title: (isActive ? 'Dezaktywacja' : 'Aktywacja') + ' playlisty',
                html: 'Czy ' + actionText + ' playlistę <strong>"' + name + '"</strong>?',
                icon: 'question',
                showCancelButton: true,
                confirmButtonText: isActive ? 'Dezaktywuj' : 'Aktywuj',
                cancelButtonText: 'Anuluj',
                confirmButtonColor: isActive ? '#6c757d' : '#198754',
                background: swalConfig.background,
                color: swalConfig.color
            }).then(function(result) {
                if (result.isConfirmed) {
                    var form = document.createElement('form');
                    form.method = 'POST';
                    form.action = baseUrl + '/playlists/toggle-active';
                    form.innerHTML = '<input type="hidden" name="csrf_token" value="' + csrfToken + '"><input type="hidden" name="id" value="' + id + '">';
                    document.body.appendChild(form);
                    form.submit();
                }
            });
        });
    });

    // Single delete button
    document.querySelectorAll('.delete-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var id = this.dataset.id;
            var name = this.dataset.name;

            Swal.fire({
                title: 'Potwierdź usunięcie',
                html: 'Czy na pewno chcesz usunąć playlistę <strong>"' + name + '"</strong>?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Usuń',
                cancelButtonText: 'Anuluj',
                confirmButtonColor: '#dc3545',
                background: swalConfig.background,
                color: swalConfig.color
            }).then(function(result) {
                if (result.isConfirmed) {
                    var form = document.createElement('form');
                    form.method = 'POST';
                    form.action = baseUrl + '/playlists/delete';
                    form.innerHTML = '<input type="hidden" name="csrf_token" value="' + csrfToken + '"><input type="hidden" name="id" value="' + id + '">';
                    document.body.appendChild(form);
                    form.submit();
                }
            });
        });
    });
    
    // Filtruj urządzenia po wyborze użytkownika
    var userFilter = document.getElementById('userFilter');
    var deviceFilter = document.getElementById('deviceFilter');
    
    // Auto-submit przy zmianie filtrów (user_id, device_id)
    document.querySelectorAll('.auto-submit').forEach(function(el) {
        el.addEventListener('change', function() {
            // Przy zmianie użytkownika - resetuj urządzenie
            if (this.id === 'userFilter') {
                var deviceFilter = document.getElementById('deviceFilter');
                if (deviceFilter) {
                    deviceFilter.value = '';
                }
            }
            document.getElementById('filterForm').submit();
        });
    });
})();
<?php echo '</script'; ?>
>

<?php
}
}
/* {/block "scripts"} */
}
