import{b as T,a as I,w as A,v as N,a9 as v,aa as w,ab as D,r as k,ac as O,j as s,P as u,ad as R}from"./strapi-BZkmC8So.js";import{C as U,T as G}from"./Form-DUXdXhmT.js";import{u as H}from"./hooks-BsyjD0Ze.js";import"./sortable.esm-CUOrBiV4.js";import"./FieldTypeIcon-frWP0K-o.js";const Q=()=>{const{trackUsage:r}=T(),{formatMessage:o}=I(),{toggleNotification:a}=A(),{_unstableFormatAPIError:c}=N(),{isLoading:F,schema:y,model:L}=v(),{isLoading:S,error:h,list:E,edit:g}=w(),{fieldSizes:x,error:d,isLoading:_,isFetching:j}=D(void 0,{selectFromResult:e=>{const l=Object.entries(e.data?.fieldSizes??{}).reduce((n,[t,{default:i}])=>(n[t]=i,n),{});return{isFetching:e.isFetching,isLoading:e.isLoading,error:e.error,fieldSizes:l}}});k.useEffect(()=>{d&&a({type:"danger",message:c(d)})},[d,c,a]);const C=F||S||_||j,[M]=O(),P=async e=>{try{r("willSaveContentTypeLayout");const l=Object.entries(E.metadatas).reduce((t,[i,{mainField:m,...f}])=>{const b=g.metadatas[i],{__temp_key__:V,size:$,name:q,...z}=e.layout.flatMap(p=>p.children).find(p=>p.name===i)??{};return t[i]={edit:{...b,...z},list:f},t},{}),n=await M({layouts:{edit:e.layout.map(t=>t.children.reduce((i,{name:m,size:f})=>m!==G?[...i,{name:m,size:f}]:i,[])),list:E.layout.map(t=>t.name)},settings:R(e.settings,"displayName",void 0),metadatas:l,uid:L});"data"in n?(r("didEditEditSettings"),a({type:"success",message:o({id:"notification.success.saved",defaultMessage:"Saved"})})):a({type:"danger",message:c(n.error)})}catch{a({type:"danger",message:o({id:"notification.error",defaultMessage:"An error occurred"})})}};return C?s.jsx(u.Loading,{}):d||h||!y?s.jsx(u.Error,{}):s.jsxs(s.Fragment,{children:[s.jsx(u.Title,{children:`Configure ${g.settings.displayName} Edit View`}),s.jsx(U,{onSubmit:P,attributes:y.attributes,fieldSizes:x,layout:g})]})},Y=()=>{const r=H(o=>o.admin_app.permissions.contentManager?.collectionTypesConfigurations);return s.jsx(u.Protect,{permissions:r,children:s.jsx(Q,{})})};export{Q as EditConfigurationPage,Y as ProtectedEditConfigurationPage};
