1import{r as g,j as e}from"./vendor-react-QE7wLE3r.js";import{a as _,u as ee,f as H,e as z,bz as V,bF as xe,D as he,v as ue,w as ge,x as pe,o as X,I as W,i as r,af as fe,B as S,s as I,bx as te,aB as je,aC as be,aD as ve,aE as ye,aG as Ne,aH as ke,aI as Ce,r as we,b as ze,d as K,bu as A,p as q,M as Se,z as se,X as ae,ad as Oe,q as ne,by as De,bq as Ee,a4 as ie,aS as le,T as Ae,bV as Z,bA as Fe,bt as Me}from"./index-DrLBs7PL.js";import{S as U}from"./stat-tile-DixMn0Wq.js";import{S as Re}from"./settings-section-shell-C3gAskEK.js";import{m as w,A as Te}from"./vendor-motion-DpnOviVe.js";import{C as Le}from"./circle-dashed-DpM7mL7r.js";import{P as _e}from"./pencil-BZ99xtnZ.js";import"./vendor-radix-C_2dRBhz.js";import"./cleo-stat-tile-RYJLfjPm.js";const Ie={nameRequired:"orgNameRequired",nameTooLong:"orgNameTooLong",nameAlreadyTaken:"orgNameAlreadyTaken",invalidColor:"orgInvalidColor",organizationNotFound:"organizationNotFound"};function Pe(t){return t instanceof te?typeof t.data=="string"?t.data:null:t instanceof Error?t.message:null}function $e({org:t,open:n,onOpenChange:s}){const{language:c}=_(),a=(m,C)=>I(c,m,C),{toast:j}=ee(),h=H(z.organizations.mutations.create),p=H(z.organizations.mutations.update),[d,b]=g.useState(""),[o,l]=g.useState(null),[f,N]=g.useState(!1),[P,k]=g.useState(!1),[F,O]=g.useState(null);g.useEffect(()=>{n&&(b(t?.name??""),l(t?.color??null),N(!!t?.color&&!V.includes(t.color)),O(null))},[n,t]);const M=o??xe(d||"default"),R=async()=>{k(!0),O(null);try{t?(await p({id:t._id,name:d,color:o===null?null:o}),j({title:a("organizationUpdated")})):(await h({name:d,color:o??void 0}),j({title:a("organizationCreated")})),s(!1)}catch(m){const C=Pe(m),D=C?Ie[C]:null;O(a(D||"common.error"))}finally{k(!1)}};return e.jsx(he,{open:n,onOpenChange:s,children:e.jsxs(ue,{children:[e.jsx(ge,{children:e.jsx(pe,{children:a(t?"editOrganization":"createOrganization")})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(X,{htmlFor:"org-name",children:a("organizationName")}),e.jsx(W,{id:"org-name",value:d,onChange:m=>b(m.target.value),maxLength:80,autoFocus:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:a("organizationColor")}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[V.map(m=>e.jsx("button",{type:"button",onClick:()=>{l(m),N(!1)},className:r("h-7 w-7 rounded-full border-2 transition",o===m?"border-gray-900 dark:border-white scale-110":"border-transparent"),style:{backgroundColor:m},"aria-label":m},m)),e.jsx("button",{type:"button",onClick:()=>N(m=>!m),className:r("h-7 px-2 rounded-full text-xs border",f?"bg-gray-900 text-white dark:bg-white dark:text-gray-900":"bg-transparent"),children:a("customColor")})]}),f&&e.jsx(W,{value:o??"",onChange:m=>l(m.target.value||null),placeholder:"#3B82F6",className:"w-32"}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx("span",{className:"h-4 w-4 rounded-full",style:{backgroundColor:M}}),e.jsx("span",{className:"text-xs text-gray-600 dark:text-gray-400",children:o===null?`${a("customColor")} (auto)`:M})]})]}),F&&e.jsx("p",{className:"text-sm text-red-600",children:F})]}),e.jsxs(fe,{children:[e.jsx(S,{variant:"outline",onClick:()=>s(!1),children:a("common.cancel")}),e.jsx(S,{onClick:R,disabled:P||d.trim().length===0,children:a(t?"common.save":"createOrganization")})]})]})})}function Be({org:t,open:n,onOpenChange:s}){const{language:c}=_(),a=(o,l)=>I(c,o,l),{toast:j}=ee(),h=H(z.organizations.mutations.deleteOrg),[p,d]=g.useState(!1);if(!t)return null;const b=async()=>{d(!0);try{const{unassignedSiteCount:o}=await h({id:t._id});j({title:a("organizationRemovedFromSites",{count:o})}),s(!1)}catch(o){const f=(o instanceof te&&typeof o.data=="string"?o.data:null)==="organizationNotFound"?"organizationNotFound":null;j({variant:"destructive",title:a(f||"common.error"),description:f?void 0:we(o)})}finally{d(!1)}};return e.jsx(je,{open:n,onOpenChange:s,children:e.jsxs(be,{children:[e.jsx(ve,{children:e.jsx(ye,{children:t.siteCount>0?a("deleteOrgConfirmWithSites",{name:t.name,count:t.siteCount}):a("deleteOrgConfirm",{name:t.name})})}),e.jsxs(Ne,{children:[e.jsx(ke,{disabled:p,children:a("common.cancel")}),e.jsx(Ce,{variant:"destructive",onClick:b,disabled:p,children:a("deleteOrganization")})]})]})})}function Ue(t,n){const s=Z(n);if(!s)return null;const c=Array.from(t),a=[];let j="";
1c.forEach((b,o)=>{const l=Z(b)||b;for(let f=0;f<l.length;f++)a.push(o);j+=l});const h=j.indexOf(s);if(h===-1||a.length===0)return null;const p=a[Math.min(h,a.length-1)],d=a[Math.min(h+s.length-1,a.length-1)]+1;return[p,d]}function G({text:t,query:n}){const s=n?Ue(t,n):null;if(!s)return e.jsx(e.Fragment,{children:t});const c=Array.from(t);return e.jsxs(e.Fragment,{children:[c.slice(0,s[0]).join(""),e.jsx("mark",{className:r("rounded-[3px] text-inherit","bg-[#5CC2FF]/30 dark:bg-[#5CC2FF]/25"),children:c.slice(s[0],s[1]).join("")}),c.slice(s[1]).join("")]})}const J=18;function He(){const{language:t}=_(),n=i=>I(t,i),s=t==="fr",{can:c}=ze(),a=K(z.organizations.queries.listWithCounts,{}),j=K(z.sites.queries.getAll),h=a===void 0||j===void 0,p=a??[],d=j??[],[b,o]=g.useState(""),l=b.trim(),[f,N]=g.useState(null),[P,k]=g.useState(!1),[F,O]=g.useState(null),[M,R]=g.useState(!1),[m,C]=g.useState(new Set),D=()=>{N(null),k(!0)},re=i=>{N(i),k(!0)},oe=i=>{O(i),R(!0)},ce=i=>C(y=>{const x=new Set(y);return x.has(i)?x.delete(i):x.add(i),x}),{sitesByOrg:Y,unassignedSites:T}=g.useMemo(()=>{const i=new Map,y=[];for(const x of d){const u={id:x.id,name:x.name,city:x.city},v=x.organizationId;if(v){const E=i.get(v);E?E.push(u):i.set(v,[u])}else y.push(u)}return{sitesByOrg:i,unassignedSites:y}},[d]),L=g.useMemo(()=>{const i=(u,v)=>{const E={key:u?u._id:"unassigned",org:u,color:u?De(u):Ee,allCount:v.length,sites:v,orgMatched:!1};if(!l)return!u&&v.length===0?null:E;const $=u!==null&&A(u.name,l),Q=v.filter(B=>A(B.name,l)||(B.city?A(B.city,l):!1));return!$&&Q.length===0?null:{...E,orgMatched:$,sites:$?v:Q}},y=[];for(const u of p){const v=i(u,Y.get(u._id)??[]);v&&y.push(v)}const x=i(null,T);return x&&y.push(x),y},[p,Y,T,l]),de=l?L.reduce((i,y)=>i+y.sites.filter(x=>A(x.name,l)||(x.city?A(x.city,l):!1)).length,0):d.length,me=L.filter(i=>i.org!==null).length;return e.jsxs(e.Fragment,{children:[e.jsxs(Re,{icon:q,title:n("organizations"),count:h?void 0:p.length,description:n("organizationsDescription"),minHeightClassName:"min-h-[calc(100vh-16rem)]",className:"flex-1",contentClassName:"p-4 md:p-5 space-y-5",testId:"organizations-shell",children:[e.jsxs(w.div,{initial:"hidden",animate:"visible",variants:{hidden:{},visible:{transition:{staggerChildren:.06,delayChildren:.12}}},className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx(U,{label:n("organizations"),value:p.length,sub:s?"groupes de sites":"site groups",icon:q,tone:"cyan",loading:h}),e.jsx(U,{label:"Sites",value:d.length,sub:s?"dans le répertoire":"in the directory",icon:Se,tone:"indigo",loading:h}),e.jsx(U,{label:s?"Non assignés":"Unassigned",value:T.length,sub:s?"sites sans organisation":"sites without organization",icon:Le,tone:T.length>0?"amber":"slate",loading:h})]}),e.jsxs(w.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.3,delay:.35},className:r("rounded-2xl p-3","co-card-inset"),children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(se,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400"}),e.jsx(W,{value:b,onChange:i=>o(i.target.value),placeholder:s?"Rechercher un site ou une organisationâ¦":"Search for a site or organizationâ¦",className:"pl-10 pr-9 h-9 bg-white/80 dark:bg-slate-950/40 border-slate-200 dark:border-slate-700"}),l&&e.jsx("button",{type:"button",onClick:()=>o(""),"aria-label":s?"Effacer la recherche":"Clear search",className:"absolute right-2.5 top-1/2 -translate-y-1/2 p-0.5 rounded-md text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:e.jsx(ae,{className:"h-4 w-4"})})]}),!c.manageOrganizations&&e.jsxs("span",{className:r("shrink-0 inline-flex items-center gap-1.5 h-8 px-2.5 text-[11px] font-semibold text-slate-500 dark:text-slate-400 bg-slate-100/80 dark:bg-slate-800/60 border border-slate-200/60 dark:border-slate-700/60","rounded-full"),children:[e.jsx(Oe,{className:"h-3 w-3"}),n("permissionDeniedReadOnly")]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-[11px] text-slate-500 dark:text-slate-400 tabular-nums",children:[e.jsx("span",{className:r("font-semibold text-slate-700 dark:text-slate-200","co-nums"),children:me}),e.jsx("span",{children:s?"organisations":"organizations"}),e.jsx("span",{className:"text-slate-300 dark:text-slate-600",children:"·"}),e.jsx("span",{className:r("font-semibold text-slate-700 dark:text-slate-200","co-nums"),children:de}),e.jsx("span",{children:"sites"}),l&&e.jsxs("span",{className:"truncate",children:[s?"pour":"for"," «",l,"»"]}),c.manageOrganizations&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-400",children:"·"}),e.jsxs(S,{onClick:D,size:"sm",className:r("h-7 px-3 gap-1.5 text-[11px] font-semibold","rounded-full bg-primary text-primary-foreground border-0 hover:bg-[#0D0087]"),children:[e.jsx(ne,{className:"h-3 w-3",strokeWidth:2.75}),n("newOrganization")]})]})]})]}),h?e.jsx(qe,{}):L.length===0&&l?e.jsx(Ye,{query:l,fr:s,onClear:()=>o("")}):e.jsxs(w.div,{initial:"hidden",animate:"visible",variants:{hidden:{},visible:{transition:{staggerChildren:.05,delayChildren:.15}}},className:"space-y-3",children:[p.length===0&&!l&&e.jsx(Ge,{fr:s,t:n,canCreate:c.manageOrganizations,onCreate:D}),e.jsx(Te,{mode:"popLayout",children:L.map(i=>e.jsx(We,{group:i,query:l,fr:s,expanded:m.has(i.key),onToggleExpanded:()=>ce(i.key),canManage:c.manageOrganizations,onEdit:i.org?()=>re(i.org):void 0,onDelete:i.org?()=>oe(i.org):void 0},i.key))})]})]}),e.jsx($e,{org:f,open:P,onOpenChange:k}),e.jsx(Be,{org:F,open:M,onOpenChange:R})]})}function We({group:t,query:n,fr:s,expanded:c,onToggleExpanded:a,canManage:j,onEdit:h,onDelete:p}){const d=t.org===null,b=t.org?t.org.name:s?"Sites non assignés":"Unassigned sites",o=!n&&t.sites.length>J,l=o&&!c?t.sites.slice(0,J):t.sites,f=t.sites.length-l.length;return e.jsxs(w.section,{layout:!0,variants:{hidden:{opacity:0,y:12},visible:{opacity:1,y:0}},exit:{opacity:0,scale:.98},transition:{type:"spring",stiffness:320,damping:28},className:r("group/row relative overflow-hidden",r("co-tile",d&&"border-dashed")),children:[e.jsx("div",{"aria-hidden":!0,
1className:r("absolute","left-0 top-2 bottom-2 w-[3px] rounded-r-full"),style:{backgroundColor:t.color,opacity:d?.45:1}}),e.jsxs("div",{className:"pl-4 pr-3 py-3.5 md:pl-5 md:pr-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{"aria-hidden":!0,className:r("h-3 w-3 rounded-full shrink-0 ring-2 ring-white dark:ring-slate-900",d&&"opacity-60"),style:{backgroundColor:t.color}}),t.org?e.jsxs(ie,{href:`/organizations/${t.org._id}`,title:s?"Ouvrir la page de l'organisation":"Open the organization page",className:"group/orglink flex items-center gap-1 min-w-0",children:[e.jsx("h2",{className:r("nav-font text-[15px] font-semibold text-slate-900 dark:text-white truncate min-w-0 transition-colors","group-hover/orglink:text-primary"),children:e.jsx(G,{text:b,query:n})}),e.jsx(le,{"aria-hidden":!0,className:r("h-3.5 w-3.5 shrink-0 text-slate-300 dark:text-slate-600 transition-colors","group-hover/orglink:text-primary")})]}):e.jsx("h2",{className:"nav-font text-[15px] font-semibold text-slate-900 dark:text-white truncate min-w-0",children:b}),e.jsxs("span",{className:r("shrink-0 inline-flex items-center gap-1 px-2 py-0.5","co-pill"),children:[e.jsx("span",{className:r("text-xs font-bold tabular-nums text-slate-800 dark:text-slate-100","co-nums"),children:t.allCount}),e.jsx("span",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400",children:t.allCount===1?"site":"sites"})]}),j&&!d&&e.jsxs("div",{className:"ml-auto flex items-center gap-0.5 opacity-0 group-hover/row:opacity-100 focus-within:opacity-100 transition-opacity duration-200",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8 text-slate-500 hover:text-slate-800 dark:hover:text-slate-100",onClick:h,"aria-label":s?"Modifier l'organisation":"Edit organization",children:e.jsx(_e,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8 text-slate-500 hover:text-rose-600 dar
1k:hover:text-rose-400",onClick:p,"aria-label":s?"Supprimer l'organisation":"Delete organization",children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]}),t.sites.length===0?e.jsx("p",{className:"mt-2.5 ml-[22px] text-xs text-slate-400 dark:text-slate-500 italic",children:s?"Aucun site dans cette organisation":"No sites in this organization"}):e.jsxs("div",{className:"mt-2.5 ml-[22px] flex flex-wrap gap-1.5",children:[l.map(N=>e.jsx(Ke,{site:N,query:n},N.id)),f>0&&e.jsxs("button",{type:"button",onClick:a,className:"inline-flex items-center h-7 px-2.5 rounded-lg text-xs font-semibold text-slate-500 dark:text-slate-400 border border-dashed border-slate-300 dark:border-slate-600 hover:text-slate-800 dark:hover:text-slate-100 hover:border-slate-400 dark:hover:border-slate-500 transition-colors active:scale-[0.98]",children:["+",f," ",s?"de plus":"more"]}),o&&c&&e.jsx("button",{type:"button",onClick:a,className:"inline-flex items-center h-7 px-2.5 rounded-lg text-xs font-semibold text-slate-500 dark:text-slate-400 border border-dashed border-slate-300 dark:border-slate-600 hover:text-slate-800 dark:hover:text-slate-100 hover:border-slate-400 dark:hover:border-slate-500 transition-colors active:scale-[0.98]",children:s?"Réduire":"Show less"})]})]})]})}function Ke({site:t,query:n}){return e.jsxs(ie,{href:`/sites/${t.id}`,className:r("group/chip inline-flex items-center gap-1.5 h-7 pl-2.5 pr-2 transition-colors duration-150 active:scale-[0.98] max-w-full","co-link-chip"),children:[e.jsx("span",{className:r("text-xs font-medium text-slate-700 dark:text-slate-200 truncate transition-colors",!1),children:e.jsx(G,{text:t.name,query:n})}),t.city&&e.jsx("span",{className:"hidden sm:inline text-[10px] text-slate-400 dark:text-slate-500 truncate max-w-[9rem]",children:e.jsx(G,{text:t.city,query:n})}),e.jsx(le,{className:r("h-3 w-3 shrink-0 text-slate-300 dark:text-slate-600 transition-colors","group-hover/chip:text-primary")})]})}function qe({}){return e.jsx("div",{className:"space-y-3","aria-hidden":!0,children:[0,1,2].map(t=>e.jsxs("div",{className:r("relative overflow-hidden pl-5 pr-4 py-4","co-tile"),style:{animationDelay:`${t*120}ms`},children:[e.jsx("div",{className:"absolute inset-y-0 left-0 w-1 bg-slate-200 dark:bg-slate-700"}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"h-3 w-3 rounded-full bg-slate-200 dark:bg-slate-700 animate-pulse"}),e.jsx("span",{className:"h-4 w-40 rounded bg-slate-200 dark:bg-slate-800 animate-pulse"}),e.jsx("span",{className:"h-5 w-14 rounded-lg bg-slate-100 dark:bg-slate-800 animate-pulse"})]}),e.jsx("div",{className:"mt-3 ml-[22px] flex flex-wrap gap-1.5",children:Array.from({length:5+t*2}).map((n,s)=>e.jsx("span",{className:"h-7 rounded-lg bg-slate-100 dark:bg-slate-800/70 animate-pulse",style:{width:`${64+s*37%72}px`}},s))})]},t))})}function Ge({fr:t,t:n,canCreate:s,onCreate:c}){return e.jsxs(w.div,{variants:{hidden:{opacity:0,y:10},visible:{opacity:1,y:0}},className:r("px-6 py-10 text-center","co-empty"),children:[e.jsx("div",{className:r("mx-auto h-12 w-12 flex items-center justify-center","co-chip"),children:e.jsx(q,{className:r("h-6 w-6",""),strokeWidth:2})}),e.jsx("p",{className:"mt-4 text-sm font-medium text-slate-600 dark:text-slate-300 max-w-md mx-auto",children:n("noOrganizationsYet")}),s&&e.jsxs(S,{onClick:c,size:"sm",className:r("mt-4 h-9 px-4 gap-1.5 text-xs font-semibold active:scale-[0.98]","rounded-full bg-primary text-primary-foreground border-0 hover:bg-[#0D0087]"),children:[e.jsx(ne,{className:"h-3.5 w-3.5",strokeWidth:2.75}),n("newOrganization")]}),!s&&e.jsx("p",{className:"mt-2 text-xs text-slate-400 dark:text-slate-500",children:t?"Un administrateur peut en créer une.":"An administrator can create one."})]})}function Ye({query:t,fr:n,onClear:s}){return e.jsxs(w.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:r("px-6 py-12 text-center","co-empty"),children:[e.jsx("div",{className:r("mx-auto h-12 w-12 flex items-center justify-center","co-chip"),children:e.jsx(se,{className:"h-6 w-6 text-slate-400 dark:text-slate-500",strokeWidth:2})}),e.jsx("p",{className:"mt-4 text-sm font-medium text-slate-600 dar
1k:text-slate-300",children:n?`Aucun site ni organisation ne correspond à «${t}»`:`No site or organization matches "${t}"`}),e.jsxs("button",{type:"button",onClick:s,className:"mt-3 inline-flex items-center gap-1.5 h-8 px-3 text-xs font-semibold rounded-md text-rose-600 dark:text-rose-300 hover:bg-rose-50 dark:hover:bg-rose-950/30 transition-colors active:scale-[0.98]",children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),n?"Effacer la recherche":"Clear search"]})]})}function nt(){const{language:t}=_(),n=c=>I(t,c),s=K(z.organizations.queries.list,{});return Fe(n("organizations"),s!==void 0?`${s.length} ${t==="fr"?s.length===1?"organisation":"organisations":s.length===1?"organization":"organizations"}`:void 0),e.jsxs("div",{className:"min-h-[calc(100vh-9rem)] -mb-8 flex flex-col",children:[e.jsx(He,{}),e.jsx(Me,{fullBleed:!0})]})}export{nt 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.