<?php
/* Smarty version 4.5.6, created on 2026-01-24 18:41:25
  from '/var/www/html/tivi/panel/templates/layout.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_69750445c791f3_18392366',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    'f27c417c41df7c3b26907f27525e7be1e3390cf4' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/layout.tpl',
      1 => 1769276384,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_69750445c791f3_18392366 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_checkPlugins(array(0=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.count.php','function'=>'smarty_modifier_count',),));
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, false);
?>
<!DOCTYPE html>
<html lang="pl" data-bs-theme="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo (($tmp = $_smarty_tpl->tpl_vars['pageTitle']->value ?? null)===null||$tmp==='' ? 'Panel' ?? null : $tmp);?>
 - Playlist Manager</title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/assets/css/style.css" rel="stylesheet">
    <?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_130277206169750445c648d8_16951131', "styles");
?>

</head>
<body>
    <?php if ($_smarty_tpl->tpl_vars['currentUser']->value) {?>
    <!-- Sidebar -->
    <aside class="sidebar" id="sidebar">
        <div class="sidebar-header">
            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/" class="sidebar-brand">
                <i class="bi bi-collection-play-fill"></i>
                <span>Playlist Panel</span>
            </a>
            <button class="sidebar-toggle d-lg-none" id="sidebarClose">
                <i class="bi bi-x-lg"></i>
            </button>
        </div>
        
        <nav class="sidebar-nav">
            <ul class="nav flex-column">
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Dashboard') {?> active<?php }?>">
                        <i class="bi bi-speedometer2"></i>
                        <span>Dashboard</span>
                    </a>
                </li>
                
                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) {?>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Użytkownicy' || $_smarty_tpl->tpl_vars['pageTitle']->value == 'Dodaj użytkownika' || $_smarty_tpl->tpl_vars['pageTitle']->value == 'Edytuj użytkownika') {?> active<?php }?>">
                        <i class="bi bi-people"></i>
                        <span>Użytkownicy</span>
                    </a>
                </li>
                <?php }?>
                
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Urządzenia' || $_smarty_tpl->tpl_vars['pageTitle']->value == 'Dodaj urządzenie' || $_smarty_tpl->tpl_vars['pageTitle']->value == 'Edytuj urządzenie') {?> active<?php }?>">
                        <i class="bi bi-tv"></i>
                        <span>Urządzenia</span>
                    </a>
                </li>
                
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Playlisty' || $_smarty_tpl->tpl_vars['pageTitle']->value == 'Dodaj playlistę' || $_smarty_tpl->tpl_vars['pageTitle']->value == 'Edytuj playlistę') {?> active<?php }?>">
                        <i class="bi bi-list-ul"></i>
                        <span>Playlisty</span>
                    </a>
                </li>
                
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/dns" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Zmiana DNS') {?> active<?php }?>">
                        <i class="bi bi-arrow-repeat"></i>
                        <span>Zmiana DNS</span>
                    </a>
                </li>
                
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/notes" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Notatki') {?> active<?php }?>">
                        <i class="bi bi-journal-text"></i>
                        <span>Notatki</span>
                    </a>
                </li>
                
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/xtream-check" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Xtream Check') {?> active<?php }?>">
                        <i class="bi bi-broadcast"></i>
                        <span>Xtream Check</span>
                    </a>
                </li>
                
                <?php if ((isset($_smarty_tpl->tpl_vars['externalLinks']->value)) && smarty_modifier_count($_smarty_tpl->tpl_vars['externalLinks']->value) > 0) {?>
                <li class="nav-header">Linki</li>
                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['externalLinks']->value, 'extLink');
$_smarty_tpl->tpl_vars['extLink']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['extLink']->value) {
$_smarty_tpl->tpl_vars['extLink']->do_else = false;
?>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['extLink']->value['url'];?>
" class="nav-link" <?php if ($_smarty_tpl->tpl_vars['extLink']->value['open_new_tab']) {?>target="_blank" rel="noopener noreferrer"<?php }?>>
                        <i class="bi <?php echo $_smarty_tpl->tpl_vars['extLink']->value['icon'];?>
"></i>
                        <span><?php echo $_smarty_tpl->tpl_vars['extLink']->value['name'];?>
</span>
                        <?php if ($_smarty_tpl->tpl_vars['extLink']->value['open_new_tab']) {?><i class="bi bi-box-arrow-up-right ms-auto small opacity-50"></i><?php }?>
                    </a>
                </li>
                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                <?php }?>
                
                                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/settings/my" class="nav-link<?php if (strstr($_smarty_tpl->tpl_vars['pageTitle']->value,'Moje ustawienia')) {?> active<?php }?>">
                        <i class="bi bi-sliders2"></i>
                        <span>Moje ustawienia</span>
                    </a>
                </li>
                
                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                <li class="nav-header">Ustawienia urządzeń</li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/settings/definitions" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Definicje ustawień') {?> active<?php }?>">
                        <i class="bi bi-sliders"></i>
                        <span>Definicje</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/settings/presets" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Zestawy ustawień') {?> active<?php }?>">
                        <i class="bi bi-collection"></i>
                        <span>Presety</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/settings/global" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Ustawienia globalne') {?> active<?php }?>">
                        <i class="bi bi-globe"></i>
                        <span>Globalne</span>
                    </a>
                </li>
                <?php }?>
                
                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value || $_smarty_tpl->tpl_vars['isReseller']->value) {?>
                <li class="nav-header">Administracja</li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/sessions" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Aktywne sesje') {?> active<?php }?>">
                        <i class="bi bi-broadcast"></i>
                        <span>Aktywne sesje</span>
                    </a>
                </li>
                <?php }?>
                <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/logs" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Logi aplikacji') {?> active<?php }?>">
                        <i class="bi bi-journal-text"></i>
                        <span>Logi aplikacji</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/logs/api" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Logi API') {?> active<?php }?>">
                        <i class="bi bi-cloud-arrow-down"></i>
                        <span>Logi API</span>
                    </a>
                </li>
                
                <li class="nav-header">Raporty</li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/reports/activity" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Raport aktywności') {?> active<?php }?>">
                        <i class="bi bi-graph-up"></i>
                        <span>Aktywność</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/reports/audit" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Historia zmian') {?> active<?php }?>">
                        <i class="bi bi-clock-history"></i>
                        <span>Historia zmian</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/reports/logins" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Historia logowań') {?> active<?php }?>">
                        <i class="bi bi-door-open"></i>
                        <span>Historia logowań</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/reports/export" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Eksport danych') {?> active<?php }?>">
                        <i class="bi bi-file-earmark-arrow-down"></i>
                        <span>Eksport CSV</span>
                    </a>
                </li>
                
                <li class="nav-header">Bezpieczeństwo</li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/security" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Bezpieczeństwo') {?> active<?php }?>">
                        <i class="bi bi-shield-check"></i>
                        <span>Dashboard</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/security/ip-rules" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Reguły IP') {?> active<?php }?>">
                        <i class="bi bi-shield-lock"></i>
                        <span>Reguły IP</span>
                    </a>
                </li>
                
                <li class="nav-header">System</li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/settings" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Konfiguracja systemu') {?> active<?php }?>">
                        <i class="bi bi-gear"></i>
                        <span>Konfiguracja</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/links" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Linki zewnętrzne') {?> active<?php }?>">
                        <i class="bi bi-link-45deg"></i>
                        <span>Linki zewnętrzne</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/monitor" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Monitor serwera') {?> active<?php }?>">
                        <i class="bi bi-speedometer2"></i>
                        <span>Monitor serwera</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/system-logs" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Logi systemowe') {?> active<?php }?>">
                        <i class="bi bi-terminal"></i>
                        <span>Logi systemowe</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/cron" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Harmonogram zadań') {?> active<?php }?>">
                        <i class="bi bi-calendar-check"></i>
                        <span>Harmonogram</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/tools" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Narzędzia') {?> active<?php }?>">
                        <i class="bi bi-tools"></i>
                        <span>Narzędzia</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/backups" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Kopie zapasowe') {?> active<?php }?>">
                        <i class="bi bi-cloud-download"></i>
                        <span>Kopie zapasowe</span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/updates" class="nav-link<?php if ($_smarty_tpl->tpl_vars['pageTitle']->value == 'Aktualizacje') {?> active<?php }?>">
                        <i class="bi bi-arrow-repeat"></i>
                        <span>Aktualizacje</span>
                    </a>
                </li>
                <?php }?>
            </ul>
        </nav>
        
        <div class="sidebar-footer">
            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/profile" class="user-info text-decoration-none">
                <div class="user-avatar">
                    <i class="bi bi-person-circle"></i>
                </div>
                <div class="user-details">
                    <span class="user-name"><?php echo $_smarty_tpl->tpl_vars['currentUser']->value['username'];?>
</span>
                    <span class="user-role"><?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>Administrator<?php } elseif ($_smarty_tpl->tpl_vars['isReseller']->value) {?>Reseller<?php } else { ?>Użytkownik<?php }?></span>
                </div>
            </a>
        </div>
    </aside>

    <!-- Main Content -->
    <main class="main-content">
        <!-- Top Navbar -->
        <nav class="top-navbar">
            <button class="sidebar-toggle d-lg-none" id="sidebarToggle">
                <i class="bi bi-list"></i>
            </button>
            
            <div class="navbar-title d-none d-md-block">
                <?php echo (($tmp = $_smarty_tpl->tpl_vars['pageTitle']->value ?? null)===null||$tmp==='' ? 'Dashboard' ?? null : $tmp);?>

            </div>
            
            <div class="navbar-actions">
                <div class="dropdown">
                    <button class="btn btn-link dropdown-toggle" type="button" data-bs-toggle="dropdown">
                        <i class="bi bi-person-circle"></i>
                        <span class="d-none d-md-inline ms-1"><?php echo $_smarty_tpl->tpl_vars['currentUser']->value['username'];?>
</span>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li>
                            <a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#changePasswordModal">
                                <i class="bi bi-key me-2"></i>Zmień hasło
                            </a>
                        </li>
                        <li><hr class="dropdown-divider"></li>
                        <li>
                            <a class="dropdown-item text-danger" href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/logout">
                                <i class="bi bi-box-arrow-right me-2"></i>Wyloguj
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>

        <!-- Page Content -->
        <div class="page-content">
            <?php if ($_smarty_tpl->tpl_vars['flash']->value) {?>
            <div class="alert alert-<?php echo $_smarty_tpl->tpl_vars['flash']->value['type'];?>
 alert-dismissible fade show" role="alert">
                <?php echo $_smarty_tpl->tpl_vars['flash']->value['message'];?>

                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
            <?php }?>

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

        </div>
    </main>

    <!-- Change Password Modal -->
    <div class="modal fade" id="changePasswordModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <form action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/change-password" method="post">
                    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                    <div class="modal-header">
                        <h5 class="modal-title">Zmień hasło</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                    </div>
                    <div class="modal-body">
                        <div class="mb-3">
                            <label class="form-label">Aktualne hasło</label>
                            <input type="password" name="current_password" class="form-control" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Nowe hasło</label>
                            <input type="password" name="new_password" class="form-control" minlength="6" required>
                        </div>
                        <div class="mb-3">
                            <label class="form-label">Potwierdź nowe hasło</label>
                            <input type="password" name="confirm_password" class="form-control" minlength="6" required>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
                        <button type="submit" class="btn btn-primary">Zmień hasło</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php } else { ?>
    <?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_174913712369750445c76387_77281302', "content");
?>

    <?php }?>

    <!-- Global Notes Modal -->
    <div class="modal fade" id="globalNotesModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">
                        <i class="bi bi-sticky me-2"></i>Notatki: <span id="notesModalEntityName"></span>
                    </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <span class="text-muted">
                            Liczba notatek: <span id="notesModalCount" class="badge bg-secondary">0</span>
                        </span>
                        <button type="button" class="btn btn-primary btn-sm" id="addNoteFromModalBtn">
                            <i class="bi bi-plus-lg me-1"></i>Dodaj notatkę
                        </button>
                    </div>
                    <div id="notesModalList" class="notes-modal-list">
                        <div class="text-center py-4 text-muted">
                            <i class="bi bi-sticky d-block mb-2" style="font-size: 2rem;"></i>
                            Brak notatek
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Note Edit Modal -->
    <div class="modal fade" id="noteEditModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="noteEditModalTitle">Nowa notatka</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="editNoteId" value="">
                    <input type="hidden" id="editNoteEntityType" value="">
                    <input type="hidden" id="editNoteEntityId" value="">
                    
                    <div class="mb-3">
                        <label class="form-label">Tytuł (opcjonalnie)</label>
                        <input type="text" id="editNoteTitle" class="form-control" placeholder="Tytuł notatki">
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">Treść <span class="text-danger">*</span></label>
                        <textarea id="editNoteContent" class="form-control" rows="4" placeholder="Treść notatki..." required></textarea>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">Kolor</label>
                        <div class="d-flex gap-2 flex-wrap" id="editNoteColors">
                            <button type="button" class="btn btn-sm note-color-btn active" data-color="default" style="background: #6c757d; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                            <button type="button" class="btn btn-sm note-color-btn" data-color="red" style="background: #dc3545; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                            <button type="button" class="btn btn-sm note-color-btn" data-color="orange" style="background: #fd7e14; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                            <button type="button" class="btn btn-sm note-color-btn" data-color="yellow" style="background: #ffc107; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                            <button type="button" class="btn btn-sm note-color-btn" data-color="green" style="background: #198754; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                            <button type="button" class="btn btn-sm note-color-btn" data-color="blue" style="background: #0d6efd; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                            <button type="button" class="btn btn-sm note-color-btn" data-color="purple" style="background: #6f42c1; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                            <button type="button" class="btn btn-sm note-color-btn" data-color="pink" style="background: #d63384; width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent;"></button>
                        </div>
                    </div>
                    
                    <div class="form-check">
                        <input type="checkbox" id="editNotePinned" class="form-check-input">
                        <label class="form-check-label" for="editNotePinned">Przypnij na górze</label>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
                    <button type="button" class="btn btn-primary" id="saveNoteEditBtn">Zapisz</button>
                </div>
            </div>
        </div>
    </div>

    <style>
    .notes-modal-list .note-item {
        padding: 12px 15px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 10px;
        position: relative;
        padding-left: 20px;
    }
    .notes-modal-list .note-item:last-child { margin-bottom: 0; }
    .notes-modal-list .note-item.pinned { background: rgba(var(--bs-primary-rgb), 0.08); }
    .notes-modal-list .note-color-bar {
        width: 5px;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        border-radius: 8px 0 0 8px;
    }
    .notes-modal-list .note-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 8px;
    }
    .notes-modal-list .note-title { font-weight: 600; font-size: 0.95rem; }
    .notes-modal-list .note-content { font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; margin-bottom: 8px; }
    .notes-modal-list .note-meta { font-size: 0.8rem; color: var(--text-muted); }
    .note-color-btn.active { border-color: #fff !important; box-shadow: 0 0 0 2px rgba(255,255,255,0.3); }
    .notes-badge { cursor: pointer; transition: transform 0.2s; }
    .notes-badge:hover { transform: scale(1.1); }
    </style>

    <!-- Bootstrap JS -->
    <?php echo '<script'; ?>
 src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"><?php echo '</script'; ?>
>
    <!-- SweetAlert2 -->
    <?php echo '<script'; ?>
 src="https://cdn.jsdelivr.net/npm/sweetalert2@11"><?php echo '</script'; ?>
>
    <!-- Custom JS -->
    <?php echo '<script'; ?>
 src="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/assets/js/app.js"><?php echo '</script'; ?>
>
    
    <!-- Global Notes Functions -->
    <?php echo '<script'; ?>
>
    
    window.NotesManager = (function() {
        var baseUrl = '';
        var currentUserId = 0;
        var isAdmin = false;
        var currentEntityType = '';
        var currentEntityId = 0;
        var currentEntityName = '';
        var notesModal = null;
        var editModal = null;
        
        var colors = {
            default: '#6c757d', red: '#dc3545', orange: '#fd7e14', yellow: '#ffc107',
            green: '#198754', blue: '#0d6efd', purple: '#6f42c1', pink: '#d63384'
        };
        
        function init(url, userId, admin) {
            baseUrl = url;
            currentUserId = userId;
            isAdmin = admin;
            notesModal = new bootstrap.Modal(document.getElementById('globalNotesModal'));
            editModal = new bootstrap.Modal(document.getElementById('noteEditModal'));
            
            // Color selection
            document.querySelectorAll('#editNoteColors .note-color-btn').forEach(function(btn) {
                btn.addEventListener('click', function() {
                    document.querySelectorAll('#editNoteColors .note-color-btn').forEach(function(b) { b.classList.remove('active'); });
                    this.classList.add('active');
                });
            });
            
            // Add from modal button
            document.getElementById('addNoteFromModalBtn').addEventListener('click', function() {
                openEditModal(null);
            });
            
            // Save button
            document.getElementById('saveNoteEditBtn').addEventListener('click', saveNote);
        }
        
        function canEditNote(note) {
            return isAdmin || (note.user_id == currentUserId);
        }
        
        function openNotesModal(entityType, entityId, entityName) {
            currentEntityType = entityType;
            currentEntityId = entityId;
            currentEntityName = entityName;
            
            document.getElementById('notesModalEntityName').textContent = entityName;
            loadNotes();
            notesModal.show();
        }
        
        function loadNotes() {
            fetch(baseUrl + '/entity-notes/list?entity_type=' + currentEntityType + '&entity_id=' + currentEntityId)
                .then(function(r) { return r.json(); })
                .then(function(data) {
                    if (data.success) {
                        renderNotes(data.notes);
                        document.getElementById('notesModalCount').textContent = data.count;
                    }
                });
        }
        
        function renderNotes(notes) {
            var list = document.getElementById('notesModalList');
            
            if (notes.length === 0) {
                list.innerHTML = '<div class="text-center py-4 text-muted"><i class="bi bi-sticky d-block mb-2" style="font-size: 2rem;"></i>Brak notatek</div>';
                return;
            }
            
            list.innerHTML = notes.map(function(note) {
                var canEdit = canEditNote(note);
                var actionButtons = '';
                
                if (canEdit) {
                    actionButtons = '<div class="btn-group btn-group-sm">' +
                        '<button class="btn btn-outline-secondary btn-pin" data-id="' + note.id + '" title="' + (note.is_pinned ? 'Odepnij' : 'Przypnij') + '">' +
                            '<i class="bi bi-pin' + (note.is_pinned ? '-fill' : '') + '"></i>' +
                        '</button>' +
                        '<button class="btn btn-outline-primary btn-edit" data-note=\'' + JSON.stringify(note).replace(/'/g, "&#39;") + '\' title="Edytuj">' +
                            '<i class="bi bi-pencil"></i>' +
                        '</button>' +
                        '<button class="btn btn-outline-danger btn-delete" data-id="' + note.id + '" title="Usuń">' +
                            '<i class="bi bi-trash"></i>' +
                        '</button>' +
                    '</div>';
                }
                
                return '<div class="note-item ' + (note.is_pinned ? 'pinned' : '') + '" data-id="' + note.id + '">' +
                    '<div class="note-color-bar" style="background: ' + (colors[note.color] || colors.default) + '"></div>' +
                    '<div class="note-header">' +
                        '<div>' +
                            (note.is_pinned ? '<i class="bi bi-pin-fill text-primary me-1"></i>' : '') +
                            (note.title ? '<span class="note-title">' + escapeHtml(note.title) + '</span>' : '<span class="note-title text-muted">Bez tytułu</span>') +
                        '</div>' +
                        actionButtons +
                    '</div>' +
                    '<div class="note-content">' + escapeHtml(note.content || note.note || '') + '</div>' +
                    '<div class="note-meta">' +
                        '<i class="bi bi-person me-1"></i>' + (note.username || 'System') + ' • ' +
                        '<i class="bi bi-clock me-1"></i>' + formatDate(note.updated_at || note.created_at) +
                    '</div>' +
                '</div>';
            }).join('');
            
            // Bind events
            list.querySelectorAll('.btn-pin').forEach(function(btn) {
                btn.addEventListener('click', function() { togglePin(this.dataset.id); });
            });
            list.querySelectorAll('.btn-edit').forEach(function(btn) {
                btn.addEventListener('click', function() { openEditModal(JSON.parse(this.dataset.note)); });
            });
            list.querySelectorAll('.btn-delete').forEach(function(btn) {
                btn.addEventListener('click', function() { deleteNote(this.dataset.id); });
            });
        }
        
        function openEditModal(note) {
            document.getElementById('editNoteId').value = note ? note.id : '';
            document.getElementById('editNoteEntityType').value = currentEntityType;
            document.getElementById('editNoteEntityId').value = currentEntityId;
            document.getElementById('editNoteTitle').value = note ? (note.title || '') : '';
            document.getElementById('editNoteContent').value = note ? (note.content || note.note || '') : '';
            document.getElementById('editNotePinned').checked = note ? note.is_pinned : false;
            
            document.querySelectorAll('#editNoteColors .note-color-btn').forEach(function(b) { b.classList.remove('active'); });
            var colorBtn = document.querySelector('#editNoteColors .note-color-btn[data-color="' + (note ? (note.color || 'default') : 'default') + '"]');
            if (colorBtn) colorBtn.classList.add('active');
            
            document.getElementById('noteEditModalTitle').textContent = note ? 'Edytuj notatkę' : 'Nowa notatka';
            editModal.show();
        }
        
        function saveNote() {
            var noteId = document.getElementById('editNoteId').value;
            var content = document.getElementById('editNoteContent').value.trim();
            
            if (!content) {
                Swal.fire({ icon: 'error', title: 'Błąd', text: 'Treść notatki jest wymagana', background: '#1a1d21', color: '#e1e1e1' });
                return;
            }
            
            var formData = new FormData();
            formData.append('entity_type', document.getElementById('editNoteEntityType').value);
            formData.append('entity_id', document.getElementById('editNoteEntityId').value);
            formData.append('title', document.getElementById('editNoteTitle').value);
            formData.append('content', content);
            formData.append('color', document.querySelector('#editNoteColors .note-color-btn.active').dataset.color);
            formData.append('is_pinned', document.getElementById('editNotePinned').checked ? 1 : 0);
            
            if (noteId) formData.append('id', noteId);
            
            var url = noteId ? baseUrl + '/entity-notes/update' : baseUrl + '/entity-notes/add';
            
            fetch(url, { method: 'POST', body: formData })
                .then(function(r) { return r.json(); })
                .then(function(data) {
                    if (data.success) {
                        editModal.hide();
                        loadNotes();
                        updateBadge();
                    } else {
                        Swal.fire({ icon: 'error', title: 'Błąd', text: data.error || 'Wystąpił błąd', background: '#1a1d21', color: '#e1e1e1' });
                    }
                });
        }
        
        function togglePin(noteId) {
            var formData = new FormData();
            formData.append('id', noteId);
            
            fetch(baseUrl + '/entity-notes/toggle-pin', { method: 'POST', body: formData })
                .then(function(r) { return r.json(); })
                .then(function(data) {
                    if (data.success) loadNotes();
                });
        }
        
        function deleteNote(noteId) {
            Swal.fire({
                title: 'Usunąć notatkę?',
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: 'Usuń',
                cancelButtonText: 'Anuluj',
                confirmButtonColor: '#dc3545',
                background: '#1a1d21',
                color: '#e1e1e1'
            }).then(function(result) {
                if (result.isConfirmed) {
                    var formData = new FormData();
                    formData.append('id', noteId);
                    
                    fetch(baseUrl + '/entity-notes/delete', { method: 'POST', body: formData })
                        .then(function(r) { return r.json(); })
                        .then(function(data) {
                            if (data.success) {
                                loadNotes();
                                updateBadge();
                            }
                        });
                }
            });
        }
        
        function updateBadge() {
            var badge = document.querySelector('.notes-badge[data-entity-type="' + currentEntityType + '"][data-entity-id="' + currentEntityId + '"]');
            if (badge) {
                fetch(baseUrl + '/entity-notes/list?entity_type=' + currentEntityType + '&entity_id=' + currentEntityId)
                    .then(function(r) { return r.json(); })
                    .then(function(data) {
                        if (data.success) {
                            badge.querySelector('.notes-count').textContent = data.count;
                            badge.style.display = data.count > 0 ? 'inline-flex' : 'none';
                        }
                    });
            }
        }
        
        function quickAdd(entityType, entityId, entityName) {
            currentEntityType = entityType;
            currentEntityId = entityId;
            currentEntityName = entityName;
            openEditModal(null);
        }
        
        function escapeHtml(text) {
            if (!text) return '';
            var div = document.createElement('div');
            div.textContent = text;
            return div.innerHTML;
        }
        
        function formatDate(dateStr) {
            if (!dateStr) return '';
            var date = new Date(dateStr);
            return date.toLocaleDateString('pl-PL') + ' ' + date.toLocaleTimeString('pl-PL', {hour: '2-digit', minute: '2-digit'});
        }
        
        return {
            init: init,
            open: openNotesModal,
            quickAdd: quickAdd
        };
    })();
    
    
    document.addEventListener('DOMContentLoaded', function() {
        NotesManager.init('<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
', <?php echo (($tmp = $_smarty_tpl->tpl_vars['currentUser']->value['id'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
, <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>true<?php } else { ?>false<?php }?>);
    });
    <?php echo '</script'; ?>
>
    
    <?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_133486551869750445c77f55_93210562', "scripts");
?>

</body>
</html>
<?php }
/* {block "styles"} */
class Block_130277206169750445c648d8_16951131 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'styles' => 
  array (
    0 => 'Block_130277206169750445c648d8_16951131',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
}
}
/* {/block "styles"} */
/* {block "content"} */
class Block_59866808769750445c75974_86673639 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_59866808769750445c75974_86673639',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
}
}
/* {/block "content"} */
/* {block "content"} */
class Block_174913712369750445c76387_77281302 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_174913712369750445c76387_77281302',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_133486551869750445c77f55_93210562 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_133486551869750445c77f55_93210562',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
}
}
/* {/block "scripts"} */
}
