import{iv as y,fH as e,bU as A,cz as c,cI as d,f1 as o,jr as x,gj as H,jw as j,gY as T,gp as u,ey as z,eI as O,gR as G,iY as U,iG as W,ht as _,gH as b,aZ as g,bL as $,jG as V,fs as Y,h1 as B,cG as q,bn as F,cx as K,dx as P,K as Z}from"./strapi-ye6TfKul.js";const J=({sort:i="",pageSize:a=10,onChange:t})=>{const{formatMessage:n}=y();return e.jsx(A,{background:"neutral0",hasRadius:!0,shadow:"tableShadow",paddingTop:6,paddingBottom:6,paddingLeft:7,paddingRight:7,children:e.jsxs(c.Root,{gap:4,children:[e.jsx(c.Item,{xs:12,m:6,direction:"column",alignItems:"stretch",children:e.jsxs(d.Root,{hint:n({id:o("config.entries.note"),defaultMessage:"Number of assets displayed by default in the Media Library"}),name:"pageSize",children:[e.jsx(d.Label,{children:n({id:o("config.entries.title"),defaultMessage:"Entries per page"})}),e.jsx(x,{onChange:s=>t({target:{name:"pageSize",value:s}}),value:a,children:H.map(s=>e.jsx(j,{value:s,children:s},s))}),e.jsx(d.Hint,{})]})}),e.jsx(c.Item,{xs:12,m:6,direction:"column",alignItems:"stretch",children:e.jsxs(d.Root,{hint:n({id:o("config.note"),defaultMessage:"Note: You can override this value in the media library."}),name:"sort",children:[e.jsx(d.Label,{children:n({id:o("config.sort.title"),defaultMessage:"Default sort order"})}),e.jsx(x,{onChange:s=>t({target:{name:"sort",value:s}}),value:i,"test-sort":i,"data-testid":"sort-select",children:T.map(s=>e.jsx(j,{"data-testid":`sort-option-${s.value}`,value:s.value,children:n({id:o(s.key),defaultMessage:`${s.value}`})},s.key))}),e.jsx(d.Hint,{})]})})]})})},v=`${u}/ON_CHANGE`,D=`${u}/SET_LOADED`,Q=({name:i,value:a})=>({type:v,keys:i,value:a}),X=()=>({type:D}),f={initialData:{},modifiedData:{}},C=i=>({...f,initialData:i,modifiedData:i}),ee=(i=f,a={type:""})=>z(i,t=>{switch(a.type){case v:{"keys"in a&&"value"in a&&a.keys&&G(t,["modifiedData",...a.keys.split(".")],a.value);break}case D:{const n=C(O(t,["modifiedData"],{}));t.initialData=n.initialData,t.modifiedData=n.modifiedData;break}default:return t}}),te=({config:i})=>{const{trackUsage:a}=U(),{formatMessage:t}=y(),{toggleNotification:n}=W(),{mutateConfig:s}=_(),{isLoading:M}=s,[k,h]=b.useState(!1),m=()=>h(r=>!r),[S,w]=b.useReducer(ee,f,()=>C(i)),p=w,{initialData:L,modifiedData:l}=S,E=r=>{r.preventDefault(),m()},I=async()=>{a("willEditMediaLibraryConfig"),await s.mutateAsync(l),h(!1),p(X()),n({type:"success",message:t({id:"notification.form.success.fields",defaultMessage:"Changes saved"})})},R=({target:{name:r,value:N}})=>{p(Q({name:r,value:N}))};return e.jsx(g.Root,{children:e.jsx($.Main,{"aria-busy":M,children:e.jsxs("form",{onSubmit:E,children:[e.jsx(g.Header,{navigationAction:e.jsx(q,{tag:F,startIcon:e.jsx(K,{}),to:`/plugins/${u}`,id:"go-back",children:t({id:o("config.back"),defaultMessage:"Back"})}),primaryAction:e.jsx(V,{size:"S",startIcon:e.jsx(B,{}),disabled:Y(l,L),type:"submit",fullWidth:!0,children:t({id:"global.save",defaultMessage:"Save"})}),subtitle:t({id:o("config.subtitle"),defaultMessage:"Define the view settings of the media library."}),title:t({id:o("config.title"),defaultMessage:"Configure the view - Media Library"})}),e.jsx(g.Content,{children:e.jsx(J,{"data-testid":"settings",pageSize:l.pageSize||"",sort:l.sort||"",onChange:R})}),e.jsx(P.Root,{open:k,onOpenChange:m,children:e.jsx(Z,{onConfirm:I,variant:"default",children:t({id:o("config.popUpWarning.warning.updateAllSettings"),defaultMessage:"This will modify all your settings"})})})]})})})};export{te as ConfigureTheView};
