"use client";

import { useTranslation } from "react-i18next";

import Button from "@/components/ui/Button";
import SocialAuthButtons from "./SocialAuthButtons";
import type { SocialProfile } from "@/lib/auth/socialSignup";

/**
 * The end of the sign-up form: submit, the social sign-up pair and the link
 * across to login.
 *
 * The social buttons stash the form's current values as a prefill before
 * handing the tab to the provider, so a user who started typing and then
 * changed their mind about the method does not lose what they entered.
 */
export default function IndividualSubmitFooter({
  submitDisabled,
  submitLoading,
  onGoogle,
  onLogin,
}: {
  submitDisabled: boolean;
  submitLoading: boolean;
  /** Called with the profile decoded from the Google ID token. */
  onGoogle: (profile: SocialProfile) => void;
  onLogin: () => void;
}) {
  const { t } = useTranslation();

  return (
    <>
      <Button
        className="mx-auto mt-[25px]"
        variant="primary"
        size="medium"
        type="submit"
        disabled={submitDisabled}
        loading={submitLoading}
      >
        {t("COMMON.CREATEACCOUNT")}
      </Button>
      <div>
        <p className="font-semibold text-[18px] leading-[24.51px] pt-8 pb-8 text-primary-5 flex items-center w-full before:flex-1 before:border-t before:border-primary-5 before:mr-4 after:flex-1 after:border-t after:border-primary-5 after:ml-4 rtl:gap-[20px]">
          {t("COMMON.SIGNUPWITH")}
        </p>
      </div>
      <SocialAuthButtons
        onGoogle={onGoogle}
      />
      <p className="text-primary-5 text-center font-[400] text-[20px] leading-[27.24px] pt-[30px]">
        {t("COMMON.ALREADYHAVEACCOUNT")}{" "}
        {/* A real <button>, not a clickable <span>: this is the only way out
            of the sign-up form to login, and it was mouse-only. `type="button"`
            matters because this sits inside the form — without it the browser
            would treat it as a submit. */}
        <button
          type="button"
          onClick={onLogin}
          className="font-bold text-[20px] leading-[27.24px] tracking-[0px] text-primary-504 border-b-2 border-b-primary-504 cursor-pointer pb-1"
        >
          {t("COMMON.LOGIN")}
        </button>
      </p>
    </>
  );
}
