import{j0 as v,fH as e,bL as y,iv as P,iF as B,iY as F,gH as u,i4 as z,iA as G,iQ as K,z as Q,eo as U,bn as Y,gX as j,cp as i,aD as f,ck as $,gZ as C,a$ as V,d2 as X,dN as Z,b6 as q,dx as J,K as ee,a_ as m}from"./strapi-ye6TfKul.js";import{u as te,H as se,R as ie}from"./useReviewWorkflows-dkXrPCbU.js";import"./useDragLayer-DA6r3b6h.js";const oe=()=>{const{formatMessage:s}=P(),a=B(),{trackUsage:b}=F(),[d,c]=u.useState(null),[M,w]=u.useState(!1),{data:S,isLoading:L}=z(),{meta:n,workflows:g,isLoading:r,delete:T}=te(),{getFeature:D,isLoading:p}=G(),R=v(t=>t.admin_app.permissions.settings?.["review-workflows"]),{allowedActions:{canCreate:h,canRead:E,canUpdate:W,canDelete:A}}=K(R),l=D("review-workflows")?.[Q],I=t=>{c(t)},N=()=>{c(null)},_=async()=>{d&&(await T(d),c(null))},x=t=>{t.preventDefault(),l&&n&&n?.workflowCount>=parseInt(l,10)?(t.preventDefault(),w(!0)):(a("create"),b("willCreateWorkflow"))};u.useEffect(()=>{!r&&!p&&l&&n&&n?.workflowCount>parseInt(l,10)&&w(!0)},[p,r,n,n?.workflowCount,l]);const k=[{label:s({id:"Settings.review-workflows.list.page.list.column.name.title",defaultMessage:"Name"}),name:"name"},{label:s({id:"Settings.review-workflows.list.page.list.column.stages.title",defaultMessage:"Stages"}),name:"stages"},{label:s({id:"Settings.review-workflows.list.page.list.column.contentTypes.title",defaultMessage:"Content Types"}),name:"content-types"}];if(r||L)return e.jsx(y.Loading,{});const H=Object.values(S??{}).reduce((t,o)=>(t.push(...o),t),[]);return e.jsxs(e.Fragment,{children:[e.jsx(se,{primaryAction:h?e.jsx(U,{startIcon:e.jsx(j,{}),size:"S",tag:Y,to:"create",onClick:x,fullWidth:!0,children:s({id:"Settings.review-workflows.list.page.create",defaultMessage:"Create new workflow"})}):null,subtitle:s({id:"Settings.review-workflows.list.page.subtitle",defaultMessage:"Manage your content review process"}),title:s({id:"Settings.review-workflows.list.page.title",defaultMessage:"Review Workflows"})}),e.jsxs(ie,{children:[e.jsx(i.Root,{isLoading:r,rows:g,footer:h?e.jsx(q,{cursor:"pointer",icon:e.jsx(j,{}),onClick:x,children:s({id:"Settings.review-workflows.list.page.create",defaultMessage:"Create new workflow"})}):null,headers:k,children:e.jsxs(i.Content,{children:[e.jsx(i.Head,{children:k.map(t=>e.jsx(i.HeaderCell,{...t},t.name))}),e.jsx(i.Body,{children:g.map(t=>e.jsxs(i.Row,{onClick:()=>{a(`${t.id}`)},children:[e.jsx(i.Cell,{width:"25rem",children:e.jsx(f,{textColor:"neutral800",fontWeight:"bold",ellipsis:!0,children:t.name})}),e.jsx(i.Cell,{children:e.jsx(f,{textColor:"neutral800",children:t.stages.length})}),e.jsx(i.Cell,{children:e.jsx(f,{textColor:"neutral800",children:t.contentTypes.map(o=>H.find(O=>O.uid===o)?.info.displayName??"").join(", ")})}),e.jsx(i.Cell,{children:e.jsxs($,{alignItems:"center",justifyContent:"end",children:[E||W?e.jsx(C,{tag:V,onClick:o=>o.stopPropagation(),to:t.id.toString(),label:s({id:"Settings.review-workflows.list.page.list.column.actions.edit.label",defaultMessage:"Edit {name}"},{name:t.name}),variant:"ghost",children:e.jsx(X,{})}):null,g.length>1&&A?e.jsx(C,{withTooltip:!1,label:s({id:"Settings.review-workflows.list.page.list.column.actions.delete.label",defaultMessage:"Delete {name}"},{name:"Default workflow"}),variant:"ghost",onClick:o=>{o.stopPropagation(),I(String(t.id))},children:e.jsx(Z,{})}):null]})})]},t.id))})]})}),e.jsx(J.Root,{open:!!d,onOpenChange:N,children:e.jsx(ee,{onConfirm:_,children:s({id:"Settings.review-workflows.list.page.delete.confirm.body",defaultMessage:"If you remove this worfklow, all stage-related information will be removed for this content-type. Are you sure you want to remove it?"})})}),e.jsxs(m.Root,{open:M,onOpenChange:()=>w(!1),children:[e.jsx(m.Title,{children:s({id:"Settings.review-workflows.list.page.workflows.limit.title",defaultMessage:"You’ve reached the limit of workflows in your plan"})}),e.jsx(m.Body,{children:s({id:"Settings.review-workflows.list.page.workflows.limit.body",defaultMessage:"Delete a workflow or contact Sales to enable more workflows."})})]})]})]})},ce=()=>{const s=v(a=>a.admin_app.permissions.settings?.["review-workflows"]?.main);return e.jsx(y.Protect,{permissions:s,children:e.jsx(oe,{})})};export{ce as ProtectedListPage,oe as ReviewWorkflowsListView};
