import { isSigninEnabledForProvider } from '@documenso/lib/constants/auth';
import { msg } from '@lingui/core/macro';
import { Trans } from '@lingui/react/macro';
import { Link, redirect } from 'react-router';

import { ForgotPasswordForm } from '~/components/forms/forgot-password';
import { appMetaTags } from '~/utils/meta';

export function meta() {
  return appMetaTags(msg`Forgot Password`);
}

export async function loader() {
  if (!isSigninEnabledForProvider('email')) {
    throw redirect('/signin');
  }

  return null;
}

export default function ForgotPasswordPage() {
  return (
    <div className="w-full max-w-lg sm:px-4">
      <div className="w-full">
        <h1 className="font-semibold text-3xl">
          <Trans>Forgot your password?</Trans>
        </h1>

        <p className="mt-2 text-muted-foreground text-sm">
          <Trans>
            No worries, it happens! Enter your email and we'll email you a special link to reset your password.
          </Trans>
        </p>

        <ForgotPasswordForm className="mt-4" />

        <p className="mt-6 text-center text-muted-foreground text-sm">
          <Trans>
            Remembered your password?{' '}
            <Link to="/signin" className="text-primary duration-200 hover:opacity-70">
              Sign In
            </Link>
          </Trans>
        </p>
      </div>
    </div>
  );
}
