import{hJ as xe,fH as e,dR as J,iv as E,ay as K,dB as w,aF as ye,jD as _,ck as h,aD as p,eo as de,a$ as ce,fP as je,jG as Y,aM as be,hG as Re,iH as ue,iG as q,hi as X,iF as Me,gH as ae,ik as ee,il as De,j7 as ve,hE as Ae,bL as U,bo as se,dx as we,K as Be,iM as Ce,iQ as ge,bH as te,iY as Ie,eZ as Te,aZ as G,h0 as Pe,k as ne,d2 as Se,dN as Ee,a2 as Le,r as ke,b5 as he,iP as ze,iW as Ne,ij as Oe,j6 as We,aP as He,aQ as $e,jr as Ue,jw as Ge,cp as T,A as Fe,bV as P,c2 as _e,c1 as V,bM as Z,ft as F,f8 as Qe,gI as Ve,c6 as Ze,c5 as ie}from"./strapi-ye6TfKul.js";import{f as re}from"./index-DJ1SXY40.js";import{u as Je,a as Ye,R as Ke,g as qe,b as Xe}from"./ReleasesPage-DzhQaVs3.js";import"./index-BRVyLNfZ.js";import"./schemas-xpBv1dp3.js";import"./index-Dll6c3MH.js";const es=_(h)`
  width: 100%;
  max-width: 256px;

  & > * {
    border-bottom: 1px solid ${({theme:s})=>s.colors.neutral150};
  }

  & > *:last-child {
    border-bottom: none;
  }
`,ss=_(h)`
  svg {
    fill: currentColor;
  }
`,S=({children:s,icon:t,color:r})=>e.jsx(J.Trigger,{children:e.jsx(Y,{variant:"ghost",endIcon:e.jsx(be,{}),children:e.jsxs(ss,{color:r,gap:2,children:[t,e.jsx(p,{textColor:r,variant:"omega",fontWeight:"bold",children:s})]})})}),ts=({action:s,status:t,hasErrors:r,requiredStage:i,entryStage:u})=>{const{formatMessage:o}=E();return s==="publish"?r||i&&i.id!==u?.id?e.jsx(S,{icon:e.jsx(K,{}),color:"danger600",children:o({id:"content-releases.pages.ReleaseDetails.entry-validation.not-ready",defaultMessage:"Not ready to publish"})}):t==="draft"?e.jsx(S,{icon:e.jsx(w,{}),color:"success600",children:o({id:"content-releases.pages.ReleaseDetails.entry-validation.ready-to-publish",defaultMessage:"Ready to publish"})}):t==="modified"?e.jsx(S,{icon:e.jsx(ye,{}),color:"alternative600",children:o({id:"content-releases.pages.ReleaseDetails.entry-validation.modified",defaultMessage:"Ready to publish changes"})}):e.jsx(S,{icon:e.jsx(w,{}),color:"success600",children:o({id:"content-releases.pages.ReleaseDetails.entry-validation.already-published",defaultMessage:"Already published"})}):t==="published"?e.jsx(S,{icon:e.jsx(w,{}),color:"success600",children:o({id:"content-releases.pages.ReleaseDetails.entry-validation.ready-to-unpublish",defaultMessage:"Ready to unpublish"})}):e.jsx(S,{icon:e.jsx(w,{}),color:"success600",children:o({id:"content-releases.pages.ReleaseDetails.entry-validation.already-unpublished",defaultMessage:"Already unpublished"})})},as=({hasErrors:s,errors:t,kind:r,contentTypeUid:i,documentId:u,locale:o})=>{const{formatMessage:d}=E();return e.jsxs(h,{direction:"column",gap:1,width:"100%",padding:5,children:[e.jsxs(h,{gap:2,width:"100%",children:[e.jsx(p,{fontWeight:"bold",children:d({id:"content-releases.pages.ReleaseDetails.entry-validation.fields",defaultMessage:"Fields"})}),s?e.jsx(K,{fill:"danger600"}):e.jsx(w,{fill:"success600"})]}),e.jsx(p,{width:"100%",textColor:"neutral600",children:s?d({id:"content-releases.pages.ReleaseDetails.entry-validation.fields.error",defaultMessage:"{errors} errors on fields."},{errors:t?Object.keys(t).length:0}):d({id:"content-releases.pages.ReleaseDetails.entry-validation.fields.success",defaultMessage:"All fields are filled correctly."})}),s&&e.jsx(de,{tag:ce,to:{pathname:`/content-manager/${r==="collectionType"?"collection-types":"single-types"}/${i}/${u}`,search:o?je.stringify({plugins:{i18n:{locale:o}}}):""},variant:"secondary",fullWidth:!0,state:{forceValidation:!0},children:d({id:"content-releases.pages.ReleaseDetails.entry-validation.fields.see-errors",defaultMessage:"See errors"})})]})},ns=({contentTypeHasReviewWorkflow:s,requiredStage:t,entryStage:r})=>s?t&&t.id!==r?.id?e.jsx(K,{fill:"danger600"}):e.jsx(w,{fill:"success600"}):e.jsx(w,{fill:"neutral200"}),is=({contentTypeHasReviewWorkflow:s,requiredStage:t,entryStage:r,formatMessage:i})=>s?t&&t.id!==r?.id?i({id:"content-releases.pages.ReleaseDetails.entry-validation.review-stage.not-ready",defaultMessage:"This entry is not at the required stage for publishing. ({stageName})"},{stageName:t?.name??""}):t&&t.id===r?.id?i({id:"content-releases.pages.ReleaseDetails.entry-validation.review-stage.ready",defaultMessage:"This entry is at the required stage for publishing. ({stageName})"},{stageName:t?.name??""}):i({id:"content-releases.pages.ReleaseDetails.entry-validation.review-stage.stage-not-required",defaultMessage:"No required stage for publication"}):i({id:"content-releases.pages.ReleaseDetails.entry-validation.review-stage.not-enabled",defaultMessage:"This entry is not associated to any workflow."}),rs=({contentTypeHasReviewWorkflow:s,requiredStage:t,entryStage:r})=>{const{formatMessage:i}=E(),u=ns({contentTypeHasReviewWorkflow:s,requiredStage:t,entryStage:r});return e.jsxs(h,{direction:"column",gap:1,width:"100%",padding:5,children:[e.jsxs(h,{gap:2,width:"100%",children:[e.jsx(p,{fontWeight:"bold",children:i({id:"content-releases.pages.ReleaseDetails.entry-validation.review-stage",defaultMessage:"Review stage"})}),u]}),e.jsx(p,{textColor:"neutral600",children:is({contentTypeHasReviewWorkflow:s,requiredStage:t,entryStage:r,formatMessage:i})})]})},os=({schema:s,entry:t,status:r,action:i})=>{const{validate:u,isLoading:o}=xe({collectionType:s?.kind??"",model:s?.uid??""},{skip:!0}),d=o?null:u(t),M=d?Object.keys(d).length>0:!1,f=s?.hasReviewWorkflow??!1,m=s?.stageRequiredToPublish,D=t.strapi_stage;return o?null:e.jsxs(J.Root,{children:[e.jsx(ts,{action:i,status:r,hasErrors:M,requiredStage:m,entryStage:D}),e.jsx(J.Content,{children:e.jsxs(es,{direction:"column",children:[e.jsx(as,{hasErrors:M,errors:d,contentTypeUid:s?.uid,kind:s?.kind,documentId:t.documentId,locale:t.locale}),e.jsx(rs,{contentTypeHasReviewWorkflow:f,requiredStage:m,entryStage:D})]})})]})},ls=Re,pe=s=>typeof s<"u"&&s.name!==void 0,ds=_(h)`
  align-self: stretch;
  border-bottom-right-radius: ${({theme:s})=>s.borderRadius};
  border-bottom-left-radius: ${({theme:s})=>s.borderRadius};
  border-top: 1px solid ${({theme:s})=>s.colors.neutral150};
`,oe=({toggleEditReleaseModal:s,toggleWarningSubmit:t,children:r})=>{const{formatMessage:i,formatDate:u,formatTime:o}=E(),{releaseId:d}=ue(),{data:M,isLoading:f,error:m}=ee({id:d},{skip:!d}),[D,{isLoading:L}]=Ce(),{toggleNotification:y}=q(),{formatAPIError:j}=X(),{allowedActions:k}=ge(te),{canUpdate:B,canDelete:z,canPublish:v}=k,C=ls(),{trackUsage:b}=Ie(),n=M?.data,N=l=>async()=>{const g=await D({id:l});if("data"in g){y({type:"success",message:i({id:"content-releases.pages.ReleaseDetails.publish-notification-success",defaultMessage:"Release was published successfully."})});const{totalEntries:R,totalPublishedEntries:H,totalUnpublishedEntries:$}=g.data.meta;b("didPublishRelease",{totalEntries:R,totalPublishedEntries:H,totalUnpublishedEntries:$})}else F(g.error)?y({type:"danger",message:j(g.error)}):y({type:"danger",message:i({id:"notification.error",defaultMessage:"An error occurred"})})},x=()=>{C(Ve.util.invalidateTags([{type:"ReleaseAction",id:"LIST"},{type:"Release",id:d}]))},c=()=>n?.createdBy?n.createdBy.username?n.createdBy.username:n.createdBy.firstname?`${n.createdBy.firstname} ${n.createdBy.lastname||""}`.trim():n.createdBy.email:null;if(f)return e.jsx(U.Loading,{});if(pe(m)&&"code"in m||!n)return e.jsx(se,{to:"..",state:{errors:[{code:m?.code}]}});const O=n.actions.meta.count||0,I=!!c(),A=n.scheduledAt&&n.timezone,W=i({id:"content-releases.pages.Details.header-subtitle",defaultMessage:"{number, plural, =0 {No entries} one {# entry} other {# entries}}"},{number:O}),a=A?i({id:"content-releases.pages.ReleaseDetails.header-subtitle.scheduled",defaultMessage:"Scheduled for {date} at {time} ({offset})"},{date:u(new Date(n.scheduledAt),{weekday:"long",day:"numeric",month:"long",year:"numeric",timeZone:n.timezone}),time:o(new Date(n.scheduledAt),{timeZone:n.timezone,hourCycle:"h23"}),offset:Te(n.timezone,new Date(n.scheduledAt))}):"";return e.jsx(G.Root,{children:e.jsxs(Pe,{"aria-busy":f,children:[e.jsx(G.Header,{title:n.name,subtitle:e.jsxs(h,{gap:2,lineHeight:6,children:[e.jsx(p,{textColor:"neutral600",variant:"epsilon",children:W+(A?` - ${a}`:"")}),e.jsx(he,{...qe(n.status),children:n.status})]}),navigationAction:e.jsx(ke,{fallback:".."}),primaryAction:!n.releasedAt&&e.jsxs(h,{gap:2,children:[e.jsxs(cs,{label:e.jsx(Le,{}),variant:"tertiary",endIcon:null,paddingLeft:"7px",paddingRight:"7px","aria-label":i({id:"content-releases.header.actions.open-release-actions",defaultMessage:"Release edit and delete menu"}),popoverPlacement:"bottom-end",children:[e.jsx(ne.Item,{disabled:!B,onSelect:s,startIcon:e.jsx(Se,{}),children:i({id:"content-releases.header.actions.edit",defaultMessage:"Edit"})}),e.jsx(ne.Item,{disabled:!z,onSelect:t,variant:"danger",startIcon:e.jsx(Ee,{}),children:i({id:"content-releases.header.actions.delete",defaultMessage:"Delete"})}),e.jsxs(ds,{direction:"column",justifyContent:"center",alignItems:"flex-start",gap:1,padding:4,children:[e.jsx(p,{variant:"pi",fontWeight:"bold",children:i({id:"content-releases.header.actions.created",defaultMessage:"Created"})}),e.jsxs(p,{variant:"pi",color:"neutral300",children:[e.jsx(Ke,{timestamp:new Date(n.createdAt)}),i({id:"content-releases.header.actions.created.description",defaultMessage:"{hasCreatedByUser, select, true { by {createdBy}} other { by deleted user}}"},{createdBy:c(),hasCreatedByUser:I})]})]})]}),e.jsx(Y,{size:"S",variant:"tertiary",onClick:x,children:i({id:"content-releases.header.actions.refresh",defaultMessage:"Refresh"})}),v?e.jsx(Y,{size:"S",variant:"default",onClick:N(n.id.toString()),loading:L,disabled:n.actions.meta.count===0,children:i({id:"content-releases.header.actions.publish",defaultMessage:"Publish"})}):null]})}),r]})})},cs=_(Qe)`
  & > span {
    display: flex;
  }
`,us=["contentType","locale","action"],gs=["contentType","action"],le=s=>s==="locale"?{id:"content-releases.pages.ReleaseDetails.groupBy.option.locales",defaultMessage:"Locales"}:s==="action"?{id:"content-releases.pages.ReleaseDetails.groupBy.option.actions",defaultMessage:"Actions"}:{id:"content-releases.pages.ReleaseDetails.groupBy.option.content-type",defaultMessage:"Content-Types"},hs=({releaseId:s})=>{const{formatMessage:t}=E(),[{query:r},i]=ze(),{toggleNotification:u}=q(),{formatAPIError:o}=X(),{data:d,isLoading:M,error:f}=ee({id:s}),{allowedActions:{canUpdate:m}}=ge(te),D=Ne("ReleaseDetailsPage",a=>a.runHookWaterfall),{displayedHeaders:L,hasI18nEnabled:y}=D("ContentReleases/pages/ReleaseDetails/add-locale-in-releases",{displayedHeaders:[{label:{id:"content-releases.page.ReleaseDetails.table.header.label.name",defaultMessage:"name"},name:"name"}],hasI18nEnabled:!1}),j=d?.data,k=r?.groupBy||"contentType",{isLoading:B,isFetching:z,isError:v,data:C,error:b}=Oe({...r,releaseId:s}),[n]=We(),N=async(a,l,g)=>{const R=await n({params:{releaseId:s,actionId:l},body:{type:a.target.value},query:r,actionPath:g});"error"in R&&(F(R.error)?u({type:"danger",message:o(R.error)}):u({type:"danger",message:t({id:"notification.error",defaultMessage:"An error occurred"})}))};if(B||M)return e.jsx(U.Loading,{});const x=C?.data,c=C?.meta,O=c?.contentTypes||{};if(c?.components,pe(f)||!j){const a=[];return f&&"code"in f&&a.push({code:f.code}),b&&"code"in b&&a.push({code:b.code}),e.jsx(se,{to:"..",state:{errors:a}})}if(v||!x)return e.jsx(U.Error,{});if(Object.keys(x).length===0)return e.jsx(G.Content,{children:e.jsx(He,{action:e.jsx(de,{tag:ce,to:{pathname:"/content-manager"},style:{textDecoration:"none"},variant:"secondary",children:t({id:"content-releases.page.Details.button.openContentManager",defaultMessage:"Open the Content Manager"})}),icon:e.jsx($e,{width:"16rem"}),content:t({id:"content-releases.pages.Details.tab.emptyEntries",defaultMessage:"This release is empty. Open the Content Manager, select an entry and add it to the release."})})});const I=t({id:"content-releases.pages.ReleaseDetails.groupBy.aria-label",defaultMessage:"Group by"}),A=[...L,{label:{id:"content-releases.page.ReleaseDetails.table.header.label.content-type",defaultMessage:"content-type"},name:"content-type"},{label:{id:"content-releases.page.ReleaseDetails.table.header.label.action",defaultMessage:"action"},name:"action"},...j.releasedAt?[]:[{label:{id:"content-releases.page.ReleaseDetails.table.header.label.status",defaultMessage:"status"},name:"status"}]],W=y?us:gs;return e.jsx(G.Content,{children:e.jsxs(h,{gap:4,direction:"column",alignItems:"stretch",children:[e.jsx(h,{children:e.jsx(Ue,{placeholder:I,"aria-label":I,customizeContent:a=>t({id:"content-releases.pages.ReleaseDetails.groupBy.label",defaultMessage:"Group by {groupBy}"},{groupBy:a}),value:t(le(k)),onChange:a=>i({groupBy:a}),children:W.map(a=>e.jsx(Ge,{value:a,children:t(le(a))},a))})}),Object.keys(x).map(a=>e.jsxs(h,{gap:4,direction:"column",alignItems:"stretch",children:[e.jsx(h,{role:"separator","aria-label":a,children:e.jsx(he,{children:a})}),e.jsx(T.Root,{rows:x[a].map(l=>({...l,id:Number(l.entry.id)})),headers:A,isLoading:B||z,children:e.jsxs(T.Content,{children:[e.jsx(T.Head,{children:A.map(({label:l,name:g})=>e.jsx(T.HeaderCell,{label:t(l),name:g},g))}),e.jsx(T.Loading,{}),e.jsx(T.Body,{children:x[a].map(({id:l,contentType:g,locale:R,type:H,entry:$,status:fe},me)=>e.jsxs(Fe,{children:[e.jsx(P,{width:"25%",maxWidth:"200px",children:e.jsx(p,{ellipsis:!0,children:`${g.mainFieldValue||$.id}`})}),y&&e.jsx(P,{width:"10%",children:e.jsx(p,{children:`${R?.name?R.name:"-"}`})}),e.jsx(P,{width:"10%",children:e.jsx(p,{children:g.displayName||""})}),e.jsx(P,{width:"20%",children:j.releasedAt?e.jsx(p,{children:t({id:"content-releases.page.ReleaseDetails.table.action-published",defaultMessage:"This entry was <b>{isPublish, select, true {published} other {unpublished}}</b>."},{isPublish:H==="publish",b:Q=>e.jsx(p,{fontWeight:"bold",children:Q})})}):e.jsx(_e,{selected:H,handleChange:Q=>N(Q,l,[a,me]),name:`release-action-${l}-type`,disabled:!m})}),!j.releasedAt&&e.jsxs(e.Fragment,{children:[e.jsx(P,{width:"20%",minWidth:"200px",children:e.jsx(os,{action:H,schema:O?.[g.uid],entry:$,status:fe})}),e.jsx(P,{children:e.jsx(h,{justifyContent:"flex-end",children:e.jsxs(V.Root,{children:[e.jsx(V.ReleaseActionEntryLinkItem,{contentTypeUid:g.uid,documentId:$.documentId,locale:R?.code}),e.jsx(V.DeleteReleaseActionItem,{releaseId:j.id,actionId:l})]})})})]})]},l))})]})})]},`releases-group-${a}`)),c?.pagination?.pageCount&&c.pagination.pageCount>1&&e.jsxs(Z.Root,{...c?.pagination,defaultPageSize:c?.pagination?.pageSize,children:[e.jsx(Z.PageSize,{}),e.jsx(Z.Links,{})]})]})})},ps=()=>{const{formatMessage:s}=E(),{releaseId:t}=ue(),{toggleNotification:r}=q(),{formatAPIError:i}=X(),u=Me(),[o,d]=ae.useState(!1),[M,f]=ae.useState(!1),{isLoading:m,data:D,isSuccess:L}=ee({id:t},{skip:!t}),{data:y,isLoading:j}=De(),[k,{isLoading:B}]=ve(),[z]=Ae(),v=()=>{d(a=>!a)},C=()=>n?.timezone?n.timezone:y?.data.defaultTimezone?y.data.defaultTimezone:null,b=()=>f(a=>!a);if(m||j)return e.jsx(oe,{toggleEditReleaseModal:v,toggleWarningSubmit:b,children:e.jsx(U.Loading,{})});if(!t)return e.jsx(se,{to:".."});const n=L&&D?.data||null,N=n?.name||"",x=C(),c=n?.scheduledAt&&x?Je(n.scheduledAt,x):null,O=c?re(c,"yyyy-MM-dd"):void 0,I=c?re(c,"HH:mm"):"",A=async a=>{const l=await k({id:t,name:a.name,scheduledAt:a.scheduledAt,timezone:a.timezone});"data"in l?(r({type:"success",message:s({id:"content-releases.modal.release-updated-notification-success",defaultMessage:"Release updated."})}),v()):F(l.error)?r({type:"danger",message:i(l.error)}):r({type:"danger",message:s({id:"notification.error",defaultMessage:"An error occurred"})})},W=async()=>{const a=await z({id:t});"data"in a?u(".."):F(a.error)?r({type:"danger",message:i(a.error)}):r({type:"danger",message:s({id:"notification.error",defaultMessage:"An error occurred"})})};return e.jsxs(oe,{toggleEditReleaseModal:v,toggleWarningSubmit:b,children:[e.jsx(hs,{releaseId:t}),e.jsx(Ye,{open:o,handleClose:v,handleSubmit:A,isLoading:m||B,initialValues:{name:N||"",scheduledAt:c,date:O,time:I,isScheduled:!!c,timezone:x}}),e.jsx(we.Root,{open:M,onOpenChange:b,children:e.jsx(Be,{onConfirm:W,children:s({id:"content-releases.dialog.confirmation-message",defaultMessage:"Are you sure you want to delete this release?"})})})]})},Rs=()=>e.jsx(U.Protect,{permissions:te.main,children:e.jsxs(Ze,{children:[e.jsx(ie,{index:!0,element:e.jsx(Xe,{})}),e.jsx(ie,{path:":releaseId",element:e.jsx(ps,{})})]})});export{Rs as App};
