<?php
/**
 * Antara — admin layout footer counterpart of _layout.php.
 * Closes the main + shell, emits ADMIN_CTX bootstrap and loads admin.js.
 */
?>
    </main>
  </div>

  <script>
    window.ADMIN_CTX = {
      apiUrl: <?php echo json_encode($apiUrl, JSON_UNESCAPED_SLASHES); ?>,
      projectBase: <?php echo json_encode($projectBase, JSON_UNESCAPED_SLASHES); ?>,
      csrf:   <?php echo json_encode($csrf, JSON_UNESCAPED_SLASHES); ?>,
      user:   <?php echo json_encode($user ? [
                'id'   => $user['id'],
                'role' => $user['role'],
                'email'=> $user['email'],
                'username' => $user['username'] ?? '',
                'profileImageRel' => antara_user_profile_image_rel($user),
              ] : null, JSON_UNESCAPED_SLASHES); ?>,
      loginRequiredGlobally: <?php echo json_encode($loginGloballyRequired, JSON_UNESCAPED_SLASHES); ?>,
      needsFirstAdminWizard: <?php echo json_encode(!empty($adminNeedsFirstWizard), JSON_UNESCAPED_SLASHES); ?>,
      activeUserCount: <?php echo json_encode((int)($adminActiveUserCount ?? 0), JSON_UNESCAPED_SLASHES); ?>,
      deploymentKind: <?php echo json_encode($adminDeploymentKind ?? 'personal', JSON_UNESCAPED_SLASHES); ?>,
      branches: <?php echo json_encode($adminWorkspaceBranches ?? [], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?>,
      clientLogo: <?php echo json_encode([
        'rel' => $adminClientLogoRel,
        'url' => $adminClientLogoUrl,
        'kind' => $adminClientLogoKind,
        'mediaFrame' => $adminClientLogoFrame,
      ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?>
    };
  </script>
  <script>
    window.ANTARA_AUTH_TAB_SYNC_CFG = {
      listenLogin: <?php echo json_encode(!$user); ?>,
      listenLogout: <?php echo json_encode((bool)$user); ?>,
      loginUrl: <?php echo json_encode($logoutUrl, JSON_UNESCAPED_SLASHES); ?>,
      reloadOnRemoteLogin: <?php echo json_encode(!$user); ?>
    };
  </script>
  <script src="<?php echo htmlspecialchars(admin_asset_url('assets/auth/auth_tab_sync.js'), ENT_QUOTES); ?>" defer></script>
  <script src="<?php echo htmlspecialchars(admin_asset_url('assets/js/tooltips.js'), ENT_QUOTES); ?>" defer></script>
  <script src="<?php echo htmlspecialchars(admin_asset_url('assets/js/app-dialog.js'), ENT_QUOTES); ?>" defer></script>
  <script src="<?php echo htmlspecialchars(admin_asset_url('assets/auth/profile_image_sync.js'), ENT_QUOTES); ?>" defer></script>
  <script src="<?php echo htmlspecialchars(antara_vendor_asset_url(ANTARA_VENDOR_CROPPER_JS, $projectBase), ENT_QUOTES); ?>" defer></script>
  <script src="<?php echo htmlspecialchars(admin_asset_url('assets/auth/avatar_square_crop.js'), ENT_QUOTES); ?>" defer></script>
  <script src="<?php echo htmlspecialchars(admin_asset_url('assets/js/install_image_picker.js'), ENT_QUOTES); ?>" defer></script>
  <script src="<?php echo htmlspecialchars(admin_asset_url('assets/auth/admin.js'), ENT_QUOTES); ?>" defer></script>
  <?php require __DIR__ . '/_image_editor_dialog.php'; ?>
</body>
</html>
