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

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_6975044ebff364_87648895',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '85e756c347404d06b7a63bba43999828709d6fc3' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/settings/values.tpl',
      1 => 1769276438,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_6975044ebff364_87648895 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, true);
?>


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


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

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

<div class="container-fluid">
    <!-- Header -->
    <div class="d-flex flex-wrap justify-content-between align-items-center mb-4">
        <div>
            <h4 class="mb-1"><?php echo $_smarty_tpl->tpl_vars['pageTitle']->value;?>
</h4>
            <p class="text-muted mb-0">
                <?php if ($_smarty_tpl->tpl_vars['timestamp']->value) {?>
                Ostatnia modyfikacja: <?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['timestamp']->value,"%d.%m.%Y %H:%M:%S");?>

                <?php } else { ?>
                Brak zapisanych ustawień - używane są wartości domyślne
                <?php }?>
            </p>
        </div>
        <div class="d-flex gap-2">
            <?php if ($_smarty_tpl->tpl_vars['scope']->value == 'device' && (isset($_smarty_tpl->tpl_vars['device']->value))) {?>
            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices/edit?id=<?php echo $_smarty_tpl->tpl_vars['device']->value['id'];?>
" class="btn btn-outline-secondary">
                <i class="bi bi-arrow-left me-1"></i>Powrót do urządzenia
            </a>
            <?php } elseif ($_smarty_tpl->tpl_vars['scope']->value == 'user' && (isset($_smarty_tpl->tpl_vars['user']->value))) {?>
            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users/edit?id=<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
" class="btn btn-outline-secondary">
                <i class="bi bi-arrow-left me-1"></i>Powrót do użytkownika
            </a>
            <?php } elseif ($_smarty_tpl->tpl_vars['scope']->value == 'reseller' && (isset($_smarty_tpl->tpl_vars['reseller']->value))) {?>
            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/users/edit?id=<?php echo $_smarty_tpl->tpl_vars['reseller']->value['id'];?>
" class="btn btn-outline-secondary">
                <i class="bi bi-arrow-left me-1"></i>Powrót do resellera
            </a>
            <?php }?>
        </div>
    </div>

    <form method="post">
        <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
        <input type="hidden" name="action" value="save" id="formAction">

        <div class="row">
            <!-- Sidebar z akcjami -->
            <div class="col-lg-3">
                <!-- Presety -->
                <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['presets']->value) > 0) {?>
                <div class="card mb-4">
                    <div class="card-header">
                        <h6 class="mb-0"><i class="bi bi-collection me-2"></i>Zastosuj preset</h6>
                    </div>
                    <div class="card-body">
                        <select class="form-select mb-2" id="presetSelect">
                            <option value="">Wybierz preset...</option>
                            <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['presets']->value, 'preset');
$_smarty_tpl->tpl_vars['preset']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['preset']->value) {
$_smarty_tpl->tpl_vars['preset']->do_else = false;
?>
                            <option value="<?php echo $_smarty_tpl->tpl_vars['preset']->value['id'];?>
"><?php echo $_smarty_tpl->tpl_vars['preset']->value['name'];?>
 (<?php echo $_smarty_tpl->tpl_vars['preset']->value['items_count'];?>
 ustawień)</option>
                            <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                        </select>
                        <button type="button" class="btn btn-outline-primary w-100" id="applyPresetBtn" disabled>
                            <i class="bi bi-lightning me-1"></i>Zastosuj
                        </button>
                    </div>
                </div>
                <?php }?>

                <!-- Akcje -->
                <div class="card mb-4">
                    <div class="card-header">
                        <h6 class="mb-0"><i class="bi bi-gear me-2"></i>Akcje</h6>
                    </div>
                    <div class="card-body d-grid gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-check-lg me-1"></i>Zapisz ustawienia
                        </button>
                        <button type="button" class="btn btn-outline-warning" id="resetBtn">
                            <i class="bi bi-arrow-counterclockwise me-1"></i>Resetuj do domyślnych
                        </button>
                    </div>
                </div>

                <!-- Info -->
                <div class="card bg-dark">
                    <div class="card-body">
                        <h6><i class="bi bi-info-circle me-2"></i>Informacje</h6>
                        <small class="text-muted">
                            <?php if ((($tmp = $_smarty_tpl->tpl_vars['isMySettings']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>
                            Ustawienia które tu zmienisz będą stosowane do <strong>wszystkich Twoich urządzeń</strong>, chyba że urządzenie ma własne ustawienia.
                            <?php } else { ?>
                            Ustawienia na poziomie <strong><?php echo $_smarty_tpl->tpl_vars['scopeLabel']->value;?>
</strong> nadpisują ustawienia z wyższych poziomów.
                            <?php }?>
                            <br><br>
                            <span class="badge bg-success">●</span> - wartość ustawiona<br>
                            <span class="badge bg-secondary">●</span> - wartość domyślna/dziedziczona
                        </small>
                    </div>
                </div>
            </div>

            <!-- Ustawienia -->
            <div class="col-lg-9">
                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['grouped']->value, 'groupDefs', false, 'groupName');
$_smarty_tpl->tpl_vars['groupDefs']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['groupName']->value => $_smarty_tpl->tpl_vars['groupDefs']->value) {
$_smarty_tpl->tpl_vars['groupDefs']->do_else = false;
?>
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0">
                            <i class="bi bi-folder me-2"></i>
                            <?php echo (($tmp = $_smarty_tpl->tpl_vars['groupLabels']->value[$_smarty_tpl->tpl_vars['groupName']->value] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['groupName']->value ?? null : $tmp);?>

                            <span class="badge bg-secondary ms-2"><?php echo count($_smarty_tpl->tpl_vars['groupDefs']->value);?>
</span>
                        </h5>
                    </div>
                    <div class="card-body">
                        <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['groupDefs']->value, 'def');
$_smarty_tpl->tpl_vars['def']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['def']->value) {
$_smarty_tpl->tpl_vars['def']->do_else = false;
?>
                        <div class="row mb-3 pb-3 border-bottom align-items-center">
                            <div class="col-md-5">
                                <div class="d-flex align-items-center">
                                    <?php if ($_smarty_tpl->tpl_vars['def']->value['has_value']) {?>
                                    <span class="badge bg-success me-2" title="Wartość ustawiona">●</span>
                                    <?php } else { ?>
                                    <span class="badge bg-secondary me-2" title="Wartość domyślna">●</span>
                                    <?php }?>
                                    <div>
                                        <strong><?php echo $_smarty_tpl->tpl_vars['def']->value['label'];?>
</strong>
                                        <br><small class="text-muted"><code><?php echo $_smarty_tpl->tpl_vars['def']->value['key'];?>
</code></small>
                                        <?php if ($_smarty_tpl->tpl_vars['def']->value['description']) {?>
                                        <br><small class="text-muted"><?php echo $_smarty_tpl->tpl_vars['def']->value['description'];?>
</small>
                                        <?php }?>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-5">
                                <?php if ($_smarty_tpl->tpl_vars['def']->value['type'] == 'boolean') {?>
                                <div class="form-check form-switch">
                                    <input type="hidden" name="values[<?php echo $_smarty_tpl->tpl_vars['def']->value['id'];?>
]" value="false">
                                    <input type="checkbox" name="values[<?php echo $_smarty_tpl->tpl_vars['def']->value['id'];?>
]" class="form-check-input" 
                                           id="setting_<?php echo $_smarty_tpl->tpl_vars['def']->value['id'];?>
" value="true"
                                           <?php if (((($tmp = $_smarty_tpl->tpl_vars['def']->value['current_value'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['def']->value['default_value'] ?? null : $tmp)) == 'true' || ((($tmp = $_smarty_tpl->tpl_vars['def']->value['current_value'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['def']->value['default_value'] ?? null : $tmp)) === true) {?>checked<?php }?>>
                                    <label class="form-check-label" for="setting_<?php echo $_smarty_tpl->tpl_vars['def']->value['id'];?>
">
                                        <?php if (((($tmp = $_smarty_tpl->tpl_vars['def']->value['current_value'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['def']->value['default_value'] ?? null : $tmp)) == 'true' || ((($tmp = $_smarty_tpl->tpl_vars['def']->value['current_value'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['def']->value['default_value'] ?? null : $tmp)) === true) {?>Włączone<?php } else { ?>Wyłączone<?php }?>
                                    </label>
                                </div>
                                <?php } elseif ($_smarty_tpl->tpl_vars['def']->value['options']) {?>
                                <select name="values[<?php echo $_smarty_tpl->tpl_vars['def']->value['id'];?>
]" class="form-select">
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['def']->value['options'], 'opt');
$_smarty_tpl->tpl_vars['opt']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['opt']->value) {
$_smarty_tpl->tpl_vars['opt']->do_else = false;
?>
                                    <option value="<?php echo $_smarty_tpl->tpl_vars['opt']->value['value'];?>
" <?php if (((($tmp = $_smarty_tpl->tpl_vars['def']->value['current_value'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['def']->value['default_value'] ?? null : $tmp)) == $_smarty_tpl->tpl_vars['opt']->value['value']) {?>selected<?php }?>>
                                        <?php echo $_smarty_tpl->tpl_vars['opt']->value['label'];?>

                                    </option>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                </select>
                                <?php } elseif ($_smarty_tpl->tpl_vars['def']->value['type'] == 'string') {?>
                                <input type="text" name="values[<?php echo $_smarty_tpl->tpl_vars['def']->value['id'];?>
]" class="form-control"
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['def']->value['current_value'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['def']->value['default_value'] ?? null : $tmp);?>
">
                                <?php } else { ?>
                                <input type="number" name="values[<?php echo $_smarty_tpl->tpl_vars['def']->value['id'];?>
]" class="form-control"
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['def']->value['current_value'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['def']->value['default_value'] ?? null : $tmp);?>
">
                                <?php }?>
                            </div>
                            <div class="col-md-2 text-end">
                                <small class="text-muted">
                                    <span class="badge bg-<?php if ($_smarty_tpl->tpl_vars['def']->value['type'] == 'boolean') {?>info<?php } elseif ($_smarty_tpl->tpl_vars['def']->value['type'] == 'int') {?>primary<?php } elseif ($_smarty_tpl->tpl_vars['def']->value['type'] == 'long') {?>warning<?php } else { ?>secondary<?php }?>">
                                        <?php echo $_smarty_tpl->tpl_vars['def']->value['type'];?>

                                    </span>
                                </small>
                            </div>
                        </div>
                        <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                    </div>
                </div>
                <?php
}
if ($_smarty_tpl->tpl_vars['groupDefs']->do_else) {
?>
                <div class="alert alert-info">
                    <i class="bi bi-info-circle me-2"></i>
                    Brak dostępnych ustawień dla tego poziomu.
                </div>
                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
            </div>
        </div>
    </form>
</div>

<!-- Hidden form for preset -->
<form id="presetForm" method="post" style="display:none;">
    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
    <input type="hidden" name="action" value="apply_preset">
    <input type="hidden" name="preset_id" id="presetIdInput">
</form>

<!-- Hidden form for reset -->
<form id="resetForm" method="post" style="display:none;">
    <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
    <input type="hidden" name="action" value="reset">
</form>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_19543430756975044ebfec37_39817062 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_19543430756975044ebfec37_39817062',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>


<?php echo '<script'; ?>
>
// Preset
var presetSelect = document.getElementById('presetSelect');
var applyPresetBtn = document.getElementById('applyPresetBtn');

if (presetSelect) {
    presetSelect.addEventListener('change', function() {
        applyPresetBtn.disabled = !this.value;
    });

    applyPresetBtn.addEventListener('click', function() {
        var presetId = presetSelect.value;
        if (!presetId) return;

        Swal.fire({
            title: 'Zastosować preset?',
            text: 'Obecne ustawienia zostaną nadpisane wartościami z presetu.',
            icon: 'question',
            showCancelButton: true,
            confirmButtonText: 'Zastosuj',
            cancelButtonText: 'Anuluj',
            background: '#1a1d21',
            color: '#e1e1e1'
        }).then(function(result) {
            if (result.isConfirmed) {
                document.getElementById('presetIdInput').value = presetId;
                document.getElementById('presetForm').submit();
            }
        });
    });
}

// Reset
document.getElementById('resetBtn').addEventListener('click', function() {
    Swal.fire({
        title: 'Resetować ustawienia?',
        text: 'Wszystkie ustawienia na tym poziomie zostaną usunięte. Będą używane wartości z wyższych poziomów lub domyślne.',
        icon: 'warning',
        showCancelButton: true,
        confirmButtonText: 'Resetuj',
        cancelButtonText: 'Anuluj',
        confirmButtonColor: '#ffc107',
        background: '#1a1d21',
        color: '#e1e1e1'
    }).then(function(result) {
        if (result.isConfirmed) {
            document.getElementById('resetForm').submit();
        }
    });
});

// Update labels for switches
document.querySelectorAll('.form-check-input[type="checkbox"]').forEach(function(checkbox) {
    checkbox.addEventListener('change', function() {
        var label = this.nextElementSibling;
        if (label) {
            label.textContent = this.checked ? 'Włączone' : 'Wyłączone';
        }
    });
});
<?php echo '</script'; ?>
>

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