import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,vt as n}from"./mui-BgU4WrXF.js";import{t as r}from"./Autocomplete-OJ15wScd.js";import{t as i}from"./TextField-DctlzLY-.js";import{Et as a,f as o,lt as s,pt as c,st as l,w as u}from"./index-bel1r0Sr.js";var d=e(t(),1),f=n(),p=e=>e.name,m=({label:e,endpointAll:t,endpointLinked:n,baseId:m,keyBase:h,keyLink:g,titleGetter:_=p})=>{let v=c(),[y,b]=(0,d.useState)(!1),[x,S]=(0,d.useState)(),[C,w]=(0,d.useState)(),[T,E]=(0,d.useState)(!1);l(async({signal:e})=>{y&&S(await(await u(t,{signal:e})).json())},[y,t]),l(async({signal:e})=>{y&&w(await(await u(n,{signal:e})).json())},[y,n]);let D=s(async e=>{let t=e=>({[h]:m,[g]:e}),n=C.map(e=>e.id),r=e.map(e=>e.id);if(!r.find(e=>e<0)){let i=[];r.filter(e=>!n.includes(e)).forEach(e=>{i.push(u(`/api/permissions`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t(e))}))}),n.filter(e=>!r.includes(e)).forEach(e=>{i.push(u(`/api/permissions`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t(e))}))}),await Promise.all(i),E(i.length>0),w(e)}},[C,m,h,g]);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(r,{size:`small`,loading:y&&!x,isOptionEqualToValue:(e,t)=>e.id===t.id,options:x||[],getOptionLabel:e=>_(e),slotProps:{chip:{size:`small`}},renderInput:t=>(0,f.jsx)(i,{...t,label:e,placeholder:y?null:v(`reportShow`),onFocus:()=>b(!0),slotProps:{...t.slotProps,inputLabel:{...t.slotProps?.inputLabel,shrink:!y||t.slotProps?.inputLabel?.shrink}}}),value:x&&C||[],onChange:(e,t)=>D(t),multiple:!0}),(0,f.jsx)(a,{open:!!T,onClose:()=>E(!1),autoHideDuration:o,message:v(`sharedSaved`)})]})};export{m as t};