import{iY as b,iv as I,iG as A,hi as N,hH as v,hI as D,i9 as H,gH as k,j1 as w,fH as s,bL as u,gT as G}from"./strapi-ye6TfKul.js";import{C as O,T as R}from"./Form-BOf61F7n.js";import{a as U}from"./hooks-HNhkYcAB.js";import"./sortable.esm-DYw6p_Rv.js";import"./FieldTypeIcon-CVX_efwb.js";const Q=()=>{const{trackUsage:r}=b(),{formatMessage:o}=I(),{toggleNotification:a}=A(),{_unstableFormatAPIError:c}=N(),{isLoading:E,schema:y,model:L}=v(),{isLoading:F,error:S,list:h,edit:g}=D(),{fieldSizes:x,error:d,isLoading:_,isFetching:j}=H(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=E||F||_||j,[M]=w(),z=async e=>{try{r("willSaveContentTypeLayout");const l=Object.entries(h.metadatas).reduce((t,[i,{mainField:m,...f}])=>{const P=g.metadatas[i],{__temp_key__:V,size:Y,name:$,...T}=e.layout.flatMap(p=>p.children).find(p=>p.name===i)??{};return t[i]={edit:{...P,...T},list:f},t},{}),n=await M({layouts:{edit:e.layout.map(t=>t.children.reduce((i,{name:m,size:f})=>m!==R?[...i,{name:m,size:f}]:i,[])),list:h.layout.map(t=>t.name)},settings:G(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||S||!y?s.jsx(u.Error,{}):s.jsxs(s.Fragment,{children:[s.jsx(u.Title,{children:`Configure ${g.settings.displayName} Edit View`}),s.jsx(O,{onSubmit:z,attributes:y.attributes,fieldSizes:x,layout:g})]})},X=()=>{const r=U(o=>o.admin_app.permissions.contentManager?.collectionTypesConfigurations);return s.jsx(u.Protect,{permissions:r,children:s.jsx(Q,{})})};export{Q as EditConfigurationPage,X as ProtectedEditConfigurationPage};
