import{a as F,a9 as ee,c9 as te,dA as xe,dB as P,U as ne,dC as je,dD as ve,aa as Ie,j as e,dE as Ce,e as h,M as U,aJ as $,dF as Me,dG as Te,dH as Fe,dI as we,dJ as Ae,r as L,k as se,dK as Ve,K as ie,C as O,a8 as v,dg as W,dL as Le,aZ as Re,T as p,ah as _,bK as ae,bA as G,B as re,aY as De,ce as Be,dM as ke,dN as Pe,dO as Se,H as S,bJ as ze,ak as Ee,b as He,w as Ne,u as H,a$ as Q,z as oe,dP as de,bn as Z,D as K,dQ as $e,G as qe,bo as Ue,q as Oe,ar as N,a_ as le,dR as We,bL as _e,dS as Ge,dT as Qe,dU as Ze,P as V,dV as Ke,dW as Ye,dX as Je,dv as Xe,dY as et,aq as Y,at as tt}from"./strapi-D_Y4QZhh.js";import{u as ce}from"./hooks-Txnjvurv.js";const z=se(Ve).attrs({closeLabel:"Close",onClose:()=>{},shadow:"none"})`
  button {
    display: none;
  }
`,nt=se(G)`
  display: block;

  & > span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }
`,st=n=>{const{formatMessage:s}=F(),i=ie(n.name);let a;if(i&&(a=Array.isArray(i.value)?{results:i.value,meta:{missingCount:0}}:i.value),!a||a.results.length===0&&a.meta.missingCount===0)return e.jsxs(e.Fragment,{children:[e.jsx(U.Label,{action:n.labelAction,children:n.label}),e.jsx(v,{marginTop:1,children:e.jsx(z,{variant:"default",children:s({id:"content-manager.history.content.no-relations",defaultMessage:"No relations."})})})]});const{results:t,meta:r}=a;return e.jsxs(v,{children:[e.jsx(U.Label,{children:n.label}),t.length>0&&e.jsx(h,{direction:"column",gap:2,marginTop:1,alignItems:"stretch",children:t.map(o=>{const{targetModel:d}=n.attribute,y=`../${W}/${d}/${o.documentId}`,f=Le(o,n.mainField),I=d==="admin::user";return e.jsxs(h,{paddingTop:2,paddingBottom:2,paddingLeft:4,paddingRight:4,hasRadius:!0,borderColor:"neutral200",background:"neutral150",justifyContent:"space-between",children:[e.jsx(v,{minWidth:0,paddingTop:1,paddingBottom:1,paddingRight:4,children:e.jsx(Re,{label:f,children:I?e.jsx(p,{children:f}):e.jsx(nt,{tag:_,to:y,children:f})})}),e.jsx(ae,{status:o.status})]},o.documentId??o.id)})}),r.missingCount>0&&e.jsx(z,{marginTop:1,variant:"warning",title:s({id:"content-manager.history.content.missing-relations.title",defaultMessage:"{number, plural, =1 {Missing relation} other {{number} missing relations}}"},{number:r.missingCount}),children:s({id:"content-manager.history.content.missing-relations.message",defaultMessage:"{number, plural, =1 {It has} other {They have}} been deleted and can't be restored."},{number:r.missingCount})})]})},it=(n,s)=>{const i=n.split("."),a={};let t=a;return i.forEach((r,o)=>{r==="__proto__"||r==="constructor"||(o===i.length-1?t[r]=s:t[r]=t[r]||{},t=t[r])}),a},at=n=>{const{value:s}=ie(n.name),i=s?.results??[],a=s?.meta??{missingCount:0},{formatMessage:t}=F(),o=ne("CustomMediaInput",d=>d.fields).media;return e.jsxs(h,{direction:"column",gap:2,alignItems:"stretch",children:[e.jsx(O,{method:"PUT",disabled:!0,initialValues:it(n.name,i),children:e.jsx(o,{...n,disabled:!0,multiple:i.length>1})}),a.missingCount>0&&e.jsx(z,{variant:"warning",closeLabel:"Close",onClose:()=>{},title:t({id:"content-manager.history.content.missing-assets.title",defaultMessage:"{number, plural, =1 {Missing asset} other {{number} missing assets}}"},{number:a.missingCount}),children:t({id:"content-manager.history.content.missing-assets.message",defaultMessage:"{number, plural, =1 {It has} other {They have}} been deleted in the Media Library and can't be restored."},{number:a.missingCount})})]})},rt=n=>{if(!L.isValidElement(n))return n;const s=n.props.title.id;return s==="i18n.Field.localized"?L.cloneElement(n,{...n.props,title:{id:"history.content.localized",defaultMessage:"This value is specific to this locale. If you restore this version, the content will not be replaced for other locales."}}):s==="i18n.Field.not-localized"?L.cloneElement(n,{...n.props,title:{id:"history.content.not-localized",defaultMessage:"This value is common to all locales. If you restore this version and save the changes, the content will be replaced for all locales."}}):n},E=({visible:n,hint:s,shouldIgnoreRBAC:i=!1,labelAction:a,...t})=>{const r=rt(a),{formatMessage:o}=F(),d=C("VersionContent",l=>l.selectedVersion),y=C("VersionContent",l=>l.configuration),f=ce(l=>l["content-manager"].app.fieldSizes),{id:I,components:T}=ee(),c=te("InputRenderer",l=>l.disabled),g=xe("isInDynamicZone",l=>l.isInDynamicZone),m=P("InputRenderer",l=>l.canCreateFields),w=P("InputRenderer",l=>l.canReadFields),M=P("InputRenderer",l=>l.canUpdateFields),A=P("InputRenderer",l=>l.canUserAction),b=I?M:m,R=I?w:m,D=A(t.name,R,t.type),u=A(t.name,b,t.type),k=ne("InputRenderer",l=>l.fields),{lazyComponentStore:ge}=je(q(t.attribute)?[t.attribute.customField]:void 0),x=ve(s,t.attribute),{edit:{components:he}}=Ie();if(!n)return null;if(!i&&!D&&!g)return e.jsx(Ce,{hint:x,...t});const j=!u&&!g||t.disabled||c,ye=d.meta.unknownAttributes.added;if(Object.keys(ye).includes(t.name))return e.jsxs(h,{direction:"column",alignItems:"flex-start",gap:1,children:[e.jsx(U.Label,{children:t.label}),e.jsx(z,{width:"100%",closeLabel:"Close",onClose:()=>{},variant:"warning",title:o({id:"content-manager.history.content.new-field.title",defaultMessage:"New field"}),children:o({id:"content-manager.history.content.new-field.message",defaultMessage:"This field didn't exist when this version was saved. If you restore this version, it will be empty."})})]});if(q(t.attribute)){const l=ge[t.attribute.customField];return l?e.jsx(l,{...t,hint:x,labelAction:r,disabled:j}):e.jsx($,{...t,hint:x,labelAction:r,type:t.attribute.customField,disabled:j})}if(t.type==="media")return e.jsx(at,{...t,labelAction:r,disabled:j});const fe=Object.keys(k);if(!q(t.attribute)&&fe.includes(t.type)){const l=k[t.type];return e.jsx(l,{...t,hint:x,labelAction:r,disabled:j})}switch(t.type){case"blocks":return e.jsx(Ae,{...t,hint:x,type:t.type,disabled:j});case"component":const{layout:l}=he[t.attribute.component],[be]=me({layout:[l],metadatas:y.components[t.attribute.component].metadatas,fieldSizes:f,schemaAttributes:T[t.attribute.component].attributes});return e.jsx(we,{...t,layout:[...l,...be||[]],hint:x,labelAction:r,disabled:j,children:B=>e.jsx(E,{...B,shouldIgnoreRBAC:!0})});case"dynamiczone":return e.jsx(Fe,{...t,hint:x,labelAction:r,disabled:j,children:B=>e.jsx(E,{...B,shouldIgnoreRBAC:!0})});case"relation":return e.jsx(st,{...t,hint:x,labelAction:r,disabled:j});case"richtext":return e.jsx(Te,{...t,hint:x,type:t.type,labelAction:r,disabled:j});case"uid":return e.jsx(Me,{...t,hint:x,type:t.type,labelAction:r,disabled:j});case"enumeration":return e.jsx($,{...t,hint:x,labelAction:r,options:t.attribute.enum.map(B=>({value:B})),type:t.customField?"custom-field":t.type,disabled:j});default:const{unique:pt,mainField:xt,...pe}=t;return e.jsx($,{...pe,hint:x,labelAction:r,type:t.customField?"custom-field":t.type,disabled:j})}},q=n=>"customField"in n&&typeof n.customField=="string",ue=n=>n.reduce((s,i)=>i.type==="dynamiczone"?(s.push([i]),s):(s[s.length-1]||s.push([]),s[s.length-1].push(i),s),[]).map(s=>[s]);function me({layout:n,metadatas:s,schemaAttributes:i,fieldSizes:a}){const t=n.flatMap(o=>o.flatMap(d=>d.flatMap(y=>y.name))),r=Object.entries(s).reduce((o,[d,y])=>{if(!t.includes(d)&&y.edit.visible===!0){const f=i[d];o.push({attribute:f,type:f.type,visible:!0,disabled:!0,label:y.edit.label||d,name:d,size:a[f.type].default??12})}return o},[]);return ue(r)}const J=({panel:n})=>{const s=te("Fields",a=>a.values),i=Se();if(n.some(a=>a.some(t=>t.type==="dynamiczone"))){const[a]=n,[t]=a,r=t.attribute?.conditions?.visible;return r&&!i.evaluate(r,s)?null:e.jsx(S.Root,{gap:4,children:e.jsx(S.Item,{col:12,s:12,xs:12,direction:"column",alignItems:"stretch",children:e.jsx(E,{...t})})},t.name)}return e.jsx(v,{hasRadius:!0,background:"neutral0",shadow:"tableShadow",paddingLeft:6,paddingRight:6,paddingTop:6,paddingBottom:6,borderColor:"neutral150",children:e.jsx(h,{direction:"column",alignItems:"stretch",gap:6,children:n.map((a,t)=>{const r=a.filter(o=>{const d=o.attribute?.conditions?.visible;return d?i.evaluate(d,s):!0});return r.length===0?null:e.jsx(S.Root,{gap:4,children:r.map(({size:o,...d})=>e.jsx(S.Item,{col:o,s:12,xs:12,direction:"column",alignItems:"stretch",children:e.jsx(E,{...d})},d.name))},t)})})})},ot=()=>{const{formatMessage:n}=F(),{fieldSizes:s}=ce(c=>c["content-manager"].app),i=C("VersionContent",c=>c.selectedVersion),a=C("VersionContent",c=>c.layout),t=C("VersionContent",c=>c.configuration),r=C("VersionContent",c=>c.schema),o=i.meta.unknownAttributes.removed,d=Object.entries(o).map(([c,g])=>({attribute:g,shouldIgnoreRBAC:!0,type:g.type,visible:!0,disabled:!0,label:c,name:c,size:s[g.type].default??12})),y=ue(d),f=me({metadatas:t.contentType.metadatas,layout:a,schemaAttributes:r.attributes,fieldSizes:s}),{components:I}=ee(),T=L.useMemo(()=>((g,m={})=>w=>{const M={attributes:g};return Be(ke(M),Pe(M,m))(w)})(i.schema,I)(i.data),[I,i.data,i.schema]);return e.jsxs(re.Content,{children:[e.jsx(v,{paddingBottom:8,children:e.jsx(O,{disabled:!0,method:"PUT",initialValues:T,children:e.jsx(h,{direction:"column",alignItems:"stretch",gap:6,position:"relative",children:[...a,...f].map((c,g)=>e.jsx(J,{panel:c},g))})})}),d.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(De,{}),e.jsxs(v,{paddingTop:8,children:[e.jsxs(h,{direction:"column",alignItems:"flex-start",paddingBottom:6,gap:1,children:[e.jsx(p,{variant:"delta",children:n({id:"content-manager.history.content.unknown-fields.title",defaultMessage:"Unknown fields"})}),e.jsx(p,{variant:"pi",children:n({id:"content-manager.history.content.unknown-fields.message",defaultMessage:"These fields have been deleted or renamed in the Content-Type Builder. <b>These fields will not be restored.</b>"},{b:c=>e.jsx(p,{variant:"pi",fontWeight:"bold",children:c})})})]}),e.jsx(O,{disabled:!0,method:"PUT",initialValues:i.data,children:e.jsx(h,{direction:"column",alignItems:"stretch",gap:6,position:"relative",children:y.map((c,g)=>e.jsx(J,{panel:c},g))})})]})]})]})},dt=ze.injectEndpoints({endpoints:n=>({getHistoryVersions:n.query({query(s){return{url:"/content-manager/history-versions",method:"GET",config:{params:s}}},providesTags:["HistoryVersion"]}),restoreVersion:n.mutation({query({params:s,body:i}){return{url:`/content-manager/history-versions/${s.versionId}/restore`,method:"PUT",data:i}},invalidatesTags:(s,i,{documentId:a,collectionType:t,params:r})=>["HistoryVersion",{type:"Document",id:t===W?`${r.contentType}_${a}`:r.contentType}]})})}),{useGetHistoryVersionsQuery:lt,useRestoreVersionMutation:ct}=dt,ut=({headerId:n})=>{const[s,i]=L.useState(!1),a=Ee(),{formatMessage:t,formatDate:r}=F(),{trackUsage:o}=He(),{toggleNotification:d}=Ne(),[{query:y}]=H(),{collectionType:f,slug:I}=Q(),[T,{isLoading:c}]=ct(),{allowedActions:g}=oe(de.map(u=>({action:u,subject:I}))),m=C("VersionHeader",u=>u.selectedVersion),w=C("VersionHeader",u=>u.mainField),M=C("VersionHeader",u=>u.schema),A=C("VersionHeader",u=>u.page===1&&u.versions.data[0].id===u.selectedVersion.id),b=m.data[w],R=()=>({pathname:"..",search:N.stringify({plugins:y.plugins},{encode:!1})}),D=async()=>{try{const u=await T({documentId:m.relatedDocumentId,collectionType:f,params:{versionId:m.id,contentType:m.contentType},body:{contentType:m.contentType}});"data"in u&&(a(R(),{relative:"path"}),d({type:"success",title:t({id:"content-manager.restore.success.title",defaultMessage:"Version restored."}),message:t({id:"content-manager.restore.success.message",defaultMessage:"A past version of the content was restored."})}),o("didRestoreHistoryVersion")),"error"in u&&d({type:"danger",message:t({id:"content-manager.history.restore.error.message",defaultMessage:"Could not restore version."})})}catch{d({type:"danger",message:t({id:"notification.error",defaultMessage:"An error occurred"})})}};return e.jsxs(Z.Root,{open:s,onOpenChange:i,children:[e.jsx(re.BaseHeader,{id:n,title:r(new Date(m.createdAt),{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric"}),secondaryAction:e.jsx(qe,{label:t({id:"components.premiumFeature.title",defaultMessage:"Premium feature"})}),subtitle:e.jsx(p,{variant:"epsilon",textColor:"neutral600",children:t({id:"content-manager.history.version.subtitle",defaultMessage:"{hasLocale, select, true {{subtitle}, in {locale}} other {{subtitle}}}"},{hasLocale:!!m.locale,subtitle:`${b||""} (${M.info.singularName})`.trim(),locale:m.locale?.name})}),navigationAction:e.jsx(G,{startIcon:e.jsx($e,{}),tag:_,to:R(),relative:"path",isExternal:!1,children:t({id:"global.back",defaultMessage:"Back"})}),sticky:!1,primaryAction:e.jsx(Z.Trigger,{children:e.jsx(K,{disabled:!g.canUpdate||A,onClick:()=>{i(!0)},children:t({id:"content-manager.history.restore.confirm.button",defaultMessage:"Restore"})})})}),e.jsx(Ue,{onConfirm:D,endAction:e.jsx(K,{variant:"secondary",onClick:D,loading:c,children:t({id:"content-manager.history.restore.confirm.button",defaultMessage:"Restore"})}),children:e.jsxs(h,{direction:"column",alignItems:"center",justifyContent:"center",gap:2,textAlign:"center",children:[e.jsx(h,{justifyContent:"center",children:e.jsx(Oe,{width:"24px",height:"24px",fill:"danger600"})}),e.jsx(p,{children:t({id:"content-manager.history.restore.confirm.title",defaultMessage:"Are you sure you want to restore this version?"})}),e.jsx(p,{children:t({id:"content-manager.history.restore.confirm.message",defaultMessage:"{isDraft, select, true {The restored content will override your draft.} other {The restored content won't be published, it will override the draft and be saved as pending changes. You'll be able to publish the changes at anytime.}}"},{isDraft:m.status==="draft"})})]})})]})},mt=n=>e.jsx(p,{textColor:"primary600",variant:"pi",children:n}),gt=({version:n,isCurrent:s})=>{const{formatDate:i,formatMessage:a}=F(),[{query:t}]=H(),r=t.id===n.id.toString(),o=n.createdBy&&We(n.createdBy);return e.jsxs(h,{direction:"column",alignItems:"flex-start",gap:3,hasRadius:!0,borderWidth:"1px",borderStyle:"solid",borderColor:r?"primary600":"neutral200",color:"neutral800",padding:5,tag:le,to:`?${N.stringify({...t,id:n.id})}`,style:{textDecoration:"none"},children:[e.jsxs(h,{direction:"column",gap:1,alignItems:"flex-start",children:[e.jsx(p,{tag:"h3",fontWeight:"semiBold",children:i(n.createdAt,{day:"numeric",month:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}),e.jsx(p,{tag:"p",variant:"pi",textColor:"neutral600",children:a({id:"content-manager.history.sidebar.versionDescription",defaultMessage:"{distanceToNow}{isAnonymous, select, true {} other { by {author}}}{isCurrent, select, true { <b>(current)</b>} other {}}"},{distanceToNow:e.jsx(_e,{timestamp:new Date(n.createdAt)}),author:o,isAnonymous:!n.createdBy,isCurrent:s,b:mt})})]}),n.status&&e.jsx(ae,{status:n.status,size:"XS"})]})},X=({page:n,children:s})=>{const[{query:i}]=H(),{id:a,...t}=i;return e.jsx(le,{to:{search:N.stringify({...t,page:n})},style:{textDecoration:"none"},children:e.jsx(p,{variant:"omega",textColor:"primary600",children:s})})},ht=()=>{const{formatMessage:n}=F(),{versions:s,page:i}=C("VersionsList",a=>({versions:a.versions,page:a.page}));return e.jsxs(h,{shrink:0,direction:"column",alignItems:"stretch",width:"320px",height:"100vh",background:"neutral0",borderColor:"neutral200",borderWidth:"0 0 0 1px",borderStyle:"solid",tag:"aside",children:[e.jsxs(h,{direction:"row",justifyContent:"space-between",padding:4,borderColor:"neutral200",borderWidth:"0 0 1px",borderStyle:"solid",tag:"header",children:[e.jsx(p,{tag:"h2",variant:"omega",fontWeight:"semiBold",children:n({id:"content-manager.history.sidebar.title",defaultMessage:"Versions"})}),e.jsx(v,{background:"neutral150",hasRadius:!0,padding:1,children:e.jsx(p,{variant:"sigma",textColor:"neutral600",children:s.meta.pagination.total})})]}),e.jsxs(v,{flex:1,overflow:"auto",children:[s.meta.pagination.page>1&&e.jsx(v,{paddingTop:4,textAlign:"center",children:e.jsx(X,{page:i-1,children:n({id:"content-manager.history.sidebar.show-newer",defaultMessage:"Show newer versions"})})}),e.jsx(h,{direction:"column",gap:3,padding:4,tag:"ul",alignItems:"stretch",children:s.data.map((a,t)=>e.jsx("li",{"aria-label":n({id:"content-manager.history.sidebar.title.version-card.aria-label",defaultMessage:"Version card"}),children:e.jsx(gt,{version:a,isCurrent:i===1&&t===0})},a.id))}),s.meta.pagination.page<s.meta.pagination.pageCount&&e.jsx(v,{paddingBottom:4,textAlign:"center",children:e.jsx(X,{page:i+1,children:n({id:"content-manager.history.sidebar.show-older",defaultMessage:"Show older versions"})})})]})]})},[yt,C]=Ge("HistoryPage"),ft=()=>{const n=L.useId(),{formatMessage:s}=F(),{slug:i,id:a,collectionType:t}=Q(),{isLoading:r,schema:o}=Ye({collectionType:t,model:i}),{isLoading:d,edit:{layout:y,settings:{displayName:f,mainField:I}}}=Je(i),{data:T,isLoading:c}=Xe(i),[{query:g}]=H(),{id:m,...w}=g,M=et(w),A=M.page?Number(M.page):1,b=lt({contentType:i,...a?{documentId:a}:{},...M},{refetchOnMountOrArgChange:!0}),R=L.useRef(b.requestId),D=b.requestId===R.current;if(!i||t===W&&!a)return e.jsx(Y,{to:"/content-manager"});if(r||d||b.isFetching||D||c)return e.jsx(V.Loading,{});if(!b.isError&&!b.data?.data?.length)return e.jsx(e.Fragment,{children:e.jsx(V.NoData,{action:e.jsx(G,{tag:_,to:`/content-manager/${t}/${i}${a?`/${a}`:""}`,children:s({id:"global.back",defaultMessage:"Back"})})})});if(b.data?.data?.length&&!m)return e.jsx(Y,{to:{search:N.stringify({...g,id:b.data.data[0].id})},replace:!0});const u=b.data?.data?.find(k=>k.id.toString()===m);return b.isError||!y||!o||!u||!T||b.data.error?e.jsx(V.Error,{}):e.jsxs(e.Fragment,{children:[e.jsx(V.Title,{children:s({id:"content-manager.history.page-title",defaultMessage:"{contentType} history"},{contentType:f})}),e.jsx(yt,{contentType:i,id:a,schema:o,layout:y,configuration:T,selectedVersion:u,versions:b.data,page:A,mainField:I,children:e.jsxs(h,{direction:"row",alignItems:"flex-start",children:[e.jsxs(tt,{grow:1,height:"100vh",background:"neutral100",paddingBottom:6,overflow:"auto",labelledBy:n,children:[e.jsx(ut,{headerId:n}),e.jsx(ot,{})]}),e.jsx(ht,{})]})})]})},bt=()=>{const{slug:n}=Q(),{permissions:s=[],isLoading:i,error:a}=oe(de.map(t=>({action:t,subject:n})));return i?e.jsx(V.Loading,{}):a||!n?e.jsx(v,{height:"100vh",width:"100vw",position:"fixed",top:0,left:0,zIndex:2,background:"neutral0",children:e.jsx(V.Error,{})}):e.jsx(v,{height:"100vh",width:"100vw",position:"fixed",top:0,left:0,zIndex:2,background:"neutral0",children:e.jsx(V.Protect,{permissions:s,children:({permissions:t})=>e.jsx(Ke,{permissions:t,children:e.jsx(ft,{})})})})},It=()=>e.jsx(Qe,{children:e.jsx(Ze,{children:e.jsx(bt,{})})});export{yt as HistoryProvider,It as ProtectedHistoryPage,C as useHistoryContext};
