import{d5 as G,r as f,e8 as oe,e9 as ne,t as l,p as A,X as I,j as e,ai as y,O as w,dE as ie,dF as le,dG as ce,ea as de,eb as ue,dH as he,aq as me,av as U,bS as pe,aW as z,ck as ge,aU as P,bI as W,bB as xe,V as T,b6 as F,aV as be,bK as N,ay as fe,aw as V,ec as ve,ed as K,cq as je,N as M,aR as Se,am as Z,b0 as X,ee as Ce,c2 as ye,bR as k,cW as we,_ as Y,bM as Te,dM as Ie,bz as ke,l as Ue,ef as Re,dB as Me,aM as Le,eg as Oe,b5 as Ae,eh as Ee,as as De,dw as Ne,au as E,d9 as Pe,aK as H}from"./index-BLPf7Sv2.js";import{C as q}from"./Card-DFtwQktq.js";import"./SimpleContentCard-wrVQJKJ3.js";function Ve(t,s){const r=G(s);return $e({filters:{...t,status:"pending"}},r).length}function _(t,s){return t.findAll(s.filters).map(r=>s.select?s.select(r):r.state)}function $e(t={},s){const r=G(s).getMutationCache(),n=f.useRef(t),a=f.useRef(null);return a.current||(a.current=_(r,t)),f.useEffect(()=>{n.current=t}),f.useSyncExternalStore(f.useCallback(d=>r.subscribe(()=>{const v=oe(a.current,_(r,n.current));a.current!==v&&(a.current=v,ne.schedule(d))}),[r]),()=>a.current,()=>a.current)}function We(t,s){const r=f.useRef(t);f.useEffect(()=>{r.current=t},[t]),f.useEffect(()=>{function n(){r&&r.current&&r.current()}const a=setInterval(n,s);return()=>clearInterval(a)},[s])}const Fe=A.div` position: relative; border-radius: 2rem; width: 100%; height: 0.15rem; background: ${l.color.light[600]}; &::after { content: ''; position: absolute; width: ${({percentage:t=50})=>t<=100?t:100}%; height: 0.125rem; top: 1px; left: 1px; border-radius: 2rem; background: ${({color:t})=>t}; } `,J={en:{title:"Delete {{itemName}}",subtitle:"This {{itemName}} is being used in the following locations and contents:",description:"By deleting this content, it will be permanently removed from all the locations listed above on our platform. This action is irreversible. Please ensure you want to proceed before confirming the deletion.",loading:"Please wait, removing content from the locations...",accordionSubtitle:"This {{entityName}} is linked to the following {{dependenciesName}}"},pt:{title:"Remover {{itemName}}",subtitle:"Este {{itemName}} está sendo usado nos seguintes locais e conteúdos:",description:"Ao excluir este conteúdo, ele será removido permanentemente de todos os locais listados acima em nossa plataforma. Esta ação é irreversível. Certifique-se de que deseja prosseguir antes de confirmar a exclusão.",loading:"Aguarde, removendo conteúdo dos locais selecionados...",accordionSubtitle:"This {{entityName}} is linked to the following {{dependenciesName}}"}},qe=A(P)` padding: 2rem; width: 100%; height: calc(100vh - 30px); margin-top: 30px; position: relative; `,Be=A(q)` background-color: ${l.color.light[300]}; `,ze=A(q)` display: flex; align-items: center; justify-content: space-between; background-color: ${l.color.light[600]}; padding: 0.5rem; .external-link { display: none; } &:hover { .external-link { display: block; } } `,He=A.div` width: 100%; height: 100vh; position: fixed; display: flex; align-items: center; justify-content: center; top: 0; left: 0; overflow: hidden; background-color: ${be(l.color.primary.contrastText,.9)}; z-index: 1; `,_e=[{fieldType:"input",type:"text",name:"removeType",text:"removeType",validationSchema:F().required("fieldRequired").matches(/(REMOVE|remove)/,"invalidValue")}],Qe=({onConfirm:t,itemName:s,contentData:r,title:n,defaultIconName:a,deleteWarningDescription:d,isLoading:v,customDelete:g,buttonSubmitAppearance:h,buttonSubmitText:j})=>{const m=I("confirmAside",J),[b,S]=f.useState(),p=n||m.eval(m.confirmAside.title,{itemName:s}),o=()=>{T.closeModal(),t&&t()},i=()=>{T.closeModal()};return e.jsxs(qe,{children:[e.jsx(y,{appearance:"h3",children:p}),e.jsx(y,{colorScheme:"light.700",appearance:"body2",mb:4,mt:3,children:m.eval(m.confirmAside.subtitle,{itemName:s})}),e.jsx(w,{sx:{gap:"8px"},children:r?.map(x=>e.jsx(e.Fragment,{children:x.listUsing?.length?e.jsxs(ie,{onChange:S,active:b,sx:{w:"100%",px:0,bg:"light.500",r:"4px"},children:[e.jsxs(le,{title:x.titleUsing,children:[e.jsx(y,{appearance:"body2",children:x.titleUsing}),e.jsx(ce,{children:b===x.titleUsing?e.jsx(de,{}):e.jsx(ue,{})})]}),e.jsx(he,{children:e.jsxs(w,{sx:{gap:"8px"},children:[e.jsx(y,{appearance:"body2",colorScheme:"light.700",children:m.eval(m.confirmAside.accordionSubtitle,{entityName:s,dependenciesName:x.titleUsing||""})}),e.jsx(me,{style:{display:"flex",rowGap:"0.5rem",flexDirection:"column",maxHeight:"calc(100vh - 500px)"},children:x.listUsing?.map((c,C)=>{const D=x.getLinkUrl(c);return e.jsxs(ze,{children:[e.jsxs(U,{gap:"0.5rem",align:"center",children:[c.imageUrl?e.jsx(pe,{name:c.imageUrl,imageSrc:c.imageUrl,style:{height:"24px",marginRight:"0.5rem"}}):a&&e.jsx(z,{name:a,width:"24px",height:"24px"}),e.jsx(y,{appearance:"h6",children:c.name})]}),e.jsx(ge,{href:D,target:"_blank",rel:"noreferrer",className:"external-link",children:e.jsx(z,{name:"external-link",color:l.color.light[700]})})]},`${c.name}-${C}`)})})]})})]},x.titleUsing):e.jsx(e.Fragment,{})}))}),e.jsxs(P,{style:{position:"absolute",bottom:"1rem",paddingRight:"2rem",flexDirection:"column",margin:"1rem 0"},children:[e.jsx(U,{children:e.jsx(W,{children:d||m.confirmAside.description})}),e.jsx(U,{style:{margin:"1rem 0"},children:e.jsx(xe,{fields:g||_e,initialValues:{},showAllOperations:!0,submitText:j||m.global.remove,onSubmit:o,anotherOperations:[{type:"button",appearance:"outline",onClick:i,children:m.global.cancel}],buttonSubmitAppearance:h})})]}),v&&e.jsx(Ge,{})]})},Ge=()=>{const t=I("confirmAside",J),[s,r]=f.useState(0);return We(()=>{r((s+10)%100)},250),e.jsx(He,{children:e.jsx(U,{children:e.jsxs(Be,{children:[e.jsx(W,{children:t.confirmAside.loading}),e.jsx(U,{style:{marginTop:"1rem"},children:e.jsx(Fe,{color:l.color.primary[500],percentage:s})})]})})})},Ke={en:{title:"Delete {{itemName}}?",dangerZone:"Danger Zone.",deleteDescription:"Please make sure everything’s right before continuing. This actions is permanent and cannot be undone.",initialDeleteMessage:"This action can’t be undone."},pt:{title:"Excluir {{itemName}}?",dangerZone:"Zona de Perigo.",deleteDescription:"Verifique se está tudo certo antes de continuar. Esta ação é permanente e não pode ser desfeita.",initialDeleteMessage:"Essa ação não pode ser desfeita."}},Ze=[{fieldType:"input",type:"text",name:"deleteType",text:"deleteType",validationSchema:F().required("fieldRequired").matches(/(DELETE|delete)/,"invalidValue"),id:"deleteType"}],xt=({itemName:t,itemLabel:s,isDeleting:r,contentData:n,onDeleteConfirmAside:a,onDeleteConfirmModal:d,defaultIconName:v,style:g,className:h,customDescription:j,customConfirm:m,customCardDescription:b,customCardTitle:S,customTitle:p,customDeleteButton:o})=>{const i=I("deleteCard",Ke),x=i.deleteCard.deleteDescription,c=async()=>{T.showCustomRightPanel(e.jsx(Qe,{onConfirm:a,contentData:n,defaultIconName:v,isLoading:r,itemName:t,customDelete:Ze,buttonSubmitAppearance:"danger",buttonSubmitText:i.global.delete}))},C=async()=>{await T.confirm({title:p??i.eval(i.deleteCard.title,{itemName:t}),children:j??i.eval(x,{itemLabel:s||""}),confirm:m})&&d?.()};return e.jsx(q,{style:g,className:h,children:e.jsxs(P,{className:"fill-width",gap:"2rem",children:[e.jsx(U,{className:"fill-width",children:e.jsxs(P,{className:"fill-width",children:[e.jsx(y,{as:"h2",appearance:"h5",children:S??`${i.global.delete} ${t}`}),e.jsx(W,{style:{marginTop:"12px"},children:b??`${i.deleteCard.initialDeleteMessage}`})]})}),e.jsx(U,{children:e.jsx(N,{"data-test-hint":o??i.global.delete,type:"button",appearance:"danger",isLoading:r,onClick:()=>fe(d?C:c,!0),children:o??i.global.delete})})]})})},L={en:{share:"Share",gotIt:"Got it",shared:"Shared with your organization's account on StackSpot AI.",sharedSince:"Shared since",optIn:"Opt-in content",copyUrl:"Copy url",shareWithUsers:"Share with users",publishOnAccount:"Publish on the account",peopleWithAccess:"People with access",read:"Read",write:"Write",removeAccess:"Remove shared as",readDescription:"Users with Read can view and use any content in the Spot.",writeDescription:"Users with Write can attach/detach content and also have the Read set.",placeholderInvite:"Invite others by name or email...",remove:"Remove shared as",copyUrlSuccess:"Copied!",shareSuccess:"Shared successfully",unableToShare:"Unable to share",deleteUsersSuccess:"Deleted successfully",unableToDelete:"Unable to delete",copyLink:"Copy link",cardEmptyUsers:"Added users will be displayed here.",owner:"Owner",secretShareErrorTitle:"Quick Command cannot be shared",secretShareErrorSubtitle:"This Quick Command has a linked personal secret, preventing sharing. For more information, please refer to the documentation.",noOptions:"No options",selectLabel:"Invite others by name or email"},pt:{share:"Compartilhar",gotIt:"Entendi",shared:"Compartilhado com a conta da sua organização na StackSpot AI.",sharedSince:"Compartilhado desde",optIn:"Conteúdo opt-in",copyUrl:"Copiar url",shareWithUsers:"Compartilhar com usuários",publishOnAccount:"Publicar na conta",peopleWithAccess:"Pessoas com acesso",read:"Leitura",write:"Escrita",removeAccess:"Remover compartilhamento",readDescription:"Usuários com compartilhamento de Leitura podem visualizar e usar qualquer conteúdo no Spot.",writeDescription:"Usuários com compartilhamento de Escrita podem anexar/desanexar conteúdo e possuem também compartilhamento de Leitura.",placeholderInvite:"Convide outros pelo nome ou por email...",remove:"Remover compartilhamento",copyUrlSuccess:"Copiado!",shareSuccess:"Compartilhado com sucesso",unableToShare:"Não foi possível compartilhar",deleteUsersSuccess:"Deletado com sucesso",unableToDelete:"Não foi possível deletar",copyLink:"Copiar link",cardEmptyUsers:"Usuários adicionados serão exibidos aqui.",owner:"Criador",secretShareErrorTitle:"Quick Command não pode ser compartilhado",secretShareErrorSubtitle:"Este Quick Command possui uma secret pessoal vinculada, impedindo o compartilhamento. Para mais informações, consulte a documentação.",noOptions:"Sem opções",selectLabel:"Convidar outras pessoas por nome ou e-mail"}},Xe=({disabled:t,isLoading:s,onSave:r,onCopy:n})=>{const a=I("share",L),d=Ve();return e.jsxs(U,{gap:".5rem",align:"center",justify:n?"space-between":"end",children:[n&&e.jsx(w,{children:e.jsx(N,{appearance:"flat",onClick:n,dataTestHintIndex:2,children:e.jsxs(w,{alignItems:"center",children:[e.jsx(V,{mr:3,children:e.jsx(ve,{})}),a.share.copyLink]})})}),e.jsxs(w,{sx:{gap:"12px"},children:[e.jsx(N,{appearance:"outline",onClick:()=>T.closeModal(),dataTestHintIndex:0,children:a.global.cancel}),e.jsx(N,{disabled:t,isLoading:s||!!d,onClick:r,dataTestHintIndex:1,children:a.global.save})]})]})},Ye=({showDelete:t=!0,index:s=0,...r})=>{const n=I("menu",Le);return e.jsxs(k.Menu,{...r,innerProps:{...r.innerProps,"data-test-hint":`select-menu-${s+1}`},children:[r.children,t&&e.jsxs(Z,{size:"sm","data-test-hint":`testesButtonRemove-${s+1}`,"aria-label":n.global.remove,appearance:"text",colorScheme:"inverse",sx:{w:12,justifyContent:"flex-start"},onClick:()=>r.action({userId:r.userId,userName:r.userName,action:r.userAction}),children:[e.jsxs(V,{size:"xs",children:[" ",r.icon," "]}),e.jsxs(y,{appearance:"body2",pl:3,children:[" ",r.text," "]})]})]})},Je={memberRow:{"&:hover":{backgroundColor:"light.500"}}},Q=t=>{const s=I("creatableSelect",Oe),r=a=>{t.removeProps.onClick?.(a)},n=t.data?.invalid;return e.jsx(k.MultiValue,{...t,children:e.jsx(Ae,{appearance:"square",palette:n?"red":"purple",sx:{mb:2,".badge-citric-container:not(:has(> button:first-child))":{marginRight:0}},afterElement:e.jsx(w,{alignItems:"center",children:e.jsx(k.MultiValueRemove,{...t,children:e.jsx(De,{type:"button","aria-label":s.eval(s.creatableSelect.ariaLabelRemoveItemButton,{itemValue:t.data.label}),colorIcon:n?"danger.500":"purple.500",appearance:"square",onClick:a=>{a.stopPropagation(),r(a)},children:e.jsx(Ne,{})})})}),beforeElement:n&&e.jsx(V,{colorIcon:"danger.600",children:e.jsx(Ee,{})}),children:t.children})})},ee=t=>e.jsx(k.Option,{...t,children:e.jsxs(w,{flexWrap:"nowrap",alignItems:"stretch",sx:{gap:"4px"},children:[e.jsx(M,{w:"16px",children:t.isSelected&&e.jsx(V,{size:"sm",children:e.jsx(we,{height:0})})}),e.jsx(w,{flexDirection:"column",w:"100%",ml:3,children:t.data.labelObject?e.jsxs(e.Fragment,{children:[e.jsx(y,{as:"label",mb:3,children:t.data.labelObject?.title}),e.jsx(y,{colorScheme:"light.700",appearance:"microtext1",children:t.data.labelObject?.description})]}):e.jsx(y,{as:"label",children:t.data.label})})]})}),te=({name:t,email:s,color:r})=>e.jsxs(w,{gap:!0,alignItems:"center",children:[e.jsx(M,{children:e.jsx(Me,{sx:{backgroundColor:r},size:"xs",children:t})}),e.jsx(M,{children:e.jsxs(w,{flexDirection:"column",children:[e.jsx(y,{appearance:"body2",children:t}),e.jsx(y,{appearance:"microtext1",colorScheme:"light.700",children:s})]})})]}),et=t=>e.jsx(k.Option,{...t,children:e.jsx(te,{name:t.data.labelObject?.title,email:t.data.labelObject?.description,color:t.data.labelObject?.color})}),tt={control:(t,s)=>({...t,minHeight:"2.5rem",height:"auto",maxHeight:"100px",overflow:"auto",backgroundColor:l.color.light[300],border:`0.063rem solid ${l.color.light[600]}`,borderRadius:"0.25rem",fontSize:"0.875rem",fontStyle:"normal",fontFeatureSettings:"'clig' off, 'liga' off",display:"flex",alignItems:"center",outlineColor:l.color.light[700],width:"100%","&:hover":{border:`0.063rem solid ${l.color.light[600]}`},...s.isFocused||s.menuIsOpen?{borderColor:`${l.color.primary[500]} !important`,outline:`0.063rem solid ${l.color.primary[500]} !important`}:{}}),input:t=>({...t,color:l.color.light.contrastText}),dropdownIndicator:()=>({display:"none"}),indicatorSeparator:()=>({display:"none"}),singleValue:t=>({...t,color:l.color.light.contrastText}),menu:t=>({...t,backgroundColor:l.color.light[300],border:`0.063rem solid ${l.color.light[400]}`,borderRadius:"0.25rem",boxShadow:`0 0 0 0.125rem ${l.color.light[300]}`,color:l.color.light.contrastText,width:"100%"}),multiValue:t=>({...t,backgroundColor:"inherit",display:"flex",alignItems:"center",justifyItems:"center",color:"white"}),option:(t,{isDisabled:s,isFocused:r,isSelected:n})=>({...t,backgroundColor:s?void 0:n?l.color.light[400]:r?l.color.light[400]:void 0,color:n?l.color.light[300]:l.color.light.contrastText,cursor:s?"not-allowed":"default",border:r?`1px solid ${l.color.inverse[400]}`:t.border,":active":{...t[":active"],backgroundColor:s?void 0:n?l.color.light.contrastText:l.color.light[400]},":hover":{...t[":hover"],backgroundColor:s?void 0:n?l.color.light[500]:l.color.light[400]}})},se={menuPortal:t=>({...t,width:"246px",zIndex:99999999999}),menu:t=>({...t,backgroundColor:l.color.light[300],padding:0,zIndex:99999999999}),option:(t,{isFocused:s})=>({...t,backgroundColor:l.color.light[300],color:l.color.light.contrastText,border:s?`2px solid ${l.color.inverse[600]}`:"2px solid transparent",":hover":{...t[":hover"],backgroundColor:l.color.light[500]}}),input:t=>({...t,color:l.color.light.contrastText})},st={control:t=>({...t,backgroundColor:l.color.light[500],border:"none",padding:"0 0 0 12px",minHeight:"24px",fontSize:"12px",cursor:"pointer","&:hover":{background:l.color.light[300]}}),indicatorsContainer:t=>({...t,height:"auto",maxHeight:"24px"}),dropdownIndicator:t=>({...t,padding:"4px 8px 4px 4px",svg:{width:"14px",height:"14px"}}),input:t=>({...t,padding:0,margin:0}),valueContainer:t=>({...t,padding:0,margin:0})},rt=A(w)` flex-wrap: nowrap; gap: .5rem; margin: 1rem 0; .badge { padding: 0; } & .badge * { font-size: 12px; div[role=button] { &:hover { background-color: inherit; color: inherit; cursor: pointer; }; }; }; .select-users { width: 100%; flex: 1; }; .select-action { width: auto; }; .creatableSelect { width: 100%; } `,at=({onSelectUser:t,membersViewOptions:s,onSelectAction:r,data:n,isLoading:a,fetchNextPage:d,onSearch:v,defaultOption:g="VIEW"})=>{const h=I("share",L),[j,m]=f.useState(""),[b,S]=f.useState([]),[p=[]]=Y.allMembers.useStatefulInfiniteQuery({page:1,size:b.length,filterBy:"email",filterValue:b.join(","),filterMode:"IN"},{enabled:b.length>0});f.useEffect(()=>{if(!p||b.length===0)return;const u=o.values.users||[],R=b.map(B=>{const $=p.find(ae=>ae.email?.toLowerCase()===B.toLowerCase());return $?{label:$.email??"",value:$.id,invalid:!1}:{label:B??"",value:"",invalid:!0}}),O=[...u,...R];o.setFieldValue("users",O),t(O,o.values.action?.value),S([])},[p,b]);const o=Te({initialValues:{users:[],action:s({t:h})[g]},validationSchema:Ie({users:ke().required("modulesIsRequired").min(1,"selectAtLeastOne"),action:F().required("providersIsRequired")}),onSubmit:()=>{}}),i=f.useMemo(()=>{const u=o.values.users?.map(R=>R.label.toLowerCase())||[];return n.filter(R=>!u.includes(R.label.toLowerCase()))},[n,o.values.users]),x=f.useCallback(Ue.debounce(u=>v(u),300),[]),c=u=>{if(u.includes(";")){const R=u.split(";").map(O=>O.trim()).filter(O=>O.length>0);return S(R),m(""),""}return m(u),x(u),u},C=u=>e.jsx(k.Menu,{...u,innerProps:{...u.innerProps,"data-test-hint":"select-users-menu-above"},children:u.children}),D=u=>e.jsx(k.IndicatorsContainer,{...u,innerProps:{...u.innerProps,"data-test-hint":"select-users-indicators-above"}}),re=u=>e.jsx(k.NoOptionsMessage,{...u,children:e.jsx("div",{role:"alert","aria-live":"assertive",children:u.children})});return e.jsx("form",{children:e.jsxs(rt,{children:[e.jsx(Re,{name:"users",className:"select-users",isMulti:!0,inputValue:j,onInputChange:u=>c(u),onMenuScrollToBottom:()=>d(),options:i,isLoading:a,placeholder:h.share.placeholderInvite,id:"dataTestHintselectUsers",noOptionsMessage:()=>h.share.noOptions,components:{NoOptionsMessage:re,MultiValue:Q,MultiValueRemove:()=>e.jsx(e.Fragment,{}),ClearIndicator:()=>null,Option:et},styles:tt,value:o.values.users,onChange:u=>{o.setFieldValue("users",u),t(u,o?.values?.action?.value)},filterOption:()=>!0}),e.jsx(X,{name:"action",className:"select-action",options:Object.values(s({t:h})),menuPortalTarget:document.body,selectStyle:se,id:"dataTestHintselectOptions","aria-label":h.eval(h.global.selectAtLeastOne,{suffix:h.global.permissionLevel}),defaultValue:s({t:h})[g],onChange:u=>{r(u?.value)},components:{MultiValue:Q,MultiValueRemove:()=>e.jsx(e.Fragment,{}),ClearIndicator:()=>null,Option:ee,Menu:C,IndicatorsContainer:D}})]})})},ot=t=>s=>e.jsx(k.IndicatorsContainer,{...s,innerProps:{...s.innerProps,"data-test-hint":`select-users-indicators-below-${t+1}`},children:s.children}),nt=({isLoading:t,resourceUsers:s,onDeleteUser:r,onEdit:n,membersViewOptions:a,fetchNextPage:d,hasNextPage:v})=>{const g=I("share",L),h=K({fromLevel:400}),[j,m]=f.useState(s),b=Object.values(a({t:g})).filter(o=>!!o&&typeof o=="object"&&"label"in o&&"value"in o).map((o,i)=>({...o,dataTestHint:`selectOptions${i}`}));f.useEffect(()=>{j||m(s)},[s]);const S=async o=>{const i=j?.filter(x=>x.username!==o.userName);m(i),r?.(o)};if(t)return e.jsx(je,{});const p=(o,i)=>{if(o?.isDelete||o?.value==="__delete__"){S({userId:i.id,userName:i.username,action:o?.userAction});return}m(x=>x?.map(c=>c.email===i.email?{...c,actions:o?.value}:c)),n(o,i)};return e.jsx(e.Fragment,{children:e.jsx(M,{mb:5,sx:{maxHeight:"220px",overflow:"auto"},id:"scrollableDiv",children:e.jsxs(w,{flexDirection:"column",sx:{gap:"4px"},children:[e.jsx(M,{children:e.jsx(y,{children:g.share.peopleWithAccess})}),!j?.length&&e.jsx(M,{p:5,r:"sm",my:2,bg:"light.500",children:e.jsx(y,{colorScheme:"light.700",align:"center",children:g.share.cardEmptyUsers})}),e.jsx(Se,{next:d,hasMore:v,dataLength:j?.length??0,scrollableTarget:"scrollableDiv",loader:e.jsx(ye,{height:"64px"}),children:j?.map((o,i)=>{const x=o.actions?.includes("grant_access"),c=b.find(C=>C.value.toLowerCase()===String(o.actions).toLowerCase());return e.jsxs(w,{p:"3",sx:Je.memberRow,alignItems:"center",children:[e.jsx(M,{flexGrow:1,children:e.jsx(te,{name:o.name,email:o.email,color:h.next().value})}),x?e.jsx(Z,{size:"sm",disabled:!0,colorScheme:"light",children:g.share.owner}):e.jsx(X,{value:c,id:`testSelectInterOptions-${c?.value?.toUpperCase()??"UNKNOWN"}${i+1}`,"aria-label":g.eval(g.global.selectAtLeastOne,{suffix:g.global.permissionLevel}),components:{Option:ee,IndicatorsContainer:ot(i),Menu:C=>e.jsx(Ye,{index:i,userId:o.id,userName:o.username,userAction:c?.value,action:S,icon:e.jsx(Ce,{}),text:g.share.removeAccess,...C,showDelete:!!r})},menuPortalTarget:document.body,menuPlacement:"auto",options:b,selectStyle:{...se,...st},onChange:C=>p(C,o)})]},o.email)})})]})})})},it=(t,s)=>{const r=K({fromLevel:400});return(t?.map(a=>({label:a.username,value:a.id,email:a.email,labelObject:{title:`${a.firstName} ${a.lastName}`,description:a.email,color:r.next().value}}))).filter(a=>a.email!==s)},lt=({t})=>({VIEW:{value:"VIEW",label:t.share.read,labelObject:{title:t.share.read,description:t.share.readDescription}},EDIT:{value:"EDIT",label:t.share.write,labelObject:{title:t.share.write,description:t.share.writeDescription}}}),bt=({resourceType:t,resourceIdentify:s})=>{const{onEdit:r,onSelectUser:n,onSelectAction:a,onDeleteUser:d,formChanged:v,selectedUsers:g,editedUsers:h,deletedUsers:j}=ht({resourceType:t,resourceIdentify:s}),m=I("share",L),{resourceUsersData:b,fetchNextPage:S,hasNextPage:p,onSave:o,isLoadingAddPermissionResource:i,isLoadingResourceUsers:x,isLoadingRemovePermissionResource:c}=ut({selectedUsers:g,editedUsers:h,deletedUsers:j,resourceType:t,resourceIdentify:s});return e.jsx(dt,{resourceUsersData:b,fetchNextPage:S,hasNextPage:p,onSave:o,isLoadingShareResource:i,isLoadingDeleteUser:c,isLoadingResourceUsers:x,onEdit:r,onSelectUser:n,onSelectAction:a,onDeleteUser:d,formChanged:v,membersViewOptions:()=>lt({t:m})})},ct=({onSelectUser:t,onSelectAction:s,membersViewOptions:r,defaultOption:n})=>{const a=I("share",L),[d,v]=f.useState(""),h=Pe()?.getTokenData().email||"",[j=[],m,,{fetchNextPage:b}]=Y.allMembers.useStatefulInfiniteQuery({page:1,size:20,search:d,filterBy:"isActive",filterValue:"true"}),S=f.useMemo(()=>it(j,h),[j]);return e.jsx(at,{onSelectAction:s,onSelectUser:t,data:S,fetchNextPage:b,onSearch:v,isLoading:m,membersViewOptions:()=>r({t:a}),defaultOption:n})},dt=({resourceUsersData:t,fetchNextPage:s,hasNextPage:r,onSave:n,isLoadingShareResource:a,isLoadingDeleteUser:d,isLoadingResourceUsers:v,onEdit:g,onSelectUser:h,onSelectAction:j,onDeleteUser:m,formChanged:b,membersViewOptions:S,defaultOption:p,onCopyLink:o})=>{const i=I("share",L);return e.jsxs(e.Fragment,{children:[e.jsx(ct,{onSelectAction:j,onSelectUser:h,membersViewOptions:()=>S({t:i}),defaultOption:p}),e.jsx(nt,{isLoading:v,resourceUsers:t,fetchNextPage:s,hasNextPage:r,onEdit:g,onDeleteUser:m,membersViewOptions:()=>S({t:i})}),e.jsx(Xe,{disabled:!b,isLoading:a||d,onSave:n,onCopy:o})]})},ut=({resourceType:t,selectedUsers:s,editedUsers:r,deletedUsers:n,resourceIdentify:a})=>{const d=I("share",L),[v,g]=E.addPermissionResource.useMutation(),[h,j]=E.removePermissionResource.useMutation(),[m,b,,{hasNextPage:S,fetchNextPage:p}]=E.listMembersResource.useStatefulInfiniteQuery({page:1,size:5,resourceType:t,resourceIdentifier:a}),o=async()=>{if(n.current.length)try{await h({permissionListForSharedRequest:{users:n.current},resourceIdentifier:a,resourceType:t.toLocaleLowerCase()}),T.showToaster({type:"success",message:d.share.deleteUsersSuccess})}catch(c){const C=H({error:c,prefix:d.share.unableToDelete});T.showToaster({type:"error",message:C})}},i=async()=>{try{const c=[...s.current,...r.current];if(!c.length)return;await v({permissionListForSharedRequest:{users:c},resourceIdentifier:a,resourceType:t.toLocaleLowerCase()}),T.showToaster({type:"success",message:d.share.shareSuccess})}catch(c){if(c.data?.details?.includes("CODEBUDDY_1063_QUICK_COMMAND_CANNOT_BE_SHARED")){await T.confirm({title:d.share.secretShareErrorTitle,children:d.share.secretShareErrorSubtitle}),T.closeModal();return}const C=H({error:c,prefix:d.share.unableToDelete});T.showToaster({type:"error",message:C})}};return{resourceUsersData:m,fetchNextPage:p,hasNextPage:S,onSave:async()=>{await o(),await i(),await E.listMembersResource.invalidate({resourceIdentifier:a}),T.closeModal()},isLoadingAddPermissionResource:g,isLoadingRemovePermissionResource:j,isLoadingResourceUsers:b}},ht=({resourceType:t,resourceIdentify:s})=>{const[r,n]=f.useState(!1),a=f.useRef([]),d=f.useRef([]),v=f.useRef([]),[g]=E.listMembersResource.useStatefulQuery({resourceIdentifier:s||"",resourceType:t||"agent"},{enabled:!!s&&!!t}),h=()=>{n(!!a.current.length||!!d.current.length||!!v.current.length)};return{onEdit:(p,o)=>{if(g?.find(c=>c.id===o.id&&p?.value?.toLowerCase()===c.actions))return;const x=d.current.find(c=>c.userId===o.id);x?x.action=p?.value:d.current.push({userId:o.id,userName:o.username,action:p?.value}),h()},onSelectUser:(p,o)=>{a.current=p.map(i=>({userName:i.label,userId:i.value,action:o})),h()},onSelectAction:p=>{a.current=a.current.map(o=>({...o,action:p})),h()},onDeleteUser:async p=>{v.current.push(p),h()},formChanged:r,selectedUsers:a,editedUsers:d,deletedUsers:v}};export{ee as C,xt as D,Xe as M,dt as S,L as a,bt as b,se as s,ht as u};