<?php
/* Smarty version 4.5.6, created on 2026-01-03 21:22:55
  from '/var/www/html/tivi/panel/templates/admin/links.tpl' */

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


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


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

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_157376899369597a9f795376_19157843 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_157376899369597a9f795376_19157843',
  ),
);
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.count.php','function'=>'smarty_modifier_count',),1=>array('file'=>'/var/www/html/tivi/vendor/smarty/smarty/libs/plugins/modifier.truncate.php','function'=>'smarty_modifier_truncate',),));
?>

<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1">Linki zewnętrzne</h4>
            <p class="text-muted mb-0">Zarządzaj linkami wyświetlanymi w menu bocznym</p>
        </div>
        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addLinkModal">
            <i class="bi bi-plus-lg me-1"></i>Dodaj link
        </button>
    </div>

    <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['links']->value) > 0) {?>
    <div class="card">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0" id="linksTable">
                    <thead>
                        <tr>
                            <th style="width: 40px;"></th>
                            <th style="width: 50px;">Ikona</th>
                            <th>Nazwa</th>
                            <th>URL</th>
                            <th style="width: 80px;">Kolejność</th>
                            <th style="width: 100px;">Status</th>
                            <th style="width: 120px;">Akcje</th>
                        </tr>
                    </thead>
                    <tbody id="linksSortable">
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['links']->value, 'link');
$_smarty_tpl->tpl_vars['link']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['link']->value) {
$_smarty_tpl->tpl_vars['link']->do_else = false;
?>
                        <tr data-id="<?php echo $_smarty_tpl->tpl_vars['link']->value['id'];?>
">
                            <td class="drag-handle" style="cursor: grab;">
                                <i class="bi bi-grip-vertical text-muted"></i>
                            </td>
                            <td>
                                <i class="bi <?php echo $_smarty_tpl->tpl_vars['link']->value['icon'];?>
 fs-5"></i>
                            </td>
                            <td>
                                <strong><?php echo $_smarty_tpl->tpl_vars['link']->value['name'];?>
</strong>
                                <?php if ($_smarty_tpl->tpl_vars['link']->value['open_new_tab']) {?>
                                <i class="bi bi-box-arrow-up-right text-muted small ms-1" title="Otwiera w nowej karcie"></i>
                                <?php }?>
                            </td>
                            <td>
                                <a href="<?php echo $_smarty_tpl->tpl_vars['link']->value['url'];?>
" target="_blank" class="text-decoration-none">
                                    <?php echo smarty_modifier_truncate($_smarty_tpl->tpl_vars['link']->value['url'],50);?>

                                    <i class="bi bi-box-arrow-up-right small"></i>
                                </a>
                            </td>
                            <td class="text-center">
                                <span class="badge bg-secondary"><?php echo $_smarty_tpl->tpl_vars['link']->value['sort_order'];?>
</span>
                            </td>
                            <td>
                                <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/links/toggle-active" class="d-inline toggle-form">
                                    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                                    <input type="hidden" name="id" value="<?php echo $_smarty_tpl->tpl_vars['link']->value['id'];?>
">
                                    <button type="submit" class="btn btn-sm <?php if ($_smarty_tpl->tpl_vars['link']->value['is_active']) {?>btn-success<?php } else { ?>btn-secondary<?php }?>">
                                        <?php if ($_smarty_tpl->tpl_vars['link']->value['is_active']) {?>
                                        <i class="bi bi-check-circle me-1"></i>Aktywny
                                        <?php } else { ?>
                                        <i class="bi bi-x-circle me-1"></i>Nieaktywny
                                        <?php }?>
                                    </button>
                                </form>
                            </td>
                            <td>
                                <button type="button" class="btn btn-sm btn-outline-primary edit-link-btn"
                                        data-id="<?php echo $_smarty_tpl->tpl_vars['link']->value['id'];?>
"
                                        data-name="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['link']->value['name'], ENT_QUOTES, 'UTF-8', true);?>
"
                                        data-url="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['link']->value['url'], ENT_QUOTES, 'UTF-8', true);?>
"
                                        data-icon="<?php echo $_smarty_tpl->tpl_vars['link']->value['icon'];?>
"
                                        data-sort-order="<?php echo $_smarty_tpl->tpl_vars['link']->value['sort_order'];?>
"
                                        data-is-active="<?php echo $_smarty_tpl->tpl_vars['link']->value['is_active'];?>
"
                                        data-open-new-tab="<?php echo $_smarty_tpl->tpl_vars['link']->value['open_new_tab'];?>
"
                                        title="Edytuj">
                                    <i class="bi bi-pencil"></i>
                                </button>
                                <button type="button" class="btn btn-sm btn-outline-danger delete-link-btn"
                                        data-id="<?php echo $_smarty_tpl->tpl_vars['link']->value['id'];?>
"
                                        data-name="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['link']->value['name'], ENT_QUOTES, 'UTF-8', true);?>
"
                                        title="Usuń">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </td>
                        </tr>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    
    <div class="alert alert-info mt-3">
        <i class="bi bi-info-circle me-2"></i>
        <strong>Wskazówka:</strong> Przeciągnij wiersze aby zmienić kolejność linków w menu.
    </div>
    <?php } else { ?>
    <div class="card">
        <div class="card-body text-center py-5">
            <i class="bi bi-link-45deg display-1 text-muted"></i>
            <h5 class="mt-3">Brak linków zewnętrznych</h5>
            <p class="text-muted">Dodaj pierwszy link, który pojawi się w menu bocznym.</p>
            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addLinkModal">
                <i class="bi bi-plus-lg me-1"></i>Dodaj link
            </button>
        </div>
    </div>
    <?php }?>
    
    <!-- Podgląd w menu -->
    <div class="card mt-4">
        <div class="card-header">
            <h6 class="mb-0"><i class="bi bi-eye me-2"></i>Podgląd w menu</h6>
        </div>
        <div class="card-body">
            <div class="bg-dark rounded p-3" style="max-width: 260px;">
                <div class="text-muted small mb-2">LINKI</div>
                <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['links']->value) > 0) {?>
                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['links']->value, 'link');
$_smarty_tpl->tpl_vars['link']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['link']->value) {
$_smarty_tpl->tpl_vars['link']->do_else = false;
?>
                        <?php if ($_smarty_tpl->tpl_vars['link']->value['is_active']) {?>
                        <a href="#" class="d-flex align-items-center text-white text-decoration-none py-2 px-2 rounded hover-bg-secondary">
                            <i class="bi <?php echo $_smarty_tpl->tpl_vars['link']->value['icon'];?>
 me-2"></i>
                            <span><?php echo $_smarty_tpl->tpl_vars['link']->value['name'];?>
</span>
                            <?php if ($_smarty_tpl->tpl_vars['link']->value['open_new_tab']) {?>
                            <i class="bi bi-box-arrow-up-right ms-auto small opacity-50"></i>
                            <?php }?>
                        </a>
                        <?php }?>
                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                <?php } else { ?>
                    <div class="text-muted small fst-italic">Brak aktywnych linków</div>
                <?php }?>
            </div>
        </div>
    </div>
</div>

<!-- Modal: Dodaj link -->
<div class="modal fade" id="addLinkModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/links/add" id="addLinkForm">
                <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                <div class="modal-header">
                    <h5 class="modal-title"><i class="bi bi-plus-lg me-2"></i>Dodaj link</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">Nazwa <span class="text-danger">*</span></label>
                        <input type="text" name="name" class="form-control" required maxlength="100" placeholder="np. Panel Xtream">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">URL <span class="text-danger">*</span></label>
                        <input type="url" name="url" class="form-control" required maxlength="500" placeholder="https://example.com">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Ikona</label>
                        <select name="icon" class="form-select icon-select">
                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['icons']->value, 'iconName', false, 'iconClass');
$_smarty_tpl->tpl_vars['iconName']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['iconClass']->value => $_smarty_tpl->tpl_vars['iconName']->value) {
$_smarty_tpl->tpl_vars['iconName']->do_else = false;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['iconClass']->value;?>
" data-icon="<?php echo $_smarty_tpl->tpl_vars['iconClass']->value;?>
"><?php echo $_smarty_tpl->tpl_vars['iconName']->value;?>
</option>
                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                        </select>
                        <div class="mt-2">
                            <span class="icon-preview"><i class="bi bi-link-45deg fs-4"></i></span>
                            <span class="text-muted small ms-2">Podgląd ikony</span>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Kolejność</label>
                        <input type="number" name="sort_order" class="form-control" value="0" min="0" max="999">
                        <small class="text-muted">Mniejsza liczba = wyżej w menu</small>
                    </div>
                    <div class="mb-3">
                        <div class="form-check form-switch">
                            <input type="checkbox" name="is_active" id="addIsActive" class="form-check-input" value="1" checked>
                            <label class="form-check-label" for="addIsActive">Aktywny</label>
                        </div>
                    </div>
                    <div class="mb-3">
                        <div class="form-check form-switch">
                            <input type="checkbox" name="open_new_tab" id="addOpenNewTab" class="form-check-input" value="1" checked>
                            <label class="form-check-label" for="addOpenNewTab">Otwórz w nowej karcie</label>
                        </div>
                    </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">
                        <i class="bi bi-plus-lg me-1"></i>Dodaj
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Modal: Edytuj link -->
<div class="modal fade" id="editLinkModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/links/edit" id="editLinkForm">
                <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                <input type="hidden" name="id" id="editLinkId">
                <div class="modal-header">
                    <h5 class="modal-title"><i class="bi bi-pencil me-2"></i>Edytuj link</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">Nazwa <span class="text-danger">*</span></label>
                        <input type="text" name="name" id="editLinkName" class="form-control" required maxlength="100">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">URL <span class="text-danger">*</span></label>
                        <input type="url" name="url" id="editLinkUrl" class="form-control" required maxlength="500">
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Ikona</label>
                        <select name="icon" id="editLinkIcon" class="form-select icon-select">
                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['icons']->value, 'iconName', false, 'iconClass');
$_smarty_tpl->tpl_vars['iconName']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['iconClass']->value => $_smarty_tpl->tpl_vars['iconName']->value) {
$_smarty_tpl->tpl_vars['iconName']->do_else = false;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['iconClass']->value;?>
" data-icon="<?php echo $_smarty_tpl->tpl_vars['iconClass']->value;?>
"><?php echo $_smarty_tpl->tpl_vars['iconName']->value;?>
</option>
                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                        </select>
                        <div class="mt-2">
                            <span class="icon-preview"><i class="bi bi-link-45deg fs-4"></i></span>
                            <span class="text-muted small ms-2">Podgląd ikony</span>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Kolejność</label>
                        <input type="number" name="sort_order" id="editLinkSortOrder" class="form-control" value="0" min="0" max="999">
                    </div>
                    <div class="mb-3">
                        <div class="form-check form-switch">
                            <input type="checkbox" name="is_active" id="editIsActive" class="form-check-input" value="1">
                            <label class="form-check-label" for="editIsActive">Aktywny</label>
                        </div>
                    </div>
                    <div class="mb-3">
                        <div class="form-check form-switch">
                            <input type="checkbox" name="open_new_tab" id="editOpenNewTab" class="form-check-input" value="1">
                            <label class="form-check-label" for="editOpenNewTab">Otwórz w nowej karcie</label>
                        </div>
                    </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">
                        <i class="bi bi-check-lg me-1"></i>Zapisz
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Modal: Potwierdzenie usunięcia -->
<div class="modal fade" id="deleteLinkModal" tabindex="-1">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/links/delete" id="deleteLinkForm">
                <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                <input type="hidden" name="id" id="deleteLinkId">
                <div class="modal-header">
                    <h5 class="modal-title text-danger"><i class="bi bi-exclamation-triangle me-2"></i>Usuń link</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <p>Czy na pewno chcesz usunąć link:</p>
                    <p class="fw-bold" id="deleteLinkName"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Anuluj</button>
                    <button type="submit" class="btn btn-danger">
                        <i class="bi bi-trash me-1"></i>Usuń
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_39525559869597a9f7a1dd1_62247463 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_39525559869597a9f7a1dd1_62247463',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<!-- Sortable.js -->
<?php echo '<script'; ?>
 src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"><?php echo '</script'; ?>
>
<?php echo '<script'; ?>
>
document.addEventListener('DOMContentLoaded', function() {
    // Drag & Drop sortowanie
    var sortable = document.getElementById('linksSortable');
    if (sortable) {
        new Sortable(sortable, {
            handle: '.drag-handle',
            animation: 150,
            onEnd: function(evt) {
                var order = [];
                sortable.querySelectorAll('tr').forEach(function(row) {
                    order.push(row.dataset.id);
                });
                
                // Zapisz kolejność
                fetch('<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/admin/links/update-order', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'X-Requested-With': 'XMLHttpRequest',
                        'X-CSRF-TOKEN': '<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
'
                    },
                    body: 'csrf_token=<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
&order=' + encodeURIComponent(JSON.stringify(order))
                })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        // Aktualizuj numery kolejności w tabeli
                        sortable.querySelectorAll('tr').forEach(function(row, index) {
                            row.querySelector('.badge').textContent = index;
                        });
                    }
                });
            }
        });
    }
    
    // Podgląd ikony
    document.querySelectorAll('.icon-select').forEach(function(select) {
        select.addEventListener('change', function() {
            var preview = this.closest('.mb-3').querySelector('.icon-preview i');
            if (preview) {
                preview.className = 'bi ' + this.value + ' fs-4';
            }
        });
    });
    
    // Edycja linku
    document.querySelectorAll('.edit-link-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            document.getElementById('editLinkId').value = this.dataset.id;
            document.getElementById('editLinkName').value = this.dataset.name;
            document.getElementById('editLinkUrl').value = this.dataset.url;
            document.getElementById('editLinkIcon').value = this.dataset.icon;
            document.getElementById('editLinkSortOrder').value = this.dataset.sortOrder;
            document.getElementById('editIsActive').checked = this.dataset.isActive === '1';
            document.getElementById('editOpenNewTab').checked = this.dataset.openNewTab === '1';
            
            // Aktualizuj podgląd ikony
            var preview = document.querySelector('#editLinkModal .icon-preview i');
            if (preview) {
                preview.className = 'bi ' + this.dataset.icon + ' fs-4';
            }
            
            new bootstrap.Modal(document.getElementById('editLinkModal')).show();
        });
    });
    
    // Usuwanie linku
    document.querySelectorAll('.delete-link-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            document.getElementById('deleteLinkId').value = this.dataset.id;
            document.getElementById('deleteLinkName').textContent = this.dataset.name;
            
            new bootstrap.Modal(document.getElementById('deleteLinkModal')).show();
        });
    });
    
    // Toggle AJAX
    document.querySelectorAll('.toggle-form').forEach(function(form) {
        form.addEventListener('submit', function(e) {
            e.preventDefault();
            
            var btn = this.querySelector('button');
            var formData = new FormData(this);
            
            fetch(this.action, {
                method: 'POST',
                headers: {
                    'X-Requested-With': 'XMLHttpRequest'
                },
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    if (data.is_active) {
                        btn.className = 'btn btn-sm btn-success';
                        btn.innerHTML = '<i class="bi bi-check-circle me-1"></i>Aktywny';
                    } else {
                        btn.className = 'btn btn-sm btn-secondary';
                        btn.innerHTML = '<i class="bi bi-x-circle me-1"></i>Nieaktywny';
                    }
                }
            });
        });
    });
});
<?php echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
}
