"use client";

import { usePathname } from "next/navigation";

/** Clears the auth cookie and returns to /login. Rendered only when auth is enabled. */
export function SignOut() {
  const pathname = usePathname();
  if (pathname === "/login") return null;

  async function signOut() {
    await fetch("/api/auth", { method: "DELETE" }).catch(() => {});
    window.location.assign("/login");
  }

  return (
    <button type="button" className="sign-out" onClick={signOut} aria-label="sign out">
      Sign out
    </button>
  );
}
