import React from 'react'; import { useWorkerProfile } from '@/lib/krowHooks'; import { getTalentScore, getScoreBand, getGrowth } from '@/lib/talentHome'; import { ShieldCheck, Smartphone, Image as ImageIcon, QrCode, Sparkles } from 'lucide-react'; import { toast } from 'react-hot-toast'; import { Image } from '@/components/ui/image'; const clamp = (n, min = 0, max = 100) => Math.max(min, Math.min(max, Math.round(Number(n) || 0))); const toFICO = (s) => 300 + Math.round((clamp(s) / 100) * 550); function buildVCard(profile) { const name = profile.full_name || 'KROW Talent'; const [first, ...rest] = name.split(' '); const last = rest.join(' '); const lines = [ 'BEGIN:VCARD', 'VERSION:3.0', `N:${last};${first};;;`, `FN:${name}`, profile.current_position ? `TITLE:${profile.current_position}` : '', profile.phone ? `TEL;TYPE=CELL:${profile.phone}` : '', profile.email ? `EMAIL:${profile.email}` : '', `URL:https://krow.app/me`, `NOTE:KROW ID ${(profile.id || '').slice(-6).toUpperCase()}`, 'END:VCARD', ].filter(Boolean); return lines.join('\n'); } function download(filename, content, type) { const blob = new Blob([content], { type }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; a.click(); URL.revokeObjectURL(url); } export default function KrowIdPreview() { const { data: profile, isLoading } = useWorkerProfile(); if (isLoading || !profile) { return
Loading KROW ID…
; } const score = getTalentScore(profile); const band = getScoreBand(score); const growth = getGrowth(profile); const fico = toFICO(score); const shortId = (profile.id || '').slice(-6).toUpperCase(); const name = profile.full_name || 'KROW Talent'; const title = profile.current_position || profile.desired_position || 'Open to work'; const initials = name.split(' ').map(p => p[0]).slice(0, 2).join('').toUpperCase(); const vcard = buildVCard(profile); const qrSrc = `https://api.qrserver.com/v1/create-qr-code/?margin=0&size=120x120&data=${encodeURIComponent(vcard)}`; const addToContacts = () => { download(`${name.replace(/\s+/g, '_')}.vcf`, vcard, 'text/vcard'); toast.success('Contact file downloaded.'); }; return (
{/* depth layers */}
{/* front pass */}
{/* header row */}
{profile.selfie_url ? ( {name} ) : ( {initials} )}

KROW ID · {shortId}

{name}

{title}

{/* score + factors row */}

{fico}

{band.label}

↑ +{growth} mo

{[ ['Reliability', clamp(profile.reliability_score)], ['Attendance', clamp(profile.attendance_score ?? 100)], ['Performance', clamp(profile.performance_score)], ['XP', Number(profile.xp) || 0], ].map(([label, value]) => ( {label} {value} ))}
{/* footer: QR + actions */}
KROW Identity QR

Scan to share your verified KROW Identity

); }