Menu="Tasks:95"
Title="Varaverk"
Icon="varaverk.png"
---
<?php
$plugin  = 'varaverk';
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
$pluginDir = "$docroot/plugins/$plugin";

require_once "$pluginDir/include/config.php";

// First-run check — show setup wizard if HOST1 is blank OR local host.conf is missing
$_master = vv_read_conf_raw('master.conf');
preg_match('/^\s*HOST1\s*=\s*"([^"]*)"/m', $_master, $_h1m);
$_host1_blank  = empty(trim($_h1m[1] ?? ''));
$_my_hostid    = vv_detect_host();
$_conf_missing = $_my_hostid !== 'unknown'
    && !file_exists(CONF_DIR . '/' . $_my_hostid . '.conf');
if ($_host1_blank || $_conf_missing) {
    include "$pluginDir/pages/setup.php";
    return;
}
unset($_master, $_h1m, $_host1_blank, $_my_hostid, $_conf_missing);

// Determine active tab
$tab = $_GET['tab'] ?? 'monitor';
$validTabs = ['monitor', 'scheduler', 'docker', 'watchdog', 'partnership', 'fallback', 'arrs'];
if (!in_array($tab, $validTabs)) $tab = 'monitor';
$tabLabels = ['monitor' => 'Monitor', 'scheduler' => 'Scheduler', 'docker' => 'Docker', 'watchdog' => 'Watchdog', 'partnership' => 'Partnership', 'fallback' => 'FallBack', 'arrs' => 'Arrs'];
?>

<link rel="stylesheet" href="/plugins/<?=$plugin?>/css/varaverk.css">

<div id="varaverk-wrap">

  <!-- Tab bar -->
  <div id="vv-tabs">
    <?php foreach ($validTabs as $t): ?>
      <a href="?tab=<?=$t?>" class="vv-tab<?= $t === $tab ? ' active' : '' ?>">
        <?= $tabLabels[$t] ?? ucfirst($t) ?>
      </a>
    <?php endforeach; ?>
  </div>

  <!-- Tab content -->
  <div id="vv-content">
    <?php
      $page = "$pluginDir/pages/$tab.php";
      if (file_exists($page)) include $page;
      else echo "<p>Page not found: $tab</p>";
    ?>
  </div>

</div>

<script src="/plugins/<?=$plugin?>/js/varaverk.js"></script>
