import{aA as o,aw as y,j as e,az as I,ax as F,a9 as p,k as D,l as w,R as E,o as l,S as u,ai as q,E as T,G as k}from"./app-BgLa5dit.js";import{a as A,b as V}from"./4qGb1BIY.chunk.js";import{S as R,a as B}from"./3qXJd5bi.chunk.js";import{C as S}from"./CdBbWXza.chunk.js";const $=o.object().shape({...R,classificationId:o.string().when("step",{is:"details",then:o.string().required("Please select a classification")}),startDate:o.string().when("step",{is:"details",then:o.string().required("Please select a start date")}),endDate:o.string().when("startDate",(t,n)=>t?n.test("is-after-start-date","End date cannot be before the start date",i=>!i||new Date(i)>=new Date(t)):n).when("step",{is:"details",then:o.string().required("Please select an end date")})});function G(t){const n=y(),i=t.presentations.filter(s=>!t.mappedClassifications.some(r=>r.presentationId===s.id)).sort((s,r)=>s.description.localeCompare(r.description));return e.jsxs(I,{children:[e.jsxs(F,{as:"select",name:"presentationId",label:"Select a presentation",onChange:s=>{n.setFieldValue("presentationId",s.target.value),t.onSelectPresentation(s.target.value)},value:n.values.presentationId,children:[e.jsx("option",{value:"",disabled:!0,children:"Select a presentation"}),i.map(s=>e.jsx("option",{value:s.id,children:s.description},s.id))]}),e.jsxs(p,{children:[e.jsx(p.Cancel,{text:"Cancel",onClick:t.onClickCancel}),e.jsx(p.Submit,{type:"button",text:"Next",onClick:()=>n.setFieldValue("step","details"),variant:"dark"})]})]})}function W(t){var h;const n=D(),i=w(),[s,r]=E.useState(),c=l(S.getSpecialEvent(t.id)),d=l(u.presentations(q.Subject)),m=l(c.hasCompleted&&u.classificationsById(c.data.policies.map(a=>a.metadata.objectId))),j=l(!!s&&u.getClassificationTree(s));async function x(a,g){try{const C={status:A.Draft,presentationId:a.presentationId,startDate:a.startDate,endDate:a.endDate,frequency:a.frequency,interval:a.interval,visible:!0,metadata:{objectType:"Topic",objectId:a.classificationId}};a.startDate===a.endDate&&delete C.endDate,await n(S.addSpecialEventPolicy(t.id,C));const P=d.data.find(b=>b.id.toString()===a.presentationId.toString());i.success(`Successfully added ${c.data.name} to ${P.description}.`),t.closePopup()}catch{i.error("Failed to add to calendar. Please try again."),g()}}function v(){return{presentationId:"",classificationId:"",startDate:"",endDate:"",frequency:V.Regular,interval:null,step:"presentation"}}function f(){return!c.hasCompleted||!d.hasCompleted||!m.hasCompleted}return e.jsx(T,{title:`Add ${(h=c.data)==null?void 0:h.name} to calendar`,closePopup:t.closePopup,showLoadingSpinner:f(),backdrop:"static",children:!f()&&e.jsx(k,{initialValues:v(),onSubmit:x,validationSchema:$,children:a=>e.jsxs(e.Fragment,{children:[a.values.step==="presentation"&&e.jsx(G,{presentations:d.data,mappedClassifications:m.data,onSelectPresentation:r,onClickCancel:t.closePopup}),a.values.step==="details"&&e.jsx(e.Fragment,{children:e.jsx(B,{classificationTree:j.data,closePopup:t.closePopup,isNew:!0})})]})})})}export{W as AddToCalendarView};
//# sourceMappingURL=CAZ3IloO.chunk.js.map
