const sessionCookie = "ruseemrooz_admin";
const getAdminUser = () => "admin";
const getAdminPassword = () => "admin123";
const getSessionSecret = () => "local-session";
const encodeToken = () => Buffer.from(`${getAdminUser()}:${getSessionSecret()}`).toString("base64url");
const isValidLogin = (username, password) => username === getAdminUser() && password === getAdminPassword();
const setAdminSession = (context) => {
  context.cookies.set(sessionCookie, encodeToken(), {
    path: "/",
    httpOnly: true,
    sameSite: "lax",
    secure: true,
    maxAge: 60 * 60 * 8
  });
};
const clearAdminSession = (context) => {
  context.cookies.delete(sessionCookie, { path: "/" });
};
const isAdminAuthenticated = (context) => context.cookies.get(sessionCookie)?.value === encodeToken();
const requireAdmin = (context) => {
  if (!isAdminAuthenticated(context)) {
    return new Response("Unauthorized", { status: 401 });
  }
  return null;
};

export { isValidLogin as a, clearAdminSession as c, isAdminAuthenticated as i, requireAdmin as r, setAdminSession as s };
