import{R as u,aJ as s,k as V,l as I,b as L,o as P,aU as v,p as k,j as n,E,a9 as c,a4 as w}from"./app-BgLa5dit.js";import{B as F}from"./CGwLt1AI.chunk.js";const O=[s.Draft,s.Published,s.Archived];function G(r){var b,S,j,g;const[A,$]=u.useState(!1),[o,d]=u.useState(s.Draft),D=V(),l=I(),{hasPermissions:h}=L(),t=P(v.getObject(r.objectId)),p=P(k.getAssemblyLineVideo(r.objectId));u.useEffect(()=>{t.hasCompleted&&d(t.data.status)},[t.hasCompleted]);function B(e){e.preventDefault(),$(!0),D(v.updateStatus(r.objectId,o)).then(()=>{var a;return l.success(`${(a=t.data)==null?void 0:a.name} has been updated to ${s[o]}`)}).catch(()=>l.error("Something went wrong.")).finally(r.closePopup)}function N(e){var a;return+e!==((a=t.data)==null?void 0:a.status)}function R(e){const a=e.target.value;d(a)}const f=t.hasCompleted&&p.hasCompleted;function m(e){var a,i;switch((a=t.data)==null?void 0:a.status){case s.Archived:return e===s.Draft;case s.Draft:return(i=p.data)!=null&&i.stage?!h(w.VideosPublish):!1;case s.Published:return e!==s.Archived;default:return!0}}function U(){var e,a,i,x,y,C;switch((e=t.data)==null?void 0:e.status){case s.Archived:return`Cannot draft an archived ${(a=t.data)==null?void 0:a.type}`;case s.Draft:return m(s.Draft)?`Please go to content pipeline to publish this ${(i=t.data)==null?void 0:i.type}. Cannot archive a draft ${(x=t.data)==null?void 0:x.type}.`:h(w.VideosPublish)?"":`This ${(y=t.data)==null?void 0:y.type} is not in the content pipeline, so it may be published.`;case s.Published:return`Cannot draft a published ${(C=t.data)==null?void 0:C.type}`;default:return""}}return n.jsx(E,{title:`Update ${(b=t.data)==null?void 0:b.type} status`,closePopup:r.closePopup,showLoadingSpinner:!f,children:f&&n.jsxs("form",{onSubmit:e=>B(e),children:[n.jsxs("div",{className:"form-group",children:[n.jsxs("p",{children:["This ",(S=t.data)==null?void 0:S.type," is currently set to: ",n.jsxs("span",{className:`badge ${F.getStatusBadgeClass((j=t.data)==null?void 0:j.status)}`,children:[" ",s[(g=t.data)==null?void 0:g.status]]})]}),n.jsx("label",{htmlFor:"status",children:"Select new status:"}),n.jsx("select",{id:"status",className:"form-control",onChange:R,value:o,children:O.map((e,a)=>n.jsx("option",{value:e,disabled:m(e),children:s[e]},a))}),n.jsx("small",{className:"text-secondary",children:U()})]}),n.jsxs(c,{children:[n.jsx(c.Cancel,{onClick:r.closePopup}),n.jsx(c.Submit,{text:"Update status",variant:"dark",disabled:!N(o),showSpinner:A})]})]})})}export{G as UpdateObjectStatusView};
//# sourceMappingURL=Uw8rPfar.chunk.js.map
