
import { api } from "./api.js";

export async function loadSession() {
  const user = await api("modules/auth/me.php");
  const features = await api("modules/auth/features.php");

  window.currentUser = user;
  window.permissions = features.permissions || {};
  window.modules = features.modules || {};
}

function saveSession(data) {
  localStorage.setItem("auth_token", data.token);
  localStorage.setItem("user", JSON.stringify(data.user));
  localStorage.setItem("permissions", JSON.stringify(data.user.permissions || []));
}

function getPermissions() {
  return JSON.parse(localStorage.getItem("permissions") || "[]");
}
