"use client"; import Link from "next/link"; import { createContext, type ReactNode, useCallback, useContext, useState } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { useIsAnonymous } from "./anonymous-mode"; interface LoginGateContextValue { gate: (feature: string) => void; } const LoginGateContext = createContext({ gate: () => {}, }); export function LoginGateProvider({ children }: { children: ReactNode }) { const isAnonymous = useIsAnonymous(); const [feature, setFeature] = useState(null); const gate = useCallback( (feat: string) => { if (isAnonymous) { setFeature(feat); } }, [isAnonymous] ); const close = () => setFeature(null); return ( {children} !open && close()}> Create a free account to {feature} Get 5 million tokens, save chat history, upload documents, use all AI tools, and connect 30+ integrations. ); } export function useLoginGate(): LoginGateContextValue { return useContext(LoginGateContext); } /** * Returns a click handler that triggers the login gate when anonymous, * or calls the original handler when authenticated. */ export function useGatedHandler(handler: (() => void) | undefined, feature: string): () => void { const { gate } = useLoginGate(); const isAnonymous = useIsAnonymous(); return useCallback(() => { if (isAnonymous) { gate(feature); } else { handler?.(); } }, [isAnonymous, gate, feature, handler]); }