"use client";

import Link from "next/link";
import { useAuthModal } from "@/components/landing/auth-modal-context";
import type { AuthModalView } from "@/components/landing/auth-modal";
import type { ReactNode } from "react";

type AuthTriggerProps = {
  view?: AuthModalView;
  children: ReactNode;
  className?: string;
  onClick?: () => void;
};

export function AuthTrigger({
  view = "register",
  children,
  className,
  onClick,
}: AuthTriggerProps) {
  const { openAuth } = useAuthModal();
  const href = view === "login" ? "/?auth=login" : "/?auth=register";

  return (
    <Link
      href={href}
      className={className}
      onClick={(event) => {
        event.preventDefault();
        onClick?.();
        openAuth(view);
      }}
    >
      {children}
    </Link>
  );
}
