<?php
/* Smarty version 4.5.6, created on 2026-01-04 16:50:04
  from '/var/www/html/tivi/panel/templates/xtream_check/index.tpl' */

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


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


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


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

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

<style>
.btn-xs {
    padding: 0.15rem 0.4rem;
    font-size: 0.75rem;
    line-height: 1.3;
    border-radius: 0.2rem;
}
</style>
<?php
}
}
/* {/block "styles"} */
/* {block "content"} */
class Block_697115240695a8c2c1a74c8_03846960 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'content' => 
  array (
    0 => 'Block_697115240695a8c2c1a74c8_03846960',
  ),
);
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">
    <div class="row justify-content-center">
        <div class="col-lg-10 col-xl-8">
            <!-- Header -->
            <div class="d-flex align-items-center mb-4">
                <div class="stat-icon bg-primary bg-opacity-10 text-primary me-3" style="width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center;">
                    <i class="bi bi-broadcast fs-4"></i>
                </div>
                <div>
                    <h4 class="mb-1">Xtream Check</h4>
                    <p class="text-muted mb-0">Sprawdź status i szczegóły konta Xtream Codes</p>
                </div>
            </div>

            <?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 }?>

            <!-- Formularz -->
            <div class="card mb-4">
                <div class="card-header">
                    <ul class="nav nav-tabs card-header-tabs" role="tablist">
                        <li class="nav-item">
                            <button class="nav-link <?php if ((!(($tmp = $_smarty_tpl->tpl_vars['inputData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp) || $_smarty_tpl->tpl_vars['inputData']->value['input_type'] == 'url') && !(($tmp = $_smarty_tpl->tpl_vars['prefillData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>active<?php }?>" 
                                    data-bs-toggle="tab" data-bs-target="#tab-url" type="button">
                                <i class="bi bi-link-45deg me-1"></i>Link URL
                            </button>
                        </li>
                        <li class="nav-item">
                            <button class="nav-link <?php if (((($tmp = $_smarty_tpl->tpl_vars['inputData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp) && $_smarty_tpl->tpl_vars['inputData']->value['input_type'] == 'manual') || (($tmp = $_smarty_tpl->tpl_vars['prefillData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>active<?php }?>" 
                                    data-bs-toggle="tab" data-bs-target="#tab-manual" type="button">
                                <i class="bi bi-input-cursor-text me-1"></i>Ręcznie
                            </button>
                        </li>
                    </ul>
                </div>
                <div class="card-body">
                    <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/xtream-check/check" id="xtreamCheckForm">
                        <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                        <input type="hidden" name="input_type" id="inputType" value="<?php if ((($tmp = $_smarty_tpl->tpl_vars['prefillData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>manual<?php } else {
echo (($tmp = $_smarty_tpl->tpl_vars['inputData']->value['input_type'] ?? null)===null||$tmp==='' ? 'url' ?? null : $tmp);
}?>">
                        
                        <div class="tab-content">
                            <!-- Tab: Link URL -->
                            <div class="tab-pane fade <?php if ((!(($tmp = $_smarty_tpl->tpl_vars['inputData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp) || $_smarty_tpl->tpl_vars['inputData']->value['input_type'] == 'url') && !(($tmp = $_smarty_tpl->tpl_vars['prefillData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>show active<?php }?>" id="tab-url">
                                <div class="mb-3">
                                    <label class="form-label">Link do API Xtream</label>
                                    <div class="input-group">
                                        <span class="input-group-text"><i class="bi bi-link-45deg"></i></span>
                                        <input type="text" 
                                               name="xtream_link" 
                                               id="xtreamLink"
                                               class="form-control" 
                                               value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['inputData']->value['url'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                               placeholder="http://server.com:port/player_api.php?username=xxx&password=yyy"
                                               autocomplete="off"
                                               data-lpignore="true"
                                               data-form-type="other">
                                    </div>
                                    <small class="text-muted">
                                        Obsługiwane formaty:<br>
                                        • <code>http://server:port/player_api.php?username=xxx&password=yyy</code><br>
                                        • <code>http://server:port/get.php?username=xxx&password=yyy&type=m3u_plus</code><br>
                                        • <code>http://server:port/live/username/password/...</code>
                                    </small>
                                </div>
                            </div>
                            
                            <!-- Tab: Ręcznie -->
                            <div class="tab-pane fade <?php if (((($tmp = $_smarty_tpl->tpl_vars['inputData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp) && $_smarty_tpl->tpl_vars['inputData']->value['input_type'] == 'manual') || (($tmp = $_smarty_tpl->tpl_vars['prefillData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>show active<?php }?>" id="tab-manual">
                                <div class="row">
                                    <div class="col-md-12 mb-3">
                                        <label class="form-label">Adres serwera</label>
                                        <div class="input-group">
                                            <span class="input-group-text"><i class="bi bi-hdd-network"></i></span>
                                            <input type="text" 
                                                   name="xc_host_addr" 
                                                   id="xtreamServer"
                                                   class="form-control" 
                                                   value="<?php echo (($tmp = (($tmp = $_smarty_tpl->tpl_vars['prefillData']->value['server'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['inputData']->value['server'] ?? null : $tmp) ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                                   placeholder="http://server.com:port"
                                                   autocomplete="new-password"
                                                   data-lpignore="true"
                                                   data-1p-ignore="true"
                                                   data-bwignore="true"
                                                   data-form-type="other">
                                        </div>
                                        <small class="text-muted">np. http://iptv.example.com:8080</small>
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label class="form-label">Nazwa użytkownika</label>
                                        <div class="input-group">
                                            <span class="input-group-text"><i class="bi bi-person"></i></span>
                                            <input type="text" 
                                                   name="xc_api_login" 
                                                   id="xtreamUser"
                                                   class="form-control" 
                                                   value="<?php echo (($tmp = (($tmp = $_smarty_tpl->tpl_vars['prefillData']->value['username'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['inputData']->value['username'] ?? null : $tmp) ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                                   placeholder="username"
                                                   autocomplete="new-password"
                                                   data-lpignore="true"
                                                   data-1p-ignore="true"
                                                   data-bwignore="true"
                                                   data-form-type="other">
                                        </div>
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label class="form-label">Hasło</label>
                                        <div class="input-group">
                                            <span class="input-group-text"><i class="bi bi-key"></i></span>
                                            <input type="text" 
                                                   name="xc_api_key" 
                                                   id="xtreamPass"
                                                   class="form-control" 
                                                   value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['prefillData']->value['password'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
"
                                                   placeholder="password"
                                                   autocomplete="new-password"
                                                   data-lpignore="true"
                                                   data-1p-ignore="true"
                                                   data-bwignore="true"
                                                   data-form-type="other">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-primary" id="checkBtn">
                                <i class="bi bi-search me-1"></i>Sprawdź konto
                            </button>
                            <button type="button" class="btn btn-outline-secondary" id="clearBtn">
                                <i class="bi bi-x-lg me-1"></i>Wyczyść
                            </button>
                        </div>
                    </form>
                </div>
            </div>

            <?php if ((($tmp = $_smarty_tpl->tpl_vars['result']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>
            <!-- Wyniki -->
            <?php if ($_smarty_tpl->tpl_vars['result']->value['success']) {?>
            
            <!-- Status konta -->
            <div class="card mb-4">
                <div class="card-header bg-success text-white">
                    <h5 class="mb-0"><i class="bi bi-check-circle me-2"></i>Konto aktywne</h5>
                </div>
                <div class="card-body">
                    <div class="row g-4">
                        <!-- Informacje o koncie -->
                        <div class="col-md-6">
                            <h6 class="text-muted mb-3"><i class="bi bi-person-badge me-2"></i>Informacje o koncie</h6>
                            <table class="table table-sm table-borderless mb-0">
                                <tr>
                                    <td class="text-muted" style="width: 140px;">Użytkownik:</td>
                                    <td><strong><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['user_info']['username'] ?? null)===null||$tmp==='' ? '-' ?? null : $tmp);?>
</strong></td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Status:</td>
                                    <td>
                                        <?php if ($_smarty_tpl->tpl_vars['result']->value['user_info']['status'] == 'Active') {?>
                                        <span class="badge bg-success">Aktywny</span>
                                        <?php } else { ?>
                                        <span class="badge bg-danger"><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['user_info']['status'] ?? null)===null||$tmp==='' ? 'Nieznany' ?? null : $tmp);?>
</span>
                                        <?php }?>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Wygasa:</td>
                                    <td>
                                        <?php if ($_smarty_tpl->tpl_vars['result']->value['user_info']['exp_date']) {?>
                                            <strong><?php echo $_smarty_tpl->tpl_vars['result']->value['user_info']['exp_date_formatted'];?>
</strong>
                                            <?php if ($_smarty_tpl->tpl_vars['result']->value['user_info']['days_left'] > 30) {?>
                                                <span class="badge bg-success ms-2"><?php echo $_smarty_tpl->tpl_vars['result']->value['user_info']['days_left'];?>
 dni</span>
                                            <?php } elseif ($_smarty_tpl->tpl_vars['result']->value['user_info']['days_left'] > 7) {?>
                                                <span class="badge bg-warning ms-2"><?php echo $_smarty_tpl->tpl_vars['result']->value['user_info']['days_left'];?>
 dni</span>
                                            <?php } elseif ($_smarty_tpl->tpl_vars['result']->value['user_info']['days_left'] > 0) {?>
                                                <span class="badge bg-danger ms-2"><?php echo $_smarty_tpl->tpl_vars['result']->value['user_info']['days_left'];?>
 dni</span>
                                            <?php } else { ?>
                                                <span class="badge bg-danger ms-2">Wygasło!</span>
                                            <?php }?>
                                        <?php } else { ?>
                                            <span class="badge bg-info">Bez limitu</span>
                                        <?php }?>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Połączenia:</td>
                                    <td>
                                        <?php if ($_smarty_tpl->tpl_vars['result']->value['user_info']['max_connections']) {?>
                                            <strong><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['user_info']['active_cons'] ?? null)===null||$tmp==='' ? 0 ?? null : $tmp);?>
</strong> / <?php echo $_smarty_tpl->tpl_vars['result']->value['user_info']['max_connections'];?>

                                            <div class="progress mt-1" style="height: 6px; width: 100px;">
                                                <div class="progress-bar <?php if ($_smarty_tpl->tpl_vars['result']->value['user_info']['conn_percent'] > 80) {?>bg-danger<?php } elseif ($_smarty_tpl->tpl_vars['result']->value['user_info']['conn_percent'] > 50) {?>bg-warning<?php } else { ?>bg-success<?php }?>" 
                                                     style="width: <?php echo $_smarty_tpl->tpl_vars['result']->value['user_info']['conn_percent'];?>
%"></div>
                                            </div>
                                        <?php } else { ?>
                                            <span class="badge bg-info">Bez limitu</span>
                                        <?php }?>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Utworzone:</td>
                                    <td>
                                        <?php if ($_smarty_tpl->tpl_vars['result']->value['user_info']['created_at']) {?>
                                            <?php echo smarty_modifier_date_format($_smarty_tpl->tpl_vars['result']->value['user_info']['created_at'],"%d.%m.%Y %H:%M");?>

                                        <?php } else { ?>
                                            -
                                        <?php }?>
                                    </td>
                                </tr>
                                <?php if ($_smarty_tpl->tpl_vars['result']->value['user_info']['is_trial']) {?>
                                <tr>
                                    <td class="text-muted">Trial:</td>
                                    <td><span class="badge bg-warning">Konto testowe</span></td>
                                </tr>
                                <?php }?>
                            </table>
                        </div>
                        
                        <!-- Informacje o serwerze -->
                        <div class="col-md-6">
                            <h6 class="text-muted mb-3"><i class="bi bi-hdd-rack me-2"></i>Informacje o serwerze</h6>
                            <table class="table table-sm table-borderless mb-0">
                                <tr>
                                    <td class="text-muted" style="width: 140px;">URL:</td>
                                    <td><code class="small"><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['server_info']['url'] ?? null)===null||$tmp==='' ? $_smarty_tpl->tpl_vars['result']->value['server'] ?? null : $tmp);?>
</code></td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Port:</td>
                                    <td><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['server_info']['port'] ?? null)===null||$tmp==='' ? '-' ?? null : $tmp);?>
</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">HTTPS Port:</td>
                                    <td><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['server_info']['https_port'] ?? null)===null||$tmp==='' ? '-' ?? null : $tmp);?>
</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Protokół:</td>
                                    <td><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['server_info']['server_protocol'] ?? null)===null||$tmp==='' ? '-' ?? null : $tmp);?>
</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Strefa czasowa:</td>
                                    <td><?php echo (($tmp = $_smarty_tpl->tpl_vars['result']->value['server_info']['timezone'] ?? null)===null||$tmp==='' ? '-' ?? null : $tmp);?>
</td>
                                </tr>
                                <tr>
                                    <td class="text-muted">Czas serwera:</td>
                                    <td>
                                        <?php if ($_smarty_tpl->tpl_vars['result']->value['server_info']['time_now']) {?>
                                            <?php echo $_smarty_tpl->tpl_vars['result']->value['server_info']['time_now'];?>

                                        <?php } else { ?>
                                            -
                                        <?php }?>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Statystyki kategorii -->
            <div class="row g-4 mb-4">
                <div class="col-md-4">
                    <div class="card h-100 border-primary">
                        <div class="card-body text-center">
                            <i class="bi bi-broadcast display-4 text-primary mb-2"></i>
                            <h2 class="mb-1"><?php echo $_smarty_tpl->tpl_vars['result']->value['stats']['live_categories'];?>
</h2>
                            <p class="text-muted mb-0">Kategorie Live TV</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card h-100 border-success">
                        <div class="card-body text-center">
                            <i class="bi bi-film display-4 text-success mb-2"></i>
                            <h2 class="mb-1"><?php echo $_smarty_tpl->tpl_vars['result']->value['stats']['vod_categories'];?>
</h2>
                            <p class="text-muted mb-0">Kategorie VOD</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card h-100 border-warning">
                        <div class="card-body text-center">
                            <i class="bi bi-collection-play display-4 text-warning mb-2"></i>
                            <h2 class="mb-1"><?php echo $_smarty_tpl->tpl_vars['result']->value['stats']['series_categories'];?>
</h2>
                            <p class="text-muted mb-0">Kategorie Seriali</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Polskie kategorie -->
            <div class="card mb-4">
                <div class="card-header <?php if ($_smarty_tpl->tpl_vars['result']->value['stats']['has_polish']) {?>bg-success text-white<?php } else { ?>bg-secondary text-white<?php }?>">
                    <h5 class="mb-0">
                        <?php if ($_smarty_tpl->tpl_vars['result']->value['stats']['has_polish']) {?>
                        <i class="bi bi-check-circle me-2"></i>Znaleziono polskie kategorie
                        <?php } else { ?>
                        <i class="bi bi-x-circle me-2"></i>Brak polskich kategorii
                        <?php }?>
                    </h5>
                </div>
                <?php if ($_smarty_tpl->tpl_vars['result']->value['stats']['has_polish']) {?>
                <div class="card-body">
                    <div class="row g-4">
                        <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['live']) > 0) {?>
                        <div class="col-md-4">
                            <h6 class="text-primary"><i class="bi bi-broadcast me-1"></i>Live TV (<?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['live']);?>
)</h6>
                            <ul class="list-unstyled mb-0">
                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['polish_categories']['live'], 'cat');
$_smarty_tpl->tpl_vars['cat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['cat']->value) {
$_smarty_tpl->tpl_vars['cat']->do_else = false;
?>
                                <li class="mb-1">
                                    <i class="bi bi-check text-success me-1"></i>
                                    <?php echo $_smarty_tpl->tpl_vars['cat']->value['category_name'];?>

                                </li>
                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                            </ul>
                        </div>
                        <?php }?>
                        
                        <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['vod']) > 0) {?>
                        <div class="col-md-4">
                            <h6 class="text-success"><i class="bi bi-film me-1"></i>VOD (<?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['vod']);?>
)</h6>
                            <ul class="list-unstyled mb-0">
                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['polish_categories']['vod'], 'cat');
$_smarty_tpl->tpl_vars['cat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['cat']->value) {
$_smarty_tpl->tpl_vars['cat']->do_else = false;
?>
                                <li class="mb-1">
                                    <i class="bi bi-check text-success me-1"></i>
                                    <?php echo $_smarty_tpl->tpl_vars['cat']->value['category_name'];?>

                                </li>
                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                            </ul>
                        </div>
                        <?php }?>
                        
                        <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['series']) > 0) {?>
                        <div class="col-md-4">
                            <h6 class="text-warning"><i class="bi bi-collection-play me-1"></i>Seriale (<?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['series']);?>
)</h6>
                            <ul class="list-unstyled mb-0">
                                <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['polish_categories']['series'], 'cat');
$_smarty_tpl->tpl_vars['cat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['cat']->value) {
$_smarty_tpl->tpl_vars['cat']->do_else = false;
?>
                                <li class="mb-1">
                                    <i class="bi bi-check text-success me-1"></i>
                                    <?php echo $_smarty_tpl->tpl_vars['cat']->value['category_name'];?>

                                </li>
                                <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                            </ul>
                        </div>
                        <?php }?>
                    </div>
                </div>
                <?php }?>
            </div>

            <!-- Generator M3U - zintegrowany z kategoriami -->
            <form method="post" action="<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/xtream-check/generate" id="m3uGeneratorForm">
                <input type="hidden" name="csrf_token" value="<?php echo $_smarty_tpl->tpl_vars['csrfToken']->value;?>
">
                <input type="hidden" name="server" value="<?php echo $_smarty_tpl->tpl_vars['result']->value['server'];?>
">
                <input type="hidden" name="username" value="<?php echo $_smarty_tpl->tpl_vars['result']->value['username'];?>
">
                <input type="hidden" name="password" value="<?php echo (($tmp = $_smarty_tpl->tpl_vars['inputData']->value['password'] ?? null)===null||$tmp==='' ? '' ?? null : $tmp);?>
">
                
                <div class="card mb-4">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">
                            <i class="bi bi-list-check me-2"></i>Wybierz kategorie do playlisty M3U
                        </h5>
                        <div class="btn-group btn-group-sm">
                            <button type="button" class="btn btn-outline-primary" id="selectAllBtn">
                                <i class="bi bi-check-all me-1"></i>Zaznacz wszystkie
                            </button>
                            <button type="button" class="btn btn-outline-secondary" id="deselectAllBtn">
                                <i class="bi bi-x-lg me-1"></i>Odznacz wszystkie
                            </button>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <!-- Live TV -->
                            <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['categories']['live']) > 0) {?>
                            <div class="col-lg-4 mb-4">
                                <div class="border-bottom pb-2 mb-2">
                                    <div class="d-flex justify-content-between align-items-center mb-2">
                                        <h6 class="text-primary mb-0">
                                            <i class="bi bi-broadcast me-1"></i>Live TV <span class="badge bg-primary"><?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['categories']['live']);?>
</span>
                                        </h6>
                                    </div>
                                    <div class="d-flex gap-1">
                                        <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['live']) > 0) {?>
                                        <button type="button" class="btn btn-xs btn-outline-danger select-polish-btn" data-type="live">
                                            🇵🇱 <?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['live']);?>

                                        </button>
                                        <?php }?>
                                        <button type="button" class="btn btn-xs btn-outline-secondary select-all-type-btn" data-type="live">
                                            Wszystkie
                                        </button>
                                    </div>
                                </div>
                                <div style="max-height: 280px; overflow-y: auto;">
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['categories']['live'], 'cat');
$_smarty_tpl->tpl_vars['cat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['cat']->value) {
$_smarty_tpl->tpl_vars['cat']->do_else = false;
?>
                                    <?php $_smarty_tpl->_assignInScope('isPolish', false);?>
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['polish_categories']['live'], 'polCat');
$_smarty_tpl->tpl_vars['polCat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['polCat']->value) {
$_smarty_tpl->tpl_vars['polCat']->do_else = false;
?>
                                        <?php if ($_smarty_tpl->tpl_vars['polCat']->value['category_id'] == $_smarty_tpl->tpl_vars['cat']->value['category_id']) {
$_smarty_tpl->_assignInScope('isPolish', true);
}?>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                    <div class="form-check py-1">
                                        <input type="checkbox" name="categories[live][]" value="<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
" 
                                               id="live_<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
" class="form-check-input cat-checkbox cat-live<?php if ($_smarty_tpl->tpl_vars['isPolish']->value) {?> polish-cat polish-live<?php }?>">
                                        <label class="form-check-label small<?php if ($_smarty_tpl->tpl_vars['isPolish']->value) {?> text-danger<?php }?>" for="live_<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
">
                                            <?php echo $_smarty_tpl->tpl_vars['cat']->value['category_name'];?>

                                        </label>
                                    </div>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                </div>
                            </div>
                            <?php }?>
                            
                            <!-- VOD -->
                            <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['categories']['vod']) > 0) {?>
                            <div class="col-lg-4 mb-4">
                                <div class="border-bottom pb-2 mb-2">
                                    <div class="d-flex justify-content-between align-items-center mb-2">
                                        <h6 class="text-success mb-0">
                                            <i class="bi bi-film me-1"></i>VOD <span class="badge bg-success"><?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['categories']['vod']);?>
</span>
                                        </h6>
                                    </div>
                                    <div class="d-flex gap-1">
                                        <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['vod']) > 0) {?>
                                        <button type="button" class="btn btn-xs btn-outline-danger select-polish-btn" data-type="vod">
                                            🇵🇱 <?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['vod']);?>

                                        </button>
                                        <?php }?>
                                        <button type="button" class="btn btn-xs btn-outline-secondary select-all-type-btn" data-type="vod">
                                            Wszystkie
                                        </button>
                                    </div>
                                </div>
                                <div style="max-height: 280px; overflow-y: auto;">
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['categories']['vod'], 'cat');
$_smarty_tpl->tpl_vars['cat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['cat']->value) {
$_smarty_tpl->tpl_vars['cat']->do_else = false;
?>
                                    <?php $_smarty_tpl->_assignInScope('isPolish', false);?>
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['polish_categories']['vod'], 'polCat');
$_smarty_tpl->tpl_vars['polCat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['polCat']->value) {
$_smarty_tpl->tpl_vars['polCat']->do_else = false;
?>
                                        <?php if ($_smarty_tpl->tpl_vars['polCat']->value['category_id'] == $_smarty_tpl->tpl_vars['cat']->value['category_id']) {
$_smarty_tpl->_assignInScope('isPolish', true);
}?>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                    <div class="form-check py-1">
                                        <input type="checkbox" name="categories[vod][]" value="<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
" 
                                               id="vod_<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
" class="form-check-input cat-checkbox cat-vod<?php if ($_smarty_tpl->tpl_vars['isPolish']->value) {?> polish-cat polish-vod<?php }?>">
                                        <label class="form-check-label small<?php if ($_smarty_tpl->tpl_vars['isPolish']->value) {?> text-danger<?php }?>" for="vod_<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
">
                                            <?php echo $_smarty_tpl->tpl_vars['cat']->value['category_name'];?>

                                        </label>
                                    </div>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                </div>
                            </div>
                            <?php }?>
                            
                            <!-- Seriale -->
                            <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['categories']['series']) > 0) {?>
                            <div class="col-lg-4 mb-4">
                                <div class="border-bottom pb-2 mb-2">
                                    <div class="d-flex justify-content-between align-items-center mb-2">
                                        <h6 class="text-warning mb-0">
                                            <i class="bi bi-collection-play me-1"></i>Seriale <span class="badge bg-warning text-dark"><?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['categories']['series']);?>
</span>
                                        </h6>
                                    </div>
                                    <div class="d-flex gap-1">
                                        <?php if (smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['series']) > 0) {?>
                                        <button type="button" class="btn btn-xs btn-outline-danger select-polish-btn" data-type="series">
                                            🇵🇱 <?php echo smarty_modifier_count($_smarty_tpl->tpl_vars['result']->value['polish_categories']['series']);?>

                                        </button>
                                        <?php }?>
                                        <button type="button" class="btn btn-xs btn-outline-secondary select-all-type-btn" data-type="series">
                                            Wszystkie
                                        </button>
                                    </div>
                                </div>
                                <div style="max-height: 280px; overflow-y: auto;">
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['categories']['series'], 'cat');
$_smarty_tpl->tpl_vars['cat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['cat']->value) {
$_smarty_tpl->tpl_vars['cat']->do_else = false;
?>
                                    <?php $_smarty_tpl->_assignInScope('isPolish', false);?>
                                    <?php
$_from = $_smarty_tpl->smarty->ext->_foreach->init($_smarty_tpl, $_smarty_tpl->tpl_vars['result']->value['polish_categories']['series'], 'polCat');
$_smarty_tpl->tpl_vars['polCat']->do_else = true;
if ($_from !== null) foreach ($_from as $_smarty_tpl->tpl_vars['polCat']->value) {
$_smarty_tpl->tpl_vars['polCat']->do_else = false;
?>
                                        <?php if ($_smarty_tpl->tpl_vars['polCat']->value['category_id'] == $_smarty_tpl->tpl_vars['cat']->value['category_id']) {
$_smarty_tpl->_assignInScope('isPolish', true);
}?>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                    <div class="form-check py-1">
                                        <input type="checkbox" name="categories[series][]" value="<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
" 
                                               id="series_<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
" class="form-check-input cat-checkbox cat-series<?php if ($_smarty_tpl->tpl_vars['isPolish']->value) {?> polish-cat polish-series<?php }?>">
                                        <label class="form-check-label small<?php if ($_smarty_tpl->tpl_vars['isPolish']->value) {?> text-danger<?php }?>" for="series_<?php echo $_smarty_tpl->tpl_vars['cat']->value['category_id'];?>
">
                                            <?php echo $_smarty_tpl->tpl_vars['cat']->value['category_name'];?>

                                        </label>
                                    </div>
                                    <?php
}
$_smarty_tpl->smarty->ext->_foreach->restore($_smarty_tpl, 1);?>
                                </div>
                            </div>
                            <?php }?>
                        </div>
                        
                        <!-- Podsumowanie i przycisk -->
                        <div class="border-top pt-3 mt-2">
                            <div class="d-flex justify-content-between align-items-center flex-wrap gap-3">
                                <div class="text-muted">
                                    <i class="bi bi-info-circle me-1"></i>
                                    Zaznaczono: <strong><span id="selectedCount">0</span></strong> kategorii
                                    <span id="selectedTypes" class="ms-2"></span>
                                </div>
                                <button type="submit" class="btn btn-primary btn-lg" id="generateBtn">
                                    <i class="bi bi-download me-2"></i>Generuj M3U
                                </button>
                            </div>
                            
                            <!-- Progress bar -->
                            <div id="generateProgress" class="mt-3" style="display: none;">
                                <div class="d-flex align-items-center mb-2">
                                    <div class="spinner-border spinner-border-sm text-primary me-2"></div>
                                    <span id="progressText">Generowanie playlisty...</span>
                                </div>
                                <div class="progress" style="height: 8px;">
                                    <div id="progressBar" class="progress-bar progress-bar-striped progress-bar-animated" 
                                         role="progressbar" style="width: 0%"></div>
                                </div>
                                <small class="text-muted mt-1 d-block" id="progressDetails"></small>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

            <?php } else { ?>
            <!-- Błąd -->
            <div class="card border-danger">
                <div class="card-header bg-danger text-white">
                    <h5 class="mb-0"><i class="bi bi-x-circle me-2"></i>Błąd sprawdzania konta</h5>
                </div>
                <div class="card-body">
                    <p class="mb-0"><?php echo $_smarty_tpl->tpl_vars['result']->value['error'];?>
</p>
                </div>
            </div>
            <?php }?>
            
            <?php }?>
        </div>
    </div>
</div>
<?php
}
}
/* {/block "content"} */
/* {block "scripts"} */
class Block_2145319105695a8c2c1cdae9_55815149 extends Smarty_Internal_Block
{
public $subBlocks = array (
  'scripts' => 
  array (
    0 => 'Block_2145319105695a8c2c1cdae9_55815149',
  ),
);
public function callBlock(Smarty_Internal_Template $_smarty_tpl) {
?>

<?php echo '<script'; ?>
>
document.addEventListener('DOMContentLoaded', function() {
    var form = document.getElementById('xtreamCheckForm');
    var inputTypeField = document.getElementById('inputType');
    var checkBtn = document.getElementById('checkBtn');
    var clearBtn = document.getElementById('clearBtn');
    
    // Zmiana taba - aktualizuj input_type
    document.querySelectorAll('[data-bs-toggle="tab"]').forEach(function(tab) {
        tab.addEventListener('shown.bs.tab', function(e) {
            if (e.target.getAttribute('data-bs-target') === '#tab-url') {
                inputTypeField.value = 'url';
            } else {
                inputTypeField.value = 'manual';
            }
        });
    });
    
    // Loading state
    if (form) {
        form.addEventListener('submit', function() {
            if (checkBtn) {
                checkBtn.disabled = true;
                checkBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-1"></span>Sprawdzanie...';
            }
        });
    }
    
    // Wyczyść formularz
    if (clearBtn) {
        clearBtn.addEventListener('click', function() {
            document.getElementById('xtreamLink').value = '';
            document.getElementById('xtreamServer').value = '';
            document.getElementById('xtreamUser').value = '';
            document.getElementById('xtreamPass').value = '';
        });
    }
    
    // ============ GENERATOR M3U ============
    
    var catCheckboxes = document.querySelectorAll('.cat-checkbox');
    var selectedCountEl = document.getElementById('selectedCount');
    var selectedTypesEl = document.getElementById('selectedTypes');
    
    // Funkcja aktualizacji licznika
    function updateSelectedCount() {
        var liveCount = document.querySelectorAll('.cat-live:checked').length;
        var vodCount = document.querySelectorAll('.cat-vod:checked').length;
        var seriesCount = document.querySelectorAll('.cat-series:checked').length;
        var total = liveCount + vodCount + seriesCount;
        
        if (selectedCountEl) {
            selectedCountEl.textContent = total;
        }
        
        if (selectedTypesEl) {
            var types = [];
            if (liveCount > 0) types.push('<span class="badge bg-primary">' + liveCount + ' Live</span>');
            if (vodCount > 0) types.push('<span class="badge bg-success">' + vodCount + ' VOD</span>');
            if (seriesCount > 0) types.push('<span class="badge bg-warning text-dark">' + seriesCount + ' Seriale</span>');
            selectedTypesEl.innerHTML = types.join(' ');
        }
        
        // Aktualizuj stany przycisków
        updateButtonStates();
    }
    
    // Funkcja aktualizacji stanów przycisków
    function updateButtonStates() {
        ['live', 'vod', 'series'].forEach(function(type) {
            var allBtn = document.querySelector('.select-all-type-btn[data-type="' + type + '"]');
            var plBtn = document.querySelector('.select-polish-btn[data-type="' + type + '"]');
            
            var allCheckboxes = document.querySelectorAll('.cat-' + type);
            var polishCheckboxes = document.querySelectorAll('.polish-' + type);
            
            var allChecked = allCheckboxes.length > 0 && Array.from(allCheckboxes).every(function(cb) { return cb.checked; });
            var allPolishChecked = polishCheckboxes.length > 0 && Array.from(polishCheckboxes).every(function(cb) { return cb.checked; });
            
            // Przycisk "Wszystkie" - szary outline / pełny secondary
            if (allBtn) {
                if (allChecked) {
                    allBtn.classList.remove('btn-outline-secondary');
                    allBtn.classList.add('btn-secondary');
                } else {
                    allBtn.classList.remove('btn-secondary');
                    allBtn.classList.add('btn-outline-secondary');
                }
            }
            
            // Przycisk "PL" - czerwony outline / pełny czerwony
            if (plBtn) {
                if (allPolishChecked) {
                    plBtn.classList.remove('btn-outline-danger');
                    plBtn.classList.add('btn-danger');
                } else {
                    plBtn.classList.remove('btn-danger');
                    plBtn.classList.add('btn-outline-danger');
                }
            }
        });
    }
    
    // Nasłuchuj zmian w checkboxach kategorii
    catCheckboxes.forEach(function(cb) {
        cb.addEventListener('change', updateSelectedCount);
    });
    
    // Przycisk "Wszystkie" dla danego typu (toggle)
    document.querySelectorAll('.select-all-type-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var type = this.dataset.type;
            var checkboxes = document.querySelectorAll('.cat-' + type);
            var allChecked = Array.from(checkboxes).every(function(cb) { return cb.checked; });
            
            // Toggle - jeśli wszystkie zaznaczone to odznacz, w przeciwnym razie zaznacz wszystkie
            checkboxes.forEach(function(cb) {
                cb.checked = !allChecked;
            });
            updateSelectedCount();
        });
    });
    
    // Zaznacz/Odznacz wszystkie (globalne)
    var selectAllBtn = document.getElementById('selectAllBtn');
    var deselectAllBtn = document.getElementById('deselectAllBtn');
    
    if (selectAllBtn) {
        selectAllBtn.addEventListener('click', function() {
            catCheckboxes.forEach(function(cb) { cb.checked = true; });
            updateSelectedCount();
        });
    }
    
    if (deselectAllBtn) {
        deselectAllBtn.addEventListener('click', function() {
            catCheckboxes.forEach(function(cb) { cb.checked = false; });
            updateSelectedCount();
        });
    }
    
    // Przycisk "PL" dla danego typu (toggle)
    document.querySelectorAll('.select-polish-btn').forEach(function(btn) {
        btn.addEventListener('click', function() {
            var type = this.dataset.type;
            var polishCheckboxes = document.querySelectorAll('.polish-' + type);
            var allPolishChecked = Array.from(polishCheckboxes).every(function(cb) { return cb.checked; });
            
            // Toggle - jeśli wszystkie polskie zaznaczone to odznacz, w przeciwnym razie zaznacz
            polishCheckboxes.forEach(function(cb) {
                cb.checked = !allPolishChecked;
            });
            updateSelectedCount();
        });
    });
    
    // Generator M3U z progress barem
    var generatorForm = document.getElementById('m3uGeneratorForm');
    if (generatorForm) {
        generatorForm.addEventListener('submit', function(e) {
            e.preventDefault();
            
            var anySelected = document.querySelectorAll('.cat-checkbox:checked').length > 0;
            if (!anySelected) {
                alert('Zaznacz przynajmniej jedną kategorię do wygenerowania playlisty M3U');
                return false;
            }
            
            var generateBtn = document.getElementById('generateBtn');
            var progressDiv = document.getElementById('generateProgress');
            var progressBar = document.getElementById('progressBar');
            var progressText = document.getElementById('progressText');
            var progressDetails = document.getElementById('progressDetails');
            
            // Zlicz wybrane typy
            var liveCount = document.querySelectorAll('.cat-live:checked').length;
            var vodCount = document.querySelectorAll('.cat-vod:checked').length;
            var seriesCount = document.querySelectorAll('.cat-series:checked').length;
            var totalCats = liveCount + vodCount + seriesCount;
            
            // Pokaż progress
            generateBtn.disabled = true;
            generateBtn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Generowanie...';
            progressDiv.style.display = 'block';
            progressBar.style.width = '5%';
            progressBar.classList.remove('bg-danger', 'bg-success');
            progressBar.classList.add('progress-bar-animated');
            
            // Timer pokazujący ile czasu minęło
            var startTime = Date.now();
            var timerInterval = setInterval(function() {
                var elapsed = Math.floor((Date.now() - startTime) / 1000);
                var mins = Math.floor(elapsed / 60);
                var secs = elapsed % 60;
                var timeStr = mins > 0 ? mins + 'm ' + secs + 's' : secs + 's';
                document.getElementById('elapsedTime').textContent = timeStr;
            }, 1000);
            
            // Informacje o zadaniu
            var taskInfo = [];
            if (liveCount > 0) taskInfo.push(liveCount + ' kat. Live');
            if (vodCount > 0) taskInfo.push(vodCount + ' kat. VOD');
            if (seriesCount > 0) taskInfo.push(seriesCount + ' kat. Seriali');
            
            progressText.innerHTML = '<i class="bi bi-hourglass-split me-1"></i>Generowanie playlisty M3U...';
            progressDetails.innerHTML = '<span class="me-3">' + taskInfo.join(', ') + '</span><span class="badge bg-secondary">Czas: <span id="elapsedTime">0s</span></span>';
            
            // Symulacja postępu - wolniejsza, bardziej realistyczna
            var progressValue = 5;
            var progressInterval = setInterval(function() {
                if (progressValue < 95) {
                    // Wolniejszy postęp dla seriali
                    var increment = seriesCount > 0 ? Math.random() * 2 : Math.random() * 4;
                    progressValue += increment;
                    progressBar.style.width = Math.min(progressValue, 95) + '%';
                    
                    // Aktualizuj tekst w zależności od postępu
                    if (progressValue < 20) {
                        progressText.innerHTML = '<i class="bi bi-cloud-download me-1"></i>Pobieranie listy strumieni...';
                    } else if (progressValue < 50) {
                        if (seriesCount > 0) {
                            progressText.innerHTML = '<i class="bi bi-collection-play me-1"></i>Pobieranie informacji o serialach (równolegle)...';
                        } else {
                            progressText.innerHTML = '<i class="bi bi-film me-1"></i>Przetwarzanie strumieni...';
                        }
                    } else if (progressValue < 80) {
                        progressText.innerHTML = '<i class="bi bi-file-earmark-text me-1"></i>Budowanie pliku M3U...';
                    } else {
                        progressText.innerHTML = '<i class="bi bi-check2-circle me-1"></i>Finalizowanie...';
                    }
                }
            }, 800);
            
            // Wyślij formularz przez AJAX z długim timeout (10 minut)
            var formData = new FormData(generatorForm);
            var controller = new AbortController();
            var timeoutId = setTimeout(function() {
                controller.abort();
            }, 600000); // 10 minut timeout
            
            fetch(generatorForm.action, {
                method: 'POST',
                body: formData,
                signal: controller.signal
            })
            .then(function(response) {
                clearTimeout(timeoutId);
                clearInterval(progressInterval);
                clearInterval(timerInterval);
                
                if (response.redirected) {
                    // Błąd - przekierowanie
                    window.location.href = response.url;
                    return null;
                }
                
                // Sprawdź czy to plik M3U
                var contentType = response.headers.get('Content-Type');
                if (contentType && contentType.includes('mpegurl')) {
                    // Sukces - pobierz plik
                    var elapsed = Math.floor((Date.now() - startTime) / 1000);
                    progressBar.style.width = '100%';
                    progressBar.classList.remove('progress-bar-animated');
                    progressBar.classList.add('bg-success');
                    progressText.innerHTML = '<i class="bi bi-check-circle-fill me-1"></i>Gotowe! Pobieranie pliku...';
                    progressDetails.innerHTML = '<span class="text-success">Wygenerowano w ' + elapsed + ' sekund</span>';
                    
                    // Pobierz nazwę pliku z headers
                    var disposition = response.headers.get('Content-Disposition');
                    var filename = 'playlist.m3u';
                    if (disposition) {
                        var match = disposition.match(/filename="(.+)"/);
                        if (match) filename = match[1];
                    }
                    
                    return response.blob().then(function(blob) {
                        return { blob: blob, filename: filename };
                    });
                } else {
                    // Prawdopodobnie błąd HTML
                    window.location.href = '<?php echo $_smarty_tpl->tpl_vars['baseUrl']->value;?>
/xtream-check';
                    return null;
                }
            })
            .then(function(data) {
                if (data && data.blob) {
                    // Utwórz link do pobrania
                    var url = window.URL.createObjectURL(data.blob);
                    var a = document.createElement('a');
                    a.href = url;
                    a.download = data.filename;
                    document.body.appendChild(a);
                    a.click();
                    window.URL.revokeObjectURL(url);
                    a.remove();
                    
                    // Reset UI po 2 sekundach
                    setTimeout(function() {
                        generateBtn.disabled = false;
                        generateBtn.innerHTML = '<i class="bi bi-download me-2"></i>Generuj M3U';
                        progressDiv.style.display = 'none';
                        progressBar.style.width = '0%';
                        progressBar.classList.add('progress-bar-animated');
                        progressBar.classList.remove('bg-success');
                    }, 2000);
                }
            })
            .catch(function(error) {
                clearTimeout(timeoutId);
                clearInterval(progressInterval);
                clearInterval(timerInterval);
                console.error('Błąd:', error);
                
                var elapsed = Math.floor((Date.now() - startTime) / 1000);
                progressBar.classList.remove('progress-bar-animated');
                progressBar.classList.add('bg-danger');
                
                // Lepsze komunikaty błędów
                if (error.name === 'AbortError') {
                    progressText.innerHTML = '<i class="bi bi-exclamation-triangle me-1"></i>Przekroczono limit czasu (10 minut)';
                    progressDetails.innerHTML = 'Spróbuj wybrać mniej kategorii seriali';
                } else if (error.message === 'Failed to fetch') {
                    progressText.innerHTML = '<i class="bi bi-wifi-off me-1"></i>Utracono połączenie z serwerem';
                    progressDetails.innerHTML = 'Serwer mógł być przeciążony (po ' + elapsed + 's) - spróbuj ponownie';
                } else {
                    progressText.innerHTML = '<i class="bi bi-x-circle me-1"></i>Wystąpił błąd';
                    progressDetails.innerHTML = error.message || 'Spróbuj ponownie';
                }
                
                setTimeout(function() {
                    generateBtn.disabled = false;
                    generateBtn.innerHTML = '<i class="bi bi-download me-2"></i>Generuj M3U';
                    progressDiv.style.display = 'none';
                    progressBar.style.width = '0%';
                    progressBar.classList.add('progress-bar-animated');
                    progressBar.classList.remove('bg-danger');
                }, 5000);
            });
        });
    }
    
    // Auto-submit jeśli przekazano dane z playlisty
    <?php if ((($tmp = $_smarty_tpl->tpl_vars['prefillData']->value ?? null)===null||$tmp==='' ? false ?? null : $tmp)) {?>
    if (form && document.getElementById('xtreamServer').value && document.getElementById('xtreamUser').value && document.getElementById('xtreamPass').value) {
        // Krótkie opóźnienie żeby strona się wyrenderowała
        setTimeout(function() {
            form.submit();
        }, 300);
    }
    <?php }?>
});
<?php echo '</script'; ?>
>
<?php
}
}
/* {/block "scripts"} */
}
