<?php
/* Smarty version 4.5.6, created on 2026-01-24 18:42:02
  from '/var/www/html/tivi/panel/templates/devices/form.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.6',
  'unifunc' => 'content_6975046a2cb6c0_12324003',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '0a9378d125b9a6e73410dea8d5fa06330fb50bac' => 
    array (
      0 => '/var/www/html/tivi/panel/templates/devices/form.tpl',
      1 => 1769259983,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
    'file:partials/entity_notes.tpl' => 1,
  ),
),false)) {
function content_6975046a2cb6c0_12324003 (Smarty_Internal_Template $_smarty_tpl) {
$_smarty_tpl->_loadInheritance();
$_smarty_tpl->inheritance->init($_smarty_tpl, true);
?>


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


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

<?php $_smarty_tpl->inheritance->endChild($_smarty_tpl, "layout.tpl");
}
/* {block "content"} */
class Block_16579872346975046a2ba0a5_32997239 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_16579872346975046a2ba0a5_32997239',
  ),
);
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',),));
?>

<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-lg-6">
            <!-- Header -->
            <div class="d-flex align-items-center mb-4">
                <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices" class="btn btn-outline-secondary me-3">
                    <i class="bi bi-arrow-left"></i>
                </a>
                <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['isEdit']->value) {?>Edytuj dane urządzenia<?php } else { ?>Dodaj nowe urządzenie<?php }?>
                    </p>
                </div>
            </div>

            <!-- Form Card -->
            <div class="card">
                <div class="card-body">
                    <?php if ((($tmp = $_smarty_tpl->tpl_vars['error']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>
                    <div class="alert alert-danger">
                        <i class="bi bi-exclamation-circle me-2"></i><?php echo $_smarty_tpl->tpl_vars['error']->value;?>

                    </div>
                    <?php }?>

                    <form method="post">
                        <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                        
                        <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value && !$_smarty_tpl->tpl_vars['isEdit']->value) {?>
                        <div class="mb-3">
                            <label class="form-label">Użytkownik <span class="text-danger">*</span></label>
                            <select name="user_id" class="form-select" required>
                                <option value="">Wybierz użytkownika...</option>
                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['users']->value, 'user');
$_smarty_tpl->tpl_vars['user']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['user']->value) {
$_smarty_tpl->tpl_vars['user']->do_else = false;
?>
                                <option value="<?php echo $_smarty_tpl->tpl_vars['user']->value['id'];?>
" <?php if (((($tmp = $_smarty_tpl->tpl_vars['data']->value['user_id'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp)) == $_smarty_tpl->tpl_vars['user']->value['id']) {?>selected<?php }?>>
                                    <?php echo $_smarty_tpl->tpl_vars['user']->value['username'];?>

                                    <?php if ($_smarty_tpl->tpl_vars['user']->value['role'] == 'reseller') {?>
                                        (<?php echo $_smarty_tpl->tpl_vars['user']->value['devices_count']+$_smarty_tpl->tpl_vars['user']->value['devices_allocated'];?>
/<?php echo $_smarty_tpl->tpl_vars['user']->value['max_devices'];?>
 urządzeń)
                                    <?php } elseif ($_smarty_tpl->tpl_vars['user']->value['role'] != 'admin') {?>
                                        (<?php echo $_smarty_tpl->tpl_vars['user']->value['devices_count'];?>
/<?php echo $_smarty_tpl->tpl_vars['user']->value['device_limit'];?>
 urządzeń)
                                    <?php }?>
                                </option>
                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                            </select>
                        </div>
                        <?php }?>

                        <div class="mb-3">
                            <label class="form-label">Nazwa urządzenia</label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-tag"></i></span>
                                <input type="text" 
                                       name="name" 
                                       class="form-control" 
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['name'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                       placeholder="np. Samsung TV Salon">
                            </div>
                            <small class="text-muted">Opcjonalna nazwa ułatwiająca identyfikację</small>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Adres MAC <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-ethernet"></i></span>
                                <input type="text" 
                                       name="mac" 
                                       class="form-control" 
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['mac'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                       placeholder="00:1A:2B:3C:4D:5E"
                                       required>
                            </div>
                            <small class="text-muted">Format: XX:XX:XX:XX:XX:XX lub XXXXXXXXXXXX</small>
                        </div>

                        <div class="mb-4">
                            <label class="form-label">Kod dostępu <span class="text-danger">*</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-key"></i></span>
                                <input type="text" 
                                       name="code" 
                                       class="form-control" 
                                       value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['code'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                       minlength="3"
                                       required>
                            </div>
                            <small class="text-muted">Kod wyświetlany na urządzeniu</small>
                        </div>

                        <?php if (!$_smarty_tpl->tpl_vars['isEdit']->value) {?>
                        <div class="mb-4">
                            <label class="form-label">Uwagi <span class="text-muted">(opcjonalne)</span></label>
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-sticky"></i></span>
                                <textarea name="initial_note" 
                                          class="form-control" 
                                          rows="2" 
                                          placeholder="Notatka dodana przy tworzeniu urządzenia..."><?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['initial_note'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
</textarea>
                            </div>
                            <small class="text-muted">Zostanie zapisana jako notatka do tego urządzenia</small>
                        </div>
                        <?php }?>

                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-check-lg me-1"></i>
                                <?php if ($_smarty_tpl->tpl_vars['isEdit']->value) {?>Zapisz zmiany<?php } else { ?>Dodaj urządzenie<?php }?>
                            </button>
                            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/devices" class="btn btn-secondary">Anuluj</a>
                        </div>
                    </form>
                </div>
            </div>

            <?php if ($_smarty_tpl->tpl_vars['isEdit']->value) {?>
            <!-- Actions Card -->
            <div class="card mt-4">
                <div class="card-header">
                    <h6 class="mb-0"><i class="bi bi-lightning me-2"></i>Akcje</h6>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2">
                        <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/settings/device?id=<?php echo $_smarty_tpl->tpl_vars['data']->value['id'];?>
" class="btn btn-outline-primary">
                            <i class="bi bi-sliders me-2"></i>Ustawienia urządzenia
                        </a>
                        <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists?device_id=<?php echo $_smarty_tpl->tpl_vars['data']->value['id'];?>
" class="btn btn-outline-info">
                            <i class="bi bi-collection-play me-2"></i>Playlisty (<?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['playlists_count'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
)
                        </a>
                    </div>
                </div>
            </div>
            
            <!-- Info Card -->
            <div class="card mt-4">
                <div class="card-header">
                    <h6 class="mb-0"><i class="bi bi-info-circle me-2"></i>Informacje</h6>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-6">
                            <small class="text-muted d-block">Utworzony</small>
                            <span><?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['data']->value['created_at'],"%d.%m.%Y %H:%M");?>
</span>
                        </div>
                        <div class="col-6">
                            <small class="text-muted d-block">Ostatnia aktualizacja</small>
                            <span><?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['data']->value['updated_at'],"%d.%m.%Y %H:%M");?>
</span>
                        </div>
                        <?php if ($_smarty_tpl->tpl_vars['isAdmin']->value) {?>
                        <div class="col-6 mt-3">
                            <small class="text-muted d-block">Właściciel</small>
                            <span><?php echo $_smarty_tpl->tpl_vars['data']->value['username'];?>
</span>
                        </div>
                        <?php }?>
                        <div class="col-6 mt-3">
                            <small class="text-muted d-block">Playlisty</small>
                            <a href="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/playlists?device_id=<?php echo $_smarty_tpl->tpl_vars['data']->value['id'];?>
"><?php echo (($tmp = $_smarty_tpl->tpl_vars['data']->value['playlists_count'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
 playlist</a>
                        </div>
                    </div>
                </div>
            </div>
            
                        <div class="mt-4">
                <?php $_smarty_tpl->_subTemplateRender("file:partials/entity_notes.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, $_smarty_tpl->cache_lifetime, array('entityType'=>"device",'entityId'=>$_smarty_tpl->tpl_vars['data']->value['id']), 0, false);
?>
            </div>
            <?php }?>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_8303283646975046a2caba7_03789676 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_8303283646975046a2caba7_03789676',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>
document.addEventListener('DOMContentLoaded', function() {
    // Formatowanie MAC address
    var macInput = document.querySelector('input[name="mac"]');
    if (macInput) {
        macInput.addEventListener('input', function(e) {
            // Usuń wszystko oprócz hex
            var value = this.value.replace(/[^0-9A-Fa-f]/g, '').toUpperCase();
            
            // Ogranicz do 12 znaków
            value = value.substring(0, 12);
            
            // Dodaj dwukropki co 2 znaki
            var formatted = '';
            for (var i = 0; i < value.length; i++) {
                if (i > 0 && i % 2 === 0) {
                    formatted += ':';
                }
                formatted += value[i];
            }
            
            this.value = formatted;
        });
        
        // Przy wklejaniu - od razu formatuj
        macInput.addEventListener('paste', function(e) {
            var self = this;
            setTimeout(function() {
                var value = self.value.replace(/[^0-9A-Fa-f]/g, '').toUpperCase();
                value = value.substring(0, 12);
                var formatted = '';
                for (var i = 0; i < value.length; i++) {
                    if (i > 0 && i % 2 === 0) {
                        formatted += ':';
                    }
                    formatted += value[i];
                }
                self.value = formatted;
            }, 0);
        });
    }
    
    // Kod urządzenia - zawsze duże litery
    var codeInput = document.querySelector('input[name="code"]');
    if (codeInput) {
        codeInput.addEventListener('input', function() {
            this.value = this.value.toUpperCase();
        });
    }
});
<?php echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
}
