const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/OrganizationForm-pGYtGO5R.js","assets/render-D1ZqzUbP.js","assets/RequiredTextField-CyIv_v4F.js","assets/TextField-B6uk33js.js","assets/Select-Ht3nAO4Q.js","assets/formControlState-C1XOL3mQ.js","assets/isMuiElement-BcEQvMml.js","assets/ImageUpload-IdvFym3o.js","assets/utils-VIUIl18e.js","assets/Button-DJ_uYab0.js","assets/Alert-M7jUzTjE.js","assets/DialogActions-JiHQNj-t.js"])))=>i.map(i=>d[i]);
import{i as I,j as e,r,a as D,u as L,B as i,P as R,I as d,T as w}from"./render-D1ZqzUbP.js";import{_ as F,L as u}from"./LinearProgress-a_GyCmbh.js";import{B as P,T as U,a as M,b as N,c as b,d as l,e as $}from"./Base-Qt2-pbvB.js";import{A as G}from"./Add-CnBbtKb6.js";import{D as H}from"./Delete-BKYo-wX-.js";import{E as V}from"./Edit-Dg4av1tV.js";import{g as C}from"./utils-VIUIl18e.js";import{G as W}from"./Grid-BihMtcd8.js";import{B as m}from"./Button-DJ_uYab0.js";import{L as X}from"./Link-4dUp4u44.js";import{D as Z}from"./Dialog-aanaDG86.js";import{A as q}from"./Alert-M7jUzTjE.js";import"./formControlState-C1XOL3mQ.js";import"./Select-Ht3nAO4Q.js";import"./isMuiElement-BcEQvMml.js";const J=I(e.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39"})),k=r.lazy(()=>F(()=>import("./OrganizationForm-pGYtGO5R.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])));function K(){const{localeMessages:n,direction:z,apiBaseUrl:x,platformBaseUrl:T,isPlatformAdmin:h}=L(),[E,o]=r.useState(!1),[S,c]=r.useState(null),[p,_]=r.useState([]),[y,f]=r.useState([]);r.useEffect(()=>{fetch(`${x}/organizations/`,{method:"GET",headers:{"Content-Type":"application/json","X-CSRFToken":C("csrftoken")}}).then(s=>s.json()).then(s=>{_(s.organizations)}).catch(s=>{console.error("Error fetching organizations:",s)})},[y]);const g=s=>{console.log("Organization created successfully:",s),o(!1),f(a=>[...a,s])},j=s=>{console.error("Error creating organization:",s)},O=s=>{window.open(s,"_blank")},v=s=>{fetch(`${x}/organizations/${s}/`,{method:"DELETE",headers:{"Content-Type":"application/json","X-CSRFToken":C("csrftoken")}}).then(a=>{a.ok?(console.log("Organization deleted successfully"),f(B=>[...B,{deletedOrganizationId:s}])):console.error("Error deleting organization")}).catch(a=>{console.error("Error deleting organization:",a)})},t=document.getElementsByTagName("html")[0],A=s=>{c(e.jsxs(i,{sx:{p:2},children:[e.jsx(w,{variant:"h6",children:n.confirm_deletion}),e.jsx(q,{severity:"warning",variant:"outlined",sx:{mt:1},children:n.are_you_sure_delete_org.replace("ORGANIZATION_NAME",s.name)}),e.jsxs(i,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:[e.jsx(m,{onClick:()=>o(!1),sx:{mr:1},children:n.cancel}),e.jsx(m,{variant:"contained",color:"error",onClick:()=>{v(s.id),o(!1)},children:n.delete})]})]})),o(!0)};return e.jsxs(P,{breadCrumbList:[{label:n.organizations,href:"#"}],showOrganizationSwitcher:!1,children:[e.jsx(W,{size:12,py:2,pl:2,children:e.jsxs(i,{p:2,sx:{border:"1px solid",borderColor:"border.main",backgroundColor:"background.box",borderRadius:2,minHeight:300},children:[h&&e.jsx(m,{variant:"contained",startIcon:e.jsx(G,{sx:{marginLeft:z=="rtl"?1:0}}),sx:{marginBottom:2},onClick:()=>{c(e.jsx(r.Suspense,{fallback:e.jsx(i,{sx:{p:2},children:e.jsx(u,{})}),children:e.jsx(k,{successCallback:g,failureCallback:j,cancelCallback:()=>o(!1),createMode:!0})})),o(!0)},children:n.add_organization}),p.length>0&&e.jsx(U,{component:R,sx:{maxHeight:440,border:"1px solid",borderColor:"grey.300",borderRadius:1},children:e.jsxs(M,{children:[e.jsx(N,{children:e.jsxs(b,{children:[e.jsx(l,{dir:t.dir,sx:{textAlign:t.dir==="rtl"?"right":"left"},children:n.name}),e.jsx(l,{sx:{width:"150px"},children:n.actions})]})}),e.jsx($,{children:p.map(s=>e.jsxs(b,{children:[e.jsx(l,{dir:t.dir,sx:{textAlign:t.dir==="rtl"?"right":"left"},children:e.jsx(X,{color:"secondary.dark",href:`${T}/organizations/${s.id}/`,children:s.name})}),e.jsxs(l,{children:[e.jsx(d,{onClick:()=>O(s.public_url),children:e.jsx(J,{fontSize:"small"})}),h&&e.jsxs(e.Fragment,{children:[e.jsx(d,{onClick:()=>{c(e.jsx(r.Suspense,{fallback:e.jsx(i,{sx:{p:2},children:e.jsx(u,{})}),children:e.jsx(k,{successCallback:g,failureCallback:j,cancelCallback:()=>o(!1),createMode:!1,initialName:s.name,initialDescription:s.description,initialLogoUrl:s.logo,organizationId:s.id})})),o(!0)},children:e.jsx(V,{fontSize:"small"})}),e.jsx(d,{onClick:()=>A(s),children:e.jsx(H,{fontSize:"small"})})]})]})]},s.id))})]})})]})}),e.jsx(Z,{open:E,onClose:()=>o(!1),fullWidth:!0,maxWidth:"sm",children:S})]})}D({children:e.jsx(K,{})});
//# sourceMappingURL=organizations-xmfIg5pj.js.map
