1+ 'use client'
2+
3+ import React , { useState } from 'react'
4+ import { motion , AnimatePresence } from 'framer-motion'
5+ import { clinicalTrialCostData , TOTAL_CURRENT_COST , TOTAL_NEW_COST } from '@/app/dfda/components/cost-savings-data'
6+ import type { CostItem } from '@/app/dfda/cost-savings'
7+ import { ChevronDown , ChevronUp } from 'lucide-react'
8+
9+ export default function CostSavingsTable ( ) {
10+ const [ expandedItem , setExpandedItem ] = useState < string | null > ( null )
11+
12+ const formatCurrency = ( amount : number ) => {
13+ return new Intl . NumberFormat ( 'en-US' , {
14+ style : 'currency' ,
15+ currency : 'USD' ,
16+ maximumFractionDigits : 0
17+ } ) . format ( amount )
18+ }
19+
20+ const calculateSavings = ( current : number , new_ : number ) => {
21+ return ( ( current - new_ ) / current * 100 ) . toFixed ( 1 )
22+ }
23+
24+ const DetailPanel = ( { item } : { item : CostItem } ) => (
25+ < motion . div
26+ initial = { { height : 0 , opacity : 0 } }
27+ animate = { { height : 'auto' , opacity : 1 } }
28+ exit = { { height : 0 , opacity : 0 } }
29+ transition = { { duration : 0.3 } }
30+ className = "overflow-hidden bg-gray-50 px-4 py-6"
31+ >
32+ < div className = "grid gap-6 md:grid-cols-3" >
33+ < div className = "rounded-xl border-2 border-black bg-yellow-100 p-4" >
34+ < h4 className = "mb-2 font-black" > Current Process 📋</ h4 >
35+ < p > { item . currentExplanation } </ p >
36+ < p className = "mt-2 font-mono font-bold text-gray-700" >
37+ Cost: { formatCurrency ( item . currentCost ) }
38+ </ p >
39+ </ div >
40+
41+ < div className = "rounded-xl border-2 border-black bg-green-100 p-4" >
42+ < h4 className = "mb-2 font-black" > Cost Reduction Strategy 📉</ h4 >
43+ < p > { item . reductionExplanation } </ p >
44+ < p className = "mt-2 font-mono font-bold text-gray-700" >
45+ New Cost: { formatCurrency ( item . newCost ) }
46+ </ p >
47+ </ div >
48+
49+ < div className = "rounded-xl border-2 border-black bg-blue-100 p-4" >
50+ < h4 className = "mb-2 font-black" > Remaining Expenses 💡</ h4 >
51+ < p > { item . remainingExplanation } </ p >
52+ < p className = "mt-2 font-mono font-bold text-gray-700" >
53+ Savings: { calculateSavings ( item . currentCost , item . newCost ) } %
54+ </ p >
55+ </ div >
56+ </ div >
57+ </ motion . div >
58+ )
59+
60+ return (
61+ < div className = "relative overflow-hidden rounded-xl border-4 border-black bg-white p-6 shadow-[8px_8px_0px_0px_rgba(0,0,0,1)]" >
62+ < motion . h2
63+ className = "mb-6 text-2xl md:text-4xl font-black uppercase"
64+ initial = { { opacity : 0 , y : - 20 } }
65+ animate = { { opacity : 1 , y : 0 } }
66+ >
67+ Clinical Trial Cost Savings 💰
68+ </ motion . h2 >
69+
70+ < div className = "-mx-6 sm:mx-0" >
71+ < div className = "min-w-full inline-block align-middle" >
72+ < div className = "overflow-x-auto" >
73+ < table className = "min-w-full border-collapse" >
74+ < thead >
75+ < tr className = "border-b-4 border-black bg-yellow-300" >
76+ < th className = "p-2 sm:p-4 text-left font-black" > Cost Item</ th >
77+ < th className = "p-2 sm:p-4 text-right font-black hidden sm:table-cell" > Current Cost</ th >
78+ < th className = "p-2 sm:p-4 text-right font-black hidden sm:table-cell" > New Cost</ th >
79+ < th className = "p-2 sm:p-4 text-right font-black" > Savings</ th >
80+ </ tr >
81+ </ thead >
82+ < tbody >
83+ { clinicalTrialCostData . map ( ( item , index ) => (
84+ < React . Fragment key = { item . name } >
85+ < motion . tr
86+ className = { `cursor-pointer border-b-2 border-black hover:bg-gray-50 ${
87+ expandedItem === item . name ? 'bg-gray-50' : ''
88+ } `}
89+ initial = { { opacity : 0 , x : - 20 } }
90+ animate = { { opacity : 1 , x : 0 } }
91+ transition = { { delay : index * 0.1 } }
92+ onClick = { ( ) => setExpandedItem ( expandedItem === item . name ? null : item . name ) }
93+ >
94+ < td className = "p-2 sm:p-4 font-bold" >
95+ < div className = "flex items-center gap-2" >
96+ { item . emoji } { item . name }
97+ { expandedItem === item . name ? (
98+ < ChevronUp className = "h-4 w-4" />
99+ ) : (
100+ < ChevronDown className = "h-4 w-4" />
101+ ) }
102+ </ div >
103+ < div className = "mt-1 text-sm text-gray-600 sm:hidden" >
104+ { formatCurrency ( item . currentCost ) } → { formatCurrency ( item . newCost ) }
105+ </ div >
106+ </ td >
107+ < td className = "p-2 sm:p-4 text-right font-mono hidden sm:table-cell" > { formatCurrency ( item . currentCost ) } </ td >
108+ < td className = "p-2 sm:p-4 text-right font-mono hidden sm:table-cell" > { formatCurrency ( item . newCost ) } </ td >
109+ < td className = "p-2 sm:p-4 text-right" >
110+ < span className = "rounded-full bg-green-400 px-2 sm:px-3 py-1 font-bold text-sm sm:text-base" >
111+ { calculateSavings ( item . currentCost , item . newCost ) } %
112+ </ span >
113+ </ td >
114+ </ motion . tr >
115+ < tr >
116+ < td colSpan = { 4 } className = "p-0" >
117+ < AnimatePresence >
118+ { expandedItem === item . name && < DetailPanel item = { item } /> }
119+ </ AnimatePresence >
120+ </ td >
121+ </ tr >
122+ </ React . Fragment >
123+ ) ) }
124+ < motion . tr
125+ className = "border-t-4 border-black bg-green-300 font-black"
126+ initial = { { opacity : 0 , y : 20 } }
127+ animate = { { opacity : 1 , y : 0 } }
128+ transition = { { delay : clinicalTrialCostData . length * 0.1 } }
129+ >
130+ < td className = "p-2 sm:p-4" >
131+ TOTAL SAVINGS 🎉
132+ < div className = "text-sm mt-1 sm:hidden" >
133+ { formatCurrency ( TOTAL_CURRENT_COST ) } → { formatCurrency ( TOTAL_NEW_COST ) }
134+ </ div >
135+ </ td >
136+ < td className = "p-2 sm:p-4 text-right hidden sm:table-cell" > { formatCurrency ( TOTAL_CURRENT_COST ) } </ td >
137+ < td className = "p-2 sm:p-4 text-right hidden sm:table-cell" > { formatCurrency ( TOTAL_NEW_COST ) } </ td >
138+ < td className = "p-2 sm:p-4 text-right" >
139+ < span className = "rounded-full bg-black px-2 sm:px-3 py-1 text-white text-sm sm:text-base" >
140+ 95.7%
141+ </ span >
142+ </ td >
143+ </ motion . tr >
144+ </ tbody >
145+ </ table >
146+ </ div >
147+ </ div >
148+ </ div >
149+
150+ < div className = "mt-6 rounded-xl border-2 border-black bg-blue-100 p-4" >
151+ < h3 className = "mb-2 font-black" > 💡 Key Benefits</ h3 >
152+ < ul className = "list-inside list-disc space-y-2" >
153+ < li > Automated processes reduce manual labor costs</ li >
154+ < li > AI-driven analysis improves efficiency and accuracy</ li >
155+ < li > Decentralized approach eliminates site-related expenses</ li >
156+ < li > Blockchain technology ensures data integrity</ li >
157+ </ ul >
158+ </ div >
159+ </ div >
160+ )
161+ }
0 commit comments