import{a as y,j as e,a8 as N,H as c,M as d,c2 as o,aw as b,e7 as $,ax as x,e8 as O,e9 as u,bQ as T,ea as H,b$ as B,b as F,w as z,eb as W,r as j,B as g,P as _,D as G,c1 as P,E as Q,bA as U,ah as q,dQ as V,bn as Y,bo as J}from"./strapi-D_Y4QZhh.js";const K=({sort:i="",pageSize:s=10,onChange:t})=>{const{formatMessage:n}=y();return e.jsx(N,{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,{s:12,col: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(b,{onChange:a=>t({target:{name:"pageSize",value:a}}),value:s,children:$.map(a=>e.jsx(x,{value:a,children:a},a))}),e.jsx(d.Hint,{})]})}),e.jsx(c.Item,{s:12,col: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(b,{onChange:a=>t({target:{name:"sort",value:a}}),value:i,"test-sort":i,"data-testid":"sort-select",children:O.map(a=>e.jsx(x,{"data-testid":`sort-option-${a.value}`,value:a.value,children:n({id:o(a.key),defaultMessage:`${a.value}`})},a.key))}),e.jsx(d.Hint,{})]})})]})})},D=`${u}/ON_CHANGE`,v=`${u}/SET_LOADED`,X=({name:i,value:s})=>({type:D,keys:i,value:s}),Z=()=>({type:v}),f={initialData:{},modifiedData:{}},S=i=>({...f,initialData:i,modifiedData:i}),ee=(i=f,s={type:""})=>T(i,t=>{switch(s.type){case D:{"keys"in s&&"value"in s&&s.keys&&B(t,["modifiedData",...s.keys.split(".")],s.value);break}case v:{const n=S(H(t,["modifiedData"],{}));t.initialData=n.initialData,t.modifiedData=n.modifiedData;break}default:return t}}),te=({config:i})=>{const{trackUsage:s}=F(),{formatMessage:t}=y(),{toggleNotification:n}=z(),{mutateConfig:a}=W(),{isLoading:M}=a,[C,h]=j.useState(!1),m=()=>h(r=>!r),[k,w]=j.useReducer(ee,f,()=>S(i)),p=w,{initialData:L,modifiedData:l}=k,E=r=>{r.preventDefault(),m()},R=async()=>{s("willEditMediaLibraryConfig"),await a.mutateAsync(l),h(!1),p(Z()),n({type:"success",message:t({id:"notification.form.success.fields",defaultMessage:"Changes saved"})})},A=({target:{name:r,value:I}})=>{p(X({name:r,value:I}))};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(U,{tag:q,startIcon:e.jsx(V,{}),to:`/plugins/${u}`,id:"go-back",children:t({id:o("config.back"),defaultMessage:"Back"})}),primaryAction:e.jsx(G,{size:"S",startIcon:e.jsx(Q,{}),disabled:P(l,L),type:"submit",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(K,{"data-testid":"settings",pageSize:l.pageSize||"",sort:l.sort||"",onChange:A})}),"x",e.jsx(Y.Root,{open:C,onOpenChange:m,children:e.jsx(J,{onConfirm:R,variant:"default",children:t({id:o("config.popUpWarning.warning.updateAllSettings"),defaultMessage:"This will modify all your settings"})})})]})})})};export{te as ConfigureTheView};
