PageSourceSearch

https://qadence.io/assets/WorkspaceApp-BAfmcGz5.js

js qadence.io collected 2026-10-02 01:57:52 UTC 243,672 bytes, 26 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BriefingBubble-DLRue185.js","assets/index-BMy8nRYZ.js","assets/index-DanzHxKN.css"])))=>i.map(i=>d[i]);
2import{j as e,O as ee,r as l,a2 as Ar,X as E,a0 as Ot,N as qe,F as er,H as pt,$ as Lr,a3 as dt,W as Pt,x as rt,t as tt,_ as Fr}from"./index-BMy8nRYZ.js";import{M as Ct,r as It}from"./index-C4qjWq0B.js";import{u as yn}from"./useGscAnalytics-CmEDrNw-.js";import{b as Tr,f as $r,h as Wr,g as Mr,A as Br,a as Dr}from"./AuthGate-Da3Ee3MR.js";import Pr from"./ProjetView-BYpHPUIR.js";import{S as Ir}from"./SourcesView-qkx2GLMC.js";import{c as Or,A as Hr}from"./conversationStore-D93rAzNV.js";import"./_commonjsHelpers-BosuxZz1.js";function ve(t){return function({size:r=24,className:s,strokeWidth:i=2,style:o}){return e.jsx("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:i,strokeLinecap:"round",strokeLinejoin:"round",className:s,style:o,"aria-hidden":"true",children:t})}}const Vr=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"m19 12-7 7-7-7"})]})),Ur=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m12 19-7-7 7-7"}),e.jsx("path",{d:"M19 12H5"})]})),Jr=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m5 12 7-7 7 7"}),e.jsx("path",{d:"M12 19V5"})]})),Gr=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"m21 16-4 4-4-4"}),e.jsx("path",{d:"M17 20V4"}),e.jsx("path",{d:"m3 8 4-4 4 4"}),e.jsx("path",{d:"M7 4v16"})]})),tr=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M7 7h10v10"}),e.jsx("path",{d:"M7 17 17 7"})]})),Qr=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M3 3v16a2 2 0 0 0 2 2h16"}),e.jsx("path",{d:"M18 17V9"}),e.jsx("path",{d:"M13 17V5"}),e.jsx("path",{d:"M8 17v-3"})]})),St=ve(e.jsx("path",{d:"m6 9 6 6 6-6"})),Kr=ve(e.jsx("path",{d:"m15 18-6-6 6-6"})),zn=ve(e.jsx("path",{d:"m9 18 6-6-6-6"})),nr=ve(e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),e.jsx("path",{d:"M2 12h20"})]})),Yr=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"}),e.jsx("path",{d:"M12 7v5l4 2"})]})),Xr=ve(e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"7",height:"7",x:"3",y:"3",rx:"1"}),e.jsx("rect",{width:"7",height:"7",x:"14",y:"3",rx:"1"}),e.jsx("rect",{width:"7",height:"7",x:"14",y:"14",rx:"1"}),e.jsx("rect",{width:"7",height:"7",x:"3",y:"14",rx:"1"})]})),Zr=ve(e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),e.jsx("path",{d:"M9 3v18"}),e.jsx("path",{d:"m16 15-3-3 3-3"})]})),es=ve(e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),e.jsx("path",{d:"M9 3v18"}),e.jsx("path",{d:"m14 9 3 3-3 3"})]})),ot=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"M12 5v14"})]})),ts=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"}),e.jsx("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}),e.jsx("path",{d:"M8 16H3v5"})]})),ns=ve(e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"m21 21-4.3-4.3"})]})),rs=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})),Rn=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),e.jsx("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),e.jsx("line",{x1:"10",x2:"10",y1:"11",y2:"17"}),e.jsx("line",{x1:"14",x2:"14",y1:"11",y2:"17"})]})),ss=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"12",cy:"7",r:"4"})]})),Nn=ve(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}));function En(t){return t.flatMap((n,r)=>{var c;if(n.role!=="user"||!n.keywordTask)return[];const s=t.filter(u=>u.role==="assistant"&&u.keywordTaskFor===n.id),i=s.length?s[s.length-1]:((c=t[r+1])==null?void 0:c.role)==="assistant"?t[r+1]:void 0,o=i?i.isError||i.interrupted?"error":i.isStreaming?"running":/```questions/.test(i.content)?"needs_input":i.content.trim()?"done":"error":"queued";return[{id:n.id,instruction:n.content,status:o,schedule:"À la demande",output:(i==null?void 0:i.errorMessage)||(i==null?void 0:i.content),steps:(s.length?s:i?[i]:[]).flatMap(u=>u.steps||[]).map(u=>({...u}))}]})}const Xt=()=>new Intl.NumberFormat("fr-FR"),is=()=>new Intl.NumberFormat("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2});function Xe(t){if(t==null||t==="")return null;const n=Number(t);return isNaN(n)?null:n}function os(t){const n=Xe(t.cpc);if(n!=null)return n;const r=Xe(t.cpc_low),s=Xe(t.cpc_high);return r!=null&&s!=null?(r+s)/2:s??r}const Zt=()=>({low:{label:E.t("rech_keywordtable.faible"),dot:"#D1D5DB"},medium:{label:E.t("rech_keywordtable.moyenne"),dot:"#9CA3AF"},high:{label:E.t("rech_keywordtable.leve"),dot:"#4B5563"}});function as(t){const n=String(t||"").toLowerCase();return n.startsWith("low")||n.startsWith("faib")?Zt().low:n.startsWith("med")||n.startsWith("moy")?Zt().medium:n.startsWith("high")||n.startsWith("élev")||n.startsWith("elev")?Zt().high:null}function ls(t){const n=s=>t.some(i=>(i==null?void 0:i[s])!=null&&i[s]!==""),r=[{cle:"keyword",label:E.t("rech_keywordtable.motCl"),tip:E.t("rech_keywordtable.laRequteCibler"),align:"left",width:"26%",rendu:s=>e.jsx("span",{className:"kw-name",children:s.keyword||""})}];return n("intention")&&r.push({cle:"intention",label:E.t("rech_keywordtable.intention"),tip:E.t("rech_keywordtable.knowSimpleRponseImmdiate"),align:"left",width:"13%",rendu:s=>e.jsx("span",{className:"kw-soft",children:s.intention||"·"})}),r.push({cle:"volume",label:E.t("rech_keywordtable.volume"),tip:E.t("rech_keywordtable.recherchesParMoisGoogle"),align:"right",width:"11%",rendu:s=>{const i=Xe(s.volume);return i?e.jsx("span",{className:"kw-num",children:Xt().format(i)}):e.jsx("span",{className:"kw-soft",title:E.t("rech_decisioncards.nonMesure"),children:E.t("rech_decisioncards.nonMesure")}
2)}}),(n("cpc")||n("cpc_low")||n("cpc_high"))&&r.push({cle:"cpc",label:"CPC",tip:E.t("rech_keywordtable.cotParClicMoyen"),align:"right",width:"10%",rendu:s=>{const i=os(s);return i?e.jsxs("span",{className:"kw-num",children:[is().format(i)," €"]}):e.jsx("span",{className:"kw-soft",children:"·"})}}),n("competition")&&r.push({cle:"competition",label:E.t("rech_keywordtable.comptition"),tip:E.t("rech_keywordtable.concurrencePublicitaireSurCe"),align:"left",width:"13%",rendu:s=>{const i=as(s.competition);return i?e.jsxs("span",{className:"kw-comp",children:[e.jsx("i",{style:{background:i.dot}}),i.label]}):e.jsx("span",{className:"kw-soft",children:"·"})}}),n("clicks")&&r.push({cle:"clicks",label:E.t("x_projectviews.clics"),tip:E.t("kw_table.tipClics"),align:"right",width:"9%",rendu:s=>{const i=Xe(s.clicks);return e.jsx("span",{className:"kw-num",children:i!=null?Xt().format(i):"·"})}}),n("impressions")&&r.push({cle:"impressions",label:"Impr.",tip:E.t("kw_table.tipImpressions"),align:"right",width:"10%",rendu:s=>{const i=Xe(s.impressions);return e.jsx("span",{className:"kw-num",children:i!=null?Xt().format(i):"·"})}}),n("position")&&r.push({cle:"position",label:E.t("x_projectviews.position"),tip:E.t("kw_table.tipPosition"),align:"right",width:"10%",rendu:s=>{const i=Xe(s.position);if(i==null)return e.jsx("span",{className:"kw-num",children:"·"});const o=i>=5&&i<=20;return e.jsx("span",{className:"kw-num",style:o?{color:"var(--accent)",fontWeight:600}:void 0,children:i.toFixed(1)})}}),n("priority")&&r.push({cle:"priority",label:E.t("kw_table.priorite"),tip:E.t("kw_table.tipPriorite"),align:"left",width:"9%",rendu:s=>e.jsx("span",{className:"kw-bucket",children:s.priority})}),n("page")&&r.push({cle:"page",label:E.t("kw_table.page"),tip:E.t("kw_table.tipPage"),align:"left",width:"18%",rendu:s=>e.jsx("span",{className:"kw-soft",title:String(s.page),children:s.page})}),r}function rr({raw:t,onRowClick:n}){const{t:r}=ee(),[s,i]=l.useState(null);let o=null;try{const a=typeof t=="string"?JSON.parse(t):t;o=Array.isArray(a)?a:Array.isArray(a==null?void 0:a.rows)?a.rows:null}catch{return null}if(!o||!o.length)return null;const c=ls(o),u=(a,p)=>{const g=a.currentTarget.getBoundingClientRect();i({text:p,x:g.left+g.width/2,y:g.bottom})};return e.jsxs("div",{className:"kchat-kwtable",role:"region","aria-label":r("chatUx.keywordTable"),tabIndex:0,children:[e.jsx("p",{className:"kchat-table-hint",children:r("chatUx.tableSwipe")}),e.jsxs("table",{children:[e.jsx("colgroup",{children:c.map(a=>e.jsx("col",{style:{width:a.width}},a.cle))}),e.jsx("thead",{children:e.jsx("tr",{children:c.map(a=>e.jsx("th",{style:{textAlign:a.align,cursor:"help"},onMouseEnter:p=>u(p,a.tip),onMouseMove:p=>u(p,a.tip),onMouseLeave:()=>i(null),children:e.jsx("span",{className:"kw-th-label",children:a.label})},a.cle))})}),e.jsx("tbody",{children:o.map((a,p)=>e.jsx("tr",{onClick:n?()=>n(a):void 0,className:n?"kw-row-click":void 0,style:{background:p%2===1?"#F3F4F6":"#FFFFFF",cursor:n?"pointer":"default"},children:c.map(g=>e.jsx("td",{style:{textAlign:g.align},children:g.rendu(a)},g.cle))},p))})]}),s&&Ar.createPortal(e.jsx("div",{style:{position:"fixed",left:s.x,top:s.y+8,transform:"translateX(-50%)",zIndex:4e3,maxWidth:260,background:"#111827",color:"#fff",fontSize:12,lineHeight:1.45,padding:"8px 11px",borderRadius:8,boxShadow:"0 12px 30px -10px rgba(0,0,0,0.45)",pointerEvents:"none",fontFamily:"var(--font)",fontWeight:400},children:s.text}),document.body)]})}const An={"know-simple":"#6B7280",know:"#6B7280",do:"#374151"};function sr({rows:t}){const{t:n}=ee();return t.length?e.jsx("div",{className:"kchat-kwtable",children:e.jsxs("table",{children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"40%"}}),e.jsx("col",{style:{width:"16%"}}),e.jsx("col",{style:{width:"44%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:{textAlign:"left"},children:n("rech_deliverabletables.microIntention")}),e.jsx("th",{style:{textAlign:"left"},children:n("rech_deliverabletables.catgorie")}),e.jsx("th",{style:{textAlign:"left"},children:n("rech_deliverabletables.ceQueLUtilisateur")})]})}),e.jsx("tbody",{children:t.map((r,s)=>e.jsxs("tr",{style:{background:s%2===1?"#F3F4F6":"#FFFFFF"},children:[e.jsx("td",{className:"kw-name",children:r.query}),e.jsx("td",{children:r.cat?e.jsx("span",{className:"kw-bucket",style:{background:`${An[r.cat.toLowerCase()]||"#6B7280"}1A`,color:An[r.cat.toLowerCase()]||"#6B7280"},children:r.cat}):e.jsx("span",{className:"kw-soft",children:"·"})}),e.jsx("td",{style:{fontSize:13.5,lineHeight:1.45,color:"var(--text-secondary)"},children:r.want||"·"})]},s))})]})}):null}function ir({rows:t}){const{t:n}=ee();return t.length?e.jsx("div",{className:"kchat-kwtable",children:e.jsxs("table",{children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"38%"}}),e.jsx("col",{style:{width:"62%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:{textAlign:"left"},children:"Objection"}),e.jsx("th",{style:{textAlign:"left"},children:n("rech_deliverabletables.rponseApporter")})]})}),e.jsx("tbody",{children:t.map((r,s)=>e.jsxs("tr",{style:{background:s%2===1?"#F3F4F6":"#FFFFFF"},children:[e.jsx("td",{className:"kw-name",children:r.objection}),e.jsx("td",{style:{fontSize:13.5,lineHeight:1.45,color:"var(--text-secondary)"},children:r.reponse||"·"})]},s))})]})}):null}const Ht={color:"var(--text-primary, #111827)"},X={text:"var(--text-primary, #111827)",secondaire:"var(--text-secondary, #4B5563)",doux:"var(--text-muted, #6B7280)",bord:"var(--border, #E5E7EB)",carte:"var(--bg-page2, #F1F2F5)",fondLibelle:"var(--bg-hover, #EDEEF1)"};function zt({children:t}){return e.jsx("div",{style:{background:X.carte,border:`1px solid ${X.bord}`,borderRadius:16,padding:"28px 28px 30px",margin:"28px 0"},children:t})}function en({libelle:t,children:n}){return e.jsxs("div",{style:{fontSize:17,lineHeight:1.75,color:X.secondaire,marginTop:12},children:[e.jsxs("strong",{style:{fontWeight:700,color:X.text},children:[t," :"]})," ",n]})}function Pe({children:t}){return e.jsx("div",{style:{fontSize:12,fontWeight:700,letterSpacing:"0.07em",textTransform:"uppercase",color:X.doux,margin:"40px 0 14px"},children:t})}function un({children:t}){return e.jsx("p",{style:{margin:0,fontSize:17,lineHeight:1.75,color:X.text},children:t})}function et({items:t}){return t.length?e.jsx("ul",{className:"fzn-liste",style:{margin:"20px 0 0",paddingLeft:24,listStyle:"disc",fontSize:17,lineHeight:1.7,color:X.secondaire},children:t.map((n,r)=>e.jsx("li",{style:{marginBottom:r===t.length-1?0:14,paddingLeft:4},children:n},r))}):null}function cs(t){window.dispatchEvent(new CustomEvent("kw-chat-prompt",{detail:{prompt:t}}))}function hn({libelle:t,prompt:n}){return e.jsx("button",{onClick:()=>cs(n),style:{background:"transparent",border:`1px solid ${X.bord}`,color:X.secondaire,borderRadius:10,padding:"10px 18px",fontSize:14,fontWeight:600,cursor:"pointer"},children:t})}function ds({data:t}){const{t:n}=ee();if(!t)return null;const r=t.statut==="valide",s=[{label:n("rech_decisioncards.quiAchete"),valeur:t.acheteur},{label:n("rech_decisioncards.quelProbleme"),valeur:t.probleme},{label:n("rech_decisioncards.ceQuiDeclenche"),valeur:t.declencheur},{label:n("rech_decisioncards.pourquoiRefus"),valeur:t.refus}].filter(i=>i.valeur);return e.jsxs(zt,{children:[e.jsx("div",{style:{fontSize:24,fontWeight:700,letterSpacing:"-0.025em",lineHeight:1.2,...Ht},children:n("rech_decisioncards.ceQueJeComprends")}),e.jsx("div",{style:{fontSize:15,fontWeight:600,color:r?"#0A8F6F":X.doux,marginTop:6,marginBottom:14},children:n(r?"rech_decisioncards.valideParVous":"rech_decisioncards.hypotheseAC
2onfirmer")}),t.vend&&e.jsx(un,{children:t.vend}),e.jsx("div",{style:{marginTop:14,display:"grid",gap:1,background:X.bord,border:`1px solid ${X.bord}`,borderRadius:10,overflow:"hidden"},children:s.map(i=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(140px, 30%) 1fr",gap:1,background:X.bord},children:[e.jsx("div",{style:{background:X.fondLibelle,padding:"14px 16px",fontSize:15,fontWeight:600,color:X.doux},children:i.label}),e.jsx("div",{style:{background:"var(--bg-white, #fff)",padding:"14px 16px",fontSize:17,lineHeight:1.7,color:X.text},children:i.valeur})]},i.label))}),t.sources.length>0&&e.jsxs("div",{style:{marginTop:20,fontSize:15,color:X.doux,lineHeight:1.7},children:[e.jsxs("strong",{style:{fontWeight:600},children:[n("rech_decisioncards.sources")," :"]})," ",t.sources.join(" · ")]}),t.a_verifier.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.aVerifier")}),e.jsx(et,{items:t.a_verifier})]}),!r&&e.jsxs("div",{style:{marginTop:16,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx(hn,{libelle:n("rech_decisioncards.cestJuste"),prompt:n("rech_decisioncards.promptCestJuste")}),e.jsx("span",{style:{fontSize:12.5,color:X.doux},children:n("rech_decisioncards.sinonDitesCeQui")})]})]})}function us({rows:t}){const{t:n}=ee();return t.length?e.jsx(e.Fragment,{children:t.map((r,s)=>{const i=[{label:n("rech_decisioncards.personneConcernee"),valeur:r.personne},{label:n("rech_decisioncards.probleme"),valeur:r.probleme},{label:n("rech_decisioncards.consequence"),valeur:r.consequence},{label:n("rech_decisioncards.solutionRecherchee"),valeur:r.solution},{label:n("rech_decisioncards.contrainte"),valeur:r.contrainte}].filter(o=>o.valeur);return e.jsxs(zt,{children:[r.verbatim&&e.jsxs("blockquote",{style:{margin:"0 0 16px",padding:0,background:"transparent"},children:[e.jsxs("div",{style:{fontSize:19,lineHeight:1.65,color:X.text,letterSpacing:"-0.015em"},children:["« ",r.verbatim," »"]}),r.source&&e.jsx("div",{style:{fontSize:15,color:X.doux,marginTop:10},children:r.source})]}),e.jsx("div",{style:{display:"grid",gap:1,background:X.bord,border:`1px solid ${X.bord}`,borderRadius:10,overflow:"hidden"},children:i.map(o=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(150px, 32%) 1fr",gap:1,background:X.bord},children:[e.jsx("div",{style:{background:X.fondLibelle,padding:"14px 16px",fontSize:15,fontWeight:600,color:X.doux},children:o.label}),e.jsx("div",{style:{background:"var(--bg-white, #fff)",padding:"14px 16px",fontSize:17,lineHeight:1.7,color:X.text},children:o.valeur})]},o.label))})]},s)})}):null}const hs=()=>new Intl.NumberFormat("fr-FR");function ps({source:t,origine:n}){const{t:r}=ee(),s=t.toLowerCase().startsWith("observ"),i=r(s?"rech_decisioncards.observe":"rech_decisioncards.propose");return e.jsxs("span",{style:{fontSize:13.5,fontWeight:600,color:s?"#0A8F6F":"#9CA3AF"},children:[i,n?` · ${n}`:""]})}function xs({rows:t}){const{t:n}=ee();return t.length?e.jsx("div",{className:"kchat-kwtable",style:{marginTop:8},children:e.jsxs("table",{children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"44%"}}),e.jsx("col",{style:{width:"28%"}}),e.jsx("col",{style:{width:"16%"}}),e.jsx("col",{style:{width:"12%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{style:{textAlign:"left"},children:n("rech_decisioncards.requete")}),e.jsx("th",{style:{textAlign:"left"},children:n("rech_decisioncards.source")}),e.jsx("th",{style:{textAlign:"right"},children:n("rech_decisioncards.volume")}),e.jsx("th",{style:{textAlign:"right"},children:n("rech_decisioncards.position")})]})}),e.jsx("tbody",{children:t.map((r,s)=>e.jsxs("tr",{style:{background:s%2===1?"#F3F4F6":"#FFFFFF"},children:[e.jsx("td",{className:"kw-name",children:r.requete}),e.jsx("td",{children:e.jsx(ps,{source:r.source,origine:r.origine})}),e.jsx("td",{className:"kw-num",style:{textAlign:"right"},children:r.volume!=null?hs().format(r.volume):e.jsx("span",{className:"kw-soft",title:n("rech_decisioncards.nonMesure"),children:n("rech_decisioncards.nonMesure")})}),e.jsx("td",{className:"kw-num",style:{textAlign:"right"},children:r.position!=null?r.position.toFixed(1):"·"})]},s))})]})}):null}function gs({rows:t}){const{t:n}=ee();return t.length?e.jsx(e.Fragment,{children:t.map((r,s)=>e.jsxs(zt,{children:[e.jsx("div",{style:{fontSize:26,fontWeight:700,letterSpacing:"-0.03em",lineHeight:1.2,...Ht},children:r.titre}),e.jsx("div",{style:{fontSize:15,color:X.doux,marginTop:8}
2,children:[r.page,r.effort].filter(Boolean).join(" · ")}),r.probleme&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.leProblemeATraiter")}),e.jsx(un,{children:r.probleme})]}),(r.pourquoi||r.preuves.length>0)&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.pourquoiCetteRecommandation")}),r.pourquoi&&e.jsx(un,{children:r.pourquoi}),e.jsx(et,{items:r.preuves})]}),r.a_ajouter.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.ceQuIlFaudraitAjouter")}),e.jsx(et,{items:r.a_ajouter})]}),r.requetes.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.lesRecherchesAssociees")}),e.jsx("div",{className:"kchat",children:e.jsx(xs,{rows:r.requetes})})]}),r.inconnues.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.ceQuOnNeSaitPas")}),e.jsx(et,{items:r.inconnues})]}),r.decision&&e.jsxs("div",{style:{marginTop:32,paddingTop:22,borderTop:`1px solid ${X.bord}`},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,letterSpacing:"0.07em",textTransform:"uppercase",color:X.doux,marginBottom:8},children:n("rech_decisioncards.decisionProposee")}),e.jsx("div",{style:{fontSize:18,lineHeight:1.65,color:X.text,fontWeight:500},children:r.decision})]}),r.action!=="observer"&&e.jsxs("div",{style:{marginTop:12,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx(hn,{libelle:n("rech_decisioncards.redigerLeBrief"),prompt:n("rech_decisioncards.promptRedigerLeBrief",{titre:r.titre,page:r.page||""})}),r.page&&e.jsx(hn,{libelle:n("rech_decisioncards.laPageEstEnLigne"),prompt:n("rech_decisioncards.promptPagePubliee",{page:r.page})}),e.jsx("span",{style:{fontSize:12.5,color:X.doux},children:n("rech_decisioncards.siCelaNeCorrespond")})]})]},s))}):null}function fs({rows:t}){const{t:n}=ee();return t.length?e.jsx(e.Fragment,{children:t.map((r,s)=>e.jsxs(zt,{children:[e.jsx("div",{style:{fontSize:22,fontWeight:700,letterSpacing:"-0.025em",lineHeight:1.2,...Ht},children:r.sujet}),r.signaux.length>0&&e.jsx(en,{libelle:n("rech_decisioncards.signaux"),children:r.signaux.join(" · ")}),r.manque&&e.jsx(en,{libelle:n("rech_decisioncards.ceQuiManque"),children:r.manque}),r.verification&&e.jsx(en,{libelle:n("rech_decisioncards.pourTrancher"),children:r.verification})]},s))}):null}function ms({data:t}){const{t:n}=ee();return t?e.jsxs(zt,{children:[e.jsx("div",{style:{fontSize:24,fontWeight:700,letterSpacing:"-0.025em",lineHeight:1.2,...Ht},children:n("rech_decisioncards.laPageFaceAuBrief")}),e.jsx("div",{style:{fontSize:15,color:X.doux,marginTop:8},children:[t.url,t.brief].filter(Boolean).join(" · ")}),t.manquant.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.cequiManqueSurLaPage")}),e.jsx(et,{items:t.manquant})]}),t.couvert.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.ceQuiEstBienLa")}),e.jsx(et,{items:t.couvert})]}),t.en_plus.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{children:n("rech_decisioncards.ceQuiAEteAjoute")}),e.jsx(et,{items:t.en_plus})]}),t.verdict&&e.jsxs("div",{style:{marginTop:32,paddingTop:22,borderTop:`1px solid ${X.bord}`},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,letterSpacing:"0.07em",textTransform:"uppercase",color:X.doux,marginBottom:8},children:n("rech_decisioncards.resteAFaire")}),e.jsx("div",{style:{fontSize:18,lineHeight:1.65,color:X.text,fontWeight:500},children:t.verdict})]})]}):null}function xt(t,n){const r=[],s=new RegExp("```"+n+"\\s*([\\s\\S]*?)```","g");let i;for(;(i=s.exec(t))!==null;)r.push(i[1].trim());return r}function gt(t){try{const n=JSON.parse(t);return Array.isArray(n)?n:Array.isArray(n==null?void 0:n.rows)?n.rows:[]}catch{return[]}}function or(t,n){const r=t.split(`
3`),s=[],i=o=>o.trim().replace(/^\|/,"").replace(/\|$/,"").split("|").map(c=>c.trim());for(let o=0;o<r.length;o++){if(!r[o].includes("|"))continue;const c=i(r[o]).map(a=>a.toLowerCase());if(!n.every(a=>c.some(p=>p.includes(a))))continue;const u=r[o+1]||"";if(/^\s*\|?[\s:-]*-[\s:|-]*\|?\s*$/.test(u)){for(let a=o+2;a<r.length;a++){const p=r[a];if(!p.includes("|"))break;const g=i(p);if(g.length<2||g.every(y=>!y))break;s.push(g)}o=r.length}}return s}function ft(t){return t.filter(n=>n.role==="assistant"&&n.content).map(n=>n.content)}function ar(t,n){const r=new Set,s=[];for(const i of t){const o=n(i).toLowerCase().trim();
3!o||r.has(o)||(r.add(o),s.push(i))}return s}function lr(t){return gt(t).map(n=>({query:String((n==null?void 0:n.query)||""),cat:String((n==null?void 0:n.cat)||""),want:String((n==null?void 0:n.want)||"")})).filter(n=>n.query)}function cr(t){return gt(t).map(n=>({objection:String((n==null?void 0:n.objection)||""),reponse:String((n==null?void 0:n.reponse)||(n==null?void 0:n.réponse)||"")})).filter(n=>n.objection)}function js(t){const n=Ot()==="en",r=(i,o,c)=>{const u=gt(i).length,a=u>1?c:o;return n?`[${u} ${a} already produced in this conversation]`:`[${u} ${a} déjà produits dans cette conversation]`},s=(i,o)=>n?o:i;return String(t||"").replace(/```strategic[\s\S]*?```/g,"").replace(/```keywords\s*([\s\S]*?)```/g,(i,o)=>r(o,...s(["mot-clé","mots-clés"],["keyword","keywords"]))).replace(/```micro\s*([\s\S]*?)```/g,(i,o)=>r(o,...s(["micro-intention","micro-intentions"],["micro-intent","micro-intents"]))).replace(/```objections\s*([\s\S]*?)```/g,(i,o)=>r(o,...s(["objection","objections"],["objection","objections"]))).replace(/```besoin\s*([\s\S]*?)```/g,(i,o)=>r(o,...s(["situation d'achat","situations d'achat"],["buying situation","buying situations"]))).replace(/```decision\s*([\s\S]*?)```/g,(i,o)=>r(o,...s(["décision de page","décisions de page"],["page decision","page decisions"]))).replace(/```veille\s*([\s\S]*?)```/g,(i,o)=>r(o,...s(["piste en observation","pistes en observation"],["lead under observation","leads under observation"]))).replace(/```verification\s*([\s\S]*?)```/g,n?"[a page already compared with its brief in this conversation]":"[une page déjà comparée à son brief dans cette conversation]").replace(/```suggestions[\s\S]*?```/g,"").replace(/```questions[\s\S]*?```/g,"").trim()}function dr(t){const n=[];for(const r of ft(t)){for(const s of xt(r,"micro"))n.push(...lr(s));for(const s of or(r,["micro-intention","cat"]))n.push({query:s[0]||"",cat:s[1]||"",want:s[2]||""})}return ar(n.filter(r=>r.query),r=>r.query)}function ur(t){const n=[];for(const r of ft(t)){for(const s of xt(r,"objections"))n.push(...cr(s));for(const s of or(r,["objection","répons"]))n.push({objection:s[0]||"",reponse:s[1]||""})}return ar(n.filter(r=>r.objection),r=>r.objection)}function re(t){return t==null?"":String(t).trim()}function Ie(t){if(Array.isArray(t))return t.map(re).filter(Boolean);const n=re(t);return n?[n]:[]}function Ln(t){if(t==null||t==="")return null;const n=Number(t);return isNaN(n)?null:n}function hr(t){let n;try{n=JSON.parse(t)}catch{return null}if(!n||typeof n!="object"||Array.isArray(n))return null;const r={statut:re(n.statut)==="valide"?"valide":"hypothese",vend:re(n.vend),acheteur:re(n.acheteur),probleme:re(n.probleme),declencheur:re(n.declencheur),refus:re(n.refus),sources:Ie(n.sources),a_verifier:Ie(n.a_verifier)};return r.vend||r.acheteur||r.probleme?r:null}function bs(t){return gt(t).map(n=>({personne:re(n==null?void 0:n.personne),probleme:re(n==null?void 0:n.probleme),consequence:re(n==null?void 0:n.consequence),solution:re(n==null?void 0:n.solution),contrainte:re(n==null?void 0:n.contrainte),verbatim:re(n==null?void 0:n.verbatim),source:re(n==null?void 0:n.source)})).filter(n=>n.probleme)}function pr(t){return gt(t).map(n=>({titre:re(n==null?void 0:n.titre),action:re(n==null?void 0:n.action).toLowerCase(),page:re(n==null?void 0:n.page),probleme:re(n==null?void 0:n.probleme),pourquoi:re(n==null?void 0:n.pourquoi),preuves:Ie(n==null?void 0:n.preuves),a_ajouter:Ie(n==null?void 0:n.a_ajouter),requetes:(Array.isArray(n==null?void 0:n.requetes)?n.requetes:[]).map(r=>({requete:re(r==null?void 0:r.requete),source:re(r==null?void 0:r.source)||"proposé",origine:re(r==null?void 0:r.origine),volume:Ln(r==null?void 0:r.volume),position:Ln(r==null?void 0:r.position)})).filter(r=>r.requete),inconnues:Ie(n==null?void 0:n.inconnues),decision:re(n==null?void 0:n.decision),effort:re(n==null?void 0:n.effort)})).filter(n=>n.titre)}function xr(t){return gt(t).map(n=>({sujet:re(n==null?void 0:n.sujet),signaux:Ie(n==null?void 0:n.signaux),manque:re(n==null?void 0:n.manque),verification:re(n==null?void 0:n.verification)})).filter(n=>n.sujet)}function ys(t){let n=null;for(const r of ft(t))for(const s of xt(r,"comprehension")){const i=hr(s);i&&(n=i)}return n}function vn(t,n){const r=new Map;for(const s of t){const i=n(s).toLowerCase().trim();i&&r.set(i,s)}return[...r.values()]}function vs(t){const n=[];for(const r of ft(t))for(const s of xt(r,"decision"))n.push(...pr(s));return vn(n,r=>r.titre)}function ws(t){const n=[];for(const r of ft(t))for(const s of xt(r,"veille"))n.push(...xr(s));return vn(n,r=>r.sujet)}function gr(t){let n;try{n=JSON.parse(t)}catch{return null}if(!n||typeof n!="object"||Array.isArray(n))return null;const r={url:re(n.url),brief:re(n.brief),couvert:Ie(n.couvert),manquant:Ie(n.manquant),en_plus:Ie(n.en_plus),verdict:re(n.verdict)};return r.url||r.couvert.length||r.manquant.length?r:null}function ks(t){const n=[];for(const r of ft(t))for(const s of xt(r,"verification")){const i=gr(s);i&&n.push(i)}return vn(n,r=>r.url)}const pn={pre({children:t,...n}){var c,u;const r=Array.isArray(t)?t[0]:t,s=((c=r==null?void 0:r.props)==null?void 0:c.className)||"",i=(u=r==null?void 0:r.props)==null?void 0:u.children,o=Array.isArray(i)?i.join(""):String(i??"");return/language-keywords/.test(s)?e.jsx(rr,{raw:o}):/language-micro/.test(s)?e.jsx(sr,{rows:lr(o)}):/language-objections/.test(s)?e.jsx(ir,{rows:cr(o)}
3):/language-comprehension/.test(s)?e.jsx(ds,{data:hr(o)}):/language-besoin/.test(s)?e.jsx(us,{rows:bs(o)}):/language-decision/.test(s)?e.jsx(gs,{rows:pr(o)}):/language-veille/.test(s)?e.jsx(fs,{rows:xr(o)}):/language-verification/.test(s)?e.jsx(ms,{data:gr(o)}):e.jsx("pre",{...n,children:t})},table({children:t,...n}){return e.jsx("div",{className:"kchat-kwtable",children:e.jsx("table",{...n,children:t})})}};function at(t){let n=[];const r=t.match(/```suggestions\s*([\s\S]*?)```/);if(r)try{const i=JSON.parse(r[1].trim());Array.isArray(i)&&(n=i.filter(o=>o&&o.label&&o.prompt).map(o=>({label:String(o.label),prompt:String(o.prompt)})))}catch{}return{clean:t.replace(/```strategic[\s\S]*?```/g,"").replace(/```strategic[\s\S]*$/,"").replace(/```source_request[\s\S]*?```/g,"").replace(/```source_request[\s\S]*$/,"").replace(/```suggestions[\s\S]*?```/g,"").replace(/```suggestions[\s\S]*$/,"").replace(/```questions[\s\S]*?```/g,"").replace(/```questions[\s\S]*$/,"").trim(),suggestions:n}}const Ss=[{skill:"recherche_mots_cles",method:"Recherche de mots-clés",title:"Trouver des mots-clés",result:"Une liste qualifiée par intention, avec les mesures disponibles.",requires:"Une offre ou un sujet à préciser",instruction:"Recherche les mots-clés pertinents pour mon offre prioritaire. Classe-les par intention et indique les volumes uniquement si une source les fournit."},{skill:"mots_cles_decisionnels",method:"Mots-clés décisionnels",title:"Trouver les recherches proches de l’achat",result:"Une sélection argumentée de requêtes liées au choix de mon offre.",requires:"Une offre et son public",instruction:"Identifie les requêtes décisionnelles liées à mon offre prioritaire. Explique leur proximité avec l’offre et propose la page adaptée à chaque intention."},{skill:"clustering_mots_cles",method:"Clustering",title:"Regrouper mes mots-clés en pages",result:"Des groupes de requêtes, un mot-clé principal et une page par intention.",requires:"Une liste de mots-clés",instruction:"Regroupe les mots-clés du projet par intention et propose une page par groupe. Distingue les regroupements vérifiés dans les SERP des hypothèses."},{skill:"quick_win",method:"Opportunités rapides",title:"Repérer les pages à renforcer",result:"Les pages prioritaires et les modifications recommandées, données à l’appui.",requires:"Search Console connecté ou données fournies",instruction:"Analyse les données Search Console disponibles et identifie les pages à renforcer en priorité pour mon offre. Précise le périmètre, la période, les limites des données et les modifications recommandées."},{skill:"peurs_objections",method:"Peurs et objections",title:"Préparer les réponses aux freins d’achat",result:"Les objections à traiter et les preuves à réunir pour y répondre.",requires:"Une offre et son public",instruction:"Identifie les freins à l’achat de mon offre pour son public cible. Sépare les hypothèses des retours clients documentés et propose les preuves et contenus à préparer."},{skill:"brief_contenu",method:"Brief de contenu",title:"Préparer le brief d’une page",result:"Un brief avec structure, intentions à couvrir et éléments à documenter.",requires:"Un mot-clé ou une page cible",instruction:"Prépare le brief de contenu d’une page prioritaire du projet. Confirme avec moi la page ou le mot-clé cible avant de produire la structure et les recommandations."}],_s=Ss.map(t=>({...t,prompt:`Charge le skill « ${t.skill} » (${t.method}) et applique sa méthode. ${t.instruction} Appuie-toi sur le contexte déjà enregistré du projet. Si une information ou une source nécessaire manque, demande-la avant de poursuivre. Restitue le livrable et les limites rencontrées ; toute publication ou modification du site nécessite une autorisation distincte.`})),Cs=t=>`Je souhaite préciser mon besoin avec toi : ${t}
4
5Appuie-toi sur le contexte du projet et les skills disponibles pour m’aider à choisir les actions utiles. Pose les questions nécessaires, puis propose des consignes concrètes à préparer. Attends que je choisisse une action avant de lancer sa réalisation.`,Fn={queued:"À lancer",running:"En cours",scheduled:"Planifiée",done:"Terminée",error:"À reprendre",needs_input:"À préciser"},qs=[{id:"example-1",instruction:"Trouve les requêtes qui montrent une intention de choisir une formation Lean.",status:"done",schedule:"À la demande",steps:[{label:"Lecture du contexte",done:!0,detail:"Offre de formation Lean utilisée dans cet exemple."},{label:"Recherche des requêtes",done:!0,detail:"Deux requêtes illustratives, sans mesure de volume."},{label:"Restitution",done:!0,detail:"Tableau de démonstration disponible dans le résultat."}],output:`### Exemple de restitution
6
7L’agent restitue ici les requêtes retenues, les données disponibles et les raisons de sa sélection.
8
9| Requête illustrative | Intention | Prochaine étape |
10|---|---|---|
11| formation Lean pour responsable industriel | Choisir une formation | Examiner la page existante |
12| formation Lean intra entreprise | Comparer une offre | Vérifier l’adéquation avec l’offre |
13
14*Exemple fictif : ces requêtes ne sont pas issues d’une analyse réelle. Aucun volume n’a été mesuré.*`},{id:"example-2",instruction:"Chaque lundi, regarde mes nouvelles requêtes Search Console et signale les opportunités liées à mon offre.",status:"scheduled",schedule:"Chaque lundi à 09:00 · Europe/Paris",steps:[]}];function zs({demo:t=!1,messages:n=[],onGiveTask:r,onDiscuss:s,onOpenChat:i,children:o}){var M,Y;const[c,u]=l.useState(""),[a,p]=l.useState("now"),[g,y]=l.useState("09:00"),[w,m]=l.useState(""),[d,h]=l.useState(qs),[j,x]=l.useState(t?"example-1":((M=En(n).find(k=>k.status==="running"))==null?void 0:M.id)||null),[z,$]=l.useState("all"),[T,L]=l.useState("result"),[b,N]=l.useState(""),[W,q]=l.useState(!1),[J,ce]=l.useState("action"),[G,je]=l.useState(""),[he,ne]=l.useState(!0),F=l.useRef(null),R=l.useRef(null),H=l.useRef(null);l.useEffect(()=>{const k=H.current;if(!k)return;const B=n.find(se=>se.keywordTask&&se.content===k.prompt&&!k.previousIds.has(se.id));B&&(x(B.id),L("activity"),$("all"),H.current=null)},[n]),l.useEffect(()=>()=>{F.current&&clearTimeout(F.current)},[]);const te=t?d:En(n),pe=te.some(k=>k.status==="running")||!t&&n.some(k=>k.isStreaming),I=te.find(k=>k.id===j);function be(k){if(F.current||pe)return;const B=["Lire le contexte du projet","Rechercher et examiner les requêtes","Préparer le résultat"];h(ge=>ge.map(oe=>oe.id===k?{...oe,status:"running",steps:B.map((fe,we)=>({label:fe,done:!1,debut:we===0?Date.now():void 0}))}:oe)),L("activity");function se(ge){F.current=setTimeout(()=>{const oe=ge===B.length-1;h(fe=>fe.map(we=>we.id===k?{...we,status:oe?"done":"running",steps:we.steps.map((De,He)=>He===ge?{...De,done:!0,fin:Date.now(),detail:"Étape simulée pour cet aperçu."}:He===ge+1?{...De,debut:Date.now()}:De),output:oe?`### Résultat de démonstration
15
16La consigne a parcouru les étapes de cet aperçu. Dans le projet connecté, cette zone contient la restitution de l’agent : requêtes, mesures disponibles et recommandations.
17
18Aucune recherche réelle n’a été exécutée dans cette simulation.`:void 0}:we)),F.current=null,oe||se(ge+1)},1600)}se(0)}function Le(k){k.preventDefault();const B=c.trim();if(!B||pe&&a==="now")return;if(!t){H.current={prompt:B,previousIds:new Set(n.map(fe=>fe.id))},r==null||r(B),u("");return}const se=Intl.DateTimeFormat().resolvedOptions().timeZone;if(a==="once"&&(!w||new Date(`${w}T${g}`)<=new Date)){N("Choisis une date et une heure à venir.");return}const ge=a==="weekly"?`Chaque lundi à ${g} · ${se}`:a==="daily"?`Chaque jour à ${g} · ${se}`:a==="once"?`Le ${new Date(`${w}T12:00`).toLocaleDateString("fr-FR")} à ${g} · ${se}`:"À la demande",oe=crypto.randomUUID();h(fe=>[{id:oe,instruction:B,status:a==="now"?"queued":"scheduled",schedule:ge,steps:[]},...fe]),x(oe),$("all"),u(""),N(a==="now"?"":"Programmation ajoutée à la démonstration. Aucun cron réel n’est activé."),a==="now"&&be(oe)}const Fe=k=>{var B;ce("action"),u(k),ne(!1),(B=R.current)==null||B.focus()},ze=te.filter(k=>z==="all"||k.status===z);return e.jsx("div",{className:"kad-view",children:e.jsxs("div",{className:"kad-content",children:[e.jsxs("header",{className:"kad-header",children:[e.jsxs("div",{children:[e.jsx("h1",{children:"Agent"}),e.jsx("p",{children:"Recherche de mots-clés"})]}),pe&&e.jsx("span",{role:"status",children:"Une action en cours"})]}),t&&e.jsx("p",{className:"kad-demo",children:"Aperçu local avec des données fictives. Les lancements et les programmations sont simulés."}),e.jsxs("section",{className:"kad-new-action","aria-labelledby":"kad-new-title",children:[e.jsxs("div",{className:"kad-section-heading",children:[e.jsx("h2",{id:"kad-new-title",children:"Que veux-tu confier à l’agent ?"}),J==="action"&&e.jsxs("button",{className:"kad-text-button",type:"button","aria-expanded":he,"aria-controls":"kad-examples",onClick:()=>ne(k=>!k),children:["Nos skills ",e.jsx(St,{size:14})]})]}),e.jsxs("div",{className:"kad-entry-modes","aria-label":"Choisir comment commencer",children:[e.jsx("button",{"aria-pressed":J==="discuss",onClick:()=>ce("discuss"),children:"Discuter"}),e.jsx("button",{"aria-pressed":J==="action",onClick:()=>ce("action"),children:"Préparer une action"})]}),J==="discuss"?e.jsxs("form",{onSubmit:k=>{if(k.preventDefault(),!(!G.trim()||pe)){if(t){N("Le chat réel est disponible dans ton projet. Dans cet aperçu sans connexion, choisis « Préparer une action » pour essayer les consignes issues de nos skills.");return}s==null||s(Cs(G.trim()))}},children:[e.jsx("label",{className:"kad-field-label",htmlFor:"kad-question",children:"Explique ce que tu cherches à obtenir"}),e.jsx("textarea",{id:"kad-question",value:G,onChange:k=>je(k.target.value),placeholder:"Je veux attirer plus de demandes pour mes formations. Par quoi commencer ?",maxLength:5e3,required:!0,rows:3}),e.jsxs("div",{className:"kad-form-footer",children:[e.jsx("p",{className:"kad-send-note",children:"L’échange continue dans le chat du projet pour préciser le besoin et les actions possibles."}),e.jsx("button",{className:"kad-primary",disabled:!G.trim()||pe||!t&&!s,children:"Discuter dans le chat"})]})]}):e.jsxs(e.Fragment,{children:[he&&e.jsxs("div",{id:"kad-examples",className:"kad-skill-list",children:[e.jsx("p",{className:"kad-send-note",children:"Choisis un résultat à produire avec nos skills, puis ajuste la consigne avant de lancer."}),_s.map(k=>e.jsxs("div",{className:"kad-skill-row",children:[e.jsxs("div",{children:[e.jsx("strong",{children:k.title}),e.jsx("p",{children:k.result}),e.jsxs("small",{children:["Méthode : ",k.method," · ",k.requires]})]}),e.jsx("button",{className:"kad-text-button",onClick:()=>Fe(k.prompt),"aria-label":`Préparer : ${k.title}`,children:"Préparer"})]},k.skill))]}),e.jsxs("form",{onSubmit:Le,children:[e.jsx("label",{className:"kad-field-label",htmlFor:"kad-instru
18ction",children:"Consigne à exécuter"}),e.jsx("textarea",{ref:R,id:"kad-instruction",value:c,onChange:k=>u(k.target.value),placeholder:"Ex. Trouve les requêtes décisionnelles pour mon offre de formation Lean.",maxLength:5e3,required:!0,rows:3,"aria-describedby":"kad-send-note"}),e.jsxs("div",{className:"kad-form-footer",children:[e.jsxs("div",{className:"kad-scheduling",children:[e.jsx("label",{htmlFor:"kad-timing",children:"Exécuter"}),e.jsxs("select",{id:"kad-timing",value:a,onChange:k=>p(k.target.value),children:[e.jsx("option",{value:"now",children:"Maintenant"}),e.jsx("option",{disabled:!t,value:"once",children:"À une date précise"}),e.jsx("option",{disabled:!t,value:"daily",children:"Chaque jour"}),e.jsx("option",{disabled:!t,value:"weekly",children:"Chaque lundi"})]}),a==="once"&&e.jsx("input",{type:"date","aria-label":"Date d’exécution",required:!0,value:w,onChange:k=>m(k.target.value)}),a!=="now"&&e.jsx("input",{type:"time","aria-label":"Heure d’exécution",required:!0,value:g,onChange:k=>y(k.target.value)})]}),e.jsx("button",{className:"kad-primary",type:"submit",disabled:!c.trim()||pe&&a==="now",children:a==="now"?"Lancer l’exécution":"Programmer l’exécution"})]}),e.jsx("p",{className:"kad-send-note",id:"kad-send-note",children:t?a==="now"?"Le lancement simule le travail de l’agent.":`Horaire local : ${Intl.DateTimeFormat().resolvedOptions().timeZone}. Programmation de démonstration.`:"L’agent exécutera la consigne avec le contexte du projet et les outils disponibles. Tu retrouveras ici ses étapes et sa restitution. La programmation automatique n’est pas encore disponible."})]})]})]}),b&&e.jsxs("div",{className:"kad-notice",role:"status",children:[b,e.jsx("button",{"aria-label":"Fermer le message",onClick:()=>N(""),children:e.jsx(Nn,{size:15})})]}),e.jsxs("section",{className:"kad-work","aria-labelledby":"kad-work-title",children:[e.jsxs("div",{className:"kad-section-heading kad-work-heading",children:[e.jsxs("h2",{id:"kad-work-title",children:["Travaux ",e.jsx("span",{children:te.length})]}),e.jsxs("label",{className:"kad-filter",children:["Afficher",e.jsxs("select",{value:z,onChange:k=>{$(k.target.value),x(null)},children:[e.jsx("option",{value:"all",children:"Tous les travaux"}),e.jsx("option",{value:"queued",children:"À lancer"}),e.jsx("option",{value:"running",children:"En cours"}),e.jsx("option",{value:"scheduled",children:"Planifiés"}),e.jsx("option",{value:"done",children:"Terminés"}),e.jsx("option",{value:"needs_input",children:"À préciser"}),e.jsx("option",{value:"error",children:"À reprendre"})]})]})]}),e.jsxs("div",{className:`kad-workspace${I?" has-selection":""}`,children:[e.jsx("section",{className:"kad-task-list","aria-label":"Travaux confiés à l’agent",children:ze.length?ze.map(k=>e.jsxs("button",{className:`kad-task${j===k.id?" selected":""}`,"aria-pressed":j===k.id,onClick:()=>{x(k.id),L(k.status==="done"?"result":"activity")},children:[e.jsx("strong",{children:k.instruction}),e.jsxs("span",{className:"kad-task-meta",children:[e.jsx("span",{className:`kad-state ${k.status}`,children:Fn[k.status]}),e.jsx("span",{children:k.schedule})]})]},k.id)):e.jsxs("div",{className:"kad-empty",children:[e.jsx("h3",{children:te.length?"Aucun travail avec ce filtre.":"Aucun travail pour le moment."}),e.jsx("p",{children:te.length?"Choisis un autre état pour retrouver tes actions.":"Rédige une consigne pour lancer la première action."}),te.length>0&&e.jsx("button",{className:"kad-text-button",onClick:()=>$("all"),children:"Afficher tous les travaux"})]})}),e.jsx("section",{className:"kad-detail","aria-label":"Lecture du travail sélectionné",children:I?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"kad-detail-heading",children:[e.jsxs("button",{className:"kad-back kad-text-button",onClick:()=>x(null),children:[e.jsx(Ur,{size:14}),"Travaux"]}),e.jsx("span",{className:`kad-state ${I.status}`,children:Fn[I.status]}),e.jsx("button",{className:"kad-close","aria-label":"Fermer le détail",onClick:()=>x(null),children:e.jsx(Nn,{size:17})})]}),e.jsx("h3",{className:"kad-task-title",children:I.instruction}),e.jsx("p",{className:"kad-task-schedule",children:I.schedule}),e.jsxs("div",{className:"kad-execution-summary",role:"status",children:[e.jsx("strong",{children:I.status==="running"?"Exécution en cours":I.status==="done"?"Action terminée":I.status==="needs_input"?"L’agent attend tes précisions":I.status==="error"?"Exécution interrompue ou en erreur":I.status==="scheduled"?"Exécution programmée":"En attente de lancement"}),e.jsx("p",{children:I.status==="running"?`${I.steps.filter(k=>k.done).length} étape(s) terminée(s). ${((Y=I.steps.find(k=>!k.done))==null?void 0:Y.label)||"Traitement de la consigne."}`:I.status==="done"?"La restitution est disponible. Le détail des étapes reste consultable.":I.status==="needs_input"?"Réponds dans le chat pour permettre à l’agent de continuer cette action.":I.status==="error"?"Consulte les étapes et le message reçu avant de reprendre.":I.status==="scheduled"?"Le travail n’a pas encore commencé.":"Aucune exécution enregistrée."}),I.status==="done"&&T!=="result"&&e.jsx("button",{className:"kad-text-button",onClick:()=>L("result"),children:"Voir le résultat"})]}),e.jsxs("div",{className:"kad-detail-tabs","aria-label":"Contenu du travail",children:[e.jsx("button",{"aria-pressed":T==="activity",onClick:()=>L("activity"),children:"Activité"}),e.jsx("button",{"aria-pressed":T==="result",onClick:()=>L("result"),children:"Résultat"})]}),T==="activity"?e.jsxs("div",{className:"kad-activity",children:[I.steps.length?e.jsx("ol",{children:I.steps.map((k,B)=>e.jsxs("li",{children:[e.jsx("span",{className:"kad-stage-state",children:k.done?"Terminée":I.status==="running"&&B===I.steps.findIndex(se=>!se.done)?"En cours":I.status==="running"?"À venir":"Non terminée"}),e.jsxs("div",{className:"kad-stage-content",children:[e.jsx("strong",{children:k.label}),k.detail&&e.jsx("p",{children:k.detail}),k.debut&&e.jsxs("small",{children:["Début à ",new Date(k.debut).toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit",second:"2-digit"}),k.fin?` · durée ${Math.max(0,Math.round((k.fin-k.debut)/1e3))} s`:""]}),k.data&&e.jsxs("details",{children:[e.jsx("summary",{children:k.data.titre}),e.jsx("ul",{children:k.data.lignes.map((se,ge)=>e.jsx("li",{children:se},ge))})]})]})]},`${k.label}-${B}`))}):e.jsx("p",{children:I.status==="scheduled"?"En attente du créneau prévu. La programmation est simulée dans cet aperçu.":"Aucune activité enregistrée."}),I.status==="done"&&e.jsx("button",{className:"kad-text-button",onClick:()=>L("result"),children:"Lire le résultat"})]}):e.jsx("div",{className:"kad-result",children:I.output?e.jsxs(e.Fragment,{children:[e.jsx(Ct,{remarkPlugins:[It],components:pn,children:at(I.output).clean}),/```questions/.test(I.output)&&e.jsx("p",{children:"L’agent demande des précisions. Ouvre l’échange pour lui répondre."})]}):e.jsx("p",{children:I.status==="running"?"Le résultat sera disponible à la fin du travail.":"Aucun résultat disponible."})}),e.jsxs("footer",{className:"kad-detail-footer",children:[t&&I.status==="queued"&&e.jsx("button",{className:"kad-primary",disabled:pe,onClick:()=>be(I.id),children:"Lancer la simulation"}),t&&I.status==="scheduled"&&e.jsx("button",{className:"kad-text-button",onClick:()=>{h(k=>k.map(B=>B.id===I.id?{...B,status:"queued",schedule:"À la demande"}:B)),N("Programmation retirée. L’action reste disponible à lancer.")},children:"Retirer la programmation"}),t&&I.status==="done"&&e.jsx("button",{className:"kad-text-button",onClick:()=>Fe(`À partir de cette action : « ${I.instruction} », approfondis `),children:"Demander une suite"}),!t&&e.jsx("button",{className:"kad-text-button",onClick:()=>i==null?void 0:i(I.id),children:"Ouvrir dans le chat"})]})]}):e.jsx("div",{className:"kad-empty",children:e.jsx("p",{children:"Sélectionne un travail pour consulter son activité et son résultat."})})})]})]}),o&&e.jsxs("section",{className:"kad-legacy",children:[e.jsxs("button",{className:"kad-text-button",onClick:()=>q(!W),"aria-expanded":W,children:["Livrables précédents ",e.jsx(St,{size:14})]}),W&&o]})]})})}const P={text:"#111827",muted:"#6B7280",pale:"#9CA3AF",border:"#E5E7EB",page:"#F4F5F7",warn:"#B45309"},Wt={P1:{bg:"rgba(10,143,111,0.10)",text:"#087A5E"},P2:{bg:"rgba(217,119,6,0.10)",text:"#B45309"},P3:{bg:"rgba(107,114,128,0.10)",text:"#4B5563"}}
18,Tn={élevé:{bg:"rgba(220,38,38,0.10)",text:"#B91C1C"},moyen:{bg:"rgba(217,119,6,0.10)",text:"#B45309"},faible:{bg:"rgba(5,150,105,0.10)",text:"#047857"}},Rs=()=>({"recherche en direct":E.t("ws_strategiegeoview.leMoteurVaChercher"),"mémoire du modèle":E.t("ws_strategiegeoview.aucuneRechercheDclencheLe"),"page éditeur citée":E.t("ws_strategiegeoview.votrePagePeuttre")}),wt=25;function tn({label:t,style:n}){return e.jsx("span",{style:{background:n.bg,color:n.text,fontSize:11,fontWeight:600,padding:"2px 8px",borderRadius:999,whiteSpace:"nowrap"},children:t})}function Ke({titre:t,compte:n,hint:r,ouvertParDefaut:s=!1,children:i}){const[o,c]=l.useState(s);return e.jsxs("section",{style:{background:"#fff",border:`1px solid ${P.border}`,borderRadius:14,marginBottom:12,overflow:"hidden"},children:[e.jsxs("button",{onClick:()=>c(u=>!u),style:{width:"100%",display:"flex",alignItems:"center",gap:12,background:"none",border:"none",padding:"15px 18px",cursor:"pointer",textAlign:"left"},children:[e.jsx("span",{style:{color:P.pale,display:"flex",flexShrink:0,transform:o?"none":"rotate(-90deg)",transition:"transform .15s"},children:e.jsx("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.6",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}),e.jsx("span",{style:{flex:1,minWidth:0,fontSize:14.5,fontWeight:650,color:P.text},children:t}),n&&e.jsx("span",{style:{fontSize:12.5,color:P.muted,fontVariantNumeric:"tabular-nums",flexShrink:0},children:n})]}),o&&e.jsxs("div",{style:{padding:"0 18px 18px"},children:[r&&e.jsx("p",{style:{fontSize:12.5,color:P.muted,margin:"0 0 14px",lineHeight:1.55},children:r}),i]})]})}function Mt({valeur:t,libelle:n,appoint:r}){return e.jsxs("div",{style:{flex:"1 1 120px",minWidth:0},children:[e.jsx("div",{style:{fontSize:23,fontWeight:700,color:P.text,letterSpacing:"-0.02em",fontVariantNumeric:"tabular-nums",lineHeight:1.1},children:t}),e.jsx("div",{style:{fontSize:12.5,color:P.muted,marginTop:3,lineHeight:1.4},children:n}),r&&e.jsx("div",{style:{fontSize:11.5,color:P.pale,marginTop:1},children:r})]})}function Ne({label:t,valeur:n}){return n?e.jsxs("div",{style:{fontSize:13,color:P.muted,marginTop:4,lineHeight:1.5},children:[e.jsxs("span",{style:{color:P.pale},children:[t," "]}),n]}):null}function Ns({data:t}){var d,h,j,x,z,$,T,L;const{t:n}=ee(),[r,s]=l.useState("toutes"),[i,o]=l.useState(""),[c,u]=l.useState(wt),a=t.univers_requetes||[],p=a.filter(b=>b.volume!=null).length,g=l.useMemo(()=>{const b=i.trim().toLowerCase();return a.filter(N=>r!=="toutes"&&N.priorite!==r?!1:b?`${N.query} ${N.query_longue||""} ${N.intention||""} ${N.chemin_citation||""} ${N.module||""}`.toLowerCase().includes(b):!0)},[a,r,i]),y=(t.architecture||[]).reduce((b,N)=>{var W;return b+(Number(N.nombre)||(((W=N.pages)==null?void 0:W.length)??0))},0),w=[(d=t.plan_90j)==null?void 0:d.j1_30,(h=t.plan_90j)==null?void 0:h.j31_60,(j=t.plan_90j)==null?void 0:j.j61_90].reduce((b,N)=>b+((N==null?void 0:N.length)||0),0),m=(t.proof_map||[]).filter(b=>b.risque==="élevé").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{background:"#fff",border:`1px solid ${P.border}`,borderRadius:14,padding:"20px 22px",marginBottom:12},children:[e.jsx("p",{style:{fontSize:14.5,lineHeight:1.65,color:P.text,margin:0,whiteSpace:"pre-line"},children:t.diagnostic||n("x_strategiegeoview.diagnosticNonProduit")}),e.jsxs("div",{style:{display:"flex",gap:20,flexWrap:"wrap",marginTop:20,paddingTop:18,borderTop:`1px solid ${P.border}`},children:[e.jsx(Mt,{valeur:String(a.length),libelle:n("ws_geo.requetes"),appoint:n("ws_geo.dontMesurees",{n:p})}),e.jsx(Mt,{valeur:String(y),libelle:n("ws_geo.pagesAProduire")}),e.jsx(Mt,{valeur:String(w),libelle:n("ws_geo.actions90")}),e.jsx(Mt,{valeur:String(m),libelle:n("ws_geo.affirmationsRisquees"),appoint:m?n("ws_geo.aEtayer"):void 0})]})]}),a.length>0&&e.jsxs(Ke,{titre:n("ws_strategiegeoview.universDeRequtes"),compte:n("ws_geo.compteRequetes",{total:a.length,mesurees:p}),hint:n("ws_geo.hintRequetes"),children:[e.jsxs("div",{style:{display:"flex",gap:8,marginBottom:12,flexWrap:"wrap",alignItems:"center"},children:[e.jsx("input",{value:i,onChange:b=>{o(b.target.value),u(wt)},placeholder:n("ws_geo.chercherUneRequete"),style:{flex:"1 1 200px",minWidth:0,background:P.page,border:`1px solid ${P.border}`,borderRadius:10,padding:"8px 12px",fontSize:13,color:P.text,outline:"none",fontFamily:"inherit"}}),["toutes","P1","P2","P3"].map(b=>e.jsx("button",{onClick:()=>{s(b),u(wt)},style:{fontSize:12,fontWeight:600,padding:"6px 12px",borderRadius:999,border:`1px solid ${r===b?P.text:P.border}`,background:r===b?P.text:"#fff",color:r===b?"#fff":P.text,cursor:"pointer"},children:b==="toutes"?n("ws_geo.toutes"):b},b))]}),g.length===0?e.jsx("div",{style:{fontSize:13,color:P.muted,padding:"18px 0"},children:n("ws_geo.aucuneRequete")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[e.jsx("thead",{children:e.jsx("tr",{style:{borderBottom:`1px solid ${P.border}`},children:[n("ws_strategiegeoview.requte"),n("ws_strategiegeoview.intention"),n("f_strategiegeoview.demande"),n("ws_strategiegeoview.cheminDeCitation"),n("ws_strategiegeoview.priorit")].map(b=>e.jsx("th",{style:{textAlign:"left",padding:"8px 10px",fontSize:11,textTransform:"uppercase",letterSpacing:"0.05em",color:P.pale,fontWeight:600,whiteSpace:"nowrap"},children:b},b))})}),e.jsx("tbody",{children:g.slice(0,c).map((b,N)=>e.jsxs("tr",{style:{borderBottom:`1px solid ${P.border}`},children:[e.jsxs("td",{style:{padding:"10px",color:P.text,fontWeight:500,minWidth:220},children:[b.query,b.query_longue&&b.query_longue!==b.query&&e.jsxs("div",{style:{fontSize:12,color:P.muted,marginTop:3},children:[n("ws_geo.poseeAUneIa")," ",b.query_longue]}),b.justification&&e.jsx("div",{style:{fontSize:12,color:P.pale,marginTop:3},children:b.justification})]}),e.jsx("td",{style:{padding:"10px",color:P.muted,whiteSpace:"nowrap"},children:b.intention||"·"}),e.jsx("td",{style:{padding:"10px",color:P.text,whiteSpace:"nowrap",fontVariantNumeric:"tabular-nums"},children:b.volume==null?e.jsx("span",{style:{color:P.pale},children:n("ws_strategiegeoview.nonMesur")}
18):e.jsxs(e.Fragment,{children:[b.volume.toLocaleString("fr-FR")," ",e.jsx("span",{style:{color:P.pale},children:"/mois"})]})}),e.jsx("td",{style:{padding:"10px",color:P.muted},children:e.jsx("span",{title:Rs()[b.chemin_citation||""]||"",style:{borderBottom:`1px dotted ${P.border}`,cursor:"help"},children:b.chemin_citation||"·"})}),e.jsx("td",{style:{padding:"10px"},children:e.jsx(tn,{label:b.priorite||"P3",style:Wt[b.priorite||"P3"]||Wt.P3})})]},N))})]})}),g.length>c&&e.jsx("button",{onClick:()=>u(b=>b+wt),style:{marginTop:12,background:"#fff",border:`1px solid ${P.border}`,borderRadius:999,padding:"8px 16px",fontSize:12.5,fontWeight:600,color:P.text,cursor:"pointer"},children:n("ws_geo.voirSuivantes",{n:Math.min(wt,g.length-c)})})]})]}),!!((x=t.architecture)!=null&&x.length)&&e.jsx(Ke,{titre:n("ws_strategiegeoview.architectureDeContenu"),compte:n("ws_geo.comptePages",{modules:t.architecture.length,pages:y}),hint:n("ws_strategiegeoview.leNombreDePages"),children:e.jsx("div",{style:{display:"grid",gap:10},children:t.architecture.map((b,N)=>{var W;return e.jsxs("div",{style:{border:`1px solid ${P.border}`,borderRadius:10,padding:14},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:12},children:[e.jsx("div",{style:{fontWeight:600,fontSize:14,color:P.text},children:b.module}),e.jsxs("div",{style:{fontSize:12,color:P.muted,whiteSpace:"nowrap"},children:[b.nombre," pages"]})]}),b.pourquoi&&e.jsx("div",{style:{fontSize:13,color:P.muted,marginTop:4,lineHeight:1.5},children:b.pourquoi}),!!((W=b.pages)!=null&&W.length)&&e.jsx("div",{style:{marginTop:10,display:"grid",gap:8},children:b.pages.map((q,J)=>e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"start",fontSize:13,color:P.text},children:[e.jsx("div",{style:{paddingTop:1},children:e.jsx(tn,{label:q.priorite||"P3",style:Wt[q.priorite||"P3"]||Wt.P3})}),e.jsxs("div",{style:{minWidth:0},children:[e.jsx("div",{style:{fontWeight:500},children:q.titre}),e.jsx(Ne,{label:n("ws_geo.requeteVisee"),valeur:q.requete_cible}),e.jsx(Ne,{label:n("ws_geo.preuveAFournir"),valeur:q.preuve_requise})]})]},J))})]},N)})})}),t.plan_90j&&w>0&&e.jsx(Ke,{titre:n("ws_geo.plan90"),compte:n("ws_geo.compteActions",{count:w}),hint:n("ws_strategiegeoview.chaqueActionPorteSa"),children:e.jsxs("div",{style:{display:"grid",gap:16},children:[[[n("ws_strategiegeoview.jours130"),t.plan_90j.j1_30],[n("ws_strategiegeoview.jours3160"),t.plan_90j.j31_60],[n("ws_strategiegeoview.jours6190"),t.plan_90j.j61_90]].map(([b,N])=>(N||[]).length>0&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.06em",color:P.pale,marginBottom:8,fontWeight:600},children:b}),e.jsx("div",{style:{display:"grid",gap:8},children:(N||[]).map((W,q)=>e.jsxs("div",{style:{border:`1px solid ${P.border}`,borderRadius:10,padding:12},children:[e.jsx("div",{style:{fontSize:13.5,color:P.text,fontWeight:500,lineHeight:1.5},children:W.action}),e.jsx(Ne,{label:n("ws_geo.pourquoi"),valeur:W.pourquoi}),e.jsx(Ne,{label:n("ws_geo.mesure"),valeur:W.mesure}),W.bloque_par&&e.jsxs("div",{style:{fontSize:13,color:P.warn,marginTop:4},children:[n("ws_geo.bloquePar")," ",W.bloque_par]})]},q))})]},b)),!!((z=t.plan_90j.risques)!=null&&z.length)&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.06em",color:P.pale,marginBottom:8,fontWeight:600},children:n("ws_strategiegeoview.ceQuiPeutFaire")}),e.jsx("ul",{style:{margin:0,paddingLeft:18,fontSize:13.5,color:P.muted,lineHeight:1.65},children:t.plan_90j.risques.map((b,N)=>e.jsx("li",{children:b},N))})]})]})}),!!(($=t.proof_map)!=null&&$.length)&&e.jsx(Ke,{titre:n("ws_strategiegeoview.preuvesEtManques"),compte:n("ws_geo.compteAffirmations",{count:t.proof_map.length}),hint:n("ws_strategiegeoview.uneAffirmationRisque"),children:e.jsx("div",{style:{display:"grid",gap:8},children:t.proof_map.map((b,N)=>e.jsxs("div",{style:{border:`1px solid ${P.border}`,borderRadius:10,padding:12},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,alignItems:"start"},children:[e.jsx("div",{style:{fontSize:13.5,color:P.text,fontWeight:500,lineHeight:1.5},children:b.affirmation}),b.risque&&e.jsx("div",{style:{flexShrink:0},children:e.jsx(tn,{label:`risque ${b.risque}`,style:Tn[b.risque]||Tn.moyen})})]}),e.jsx(Ne,{label:n("ws_geo.preuveActuelle"),valeur:b.preuve_actuelle}),e.jsx(Ne,{label:n("ws_geo.aFaire"),valeur:b.action})]},N))})}),t.entite&&Object.keys(t.entite).length>0&&e.jsx(Ke,{titre:n("ws_strategiegeoview.carteDEntit"),hint:n("ws_strategiegeoview.ceQueLesMoteurs"),children:e.jsxs("div",{style:{display:"grid",gap:12},children:[t.entite.produit&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.06em",color:P.pale,marginBottom:4,fontWeight:600},children:n("x_strategiegeoview.produit")}),e.jsx("div",{style:{fontSize:13.5,color:P.text,lineHeight:1.5},children:t.entite.produit})]}),Object.entries(t.entite).filter(([b,N])=>b!=="produit"&&Array.isArray(N)&&N.length>0).map(([b,N])=>e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.06em",color:P.pale,marginBottom:4,fontWeight:600},children:b.replace(/_/g," ")}),e.jsx("div",{style:{fontSize:13.5,color:P.text,lineHeight:1.6},children:N.join(" · ")})]},b))]})}),!!((T=t.autorite)!=null&&T.length)&&e.jsx(Ke,{titre:n("ws_strategiegeoview.autoritTierce"),compte:n("ws_geo.compteCibles",{count:t.autorite.length}),hint:n("ws_strategiegeoview.uneAffirmationSurVous"),children:e.jsx("div",{style:{display:"grid",gap:8},children:t.autorite.map((b,N)=>e.jsxs("div",{style:{border:`1px solid ${P.border}`,borderRadius:10,padding:12},children:[e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"baseline"},children:[e.jsx("div",{style:{fontSize:13.5,fontWeight:600,color:P.text},children:b.cible}),b.type&&e.jsx("span",{style:{fontSize:12,color:P.pale},children:b.type})]}),e.jsx(Ne,{label:n("ws_geo.pourquoi"),valeur:b.pourquoi}),e.jsx(Ne,{label:n("ws_geo.sujet"),valeur:b.sujet}),e.jsx(Ne,{label:n("ws_geo.preuveAFournir"),valeur:b.preuve_a_fournir})]},N))})}),!!((L=t.actifs_donnees)!=null&&L.length)&&e.jsx(Ke,{titre:n("ws_strategiegeoview.actifsDeDonnes"),compte:n("ws_geo.compteActifs",{count:t.actifs_donnees.length}),hint:n("ws_strategiegeoview.unActifDeDonnes"),children:e.jsx("div",{style:{display:"grid",gap:8},children:t.actifs_donnees.map((b,N)=>e.jsxs("div",{style:{border:`1px solid ${P.border}`,borderRadius:10,padding:12},children:[e.jsx("div",{style:{fontSize:13.5,fontWeight:600,color:P.text},children:b.nom}),e.jsx(Ne,{label:n("ws_geo.repondALa"),valeur:b.question}),e.jsx(Ne,{label:n("ws_geo.donnees"),valeur:b.dataset}),e.jsx(Ne,{label:n("ws_geo.methode"),valeur:b.methodologie}),e.jsx(Ne,{label:n("ws_geo.frequence"),valeur:b.frequence})]},N))})}),e.jsx("p",{style:{fontSize:12,color:P.pale,marginTop:6,lineHeight:1.5},children:n("ws_strategiegeoview.lesVolumesAffichsViennent")})]})}const Es=".txt,.csv,.json,.md,.docx,.pdf,.xlsx,.xls",As="TXT, MD, CSV, JSON, DOCX, PDF, XLSX",xn="qadence_kw_gsc_property";function fr(){try{return localStorage.getItem(xn)}catch{return null}}function $n(t){try{t?localStorage.setItem(xn,t):localStorage.removeItem(xn)}catch{}}function Ls(t){return t.replace(/^sc-domain:/,"").replace(/^https?:\/\//,"").replace(/\/$/,"")}
18const Wn={display:"flex",alignItems:"center",gap:7,background:"var(--bg-white)",border:"1px solid var(--border)",borderRadius:999,padding:"6px 12px",fontSize:12.5,fontWeight:500,color:"var(--text-secondary)",cursor:"pointer"};function Fs({siteProperty:t,siteName:n,onChoisir:r}={}){const{t:s}=ee(),[i,o]=l.useState([]),[c,u]=l.useState(t||null),[a,p]=l.useState(!1),g=!!n||!!r,y=l.useRef(0),w=l.useCallback(async()=>{const d=++y.current,{data:{user:h}}=await qe.auth.getUser();if(d!==y.current)return;if(!h){o([]);return}const{data:j}=await qe.from("google_connections").select("gsc_site").not("gsc_site","is",null);if(d!==y.current)return;const x=Array.from(new Set((j||[]).map(L=>L.gsc_site).filter(Boolean)));o(x);const z=t&&x.includes(t)?t:null,$=fr(),T=z||(g?null:$&&x.includes($)?$:x[0]||null);u(T),T&&$n(T)},[t,g]);l.useEffect(()=>{const d=w(),h=y.current;d.catch(()=>{h===y.current&&o([])}),new URLSearchParams(window.location.search).get("google_connected")==="true"&&window.history.replaceState({},"",window.location.pathname);const x=y;return()=>{x.current===h&&(x.current=h+1)}},[w]);async function m(){var d;p(!0);try{let{data:{user:h}}=await qe.auth.getUser();if(!h&&(h=((d=(await qe.auth.signInAnonymously()).data)==null?void 0:d.user)||null,!h)){window.location.href="/app2";return}const{data:j}=await qe.functions.invoke("google-auth",{body:{user_id:h.id,return_url:window.location.origin+"/app2"}}),x=j==null?void 0:j.url;if(x){window.location.href=x;return}p(!1)}catch{p(!1)}}return i.length>0?e.jsxs("div",{style:Wn,title:n?`Search Console du site ${n}`:s("rech_gscconnect.propritSearchConsoleUtilise"),children:[e.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"var(--success)",flexShrink:0}}),e.jsx("span",{style:{fontSize:10.5,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--text-muted, #9CA3AF)",flexShrink:0},children:"Search Console"}),e.jsxs("select",{"aria-label":s("chatUx.chooseProperty"),value:c||"",onChange:d=>{u(d.target.value),$n(d.target.value),r==null||r(d.target.value)},style:{border:"none",background:"none",outline:"none",fontSize:12.5,fontWeight:500,color:"var(--text-secondary)",cursor:"pointer",maxWidth:160},children:[e.jsx("option",{value:"",disabled:!0,children:s("chatUx.chooseProperty")}),i.map(d=>e.jsx("option",{value:d,children:Ls(d)},d))]})]}):e.jsxs("button",{onClick:m,disabled:a,style:{...Wn,opacity:a?.6:1},onMouseEnter:d=>{a||(d.currentTarget.style.borderColor="var(--accent)",d.currentTarget.style.color="var(--accent)")},onMouseLeave:d=>{d.currentTarget.style.borderColor="var(--border)",d.currentTarget.style.color="var(--text-secondary)"},children:[e.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#9CA3AF",flexShrink:0}}),a?"Connexion…":"Connecter Google"]})}const Ce={text:"#111827",muted:"#6B7280",pale:"#9CA3AF",border:"#E5E7EB",accent:"#0A8F6F",page:"#F4F5F7",ok:"#059669"},Ts={plan:[{cle:"collecte",attendu:"Collecte des requêtes réelles"},{cle:"mesure",attendu:"Mesure des volumes au Keyword Planner"},{cle:"clusters",attendu:"Regroupement : un groupe égale une page"},{cle:"decisionnel",attendu:"Classement par étage de décision"},{cle:"resistance",attendu:"Ce qu’une IA peut répondre à votre place"},{cle:"plan",attendu:"Décision : créer, renforcer, ou laisser"}],geo:[{cle:"lecture",attendu:"Lecture du projet"},{cle:"redaction",attendu:"Rédaction de la stratégie"},{cle:"mesure",attendu:"Mesure des volumes au Keyword Planner"},{cle:"enregistrement",attendu:"Enregistrement"}]};function Mn(t){try{return new Date(t).toLocaleTimeString("fr-FR",{hour:"2-digit",minute:"2-digit"})}catch{return""}}function $s(t,n){try{const r=Math.max(0,Math.round((n-new Date(t).getTime())/1e3));return r<60?`${r} s`:`${Math.floor(r/60)} min ${String(r%60).padStart(2,"0")}`}catch{return""}}function Ws({etat:t}){return t==="fait"?e.jsx("span",{style:{width:18,height:18,borderRadius:"50%",background:"rgba(5,150,105,0.12)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx("svg",{width:10,height:10,viewBox:"0 0 24 24",fill:"none",stroke:Ce.ok,strokeWidth:"3.4",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}
18):t==="encours"?e.jsx("span",{style:{width:18,height:18,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:Ce.accent,strokeWidth:"2.6",strokeLinecap:"round",style:{animation:"kchat-spin 1s linear infinite"},children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}):e.jsx("span",{style:{width:18,height:18,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx("span",{style:{width:7,height:7,borderRadius:"50%",border:`1.5px solid ${Ce.border}`}})})}function mr({kind:t,journal:n,phase:r,startedAt:s,error:i,titre:o}){var m;const{t:c}=ee(),[u,a]=l.useState(()=>Date.now()),p=r==="done"||r==="error";l.useEffect(()=>{if(p)return;const d=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(d)},[p]);const g=Ts[t],y=new Map(n.map(d=>[d.cle,d])),w=p?-1:g.findIndex(d=>!y.has(d.cle));return e.jsxs("div",{style:{background:"#fff",border:`1px solid ${Ce.border}`,borderRadius:14,overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,padding:"16px 20px",borderBottom:`1px solid ${Ce.border}`},children:[e.jsx("div",{style:{fontSize:14.5,fontWeight:650,color:Ce.text},children:o}),e.jsx("div",{style:{fontSize:12.5,color:Ce.muted,fontVariantNumeric:"tabular-nums"},children:p?Mn(((m=n[n.length-1])==null?void 0:m.at)||s):$s(s,u)})]}),e.jsx("div",{style:{padding:"6px 20px 16px"},children:g.map((d,h)=>{const j=y.get(d.cle),x=j?"fait":h===w?"encours":"attente",z=h===g.length-1;return e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",flexShrink:0},children:[e.jsx("div",{style:{paddingTop:12},children:e.jsx(Ws,{etat:x})}),!z&&e.jsx("div",{style:{flex:1,width:1.5,background:j?"rgba(5,150,105,0.22)":Ce.border,borderRadius:1,marginTop:2}})]}),e.jsxs("div",{style:{flex:1,minWidth:0,padding:"10px 0 12px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:13.5,fontWeight:j?600:500,color:x==="attente"?Ce.pale:Ce.text},children:j?j.titre:d.attendu}),j&&e.jsx("span",{style:{fontSize:11.5,color:Ce.pale,fontVariantNumeric:"tabular-nums"},children:Mn(j.at)})]}),(j==null?void 0:j.detail)&&e.jsx("div",{style:{fontSize:12.5,color:Ce.muted,lineHeight:1.55,marginTop:3},children:j.detail}),!j&&x==="encours"&&e.jsx("div",{style:{fontSize:12.5,color:Ce.muted,lineHeight:1.55,marginTop:3},children:c("rech_journal.enCours")})]})]},d.cle)})}),i&&e.jsx("div",{style:{borderTop:`1px solid ${Ce.border}`,background:"rgba(10,143,111,0.05)",padding:"12px 20px",fontSize:12.5,color:"#B91C1C",lineHeight:1.5},children:i}),!p&&e.jsx("div",{style:{borderTop:`1px solid ${Ce.border}`,background:Ce.page,padding:"11px 20px",fontSize:12.5,color:Ce.muted,lineHeight:1.5},children:c("rech_journal.fermerLaPage")})]})}const Z={text:"#111827",muted:"#6B7280",pale:"#9CA3AF",border:"#E5E7EB",accent:"#0A8F6F",page:"#F4F5F7"};function Ue({titre:t,children:n}){return e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,textTransform:"uppercase",letterSpacing:"0.06em",color:Z.pale,fontWeight:600,marginBottom:6},children:t}),n]})}function nn({items:t}){return e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:t.map((n,r)=>e.jsx("span",{style:{background:Z.page,border:`1px solid ${Z.border}`,borderRadius:999,padding:"4px 11px",fontSize:12.5,color:Z.text},children:n},r))})}function Ms({fiche:t,ficheLe:n,domaine:r,enCours:s,erreur:i,onRefaire:o}){var a,p,g,y,w,m;const{t:c}=ee(),u=e.jsx("button",{onClick:o,disabled:s,style:{background:t?"#fff":Z.accent,color:t?Z.text:"#fff",border:t?`1px solid ${Z.border}`:"none",borderRadius:999,padding:"8px 16px",fontSize:12.5,fontWeight:600,cursor:s?"wait":"pointer",opacity:s?.6:1},children:c(s?"rech_fiche.lecture":t?"rech_fiche.refaire":"rech_fiche.lire")});return r?!t||!t.promesse?e.jsxs("div",{style:{border:`1px dashed ${Z.border}`,borderRadius:14,background:"#fff",padding:"40px 28px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:15,color:Z.text,fontWeight:600,marginBottom:6},children:s?c("rech_fiche.lectureTitre",{domaine:r}):c("rech_fiche.videTitre")}),e.jsx("div",{style:{fontSize:13.5,color:Z.muted,lineHeight:1.5,maxWidth:520,margin:"0 auto 18px"},children:s?c("rech_fiche.lectureTexte"):c("rech_fiche.videTexte",{domaine:r})}),i&&e.jsx("div",{style:{fontSize:12.5,color:"#B91C1C",marginBottom:14},children:i}),!s&&u]}):e.jsxs("div",{children:[e.jsxs("div",{style:{background:"#fff",border:`1px solid ${Z.border}`,borderRadius:14,padding:"20px 22px",marginBottom:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[e.jsx("div",{style:{fontSize:18,fontWeight:700,color:Z.text,letterSpacing:"-0.015em"},children:t.nom||r}),u]}),t.promesse&&e.jsx("p",{style:{fontSize:14.5,lineHeight:1.6,color:Z.text,margin:"12px 0 0"},children:t.promesse}),t.activite&&e.jsx("p",{style:{fontSize:13.5,lineHeight:1.6,color:Z.muted,margin:"10px 0 0"},children:t.activite}),e.jsxs("div",{style:{display:"flex",gap:24,flexWrap:"wrap",marginTop:16,paddingTop:14,borderTop:`1px solid ${Z.border}`},children:[t.point_conversion&&e.jsx(Ue,{titre:c("rech_fiche.pointConversion"),children:e.jsx("div",{style:{fontSize:13.5,color:Z.text},children:t.point_conversion})}),t.zone&&e.jsx(Ue,{titre:c("rech_fiche.zone"),children:e.jsx("div",{style:{fontSize:13.5,color:Z.text},children:t.zone})})]})]}),e.jsxs("div",{style:{display:"grid",gap:12},children:[!!((a=t.offres)!=null&&a.length)&&e.jsx("div",{style:{background:"#fff",border:`1px solid ${Z.border}`,borderRadius:14,padding:"18px 20px"},children:e.jsx(Ue,{titre:c("rech_fiche.offres"),children:e.jsx("div",{style:{display:"grid",gap:8},children:t.offres.map((d,h)=>e.jsxs("div",{style:{border:`1px solid ${Z.border}`,borderRadius:10,padding:12},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,alignItems:"baseline"},children:[e.jsx("div",{style:{fontSize:13.5,fontWeight:600,color:Z.text},children:d.nom}),e.jsx("div",{style:{fontSize:12.5,color:d.prix?Z.text:Z.pale,whiteSpace:"nowrap"},children:d.prix||c("rech_fiche.prixNonPublie")})]}),d.description&&e.jsx("div",{style:{fontSize:13,color:Z.muted,marginTop:4,lineHeight:1.5},children:d.description})]},h))})})}),e.jsxs("div",{style:{background:"#fff",border:`1px solid ${Z.border}`,borderRadius:14,padding:"18px 20px",display:"grid",gap:16},children:[!!((p=t.cibles)!=null&&p.length)&&e.jsx(Ue,{titre:c("rech_fiche.cibles"),children:e.jsx(nn,{items:t.cibles})}),!!((g=t.preuves)!=null&&g.length)&&e.jsx(Ue,{titre:c("rech_fiche.preuves"),children:e.jsx(nn,{items:t.preuves})}),!!((y=t.vocabulaire)!=null&&y.length)&&e.jsx(Ue,{titre:c("rech_fiche.vocabulaire"),children:e.jsx(nn,{items:t.vocabulaire})})]}),!!((w=t.ce_qui_manque)!=null&&w.length)&&e.jsx("div",{style:{background:"#fff",border:`1px solid ${Z.border}`,borderRadius:14,padding:"18px 20px"},children:e.jsxs(Ue,{titre:c("rech_fiche.manque"),children:[e.jsx("p",{style:{fontSize:12.5,color:Z.muted,margin:"0 0 10px",lineHeight:1.55},children:c("rech_fiche.manqueHint")}),e.jsx("ul",{style:{margin:0,paddingLeft:18,fontSize:13.5,color:Z.text,lineHeight:1.7},children:t.ce_qui_manque.map((d,h)=>e.jsx("li",{children:d},h))})]})}
18),!!((m=t.pages_lues)!=null&&m.length)&&e.jsx("div",{style:{background:"#fff",border:`1px solid ${Z.border}`,borderRadius:14,padding:"18px 20px"},children:e.jsxs(Ue,{titre:c("rech_fiche.pagesLues",{count:t.pages_lues.length}),children:[e.jsx("p",{style:{fontSize:12.5,color:Z.muted,margin:"0 0 10px",lineHeight:1.55},children:c("rech_fiche.pagesLuesHint")}),e.jsx("div",{style:{display:"grid",gap:4},children:t.pages_lues.map((d,h)=>e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",style:{fontSize:12.5,color:Z.muted,textDecoration:"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d},h))})]})})]}),n&&e.jsx("p",{style:{fontSize:12,color:Z.pale,marginTop:10},children:c("rech_fiche.lue",{date:new Date(n).toLocaleDateString("fr-FR",{day:"2-digit",month:"long",year:"numeric"})})})]}):e.jsxs("div",{style:{border:`1px dashed ${Z.border}`,borderRadius:14,background:"#fff",padding:"40px 28px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:15,color:Z.text,fontWeight:600,marginBottom:6},children:c("rech_fiche.sansDomaineTitre")}),e.jsx("div",{style:{fontSize:13.5,color:Z.muted,lineHeight:1.5,maxWidth:480,margin:"0 auto"},children:c("rech_fiche.sansDomaineTexte")})]})}function wn(t){const n=t.filter(s=>s.role==="assistant"&&!s.isStreaming&&!s.isError&&!s.interrupted&&s.strategy).sort((s,i)=>s.strategy.generatedAt-i.strategy.generatedAt||s.id.localeCompare(i.id)),r=new Map;for(const s of n)for(const i of s.strategy.points)r.set(i.key,{...i,messageId:s.id,generatedAt:s.strategy.generatedAt});return[...r.values()].filter(s=>s.status==="active").sort((s,i)=>i.generatedAt-s.generatedAt||s.key.localeCompare(i.key))}const kn="#F4F5F7",_={text:"#111827",muted:"#6B7280",border:"#E5E7EB",accent:"#0A8F6F"},Oe=["#3450C0","#597BF2","#8AA5F6","#B6C5FA","#D6DEF6"],Bs="#047857",Sn="#B91C1C",le=t=>t==null||Number.isNaN(t)?"—":new Intl.NumberFormat("fr-FR").format(Math.round(t)),_n=(t,n=1)=>t==null||Number.isNaN(t)?"—":`${t.toFixed(n).replace(".",",")} %`,$e=t=>t==null||Number.isNaN(t)?"—":t.toFixed(1).replace(".",","),Me=t=>new Date(t+(t.length===10?"T12:00:00":"")).toLocaleDateString("fr-FR",{day:"2-digit",month:"short",year:"numeric"}),gn=t=>{const[n,r]=t.split("-");return new Date(Number(n),Number(r)-1,1).toLocaleDateString("fr-FR",{month:"short",year:"2-digit"})},Ds=t=>`${t.slice(0,4)}-${t.slice(4,6)}-${t.slice(6,8)}`,ut=t=>{try{return new URL(t).pathname||"/"}catch{return t}};function Be({title:t,subtitle:n,action:r,large:s=!1,children:i}){return e.jsx("div",{style:{height:"100%",overflowY:"auto",background:kn},children:e.jsxs("div",{style:{maxWidth:s?1180:980,margin:"0 auto",padding:"40px 28px 80px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16},children:[e.jsxs("div",{children:[e.jsx("div",{className:"qadence-title-gradient",style:{fontSize:34,fontWeight:700,letterSpacing:"-0.03em",lineHeight:1.15,width:"fit-content",maxWidth:"100%"},children:t}),n&&e.jsx("div",{style:{fontSize:16,color:_.muted,marginTop:10,lineHeight:1.65,maxWidth:680},children:n})]}),r&&e.jsx("div",{style:{flexShrink:0,paddingTop:2},children:r})]}),e.jsx("div",{style:{marginTop:28},children:i})]})})}function ht({children:t,style:n}){return e.jsx("div",{style:{background:"#fff",border:`1px solid ${_.border}`,borderRadius:14,...n},children:t})}function Cn({children:t}){return e.jsxs("div",{style:{display:"flex",gap:10,padding:"14px 16px",background:"#fff",border:`1px solid ${_.border}`,borderRadius:14,marginBottom:18},children:[e.jsx("div",{style:{width:3,borderRadius:2,background:_.accent,flexShrink:0}}),e.jsx("div",{style:{fontSize:13.5,color:_.text,lineHeight:1.6},children:t})]})}function We({mode:t,quoi:n,erreur:r}){const s=t==="loading"?`Lecture de ${n}…`:t==="error"?`${n} : lecture impossible${r?` (${r})`:""}. Rien n'est affiché plutôt qu'une donnée approchée.`:`${n} : rien d'enregistré pour ce site.`;return e.jsxs("div",{style:{border:`1px dashed ${_.border}`,borderRadius:14,background:"#fff",padding:"28px 24px",fontSize:13.5,color:_.muted,lineHeight:1.6},children:[t==="loading"&&e.jsx(Vt,{}),s]})}function Vt(){return e.jsx("span",{style:{display:"inline-block",width:12,height:12,marginRight:8,border:`2px solid ${_.border}`,borderTopColor:_.accent,borderRadius:"50%",animation:"dc-spin .7s linear infinite",verticalAlign:"-1px"},children:e.jsx("style",{children:"@keyframes dc-spin{to{transform:rotate(360deg)}}"})})}function jr({valeur:t}){if(t==null||t===0)return e.jsx("span",{style:{color:_.muted},children:"—"});const n=t>0;return e.jsxs("span",{style:{color:n?Bs:Sn,fontWeight:600,whiteSpace:"nowrap"},children:[n?"▲":"▼"," ",le(Math.abs(t))]})}function Ps({part:t,rang:n}){return e.jsx("div",{style:{height:6,borderRadius:3,background:"#EEF1F6",overflow:"hidden"},children:e.jsx("div",{style:{width:`${Math.max(1,Math.min(100,t*100))}%`,height:"100%",background:Oe[Math.min(n,Oe.length-1)],borderRadius:3}})})}function ct({onClick:t,children:n,primaire:r=!1,petit:s=!1}){return e.jsxs("button",{onClick:t,className:"dc-btn",style:{background:r?_.accent:"#fff",color:r?"#fff":_.text,border:r?"none":`1px solid ${_.border}`,borderRadius:s?8:10,padding:s?"6px 11px":"9px 16px",fontSize:s?12.5:13.5,fontWeight:600,cursor:"pointer"},children:[e.jsx("style",{children:".dc-btn{transition-property:background-color,color,scale;transition-duration:150ms;transition-timing-function:cubic-bezier(.2,0,0,1)}.dc-btn:active{scale:.96}"}),n]})}function Je({label:t,valeur:n,note:r}){return e.jsxs("div",{style:{background:kn,borderRadius:10,padding:"10px 12px"},children:[e.jsx("div",{style:{fontSize:11,color:_.muted,textTransform:"uppercase",letterSpacing:"0.05em",fontWeight:600},children:t}),e.jsx("div",{style:{fontSize:17,color:_.text,fontWeight:600,marginTop:3,fontVariantNumeric:"tabular-nums"},children:n}),r&&e.jsx("div",{style:{fontSize:11.5,color:_.muted,marginTop:2,lineHeight:1.4},children:r})]})}function br({titre:t,sousTitre:n,onClose:r,children:s}){return l.useEffect(()=>{const i=o=>{o.key==="Escape"&&r()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[r]),e.jsxs("div",{style:{position:"fixed",top:0,right:0,bottom:0,width:"min(460px, 100vw)",background:"#fff",borderLeft:`1px solid ${_.border}`,boxShadow:"-24px 0 48px -32px rgba(16,24,40,.28)",zIndex:90,display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"18px 20px 14px",borderBottom:`1px solid ${_.border}
18`,display:"flex",alignItems:"flex-start",gap:12},children:[e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsx("div",{style:{fontSize:15.5,fontWeight:700,color:_.text,wordBreak:"break-word",lineHeight:1.35},children:t}),n&&e.jsx("div",{style:{fontSize:12.5,color:_.muted,marginTop:4},children:n})]}),e.jsx("button",{onClick:r,"aria-label":"Fermer",className:"dc-btn",style:{background:"none",border:"none",cursor:"pointer",color:_.muted,fontSize:20,lineHeight:1,padding:4,borderRadius:8},children:"×"})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"16px 20px 28px"},children:s})]})}function fn({titre:t,aside:n,children:r}){return e.jsxs("div",{style:{marginTop:20},children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10,marginBottom:8},children:[e.jsx("div",{style:{fontSize:11.5,color:_.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700},children:t}),n]}),r]})}function Ut({titre:t,lignes:n}){return e.jsxs("div",{style:{border:`1px dashed ${_.border}`,borderRadius:14,background:"#fff",padding:"16px 18px"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:700,color:_.text},children:t}),e.jsx("ul",{style:{margin:"8px 0 0",padding:"0 0 0 18px",fontSize:13,color:_.muted,lineHeight:1.7},children:n.map(r=>e.jsx("li",{children:r},r))})]})}async function mn(t,n=2){let r="";for(let s=0;s<n;s++){s&&await new Promise(o=>setTimeout(o,1800));const i=await fetch(`/__fetch?url=${encodeURIComponent(t)}`);if(i.ok)return await i.text();if(r=`HTTP ${i.status}`,i.status<500)break}throw new Error(r)}async function Is(t,n,r){const s=[...t];await Promise.all(Array.from({length:Math.min(n,s.length)},async()=>{for(let i=s.shift();i!==void 0;i=s.shift())await r(i)}))}async function yr(t){const n=`https://web.archive.org/cdx/search/cdx?url=${encodeURIComponent(t)}&output=json&fl=timestamp,digest,statuscode&collapse=digest&limit=400`,r=await mn(n);let s;try{s=JSON.parse(r)}catch{throw new Error("réponse illisible")}return!Array.isArray(s)||s.length<2?[]:s.slice(1).filter(i=>!i[2]||i[2]==="200"||i[2]==="-").map(i=>({date:Ds(i[0]),digest:i[1]}))}async function vr(t){var a,p,g,y,w;const n=t.startsWith("http")?t:`https://${t}`,r=await mn(`${n.replace(/\/$/,"")}/sitemap.xml`),s=m=>new DOMParser().parseFromString(m,"text/xml"),i=s(r),o=[...i.querySelectorAll("sitemapindex > sitemap > loc")].map(m=>m.textContent||"").filter(Boolean),c=o.length?await Promise.all(o.slice(0,5).map(async m=>{try{return s(await mn(m))}catch{return null}})):[i],u=[];for(const m of c)if(m)for(const d of m.querySelectorAll("url")){const h=(p=(a=d.querySelector("loc"))==null?void 0:a.textContent)==null?void 0:p.trim();h&&u.push({url:h,lastmod:((w=(y=(g=d.querySelector("lastmod"))==null?void 0:g.textContent)==null?void 0:y.trim())==null?void 0:w.slice(0,10))||null})}return u}const Os=1e3,Hs=500,Vs=2500;function Us(t){var i,o;const n=t.byQuery.reduce((c,u)=>c+(u.impressions||0),0),r=((i=t.totals)==null?void 0:i.impressions)||0,s=Math.max(0,r-n);return{total:r,listees:n,manquant:s,part:r?s/r*100:0,tronque:t.byQuery.length>=Os,clicsManquants:Math.max(0,(((o=t.totals)==null?void 0:o.clicks)||0)-t.byQuery.reduce((c,u)=>c+(u.clicks||0),0))}}function Js(t){const n=new Map;for(const r of t.byQueryPage||[]){const s=n.get(r.page)||[];s.push(r),n.set(r.page,s)}for(const r of n.values())r.sort((s,i)=>i.impressions-s.impressions);return n}function Gs({userId:t,gscSite:n,domain:r}){const s=yn(n,t),[i,o]=l.useState("impressions"),[c,u]=l.useState(null),a=s.payload,p=l.useMemo(()=>a?Js(a):new Map,[a]),g=l.useMemo(()=>{if(!a)return[];const m=new Map((a.prevByPage||[]).map(h=>[h.page,h])),d=(a.byPage||[]).map(h=>{const j=(p.get(h.page)||[]).reduce((x,z)=>x+z.impressions,0);return{...h,requetes:(p.get(h.page)||[]).length,masque:Math.max(0,h.impressions-j),deltaClics:m.has(h.page)?h.clicks-(m.get(h.page).clicks||0):null}});return d.sort((h,j)=>i==="position"?h.position-j.position:j[i]-h[i]),d},[a,p,i]);if(s.loading)return e.jsx(Be,{title:"Pages",large:!0,children:e.jsx(We,{mode:"loading",quoi:"la Search Console"})});if(!a)return e.jsx(Be,{title:"Pages",subtitle:"La vie de chaque URL, conservée jour après jour.",large:!0,children:e.jsx(We,{mode:s.mode==="error"?"error":"empty",quoi:"la Search Console"})});const y=Math.max(...g.map(m=>m.impressions),1),w=c?g.find(m=>m.page===c):null;
18return e.jsxs(Be,{title:"Pages",subtitle:"Une fiche par URL : ce qu'elle capte, ce que Google n'y rattache pas, et ce que son contenu a été.",large:!0,action:e.jsxs("div",{style:{fontSize:12.5,color:_.muted},children:[a.range.startDate," → ",a.range.endDate]}),children:[e.jsxs(Cn,{children:["Google liste ",le(a.byPage.length)," pages sur la fenêtre servie",a.byPage.length>=Hs?" (liste tronquée à 500 lignes par l'API)":"",", sans jamais croiser une URL avec les requêtes qui l'amènent. Le croisement ci-dessous est reconstruit ligne à ligne, et la colonne ",e.jsx("strong",{children:"non rattaché"})," est la part d'impressions que Google refuse d'attribuer à une requête affichée."]}),e.jsxs(ht,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:`1px solid ${_.border}`},children:[e.jsx("div",{style:{fontSize:12,color:_.muted,fontWeight:600},children:"Trier par"}),[["impressions","Impressions"],["clicks","Clics"],["position","Position"],["masque","Non rattaché"]].map(([m,d])=>e.jsx("button",{onClick:()=>o(m),className:"dc-btn",style:{background:i===m?"#EAF3F0":"transparent",color:i===m?_.accent:_.muted,border:"none",borderRadius:8,padding:"5px 10px",fontSize:12.5,fontWeight:600,cursor:"pointer"},children:d},m))]}),e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{color:_.muted,fontSize:11.5,textTransform:"uppercase",letterSpacing:"0.05em"},children:[e.jsx("th",{style:{textAlign:"left",padding:"10px 16px",fontWeight:700},children:"URL"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"Clics"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"28 j préc."}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"Impressions"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"Position"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"Requêtes"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 16px",fontWeight:700},children:"Non rattaché"})]})}),e.jsx("tbody",{children:g.slice(0,200).map((m,d)=>e.jsxs("tr",{onClick:()=>u(m.page),className:"dc-row",style:{borderTop:`1px solid ${_.border}`,cursor:"pointer",background:c===m.page?"#F7FAF9":"#fff"},children:[e.jsxs("td",{style:{padding:"10px 16px",maxWidth:420},children:[e.jsx("div",{style:{color:_.text,fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ut(m.page)}),e.jsx("div",{style:{marginTop:6,maxWidth:260},children:e.jsx(Ps,{part:m.impressions/y,rang:Math.min(4,Math.floor(d/12))})})]}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:le(m.clicks)}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:e.jsx(jr,{valeur:m.deltaClics})}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:le(m.impressions)}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:$e(m.position)}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:le(m.requetes)}),e.jsxs("td",{style:{padding:"10px 16px",textAlign:"right",fontVariantNumeric:"tabular-nums",color:m.masque>0?_.text:_.muted},children:[le(m.masque),m.impressions>0&&e.jsxs("span",{style:{color:_.muted,fontSize:11.5},children:[" · ",_n(m.masque/m.impressions*100,0)]})]})]},m.page))})]})}),e.jsx("style",{children:".dc-row{transition-property:background-color;transition-duration:120ms}.dc-row:hover{background:#F7FAF9 !important}"})]}),a.byQueryPage.length>=Vs&&e.jsx("div",{style:{fontSize:12.5,color:_.muted,marginTop:10,lineHeight:1.6},children:"Le croisement requête × page est remonté par l'API à 2 500 lignes : la colonne « non rattaché » de ce site contient donc aussi de la queue tronquée, pas seulement des requêtes anonymisées."}),w&&e.jsx(br,{titre:ut(w.page),sousTitre:w.page,onClose:()=>u(null),children:e.jsx(Qs,{page:w,requetes:p.get(w.page)||[],userId:t,gscSite:n,domain:r})})]})}function Qs({page:t,requetes:n,domain:r}){const[s,i]=l.useState({etat:"idle"}),o=()=>{i({etat:"load"}),yr(t.page).then(c=>i({etat:"ok",data:c})).catch(c=>i({etat:"err",err:String(c.message||c)}))};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx(Je,{label:"Clics 28 j",valeur:le(t.clicks)}),e.jsx(Je,{label:"Impressions",valeur:le(t.impressions)}),e.jsx(Je,{label:"Position",valeur:$e(t.position)}),e.jsx(Je,{label:"Non rattaché",valeur:le(t.masque),note:t.impressions?`${_n(t.masque/t.impressions*100,0)} des impressions`:void 0})]}),e.jsx(fn,{titre:`Requêtes rattachées (${n.length})`,children:n.length===0?e.jsx("div",{style:{fontSize:13,color:_.muted},children:"Aucune requête rattachée à cette URL dans la fenêtre servie."}):e.jsx("div",{style:{border:`1px solid ${_.border}`,borderRadius:10,overflow:"hidden"},children:n.slice(0,14).map((c,u)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"8px 11px",borderTop:u?`1px solid ${_.border}`:"none",fontSize:12.5},children:[e.jsx("div",{style:{flex:1,minWidth:0,color:_.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.query}),e.jsxs("div",{style:{color:_.muted,fontVariantNumeric:"tabular-nums"},children:[le(c.impressions)," impr."]}),e.jsx("div",{style:{color:_.text,fontWeight:600,fontVariantNumeric:"tabular-nums",width:34,textAlign:"right"},children:$e(c.position)})]}
18,c.query))})}),e.jsxs(fn,{titre:"Historique du contenu",aside:s.etat==="idle"?e.jsx(ct,{petit:!0,onClick:o,children:"Relever"}):void 0,children:[s.etat==="idle"&&e.jsx("div",{style:{fontSize:13,color:_.muted,lineHeight:1.6},children:"Dates auxquelles le contenu de cette URL a changé, d'après les empreintes d'archive.org. Retroactif, donc lisible avant tout enregistrement de notre côté."}),s.etat==="load"&&e.jsxs("div",{style:{fontSize:13,color:_.muted},children:[e.jsx(Vt,{}),"Lecture des archives…"]}),s.etat==="err"&&e.jsx(We,{mode:"error",quoi:"L'archive publique",erreur:s.err}),s.etat==="ok"&&(s.data.length===0?e.jsx("div",{style:{fontSize:13,color:_.muted},children:"Aucune archive de cette URL. Rien à en déduire : l'absence d'archive ne dit pas que la page n'a pas changé."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{fontSize:13,color:_.text,marginBottom:8},children:[e.jsx("strong",{children:s.data.length})," changements de contenu constatés, du ",Me(s.data[0].date)," au ",Me(s.data[s.data.length-1].date),"."]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:s.data.slice(-14).reverse().map(c=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:12.5,color:_.muted},children:[e.jsx("span",{style:{width:5,height:5,borderRadius:"50%",background:Oe[1],flexShrink:0}}),Me(c.date)]},c.date+c.digest))})]}))]}),e.jsx("div",{style:{marginTop:22},children:e.jsx(Ut,{titre:"Ce qui n'est pas encore enregistré pour cette URL",lignes:["La courbe quotidienne de la page : rank_history est tenu par requête, pas par URL.","La date de première indexation et l'historique d'exploration : aucune source rétroactive, il faut relever chaque jour.","Le texte et la capture d'écran à chaque changement : lus ici chez archive.org, jamais conservés chez nous.",r?`Les liens internes reçus sur ${r} au fil du temps.`:"Les liens internes reçus au fil du temps."]})})]})}function Ks({userId:t,gscSite:n}){var w,m,d,h,j;const r=yn(n,t),[s,i]=l.useState(null),[o,c]=l.useState({etat:"idle"}),u=l.useRef(!1);l.useEffect(()=>{!t||!n||u.current||(u.current=!0,c({etat:"load"}),fetch(`${er}/gsc-history`,{method:"POST",headers:pt,body:JSON.stringify({user_id:t,gsc_site:n})}).then(x=>{if(!x.ok)throw new Error(`HTTP ${x.status}`);return x.json()}).then(x=>c({etat:"ok",data:x})).catch(x=>c({etat:"err",err:String(x.message||x)})))},[t,n]);const a=r.payload,p=l.useMemo(()=>a?Us(a):null,[a]),g=l.useMemo(()=>{if(!a)return[];const x=new Map((a.prevByQuery||[]).map(T=>[T.query,T])),z=new Map;for(const T of a.byQueryPage||[]){const L=z.get(T.query);(!L||L.impressions<T.impressions)&&z.set(T.query,{page:T.page,impressions:T.impressions})}const $=new Map([...z].map(([T,L])=>[T,L.page]));return(a.byQuery||[]).map(T=>({...T,page:$.get(T.query)||null,deltaClics:x.has(T.query)?T.clicks-(x.get(T.query).clicks||0):null}))},[a]);if(r.loading)return e.jsx(Be,{title:"Requêtes",large:!0,children:e.jsx(We,{mode:"loading",quoi:"la Search Console"})});if(!a||!p)return e.jsx(Be,{title:"Requêtes",subtitle:"Ce que Google affiche, et ce qu'il garde pour lui.",large:!0,children:e.jsx(We,{mode:r.mode==="error"?"error":"empty",quoi:"la Search Console"})});const y=o.etat==="ok"&&((w=o.data)!=null&&w.tracked)&&s?o.data.queries.find(x=>x.query===s):null;return e.jsxs(Be,{title:"Requêtes",subtitle:"La liste des requêtes, l'écart que Google ne commente jamais, et la courbe quotidienne de chacune.",large:!0,action:e.jsxs("div",{style:{fontSize:12.5,color:_.muted},children:[a.range.startDate," → ",a.range.endDate]}),children:[e.jsx(ht,{style:{padding:"20px 22px",marginBottom:18},children:e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:28,alignItems:"flex-end"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11.5,color:_.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700},children:"Impressions non rattachées à une requête affichée"}),e.jsx("div",{style:{fontSize:40,fontWeight:700,color:_.text,letterSpacing:"-0.03em",fontVariantNumeric:"tabular-nums",marginTop:6},children:_n(p.part,1)}),e.jsxs("div",{style:{fontSize:13,color:_.muted,marginTop:2,fontVariantNumeric:"tabular-nums"},children:[le(p.manquant)," impressions sur ",le(p.total)]})]}),e.jsxs("div",{style:{flex:1,minWidth:260},children:[e.jsxs("div",{style:{display:"flex",height:10,borderRadius:5,overflow:"hidden",background:"#EEF1F6"},children:[e.jsx("div",{style:{width:`${100-p.part}%`,background:Oe[1]}}),e.jsx("div",{style:{width:`${p.part}%`,background:Oe[4]}})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:12,color:_.muted,marginTop:7},children:[e.jsxs("span",{children:[le(p.listees)," rattachées à ",le(a.byQuery.length)," requêtes"]}),e.jsxs("span",{children:[le(p.manquant)," sans requête"]})]}),e.jsxs("div",{style:{fontSize:12.5,color:_.muted,marginTop:12,lineHeight:1.6},children:[p.tronque?"Deux causes mêlées ici : les requêtes anonymisées par Google, et la queue au-delà des 1 000 requêtes que l'API accepte de remonter. Les séparer demande de relever la liste chaque jour et de cumuler.":"La liste des requêtes n'est pas tronquée sur ce site : cet écart est entièrement de l'anonymisation Google. Ces recherches existent, elles ne seront jamais nommées.",p.clicsManquants>0&&e.jsxs(e.Fragment,{children:[" ",le(p.clicsManquants)," clics sont dans le même cas."]})]})]})]})}),e.jsx(ht,{children:e.jsx("div",{style:{overflowX:"auto"},children:e.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{color:_.muted,fontSize:11.5,textTransform:"uppercase",letterSpacing:"0.05em"},children:[e.jsx("th",{style:{textAlign:"left",padding:"10px 16px",fontWeight:700},children:"Requête"}),e.jsx("th",{style:{textAlign:"left",padding:"10px 12px",fontWeight:700},children:"Page qui la porte"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"Clics"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"28 j préc."}),e.jsx("th",{style:{textAlign:"right",padding:"10px 12px",fontWeight:700},children:"Impressions"}),e.jsx("th",{style:{textAlign:"right",padding:"10px 16px",fontWeight:700},children:"Position"})]})}),e.jsx("tbody",{children:g.slice(0,200).map(x=>e.jsxs("tr",{onClick:()=>i(x.query),className:"dc-row",style:{borderTop:`1px solid ${_.border}`,cursor:"pointer",background:s===x.query?"#F7FAF9":"#fff"},children:[e.jsx("td",{style:{padding:"10px 16px",color:_.text,fontWeight:600},children:x.query}),e.jsx("td",{style:{padding:"10px 12px",color:_.muted,maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.page?ut(x.page):"—"}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:le(x.clicks)}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:e.jsx(jr,{valeur:x.deltaClics})}),e.jsx("td",{style:{padding:"10px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:le(x.impressions)}),e.jsx("td",{style:{padding:"10px 16px",textAlign:"right",fontVariantNumeric:"tabular-nums"},children:$e(x.position)})]},x.query))})]})})}),e.jsxs("div",{style:{marginTop:18},children:[o.etat==="load"&&e.jsx(We,{mode:"loading",quoi:"le relevé quotidien"}),o.etat==="err"&&e.jsx(We,{mode:"error",quoi:"Le relevé quotidien",erreur:o.err}),o.etat==="ok"&&!((m=o.data)!=null&&m.tracked)&&e.jsx(Ut,{titre:"Aucun relevé quotidien pour ce site",lignes:["rank_history n'a aucune ligne : le cron de relevé ne couvre que les projets dont la mémoire a moins de 30 jours.","Sans relevé, la courbe d'une requête s'arrête à ce que Google veut bien servir le jour où on l'interroge."]}),o.etat==="ok"&&((d=o.data)==null?void 0:d.tracked)&&e.jsxs("div",{style:{fontSize:13,color:_.muted,lineHeight:1.6},children:["Relevé quotidien conservé depuis le ",o.data.firstDate?Me(o.data.firstDate):"—"," · ",le((h=o.data.dates)==null?void 0:h.length)," jours servis · ",le((j=o.data.queries)==null?void 0:j.length)," requêtes suivies. Cliquer une requête ouvre sa courbe."]})]}),s&&e.jsxs(br,{titre:s,sousTitre:"Courbe de position, relevé quotidien",onClose:()=>i(null),children:[y?e.jsx(Ys,{points:y.points}):e.jsx("div",{style:{fontSize:13,color:_.muted,lineHeight:1.6},children:"Cette requête n'est pas dans le relevé quotidien (les 40 requêtes les plus vues du site y sont, pas les autres). Ce qui suit vient donc du seul pull Search Console du jour, sans historique."}),e.jsx(fn,{titre:"Sur la fenêtre servie",children:e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:(()=>{const x=g.find(z=>z.query===s);return e.jsxs(e.Fragment,{children:[e.jsx(Je,{label:"Clics",valeur:le(x.clicks)}),e.jsx(Je,{label:"Impressions",valeur:le(x.impressions)}),e.jsx(Je,{label:"Position",valeur:$e(x.position)}),e.jsx(Je,{label:"Page",valeur:x.page?ut(x.page):"—"})]})})()})})]})]})}function Ys({points:t}){const s={t:12,r:8,b:22,l:30},i=t.filter(y=>y.position!=null);if(i.length<2)return e.jsx("div",{style:{fontSize:13,color:_.muted},children:"Un seul jour relevé : pas encore de courbe."});const o=Math.min(...i.map(y=>y.position)),c=Math.max(...i.map(y=>y.position)),u=Math.max(c,o+1),a=y=>s.l+y/(i.length-1)*(400-s.l-s.r),p=y=>s.t+(y-o)/(u-o)*(140-s.t-s.b),g=i.map((y,w)=>`${w?"L":"M"}${a(w).toFixed(1)},${p(y.position).toFixed(1)}`).join(" ");return e.jsxs("div",{children:[e.jsxs("svg",{viewBox:"0 0 400 140",style:{width:"100%",height:"auto",display:"block"},role:"img","aria-label":"Courbe de position",children:[e.jsx("line",{x1:s.l,y1:s.t,x2:s.l,y2:140-s.b,stroke:_.border}),e.jsx("line",{x1:s.l,y1:140-s.b,x2:400-s.r,y2:140-s.b,stroke:_.border}),e.jsx("text",{x:s.l-6,y:s.t+4,textAnchor:"end",fontSize:"9",fill:_.muted,children:$e(o)}),e.jsx("text",{x:s.l-6,y:140-s.b,textAnchor:"end",fontSize:"9",fill:_.muted,children:$e(u)}),e.jsx("path",{d:g,fill:"none",stroke:Oe[1],strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),i.map((y,w)=>e.jsx("circle",{cx:a(w),cy:p(y.position),r:"2.5",fill:"#fff",stroke:Oe[0],strokeWidth:"1.5"},y.date)),e.jsx("text",{x:s.l,y:134,fontSize:"9",fill:_.muted,children:Me(i[0].date)}),e.jsx("text",{x:400-s.r,y:134,textAnchor:"end",fontSize:"9",fill:_.muted,children:Me(i[i.length-1].date)})]}),e.jsxs("div",{style:{fontSize:12.5,color:_.muted,marginTop:6},children:[le(i.length)," jours relevés · position ",$e(i[0].position)," → ",$e(i[i.length-1].position)]})]})}function Xs({userId:t,gscSite:n,domain:r}){var h;const s=yn(n,t),[i,o]=l.useState({}),[c,u]=l.useState(null),[a,p]=l.useState(new Map),g=l.useRef(!1);l.useEffect(()=>{if(!r)return;let j=!0;return vr(r).then(x=>{j&&p(new Map(x.filter(z=>z.lastmod).map(z=>[z.url.replace(/\/$/,""),z.lastmod])))}).catch(()=>{}),()=>{j=!1}},[r]);const y=l.useMemo(()=>{var j;return(((j=s.payload)==null?void 0:j.byPage)||[]).slice(0,25)},[s.payload]),w=j=>{o(x=>({...x,...Object.fromEntries(j.map(z=>[z,{etat:"load"}]))})),Is(j,2,async x=>{try{const z=await yr(x);o($=>({...$,[x]:{etat:"ok",data:z}}))}catch(z){o($=>({...$,[x]:{etat:"err",err:String(z.message||z)}}))}})};if(l.useEffect(()=>{g.current||!y.length||(g.current=!0,w(y.slice(0,6).map(j=>j.page)))},[y]),s.loading)return e.jsx(Be,{title:"Contenu",large:!0,children:e.jsx(We,{mode:"loading",quoi:"la Search Console"})});if(!s.payload)return e.jsx(Be,{title:"Contenu",subtitle:"Ce que la page disait, à chaque date.",large:!0,children:e.jsx(We,{mode:s.mode==="error"?"error":"empty",quoi:"la Search Console"})});const m=y.filter(j=>!i[j.page]).map(j=>j.page),d=y.filter(j=>{var x;return((x=i[j.page])==null?void 0:x.etat)==="err"}).length;return e.jsxs(Be,{title:"Contenu",subtitle:"Google ne garde aucune trace de ce qu'une page disait. Les dates ci-dessous sont des changements de contenu réellement constatés.",large:!0,action:m.length?e.jsxs(ct,{onClick:()=>w(m),children:["Relever les ",m.length," autres"]}):void 0,children:[e.jsxs(Cn,{children:["Deux sources, aucune tenue par Google. ",e.jsx("strong",{children:"Constaté"})," : les empreintes de contenu d'archive.org, une ligne par version distincte, rétroactif mais incomplet (une page jamais archivée n'a pas d'historique ici, ce qui ne dit pas qu'elle n'a pas changé). ",e.jsx("strong",{children:"Déclaré"})," : le ",e.jsx("code",{children:"lastmod"})," du sitemap du site, qui répond même sans archive, et qui n'engage que le site."]}),d>0&&e.jsx("div",{style:{marginBottom:14},children:e.jsx(We,{mode:"error",quoi:`L'archive publique (${d} page${d>1?"s":""})`,erreur:(h=i[y.find(j=>{var x;return((x=i[j.page])==null?void 0:x.etat)==="err"}).page])==null?void 0:h.err})}),e.jsx(ht,{children:y.map((j,x)=>{const z=i[j.page],$=(z==null?void 0:z.etat)==="ok"?z.data:null,T=$&&$.length?$[$.length-1]:null,L=new Map;for(const W of $||[])L.set(W.date.slice(0,7),(L.get(W.date.slice(0,7))||0)+1);const b=[...L.entries()].sort((W,q)=>W[0].localeCompare(q[0])).slice(-18),N=Math.max(...b.map(W=>W[1]),1);return e.jsxs("div",{style:{borderTop:x?`1px solid ${_.border}`:"none",padding:"14px 16px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13.5,fontWeight:600,color:_.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ut(j.page)}),e.jsxs("div",{style:{fontSize:12,color:_.muted,marginTop:2,fontVariantNumeric:"tabular-nums"},children:[le(j.impressions)," impressions sur la fenêtre servie · position ",$e(j.position),a.get(j.page.replace(/\/$/,""))&&e.jsxs(e.Fragment,{children:[" · dernière modification déclarée le ",Me(a.get(j.page.replace(/\/$/,"")))]})]})]}),e.jsxs("div",{style:{textAlign:"right",minWidth:170},children:[!z&&e.jsx("span",{style:{fontSize:12.5,color:_.muted},children:"non relevé"}),(z==null?void 0:z.etat)==="load"&&e.jsxs("span",{style:{fontSize:12.5,color:_.muted},children:[e.jsx(Vt,{}),"relevé…"]}),(z==null?void 0:z.etat)==="err"&&e.jsx("span",{style:{fontSize:12.5,color:Sn},children:"archive injoignable"}),$&&($.length===0?e.jsx("span",{style:{fontSize:12.5,color:_.muted},children:"aucune archive"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{fontSize:13.5,fontWeight:700,color:_.text,fontVariantNumeric:"tabular-nums"},children:[le($.length)," changements"]}),e.jsxs("div",{style:{fontSize:12,color:_.muted},children:["dernier le ",Me(T.date)]})]}))]}),$&&$.length>0&&e.jsx(ct,{petit:!0,onClick:()=>u(c===j.page?null:j.page),children:c===j.page?"Replier":"Voir"})]}),$&&$.length>0&&e.jsx("div",{style:{display:"flex",alignItems:"flex-end",gap:3,height:34,marginTop:10},children:b.map(([W,q],J)=>e.jsx("div",{title:`${gn(W)} : ${q} changement${q>1?"s":""}`,style:{flex:1,height:`${q/N*100}%`,minHeight:3,background:Oe[Math.min(4,Math.floor((b.length-1-J)/4))],borderRadius:2}},W))}),c===j.page&&$&&e.jsxs("div",{style:{marginTop:12,background:kn,borderRadius:10,padding:"12px 14px"},children:[e.jsx("div",{style:{fontSize:12,color:_.muted,marginBottom:8},children:"Versions distinctes, de la plus récente à la plus ancienne"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(150px, 1fr))",gap:6},children:$.slice().reverse().slice(0,40).map(W=>e.jsx("a",{href:`https://web.archive.org/web/${W.date.replace(/-/g,"")}/${j.page}`,target:"_blank",rel:"noreferrer",style:{fontSize:12.5,color:_.text,textDecoration:"none",background:"#fff",border:`1px solid ${_.border}`,borderRadius:8,padding:"6px 9px"},children:Me(W.date)},W.date+W.digest))})]})]},j.page)})}),e.jsx("div",{style:{marginTop:18},children:e.jsx(Ut,{titre:"Ce que l'enregistrement quotidien ajoutera, et que l'archive ne donne pas",lignes:["Le texte complet de la page à chaque version, chez nous, interrogeable par l'agent.","Une capture d'écran datée : à quoi ressemblait la page le jour où elle était 3e.","Le diff lisible entre deux ver
18sions (titre, Hn, paragraphes, liens sortants).","Le rattachement à la courbe : un changement de contenu posé sur la courbe du jour même, ce qui exige d'avoir les deux au jour près."]})})]})}const Bn="suivi:sites";function Zs({memory:t,onSaveMemory:n,domain:r}){const s=l.useMemo(()=>((t==null?void 0:t[Bn])||"").split(",").map(m=>m.trim()).filter(Boolean),[t]),[i,o]=l.useState(s),[c,u]=l.useState(""),[a,p]=l.useState({});l.useEffect(()=>{o(s)},[s]);const g=m=>{p(d=>({...d,[m]:{etat:"load"}})),vr(m).then(d=>p(h=>({...h,[m]:{etat:"ok",data:d}}))).catch(d=>p(h=>({...h,[m]:{etat:"err",err:String(d.message||d)}})))};l.useEffect(()=>{for(const m of i)a[m]||g(m)},[i]);const y=m=>{o(m),n==null||n(Bn,m.join(","))},w=()=>{const m=c.trim().replace(/^https?:\/\//,"").replace(/\/.*$/,"").toLowerCase();if(!m||i.includes(m)){u("");return}y([...i,m]),u("")};return e.jsxs(Be,{title:"Suivi",subtitle:"Les mêmes fiches, pour des sites dont on n'a pas la Search Console. Ce qu'ils publient, ce qu'ils modifient, et quand.",large:!0,children:[e.jsxs(Cn,{children:["Source : le sitemap.xml déclaré par le site, lu en direct. Les dates ",e.jsx("code",{children:"lastmod"})," sont celles que le site annonce lui-même : elles disent la publication et la modification sans qu'aucun accès ne soit nécessaire. Un site sans sitemap, ou sans ",e.jsx("code",{children:"lastmod"}),", ne donne que sa liste d'URLs."]}),e.jsxs(ht,{style:{padding:"14px 16px",marginBottom:18},children:[e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[e.jsx("input",{value:c,onChange:m=>u(m.target.value),onKeyDown:m=>{m.key==="Enter"&&w()},placeholder:r?`Un site à suivre, autre que ${r}`:"exemple.fr",style:{flex:1,minWidth:220,border:`1px solid ${_.border}`,borderRadius:10,padding:"9px 12px",fontSize:13.5,color:_.text,outlineColor:_.accent}}),e.jsx(ct,{primaire:!0,onClick:w,children:"Suivre"})]}),!n&&e.jsx("div",{style:{fontSize:12,color:_.muted,marginTop:8},children:"La liste n'est pas enregistrée dans ce contexte : elle repart à zéro au rechargement."})]}),i.length===0&&e.jsxs("div",{style:{border:`1px dashed ${_.border}`,borderRadius:14,background:"#fff",padding:"34px 24px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:14.5,fontWeight:700,color:_.text},children:"Aucun site suivi"}),e.jsx("div",{style:{fontSize:13.5,color:_.muted,lineHeight:1.6,maxWidth:480,margin:"8px auto 0"},children:"Cet onglet est le seul qui fonctionne au premier jour, sans connexion et sans attendre qu'un enregistrement se remplisse."})]}),i.map(m=>{const d=a[m],h=(d==null?void 0:d.etat)==="ok"?d.data:null,j=(h||[]).filter(L=>L.lastmod),x=new Map;for(const L of j)x.set(L.lastmod.slice(0,7),(x.get(L.lastmod.slice(0,7))||0)+1);const z=[...x.entries()].sort((L,b)=>L[0].localeCompare(b[0])).slice(-24),$=Math.max(...z.map(L=>L[1]),1),T=j.slice().sort((L,b)=>b.lastmod.localeCompare(L.lastmod)).slice(0,12);return e.jsxs(ht,{style:{marginBottom:14,overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"14px 16px",borderBottom:h?`1px solid ${_.border}`:"none"},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:15,fontWeight:700,color:_.text},children:m}),h&&e.jsxs("div",{style:{fontSize:12.5,color:_.muted,marginTop:2,fontVariantNumeric:"tabular-nums"},children:[le(h.length)," URLs dans le sitemap · ",le(j.length)," avec une date déclarée"]}),(d==null?void 0:d.etat)==="load"&&e.jsxs("div",{style:{fontSize:12.5,color:_.muted,marginTop:2},children:[e.jsx(Vt,{}),"lecture du sitemap…"]}),(d==null?void 0:d.etat)==="err"&&e.jsxs("div",{style:{fontSize:12.5,color:Sn,marginTop:2},children:["sitemap illisible (",d.err,")"]})]}),e.jsx(ct,{petit:!0,onClick:()=>g(m),children:"Relire"}),e.jsx(ct,{petit:!0,onClick:()=>y(i.filter(L=>L!==m)),children:"Retirer"})]}),h&&z.length>0&&e.jsxs("div",{style:{padding:"16px 16px 14px"},children:[e.jsx("div",{style:{fontSize:11.5,color:_.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700,marginBottom:10},children:"Pages publiées ou modifiées, par mois"}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end",gap:4,height:72},children:z.map(([L,b],N)=>e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:4},children:[e.jsx("div",{title:`${gn(L)} : ${b}`,style:{width:"100%",height:`${b/$*100}%`,minHeight:3,background:Oe[Math.min(4,Math.floor((z.length-1-N)/6))],borderRadius:3}}),e.jsx("div",{style:{fontSize:9.5,color:_.muted,whiteSpace:"nowrap"},children:N%3===0?gn(L):""})]},L))})]}),h&&T.length>0&&e.jsxs("div",{style:{padding:"0 16px 16px"},children:[e.jsx("div",{style:{fontSize:11.5,color:_.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700,marginBottom:8},children:"Dernières pages touchées"}),e.jsx("div",{style:{border:`1px solid ${_.border}`,borderRadius:10,overflow:"hidden"},children:T.map((L,b)=>e.jsxs("div",{style:{display:"flex",gap:10,padding:"8px 11px",borderTop:b?`1px solid ${_.border}`:"none",fontSize:12.5,alignItems:"center"},children:[e.jsx("span",{style:{color:_.muted,fontVariantNumeric:"tabular-nums",width:92,flexShrink:0},children:Me(L.lastmod)}),e.jsx("a",{href:L.url,target:"_blank",rel:"noreferrer",style:{color:_.text,textDecoration:"none",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:ut(L.url)})]},L.url))})]}),h&&j.length===0&&e.jsx("div",{style:{padding:"14px 16px",fontSize:13,color:_.muted,lineHeight:1.6},children:"Ce sitemap ne déclare aucune date. La liste des URLs est là ; les dates de publication devront venir d'un relevé quotidien de notre côté (une URL nouvelle est une URL absente du relevé de la veille)."})]},m)}),i.length>0&&e.jsx("div",{style:{marginTop:18},children:e.jsx(Ut,{titre:"Ce qui manque pour que cet onglet tienne en production",lignes:["Une fonction edge de lecture publique : le navigateur ne peut pas appeler un sitemap tiers, et le proxy utilisé ici n'existe qu'en développement.","Un relevé quotidien de chaque site suivi, pour détecter les pages nouvelles et les contenus modifiés même sans lastmod.","Le relevé de position sur les requêtes du projet, pour ces sites-là aussi."]})})]})}const Jt=(t,n)=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t}),ei=({size:t=15})=>Jt(e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2.5"}),e.jsx("path",{d:"M3 9h18"}),e.jsx("path",{d:"M9 21V9"})]}),t),ti=({size:t=15})=>Jt(e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"10.5",cy:"10.5",r:"6.5"}),e.jsx("path",{d:"M20 20l-4.7-4.7"}),e.jsx("path",{d:"M7.5 10.5h6"})]}),t),ni=({size:t=15})=>Jt(e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 5h16"}),e.jsx("path",{d:"M4 12h10"}),e.jsx("path",{d:"M4 19h7"}),e.jsx("circle",{cx:"18.5",cy:"16.5",r:"3.5"})]}),t),ri=({size:t=15})=>Jt(e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M12 2v3M12 19v3M2 12h3M19 12h3"}),e.jsx("circle",{cx:"12",cy:"12",r:"9",strokeDasharray:"3 3"})]}),t),Dn=["pages","requetes","contenu","suivi"];function si({view:t,userId:n,domain:r,gscSite:s,memory:i,onSaveMemory:o}){return t==="pages"?e.jsx(Gs,{userId:n,gscSite:s,domain:r}):t==="requetes"?e.jsx(Ks,{userId:n,gscSite:s}):t==="contenu"?e.jsx(Xs,{userId:n,gscSite:s,domain:r}):e.jsx(Zs,{memory:i,onSaveMemory:o,domain:r})}function Pn(t,n,r=!0){const s=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");let i;try{i=new RegExp(s.replace("\\{\\{keyword\\}\\}","(.+?)"))}catch{return[]}const o=[];for(let c=0;c<t.length-1;c++){const u=t[c];if(u.role!=="user")continue;const a=i.exec((u.content||"").trim());if(!a)continue;const p=t[c+1];!p||p.role!=="assistant"||o.push({id:p.id,keyword:a[1],markdown:p.content||"",pending:!!p.isStreaming,error:!!p.isError,interrupted:!!p.interrupted,errorMessage:p.errorMessage,steps:(p.steps||[]).map(g=>g.label),prompt:u.content})}return r?o.reverse():o}function ii({size:t=15}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),e.jsx("circle",{cx:"9",cy:"10",r:"2"}),e.jsx("path",{d:"M6 16c.7-1.6 1.8-2.4 3-2.4s2.3.8 3 2.4"}),e.jsx("line",{x1:"15",y1:"9",x2:"18",y2:"9"}),e.jsx("line",{x1:"15",y1:"13",x2:"18",y2:"13"})]})}function oi({size:t=15}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function ai({size:t=15}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M20.6 13.4l-7.2 7.2a2 2 0 0 1-2.8 0L2 12V2h10l8.6 8.6a2 2 0 0 1 0 2.8z"}),e.jsx("line",{x1:"7",y1:"7",x2:"7",y2:"7"})]})}function li({size:t=15}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),e.jsx("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]})}function ci({size:t=15}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 3v18"}),e.jsx("path",{d:"M3 12h18"}),e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M12 3a14 14 0 0 0 0 18a14 14 0 0 0 0-18"})]})}function di({size:t=15}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e.jsx("path",{d:"M3 5v14a9 3 0 0 0 18 0V5"}),e.jsx("path",{d:"M3 12a9 3 0 0 0 18 0"})]})}function ui({size:t=15}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 3l9 5-9 5-9-5z"}),e.jsx("path",{d:"M3 13l9 5 9-5"})]})}function hi({size:t=15}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}const jn=[{id:"chat",label:"Chat",icon:oi},{id:"projet",label:E.t("kw_onglets.projet"),icon:ui},{id:"sources",label:E.t("kw_onglets.sources"),icon:hi},{id:"fiche",label:E.t("rech_fiche.titre"),icon:ii},{id:"keywords",label:E.t("rech_projectviews.motsCls"),icon:ai},{id:"gsc",label:"Search Console",icon:ci},{id:"pages",label:E.t("kw_onglets.pages"),icon:ei},{id:"requetes",label:E.t("kw_onglets.requetes"),icon:ti},{id:"contenu",label:E.t("kw_onglets.contenu"),icon:ni},{id:"suivi",label:E.t("kw_onglets.suivi"),icon:ri},{id:"briefs",label:E.t("x_projectviews.briefs"),icon:li},{id:"memory",label:E.t("rech_projectviews.mmoire"),icon:di}];function In(t){return t==="micro"||t==="objections"?"keywords":t==="strategie"||t==="agent"?"chat":jn.some(n=>n.id===t)||t==="decisions"?t:"chat"}function qn(t){const n=[],r=new Set,s=/```keywords\s*([\s\S]*?)```/g;for(const i of t){if(i.role!=="assistant"||!i.content)continue;let o;for(s.lastIndex=0;(o=s.exec(i.content))!==null;)try{const c=JSON.parse(o[1].trim()),u=Array.isArray(c)?c:Array.isArray(c==null?void 0:c.rows)?c.rows:[];for(const a of u){const p=String((a==null?void 0:a.keyword)||"").toLowerCase().trim();!p||r.has(p)||(r.add(p),n.push(a))}}catch{}}return n}const mt="#F4F5F7",C={text:"#111827",muted:"#6B7280",border:"#E5E7EB",accent:"#0A8F6F"};function Rt({title:t,subtitle:n,action:r,children:s}){return e.jsx("div",{style:{height:"100%",overflowY:"auto",background:mt},children:e.jsxs("div",{style:{maxWidth:980,margin:"0 auto",padding:"40px 28px 80px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16},children:[e.jsxs("div",{children:[e.jsx("div",{className:"qadence-title-gradient",style:{fontSize:34,fontWeight:700,letterSpacing:"-0.03em",lineHeight:1.15,width:"fit-content",maxWidth:"100%"},children:t}),n&&e.jsx("div",{style:{fontSize:16,color:C.muted,marginTop:10,lineHeight:1.65},children:n})]}),r&&e.jsx("div",{style:{flexShrink:0,paddingTop:2},children:r})]}),e.jsx("div",{style:{marginTop:28},children:s})]})})}function wr({label:t,description:n,cta:r,prompt:s,onAskInChat:i}){return e.jsxs("div",{style:{border:`1px dashed ${C.border}`,borderRadius:14,background:"#fff",padding:"40px 28px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:15,color:C.text,fontWeight:600,marginBottom:6},children:t}),e.jsx("div",{style:{fontSize:13.5,color:C.muted,lineHeight:1.5,maxWidth:460,margin:"0 auto 18px"},children:n}),e.jsx("button",{onClick:()=>i(s),style:{background:C.accent,color:"#fff",border:"none",borderRadius:10,padding:"10px 20px",fontSize:13.5,fontWeight:600,cursor:"pointer"},children:r})]})}function Ye({label:t,value:n}){return e.jsxs("div",{style:{background:mt,borderRadius:10,padding:"10px 12px"},children:[e.jsx("div",{style:{fontSize:11,color:C.muted,textTransform:"uppercase",letterSpacing:"0.05em",fontWeight:600},children:t}),e.jsx("div",{style:{fontSize:15,color:C.text,fontWeight:600,marginTop:3},children:n})]})}function kr(){return e.jsx("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:C.accent,strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"kchat-spin 1s linear infinite",flexShrink:0},children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function Sr({steps:t}){const{t:n}=ee(),r=t&&t.length?t:[n("rech_projectviews.jePrpareLeBrief")];return e.jsx("div",{style:{background:mt,border:`1px solid ${C.border}`,borderRadius:10,padding:"12px 14px",display:"flex",flexDirection:"column",gap:7},children:r.map((s,i)=>{const o=i===r.length-1;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,color:o?C.accent:C.muted,fontWeight:o?500:400},children:[e.jsx("span",{style:{display:"flex",width:14,justifyContent:"center"},children:o?e.jsx(kr,{}):e.jsx("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"#059669",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),s]},i)})})}function pi({brief:t,onClose:n,onRegenerate:r}){const{t:s}=ee(),[i,o]=l.useState(!1);l.useEffect(()=>{const g=y=>{y.key==="Escape"&&n()};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[n]),l.useEffect(()=>{if(!i)return;const g=setTimeout(()=>
18o(!1),1800);return()=>clearTimeout(g)},[i]);async function c(){try{await navigator.clipboard.writeText(t.markdown||""),o(!0)}catch{}}let u="";if(t.createdAt)try{u=new Date(t.createdAt).toLocaleDateString("fr-FR",{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit"})}catch{}const a=!t.pending&&!t.error&&!t.interrupted&&!!t.markdown,p=!t.pending&&(t.error||t.interrupted);return e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:n,style:{position:"fixed",inset:0,zIndex:110,background:"rgba(17,24,39,0.18)"}}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t.keyword,style:{position:"fixed",top:0,right:0,height:"100vh",width:"min(720px, 96vw)",zIndex:120,background:"#fff",borderLeft:`1px solid ${C.border}`,boxShadow:"-12px 0 40px -20px rgba(17,24,39,0.3)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,padding:"18px 22px",borderBottom:`1px solid ${C.border}`},children:[e.jsxs("div",{style:{minWidth:0},children:[e.jsxs("div",{style:{fontSize:11,color:t.pending?C.accent:p?"var(--danger, #B4534B)":C.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700},children:[t.pending?s("rech_projectviews.enCours"):p?s("kw_brief.rowInterrompu"):"Brief",u?` · ${u}`:""]}),e.jsx("div",{style:{fontSize:19,fontWeight:700,color:C.text,marginTop:3,overflowWrap:"anywhere"},children:t.keyword})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,flexShrink:0},children:[a&&e.jsxs("button",{onClick:c,"aria-label":"Copier le brief",title:"Copier le brief",style:{display:"flex",alignItems:"center",gap:6,background:"none",border:`1px solid ${C.border}`,borderRadius:8,padding:"7px 11px",fontSize:12.5,fontWeight:500,color:i?C.accent:C.muted,cursor:"pointer"},children:[i?e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"12",height:"12",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),i?"Copié":"Copier"]}),e.jsx("button",{onClick:n,"aria-label":s("x_projectviews.fermer"),style:{background:"none",border:"none",color:C.muted,cursor:"pointer",padding:"6px 8px",fontSize:18,lineHeight:1},children:"✕"})]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"20px 22px 32px"},children:t.pending?e.jsx(Sr,{steps:t.steps}):e.jsxs(e.Fragment,{children:[t.markdown&&e.jsx("div",{className:"kbrief",children:e.jsx(Ct,{remarkPlugins:[It],children:t.markdown})}),p&&e.jsxs("div",{role:"status",style:{marginTop:t.markdown?20:0,borderLeft:"3px solid var(--danger, #B4534B)",background:"var(--danger-soft, #F9EFEE)",borderRadius:"0 10px 10px 0",padding:"12px 16px"},children:[e.jsx("div",{style:{fontSize:13.5,fontWeight:600,color:C.text},children:t.markdown?s("kw_brief.interrompuTitre"):s("kw_brief.echecTitre")}),e.jsx("div",{style:{fontSize:13,color:C.muted,lineHeight:1.55,marginTop:3},children:t.markdown?s("kw_brief.interrompuTexte"):t.errorMessage||s("kw_brief.echecTexte")})]})]})}),(a||p)&&e.jsx("div",{style:{borderTop:`1px solid ${C.border}`,padding:"12px 22px"},children:e.jsx("button",{onClick:()=>r(t.keyword),style:p?{background:C.accent,color:"#fff",border:"none",borderRadius:9,padding:"9px 14px",fontSize:13,fontWeight:600,cursor:"pointer"}:{background:"none",border:`1px solid ${C.border}`,borderRadius:9,padding:"9px 14px",fontSize:13,fontWeight:500,color:C.text,cursor:"pointer"},children:s(p?"kw_brief.reprendre":"kw_brief.regenerer")})})]})]})}function xi({row:t,onGenerate:n,onClose:r}){const{t:s}=ee(),i=String(t.keyword||""),o=t.volume!=null&&t.volume!==""?new Intl.NumberFormat("fr-FR").format(Number(t.volume)):"·",c=t.cpc!=null&&t.cpc!==""?`${Number(t.cpc).toFixed(2)} €`:"·";return String(t.bucket||""),e.jsxs(e.Fragment,{children:[e.jsx("div",{onClick:r,style:{position:"fixed",inset:0,zIndex:110,background:"rgba(17,24,39,0.18)"}}),e.jsxs("div",{style:{position:"fixed",top:0,right:0,height:"100vh",width:"min(440px, 92vw)",zIndex:120,background:"#fff",borderLeft:`1px solid ${C.border}`,boxShadow:"-12px 0 40px -20px rgba(17,24,39,0.3)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,padding:"18px 20px",borderBottom:`1px solid ${C.border}`},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:11,color:C.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:600},children:s("rech_projectviews.motCl")}),e.jsx("div",{style:{fontSize:18,fontWeight:700,color:C.text,marginTop:2},children:i})]}),e.jsx("button",{onClick:r,"aria-label":s("x_projectviews.fermer"),style:{background:"none",border:"none",color:C.muted,cursor:"pointer",padding:4,fontSize:18,lineHeight:1},children:"✕"})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:20},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:[e.jsx(Ye,{label:s("rech_projectviews.intention"),value:String(t.intention||"·")}),e.jsx(Ye,{label:s("rech_projectviews.volumeMois"),value:o}),e.jsx(Ye,{label:"CPC",value:c}),e.jsx(Ye,{label:s("rech_projectviews.comptition"),value:String(t.competition||"·")}),t.clicks!=null&&e.jsx(Ye,{label:s("x_projectviews.clics"),value:String(t.clicks)}),t.impressions!=null&&e.jsx(Ye,{label:"Impressions",value:new Intl.NumberFormat("fr-FR").format(Number(t.impressions))}),t.position!=null&&e.jsx(Ye,{label:s("x_projectviews.position"),value:Number(t.position).toFixed(1)})]}),e.jsxs("div",{style:{marginTop:22},children:[e.jsx("button",{onClick:()=>{n(i),r()},style:{width:"100%",background:C.accent,color:"#fff",border:"none",borderRadius:10,padding:"13px",fontSize:14,fontWeight:600,cursor:"pointer"},children:s("rech_projectviews.gnrerUnBrief")}),e.jsx("div",{style:{fontSize:12.5,color:C.muted,marginTop:10,lineHeight:1.5},children:s("rech_projectviews.lAgentOuvreL")})]})]})]})]})}
18const On=";";function rn(t){if(t==null)return"";const n=String(t);return/[;"\n\r]/.test(n)?`"${n.replace(/"/g,'""')}"`:n}function gi(t,n){return t.normalize("NFD").replace(/[̀-ͯ]/g,"").replace(/[^a-zA-Z0-9]+/g,"-").toLowerCase().replace(/^-+|-+$/g,"")||n}function fi(t,n,r){const s=[],i=wn(t);i.length&&s.push({label:"Synthèse stratégique",headers:["Sujet","Information","Intérêt pour le projet","Nature","Extrait de l’échange"],rows:i.map(g=>[g.title,g.detail,g.why,g.kind,g.quote])});const o=qn(t);o.length&&s.push({label:E.t("rech_projectviews.motsCls"),headers:[E.t("rech_projectviews.motCl"),E.t("rech_projectviews.intention"),E.t("rech_projectviews.volumeMois"),"CPC (€)",E.t("rech_projectviews.comptition"),E.t("x_projectviews.clics"),"Impressions",E.t("x_projectviews.position")],rows:o.map(g=>[g.keyword??"",g.intention??"",g.volume??"",g.cpc??"",g.competition??"",g.clicks??"",g.impressions??"",g.position??""])});const c=dr(t);c.length&&s.push({label:"Micro-intentions",headers:[E.t("rech_projectviews.microIntention"),E.t("rech_projectviews.catgorie"),E.t("rech_projectviews.ceQueLUtilisateur")],rows:c.map(g=>[g.query,g.cat,g.want])});const u=ur(t);u.length&&s.push({label:E.t("x_projectviews.objections"),headers:["Objection",E.t("rech_projectviews.rponseApporter")],rows:u.map(g=>[g.objection,g.reponse])});const a=r.filter(g=>!g.pending&&!g.error&&g.markdown);a.length&&s.push({label:E.t("x_projectviews.briefs"),headers:[E.t("rech_projectviews.motCl"),"Date","Brief"],rows:a.map(g=>{let y="";try{y=new Date(g.createdAt).toLocaleString("fr-FR")}catch{}return[g.keyword,y,g.markdown]})});const p=Object.entries(n||{});return p.length&&s.push({label:E.t("rech_projectviews.mmoire"),headers:["Fait","Valeur"],rows:p.map(([g,y])=>[g,y])}),s}function mi(t){const n=[];return t.forEach((r,s)=>{s&&n.push(""),n.push(rn(r.label)),n.push(r.headers.map(rn).join(On));for(const i of r.rows)n.push(i.map(rn).join(On))}),"\uFEFF"+n.join(`\r
19`)+`\r
20`}function ji(t,n){if(!n.length)return;const r=new Blob([mi(n)],{type:"text/csv;charset=utf-8;"}),s=URL.createObjectURL(r),i=document.createElement("a");i.href=s,i.download=`${gi(t||"projet","projet")}-export-${new Date().toISOString().split("T")[0]}.csv`,i.click(),setTimeout(()=>URL.revokeObjectURL(s),1e3)}function bi({onExport:t}){const{t:n}=ee();return e.jsxs("button",{onClick:t,title:n("rech_projectviews.tlchargerTousLesOnglets"),style:{display:"flex",alignItems:"center",gap:7,background:"#fff",color:C.text,border:`1px solid ${C.border}`,borderRadius:10,padding:"9px 14px",fontSize:13.5,fontWeight:600,cursor:"pointer"},children:[e.jsxs("svg",{width:15,height:15,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),n("rech_projectviews.exporterToutEnCsv")]})}function yi({actif:t,onChange:n,compteurs:r}){const{t:s}=ee(),o=[{id:"mots",label:s("rech_projectviews.motsCls")},{id:"micro",label:"Micro-intentions"},{id:"objections",label:s("x_projectviews.objections")}].filter(c=>c.id==="mots"||r[c.id]>0);return o.length<2?null:e.jsx("div",{style:{display:"flex",gap:6,borderBottom:`1px solid ${C.border}`,marginBottom:18},children:o.map(c=>{const u=t===c.id;return e.jsxs("button",{onClick:()=>n(c.id),style:{display:"flex",alignItems:"center",gap:7,background:"none",border:"none",cursor:"pointer",padding:"9px 4px",marginRight:14,fontSize:14,fontWeight:u?600:500,color:u?C.text:C.muted,borderBottom:`2px solid ${u?C.accent:"transparent"}`,marginBottom:-1},children:[c.label,r[c.id]>0&&e.jsx("span",{style:{fontSize:11.5,fontWeight:600,color:u?C.accent:C.muted,background:u?"rgba(10,143,111,0.08)":mt,borderRadius:999,padding:"1px 7px"},children:r[c.id]})]},c.id)})})}function vi({messages:t,action:n,onOpenMessage:r}){const{t:s}=ee(),i=ys(t),o=vs(t),c=o.filter(w=>w.action==="creer"||w.action==="renforcer"),u=o.filter(w=>w.action==="observer"),a=ws(t),p=ks(t),g=!i&&!o.length&&!a.length&&!p.length,y=wn(t).length>0||t.some(w=>{var m;return((m=w.strategy)==null?void 0:m.points.length)&&!w.isStreaming&&!w.isError&&!w.interrupted});return e.jsx(Rt,{title:s("rech_projectviews.dcisions"),subtitle:"Votre synthèse stratég
20ique, alimentée automatiquement par le chat.",action:n,children:e.jsx(wi,{messages:t,comprehension:i,maintenant:c,observees:u,veille:a,verifications:p,rien:g,hasStrategy:y,onOpenMessage:r,t:s})})}function wi({messages:t,comprehension:n,maintenant:r,observees:s,veille:i,verifications:o,rien:c,hasStrategy:u,onOpenMessage:a,t:p}){const[g,y]=l.useState("tout"),w=wn(t),m=[...w.map(h=>({kind:h.kind==="decision"||h.kind==="priority"?"decisions":"tout",section:h.kind==="decision"||h.kind==="priority"?"Décisions à prendre":"Contexte du projet",date:h.generatedAt,title:h.title,detail:h.detail,why:h.why,quote:h.quote,messageId:h.messageId,label:h.kind==="decision"?"Décision":h.kind==="priority"?"Priorité":h.kind==="constraint"?"Contrainte":h.kind==="hypothesis"?"Hypothèse":"Constat"})),...r.map(h=>{var j,x;return{kind:"decisions",section:"Décisions à prendre",date:Date.now(),title:h.titre,detail:h.decision||h.probleme,why:h.pourquoi,quote:((x=(j=h.requetes)==null?void 0:j[0])==null?void 0:x.requete)||"",messageId:void 0,label:h.action==="renforcer"?"À renforcer":"À créer"}}),...o.map(h=>{var j;return{kind:"verifie",section:"Vérifications terminées",date:Date.now(),title:h.brief||h.url,detail:h.verdict,why:(j=h.manquant)!=null&&j.length?`${h.manquant.length} point(s) restent à traiter.`:"La page couvre le brief.",quote:h.url,messageId:void 0,label:"Vérifié"}}),...[...s,...i].map(h=>({kind:"veille",section:"Signaux à surveiller",date:Date.now(),title:"sujet"in h?h.sujet:h.titre,detail:"sujet"in h?h.signaux.join(" · "):h.probleme,why:"sujet"in h?h.verification:h.pourquoi,quote:"",messageId:void 0,label:"À surveiller"}))].filter(h=>g==="tout"||h.kind===g),d=m.sort((h,j)=>j.date-h.date);return e.jsxs("section",{className:"decision-feed","aria-label":"Fil des décisions",children:[e.jsxs("div",{className:"decision-feed-intro",children:[e.jsxs("div",{children:[e.jsx("p",{className:"decision-feed-kicker",children:"FIL STRATÉGIQUE"}),e.jsx("p",{children:"Chaque signal important devient une publication exploitable. Ouvrez une carte pour retrouver le raisonnement."})]}),e.jsx("div",{className:"decision-feed-filters",role:"tablist","aria-label":"Filtrer le fil",children:[["tout","Tout"],["decisions","Décisions"],["veille","Veille"],["verifie","Vérifié"]].map(([h,j])=>e.jsxs("button",{className:g===h?"is-active":"",onClick:()=>y(h),role:"tab","aria-selected":g===h,children:[j,e.jsx("span",{children:h==="tout"?m.length:h==="decisions"?r.length+w.filter(x=>x.kind==="decision"||x.kind==="priority").length:h==="veille"?s.length+i.length:o.length})]},h))})]}),n&&g==="tout"&&e.jsxs("article",{className:"decision-feed-card decision-feed-profile",children:[e.jsx("div",{className:"decision-feed-avatar",children:"✦"}),e.jsxs("div",{className:"decision-feed-card-body",children:[e.jsxs("div",{className:"decision-feed-meta",children:[e.jsx("span",{children:"Profil compris"}),e.jsx("time",{children:"Maintenant"})]}),e.jsx("h3",{children:n.vend}),e.jsx("p",{children:n.probleme}),e.jsxs("div",{className:"decision-feed-tags",children:[e.jsx("span",{children:n.acheteur}),e.jsx("span",{children:n.declencheur})]})]})]}),c&&e.jsxs("div",{className:"decision-feed-empty",children:[e.jsx("div",{className:"decision-feed-empty-icon",children:"✦"}),e.jsx("h3",{children:"Votre fil se construit dans le chat"}),e.jsx("p",{children:"Décrivez votre activité et vos priorités. Les décisions, signaux et vérifications apparaîtront ici automatiquement."})]}),!c&&!d.length&&e.jsxs("div",{className:"decision-feed-empty",children:[e.jsx("h3",{children:"Aucun élément dans ce filtre"}),e.jsx("p",{children:"Essayez « Tout » pour retrouver les autres signaux du projet."})]}),!!d.length&&e.jsx("div",{className:"decision-feed-sections",children:["Contexte du projet","Décisions à prendre","Signaux à surveiller","Vérifications terminées"].map(h=>{const j=d.filter(x=>x.section===h);return j.length?e.jsxs("section",{className:"decision-feed-section",children:[e.jsxs("div",{className:"decision-feed-section-heading",children:[e.jsx("h2",{children:h}),e.jsxs("span",{children:[j.length," ",j.length>1?"éléments":"élément"]})]}),e.jsx("div",{className:"decision-feed-list",children:j.map((x,z)=>e.jsxs("article",{className:"decision-feed-card",children:[e.jsx("div",{className:`decision-feed-avatar decision-feed-avatar-${x.kind}`,children:x.kind==="verifie"?"✓":x.kind==="veille"?"◌":"→"}),e.jsxs("div",{className:"decision-feed-card-body",children:[e.jsxs("div",{className:"decision-feed-meta",children:[e.jsx("span",{children:x.label}),e.jsx("time",{children:z===0?"À l’instant":"Dans le fil"})]}),e.jsx("h3",{children:x.title}),e.jsx("div",{className:"decision-feed-detail",children:e.jsx(Ct,{children:x.detail})}),x.why&&e.jsx("p",{className:"decision-feed-why",children:x.why}),x.quote&&e.jsxs("blockquote",{children:["« ",x.quote," »"]}),e.jsxs("div",{className:"decision-feed-actions",children:[x.messageId&&a&&e.jsx("button",{onClick:()=>a(x.messageId),children:"Revoir l’échange"}),e.jsx("span",{className:"decision-feed-status",children:x.kind==="decisions"?"Action recommandée":x.kind==="verifie"?"Contrôle terminé":x.kind==="veille"?"À qualifier":"Nouveau signal"})]})]})]},`${x.title}-${z}`))})]},h):null})}),u&&e.jsx("p",{className:"decision-feed-footnote",children:"Le fil est mis à jour à chaque nouvelle précision dans le chat."})]})}function ki({messages:t,action:n,onGenerateBrief:r,onAskInChat:s}){var x;const{t:i}=ee(),o=qn(t),c=dr(t),u=ur(t),a=t.some(z=>z.isStreaming),p=t.find(z=>z.isStreaming),g=((x=p==null?void 0:p.steps)==null?void 0:x.map(z=>z.detail?`${z.label} · ${z.detail}`:z.label))||[],[y,w]=l.useState("mots"),[m,d]=l.useState(null),h=y==="micro"&&!c.length||y==="objections"&&!u.length?"mots":y,j={mots:o.length?`${o.length} mots-clés priorisés. Cliquez un mot-clé pour ses détails et générer un brief.`:void 0,micro:c.length?`${c.length} micro-intentions à couvrir, tirées des requêtes réellement tapées.`:void 0,objections:u.length?`${u.length} objections à lever avant la conversion.`:void 0};return e.jsxs(Rt,{title:i("rech_projectviews.motsCls"),subtitle:j[h],action:n,children:[e.jsx(yi,{actif:h,onChange:w,compteurs:{mots:o.length,micro:c.length,objections:u.length}}),a&&e.jsxs("div",{style:{marginBottom:16},role:"status","aria-live":"polite",children:[e.jsx("div",{style:{fontSize:13,color:C.muted,marginBottom:7,fontWeight:600},children:"Qadence prépare vos mots-clés"}),e.jsx(Sr,{steps:g.length?g:["Je lis le contexte du projet","Je génère les mots-clés business","Je mesure le volume et le CPC","Je décline les micro-intentions et objections"]})]}),h==="mots"&&(o.length===0&&!a?e.jsx(wr,{label:i("rech_projectviews.aucunMotClPour"),description:i("rech_projectviews.dcrivezVotreProduitDans"),cta:i("rech_projectviews.lancerLaRecherche"),prompt:i("rech_projectviews.donneMoiLesMots"),onAskInChat:s}):e.jsx("div",{style:{background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,padding:16},children:e.jsx("div",{className:"kchat",children:e.jsx(rr,{raw:JSON.stringify(o),onRowClick:d})})})),h==="micro"&&e.jsx("div",{style:{background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,padding:16},children:e.jsx("div",{className:"kchat",children:e.jsx(sr,{rows:c})})}),h==="objections"&&e.jsx("div",{style:{background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,padding:16},children:e.jsx("div",{className:"kchat",children:e.jsx(ir,{rows:u})})}),m&&e.jsx(xi,{row:m,onGenerate:r,onClose:()=>d(null)})]})}const Si={low:1,medium:2,high:3,faible:1,moyenne:2,élevée:3,elevee:3},Hn=()=>[{champ:"query",label:E.t("x_projectviews.requte"),align:"left",texte:!0},{champ:"clicks",label:E.t("x_projectviews.clics"),align:"right"},{champ:"impressions",label:"Impr.",align:"right"},{champ:"ctr",label:"CTR",align:"right"},{champ:"position",label:E.t("x_projectviews.position"),align:"right"},{champ:"volume",label:E.t("x_projectviews.volume"),align:"right"},{champ:"cpc_high",label:E.t("x_projectviews.enchreHautDePage"),align:"left"},{champ:"competition",label:E.t("x_projectviews.comptition"),align:"left",texte:!0}];function Vn(t,n){return n==="query"?t.query.toLowerCase():n==="competition"?Si[String(t.competition||"").toLowerCase()]??null:n==="cpc_high"?t.cpc_high:n==="volume"?t.volume:t[n]}const sn=()=>({low:{label:E.t("rech_projectviews.faible"),dot:"#D1D5DB"},medium:{label:E.t("rech_projectviews.moyenne"),dot:"#9CA3AF"},high:{label:E.t("rech_projectviews.leve"),dot:"#4B5563"}});function _i(t){const n=String(t||"").toLowerCase();return n.startsWith("low")||n.startsWith("faib")?sn().low:n.startsWith("med")||n.startsWith("moy")?sn().medium:n.startsWith("high")||n.startsWith("élev")||n.startsWith("elev")?sn().high:null}function Ci({rows:t,loading:n,error:r,onImport:s,action:i,siteProperty:o,onGscProperty:c,sourceControl:u}){const{t:a}=ee(),[p,g]=l.useState("impressions"),[y,w]=l.useState("desc"),[m,d]=l.useState(!1),[h,j]=l.useState(28),[x,z]=l.useState(""),[$,T]=l.useState(0),L=50;function b(R){if(T(0),R===p){w(te=>te==="desc"?"asc":"desc");return}const H=Hn().find(te=>te.champ===R);g(R),w(H!=null&&H.texte||R==="position"?"asc":"desc")}const N=[...t].filter(R=>(!m||R.position>=5&&R.position<=20)&&R.query.toLocaleLowerCase().includes(x.trim().toLocaleLowerCase())).sort((R,H)=>{const te=Vn(R,p),pe=Vn(H,p);if(te==null&&pe==null)return 0;if(te==null)return 1;if(pe==null)return-1;
20const I=typeof te=="string"&&typeof pe=="string"?te.localeCompare(pe,"fr"):Number(te)-Number(pe);return y==="asc"?I:-I}),W=t[0],q=t.filter(R=>R.volume!=null).length;let J="";try{W&&(J=new Date(W.releve_le).toLocaleDateString("fr-FR",{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit"}))}catch{}const ce=t.reduce((R,H)=>R+H.clicks,0),G=t.reduce((R,H)=>R+H.impressions,0),je=t.filter(R=>R.position>=5&&R.position<=20).length,he=Math.max(0,Math.ceil(N.length/L)-1),ne=Math.min($,he),F=R=>new Intl.NumberFormat("fr-FR").format(R);return e.jsx("div",{className:"gsc-view","aria-busy":n,children:e.jsxs("div",{className:"gsc-content",children:[e.jsxs("header",{className:"gsc-header",children:[e.jsxs("div",{children:[e.jsx("h1",{children:"Search Console"}),e.jsx("p",{children:"Les requêtes qui font venir vos visiteurs."})]}),i]}),e.jsxs("div",{className:"gsc-sourcebar",children:[e.jsxs("div",{className:"gsc-source",children:[u??e.jsx(Fs,{siteProperty:o,onChoisir:c}),W&&e.jsxs("span",{className:"gsc-sync",children:["Relevé du ",J]})]}),e.jsxs("div",{className:"gsc-import",children:[e.jsxs("label",{className:"gsc-period",children:["Période à importer",e.jsxs("select",{value:h,onChange:R=>j(Number(R.target.value)),disabled:n,children:[e.jsx("option",{value:28,children:"28 jours"}),e.jsx("option",{value:90,children:"90 jours"}),e.jsx("option",{value:180,children:"6 mois"}),e.jsx("option",{value:365,children:"12 mois"})]})]}),e.jsxs("button",{className:"gsc-primary",onClick:()=>s(h),disabled:n,children:[e.jsx(ts,{size:15,className:n?"gsc-spinning":""}),n?a("rech_projectviews.importEnCours"):t.length?"Actualiser":a("rech_projectviews.importerMesRequtes")]})]})]}),r&&e.jsx("div",{className:"gsc-error",role:"alert",children:r}),n&&e.jsxs("div",{className:"gsc-loading",role:"status",children:[e.jsx(kr,{}),e.jsxs("span",{children:[a("rech_projectviews.lectureDeLaSearch"),e.jsx("small",{children:a("rech_projectviews.puisMesureDeChaque")})]})]}),!n&&!t.length&&e.jsxs("section",{className:"gsc-empty",children:[e.jsx("div",{className:"gsc-empty-icon",children:e.jsx(Qr,{size:32})}),e.jsx("h2",{children:"Découvrez comment votre site est trouvé"}),e.jsx("p",{children:"Connectez votre propriété Google, puis importez vos requêtes pour retrouver leurs clics, leurs positions et leur potentiel de recherche."}),e.jsxs("div",{className:"gsc-empty-sources",children:[e.jsxs("span",{children:[e.jsx("strong",{children:"Search Console"}),"Clics, impressions et positions"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"Google Ads"}),"Volumes et enchères publicitaires"]})]})]}),t.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"gsc-summary-heading",children:[e.jsx("h2",{children:"Vue d’ensemble"}),e.jsxs("span",{children:[(W==null?void 0:W.periode_jours)??h," jours · ",F(t.length)," requêtes importées"]})]}),e.jsxs("div",{className:"gsc-metrics",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Clics"}),e.jsx("strong",{children:F(ce)}),e.jsx("small",{children:"Sur les requêtes importées"})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Impressions"}),e.jsx("strong",{children:F(G)}),e.jsx("small",{children:"Apparitions dans les résultats"})]}),e.jsxs("div",{children:[e.jsx("span",{children:"CTR global"}),e.jsx("strong",{children:G?(ce/G*100).toLocaleString("fr-FR",{maximumFractionDigits:1})+" %":"—"}),e.jsx("small",{children:"Clics ÷ impressions importées"})]}),e.jsxs("button",{className:m?"gsc-opportunity is-active":"gsc-opportunity","aria-pressed":m,onClick:()=>{d(R=>!R),T(0)},children:[e.jsx("span",{children:"Positions à travailler"}),e.jsx("strong",{children:F(je)}),e.jsxs("small",{children:["Explorer les positions 5–20 ",e.jsx(zn,{size:14})]})]})]}),e.jsxs("section",{className:"gsc-table-section","aria-label":"Requêtes Search Console",children:[e.jsx("div",{className:"gsc-table-heading",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Vos requêtes"}),e.jsxs("p",{children:[F(q)," sur ",F(t.length)," enrichies avec Google Ads"]})]})}),e.jsxs("div",{className:"gsc-toolbar",children:[e.jsxs("label",{className:"gsc-search",children:[e.jsx(ns,{size:16}),e.jsx("input",{type:"search","aria-label":"Rechercher une requête",placeholder:"Rechercher une requête…",value:x,onChange:R=>{z(R.target.value),T(0)}})]}),e.jsxs("div",{className:"gsc-filters","aria-label":"Filtrer les positions",children:[e.jsxs("button",{"aria-pressed":!m,onClick:()=>{d(!1),T(0)},children:["Toutes ",e.jsx("span",{children:F(t.length)})]}),e.jsxs("button",{"aria-pressed":m,onClick:()=>{d(!0),T(0)},children:["Positions 5–20 ",e.jsx("span",{children:F(je)})]})]})]}),e.jsx("div",{className:"gsc-table-scroll",tabIndex:0,role:"region","aria-label":"Tableau des requêtes, défilement horizontal",children:e.jsxs("table",{className:"gsc-table",children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"24%"}}),e.jsx("col",{style:{width:"7%"}}),e.jsx("col",{style:{width:"9%"}}),e.jsx("col",{style:{width:"7%"}}),e.jsx("col",{style:{width:"8%"}}),e.jsx("col",{style:{width:"10%"}}),e.jsx("col",{style:{width:"22%"}}),e.jsx("col",{style:{width:"13%"}})]}),e.jsxs("thead",{children:[e.jsxs("tr",{className:"gsc-source-labels",children:[e.jsx("th",{scope:"col",children:"Requête de recherche"}),e.jsxs("th",{colSpan:4,scope:"colgroup",children:["Google Search Console ",e.jsx("span",{children:"Performance du site"})]}),e.jsxs("th",{colSpan:3,scope:"colgroup",children:["Google Ads ",e.jsx("span",{children:"Demande du marché"})]})]}),e.jsx("tr",{children:Hn().map(R=>e.jsx("th",{scope:"col","aria-sort":p===R.champ?y==="asc"?"ascending":"descending":"none",style:{textAlign:R.align},children:e.jsxs("button",{onClick:()=>b(R.champ),style:{justifyContent:R.align==="right"?"flex-end":"flex-start"},children:[R.label,p===R.champ?y==="asc"?e.jsx(Jr,{size:13}):e.jsx(Vr,{size:13}):e.jsx(Gr,{size:12})]})},R.champ))})]}),e.jsxs("tbody",{children:[N.slice(ne*L,(ne+1)*L).map(R=>{const H=_i(R.competition);return e.jsxs("tr",{children:[e.jsx("td",{title:R.query,className:"gsc-query",children:R.query}),e.jsx("td",{className:"gsc-number",children:R.clicks}),e.jsx("td",{className:"gsc-number",children:new Intl.NumberFormat("fr-FR").format(R.impressions)}),e.jsxs("td",{className:"gsc-number",children:[R.ctr.toFixed(1)," %"]}),e.jsx("td",{className:`gsc-number${R.position>=5&&R.position<=20?" gsc-position-opportunity":""}`,children:R.position.toFixed(1)}),e.jsx("td",{className:"gsc-number",children:R.volume==null?e.jsx("span",{className:"gsc-unmeasured",children:a("rech_projectviews.nonMesur")}):new Intl.NumberFormat("fr-FR").format(R.volume)}),e.jsx("td",{className:"gsc-market",children:R.cpc_low==null&&R.cpc_high==null?"·":`${Number(R.cpc_low??0).toFixed(2)} à ${Number(R.cpc_high??0).toFixed(2)} €`}),e.jsx("td",{className:"gsc-market",children:H?e.jsxs("span",{className:"gsc-competition",children:[e.jsx("i",{style:{background:H.dot}}),H.label]}):"·"})]},R.id)}),!N.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,children:e.jsxs("div",{className:"gsc-no-results",children:[e.jsx("strong",{children:"Aucune requête ne correspond"}),e.jsx("span",{children:"Essayez un autre mot ou retirez le filtre de position."}),e.jsx("button",{onClick:()=>{z(""),d(!1),T(0)},children:"Réinitialiser les filtres"})]})})})]})]})}),e.jsxs("footer",{className:"gsc-pagination",children:[e.jsx("span",{role:"status",children:N.length?`${ne*L+1}–${Math.min((ne+1)*L,N.length)} sur ${F(N.length)} requêtes`:"0 requête"}),e.jsxs("div",{children:[e.jsx("button",{"aria-label":"Page précédente",disabled:ne===0,onClick:()=>T(ne-1),children:e.jsx(Kr,{size:16})}),e.jsxs("span",{children:["Page ",ne+1," / ",he+1]}),e.jsx("button",{"aria-label":"Page suivante",disabled:ne>=he,onClick:()=>T(ne+1),children:e.jsx(zn,{size:16})})]})]})]}),e.jsx("p",{className:"gsc-footnote",children:a("rech_projectviews.clicsImpressionsCtrEt")})]})]})})}const qi=()=>({renforcer:{label:"Renforcer",bg:"rgba(5,150,105,0.10)",text:"#047857"},creer:{label:E.t("rech_projectviews.crer"),bg:"rgba(10,143,111,0.10)",text:"#087A5E"},ignorer:{label:"Ne rien faire",bg:"rgba(107,114,128,0.10)",text:"#4B5563"}});function zi({decisions:t,run:n,lancement:r,erreur:s,onLancer:i}
20){const{t:o}=ee(),[c,u]=l.useState({}),[a,p]=l.useState(!1);if(r||!!n&&!["done","error"].includes(n.phase))return e.jsx(mr,{kind:"plan",journal:(n==null?void 0:n.journal)||[],phase:(n==null?void 0:n.phase)||"queued",startedAt:(n==null?void 0:n.started_at)||new Date().toISOString(),error:n==null?void 0:n.error,titre:o("rech_projectviews.constructionDuPlan")});if(!t.length)return e.jsxs("div",{style:{border:`1px dashed ${C.border}`,borderRadius:14,background:"#fff",padding:"40px 28px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:15,color:C.text,fontWeight:600,marginBottom:6},children:o("rech_projectviews.pasEncoreDePlan")}),e.jsx("div",{style:{fontSize:13.5,color:C.muted,lineHeight:1.5,maxWidth:540,margin:"0 auto 18px"},children:o("rech_projectviews.qadencePartDeCe")}),(n==null?void 0:n.error)&&e.jsxs("div",{style:{background:"rgba(220,38,38,0.06)",border:"1px solid rgba(220,38,38,0.2)",borderRadius:10,padding:"11px 14px",fontSize:13,color:"#DC2626",marginBottom:16,textAlign:"left"},children:["Dernier essai interrompu : ",n.error]}),s&&e.jsx("div",{style:{background:"rgba(220,38,38,0.06)",border:"1px solid rgba(220,38,38,0.2)",borderRadius:10,padding:"11px 14px",fontSize:13,color:"#DC2626",marginBottom:16,textAlign:"left"},children:s}),e.jsx("button",{onClick:i,style:{background:C.accent,color:"#fff",border:"none",borderRadius:10,padding:"11px 22px",fontSize:13.5,fontWeight:600,cursor:"pointer"},children:o("rech_projectviews.lancerLaRecherche")})]});const y=t.filter(d=>d.decision!=="ignorer"),w=t.filter(d=>d.decision==="ignorer"),m=a?t:y;return e.jsxs("div",{children:[(n==null?void 0:n.resume)&&e.jsx("div",{style:{background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,padding:"14px 16px",fontSize:13.5,color:C.muted,lineHeight:1.6,marginBottom:14},children:n.resume}),s&&e.jsx("div",{style:{background:"rgba(220,38,38,0.06)",border:"1px solid rgba(220,38,38,0.2)",borderRadius:10,padding:"11px 14px",fontSize:13,color:"#DC2626",marginBottom:14},children:s}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14,flexWrap:"wrap"},children:[e.jsxs("button",{onClick:()=>p(d=>!d),style:{background:a?C.text:"#fff",color:a?"#fff":C.text,border:`1px solid ${a?C.text:C.border}`,borderRadius:999,padding:"6px 13px",fontSize:12.5,fontWeight:600,cursor:"pointer"},children:[a?"Masquer":"Voir"," les ",w.length," groupes laissés de côté"]}),e.jsx("button",{onClick:i,style:{background:"#fff",color:C.text,border:`1px solid ${C.border}`,borderRadius:999,padding:"6px 13px",fontSize:12.5,fontWeight:600,cursor:"pointer"},children:o("rech_projectviews.relancerLaRecherche")})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:m.map(d=>{const h=qi()[d.decision],j=!!c[d.id];return e.jsxs("div",{style:{background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,overflow:"hidden",opacity:d.decision==="ignorer"?.72:1},children:[e.jsxs("div",{style:{padding:"14px 16px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx("span",{style:{background:h.bg,color:h.text,fontSize:11.5,fontWeight:700,padding:"3px 10px",borderRadius:999,textTransform:"uppercase",letterSpacing:"0.04em"},children:h.label}),e.jsx("span",{style:{fontSize:15,fontWeight:600,color:C.text},children:d.cluster_nom}),d.etage&&e.jsx("span",{style:{fontSize:12,color:C.muted},children:d.etage})]}),e.jsx("div",{style:{fontSize:13.5,color:C.muted,lineHeight:1.55,marginTop:8},children:d.justification}),e.jsxs("div",{style:{display:"flex",gap:18,flexWrap:"wrap",marginTop:10,fontSize:12.5,color:C.muted,fontVariantNumeric:"tabular-nums"},children:[e.jsxs("span",{children:[d.nb_requetes," requête",d.nb_requetes>1?"s":""]}),e.jsx("span",{children:d.volume_total==null?o("rech_projectviews.demandeNonMesure"):`${d.volume_total.toLocaleString("fr-FR")} recherches/mois`}),d.impressions_total>0&&e.jsxs("span",{children:[d.impressions_total.toLocaleString("fr-FR")," impressions"]}),d.position_moyenne!=null&&e.jsxs("span",{children:["position ",d.position_moyenne]}),d.score_conversion!=null&&e.jsxs("span",{children:["conversion ",d.score_conversion,"/100"]}),d.reponse_ia&&e.jsxs("span",{children:["l'IA répond à votre place : ",d.reponse_ia]})]}),e.jsx("button",{onClick:()=>u(x=>({...x,[d.id]:!j})),style:{marginTop:10,background:"none",border:"none",padding:0,color:C.accent,fontSize:12.5,fontWeight:600,cursor:"pointer"},children:o(j?"rech_projectviews.masquerLesRequtes":"rech_projectviews.voirLesRequtes")})]}),j&&e.jsx("div",{style:{padding:"0 16px 16px"},children:e.jsx("div",{style:{background:mt,borderRadius:10,padding:"12px 14px",fontSize:13,color:C.text,lineHeight:1.8},children:d.requetes.map((x,z)=>e.jsxs("span",{style:{color:x===d.pivot?C.text:C.muted,fontWeight:x===d.pivot?600:4
2000},children:[x,z<d.requetes.length-1?" · ":""]},x))})})]},d.id)})})]})}function Ri({data:t,run:n,onGenerate:r}){var o;const{t:s}=ee();return!!n&&!["done","error"].includes(n.phase)?e.jsx(mr,{kind:"geo",journal:(n==null?void 0:n.journal)||[],phase:(n==null?void 0:n.phase)||"queued",startedAt:(n==null?void 0:n.started_at)||new Date().toISOString(),error:n==null?void 0:n.error,titre:s("rech_projectviews.constructionDeLaStratgie")}):(o=t==null?void 0:t.univers_requetes)!=null&&o.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:12},children:e.jsx("button",{onClick:r,style:{background:"#fff",color:C.text,border:`1px solid ${C.border}`,borderRadius:999,padding:"6px 13px",fontSize:12.5,fontWeight:600,cursor:"pointer"},children:s("rech_projectviews.regnrer")})}),e.jsx(Ns,{data:t})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{style:{border:`1px dashed ${C.border}`,borderRadius:14,background:"#fff",padding:"40px 28px",textAlign:"center"},children:[e.jsx("div",{style:{fontSize:15,color:C.text,fontWeight:600,marginBottom:6},children:s("rech_projectviews.pasEncoreDeStratgie")}),e.jsx("div",{style:{fontSize:13.5,color:C.muted,lineHeight:1.5,maxWidth:520,margin:"0 auto 18px"},children:s("rech_projectviews.diagnosticDeVotrePrsence")}),e.jsx("button",{onClick:r,style:{background:C.accent,color:"#fff",border:"none",borderRadius:10,padding:"11px 22px",fontSize:13.5,fontWeight:600,cursor:"pointer"},children:s("rech_projectviews.construireLaStratgie")})]})})}function Ni(t){const n=t.decisions.length>0||!!t.run||t.planLancement||!!t.planErreur,r=!!t.data||!!t.geoRun;return e.jsx(zs,{messages:t.messages,onGiveTask:t.onGiveTask,onDiscuss:t.onDiscuss,onOpenChat:t.onOpenChat,children:n||r?e.jsxs("div",{className:"kad-legacy-results",children:[n&&e.jsxs("details",{children:[e.jsx("summary",{children:"Plan de pages"}),e.jsx(zi,{decisions:t.decisions,run:t.run,lancement:t.planLancement,erreur:t.planErreur,onLancer:t.onLancerPlan})]}),r&&e.jsxs("details",{children:[e.jsx("summary",{children:"Stratégie GEO"}),e.jsx(Ri,{data:t.data,run:t.geoRun,onGenerate:t.onGenerate})]})]}):void 0})}function Ei(t){return t?t<1024?`${t} o`:t<1024*1024?`${Math.round(t/1024)} ko`:`${(t/(1024*1024)).toFixed(1)} Mo`:""}function Ai({memory:t,documents:n,uploading:r,uploadError:s,onUpload:i,onDelete:o,action:c,sourceTools:u,onAnalyzeDocument:a}){const{t:p}=ee(),g=Object.entries(t),[y,w]=l.useState({}),[m,d]=l.useState(!1);return e.jsxs(Rt,{title:p("rech_projectviews.mmoire"),subtitle:`${g.length} fait${g.length>1?"s":""} retenu${g.length>1?"s":""}, ${n.length} document${n.length>1?"s":""}. L'agent y cherche ce dont il a besoin au moment où il en a besoin.`,action:c,children:[u,g.length>0&&e.jsxs("div",{style:{marginBottom:26},children:[e.jsx("div",{style:{fontSize:11.5,color:C.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700,marginBottom:10},children:p("rech_projectviews.ceQueLAgent")}),e.jsx("div",{style:{background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,overflow:"hidden"},children:g.map(([h,j],x)=>e.jsxs("div",{style:{display:"flex",gap:16,padding:"13px 18px",borderTop:x?`1px solid ${C.border}`:"none"},children:[e.jsx("div",{style:{width:160,flexShrink:0,fontSize:13,fontWeight:600,color:C.text},children:h}),e.jsx("div",{style:{fontSize:13.5,color:C.muted,lineHeight:1.5},children:j})]},h))})]}),e.jsx("div",{style:{fontSize:11.5,color:C.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700,marginBottom:10},children:p("rech_projectviews.documentsDuProjet")}),!u&&e.jsxs("label",{onDragOver:h=>{h.preventDefault(),d(!0)},onDragLeave:()=>d(!1),onDrop:h=>{var j;h.preventDefault(),d(!1),(j=h.dataTransfer.files)!=null&&j.length&&i(h.dataTransfer.files)},style:{display:"block",cursor:r?"wait":"pointer",border:`1px dashed ${m?C.accent:C.border}`,background:m?"rgba(10,143,111,0.03)":"#fff",borderRadius:14,padding:"26px 20px",textAlign:"center",marginBottom:16},children:[e.jsx("input",{type:"file",multiple:!0,accept:Es,disabled:r,onChange:h=>{var j;(j=h.target.files)!=null&&j.length&&i(h.target.files),h.target.value=""},style:{display:"none"}}),e.jsx("div",{style:{fontSize:14,fontWeight:600,color:C.text},children:p(r?"rech_projectviews.lectureDuDocument":"rech_projectviews.dposezVosDocumentsIci")}),e.jsxs("div",{style:{fontSize:13,color:C.muted,marginTop:5,lineHeight:1.5},children:["Brief client, transcript d'appel, offre, export, notes. ",As,". Le texte est extrait sur votre poste, seul le texte est envoyé."]})]}),s&&e.jsx("div",{style:{background:"rgba(220,38,38,0.06)",border:"1px solid rgba(220,38,38,0.2)",borderRadius:10,padding:"11px 14px",fontSize:13.5,color:"#DC2626",marginBottom:16},children:s}),n.length===0?e.jsx("div",{style:{fontSize:13.5,color:C.muted,lineHeight:1.6},children:p("rech_projectviews.aucunDocumentPourL")}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:n.map(h=>{const j=!!y[h.id];let x="";try{x=new Date(h.created_at).toLocaleDateString("fr-FR",{day:"2-digit",month:"short",year:"numeric"})}catch{}return e.jsxs("div",{style:{background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"13px 16px"},children:[e.jsxs("button",{onClick:()=>w(z=>({...z,[h.id]:!j})),style:{flex:1,display:"flex",alignItems:"center",gap:10,background:"none",border:"none",cursor:"pointer",textAlign:"left",padding:0,minWidth:0},children:[e.jsx("span",{style:{display:"flex",transform:j?"none":"rotate(-90deg)",transition:"transform .15s",color:C.muted,flexShrink:0},children:e.jsx("svg",{width:15,height:15,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}),e.jsx("span",{style:{fontSize:14,fontWeight:600,color:C.text,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:h.file_name}),e.jsx("span",{style:{fontSize:12,color:C.muted,flexShrink:0}
20,children:[Ei(h.file_size),x].filter(Boolean).join(" · ")})]}),a&&e.jsx("button",{className:"fs-source-link",onClick:()=>a(h),children:"Analyser les passages utiles"}),e.jsx("button",{onClick:()=>o(h.id),title:p("rech_projectviews.retirerCeDocumentDe"),style:{background:"none",border:"none",color:C.muted,cursor:"pointer",padding:4,flexShrink:0},children:e.jsxs("svg",{width:15,height:15,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]}),j&&e.jsx("div",{style:{padding:"0 16px 16px"},children:e.jsxs("div",{style:{background:mt,borderRadius:10,padding:"12px 14px",fontSize:13,color:C.muted,lineHeight:1.6,whiteSpace:"pre-wrap",maxHeight:320,overflowY:"auto"},children:[h.content.slice(0,4e3),h.content.length>4e3&&`
21
22… document tronqué à l'affichage, ${new Intl.NumberFormat("fr-FR").format(h.content.length)} caractères au total.`]})})]},h.id)})})]})}function Li({messages:t,briefs:n,action:r,onGenerateBrief:s,onAskInChat:i}){const{t:o}=ee(),[c,u]=l.useState(null),a=qn(t),p=new Map;for(const d of n){const h=d.keyword.toLowerCase().trim();p.has(h)||p.set(h,d)}const g=[...p.values()],y=c?p.get(c.toLowerCase().trim()):void 0,w=d=>d!=null&&d!==""?new Intl.NumberFormat("fr-FR").format(Number(d)):"—",m=d=>d!=null&&d!==""?`${Number(d).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2})} €`:"Non mesuré";return e.jsxs(Rt,{title:o("x_projectviews.briefs"),subtitle:a.length?`${a.length} mots-clés business · cliquez une carte pour générer son brief`:n.length?`${n.length} brief${n.length>1?"s":""} dans ce projet`:void 0,action:r,children:[a.length>0&&e.jsx("div",{className:"brief-keyword-grid",children:a.map(d=>{const h=String(d.keyword||""),j=p.get(h.toLowerCase().trim());return e.jsxs("button",{className:"brief-keyword-card",onClick:()=>{j||s(h),u(h)},children:[e.jsxs("span",{className:"brief-keyword-topline",children:[e.jsx("span",{className:"brief-keyword-family",children:"Business"}),e.jsx("span",{className:"brief-keyword-arrow","aria-hidden":"true",children:"↗"})]}),e.jsx("strong",{className:"brief-keyword-name",children:h}),e.jsxs("span",{className:"brief-keyword-metrics",children:[e.jsxs("span",{children:[e.jsx("small",{children:"Volume"}),e.jsx("b",{children:w(d.volume)})]}),e.jsxs("span",{children:[e.jsx("small",{children:"CPC"}),e.jsx("b",{children:m(d.cpc)})]}),e.jsxs("span",{children:[e.jsx("small",{children:"Intention"}),e.jsx("b",{children:d.intention||"À qualifier"})]})]}),e.jsx("span",{className:`brief-keyword-action ${j!=null&&j.pending?"is-pending":""}`,children:j!=null&&j.pending?"Brief en cours…":j?"Ouvrir le brief":"Générer le brief"})]},h)})}),!a.length&&!n.length&&e.jsxs(e.Fragment,{children:[e.jsx(wr,{label:o("rech_projectviews.pasEncoreDeBrief"),description:o("rech_projectviews.ouvrezUnMotCl"),cta:o("rech_projectviews.gnrerUnBrief"),prompt:o("rech_projectviews.rdigeLeBriefDu"),onAskInChat:i}),e.jsx("div",{style:{fontSize:13,color:C.muted,marginTop:14},children:o("rech_projectviews.astuceDansLOnglet")})]}),g.length>0&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10,marginTop:a.length?30:0},children:[a.length>0&&e.jsx("div",{style:{fontSize:13,color:C.muted,fontWeight:600},children:"Briefs générés"}),g.map(d=>{let h="";if(d.createdAt)try{h=new Date(d.createdAt).toLocaleDateString("fr-FR",{day:"2-digit",month:"short",hour:"2-digit",minute:"2-digit"})}catch{}return e.jsxs("button",{onClick:()=>u(d.keyword),style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,background:"#fff",border:`1px solid ${C.border}`,borderRadius:14,padding:"14px 18px",cursor:"pointer",textAlign:"left"},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:10,minWidth:0},children:[e.jsx("span",{style:{fontSize:10.5,color:d.pending?C.accent:d.error||d.interrupted?"var(--danger, #B4534B)":C.muted,textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:700,flexShrink:0},children:d.pending?o("rech_projectviews.enCours"):d.error||d.interrupted?o("kw_brief.rowInterrompu"):"Brief"}),e.jsx("span",{style:{fontSize:14,fontWeight:600,color:C.text,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:d.keyword})]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:12,flexShrink:0,color:C.muted},children:[h&&e.jsx("span",{style:{fontSize:12},children:h}),e.jsx("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})]})]},d.id)})]}),y&&e.jsx(pi,{brief:y,onClose:()=>u(null),onRegenerate:d=>s(d)})]})}function Fi({view:t,messages:n,memory:r={},briefs:s=[],projectName:i,onGenerateBrief:o,onAskInChat:c,onGiveKeywordTask:u,onOpenAgentChat:a,gscRows:p=[],gscLoading:g=!1,gscError:y=null,onImportGsc:w,siteProperty:m,onGscProperty:d,fiche:h=null,ficheLe:j=null,ficheDomaine:x,ficheEnCours:z=!1,ficheErreur:$=null,onRefaireFiche:T,documents:L=[],uploadingDoc:b=!1,uploadError:N=null,onUploadDocuments:W,onDeleteDocument:q,sourceTools:J,onAnalyzeDocument:ce,decisions:G=[],run:je=null,planLancement:he=!1,planErreur:ne=null,onLancerPlan:F,strategie:R=null,geoRun:H=null,onGenerateStrategie:te}){const pe=fi(n,r,s),I=pe.length?e.jsx(bi,{onExport:()=>ji(i,pe)}):void 0;return t==="decisions"?e.jsx(vi,{messages:n,action:I,onOpenMessage:a}):t==="fiche"?e.jsx(Rt,{title:E.t("rech_fiche.titre"),subtitle:x?E.t("rech_fiche.sousTitre",{domaine:x}):void 0,action:I,children:e.jsx(Ms,{fiche:h,ficheLe:j,domaine:x,enCours:z,erreur:$,onRefaire:()=>T==null?void 0:T()})}):t==="keywords"?e.jsx(ki,{messages:n,action:I,onGenerateBrief:be=>o==null?void 0:o(be),onAskInChat:c}
22):t==="gsc"?e.jsx(Ci,{rows:p,loading:g,error:y,onImport:be=>w==null?void 0:w(be),action:I,siteProperty:m,onGscProperty:d}):t==="agent"?e.jsx(Ni,{messages:n,onGiveTask:u||c,onDiscuss:c,onOpenChat:a,data:R,geoRun:H,onGenerate:()=>te==null?void 0:te(),action:I,decisions:G,run:je,planLancement:he,planErreur:ne,onLancerPlan:()=>F==null?void 0:F()}):t==="briefs"?e.jsx(Li,{messages:n,briefs:s,action:I,onGenerateBrief:be=>o==null?void 0:o(be),onAskInChat:c}):t==="memory"?e.jsx(Ai,{sourceTools:J,onAnalyzeDocument:ce,memory:r,documents:L,uploading:b,uploadError:N,onUpload:be=>W==null?void 0:W(be),onDelete:be=>q==null?void 0:q(be),action:I}):null}function Bt(t){const n=(t.domain||t.gsc_property||"").trim().replace(/^sc-domain:/,"");if(!n)return"";try{const r=new URL(/^https?:\/\//i.test(n)?n:`https://${n}`);return/^https?:$/.test(r.protocol)?r.hostname:""}catch{return""}}function Un({hostname:t}){const[n,r]=l.useState(!1);return!t||n?e.jsx(nr,{size:18}):e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${encodeURIComponent(t)}&sz=64`,width:20,height:20,alt:"",referrerPolicy:"no-referrer",onError:()=>r(!0),style:{objectFit:"contain"}})}function Ti({collapsed:t,onToggleCollapse:n,projects:r,activeProjectId:s,onSetProject:i,onNewProject:o,onNewConversation:c,onDeleteProject:u,activeView:a,onSelectView:p,history:g,activeConvId:y,onLoadConv:w,onOpenAccount:m,onOpenOverview:d,overviewActive:h,onAnalyzeSource:j}){var ze;const{t:x}=ee(),[z,$]=l.useState(!1),[T,L]=l.useState({}),[b,N]=l.useState(!1),[W,q]=l.useState(!1),[J,ce]=l.useState({}),G=l.useRef(null),je=l.useRef(null),he=l.useId(),ne=l.useId();l.useEffect(()=>{let M=!0;return(async()=>{var ge,oe,fe;const{data:{user:Y}}=await qe.auth.getUser();if(!Y||!M)return;L({name:((ge=Y.user_metadata)==null?void 0:ge.full_name)||((oe=Y.user_metadata)==null?void 0:oe.name),email:Y.email,picture:(fe=Y.user_metadata)==null?void 0:fe.avatar_url});const{data:k}=await qe.from("google_connections").select("email, name, picture").order("updated_at",{ascending:!1}),B=k||[],se=B.find(we=>we.email)||B[0];M&&se&&L(we=>({name:se.name||we.name,email:se.email||we.email,picture:se.picture||we.picture}))})().catch(()=>{}),()=>{M=!1}},[]),l.useEffect(()=>{if(!W)return;function M(k){var B;(B=G.current)!=null&&B.contains(k.target)||q(!1)}function Y(k){var B;k.key==="Escape"&&(q(!1),(B=je.current)==null||B.focus())}return document.addEventListener("pointerdown",M),document.addEventListener("keydown",Y),()=>{document.removeEventListener("pointerdown",M),document.removeEventListener("keydown",Y)}},[W]);const F=r.filter(M=>!M.parent_id),R=r.find(M=>M.id===s)||null,H=R!=null&&R.parent_id&&r.find(M=>M.id===R.parent_id)||R,te=(H==null?void 0:H.domain)||(H==null?void 0:H.name)||x("rech_sidebar.nouveauProjet"),pe=T.name||((ze=T.email)==null?void 0:ze.split("@")[0])||x("rech_sidebar.monCompte"),I=l.useMemo(()=>{const Y=Date.now(),k=[];for(const B of[...g].sort((se,ge)=>ge.updatedAt-se.updatedAt)){const se=Y-B.updatedAt,ge=se<864e5?"today":se<7*864e5?"week":"older";let oe=k.find(fe=>fe.bucket===ge);oe||(oe={bucket:ge,items:[]},k.push(oe)),oe.items.push(B)}return k},[g]),be={today:x("rech_sidebar.aujourdhui"),week:x("rech_sidebar.septDerniersJours"),older:x("rech_sidebar.plusAncien")};function Le(M){var Y;q(!1),i(M),(Y=je.current)==null||Y.focus()}function Fe(){q(!1),n()}return t?e.jsxs("aside",{className:"qadence-sidebar fs-collapsed","aria-label":"Barre latérale réduite",children:[e.jsx("button",{className:"fs-collapsed-toggle",onClick:n,title:"Ouvrir la barre latérale","aria-label":"Ouvrir la barre latérale",children:e.jsx(es,{size:18})}),e.jsx("nav",{className:"fs-collapsed-tabs","aria-label":"Onglets du projet",children:jn.map(({id:M,label:Y,icon:k})=>{const B=M===a;return e.jsx("button",{className:`fs-collapsed-tab ${B?"is-active":""}`,onClick:()=>p(M),"aria-label":Y,"aria-current":B?"page":void 0,title:Y,children:e.jsx(k,{size:18})},M)})})]}):e.jsxs("aside",{className:"qadence-sidebar","aria-label":x("rech_sidebar.navigationProjet"),children:[e.jsxs("header",{className:"fs-header",children:[e.jsxs("div",{className:"fs-brand",children:[e.jsx(Lr,{height:20}),e.jsx("span",{children:"qadence"}),e.jsx("small",{children:"workspace"})]}),e.jsx("button",{className:"fs-icon-button",onClick:Fe,title:x("rech_sidebar.masquerLeMe
22nu"),"aria-label":x("rech_sidebar.masquerLeMenu"),children:e.jsx(Zr,{size:17})})]}),e.jsxs("div",{className:"fs-picker",ref:G,onBlur:M=>{M.currentTarget.contains(M.relatedTarget)||q(!1)},children:[e.jsxs("button",{ref:je,className:"fs-site-select",onClick:()=>q(M=>!M),"aria-expanded":W,"aria-controls":he,children:[e.jsx("span",{className:"fs-site-avatar","aria-hidden":"true",children:H?e.jsx(Un,{hostname:Bt(H)},Bt(H)):e.jsx(ot,{size:16})}),e.jsxs("span",{className:"fs-site-identity",children:[e.jsx("small",{children:x("rech_sidebar.siteActif")}),e.jsx("strong",{title:te,children:te}),(R==null?void 0:R.parent_id)&&e.jsx("span",{title:R.name,children:R.name})]}),e.jsx(St,{size:15,className:W?"fs-chevron-open":""})]}),W&&e.jsxs("div",{id:he,className:"fs-site-menu",children:[F.map(M=>{const Y=r.filter(B=>B.parent_id===M.id),k=J[M.id]??Y.some(B=>B.id===s);return e.jsxs("div",{children:[e.jsxs("div",{className:`fs-project-row ${M.id===s?"is-active":""}`,children:[Y.length>0&&e.jsx("button",{className:"fs-icon-button fs-tree-toggle",onClick:()=>ce(B=>({...B,[M.id]:!k})),"aria-expanded":k,"aria-label":`${x("rech_sidebar.sousProjets")} ${M.domain||M.name}`,children:e.jsx(St,{size:12,className:k?"":"fs-chevron-closed"})}),e.jsxs("button",{className:"fs-project-select",onClick:()=>Le(M.id),"aria-current":M.id===s?"true":void 0,children:[e.jsx("span",{className:"fs-project-favicon","aria-hidden":"true",children:e.jsx(Un,{hostname:Bt(M)},Bt(M))}),e.jsxs("span",{title:M.domain||M.name,children:[M.domain||M.name,!M.domain&&e.jsx("small",{children:x("rech_sidebar.sansDomaine")})]})]}),e.jsx("button",{className:"fs-icon-button fs-delete",onClick:()=>u(M.id),"aria-label":`${x("x_sidebar.supprimer")} ${M.domain||M.name}`,children:e.jsx(Rn,{size:13})})]}),k&&Y.map(B=>e.jsxs("div",{className:`fs-project-row fs-child ${B.id===s?"is-active":""}`,children:[e.jsx("button",{className:"fs-project-select",onClick:()=>Le(B.id),"aria-current":B.id===s?"true":void 0,children:e.jsx("span",{title:B.name,children:B.name})}),e.jsx("button",{className:"fs-icon-button fs-delete",onClick:()=>u(B.id),"aria-label":`${x("x_sidebar.supprimer")} ${B.name}`,children:e.jsx(Rn,{size:12})})]},B.id))]},M.id)}),e.jsxs("button",{className:"fs-add-site",onClick:()=>{q(!1),o()},children:[e.jsx(ot,{size:15}),x("rech_sidebar.nouveauProjet")]})]})]}),e.jsxs("div",{className:"fs-scroll",children:[e.jsxs("button",{className:`fs-nav-item fs-overview ${h?"is-active":""}`,onClick:d,"aria-current":h?"page":void 0,children:[e.jsx(Xr,{size:17,strokeWidth:1.7}),e.jsx("span",{children:x("rech_sidebar.tousMesProjets")}),e.jsx(tr,{size:14})]}),e.jsx("div",{className:"fs-section-label",children:x("rech_sidebar.dansCeProjet")}),e.jsx("nav",{"aria-label":x("rech_sidebar.dansCeProjet"),children:jn.map(({id:M,label:Y,icon:k})=>e.jsxs("button",{className:`fs-nav-item ${!h&&M===a?"is-active":""}`,onClick:()=>p(M),"aria-current":!h&&M===a?"page":void 0,children:[e.jsx(k,{size:17}),e.jsx("span",{children:Y})]},M))}),e.jsxs("section",{className:"fs-history",children:[e.jsxs("button",{className:"fs-history-toggle",onClick:()=>$(M=>!M),"aria-expanded":z,"aria-controls":ne,children:[e.jsx(Yr,{size:15}),e.jsx("span",{children:x("rech_sidebar.conversationsRecentes")}),e.jsx(St,{size:14,className:z?"":"fs-chevron-closed"})]}),z&&e.jsxs("div",{id:ne,className:"fs-history-items",children:[g.length===0&&e.jsx("p",{children:x("rech_sidebar.aucuneConversation")}),I.map(M=>e.jsxs("div",{children:[e.jsx("div",{className:"fs-history-date",children:be[M.bucket]}),M.items.map(Y=>e.jsx("button",{title:Y.title||x("rech_sidebar.conversation"),className:!h&&Y.id===y&&a==="chat"?"is-active":"",onClick:()=>w(Y.id),children:Y.title||x("rech_sidebar.conversation")},Y.id))]},M.bucket))]})]})]}),e.jsxs("footer",{className:"fs-footer",children:[c&&e.jsxs("button",{className:"fs-new-conversation",onClick:c,children:[e.jsx(ot,{size:16}),x("chatUx.newConversation")]}),j&&R&&e.jsxs("button",{className:"fs-nav-item",onClick:j,children:[e.jsx(ot,{size:16}),e.jsx("span",{children:"Analyser une source"})]}),e.jsxs("button",{className:"fs-new-project",onClick:o,children:[e.jsx(ot,{size:17}),x("rech_sidebar.nouveauProjet")]}),e.jsxs("button",{className:"fs-account",onClick:m,children:[T.picture&&!b?e.jsx("img",{className:"fs-user-avatar",src:T.picture,alt:"",referrerPolicy:"no-referrer",onError:()=>N(!0)}):e.jsx("span",{className:"fs-user-avatar",children:T.name||T.email?pe.split(/\s+/).slice(0,2).map(M=>M.charAt(0)).join("").toUpperCase():e.jsx(ss,{size:16})}),e.jsxs("span",{className:"fs-account-label",children:[e.jsx("strong",{title:pe,children:pe}),e.jsx("small",{children:x("rech_sidebar.monCompte")})]}),e.jsx(rs,{size:16})]})]})]})}function Jn(){return t=>_r(t)}function _r(t){if(!t||!Array.isArray(t.children))return;const n=[];for(const r of t.children)r.type==="text"&&typeof r.value=="string"&&r.value.includes("==")?r.value.split(/==([^=\n]+)==/g).forEach((i,o)=>{i!==""&&(o%2===1?n.push({type:"emphasis",data:{hName:"mark",hProperties:{className:["kchat-hl"]}},children:[{type:"text",value:i}]}):n.push({type:"text",value:i}))}):(_r(r),n.push(r));t.children=n}async function Cr(t,n){if(!t.body)return;const r=t.body.getReader(),s=new TextDecoder;let i="";for(;;){const{done:o,value:c}=await r.read();if(o)break;i+=s.decode(c,{stream:!0});const u=i.split(`
23`);i=u.pop()??"";for(const a of u){if(!a.startsWith("data:"))continue;const p=a.slice(5).trim();if(!p||p==="[DONE]")continue;let g;
23try{g=JSON.parse(p)}catch{continue}n(g)}}}const $i=`${Pt}/functions/v1/keyword-agent`;class Ze extends Error{constructor(n,r=""){super(n),this.name="AgentError",this.code=r}}async function qr(t){let n="",r="";try{const s=await t.json();n=String((s==null?void 0:s.error)||""),r=String((s==null?void 0:s.message)||"")}catch{}return n==="free_quota_exhausted"?new Ze(r||E.t("h_keywordagent.quotaGratuitEpuise"),n):n==="premium_required"?new Ze(r||E.t("h_keywordagent.laRechercheDeMots"),n):n==="auth_required"?new Ze(r||E.t("h_keywordagent.connectezVousPourUtiliser"),n):new Ze(r||`Agent ${t.status}`,n)}async function Wi(t,n={},r){var c,u,a;let s=dt;try{const{data:p}=await qe.auth.getSession();(c=p.session)!=null&&c.access_token&&(s=p.session.access_token)}catch{}const i=await fetch($i,{method:"POST",headers:{"Content-Type":"application/json",apikey:dt,Authorization:`Bearer ${s}`},body:JSON.stringify({message:t,history:(n.history||[]).slice(-6).map(p=>({role:p.role,content:String(p.content).slice(0,2500)})),lang:Ot(),kickoff:!1,project:n.project||{},memory:n.memory||{},context:n.context||"",gscProperty:((u=n.project)==null?void 0:u.gsc_property)??((a=n.project)!=null&&a.id?"":fr()||"")})});if(!i.ok)throw await qr(i);let o="";return await Cr(i,p=>{if(p.thinking,typeof p.text=="string"&&(o+=p.text),p.error)throw new Error(String(p.error))}),o.replace(/```suggestions[\s\S]*?```/g,"").trim()}const Mi='button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), a[href], [tabindex="0"]';function Bi(t,n,r){const s=l.useRef(r);s.current=r,l.useEffect(()=>{if(!n||!t.current)return;const i=t.current,o=document.activeElement,c=()=>Array.from(i.querySelectorAll(Mi)).filter(p=>p.getClientRects().length);(i.querySelector("[data-autofocus]")||c()[0]||i).focus();function u(p){if(p.key==="Escape"&&(p.preventDefault(),p.stopPropagation(),s.current()),p.key==="Tab"){const g=c(),y=g[0]||i,w=g[g.length-1]||i;p.shiftKey&&(document.activeElement===y||document.activeElement===i)?(p.preventDefault(),w.focus()):!p.shiftKey&&(document.activeElement===w||!i.contains(document.activeElement))&&(p.preventDefault(),y.focus())}}function a(p){i.contains(p.target)||(c()[0]||i).focus()}return document.addEventListener("keydown",u,!0),document.addEventListener("focusin",a),()=>{document.removeEventListener("keydown",u,!0),document.removeEventListener("focusin",a),o!=null&&o.isConnected&&o.focus()}},[n,t])}const Se={text:"#111827",muted:"#6B7280",border:"#E5E7EB",accent:"#0A8F6F",accentLight:"rgba(10,143,111,0.09)",page:"#F4F5F7"},lt=()=>[{key:"secteur",label:E.t("rech_contextmodal.quelEstVotreSecteur"),placeholder:E.t("rech_contextmodal.exSaasDeFacturation")},{key:"offre",label:E.t("rech_contextmodal.queVendezVousExactement"),placeholder:E.t("rech_contextmodal.votreOffrePrincipaleEn")},{key:"cible",label:E.t("rech_contextmodal.QuiVousAdressez"),placeholder:E.t("rech_contextmodal.exTpePmeE")},{key:"conversion",label:E.t("rech_contextmodal.quelEstVotrePoint"),placeholder:E.t("rech_contextmodal.exDemandeDeDevis")},{key:"zone",label:E.t("rech_contextmodal.quelleZoneGographique"),placeholder:E.t("rech_contextmodal.exFranceEntireLyon")},{key:"eviter",label:E.t("rech_contextmodal.quelqueChoseviter"),placeholder:E.t("rech_contextmodal.positionnementCeQuIl")},{key:"notes",label:E.t("rech_contextmodal.autresPrcisionsOptionnel"),placeholder:E.t("rech_contextmodal.toutCeQuiPeut")}];function Di(t){const n={},r=[];for(const s of(t||"").split(`
24`)){const i=s.trim();if(!i)continue;const o=lt().find(c=>c.key!=="notes"&&i.startsWith(c.label+" :"));o?n[o.key]=i.slice((o.label+" :").length).trim():r.push(i)}return r.length&&(n.notes=r.join(`
25`)),n}function Gn(t){const n=[];for(const s of lt()){if(s.key==="notes")continue;const i=(t[s.key]||"").trim();i&&n.push(`${s.label} : ${i}`)}const r=(t.notes||"").trim();return r&&n.push(r),n.join(`
26`)}function Pi({open:t,context:n,project:r,description:s,memory:i,onSave:o,onClose:c}){const{t:u}=ee(),a=l.useRef(null),p=l.useId();Bi(a,t,c);const[g,y]=l.useState({}),[w,m]=l.useState(0),[d,h]=l.useState(!1),[j,x]=l.useState("");
26if(l.useEffect(()=>{t&&(y(Di(n)),m(0),x(""))},[t,n]),!t)return null;const z=lt()[w],$=w===lt().length-1;async function T(){h(!0),x("");try{const b=((r==null?void 0:r.description)||(r==null?void 0:r.name)||s||Gn(g)||n||"").trim();if(!b){x(u("rech_contextmodal.dcrivezDAbordVotre"));return}const N=`Produit ou service : "${b}". Propose un contexte projet pour cibler des mots-clés SEO. Réponds UNIQUEMENT avec un objet JSON (aucun texte autour, aucun bloc suggestions, aucun outil) aux clés exactes : secteur, offre, cible, conversion, zone, eviter. Valeurs courtes, concrètes, en français.`,q=(await Wi(N,{project:r,context:n,memory:i})).match(/\{[\s\S]*\}/);if(!q)throw new Error("no-json");const J=JSON.parse(q[0]),ce=["secteur","offre","cible","conversion","zone","eviter"];let G=0;y(je=>{const he={...je};for(const ne of ce)J[ne]!=null&&String(J[ne]).trim()&&(he[ne]=String(J[ne]).trim(),G++);return he}),G||x(u("rech_contextmodal.rponseInexploitableRessayez"))}catch{x(u("rech_contextmodal.lePrremplissageAchou"))}finally{h(!1)}}function L(){o(Gn(g)),c()}return e.jsx("div",{onClick:c,style:{position:"fixed",inset:0,zIndex:200,background:"rgba(17,24,39,0.34)",backdropFilter:"blur(2px)",display:"flex",alignItems:"center",justifyContent:"center",padding:24},children:e.jsxs("div",{ref:a,role:"dialog","aria-modal":"true","aria-labelledby":p,tabIndex:-1,className:"kchat-dialog",onClick:b=>b.stopPropagation(),style:{width:"min(560px, calc(100vw - 48px))",maxHeight:"90vh",overflowY:"auto",background:"#fff",border:`1px solid ${Se.border}`,borderRadius:16,padding:24,boxShadow:"0 24px 60px -18px rgba(17,24,39,0.32)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[e.jsx("div",{id:p,style:{fontSize:20,fontWeight:700,letterSpacing:"-0.01em",color:Se.text},children:u("rech_contextmodal.contexteDuProjet")}),e.jsxs("button",{onClick:T,disabled:d,title:u("rech_contextmodal.proposerDesRponses"),style:{display:"flex",alignItems:"center",gap:6,background:Se.accentLight,color:Se.accent,border:`1px solid ${Se.accent}`,borderRadius:999,padding:"6px 13px",fontSize:12.5,fontWeight:600,cursor:d?"default":"pointer",opacity:d?.7:1,flexShrink:0},children:[e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M18.4 5.6l-2.8 2.8M8.4 15.6l-2.8 2.8"})}),u(d?"rech_contextmodal.gnration":"rech_contextmodal.prremplirAvecLIa")]})]}),j&&e.jsx("div",{role:"alert",style:{marginTop:10,fontSize:12.5,color:Se.accent,background:Se.accentLight,border:`1px solid ${Se.accent}`,borderRadius:10,padding:"8px 12px"},children:j}),e.jsx("div",{style:{display:"flex",alignItems:"center",gap:6,margin:"16px 0 14px"},children:lt().map((b,N)=>e.jsx("span",{style:{height:4,flex:1,borderRadius:999,background:N<=w?Se.accent:Se.border}},b.key))}),e.jsxs("div",{style:{fontSize:12,color:Se.muted,marginBottom:10},children:["Question ",w+1," sur ",lt().length]}),e.jsx("label",{htmlFor:`${p}-answer`,style:{display:"block",fontSize:15.5,fontWeight:600,color:Se.text,marginBottom:10},children:z.label}),e.jsx("textarea",{id:`${p}-answer`,"data-autofocus":!0,value:g[z.key]||"",onChange:b=>y(N=>({...N,[z.key]:b.target.value})),onKeyDown:b=>{b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&($?L():m(N=>N+1))},rows:3,placeholder:z.placeholder,style:{width:"100%",resize:"vertical",background:Se.page,border:`1px solid ${Se.border}`,borderRadius:12,padding:"12px 14px",fontSize:14.5,lineHeight:1.6,color:Se.text,outline:"none",fontFamily:"inherit"}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginTop:18},children:[e.jsx("button",{onClick:w===0?c:()=>m(b=>b-1),style:{background:"transparent",border:"none",color:Se.muted,borderRadius:999,padding:"10px 14px",fontSize:13.5,fontWeight:500,cursor:"pointer"},children:u(w===0?"x_contextmodal.fermer":"rech_contextmodal.prcdent")}),e.jsxs("div",{style:{display:"flex",gap:10},children:[!$&&e.jsx("button",{onClick:L,style:{background:"transparent",border:`1px solid ${Se.border}`,color:Se.text,borderRadius:999,padding:"10px 18px",fontSize:13.5,fontWeight:600,cursor:"pointer"},children:u("x_contextmodal.enregistrer")}),e.jsx("button",{onClick:$?L:()=>m(b=>b+1),style:{background:Se.accent,color:"#fff",border:"none",borderRadius:999,padding:"10px 22px",fontSize:13.5,fontWeight:600,cursor:"pointer"},children:$?u("x_contextmodal.enregistrer"):"Suivant"})]})]})]})})}const _e={text:"#111827",muted:"#6B7280",border:"#E5E7EB",accent:"#0A8F6F",accentLight:"rgba(10,143,111,0.09)"},Ii={color:"var(--text-primary, #111827)"};function Oi({questions:t,initialAnswers:n={},disabled:r=!1,answered:s=!1,onSubmit:i}){const{t:o}=ee(),[c,u]=l.useState(n),[a,p]=l.useState(()=>Object.fromEntries(Object.entries(n).map(([w,m])=>{var d;return[w,!(((d=t[Number(w)])==null?void 0:d.options)||[]).includes(m)]})));if(!t.length)return null;const g=t.every((w,m)=>(c[m]||"").trim()),y=()=>{const w=t.map((m,d)=>`${m.header||"Réponse"} : ${(c[d]||"").trim()||"(non précisé)"}`).join(". ");i(w,c)};return e.jsxs("div",{style:{background:"var(--bg-page2, #F1F2F5)",border:`1px solid ${_e.border}`,borderRadius:16,padding:"28px 28px 24px",margin:"24px 0 0"},children:[e.jsx("div",{style:{fontSize:22,fontWeight:700,letterSpacing:"-0.025em",lineHeight:1.2,...Ii},children:o("kw_cadrage.titre",{count:t.length})}),e.jsx("div",{style:{fontSize:15.5,color:_e.muted,marginTop:8,marginBottom:26,lineHeight:1.65},children:o("kw_cadrage.aide",{count:t.length})}),t.map((w,m)=>e.jsxs("div",{style:{marginBottom:26},children:[w.header&&e.jsx("div",{style:{fontSize:12,color:_e.muted,textTransform:"uppercase",letterSpacing:"0.07em",fontWeight:700,marginBottom:8},children:w.header}),e.jsx("div",{style:{fontSize:17,color:_e.text,fontWeight:500,marginBottom:14,lineHeight:1.6},children:w.question}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:10},children:[(w.options||[]).map(d=>{const h=c[m]===d;return e.jsx("button",{"aria-pressed":h,disabled:r,onClick:()=>{u(j=>({...j,[m]:d})),p(j=>({...j,[m]:!1}))},style:{background:h?_e.accentLight:"var(--bg, #FBFBFC)",border:`1px solid ${h?_e.accent:_e.border}`,color:h?_e.accent:_e.text,borderRadius:10,padding:"11px 18px",fontSize:15,fontWeight:h?600:500,cursor:r?"default":"pointer",opacity:r?.6:1},children:d},d)}),e.jsx("button",{"aria-expanded":!!a[m],disabled:r,onClick:()=>{p(d=>({...d,[m]:!d[m]})),u(d=>({...d,[m]:""}))},style:{background:a[m]?_e.accentLight:"var(--bg, #FBFBFC)",border:`1px solid ${a[m]?_e.accent:_e.border}`,color:a[m]?_e.accent:_e.muted,borderRadius:10,padding:"11px 18px",fontSize:15,fontWeight:500,cursor:r?"default":"pointer",opacity:r?.6:1},children:o("chatUx.other")})]}),a[m]&&e.jsx("input",{"aria-label":w.question,value:c[m]&&!(w.options||[]).includes(c[m])?c[m]:"",onCh
26ange:d=>u(h=>({...h,[m]:d.target.value})),placeholder:o("rech_questionsmodal.votreRponse"),style:{width:"100%",marginTop:12,padding:"12px 14px",borderRadius:10,border:`1px solid ${_e.border}`,fontSize:15.5,color:_e.text,outline:"none",background:"transparent"}})]},m)),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14,flexWrap:"wrap",marginTop:4},children:[e.jsx("button",{onClick:y,disabled:!g||r,style:{background:g&&!r?_e.accent:"#E5E7EB",color:g&&!r?"#fff":"#9CA3AF",border:"none",borderRadius:10,padding:"13px 26px",fontSize:15,fontWeight:600,cursor:g&&!r?"pointer":"default"},children:o(s?"rech_questionsmodal.relancerLaRecherche":"rech_questionsmodal.lancerLaRecherche")}),!g&&e.jsx("span",{style:{fontSize:14,color:_e.muted},children:o("kw_cadrage.reste",{count:t.length})})]})]})}const _t=t=>t.map(n=>n.isStreaming?{...n,isStreaming:!1,interrupted:!0}:n);function Hi(t,n,r){const[s,i]=l.useState(()=>_t(t)),o=l.useRef(s),c=l.useRef(n),u=l.useRef(r);u.current=r;const a=l.useRef(null),p=l.useRef(!0),g=l.useRef(!1),y=l.useCallback(()=>{var m;a.current&&clearTimeout(a.current),a.current=null,g.current&&(g.current=!1,(m=u.current)==null||m.call(u,_t(o.current),c.current))},[]),w=l.useCallback((m,d=!1)=>{p.current&&(o.current=typeof m=="function"?m(o.current):m,i(o.current),g.current=!0,d?y():a.current||(a.current=setTimeout(y,500)))},[y]);return l.useEffect(()=>{p.current=!0;const m=()=>{document.visibilityState==="hidden"&&y()};return window.addEventListener("pagehide",y),window.addEventListener("kw-chat-flush",y),document.addEventListener("visibilitychange",m),()=>{p.current=!1,y(),window.removeEventListener("pagehide",y),window.removeEventListener("kw-chat-flush",y),document.removeEventListener("visibilitychange",m)}},[y]),{messages:s,messagesRef:o,setMessages:w,flush:y}}function zr({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 256 230",xmlns:"http://www.w3.org/2000/svg",style:{flexShrink:0,display:"block"},"aria-hidden":"true",children:[e.jsx("path",{d:"M5.888 166.405 90.88 20.9c10.796 6.356 65.236 36.484 74.028 42.214L79.916 208.627c-9.295 12.28-85.804-23.587-74.028-42.23z",fill:"#FBBC04"}),e.jsx("path",{d:"M250.084 166.402 165.092 20.906C153.21 1.132 127.619-6.054 106.6 5.625 85.582 17.304 79.182 42.462 91.064 63.119l84.992 145.514c11.882 19.765 37.473 26.95 58.491 15.272 20.1-11.679 27.419-37.729 15.537-57.485z",fill:"#4285F4"}),e.jsx("ellipse",{fill:"#34A853",cx:"42.664",cy:"187.924",rx:"42.664",ry:"41.604"})]})}function Rr({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 256 228",xmlns:"http://www.w3.org/2000/svg",style:{flexShrink:0,display:"block"},"aria-hidden":"true",children:[e.jsx("polygon",{fill:"#737373",points:"165.979 0 90.021 0 71.097 19.055 71.097 37.979 90.021 37.979 90.021 19.055 165.979 19.055 165.979 37.979 184.903 37.979 184.903 19.055"}),e.jsx("polygon",{fill:"#BFBFBF",points:"90.021 0 90.021 19.055 165.979 19.055 165.979 0"}),e.jsx("path",{d:"M36.402 37.979 0 74.382V208.559C0 219.072 8.542 227.483 18.924 227.483H237.076C247.589 227.483 256 218.94 256 208.559V74.513L219.466 37.979H36.402Z",fill:"#E6E7E8"}),e.jsx("polygon",{fill:"#FFFFFF",points:"28.517 109.076 227.614 109.076 227.614 227.614 28.517 227.614"}),e.jsx("polygon",{fill:"#E0E0E0",points:"36.402 37.979 0 74.382 0 109.076 256 109.076 256 74.513 219.466 37.979"}),e.jsx("path",{d:"M28.517 86.998C28.517 78.85 35.088 72.279 43.236 72.279H212.764C220.912 72.279 227.483 78.85 227.483 86.998V109.076H28.517V86.998Z",fill:"#4285F4"}),e.jsx("path",{d:"M56.903 90.152C56.903 94.094 53.749 97.248 49.807 97.248 45.864 97.248 42.71 94.094 42.71 90.152 42.71 86.209 45.864 83.055 49.807 83.055 53.749 83.055 56.903 86.209 56.903 90.152M80.559 90.152C80.559 94.094 77.405 97.248 73.462 97.248 69.52 97.248 66.366 94.094 66.366 90.152 66.366 86.209 69.52 83.055 73.462 83.055 77.405 83.055 80.559 86.209 80.559 90.152",fill:"#E6E6E6"}),e.jsx("path",{d:"M208.821 164.008C208.821 147.187 198.965 132.731 184.903 125.766V165.717L166.111 175.836 147.055 165.717V125.634C132.994 132.6 123.4 147.187 123.4 163.877 123.4 180.698 133.125 195.154 147.187 202.119V227.483H185.035V202.119C198.965 195.285 208.821 180.698 208.821 164.008Z",fill:"#4D4D4D"}),e.jsx("polygon",{fill:"#D1D1D1",points:"42.71 123.269 109.076 123.269 109.076 199.097 42.71 199.097"})]})}function Vi(t){const n=t.toLowerCase();return/google ads|\bcpc\b|volume/.test(n)?"ads":/search console|\bgsc\b|position|impression|requête|requetes|requêtes|clics?/.test(n)?"gsc":null}const Ui=`${Pt}/functions/v1/seo-agent`;
26class on extends Error{}function Ji(t){if(t<1e3)return`${Math.max(0,Math.round(t/100)/10).toFixed(1)} s`;const n=t/1e3;if(n<60)return`${n.toFixed(1)} s`;const r=Math.floor(n/60);return`${r} min ${String(Math.round(n-r*60)).padStart(2,"0")}`}function Gi({step:t}){const[,n]=l.useState(0),r=!t.done&&!!t.debut;if(l.useEffect(()=>{if(!r)return;const i=setInterval(()=>n(o=>o+1),100);return()=>clearInterval(i)},[r]),!t.debut)return null;const s=(t.fin??Date.now())-t.debut;return e.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:12,fontVariantNumeric:"tabular-nums",color:"var(--text-muted)",flexShrink:0},children:Ji(s)})}const Qi={search_kb:"Je cherche dans la base de connaissances",get_document:"Je lis un document du projet",gsc_query:"Je lis la Search Console",ga4_query:"Je lis Google Analytics",load_skill:"Je charge la méthode",update_memory:"Je note ce qu'il faut retenir",generate_keywords:"Je cherche les mots-clés du marché",get_keyword_research:"Je relis la recherche précédente",start_keyword_pipeline:"Je lance la recherche de fond",get_keyword_pipeline:"Je relis le plan de pages",start_content_plan:"Je construis le plan éditorial",get_content_plan:"Je relis le plan éditorial",keyword_ideas:"J'élargis la liste de requêtes",keyword_metrics:"Je mesure volume et concurrence",fetch_page:"Je lis la page",internal_links:"Je regarde les liens internes",score_content:"Je note le contenu",get_discoveries:"Je relis les signaux du site",record_decision:"J'enregistre la décision",track_reco:"Je mets la recommandation sous surveillance",add_calendar_items:"J'ajoute au calendrier",deliver_audit:"Je rends l'audit"};function Ki(t){return Qi[t]||"Je travaille"}function Yi({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),e.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function Xi({size:t=13}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})}function Zi({size:t=16}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),e.jsx("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),e.jsx("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}function eo({size:t=13}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"var(--success)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}function Nr({size:t=13}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2.5",strokeLinecap:"round",style:{animation:"kchat-spin 1s linear infinite",flexShrink:0},children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function to({size:t=13}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Qn({steps:t,marginBottom:n=0,muted:r=!1,stopped:s=!1}){const{t:i}=ee(),[o,c]=l.useState({});return e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,marginBottom:n,padding:"14px 16px",background:"var(--bg-page2)",border:"1px solid var(--border)",borderRadius:12},children:t.map((u,a)=>{const p=Vi(u.label);return e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"5px 0",fontSize:14,color:r?"var(--text-muted)":u.done?"var(--text-secondary)":"var(--accent)",fontWeight:u.done?400:500},children:[e.jsx("span",{style:{display:"flex",width:14,justifyContent:"center",flexShrink:0,marginTop:3},children:u.done?e.jsx(eo,{}):s?e.jsx("span",{"aria-label":i("chatUx.interrupted"),children:"–"}):e.jsx(Nr,{})}),e.jsxs("span",{style:{flex:1,minWidth:0,lineHeight:1.5},children:[u.data?e.jsx("button",{onClick:()=>c(g=>({...g,[a]:!g[a]})),"aria-expanded":!!o[a],style:{background:"none",border:"none",padding:0,font:"inherit",color:"inherit",curs
26or:"pointer",textAlign:"left",textDecoration:"underline",textDecorationColor:"var(--border)",textUnderlineOffset:3},children:u.label}):u.label,p&&e.jsx("span",{title:i(p==="ads"?"rech_keywordchat.volumeEtCpcIssus":"rech_keywordchat.positionsEtImpressionsIssues"),style:{display:"inline-flex",alignItems:"center",gap:4,marginLeft:6,verticalAlign:"middle",opacity:r?.55:1},children:p==="ads"?e.jsx(zr,{size:14}):e.jsx(Rr,{size:14})}),u.detail&&e.jsxs("span",{style:{display:"block",fontSize:13,fontWeight:400,color:"var(--text-muted)",marginTop:2,lineHeight:1.5},children:[u.detail,u.data&&e.jsx("span",{style:{marginLeft:6,color:"var(--text-muted)"},children:o[a]?i("chatUx.hideRead"):i("chatUx.showRead")})]}),u.data&&o[a]&&e.jsxs("span",{style:{display:"block",marginTop:10,paddingLeft:0},children:[e.jsx("span",{style:{display:"block",fontSize:12,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--text-muted)",marginBottom:6},children:u.data.titre}),u.data.lignes.map((g,y)=>e.jsx("span",{style:{display:"block",fontSize:13.5,lineHeight:1.6,color:"var(--text-secondary)",padding:"4px 0",borderTop:y?"1px solid var(--border)":"none"},children:g},y))]})]}),e.jsx(Gi,{step:u})]},a)})})}function no(t){const n=t.match(/```questions\s*([\s\S]*?)```/);if(!n)return[];try{const r=JSON.parse(n[1].trim());return Array.isArray(r)?r.filter(s=>s&&s.question):[]}catch{return[]}}function ro({conversationId:t,initialMessages:n,kickoffDescription:r,projectName:s,userName:i,project:o,memory:c,context:u,onMemoryUpdate:a,onSaveContext:p,onToggleSidebar:g,onPersist:y,onLiveMessages:w,onOpenKeywords:m,onOpenView:d,onOpenAgent:h}){var Tt,vt;const[j,x]=l.useState(!1),[z,$]=l.useState(null),T=(o==null?void 0:o.userId)||"";l.useEffect(()=>{if(!T)return;let f=!0;return qe.rpc("peek_quota",{p_user_id:T}).then(({data:D})=>{if(!f||!D)return;
26const O=typeof D=="string"?JSON.parse(D):D;$({limit:typeof O.limit=="number"?O.limit:null,lifetime:O.lifetime===!0}),O.allowed===!1&&x(!0)}).catch(()=>{}),()=>{f=!1}},[T]);const L=z!=null&&z.limit?q(z.lifetime?"chatUx.quotaTitleLifetime":"chatUx.quotaTitleMonthly",{count:z.limit}):q("chatUx.quotaTitleGeneric"),{conn:b}=Tr((o==null?void 0:o.userId)||"",(o==null?void 0:o.domain)||""),[N,W]=l.useState(null),{t:q}=ee(),{messages:J,messagesRef:ce,setMessages:G}=Hi(n,{conversationId:t,projectId:o==null?void 0:o.id},y),je=l.useRef(w);je.current=w,l.useEffect(()=>{var f;(f=je.current)==null||f.call(je,J,{conversationId:t,projectId:o==null?void 0:o.id})},[J,t,o==null?void 0:o.id]);const[he,ne]=l.useState(()=>typeof window<"u"&&window.innerWidth<=900);l.useEffect(()=>{const f=()=>ne(window.innerWidth<=900);return window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[]);const[F,R]=l.useState(""),[H,te]=l.useState(!1),[pe,I]=l.useState(!1),[be,Le]=l.useState(!1),[Fe,ze]=l.useState(""),[M,Y]=l.useState(!1),[k,B]=l.useState({}),se=l.useRef(null),ge=l.useRef(null),oe=l.useRef(null),fe=l.useRef(null),we=l.useRef(!0),De=l.useRef(!1),He=l.useRef(null),Ge=l.useRef(o),Gt=l.useRef(c||{}),Nt=l.useRef(u||"");l.useEffect(()=>{Ge.current=o},[o]),l.useEffect(()=>{Gt.current=c||{}},[c]),l.useEffect(()=>{Nt.current=u||""},[u]);const Re=l.useRef(!0);l.useEffect(()=>(Re.current=!0,()=>{Re.current=!1,queueMicrotask(()=>{var f;Re.current||(f=fe.current)==null||f.abort()})}),[]);const de=l.useCallback((f,D)=>{if(!D)return;const O=Date.now();G(Q=>Q.map(U=>{if(U.id!==f)return U;const ue=(U.steps||[]).map(ae=>ae.done?ae:{...ae,done:!0,fin:ae.fin??O});return ue.push({label:D,done:!1,debut:O}),{...U,steps:ue}}))},[G]),jt=l.useCallback((f,D)=>{D&&G(O=>O.map(Q=>{var ae;if(Q.id!==f||!((ae=Q.steps)!=null&&ae.length))return Q;const U=[...Q.steps],ue=U.length-1;return U[ue]={...U[ue],detail:D},{...Q,steps:U}}))},[G]),bt=l.useCallback((f,D)=>{var O;(O=D==null?void 0:D.lignes)!=null&&O.length&&G(Q=>Q.map(U=>{var xe;if(U.id!==f||!((xe=U.steps)!=null&&xe.length))return U;const ue=[...U.steps],ae=ue.length-1;return ue[ae]={...ue[ae],data:D},{...U,steps:ue}}))},[G]),st=l.useCallback(f=>{const D=Date.now();G(O=>O.map(Q=>Q.id===f?{...Q,steps:(Q.steps||[]).map(U=>U.done?U:{...U,done:!0,fin:U.fin??D})}:Q))},[G]),Et=l.useCallback(async(f,D,O,Q,U)=>{var v;let ue=dt;try{const{data:S}=await qe.auth.getSession();(v=S.session)!=null&&v.access_token&&(ue=S.session.access_token)}catch{}if(Q.aborted)throw new DOMException("Aborted","AbortError");const ae=await fetch(Ui,{method:"POST",headers:{"Content-Type":"application/json",apikey:dt,Authorization:`Bearer ${ue}`},body:JSON.stringify({message:f,user_id:U.userId,domain:U.domain,gscSite:U.gscSite||"",history:U.history,lang:U.lang,...U.agent?{agent:U.agent}:{},kickoff:O}),signal:Q});if(!ae.ok)throw await qr(ae);let xe="",Qe=!1;if(await Cr(ae,S=>{if(Q.aborted)throw new DOMException("Aborted","AbortError");typeof S.tool=="string"?de(D,String(S.reasoning||Ki(String(S.tool)))):typeof S.reasoning=="string"?de(D,S.reasoning):typeof S.thinking=="string"&&de(D,S.thinking),typeof S.stepResult=="string"&&jt(D,S.stepResult),S.stepData&&typeof S.stepData=="object"&&bt(D,S.stepData);const A=ye=>G(Ae=>Ae.map(Te=>Te.id===D?{...Te,...ye}:Te)),V=S.qcm;V!=null&&V.question&&Array.isArray(V.options)&&A({qcm:V});const ie=S.open_view;ie!=null&&ie.view&&A({openView:{view:ie.view,label:ie.label||""}});const me=S.action;me!=null&&me.type&&(me!=null&&me.label)&&A({action:me});const ke=S.suggest_agent;if(ke!=null&&ke.agent&&(ke!=null&&ke.label)&&A({suggestAgent:ke}),S.memory_updated&&(a==null||a()),typeof S.text=="string"&&(xe||st(D),xe+=S.text,G(ye=>ye.map(Ae=>Ae.id===D?{...Ae,content:xe}:Ae))),S.error&&!S.text)throw new Error(String(S.error));S.quota_exceeded&&x(!0),S.done&&(Qe=!0,st(D))}),Q.aborted)throw new DOMException("Aborted","AbortError");if(!xe.trim())throw new on(q("chatUx.emptyResponse"));if(!Qe)throw new on(q("chatUx.truncated"));return st(D),xe},[bt,jt,st,a,de,G,q]),Ee=l.useCallback(async(f,D={})=>{var Qe,v,S;const O=(f??F).trim();if(!O)return;if(fe.current){D.keywordTask&&(He.current=O,R(O),ze("Une action est déjà en cours. Ta nouvelle consigne est prête à envoyer après sa fin."));return}if(j){window.dispatchEvent(new CustomEvent("kw-open-account",{detail:{section:"abonnement"}}));return}R(""),ze(""),oe.current&&(oe.current.style.height="auto");const Q=D.request||{history:D.agent?[]:ce.current.filter(A=>A.content&&!A.isError&&!A.interrupted).slice(-10).map(A=>({role:A.role,content:js(A.content).slice(0,4e3)})),userId:((Qe=Ge.current)==null?void 0:Qe.userId)||"",domain:((v=Ge.current)==null?void 0:v.domain)||"",gscSite:((S=Ge.current)==null?void 0:S.gscSite)||"",lang:Ot(),agent:D.agent},U=D.keywordTask||He.current===O;He.current=null;const ue={id:crypto.randomUUID(),role:"user",content:O,...U?{keywordTask:!0}:{}},ae=crypto.randomUUID();G(A=>[...A,ue,{id:ae,role:"assistant",content:"",isStreaming:!0,kickoff:D.kickoff,request:Q,keywordTaskFor:U?ue.id:D.taskFor}],!0),te(!0);const xe=new AbortController;fe.current=xe;try{await Et(O,ae,!!D.kickoff,xe.signal,Q)}catch(A){if(xe.signal.aborted||A instanceof Error&&A.name==="AbortError")return;const V=A instanceof Ze&&(A.code==="free_quota_exhausted"||A.code==="premium_required"),ie=V||A instanceof Ze&&A.code==="auth_required",me=A instanceof TypeError,ke=me?q("chatUx.networkError"):A instanceof Error?A.message:q("chatUx.unknownError"),ye=ie||me||A instanceof on;V&&x(!0),G(Ae=>Ae.map(Te=>Te.id===ae?{...Te,errorMessage:ye?ke:q("chatUx.failed",{message:ke}),isError:!0,authRequired:A instanceof Ze&&A.code==="auth_required",needsUpgrade:V,isStreaming:!1}:Te))}finally{fe.current===xe&&(fe.current=null,te(!1),G(A=>A.map(V=>V.id===ae?{...V,isStreaming:!1,request:V.isError||V.interrupted?V.request:void 0}:V),!0))}},[F,ce,j,G,Et,q]),Ve=l.useCallback((f,D,O)=>{var U,ue;if(fe.current)return;G(ae=>ae.map(xe=>xe.id===f?{...xe,questionsAnswered:!0,questionAnswers:O}:xe),!0);const Q=(U=ce.current.find(ae=>ae.id===f))==null?void 0:U.keywordTaskFor;Ee(D,{taskFor:Q,request:(ue=ce.current.find(ae=>ae.id===f))==null?void 0:ue.request})},[ce,Ee,G]);l.useEffect(()=>{De.current||n.length>0||!(r!=null&&r.trim())||(De.current=!0,Ee(r.trim(),{kickoff:!0}))},[r,n.length,Ee]),l.useEffect(()=>{const f=D=>{const O=D.detail;O!=null&&O.prompt&&Ee(O.prompt,{keywordTask:O.keywordTask===!0,agent:typeof O.agent=="string"?O.agent:void 0})};return window.addEventListener("kw-chat-prompt",f),()=>window.removeEventListener("kw-chat-prompt",f)},[Ee]);function At(){var f;(f=fe.current)==null||f.abort(),fe.current=null,te(!1),G(D=>D.map(O=>O.isStreaming?{...O,isStreaming:!1,interrupted:!0}:O),!0)}function Qt(){const f=se.current;if(!f)return;const D=f.scrollHeight-f.scrollTop-f.clientHeight<80;we.current=D,Le(!D);const O=f.scrollTop>8;Y(Q=>Q===O?Q:O)}function Kt(f){R(f.target.value),f.target.style.height="auto",f.target.style.height=Math.min(f.target.scrollHeight,160)+"px"}function Yt(f){f.key==="Enter"&&!f.shiftKey&&!f.nativeEvent.isComposing&&(f.preventDefault(),Ee())}function Lt(f){R(f),requestAnimationFrame(()=>{const D=oe.current;D&&(D.focus(),D.style.height="auto",D.style.height=Math.min(D.scrollHeight,160)+"px")})}async function yt(f){try{await navigator.clipboard.writeText(at(f).clean),ze(q("chatUx.copied"))}catch{ze(q("chatUx.copyFailed"))}}function Ft(){var f;we.current=!0,Le(!1),(f=ge.current)==null||f.scrollIntoView({behavior:"auto"})}const it=J.length===0;return e.jsxs("div",{className:"kchat",style:{display:"flex",flexDirection:"column",height:"100%",background:"var(--bg)",minWidth:0},children:[e.jsxs("div",{style:{minHeight:48,flexShrink:0,display:"flex",alignItems:"center",gap:10,padding:"8px 16px",background:"var(--bg-white)",borderBottom:"1px solid var(--border)"},children:[e.jsx("button",{onClick:g,"aria-label":q("rech_keywordchat.barreLatrale"),style:{background:"none",border:"none",color:"var(--text-muted)",padding:4,borderRadius:6,cursor:"pointer",display:"flex"},children:e.jsx(Zi,{size:16})}),s&&e.jsx("span",{className:"kchat-project-name",title:s,style:{fontSize:13,color:"var(--text-secondary)",fontWeight:500,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:s}),!he&&e.jsxs("div",{title:o!=null&&o.gscSite?q("kw_sources.reliee"):q("kw_sources.sansGsc"),style:{display:"flex",alignItems:"center",gap:7,padding:"5px 11px",borderRadius:999,border:"1px solid var(--border)",background:"var(--bg-white)",whiteSpace:"nowrap"},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:5,opacity:o!=null&&o.gscSite?1:.45},children:[e.jsx(Rr,{size:15}),e.jsx(zr,{size:15})]}),e.jsx("span",{style:{fontSize:12,fontWeight:500,color:"var(--text-secondary)"},children:o!=null&&o.gscSite?q("kw_sources.reliee"):q("kw_sources.sansGsc")})]}),e.jsx("div",{style:{marginLeft:"auto",display:"flex",alignItems:"center",gap:8},children:e.jsxs("button",{onClick:()=>I(!0),title:q("rech_keywordchat.contexteDuProjet"),style:{display:"flex",alignItems:"center",gap:7,background:"var(--bg-white)",border:"1px solid var(--border)",borderRadius:999,padding:he?"7px 9px":"6px 13px",fontSize:12.5,fontWeight:500,color:"var(--text-secondary)",cursor:"pointer"},onMouseEnter:f=>{f.currentTarget.style.borderColor="var(--accent)",f.currentTarget.style.color="var(--accent)"},onMouseLeave:f=>{f.currentTarget.style.borderColor="var(--border)",f.currentTarget.style.color="var(--text-secondary)"},children:[e.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:u&&u.trim()?"var(--accent)":"#9CA3AF"}}
26),q("x_keywordchat.contexte")]})})]}),e.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",className:"kchat-sr-only",children:H?q("chatUx.generating"):Fe||((Tt=J[J.length-1])!=null&&Tt.interrupted?q("chatUx.interrupted"):J.length?q("chatUx.ready"):"")}),e.jsx("div",{role:"region","aria-label":q("chatUx.conversation"),ref:se,onScroll:Qt,style:{flex:1,minWidth:0,overflowY:"auto",overflowX:"hidden",padding:"24px 0",maskImage:M?"linear-gradient(to bottom, transparent 0, #000 20px)":void 0,WebkitMaskImage:M?"linear-gradient(to bottom, transparent 0, #000 20px)":void 0},children:it?e.jsxs("div",{style:{maxWidth:900,margin:"0 auto",padding:"8vh 24px 0"},children:[e.jsx("div",{className:"qadence-title-gradient",style:{fontSize:40,fontWeight:700,letterSpacing:"-0.03em",lineHeight:1.15,marginBottom:14,width:"fit-content",maxWidth:"100%"},children:i?q("kw_accueil.titreBienvenue",{prenom:i}):q("kw_accueil.titre")}),e.jsx("div",{style:{fontSize:17,color:"var(--text-secondary)",lineHeight:1.75},children:q("kw_accueil.sousTitre")}),e.jsx("div",{className:"kchat-starters",children:["audit","quickwins","motscles","contenu"].map(f=>e.jsx("button",{onClick:()=>Lt(q(`kw_accueil.amorce_${f}`)),children:q(`kw_accueil.amorceLabel_${f}`)},f))})]}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:56,padding:"0 24px",maxWidth:900,width:"100%",margin:"0 auto"},children:[J.map(f=>{var D;return e.jsx("div",{id:`chat-message-${f.id}`,className:"fade-in",style:{display:"flex",flexDirection:"column",alignItems:f.role==="user"?"flex-end":"flex-start"},children:f.role==="user"?e.jsx("div",{style:{background:"transparent",border:"1px solid var(--border)",color:"var(--text-primary)",padding:"14px 20px",borderRadius:14,fontFamily:"var(--font-content)",fontSize:16.5,lineHeight:1.7,maxWidth:"75%"},children:f.content}):e.jsxs("div",{style:{width:"100%",padding:"2px 0"},children:[e.jsxs("div",{className:"markdown",style:{fontFamily:"var(--font-content)",fontSize:17,lineHeight:1.8,color:"var(--text-primary)"},children:[f.isStreaming&&f.steps&&f.steps.length>0&&e.jsx(Qn,{steps:f.steps,marginBottom:f.content?14:0}),!f.isStreaming&&f.steps&&f.steps.length>0&&e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs("button",{"aria-expanded":!!k[f.id],onClick:()=>B(O=>({...O,[f.id]:!O[f.id]})),style:{display:"flex",alignItems:"center",gap:6,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,padding:"2px 0",cursor:"pointer"},children:[e.jsx("span",{style:{display:"flex",transform:k[f.id]?"none":"rotate(-90deg)",transition:"transform .15s"},children:e.jsx(to,{size:13})}),q("chatUx.steps",{count:f.steps.length})]}),k[f.id]&&e.jsx("div",{style:{marginTop:8},children:e.jsx(Qn,{steps:f.steps,muted:!0,stopped:!!f.interrupted||!!f.isError})})]}),f.content||f.isError?f.isError?f.needsUpgrade?e.jsxs("div",{style:{border:"1px solid var(--border)",borderRadius:10,padding:"14px 16px"},children:[e.jsx("div",{style:{fontSize:14.5,color:"var(--text-primary)",fontWeight:600,marginBottom:6},children:L}),e.jsx("div",{style:{fontSize:13.5,color:"var(--text-secondary)",lineHeight:1.55,marginBottom:12},children:q("chatUx.quotaBody")}),e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:[e.jsx("a",{href:"/tarifs",style:{display:"inline-block",background:"var(--dark)",color:"#fff",textDecoration:"none",borderRadius:9,padding:"10px 18px",fontSize:13.5,fontWeight:600},children:q("chatUx.seePricing")}),e.jsx("button",{onClick:()=>window.dispatchEvent(new CustomEvent("kw-open-account",{detail:{section:"abonnement"}})),style:{background:"none",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:9,padding:"10px 18px",fontSize:13.5,fontWeight:600,cursor:"pointer"},children:q("chatUx.subscription")})]})]}):e.jsxs(e.Fragment,{children:[f.content&&e.jsx(Ct,{remarkPlugins:[It,Jn],components:pn,children:at(f.content).clean}),e.jsxs("div",{role:"alert",className:`kchat-error${f.content?" kchat-error--partial":""}`,children:[e.jsx("p",{className:"kchat-error-title",children:f.errorMessage}),f.content&&e.jsx("p",{className:"kchat-error-hint",children:q("chatUx.partialKept")}),f.authRequired&&e.jsx("a",{href:"/connexion",children:q("chatUx.signIn")})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ct,{remarkPlugins:[It,Jn],components:pn,children:at(f.content).clean}),f.isStreaming&&e.jsx("span",{className:"cursor-blink"})]}):f.isStreaming&&(!f.steps||f.steps.length===0)?e.jsxs("span",{style:{color:"var(--text-muted)",display:"flex",alignItems:"center",gap:6},children:[e.jsx(Nr,{})," ",q("kw_accueil.enCours")]}):null]}),f.interrupted&&e.jsx("p",{role:"status",className:"kchat-interrupted",children:q("chatUx.interrupted")}),!f.isStreaming&&!f.isError&&(()=>{const O=f.qcm?[{question:f.qcm.question,options:f.qcm.options}]:no(f.content);return O.length?e.jsx(Oi,{questions:O,initialAnswers:f.questionAnswers,disabled:H,answered:!!f.questionsAnswered,onSubmit:(Q,U)=>Ve(f.id,Q,U)},f.id):null})(),!f.isStreaming&&(()=>{var U;const O=J.indexOf(f),Q=(U=J.slice(0,O).reverse().find(ue=>ue.role==="user"))==null?void 0:U.content;return e.jsxs("div",{className:"kchat-actions",children:[(f.isError||f.interrupted)&&!f.needsUpgrade&&!f.authRequired&&Q&&e.jsxs(e.Fragment,{children:[e.jsx("button",{disabled:H,onClick:()=>Ee(Q,{kickoff:f.kickoff,request:f.request}),children:q("chatUx.retry")}),e.jsx("button",{disabled:H,onClick:()=>Lt(Q),children:q("chatUx.edit")})]}),!f.isError&&at(f.content).clean&&e.jsx("button",{onClick:()=>yt(f.content),children:q("chatUx.copy")}),!f.isError&&f.content.includes("```keywords")&&m&&e.jsx("button",{onClick:m,children:q("chatUx.openKeywords")}),!f.isError&&f.suggestAgent&&h&&e.jsx("button",{onClick:()=>h({agent:f.suggestAgent.agent,label:f.suggestAgent.label}),children:f.suggestAgent.label}),!f.isError&&f.openView&&d&&e.jsx("button",{onClick:()=>d(f.openView.view),children:f.openView.label||q("chatUx.openView")})]})})(),!f.isStreaming&&!f.isError&&f.action&&e.jsx($r,{action:f.action,connected:!!b,ready:f.action.type==="internal_links"?(((D=f.action.links)==null?void 0:D.length)||0)>0:(f.content||"").length>320,onRun:()=>W(f)}),!f.isStreaming&&!f.isError&&(()=>{const O=at(f.content||"").suggestions;
26return O.length?e.jsx("div",{style:{marginTop:24,display:"flex",flexWrap:"wrap",gap:10},children:O.map((Q,U)=>e.jsx("button",{onClick:()=>!H&&Ee(Q.prompt),disabled:H,title:Q.prompt,style:{background:"transparent",border:"1px solid var(--border)",color:"var(--text-secondary)",borderRadius:10,padding:"10px 18px",fontSize:14,fontWeight:500,cursor:H?"default":"pointer",opacity:H?.6:1},children:Q.label},U))}):null})()]})},f.id)}),e.jsx("div",{ref:ge})]})}),be&&e.jsx("button",{className:"kchat-latest",onClick:Ft,children:q("chatUx.latest")}),j?e.jsx("div",{style:{padding:"12px 24px 20px",background:"var(--bg)",flexShrink:0},children:e.jsxs("div",{style:{maxWidth:900,margin:"0 auto",border:"1px solid var(--border)",borderRadius:16,padding:"18px 20px"},children:[e.jsx("div",{style:{fontSize:15,fontWeight:700,color:"var(--text-primary)",marginBottom:6},children:L}),e.jsx("div",{style:{fontSize:13.5,color:"var(--text-secondary)",lineHeight:1.55,marginBottom:14},children:q("chatUx.quotaBody")}),e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:[e.jsx("a",{href:"/tarifs",style:{display:"inline-block",background:"var(--dark)",color:"#fff",textDecoration:"none",borderRadius:10,padding:"11px 20px",fontSize:14,fontWeight:600},children:q("chatUx.seePricing")}),e.jsx("button",{onClick:()=>window.dispatchEvent(new CustomEvent("kw-open-account",{detail:{section:"abonnement"}})),style:{background:"none",color:"var(--text-primary)",border:"1px solid var(--border)",borderRadius:10,padding:"11px 20px",fontSize:14,fontWeight:600,cursor:"pointer"},children:q("chatUx.subscription")})]})]})}):e.jsxs("div",{style:{padding:"12px 24px 16px",background:"var(--bg)",flexShrink:0},children:[e.jsxs("div",{className:"kchat-composer",style:{maxWidth:900,margin:"0 auto",display:"flex",alignItems:"center",gap:10,background:"var(--glass)",backdropFilter:"var(--blur)",WebkitBackdropFilter:"var(--blur)",border:"1px solid var(--glass-brd)",borderRadius:24,padding:"12px 12px 12px 18px",boxShadow:"var(--shadow-md)"},children:[e.jsx("textarea",{"aria-label":q("chatUx.messageLabel"),"aria-describedby":"kchat-input-help",ref:oe,value:F,onChange:Kt,onKeyDown:Yt,rows:1,placeholder:q(it?"kw_accueil.saisieVide":"kw_accueil.saisieSuite"),style:{flex:1,border:"none",background:"none",resize:"none",outline:"none",fontSize:17,lineHeight:1.7,color:"var(--text-primary)",minHeight:30,maxHeight:180,padding:0,fontFamily:"inherit"}}),H?e.jsx("button",{onClick:At,"aria-label":q("rech_keywordchat.arrter"),style:{width:40,height:40,borderRadius:999,background:"var(--danger-soft)",color:"var(--danger)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"1px solid var(--danger-line)",cursor:"pointer"},children:e.jsx(Xi,{})}):e.jsx("button",{onClick:()=>Ee(),disabled:!F.trim(),"aria-label":q("chatUx.send"),style:{width:40,height:40,borderRadius:999,background:F.trim()?"var(--dark)":"var(--bg-hover)",color:F.trim()?"#fff":"var(--text-muted)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,border:"none",cursor:F.trim()?"pointer":"default"},children:e.jsx(Yi,{})})]}),e.jsx("div",{id:"kchat-input-help",style:{textAlign:"center",fontSize:11,color:"var(--text-muted)",marginTop:8},children:q("chatUx.inputHelp")})]}),e.jsx(Pi,{open:pe,context:u||"",project:o,description:r,memory:c,onSave:f=>p==null?void 0:p(f),onClose:()=>I(!1)}),((vt=N==null?void 0:N.action)==null?void 0:vt.type)==="internal_links"&&e.jsx(Wr,{userId:(o==null?void 0:o.userId)||"",domain:(o==null?void 0:o.domain)||"",links:N.action.links,onClose:()=>W(null)}),(N==null?void 0:N.action)&&N.action.type!=="internal_links"&&e.jsx(Mr,{userId:(o==null?void 0:o.userId)||"",domain:(o==null?void 0:o.domain)||"",initialContent:N.content,onClose:()=>W(null)})]})}function bn(t){return(t||"").replace(/^sc-domain:/,"").replace(/^https?:\/\//,"").replace(/\/$/,"").replace(/^www\./,"").toLowerCase()}function Er(t,n){const r=bn(n);if(!r)return 0;const s=t.startsWith("sc-domain:"),i=bn(t);return i===r?100+(s?10:t.startsWith("https")?5:0):r.endsWith("."+i)?s?70:40:i.endsWith("."+r)?30:0}function so(t,n){let r=null;for(const s of t||[]){const i=Er(s,n);i>0&&(!r||i>r.score)&&(r={site:s,score:i})}return r}function an(t){return bn(t)}function ln(t){return(t||"").trim().replace(/^https?:\/\//,"").replace(/^www\./,"").replace(/\/.*$/,"").toLowerCase()}const K={text:"#111827",muted:"#6B7280",border:"#E5E7EB",borderLight:"#F1F2F4",accent:"#0A8F6F",page:"#F4F5F7",dar
26k:"#111827",ok:"#15803D",warn:"#B45309"};function io({open:t,onCreate:n,onClose:r}){const{t:s}=ee(),[i,o]=l.useState(""),[c,u]=l.useState(""),[a,p]=l.useState(""),[g,y]=l.useState(!1),[w,m]=l.useState([]),[d,h]=l.useState(!1),[j,x]=l.useState(!1),[z,$]=l.useState(!1),[T,L]=l.useState(!1),b=l.useRef(null);async function N(){h(!0);try{const{data:F}=await qe.from("google_connections").select("gsc_site"),R=F||[];x(R.length>0),m(Array.from(new Set(R.map(H=>H.gsc_site).filter(H=>!!H))))}finally{h(!1)}}l.useEffect(()=>{t&&(o(""),u(""),p(""),y(!1),$(!1),L(!1),setTimeout(()=>{var F;return(F=b.current)==null?void 0:F.focus()},30),N())},[t]);const W=l.useMemo(()=>ln(c||i),[c,i]),q=/\.[a-z]{2,}$/i.test(W);if(l.useEffect(()=>{if(g||!q)return;const F=so(w,W);p(F?F.site:"")},[W,q,w,g]),!t)return null;const J=j&&w.length>0,ce=!!a,G=j&&!d&&w.length===0;async function je(){const{data:{user:F}}=await qe.auth.getUser();if(!F){window.location.href="/app2";return}const{data:R}=await qe.functions.invoke("google-auth",{body:{user_id:F.id,return_url:window.location.origin+"/app2"}}),H=R==null?void 0:R.url;H&&(window.location.href=H)}function he(){const F=ln(c)||an(a)||ln(i),R=i.trim()||F;if(!R||!F){L(!0);return}const H=a&&Er(a,F)>=40?a:"";n({name:R,domain:F,gsc_property:H}),r()}const ne=e.jsxs("select",{value:a,onChange:F=>{p(F.target.value),y(!0),L(!1)},style:{width:"100%",marginTop:8,padding:"11px 13px",borderRadius:10,border:`1px solid ${K.border}`,background:"#fff",color:a?K.text:K.muted,fontSize:14,fontFamily:"inherit"},children:[e.jsx("option",{value:"",children:s("rech_newproject.aucunePropriete")}),w.map(F=>e.jsx("option",{value:F,children:an(F)},F))]});return e.jsx("div",{onClick:r,style:{position:"fixed",inset:0,zIndex:200,background:"rgba(17,24,39,0.34)",backdropFilter:"blur(2px)",display:"flex",alignItems:"center",justifyContent:"center",padding:24},children:e.jsxs("div",{onClick:F=>F.stopPropagation(),style:{width:"min(460px, calc(100vw - 48px))",background:"#fff",border:`1px solid ${K.border}`,borderRadius:16,padding:24,boxShadow:"0 24px 60px -18px rgba(17,24,39,0.32)"},children:[e.jsx("div",{style:{fontSize:19,fontWeight:700,letterSpacing:"-0.015em",color:K.text},children:s("rech_newproject.titre")}),e.jsx("div",{style:{fontSize:13.5,color:K.muted,marginTop:4,marginBottom:18,lineHeight:1.5},children:s("rech_newproject.sousTitre")}),e.jsx("input",{ref:b,value:i,onChange:F=>{o(F.target.value),L(!1)},onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),he())},placeholder:s("rech_newproject.nomPlaceholder"),style:{width:"100%",padding:"0 2px 11px",border:"none",background:"none",color:K.text,fontFamily:"inherit",fontSize:24,fontWeight:600,letterSpacing:"-0.028em",outline:"none",caretColor:K.accent}}),e.jsx("div",{style:{height:2,background:K.border,borderRadius:2,overflow:"hidden",marginBottom:4},children:e.jsx("div",{style:{height:"100%",width:i.trim()?"100%":0,background:K.accent,transition:"width .34s cubic-bezier(.2,.8,.2,1)"}})}),e.jsx("input",{value:c,onChange:F=>{u(F.target.value),y(!1),L(!1)},onKeyDown:F=>{F.key==="Enter"&&(F.preventDefault(),he())},placeholder:s("rech_newproject.domainePlaceholder"),style:{width:"100%",padding:"10px 2px",border:"none",background:"none",color:K.text,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",fontSize:13.5,outline:"none",caretColor:K.accent}}),e.jsx("div",{style:{height:1,background:K.borderLight,marginBottom:14}}),j&&d&&w.length===0&&e.jsx("div",{style:{fontSize:12.5,color:K.muted,marginBottom:12},children:s("rech_newproject.chargementProprietes")}),J&&ce&&e.jsxs("div",{style:{marginBottom:14},children:[e.jsxs("div",{style:{fontSize:12.5,color:K.ok,fontWeight:600,display:"flex",alignItems:"center",gap:6},children:["● ",s("rech_newproject.reliee",{domaine:an(a)})]}),e.jsx("button",{onClick:()=>$(F=>!F),style:{marginTop:8,padding:0,background:"none",border:"none",color:K.accent,fontSize:12.5,fontWeight:600,textDecoration:"underline",textUnderlineOffset:3,cursor:"pointer"},children:s(z?"rech_newproject.masquer":"rech_newproject.choisirAutre")}),z&&ne]}),J&&!ce&&!q&&e.jsx("div",{style:{marginBottom:14,fontSize:12.5,color:K.muted,lineHeight:1.5},children:s("rech_newproject.enAttenteDomaine")}),J&&!ce&&q&&e.jsxs("div",{style:{marginBottom:14,border:`1px solid ${K.border}`,background:K.page,borderRadius:10,padding:"12px 13px"},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:650,color:K.warn,marginBottom:4},children:s("rech_newproject.aucuneCorrespondTitre")}),e.jsx("div",{style:{fontSize:12,color:K.muted,lineHeight:1.5,marginBottom:9},children:s("rech_newproject.aucuneCorrespondTexte",{domaine:W})}),ne]}),G&&e.jsxs("div",{style:{marginBottom:14,border:`1px solid ${K.border}`,background:K.page,borderRadius:10,padding:"12px 13px"},children:[e.jsx("div",{style:{fontSize:12.5,fontWeight:650,color:K.warn,marginBottom:4},children:s("rech_newproject.aucuneVerifieeTitre")}),e.jsx("div",{style:{fontSize:12,color:K.muted,lineHeight:1.5,marginBottom:10},children:s("rech_newproject.aucuneVerifieeTexte")}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("a",{href:"https://search.google.com/search-console",target:"_blank",rel:"noopener noreferrer",style:{flex:1,textAlign:"center",padding:"9px 12px",borderRadius:9,background:K.dark,color:"#fff",fontSize:12.5,fontWeight:600,textDecoration:"none"},children:s("rech_newproject.ouvrirSearchConsole")}),e.jsx("button",{onClick:()=>void N(),style:{padding:"9px 14px",borderRadius:9,background:"#fff",color:K.muted,fontSize:12.5,fontWeight:600,border:`1px solid ${K.border}`,cursor:"pointer"},children:s("rech_newproject.recharger")})]})]}),!j&&!d&&e.jsxs("div",{style:{marginBottom:14,border:`1px solid ${K.border}`,background:K.page,borderRadius:10,padding:"12px 13px"},children:[e.jsx("div",{style:{fontSize:12.5,color:K.muted,lineHeight:1.5,marginBottom:8},children:s("rech_newproject.relierGoogleTexte")}),e.jsx("button",{onClick:()=>void je(),style:{padding:"9px 14px",borderRadius:9,background:"#fff",color:K.text,fontSize:12.5,fontWeight:600,border:`1px solid ${K.border}`,cursor:"pointer"},children:s("rech_newproject.relierGoogleBouton")})]}),T&&e.jsx("div",{style:{marginBottom:12,fontSize:12.5,color:K.accent,lineHeight:1.5},children:s("rech_newproject.erreurDomaine")}),e.jsxs("div",{style:{display:"flex",gap:10,marginTop:6},children:[e.jsx("button",{onClick:he,style:ce?{flex:1,padding:11,borderRadius:999,background:K.accent,color:"#fff",fontSize:14,fontWeight:600,border:"none",cursor:"pointer"}:{flex:1,padding:11,borderRadius:999,background:"#fff",color:K.muted,fontSize:13.5,fontWeight:600,border:`1px solid ${K.border}`,cursor:"pointer"},children:s(ce?"rech_newproject.ajouter":"rech_newproject.creerSansGsc")}),e.jsx("button",{onClick:r,style:{padding:"11px 18px",borderRadius:999,background:"transparent",color:K.muted,fontSize:14,fontWeight:500,border:"1px solid transparent",curs
26or:"pointer"},children:s("x_newsearchmodal.annuler")})]})]})})}const Kn={display:"flex",alignItems:"center",gap:12,textAlign:"left",width:"100%",background:"var(--bg-white, #fff)",border:"1px solid var(--border, #E5E7EB)",borderRadius:12,padding:"16px 18px",cursor:"pointer",color:"inherit"};function oo({projects:t,activeId:n,onOpen:r,onNew:s,onClose:i}){const{t:o}=ee();return e.jsxs("div",{style:{position:"relative",flex:1,minWidth:0,height:"100%",background:"var(--bg-white, #fff)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"10px 20px",borderBottom:"1px solid var(--border-light, #EEF0F3)",fontSize:12.5,color:"var(--text-muted, #6B7280)",flexShrink:0},children:[e.jsxs("button",{onClick:i,style:{display:"flex",alignItems:"center",gap:6,background:"none",border:"1px solid var(--border, #E5E7EB)",borderRadius:7,padding:"5px 10px",color:"var(--text-secondary, #374151)",fontSize:12.5,cursor:"pointer"},children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Chat"]}),e.jsx("span",{style:{color:"var(--text-primary, #111827)",fontWeight:600},children:o("rech_sidebar.tousMesProjets")}),e.jsx("span",{style:{flex:1}})]}),e.jsx("div",{style:{flex:1,overflowY:"auto"},children:e.jsxs("div",{style:{maxWidth:880,margin:"0 auto",padding:"32px 24px 70px"},children:[e.jsx("h3",{style:{margin:"0 0 4px",fontSize:17,color:"var(--text-primary, #111827)"},children:o("rech_sidebar.tousMesProjets")}),e.jsxs("p",{style:{margin:"0 0 20px",fontSize:13,color:"var(--text-muted, #6B7280)"},children:[t.length," projet",t.length>1?"s":""]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(250px, 1fr))",gap:12},children:[t.map(c=>{const u=c.domain||c.id,a=u===n;return e.jsxs("button",{onClick:()=>r(u),style:{...Kn,borderColor:a?"var(--accent, #2456F5)":"var(--border, #E5E7EB)"},children:[e.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:34,height:34,flex:"none",borderRadius:9,background:"var(--bg, #F4F5F7)",color:"var(--text-secondary, #374151)"},children:e.jsx(nr,{size:17})}),e.jsxs("span",{style:{flex:1,minWidth:0},children:[e.jsx("strong",{style:{display:"block",fontSize:14,color:"var(--text-primary, #111827)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.domain||c.name}),e.jsx("small",{style:{fontSize:12,color:"var(--text-muted, #6B7280)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block"},children:a?o("rech_sidebar.siteActif"):c.name&&c.name!==c.domain?c.name:" "})]}),e.jsx(tr,{size:15})]},c.id)}),e.jsxs("button",{onClick:s,style:{...Kn,borderStyle:"dashed",color:"var(--text-secondary, #374151)",justifyContent:"center",minHeight:68},children:[e.jsx(ot,{size:16})," ",o("rech_sidebar.nouveauProjet")]})]})]})})]})}function ao(){const[t,n]=l.useState(null),[r,s]=l.useState(!0);return l.useEffect(()=>{let i=!0;qe.auth.getSession().then(({data:c})=>{var u;i&&(n(((u=c.session)==null?void 0:u.user)||null),s(!1))}).catch(()=>{i&&s(!1)});const{data:o}=qe.auth.onAuthStateChange((c,u)=>{i&&(n((u==null?void 0:u.user)||null),s(!1))});return()=>{i=!1,o.subscription.unsubscribe()}},[]),{user:t,loading:r}}function qt(t){return String(t||"").replace(/^sc-domain:/,"").replace(/^https?:\/\//,"").replace(/\/$/,"").replace(/^www\./,"").toLowerCase()}function lo(t,n){const r=qt(t),s=qt(n);return!r||!s?!1:r===s||s.endsWith("."+r)||r.endsWith("."+s)}async function nt(t){try{const n=await fetch(`${tt}/${t}`,{headers:await rt()});return n.ok?await n.json():null}catch{return null}}async function cn(t){const n=await nt(`projects?user_id=eq.${t}&select=name,domain,gsc_site,created_at&order=created_at.asc`);if(!Array.isArray(n))return[];const r=new Map;for(const s of n){const i=qt(s.domain);if(!i)continue;const o=lo(s.gsc_site,i)?s.gsc_site:"",c=r.get(i);c&&c.gsc_site&&!o||r.set(i,{domain:i,name:s.name||i,gsc_site:o,created_at:s.created_at})}return[...r.values()]}async function co(t,n){const r=qt(n.domain);r&&await fetch(`${tt}/projects`,{method:"POST",headers:{...pt,...await rt(),Prefer:"return=minimal"},body:JSON.stringify({user_id:t,name:n.name||r,domain:r,gsc_site:n.gsc_site||null})}).catch(()=>{})}async function uo(t,n,r){await fetch(`${tt}/projects?user_id=eq.${t}&domain=eq.${encodeURIComponent(n)}`,{method:"PATCH",headers:{...pt,...await rt(),Prefer:"return=minimal"},body:JSON.stringify({gsc_site:r||null,updated_at:new Date().toISOString()})}).catch(()=>{})}async function ho(t,n){await fetch(`${tt}/projects?user_id=eq.${t}&domain=eq.${encodeURIComponent(n)}`,{method:"DELETE",headers:{...pt,...await rt(),Prefer:"return=minimal"}}
26).catch(()=>{})}async function po(t,n,r=40){const s=await nt(`conversations?user_id=eq.${t}&domain=eq.${encodeURIComponent(n)}&select=id,title,message_count,updated_at,pinned&order=pinned.desc.nullslast,updated_at.desc&limit=${r}`);return Array.isArray(s)?s.map(i=>({id:i.id,title:i.title||"",updatedAt:new Date(i.updated_at).getTime()||Date.now(),pinned:!!i.pinned,messageCount:i.message_count||0})):[]}async function xo(t){var c;const[n,r]=await Promise.all([nt(`conversation_messages?conversation_id=eq.${t}&select=seq,payload&order=seq.asc`),nt(`conversations?id=eq.${t}&select=messages`)]),s=(Array.isArray(r)&&Array.isArray((c=r[0])==null?void 0:c.messages)?r[0].messages:[]).filter(Boolean),i=new Map;for(const u of Array.isArray(n)?n:[]){const a=u.payload,p=a&&typeof a.id=="string"?a.id:"";a&&p&&i.set(p,a)}const o=[...i.values()];if(o.length>s.length){const u=new Set(s.map(p=>String(p.id||"")));return[...o.filter(p=>!u.has(String(p.id||""))),...s]}return s.length?s:o}async function go(t,n,r=40){const s=await nt(`conversations?user_id=eq.${t}&domain=eq.${encodeURIComponent(n)}&select=messages&order=updated_at.desc&limit=${r}`);return Array.isArray(s)?s.flatMap(i=>Array.isArray(i.messages)?i.messages:[]).filter(Boolean):[]}async function fo(t,n,r,s,i={}){const o=Or(s);if(!t||!n||!r||!o.length)return;const c={...pt,...await rt()},u=o.find(g=>g.role==="user"),a={id:r,user_id:t,domain:n,messages:o.slice(-50),message_count:o.length,updated_at:new Date().toISOString()};!i.distilled&&u&&(a.title=u.content.slice(0,70));const p=o.map((g,y)=>({conversation_id:r,msg_id:g.id,user_id:t,domain:n,seq:y,role:g.role,content:String(g.content||"").slice(0,1e5),payload:g}));await Promise.all([fetch(`${tt}/conversations`,{method:"POST",headers:{...c,Prefer:"resolution=merge-duplicates,return=minimal"},body:JSON.stringify(a),keepalive:!0}).catch(()=>{}),fetch(`${tt}/conversation_messages`,{method:"POST",headers:{...c,Prefer:"resolution=merge-duplicates,return=minimal"},body:JSON.stringify(p),keepalive:!0}).catch(()=>{})])}const mo=new Set(["audit_technique","veilleur_alerts","resultats_actions"]),jo=["analyse:","decision:","explained:"];function bo(t){const n=String(t||"");return mo.has(n)||jo.some(r=>n.startsWith(r))}async function Yn(t,n){const r=await nt(`project_memory?user_id=eq.${t}&domain=eq.${encodeURIComponent(n)}&select=key,value&limit=200`),s={};for(const i of r||[])bo(i.key)||(s[i.key]=i.value);return s}async function yo(t,n,r,s){await fetch(`${tt}/project_memory`,{method:"POST",headers:{...pt,...await rt(),Prefer:"resolution=merge-duplicates,return=minimal"},body:JSON.stringify({user_id:t,domain:n,key:r,value:s,updated_at:new Date().toISOString()})}).catch(()=>{})}async function vo(t,n){const r=await nt(`project_context?user_id=eq.${t}&domain=eq.${encodeURIComponent(n)}&select=fields,summary,site_fiche,site_fiche_at`),s=Array.isArray(r)?r[0]:null;return{fields:(s==null?void 0:s.fields)||null,summary:(s==null?void 0:s.summary)||"",site_fiche:s!=null&&s.site_fiche&&Object.keys(s.site_fiche).length?s.site_fiche:null,site_fiche_at:(s==null?void 0:s.site_fiche_at)||null}}function wo(t,n=""){if(!t.length)return null;const r=n?t.find(s=>s.id===n):void 0;return r||t.reduce((s,i)=>i.updatedAt>s.updatedAt?i:s)}const ko=l.lazy(()=>Fr(()=>import("./BriefingBubble-DLRue185.js"),__vite__mapDeps([0,1,2]))),Xn="qadence_kw_last_domain",Zn=t=>`qadence_kw_view_${t}`,dn=t=>`qadence_kw_conversation_${t}`;function Dt(t){try{return localStorage.getItem(t)||""}catch{return""}}function kt(t,n){try{localStorage.setItem(t,n)}catch{}}function So(){return Dt("qadence_briefing_seen")===new Date().toISOString().split("T")[0]}function _o(){kt("qadence_briefing_seen",new Date().toISOString().split("T")[0])}function Co(){try{const t=(sessionStorage.getItem("qadence_kw_pending")||"").trim();return t&&sessionStorage.removeItem("qadence_kw_pending"),t}catch{return""}}function qo(t){return{id:t.domain,name:t.name||t.domain,domain:t.domain,gsc_property:t.gsc_site}}function $o(){const{t}=ee(),{user:n,loading:r}=ao(),s=(n==null?void 0:n.id)||"",i=!!n&&n.is_anonymous!==!0&&!!n.email,[o,c]=l.useState([]),[u,a]=l.useState(""),[p,g]=l.useState([]),[y,w]=l.useState(""),[m,d]=l.useState([]),[h,j]=l.useState([]),[x,z]=l.useState([]),[$,T]=l.useState("chat"),[L,b]=l.useState(!0),[N,W]=l.useState(!1),[q,J]=l.useState(!1),[ce,G]=l.useState(!1),[je,he]=l.useState(void 0),[ne,F]=l.useState({}),[R,H]=l.useState({fields:null,summary:"",site_fiche:null,site_fiche_at:null}),[te,pe]=l.useState(!1),[I,be]=l.useState(null),[Le,Fe]=l.useState([]),[ze,M]=l.useState(!1),[Y,k]=l.useState(null),[B,se]=l.useState(()=>typeof window<"u"&&window.innerWidth<=900),[ge,oe]=l.useState([]),[fe,we]=l.useState(null),[De,He]=l.useState(null),[Ge,Gt]=l.useState({}),Nt=l.useRef(!1),Re=l.useRef(""),de=l.useMemo(()=>o.find(v=>v.domain===u)||null,[o,u]),jt=l.useMemo(()=>o.map(qo),[o]),bt=l.useMemo(()=>(Ge.name||"").trim().split(/\s+/)[0]||"",[Ge.name]),st=l.useMemo(()=>{const v=new Map;for(const S of x)S!=null&&S.id&&v.set(S.id,S);for(const S of h)S!=null&&S.id&&v.set(S.id,S);return[...v.values()]},[x,h]);l.useEffect(()=>{const v=()=>{const S=window.innerWidth<=900;se(S),S&&b(!1)};return v(),window.addEventListener("resize",v),()=>window.removeEventListener("resize",v)},[]);function Et(v){oe(S=>{const A=S.find(ie=>ie.agent===v.agent);if(A)return we(A.id),S;const V=`${v.agent}-${S.length}-${Math.random().toString(36).slice(2,7)}`;return we(V),[...S,{id:V,agent:v.agent,label:v.label,seed:v.input||v.seed||null}]})}function Ee(v){oe(S=>{const A=S.filter(V=>V.id!==v);return we(V=>{var ie;return V===v?((ie=A[A.length-1])==null?void 0:ie.id)??null:V}
26),A})}l.useEffect(()=>{if(!s)return;let v=!1;const S=setTimeout(()=>{(async()=>{try{const A=await fetch(`${er}/daily-briefing`,{method:"POST",headers:await rt(),body:"{}"});if(!A.ok)return;const V=await A.json();!v&&(V!=null&&V.hasContent)&&He(V)}catch{}})()},1200);return()=>{v=!0,clearTimeout(S)}},[s]),l.useEffect(()=>{var S,A;const v=((S=n==null?void 0:n.user_metadata)==null?void 0:S.full_name)||((A=n==null?void 0:n.user_metadata)==null?void 0:A.name)||"";v&&Gt({name:v})},[n]),l.useEffect(()=>{!i||!s||Nt.current||(Nt.current=!0,(async()=>{const v=await cn(s);c(v);const S=Dt(Xn),A=v.find(ie=>ie.domain===S)||v[0];A?Ve(A.domain,v):G(!0);const V=Co();V&&A&&he(V)})())},[i,s]);const Ve=l.useCallback(async(v,S)=>{if(!(S||o).some(Ae=>Ae.domain===v))return;Re.current=v,a(v),kt(Xn,v),T(In(Dt(Zn(v))||"chat")),J(!1),g([]),d([]),j([]),z([]),F({}),H({fields:null,summary:"",site_fiche:null,site_fiche_at:null}),Fe([]),k(null),he(void 0),B&&b(!1);const[V,ie,me,ke]=await Promise.all([po(s,v),Yn(s,v),vo(s,v),go(s,v)]);if(Re.current!==v)return;g(V),F(ie),H(me),z(_t(ke));const ye=wo(V,Dt(dn(v)));ye?At(ye.id,v):w(crypto.randomUUID())},[o,s,B]),At=l.useCallback(async(v,S=Re.current)=>{T("chat"),W(!1),J(!1),B&&b(!1);const A=await xo(v);Re.current===S&&(d(_t(A)),j(_t(A)),w(v),kt(dn(S),v))},[B]);function Qt(){w(crypto.randomUUID()),d([]),j([]),he(void 0),T("chat"),W(!1),J(!1),B&&b(!1)}async function Kt(v){const S=qt(v.domain);if(!S||!s)return;await co(s,{name:v.name,domain:S,gsc_site:v.gsc_property});const A=await cn(s);c(A),await Ve(S,A),T("fiche"),yt(S)}async function Yt(v){if(!window.confirm(t("rech_recherche.supprimerCeProjetEt")))return;await ho(s,v);const S=await cn(s);c(S),v===u&&(S[0]?await Ve(S[0].domain,S):(a(""),g([]),d([])))}async function Lt(v){u&&(await uo(s,u,v),c(S=>S.map(A=>A.domain===u?{...A,gsc_site:v}:A)),Fe([]),k(null))}const yt=l.useCallback(async(v=Re.current)=>{var S;if(!(!v||te)){pe(!0),be(null);try{const{data:A}=await qe.auth.getSession(),V=(S=A.session)==null?void 0:S.access_token;if(!V){be(t("x_recherche.sessionExpireReconnectezVous"));return}const ie=await fetch(`${Pt}/functions/v1/fiche-site`,{method:"POST",headers:{"Content-Type":"application/json",apikey:dt,Authorization:`Bearer ${V}`},body:JSON.stringify({domain:v,lang:Ot()})}),me=await ie.json();if(!ie.ok||!me.success){be(String(me.error||t("rech_fiche.echec")));return}if(Re.current!==v)return;H(ke=>({...ke,site_fiche:me.fiche,site_fiche_at:me.fiche_le||new Date().toISOString()}))}catch{be(t("rech_fiche.echec"))}finally{pe(!1)}}},[te,t]);l.useEffect(()=>{$==="fiche"&&u&&!R.site_fiche&&!te&&yt(u)},[$,u,R.site_fiche]);const Ft=l.useCallback(async v=>{var V,ie,me,ke;const S=Re.current,A=(V=o.find(ye=>ye.domain===S))==null?void 0:V.gsc_site;if(!(!S||!A||ze)){M(!0),k(null);try{const{data:ye}=await qe.auth.getSession(),Ae=(ie=ye.session)==null?void 0:ie.access_token;if(!Ae){k(t("x_recherche.sessionExpireReconnectezVous"));return}const Te=await fetch(`${Pt}/functions/v1/import-gsc-keywords`,{method:"POST",headers:{"Content-Type":"application/json",apikey:dt,Authorization:`Bearer ${Ae}`},body:JSON.stringify({domain:S,days:v,property:A})}),$t=await Te.json();if(!Te.ok||!$t.success){k($t.error||t("rech_recherche.lesRequtesNOnt"));return}if(Re.current!==S)return;Fe(((me=$t.data)==null?void 0:me.rows)||[]),(ke=$t.data)!=null&&ke.plafond_atteint&&k(t("kw_gsc.plafond"))}catch{k(t("rech_recherche.lesRequtesNOnt2"))}finally{M(!1)}}},[o,ze,t]);l.useEffect(()=>{$==="gsc"&&(de!=null&&de.gsc_site)&&!Le.length&&!ze&&Ft(28)},[$,de==null?void 0:de.gsc_site]);const it=l.useRef(null),Tt=l.useCallback(v=>{const S=Re.current;!s||!S||!y||!v.length||(kt(dn(S),y),it.current&&clearTimeout(it.current),it.current=setTimeout(()=>{fo(s,S,y,v),g(A=>{var ke;const V=((ke=v.find(ye=>ye.role==="user"))==null?void 0:ke.content.slice(0,70))||"",ie=A.some(ye=>ye.id===y),me={id:y,title:V,updatedAt:Date.now()};return ie?A.map(ye=>ye.id===y?{...ye,title:ye.title||V,updatedAt:Date.now()}:ye):[me,...A]})},700))},[s,y]);function vt(v,S=!1,A=!1,V){A||(T("chat"),W(!1),J(!1)),setTimeout(()=>window.dispatchEvent(new CustomEvent("kw-chat-prompt",{detail:{prompt:v,keywordTask:S,agent:V}})),0)}function f(v){const S=In(v);T(S),W(!1),J(!1),u&&kt(Zn(u),S)}const[D,O]=l.useState("dashboard");l.useEffect(()=>{const v=S=>{var V;const A=(V=S.detail)==null?void 0:V.section;O(typeof A=="string"?A:"dashboard"),W(!0)};return window.addEventListener("kw-open-account",v),()=>window.removeEventListener("kw-open-account",v)},[]);function Q(v){T("briefs");const S=`Produis uniquement le brief éditorial complet pour le mot-clé « ${v} ». Ne traite aucune autre demande et n’analyse pas les autres requêtes du fil. ${t("kw_brief.prompt",{keyword:v})}`;vt(S,!1,!0,"carmin")}const U=l.useMemo(()=>{const v=t("kw_brief.prompt",{keyword:"{{keyword}}"}),S=Pn(h,v),A=Pn(x,v,!1),V=new Set(S.map(ie=>ie.id));return[...S,...A.filter(ie=>!V.has(ie.id))]},[h,x,t]),ue=l.useRef({});for(const v of U)v.pending&&!ue.current[v.id]&&(ue.current[v.id]=Date.now());const ae=l.useMemo(()=>
26U.map(v=>ue.current[v.id]?{...v,createdAt:ue.current[v.id]}:v),[U]);if(r)return e.jsx("div",{style:{position:"fixed",inset:0,background:"var(--bg, #FAFAFC)"}});if(!i)return e.jsx(Br,{userId:s||null,authed:!!n,onConnected:()=>window.location.reload()});const xe=(de==null?void 0:de.gsc_site)||"",Qe={userId:s,domain:u,gscSite:xe};return e.jsxs("div",{style:{position:"fixed",inset:0,display:"flex",background:"var(--bg, #FAFAFC)"},children:[B&&L&&e.jsx("div",{onClick:()=>b(!1),style:{position:"fixed",inset:0,zIndex:190,background:"var(--scrim, rgba(17,24,39,.32))"}}),e.jsx("div",{style:B?{position:"fixed",top:0,bottom:0,left:0,zIndex:200,transform:L?"translateX(0)":"none",transition:"transform .25s cubic-bezier(.2,.8,.2,1)",display:"flex"}:{display:"flex",height:"100%"},children:e.jsx(Ti,{collapsed:B?!1:!L,onToggleCollapse:()=>b(v=>!v),projects:jt,activeProjectId:u,onSetProject:v=>void Ve(v),onNewProject:()=>G(!0),onNewConversation:Qt,onDeleteProject:v=>void Yt(v),activeView:$,onSelectView:f,history:p,activeConvId:y,onLoadConv:v=>void At(v),onOpenAccount:()=>{O("dashboard"),W(!0),J(!1)},onOpenOverview:()=>{J(!0),W(!1)},overviewActive:q})}),e.jsxs("div",{style:{flex:1,minWidth:0,position:"relative"},children:[e.jsx("div",{style:{position:"absolute",inset:0,display:$==="chat"&&!N?"block":"none"},children:e.jsx(ro,{conversationId:y,initialMessages:m,kickoffDescription:je,projectName:(de==null?void 0:de.domain)||(de==null?void 0:de.name),userName:bt,project:{userId:s,domain:u,gscSite:xe,name:de==null?void 0:de.name},memory:ne,onMemoryUpdate:()=>{Yn(s,Re.current).then(F)},onToggleSidebar:()=>b(v=>!v),onPersist:Tt,onLiveMessages:v=>j(v),onOpenKeywords:()=>f("keywords"),onOpenView:f,onOpenAgent:Et},y)}),$==="projet"&&!N&&u&&e.jsx("div",{style:{position:"absolute",inset:0,overflowY:"auto"},children:e.jsx(Pr,{...Qe,onClose:()=>f("chat")})}),$==="sources"&&!N&&u&&e.jsx("div",{style:{position:"absolute",inset:0,overflowY:"auto"},children:e.jsx(Ir,{userId:s,domain:u,onClose:()=>f("chat")})}),Dn.includes($)&&!N&&u&&e.jsx("div",{style:{position:"absolute",inset:0},children:e.jsx(si,{view:$,userId:s,domain:u,gscSite:xe,memory:ne,onSaveMemory:async(v,S)=>{await yo(s,Re.current,v,S),F(A=>({...A,[v]:S}))}})}),$!=="chat"&&$!=="projet"&&$!=="sources"&&!Dn.includes($)&&!N&&e.jsx("div",{style:{position:"absolute",inset:0},children:e.jsx(Fi,{view:$,messages:st,memory:ne,briefs:ae,projectName:de==null?void 0:de.domain,onGenerateBrief:Q,onAskInChat:vt,fiche:R.site_fiche,ficheLe:R.site_fiche_at,ficheDomaine:u,ficheEnCours:te,ficheErreur:I,onRefaireFiche:()=>void yt(),gscRows:Le,gscLoading:ze,gscError:Y,onImportGsc:Ft,siteProperty:xe,onGscProperty:v=>void Lt(v),documents:[]})}),q&&!N&&e.jsx("div",{style:{position:"absolute",inset:0},children:e.jsx(oo,{projects:jt,activeId:u,onOpen:v=>{J(!1),Ve(v)},onNew:()=>G(!0),onClose:()=>J(!1)})}),N&&e.jsx("div",{style:{position:"absolute",inset:0},children:e.jsx(Dr,{userId:s,initialSection:D==="dashboard"?void 0:D,onBack:()=>W(!1)},D)})]}),De&&e.jsx(l.Suspense,{fallback:null,children:e.jsx(ko,{briefing:De,userName:bt,startKilled:So(),onDismiss:_o,onOpenProject:v=>void Ve(v)})}),e.jsx(Hr,{agents:ge,activeId:fe,onActivate:we,onClose:Ee,domain:u,gscSite:xe,userId:s,googleConnected:!!xe,projectMemory:ne,onInject:(v,S)=>window.dispatchEvent(new CustomEvent("agent-result",{detail:{content:v,label:S}})),isMobile:B}),e.jsx(io,{open:ce,onCreate:v=>void Kt(v),onClose:()=>G(!1)})]})}export{$o as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.