import React,{useState,useEffect,useRef} from 'react';
import{createRoot}from'react-dom/client';
import{motion,MotionConfig,useMotionValue,useSpring,useTransform,useReducedMotion,useScroll}from'framer-motion';
import{ArrowUpRight,ArrowDown,ArrowRight,Menu,X,MapPin,Layers,Users,TrendingUp,Mail,Globe,Phone,LayoutDashboard,User,Briefcase,GraduationCap,Settings,Eye,Save,Plus,Trash2,ChevronUp,ChevronDown,LogOut,ExternalLink,Check,Upload,Palette,PanelLeft,Loader2,Download,Cpu,Network,Code2,Printer,Copy,ChevronRight}from'lucide-react';
import{DEMO,api,getContent,saveContent,upload}from'./api';
import initial from './content.json';
import {applyTheme} from './theme';
import '../css/app.css';
import '../css/polish.css';
import ProjectDetails from './project-details';
import {syncMetadata} from './metadata';
const ext={target:'_blank',rel:'noopener noreferrer'};
const safeLink=(s)=>/^(https?:\/\/|mailto:|tel:|#|\/)/i.test(s||'')?s:'#';
const A=({href,children,...rest})=>{children} ;
const Reveal=({children,className=''})=>{children} ;
function TechPortrait({profile:p}){
const reduced=useReducedMotion();
const mx=useMotionValue(0),my=useMotionValue(0);
const rx=useSpring(useTransform(my,[-.5,.5],[7,-7]),{stiffness:110,damping:22});
const ry=useSpring(useTransform(mx,[-.5,.5],[-7,7]),{stiffness:110,damping:22});
const follow=e=>{if(reduced||e.pointerType!=='mouse')return;const r=e.currentTarget.getBoundingClientRect();mx.set((e.clientX-r.left)/r.width-.5);my.set((e.clientY-r.top)/r.height-.5)};
return
{mx.set(0);my.set(0)}}>
{p.initials} // PROFILE
{p.portraitCaption}
}
function SchoolMark({education:e}){return e.logo? :{e.institution.split(/[\s—-]+/).filter(Boolean).map(w=>w[0]).slice(0,3).join('')} }
const techLogos={'Next.js':'nextdotjs','React':'react','Laravel':'laravel','PHP':'php','MySQL':'mysql','Tailwind CSS':'tailwindcss','JavaScript':'javascript','HTML':'html5','CSS':'css'};
function TechnologyChips({technologies}){return {technologies.split(',').map(t=>t.trim()).filter(Boolean).map((t,i)=>
{techLogos[t]? :}{t} )}
}
function PdfDownload({data}){const[busy,setBusy]=useState(false),[error,setError]=useState('');return <>{setBusy(true);setError('');try{const{saveResumePdf}=await import('./resume-pdf');await saveResumePdf(data)}catch{setError('PDF download failed. Please use Print / Save PDF.')}finally{setBusy(false)}}}>{busy? :} {busy?'Preparing PDF…':data.copy.pdfButton} {error&&{error} }>}
function Resume({data}){const p=data.profile;return Professional profile {p.bio}
{data.sections.experience&&Experience {data.experience.map((e,i)=>
{e.role} {e.period} {e.organization} {e.description}
)} }{data.sections.education&&Education & credentials {data.education.map((e,i)=>
{e.degree} {e.honor} {e.institution} {e.specialization&&
{e.specialization}
}{(e.period||e.location)&&
{[e.period,e.location].filter(Boolean).join(' · ')}
}{e.details&&
{e.details}
}
)} }{data.sections.expertise&&Core expertise {data.expertise.map((e,i)=>
)}
}{data.sections.skills&&Software development skills {data.skills.map((g,i)=>
{g.title} {g.technologies}
)}
}{data.sections.projects&&Selected projects {data.projects.filter(p=>p.featured).map((p,i)=>
{p.title} {p.category} {p.description}
{p.url} )}
} }
function Portfolio({data,preview=false}){
const[menu,setMenu]=useState(false);const[selectedProject,setSelectedProject]=useState(null);const[copied,setCopied]=useState(false);const[copyError,setCopyError]=useState('');const[filter,setFilter]=useState('All projects');const p=data.profile,c=data.copy;
const projects=data.projects.filter(x=>x.featured&&(filter==='All projects'||x.category===filter));
useEffect(()=>syncMetadata(data),[data]);
useEffect(()=>{const escape=e=>{if(e.key==='Escape')setMenu(false)};window.addEventListener('keydown',escape);return()=>window.removeEventListener('keydown',escape)},[]);
useEffect(()=>{if(!copied)return;const timer=setTimeout(()=>setCopied(false),2500);return()=>clearTimeout(timer)},[copied]);
const {scrollYProgress}=useScroll();const progress=useSpring(scrollYProgress,{stiffness:100,damping:30});const reduced=useReducedMotion();
const nav=[['about',c.navAbout],['experience',c.navExperience],['projects',c.navProjects],['/resume',c.navResume]];
return
{preview&&
Draft preview window.close()}>Close preview
}
Skip to content
{menu&&
{nav.filter(([id])=>id.startsWith('/')||data.sections[id]).map(([id,label])=>setMenu(false)}>{label} )} }
{if(reduced||e.pointerType!=='mouse')return;const r=e.currentTarget.getBoundingClientRect();e.currentTarget.style.setProperty('--pointer-x',`${e.clientX-r.left}px`);e.currentTarget.style.setProperty('--pointer-y',`${e.clientY-r.top}px`)}}>
{p.eyebrow}
{p.headline.split('\n').map((v,i)=>{i>0&& }{v} )} {p.intro}
{p.role}{p.company}
{data.sections.about&&}
{data.sections.experience&&02 / {c.experienceLabel}
{c.experienceTitle} {c.experienceCaption}
{data.experience.map((e,i)=>
{e.period} {e.role} {e.organization}
{e.description}
)}
}
{data.sections.education&&03 / {c.educationLabel}
{c.educationTitle} {data.education.map((e,i)=>
{e.level&&{e.level} }{e.period&&{e.period} }
{e.honor&&
{e.honor} }
{e.institution} {e.degree&&e.degree!==e.level&&
{e.degree}
}{e.specialization&&
{e.specialization}
}{e.location&&
{e.location}
}{e.details&&
{e.details}
}{e.website&&
Visit school }
)}
}
{data.sections.expertise&&04 / {c.expertiseLabel}
{c.expertiseTitle} {data.expertise.map((e,i)=>{const Icon=[Layers,Users,TrendingUp][i%3];return
0{i+1}
{e.title} {e.description}
{e.tags.split(',').map(t=>{t.trim()} )}
})}
}
{data.sections.skills&&{c.skillsLabel}
{c.skillsTitle} {c.skillsIntro}
{data.skills.map((g,i)=>
{String(i+1).padStart(2,'0')} {g.title} {g.description}
)}
}
{data.sections.projects&&05 / {c.projectsLabel}
{c.projectsTitle} {c.projectsIntro}
setFilter('All projects')}>All projects {data.projects.filter(x=>x.featured).length.toString().padStart(2,'0')} setFilter(e.target.value)}>All projects {[...new Set(data.projects.filter(x=>x.featured).map(x=>x.category))].map(x=>{x} )}
{!projects.length&&
No projects in this category yet.
}
}
{data.sections.contact&&}
{selectedProject&&
setSelectedProject(null)}/>}
}
const tabs=[['overview','Overview',LayoutDashboard],['profile','Profile & hero',User],['copy','Section headings',PanelLeft],['expertise','Expertise',Layers],['skills','Development skills',Code2],['projects','Projects',Briefcase],['experience','Experience',TrendingUp],['education','Education',GraduationCap],['contact','Contact & socials',Mail],['appearance','Appearance & SEO',Palette],['sections','Section visibility',Eye]];
const schemas={profile:{name:'Full name',shortName:'Short name',initials:'Monogram',role:'Role',company:'Company',location:'Location',eyebrow:'Hero label',headline:'Hero headline|textarea',intro:'Introduction|textarea',bio:'Biography|textarea',portrait:'Portrait|image',portraitCaption:'Portrait caption',years:'Experience number',yearsLabel:'Experience label',primaryCta:'Primary button',secondaryCta:'Contact button',resumeCta:'Résumé button'},copy:Object.fromEntries(Object.keys(initial.copy).map(k=>[k,k.replace(/([A-Z])/g,' $1').replace(/^./,c=>c.toUpperCase())+(/Title|Intro|Text|Caption/.test(k)?'|textarea':'')])),expertise:{title:'Title',description:'Description|textarea',tags:'Tags (comma-separated)'},projects:{title:'Project name',category:'Category',description:'Card description|textarea',overview:'Project overview|textarea',focus:'Platform focus (one per line)|textarea',role:'Your role (optional)',contribution:'Your contribution (optional)|textarea',stack:'Project technology stack (optional)',results:'Results and impact (optional)|textarea',url:'Website|url',color:'Card background|color',image:'Project image (optional)|image',symbol:'Monogram',featured:'Visible on portfolio|checkbox'},experience:{role:'Role',organization:'Organization',period:'Period',description:'Description|textarea'},skills:{title:'Skill group',technologies:'Technologies (comma-separated)',description:'Description|textarea'},education:{level:'Education level',period:'Years attended',location:'Location',details:'Additional details|textarea',website:'School website|url',institution:'Institution',degree:'Degree',specialization:'Specialization',honor:'Honor or credential',logo:'Institution logo|image'},contact:{email:'Email|email',phone:'Phone',website:'Company website|url',booking:'Booking link|url',facebook:'Facebook|url',linkedin:'LinkedIn|url',github:'GitHub|url',whatsapp:'WhatsApp|url'},appearance:{socialImage:'Social sharing image|image',accent:'Accent color|color',background:'Page background|color',seoTitle:'Page title',seoDescription:'Search description|textarea'}};
function Field({name,spec,value,onChange,onError}){const[label,type='text']=spec.split('|');const[busy,setBusy]=useState(false);const changeImage=async e=>{if(!e.target.files[0])return;setBusy(true);try{onChange(await upload(e.target.files[0]))}catch(err){onError(err.message)}finally{setBusy(false)}};
if(type==='checkbox')return onChange(e.target.checked)}/>{label} ;
return {label} {type==='textarea'?
}
function Login({onLogin}){const[error,setError]=useState(''),[busy,setBusy]=useState(false);return }
function Dashboard(){const[authorized,setAuthorized]=useState(DEMO),[loading,setLoading]=useState(true),[data,setData]=useState(null),[tab,setTab]=useState('overview'),[dirty,setDirty]=useState(false),[busy,setBusy]=useState(false),[notice,setNotice]=useState(''),[error,setError]=useState(''),[revision,setRevision]=useState(0),[sidebar,setSidebar]=useState(false),[confirmDelete,setConfirmDelete]=useState(null);
async function load(){setLoading(true);try{const r=await getContent(true);setData(DEMO?r:r.data);setRevision(r.revision??0)}catch(e){setError(e.message);if(!DEMO)setAuthorized(false)}finally{setLoading(false)}}
useEffect(()=>{if(DEMO){load();return}api('admin/me',undefined,'GET').then(()=>{setAuthorized(true);load()}).catch(()=>{setAuthorized(false);setLoading(false)})},[]);
useEffect(()=>{const handler=e=>{if(dirty){e.preventDefault();e.returnValue=''}};window.addEventListener('beforeunload',handler);return()=>window.removeEventListener('beforeunload',handler)},[dirty]);
useEffect(()=>{if(!notice)return;const t=setTimeout(()=>setNotice(''),5000);return()=>clearTimeout(t)},[notice]);
const update=(section,key,value,index)=>{setData(d=>{const n=structuredClone(d);if(index!==undefined)n[section][index][key]=value;else n[section][key]=value;return n});setDirty(true);setError('')};
const persist=async publish=>{if(busy)return;setBusy(true);setError('');try{const res=await saveContent(data,publish,revision);setRevision(res.revision);setDirty(false);setNotice(publish?(DEMO?'Published in this browser.':'Portfolio published.'):'Draft saved.')}catch(e){setError(e.message)}finally{setBusy(false)}};
const preview=()=>{localStorage.setItem('portfolio-preview',JSON.stringify(data));window.open('/#/preview','_blank','noopener')};
const changeTab=id=>{setTab(id);setSidebar(false);setConfirmDelete(null);setError('')};
const addItem=()=>{const template=Object.fromEntries(Object.keys(schemas[tab]).map(k=>[k,k==='featured'?true:k==='color'?'#dbe2d5':'']));setData(d=>({...d,[tab]:[...d[tab],template]}));setDirty(true)};
const move=(index,delta)=>{setData(d=>{const arr=[...d[tab]];[arr[index],arr[index+delta]]=[arr[index+delta],arr[index]];return{...d,[tab]:arr}});setDirty(true)};
if(!authorized)return {setAuthorized(true);load()}}/>;
if(loading||!data)return Loading your workspace…{error&&
{error}
}
;
const current=tabs.find(t=>t[0]===tab);
return
{DEMO&&
PREVIEW MODE Changes are saved in this browser. The Laravel version saves securely to MySQL.
}
{notice&&
{notice}
}{error&&
{error}
}
{tab==='overview'?<>
YOUR PERSONAL SPACE
Make a lasting impression. Welcome back, {data.profile.shortName}. Your next chapter starts here.
{[[data.projects.length,'Projects',Briefcase,'projects'],[data.experience.length,'Experience entries',TrendingUp,'experience'],[Object.values(data.sections).filter(Boolean).length,'Visible sections',Eye,'sections']].map(([n,label,Icon,target])=>
changeTab(target)}>{String(n).padStart(2,'0')} {label} )}
Your portfolio changeTab('profile')}>Edit profile {data.profile.name} {data.profile.role}
{data.profile.company} {data.profile.location} Ready to tell your story
Open preview Make it your own A few thoughtful updates go a long way.
{[['profile','Refresh your introduction',User],['projects','Showcase your latest work',Briefcase],['appearance','Fine-tune your visual identity',Palette]].map(([id,label,Icon])=>
changeTab(id)}>{label} )}
Selected projects changeTab('projects')}>Manage projects {data.projects.slice(0,4).map((p,i)=>
changeTab('projects')}>{p.symbol} {p.title||'Untitled project'} {p.category}
{p.featured?'Visible':'Hidden'} )}
>:<>
CONTENT MANAGER
{current[1]} {tab==='sections'?'Choose what visitors see on your portfolio.':tab==='copy'?'Edit the words that guide visitors through your story.':'Keep your story current. Save a draft or publish when ready.'}
{Array.isArray(data[tab])&&
Add {tab==='expertise'?'expertise':tab==='education'?'credential':tab==='skills'?'skill group':tab==='experience'?'experience':'project'} }
{tab==='sections'?
{Object.entries(data.sections).map(([k,v])=>
{k[0].toUpperCase()+k.slice(1)} {v?'Visible on your portfolio':'Hidden from visitors'}
update('sections',k,e.target.checked)}/>)}
:Array.isArray(data[tab])?
{data[tab].map((item,i)=>
{String(i+1).padStart(2,'0')} {item.title||item.role||item.institution||'New entry'}move(i,-1)}> move(i,1)}> setConfirmDelete(i)}>
{confirmDelete===i&&
Remove this entry?{setData(d=>({...d,[tab]:d[tab].filter((_,j)=>j!==i)}));setDirty(true);setConfirmDelete(null)}}>Remove setConfirmDelete(null)}>Cancel
}
{Object.entries(schemas[tab]).map(([key,spec])=>update(tab,key,v,i)}/>)}
)}{!data[tab].length&&
No entries yet. Add your first one above.
}
:
{Object.entries(schemas[tab]).map(([key,spec])=>update(tab,key,v)}/>)}
}
>}
}
export function App(){const[route,setRoute]=useState(location.hash),[data,setData]=useState(null),[error,setError]=useState('');useEffect(()=>{const h=()=>setRoute(location.hash);addEventListener('hashchange',h);return()=>removeEventListener('hashchange',h)},[]);useEffect(()=>{if(data&&!route.startsWith('#/admin'))syncMetadata(data)},[data,route]);useEffect(()=>{if(route.startsWith('#/admin'))return;if(route==='#/preview'){try{const p=JSON.parse(localStorage.getItem('portfolio-preview'));if(p){setData(applyTheme(p));return}}catch{}}getContent().then(setData).catch(e=>setError(e.message))},[route]);return {route.startsWith('#/admin')||location.pathname.startsWith('/admin')? :data?route==='#/resume'?::{error||'Opening portfolio…'}
} }
if(import.meta.env.MODE!=='test')createRoot(document.getElementById('root')).render( );