import{fH as e,bU as S,iw as A,ck as f,aM as K,aD as _,gZ as I,dN as Q,cE as H,jD as F,ag as V,b0 as Z,Y as J,T as q,x as X,iG as ee,iW as te,au as se,iv as P,hi as ne,f2 as y,hn as ae,i9 as ie,gH as j,i1 as re,aA as oe,gU as le,fP as ce,D as de,cc as ue,S as pe,bS as ge,ci as h,jB as k,ah as he,dP as fe,iC as me,ix as ye,iB as xe,bL as C,bo as D,aZ as je,bz as Te,aL as L}from"./strapi-ye6TfKul.js";import{u as be}from"./useDragLayer-DA6r3b6h.js";import{C as Le}from"./CardDragPreview-CKxlcgRl.js";import{u as Ce,a as E}from"./hooks-HNhkYcAB.js";function Se(t,n,a){if(!t||!n||!a)return{display:"none"};const{x:s,y:o}=a;return{transform:`translate(${s}px, ${o}px)`}}const Me=({renderItem:t})=>{const{itemType:n,isDragging:a,item:s,initialOffset:o,currentOffset:l,mouseOffset:u}=be(r=>({item:r.getItem(),itemType:r.getItemType(),initialOffset:r.getInitialSourceClientOffset(),currentOffset:r.getSourceClientOffset(),isDragging:r.isDragging(),mouseOffset:r.getClientOffset()}));return a?e.jsx(S,{height:"100%",left:0,position:"fixed",pointerEvents:"none",top:0,zIndex:100,width:"100%",children:e.jsx(S,{style:Se(o,l,u),children:t({type:n,item:s})})}):null},ke=({displayedValue:t})=>{const n=A();return e.jsxs(f,{background:"neutral0",borderColor:"neutral200",justifyContent:"space-between",gap:3,padding:3,width:"30rem",children:[e.jsx(Ie,{type:"button",children:e.jsxs(f,{gap:6,children:[e.jsx(De,{alignItems:"center",justifyContent:"center",background:"neutral200",height:"3.2rem",width:"3.2rem",children:e.jsx(K,{})}),e.jsx(f,{maxWidth:"15rem",children:e.jsx(_,{textColor:"neutral700",ellipsis:!0,children:t})})]})}),e.jsxs(f,{gap:2,children:[e.jsx(I,{withTooltip:!1,label:"",variant:"ghost",children:e.jsx(Q,{})}),n&&e.jsx(I,{withTooltip:!1,label:"",variant:"ghost",children:e.jsx(H,{})})]})]})},De=F(f)`
  border-radius: 50%;

  svg {
    height: 0.6rem;
    width: 1.1rem;
    > path {
      fill: ${({theme:t})=>t.colors.neutral600};
    }
  }
`,Ie=F.button`
  border: none;
  background: transparent;
  display: block;
  width: 100%;
  text-align: unset;
  padding: 0;
`,Ee=({status:t,displayedValue:n,width:a})=>{const s=A();return e.jsx(S,{style:{width:a},children:e.jsxs(f,{paddingTop:2,paddingBottom:2,paddingLeft:2,paddingRight:4,hasRadius:!0,borderWidth:1,background:"neutral0",borderColor:"neutral200",justifyContent:"space-between",gap:4,children:[e.jsxs(V,{gap:1,children:[s&&e.jsx(I,{withTooltip:!1,label:"",variant:"ghost",children:e.jsx(H,{})}),e.jsxs(f,{width:"100%",minWidth:0,justifyContent:"space-between",children:[e.jsx(S,{minWidth:0,paddingTop:1,paddingBottom:1,paddingRight:4,children:e.jsx(Z,{href:"",children:e.jsx(_,{textColor:"primary600",ellipsis:!0,children:n})})}),t?e.jsx(J,{status:t}):null]})]}),e.jsx(q,{type:"button",children:e.jsx(X,{width:"12px"})})]})})},{MUTATE_COLLECTION_TYPES_LINKS:Pe,MUTATE_SINGLE_TYPES_LINKS:we}=oe,N=t=>`${t.action}::${t.subject??""}`,Oe=async(t,n)=>{const a=await n(t.flatMap(({permissions:o})=>o)),s=new Set(a.map(N));return t.filter(({permissions:o})=>o.some(l=>s.has(N(l))))},W=()=>{const{toggleNotification:t}=ee(),n=Ce(),a=te("useContentManagerInitData",p=>p.runHookWaterfall),{notifyStatus:s}=se(),{formatMessage:o}=P(),{_unstableFormatAPIError:l}=ne(y),u=ae("useContentManagerInitData",p=>p.checkUserHasPermissions),r=E(p=>p["content-manager"].app),i=ie(void 0,{refetchOnMountOrArgChange:!0});j.useEffect(()=>{i.data&&s(o({id:y("App.schemas.data-loaded"),defaultMessage:"The schemas have been successfully loaded."}))},[o,i.data,s]),j.useEffect(()=>{i.error&&t({type:"danger",message:l(i.error)})},[l,i.error,t]);const c=re();j.useEffect(()=>{c.error&&t({type:"danger",message:l(c.error)})},[l,c.error,t]);const m=j.useCallback(async(p,T,x,d)=>{const{collectionType:g,singleType:M}=T.reduce((b,O)=>(b[O.kind].push(O),b),{collectionType:[],singleType:[]}),R=v(g,"collectionTypes",d),$=v(M,"singleTypes"),w=await Oe([...R,...$],u),B=w.filter(b=>b.kind==="collectionType"),G=w.filter(b=>b.kind==="singleType"),{ctLinks:U}=a(Pe,{ctLinks:B,models:T}),{stLinks:Y}=a(we,{stLinks:G,models:T});n(le({authorizedCollectionTypeLinks:U,authorizedSingleTypeLinks:Y,components:p,contentTypeSchemas:T,fieldSizes:x}))},[u,n,a]);return j.useEffect(()=>{i.data&&c.data&&m(i.data.components,i.data.contentTypes,i.data.fieldSizes,c.data).catch(p=>{t({type:"danger",message:l(p)})})},[l,m,i.data,c.data,t]),{...r}},v=(t,n,a=[])=>t.filter(s=>s.isDisplayed).map(s=>{const o=[{action:"plugin::content-manager.explorer.create",subject:s.uid},{action:"plugin::content-manager.explorer.read",subject:s.uid}],l=[{action:"plugin::content-manager.explorer.read",subject:s.uid}],u=n==="collectionTypes"?o:l,r=a.find(({uid:c})=>c===s.uid);let i=null;if(r){const c={page:1,pageSize:r.settings.pageSize,sort:`${r.settings.defaultSortBy}:${r.settings.defaultSortOrder}`};i=ce.stringify(c,{encode:!1})}return{permissions:u,search:i,kind:s.kind,title:s.info.displayName,to:`/content-manager/${s.kind==="collectionType"?de:ue}/${s.uid}`,uid:s.uid,name:s.uid,isDisplayed:s.isDisplayed}}),z=({isFullPage:t=!1})=>{const[n,a]=j.useState(""),{formatMessage:s,locale:o}=P(),{isLoading:l}=W(),u=E(d=>d["content-manager"].app.collectionTypeLinks),r=E(d=>d["content-manager"].app.singleTypeLinks),{contains:i}=pe(o,{sensitivity:"base"}),c=ge(o,{sensitivity:"base"}),m=j.useMemo(()=>[{id:"collectionTypes",title:s({id:y("components.LeftMenu.collection-types"),defaultMessage:"Collection Types"}),searchable:!0,links:u},{id:"singleTypes",title:s({id:y("components.LeftMenu.single-types"),defaultMessage:"Single Types"}),searchable:!0,links:r}].map(d=>({...d,links:d.links.filter(g=>i(g.title,n.trim())).sort((g,M)=>c.compare(g.title,M.title)).map(g=>({...g,title:s({id:g.title,defaultMessage:g.title})}))})),[u,n,r,i,s,c]),p=()=>{a("")},T=d=>{a(d.target.value)},x=s({id:y("header.name"),defaultMessage:"Content Manager"});return l?e.jsxs(h.Main,{"aria-label":x,children:[e.jsx(h.Header,{label:x}),e.jsx(k,{}),e.jsx(f,{padding:4,justifyContent:"center",children:e.jsx(he,{})})]}):e.jsxs(h.Main,{"aria-label":x,children:[!t&&e.jsxs(e.Fragment,{children:[e.jsx(h.Header,{label:x}),e.jsx(k,{})]}),e.jsxs(h.Content,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(h.Header,{label:x}),e.jsx(k,{})]}),e.jsx(f,{paddingLeft:{initial:3,large:5},paddingRight:{initial:3,large:5},paddingTop:5,paddingBottom:{initial:1,large:0},gap:3,direction:"column",alignItems:"stretch",children:e.jsx(fe,{value:n,onChange:T,onClear:p,placeholder:s({id:"search.placeholder",defaultMessage:"Search"}),size:"S",children:void 0,name:"search_contentType",clearLabel:s({id:"clearLabel",defaultMessage:"Clear"})})}),e.jsx(h.Sections,{children:m.map(d=>e.jsx(h.Section,{label:d.title,badgeLabel:d.links.length.toString(),children:d.links.map(g=>e.jsx(h.Link,{to:{pathname:g.to},label:g.title},g.uid))},d.id))})]})]})},He=()=>{const t=me("/content-manager/:kind/:uid/*"),n=ye(),{isLoading:a,collectionTypeLinks:s,models:o,singleTypeLinks:l}=W(),u=[...s,...l].sort((m,p)=>m.title.localeCompare(p.title)),{pathname:r}=xe(),{formatMessage:i}=P();if(a)return e.jsxs(e.Fragment,{children:[e.jsx(C.Title,{children:i({id:y("plugin.name"),defaultMessage:"Content Manager"})}),e.jsx(C.Loading,{})]});const c=o.filter(({isDisplayed:m})=>m);return u.length===0&&c.length>0&&r!=="/content-manager/403"?e.jsx(D,{to:"/403"}):c.length===0&&r!=="/no-content-types"?e.jsx(D,{to:"/no-content-types"}):!t&&u.length>0?n?e.jsxs(e.Fragment,{children:[e.jsx(C.Title,{children:i({id:y("plugin.name"),defaultMessage:"Content Manager"})}),e.jsx(h.PageWrapper,{children:e.jsx(z,{isFullPage:!0})})]}):e.jsx(D,{to:{pathname:u[0].to,search:u[0].search??""},replace:!0}):e.jsxs(e.Fragment,{children:[e.jsx(C.Title,{children:i({id:y("plugin.name"),defaultMessage:"Content Manager"})}),e.jsxs(je.Root,{sideNav:e.jsx(z,{}),children:[e.jsx(Me,{renderItem:Ne}),e.jsx(Te,{})]})]})};function Ne({type:t,item:n}){if(!t||t&&typeof t!="string")return null;const[a]=t.split("_");switch(a){case L.EDIT_FIELD:case L.FIELD:return e.jsx(Le,{label:n.label});case L.COMPONENT:case L.DYNAMIC_ZONE:return e.jsx(ke,{displayedValue:n.displayedValue});case L.RELATION:return e.jsx(Ee,{...n});default:return null}}export{He as Layout};
