import{gN as Ce,gH as I,hP as Me,hM as Ae,fH as e,aD as V,ck as q,dZ as Pe,jD as $,bU as z,iv as B,iY as fe,h_ as F,hU as X,F as Ee,eQ as De,dI as ie,ce as Y,k as Q,a2 as Ie,gZ as he,cE as Oe,cz as Z,bd as pe,iG as me,cI as C,cQ as _e,dM as qe,gf as we,fT as be,dx as oe,b as Le,K as ve,h as Ne,eY as le,jr as ye,jw as ae,cN as ke,i4 as We,bS as Fe,j0 as xe,bL as ne,iH as $e,hi as Be,iF as Ge,iQ as He,iA as Ve,z as ze,y as Ke,an as Ue,jG as Ye,h1 as Qe,r as Ze,a_ as U,eH as Xe,e5 as se,e6 as H,e8 as te,eb as de,fp as ce}from"./strapi-ye6TfKul.js";import{D as Je,u as je,a as es,H as ss,R as ts}from"./useReviewWorkflows-dkXrPCbU.js";import"./useDragLayer-DA6r3b6h.js";const rs=Ce.injectEndpoints({endpoints(s){return{getAdminRoles:s.query({query:()=>({url:"/admin/roles",method:"GET"}),transformResponse:t=>t.data})}}}),{useGetAdminRolesQuery:os}=rs,as=(s,t,{onCancel:r,onDropItem:o,onGrabItem:p,onMoveItem:i})=>{const[c,a]=I.useState(!1),b=d=>{c&&typeof t=="number"&&i&&(d==="UP"?i(t-1,t):d==="DOWN"&&i(t+1,t))},j=()=>{c?(o&&o(t),a(!1)):(p&&p(t),a(!0))},m=()=>{c&&(a(!1),r&&r(t))};return d=>{if(s&&!(d.key==="Tab"&&!c))switch(d.preventDefault(),d.key){case" ":case"Enter":j();break;case"Escape":m();break;case"ArrowDown":case"ArrowRight":b("DOWN");break;case"ArrowUp":case"ArrowLeft":b("UP");break}}},ge={UPWARD:"upward",DOWNWARD:"downward"},re={REGULAR:"regular"},ns=(s,{type:t="STRAPI_DND",index:r,item:o,onStart:p,onEnd:i,onGrabItem:c,onDropItem:a,onCancel:b,onMoveItem:j,dropSensitivity:m=re.REGULAR})=>{const w=I.useRef(null),[{handlerId:d,isOver:M},g]=Me({accept:t,collect(n){return{handlerId:n.getHandlerId(),isOver:n.isOver({shallow:!0})}},drop(n){const u=n.index;M&&a&&a(u,r)},hover(n,u){if(!w.current||!j)return;const R=n.index,k=r,O=w.current?.getBoundingClientRect(),E=(O.bottom-O.top)/2,L=u.getClientOffset();if(!L)return;const N=L&&L.y-O.top;if(typeof R=="number"&&typeof k=="number"){if(R===k||m===re.REGULAR&&(R<k&&N<E||R>k&&N>E))return;j(k,R),n.index=k}else{if(Array.isArray(R)&&Array.isArray(k)){const J=Math.min(R.length,k.length);let W=!0,G=!1,f=!1;for(let x=0;x<J;x++)if(R[x]<k[x]){G=!0,W=!1;break}else if(R[x]>k[x]){f=!0,W=!1;break}if(W&&R.length===k.length||m===re.REGULAR&&(G&&!f&&N<E||f&&!G&&N>E))return}j(k,R),n.index=k}}}),v=n=>{if(n&&n.isDragging()&&!n.didDrop()&&n.getInitialClientOffset()&&n.getClientOffset()){const u=n.getInitialClientOffset().y-n.getClientOffset().y;return u>0?ge.UPWARD:u<0?ge.DOWNWARD:null}return null},[{isDragging:A,direction:y},_,P]=Ae({type:t,item(){p&&p();const{width:n}=w.current?.getBoundingClientRect()??{};return{index:r,width:n,...o}},end(){i&&i()},canDrag:s,isDragging:o?.id?n=>o.id===n.getItem().id:void 0,collect:n=>({isDragging:n.isDragging(),initialOffset:n.getInitialClientOffset(),currentOffset:n.getClientOffset(),direction:v(n)})}),h=as(s,r,{onGrabItem:c,onDropItem:a,onCancel:b,onMoveItem:j});return[{handlerId:d,isDragging:A,handleKeyDown:h,isOverDropTarget:M,direction:y},w,g,_,P]},is=({children:s,...t})=>e.jsx(ls,{tag:"button",background:"neutral0",borderColor:"neutral150",paddingBottom:3,paddingLeft:4,paddingRight:4,paddingTop:3,shadow:"filterShadow",...t,children:e.jsx(V,{variant:"pi",fontWeight:"bold",children:e.jsxs(q,{tag:"span",gap:2,children:[e.jsx(Pe,{width:"2.4rem",height:"2.4rem","aria-hidden":!0}),s]})})}),ls=$(z)`
  border-radius: 26px;
  color: ${({theme:s})=>s.colors.neutral500};

  &:hover {
    color: ${({theme:s})=>s.colors.primary600};
  }

  &:active {
    color: ${({theme:s})=>s.colors.primary600};
  }
`,ds=({canDelete:s=!0,canUpdate:t=!0,isCreating:r})=>{const{formatMessage:o}=B(),{trackUsage:p}=fe(),i=F("Stages",a=>a.addFieldRow),{value:c=[]}=X("stages");return e.jsxs(q,{direction:"column",gap:6,width:"100%",children:[e.jsxs(z,{position:"relative",width:"100%",children:[e.jsx(cs,{background:"neutral200",height:"100%",left:"50%",position:"absolute",top:"0",width:2}),e.jsx(q,{direction:"column",alignItems:"stretch",gap:6,position:"relative",tag:"ol",children:c.map((a,b)=>e.jsx(z,{tag:"li",children:e.jsx(gs,{index:b,canDelete:c.length>1&&s,canReorder:c.length>1,canUpdate:t,stagesCount:c.length,defaultOpen:!a.id,...a})},a.__temp_key__))})]}),t&&e.jsx(is,{type:"button",onClick:()=>{i("stages",{name:""}),p("willCreateStage")},children:o({id:"Settings.review-workflows.stage.add",defaultMessage:"Add new stage"})})]})},cs=$(z)`
  transform: translateX(-50%);
`,gs=({index:s,canDelete:t=!1,canReorder:r=!1,canUpdate:o=!1,stagesCount:p,name:i,fromPermissions:c,toPermissions:a,color:b,defaultOpen:j})=>{const[m,w]=I.useState(),{formatMessage:d}=B(),{trackUsage:M}=fe(),v=F("Stages",l=>l.errors.stages)?.[s],A=F("Stage",l=>l.addFieldRow),y=F("Stage",l=>l.moveFieldRow),_=F("Stage",l=>l.removeFieldRow),P=l=>`${l+1} of ${p}`,h=l=>{w(d({id:"dnd.grab-item",defaultMessage:"{item}, grabbed. Current position in list: {position}. Press up and down arrow to change position, Spacebar to drop, Escape to cancel."},{item:i,position:P(l)}))},n=l=>{w(d({id:"dnd.drop-item",defaultMessage:"{item}, dropped. Final position in list: {position}."},{item:i,position:P(l)}))},u=()=>{w(d({id:"dnd.cancel-item",defaultMessage:"{item}, dropped. Re-order cancelled."},{item:i}))},R=(l,T)=>{w(d({id:"dnd.reorder",defaultMessage:"{item}, moved. New position in list: {position}."},{item:i,position:P(l)})),y("stages",T,l)},[{handlerId:k,isDragging:O,handleKeyDown:E},L,N,J,W]=ns(r,{index:s,item:{index:s,name:i},onGrabItem:h,onDropItem:n,onMoveItem:R,onCancel:u,type:Je.STAGE}),G=Ee(L,N);I.useEffect(()=>{W(De(),{captureDraggingState:!1})},[W,s]);const f=()=>{A("stages",{name:i,color:b,fromPermissions:c,toPermissions:a})},x=I.useId();return e.jsxs(z,{ref:G,shadow:"tableShadow",children:[m&&e.jsx(ie,{"aria-live":"assertive",children:m}),O?e.jsx(z,{background:"primary100",borderStyle:"dashed",borderColor:"primary600",borderWidth:"1px",display:"block",hasRadius:!0,padding:6}):e.jsx(us,{onValueChange:l=>{l&&M("willEditStage")},defaultValue:j?x:void 0,$error:Object.values(v??{}).length>0,children:e.jsxs(Y.Item,{value:x,children:[e.jsxs(Y.Header,{children:[e.jsx(Y.Trigger,{children:i}),e.jsx(Y.Actions,{children:t||o?e.jsxs(e.Fragment,{children:[e.jsxs(Q.Root,{children:[e.jsxs(fs,{size:"S",endIcon:null,paddingLeft:2,paddingRight:2,children:[e.jsx(Ie,{"aria-hidden":!0,focusable:!1}),e.jsx(ie,{tag:"span",children:d({id:"[tbdb].components.DynamicZone.more-actions",defaultMessage:"More actions"})})]}),e.jsx(Q.Content,{popoverPlacement:"bottom-end",zIndex:2,children:e.jsxs(Q.SubRoot,{children:[o&&e.jsx(Q.Item,{onClick:f,children:d({id:"Settings.review-workflows.stage.delete",defaultMessage:"Duplicate stage"})}),t&&e.jsx(Q.Item,{onClick:()=>_("stages",s),variant:"danger",children:d({id:"Settings.review-workflows.stage.delete",defaultMessage:"Delete"})})]})})]}),o&&e.jsx(he,{background:"transparent",hasRadius:!0,variant:"ghost","data-handler-id":k,ref:J,label:d({id:"Settings.review-workflows.stage.drag",defaultMessage:"Drag"}),onClick:l=>l.stopPropagation(),onKeyDown:E,children:e.jsx(Oe,{})})]}):null})]}),e.jsx(Y.Content,{children:e.jsx(Z.Root,{gap:4,padding:6,children:[{disabled:!o,label:d({id:"Settings.review-workflows.stage.name.label",defaultMessage:"Stage name"}),name:`stages.${s}.name`,required:!0,size:6,type:"string"},{disabled:!o,label:d({id:"content-manager.reviewWorkflows.stage.color",defaultMessage:"Color"}),name:`stages.${s}.color`,required:!0,size:6,type:"color"},{disabled:!o,label:d({id:"Settings.review-workflows.stage.permissions.label",defaultMessage:"Roles that can change from this stage"}),name:`stages.${s}.fromPermissions`,placeholder:d({id:"Settings.review-workflows.stage.permissions.placeholder",defaultMessage:"Select a role"}),required:!0,size:6,type:"permissions"},{disabled:!o,label:d({id:"Settings.review-workflows.stage.toPermissions.label",defaultMessage:"Roles that can move content to this stage"}),name:`stages.${s}.toPermissions`,placeholder:d({id:"Settings.review-workflows.stage.toPermissions.placeholder",defaultMessage:"Select a role"}),required:!1,size:6,type:"permissions"}].map(({size:l,...T})=>e.jsx(Z.Item,{col:l,xs:12,direction:"column",alignItems:"stretch",children:e.jsx(hs,{...T})},T.name))})})]})})]})},us=$(Y.Root)`
  border: 1px solid
    ${({theme:s,$error:t})=>t?s.colors.danger600:s.colors.neutral200};
`,fs=$(Q.Trigger)`
  :hover,
  :focus {
    background-color: ${({theme:s})=>s.colors.neutral100};
  }

  > span {
    font-size: 0;
  }
`,hs=s=>{switch(s.type){case"color":return e.jsx(ps,{...s});case"permissions":return e.jsx(ms,{...s});default:return e.jsx(pe,{...s})}},ps=({disabled:s,label:t,name:r,required:o})=>{const{formatMessage:p}=B(),{value:i,error:c,onChange:a}=X(r),b=Ne.map(({hex:m,name:w})=>({value:m,label:p({id:"Settings.review-workflows.stage.color.name",defaultMessage:"{name}"},{name:w}),color:m})),{themeColorName:j}=le(i)??{};return e.jsxs(C.Root,{error:c,name:r,required:o,children:[e.jsx(C.Label,{children:t}),e.jsx(ye,{disabled:s,onChange:m=>{a(r,m.toString())},value:i?.toUpperCase(),startIcon:e.jsx(q,{tag:"span",height:2,background:i,borderColor:j==="neutral0"?"neutral150":"transparent",hasRadius:!0,shrink:0,width:2}),children:b.map(({value:m,label:w,color:d})=>{const{themeColorName:M}=le(d)||{};return e.jsx(ae,{value:m,startIcon:e.jsx(q,{tag:"span",height:2,background:d,borderColor:M==="neutral0"?"neutral150":"transparent",hasRadius:!0,shrink:0,width:2}),children:w},m)})}),e.jsx(C.Error,{})]})},ms=({label:s,disabled:t,name:r,placeholder:o,required:p})=>{const{formatMessage:i}=B(),{toggleNotification:c}=me(),[a,b]=I.useState(!1),{value:j=[],error:m,onChange:w}=X(r),d=F("PermissionsField",h=>h.values.stages),M=F("PermissionsField",h=>h.onChange),g=r.split(".").pop(),v=I.useRef(0),{data:A=[],isLoading:y,error:_}=os(),P=A?.filter(h=>h.code!=="strapi-super-admin")??[];return I.useEffect(()=>{!y&&_&&"status"in _&&_.status==403&&v.current===0&&(v.current=1,c({blockTransition:!0,type:"danger",message:i({id:"review-workflows.stage.permissions.noPermissions.description",defaultMessage:"You don’t have the permission to see roles. Contact your administrator."})}))},[i,y,A,c,_]),!y&&P.length===0?e.jsxs(C.Root,{name:r,hint:i({id:"Settings.review-workflows.stage.permissions.noPermissions.description",defaultMessage:"You don’t have the permission to see roles"}),required:p,children:[e.jsx(C.Label,{children:s}),e.jsx(_e,{disabled:!0,placeholder:i({id:"components.NotAllowedInput.text",defaultMessage:"No permissions to see this field"}),startAction:e.jsx(qe,{fill:"neutral600"}),type:"text",value:""}),e.jsx(C.Hint,{})]}):e.jsx(e.Fragment,{children:e.jsxs(q,{alignItems:"flex-end",gap:3,children:[e.jsx(bs,{grow:1,children:e.jsxs(C.Root,{error:m,name:r,required:!0,children:[e.jsx(C.Label,{children:s}),e.jsx(we,{disabled:t,onChange:h=>{const n=h.map(u=>({role:parseInt(u,10),action:"admin::review-workflows.stage.transition"}));w(r,n)},placeholder:o,value:j.map(h=>`${h.role}`),withTags:!0,children:e.jsx(be,{label:i({id:"Settings.review-workflows.stage.permissions.allRoles.label",defaultMessage:"All roles"}),values:P.map(h=>`${h.id}`),children:P.map(h=>e.jsx(ws,{value:`${h.id}`,children:h.name},h.id))})}),e.jsx(C.Error,{})]})}),e.jsxs(oe.Root,{open:a,onOpenChange:b,children:[e.jsx(oe.Trigger,{children:e.jsx(he,{disabled:t,label:i({id:"Settings.review-workflows.stage.permissions.apply.label",defaultMessage:"Apply to all stages"}),size:"L",children:e.jsx(Le,{})})}),e.jsx(ve,{onConfirm:()=>{M("stages",d.map(h=>({...h,[g]:j}))),b(!1),c({type:"success",message:i({id:"Settings.review-workflows.page.edit.confirm.stages.permissions.copy.success",defaultMessage:"Applied roles to all other stages of the workflow"})})},variant:"default",children:i({id:"Settings.review-workflows.page.edit.confirm.stages.permissions.copy",defaultMessage:"Roles that can change that stage will be applied to all the other stages."})})]})]})})},ws=$(ke)`
  padding-left: ${({theme:s})=>s.spaces[7]};
`,bs=$(q)`
  > * {
    flex-grow: 1;
  }
`,vs=({canUpdate:s=!0})=>{const{formatMessage:t}=B();return e.jsxs(Z.Root,{background:"neutral0",hasRadius:!0,gap:4,padding:6,shadow:"tableShadow",children:[e.jsx(Z.Item,{col:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsx(pe,{disabled:!s,label:t({id:"Settings.review-workflows.workflow.name.label",defaultMessage:"Workflow Name"}),name:"name",required:!0,type:"text"})}),e.jsx(Z.Item,{col:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsx(ys,{disabled:!s})}),e.jsx(Z.Item,{col:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsx(js,{disabled:!s})})]})},ys=({disabled:s})=>{const{formatMessage:t,locale:r}=B(),{data:o,isLoading:p}=We(),{workflows:i}=je(),c=F("ContentTypesSelector",g=>g.values),{error:a,value:b,onChange:j}=X("contentTypes"),m=Fe(r,{sensitivity:"base"}),w=s||p||!o||o.collectionType.length===0&&o.singleType.length===0,d=(o?.collectionType??[]).toSorted((g,v)=>m.compare(g.info.displayName,v.info.displayName)).map(g=>({label:g.info.displayName,value:g.uid})),M=(o?.singleType??[]).map(g=>({label:g.info.displayName,value:g.uid}));return e.jsxs(C.Root,{error:a,name:"contentTypes",children:[e.jsx(C.Label,{children:t({id:"Settings.review-workflows.workflow.contentTypes.label",defaultMessage:"Associated to"})}),e.jsx(we,{customizeContent:g=>t({id:"Settings.review-workflows.workflow.contentTypes.displayValue",defaultMessage:"{count} {count, plural, one {content type} other {content types}} selected"},{count:g?.length}),disabled:w,onChange:g=>{j("contentTypes",g)},value:b,placeholder:t({id:"Settings.review-workflows.workflow.contentTypes.placeholder",defaultMessage:"Select"}),children:[...d.length>0?[{label:t({id:"Settings.review-workflows.workflow.contentTypes.collectionTypes.label",defaultMessage:"Collection Types"}),children:d}]:[],...M.length>0?[{label:t({id:"Settings.review-workflows.workflow.contentTypes.singleTypes.label",defaultMessage:"Single Types"}),children:M}]:[]].map(g=>e.jsx(be,{label:g.label,values:g.children.map(v=>v.value.toString()),children:g.children.map(v=>{const{name:A}=i?.find(y=>(c&&y.id!==c.id||!c)&&y.contentTypes.includes(v.value))??{};return e.jsx(ks,{value:v.value,children:e.jsx(V,{children:t({id:"Settings.review-workflows.workflow.contentTypes.assigned.notice",defaultMessage:"{label} {name, select, undefined {} other {<i>(assigned to <em>{name}</em> workflow)</i>}}"},{label:v.label,name:A,em:(...y)=>e.jsx(V,{tag:"em",fontWeight:"bold",children:y}),i:(...y)=>e.jsx(xs,{children:y})})})},v.value)})},g.label))})]})},ks=$(ke)`
  padding-left: ${({theme:s})=>s.spaces[7]};
`,xs=$(V)`
  font-style: italic;
`,js=({disabled:s})=>{const{value:t=[]}=X("stages"),{formatMessage:r}=B(),{error:o,value:p,onChange:i}=X("stageRequiredToPublish"),c=t.filter(a=>a.name);return e.jsxs(C.Root,{error:o,name:"stageRequiredToPublish",hint:r({id:"settings.review-workflows.workflow.stageRequiredToPublish.hint",defaultMessage:"Prevents entries from being published if they are not at the required stage."}),children:[e.jsx(C.Label,{children:r({id:"settings.review-workflows.workflow.stageRequiredToPublish.label",defaultMessage:"Required stage for publishing"})}),e.jsxs(ye,{disabled:s,onChange:a=>{i("stageRequiredToPublish",a)},value:p,children:[e.jsx(ae,{value:"",children:r({id:"settings.review-workflows.workflow.stageRequiredToPublish.any",defaultMessage:"Any stage"})}),c.map((a,b)=>e.jsx(ae,{value:a.id?.toString()||a.__temp_key__,children:a.name},`requiredToPublishStage-${a.id||a.__temp_key__}`))]}),e.jsx(C.Hint,{})]})},ue=(s,t)=>s?.length!==t?.length?!0:!s?.every(r=>t?.some(o=>o.role===r.role)),Rs=se({contentTypes:te().of(H()),name:H().max(255,{id:"review-workflows.validation.name.max-length",defaultMessage:"Name can not be longer than 255 characters"}).required().nullable(),stages:te().of(se().shape({name:H().nullable().required({id:"review-workflows.validation.stage.name",defaultMessage:"Name is required"}).max(255,{id:"review-workflows.validation.stage.max-length",defaultMessage:"Name can not be longer than 255 characters"}).test("unique-name",{id:"review-workflows.validation.stage.duplicate",defaultMessage:"Stage name must be unique"},(s,t)=>{const{stages:r}=t.from[1].value;return r.filter(o=>o.name===s).length===1}),color:H().nullable().required({id:"review-workflows.validation.stage.color",defaultMessage:"Color is required"}).matches(/^#(?:[0-9a-fA-F]{3}){1,2}$/i),fromPermissions:te(se({role:de().strict().typeError({id:"review-workflows.validation.stage.permissions.role.number",defaultMessage:"Role must be of type number"}).required(),action:H().required({id:"review-workflows.validation.stage.permissions.action.required",defaultMessage:"Action is a required argument"})})).strict(),toPermissions:te(se({role:de().strict().typeError({id:"review-workflows.validation.stage.permissions.role.number",defaultMessage:"Role must be of type number"}).required(),action:H().required({id:"review-workflows.validation.stage.permissions.action.required",defaultMessage:"Action is a required argument"})})).strict()})).min(1),stageRequiredToPublish:H().nullable()}),Ss=()=>{const{id:s=""}=$e(),t=s==="create",{formatMessage:r}=B(),{_unstableFormatValidationErrors:o}=Be(),p=Ge(),{toggleNotification:i}=me(),{isLoading:c,meta:a,workflows:b,error:j,update:m,create:w}=je(),d=xe(f=>f.admin_app.permissions.settings?.["review-workflows"]),{allowedActions:{canDelete:M,canUpdate:g,canCreate:v}}=He(d),[A,y]=I.useState({}),{getFeature:_,isLoading:P}=Ve(),[h,n]=I.useState(null),u=b?.find(f=>f.id===parseInt(s,10)),R=b?.filter(f=>f.id!==parseInt(s,10)).flatMap(f=>f.contentTypes),k=_("review-workflows"),O=k?.[ze],E=k?.[Ke],L=async(f,x)=>{try{const{stageRequiredToPublish:l,...T}=f,D=l===""?null:T.stages.find(S=>S.id===Number(l)||S.__temp_key__===l)?.name;if(t){const S=await w({...T,stageRequiredToPublishName:D});"error"in S&&ce(S.error)&&S.error.name==="ValidationError"?x.setErrors(o(S.error)):"data"in S&&p(`../${S.data.id}`,{replace:!0})}else{const S=await m(s,{...T,stages:T.stages.map(K=>{const ee=u?.stages?.find(Te=>Te.id===K?.id),Re=!ee||ue(ee.fromPermissions,K.fromPermissions),Se=!ee||ue(ee.toPermissions,K.toPermissions);return{...K,fromPermissions:Re?K.fromPermissions:void 0,toPermissions:Se?K.toPermissions:void 0}}),stageRequiredToPublishName:D});"error"in S&&ce(S.error)&&S.error.name==="ValidationError"&&x.setErrors(o(S.error))}}catch{i({type:"danger",message:r({id:"notification.error",defaultMessage:"An error occurred"})})}y({})},N=(f,x)=>async()=>{await L(f,x)},J=()=>{y({})},W=async(f,x)=>{const l=f.contentTypes.some(D=>R?.includes(D)),T=!t&&!u?.stages.every(D=>f.stages.some(S=>S.id===D.id));a&&O&&a?.workflowCount>parseInt(O,10)?n("workflow"):f.stages&&E&&f.stages.length>parseInt(E,10)?n("stage"):T||l?(T&&y(D=>({...D,hasDeletedServerStages:!0})),l&&y(D=>({...D,hasReassignedContentTypes:!0}))):await L(f,x)};I.useEffect(()=>{!c&&!P&&(a&&O&&a?.workflowCount>parseInt(O,10)?n("workflow"):u&&u.stages&&E&&u.stages.length>parseInt(E,10)&&n("stage"))},[u,P,c,k,a,O,E]);const G=I.useMemo(()=>t||!u?{name:"",stages:[],contentTypes:[],stageRequiredToPublish:""}:{name:u.name,stages:Ts(u.stages),contentTypes:u.contentTypes,stageRequiredToPublish:u.stageRequiredToPublish?.id.toString()??""},[u,t]);return c?e.jsx(ne.Loading,{}):j?e.jsx(ne.Error,{}):e.jsxs(e.Fragment,{children:[e.jsx(es,{}),e.jsx(Ue,{method:t?"POST":"PUT",initialValues:G,validationSchema:Rs,onSubmit:W,children:({modified:f,isSubmitting:x,values:l,setErrors:T})=>e.jsxs(e.Fragment,{children:[e.jsx(ss,{navigationAction:e.jsx(z,{display:{initial:"none",medium:"block"},children:e.jsx(Ze,{fallback:".."})}),primaryAction:g||v?e.jsx(Ye,{startIcon:e.jsx(Qe,{}),type:"submit",disabled:!f||x||l.stages.length===0,loading:!(Object.keys(A).length>0)&&x,fullWidth:!0,children:r({id:"global.save",defaultMessage:"Save"})}):null,subtitle:r({id:"review-workflows.page.subtitle",defaultMessage:"{count, plural, one {# stage} other {# stages}}"},{count:u?.stages?.length??0}),title:u?.name||r({id:"Settings.review-workflows.create.page.title",defaultMessage:"Create Review Workflow"})}),e.jsx(ts,{children:e.jsxs(q,{alignItems:"stretch",direction:"column",gap:7,children:[e.jsx(vs,{canUpdate:g||v}),e.jsx(ds,{canDelete:M,canUpdate:g||v,isCreating:t})]})}),e.jsx(oe.Root,{open:Object.keys(A).length>0,onOpenChange:J,children:e.jsx(ve,{onConfirm:N(l,{setErrors:T}),children:e.jsxs(q,{direction:"column",gap:5,children:[A.hasDeletedServerStages&&e.jsx(V,{textAlign:"center",variant:"omega",children:r({id:"review-workflows.page.delete.confirm.stages.body",defaultMessage:"All entries assigned to deleted stages will be moved to the previous stage."})}),A.hasReassignedContentTypes&&e.jsx(V,{textAlign:"center",variant:"omega",children:r({id:"review-workflows.page.delete.confirm.contentType.body",defaultMessage:"{count} {count, plural, one {content-type} other {content-types}} {count, plural, one {is} other {are}} already mapped to {count, plural, one {another workflow} other {other workflows}}. If you save changes, {count, plural, one {this} other {these}} {count, plural, one {content-type} other {{count} content-types}} will no more be mapped to the {count, plural, one {another workflow} other {other workflows}} and all corresponding information will be removed."},{count:R?.filter(D=>l.contentTypes.includes(D)).length??0})}),e.jsx(V,{textAlign:"center",variant:"omega",children:r({id:"review-workflows.page.delete.confirm.confirm",defaultMessage:"Are you sure you want to save?"})})]})})})]})}),e.jsxs(U.Root,{open:h==="workflow",onOpenChange:()=>n(null),children:[e.jsx(U.Title,{children:r({id:"review-workflows.edit.page.workflows.limit.title",defaultMessage:"You’ve reached the limit of workflows in your plan"})}),e.jsx(U.Body,{children:r({id:"review-workflows.edit.page.workflows.limit.body",defaultMessage:"Delete a workflow or contact Sales to enable more workflows."})})]}),e.jsxs(U.Root,{open:h==="stage",onOpenChange:()=>n(null),children:[e.jsx(U.Title,{children:r({id:"review-workflows.edit.page.stages.limit.title",defaultMessage:"You have reached the limit of stages for this workflow in your plan"})}),e.jsx(U.Body,{children:r({id:"review-workflows.edit.page.stages.limit.body",defaultMessage:"Try deleting some stages or contact Sales to enable more stages."})})]})]})},Ts=s=>{const t=Xe(void 0,void 0,s.length);return s.map((r,o)=>({...r,__temp_key__:t[o]}))},Ps=()=>{const s=xe(t=>{const{create:r=[],update:o=[],read:p=[]}=t.admin_app.permissions.settings?.["review-workflows"]??{};return[...r,...o,...p]});return e.jsx(ne.Protect,{permissions:s,children:e.jsx(Ss,{})})};export{Ps as ProtectedEditPage};
