import { useState, useRef, useCallback } from "react";
const GROQ_KEY = "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";
const SECTORS = [
{ id:"avocat", label:"Avocat / Cabinet juridique", icon:"⚖️" },
{ id:"immobilier", label:"Immobilier / Mandataire", icon:"🏠" },
{ id:"comptable", label:"Expert-comptable", icon:"📊" },
{ id:"conseil", label:"Conseil / Stratégie", icon:"💼" },
{ id:"opticien", label:"Opticien / Santé", icon:"👓" },
{ id:"medical", label:"Médical / Paramédical", icon:"🩺" },
{ id:"architecte", label:"Architecte / Design", icon:"📐" },
{ id:"restaurant", label:"Restaurant / Traiteur", icon:"🍽️" },
{ id:"artisan", label:"Artisan / BTP", icon:"🔨" },
{ id:"beaute", label:"Beauté / Bien-être", icon:"✨" },
{ id:"formation", label:"Formation / Coaching", icon:"🎓" },
{ id:"autre", label:"Autre secteur", icon:"🏢" },
];
const PALETTES = [
{ id:"navy", label:"Marine & Or", primary:"#1a2744", accent:"#c9a84c", bg:"#f8f6f1" },
{ id:"forest", label:"Forêt & Crème", primary:"#2d4a3e", accent:"#a8875a", bg:"#faf9f6" },
{ id:"burgundy", label:"Bordeaux & Doré", primary:"#5c1a2a", accent:"#d4a953", bg:"#fdf8f5" },
{ id:"slate", label:"Ardoise & Bleu", primary:"#2c3e50", accent:"#3498db", bg:"#f5f7fa" },
{ id:"charcoal", label:"Charbon & Cuivre", primary:"#1a1a2e", accent:"#c87941", bg:"#f9f7f5" },
{ id:"ocean", label:"Océan & Sable", primary:"#0d3b66", accent:"#e8a87c", bg:"#fafbf9" },
{ id:"modern", label:"Noir & Rouge", primary:"#111111", accent:"#e63946", bg:"#ffffff" },
{ id:"terra", label:"Terracotta & Olive", primary:"#7a3b2e", accent:"#6B8E23", bg:"#FFF8F0" },
];
const FONTS = [
{ id:"classic", label:"Classique élégant", heading:"'Playfair Display',serif", body:"'Source Sans 3',sans-serif", imp:"Playfair+Display:wght@400;600;700;800&family=Source+Sans+3:wght@300;400;600;700" },
{ id:"modern", label:"Moderne épuré", heading:"'DM Sans',sans-serif", body:"'DM Sans',sans-serif", imp:"DM+Sans:wght@300;400;500;600;700" },
{ id:"editorial", label:"Éditorial chic", heading:"'Cormorant Garamond',serif", body:"'Montserrat',sans-serif", imp:"Cormorant+Garamond:wght@400;500;600;700&family=Montserrat:wght@300;400;500;600;700" },
{ id:"bold", label:"Audacieux pro", heading:"'Sora',sans-serif", body:"'Work Sans',sans-serif", imp:"Sora:wght@300;400;600;700;800&family=Work+Sans:wght@300;400;500;600" },
{ id:"luxury", label:"Luxe raffiné", heading:"'Libre Baskerville',serif", body:"'Karla',sans-serif", imp:"Libre+Baskerville:wght@400;700&family=Karla:wght@300;400;500;600;700" },
];
const emptyForm = () => ({
businessName:"", tagline:"", sector:"", sectorCustom:"", description:"",
services:["","","",""], serviceDescs:["","","",""],
ownerName:"", ownerTitle:"", ownerBio:"",
phone:"", email:"", address:"", hours:"",
socialFb:"", socialIg:"", socialLi:"", socialG:"",
testimonials:[{name:"",text:""},{name:"",text:""},{name:"",text:""}],
palette:"navy", fonts:"classic", ctaText:"Prendre rendez-vous", ctaUrl:"#contact",
stats:[{n:"",l:""},{n:"",l:""},{n:"",l:""}],
imgLogo:null, imgHero:null, imgOwner:null, imgSvc:[null,null,null,null],
articles:[{title:"",date:"",excerpt:"",img:null,content:""},{title:"",date:"",excerpt:"",img:null,content:""},{title:"",date:"",excerpt:"",img:null,content:""},{title:"",date:"",excerpt:"",img:null,content:""},{title:"",date:"",excerpt:"",img:null,content:""},{title:"",date:"",excerpt:"",img:null,content:""}],
});
/* ── GROQ ── */
async function callGroq(prompt) {
try {
const r = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method:"POST", headers:{"Content-Type":"application/json",Authorization:`Bearer ${GROQ_KEY}`},
body: JSON.stringify({model:"llama-3.3-70b-versatile",messages:[{role:"user",content:prompt}],temperature:0.7,max_tokens:2000}),
});
const d = await r.json();
const txt = d.choices?.[0]?.message?.content||"";
const c = txt.replace(/```json|```/g,"").trim();
const s = c.indexOf("{"), e = c.lastIndexOf("}");
if(s===-1) return null;
return JSON.parse(c.slice(s,e+1));
} catch(e){console.error(e);return null;}
}
async function aiEnhance(f) {
const sec = f.sector==="autre"?f.sectorCustom:SECTORS.find(s=>s.id===f.sector)?.label||"pro";
return callGroq(`Tu es un copywriter web français expert. Client: ${f.businessName} | Secteur: ${sec} | Tagline: ${f.tagline||"?"} | Desc: ${f.description||"?"} | Dirigeant: ${f.ownerName||"?"} (${f.ownerTitle||"?"}) | Services: ${f.services.filter(Boolean).join(", ")||"?"}
JSON uniquement:
{"tagline":"max 15 mots, un mot entre *astérisques*","description":"2-3 phrases max 250 car","ownerBio":"3-4 phrases bio (vide si pas de nom)","serviceDescs":["desc1","desc2","desc3","desc4"],"stats":[{"number":"25+","label":"années"},{"number":"500+","label":"clients"},{"number":"98%","label":"satisfaction"}]}`);
}
async function aiArticles(f) {
const sec = f.sector==="autre"?f.sectorCustom:SECTORS.find(s=>s.id===f.sector)?.label||"pro";
return callGroq(`Rédacteur web expert. 6 articles blog style Artur'in pour "${f.businessName}" (${sec}). Informatifs, SEO, conseil client.
JSON uniquement:
{"articles":[{"title":"T1","date":"2025-01-15","excerpt":"Résumé","content":"150-200 mots, paragraphes par \\n\\n"},{"title":"T2","date":"2025-02-03","excerpt":"...","content":"..."},{"title":"T3","date":"2025-02-20","excerpt":"...","content":"..."},{"title":"T4","date":"2025-03-10","excerpt":"...","content":"..."},{"title":"T5","date":"2025-03-28","excerpt":"...","content":"..."},{"title":"T6","date":"2025-04-14","excerpt":"...","content":"..."}]}`);
}
/* ── IMAGE ── */
function toB64(file){return new Promise(r=>{const fr=new FileReader();fr.onload=()=>r(fr.result);fr.readAsDataURL(file)})}
function ImgUp({label,value,onChange,w=200,h=140}){
const ref=useRef(null);
return
{label&&
{label}}
ref.current?.click()} style={{width:w,height:h,borderRadius:8,border:"2px dashed #ccc",background:value?`url(${value}) center/cover`:"#f5f5f5",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",position:"relative",overflow:"hidden"}}>
{!value&&📷 Cliquer}
{value&&}
{const file=e.target.files?.[0];if(file)onChange(await toB64(file))}} style={{display:"none"}} />
;
}
/* ── FIELD ── */
function Fld({label,sub,value,onChange,ph,ta,half,req}){
const T=ta?"textarea":"input";
return
{sub&&{sub}}
onChange(e.target.value)} placeholder={ph} rows={ta?3:undefined}
style={{width:"100%",padding:"8px 11px",border:"1.5px solid #ddd",borderRadius:6,fontSize:13,fontFamily:"inherit",resize:ta?"vertical":undefined,outline:"none",background:"#fafafa",boxSizing:"border-box"}}
onFocus={e=>e.target.style.borderColor="#1a2744"} onBlur={e=>e.target.style.borderColor="#ddd"} />
;
}
/* ── STEPPER ── */
function Steps({cur,labels}){
return ;
}
/* ── HTML GEN ── */
function genHTML(f){
const P=PALETTES.find(p=>p.id===f.palette)||PALETTES[0];
const FN=FONTS.find(x=>x.id===f.fonts)||FONTS[0];
const sec=f.sector==="autre"?f.sectorCustom:SECTORS.find(s=>s.id===f.sector)?.label||"";
const svcs=f.services.filter(s=>s.trim());
const testos=f.testimonials.filter(t=>t.name&&t.text);
const stats=f.stats.filter(s=>s.n&&s.l);
const arts=f.articles.filter(a=>a.title&&a.excerpt);
const nav=["Accueil",svcs.length&&"Services",f.ownerName&&"À propos",testos.length&&"Témoignages",arts.length&&"Actualités","Contact"].filter(Boolean);
const soc=[f.socialFb&&`Facebook`,f.socialIg&&`Instagram`,f.socialLi&&`LinkedIn`,f.socialG&&`Google`].filter(Boolean);
const ic=["◆","◇","▸","●"];
const hs=f.imgHero?`background:linear-gradient(rgba(0,0,0,.52),rgba(0,0,0,.52)),url('${f.imgHero}') center/cover no-repeat`:`background:linear-gradient(135deg,${P.primary} 0%,color-mix(in srgb,${P.primary} 75%,#000) 100%)`;
const logo=f.imgLogo?`
`:`${f.businessName}`;
const sl=n=>n.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f\s]/g,'');
const fmtD=d=>{try{return new Date(d+'T00:00:00').toLocaleDateString('fr-FR',{day:'numeric',month:'long',year:'numeric'})}catch(e){return d}};
return `
${f.businessName} | ${f.tagline||sec}
${f.imgHero?``:''}
${nav.map(n=>'
'+n+'').join('')}
${sec}
${(f.tagline||f.businessName).replace(/\*([^*]+)\*/g,'$1')}
${f.description||''}
${f.ctaText}
${stats.length?''+stats.map(s=>'
').join('')+'
':''}
${svcs.length?'Nos services
Comment puis-je vous accompagner ?
Des solutions sur-mesure adaptées à vos besoins.
'+svcs.map((s,i)=>'
'+(f.imgSvc[i]?'

':'
'+ic[i%4]+'
')+'
'+s+'
'+(f.serviceDescs[i]||'Un accompagnement personnalisé.')+'
').join('')+'
':''}
${f.ownerName?''+(f.imgOwner?'

':'
'+f.ownerName.split(' ').map(n=>n[0]).join('').toUpperCase()+'
')+'
À propos
'+f.ownerName+'
'+(f.ownerTitle||sec)+''+(f.ownerBio||'')+'
'+(f.ownerBio?'
"Mon engagement : un accompagnement humain et sur-mesure pour chacun de mes clients."
':'')+'
':''}
${testos.length?'Témoignages
Ce que disent nos clients
La satisfaction de nos clients est notre meilleure carte de visite.
'+testos.map(t=>'
★★★★★
"'+t.text+'"
— '+t.name+'
').join('')+'
':''}
${arts.length?'Actualités
Nos derniers articles
Retrouvez nos conseils et notre expertise.
'+arts.map((a,i)=>'
'+(a.img?'

':'
')+'
').join('')+'
\n'+arts.map((a,i)=>''+a.title+'
'+fmtD(a.date)+'
'+(a.img?'

':'')+'
'+(a.content||a.excerpt).split(/\n\n|\n/).filter(p=>p.trim()).map(p=>'
'+p+'
').join('')+'
').join('\n'):''}
`;
}
/* ── MAIN ── */
export default function App(){
const [f,setF]=useState(emptyForm);
const [step,setStep]=useState(0);
const [prev,setPrev]=useState(false);
const [aiL,setAiL]=useState(false);
const [artL,setArtL]=useState(false);
const [aiOk,setAiOk]=useState(false);
const [artOk,setArtOk]=useState(false);
const [toast,setToast]=useState("");
const u=useCallback((k,v)=>setF(p=>({...p,[k]:v})),[]);
const uA=useCallback((k,i,v)=>setF(p=>{const a=[...p[k]];a[i]=v;return{...p,[k]:a}}),[]);
const uT=useCallback((i,k,v)=>setF(p=>{const a=[...p.testimonials];a[i]={...a[i],[k]:v};return{...p,testimonials:a}}),[]);
const uS=useCallback((i,k,v)=>setF(p=>{const a=[...p.stats];a[i]={...a[i],[k]:v};return{...p,stats:a}}),[]);
const uR=useCallback((i,k,v)=>setF(p=>{const a=[...p.articles];a[i]={...a[i],[k]:v};return{...p,articles:a}}),[]);
const uSI=useCallback((i,v)=>setF(p=>{const a=[...p.imgSvc];a[i]=v;return{...p,imgSvc:a}}),[]);
const msg=m=>{setToast(m);setTimeout(()=>setToast(""),3000)};
const doAI=async()=>{
setAiL(true);
const r=await aiEnhance(f);
if(r){setF(p=>({...p,tagline:r.tagline||p.tagline,description:r.description||p.description,ownerBio:r.ownerBio||p.ownerBio,serviceDescs:r.serviceDescs?.length?r.serviceDescs:p.serviceDescs,stats:r.stats?.length?r.stats.map(s=>({n:s.number||s.n,l:s.label||s.l})):p.stats}));setAiOk(true);msg("✅ Textes enrichis !")}
else msg("❌ Erreur — réessayez");
setAiL(false);
};
const doArt=async()=>{
setArtL(true);
const r=await aiArticles(f);
if(r?.articles){setF(p=>({...p,articles:r.articles.map((a,i)=>({...p.articles[i],title:a.title,date:a.date,excerpt:a.excerpt,content:a.content}))}));setArtOk(true);msg("✅ 6 articles générés !")}
else msg("❌ Erreur — réessayez");
setArtL(false);
};
const dl=()=>{const h=genHTML(f);const b=new Blob([h],{type:"text/html"});const u=URL.createObjectURL(b);const a=document.createElement("a");a.href=u;a.download=`${f.businessName.toLowerCase().replace(/[^a-z0-9]/g,"-")||"site"}.html`;a.click();URL.revokeObjectURL(u)};
const ST=["Identité","Images","Services","À propos","Avis","Contact","Actu","Design"];
const T=toast?{toast}
:null;
const btnS={padding:"7px 16px",borderRadius:5,cursor:"pointer",fontSize:12,border:"none",fontFamily:"inherit"};
if(prev) return
🌐 {f.businessName}
{T}
;
const ok=f.businessName.trim();
const box={marginBottom:14,padding:16,background:"#fff",borderRadius:10,border:"1px solid #eee"};
const lbl={fontSize:11,fontWeight:600,color:"#bbb",marginBottom:8,textTransform:"uppercase",letterSpacing:1};
const aiBtn=(loading,done,onClick,text,doneText)=>;
return
✦ Générateur de Site Vitrine Pro
Formulaire → IA Groq → Site complet avec Actualités Artur'in
{step===0&&
Identité
Les bases de votre activité.
u("businessName",v)} ph="ex: Cabinet Dupont" req />
Secteur *
{SECTORS.map(s=>)}
{f.sector==="autre"&&<>
u("sectorCustom",v)} ph="ex: Consultant RSE" />>}
u("tagline",v)} ph="ex: Défendre vos droits, *protéger votre avenir*" />
u("description",v)} ph="Expertise juridique rigoureuse et humaine..." ta />
}
{step===1&&
Images
Toutes optionnelles. Les images seront intégrées en base64 dans le HTML.
u("imgLogo",v)} w={180} h={80} />
u("imgHero",v)} w={280} h={150} />
u("imgOwner",v)} w={170} h={200} />
Images services
{[0,1,2,3].map(i=>
uSI(i,v)} w={150} h={100} />)}
}
{step===2&&
Services
Jusqu'à 4 services.
{[0,1,2,3].map(i=>
Service {i+1}
uA("services",i,v)} ph="ex: Droit de la famille" half />
uA("serviceDescs",i,v)} ph="Accompagnement personnalisé..." half />
)}
Chiffres clés
{[0,1,2].map(i=>
uS(i,"n",v)} ph="25+" />
uS(i,"l",v)} ph="années" />
)}
}
{step===3&&
À propos
Le dirigeant / fondateur.
u("ownerName",v)} ph="Maître Cathy Pereira" half />
u("ownerTitle",v)} ph="Avocate au Barreau" half />
u("ownerBio",v)} ph="Parcours, valeurs..." ta />
}
{step===4&&
Témoignages
Jusqu'à 3 avis.
{[0,1,2].map(i=>
uT(i,"name",v)} ph="Sophie Martin" half />
uT(i,"text",v)} ph="Accompagnement remarquable..." half />
)}
}
{step===5&&
Contact
Coordonnées de l'entreprise.
u("phone",v)} ph="+33 6 12 34 56 78" half />
u("email",v)} ph="contact@monsite.fr" half />
u("address",v)} ph="12 rue de la Paix, 75001 Paris" />
u("hours",v)} ph="Lun-Ven : 9h-18h" half />
u("ctaText",v)} ph="Prendre rendez-vous" half />
Réseaux sociaux
u("socialFb",v)} ph="https://facebook.com/..." half />
u("socialIg",v)} ph="https://instagram.com/..." half />
u("socialLi",v)} ph="https://linkedin.com/..." half />
u("socialG",v)} ph="https://google.com/maps/..." half />
}
{step===6&&
Page Actualités
Articles style Artur'in. Manuels ou générés par IA.
{aiBtn(artL,artOk,doArt,"✨ Générer 6 articles avec l'IA","✅ Générés — Regénérer")}
{f.articles.map((a,i)=>
Article {i+1}
uR(i,"img",v)} w={70} h={45} />
uR(i,"title",v)} ph="Titre article" half />
uR(i,"date",v)} ph="2025-03-15" half />
uR(i,"excerpt",v)} ph="Résumé court..." />
uR(i,"content",v)} ph="Contenu complet... Lignes vides = paragraphes" ta />
)}
}
{step===7&&
Design
Couleurs et typographie.
Palette
{PALETTES.map(p=>
{T}
;
}