1var __IMPORT_META_ENV={};var __PROCESS_ENV={NODE_ENV:"production"}; 2import{a as R}from"/chunks/chunk-54YMUYLG.js";import{b as W,q as Y,r as L,s as Z}from"/chunks/chunk-HCCVXZDS.js";import{k}from"/chunks/chunk-GJM4F2QE.js";import{a as f}from"/chunks/chunk-5LKAQM72.js";import{c as I}from"/chunks/chunk-XAPW7ZU2.js";import{a as q,b as B}from"/chunks/chunk-OTUEUC6J.js";import{$c as Q,M as z,P as G,Pc as X,Ra as _,Yc as K,bd as P,ec as F,gc as M,ja as J,k as U,qc as H,vc as V,xb as w,y as E}from"/chunks/chunk-A6Q5DW52.js";import{a as $}from"/chunks/chunk-A6NSEO7N.js";import{a as ie}from"/chunks/chunk-2F2XG2RD.js";import{e as O,k as S}from"/chunks/chunk-RG6TS3QI.js";import{d as A}from"/chunks/chunk-43M3N6VY.js";var a=A(ie());var e=A($()),ne="https://horizon-pro-7072.taskade.app";function oe(){return"bot-"+Math.random().toString(36).slice(2,8)}function ee({label:o,subtitle:l,isPrincipal:m,assignedCount:n=0,onEdit:u,onDelete:p,deleting:g}){return(0,e.jsxs)(B.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},className:I("group relative flex items-center gap-4 p-4 rounded-2xl border transition-all cursor-pointer",m?"border-indigo-500/30 bg-indigo-500/5 hover:bg-indigo-500/10":"border-border/40 bg-card/60 hover:bg-card/90"),children:[(0,e.jsx)("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:m?"linear-gradient(135deg,#4f46e5,#7c3aed)":"linear-gradient(135deg,#0891b2,#0ea5e9)"},children:(0,e.jsx)(E,{className:"w-5 h-5 text-white"})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("p",{className:"text-sm font-semibold text-foreground truncate",children:o}),m&&(0,e.jsx)("span",{className:"px-1.5 py-0.5 rounded-md text-[10px] font-bold bg-indigo-500/15 text-indigo-400 border border-indigo-500/20",children:"Principal"})]}),(0,e.jsx)("p",{className:"text-[11px] text-muted-foreground",children:l}),n>0&&(0,e.jsxs)("p",{className:"text-[11px] text-cyan-400 mt-0.5",children:[(0,e.jsx)(P,{className:"inline w-3 h-3 mr-0.5"}),n," utilisateur",n>1?"s":""," assign\xE9",n>1?"s":""]})]}),(0,e.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[p&&(0,e.jsx)("button",{onClick:h=>{h.stopPropagation(),p()},disabled:g,className:"opacity-0 group-hover:opacity-100 w-7 h-7 rounded-lg flex items-center justify-center text-red-400 hover:bg-red-500/10 transition-all",title:"Supprimer ce bot",children:g?(0,e.jsx)(w,{className:"w-3.5 h-3.5 animate-spin"}):(0,e.jsx)(X,{className:"w-3.5 h-3.5"})}),(0,e.jsxs)("button",{onClick:u,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-primary/10 hover:bg-primary/20 text-primary text-xs font-semibold transition-all",children:[(0,e.jsx)(H,{className:"w-3.5 h-3.5"}),"Configurer",(0,e.jsx)(G,{className:"w-3 h-3"})]})]})]})}function le({bot:o,allUsers:l,onClose:m,onUpdated:n}){let[u,p]=(0,a.useState)(null),g=o.assignedUserIds||[],h=l.filter(s=>s.role!=="admin"),C=async s=>{let b=g.includes(s.id);p(s.id);try{let x;b?x=g.filter(v=>v!==s.id):x=[...g,s.id];let y={...o,assignedUserIds:x};await L(y);let d=[];try{d=JSON.parse(s.chatbotAssignedBotIds||"[]")}catch{d=[]}b?d=d.filter(v=>v!==o.botId):d.includes(o.botId)||d.push(o.botId),await S(s.id,{chatbotAssignedBotIds:JSON.stringify(d)}),n(y),f.success(b?"Acc\xE8s r\xE9voqu\xE9":"Bot partag\xE9 avec succ\xE8s \u2713")}catch{f.error("Erreur lors de la mise \xE0 jour")}finally{p(null)}};return(0,e.jsxs)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center p-4",children:[(0,e.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:m}),(0,e.jsxs)(B.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative bg-card border border-border rounded-2xl p-5 w-full max-w-md
2shadow-2xl z-10",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h3",{className:"font-bold text-foreground text-sm",children:"Partager le bot"}),(0,e.jsx)("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:o.name})]}),(0,e.jsx)("button",{onClick:m,className:"w-7 h-7 flex items-center justify-center rounded-lg hover:bg-muted/20 text-muted-foreground text-sm",children:"\u2715"})]}),h.length===0?(0,e.jsx)("p",{className:"text-sm text-muted-foreground text-center py-6",children:"Aucun utilisateur disponible"}):(0,e.jsx)("div",{className:"space-y-2 max-h-80 overflow-y-auto pr-1",children:h.map(s=>{let b=g.includes(s.id),x=u===s.id;return(0,e.jsxs)("div",{className:I("flex items-center justify-between p-3 rounded-xl border transition-all",b?"border-emerald-500/30 bg-emerald-500/5":"border-border/40 bg-muted/5"),children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm font-medium text-foreground",children:s.username}),(0,e.jsx)("p",{className:"text-[11px] text-muted-foreground",children:s.role})]}),(0,e.jsx)("button",{onClick:()=>C(s),disabled:!!x,className:I("flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all",b?"bg-red-500/10 text-red-400 hover:bg-red-500/20":"bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20"),children:x?(0,e.jsx)(w,{className:"w-3.5 h-3.5 animate-spin"}):b?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Q,{className:"w-3.5 h-3.5"}),"R\xE9voquer"]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(K,{className:"w-3.5 h-3.5"}),"Partager"]})})]},s.id)})})]})]})}function de({initialLeadId:o}={}){let{allUsers:l}=k(),[m,n]=(0,a.useState)(o?{type:"edit-principal"}:{type:"list"}),[u,p]=(0,a.useState)([]),[g,h]=(0,a.useState)(!0),[C,s]=(0,a.useState)(!1),[b,x]=(0,a.useState)(null),[y,d]=(0,a.useState)(null),[v,D]=(0,a.useState)(!1),{setAllUsers:j}=k(),[te,T]=(0,a.useState)(null);(0,a.useEffect)(()=>{Y().then(p).catch(()=>f.error("Impossible de charger le registre des bots")).finally(()=>h(!1))},[]),(0,a.useEffect)(()=>{l.length===0&&(D(!0),O().then(t=>j(t)).catch(()=>{}).finally(()=>D(!1)))},[l.length,j]);let se=(0,a.useCallback)(async()=>{let t=prompt("Nom du nouveau bot :");if(!(!t||!t.trim())){s(!0);try{let i=oe(),r=t.trim(),c={botId:i,name:r,config:{...W,nom:r,enabled:!0,pagesActives:[],systemPrompt:"",baseConnaissance:"",offresEtTarifs:[],faq:[],questionsLancement:[],messageAccueil:"",boutonLabel:""},leadsProjectId:"",createdAt:new Date().toISOString(),assignedUserIds:[]};await L(c),p(N=>[...N,c]),f.success(`Bot "${r}" cr\xE9\xE9 \u2713`),n({type:"edit-extra",bot:c})}catch{f.error("Erreur lors de la cr\xE9ation du bot")}finally{s(!1)}}},[]),ae=(0,a.useCallback)(async t=>{if(confirm(`Supprimer le bot "${t.name}" ? Les leads sont conserv\xE9s.`)){x(t.botId);try{for(let i of t.assignedUserIds||[]){let r=l.find(N=>N.id===i);if(!r)continue;let c=[];try{c=JSON.parse(r.chatbotAssignedBotIds||"[]")}catch{c=[]}c=c.filter(N=>N!==t.botId),await S(i,{chatbotAssignedBotIds:JSON.stringify(c)})}await Z(t.botId),p(i=>i.filter(r=>r.botId!==t.botId)),f.success("Bot supprim\xE9")}catch{f.error("Erreur lors de la suppression")}finally{x(null)}}},[l]),re=t=>{let i=`${ne}/zen/chatbot-embed?bot=${t}`;navigator.clipboard.writeText(i),T(t),f.success("URL copi\xE9e \u2713"),setTimeout(()=>T(null),2e3)};if(m.type==="edit-principal")return(0,e.jsxs)("div",{children:[(0,e.jsxs)("button",{onClick:()=>n({type:"list"}),className:"flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors px-5 pt-4 pb-2",children:[(0,e.jsx)(U,{className:"w-3.5 h-3.5"}),"Retour aux bots"]}),(0,e.jsx)(R,{initialLeadId:o})]});if(m.type==="edit-extra"){let{bot:t}=m;return(0,e.jsxs)("div",{children:[(0,e.jsxs)("button",{onClick:()=>n({type:"list"}),className:"flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors px-5 pt-4 pb-2",children:[(0,e.jsx)(U,{className:"w-3.5 h-3.5"}),"Retour aux bots"]}),(0,e.jsx)(R,{botId:t.botId,botName:t.name})]})}return(0,e.jsxs)("div",{className:"p-5 space-y-6",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center",style:{background:"linear-gradient(135deg,#4f46e5,#7c3aed)"},children:(0,e.jsx)(E,{className:"w-5 h-5 text-white"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"text-sm font-bold text-foreground",children:"Gestion des Chatbots"}),(0,e.jsxs)("p",{className:"text-[11px] text-muted-foreground",children:[1+u.length," bot",u.length>0?"s":""," \xB7 ",l.filter(t=>t.role!=="admin").length," utilisateurs disponibles"]})]})]}),(0,e.jsxs)("button",{onClick:se,disabled:C,className:"flex items-center gap-2 px-3 py-2 rounded-xl bg-indigo-500/10 hover:bg-indigo-500/20 border border-indigo-500/20 text-indigo-400 text-xs font-semibold transition-all disabled:opacity-50",children:[C?(0,e.jsx)(w,{className:"w-3.5 h-3.5 animate-spin"}):(0,e.jsx)(F,{className:"w-3.5 h-3.5"}),"Cr\xE9er un nouveau bot"]})]}),g?(0,e.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,e.jsx)(w,{className:"w-6 h-6 animate-spin text-indigo-400"})}):(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wide px-1",children:"Bot principal"}),(0,e.jsx)(ee,{label:"Chatbot Vitrine",subtitle:"Bot public \u2014 config principale de l'application",isPrincipal:!0,onEdit:()=>n({type:"edit-principal"})})]}),u.length>0&&(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wide px-1",children:"Bots personnalis\xE9s"}),u.map(t=>(0,e.jsxs)("div",{className:"space-y-1",children:[(0,e.jsx)(ee,{label:t.name,subtitle:`ID: ${t.botId} \xB7 Cr\xE9\xE9 le ${new Date(t.createdAt).toLocaleDateString("fr-FR")}`,assignedCount:(t.assignedUserIds||[]).length,onEdit:()=>n({type:"edit-extra",bot:t}),onDelete:()=>ae(t),deleting:b===t.botId}),(0,e.jsxs)("div",{className:"flex items-center gap-2 pl-14 flex-wrap",children:[(0,e.jsxs)("button",{onClick:()=>d(t),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-cyan-500/10 hover:bg-cyan-500/20 text-cyan-400 text-[11px] font-semibold transition-all",children:[(0,e.jsx)(P,{className:"w-3 h-3"}),"G\xE9rer les acc\xE8s"]}),(0,e.jsxs)("button",{onClick:()=>re(t.botId),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-muted/20 hover:bg-muted/40 text-muted-foreground text-[11px] font-semibold transition-all",children:[te===t.botId?(0,e.jsx)(z,{className:"w-3 h-3 text-emerald-400"}):(0,e.jsx)(J,{className:"w-3 h-3"}),"URL embed"]}),(t.assignedUserIds||[]).map(i=>{let r=l.find(c=>c.id===i);return r?(0,e.jsxs)("span",{className:"flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-[10px]",children:[(0,e.jsx)(V,{className:"w-2.5 h-2.5"}),r.username]},i):null})]})]},t.botId))]}),u.length===0&&(0,e.jsxs)("div",{className:"text-center py-10 text-muted-foreground",children:[(0,e.jsx)(_,{className:"w-8 h-8 mx-auto mb-3 opacity-30"}),(0,e.jsx)("p",{className:"text-sm",children:"Aucun bot personnalis\xE9 pour l'instant."}),(0,e.jsx)("p",{className:"text-xs mt-1",children:'Cliquez sur "Cr\xE9er un nouveau bot" pour commencer.'})]})]}),v&&(0,e.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,e.jsx)(M,{className:"w-3 h-3 animate-spin"}),"Chargement des utilisateurs\u2026"]}),(0,e.jsx)(q,{children:y&&(0,e.jsx)(le,{bot:y,allUsers:l,onClose:()=>d(null),onUpdated:t=>{p(i=>i.map(r=>r.botId===t.botId?t:r)),d(t)}})})]})}export{de as a};
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.