<?php
/* Smarty version 4.5.6, created on 2025-12-12 20:44:33
  from '/var/www/html/tivi/panel/templates/notes/index.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_693c70a1d83456_88782649',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '1d8cc595fe32287b897de1adbe26d164578af43c' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/notes/index.tpl',
      1 => 1765568568,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_693c70a1d83456_88782649 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, true);
?>


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


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


<?php 
$_smarty_tpl->inheritance->instanceBlock($_smarty_tpl, 'Block_925246138693c70a1d82dc8_51106156', "styles");
?>

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_14012542693c70a1d7cc28_16904169 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_14012542693c70a1d7cc28_16904169',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<div class="container-fluid">
    <div class="row">
        <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
        <!-- Sidebar z listą użytkowników -->
        <div class="col-lg-3 mb-4">
            <div class="card">
                <div class="card-header">
                    <h6 class="mb-0"><i class="bi bi-people me-2"></i>Użytkownicy</h6>
                </div>
                <div class="card-body p-0">
                    <div class="list-group list-group-flush notes-user-list">
                        <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/notes" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center<?php if (!$_smarty_tpl->tpl_vars['viewUserId']->value) {?> active<?php }?>">
                            <span><i class="bi bi-person-fill me-2"></i>Moje notatki</span>
                        </a>
                        <?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;
?>
                        <?php if ($_smarty_tpl->tpl_vars['user']->value['id'] != $_smarty_tpl->tpl_vars['currentUser']->value['id']) {?>
                        <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/notes?user_id=<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center<?php if ($_smarty_tpl->tpl_vars['viewUserId']->value == $_smarty_tpl->tpl_vars['user']->value['id']) {?> active<?php }?>">
                            <span>
                                <i class="bi bi-person me-2"></i><?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>

                                <?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'admin') {?><span class="badge bg-warning text-dark ms-1">Admin</span><?php }?>
                            </span>
                        </a>
                        <?php }?>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- Główna zawartość -->
        <div class="col-lg-9">
        <?php } else { ?>
        <div class="col-12">
        <?php }?>
            <!-- Header -->
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div>
                    <h4 class="mb-1">
                        <?php if ($_smarty_tpl->tpl_vars['viewUser']->value) {?>
                        <i class="bi bi-journal-text me-2"></i>Notatki: <?php echo $_smarty_tpl->tpl_vars['viewUser']->value['username'];?>

                        <?php } else { ?>
                        <i class="bi bi-journal-text me-2"></i>Moje notatki
                        <?php }?>
                    </h4>
                    <p class="text-muted mb-0">Przechowuj swoje notatki i informacje</p>
                </div>
                <div id="saveStatus" class="text-muted small" style="display:none;">
                    <i class="bi bi-check-circle text-success me-1"></i>Zapisano
                </div>
            </div>

            <!-- Notes Card -->
            <div class="card">
                <div class="card-body">
                    <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/notes/save" id="notesForm">
                        <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                        <?php if ($_smarty_tpl->tpl_vars['viewUserId']->value) {?>
                        <input type="hidden" name="user_id" value="<?php echo $_smarty_tpl->tpl_vars['viewUserId']->value;?>
">
                        <?php }?>
                        
                        <div class="mb-3">
                            <textarea name="content" 
                                      id="notesContent" 
                                      class="form-control notes-textarea" 
                                      rows="20" 
                                      placeholder="Wpisz swoje notatki tutaj..."><?php echo $_smarty_tpl->tpl_vars['notes']->value;?>
</textarea>
                        </div>

                        <div class="d-flex justify-content-between align-items-center">
                            <small class="text-muted">
                                <i class="bi bi-info-circle me-1"></i>
                                Notatki zapisują się automatycznie po 2 sekundach od ostatniej zmiany
                            </small>
                            <button type="submit" class="btn btn-primary" id="saveBtn">
                                <i class="bi bi-check-lg me-1"></i>Zapisz
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_1906222485693c70a1d81ee7_56107225 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_1906222485693c70a1d81ee7_56107225',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>
(function() {
    const form = document.getElementById('notesForm');
    const textarea = document.getElementById('notesContent');
    const saveBtn = document.getElementById('saveBtn');
    const saveStatus = document.getElementById('saveStatus');
    let saveTimeout = null;
    let isSaving = false;
    let lastSavedContent = textarea.value;

    // Autosave po 2 sekundach od ostatniej zmiany
    textarea.addEventListener('input', function() {
        if (saveTimeout) {
            clearTimeout(saveTimeout);
        }
        
        saveStatus.style.display = 'none';
        
        saveTimeout = setTimeout(function() {
            if (textarea.value !== lastSavedContent) {
                autoSave();
            }
        }, 2000);
    });

    // Zapisz przy opuszczaniu strony
    window.addEventListener('beforeunload', function(e) {
        if (textarea.value !== lastSavedContent && !isSaving) {
            e.preventDefault();
            e.returnValue = '';
        }
    });

    // Funkcja autosave
    async function autoSave() {
        if (isSaving) return;
        
        isSaving = true;
        saveBtn.disabled = true;
        saveBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span>Zapisuję...';
        
        try {
            const formData = new FormData(form);
            const response = await fetch(form.action, {
                method: 'POST',
                body: formData,
                headers: {
                    'X-Requested-With': 'XMLHttpRequest'
                }
            });
            
            const result = await response.json();
            
            if (result.success) {
                lastSavedContent = textarea.value;
                saveStatus.style.display = 'block';
                setTimeout(function() {
                    saveStatus.style.display = 'none';
                }, 3000);
            }
        } catch (error) {
            console.error('Błąd zapisu:', error);
        } finally {
            isSaving = false;
            saveBtn.disabled = false;
            saveBtn.innerHTML = '<i class="bi bi-check-lg me-1"></i>Zapisz';
        }
    }

    // Obsługa formularza
    form.addEventListener('submit', function(e) {
        if (textarea.value === lastSavedContent) {
            e.preventDefault();
            saveStatus.style.display = 'block';
            return;
        }
        
        // Pozwól na normalny submit jeśli coś się zmieniło
    });
})();
<?php echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
/* {block "styles"} */
class Block_925246138693c70a1d82dc8_51106156 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'styles' => 
  array (
    0 => 'Block_925246138693c70a1d82dc8_51106156',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<style>
.notes-textarea {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    resize: vertical;
    min-height: 400px;
}

.notes-user-list {
    max-height: 500px;
    overflow-y: auto;
}

.notes-user-list .list-group-item {
    background: transparent;
    border-color: var(--sidebar-border);
    color: var(--text-primary);
    padding: 0.6rem 1rem;
}

.notes-user-list .list-group-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.notes-user-list .list-group-item.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}
</style>
<?php
}
}
/* {/block "styles"} */
}
