1import{r as o,G as e}from"./vendor-9aa0039e.js";import{B as d,C as I}from"./seo-templates-6f8c3622.js";import{u as D}from"./CrmApp-714fc336.js";import{a as b}from"./crmApi-ddd9bde6.js";import"./realtime-9d95d988.js";import"./helmet-1a5b5a98.js";import"./network-0d55e701.js";import"./seo-local-data-04ba360a.js";import"./seo-city-profiles-08a5ed0c.js";import"./index-34e8a738.js";import"./AppContext-cdb3a4f1.js";const N={IdResponsable:0,ResponsableName:"",ResponsableMail:"",ResponsableTelephone:"",PassWord:"",TelKeyyo:"",PasseKeyyo:"",ResponsableNameClient:"",ResponsableMailClient:"",ResponsableTelephoneClient:"",max_leads_per_day:20,priority:10,departments:[],notes:"",crm_is_active:1,Administrateur:0},H=()=>{const _=s=>{if(!s)return"-";const t=new Date(s.replace(" ","T"));if(Number.isNaN(t.getTime()))return s;const n=r=>r.toString().padStart(2,"0");return`${n(t.getDate())}-${n(t.getMonth()+1)}-${t.getFullYear()} ${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`},{isAuthenticated:w,user:m}=D(),u="Accès réservé aux managers/admin.",[C,k]=o.useState([]),[E,R]=o.useState(!0),[f,x]=o.useState(null),[c,h]=o.useState(null),[a,p]=o.useState(N),l="w-full rounded-2xl border border-white/60 bg-white/70 px-3 py-2 text-sm text-slate-700 shadow-[0_8px_24px_rgba(15,23,42,0.05)] focus:outline-none focus:ring-2 focus:ring-cyan-300/70",A="rounded-2xl border border-white/40 bg-white/60 backdrop-blur-[12px] shadow-[0_8px_24px_rgba(15,23,42,0.06)]",j="rounded-full border border-emerald-200/70 bg-emerald-50/70 px-2.5 py-1 text-xs font-semibold text-emerald-700",g="rounded-full border border-slate-200/70 bg-white/70 px-2.5 py-1 text-xs font-semibold text-slate-600",v=o.useMemo(()=>(m==null?void 0:m.role)==="manager"||(m==null?void 0:m.role)==="admin",[m==null?void 0:m.role]);o.useEffect(()=>{!w||!v||y()},[w,v]);const y=async()=>{var s;R(!0),x(null);try{const t=await b.list();k(t)}catch(t){let n="Impossible de charger les commerciaux";if(t instanceof Error)try{const r=JSON.parse(t.message);(r==null?void 0:r.error)==="FORBIDDEN"||(s=r==null?void 0:r.message)!=null&&s.includes("Permissions insuffisantes")?n=u:r!=null&&r.message&&(n=r.message)}catch{(t.message.includes("FORBIDDEN")||t.message.includes("Permissions insuffisantes"))&&(n=u)}x(n)}finally{R(!1)}},S=()=>{h(null),p({...N})},M=s=>{h(s),p({...s,departments:Array.isArray(s.departments)?s.departments:(typeof s.departments=="string"&&s.departments?s.departments:"").split(",").map(t=>t.trim()).filter(Boolean)})},i=(s,t)=>{p(n=>({...n,[s]:t}))},P=async()=>{try{x(null);const s={...a,departments:Array.isArray(a.departments)?a.departments:[],crm_is_active:Number(a.crm_is_active),Administrateur:Number(a.Administrateur),max_leads_per_day:Number(a.max_leads_per_day),priority:Number(a.priority)};c?await b.update({...s,IdResponsable:c.IdResponsable}):await b.create(s),p({...N}),h(null),await y()}catch{x("Echec de l'enregistrement du commercial")}},T=async s=>{if(window.confirm("Supprimer ce commercial ?"))try{await b.remove(s),await y()}catch{x("Suppression impossible")}};return v?e.jsxs("div",{className:"space-y-6 overflow-x-hidden text-slate-900",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-3xl md:text-4xl leading-tight font-semibold",children:"Commerciaux"}),e.jsx("p",{className:"text-slate-600",children:"Gestion des membres de t_ac"})]}),e.jsx(d,{className:"w-full sm:w-auto",onClick:S,children:"Nouveau commercial"})]}),f&&e.jsx("div",{className:`rounded-2xl border p-4 text-sm shadow-[0_12px_30px_rgba(15,23,42,0.08)] ${f===u?"border-amber-200/70 bg-amber-50/80 text-amber-900":"border-rose-200/70 bg-rose-50/80 text-rose-700"}`,children:f}),e.jsx(I,{className:"p-6",children:E?e.jsx("div",{className:"h-32 animate-pulse rounded-2xl border border-white/60 bg-white/60"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`hidden md:block ${A} overflow-x-auto`,children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-white/60 text-left text-xs uppercase tracking-wide text-slate-500",children:e.jsxs("tr",{className:"border-b border-white/60",children:[e.jsx("th",{className:"px-3 py-2 text-left",children:"Nom"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Email"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Téléphone"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Max/jour"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Priorité"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Connecte"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Actif"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-white/60 text-slate-700",children:C.map(s=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2",children:s.ResponsableName}),e.jsx("td",{className:"px-3 py-2",children:s.ResponsableMail}),e.jsx("td",{className:"px-3 py-2",children:s.ResponsableTelephone}),e.jsx("td",{className:"px-3 py-2",children:s.max_leads_per_day??0}),e.jsx("td",{className:"px-3 py-2",children:s.priority??0}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("span",{className:s.minutes_since_activity!==null&&s.minutes_since_activity!==void 0&&s.minutes_since_activity<=30?j:g,children:s.minutes_since_activity!==null&&s.minutes_since_activity!==void 0&&s.minutes_since_activity<=30?"Connecte":"Deconnecte"}),e.jsx("div",{className:"mt-1 text-[10px] text-slate-500",children:_(s.last_seen)})]}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:s.crm_is_active?j:g,children:s.crm_is_active?"Actif":"Inactif"})}),e.jsxs("td",{className:"px-3 py-2 space-x-2",children:[e.jsx(d,{size:"sm",variant:"outline",onClick:()=>M(s),children:"Modifier"}),e.jsx(d,{size:"sm",variant:"outline",onClick:()=>T(s.IdResponsable),children:"Supprimer"})]})]},s.IdResponsable))})]})}),e.jsx("div",{className:"space-y-2 md:hidden",children:C.map(s=>e.jsxs("div",{className:`${A} p-3`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"min-w-0 break-words text-sm font-semibold text-slate-900",children:s.ResponsableName}),e.jsx("span",{className:s.crm_is_active?j:g,children:s.crm_is_active?"Actif":"Inactif"})]}),e.jsxs("div",{className:"mt-2 space-y-1 text-xs text-slate-600",children:[e.jsxs("p",{className:"break-all",children:[e.jsx("span",{className:"font-medium text-slate-700",children:"Email:"})," ",s.ResponsableMail||"-"]}),e.jsxs("p",{className:"break-all",children:[e.jsx("span",{className:"font-medium text-slate-700",children:"Telephone:"})," ",s.ResponsableTelephone||"-"]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-slate-700",children:"Max/jour:"})," ",s.max_leads_per_day??0]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-slate-700",children:"Priorite:"})," ",s.priority??0]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-medium text-slate-700",children:"Connecte:"})," ",s.minutes_since_activity!==null&&s.minutes_since_activity!==void 0&&s.minutes_since_activity<=30?"Oui":"Non"]}),e.jsxs("p",{className:"break-words",children:[e.jsx("span",{className:"font-medium text-slate-700",children:"Derniere activite:"})," ",_(s.last_seen)]})]}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2 sm:flex-row",children:[e.jsx(d,{size:"sm",variant:"outline",className:"w-full sm:w-auto",onClick:()=>M(s),children:"Modifier"}),e.jsx(d,{size:"sm",variant:"outline",className:"w-full sm:w-auto",onClick:()=>T(s.IdResponsable),children:"Supprimer"})]})]},s.IdResponsable))})]})}),e.jsxs(I,{className:"p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold mb-3",children:[c?"Modifier":"Nouveau"," commercial"]}),c&&e.jsxs("div",{className:"mb-3 break-words text-sm text-slate-600",children:["Identifiant : ",e.jsx("span",{className:"font-semibold",children:c.IdResponsable})," ",c.updated_at&&`(MAJ: ${c.updated_at})`]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Nom",e.jsx("input",{className:l,value:a.ResponsableName,onChange:s=>i("ResponsableName",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Mail",e.jsx("input",{className:l,value:a.ResponsableMail,onChange:s=>i("ResponsableMail",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Téléphone",e.jsx("input",{className:l,value:a.ResponsableTelephone,onChange:s=>i("ResponsableTelephone",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Mot de passe",e.jsx("input",{className:l,value:a.PassWord,onChange:s=>i("PassWord",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Tel KEYYO",e.jsx("input",{className:l,value:a.TelKeyyo??"",onChange:s=>i("TelKeyyo",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Pass KEYYO",e.jsx("input",{className:l,value:a.PasseKeyyo??"",onChange:s=>i("PasseKeyyo",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Nom pour client",e.jsx("input",{className:l,value:a.ResponsableNameClient??"",onChange:s=>i("ResponsableNameClient",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Mail pour client",e.jsx("input",{className:l,value:a.ResponsableMailClient??"",onChange:s=>i("ResponsableMailClient",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Téléphone pour client",e.jsx("input",{className:l,value:a.ResponsableTelephoneClient??"",onChange:s=>i("ResponsableTelephoneClient",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Nb lead / jour",e.jsx("input",{type:"number",className:l,value:a.max_leads_per_day??0,onChange:s=>i("max_leads_per_day",Number(s.target.value))})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Pri
1orité",e.jsx("input",{type:"number",className:l,value:a.priority??0,onChange:s=>i("priority",Number(s.target.value))})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Département (liste séparée par des virgules)",e.jsx("input",{className:l,value:Array.isArray(a.departments)?a.departments.join(", "):"",onChange:s=>i("departments",s.target.value.split(",").map(t=>t.trim()).filter(Boolean))})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Notes",e.jsx("input",{className:l,value:a.notes??"",onChange:s=>i("notes",s.target.value)})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["CRM Actif",e.jsxs("select",{className:l,value:a.crm_is_active,onChange:s=>i("crm_is_active",Number(s.target.value)),children:[e.jsx("option",{value:1,children:"Actif"}),e.jsx("option",{value:0,children:"Inactif"})]})]}),e.jsxs("label",{className:"text-sm flex flex-col gap-1",children:["Administrateur",e.jsxs("select",{className:l,value:a.Administrateur??0,onChange:s=>i("Administrateur",Number(s.target.value)),children:[e.jsx("option",{value:0,children:"Non"}),e.jsx("option",{value:1,children:"Oui"})]})]})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-3",children:[e.jsx(d,{className:"w-full sm:w-auto",onClick:P,children:c?"Enregistrer":"Créer"}),c&&e.jsx(d,{className:"w-full sm:w-auto",variant:"outline",onClick:()=>{h(null),p({...N})},children:"Annuler"})]})]})]}):e.jsxs("div",{className:"rounded-2xl border border-amber-200/70 bg-amber-50/80 p-6 text-amber-900 shadow-[0_12px_30px_rgba(15,23,42,0.08)]",children:[e.jsx("p",{className:"font-semibold",children:"Accès restreint"}),e.jsx("p",{className:"text-sm text-amber-700",children:u})]})};export{H 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.