'use client' import { useAuth } from '@thedaviddias/auth' import { Button } from '@thedaviddias/design-system/button' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@thedaviddias/design-system/dialog' import { ArrowRight, Github, Heart, Users, X, Zap } from 'lucide-react' import Link from 'next/link' import { useEffect, useState } from 'react' interface SmartAuthPromptProps { trigger: 'favorite' | 'search' | 'browse-time' | 'engagement' onComplete?: () => void } type PromptContext = { title: string description: string icon: any benefits: string[] primaryCTA: { text: string href: string variant: 'default' | 'outline' } secondaryCTA: { text: string href: string variant: 'default' | 'outline' } } function getPromptContext(trigger: SmartAuthPromptProps['trigger']): PromptContext { const contexts: Record = { favorite: { title: 'Want to save this?', description: 'Create a free account to save your favorite AI documentation and access them from anywhere.', icon: Heart, benefits: ['Sync across devices', 'Never lose bookmarks', 'Quick access dashboard'], primaryCTA: { text: 'Quick Email Signup', href: '/auth/email-signup', variant: 'default' }, secondaryCTA: { text: 'Sign in with GitHub', href: '/login', variant: 'outline' } }, search: { title: 'Finding great resources?', description: 'Save your discoveries and get personalized recommendations based on your interests.', icon: Zap, benefits: ['Smart recommendations', 'Search history', 'Curated collections'], primaryCTA: { text: 'Start Saving Discoveries', href: '/auth/email-signup', variant: 'default' }, secondaryCTA: { text: 'GitHub Sign In', href: '/login', variant: 'outline' } }, 'browse-time': { title: 'Enjoying your exploration?', description: 'Join our community of developers building the future of AI documentation.', icon: Users, benefits: ['Community updates', 'Early access', 'Connect with builders'], primaryCTA: { text: 'Create Free Account', href: '/auth/email-signup', variant: 'default' }, secondaryCTA: { text: 'Sign in with GitHub', href: '/login', variant: 'outline' } }, engagement: { title: 'Ready to contribute?', description: 'Help grow the ecosystem by sharing your llms.txt or curating great resources.', icon: Github, benefits: ['Direct submissions', 'Contributor profile', 'Community recognition'], primaryCTA: { text: 'Connect GitHub', href: '/login', variant: 'default' }, secondaryCTA: { text: 'Email Signup First', href: '/auth/email-signup', variant: 'outline' } } } return contexts[trigger] } export function SmartAuthPrompt({ trigger, onComplete }: SmartAuthPromptProps) { const { user } = useAuth() const [isOpen, setIsOpen] = useState(false) const [, setShowCount] = useState(0) const context = getPromptContext(trigger) const IconComponent = context.icon useEffect(() => { if (user) return // Don't show if already authenticated // Get interaction counts from localStorage const interactionKey = `auth-prompt-${trigger}` const interactionCount = Number.parseInt(localStorage.getItem(interactionKey) || '0', 10) // Smart timing based on trigger type const shouldShow = () => { switch (trigger) { case 'favorite': return interactionCount === 0 // Show immediately on first favorite attempt case 'search': return interactionCount >= 2 // Show after 3rd search case 'browse-time': return interactionCount >= 5 // Show after browsing multiple pages case 'engagement': return interactionCount >= 3 // Show after several interactions default: return false } } if (shouldShow()) { setIsOpen(true) setShowCount(interactionCount + 1) } else { // Increment counter localStorage.setItem(interactionKey, String(interactionCount + 1)) } }, [trigger, user]) const handleClose = () => { setIsOpen(false) // Mark as dismissed for this session const dismissedKey = `auth-prompt-dismissed-${trigger}` localStorage.setItem(dismissedKey, Date.now().toString()) onComplete?.() } const handleCTAClick = () => { // Track conversion const conversionKey = `auth-prompt-conversion-${trigger}` localStorage.setItem(conversionKey, Date.now().toString()) onComplete?.() } if (!isOpen || user) return null return (
{context.title} {context.description}
{/* Benefits */}
{context.benefits.map((benefit, index) => (
{benefit}
))}
{/* CTA Buttons */}
{/* Skip option */}
) }