All files / components/homepage TrustScoreSection.tsx

100% Statements 181/181
87.5% Branches 7/8
100% Functions 3/3
100% Lines 181/181

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 2301x                                     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   61x 61x 61x 61x 61x 61x   61x 61x 61x 61x 61x 61x 61x 61x 61x   61x 61x 61x 61x   61x 61x   61x 61x 61x   61x 61x 61x 61x 61x 61x 61x 61x 61x   61x   1x 61x 61x 61x 61x   61x 61x 61x 61x 61x 61x   61x 61x   61x   61x   61x 61x   61x 61x   61x     61x   61x 61x 305x 305x 305x 305x 305x 305x 305x   305x 305x   305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 61x 61x   61x 61x   61x 61x 61x 61x     61x 61x 61x 61x 61x 61x   61x 61x 61x 61x 61x 61x 61x 61x   61x 61x 61x   61x 61x 305x 305x 305x   305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 305x 61x 61x   61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x 61x   61x  
'use client';
 
import { motion, useMotionValue, useTransform, animate } from 'framer-motion';
import { useEffect, useState, useRef } from 'react';
import { useInView } from 'framer-motion';
import Link from 'next/link';
import {
  Shield,
  FileCheck,
  CheckCircle2,
  Calendar,
  Users,
  Clock,
  ArrowRight,
  TrendingUp,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
 
const trustComponents = [
  {
    icon: FileCheck,
    label: 'Proof Quality',
    weight: 30,
    description: 'Quality and authenticity of submitted proofs',
    color: 'bg-blue-500',
  },
  {
    icon: CheckCircle2,
    label: 'Verifications',
    weight: 25,
    description: 'Official verifications from registries and institutions',
    color: 'bg-green-500',
  },
  {
    icon: Calendar,
    label: 'Consistency',
    weight: 20,
    description: 'Regular updates and maintained credentials',
    color: 'bg-purple-500',
  },
  {
    icon: Users,
    label: 'Peer Recognition',
    weight: 15,
    description: 'Attestations from verified colleagues',
    color: 'bg-amber-500',
  },
  {
    icon: Clock,
    label: 'Tenure',
    weight: 10,
    description: 'Time as a verified member',
    color: 'bg-pink-500',
  },
];
 
function AnimatedCounter({ value, duration = 2 }: { value: number; duration?: number }) {
  const ref = useRef(null);
  const isInView = useInView(ref, { once: true });
  const count = useMotionValue(0);
  const rounded = useTransform(count, (latest) => Math.round(latest));
  const [displayValue, setDisplayValue] = useState(0);
 
  useEffect(() => {
    if (isInView) {
      const controls = animate(count, value, {
        duration,
        ease: 'easeOut',
      });
      return controls.stop;
    }
  }, [isInView, value, duration, count]);
 
  useEffect(() => {
    const unsubscribe = rounded.on('change', (v) => setDisplayValue(v));
    return unsubscribe;
  }, [rounded]);
 
  return <span ref={ref}>{displayValue}</span>;
}
 
function AnimatedProgressBar({ width, delay = 0 }: { width: number; delay?: number }) {
  const ref = useRef(null);
  const isInView = useInView(ref, { once: true });
 
  return (
    <div ref={ref} className="h-2 w-full overflow-hidden rounded-full bg-muted">
      <motion.div
        initial={{ width: 0 }}
        animate={isInView ? { width: `${width}%` } : { width: 0 }}
        transition={{ duration: 1, delay, ease: 'easeOut' }}
        className="h-full bg-primary"
      />
    </div>
  );
}
 
export function TrustScoreSection() {
  return (
    <section className="py-20 md:py-28">
      <div className="container">
        <div className="grid gap-12 lg:grid-cols-2 lg:gap-16">
          {/* Left side - Content */}
          <motion.div
            initial={{ opacity: 0, x: -30 }}
            whileInView={{ opacity: 1, x: 0 }}
            viewport={{ once: true, margin: '-100px' }}
            transition={{ duration: 0.6 }}
            className="flex flex-col justify-center"
          >
            <span className="mb-4 inline-flex w-fit items-center gap-2 rounded-full bg-primary/10 px-4 py-1.5 text-sm font-medium text-primary">
              <TrendingUp className="h-4 w-4" />
              Trust Score System
            </span>
 
            <h2 className="mb-4 text-3xl font-bold md:text-4xl lg:text-5xl">
              Build Trust with
              <span className="bg-gradient-to-r from-primary to-lime-500 bg-clip-text text-transparent">
                {' '}
                Verified Proof
              </span>
            </h2>
 
            <p className="mb-6 text-lg text-muted-foreground">
              Your trust score reflects the strength of your verified credentials. The more you
              verify, the higher your score and the more clients trust you.
            </p>
 
            <div className="mb-8 space-y-4">
              {trustComponents.map((component, index) => (
                <motion.div
                  key={component.label}
                  initial={{ opacity: 0, x: -20 }}
                  whileInView={{ opacity: 1, x: 0 }}
                  viewport={{ once: true }}
                  transition={{ delay: index * 0.1 }}
                  className="flex items-center gap-4"
                >
                  <div
                    className={`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg ${component.color}/10`}
                  >
                    <component.icon
                      className={`h-5 w-5 ${component.color.replace('bg-', 'text-')}`}
                    />
                  </div>
                  <div className="flex-1">
                    <div className="flex items-center justify-between">
                      <span className="font-medium">{component.label}</span>
                      <span className="text-sm text-muted-foreground">{component.weight}%</span>
                    </div>
                    <p className="text-xs text-muted-foreground">{component.description}</p>
                  </div>
                </motion.div>
              ))}
            </div>
 
            <Button className="group w-fit" asChild>
              <Link href="/login">
                Start Building Trust
                <ArrowRight className="ml-2 h-4 w-4 transition-transform group-hover:translate-x-1" />
              </Link>
            </Button>
          </motion.div>
 
          {/* Right side - Trust Score Preview */}
          <motion.div
            initial={{ opacity: 0, x: 30 }}
            whileInView={{ opacity: 1, x: 0 }}
            viewport={{ once: true, margin: '-100px' }}
            transition={{ duration: 0.6, delay: 0.2 }}
            className="flex items-center justify-center"
          >
            <div className="w-full max-w-md overflow-hidden rounded-3xl border bg-gradient-to-br from-background via-background to-muted/50 p-8 shadow-xl">
              <div className="mb-6 text-center">
                <div className="mb-2 text-sm text-muted-foreground">Your Trust Score</div>
                <div className="text-6xl font-bold">
                  <AnimatedCounter value={78} />
                </div>
                <Badge className="mt-2 bg-green-100 text-green-700">High Confidence</Badge>
              </div>
 
              <div className="mb-6">
                <AnimatedProgressBar width={78} delay={0.5} />
              </div>
 
              <div className="space-y-3">
                {trustComponents.map((component, index) => (
                  <div key={component.label} className="flex items-center gap-3">
                    <div
                      className={`flex h-8 w-8 shrink-0 items-center justify-center rounded ${component.color}/10`}
                    >
                      <component.icon
                        className={`h-4 w-4 ${component.color.replace('bg-', 'text-')}`}
                      />
                    </div>
                    <div className="flex-1">
                      <div className="flex items-center justify-between text-sm">
                        <span>{component.label}</span>
                        <span className="font-medium">{Math.round(component.weight * 0.78)}</span>
                      </div>
                      <div className="mt-1 h-1.5 w-full overflow-hidden rounded-full bg-muted">
                        <motion.div
                          initial={{ width: 0 }}
                          whileInView={{ width: `${component.weight * 0.78}%` }}
                          viewport={{ once: true }}
                          transition={{ duration: 0.8, delay: 0.8 + index * 0.1 }}
                          className={`h-full ${component.color}`}
                        />
                      </div>
                    </div>
                  </div>
                ))}
              </div>
 
              <div className="mt-6 rounded-lg bg-muted/50 p-4 text-center">
                <p className="text-sm text-muted-foreground">
                  <Shield className="mr-1 inline h-4 w-4 text-primary" />
                  Verified by{' '}
                  <span className="font-medium text-foreground">3 official sources</span>
                </p>
              </div>
            </div>
          </motion.div>
        </div>
      </div>
    </section>
  );
}