'use client' import { useAuth } from '@thedaviddias/auth' import { Badge } from '@thedaviddias/design-system/badge' import { Button } from '@thedaviddias/design-system/button' import { Check, Eye, Github, Lock, Mail } from 'lucide-react' import Link from 'next/link' import { Card } from '@/components/ui/card' import { getMemberBadgeSync } from '@/lib/member-client-utils' export type AuthTier = 'anonymous' | 'email' | 'github' interface Feature { name: string description: string tiers: AuthTier[] } const FEATURES: Feature[] = [ { name: 'Browse & Search', description: 'Full access to all projects and documentation', tiers: ['anonymous', 'email', 'github'] }, { name: 'Local Favorites', description: 'Save favorites locally (device-only)', tiers: ['anonymous'] }, { name: 'Cloud Favorites', description: 'Sync favorites across all devices', tiers: ['email', 'github'] }, { name: 'Community Updates', description: 'Newsletter and platform updates', tiers: ['email', 'github'] }, { name: 'Direct Submission', description: 'Submit projects directly through the platform', tiers: ['github'] }, { name: 'Contributor Profile', description: 'Showcase your contributions and GitHub activity', tiers: ['github'] } ] /** * Returns display info (name, icon, color) for an auth tier */ function getTierInfo(tier: AuthTier) { switch (tier) { case 'anonymous': return { name: 'Browser', icon: Eye, color: 'bg-gray-100 text-gray-700', description: 'Full browsing access' } case 'email': return { name: 'Community Member', icon: Mail, color: 'bg-blue-100 text-blue-700', description: 'Email account with cloud sync' } case 'github': return { name: 'Contributor', icon: Github, color: 'bg-green-100 text-green-700', description: 'Full access with GitHub integration' } } } /** * Determines the current user's auth tier based on their metadata */ function getCurrentUserTier(user: any): AuthTier { if (!user) return 'anonymous' // Check if user has GitHub integration if (user.user_metadata?.github_username || user.user_metadata?.user_name) { return 'github' } // Has email but no GitHub if (user.email) { return 'email' } return 'anonymous' } /** * Checks whether the user has GitHub contributions */ function getUserContributions(user: any): boolean { // This would need to be determined based on actual contribution data // For now, we'll assume GitHub users might be contributors const tier = getCurrentUserTier(user) return tier === 'github' // This is a simplified assumption } interface AuthTierIndicatorProps { showUpgrade?: boolean compact?: boolean } /** * Displays the user's current auth tier with feature comparison and upgrade options */ export function AuthTierIndicator({ showUpgrade = true, compact = false }: AuthTierIndicatorProps) { const { user } = useAuth() const currentTier = getCurrentUserTier(user) const tierInfo = getTierInfo(currentTier) const IconComponent = tierInfo.icon if (compact) { // Use the same badge system as member cards const hasContributions = getUserContributions(user) const memberBadge = getMemberBadgeSync(hasContributions) return (
{tierInfo.description}
{feature.description}