
import * as ActionIcons from '@/components/Icons';
import { redirect } from 'next/navigation';
import { isPortalRole, me } from '@/lib/api';
import { AuthShell } from '@/components/AuthShell';
import { ChangePasswordForm } from '@/components/AccountForms';
import { logout } from '../actions';

export const metadata = { title: 'Choose a new password' };
export const dynamic = 'force-dynamic';

/** Shown when an admin forced a reset or the owner was bootstrapped with a one-time password */
export default async function ForcedPasswordChange() {
  const user = await me();
  const home = isPortalRole(user.role) ? '/portal' : '/';
  if (!user.mustChangePassword) redirect(home);
  return (
    <AuthShell title="Choose a new password" description="Your account requires a new password before you can continue." backToLogin={false}>
      <ChangePasswordForm requireCode={false} back={home} />
      <form action={logout} className="mt-4">
        <button className="btn btn-ghost btn-sm w-full"><ActionIcons.LogOutIcon />Sign out instead</button>
      </form>
    </AuthShell>
  );
}
