"use client";

import { signOut } from "next-auth/react";

export function LogoutButton({ label }: { label: string }) {
  const handleLogout = async () => {
    const res = await fetch("/api/auth/logout");
    const { logoutUrl } = await res.json();
    await signOut({ redirect: false });
    window.location.href = logoutUrl;
  };

  return (
    <button type="button" onClick={handleLogout} className="dropdown-item">
      <i className="ph-sign-out me-2"></i>
      {label}
    </button>
  );
}
