@outbuild-company/schedule-core 1.13.3 → 1.13.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/schedule-core.global.js +1 -1
- package/dist/cdn/schedule-core.global.js.map +1 -1
- package/dist/index.cjs +35 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +35 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var ScheduleCore=(()=>{var Vn=Object.defineProperty;var yf=Object.getOwnPropertyDescriptor;var hf=Object.getOwnPropertyNames;var mf=Object.prototype.hasOwnProperty;var If=(e,t)=>{for(var r in t)Vn(e,r,{get:t[r],enumerable:!0})},gf=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of hf(t))!mf.call(e,n)&&n!==r&&Vn(e,n,{get:()=>t[n],enumerable:!(i=yf(t,n))||i.enumerable});return e};var Af=e=>gf(Vn({},"__esModule",{value:!0}),e);var jA={};If(jA,{ACTIVITY_BATCH_ACTION_KIND:()=>ue,ACTIVITY_BATCH_MODE:()=>pt,ACTIVITY_DATE_EDGE:()=>Pr,ACTIVITY_FIELD:()=>It,ACTIVITY_PONDERATOR_CRITERION:()=>gt,ACTIVITY_PROGRESS_ORIGIN:()=>Wi,ACTIVITY_TYPE:()=>D,CALENDAR_UNIT:()=>mt,CHANGE_SET_SOURCE_KIND:()=>oe,COLUMN:()=>_,COMPLETED_PROGRESS:()=>br,CONSTRAINT_TYPE:()=>A,CONSTRAINT_TYPE_TO_LABEL:()=>df,CONSTRAINT_WARNING_KIND:()=>ji,CREATION_KIND:()=>ff,DATE_GESTURE_KIND:()=>_r,DEFAULT_HOURS_PER_DAY:()=>uf,DISPATCH_ACTION_KIND:()=>m,DISPATCH_ACTION_KINDS:()=>Xa,DISPATCH_LINK_OPERATION_KIND:()=>at,DISPATCH_TRACK_EVENT:()=>Kt,EDIT_ALERT_KEY:()=>oc,EDIT_DENIAL_REASON:()=>Wr,ENTITY_CHANGE_KIND:()=>N,FILTER_FIELD:()=>Y,FILTER_LOGIC:()=>li,FILTER_OPERATOR:()=>W,FILTER_REJECTION_REASON:()=>vt,FILTER_VALUE_KIND:()=>O,LINK_BATCH_OPERATION_KIND:()=>qe,LINK_CODE:()=>Ct,LINK_CODE_TO_TYPE:()=>Ne,LINK_REJECTION_REASON:()=>At,LINK_RELATIONSHIP:()=>ke,LINK_TYPE:()=>H,LINK_TYPE_CODE:()=>Ei,NEW_ACTIVITY_DEFAULTS:()=>ln,NOT_STARTED_PROGRESS:()=>Ds,ORDER_DIRECTION:()=>Pe,REJECTION_REASON:()=>C,ROOT_PARENT_ID:()=>V,SCHEDULE_CORE_STATUS:()=>Zt,SCHEDULE_EFFECT_KIND:()=>Vi,SIR_AUTO_REJECT_REASON:()=>Ki,STATUS:()=>_t,STATUS_CRITERIA:()=>de,ScheduleCore:()=>kr,WORK_TIME_DIRECTION:()=>K,checkNoUpdatedLinks:()=>vu,computeExpectedProgress:()=>Co,createSchedule:()=>cf,expectedProgressFromBaseline:()=>dr,getActiveBaseline:()=>kt,getUnsavedActivities:()=>lf,isRootParent:()=>M,normalizeParentKey:()=>Gt,parseFromBackend:()=>Fn,willRunCriticalPath:()=>Zd,yieldToBrowser:()=>st});var D={TASK:"task",PROJECT:"project",MILESTONE:"milestone"},vf=Object.values(D);function Kn(e){return vf.includes(e)}var ni={CONSTRAINT:"constraint",ALERT:"alert",WARNING:"warning"},K={FUTURE:"future",PAST:"past"},mt={HOUR:"hour",DAY:"day"},gt={DURATION:"DURATION",COST:"COST",WORK_HOURS:"HH"},de={BASELINE:"Baseline",ACTUAL:"Actual"},_t={DONE:"Done",OVERDUE:"Overdue",ADVANCEMENT:"Advancement",WAITING:"Waiting",DOING:"Doing"},N={CREATED:"created",UPDATED:"updated",DELETED:"deleted"};var A={ASAP:"asap",ALAP:"alap",SNET:"snet",SNLT:"snlt",FNET:"fnet",FNLT:"fnlt",MSO:"mso",MFO:"mfo"},Cf={[A.MSO]:()=>!0,[A.MFO]:()=>!0,[A.SNLT]:(e,t)=>e<t,[A.SNET]:(e,t)=>e>t,[A.FNLT]:(e,t)=>e<t,[A.FNET]:(e,t)=>e>t};function $a(e,t,r){if(!t)return{violated:!1};let i=Cf[e];return i?i(t,r)?{violated:!0,constraintType:e,constraintDate:t}:{violated:!1}:{violated:!1}}var Sf=new Set([A.MSO,A.SNET,A.SNLT]);function Rr(e,t,r){return Sf.has(e)?t:r}function za(e,t,r){return{type:ni.CONSTRAINT,messageKey:"constraint_violation",data:{constraintType:e,constraintDate:t,...r?{projectedDate:r}:{}}}}var Tf={[A.SNET]:{startOfDay:!0,direction:K.FUTURE},[A.SNLT]:{startOfDay:!0,direction:K.PAST},[A.FNET]:{startOfDay:!1,direction:K.FUTURE},[A.FNLT]:{startOfDay:!1,direction:K.PAST},[A.MSO]:{startOfDay:!0,direction:K.FUTURE},[A.MFO]:{startOfDay:!1,direction:K.PAST}},oi=e=>new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())),Ga=(e,t)=>new Date(e.getTime()+t*864e5),Ef=(e,t)=>e.getUTCFullYear()===t.getUTCFullYear()&&e.getUTCMonth()===t.getUTCMonth()&&e.getUTCDate()===t.getUTCDate();function jn(e,t){if(!e.constraintDate||!e.constraintType)return null;let r=Tf[e.constraintType];if(!r)return e.constraintDate;let i=e.constraintDate,n=t.getClosestWorkTime({date:oi(i),dir:K.FUTURE,task:e});if(Ef(n,i))return i.getTime()!==oi(i).getTime()?i:r.startOfDay?n:t.getClosestWorkTime({date:Ga(oi(i),1),dir:K.PAST,task:e});let o=oi(t.getClosestWorkTime({date:i,dir:r.direction,task:e}));return r.startOfDay?t.getClosestWorkTime({date:o,dir:K.FUTURE,task:e}):t.getClosestWorkTime({date:Ga(o,1),dir:K.PAST,task:e})}function qa(e,t){let r={earliestStart:null,latestStart:null,earliestEnd:null,latestEnd:null},i=e.constraintType;if(!i||i===A.ASAP||i===A.ALAP)return r;let n=jn(e,t);if(!n)return r;let o=s=>t.calculateEndDate({startDate:s,durationHours:e.durationHours,task:e}),a=s=>t.calculateEndDate({startDate:s,durationHours:-e.durationHours,task:e});switch(i){case A.SNET:return{earliestStart:n,latestStart:null,earliestEnd:o(n),latestEnd:null};case A.SNLT:return{earliestStart:null,latestStart:n,earliestEnd:null,latestEnd:o(n)};case A.FNET:return{earliestStart:a(n),latestStart:null,earliestEnd:n,latestEnd:null};case A.FNLT:return{earliestStart:null,latestStart:a(n),earliestEnd:null,latestEnd:n};case A.MSO:{let s=o(n);return{earliestStart:n,latestStart:n,earliestEnd:s,latestEnd:s}}case A.MFO:{let s=a(n);return{earliestStart:s,latestStart:s,earliestEnd:n,latestEnd:n}}default:return r}}function Ja(e,t){return!(t.earliestStart&&e<t.earliestStart||t.latestStart&&e>t.latestStart)}function Yn(e,t){return t.latestStart&&e>t.latestStart?t.latestStart:t.earliestStart&&e<t.earliestStart?t.earliestStart:e}var H={FINISH_TO_START:"0",START_TO_START:"1",FINISH_TO_FINISH:"2",START_TO_FINISH:"3"},Df=Object.values(H);function ai(e){return Df.includes(e)}var _f={TEXT:"text",DESCRIPTION:"description",DURATION:"duration",PROGRESS:"progress",COST:"cost",USED_COST:"used_cost",HH_WORK_TIME:"hhWorkTime",START_DATE:"start_date",END_DATE:"end_date",CONSTRAINT_TYPE:"constraint_type",CONSTRAINT_DATE:"constraint_date",CALENDAR_ID:"calendar_id",CUSTOM_ID:"custom_id",SUBCONTRACT_ID:"subcontractId",RESPONSABLES:"responsables",TAGS:"tags",CUSTOM_PREDECESSORS:"custom_predecessors",CUSTOM_SUCESSORS:"custom_sucessors"},kf={REAL_WORK:"real_work",REAL_COST:"real_cost",EXPECTED_PROGRESS:"expected_progress",EXPECTED_PROGRESS_BASE:"expected_progress_base",START_BASE:"start_base",END_BASE:"end_base",DURATION_BASE:"duration_base",COST_BASE:"cost_base",WORK_BASE:"work_base",CALENDAR_DURATION:"calendarDuration",IS_CRITICAL:"is_critical",EARLY_START:"earlyStart",EARLY_FINISH:"earlyFinish",LATE_START:"lateStart",LATE_FINISH:"lateFinish",FREE_SLACK:"freeSlack",TOTAL_SLACK:"totalSlack",CORRELATIVE_ID:"correlative_id",UNIQUE_CORRELATIVE_ID:"unique_correlative_id",PONDERATOR:"ponderator",STATUS:"status"},_={..._f,...kf};var dt={CREATE:"create",UPDATE:"update",DELETE:"delete"},At={SELF_LINK:"self-link",CYCLE:"cycle",DUPLICATE:"duplicate",ACTIVITY_MISSING:"activity-missing",LINK_MISSING:"link-missing",HIERARCHY_LINK:"hierarchy-link"};var m={ACTIVITY_CLIPBOARD_CLEAR:"activity-clipboard-clear",ACTIVITY_COPY:"activity-copy",CALENDAR_RECONCILE:"calendar-reconcile",ACTIVITY_PASTE_COPIED:"activity-paste-copied",PERSISTENCE_ACKNOWLEDGE:"persistence-acknowledge",BASELINE_APPLY:"baseline-apply",PONDERATOR_CRITERION_SET:"ponderator-criterion-set",STATUS_CRITERIA_SET:"status-criteria-set",INLINE_EDIT:"inline-edit",DATES_BATCH:"dates-batch",BULK_EDIT:"bulk-edit",LINK_CREATE:"link-create",LINK_UPDATE:"link-update",LINK_DELETE:"link-delete",LINKS_BATCH:"links-batch",ACTIVITY_CREATE:"activity-create",ACTIVITY_DELETE:"activity-delete",ACTIVITY_MOVE:"activity-move",ACTIVITY_INDENT:"activity-indent",ACTIVITY_OUTDENT:"activity-outdent",ACTIVITY_SET_PROGRESS:"activity-set-progress",ACTIVITY_LOOKAHEAD_CONVERT:"activity-lookahead-convert",SELECTION_TOGGLE:"selection-toggle",SELECTION_REPLACE:"selection-replace",VISIBILITY_SET:"visibility-set",FILTER_SET:"filter-set",SORT_SET:"sort-set",SIR_SYNC:"sir-sync",ACTIVITY_LOOKAHEAD_SYNC:"activity-lookahead-sync"},ue="activity-batch",at=dt,Xa=Object.values(m);function kt(e){let t=e?.baselinePoints;return!Array.isArray(t)||t.length===0?null:t.find(r=>r.isActiveVersion)??null}var It={NAME:"name",DESCRIPTION:"description",DURATION_DAYS:"durationDays",PROGRESS:"progress",COST:"cost",USED_COST:"usedCost",WORK_HOURS:"workHours",START_DATE:"startDate",END_DATE:"endDate",CONSTRAINT_TYPE:"constraintType",CONSTRAINT_DATE:"constraintDate",CALENDAR_ID:"calendarId",CUSTOM_ID:"customId",SUBCONTRACT_ID:"subcontractId",RESPONSABLE_IDS:"responsableIds",TAG_IDS:"tagIds"},Pr={START:"start",END:"end"},ke={FINISH_TO_START:"finish-to-start",START_TO_START:"start-to-start",FINISH_TO_FINISH:"finish-to-finish",START_TO_FINISH:"start-to-finish"},qe={CREATE:"create",UPDATE:"update",REMOVE:"remove"};var Rf={[It.NAME]:_.TEXT,[It.DESCRIPTION]:_.DESCRIPTION,[It.DURATION_DAYS]:_.DURATION,[It.PROGRESS]:_.PROGRESS,[It.COST]:_.COST,[It.USED_COST]:_.USED_COST,[It.WORK_HOURS]:_.HH_WORK_TIME,[It.START_DATE]:_.START_DATE,[It.END_DATE]:_.END_DATE,[It.CONSTRAINT_TYPE]:_.CONSTRAINT_TYPE,[It.CONSTRAINT_DATE]:_.CONSTRAINT_DATE,[It.CALENDAR_ID]:_.CALENDAR_ID,[It.CUSTOM_ID]:_.CUSTOM_ID,[It.SUBCONTRACT_ID]:_.SUBCONTRACT_ID,[It.RESPONSABLE_IDS]:_.RESPONSABLES,[It.TAG_IDS]:_.TAGS};function Gn(e,t){return{activityId:e,column:Rf[t.field],newValue:t.value}}var Pf={[ke.FINISH_TO_START]:H.FINISH_TO_START,[ke.START_TO_START]:H.START_TO_START,[ke.FINISH_TO_FINISH]:H.FINISH_TO_FINISH,[ke.START_TO_FINISH]:H.START_TO_FINISH};function Lr(e){return Pf[e]}function Lf(e){return e.kind===qe.CREATE?{kind:at.CREATE,source:e.sourceId,target:e.targetId,type:Lr(e.relationship),...e.lagDays===void 0?{}:{lag:e.lagDays},...e.linkId===void 0?{}:{linkId:e.linkId}}:e.kind===qe.UPDATE?{kind:at.UPDATE,linkId:e.linkId,...e.relationship===void 0?{}:{type:Lr(e.relationship)},...e.lagDays===void 0?{}:{lag:e.lagDays}}:e.kind===qe.REMOVE?{kind:at.DELETE,linkId:e.linkId}:e}function Of(e){return e===Pr.START?_.START_DATE:e===Pr.END?_.END_DATE:e}function Nf(e){return{kind:ue,mode:e.mode,items:e.items,links:e.links.map(t=>({source:t.source,target:t.target,type:Lr(t.relationship),...t.lagDays===void 0?{}:{lag:t.lagDays},...t.linkId===void 0?{}:{linkId:t.linkId}})),...e.eventSource===void 0?{}:{eventSource:e.eventSource}}}function bf(e){return{get:t=>e.getActivityView(t),list:()=>e.getAllActivitiesView(),ids:()=>e.getAllIds(),forEachId:t=>e.forEachActivityId(t),property:(t,r)=>e.getProperty(t,r),children:t=>e.getChildrenView(t),childIds:t=>e.getChildrenIds(t),hasChildren:t=>e.hasChild(t),indentTargetParentIds:t=>e.getIndentTargetParentIds(t),isCustomIdInUse:(t,r)=>e.isCustomIdInUse(t,r??null),create:(t,r)=>e.dispatch({...t,kind:m.ACTIVITY_CREATE},r),applyBatch:(t,r)=>e.applyActivityBatch(Nf(t),r),editInline:(t,r,i)=>e.dispatch({...Gn(t,r),kind:m.INLINE_EDIT},i),applyDragBatch:(t,r)=>e.dispatch({kind:m.DATES_BATCH,edits:t.map(i=>({activityId:i.activityId,column:Of(i.edge),newValue:i.value}))},r),editFields:(t,r)=>e.dispatch({kind:m.BULK_EDIT,edits:t.map(i=>Gn(i.activityId,i))},r),remove:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_DELETE,activityIds:t}),move:(t,r)=>e.dispatch({...t,kind:m.ACTIVITY_MOVE},r),planLookaheadConversion:t=>e.planLookaheadConversion(t),applyLookaheadConversion:t=>e.applyLookaheadConversion(t),indent:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_INDENT,activityIds:t}),outdent:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_OUTDENT,activityIds:t}),setProgress:(t,r,i={})=>e.dispatch({...i,kind:m.ACTIVITY_SET_PROGRESS,activityId:t,newValue:r}),copy:(t={})=>e.dispatch({...t,kind:m.ACTIVITY_COPY}),paste:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_PASTE_COPIED,destination:{afterSiblingId:t}}),clearClipboard:(t={})=>e.dispatch({...t,kind:m.ACTIVITY_CLIPBOARD_CLEAR}),lookaheadSync:t=>e.dispatch({...t,kind:m.ACTIVITY_LOOKAHEAD_SYNC}),createDateGesturePreview:t=>e.createDateGesturePreview(t)}}function Ff(e){return{get:t=>e.getLinkView(t),list:()=>e.getAllLinksView(),forActivity:t=>e.getLinksForActivityView(t),create:(t,r)=>e.dispatch({kind:m.LINK_CREATE,source:t.sourceId,target:t.targetId,type:Lr(t.relationship),...t.lagDays===void 0?{}:{lag:t.lagDays},...t.linkId===void 0?{}:{linkId:t.linkId}},r),update:(t,r,i)=>e.dispatch({kind:m.LINK_UPDATE,linkId:t,...r.relationship===void 0?{}:{type:Lr(r.relationship)},...r.lagDays===void 0?{}:{lag:r.lagDays}},i),remove:(t,r)=>e.dispatch({kind:m.LINK_DELETE,linkId:t},r),batch:(t,r)=>e.dispatch({kind:m.LINKS_BATCH,operations:t.map(Lf)},r)}}function Za(e){let t=(r,i)=>e.dispatch({kind:m.BASELINE_APPLY,points:r},i);return{activities:bf(e),links:Ff(e),calendars:{get:r=>e.getCalendar(r),list:()=>e.getAllCalendars(),listBase:()=>e.getBaseCalendars(),projectWorkHours:()=>e.getProjectWorkHours(),reconcile:r=>e.dispatch({kind:m.CALENDAR_RECONCILE},r)},selection:{ids:()=>e.getSelectedActivityIds(),toggle:({checked:r,...i})=>e.dispatch({...i,kind:m.SELECTION_TOGGLE,isChecked:r}),replace:(r,i={})=>e.dispatch({...i,kind:m.SELECTION_REPLACE,activityIds:r})},view:{hiddenActivityIds:()=>e.getHiddenActivityIds(),visibleActivityIds:()=>e.getVisibleActivityIds(),visualOrderIds:()=>e.getVisualOrderIds(),filter:()=>e.getActiveFilter(),setFilter:r=>e.dispatch({...r,kind:m.FILTER_SET}),order:()=>e.getActiveOrder(),setOrder:(r,i={})=>e.dispatch({...i,kind:m.SORT_SET,rules:r}),setVisibility:(r,i={})=>e.dispatch({...i,kind:m.VISIBILITY_SET,visibleIds:r}),setStatusCriteria:(r,i)=>e.dispatch({kind:m.STATUS_CRITERIA_SET,criteria:r},i)},baselines:{refresh:t,setVisibility:t,setPonderatorCriterion:(r,i)=>e.dispatch({kind:m.PONDERATOR_CRITERION_SET,criterion:r},i),activeFor:r=>kt(r)},impactRequests:{sync:r=>e.dispatch({...r,kind:m.SIR_SYNC})},persistence:{hasChanges:()=>e.hasUnsavedChanges(),modifiedActivities:()=>e.getModifiedActivities(),modifiedActivityFields:()=>e.getModifiedActivityFields(),newActivities:()=>e.getNewActivities(),deletedActivities:()=>e.getDeletedActivitiesSinceLastSave(),modifiedLinks:()=>e.getModifiedLinks(),newLinks:()=>e.getNewLinks(),deletedLinks:()=>e.getDeletedLinksSinceLastSave(),captureHistoryBoundary:()=>e.capturePersistenceHistoryBoundary(),readSnapshot:()=>({activities:e.getAllActivitiesView(),links:e.getAllLinksView(),historyBoundary:e.capturePersistenceHistoryBoundary()}),acknowledge:r=>e.dispatch({kind:m.PERSISTENCE_ACKNOWLEDGE,checkpoint:r})},history:{undo:r=>e.undo(r),redo:r=>e.redo(r),canUndo:()=>e.canUndo(),canRedo:()=>e.canRedo(),clear:()=>e.clearHistory(),depth:()=>e.undoDepth()},projection:{changeSetFrom:r=>e.createProjectionChangeSetFrom(r)},criticalPath:{get ready(){return e.criticalPathReady},recompute:()=>e.recomputeCriticalPath(),isSettled:()=>e.isCriticalPathSettled(),whenSettled:()=>e.whenCriticalPathSettled()},diagnostics:{auditEffectiveGraph:()=>e.auditEffectiveGraph(),revision:()=>e.getScheduleRevision(),stateRevision:()=>e.getStateRevision(),canonicalDigest:()=>e.getCanonicalDigest()}}}var xt=class{items=[];head=0;enqueue(t){this.items.push(t)}dequeue(){if(this.head>=this.items.length)return;let t=this.items[this.head];return this.head+=1,t}peek(){if(!(this.head>=this.items.length))return this.items[this.head]}get size(){return this.items.length-this.head}isEmpty(){return this.head>=this.items.length}};var si=e=>String(e);function Qa(e){let{clickedId:t,isChecked:r,currentSelection:i,hierarchy:n,isFrozen:o,exists:a,autoCheckParents:s}=e,c=si(t),l=new Set([...i].map(String)),d=new Set(l),u=wf(c,n).filter(a),f=u.filter(y=>!o(y)),p=r&&f.length<u.length;r&&!p?d.add(c):d.delete(c);for(let y of f)r?d.add(y):d.delete(y);return p||xf({id:c,isChecked:r,autoCheckParents:s,hierarchy:n,isFrozen:o,exists:a,next:d}),{nextSelection:d,changed:Mf(l,d),parentBlocked:p}}function wf(e,t){let r=[],i=new xt;i.enqueue(e);let n=new Set([e]);for(;!i.isEmpty();){let o=i.dequeue();for(let a of t.getChildrenIds(o)){let s=si(a);n.has(s)||(n.add(s),r.push(s),i.enqueue(s))}}return r}function xf(e){let{id:t,isChecked:r,autoCheckParents:i,hierarchy:n,isFrozen:o,exists:a,next:s}=e,c=n.getParentId(t);for(;c!==null&&typeof c<"u";){let l=si(c);if(o(l))return;let d=n.getChildrenIds(l).map(si).filter(a),u=d.some(o),f=d.filter(I=>!o(I)),y=f.length>0&&f.every(I=>s.has(I))&&!u;if(r){if(!i||!y||s.has(l))return;s.add(l)}else{if(y||!s.has(l))return;s.delete(l)}c=n.getParentId(l)}}function Mf(e,t){let r=[],i=[];for(let n of t)e.has(n)||r.push(n);for(let n of e)t.has(n)||i.push(n);return{checked:r,unchecked:i}}function Je(e){return(e.pendingRequestIds?.length??0)>0}var C={CANNOT_EDIT:"cannot_edit",PARSE_ERROR:"parse_error",INVALID:"invalid",CUSTOM_ID_DUPLICATE:"custom_id_duplicate",INVALID_LINK_TYPE:"invalid_link_type",INVALID_LINK_LAG:"invalid_link_lag",INVALID_VALUE:"invalid_value",NO_PIPELINE_FOR_COLUMN:"no_pipeline_for_column",ACTIVITY_NOT_FOUND:"activity_not_found",PARENT_NOT_FOUND:"parent_not_found",ACTIVITY_IDS_EMPTY:"activity_ids_empty",NO_ACTIVITY_SELECTION:"no_activity_selection",CLIPBOARD_EMPTY:"clipboard_empty",ACTIVITY_PASTE_INVARIANT_FAILED:"activity_paste_invariant_failed",ANCHOR_SIBLING_CONFLICT:"anchor_sibling_conflict",ANCHOR_SIBLING_NOT_FOUND:"anchor_sibling_not_found",ANCHOR_SIBLING_WRONG_PARENT:"anchor_sibling_wrong_parent",PARENT_FROZEN_BY_SIR:"parent_frozen_by_sir",CANNOT_MOVE_INTO_OWN_DESCENDANT:"cannot_move_into_own_descendant",INDENT_NO_ELIGIBLE_SIBLING:"indent_no_eligible_sibling",OUTDENT_ROOT_LEVEL_NOT_EDITABLE:"outdent_root_level_not_editable",HIERARCHY_CYCLE:"hierarchy_cycle",SANDBOX_PERSISTENCE_FORBIDDEN:"sandbox_persistence_forbidden",STALE_STATE_REVISION:"stale-state-revision",INVALID_PROGRESS_VALUE:"invalid_progress_value_must_be_0_or_100"};var ts=(e,t)=>{let r=e.getActivity(t);return r!=null&&Je(r)},es=(e,t,r)=>{let i=[],n=(o,a)=>{let s=t.isChecked(o);t.setChecked(o,a)&&i.push({activityId:o,checked:{before:s,after:a}})};for(let o of r.checked)n(o,!0);for(let o of r.unchecked)n(o,!1);return{source:e,activities:[],links:[],calendars:[],trackingEvents:[],viewState:i}};function rs(e,t){let{adapter:r}=t,i=e.activityId;if(!r.getActivity(i))return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let n=e.frozenIds?new Set(e.frozenIds):null,o=n?s=>n.has(s):s=>ts(r,s),a=Qa({clickedId:i,isChecked:e.isChecked,currentSelection:new Set(r.checkedIds().map(String)),hierarchy:{getChildrenIds:s=>r.getChildren(s),getParentId:s=>{let c=r.getParentId(s);return!c||c==="0"?null:String(c)}},isFrozen:o,exists:s=>r.activityExists(s),autoCheckParents:e.autoCheckParents??!1});return{ok:!0,changes:es(e,r,a.changed)}}function ci(e,t){let{adapter:r}=t,i=new Set(e.activityIds.map(String).filter(a=>r.activityExists(a)).filter(a=>!ts(r,a))),n=new Set(r.checkedIds().map(String)),o={checked:[...i].filter(a=>!n.has(a)),unchecked:[...n].filter(a=>!i.has(a))};return{ok:!0,changes:es(e,r,o)}}function Xe(e,t,r=e.getAllIds()){let i=[];for(let n of r){let o=String(n),a=t.has(o),s=e.isVisible(o);s!==a&&(e.setVisible(o,a),i.push({activityId:o,visible:{before:s,after:a}}))}return i}function is(e,t){let{adapter:r}=t,i=new Set(e.visibleIds.map(String)),n=Xe(r,i);return{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[],viewState:n}}}var ns={ALAP_DEBOUNCE_MS:1e3,CRITICAL_PATH_DEBOUNCE_MS:1e3,YIELD_SLICE_MS:8};var O={STRING:"string",NUMBER:"number",DATE:"date",ID_ARRAY:"id-array",ENUM:"enum",BOOLEAN:"boolean",REFERENCE:"reference"},Y={NAME:"name",DESCRIPTION:"description",CUSTOM_ID:"customId",CORRELATIVE_ID:"correlativeId",UNIQUE_CORRELATIVE_ID:"uniqueCorrelativeId",PROGRESS:"progress",DURATION_DAYS:"durationDays",CALENDAR_DURATION:"calendarDuration",COST:"cost",USED_COST:"usedCost",REAL_COST:"realCost",WORK_HOURS:"workHours",REAL_WORK_HOURS:"realWorkHours",PONDERATOR:"ponderator",FREE_SLACK_DAYS:"freeSlackDays",TOTAL_SLACK_DAYS:"totalSlackDays",EXPECTED_PROGRESS_BASELINE:"expectedProgressBaseline",BASELINE_DURATION_DAYS:"baselineDurationDays",BASELINE_COST:"baselineCost",BASELINE_WORK_HOURS:"baselineWorkHours",EXPECTED_PROGRESS:"expectedProgress",START_DATE:"startDate",END_DATE:"endDate",CONSTRAINT_DATE:"constraintDate",BASELINE_START_DATE:"baselineStartDate",BASELINE_END_DATE:"baselineEndDate",EARLY_START:"earlyStart",EARLY_FINISH:"earlyFinish",LATE_START:"lateStart",LATE_FINISH:"lateFinish",RESPONSABLE_IDS:"responsableIds",TAG_IDS:"tagIds",STATUS:"status",CONSTRAINT_TYPE:"constraintType",CALENDAR_ID:"calendarId",SUBCONTRACT_ID:"subcontractId",IS_CRITICAL:"isCritical"},W={INCLUDES:"includes",NOT_INCLUDES:"notIncludes",IS:"is",IS_NOT:"isNot",EQUALS:"equals",NOT_EQUALS:"notEquals",GREATER_THAN:"greaterThan",LESS_THAN:"lessThan",GREATER_OR_EQUAL:"greaterOrEqual",LESS_OR_EQUAL:"lessOrEqual",AFTER:"after",BEFORE:"before",BETWEEN:"between",SOME_OF:"someOf",NOT_SOME_OF:"notSomeOf"},li={AND:"and",OR:"or"};var Uf=2,Bf=[_t.WAITING,_t.DONE,_t.DOING,_t.OVERDUE,_t.ADVANCEMENT],Hf=[A.MFO,A.MSO,A.SNLT,A.SNET,A.ALAP,A.ASAP,A.FNET,A.FNLT],Wf=1e3*60*60*24;function $n(e,t){return e===null||t<=0?null:e/t}function Vf(e,t){let r=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()),i=Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate());return Math.floor((i-r)/Wf)+1}var Kf={[Y.NAME]:{valueKind:O.STRING,extract:e=>e.name},[Y.DESCRIPTION]:{valueKind:O.STRING,extract:e=>e.description},[Y.CUSTOM_ID]:{valueKind:O.STRING,extract:e=>e.customId},[Y.CORRELATIVE_ID]:{valueKind:O.NUMBER,extract:e=>e.correlativeId},[Y.UNIQUE_CORRELATIVE_ID]:{valueKind:O.NUMBER,extract:e=>{let t=Number(e.uniqueCorrelativeId);return Number.isFinite(t)?t:null}},[Y.PROGRESS]:{valueKind:O.NUMBER,extract:e=>e.progress},[Y.DURATION_DAYS]:{valueKind:O.NUMBER,extract:(e,t)=>$n(e.durationHours,t.hoursPerDay)},[Y.CALENDAR_DURATION]:{valueKind:O.NUMBER,extract:e=>e.type===D.MILESTONE?0:Vf(e.startDate,e.endDate)},[Y.COST]:{valueKind:O.NUMBER,extract:e=>e.cost},[Y.USED_COST]:{valueKind:O.NUMBER,extract:e=>e.usedCost},[Y.REAL_COST]:{valueKind:O.NUMBER,extract:e=>e.realCost},[Y.WORK_HOURS]:{valueKind:O.NUMBER,extract:e=>e.workHours},[Y.REAL_WORK_HOURS]:{valueKind:O.NUMBER,extract:e=>e.realWorkHours},[Y.PONDERATOR]:{valueKind:O.NUMBER,extract:e=>e.ponderator},[Y.FREE_SLACK_DAYS]:{valueKind:O.NUMBER,extract:(e,t)=>$n(e.freeSlackHours,t.hoursPerDay)},[Y.TOTAL_SLACK_DAYS]:{valueKind:O.NUMBER,extract:(e,t)=>$n(e.criticalPath?.totalSlackHours??null,t.hoursPerDay)},[Y.EXPECTED_PROGRESS_BASELINE]:{valueKind:O.NUMBER,equalityPrecision:Uf,extract:e=>e.expectedProgressBaseline},[Y.EXPECTED_PROGRESS]:{valueKind:O.NUMBER,extract:e=>e.expectedProgress},[Y.BASELINE_DURATION_DAYS]:{valueKind:O.NUMBER,extract:e=>e.baselineSnapshot?.durationDays??null},[Y.BASELINE_COST]:{valueKind:O.NUMBER,extract:e=>e.baselineSnapshot?.cost??null},[Y.BASELINE_WORK_HOURS]:{valueKind:O.NUMBER,extract:e=>e.baselineSnapshot?.workHours??null},[Y.START_DATE]:{valueKind:O.DATE,extract:e=>e.startDate},[Y.END_DATE]:{valueKind:O.DATE,extract:e=>e.endDate},[Y.CONSTRAINT_DATE]:{valueKind:O.DATE,extract:e=>e.constraintDate},[Y.BASELINE_START_DATE]:{valueKind:O.DATE,extract:e=>e.baselineSnapshot?.startDate??null},[Y.BASELINE_END_DATE]:{valueKind:O.DATE,extract:e=>e.baselineSnapshot?.endDate??null},[Y.EARLY_START]:{valueKind:O.DATE,extract:e=>e.criticalPath?.earlyStart??null},[Y.EARLY_FINISH]:{valueKind:O.DATE,extract:e=>e.criticalPath?.earlyFinish??null},[Y.LATE_START]:{valueKind:O.DATE,extract:e=>e.criticalPath?.lateStart??null},[Y.LATE_FINISH]:{valueKind:O.DATE,extract:e=>e.criticalPath?.lateFinish??null},[Y.RESPONSABLE_IDS]:{valueKind:O.ID_ARRAY,extract:e=>e.responsableIds},[Y.TAG_IDS]:{valueKind:O.ID_ARRAY,extract:e=>e.tagIds},[Y.STATUS]:{valueKind:O.ENUM,order:Bf,extract:e=>e.status},[Y.CONSTRAINT_TYPE]:{valueKind:O.ENUM,order:Hf,extract:e=>e.constraintType},[Y.CALENDAR_ID]:{valueKind:O.REFERENCE,extract:e=>e.calendarId===null?null:String(e.calendarId)},[Y.SUBCONTRACT_ID]:{valueKind:O.REFERENCE,extract:e=>e.subcontractId===null?null:String(e.subcontractId)},[Y.IS_CRITICAL]:{valueKind:O.BOOLEAN,extract:e=>e.isCritical}};function fe(e){return Kf[e]??null}function zn(e){return e instanceof Date?e:typeof e=="string"||typeof e=="number"?new Date(e):new Date(Number.NaN)}function ee(e){return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function jf(e,t,r){let i=e===null;return r===W.INCLUDES?!i&&String(e).toLowerCase().includes(t.toLowerCase()):r===W.NOT_INCLUDES?i||!String(e).toLowerCase().includes(t.toLowerCase()):r===W.IS?!i&&String(e)===t:r===W.IS_NOT?i||String(e)!==t:!1}function Yf(e,t,r,i){if(e===null||typeof e!="number")return r===W.NOT_EQUALS;let n=i===void 0?e:Number(e.toFixed(i));return r===W.EQUALS?n===t:r===W.NOT_EQUALS?n!==t:r===W.GREATER_THAN?e>t:r===W.LESS_THAN?e<t:r===W.GREATER_OR_EQUAL?e>=t:r===W.LESS_OR_EQUAL?e<=t:!1}function Gf(e,t,r){return typeof e=="number"&&e>=t&&e<=r}function $f(e,t,r){if(!(e instanceof Date))return!1;let i=ee(e),n=ee(t);return r===W.AFTER?i>n:r===W.BEFORE?i<n:!1}function zf(e,t,r){if(!(e instanceof Date))return!1;let i=ee(e);return i>=ee(t)&&i<=ee(r)}function qf(e,t,r){let n=(Array.isArray(e)?e:[]).some(o=>t.has(String(o)));return r===W.SOME_OF?n:r===W.NOT_SOME_OF?!n:!1}function Jf(e,t,r){let i=e!==null&&t.has(String(e));return r===W.SOME_OF?i:r===W.NOT_SOME_OF?!i:!1}function os(e){let t=Array.isArray(e)?e:[e];return new Set(t.map(r=>String(r)))}function as(e,t,r){let i=fe(t.field);if(i===null)return!1;let n=i.extract(e,r),{operator:o}=t;return o===W.BETWEEN?i.valueKind===O.NUMBER?Gf(n,Number(t.value),Number(t.valueTo)):i.valueKind===O.DATE?zf(n,zn(t.value),zn(t.valueTo)):!1:i.valueKind===O.STRING?jf(n,String(t.value),o):i.valueKind===O.NUMBER?Yf(n,Number(t.value),o,i.equalityPrecision):i.valueKind===O.DATE?$f(n,zn(t.value),o):i.valueKind===O.ID_ARRAY?qf(n,os(t.value),o):Jf(n,os(t.value),o)}function Xf(e,t,r){return t.criteria.length===0?!0:t.logic===li.OR?t.criteria.some(i=>as(e,i,r)):t.criteria.every(i=>as(e,i,r))}function Zf(e,t){let r=ee(e.startDate),i=ee(e.endDate),n=ee(t.start),o=ee(t.end),a=r>=n&&i<=o,s=r>=n&&r<=o,c=n>=r&&n<=i;return a||s||c}function qn(e,t,r){let i=Xf(e,t,r),n=t.dateRange,o=n===void 0||Zf(e,n);return i&&o}function Qf(e,t,r){let i=t(e);for(;i!==null&&!r.has(String(i));)r.add(String(i)),i=t(i)}function ss(e){let{activities:t,parentOf:r,filter:i,context:n}=e,o=new Set,a=[];for(let s of t)qn(s,i,n)&&(o.add(String(s.id)),a.push(s.id));for(let s of a)Qf(s,r,o);return o}function tp(e){let{activities:t,parentOf:r,filter:i,context:n}=e,o=new Set,a=new Map,s=new Map,c=new Map;for(let l of t){let d=String(l.id),u=r(d);s.set(d,u),c.set(d,c.get(d)??0),u!==null&&c.set(u,(c.get(u)??0)+1);let f=qn(l,i,n);a.set(d,f?1:0),f&&o.add(d)}return{matchedIds:o,visibleReferenceCounts:a,parentIds:s,remainingChildren:c}}function ep(e){let{visibleReferenceCounts:t,parentIds:r,remainingChildren:i}=e,n=[];for(let o of r.keys())i.get(o)===0&&n.push(o);for(;n.length>0;){let o=n.pop();if(o===void 0)break;let a=r.get(o);if(a==null)continue;let s=t.get(o)??0;t.set(a,(t.get(a)??0)+s);let c=(i.get(a)??1)-1;i.set(a,c),c===0&&n.push(a)}}function rp(e){let t=new Set;for(let[r,i]of e)i>0&&t.add(r);return t}function di(e){let t=tp(e);ep(t);let r=rp(t.visibleReferenceCounts);return{filter:e.filter,context:e.context,matchedIds:t.matchedIds,visibleIds:r,visibleReferenceCounts:t.visibleReferenceCounts}}function cs(e,t,r){let i=new Set;for(let n of t){let o=String(n.id);i.add(o);let a=e.matchedIds.has(o),s=qn(n,e.filter,e.context);if(a===s)continue;s?e.matchedIds.add(o):e.matchedIds.delete(o);let c=s?1:-1,l=o;for(;l!==null;){let d=e.visibleReferenceCounts.get(l)??0,u=d+c;e.visibleReferenceCounts.set(l,u);let f=d>0,p=u>0;f!==p&&(i.add(l),p?e.visibleIds.add(l):e.visibleIds.delete(l)),l=r(l)}}return i}function Re(e){return{hoursPerDay:e,locale:"en"}}var vt={UNKNOWN_FIELD:"unknown_field",UNKNOWN_OPERATOR:"unknown_operator",INVALID_VALUE:"invalid_value"},ip={[O.STRING]:new Set([W.INCLUDES,W.NOT_INCLUDES,W.IS,W.IS_NOT]),[O.NUMBER]:new Set([W.EQUALS,W.NOT_EQUALS,W.GREATER_THAN,W.LESS_THAN,W.GREATER_OR_EQUAL,W.LESS_OR_EQUAL,W.BETWEEN]),[O.DATE]:new Set([W.AFTER,W.BEFORE,W.BETWEEN]),[O.ID_ARRAY]:new Set([W.SOME_OF,W.NOT_SOME_OF]),[O.ENUM]:new Set([W.SOME_OF,W.NOT_SOME_OF]),[O.BOOLEAN]:new Set([W.SOME_OF,W.NOT_SOME_OF]),[O.REFERENCE]:new Set([W.SOME_OF,W.NOT_SOME_OF])};function ls(e){if(e===void 0)return{ok:!0,dateRange:void 0};if(typeof e!="object"||e===null)return{ok:!1,reason:vt.INVALID_VALUE};let{start:t,end:r}=e;if(!(t instanceof Date)||!(r instanceof Date))return{ok:!1,reason:vt.INVALID_VALUE};let i=t.getTime(),n=r.getTime();return!Number.isFinite(i)||!Number.isFinite(n)||i>n?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,dateRange:{start:new Date(i),end:new Date(n)}}}function ds(e){let t=fe(e.field);if(t===null)return{ok:!1,reason:vt.UNKNOWN_FIELD};if(!ip[t.valueKind].has(e.operator))return{ok:!1,reason:vt.UNKNOWN_OPERATOR};if(e.operator===W.BETWEEN)return np(e,t.valueKind);if(t.valueKind===O.NUMBER){let i=Jn(e.value);return i===null?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:i}}}if(t.valueKind===O.DATE){let i=Xn(e.value);return i===null?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:i}}}let r=op(e,t.valueKind);return r!==null?{ok:!1,reason:r}:t.valueKind===O.BOOLEAN?{ok:!0,criterion:{...e,value:[...new Set(e.value)]}}:t.valueKind===O.ID_ARRAY||t.valueKind===O.ENUM||t.valueKind===O.REFERENCE?{ok:!0,criterion:{...e,value:[...new Set(e.value.map(String))]}}:{ok:!0,criterion:e}}function np(e,t){if(t===O.NUMBER){let r=Jn(e.value),i=Jn(e.valueTo);return r===null||i===null||r>i?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:r,valueTo:i}}}if(t===O.DATE){let r=Xn(e.value),i=Xn(e.valueTo);return r===null||i===null||r.getTime()>i.getTime()?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:r,valueTo:i}}}return{ok:!1,reason:vt.UNKNOWN_OPERATOR}}function op(e,t){let{value:r}=e;return t===O.BOOLEAN?Array.isArray(r)&&r.every(i=>typeof i=="boolean")?null:vt.INVALID_VALUE:t===O.ID_ARRAY||t===O.ENUM||t===O.REFERENCE?Array.isArray(r)&&r.every(i=>typeof i=="string"||typeof i=="number")?null:vt.INVALID_VALUE:Array.isArray(r)?vt.INVALID_VALUE:null}function Jn(e){if(typeof e=="string"&&e.trim()===""||typeof e!="string"&&typeof e!="number")return null;let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:null}function Xn(e){let t;if(e instanceof Date)t=new Date(e.getTime());else if(typeof e=="string")t=new Date(e);else if(typeof e=="number")t=new Date(e);else return null;return Number.isFinite(t.getTime())?t:null}function F(e){return structuredClone(e)}function us(e){return e.criteria.length===0&&e.dateRange===void 0}function ap(e,t,r){let i=e.getAllActivities();if(us(t))return{visibleIds:ss({activities:i,parentOf:o=>e.getParentId(o),filter:t,context:Re(r)}),projection:null};let n=di({activities:i,parentOf:o=>e.getParentId(o),filter:t,context:Re(r)});return{visibleIds:n.visibleIds,projection:n}}function fs(e,t){let{adapter:r,hoursPerDay:i}=t,n=[];for(let u of e.criteria){let f=ds(u);if(!f.ok)return{ok:!1,reason:f.reason};n.push(f.criterion)}let o=ls(e.dateRange);if(!o.ok)return{ok:!1,reason:o.reason};let a=F(o.dateRange===void 0?{criteria:n,logic:e.logic}:{criteria:n,logic:e.logic,dateRange:o.dateRange});r.setActiveFilter(us(a)?null:a);let{visibleIds:s,projection:c}=ap(r,a,i);r.setFilterProjection(c);let l=Xe(r,s);return{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[],viewState:l}}}var Pe={ASCENDING:"asc",DESCENDING:"desc"};var V="0";function M(e){return e==null||e===0||e==="0"}function Gt(e){return M(e)?"0":String(e)}var Zn=Number.MAX_SAFE_INTEGER;function Ht(e,t){let r=Or(e,t),i=t.getOrderComparator?.()??null;return r.sort(i===null?ui:(n,o)=>i(n,o)||ui(n,o)),r.map(n=>String(n.id))}function ys(e){let t=[],r=n=>{t.push(n);let o=Ht(String(n.id),e);for(let a of o){let s=e.getActivity(a);s&&r(s)}},i=Ht("0",e);for(let n of i){let o=e.getActivity(n);o&&r(o)}return t}function hs(e,t,r){let i=r.getActivity(e);if(!i)return null;let n=ms(i),o=Ht(n,r),a=o.findIndex(s=>String(s)===String(e));if(a<=0)return null;for(let s=a-1;s>=0;s--){let c=o[s];if(c!==void 0&&!sp(t,c))return c}return null}function Qn(e,t){let r=t.getActivity(e);if(!r)return-1;let i=ms(r);return Ht(i,t).findIndex(o=>String(o)===String(e))}function Or(e,t){let r=String(e)==="0"?t.getRootIds?.()??t.getChildren("0"):t.getChildren(e),i=[];for(let n of r){let o=t.getActivity(n);o&&i.push(o)}return i}function ui(e,t){let r=ps(e),i=ps(t);return r!==i?r-i:String(e.id).localeCompare(String(t.id))}function ps(e){let t=e.correlativeId,r=typeof t=="number"?t:Number(t);return Number.isFinite(r)?r:Zn}function ms(e){let t=e.parentId;return t===null?"0":t}function sp(e,t){return e.has(t)?!0:e.has(String(t))}function Ze(e){let t=[],r=i=>{let n=Ht(i,e);n.length>1&&t.push({parentId:i,childIds:n});for(let o of n)r(o)};return r("0"),t}function to(e,t){let r=[];for(let i of t){let n=Ht(i,e);n.length>1&&r.push({parentId:i,childIds:n})}return r}function cp(e){return fe(e.field)===null?vt.UNKNOWN_FIELD:e.direction!==Pe.ASCENDING&&e.direction!==Pe.DESCENDING?vt.UNKNOWN_OPERATOR:null}function Is(e,t){let{adapter:r}=t;for(let o of e.rules){let a=cp(o);if(a!==null)return{ok:!1,reason:a}}let i=e.rules.length===0?null:F({rules:e.rules});return r.setActiveOrder(i),{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[],order:Ze(r)}}}function gs(e,t){throw new Error(t)}function As(e,t){return()=>t()===e}var eo=typeof window>"u",lp=!eo&&typeof MessageChannel<"u";function st(){return lp?new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),t.port2.close(),e()},t.port2.postMessage(null)}):Promise.resolve()}async function fi(e,t){return performance.now()-e<ns.YIELD_SLICE_MS?{aborted:!1,newSliceStart:e}:(await st(),t()?{aborted:!1,newSliceStart:performance.now()}:{aborted:!0,newSliceStart:performance.now()})}async function Qe(e){return eo||await st(),e()?{aborted:!1}:{aborted:!0}}function pi(e,t){let{inDegree:r,successors:i}=dp(e,t),n=up(r),o=fp(n,r,i),a=o.length<e.length,s=a?pp(e,o):[],c=[...o].reverse();return{ordered:o,reversed:c,hasCycles:a,cycleNodes:s}}function dp(e,t){let r=new Map,i=new Map;for(let n of e)r.set(n,0),i.set(n,[]);for(let n of t){let o=n.source,a=n.target;!r.has(o)||!r.has(a)||(i.get(o).push(a),r.set(a,(r.get(a)??0)+1))}return{inDegree:r,successors:i}}function up(e){let t=new xt;for(let[r,i]of e)i===0&&t.enqueue(r);return t}function fp(e,t,r){let i=[];for(;!e.isEmpty();){let n=e.dequeue();i.push(n);for(let o of r.get(n)??[]){let a=(t.get(o)??1)-1;t.set(o,a),a===0&&e.enqueue(o)}}return i}function pp(e,t){let r=new Set(t);return e.filter(i=>!r.has(i))}var yi=class{cached=null;invalidate(){this.cached=null}get(t,r){return this.cached?this.cached:(this.cached=pi(t,r),this.cached)}};function vs(e,t){let r=[];for(let i of e)t.has(i)&&r.push(i);return r}var ro={OWN_BASELINE:"own-baseline",RECURSIVE_LEAF_SUM:"recursive-leaf-sum",ZERO:"zero"},io={[D.PROJECT]:{alwaysSummary:!0,holdsConstraint:!1,carriesCustomId:!1,forcedDuration:null,ponderatorWeight:ro.RECURSIVE_LEAF_SUM,promotesToProjectOnFirstChild:!1},[D.TASK]:{alwaysSummary:!1,holdsConstraint:!0,carriesCustomId:!0,forcedDuration:null,ponderatorWeight:ro.OWN_BASELINE,promotesToProjectOnFirstChild:!0},[D.MILESTONE]:{alwaysSummary:!1,holdsConstraint:!0,carriesCustomId:!0,forcedDuration:0,ponderatorWeight:ro.ZERO,promotesToProjectOnFirstChild:!0}};function $t(e,t){return t||Kn(e)&&io[e].alwaysSummary}function re(e){return e===D.MILESTONE}function pe(e){return Kn(e)&&io[e].promotesToProjectOnFirstChild}var no=D.PROJECT,tr=D.TASK;function Nr(e,t){return t===0?D.MILESTONE:e===0&&t>0?D.TASK:null}function hi(e,t){let r=t.getActivity(e);return r?$t(r.type,t.getChildren(e).length>0):!1}function mi(e,t,r){let i=String(t),n=r.getActivity(e);for(;n?.parentId&&String(n.parentId)!=="0";){if(String(n.parentId)===i)return!0;n=r.getActivity(n.parentId)}return!1}function oo(e,t,r){let i=hi(e,r);return hi(t,r)&&mi(e,t,r)||i&&mi(t,e,r)}function Ts(e,t){let r=[],i=[e];for(;i.length>0;){let n=i.pop(),o=t.getChildren(n);if(o.length===0){String(n)!==String(e)&&r.push(n);continue}for(let a of o)i.push(a)}return r}function yp(e){let t=new Map;for(let r of e)Cs(t,String(r.source),r),Cs(t,String(r.target),r);return t}function Cs(e,t,r){let i=e.get(t);if(i){i.push(r);return}e.set(t,[r])}function hp(e,t,r,i){if(e.length<=1)return e;let n=new Set(e.map(String)),o=[];for(let a of e)mp(a,n,t,r,i)||o.push(a);return o.length>0?o:e}function mp(e,t,r,i,n){let o=String(e),a=r.getActivity(e);if(!a||a.autoScheduling===!1)return!1;let s=i.get(o)??[];for(let c of s)if(Ip(c,o,a,t,r,n))return!0;return!1}function Ip(e,t,r,i,n,o){if(gp(e)||!(o?String(e.source)===t:String(e.target)===t))return!1;let s=Ap(e,t);if(!i.has(String(s)))return!1;let c=n.getActivity(s);return!!(c?.autoScheduling!==!1&&c&&vp(e,r,c))}function gp(e){return e.source===e.target}function Ap(e,t){return String(e.source)===t?e.target:e.source}function vp(e,t,r){let i=e.lag??0,n=Math.abs(i);return String(e.target)===String(r.id)&&n<=r.durationHours||String(e.target)===String(t.id)&&n<=t.durationHours}function gi(e,t){let r=[],i=yp(e),n=0;for(let o of e){let a=hi(o.source,t),s=hi(o.target,t);if(Cp(o,a,s,t))continue;if(!a&&!s){r.push(o);continue}let c=Ss(o.source,a,t,i,!0),l=Ss(o.target,s,t,i,!1);n=Rp(r,c,l,o,t,n,i)}return r}function Cp(e,t,r,i){return r&&mi(e.source,e.target,i)||t&&mi(e.target,e.source,i)}function Ss(e,t,r,i,n){return t?hp(Ts(e,r),r,i,n):[e]}function Sp(e,t,r){let i=Ts(e,t);if(i.length===0)return null;let n=null,o=null;for(let a of i){let s=r(a);if(!s)continue;(n===null||s.startDate<n)&&(n=s.startDate),(o===null||s.endDate>o)&&(o=s.endDate)}return n===null||o===null?null:{startDate:n,endDate:o}}function Ii(e,t){return Sp(e,t,r=>{let i=t.getActivity(r);return i?{startDate:i.startDate,endDate:i.endDate}:null})}function Tp(e,t,r){return e?t?r.calculateDuration({startDate:t.startDate,endDate:t.endDate,task:e}):e.durationHours:0}function Ep(e,t,r,i){if(!t)return 0;let n=i.getActivity(e);return!r||!n?-t.durationHours:-i.calculateDuration({startDate:r.startDate,endDate:n.endDate,task:t})}function Dp(e,t){let r=String(e);return(t.get(r)??[]).some(n=>String(n.target)===r)}function _p(e,t,r,i,n){if(Dp(e,n))return 0;let o=i.getActivity(e);return!t||!o||!r?0:i.calculateDuration({startDate:t,endDate:o.startDate,task:r})}function kp(e,t){let r=t.getActivity(e.source),i=t.getActivity(e.target),n=Ii(e.source,t),o=Ii(e.target,t),a=e.type===H.START_TO_START||e.type===H.START_TO_FINISH,s=e.type===H.FINISH_TO_FINISH||e.type===H.START_TO_FINISH;return{source:r,sourceBounds:n,targetStart:o?.startDate??i?.startDate,userLag:e.lag??0,sourceEndpointIsStart:a,targetLag:s?-Tp(i,o,t):0,summarySourceId:e.type===H.START_TO_START&&n?e.source:void 0,finishAnchoredSummaryTargetId:s&&o?e.target:void 0}}function Rp(e,t,r,i,n,o,a){let s=kp(i,n),{source:c,sourceBounds:l,targetStart:d,userLag:u}=s,{sourceEndpointIsStart:f,targetLag:p,summarySourceId:y,finishAnchoredSummaryTargetId:I}=s,T=o;for(let L of t){let S=f?Ep(L,c,l,n):0;for(let E of r){if(String(L)===String(E))continue;let g=_p(E,d,c,n,a);e.push(Pp(i,L,E,T,S,p,u+g,y,I??(g!==0&&p===0?i.target:void 0))),T+=1}}return T}function Pp(e,t,r,i,n,o,a,s,c){return{id:`virtual_${e.id}_${i}`,source:t,target:r,type:e.type,lag:e.lag,freeSlackHours:null,isCritical:!1,_sourceLag:n,_targetLag:o,_trueLag:a,...s===void 0?{}:{_summarySourceId:s},...c===void 0?{}:{_summaryTargetId:c}}}var Ai=class{invalidate(){}get(t,r){return gi(t,r)}};function Lp(e){let t=new Map,r=i=>(t.has(i)||t.set(i,new Set),t.get(i));for(let i of e)r(i.source).add(i.id),r(i.target).add(i.id);return{neighbors:t}}function Op(e,t,r){let i=new Set,n=new Map,o=new xt;for(o.enqueue(e);!o.isEmpty();){let a=o.dequeue(),s=String(a);if(i.has(s))continue;i.add(s);let c=r.neighbors.get(a);if(c)for(let l of c){let d=t.get(l);if(!d)continue;let u=`${d.source}-${d.target}-${d.type}`;n.has(u)||n.set(u,d);let f=String(d.source)===s?d.target:d.source;i.has(String(f))||o.enqueue(f)}}return Array.from(n.values())}function Es(e,t){let r=new Map;for(let a of t)r.set(a.id,a);let i=Lp(t),n=Op(e,r,i),o=new Set([String(e)]);for(let a of n)o.add(String(a.source)),o.add(String(a.target));return{activityIds:o,links:n}}var Ds=0,br=100;function Le(e){return e===0}function _s(e,t,r){let i=r.type===H.FINISH_TO_START,n=r.type===H.FINISH_TO_FINISH;if(r._targetLag!==void 0)return{sourceLag:r._sourceLag??0,targetLag:r._targetLag,trueLag:r._trueLag??r.lag??0,isFS:i,isFF:n,isZeroDurationCase:!1};let o=r.lag??0;switch(r.type){case H.FINISH_TO_START:return{sourceLag:0,targetLag:0,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};case H.START_TO_START:return{sourceLag:-e.durationHours,targetLag:0,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};case H.FINISH_TO_FINISH:return{sourceLag:0,targetLag:-t.durationHours,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};case H.START_TO_FINISH:return{sourceLag:-e.durationHours,targetLag:-t.durationHours,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};default:return{sourceLag:0,targetLag:0,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1}}}function Np(e,t,r){if(e._summarySourceId===void 0)return null;let i=r.getActivity(e._summarySourceId);if(!i)return null;let n=Ii(e._summarySourceId,r);return n?-r.calculateDuration({startDate:n.startDate,endDate:t.endDate,task:i}):null}function bp(e,t,r,i,n){let o=t.durationHours===0&&n;return{successorStart:i.getClosestWorkTime({date:e.endDate,dir:o?"past":"future",task:t}),link:r}}function ks(e,t,r,i){let{sourceLag:n,targetLag:o,trueLag:a,isFS:s,isFF:c}=_s(e,t,r),l=Np(r,e,i)??n,d=l+o+a;if(!(t.durationHours===0?d!==0:l!==0||o!==0||a!==0))return bp(e,t,r,i,s||c);let p=s?t:e,y=i.getClosestWorkTime({date:e.endDate,dir:"future",task:p});if(l!==0&&(y=i.calculateEndDate({startDate:y,durationHours:l,task:e})),o!==0&&(y=i.calculateEndDate({startDate:y,durationHours:o,task:t})),a!==0&&(y=i.calculateEndDate({startDate:y,durationHours:a,task:t})),t.durationHours===0){if(s||c)return{successorStart:i.getClosestWorkTime({date:y,dir:"past",task:t}),link:r};let I=new Date(Date.UTC(y.getUTCFullYear(),y.getUTCMonth(),y.getUTCDate()));return{successorStart:i.getClosestWorkTime({date:I,dir:"future",task:t}),link:r}}return{successorStart:i.getClosestWorkTime({date:y,dir:"future",task:t}),link:r}}function Rs(e,t,r,i){let{sourceLag:n,targetLag:o,trueLag:a}=_s(t,e,r),s=i.getClosestWorkTime({date:e.startDate,dir:"past",task:e});return a!==0&&(s=i.calculateEndDate({startDate:s,durationHours:-a,task:e})),o!==0&&(s=i.calculateEndDate({startDate:s,durationHours:-o,task:e})),n!==0&&(s=i.calculateEndDate({startDate:s,durationHours:-n,task:t})),s}function Ps(e,t,r){for(let i of e){let n=t.getActivity(i);if(!n)continue;let o=n.constraintType;if(!o||o===A.ASAP||o===A.ALAP)continue;let a=qa(n,t);!a.earliestStart&&!a.latestStart&&!a.earliestEnd&&!a.latestEnd||r.set(i,{activityId:i,startDate:n.startDate,endDate:n.endDate,drivingLinkId:null,kind:A.ASAP,conflict:!1,earliestStart:a.earliestStart,latestStart:a.latestStart,earliestEnd:a.earliestEnd,latestEnd:a.latestEnd})}}function vi(e,t,r){let i={earliestStart:t.earliestStart??null,latestStart:t.latestStart??null,earliestEnd:t.earliestEnd??null,latestEnd:t.latestEnd??null},n=t.earliestSchedulingStart??t.latestSchedulingStart??null,o;n===null?o=Yn(e.startDate,i):Ja(n,i)?o=n:o=Yn(n,i),t.startDate=o,t.endDate=r.calculateEndDate({startDate:o,durationHours:e.durationHours,task:e})}function Ls(e,t){if(!e||!t)return new Date;let{constraintType:r,constraintDate:i}=e;if(!r||!i)return t;switch(r){case A.MSO:case A.MFO:return new Date(i);case A.SNET:case A.FNET:return i>t?new Date(i):t;case A.SNLT:case A.FNLT:return i<t?new Date(i):t;default:return t}}function Fp(e,t){return t.length?t.some(r=>String(r)===String(e)):!1}function Os(e,t,r){return ao(e.id,t,r)?{startDate:e.startDate,endDate:e.endDate}:{startDate:e.startDate,endDate:e.endDate}}function ao(e,t,r){return t.dragWithMultiple&&Fp(e,r)}async function Ns(e,t,r,i,n,o){let a=new Map;for(let u of t){let f=String(u.target);a.has(f)||a.set(f,[]),a.get(f).push(u)}let s=u=>{let f=o.get(u);if(f?.startDate&&f.endDate)return{startDate:f.startDate,endDate:f.endDate};let p=r.getActivity(u);return p?{startDate:p.startDate,endDate:p.endDate}:{startDate:new Date,endDate:new Date}},c=r.getFlags(),l=i.draggedIds??[],d=performance.now();for(let u of e){let f=await fi(d,n);if(f.aborted)return o;d=f.newSliceStart;let p=r.getActivity(u);if(!p||!p.autoScheduling||p.progress===100||wp(p,r))continue;let y=a.get(String(u))??[],I=null,T=null,L=!1;for(let B of y){let k=r.getActivity(B.source);if(!k)continue;let v=s(B.source),P=v.startDate.getTime()!==k.startDate.getTime()||v.endDate.getTime()!==k.endDate.getTime(),q={...k,startDate:v.startDate,endDate:v.endDate},$=Os(q,c,l),ot={...q,startDate:$.startDate,endDate:$.endDate},it=ao(B.source,c,l)?{...B,lag:0}:B,Dt=ks(ot,p,it,r);(!I||Dt.successorStart>I)&&(I=Dt.successorStart,T=String(B.id),L=B._summaryTargetId!==void 0&&!P&&(B._targetLag===0||i.preventSummaryTargetPullback===!0))}I!==null&&L&&I<p.startDate&&(I=new Date(p.startDate));let E=o.get(u),g=E?{...E}:{activityId:u,startDate:p.startDate,endDate:p.endDate,drivingLinkId:null,kind:A.ASAP,conflict:!1},b=g.earliestStart||g.latestStart||g.earliestEnd||g.latestEnd;if(!(!I&&!b)){if(I){let B=I;p.type===D.MILESTONE&&(B=Ls(p,I)),g.drivingLinkId=T,g.startDate=B,g.endDate=r.calculateEndDate({startDate:B,durationHours:p.durationHours,task:p}),g.earliestSchedulingStart=B,g.earliestSchedulingEnd=g.endDate}else p.constraintType===A.MSO?g.earliestStart&&(g.startDate=g.earliestStart,g.endDate=g.earliestEnd??r.calculateEndDate({startDate:g.earliestStart,durationHours:p.durationHours,task:p})):p.constraintType===A.MFO&&g.latestStart&&(g.startDate=g.latestStart,g.endDate=g.latestEnd??r.calculateEndDate({startDate:g.latestStart,durationHours:p.durationHours,task:p}));vi(p,g,r),o.set(u,g)}}return o}function wp(e,t){return $t(e.type,t.getChildren(e.id).length>0)}async function bs(e,t,r,i,n,o){let a=new Map(r),s=i.getAllActivities(),c=s.length,l=[];for(let T of s)T.constraintType===A.ALAP&&l.push(T.id);if(l.length===0)return a;let d=new Map,u=new Map;for(let T of t){let L=String(T.source);d.has(L)||d.set(L,[]),d.get(L).push(T);let S=String(T.target);u.has(S)||u.set(S,[]),u.get(S).push(T)}let f=T=>{let L=a.get(T);if(L)return{startDate:L.startDate,endDate:L.endDate};let S=i.getActivity(T);return S?{startDate:S.startDate,endDate:S.endDate}:{startDate:new Date,endDate:new Date}},p=T=>!T.parentId||M(T.parentId)?i.getProjectEnd():f(T.parentId).endDate,y=(T,L)=>{let S=T,E=0;for(;S&&!M(S)&&E++<c+1;){if(String(S)===String(L))return!0;let g=i.getActivity(S);if(!g||!g.parentId)break;S=g.parentId}return!1},I=performance.now();for(let T of e){let L=await fi(I,o);if(L.aborted)return a;I=L.newSliceStart;let S=i.getActivity(T);if(!S||S.constraintType!==A.ALAP||!S.autoScheduling||S.progress===100||$t(S.type,i.getChildren(T).length>0))continue;let E=p(S);if(!E)continue;let g=E,b=null,B=!1,k=d.get(String(T))??[];for(let Yt of k){if((Yt.lag??0)<0)continue;let ze=i.getActivity(Yt.target);if(!ze||ze.autoScheduling===!1)continue;let Ya=f(Yt.target),pf={...ze,startDate:Ya.startDate,endDate:Ya.endDate},ii=Rs(pf,S,Yt,i);ii<g&&(g=ii),(b===null||ii<b)&&(b=ii,B=S.parentId&&!M(S.parentId)?y(Yt.target,S.parentId):!1)}if(b!==null)if(B)g=b;else{let Yt=f(T).endDate,ze=Yt.getTime()>E.getTime()?Yt:E;g=b<ze?b:ze}else g>E&&(g=E);let P=(u.get(String(T))??[]).some(Yt=>Yt.type===H.FINISH_TO_START||Yt.type===H.FINISH_TO_FINISH),q=new Date(Date.UTC(g.getUTCFullYear(),g.getUTCMonth(),g.getUTCDate())),$=()=>i.getClosestWorkTime({date:q,dir:"past",task:S}),ot=i.getClosestWorkTime({date:g,dir:"future",task:S}).getTime()===g.getTime(),it;S.durationHours===0&&b===null?it=P&&ot?$():i.getClosestWorkTime({date:g,dir:"past",task:S}):S.durationHours===0?P?it=$():it=i.getClosestWorkTime({date:g,dir:"future",task:S}):it=i.getClosestWorkTime({date:g,dir:"future",task:S});let Dt=i.calculateEndDate({startDate:it,durationHours:-S.durationHours,task:S}),wt=a.get(T),ht=wt?{...wt}:{activityId:T,startDate:Dt,endDate:it,drivingLinkId:null,kind:A.ALAP,conflict:!1};ht.startDate=Dt,ht.endDate=it,ht.drivingLinkId=null,ht.kind=A.ALAP;let Ge=ht.earliestSchedulingStart??null;ht.earliestSchedulingStart=null,ht.earliestSchedulingEnd=null;let $e=Ge!==null&&Ge.getTime()>Dt.getTime()?Ge:Dt;ht.latestSchedulingStart=$e,ht.latestSchedulingEnd=$e===Dt?it:i.calculateEndDate({startDate:$e,durationHours:S.durationHours,task:S}),vi(S,ht,i),a.set(T,ht)}return a}var er={warn(){},error(){}};var xp=864e5;function Qt(e){if(e.type===D.MILESTONE)return 0;let t=e.startDate?.getTime(),r=e.endDate?.getTime();return t==null||r==null||Number.isNaN(t)||Number.isNaN(r)?null:Math.floor((r-t)/xp)+1}function Fr(e,t){t.cancelled||t.updatedIds.length===0||e.batchUpdate(()=>{for(let r of t.updatedIds){let i=t.plans.get(r);if(!i)continue;let n=e.getLiveActivity(r);n&&(n.startDate=i.startDate,n.endDate=i.endDate,n.calendarDuration=Qt(n),e.updateActivity(r))}})}function so(e,t){let r=String(t.source),i=String(t.target);if(r===i)return!0;let n=new Map;for(let o of e){let a=String(o.source),s=String(o.target),c=n.get(a)??[];c.push(s),n.set(a,c)}return Mp(n,i,r)}function wr(e){let t=new Map,r=new Map;for(let o of e){let a=String(o.source),s=String(o.target),c=t.get(a)??[];c.push(s),t.set(a,c),r.set(a,r.get(a)??0),r.set(s,(r.get(s)??0)+1)}let i=new xt;for(let[o,a]of r)a===0&&i.enqueue(o);let n=0;for(;!i.isEmpty();){let o=i.dequeue();n+=1;for(let a of t.get(o)??[]){let s=r.get(a)-1;r.set(a,s),s===0&&i.enqueue(a)}}return n!==r.size}function Mp(e,t,r){if(t===r)return!0;let i=new Set([t]),n=new xt;for(n.enqueue(t);!n.isEmpty();){let o=n.dequeue(),a=e.get(o)??[];for(let s of a){if(s===r)return!0;i.has(s)||(i.add(s),n.enqueue(s))}}return!1}function Ci(e){let t=Up(e);for(let r of t.adjacency.keys())t.records.has(r)||Bp(r,t);return t.components}function Up(e){let t=new Map,r=new Set;for(let i of e){let n=String(i.source),o=String(i.target),a=Fs(t,n);if(Fs(t,o),n===o){r.add(n);continue}a.push(o)}return{adjacency:t,selfLooped:r,records:new Map,componentStack:[],nextIndex:0,components:[]}}function Fs(e,t){let r=e.get(t);if(r)return r;let i=[];return e.set(t,i),i}function Bp(e,t){let r=[];for(r.push({node:e,record:ws(e,t),neighborCursor:0});r.length>0;){let i=r[r.length-1];if(i===void 0)break;let n=t.adjacency.get(i.node)??[];if(i.neighborCursor<n.length){let s=n[i.neighborCursor];if(i.neighborCursor+=1,s===void 0)continue;Hp(i,s,r,t);continue}r.pop();let o=r[r.length-1];o&&i.record.lowLink<o.record.lowLink&&(o.record.lowLink=i.record.lowLink),i.record.lowLink===i.record.visitIndex&&Wp(i.node,t)}}function Hp(e,t,r,i){let n=i.records.get(t);if(!n){r.push({node:t,record:ws(t,i),neighborCursor:0});return}n.onStack&&n.visitIndex<e.record.lowLink&&(e.record.lowLink=n.visitIndex)}function ws(e,t){let r={visitIndex:t.nextIndex,lowLink:t.nextIndex,onStack:!0};return t.nextIndex+=1,t.records.set(e,r),t.componentStack.push({node:e,record:r}),r}function Wp(e,t){let r=[];for(;;){let a=t.componentStack.pop();if(a===void 0||(a.record.onStack=!1,r.push(a.node),a.node===e))break}let i=r[0],n=r.length===1&&i!==void 0&&t.selfLooped.has(i);(r.length>1||n)&&t.components.push(r)}function xr(e,t,r){let i=r?new co(e,r):e;return gi([...t],i)}var co=class{constructor(t,r){this.base=t;for(let[i,n]of r.reparented){let o=String(i),a=n===null||M(n)?null:n,s=t.getActivity(i)?.parentId??null,c=s===null||M(s)?null:String(s),l=a===null?null:String(a);if(c!==l){if(this.reparented.set(o,a),c!==null){let d=this.movedOutByParent.get(c)??new Set;d.add(o),this.movedOutByParent.set(c,d)}if(l!==null){let d=this.movedInByParent.get(l)??[];d.push(i),this.movedInByParent.set(l,d)}}}}base;reparented=new Map;movedOutByParent=new Map;movedInByParent=new Map;withOverride(t){if(!t)return null;let r=this.reparented.get(String(t.id));return r===void 0?t:{...t,parentId:r}}getActivity(t){return this.withOverride(this.base.getActivity(t))}getLiveActivity(t){return this.withOverride(this.base.getLiveActivity(t))}getAllActivities(){return this.base.getAllActivities().map(t=>this.withOverride(t)??t)}getChildren(t){let r=String(t),i=this.movedOutByParent.get(r),n=this.base.getChildren(t),o=i?n.filter(s=>!i.has(String(s))):[...n],a=this.movedInByParent.get(r);return a&&o.push(...a),o}getParent(t){let r=this.reparented.get(String(t));return r===void 0?this.base.getParent(t):r===null?null:this.getActivity(r)}isChildOf(t,r){let i=String(r),n=new Set,o=this.getActivity(t);for(;o;){let a=o.parentId;if(a===null||M(a))return!1;let s=String(a);if(s===i)return!0;if(n.has(s))return!1;n.add(s),o=this.getActivity(a)}return!1}getAllLinks(){return this.base.getAllLinks()}getAllIds(){return this.base.getAllIds()}getLink(t){return this.base.getLink(t)}activityExists(t){return this.base.activityExists(t)}getOutgoingLinkIds(t){return this.base.getOutgoingLinkIds(t)}getIncomingLinkIds(t){return this.base.getIncomingLinkIds(t)}getClosestWorkTime(t){return this.base.getClosestWorkTime(t)}calculateEndDate(t){return this.base.calculateEndDate(t)}calculateDuration(t){return this.base.calculateDuration(t)}batchUpdate(t){this.base.batchUpdate(t)}updateActivity(t){this.base.updateActivity(t)}getFlags(){return this.base.getFlags()}getProjectEnd(){return this.base.getProjectEnd()}};function Oe(e){let{port:t,proposedPort:r,currentLinks:i,proposedLinks:n,proposal:o}=e,a=xr(r??t,n,o);if(!wr(a))return{ok:!0};let s=xr(t,i),c=xs(s),d=[...xs(a)].filter(u=>!c.has(u));return d.length===0?{ok:!0}:{ok:!1,newlyCyclicActivityIds:d}}function xs(e){let t=new Set;for(let r of Ci(e))for(let i of r)t.add(i);return t}function ye(e,t){switch(e.kind){case dt.CREATE:return Vp(e,t);case dt.UPDATE:return Mr(e,t.port);case dt.DELETE:return Kp(e,t)}}function Ti(e,t){if(e.length===0)return{applied:!0};let r=t.port.getAllLinks(),i=new Map,n=[];for(let l of r){let d=Ms(l);i.has(d)||i.set(d,l.id),n.push({source:l.source,target:l.target})}let o=wr(n),a=null;for(let{operation:l,linkId:d}of e){if(String(l.source)===String(l.target)){a={applied:!1,rejected:At.SELF_LINK};break}if(!t.port.getActivity(l.source)||!t.port.getActivity(l.target)){a={applied:!1,rejected:At.ACTIVITY_MISSING};break}if(oo(l.source,l.target,t.port)){a={applied:!1,rejected:At.HIERARCHY_LINK};break}let u=Ms(l),f=i.get(u);if(f!==void 0){a={applied:!1,rejected:At.DUPLICATE,linkId:f};break}if(i.set(u,d),o&&so(n,{source:l.source,target:l.target}))return{applied:!1,rejected:At.CYCLE};n.push({source:l.source,target:l.target})}if(!o&&wr(n))return{applied:!1,rejected:At.CYCLE};if(a)return a;let s=[...r,...e.map(({operation:l,linkId:d})=>({id:d,source:l.source,target:l.target,type:l.type,lag:l.lag,freeSlackHours:null,isCritical:!1}))];if(!Oe({port:t.port,currentLinks:r,proposedLinks:s}).ok)return{applied:!1,rejected:At.CYCLE};for(let{operation:l,linkId:d}of e){let u=t.preserved?.get(d);t.port.addLink({id:d,source:l.source,target:l.target,type:l.type,lag:l.lag,freeSlackHours:null,isCritical:!1,...u?.ganttId===void 0?{}:{ganttId:u.ganttId},...u?.sectorId===void 0?{}:{sectorId:u.sectorId},...u?.proplannerId===void 0?{}:{proplannerId:u.proplannerId}})}return{applied:!0}}function Ms(e){return JSON.stringify([String(e.source),String(e.target),e.type])}function Vp(e,t){let{port:r}=t;if(String(e.source)===String(e.target))return{applied:!1,rejected:At.SELF_LINK};let i=r.getActivity(e.source),n=r.getActivity(e.target);if(!i||!n)return{applied:!1,rejected:At.ACTIVITY_MISSING};if(oo(e.source,e.target,r))return{applied:!1,rejected:At.HIERARCHY_LINK};let o=r.getAllLinks();for(let d of o)if(String(d.source)===String(e.source)&&String(d.target)===String(e.target)&&d.type===e.type)return{applied:!1,rejected:At.DUPLICATE,linkId:d.id};let a=o.map(d=>({source:d.source,target:d.target}));if(so(a,{source:e.source,target:e.target}))return{applied:!1,rejected:At.CYCLE};let s=(t.newLinkId??jp)(),c={id:s,source:e.source,target:e.target,type:e.type,lag:e.lag,freeSlackHours:null,isCritical:!1};return Oe({port:r,currentLinks:o,proposedLinks:[...o,c]}).ok?(r.addLink(c),{applied:!0,linkId:s}):{applied:!1,rejected:At.CYCLE}}function Mr(e,t){return t.getLink(e.linkId)?(e.lag!==void 0&&t.setLinkField(e.linkId,"lag",e.lag),e.type!==void 0&&t.setLinkField(e.linkId,"type",e.type),{applied:!0,linkId:e.linkId}):{applied:!1,rejected:At.LINK_MISSING}}function Kp(e,t){let{port:r}=t;return r.getLink(e.linkId)?(r.removeLink(e.linkId),{applied:!0,linkId:e.linkId}):{applied:!1,rejected:At.LINK_MISSING}}var Si=null;function jp(){return Si===null&&(Si=Date.now()),Si+=1,String(Si)}var Ct={FINISH_TO_START:"fs",START_TO_START:"ss",FINISH_TO_FINISH:"ff",START_TO_FINISH:"sf"},Ei={[H.FINISH_TO_START]:Ct.FINISH_TO_START,[H.START_TO_START]:Ct.START_TO_START,[H.FINISH_TO_FINISH]:Ct.FINISH_TO_FINISH,[H.START_TO_FINISH]:Ct.START_TO_FINISH},Ne={[Ct.FINISH_TO_START]:H.FINISH_TO_START,[Ct.START_TO_START]:H.START_TO_START,[Ct.FINISH_TO_FINISH]:H.FINISH_TO_FINISH,[Ct.START_TO_FINISH]:H.START_TO_FINISH},Us=Ct.FINISH_TO_START;function Bs(e){if(e in Ne)return Ne[e]}var Hs=";",he={DAY:"d",WEEK:"w",WEEK_DHTMLX:"wk",MONTH:"m",MONTH_DHTMLX:"mon",YEAR:"y"},Ws=/^(\d+)(fs|ss|ff|sf)?(?:([+-]?)(\d+(?:\.\d+)?)(weeks?|wk|w|months?|mon|m|days?|d|years?|y)?)?$/i;var Yp=5,Di=30,lo=365,Gp={[he.DAY]:1,day:1,days:1,[he.MONTH]:Di,[he.MONTH_DHTMLX]:Di,month:Di,months:Di,[he.YEAR]:lo,year:lo,years:lo},$p=new Set([he.WEEK,he.WEEK_DHTMLX,"week","weeks"]);function _i(e,t={}){let r=[],i=[],n=t.daysPerWeek!==void 0&&Number.isFinite(t.daysPerWeek)&&t.daysPerWeek>0?t.daysPerWeek:Yp,o=e.replace(/\s+/g,"");if(o.length===0)return{specs:r,errors:i};for(let a of o.split(Hs)){if(a.length===0)continue;let s=zp(a,n);s?r.push(s):i.push(a)}return{specs:r,errors:i}}function zp(e,t){let r=e.toLowerCase(),i=Ws.exec(r);if(!i)return null;let[,n,o,a,s,c]=i,l=o?Ne[o]:Ne[Us],d=0;if(s!==void 0){let u=Number(s);if(Number.isNaN(u))return null;let f=c!==void 0&&$p.has(c)?t:Gp[c??he.DAY],p=u*f;d=a==="-"?-p:p}return{correlativeId:n,type:l,lag:d}}function Ri(e){let{targetActivityId:t,currentLinks:r,desiredSpecs:i}=e,n=[],o=new Map;for(let c of i){let l=e.resolveActivityByCorrelative(c.correlativeId);if(l==null){n.push(c);continue}let d=ki(l,c.type);o.has(d)||o.set(d,{source:l,type:c.type,lag:c.lag})}let a=new Map;for(let c of r)String(c.target)===String(t)&&a.set(ki(c.source,c.type),c);let s=[];for(let[c,l]of a)o.has(c)||s.push({kind:dt.DELETE,linkId:l.id});for(let[c,l]of o){let d=a.get(c);d&&d.lag!==l.lag&&s.push({kind:dt.UPDATE,linkId:d.id,lag:l.lag})}for(let[c,l]of o)a.has(c)||s.push({kind:dt.CREATE,source:l.source,target:t,type:l.type,lag:l.lag});return{operations:s,unresolved:n}}function ki(e,t){return`${String(e)}::${t}`}function Pi(e){let{sourceActivityId:t,currentLinks:r,desiredSpecs:i}=e,n=[],o=new Map;for(let c of i){let l=e.resolveActivityByCorrelative(c.correlativeId);if(l==null){n.push(c);continue}let d=ki(l,c.type);o.has(d)||o.set(d,{target:l,type:c.type,lag:c.lag})}let a=new Map;for(let c of r)String(c.source)===String(t)&&a.set(ki(c.target,c.type),c);let s=[];for(let[c,l]of a)o.has(c)||s.push({kind:dt.DELETE,linkId:l.id});for(let[c,l]of o){let d=a.get(c);d&&d.lag!==l.lag&&s.push({kind:dt.UPDATE,linkId:d.id,lag:l.lag})}for(let[c,l]of o)a.has(c)||s.push({kind:dt.CREATE,source:t,target:l.target,type:l.type,lag:l.lag});return{operations:s,unresolved:n}}function Li(e){let t=Math.sign(e)*Math.round(Math.abs(e));return Object.is(t,-0)?0:t}function Wt(e,t){return Math.sign(e)*Math.round(Math.abs(e)*t)}var Vs={rawInputToConstraintDate(e,t){let r=new Date(e);return r.setUTCHours(0,0,0,0),r.getTime()===e.getTime()?t.getClosestWorkTime({direction:K.FUTURE,date:e,unit:mt.HOUR}):t.isWorkTime(e,mt.HOUR)?e:r},computeLagBetweenTasks(e,t,r){return r.calculateDuration(e,t)}};function uo(e,t,r){switch(r){case H.FINISH_TO_START:return{sourceDate:e.endDate,targetDate:t.startDate};case H.START_TO_START:return{sourceDate:e.startDate,targetDate:t.startDate};case H.FINISH_TO_FINISH:return{sourceDate:e.endDate,targetDate:t.endDate};case H.START_TO_FINISH:return{sourceDate:e.startDate,targetDate:t.endDate}}}var fo=Vs;var rr=class{adapter;reporter;currentCalculationId=0;topoCache=new yi;expandedLinksCache=new Ai;constructor(t,r=er){this.adapter=t,this.reporter=r}getCurrentCalculationId(){return this.currentCalculationId}invalidateTopoCache(){this.topoCache.invalidate()}invalidateExpandedLinksCache(){this.expandedLinksCache.invalidate()}invalidateAllCaches(){this.topoCache.invalidate(),this.expandedLinksCache.invalidate()}async schedule(t={}){let r=++this.currentCalculationId,i=As(r,()=>this.currentCalculationId),n={plans:new Map,updatedIds:[],cycles:[],cancelled:!1};try{Xp(this.adapter);let o=me("schedule.total"),a=me("schedule.expandParentLinks"),s=this.adapter.getAllLinks(),c=this.expandedLinksCache.get(s,this.adapter);ie(a);let l=c;if((await Qe(i)).aborted)return{...n,cancelled:!0};let d=me("schedule.scoping"),u=this.adapter.getAllIds(),f=Zp(t,l,this.adapter),p=f.links,y=f.idSet;ie(d);let I=me("schedule.topologicalSort"),T=ty(this.topoCache,u,l,y);if(ie(I),T.hasCycles)return ie(o),{...n,cycles:[T.cycleNodes]};if((await Qe(i)).aborted)return{...n,cancelled:!0};let L=me("schedule.processConstraints"),S=new Map;if(Ps(T.ordered,this.adapter,S),ie(L),(await Qe(i)).aborted)return{...n,cancelled:!0};let E=me("schedule.asapPass"),g=await Ns(T.ordered,p,this.adapter,t,i,S);if(ie(E),(await Qe(i)).aborted)return{...n,cancelled:!0};let b=me("schedule.alapPass"),B=await bs(T.reversed,p,g,this.adapter,t,i);if(ie(b),(await Qe(i)).aborted)return{...n,cancelled:!0};let k=me("schedule.diff"),v=[];for(let[P,q]of B){let $=this.adapter.getActivity(P);if(!$)continue;let ot=$.startDate.getTime()!==q.startDate.getTime(),it=$.endDate.getTime()!==q.endDate.getTime();(ot||it)&&v.push(P)}return ie(k),ie(o),{plans:B,updatedIds:v,cycles:[],cancelled:!1}}catch(o){throw this.reporter.error("[AutoScheduler] Error during scheduling",o),o}}},qp=!1;function Jp(){let e=globalThis.__SCHEDULER_PHASE_LOG__;return typeof e=="boolean"?e:qp}function me(e){return{name:e,startedAt:performance.now()}}function Xp(e){let t=e;typeof t.clearCalendarCache=="function"&&t.clearCalendarCache()}function ie(e){if(!Jp())return;let t=performance.now()-e.startedAt;console.log(`[scheduler] ${e.name} ${t.toFixed(1)}ms`)}function Zp(e,t,r){let i=e.triggerId;if(i==null)return{idSet:null,links:t};let n=Es(i,t);return Qp(n,t,r)}function Qp(e,t,r){let i=new Set(e.activityIds),n=new Set;for(let a of r.getAllActivities()){let s=String(a.id);a.constraintType===A.ALAP&&!i.has(s)&&(n.add(s),i.add(s))}if(n.size===0)return{idSet:i,links:e.links};let o=[...e.links];for(let a of t)(n.has(String(a.source))||n.has(String(a.target)))&&o.push(a);return{idSet:i,links:o}}function ty(e,t,r,i){let n=e.get(t,r);if(n.hasCycles){let a=i?Array.from(i):t;return pi(a,r)}if(!i)return n;let o=vs(n.ordered,i);return{ordered:o,reversed:[...o].reverse(),hasCycles:!1,cycleNodes:[]}}function Ks(e,t,r){let i=t.getActivity(e);if(!i)return;let n=r?{...i,endDate:r.endDate}:i,o=t.calendarReader.getCalendar(String(i.calendarId));for(let a of t.getIncomingLinkIds(e)){let s=t.getLink(a);if(!s)continue;let c=t.getActivity(s.source);if(!c||c.constraintType===A.ALAP||re(i.type)&&(s.type===H.START_TO_FINISH||s.type===H.FINISH_TO_FINISH))continue;let{sourceDate:d,targetDate:u}=uo(c,n,s.type),f=fo.computeLagBetweenTasks(d,u,o);f!==s.lag&&Mr({kind:dt.UPDATE,linkId:s.id,lag:f},t)}}function js(e,t){let r=t.getActivity(e);r&&re(r.type)&&(r.durationHours=0)}function Oi(e){let t=0,r=!1;for(let i of e)i.ponderator>0&&(t+=i.ponderator/100*i.progress,r=!0);return r?t:null}function Ys(e){return Number(e.toFixed(2))}function Ur(e){for(let t of ey(e))$s(t,e)}function Gs(e,t){for(let r of e)$s(r,t)}function ey(e){let t=new Set;e.forEachActivity((i,n)=>{e.getChildren(n).length>0&&t.add(n)});let r=new Map;for(let i of t)r.set(i,ry(i,e));return[...t].sort((i,n)=>(r.get(n)??0)-(r.get(i)??0))}function ry(e,t){let r=0,i=e;for(;i&&i!=="0"&&t.getActivity(i);)r+=1,i=t.getParentId(i);return r}function $s(e,t){let r=t.getChildren(e);if(r.length===0)return;let i=[];for(let n of r){let o=t.getActivity(n);o&&i.push({progress:Number(o.progress??0),ponderator:Number(o.ponderator??0)})}po(e,i,t)}function po(e,t,r){let i=r.getActivity(e);if(!i)return;let n=Oi(t);if(n===null){let o=r.getProgressFallback(e);o!==null&&r.setActivityField(e,_.PROGRESS,o);return}r.getProgressFallback(e)===null&&r.setProgressFallback(e,Number(i.progress??0)),r.setActivityField(e,_.PROGRESS,Ys(n))}function zs(e,t,r){let i=[e];for(;i.length>0;){let n=i.pop();if(n===void 0)continue;let o=r.getChildren(n);o.length!==0&&(r.setProgressFallback(n,t),i.push(...o))}}function Nt(e,t){return(Number(e)||0)*(Number(t)||0)/100}var Br={SKIP:"skip",FREEZE_WITHOUT_CONTRIBUTION:"freeze-when-no-contribution"};async function ir(e,t,r=!0,i={}){let n=t?Hr(e,t):cy(e),o=r?i.progressMode??Br.FREEZE_WITHOUT_CONTRIBUTION:Br.SKIP;await iy(n,e,o,{recomputeRealWork:i.recomputeRealWork??!1})}function Ni(e,t){qs(e,t,Br.SKIP)}async function iy(e,t,r,i={recomputeRealWork:!1}){let o=0;for(let a of e)qs(a,t,r,i.recomputeRealWork),o+=1,o%200===0&&await st()}function Hr(e,t){let r=new Set,i=new Map;for(let a of t)ny(a,e,r,i);if(r.size===0)return[];let n=Array.from(r),o=oy(n,i);return Js(n,o)}function ny(e,t,r,i){let n=t.getParentId(e);for(;n&&!M(n);){if(r.has(n))return;r.add(n);let o=t.getParentId(n);i.set(n,o),n=o}}function oy(e,t){let r=new Map;for(let i of e){if(r.has(i))continue;let n=[],o=new Set,a=i;for(;a&&!M(a)&&!r.has(a)&&!o.has(a);)n.push(a),o.add(a),a=t.get(a)??null;let s=a?r.get(a)??0:0;for(let c=n.length-1;c>=0;c-=1)s+=1,r.set(n[c],s)}return r}function ay(e,t,r){let i=null,n=null,o=0,a=[];for(let s of e){let c=t.getActivity(s);if(!c)continue;let l=c.startDate.getTime(),d=c.endDate.getTime();(i===null||l<i)&&(i=l),(n===null||d>n)&&(n=d),r&&(o+=sy(c,t.getChildren(s).length>0)),a.push({progress:Number(c.progress??0),ponderator:Number(c.ponderator??0)})}return{minStart:i,maxEnd:n,realWorkSum:o,weightedChildren:a}}function qs(e,t,r=Br.FREEZE_WITHOUT_CONTRIBUTION,i=!1){let n=t.getActivity(e);if(!n)return;let o=t.getChildren(e);if(o.length===0)return;let a=ay(o,t,i);if(a.minStart===null||a.maxEnd===null)return;let s=String(n.calendarId??""),c=t.calendarReader.getCalendar(s),l=new Date(a.minStart),d=new Date(a.maxEnd),u=c.calculateDuration(l,d);t.setActivityField(e,"startDate",l),t.setActivityField(e,"endDate",d),t.setActivityField(e,"durationHours",u),r!==Br.SKIP&&po(e,a.weightedChildren,t),i&&t.setActivityField(e,"realWorkHours",a.realWorkSum)}function sy(e,t){return t?Number(e.realWorkHours)||0:Nt(e.workHours,e.progress)}function cy(e){let t=ly(e),r=dy(t,e);return Js(t,r)}function ly(e){let t=new Set;return e.forEachActivity(r=>{r.parentId!==null&&t.add(r.parentId)}),Array.from(t)}function dy(e,t){let r=new Map;for(let i of e)r.set(i,uy(i,t));return r}function uy(e,t){let r=0,i=e;for(;i&&!M(i)&&t.getActivity(i);)r+=1,i=t.getParentId(i);return r}function Js(e,t){return[...e].sort((r,i)=>(t.get(i)??0)-(t.get(r)??0))}var Xs={updateActivityDuration:js,updateTaskTiming:py("updateTaskTiming"),adjustLinkLagOnTaskMove:Ks,recordLastStartDate:fy};function fy(e,t){let r=t.getActivity(e);r&&t.setLastStartDate(e,r.startDate)}function Ie(e,t,r,i){for(let n of t){let o=n in Xs?Xs[n]:void 0;if(!o){console.warn(`[replay post-processors] unknown: ${n} \u2014 skipping. Add an entry in POST_PROCESSORS if a fixture needs it.`);continue}o(e,r,i??null)}}function py(e){return()=>{console.debug(`[replay post-processors] ${e}: not yet ported to adapter \u2014 no-op.`)}}function j(e,t){return t!==void 0?{ok:!0,value:e,raw:t}:{ok:!0,value:e}}function J(e){return{ok:!1,reason:e}}function tt(){return{valid:!0}}function ut(e,t){return t!==void 0?{valid:!1,reason:e,notification:t}:{valid:!1,reason:e}}function X(){return{allowed:!0}}function nt(e,t){return t!==void 0?{allowed:!1,reason:e,alertKey:t}:{allowed:!1,reason:e}}function Q(e,t={}){return{patch:e,needsAutoSchedule:t.autoSchedule??!1,postProcessors:t.postProcessors??[],...t.cascadeMutations!==void 0?{cascadeMutations:t.cascadeMutations}:{},...t.trackingEvents!==void 0?{trackingEvents:t.trackingEvents}:{}}}var lt={PROGRESS_ENTRY:"activity_progress_entry",PROGRESS_UPDATE_RADIO_BUTTON:"activity_progress_update_radio_button",DURATION_ENTRY:"activity_duration_entry",START_DATE_ENTRY:"activity_start_date_entry",END_DATE_ENTRY:"activity_end_date_entry",NAME_ENTRY:"activity_name_entry",DESCRIPTION_ENTRY:"activity_description_entry",CALENDAR_ASSIGNMENT:"activity_calendar_assignment",COST_BUDGETED_ENTRY:"activity_cost_budgeted_entry",COST_SPENT_ENTRY:"activity_cost_spent_entry",LABOR_HOURS_BUDGETED_ENTRY:"activity_labor_hours_budgeted_entry"};var Zs={targetField:"name",canEdit(){return X()},parseInput(e){return typeof e!="string"?J("not_a_string"):j(e)},validate(){return tt()},transform(e,t){return Q({name:t},{autoSchedule:!1,postProcessors:[]})},trackEvent:lt.NAME_ENTRY};var Qs={targetField:"description",canEdit(){return X()},parseInput(e){return typeof e!="string"?J("not_a_string"):j(e.trim())},validate(){return tt()},transform(e,t){return Q({description:t},{autoSchedule:!1,postProcessors:[]})},trackEvent:lt.DESCRIPTION_ENTRY};function zt(e){return e.constraintType??A.ASAP}var bi=100;function ge(e){return e.progress>=bi}function ft(e,t){return $t(e.type,t.hasChildren(e.id))}function tc(e){return e.progress>0}function ec(e){return e.hasLookaheadTasks}function be(e,t){return Math.round(Math.ceil(e*t*60)/60)}var nr=e=>({endDate:e});var Fi="UTC";function Ae(e,t){if(t){let r=new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(e),i=n=>Number(r.find(o=>o.type===n)?.value);return new Date(Date.UTC(i("year"),i("month")-1,i("day")))}return new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()))}function xi(e,t){if(!t||t===Fi){let f=new Date(e);return f.setUTCHours(23,59,0,0),f}let r=new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(e),i=f=>Number(r.find(p=>p.type===f)?.value),n=i("year"),o=i("month"),a=i("day"),s=Date.UTC(n,o-1,a,23,59,0,0),c=new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(s)),l=f=>Number(c.find(p=>p.type===f)?.value),u=Date.UTC(l("year"),l("month")-1,l("day"),l("hour")===24?0:l("hour"),l("minute"),l("second"))-s;return new Date(s-u)}function yy(e,t){let r=Ae(t,Fi);for(;!e.isWorkTime(r,mt.DAY);)r=new Date(r),r.setUTCDate(r.getUTCDate()+1),r=Ae(r,Fi);return r}function yo(e,t){return e.getClosestWorkTime({direction:K.FUTURE,date:t,unit:mt.HOUR})}function ho(e,t){let r=yy(e,t),i=new Date(r);return i.setUTCDate(i.getUTCDate()+1),i.setUTCHours(0,0,0,0),e.getClosestWorkTime({direction:K.PAST,date:i,unit:mt.HOUR})}var wi=new Set([A.SNET,A.SNLT,A.MSO]),mo=new Set([A.FNET,A.FNLT,A.MFO]),ve=new Set([A.ASAP,A.ALAP]),Mi=A.SNET;function ne(e,t,r){let i=Ae(e,Fi);if(!wi.has(r)&&!mo.has(r))return i;let n=wi.has(r)?yo(t,i):ho(t,i),o=new Date(i);return o.setUTCHours(n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds()),o}var Ce=()=>({constraintType:Mi});var Fe=e=>({constraintDate:e}),rc=e=>({constraintDate:e});var ic={UPDATE_ACTIVITY_DURATION:"updateActivityDuration",UPDATE_TASK_TIMING:"updateTaskTiming",ADJUST_LINK_LAG_ON_TASK_MOVE:"adjustLinkLagOnTaskMove",RECORD_LAST_START_DATE:"recordLastStartDate"};var nc={UNCHANGED:"unchanged",OUT_OF_RANGE:"out_of_range",NEGATIVE_DURATION:"negative_duration",NOT_WORKING_DAY:"not_working_day",BEFORE_PARENT_START:"before_parent_start",BEFORE_START_DATE:"before_start_date",BEFORE_DATE_ORIGIN:"before_date_origin",CONSTRAINT_VIOLATION:"constraint_violation",MISSING_ID:"missing_id",UNKNOWN_CALENDAR:"unknown_calendar"},Wr={COMPLETED:"completed",SUMMARY:"summary",HAS_PROGRESS:"has_progress",HAS_LOOKAHEAD_TASKS:"has_lookahead_tasks",SIR_START_AFTER_PROGRESS:"sir_start_after_progress"},oc={CANT_EDIT_COMPLETED:"cant_edit_completed_activity",SUMMARY_COLUMN_VALUE:"summary_column_value",CANT_EDIT_WITH_PROGRESS:"cant_edit_activity_with_progress",SIR_CANT_MOVE_START_AFTER_PROGRESS:"sir_cant_move_start_after_progress",CANT_EDIT_WITH_TASK:"cant_edit_actvity_with_task"};function or(e,t,r){return $a(e,t,r)}function ar(e,t,r){return za(e,t,r)}var sc={targetField:"durationHours",canEdit(e,t){return ge(e)?nt("completed","cant_edit_completed_activity"):ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e,t,r){let i=parseFloat(String(e));return Number.isFinite(i)?j(be(i,r.hoursPerDay)):J("not_a_number")},validate(e,t,r){return ac(r)?ut(nc.NEGATIVE_DURATION):hy(t,r)?ut("unchanged"):tt()},transform(e,t,r){if(ac(t))return Q({},{autoSchedule:!1,postProcessors:[]});let i=my(e,t,r),n=Iy(e,t,r,i.violated);return{...Q(n,{autoSchedule:!0,postProcessors:[ic.RECORD_LAST_START_DATE]}),...i.violated?{constraintWarning:ar(i.constraintType,i.constraintDate,cc(e,t,r)??void 0)}:{}}},trackEvent:lt.DURATION_ENTRY};function ac(e){return Math.sign(e)===-1}function hy(e,t){return e===t}function my(e,t,r){let i=r.calendars.getCalendar(e.calendarId);if(!i)return{violated:!1};let n=e.constraintType;if(n!==A.FNET&&n!==A.FNLT&&n!==A.MFO)return{violated:!1};let o=i.calculateEndDate(e.startDate,t);return or(n,e.constraintDate,o)}function Iy(e,t,r,i=!1){let n={};i&&Object.assign(n,Ce(),Fe(e.startDate));let o=Nr(e.durationHours,t);o&&(n.type=o),n.durationHours=t;let a=cc(e,t,r);return a&&Object.assign(n,nr(a)),n}function cc(e,t,r){let i=r.calendars.getCalendar(e.calendarId);return i?i.calculateEndDate(e.startDate,t):null}var sr=e=>({realWorkHours:e});var gy=0,Ay=bi,Ui={targetField:"progress",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):ec(e)?nt("has_lookahead_tasks","cant_edit_actvity_with_task"):X()},parseInput(e){let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(e,t,r){return vy(r)?ut("out_of_range"):tt()},transform(e,t,r){let i=Le(t),n=e.progress!==t&&i,o=Cy(t),a=Ey(e,t,r.hierarchy),s={progress:t,autoScheduling:i,...sr(a.get(e.id)??0)},c=o?Sy(e,t,i,r.hierarchy,a):[],l=o?_y(e,t,r.hierarchy):[],d=c.length+l.length>0?[...c,...l]:void 0,u=[],f=o?Ry(e,t):void 0;return Q(s,{autoSchedule:n,postProcessors:u,cascadeMutations:d,trackingEvents:f})},trackEvent:lt.PROGRESS_ENTRY};function vy(e){return e<gy||e>Ay}function Cy(e){return e===bi||Le(e)}function Sy(e,t,r,i,n){return i.getDescendantIds(e.id).map(a=>({activityId:a,fields:Ty(t,r,n.get(a)??0)}))}function Ty(e,t,r){return{progress:e,autoScheduling:t,...sr(r)}}function Ey(e,t,r){let i=new Map,n=a=>{let s=0;for(let c of r.getChildHhInfo(a)){let l=r.hasChildren(c.id)?n(c.id):Nt(c.workHours,t);i.set(c.id,l),s+=l}return s},o=r.hasChildren(e.id)?n(e.id):Nt(e.workHours,t);return i.set(e.id,o),i}function Dy(e,t){let r=[e.id,...t.getDescendantIds(e.id)],i=o=>t.getChildProgressInfo(o).some(a=>t.hasChildren(a.id)),n=o=>t.getAncestorIds(o).length;return r.filter(o=>i(String(o))).map(String).sort((o,a)=>n(a)-n(o))}function _y(e,t,r){let i=new Map;i.set(e.id,t);for(let a of r.getDescendantIds(e.id))i.set(a,t);let n=[...Dy(e,r),...r.getAncestorIds(e.id)],o=[];for(let a of n){let s=ky(a,i,r);s!==null&&(i.set(a,s),o.push({activityId:a,fields:{progress:s}}))}return o}function ky(e,t,r){let i=r.getChildProgressInfo(e).map(o=>({progress:t.has(o.id)?t.get(o.id):o.progress,ponderator:o.ponderator??0})),n=Oi(i);return n===null?null:Number(n.toFixed(2))}function Ry(e,t){return[{name:lt.PROGRESS_UPDATE_RADIO_BUTTON,properties:{activity_id:e.id,activity_name:e.name,progress_updated:t}}]}var lc={targetField:"cost",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(String(e).trim()==="")return j(0);let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(){return tt()},transform(e,t,r){let i=Py(e,t,r.hierarchy);return Q({cost:t},{autoSchedule:!1,postProcessors:[],cascadeMutations:i})},trackEvent:lt.COST_BUDGETED_ENTRY};function Py(e,t,r){let i=new Map;i.set(e.id,t);let n=[];for(let o of r.getAncestorIds(e.id)){let a=0;for(let s of r.getChildCostInfo(o))a+=i.has(s.id)?i.get(s.id):s.cost;i.set(o,a),n.push({activityId:o,fields:{cost:a}})}return n}var dc={targetField:"usedCost",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(String(e).trim()==="")return j(0);let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(){return tt()},transform(e,t,r){let i=Ly(e,t,r.hierarchy);return Q({usedCost:t},{autoSchedule:!1,postProcessors:[],cascadeMutations:i})},trackEvent:lt.COST_SPENT_ENTRY};function Ly(e,t,r){let i=new Map;i.set(e.id,t);let n=[];for(let o of r.getAncestorIds(e.id)){let a=0;for(let s of r.getChildUsedCostInfo(o))a+=i.has(s.id)?i.get(s.id):s.usedCost;i.set(o,a),n.push({activityId:o,fields:{usedCost:a}})}return n}var uc={targetField:"workHours",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(String(e).trim()==="")return j(0,e);let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(){return tt()},transform(e,t,r,i){let n=fc(t,e.progress),o=String(i).trim()===""?[]:Oy(e,t,n,r.hierarchy);return Q({workHours:t,...sr(n)},{autoSchedule:!1,postProcessors:[],cascadeMutations:o})},trackEvent:lt.LABOR_HOURS_BUDGETED_ENTRY};function fc(e,t){return Nt(e,t)}function Oy(e,t,r,i){let n=new Map,o=new Map;n.set(e.id,t),o.set(e.id,r);let a=[];for(let s of i.getAncestorIds(e.id)){let c=0,l=0;for(let d of i.getChildHhInfo(s)){let u=n.has(d.id)?n.get(d.id):d.workHours,f=o.has(d.id)?o.get(d.id):d.realWorkHours??fc(d.workHours,d.progress);c+=u,l+=f}n.set(s,c),o.set(s,l),a.push({activityId:s,fields:{workHours:c,...sr(l)}})}return a}function Vr(e,t){return e.getUTCFullYear()===t.getUTCFullYear()&&e.getUTCMonth()===t.getUTCMonth()&&e.getUTCDate()===t.getUTCDate()}function Io(e,t){return e.getTime()<t.getTime()}function we(e){return e instanceof Date&&!Number.isNaN(e.getTime())}var Bi=e=>({durationHours:e});var Ny="sir-apply",pc={targetField:"startDate",canEdit(e,t,r){return ft(e,t)?nt("summary","summary_column_value"):tc(e)?r?.eventSource!==Ny?nt("has_progress","cant_edit_activity_with_progress"):ge(e)?nt("completed","cant_edit_completed_activity"):we(r.newValue)?Vr(e.startDate,r.newValue)?X():r.newValue.getTime()>e.startDate.getTime()?nt("sir_start_after_progress","sir_cant_move_start_after_progress"):X():X():X()},parseInput(e,t,r){return we(e)?j(Ae(e,"UTC")):J("invalid_date")},validate(e,t,r,i){if(Vr(t,r))return ut("unchanged");let n=by(e,r,i);return n||tt()},transform(e,t,r){let i=r.calendars.getCalendar(e.calendarId);if(!i)throw new Error("startDatePipeline: no calendar resolved (integrity)");let n=yo(i,t),o=e.type===D.MILESTONE,a=o?n:i.calculateEndDate(n,e.durationHours),s=n;return{...Q({startDate:n,...nr(a),...o?Bi(0):{},...Ce(),...Fe(s)},{autoSchedule:!0,postProcessors:["adjustLinkLagOnTaskMove"]}),constraintWarning:Fy(e,n,i)}},trackEvent:lt.START_DATE_ENTRY};function by(e,t,r){let i=r.hierarchy.getParentStartDateIfHasPredecessors(e.id);if(!i)return null;let n=Ae(i,"UTC");return t.getTime()<n.getTime()?ut("before_parent_start"):null}function Fy(e,t,r){let i=r.calculateEndDate(t,e.durationHours),n=Rr(zt(e),t,i),o=or(zt(e),e.constraintDate,n);if(o.violated)return ar(o.constraintType,o.constraintDate,n)}var wy=99.999,hc={targetField:"endDate",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):xy(e)?nt("completed","cant_edit_completed_activity"):X()},parseInput(e,t,r){if(!we(e))return J("invalid_date");let i=Ae(e,"UTC"),n=r.calendars.getCalendar(t.calendarId);return n?n.isWorkTime(i,mt.DAY)?j(ho(n,i)):j(n.getClosestWorkTime({direction:"past",date:i,unit:mt.HOUR})):j(i)},validate(e,t,r,i){if(Vr(e.endDate,r))return ut("unchanged");if(My(r,e))return ut("before_date_origin");if(Uy(r,e))return ut("before_start_date");let n=By(r,e,i);return n||tt()},transform(e,t,r){let i=Hy(e,t),n=Wy(e,t,r,!!i);return{...Q(n,{autoSchedule:!0,postProcessors:["updateTaskTiming"]}),...i?{constraintWarning:i}:{}}},trackEvent:lt.END_DATE_ENTRY};function xy(e){return e.progress>=wy}function My(e,t){return t.dateOrigin?Io(e,t.dateOrigin):!1}function Uy(e,t){return Io(e,t.startDate)}function By(e,t,r){let i=r.calendars.getCalendar(t.calendarId);return i?i.isWorkTime(e,mt.DAY)?null:ut("not_working_day"):null}function Hy(e,t){if(zt(e)===A.MSO)return;let i=Rr(zt(e),e.startDate,t),n=or(zt(e),e.constraintDate,i);if(n.violated)return ar(n.constraintType,n.constraintDate,i)}function Wy(e,t,r,i=!1){let n={};re(e.type)&&!i&&yc(e)?Object.assign(n,Fe(e.startDate)):(i||yc(e))&&Object.assign(n,Ce(),Fe(e.startDate));let s=Vy(e,t,r),c=Nr(e.durationHours,s);return c&&(n.type=c),Object.assign(n,Bi(s)),n.endDate=t,n}function yc(e){return ve.has(zt(e))}function Vy(e,t,r){let i=r.calendars.getCalendar(e.calendarId);return i?i.calculateDuration(e.startDate,t):e.durationHours}var Ky=new Set(Object.values(A)),mc={targetField:"constraintType",canEdit(e,t){return ge(e)?nt("completed","cant_edit_completed_activity"):ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){let t=String(e).toLowerCase();return jy(t)?j(t):J("invalid_constraint_type")},validate(){return tt()},transform(e,t,r){let i=Yy(e,t,r);return Q(i,{autoSchedule:!0})}};function jy(e){return Ky.has(e)}function Yy(e,t,r){let i=$y(e,t);return{constraintType:t,...rc(Gy(e,t,i,r))}}function Gy(e,t,r,i){if(e.type!==D.MILESTONE||!r)return r;let n=i.calendars.getCalendar(String(e.calendarId));return n?ne(r,n,t):r}function $y(e,t){return ve.has(t)?null:wi.has(t)?e.startDate:mo.has(t)?e.endDate:e.constraintDate}var Ic={targetField:"constraintDate",canEdit(e,t){return ge(e)?nt("completed","cant_edit_completed_activity"):ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){return we(e)?j(e):J("invalid_date")},validate(){return tt()},transform(e,t,r){let i=gc(e)?Mi:zt(e),n=r.calendars.getCalendar(e.calendarId);if(!n)throw new Error("constraintDatePipeline: no calendar resolved (integrity)");let o=ne(t,n,i),a=zy(e,o);return Q(a,{autoSchedule:!0})}};function zy(e,t){return{constraintDate:t,...gc(e)?Ce():{}}}function gc(e){return ve.has(zt(e))||!e.constraintType}var Ac={targetField:"calendarId",canEdit(){return X()},parseInput(e){let t=String(e).trim();return qy(t)?J("empty_calendar"):j(t)},validate(e,t,r,i){return Jy(e.calendarId,r)?ut("unchanged"):i.calendars.getCalendar(r)?tt():ut("unknown_calendar")},transform(e,t,r){return Q(Xy(e,t,r),{autoSchedule:!0,postProcessors:[]})},trackEvent:lt.CALENDAR_ASSIGNMENT};function qy(e){return e===""}function Jy(e,t){return e===t}function Xy(e,t,r){let i={calendarId:t,assignedDefaultCalendar:!1},n=r.calendars.getCalendar(t);if(n){let o=e.durationHours===0,a=o?Zy(e.startDate):e.startDate,s=n.getClosestWorkTime({date:a,direction:"future",unit:"hour"});if((!e.autoScheduling||o||n.getWorkHours(e.startDate).length===0)&&(i.startDate=s),!e.autoScheduling)return i;let c=i.startDate??e.startDate;Object.assign(i,nr(n.calculateEndDate(c,e.durationHours)))}return i}function Zy(e){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()))}var vc={targetField:"customId",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(e==null)return J("empty_custom_id");if(typeof e!="string")return J("not_a_string");let t=e.trim();return t.length===0?J("empty_custom_id"):t.length>20?J("exceeds_max_length"):j(t)},validate(){return tt()},transform(e,t){return Q({customId:t},{autoSchedule:!1,postProcessors:[]})}};var Cc={targetField:"subcontractId",canEdit(){return X()},parseInput(e){if(e==null)return j(null);if(typeof e=="string"){let t=e.trim();if(t.length===0)return j(null);let r=Number(t);return!Number.isFinite(r)||!Number.isInteger(r)?J("not_an_integer"):j(r)}return typeof e=="number"?!Number.isFinite(e)||!Number.isInteger(e)?J("not_an_integer"):j(e):J("not_an_integer")},validate(){return tt()},transform(e,t){return Q({subcontractId:t},{autoSchedule:!1,postProcessors:[]})}};function Kr(e){if(e==null)return null;if(typeof e=="object"){if(!("id"in e))return null;let t=e.id;return t==null?null:String(t)}return String(e)}function Hi(e){return e.some(t=>Kr(t)===null)}var Sc={targetField:"responsableIds",canEdit(){return X()},parseInput(e){return e==null?j([]):Array.isArray(e)?j(e):J("not_an_array")},validate(e,t,r){return Hi(r)?ut("missing_id"):tt()},transform(e,t){let r=t.map(Kr).filter(i=>i!==null);return Q({responsableIds:r},{autoSchedule:!1,postProcessors:[]})}};var Tc={targetField:"tagIds",canEdit(){return X()},parseInput(e){return e==null?j([]):Array.isArray(e)?j(e):J("not_an_array")},validate(e,t,r){return Hi(r)?ut("missing_id"):tt()},transform(e,t){let r=t.map(Kr).filter(i=>i!==null);return Q({tagIds:r},{autoSchedule:!1,postProcessors:[]})}};var Qy=new Map([[_.TEXT,Zs],[_.DESCRIPTION,Qs],[_.DURATION,sc],[_.PROGRESS,Ui],[_.COST,lc],[_.USED_COST,dc],[_.HH_WORK_TIME,uc],[_.START_DATE,pc],[_.END_DATE,hc],[_.CONSTRAINT_TYPE,mc],[_.CONSTRAINT_DATE,Ic],[_.CALENDAR_ID,Ac],[_.CUSTOM_ID,vc],[_.SUBCONTRACT_ID,Cc],[_.RESPONSABLES,Sc],[_.TAGS,Tc]]);function Se(e){return Qy.get(e)}var pt={APPEND:"append",REPLACE:"replace"},Wi={ACTION_BUTTON:"action-button"},Vi={SIR_AUTO_REJECT:"sir-auto-reject"},Ki={DATE_CHANGED:"date_changed",ACTIVITY_DELETED:"activity_deleted"},ji={VIOLATION:"constraint_violation"},oe={INIT:"init",UNDO:"undo",REDO:"redo"};function cr(e,t){if(!t||t.type!==ni.CONSTRAINT)return null;let r=t.data;return!r?.constraintType||!r.constraintDate?null:{kind:ji.VIOLATION,activityId:e,constraintType:r.constraintType,constraintDate:r.constraintDate,projectedDate:r.projectedDate??r.constraintDate,messageKey:t.messageKey}}var th=["name","description","type","startDate","endDate","durationHours","constraintType","constraintDate","calendarId","assignedDefaultCalendar","autoScheduling","progress","cost","usedCost","workHours","realWorkHours","customId","subcontractId","responsableIds","tagIds"],Ec=new Set(th);var x={ID:"id",PROPLANNER_ID:"proplannerId",PARENT:"parentId",NAME:"name",DESCRIPTION:"description",TYPE:"type",START_DATE:"startDate",END_DATE:"endDate",DURATION_HOURS:"durationHours",CONSTRAINT_TYPE:"constraintType",CONSTRAINT_DATE:"constraintDate",AUTO_SCHEDULING:"autoScheduling",CALENDAR_ID:"calendarId",ASSIGNED_DEFAULT_CALENDAR:"assignedDefaultCalendar",DATE_ORIGIN:"dateOrigin",PROGRESS:"progress",COST:"cost",USED_COST:"usedCost",REAL_COST:"realCost",WORK_HOURS:"workHours",REAL_WORK_HOURS:"realWorkHours",PONDERATOR:"ponderator",HAS_CUSTOM_PONDERATOR:"hasCustomPonderator",CORRELATIVE_ID:"correlativeId",UNIQUE_CORRELATIVE_ID:"uniqueCorrelativeId",CUSTOM_ID:"customId",SUBCONTRACT_ID:"subcontractId",IS_LOOKAHEAD:"isLookahead",HAS_LOOKAHEAD_TASKS:"hasLookaheadTasks",NEW_ACTIVITIES_ARRAY:"newActivityIds",HAS_NEW_ACTIVITIES:"hasNewActivities",IS_NEW_ACTIVITY:"isNewActivity",PENDING_REQUEST_IDS:"pendingRequestIds",RESPONSABLE_IDS:"responsableIds",TAG_IDS:"tagIds",BASELINE_POINTS:"baselinePoints",BASELINE_SNAPSHOT:"baselineSnapshot",SUM_OF_DURATION_RECURSIVELY:"recursiveDurationHours",CALENDAR_DURATION:"calendarDuration",IS_CRITICAL:"isCritical",FREE_SLACK_HOURS:"freeSlackHours",EXPECTED_PROGRESS:"expectedProgress",EXPECTED_PROGRESS_BASELINE:"expectedProgressBaseline",STATUS:"status",CRITICAL_PATH:"criticalPath"},jr={ID:"id",SOURCE:"source",TARGET:"target",TYPE:"type",LAG:"lag",FREE_SLACK_HOURS:"freeSlackHours",IS_CRITICAL:"isCritical",SOURCE_LAG:"_sourceLag",TARGET_LAG:"_targetLag",TRUE_LAG:"_trueLag",SUMMARY_SOURCE_ID:"_summarySourceId",SUMMARY_TARGET_ID:"_summaryTargetId",GANTT_ID:"ganttId",SECTOR_ID:"sectorId",PROPLANNER_ID:"proplannerId"};function yt(e,t,r,i){e.setActivityFieldDynamic(t,r,i)}function Dc(e,t,r,i){e.setLinkFieldDynamic(t,r,i)}function ae(e){return{...e,startDate:new Date(e.startDate),endDate:new Date(e.endDate),constraintDate:te(e.constraintDate),dateOrigin:te(e.dateOrigin),newActivityIds:[...e.newActivityIds],pendingRequestIds:[...e.pendingRequestIds],responsableIds:[...e.responsableIds],tagIds:[...e.tagIds],baselinePoints:e.baselinePoints.map(t=>({...t,startDate:te(t.startDate),endDate:te(t.endDate)})),baselineSnapshot:eh(e.baselineSnapshot),criticalPath:rh(e.criticalPath)}}function te(e){return e===null?null:new Date(e)}function eh(e){return e===null?null:{...e,startDate:te(e.startDate),endDate:te(e.endDate)}}function rh(e){return e===null?null:{...e,earlyStart:te(e.earlyStart),earlyFinish:te(e.earlyFinish),lateStart:te(e.lateStart),lateFinish:te(e.lateFinish)}}var Rc=200;function Te(e,t){let r=new Set([String(e)]);for(let i of t.cascadeMutations??[])r.add(String(i.activityId));return r}async function rt(e,t){let r=new Map,i=0;for(let n of t){i+=1,i%Rc===0&&await st();let o=e.getActivity(n);o&&r.set(n,et(o))}return r}function et(e){return ae(e)}function Yi(e,t){let r=e.getActivity(t);return r?ae(r):null}function Ee(e,t,r){_c(e,t,r.patch);for(let i of r.cascadeMutations??[])_c(e,i.activityId,i.fields)}function _c(e,t,r){for(let[i,n]of Object.entries(r)){if(!Ec.has(i))throw new Error(`applyFieldChanges: column write to non-writable field "${i}"`);yt(e,t,i,n)}}async function Gi(e,t,r,i){let n=[],o=0;for(let a of r){o+=1,o%Rc===0&&await st();let s=ih(e,t,a,i);s&&n.push(s)}return n}function ih(e,t,r,i){let n=e.getActivity(r);if(!n)return{id:r,kind:N.DELETED,after:null};let o=t.get(r);if(!o&&i?.has(r))return nh(r,i.get(r),n);let a=Ao(o,n);return oh(a,i,r,n),o&&Object.keys(a).length===0?null:{id:r,kind:o?N.UPDATED:N.CREATED,fields:a,after:et(n)}}function nh(e,t,r){return t===r.correlativeId?null:{id:e,kind:N.UPDATED,fields:{correlativeId:{before:t,after:r.correlativeId}},after:et(r)}}function oh(e,t,r,i){if(!t?.has(r)||Object.hasOwn(e,"correlativeId"))return;let n=t.get(r);n!==i.correlativeId&&(e.correlativeId={before:n,after:i.correlativeId})}function Ao(e,t){let r={},i=e??{},n=t,o=new Set([...Object.keys(i),...Object.keys(n)]);o.delete(x.CALENDAR_DURATION);for(let a of o)(Object.hasOwn(i,a)!==Object.hasOwn(n,a)||!go(i[a],n[a]))&&(r[a]={before:kc(i[a]),after:kc(n[a])});return r}function kc(e){return e===null||typeof e!="object"?e:F(e)}function go(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e==null||t==null)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((a,s)=>go(a,t[s]));if(typeof e!="object"||typeof t!="object")return!1;let r=e,i=t,n=Object.keys(r),o=Object.keys(i);return n.length!==o.length?!1:n.every(a=>Object.hasOwn(i,a)&&go(r[a],i[a]))}function $i(e,t,r){let i=new Set;i.add(e);for(let n of t)i.add(n);for(let n of r)i.add(n);return i}function vo(e,t){let r=new Set;for(let i of e)r.add(String(i));for(let i of t)r.add(i);return r}function lr(e,t,r,i,n){for(let o of t){if(r.has(o.activityId)||(n.add(o.activityId),i.has(o.activityId)))continue;let a=e.getActivity(o.activityId);if(!a)continue;let s=et(a);o.before!==void 0&&(s.correlativeId=o.before),i.set(o.activityId,s)}}var ah=/^(\d{4})\/(\d{1,2})\/(\d{1,2})\s+(\d{1,2}):(\d{2})$/;function se(e){if(e==null||e==="")throw new Error(`[parseFromBackend] expected a date string, got "${e}"`);if(e.includes("T")||e.endsWith("Z")){let s=new Date(e);if(Number.isNaN(s.getTime()))throw new Error(`[parseFromBackend] invalid ISO date "${e}"`);return s}let t=e.match(ah);if(!t)throw new Error(`[parseFromBackend] unsupported date format "${e}" (expected "YYYY/MM/DD H:MM" or ISO)`);let[,r,i,n,o,a]=t;return new Date(Date.UTC(Number(r),Number(i)-1,Number(n),Number(o),Number(a)))}function dr(e,t,r,i){if(e.getTime()>r.getTime())return 0;if(t.getTime()<r.getTime()||e.getTime()===t.getTime())return 100;let n=i.calculateDuration(e,r),o=i.calculateDuration(e,t);return o===0?0:n*100/o}var sh=e=>e.type===D.PROJECT,ch=(e,t,r)=>{let i=e.calendarId,n=i!=null?r.calendarReader.getCalendar(String(i)):null;if(!n)return 0;let o=a=>a instanceof Date?a:se(String(a));return dr(o(e.startDate),o(e.endDate),t,n)};function lh(e,t,r){let i=[],n=(a,s)=>{let c=r.getActivity(a);c&&c.expectedProgress!==s&&(r.setActivityField(a,"expectedProgress",s),i.push(String(a)))},o=a=>{let s=r.getActivity(a);if(!s)return 0;if(!sh(s)){let d=ch(s,t,r);return n(a,d),d}let c=0;for(let d of r.getChildren(a)){let u=o(d),f=r.getActivity(d),p=typeof f?.ponderator=="number"?f.ponderator:0;c+=u*p}let l=c/100;return n(a,l),l};for(let a of e)o(a);return i}function Me(e,t){let r=[];e.forEachActivity((i,n)=>{i.parentId===null&&r.push(n)}),lh(r,t,e)}var dh=e=>e.type===D.PROJECT,uh=e=>kt(e),fh=(e,t,r,i)=>{let n=uh(e);if(!n)return 0;let o=(n.baseCalendarId!=null?r.getBaseCalendar(`${n.baseCalendarId}-base`):null)??(i?r.getBaseCalendar(i):null);return!o||!n.startDate||!n.endDate?0:dr(n.startDate,n.endDate,t,o)};function Co(e,t,r,i=null){let n=[],o=(s,c)=>{let l=r.getActivity(s);l&&l.expectedProgressBaseline!==c&&(r.setActivityField(s,"expectedProgressBaseline",c),n.push(s))},a=s=>{let c=r.getActivity(s);if(!c)return 0;if(!dh(c)){let u=fh(c,t,r,i);return o(s,u),u}let l=0;for(let u of r.getChildrenIds(s)){let f=a(u),p=r.getActivity(u),y=typeof p?.ponderator=="number"?p.ponderator:0;l+=f*y}let d=l/100;return o(s,d),d};for(let s of e)a(s);return n}function ur(e,t,r=null){let i={getChildrenIds:o=>e.getChildren(String(o)).map(a=>String(a)),getActivity:o=>e.getActivity(o),setActivityField:(o,a,s)=>yt(e,o,a,s),getBaseCalendar:o=>e.calendarReader.getCalendar(o)},n=[];return e.forEachActivity((o,a)=>{o.parentId===null&&n.push(a)}),Co(n,t,i,r)}var So=de.BASELINE;function zi(e){return e===de.ACTUAL?de.ACTUAL:So}var Pc=e=>Math.round(e*100)/100;function ph(e,t){return(t===de.BASELINE?e.expectedProgressBaseline:e.expectedProgress)??void 0}function yh(e,t){let r=Pc(e),i=Pc(t);return r>99.99?_t.DONE:i>r?_t.OVERDUE:e>0&&r>i?_t.ADVANCEMENT:e===0&&t===0?_t.WAITING:e>0&&r<i?_t.DOING:_t.WAITING}function ce(e,t){let r=[];return e.forEachActivity((i,n)=>{let o=typeof i.progress=="number"?i.progress:0,a=yh(o,ph(i,t));i.status!==a&&(yt(e,n,_.STATUS,a),r.push(n))}),r}function To(e){let t=e instanceof Date?new Date(e.getTime()):e&&typeof e=="object"&&typeof e.valueOf=="function"?new Date(e.valueOf()):new Date(e),r=(n,o)=>a=>a===void 0?t[n]():(t[o](a),i),i={__isMomentShim:!0,clone:()=>To(t),hours:r("getUTCHours","setUTCHours"),minutes:r("getUTCMinutes","setUTCMinutes"),seconds:r("getUTCSeconds","setUTCSeconds"),milliseconds:r("getUTCMilliseconds","setUTCMilliseconds"),valueOf:()=>t.getTime(),toDate:()=>new Date(t.getTime()),getTime:()=>t.getTime()};return i}To.isMoment=e=>!!e&&typeof e=="object"&&e.__isMomentShim===!0;var Vt=To;function hh(e){return e&&e.constructor===Date?!!(e.getFullYear&&e.getMonth&&e.getDate):!1}function qi(e){return hh(e)&&!isNaN(e.getTime())}function R(e,t,r,i){if(!qi(new Date(t)))throw new Error(`Invalid date argument for calculateEndDate method. Date: ${t}, Activity: ${JSON.stringify(i)}`);let n=t;return e.calculateEndDate({start_date:new Date(n),duration:r,unit:"hour",task:i})}function Mt(e){if(!qi(new Date(e.dateBaseToCalculate)))throw new Error("Invalid date argument for getClosestWorkTime method");let{dateBaseToCalculate:t,activityCalendar:r,direction:i,activity:n}=e;return r.$gantt.getClosestWorkTime({date:new Date(t),dir:i,unit:"hour",task:n})}var h=A;var U=Object.freeze({FS:Ct.FINISH_TO_START,SS:Ct.START_TO_START,FF:Ct.FINISH_TO_FINISH,SF:Ct.START_TO_FINISH});function Ue(e){return Ei[String(Number(e))]??Ct.START_TO_FINISH}var G=Object.freeze({FORWARD:"forward",BACKWARD:"backward"}),Be=Object.freeze({GREATER:"greater",LESS:"less"}),qt=Object.freeze({SOURCE:"$source"});var mh=e=>e?e.$level===1:!1,Ih=e=>e.type===D.PROJECT,gh=e=>e.$level!==0,Ah=e=>e.type===D.TASK,vh=e=>e.type===D.TASK||e.type===D.MILESTONE,Lt={byFirstLevel:mh,filterByParentType:Ih,avoidSubproject:gh,byTaskType:Ah,byTaskTypeAndMilestone:vh};function Lc(e){let{gantt:t,pendingParentsWithNoLinks:r,calculations:i,linkProperty:n}=e;try{let o=Ch({gantt:t,pendingParentsWithNoLinks:r});if(o.length===0)return new Set;let a=Sh({gantt:t,subprojectsWithNoLinks:o}),s=Th({gantt:t,childrenIds:a,linkProperty:n,getArrayOfLinkedActivities:Eh,calculations:i});return new Set(s.map(c=>c.id))}catch(o){throw o}}function Ch(e){let{gantt:t,pendingParentsWithNoLinks:r}=e;return t.getTaskByTime().filter(Lt.filterByParentType).filter(i=>r.has(i.id)).map(i=>i.id)}function Sh(e){let{gantt:t,subprojectsWithNoLinks:r}=e,i=new Set;for(let n of r)t.getChildren(n).filter(s=>{let c=t.getTask(s),l=Lt.byTaskTypeAndMilestone(c),d=Number(c.progress)<100;return l&&d}).forEach(s=>i.add(s));return[...i]}function Th(e){let{gantt:t,childrenIds:r,linkProperty:i,getArrayOfLinkedActivities:n,calculations:o}=e,a=[];for(let s of r){let c=t.getTask(s),l=c[i]||[];n({gantt:t,links:l,linkDirection:i===qt.SOURCE?"target":"source"}).every(f=>o.has(f))&&a.push(c)}return a}function Eh(e){let{gantt:t,links:r,linkDirection:i}=e,n=[];for(let o of r){let a=t.getLink(o);if(!a){`${o}`;continue}let s=Number(a[i]);n.push(s)}return n}function Oc({gantt:e,linkProperty:t,direction:r}){try{let i=Dh(e,t);if(r===G.FORWARD)return{chainStartActivities:i,activitiesStartChainButChildrenOfLinkedParents:null};if(r===G.BACKWARD)return _h(i,e,t)}catch(i){throw console.log("Critical Path",i),i}}function Dh(e,t){return e.getTaskByTime().filter(Lt.avoidSubproject).filter(Lt.byTaskTypeAndMilestone).filter(r=>!r[t].length)}function _h(e,t,r){let i=[],n=new Set;return e.forEach(o=>{let a=Number(o.parent),s=t.getTask(a);s&&(s[r].length>0?n.add(o.id):s.constraint_type!==h.FNLT&&i.push(o))}),{chainStartActivities:i,activitiesStartChainButChildrenOfLinkedParents:n}}function Nc({gantt:e,direction:t,linkProperty:r}){try{let i=kh(e),n=new Set,o=new Set,a=new Set;t===G.BACKWARD&&Lh(i).forEach(d=>{n.add(d.id)});let s=Rh(i,t,r),c=Ph(i,s);return s.forEach(l=>{o.add(l.id)}),c.forEach(l=>{a.add(l.id)}),{parentsWithFullProgress:n,pendingParentsWithNoLinks:o,pendingParentsWithLinks:a}}catch(i){throw i}}function kh(e){return e.getTaskByTime().filter(Lt.filterByParentType).filter(Lt.avoidSubproject)}function Rh(e,t,r){return e.filter(i=>{let n=i[r];if(!Array.isArray(n))return!1;let o=n.length>0,a=i.constraint_type||"",s=a!==h.FNLT;if(t===G.FORWARD){let c=a!==h.SNET;return!o&&s&&c}else return!o&&s})}function Ph(e,t){let r=new Set(t.map(i=>i.id));return e.filter(i=>!r.has(i.id))}function Lh(e){return e.filter(t=>{let r=Number(t.progress);return Number.isNaN(r)?!1:r===100})}function bc({pendingParentsWithLinks:e,gantt:t,direction:r}){try{let i=new Set;return e.forEach(n=>{let o=t.getTask(n),a=Oh(r),s=Nh(r),c=o[a];if(!Array.isArray(c))return;bh(t,c,s).forEach(d=>{i.add(d)})}),i}catch(i){throw i}}function Oh(e){return e===G.FORWARD?qt.SOURCE:"$target"}function Nh(e){return e===G.FORWARD?"target":"source"}function bh(e,t,r){return t.map(i=>{let o=e.getLink(i)[r];return Number(o)})}var Yr={identifySecondLevelActivities:Lc,identifyInitialActivities:Oc,identifyParentsWithAndWithoutLinks:Nc,identifyForbiddenActivities:bc};function Ji(e){return e.length?e.reduce((t,r)=>r.ef>t.ef?r:t):!1}function Eo({linkType:e,lag:t,predecessorTime:r,activityCalendar:i,activity:n}){return e===U.FS&&t===0?Mt({predecessorTime:r,activityCalendar:i,direction:"future",activity:n}):Gr(r,e,i,n)}function Fc({duration:e,constraintDate:t,activityCalendar:r,activity:i}){let n=new Date(t);return{es:R(r,n,e,i),ef:n}}function wc({duration:e,constraintDate:t,activityCalendar:r,activity:i}){let n=new Date(t),o=R(r,n,e,i);return{es:n,ef:o}}function Gr(e,t,r,i){if(![U.FS,U.SS,U.FF].includes(t))return e;let o=[U.FS,U.SS].includes(t)?"future":"past";return Mt({dateBaseToCalculate:e,activityCalendar:r,direction:o,activity:i})}var Do=class{constructor(t,r,i,n){if(this.linkedActivitiesData=t,this.activity=r,this.gantt=i,this.linkCandidates=n,this.activityCalendar=this.gantt.getCalendar(this.activity.calendar_id),!this.activityCalendar)throw new Error(`Error trying to get calendar with id: ${this.activity.calendar_id}`)}calculate(){let t=this.calculateLinks(),r=Ji(t),i=this.activity.constraint_type;return i===h.SNET?this.handleSNETConstraint(r):i===h.FNLT?this.handleFNLTConstraint(r):r}calculateLinks(){let t=[];for(let r of this.linkedActivitiesData){let i=r.linkType,n=Ue(i),o=r.linkLag,a=r.es,s=r.ef,c=null;if(n===U.SS)c=this.calculateSSLink({lag:o,predecessorEs:a});else if(n===U.FF)c=this.calculateFFLink({lag:o,predecessorEf:s});else if(n===U.FS)c=this.calculateFSLink({lag:o,predecessorEf:s});else if(n===U.SF)c=this.calculateSFLink({lag:o,predecessorEs:a,predecessorEf:s});else continue;c&&(this.linkCandidates?.set(r.linkId,{targetId:String(this.activity.id),...c}),t.push(c))}return t}handleSNETConstraint(t){let r=wc({duration:this.activity.duration,constraintDate:this.activity.constraint_date,activityCalendar:this.activityCalendar,activity:this.activity});return t&&t.ef>r.ef?t:r}handleFNLTConstraint(t){let r=Fc({duration:-this.activity.duration,constraintDate:this.activity.constraint_date,activityCalendar:this.activityCalendar,activity:this.activity});return t?t.ef>r.ef?r:t:r}calculateSSLink({lag:t,predecessorEs:r}){let i=Eo({linkType:U.SS,lag:t,predecessorTime:r,activityCalendar:this.activityCalendar,activity:this.activity}),n=R(this.activityCalendar,i,t,this.activity);t>0&&(n=Gr(n,U.SS,this.activityCalendar,this.activity));let o=R(this.activityCalendar,n,this.activity.duration,this.activity);return{es:n,ef:o}}calculateFFLink({lag:t,predecessorEf:r}){let i=Eo({linkType:U.FF,lag:t,predecessorTime:r,activityCalendar:this.activityCalendar,activity:this.activity}),n=R(this.activityCalendar,i,t,this.activity),o=R(this.activityCalendar,n,-this.activity.duration,this.activity);return t>0&&(o=Gr(o,U.FF,this.activityCalendar,this.activity)),{es:o,ef:n}}calculateFSLink({lag:t,predecessorEf:r}){let i=r;t===0&&(i=Mt({dateBaseToCalculate:r,activityCalendar:this.activityCalendar,direction:"future",activity:this.activity}));let n=R(this.activityCalendar,i,t,this.activity),o=R(this.activityCalendar,n,this.activity.duration,this.activity);return{es:n,ef:o}}calculateSFLink({lag:t,predecessorEs:r}){let i=R(this.activityCalendar,r,t,this.activity),n=R(this.activityCalendar,i,-this.activity.duration,this.activity);return t>0&&(n=Gr(n,U.SF,this.activityCalendar,this.activity)),{es:n,ef:i}}},xc=Do;var _o=class{constructor(t){this.linkedActivitiesData=t.linksWithActivityData,this.activity=t.activity,this.gantt=t.gantt}calculate(){if(this.activityCalendar=this.gantt.getCalendar(this.activity.calendar_id),!this.activityCalendar)throw new Error(`Error trying to get calendar with id: ${this.activity.calendar_id}`);let t=[];for(let r of this.linkedActivitiesData){let i=Ue(r.linkType);if(r.type===D.TASK&&Number(r.progress)>0||r.type===D.PROJECT&&Number(r.progress)===100)continue;let n=r.linkLag,o=r.ls,a=r.lf;if(i===U.SS){let s={lag:n,workTime:o,lsDataCalculation:-n,lfDataCalculation:this.activity.duration},{ls:c,lf:l}=this.calculateSSLink(s);t.push({ls:c,lf:l})}if(i===U.FF){let s={lag:n,workTime:a,lsDataCalculation:-this.activity.duration,lfDataCalculation:-n},{ls:c,lf:l}=this.calculateFFLink(s);t.push({ls:c,lf:l})}if(i===U.FS){let s={lag:n,workTime:o,lsDataCalculation:-this.activity.duration,lfDataCalculation:-n},{ls:c,lf:l}=this.calculateFsLink(s);t.push({ls:c,lf:l})}if(i===U.SF){let s={lag:n,workTime:a,lsDataCalculation:-n,lfDataCalculation:this.activity.duration},{ls:c,lf:l}=this.calculateSFLink(s);t.push({ls:c,lf:l})}}if(this.activity.constraint_type===h.FNLT){let r=this.getMinLfFromLinks(t),i=this.calculateSfRestrictionDates();return r?this.getMinLfFromLinks([i,r]):i}else{let r=this.getMinLfFromLinks(t);if(r===!1){let i=this.gantt.getSubtaskDates();return{ls:R(this.activityCalendar,i.end_date,-this.activity.duration,this.activity),lf:i.end_date}}return r}}calculateFFLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n}){let o=null,a=null;if(t===0)return o=R(this.activityCalendar,r,n,this.activity),a=R(this.activityCalendar,o,i,this.activity),{ls:a,lf:o};let s=r;return t>0&&(s=this.getLastWorkingHour(s,this.activityCalendar,K.PAST)),o=R(this.activityCalendar,s,n,this.activity),a=R(this.activityCalendar,o,i,this.activity),{ls:a,lf:o}}calculateFsLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n,isMilestone:o=!1}){let a=null,s=null;if(t===0){let l=this.getLastWorkingHour(r,this.activityCalendar,K.PAST);return a=R(this.activityCalendar,l,n,this.activity),a=this.getLastWorkingHour(a,this.activityCalendar,K.PAST),s=R(this.activityCalendar,a,i,this.activity),{ls:s,lf:a}}let c=r;return o||(c=this.getLastWorkingHour(r,this.activityCalendar)),a=R(this.activityCalendar,c,n,this.activity),s=R(this.activityCalendar,a,i,this.activity),o||(a=this.getLastWorkingHour(a,this.activityCalendar,K.PAST)),{ls:s,lf:a}}calculateSFLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n}){let o=null,a=null,s=r;return a=R(this.activityCalendar,s,i,this.activity),o=R(this.activityCalendar,a,n,this.activity),{ls:a,lf:o}}calculateSSLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n,isMilestone:o=!1}){let a=null,s=null;if(t===0)return s=R(this.activityCalendar,r,i,this.activity),a=R(this.activityCalendar,s,n,this.activity),{ls:s,lf:a};let c=r;return t<0&&!o&&(c=this.getLastWorkingHour(c,this.activityCalendar,"future")),s=R(this.activityCalendar,c,i,this.activity),a=R(this.activityCalendar,s,n,this.activity),{ls:s,lf:a}}getMinLfFromLinks(t=[]){return t.length?t.reduce((r,i)=>i.lf<r.lf?i:r):!1}calculateSfRestrictionDates(){let t=this.activity.constraint_date,r=this.activity.duration;return{ls:R(this.activityCalendar,t,-r,this.activity),lf:t}}getLastWorkingHour(t,r,i=K.PAST){let n=t instanceof Date?t:new Date(t),o=Vt(n).clone();return this.isActivityInInitHour(r,n)&&i===K.PAST&&(o=o.hours(0).minutes(0).seconds(0).milliseconds(0)),Mt({dateBaseToCalculate:new Date(o),direction:i,activityCalendar:r,activity:this.activity})}isActivityInInitHour(t,r){let i=r instanceof Date?r:new Date(r),o=t.getWorkHours(i)[0];if(!o||!o.includes("-"))return!1;let a=o.split("-")[0];if(!a.includes(":"))return!1;let s=a.split(":");return s.length<2?!1:(a=parseInt(s[0],10),Vt.isMoment(r)?r.hours()===a:i.getUTCHours()===a)}},Mc=_o;function Uc(e){let{parent:t,linkProperty:r,linkDirection:i,calculations:n,gantt:o,direction:a,linkCandidates:s}=e,c=t[r],l=Fh(t),d=null;if(a===G.FORWARD){let u=wh(c,i,n,o);d=new xc(u,t,o,s),d=d.calculate()}else{let u=xh(c,i,n,o);d=new Mc({linksWithActivityData:u,activity:t,parentData:l,gantt:o}).calculate()}return d}function Fh(e){return{duration:e.duration,calendarId:e.calendar_id}}function wh(e,t,r,i){return e.length===0?[]:e.map(n=>{let o=i.getLink(n);if(!o)return console.warn(`Link not found: ${n}`),null;let a=Number(o[t]),s=r.get(a);return s?{linkId:String(o.id),es:s.es,ef:s.ef,linkLag:o.lag,linkType:o.type}:(console.warn(`Calculations not found for activity: ${a}`),null)}).filter(Boolean)}function xh(e,t,r,i){return e.length===0?[]:e.map(n=>{let o=i.getLink(n);if(!o)return console.warn(`Link not found: ${n}`),null;let a=Number(o[t]),s=r.get(a);if(!s)return null;let c=i.getTask(a);return c?{ls:s.ls,lf:s.lf,linkLag:o.lag||0,linkType:o.type,progress:c.progress,type:c.type}:null}).filter(Boolean)}function Wc(e){let{activityData:t,calculations:r,singleParents:i,direction:n}=e;if(Mh(t.id,r))return null;let o=Uh(t.id,i),a=Bh(o,r);return a.length===0?null:Hh(a,n)}function Mh(e,t){return t.has(e)}function Uh(e,t){let r=t.get(e);return r?r.childrens:[]}function Bh(e,t){return e.filter(r=>t.has(r)).map(r=>t.get(r))}function Hh(e,t){if(t===G.FORWARD){let r=Bc(e,"es"),i=Hc(e,"ef");return{es:r,ef:i}}else{let r=Bc(e,"ls"),i=Hc(e,"lf");return{ls:r,lf:i}}}function Bc(e,t){return e.reduce((r,i)=>i[t]<r[t]?i:r)[t]}function Hc(e,t){return e.reduce((r,i)=>i[t]>r[t]?i:r)[t]}var ko={parentWithLinks:Uc,parentWithNoLinks:Wc};var Ro=class{constructor(t){this.activity=t.activity,this.direction=t.direction,this.linkProperty=t.direction===G.FORWARD?"$target":qt.SOURCE,this.linkDirection=t.direction===G.FORWARD?"source":"target",this.calculationsOfParentThatImpactChildrens=t.calculationsOfParentThatImpactChildrens,this.calculations=t.calculations,this.calculationOfParentsFromLinks=t.calculationOfParentsFromLinks,this.singleParents=t.singleParents,this.parentCalculationFromChildren=t.parentCalculationFromChildren,this.linkCandidates=t.linkCandidates,this.gantt=t.gantt}handleParentWithLinks(){try{let t=this.getArrayOfIdOfLinkedActivities(this.activity[this.linkProperty]);if(this.direction===G.BACKWARD){let i=[h.FNLT];if(this.shouldCalculateParentWithLinksBackward(i)){this.calculateAndStoreParentWithLinks(this.activity);return}if(this.shouldSetDatesToParentsWithLinks(i)){this.setDatesToParentsWithLinksBackward();return}}if(this.areAllLinksCalculated(t)&&this.calculationsOfParentThatImpactChildrens.has(this.activity.id)){this.direction===G.FORWARD&&this.setDatesToParentsWithLinks(),this.direction===G.BACKWARD&&this.setDatesToParentsWithLinksBackward();return}this.calculateAndStoreParentWithLinks(this.activity)}catch(t){throw t}}shouldCalculateParentWithLinksBackward(t){let r=t.includes(this.activity.constraint_type),i=!this.calculationOfParentsFromLinks.has(this.activity.id);return r&&i}calculateAndStoreParentWithLinks(t){let r=ko.parentWithLinks({parent:t,linkProperty:this.linkProperty,linkDirection:this.linkDirection,gantt:this.gantt,calculations:this.calculations,direction:this.direction,linkCandidates:this.linkCandidates});this.calculationsOfParentThatImpactChildrens.set(t.id,r),this.calculationOfParentsFromLinks.add(t.id)}areAllLinksCalculated(t){return t.every(r=>this.calculations.has(r))}shouldSetDatesToParentsWithLinks(t){let r=t.includes(this.activity.constraint_type),i=this.calculationOfParentsFromLinks.has(this.activity.id);return r&&i}handleParentWithNoLinks(){let t=ko.parentWithNoLinks({activityData:this.activity,gantt:this.gantt,singleParents:this.singleParents,calculations:this.calculations,direction:this.direction});t&&this.calculations.set(this.activity.id,t)}setDatesToParentsWithLinks(){if(!this.activity)throw new Error("Error trying to get parent",{cause:{parentActivity:this.activity}});let t=this.singleParents.get(this.activity.id)?.childrens,i=Array.from(this.calculations).filter(a=>t.includes(a[0])).map(a=>a[1]),{minEs:n,maxEf:o}=i.reduce((a,{es:s,ef:c})=>({minEs:new Date(Math.min(a.minEs.getTime(),new Date(s).getTime())),maxEf:new Date(Math.max(a.maxEf.getTime(),new Date(c).getTime()))}),{minEs:new Date(i[0].es),maxEf:new Date(i[0].ef)});this.calculations.set(this.activity.id,{es:n,ef:o}),this.parentCalculationFromChildren.add(this.activity.id)}setDatesToParentsWithLinksBackward(){if(!this.activity)throw new Error("Error trying to get parent",{cause:{parentActivity:this.activity}});let t=this.singleParents.get(this.activity.id)?.childrens,i=Array.from(this.calculations).filter(a=>t.includes(a[0])).map(a=>a[1]),{minLs:n,maxLf:o}=i.reduce((a,{ls:s,lf:c})=>({minLs:new Date(Math.min(a.minLs.getTime(),new Date(s).getTime())),maxLf:new Date(Math.max(a.maxLf.getTime(),new Date(c).getTime()))}),{minLs:new Date(i[0].ls),maxLf:new Date(i[0].lf)});this.calculations.set(this.activity.id,{ls:n,lf:o})}getArrayOfIdOfLinkedActivities(t,r=!1){return t.map(i=>{let o=this.gantt.getLink(i)[r||this.linkDirection];return Number(o)})}},Vc=Ro;var Po=class{constructor({gantt:t,linkProperty:r}){this.gantt=t,this.linkProperty=r,this.structureOfParents=new Map,this.singleParents=new Map}identifyThirdLevelActivities(){try{let t=this.getFirstLevelParents();for(let r of t){let i=this.processEachActivity(r),{activitiesByLevel:n}=i,o=this.getAllLevels(n),a=this.getDeepestLevel(o),s=this.createResult(r,i,a,o);this.structureOfParents.set(r.id,s)}return{structureOfParents:this.structureOfParents,singleParents:this.singleParents}}catch(t){throw t}}getFirstLevelParents(){return this.gantt.getTaskByTime().filter(Lt.byFirstLevel).filter(Lt.filterByParentType)}processEachActivity(t){let r=new Set,i=new Set,n=new Map;return this.initializeParent(t),this.gantt.eachTask(o=>{this.processActivity(o,r,i,n)},t.id),{parentsIds:r,allTasks:i,activitiesByLevel:n}}initializeParent(t){let r=Number(t.id),i=!!t[this.linkProperty]?.length,n=t.$level;this.singleParents.set(r,{level:n,hasLink:i,childrens:[]})}processActivity(t,r,i,n){let o=Number(t.id),a=Number(t.parent);i.add(o),this.isProjectActivity(t)&&this.addParentInfo(t,r);let c=this.doesParentExist(a);a!=null&&c&&this.addChildToParent(a,o),this.addActivityToLevel(t,n)}isProjectActivity(t){return t.type===D.PROJECT}hasLink(t){return!!t[this.linkProperty]?.length}addParentInfo(t,r){let i=Number(t.id),n=t.$level,o=this.hasLink(t),a={level:n,hasLink:o,childrens:[]};r.add(i),this.singleParents.set(i,a)}doesParentExist(t){return this.singleParents.has(t)}addChildToParent(t,r){this.singleParents.get(t).childrens.push(r)}addActivityToLevel(t,r){let i=t.$level,n=Number(t.parent);r.has(i)||r.set(i,new Map);let o=r.get(i);o.has(n)||o.set(n,[]),o.get(n).push({id:Number(t.id),isParent:this.isProjectActivity(t),calculated:!1})}getAllLevels(t){return new Set(t.keys())}getDeepestLevel(t){return t.size===0?0:Math.max(...t)}createResult(t,r,i,n){let{activitiesByLevel:o,parentsIds:a,allTasks:s}=r;return{parent:t.id,isALinkedParent:this.hasLink(t),levels:n,allParentChildrens:a,allChildrens:s,childrensByLevel:o,currentResolutionLevel:i,canBeCalculated:!1}}},Kc=Po;var Lo=class{constructor(t,r){this.direction=r,this.gantt=t,this.linkProperty=this.direction===G.FORWARD?"$target":qt.SOURCE,this.linkDirection=this.direction===G.FORWARD?"source":"target",this.projectDates=t.getSubtaskDates()}tryToCalculateLastLevelChildrens(){this.structureOfParents.forEach(t=>{let{currentResolutionLevel:r,childrensByLevel:i,isALinkedParent:n}=t;if(n)return;let o=i.get(r);for(let[a,s]of o)if(s.filter(l=>!this.calculations.has(l.id)).length===0){let l=this.gantt.getTask(a);this.calculateParentWithNoLinks(l,s);return}})}initActivitiesWaitingForCalculation(){try{this.gantt.getTaskByTime().filter(Lt.avoidSubproject).forEach(t=>{this.activitiesWaitingForCalculation.add(t.id)})}catch(t){throw t}}identifyParentsWithAndWithoutLinks(){try{let{parentsWithFullProgress:t,pendingParentsWithNoLinks:r,pendingParentsWithLinks:i}=Yr.identifyParentsWithAndWithoutLinks({gantt:this.gantt,direction:this.direction,linkProperty:this.linkProperty});this.parentsWithFullProgress=t,this.pendingParentsWithNoLinks=r,this.pendingParentsWithLinks=i}catch(t){throw t}}identifyForbiddenActivitiesLinkedToParentsWithLinks(){try{this.forbiddenActivitiesLinkedToParentsWithLinks=Yr.identifyForbiddenActivities({pendingParentsWithLinks:this.pendingParentsWithLinks,gantt:this.gantt,direction:this.direction})}catch(t){throw t}}getArrayOfIdOfLinkedActivities(t,r=!1){return t.map(i=>{let o=this.gantt.getLink(i)[r||this.linkDirection];return Number(o)})}async identifyThirdLevelActivities(){try{let{structureOfParents:t,singleParents:r}=new Kc({gantt:this.gantt,linkProperty:this.linkProperty}).identifyThirdLevelActivities();this.structureOfParents=t,this.singleParents=r}catch(t){throw t}}processEachActivity(t){let r=new Set,i=new Set,n=new Map,o=new Map;return this.singleParents.set(Number(t.id),{level:t.$level,hasLink:!!t[this.linkProperty].length,childrens:[]}),new Promise((a,s)=>{this.gantt.eachTask(function(c){let l=Number(c.parent);if(i.add(c.id),c.type===D.PROJECT){let u={level:c.$level,hasLink:!!c[this.linkProperty].length,childrens:[]};r.add(c.id),this.singleParents.set(Number(c.id),u)}l&&this.singleParents.has(l)&&this.singleParents.get(l).childrens.push(c.id),n.has(c.$level)||n.set(c.$level,new Map);let d=n.get(c.$level);d.has(Number(c.parent))||d.set(Number(c.parent),[]),d.get(Number(c.parent)).push({id:c.id,isParent:c.type===D.PROJECT,calculated:!1})}.bind(this),t.id),a({parentsIds:r,allTasks:i,activitiesByLevel:n,singleParents:o})})}identifySecondLevelActivities(){try{let t=Yr.identifySecondLevelActivities({gantt:this.gantt,pendingParentsWithNoLinks:this.pendingParentsWithNoLinks,calculations:this.calculations,linkProperty:this.linkProperty});this.secondLevelActivities=new Set([...this.secondLevelActivities,...t])}catch(t){throw t}}identifyInitialActivities(){try{let{chainStartActivities:t,activitiesStartChainButChildrenOfLinkedParents:r}=Yr.identifyInitialActivities({gantt:this.gantt,linkProperty:this.linkProperty,direction:this.direction});this.chainStartActivities=t,r&&(this.activitiesStartChainButChildrenOfLinkedParents=r)}catch(t){throw new Error("Error in identifyInitialActivities",{cause:t})}}calculateSecondLevelActivities(){try{this.direction===G.FORWARD?this.recursiveCalculateEfAndEs(Array.from(this.secondLevelActivities),0,"secondLevel"):this.recursiveCalculateLfAndLs(Array.from(this.secondLevelActivities))}catch(t){throw t}}calculateStartAndFinishOfActivitiesThatStartChain(){try{this.chainStartActivities.forEach(t=>{if(!t||t.progress>100||t.type===D.PROJECT)return;let r=this.calculateStartAndFinishOfChainOrigin(t,this.direction);if(this.direction===G.FORWARD){let{es:i,ef:n}=r;this.calculations.set(t.id,{es:i,ef:n,text:t.text}),this.activitiesWaitingForCalculation.delete(t.id)}else{let{ls:i,lf:n}=r;this.calculations.set(t.id,{ls:i,lf:n,text:t.text}),this.activitiesWaitingForCalculation.delete(t.id)}})}catch(t){throw t}}buildDependencyGraph(t){let r=new Map,i=new Set(this.calculations.keys()),n=new Map;return t.forEach(o=>{o&&n.set(o.id,o)}),n.forEach((o,a)=>{if(i.has(a))return;let s=[];(o[this.linkDirection]||[]).forEach(l=>{let d=this.gantt.getLink(l);if(d){let u=Number(d[this.linkProperty]);s.push(u)}}),s=s.filter(l=>n.has(l)||i.has(l)),r.set(a,s)}),{graph:r,activityMap:n,calculatedActivities:i}}topologicalSort(t,r){let i=new Set,n=new Set,o=[],a=s=>{if(n.has(s))throw new Error("Cyclical dependency detected",{cause:{nodeId:s}});if(!i.has(s)&&!r.has(s)){n.add(s);let c=t.get(s)||[];for(let l of c)a(l);n.delete(s),i.add(s),o.push(s)}};for(let s of t.keys())!i.has(s)&&!r.has(s)&&a(s);return o.reverse()}calculateStartAndFinishOfChainOrigin(t=null,r=null){try{let i=t,n=Number(i.progress);n==="0.00"&&(n=0);let o=this.gantt.getCalendar(i.calendar_id);if(!o)throw new Error(`Error trying to get calendar with id: ${i.calendar_id}`);if((r||this.direction)===G.FORWARD){let s=i.start_date,c=i.end_date;return{es:s,ef:c}}else{if(n>=100)return{ls:Vt(i.start_date).clone(),lf:Vt(i.end_date).clone()};if(n===0)return this.calculateBackwardWhenZeroProgress(i,o);if(n<100&&n>0)return this.calculateWhenProgressIsBetweenZeroAndOneHundred(i,o)}}catch(i){throw i}}calculateBackwardWhenZeroProgress(t,r){let i=Vt(t.start_date).clone(),n=Vt(t.end_date).clone(),o=t.duration,a=[h.ASAP,h.ALAP,h.SNET,h.FNET],s=t.constraint_type||h.ASAP;if(a.includes(s))n=this.projectDates.end_date,i=R(r,n,-o,t);else{let c=[h.SNLT,h.MSO],l=[h.FNLT,h.MFO];c.includes(s)&&(i=t.constraint_date,n=R(r,i,o,t)),l.includes(s)&&(n=t.constraint_date,i=R(r,n,-o,t))}return{ls:i,lf:n}}calculateWhenProgressIsBetweenZeroAndOneHundred(t){let r=t.start_date,i=null,n=t.constraint_type||h.ASAP,o=this.projectDates.end_date,a=[h.ASAP,h.ALAP,h.SNET,h.FNET],s=[h.SNLT,h.FNLT];if(a.includes(n))i=Math.max(t.end_date,o);else if(n===h.MSO)i=t.end_date;else if(n===h.MFO||s.includes(n)){let c=Math.min(o,t.constraint_date);i=Math.max(c,t.end_date)}return{ls:r,lf:new Date(i)}}initializeActivitiesWithFullProgress(){try{Array.from(this.activitiesWaitingForCalculation).filter(i=>Number(this.gantt.getTask(i).progress)===100).map(i=>this.gantt.getTask(i)).forEach(i=>{let n=i.type===D.PROJECT;this.setDatesForActivityWithFullProgress(i),this.activitiesWaitingForCalculation.delete(i.id),n&&this.pendingParentsWithLinks.has(i.id)&&(this.parentCalculationFromChildren.add(i.id),this.calculationsOfParentThatImpactChildrens.set(i.id,{[this.direction===G.FORWARD?"es":"ls"]:i.start_date,[this.direction===G.FORWARD?"ef":"lf"]:i.end_date}),this.calculationOfParentsFromLinks.add(i.id))})}catch(t){throw t}}doCalculationForParentType(t){let r=new Vc({activity:t,direction:this.direction,calculationsOfParentThatImpactChildrens:this.calculationsOfParentThatImpactChildrens,calculations:this.calculations,calculationOfParentsFromLinks:this.calculationOfParentsFromLinks,singleParents:this.singleParents,parentCalculationFromChildren:this.parentCalculationFromChildren,linkCandidates:this.linkCandidates,gantt:this.gantt});this.pendingParentsWithLinks.has(t.id)?r.handleParentWithLinks():r.handleParentWithNoLinks()}},De=Lo;function Wh(e,t,r){let i={es:null,ef:null};if(!e)return i;if([h.SNET,h.SNLT].includes(t)){let n=new Date(e.constraint_date);i.es=n,i.ef=R(r,n,e.duration,e)}else if([h.FNLT,h.FNET].includes(t)){let n=new Date(e.constraint_date);i.es=R(r,n,-e.duration,e),i.ef=n}else if(t===h.MSO){let n=new Date(e.constraint_date);i.es=n,i.ef=R(r,n,e.duration,e)}else if(t===h.MFO){let n=new Date(e.constraint_date);i.es=R(r,n,-e.duration,e),i.ef=n}return i}var Xi=Wh;var Oo=class{constructor(t){this.referenceActivity=t.activity,this.activityToCalculate=null,this.links=t.links,this.calculatedActivities=t.calculatedActivitiesMap,this.alapMap=t.calculatedAlapsMap,this.parentsWithLinks=t.parentsWithLinks,this.parentsCalculations=t.parentsCalculations,this.gantt=t.ganttInstance,this.linkCandidates=t.linkCandidates}getEsAndEfFromPreviousCalculatedActivities(t){return this.alapMap.has(t)?this.alapMap.get(Number(t)):this.calculatedActivities.get(Number(t))}calculateSucessorTimes(t,r,i=0,n,o=U.FS){let a=this.gantt.getCalendar(this.referenceActivity.calendar_id);if(!a)throw new Error(`Error trying to get calendar with id: ${this.referenceActivity.calendar_id}`);let s=t,c=null,l=null,d=this.referenceActivity.type===D.MILESTONE;return d||(o===U.FS&&n===0?s=Mt({dateBaseToCalculate:s,activityCalendar:a,direction:"future",activity:this.referenceActivity}):s=this.mutateTheDateToFutureOrPastInBaseRestriction(t,o,a)),[U.FF,U.SF].includes(o)?(l=R(a,s,i,this.referenceActivity),c=R(a,l,r,this.referenceActivity),!d&&n>0&&(c=this.mutateTheDateToFutureOrPastInBaseRestriction(c,o,a))):(c=R(a,s,r,this.referenceActivity),!d&&n>0&&(c=this.mutateTheDateToFutureOrPastInBaseRestriction(c,o,a)),l=R(a,c,i,this.referenceActivity)),{es:c,ef:l}}calculateSS(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),i=t.lag||0,o=this.referenceActivity.duration,a=t.lag||0;return this.calculateSucessorTimes(r.es,i,o,a,U.SS)}calculateFF(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),n=-this.referenceActivity.duration,o=t.lag||0,a=t.lag||0;return this.calculateSucessorTimes(r.ef,n,o,a,U.FF)}calculateFS(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),i=t.lag||0,o=this.referenceActivity.duration,a=t.lag||0;return this.calculateSucessorTimes(r.ef,i,o,a,U.FS)}calculateSF(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),n=-this.referenceActivity.duration,o=t.lag||0,a=t.lag||0;return this.calculateSucessorTimes(r.es,n,o,a,U.SF)}mutateTheDateToFutureOrPastInBaseRestriction(t,r,i){if(![U.FS,U.SS,U.FF].includes(r))return t;let o=[U.FS,U.SS].includes(r)?"future":K.PAST;return Mt({dateBaseToCalculate:t,activityCalendar:i,direction:o,activity:this.referenceActivity})}},jc=Oo;var $r=class extends jc{constructor(t){super(t)}calculate(){if(this.links.length===0)return new De(this.gantt,"forward").calculateStartAndFinishOfChainOrigin(this.referenceActivity);let t=this.links.map(i=>{let n=this.gantt.getLink(i);if(!n)throw new Error("Link data not found",{cause:{linkId:i}});let o=this.calculateLink(n);return this.linkCandidates?.set(String(n.id),{targetId:String(this.referenceActivity.id),...o}),o}),r=Number(this.referenceActivity.parent);if(this.parentsWithLinks.has(r)){let i=this.gantt.getCalendar(this.referenceActivity.calendar_id),n=this.parentsCalculations.get(r).es,o=R(i,n,this.referenceActivity.duration,this.referenceActivity);t.push({es:n,ef:o})}return Ji(t)}calculateLink(t){return{0:()=>this.calculateFS(t),1:()=>this.calculateSS(t),2:()=>this.calculateFF(t),3:()=>this.calculateSF(t)}[t.type]()}};var No=class{constructor(t){this.gantt=t.gantt,this.direction=t.direction,this.pendingParentsWithNoLinks=t.pendingParentsWithNoLinks,this.pendingParentsWithLinks=t.pendingParentsWithLinks,this.calculationOfParentsFromLinks=t.calculationOfParentsFromLinks,this.singleParents=t.singleParents,this.calculations=t.calculations,this.activitiesStartChainButChildrenOfLinkedParents=t.activitiesStartChainButChildrenOfLinkedParents,this.linkProperty=t.linkProperty,this.linkDirection=t.linkDirection}checkActivitiesThatNowCanBeCalculated(t){let r=new Set,i=new Set(t);for(let n of t){let o=this.gantt.getTask(n);o.type===D.PROJECT?this.handleProjectActivity(n,o,r,i):this.handleNonProjectActivity(n,o,r,i)}return{activitiesThatCanBeCalculated:r,pendingActivities:i}}handleProjectActivity(t,r,i,n){let o=this.pendingParentsWithNoLinks.has(t),a=this.pendingParentsWithLinks.has(t),s=this.calculationOfParentsFromLinks.has(t);if(o){let c=this.singleParents.get(t)?.childrens;if(!c)return;c.every(d=>this.calculations.has(d))&&(i.add(t),n.delete(t));return}if(a&&s){let c=this.singleParents.get(t)?.childrens;if(!c)return;c.every(d=>this.calculations.has(d))&&(i.add(t),n.delete(t));return}a&&!s&&this.canCalculateParentActivity(r)&&(i.add(t),n.delete(t))}canCalculateParentActivity(t){let r=(t[this.linkProperty]||[]).length===0,i=t.constraint_type;return(this.direction===G.FORWARD?i===h.FNLT||i===h.SNLT:i===h.FNLT)&&r?!0:this.getArrayOfLinkedActivities(t[this.linkProperty]).every(a=>this.calculations.has(a))}handleNonProjectActivity(t,r,i,n){let o=Number(r.parent),a=this.pendingParentsWithLinks.has(o),s=this.calculationOfParentsFromLinks.has(o);if(a&&!s||this.direction===G.BACKWARD&&this.activitiesStartChainButChildrenOfLinkedParents.has(t)&&!s)return;if(r.$target.length===0&&r[qt.SOURCE].length===0){i.add(t),n.delete(t);return}let c=this.getLinkedActivities(r[this.linkProperty]),l=c.every(d=>this.calculations.has(d.id));if(this.direction===G.BACKWARD&&(c.length===0||l)&&s){i.add(t),n.delete(t);return}l&&(i.add(t),n.delete(t))}getLinkedActivities(t){if(!Array.isArray(t))return[];let r=[];for(let i of t){let n=this.gantt.getLink(i);if(!n)continue;let o=n[this.linkDirection],a=this.gantt.getTask(o);a&&r.push(a)}return r}getArrayOfLinkedActivities(t){if(!Array.isArray(t))return[];let r=[];for(let i of t){let n=this.gantt.getLink(i);n&&r.push(Number(n[this.linkDirection]))}return r}},Zi=No;var bo=(e,t)=>()=>t()===e;var Fo=e=>!e?.fullyParsed;var Vh=16,He=async e=>performance.now()-e>Vh?(await st(),performance.now()):e;var zr=async({pending:e,activityCalculator:t,calculateFn:r,shouldKeepPending:i,isCalculated:n,onActivityProcessed:o,isCurrent:a})=>{let s=new Set(e),c=performance.now();for(;s.size>0;){if(!a())return;c=await He(c);let{activitiesThatCanBeCalculated:l,pendingActivities:d}=t.checkActivitiesThatNowCanBeCalculated(s);if(l.size===0)break;for(let u of l){if(!a())return;c=await He(c),r([u])}for(let u of l){if(!a())return;i(u)&&d.add(u),o(u),n(u)&&d.delete(u)}s=d}};var wo=class extends De{constructor(t){super(t,G.FORWARD),this.gantt=t,this.chainStartActivities=new Set,this.secondLevelActivities=new Set,this.pendingParentsWithLinks=new Set,this.pendingParentsWithNoLinks=new Set,this.structureOfParents=new Map,this.singleParents=new Map,this.calculations=new Map,this.calculationsOfParentThatImpactChildrens=new Map,this.alapMap=new Map,this.activitiesWaitingForCalculation=new Set,this.constraintsMap=new Map,this.totalFloatSnltFnlt=new Map,this.totalFloatForMsoMfo=new Map,this.totalFloatForAsap=new Map,this.linkCandidates=new Map,this.calculationOfParentsFromLinks=new Set,this.parentCalculationFromChildren=new Set,this.forbiddenActivitiesLinkedToParentsWithLinks=new Set,this.activitiesStartChainButChildrenOfLinkedParents=new Set,this.identifyInitialActivities(),this.initActivitiesWaitingForCalculation()}async calculateAsync(t){this.identifyParentsWithAndWithoutLinks(),t()&&(this.identifyForbiddenActivitiesLinkedToParentsWithLinks(),t()&&(this.initializeActivitiesWithFullProgress(),t()&&(this.calculateStartAndFinishOfActivitiesThatStartChain(),t()&&(this.identifySecondLevelActivities(),t()&&(this.identifyThirdLevelActivities(),t()&&await this.iterativeCalculateEfAndEs(t))))))}async iterativeCalculateEfAndEs(t){let r=new Zi({gantt:this.gantt,direction:this.direction,pendingParentsWithNoLinks:this.pendingParentsWithNoLinks,pendingParentsWithLinks:this.pendingParentsWithLinks,calculationOfParentsFromLinks:this.calculationOfParentsFromLinks,singleParents:this.singleParents,calculations:this.calculations,activitiesStartChainButChildrenOfLinkedParents:this.activitiesStartChainButChildrenOfLinkedParents,linkProperty:this.linkProperty,linkDirection:this.linkDirection});await zr({pending:this.activitiesWaitingForCalculation,activityCalculator:r,calculateFn:i=>this.calculateStartAndFinishTimes(i),shouldKeepPending:i=>this.calculationOfParentsFromLinks.has(i)&&!this.calculations.has(i),isCalculated:i=>this.calculations.has(i),onActivityProcessed:i=>this.activitiesWaitingForCalculation.delete(i),isCurrent:t})}calculateStartAndFinishTimes(t){t.forEach(r=>{let i=this.gantt.getTask(r);if(i.type===D.PROJECT)return this.doCalculationForParentType(i);if(!i)throw new Error("Error trying to get activity",{cause:{activityId:r}});let n=i.$target,o=i.constraint_type||h.ASAP,a=[h.SNET,h.SNLT,h.FNLT,h.FNET],s=[h.ASAP,h.ALAP,h.SNET,h.FNET,h.SNLT,h.FNLT],c=this.gantt.getCalendar(i.calendar_id);if(!c)throw new Error(`Error trying to get calendar with id: ${i.calendar_id}`);let l=Number(i.progress),d=null,u=null,f=null;if(l===100){this.setDatesForActivityWithFullProgress(i);return}l>0&&s.includes(o)?({es:d,ef:u}=this.getDatesForActivityWithZeroProgress(i),f=new $r({links:n,activity:i,calculatedActivitiesMap:this.calculations,calculatedAlapsMap:this.alapMap,constraint:o,parentsWithLinks:this.pendingParentsWithLinks,parentsCalculations:this.calculationsOfParentThatImpactChildrens,ganttInstance:this.gantt,linkCandidates:this.linkCandidates}).calculate(),o===h.ASAP&&this.totalFloatForAsap.set(r,{es:f.es,ef:f.ef,text:i.text})):{es:d,ef:u}=new $r({links:n,activity:i,calculatedActivitiesMap:this.calculations,calculatedAlapsMap:this.alapMap,constraint:o,parentsWithLinks:this.pendingParentsWithLinks,parentsCalculations:this.calculationsOfParentThatImpactChildrens,ganttInstance:this.gantt,linkCandidates:this.linkCandidates}).calculate(),o===h.ALAP&&this.alapMap.set(r,{es:i.start_date,ef:i.end_date,text:i.text});let p=Xi(i,o,c);if(a.includes(o)&&(this.constraintsMap.set(r,p),this.totalFloatSnltFnlt.set(r,{es:d,ef:u}),{es:d,ef:u}=this.recalculateInBaseConstraint(o,p,{es:d,ef:u})),[h.MSO,h.MFO].includes(o))if(this.totalFloatForMsoMfo.set(r,{es:d,ef:u}),this.constraintsMap.set(r,p),i.progress===0)d=p.es,u=p.ef;else{let y=i.end_date;o===h.MFO&&(y=Math.max(p.ef,i.end_date)),d=i.start_date,u=y}this.calculations.set(r,{es:d,ef:u}),this.activitiesWaitingForCalculation.delete(r)})}getTheGreatesDateBetweenRestrictionAndEsEf(t,r,i=Be.GREATER){if(i===Be.GREATER)return r.ef>t.ef?r:t;if(i===Be.LESS)return r.ef<t.ef?r:t}setDatesForActivityWithFullProgress(t){this.calculations.set(t.id,{es:t.start_date,ef:t.end_date})}getDatesForActivityWithZeroProgress(t){return{es:t.start_date,ef:t.end_date}}recalculateInBaseConstraint(t,r,i){let n=[h.SNET,h.FNET].includes(t)?Be.GREATER:Be.LESS,{es:o,ef:a}=this.getTheGreatesDateBetweenRestrictionAndEsEf(r,i,n);return{es:o,ef:a}}cleanAllActivityParentsFromLinks(t){return t.map(r=>{let i=this.gantt.getLink(r);if(!i)throw new Error("Error trying to get link",{cause:{linkId:r}});let n=i.source,o=i.target;if(!(!this.gantt.getTask(n)||this.gantt.getTask(n)?.type===D.PROJECT)&&!(!this.gantt.getTask(o)||this.gantt.getTask(o)?.type===D.PROJECT))return r}).filter(Boolean)}},Yc=wo;var xo=class{constructor(t){this.activity=t.activity,this.links=t.links,this.calculatedActivities=t.calculatedActivitiesMap,this.forwardPathCalculations=t.calculatedForwardActivitiesMap,this.gantt=t.ganttInstance}getForwardOrBackwardCalculations(t,r=null){return r===h.ALAP?this.forwardPathCalculations.get(t):this.calculatedActivities.get(t)}calculateSuccessorTimes(t,r,i=0,n,o=U.FS){let a=this.gantt.getCalendar(this.activity.calendar_id);if(!a)throw new Error(`Error trying to get calendar with id: ${this.activity.calendar_id}`);let s=t,c=this.activity.type===D.MILESTONE;if(c&&n===0){let d=R(a,s,r,this.activity),u=R(a,d,i,this.activity);return{ls:d,lf:u}}let l={lag:n,workTime:s,activityCalendar:a,lsDataCalculation:r,lfDataCalculation:i,isMilestone:c};if(o===U.FS){let{ls:d,lf:u}=this.calculateFsLink(l);return{ls:d,lf:u}}if(o===U.FF){let{ls:d,lf:u}=this.calculateFFLink(l);return{ls:d,lf:u}}if(o===U.SS){let{ls:d,lf:u}=this.calculateSSlink(l);return{ls:d,lf:u}}if(o===U.SF){let{ls:d,lf:u}=this.calculateSFLink(l);return{ls:d,lf:u}}}calculateSS(t,r=!1){let i=this.getValueForSS(t,r),n=-t.lag||0,o=this.activity.duration,a=t.lag;return this.calculateSuccessorTimes(i,n,o,a,U.SS)}calculateFF(t,r){let i=this.getForwardOrBackwardCalculations(Number(t.target)),n=r===h.ALAP?"ef":"lf",o=i[n],a=-this.activity.duration,s=-t.lag||0,c=t.lag;return this.calculateSuccessorTimes(o,a,s,c,U.FF)}calculateFS(t,r){let i="ls";i=r===h.ALAP?"es":"ls";let n=this.getForwardOrBackwardCalculations(Number(t.target),r),o=-this.activity.duration,a=t.lag||0,s=-t.lag||0;return this.calculateSuccessorTimes(n[i],o,s,a,U.FS)}calculateSF(t,r=!1){let i=r?this.getEarlyStartFromForwardPath(Number(t.target)).ef:this.getForwardOrBackwardCalculations(Number(t.target)).lf,n=-t.lag||0,o=this.activity.duration,a=t.lag;return this.calculateSuccessorTimes(i,n,o,a,U.SF)}getEarlyStartFromForwardPath(t){return this.forwardPathCalculations.get(t)}getValueForSS(t,r){return r?this.getEarlyStartFromForwardPath(Number(t.target)).es:this.getForwardOrBackwardCalculations(Number(t.target))["ls"]}calculateDate(t,r,i){let n=Vt(r).clone();return R(t,new Date(n),i,this.activity)}getLastWorkingHour(t,r,i=K.PAST){let n=t instanceof Date?t:new Date(t),o=Vt(n).clone();return this.isActivityInInitHour(r,n)&&i===K.PAST&&(o=o.hours(0).minutes(0).seconds(0).milliseconds(0)),Mt({dateBaseToCalculate:new Date(o),direction:i,activityCalendar:r,activity:this.activity})}isActivityInInitHour(t,r){let i=r instanceof Date?r:new Date(r),o=t.getWorkHours(i)[0];if(!o||!o.includes("-"))return!1;let a=o.split("-")[0];if(!a.includes(":"))return!1;let s=a.split(":");return s.length<2?!1:(a=parseInt(s[0],10),Vt.isMoment(r)?r.hours()===a:i.getUTCHours()===a)}calculateFsLink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o,isMilestone:a=!1}){let s=null,c=null;if(t===0){let d=this.getLastWorkingHour(r,i,K.PAST);return s=R(i,d,o,this.activity),s=this.getLastWorkingHour(s,i,K.PAST),c=R(i,s,n,this.activity),{ls:c,lf:s}}let l=r;return a||(l=this.getLastWorkingHour(r,i)),s=R(i,l,o,this.activity),c=R(i,s,n,this.activity),a||(s=this.getLastWorkingHour(s,i,K.PAST,!0)),{ls:c,lf:s}}calculateFFLink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o}){let a=null,s=null;if(t===0)return a=R(i,r,o,this.activity),s=R(i,a,n,this.activity),{ls:s,lf:a};let c=r;return t>0&&(c=this.getLastWorkingHour(c,i,K.PAST)),a=R(i,c,o,this.activity),s=R(i,a,n,this.activity),{ls:s,lf:a}}calculateSSlink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o,isMilestone:a=!1}){let s=null,c=null;if(t===0)return c=R(i,r,n,this.activity),s=R(i,c,o,this.activity),{ls:c,lf:s};let l=r;return t<0&&!a&&(l=this.getLastWorkingHour(l,i,"future")),c=R(i,l,n,this.activity),s=R(i,c,o,this.activity),{ls:c,lf:s}}calculateSFLink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o}){let a=null,s=null;return t===0?(s=R(i,r,n),a=R(i,s,o,this.activity),{ls:s,lf:a}):(s=R(i,r,n,this.activity),a=R(i,s,o,this.activity),{ls:s,lf:a})}},Gc=xo;var Mo=class extends Gc{constructor(t){super(t),this.constraint=t.constraint||h.ASAP,this.parentsWithFullProgress=t.parentsWithFullProgress,this.parentsThatImpactChildrens=t.parentsThatImpactChildrens,this.projectDates=this.gantt.getSubtaskDates()}calculate(){if(this.links.length===0)return new De(this.gantt,G.BACKWARD).calculateStartAndFinishOfChainOrigin(this.activity);let t=this.activity.progress>0&&this.activity.progress<100,r=this.gantt.getTask(this.activity.parent),i=!1;r&&(i=this.parentsThatImpactChildrens.has(Number(this.activity.parent)));let n=this.links.map(a=>{let s=this.gantt.getLink(a);if(!s)throw new Error("Link not found",{cause:{linkId:a}});if(!this.parentsWithFullProgress.has(Number(s.target)))return this.calculateLink(s)}).filter(a=>a);if(n.length!==0){let a=this.getMinLfFromLinks(n);if(n.push(this.calculateTheLsAndLfForTheActivity()),i){let d=this.parentsThatImpactChildrens.get(Number(this.activity.parent));n.push(this.calculateTheLsAndLfForTheActivity(d))}let s=this.getMinDateFromLinks(n),c=s.ls,l=s.lf;return t&&(c=this.activity.start_date,l=this.getMinCalculationLogic(s)),{ls:c,lf:l,minFromLinks:a}}if(i){n.push(this.calculateTheLsAndLfForTheActivity());let s=this.parentsThatImpactChildrens.get(Number(this.activity.parent)).lf,c=R(this.gantt.getCalendar(this.activity.calendar_id),s,-this.activity.duration,this.activity);n.push({ls:c,lf:s});let l=this.getMinDateFromLinks(n);return{ls:l.ls,lf:l.lf,minFromLinks:l}}let o=this.calculateTheLsAndLfForTheActivity();return{ls:o.ls,lf:o.lf,minFromLinks:o}}calculateTheLsAndLfForTheActivity(t=null){try{let r=this.activity.duration,i=this.gantt.getCalendar(this.activity.calendar_id);if(!i)throw new Error(`Calendar not found with id ${this.activity.calendar_id}`);let n=t?t.lf:this.projectDates.end_date;if(!n)throw new Error("End date not found for activity",{cause:{activityId:this.activity.id}});return{ls:R(i,n,-r,this.activity),lf:n}}catch(r){throw Error(r.message)}}SnetSnltMsoMinDate(t){let r=Math.min(t.lf,this.projectDates.end_date);return new Date(Math.max(r,this.activity.end_date))}calculateLink(t){let r=this.gantt.getTask(t.target);if(!r||r.progress>0&&r.type!==D.PROJECT)return;let i=this.getSpecialCalculationParamForConstraintLink(),n=this.getSpecialParamForSf(),o=this.getSpecialParamForFF();return{0:()=>this.calculateFS(t,i),1:()=>this.calculateSS(t),2:()=>this.calculateFF(t,o),3:()=>this.calculateSF(t,n)}[t.type]()}getSpecialCalculationParamForConstraintLink(){if(this.constraint===h.ALAP)return h.ALAP;if(this.constraint===h.FNET||this.constraint===h.SNET)return"snet-fnet";if(this.constraint===h.FNLT)return h.FNLT}getSpecialParamForSf(){return!![h.ALAP].includes(this.constraint)}getSpecialParamForFF(){return!![h.MFO,h.MSO].includes(this.constraint)}getMinCalculationLogic(t){if(this.constraint===h.ALAP)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.FNET)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.FNLT)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.MFO)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.SNET||this.constraint===h.SNLT||this.constraint===h.MSO)return this.SnetSnltMsoMinDate(t);if(this.constraint===h.ASAP)return this.getMinDateBasedOnConstraint(t)}getMinDateFromLinks(t){try{return this.constraint===h.ALAP||this.constraint===h.ASAP?t.reduce((i,n)=>n.lf<i.lf?n:i):t.reduce((r,i)=>i.ls<r.ls?i:r)}catch(r){throw new Error(`Function: getMinDateFromLinks in LinksConstraintCalculator - ${r.message}`)}}getMinLfFromLinks(t){return t.reduce((r,i)=>i.lf<r.lf?i:r)}getMinDateBasedOnConstraint(t,r=this.constraint){let i=Math.min(t.lf,this.projectDates.end_date),n=this.activity.end_date,o=this.activity.constraint_date;if(r===h.ASAP)return new Date(Math.max(i,n));if(r===h.FNET||r===h.FNLT){let a=Math.min(i,o);return new Date(Math.max(i,a))}if(r===h.ALAP)return new Date(Math.min(i,n))}},$c=Mo;function Kh(e,t,r){let i={ls:null,lf:null};return r===h.MSO&&(i.ls=t.constraint_date,i.lf=R(e,i.ls,t.duration,t)),r===h.MFO&&(i.lf=t.constraint_date,i.ls=R(e,i.lf,-t.duration,t)),i}var zc=Kh;var Uo=class extends De{constructor(t,r,i){super(t,G.BACKWARD),this.gantt=t,this.chainStartActivities=new Set,this.secondLevelActivities=new Set,this.pendingParentsWithLinks=new Set,this.pendingParentsWithNoLinks=new Set,this.structureOfParents=new Map,this.singleParents=new Map,this.calculationsOfParentThatImpactChildrens=new Map,this.activitiesWaitingForCalculation=new Set,this.calculations=new Map,this.mapOfRelationsWithActivitiesIds=new Map,this.activitiesWaitingForCalculation=new Set,this.forwardPathCalculations=r,this.forwardConstraintsMap=i,this.constraintMap=new Map,this.minFromLinks=new Map,this.activitiesStartChainButChildrenOfLinkedParents=new Set,this.calculationOfParentsFromLinks=new Set,this.parentCalculationFromChildren=new Set,this.parentsWithFullProgress=new Set,this.forbiddenActivitiesLinkedToParentsWithLinks=new Set,this.identifyInitialActivities(),this.initActivitiesWaitingForCalculation()}async calculateAsync(t){this.identifyParentsWithAndWithoutLinks(),t()&&(this.identifyForbiddenActivitiesLinkedToParentsWithLinks(),t()&&(this.initializeActivitiesWithFullProgress(),t()&&(this.calculateStartAndFinishOfActivitiesThatStartChain(),t()&&(this.identifySecondLevelActivities(),t()&&(this.identifyThirdLevelActivities(),t()&&await this.iterativeCalculateLfAndLs(t))))))}async iterativeCalculateLfAndLs(t){let r=new Zi({gantt:this.gantt,direction:this.direction,pendingParentsWithNoLinks:this.pendingParentsWithNoLinks,pendingParentsWithLinks:this.pendingParentsWithLinks,calculationOfParentsFromLinks:this.calculationOfParentsFromLinks,singleParents:this.singleParents,calculations:this.calculations,activitiesStartChainButChildrenOfLinkedParents:this.activitiesStartChainButChildrenOfLinkedParents,linkProperty:this.linkProperty,linkDirection:this.linkDirection});await zr({pending:this.activitiesWaitingForCalculation,activityCalculator:r,calculateFn:i=>this.calculateStartAndFinishTimes(i),shouldKeepPending:i=>this.calculationOfParentsFromLinks.has(i)&&!this.calculations.has(i),isCalculated:i=>this.calculations.has(i),onActivityProcessed:i=>this.activitiesWaitingForCalculation.delete(i),isCurrent:t})}setDatesToParentsWithLinks(t){if(!t)throw new Error("Error trying to get parent",{cause:{receivedParentData:t}});let r=this.singleParents.get(t.id).childrens,n=Array.from(this.calculations).filter(s=>r.includes(s[0])).map(s=>s[1]),{minLs:o,maxLf:a}=n.reduce((s,{ls:c,lf:l})=>({minLs:new Date(Math.min(s.minLs.getTime(),new Date(c).getTime())),maxLf:new Date(Math.max(s.maxLf.getTime(),new Date(l).getTime()))}),{minLs:new Date(n[0].ls),maxLf:new Date(n[0].lf)});this.calculations.set(t.id,{ls:o,lf:a})}calculateStartAndFinishTimes(t){t.forEach(r=>{let i=this.gantt.getTask(r);if(!i)throw new Error("Activity not found",{cause:{activityId:r}});let n=i.$source,o=i.constraint_type||h.ASAP,a=Number(i.progress);if(this.activitiesStartChainButChildrenOfLinkedParents.has(r)){if(this.calculationsOfParentThatImpactChildrens.has(Number(i.parent))&&this.calculationsOfParentThatImpactChildrens.get(Number(i.parent))===!1){let{ls:d,lf:u}=this.calculateStartAndFinishOfChainOrigin(i,this.direction);this.setCalculations(i,d,u);return}return this.doCalculationForActivitiesThatStartLinkButHisParentIsLinked(i)}if(i.type===D.PROJECT)return this.doCalculationForParentType(i);if(a===100){this.setDatesForActivityWithFullProgress(i);return}if(this.allLinkedActivitiesHasProgress(n,i)){this.setWhenAllLinkedActivitiesHasProgress(i);return}if(a>0&&a<100&&(o===h.MSO||o===h.MFO)){this.setWhenActivitiesHasProgressButLessThanOneHundred(i,o);return}if(o===h.MSO||o===h.MFO){this.recalculateInBaseRestriction(i,o);return}let{ls:s,lf:c,minFromLinks:l}=this.calculateLfandLsFromLinks(n,i,o,this.parentsWithFullProgress,this.calculationsOfParentThatImpactChildrens);(o===h.SNLT||o===h.FNLT)&&({ls:s,lf:c}=this.getTheLessLateInBasEsEfConstraint(i.id,{ls:s,lf:c},o)),this.setCalculations(i,s,c),this.minFromLinks.set(i.id,{ls:l.ls,lf:l.lf})})}getTheLessLateInBasEsEfConstraint(t,r,i){let n=this.forwardConstraintsMap.get(t);if(!n){let o=this.gantt.getTask(t),a=this.gantt.getCalendar(o.calendar_id);n=Xi(o,i,a)}return r.lf<n.ef?r:{ls:n.es,lf:n.ef}}allLinkedActivitiesHasProgress(t){try{let r=!0;for(let i of t){let n=this.gantt.getLink(i);if(!n)continue;let o=this.gantt.getTask(n.target);o&&(o.type===D.PROJECT&&(r=!1),o.progress===0&&(r=!1))}return r}catch(r){throw new Error(r.message)}}setDatesForActivityWithFullProgress(t){this.setCalculations(t,t.start_date,t.end_date)}setWhenAllLinkedActivitiesHasProgress(t){let r=Number(t.parent),{ls:i,lf:n}=this.calculateStartAndFinishOfChainOrigin(t,G.BACKWARD);if(this.calculationsOfParentThatImpactChildrens.has(r)){i=t.start_date;let o=this.calculationsOfParentThatImpactChildrens.get(r);o&&typeof o=="object"&&o.lf!=null&&(n=new Date(Math.min(n,o.lf)))}this.setCalculations(t,i,n)}setWhenActivitiesHasProgressButLessThanOneHundred(t,r){if(r===h.MSO){this.setCalculations(t,t.start_date,t.end_date);return}if(r===h.MFO){let i=Math.min(t.constraint_date,this.projectDates.end_date),n=new Date(Math.max(i,t.end_date));this.setCalculations(t,t.start_date,n);return}}setCalculations(t,r,i){this.calculations.set(t.id,{ls:r,lf:i,text:t.text})}calculateLfandLsFromLinks(t,r,i,n,o){return new $c({links:t,activity:r,calculatedActivitiesMap:this.calculations,calculatedForwardActivitiesMap:this.forwardPathCalculations,constraint:i,parentsWithFullProgress:n,parentsThatImpactChildrens:o,ganttInstance:this.gantt}).calculate()}recalculateInBaseRestriction(t,r){try{let i=this.gantt.getCalendar(t.calendar_id);if(!i)throw new Error(`Error trying to get calendar with id: ${t.calendar_id}`);let n=zc(i,t,r);this.constraintMap.set(t,n),this.setCalculations(t,n.ls,n.lf)}catch(i){throw new Error(i.message)}}cleanAllActivityParentsFromLinks(t){return t.map(r=>{let i=this.gantt.getLink(r).source,n=this.gantt.getLink(r).target;if(!(!this.gantt.getTask(i)||this.gantt.getTask(i)?.type===D.PROJECT)&&!(!this.gantt.getTask(n)||this.gantt.getTask(n)?.type===D.PROJECT))return r}).filter(Boolean)}doCalculationForActivitiesThatStartLinkButHisParentIsLinked(t){let r=Number(t.parent),i=this.calculationsOfParentThatImpactChildrens.get(r),n=0,o=0;if([h.ASAP,h.ALAP,h.SNET,h.FNET].includes(t.constraint_type))if(Number(t.progress)>0){let l=this.projectDates.end_date;o=new Date(Math.min(l,i.lf)),n=t.start_date}else o=i.lf,n=R(this.gantt.getCalendar(t.calendar_id),o,-t.duration,t);if([h.SNLT].includes(t.constraint_type)){let l=this.calculationsOfParentThatImpactChildrens.get(r),d=R(this.gantt.getCalendar(t.calendar_id),l.lf,-t.duration,t),u=t.constraint_date??d;n=new Date(Math.min(u.getTime(),d.getTime())),o=R(this.gantt.getCalendar(t.calendar_id),n,t.duration,t)}if([h.FNLT].includes(t.constraint_type)){let l=this.calculationsOfParentThatImpactChildrens.get(r),d=t.constraint_date??l.lf;n=new Date(Math.min(d.getTime(),l.lf.getTime())),o=R(this.gantt.getCalendar(t.calendar_id),n,t.duration,t)}[h.MSO].includes(t.constraint_type)&&(n=t.constraint_date,o=R(this.gantt.getCalendar(t.calendar_id),n,t.duration,t)),[h.MFO].includes(t.constraint_type)&&(o=t.constraint_date,n=R(this.gantt.getCalendar(t.calendar_id),o,-t.duration,t));let a=this.projectDates.end_date,s=[{ls:n,lf:o}];s.push({ls:R(this.gantt.getCalendar(t.calendar_id),a,-t.duration,t),lf:a});let c=this.getMinLfFromLinks(s);this.calculations.set(t.id,{ls:c.ls,lf:c.lf,text:t.text})}getMinLfFromLinks(t=[]){return t.length?t.reduce((r,i)=>i.lf<r.lf?i:r):!1}},qc=Uo;function Jc(){return null}var Xc=({forward:e,backward:t,id:r,activity:i,gantt:n,projectDates:o})=>({totalFloat:{es:e.calculations.get(r)?.es||0,ef:e.calculations.get(r)?.ef||0,ls:t.calculations.get(r)?.ls||0,lf:t.calculations.get(r)?.lf||0,constraintsMap:e.constraintsMap.get(r),totalFloatSnltFnlt:e.totalFloatSnltFnlt.get(r),totalFloatForMsoMfo:e.totalFloatForMsoMfo.get(r),minFromLinks:t.minFromLinks.get(r),activity:i,gantt:n},freeFloat:{forwardMap:e.calculations||new Map,backwardMap:t.calculations||new Map,activity:i,projectDates:o,gantt:n}});var Bo=class{constructor(t){this.gantt=t.gantt,this.activity=t.activity,this.es=t.es,this.ef=t.ef,this.ls=t.ls,this.lf=t.lf,this.constrainstMap=t.constraintsMap,this.totalFloatSnltFnlt=t.totalFloatSnltFnlt,this.totalFloatForMsoMfo=t.totalFloatForMsoMfo,this.minFromLinks=t.minFromLinks}getTotalFloat(){let{constraint_type:t}=this.activity,r=Number(this.activity.progress);if(r===100)return 0;if(t||(t=h.ASAP),t===h.ASAP||!t)return r===0?this.calculateAsap():this.calculateAsapWithProgress();if(t===h.ALAP)return r===0?this.calculateAlap():this.calculateAlapWithProgress();if(t===h.SNET||t===h.FNET)return r===0?this.calculateSnetFet():this.calculateSnetFnetSnltWithProgress();if(t===h.SNLT)return r===0?this.calculateSnltFnlt():this.calculateSnetFnetSnltWithProgress();if(t===h.FNLT)return r===0?this.calculateSnltFnlt():this.calculateFnltWithProgress();if(t===h.MSO||t===h.MFO)return r===0?this.calculateMsoMfo():this.calculateMsoMfoWithProgress()}calculateAsap(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}calculateAsapWithProgress(){let t=this.calculationWithCalendar(this.lf,this.ef);if(this.minFromLinks){let r=this.calculationWithCalendar(this.minFromLinks.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}return t/this.gantt.config.hoursPerDay}calculateAlap(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef),i=this.getMinValue(t,r),n=this.calculationWithCalendar(this.lf,this.activity.end_date);return this.getMinValue(i,n)/this.gantt.config.hoursPerDay}calculateAlapWithProgress(){return this.calculationWithCalendar(this.lf,this.ef)/this.gantt.config.hoursPerDay}calculateSnetFnetSnltWithProgress(){let t=this.calculationWithCalendar(this.lf,this.ef);if(this.minFromLinks){let r=this.calculationWithCalendar(this.minFromLinks.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}return t/this.gantt.config.hoursPerDay}calculateFnltWithProgress(){let t=this.calculationWithCalendar(this.lf,this.ef),r=this.calculationWithCalendar(this.activity.constraint_date,this.ef);if(this.minFromLinks){let i=this.calculationWithCalendar(this.minFromLinks.lf,this.ef);return this.getMinValue(t,r,i)/this.gantt.config.hoursPerDay}return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}calculateMsoMfoWithProgress(){return this.calculationWithCalendar(this.lf,this.ef)/this.gantt.config.hoursPerDay}calculateSnetFet(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}calculateSnltFnlt(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef),i=this.getMinValue(t,r);if(!this.totalFloatSnltFnlt&&!this.constrainstMap)return this.getMinValue(t,r)/this.gantt.config.hoursPerDay;let n=0;return this.activity.constraint_type===h.SNLT?n=this.calculationWithCalendar(this.constrainstMap.es,this.totalFloatSnltFnlt.es):n=this.calculationWithCalendar(this.constrainstMap.ef,this.totalFloatSnltFnlt.ef),this.getMinValue(n,i)/this.gantt.config.hoursPerDay}calculateMsoMfo(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef),i=this.getMinValue(t,r);if(!this.totalFloatForMsoMfo&&!this.constrainstMap)return this.getMinValue(t,r)/this.gantt.config.hoursPerDay;let n=0;return this.activity.constraint_type===h.MSO?n=this.calculationWithCalendar(this.constrainstMap.es,this.totalFloatForMsoMfo.es):n=this.calculationWithCalendar(this.constrainstMap.ef,this.totalFloatForMsoMfo.ef),this.getMinValue(n,i)/this.gantt.config.hoursPerDay}getMinValue(...t){return Math.min(...t)}calculationWithCalendar(t,r){return this.gantt.getCalendar(this.activity.calendar_id).calculateDuration({start_date:new Date(r),end_date:new Date(t)})}},Zc=Bo;var Ho=class{constructor(t){this.gantt=t.gantt,this.activity=t.activity,this.forwardMap=t.forwardMap,this.backwardMap=t.backwardMap,this.projectDates=t.projectDates,this.linksFreeFloatArray=[],this.linksFreeFloatObject={},this.durationCache=new Map}getFreeFloat(){let t=Number(this.activity.progress),r=this.getConstraintType();return this.calculateFreeFloatOfLink(r),{activityFreeFloat:t===100?0:this.getFreeFloatBaseConstraint(r),linksFreeFloat:this.linksFreeFloatObject}}getFreeFloatBaseConstraint(t){return t===h.MSO||t===h.MFO?this.calculateMsoMfo(t):this.calculateGeneral(t)}calculateFreeFloatOfLink(t=h.ASAP){let r=this.activity.$source.map(i=>{let{LINK:n,LINK_TYPE:o}=this.getLinkData(i),a=this.gantt.getTask(n.target);if(!a)return{linkId:n.id,freeFloat:null,hasProgress:!1};let s=Number(a.progress)>0,{sucessorDateToCalculate:c,predecessorDateToCalculate:l}=this.getDatesFromSucessorAndPredecessor(o,t,a),d=this.calculationWithCalendar(c,l),u=this.parseHoursToDays(d)-this.parseHoursToDays(n.lag),f=Math.max(0,u);return this.linksFreeFloatObject[n.id]=f,{linkId:n.id,freeFloat:f,hasProgress:s}}).filter(i=>i.freeFloat!==null&&i.freeFloat!==void 0);return this.linksFreeFloatArray=r,r}calculateGeneral(t=h.ASAP){let r=this.getMinFloat(this.linksFreeFloatArray),i=this.calculateFreeFloatForEndOfProject(t),n=0;return[h.SNLT,h.FNLT].includes(t)?n=this.doCalculationForSnltFnlt(t,i,r):n=this.doGeneralCalculation(i,r),Math.max(0,n)}getConstraintType(){let{constraint_type:t}=this.activity;return t||(t=h.ASAP),t}getDatesFromSucessorAndPredecessor(t,r,i){let n=i.constraint_type===h.ALAP,o=this.getSucessorAndPredecessorDates({constraint:r,isSuscessorAlap:n,sucessorId:i.id,predecessorId:this.activity.id}),a=new Date,s=new Date;return a=o[t].sucessor,s=o[t].predecessor,{sucessorDateToCalculate:a,predecessorDateToCalculate:s}}doGeneralCalculation(t,r){return r===null?t:this.getMinValue(r,t)}doCalculationForSnltFnlt(t,r,i){let n=this.calculateFreeFloatOfRestriction(t);return this.getMinValue(i,r,n)}calculateFreeFloatForEndOfProject(t){let r=t===h.ALAP?this.backwardMap.get(this.activity.id):this.forwardMap.get(this.activity.id);return this.parseHoursToDays(this.calculationWithCalendar(this.gantt.getSubtaskDates().end_date,t===h.ALAP?r?.lf:r?.ef))}calculateFreeFloatOfRestriction(t){let r=this.forwardMap.get(this.activity.id);return this.parseHoursToDays(this.calculationWithCalendar(this.activity.constraint_date,t===h.FNLT?r?.ef:r?.es))}getLinkData(t){let r=this.gantt.getLink(t)||{},i=Ue(r.type);return{LINK:r,LINK_TYPE:i}}getSucessorAndPredecessorDates({constraint:t,isSuscessorAlap:r,sucessorId:i,predecessorId:n}){let o=(r?this.backwardMap:this.forwardMap).get(i),a=(t===h.ALAP?this.backwardMap:this.forwardMap).get(n),s=t===h.ALAP?a?.ls:a?.es,c=t===h.ALAP?a?.lf:a?.ef;return{fs:{sucessor:o?.ls??o?.es,predecessor:c},ss:{sucessor:o?.ls??o?.es,predecessor:s},ff:{sucessor:o?.lf??o?.ef,predecessor:c},sf:{sucessor:o?.lf??o?.ef,predecessor:s}}}calculateMsoMfo(t){let r=this.activity.constraint_date||new Date,i=this.forwardMap.get(this.activity.id),n=t===h.MSO?i?.es:i?.ef,o=this.calculationWithCalendar(r,n);return Math.max(0,this.parseHoursToDays(o))}getMinValue(...t){let r=t.filter(i=>i!=null);return r.length?Math.min(...r):0}calculationWithCalendar(t,r){if(!(t instanceof Date)||!(r instanceof Date)||!Number.isFinite(t.getTime())||!Number.isFinite(r.getTime()))return Number.NaN;let i=`${r.getTime()}_${t.getTime()}`;if(this.durationCache.has(i))return this.durationCache.get(i);let o=this.gantt.getCalendar(this.activity.calendar_id).calculateDuration({start_date:new Date(r),end_date:new Date(t)});return this.durationCache.set(i,o),o}parseHoursToDays(t){return t==null?0:t/this.gantt.config.hoursPerDay}getMinFloat(t){if(!t?.length)return null;let r=t.filter(i=>!i.hasProgress).map(i=>i.freeFloat);return r.length===0?null:Math.min(...r)}},Qc=Ho;var tl=e=>({totalFloat:new Zc(e.totalFloat).getTotalFloat(),freeFloat:new Qc(e.freeFloat).getFreeFloat()});var Wo=async({activityIds:e,forward:t,backward:r,gantt:i,projectDates:n,isCurrent:o})=>{let a=performance.now(),s=new Map,c=new Map;for(let l of e){if(o&&!o())return{totalFloatMap:s,freeFloatMap:c};let d=i.getTask(l);if(!d)continue;let u=Xc({forward:t,backward:r,id:l,activity:d,gantt:i,projectDates:n}),{totalFloat:f,freeFloat:p}=tl(u);s.set(l,f),c.set(l,p),a=await He(a)}return{totalFloatMap:s,freeFloatMap:c}};var Vo=class{constructor(t){this.gantt=t,this.forwardPathCalculations=null,this.backwardPathCalculations=null,this.totalFloat=new Map,this.freeFloat=new Map,this.linkResidualHours=new Map,this.currentCalculationId=0}getCurrentCalculationId=()=>this.currentCalculationId;async calculate(t,r=()=>!0){let i=++this.currentCalculationId,n=bo(i,this.getCurrentCalculationId),o=()=>n()&&r();try{let a=t||this.gantt;if(this.gantt=a||Jc(),Fo(this.gantt))return!1;let s=new Yc(this.gantt);if(await s.calculateAsync(o),!o())return!1;let c=s.calculations,l=s.constraintsMap,d=new qc(this.gantt,c,l);if(await d.calculateAsync(o),!o())return!1;this.forwardPathCalculations=c,this.backwardPathCalculations=d.calculations;let u=await this.calculateLinkResidualHours(s.linkCandidates,c,o);if(!u||!o())return!1;this.linkResidualHours=u;let{totalFloatMap:f,freeFloatMap:p}=await this.calculateFloatsAsync(s,d,o);return o()?(this.totalFloat=f,this.freeFloat=p,this.gantt.refreshData(),!0):!1}catch(a){throw this.forwardPathCalculations?.size,a}}async calculateLinkResidualHours(t,r,i=()=>!0){let n=new Map,o=performance.now();for(let[a,s]of t){if(o=await He(o),!i())return null;let c=Number(s.targetId),l=this.gantt.getTask(c),d=r.get(c),u=s.ef,f=d?.ef,p=l&&this.gantt.getCalendar(l.calendar_id);if(!p||!(u instanceof Date)||!(f instanceof Date)||!Number.isFinite(u.getTime())||!Number.isFinite(f.getTime())){n.set(a,null);continue}let y=u.getTime(),T=f.getTime()>=y?p.calculateDuration({start_date:u,end_date:f}):-p.calculateDuration({start_date:f,end_date:u});n.set(a,Number.isFinite(T)?Object.is(T,-0)?0:T:null)}return n}async calculateFloatsAsync(t,r,i){try{let n=this.gantt.getSubtaskDates(),o=Array.from(this.forwardPathCalculations.keys());return await Wo({activityIds:o,forward:t,backward:r,gantt:this.gantt,projectDates:n,isCurrent:i})}catch(n){throw this.forwardPathCalculations?.size,n}}},el=Vo;var jh=e=>e===A.FNET||e===A.FNLT||e===A.MFO,Yh=e=>new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()));function Gh(e,t){let r=e.constraintDate;if(!r||!jh(e.constraintType))return r;let i=Yh(r);if(r.getTime()!==i.getTime())return r;let n=t.getClosestWorkTime({date:i,dir:"future",task:e});return n.getUTCFullYear()===r.getUTCFullYear()&&n.getUTCMonth()===r.getUTCMonth()&&n.getUTCDate()===r.getUTCDate()?jn(e,t):r}function $h(e){let t=new Map,r=new Map,i=new Map;return{calculateEndDate:({start_date:n,duration:o})=>{let a=`${n.getTime()}|${o}`,s=t.get(a);if(s!==void 0)return new Date(s);let c=e.calculateEndDate(n,o);return t.set(a,c.getTime()),c},calculateDuration:({start_date:n,end_date:o})=>{let a=`${n.getTime()}|${o.getTime()}`,s=r.get(a);if(s!==void 0)return s;let c=e.calculateDuration(n,o);return r.set(a,c),c},getWorkHours:n=>e.getWorkHours(n),$gantt:{getClosestWorkTime:({date:n,dir:o,unit:a})=>{let s=a??"hour",c=`${n.getTime()}|${o}|${s}`,l=i.get(c);if(l!==void 0)return new Date(l);let d=e.getClosestWorkTime({date:n,direction:o,unit:s});return i.set(c,d.getTime()),d}}}}function zh(e){let t=new Map;e.forEachActivity((n,o)=>t.set(String(o),n));let r=new Map,i=(n,o)=>{let a=r.get(n);if(a!=null)return a;let c=t.get(n)?.parentId??null,l=0;return c!==null&&!o.has(n)&&(o.add(n),l=i(String(c),o)+1),r.set(n,l),l};for(let n of t.keys())i(n,new Set);return r}function qh(e){let t=new Set;e.forEachActivity((s,c)=>{t.add(String(c)),s.parentId!==null&&t.add(String(s.parentId))});let r=new Map;for(let s of t){let c=Number(s);Number.isSafeInteger(c)&&c!==0&&r.set(c,(r.get(c)??0)+1)}let i=new Map,n=new Map;for(let s of t){let c=Number(s);Number.isSafeInteger(c)&&c!==0&&r.get(c)===1&&(i.set(s,c),n.set(c,s))}let o=1,a=s=>{let c=String(s),l=i.get(c);if(l!==void 0)return l;for(;n.has(o);)o+=1;return i.set(c,o),n.set(o,c),o++};for(let s of t)a(s);return{toLegacy:a,toCanonical:s=>typeof s=="number"?n.get(s)??null:i.has(String(s))?String(s):null}}function Jh(e,t){let r=zh(e),i=new Map;return e.forEachActivity((n,o)=>{let a=String(o);i.set(a,{id:t.toLegacy(a),parent:n.parentId===null?0:t.toLegacy(n.parentId),$level:r.get(a)??0,$source:e.getOutgoingLinkIds(a),$target:e.getIncomingLinkIds(a),start_date:n.startDate,end_date:n.endDate,duration:n.durationHours,progress:n.progress,type:n.type,calendar_id:n.calendarId,constraint_type:n.constraintType,constraint_date:Gh(n,e)})}),i}function Xh(e){let t=new Map;for(let a of e.values()){let s=t.get(a.parent);s?s.push(a):t.set(a.parent,[a])}let r=[],i=new Set,n=[],o=a=>{if(a)for(let s=a.length-1;s>=0;s-=1)n.push(a[s])};for(o(t.get(0));n.length>0;){let a=n.pop();i.has(a)||(i.add(a),r.push(a),o(t.get(a.id)))}if(r.length<e.size)for(let a of e.values())i.has(a)||r.push(a);return r}function Zh(e){let t=null,r=null;return e.forEachActivity(i=>{if(i.startDate){let n=i.startDate.getTime();t=t==null?n:Math.min(t,n)}if(i.endDate){let n=i.endDate.getTime();r=r==null?n:Math.max(r,n)}}),{start_date:new Date(t??0),end_date:new Date(r??0)}}async function rl(e,t){let r=new Map,i=l=>{let d=l==null?"__default__":String(l),u=r.get(d);if(u)return u;let f=e.calendarReader.getCalendar(String(l)),p=$h(f);return r.set(d,p),p},n=Zh(e);await st();let o=qh(e),a=Jh(e,o);await st();let s=[...a.values()].sort((l,d)=>(l.start_date?.getTime()??0)-(d.start_date?.getTime()??0));await st();let c=Xh(a);return{fullyParsed:!0,config:{hoursPerDay:t},getTask:l=>{let d=o.toCanonical(l);return d===null?null:a.get(d)??null},getLink:l=>{let d=e.getLink(l);return d?{...d,source:o.toLegacy(d.source),target:o.toLegacy(d.target),lag:d.lag}:null},getCalendar:i,getChildren:l=>{let d=o.toCanonical(l);return d===null?[]:e.getChildren(d).map(o.toLegacy)},eachTask:l=>{for(let d of c)l(d)},getTaskByTime:()=>s,getSubtaskDates:()=>n,getCanonicalActivityId:o.toCanonical,refreshData:()=>{}}}var jo=1e3,Qh=e=>typeof e!="number"||!Number.isFinite(e)?null:Object.is(e,-0)?0:e,tm=(e,t)=>typeof e!="number"||e<0?null:Ko(e,t);function em(e){let t=tm(e.freeFloatDays,e.hoursPerDay),r=Qh(e.residualHours);return{freeSlackHours:t,isCritical:r!==null&&r<=0&&e.sourceIsCritical&&e.targetIsCritical&&e.targetProgress===0}}async function rm(e,t){let r=new Map,i=0;for(let n of e.values())for(let o in n.linksFreeFloat)if(Object.hasOwn(n.linksFreeFloat,o)){if(++i>=jo&&(i=0,await st(),!t()))return null;r.set(String(o),n.linksFreeFloat[o])}return t()?r:null}async function im(e,t,r,i,n){let o=new Map,a=0;for(let s of t.forward?.keys()??[]){if(++a>=jo&&(a=0,await st(),!n()))return null;let c=i(s);if(c===null)continue;let l=e.getActivity(c);l&&o.set(String(c),om(s,Number(l.progress??0),t,r))}return n()?o:null}async function nm(e,t,r,i,n,o){let a=new Map,s=0;for(let c of e.getAllLinks()){if(++s>=jo&&(s=0,await st(),!o()))return null;a.set(String(c.id),em({freeFloatDays:t.get(String(c.id)),residualHours:r.get(String(c.id)),hoursPerDay:n,sourceIsCritical:i.get(c.source)?.isCritical===!0,targetIsCritical:i.get(c.target)?.isCritical===!0,targetProgress:e.getActivity(c.target)?.progress}))}return o()?a:null}var Ko=(e,t)=>{if(typeof e!="number"||!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return null;let r=e*t;return Number.isFinite(r)?Object.is(r,-0)?0:r:null};function om(e,t,r,i){let n=c=>{if(c==null)return null;let l=new Date(c);return Number.isFinite(l.getTime())?l:null},o=r.forward?.get(e),a=r.backward?.get(e),s=Ko(r.totalFloat.get(e),i);return{criticalPath:{earlyStart:n(o?.es),earlyFinish:n(o?.ef),lateStart:n(a?.ls),lateFinish:n(a?.lf),totalSlackHours:s},isCritical:t<100&&s!==null&&s<=0,freeSlackHours:Ko(r.freeFloat.get(e)?.activityFreeFloat,i)}}var Qi=(e,t)=>e===t||e!==null&&t!==null&&e.getTime()===t.getTime();function Yo(e,t,r){let i=e.getActivity(t),n=i?.criticalPath,o=r.criticalPath;i&&n&&Qi(n.earlyStart,o.earlyStart)&&Qi(n.earlyFinish,o.earlyFinish)&&Qi(n.lateStart,o.lateStart)&&Qi(n.lateFinish,o.lateFinish)&&Object.is(n.totalSlackHours,o.totalSlackHours)&&Object.is(i.isCritical,r.isCritical)&&Object.is(i.freeSlackHours,r.freeSlackHours)||e.setActivityFields(t,r)}function Go(e,t,r){let i=e.getLink(t);!i||Object.is(i.freeSlackHours,r.freeSlackHours)&&Object.is(i.isCritical,r.isCritical)||(e.setLinkField(t,"freeSlackHours",r.freeSlackHours),e.setLinkField(t,"isCritical",r.isCritical))}async function $o(e,t,r=()=>!0){if(!r())return null;let i=await rl(e,t);if(!r())return null;let n=new el(i);if(!await n.calculate(i,r)){if(!r())return null;throw new Error("critical path calculation aborted")}if(!r())return null;let a={forward:n.forwardPathCalculations,backward:n.backwardPathCalculations,totalFloat:n.totalFloat,freeFloat:n.freeFloat},s=await im(e,a,t,i.getCanonicalActivityId,r);if(!s)return null;let c=await rm(a.freeFloat,r);if(!c)return null;let l=await nm(e,c,n.linkResidualHours,s,t,r);return l?{activities:s,links:l}:null}async function il(e,t,r=()=>!0){let i=await $o(e,t,r);if(!i||!r())return!1;for(let[n,o]of i.activities){if(!r())return!1;Yo(e,n,o)}for(let[n,o]of i.links){if(!r())return!1;Go(e,n,o)}return!0}function fr(e){let t=[],r=[];e.forEachActivity((n,o)=>{n.parentId===null&&t.push(String(o))});let i=n=>{let o=e.getActivity(String(n));if(!o)return 0;let a=[...e.getChildren(String(n))],s;if(a.length===0){let c=kt(o),l=c&&Number(c.cost)||0;s=(Number(o.progress)||0)/100*l}else{let c=0;for(let l of a)c+=i(String(l));s=c}return e.setActivityField(String(n),x.REAL_COST,s),r.push(String(n)),s};for(let n of t)i(n);return r}var nl=new Set;var ol=new Set(["activity-outdent","activity-indent"]);var qr=new Set([_.TEXT,_.DESCRIPTION,_.COST,_.USED_COST,_.CUSTOM_ID,_.RESPONSABLES,_.SUBCONTRACT_ID,_.TAGS]),am=new Set([m.ACTIVITY_CLIPBOARD_CLEAR,m.ACTIVITY_COPY,m.SELECTION_TOGGLE,m.SELECTION_REPLACE,m.VISIBILITY_SET,m.FILTER_SET,m.SORT_SET,m.SIR_SYNC,m.ACTIVITY_LOOKAHEAD_SYNC,m.PERSISTENCE_ACKNOWLEDGE,m.BASELINE_APPLY,m.PONDERATOR_CRITERION_SET,m.STATUS_CRITERIA_SET]),sm=new Set([m.ACTIVITY_CLIPBOARD_CLEAR,m.ACTIVITY_COPY,m.SELECTION_TOGGLE,m.SELECTION_REPLACE,m.VISIBILITY_SET,m.FILTER_SET,m.SORT_SET]);function sl(e){return!sm.has(e.kind)}var cm=new Set;function lm(e){return e.kind===m.INLINE_EDIT?qr.has(e.column):e.kind===m.BULK_EDIT?e.edits.every(t=>qr.has(t.column)):!1}function zo(e,t){return!(am.has(e.kind)||t.has(e.kind)||lm(e))}function qo(e){return e.kind===m.ACTIVITY_LOOKAHEAD_SYNC?e.persistedProgress!==void 0:zo(e,cm)}function We(e){return e.kind===m.ACTIVITY_LOOKAHEAD_SYNC?e.persistedProgress!==void 0:zo(e,nl)}function cl(e){return zo(e,ol)}function Jo(e){return e.kind===m.ACTIVITY_SET_PROGRESS?!0:e.kind===m.INLINE_EDIT?e.column===_.PROGRESS:e.kind===m.BULK_EDIT?e.edits.some(t=>t.column===_.PROGRESS):!1}function dm(e){return cl(e)&&Jo(e)}var al=new Set([_.PROGRESS,_.HH_WORK_TIME,_.DURATION,_.COST,_.USED_COST,_.REAL_COST]);function um(e){return e.kind===m.ACTIVITY_SET_PROGRESS?!0:e.kind===m.INLINE_EDIT?al.has(e.column):e.kind===m.BULK_EDIT?e.edits.some(t=>al.has(t.column)):!1}var Tt={AUTOSCHEDULE:"autoschedule",PARENT_BOUNDS:"parent-bounds",PARENT_PROGRESS:"parent-progress",REAL_WORK:"real-work",EXPECTED_PROGRESS:"expected-progress",REAL_COST:"real-cost",CRITICAL_PATH:"critical-path"};function ll(e,t,r){let i=new Set;t.ran&&i.add(Tt.AUTOSCHEDULE),i.add(Tt.PARENT_BOUNDS),um(e)&&i.add(Tt.PARENT_PROGRESS),Jo(e)&&i.add(Tt.REAL_WORK);let n=!r.skipAutoSchedule;return n&&cl(e)&&i.add(Tt.EXPECTED_PROGRESS),n&&dm(e)&&i.add(Tt.REAL_COST),n&&We(e)&&!r.skipCriticalPath&&i.add(Tt.CRITICAL_PATH),i}var Et={INSERT:"insert",REMOVE:"remove",LINK_ADD:"link-add",LINK_REMOVE:"link-remove",LINK_FIELD:"link-field"},tn=class{_journal=null;begin(){this._journal={dirty:new Set,before:new Map,ops:[],linkFieldCaptured:new Set,correlativeBefore:new Map,scheduledBefore:new Map,progressFallbackBefore:new Map}}peek(){return this._journal}end(){this._journal=null}note(t,r){let i=this._journal;i&&(i.before.has(t)||i.before.set(t,ae(r)),i.dirty.add(t))}noteInsert(t){this._journal?.ops.push({kind:Et.INSERT,activityId:t})}noteRemove(t,r){this._journal?.ops.push({kind:Et.REMOVE,activityId:t,before:ae(r)})}noteLinkAdd(t){this._journal?.ops.push({kind:Et.LINK_ADD,linkId:t})}noteLinkRemove(t,r){this._journal?.ops.push({kind:Et.LINK_REMOVE,linkId:t,before:dl(r)})}noteCorrelativeBefore(t,r){let i=this._journal;if(!i||i.correlativeBefore.has(t))return;let n=i.before.get(t)?.correlativeId;i.correlativeBefore.set(t,typeof n=="number"?n:r)}noteScheduledBefore(t,r){let i=this._journal;if(!i)return;let n=ae(r);i.scheduledBefore.has(t)||i.scheduledBefore.set(t,n),i.before.has(t)||i.before.set(t,n),i.dirty.add(t)}noteLinkField(t,r){let i=this._journal;!i||i.linkFieldCaptured.has(t)||(i.linkFieldCaptured.add(t),i.ops.push({kind:Et.LINK_FIELD,linkId:t,before:dl(r)}))}noteProgressFallback(t,r){let i=this._journal;!i||i.progressFallbackBefore.has(t)||i.progressFallbackBefore.set(t,r)}};function dl(e){return{...e}}var Ot={ROOTS:"roots"};async function Z(e,t){let r=pm(e.adapter),i=fm(t,r);i.has(Tt.AUTOSCHEDULE)&&await Am(e.adapter,t);let n=i.has(Tt.AUTOSCHEDULE)?await mm(e,t.autoscheduleFrom,t.preventSummaryTargetPullback):gm();return await vm(e.adapter,t,n.scheduledIds,i,r),await Sm(e,i,t.now),n}function fm(e,t){let r=e.autoscheduleFrom!==null,i=!e.options.skipAutoSchedule&&r,n=new Set(ll(e.action,{requested:r,ran:i},e.options));return(e.recomputeParentProgress||t.affectedParents.size>0)&&n.add(Tt.PARENT_PROGRESS),n}function pm(e){let t=new Set,r=new Set,i=e.peekWriteCapture();if(!i)return{affectedParents:t,dirtySeeds:r};let n=o=>{if(o===null||M(o))return;let a=String(o);t.add(a);let s=e.getChildren(a)[0];s!==void 0&&r.add(s)};return ym(e,i.ops,n),hm(e,i.before,r,n),{affectedParents:t,dirtySeeds:r}}function ym(e,t,r){for(let i of t)if(i.kind===Et.INSERT){let n=e.getActivity(i.activityId);n&&r(n.parentId)}else i.kind===Et.REMOVE&&r(i.before.parentId)}function hm(e,t,r,i){for(let[n,o]of t){let a=e.getActivity(n);if(!a)continue;let s=!Object.is(o.progress,a.progress),c=!Object.is(o.ponderator,a.ponderator),l=!Object.is(o.parentId,a.parentId);(s||c)&&(i(a.parentId),r.add(String(n))),l&&(i(o.parentId),i(a.parentId),r.add(String(n)))}}async function mm(e,t,r=!1){let i=t===Ot.ROOTS?{}:{triggerId:t};r&&(i.preventSummaryTargetPullback=!0);let n=await e.scheduler.schedule(i),o=Im(e.adapter,n.updatedIds);return Fr(e.adapter,n),o}function Im(e,t){let r=[];for(let i of t){let n=String(i);r.push(n);let o=e.getActivity(n);o&&e.noteScheduledBefore(n,o)}return{scheduledIds:r}}function gm(){return{scheduledIds:[]}}async function Am(e,t){let r=t.collectDirty?t.collectDirty([]):vo(t.recomputeParentsFrom,[]);r.size!==0&&await ir(e,r,!1)}async function vm(e,t,r,i,n){i.has(Tt.PARENT_PROGRESS)&&Cm(e,n.affectedParents);let o=t.collectDirty?t.collectDirty(r):vo(t.recomputeParentsFrom,r);for(let a of n.dirtySeeds)o.add(a);await ir(e,o,i.has(Tt.PARENT_PROGRESS),{recomputeRealWork:i.has(Tt.REAL_WORK),progressMode:"freeze-when-no-contribution"})}function Cm(e,t){for(let r of t){if(e.hasChildren(r))continue;let i=e.getProgressFallback(r);i!==null&&(e.setActivityField(r,"progress",i),e.setProgressFallback(r,null))}}async function Sm(e,t,r){t.has(Tt.EXPECTED_PROGRESS)&&r!==null&&(Tm(e.adapter)&&ur(e.adapter,r,e.defaultBaseCalendarId??null),Me(e.adapter,r),ce(e.adapter,e.sector.statusCriteria)),t.has(Tt.REAL_COST)&&fr(e.adapter),t.has(Tt.CRITICAL_PATH)&&await il(e.adapter,e.sector.hoursPerDay)}function Tm(e){let t=!1;return e.forEachActivity(r=>{kt(r)&&(t=!0)}),t}var Em=new Set([_.CONSTRAINT_TYPE,_.CONSTRAINT_DATE]),Dm=new Set([A.MSO,A.MFO]);function en(e){return Em.has(e)}function rn(e){return e===_.CONSTRAINT_DATE}function nn(e,t,r,i){let n=r.getActivity(e);if(!n)return!1;let o=n.constraintType;if(!o||ve.has(o)||Dm.has(o))return!1;let a=Xo(n.startDate),s=Xo(r.getLastStartDate(e));if(!s||!a||a.getTime()!==s.getTime())return!1;let c=_m(t,o,String(n.calendarId??""),i),l=Xo(n.constraintDate);return km(l,c)?!1:(r.setActivityField(e,"constraintDate",c),!0)}function _m(e,t,r,i){if(e===null)return null;let n=i.getCalendar(r);return n?ne(e,n,t):e}function Xo(e){if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){let t=new Date(e);return Number.isNaN(t.getTime())?null:t}return null}function km(e,t){return e===null&&t===null?!0:e===null||t===null?!1:e.getTime()===t.getTime()}async function on(e,{postMutationArgs:t,revertTargets:r,revert:i}){let{scheduledIds:n}=await Z(e,ul(t)),o=!1;for(let{activityId:a,priorConstraintDate:s}of r){let c=i(a,s);o=o||c}if(o){let a=await Z(e,ul(t));n=Pm(n,a.scheduledIds)}return We(t.action)&&await Z(e,Rm(t)),{scheduledIds:n}}function ul(e){return{...e,options:{...e.options,skipCriticalPath:!0}}}function Rm(e){return{action:e.action,autoscheduleFrom:null,recomputeParentsFrom:[],now:null,options:e.options}}function Pm(e,t){let r=new Set(e);for(let i of t)r.add(i);return[...r]}function Zo(e,t,r){let i=[];for(let n of r){let o=e.get(n);if(!o)continue;let a=o.pendingRequestIds??[];if(Je({pendingRequestIds:a})&&t.getActivity(n)==null)for(let s of a)i.push({kind:Vi.SIR_AUTO_REJECT,activityId:n,sirId:s,reason:Ki.ACTIVITY_DELETED})}return i}function bt(e){let t={id:String(e.id),source:String(e.source),target:String(e.target),type:e.type,lag:Number(e.lag),freeSlackHours:typeof e.freeSlackHours=="number"&&Number.isFinite(e.freeSlackHours)?e.freeSlackHours:null,isCritical:e.isCritical===!0};return e.proplannerId!=null&&(t.proplannerId=Number(e.proplannerId)),e.ganttId!=null&&(t.ganttId=Number(e.ganttId)),e.sectorId!=null&&(t.sectorId=Number(e.sectorId)),t}var Ft={BEFORE_DIFF:"before-diff",AFTER_DIFF:"after-diff"};async function z(e,t){let r=bm(e,t),i=new Map(t.beforeSnap),n=e.peekWriteCapture();if(n){let f=wm(n);Fm(e,n,f,i,r)}let o=t.sirDetection,a=o===Ft.BEFORE_DIFF?Zo(i,e,r):[],s=Nm(t.correlativeShifts,r),c=await Gi(e,i,r,s),l=o===Ft.AFTER_DIFF?Zo(i,e,r):a,d=t.warnings??[],u=Om(t.links??[],n?Lm(e,n):[]);return{source:t.source,activities:c,links:u,calendars:[],trackingEvents:t.trackingEvents??[],...l.length>0?{effects:l}:{},...d.length>0?{warnings:d}:{}}}function Lm(e,t){let r=[];for(let i of t.ops){if(i.kind!==Et.LINK_FIELD)continue;let n=e.getLink(i.linkId);if(!n)continue;let o={};for(let a of["freeSlackHours","isCritical"])Object.is(i.before[a],n[a])||(o[a]={before:i.before[a],after:n[a]});Object.keys(o).length!==0&&r.push({id:i.linkId,kind:N.UPDATED,fields:o,after:bt(n)})}return r}function Om(e,t){let r=[],i=new Map;for(let n of e){let o=i.get(n.id);if(o===void 0){i.set(n.id,r.length),r.push(n);continue}let a=r[o];if((a.kind===N.UPDATED||a.kind===N.CREATED)&&n.kind===N.UPDATED){r[o]={...a,fields:{...a.fields,...n.fields},after:n.after};continue}r[o]=n}for(let n of t){let o=i.get(n.id);if(o===void 0){i.set(n.id,r.length),r.push(n);continue}let a=r[o];if(a.kind===N.DELETED)continue;let s=a.kind===N.CREATED?Object.fromEntries(Object.entries(n.fields??{}).map(([c,l])=>[c,{before:void 0,after:l.after}])):n.fields;r[o]={...a,fields:{...a.fields,...s},after:n.after}}return r}function Nm(e,t){if(!e||e.length===0)return;let r=new Map;for(let i of e)r.set(i.activityId,i.before),t.add(i.activityId);return r}function bm(e,t){let r=new Set;for(let i of t.touchedIds)r.add(i);for(let i of t.scheduledIds)r.add(i);if(t.includeAllIds)for(let i of e.getAllIds())r.add(i);return r}function Fm(e,t,r,i,n){for(let o of t.dirty){if(r.has(o)||i.has(o))continue;let a=t.before.get(o),s=e.getActivity(o);!a||!s||Object.keys(Ao(a,s)).length!==0&&(i.set(o,a),n.add(o))}}function wm(e){return new Set(e.ops.filter(t=>t.kind===Et.INSERT).map(t=>t.activityId))}function pr(e,t,r){let i=[];for(let{op:n,finalLinkId:o,rejected:a}of e){if(a!==null)continue;if(n.kind===dt.CREATE){if(!o)continue;let d=r.getLink(o);if(!d)continue;let u=t.get(o);if(u){let f={};String(u.source)!==String(d.source)&&(f.source={before:String(u.source),after:String(d.source)}),String(u.target)!==String(d.target)&&(f.target={before:String(u.target),after:String(d.target)}),u.type!==d.type&&(f.type={before:u.type,after:d.type}),Number(u.lag)!==Number(d.lag)&&(f.lag={before:Number(u.lag),after:Number(d.lag)}),Object.keys(f).length>0&&i.push({id:String(o),kind:N.UPDATED,fields:f,after:bt(d)});continue}i.push({id:String(o),kind:N.CREATED,fields:{source:{before:void 0,after:String(d.source)},target:{before:void 0,after:String(d.target)},type:{before:void 0,after:d.type},lag:{before:void 0,after:Number(d.lag)}},after:bt(d)});continue}if(n.kind===dt.DELETE){if(r.getLink(n.linkId))continue;let d=t.get(n.linkId);i.push({id:String(n.linkId),kind:N.DELETED,fields:d?{source:{before:String(d.source),after:void 0},target:{before:String(d.target),after:void 0},type:{before:d.type,after:void 0},lag:{before:Number(d.lag),after:void 0}}:void 0,after:null});continue}let s=t.get(n.linkId),c=r.getLink(n.linkId);if(!c)continue;let l={};s&&s.type!==c.type&&(l.type={before:s.type,after:c.type}),s&&Number(s.lag)!==Number(c.lag)&&(l.lag={before:Number(s.lag),after:Number(c.lag)}),i.push({id:String(n.linkId),kind:N.UPDATED,fields:l,after:bt(c)})}return i}function yr(e,t){let r=new Map;if(!e.getActivity(t))return r;for(let i of e.getIncomingLinkIds(t)){let n=e.getLink(i);n&&r.set(String(n.id),Number(n.lag))}return r}function hr(e,t,r){let i=[];if(!t.getActivity(r))return i;for(let n of t.getIncomingLinkIds(r)){let o=t.getLink(n);if(!o)continue;let a=e.get(String(o.id));a===void 0||a===Number(o.lag)||i.push({id:String(o.id),kind:N.UPDATED,fields:{lag:{before:a,after:Number(o.lag)}},after:bt(o)})}return i}function an(e,t){typeof e=="string"&&e.length>0&&t.releaseCustomId(e)}async function fl(e,t,r){let{adapter:i,ctx:n,scheduler:o,sector:a}=r,s=Se(e.column);if(!s)return{ok:!1,reason:C.NO_PIPELINE_FOR_COLUMN};e.column===_.DURATION&&o.invalidateExpandedLinksCache();let c=n.activityReader.getActivity(e.activityId);if(!c)return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let l=s.canEdit(c,n.hierarchy);if(!l.allowed)return{ok:!1,reason:l.reason??C.CANNOT_EDIT,alertKey:l.alertKey};let d=s.parseInput(e.newValue,c,n);if(!d.ok)return{ok:!1,reason:d.reason??C.PARSE_ERROR};let u=Reflect.get(c,s.targetField),f=s.validate(c,u,d.value,n);if(!f.valid)return{ok:!1,reason:f.reason??C.INVALID,alertKey:f.notification?.messageKey};if(e.column===_.CUSTOM_ID&&d.value!==null){let v=i.getActivity(e.activityId),P=v?v.customId:null,q=typeof P=="string"?P:null;if(r.customIdTracker.isCustomIdInUse(String(d.value),q))return{ok:!1,reason:C.CUSTOM_ID_DUPLICATE}}let p=s.transform(c,d.value,n,d.raw),y=Te(e.activityId,p),I=await rt(i,y),T=yr(i,String(e.activityId)),L=c.constraintDate;Ee(i,e.activityId,p),Ie(e.activityId,p.postProcessors??[],i,I.get(String(e.activityId))??null);let S=hr(T,i,String(e.activityId));if(e.column===_.CUSTOM_ID){let v=I.get(String(e.activityId)),P=v?v.customId:null,q=typeof P=="string"?P:null,$=typeof d.value=="string"?d.value:null;q!==$&&r.customIdTracker.trackCustomIdChange(q,$)}let E=()=>({action:e,autoscheduleFrom:p.needsAutoSchedule?String(e.activityId):null,recomputeParentsFrom:[],collectDirty:v=>$i(e.activityId,y,v),now:r.now,options:t}),g=en(e.column),{scheduledIds:b}=await(g?on({adapter:i,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{postMutationArgs:E(),revertTargets:rn(e.column)?[]:[{activityId:e.activityId,priorConstraintDate:L}],revert:(v,P)=>nn(v,P,i,n.calendars)}):Z({adapter:i,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},E())),B=(p.trackingEvents??[]).map(v=>({name:v.name,properties:v.properties??{}}));s.trackEvent&&!(e.column===_.PROGRESS&&Number(d.value)<=0)&&B.unshift({name:s.trackEvent,properties:{activity_name:c.name,activity_id:c.id,activity_index:c.correlativeId}});let k=cr(e.activityId,p.constraintWarning);return{ok:!0,changes:await z(i,{source:e,beforeSnap:I,touchedIds:y,scheduledIds:b,sirDetection:Ft.BEFORE_DIFF,links:S,trackingEvents:B,...k?{warnings:[k]}:{},hoursPerDay:a.hoursPerDay})}}function sn(e){return ai(e)}function cn(e,t){return Object.hasOwn(e,t)}function xm(e){if(e.kind===m.LINK_CREATE)return sn(e.type)?e.lag===void 0||Number.isFinite(e.lag)?null:C.INVALID_LINK_LAG:C.INVALID_LINK_TYPE;if(e.kind===m.LINK_UPDATE){if(cn(e,"type")&&!sn(e.type))return C.INVALID_LINK_TYPE;if(cn(e,"lag")&&!Number.isFinite(e.lag))return C.INVALID_LINK_LAG}return null}function Mm(e){return e.kind===at.CREATE?sn(e.type)?e.lag===void 0||Number.isFinite(e.lag)?null:C.INVALID_LINK_LAG:C.INVALID_LINK_TYPE:e.kind===at.UPDATE?cn(e,"type")&&!sn(e.type)?C.INVALID_LINK_TYPE:!cn(e,"lag")||Number.isFinite(e.lag)?null:C.INVALID_LINK_LAG:e.kind===at.DELETE?null:C.INVALID_VALUE}function Um(e){for(let t of e){let r=Mm(t);if(r!==null)return r}return null}function Bm(e,t){let r=new Set,i=new Map;for(let n of e){if(n.kind===at.CREATE){r.add(String(n.source)),r.add(String(n.target));continue}let o=t.getLink(n.linkId);o&&(r.add(String(o.source)),r.add(String(o.target)),i.set(n.linkId,{...o}))}return{activityIds:r,links:i}}function Hm(e,t,r,i){return e.map((n,o)=>{let a=n.kind===at.CREATE?i?.get(o):void 0,s=ye(n,{port:t,newLinkId:a?()=>a:r.next});return{op:n,finalLinkId:s.applied?s.linkId:null,rejected:s.applied?null:s.rejected??C.INVALID}})}function Wm(e){return new Map([...e].map(([t,r])=>[String(t),r]))}async function pl(e,t,r){let i=xm(e);return i!==null?{ok:!1,reason:i}:Qo([$m(e,r.sector.hoursPerDay)],e,t,r,e.kind===m.LINK_CREATE&&e.linkId?new Map([[0,e.linkId]]):void 0)}async function yl(e,t,r){let i=Um(e.operations);if(i!==null)return{ok:!1,reason:i};let{hoursPerDay:n}=r.sector,o=e.operations.map(s=>jm(s,n)),a=Vm(e.operations);return Qo(o,e,t,r,a)}function Vm(e){let t=new Map;return e.forEach((r,i)=>{r.kind===at.CREATE&&r.linkId&&t.set(i,r.linkId)}),t.size>0?t:void 0}function Km(e,t){if(e===void 0)return;let r=new Map,i=new Set,n=()=>{let o=t.linkIdGen.next();for(;t.adapter.getLink(o)!==null||t.isLinkIdReserved(String(o))||i.has(String(o));)o=t.linkIdGen.next();return o};for(let[o,a]of e){let s=t.adapter.getLink(a)!==null||t.isLinkIdReserved(String(a))||i.has(String(a)),c=s?n():a;s||t.linkIdGen.bump(a),i.add(String(c)),r.set(o,c)}return r}function jm(e,t){return e.kind===at.CREATE?{kind:at.CREATE,source:e.source,target:e.target,type:e.type,lag:Wt(e.lag??0,t)}:e.kind===at.UPDATE?{kind:at.UPDATE,linkId:e.linkId,type:e.type,lag:e.lag===void 0?void 0:Wt(e.lag,t)}:{kind:at.DELETE,linkId:e.linkId}}async function Qo(e,t,r,i,n){let{adapter:o,scheduler:a,sector:s,linkIdGen:c}=i;a.invalidateAllCaches();let{activityIds:l,links:d}=Bm(e,o),u=await rt(o,l),f=Hm(e,o,c,Km(n,i));if(e.length===1&&f[0]&&f[0].rejected!==null&&t.kind!==m.INLINE_EDIT)return{ok:!1,reason:f[0].rejected};let p=Ym(f,d,o),{scheduledIds:y}=await Z({adapter:o,scheduler:a,sector:i.sector,defaultBaseCalendarId:i.defaultBaseCalendarId},{action:t,autoscheduleFrom:p,recomputeParentsFrom:l,now:i.now,options:r}),I=pr(f,d,o);return{ok:!0,linkVerdicts:f.map((T,L)=>T.rejected===null?{operationIndex:L,kind:T.op.kind,ok:!0,linkId:String(T.finalLinkId)}:{operationIndex:L,kind:T.op.kind,ok:!1,reason:T.rejected}),__beforeLinks:Wm(d),changes:await z(o,{source:t,beforeSnap:u,touchedIds:l,scheduledIds:y,links:I,hoursPerDay:s.hoursPerDay})}}function Ym(e,t,r){for(let i of e){if(i.rejected!==null)continue;let n=Gm(i.op,t,r);if(n!==null)return r.hasChildren(n)?Ot.ROOTS:String(n)}return null}function Gm(e,t,r){return e.kind===at.CREATE?e.target:e.kind===at.DELETE?t.get(e.linkId)?.target??null:r.getLink(e.linkId)?.target??null}function $m(e,t){return e.kind===m.LINK_CREATE?{kind:at.CREATE,source:e.source,target:e.target,type:e.type,lag:Wt(e.lag??0,t)}:e.kind===m.LINK_UPDATE?{kind:at.UPDATE,linkId:e.linkId,type:e.type,lag:e.lag===void 0?void 0:Wt(e.lag,t)}:{kind:at.DELETE,linkId:e.linkId}}async function hl(e,t,r){let{adapter:i,sector:n}=r;if(typeof e.newValue!="string")return{ok:!1,reason:C.INVALID_VALUE};if(!i.getActivity(e.activityId))return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let a=e.column===_.CUSTOM_PREDECESSORS,{specs:s,errors:c}=_i(e.newValue,{daysPerWeek:n.hoursPerWeek/n.hoursPerDay});if(c.length>0)return{ok:!1,reason:C.INVALID_VALUE};let l=s.map(I=>({...I,lag:Wt(Li(I.lag),n.hoursPerDay)})),d=new Map;i.forEachActivity(I=>{I.correlativeId!=null&&d.set(String(I.correlativeId),I.id)});let u=I=>d.get(I)??null,f=a?i.getIncomingLinkIds(e.activityId):i.getOutgoingLinkIds(e.activityId),p=[];for(let I of f){let T=i.getLink(I);T&&p.push(T)}let y=a?Ri({targetActivityId:e.activityId,currentLinks:p,desiredSpecs:l,resolveActivityByCorrelative:u}):Pi({sourceActivityId:e.activityId,currentLinks:p,desiredSpecs:l,resolveActivityByCorrelative:u});return Qo(y.operations,e,t,r)}var Kt={ACTIVITY_CREATION:"schedule_activity_creation",ACTIVITY_DELETION:"schedule_activity_deletion",ACTIVITY_MOVE:"schedule_activity_move",ACTIVITY_INDENT:"schedule_activity_indent",ACTIVITY_OUTDENT:"schedule_activity_outdent"};function St(e){e.invalidateVisualOrderIds?.();let t=[];e.forEachActivity(o=>{M(o.parentId)&&t.push(o)}),t.sort(gl);let r=[];ml(r,t);let i=[],n=0;for(;r.length>0;){let o=r.pop();if(o.correlativeId!==n){let s=typeof o.correlativeId=="number"?o.correlativeId:void 0;i.push({activityId:String(o.id),before:s}),s!==void 0&&e.noteCorrelativeBefore?.(String(o.id),s),zm(o,n)}n+=1;let a=Or(String(o.id),e);a.sort(gl),ml(r,a)}return i}function ml(e,t){for(let r=t.length-1;r>=0;r-=1)e.push(t[r])}function Il(e){let t=e.correlativeId,r=typeof t=="number"?t:Number(t);return Number.isFinite(r)?r:Zn}var gl=(e,t)=>Il(e)-Il(t);function zm(e,t){e.correlativeId=t}function ta(e,t){if(!e||e==="0")return;let r=String(e);for(;r!==null;){let{workHours:i,realWorkHours:n}=Cl(r,t);t.setActivityField(r,x.WORK_HOURS,i),t.setActivityField(r,x.REAL_WORK_HOURS,n);let o=t.getActivity(r);if(!o)break;let a=o.parentId;if(!a||M(a))break;r=a}}function Al(e,t){let r=t.getActivity(e);if(!r)return;let i=r.parentId;!i||M(i)||ta(i,t)}function vl(e,t,r){for(let i of e){if(r.hasChildren(i))continue;let n=r.getActivity(i);n&&r.setActivityField(i,x.REAL_WORK_HOURS,Nt(Jr(n,x.WORK_HOURS),Jr(n,x.PROGRESS)))}for(let i of t)r.setActivityField(i,x.REAL_WORK_HOURS,Cl(i,r).realWorkHours)}function Cl(e,t){let r=0,i=0;for(let n of t.getChildren(e)){let o=t.getActivity(n);if(!o)continue;let a=Jr(o,x.WORK_HOURS);r+=a,i+=qm(n,o,a,t)}return{workHours:r,realWorkHours:i}}function Jr(e,t){let r=e[t];return typeof r=="number"&&Number.isFinite(r)?r:0}function qm(e,t,r,i){return i.hasChildren(e)?Jr(t,x.REAL_WORK_HOURS):Nt(r,Jr(t,x.PROGRESS))}function ea(e,t){if(!e||e==="0")return;let r=String(e);for(;r!==null;){let i=t.getChildren(r),n=0;for(let s of i){let c=t.getActivity(s);c&&(n+=Jm(c,x.USED_COST))}t.setActivityField(r,x.USED_COST,n);let o=t.getActivity(r);if(!o)break;let a=o.parentId;if(!a||M(a))break;r=a}}function Sl(e,t){let r=t.getActivity(e);if(!r)return;let i=r.parentId;!i||M(i)||ea(i,t)}function Jm(e,t){let r=e[t];return typeof r=="number"&&Number.isFinite(r)?r:0}function ra(e,t){if(!e||e==="0")return;let r=String(e);for(;r!==null;){let i=t.getChildren(r),n=0;for(let s of i){let c=t.getActivity(s);c&&(n+=Xm(c,x.COST))}t.setActivityField(r,x.COST,n);let o=t.getActivity(r);if(!o)break;let a=o.parentId;if(!a||M(a))break;r=a}}function Tl(e,t){let r=t.getActivity(e);if(!r)return;let i=r.parentId;!i||M(i)||ra(i,t)}function Xm(e,t){let r=e[t];return typeof r=="number"&&Number.isFinite(r)?r:0}var ln=Object.freeze({proplannerId:null,description:"",type:D.TASK,progress:0,constraintType:A.ASAP,constraintDate:null,autoScheduling:!0,assignedDefaultCalendar:!1,dateOrigin:null,cost:0,usedCost:0,realCost:0,workHours:0,realWorkHours:0,ponderator:0,hasCustomPonderator:!1,correlativeId:0,customId:null,subcontractId:null,isLookahead:!1,hasLookaheadTasks:!1,newActivityIds:[],hasNewActivities:!1,pendingRequestIds:[],responsableIds:[],tagIds:[],baselinePoints:[],baselineSnapshot:null,recursiveDurationHours:0,isCritical:!1,freeSlackHours:null,expectedProgress:null,expectedProgressBaseline:null,status:null,criticalPath:null}),El="New Master Plan",Dl="New Activity";var Zm=["name","description","type","startDate","durationHours","constraintType","constraintDate","calendarId","assignedDefaultCalendar","autoScheduling","progress","cost","usedCost","realCost","workHours","realWorkHours","ponderator","hasCustomPonderator","customId","subcontractId","responsableIds","tagIds","isLookahead"],dn=new Set(Zm);function Qm(e){let t=Object.getPrototypeOf(e);if(t!==null&&t!==Object.prototype)throw new Error("activity-create: override bag must be a plain object with no custom prototype");for(let r of Reflect.ownKeys(e))if(typeof r=="symbol"||!dn.has(r))throw new Error(`activity-create: rejected override key "${String(r)}" \u2014 not a creation-writable canonical field`);return e}function _l(e,t){let r=e.parentId!=null?t.getActivity(e.parentId):null,i=Qm(e.activityOverrides??{}),n=e.numTasksInGantt===0?El:Dl,o=i.name??n,a=i.durationHours??e.sector.hoursPerDay,s=i.calendarId??e.sector.defaultCalendar,c=tI(r,e.fallbackStartDate,i.startDate),l={...ln,...i,id:e.id,parentId:e.parentId,uniqueCorrelativeId:e.nextUniqueCorrelativeId,name:o,durationHours:a,calendarId:s,startDate:c,endDate:c},d=i.startDate?new Date(l.startDate):t.getClosestWorkTime({date:l.startDate,dir:K.FUTURE,task:l});if(!i.startDate&&r&&re(r.type)){let p=new Date(r.startDate);p.setUTCHours(0,0,0,0);let y=new Date(d);y.setUTCHours(0,0,0,0),y.getTime()!==p.getTime()&&(d=t.getClosestWorkTime({date:p,dir:K.FUTURE,task:l}))}let u=t.calculateEndDate({startDate:d,durationHours:l.durationHours,task:l});return{newTask:{...l,startDate:d,endDate:u,calendarDuration:Qt({type:l.type,startDate:d,endDate:u}),newActivityIds:[...l.newActivityIds],pendingRequestIds:[...l.pendingRequestIds],responsableIds:[...l.responsableIds],tagIds:[...l.tagIds],baselinePoints:[...l.baselinePoints]}}}function tI(e,t,r){return r?new Date(r):e?new Date(e.startDate):t?new Date(t):new Date}var mr={CREATE:"create",REPARENT:"reparent"};function eI(e){let t=e.type;if(t!==D.TASK&&t!==D.MILESTONE)return null;let r=e.startDate,i=e.endDate;return!(r instanceof Date)||!(i instanceof Date)?null:{type:t,startDate:new Date(r),endDate:new Date(i),durationHours:Number(e.durationHours??0),expectedProgressBaseline:typeof e.expectedProgressBaseline=="number"?e.expectedProgressBaseline:null,constraintType:e.constraintType??null,constraintDate:e.constraintDate instanceof Date?new Date(e.constraintDate):null,progress:Number(e.progress??0)}}function Ir(e){let t=e.getParent(e.parentId);if(!t)return null;let r=e.isCurrentlyLeaf!==void 0?e.isCurrentlyLeaf&&pe(t.type):rI(t),i=Array.isArray(t.newActivityIds)?t.newActivityIds:[],o={isLookahead:!1,hasNewActivities:!0,newActivityIds:i.some(a=>String(a)===String(e.newChildId))?[...i]:[...i,e.newChildId]};return t.customId!=null&&t.customId!==""&&(o.customId=null),r&&(o.type=no,(e.promotionSource??mr.CREATE)===mr.CREATE&&(o.constraintType=A.ASAP,o.constraintDate=null)),{parentId:e.parentId,fields:o,promotionSnapshot:eI(t)}}function rI(e){return pe(e.type)&&(!Array.isArray(e.newActivityIds)||e.newActivityIds.length===0)}function gr(e,t,r,i){let n=t,o=n==="0",a=ia(e,n);if(i!==void 0){let c=a.find(l=>l.id===i);if(c){let l=Rt(c),d=a.map(Rt).filter(f=>f<l);return d.length===0?l-1:(Math.max(...d)+l)/2}}if(r!==void 0){let c=a.find(l=>l.id===r);if(c){let l=Rt(c),d=a.map(Rt).filter(f=>f>l);if(d.length===0)return l+1;let u=Math.min(...d);return(l+u)/2}}return a.length===0?0:Math.max(...a.map(Rt))+1}var Ve=Number.MAX_SAFE_INTEGER,kl=Number.MAX_SAFE_INTEGER-1;function Rt(e){let t=e.correlativeId,r=typeof t=="number"?t:Number(t);return Number.isFinite(r)?r:Ve}function ia(e,t){return Or(t,e)}function Rl(e,t,r){let i=e,n=_e(e,r);for(;n!=null&&t.has(n);)i=n,n=_e(n,r);return i}function Ar(e,t,r){let i=new Set([e]),n=Gt(r.getActivity(e)?.parentId);for(;n!=="0"&&!i.has(n);){if(t.has(n))return!0;i.add(n),n=Gt(r.getActivity(n)?.parentId)}return!1}function _e(e,t){let r=t.getActivity(e);if(!r)return null;let i=Gt(r.parentId),n=Ht(i,t),o=n.findIndex(a=>String(a)===String(e));return o<=0?null:n[o-1]??null}function Pl(e,t,r,i){let n=Ht(t,e).filter(c=>String(c)!==String(i)).map(c=>e.getActivity(c)).filter(c=>c!==null);if(n.length===0)return 0;let o=n.map(Rt);if(r<=0)return o[0]-1;if(r>=o.length)return o[o.length-1]+1;let a=o[r-1],s=o[r];return(a+s)/2}var iI=new Set([...[...dn].filter(e=>e!==x.DURATION_HOURS),"durationDays"]);function un(e,t){if(e===void 0)return{ok:!0,value:{}};let r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype)return{ok:!1,reason:C.INVALID_VALUE};for(let o of Reflect.ownKeys(e))if(typeof o=="symbol"||!iI.has(o))return{ok:!1,reason:C.INVALID_VALUE};let{durationDays:i,...n}=e;return i!==void 0&&(!Number.isFinite(i)||i<0)?{ok:!1,reason:C.INVALID_VALUE}:{ok:!0,value:{...n,...i===0&&(n.type===void 0||n.type===D.TASK)?{type:D.MILESTONE}:{},...i===void 0?{}:{durationHours:be(i,t)}}}}async function Xr(e,t,r={}){let{adapter:i,scheduler:n,sector:o,calendars:a,activityIdGen:s,uidGen:c}=t;r.skipCacheInvalidation||n.invalidateAllCaches();let l=nI(e,i);if(!l.ok)return l;let{parent:d,anchorSiblingId:u,isRoot:f}=l,p=aI(e.activityId,i,s,t.isActivityIdReserved),y=c.next(),I={id:p,parentId:f?null:e.parentId,sector:{id:o.id,hoursPerDay:o.hoursPerDay,defaultCalendar:fI(a)},numTasksInGantt:i.activityCount(),nextUniqueCorrelativeId:y,activityOverrides:e.overrides??{}},L=_l(I,{getActivity:v=>i.getActivity(v),calculateEndDate:v=>i.calculateEndDate(v),getClosestWorkTime:v=>i.getClosestWorkTime(v)}).newTask;L.realWorkHours=Nt(L.workHours,L.progress),cI(L,e,t,u,d,r);let S=r.insertionCorrelativeId??gr(i,f?"0":e.parentId,e.afterSiblingId,e.beforeSiblingId);L.correlativeId=S;let E=new Set([p]);d&&E.add(d.id);let g=d!==null&&i.getChildren(d.id).length===0,b=g?d?.customId:null,B=r.skipBeforeSnap?new Map:await rt(i,E);i.addActivity(L),lI(e,p,d,i,g),b&&t.customIdTracker.releaseCustomId(b),r.skipRollupCascades||(Al(p,i),Sl(p,i),Tl(p,i));let k=dI(i,p,E,r);return{ok:!0,newId:p,parent:d,newActivity:L,beforeSnap:B,initialTouched:E,correlativeShifts:k}}function nI(e,t){let r=M(e.parentId),i=r?null:t.getActivity(e.parentId);if(!r&&!i)return{ok:!1,reason:C.PARENT_NOT_FOUND};if(i!==null&&Je(i))return{ok:!1,reason:C.PARENT_FROZEN_BY_SIR};if(e.afterSiblingId!==void 0&&e.beforeSiblingId!==void 0)return{ok:!1,reason:C.ANCHOR_SIBLING_CONFLICT};let a=e.afterSiblingId??e.beforeSiblingId,s=oI(e,t,r,a);return s||{ok:!0,parent:i,anchorSiblingId:a,isRoot:r}}function oI(e,t,r,i){if(i===void 0)return null;let n=t.getActivity(i);if(!n)return{ok:!1,reason:C.ANCHOR_SIBLING_NOT_FOUND};let o=r?"0":e.parentId;return(n.parentId==null?"0":String(n.parentId))!==o?{ok:!1,reason:C.ANCHOR_SIBLING_WRONG_PARENT}:null}function aI(e,t,r,i){let n=()=>{let o=r.next();for(;t.activityExists(o)||i(String(o));)o=r.next();return o};return e===void 0||t.activityExists(e)||i(String(e))?n():(r.bump(e),e)}function sI(e){let t=e.overrides?.customId;return typeof t=="string"?t:void 0}function cI(e,t,r,i,n,o){let{adapter:a,customIdTracker:s}=r,c=sI(t);if(c!==void 0){if(c.length===0)return;if(!s.isCustomIdInUse(c)){s.registerCustomId(c);return}}let l=o.customIdReferenceId??i,d=l!==void 0,u=d?a.getActivity(l):n;e.customId=s.generateCustomIdForNewChild({activity:u??{},useActivityCustomIdAsReference:d})}function lI(e,t,r,i,n){if(!r)return;let o=Ir({parentId:e.parentId,newChildId:t,isCurrentlyLeaf:n,getParent:a=>i.getActivity(a)??null});if(o){for(let[a,s]of Object.entries(o.fields))yt(i,o.parentId,a,s);o.promotionSnapshot&&i.setPromotionSnapshot(o.parentId,o.promotionSnapshot)}}function dI(e,t,r,i){if(i.skipCorrelativeRecompute)return[];let n=St(e).filter(o=>o.activityId!==String(t));for(let o of n)r.add(o.activityId);return n}async function uI(e,t,r,i,n){let{newId:o,newActivity:a,beforeSnap:s,initialTouched:c,correlativeShifts:l}=r,d={name:Kt.ACTIVITY_CREATION,properties:{parent_id:t.parentId,activity_id:o,created_duration:a.durationHours}};return t.eventSource!==void 0&&(d.properties.event_source=t.eventSource),z(e,{source:t,beforeSnap:s,touchedIds:c,scheduledIds:i,correlativeShifts:l,trackingEvents:[d],hoursPerDay:n})}async function Ll(e,t,r){let{adapter:i,scheduler:n,sector:o}=r,a=un(e.overrides,o.hoursPerDay);if(!a.ok)return a;let s=await Xr({...e,overrides:a.value},r);if(!s.ok)return s;let{newId:c}=s,l=s.newActivity.autoScheduling;i.setActivityField(c,"autoScheduling",!1);let d;try{d=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:c,recomputeParentsFrom:[c],preventSummaryTargetPullback:!0,now:r.now,options:t})}finally{i.setActivityField(c,"autoScheduling",l)}let{scheduledIds:u}=d;return{ok:!0,changes:await uI(i,e,s,u,o.hoursPerDay)}}function fI(e){for(let r of e.values())if(r.is_default)return r.id;let t=e.values().next();return!t.done&&t.value?t.value.id:"global"}function Ut(e,t){ta(e,t),ea(e,t),ra(e,t)}function fn(e,t){let r=new Set,i=[];for(let n of e){let o=String(n);r.has(o)||(r.add(o),i.push(o))}for(;i.length>0;){let n=i.pop(),o=t.getChildren(n);for(let a of o){let s=String(a);r.has(s)||(r.add(s),i.push(s))}}return r}function pn(e,t){let r=new Set;for(let i of e){for(let n of t.getOutgoingLinkIds(i))r.add(String(n));for(let n of t.getIncomingLinkIds(i))r.add(String(n))}return[...r]}function pI(e){return e?{type:e.type,startDate:new Date(e.startDate),endDate:new Date(e.endDate),durationHours:e.durationHours,expectedProgressBaseline:e.expectedProgressBaseline,constraintType:e.constraintType,constraintDate:e.constraintDate?new Date(e.constraintDate):null,progress:e.progress}:null}function yI(e,t,r){let i=e.startDate;return!r||!(i instanceof Date)?{}:{endDate:r(i,t)}}function vr(e){if(e.remainingChildIds.length>0)return null;let t=e.parent,r=e.defaultDurationHours,i=Number.isFinite(r),n=pI(e.promotionSnapshot)??(i?{type:tr,durationHours:r,progress:0,autoScheduling:!0,constraintType:A.ASAP,constraintDate:null,hasNewActivities:!1,...yI(t,r,e.computeEndDate)}:{type:tr});if(e.idsRemoved&&e.idsRemoved.size>0){let o=Array.isArray(t.newActivityIds)?t.newActivityIds:[];if(o.length>0){let a=o.filter(s=>!e.idsRemoved.has(s)&&!e.idsRemoved.has(String(s)));a.length!==o.length&&(n.newActivityIds=a)}}return t.hasLookaheadTasks&&(n.isLookahead=!0),{parentId:String(t.id),fields:n}}function yn(e){if(e.idsRemoved.size===0)return null;let t=e.parent.newActivityIds;if(!Array.isArray(t)||t.length===0)return null;let r=t,i=r.filter(n=>!e.idsRemoved.has(n)&&!e.idsRemoved.has(String(n)));return i.length===r.length?null:{parentId:String(e.parent.id),fields:{newActivityIds:[...i],hasNewActivities:i.length>0}}}var Ol=200;async function Nl(e,t,r){let{adapter:i,scheduler:n,customIdTracker:o,sector:a}=r;if(n.invalidateAllCaches(),e.activityIds.length===0)return{ok:!1,reason:C.ACTIVITY_IDS_EMPTY};for(let v of e.activityIds)if(!i.getActivity(v))return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let s=e.activityIds.filter(v=>{let P=i.getActivity(v);return!(P?.correlativeId===0&&P.type===D.PROJECT)}),c=fn(s,i),l=pn(c,i),d=new Set;for(let v of e.activityIds){let P=i.getActivity(v);if(!P)continue;let q=P.parentId;if(M(q))continue;let $=String(q);c.has($)||d.add($)}let u=new Set([...c,...d]),f=await rt(i,u),p=new Map;for(let v of l){let P=i.getLink(v);P&&p.set(v,{...P})}let y=new Set,I=0;for(let v of c){I+=1,I%Ol===0&&await st();let P=i.getActivity(v);if(!P)continue;let q=M(P.parentId)?null:i.getActivity(String(P.parentId)),$=q?.hasNewActivities===!0&&q.newActivityIds.some(it=>String(it)===String(v));(P.isNewActivity===!0||$)&&y.add(v);let ot=P.customId;typeof ot=="string"&&ot.length>0&&o.releaseCustomId(ot)}for(let v of l)i.removeLink(v);let T=Zr(i,c),L=0;for(let v of c)L+=1,L%Ol===0&&await st(),i.removeActivity(v);for(let v of d){let P=i.getActivity(v);if(!P)continue;hI(P,y,i);let q=i.getChildren(v),$=vr({parent:P,remainingChildIds:q.map(String),defaultDurationHours:a.hoursPerDay,promotionSnapshot:i.getPromotionSnapshot(v),computeEndDate:(ot,it)=>i.calculateEndDate({startDate:ot,durationHours:it,task:P}),idsRemoved:c});if(!$){Ni(v,i);continue}for(let[ot,it]of Object.entries($.fields))yt(i,v,ot,it);if(P.customId==null||P.customId===""){let ot=_e(v,i),it=ot?i.getActivity(ot)?.customId:null,Dt=o.generateCustomIdForRestoredChild(typeof it=="string"&&it?it:null);i.setActivityField(v,x.CUSTOM_ID,Dt)}}for(let v of d)Ut(v,i);let S=St(i),{scheduledIds:E}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:Ot.ROOTS,recomputeParentsFrom:d,now:r.now,options:t}),g={name:Kt.ACTIVITY_DELETION,properties:{activity_ids:[...e.activityIds],cascade_count:c.size}};e.eventSource!==void 0&&(g.properties.event_source=e.eventSource);let b=new Map;for(let[v,P]of p)b.set(v,P);let B=new Map;for(let v of c){let P=f.get(String(v));P&&B.set(String(v),P)}let k=await z(i,{source:e,beforeSnap:f,touchedIds:u,scheduledIds:E,sirDetection:Ft.AFTER_DIFF,links:oa(p),trackingEvents:[g],hoursPerDay:a.hoursPerDay,correlativeShifts:S});return{ok:!0,changes:T.length>0?{...k,viewState:T}:k,__beforeSnap:B,__beforeLinks:b}}function hI(e,t,r){let i=yn({parent:e,idsRemoved:t});if(i)for(let[n,o]of Object.entries(i.fields))yt(r,i.parentId,n,o)}function Zr(e,t){let r=[];for(let i of t){let n=e.isChecked(i),o=e.isVisible(i);!n&&o||r.push({activityId:String(i),...n?{checked:{before:!0,after:!1}}:{},...o?{}:{visible:{before:!1,after:!0}}})}return r}function oa(e){let t=[];for(let[r,i]of e.entries())t.push({id:r,kind:N.DELETED,fields:{source:{before:String(i.source),after:void 0},target:{before:String(i.target),after:void 0},type:{before:i.type,after:void 0},lag:{before:Number(i.lag),after:void 0}},after:null});return t}async function wl(e,t,r){let i=mI(e,r);if(i)return{ok:!1,reason:i};let n=gI(e,r);if(!n.ok)return n;let o=e.mode===pt.REPLACE?new Set(r.adapter.getAllIds().map(g=>String(g))):new Set,a=e.mode===pt.REPLACE?await rt(r.adapter,o):new Map,s=e.mode===pt.REPLACE?EI(r):new Map,c=e.mode===pt.REPLACE?Zr(r.adapter,o):[];r.scheduler.invalidateAllCaches();let l=[];if(e.mode===pt.REPLACE){for(let g of s.keys()){let b=ye({kind:at.DELETE,linkId:g},{port:r.adapter});if(!b.applied)return{ok:!1,reason:b.rejected??C.INVALID};l.push({op:{kind:at.DELETE,linkId:g},finalLinkId:g,rejected:null})}for(let g of o){let b=r.adapter.getActivity(g)?.customId;typeof b=="string"&&b.length>0&&r.customIdTracker.releaseCustomId(b),r.adapter.removeActivity(g)}}let d=await TI(e,n.plan.items,r);if(!d.ok)return d;let u=xl(e)?[]:St(r.adapter),f=new Set(n.plan.items.map(g=>String(g.activityId))),p=u.filter(g=>!f.has(g.activityId)),y=e.mode===pt.REPLACE?new Set(o):new Set;lr(r.adapter,u,f,a,y);for(let g of n.plan.items)y.add(String(g.activityId));let I=n.plan.links.map(g=>({operation:{kind:at.CREATE,source:g.source,target:g.target,type:g.type,lag:Wt(g.lag??0,r.sector.hoursPerDay)},linkId:g.linkId})),T=Ti(I,{port:r.adapter,preserved:s});if(!T.applied)return{ok:!1,reason:T.rejected??C.INVALID};for(let{operation:g,linkId:b}of I)l.push({op:g,finalLinkId:b,rejected:null});let L=n.plan.items.map(g=>g.activityId),{scheduledIds:S}=await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:e.items.length>0||e.links.length>0?Ot.ROOTS:null,recomputeParentsFrom:L,now:r.now,options:t}),E=await z(r.adapter,{source:e,beforeSnap:a,touchedIds:y,scheduledIds:S,links:pr(l,s,r.adapter),hoursPerDay:r.sector.hoursPerDay,correlativeShifts:p,...e.mode===pt.REPLACE?{sirDetection:Ft.AFTER_DIFF}:{}});return{ok:!0,changes:c.length>0?{...E,viewState:c}:E,...e.mode===pt.REPLACE?{__beforeSnap:a,__beforeLinks:DI(s)}:{}}}function mI(e,t){if(e.mode!==pt.APPEND&&e.mode!==pt.REPLACE)return C.INVALID;let r=new Set,i=new Set;for(let o of e.items){if(o.batchId.length===0||r.has(o.batchId))return C.INVALID;if(r.add(o.batchId),o.index!==void 0&&(!Number.isInteger(o.index)||o.index<0))return C.INVALID;if(o.activityId!==void 0){let a=String(o.activityId);if(a.length===0||a==="0"||i.has(a))return C.INVALID;i.add(a)}}for(let o of e.items)if(!aa(o.parent,!0,e.mode,r,t))return C.PARENT_NOT_FOUND;if(II(e.items))return C.INVALID;let n=new Set;for(let o of e.links){if(!Object.values(H).includes(o.type))return C.INVALID_LINK_TYPE;if(o.lag!==void 0&&!Number.isFinite(o.lag))return C.INVALID_LINK_LAG;if(!aa(o.source,!1,e.mode,r,t)||!aa(o.target,!1,e.mode,r,t))return C.ACTIVITY_NOT_FOUND;if(o.linkId!==void 0){let a=String(o.linkId);if(a.length===0||n.has(a))return C.INVALID;n.add(a)}}return null}function aa(e,t,r,i,n){return typeof e=="string"?e==="0"?t:r===pt.APPEND&&n.adapter.getActivity(String(e))!==null:e!==null&&e.batchId.length>0&&i.has(e.batchId)}function II(e){let t=new Map;for(let i of e)typeof i.parent!="string"&&t.set(i.batchId,i.parent.batchId);let r=new Set;for(let i of e){let n=new Set,o=i.batchId;for(;o!==void 0&&!r.has(o);){if(n.has(o))return!0;n.add(o),o=t.get(o)}for(let a of n)r.add(a)}return!1}function gI(e,t){let r=new Map;for(let d of e.items){let u=un(d.overrides,t.sector.hoursPerDay);if(!u.ok)return u;r.set(d.batchId,u.value)}let i=new Map,n=new Set;for(let d of e.items){let u=AI(d.activityId,e.mode,n,t);n.add(String(u)),i.set(d.batchId,u)}let o=new Set,a=e.links.map(d=>{let u=vI(d.linkId,e.mode,o,t);return o.add(String(u)),u}),s=CI(e,i,t),c=[];for(let d of e.items){let u=i.get(d.batchId),f=s.get(d.batchId);if(u===void 0||f===void 0)return{ok:!1,reason:C.INVALID};let p=typeof d.parent=="string"?null:d.parent.batchId,y=typeof d.parent=="string"?d.parent:i.get(d.parent.batchId);if(y===void 0)return{ok:!1,reason:C.PARENT_NOT_FOUND};c.push({input:d,activityId:u,parentId:y,parentBatchId:p,insertionCorrelativeId:f,overrides:r.get(d.batchId)??{}})}let l=[];for(let[d,u]of e.links.entries()){let f=Fl(u.source,i),p=Fl(u.target,i),y=a[d];if(f===null||p===null||y===void 0)return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};l.push({source:f,target:p,type:u.type,lag:u.lag??0,linkId:y})}return{ok:!0,plan:{items:c,links:l}}}function AI(e,t,r,i){if(e!==void 0&&(t===pt.REPLACE||i.adapter.getActivity(e)===null&&!i.isActivityIdReserved(String(e)))&&!r.has(String(e)))return i.activityIdGen.bump(e),e;let o=i.activityIdGen.next();for(;r.has(String(o))||t===pt.APPEND&&(i.adapter.getActivity(o)!==null||i.isActivityIdReserved(String(o)));)o=i.activityIdGen.next();return o}function vI(e,t,r,i){if(e!==void 0&&(t===pt.REPLACE||i.adapter.getLink(e)===null&&!i.isLinkIdReserved(String(e)))&&!r.has(String(e)))return i.linkIdGen.bump(e),e;let o=i.linkIdGen.next();for(;r.has(String(o))||t===pt.APPEND&&(i.adapter.getLink(o)!==null||i.isLinkIdReserved(String(o)));)o=i.linkIdGen.next();return o}function CI(e,t,r){if(xl(e)){let s=r.adapter.activityCount();return new Map(e.items.map((c,l)=>[c.batchId,s+l]))}let i=new Set(Array.from(t.values(),s=>String(s))),n=new Map;for(let s of e.items){let c=t.get(s.batchId);if(c===void 0)continue;let l=typeof s.parent=="string"?s.parent:t.get(s.parent.batchId);if(l===void 0)continue;let d=String(l),u=n.get(d);u||(u={existing:e.mode===pt.REPLACE||typeof s.parent!="string"&&t.has(s.parent.batchId)?[]:ia(r.adapter,d).sort((I,T)=>Rt(I)-Rt(T)||String(I.id).localeCompare(String(T.id))).map(I=>String(I.id)),newIdsByTarget:new Map},n.set(d,u));let f=s.index===void 0?u.existing.length:Math.min(s.index,u.existing.length),p=u.newIdsByTarget.get(f)??[];p.push(String(c)),u.newIdsByTarget.set(f,p)}let o=new Map,a=new Map(Array.from(t,([s,c])=>[String(c),s]));for(let s of n.values()){let c=[];for(let d=0;d<=s.existing.length;d+=1){for(let f of s.newIdsByTarget.get(d)??[])c.push(f);let u=s.existing[d];u!==void 0&&c.push(u)}let l=0;for(;l<c.length;){if(!i.has(c[l])){l+=1;continue}let d=l;for(;l<c.length&&i.has(c[l]);)l+=1;let u=l-d,f=d>0?bl(c[d-1],r):null,p=l<c.length?bl(c[l],r):null;for(let y=0;y<u;y+=1){let I=c[d+y],T=a.get(I);T!==void 0&&o.set(T,SI(f,p,y+1,u))}}}return o}function xl(e){return e.mode===pt.APPEND&&e.items.every(t=>t.parent==="0"&&t.index===void 0)}function bl(e,t){let r=t.adapter.getActivity(e);return r?Rt(r):0}function SI(e,t,r,i){return e!==null&&t!==null&&t>e?e+(t-e)*r/(i+1):e!==null?e+r:t!==null?t-(i-r+1):r-1}async function TI(e,t,r){let i=new Map,n=[];for(let a of t){if(a.parentBatchId===null){n.push(a);continue}let s=i.get(a.parentBatchId)??[];s.push(a),i.set(a.parentBatchId,s)}for(let a=0;a<n.length;a+=1){let s=n[a],c=await Xr({kind:m.ACTIVITY_CREATE,parentId:s.parentId,activityId:s.activityId,overrides:s.overrides,...e.eventSource===void 0?{}:{eventSource:e.eventSource}},r,{skipCorrelativeRecompute:!0,skipBeforeSnap:!0,skipCacheInvalidation:!0,skipRollupCascades:!0,insertionCorrelativeId:s.insertionCorrelativeId});if(!c.ok)return c;for(let l of i.get(s.input.batchId)??[])n.push(l)}if(n.length!==t.length)return{ok:!1,reason:C.INVALID};let o=new Set;for(let a=n.length-1;a>=0;a-=1){let s=n[a].parentId;s==="0"||o.has(String(s))||(o.add(String(s)),Ut(s,r.adapter))}return{ok:!0}}function Fl(e,t){return typeof e=="string"?e:t.get(e.batchId)??null}function EI(e){return new Map(e.adapter.getAllLinks().map(t=>[String(t.id),{...t}]))}function DI(e){return new Map(Array.from(e,([t,r])=>[String(t),r]))}function Ml(e,t){let{adapter:r}=t,i=e.activityId,n=r.getActivity(i);if(!n)return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let o=n.pendingRequestIds??[],a=e.pendingRequests.map(l=>l.id);r.setActivityField(e.activityId,"pendingRequestIds",a);let s=r.getActivity(i);if(!s)return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let c={id:i,kind:N.UPDATED,fields:{pendingRequestIds:{before:o,after:a}},after:et(s)};return{ok:!0,changes:{source:e,activities:[c],links:[],calendars:[],trackingEvents:[]}}}function Ul(e){let t=new Map;for(let r of e){let i=r.proplannerId;typeof i=="number"&&Number.isSafeInteger(i)&&i>0&&t.set(i,String(r.id))}return t}function Bl(e,t,r){let i=new Set(t.map(({id:n})=>String(n)));for(let n of e)if((n.proplannerId==null||n.proplannerId===0)&&!i.has(String(n.id)))throw new Error(`persistence-acknowledge: missing ${r} proplannerId for "${String(n.id)}"`)}function _I(e,t,r,i,n,o){let a=String(e.id);if(a.length===0||n.has(a))throw new Error(`persistence-acknowledge: duplicate or empty ${t} id "${a}"`);if(!Number.isSafeInteger(e.proplannerId)||e.proplannerId<=0)throw new Error(`persistence-acknowledge: invalid ${t} proplannerId ${String(e.proplannerId)}`);if(o.has(e.proplannerId))throw new Error(`persistence-acknowledge: duplicate ${t} proplannerId ${String(e.proplannerId)}`);let s=r(a);if(!s.exists)throw new Error(`persistence-acknowledge: unknown ${t} id "${a}"`);if(s.current!==null&&s.current!==0&&s.current!==e.proplannerId)throw new Error(`persistence-acknowledge: ${t} "${a}" already has proplannerId ${String(s.current)}`);let c=i.get(e.proplannerId);if(c!==void 0&&c!==a)throw new Error(`persistence-acknowledge: ${t} proplannerId ${String(e.proplannerId)} already belongs to "${c}"`);n.add(a),o.add(e.proplannerId)}function Hl(e,t,r,i){let n=new Set,o=new Set;for(let a of e)_I(a,t,r,i,n,o)}async function Wl(e,t){let r=e.filter(s=>{let c=t.adapter.getActivity(String(s.activityId));return c!==null&&c.progress!==s.progress}),i=new Set(r.map(s=>String(s.activityId))),n=Hr(t.adapter,i),o=new Set(i);for(let s of n)o.add(String(s));let a=await rt(t.adapter,o);return t.adapter.batchUpdate(()=>{for(let s of r){let c=String(s.activityId);t.adapter.setActivityField(c,"progress",s.progress),t.adapter.setActivityField(c,"autoScheduling",Le(s.progress))}Gs(n,t.adapter),vl(i,n,t.adapter)}),[...await Gi(t.adapter,a,o)]}async function Vl(e,t){let r=e.activities??[],i=e.links??[],n=t.adapter.getAllActivities(),o=t.adapter.getAllLinks(),a=e.checkpoint?.activities??n,s=e.checkpoint?.links??o,c=new Map(a.map(y=>[String(y.id),y])),l=new Map(s.map(y=>[String(y.id),y])),d=Ul(a),u=Ul(s);Hl(r,"activity",y=>{let I=c.get(y);return{exists:I!==void 0,current:I?.proplannerId??null}},d),Hl(i,"link",y=>{let I=l.get(y);return{exists:I!==void 0,current:I?.proplannerId??null}},u),Bl(a,r,"activity"),Bl(s,i,"link");let f=[],p=[];return t.adapter.batchUpdate(()=>{for(let y of r){let I=t.adapter.getActivity(y.id);if(!I||I.proplannerId===y.proplannerId)continue;let T=I.proplannerId;t.adapter.setActivityField(y.id,"proplannerId",y.proplannerId),f.push({id:y.id,kind:N.UPDATED,fields:{proplannerId:{before:T,after:y.proplannerId}},after:{...I,proplannerId:y.proplannerId}})}for(let y of i){let I=t.adapter.getLink(y.id);if(!I||I.proplannerId===y.proplannerId)continue;let T=I.proplannerId;t.adapter.setLinkProplannerId(y.id,y.proplannerId),p.push({id:y.id,kind:N.UPDATED,fields:{proplannerId:{before:T,after:y.proplannerId}},after:{...I,proplannerId:y.proplannerId}})}}),{ok:!0,changes:{source:e,activities:f,links:p,calendars:[],trackingEvents:[]}}}async function Kl(e,t,r){if(kI(e))return{ok:!1,reason:C.INVALID_VALUE};let i=[...new Set(e.activityIds.map(String))];if(e.acknowledgePersistedLookahead===!0&&i.some(s=>!r.isActivityIdReserved(s)))return{ok:!1,reason:C.INVALID};let o=i.map(s=>r.adapter.getActivity(s));if(o.some(s=>!s))return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let a=[];for(let[s,c]of i.entries()){let l=o[s];if(!l)continue;let d={};l.isLookahead!==e.isLookahead&&(d.isLookahead={before:l.isLookahead,after:e.isLookahead},r.adapter.setActivityField(c,"isLookahead",e.isLookahead)),l.hasLookaheadTasks!==e.hasLookaheadTasks&&(d.hasLookaheadTasks={before:l.hasLookaheadTasks,after:e.hasLookaheadTasks},r.adapter.setActivityField(c,"hasLookaheadTasks",e.hasLookaheadTasks)),Object.keys(d).length!==0&&a.push({id:c,kind:N.UPDATED,fields:d,after:{...l,isLookahead:e.isLookahead,hasLookaheadTasks:e.hasLookaheadTasks}})}return e.persistedProgress!==void 0&&(await Wl([{activityId:i[0],progress:e.persistedProgress}],r)).length>0?(await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:e.persistedProgress===0?i[0]:null,recomputeParentsFrom:[],now:r.now,options:t}),{ok:!0,changes:await z(r.adapter,{source:e,beforeSnap:new Map,touchedIds:[],scheduledIds:[],hoursPerDay:r.sector.hoursPerDay})}):{ok:!0,changes:{source:e,activities:a,links:[],calendars:[],trackingEvents:[]}}}function kI(e){let t=e.persistedProgress;return t!==void 0&&(e.activityIds.length!==1||!Number.isFinite(t)||t<0||t>100)}function ca(e,t){let{adapter:r}=t,i=new Set(e.conversionRootIds.map(f=>String(f)));if(i.size===0)throw new Error("Conversion requires at least one root");for(let f of i)MI(f,r);let n=r.getVisualOrderIds().filter(f=>i.has(f)&&!Ar(f,i,r)),o=n.map(f=>RI(f,r)),a=o.map(({conversionRootId:f,convertedActivities:p})=>({conversionRootId:f,convertedActivities:p})),s=o.flatMap(f=>f.milestoneMoves),c=o.flatMap(f=>f.activityIdsToDelete),l=o.map(f=>f.formerParent),d=new Set(c),u=pn(d,r);return{sourceStateRevision:t.stateRevision,conversionRootIds:n,conversionGroups:a,milestoneMoves:s,activityIdsToDelete:c,linkIdsToDelete:u,formerParents:l}}async function Gl(e,t,r){if(e.expectedStateRevision!==r.stateRevision)return{ok:!1,reason:C.STALE_STATE_REVISION};let i=ca(e,r);if(!UI(i,r.adapter))return{ok:!1,reason:C.HIERARCHY_CYCLE};let{adapter:n,scheduler:o}=r;o.invalidateAllCaches();let a=await NI(i,n);bI(i,r),$l(i,n),FI(i,a.deletedIds,n);let s=wI(i,n);lr(n,s,a.deletedIds,a.beforeSnap,a.touchedIds);let{scheduledIds:c}=await Z({adapter:n,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:"roots",recomputeParentsFrom:a.touchedIds,now:r.now,options:t,recomputeParentProgress:!0}),l=await z(n,{source:e,beforeSnap:a.beforeSnap,touchedIds:a.touchedIds,scheduledIds:c,sirDetection:"after-diff",links:oa(a.beforeLinks),hoursPerDay:r.sector.hoursPerDay,correlativeShifts:s});return xI(i,a,l)}function RI(e,t){let r=sa(e,t),i=fn([e],t);if(i.delete(e),i.size===0)throw new Error(`Conversion root ${e} has no descendants`);let n=t.getVisualOrderIds().filter(c=>i.has(c)).map(c=>sa(c,t));Yl(r);for(let c of n)Yl(c);let o=n.filter(c=>c.type!==D.MILESTONE),a=n.filter(c=>c.type===D.MILESTONE),s=PI(r,o);return{conversionRootId:e,convertedActivities:o.map(c=>LI(c,s)),milestoneMoves:OI(r,a),activityIdsToDelete:o.map(c=>c.id),formerParent:{activity:et(r),hasConvertedActivities:o.length>0}}}function PI(e,t){let r=new Map;t.length>0&&r.set(e.id,jl(e));for(let i of t)r.set(i.id,jl(i));return r}function LI(e,t){let r=et(e),i=Gt(e.parentId),n=t.get(i);return r.parentId=n===void 0?null:String(n),r}function OI(e,t){let r=[],i=Gt(e.parentId),n=e.id;for(let o of t)r.push({activityId:o.id,parentId:i,afterSiblingId:n}),n=o.id;return r}async function NI(e,t){let r=new Set(e.activityIdsToDelete),i=new Set([...e.conversionRootIds,...e.activityIdsToDelete,...e.milestoneMoves.map(({activityId:n})=>n),...e.milestoneMoves.map(({parentId:n})=>n).filter(n=>n!=="0")]);return{deletedIds:r,touchedIds:i,beforeSnap:await rt(t,i),beforeLinks:BI(e.linkIdsToDelete,t),viewStateChanges:Zr(t,r)}}function bI(e,t){for(let r of e.activityIdsToDelete){let i=t.adapter.getActivity(r)?.customId;i&&t.customIdTracker.releaseCustomId(i)}}function $l(e,t){for(let r of e.milestoneMoves)t.setActivityFields(r.activityId,{parentId:r.parentId,correlativeId:gr(t,r.parentId,r.afterSiblingId,void 0)});for(let r of e.linkIdsToDelete)t.removeLink(r);for(let r of[...e.activityIdsToDelete].reverse())t.removeActivity(r);for(let{activity:r}of e.formerParents)t.setActivityField(r.id,x.TYPE,D.TASK)}function FI(e,t,r){for(let{activity:i,hasConvertedActivities:n}of e.formerParents){let o=sa(i.id,r),a=yn({parent:o,idsRemoved:t});r.setActivityFields(i.id,{isLookahead:i.isLookahead||n,hasLookaheadTasks:i.hasLookaheadTasks||n,...a?.fields??{}})}}function wI(e,t){for(let{activity:r}of e.formerParents)Ut(r.parentId,t);return St(t)}function xI(e,t,r){let i=new Map;for(let n of t.deletedIds){let o=t.beforeSnap.get(n);o&&i.set(n,o)}return{ok:!0,changes:t.viewStateChanges.length===0?r:{...r,viewState:t.viewStateChanges},conversionGroups:e.conversionGroups.map(({conversionRootId:n,convertedActivities:o})=>({conversionRootId:n,convertedActivities:o.map(a=>et(a))})),__beforeSnap:i,__beforeLinks:t.beforeLinks}}function MI(e,t){let r=t.getActivity(e);if(!r)throw new Error(`Conversion root ${e} was not found`);if(r.type===D.PROJECT&&r.correlativeId===0)throw new Error(`Conversion root ${e} is the visual project root`)}function sa(e,t){let r=t.getActivity(e);if(!r)throw new Error(`Conversion activity ${e} is missing`);return r}function jl(e){if(e.proplannerId==null)throw new Error(`Conversion activity ${e.id} has no persisted identifier`);return e.proplannerId}function Yl(e){if(!Number.isFinite(e.startDate.getTime()))throw new Error(`Conversion activity ${e.id} has invalid startDate`);if(!Number.isFinite(e.endDate.getTime()))throw new Error(`Conversion activity ${e.id} has invalid endDate`)}function UI(e,t){let r=t.fork();return $l(e,r),Oe({port:t,proposedPort:r,currentLinks:t.getAllLinks(),proposedLinks:r.getAllLinks()}).ok}function BI(e,t){let r=new Map;for(let i of e){let n=t.getLink(i);n&&r.set(i,{...n})}return r}function hn(e,t){let r=new Set;for(let n of e)r.add(String(n));let i=[];for(let n of t.getAllLinks()){let o=String(n.source),a=String(n.target);!r.has(o)&&!r.has(a)||(zl(a,o,t)||zl(o,a,t))&&i.push(String(n.id))}return i}function zl(e,t,r){let i=String(e),n=new Set;for(;i!=null;){if(n.has(i))return!1;n.add(i);let o=r.getActivity(i);if(!o)return!1;let a=o.parentId;if(a===null||M(a))return!1;let s=a;if(s===t)return!0;i=s}return!1}function mn(e,t){let r=e.getAllLinks();return!Oe({port:e,currentLinks:r,proposedLinks:r,proposal:{reparented:t}}).ok}function In(e,t){let r=new Set;if(e.length===0)return r;let i=new Map(e.map(o=>[o.activityId,o.newParentId]));if(!mn(t,i))return r;let n=new Map;for(let o of e){let a=new Map(n);if(a.set(o.activityId,o.newParentId),mn(t,a)){r.add(o.activityId);continue}n.set(o.activityId,o.newParentId)}return r}async function ql(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;n.invalidateAllCaches();let a=i.getActivity(e.activityId);if(!a)return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let s=M(e.parentId);if(!s&&!i.getActivity(e.parentId))return{ok:!1,reason:C.PARENT_NOT_FOUND};if(!s&&(e.parentId===e.activityId||i.isChildOf(e.parentId,e.activityId)))return{ok:!1,reason:C.CANNOT_MOVE_INTO_OWN_DESCENDANT};if(e.afterSiblingId!==void 0&&e.beforeSiblingId!==void 0)return{ok:!1,reason:C.ANCHOR_SIBLING_CONFLICT};let c=e.afterSiblingId??e.beforeSiblingId;if(c!==void 0){let b=i.getActivity(c);if(!b)return{ok:!1,reason:C.ANCHOR_SIBLING_NOT_FOUND};if((b.parentId===null?"0":String(b.parentId))!==e.parentId)return{ok:!1,reason:C.ANCHOR_SIBLING_WRONG_PARENT}}let l=a.parentId,d=Gt(l),u=String(e.parentId),f=d!==u;if(f){let b=new Map([[e.activityId,s?null:e.parentId]]);if(mn(i,b))return{ok:!1,reason:C.HIERARCHY_CYCLE}}let p=new Set([e.activityId]);f?(d!=="0"&&p.add(d),u!=="0"&&p.add(u)):d!=="0"&&p.add(d);let y=await rt(i,p);f&&i.setActivityField(e.activityId,x.PARENT,u);let I=gr(i,e.parentId,e.afterSiblingId,e.beforeSiblingId);if(i.setActivityField(e.activityId,x.CORRELATIVE_ID,I),f){if(!s){let b=i.getActivity(e.parentId);if(b){let B=b.customId,k=pe(b.type)&&i.getChildren(e.parentId).filter(P=>P!==e.activityId).length===0,v=Ir({parentId:e.parentId,newChildId:e.activityId,getParent:P=>i.getActivity(P)??null,isCurrentlyLeaf:k,promotionSource:mr.REPARENT});if(v){for(let[P,q]of Object.entries(v.fields))yt(i,v.parentId,P,q);v.promotionSnapshot&&i.setPromotionSnapshot(v.parentId,v.promotionSnapshot),v.fields.customId===null&&an(B,r.customIdTracker)}}}if(d!=="0"){let b=i.getActivity(d);if(b){let B=i.getChildren(d),k=vr({parent:b,remainingChildIds:B.map(String),defaultDurationHours:o.hoursPerDay,promotionSnapshot:i.getPromotionSnapshot(d),computeEndDate:(v,P)=>i.calculateEndDate({startDate:v,durationHours:P,task:b}),idsRemoved:new Set([e.activityId])});if(k){for(let[ot,it]of Object.entries(k.fields))yt(i,d,ot,it);let v=_e(d,i),P=v?i.getActivity(v)?.customId:null,q=typeof P=="string"&&P?P:null,$=r.customIdTracker.generateCustomIdForRestoredChild(q);i.setActivityField(d,x.CUSTOM_ID,$)}}}}f&&(d!=="0"&&Ut(d,i),s||Ut(e.parentId,i));let T=St(i);for(let b of T){if(p.add(b.activityId),y.has(b.activityId))continue;let B=i.getActivity(b.activityId);if(!B)continue;let k=et(B);b.before!==void 0&&(k.correlativeId=b.before),y.set(b.activityId,k)}let L=f&&d!=="0"?i.getChildren(d).map(String):[],{scheduledIds:S}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:e.activityId,recomputeParentsFrom:[e.activityId,e.parentId,...L],now:r.now,options:t,recomputeParentProgress:f}),E=f?hn([e.activityId],i):[],g={name:Kt.ACTIVITY_MOVE,properties:{activity_id:e.activityId,new_parent_id:e.parentId,after_sibling_id:e.afterSiblingId??null,before_sibling_id:e.beforeSiblingId??null,invalid_link_ids:E.map(String)}};return e.eventSource!==void 0&&(g.properties.event_source=e.eventSource),{ok:!0,changes:await z(i,{source:e,beforeSnap:y,touchedIds:p,scheduledIds:S,sirDetection:Ft.BEFORE_DIFF,trackingEvents:[g],hoursPerDay:o.hoursPerDay})}}function gn(e,t){let r=new Set(e),i=[],n=[],o=new Set,a=new Set(r),s=[...e].sort((d,u)=>{let f=t.getActivity(d),p=t.getActivity(u),y=f?Rt(f):Ve,I=p?Rt(p):Ve;return y-I});for(let d of s){if(!t.getActivity(d)){i.push({activityId:d,reason:C.ACTIVITY_NOT_FOUND}),a.delete(d);continue}if(Ar(d,o,t))continue;let f=hs(d,a,t);if(f==null){i.push({activityId:d,reason:C.INDENT_NO_ELIGIBLE_SIBLING}),a.delete(d);continue}let p=t.getActivity(d)?.parentId,y=M(p)?"0":String(p);n.push({activityId:d,newParentId:f,oldParentId:y}),o.add(d)}let c=In(n,t);for(let d of c)i.push({activityId:d,reason:C.HIERARCHY_CYCLE});let l=n.filter(d=>!c.has(d.activityId));return{moves:n,cyclicMoveIds:c,allowedMoves:l,failed:i}}async function Jl(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;if(n.invalidateAllCaches(),e.activityIds.length===0)return{ok:!1,reason:C.ACTIVITY_IDS_EMPTY};let a=new Set,s=[],c=gn(e.activityIds,i),l=[...c.failed];for(let S of c.moves)a.add(String(S.activityId)),a.add(String(S.newParentId)),S.oldParentId!=="0"&&a.add(String(S.oldParentId));let d=c.allowedMoves,u=await rt(i,a);for(let{activityId:S,newParentId:E}of d)i.setActivityField(S,x.PARENT,E),i.setActivityField(S,x.CORRELATIVE_ID,kl),s.push(S);let f=new Set;for(let{activityId:S,newParentId:E}of d){if(f.has(E))continue;f.add(E);let g=i.getActivity(E);if(!g)continue;let b=g.customId,B=pe(g.type)&&i.getChildren(E).filter(P=>!s.includes(P)).length===0,k=g.hasNewActivities&&g.newActivityIds.some(P=>String(P)===String(S)),v=Ir({parentId:E,newChildId:S,getParent:P=>i.getActivity(P)??null,isCurrentlyLeaf:B,promotionSource:mr.REPARENT});if(v){for(let[P,q]of Object.entries(v.fields))yt(i,v.parentId,P,q);v.promotionSnapshot&&i.setPromotionSnapshot(v.parentId,v.promotionSnapshot),k||(i.setActivityField(E,x.HAS_NEW_ACTIVITIES,!1),i.setActivityField(E,x.NEW_ACTIVITIES_ARRAY,[]))}i.setActivityField(E,x.CONSTRAINT_TYPE,A.ASAP),i.setActivityField(E,x.CONSTRAINT_DATE,null),i.setActivityField(E,x.CUSTOM_ID,null),an(b,r.customIdTracker)}let p=new Set;for(let S of d)S.oldParentId!=="0"&&p.add(S.oldParentId),p.add(S.newParentId);for(let S of p)Ut(S,i);let y=St(i);for(let S of y){if(a.add(S.activityId),u.has(S.activityId))continue;let E=i.getActivity(S.activityId);if(!E)continue;let g=et(E);S.before!==void 0&&(g.correlativeId=S.before),u.set(S.activityId,g)}let{scheduledIds:I}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:null,recomputeParentsFrom:s,now:r.now,options:t}),T=hn(s,i),L={name:Kt.ACTIVITY_INDENT,properties:{activity_ids:s,failed:l.map(S=>({activity_id:S.activityId,reason:S.reason})),invalid_link_ids:T}};return e.eventSource!==void 0&&(L.properties.event_source=e.eventSource),{ok:!0,activityVerdicts:e.activityIds.map(S=>{let E=l.find(g=>String(g.activityId)===String(S));return E?{activityId:String(S),ok:!1,reason:E.reason}:{activityId:String(S),ok:!0}}),changes:await z(i,{source:e,beforeSnap:u,touchedIds:a,scheduledIds:I,trackingEvents:[L],hoursPerDay:o.hoursPerDay})}}async function Xl(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;if(n.invalidateAllCaches(),e.activityIds.length===0)return{ok:!1,reason:C.ACTIVITY_IDS_EMPTY};let a=new Set(e.activityIds),s=new Map,c=new Map;for(let k of e.activityIds){let v=k;i.getActivity(v)&&(s.set(v,Qn(v,i)),c.set(v,Rl(v,a,i)))}let l=new Set,d=[],u=[],f=new Set,p=[],y=new Set,I=[...e.activityIds].sort((k,v)=>{let P=i.getActivity(k),q=i.getActivity(v),$=P?Rt(P):Ve,ot=q?Rt(q):Ve;return $-ot});for(let k of I){let v=k,P=i.getActivity(v);if(!P){d.push({activityId:v,reason:C.ACTIVITY_NOT_FOUND});continue}if(Ar(v,y,i))continue;let q=P.parentId;if(M(q)){d.push({activityId:v,reason:C.OUTDENT_ROOT_LEVEL_NOT_EDITABLE});continue}let $=String(q),ot=i.getActivity($);if(!ot){d.push({activityId:v,reason:C.ACTIVITY_NOT_FOUND});continue}let it=ot.parentId;if(M(it)){d.push({activityId:v,reason:C.OUTDENT_ROOT_LEVEL_NOT_EDITABLE});continue}let Dt=String(it),wt=Qn($,i)+1,ht=c.get(v);if(ht!=null&&a.has(ht)){let Ge=s.get(ht)??-1,$e=s.get(v)??-1;Ge>=0&&$e>=0&&(wt+=$e-Ge)}p.push({activityId:v,grandparentKey:Dt,oldParentKey:$,targetIndexInGrandparent:wt}),y.add(v),l.add(String(v)),l.add(String($)),Dt!=="0"&&l.add(String(Dt)),f.add($)}let T=In(p.map(k=>({activityId:k.activityId,newParentId:k.grandparentKey})),i);for(let k of T)d.push({activityId:k,reason:C.HIERARCHY_CYCLE});let L=p.filter(k=>!T.has(k.activityId)),S=await rt(i,l);for(let k of L){i.setActivityField(k.activityId,x.PARENT,k.grandparentKey);let v=Pl(i,k.grandparentKey,k.targetIndexInGrandparent,k.activityId);i.setActivityField(k.activityId,x.CORRELATIVE_ID,v),u.push(k.activityId)}for(let k of f){let v=i.getActivity(k);if(!v)continue;let P=i.getChildren(k),q=vr({parent:v,remainingChildIds:P.map(String),defaultDurationHours:o.hoursPerDay,promotionSnapshot:i.getPromotionSnapshot(k),computeEndDate:(wt,ht)=>i.calculateEndDate({startDate:wt,durationHours:ht,task:v}),idsRemoved:new Set(L.filter(wt=>wt.oldParentKey===k).map(wt=>wt.activityId))});if(!q){Ni(k,i);continue}for(let[wt,ht]of Object.entries(q.fields))yt(i,k,wt,ht);let $=_e(k,i),ot=$?i.getActivity($)?.customId:null,it=typeof ot=="string"&&ot?ot:null,Dt=r.customIdTracker.generateCustomIdForRestoredChild(it);i.setActivityField(k,x.CUSTOM_ID,Dt)}let E=new Set;for(let k of f)E.add(String(k));for(let k of L)k.grandparentKey!=="0"&&E.add(String(k.grandparentKey));for(let k of E)Ut(k,i);let g=St(i);for(let k of g){if(l.add(k.activityId),S.has(k.activityId))continue;let v=i.getActivity(k.activityId);if(!v)continue;let P=et(v);k.before!==void 0&&(P.correlativeId=k.before),S.set(k.activityId,P)}let{scheduledIds:b}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:u.length>0?Ot.ROOTS:null,recomputeParentsFrom:u,now:r.now,options:t}),B={name:Kt.ACTIVITY_OUTDENT,properties:{activity_ids:u.map(String),failed:d.map(k=>({activity_id:String(k.activityId),reason:k.reason}))}};return e.eventSource!==void 0&&(B.properties.event_source=e.eventSource),{ok:!0,activityVerdicts:e.activityIds.map(k=>{let v=d.find(P=>String(P.activityId)===String(k));return v?{activityId:String(k),ok:!1,reason:v.reason}:{activityId:String(k),ok:!0}}),changes:await z(i,{source:e,beforeSnap:S,touchedIds:l,scheduledIds:b,trackingEvents:[B],hoursPerDay:o.hoursPerDay})}}async function Zl(e,t,r){let{adapter:i,ctx:n,scheduler:o,sector:a}=r;if(e.newValue!==0&&e.newValue!==100)return{ok:!1,reason:C.INVALID_PROGRESS_VALUE};let s=n.activityReader.getActivity(e.activityId);if(!s)return{ok:!1,reason:C.ACTIVITY_NOT_FOUND};let c=Se(_.PROGRESS);if(!c)throw new Error("[ScheduleCore] progressPipeline not registered \u2014 cannot dispatch activity-set-progress");let l=c.canEdit(s,n.hierarchy);if(!l.allowed&&!(e.origin===Wi.ACTION_BUTTON&&(l.reason===Wr.HAS_LOOKAHEAD_TASKS||l.reason===Wr.SUMMARY)))return{ok:!1,reason:l.reason,...l.alertKey?{alertKey:l.alertKey}:{}};let d=c.transform(s,e.newValue,n,e.newValue),u=Te(e.activityId,d),f=await rt(i,u);Ee(i,e.activityId,d),zs(e.activityId,e.newValue,i),Ie(e.activityId,d.postProcessors??[],i);let{scheduledIds:p}=await Z({adapter:i,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:d.needsAutoSchedule?e.activityId:null,recomputeParentsFrom:[],collectDirty:I=>$i(e.activityId,u,I),now:r.now,options:t}),y=(d.trackingEvents??[]).map(I=>({name:I.name,properties:I.properties??{}}));return{ok:!0,changes:await z(i,{source:e,beforeSnap:f,touchedIds:u,scheduledIds:p,trackingEvents:y,hoursPerDay:a.hoursPerDay})}}function HI(e){return e===_.START_DATE||e===_.END_DATE}async function Ql(e,t,r){if(e.edits.some(y=>!HI(y.column)))return{ok:!1,reason:C.INVALID_VALUE};let{adapter:i,scheduler:n,sector:o}=r,a=[],s=new Map,c=new Set,l=[],d=[],u=[],f=!1;for(let y of e.edits){let I=WI(y,r);if(a.push(I.verdict),!I.verdict.ok||!I.changes)continue;let T=Te(y.activityId,I.changes);VI(s,T,r);for(let g of T)c.add(g);let L=yr(i,y.activityId),S=Yi(i,String(y.activityId));Ee(i,y.activityId,I.changes),Ie(y.activityId,I.changes.postProcessors??[],i,S),d.push(...hr(L,i,y.activityId)),f||=!!I.changes.needsAutoSchedule;for(let g of I.changes.trackingEvents??[])l.push({name:g.name,properties:g.properties??{}});let E=cr(y.activityId,I.changes.constraintWarning);E&&u.push(E)}let{scheduledIds:p}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:f?Ot.ROOTS:null,recomputeParentsFrom:c,now:r.now,options:t});return{ok:!0,verdicts:a,changes:await z(i,{source:e,beforeSnap:s,touchedIds:c,scheduledIds:p,sirDetection:Ft.BEFORE_DIFF,links:d,trackingEvents:l,warnings:u,hoursPerDay:o.hoursPerDay})}}function WI(e,t){let{ctx:r}=t,i=e.activityId,n=Se(e.column);if(!n)throw new Error(`[ScheduleCore] no pipeline registered for column "${e.column}"`);let o=r.activityReader.getActivity(e.activityId);if(!o)throw new Error(`[ScheduleCore] activity "${e.activityId}" not found`);let a=n.canEdit(o,r.hierarchy);if(!a.allowed)return{verdict:{activityId:i,ok:!1,reason:a.reason??C.CANNOT_EDIT,...a.alertKey?{alertKey:a.alertKey}:{}},changes:null};let s=n.parseInput(e.newValue,o,r);if(!s.ok)return{verdict:{activityId:i,ok:!1,reason:s.reason??C.PARSE_ERROR},changes:null};let c=Reflect.get(o,n.targetField),l=n.validate(o,c,s.value,r);if(!l.valid)return{verdict:{activityId:i,ok:!1,reason:l.reason??C.INVALID,...l.notification?.messageKey?{alertKey:l.notification.messageKey}:{}},changes:null};let d=n.transform(o,s.value,r,s.raw);return{verdict:{activityId:i,ok:!0},changes:d}}function VI(e,t,r){let i=new Set;for(let n of t)e.has(n)||i.add(n);if(i.size!==0)for(let n of i){let o=r.adapter.getActivity(n);o&&e.set(n,et(o))}}var la=_.CUSTOM_ID;async function td(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;e.edits.some(E=>E.column===_.DURATION)&&n.invalidateExpandedLinksCache();let s=[],c=new Map,l=new Map,d=new Set,u=new Set,f=[],p=[],y=[],I=!1;for(let E of e.edits){let g=KI(E,r,e.eventSource);if(s.push(g.verdict),!g.verdict.ok||!g.changes)continue;let b=cr(E.activityId,g.changes.constraintWarning);b&&y.push(b);let B=Te(E.activityId,g.changes);$I(c,B,r);for(let $ of B)u.add($);GI(l,E,c),rn(E.column)&&d.add(String(E.activityId));let k=yr(i,E.activityId),v=Yi(i,String(E.activityId)),P=jI(E,r),q=g.changes;Ee(i,E.activityId,q),Ie(E.activityId,g.changes.postProcessors??[],i,v),YI(E,P,r),p.push(...hr(k,i,E.activityId)),I||=!!g.changes.needsAutoSchedule;for(let $ of g.changes.trackingEvents??[])f.push({name:$.name,properties:$.properties??{}})}let T={action:e,autoscheduleFrom:I?Ot.ROOTS:null,recomputeParentsFrom:u,now:r.now,options:t},L=l.size>0,{scheduledIds:S}=await(L?on({adapter:i,scheduler:n,sector:o,defaultBaseCalendarId:r.defaultBaseCalendarId},{postMutationArgs:T,revertTargets:[...l].filter(([E])=>!d.has(E)).map(([E,g])=>({activityId:E,priorConstraintDate:g})),revert:(E,g)=>nn(E,g,i,r.ctx.calendars)}):Z({adapter:i,scheduler:n,sector:o,defaultBaseCalendarId:r.defaultBaseCalendarId},T));return{ok:!0,verdicts:s,changes:await z(i,{source:e,beforeSnap:c,touchedIds:u,scheduledIds:S,sirDetection:Ft.BEFORE_DIFF,links:p,trackingEvents:f,warnings:y,hoursPerDay:o.hoursPerDay})}}function KI(e,t,r){let{ctx:i}=t,n=e.activityId,o=Se(e.column);if(!o)return{verdict:{activityId:n,ok:!1,reason:C.NO_PIPELINE_FOR_COLUMN},changes:null};let a=i.activityReader.getActivity(e.activityId);if(!a)return{verdict:{activityId:n,ok:!1,reason:C.ACTIVITY_NOT_FOUND},changes:null};let s=o.canEdit(a,i.hierarchy,{eventSource:r,newValue:e.newValue});if(!s.allowed)return{verdict:{activityId:n,ok:!1,reason:s.reason??C.CANNOT_EDIT,...s.alertKey?{alertKey:s.alertKey}:{}},changes:null};let c=o.parseInput(e.newValue,a,i);if(!c.ok)return{verdict:{activityId:n,ok:!1,reason:c.reason??C.PARSE_ERROR},changes:null};let l=Reflect.get(a,o.targetField),d=o.validate(a,l,c.value,i);if(!d.valid)return{verdict:{activityId:n,ok:!1,reason:d.reason??C.INVALID,...d.notification?.messageKey?{alertKey:d.notification.messageKey}:{}},changes:null};if(e.column===la&&c.value!==null){let f=t.adapter.getActivity(e.activityId),p=f?f.customId:null,y=typeof p=="string"?p:null;if(t.customIdTracker.isCustomIdInUse(String(c.value),y))return{verdict:{activityId:n,ok:!1,reason:C.CUSTOM_ID_DUPLICATE},changes:null}}let u=o.transform(a,c.value,i,c.raw);return{verdict:{activityId:n,ok:!0},changes:u}}function jI(e,t){if(e.column!==la)return null;let r=t.adapter.getActivity(e.activityId),i=r?r.customId:null;return typeof i=="string"?i:null}function YI(e,t,r){if(e.column!==la)return;let i=r.adapter.getActivity(e.activityId),n=i?i.customId:null,o=typeof n=="string"?n:null;t!==o&&r.customIdTracker.trackCustomIdChange(t,o)}function GI(e,t,r){if(!en(t.column))return;let i=String(t.activityId);if(e.has(i))return;let n=r.get(i);n&&e.set(i,n.constraintDate??null)}function $I(e,t,r){let i=new Set;for(let n of t)e.has(n)||i.add(n);if(i.size!==0)for(let n of i){let o=r.adapter.getActivity(n);o&&e.set(n,et(o))}}var Pt={INVALID_BASELINE_POINT:"invalid_baseline_point",UNKNOWN_CONSTRAINT:"unknown_constraint",ORPHAN_ACTIVITY:"orphan_activity",INVALID_LINK:"invalid_link",DUPLICATE_LINK:"duplicate_link"},zI=[Pt.INVALID_BASELINE_POINT,Pt.UNKNOWN_CONSTRAINT,Pt.ORPHAN_ACTIVITY,Pt.INVALID_LINK,Pt.DUPLICATE_LINK],Cr=()=>{};function ed(){let e=new Map,t=new Map;return{record:(n,o)=>{e.set(n,(e.get(n)??0)+1);let a=t.get(n)??[];a.length<10&&!a.includes(o)&&(a.push(o),t.set(n,a))},snapshot:()=>Object.freeze(zI.flatMap(n=>{let o=e.get(n);return o===void 0?[]:[Object.freeze({code:n,count:o,sampleIds:Object.freeze([...t.get(n)??[]])})]}))}}function rd(e){return typeof e=="string"&&e.length>0?se(e):e instanceof Date?e:null}function da(e){let t=typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):Number.NaN;return!Number.isFinite(t)||t<0?null:t}function An(e,t,r){let i=da(e.duration),n=da(e.cost),o=da(e.hh_work);return i===null||n===null||o===null?(r&&r.record(Pt.INVALID_BASELINE_POINT,r.sampleId),t.warn(`[baseline] dropping point with non-finite/negative magnitude \u2014 duration=${JSON.stringify(e.duration)}, cost=${JSON.stringify(e.cost)}, hh_work=${JSON.stringify(e.hh_work)}`),null):{startDate:rd(e.start_date),endDate:rd(e.end_date),durationDays:i,cost:n,workHours:o,versionId:typeof e.sectorbaselineversionId=="number"?e.sectorbaselineversionId:null,isActiveVersion:!!e.sectorbaselineversion?.active,isVisibleVersion:!!e.sectorbaselineversion?.visible,baseCalendarId:e.baseCalendarId!=null?String(e.baseCalendarId):null,hoursPerDay:typeof e.hoursPerDay=="number"?e.hoursPerDay:null,hoursPerWeek:typeof e.hoursPerWeek=="number"?e.hoursPerWeek:null}}function id(e,t,r,i=Cr){let n=new Map;e.forEachActivity((s,c)=>{let l=s.proplannerId;typeof l=="number"&&n.set(l,c)});let o=new Map;for(let s of t){let c=s.activityId;if(typeof c!="number"){i(Pt.INVALID_BASELINE_POINT,String(c??"unknown"));continue}let l=n.get(c);if(l===void 0){i(Pt.INVALID_BASELINE_POINT,String(c));continue}let d=o.get(l);d?d.push(s):o.set(l,[s])}let a=[];for(let[s,c]of o)e.setActivityField(s,"baselinePoints",c.map(l=>An(l,r,{record:i,sampleId:s})).filter(l=>l!==null)),a.push(s);return e.forEachActivity((s,c)=>{if(o.has(c))return;let l=s.baselinePoints;Array.isArray(l)&&l.length>0&&(e.setActivityField(c,"baselinePoints",[]),a.push(c))}),a}function qI(e){let t=kt(e);return t?{startDate:t.startDate,endDate:t.endDate,durationDays:t.durationDays,cost:t.cost,workHours:t.workHours}:null}function nd(e){let t=[];return e.forEachActivity((r,i)=>{let n=qI(r);if(!n){r.baselineSnapshot!==null&&(e.setActivityField(i,"baselineSnapshot",null),t.push(i));return}e.setActivityField(i,"baselineSnapshot",n),t.push(i)}),t}function vn(e,t,r,i,n=null,o=Cr){let a=new Set;for(let s of id(e,t,i,o))a.add(s);if(r)for(let s of ur(e,r,n))a.add(s);for(let s of nd(e))a.add(s);for(let s of fr(e))a.add(s);return[...a]}function od(e,t,r){if(!e||e==="0")return;let i=r.getChildren(e);if(i.length===0)return;let n=new Map,o=0;for(let s of i){let c=JI(String(s),t,r);n.set(String(s),c),o+=c}let a=o?100/o:0;for(let s of i){let c=r.getActivity(s);if(!c)continue;let l=c.baselinePoints;if(kt(c)){let u=n.get(String(s))??0;r.setActivityField(s,_.PONDERATOR,a*u)}else(!Array.isArray(l)||l.length===0)&&r.setActivityField(s,_.PONDERATOR,0)}}function JI(e,t,r){let i=r.getActivity(e);if(!i)return 0;let n=kt(i);if(!n)return 0;if(t===gt.COST)return Cn(n.cost);if(t===gt.WORK_HOURS)return Cn(n.workHours);let{type:o}=i;return o===D.PROJECT?ad(e,r):o===D.MILESTONE?0:Cn(n.durationDays)}function ad(e,t){let r=0;for(let i of t.getChildren(e)){let n=t.getActivity(i);if(!n)continue;let o=kt(n);if(!o)continue;let{type:a}=n;a===D.PROJECT?r+=ad(String(i),t):a!==D.MILESTONE&&(r+=Cn(o.durationDays))}return r}function Cn(e){let t=typeof e=="string"?parseFloat(e):e;return typeof t=="number"&&Number.isFinite(t)?t:0}function sd(e,t){t.forEachActivity((r,i)=>{t.setActivityField(i,_.PONDERATOR,0)}),t.forEachActivity((r,i)=>{t.getChildren(i).length>0&&od(String(i),e,t)})}function Sn(e,t){sd(t,e.adapter),Ur(e.adapter),e.now&&(ur(e.adapter,e.now,e.defaultBaseCalendarId??null),Me(e.adapter,e.now)),fr(e.adapter),e.now&&ce(e.adapter,e.sector.statusCriteria)}function cd(e){return JSON.stringify(e.adapter.getAllIds().map(t=>{let r=e.adapter.getActivity(t)?.baselinePoints.find(i=>i.isActiveVersion);return r?[String(t),r.versionId,r.startDate?.getTime()??null,r.endDate?.getTime()??null,r.durationDays,r.cost,r.workHours,r.baseCalendarId,r.hoursPerDay,r.hoursPerWeek]:[String(t),null]}))}async function ld(e,t){let r=await rt(t.adapter,new Set(t.adapter.getAllIds())),i=cd(t),n=vn(t.adapter,e.points,t.now,t.reporter,t.defaultBaseCalendarId??null);return cd(t)!==i&&Sn(t,t.sector.activityCreter??gt.DURATION),{ok:!0,changes:await z(t.adapter,{source:e,beforeSnap:r,touchedIds:n,scheduledIds:[],hoursPerDay:t.sector.hoursPerDay})}}function XI(e){return Object.values(gt).includes(e)}async function dd(e,t){if(!XI(e.criterion))return{ok:!1,reason:C.INVALID_VALUE};let r=new Set(t.adapter.getAllIds()),i=await rt(t.adapter,r);return Sn(t,e.criterion),t.sector.activityCreter=e.criterion,{ok:!0,changes:await z(t.adapter,{source:e,beforeSnap:i,touchedIds:r,scheduledIds:[],hoursPerDay:t.sector.hoursPerDay})}}async function ud(e,t){let r=zi(e.criteria),i=new Set(t.adapter.getAllIds()),n=await rt(t.adapter,i),o=ce(t.adapter,r);return t.sector.statusCriteria=r,{ok:!0,changes:await z(t.adapter,{source:e,beforeSnap:n,touchedIds:o,scheduledIds:[],hoursPerDay:t.sector.hoursPerDay})}}async function pd(e,t,r){let i=new Map,n=new Set;for(let a of r.adapter.getAllActivities()){if(!ZI(a,r))continue;let s=r.ctx.calendars.getCalendar(a.calendarId);if(!s)continue;let c=s.getClosestWorkTime({date:a.startDate,direction:K.FUTURE,unit:mt.HOUR}),l=s.calculateEndDate(c,a.durationHours);if(fd(c,a.startDate)&&fd(l,a.endDate))continue;let d=String(a.id);i.set(d,et(a)),n.add(d),r.adapter.setActivityFields(d,{startDate:c,endDate:l})}let{scheduledIds:o}=await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:Ot.ROOTS,recomputeParentsFrom:n,now:r.now,options:t});return{ok:!0,changes:await z(r.adapter,{source:e,beforeSnap:i,touchedIds:n,scheduledIds:o,hoursPerDay:r.sector.hoursPerDay})}}function ZI(e,t){return e.progress===0&&!$t(e.type,t.adapter.hasChildren(e.id))}function fd(e,t){return e.getTime()===t.getTime()}var yd=["name","description","type","startDate","durationHours","constraintType","constraintDate","calendarId","cost","hasCustomPonderator","subcontractId","responsableIds","tagIds"];function QI(e){let t={};for(let r of yd)Object.assign(t,{[r]:F(e[r])});return t}function tg(e,t){let r=[],i=n=>{t.has(String(n))&&r.push(n);for(let o of e.getChildren(n))i(o)};for(let n of e.getRootIds())i(n);return r}function hd(e,t){let r=new Set(t.adapter.checkedIds().map(String));if(r.size===0)return{ok:!1,reason:C.NO_ACTIVITY_SELECTION};let i=tg(t.adapter,r);t.clipboard.value={activities:i.map(o=>{let a=t.adapter.getActivity(o);if(a===null)throw new Error(`Selected activity ${o} is missing`);return{originalId:o,originalParentId:a.parentId??"0",overrides:QI(a)}}),links:t.adapter.getAllLinks().filter(o=>r.has(String(o.source))&&r.has(String(o.target))).map(o=>F(o))};let n=ci({kind:m.SELECTION_REPLACE,activityIds:[]},{adapter:t.adapter});return n.ok?{...n,changes:{...n.changes,source:e}}:n}function md(e,t){return t.value=null,{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[]}}}function eg(e,t){let r=t.getActivity(e);return r?r.parentId==null?t.getRootIds().length===1?{ok:!0,parentId:r.id}:{ok:!0,parentId:"0",afterSiblingId:e}:{ok:!0,parentId:String(r.parentId),afterSiblingId:e}:{ok:!1,reason:C.ANCHOR_SIBLING_NOT_FOUND}}var Id=()=>({ok:!1,reason:C.ACTIVITY_PASTE_INVARIANT_FAILED});async function gd(e,t,r){let i=r.activityClipboard.value;if(i===null)return{ok:!1,reason:C.CLIPBOARD_EMPTY};let n=eg(e.destination.afterSiblingId,r.adapter);if(!n.ok)return n;let o=await rt(r.adapter,new Set),a=new Set,s=new Map,c=[],l;for(let I of i.activities){let T=s.get(I.originalParentId),L=T===void 0?l??n.afterSiblingId:void 0,S=await Xr({kind:m.ACTIVITY_CREATE,parentId:T??n.parentId,...L===void 0?{}:{afterSiblingId:L},overrides:F(I.overrides),eventSource:e.eventSource},r,{skipCorrelativeRecompute:!0,skipBeforeSnap:!0,customIdReferenceId:e.destination.afterSiblingId});if(!S.ok)return S;s.set(I.originalId,S.newId),c.push(S.newId),T===void 0&&(l=S.newId)}let d=St(r.adapter),u=new Set(c.map(String));lr(r.adapter,d,u,o,a);for(let I of c)a.add(String(I));let f=[];for(let I of i.links){let T=s.get(I.source),L=s.get(I.target);if(T===void 0||L===void 0)return Id();let S={kind:dt.CREATE,source:T,target:L,type:I.type,lag:I.lag},E=ye(S,{port:r.adapter,newLinkId:r.linkIdGen.next});if(!E.applied)return Id();f.push({op:S,finalLinkId:E.linkId,rejected:null})}let{scheduledIds:p}=await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:c[0]??null,recomputeParentsFrom:c,now:r.now,options:t}),y=pr(f,new Map,r.adapter);return{ok:!0,changes:await z(r.adapter,{source:e,beforeSnap:o,touchedIds:a,scheduledIds:p,links:y,hoursPerDay:r.sector.hoursPerDay})}}async function Ad(e,t,r){return e.kind===m.ACTIVITY_COPY?hd(e,{adapter:r.adapter,clipboard:r.activityClipboard}):e.kind===m.CALENDAR_RECONCILE?pd(e,t,r):e.kind===m.ACTIVITY_CLIPBOARD_CLEAR?md(e,r.activityClipboard):e.kind===m.ACTIVITY_PASTE_COPIED?gd(e,t,r):e.kind===ue?wl(e,t,r):e.kind===m.PERSISTENCE_ACKNOWLEDGE?Vl(e,r):e.kind===m.BASELINE_APPLY?ld(e,r):e.kind===m.PONDERATOR_CRITERION_SET?dd(e,r):e.kind===m.STATUS_CRITERIA_SET?ud(e,r):e.kind===m.LINK_CREATE||e.kind===m.LINK_UPDATE||e.kind===m.LINK_DELETE?pl(e,t,r):e.kind===m.LINKS_BATCH?yl(e,t,r):e.kind===m.ACTIVITY_CREATE?Ll(e,t,r):e.kind===m.ACTIVITY_DELETE?Nl(e,t,r):e.kind===m.ACTIVITY_MOVE?ql(e,t,r):e.kind===m.ACTIVITY_INDENT?Jl(e,t,r):e.kind===m.ACTIVITY_OUTDENT?Xl(e,t,r):e.kind===m.ACTIVITY_SET_PROGRESS?Zl(e,t,r):e.kind===m.DATES_BATCH?Ql(e,t,r):e.kind===m.BULK_EDIT?td(e,t,r):e.kind===m.SELECTION_TOGGLE?rs(e,ua(r)):e.kind===m.SELECTION_REPLACE?ci(e,ua(r)):e.kind===m.VISIBILITY_SET?is(e,ua(r)):e.kind===m.FILTER_SET?fs(e,{adapter:r.adapter,hoursPerDay:r.sector.hoursPerDay}):e.kind===m.SORT_SET?Is(e,{adapter:r.adapter}):e.kind===m.SIR_SYNC?Ml(e,r):e.kind===m.ACTIVITY_LOOKAHEAD_SYNC?Kl(e,t,r):e.kind===m.ACTIVITY_LOOKAHEAD_CONVERT?Gl(e,t,r):e.kind===m.INLINE_EDIT&&(e.column===_.CUSTOM_PREDECESSORS||e.column===_.CUSTOM_SUCESSORS)?hl(e,t,r):e.kind!==m.INLINE_EDIT?gs(e,`[ScheduleCore] dispatch kind "${e.kind}" not supported yet`):fl(e,t,r)}function ua(e){return{adapter:e.adapter}}var rg=new Set(["startDate","endDate","constraintDate"]);function vd(e,t){return rg.has(e)&&typeof t=="string"?new Date(t):t}function Cd(e,t={}){let r=t.defaultUnit??mt.HOUR;return{getCalendar(i){let n=e.getCalendar(String(i));return n?ig(n,r):null}}}function ig(e,t){return{getClosestWorkTime(r){return e.getClosestWorkTime({date:r.date,dir:r.direction,unit:r.unit})},calculateEndDate(r,i){return e.calculateEndDate({start_date:r,duration:i,unit:t})},calculateDuration(r,i){return e.calculateDuration({start_date:r,end_date:i,unit:t})},isWorkTime(r,i){return e.isWorkTime({date:r,unit:i})},getWorkHours(r){return e.getWorkHours(r)}}}function ng(e){return Array.isArray?Array.isArray(e):e&&e.length!==void 0&&e.pop&&e.push}function Ke(e){return e&&typeof e=="object"?!!(e.getFullYear&&e.getMonth&&e.getDate):!1}function je(e){return Ke(e)&&!isNaN(e.getTime())}var og={}.constructor.toString();function ag(e){var t=e.constructor.toString();return t!==og}function sg(e){return e.$$typeof&&e.$$typeof.toString().includes("react.")}function Jt(e){var t,r;if(e&&typeof e=="object")switch(!0){case Ke(e):r=new Date(e);break;case ng(e):for(r=new Array(e.length),t=0;t<e.length;t++)r[t]=Jt(e[t]);break;default:if(ag(e))r=Object.create(e);else{if(sg(e))return r=e,r;r={}}for(t in e)Object.prototype.hasOwnProperty.apply(e,[t])&&(r[t]=Jt(e[t]));break}return r||e}function Sr(e,t,r){for(var i in t)(e[i]===void 0||r)&&(e[i]=t[i]);return e}function Sd(e){return typeof e<"u"}var Tn;function fa(){return Tn||(Tn=new Date().valueOf()),Tn++,Tn}function Bt(e,t){return e.bind?e.bind(t):function(){return e.apply(t,arguments)}}var lg=(e,t,r)=>{e=e.replace(/%[a-zA-Z]/g,n=>{switch(n){case"%d":return`"+to_fixed(date.get${t?"UTC":""}Date())+"`;case"%m":return`"+to_fixed((date.get${t?"UTC":""}Month()+1))+"`;case"%j":return`"+date.get${t?"UTC":""}Date()+"`;case"%n":return`"+(date.get${t?"UTC":""}Month()+1)+"`;case"%y":return`"+to_fixed(date.get${t?"UTC":""}FullYear()%100)+"`;case"%Y":return`"+date.get${t?"UTC":""}FullYear()+"`;case"%D":return`"+locale.date.day_short[date.get${t?"UTC":""}Day()]+"`;case"%l":return`"+locale.date.day_full[date.get${t?"UTC":""}Day()]+"`;case"%M":return`"+locale.date.month_short[date.get${t?"UTC":""}Month()]+"`;case"%F":return`"+locale.date.month_full[date.get${t?"UTC":""}Month()]+"`;case"%h":return`"+to_fixed((date.get${t?"UTC":""}Hours()+11)%12+1)+"`;case"%g":return`"+((date.get${t?"UTC":""}Hours()+11)%12+1)+"`;case"%G":return`"+date.get${t?"UTC":""}Hours()+"`;case"%H":return`"+to_fixed(date.get${t?"UTC":""}Hours())+"`;case"%i":return`"+to_fixed(date.get${t?"UTC":""}Minutes())+"`;case"%a":return`"+(date.get${t?"UTC":""}Hours()>11?"pm":"am")+"`;case"%A":return`"+(date.get${t?"UTC":""}Hours()>11?"PM":"AM")+"`;case"%s":return`"+to_fixed(date.get${t?"UTC":""}Seconds())+"`;case"%W":return'"+to_fixed(getISOWeek(date))+"';case"%w":return'"+to_fixed(getWeek(date))+"';default:return n}});let i=new Function("date","to_fixed","locale","getISOWeek","getWeek",`return "${e}";`);return n=>i(n,r.date.to_fixed,r.locale,r.date.getISOWeek,r.date.getWeek)},dg=(e,t,r)=>{let i="var temp=date.match(/[a-zA-Z]+|[0-9]+/g);",n=e.match(/%[a-zA-Z]/g);for(let s=0;s<n.length;s++)switch(n[s]){case"%j":case"%d":i+=`set[2]=temp[${s}]||1;`;break;case"%n":case"%m":i+=`set[1]=(temp[${s}]||1)-1;`;break;case"%y":i+=`set[0]=temp[${s}]*1+(temp[${s}]>50?1900:2000);`;break;case"%g":case"%G":case"%h":case"%H":i+=`set[3]=temp[${s}]||0;`;break;case"%i":i+=`set[4]=temp[${s}]||0;`;break;case"%Y":i+=`set[0]=temp[${s}]||0;`;break;case"%a":case"%A":i+=`set[3]=set[3]%12+((temp[${s}]||'').toLowerCase()=='am'?0:12);`;break;case"%s":i+=`set[5]=temp[${s}]||0;`;break;case"%M":i+=`set[1]=locale.date.month_short_hash[temp[${s}]]||0;`;break;case"%F":i+=`set[1]=locale.date.month_full_hash[temp[${s}]]||0;`;break}let o="set[0],set[1],set[2],set[3],set[4],set[5]";t&&(o=` Date.UTC(${o})`);let a=new Function("date","locale",`var set=[0,0,1,0,0,0]; ${i} return new Date(${o});`);return s=>a(s,r.locale)},Td={date_to_str:lg,str_to_date:dg},ug=(e,t,r)=>i=>e.replace(/%[a-zA-Z]/g,n=>{switch(n){case"%d":return t?r.date.to_fixed(i.getUTCDate()):r.date.to_fixed(i.getDate());case"%m":return t?r.date.to_fixed(i.getUTCMonth()+1):r.date.to_fixed(i.getMonth()+1);case"%j":return t?i.getUTCDate():i.getDate();case"%n":return t?i.getUTCMonth()+1:i.getMonth()+1;case"%y":return t?r.date.to_fixed(i.getUTCFullYear()%100):r.date.to_fixed(i.getFullYear()%100);case"%Y":return t?i.getUTCFullYear():i.getFullYear();case"%D":return t?r.locale.date.day_short[i.getUTCDay()]:r.locale.date.day_short[i.getDay()];case"%l":return t?r.locale.date.day_full[i.getUTCDay()]:r.locale.date.day_full[i.getDay()];case"%M":return t?r.locale.date.month_short[i.getUTCMonth()]:r.locale.date.month_short[i.getMonth()];case"%F":return t?r.locale.date.month_full[i.getUTCMonth()]:r.locale.date.month_full[i.getMonth()];case"%h":return t?r.date.to_fixed((i.getUTCHours()+11)%12+1):r.date.to_fixed((i.getHours()+11)%12+1);case"%g":return t?(i.getUTCHours()+11)%12+1:(i.getHours()+11)%12+1;case"%G":return t?i.getUTCHours():i.getHours();case"%H":return t?r.date.to_fixed(i.getUTCHours()):r.date.to_fixed(i.getHours());case"%i":return t?r.date.to_fixed(i.getUTCMinutes()):r.date.to_fixed(i.getMinutes());case"%a":return t?i.getUTCHours()>11?"pm":"am":i.getHours()>11?"pm":"am";case"%A":return t?i.getUTCHours()>11?"PM":"AM":i.getHours()>11?"PM":"AM";case"%s":return t?r.date.to_fixed(i.getUTCSeconds()):r.date.to_fixed(i.getSeconds());case"%W":return t?r.date.to_fixed(r.date.getUTCISOWeek(i)):r.date.to_fixed(r.date.getISOWeek(i));case"%w":return r.date.to_fixed(r.date.getWeek(i));default:return n}}),fg=(e,t,r)=>i=>{let n=[0,0,1,0,0,0],o=i.match(/[a-zA-Z]+|[0-9]+/g),a=e.match(/%[a-zA-Z]/g);for(let s=0;s<a.length;s++)switch(a[s]){case"%j":case"%d":n[2]=o[s]||1;break;case"%n":case"%m":n[1]=(o[s]||1)-1;break;case"%y":n[0]=o[s]*1+(o[s]>50?1900:2e3);break;case"%g":case"%G":case"%h":case"%H":n[3]=o[s]||0;break;case"%i":n[4]=o[s]||0;break;case"%Y":n[0]=o[s]||0;break;case"%a":case"%A":n[3]=n[3]%12+((o[s]||"").toLowerCase()==="am"?0:12);break;case"%s":n[5]=o[s]||0;break;case"%M":n[1]=r.locale.date.month_short_hash[o[s]]||0;break;case"%F":n[1]=r.locale.date.month_full_hash[o[s]]||0;break}return t?new Date(Date.UTC(n[0],n[1],n[2],n[3],n[4],n[5])):new Date(n[0],n[1],n[2],n[3],n[4],n[5])},Ed={date_to_str:ug,str_to_date:fg};function Dd(e){var t=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;function r(s){var c=new Date(s);return isNaN(c.getTime())?null:c}var i=null;function n(){try{new Function("canUseCsp = false;")}catch{i=!0}}function o(){var s=!1;return e.config.csp==="auto"?(i===null&&n(),s=i):s=e.config.csp,s}var a={_isoDateDetected:!1,_isoDateOnly:!1,formatISODate:function(s){return s.toISOString()},formatISODateOnly:function(s){return s.getUTCFullYear()+"-"+e.date.to_fixed(s.getUTCMonth()+1)+"-"+e.date.to_fixed(s.getUTCDate())},init:function(){for(var s=e.locale,l=s.date.month_short,d=s.date.month_short_hash={},c=0;c<l.length;c++)d[l[c]]=c;for(var l=s.date.month_full,d=s.date.month_full_hash={},c=0;c<l.length;c++)d[l[c]]=c},date_part:function(s){return s.setUTCHours(0,0,0,0),s},time_part:function(s){return s.valueOf()/1e3%86400},week_start:function(s){var c=s.getUTCDay();return e.config.start_on_monday&&(c===0?c=6:c--),this.date_part(this.add(s,-1*c,"day"))},month_start:function(s){return s.setUTCDate(1),this.date_part(s)},quarter_start:function(s){this.month_start(s);var c=s.getUTCMonth(),l;return c>=9?l=9:c>=6?l=6:c>=3?l=3:l=0,s.setUTCMonth(l),s},year_start:function(s){return s.setUTCMonth(0),this.month_start(s)},day_start:function(s){return this.date_part(s)},hour_start:function(s){return s.getUTCMinutes()&&s.setUTCMinutes(0),this.minute_start(s),s},minute_start:function(s){return s.getUTCSeconds()&&s.setUTCSeconds(0),s.getUTCMilliseconds()&&s.setUTCMilliseconds(0),s},_add_days:function(s,c,l){return s.setUTCDate(s.getUTCDate()+c),s},add:function(s,c,l){var d=new Date(s.valueOf());switch(l){case"day":d=this._add_days(d,c,s);break;case"week":d=this._add_days(d,c*7,s);break;case"month":d.setUTCMonth(d.getUTCMonth()+c);break;case"year":d.setUTCFullYear(d.getUTCFullYear()+c);break;case"hour":d.setTime(d.getTime()+c*60*60*1e3);break;case"minute":d.setTime(d.getTime()+c*60*1e3);break;default:return this["add_"+l](s,c,l)}return d},add_quarter:function(s,c){return this.add(s,c*3,"month")},to_fixed:function(s){return s<10?"0"+s:s},copy:function(s){return new Date(s.valueOf())},date_to_str:function(s,c){var l=Td;return o()&&(l=Ed),l.date_to_str(s,c,e)},str_to_date:function(s,c){var l=Td;return o()&&(l=Ed),l.str_to_date(s,c,e)},getISOWeek:function(s){return e.date._getWeekNumber(s,!0)},_getWeekNumber:function(s,c){if(!s)return!1;var l=s.getUTCDay();c&&l===0&&(l=7);var d=new Date(s.valueOf());d.setUTCDate(s.getUTCDate()+(4-l));var u=d.getUTCFullYear(),f=Math.round((d.getTime()-Date.UTC(u,0,1))/864e5),p=1+Math.floor(f/7);return p},getWeek:function(s){return e.date._getWeekNumber(s,e.config.start_on_monday)},getUTCISOWeek:function(s){return e.date.getISOWeek(s)},parseDate:function(s,c){if(s&&!s.getFullYear){var l=!c||c==="parse_date"||c==="xml_date",d=l&&(e.defined(e.templates.xml_date)||e.templates.parse_date&&!e.templates.parse_date._ganttAuto);if(!d&&typeof s=="string"&&t.test(s)){var u=s.indexOf("T")!==-1,f=r(s);if(f)return a._isoDateDetected?u&&(a._isoDateOnly=!1):(a._isoDateDetected=!0,a._isoDateOnly=!u),f}typeof c!="function"&&(typeof c=="string"?c==="parse_date"||c==="xml_date"?c=e.defined(e.templates.xml_date)?e.templates.xml_date:e.templates.parse_date:c=e.defined(e.templates[c])?e.templates[c]:e.date.str_to_date(c,!0):c=e.defined(e.templates.xml_date)?e.templates.xml_date:e.templates.parse_date),s?s=c(s):s=null}return s}};return a}function pa(e,t,r,i,n){return this.date=e,this.unit=t,this.task=r,this.id=i,this.calendar=n,this}function ya(e,t,r,i,n,o){return this.date=e,this.dir=t,this.unit=r,this.task=i,this.id=n,this.calendar=o,this}function ha(e,t,r,i,n,o,a){return this.start_date=e,this.duration=t,this.unit=r,this.step=i,this.task=n,this.id=o,this.calendar=a,this}function pg(e,t,r,i){return this.start_date=e,this.end_date=t,this.task=r,this.calendar=i,this.unit=null,this.step=null,this}var _d=function(e){return{getWorkHoursArguments:function(){var t=arguments[0];if(Ke(t)?t={date:t}:t=Sr({},t),!je(t.date))throw e.assert(!1,"Invalid date argument for getWorkHours method"),new Error("Invalid date argument for getWorkHours method");return t},setWorkTimeArguments:function(){return arguments[0]},unsetWorkTimeArguments:function(){return arguments[0]},isWorkTimeArguments:function(){var t=arguments[0];if(t instanceof pa)return t;var r;if(t.date?r=new pa(t.date,t.unit,t.task,null,t.calendar):r=new pa(arguments[0],arguments[1],arguments[2],null,arguments[3]),r.unit=r.unit||e.config.duration_unit,!je(r.date))throw e.assert(!1,"Invalid date argument for isWorkTime method"),new Error("Invalid date argument for isWorkTime method");return r},getClosestWorkTimeArguments:function(t){var r=arguments[0];if(r instanceof ya)return r;var i;if(Ke(r)?i=new ya(r):i=new ya(r.date,r.dir,r.unit,r.task,null,r.calendar),r.id&&(i.task=r),i.dir=r.dir||"any",i.unit=r.unit||e.config.duration_unit,!je(i.date))throw e.assert(!1,"Invalid date argument for getClosestWorkTime method"),new Error("Invalid date argument for getClosestWorkTime method");return i},_getStartEndConfig:function(t){var r=pg,i;if(t instanceof r)return t;if(Ke(t)?i=new r(arguments[0],arguments[1],arguments[2],arguments[3]):(i=new r(t.start_date,t.end_date,t.task),t.id!==null&&t.id!==void 0&&(i.task=t)),i.unit=i.unit||e.config.duration_unit,i.step=i.step||e.config.duration_step,i.start_date=i.start_date||i.start||i.date,!je(i.start_date))throw e.assert(!1,"Invalid start_date argument for getDuration method"),new Error("Invalid start_date argument for getDuration method");if(!je(i.end_date))throw e.assert(!1,"Invalid end_date argument for getDuration method"),new Error("Invalid end_date argument for getDuration method");return i},getDurationArguments:function(t,r,i,n){return this._getStartEndConfig.apply(this,arguments)},hasDurationArguments:function(t,r,i,n){return this._getStartEndConfig.apply(this,arguments)},calculateEndDateArguments:function(t,r,i,n){var o=arguments[0];if(o instanceof ha)return o;var a;if(Ke(o)?a=new ha(arguments[0],arguments[1],arguments[2],void 0,arguments[3],void 0,arguments[4]):a=new ha(o.start_date,o.duration,o.unit,o.step,o.task,null,o.calendar),o.id!==null&&o.id!==void 0&&(a.task=o,a.unit=null,a.step=null),a.unit=a.unit||e.config.duration_unit,a.step=a.step||e.config.duration_step,!je(a.start_date))throw e.assert(!1,"Invalid start_date argument for calculateEndDate method"),new Error("Invalid start_date argument for calculateEndDate method");return a}}};function kd(){}kd.prototype={_getIntervals:function(e){for(var t=[],r=0;r<e.length;r+=2)t.push({start:e[r],end:e[r+1]});return t},_toHoursArray:function(e){var t=[];function r(o){var a=String(o);return a.length<2&&(a="0"+a),a}function i(o){var a=Math.floor(o/3600),s=o-a*60*60,c=Math.floor(s/60);return a+":"+r(c)}for(var n=0;n<e.length;n++)t.push(i(e[n].start)+"-"+i(e[n].end));return t},_intersectHourRanges:function(e,t){var n=[],r=e.length>t.length?e:t,i=e===r?t:e;r=r.slice(),i=i.slice();for(var n=[],o=0;o<r.length;o++)for(var a=r[o],s=0;s<i.length;s++){var c=i[s];c.start<a.end&&c.end>a.start&&(n.push({start:Math.max(a.start,c.start),end:Math.min(a.end,c.end)}),a.end>c.end&&(i.splice(s,1),s--,o--))}return n},_mergeAdjacentIntervals:function(e){var t=e.slice();t.sort(function(o,a){return o.start-a.start});for(var r=t[0],i=1;i<t.length;i++){var n=t[i];n.start<=r.end?(n.end>r.end&&(r.end=n.end),t.splice(i,1),i--):r=n}return t},_mergeHoursConfig:function(e,t){return this._mergeAdjacentIntervals(this._intersectHourRanges(e,t))},merge:function(e,t){let r=Jt(e.getConfig()),i=Jt(t.getConfig()),n=r.parsed,o=i.parsed;n.customWeeks=r.customWeeks,o.customWeeks=i.customWeeks;var a={hours:this._toHoursArray(this._mergeHoursConfig(n.hours,o.hours)),dates:{},customWeeks:{}};let s=(l,d)=>{for(let u in l.dates){let f=l.dates[u];+u>1e3&&(a.dates[u]=!1);for(let p in d.dates){let y=d.dates[p];if(p==u&&(a.dates[u]=!!(f&&y)),Array.isArray(f)){let I=Array.isArray(y)?y:d.hours;a.dates[u]=this._toHoursArray(this._mergeHoursConfig(f,I))}}}};if(s(n,o),s(o,n),n.customWeeks)for(var c in n.customWeeks)a.customWeeks[c]=n.customWeeks[c];if(o.customWeeks)for(var c in o.customWeeks)a.customWeeks[c]?a.customWeeks[c+"_second"]=o.customWeeks[c]:a.customWeeks[c]=o.customWeeks[c];return a}};var ma=class{constructor(){this.clear()}getItem(t,r,i){if(this._cache.has(t)){let o=this._cache.get(t)[i.getUTCFullYear()];if(o&&o.has(r))return o.get(r)}return-1}setItem(t,r,i,n){if(!t||!r)return;let o=this._cache,a=n.getUTCFullYear(),s;o.has(t)?s=o.get(t):(s=[],o.set(t,s));let c=s[a];c||(c=s[a]=new Map),c.set(r,i)}clear(){this._cache=new Map}},Ia=class{constructor(){this.clear()}getItem(t,r,i){let n=this._cache;if(n&&n[t]){let o=n[t];if(o===void 0)return-1;let a=o[i.getUTCFullYear()];if(a&&a[r]!==void 0)return a[r]}return-1}setItem(t,r,i,n){if(!t||!r)return;let o=this._cache;if(!o)return;o[t]||(o[t]=[]);let a=o[t],s=n.getUTCFullYear(),c=a[s];c||(c=a[s]={}),c[r]=i}clear(){this._cache={}}},ga=class{constructor(t){this.getMinutesPerWeek=r=>{let i=r.valueOf();if(this._weekCache.has(i))return this._weekCache.get(i);let n=this._calendar,o=this._calendar.$gantt,a=0,s=o.date.week_start(new Date(r));for(let c=0;c<7;c++)a+=n.getHoursPerDay(s)*60,s=o.date.add(s,1,"day");return this._weekCache.set(i,a),a},this.getMinutesPerMonth=r=>{let i=r.valueOf();if(this._monthCache.has(i))return this._monthCache.get(i);let n=this._calendar,o=this._calendar.$gantt,a=0,s=o.date.week_start(new Date(r)),c=o.date.add(s,1,"month").valueOf();for(;s.valueOf()<c;)a+=n.getHoursPerDay(s)*60,s=o.date.add(s,1,"day");return this._monthCache.set(i,a),a},this.clear=()=>{this._weekCache=new Map,this._monthCache=new Map},this.clear(),this._calendar=t}};function yg(){return typeof Map<"u"?new ma:new Ia}var Aa=class{constructor(){this.clear()}_getCacheObject(t,r,i){let n=this._cache;n[r]||(n[r]=[]);let o=n[r];o||(o=n[r]={});let a=o[i];a||(a=o[i]={});let s=t.getUTCFullYear(),c=a[s];return c||(c=a[s]={durations:{},endDates:{}}),c}_endDateCacheKey(t,r){return String(t)+"-"+String(r)}_durationCacheKey(t,r){return String(t)+"-"+String(r)}getEndDate(t,r,i,n,o){let a=this._getCacheObject(t,i,n),s=t.valueOf(),c=this._endDateCacheKey(s,r),l;if(a.endDates[c]===void 0){let d=o(),u=d.valueOf();a.endDates[c]=u,a.durations[this._durationCacheKey(s,u)]=r,l=d}else l=new Date(a.endDates[c]);return l}getDuration(t,r,i,n,o){let a=this._getCacheObject(t,i,n),s=t.valueOf(),c=r.valueOf(),l=this._durationCacheKey(s,c),d;if(a.durations[l]===void 0){let u=o();a.durations[l]=u.valueOf(),d=u}else d=a.durations[l];return d}clear(){this._cache={}}};function va(e,t){this.argumentsHelper=t,this.$gantt=e,this._workingUnitsCache=yg(),this._largeUnitsCache=new ga(this),this._dateDurationCache=new Aa,this._worktime=null,this._cached_timestamps={},this._cached_timestamps_count=0}va.prototype={units:["year","month","week","day","hour","minute"],_clearCaches:function(){this._workingUnitsCache.clear(),this._largeUnitsCache.clear(),this._dateDurationCache.clear()},_getUnitOrder:function(e){for(var t=0,r=this.units.length;t<r;t++)if(this.units[t]==e)return t},_resetTimestampCache:function(){this._cached_timestamps={},this._cached_timestamps_count=0},_timestamp:function(e){this._cached_timestamps_count>1e6&&this._resetTimestampCache();var t=null;if(e.day||e.day===0)t=e.day;else if(e.date){var r=String(e.date.valueOf());this._cached_timestamps[r]?t=this._cached_timestamps[r]:(t=Date.UTC(e.date.getUTCFullYear(),e.date.getUTCMonth(),e.date.getUTCDate()),this._cached_timestamps[r]=t,this._cached_timestamps_count++)}return t},_checkIfWorkingUnit:function(e,t){if(!this["_is_work_"+t]){let r=this.$gantt.date[`${t}_start`](new Date(e)),i=this.$gantt.date.add(r,1,t);return this.hasDuration(r,i)}return this["_is_work_"+t](e)},_is_work_day:function(e){var t=this._getWorkHours(e);return Array.isArray(t)?t.length>0:!1},_is_work_hour:function(e){for(var t=this._getWorkHours(e),r=e.getUTCHours(),i=0;i<t.length;i++)if(r>=t[i].startHour&&r<t[i].endHour)return!0;return!1},_getTimeOfDayStamp:function(e,t){var r=e.getUTCHours();return!e.getUTCHours()&&!e.getUTCMinutes()&&t&&(r=24),r*60*60+e.getUTCMinutes()*60},_is_work_minute:function(e){for(var t=this._getWorkHours(e),r=this._getTimeOfDayStamp(e),i=0;i<t.length;i++)if(r>=t[i].start&&r<t[i].end)return!0;return!1},_nextDate:function(e,t,r){return this.$gantt.date.add(e,r,t)},_getWorkUnitsBetweenGeneric:function(e,t,r,i){var n=this.$gantt.date,o=new Date(e),a=new Date(t);i=i||1;var s=0,c=null,l,d,u=!1;l=n[r+"_start"](new Date(o)),l.valueOf()!=o.valueOf()&&(u=!0);var f=!1;d=n[r+"_start"](new Date(t)),d.valueOf()!=t.valueOf()&&(f=!0);for(var p=!1;o.valueOf()<a.valueOf();){if(c=this._nextDate(o,r,i),p=c.valueOf()>a.valueOf(),this._isWorkTime(o,r))(u||f&&p)&&(l=n[r+"_start"](new Date(o)),d=n.add(l,i,r)),u?(u=!1,c=this._nextDate(l,r,i),s+=(d.valueOf()-o.valueOf())/(d.valueOf()-l.valueOf())):f&&p?(f=!1,s+=(a.valueOf()-o.valueOf())/(d.valueOf()-l.valueOf())):s++;else{var y=this._getUnitOrder(r),I=this.units[y-1];I&&!this._isWorkTime(o,I)&&(c=this._getClosestWorkTimeFuture(o,I))}o=c}return s},_getMinutesPerHour:function(e){var t=this._getTimeOfDayStamp(e),r=this._getTimeOfDayStamp(this._nextDate(e,"hour",1));r===0&&(r=1440*60);for(var i=this._getWorkHours(e),n=0;n<i.length;n++){var o=i[n];if(t>=o.start&&r<=o.end)return 60;if(t<o.end&&r>o.start){var a=Math.min(r,o.end)-Math.max(t,o.start);return a/60}}return 0},_getMinutesPerDay:function(e){var t=this._getWorkHours(e),r=0;return t.forEach(function(i){r+=i.durationMinutes}),r},getHoursPerDay:function(e){var t=this._getWorkHours(e),r=0;return t.forEach(function(i){r+=i.durationHours}),r},_getWorkUnitsForRange:function(e,t,r,i){var n=0,o=new Date(e),a=new Date(t),s;for(r=="minute"?s=Bt(this._getMinutesPerDay,this):s=Bt(this.getHoursPerDay,this);o.valueOf()<a.valueOf();){if(a-o>1e3*60*60*24*32&&o.getUTCDate()===0){var c=this._largeUnitsCache.getMinutesPerMonth(o);r=="hour"&&(c=c/60),n+=c,o=this.$gantt.date.add(o,1,"month");continue}else if(a-o>1e3*60*60*24*16){var l=this.$gantt.date.week_start(new Date(o));if(o.valueOf()===l.valueOf()){var c=this._largeUnitsCache.getMinutesPerWeek(o);r=="hour"&&(c=c/60),n+=c,o=this.$gantt.date.add(o,7,"day");continue}}n+=s(o),o=this._nextDate(o,"day",1)}return n/i},_getMinutesBetweenSingleDay:function(e,t){for(var r=this._getIntervalTimestamp(e,t),i=this._getWorkHours(e),n=0,o=0;o<i.length;o++){var a=i[o];if(r.end>=a.start&&r.start<=a.end){var s=Math.max(a.start,r.start),c=Math.min(a.end,r.end);n+=(c-s)/60,r.start=c}}return Math.floor(n)},_getMinutesBetween:function(e,t,r,i){var n=new Date(e),o=new Date(t);i=i||1;var a=new Date(n),s=this.$gantt.date.add(this.$gantt.date.day_start(new Date(n)),1,"day");if(o.valueOf()<=s.valueOf())return this._getMinutesBetweenSingleDay(e,t);var c=this.$gantt.date.day_start(new Date(o)),l=o,d=this._getMinutesBetweenSingleDay(a,s),u=this._getMinutesBetweenSingleDay(c,l),f=this._getWorkUnitsForRange(s,c,r,i),p=d+f+u;return p},_getHoursBetween:function(e,t,r,i){var n=new Date(e),o=new Date(t);i=i||1;var a=new Date(n),s=this.$gantt.date.add(this.$gantt.date.day_start(new Date(n)),1,"day");if(o.valueOf()<=s.valueOf())return Math.round(this._getMinutesBetweenSingleDay(e,t)/60);var c=this.$gantt.date.day_start(new Date(o)),l=o,d=this._getMinutesBetweenSingleDay(a,s,r,i)/60,u=this._getMinutesBetweenSingleDay(c,l,r,i)/60,f=this._getWorkUnitsForRange(s,c,r,i),p=d+f+u;return Math.round(p)},getConfig:function(){return this._worktime},_setConfig:function(e){this._worktime=e,this._parseSettings(),this._clearCaches()},_parseSettings:function(){var e=this.getConfig();e.parsed={dates:{},hours:null,haveCustomWeeks:!1,customWeeks:{},customWeeksRangeStart:null,customWeeksRangeEnd:null,customWeeksBoundaries:[]},e.parsed.hours=this._parseHours(e.hours);for(var t in e.dates)e.parsed.dates[t]=this._parseHours(e.dates[t]);if(e.customWeeks){var r=null,i=null;for(var t in e.customWeeks){var n=e.customWeeks[t];if(n.from&&n.to){var o=n.from,a=n.to;(!r||r>o.valueOf())&&(r=o.valueOf()),(!i||i<a.valueOf())&&(i=a.valueOf()),e.parsed.customWeeksBoundaries.push({from:o.valueOf(),fromReadable:new Date(o),to:a.valueOf(),toReadable:new Date(a),name:t}),e.parsed.haveCustomWeeks=!0;var s=e.parsed.customWeeks[t]={from:n.from,to:n.to,hours:this._parseHours(n.hours),dates:{}};if(n.days&&!n.dates){n.dates=n.dates||{};for(var t=0;t<n.days.length;t++)n.dates[t]=n.days[t],n.days[t]instanceof Array||(n.dates[t]=!!n.days[t]);delete n.days}for(var c in n.dates)s.dates[c]=this._parseHours(n.dates[c])}}e.parsed.customWeeksRangeStart=r,e.parsed.customWeeksRangeEnd=i}},_tryChangeCalendarSettings:function(e){var t=JSON.stringify(this.getConfig());return e(),this.hasWorkTime()?!0:(this._setConfig(JSON.parse(t)),this._clearCaches(),!1)},_arraysEqual:function(e,t){if(e===t)return!0;if(!e||!t||e.length!=t.length)return!1;for(var r=0;r<e.length;++r)if(e[r]!==t[r])return!1;return!0},_compareSettings:function(e,t){if(!this._arraysEqual(e.hours,t.hours))return!1;var r=Object.keys(e.dates),i=Object.keys(t.dates);if(r.sort(),i.sort(),!this._arraysEqual(r,i))return!1;for(var n=0;n<r.length;n++){var o=r[n],a=e.dates[o],s=t.dates[o];if(a!==s&&!(Array.isArray(a)&&Array.isArray(s)&&this._arraysEqual(a,s)))return!1}return!0},equals:function(e){if(!(e instanceof va))return!1;var t=this.getConfig(),r=e.getConfig();if(!this._compareSettings(t,r))return!1;if(t.parsed.haveCustomWeeks&&r.parsed.haveCustomWeeks){if(t.parsed.customWeeksBoundaries.length!=r.parsed.customWeeksBoundaries.length)return!1;for(var i in t.parsed.customWeeks){var n=t.parsed.customWeeks[i],o=r.parsed.customWeeks[i];if(!o||!this._compareSettings(n,o))return!1}}else if(t.parse.haveCustomWeeks!==r.parsed.haveCustomWeeks)return!1;return!0},getWorkHours:function(){var e=this.argumentsHelper.getWorkHoursArguments.apply(this.argumentsHelper,arguments);return this._getWorkHours(e.date,!1)},_getWorkHours:function(e,t){var r=this.getConfig();if(t!==!1&&(r=r.parsed),!e)return r.hours;let i=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()));var n=this._timestamp({date:i});if(r.haveCustomWeeks&&r.customWeeksRangeStart<=n&&r.customWeeksRangeEnd>n){for(var o=0;o<r.customWeeksBoundaries.length;o++)if(r.customWeeksBoundaries[o].from<=n&&r.customWeeksBoundaries[o].to>n){r=r.customWeeks[r.customWeeksBoundaries[o].name];break}}var a=!0;return r.dates[n]!==void 0?a=r.dates[n]:r.dates[e.getUTCDay()]!==void 0&&(a=r.dates[e.getUTCDay()]),a===!0?r.hours:a||[]},_getIntervalTimestamp:function(e,t){var r={start:0,end:0};r.start=e.getUTCHours()*60*60+e.getUTCMinutes()*60+e.getUTCSeconds();var i=t.getUTCHours();return!i&&!t.getUTCMinutes()&&!t.getUTCSeconds()&&e.valueOf()<t.valueOf()&&(i=24),r.end=i*60*60+t.getUTCMinutes()*60+t.getUTCSeconds(),r},_parseHours:function(e){if(Array.isArray(e)){var t=[];e.forEach(function(s){typeof s=="number"?t.push(s*60*60):typeof s=="string"&&s.split("-").map(function(c){return c.trim()}).forEach(function(c){var l=c.split(":").map(function(u){return u.trim()}),d=parseInt(l[0]*60*60);l[1]&&(d+=parseInt(l[1]*60)),l[2]&&(d+=parseInt(l[2])),t.push(d)})});for(var r=[],i=0;i<t.length;i+=2){var n=t[i],o=t[i+1],a=o-n;r.push({start:n,end:o,startHour:Math.floor(n/3600),startMinute:Math.floor(n/60),endHour:Math.ceil(o/3600),endMinute:Math.ceil(o/60),durationSeconds:a,durationMinutes:a/60,durationHours:a/3600})}return r}else return e},setWorkTime:function(e){return this._tryChangeCalendarSettings(Bt(function(){var t=e.hours!==void 0?e.hours:!0,r=this._timestamp(e),i=this.getConfig();if(r!==null?i.dates[r]=t:e.customWeeks||(i.hours=t),e.customWeeks){if(i.customWeeks||(i.customWeeks={}),typeof e.customWeeks=="string")r!==null?i.customWeeks[e.customWeeks].dates[r]=t:e.customWeeks||(i.customWeeks[e.customWeeks].hours=t);else if(typeof e.customWeeks=="object"&&e.customWeeks.constructor===Object)for(var n in e.customWeeks)i.customWeeks[n]=e.customWeeks[n]}this._parseSettings(),this._clearCaches()},this))},unsetWorkTime:function(e){return this._tryChangeCalendarSettings(Bt(function(){if(!e)this.reset_calendar();else{var t=this._timestamp(e);t!==null&&delete this.getConfig().dates[t]}this._parseSettings(),this._clearCaches()},this))},_isWorkTime:function(e,t){var r=-1,i=null;return i=String(e.valueOf()),r=this._workingUnitsCache.getItem(t,i,e),r==-1&&(r=this._checkIfWorkingUnit(e,t),this._workingUnitsCache.setItem(t,i,r,e)),r},isWorkTime:function(){var e=this.argumentsHelper.isWorkTimeArguments.apply(this.argumentsHelper,arguments);return this._isWorkTime(e.date,e.unit)},calculateDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments);if(!e.unit)return!1;var t=this;return this._dateDurationCache.getDuration(e.start_date,e.end_date,e.unit,e.step,function(){return t._calculateDuration(e.start_date,e.end_date,e.unit,e.step)})},_calculateDuration:function(e,t,r,i){var n=0,o=1;if(e.valueOf()>t.valueOf()){var a=t;t=e,e=a,o=-1}return r=="hour"&&i==1?n=this._getHoursBetween(e,t,r,i):r=="minute"&&i==1?n=this._getMinutesBetween(e,t,r,i):n=this._getWorkUnitsBetweenGeneric(e,t,r,i),o*Math.round(n)},hasDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.end_date,i=e.unit,n=e.step;if(!i)return!1;var o=new Date(t),a=new Date(r);for(n=n||1;o.valueOf()<a.valueOf();){if(this._isWorkTime(o,i))return!0;o=this._nextDate(o,i,n)}return!1},calculateEndDate:function(){var e=this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.duration,i=e.unit,n=e.step;if(!i)return!1;var o=e.duration>=0?1:-1;r=Math.abs(r*1);var a=this;return this._dateDurationCache.getEndDate(t,r,i,n*o,function(){return a._calculateEndDate(t,r,i,n*o)})},_calculateEndDate:function(e,t,r,i){if(!r)return!1;if(i==1&&r=="minute")return this._calculateMinuteEndDate(e,t,i);if(i==-1&&r=="minute")return this._subtractMinuteDate(e,t,i);if(i==1&&r=="hour")return this._calculateHourEndDate(e,t,i);var n=this._addInterval(e,t,r,i,null);return n.end},_addInterval:function(e,t,r,i,n){for(var o=0,a=e;o<t&&!(n&&n(a));){var s=this._nextDate(a,r,i),c=new Date(s.valueOf()+1);i>0&&(c=new Date(s.valueOf()-1));var l=this._isWorkTime(c,r);l&&o++,a=s}return{end:a,start:e,added:o}},_addHoursUntilDayEnd:function(e,t){for(var r=this.$gantt.date.add(this.$gantt.date.day_start(new Date(e)),1,"day"),i=0,n=t,o=this._getIntervalTimestamp(e,r),a=this._getWorkHours(e),s=0;s<a.length&&i<t;s++){var c=a[s];if(o.end>=c.start&&o.start<=c.end){var l=Math.max(c.start,o.start),d=Math.min(c.end,o.end),u=(d-l)/3600;u>n&&(u=n,d=l+n*60*60);var f=Math.round((d-l)/3600);i+=f,n-=f,o.start=d}}var p=r;return i===t&&(p=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),0,0,o.start))),{added:i,end:p}},_calculateHourEndDate:function(e,t,r){var i=new Date(e),n=0;r=r||1,t=Math.abs(t*1);var o=this._addHoursUntilDayEnd(i,t);n=o.added,i=o.end;var a=t-n;if(a){for(var s=i;n<t;){var c=this._nextDate(s,"day",r);c.setUTCHours(0),c.setUTCMinutes(0),c.setUTCSeconds(0);var l=0;if(r>0?l=this.getHoursPerDay(new Date(c.valueOf()-1)):l=this.getHoursPerDay(new Date(c.valueOf()+1)),n+l>=t)break;n+=l,s=c}i=s}if(n<t){var a=t-n;o=this._addHoursUntilDayEnd(i,a),i=o.end}return i},_addMinutesUntilHourEnd:function(e,t){if(e.getUTCMinutes()===0)return{added:0,end:new Date(e)};for(var r=this.$gantt.date.add(this.$gantt.date.hour_start(new Date(e)),1,"hour"),i=0,n=t,o=this._getIntervalTimestamp(e,r),a=this._getWorkHours(e),s=0;s<a.length&&i<t;s++){var c=a[s];if(o.end>=c.start&&o.start<=c.end){var l=Math.max(c.start,o.start),d=Math.min(c.end,o.end),u=(d-l)/60;u>n&&(u=n,d=l+n*60);var f=Math.round((d-l)/60);n-=f,i+=f,o.start=d}}var p=r;return i===t&&(p=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),0,0,o.start))),{added:i,end:p}},_subtractMinutesUntilHourStart:function(e,t){for(var r=this.$gantt.date.hour_start(new Date(e)),i=0,n=t,o=r.getUTCHours()*60*60+r.getUTCMinutes()*60+r.getUTCSeconds(),a=e.getUTCHours()*60*60+e.getUTCMinutes()*60+e.getUTCSeconds(),s=this._getWorkHours(e),c=s.length-1;c>=0&&i<t;c--){var l=s[c];if(a>l.start&&o<=l.end){var d=Math.min(a,l.end),u=Math.max(o,l.start),f=(d-u)/60;f>n&&(f=n,u=d-n*60);var p=Math.abs(Math.round((d-u)/60));n-=p,i+=p,a=u}}var y=r;return i===t&&(y=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),0,0,a))),{added:i,end:y}},_subtractMinuteDate:function(e,t,r){var i=this.getClosestWorkTime({date:e,dir:"past",unit:"minute"}),n=0;r=r||-1,t=Math.abs(t*1),t=Math.round(t);let o=this._isMinutePrecision(i),a=this._subtractMinutesUntilHourStart(i,t);n+=a.added,i=a.end;for(var s=0,c=[],l=0;n<t;){var d=this.$gantt.date.day_start(new Date(i)),u=!1;i.valueOf()===d.valueOf()&&(d=this.$gantt.date.add(d,-1,"day"),u=!0);var f=new Date(Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate(),23,59,59,999)).valueOf();f!==s&&(c=this._getWorkHours(d),l=this._getMinutesPerDay(d),s=f);var p=t-n,y=this._getTimeOfDayStamp(i,u);if(!c.length||!l){i=this.$gantt.date.add(i,-1,"day");continue}if(c[c.length-1].end<=y&&p>l){n+=l,i=this.$gantt.date.add(i,-1,"day");continue}for(var I=!1,T=null,L=null,S=c.length-1;S>=0;S--)if(c[S].start<y-1&&c[S].end>=y-1){I=!0,T=c[S],L=c[S-1];break}if(I)if(y===T.end&&p>=T.durationMinutes)n+=T.durationMinutes,i=this.$gantt.date.add(i,-T.durationMinutes,"minute");else if(!o&&p<=y/60-T.startMinute)n+=p,i=this.$gantt.date.add(i,-p,"minute");else if(o)p<=y/60-T.startMinute?(n+=p,i=this.$gantt.date.add(i,-p,"minute")):(n+=y/60-T.startMinute,L?i=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,L.end)):i=this.$gantt.date.day_start(i));else{var E=this._getMinutesPerHour(i);E<=p?(n+=E,i=this._nextDate(i,"hour",r)):(a=this._subtractMinutesUntilHourStart(i,p),n+=a.added,i=a.end)}else if(i.getUTCHours()===0&&i.getUTCMinutes()===0&&i.getUTCSeconds()===0){var g=this._getClosestWorkTimePast(i,"hour");if(g.valueOf()===i.valueOf()){var g=this.$gantt.date.add(i,-1,"day"),b=this._getWorkHours(g);if(b.length){var B=b[b.length-1];g.setUTCSeconds(B.durationSeconds)}}i=g}else i=this._getClosestWorkTimePast(new Date(i-1),"hour")}if(n<t){var k=t-n;a=this._subtractMinutesUntilHourStart(i,k),n+=a.added,i=a.end}return i},_calculateMinuteEndDate:function(e,t,r){var i=new Date(e),n=0;r=r||1,t=Math.abs(t*1),t=Math.round(t);var o=this._addMinutesUntilHourEnd(i,t);n+=o.added,i=o.end;for(var a=0,s=[],c=0,l=this._isMinutePrecision(i);n<t;){var d=this.$gantt.date.day_start(new Date(i)).valueOf();d!==a&&(s=this._getWorkHours(i),c=this._getMinutesPerDay(i),a=d);var u=t-n,f=this._getTimeOfDayStamp(i);if(!s.length||!c){i=this.$gantt.date.add(this.$gantt.date.day_start(i),1,"day");continue}if(s[0].start>=f&&u>=c){if(n+=c,u==c){i=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,s[s.length-1].end));break}else i=this.$gantt.date.add(i,1,"day"),i=this.$gantt.date.day_start(i);continue}for(var p=!1,y=null,I=0;I<s.length;I++)if(s[I].start<=f&&s[I].end>f){p=!0,y=s[I];break}if(p)if(f===y.start&&u>=y.durationMinutes)n+=y.durationMinutes,i=this.$gantt.date.add(i,y.durationMinutes,"minute");else if(u<=y.endMinute-f/60)n+=u,i=this.$gantt.date.add(i,u,"minute");else{var T=this._getMinutesPerHour(i);T<=u?(n+=T,l?i=this.$gantt.date.add(i,T,"minute"):i=this._nextDate(i,"hour",r)):(o=this._addMinutesUntilHourEnd(i,u),n+=o.added,i=o.end)}else i=this._getClosestWorkTimeFuture(i,"hour")}if(n<t){var L=t-n;o=this._addMinutesUntilHourEnd(i,L),n+=o.added,i=o.end}return i},getClosestWorkTime:function(){var e=this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper,arguments);return this._getClosestWorkTime(e.date,e.unit,e.dir)},_getClosestWorkTime:function(e,t,r){var i=new Date(e);if(this._isWorkTime(i,t))return i;if(i=this.$gantt.date[t+"_start"](i),r=="any"||!r){var n=this._getClosestWorkTimeFuture(i,t),o=this._getClosestWorkTimePast(i,t);Math.abs(n-e)<=Math.abs(e-o)?i=n:i=o}else r=="past"?i=this._getClosestWorkTimePast(i,t):i=this._getClosestWorkTimeFuture(i,t);return i},_getClosestWorkTimeFuture:function(e,t){return this._getClosestWorkTimeGeneric(e,t,1)},_getClosestWorkTimePast:function(e,t){var r=this._getClosestWorkTimeGeneric(e,t,-1);return this.$gantt.date.add(r,1,t)},_findClosestTimeInDay:function(e,t,r){var i=new Date(e),n=null,o=!1;this._getWorkHours(i).length||(i=this._getClosestWorkTime(i,"day",t<0?"past":"future"),t<0&&(i=new Date(i.valueOf()-1),o=!0),r=this._getWorkHours(i));var a=this._getTimeOfDayStamp(i);if(o&&(a=this._getTimeOfDayStamp(new Date(i.valueOf()+1),o)),t>0){for(var s=0;s<r.length;s++)if(r[s].start>=a){n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,r[s].start));break}}else for(var s=r.length-1;s>=0;s--)if(r[s].end<=a){n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,r[s].end));break}else if(r[s].end>a&&r[s].start<=a){n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,a));break}return n},_getClosestWorkMinute:function(e,t,r){var i=new Date(e),n=this._getWorkHours(i),o=this._findClosestTimeInDay(i,r,n);return o||(r>0?(i=this.calculateEndDate(i,r,t),i=this.$gantt.date.day_start(i)):(i=this.calculateEndDate(i,r,"day"),i=this.$gantt.date.day_start(i),i=this.$gantt.date.add(i,1,"day"),i=new Date(i.valueOf()-1)),n=this._getWorkHours(i),o=this._findClosestTimeInDay(i,r,n)),r<0&&(o=this.$gantt.date.add(o,-1,t)),o},_getClosestWorkTimeGeneric:function(e,t,r){if(t==="hour"||t==="minute")return this._getClosestWorkMinute(e,t,r);for(var i=this._getUnitOrder(t),n=this.units[i-1],o=e,a=3e3,s=0;!this._isWorkTime(o,t)&&!(n&&!this._isWorkTime(o,n)&&(r>0?o=this._getClosestWorkTimeFuture(o,n):o=this._getClosestWorkTimePast(o,n),this._isWorkTime(o,t)));){if(s++,s>a)return this.$gantt.assert(!1,"Invalid working time check"),!1;o=this.$gantt.date.add(o,r,t),this.$gantt.date[t+"_start"]&&(o=this.$gantt.date[t+"_start"](o))}return o},hasWorkTime:function(){var e=this.getConfig(),t=e.dates,r=[0,1,2,3,4,5,6];for(var i in e.dates);var n=this._checkWorkHours(e.hours),o=!1;return r.forEach((function(a){if(!o){var s=t[a];s===!0?o=n:Array.isArray(s)&&(o=this._checkWorkHours(s))}}).bind(this)),o},_checkWorkHours:function(e){if(e.length===0)return!1;for(var t=!1,r=0;r<e.length;r+=2)e[r]!==e[r+1]&&(t=!0);return t},_isMinutePrecision:function(e){let t=!1;return this._getWorkHours(e).forEach(function(r){(r.startMinute%60||r.endMinute%60)&&(t=!0)}),t}};var Qr={isLegacyResourceCalendarFormat:function(e){if(!e)return!1;for(var t in e)if(e[t]&&typeof e[t]=="object")return!0;return!1},getResourceProperty:function(e){var t=e.resource_calendars,r=e.resource_property;if(this.isLegacyResourceCalendarFormat(t))for(var i in e){r=i;break}return r},getCalendarIdFromLegacyConfig:function(e,t){if(t)for(var r in t){var i=t[r];if(e[r]){var n=i[e[r]];if(n)return n}}return null}};function hg(){function e(n){return n.map(function(o){return o&&o.resource_id?o.resource_id:o}).sort().join("-")}var t={};function r(n,o){return o.mergeCalendars(n.map(function(a){var s=a&&a.resource_id?a.resource_id:a;return o.getResourceCalendar(s)}))}function i(n,o){var a=e(n);if(n.length){if(n.length===1)return o.getResourceCalendar(a).id;if(t[a])return t[a].id;var s=r(n,o);return t[a]=s,o.addCalendar(s)}else return null}return{getCalendarIdFromMultipleResources:i}}var mg=hg();function Rd(e){this.$gantt=e,this._calendars={},this._legacyConfig=void 0,this.$gantt.attachEvent("onGanttReady",(function(){this.$gantt.config.resource_calendars&&(this._isLegacyConfig=Qr.isLegacyResourceCalendarFormat(this.$gantt.config.resource_calendars))}).bind(this)),this.$gantt.attachEvent("onBeforeGanttReady",(function(){this.createDefaultCalendars()}).bind(this)),this.$gantt.attachEvent("onBeforeGanttRender",(function(){this.createDefaultCalendars()}).bind(this))}Rd.prototype={_calendars:{},_convertWorkTimeSettings:function(e){let t=e.days;if(typeof t=="object"&&!Array.isArray(t)&&t!==null){let r={};if(t?.weekdays)for(let i=0;i<7;i++)r[i]=t.weekdays[i];t?.dates&&Object.entries(t.dates).forEach(([i,n])=>{r[new Date(i).valueOf()]=n}),Object.entries(r).forEach(([i,n])=>{n instanceof Array||(r[i]=!!n)}),e={...e,dates:r}}else if(t&&!e.dates){e.dates=e.dates||{};for(let r=0;r<t.length;r++)e.dates[r]=t[r],t[r]instanceof Array||(e.dates[r]=!!t[r])}return delete e.days,e},mergeCalendars:function(){var e=[],t=arguments;if(Array.isArray(t[0]))e=t[0].slice();else for(var r=0;r<arguments.length;r++)e.push(arguments[r]);var i=new kd,n;return e.forEach((function(o){n?n=this._createCalendarFromConfig(i.merge(n,o)):n=o}).bind(this)),this.createCalendar(n)},_createCalendarFromConfig:function(e){var t=new va(this.$gantt,_d(this.$gantt));t.id=String(fa());var r=this._convertWorkTimeSettings(e);if(r.customWeeks)for(var i in r.customWeeks)r.customWeeks[i]=this._convertWorkTimeSettings(r.customWeeks[i]);return t._setConfig(r),t},createCalendar:function(e){var t;e||(e={}),e.getConfig?t=Jt(e.getConfig()):e.worktime?t=Jt(e.worktime):t=Jt(e);var r=Jt(this.defaults.fulltime.worktime);return Sr(t,r),this._createCalendarFromConfig(t)},getCalendar:function(e){e=e||"global";var t=this._calendars[e];return t||(this.createDefaultCalendars(),t=this._calendars[e]),t},getCalendars:function(){var e=[];for(var t in this._calendars)e.push(this.getCalendar(t));return e},_getOwnCalendar:function(e){var t=this.$gantt.config;if(e[t.calendar_property])return this.getCalendar(e[t.calendar_property]);if(t.resource_calendars){var r,i,n;if(this._legacyConfig===!1?n=t.resource_property:n=Qr.getResourceProperty(t),Array.isArray(e[n])&&e[n].length)t.dynamic_resource_calendars?i=mg.getCalendarIdFromMultipleResources(e[n],this):r=this.getResourceCalendar(e[n]);else if(this._legacyConfig===void 0&&(this._legacyConfig=Qr.isLegacyResourceCalendarFormat(t.resource_calendars)),this._legacyConfig)var i=Qr.getCalendarIdFromLegacyConfig(e,t.resource_calendars);else if(n&&e[n]&&t.resource_calendars[e[n]])var r=this.getResourceCalendar(e[n]);if(i&&(r=this.getCalendar(i)),r)return r}return null},getResourceCalendar:function(e){if(e==null)return this.getCalendar();var t=null;typeof e=="number"||typeof e=="string"?t=e:t=e.id||e.key;var r=this.$gantt.config,i=r.resource_calendars,n=null;if(Array.isArray(e)&&e.length===1&&(typeof e[0]=="object"?t=e[0].resource_id:t=e[0]),i){if(this._legacyConfig===void 0&&(this._legacyConfig=Qr.isLegacyResourceCalendarFormat(r.resource_calendars)),this._legacyConfig){for(var o in i)if(i[o][t]){n=i[o][t];break}}else var n=i[t];if(n)return this.getCalendar(n)}return this.getCalendar()},getTaskCalendar:function(e){var t=this.$gantt,r;if(e==null)return this.getCalendar();if((typeof e=="number"||typeof e=="string")&&t.isTaskExists(e)?r=t.getTask(e):r=e,!r)return this.getCalendar();var i=this._getOwnCalendar(r),n=!!t.getState().group_mode;if(!i&&t.config.inherit_calendar&&t.isTaskExists(r.parent)){for(var o=r;t.isTaskExists(o.parent)&&(o=t.getTask(o.parent),!(t.isSummaryTask(o)&&(i=this._getOwnCalendar(o),i))););n&&!i&&e.$effective_calendar&&(i=this.getCalendar(e.$effective_calendar))}return i||this.getCalendar()},addCalendar:function(e){if(!this.isCalendar(e)){var t=e.id;e=this.createCalendar(e),e.id=t}if(e._tryChangeCalendarSettings(function(){})){var r=this.$gantt.config;return e.id=e.id||fa(),this._calendars[e.id]=e,r.worktimes||(r.worktimes={}),r.worktimes[e.id]=e.getConfig(),e.id}else return this.$gantt.callEvent("onCalendarError",[{message:"Invalid calendar settings, no worktime available"},e]),null},deleteCalendar:function(e){var t=this.$gantt.config;return e&&this._calendars[e]?(delete this._calendars[e],t.worktimes&&t.worktimes[e]&&delete t.worktimes[e],!0):!1},restoreConfigCalendars:function(e){for(var t in e)if(!this._calendars[t]){var r=e[t],i=this.createCalendar(r);i.id=t,this.addCalendar(i)}},defaults:{global:{id:"global",worktime:{hours:[8,12,13,17],days:[0,1,1,1,1,1,0]}},fulltime:{id:"fulltime",worktime:{hours:[0,24],days:[1,1,1,1,1,1,1]}}},createDefaultCalendars:function(){var e=this.$gantt.config;this.restoreConfigCalendars(this.defaults),this.restoreConfigCalendars(e.worktimes)},isCalendar:function(e){var t=[e.isWorkTime,e.setWorkTime,e.getWorkHours,e.unsetWorkTime,e.getClosestWorkTime,e.calculateDuration,e.hasDuration,e.calculateEndDate];return t.every(function(r){return r instanceof Function})}};function Ca(e,t){this.argumentsHelper=t,this.$gantt=e}Ca.prototype={getWorkHours:function(){return[0,24]},setWorkTime:function(){return!0},unsetWorkTime:function(){return!0},isWorkTime:function(){return!0},getClosestWorkTime:function(t){var t=this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper,arguments);return t.date},calculateDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.end_date,i=e.unit,n=e.step;return this._calculateDuration(t,r,i,n)},_calculateDuration:function(e,t,r,i){var n=this.$gantt.date,o={week:1e3*60*60*24*7,day:1e3*60*60*24,hour:1e3*60*60,minute:1e3*60},a=0;if(o[r])a=Math.round((t-e)/(i*o[r]));else{for(var s=new Date(e),c=new Date(t);s.valueOf()<c.valueOf();)a+=1,s=n.add(s,i,r);s.valueOf()!=t.valueOf()&&(a+=(c-s)/(n.add(s,i,r)-s))}return Math.round(a)},hasDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.end_date,i=e.unit;return i?(t=new Date(t),r=new Date(r),t.valueOf()<r.valueOf()):!1},hasWorkTime:function(){return!0},equals:function(e){return e instanceof Ca},calculateEndDate:function(){var e=this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.duration,i=e.unit,n=e.step;return this.$gantt.date.add(t,n*r,i)}};function Pd(e){this.$gantt=e.$gantt,this.argumentsHelper=_d(this.$gantt),this.calendarManager=e,this.$disabledCalendar=new Ca(this.$gantt,this.argumentsHelper)}Pd.prototype={_getCalendar:function(e){var t;if(!this.$gantt.config.work_time)t=this.$disabledCalendar;else{var r=this.calendarManager;e.task?t=r.getTaskCalendar(e.task):e.id?t=r.getTaskCalendar(e):e.calendar&&(t=e.calendar),t||(t=r.getTaskCalendar())}return t},getWorkHours:function(e){e=this.argumentsHelper.getWorkHoursArguments.apply(this.argumentsHelper,arguments);var t=this._getCalendar(e);return t.getWorkHours(e.date)},setWorkTime:function(e,t){return e=this.argumentsHelper.setWorkTimeArguments.apply(this.argumentsHelper,arguments),t||(t=this.calendarManager.getCalendar()),t.setWorkTime(e)},unsetWorkTime:function(e,t){return e=this.argumentsHelper.unsetWorkTimeArguments.apply(this.argumentsHelper,arguments),t||(t=this.calendarManager.getCalendar()),t.unsetWorkTime(e)},isWorkTime:function(e,t,r,i){var n=this.argumentsHelper.isWorkTimeArguments.apply(this.argumentsHelper,arguments);return i=this._getCalendar(n),i.isWorkTime(n)},getClosestWorkTime:function(e){e=this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper,arguments);var t=this._getCalendar(e);return t.getClosestWorkTime(e)},calculateDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=this._getCalendar(e);return t.calculateDuration(e)},hasDuration:function(){var e=this.argumentsHelper.hasDurationArguments.apply(this.argumentsHelper,arguments),t=this._getCalendar(e);return t.hasDuration(e)},calculateEndDate:function(t){var t=this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper,arguments),r=this._getCalendar(t);return r.calculateEndDate(t)}};var Ig=function(e,t){return{getWorkHours:function(r){return t.getWorkHours(r)},setWorkTime:function(r){return t.setWorkTime(r)},unsetWorkTime:function(r){t.unsetWorkTime(r)},isWorkTime:function(r,i,n){return t.isWorkTime(r,i,n)},getClosestWorkTime:function(r){return t.getClosestWorkTime(r)},calculateDuration:function(r,i,n){return t.calculateDuration(r,i,n)},_hasDuration:function(r,i,n){return t.hasDuration(r,i,n)},calculateEndDate:function(r,i,n,o){return t.calculateEndDate(r,i,n,o)},mergeCalendars:Bt(e.mergeCalendars,e),createCalendar:Bt(e.createCalendar,e),addCalendar:Bt(e.addCalendar,e),getCalendar:Bt(e.getCalendar,e),getCalendars:Bt(e.getCalendars,e),getResourceCalendar:Bt(e.getResourceCalendar,e),getTaskCalendar:Bt(e.getTaskCalendar,e),deleteCalendar:Bt(e.deleteCalendar,e)}},gg={create:Ig};function Ld(e){var t=new Rd(e),r=new Pd(t),i=gg.create(t,r);Sr(e,i)}var Od={date:{month_full:["January","February","March","April","May","June","July","August","September","October","November","December"],month_short:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],day_full:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],day_short:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]},labels:{}};function Nd(e={}){let t=e.config||{},r={config:Object.assign({duration_unit:"hour",duration_step:1,work_time:!1,worktimes:{},work_days:null,inherit_calendar:!1,calendar_property:"calendar_id",resource_property:"resource_id",resource_calendars:{},dynamic_resource_calendars:!1,start_on_monday:!0,server_utc:!0,csp:"auto",show_errors:!1},t),locale:e.locale||Od,templates:e.templates||{},getTask:e.getTask||function(i){return null},isTaskExists:e.isTaskExists||function(i){return!1},isSummaryTask:e.isSummaryTask||function(i){return!1},getState:function(){return{group_mode:!1}},callEvent:function(i,n){let o=e.onEvent;return o&&o(i,n),!0},attachEvent:function(){return 0},checkEvent:function(){return!1},detachEvent:function(){},defined:Sd,mixin:Sr,copy:Jt,assert:function(i,n){if(!i){if(e.throwOnAssert)throw new Error("[calendar] "+n);e.silent!==!0&&console.error("[calendar]",n)}},$services:{getService:function(){return null}},$ui:{getView:function(){return null}}};return r._correct_dst_change=function(i){return i},r.date=Dd(r),r.date.init(),Ld(r),r}function Ag(e={}){let t=Nd(e);return{addCalendar:function(r){return t.addCalendar(r)},deleteCalendar:function(r){return t.deleteCalendar(r)},getCalendar:function(r){return t.getCalendar(r)},getCalendars:function(){return t.getCalendars()},mergeCalendars:function(){return t.mergeCalendars.apply(t,arguments)},getTaskCalendar:function(r){return t.getTaskCalendar(r)},getResourceCalendar:function(r){return t.getResourceCalendar(r)},setWorkTime:function(r){return t.setWorkTime(r)},unsetWorkTime:function(r){return t.unsetWorkTime(r)},isWorkTime:function(){return t.isWorkTime.apply(t,arguments)},getClosestWorkTime:function(){return t.getClosestWorkTime.apply(t,arguments)},getWorkHours:function(){return t.getWorkHours.apply(t,arguments)},calculateDuration:function(){return t.calculateDuration.apply(t,arguments)},calculateEndDate:function(){return t.calculateEndDate.apply(t,arguments)},_internals:t}}var bd={createCalendar:Ag};var yU=3600*1e3;function Md(e){return{getActivity(t){return e.getActivity(t)}}}var{createCalendar:vg}=bd,ti="__replay_default__";function Cg(e){if(!e||e.length===0||typeof e[0]=="string")return e;let t=e.map(Number);if(t.some(o=>Number.isNaN(o)))return e;let r=t[0],i=t[t.length-1];return t.every((o,a)=>o===r+a)?[`${r}:00-${i+1}:00`]:e}var Fd={hours:["8:00-16:00"],days:[!1,!0,!0,!0,!0,!0,!1]},wd="__main_global__",Sg={hours:["8:00-12:00","13:00-17:00"],days:[!1,!0,!0,!0,!0,!0,!1]};function xd(e){return!e||e.hours===void 0||e.hours.length>0||e.days?.some(t=>Array.isArray(t)&&t.length>0)===!0?!0:Object.values(e.dates??{}).some(t=>Array.isArray(t)&&t.length>0)}function Tg(e){let t={};if(Array.isArray(e.days))for(let i=0;i<e.days.length;i+=1)t[i]=e.days[i];if(e.dates)for(let[i,n]of Object.entries(e.dates))t[i]=n;let r={hours:Cg(e.hours),dates:t};return e.customWeeks&&(r.customWeeks=e.customWeeks),r}function Ud(e){let t=vg({config:{work_time:!0}});t.addCalendar({id:ti,worktime:Fd}),t.addCalendar({id:wd,worktime:Sg});let r=new Set(e.filter(d=>!xd(d.worktime)).map(d=>String(d.id))),i=e.filter(d=>xd(d.worktime));for(let d of i)t.addCalendar({id:d.id,worktime:d.worktime?Tg(d.worktime):Fd});let n=Cd(t),o=n.getCalendar(ti),a=n.getCalendar(wd);if(!o||!a)throw new Error("[replay-calendar] fallback calendars failed to register in work-calendar instance");let s=new Set([ti]);for(let d of i)s.add(String(d.id));let c=new Map;return{reader:{getCalendar(d){let u=String(d),f=c.get(u);if(f)return f;let p=o;return s.has(u)?p=n.getCalendar(d)??o:r.has(u)&&(p=a),c.set(u,p),p}}}}function Bd(e){return{hasChildren(t){return e.hasChildren(t)},getParentStartDateIfHasPredecessors(t){let r=e.getActivity(t);if(!r)return null;let i=e.getParent(r.id);return!i||e.getIncomingLinkIds(i.id).length===0?null:i.startDate},getDescendantIds(t){return Eg(e,t).map(r=>String(r))},getAncestorIds(t){let r=[],i=e.getActivity(t);for(;i;){let n=i.parentId;if(n===null)break;let o=e.getActivity(n);if(!o)break;r.push(String(n)),i=o}return r},getChildProgressInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,progress:Number(n?.progress??0),ponderator:Number(n?.ponderator??0)}})},getChildHhInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,workHours:Number(n?.workHours??0),progress:Number(n?.progress??0),realWorkHours:Number(n?.realWorkHours??0)}})},getChildUsedCostInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,usedCost:Number(n?.usedCost??0)}})},getChildCostInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,cost:Number(n?.cost??0)}})}}}function Eg(e,t){let r=[],i=new xt;for(let n of e.getChildren(t))i.enqueue(n);for(;!i.isEmpty();){let n=i.dequeue();r.push(n);for(let o of e.getChildren(n))i.enqueue(o)}return r}var En=class{_cache={closestWorkTime:new Map,endDate:new Map,duration:new Map};reader;constructor(t){this.reader=t.reader}resolveCalendar(t){let r=Hd(t);return this.reader.getCalendar(r??ti)}getClosestWorkTime(t){let r=`${Ta(t.task)}|${t.dir}|${t.date.getTime()}`;return Sa(this._cache.closestWorkTime,r,()=>this.resolveCalendar(t.task).getClosestWorkTime({direction:t.dir,date:t.date,unit:mt.HOUR}))}calculateEndDate(t){let r=`${Ta(t.task)}|${t.startDate.getTime()}|${t.durationHours}`;return Sa(this._cache.endDate,r,()=>this.resolveCalendar(t.task).calculateEndDate(t.startDate,t.durationHours))}calculateDuration(t){let r=`${Ta(t.task)}|${t.startDate.getTime()}|${t.endDate.getTime()}`;return Sa(this._cache.duration,r,()=>this.resolveCalendar(t.task).calculateDuration(t.startDate,t.endDate))}clearCache(){this._cache.closestWorkTime.clear(),this._cache.endDate.clear(),this._cache.duration.clear()}};function Sa(e,t,r){let i=e.get(t);if(i!==void 0)return i;let n=r();return e.set(t,n),n}var Dg="__default__";function Hd(e){if(!e)return null;let t=e.calendarId;return t==null?null:String(t)}function Ta(e){return Hd(e)??Dg}var Dn=class{constructor(t){this.activities=t}activities;_childrenByParent=new Map;_roots=[];_dirty=!1;markDirty(){this._dirty=!0}getChildren(t){return this._dirty&&(this.rebuild(),this._dirty=!1),this._childrenByParent.get(String(t))??[]}hasChildren(t){return this._dirty&&(this.rebuild(),this._dirty=!1),(this._childrenByParent.get(String(t))?.length??0)>0}getRootIds(){return this._dirty&&(this.rebuild(),this._dirty=!1),[...this._roots]}isChildOf(t,r){let i=this.activities.get(t)?.parentId,n=0,o=this.activities.size;for(;i&&!M(i);){if(i===r)return!0;if(++n>o)return!1;i=this.activities.get(i)?.parentId}return!1}getParent(t){let r=this.activities.get(t)?.parentId;return!r||M(r)?null:this.activities.get(r)??null}getParentId(t){return this.activities.get(t)?.parentId??null}addChild(t,r){if(this._dirty)return;if(M(t)){this._roots.push(r);return}let i=String(t),n=this._childrenByParent.get(i);n?n.push(r):this._childrenByParent.set(i,[r])}rebuild(){this._childrenByParent.clear(),this._roots=[];for(let r of this.activities.values()){if(M(r.parentId)){this._roots.push(r.id);continue}let i=String(r.parentId),n=this._childrenByParent.get(i)??[];n.push(r.id),this._childrenByParent.set(i,n)}let t=(r,i)=>{let n=this.activities.get(r),o=this.activities.get(i);return n&&o?ui(n,o):String(r).localeCompare(String(i))};this._roots.sort(t);for(let r of this._childrenByParent.values())r.sort(t)}};var _n=class{checkedSet=new Set;hiddenSet=new Set;activeFilter=null;activeOrder=null;isChecked(t){return this.checkedSet.has(t)}isVisible(t){return!this.hiddenSet.has(t)}hiddenIds(){return[...this.hiddenSet]}getActiveFilter(){return this.activeFilter}setActiveFilter(t){this.activeFilter=t}getActiveOrder(){return this.activeOrder}setActiveOrder(t){this.activeOrder=t}checkedIds(){return[...this.checkedSet]}checkedCount(){return this.checkedSet.size}setChecked(t,r){return r===this.checkedSet.has(t)?!1:(r?this.checkedSet.add(t):this.checkedSet.delete(t),!0)}setVisible(t,r){return r===!this.hiddenSet.has(t)?!1:(r?this.hiddenSet.delete(t):this.hiddenSet.add(t),!0)}forget(t){this.checkedSet.delete(t),this.hiddenSet.delete(t)}hydrate(t){this.checkedSet=new Set(t.checkedIds??[]),this.hiddenSet=new Set(t.hiddenIds??[]),this.activeFilter=null,this.activeOrder=null}snapshot(){return{checked:new Set(this.checkedSet),hidden:new Set(this.hiddenSet),activeFilter:this.activeFilter,activeOrder:this.activeOrder}}restore(t){this.checkedSet=new Set(t.checked),this.hiddenSet=new Set(t.hidden),this.activeFilter=t.activeFilter,this.activeOrder=t.activeOrder}};var Tr=class e{_activities=new Map;_lastStartDate=new Map;_promotionSnapshot=new Map;_progressFallback=new Map;_links=new Map;_outgoing=new Map;_incoming=new Map;_hierarchy;_buildOrderComparator;_cache={ids:null,visualOrderIds:null,orderComparator:null};_writeCapture=new tn;_viewState=new _n;_filterProjection=null;_viewStateBefore=null;_lastStartDateBefore=null;_promotionSnapshotBefore=null;_calendar;_flags;_calendarSnapshot;constructor(t,r=()=>null){this._buildOrderComparator=r,this._calendarSnapshot=F(t.calendars);for(let i of t.activities)this._activities.set(i.id,i);for(let i of t.links){let n={...i,freeSlackHours:i.freeSlackHours??null,isCritical:i.isCritical===!0};this._links.set(String(i.id),n),this._indexLink(n)}this._calendar=new En(Ud(this._calendarSnapshot)),this._flags=kg(t),this._hierarchy=new Dn(this._activities),this._hierarchy.rebuild()}fork(){let t=new e({activities:this.getAllActivities().map(ae),links:this.getAllLinks().map(r=>({...r})),calendars:F(this._calendarSnapshot)},this._buildOrderComparator);return t._viewState.restore(F(this._viewState.snapshot())),t._lastStartDate=new Map(Array.from(this._lastStartDate,([r,i])=>[r,new Date(i)])),t._promotionSnapshot=new Map(Array.from(this._promotionSnapshot,([r,i])=>[r,F(i)])),t._progressFallback=new Map(this._progressFallback),t._flags=F(this._flags),t._filterProjection=F(this._filterProjection),t}getAllActivities(){return Array.from(this._activities.values())}getAllLinks(){return Array.from(this._links.values())}getAllIds(){return this._cache.ids?this._cache.ids:(this._cache.ids=Array.from(this._activities.keys()),this._cache.ids)}activityCount(){return this._activities.size}getVisualOrderIds(){return this._cache.visualOrderIds?this._cache.visualOrderIds:(this._cache.visualOrderIds=ys(this).map(t=>String(t.id)),this._cache.visualOrderIds)}invalidateVisualOrderIds(){this._cache.visualOrderIds=null}forEachActivity(t){for(let[r,i]of this._activities)t(i,r)}getParentId(t){return this._hierarchy.getParentId(t)}getActivity(t){return this._activities.get(String(t))??null}getLastStartDate(t){return this._lastStartDate.get(String(t))??null}setLastStartDate(t,r){this._captureLastStartDateOnce(),this._lastStartDate.set(String(t),r)}getPromotionSnapshot(t){return this._promotionSnapshot.get(String(t))??null}setPromotionSnapshot(t,r){this._capturePromotionSnapshotOnce(),this._promotionSnapshot.set(String(t),r)}getProgressFallback(t){return this._progressFallback.get(String(t))??null}setProgressFallback(t,r){let i=String(t),n=this._progressFallback.get(i)??null;Object.is(n,r)||(this._writeCapture.noteProgressFallback(i,n),r===null?this._progressFallback.delete(i):this._progressFallback.set(i,r))}_capturePromotionSnapshotOnce(){this._writeCapture.peek()!==null&&this._promotionSnapshotBefore===null&&(this._promotionSnapshotBefore=new Map(this._promotionSnapshot))}_captureLastStartDateOnce(){this._writeCapture.peek()!==null&&this._lastStartDateBefore===null&&(this._lastStartDateBefore=new Map(this._lastStartDate))}getLink(t){return this._links.get(String(t))??null}activityExists(t){return this._activities.has(String(t))}isChecked(t){return this._viewState.isChecked(String(t))}isVisible(t){return this._viewState.isVisible(String(t))}checkedIds(){return this._viewState.checkedIds()}hiddenIds(){return this._viewState.hiddenIds()}setChecked(t,r){return this._captureViewStateOnce(),this._viewState.setChecked(String(t),r)}setVisible(t,r){return this._captureViewStateOnce(),this._viewState.setVisible(String(t),r)}getActiveFilter(){return this._viewState.getActiveFilter()}setActiveFilter(t){this._captureViewStateOnce(),this._viewState.setActiveFilter(t),this._filterProjection=null}getFilterProjection(){return this._filterProjection}setFilterProjection(t){this._filterProjection=t}getActiveOrder(){return this._viewState.getActiveOrder()}setActiveOrder(t){this._captureViewStateOnce(),this._viewState.setActiveOrder(t),this.invalidateDerivedOrder()}getOrderComparator(){let t=this._viewState.getActiveOrder();return t===null?(this._cache.orderComparator=null,null):this._cache.orderComparator?this._cache.orderComparator:(this._cache.orderComparator=this._buildOrderComparator(t),this._cache.orderComparator)}invalidateDerivedOrder(){this._cache.orderComparator=null,this._cache.visualOrderIds=null}hydrateViewState(t){this._viewState.hydrate(t),this._filterProjection=null,this.invalidateDerivedOrder()}_captureViewStateOnce(){this._writeCapture.peek()!==null&&this._viewStateBefore===null&&(this._viewStateBefore=this._viewState.snapshot())}getOutgoingLinkIds(t){return this._outgoing.get(String(t))??Wd}getIncomingLinkIds(t){return this._incoming.get(String(t))??Wd}getChildren(t){return this._hierarchy.getChildren(t)}hasChildren(t){return this._hierarchy.hasChildren(t)}isChildOf(t,r){return this._hierarchy.isChildOf(t,r)}getParent(t){return this._hierarchy.getParent(t)}getRootIds(){return this._hierarchy.getRootIds()}getClosestWorkTime(t){return this._calendar.getClosestWorkTime(t)}calculateEndDate(t){return this._calendar.calculateEndDate(t)}calculateDuration(t){return this._calendar.calculateDuration(t)}clearCalendarCache(){this._calendar.clearCache()}get calendarReader(){return this._calendar.reader}batchUpdate(t){t()}updateActivity(t){}getLiveActivity(t){return this.getActivity(t)}getFlags(){return{...this._flags,allCheckedTaskIds:this._viewState.checkedIds()}}getProjectEnd(){return null}beginWriteCapture(){this._writeCapture.begin(),this._viewStateBefore=null,this._lastStartDateBefore=null,this._promotionSnapshotBefore=null}peekWriteCapture(){return this._writeCapture.peek()}endWriteCapture(){this._writeCapture.end(),this._viewStateBefore=null,this._lastStartDateBefore=null,this._promotionSnapshotBefore=null}setActivityField(t,r,i){let n=this.getActivity(t);n&&(this._writeCapture.note(String(t),n),n[r]=i,Da(n,r),r===x.PARENT&&this._hierarchy.markDirty(),Ea(r)&&(this._cache.visualOrderIds=null))}setActivityFieldDynamic(t,r,i){let n=this.getActivity(t);if(n){if(!Object.hasOwn(n,r))throw new Error(`setActivityFieldDynamic: unknown CoreActivity field "${r}"`);this._writeCapture.note(String(t),n),Reflect.set(n,r,vd(r,i)),Da(n,r),r===x.PARENT&&this._hierarchy.markDirty(),Ea(r)&&(this._cache.visualOrderIds=null)}}setActivityFields(t,r){let i=this.getActivity(t);if(!i)return;this._writeCapture.note(String(t),i);let n=!1;for(let o of Object.keys(r))Reflect.set(i,o,Reflect.get(r,o)),Da(i,o),o===x.PARENT&&(n=!0),Ea(o)&&(this._cache.visualOrderIds=null);n&&this._hierarchy.markDirty()}addLink(t){this._writeCapture.noteLinkAdd(String(t.id));let r=this._links.get(String(t.id));r&&this._deindexLink(r);let i={...t,freeSlackHours:t.freeSlackHours??null,isCritical:t.isCritical===!0};this._links.set(String(t.id),i),this._indexLink(i)}_indexLink(t){Kd(this._outgoing,String(t.source),t.id),Kd(this._incoming,String(t.target),t.id)}_deindexLink(t){let r=this._outgoing.get(String(t.source));r&&this._outgoing.set(String(t.source),Vd(r,t.id));let i=this._incoming.get(String(t.target));i&&this._incoming.set(String(t.target),Vd(i,t.id))}setLinkField(t,r,i){let n=this.getLink(t);n&&(this._writeCapture.noteLinkField(String(t),n),n[r]=i)}setLinkFieldDynamic(t,r,i){if(!_g(r))return;let n=this.getLink(t);n&&(this._writeCapture.noteLinkField(String(t),n),Reflect.set(n,r,i))}setLinkProplannerId(t,r){let i=this.getLink(t);i&&(this._writeCapture.noteLinkField(String(t),i),i.proplannerId=r)}removeLink(t){let r=this.getLink(t);r&&(this._writeCapture.noteLinkRemove(String(t),r),this._links.delete(String(t)),this._deindexLink(r))}addActivity(t){this._writeCapture.noteInsert(String(t.id)),this._activities.set(t.id,t),this._cache.ids=null,this._cache.visualOrderIds=null,this._hierarchy.addChild(t.parentId,t.id)}removeActivity(t){let r=this.getActivity(t);r&&this._writeCapture.noteRemove(String(t),r);let i=String(t);this.setProgressFallback(i,null),(this._viewState.isChecked(i)||!this._viewState.isVisible(i))&&this._captureViewStateOnce(),this._viewState.forget(i),this._activities.delete(t),this._lastStartDate.has(String(t))&&(this._captureLastStartDateOnce(),this._lastStartDate.delete(String(t))),this._outgoing.delete(String(t)),this._incoming.delete(String(t)),this._cache.ids=null,this._cache.visualOrderIds=null,this._hierarchy.markDirty()}noteCorrelativeBefore(t,r){this._writeCapture.noteCorrelativeBefore(t,r)}noteScheduledBefore(t,r){this._writeCapture.noteScheduledBefore(t,r)}restoreFromCapture(){let t=this._writeCapture.peek();if(!t)return;let{ops:r,before:i,correlativeBefore:n,scheduledBefore:o,progressFallbackBefore:a}=t;this._undoLinkAdds(r),this._undoInserts(r),this._reInsertRemovedActivities(r),this._reAddRemovedLinks(r),this._restoreLinkFields(r),this._restoreActivityFields(o),this._restoreActivityFields(i),this._restoreCorrelatives(n),this._restoreProgressFallbacks(a),this._viewStateBefore!==null&&(this._viewState.restore(this._viewStateBefore),this._filterProjection=null,this.invalidateDerivedOrder()),this._promotionSnapshotBefore!==null&&(this._promotionSnapshot=this._promotionSnapshotBefore),this._lastStartDateBefore!==null&&(this._lastStartDate=this._lastStartDateBefore),this._cache.ids=null,this._cache.visualOrderIds=null,this._hierarchy.markDirty()}_restoreProgressFallbacks(t){for(let[r,i]of t)i===null?this._progressFallback.delete(r):this._progressFallback.set(r,i)}_restoreCorrelatives(t){for(let[r,i]of t){let n=this._activities.get(r);n&&(n.correlativeId=i)}}_undoLinkAdds(t){for(let r of t)r.kind===Et.LINK_ADD&&this._detachLink(r.linkId)}_undoInserts(t){for(let r of t)r.kind===Et.INSERT&&this._activities.delete(r.activityId)}_reInsertRemovedActivities(t){for(let r of t)r.kind===Et.REMOVE&&this._activities.set(r.activityId,r.before)}_reAddRemovedLinks(t){for(let r of t)r.kind===Et.LINK_REMOVE&&this._attachLink(r.before)}_restoreLinkFields(t){for(let r of t)r.kind===Et.LINK_FIELD&&this._links.has(r.linkId)&&this._links.set(r.linkId,r.before)}_restoreActivityFields(t){for(let[r,i]of t){let n=this._activities.get(r);n&&this._restoreScalarFields(n,i)}}_restoreScalarFields(t,r){for(let i of Object.keys(t))Object.hasOwn(r,i)||Reflect.deleteProperty(t,i);for(let i of Object.keys(r))Reflect.set(t,i,Reflect.get(r,i))}_attachLink(t){this._links.set(String(t.id),{...t}),this._indexLink(t)}_detachLink(t){let r=this.getLink(t);r&&(this._links.delete(String(t)),this._deindexLink(r))}},Wd=[];function _g(e){return e===jr.LAG||e===jr.TYPE||e===jr.FREE_SLACK_HOURS||e===jr.IS_CRITICAL}function Ea(e){return e===x.PARENT||e===x.CORRELATIVE_ID}function Da(e,t){t!==x.START_DATE&&t!==x.END_DATE&&t!==x.TYPE||(e.calendarDuration=Qt(e))}function Vd(e,t){return e.filter(r=>String(r)!==String(t))}function Kd(e,t,r){let i=e.get(t);i?i.push(r):e.set(t,[r])}function kg(e){let t=e.runtimeFlags??{};return{isPasting:!!t.isPasting,isBulkOperation:!!t.isBulkOperation,dragWithMultiple:!!t.dragWithMultiple,draggingSingleMilestone:!!t.draggingSingleMilestone,creatingActivity:!1,avoidAutoScheduleBeforeDrag:!1,maxPerformance:!!t.maxPerformance,allCheckedTaskIds:[]}}function _a(e,t){let r=e.getActivity(t);return r?F(r):null}function jd(e){return e.getAllActivities().map(F)}function Yd(e){return e.getAllIds().map(String)}function Gd(e,t){e.forEachActivity((r,i)=>t(i))}function $d(e,t){let r=t==="0"?ka(e,"0"):e.getChildren(t),i=[];for(let n of r){let o=e.getActivity(n);o&&i.push(F(o))}return i.sort((n,o)=>(n.correlativeId??0)-(o.correlativeId??0)),i}function ka(e,t){return Ht(t,e)}function zd(e){return e.checkedIds().map(String)}function qd(e,t){if(t==="0"){let r=!1;return e.forEachActivity(i=>{r||=M(i.parentId)}),r}return e.getChildren(t).length>0}function Ra(e,t){let r=e.getLink(t);return r?bt(r):null}function Jd(e){return e.getAllLinks().map(t=>bt(t))}function kn(e){let[t,r]=e.split(":");return Number(t)*60+Number(r??0)}function Rg(e){return e.reduce((t,r)=>kn(r)<kn(t)?r:t)}function Pg(e){return e.reduce((t,r)=>kn(r)>kn(t)?r:t)}function Lg(e){return e.worktime.days.flatMap(t=>Array.isArray(t)?t:t===!0?e.worktime.hours:[])}function Xd(e){let t=[...e].find(o=>o.is_default);if(!t)return null;let r=Lg(t);if(r.length===0)return null;let i=r.map(o=>o.split("-")[0]),n=r.map(o=>o.split("-")[1]);return{startHour:Rg(i),endHour:Pg(n)}}function Pa(e,t){return{calendars:e.calendarReader,hierarchy:Bd(e),activityReader:Md(e),dateFormat:t.dateFormat??"YYYY-MM-DD",customHours:t.customHours??{},hoursPerDay:t.hoursPerDay}}function Zd(e){return We(e)}var Og=new Set(["freeSlackHours","isCritical"]);function Ng(e,t){let r=Object.fromEntries(Object.entries(e.fields??{}).filter(([i])=>!t.has(i)));return e.kind===N.UPDATED&&Object.keys(r).length===0?null:{...e,...e.fields===void 0?{}:{fields:r},after:null}}function ru(e){let t=e.activities.map(n=>({...n,after:null})),r=e.links.map(n=>Ng(n,Og)).filter(n=>n!==null),i=e.source.kind===ue?{...e.source,items:[],links:[]}:e.source;return F({...e,source:i,activities:t,links:r})}function La(e,t,r,i,n,o,a){return{changeSet:e,beforeSnap:t,beforeLinks:Qd(r),afterSnap:i,afterLinks:Qd(n),progressFallbackBefore:o,progressFallbackAfter:a}}function Qd(e){if(e)return new Map(Array.from(e,([t,r])=>[t,{...r,freeSlackHours:null,isCritical:!1}]))}function iu(e,t){let r=new Map,i=new Map;for(let n of t.activities){if(n.kind!==N.CREATED)continue;let o=e.getActivity(String(n.id));o&&r.set(String(n.id),et(o))}for(let n of t.links){if(n.kind===N.DELETED)continue;let o=e.getLink(String(n.id));o&&i.set(String(n.id),{...o})}return{afterSnap:r,afterLinks:i}}function nu(e){return e.kind!==m.INLINE_EDIT||!qr.has(e.column)?null:`inline-edit:${String(e.activityId)}:${e.column}`}function tu(e){return e.changeSet.activities.length===1&&e.changeSet.activities[0]?.kind===N.UPDATED&&e.changeSet.links.length===0&&!e.beforeSnap?.size&&!e.afterSnap?.size}function ou(e,t){if(!tu(e)||!tu(t))return!1;let r=e.changeSet.activities[0],i=t.changeSet.activities[0];return!!r&&!!i&&String(r.id)===String(i.id)}function au(e,t){let r=e.changeSet.activities[0],i=t.changeSet.activities[0];if(!r||!i)return t;let n=r.fields??{},o=i.fields??{},a={};for(let c of new Set([...Object.keys(n),...Object.keys(o)])){let l=n[c],d=o[c];a[c]={before:l?l.before:d?.before,after:d?d.after:l?.after}}let s={...t.changeSet,activities:[{...i,fields:a}]};return La(s)}var Er={RECORD:"record",SKIP:"skip",CHECKPOINT_ON_SUCCESS:"checkpoint-on-success"},ct={BEFORE:"before",AFTER:"after"};function su(e){return e.kind===m.PERSISTENCE_ACKNOWLEDGE?Er.CHECKPOINT_ON_SUCCESS:e.kind===m.SIR_SYNC||e.kind===m.CALENDAR_RECONCILE||e.kind===m.ACTIVITY_LOOKAHEAD_SYNC||e.kind===m.BASELINE_APPLY||e.kind===m.PONDERATOR_CRITERION_SET||e.kind===m.STATUS_CRITERIA_SET||e.kind===m.ACTIVITY_CLIPBOARD_CLEAR||e.kind===m.ACTIVITY_COPY||e.kind===m.SELECTION_TOGGLE||e.kind===m.SELECTION_REPLACE||e.kind===m.VISIBILITY_SET||e.kind===m.FILTER_SET||e.kind===m.SORT_SET?Er.SKIP:Er.RECORD}function Oa(e){for(let t of e.changeSet.activities)if(t.kind===N.CREATED||t.kind===N.DELETED||t.kind===N.UPDATED&&t.fields&&_.CUSTOM_ID in t.fields)return!0;return!1}function Na(e,t,r){let i=[],n=[];for(let a of t.changeSet.activities){let s=String(a.id);if(a.kind===N.UPDATED){let c=e.getActivity(s);i.push({id:s,kind:N.UPDATED,fields:eu(a.fields,r),after:c?et(c):null})}else if(a.kind===N.DELETED)if(r===ct.BEFORE){let c=e.getActivity(s);i.push({id:s,kind:N.CREATED,after:c?et(c):null})}else i.push({id:s,kind:N.DELETED,after:null});else if(r===ct.BEFORE)i.push({id:s,kind:N.DELETED,after:null});else{let c=e.getActivity(s);i.push({id:s,kind:N.CREATED,after:c?et(c):null})}}for(let a of t.changeSet.links){let s=String(a.id);if(a.kind===N.UPDATED){let c=e.getLink(s);n.push({id:s,kind:N.UPDATED,fields:eu(a.fields,r),after:c?bt(c):null})}else if(a.kind===N.DELETED)if(r===ct.BEFORE){let c=e.getLink(s);n.push({id:s,kind:N.CREATED,after:c?bt(c):null})}else n.push({id:s,kind:N.DELETED,after:null});else if(r===ct.BEFORE)n.push({id:s,kind:N.DELETED,after:null});else{let c=e.getLink(s);n.push({id:s,kind:N.CREATED,after:c?bt(c):null})}}let o=(t.changeSet.viewState??[]).map(a=>r===ct.BEFORE?bg(a):a);return{source:{kind:r===ct.BEFORE?oe.UNDO:oe.REDO},activities:i,links:n,calendars:[],trackingEvents:[],effects:[],viewState:o}}function eu(e,t){if(e!=null)return Object.fromEntries(Object.entries(e).map(([r,i])=>[r,t===ct.BEFORE?{before:F(i.after),after:F(i.before)}:{before:F(i.before),after:F(i.after)}]))}function bg(e){return{activityId:e.activityId,...e.checked?{checked:{before:e.checked.after,after:e.checked.before}}:{},...e.visible?{visible:{before:e.visible.after,after:e.visible.before}}:{}}}function ba(e){return e.activities.length>0||e.links.length>0||(e.viewState?.length??0)>0||(e.effects?.length??0)>0}function cu(e,t){du(e,t,ct.BEFORE)}function lu(e,t){du(e,t,ct.AFTER)}function du(e,t,r){let i=t.changeSet;for(let o of i.activities)if(o.kind===N.UPDATED){if(!o.fields)continue;for(let[a,s]of Object.entries(o.fields))yt(e,o.id,a,r===ct.BEFORE?s.before:s.after)}else if(o.kind===N.DELETED)if(r===ct.BEFORE){let a=t.beforeSnap?.get(String(o.id));if(!a)throw new Error(`undo: missing beforeSnap for resurrecting activity ${o.id}`);e.addActivity(et(a))}else e.removeActivity(String(o.id));else if(r===ct.BEFORE)e.removeActivity(String(o.id));else{let a=t.afterSnap?.get(String(o.id));if(!a)throw new Error(`redo: missing afterSnap for re-creating activity ${o.id}`);e.addActivity(et(a))}for(let o of i.links)if(o.kind===N.UPDATED){if(!o.fields)continue;if(Object.hasOwn(o.fields,"source")||Object.hasOwn(o.fields,"target")){let a=r===ct.BEFORE?t.beforeLinks?.get(String(o.id)):t.afterLinks?.get(String(o.id));if(!a)throw new Error(`${r===ct.BEFORE?"undo":"redo"}: missing link snapshot for ${o.id}`);e.removeLink(String(o.id)),e.addLink({...a});continue}for(let[a,s]of Object.entries(o.fields))Dc(e,String(o.id),a,r===ct.BEFORE?s.before:s.after)}else if(o.kind===N.DELETED)if(r===ct.BEFORE){let a=t.beforeLinks?.get(String(o.id));if(!a)throw new Error(`undo: missing beforeLinks for re-adding link ${o.id}`);e.addLink(a)}else e.removeLink(String(o.id));else if(r===ct.BEFORE)e.removeLink(String(o.id));else{let a=t.afterLinks?.get(String(o.id));if(!a)throw new Error(`redo: missing afterLinks for re-creating link ${o.id}`);e.addLink(a)}for(let o of i.viewState??[])o.checked&&e.setChecked(o.activityId,r===ct.BEFORE?o.checked.before:o.checked.after),o.visible&&e.setVisible(o.activityId,r===ct.BEFORE?o.visible.before:o.visible.after);let n=r===ct.BEFORE?t.progressFallbackBefore:t.progressFallbackAfter;for(let[o,a]of n??[])e.setProgressFallback(o,a)}var Fg=100,wg=600,Rn=class e{constructor(t=Fg){this.maxDepth=t}maxDepth;undoStack=[];redoStack=[];sequence=0;_lastKey=null;_lastTime=0;fork(){let t=new e(this.maxDepth);return t.undoStack.push(...F(this.undoStack)),t.redoStack.push(...F(this.redoStack)),t.sequence=this.sequence,t._lastKey=this._lastKey,t._lastTime=this._lastTime,t}record(t,r=null,i=0){let n=this.undoStack[this.undoStack.length-1];r!=null&&r===this._lastKey&&i-this._lastTime<=wg&&n!==void 0&&ou(n.entry,t)?(n.entry=au(n.entry,t),n.touchedAt=this.touch()):(this.undoStack.push({entry:t,touchedAt:this.touch()}),this.undoStack.length>this.maxDepth&&this.undoStack.splice(0,this.undoStack.length-this.maxDepth)),this._lastKey=r,this._lastTime=i,this.redoStack.length=0}resetCoalesce(){this._lastKey=null}takeUndo(){return this.undoStack.pop()?.entry??null}takeRedo(){return this.redoStack.pop()?.entry??null}pushRedo(t){this.redoStack.push({entry:t,touchedAt:this.touch()})}pushUndo(t){this.undoStack.push({entry:t,touchedAt:this.touch()})}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undoDepth(){return this.undoStack.length}capturePersistenceBoundary(){return this.resetCoalesce(),this.sequence}discardThrough(t){this.removeEntriesThrough(this.undoStack,t),this.removeEntriesThrough(this.redoStack,t),this.resetCoalesce()}applyPersistedIdentities(t,r){let i=new Map(t.map(({id:o,proplannerId:a})=>[String(o),a])),n=new Map(r.map(({id:o,proplannerId:a})=>[String(o),a]));for(let o of[...this.undoStack,...this.redoStack])o.entry=this.withPersistedIdentities(o.entry,i,n)}clear(){this.undoStack.length=0,this.redoStack.length=0,this.resetCoalesce()}touch(){return this.sequence+=1,this.sequence}removeEntriesThrough(t,r){let i=t.filter(({touchedAt:n})=>n>r);t.splice(0,t.length,...i)}withPersistedIdentities(t,r,i){let n=a=>a===void 0?void 0:new Map(Array.from(a,([s,c])=>[s,r.has(s)?{...c,proplannerId:r.get(s)}:c])),o=a=>a===void 0?void 0:new Map(Array.from(a,([s,c])=>[s,i.has(s)?{...c,proplannerId:i.get(s)}:c]));return{...t,beforeSnap:n(t.beforeSnap),afterSnap:n(t.afterSnap),beforeLinks:o(t.beforeLinks),afterLinks:o(t.afterLinks)}}};var xg=["parentId","correlativeId"];function fu(e,t){let r=new Set,i=n=>{let o=t(n);r.add(o===null?"0":String(o))};for(let n of e.activities){let o=String(n.id);if(n.kind===N.CREATED){i(o);continue}if(n.kind===N.DELETED){let c=n.fields;c&&"parentId"in c&&r.add(uu(c.parentId?.before));continue}let a=n.fields;!a||!xg.some(c=>c in a)||(i(o),"parentId"in a&&r.add(uu(a.parentId?.before)))}return r}function uu(e){return e==null?"0":String(e)}function Mg(e){return{...e,id:String(e.id),source:String(e.source),target:String(e.target),type:e.type,lag:Number(e.lag)}}function Ug(e){return{days:e.days,hours:e.hours,...e.dates?{dates:e.dates}:{},...e.customWeeks?{customWeeks:e.customWeeks}:{}}}function pu(e){return{id:String(e.id),worktime:Ug(e.worktime)}}function Pn(e,t,r,i=[]){let n=t.map(Mg),o=[...r.map(pu),...i.map(pu)];return{activities:[...e],links:n,calendars:o}}var w={TRACKED:"tracked",IGNORED:"ignored"};var yu={id:w.IGNORED,proplannerId:w.IGNORED,parentId:w.TRACKED,name:w.TRACKED,description:w.TRACKED,type:w.TRACKED,startDate:w.TRACKED,endDate:w.TRACKED,durationHours:w.TRACKED,constraintType:w.TRACKED,constraintDate:w.TRACKED,autoScheduling:w.TRACKED,calendarId:w.TRACKED,assignedDefaultCalendar:w.IGNORED,dateOrigin:w.TRACKED,progress:w.TRACKED,cost:w.TRACKED,usedCost:w.TRACKED,realCost:w.TRACKED,workHours:w.TRACKED,realWorkHours:w.TRACKED,ponderator:w.TRACKED,hasCustomPonderator:w.TRACKED,correlativeId:w.TRACKED,uniqueCorrelativeId:w.TRACKED,customId:w.TRACKED,subcontractId:w.TRACKED,isLookahead:w.TRACKED,hasLookaheadTasks:w.IGNORED,newActivityIds:w.TRACKED,hasNewActivities:w.TRACKED,isNewActivity:w.IGNORED,pendingRequestIds:w.IGNORED,responsableIds:w.TRACKED,tagIds:w.TRACKED,baselinePoints:w.IGNORED,baselineSnapshot:w.IGNORED,recursiveDurationHours:w.IGNORED,isCritical:w.IGNORED,freeSlackHours:w.IGNORED,calendarDuration:w.IGNORED,expectedProgress:w.IGNORED,expectedProgressBaseline:w.IGNORED,status:w.IGNORED,criticalPath:w.IGNORED},hu=Object.keys(yu).filter(e=>yu[e]===w.TRACKED),mu=new Set(["startDate","endDate","constraintDate","dateOrigin"]),Iu=new Set(["newActivityIds","responsableIds","tagIds"]);function gu(e){let t=hu.map(r=>[r,Bg(r,e[r])]);return Object.fromEntries(t)}function Bg(e,t){return mu.has(e)?t instanceof Date?new Date(t):null:Iu.has(e)?Array.isArray(t)?[...t]:[]:t}function ei(e,t){return Fa(e,t).length>0}function Fa(e,t){return hu.filter(r=>!Hg(r,e[r],t[r]))}function Hg(e,t,r){return mu.has(e)?Wg(t,r):Iu.has(e)?Vg(t,r):(t??null)===(r??null)}function Wg(e,t){let r=e instanceof Date?e.getTime():null,i=t instanceof Date?t.getTime():null;return r===i}function Vg(e,t){let r=new Set(Array.isArray(e)?e.map(String):[]),i=new Set(Array.isArray(t)?t.map(String):[]);if(r.size!==i.size)return!1;for(let n of r)if(!i.has(n))return!1;return!0}var Au={id:w.IGNORED,source:w.TRACKED,target:w.TRACKED,type:w.TRACKED,lag:w.TRACKED,freeSlackHours:w.IGNORED,isCritical:w.IGNORED,ganttId:w.IGNORED,sectorId:w.IGNORED,proplannerId:w.IGNORED},Kg=Object.keys(Au).filter(e=>Au[e]===w.TRACKED);function Ln(e,t){return Kg.some(r=>e[r]!==t[r])}function vu(e,t){let r=new Map(e.map(i=>[String(i.id),i]));return t.filter(i=>{let n=r.get(String(i.id));return n?Ln(n,i):!1})}function Xt(e){if(e==null||e===0)return!1;if(!(typeof e=="number"&&Number.isSafeInteger(e)&&e>0))throw new Error(`invalid proplannerId ${String(e)}`);return!0}function Cu(e,t){for(let r of e)Xt(r.proplannerId);for(let r of t)Xt(r.proplannerId)}var On=class e{trackingEnabled;initialized=!1;dirtyActivityIds=new Set;dirtyLinkIds=new Set;initialCalendarRepairIds=new Set;linksAtLastSave=new Map;activitiesAtLastSave=new Map;constructor(t=!0){this.trackingEnabled=t}fork(){let t=new e(!1);t.initialized=this.initialized;for(let[r,i]of this.linksAtLastSave)t.linksAtLastSave.set(r,F(i));for(let[r,i]of this.activitiesAtLastSave)t.activitiesAtLastSave.set(r,F(i));return t}init(t,r){if(this.trackingEnabled){Cu(t,r),this.snapshotActivities(t),this.snapshotLinks(r);for(let i of t)if(i.assignedDefaultCalendar){let n=String(i.id);this.initialCalendarRepairIds.add(n),this.dirtyActivityIds.add(n)}this.initialized=!0}}acknowledge(t,r,i=[],n=[],o,a){if(!this.trackingEnabled)return;let s=new Map(i.map(({id:p,proplannerId:y})=>[String(p),y])),c=new Map(n.map(({id:p,proplannerId:y})=>[String(p),y])),l=t.map(p=>({...p,proplannerId:s.get(String(p.id))??p.proplannerId})),d=r.map(p=>{let y=c.get(String(p.id));return y===void 0?{...p}:{...p,proplannerId:y}});if(Cu(l,d),this.snapshotActivities(l),this.snapshotLinks(d),!o||!a)return;let u=new Map(o.map(p=>[String(p.id),p])),f=new Map(a.map(p=>[String(p.id),p]));for(let p of l){let y=String(p.id);this.activityIsDirty(y,u.get(y)??null)&&this.dirtyActivityIds.add(y)}for(let p of o){let y=String(p.id);this.activityIsDirty(y,p)&&this.dirtyActivityIds.add(y)}for(let p of d){let y=String(p.id);this.linkIsDirty(y,f.get(y)??null)&&this.dirtyLinkIds.add(y)}for(let p of a){let y=String(p.id);this.linkIsDirty(y,p)&&this.dirtyLinkIds.add(y)}}snapshotActivities(t){if(this.trackingEnabled){this.activitiesAtLastSave.clear(),this.dirtyActivityIds.clear(),this.initialCalendarRepairIds.clear();for(let r of t){let i=String(r.id);if(!Xt(r.proplannerId)){this.dirtyActivityIds.add(i);continue}let n=gu(r);this.activitiesAtLastSave.set(String(r.id),{persistable:n,deletedSnapshot:{id:r.id,proplannerId:r.proplannerId,parentId:r.parentId,hadBaseline:r.baselineSnapshot!==null||r.baselinePoints.length>0}}),ei(r,n)&&this.dirtyActivityIds.add(i)}}}snapshotLinks(t){if(this.trackingEnabled){this.linksAtLastSave.clear(),this.dirtyLinkIds.clear();for(let r of t){let i=String(r.id);if(!Xt(r.proplannerId)){this.dirtyLinkIds.add(i);continue}this.linksAtLastSave.set(String(r.id),{id:r.id,proplannerId:r.proplannerId,source:r.source,target:r.target,lag:r.lag,type:r.type})}}}recordChanges(t,r,i,n){if(!(!this.trackingEnabled||!this.initialized)){for(let o of t){let a=String(o.id),s=i(a);this.activityIsDirty(a,s)?this.dirtyActivityIds.add(a):this.dirtyActivityIds.delete(a)}for(let o of r){let a=String(o.id),s=n(a);this.linkIsDirty(a,s)?this.dirtyLinkIds.add(a):this.dirtyLinkIds.delete(a)}}}activityIsDirty(t,r){let i=this.activitiesAtLastSave.get(t);return r===null?i!==void 0:this.initialCalendarRepairIds.has(t)||!Xt(r.proplannerId)||i===void 0||ei(r,i.persistable)}linkIsDirty(t,r){let i=this.linksAtLastSave.get(t);return r===null?i!==void 0:!Xt(r.proplannerId)||i===void 0||Ln(i,r)}acknowledgePersistedLookahead(t,r){if(!this.trackingEnabled||!this.initialized)return;let i=t.map(n=>{let o=typeof n=="string"?n:String(n.id),a=r(o),s=this.activitiesAtLastSave.get(o);if(a===null||s===void 0)throw new Error(`unknown persisted activity "${o}"`);return{activityId:o,acknowledgesLookahead:typeof n=="string"||!!n.fields?.isLookahead,acknowledgesProgress:typeof n!="string"&&!!n.fields?.progress,current:a,saved:s}});for(let{activityId:n,acknowledgesLookahead:o,acknowledgesProgress:a,current:s,saved:c}of i){let l={...c.persistable,...o?{isLookahead:s.isLookahead}:{},...a?{progress:s.progress,autoScheduling:s.autoScheduling}:{}};this.activitiesAtLastSave.set(n,{...c,persistable:l}),this.initialCalendarRepairIds.has(n)||!Xt(s.proplannerId)||ei(s,l)?this.dirtyActivityIds.add(n):this.dirtyActivityIds.delete(n)}}hasCheckpointActivityId(t){return this.activitiesAtLastSave.has(t)}hasCheckpointLinkId(t){return this.linksAtLastSave.has(t)}hasUnsavedChanges(){return this.trackingEnabled&&this.initialized&&(this.dirtyActivityIds.size>0||this.dirtyLinkIds.size>0)}newActivities(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyActivityIds){let n=t(i);n!==null&&!Xt(n.proplannerId)&&r.push(n)}return r}newLinks(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyLinkIds){let n=t(i);n!==null&&!Xt(n.proplannerId)&&r.push(n)}return r}deletedActivities(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyActivityIds){let n=this.activitiesAtLastSave.get(i);n&&t(i)===null&&r.push({...n.deletedSnapshot})}return r}deletedLinks(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyLinkIds){let n=this.linksAtLastSave.get(i);n&&t(i)===null&&r.push({...n})}return r}modifiedActivities(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyActivityIds){let n=t(i);if(n===null||!Xt(n.proplannerId))continue;let o=this.activitiesAtLastSave.get(i);(o===void 0||this.initialCalendarRepairIds.has(i)||ei(n,o.persistable))&&r.push(n)}return r}modifiedActivityFields(t){let r=new Map;if(!this.trackingEnabled||!this.initialized)return r;for(let i of this.dirtyActivityIds){let n=t(i),o=this.activitiesAtLastSave.get(i);if(!n||!o)continue;let a=Fa(n,o.persistable);a.length>0&&r.set(i,a)}return r}modifiedLinks(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyLinkIds){let n=t(i);if(n===null||!Xt(n.proplannerId))continue;let o=this.linksAtLastSave.get(i);(o===void 0||Ln(o,n))&&r.push(n)}return r}clear(){this.initialized=!1,this.dirtyActivityIds.clear(),this.dirtyLinkIds.clear(),this.initialCalendarRepairIds.clear(),this.linksAtLastSave.clear(),this.activitiesAtLastSave.clear()}};var Su=1440*60*1e3,Tu=/^(\d{4})[/-](\d{1,2})[/-](\d{1,2})/,Nn=7,wa=[!1,!0,!0,!0,!0,!0,!1],Eu=new Set(["1","true"]),xa=gt.DURATION,Du=A.ASAP,_u={ASAP:A.ASAP,ALAP:A.ALAP,SNET:A.SNET,SNLT:A.SNLT,FNET:A.FNET,FNLT:A.FNLT,MSO:A.MSO,MFO:A.MFO,"AS SOON AS POSSIBLE":A.ASAP,"AS LATE AS POSSIBLE":A.ALAP,"START NO EARLIER THAN":A.SNET,"START NO LATER THAN":A.SNLT,"FINISH NO EARLIER THAN":A.FNET,"FINISH NO LATER THAN":A.FNLT,"MUST START ON":A.MSO,"MUST FINISH ON":A.MFO};function ku(e,t){let r=[],i=e.map(o=>{let a=Qg(o,t);return o.should_be_showed===!1&&r.push(a.id),a});eA(i);let n=new Set(i.map(o=>o.id));return rA(i,n,t.reporter,t.recordDiagnostic),{activities:i,activityIds:n,hiddenIds:r}}function jg(e,t,r,i){if(!e)return null;let n=_u[e.toUpperCase()];return n===void 0?(r(Pt.UNKNOWN_CONSTRAINT,i),t.warn(`[parseFromBackend] unknown constraint label "${e}" \u2014 defaulting to "asap"`),Du):n}function Yg(e,t,r){let i=jg(e.constraint,t,r,String(e.unique_id)),o=i!==A.ASAP&&i!==A.ALAP&&e.constraint_date?se(e.constraint_date):null;return{constraintType:i,constraintDate:o}}function Gg(e,t,r){if(e==null)return r;let i=String(e);return t.has(i)?i:r}function $g(e){if(e==null||e==="")return[];if(Array.isArray(e))return e.map(String);if(typeof e!="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(String):[]}catch{return[]}}function zg(e){if(typeof e!="object"||e===null||!("id"in e))return!1;let t=e.id;return typeof t=="string"||typeof t=="number"}function Ma(e){if(!Array.isArray(e))return[];let t=[];for(let r of e)zg(r)&&t.push(String(r.id));return t}function qg(e){return e==="0"?null:String(e)}function Jg(e){if(e==null)return null;if(!(typeof e=="number"&&(e===0||Number.isSafeInteger(e)&&e>0)))throw new Error(`invalid activity proplannerId ${String(e)}`);return e}function Xg(e,t){return typeof e.is_critical=="boolean"?e.is_critical:(t.error("[parseFromBackend] invalid activity is_critical \u2014 defaulting to false",new TypeError(`activity "${e.unique_id}" received ${typeof e.is_critical}`)),!1)}function Zg(e,t,r,i){return Array.isArray(e)?e.map(n=>An(n,t,{record:r,sampleId:i})).filter(n=>n!==null):[]}function Qg(e,t){let r=Gg(e.calendarId,t.knownCalendarIds,t.defaultCalendarId),i=e.calendarId==null||!t.knownCalendarIds.has(String(e.calendarId)),n=Number(e.progress),{constraintType:o,constraintDate:a}=Yg(e,t.reporter,t.recordDiagnostic),s=e.type===D.MILESTONE,c=se(e.start_date),l=s?c:se(e.end_date),d=s?0:Number(e.duration),u=Xg(e,t.reporter);return{id:String(e.unique_id),proplannerId:Jg(e.id),parentId:qg(e.parent_id),name:e.name,description:e.description??"",type:e.type,startDate:c,endDate:l,durationHours:be(d,t.hoursPerDay),constraintType:o,constraintDate:a,autoScheduling:Le(n),calendarId:r,assignedDefaultCalendar:r!=null&&i,dateOrigin:e.date_origin==null?null:se(e.date_origin),progress:n,cost:Number(e.cost),usedCost:Number(e.used_cost??0),realCost:Number(e.real_cost??0),workHours:Number(e.hhWorkTime),realWorkHours:Number(e.real_work??0),ponderator:Number(e.ponderator??0),hasCustomPonderator:e.hasCustomPonderator,correlativeId:e.correlative_id,uniqueCorrelativeId:e.unique_correlative_id,customId:tA(e),subcontractId:e.subcontractId,isLookahead:e.isOnLookahead,hasLookaheadTasks:Array.isArray(e.tasks)&&e.tasks.length>0,newActivityIds:$g(e.newActivitiesArray),hasNewActivities:e.hasNewActivities??!1,...e.isNewActivity===!0?{isNewActivity:!0}:{},pendingRequestIds:Ma(e.pendingRequests),responsableIds:Ma(e.responsables),tagIds:Ma(e.tags),baselinePoints:Zg(e.baseline_points,t.reporter,t.recordDiagnostic,String(e.unique_id)),baselineSnapshot:null,recursiveDurationHours:be(Number(e.sumOfDurationRecursively??0),t.hoursPerDay),calendarDuration:Qt({type:e.type,startDate:c,endDate:l}),isCritical:u,freeSlackHours:null,expectedProgress:null,expectedProgressBaseline:null,status:null,criticalPath:null}}function tA(e){return e.has_childs?null:e.custom_id}function eA(e){let t=e.find(r=>r.correlativeId===0&&r.type===D.PROJECT);t&&(t.parentId=null)}function rA(e,t,r,i){for(let n of e)n.parentId!==null&&(t.has(n.parentId)||(r.warn(`[parseFromBackend] activity "${n.id}" references unknown parent "${n.parentId}" \u2014 re-parenting to root (null)`),i(Pt.ORPHAN_ACTIVITY,n.id),n.parentId=null))}function Ou(e,t,r,i=null){let a=(e!==void 0&&e.length>0?e:t??[]).map(c=>nA(c,i)),s=(r??[]).map(c=>oA(c,i));return{calendars:a,baseCalendars:s,knownCalendarIds:new Set(a.map(c=>c.id)),defaultCalendarId:iA(a)}}function iA(e){let t=e.find(i=>i.is_default);if(t)return t.id;let r=e[0];return r?r.id:null}function Nu(e,t){let r=uA(e.working_days),{days:i,hours:n}=dA(e,r),o=aA(t.exceptionsSource,t.exceptionRange),a={days:i,hours:n};return o&&(a.dates=o),{id:`${String(e.id)}${t.idSuffix}`,name:e.name,is_default:t.isDefault,...t.baseDefault!==void 0?{baseDefault:t.baseDefault}:{},worktime:a}}function nA(e,t){let r=e.baseDefault,i=typeof r=="boolean"?r:void 0;return Nu(e,{idSuffix:"",isDefault:!!e.is_default,baseDefault:i,exceptionsSource:e.exceptiondays,exceptionRange:t})}function oA(e,t){return Nu(e,{idSuffix:"-base",isDefault:!1,baseDefault:!!e.is_default,exceptionsSource:e.baseexceptiondays??e.exceptiondays,exceptionRange:t})}function aA(e,t){if(!Array.isArray(e)||e.length===0)return null;let r={};for(let i of e){if(!i)continue;let n=sA(i.from_date,i.to_date,t);if(n.length===0)continue;let o=cA(i);if(o!==void 0)for(let a of n)r[a]=o}return Object.keys(r).length>0?r:null}function sA(e,t,r){let i=Ru(e),n=Ru(t);if(i===null||n===null)return[];if(r&&(n<r.start||i>r.end))return[];let o=[],a=r?Math.max(i,r.start):i,s=r?Math.min(n,r.end):n;for(;a<=s;)o.push(String(a)),a+=Su;return o}function Ru(e){if(typeof e!="string")return null;let t=Tu.exec(e.trim());if(!t)return null;let r=Number(t[1]),i=Number(t[2]),n=Number(t[3]);return Number.isFinite(r)&&Number.isFinite(i)&&Number.isFinite(n)?Date.UTC(r,i-1,n):null}function cA(e){if(e.workable===!1)return!1;let t=e.shifts;if(Array.isArray(t)&&t.length>0){let r=lA(t);if(r.length>0)return r}}var Pu=/^\d{1,2}:\d{2}$/;function lA(e){let t=[];for(let r of e){let i=wu(r?.shift_string);if(!i)continue;if(!i.startsCsv.includes(",")&&!i.endsCsv.includes(",")){let s=i.startsCsv.trim(),c=i.endsCsv.trim();!bn(s)&&!bn(c)&&Pu.test(s)&&Pu.test(c)&&t.push(`${s}-${c}`);continue}let a=Fu(i.startsCsv,i.endsCsv).find(s=>s!==null);a&&t.push(a)}return t.sort(bu),t}function Lu(e){let t=e.indexOf("-"),r=t>0?e.slice(0,t):e,[i,n]=r.split(":");return(Number(i)||0)*60+(Number(n)||0)}function bu(e,t){return Lu(e)-Lu(t)}function dA(e,t){let r=Array.from({length:7},()=>[]),i=(l,d)=>{let u=Fu(l,d);for(let f=0;f<7;f+=1){let p=u[f],y=r[f];p&&y&&y.push(p)}},n=Array.isArray(e.shifts)&&e.shifts.length>0,o=typeof e.shift_start=="string"&&typeof e.shift_end=="string";if(n)for(let l of e.shifts){let d=wu(l?.shift_string);d&&i(d.startsCsv,d.endsCsv)}else o&&i(e.shift_start,e.shift_end);for(let l of r)l.sort(bu);let s=r.find((l,d)=>!!t[d]&&l.length>0)??[];return{days:t.map((l,d)=>{if(!l)return!1;let u=r[d];return u&&u.length>0?u:s}),hours:s}}function Fu(e,t){let r=Array.from({length:Nn},()=>null);if(typeof e!="string"||typeof t!="string")return r;let i=e.split(",").map(s=>s.trim()),n=t.split(",").map(s=>s.trim());if(!(i.length===n.length&&i.length>0&&i.length<=Nn))return r;let a=[...r];for(let s=0;s<i.length;s+=1){let c=i[s],l=n[s];bn(c)||bn(l)||(a[s]=`${c}-${l}`)}return a}function wu(e){if(typeof e!="string")return null;let t=e.indexOf("-");return t<=0?null:{startsCsv:e.slice(0,t),endsCsv:e.slice(t+1)}}function uA(e){if(typeof e!="string")return[...wa];let t=e.split(",").map(r=>r.trim());return t.length!==Nn?[...wa]:t.map(r=>Eu.has(r))}var fA=new Set(["false","null"]);function bn(e){return!e||fA.has(e)}function pA(e){if(typeof e!="string")return null;let t=Bs(e);return t||(ai(e)?e:null)}function yA(e){if(e==null)return;if(!(typeof e=="number"&&(e===0||Number.isSafeInteger(e)&&e>0)))throw new Error(`invalid link proplannerId ${String(e)}`);return e}function Mu(e,t){let r=[];for(let i of e)try{r.push(hA(i,t.knownActivityIds,t.hoursPerDay))}catch(n){t.recordDiagnostic(Pt.INVALID_LINK,String(i.unique_id??i.id)),t.reporter.warn("[parseFromBackend] dropping invalid link",n)}return mA(r,t.recordDiagnostic)}function hA(e,t,r){let i=String(e.unique_id??e.id),n=String(e.source_id??e.source??""),o=String(e.target_id??e.target??"");if(!t.has(n))throw new Error(`[parseFromBackend] link "${i}" source "${n}" does not exist`);if(!t.has(o))throw new Error(`[parseFromBackend] link "${i}" target "${o}" does not exist`);let a=pA(e.type);if(a===null)throw new Error(`[parseFromBackend] link "${i}" has invalid type "${String(e.type)}"`);let s=e.ganttId,c=e.sectorId,l=yA(e.id);return{id:i,source:n,target:o,type:a,lag:Wt(Number(e.lag??0),r),freeSlackHours:null,isCritical:!1,...typeof s=="number"?{ganttId:s}:{},...typeof c=="number"?{sectorId:c}:{},...l===void 0?{}:{proplannerId:l}}}function mA(e,t){let r=new Map;for(let i of e){let n=`${i.source}-${i.target}-${i.type}`,o=r.get(n);if(!o){r.set(n,i);continue}let a=xu(i)>xu(o),s=a?o:i;t(Pt.DUPLICATE_LINK,s.id),a&&r.set(n,i)}return[...r.values()]}function xu(e){let t=Number(e.id);return Number.isFinite(t)?t:-1/0}function IA(e){if(typeof e!="string")return xa;switch(e.toUpperCase()){case gt.DURATION:return gt.DURATION;case gt.COST:return gt.COST;case gt.WORK_HOURS:return gt.WORK_HOURS;default:return xa}}function gA(e){let t=e.custom_id_prefix;return typeof t=="string"&&t.length>0?t:void 0}function AA(e){let t=e.custom_id_increment;return typeof t=="string"?t:typeof t=="number"&&Number.isFinite(t)?String(t):void 0}function Uu(e){let t=gA(e),r=AA(e),i=e.update_duration_for_primavera_for_end_date===!0;return{id:String(e.id),name:e.name,hoursPerDay:e.hoursPerDay,hoursPerWeek:e.hoursPerWeek,dateFormat:e.dateFormat,projectId:e.projectId,companyId:e.companyId,...t!==void 0?{customIdPrefix:t}:{},...r!==void 0?{customIdIncrement:r}:{},...i?{updateDurationForPrimaveraEndDate:!0}:{},activityCreter:IA(e.activity_creter),statusCriteria:So,ganttId:null}}function Fn(e,t=er,r=Cr){let i=Uu(e.sector),{calendars:n,baseCalendars:o,knownCalendarIds:a,defaultCalendarId:s}=Ou(e.calendars,e.sector.calendars,e.baseCalendars,vA(e.activities)),{activities:c,activityIds:l,hiddenIds:d}=ku(e.activities,{knownCalendarIds:a,defaultCalendarId:s,hoursPerDay:i.hoursPerDay,reporter:t,recordDiagnostic:r}),u=Mu(e.links,{knownActivityIds:l,hoursPerDay:i.hoursPerDay,reporter:t,recordDiagnostic:r});return{sector:i,activities:c,links:u,calendars:n,baseCalendars:o,viewStateSeed:{hiddenIds:d}}}function vA(e){let t=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(let o of e){let a=new Date(o.start_date).getTime(),s=new Date(o.end_date).getTime();Number.isFinite(a)&&(t=Math.min(t,a)),Number.isFinite(s)&&(r=Math.max(r,s))}if(!Number.isFinite(t)||!Number.isFinite(r))return null;let i=new Date(t),n=new Date(r);return i.setFullYear(i.getFullYear()-1),n.setFullYear(n.getFullYear()+1),{start:i.getTime(),end:n.getTime()}}function Ua(e={}){let t=e.seed??0,r=i=>{i>t&&(t=i)};if(e.knownIds)for(let i of e.knownIds){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)}return{fork(){return Ua({seed:t})},next(){return t+=1,String(t)},bump(i){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)},snapshot(){return t},restore(i){t=i}}}function Ba(e={}){let t=e.seed??0,r=i=>{i>t&&(t=i)};if(e.knownIds)for(let i of e.knownIds){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)}return{fork(){return Ba({seed:t})},next(){return t+=1,String(t)},bump(i){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)},snapshot(){return t},restore(i){t=i}}}function Ha(e={}){let t=e.seed??0,r=i=>{Number.isFinite(i)&&i>0&&i<=9999999&&i>t&&(t=i)};if(e.knownIds)for(let i of e.knownIds){if(i==null)continue;let n=typeof i=="number"?i:Number(i);r(n)}return{fork(){return Ha({seed:t})},next(){return t+=1,String(t)},bump(i){if(i==null)return;let n=typeof i=="number"?i:Number(i);r(n)},snapshot(){return t},restore(i){t=i}}}function Bu(e){return!!e&&typeof e=="string"&&e.trim().length>0}function wn(e){if(!e||typeof e!="string"||e.trim().length===0)return"";let t=e.match(/^(.*?)(\d+)$/);return t?t[1]??"":e}function xn(e){if(!e||typeof e!="string"||e.trim().length===0)return"";let t=e.match(/(\d+)$/);return t?t[1]??"":""}function Hu(e){if(!e||typeof e!="object")return"";let t=e.customId;return typeof t=="string"?t:""}function Wu(e,t){return!t&&Bu(e)}function Vu(e,t){return t&&Bu(e)}function ri(e){return typeof e=="string"&&e.length>0&&/^\d+$/.test(e)}function Mn(e){if(!ri(e))return 0n;try{return BigInt(e)}catch{return 0n}}function CA(e,t){if(typeof e!="bigint")return"";let r=e.toString();if(!ri(t))return r;let i=t.length;return r.padStart(i,"0")}function jt(e,t){let r=Mn(e),i=Mn(t),n=r+i;return CA(n,e)}function Un(e,t){let r=Mn(e),i=Mn(t);return r<i?-1:r>i?1:0}function Bn(e,t){return Un(e,t)<=0?e:t}function Hn(e,t){return Un(e,t)>=0?e:t}function Ku(e){if(!e||e.length===0)throw new Error("minSuffixFromArray requires non-empty array");return e.reduce((t,r)=>Bn(t,r))}function ju(e){if(!e||e.length===0)throw new Error("maxSuffixFromArray requires non-empty array");return e.reduce((t,r)=>Hn(t,r))}var le={PARENT_CONVERSION:"parentConversion",PASTE_REFERENCE:"pasteReference",NO_CONTEXT:"noContext"};function Yu(e){return{prefix:e,baseSuffix:null}}function Gu(e,t){let r=xn(e);return{prefix:wn(e),baseSuffix:jt(r,t)}}function $u(e){return{prefix:e,baseSuffix:null}}function zu(e,t){return Wu(e,t)?le.PARENT_CONVERSION:Vu(e,t)?le.PASTE_REFERENCE:le.NO_CONTEXT}function qu(e){return{...e,usedSuffixes:new Set(e.usedSuffixes)}}var Wn=class e{prefixMap=new Map;processedIds=new Set;_journalPrefixBefore=null;_journalIds=null;beginCustomIdTransaction(){this._journalPrefixBefore=new Map,this._journalIds=[]}commitCustomIdTransaction(){this._journalPrefixBefore=null,this._journalIds=null}rollbackCustomIdTransaction(){let t=this._journalPrefixBefore,r=this._journalIds;if(!(t===null||r===null)){for(let[i,n]of t)n===null?this.prefixMap.delete(i):this.prefixMap.set(i,n);for(let i of[...r].reverse())i.hadId?this.processedIds.add(i.customId):this.processedIds.delete(i.customId);this._journalPrefixBefore=null,this._journalIds=null}}_noteCustomIdBefore(t){if(this._journalPrefixBefore===null||this._journalIds===null)return;let{prefix:r}=this.analyzeCustomId(t);if(!this._journalPrefixBefore.has(r)){let i=this.prefixMap.get(r);this._journalPrefixBefore.set(r,i?qu(i):null)}this._journalIds.push({customId:t,hadId:this.processedIds.has(t)})}_ensureFreshBounds(t){let r=this.prefixMap.get(t);if(!r?.boundsDirty)return;r.boundsDirty=!1;let i=Array.from(r.usedSuffixes);r.min=Ku(i),r.max=ju(i),r.quantity=i.length,this._recalculateNext(t)}defaultPrefix;suffixIncrement;constructor(t={}){this.defaultPrefix=t.defaultPrefix??"A",this.suffixIncrement=t.suffixIncrement??"10"}fork(){let t=new e({defaultPrefix:this.defaultPrefix,suffixIncrement:this.suffixIncrement});for(let[r,i]of this.prefixMap)t.prefixMap.set(r,qu(i));for(let r of this.processedIds)t.processedIds.add(r);return t}extractPrefix(t){return wn(t)}extractSuffix(t){return xn(t)}analyzeCustomId(t){return{prefix:this.extractPrefix(t),suffix:this.extractSuffix(t)}}_updatePrefixStats(t,r){if(this._ensureFreshBounds(t),!this.prefixMap.has(t)){this.prefixMap.set(t,{min:r,max:r,next:r,quantity:1,usedSuffixes:new Set([r])}),this._recalculateNext(t);return}let i=this.prefixMap.get(t);i.usedSuffixes.has(r)||(i.usedSuffixes.add(r),i.min=Bn(r,i.min),i.max=Hn(r,i.max),i.quantity+=1,this._recalculateNext(t))}_recalculateNext(t){let r=this.prefixMap.get(t);if(!r)return;let i=this.getNextAvailableSuffix(t);r.next=i??this.suffixIncrement}getPrefixStats(t){this._ensureFreshBounds(t);let r=this.prefixMap.get(t);return r?{min:r.min,max:r.max,next:r.next,quantity:r.quantity}:null}getNextSuffix(t){this._ensureFreshBounds(t);let r=this.prefixMap.get(t);return r?r.next:this.suffixIncrement}getAllPrefixes(){return Array.from(this.prefixMap.keys())}registerCustomId(t){if(!t||typeof t!="string")return{prefix:"",suffix:""};let{prefix:r,suffix:i}=this.analyzeCustomId(t);if(!r&&!i)return{prefix:r,suffix:i};if(this._noteCustomIdBefore(t),this._ensureFreshBounds(r),this.prefixMap.has(r)){let n=this.prefixMap.get(r);n.usedSuffixes.has(i)||(n.usedSuffixes.add(i),n.min=Bn(i,n.min),n.max=Hn(i,n.max),n.quantity+=1,this._recalculateNext(r))}else this.prefixMap.set(r,{min:i,max:i,next:jt(i,this.suffixIncrement),quantity:1,usedSuffixes:new Set([i])});return this.processedIds.add(t),{prefix:r,suffix:i}}releaseCustomId(t=null){if(!t||typeof t!="string")return{prefix:"",suffix:""};let{prefix:r,suffix:i}=this.analyzeCustomId(t);if(!this.prefixMap.has(r))return{prefix:r,suffix:i};this._noteCustomIdBefore(t);let n=this.prefixMap.get(r);return n.usedSuffixes.has(i)&&(n.usedSuffixes.delete(i),n.quantity-=1,n.usedSuffixes.size===0?this.prefixMap.delete(r):n.boundsDirty=!0),this.processedIds.delete(t),{prefix:r,suffix:i}}trackCustomIdChange(t,r){let i=this.releaseCustomId(t),n=this.registerCustomId(r);return{oldPrefix:i.prefix,oldSuffix:i.suffix,newPrefix:n.prefix,newSuffix:n.suffix}}_exceedsMaxLength(t){return t.length>20}_shouldSearchForGaps(t){if(this._ensureFreshBounds(t),!this.prefixMap.has(t))return!1;let r=this.prefixMap.get(t);return`${t}${jt(r.max,this.suffixIncrement)}`.length>20}_suffixForUnknownPrefix(t,r){let i=r&&ri(r)?r:this.suffixIncrement;return`${t}${i}`.length>20?null:i}_findFirstAvailableGap(t){if(this._ensureFreshBounds(t),!this.prefixMap.has(t))return null;let r=this.prefixMap.get(t),i=this.suffixIncrement;for(;Un(i,r.max)<0;){if(`${t}${i}`.length>20)return null;if(!r.usedSuffixes.has(i))return i;i=jt(i,this.suffixIncrement)}return null}_generateDefaultCustomId(){let t=this.getNextAvailableSuffix(this.defaultPrefix);if(t===null){if(this._shouldSearchForGaps(this.defaultPrefix)){let r=this._findFirstAvailableGap(this.defaultPrefix);if(r!==null)return`${this.defaultPrefix}${r}`}return`${this.defaultPrefix}${this.suffixIncrement}`}return`${this.defaultPrefix}${t}`}getNextAvailableSuffix(t,r=null){if(this._ensureFreshBounds(t),!this.prefixMap.has(t))return this._suffixForUnknownPrefix(t,r);let i=this.prefixMap.get(t),n=this.suffixIncrement;if(!r||!ri(r)){let s=jt(i.max,n);return`${t}${s}`.length>20?null:s}let o=r;for(let s=0;s<100;s++){if(`${t}${o}`.length>20)return null;if(!i.usedSuffixes.has(o))return o;o=jt(o,n)}let a=jt(i.max,n);return`${t}${a}`.length>20?null:a}generateNextCustomId(t){let r=this.getNextAvailableSuffix(t);if(r===null)return this._generateDefaultCustomId();if(this.prefixMap.has(t)){let n=this.prefixMap.get(t),o=0;for(;n.usedSuffixes.has(r)&&o<1e4;){let a=this.getNextAvailableSuffix(t,jt(r,this.suffixIncrement));if(a===null)return this._generateDefaultCustomId();r=a,o++}}let i=`${t}${r}`;return this._exceedsMaxLength(i)&&(i=this._generateDefaultCustomId()),i}populateFromActivities(t){if(!Array.isArray(t))return this;let r=[...new Set(t.filter(i=>i&&typeof i.customId=="string"&&i.customId).map(i=>i.customId))];for(let i of r){if(this.processedIds.has(i))continue;let{prefix:n,suffix:o}=this.analyzeCustomId(i);(n||o)&&(this._updatePrefixStats(n,o),this.processedIds.add(i))}return this}getDefaults(){return{prefix:this.defaultPrefix,increment:this.suffixIncrement}}generateCustomIdForNewChild(t){let{activity:r,useActivityCustomIdAsReference:i=!1}=t,n=Hu(r),o=zu(n,i),{prefix:a,baseSuffix:s}=this._applyGenerationStrategy(o,n),c=null;if(o===le.PARENT_CONVERSION&&this.prefixMap.has(a)){this._ensureFreshBounds(a);let f=this.prefixMap.get(a).max;c=jt(f,this.suffixIncrement)}o===le.PARENT_CONVERSION&&this.releaseCustomId(n);let l=o===le.PARENT_CONVERSION&&c?c:s,d=this.getNextAvailableSuffix(a,l);if(d===null){let f=this._generateDefaultCustomId();return this.registerCustomId(f),f}let u=`${a}${d}`;return this._exceedsMaxLength(u)&&(u=this._generateDefaultCustomId()),this.registerCustomId(u),u}_applyGenerationStrategy(t,r){switch(t){case le.PARENT_CONVERSION:return Yu(this.defaultPrefix);case le.PASTE_REFERENCE:return Gu(r,this.suffixIncrement);default:return $u(this.defaultPrefix)}}generateCustomIdForRestoredChild(t=null){if(t){let i=t.trim();if(i.length>0){let n=this.extractPrefix(i),o=this.extractSuffix(i),a=jt(o,this.suffixIncrement),s=this.getNextAvailableSuffix(n,a);if(s===null){let l=this._generateDefaultCustomId();return this.registerCustomId(l),l}let c=`${n}${s}`;return this._exceedsMaxLength(c)&&(c=this._generateDefaultCustomId()),this.registerCustomId(c),c}}let r=this.generateNextCustomId(this.defaultPrefix);return this.registerCustomId(r),r}clear(){this.prefixMap.clear(),this.processedIds.clear()}getTotalPrefixes(){return this.prefixMap.size}hasPrefix(t){return this.prefixMap.has(t)}isCustomIdInUse(t,r=null){if(!t||typeof t!="string"||!t.trim())return!1;let i=t.trim();return r&&i===r.trim()?!1:this.processedIds.has(i)}};var SA=1,TA=-1;function EA(e,t){return!e&&!t?null:e&&t?0:e?SA:TA}function Ju(e){return e==null}function Xu(e,t){let r=t.indexOf(String(e));return r===-1?t.length:r}function DA(e,t,r){return e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():typeof e=="number"&&typeof t=="number"?e-t:typeof e=="boolean"&&typeof t=="boolean"?Number(e)-Number(t):Array.isArray(e)&&Array.isArray(t)?e.length-t.length:String(e).localeCompare(String(t),r,{sensitivity:"base",numeric:!0})}function _A(e,t){let r=fe(e.field);return r===null?null:(i,n)=>{let o=r.extract(i,t),a=r.extract(n,t),s=EA(Ju(o),Ju(a));if(s!==null)return s;let c=r.valueKind===O.ENUM?Xu(o,r.order)-Xu(a,r.order):DA(o,a,t.locale);return e.direction===Pe.DESCENDING?-c:c}}function Zu(e,t){let r=e.rules.map(i=>_A(i,t)).filter(i=>i!==null);return r.length===0?null:(i,n)=>{for(let o of r){let a=o(i,n);if(a!==0)return a}return 0}}function Qu(e){let t=[];e.forEachActivity((r,i)=>{r.type===D.PROJECT&&e.getChildren(String(i)).length===0&&t.push(String(i))});for(let r of t)e.setActivityField(r,x.TYPE,tr),kA(e,r)}function kA(e,t){let r=e.getActivity(t);if(!r||!r.startDate||r.durationHours==null)return;let i=new Date(r.startDate);i.setUTCHours(0,0,0,0);let n=e.getClosestWorkTime({date:i,dir:K.FUTURE,task:r});if(n.getTime()===r.startDate.getTime())return;let o=e.calculateEndDate({startDate:n,durationHours:r.durationHours,task:r});e.setActivityField(t,x.START_DATE,n),e.setActivityField(t,x.END_DATE,o)}function tf(e){let t=[],r=[];e.forEachActivity((n,o)=>{n.parentId===null&&t.push(String(o))});let i=n=>{let o=e.getActivity(n);if(!o)return 0;let a=[...e.getChildren(n)],s=a.length===0?Nt(o.workHours,o.progress):a.reduce((c,l)=>c+i(String(l)),0);return e.setActivityField(n,x.REAL_WORK_HOURS,s),r.push(n),s};for(let n of t)i(n);return r}async function ef(e){let{state:t,sector:r,scheduler:i,skipAutoSchedule:n,now:o}=e;if(St(t),r.updateDurationForPrimaveraEndDate&&PA(t),LA(t),tf(t),n){Ur(t),o&&(Me(t,o),ce(t,r.statusCriteria));return}let a=await i.schedule({});Fr(t,a),OA(t),RA(t),await ir(t,void 0,!1),Ur(t),o&&(Me(t,o),ce(t,r.statusCriteria))}function RA(e){e.forEachActivity(t=>{t.autoScheduling||!t.startDate||t.durationHours==null||e.getChildren(t.id).length>0||(t.endDate=e.calculateEndDate({startDate:t.startDate,durationHours:t.durationHours,task:t}),t.calendarDuration=Qt(t))})}function PA(e){e.forEachActivity(t=>{!t.startDate||!t.endDate||(t.durationHours=e.calculateDuration({startDate:t.startDate,endDate:t.endDate,task:t}))})}function LA(e){e.forEachActivity(t=>{let r=t.constraintType;if(!r||!t.constraintDate)return;let i=t.constraintDate;if(t.type===D.MILESTONE&&(i.getUTCHours()!==0||i.getUTCMinutes()!==0))return;let n=e.calendarReader.getCalendar(String(t.calendarId));n&&(t.constraintDate=ne(t.constraintDate,n,r))})}function OA(e){e.forEachActivity(t=>{if(t.type!==D.MILESTONE)return;let r=t.constraintType;if(!r||!t.constraintDate)return;let i=e.calendarReader.getCalendar(String(t.calendarId));i&&(t.constraintDate=ne(t.constraintDate,i,r))})}var Zt={READY:"ready",DESTROYED:"destroyed",POISONED:"poisoned"};function rf(e){let t=e.clock??null,r=t?.()??null,i=r?xi(r):null,n=e.reporter??er,o=ed(),a=Fn({sector:e.sector,activities:e.activities,links:e.links,calendars:e.calendars,baseCalendars:e.baseCalendars},n,o.record),s=a.sector;s.statusCriteria=zi(e.statusCriteria),s.ganttId=e.ganttId??null;let c=a.calendars,l=a.baseCalendars??[],d=Pn(a.activities,a.links,a.calendars,l),u=E=>Zu(E,Re(s.hoursPerDay)),f=new Tr(d,u);f.hydrateViewState({hiddenIds:a.viewStateSeed.hiddenIds});let p=new rr(f,n);Qu(f);let y=Ua({knownIds:a.activities.map(E=>E.id)}),I=Ba({seed:r?.getTime()??0,knownIds:a.links.map(E=>E.id)}),T=Ha({knownIds:a.activities.map(E=>E.uniqueCorrelativeId)}),L=new Wn({defaultPrefix:s.customIdPrefix,suffixIncrement:s.customIdIncrement});if(L.populateFromActivities(a.activities),e.baselinePoints&&e.baselinePoints.length>0){let E=l.find(g=>g.baseDefault)?.id??null;vn(f,e.baselinePoints,i,n,E,o.record)}let S=ef({state:f,sector:s,scheduler:p,skipAutoSchedule:e.skipInitialAutoSchedule===!0,now:i??void 0});return{sector:s,state:f,scheduler:p,activityIdGen:y,linkIdGen:I,uidGen:T,customIdTracker:L,calendars:c,baseCalendars:l,clock:t,reporter:n,loadDiagnostics:o.snapshot,initPromise:S}}function Dr(e){if(e===void 0)return["undefined"];if(e===null)return["null"];if(typeof e=="string")return["string",e];if(typeof e=="boolean")return["boolean",e];if(typeof e=="number")return["number",Object.is(e,-0)?"-0":String(e)];if(typeof e=="bigint")return["bigint",String(e)];if(e instanceof Date)return["date",String(e.getTime())];if(Array.isArray(e))return["array",e.map(Dr)];if(e instanceof Map)return["map",Array.from(e,([t,r])=>[Dr(t),Dr(r)]).sort((t,r)=>JSON.stringify(t).localeCompare(JSON.stringify(r)))];if(e instanceof Set)return["set",Array.from(e,Dr).sort((t,r)=>JSON.stringify(t).localeCompare(JSON.stringify(r)))];if(typeof e=="object")return["object",Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,Dr(r)])];throw new TypeError(`Unsupported canonical value: ${typeof e}`)}function Ye(e){return JSON.stringify(Dr(e))}function Wa(e,t){let r=new Map(e.map(a=>[String(a.id),a])),i=new Map(t.map(a=>[String(a.id),a])),n=[...new Set([...r.keys(),...i.keys()])].sort(),o=[];for(let a of n){let s=i.get(a),c=r.get(a);if(c===void 0){o.push({id:a,kind:N.DELETED,after:null});continue}if(s===void 0){o.push({id:a,kind:N.CREATED,after:F(c)});continue}let l=NA(s,c);Object.keys(l).length>0&&o.push({id:a,kind:N.UPDATED,fields:l,after:F(c)})}return o}function NA(e,t){let r={},i=[...new Set([...Object.keys(e),...Object.keys(t)])].sort();for(let n of i)Ye(e[n])!==Ye(t[n])&&(r[n]={before:F(e[n]),after:F(t[n])});return r}function bA(e,t){let r=new Set(t.selectedIds.map(String)),i=new Set(e.selectedIds.map(String)),n=new Set(t.hiddenIds.map(String)),o=new Set(e.hiddenIds.map(String)),a=e.activities.map(({id:c})=>String(c)).sort(),s=[];for(let c of a){let l=r.has(c),d=i.has(c),u=!n.has(c),f=!o.has(c);l===d&&u===f||s.push({activityId:c,...l===d?{}:{checked:{before:l,after:d}},...u===f?{}:{visible:{before:u,after:f}}})}return s}function nf(e,t){let r=Ye(e.order)!==Ye(t.order);return{source:{kind:oe.INIT},activities:Wa(e.activities,t.activities),links:Wa(e.links,t.links),calendars:Wa(e.calendars,t.calendars),trackingEvents:[],effects:[],viewState:bA(e,t),...r?{order:F(e.order)}:{}}}var _r={MOVE:"move",RESIZE_START:"resize-start",RESIZE_END:"resize-end"},FA=()=>({constantStart:null,variableStartOffset:null,constantEnd:null,variableEndOffset:null}),Va=(e,t)=>e===null?t:Math.min(e,t),Ka=(e,t)=>e===null?t:Math.max(e,t);function af(e,t,r){let i=[...new Set(t.kind===_r.MOVE?t.activityIds.map(String):[String(t.activityId)])];if(i.length===0)throw new Error("[ScheduleCore] date gesture has no participants");let n=wA(e,t,i);return xA(e,i,n),{getDates(o,a){if(r(),!Number.isFinite(a))throw new Error("[ScheduleCore] invalid date gesture edge");let s=n.get(String(o));if(!s)return null;let c=UA(s,a),l=BA(s,a);if(c===null||l===null)throw new Error(`[ScheduleCore] incomplete date gesture bounds for ${String(o)}`);return{startTimeMs:c,endTimeMs:l}}}}function wA(e,t,r){let i=new Map,n=t.kind===_r.MOVE?String(t.anchorActivityId):null,o=n===null?null:of(e,n);if(n!==null&&!r.includes(n))throw new Error("[ScheduleCore] move anchor is not a participant");for(let a of r){let s=of(e,a);if(t.kind===_r.MOVE){let c=o.startDate.getTime();i.set(a,{constantStart:null,variableStartOffset:s.startDate.getTime()-c,constantEnd:null,variableEndOffset:s.endDate.getTime()-c})}else t.kind===_r.RESIZE_START?i.set(a,{constantStart:null,variableStartOffset:0,constantEnd:s.endDate.getTime(),variableEndOffset:null}):i.set(a,{constantStart:s.startDate.getTime(),variableStartOffset:null,constantEnd:null,variableEndOffset:0})}return i}function xA(e,t,r){let i=Hr(e,new Set(t));for(let n of i){let o=FA();for(let a of e.getChildren(n)){let s=r.get(a);if(s){MA(o,s);continue}let c=e.getActivity(a);if(!c)throw new Error(`[ScheduleCore] missing child ${a} while previewing parent ${n}`);o.constantStart=Va(o.constantStart,c.startDate.getTime()),o.constantEnd=Ka(o.constantEnd,c.endDate.getTime())}r.set(n,o)}}function of(e,t){let r=e.getActivity(t);if(!r)throw new Error(`[ScheduleCore] missing date gesture activity ${t}`);if(e.hasChildren(t))throw new Error(`[ScheduleCore] summary activity ${t} cannot be dragged directly`);return r}function MA(e,t){t.constantStart!==null&&(e.constantStart=Va(e.constantStart,t.constantStart)),t.variableStartOffset!==null&&(e.variableStartOffset=Va(e.variableStartOffset,t.variableStartOffset)),t.constantEnd!==null&&(e.constantEnd=Ka(e.constantEnd,t.constantEnd)),t.variableEndOffset!==null&&(e.variableEndOffset=Ka(e.variableEndOffset,t.variableEndOffset))}function UA(e,t){if(e.variableStartOffset===null)return e.constantStart;let r=t+e.variableStartOffset;return e.constantStart===null?r:Math.min(e.constantStart,r)}function BA(e,t){if(e.variableEndOffset===null)return e.constantEnd;let r=t+e.variableEndOffset;return e.constantEnd===null?r:Math.max(e.constantEnd,r)}var ja=Symbol("ScheduleCore.fork.source");function HA(e){return e.kind===m.PERSISTENCE_ACKNOWLEDGE||e.kind===m.ACTIVITY_LOOKAHEAD_SYNC&&e.acknowledgePersistedLookahead===!0}function WA(e){for(let t of e.activities)if(t.kind===N.DELETED||t.kind===N.UPDATED&&t.fields!==void 0&&"parentId"in t.fields)return!0;return!1}function VA(e,t){let r=[];for(let i of e.activities){let n=t.getActivity(i.id);if(n===null)return null;r.push(n)}return r}function KA(e,t,r){if(e===null||e.filter!==t)return!1;let i=e.context.hoursPerDay===r.hoursPerDay,n=e.context.locale===r.locale;return i&&n}var kr=class e{activities;links;calendars;selection;view;baselines;impactRequests;persistence;history;projection;criticalPath;diagnostics;_activityClipboard={value:null};_status=Zt.READY;coreRuntime;_isFork;_undo=new Rn;_opQueue=Promise.resolve();_scheduleRevision=0;_stateRevision=0;_pendingScheduleRevision=0;_criticalPathRevision=-1;_activeCriticalPath=null;constructor(t){if(Object.assign(this,Za(this)),ja in t){this._isFork=!0;let n=t[ja],o=n.coreRuntime.state.fork();this.coreRuntime={state:o,scheduler:new rr(o,n.coreRuntime.reporter),sector:F(n.coreRuntime.sector),activityIdGenerator:n.coreRuntime.activityIdGenerator.fork(),linkIdGenerator:n.coreRuntime.linkIdGenerator.fork(),uniqueCorrelativeIdGenerator:n.coreRuntime.uniqueCorrelativeIdGenerator.fork(),customIdTracker:n.coreRuntime.customIdTracker.fork(),calendars:new Map(Array.from(n.coreRuntime.calendars,([a,s])=>[a,F(s)])),baseCalendars:F(n.coreRuntime.baseCalendars),clock:n.coreRuntime.clock,reporter:n.coreRuntime.reporter,loadDiagnostics:n.coreRuntime.loadDiagnostics},this._activityClipboard.value=F(n._activityClipboard.value),this._undo=n._undo.fork(),this._saveTracker=n._saveTracker.fork(),this._scheduleRevision=n._scheduleRevision,this._stateRevision=n._stateRevision,this._pendingScheduleRevision=n._scheduleRevision,this._criticalPathRevision=n._criticalPathRevision,this._initPromise=Promise.resolve(),this._criticalPathReady=Promise.resolve(null),this._ready=this._initPromise;return}this._isFork=!1;let r=rf(t);this.coreRuntime={state:r.state,scheduler:r.scheduler,sector:r.sector,activityIdGenerator:r.activityIdGen,linkIdGenerator:r.linkIdGen,uniqueCorrelativeIdGenerator:r.uidGen,customIdTracker:r.customIdTracker,clock:r.clock,calendars:new Map(r.calendars.map(n=>[n.id,n])),baseCalendars:r.baseCalendars,reporter:r.reporter,loadDiagnostics:r.loadDiagnostics},this._initPromise=r.initPromise.then(()=>{this._status!==Zt.DESTROYED&&this._saveTracker.init(this.coreRuntime.state.getAllActivities(),this.getAllLinksView())}),this._criticalPathReady=this._initPromise.then(()=>this._startCriticalPathForCurrentRevision());let i=t.criticalPathOnLoad===!0;this._ready=i?this._criticalPathReady.then(()=>{}):this._initPromise}get ready(){return this._ready}fork(){return this._enqueue(async()=>(await this._ready,this.assertReady(),new e({[ja]:this})))}get criticalPathReady(){return this._criticalPathReady}get status(){return this._status}getSector(){return F(this.coreRuntime.sector)}getLoadDiagnostics(){return this.assertReady(),this.coreRuntime.loadDiagnostics()}getActivityView(t){return this.assertReady(),_a(this.coreRuntime.state,t)}getProgressEditability(t){this.assertReady();let r=_a(this.coreRuntime.state,t);if(!r)return null;let i=Pa(this.coreRuntime.state,{hoursPerDay:this.coreRuntime.sector.hoursPerDay,dateFormat:this.coreRuntime.sector.dateFormat});return Ui.canEdit(r,i.hierarchy)}createDateGesturePreview(t){this.assertReady();let r=this._scheduleRevision;return af(this.coreRuntime.state,t,()=>{if(this.assertReady(),this._scheduleRevision!==r)throw new Error("[ScheduleCore] date gesture preview is stale")})}getAllActivitiesView(){return this.assertReady(),jd(this.coreRuntime.state)}getIndentTargetParentIds(t){this.assertReady();let r=gn(t.map(i=>String(i)),this.coreRuntime.state);return[...new Set(r.allowedMoves.map(i=>String(i.newParentId)))]}getChildrenView(t){return this.assertReady(),$d(this.coreRuntime.state,t)}getLinkView(t){return this.assertReady(),Ra(this.coreRuntime.state,t)}getLinksForActivityView(t){this.assertReady();let r=this.coreRuntime.state,i=[],n=new Set,o=a=>{if(n.has(a))return;n.add(a);let s=Ra(r,a);s&&i.push(s)};for(let a of r.getOutgoingLinkIds(t))o(a);for(let a of r.getIncomingLinkIds(t))o(a);return i}getAllLinksView(){return this.assertReady(),Jd(this.coreRuntime.state)}auditEffectiveGraph(){this.assertReady();let t=this.coreRuntime.state,r=t.getAllLinks(),i=xr(t,r),n=Ci(i),o=0;for(let a of n)a.length>o&&(o=a.length);return{activityCount:t.getAllIds().length,logicalLinkCount:r.length,effectiveEdgeCount:i.length,circularComponents:n,largestComponentSize:o}}getProperty(t,r){this.assertReady();let i=this.coreRuntime.state.getActivity(t);return i?F(i[r]):null}getAllIds(){return this.assertReady(),Yd(this.coreRuntime.state)}forEachActivityId(t){this.assertReady(),Gd(this.coreRuntime.state,t)}getChildrenIds(t){return this.assertReady(),ka(this.coreRuntime.state,t)}getSelectedActivityIds(){return this.assertReady(),zd(this.coreRuntime.state)}getHiddenActivityIds(){return this.assertReady(),this.coreRuntime.state.hiddenIds().map(String)}getVisibleActivityIds(){this.assertReady();let t=new Set(this.coreRuntime.state.hiddenIds().map(String));return this.coreRuntime.state.getAllIds().map(String).filter(r=>!t.has(r))}getActiveFilter(){return this.assertReady(),F(this.coreRuntime.state.getActiveFilter())}getActiveOrder(){return this.assertReady(),F(this.coreRuntime.state.getActiveOrder())}getVisualOrderIds(){return this.assertReady(),[...this.coreRuntime.state.getVisualOrderIds()]}hasChild(t){return this.assertReady(),qd(this.coreRuntime.state,t)}getCalendar(t){this.assertReady();let r=this.coreRuntime.calendars.get(t);return r?F(r):null}getAllCalendars(){return this.assertReady(),Array.from(this.coreRuntime.calendars.values(),t=>F(t))}getBaseCalendars(){return this.assertReady(),this.coreRuntime.baseCalendars.map(t=>F(t))}isCustomIdInUse(t,r=null){return this.assertReady(),this.coreRuntime.customIdTracker.isCustomIdInUse(t,r)}getProjectWorkHours(){return this.assertReady(),Xd(this.coreRuntime.calendars.values())}getModifiedLinks(){return this.assertReady(),this._saveTracker.modifiedLinks(t=>this.coreRuntime.state.getLink(t)).map(F)}getNewLinks(){return this.assertReady(),this._saveTracker.newLinks(t=>this.coreRuntime.state.getLink(t)).map(F)}getModifiedActivities(){return this.assertReady(),this._saveTracker.modifiedActivities(t=>this.coreRuntime.state.getActivity(t)).map(F)}getModifiedActivityFields(){return this.assertReady(),F(this._saveTracker.modifiedActivityFields(t=>this.coreRuntime.state.getActivity(t)))}getNewActivities(){return this.assertReady(),this._saveTracker.newActivities(t=>this.coreRuntime.state.getActivity(t)).map(F)}hasUnsavedChanges(){return this.assertReady(),this._saveTracker.hasUnsavedChanges()}getScheduleRevision(){return this._scheduleRevision}getStateRevision(){return this._stateRevision}capturePersistenceHistoryBoundary(){return this.assertReady(),this._undo.capturePersistenceBoundary()}getCanonicalDigest(){this.assertReady();let t=(r,i)=>String(r.id).localeCompare(String(i.id));return Ye({sector:this.getSector(),activities:[...this.getAllActivitiesView()].sort(t),links:[...this.getAllLinksView()].sort(t),calendars:[...this.getAllCalendars()].sort(t),baseCalendars:[...this.getBaseCalendars()].sort(t)})}createProjectionChangeSetFrom(t){this.assertReady(),t.assertReady();let r=i=>({activities:i.getAllActivitiesView(),links:i.getAllLinksView(),calendars:i.getAllCalendars(),selectedIds:i.getSelectedActivityIds(),hiddenIds:i.getHiddenActivityIds(),order:Ze(i.coreRuntime.state)});return nf(r(this),r(t))}getDeletedActivitiesSinceLastSave(){return this.assertReady(),this._saveTracker.deletedActivities(t=>this.coreRuntime.state.getActivity(t)).map(F)}getDeletedLinksSinceLastSave(){return this.assertReady(),this._saveTracker.deletedLinks(t=>this.coreRuntime.state.getLink(t)).map(F)}_enqueue(t){let r=this._opQueue.then(t,t);return this._opQueue=r.then(()=>{},()=>{}),r}_beginScheduleMutation(t){return qo(t)?this._admitScheduleMutation():!1}_admitScheduleMutation(){return this._pendingScheduleRevision++,this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0),!0}_settleScheduleMutation(t,r){t&&(r||(this._pendingScheduleRevision=Math.max(this._pendingScheduleRevision-1,this._scheduleRevision),this._pendingScheduleRevision===this._scheduleRevision&&this._criticalPathRevision!==this._scheduleRevision&&this.recomputeCriticalPath().catch(i=>{this.coreRuntime.reporter.error("[ScheduleCore] Critical Path re-arm after a barren mutation failed",i)})))}async dispatch(t,r={}){let i=this._beginScheduleMutation(t);return this._enqueue(()=>this._dispatchInner(t,r,i))}async applyActivityBatch(t,r={}){let i=this._beginScheduleMutation(t);return this._enqueue(()=>this._dispatchInner(t,r,i))}planLookaheadConversion(t){return this.assertReady(),ca(t,{adapter:this.coreRuntime.state,stateRevision:this._stateRevision})}applyLookaheadConversion(t){return this.dispatch({...t,kind:m.ACTIVITY_LOOKAHEAD_CONVERT})}async _dispatchInner(t,r={},i=!1){let n=!1;try{let o=await this._runDispatch(t,r);return n=o.changedState,o.result}finally{this._settleScheduleMutation(i,n)}}async _runDispatch(t,r){if(this.assertReady(),this._isFork&&HA(t))return{result:{ok:!1,reason:C.SANDBOX_PERSISTENCE_FORBIDDEN},changedState:!1};let i=Pa(this.coreRuntime.state,{hoursPerDay:this.coreRuntime.sector.hoursPerDay,dateFormat:this.coreRuntime.sector.dateFormat}),n=su(t),o=[this.coreRuntime.activityIdGenerator.snapshot(),this.coreRuntime.linkIdGenerator.snapshot(),this.coreRuntime.uniqueCorrelativeIdGenerator.snapshot()];this.coreRuntime.state.beginWriteCapture(),this.coreRuntime.customIdTracker.beginCustomIdTransaction();let a,s;try{a=await Ad(t,r,{adapter:this.coreRuntime.state,ctx:i,scheduler:this.coreRuntime.scheduler,sector:this.coreRuntime.sector,calendars:this.coreRuntime.calendars,activityIdGen:this.coreRuntime.activityIdGenerator,linkIdGen:this.coreRuntime.linkIdGenerator,isActivityIdReserved:d=>this._saveTracker.hasCheckpointActivityId(d),isLinkIdReserved:d=>this._saveTracker.hasCheckpointLinkId(d),uidGen:this.coreRuntime.uniqueCorrelativeIdGenerator,customIdTracker:this.coreRuntime.customIdTracker,reporter:this.coreRuntime.reporter,activityClipboard:this._activityClipboard,stateRevision:this._stateRevision,defaultBaseCalendarId:this.coreRuntime.baseCalendars.find(d=>d.baseDefault)?.id??null,now:this.coreRuntime.clock?xi(this.coreRuntime.clock()):null});let l=this.coreRuntime.state.peekWriteCapture()?.progressFallbackBefore;l&&l.size>0&&(s=new Map(l)),a.ok||this._rollback(o)}catch(l){throw this._rollback(o),l}finally{this.coreRuntime.state.endWriteCapture(),this.coreRuntime.customIdTracker.commitCustomIdTransaction()}if(a.ok&&n===Er.RECORD&&ba(a.changes)){let l=iu(this.coreRuntime.state,a.changes),d=s?new Map(Array.from(s.keys(),u=>[u,this.coreRuntime.state.getProgressFallback(u)])):void 0;this._undo.record(La(ru(a.changes),a.__beforeSnap,a.__beforeLinks,l.afterSnap,l.afterLinks,s,d),nu(t),Date.now())}if(a.ok)if(n===Er.CHECKPOINT_ON_SUCCESS){if(t.kind!==m.PERSISTENCE_ACKNOWLEDGE)throw new Error("checkpoint-on-success requires persistence acknowledge");let l=this.coreRuntime.state.getAllActivities(),d=this.coreRuntime.state.getAllLinks(),u=t.checkpoint,f=u?.historyBoundary??this._undo.capturePersistenceBoundary();this._saveTracker.acknowledge(u?.activities??l,u?.links??d,t.activities,t.links,l,d),this._undo.discardThrough(f),this._undo.applyPersistedIdentities(t.activities??[],t.links??[])}else t.kind===m.ACTIVITY_LOOKAHEAD_SYNC&&t.acknowledgePersistedLookahead===!0?(this._saveTracker.acknowledgePersistedLookahead(a.changes.activities,l=>this.coreRuntime.state.getActivity(l)),t.persistedProgress!==void 0&&this._undo.clear()):this._saveTracker.recordChanges(a.changes.activities,a.changes.links,l=>this.coreRuntime.state.getActivity(l),l=>this.coreRuntime.state.getLink(l));if(a=this._withReappliedViewState(t,a),!a.ok)return{result:a,changedState:!1};let c=ba(a.changes);return c&&this._stateRevision++,qo(t)&&c?(this._recordScheduleMutation(r.skipAutoSchedule!==!0&&r.skipCriticalPath!==!0&&We(t)),{result:sf(a),changedState:!0}):{result:sf(a),changedState:!1}}recomputeCriticalPath(){let t=this._enqueue(async()=>({job:this._startCriticalPathForCurrentRevision()})).then(({job:r})=>r);return this._criticalPathReady=t,t}isCriticalPathSettled(){return this._criticalPathRevision===this._scheduleRevision&&this._pendingScheduleRevision===this._scheduleRevision&&this._activeCriticalPath===null}async whenCriticalPathSettled(){for(;!this.isCriticalPathSettled();)await this.recomputeCriticalPath()}_withReappliedViewState(t,r){if(!r.ok||(t.kind===m.VISIBILITY_SET&&this.coreRuntime.state.setFilterProjection(null),!sl(t)))return r;let i=this._reapplyViewState(r.changes);return i===null?r:{...r,changes:i}}_reapplyViewState(t){let r=this._reapplyActiveFilter(t),i=this._emitTouchedBranchOrder(r??t);return this._reapplyActiveOrder(i.changes??r??t,i.touchedParents)??i.changes??r}_emitTouchedBranchOrder(t){let r=this.coreRuntime.state,i=fu(t,o=>r.getParentId(o));if(r.getActiveOrder()!==null)return{changes:null,touchedParents:i};if(i.size===0)return{changes:null,touchedParents:i};let n=to(r,i);return n.length===0?{changes:null,touchedParents:i}:{changes:{...t,order:n},touchedParents:i}}_reapplyActiveOrder(t,r){let i=this.coreRuntime.state;if(i.getActiveOrder()===null)return null;if(i.invalidateDerivedOrder(),t.links.length>0||t.calendars.length>0)return{...t,order:Ze(i)};let o=new Set(r);for(let s of t.activities){if(s.kind===N.DELETED)return{...t,order:Ze(i)};let c=i.getParentId(s.id);o.add(c===null?"0":String(c))}let a=to(i,o);return a.length===0?null:{...t,order:a}}_reapplyActiveFilter(t){let r=this.coreRuntime.state,i=r.getActiveFilter();if(i===null)return null;let n=Re(this.coreRuntime.sector.hoursPerDay),o=r.getFilterProjection(),a=KA(o,i,n),s=WA(t)?null:VA(t,r),c,l;if(s===null||!a){let f=di({activities:r.getAllActivities(),parentOf:p=>r.getParentId(p),filter:i,context:n});r.setFilterProjection(f),l=f.visibleIds,c=r.getAllIds()}else c=cs(o,s,f=>r.getParentId(f)),l=o.visibleIds;let u=Xe(r,l,c);return u.length===0?null:{...t,viewState:[...t.viewState??[],...u]}}_recordScheduleMutation(t){this._scheduleRevision++,this._pendingScheduleRevision=Math.max(this._pendingScheduleRevision,this._scheduleRevision),this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0),t&&(this._criticalPathRevision=this._scheduleRevision)}_startCriticalPathForCurrentRevision(){if(this._status===Zt.DESTROYED)return Promise.resolve(null);let t=this._scheduleRevision;if(this._criticalPathRevision===t)return Promise.resolve(null);if(this._activeCriticalPath?.revision===t)return this._activeCriticalPath.promise;this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0);let r={cancelled:!1},i=new Tr(Pn(this.coreRuntime.state.getAllActivities().map(s=>et(s)),this.coreRuntime.state.getAllLinks().map(s=>({...s})),Array.from(this.coreRuntime.calendars.values()),this.coreRuntime.baseCalendars)),n=()=>!r.cancelled&&this._status!==Zt.DESTROYED&&this._scheduleRevision===t&&this._pendingScheduleRevision===this._scheduleRevision,o=(async()=>{let s=await $o(i,this.coreRuntime.sector.hoursPerDay,n);return!n()||s===null?null:this._enqueue(async()=>{if(!n())return null;this.coreRuntime.state.beginWriteCapture(),this.coreRuntime.customIdTracker.beginCustomIdTransaction();let c;try{for(let[l,d]of s.activities)Yo(this.coreRuntime.state,l,d);for(let[l,d]of s.links)Go(this.coreRuntime.state,l,d);c=await z(this.coreRuntime.state,{source:{kind:oe.INIT},beforeSnap:new Map,touchedIds:[],scheduledIds:[],hoursPerDay:this.coreRuntime.sector.hoursPerDay}),this._criticalPathRevision=t}catch(l){throw this._rollback(),l}finally{this.coreRuntime.state.endWriteCapture(),this.coreRuntime.customIdTracker.commitCustomIdTransaction()}return{changes:c}})})();this._activeCriticalPath={revision:t,cancellation:r,promise:o};let a=()=>{this._activeCriticalPath?.promise===o&&(this._activeCriticalPath=null)};return o.then(a,a),o}undo(t={}){let r=this._admitScheduleMutation(),i=!1,n=this._enqueue(async()=>{try{return await this._runUndo(t,o=>{i=o})}finally{this._settleScheduleMutation(r,i)}});return n.then(o=>{o&&t.skipCriticalPath!==!0&&this.recomputeCriticalPath().catch(a=>{this.coreRuntime.reporter.error("[ScheduleCore] Critical Path recompute after undo failed",a)})},()=>{}),n}async _runUndo(t,r){{if(this.assertReady(),t.expectedUndoDepth!==void 0&&this._undo.undoDepth()!==t.expectedUndoDepth)return null;let i=this._undo.takeUndo();if(!i)return null;cu(this.coreRuntime.state,i),this._recordScheduleMutation(!1),r(!0),Oa(i)&&this._resyncCustomIdTrackerFromModel(),this._undo.pushRedo(i),this._undo.resetCoalesce();let n=Na(this.coreRuntime.state,i,ct.BEFORE);return this._saveTracker.recordChanges(n.activities,n.links,o=>this.coreRuntime.state.getActivity(o),o=>this.coreRuntime.state.getLink(o)),this._reapplyViewState(n)??n}}redo(t={}){let r=this._admitScheduleMutation(),i=!1,n=this._enqueue(async()=>{try{return await this._runRedo(o=>{i=o})}finally{this._settleScheduleMutation(r,i)}});return n.then(o=>{o&&t.skipCriticalPath!==!0&&this.recomputeCriticalPath().catch(a=>{this.coreRuntime.reporter.error("[ScheduleCore] Critical Path recompute after redo failed",a)})},()=>{}),n}async _runRedo(t){this.assertReady();let r=this._undo.takeRedo();if(!r)return null;lu(this.coreRuntime.state,r),this._recordScheduleMutation(!1),t(!0),Oa(r)&&this._resyncCustomIdTrackerFromModel(),this._undo.pushUndo(r),this._undo.resetCoalesce();let i=Na(this.coreRuntime.state,r,ct.AFTER);return this._saveTracker.recordChanges(i.activities,i.links,n=>this.coreRuntime.state.getActivity(n),n=>this.coreRuntime.state.getLink(n)),this._reapplyViewState(i)??i}canUndo(){return this._undo.canUndo()}canRedo(){return this._undo.canRedo()}clearHistory(){this._undo.clear()}undoDepth(){return this._undo.undoDepth()}_resyncCustomIdTrackerFromModel(){this.coreRuntime.customIdTracker.clear(),this.coreRuntime.customIdTracker.populateFromActivities(this.coreRuntime.state.getAllActivities())}destroy(){this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0),this.coreRuntime.calendars.clear(),this._saveTracker.clear(),this._status=Zt.DESTROYED}_initPromise;_criticalPathReady;_ready;_saveTracker=new On;assertReady(){if(this._status===Zt.DESTROYED)throw new Error("[ScheduleCore] instance is destroyed");if(this._status===Zt.POISONED)throw new Error("[ScheduleCore] instance is poisoned (a rollback failed) \u2014 reload from backend")}_rollback(t){try{this.coreRuntime.state.restoreFromCapture(),this.coreRuntime.scheduler.invalidateAllCaches(),this.coreRuntime.customIdTracker.rollbackCustomIdTransaction(),t&&(this.coreRuntime.activityIdGenerator.restore(t[0]),this.coreRuntime.linkIdGenerator.restore(t[1]),this.coreRuntime.uniqueCorrelativeIdGenerator.restore(t[2]))}catch(r){throw this._status=Zt.POISONED,this.coreRuntime.reporter.error("[ScheduleCore] rollback failed \u2014 core poisoned",r),r}}};function sf(e){let{__beforeSnap:t,__beforeLinks:r,...i}=e;return i}async function cf(e){let t=new kr(e);return await t.ready,t}var lf=(e=[])=>(e??[]).filter(t=>!t.proplannerId);var df={asap:"AS SOON AS POSSIBLE",alap:"AS LATE AS POSSIBLE",snet:"START NO EARLIER THAN",snlt:"START NO LATER THAN",fnet:"FINISH NO EARLIER THAN",fnlt:"FINISH NO LATER THAN",mso:"MUST START ON",mfo:"MUST FINISH ON"};var uf=8;var ff={CHILD:"child",CHILD_CONFIRMED:"child-confirmed",LINE:"line",ROOT:"root"};return Af(jA);})();
|
|
1
|
+
"use strict";var ScheduleCore=(()=>{var Vn=Object.defineProperty;var yf=Object.getOwnPropertyDescriptor;var hf=Object.getOwnPropertyNames;var mf=Object.prototype.hasOwnProperty;var If=(e,t)=>{for(var r in t)Vn(e,r,{get:t[r],enumerable:!0})},gf=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of hf(t))!mf.call(e,n)&&n!==r&&Vn(e,n,{get:()=>t[n],enumerable:!(i=yf(t,n))||i.enumerable});return e};var Af=e=>gf(Vn({},"__esModule",{value:!0}),e);var jA={};If(jA,{ACTIVITY_BATCH_ACTION_KIND:()=>ue,ACTIVITY_BATCH_MODE:()=>pt,ACTIVITY_DATE_EDGE:()=>Pr,ACTIVITY_FIELD:()=>It,ACTIVITY_PONDERATOR_CRITERION:()=>gt,ACTIVITY_PROGRESS_ORIGIN:()=>Wi,ACTIVITY_TYPE:()=>D,CALENDAR_UNIT:()=>mt,CHANGE_SET_SOURCE_KIND:()=>oe,COLUMN:()=>_,COMPLETED_PROGRESS:()=>br,CONSTRAINT_TYPE:()=>A,CONSTRAINT_TYPE_TO_LABEL:()=>df,CONSTRAINT_WARNING_KIND:()=>ji,CREATION_KIND:()=>ff,DATE_GESTURE_KIND:()=>_r,DEFAULT_HOURS_PER_DAY:()=>uf,DISPATCH_ACTION_KIND:()=>m,DISPATCH_ACTION_KINDS:()=>Xa,DISPATCH_LINK_OPERATION_KIND:()=>at,DISPATCH_TRACK_EVENT:()=>Kt,EDIT_ALERT_KEY:()=>oc,EDIT_DENIAL_REASON:()=>Wr,ENTITY_CHANGE_KIND:()=>N,FILTER_FIELD:()=>Y,FILTER_LOGIC:()=>li,FILTER_OPERATOR:()=>W,FILTER_REJECTION_REASON:()=>vt,FILTER_VALUE_KIND:()=>O,LINK_BATCH_OPERATION_KIND:()=>qe,LINK_CODE:()=>Ct,LINK_CODE_TO_TYPE:()=>Ne,LINK_REJECTION_REASON:()=>At,LINK_RELATIONSHIP:()=>ke,LINK_TYPE:()=>H,LINK_TYPE_CODE:()=>Ei,NEW_ACTIVITY_DEFAULTS:()=>ln,NOT_STARTED_PROGRESS:()=>Ds,ORDER_DIRECTION:()=>Pe,REJECTION_REASON:()=>S,ROOT_PARENT_ID:()=>V,SCHEDULE_CORE_STATUS:()=>Zt,SCHEDULE_EFFECT_KIND:()=>Vi,SIR_AUTO_REJECT_REASON:()=>Ki,STATUS:()=>kt,STATUS_CRITERIA:()=>de,ScheduleCore:()=>kr,WORK_TIME_DIRECTION:()=>K,checkNoUpdatedLinks:()=>vu,computeExpectedProgress:()=>Co,createSchedule:()=>cf,expectedProgressFromBaseline:()=>dr,getActiveBaseline:()=>Rt,getUnsavedActivities:()=>lf,isRootParent:()=>M,normalizeParentKey:()=>Gt,parseFromBackend:()=>Fn,willRunCriticalPath:()=>Zd,yieldToBrowser:()=>st});var D={TASK:"task",PROJECT:"project",MILESTONE:"milestone"},vf=Object.values(D);function Kn(e){return vf.includes(e)}var ni={CONSTRAINT:"constraint",ALERT:"alert",WARNING:"warning"},K={FUTURE:"future",PAST:"past"},mt={HOUR:"hour",DAY:"day"},gt={DURATION:"DURATION",COST:"COST",WORK_HOURS:"HH"},de={BASELINE:"Baseline",ACTUAL:"Actual"},kt={DONE:"Done",OVERDUE:"Overdue",ADVANCEMENT:"Advancement",WAITING:"Waiting",DOING:"Doing"},N={CREATED:"created",UPDATED:"updated",DELETED:"deleted"};var A={ASAP:"asap",ALAP:"alap",SNET:"snet",SNLT:"snlt",FNET:"fnet",FNLT:"fnlt",MSO:"mso",MFO:"mfo"},Cf={[A.MSO]:()=>!0,[A.MFO]:()=>!0,[A.SNLT]:(e,t)=>e<t,[A.SNET]:(e,t)=>e>t,[A.FNLT]:(e,t)=>e<t,[A.FNET]:(e,t)=>e>t};function $a(e,t,r){if(!t)return{violated:!1};let i=Cf[e];return i?i(t,r)?{violated:!0,constraintType:e,constraintDate:t}:{violated:!1}:{violated:!1}}var Sf=new Set([A.MSO,A.SNET,A.SNLT]);function Rr(e,t,r){return Sf.has(e)?t:r}function za(e,t,r){return{type:ni.CONSTRAINT,messageKey:"constraint_violation",data:{constraintType:e,constraintDate:t,...r?{projectedDate:r}:{}}}}var Tf={[A.SNET]:{startOfDay:!0,direction:K.FUTURE},[A.SNLT]:{startOfDay:!0,direction:K.PAST},[A.FNET]:{startOfDay:!1,direction:K.FUTURE},[A.FNLT]:{startOfDay:!1,direction:K.PAST},[A.MSO]:{startOfDay:!0,direction:K.FUTURE},[A.MFO]:{startOfDay:!1,direction:K.PAST}},oi=e=>new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())),Ga=(e,t)=>new Date(e.getTime()+t*864e5),Ef=(e,t)=>e.getUTCFullYear()===t.getUTCFullYear()&&e.getUTCMonth()===t.getUTCMonth()&&e.getUTCDate()===t.getUTCDate();function jn(e,t){if(!e.constraintDate||!e.constraintType)return null;let r=Tf[e.constraintType];if(!r)return e.constraintDate;let i=e.constraintDate,n=t.getClosestWorkTime({date:oi(i),dir:K.FUTURE,task:e});if(Ef(n,i))return i.getTime()!==oi(i).getTime()?i:r.startOfDay?n:t.getClosestWorkTime({date:Ga(oi(i),1),dir:K.PAST,task:e});let o=oi(t.getClosestWorkTime({date:i,dir:r.direction,task:e}));return r.startOfDay?t.getClosestWorkTime({date:o,dir:K.FUTURE,task:e}):t.getClosestWorkTime({date:Ga(o,1),dir:K.PAST,task:e})}function qa(e,t){let r={earliestStart:null,latestStart:null,earliestEnd:null,latestEnd:null},i=e.constraintType;if(!i||i===A.ASAP||i===A.ALAP)return r;let n=jn(e,t);if(!n)return r;let o=s=>t.calculateEndDate({startDate:s,durationHours:e.durationHours,task:e}),a=s=>t.calculateEndDate({startDate:s,durationHours:-e.durationHours,task:e});switch(i){case A.SNET:return{earliestStart:n,latestStart:null,earliestEnd:o(n),latestEnd:null};case A.SNLT:return{earliestStart:null,latestStart:n,earliestEnd:null,latestEnd:o(n)};case A.FNET:return{earliestStart:a(n),latestStart:null,earliestEnd:n,latestEnd:null};case A.FNLT:return{earliestStart:null,latestStart:a(n),earliestEnd:null,latestEnd:n};case A.MSO:{let s=o(n);return{earliestStart:n,latestStart:n,earliestEnd:s,latestEnd:s}}case A.MFO:{let s=a(n);return{earliestStart:s,latestStart:s,earliestEnd:n,latestEnd:n}}default:return r}}function Ja(e,t){return!(t.earliestStart&&e<t.earliestStart||t.latestStart&&e>t.latestStart)}function Yn(e,t){return t.latestStart&&e>t.latestStart?t.latestStart:t.earliestStart&&e<t.earliestStart?t.earliestStart:e}var H={FINISH_TO_START:"0",START_TO_START:"1",FINISH_TO_FINISH:"2",START_TO_FINISH:"3"},Df=Object.values(H);function ai(e){return Df.includes(e)}var _f={TEXT:"text",DESCRIPTION:"description",DURATION:"duration",PROGRESS:"progress",COST:"cost",USED_COST:"used_cost",HH_WORK_TIME:"hhWorkTime",START_DATE:"start_date",END_DATE:"end_date",CONSTRAINT_TYPE:"constraint_type",CONSTRAINT_DATE:"constraint_date",CALENDAR_ID:"calendar_id",CUSTOM_ID:"custom_id",SUBCONTRACT_ID:"subcontractId",RESPONSABLES:"responsables",TAGS:"tags",CUSTOM_PREDECESSORS:"custom_predecessors",CUSTOM_SUCESSORS:"custom_sucessors"},kf={REAL_WORK:"real_work",REAL_COST:"real_cost",EXPECTED_PROGRESS:"expected_progress",EXPECTED_PROGRESS_BASE:"expected_progress_base",START_BASE:"start_base",END_BASE:"end_base",DURATION_BASE:"duration_base",COST_BASE:"cost_base",WORK_BASE:"work_base",CALENDAR_DURATION:"calendarDuration",IS_CRITICAL:"is_critical",EARLY_START:"earlyStart",EARLY_FINISH:"earlyFinish",LATE_START:"lateStart",LATE_FINISH:"lateFinish",FREE_SLACK:"freeSlack",TOTAL_SLACK:"totalSlack",CORRELATIVE_ID:"correlative_id",UNIQUE_CORRELATIVE_ID:"unique_correlative_id",PONDERATOR:"ponderator",STATUS:"status"},_={..._f,...kf};var dt={CREATE:"create",UPDATE:"update",DELETE:"delete"},At={SELF_LINK:"self-link",CYCLE:"cycle",DUPLICATE:"duplicate",ACTIVITY_MISSING:"activity-missing",LINK_MISSING:"link-missing",HIERARCHY_LINK:"hierarchy-link"};var m={ACTIVITY_CLIPBOARD_CLEAR:"activity-clipboard-clear",ACTIVITY_COPY:"activity-copy",CALENDAR_RECONCILE:"calendar-reconcile",ACTIVITY_PASTE_COPIED:"activity-paste-copied",PERSISTENCE_ACKNOWLEDGE:"persistence-acknowledge",BASELINE_APPLY:"baseline-apply",PONDERATOR_CRITERION_SET:"ponderator-criterion-set",STATUS_CRITERIA_SET:"status-criteria-set",INLINE_EDIT:"inline-edit",DATES_BATCH:"dates-batch",BULK_EDIT:"bulk-edit",LINK_CREATE:"link-create",LINK_UPDATE:"link-update",LINK_DELETE:"link-delete",LINKS_BATCH:"links-batch",ACTIVITY_CREATE:"activity-create",ACTIVITY_DELETE:"activity-delete",ACTIVITY_MOVE:"activity-move",ACTIVITY_INDENT:"activity-indent",ACTIVITY_OUTDENT:"activity-outdent",ACTIVITY_SET_PROGRESS:"activity-set-progress",ACTIVITY_LOOKAHEAD_CONVERT:"activity-lookahead-convert",SELECTION_TOGGLE:"selection-toggle",SELECTION_REPLACE:"selection-replace",VISIBILITY_SET:"visibility-set",FILTER_SET:"filter-set",SORT_SET:"sort-set",SIR_SYNC:"sir-sync",ACTIVITY_LOOKAHEAD_SYNC:"activity-lookahead-sync"},ue="activity-batch",at=dt,Xa=Object.values(m);function Rt(e){let t=e?.baselinePoints;return!Array.isArray(t)||t.length===0?null:t.find(r=>r.isActiveVersion)??null}var It={NAME:"name",DESCRIPTION:"description",DURATION_DAYS:"durationDays",PROGRESS:"progress",COST:"cost",USED_COST:"usedCost",WORK_HOURS:"workHours",START_DATE:"startDate",END_DATE:"endDate",CONSTRAINT_TYPE:"constraintType",CONSTRAINT_DATE:"constraintDate",CALENDAR_ID:"calendarId",CUSTOM_ID:"customId",SUBCONTRACT_ID:"subcontractId",RESPONSABLE_IDS:"responsableIds",TAG_IDS:"tagIds"},Pr={START:"start",END:"end"},ke={FINISH_TO_START:"finish-to-start",START_TO_START:"start-to-start",FINISH_TO_FINISH:"finish-to-finish",START_TO_FINISH:"start-to-finish"},qe={CREATE:"create",UPDATE:"update",REMOVE:"remove"};var Rf={[It.NAME]:_.TEXT,[It.DESCRIPTION]:_.DESCRIPTION,[It.DURATION_DAYS]:_.DURATION,[It.PROGRESS]:_.PROGRESS,[It.COST]:_.COST,[It.USED_COST]:_.USED_COST,[It.WORK_HOURS]:_.HH_WORK_TIME,[It.START_DATE]:_.START_DATE,[It.END_DATE]:_.END_DATE,[It.CONSTRAINT_TYPE]:_.CONSTRAINT_TYPE,[It.CONSTRAINT_DATE]:_.CONSTRAINT_DATE,[It.CALENDAR_ID]:_.CALENDAR_ID,[It.CUSTOM_ID]:_.CUSTOM_ID,[It.SUBCONTRACT_ID]:_.SUBCONTRACT_ID,[It.RESPONSABLE_IDS]:_.RESPONSABLES,[It.TAG_IDS]:_.TAGS};function Gn(e,t){return{activityId:e,column:Rf[t.field],newValue:t.value}}var Pf={[ke.FINISH_TO_START]:H.FINISH_TO_START,[ke.START_TO_START]:H.START_TO_START,[ke.FINISH_TO_FINISH]:H.FINISH_TO_FINISH,[ke.START_TO_FINISH]:H.START_TO_FINISH};function Lr(e){return Pf[e]}function Lf(e){return e.kind===qe.CREATE?{kind:at.CREATE,source:e.sourceId,target:e.targetId,type:Lr(e.relationship),...e.lagDays===void 0?{}:{lag:e.lagDays},...e.linkId===void 0?{}:{linkId:e.linkId}}:e.kind===qe.UPDATE?{kind:at.UPDATE,linkId:e.linkId,...e.relationship===void 0?{}:{type:Lr(e.relationship)},...e.lagDays===void 0?{}:{lag:e.lagDays}}:e.kind===qe.REMOVE?{kind:at.DELETE,linkId:e.linkId}:e}function Of(e){return e===Pr.START?_.START_DATE:e===Pr.END?_.END_DATE:e}function Nf(e){return{kind:ue,mode:e.mode,items:e.items,links:e.links.map(t=>({source:t.source,target:t.target,type:Lr(t.relationship),...t.lagDays===void 0?{}:{lag:t.lagDays},...t.linkId===void 0?{}:{linkId:t.linkId}})),...e.eventSource===void 0?{}:{eventSource:e.eventSource}}}function bf(e){return{get:t=>e.getActivityView(t),list:()=>e.getAllActivitiesView(),ids:()=>e.getAllIds(),forEachId:t=>e.forEachActivityId(t),property:(t,r)=>e.getProperty(t,r),children:t=>e.getChildrenView(t),childIds:t=>e.getChildrenIds(t),hasChildren:t=>e.hasChild(t),indentTargetParentIds:t=>e.getIndentTargetParentIds(t),isCustomIdInUse:(t,r)=>e.isCustomIdInUse(t,r??null),create:(t,r)=>e.dispatch({...t,kind:m.ACTIVITY_CREATE},r),applyBatch:(t,r)=>e.applyActivityBatch(Nf(t),r),editInline:(t,r,i)=>e.dispatch({...Gn(t,r),kind:m.INLINE_EDIT},i),applyDragBatch:(t,r)=>e.dispatch({kind:m.DATES_BATCH,edits:t.map(i=>({activityId:i.activityId,column:Of(i.edge),newValue:i.value}))},r),editFields:(t,r)=>e.dispatch({kind:m.BULK_EDIT,edits:t.map(i=>Gn(i.activityId,i))},r),remove:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_DELETE,activityIds:t}),move:(t,r)=>e.dispatch({...t,kind:m.ACTIVITY_MOVE},r),planLookaheadConversion:t=>e.planLookaheadConversion(t),applyLookaheadConversion:t=>e.applyLookaheadConversion(t),indent:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_INDENT,activityIds:t}),outdent:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_OUTDENT,activityIds:t}),setProgress:(t,r,i={})=>e.dispatch({...i,kind:m.ACTIVITY_SET_PROGRESS,activityId:t,newValue:r}),copy:(t={})=>e.dispatch({...t,kind:m.ACTIVITY_COPY}),paste:(t,r={})=>e.dispatch({...r,kind:m.ACTIVITY_PASTE_COPIED,destination:{afterSiblingId:t}}),clearClipboard:(t={})=>e.dispatch({...t,kind:m.ACTIVITY_CLIPBOARD_CLEAR}),lookaheadSync:t=>e.dispatch({...t,kind:m.ACTIVITY_LOOKAHEAD_SYNC}),createDateGesturePreview:t=>e.createDateGesturePreview(t)}}function Ff(e){return{get:t=>e.getLinkView(t),list:()=>e.getAllLinksView(),forActivity:t=>e.getLinksForActivityView(t),create:(t,r)=>e.dispatch({kind:m.LINK_CREATE,source:t.sourceId,target:t.targetId,type:Lr(t.relationship),...t.lagDays===void 0?{}:{lag:t.lagDays},...t.linkId===void 0?{}:{linkId:t.linkId}},r),update:(t,r,i)=>e.dispatch({kind:m.LINK_UPDATE,linkId:t,...r.relationship===void 0?{}:{type:Lr(r.relationship)},...r.lagDays===void 0?{}:{lag:r.lagDays}},i),remove:(t,r)=>e.dispatch({kind:m.LINK_DELETE,linkId:t},r),batch:(t,r)=>e.dispatch({kind:m.LINKS_BATCH,operations:t.map(Lf)},r)}}function Za(e){let t=(r,i)=>e.dispatch({kind:m.BASELINE_APPLY,points:r},i);return{activities:bf(e),links:Ff(e),calendars:{get:r=>e.getCalendar(r),list:()=>e.getAllCalendars(),listBase:()=>e.getBaseCalendars(),projectWorkHours:()=>e.getProjectWorkHours(),reconcile:r=>e.dispatch({kind:m.CALENDAR_RECONCILE},r)},selection:{ids:()=>e.getSelectedActivityIds(),toggle:({checked:r,...i})=>e.dispatch({...i,kind:m.SELECTION_TOGGLE,isChecked:r}),replace:(r,i={})=>e.dispatch({...i,kind:m.SELECTION_REPLACE,activityIds:r})},view:{hiddenActivityIds:()=>e.getHiddenActivityIds(),visibleActivityIds:()=>e.getVisibleActivityIds(),visualOrderIds:()=>e.getVisualOrderIds(),filter:()=>e.getActiveFilter(),setFilter:r=>e.dispatch({...r,kind:m.FILTER_SET}),order:()=>e.getActiveOrder(),setOrder:(r,i={})=>e.dispatch({...i,kind:m.SORT_SET,rules:r}),setVisibility:(r,i={})=>e.dispatch({...i,kind:m.VISIBILITY_SET,visibleIds:r}),setStatusCriteria:(r,i)=>e.dispatch({kind:m.STATUS_CRITERIA_SET,criteria:r},i)},baselines:{refresh:t,setVisibility:t,setPonderatorCriterion:(r,i)=>e.dispatch({kind:m.PONDERATOR_CRITERION_SET,criterion:r},i),activeFor:r=>Rt(r)},impactRequests:{sync:r=>e.dispatch({...r,kind:m.SIR_SYNC})},persistence:{hasChanges:()=>e.hasUnsavedChanges(),modifiedActivities:()=>e.getModifiedActivities(),modifiedActivityFields:()=>e.getModifiedActivityFields(),newActivities:()=>e.getNewActivities(),deletedActivities:()=>e.getDeletedActivitiesSinceLastSave(),modifiedLinks:()=>e.getModifiedLinks(),newLinks:()=>e.getNewLinks(),deletedLinks:()=>e.getDeletedLinksSinceLastSave(),captureHistoryBoundary:()=>e.capturePersistenceHistoryBoundary(),readSnapshot:()=>({activities:e.getAllActivitiesView(),links:e.getAllLinksView(),historyBoundary:e.capturePersistenceHistoryBoundary()}),acknowledge:r=>e.dispatch({kind:m.PERSISTENCE_ACKNOWLEDGE,checkpoint:r})},history:{undo:r=>e.undo(r),redo:r=>e.redo(r),canUndo:()=>e.canUndo(),canRedo:()=>e.canRedo(),clear:()=>e.clearHistory(),depth:()=>e.undoDepth()},projection:{changeSetFrom:r=>e.createProjectionChangeSetFrom(r)},criticalPath:{get ready(){return e.criticalPathReady},recompute:()=>e.recomputeCriticalPath(),isSettled:()=>e.isCriticalPathSettled(),whenSettled:()=>e.whenCriticalPathSettled()},diagnostics:{auditEffectiveGraph:()=>e.auditEffectiveGraph(),revision:()=>e.getScheduleRevision(),stateRevision:()=>e.getStateRevision(),canonicalDigest:()=>e.getCanonicalDigest()}}}var xt=class{items=[];head=0;enqueue(t){this.items.push(t)}dequeue(){if(this.head>=this.items.length)return;let t=this.items[this.head];return this.head+=1,t}peek(){if(!(this.head>=this.items.length))return this.items[this.head]}get size(){return this.items.length-this.head}isEmpty(){return this.head>=this.items.length}};var si=e=>String(e);function Qa(e){let{clickedId:t,isChecked:r,currentSelection:i,hierarchy:n,isFrozen:o,exists:a,autoCheckParents:s}=e,c=si(t),l=new Set([...i].map(String)),d=new Set(l),u=wf(c,n).filter(a),f=u.filter(y=>!o(y)),p=r&&f.length<u.length;r&&!p?d.add(c):d.delete(c);for(let y of f)r?d.add(y):d.delete(y);return p||xf({id:c,isChecked:r,autoCheckParents:s,hierarchy:n,isFrozen:o,exists:a,next:d}),{nextSelection:d,changed:Mf(l,d),parentBlocked:p}}function wf(e,t){let r=[],i=new xt;i.enqueue(e);let n=new Set([e]);for(;!i.isEmpty();){let o=i.dequeue();for(let a of t.getChildrenIds(o)){let s=si(a);n.has(s)||(n.add(s),r.push(s),i.enqueue(s))}}return r}function xf(e){let{id:t,isChecked:r,autoCheckParents:i,hierarchy:n,isFrozen:o,exists:a,next:s}=e,c=n.getParentId(t);for(;c!==null&&typeof c<"u";){let l=si(c);if(o(l))return;let d=n.getChildrenIds(l).map(si).filter(a),u=d.some(o),f=d.filter(g=>!o(g)),y=f.length>0&&f.every(g=>s.has(g))&&!u;if(r){if(!i||!y||s.has(l))return;s.add(l)}else{if(y||!s.has(l))return;s.delete(l)}c=n.getParentId(l)}}function Mf(e,t){let r=[],i=[];for(let n of t)e.has(n)||r.push(n);for(let n of e)t.has(n)||i.push(n);return{checked:r,unchecked:i}}function Je(e){return(e.pendingRequestIds?.length??0)>0}var S={CANNOT_EDIT:"cannot_edit",PARSE_ERROR:"parse_error",INVALID:"invalid",CUSTOM_ID_DUPLICATE:"custom_id_duplicate",INVALID_LINK_TYPE:"invalid_link_type",INVALID_LINK_LAG:"invalid_link_lag",INVALID_VALUE:"invalid_value",NO_PIPELINE_FOR_COLUMN:"no_pipeline_for_column",ACTIVITY_NOT_FOUND:"activity_not_found",PARENT_NOT_FOUND:"parent_not_found",ACTIVITY_IDS_EMPTY:"activity_ids_empty",NO_ACTIVITY_SELECTION:"no_activity_selection",CLIPBOARD_EMPTY:"clipboard_empty",ACTIVITY_PASTE_INVARIANT_FAILED:"activity_paste_invariant_failed",ANCHOR_SIBLING_CONFLICT:"anchor_sibling_conflict",ANCHOR_SIBLING_NOT_FOUND:"anchor_sibling_not_found",ANCHOR_SIBLING_WRONG_PARENT:"anchor_sibling_wrong_parent",PARENT_FROZEN_BY_SIR:"parent_frozen_by_sir",CANNOT_MOVE_INTO_OWN_DESCENDANT:"cannot_move_into_own_descendant",INDENT_NO_ELIGIBLE_SIBLING:"indent_no_eligible_sibling",OUTDENT_ROOT_LEVEL_NOT_EDITABLE:"outdent_root_level_not_editable",HIERARCHY_CYCLE:"hierarchy_cycle",SANDBOX_PERSISTENCE_FORBIDDEN:"sandbox_persistence_forbidden",STALE_STATE_REVISION:"stale-state-revision",INVALID_PROGRESS_VALUE:"invalid_progress_value_must_be_0_or_100"};var ts=(e,t)=>{let r=e.getActivity(t);return r!=null&&Je(r)},es=(e,t,r)=>{let i=[],n=(o,a)=>{let s=t.isChecked(o);t.setChecked(o,a)&&i.push({activityId:o,checked:{before:s,after:a}})};for(let o of r.checked)n(o,!0);for(let o of r.unchecked)n(o,!1);return{source:e,activities:[],links:[],calendars:[],trackingEvents:[],viewState:i}};function rs(e,t){let{adapter:r}=t,i=e.activityId;if(!r.getActivity(i))return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let n=e.frozenIds?new Set(e.frozenIds):null,o=n?s=>n.has(s):s=>ts(r,s),a=Qa({clickedId:i,isChecked:e.isChecked,currentSelection:new Set(r.checkedIds().map(String)),hierarchy:{getChildrenIds:s=>r.getChildren(s),getParentId:s=>{let c=r.getParentId(s);return!c||c==="0"?null:String(c)}},isFrozen:o,exists:s=>r.activityExists(s),autoCheckParents:e.autoCheckParents??!1});return{ok:!0,changes:es(e,r,a.changed)}}function ci(e,t){let{adapter:r}=t,i=new Set(e.activityIds.map(String).filter(a=>r.activityExists(a)).filter(a=>!ts(r,a))),n=new Set(r.checkedIds().map(String)),o={checked:[...i].filter(a=>!n.has(a)),unchecked:[...n].filter(a=>!i.has(a))};return{ok:!0,changes:es(e,r,o)}}function Xe(e,t,r=e.getAllIds()){let i=[];for(let n of r){let o=String(n),a=t.has(o),s=e.isVisible(o);s!==a&&(e.setVisible(o,a),i.push({activityId:o,visible:{before:s,after:a}}))}return i}function is(e,t){let{adapter:r}=t,i=new Set(e.visibleIds.map(String)),n=Xe(r,i);return{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[],viewState:n}}}var ns={ALAP_DEBOUNCE_MS:1e3,CRITICAL_PATH_DEBOUNCE_MS:1e3,YIELD_SLICE_MS:8};var O={STRING:"string",NUMBER:"number",DATE:"date",ID_ARRAY:"id-array",ENUM:"enum",BOOLEAN:"boolean",REFERENCE:"reference"},Y={NAME:"name",DESCRIPTION:"description",CUSTOM_ID:"customId",CORRELATIVE_ID:"correlativeId",UNIQUE_CORRELATIVE_ID:"uniqueCorrelativeId",PROGRESS:"progress",DURATION_DAYS:"durationDays",CALENDAR_DURATION:"calendarDuration",COST:"cost",USED_COST:"usedCost",REAL_COST:"realCost",WORK_HOURS:"workHours",REAL_WORK_HOURS:"realWorkHours",PONDERATOR:"ponderator",FREE_SLACK_DAYS:"freeSlackDays",TOTAL_SLACK_DAYS:"totalSlackDays",EXPECTED_PROGRESS_BASELINE:"expectedProgressBaseline",BASELINE_DURATION_DAYS:"baselineDurationDays",BASELINE_COST:"baselineCost",BASELINE_WORK_HOURS:"baselineWorkHours",EXPECTED_PROGRESS:"expectedProgress",START_DATE:"startDate",END_DATE:"endDate",CONSTRAINT_DATE:"constraintDate",BASELINE_START_DATE:"baselineStartDate",BASELINE_END_DATE:"baselineEndDate",EARLY_START:"earlyStart",EARLY_FINISH:"earlyFinish",LATE_START:"lateStart",LATE_FINISH:"lateFinish",RESPONSABLE_IDS:"responsableIds",TAG_IDS:"tagIds",STATUS:"status",CONSTRAINT_TYPE:"constraintType",CALENDAR_ID:"calendarId",SUBCONTRACT_ID:"subcontractId",IS_CRITICAL:"isCritical"},W={INCLUDES:"includes",NOT_INCLUDES:"notIncludes",IS:"is",IS_NOT:"isNot",EQUALS:"equals",NOT_EQUALS:"notEquals",GREATER_THAN:"greaterThan",LESS_THAN:"lessThan",GREATER_OR_EQUAL:"greaterOrEqual",LESS_OR_EQUAL:"lessOrEqual",AFTER:"after",BEFORE:"before",BETWEEN:"between",SOME_OF:"someOf",NOT_SOME_OF:"notSomeOf"},li={AND:"and",OR:"or"};var Uf=2,Bf=[kt.WAITING,kt.DONE,kt.DOING,kt.OVERDUE,kt.ADVANCEMENT],Hf=[A.MFO,A.MSO,A.SNLT,A.SNET,A.ALAP,A.ASAP,A.FNET,A.FNLT],Wf=1e3*60*60*24;function $n(e,t){return e===null||t<=0?null:e/t}function Vf(e,t){let r=Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()),i=Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate());return Math.floor((i-r)/Wf)+1}var Kf={[Y.NAME]:{valueKind:O.STRING,extract:e=>e.name},[Y.DESCRIPTION]:{valueKind:O.STRING,extract:e=>e.description},[Y.CUSTOM_ID]:{valueKind:O.STRING,extract:e=>e.customId},[Y.CORRELATIVE_ID]:{valueKind:O.NUMBER,extract:e=>e.correlativeId},[Y.UNIQUE_CORRELATIVE_ID]:{valueKind:O.NUMBER,extract:e=>{let t=Number(e.uniqueCorrelativeId);return Number.isFinite(t)?t:null}},[Y.PROGRESS]:{valueKind:O.NUMBER,extract:e=>e.progress},[Y.DURATION_DAYS]:{valueKind:O.NUMBER,extract:(e,t)=>$n(e.durationHours,t.hoursPerDay)},[Y.CALENDAR_DURATION]:{valueKind:O.NUMBER,extract:e=>e.type===D.MILESTONE?0:Vf(e.startDate,e.endDate)},[Y.COST]:{valueKind:O.NUMBER,extract:e=>e.cost},[Y.USED_COST]:{valueKind:O.NUMBER,extract:e=>e.usedCost},[Y.REAL_COST]:{valueKind:O.NUMBER,extract:e=>e.realCost},[Y.WORK_HOURS]:{valueKind:O.NUMBER,extract:e=>e.workHours},[Y.REAL_WORK_HOURS]:{valueKind:O.NUMBER,extract:e=>e.realWorkHours},[Y.PONDERATOR]:{valueKind:O.NUMBER,extract:e=>e.ponderator},[Y.FREE_SLACK_DAYS]:{valueKind:O.NUMBER,extract:(e,t)=>$n(e.freeSlackHours,t.hoursPerDay)},[Y.TOTAL_SLACK_DAYS]:{valueKind:O.NUMBER,extract:(e,t)=>$n(e.criticalPath?.totalSlackHours??null,t.hoursPerDay)},[Y.EXPECTED_PROGRESS_BASELINE]:{valueKind:O.NUMBER,equalityPrecision:Uf,extract:e=>e.expectedProgressBaseline},[Y.EXPECTED_PROGRESS]:{valueKind:O.NUMBER,extract:e=>e.expectedProgress},[Y.BASELINE_DURATION_DAYS]:{valueKind:O.NUMBER,extract:e=>e.baselineSnapshot?.durationDays??null},[Y.BASELINE_COST]:{valueKind:O.NUMBER,extract:e=>e.baselineSnapshot?.cost??null},[Y.BASELINE_WORK_HOURS]:{valueKind:O.NUMBER,extract:e=>e.baselineSnapshot?.workHours??null},[Y.START_DATE]:{valueKind:O.DATE,extract:e=>e.startDate},[Y.END_DATE]:{valueKind:O.DATE,extract:e=>e.endDate},[Y.CONSTRAINT_DATE]:{valueKind:O.DATE,extract:e=>e.constraintDate},[Y.BASELINE_START_DATE]:{valueKind:O.DATE,extract:e=>e.baselineSnapshot?.startDate??null},[Y.BASELINE_END_DATE]:{valueKind:O.DATE,extract:e=>e.baselineSnapshot?.endDate??null},[Y.EARLY_START]:{valueKind:O.DATE,extract:e=>e.criticalPath?.earlyStart??null},[Y.EARLY_FINISH]:{valueKind:O.DATE,extract:e=>e.criticalPath?.earlyFinish??null},[Y.LATE_START]:{valueKind:O.DATE,extract:e=>e.criticalPath?.lateStart??null},[Y.LATE_FINISH]:{valueKind:O.DATE,extract:e=>e.criticalPath?.lateFinish??null},[Y.RESPONSABLE_IDS]:{valueKind:O.ID_ARRAY,extract:e=>e.responsableIds},[Y.TAG_IDS]:{valueKind:O.ID_ARRAY,extract:e=>e.tagIds},[Y.STATUS]:{valueKind:O.ENUM,order:Bf,extract:e=>e.status},[Y.CONSTRAINT_TYPE]:{valueKind:O.ENUM,order:Hf,extract:e=>e.constraintType},[Y.CALENDAR_ID]:{valueKind:O.REFERENCE,extract:e=>e.calendarId===null?null:String(e.calendarId)},[Y.SUBCONTRACT_ID]:{valueKind:O.REFERENCE,extract:e=>e.subcontractId===null?null:String(e.subcontractId)},[Y.IS_CRITICAL]:{valueKind:O.BOOLEAN,extract:e=>e.isCritical}};function fe(e){return Kf[e]??null}function zn(e){return e instanceof Date?e:typeof e=="string"||typeof e=="number"?new Date(e):new Date(Number.NaN)}function ee(e){return Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function jf(e,t,r){let i=e===null;return r===W.INCLUDES?!i&&String(e).toLowerCase().includes(t.toLowerCase()):r===W.NOT_INCLUDES?i||!String(e).toLowerCase().includes(t.toLowerCase()):r===W.IS?!i&&String(e)===t:r===W.IS_NOT?i||String(e)!==t:!1}function Yf(e,t,r,i){if(e===null||typeof e!="number")return r===W.NOT_EQUALS;let n=i===void 0?e:Number(e.toFixed(i));return r===W.EQUALS?n===t:r===W.NOT_EQUALS?n!==t:r===W.GREATER_THAN?e>t:r===W.LESS_THAN?e<t:r===W.GREATER_OR_EQUAL?e>=t:r===W.LESS_OR_EQUAL?e<=t:!1}function Gf(e,t,r){return typeof e=="number"&&e>=t&&e<=r}function $f(e,t,r){if(!(e instanceof Date))return!1;let i=ee(e),n=ee(t);return r===W.AFTER?i>n:r===W.BEFORE?i<n:!1}function zf(e,t,r){if(!(e instanceof Date))return!1;let i=ee(e);return i>=ee(t)&&i<=ee(r)}function qf(e,t,r){let n=(Array.isArray(e)?e:[]).some(o=>t.has(String(o)));return r===W.SOME_OF?n:r===W.NOT_SOME_OF?!n:!1}function Jf(e,t,r){let i=e!==null&&t.has(String(e));return r===W.SOME_OF?i:r===W.NOT_SOME_OF?!i:!1}function os(e){let t=Array.isArray(e)?e:[e];return new Set(t.map(r=>String(r)))}function as(e,t,r){let i=fe(t.field);if(i===null)return!1;let n=i.extract(e,r),{operator:o}=t;return o===W.BETWEEN?i.valueKind===O.NUMBER?Gf(n,Number(t.value),Number(t.valueTo)):i.valueKind===O.DATE?zf(n,zn(t.value),zn(t.valueTo)):!1:i.valueKind===O.STRING?jf(n,String(t.value),o):i.valueKind===O.NUMBER?Yf(n,Number(t.value),o,i.equalityPrecision):i.valueKind===O.DATE?$f(n,zn(t.value),o):i.valueKind===O.ID_ARRAY?qf(n,os(t.value),o):Jf(n,os(t.value),o)}function Xf(e,t,r){return t.criteria.length===0?!0:t.logic===li.OR?t.criteria.some(i=>as(e,i,r)):t.criteria.every(i=>as(e,i,r))}function Zf(e,t){let r=ee(e.startDate),i=ee(e.endDate),n=ee(t.start),o=ee(t.end),a=r>=n&&i<=o,s=r>=n&&r<=o,c=n>=r&&n<=i;return a||s||c}function qn(e,t,r){let i=Xf(e,t,r),n=t.dateRange,o=n===void 0||Zf(e,n);return i&&o}function Qf(e,t,r){let i=t(e);for(;i!==null&&!r.has(String(i));)r.add(String(i)),i=t(i)}function ss(e){let{activities:t,parentOf:r,filter:i,context:n}=e,o=new Set,a=[];for(let s of t)qn(s,i,n)&&(o.add(String(s.id)),a.push(s.id));for(let s of a)Qf(s,r,o);return o}function tp(e){let{activities:t,parentOf:r,filter:i,context:n}=e,o=new Set,a=new Map,s=new Map,c=new Map;for(let l of t){let d=String(l.id),u=r(d);s.set(d,u),c.set(d,c.get(d)??0),u!==null&&c.set(u,(c.get(u)??0)+1);let f=qn(l,i,n);a.set(d,f?1:0),f&&o.add(d)}return{matchedIds:o,visibleReferenceCounts:a,parentIds:s,remainingChildren:c}}function ep(e){let{visibleReferenceCounts:t,parentIds:r,remainingChildren:i}=e,n=[];for(let o of r.keys())i.get(o)===0&&n.push(o);for(;n.length>0;){let o=n.pop();if(o===void 0)break;let a=r.get(o);if(a==null)continue;let s=t.get(o)??0;t.set(a,(t.get(a)??0)+s);let c=(i.get(a)??1)-1;i.set(a,c),c===0&&n.push(a)}}function rp(e){let t=new Set;for(let[r,i]of e)i>0&&t.add(r);return t}function di(e){let t=tp(e);ep(t);let r=rp(t.visibleReferenceCounts);return{filter:e.filter,context:e.context,matchedIds:t.matchedIds,visibleIds:r,visibleReferenceCounts:t.visibleReferenceCounts}}function cs(e,t,r){let i=new Set;for(let n of t){let o=String(n.id);i.add(o);let a=e.matchedIds.has(o),s=qn(n,e.filter,e.context);if(a===s)continue;s?e.matchedIds.add(o):e.matchedIds.delete(o);let c=s?1:-1,l=o;for(;l!==null;){let d=e.visibleReferenceCounts.get(l)??0,u=d+c;e.visibleReferenceCounts.set(l,u);let f=d>0,p=u>0;f!==p&&(i.add(l),p?e.visibleIds.add(l):e.visibleIds.delete(l)),l=r(l)}}return i}function Re(e){return{hoursPerDay:e,locale:"en"}}var vt={UNKNOWN_FIELD:"unknown_field",UNKNOWN_OPERATOR:"unknown_operator",INVALID_VALUE:"invalid_value"},ip={[O.STRING]:new Set([W.INCLUDES,W.NOT_INCLUDES,W.IS,W.IS_NOT]),[O.NUMBER]:new Set([W.EQUALS,W.NOT_EQUALS,W.GREATER_THAN,W.LESS_THAN,W.GREATER_OR_EQUAL,W.LESS_OR_EQUAL,W.BETWEEN]),[O.DATE]:new Set([W.AFTER,W.BEFORE,W.BETWEEN]),[O.ID_ARRAY]:new Set([W.SOME_OF,W.NOT_SOME_OF]),[O.ENUM]:new Set([W.SOME_OF,W.NOT_SOME_OF]),[O.BOOLEAN]:new Set([W.SOME_OF,W.NOT_SOME_OF]),[O.REFERENCE]:new Set([W.SOME_OF,W.NOT_SOME_OF])};function ls(e){if(e===void 0)return{ok:!0,dateRange:void 0};if(typeof e!="object"||e===null)return{ok:!1,reason:vt.INVALID_VALUE};let{start:t,end:r}=e;if(!(t instanceof Date)||!(r instanceof Date))return{ok:!1,reason:vt.INVALID_VALUE};let i=t.getTime(),n=r.getTime();return!Number.isFinite(i)||!Number.isFinite(n)||i>n?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,dateRange:{start:new Date(i),end:new Date(n)}}}function ds(e){let t=fe(e.field);if(t===null)return{ok:!1,reason:vt.UNKNOWN_FIELD};if(!ip[t.valueKind].has(e.operator))return{ok:!1,reason:vt.UNKNOWN_OPERATOR};if(e.operator===W.BETWEEN)return np(e,t.valueKind);if(t.valueKind===O.NUMBER){let i=Jn(e.value);return i===null?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:i}}}if(t.valueKind===O.DATE){let i=Xn(e.value);return i===null?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:i}}}let r=op(e,t.valueKind);return r!==null?{ok:!1,reason:r}:t.valueKind===O.BOOLEAN?{ok:!0,criterion:{...e,value:[...new Set(e.value)]}}:t.valueKind===O.ID_ARRAY||t.valueKind===O.ENUM||t.valueKind===O.REFERENCE?{ok:!0,criterion:{...e,value:[...new Set(e.value.map(String))]}}:{ok:!0,criterion:e}}function np(e,t){if(t===O.NUMBER){let r=Jn(e.value),i=Jn(e.valueTo);return r===null||i===null||r>i?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:r,valueTo:i}}}if(t===O.DATE){let r=Xn(e.value),i=Xn(e.valueTo);return r===null||i===null||r.getTime()>i.getTime()?{ok:!1,reason:vt.INVALID_VALUE}:{ok:!0,criterion:{...e,value:r,valueTo:i}}}return{ok:!1,reason:vt.UNKNOWN_OPERATOR}}function op(e,t){let{value:r}=e;return t===O.BOOLEAN?Array.isArray(r)&&r.every(i=>typeof i=="boolean")?null:vt.INVALID_VALUE:t===O.ID_ARRAY||t===O.ENUM||t===O.REFERENCE?Array.isArray(r)&&r.every(i=>typeof i=="string"||typeof i=="number")?null:vt.INVALID_VALUE:Array.isArray(r)?vt.INVALID_VALUE:null}function Jn(e){if(typeof e=="string"&&e.trim()===""||typeof e!="string"&&typeof e!="number")return null;let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?t:null}function Xn(e){let t;if(e instanceof Date)t=new Date(e.getTime());else if(typeof e=="string")t=new Date(e);else if(typeof e=="number")t=new Date(e);else return null;return Number.isFinite(t.getTime())?t:null}function F(e){return structuredClone(e)}function us(e){return e.criteria.length===0&&e.dateRange===void 0}function ap(e,t,r){let i=e.getAllActivities();if(us(t))return{visibleIds:ss({activities:i,parentOf:o=>e.getParentId(o),filter:t,context:Re(r)}),projection:null};let n=di({activities:i,parentOf:o=>e.getParentId(o),filter:t,context:Re(r)});return{visibleIds:n.visibleIds,projection:n}}function fs(e,t){let{adapter:r,hoursPerDay:i}=t,n=[];for(let u of e.criteria){let f=ds(u);if(!f.ok)return{ok:!1,reason:f.reason};n.push(f.criterion)}let o=ls(e.dateRange);if(!o.ok)return{ok:!1,reason:o.reason};let a=F(o.dateRange===void 0?{criteria:n,logic:e.logic}:{criteria:n,logic:e.logic,dateRange:o.dateRange});r.setActiveFilter(us(a)?null:a);let{visibleIds:s,projection:c}=ap(r,a,i);r.setFilterProjection(c);let l=Xe(r,s);return{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[],viewState:l}}}var Pe={ASCENDING:"asc",DESCENDING:"desc"};var V="0";function M(e){return e==null||e===0||e==="0"}function Gt(e){return M(e)?"0":String(e)}var Zn=Number.MAX_SAFE_INTEGER;function Ht(e,t){let r=Or(e,t),i=t.getOrderComparator?.()??null;return r.sort(i===null?ui:(n,o)=>i(n,o)||ui(n,o)),r.map(n=>String(n.id))}function ys(e){let t=[],r=n=>{t.push(n);let o=Ht(String(n.id),e);for(let a of o){let s=e.getActivity(a);s&&r(s)}},i=Ht("0",e);for(let n of i){let o=e.getActivity(n);o&&r(o)}return t}function hs(e,t,r){let i=r.getActivity(e);if(!i)return null;let n=ms(i),o=Ht(n,r),a=o.findIndex(s=>String(s)===String(e));if(a<=0)return null;for(let s=a-1;s>=0;s--){let c=o[s];if(c!==void 0&&!sp(t,c))return c}return null}function Qn(e,t){let r=t.getActivity(e);if(!r)return-1;let i=ms(r);return Ht(i,t).findIndex(o=>String(o)===String(e))}function Or(e,t){let r=String(e)==="0"?t.getRootIds?.()??t.getChildren("0"):t.getChildren(e),i=[];for(let n of r){let o=t.getActivity(n);o&&i.push(o)}return i}function ui(e,t){let r=ps(e),i=ps(t);return r!==i?r-i:String(e.id).localeCompare(String(t.id))}function ps(e){let t=e.correlativeId,r=typeof t=="number"?t:Number(t);return Number.isFinite(r)?r:Zn}function ms(e){let t=e.parentId;return t===null?"0":t}function sp(e,t){return e.has(t)?!0:e.has(String(t))}function Ze(e){let t=[],r=i=>{let n=Ht(i,e);n.length>1&&t.push({parentId:i,childIds:n});for(let o of n)r(o)};return r("0"),t}function to(e,t){let r=[];for(let i of t){let n=Ht(i,e);n.length>1&&r.push({parentId:i,childIds:n})}return r}function cp(e){return fe(e.field)===null?vt.UNKNOWN_FIELD:e.direction!==Pe.ASCENDING&&e.direction!==Pe.DESCENDING?vt.UNKNOWN_OPERATOR:null}function Is(e,t){let{adapter:r}=t;for(let o of e.rules){let a=cp(o);if(a!==null)return{ok:!1,reason:a}}let i=e.rules.length===0?null:F({rules:e.rules});return r.setActiveOrder(i),{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[],order:Ze(r)}}}function gs(e,t){throw new Error(t)}function As(e,t){return()=>t()===e}var eo=typeof window>"u",lp=!eo&&typeof MessageChannel<"u";function st(){return lp?new Promise(e=>{let t=new MessageChannel;t.port1.onmessage=()=>{t.port1.close(),t.port2.close(),e()},t.port2.postMessage(null)}):Promise.resolve()}async function fi(e,t){return performance.now()-e<ns.YIELD_SLICE_MS?{aborted:!1,newSliceStart:e}:(await st(),t()?{aborted:!1,newSliceStart:performance.now()}:{aborted:!0,newSliceStart:performance.now()})}async function Qe(e){return eo||await st(),e()?{aborted:!1}:{aborted:!0}}function pi(e,t){let{inDegree:r,successors:i}=dp(e,t),n=up(r),o=fp(n,r,i),a=o.length<e.length,s=a?pp(e,o):[],c=[...o].reverse();return{ordered:o,reversed:c,hasCycles:a,cycleNodes:s}}function dp(e,t){let r=new Map,i=new Map;for(let n of e)r.set(n,0),i.set(n,[]);for(let n of t){let o=n.source,a=n.target;!r.has(o)||!r.has(a)||(i.get(o).push(a),r.set(a,(r.get(a)??0)+1))}return{inDegree:r,successors:i}}function up(e){let t=new xt;for(let[r,i]of e)i===0&&t.enqueue(r);return t}function fp(e,t,r){let i=[];for(;!e.isEmpty();){let n=e.dequeue();i.push(n);for(let o of r.get(n)??[]){let a=(t.get(o)??1)-1;t.set(o,a),a===0&&e.enqueue(o)}}return i}function pp(e,t){let r=new Set(t);return e.filter(i=>!r.has(i))}var yi=class{cached=null;invalidate(){this.cached=null}get(t,r){return this.cached?this.cached:(this.cached=pi(t,r),this.cached)}};function vs(e,t){let r=[];for(let i of e)t.has(i)&&r.push(i);return r}var ro={OWN_BASELINE:"own-baseline",RECURSIVE_LEAF_SUM:"recursive-leaf-sum",ZERO:"zero"},io={[D.PROJECT]:{alwaysSummary:!0,holdsConstraint:!1,carriesCustomId:!1,forcedDuration:null,ponderatorWeight:ro.RECURSIVE_LEAF_SUM,promotesToProjectOnFirstChild:!1},[D.TASK]:{alwaysSummary:!1,holdsConstraint:!0,carriesCustomId:!0,forcedDuration:null,ponderatorWeight:ro.OWN_BASELINE,promotesToProjectOnFirstChild:!0},[D.MILESTONE]:{alwaysSummary:!1,holdsConstraint:!0,carriesCustomId:!0,forcedDuration:0,ponderatorWeight:ro.ZERO,promotesToProjectOnFirstChild:!0}};function $t(e,t){return t||Kn(e)&&io[e].alwaysSummary}function re(e){return e===D.MILESTONE}function pe(e){return Kn(e)&&io[e].promotesToProjectOnFirstChild}var no=D.PROJECT,tr=D.TASK;function Nr(e,t){return t===0?D.MILESTONE:e===0&&t>0?D.TASK:null}function hi(e,t){let r=t.getActivity(e);return r?$t(r.type,t.getChildren(e).length>0):!1}function mi(e,t,r){let i=String(t),n=r.getActivity(e);for(;n?.parentId&&String(n.parentId)!=="0";){if(String(n.parentId)===i)return!0;n=r.getActivity(n.parentId)}return!1}function oo(e,t,r){let i=hi(e,r);return hi(t,r)&&mi(e,t,r)||i&&mi(t,e,r)}function Ts(e,t){let r=[],i=[e];for(;i.length>0;){let n=i.pop(),o=t.getChildren(n);if(o.length===0){String(n)!==String(e)&&r.push(n);continue}for(let a of o)i.push(a)}return r}function yp(e){let t=new Map;for(let r of e)Cs(t,String(r.source),r),Cs(t,String(r.target),r);return t}function Cs(e,t,r){let i=e.get(t);if(i){i.push(r);return}e.set(t,[r])}function hp(e,t,r,i){if(e.length<=1)return e;let n=new Set(e.map(String)),o=[];for(let a of e)mp(a,n,t,r,i)||o.push(a);return o.length>0?o:e}function mp(e,t,r,i,n){let o=String(e),a=r.getActivity(e);if(!a||a.autoScheduling===!1)return!1;let s=i.get(o)??[];for(let c of s)if(Ip(c,o,a,t,r,n))return!0;return!1}function Ip(e,t,r,i,n,o){if(gp(e)||!(o?String(e.source)===t:String(e.target)===t))return!1;let s=Ap(e,t);if(!i.has(String(s)))return!1;let c=n.getActivity(s);return!!(c?.autoScheduling!==!1&&c&&vp(e,r,c))}function gp(e){return e.source===e.target}function Ap(e,t){return String(e.source)===t?e.target:e.source}function vp(e,t,r){let i=e.lag??0,n=Math.abs(i);return String(e.target)===String(r.id)&&n<=r.durationHours||String(e.target)===String(t.id)&&n<=t.durationHours}function gi(e,t){let r=[],i=yp(e),n=0;for(let o of e){let a=hi(o.source,t),s=hi(o.target,t);if(Cp(o,a,s,t))continue;if(!a&&!s){r.push(o);continue}let c=Ss(o.source,a,t,i,!0),l=Ss(o.target,s,t,i,!1);n=Rp(r,c,l,o,t,n,i)}return r}function Cp(e,t,r,i){return r&&mi(e.source,e.target,i)||t&&mi(e.target,e.source,i)}function Ss(e,t,r,i,n){return t?hp(Ts(e,r),r,i,n):[e]}function Sp(e,t,r){let i=Ts(e,t);if(i.length===0)return null;let n=null,o=null;for(let a of i){let s=r(a);if(!s)continue;(n===null||s.startDate<n)&&(n=s.startDate),(o===null||s.endDate>o)&&(o=s.endDate)}return n===null||o===null?null:{startDate:n,endDate:o}}function Ii(e,t){return Sp(e,t,r=>{let i=t.getActivity(r);return i?{startDate:i.startDate,endDate:i.endDate}:null})}function Tp(e,t,r){return e?t?r.calculateDuration({startDate:t.startDate,endDate:t.endDate,task:e}):e.durationHours:0}function Ep(e,t,r,i){if(!t)return 0;let n=i.getActivity(e);return!r||!n?-t.durationHours:-i.calculateDuration({startDate:r.startDate,endDate:n.endDate,task:t})}function Dp(e,t){let r=String(e);return(t.get(r)??[]).some(n=>String(n.target)===r)}function _p(e,t,r,i,n){if(Dp(e,n))return 0;let o=i.getActivity(e);return!t||!o||!r?0:i.calculateDuration({startDate:t,endDate:o.startDate,task:r})}function kp(e,t){let r=t.getActivity(e.source),i=t.getActivity(e.target),n=Ii(e.source,t),o=Ii(e.target,t),a=e.type===H.START_TO_START||e.type===H.START_TO_FINISH,s=e.type===H.FINISH_TO_FINISH||e.type===H.START_TO_FINISH;return{source:r,sourceBounds:n,targetStart:o?.startDate??i?.startDate,userLag:e.lag??0,sourceEndpointIsStart:a,targetLag:s?-Tp(i,o,t):0,summarySourceId:e.type===H.START_TO_START&&n?e.source:void 0,finishAnchoredSummaryTargetId:s&&o?e.target:void 0}}function Rp(e,t,r,i,n,o,a){let s=kp(i,n),{source:c,sourceBounds:l,targetStart:d,userLag:u}=s,{sourceEndpointIsStart:f,targetLag:p,summarySourceId:y,finishAnchoredSummaryTargetId:g}=s,C=o;for(let L of t){let T=f?Ep(L,c,l,n):0;for(let E of r){if(String(L)===String(E))continue;let I=_p(E,d,c,n,a);e.push(Pp(i,L,E,C,T,p,u+I,y,g??(I!==0&&p===0?i.target:void 0))),C+=1}}return C}function Pp(e,t,r,i,n,o,a,s,c){return{id:`virtual_${e.id}_${i}`,source:t,target:r,type:e.type,lag:e.lag,freeSlackHours:null,isCritical:!1,_sourceLag:n,_targetLag:o,_trueLag:a,...s===void 0?{}:{_summarySourceId:s},...c===void 0?{}:{_summaryTargetId:c}}}var Ai=class{invalidate(){}get(t,r){return gi(t,r)}};function Lp(e){let t=new Map,r=i=>(t.has(i)||t.set(i,new Set),t.get(i));for(let i of e)r(i.source).add(i.id),r(i.target).add(i.id);return{neighbors:t}}function Op(e,t,r){let i=new Set,n=new Map,o=new xt;for(o.enqueue(e);!o.isEmpty();){let a=o.dequeue(),s=String(a);if(i.has(s))continue;i.add(s);let c=r.neighbors.get(a);if(c)for(let l of c){let d=t.get(l);if(!d)continue;let u=`${d.source}-${d.target}-${d.type}`;n.has(u)||n.set(u,d);let f=String(d.source)===s?d.target:d.source;i.has(String(f))||o.enqueue(f)}}return Array.from(n.values())}function Es(e,t){let r=new Map;for(let a of t)r.set(a.id,a);let i=Lp(t),n=Op(e,r,i),o=new Set([String(e)]);for(let a of n)o.add(String(a.source)),o.add(String(a.target));return{activityIds:o,links:n}}var Ds=0,br=100;function Le(e){return e===0}function _s(e,t,r){let i=r.type===H.FINISH_TO_START,n=r.type===H.FINISH_TO_FINISH;if(r._targetLag!==void 0)return{sourceLag:r._sourceLag??0,targetLag:r._targetLag,trueLag:r._trueLag??r.lag??0,isFS:i,isFF:n,isZeroDurationCase:!1};let o=r.lag??0;switch(r.type){case H.FINISH_TO_START:return{sourceLag:0,targetLag:0,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};case H.START_TO_START:return{sourceLag:-e.durationHours,targetLag:0,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};case H.FINISH_TO_FINISH:return{sourceLag:0,targetLag:-t.durationHours,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};case H.START_TO_FINISH:return{sourceLag:-e.durationHours,targetLag:-t.durationHours,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1};default:return{sourceLag:0,targetLag:0,trueLag:o,isFS:i,isFF:n,isZeroDurationCase:!1}}}function Np(e,t,r){if(e._summarySourceId===void 0)return null;let i=r.getActivity(e._summarySourceId);if(!i)return null;let n=Ii(e._summarySourceId,r);return n?-r.calculateDuration({startDate:n.startDate,endDate:t.endDate,task:i}):null}function bp(e,t,r,i,n){let o=t.durationHours===0&&n;return{successorStart:i.getClosestWorkTime({date:e.endDate,dir:o?"past":"future",task:t}),link:r}}function ks(e,t,r,i){let{sourceLag:n,targetLag:o,trueLag:a,isFS:s,isFF:c}=_s(e,t,r),l=Np(r,e,i)??n,d=l+o+a;if(!(t.durationHours===0?d!==0:l!==0||o!==0||a!==0))return bp(e,t,r,i,s||c);let p=s?t:e,y=i.getClosestWorkTime({date:e.endDate,dir:"future",task:p});if(l!==0&&(y=i.calculateEndDate({startDate:y,durationHours:l,task:e})),o!==0&&(y=i.calculateEndDate({startDate:y,durationHours:o,task:t})),a!==0&&(y=i.calculateEndDate({startDate:y,durationHours:a,task:t})),t.durationHours===0){if(s||c)return{successorStart:i.getClosestWorkTime({date:y,dir:"past",task:t}),link:r};let g=new Date(Date.UTC(y.getUTCFullYear(),y.getUTCMonth(),y.getUTCDate()));return{successorStart:i.getClosestWorkTime({date:g,dir:"future",task:t}),link:r}}return{successorStart:i.getClosestWorkTime({date:y,dir:"future",task:t}),link:r}}function Rs(e,t,r,i){let{sourceLag:n,targetLag:o,trueLag:a}=_s(t,e,r),s=i.getClosestWorkTime({date:e.startDate,dir:"past",task:e});return a!==0&&(s=i.calculateEndDate({startDate:s,durationHours:-a,task:e})),o!==0&&(s=i.calculateEndDate({startDate:s,durationHours:-o,task:e})),n!==0&&(s=i.calculateEndDate({startDate:s,durationHours:-n,task:t})),s}function Ps(e,t,r){for(let i of e){let n=t.getActivity(i);if(!n)continue;let o=n.constraintType;if(!o||o===A.ASAP||o===A.ALAP)continue;let a=qa(n,t);!a.earliestStart&&!a.latestStart&&!a.earliestEnd&&!a.latestEnd||r.set(i,{activityId:i,startDate:n.startDate,endDate:n.endDate,drivingLinkId:null,kind:A.ASAP,conflict:!1,earliestStart:a.earliestStart,latestStart:a.latestStart,earliestEnd:a.earliestEnd,latestEnd:a.latestEnd})}}function vi(e,t,r){let i={earliestStart:t.earliestStart??null,latestStart:t.latestStart??null,earliestEnd:t.earliestEnd??null,latestEnd:t.latestEnd??null},n=t.earliestSchedulingStart??t.latestSchedulingStart??null,o;n===null?o=Yn(e.startDate,i):Ja(n,i)?o=n:o=Yn(n,i),t.startDate=o,t.endDate=r.calculateEndDate({startDate:o,durationHours:e.durationHours,task:e})}function Ls(e,t){if(!e||!t)return new Date;let{constraintType:r,constraintDate:i}=e;if(!r||!i)return t;switch(r){case A.MSO:case A.MFO:return new Date(i);case A.SNET:case A.FNET:return i>t?new Date(i):t;case A.SNLT:case A.FNLT:return i<t?new Date(i):t;default:return t}}function Fp(e,t){return t.length?t.some(r=>String(r)===String(e)):!1}function Os(e,t,r){return ao(e.id,t,r)?{startDate:e.startDate,endDate:e.endDate}:{startDate:e.startDate,endDate:e.endDate}}function ao(e,t,r){return t.dragWithMultiple&&Fp(e,r)}async function Ns(e,t,r,i,n,o){let a=new Map;for(let u of t){let f=String(u.target);a.has(f)||a.set(f,[]),a.get(f).push(u)}let s=u=>{let f=o.get(u);if(f?.startDate&&f.endDate)return{startDate:f.startDate,endDate:f.endDate};let p=r.getActivity(u);return p?{startDate:p.startDate,endDate:p.endDate}:{startDate:new Date,endDate:new Date}},c=r.getFlags(),l=i.draggedIds??[],d=performance.now();for(let u of e){let f=await fi(d,n);if(f.aborted)return o;d=f.newSliceStart;let p=r.getActivity(u);if(!p||!p.autoScheduling||p.progress===100||wp(p,r))continue;let y=a.get(String(u))??[],g=null,C=null,L=!1;for(let B of y){let k=r.getActivity(B.source);if(!k)continue;let v=s(B.source),P=v.startDate.getTime()!==k.startDate.getTime()||v.endDate.getTime()!==k.endDate.getTime(),q={...k,startDate:v.startDate,endDate:v.endDate},$=Os(q,c,l),ot={...q,startDate:$.startDate,endDate:$.endDate},it=ao(B.source,c,l)?{...B,lag:0}:B,_t=ks(ot,p,it,r);(!g||_t.successorStart>g)&&(g=_t.successorStart,C=String(B.id),L=B._summaryTargetId!==void 0&&!P&&(B._targetLag===0||i.preventSummaryTargetPullback===!0))}g!==null&&L&&g<p.startDate&&(g=new Date(p.startDate));let E=o.get(u),I=E?{...E}:{activityId:u,startDate:p.startDate,endDate:p.endDate,drivingLinkId:null,kind:A.ASAP,conflict:!1},b=I.earliestStart||I.latestStart||I.earliestEnd||I.latestEnd;if(!(!g&&!b)){if(g){let B=g;p.type===D.MILESTONE&&(B=Ls(p,g)),I.drivingLinkId=C,I.startDate=B,I.endDate=r.calculateEndDate({startDate:B,durationHours:p.durationHours,task:p}),I.earliestSchedulingStart=B,I.earliestSchedulingEnd=I.endDate}else p.constraintType===A.MSO?I.earliestStart&&(I.startDate=I.earliestStart,I.endDate=I.earliestEnd??r.calculateEndDate({startDate:I.earliestStart,durationHours:p.durationHours,task:p})):p.constraintType===A.MFO&&I.latestStart&&(I.startDate=I.latestStart,I.endDate=I.latestEnd??r.calculateEndDate({startDate:I.latestStart,durationHours:p.durationHours,task:p}));vi(p,I,r),o.set(u,I)}}return o}function wp(e,t){return $t(e.type,t.getChildren(e.id).length>0)}async function bs(e,t,r,i,n,o){let a=new Map(r),s=i.getAllActivities(),c=s.length,l=[];for(let C of s)C.constraintType===A.ALAP&&l.push(C.id);if(l.length===0)return a;let d=new Map,u=new Map;for(let C of t){let L=String(C.source);d.has(L)||d.set(L,[]),d.get(L).push(C);let T=String(C.target);u.has(T)||u.set(T,[]),u.get(T).push(C)}let f=C=>{let L=a.get(C);if(L)return{startDate:L.startDate,endDate:L.endDate};let T=i.getActivity(C);return T?{startDate:T.startDate,endDate:T.endDate}:{startDate:new Date,endDate:new Date}},p=C=>!C.parentId||M(C.parentId)?i.getProjectEnd():f(C.parentId).endDate,y=(C,L)=>{let T=C,E=0;for(;T&&!M(T)&&E++<c+1;){if(String(T)===String(L))return!0;let I=i.getActivity(T);if(!I||!I.parentId)break;T=I.parentId}return!1},g=performance.now();for(let C of e){let L=await fi(g,o);if(L.aborted)return a;g=L.newSliceStart;let T=i.getActivity(C);if(!T||T.constraintType!==A.ALAP||!T.autoScheduling||T.progress===100||$t(T.type,i.getChildren(C).length>0))continue;let E=p(T);if(!E)continue;let I=E,b=null,B=!1,k=d.get(String(C))??[];for(let Yt of k){if((Yt.lag??0)<0)continue;let ze=i.getActivity(Yt.target);if(!ze||ze.autoScheduling===!1)continue;let Ya=f(Yt.target),pf={...ze,startDate:Ya.startDate,endDate:Ya.endDate},ii=Rs(pf,T,Yt,i);ii<I&&(I=ii),(b===null||ii<b)&&(b=ii,B=T.parentId&&!M(T.parentId)?y(Yt.target,T.parentId):!1)}if(b!==null)if(B)I=b;else{let Yt=f(C).endDate,ze=Yt.getTime()>E.getTime()?Yt:E;I=b<ze?b:ze}else I>E&&(I=E);let P=(u.get(String(C))??[]).some(Yt=>Yt.type===H.FINISH_TO_START||Yt.type===H.FINISH_TO_FINISH),q=new Date(Date.UTC(I.getUTCFullYear(),I.getUTCMonth(),I.getUTCDate())),$=()=>i.getClosestWorkTime({date:q,dir:"past",task:T}),ot=i.getClosestWorkTime({date:I,dir:"future",task:T}).getTime()===I.getTime(),it;T.durationHours===0&&b===null?it=P&&ot?$():i.getClosestWorkTime({date:I,dir:"past",task:T}):T.durationHours===0?P?it=$():it=i.getClosestWorkTime({date:I,dir:"future",task:T}):it=i.getClosestWorkTime({date:I,dir:"future",task:T});let _t=i.calculateEndDate({startDate:it,durationHours:-T.durationHours,task:T}),wt=a.get(C),ht=wt?{...wt}:{activityId:C,startDate:_t,endDate:it,drivingLinkId:null,kind:A.ALAP,conflict:!1};ht.startDate=_t,ht.endDate=it,ht.drivingLinkId=null,ht.kind=A.ALAP;let Ge=ht.earliestSchedulingStart??null;ht.earliestSchedulingStart=null,ht.earliestSchedulingEnd=null;let $e=Ge!==null&&Ge.getTime()>_t.getTime()?Ge:_t;ht.latestSchedulingStart=$e,ht.latestSchedulingEnd=$e===_t?it:i.calculateEndDate({startDate:$e,durationHours:T.durationHours,task:T}),vi(T,ht,i),a.set(C,ht)}return a}var er={warn(){},error(){}};var xp=864e5;function Qt(e){if(e.type===D.MILESTONE)return 0;let t=e.startDate?.getTime(),r=e.endDate?.getTime();return t==null||r==null||Number.isNaN(t)||Number.isNaN(r)?null:Math.floor((r-t)/xp)+1}function Fr(e,t){t.cancelled||t.updatedIds.length===0||e.batchUpdate(()=>{for(let r of t.updatedIds){let i=t.plans.get(r);if(!i)continue;let n=e.getLiveActivity(r);n&&(n.startDate=i.startDate,n.endDate=i.endDate,n.calendarDuration=Qt(n),e.updateActivity(r))}})}function so(e,t){let r=String(t.source),i=String(t.target);if(r===i)return!0;let n=new Map;for(let o of e){let a=String(o.source),s=String(o.target),c=n.get(a)??[];c.push(s),n.set(a,c)}return Mp(n,i,r)}function wr(e){let t=new Map,r=new Map;for(let o of e){let a=String(o.source),s=String(o.target),c=t.get(a)??[];c.push(s),t.set(a,c),r.set(a,r.get(a)??0),r.set(s,(r.get(s)??0)+1)}let i=new xt;for(let[o,a]of r)a===0&&i.enqueue(o);let n=0;for(;!i.isEmpty();){let o=i.dequeue();n+=1;for(let a of t.get(o)??[]){let s=r.get(a)-1;r.set(a,s),s===0&&i.enqueue(a)}}return n!==r.size}function Mp(e,t,r){if(t===r)return!0;let i=new Set([t]),n=new xt;for(n.enqueue(t);!n.isEmpty();){let o=n.dequeue(),a=e.get(o)??[];for(let s of a){if(s===r)return!0;i.has(s)||(i.add(s),n.enqueue(s))}}return!1}function Ci(e){let t=Up(e);for(let r of t.adjacency.keys())t.records.has(r)||Bp(r,t);return t.components}function Up(e){let t=new Map,r=new Set;for(let i of e){let n=String(i.source),o=String(i.target),a=Fs(t,n);if(Fs(t,o),n===o){r.add(n);continue}a.push(o)}return{adjacency:t,selfLooped:r,records:new Map,componentStack:[],nextIndex:0,components:[]}}function Fs(e,t){let r=e.get(t);if(r)return r;let i=[];return e.set(t,i),i}function Bp(e,t){let r=[];for(r.push({node:e,record:ws(e,t),neighborCursor:0});r.length>0;){let i=r[r.length-1];if(i===void 0)break;let n=t.adjacency.get(i.node)??[];if(i.neighborCursor<n.length){let s=n[i.neighborCursor];if(i.neighborCursor+=1,s===void 0)continue;Hp(i,s,r,t);continue}r.pop();let o=r[r.length-1];o&&i.record.lowLink<o.record.lowLink&&(o.record.lowLink=i.record.lowLink),i.record.lowLink===i.record.visitIndex&&Wp(i.node,t)}}function Hp(e,t,r,i){let n=i.records.get(t);if(!n){r.push({node:t,record:ws(t,i),neighborCursor:0});return}n.onStack&&n.visitIndex<e.record.lowLink&&(e.record.lowLink=n.visitIndex)}function ws(e,t){let r={visitIndex:t.nextIndex,lowLink:t.nextIndex,onStack:!0};return t.nextIndex+=1,t.records.set(e,r),t.componentStack.push({node:e,record:r}),r}function Wp(e,t){let r=[];for(;;){let a=t.componentStack.pop();if(a===void 0||(a.record.onStack=!1,r.push(a.node),a.node===e))break}let i=r[0],n=r.length===1&&i!==void 0&&t.selfLooped.has(i);(r.length>1||n)&&t.components.push(r)}function xr(e,t,r){let i=r?new co(e,r):e;return gi([...t],i)}var co=class{constructor(t,r){this.base=t;for(let[i,n]of r.reparented){let o=String(i),a=n===null||M(n)?null:n,s=t.getActivity(i)?.parentId??null,c=s===null||M(s)?null:String(s),l=a===null?null:String(a);if(c!==l){if(this.reparented.set(o,a),c!==null){let d=this.movedOutByParent.get(c)??new Set;d.add(o),this.movedOutByParent.set(c,d)}if(l!==null){let d=this.movedInByParent.get(l)??[];d.push(i),this.movedInByParent.set(l,d)}}}}base;reparented=new Map;movedOutByParent=new Map;movedInByParent=new Map;withOverride(t){if(!t)return null;let r=this.reparented.get(String(t.id));return r===void 0?t:{...t,parentId:r}}getActivity(t){return this.withOverride(this.base.getActivity(t))}getLiveActivity(t){return this.withOverride(this.base.getLiveActivity(t))}getAllActivities(){return this.base.getAllActivities().map(t=>this.withOverride(t)??t)}getChildren(t){let r=String(t),i=this.movedOutByParent.get(r),n=this.base.getChildren(t),o=i?n.filter(s=>!i.has(String(s))):[...n],a=this.movedInByParent.get(r);return a&&o.push(...a),o}getParent(t){let r=this.reparented.get(String(t));return r===void 0?this.base.getParent(t):r===null?null:this.getActivity(r)}isChildOf(t,r){let i=String(r),n=new Set,o=this.getActivity(t);for(;o;){let a=o.parentId;if(a===null||M(a))return!1;let s=String(a);if(s===i)return!0;if(n.has(s))return!1;n.add(s),o=this.getActivity(a)}return!1}getAllLinks(){return this.base.getAllLinks()}getAllIds(){return this.base.getAllIds()}getLink(t){return this.base.getLink(t)}activityExists(t){return this.base.activityExists(t)}getOutgoingLinkIds(t){return this.base.getOutgoingLinkIds(t)}getIncomingLinkIds(t){return this.base.getIncomingLinkIds(t)}getClosestWorkTime(t){return this.base.getClosestWorkTime(t)}calculateEndDate(t){return this.base.calculateEndDate(t)}calculateDuration(t){return this.base.calculateDuration(t)}batchUpdate(t){this.base.batchUpdate(t)}updateActivity(t){this.base.updateActivity(t)}getFlags(){return this.base.getFlags()}getProjectEnd(){return this.base.getProjectEnd()}};function Oe(e){let{port:t,proposedPort:r,currentLinks:i,proposedLinks:n,proposal:o}=e,a=xr(r??t,n,o);if(!wr(a))return{ok:!0};let s=xr(t,i),c=xs(s),d=[...xs(a)].filter(u=>!c.has(u));return d.length===0?{ok:!0}:{ok:!1,newlyCyclicActivityIds:d}}function xs(e){let t=new Set;for(let r of Ci(e))for(let i of r)t.add(i);return t}function ye(e,t){switch(e.kind){case dt.CREATE:return Vp(e,t);case dt.UPDATE:return Mr(e,t.port);case dt.DELETE:return Kp(e,t)}}function Ti(e,t){if(e.length===0)return{applied:!0};let r=t.port.getAllLinks(),i=new Map,n=[];for(let l of r){let d=Ms(l);i.has(d)||i.set(d,l.id),n.push({source:l.source,target:l.target})}let o=wr(n),a=null;for(let{operation:l,linkId:d}of e){if(String(l.source)===String(l.target)){a={applied:!1,rejected:At.SELF_LINK};break}if(!t.port.getActivity(l.source)||!t.port.getActivity(l.target)){a={applied:!1,rejected:At.ACTIVITY_MISSING};break}if(oo(l.source,l.target,t.port)){a={applied:!1,rejected:At.HIERARCHY_LINK};break}let u=Ms(l),f=i.get(u);if(f!==void 0){a={applied:!1,rejected:At.DUPLICATE,linkId:f};break}if(i.set(u,d),o&&so(n,{source:l.source,target:l.target}))return{applied:!1,rejected:At.CYCLE};n.push({source:l.source,target:l.target})}if(!o&&wr(n))return{applied:!1,rejected:At.CYCLE};if(a)return a;let s=[...r,...e.map(({operation:l,linkId:d})=>({id:d,source:l.source,target:l.target,type:l.type,lag:l.lag,freeSlackHours:null,isCritical:!1}))];if(!Oe({port:t.port,currentLinks:r,proposedLinks:s}).ok)return{applied:!1,rejected:At.CYCLE};for(let{operation:l,linkId:d}of e){let u=t.preserved?.get(d);t.port.addLink({id:d,source:l.source,target:l.target,type:l.type,lag:l.lag,freeSlackHours:null,isCritical:!1,...u?.ganttId===void 0?{}:{ganttId:u.ganttId},...u?.sectorId===void 0?{}:{sectorId:u.sectorId},...u?.proplannerId===void 0?{}:{proplannerId:u.proplannerId}})}return{applied:!0}}function Ms(e){return JSON.stringify([String(e.source),String(e.target),e.type])}function Vp(e,t){let{port:r}=t;if(String(e.source)===String(e.target))return{applied:!1,rejected:At.SELF_LINK};let i=r.getActivity(e.source),n=r.getActivity(e.target);if(!i||!n)return{applied:!1,rejected:At.ACTIVITY_MISSING};if(oo(e.source,e.target,r))return{applied:!1,rejected:At.HIERARCHY_LINK};let o=r.getAllLinks();for(let d of o)if(String(d.source)===String(e.source)&&String(d.target)===String(e.target)&&d.type===e.type)return{applied:!1,rejected:At.DUPLICATE,linkId:d.id};let a=o.map(d=>({source:d.source,target:d.target}));if(so(a,{source:e.source,target:e.target}))return{applied:!1,rejected:At.CYCLE};let s=(t.newLinkId??jp)(),c={id:s,source:e.source,target:e.target,type:e.type,lag:e.lag,freeSlackHours:null,isCritical:!1};return Oe({port:r,currentLinks:o,proposedLinks:[...o,c]}).ok?(r.addLink(c),{applied:!0,linkId:s}):{applied:!1,rejected:At.CYCLE}}function Mr(e,t){return t.getLink(e.linkId)?(e.lag!==void 0&&t.setLinkField(e.linkId,"lag",e.lag),e.type!==void 0&&t.setLinkField(e.linkId,"type",e.type),{applied:!0,linkId:e.linkId}):{applied:!1,rejected:At.LINK_MISSING}}function Kp(e,t){let{port:r}=t;return r.getLink(e.linkId)?(r.removeLink(e.linkId),{applied:!0,linkId:e.linkId}):{applied:!1,rejected:At.LINK_MISSING}}var Si=null;function jp(){return Si===null&&(Si=Date.now()),Si+=1,String(Si)}var Ct={FINISH_TO_START:"fs",START_TO_START:"ss",FINISH_TO_FINISH:"ff",START_TO_FINISH:"sf"},Ei={[H.FINISH_TO_START]:Ct.FINISH_TO_START,[H.START_TO_START]:Ct.START_TO_START,[H.FINISH_TO_FINISH]:Ct.FINISH_TO_FINISH,[H.START_TO_FINISH]:Ct.START_TO_FINISH},Ne={[Ct.FINISH_TO_START]:H.FINISH_TO_START,[Ct.START_TO_START]:H.START_TO_START,[Ct.FINISH_TO_FINISH]:H.FINISH_TO_FINISH,[Ct.START_TO_FINISH]:H.START_TO_FINISH},Us=Ct.FINISH_TO_START;function Bs(e){if(e in Ne)return Ne[e]}var Hs=";",he={DAY:"d",WEEK:"w",WEEK_DHTMLX:"wk",MONTH:"m",MONTH_DHTMLX:"mon",YEAR:"y"},Ws=/^(\d+)(fs|ss|ff|sf)?(?:([+-]?)(\d+(?:\.\d+)?)(weeks?|wk|w|months?|mon|m|days?|d|years?|y)?)?$/i;var Yp=5,Di=30,lo=365,Gp={[he.DAY]:1,day:1,days:1,[he.MONTH]:Di,[he.MONTH_DHTMLX]:Di,month:Di,months:Di,[he.YEAR]:lo,year:lo,years:lo},$p=new Set([he.WEEK,he.WEEK_DHTMLX,"week","weeks"]);function _i(e,t={}){let r=[],i=[],n=t.daysPerWeek!==void 0&&Number.isFinite(t.daysPerWeek)&&t.daysPerWeek>0?t.daysPerWeek:Yp,o=e.replace(/\s+/g,"");if(o.length===0)return{specs:r,errors:i};for(let a of o.split(Hs)){if(a.length===0)continue;let s=zp(a,n);s?r.push(s):i.push(a)}return{specs:r,errors:i}}function zp(e,t){let r=e.toLowerCase(),i=Ws.exec(r);if(!i)return null;let[,n,o,a,s,c]=i,l=o?Ne[o]:Ne[Us],d=0;if(s!==void 0){let u=Number(s);if(Number.isNaN(u))return null;let f=c!==void 0&&$p.has(c)?t:Gp[c??he.DAY],p=u*f;d=a==="-"?-p:p}return{correlativeId:n,type:l,lag:d}}function Ri(e){let{targetActivityId:t,currentLinks:r,desiredSpecs:i}=e,n=[],o=new Map;for(let c of i){let l=e.resolveActivityByCorrelative(c.correlativeId);if(l==null){n.push(c);continue}let d=ki(l,c.type);o.has(d)||o.set(d,{source:l,type:c.type,lag:c.lag})}let a=new Map;for(let c of r)String(c.target)===String(t)&&a.set(ki(c.source,c.type),c);let s=[];for(let[c,l]of a)o.has(c)||s.push({kind:dt.DELETE,linkId:l.id});for(let[c,l]of o){let d=a.get(c);d&&d.lag!==l.lag&&s.push({kind:dt.UPDATE,linkId:d.id,lag:l.lag})}for(let[c,l]of o)a.has(c)||s.push({kind:dt.CREATE,source:l.source,target:t,type:l.type,lag:l.lag});return{operations:s,unresolved:n}}function ki(e,t){return`${String(e)}::${t}`}function Pi(e){let{sourceActivityId:t,currentLinks:r,desiredSpecs:i}=e,n=[],o=new Map;for(let c of i){let l=e.resolveActivityByCorrelative(c.correlativeId);if(l==null){n.push(c);continue}let d=ki(l,c.type);o.has(d)||o.set(d,{target:l,type:c.type,lag:c.lag})}let a=new Map;for(let c of r)String(c.source)===String(t)&&a.set(ki(c.target,c.type),c);let s=[];for(let[c,l]of a)o.has(c)||s.push({kind:dt.DELETE,linkId:l.id});for(let[c,l]of o){let d=a.get(c);d&&d.lag!==l.lag&&s.push({kind:dt.UPDATE,linkId:d.id,lag:l.lag})}for(let[c,l]of o)a.has(c)||s.push({kind:dt.CREATE,source:t,target:l.target,type:l.type,lag:l.lag});return{operations:s,unresolved:n}}function Li(e){let t=Math.sign(e)*Math.round(Math.abs(e));return Object.is(t,-0)?0:t}function Wt(e,t){return Math.sign(e)*Math.round(Math.abs(e)*t)}var Vs={rawInputToConstraintDate(e,t){let r=new Date(e);return r.setUTCHours(0,0,0,0),r.getTime()===e.getTime()?t.getClosestWorkTime({direction:K.FUTURE,date:e,unit:mt.HOUR}):t.isWorkTime(e,mt.HOUR)?e:r},computeLagBetweenTasks(e,t,r){return r.calculateDuration(e,t)}};function uo(e,t,r){switch(r){case H.FINISH_TO_START:return{sourceDate:e.endDate,targetDate:t.startDate};case H.START_TO_START:return{sourceDate:e.startDate,targetDate:t.startDate};case H.FINISH_TO_FINISH:return{sourceDate:e.endDate,targetDate:t.endDate};case H.START_TO_FINISH:return{sourceDate:e.startDate,targetDate:t.endDate}}}var fo=Vs;var rr=class{adapter;reporter;currentCalculationId=0;topoCache=new yi;expandedLinksCache=new Ai;constructor(t,r=er){this.adapter=t,this.reporter=r}getCurrentCalculationId(){return this.currentCalculationId}invalidateTopoCache(){this.topoCache.invalidate()}invalidateExpandedLinksCache(){this.expandedLinksCache.invalidate()}invalidateAllCaches(){this.topoCache.invalidate(),this.expandedLinksCache.invalidate()}async schedule(t={}){let r=++this.currentCalculationId,i=As(r,()=>this.currentCalculationId),n={plans:new Map,updatedIds:[],cycles:[],cancelled:!1};try{Xp(this.adapter);let o=me("schedule.total"),a=me("schedule.expandParentLinks"),s=this.adapter.getAllLinks(),c=this.expandedLinksCache.get(s,this.adapter);ie(a);let l=c;if((await Qe(i)).aborted)return{...n,cancelled:!0};let d=me("schedule.scoping"),u=this.adapter.getAllIds(),f=Zp(t,l,this.adapter),p=f.links,y=f.idSet;ie(d);let g=me("schedule.topologicalSort"),C=ty(this.topoCache,u,l,y);if(ie(g),C.hasCycles)return ie(o),{...n,cycles:[C.cycleNodes]};if((await Qe(i)).aborted)return{...n,cancelled:!0};let L=me("schedule.processConstraints"),T=new Map;if(Ps(C.ordered,this.adapter,T),ie(L),(await Qe(i)).aborted)return{...n,cancelled:!0};let E=me("schedule.asapPass"),I=await Ns(C.ordered,p,this.adapter,t,i,T);if(ie(E),(await Qe(i)).aborted)return{...n,cancelled:!0};let b=me("schedule.alapPass"),B=await bs(C.reversed,p,I,this.adapter,t,i);if(ie(b),(await Qe(i)).aborted)return{...n,cancelled:!0};let k=me("schedule.diff"),v=[];for(let[P,q]of B){let $=this.adapter.getActivity(P);if(!$)continue;let ot=$.startDate.getTime()!==q.startDate.getTime(),it=$.endDate.getTime()!==q.endDate.getTime();(ot||it)&&v.push(P)}return ie(k),ie(o),{plans:B,updatedIds:v,cycles:[],cancelled:!1}}catch(o){throw this.reporter.error("[AutoScheduler] Error during scheduling",o),o}}},qp=!1;function Jp(){let e=globalThis.__SCHEDULER_PHASE_LOG__;return typeof e=="boolean"?e:qp}function me(e){return{name:e,startedAt:performance.now()}}function Xp(e){let t=e;typeof t.clearCalendarCache=="function"&&t.clearCalendarCache()}function ie(e){if(!Jp())return;let t=performance.now()-e.startedAt;console.log(`[scheduler] ${e.name} ${t.toFixed(1)}ms`)}function Zp(e,t,r){let i=e.triggerId;if(i==null)return{idSet:null,links:t};let n=Es(i,t);return Qp(n,t,r)}function Qp(e,t,r){let i=new Set(e.activityIds),n=new Set;for(let a of r.getAllActivities()){let s=String(a.id);a.constraintType===A.ALAP&&!i.has(s)&&(n.add(s),i.add(s))}if(n.size===0)return{idSet:i,links:e.links};let o=[...e.links];for(let a of t)(n.has(String(a.source))||n.has(String(a.target)))&&o.push(a);return{idSet:i,links:o}}function ty(e,t,r,i){let n=e.get(t,r);if(n.hasCycles){let a=i?Array.from(i):t;return pi(a,r)}if(!i)return n;let o=vs(n.ordered,i);return{ordered:o,reversed:[...o].reverse(),hasCycles:!1,cycleNodes:[]}}function Ks(e,t,r){let i=t.getActivity(e);if(!i)return;let n=r?{...i,endDate:r.endDate}:i,o=t.calendarReader.getCalendar(String(i.calendarId));for(let a of t.getIncomingLinkIds(e)){let s=t.getLink(a);if(!s)continue;let c=t.getActivity(s.source);if(!c||c.constraintType===A.ALAP||re(i.type)&&(s.type===H.START_TO_FINISH||s.type===H.FINISH_TO_FINISH))continue;let{sourceDate:d,targetDate:u}=uo(c,n,s.type),f=fo.computeLagBetweenTasks(d,u,o);f!==s.lag&&Mr({kind:dt.UPDATE,linkId:s.id,lag:f},t)}}function js(e,t){let r=t.getActivity(e);r&&re(r.type)&&(r.durationHours=0)}function Oi(e){let t=0,r=!1;for(let i of e)i.ponderator>0&&(t+=i.ponderator/100*i.progress,r=!0);return r?t:null}function Ys(e){return Number(e.toFixed(2))}function Ur(e){for(let t of ey(e))$s(t,e)}function Gs(e,t){for(let r of e)$s(r,t)}function ey(e){let t=new Set;e.forEachActivity((i,n)=>{e.getChildren(n).length>0&&t.add(n)});let r=new Map;for(let i of t)r.set(i,ry(i,e));return[...t].sort((i,n)=>(r.get(n)??0)-(r.get(i)??0))}function ry(e,t){let r=0,i=e;for(;i&&i!=="0"&&t.getActivity(i);)r+=1,i=t.getParentId(i);return r}function $s(e,t){let r=t.getChildren(e);if(r.length===0)return;let i=[];for(let n of r){let o=t.getActivity(n);o&&i.push({progress:Number(o.progress??0),ponderator:Number(o.ponderator??0)})}po(e,i,t)}function po(e,t,r){let i=r.getActivity(e);if(!i)return;let n=Oi(t);if(n===null){let o=r.getProgressFallback(e);o!==null&&r.setActivityField(e,_.PROGRESS,o);return}r.getProgressFallback(e)===null&&r.setProgressFallback(e,Number(i.progress??0)),r.setActivityField(e,_.PROGRESS,Ys(n))}function zs(e,t,r){let i=[e];for(;i.length>0;){let n=i.pop();if(n===void 0)continue;let o=r.getChildren(n);o.length!==0&&(r.setProgressFallback(n,t),i.push(...o))}}function Nt(e,t){return(Number(e)||0)*(Number(t)||0)/100}var Br={SKIP:"skip",FREEZE_WITHOUT_CONTRIBUTION:"freeze-when-no-contribution"};async function ir(e,t,r=!0,i={}){let n=t?Hr(e,t):cy(e),o=r?i.progressMode??Br.FREEZE_WITHOUT_CONTRIBUTION:Br.SKIP;await iy(n,e,o,{recomputeRealWork:i.recomputeRealWork??!1})}function Ni(e,t){qs(e,t,Br.SKIP)}async function iy(e,t,r,i={recomputeRealWork:!1}){let o=0;for(let a of e)qs(a,t,r,i.recomputeRealWork),o+=1,o%200===0&&await st()}function Hr(e,t){let r=new Set,i=new Map;for(let a of t)ny(a,e,r,i);if(r.size===0)return[];let n=Array.from(r),o=oy(n,i);return Js(n,o)}function ny(e,t,r,i){let n=t.getParentId(e);for(;n&&!M(n);){if(r.has(n))return;r.add(n);let o=t.getParentId(n);i.set(n,o),n=o}}function oy(e,t){let r=new Map;for(let i of e){if(r.has(i))continue;let n=[],o=new Set,a=i;for(;a&&!M(a)&&!r.has(a)&&!o.has(a);)n.push(a),o.add(a),a=t.get(a)??null;let s=a?r.get(a)??0:0;for(let c=n.length-1;c>=0;c-=1)s+=1,r.set(n[c],s)}return r}function ay(e,t,r){let i=null,n=null,o=0,a=[];for(let s of e){let c=t.getActivity(s);if(!c)continue;let l=c.startDate.getTime(),d=c.endDate.getTime();(i===null||l<i)&&(i=l),(n===null||d>n)&&(n=d),r&&(o+=sy(c,t.getChildren(s).length>0)),a.push({progress:Number(c.progress??0),ponderator:Number(c.ponderator??0)})}return{minStart:i,maxEnd:n,realWorkSum:o,weightedChildren:a}}function qs(e,t,r=Br.FREEZE_WITHOUT_CONTRIBUTION,i=!1){let n=t.getActivity(e);if(!n)return;let o=t.getChildren(e);if(o.length===0)return;let a=ay(o,t,i);if(a.minStart===null||a.maxEnd===null)return;let s=String(n.calendarId??""),c=t.calendarReader.getCalendar(s),l=new Date(a.minStart),d=new Date(a.maxEnd),u=c.calculateDuration(l,d);t.setActivityField(e,"startDate",l),t.setActivityField(e,"endDate",d),t.setActivityField(e,"durationHours",u),r!==Br.SKIP&&po(e,a.weightedChildren,t),i&&t.setActivityField(e,"realWorkHours",a.realWorkSum)}function sy(e,t){return t?Number(e.realWorkHours)||0:Nt(e.workHours,e.progress)}function cy(e){let t=ly(e),r=dy(t,e);return Js(t,r)}function ly(e){let t=new Set;return e.forEachActivity(r=>{r.parentId!==null&&t.add(r.parentId)}),Array.from(t)}function dy(e,t){let r=new Map;for(let i of e)r.set(i,uy(i,t));return r}function uy(e,t){let r=0,i=e;for(;i&&!M(i)&&t.getActivity(i);)r+=1,i=t.getParentId(i);return r}function Js(e,t){return[...e].sort((r,i)=>(t.get(i)??0)-(t.get(r)??0))}var Xs={updateActivityDuration:js,updateTaskTiming:py("updateTaskTiming"),adjustLinkLagOnTaskMove:Ks,recordLastStartDate:fy};function fy(e,t){let r=t.getActivity(e);r&&t.setLastStartDate(e,r.startDate)}function Ie(e,t,r,i){for(let n of t){let o=n in Xs?Xs[n]:void 0;if(!o){console.warn(`[replay post-processors] unknown: ${n} \u2014 skipping. Add an entry in POST_PROCESSORS if a fixture needs it.`);continue}o(e,r,i??null)}}function py(e){return()=>{console.debug(`[replay post-processors] ${e}: not yet ported to adapter \u2014 no-op.`)}}function j(e,t){return t!==void 0?{ok:!0,value:e,raw:t}:{ok:!0,value:e}}function J(e){return{ok:!1,reason:e}}function tt(){return{valid:!0}}function ut(e,t){return t!==void 0?{valid:!1,reason:e,notification:t}:{valid:!1,reason:e}}function X(){return{allowed:!0}}function nt(e,t){return t!==void 0?{allowed:!1,reason:e,alertKey:t}:{allowed:!1,reason:e}}function Q(e,t={}){return{patch:e,needsAutoSchedule:t.autoSchedule??!1,postProcessors:t.postProcessors??[],...t.cascadeMutations!==void 0?{cascadeMutations:t.cascadeMutations}:{},...t.trackingEvents!==void 0?{trackingEvents:t.trackingEvents}:{}}}var lt={PROGRESS_ENTRY:"activity_progress_entry",PROGRESS_UPDATE_RADIO_BUTTON:"activity_progress_update_radio_button",DURATION_ENTRY:"activity_duration_entry",START_DATE_ENTRY:"activity_start_date_entry",END_DATE_ENTRY:"activity_end_date_entry",NAME_ENTRY:"activity_name_entry",DESCRIPTION_ENTRY:"activity_description_entry",CALENDAR_ASSIGNMENT:"activity_calendar_assignment",COST_BUDGETED_ENTRY:"activity_cost_budgeted_entry",COST_SPENT_ENTRY:"activity_cost_spent_entry",LABOR_HOURS_BUDGETED_ENTRY:"activity_labor_hours_budgeted_entry"};var Zs={targetField:"name",canEdit(){return X()},parseInput(e){return typeof e!="string"?J("not_a_string"):j(e)},validate(){return tt()},transform(e,t){return Q({name:t},{autoSchedule:!1,postProcessors:[]})},trackEvent:lt.NAME_ENTRY};var Qs={targetField:"description",canEdit(){return X()},parseInput(e){return typeof e!="string"?J("not_a_string"):j(e.trim())},validate(){return tt()},transform(e,t){return Q({description:t},{autoSchedule:!1,postProcessors:[]})},trackEvent:lt.DESCRIPTION_ENTRY};function zt(e){return e.constraintType??A.ASAP}var bi=100;function ge(e){return e.progress>=bi}function ft(e,t){return $t(e.type,t.hasChildren(e.id))}function tc(e){return e.progress>0}function ec(e){return e.hasLookaheadTasks}function be(e,t){return Math.round(Math.ceil(e*t*60)/60)}var nr=e=>({endDate:e});var Fi="UTC";function Ae(e,t){if(t){let r=new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(e),i=n=>Number(r.find(o=>o.type===n)?.value);return new Date(Date.UTC(i("year"),i("month")-1,i("day")))}return new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()))}function xi(e,t){if(!t||t===Fi){let f=new Date(e);return f.setUTCHours(23,59,0,0),f}let r=new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"}).formatToParts(e),i=f=>Number(r.find(p=>p.type===f)?.value),n=i("year"),o=i("month"),a=i("day"),s=Date.UTC(n,o-1,a,23,59,0,0),c=new Intl.DateTimeFormat("en-CA",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(s)),l=f=>Number(c.find(p=>p.type===f)?.value),u=Date.UTC(l("year"),l("month")-1,l("day"),l("hour")===24?0:l("hour"),l("minute"),l("second"))-s;return new Date(s-u)}function yy(e,t){let r=Ae(t,Fi);for(;!e.isWorkTime(r,mt.DAY);)r=new Date(r),r.setUTCDate(r.getUTCDate()+1),r=Ae(r,Fi);return r}function yo(e,t){return e.getClosestWorkTime({direction:K.FUTURE,date:t,unit:mt.HOUR})}function ho(e,t){let r=yy(e,t),i=new Date(r);return i.setUTCDate(i.getUTCDate()+1),i.setUTCHours(0,0,0,0),e.getClosestWorkTime({direction:K.PAST,date:i,unit:mt.HOUR})}var wi=new Set([A.SNET,A.SNLT,A.MSO]),mo=new Set([A.FNET,A.FNLT,A.MFO]),ve=new Set([A.ASAP,A.ALAP]),Mi=A.SNET;function ne(e,t,r){let i=Ae(e,Fi);if(!wi.has(r)&&!mo.has(r))return i;let n=wi.has(r)?yo(t,i):ho(t,i),o=new Date(i);return o.setUTCHours(n.getUTCHours(),n.getUTCMinutes(),n.getUTCSeconds(),n.getUTCMilliseconds()),o}var Ce=()=>({constraintType:Mi});var Fe=e=>({constraintDate:e}),rc=e=>({constraintDate:e});var ic={UPDATE_ACTIVITY_DURATION:"updateActivityDuration",UPDATE_TASK_TIMING:"updateTaskTiming",ADJUST_LINK_LAG_ON_TASK_MOVE:"adjustLinkLagOnTaskMove",RECORD_LAST_START_DATE:"recordLastStartDate"};var nc={UNCHANGED:"unchanged",OUT_OF_RANGE:"out_of_range",NEGATIVE_DURATION:"negative_duration",NOT_WORKING_DAY:"not_working_day",BEFORE_PARENT_START:"before_parent_start",BEFORE_START_DATE:"before_start_date",BEFORE_DATE_ORIGIN:"before_date_origin",CONSTRAINT_VIOLATION:"constraint_violation",MISSING_ID:"missing_id",UNKNOWN_CALENDAR:"unknown_calendar"},Wr={COMPLETED:"completed",SUMMARY:"summary",HAS_PROGRESS:"has_progress",HAS_LOOKAHEAD_TASKS:"has_lookahead_tasks",SIR_START_AFTER_PROGRESS:"sir_start_after_progress"},oc={CANT_EDIT_COMPLETED:"cant_edit_completed_activity",SUMMARY_COLUMN_VALUE:"summary_column_value",CANT_EDIT_WITH_PROGRESS:"cant_edit_activity_with_progress",SIR_CANT_MOVE_START_AFTER_PROGRESS:"sir_cant_move_start_after_progress",CANT_EDIT_WITH_TASK:"cant_edit_actvity_with_task"};function or(e,t,r){return $a(e,t,r)}function ar(e,t,r){return za(e,t,r)}var sc={targetField:"durationHours",canEdit(e,t){return ge(e)?nt("completed","cant_edit_completed_activity"):ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e,t,r){let i=parseFloat(String(e));return Number.isFinite(i)?j(be(i,r.hoursPerDay)):J("not_a_number")},validate(e,t,r){return ac(r)?ut(nc.NEGATIVE_DURATION):hy(t,r)?ut("unchanged"):tt()},transform(e,t,r){if(ac(t))return Q({},{autoSchedule:!1,postProcessors:[]});let i=my(e,t,r),n=Iy(e,t,r,i.violated);return{...Q(n,{autoSchedule:!0,postProcessors:[ic.RECORD_LAST_START_DATE]}),...i.violated?{constraintWarning:ar(i.constraintType,i.constraintDate,cc(e,t,r)??void 0)}:{}}},trackEvent:lt.DURATION_ENTRY};function ac(e){return Math.sign(e)===-1}function hy(e,t){return e===t}function my(e,t,r){let i=r.calendars.getCalendar(e.calendarId);if(!i)return{violated:!1};let n=e.constraintType;if(n!==A.FNET&&n!==A.FNLT&&n!==A.MFO)return{violated:!1};let o=i.calculateEndDate(e.startDate,t);return or(n,e.constraintDate,o)}function Iy(e,t,r,i=!1){let n={};i&&Object.assign(n,Ce(),Fe(e.startDate));let o=Nr(e.durationHours,t);o&&(n.type=o),n.durationHours=t;let a=cc(e,t,r);return a&&Object.assign(n,nr(a)),n}function cc(e,t,r){let i=r.calendars.getCalendar(e.calendarId);return i?i.calculateEndDate(e.startDate,t):null}var sr=e=>({realWorkHours:e});var gy=0,Ay=bi,Ui={targetField:"progress",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):ec(e)?nt("has_lookahead_tasks","cant_edit_actvity_with_task"):X()},parseInput(e){let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(e,t,r){return vy(r)?ut("out_of_range"):tt()},transform(e,t,r){let i=Le(t),n=e.progress!==t&&i,o=Cy(t),a=Ey(e,t,r.hierarchy),s={progress:t,autoScheduling:i,...sr(a.get(e.id)??0)},c=o?Sy(e,t,i,r.hierarchy,a):[],l=o?_y(e,t,r.hierarchy):[],d=c.length+l.length>0?[...c,...l]:void 0,u=[],f=o?Ry(e,t):void 0;return Q(s,{autoSchedule:n,postProcessors:u,cascadeMutations:d,trackingEvents:f})},trackEvent:lt.PROGRESS_ENTRY};function vy(e){return e<gy||e>Ay}function Cy(e){return e===bi||Le(e)}function Sy(e,t,r,i,n){return i.getDescendantIds(e.id).map(a=>({activityId:a,fields:Ty(t,r,n.get(a)??0)}))}function Ty(e,t,r){return{progress:e,autoScheduling:t,...sr(r)}}function Ey(e,t,r){let i=new Map,n=a=>{let s=0;for(let c of r.getChildHhInfo(a)){let l=r.hasChildren(c.id)?n(c.id):Nt(c.workHours,t);i.set(c.id,l),s+=l}return s},o=r.hasChildren(e.id)?n(e.id):Nt(e.workHours,t);return i.set(e.id,o),i}function Dy(e,t){let r=[e.id,...t.getDescendantIds(e.id)],i=o=>t.getChildProgressInfo(o).some(a=>t.hasChildren(a.id)),n=o=>t.getAncestorIds(o).length;return r.filter(o=>i(String(o))).map(String).sort((o,a)=>n(a)-n(o))}function _y(e,t,r){let i=new Map;i.set(e.id,t);for(let a of r.getDescendantIds(e.id))i.set(a,t);let n=[...Dy(e,r),...r.getAncestorIds(e.id)],o=[];for(let a of n){let s=ky(a,i,r);s!==null&&(i.set(a,s),o.push({activityId:a,fields:{progress:s}}))}return o}function ky(e,t,r){let i=r.getChildProgressInfo(e).map(o=>({progress:t.has(o.id)?t.get(o.id):o.progress,ponderator:o.ponderator??0})),n=Oi(i);return n===null?null:Number(n.toFixed(2))}function Ry(e,t){return[{name:lt.PROGRESS_UPDATE_RADIO_BUTTON,properties:{activity_id:e.id,activity_name:e.name,progress_updated:t}}]}var lc={targetField:"cost",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(String(e).trim()==="")return j(0);let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(){return tt()},transform(e,t,r){let i=Py(e,t,r.hierarchy);return Q({cost:t},{autoSchedule:!1,postProcessors:[],cascadeMutations:i})},trackEvent:lt.COST_BUDGETED_ENTRY};function Py(e,t,r){let i=new Map;i.set(e.id,t);let n=[];for(let o of r.getAncestorIds(e.id)){let a=0;for(let s of r.getChildCostInfo(o))a+=i.has(s.id)?i.get(s.id):s.cost;i.set(o,a),n.push({activityId:o,fields:{cost:a}})}return n}var dc={targetField:"usedCost",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(String(e).trim()==="")return j(0);let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(){return tt()},transform(e,t,r){let i=Ly(e,t,r.hierarchy);return Q({usedCost:t},{autoSchedule:!1,postProcessors:[],cascadeMutations:i})},trackEvent:lt.COST_SPENT_ENTRY};function Ly(e,t,r){let i=new Map;i.set(e.id,t);let n=[];for(let o of r.getAncestorIds(e.id)){let a=0;for(let s of r.getChildUsedCostInfo(o))a+=i.has(s.id)?i.get(s.id):s.usedCost;i.set(o,a),n.push({activityId:o,fields:{usedCost:a}})}return n}var uc={targetField:"workHours",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(String(e).trim()==="")return j(0,e);let t=parseFloat(String(e));return Number.isNaN(t)?J("not_a_number"):j(t)},validate(){return tt()},transform(e,t,r,i){let n=fc(t,e.progress),o=String(i).trim()===""?[]:Oy(e,t,n,r.hierarchy);return Q({workHours:t,...sr(n)},{autoSchedule:!1,postProcessors:[],cascadeMutations:o})},trackEvent:lt.LABOR_HOURS_BUDGETED_ENTRY};function fc(e,t){return Nt(e,t)}function Oy(e,t,r,i){let n=new Map,o=new Map;n.set(e.id,t),o.set(e.id,r);let a=[];for(let s of i.getAncestorIds(e.id)){let c=0,l=0;for(let d of i.getChildHhInfo(s)){let u=n.has(d.id)?n.get(d.id):d.workHours,f=o.has(d.id)?o.get(d.id):d.realWorkHours??fc(d.workHours,d.progress);c+=u,l+=f}n.set(s,c),o.set(s,l),a.push({activityId:s,fields:{workHours:c,...sr(l)}})}return a}function Vr(e,t){return e.getUTCFullYear()===t.getUTCFullYear()&&e.getUTCMonth()===t.getUTCMonth()&&e.getUTCDate()===t.getUTCDate()}function Io(e,t){return e.getTime()<t.getTime()}function we(e){return e instanceof Date&&!Number.isNaN(e.getTime())}var Bi=e=>({durationHours:e});var Ny="sir-apply",pc={targetField:"startDate",canEdit(e,t,r){return ft(e,t)?nt("summary","summary_column_value"):tc(e)?r?.eventSource!==Ny?nt("has_progress","cant_edit_activity_with_progress"):ge(e)?nt("completed","cant_edit_completed_activity"):we(r.newValue)?Vr(e.startDate,r.newValue)?X():r.newValue.getTime()>e.startDate.getTime()?nt("sir_start_after_progress","sir_cant_move_start_after_progress"):X():X():X()},parseInput(e,t,r){return we(e)?j(Ae(e,"UTC")):J("invalid_date")},validate(e,t,r,i){if(Vr(t,r))return ut("unchanged");let n=by(e,r,i);return n||tt()},transform(e,t,r){let i=r.calendars.getCalendar(e.calendarId);if(!i)throw new Error("startDatePipeline: no calendar resolved (integrity)");let n=yo(i,t),o=e.type===D.MILESTONE,a=o?n:i.calculateEndDate(n,e.durationHours),s=n;return{...Q({startDate:n,...nr(a),...o?Bi(0):{},...Ce(),...Fe(s)},{autoSchedule:!0,postProcessors:["adjustLinkLagOnTaskMove"]}),constraintWarning:Fy(e,n,i)}},trackEvent:lt.START_DATE_ENTRY};function by(e,t,r){let i=r.hierarchy.getParentStartDateIfHasPredecessors(e.id);if(!i)return null;let n=Ae(i,"UTC");return t.getTime()<n.getTime()?ut("before_parent_start"):null}function Fy(e,t,r){let i=r.calculateEndDate(t,e.durationHours),n=Rr(zt(e),t,i),o=or(zt(e),e.constraintDate,n);if(o.violated)return ar(o.constraintType,o.constraintDate,n)}var wy=99.999,hc={targetField:"endDate",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):xy(e)?nt("completed","cant_edit_completed_activity"):X()},parseInput(e,t,r){if(!we(e))return J("invalid_date");let i=Ae(e,"UTC"),n=r.calendars.getCalendar(t.calendarId);return n?n.isWorkTime(i,mt.DAY)?j(ho(n,i)):j(n.getClosestWorkTime({direction:"past",date:i,unit:mt.HOUR})):j(i)},validate(e,t,r,i){if(Vr(e.endDate,r))return ut("unchanged");if(My(r,e))return ut("before_date_origin");if(Uy(r,e))return ut("before_start_date");let n=By(r,e,i);return n||tt()},transform(e,t,r){let i=Hy(e,t),n=Wy(e,t,r,!!i);return{...Q(n,{autoSchedule:!0,postProcessors:["updateTaskTiming"]}),...i?{constraintWarning:i}:{}}},trackEvent:lt.END_DATE_ENTRY};function xy(e){return e.progress>=wy}function My(e,t){return t.dateOrigin?Io(e,t.dateOrigin):!1}function Uy(e,t){return Io(e,t.startDate)}function By(e,t,r){let i=r.calendars.getCalendar(t.calendarId);return i?i.isWorkTime(e,mt.DAY)?null:ut("not_working_day"):null}function Hy(e,t){if(zt(e)===A.MSO)return;let i=Rr(zt(e),e.startDate,t),n=or(zt(e),e.constraintDate,i);if(n.violated)return ar(n.constraintType,n.constraintDate,i)}function Wy(e,t,r,i=!1){let n={};re(e.type)&&!i&&yc(e)?Object.assign(n,Fe(e.startDate)):(i||yc(e))&&Object.assign(n,Ce(),Fe(e.startDate));let s=Vy(e,t,r),c=Nr(e.durationHours,s);return c&&(n.type=c),Object.assign(n,Bi(s)),n.endDate=t,n}function yc(e){return ve.has(zt(e))}function Vy(e,t,r){let i=r.calendars.getCalendar(e.calendarId);return i?i.calculateDuration(e.startDate,t):e.durationHours}var Ky=new Set(Object.values(A)),mc={targetField:"constraintType",canEdit(e,t){return ge(e)?nt("completed","cant_edit_completed_activity"):ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){let t=String(e).toLowerCase();return jy(t)?j(t):J("invalid_constraint_type")},validate(){return tt()},transform(e,t,r){let i=Yy(e,t,r);return Q(i,{autoSchedule:!0})}};function jy(e){return Ky.has(e)}function Yy(e,t,r){let i=$y(e,t);return{constraintType:t,...rc(Gy(e,t,i,r))}}function Gy(e,t,r,i){if(e.type!==D.MILESTONE||!r)return r;let n=i.calendars.getCalendar(String(e.calendarId));return n?ne(r,n,t):r}function $y(e,t){return ve.has(t)?null:wi.has(t)?e.startDate:mo.has(t)?e.endDate:e.constraintDate}var Ic={targetField:"constraintDate",canEdit(e,t){return ge(e)?nt("completed","cant_edit_completed_activity"):ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){return we(e)?j(e):J("invalid_date")},validate(){return tt()},transform(e,t,r){let i=gc(e)?Mi:zt(e),n=r.calendars.getCalendar(e.calendarId);if(!n)throw new Error("constraintDatePipeline: no calendar resolved (integrity)");let o=ne(t,n,i),a=zy(e,o);return Q(a,{autoSchedule:!0})}};function zy(e,t){return{constraintDate:t,...gc(e)?Ce():{}}}function gc(e){return ve.has(zt(e))||!e.constraintType}var Ac={targetField:"calendarId",canEdit(){return X()},parseInput(e){let t=String(e).trim();return qy(t)?J("empty_calendar"):j(t)},validate(e,t,r,i){return Jy(e.calendarId,r)?ut("unchanged"):i.calendars.getCalendar(r)?tt():ut("unknown_calendar")},transform(e,t,r){return Q(Xy(e,t,r),{autoSchedule:!0,postProcessors:[]})},trackEvent:lt.CALENDAR_ASSIGNMENT};function qy(e){return e===""}function Jy(e,t){return e===t}function Xy(e,t,r){let i={calendarId:t,assignedDefaultCalendar:!1},n=r.calendars.getCalendar(t);if(n){let o=e.durationHours===0,a=o?Zy(e.startDate):e.startDate,s=n.getClosestWorkTime({date:a,direction:"future",unit:"hour"});if((!e.autoScheduling||o||n.getWorkHours(e.startDate).length===0)&&(i.startDate=s),!e.autoScheduling)return i;let c=i.startDate??e.startDate;Object.assign(i,nr(n.calculateEndDate(c,e.durationHours)))}return i}function Zy(e){return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()))}var vc={targetField:"customId",canEdit(e,t){return ft(e,t)?nt("summary","summary_column_value"):X()},parseInput(e){if(e==null)return J("empty_custom_id");if(typeof e!="string")return J("not_a_string");let t=e.trim();return t.length===0?J("empty_custom_id"):t.length>20?J("exceeds_max_length"):j(t)},validate(){return tt()},transform(e,t){return Q({customId:t},{autoSchedule:!1,postProcessors:[]})}};var Cc={targetField:"subcontractId",canEdit(){return X()},parseInput(e){if(e==null)return j(null);if(typeof e=="string"){let t=e.trim();if(t.length===0)return j(null);let r=Number(t);return!Number.isFinite(r)||!Number.isInteger(r)?J("not_an_integer"):j(r)}return typeof e=="number"?!Number.isFinite(e)||!Number.isInteger(e)?J("not_an_integer"):j(e):J("not_an_integer")},validate(){return tt()},transform(e,t){return Q({subcontractId:t},{autoSchedule:!1,postProcessors:[]})}};function Kr(e){if(e==null)return null;if(typeof e=="object"){if(!("id"in e))return null;let t=e.id;return t==null?null:String(t)}return String(e)}function Hi(e){return e.some(t=>Kr(t)===null)}var Sc={targetField:"responsableIds",canEdit(){return X()},parseInput(e){return e==null?j([]):Array.isArray(e)?j(e):J("not_an_array")},validate(e,t,r){return Hi(r)?ut("missing_id"):tt()},transform(e,t){let r=t.map(Kr).filter(i=>i!==null);return Q({responsableIds:r},{autoSchedule:!1,postProcessors:[]})}};var Tc={targetField:"tagIds",canEdit(){return X()},parseInput(e){return e==null?j([]):Array.isArray(e)?j(e):J("not_an_array")},validate(e,t,r){return Hi(r)?ut("missing_id"):tt()},transform(e,t){let r=t.map(Kr).filter(i=>i!==null);return Q({tagIds:r},{autoSchedule:!1,postProcessors:[]})}};var Qy=new Map([[_.TEXT,Zs],[_.DESCRIPTION,Qs],[_.DURATION,sc],[_.PROGRESS,Ui],[_.COST,lc],[_.USED_COST,dc],[_.HH_WORK_TIME,uc],[_.START_DATE,pc],[_.END_DATE,hc],[_.CONSTRAINT_TYPE,mc],[_.CONSTRAINT_DATE,Ic],[_.CALENDAR_ID,Ac],[_.CUSTOM_ID,vc],[_.SUBCONTRACT_ID,Cc],[_.RESPONSABLES,Sc],[_.TAGS,Tc]]);function Se(e){return Qy.get(e)}var pt={APPEND:"append",REPLACE:"replace"},Wi={ACTION_BUTTON:"action-button"},Vi={SIR_AUTO_REJECT:"sir-auto-reject"},Ki={DATE_CHANGED:"date_changed",ACTIVITY_DELETED:"activity_deleted"},ji={VIOLATION:"constraint_violation"},oe={INIT:"init",UNDO:"undo",REDO:"redo"};function cr(e,t){if(!t||t.type!==ni.CONSTRAINT)return null;let r=t.data;return!r?.constraintType||!r.constraintDate?null:{kind:ji.VIOLATION,activityId:e,constraintType:r.constraintType,constraintDate:r.constraintDate,projectedDate:r.projectedDate??r.constraintDate,messageKey:t.messageKey}}var th=["name","description","type","startDate","endDate","durationHours","constraintType","constraintDate","calendarId","assignedDefaultCalendar","autoScheduling","progress","cost","usedCost","workHours","realWorkHours","customId","subcontractId","responsableIds","tagIds"],Ec=new Set(th);var x={ID:"id",PROPLANNER_ID:"proplannerId",PARENT:"parentId",NAME:"name",DESCRIPTION:"description",TYPE:"type",START_DATE:"startDate",END_DATE:"endDate",DURATION_HOURS:"durationHours",CONSTRAINT_TYPE:"constraintType",CONSTRAINT_DATE:"constraintDate",AUTO_SCHEDULING:"autoScheduling",CALENDAR_ID:"calendarId",ASSIGNED_DEFAULT_CALENDAR:"assignedDefaultCalendar",DATE_ORIGIN:"dateOrigin",PROGRESS:"progress",COST:"cost",USED_COST:"usedCost",REAL_COST:"realCost",WORK_HOURS:"workHours",REAL_WORK_HOURS:"realWorkHours",PONDERATOR:"ponderator",HAS_CUSTOM_PONDERATOR:"hasCustomPonderator",CORRELATIVE_ID:"correlativeId",UNIQUE_CORRELATIVE_ID:"uniqueCorrelativeId",CUSTOM_ID:"customId",SUBCONTRACT_ID:"subcontractId",IS_LOOKAHEAD:"isLookahead",HAS_LOOKAHEAD_TASKS:"hasLookaheadTasks",NEW_ACTIVITIES_ARRAY:"newActivityIds",HAS_NEW_ACTIVITIES:"hasNewActivities",IS_NEW_ACTIVITY:"isNewActivity",PENDING_REQUEST_IDS:"pendingRequestIds",RESPONSABLE_IDS:"responsableIds",TAG_IDS:"tagIds",BASELINE_POINTS:"baselinePoints",BASELINE_SNAPSHOT:"baselineSnapshot",SUM_OF_DURATION_RECURSIVELY:"recursiveDurationHours",CALENDAR_DURATION:"calendarDuration",IS_CRITICAL:"isCritical",FREE_SLACK_HOURS:"freeSlackHours",EXPECTED_PROGRESS:"expectedProgress",EXPECTED_PROGRESS_BASELINE:"expectedProgressBaseline",STATUS:"status",CRITICAL_PATH:"criticalPath"},jr={ID:"id",SOURCE:"source",TARGET:"target",TYPE:"type",LAG:"lag",FREE_SLACK_HOURS:"freeSlackHours",IS_CRITICAL:"isCritical",SOURCE_LAG:"_sourceLag",TARGET_LAG:"_targetLag",TRUE_LAG:"_trueLag",SUMMARY_SOURCE_ID:"_summarySourceId",SUMMARY_TARGET_ID:"_summaryTargetId",GANTT_ID:"ganttId",SECTOR_ID:"sectorId",PROPLANNER_ID:"proplannerId"};function yt(e,t,r,i){e.setActivityFieldDynamic(t,r,i)}function Dc(e,t,r,i){e.setLinkFieldDynamic(t,r,i)}function ae(e){return{...e,startDate:new Date(e.startDate),endDate:new Date(e.endDate),constraintDate:te(e.constraintDate),dateOrigin:te(e.dateOrigin),newActivityIds:[...e.newActivityIds],pendingRequestIds:[...e.pendingRequestIds],responsableIds:[...e.responsableIds],tagIds:[...e.tagIds],baselinePoints:e.baselinePoints.map(t=>({...t,startDate:te(t.startDate),endDate:te(t.endDate)})),baselineSnapshot:eh(e.baselineSnapshot),criticalPath:rh(e.criticalPath)}}function te(e){return e===null?null:new Date(e)}function eh(e){return e===null?null:{...e,startDate:te(e.startDate),endDate:te(e.endDate)}}function rh(e){return e===null?null:{...e,earlyStart:te(e.earlyStart),earlyFinish:te(e.earlyFinish),lateStart:te(e.lateStart),lateFinish:te(e.lateFinish)}}var Rc=200;function Te(e,t){let r=new Set([String(e)]);for(let i of t.cascadeMutations??[])r.add(String(i.activityId));return r}async function rt(e,t){let r=new Map,i=0;for(let n of t){i+=1,i%Rc===0&&await st();let o=e.getActivity(n);o&&r.set(n,et(o))}return r}function et(e){return ae(e)}function Yi(e,t){let r=e.getActivity(t);return r?ae(r):null}function Ee(e,t,r){_c(e,t,r.patch);for(let i of r.cascadeMutations??[])_c(e,i.activityId,i.fields)}function _c(e,t,r){for(let[i,n]of Object.entries(r)){if(!Ec.has(i))throw new Error(`applyFieldChanges: column write to non-writable field "${i}"`);yt(e,t,i,n)}}async function Gi(e,t,r,i){let n=[],o=0;for(let a of r){o+=1,o%Rc===0&&await st();let s=ih(e,t,a,i);s&&n.push(s)}return n}function ih(e,t,r,i){let n=e.getActivity(r);if(!n)return{id:r,kind:N.DELETED,after:null};let o=t.get(r);if(!o&&i?.has(r))return nh(r,i.get(r),n);let a=Ao(o,n);return oh(a,i,r,n),o&&Object.keys(a).length===0?null:{id:r,kind:o?N.UPDATED:N.CREATED,fields:a,after:et(n)}}function nh(e,t,r){return t===r.correlativeId?null:{id:e,kind:N.UPDATED,fields:{correlativeId:{before:t,after:r.correlativeId}},after:et(r)}}function oh(e,t,r,i){if(!t?.has(r)||Object.hasOwn(e,"correlativeId"))return;let n=t.get(r);n!==i.correlativeId&&(e.correlativeId={before:n,after:i.correlativeId})}function Ao(e,t){let r={},i=e??{},n=t,o=new Set([...Object.keys(i),...Object.keys(n)]);o.delete(x.CALENDAR_DURATION);for(let a of o)(Object.hasOwn(i,a)!==Object.hasOwn(n,a)||!go(i[a],n[a]))&&(r[a]={before:kc(i[a]),after:kc(n[a])});return r}function kc(e){return e===null||typeof e!="object"?e:F(e)}function go(e,t){if(Object.is(e,t))return!0;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(e==null||t==null)return!1;if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((a,s)=>go(a,t[s]));if(typeof e!="object"||typeof t!="object")return!1;let r=e,i=t,n=Object.keys(r),o=Object.keys(i);return n.length!==o.length?!1:n.every(a=>Object.hasOwn(i,a)&&go(r[a],i[a]))}function $i(e,t,r){let i=new Set;i.add(e);for(let n of t)i.add(n);for(let n of r)i.add(n);return i}function vo(e,t){let r=new Set;for(let i of e)r.add(String(i));for(let i of t)r.add(i);return r}function lr(e,t,r,i,n){for(let o of t){if(r.has(o.activityId)||(n.add(o.activityId),i.has(o.activityId)))continue;let a=e.getActivity(o.activityId);if(!a)continue;let s=et(a);o.before!==void 0&&(s.correlativeId=o.before),i.set(o.activityId,s)}}var ah=/^(\d{4})\/(\d{1,2})\/(\d{1,2})\s+(\d{1,2}):(\d{2})$/;function se(e){if(e==null||e==="")throw new Error(`[parseFromBackend] expected a date string, got "${e}"`);if(e.includes("T")||e.endsWith("Z")){let s=new Date(e);if(Number.isNaN(s.getTime()))throw new Error(`[parseFromBackend] invalid ISO date "${e}"`);return s}let t=e.match(ah);if(!t)throw new Error(`[parseFromBackend] unsupported date format "${e}" (expected "YYYY/MM/DD H:MM" or ISO)`);let[,r,i,n,o,a]=t;return new Date(Date.UTC(Number(r),Number(i)-1,Number(n),Number(o),Number(a)))}function dr(e,t,r,i){if(e.getTime()>r.getTime())return 0;if(t.getTime()<r.getTime()||e.getTime()===t.getTime())return 100;let n=i.calculateDuration(e,r),o=i.calculateDuration(e,t);return o===0?0:n*100/o}var sh=e=>e.type===D.PROJECT,ch=(e,t,r)=>{let i=e.calendarId,n=i!=null?r.calendarReader.getCalendar(String(i)):null;if(!n)return 0;let o=a=>a instanceof Date?a:se(String(a));return dr(o(e.startDate),o(e.endDate),t,n)};function lh(e,t,r){let i=[],n=(a,s)=>{let c=r.getActivity(a);c&&c.expectedProgress!==s&&(r.setActivityField(a,"expectedProgress",s),i.push(String(a)))},o=a=>{let s=r.getActivity(a);if(!s)return 0;if(!sh(s)){let d=ch(s,t,r);return n(a,d),d}let c=0;for(let d of r.getChildren(a)){let u=o(d),f=r.getActivity(d),p=typeof f?.ponderator=="number"?f.ponderator:0;c+=u*p}let l=c/100;return n(a,l),l};for(let a of e)o(a);return i}function Me(e,t){let r=[];e.forEachActivity((i,n)=>{i.parentId===null&&r.push(n)}),lh(r,t,e)}var dh=e=>e.type===D.PROJECT,uh=e=>Rt(e),fh=(e,t,r,i)=>{let n=uh(e);if(!n)return 0;let o=(n.baseCalendarId!=null?r.getBaseCalendar(`${n.baseCalendarId}-base`):null)??(i?r.getBaseCalendar(i):null);return!o||!n.startDate||!n.endDate?0:dr(n.startDate,n.endDate,t,o)};function Co(e,t,r,i=null){let n=[],o=(s,c)=>{let l=r.getActivity(s);l&&l.expectedProgressBaseline!==c&&(r.setActivityField(s,"expectedProgressBaseline",c),n.push(s))},a=s=>{let c=r.getActivity(s);if(!c)return 0;if(!dh(c)){let u=fh(c,t,r,i);return o(s,u),u}let l=0;for(let u of r.getChildrenIds(s)){let f=a(u),p=r.getActivity(u),y=typeof p?.ponderator=="number"?p.ponderator:0;l+=f*y}let d=l/100;return o(s,d),d};for(let s of e)a(s);return n}function ur(e,t,r=null){let i={getChildrenIds:o=>e.getChildren(String(o)).map(a=>String(a)),getActivity:o=>e.getActivity(o),setActivityField:(o,a,s)=>yt(e,o,a,s),getBaseCalendar:o=>e.calendarReader.getCalendar(o)},n=[];return e.forEachActivity((o,a)=>{o.parentId===null&&n.push(a)}),Co(n,t,i,r)}var So=de.BASELINE;function zi(e){return e===de.ACTUAL?de.ACTUAL:So}var Pc=e=>Math.round(e*100)/100;function ph(e,t){return(t===de.BASELINE?e.expectedProgressBaseline:e.expectedProgress)??void 0}function yh(e,t){let r=Pc(e),i=Pc(t);return r>99.99?kt.DONE:i>r?kt.OVERDUE:e>0&&r>i?kt.ADVANCEMENT:e===0&&t===0?kt.WAITING:e>0&&r<i?kt.DOING:kt.WAITING}function ce(e,t){let r=[];return e.forEachActivity((i,n)=>{let o=typeof i.progress=="number"?i.progress:0,a=yh(o,ph(i,t));i.status!==a&&(yt(e,n,_.STATUS,a),r.push(n))}),r}function To(e){let t=e instanceof Date?new Date(e.getTime()):e&&typeof e=="object"&&typeof e.valueOf=="function"?new Date(e.valueOf()):new Date(e),r=(n,o)=>a=>a===void 0?t[n]():(t[o](a),i),i={__isMomentShim:!0,clone:()=>To(t),hours:r("getUTCHours","setUTCHours"),minutes:r("getUTCMinutes","setUTCMinutes"),seconds:r("getUTCSeconds","setUTCSeconds"),milliseconds:r("getUTCMilliseconds","setUTCMilliseconds"),valueOf:()=>t.getTime(),toDate:()=>new Date(t.getTime()),getTime:()=>t.getTime()};return i}To.isMoment=e=>!!e&&typeof e=="object"&&e.__isMomentShim===!0;var Vt=To;function hh(e){return e&&e.constructor===Date?!!(e.getFullYear&&e.getMonth&&e.getDate):!1}function qi(e){return hh(e)&&!isNaN(e.getTime())}function R(e,t,r,i){if(!qi(new Date(t)))throw new Error(`Invalid date argument for calculateEndDate method. Date: ${t}, Activity: ${JSON.stringify(i)}`);let n=t;return e.calculateEndDate({start_date:new Date(n),duration:r,unit:"hour",task:i})}function Mt(e){if(!qi(new Date(e.dateBaseToCalculate)))throw new Error("Invalid date argument for getClosestWorkTime method");let{dateBaseToCalculate:t,activityCalendar:r,direction:i,activity:n}=e;return r.$gantt.getClosestWorkTime({date:new Date(t),dir:i,unit:"hour",task:n})}var h=A;var U=Object.freeze({FS:Ct.FINISH_TO_START,SS:Ct.START_TO_START,FF:Ct.FINISH_TO_FINISH,SF:Ct.START_TO_FINISH});function Ue(e){return Ei[String(Number(e))]??Ct.START_TO_FINISH}var G=Object.freeze({FORWARD:"forward",BACKWARD:"backward"}),Be=Object.freeze({GREATER:"greater",LESS:"less"}),qt=Object.freeze({SOURCE:"$source"});var mh=e=>e?e.$level===1:!1,Ih=e=>e.type===D.PROJECT,gh=e=>e.$level!==0,Ah=e=>e.type===D.TASK,vh=e=>e.type===D.TASK||e.type===D.MILESTONE,Ot={byFirstLevel:mh,filterByParentType:Ih,avoidSubproject:gh,byTaskType:Ah,byTaskTypeAndMilestone:vh};function Lc(e){let{gantt:t,pendingParentsWithNoLinks:r,calculations:i,linkProperty:n}=e;try{let o=Ch({gantt:t,pendingParentsWithNoLinks:r});if(o.length===0)return new Set;let a=Sh({gantt:t,subprojectsWithNoLinks:o}),s=Th({gantt:t,childrenIds:a,linkProperty:n,getArrayOfLinkedActivities:Eh,calculations:i});return new Set(s.map(c=>c.id))}catch(o){throw o}}function Ch(e){let{gantt:t,pendingParentsWithNoLinks:r}=e;return t.getTaskByTime().filter(Ot.filterByParentType).filter(i=>r.has(i.id)).map(i=>i.id)}function Sh(e){let{gantt:t,subprojectsWithNoLinks:r}=e,i=new Set;for(let n of r)t.getChildren(n).filter(s=>{let c=t.getTask(s),l=Ot.byTaskTypeAndMilestone(c),d=Number(c.progress)<100;return l&&d}).forEach(s=>i.add(s));return[...i]}function Th(e){let{gantt:t,childrenIds:r,linkProperty:i,getArrayOfLinkedActivities:n,calculations:o}=e,a=[];for(let s of r){let c=t.getTask(s),l=c[i]||[];n({gantt:t,links:l,linkDirection:i===qt.SOURCE?"target":"source"}).every(f=>o.has(f))&&a.push(c)}return a}function Eh(e){let{gantt:t,links:r,linkDirection:i}=e,n=[];for(let o of r){let a=t.getLink(o);if(!a){`${o}`;continue}let s=Number(a[i]);n.push(s)}return n}function Oc({gantt:e,linkProperty:t,direction:r}){try{let i=Dh(e,t);if(r===G.FORWARD)return{chainStartActivities:i,activitiesStartChainButChildrenOfLinkedParents:null};if(r===G.BACKWARD)return _h(i,e,t)}catch(i){throw console.log("Critical Path",i),i}}function Dh(e,t){return e.getTaskByTime().filter(Ot.avoidSubproject).filter(Ot.byTaskTypeAndMilestone).filter(r=>!r[t].length)}function _h(e,t,r){let i=[],n=new Set;return e.forEach(o=>{let a=Number(o.parent),s=t.getTask(a);s&&(s[r].length>0?n.add(o.id):s.constraint_type!==h.FNLT&&i.push(o))}),{chainStartActivities:i,activitiesStartChainButChildrenOfLinkedParents:n}}function Nc({gantt:e,direction:t,linkProperty:r}){try{let i=kh(e),n=new Set,o=new Set,a=new Set;t===G.BACKWARD&&Lh(i).forEach(d=>{n.add(d.id)});let s=Rh(i,t,r),c=Ph(i,s);return s.forEach(l=>{o.add(l.id)}),c.forEach(l=>{a.add(l.id)}),{parentsWithFullProgress:n,pendingParentsWithNoLinks:o,pendingParentsWithLinks:a}}catch(i){throw i}}function kh(e){return e.getTaskByTime().filter(Ot.filterByParentType).filter(Ot.avoidSubproject)}function Rh(e,t,r){return e.filter(i=>{let n=i[r];if(!Array.isArray(n))return!1;let o=n.length>0,a=i.constraint_type||"",s=a!==h.FNLT;if(t===G.FORWARD){let c=a!==h.SNET;return!o&&s&&c}else return!o&&s})}function Ph(e,t){let r=new Set(t.map(i=>i.id));return e.filter(i=>!r.has(i.id))}function Lh(e){return e.filter(t=>{let r=Number(t.progress);return Number.isNaN(r)?!1:r===100})}function bc({pendingParentsWithLinks:e,gantt:t,direction:r}){try{let i=new Set;return e.forEach(n=>{let o=t.getTask(n),a=Oh(r),s=Nh(r),c=o[a];if(!Array.isArray(c))return;bh(t,c,s).forEach(d=>{i.add(d)})}),i}catch(i){throw i}}function Oh(e){return e===G.FORWARD?qt.SOURCE:"$target"}function Nh(e){return e===G.FORWARD?"target":"source"}function bh(e,t,r){return t.map(i=>{let o=e.getLink(i)[r];return Number(o)})}var Yr={identifySecondLevelActivities:Lc,identifyInitialActivities:Oc,identifyParentsWithAndWithoutLinks:Nc,identifyForbiddenActivities:bc};function Ji(e){return e.length?e.reduce((t,r)=>r.ef>t.ef?r:t):!1}function Eo({linkType:e,lag:t,predecessorTime:r,activityCalendar:i,activity:n}){return e===U.FS&&t===0?Mt({predecessorTime:r,activityCalendar:i,direction:"future",activity:n}):Gr(r,e,i,n)}function Fc({duration:e,constraintDate:t,activityCalendar:r,activity:i}){let n=new Date(t);return{es:R(r,n,e,i),ef:n}}function wc({duration:e,constraintDate:t,activityCalendar:r,activity:i}){let n=new Date(t),o=R(r,n,e,i);return{es:n,ef:o}}function Gr(e,t,r,i){if(![U.FS,U.SS,U.FF].includes(t))return e;let o=[U.FS,U.SS].includes(t)?"future":"past";return Mt({dateBaseToCalculate:e,activityCalendar:r,direction:o,activity:i})}var Do=class{constructor(t,r,i,n){if(this.linkedActivitiesData=t,this.activity=r,this.gantt=i,this.linkCandidates=n,this.activityCalendar=this.gantt.getCalendar(this.activity.calendar_id),!this.activityCalendar)throw new Error(`Error trying to get calendar with id: ${this.activity.calendar_id}`)}calculate(){let t=this.calculateLinks(),r=Ji(t),i=this.activity.constraint_type;return i===h.SNET?this.handleSNETConstraint(r):i===h.FNLT?this.handleFNLTConstraint(r):r}calculateLinks(){let t=[];for(let r of this.linkedActivitiesData){let i=r.linkType,n=Ue(i),o=r.linkLag,a=r.es,s=r.ef,c=null;if(n===U.SS)c=this.calculateSSLink({lag:o,predecessorEs:a});else if(n===U.FF)c=this.calculateFFLink({lag:o,predecessorEf:s});else if(n===U.FS)c=this.calculateFSLink({lag:o,predecessorEf:s});else if(n===U.SF)c=this.calculateSFLink({lag:o,predecessorEs:a,predecessorEf:s});else continue;c&&(this.linkCandidates?.set(r.linkId,{targetId:String(this.activity.id),...c}),t.push(c))}return t}handleSNETConstraint(t){let r=wc({duration:this.activity.duration,constraintDate:this.activity.constraint_date,activityCalendar:this.activityCalendar,activity:this.activity});return t&&t.ef>r.ef?t:r}handleFNLTConstraint(t){let r=Fc({duration:-this.activity.duration,constraintDate:this.activity.constraint_date,activityCalendar:this.activityCalendar,activity:this.activity});return t?t.ef>r.ef?r:t:r}calculateSSLink({lag:t,predecessorEs:r}){let i=Eo({linkType:U.SS,lag:t,predecessorTime:r,activityCalendar:this.activityCalendar,activity:this.activity}),n=R(this.activityCalendar,i,t,this.activity);t>0&&(n=Gr(n,U.SS,this.activityCalendar,this.activity));let o=R(this.activityCalendar,n,this.activity.duration,this.activity);return{es:n,ef:o}}calculateFFLink({lag:t,predecessorEf:r}){let i=Eo({linkType:U.FF,lag:t,predecessorTime:r,activityCalendar:this.activityCalendar,activity:this.activity}),n=R(this.activityCalendar,i,t,this.activity),o=R(this.activityCalendar,n,-this.activity.duration,this.activity);return t>0&&(o=Gr(o,U.FF,this.activityCalendar,this.activity)),{es:o,ef:n}}calculateFSLink({lag:t,predecessorEf:r}){let i=r;t===0&&(i=Mt({dateBaseToCalculate:r,activityCalendar:this.activityCalendar,direction:"future",activity:this.activity}));let n=R(this.activityCalendar,i,t,this.activity),o=R(this.activityCalendar,n,this.activity.duration,this.activity);return{es:n,ef:o}}calculateSFLink({lag:t,predecessorEs:r}){let i=R(this.activityCalendar,r,t,this.activity),n=R(this.activityCalendar,i,-this.activity.duration,this.activity);return t>0&&(n=Gr(n,U.SF,this.activityCalendar,this.activity)),{es:n,ef:i}}},xc=Do;var _o=class{constructor(t){this.linkedActivitiesData=t.linksWithActivityData,this.activity=t.activity,this.gantt=t.gantt}calculate(){if(this.activityCalendar=this.gantt.getCalendar(this.activity.calendar_id),!this.activityCalendar)throw new Error(`Error trying to get calendar with id: ${this.activity.calendar_id}`);let t=[];for(let r of this.linkedActivitiesData){let i=Ue(r.linkType);if(r.type===D.TASK&&Number(r.progress)>0||r.type===D.PROJECT&&Number(r.progress)===100)continue;let n=r.linkLag,o=r.ls,a=r.lf;if(i===U.SS){let s={lag:n,workTime:o,lsDataCalculation:-n,lfDataCalculation:this.activity.duration},{ls:c,lf:l}=this.calculateSSLink(s);t.push({ls:c,lf:l})}if(i===U.FF){let s={lag:n,workTime:a,lsDataCalculation:-this.activity.duration,lfDataCalculation:-n},{ls:c,lf:l}=this.calculateFFLink(s);t.push({ls:c,lf:l})}if(i===U.FS){let s={lag:n,workTime:o,lsDataCalculation:-this.activity.duration,lfDataCalculation:-n},{ls:c,lf:l}=this.calculateFsLink(s);t.push({ls:c,lf:l})}if(i===U.SF){let s={lag:n,workTime:a,lsDataCalculation:-n,lfDataCalculation:this.activity.duration},{ls:c,lf:l}=this.calculateSFLink(s);t.push({ls:c,lf:l})}}if(this.activity.constraint_type===h.FNLT){let r=this.getMinLfFromLinks(t),i=this.calculateSfRestrictionDates();return r?this.getMinLfFromLinks([i,r]):i}else{let r=this.getMinLfFromLinks(t);if(r===!1){let i=this.gantt.getSubtaskDates();return{ls:R(this.activityCalendar,i.end_date,-this.activity.duration,this.activity),lf:i.end_date}}return r}}calculateFFLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n}){let o=null,a=null;if(t===0)return o=R(this.activityCalendar,r,n,this.activity),a=R(this.activityCalendar,o,i,this.activity),{ls:a,lf:o};let s=r;return t>0&&(s=this.getLastWorkingHour(s,this.activityCalendar,K.PAST)),o=R(this.activityCalendar,s,n,this.activity),a=R(this.activityCalendar,o,i,this.activity),{ls:a,lf:o}}calculateFsLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n,isMilestone:o=!1}){let a=null,s=null;if(t===0){let l=this.getLastWorkingHour(r,this.activityCalendar,K.PAST);return a=R(this.activityCalendar,l,n,this.activity),a=this.getLastWorkingHour(a,this.activityCalendar,K.PAST),s=R(this.activityCalendar,a,i,this.activity),{ls:s,lf:a}}let c=r;return o||(c=this.getLastWorkingHour(r,this.activityCalendar)),a=R(this.activityCalendar,c,n,this.activity),s=R(this.activityCalendar,a,i,this.activity),o||(a=this.getLastWorkingHour(a,this.activityCalendar,K.PAST)),{ls:s,lf:a}}calculateSFLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n}){let o=null,a=null,s=r;return a=R(this.activityCalendar,s,i,this.activity),o=R(this.activityCalendar,a,n,this.activity),{ls:a,lf:o}}calculateSSLink({lag:t,workTime:r,lsDataCalculation:i,lfDataCalculation:n,isMilestone:o=!1}){let a=null,s=null;if(t===0)return s=R(this.activityCalendar,r,i,this.activity),a=R(this.activityCalendar,s,n,this.activity),{ls:s,lf:a};let c=r;return t<0&&!o&&(c=this.getLastWorkingHour(c,this.activityCalendar,"future")),s=R(this.activityCalendar,c,i,this.activity),a=R(this.activityCalendar,s,n,this.activity),{ls:s,lf:a}}getMinLfFromLinks(t=[]){return t.length?t.reduce((r,i)=>i.lf<r.lf?i:r):!1}calculateSfRestrictionDates(){let t=this.activity.constraint_date,r=this.activity.duration;return{ls:R(this.activityCalendar,t,-r,this.activity),lf:t}}getLastWorkingHour(t,r,i=K.PAST){let n=t instanceof Date?t:new Date(t),o=Vt(n).clone();return this.isActivityInInitHour(r,n)&&i===K.PAST&&(o=o.hours(0).minutes(0).seconds(0).milliseconds(0)),Mt({dateBaseToCalculate:new Date(o),direction:i,activityCalendar:r,activity:this.activity})}isActivityInInitHour(t,r){let i=r instanceof Date?r:new Date(r),o=t.getWorkHours(i)[0];if(!o||!o.includes("-"))return!1;let a=o.split("-")[0];if(!a.includes(":"))return!1;let s=a.split(":");return s.length<2?!1:(a=parseInt(s[0],10),Vt.isMoment(r)?r.hours()===a:i.getUTCHours()===a)}},Mc=_o;function Uc(e){let{parent:t,linkProperty:r,linkDirection:i,calculations:n,gantt:o,direction:a,linkCandidates:s}=e,c=t[r],l=Fh(t),d=null;if(a===G.FORWARD){let u=wh(c,i,n,o);d=new xc(u,t,o,s),d=d.calculate()}else{let u=xh(c,i,n,o);d=new Mc({linksWithActivityData:u,activity:t,parentData:l,gantt:o}).calculate()}return d}function Fh(e){return{duration:e.duration,calendarId:e.calendar_id}}function wh(e,t,r,i){return e.length===0?[]:e.map(n=>{let o=i.getLink(n);if(!o)return console.warn(`Link not found: ${n}`),null;let a=Number(o[t]),s=r.get(a);return s?{linkId:String(o.id),es:s.es,ef:s.ef,linkLag:o.lag,linkType:o.type}:(console.warn(`Calculations not found for activity: ${a}`),null)}).filter(Boolean)}function xh(e,t,r,i){return e.length===0?[]:e.map(n=>{let o=i.getLink(n);if(!o)return console.warn(`Link not found: ${n}`),null;let a=Number(o[t]),s=r.get(a);if(!s)return null;let c=i.getTask(a);return c?{ls:s.ls,lf:s.lf,linkLag:o.lag||0,linkType:o.type,progress:c.progress,type:c.type}:null}).filter(Boolean)}function Wc(e){let{activityData:t,calculations:r,singleParents:i,direction:n}=e;if(Mh(t.id,r))return null;let o=Uh(t.id,i),a=Bh(o,r);return a.length===0?null:Hh(a,n)}function Mh(e,t){return t.has(e)}function Uh(e,t){let r=t.get(e);return r?r.childrens:[]}function Bh(e,t){return e.filter(r=>t.has(r)).map(r=>t.get(r))}function Hh(e,t){if(t===G.FORWARD){let r=Bc(e,"es"),i=Hc(e,"ef");return{es:r,ef:i}}else{let r=Bc(e,"ls"),i=Hc(e,"lf");return{ls:r,lf:i}}}function Bc(e,t){return e.reduce((r,i)=>i[t]<r[t]?i:r)[t]}function Hc(e,t){return e.reduce((r,i)=>i[t]>r[t]?i:r)[t]}var ko={parentWithLinks:Uc,parentWithNoLinks:Wc};var Ro=class{constructor(t){this.activity=t.activity,this.direction=t.direction,this.linkProperty=t.direction===G.FORWARD?"$target":qt.SOURCE,this.linkDirection=t.direction===G.FORWARD?"source":"target",this.calculationsOfParentThatImpactChildrens=t.calculationsOfParentThatImpactChildrens,this.calculations=t.calculations,this.calculationOfParentsFromLinks=t.calculationOfParentsFromLinks,this.singleParents=t.singleParents,this.parentCalculationFromChildren=t.parentCalculationFromChildren,this.linkCandidates=t.linkCandidates,this.gantt=t.gantt}handleParentWithLinks(){try{let t=this.getArrayOfIdOfLinkedActivities(this.activity[this.linkProperty]);if(this.direction===G.BACKWARD){let i=[h.FNLT];if(this.shouldCalculateParentWithLinksBackward(i)){this.calculateAndStoreParentWithLinks(this.activity);return}if(this.shouldSetDatesToParentsWithLinks(i)){this.setDatesToParentsWithLinksBackward();return}}if(this.areAllLinksCalculated(t)&&this.calculationsOfParentThatImpactChildrens.has(this.activity.id)){this.direction===G.FORWARD&&this.setDatesToParentsWithLinks(),this.direction===G.BACKWARD&&this.setDatesToParentsWithLinksBackward();return}this.calculateAndStoreParentWithLinks(this.activity)}catch(t){throw t}}shouldCalculateParentWithLinksBackward(t){let r=t.includes(this.activity.constraint_type),i=!this.calculationOfParentsFromLinks.has(this.activity.id);return r&&i}calculateAndStoreParentWithLinks(t){let r=ko.parentWithLinks({parent:t,linkProperty:this.linkProperty,linkDirection:this.linkDirection,gantt:this.gantt,calculations:this.calculations,direction:this.direction,linkCandidates:this.linkCandidates});this.calculationsOfParentThatImpactChildrens.set(t.id,r),this.calculationOfParentsFromLinks.add(t.id)}areAllLinksCalculated(t){return t.every(r=>this.calculations.has(r))}shouldSetDatesToParentsWithLinks(t){let r=t.includes(this.activity.constraint_type),i=this.calculationOfParentsFromLinks.has(this.activity.id);return r&&i}handleParentWithNoLinks(){let t=ko.parentWithNoLinks({activityData:this.activity,gantt:this.gantt,singleParents:this.singleParents,calculations:this.calculations,direction:this.direction});t&&this.calculations.set(this.activity.id,t)}setDatesToParentsWithLinks(){if(!this.activity)throw new Error("Error trying to get parent",{cause:{parentActivity:this.activity}});let t=this.singleParents.get(this.activity.id)?.childrens,i=Array.from(this.calculations).filter(a=>t.includes(a[0])).map(a=>a[1]),{minEs:n,maxEf:o}=i.reduce((a,{es:s,ef:c})=>({minEs:new Date(Math.min(a.minEs.getTime(),new Date(s).getTime())),maxEf:new Date(Math.max(a.maxEf.getTime(),new Date(c).getTime()))}),{minEs:new Date(i[0].es),maxEf:new Date(i[0].ef)});this.calculations.set(this.activity.id,{es:n,ef:o}),this.parentCalculationFromChildren.add(this.activity.id)}setDatesToParentsWithLinksBackward(){if(!this.activity)throw new Error("Error trying to get parent",{cause:{parentActivity:this.activity}});let t=this.singleParents.get(this.activity.id)?.childrens,i=Array.from(this.calculations).filter(a=>t.includes(a[0])).map(a=>a[1]),{minLs:n,maxLf:o}=i.reduce((a,{ls:s,lf:c})=>({minLs:new Date(Math.min(a.minLs.getTime(),new Date(s).getTime())),maxLf:new Date(Math.max(a.maxLf.getTime(),new Date(c).getTime()))}),{minLs:new Date(i[0].ls),maxLf:new Date(i[0].lf)});this.calculations.set(this.activity.id,{ls:n,lf:o})}getArrayOfIdOfLinkedActivities(t,r=!1){return t.map(i=>{let o=this.gantt.getLink(i)[r||this.linkDirection];return Number(o)})}},Vc=Ro;var Po=class{constructor({gantt:t,linkProperty:r}){this.gantt=t,this.linkProperty=r,this.structureOfParents=new Map,this.singleParents=new Map}identifyThirdLevelActivities(){try{let t=this.getFirstLevelParents();for(let r of t){let i=this.processEachActivity(r),{activitiesByLevel:n}=i,o=this.getAllLevels(n),a=this.getDeepestLevel(o),s=this.createResult(r,i,a,o);this.structureOfParents.set(r.id,s)}return{structureOfParents:this.structureOfParents,singleParents:this.singleParents}}catch(t){throw t}}getFirstLevelParents(){return this.gantt.getTaskByTime().filter(Ot.byFirstLevel).filter(Ot.filterByParentType)}processEachActivity(t){let r=new Set,i=new Set,n=new Map;return this.initializeParent(t),this.gantt.eachTask(o=>{this.processActivity(o,r,i,n)},t.id),{parentsIds:r,allTasks:i,activitiesByLevel:n}}initializeParent(t){let r=Number(t.id),i=!!t[this.linkProperty]?.length,n=t.$level;this.singleParents.set(r,{level:n,hasLink:i,childrens:[]})}processActivity(t,r,i,n){let o=Number(t.id),a=Number(t.parent);i.add(o),this.isProjectActivity(t)&&this.addParentInfo(t,r);let c=this.doesParentExist(a);a!=null&&c&&this.addChildToParent(a,o),this.addActivityToLevel(t,n)}isProjectActivity(t){return t.type===D.PROJECT}hasLink(t){return!!t[this.linkProperty]?.length}addParentInfo(t,r){let i=Number(t.id),n=t.$level,o=this.hasLink(t),a={level:n,hasLink:o,childrens:[]};r.add(i),this.singleParents.set(i,a)}doesParentExist(t){return this.singleParents.has(t)}addChildToParent(t,r){this.singleParents.get(t).childrens.push(r)}addActivityToLevel(t,r){let i=t.$level,n=Number(t.parent);r.has(i)||r.set(i,new Map);let o=r.get(i);o.has(n)||o.set(n,[]),o.get(n).push({id:Number(t.id),isParent:this.isProjectActivity(t),calculated:!1})}getAllLevels(t){return new Set(t.keys())}getDeepestLevel(t){return t.size===0?0:Math.max(...t)}createResult(t,r,i,n){let{activitiesByLevel:o,parentsIds:a,allTasks:s}=r;return{parent:t.id,isALinkedParent:this.hasLink(t),levels:n,allParentChildrens:a,allChildrens:s,childrensByLevel:o,currentResolutionLevel:i,canBeCalculated:!1}}},Kc=Po;var Lo=class{constructor(t,r){this.direction=r,this.gantt=t,this.linkProperty=this.direction===G.FORWARD?"$target":qt.SOURCE,this.linkDirection=this.direction===G.FORWARD?"source":"target",this.projectDates=t.getSubtaskDates()}tryToCalculateLastLevelChildrens(){this.structureOfParents.forEach(t=>{let{currentResolutionLevel:r,childrensByLevel:i,isALinkedParent:n}=t;if(n)return;let o=i.get(r);for(let[a,s]of o)if(s.filter(l=>!this.calculations.has(l.id)).length===0){let l=this.gantt.getTask(a);this.calculateParentWithNoLinks(l,s);return}})}initActivitiesWaitingForCalculation(){try{this.gantt.getTaskByTime().filter(Ot.avoidSubproject).forEach(t=>{this.activitiesWaitingForCalculation.add(t.id)})}catch(t){throw t}}identifyParentsWithAndWithoutLinks(){try{let{parentsWithFullProgress:t,pendingParentsWithNoLinks:r,pendingParentsWithLinks:i}=Yr.identifyParentsWithAndWithoutLinks({gantt:this.gantt,direction:this.direction,linkProperty:this.linkProperty});this.parentsWithFullProgress=t,this.pendingParentsWithNoLinks=r,this.pendingParentsWithLinks=i}catch(t){throw t}}identifyForbiddenActivitiesLinkedToParentsWithLinks(){try{this.forbiddenActivitiesLinkedToParentsWithLinks=Yr.identifyForbiddenActivities({pendingParentsWithLinks:this.pendingParentsWithLinks,gantt:this.gantt,direction:this.direction})}catch(t){throw t}}getArrayOfIdOfLinkedActivities(t,r=!1){return t.map(i=>{let o=this.gantt.getLink(i)[r||this.linkDirection];return Number(o)})}async identifyThirdLevelActivities(){try{let{structureOfParents:t,singleParents:r}=new Kc({gantt:this.gantt,linkProperty:this.linkProperty}).identifyThirdLevelActivities();this.structureOfParents=t,this.singleParents=r}catch(t){throw t}}processEachActivity(t){let r=new Set,i=new Set,n=new Map,o=new Map;return this.singleParents.set(Number(t.id),{level:t.$level,hasLink:!!t[this.linkProperty].length,childrens:[]}),new Promise((a,s)=>{this.gantt.eachTask(function(c){let l=Number(c.parent);if(i.add(c.id),c.type===D.PROJECT){let u={level:c.$level,hasLink:!!c[this.linkProperty].length,childrens:[]};r.add(c.id),this.singleParents.set(Number(c.id),u)}l&&this.singleParents.has(l)&&this.singleParents.get(l).childrens.push(c.id),n.has(c.$level)||n.set(c.$level,new Map);let d=n.get(c.$level);d.has(Number(c.parent))||d.set(Number(c.parent),[]),d.get(Number(c.parent)).push({id:c.id,isParent:c.type===D.PROJECT,calculated:!1})}.bind(this),t.id),a({parentsIds:r,allTasks:i,activitiesByLevel:n,singleParents:o})})}identifySecondLevelActivities(){try{let t=Yr.identifySecondLevelActivities({gantt:this.gantt,pendingParentsWithNoLinks:this.pendingParentsWithNoLinks,calculations:this.calculations,linkProperty:this.linkProperty});this.secondLevelActivities=new Set([...this.secondLevelActivities,...t])}catch(t){throw t}}identifyInitialActivities(){try{let{chainStartActivities:t,activitiesStartChainButChildrenOfLinkedParents:r}=Yr.identifyInitialActivities({gantt:this.gantt,linkProperty:this.linkProperty,direction:this.direction});this.chainStartActivities=t,r&&(this.activitiesStartChainButChildrenOfLinkedParents=r)}catch(t){throw new Error("Error in identifyInitialActivities",{cause:t})}}calculateSecondLevelActivities(){try{this.direction===G.FORWARD?this.recursiveCalculateEfAndEs(Array.from(this.secondLevelActivities),0,"secondLevel"):this.recursiveCalculateLfAndLs(Array.from(this.secondLevelActivities))}catch(t){throw t}}calculateStartAndFinishOfActivitiesThatStartChain(){try{this.chainStartActivities.forEach(t=>{if(!t||t.progress>100||t.type===D.PROJECT)return;let r=this.calculateStartAndFinishOfChainOrigin(t,this.direction);if(this.direction===G.FORWARD){let{es:i,ef:n}=r;this.calculations.set(t.id,{es:i,ef:n,text:t.text}),this.activitiesWaitingForCalculation.delete(t.id)}else{let{ls:i,lf:n}=r;this.calculations.set(t.id,{ls:i,lf:n,text:t.text}),this.activitiesWaitingForCalculation.delete(t.id)}})}catch(t){throw t}}buildDependencyGraph(t){let r=new Map,i=new Set(this.calculations.keys()),n=new Map;return t.forEach(o=>{o&&n.set(o.id,o)}),n.forEach((o,a)=>{if(i.has(a))return;let s=[];(o[this.linkDirection]||[]).forEach(l=>{let d=this.gantt.getLink(l);if(d){let u=Number(d[this.linkProperty]);s.push(u)}}),s=s.filter(l=>n.has(l)||i.has(l)),r.set(a,s)}),{graph:r,activityMap:n,calculatedActivities:i}}topologicalSort(t,r){let i=new Set,n=new Set,o=[],a=s=>{if(n.has(s))throw new Error("Cyclical dependency detected",{cause:{nodeId:s}});if(!i.has(s)&&!r.has(s)){n.add(s);let c=t.get(s)||[];for(let l of c)a(l);n.delete(s),i.add(s),o.push(s)}};for(let s of t.keys())!i.has(s)&&!r.has(s)&&a(s);return o.reverse()}calculateStartAndFinishOfChainOrigin(t=null,r=null){try{let i=t,n=Number(i.progress);n==="0.00"&&(n=0);let o=this.gantt.getCalendar(i.calendar_id);if(!o)throw new Error(`Error trying to get calendar with id: ${i.calendar_id}`);if((r||this.direction)===G.FORWARD){let s=i.start_date,c=i.end_date;return{es:s,ef:c}}else{if(n>=100)return{ls:Vt(i.start_date).clone(),lf:Vt(i.end_date).clone()};if(n===0)return this.calculateBackwardWhenZeroProgress(i,o);if(n<100&&n>0)return this.calculateWhenProgressIsBetweenZeroAndOneHundred(i,o)}}catch(i){throw i}}calculateBackwardWhenZeroProgress(t,r){let i=Vt(t.start_date).clone(),n=Vt(t.end_date).clone(),o=t.duration,a=[h.ASAP,h.ALAP,h.SNET,h.FNET],s=t.constraint_type||h.ASAP;if(a.includes(s))n=this.projectDates.end_date,i=R(r,n,-o,t);else{let c=[h.SNLT,h.MSO],l=[h.FNLT,h.MFO];c.includes(s)&&(i=t.constraint_date,n=R(r,i,o,t)),l.includes(s)&&(n=t.constraint_date,i=R(r,n,-o,t))}return{ls:i,lf:n}}calculateWhenProgressIsBetweenZeroAndOneHundred(t){let r=t.start_date,i=null,n=t.constraint_type||h.ASAP,o=this.projectDates.end_date,a=[h.ASAP,h.ALAP,h.SNET,h.FNET],s=[h.SNLT,h.FNLT];if(a.includes(n))i=Math.max(t.end_date,o);else if(n===h.MSO)i=t.end_date;else if(n===h.MFO||s.includes(n)){let c=Math.min(o,t.constraint_date);i=Math.max(c,t.end_date)}return{ls:r,lf:new Date(i)}}initializeActivitiesWithFullProgress(){try{Array.from(this.activitiesWaitingForCalculation).filter(i=>Number(this.gantt.getTask(i).progress)===100).map(i=>this.gantt.getTask(i)).forEach(i=>{let n=i.type===D.PROJECT;this.setDatesForActivityWithFullProgress(i),this.activitiesWaitingForCalculation.delete(i.id),n&&this.pendingParentsWithLinks.has(i.id)&&(this.parentCalculationFromChildren.add(i.id),this.calculationsOfParentThatImpactChildrens.set(i.id,{[this.direction===G.FORWARD?"es":"ls"]:i.start_date,[this.direction===G.FORWARD?"ef":"lf"]:i.end_date}),this.calculationOfParentsFromLinks.add(i.id))})}catch(t){throw t}}doCalculationForParentType(t){let r=new Vc({activity:t,direction:this.direction,calculationsOfParentThatImpactChildrens:this.calculationsOfParentThatImpactChildrens,calculations:this.calculations,calculationOfParentsFromLinks:this.calculationOfParentsFromLinks,singleParents:this.singleParents,parentCalculationFromChildren:this.parentCalculationFromChildren,linkCandidates:this.linkCandidates,gantt:this.gantt});this.pendingParentsWithLinks.has(t.id)?r.handleParentWithLinks():r.handleParentWithNoLinks()}},De=Lo;function Wh(e,t,r){let i={es:null,ef:null};if(!e)return i;if([h.SNET,h.SNLT].includes(t)){let n=new Date(e.constraint_date);i.es=n,i.ef=R(r,n,e.duration,e)}else if([h.FNLT,h.FNET].includes(t)){let n=new Date(e.constraint_date);i.es=R(r,n,-e.duration,e),i.ef=n}else if(t===h.MSO){let n=new Date(e.constraint_date);i.es=n,i.ef=R(r,n,e.duration,e)}else if(t===h.MFO){let n=new Date(e.constraint_date);i.es=R(r,n,-e.duration,e),i.ef=n}return i}var Xi=Wh;var Oo=class{constructor(t){this.referenceActivity=t.activity,this.activityToCalculate=null,this.links=t.links,this.calculatedActivities=t.calculatedActivitiesMap,this.alapMap=t.calculatedAlapsMap,this.parentsWithLinks=t.parentsWithLinks,this.parentsCalculations=t.parentsCalculations,this.gantt=t.ganttInstance,this.linkCandidates=t.linkCandidates}getEsAndEfFromPreviousCalculatedActivities(t){return this.alapMap.has(t)?this.alapMap.get(Number(t)):this.calculatedActivities.get(Number(t))}calculateSucessorTimes(t,r,i=0,n,o=U.FS){let a=this.gantt.getCalendar(this.referenceActivity.calendar_id);if(!a)throw new Error(`Error trying to get calendar with id: ${this.referenceActivity.calendar_id}`);let s=t,c=null,l=null,d=this.referenceActivity.type===D.MILESTONE;return d||(o===U.FS&&n===0?s=Mt({dateBaseToCalculate:s,activityCalendar:a,direction:"future",activity:this.referenceActivity}):s=this.mutateTheDateToFutureOrPastInBaseRestriction(t,o,a)),[U.FF,U.SF].includes(o)?(l=R(a,s,i,this.referenceActivity),c=R(a,l,r,this.referenceActivity),!d&&n>0&&(c=this.mutateTheDateToFutureOrPastInBaseRestriction(c,o,a))):(c=R(a,s,r,this.referenceActivity),!d&&n>0&&(c=this.mutateTheDateToFutureOrPastInBaseRestriction(c,o,a)),l=R(a,c,i,this.referenceActivity)),{es:c,ef:l}}calculateSS(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),i=t.lag||0,o=this.referenceActivity.duration,a=t.lag||0;return this.calculateSucessorTimes(r.es,i,o,a,U.SS)}calculateFF(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),n=-this.referenceActivity.duration,o=t.lag||0,a=t.lag||0;return this.calculateSucessorTimes(r.ef,n,o,a,U.FF)}calculateFS(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),i=t.lag||0,o=this.referenceActivity.duration,a=t.lag||0;return this.calculateSucessorTimes(r.ef,i,o,a,U.FS)}calculateSF(t){let r=this.getEsAndEfFromPreviousCalculatedActivities(Number(t.source)),n=-this.referenceActivity.duration,o=t.lag||0,a=t.lag||0;return this.calculateSucessorTimes(r.es,n,o,a,U.SF)}mutateTheDateToFutureOrPastInBaseRestriction(t,r,i){if(![U.FS,U.SS,U.FF].includes(r))return t;let o=[U.FS,U.SS].includes(r)?"future":K.PAST;return Mt({dateBaseToCalculate:t,activityCalendar:i,direction:o,activity:this.referenceActivity})}},jc=Oo;var $r=class extends jc{constructor(t){super(t)}calculate(){if(this.links.length===0)return new De(this.gantt,"forward").calculateStartAndFinishOfChainOrigin(this.referenceActivity);let t=this.links.map(i=>{let n=this.gantt.getLink(i);if(!n)throw new Error("Link data not found",{cause:{linkId:i}});let o=this.calculateLink(n);return this.linkCandidates?.set(String(n.id),{targetId:String(this.referenceActivity.id),...o}),o}),r=Number(this.referenceActivity.parent);if(this.parentsWithLinks.has(r)){let i=this.gantt.getCalendar(this.referenceActivity.calendar_id),n=this.parentsCalculations.get(r).es,o=R(i,n,this.referenceActivity.duration,this.referenceActivity);t.push({es:n,ef:o})}return Ji(t)}calculateLink(t){return{0:()=>this.calculateFS(t),1:()=>this.calculateSS(t),2:()=>this.calculateFF(t),3:()=>this.calculateSF(t)}[t.type]()}};var No=class{constructor(t){this.gantt=t.gantt,this.direction=t.direction,this.pendingParentsWithNoLinks=t.pendingParentsWithNoLinks,this.pendingParentsWithLinks=t.pendingParentsWithLinks,this.calculationOfParentsFromLinks=t.calculationOfParentsFromLinks,this.singleParents=t.singleParents,this.calculations=t.calculations,this.activitiesStartChainButChildrenOfLinkedParents=t.activitiesStartChainButChildrenOfLinkedParents,this.linkProperty=t.linkProperty,this.linkDirection=t.linkDirection}checkActivitiesThatNowCanBeCalculated(t){let r=new Set,i=new Set(t);for(let n of t){let o=this.gantt.getTask(n);o.type===D.PROJECT?this.handleProjectActivity(n,o,r,i):this.handleNonProjectActivity(n,o,r,i)}return{activitiesThatCanBeCalculated:r,pendingActivities:i}}handleProjectActivity(t,r,i,n){let o=this.pendingParentsWithNoLinks.has(t),a=this.pendingParentsWithLinks.has(t),s=this.calculationOfParentsFromLinks.has(t);if(o){let c=this.singleParents.get(t)?.childrens;if(!c)return;c.every(d=>this.calculations.has(d))&&(i.add(t),n.delete(t));return}if(a&&s){let c=this.singleParents.get(t)?.childrens;if(!c)return;c.every(d=>this.calculations.has(d))&&(i.add(t),n.delete(t));return}a&&!s&&this.canCalculateParentActivity(r)&&(i.add(t),n.delete(t))}canCalculateParentActivity(t){let r=(t[this.linkProperty]||[]).length===0,i=t.constraint_type;return(this.direction===G.FORWARD?i===h.FNLT||i===h.SNLT:i===h.FNLT)&&r?!0:this.getArrayOfLinkedActivities(t[this.linkProperty]).every(a=>this.calculations.has(a))}handleNonProjectActivity(t,r,i,n){let o=Number(r.parent),a=this.pendingParentsWithLinks.has(o),s=this.calculationOfParentsFromLinks.has(o);if(a&&!s||this.direction===G.BACKWARD&&this.activitiesStartChainButChildrenOfLinkedParents.has(t)&&!s)return;if(r.$target.length===0&&r[qt.SOURCE].length===0){i.add(t),n.delete(t);return}let c=this.getLinkedActivities(r[this.linkProperty]),l=c.every(d=>this.calculations.has(d.id));if(this.direction===G.BACKWARD&&(c.length===0||l)&&s){i.add(t),n.delete(t);return}l&&(i.add(t),n.delete(t))}getLinkedActivities(t){if(!Array.isArray(t))return[];let r=[];for(let i of t){let n=this.gantt.getLink(i);if(!n)continue;let o=n[this.linkDirection],a=this.gantt.getTask(o);a&&r.push(a)}return r}getArrayOfLinkedActivities(t){if(!Array.isArray(t))return[];let r=[];for(let i of t){let n=this.gantt.getLink(i);n&&r.push(Number(n[this.linkDirection]))}return r}},Zi=No;var bo=(e,t)=>()=>t()===e;var Fo=e=>!e?.fullyParsed;var Vh=16,He=async e=>performance.now()-e>Vh?(await st(),performance.now()):e;var zr=async({pending:e,activityCalculator:t,calculateFn:r,shouldKeepPending:i,isCalculated:n,onActivityProcessed:o,isCurrent:a})=>{let s=new Set(e),c=performance.now();for(;s.size>0;){if(!a())return;c=await He(c);let{activitiesThatCanBeCalculated:l,pendingActivities:d}=t.checkActivitiesThatNowCanBeCalculated(s);if(l.size===0)break;for(let u of l){if(!a())return;c=await He(c),r([u])}for(let u of l){if(!a())return;i(u)&&d.add(u),o(u),n(u)&&d.delete(u)}s=d}};var wo=class extends De{constructor(t){super(t,G.FORWARD),this.gantt=t,this.chainStartActivities=new Set,this.secondLevelActivities=new Set,this.pendingParentsWithLinks=new Set,this.pendingParentsWithNoLinks=new Set,this.structureOfParents=new Map,this.singleParents=new Map,this.calculations=new Map,this.calculationsOfParentThatImpactChildrens=new Map,this.alapMap=new Map,this.activitiesWaitingForCalculation=new Set,this.constraintsMap=new Map,this.totalFloatSnltFnlt=new Map,this.totalFloatForMsoMfo=new Map,this.totalFloatForAsap=new Map,this.linkCandidates=new Map,this.calculationOfParentsFromLinks=new Set,this.parentCalculationFromChildren=new Set,this.forbiddenActivitiesLinkedToParentsWithLinks=new Set,this.activitiesStartChainButChildrenOfLinkedParents=new Set,this.identifyInitialActivities(),this.initActivitiesWaitingForCalculation()}async calculateAsync(t){this.identifyParentsWithAndWithoutLinks(),t()&&(this.identifyForbiddenActivitiesLinkedToParentsWithLinks(),t()&&(this.initializeActivitiesWithFullProgress(),t()&&(this.calculateStartAndFinishOfActivitiesThatStartChain(),t()&&(this.identifySecondLevelActivities(),t()&&(this.identifyThirdLevelActivities(),t()&&await this.iterativeCalculateEfAndEs(t))))))}async iterativeCalculateEfAndEs(t){let r=new Zi({gantt:this.gantt,direction:this.direction,pendingParentsWithNoLinks:this.pendingParentsWithNoLinks,pendingParentsWithLinks:this.pendingParentsWithLinks,calculationOfParentsFromLinks:this.calculationOfParentsFromLinks,singleParents:this.singleParents,calculations:this.calculations,activitiesStartChainButChildrenOfLinkedParents:this.activitiesStartChainButChildrenOfLinkedParents,linkProperty:this.linkProperty,linkDirection:this.linkDirection});await zr({pending:this.activitiesWaitingForCalculation,activityCalculator:r,calculateFn:i=>this.calculateStartAndFinishTimes(i),shouldKeepPending:i=>this.calculationOfParentsFromLinks.has(i)&&!this.calculations.has(i),isCalculated:i=>this.calculations.has(i),onActivityProcessed:i=>this.activitiesWaitingForCalculation.delete(i),isCurrent:t})}calculateStartAndFinishTimes(t){t.forEach(r=>{let i=this.gantt.getTask(r);if(i.type===D.PROJECT)return this.doCalculationForParentType(i);if(!i)throw new Error("Error trying to get activity",{cause:{activityId:r}});let n=i.$target,o=i.constraint_type||h.ASAP,a=[h.SNET,h.SNLT,h.FNLT,h.FNET],s=[h.ASAP,h.ALAP,h.SNET,h.FNET,h.SNLT,h.FNLT],c=this.gantt.getCalendar(i.calendar_id);if(!c)throw new Error(`Error trying to get calendar with id: ${i.calendar_id}`);let l=Number(i.progress),d=null,u=null,f=null;if(l===100){this.setDatesForActivityWithFullProgress(i);return}l>0&&s.includes(o)?({es:d,ef:u}=this.getDatesForActivityWithZeroProgress(i),f=new $r({links:n,activity:i,calculatedActivitiesMap:this.calculations,calculatedAlapsMap:this.alapMap,constraint:o,parentsWithLinks:this.pendingParentsWithLinks,parentsCalculations:this.calculationsOfParentThatImpactChildrens,ganttInstance:this.gantt,linkCandidates:this.linkCandidates}).calculate(),o===h.ASAP&&this.totalFloatForAsap.set(r,{es:f.es,ef:f.ef,text:i.text})):{es:d,ef:u}=new $r({links:n,activity:i,calculatedActivitiesMap:this.calculations,calculatedAlapsMap:this.alapMap,constraint:o,parentsWithLinks:this.pendingParentsWithLinks,parentsCalculations:this.calculationsOfParentThatImpactChildrens,ganttInstance:this.gantt,linkCandidates:this.linkCandidates}).calculate(),o===h.ALAP&&this.alapMap.set(r,{es:i.start_date,ef:i.end_date,text:i.text});let p=Xi(i,o,c);if(a.includes(o)&&(this.constraintsMap.set(r,p),this.totalFloatSnltFnlt.set(r,{es:d,ef:u}),{es:d,ef:u}=this.recalculateInBaseConstraint(o,p,{es:d,ef:u})),[h.MSO,h.MFO].includes(o))if(this.totalFloatForMsoMfo.set(r,{es:d,ef:u}),this.constraintsMap.set(r,p),i.progress===0)d=p.es,u=p.ef;else{let y=i.end_date;o===h.MFO&&(y=Math.max(p.ef,i.end_date)),d=i.start_date,u=y}this.calculations.set(r,{es:d,ef:u}),this.activitiesWaitingForCalculation.delete(r)})}getTheGreatesDateBetweenRestrictionAndEsEf(t,r,i=Be.GREATER){if(i===Be.GREATER)return r.ef>t.ef?r:t;if(i===Be.LESS)return r.ef<t.ef?r:t}setDatesForActivityWithFullProgress(t){this.calculations.set(t.id,{es:t.start_date,ef:t.end_date})}getDatesForActivityWithZeroProgress(t){return{es:t.start_date,ef:t.end_date}}recalculateInBaseConstraint(t,r,i){let n=[h.SNET,h.FNET].includes(t)?Be.GREATER:Be.LESS,{es:o,ef:a}=this.getTheGreatesDateBetweenRestrictionAndEsEf(r,i,n);return{es:o,ef:a}}cleanAllActivityParentsFromLinks(t){return t.map(r=>{let i=this.gantt.getLink(r);if(!i)throw new Error("Error trying to get link",{cause:{linkId:r}});let n=i.source,o=i.target;if(!(!this.gantt.getTask(n)||this.gantt.getTask(n)?.type===D.PROJECT)&&!(!this.gantt.getTask(o)||this.gantt.getTask(o)?.type===D.PROJECT))return r}).filter(Boolean)}},Yc=wo;var xo=class{constructor(t){this.activity=t.activity,this.links=t.links,this.calculatedActivities=t.calculatedActivitiesMap,this.forwardPathCalculations=t.calculatedForwardActivitiesMap,this.gantt=t.ganttInstance}getForwardOrBackwardCalculations(t,r=null){return r===h.ALAP?this.forwardPathCalculations.get(t):this.calculatedActivities.get(t)}calculateSuccessorTimes(t,r,i=0,n,o=U.FS){let a=this.gantt.getCalendar(this.activity.calendar_id);if(!a)throw new Error(`Error trying to get calendar with id: ${this.activity.calendar_id}`);let s=t,c=this.activity.type===D.MILESTONE;if(c&&n===0){let d=R(a,s,r,this.activity),u=R(a,d,i,this.activity);return{ls:d,lf:u}}let l={lag:n,workTime:s,activityCalendar:a,lsDataCalculation:r,lfDataCalculation:i,isMilestone:c};if(o===U.FS){let{ls:d,lf:u}=this.calculateFsLink(l);return{ls:d,lf:u}}if(o===U.FF){let{ls:d,lf:u}=this.calculateFFLink(l);return{ls:d,lf:u}}if(o===U.SS){let{ls:d,lf:u}=this.calculateSSlink(l);return{ls:d,lf:u}}if(o===U.SF){let{ls:d,lf:u}=this.calculateSFLink(l);return{ls:d,lf:u}}}calculateSS(t,r=!1){let i=this.getValueForSS(t,r),n=-t.lag||0,o=this.activity.duration,a=t.lag;return this.calculateSuccessorTimes(i,n,o,a,U.SS)}calculateFF(t,r){let i=this.getForwardOrBackwardCalculations(Number(t.target)),n=r===h.ALAP?"ef":"lf",o=i[n],a=-this.activity.duration,s=-t.lag||0,c=t.lag;return this.calculateSuccessorTimes(o,a,s,c,U.FF)}calculateFS(t,r){let i="ls";i=r===h.ALAP?"es":"ls";let n=this.getForwardOrBackwardCalculations(Number(t.target),r),o=-this.activity.duration,a=t.lag||0,s=-t.lag||0;return this.calculateSuccessorTimes(n[i],o,s,a,U.FS)}calculateSF(t,r=!1){let i=r?this.getEarlyStartFromForwardPath(Number(t.target)).ef:this.getForwardOrBackwardCalculations(Number(t.target)).lf,n=-t.lag||0,o=this.activity.duration,a=t.lag;return this.calculateSuccessorTimes(i,n,o,a,U.SF)}getEarlyStartFromForwardPath(t){return this.forwardPathCalculations.get(t)}getValueForSS(t,r){return r?this.getEarlyStartFromForwardPath(Number(t.target)).es:this.getForwardOrBackwardCalculations(Number(t.target))["ls"]}calculateDate(t,r,i){let n=Vt(r).clone();return R(t,new Date(n),i,this.activity)}getLastWorkingHour(t,r,i=K.PAST){let n=t instanceof Date?t:new Date(t),o=Vt(n).clone();return this.isActivityInInitHour(r,n)&&i===K.PAST&&(o=o.hours(0).minutes(0).seconds(0).milliseconds(0)),Mt({dateBaseToCalculate:new Date(o),direction:i,activityCalendar:r,activity:this.activity})}isActivityInInitHour(t,r){let i=r instanceof Date?r:new Date(r),o=t.getWorkHours(i)[0];if(!o||!o.includes("-"))return!1;let a=o.split("-")[0];if(!a.includes(":"))return!1;let s=a.split(":");return s.length<2?!1:(a=parseInt(s[0],10),Vt.isMoment(r)?r.hours()===a:i.getUTCHours()===a)}calculateFsLink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o,isMilestone:a=!1}){let s=null,c=null;if(t===0){let d=this.getLastWorkingHour(r,i,K.PAST);return s=R(i,d,o,this.activity),s=this.getLastWorkingHour(s,i,K.PAST),c=R(i,s,n,this.activity),{ls:c,lf:s}}let l=r;return a||(l=this.getLastWorkingHour(r,i)),s=R(i,l,o,this.activity),c=R(i,s,n,this.activity),a||(s=this.getLastWorkingHour(s,i,K.PAST,!0)),{ls:c,lf:s}}calculateFFLink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o}){let a=null,s=null;if(t===0)return a=R(i,r,o,this.activity),s=R(i,a,n,this.activity),{ls:s,lf:a};let c=r;return t>0&&(c=this.getLastWorkingHour(c,i,K.PAST)),a=R(i,c,o,this.activity),s=R(i,a,n,this.activity),{ls:s,lf:a}}calculateSSlink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o,isMilestone:a=!1}){let s=null,c=null;if(t===0)return c=R(i,r,n,this.activity),s=R(i,c,o,this.activity),{ls:c,lf:s};let l=r;return t<0&&!a&&(l=this.getLastWorkingHour(l,i,"future")),c=R(i,l,n,this.activity),s=R(i,c,o,this.activity),{ls:c,lf:s}}calculateSFLink({lag:t,workTime:r,activityCalendar:i,lsDataCalculation:n,lfDataCalculation:o}){let a=null,s=null;return t===0?(s=R(i,r,n),a=R(i,s,o,this.activity),{ls:s,lf:a}):(s=R(i,r,n,this.activity),a=R(i,s,o,this.activity),{ls:s,lf:a})}},Gc=xo;var Mo=class extends Gc{constructor(t){super(t),this.constraint=t.constraint||h.ASAP,this.parentsWithFullProgress=t.parentsWithFullProgress,this.parentsThatImpactChildrens=t.parentsThatImpactChildrens,this.projectDates=this.gantt.getSubtaskDates()}calculate(){if(this.links.length===0)return new De(this.gantt,G.BACKWARD).calculateStartAndFinishOfChainOrigin(this.activity);let t=this.activity.progress>0&&this.activity.progress<100,r=this.gantt.getTask(this.activity.parent),i=!1;r&&(i=this.parentsThatImpactChildrens.has(Number(this.activity.parent)));let n=this.links.map(a=>{let s=this.gantt.getLink(a);if(!s)throw new Error("Link not found",{cause:{linkId:a}});if(!this.parentsWithFullProgress.has(Number(s.target)))return this.calculateLink(s)}).filter(a=>a);if(n.length!==0){let a=this.getMinLfFromLinks(n);if(n.push(this.calculateTheLsAndLfForTheActivity()),i){let d=this.parentsThatImpactChildrens.get(Number(this.activity.parent));n.push(this.calculateTheLsAndLfForTheActivity(d))}let s=this.getMinDateFromLinks(n),c=s.ls,l=s.lf;return t&&(c=this.activity.start_date,l=this.getMinCalculationLogic(s)),{ls:c,lf:l,minFromLinks:a}}if(i){n.push(this.calculateTheLsAndLfForTheActivity());let s=this.parentsThatImpactChildrens.get(Number(this.activity.parent)).lf,c=R(this.gantt.getCalendar(this.activity.calendar_id),s,-this.activity.duration,this.activity);n.push({ls:c,lf:s});let l=this.getMinDateFromLinks(n);return{ls:l.ls,lf:l.lf,minFromLinks:l}}let o=this.calculateTheLsAndLfForTheActivity();return{ls:o.ls,lf:o.lf,minFromLinks:o}}calculateTheLsAndLfForTheActivity(t=null){try{let r=this.activity.duration,i=this.gantt.getCalendar(this.activity.calendar_id);if(!i)throw new Error(`Calendar not found with id ${this.activity.calendar_id}`);let n=t?t.lf:this.projectDates.end_date;if(!n)throw new Error("End date not found for activity",{cause:{activityId:this.activity.id}});return{ls:R(i,n,-r,this.activity),lf:n}}catch(r){throw Error(r.message)}}SnetSnltMsoMinDate(t){let r=Math.min(t.lf,this.projectDates.end_date);return new Date(Math.max(r,this.activity.end_date))}calculateLink(t){let r=this.gantt.getTask(t.target);if(!r||r.progress>0&&r.type!==D.PROJECT)return;let i=this.getSpecialCalculationParamForConstraintLink(),n=this.getSpecialParamForSf(),o=this.getSpecialParamForFF();return{0:()=>this.calculateFS(t,i),1:()=>this.calculateSS(t),2:()=>this.calculateFF(t,o),3:()=>this.calculateSF(t,n)}[t.type]()}getSpecialCalculationParamForConstraintLink(){if(this.constraint===h.ALAP)return h.ALAP;if(this.constraint===h.FNET||this.constraint===h.SNET)return"snet-fnet";if(this.constraint===h.FNLT)return h.FNLT}getSpecialParamForSf(){return!![h.ALAP].includes(this.constraint)}getSpecialParamForFF(){return!![h.MFO,h.MSO].includes(this.constraint)}getMinCalculationLogic(t){if(this.constraint===h.ALAP)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.FNET)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.FNLT)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.MFO)return this.getMinDateBasedOnConstraint(t);if(this.constraint===h.SNET||this.constraint===h.SNLT||this.constraint===h.MSO)return this.SnetSnltMsoMinDate(t);if(this.constraint===h.ASAP)return this.getMinDateBasedOnConstraint(t)}getMinDateFromLinks(t){try{return this.constraint===h.ALAP||this.constraint===h.ASAP?t.reduce((i,n)=>n.lf<i.lf?n:i):t.reduce((r,i)=>i.ls<r.ls?i:r)}catch(r){throw new Error(`Function: getMinDateFromLinks in LinksConstraintCalculator - ${r.message}`)}}getMinLfFromLinks(t){return t.reduce((r,i)=>i.lf<r.lf?i:r)}getMinDateBasedOnConstraint(t,r=this.constraint){let i=Math.min(t.lf,this.projectDates.end_date),n=this.activity.end_date,o=this.activity.constraint_date;if(r===h.ASAP)return new Date(Math.max(i,n));if(r===h.FNET||r===h.FNLT){let a=Math.min(i,o);return new Date(Math.max(i,a))}if(r===h.ALAP)return new Date(Math.min(i,n))}},$c=Mo;function Kh(e,t,r){let i={ls:null,lf:null};return r===h.MSO&&(i.ls=t.constraint_date,i.lf=R(e,i.ls,t.duration,t)),r===h.MFO&&(i.lf=t.constraint_date,i.ls=R(e,i.lf,-t.duration,t)),i}var zc=Kh;var Uo=class extends De{constructor(t,r,i){super(t,G.BACKWARD),this.gantt=t,this.chainStartActivities=new Set,this.secondLevelActivities=new Set,this.pendingParentsWithLinks=new Set,this.pendingParentsWithNoLinks=new Set,this.structureOfParents=new Map,this.singleParents=new Map,this.calculationsOfParentThatImpactChildrens=new Map,this.activitiesWaitingForCalculation=new Set,this.calculations=new Map,this.mapOfRelationsWithActivitiesIds=new Map,this.activitiesWaitingForCalculation=new Set,this.forwardPathCalculations=r,this.forwardConstraintsMap=i,this.constraintMap=new Map,this.minFromLinks=new Map,this.activitiesStartChainButChildrenOfLinkedParents=new Set,this.calculationOfParentsFromLinks=new Set,this.parentCalculationFromChildren=new Set,this.parentsWithFullProgress=new Set,this.forbiddenActivitiesLinkedToParentsWithLinks=new Set,this.identifyInitialActivities(),this.initActivitiesWaitingForCalculation()}async calculateAsync(t){this.identifyParentsWithAndWithoutLinks(),t()&&(this.identifyForbiddenActivitiesLinkedToParentsWithLinks(),t()&&(this.initializeActivitiesWithFullProgress(),t()&&(this.calculateStartAndFinishOfActivitiesThatStartChain(),t()&&(this.identifySecondLevelActivities(),t()&&(this.identifyThirdLevelActivities(),t()&&await this.iterativeCalculateLfAndLs(t))))))}async iterativeCalculateLfAndLs(t){let r=new Zi({gantt:this.gantt,direction:this.direction,pendingParentsWithNoLinks:this.pendingParentsWithNoLinks,pendingParentsWithLinks:this.pendingParentsWithLinks,calculationOfParentsFromLinks:this.calculationOfParentsFromLinks,singleParents:this.singleParents,calculations:this.calculations,activitiesStartChainButChildrenOfLinkedParents:this.activitiesStartChainButChildrenOfLinkedParents,linkProperty:this.linkProperty,linkDirection:this.linkDirection});await zr({pending:this.activitiesWaitingForCalculation,activityCalculator:r,calculateFn:i=>this.calculateStartAndFinishTimes(i),shouldKeepPending:i=>this.calculationOfParentsFromLinks.has(i)&&!this.calculations.has(i),isCalculated:i=>this.calculations.has(i),onActivityProcessed:i=>this.activitiesWaitingForCalculation.delete(i),isCurrent:t})}setDatesToParentsWithLinks(t){if(!t)throw new Error("Error trying to get parent",{cause:{receivedParentData:t}});let r=this.singleParents.get(t.id).childrens,n=Array.from(this.calculations).filter(s=>r.includes(s[0])).map(s=>s[1]),{minLs:o,maxLf:a}=n.reduce((s,{ls:c,lf:l})=>({minLs:new Date(Math.min(s.minLs.getTime(),new Date(c).getTime())),maxLf:new Date(Math.max(s.maxLf.getTime(),new Date(l).getTime()))}),{minLs:new Date(n[0].ls),maxLf:new Date(n[0].lf)});this.calculations.set(t.id,{ls:o,lf:a})}calculateStartAndFinishTimes(t){t.forEach(r=>{let i=this.gantt.getTask(r);if(!i)throw new Error("Activity not found",{cause:{activityId:r}});let n=i.$source,o=i.constraint_type||h.ASAP,a=Number(i.progress);if(this.activitiesStartChainButChildrenOfLinkedParents.has(r)){if(this.calculationsOfParentThatImpactChildrens.has(Number(i.parent))&&this.calculationsOfParentThatImpactChildrens.get(Number(i.parent))===!1){let{ls:d,lf:u}=this.calculateStartAndFinishOfChainOrigin(i,this.direction);this.setCalculations(i,d,u);return}return this.doCalculationForActivitiesThatStartLinkButHisParentIsLinked(i)}if(i.type===D.PROJECT)return this.doCalculationForParentType(i);if(a===100){this.setDatesForActivityWithFullProgress(i);return}if(this.allLinkedActivitiesHasProgress(n,i)){this.setWhenAllLinkedActivitiesHasProgress(i);return}if(a>0&&a<100&&(o===h.MSO||o===h.MFO)){this.setWhenActivitiesHasProgressButLessThanOneHundred(i,o);return}if(o===h.MSO||o===h.MFO){this.recalculateInBaseRestriction(i,o);return}let{ls:s,lf:c,minFromLinks:l}=this.calculateLfandLsFromLinks(n,i,o,this.parentsWithFullProgress,this.calculationsOfParentThatImpactChildrens);(o===h.SNLT||o===h.FNLT)&&({ls:s,lf:c}=this.getTheLessLateInBasEsEfConstraint(i.id,{ls:s,lf:c},o)),this.setCalculations(i,s,c),this.minFromLinks.set(i.id,{ls:l.ls,lf:l.lf})})}getTheLessLateInBasEsEfConstraint(t,r,i){let n=this.forwardConstraintsMap.get(t);if(!n){let o=this.gantt.getTask(t),a=this.gantt.getCalendar(o.calendar_id);n=Xi(o,i,a)}return r.lf<n.ef?r:{ls:n.es,lf:n.ef}}allLinkedActivitiesHasProgress(t){try{let r=!0;for(let i of t){let n=this.gantt.getLink(i);if(!n)continue;let o=this.gantt.getTask(n.target);o&&(o.type===D.PROJECT&&(r=!1),o.progress===0&&(r=!1))}return r}catch(r){throw new Error(r.message)}}setDatesForActivityWithFullProgress(t){this.setCalculations(t,t.start_date,t.end_date)}setWhenAllLinkedActivitiesHasProgress(t){let r=Number(t.parent),{ls:i,lf:n}=this.calculateStartAndFinishOfChainOrigin(t,G.BACKWARD);if(this.calculationsOfParentThatImpactChildrens.has(r)){i=t.start_date;let o=this.calculationsOfParentThatImpactChildrens.get(r);o&&typeof o=="object"&&o.lf!=null&&(n=new Date(Math.min(n,o.lf)))}this.setCalculations(t,i,n)}setWhenActivitiesHasProgressButLessThanOneHundred(t,r){if(r===h.MSO){this.setCalculations(t,t.start_date,t.end_date);return}if(r===h.MFO){let i=Math.min(t.constraint_date,this.projectDates.end_date),n=new Date(Math.max(i,t.end_date));this.setCalculations(t,t.start_date,n);return}}setCalculations(t,r,i){this.calculations.set(t.id,{ls:r,lf:i,text:t.text})}calculateLfandLsFromLinks(t,r,i,n,o){return new $c({links:t,activity:r,calculatedActivitiesMap:this.calculations,calculatedForwardActivitiesMap:this.forwardPathCalculations,constraint:i,parentsWithFullProgress:n,parentsThatImpactChildrens:o,ganttInstance:this.gantt}).calculate()}recalculateInBaseRestriction(t,r){try{let i=this.gantt.getCalendar(t.calendar_id);if(!i)throw new Error(`Error trying to get calendar with id: ${t.calendar_id}`);let n=zc(i,t,r);this.constraintMap.set(t,n),this.setCalculations(t,n.ls,n.lf)}catch(i){throw new Error(i.message)}}cleanAllActivityParentsFromLinks(t){return t.map(r=>{let i=this.gantt.getLink(r).source,n=this.gantt.getLink(r).target;if(!(!this.gantt.getTask(i)||this.gantt.getTask(i)?.type===D.PROJECT)&&!(!this.gantt.getTask(n)||this.gantt.getTask(n)?.type===D.PROJECT))return r}).filter(Boolean)}doCalculationForActivitiesThatStartLinkButHisParentIsLinked(t){let r=Number(t.parent),i=this.calculationsOfParentThatImpactChildrens.get(r),n=0,o=0;if([h.ASAP,h.ALAP,h.SNET,h.FNET].includes(t.constraint_type))if(Number(t.progress)>0){let l=this.projectDates.end_date;o=new Date(Math.min(l,i.lf)),n=t.start_date}else o=i.lf,n=R(this.gantt.getCalendar(t.calendar_id),o,-t.duration,t);if([h.SNLT].includes(t.constraint_type)){let l=this.calculationsOfParentThatImpactChildrens.get(r),d=R(this.gantt.getCalendar(t.calendar_id),l.lf,-t.duration,t),u=t.constraint_date??d;n=new Date(Math.min(u.getTime(),d.getTime())),o=R(this.gantt.getCalendar(t.calendar_id),n,t.duration,t)}if([h.FNLT].includes(t.constraint_type)){let l=this.calculationsOfParentThatImpactChildrens.get(r),d=t.constraint_date??l.lf;n=new Date(Math.min(d.getTime(),l.lf.getTime())),o=R(this.gantt.getCalendar(t.calendar_id),n,t.duration,t)}[h.MSO].includes(t.constraint_type)&&(n=t.constraint_date,o=R(this.gantt.getCalendar(t.calendar_id),n,t.duration,t)),[h.MFO].includes(t.constraint_type)&&(o=t.constraint_date,n=R(this.gantt.getCalendar(t.calendar_id),o,-t.duration,t));let a=this.projectDates.end_date,s=[{ls:n,lf:o}];s.push({ls:R(this.gantt.getCalendar(t.calendar_id),a,-t.duration,t),lf:a});let c=this.getMinLfFromLinks(s);this.calculations.set(t.id,{ls:c.ls,lf:c.lf,text:t.text})}getMinLfFromLinks(t=[]){return t.length?t.reduce((r,i)=>i.lf<r.lf?i:r):!1}},qc=Uo;function Jc(){return null}var Xc=({forward:e,backward:t,id:r,activity:i,gantt:n,projectDates:o})=>({totalFloat:{es:e.calculations.get(r)?.es||0,ef:e.calculations.get(r)?.ef||0,ls:t.calculations.get(r)?.ls||0,lf:t.calculations.get(r)?.lf||0,constraintsMap:e.constraintsMap.get(r),totalFloatSnltFnlt:e.totalFloatSnltFnlt.get(r),totalFloatForMsoMfo:e.totalFloatForMsoMfo.get(r),minFromLinks:t.minFromLinks.get(r),activity:i,gantt:n},freeFloat:{forwardMap:e.calculations||new Map,backwardMap:t.calculations||new Map,activity:i,projectDates:o,gantt:n}});var Bo=class{constructor(t){this.gantt=t.gantt,this.activity=t.activity,this.es=t.es,this.ef=t.ef,this.ls=t.ls,this.lf=t.lf,this.constrainstMap=t.constraintsMap,this.totalFloatSnltFnlt=t.totalFloatSnltFnlt,this.totalFloatForMsoMfo=t.totalFloatForMsoMfo,this.minFromLinks=t.minFromLinks}getTotalFloat(){let{constraint_type:t}=this.activity,r=Number(this.activity.progress);if(r===100)return 0;if(t||(t=h.ASAP),t===h.ASAP||!t)return r===0?this.calculateAsap():this.calculateAsapWithProgress();if(t===h.ALAP)return r===0?this.calculateAlap():this.calculateAlapWithProgress();if(t===h.SNET||t===h.FNET)return r===0?this.calculateSnetFet():this.calculateSnetFnetSnltWithProgress();if(t===h.SNLT)return r===0?this.calculateSnltFnlt():this.calculateSnetFnetSnltWithProgress();if(t===h.FNLT)return r===0?this.calculateSnltFnlt():this.calculateFnltWithProgress();if(t===h.MSO||t===h.MFO)return r===0?this.calculateMsoMfo():this.calculateMsoMfoWithProgress()}calculateAsap(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}calculateAsapWithProgress(){let t=this.calculationWithCalendar(this.lf,this.ef);if(this.minFromLinks){let r=this.calculationWithCalendar(this.minFromLinks.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}return t/this.gantt.config.hoursPerDay}calculateAlap(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef),i=this.getMinValue(t,r),n=this.calculationWithCalendar(this.lf,this.activity.end_date);return this.getMinValue(i,n)/this.gantt.config.hoursPerDay}calculateAlapWithProgress(){return this.calculationWithCalendar(this.lf,this.ef)/this.gantt.config.hoursPerDay}calculateSnetFnetSnltWithProgress(){let t=this.calculationWithCalendar(this.lf,this.ef);if(this.minFromLinks){let r=this.calculationWithCalendar(this.minFromLinks.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}return t/this.gantt.config.hoursPerDay}calculateFnltWithProgress(){let t=this.calculationWithCalendar(this.lf,this.ef),r=this.calculationWithCalendar(this.activity.constraint_date,this.ef);if(this.minFromLinks){let i=this.calculationWithCalendar(this.minFromLinks.lf,this.ef);return this.getMinValue(t,r,i)/this.gantt.config.hoursPerDay}return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}calculateMsoMfoWithProgress(){return this.calculationWithCalendar(this.lf,this.ef)/this.gantt.config.hoursPerDay}calculateSnetFet(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef);return this.getMinValue(t,r)/this.gantt.config.hoursPerDay}calculateSnltFnlt(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef),i=this.getMinValue(t,r);if(!this.totalFloatSnltFnlt&&!this.constrainstMap)return this.getMinValue(t,r)/this.gantt.config.hoursPerDay;let n=0;return this.activity.constraint_type===h.SNLT?n=this.calculationWithCalendar(this.constrainstMap.es,this.totalFloatSnltFnlt.es):n=this.calculationWithCalendar(this.constrainstMap.ef,this.totalFloatSnltFnlt.ef),this.getMinValue(n,i)/this.gantt.config.hoursPerDay}calculateMsoMfo(){let t=this.calculationWithCalendar(this.ls,this.es),r=this.calculationWithCalendar(this.lf,this.ef),i=this.getMinValue(t,r);if(!this.totalFloatForMsoMfo&&!this.constrainstMap)return this.getMinValue(t,r)/this.gantt.config.hoursPerDay;let n=0;return this.activity.constraint_type===h.MSO?n=this.calculationWithCalendar(this.constrainstMap.es,this.totalFloatForMsoMfo.es):n=this.calculationWithCalendar(this.constrainstMap.ef,this.totalFloatForMsoMfo.ef),this.getMinValue(n,i)/this.gantt.config.hoursPerDay}getMinValue(...t){return Math.min(...t)}calculationWithCalendar(t,r){return this.gantt.getCalendar(this.activity.calendar_id).calculateDuration({start_date:new Date(r),end_date:new Date(t)})}},Zc=Bo;var Ho=class{constructor(t){this.gantt=t.gantt,this.activity=t.activity,this.forwardMap=t.forwardMap,this.backwardMap=t.backwardMap,this.projectDates=t.projectDates,this.linksFreeFloatArray=[],this.linksFreeFloatObject={},this.durationCache=new Map}getFreeFloat(){let t=Number(this.activity.progress),r=this.getConstraintType();return this.calculateFreeFloatOfLink(r),{activityFreeFloat:t===100?0:this.getFreeFloatBaseConstraint(r),linksFreeFloat:this.linksFreeFloatObject}}getFreeFloatBaseConstraint(t){return t===h.MSO||t===h.MFO?this.calculateMsoMfo(t):this.calculateGeneral(t)}calculateFreeFloatOfLink(t=h.ASAP){let r=this.activity.$source.map(i=>{let{LINK:n,LINK_TYPE:o}=this.getLinkData(i),a=this.gantt.getTask(n.target);if(!a)return{linkId:n.id,freeFloat:null,hasProgress:!1};let s=Number(a.progress)>0,{sucessorDateToCalculate:c,predecessorDateToCalculate:l}=this.getDatesFromSucessorAndPredecessor(o,t,a),d=this.calculationWithCalendar(c,l),u=this.parseHoursToDays(d)-this.parseHoursToDays(n.lag),f=Math.max(0,u);return this.linksFreeFloatObject[n.id]=f,{linkId:n.id,freeFloat:f,hasProgress:s}}).filter(i=>i.freeFloat!==null&&i.freeFloat!==void 0);return this.linksFreeFloatArray=r,r}calculateGeneral(t=h.ASAP){let r=this.getMinFloat(this.linksFreeFloatArray),i=this.calculateFreeFloatForEndOfProject(t),n=0;return[h.SNLT,h.FNLT].includes(t)?n=this.doCalculationForSnltFnlt(t,i,r):n=this.doGeneralCalculation(i,r),Math.max(0,n)}getConstraintType(){let{constraint_type:t}=this.activity;return t||(t=h.ASAP),t}getDatesFromSucessorAndPredecessor(t,r,i){let n=i.constraint_type===h.ALAP,o=this.getSucessorAndPredecessorDates({constraint:r,isSuscessorAlap:n,sucessorId:i.id,predecessorId:this.activity.id}),a=new Date,s=new Date;return a=o[t].sucessor,s=o[t].predecessor,{sucessorDateToCalculate:a,predecessorDateToCalculate:s}}doGeneralCalculation(t,r){return r===null?t:this.getMinValue(r,t)}doCalculationForSnltFnlt(t,r,i){let n=this.calculateFreeFloatOfRestriction(t);return this.getMinValue(i,r,n)}calculateFreeFloatForEndOfProject(t){let r=t===h.ALAP?this.backwardMap.get(this.activity.id):this.forwardMap.get(this.activity.id);return this.parseHoursToDays(this.calculationWithCalendar(this.gantt.getSubtaskDates().end_date,t===h.ALAP?r?.lf:r?.ef))}calculateFreeFloatOfRestriction(t){let r=this.forwardMap.get(this.activity.id);return this.parseHoursToDays(this.calculationWithCalendar(this.activity.constraint_date,t===h.FNLT?r?.ef:r?.es))}getLinkData(t){let r=this.gantt.getLink(t)||{},i=Ue(r.type);return{LINK:r,LINK_TYPE:i}}getSucessorAndPredecessorDates({constraint:t,isSuscessorAlap:r,sucessorId:i,predecessorId:n}){let o=(r?this.backwardMap:this.forwardMap).get(i),a=(t===h.ALAP?this.backwardMap:this.forwardMap).get(n),s=t===h.ALAP?a?.ls:a?.es,c=t===h.ALAP?a?.lf:a?.ef;return{fs:{sucessor:o?.ls??o?.es,predecessor:c},ss:{sucessor:o?.ls??o?.es,predecessor:s},ff:{sucessor:o?.lf??o?.ef,predecessor:c},sf:{sucessor:o?.lf??o?.ef,predecessor:s}}}calculateMsoMfo(t){let r=this.activity.constraint_date||new Date,i=this.forwardMap.get(this.activity.id),n=t===h.MSO?i?.es:i?.ef,o=this.calculationWithCalendar(r,n);return Math.max(0,this.parseHoursToDays(o))}getMinValue(...t){let r=t.filter(i=>i!=null);return r.length?Math.min(...r):0}calculationWithCalendar(t,r){if(!(t instanceof Date)||!(r instanceof Date)||!Number.isFinite(t.getTime())||!Number.isFinite(r.getTime()))return Number.NaN;let i=`${r.getTime()}_${t.getTime()}`;if(this.durationCache.has(i))return this.durationCache.get(i);let o=this.gantt.getCalendar(this.activity.calendar_id).calculateDuration({start_date:new Date(r),end_date:new Date(t)});return this.durationCache.set(i,o),o}parseHoursToDays(t){return t==null?0:t/this.gantt.config.hoursPerDay}getMinFloat(t){if(!t?.length)return null;let r=t.filter(i=>!i.hasProgress).map(i=>i.freeFloat);return r.length===0?null:Math.min(...r)}},Qc=Ho;var tl=e=>({totalFloat:new Zc(e.totalFloat).getTotalFloat(),freeFloat:new Qc(e.freeFloat).getFreeFloat()});var Wo=async({activityIds:e,forward:t,backward:r,gantt:i,projectDates:n,isCurrent:o})=>{let a=performance.now(),s=new Map,c=new Map;for(let l of e){if(o&&!o())return{totalFloatMap:s,freeFloatMap:c};let d=i.getTask(l);if(!d)continue;let u=Xc({forward:t,backward:r,id:l,activity:d,gantt:i,projectDates:n}),{totalFloat:f,freeFloat:p}=tl(u);s.set(l,f),c.set(l,p),a=await He(a)}return{totalFloatMap:s,freeFloatMap:c}};var Vo=class{constructor(t){this.gantt=t,this.forwardPathCalculations=null,this.backwardPathCalculations=null,this.totalFloat=new Map,this.freeFloat=new Map,this.linkResidualHours=new Map,this.currentCalculationId=0}getCurrentCalculationId=()=>this.currentCalculationId;async calculate(t,r=()=>!0){let i=++this.currentCalculationId,n=bo(i,this.getCurrentCalculationId),o=()=>n()&&r();try{let a=t||this.gantt;if(this.gantt=a||Jc(),Fo(this.gantt))return!1;let s=new Yc(this.gantt);if(await s.calculateAsync(o),!o())return!1;let c=s.calculations,l=s.constraintsMap,d=new qc(this.gantt,c,l);if(await d.calculateAsync(o),!o())return!1;this.forwardPathCalculations=c,this.backwardPathCalculations=d.calculations;let u=await this.calculateLinkResidualHours(s.linkCandidates,c,o);if(!u||!o())return!1;this.linkResidualHours=u;let{totalFloatMap:f,freeFloatMap:p}=await this.calculateFloatsAsync(s,d,o);return o()?(this.totalFloat=f,this.freeFloat=p,this.gantt.refreshData(),!0):!1}catch(a){throw this.forwardPathCalculations?.size,a}}async calculateLinkResidualHours(t,r,i=()=>!0){let n=new Map,o=performance.now();for(let[a,s]of t){if(o=await He(o),!i())return null;let c=Number(s.targetId),l=this.gantt.getTask(c),d=r.get(c),u=s.ef,f=d?.ef,p=l&&this.gantt.getCalendar(l.calendar_id);if(!p||!(u instanceof Date)||!(f instanceof Date)||!Number.isFinite(u.getTime())||!Number.isFinite(f.getTime())){n.set(a,null);continue}let y=u.getTime(),C=f.getTime()>=y?p.calculateDuration({start_date:u,end_date:f}):-p.calculateDuration({start_date:f,end_date:u});n.set(a,Number.isFinite(C)?Object.is(C,-0)?0:C:null)}return n}async calculateFloatsAsync(t,r,i){try{let n=this.gantt.getSubtaskDates(),o=Array.from(this.forwardPathCalculations.keys());return await Wo({activityIds:o,forward:t,backward:r,gantt:this.gantt,projectDates:n,isCurrent:i})}catch(n){throw this.forwardPathCalculations?.size,n}}},el=Vo;var jh=e=>e===A.FNET||e===A.FNLT||e===A.MFO,Yh=e=>new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()));function Gh(e,t){let r=e.constraintDate;if(!r||!jh(e.constraintType))return r;let i=Yh(r);if(r.getTime()!==i.getTime())return r;let n=t.getClosestWorkTime({date:i,dir:"future",task:e});return n.getUTCFullYear()===r.getUTCFullYear()&&n.getUTCMonth()===r.getUTCMonth()&&n.getUTCDate()===r.getUTCDate()?jn(e,t):r}function $h(e){let t=new Map,r=new Map,i=new Map;return{calculateEndDate:({start_date:n,duration:o})=>{let a=`${n.getTime()}|${o}`,s=t.get(a);if(s!==void 0)return new Date(s);let c=e.calculateEndDate(n,o);return t.set(a,c.getTime()),c},calculateDuration:({start_date:n,end_date:o})=>{let a=`${n.getTime()}|${o.getTime()}`,s=r.get(a);if(s!==void 0)return s;let c=e.calculateDuration(n,o);return r.set(a,c),c},getWorkHours:n=>e.getWorkHours(n),$gantt:{getClosestWorkTime:({date:n,dir:o,unit:a})=>{let s=a??"hour",c=`${n.getTime()}|${o}|${s}`,l=i.get(c);if(l!==void 0)return new Date(l);let d=e.getClosestWorkTime({date:n,direction:o,unit:s});return i.set(c,d.getTime()),d}}}}function zh(e){let t=new Map;e.forEachActivity((n,o)=>t.set(String(o),n));let r=new Map,i=(n,o)=>{let a=r.get(n);if(a!=null)return a;let c=t.get(n)?.parentId??null,l=0;return c!==null&&!o.has(n)&&(o.add(n),l=i(String(c),o)+1),r.set(n,l),l};for(let n of t.keys())i(n,new Set);return r}function qh(e){let t=new Set;e.forEachActivity((s,c)=>{t.add(String(c)),s.parentId!==null&&t.add(String(s.parentId))});let r=new Map;for(let s of t){let c=Number(s);Number.isSafeInteger(c)&&c!==0&&r.set(c,(r.get(c)??0)+1)}let i=new Map,n=new Map;for(let s of t){let c=Number(s);Number.isSafeInteger(c)&&c!==0&&r.get(c)===1&&(i.set(s,c),n.set(c,s))}let o=1,a=s=>{let c=String(s),l=i.get(c);if(l!==void 0)return l;for(;n.has(o);)o+=1;return i.set(c,o),n.set(o,c),o++};for(let s of t)a(s);return{toLegacy:a,toCanonical:s=>typeof s=="number"?n.get(s)??null:i.has(String(s))?String(s):null}}function Jh(e,t){let r=zh(e),i=new Map;return e.forEachActivity((n,o)=>{let a=String(o);i.set(a,{id:t.toLegacy(a),parent:n.parentId===null?0:t.toLegacy(n.parentId),$level:r.get(a)??0,$source:e.getOutgoingLinkIds(a),$target:e.getIncomingLinkIds(a),start_date:n.startDate,end_date:n.endDate,duration:n.durationHours,progress:n.progress,type:n.type,calendar_id:n.calendarId,constraint_type:n.constraintType,constraint_date:Gh(n,e)})}),i}function Xh(e){let t=new Map;for(let a of e.values()){let s=t.get(a.parent);s?s.push(a):t.set(a.parent,[a])}let r=[],i=new Set,n=[],o=a=>{if(a)for(let s=a.length-1;s>=0;s-=1)n.push(a[s])};for(o(t.get(0));n.length>0;){let a=n.pop();i.has(a)||(i.add(a),r.push(a),o(t.get(a.id)))}if(r.length<e.size)for(let a of e.values())i.has(a)||r.push(a);return r}function Zh(e){let t=null,r=null;return e.forEachActivity(i=>{if(i.startDate){let n=i.startDate.getTime();t=t==null?n:Math.min(t,n)}if(i.endDate){let n=i.endDate.getTime();r=r==null?n:Math.max(r,n)}}),{start_date:new Date(t??0),end_date:new Date(r??0)}}async function rl(e,t){let r=new Map,i=l=>{let d=l==null?"__default__":String(l),u=r.get(d);if(u)return u;let f=e.calendarReader.getCalendar(String(l)),p=$h(f);return r.set(d,p),p},n=Zh(e);await st();let o=qh(e),a=Jh(e,o);await st();let s=[...a.values()].sort((l,d)=>(l.start_date?.getTime()??0)-(d.start_date?.getTime()??0));await st();let c=Xh(a);return{fullyParsed:!0,config:{hoursPerDay:t},getTask:l=>{let d=o.toCanonical(l);return d===null?null:a.get(d)??null},getLink:l=>{let d=e.getLink(l);return d?{...d,source:o.toLegacy(d.source),target:o.toLegacy(d.target),lag:d.lag}:null},getCalendar:i,getChildren:l=>{let d=o.toCanonical(l);return d===null?[]:e.getChildren(d).map(o.toLegacy)},eachTask:l=>{for(let d of c)l(d)},getTaskByTime:()=>s,getSubtaskDates:()=>n,getCanonicalActivityId:o.toCanonical,refreshData:()=>{}}}var jo=1e3,Qh=e=>typeof e!="number"||!Number.isFinite(e)?null:Object.is(e,-0)?0:e,tm=(e,t)=>typeof e!="number"||e<0?null:Ko(e,t);function em(e){let t=tm(e.freeFloatDays,e.hoursPerDay),r=Qh(e.residualHours);return{freeSlackHours:t,isCritical:r!==null&&r<=0&&e.sourceIsCritical&&e.targetIsCritical&&e.targetProgress===0}}async function rm(e,t){let r=new Map,i=0;for(let n of e.values())for(let o in n.linksFreeFloat)if(Object.hasOwn(n.linksFreeFloat,o)){if(++i>=jo&&(i=0,await st(),!t()))return null;r.set(String(o),n.linksFreeFloat[o])}return t()?r:null}async function im(e,t,r,i,n){let o=new Map,a=0;for(let s of t.forward?.keys()??[]){if(++a>=jo&&(a=0,await st(),!n()))return null;let c=i(s);if(c===null)continue;let l=e.getActivity(c);l&&o.set(String(c),om(s,Number(l.progress??0),t,r))}return n()?o:null}async function nm(e,t,r,i,n,o){let a=new Map,s=0;for(let c of e.getAllLinks()){if(++s>=jo&&(s=0,await st(),!o()))return null;a.set(String(c.id),em({freeFloatDays:t.get(String(c.id)),residualHours:r.get(String(c.id)),hoursPerDay:n,sourceIsCritical:i.get(c.source)?.isCritical===!0,targetIsCritical:i.get(c.target)?.isCritical===!0,targetProgress:e.getActivity(c.target)?.progress}))}return o()?a:null}var Ko=(e,t)=>{if(typeof e!="number"||!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return null;let r=e*t;return Number.isFinite(r)?Object.is(r,-0)?0:r:null};function om(e,t,r,i){let n=c=>{if(c==null)return null;let l=new Date(c);return Number.isFinite(l.getTime())?l:null},o=r.forward?.get(e),a=r.backward?.get(e),s=Ko(r.totalFloat.get(e),i);return{criticalPath:{earlyStart:n(o?.es),earlyFinish:n(o?.ef),lateStart:n(a?.ls),lateFinish:n(a?.lf),totalSlackHours:s},isCritical:t<100&&s!==null&&s<=0,freeSlackHours:Ko(r.freeFloat.get(e)?.activityFreeFloat,i)}}var Qi=(e,t)=>e===t||e!==null&&t!==null&&e.getTime()===t.getTime();function Yo(e,t,r){let i=e.getActivity(t),n=i?.criticalPath,o=r.criticalPath;i&&n&&Qi(n.earlyStart,o.earlyStart)&&Qi(n.earlyFinish,o.earlyFinish)&&Qi(n.lateStart,o.lateStart)&&Qi(n.lateFinish,o.lateFinish)&&Object.is(n.totalSlackHours,o.totalSlackHours)&&Object.is(i.isCritical,r.isCritical)&&Object.is(i.freeSlackHours,r.freeSlackHours)||e.setActivityFields(t,r)}function Go(e,t,r){let i=e.getLink(t);!i||Object.is(i.freeSlackHours,r.freeSlackHours)&&Object.is(i.isCritical,r.isCritical)||(e.setLinkField(t,"freeSlackHours",r.freeSlackHours),e.setLinkField(t,"isCritical",r.isCritical))}async function $o(e,t,r=()=>!0){if(!r())return null;let i=await rl(e,t);if(!r())return null;let n=new el(i);if(!await n.calculate(i,r)){if(!r())return null;throw new Error("critical path calculation aborted")}if(!r())return null;let a={forward:n.forwardPathCalculations,backward:n.backwardPathCalculations,totalFloat:n.totalFloat,freeFloat:n.freeFloat},s=await im(e,a,t,i.getCanonicalActivityId,r);if(!s)return null;let c=await rm(a.freeFloat,r);if(!c)return null;let l=await nm(e,c,n.linkResidualHours,s,t,r);return l?{activities:s,links:l}:null}async function il(e,t,r=()=>!0){let i=await $o(e,t,r);if(!i||!r())return!1;for(let[n,o]of i.activities){if(!r())return!1;Yo(e,n,o)}for(let[n,o]of i.links){if(!r())return!1;Go(e,n,o)}return!0}function fr(e){let t=[],r=[];e.forEachActivity((n,o)=>{n.parentId===null&&t.push(String(o))});let i=n=>{let o=e.getActivity(String(n));if(!o)return 0;let a=[...e.getChildren(String(n))],s;if(a.length===0){let c=Rt(o),l=c&&Number(c.cost)||0;s=(Number(o.progress)||0)/100*l}else{let c=0;for(let l of a)c+=i(String(l));s=c}return e.setActivityField(String(n),x.REAL_COST,s),r.push(String(n)),s};for(let n of t)i(n);return r}var nl=new Set;var ol=new Set(["activity-outdent","activity-indent"]);var qr=new Set([_.TEXT,_.DESCRIPTION,_.COST,_.USED_COST,_.CUSTOM_ID,_.RESPONSABLES,_.SUBCONTRACT_ID,_.TAGS]),am=new Set([m.ACTIVITY_CLIPBOARD_CLEAR,m.ACTIVITY_COPY,m.SELECTION_TOGGLE,m.SELECTION_REPLACE,m.VISIBILITY_SET,m.FILTER_SET,m.SORT_SET,m.SIR_SYNC,m.ACTIVITY_LOOKAHEAD_SYNC,m.PERSISTENCE_ACKNOWLEDGE,m.BASELINE_APPLY,m.PONDERATOR_CRITERION_SET,m.STATUS_CRITERIA_SET]),sm=new Set([m.ACTIVITY_CLIPBOARD_CLEAR,m.ACTIVITY_COPY,m.SELECTION_TOGGLE,m.SELECTION_REPLACE,m.VISIBILITY_SET,m.FILTER_SET,m.SORT_SET]);function sl(e){return!sm.has(e.kind)}var cm=new Set;function lm(e){return e.kind===m.INLINE_EDIT?qr.has(e.column):e.kind===m.BULK_EDIT?e.edits.every(t=>qr.has(t.column)):!1}function zo(e,t){return!(am.has(e.kind)||t.has(e.kind)||lm(e))}function qo(e){return e.kind===m.ACTIVITY_LOOKAHEAD_SYNC?e.persistedProgress!==void 0:zo(e,cm)}function We(e){return e.kind===m.ACTIVITY_LOOKAHEAD_SYNC?e.persistedProgress!==void 0:zo(e,nl)}function cl(e){return zo(e,ol)}function Jo(e){return e.kind===m.ACTIVITY_SET_PROGRESS?!0:e.kind===m.INLINE_EDIT?e.column===_.PROGRESS:e.kind===m.BULK_EDIT?e.edits.some(t=>t.column===_.PROGRESS):!1}function dm(e){return cl(e)&&Jo(e)}var al=new Set([_.PROGRESS,_.HH_WORK_TIME,_.DURATION,_.COST,_.USED_COST,_.REAL_COST]);function um(e){return e.kind===m.ACTIVITY_SET_PROGRESS?!0:e.kind===m.INLINE_EDIT?al.has(e.column):e.kind===m.BULK_EDIT?e.edits.some(t=>al.has(t.column)):!1}var Tt={AUTOSCHEDULE:"autoschedule",PARENT_BOUNDS:"parent-bounds",PARENT_PROGRESS:"parent-progress",REAL_WORK:"real-work",EXPECTED_PROGRESS:"expected-progress",REAL_COST:"real-cost",CRITICAL_PATH:"critical-path"};function ll(e,t,r){let i=new Set;t.ran&&i.add(Tt.AUTOSCHEDULE),i.add(Tt.PARENT_BOUNDS),um(e)&&i.add(Tt.PARENT_PROGRESS),Jo(e)&&i.add(Tt.REAL_WORK);let n=!r.skipAutoSchedule;return n&&cl(e)&&i.add(Tt.EXPECTED_PROGRESS),n&&dm(e)&&i.add(Tt.REAL_COST),n&&We(e)&&!r.skipCriticalPath&&i.add(Tt.CRITICAL_PATH),i}var Et={INSERT:"insert",REMOVE:"remove",LINK_ADD:"link-add",LINK_REMOVE:"link-remove",LINK_FIELD:"link-field"},tn=class{_journal=null;begin(){this._journal={dirty:new Set,before:new Map,ops:[],linkFieldCaptured:new Set,correlativeBefore:new Map,scheduledBefore:new Map,progressFallbackBefore:new Map}}peek(){return this._journal}end(){this._journal=null}note(t,r){let i=this._journal;i&&(i.before.has(t)||i.before.set(t,ae(r)),i.dirty.add(t))}noteInsert(t){this._journal?.ops.push({kind:Et.INSERT,activityId:t})}noteRemove(t,r){this._journal?.ops.push({kind:Et.REMOVE,activityId:t,before:ae(r)})}noteLinkAdd(t){this._journal?.ops.push({kind:Et.LINK_ADD,linkId:t})}noteLinkRemove(t,r){this._journal?.ops.push({kind:Et.LINK_REMOVE,linkId:t,before:dl(r)})}noteCorrelativeBefore(t,r){let i=this._journal;if(!i||i.correlativeBefore.has(t))return;let n=i.before.get(t)?.correlativeId;i.correlativeBefore.set(t,typeof n=="number"?n:r)}noteScheduledBefore(t,r){let i=this._journal;if(!i)return;let n=ae(r);i.scheduledBefore.has(t)||i.scheduledBefore.set(t,n),i.before.has(t)||i.before.set(t,n),i.dirty.add(t)}noteLinkField(t,r){let i=this._journal;!i||i.linkFieldCaptured.has(t)||(i.linkFieldCaptured.add(t),i.ops.push({kind:Et.LINK_FIELD,linkId:t,before:dl(r)}))}noteProgressFallback(t,r){let i=this._journal;!i||i.progressFallbackBefore.has(t)||i.progressFallbackBefore.set(t,r)}};function dl(e){return{...e}}var Dt={ROOTS:"roots"};async function Z(e,t){let r=pm(e.adapter),i=fm(t,r);i.has(Tt.AUTOSCHEDULE)&&await Am(e.adapter,t);let n=i.has(Tt.AUTOSCHEDULE)?await mm(e,t.autoscheduleFrom,t.preventSummaryTargetPullback):gm();return await vm(e.adapter,t,n.scheduledIds,i,r),await Sm(e,i,t.now),n}function fm(e,t){let r=e.autoscheduleFrom!==null,i=!e.options.skipAutoSchedule&&r,n=new Set(ll(e.action,{requested:r,ran:i},e.options));return(e.recomputeParentProgress||t.affectedParents.size>0)&&n.add(Tt.PARENT_PROGRESS),n}function pm(e){let t=new Set,r=new Set,i=e.peekWriteCapture();if(!i)return{affectedParents:t,dirtySeeds:r};let n=o=>{if(o===null||M(o))return;let a=String(o);t.add(a);let s=e.getChildren(a)[0];s!==void 0&&r.add(s)};return ym(e,i.ops,n),hm(e,i.before,r,n),{affectedParents:t,dirtySeeds:r}}function ym(e,t,r){for(let i of t)if(i.kind===Et.INSERT){let n=e.getActivity(i.activityId);n&&r(n.parentId)}else i.kind===Et.REMOVE&&r(i.before.parentId)}function hm(e,t,r,i){for(let[n,o]of t){let a=e.getActivity(n);if(!a)continue;let s=!Object.is(o.progress,a.progress),c=!Object.is(o.ponderator,a.ponderator),l=!Object.is(o.parentId,a.parentId);(s||c)&&(i(a.parentId),r.add(String(n))),l&&(i(o.parentId),i(a.parentId),r.add(String(n)))}}async function mm(e,t,r=!1){let i=t===Dt.ROOTS?{}:{triggerId:t};r&&(i.preventSummaryTargetPullback=!0);let n=await e.scheduler.schedule(i),o=Im(e.adapter,n.updatedIds);return Fr(e.adapter,n),o}function Im(e,t){let r=[];for(let i of t){let n=String(i);r.push(n);let o=e.getActivity(n);o&&e.noteScheduledBefore(n,o)}return{scheduledIds:r}}function gm(){return{scheduledIds:[]}}async function Am(e,t){let r=t.collectDirty?t.collectDirty([]):vo(t.recomputeParentsFrom,[]);r.size!==0&&await ir(e,r,!1)}async function vm(e,t,r,i,n){i.has(Tt.PARENT_PROGRESS)&&Cm(e,n.affectedParents);let o=t.collectDirty?t.collectDirty(r):vo(t.recomputeParentsFrom,r);for(let a of n.dirtySeeds)o.add(a);await ir(e,o,i.has(Tt.PARENT_PROGRESS),{recomputeRealWork:i.has(Tt.REAL_WORK),progressMode:"freeze-when-no-contribution"})}function Cm(e,t){for(let r of t){if(e.hasChildren(r))continue;let i=e.getProgressFallback(r);i!==null&&(e.setActivityField(r,"progress",i),e.setProgressFallback(r,null))}}async function Sm(e,t,r){t.has(Tt.EXPECTED_PROGRESS)&&r!==null&&(Tm(e.adapter)&&ur(e.adapter,r,e.defaultBaseCalendarId??null),Me(e.adapter,r),ce(e.adapter,e.sector.statusCriteria)),t.has(Tt.REAL_COST)&&fr(e.adapter),t.has(Tt.CRITICAL_PATH)&&await il(e.adapter,e.sector.hoursPerDay)}function Tm(e){let t=!1;return e.forEachActivity(r=>{Rt(r)&&(t=!0)}),t}var Em=new Set([_.CONSTRAINT_TYPE,_.CONSTRAINT_DATE]),Dm=new Set([A.MSO,A.MFO]);function en(e){return Em.has(e)}function rn(e){return e===_.CONSTRAINT_DATE}function nn(e,t,r,i){let n=r.getActivity(e);if(!n)return!1;let o=n.constraintType;if(!o||ve.has(o)||Dm.has(o))return!1;let a=Xo(n.startDate),s=Xo(r.getLastStartDate(e));if(!s||!a||a.getTime()!==s.getTime())return!1;let c=_m(t,o,String(n.calendarId??""),i),l=Xo(n.constraintDate);return km(l,c)?!1:(r.setActivityField(e,"constraintDate",c),!0)}function _m(e,t,r,i){if(e===null)return null;let n=i.getCalendar(r);return n?ne(e,n,t):e}function Xo(e){if(e instanceof Date)return e;if(typeof e=="string"||typeof e=="number"){let t=new Date(e);return Number.isNaN(t.getTime())?null:t}return null}function km(e,t){return e===null&&t===null?!0:e===null||t===null?!1:e.getTime()===t.getTime()}async function on(e,{postMutationArgs:t,revertTargets:r,revert:i}){let{scheduledIds:n}=await Z(e,ul(t)),o=!1;for(let{activityId:a,priorConstraintDate:s}of r){let c=i(a,s);o=o||c}if(o){let a=await Z(e,ul(t));n=Pm(n,a.scheduledIds)}return We(t.action)&&await Z(e,Rm(t)),{scheduledIds:n}}function ul(e){return{...e,options:{...e.options,skipCriticalPath:!0}}}function Rm(e){return{action:e.action,autoscheduleFrom:null,recomputeParentsFrom:[],now:null,options:e.options}}function Pm(e,t){let r=new Set(e);for(let i of t)r.add(i);return[...r]}function Zo(e,t,r){let i=[];for(let n of r){let o=e.get(n);if(!o)continue;let a=o.pendingRequestIds??[];if(Je({pendingRequestIds:a})&&t.getActivity(n)==null)for(let s of a)i.push({kind:Vi.SIR_AUTO_REJECT,activityId:n,sirId:s,reason:Ki.ACTIVITY_DELETED})}return i}function bt(e){let t={id:String(e.id),source:String(e.source),target:String(e.target),type:e.type,lag:Number(e.lag),freeSlackHours:typeof e.freeSlackHours=="number"&&Number.isFinite(e.freeSlackHours)?e.freeSlackHours:null,isCritical:e.isCritical===!0};return e.proplannerId!=null&&(t.proplannerId=Number(e.proplannerId)),e.ganttId!=null&&(t.ganttId=Number(e.ganttId)),e.sectorId!=null&&(t.sectorId=Number(e.sectorId)),t}var Ft={BEFORE_DIFF:"before-diff",AFTER_DIFF:"after-diff"};async function z(e,t){let r=bm(e,t),i=new Map(t.beforeSnap),n=e.peekWriteCapture();if(n){let f=wm(n);Fm(e,n,f,i,r)}let o=t.sirDetection,a=o===Ft.BEFORE_DIFF?Zo(i,e,r):[],s=Nm(t.correlativeShifts,r),c=await Gi(e,i,r,s),l=o===Ft.AFTER_DIFF?Zo(i,e,r):a,d=t.warnings??[],u=Om(t.links??[],n?Lm(e,n):[]);return{source:t.source,activities:c,links:u,calendars:[],trackingEvents:t.trackingEvents??[],...l.length>0?{effects:l}:{},...d.length>0?{warnings:d}:{}}}function Lm(e,t){let r=[];for(let i of t.ops){if(i.kind!==Et.LINK_FIELD)continue;let n=e.getLink(i.linkId);if(!n)continue;let o={};for(let a of["freeSlackHours","isCritical"])Object.is(i.before[a],n[a])||(o[a]={before:i.before[a],after:n[a]});Object.keys(o).length!==0&&r.push({id:i.linkId,kind:N.UPDATED,fields:o,after:bt(n)})}return r}function Om(e,t){let r=[],i=new Map;for(let n of e){let o=i.get(n.id);if(o===void 0){i.set(n.id,r.length),r.push(n);continue}let a=r[o];if((a.kind===N.UPDATED||a.kind===N.CREATED)&&n.kind===N.UPDATED){r[o]={...a,fields:{...a.fields,...n.fields},after:n.after};continue}r[o]=n}for(let n of t){let o=i.get(n.id);if(o===void 0){i.set(n.id,r.length),r.push(n);continue}let a=r[o];if(a.kind===N.DELETED)continue;let s=a.kind===N.CREATED?Object.fromEntries(Object.entries(n.fields??{}).map(([c,l])=>[c,{before:void 0,after:l.after}])):n.fields;r[o]={...a,fields:{...a.fields,...s},after:n.after}}return r}function Nm(e,t){if(!e||e.length===0)return;let r=new Map;for(let i of e)r.set(i.activityId,i.before),t.add(i.activityId);return r}function bm(e,t){let r=new Set;for(let i of t.touchedIds)r.add(i);for(let i of t.scheduledIds)r.add(i);if(t.includeAllIds)for(let i of e.getAllIds())r.add(i);return r}function Fm(e,t,r,i,n){for(let o of t.dirty){if(r.has(o)||i.has(o))continue;let a=t.before.get(o),s=e.getActivity(o);!a||!s||Object.keys(Ao(a,s)).length!==0&&(i.set(o,a),n.add(o))}}function wm(e){return new Set(e.ops.filter(t=>t.kind===Et.INSERT).map(t=>t.activityId))}function pr(e,t,r){let i=[];for(let{op:n,finalLinkId:o,rejected:a}of e){if(a!==null)continue;if(n.kind===dt.CREATE){if(!o)continue;let d=r.getLink(o);if(!d)continue;let u=t.get(o);if(u){let f={};String(u.source)!==String(d.source)&&(f.source={before:String(u.source),after:String(d.source)}),String(u.target)!==String(d.target)&&(f.target={before:String(u.target),after:String(d.target)}),u.type!==d.type&&(f.type={before:u.type,after:d.type}),Number(u.lag)!==Number(d.lag)&&(f.lag={before:Number(u.lag),after:Number(d.lag)}),Object.keys(f).length>0&&i.push({id:String(o),kind:N.UPDATED,fields:f,after:bt(d)});continue}i.push({id:String(o),kind:N.CREATED,fields:{source:{before:void 0,after:String(d.source)},target:{before:void 0,after:String(d.target)},type:{before:void 0,after:d.type},lag:{before:void 0,after:Number(d.lag)}},after:bt(d)});continue}if(n.kind===dt.DELETE){if(r.getLink(n.linkId))continue;let d=t.get(n.linkId);i.push({id:String(n.linkId),kind:N.DELETED,fields:d?{source:{before:String(d.source),after:void 0},target:{before:String(d.target),after:void 0},type:{before:d.type,after:void 0},lag:{before:Number(d.lag),after:void 0}}:void 0,after:null});continue}let s=t.get(n.linkId),c=r.getLink(n.linkId);if(!c)continue;let l={};s&&s.type!==c.type&&(l.type={before:s.type,after:c.type}),s&&Number(s.lag)!==Number(c.lag)&&(l.lag={before:Number(s.lag),after:Number(c.lag)}),i.push({id:String(n.linkId),kind:N.UPDATED,fields:l,after:bt(c)})}return i}function yr(e,t){let r=new Map;if(!e.getActivity(t))return r;for(let i of e.getIncomingLinkIds(t)){let n=e.getLink(i);n&&r.set(String(n.id),Number(n.lag))}return r}function hr(e,t,r){let i=[];if(!t.getActivity(r))return i;for(let n of t.getIncomingLinkIds(r)){let o=t.getLink(n);if(!o)continue;let a=e.get(String(o.id));a===void 0||a===Number(o.lag)||i.push({id:String(o.id),kind:N.UPDATED,fields:{lag:{before:a,after:Number(o.lag)}},after:bt(o)})}return i}function an(e,t){typeof e=="string"&&e.length>0&&t.releaseCustomId(e)}async function fl(e,t,r){let{adapter:i,ctx:n,scheduler:o,sector:a}=r,s=Se(e.column);if(!s)return{ok:!1,reason:S.NO_PIPELINE_FOR_COLUMN};e.column===_.DURATION&&o.invalidateExpandedLinksCache();let c=n.activityReader.getActivity(e.activityId);if(!c)return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let l=s.canEdit(c,n.hierarchy);if(!l.allowed)return{ok:!1,reason:l.reason??S.CANNOT_EDIT,alertKey:l.alertKey};let d=s.parseInput(e.newValue,c,n);if(!d.ok)return{ok:!1,reason:d.reason??S.PARSE_ERROR};let u=Reflect.get(c,s.targetField),f=s.validate(c,u,d.value,n);if(!f.valid)return{ok:!1,reason:f.reason??S.INVALID,alertKey:f.notification?.messageKey};if(e.column===_.CUSTOM_ID&&d.value!==null){let v=i.getActivity(e.activityId),P=v?v.customId:null,q=typeof P=="string"?P:null;if(r.customIdTracker.isCustomIdInUse(String(d.value),q))return{ok:!1,reason:S.CUSTOM_ID_DUPLICATE}}let p=s.transform(c,d.value,n,d.raw),y=Te(e.activityId,p),g=await rt(i,y),C=yr(i,String(e.activityId)),L=c.constraintDate;Ee(i,e.activityId,p),Ie(e.activityId,p.postProcessors??[],i,g.get(String(e.activityId))??null);let T=hr(C,i,String(e.activityId));if(e.column===_.CUSTOM_ID){let v=g.get(String(e.activityId)),P=v?v.customId:null,q=typeof P=="string"?P:null,$=typeof d.value=="string"?d.value:null;q!==$&&r.customIdTracker.trackCustomIdChange(q,$)}let E=()=>({action:e,autoscheduleFrom:p.needsAutoSchedule?String(e.activityId):null,recomputeParentsFrom:[],collectDirty:v=>$i(e.activityId,y,v),now:r.now,options:t}),I=en(e.column),{scheduledIds:b}=await(I?on({adapter:i,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{postMutationArgs:E(),revertTargets:rn(e.column)?[]:[{activityId:e.activityId,priorConstraintDate:L}],revert:(v,P)=>nn(v,P,i,n.calendars)}):Z({adapter:i,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},E())),B=(p.trackingEvents??[]).map(v=>({name:v.name,properties:v.properties??{}}));s.trackEvent&&!(e.column===_.PROGRESS&&Number(d.value)<=0)&&B.unshift({name:s.trackEvent,properties:{activity_name:c.name,activity_id:c.id,activity_index:c.correlativeId}});let k=cr(e.activityId,p.constraintWarning);return{ok:!0,changes:await z(i,{source:e,beforeSnap:g,touchedIds:y,scheduledIds:b,sirDetection:Ft.BEFORE_DIFF,links:T,trackingEvents:B,...k?{warnings:[k]}:{},hoursPerDay:a.hoursPerDay})}}function sn(e){return ai(e)}function cn(e,t){return Object.hasOwn(e,t)}function xm(e){if(e.kind===m.LINK_CREATE)return sn(e.type)?e.lag===void 0||Number.isFinite(e.lag)?null:S.INVALID_LINK_LAG:S.INVALID_LINK_TYPE;if(e.kind===m.LINK_UPDATE){if(cn(e,"type")&&!sn(e.type))return S.INVALID_LINK_TYPE;if(cn(e,"lag")&&!Number.isFinite(e.lag))return S.INVALID_LINK_LAG}return null}function Mm(e){return e.kind===at.CREATE?sn(e.type)?e.lag===void 0||Number.isFinite(e.lag)?null:S.INVALID_LINK_LAG:S.INVALID_LINK_TYPE:e.kind===at.UPDATE?cn(e,"type")&&!sn(e.type)?S.INVALID_LINK_TYPE:!cn(e,"lag")||Number.isFinite(e.lag)?null:S.INVALID_LINK_LAG:e.kind===at.DELETE?null:S.INVALID_VALUE}function Um(e){for(let t of e){let r=Mm(t);if(r!==null)return r}return null}function Bm(e,t){let r=new Set,i=new Map;for(let n of e){if(n.kind===at.CREATE){r.add(String(n.source)),r.add(String(n.target));continue}let o=t.getLink(n.linkId);o&&(r.add(String(o.source)),r.add(String(o.target)),i.set(n.linkId,{...o}))}return{activityIds:r,links:i}}function Hm(e,t,r,i){return e.map((n,o)=>{let a=n.kind===at.CREATE?i?.get(o):void 0,s=ye(n,{port:t,newLinkId:a?()=>a:r.next});return{op:n,finalLinkId:s.applied?s.linkId:null,rejected:s.applied?null:s.rejected??S.INVALID}})}function Wm(e){return new Map([...e].map(([t,r])=>[String(t),r]))}async function pl(e,t,r){let i=xm(e);return i!==null?{ok:!1,reason:i}:Qo([$m(e,r.sector.hoursPerDay)],e,t,r,e.kind===m.LINK_CREATE&&e.linkId?new Map([[0,e.linkId]]):void 0)}async function yl(e,t,r){let i=Um(e.operations);if(i!==null)return{ok:!1,reason:i};let{hoursPerDay:n}=r.sector,o=e.operations.map(s=>jm(s,n)),a=Vm(e.operations);return Qo(o,e,t,r,a)}function Vm(e){let t=new Map;return e.forEach((r,i)=>{r.kind===at.CREATE&&r.linkId&&t.set(i,r.linkId)}),t.size>0?t:void 0}function Km(e,t){if(e===void 0)return;let r=new Map,i=new Set,n=()=>{let o=t.linkIdGen.next();for(;t.adapter.getLink(o)!==null||t.isLinkIdReserved(String(o))||i.has(String(o));)o=t.linkIdGen.next();return o};for(let[o,a]of e){let s=t.adapter.getLink(a)!==null||t.isLinkIdReserved(String(a))||i.has(String(a)),c=s?n():a;s||t.linkIdGen.bump(a),i.add(String(c)),r.set(o,c)}return r}function jm(e,t){return e.kind===at.CREATE?{kind:at.CREATE,source:e.source,target:e.target,type:e.type,lag:Wt(e.lag??0,t)}:e.kind===at.UPDATE?{kind:at.UPDATE,linkId:e.linkId,type:e.type,lag:e.lag===void 0?void 0:Wt(e.lag,t)}:{kind:at.DELETE,linkId:e.linkId}}async function Qo(e,t,r,i,n){let{adapter:o,scheduler:a,sector:s,linkIdGen:c}=i;a.invalidateAllCaches();let{activityIds:l,links:d}=Bm(e,o),u=await rt(o,l),f=Hm(e,o,c,Km(n,i));if(e.length===1&&f[0]&&f[0].rejected!==null&&t.kind!==m.INLINE_EDIT)return{ok:!1,reason:f[0].rejected};let p=Ym(f,d,o),{scheduledIds:y}=await Z({adapter:o,scheduler:a,sector:i.sector,defaultBaseCalendarId:i.defaultBaseCalendarId},{action:t,autoscheduleFrom:p,recomputeParentsFrom:l,now:i.now,options:r}),g=pr(f,d,o);return{ok:!0,linkVerdicts:f.map((C,L)=>C.rejected===null?{operationIndex:L,kind:C.op.kind,ok:!0,linkId:String(C.finalLinkId)}:{operationIndex:L,kind:C.op.kind,ok:!1,reason:C.rejected}),__beforeLinks:Wm(d),changes:await z(o,{source:t,beforeSnap:u,touchedIds:l,scheduledIds:y,links:g,hoursPerDay:s.hoursPerDay})}}function Ym(e,t,r){for(let i of e){if(i.rejected!==null)continue;let n=Gm(i.op,t,r);if(n!==null)return r.hasChildren(n)?Dt.ROOTS:String(n)}return null}function Gm(e,t,r){return e.kind===at.CREATE?e.target:e.kind===at.DELETE?t.get(e.linkId)?.target??null:r.getLink(e.linkId)?.target??null}function $m(e,t){return e.kind===m.LINK_CREATE?{kind:at.CREATE,source:e.source,target:e.target,type:e.type,lag:Wt(e.lag??0,t)}:e.kind===m.LINK_UPDATE?{kind:at.UPDATE,linkId:e.linkId,type:e.type,lag:e.lag===void 0?void 0:Wt(e.lag,t)}:{kind:at.DELETE,linkId:e.linkId}}async function hl(e,t,r){let{adapter:i,sector:n}=r;if(typeof e.newValue!="string")return{ok:!1,reason:S.INVALID_VALUE};if(!i.getActivity(e.activityId))return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let a=e.column===_.CUSTOM_PREDECESSORS,{specs:s,errors:c}=_i(e.newValue,{daysPerWeek:n.hoursPerWeek/n.hoursPerDay});if(c.length>0)return{ok:!1,reason:S.INVALID_VALUE};let l=s.map(g=>({...g,lag:Wt(Li(g.lag),n.hoursPerDay)})),d=new Map;i.forEachActivity(g=>{g.correlativeId!=null&&d.set(String(g.correlativeId),g.id)});let u=g=>d.get(g)??null,f=a?i.getIncomingLinkIds(e.activityId):i.getOutgoingLinkIds(e.activityId),p=[];for(let g of f){let C=i.getLink(g);C&&p.push(C)}let y=a?Ri({targetActivityId:e.activityId,currentLinks:p,desiredSpecs:l,resolveActivityByCorrelative:u}):Pi({sourceActivityId:e.activityId,currentLinks:p,desiredSpecs:l,resolveActivityByCorrelative:u});return Qo(y.operations,e,t,r)}var Kt={ACTIVITY_CREATION:"schedule_activity_creation",ACTIVITY_DELETION:"schedule_activity_deletion",ACTIVITY_MOVE:"schedule_activity_move",ACTIVITY_INDENT:"schedule_activity_indent",ACTIVITY_OUTDENT:"schedule_activity_outdent"};function St(e){e.invalidateVisualOrderIds?.();let t=[];e.forEachActivity(o=>{M(o.parentId)&&t.push(o)}),t.sort(gl);let r=[];ml(r,t);let i=[],n=0;for(;r.length>0;){let o=r.pop();if(o.correlativeId!==n){let s=typeof o.correlativeId=="number"?o.correlativeId:void 0;i.push({activityId:String(o.id),before:s}),s!==void 0&&e.noteCorrelativeBefore?.(String(o.id),s),zm(o,n)}n+=1;let a=Or(String(o.id),e);a.sort(gl),ml(r,a)}return i}function ml(e,t){for(let r=t.length-1;r>=0;r-=1)e.push(t[r])}function Il(e){let t=e.correlativeId,r=typeof t=="number"?t:Number(t);return Number.isFinite(r)?r:Zn}var gl=(e,t)=>Il(e)-Il(t);function zm(e,t){e.correlativeId=t}function ta(e,t){if(!e||e==="0")return;let r=String(e);for(;r!==null;){let{workHours:i,realWorkHours:n}=Cl(r,t);t.setActivityField(r,x.WORK_HOURS,i),t.setActivityField(r,x.REAL_WORK_HOURS,n);let o=t.getActivity(r);if(!o)break;let a=o.parentId;if(!a||M(a))break;r=a}}function Al(e,t){let r=t.getActivity(e);if(!r)return;let i=r.parentId;!i||M(i)||ta(i,t)}function vl(e,t,r){for(let i of e){if(r.hasChildren(i))continue;let n=r.getActivity(i);n&&r.setActivityField(i,x.REAL_WORK_HOURS,Nt(Jr(n,x.WORK_HOURS),Jr(n,x.PROGRESS)))}for(let i of t)r.setActivityField(i,x.REAL_WORK_HOURS,Cl(i,r).realWorkHours)}function Cl(e,t){let r=0,i=0;for(let n of t.getChildren(e)){let o=t.getActivity(n);if(!o)continue;let a=Jr(o,x.WORK_HOURS);r+=a,i+=qm(n,o,a,t)}return{workHours:r,realWorkHours:i}}function Jr(e,t){let r=e[t];return typeof r=="number"&&Number.isFinite(r)?r:0}function qm(e,t,r,i){return i.hasChildren(e)?Jr(t,x.REAL_WORK_HOURS):Nt(r,Jr(t,x.PROGRESS))}function ea(e,t){if(!e||e==="0")return;let r=String(e);for(;r!==null;){let i=t.getChildren(r),n=0;for(let s of i){let c=t.getActivity(s);c&&(n+=Jm(c,x.USED_COST))}t.setActivityField(r,x.USED_COST,n);let o=t.getActivity(r);if(!o)break;let a=o.parentId;if(!a||M(a))break;r=a}}function Sl(e,t){let r=t.getActivity(e);if(!r)return;let i=r.parentId;!i||M(i)||ea(i,t)}function Jm(e,t){let r=e[t];return typeof r=="number"&&Number.isFinite(r)?r:0}function ra(e,t){if(!e||e==="0")return;let r=String(e);for(;r!==null;){let i=t.getChildren(r),n=0;for(let s of i){let c=t.getActivity(s);c&&(n+=Xm(c,x.COST))}t.setActivityField(r,x.COST,n);let o=t.getActivity(r);if(!o)break;let a=o.parentId;if(!a||M(a))break;r=a}}function Tl(e,t){let r=t.getActivity(e);if(!r)return;let i=r.parentId;!i||M(i)||ra(i,t)}function Xm(e,t){let r=e[t];return typeof r=="number"&&Number.isFinite(r)?r:0}var ln=Object.freeze({proplannerId:null,description:"",type:D.TASK,progress:0,constraintType:A.ASAP,constraintDate:null,autoScheduling:!0,assignedDefaultCalendar:!1,dateOrigin:null,cost:0,usedCost:0,realCost:0,workHours:0,realWorkHours:0,ponderator:0,hasCustomPonderator:!1,correlativeId:0,customId:null,subcontractId:null,isLookahead:!1,hasLookaheadTasks:!1,newActivityIds:[],hasNewActivities:!1,pendingRequestIds:[],responsableIds:[],tagIds:[],baselinePoints:[],baselineSnapshot:null,recursiveDurationHours:0,isCritical:!1,freeSlackHours:null,expectedProgress:null,expectedProgressBaseline:null,status:null,criticalPath:null}),El="New Master Plan",Dl="New Activity";var Zm=["name","description","type","startDate","durationHours","constraintType","constraintDate","calendarId","assignedDefaultCalendar","autoScheduling","progress","cost","usedCost","realCost","workHours","realWorkHours","ponderator","hasCustomPonderator","customId","subcontractId","responsableIds","tagIds","isLookahead"],dn=new Set(Zm);function Qm(e){let t=Object.getPrototypeOf(e);if(t!==null&&t!==Object.prototype)throw new Error("activity-create: override bag must be a plain object with no custom prototype");for(let r of Reflect.ownKeys(e))if(typeof r=="symbol"||!dn.has(r))throw new Error(`activity-create: rejected override key "${String(r)}" \u2014 not a creation-writable canonical field`);return e}function _l(e,t){let r=e.parentId!=null?t.getActivity(e.parentId):null,i=Qm(e.activityOverrides??{}),n=e.numTasksInGantt===0?El:Dl,o=i.name??n,a=i.durationHours??e.sector.hoursPerDay,s=i.calendarId??e.sector.defaultCalendar,c=tI(r,e.fallbackStartDate,i.startDate),l={...ln,...i,id:e.id,parentId:e.parentId,uniqueCorrelativeId:e.nextUniqueCorrelativeId,name:o,durationHours:a,calendarId:s,startDate:c,endDate:c},d=i.startDate?new Date(l.startDate):t.getClosestWorkTime({date:l.startDate,dir:K.FUTURE,task:l});if(!i.startDate&&r&&re(r.type)){let p=new Date(r.startDate);p.setUTCHours(0,0,0,0);let y=new Date(d);y.setUTCHours(0,0,0,0),y.getTime()!==p.getTime()&&(d=t.getClosestWorkTime({date:p,dir:K.FUTURE,task:l}))}let u=t.calculateEndDate({startDate:d,durationHours:l.durationHours,task:l});return{newTask:{...l,startDate:d,endDate:u,calendarDuration:Qt({type:l.type,startDate:d,endDate:u}),newActivityIds:[...l.newActivityIds],pendingRequestIds:[...l.pendingRequestIds],responsableIds:[...l.responsableIds],tagIds:[...l.tagIds],baselinePoints:[...l.baselinePoints]}}}function tI(e,t,r){return r?new Date(r):e?new Date(e.startDate):t?new Date(t):new Date}var mr={CREATE:"create",REPARENT:"reparent"};function eI(e){let t=e.type;if(t!==D.TASK&&t!==D.MILESTONE)return null;let r=e.startDate,i=e.endDate;return!(r instanceof Date)||!(i instanceof Date)?null:{type:t,startDate:new Date(r),endDate:new Date(i),durationHours:Number(e.durationHours??0),expectedProgressBaseline:typeof e.expectedProgressBaseline=="number"?e.expectedProgressBaseline:null,constraintType:e.constraintType??null,constraintDate:e.constraintDate instanceof Date?new Date(e.constraintDate):null,progress:Number(e.progress??0)}}function Ir(e){let t=e.getParent(e.parentId);if(!t)return null;let r=e.isCurrentlyLeaf!==void 0?e.isCurrentlyLeaf&&pe(t.type):rI(t),i=Array.isArray(t.newActivityIds)?t.newActivityIds:[],o={isLookahead:!1,hasNewActivities:!0,newActivityIds:i.some(a=>String(a)===String(e.newChildId))?[...i]:[...i,e.newChildId]};return t.customId!=null&&t.customId!==""&&(o.customId=null),r&&(o.type=no,(e.promotionSource??mr.CREATE)===mr.CREATE&&(o.constraintType=A.ASAP,o.constraintDate=null)),{parentId:e.parentId,fields:o,promotionSnapshot:eI(t)}}function rI(e){return pe(e.type)&&(!Array.isArray(e.newActivityIds)||e.newActivityIds.length===0)}function gr(e,t,r,i){let n=t,o=n==="0",a=ia(e,n);if(i!==void 0){let c=a.find(l=>l.id===i);if(c){let l=Pt(c),d=a.map(Pt).filter(f=>f<l);return d.length===0?l-1:(Math.max(...d)+l)/2}}if(r!==void 0){let c=a.find(l=>l.id===r);if(c){let l=Pt(c),d=a.map(Pt).filter(f=>f>l);if(d.length===0)return l+1;let u=Math.min(...d);return(l+u)/2}}return a.length===0?0:Math.max(...a.map(Pt))+1}var Ve=Number.MAX_SAFE_INTEGER,kl=Number.MAX_SAFE_INTEGER-1;function Pt(e){let t=e.correlativeId,r=typeof t=="number"?t:Number(t);return Number.isFinite(r)?r:Ve}function ia(e,t){return Or(t,e)}function Rl(e,t,r){let i=e,n=_e(e,r);for(;n!=null&&t.has(n);)i=n,n=_e(n,r);return i}function Ar(e,t,r){let i=new Set([e]),n=Gt(r.getActivity(e)?.parentId);for(;n!=="0"&&!i.has(n);){if(t.has(n))return!0;i.add(n),n=Gt(r.getActivity(n)?.parentId)}return!1}function _e(e,t){let r=t.getActivity(e);if(!r)return null;let i=Gt(r.parentId),n=Ht(i,t),o=n.findIndex(a=>String(a)===String(e));return o<=0?null:n[o-1]??null}function Pl(e,t,r,i){let n=Ht(t,e).filter(c=>String(c)!==String(i)).map(c=>e.getActivity(c)).filter(c=>c!==null);if(n.length===0)return 0;let o=n.map(Pt);if(r<=0)return o[0]-1;if(r>=o.length)return o[o.length-1]+1;let a=o[r-1],s=o[r];return(a+s)/2}var iI=new Set([...[...dn].filter(e=>e!==x.DURATION_HOURS),"durationDays"]);function un(e,t){if(e===void 0)return{ok:!0,value:{}};let r=Object.getPrototypeOf(e);if(r!==null&&r!==Object.prototype)return{ok:!1,reason:S.INVALID_VALUE};for(let o of Reflect.ownKeys(e))if(typeof o=="symbol"||!iI.has(o))return{ok:!1,reason:S.INVALID_VALUE};let{durationDays:i,...n}=e;return i!==void 0&&(!Number.isFinite(i)||i<0)?{ok:!1,reason:S.INVALID_VALUE}:{ok:!0,value:{...n,...i===0&&(n.type===void 0||n.type===D.TASK)?{type:D.MILESTONE}:{},...i===void 0?{}:{durationHours:be(i,t)}}}}async function Xr(e,t,r={}){let{adapter:i,scheduler:n,sector:o,calendars:a,activityIdGen:s,uidGen:c}=t;r.skipCacheInvalidation||n.invalidateAllCaches();let l=nI(e,i);if(!l.ok)return l;let{parent:d,anchorSiblingId:u,isRoot:f}=l,p=aI(e.activityId,i,s,t.isActivityIdReserved),y=c.next(),g={id:p,parentId:f?null:e.parentId,sector:{id:o.id,hoursPerDay:o.hoursPerDay,defaultCalendar:fI(a)},numTasksInGantt:i.activityCount(),nextUniqueCorrelativeId:y,activityOverrides:e.overrides??{}},L=_l(g,{getActivity:v=>i.getActivity(v),calculateEndDate:v=>i.calculateEndDate(v),getClosestWorkTime:v=>i.getClosestWorkTime(v)}).newTask;L.realWorkHours=Nt(L.workHours,L.progress),cI(L,e,t,u,d,r);let T=r.insertionCorrelativeId??gr(i,f?"0":e.parentId,e.afterSiblingId,e.beforeSiblingId);L.correlativeId=T;let E=new Set([p]);d&&E.add(d.id);let I=d!==null&&i.getChildren(d.id).length===0,b=I?d?.customId:null,B=r.skipBeforeSnap?new Map:await rt(i,E);i.addActivity(L),lI(e,p,d,i,I),b&&t.customIdTracker.releaseCustomId(b),r.skipRollupCascades||(Al(p,i),Sl(p,i),Tl(p,i));let k=dI(i,p,E,r);return{ok:!0,newId:p,parent:d,newActivity:L,beforeSnap:B,initialTouched:E,correlativeShifts:k}}function nI(e,t){let r=M(e.parentId),i=r?null:t.getActivity(e.parentId);if(!r&&!i)return{ok:!1,reason:S.PARENT_NOT_FOUND};if(i!==null&&Je(i))return{ok:!1,reason:S.PARENT_FROZEN_BY_SIR};if(e.afterSiblingId!==void 0&&e.beforeSiblingId!==void 0)return{ok:!1,reason:S.ANCHOR_SIBLING_CONFLICT};let a=e.afterSiblingId??e.beforeSiblingId,s=oI(e,t,r,a);return s||{ok:!0,parent:i,anchorSiblingId:a,isRoot:r}}function oI(e,t,r,i){if(i===void 0)return null;let n=t.getActivity(i);if(!n)return{ok:!1,reason:S.ANCHOR_SIBLING_NOT_FOUND};let o=r?"0":e.parentId;return(n.parentId==null?"0":String(n.parentId))!==o?{ok:!1,reason:S.ANCHOR_SIBLING_WRONG_PARENT}:null}function aI(e,t,r,i){let n=()=>{let o=r.next();for(;t.activityExists(o)||i(String(o));)o=r.next();return o};return e===void 0||t.activityExists(e)||i(String(e))?n():(r.bump(e),e)}function sI(e){let t=e.overrides?.customId;return typeof t=="string"?t:void 0}function cI(e,t,r,i,n,o){let{adapter:a,customIdTracker:s}=r,c=sI(t);if(c!==void 0){if(c.length===0)return;if(!s.isCustomIdInUse(c)){s.registerCustomId(c);return}}let l=o.customIdReferenceId??i,d=l!==void 0,u=d?a.getActivity(l):n;e.customId=s.generateCustomIdForNewChild({activity:u??{},useActivityCustomIdAsReference:d})}function lI(e,t,r,i,n){if(!r)return;let o=Ir({parentId:e.parentId,newChildId:t,isCurrentlyLeaf:n,getParent:a=>i.getActivity(a)??null});if(o){for(let[a,s]of Object.entries(o.fields))yt(i,o.parentId,a,s);o.promotionSnapshot&&i.setPromotionSnapshot(o.parentId,o.promotionSnapshot)}}function dI(e,t,r,i){if(i.skipCorrelativeRecompute)return[];let n=St(e).filter(o=>o.activityId!==String(t));for(let o of n)r.add(o.activityId);return n}async function uI(e,t,r,i,n){let{newId:o,newActivity:a,beforeSnap:s,initialTouched:c,correlativeShifts:l}=r,d={name:Kt.ACTIVITY_CREATION,properties:{parent_id:t.parentId,activity_id:o,created_duration:a.durationHours}};return t.eventSource!==void 0&&(d.properties.event_source=t.eventSource),z(e,{source:t,beforeSnap:s,touchedIds:c,scheduledIds:i,correlativeShifts:l,trackingEvents:[d],hoursPerDay:n})}async function Ll(e,t,r){let{adapter:i,scheduler:n,sector:o}=r,a=un(e.overrides,o.hoursPerDay);if(!a.ok)return a;let s=await Xr({...e,overrides:a.value},r);if(!s.ok)return s;let{newId:c}=s,l=s.newActivity.autoScheduling;i.setActivityField(c,"autoScheduling",!1);let d;try{d=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:c,recomputeParentsFrom:[c],preventSummaryTargetPullback:!0,now:r.now,options:t})}finally{i.setActivityField(c,"autoScheduling",l)}let{scheduledIds:u}=d;return{ok:!0,changes:await uI(i,e,s,u,o.hoursPerDay)}}function fI(e){for(let r of e.values())if(r.is_default)return r.id;let t=e.values().next();return!t.done&&t.value?t.value.id:"global"}function Ut(e,t){ta(e,t),ea(e,t),ra(e,t)}function fn(e,t){let r=new Set,i=[];for(let n of e){let o=String(n);r.has(o)||(r.add(o),i.push(o))}for(;i.length>0;){let n=i.pop(),o=t.getChildren(n);for(let a of o){let s=String(a);r.has(s)||(r.add(s),i.push(s))}}return r}function pn(e,t){let r=new Set;for(let i of e){for(let n of t.getOutgoingLinkIds(i))r.add(String(n));for(let n of t.getIncomingLinkIds(i))r.add(String(n))}return[...r]}function pI(e){return e?{type:e.type,startDate:new Date(e.startDate),endDate:new Date(e.endDate),durationHours:e.durationHours,expectedProgressBaseline:e.expectedProgressBaseline,constraintType:e.constraintType,constraintDate:e.constraintDate?new Date(e.constraintDate):null,progress:e.progress}:null}function yI(e,t,r){let i=e.startDate;return!r||!(i instanceof Date)?{}:{endDate:r(i,t)}}function vr(e){if(e.remainingChildIds.length>0)return null;let t=e.parent,r=e.defaultDurationHours,i=Number.isFinite(r),n=pI(e.promotionSnapshot)??(i?{type:tr,durationHours:r,progress:0,autoScheduling:!0,constraintType:A.ASAP,constraintDate:null,hasNewActivities:!1,...yI(t,r,e.computeEndDate)}:{type:tr});if(e.idsRemoved&&e.idsRemoved.size>0){let o=Array.isArray(t.newActivityIds)?t.newActivityIds:[];if(o.length>0){let a=o.filter(s=>!e.idsRemoved.has(s)&&!e.idsRemoved.has(String(s)));a.length!==o.length&&(n.newActivityIds=a)}}return t.hasLookaheadTasks&&(n.isLookahead=!0),{parentId:String(t.id),fields:n}}function yn(e){if(e.idsRemoved.size===0)return null;let t=e.parent.newActivityIds;if(!Array.isArray(t)||t.length===0)return null;let r=t,i=r.filter(n=>!e.idsRemoved.has(n)&&!e.idsRemoved.has(String(n)));return i.length===r.length?null:{parentId:String(e.parent.id),fields:{newActivityIds:[...i],hasNewActivities:i.length>0}}}var Ol=200;async function Nl(e,t,r){let{adapter:i,scheduler:n,customIdTracker:o,sector:a}=r;if(n.invalidateAllCaches(),e.activityIds.length===0)return{ok:!1,reason:S.ACTIVITY_IDS_EMPTY};for(let v of e.activityIds)if(!i.getActivity(v))return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let s=e.activityIds.filter(v=>{let P=i.getActivity(v);return!(P?.correlativeId===0&&P.type===D.PROJECT)}),c=fn(s,i),l=pn(c,i),d=new Set;for(let v of e.activityIds){let P=i.getActivity(v);if(!P)continue;let q=P.parentId;if(M(q))continue;let $=String(q);c.has($)||d.add($)}let u=new Set([...c,...d]),f=await rt(i,u),p=new Map;for(let v of l){let P=i.getLink(v);P&&p.set(v,{...P})}let y=new Set,g=0;for(let v of c){g+=1,g%Ol===0&&await st();let P=i.getActivity(v);if(!P)continue;let q=M(P.parentId)?null:i.getActivity(String(P.parentId)),$=q?.hasNewActivities===!0&&q.newActivityIds.some(it=>String(it)===String(v));(P.isNewActivity===!0||$)&&y.add(v);let ot=P.customId;typeof ot=="string"&&ot.length>0&&o.releaseCustomId(ot)}for(let v of l)i.removeLink(v);let C=Zr(i,c),L=0;for(let v of c)L+=1,L%Ol===0&&await st(),i.removeActivity(v);for(let v of d){let P=i.getActivity(v);if(!P)continue;hI(P,y,i);let q=i.getChildren(v),$=vr({parent:P,remainingChildIds:q.map(String),defaultDurationHours:a.hoursPerDay,promotionSnapshot:i.getPromotionSnapshot(v),computeEndDate:(ot,it)=>i.calculateEndDate({startDate:ot,durationHours:it,task:P}),idsRemoved:c});if(!$){Ni(v,i);continue}for(let[ot,it]of Object.entries($.fields))yt(i,v,ot,it);if(P.customId==null||P.customId===""){let ot=_e(v,i),it=ot?i.getActivity(ot)?.customId:null,_t=o.generateCustomIdForRestoredChild(typeof it=="string"&&it?it:null);i.setActivityField(v,x.CUSTOM_ID,_t)}}for(let v of d)Ut(v,i);let T=St(i),{scheduledIds:E}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:Dt.ROOTS,recomputeParentsFrom:d,now:r.now,options:t}),I={name:Kt.ACTIVITY_DELETION,properties:{activity_ids:[...e.activityIds],cascade_count:c.size}};e.eventSource!==void 0&&(I.properties.event_source=e.eventSource);let b=new Map;for(let[v,P]of p)b.set(v,P);let B=new Map;for(let v of c){let P=f.get(String(v));P&&B.set(String(v),P)}let k=await z(i,{source:e,beforeSnap:f,touchedIds:u,scheduledIds:E,sirDetection:Ft.AFTER_DIFF,links:oa(p),trackingEvents:[I],hoursPerDay:a.hoursPerDay,correlativeShifts:T});return{ok:!0,changes:C.length>0?{...k,viewState:C}:k,__beforeSnap:B,__beforeLinks:b}}function hI(e,t,r){let i=yn({parent:e,idsRemoved:t});if(i)for(let[n,o]of Object.entries(i.fields))yt(r,i.parentId,n,o)}function Zr(e,t){let r=[];for(let i of t){let n=e.isChecked(i),o=e.isVisible(i);!n&&o||r.push({activityId:String(i),...n?{checked:{before:!0,after:!1}}:{},...o?{}:{visible:{before:!1,after:!0}}})}return r}function oa(e){let t=[];for(let[r,i]of e.entries())t.push({id:r,kind:N.DELETED,fields:{source:{before:String(i.source),after:void 0},target:{before:String(i.target),after:void 0},type:{before:i.type,after:void 0},lag:{before:Number(i.lag),after:void 0}},after:null});return t}async function wl(e,t,r){let i=mI(e,r);if(i)return{ok:!1,reason:i};let n=gI(e,r);if(!n.ok)return n;let o=e.mode===pt.REPLACE?new Set(r.adapter.getAllIds().map(I=>String(I))):new Set,a=e.mode===pt.REPLACE?await rt(r.adapter,o):new Map,s=e.mode===pt.REPLACE?EI(r):new Map,c=e.mode===pt.REPLACE?Zr(r.adapter,o):[];r.scheduler.invalidateAllCaches();let l=[];if(e.mode===pt.REPLACE){for(let I of s.keys()){let b=ye({kind:at.DELETE,linkId:I},{port:r.adapter});if(!b.applied)return{ok:!1,reason:b.rejected??S.INVALID};l.push({op:{kind:at.DELETE,linkId:I},finalLinkId:I,rejected:null})}for(let I of o){let b=r.adapter.getActivity(I)?.customId;typeof b=="string"&&b.length>0&&r.customIdTracker.releaseCustomId(b),r.adapter.removeActivity(I)}}let d=await TI(e,n.plan.items,r);if(!d.ok)return d;let u=xl(e)?[]:St(r.adapter),f=new Set(n.plan.items.map(I=>String(I.activityId))),p=u.filter(I=>!f.has(I.activityId)),y=e.mode===pt.REPLACE?new Set(o):new Set;lr(r.adapter,u,f,a,y);for(let I of n.plan.items)y.add(String(I.activityId));let g=n.plan.links.map(I=>({operation:{kind:at.CREATE,source:I.source,target:I.target,type:I.type,lag:Wt(I.lag??0,r.sector.hoursPerDay)},linkId:I.linkId})),C=Ti(g,{port:r.adapter,preserved:s});if(!C.applied)return{ok:!1,reason:C.rejected??S.INVALID};for(let{operation:I,linkId:b}of g)l.push({op:I,finalLinkId:b,rejected:null});let L=n.plan.items.map(I=>I.activityId),{scheduledIds:T}=await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:e.items.length>0||e.links.length>0?Dt.ROOTS:null,recomputeParentsFrom:L,now:r.now,options:t}),E=await z(r.adapter,{source:e,beforeSnap:a,touchedIds:y,scheduledIds:T,links:pr(l,s,r.adapter),hoursPerDay:r.sector.hoursPerDay,correlativeShifts:p,...e.mode===pt.REPLACE?{sirDetection:Ft.AFTER_DIFF}:{}});return{ok:!0,changes:c.length>0?{...E,viewState:c}:E,...e.mode===pt.REPLACE?{__beforeSnap:a,__beforeLinks:DI(s)}:{}}}function mI(e,t){if(e.mode!==pt.APPEND&&e.mode!==pt.REPLACE)return S.INVALID;let r=new Set,i=new Set;for(let o of e.items){if(o.batchId.length===0||r.has(o.batchId))return S.INVALID;if(r.add(o.batchId),o.index!==void 0&&(!Number.isInteger(o.index)||o.index<0))return S.INVALID;if(o.activityId!==void 0){let a=String(o.activityId);if(a.length===0||a==="0"||i.has(a))return S.INVALID;i.add(a)}}for(let o of e.items)if(!aa(o.parent,!0,e.mode,r,t))return S.PARENT_NOT_FOUND;if(II(e.items))return S.INVALID;let n=new Set;for(let o of e.links){if(!Object.values(H).includes(o.type))return S.INVALID_LINK_TYPE;if(o.lag!==void 0&&!Number.isFinite(o.lag))return S.INVALID_LINK_LAG;if(!aa(o.source,!1,e.mode,r,t)||!aa(o.target,!1,e.mode,r,t))return S.ACTIVITY_NOT_FOUND;if(o.linkId!==void 0){let a=String(o.linkId);if(a.length===0||n.has(a))return S.INVALID;n.add(a)}}return null}function aa(e,t,r,i,n){return typeof e=="string"?e==="0"?t:r===pt.APPEND&&n.adapter.getActivity(String(e))!==null:e!==null&&e.batchId.length>0&&i.has(e.batchId)}function II(e){let t=new Map;for(let i of e)typeof i.parent!="string"&&t.set(i.batchId,i.parent.batchId);let r=new Set;for(let i of e){let n=new Set,o=i.batchId;for(;o!==void 0&&!r.has(o);){if(n.has(o))return!0;n.add(o),o=t.get(o)}for(let a of n)r.add(a)}return!1}function gI(e,t){let r=new Map;for(let d of e.items){let u=un(d.overrides,t.sector.hoursPerDay);if(!u.ok)return u;r.set(d.batchId,u.value)}let i=new Map,n=new Set;for(let d of e.items){let u=AI(d.activityId,e.mode,n,t);n.add(String(u)),i.set(d.batchId,u)}let o=new Set,a=e.links.map(d=>{let u=vI(d.linkId,e.mode,o,t);return o.add(String(u)),u}),s=CI(e,i,t),c=[];for(let d of e.items){let u=i.get(d.batchId),f=s.get(d.batchId);if(u===void 0||f===void 0)return{ok:!1,reason:S.INVALID};let p=typeof d.parent=="string"?null:d.parent.batchId,y=typeof d.parent=="string"?d.parent:i.get(d.parent.batchId);if(y===void 0)return{ok:!1,reason:S.PARENT_NOT_FOUND};c.push({input:d,activityId:u,parentId:y,parentBatchId:p,insertionCorrelativeId:f,overrides:r.get(d.batchId)??{}})}let l=[];for(let[d,u]of e.links.entries()){let f=Fl(u.source,i),p=Fl(u.target,i),y=a[d];if(f===null||p===null||y===void 0)return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};l.push({source:f,target:p,type:u.type,lag:u.lag??0,linkId:y})}return{ok:!0,plan:{items:c,links:l}}}function AI(e,t,r,i){if(e!==void 0&&(t===pt.REPLACE||i.adapter.getActivity(e)===null&&!i.isActivityIdReserved(String(e)))&&!r.has(String(e)))return i.activityIdGen.bump(e),e;let o=i.activityIdGen.next();for(;r.has(String(o))||t===pt.APPEND&&(i.adapter.getActivity(o)!==null||i.isActivityIdReserved(String(o)));)o=i.activityIdGen.next();return o}function vI(e,t,r,i){if(e!==void 0&&(t===pt.REPLACE||i.adapter.getLink(e)===null&&!i.isLinkIdReserved(String(e)))&&!r.has(String(e)))return i.linkIdGen.bump(e),e;let o=i.linkIdGen.next();for(;r.has(String(o))||t===pt.APPEND&&(i.adapter.getLink(o)!==null||i.isLinkIdReserved(String(o)));)o=i.linkIdGen.next();return o}function CI(e,t,r){if(xl(e)){let s=r.adapter.activityCount();return new Map(e.items.map((c,l)=>[c.batchId,s+l]))}let i=new Set(Array.from(t.values(),s=>String(s))),n=new Map;for(let s of e.items){let c=t.get(s.batchId);if(c===void 0)continue;let l=typeof s.parent=="string"?s.parent:t.get(s.parent.batchId);if(l===void 0)continue;let d=String(l),u=n.get(d);u||(u={existing:e.mode===pt.REPLACE||typeof s.parent!="string"&&t.has(s.parent.batchId)?[]:ia(r.adapter,d).sort((g,C)=>Pt(g)-Pt(C)||String(g.id).localeCompare(String(C.id))).map(g=>String(g.id)),newIdsByTarget:new Map},n.set(d,u));let f=s.index===void 0?u.existing.length:Math.min(s.index,u.existing.length),p=u.newIdsByTarget.get(f)??[];p.push(String(c)),u.newIdsByTarget.set(f,p)}let o=new Map,a=new Map(Array.from(t,([s,c])=>[String(c),s]));for(let s of n.values()){let c=[];for(let d=0;d<=s.existing.length;d+=1){for(let f of s.newIdsByTarget.get(d)??[])c.push(f);let u=s.existing[d];u!==void 0&&c.push(u)}let l=0;for(;l<c.length;){if(!i.has(c[l])){l+=1;continue}let d=l;for(;l<c.length&&i.has(c[l]);)l+=1;let u=l-d,f=d>0?bl(c[d-1],r):null,p=l<c.length?bl(c[l],r):null;for(let y=0;y<u;y+=1){let g=c[d+y],C=a.get(g);C!==void 0&&o.set(C,SI(f,p,y+1,u))}}}return o}function xl(e){return e.mode===pt.APPEND&&e.items.every(t=>t.parent==="0"&&t.index===void 0)}function bl(e,t){let r=t.adapter.getActivity(e);return r?Pt(r):0}function SI(e,t,r,i){return e!==null&&t!==null&&t>e?e+(t-e)*r/(i+1):e!==null?e+r:t!==null?t-(i-r+1):r-1}async function TI(e,t,r){let i=new Map,n=[];for(let a of t){if(a.parentBatchId===null){n.push(a);continue}let s=i.get(a.parentBatchId)??[];s.push(a),i.set(a.parentBatchId,s)}for(let a=0;a<n.length;a+=1){let s=n[a],c=await Xr({kind:m.ACTIVITY_CREATE,parentId:s.parentId,activityId:s.activityId,overrides:s.overrides,...e.eventSource===void 0?{}:{eventSource:e.eventSource}},r,{skipCorrelativeRecompute:!0,skipBeforeSnap:!0,skipCacheInvalidation:!0,skipRollupCascades:!0,insertionCorrelativeId:s.insertionCorrelativeId});if(!c.ok)return c;for(let l of i.get(s.input.batchId)??[])n.push(l)}if(n.length!==t.length)return{ok:!1,reason:S.INVALID};let o=new Set;for(let a=n.length-1;a>=0;a-=1){let s=n[a].parentId;s==="0"||o.has(String(s))||(o.add(String(s)),Ut(s,r.adapter))}return{ok:!0}}function Fl(e,t){return typeof e=="string"?e:t.get(e.batchId)??null}function EI(e){return new Map(e.adapter.getAllLinks().map(t=>[String(t.id),{...t}]))}function DI(e){return new Map(Array.from(e,([t,r])=>[String(t),r]))}function Ml(e,t){let{adapter:r}=t,i=e.activityId,n=r.getActivity(i);if(!n)return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let o=n.pendingRequestIds??[],a=e.pendingRequests.map(l=>l.id);r.setActivityField(e.activityId,"pendingRequestIds",a);let s=r.getActivity(i);if(!s)return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let c={id:i,kind:N.UPDATED,fields:{pendingRequestIds:{before:o,after:a}},after:et(s)};return{ok:!0,changes:{source:e,activities:[c],links:[],calendars:[],trackingEvents:[]}}}function Ul(e){let t=new Map;for(let r of e){let i=r.proplannerId;typeof i=="number"&&Number.isSafeInteger(i)&&i>0&&t.set(i,String(r.id))}return t}function Bl(e,t,r){let i=new Set(t.map(({id:n})=>String(n)));for(let n of e)if((n.proplannerId==null||n.proplannerId===0)&&!i.has(String(n.id)))throw new Error(`persistence-acknowledge: missing ${r} proplannerId for "${String(n.id)}"`)}function _I(e,t,r,i,n,o){let a=String(e.id);if(a.length===0||n.has(a))throw new Error(`persistence-acknowledge: duplicate or empty ${t} id "${a}"`);if(!Number.isSafeInteger(e.proplannerId)||e.proplannerId<=0)throw new Error(`persistence-acknowledge: invalid ${t} proplannerId ${String(e.proplannerId)}`);if(o.has(e.proplannerId))throw new Error(`persistence-acknowledge: duplicate ${t} proplannerId ${String(e.proplannerId)}`);let s=r(a);if(!s.exists)throw new Error(`persistence-acknowledge: unknown ${t} id "${a}"`);if(s.current!==null&&s.current!==0&&s.current!==e.proplannerId)throw new Error(`persistence-acknowledge: ${t} "${a}" already has proplannerId ${String(s.current)}`);let c=i.get(e.proplannerId);if(c!==void 0&&c!==a)throw new Error(`persistence-acknowledge: ${t} proplannerId ${String(e.proplannerId)} already belongs to "${c}"`);n.add(a),o.add(e.proplannerId)}function Hl(e,t,r,i){let n=new Set,o=new Set;for(let a of e)_I(a,t,r,i,n,o)}async function Wl(e,t){let r=e.filter(s=>{let c=t.adapter.getActivity(String(s.activityId));return c!==null&&c.progress!==s.progress}),i=new Set(r.map(s=>String(s.activityId))),n=Hr(t.adapter,i),o=new Set(i);for(let s of n)o.add(String(s));let a=await rt(t.adapter,o);return t.adapter.batchUpdate(()=>{for(let s of r){let c=String(s.activityId);t.adapter.setActivityField(c,"progress",s.progress),t.adapter.setActivityField(c,"autoScheduling",Le(s.progress))}Gs(n,t.adapter),vl(i,n,t.adapter)}),[...await Gi(t.adapter,a,o)]}async function Vl(e,t){let r=e.activities??[],i=e.links??[],n=t.adapter.getAllActivities(),o=t.adapter.getAllLinks(),a=e.checkpoint?.activities??n,s=e.checkpoint?.links??o,c=new Map(a.map(y=>[String(y.id),y])),l=new Map(s.map(y=>[String(y.id),y])),d=Ul(a),u=Ul(s);Hl(r,"activity",y=>{let g=c.get(y);return{exists:g!==void 0,current:g?.proplannerId??null}},d),Hl(i,"link",y=>{let g=l.get(y);return{exists:g!==void 0,current:g?.proplannerId??null}},u),Bl(a,r,"activity"),Bl(s,i,"link");let f=[],p=[];return t.adapter.batchUpdate(()=>{for(let y of r){let g=t.adapter.getActivity(y.id);if(!g||g.proplannerId===y.proplannerId)continue;let C=g.proplannerId;t.adapter.setActivityField(y.id,"proplannerId",y.proplannerId),f.push({id:y.id,kind:N.UPDATED,fields:{proplannerId:{before:C,after:y.proplannerId}},after:{...g,proplannerId:y.proplannerId}})}for(let y of i){let g=t.adapter.getLink(y.id);if(!g||g.proplannerId===y.proplannerId)continue;let C=g.proplannerId;t.adapter.setLinkProplannerId(y.id,y.proplannerId),p.push({id:y.id,kind:N.UPDATED,fields:{proplannerId:{before:C,after:y.proplannerId}},after:{...g,proplannerId:y.proplannerId}})}}),{ok:!0,changes:{source:e,activities:f,links:p,calendars:[],trackingEvents:[]}}}async function Kl(e,t,r){if(kI(e))return{ok:!1,reason:S.INVALID_VALUE};let i=[...new Set(e.activityIds.map(String))];if(e.acknowledgePersistedLookahead===!0&&i.some(s=>!r.isActivityIdReserved(s)))return{ok:!1,reason:S.INVALID};let o=i.map(s=>r.adapter.getActivity(s));if(o.some(s=>!s))return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let a=[];for(let[s,c]of i.entries()){let l=o[s];if(!l)continue;let d={};l.isLookahead!==e.isLookahead&&(d.isLookahead={before:l.isLookahead,after:e.isLookahead},r.adapter.setActivityField(c,"isLookahead",e.isLookahead)),l.hasLookaheadTasks!==e.hasLookaheadTasks&&(d.hasLookaheadTasks={before:l.hasLookaheadTasks,after:e.hasLookaheadTasks},r.adapter.setActivityField(c,"hasLookaheadTasks",e.hasLookaheadTasks)),Object.keys(d).length!==0&&a.push({id:c,kind:N.UPDATED,fields:d,after:{...l,isLookahead:e.isLookahead,hasLookaheadTasks:e.hasLookaheadTasks}})}return e.persistedProgress!==void 0&&(await Wl([{activityId:i[0],progress:e.persistedProgress}],r)).length>0?(await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:e.persistedProgress===0?i[0]:null,recomputeParentsFrom:[],now:r.now,options:t}),{ok:!0,changes:await z(r.adapter,{source:e,beforeSnap:new Map,touchedIds:[],scheduledIds:[],hoursPerDay:r.sector.hoursPerDay})}):{ok:!0,changes:{source:e,activities:a,links:[],calendars:[],trackingEvents:[]}}}function kI(e){let t=e.persistedProgress;return t!==void 0&&(e.activityIds.length!==1||!Number.isFinite(t)||t<0||t>100)}function ca(e,t){let{adapter:r}=t,i=new Set(e.conversionRootIds.map(f=>String(f)));if(i.size===0)throw new Error("Conversion requires at least one root");for(let f of i)MI(f,r);let n=r.getVisualOrderIds().filter(f=>i.has(f)&&!Ar(f,i,r)),o=n.map(f=>RI(f,r)),a=o.map(({conversionRootId:f,convertedActivities:p})=>({conversionRootId:f,convertedActivities:p})),s=o.flatMap(f=>f.milestoneMoves),c=o.flatMap(f=>f.activityIdsToDelete),l=o.map(f=>f.formerParent),d=new Set(c),u=pn(d,r);return{sourceStateRevision:t.stateRevision,conversionRootIds:n,conversionGroups:a,milestoneMoves:s,activityIdsToDelete:c,linkIdsToDelete:u,formerParents:l}}async function Gl(e,t,r){if(e.expectedStateRevision!==r.stateRevision)return{ok:!1,reason:S.STALE_STATE_REVISION};let i=ca(e,r);if(!UI(i,r.adapter))return{ok:!1,reason:S.HIERARCHY_CYCLE};let{adapter:n,scheduler:o}=r;o.invalidateAllCaches();let a=await NI(i,n);bI(i,r),$l(i,n),FI(i,a.deletedIds,n);let s=wI(i,n);lr(n,s,a.deletedIds,a.beforeSnap,a.touchedIds);let{scheduledIds:c}=await Z({adapter:n,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:"roots",recomputeParentsFrom:a.touchedIds,now:r.now,options:t,recomputeParentProgress:!0}),l=await z(n,{source:e,beforeSnap:a.beforeSnap,touchedIds:a.touchedIds,scheduledIds:c,sirDetection:"after-diff",links:oa(a.beforeLinks),hoursPerDay:r.sector.hoursPerDay,correlativeShifts:s});return xI(i,a,l)}function RI(e,t){let r=sa(e,t),i=fn([e],t);if(i.delete(e),i.size===0)throw new Error(`Conversion root ${e} has no descendants`);let n=t.getVisualOrderIds().filter(c=>i.has(c)).map(c=>sa(c,t));Yl(r);for(let c of n)Yl(c);let o=n.filter(c=>c.type!==D.MILESTONE),a=n.filter(c=>c.type===D.MILESTONE),s=PI(r,o);return{conversionRootId:e,convertedActivities:o.map(c=>LI(c,s)),milestoneMoves:OI(r,a),activityIdsToDelete:o.map(c=>c.id),formerParent:{activity:et(r),hasConvertedActivities:o.length>0}}}function PI(e,t){let r=new Map;t.length>0&&r.set(e.id,jl(e));for(let i of t)r.set(i.id,jl(i));return r}function LI(e,t){let r=et(e),i=Gt(e.parentId),n=t.get(i);return r.parentId=n===void 0?null:String(n),r}function OI(e,t){let r=[],i=Gt(e.parentId),n=e.id;for(let o of t)r.push({activityId:o.id,parentId:i,afterSiblingId:n}),n=o.id;return r}async function NI(e,t){let r=new Set(e.activityIdsToDelete),i=new Set([...e.conversionRootIds,...e.activityIdsToDelete,...e.milestoneMoves.map(({activityId:n})=>n),...e.milestoneMoves.map(({parentId:n})=>n).filter(n=>n!=="0")]);return{deletedIds:r,touchedIds:i,beforeSnap:await rt(t,i),beforeLinks:BI(e.linkIdsToDelete,t),viewStateChanges:Zr(t,r)}}function bI(e,t){for(let r of e.activityIdsToDelete){let i=t.adapter.getActivity(r)?.customId;i&&t.customIdTracker.releaseCustomId(i)}}function $l(e,t){for(let r of e.milestoneMoves)t.setActivityFields(r.activityId,{parentId:r.parentId,correlativeId:gr(t,r.parentId,r.afterSiblingId,void 0)});for(let r of e.linkIdsToDelete)t.removeLink(r);for(let r of[...e.activityIdsToDelete].reverse())t.removeActivity(r);for(let{activity:r}of e.formerParents)t.setActivityField(r.id,x.TYPE,D.TASK)}function FI(e,t,r){for(let{activity:i,hasConvertedActivities:n}of e.formerParents){let o=sa(i.id,r),a=yn({parent:o,idsRemoved:t});r.setActivityFields(i.id,{isLookahead:i.isLookahead||n,hasLookaheadTasks:i.hasLookaheadTasks||n,...a?.fields??{}})}}function wI(e,t){for(let{activity:r}of e.formerParents)Ut(r.parentId,t);return St(t)}function xI(e,t,r){let i=new Map;for(let n of t.deletedIds){let o=t.beforeSnap.get(n);o&&i.set(n,o)}return{ok:!0,changes:t.viewStateChanges.length===0?r:{...r,viewState:t.viewStateChanges},conversionGroups:e.conversionGroups.map(({conversionRootId:n,convertedActivities:o})=>({conversionRootId:n,convertedActivities:o.map(a=>et(a))})),__beforeSnap:i,__beforeLinks:t.beforeLinks}}function MI(e,t){let r=t.getActivity(e);if(!r)throw new Error(`Conversion root ${e} was not found`);if(r.type===D.PROJECT&&r.correlativeId===0)throw new Error(`Conversion root ${e} is the visual project root`)}function sa(e,t){let r=t.getActivity(e);if(!r)throw new Error(`Conversion activity ${e} is missing`);return r}function jl(e){if(e.proplannerId==null)throw new Error(`Conversion activity ${e.id} has no persisted identifier`);return e.proplannerId}function Yl(e){if(!Number.isFinite(e.startDate.getTime()))throw new Error(`Conversion activity ${e.id} has invalid startDate`);if(!Number.isFinite(e.endDate.getTime()))throw new Error(`Conversion activity ${e.id} has invalid endDate`)}function UI(e,t){let r=t.fork();return $l(e,r),Oe({port:t,proposedPort:r,currentLinks:t.getAllLinks(),proposedLinks:r.getAllLinks()}).ok}function BI(e,t){let r=new Map;for(let i of e){let n=t.getLink(i);n&&r.set(i,{...n})}return r}function hn(e,t){let r=new Set;for(let n of e)r.add(String(n));let i=[];for(let n of t.getAllLinks()){let o=String(n.source),a=String(n.target);!r.has(o)&&!r.has(a)||(zl(a,o,t)||zl(o,a,t))&&i.push(String(n.id))}return i}function zl(e,t,r){let i=String(e),n=new Set;for(;i!=null;){if(n.has(i))return!1;n.add(i);let o=r.getActivity(i);if(!o)return!1;let a=o.parentId;if(a===null||M(a))return!1;let s=a;if(s===t)return!0;i=s}return!1}function mn(e,t){let r=e.getAllLinks();return!Oe({port:e,currentLinks:r,proposedLinks:r,proposal:{reparented:t}}).ok}function In(e,t){let r=new Set;if(e.length===0)return r;let i=new Map(e.map(o=>[o.activityId,o.newParentId]));if(!mn(t,i))return r;let n=new Map;for(let o of e){let a=new Map(n);if(a.set(o.activityId,o.newParentId),mn(t,a)){r.add(o.activityId);continue}n.set(o.activityId,o.newParentId)}return r}async function ql(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;n.invalidateAllCaches();let a=i.getActivity(e.activityId);if(!a)return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let s=M(e.parentId);if(!s&&!i.getActivity(e.parentId))return{ok:!1,reason:S.PARENT_NOT_FOUND};if(!s&&(e.parentId===e.activityId||i.isChildOf(e.parentId,e.activityId)))return{ok:!1,reason:S.CANNOT_MOVE_INTO_OWN_DESCENDANT};if(e.afterSiblingId!==void 0&&e.beforeSiblingId!==void 0)return{ok:!1,reason:S.ANCHOR_SIBLING_CONFLICT};let c=e.afterSiblingId??e.beforeSiblingId;if(c!==void 0){let b=i.getActivity(c);if(!b)return{ok:!1,reason:S.ANCHOR_SIBLING_NOT_FOUND};if((b.parentId===null?"0":String(b.parentId))!==e.parentId)return{ok:!1,reason:S.ANCHOR_SIBLING_WRONG_PARENT}}let l=a.parentId,d=Gt(l),u=String(e.parentId),f=d!==u;if(f){let b=new Map([[e.activityId,s?null:e.parentId]]);if(mn(i,b))return{ok:!1,reason:S.HIERARCHY_CYCLE}}let p=new Set([e.activityId]);f?(d!=="0"&&p.add(d),u!=="0"&&p.add(u)):d!=="0"&&p.add(d);let y=await rt(i,p);f&&i.setActivityField(e.activityId,x.PARENT,u);let g=gr(i,e.parentId,e.afterSiblingId,e.beforeSiblingId);if(i.setActivityField(e.activityId,x.CORRELATIVE_ID,g),f){if(!s){let b=i.getActivity(e.parentId);if(b){let B=b.customId,k=pe(b.type)&&i.getChildren(e.parentId).filter(P=>P!==e.activityId).length===0,v=Ir({parentId:e.parentId,newChildId:e.activityId,getParent:P=>i.getActivity(P)??null,isCurrentlyLeaf:k,promotionSource:mr.REPARENT});if(v){for(let[P,q]of Object.entries(v.fields))yt(i,v.parentId,P,q);v.promotionSnapshot&&i.setPromotionSnapshot(v.parentId,v.promotionSnapshot),v.fields.customId===null&&an(B,r.customIdTracker)}}}if(d!=="0"){let b=i.getActivity(d);if(b){let B=i.getChildren(d),k=vr({parent:b,remainingChildIds:B.map(String),defaultDurationHours:o.hoursPerDay,promotionSnapshot:i.getPromotionSnapshot(d),computeEndDate:(v,P)=>i.calculateEndDate({startDate:v,durationHours:P,task:b}),idsRemoved:new Set([e.activityId])});if(k){for(let[ot,it]of Object.entries(k.fields))yt(i,d,ot,it);let v=_e(d,i),P=v?i.getActivity(v)?.customId:null,q=typeof P=="string"&&P?P:null,$=r.customIdTracker.generateCustomIdForRestoredChild(q);i.setActivityField(d,x.CUSTOM_ID,$)}}}}f&&(d!=="0"&&Ut(d,i),s||Ut(e.parentId,i));let C=St(i);for(let b of C){if(p.add(b.activityId),y.has(b.activityId))continue;let B=i.getActivity(b.activityId);if(!B)continue;let k=et(B);b.before!==void 0&&(k.correlativeId=b.before),y.set(b.activityId,k)}let L=f&&d!=="0"?i.getChildren(d).map(String):[],{scheduledIds:T}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:e.activityId,recomputeParentsFrom:[e.activityId,e.parentId,...L],now:r.now,options:t,recomputeParentProgress:f}),E=f?hn([e.activityId],i):[],I={name:Kt.ACTIVITY_MOVE,properties:{activity_id:e.activityId,new_parent_id:e.parentId,after_sibling_id:e.afterSiblingId??null,before_sibling_id:e.beforeSiblingId??null,invalid_link_ids:E.map(String)}};return e.eventSource!==void 0&&(I.properties.event_source=e.eventSource),{ok:!0,changes:await z(i,{source:e,beforeSnap:y,touchedIds:p,scheduledIds:T,sirDetection:Ft.BEFORE_DIFF,trackingEvents:[I],hoursPerDay:o.hoursPerDay})}}function gn(e,t){let r=new Set(e),i=[],n=[],o=new Set,a=new Set(r),s=[...e].sort((d,u)=>{let f=t.getActivity(d),p=t.getActivity(u),y=f?Pt(f):Ve,g=p?Pt(p):Ve;return y-g});for(let d of s){if(!t.getActivity(d)){i.push({activityId:d,reason:S.ACTIVITY_NOT_FOUND}),a.delete(d);continue}if(Ar(d,o,t))continue;let f=hs(d,a,t);if(f==null){i.push({activityId:d,reason:S.INDENT_NO_ELIGIBLE_SIBLING}),a.delete(d);continue}let p=t.getActivity(d)?.parentId,y=M(p)?"0":String(p);n.push({activityId:d,newParentId:f,oldParentId:y}),o.add(d)}let c=In(n,t);for(let d of c)i.push({activityId:d,reason:S.HIERARCHY_CYCLE});let l=n.filter(d=>!c.has(d.activityId));return{moves:n,cyclicMoveIds:c,allowedMoves:l,failed:i}}async function Jl(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;if(n.invalidateAllCaches(),e.activityIds.length===0)return{ok:!1,reason:S.ACTIVITY_IDS_EMPTY};let a=new Set,s=[],c=gn(e.activityIds,i),l=[...c.failed];for(let T of c.moves)a.add(String(T.activityId)),a.add(String(T.newParentId)),T.oldParentId!=="0"&&a.add(String(T.oldParentId));let d=c.allowedMoves,u=await rt(i,a);for(let{activityId:T,newParentId:E}of d)i.setActivityField(T,x.PARENT,E),i.setActivityField(T,x.CORRELATIVE_ID,kl),s.push(T);let f=new Set;for(let{activityId:T,newParentId:E}of d){if(f.has(E))continue;f.add(E);let I=i.getActivity(E);if(!I)continue;let b=I.customId,B=pe(I.type)&&i.getChildren(E).filter(P=>!s.includes(P)).length===0,k=I.hasNewActivities&&I.newActivityIds.some(P=>String(P)===String(T)),v=Ir({parentId:E,newChildId:T,getParent:P=>i.getActivity(P)??null,isCurrentlyLeaf:B,promotionSource:mr.REPARENT});if(v){for(let[P,q]of Object.entries(v.fields))yt(i,v.parentId,P,q);v.promotionSnapshot&&i.setPromotionSnapshot(v.parentId,v.promotionSnapshot),k||(i.setActivityField(E,x.HAS_NEW_ACTIVITIES,!1),i.setActivityField(E,x.NEW_ACTIVITIES_ARRAY,[]))}i.setActivityField(E,x.CONSTRAINT_TYPE,A.ASAP),i.setActivityField(E,x.CONSTRAINT_DATE,null),i.setActivityField(E,x.CUSTOM_ID,null),an(b,r.customIdTracker)}let p=new Set;for(let T of d)T.oldParentId!=="0"&&p.add(T.oldParentId),p.add(T.newParentId);for(let T of p)Ut(T,i);let y=St(i);for(let T of y){if(a.add(T.activityId),u.has(T.activityId))continue;let E=i.getActivity(T.activityId);if(!E)continue;let I=et(E);T.before!==void 0&&(I.correlativeId=T.before),u.set(T.activityId,I)}let{scheduledIds:g}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:null,recomputeParentsFrom:s,now:r.now,options:t}),C=hn(s,i),L={name:Kt.ACTIVITY_INDENT,properties:{activity_ids:s,failed:l.map(T=>({activity_id:T.activityId,reason:T.reason})),invalid_link_ids:C}};return e.eventSource!==void 0&&(L.properties.event_source=e.eventSource),{ok:!0,activityVerdicts:e.activityIds.map(T=>{let E=l.find(I=>String(I.activityId)===String(T));return E?{activityId:String(T),ok:!1,reason:E.reason}:{activityId:String(T),ok:!0}}),changes:await z(i,{source:e,beforeSnap:u,touchedIds:a,scheduledIds:g,trackingEvents:[L],hoursPerDay:o.hoursPerDay})}}async function Xl(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;if(n.invalidateAllCaches(),e.activityIds.length===0)return{ok:!1,reason:S.ACTIVITY_IDS_EMPTY};let a=new Set(e.activityIds),s=new Map,c=new Map;for(let k of e.activityIds){let v=k;i.getActivity(v)&&(s.set(v,Qn(v,i)),c.set(v,Rl(v,a,i)))}let l=new Set,d=[],u=[],f=new Set,p=[],y=new Set,g=[...e.activityIds].sort((k,v)=>{let P=i.getActivity(k),q=i.getActivity(v),$=P?Pt(P):Ve,ot=q?Pt(q):Ve;return $-ot});for(let k of g){let v=k,P=i.getActivity(v);if(!P){d.push({activityId:v,reason:S.ACTIVITY_NOT_FOUND});continue}if(Ar(v,y,i))continue;let q=P.parentId;if(M(q)){d.push({activityId:v,reason:S.OUTDENT_ROOT_LEVEL_NOT_EDITABLE});continue}let $=String(q),ot=i.getActivity($);if(!ot){d.push({activityId:v,reason:S.ACTIVITY_NOT_FOUND});continue}let it=ot.parentId;if(M(it)){d.push({activityId:v,reason:S.OUTDENT_ROOT_LEVEL_NOT_EDITABLE});continue}let _t=String(it),wt=Qn($,i)+1,ht=c.get(v);if(ht!=null&&a.has(ht)){let Ge=s.get(ht)??-1,$e=s.get(v)??-1;Ge>=0&&$e>=0&&(wt+=$e-Ge)}p.push({activityId:v,grandparentKey:_t,oldParentKey:$,targetIndexInGrandparent:wt}),y.add(v),l.add(String(v)),l.add(String($)),_t!=="0"&&l.add(String(_t)),f.add($)}let C=In(p.map(k=>({activityId:k.activityId,newParentId:k.grandparentKey})),i);for(let k of C)d.push({activityId:k,reason:S.HIERARCHY_CYCLE});let L=p.filter(k=>!C.has(k.activityId)),T=await rt(i,l);for(let k of L){i.setActivityField(k.activityId,x.PARENT,k.grandparentKey);let v=Pl(i,k.grandparentKey,k.targetIndexInGrandparent,k.activityId);i.setActivityField(k.activityId,x.CORRELATIVE_ID,v),u.push(k.activityId)}for(let k of f){let v=i.getActivity(k);if(!v)continue;let P=i.getChildren(k),q=vr({parent:v,remainingChildIds:P.map(String),defaultDurationHours:o.hoursPerDay,promotionSnapshot:i.getPromotionSnapshot(k),computeEndDate:(wt,ht)=>i.calculateEndDate({startDate:wt,durationHours:ht,task:v}),idsRemoved:new Set(L.filter(wt=>wt.oldParentKey===k).map(wt=>wt.activityId))});if(!q){Ni(k,i);continue}for(let[wt,ht]of Object.entries(q.fields))yt(i,k,wt,ht);let $=_e(k,i),ot=$?i.getActivity($)?.customId:null,it=typeof ot=="string"&&ot?ot:null,_t=r.customIdTracker.generateCustomIdForRestoredChild(it);i.setActivityField(k,x.CUSTOM_ID,_t)}let E=new Set;for(let k of f)E.add(String(k));for(let k of L)k.grandparentKey!=="0"&&E.add(String(k.grandparentKey));for(let k of E)Ut(k,i);let I=St(i);for(let k of I){if(l.add(k.activityId),T.has(k.activityId))continue;let v=i.getActivity(k.activityId);if(!v)continue;let P=et(v);k.before!==void 0&&(P.correlativeId=k.before),T.set(k.activityId,P)}let{scheduledIds:b}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:u.length>0?Dt.ROOTS:null,recomputeParentsFrom:u,now:r.now,options:t}),B={name:Kt.ACTIVITY_OUTDENT,properties:{activity_ids:u.map(String),failed:d.map(k=>({activity_id:String(k.activityId),reason:k.reason}))}};return e.eventSource!==void 0&&(B.properties.event_source=e.eventSource),{ok:!0,activityVerdicts:e.activityIds.map(k=>{let v=d.find(P=>String(P.activityId)===String(k));return v?{activityId:String(k),ok:!1,reason:v.reason}:{activityId:String(k),ok:!0}}),changes:await z(i,{source:e,beforeSnap:T,touchedIds:l,scheduledIds:b,trackingEvents:[B],hoursPerDay:o.hoursPerDay})}}async function Zl(e,t,r){let{adapter:i,ctx:n,scheduler:o,sector:a}=r;if(e.newValue!==0&&e.newValue!==100)return{ok:!1,reason:S.INVALID_PROGRESS_VALUE};let s=n.activityReader.getActivity(e.activityId);if(!s)return{ok:!1,reason:S.ACTIVITY_NOT_FOUND};let c=Se(_.PROGRESS);if(!c)throw new Error("[ScheduleCore] progressPipeline not registered \u2014 cannot dispatch activity-set-progress");let l=c.canEdit(s,n.hierarchy);if(!l.allowed&&!(e.origin===Wi.ACTION_BUTTON&&(l.reason===Wr.HAS_LOOKAHEAD_TASKS||l.reason===Wr.SUMMARY)))return{ok:!1,reason:l.reason,...l.alertKey?{alertKey:l.alertKey}:{}};let d=c.transform(s,e.newValue,n,e.newValue),u=Te(e.activityId,d),f=await rt(i,u);Ee(i,e.activityId,d),zs(e.activityId,e.newValue,i),Ie(e.activityId,d.postProcessors??[],i);let p=d.needsAutoSchedule?n.hierarchy.hasChildren(e.activityId)?Dt.ROOTS:e.activityId:null,{scheduledIds:y}=await Z({adapter:i,scheduler:o,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:p,recomputeParentsFrom:[],collectDirty:C=>$i(e.activityId,u,C),now:r.now,options:t}),g=(d.trackingEvents??[]).map(C=>({name:C.name,properties:C.properties??{}}));return{ok:!0,changes:await z(i,{source:e,beforeSnap:f,touchedIds:u,scheduledIds:y,trackingEvents:g,hoursPerDay:a.hoursPerDay})}}function HI(e){return e===_.START_DATE||e===_.END_DATE}async function Ql(e,t,r){if(e.edits.some(y=>!HI(y.column)))return{ok:!1,reason:S.INVALID_VALUE};let{adapter:i,scheduler:n,sector:o}=r,a=[],s=new Map,c=new Set,l=[],d=[],u=[],f=!1;for(let y of e.edits){let g=WI(y,r);if(a.push(g.verdict),!g.verdict.ok||!g.changes)continue;let C=Te(y.activityId,g.changes);VI(s,C,r);for(let I of C)c.add(I);let L=yr(i,y.activityId),T=Yi(i,String(y.activityId));Ee(i,y.activityId,g.changes),Ie(y.activityId,g.changes.postProcessors??[],i,T),d.push(...hr(L,i,y.activityId)),f||=!!g.changes.needsAutoSchedule;for(let I of g.changes.trackingEvents??[])l.push({name:I.name,properties:I.properties??{}});let E=cr(y.activityId,g.changes.constraintWarning);E&&u.push(E)}let{scheduledIds:p}=await Z({adapter:i,scheduler:n,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:f?Dt.ROOTS:null,recomputeParentsFrom:c,now:r.now,options:t});return{ok:!0,verdicts:a,changes:await z(i,{source:e,beforeSnap:s,touchedIds:c,scheduledIds:p,sirDetection:Ft.BEFORE_DIFF,links:d,trackingEvents:l,warnings:u,hoursPerDay:o.hoursPerDay})}}function WI(e,t){let{ctx:r}=t,i=e.activityId,n=Se(e.column);if(!n)throw new Error(`[ScheduleCore] no pipeline registered for column "${e.column}"`);let o=r.activityReader.getActivity(e.activityId);if(!o)throw new Error(`[ScheduleCore] activity "${e.activityId}" not found`);let a=n.canEdit(o,r.hierarchy);if(!a.allowed)return{verdict:{activityId:i,ok:!1,reason:a.reason??S.CANNOT_EDIT,...a.alertKey?{alertKey:a.alertKey}:{}},changes:null};let s=n.parseInput(e.newValue,o,r);if(!s.ok)return{verdict:{activityId:i,ok:!1,reason:s.reason??S.PARSE_ERROR},changes:null};let c=Reflect.get(o,n.targetField),l=n.validate(o,c,s.value,r);if(!l.valid)return{verdict:{activityId:i,ok:!1,reason:l.reason??S.INVALID,...l.notification?.messageKey?{alertKey:l.notification.messageKey}:{}},changes:null};let d=n.transform(o,s.value,r,s.raw);return{verdict:{activityId:i,ok:!0},changes:d}}function VI(e,t,r){let i=new Set;for(let n of t)e.has(n)||i.add(n);if(i.size!==0)for(let n of i){let o=r.adapter.getActivity(n);o&&e.set(n,et(o))}}var la=_.CUSTOM_ID;async function td(e,t,r){let{adapter:i,scheduler:n,sector:o}=r;e.edits.some(E=>E.column===_.DURATION)&&n.invalidateExpandedLinksCache();let s=[],c=new Map,l=new Map,d=new Set,u=new Set,f=[],p=[],y=[],g=!1;for(let E of e.edits){let I=KI(E,r,e.eventSource);if(s.push(I.verdict),!I.verdict.ok||!I.changes)continue;let b=cr(E.activityId,I.changes.constraintWarning);b&&y.push(b);let B=Te(E.activityId,I.changes);$I(c,B,r);for(let $ of B)u.add($);GI(l,E,c),rn(E.column)&&d.add(String(E.activityId));let k=yr(i,E.activityId),v=Yi(i,String(E.activityId)),P=jI(E,r),q=I.changes;Ee(i,E.activityId,q),Ie(E.activityId,I.changes.postProcessors??[],i,v),YI(E,P,r),p.push(...hr(k,i,E.activityId)),g||=!!I.changes.needsAutoSchedule;for(let $ of I.changes.trackingEvents??[])f.push({name:$.name,properties:$.properties??{}})}let C={action:e,autoscheduleFrom:g?Dt.ROOTS:null,recomputeParentsFrom:u,now:r.now,options:t},L=l.size>0,{scheduledIds:T}=await(L?on({adapter:i,scheduler:n,sector:o,defaultBaseCalendarId:r.defaultBaseCalendarId},{postMutationArgs:C,revertTargets:[...l].filter(([E])=>!d.has(E)).map(([E,I])=>({activityId:E,priorConstraintDate:I})),revert:(E,I)=>nn(E,I,i,r.ctx.calendars)}):Z({adapter:i,scheduler:n,sector:o,defaultBaseCalendarId:r.defaultBaseCalendarId},C));return{ok:!0,verdicts:s,changes:await z(i,{source:e,beforeSnap:c,touchedIds:u,scheduledIds:T,sirDetection:Ft.BEFORE_DIFF,links:p,trackingEvents:f,warnings:y,hoursPerDay:o.hoursPerDay})}}function KI(e,t,r){let{ctx:i}=t,n=e.activityId,o=Se(e.column);if(!o)return{verdict:{activityId:n,ok:!1,reason:S.NO_PIPELINE_FOR_COLUMN},changes:null};let a=i.activityReader.getActivity(e.activityId);if(!a)return{verdict:{activityId:n,ok:!1,reason:S.ACTIVITY_NOT_FOUND},changes:null};let s=o.canEdit(a,i.hierarchy,{eventSource:r,newValue:e.newValue});if(!s.allowed)return{verdict:{activityId:n,ok:!1,reason:s.reason??S.CANNOT_EDIT,...s.alertKey?{alertKey:s.alertKey}:{}},changes:null};let c=o.parseInput(e.newValue,a,i);if(!c.ok)return{verdict:{activityId:n,ok:!1,reason:c.reason??S.PARSE_ERROR},changes:null};let l=Reflect.get(a,o.targetField),d=o.validate(a,l,c.value,i);if(!d.valid)return{verdict:{activityId:n,ok:!1,reason:d.reason??S.INVALID,...d.notification?.messageKey?{alertKey:d.notification.messageKey}:{}},changes:null};if(e.column===la&&c.value!==null){let f=t.adapter.getActivity(e.activityId),p=f?f.customId:null,y=typeof p=="string"?p:null;if(t.customIdTracker.isCustomIdInUse(String(c.value),y))return{verdict:{activityId:n,ok:!1,reason:S.CUSTOM_ID_DUPLICATE},changes:null}}let u=o.transform(a,c.value,i,c.raw);return{verdict:{activityId:n,ok:!0},changes:u}}function jI(e,t){if(e.column!==la)return null;let r=t.adapter.getActivity(e.activityId),i=r?r.customId:null;return typeof i=="string"?i:null}function YI(e,t,r){if(e.column!==la)return;let i=r.adapter.getActivity(e.activityId),n=i?i.customId:null,o=typeof n=="string"?n:null;t!==o&&r.customIdTracker.trackCustomIdChange(t,o)}function GI(e,t,r){if(!en(t.column))return;let i=String(t.activityId);if(e.has(i))return;let n=r.get(i);n&&e.set(i,n.constraintDate??null)}function $I(e,t,r){let i=new Set;for(let n of t)e.has(n)||i.add(n);if(i.size!==0)for(let n of i){let o=r.adapter.getActivity(n);o&&e.set(n,et(o))}}var Lt={INVALID_BASELINE_POINT:"invalid_baseline_point",UNKNOWN_CONSTRAINT:"unknown_constraint",ORPHAN_ACTIVITY:"orphan_activity",INVALID_LINK:"invalid_link",DUPLICATE_LINK:"duplicate_link"},zI=[Lt.INVALID_BASELINE_POINT,Lt.UNKNOWN_CONSTRAINT,Lt.ORPHAN_ACTIVITY,Lt.INVALID_LINK,Lt.DUPLICATE_LINK],Cr=()=>{};function ed(){let e=new Map,t=new Map;return{record:(n,o)=>{e.set(n,(e.get(n)??0)+1);let a=t.get(n)??[];a.length<10&&!a.includes(o)&&(a.push(o),t.set(n,a))},snapshot:()=>Object.freeze(zI.flatMap(n=>{let o=e.get(n);return o===void 0?[]:[Object.freeze({code:n,count:o,sampleIds:Object.freeze([...t.get(n)??[]])})]}))}}function rd(e){return typeof e=="string"&&e.length>0?se(e):e instanceof Date?e:null}function da(e){let t=typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):Number.NaN;return!Number.isFinite(t)||t<0?null:t}function An(e,t,r,i=!1){let n=da(e.duration),o=da(e.cost),a=da(e.hh_work);if(n===null||o===null||a===null)return r&&r.record(Lt.INVALID_BASELINE_POINT,r.sampleId),t.warn(`[baseline] dropping point with non-finite/negative magnitude \u2014 duration=${JSON.stringify(e.duration)}, cost=${JSON.stringify(e.cost)}, hh_work=${JSON.stringify(e.hh_work)}`),null;let s=rd(e.start_date),c=rd(e.end_date),l=i&&n===0&&s!==null&&c!==null&&c<s;return l&&t.warn("[baseline] normalizing inverted zero-duration milestone to one instant"),{startDate:s,endDate:l?s:c,durationDays:n,cost:o,workHours:a,versionId:typeof e.sectorbaselineversionId=="number"?e.sectorbaselineversionId:null,isActiveVersion:!!e.sectorbaselineversion?.active,isVisibleVersion:!!e.sectorbaselineversion?.visible,baseCalendarId:e.baseCalendarId!=null?String(e.baseCalendarId):null,hoursPerDay:typeof e.hoursPerDay=="number"?e.hoursPerDay:null,hoursPerWeek:typeof e.hoursPerWeek=="number"?e.hoursPerWeek:null}}function id(e,t,r,i=Cr){let n=new Map;e.forEachActivity((s,c)=>{let l=s.proplannerId;typeof l=="number"&&n.set(l,c)});let o=new Map;for(let s of t){let c=s.activityId;if(typeof c!="number"){i(Lt.INVALID_BASELINE_POINT,String(c??"unknown"));continue}let l=n.get(c);if(l===void 0){i(Lt.INVALID_BASELINE_POINT,String(c));continue}let d=o.get(l);d?d.push(s):o.set(l,[s])}let a=[];for(let[s,c]of o){let l=e.getActivity(s)?.type===D.MILESTONE;e.setActivityField(s,"baselinePoints",c.map(d=>An(d,r,{record:i,sampleId:s},l)).filter(d=>d!==null)),a.push(s)}return e.forEachActivity((s,c)=>{if(o.has(c))return;let l=s.baselinePoints;Array.isArray(l)&&l.length>0&&(e.setActivityField(c,"baselinePoints",[]),a.push(c))}),a}function qI(e){let t=Rt(e);return t?{startDate:t.startDate,endDate:t.endDate,durationDays:t.durationDays,cost:t.cost,workHours:t.workHours}:null}function nd(e){let t=[];return e.forEachActivity((r,i)=>{let n=qI(r);if(!n){r.baselineSnapshot!==null&&(e.setActivityField(i,"baselineSnapshot",null),t.push(i));return}e.setActivityField(i,"baselineSnapshot",n),t.push(i)}),t}function vn(e,t,r,i,n=null,o=Cr){let a=new Set;for(let s of id(e,t,i,o))a.add(s);if(r)for(let s of ur(e,r,n))a.add(s);for(let s of nd(e))a.add(s);for(let s of fr(e))a.add(s);return[...a]}function od(e,t,r){if(!e||e==="0")return;let i=r.getChildren(e);if(i.length===0)return;let n=new Map,o=0;for(let s of i){let c=JI(String(s),t,r);n.set(String(s),c),o+=c}let a=o?100/o:0;for(let s of i){let c=r.getActivity(s);if(!c)continue;let l=c.baselinePoints;if(Rt(c)){let u=n.get(String(s))??0;r.setActivityField(s,_.PONDERATOR,a*u)}else(!Array.isArray(l)||l.length===0)&&r.setActivityField(s,_.PONDERATOR,0)}}function JI(e,t,r){let i=r.getActivity(e);if(!i)return 0;let n=Rt(i);if(!n)return 0;if(t===gt.COST)return Cn(n.cost);if(t===gt.WORK_HOURS)return Cn(n.workHours);let{type:o}=i;return o===D.PROJECT?ad(e,r):o===D.MILESTONE?0:Cn(n.durationDays)}function ad(e,t){let r=0;for(let i of t.getChildren(e)){let n=t.getActivity(i);if(!n)continue;let o=Rt(n);if(!o)continue;let{type:a}=n;a===D.PROJECT?r+=ad(String(i),t):a!==D.MILESTONE&&(r+=Cn(o.durationDays))}return r}function Cn(e){let t=typeof e=="string"?parseFloat(e):e;return typeof t=="number"&&Number.isFinite(t)?t:0}function sd(e,t){t.forEachActivity((r,i)=>{t.setActivityField(i,_.PONDERATOR,0)}),t.forEachActivity((r,i)=>{t.getChildren(i).length>0&&od(String(i),e,t)})}function Sn(e,t){sd(t,e.adapter),Ur(e.adapter),e.now&&(ur(e.adapter,e.now,e.defaultBaseCalendarId??null),Me(e.adapter,e.now)),fr(e.adapter),e.now&&ce(e.adapter,e.sector.statusCriteria)}function cd(e){return JSON.stringify(e.adapter.getAllIds().map(t=>{let r=e.adapter.getActivity(t)?.baselinePoints.find(i=>i.isActiveVersion);return r?[String(t),r.versionId,r.startDate?.getTime()??null,r.endDate?.getTime()??null,r.durationDays,r.cost,r.workHours,r.baseCalendarId,r.hoursPerDay,r.hoursPerWeek]:[String(t),null]}))}async function ld(e,t){let r=await rt(t.adapter,new Set(t.adapter.getAllIds())),i=cd(t),n=vn(t.adapter,e.points,t.now,t.reporter,t.defaultBaseCalendarId??null);return cd(t)!==i&&Sn(t,t.sector.activityCreter??gt.DURATION),{ok:!0,changes:await z(t.adapter,{source:e,beforeSnap:r,touchedIds:n,scheduledIds:[],hoursPerDay:t.sector.hoursPerDay})}}function XI(e){return Object.values(gt).includes(e)}async function dd(e,t){if(!XI(e.criterion))return{ok:!1,reason:S.INVALID_VALUE};let r=new Set(t.adapter.getAllIds()),i=await rt(t.adapter,r);return Sn(t,e.criterion),t.sector.activityCreter=e.criterion,{ok:!0,changes:await z(t.adapter,{source:e,beforeSnap:i,touchedIds:r,scheduledIds:[],hoursPerDay:t.sector.hoursPerDay})}}async function ud(e,t){let r=zi(e.criteria),i=new Set(t.adapter.getAllIds()),n=await rt(t.adapter,i),o=ce(t.adapter,r);return t.sector.statusCriteria=r,{ok:!0,changes:await z(t.adapter,{source:e,beforeSnap:n,touchedIds:o,scheduledIds:[],hoursPerDay:t.sector.hoursPerDay})}}async function pd(e,t,r){let i=new Map,n=new Set;for(let a of r.adapter.getAllActivities()){if(!ZI(a,r))continue;let s=r.ctx.calendars.getCalendar(a.calendarId);if(!s)continue;let c=s.getClosestWorkTime({date:a.startDate,direction:K.FUTURE,unit:mt.HOUR}),l=s.calculateEndDate(c,a.durationHours);if(fd(c,a.startDate)&&fd(l,a.endDate))continue;let d=String(a.id);i.set(d,et(a)),n.add(d),r.adapter.setActivityFields(d,{startDate:c,endDate:l})}let{scheduledIds:o}=await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:Dt.ROOTS,recomputeParentsFrom:n,now:r.now,options:t});return{ok:!0,changes:await z(r.adapter,{source:e,beforeSnap:i,touchedIds:n,scheduledIds:o,hoursPerDay:r.sector.hoursPerDay})}}function ZI(e,t){return e.progress===0&&!$t(e.type,t.adapter.hasChildren(e.id))}function fd(e,t){return e.getTime()===t.getTime()}var yd=["name","description","type","startDate","durationHours","constraintType","constraintDate","calendarId","cost","hasCustomPonderator","subcontractId","responsableIds","tagIds"];function QI(e){let t={};for(let r of yd)Object.assign(t,{[r]:F(e[r])});return t}function tg(e,t){let r=[],i=n=>{t.has(String(n))&&r.push(n);for(let o of e.getChildren(n))i(o)};for(let n of e.getRootIds())i(n);return r}function hd(e,t){let r=new Set(t.adapter.checkedIds().map(String));if(r.size===0)return{ok:!1,reason:S.NO_ACTIVITY_SELECTION};let i=tg(t.adapter,r);t.clipboard.value={activities:i.map(o=>{let a=t.adapter.getActivity(o);if(a===null)throw new Error(`Selected activity ${o} is missing`);return{originalId:o,originalParentId:a.parentId??"0",overrides:QI(a)}}),links:t.adapter.getAllLinks().filter(o=>r.has(String(o.source))&&r.has(String(o.target))).map(o=>F(o))};let n=ci({kind:m.SELECTION_REPLACE,activityIds:[]},{adapter:t.adapter});return n.ok?{...n,changes:{...n.changes,source:e}}:n}function md(e,t){return t.value=null,{ok:!0,changes:{source:e,activities:[],links:[],calendars:[],trackingEvents:[]}}}function eg(e,t){let r=t.getActivity(e);return r?r.parentId==null?t.getRootIds().length===1?{ok:!0,parentId:r.id}:{ok:!0,parentId:"0",afterSiblingId:e}:{ok:!0,parentId:String(r.parentId),afterSiblingId:e}:{ok:!1,reason:S.ANCHOR_SIBLING_NOT_FOUND}}var Id=()=>({ok:!1,reason:S.ACTIVITY_PASTE_INVARIANT_FAILED});async function gd(e,t,r){let i=r.activityClipboard.value;if(i===null)return{ok:!1,reason:S.CLIPBOARD_EMPTY};let n=eg(e.destination.afterSiblingId,r.adapter);if(!n.ok)return n;let o=await rt(r.adapter,new Set),a=new Set,s=new Map,c=[],l;for(let g of i.activities){let C=s.get(g.originalParentId),L=C===void 0?l??n.afterSiblingId:void 0,T=await Xr({kind:m.ACTIVITY_CREATE,parentId:C??n.parentId,...L===void 0?{}:{afterSiblingId:L},overrides:F(g.overrides),eventSource:e.eventSource},r,{skipCorrelativeRecompute:!0,skipBeforeSnap:!0,customIdReferenceId:e.destination.afterSiblingId});if(!T.ok)return T;s.set(g.originalId,T.newId),c.push(T.newId),C===void 0&&(l=T.newId)}let d=St(r.adapter),u=new Set(c.map(String));lr(r.adapter,d,u,o,a);for(let g of c)a.add(String(g));let f=[];for(let g of i.links){let C=s.get(g.source),L=s.get(g.target);if(C===void 0||L===void 0)return Id();let T={kind:dt.CREATE,source:C,target:L,type:g.type,lag:g.lag},E=ye(T,{port:r.adapter,newLinkId:r.linkIdGen.next});if(!E.applied)return Id();f.push({op:T,finalLinkId:E.linkId,rejected:null})}let{scheduledIds:p}=await Z({adapter:r.adapter,scheduler:r.scheduler,sector:r.sector,defaultBaseCalendarId:r.defaultBaseCalendarId},{action:e,autoscheduleFrom:c[0]??null,recomputeParentsFrom:c,now:r.now,options:t}),y=pr(f,new Map,r.adapter);return{ok:!0,changes:await z(r.adapter,{source:e,beforeSnap:o,touchedIds:a,scheduledIds:p,links:y,hoursPerDay:r.sector.hoursPerDay})}}async function Ad(e,t,r){return e.kind===m.ACTIVITY_COPY?hd(e,{adapter:r.adapter,clipboard:r.activityClipboard}):e.kind===m.CALENDAR_RECONCILE?pd(e,t,r):e.kind===m.ACTIVITY_CLIPBOARD_CLEAR?md(e,r.activityClipboard):e.kind===m.ACTIVITY_PASTE_COPIED?gd(e,t,r):e.kind===ue?wl(e,t,r):e.kind===m.PERSISTENCE_ACKNOWLEDGE?Vl(e,r):e.kind===m.BASELINE_APPLY?ld(e,r):e.kind===m.PONDERATOR_CRITERION_SET?dd(e,r):e.kind===m.STATUS_CRITERIA_SET?ud(e,r):e.kind===m.LINK_CREATE||e.kind===m.LINK_UPDATE||e.kind===m.LINK_DELETE?pl(e,t,r):e.kind===m.LINKS_BATCH?yl(e,t,r):e.kind===m.ACTIVITY_CREATE?Ll(e,t,r):e.kind===m.ACTIVITY_DELETE?Nl(e,t,r):e.kind===m.ACTIVITY_MOVE?ql(e,t,r):e.kind===m.ACTIVITY_INDENT?Jl(e,t,r):e.kind===m.ACTIVITY_OUTDENT?Xl(e,t,r):e.kind===m.ACTIVITY_SET_PROGRESS?Zl(e,t,r):e.kind===m.DATES_BATCH?Ql(e,t,r):e.kind===m.BULK_EDIT?td(e,t,r):e.kind===m.SELECTION_TOGGLE?rs(e,ua(r)):e.kind===m.SELECTION_REPLACE?ci(e,ua(r)):e.kind===m.VISIBILITY_SET?is(e,ua(r)):e.kind===m.FILTER_SET?fs(e,{adapter:r.adapter,hoursPerDay:r.sector.hoursPerDay}):e.kind===m.SORT_SET?Is(e,{adapter:r.adapter}):e.kind===m.SIR_SYNC?Ml(e,r):e.kind===m.ACTIVITY_LOOKAHEAD_SYNC?Kl(e,t,r):e.kind===m.ACTIVITY_LOOKAHEAD_CONVERT?Gl(e,t,r):e.kind===m.INLINE_EDIT&&(e.column===_.CUSTOM_PREDECESSORS||e.column===_.CUSTOM_SUCESSORS)?hl(e,t,r):e.kind!==m.INLINE_EDIT?gs(e,`[ScheduleCore] dispatch kind "${e.kind}" not supported yet`):fl(e,t,r)}function ua(e){return{adapter:e.adapter}}var rg=new Set(["startDate","endDate","constraintDate"]);function vd(e,t){return rg.has(e)&&typeof t=="string"?new Date(t):t}function Cd(e,t={}){let r=t.defaultUnit??mt.HOUR;return{getCalendar(i){let n=e.getCalendar(String(i));return n?ig(n,r):null}}}function ig(e,t){return{getClosestWorkTime(r){return e.getClosestWorkTime({date:r.date,dir:r.direction,unit:r.unit})},calculateEndDate(r,i){return e.calculateEndDate({start_date:r,duration:i,unit:t})},calculateDuration(r,i){return e.calculateDuration({start_date:r,end_date:i,unit:t})},isWorkTime(r,i){return e.isWorkTime({date:r,unit:i})},getWorkHours(r){return e.getWorkHours(r)}}}function ng(e){return Array.isArray?Array.isArray(e):e&&e.length!==void 0&&e.pop&&e.push}function Ke(e){return e&&typeof e=="object"?!!(e.getFullYear&&e.getMonth&&e.getDate):!1}function je(e){return Ke(e)&&!isNaN(e.getTime())}var og={}.constructor.toString();function ag(e){var t=e.constructor.toString();return t!==og}function sg(e){return e.$$typeof&&e.$$typeof.toString().includes("react.")}function Jt(e){var t,r;if(e&&typeof e=="object")switch(!0){case Ke(e):r=new Date(e);break;case ng(e):for(r=new Array(e.length),t=0;t<e.length;t++)r[t]=Jt(e[t]);break;default:if(ag(e))r=Object.create(e);else{if(sg(e))return r=e,r;r={}}for(t in e)Object.prototype.hasOwnProperty.apply(e,[t])&&(r[t]=Jt(e[t]));break}return r||e}function Sr(e,t,r){for(var i in t)(e[i]===void 0||r)&&(e[i]=t[i]);return e}function Sd(e){return typeof e<"u"}var Tn;function fa(){return Tn||(Tn=new Date().valueOf()),Tn++,Tn}function Bt(e,t){return e.bind?e.bind(t):function(){return e.apply(t,arguments)}}var lg=(e,t,r)=>{e=e.replace(/%[a-zA-Z]/g,n=>{switch(n){case"%d":return`"+to_fixed(date.get${t?"UTC":""}Date())+"`;case"%m":return`"+to_fixed((date.get${t?"UTC":""}Month()+1))+"`;case"%j":return`"+date.get${t?"UTC":""}Date()+"`;case"%n":return`"+(date.get${t?"UTC":""}Month()+1)+"`;case"%y":return`"+to_fixed(date.get${t?"UTC":""}FullYear()%100)+"`;case"%Y":return`"+date.get${t?"UTC":""}FullYear()+"`;case"%D":return`"+locale.date.day_short[date.get${t?"UTC":""}Day()]+"`;case"%l":return`"+locale.date.day_full[date.get${t?"UTC":""}Day()]+"`;case"%M":return`"+locale.date.month_short[date.get${t?"UTC":""}Month()]+"`;case"%F":return`"+locale.date.month_full[date.get${t?"UTC":""}Month()]+"`;case"%h":return`"+to_fixed((date.get${t?"UTC":""}Hours()+11)%12+1)+"`;case"%g":return`"+((date.get${t?"UTC":""}Hours()+11)%12+1)+"`;case"%G":return`"+date.get${t?"UTC":""}Hours()+"`;case"%H":return`"+to_fixed(date.get${t?"UTC":""}Hours())+"`;case"%i":return`"+to_fixed(date.get${t?"UTC":""}Minutes())+"`;case"%a":return`"+(date.get${t?"UTC":""}Hours()>11?"pm":"am")+"`;case"%A":return`"+(date.get${t?"UTC":""}Hours()>11?"PM":"AM")+"`;case"%s":return`"+to_fixed(date.get${t?"UTC":""}Seconds())+"`;case"%W":return'"+to_fixed(getISOWeek(date))+"';case"%w":return'"+to_fixed(getWeek(date))+"';default:return n}});let i=new Function("date","to_fixed","locale","getISOWeek","getWeek",`return "${e}";`);return n=>i(n,r.date.to_fixed,r.locale,r.date.getISOWeek,r.date.getWeek)},dg=(e,t,r)=>{let i="var temp=date.match(/[a-zA-Z]+|[0-9]+/g);",n=e.match(/%[a-zA-Z]/g);for(let s=0;s<n.length;s++)switch(n[s]){case"%j":case"%d":i+=`set[2]=temp[${s}]||1;`;break;case"%n":case"%m":i+=`set[1]=(temp[${s}]||1)-1;`;break;case"%y":i+=`set[0]=temp[${s}]*1+(temp[${s}]>50?1900:2000);`;break;case"%g":case"%G":case"%h":case"%H":i+=`set[3]=temp[${s}]||0;`;break;case"%i":i+=`set[4]=temp[${s}]||0;`;break;case"%Y":i+=`set[0]=temp[${s}]||0;`;break;case"%a":case"%A":i+=`set[3]=set[3]%12+((temp[${s}]||'').toLowerCase()=='am'?0:12);`;break;case"%s":i+=`set[5]=temp[${s}]||0;`;break;case"%M":i+=`set[1]=locale.date.month_short_hash[temp[${s}]]||0;`;break;case"%F":i+=`set[1]=locale.date.month_full_hash[temp[${s}]]||0;`;break}let o="set[0],set[1],set[2],set[3],set[4],set[5]";t&&(o=` Date.UTC(${o})`);let a=new Function("date","locale",`var set=[0,0,1,0,0,0]; ${i} return new Date(${o});`);return s=>a(s,r.locale)},Td={date_to_str:lg,str_to_date:dg},ug=(e,t,r)=>i=>e.replace(/%[a-zA-Z]/g,n=>{switch(n){case"%d":return t?r.date.to_fixed(i.getUTCDate()):r.date.to_fixed(i.getDate());case"%m":return t?r.date.to_fixed(i.getUTCMonth()+1):r.date.to_fixed(i.getMonth()+1);case"%j":return t?i.getUTCDate():i.getDate();case"%n":return t?i.getUTCMonth()+1:i.getMonth()+1;case"%y":return t?r.date.to_fixed(i.getUTCFullYear()%100):r.date.to_fixed(i.getFullYear()%100);case"%Y":return t?i.getUTCFullYear():i.getFullYear();case"%D":return t?r.locale.date.day_short[i.getUTCDay()]:r.locale.date.day_short[i.getDay()];case"%l":return t?r.locale.date.day_full[i.getUTCDay()]:r.locale.date.day_full[i.getDay()];case"%M":return t?r.locale.date.month_short[i.getUTCMonth()]:r.locale.date.month_short[i.getMonth()];case"%F":return t?r.locale.date.month_full[i.getUTCMonth()]:r.locale.date.month_full[i.getMonth()];case"%h":return t?r.date.to_fixed((i.getUTCHours()+11)%12+1):r.date.to_fixed((i.getHours()+11)%12+1);case"%g":return t?(i.getUTCHours()+11)%12+1:(i.getHours()+11)%12+1;case"%G":return t?i.getUTCHours():i.getHours();case"%H":return t?r.date.to_fixed(i.getUTCHours()):r.date.to_fixed(i.getHours());case"%i":return t?r.date.to_fixed(i.getUTCMinutes()):r.date.to_fixed(i.getMinutes());case"%a":return t?i.getUTCHours()>11?"pm":"am":i.getHours()>11?"pm":"am";case"%A":return t?i.getUTCHours()>11?"PM":"AM":i.getHours()>11?"PM":"AM";case"%s":return t?r.date.to_fixed(i.getUTCSeconds()):r.date.to_fixed(i.getSeconds());case"%W":return t?r.date.to_fixed(r.date.getUTCISOWeek(i)):r.date.to_fixed(r.date.getISOWeek(i));case"%w":return r.date.to_fixed(r.date.getWeek(i));default:return n}}),fg=(e,t,r)=>i=>{let n=[0,0,1,0,0,0],o=i.match(/[a-zA-Z]+|[0-9]+/g),a=e.match(/%[a-zA-Z]/g);for(let s=0;s<a.length;s++)switch(a[s]){case"%j":case"%d":n[2]=o[s]||1;break;case"%n":case"%m":n[1]=(o[s]||1)-1;break;case"%y":n[0]=o[s]*1+(o[s]>50?1900:2e3);break;case"%g":case"%G":case"%h":case"%H":n[3]=o[s]||0;break;case"%i":n[4]=o[s]||0;break;case"%Y":n[0]=o[s]||0;break;case"%a":case"%A":n[3]=n[3]%12+((o[s]||"").toLowerCase()==="am"?0:12);break;case"%s":n[5]=o[s]||0;break;case"%M":n[1]=r.locale.date.month_short_hash[o[s]]||0;break;case"%F":n[1]=r.locale.date.month_full_hash[o[s]]||0;break}return t?new Date(Date.UTC(n[0],n[1],n[2],n[3],n[4],n[5])):new Date(n[0],n[1],n[2],n[3],n[4],n[5])},Ed={date_to_str:ug,str_to_date:fg};function Dd(e){var t=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;function r(s){var c=new Date(s);return isNaN(c.getTime())?null:c}var i=null;function n(){try{new Function("canUseCsp = false;")}catch{i=!0}}function o(){var s=!1;return e.config.csp==="auto"?(i===null&&n(),s=i):s=e.config.csp,s}var a={_isoDateDetected:!1,_isoDateOnly:!1,formatISODate:function(s){return s.toISOString()},formatISODateOnly:function(s){return s.getUTCFullYear()+"-"+e.date.to_fixed(s.getUTCMonth()+1)+"-"+e.date.to_fixed(s.getUTCDate())},init:function(){for(var s=e.locale,l=s.date.month_short,d=s.date.month_short_hash={},c=0;c<l.length;c++)d[l[c]]=c;for(var l=s.date.month_full,d=s.date.month_full_hash={},c=0;c<l.length;c++)d[l[c]]=c},date_part:function(s){return s.setUTCHours(0,0,0,0),s},time_part:function(s){return s.valueOf()/1e3%86400},week_start:function(s){var c=s.getUTCDay();return e.config.start_on_monday&&(c===0?c=6:c--),this.date_part(this.add(s,-1*c,"day"))},month_start:function(s){return s.setUTCDate(1),this.date_part(s)},quarter_start:function(s){this.month_start(s);var c=s.getUTCMonth(),l;return c>=9?l=9:c>=6?l=6:c>=3?l=3:l=0,s.setUTCMonth(l),s},year_start:function(s){return s.setUTCMonth(0),this.month_start(s)},day_start:function(s){return this.date_part(s)},hour_start:function(s){return s.getUTCMinutes()&&s.setUTCMinutes(0),this.minute_start(s),s},minute_start:function(s){return s.getUTCSeconds()&&s.setUTCSeconds(0),s.getUTCMilliseconds()&&s.setUTCMilliseconds(0),s},_add_days:function(s,c,l){return s.setUTCDate(s.getUTCDate()+c),s},add:function(s,c,l){var d=new Date(s.valueOf());switch(l){case"day":d=this._add_days(d,c,s);break;case"week":d=this._add_days(d,c*7,s);break;case"month":d.setUTCMonth(d.getUTCMonth()+c);break;case"year":d.setUTCFullYear(d.getUTCFullYear()+c);break;case"hour":d.setTime(d.getTime()+c*60*60*1e3);break;case"minute":d.setTime(d.getTime()+c*60*1e3);break;default:return this["add_"+l](s,c,l)}return d},add_quarter:function(s,c){return this.add(s,c*3,"month")},to_fixed:function(s){return s<10?"0"+s:s},copy:function(s){return new Date(s.valueOf())},date_to_str:function(s,c){var l=Td;return o()&&(l=Ed),l.date_to_str(s,c,e)},str_to_date:function(s,c){var l=Td;return o()&&(l=Ed),l.str_to_date(s,c,e)},getISOWeek:function(s){return e.date._getWeekNumber(s,!0)},_getWeekNumber:function(s,c){if(!s)return!1;var l=s.getUTCDay();c&&l===0&&(l=7);var d=new Date(s.valueOf());d.setUTCDate(s.getUTCDate()+(4-l));var u=d.getUTCFullYear(),f=Math.round((d.getTime()-Date.UTC(u,0,1))/864e5),p=1+Math.floor(f/7);return p},getWeek:function(s){return e.date._getWeekNumber(s,e.config.start_on_monday)},getUTCISOWeek:function(s){return e.date.getISOWeek(s)},parseDate:function(s,c){if(s&&!s.getFullYear){var l=!c||c==="parse_date"||c==="xml_date",d=l&&(e.defined(e.templates.xml_date)||e.templates.parse_date&&!e.templates.parse_date._ganttAuto);if(!d&&typeof s=="string"&&t.test(s)){var u=s.indexOf("T")!==-1,f=r(s);if(f)return a._isoDateDetected?u&&(a._isoDateOnly=!1):(a._isoDateDetected=!0,a._isoDateOnly=!u),f}typeof c!="function"&&(typeof c=="string"?c==="parse_date"||c==="xml_date"?c=e.defined(e.templates.xml_date)?e.templates.xml_date:e.templates.parse_date:c=e.defined(e.templates[c])?e.templates[c]:e.date.str_to_date(c,!0):c=e.defined(e.templates.xml_date)?e.templates.xml_date:e.templates.parse_date),s?s=c(s):s=null}return s}};return a}function pa(e,t,r,i,n){return this.date=e,this.unit=t,this.task=r,this.id=i,this.calendar=n,this}function ya(e,t,r,i,n,o){return this.date=e,this.dir=t,this.unit=r,this.task=i,this.id=n,this.calendar=o,this}function ha(e,t,r,i,n,o,a){return this.start_date=e,this.duration=t,this.unit=r,this.step=i,this.task=n,this.id=o,this.calendar=a,this}function pg(e,t,r,i){return this.start_date=e,this.end_date=t,this.task=r,this.calendar=i,this.unit=null,this.step=null,this}var _d=function(e){return{getWorkHoursArguments:function(){var t=arguments[0];if(Ke(t)?t={date:t}:t=Sr({},t),!je(t.date))throw e.assert(!1,"Invalid date argument for getWorkHours method"),new Error("Invalid date argument for getWorkHours method");return t},setWorkTimeArguments:function(){return arguments[0]},unsetWorkTimeArguments:function(){return arguments[0]},isWorkTimeArguments:function(){var t=arguments[0];if(t instanceof pa)return t;var r;if(t.date?r=new pa(t.date,t.unit,t.task,null,t.calendar):r=new pa(arguments[0],arguments[1],arguments[2],null,arguments[3]),r.unit=r.unit||e.config.duration_unit,!je(r.date))throw e.assert(!1,"Invalid date argument for isWorkTime method"),new Error("Invalid date argument for isWorkTime method");return r},getClosestWorkTimeArguments:function(t){var r=arguments[0];if(r instanceof ya)return r;var i;if(Ke(r)?i=new ya(r):i=new ya(r.date,r.dir,r.unit,r.task,null,r.calendar),r.id&&(i.task=r),i.dir=r.dir||"any",i.unit=r.unit||e.config.duration_unit,!je(i.date))throw e.assert(!1,"Invalid date argument for getClosestWorkTime method"),new Error("Invalid date argument for getClosestWorkTime method");return i},_getStartEndConfig:function(t){var r=pg,i;if(t instanceof r)return t;if(Ke(t)?i=new r(arguments[0],arguments[1],arguments[2],arguments[3]):(i=new r(t.start_date,t.end_date,t.task),t.id!==null&&t.id!==void 0&&(i.task=t)),i.unit=i.unit||e.config.duration_unit,i.step=i.step||e.config.duration_step,i.start_date=i.start_date||i.start||i.date,!je(i.start_date))throw e.assert(!1,"Invalid start_date argument for getDuration method"),new Error("Invalid start_date argument for getDuration method");if(!je(i.end_date))throw e.assert(!1,"Invalid end_date argument for getDuration method"),new Error("Invalid end_date argument for getDuration method");return i},getDurationArguments:function(t,r,i,n){return this._getStartEndConfig.apply(this,arguments)},hasDurationArguments:function(t,r,i,n){return this._getStartEndConfig.apply(this,arguments)},calculateEndDateArguments:function(t,r,i,n){var o=arguments[0];if(o instanceof ha)return o;var a;if(Ke(o)?a=new ha(arguments[0],arguments[1],arguments[2],void 0,arguments[3],void 0,arguments[4]):a=new ha(o.start_date,o.duration,o.unit,o.step,o.task,null,o.calendar),o.id!==null&&o.id!==void 0&&(a.task=o,a.unit=null,a.step=null),a.unit=a.unit||e.config.duration_unit,a.step=a.step||e.config.duration_step,!je(a.start_date))throw e.assert(!1,"Invalid start_date argument for calculateEndDate method"),new Error("Invalid start_date argument for calculateEndDate method");return a}}};function kd(){}kd.prototype={_getIntervals:function(e){for(var t=[],r=0;r<e.length;r+=2)t.push({start:e[r],end:e[r+1]});return t},_toHoursArray:function(e){var t=[];function r(o){var a=String(o);return a.length<2&&(a="0"+a),a}function i(o){var a=Math.floor(o/3600),s=o-a*60*60,c=Math.floor(s/60);return a+":"+r(c)}for(var n=0;n<e.length;n++)t.push(i(e[n].start)+"-"+i(e[n].end));return t},_intersectHourRanges:function(e,t){var n=[],r=e.length>t.length?e:t,i=e===r?t:e;r=r.slice(),i=i.slice();for(var n=[],o=0;o<r.length;o++)for(var a=r[o],s=0;s<i.length;s++){var c=i[s];c.start<a.end&&c.end>a.start&&(n.push({start:Math.max(a.start,c.start),end:Math.min(a.end,c.end)}),a.end>c.end&&(i.splice(s,1),s--,o--))}return n},_mergeAdjacentIntervals:function(e){var t=e.slice();t.sort(function(o,a){return o.start-a.start});for(var r=t[0],i=1;i<t.length;i++){var n=t[i];n.start<=r.end?(n.end>r.end&&(r.end=n.end),t.splice(i,1),i--):r=n}return t},_mergeHoursConfig:function(e,t){return this._mergeAdjacentIntervals(this._intersectHourRanges(e,t))},merge:function(e,t){let r=Jt(e.getConfig()),i=Jt(t.getConfig()),n=r.parsed,o=i.parsed;n.customWeeks=r.customWeeks,o.customWeeks=i.customWeeks;var a={hours:this._toHoursArray(this._mergeHoursConfig(n.hours,o.hours)),dates:{},customWeeks:{}};let s=(l,d)=>{for(let u in l.dates){let f=l.dates[u];+u>1e3&&(a.dates[u]=!1);for(let p in d.dates){let y=d.dates[p];if(p==u&&(a.dates[u]=!!(f&&y)),Array.isArray(f)){let g=Array.isArray(y)?y:d.hours;a.dates[u]=this._toHoursArray(this._mergeHoursConfig(f,g))}}}};if(s(n,o),s(o,n),n.customWeeks)for(var c in n.customWeeks)a.customWeeks[c]=n.customWeeks[c];if(o.customWeeks)for(var c in o.customWeeks)a.customWeeks[c]?a.customWeeks[c+"_second"]=o.customWeeks[c]:a.customWeeks[c]=o.customWeeks[c];return a}};var ma=class{constructor(){this.clear()}getItem(t,r,i){if(this._cache.has(t)){let o=this._cache.get(t)[i.getUTCFullYear()];if(o&&o.has(r))return o.get(r)}return-1}setItem(t,r,i,n){if(!t||!r)return;let o=this._cache,a=n.getUTCFullYear(),s;o.has(t)?s=o.get(t):(s=[],o.set(t,s));let c=s[a];c||(c=s[a]=new Map),c.set(r,i)}clear(){this._cache=new Map}},Ia=class{constructor(){this.clear()}getItem(t,r,i){let n=this._cache;if(n&&n[t]){let o=n[t];if(o===void 0)return-1;let a=o[i.getUTCFullYear()];if(a&&a[r]!==void 0)return a[r]}return-1}setItem(t,r,i,n){if(!t||!r)return;let o=this._cache;if(!o)return;o[t]||(o[t]=[]);let a=o[t],s=n.getUTCFullYear(),c=a[s];c||(c=a[s]={}),c[r]=i}clear(){this._cache={}}},ga=class{constructor(t){this.getMinutesPerWeek=r=>{let i=r.valueOf();if(this._weekCache.has(i))return this._weekCache.get(i);let n=this._calendar,o=this._calendar.$gantt,a=0,s=o.date.week_start(new Date(r));for(let c=0;c<7;c++)a+=n.getHoursPerDay(s)*60,s=o.date.add(s,1,"day");return this._weekCache.set(i,a),a},this.getMinutesPerMonth=r=>{let i=r.valueOf();if(this._monthCache.has(i))return this._monthCache.get(i);let n=this._calendar,o=this._calendar.$gantt,a=0,s=o.date.week_start(new Date(r)),c=o.date.add(s,1,"month").valueOf();for(;s.valueOf()<c;)a+=n.getHoursPerDay(s)*60,s=o.date.add(s,1,"day");return this._monthCache.set(i,a),a},this.clear=()=>{this._weekCache=new Map,this._monthCache=new Map},this.clear(),this._calendar=t}};function yg(){return typeof Map<"u"?new ma:new Ia}var Aa=class{constructor(){this.clear()}_getCacheObject(t,r,i){let n=this._cache;n[r]||(n[r]=[]);let o=n[r];o||(o=n[r]={});let a=o[i];a||(a=o[i]={});let s=t.getUTCFullYear(),c=a[s];return c||(c=a[s]={durations:{},endDates:{}}),c}_endDateCacheKey(t,r){return String(t)+"-"+String(r)}_durationCacheKey(t,r){return String(t)+"-"+String(r)}getEndDate(t,r,i,n,o){let a=this._getCacheObject(t,i,n),s=t.valueOf(),c=this._endDateCacheKey(s,r),l;if(a.endDates[c]===void 0){let d=o(),u=d.valueOf();a.endDates[c]=u,a.durations[this._durationCacheKey(s,u)]=r,l=d}else l=new Date(a.endDates[c]);return l}getDuration(t,r,i,n,o){let a=this._getCacheObject(t,i,n),s=t.valueOf(),c=r.valueOf(),l=this._durationCacheKey(s,c),d;if(a.durations[l]===void 0){let u=o();a.durations[l]=u.valueOf(),d=u}else d=a.durations[l];return d}clear(){this._cache={}}};function va(e,t){this.argumentsHelper=t,this.$gantt=e,this._workingUnitsCache=yg(),this._largeUnitsCache=new ga(this),this._dateDurationCache=new Aa,this._worktime=null,this._cached_timestamps={},this._cached_timestamps_count=0}va.prototype={units:["year","month","week","day","hour","minute"],_clearCaches:function(){this._workingUnitsCache.clear(),this._largeUnitsCache.clear(),this._dateDurationCache.clear()},_getUnitOrder:function(e){for(var t=0,r=this.units.length;t<r;t++)if(this.units[t]==e)return t},_resetTimestampCache:function(){this._cached_timestamps={},this._cached_timestamps_count=0},_timestamp:function(e){this._cached_timestamps_count>1e6&&this._resetTimestampCache();var t=null;if(e.day||e.day===0)t=e.day;else if(e.date){var r=String(e.date.valueOf());this._cached_timestamps[r]?t=this._cached_timestamps[r]:(t=Date.UTC(e.date.getUTCFullYear(),e.date.getUTCMonth(),e.date.getUTCDate()),this._cached_timestamps[r]=t,this._cached_timestamps_count++)}return t},_checkIfWorkingUnit:function(e,t){if(!this["_is_work_"+t]){let r=this.$gantt.date[`${t}_start`](new Date(e)),i=this.$gantt.date.add(r,1,t);return this.hasDuration(r,i)}return this["_is_work_"+t](e)},_is_work_day:function(e){var t=this._getWorkHours(e);return Array.isArray(t)?t.length>0:!1},_is_work_hour:function(e){for(var t=this._getWorkHours(e),r=e.getUTCHours(),i=0;i<t.length;i++)if(r>=t[i].startHour&&r<t[i].endHour)return!0;return!1},_getTimeOfDayStamp:function(e,t){var r=e.getUTCHours();return!e.getUTCHours()&&!e.getUTCMinutes()&&t&&(r=24),r*60*60+e.getUTCMinutes()*60},_is_work_minute:function(e){for(var t=this._getWorkHours(e),r=this._getTimeOfDayStamp(e),i=0;i<t.length;i++)if(r>=t[i].start&&r<t[i].end)return!0;return!1},_nextDate:function(e,t,r){return this.$gantt.date.add(e,r,t)},_getWorkUnitsBetweenGeneric:function(e,t,r,i){var n=this.$gantt.date,o=new Date(e),a=new Date(t);i=i||1;var s=0,c=null,l,d,u=!1;l=n[r+"_start"](new Date(o)),l.valueOf()!=o.valueOf()&&(u=!0);var f=!1;d=n[r+"_start"](new Date(t)),d.valueOf()!=t.valueOf()&&(f=!0);for(var p=!1;o.valueOf()<a.valueOf();){if(c=this._nextDate(o,r,i),p=c.valueOf()>a.valueOf(),this._isWorkTime(o,r))(u||f&&p)&&(l=n[r+"_start"](new Date(o)),d=n.add(l,i,r)),u?(u=!1,c=this._nextDate(l,r,i),s+=(d.valueOf()-o.valueOf())/(d.valueOf()-l.valueOf())):f&&p?(f=!1,s+=(a.valueOf()-o.valueOf())/(d.valueOf()-l.valueOf())):s++;else{var y=this._getUnitOrder(r),g=this.units[y-1];g&&!this._isWorkTime(o,g)&&(c=this._getClosestWorkTimeFuture(o,g))}o=c}return s},_getMinutesPerHour:function(e){var t=this._getTimeOfDayStamp(e),r=this._getTimeOfDayStamp(this._nextDate(e,"hour",1));r===0&&(r=1440*60);for(var i=this._getWorkHours(e),n=0;n<i.length;n++){var o=i[n];if(t>=o.start&&r<=o.end)return 60;if(t<o.end&&r>o.start){var a=Math.min(r,o.end)-Math.max(t,o.start);return a/60}}return 0},_getMinutesPerDay:function(e){var t=this._getWorkHours(e),r=0;return t.forEach(function(i){r+=i.durationMinutes}),r},getHoursPerDay:function(e){var t=this._getWorkHours(e),r=0;return t.forEach(function(i){r+=i.durationHours}),r},_getWorkUnitsForRange:function(e,t,r,i){var n=0,o=new Date(e),a=new Date(t),s;for(r=="minute"?s=Bt(this._getMinutesPerDay,this):s=Bt(this.getHoursPerDay,this);o.valueOf()<a.valueOf();){if(a-o>1e3*60*60*24*32&&o.getUTCDate()===0){var c=this._largeUnitsCache.getMinutesPerMonth(o);r=="hour"&&(c=c/60),n+=c,o=this.$gantt.date.add(o,1,"month");continue}else if(a-o>1e3*60*60*24*16){var l=this.$gantt.date.week_start(new Date(o));if(o.valueOf()===l.valueOf()){var c=this._largeUnitsCache.getMinutesPerWeek(o);r=="hour"&&(c=c/60),n+=c,o=this.$gantt.date.add(o,7,"day");continue}}n+=s(o),o=this._nextDate(o,"day",1)}return n/i},_getMinutesBetweenSingleDay:function(e,t){for(var r=this._getIntervalTimestamp(e,t),i=this._getWorkHours(e),n=0,o=0;o<i.length;o++){var a=i[o];if(r.end>=a.start&&r.start<=a.end){var s=Math.max(a.start,r.start),c=Math.min(a.end,r.end);n+=(c-s)/60,r.start=c}}return Math.floor(n)},_getMinutesBetween:function(e,t,r,i){var n=new Date(e),o=new Date(t);i=i||1;var a=new Date(n),s=this.$gantt.date.add(this.$gantt.date.day_start(new Date(n)),1,"day");if(o.valueOf()<=s.valueOf())return this._getMinutesBetweenSingleDay(e,t);var c=this.$gantt.date.day_start(new Date(o)),l=o,d=this._getMinutesBetweenSingleDay(a,s),u=this._getMinutesBetweenSingleDay(c,l),f=this._getWorkUnitsForRange(s,c,r,i),p=d+f+u;return p},_getHoursBetween:function(e,t,r,i){var n=new Date(e),o=new Date(t);i=i||1;var a=new Date(n),s=this.$gantt.date.add(this.$gantt.date.day_start(new Date(n)),1,"day");if(o.valueOf()<=s.valueOf())return Math.round(this._getMinutesBetweenSingleDay(e,t)/60);var c=this.$gantt.date.day_start(new Date(o)),l=o,d=this._getMinutesBetweenSingleDay(a,s,r,i)/60,u=this._getMinutesBetweenSingleDay(c,l,r,i)/60,f=this._getWorkUnitsForRange(s,c,r,i),p=d+f+u;return Math.round(p)},getConfig:function(){return this._worktime},_setConfig:function(e){this._worktime=e,this._parseSettings(),this._clearCaches()},_parseSettings:function(){var e=this.getConfig();e.parsed={dates:{},hours:null,haveCustomWeeks:!1,customWeeks:{},customWeeksRangeStart:null,customWeeksRangeEnd:null,customWeeksBoundaries:[]},e.parsed.hours=this._parseHours(e.hours);for(var t in e.dates)e.parsed.dates[t]=this._parseHours(e.dates[t]);if(e.customWeeks){var r=null,i=null;for(var t in e.customWeeks){var n=e.customWeeks[t];if(n.from&&n.to){var o=n.from,a=n.to;(!r||r>o.valueOf())&&(r=o.valueOf()),(!i||i<a.valueOf())&&(i=a.valueOf()),e.parsed.customWeeksBoundaries.push({from:o.valueOf(),fromReadable:new Date(o),to:a.valueOf(),toReadable:new Date(a),name:t}),e.parsed.haveCustomWeeks=!0;var s=e.parsed.customWeeks[t]={from:n.from,to:n.to,hours:this._parseHours(n.hours),dates:{}};if(n.days&&!n.dates){n.dates=n.dates||{};for(var t=0;t<n.days.length;t++)n.dates[t]=n.days[t],n.days[t]instanceof Array||(n.dates[t]=!!n.days[t]);delete n.days}for(var c in n.dates)s.dates[c]=this._parseHours(n.dates[c])}}e.parsed.customWeeksRangeStart=r,e.parsed.customWeeksRangeEnd=i}},_tryChangeCalendarSettings:function(e){var t=JSON.stringify(this.getConfig());return e(),this.hasWorkTime()?!0:(this._setConfig(JSON.parse(t)),this._clearCaches(),!1)},_arraysEqual:function(e,t){if(e===t)return!0;if(!e||!t||e.length!=t.length)return!1;for(var r=0;r<e.length;++r)if(e[r]!==t[r])return!1;return!0},_compareSettings:function(e,t){if(!this._arraysEqual(e.hours,t.hours))return!1;var r=Object.keys(e.dates),i=Object.keys(t.dates);if(r.sort(),i.sort(),!this._arraysEqual(r,i))return!1;for(var n=0;n<r.length;n++){var o=r[n],a=e.dates[o],s=t.dates[o];if(a!==s&&!(Array.isArray(a)&&Array.isArray(s)&&this._arraysEqual(a,s)))return!1}return!0},equals:function(e){if(!(e instanceof va))return!1;var t=this.getConfig(),r=e.getConfig();if(!this._compareSettings(t,r))return!1;if(t.parsed.haveCustomWeeks&&r.parsed.haveCustomWeeks){if(t.parsed.customWeeksBoundaries.length!=r.parsed.customWeeksBoundaries.length)return!1;for(var i in t.parsed.customWeeks){var n=t.parsed.customWeeks[i],o=r.parsed.customWeeks[i];if(!o||!this._compareSettings(n,o))return!1}}else if(t.parse.haveCustomWeeks!==r.parsed.haveCustomWeeks)return!1;return!0},getWorkHours:function(){var e=this.argumentsHelper.getWorkHoursArguments.apply(this.argumentsHelper,arguments);return this._getWorkHours(e.date,!1)},_getWorkHours:function(e,t){var r=this.getConfig();if(t!==!1&&(r=r.parsed),!e)return r.hours;let i=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate()));var n=this._timestamp({date:i});if(r.haveCustomWeeks&&r.customWeeksRangeStart<=n&&r.customWeeksRangeEnd>n){for(var o=0;o<r.customWeeksBoundaries.length;o++)if(r.customWeeksBoundaries[o].from<=n&&r.customWeeksBoundaries[o].to>n){r=r.customWeeks[r.customWeeksBoundaries[o].name];break}}var a=!0;return r.dates[n]!==void 0?a=r.dates[n]:r.dates[e.getUTCDay()]!==void 0&&(a=r.dates[e.getUTCDay()]),a===!0?r.hours:a||[]},_getIntervalTimestamp:function(e,t){var r={start:0,end:0};r.start=e.getUTCHours()*60*60+e.getUTCMinutes()*60+e.getUTCSeconds();var i=t.getUTCHours();return!i&&!t.getUTCMinutes()&&!t.getUTCSeconds()&&e.valueOf()<t.valueOf()&&(i=24),r.end=i*60*60+t.getUTCMinutes()*60+t.getUTCSeconds(),r},_parseHours:function(e){if(Array.isArray(e)){var t=[];e.forEach(function(s){typeof s=="number"?t.push(s*60*60):typeof s=="string"&&s.split("-").map(function(c){return c.trim()}).forEach(function(c){var l=c.split(":").map(function(u){return u.trim()}),d=parseInt(l[0]*60*60);l[1]&&(d+=parseInt(l[1]*60)),l[2]&&(d+=parseInt(l[2])),t.push(d)})});for(var r=[],i=0;i<t.length;i+=2){var n=t[i],o=t[i+1],a=o-n;r.push({start:n,end:o,startHour:Math.floor(n/3600),startMinute:Math.floor(n/60),endHour:Math.ceil(o/3600),endMinute:Math.ceil(o/60),durationSeconds:a,durationMinutes:a/60,durationHours:a/3600})}return r}else return e},setWorkTime:function(e){return this._tryChangeCalendarSettings(Bt(function(){var t=e.hours!==void 0?e.hours:!0,r=this._timestamp(e),i=this.getConfig();if(r!==null?i.dates[r]=t:e.customWeeks||(i.hours=t),e.customWeeks){if(i.customWeeks||(i.customWeeks={}),typeof e.customWeeks=="string")r!==null?i.customWeeks[e.customWeeks].dates[r]=t:e.customWeeks||(i.customWeeks[e.customWeeks].hours=t);else if(typeof e.customWeeks=="object"&&e.customWeeks.constructor===Object)for(var n in e.customWeeks)i.customWeeks[n]=e.customWeeks[n]}this._parseSettings(),this._clearCaches()},this))},unsetWorkTime:function(e){return this._tryChangeCalendarSettings(Bt(function(){if(!e)this.reset_calendar();else{var t=this._timestamp(e);t!==null&&delete this.getConfig().dates[t]}this._parseSettings(),this._clearCaches()},this))},_isWorkTime:function(e,t){var r=-1,i=null;return i=String(e.valueOf()),r=this._workingUnitsCache.getItem(t,i,e),r==-1&&(r=this._checkIfWorkingUnit(e,t),this._workingUnitsCache.setItem(t,i,r,e)),r},isWorkTime:function(){var e=this.argumentsHelper.isWorkTimeArguments.apply(this.argumentsHelper,arguments);return this._isWorkTime(e.date,e.unit)},calculateDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments);if(!e.unit)return!1;var t=this;return this._dateDurationCache.getDuration(e.start_date,e.end_date,e.unit,e.step,function(){return t._calculateDuration(e.start_date,e.end_date,e.unit,e.step)})},_calculateDuration:function(e,t,r,i){var n=0,o=1;if(e.valueOf()>t.valueOf()){var a=t;t=e,e=a,o=-1}return r=="hour"&&i==1?n=this._getHoursBetween(e,t,r,i):r=="minute"&&i==1?n=this._getMinutesBetween(e,t,r,i):n=this._getWorkUnitsBetweenGeneric(e,t,r,i),o*Math.round(n)},hasDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.end_date,i=e.unit,n=e.step;if(!i)return!1;var o=new Date(t),a=new Date(r);for(n=n||1;o.valueOf()<a.valueOf();){if(this._isWorkTime(o,i))return!0;o=this._nextDate(o,i,n)}return!1},calculateEndDate:function(){var e=this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.duration,i=e.unit,n=e.step;if(!i)return!1;var o=e.duration>=0?1:-1;r=Math.abs(r*1);var a=this;return this._dateDurationCache.getEndDate(t,r,i,n*o,function(){return a._calculateEndDate(t,r,i,n*o)})},_calculateEndDate:function(e,t,r,i){if(!r)return!1;if(i==1&&r=="minute")return this._calculateMinuteEndDate(e,t,i);if(i==-1&&r=="minute")return this._subtractMinuteDate(e,t,i);if(i==1&&r=="hour")return this._calculateHourEndDate(e,t,i);var n=this._addInterval(e,t,r,i,null);return n.end},_addInterval:function(e,t,r,i,n){for(var o=0,a=e;o<t&&!(n&&n(a));){var s=this._nextDate(a,r,i),c=new Date(s.valueOf()+1);i>0&&(c=new Date(s.valueOf()-1));var l=this._isWorkTime(c,r);l&&o++,a=s}return{end:a,start:e,added:o}},_addHoursUntilDayEnd:function(e,t){for(var r=this.$gantt.date.add(this.$gantt.date.day_start(new Date(e)),1,"day"),i=0,n=t,o=this._getIntervalTimestamp(e,r),a=this._getWorkHours(e),s=0;s<a.length&&i<t;s++){var c=a[s];if(o.end>=c.start&&o.start<=c.end){var l=Math.max(c.start,o.start),d=Math.min(c.end,o.end),u=(d-l)/3600;u>n&&(u=n,d=l+n*60*60);var f=Math.round((d-l)/3600);i+=f,n-=f,o.start=d}}var p=r;return i===t&&(p=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),0,0,o.start))),{added:i,end:p}},_calculateHourEndDate:function(e,t,r){var i=new Date(e),n=0;r=r||1,t=Math.abs(t*1);var o=this._addHoursUntilDayEnd(i,t);n=o.added,i=o.end;var a=t-n;if(a){for(var s=i;n<t;){var c=this._nextDate(s,"day",r);c.setUTCHours(0),c.setUTCMinutes(0),c.setUTCSeconds(0);var l=0;if(r>0?l=this.getHoursPerDay(new Date(c.valueOf()-1)):l=this.getHoursPerDay(new Date(c.valueOf()+1)),n+l>=t)break;n+=l,s=c}i=s}if(n<t){var a=t-n;o=this._addHoursUntilDayEnd(i,a),i=o.end}return i},_addMinutesUntilHourEnd:function(e,t){if(e.getUTCMinutes()===0)return{added:0,end:new Date(e)};for(var r=this.$gantt.date.add(this.$gantt.date.hour_start(new Date(e)),1,"hour"),i=0,n=t,o=this._getIntervalTimestamp(e,r),a=this._getWorkHours(e),s=0;s<a.length&&i<t;s++){var c=a[s];if(o.end>=c.start&&o.start<=c.end){var l=Math.max(c.start,o.start),d=Math.min(c.end,o.end),u=(d-l)/60;u>n&&(u=n,d=l+n*60);var f=Math.round((d-l)/60);n-=f,i+=f,o.start=d}}var p=r;return i===t&&(p=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),0,0,o.start))),{added:i,end:p}},_subtractMinutesUntilHourStart:function(e,t){for(var r=this.$gantt.date.hour_start(new Date(e)),i=0,n=t,o=r.getUTCHours()*60*60+r.getUTCMinutes()*60+r.getUTCSeconds(),a=e.getUTCHours()*60*60+e.getUTCMinutes()*60+e.getUTCSeconds(),s=this._getWorkHours(e),c=s.length-1;c>=0&&i<t;c--){var l=s[c];if(a>l.start&&o<=l.end){var d=Math.min(a,l.end),u=Math.max(o,l.start),f=(d-u)/60;f>n&&(f=n,u=d-n*60);var p=Math.abs(Math.round((d-u)/60));n-=p,i+=p,a=u}}var y=r;return i===t&&(y=new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),0,0,a))),{added:i,end:y}},_subtractMinuteDate:function(e,t,r){var i=this.getClosestWorkTime({date:e,dir:"past",unit:"minute"}),n=0;r=r||-1,t=Math.abs(t*1),t=Math.round(t);let o=this._isMinutePrecision(i),a=this._subtractMinutesUntilHourStart(i,t);n+=a.added,i=a.end;for(var s=0,c=[],l=0;n<t;){var d=this.$gantt.date.day_start(new Date(i)),u=!1;i.valueOf()===d.valueOf()&&(d=this.$gantt.date.add(d,-1,"day"),u=!0);var f=new Date(Date.UTC(d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate(),23,59,59,999)).valueOf();f!==s&&(c=this._getWorkHours(d),l=this._getMinutesPerDay(d),s=f);var p=t-n,y=this._getTimeOfDayStamp(i,u);if(!c.length||!l){i=this.$gantt.date.add(i,-1,"day");continue}if(c[c.length-1].end<=y&&p>l){n+=l,i=this.$gantt.date.add(i,-1,"day");continue}for(var g=!1,C=null,L=null,T=c.length-1;T>=0;T--)if(c[T].start<y-1&&c[T].end>=y-1){g=!0,C=c[T],L=c[T-1];break}if(g)if(y===C.end&&p>=C.durationMinutes)n+=C.durationMinutes,i=this.$gantt.date.add(i,-C.durationMinutes,"minute");else if(!o&&p<=y/60-C.startMinute)n+=p,i=this.$gantt.date.add(i,-p,"minute");else if(o)p<=y/60-C.startMinute?(n+=p,i=this.$gantt.date.add(i,-p,"minute")):(n+=y/60-C.startMinute,L?i=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,L.end)):i=this.$gantt.date.day_start(i));else{var E=this._getMinutesPerHour(i);E<=p?(n+=E,i=this._nextDate(i,"hour",r)):(a=this._subtractMinutesUntilHourStart(i,p),n+=a.added,i=a.end)}else if(i.getUTCHours()===0&&i.getUTCMinutes()===0&&i.getUTCSeconds()===0){var I=this._getClosestWorkTimePast(i,"hour");if(I.valueOf()===i.valueOf()){var I=this.$gantt.date.add(i,-1,"day"),b=this._getWorkHours(I);if(b.length){var B=b[b.length-1];I.setUTCSeconds(B.durationSeconds)}}i=I}else i=this._getClosestWorkTimePast(new Date(i-1),"hour")}if(n<t){var k=t-n;a=this._subtractMinutesUntilHourStart(i,k),n+=a.added,i=a.end}return i},_calculateMinuteEndDate:function(e,t,r){var i=new Date(e),n=0;r=r||1,t=Math.abs(t*1),t=Math.round(t);var o=this._addMinutesUntilHourEnd(i,t);n+=o.added,i=o.end;for(var a=0,s=[],c=0,l=this._isMinutePrecision(i);n<t;){var d=this.$gantt.date.day_start(new Date(i)).valueOf();d!==a&&(s=this._getWorkHours(i),c=this._getMinutesPerDay(i),a=d);var u=t-n,f=this._getTimeOfDayStamp(i);if(!s.length||!c){i=this.$gantt.date.add(this.$gantt.date.day_start(i),1,"day");continue}if(s[0].start>=f&&u>=c){if(n+=c,u==c){i=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,s[s.length-1].end));break}else i=this.$gantt.date.add(i,1,"day"),i=this.$gantt.date.day_start(i);continue}for(var p=!1,y=null,g=0;g<s.length;g++)if(s[g].start<=f&&s[g].end>f){p=!0,y=s[g];break}if(p)if(f===y.start&&u>=y.durationMinutes)n+=y.durationMinutes,i=this.$gantt.date.add(i,y.durationMinutes,"minute");else if(u<=y.endMinute-f/60)n+=u,i=this.$gantt.date.add(i,u,"minute");else{var C=this._getMinutesPerHour(i);C<=u?(n+=C,l?i=this.$gantt.date.add(i,C,"minute"):i=this._nextDate(i,"hour",r)):(o=this._addMinutesUntilHourEnd(i,u),n+=o.added,i=o.end)}else i=this._getClosestWorkTimeFuture(i,"hour")}if(n<t){var L=t-n;o=this._addMinutesUntilHourEnd(i,L),n+=o.added,i=o.end}return i},getClosestWorkTime:function(){var e=this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper,arguments);return this._getClosestWorkTime(e.date,e.unit,e.dir)},_getClosestWorkTime:function(e,t,r){var i=new Date(e);if(this._isWorkTime(i,t))return i;if(i=this.$gantt.date[t+"_start"](i),r=="any"||!r){var n=this._getClosestWorkTimeFuture(i,t),o=this._getClosestWorkTimePast(i,t);Math.abs(n-e)<=Math.abs(e-o)?i=n:i=o}else r=="past"?i=this._getClosestWorkTimePast(i,t):i=this._getClosestWorkTimeFuture(i,t);return i},_getClosestWorkTimeFuture:function(e,t){return this._getClosestWorkTimeGeneric(e,t,1)},_getClosestWorkTimePast:function(e,t){var r=this._getClosestWorkTimeGeneric(e,t,-1);return this.$gantt.date.add(r,1,t)},_findClosestTimeInDay:function(e,t,r){var i=new Date(e),n=null,o=!1;this._getWorkHours(i).length||(i=this._getClosestWorkTime(i,"day",t<0?"past":"future"),t<0&&(i=new Date(i.valueOf()-1),o=!0),r=this._getWorkHours(i));var a=this._getTimeOfDayStamp(i);if(o&&(a=this._getTimeOfDayStamp(new Date(i.valueOf()+1),o)),t>0){for(var s=0;s<r.length;s++)if(r[s].start>=a){n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,r[s].start));break}}else for(var s=r.length-1;s>=0;s--)if(r[s].end<=a){n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,r[s].end));break}else if(r[s].end>a&&r[s].start<=a){n=new Date(Date.UTC(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate(),0,0,a));break}return n},_getClosestWorkMinute:function(e,t,r){var i=new Date(e),n=this._getWorkHours(i),o=this._findClosestTimeInDay(i,r,n);return o||(r>0?(i=this.calculateEndDate(i,r,t),i=this.$gantt.date.day_start(i)):(i=this.calculateEndDate(i,r,"day"),i=this.$gantt.date.day_start(i),i=this.$gantt.date.add(i,1,"day"),i=new Date(i.valueOf()-1)),n=this._getWorkHours(i),o=this._findClosestTimeInDay(i,r,n)),r<0&&(o=this.$gantt.date.add(o,-1,t)),o},_getClosestWorkTimeGeneric:function(e,t,r){if(t==="hour"||t==="minute")return this._getClosestWorkMinute(e,t,r);for(var i=this._getUnitOrder(t),n=this.units[i-1],o=e,a=3e3,s=0;!this._isWorkTime(o,t)&&!(n&&!this._isWorkTime(o,n)&&(r>0?o=this._getClosestWorkTimeFuture(o,n):o=this._getClosestWorkTimePast(o,n),this._isWorkTime(o,t)));){if(s++,s>a)return this.$gantt.assert(!1,"Invalid working time check"),!1;o=this.$gantt.date.add(o,r,t),this.$gantt.date[t+"_start"]&&(o=this.$gantt.date[t+"_start"](o))}return o},hasWorkTime:function(){var e=this.getConfig(),t=e.dates,r=[0,1,2,3,4,5,6];for(var i in e.dates);var n=this._checkWorkHours(e.hours),o=!1;return r.forEach((function(a){if(!o){var s=t[a];s===!0?o=n:Array.isArray(s)&&(o=this._checkWorkHours(s))}}).bind(this)),o},_checkWorkHours:function(e){if(e.length===0)return!1;for(var t=!1,r=0;r<e.length;r+=2)e[r]!==e[r+1]&&(t=!0);return t},_isMinutePrecision:function(e){let t=!1;return this._getWorkHours(e).forEach(function(r){(r.startMinute%60||r.endMinute%60)&&(t=!0)}),t}};var Qr={isLegacyResourceCalendarFormat:function(e){if(!e)return!1;for(var t in e)if(e[t]&&typeof e[t]=="object")return!0;return!1},getResourceProperty:function(e){var t=e.resource_calendars,r=e.resource_property;if(this.isLegacyResourceCalendarFormat(t))for(var i in e){r=i;break}return r},getCalendarIdFromLegacyConfig:function(e,t){if(t)for(var r in t){var i=t[r];if(e[r]){var n=i[e[r]];if(n)return n}}return null}};function hg(){function e(n){return n.map(function(o){return o&&o.resource_id?o.resource_id:o}).sort().join("-")}var t={};function r(n,o){return o.mergeCalendars(n.map(function(a){var s=a&&a.resource_id?a.resource_id:a;return o.getResourceCalendar(s)}))}function i(n,o){var a=e(n);if(n.length){if(n.length===1)return o.getResourceCalendar(a).id;if(t[a])return t[a].id;var s=r(n,o);return t[a]=s,o.addCalendar(s)}else return null}return{getCalendarIdFromMultipleResources:i}}var mg=hg();function Rd(e){this.$gantt=e,this._calendars={},this._legacyConfig=void 0,this.$gantt.attachEvent("onGanttReady",(function(){this.$gantt.config.resource_calendars&&(this._isLegacyConfig=Qr.isLegacyResourceCalendarFormat(this.$gantt.config.resource_calendars))}).bind(this)),this.$gantt.attachEvent("onBeforeGanttReady",(function(){this.createDefaultCalendars()}).bind(this)),this.$gantt.attachEvent("onBeforeGanttRender",(function(){this.createDefaultCalendars()}).bind(this))}Rd.prototype={_calendars:{},_convertWorkTimeSettings:function(e){let t=e.days;if(typeof t=="object"&&!Array.isArray(t)&&t!==null){let r={};if(t?.weekdays)for(let i=0;i<7;i++)r[i]=t.weekdays[i];t?.dates&&Object.entries(t.dates).forEach(([i,n])=>{r[new Date(i).valueOf()]=n}),Object.entries(r).forEach(([i,n])=>{n instanceof Array||(r[i]=!!n)}),e={...e,dates:r}}else if(t&&!e.dates){e.dates=e.dates||{};for(let r=0;r<t.length;r++)e.dates[r]=t[r],t[r]instanceof Array||(e.dates[r]=!!t[r])}return delete e.days,e},mergeCalendars:function(){var e=[],t=arguments;if(Array.isArray(t[0]))e=t[0].slice();else for(var r=0;r<arguments.length;r++)e.push(arguments[r]);var i=new kd,n;return e.forEach((function(o){n?n=this._createCalendarFromConfig(i.merge(n,o)):n=o}).bind(this)),this.createCalendar(n)},_createCalendarFromConfig:function(e){var t=new va(this.$gantt,_d(this.$gantt));t.id=String(fa());var r=this._convertWorkTimeSettings(e);if(r.customWeeks)for(var i in r.customWeeks)r.customWeeks[i]=this._convertWorkTimeSettings(r.customWeeks[i]);return t._setConfig(r),t},createCalendar:function(e){var t;e||(e={}),e.getConfig?t=Jt(e.getConfig()):e.worktime?t=Jt(e.worktime):t=Jt(e);var r=Jt(this.defaults.fulltime.worktime);return Sr(t,r),this._createCalendarFromConfig(t)},getCalendar:function(e){e=e||"global";var t=this._calendars[e];return t||(this.createDefaultCalendars(),t=this._calendars[e]),t},getCalendars:function(){var e=[];for(var t in this._calendars)e.push(this.getCalendar(t));return e},_getOwnCalendar:function(e){var t=this.$gantt.config;if(e[t.calendar_property])return this.getCalendar(e[t.calendar_property]);if(t.resource_calendars){var r,i,n;if(this._legacyConfig===!1?n=t.resource_property:n=Qr.getResourceProperty(t),Array.isArray(e[n])&&e[n].length)t.dynamic_resource_calendars?i=mg.getCalendarIdFromMultipleResources(e[n],this):r=this.getResourceCalendar(e[n]);else if(this._legacyConfig===void 0&&(this._legacyConfig=Qr.isLegacyResourceCalendarFormat(t.resource_calendars)),this._legacyConfig)var i=Qr.getCalendarIdFromLegacyConfig(e,t.resource_calendars);else if(n&&e[n]&&t.resource_calendars[e[n]])var r=this.getResourceCalendar(e[n]);if(i&&(r=this.getCalendar(i)),r)return r}return null},getResourceCalendar:function(e){if(e==null)return this.getCalendar();var t=null;typeof e=="number"||typeof e=="string"?t=e:t=e.id||e.key;var r=this.$gantt.config,i=r.resource_calendars,n=null;if(Array.isArray(e)&&e.length===1&&(typeof e[0]=="object"?t=e[0].resource_id:t=e[0]),i){if(this._legacyConfig===void 0&&(this._legacyConfig=Qr.isLegacyResourceCalendarFormat(r.resource_calendars)),this._legacyConfig){for(var o in i)if(i[o][t]){n=i[o][t];break}}else var n=i[t];if(n)return this.getCalendar(n)}return this.getCalendar()},getTaskCalendar:function(e){var t=this.$gantt,r;if(e==null)return this.getCalendar();if((typeof e=="number"||typeof e=="string")&&t.isTaskExists(e)?r=t.getTask(e):r=e,!r)return this.getCalendar();var i=this._getOwnCalendar(r),n=!!t.getState().group_mode;if(!i&&t.config.inherit_calendar&&t.isTaskExists(r.parent)){for(var o=r;t.isTaskExists(o.parent)&&(o=t.getTask(o.parent),!(t.isSummaryTask(o)&&(i=this._getOwnCalendar(o),i))););n&&!i&&e.$effective_calendar&&(i=this.getCalendar(e.$effective_calendar))}return i||this.getCalendar()},addCalendar:function(e){if(!this.isCalendar(e)){var t=e.id;e=this.createCalendar(e),e.id=t}if(e._tryChangeCalendarSettings(function(){})){var r=this.$gantt.config;return e.id=e.id||fa(),this._calendars[e.id]=e,r.worktimes||(r.worktimes={}),r.worktimes[e.id]=e.getConfig(),e.id}else return this.$gantt.callEvent("onCalendarError",[{message:"Invalid calendar settings, no worktime available"},e]),null},deleteCalendar:function(e){var t=this.$gantt.config;return e&&this._calendars[e]?(delete this._calendars[e],t.worktimes&&t.worktimes[e]&&delete t.worktimes[e],!0):!1},restoreConfigCalendars:function(e){for(var t in e)if(!this._calendars[t]){var r=e[t],i=this.createCalendar(r);i.id=t,this.addCalendar(i)}},defaults:{global:{id:"global",worktime:{hours:[8,12,13,17],days:[0,1,1,1,1,1,0]}},fulltime:{id:"fulltime",worktime:{hours:[0,24],days:[1,1,1,1,1,1,1]}}},createDefaultCalendars:function(){var e=this.$gantt.config;this.restoreConfigCalendars(this.defaults),this.restoreConfigCalendars(e.worktimes)},isCalendar:function(e){var t=[e.isWorkTime,e.setWorkTime,e.getWorkHours,e.unsetWorkTime,e.getClosestWorkTime,e.calculateDuration,e.hasDuration,e.calculateEndDate];return t.every(function(r){return r instanceof Function})}};function Ca(e,t){this.argumentsHelper=t,this.$gantt=e}Ca.prototype={getWorkHours:function(){return[0,24]},setWorkTime:function(){return!0},unsetWorkTime:function(){return!0},isWorkTime:function(){return!0},getClosestWorkTime:function(t){var t=this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper,arguments);return t.date},calculateDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.end_date,i=e.unit,n=e.step;return this._calculateDuration(t,r,i,n)},_calculateDuration:function(e,t,r,i){var n=this.$gantt.date,o={week:1e3*60*60*24*7,day:1e3*60*60*24,hour:1e3*60*60,minute:1e3*60},a=0;if(o[r])a=Math.round((t-e)/(i*o[r]));else{for(var s=new Date(e),c=new Date(t);s.valueOf()<c.valueOf();)a+=1,s=n.add(s,i,r);s.valueOf()!=t.valueOf()&&(a+=(c-s)/(n.add(s,i,r)-s))}return Math.round(a)},hasDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.end_date,i=e.unit;return i?(t=new Date(t),r=new Date(r),t.valueOf()<r.valueOf()):!1},hasWorkTime:function(){return!0},equals:function(e){return e instanceof Ca},calculateEndDate:function(){var e=this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper,arguments),t=e.start_date,r=e.duration,i=e.unit,n=e.step;return this.$gantt.date.add(t,n*r,i)}};function Pd(e){this.$gantt=e.$gantt,this.argumentsHelper=_d(this.$gantt),this.calendarManager=e,this.$disabledCalendar=new Ca(this.$gantt,this.argumentsHelper)}Pd.prototype={_getCalendar:function(e){var t;if(!this.$gantt.config.work_time)t=this.$disabledCalendar;else{var r=this.calendarManager;e.task?t=r.getTaskCalendar(e.task):e.id?t=r.getTaskCalendar(e):e.calendar&&(t=e.calendar),t||(t=r.getTaskCalendar())}return t},getWorkHours:function(e){e=this.argumentsHelper.getWorkHoursArguments.apply(this.argumentsHelper,arguments);var t=this._getCalendar(e);return t.getWorkHours(e.date)},setWorkTime:function(e,t){return e=this.argumentsHelper.setWorkTimeArguments.apply(this.argumentsHelper,arguments),t||(t=this.calendarManager.getCalendar()),t.setWorkTime(e)},unsetWorkTime:function(e,t){return e=this.argumentsHelper.unsetWorkTimeArguments.apply(this.argumentsHelper,arguments),t||(t=this.calendarManager.getCalendar()),t.unsetWorkTime(e)},isWorkTime:function(e,t,r,i){var n=this.argumentsHelper.isWorkTimeArguments.apply(this.argumentsHelper,arguments);return i=this._getCalendar(n),i.isWorkTime(n)},getClosestWorkTime:function(e){e=this.argumentsHelper.getClosestWorkTimeArguments.apply(this.argumentsHelper,arguments);var t=this._getCalendar(e);return t.getClosestWorkTime(e)},calculateDuration:function(){var e=this.argumentsHelper.getDurationArguments.apply(this.argumentsHelper,arguments),t=this._getCalendar(e);return t.calculateDuration(e)},hasDuration:function(){var e=this.argumentsHelper.hasDurationArguments.apply(this.argumentsHelper,arguments),t=this._getCalendar(e);return t.hasDuration(e)},calculateEndDate:function(t){var t=this.argumentsHelper.calculateEndDateArguments.apply(this.argumentsHelper,arguments),r=this._getCalendar(t);return r.calculateEndDate(t)}};var Ig=function(e,t){return{getWorkHours:function(r){return t.getWorkHours(r)},setWorkTime:function(r){return t.setWorkTime(r)},unsetWorkTime:function(r){t.unsetWorkTime(r)},isWorkTime:function(r,i,n){return t.isWorkTime(r,i,n)},getClosestWorkTime:function(r){return t.getClosestWorkTime(r)},calculateDuration:function(r,i,n){return t.calculateDuration(r,i,n)},_hasDuration:function(r,i,n){return t.hasDuration(r,i,n)},calculateEndDate:function(r,i,n,o){return t.calculateEndDate(r,i,n,o)},mergeCalendars:Bt(e.mergeCalendars,e),createCalendar:Bt(e.createCalendar,e),addCalendar:Bt(e.addCalendar,e),getCalendar:Bt(e.getCalendar,e),getCalendars:Bt(e.getCalendars,e),getResourceCalendar:Bt(e.getResourceCalendar,e),getTaskCalendar:Bt(e.getTaskCalendar,e),deleteCalendar:Bt(e.deleteCalendar,e)}},gg={create:Ig};function Ld(e){var t=new Rd(e),r=new Pd(t),i=gg.create(t,r);Sr(e,i)}var Od={date:{month_full:["January","February","March","April","May","June","July","August","September","October","November","December"],month_short:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],day_full:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],day_short:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]},labels:{}};function Nd(e={}){let t=e.config||{},r={config:Object.assign({duration_unit:"hour",duration_step:1,work_time:!1,worktimes:{},work_days:null,inherit_calendar:!1,calendar_property:"calendar_id",resource_property:"resource_id",resource_calendars:{},dynamic_resource_calendars:!1,start_on_monday:!0,server_utc:!0,csp:"auto",show_errors:!1},t),locale:e.locale||Od,templates:e.templates||{},getTask:e.getTask||function(i){return null},isTaskExists:e.isTaskExists||function(i){return!1},isSummaryTask:e.isSummaryTask||function(i){return!1},getState:function(){return{group_mode:!1}},callEvent:function(i,n){let o=e.onEvent;return o&&o(i,n),!0},attachEvent:function(){return 0},checkEvent:function(){return!1},detachEvent:function(){},defined:Sd,mixin:Sr,copy:Jt,assert:function(i,n){if(!i){if(e.throwOnAssert)throw new Error("[calendar] "+n);e.silent!==!0&&console.error("[calendar]",n)}},$services:{getService:function(){return null}},$ui:{getView:function(){return null}}};return r._correct_dst_change=function(i){return i},r.date=Dd(r),r.date.init(),Ld(r),r}function Ag(e={}){let t=Nd(e);return{addCalendar:function(r){return t.addCalendar(r)},deleteCalendar:function(r){return t.deleteCalendar(r)},getCalendar:function(r){return t.getCalendar(r)},getCalendars:function(){return t.getCalendars()},mergeCalendars:function(){return t.mergeCalendars.apply(t,arguments)},getTaskCalendar:function(r){return t.getTaskCalendar(r)},getResourceCalendar:function(r){return t.getResourceCalendar(r)},setWorkTime:function(r){return t.setWorkTime(r)},unsetWorkTime:function(r){return t.unsetWorkTime(r)},isWorkTime:function(){return t.isWorkTime.apply(t,arguments)},getClosestWorkTime:function(){return t.getClosestWorkTime.apply(t,arguments)},getWorkHours:function(){return t.getWorkHours.apply(t,arguments)},calculateDuration:function(){return t.calculateDuration.apply(t,arguments)},calculateEndDate:function(){return t.calculateEndDate.apply(t,arguments)},_internals:t}}var bd={createCalendar:Ag};var hU=3600*1e3;function Md(e){return{getActivity(t){return e.getActivity(t)}}}var{createCalendar:vg}=bd,ti="__replay_default__";function Cg(e){if(!e||e.length===0||typeof e[0]=="string")return e;let t=e.map(Number);if(t.some(o=>Number.isNaN(o)))return e;let r=t[0],i=t[t.length-1];return t.every((o,a)=>o===r+a)?[`${r}:00-${i+1}:00`]:e}var Fd={hours:["8:00-16:00"],days:[!1,!0,!0,!0,!0,!0,!1]},wd="__main_global__",Sg={hours:["8:00-12:00","13:00-17:00"],days:[!1,!0,!0,!0,!0,!0,!1]};function xd(e){return!e||e.hours===void 0||e.hours.length>0||e.days?.some(t=>Array.isArray(t)&&t.length>0)===!0?!0:Object.values(e.dates??{}).some(t=>Array.isArray(t)&&t.length>0)}function Tg(e){let t={};if(Array.isArray(e.days))for(let i=0;i<e.days.length;i+=1)t[i]=e.days[i];if(e.dates)for(let[i,n]of Object.entries(e.dates))t[i]=n;let r={hours:Cg(e.hours),dates:t};return e.customWeeks&&(r.customWeeks=e.customWeeks),r}function Ud(e){let t=vg({config:{work_time:!0}});t.addCalendar({id:ti,worktime:Fd}),t.addCalendar({id:wd,worktime:Sg});let r=new Set(e.filter(d=>!xd(d.worktime)).map(d=>String(d.id))),i=e.filter(d=>xd(d.worktime));for(let d of i)t.addCalendar({id:d.id,worktime:d.worktime?Tg(d.worktime):Fd});let n=Cd(t),o=n.getCalendar(ti),a=n.getCalendar(wd);if(!o||!a)throw new Error("[replay-calendar] fallback calendars failed to register in work-calendar instance");let s=new Set([ti]);for(let d of i)s.add(String(d.id));let c=new Map;return{reader:{getCalendar(d){let u=String(d),f=c.get(u);if(f)return f;let p=o;return s.has(u)?p=n.getCalendar(d)??o:r.has(u)&&(p=a),c.set(u,p),p}}}}function Bd(e){return{hasChildren(t){return e.hasChildren(t)},getParentStartDateIfHasPredecessors(t){let r=e.getActivity(t);if(!r)return null;let i=e.getParent(r.id);return!i||e.getIncomingLinkIds(i.id).length===0?null:i.startDate},getDescendantIds(t){return Eg(e,t).map(r=>String(r))},getAncestorIds(t){let r=[],i=e.getActivity(t);for(;i;){let n=i.parentId;if(n===null)break;let o=e.getActivity(n);if(!o)break;r.push(String(n)),i=o}return r},getChildProgressInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,progress:Number(n?.progress??0),ponderator:Number(n?.ponderator??0)}})},getChildHhInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,workHours:Number(n?.workHours??0),progress:Number(n?.progress??0),realWorkHours:Number(n?.realWorkHours??0)}})},getChildUsedCostInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,usedCost:Number(n?.usedCost??0)}})},getChildCostInfo(t){return e.getChildren(t).map(i=>{let n=e.getActivity(i);return{id:i,cost:Number(n?.cost??0)}})}}}function Eg(e,t){let r=[],i=new xt;for(let n of e.getChildren(t))i.enqueue(n);for(;!i.isEmpty();){let n=i.dequeue();r.push(n);for(let o of e.getChildren(n))i.enqueue(o)}return r}var En=class{_cache={closestWorkTime:new Map,endDate:new Map,duration:new Map};reader;constructor(t){this.reader=t.reader}resolveCalendar(t){let r=Hd(t);return this.reader.getCalendar(r??ti)}getClosestWorkTime(t){let r=`${Ta(t.task)}|${t.dir}|${t.date.getTime()}`;return Sa(this._cache.closestWorkTime,r,()=>this.resolveCalendar(t.task).getClosestWorkTime({direction:t.dir,date:t.date,unit:mt.HOUR}))}calculateEndDate(t){let r=`${Ta(t.task)}|${t.startDate.getTime()}|${t.durationHours}`;return Sa(this._cache.endDate,r,()=>this.resolveCalendar(t.task).calculateEndDate(t.startDate,t.durationHours))}calculateDuration(t){let r=`${Ta(t.task)}|${t.startDate.getTime()}|${t.endDate.getTime()}`;return Sa(this._cache.duration,r,()=>this.resolveCalendar(t.task).calculateDuration(t.startDate,t.endDate))}clearCache(){this._cache.closestWorkTime.clear(),this._cache.endDate.clear(),this._cache.duration.clear()}};function Sa(e,t,r){let i=e.get(t);if(i!==void 0)return i;let n=r();return e.set(t,n),n}var Dg="__default__";function Hd(e){if(!e)return null;let t=e.calendarId;return t==null?null:String(t)}function Ta(e){return Hd(e)??Dg}var Dn=class{constructor(t){this.activities=t}activities;_childrenByParent=new Map;_roots=[];_dirty=!1;markDirty(){this._dirty=!0}getChildren(t){return this._dirty&&(this.rebuild(),this._dirty=!1),this._childrenByParent.get(String(t))??[]}hasChildren(t){return this._dirty&&(this.rebuild(),this._dirty=!1),(this._childrenByParent.get(String(t))?.length??0)>0}getRootIds(){return this._dirty&&(this.rebuild(),this._dirty=!1),[...this._roots]}isChildOf(t,r){let i=this.activities.get(t)?.parentId,n=0,o=this.activities.size;for(;i&&!M(i);){if(i===r)return!0;if(++n>o)return!1;i=this.activities.get(i)?.parentId}return!1}getParent(t){let r=this.activities.get(t)?.parentId;return!r||M(r)?null:this.activities.get(r)??null}getParentId(t){return this.activities.get(t)?.parentId??null}addChild(t,r){if(this._dirty)return;if(M(t)){this._roots.push(r);return}let i=String(t),n=this._childrenByParent.get(i);n?n.push(r):this._childrenByParent.set(i,[r])}rebuild(){this._childrenByParent.clear(),this._roots=[];for(let r of this.activities.values()){if(M(r.parentId)){this._roots.push(r.id);continue}let i=String(r.parentId),n=this._childrenByParent.get(i)??[];n.push(r.id),this._childrenByParent.set(i,n)}let t=(r,i)=>{let n=this.activities.get(r),o=this.activities.get(i);return n&&o?ui(n,o):String(r).localeCompare(String(i))};this._roots.sort(t);for(let r of this._childrenByParent.values())r.sort(t)}};var _n=class{checkedSet=new Set;hiddenSet=new Set;activeFilter=null;activeOrder=null;isChecked(t){return this.checkedSet.has(t)}isVisible(t){return!this.hiddenSet.has(t)}hiddenIds(){return[...this.hiddenSet]}getActiveFilter(){return this.activeFilter}setActiveFilter(t){this.activeFilter=t}getActiveOrder(){return this.activeOrder}setActiveOrder(t){this.activeOrder=t}checkedIds(){return[...this.checkedSet]}checkedCount(){return this.checkedSet.size}setChecked(t,r){return r===this.checkedSet.has(t)?!1:(r?this.checkedSet.add(t):this.checkedSet.delete(t),!0)}setVisible(t,r){return r===!this.hiddenSet.has(t)?!1:(r?this.hiddenSet.delete(t):this.hiddenSet.add(t),!0)}forget(t){this.checkedSet.delete(t),this.hiddenSet.delete(t)}hydrate(t){this.checkedSet=new Set(t.checkedIds??[]),this.hiddenSet=new Set(t.hiddenIds??[]),this.activeFilter=null,this.activeOrder=null}snapshot(){return{checked:new Set(this.checkedSet),hidden:new Set(this.hiddenSet),activeFilter:this.activeFilter,activeOrder:this.activeOrder}}restore(t){this.checkedSet=new Set(t.checked),this.hiddenSet=new Set(t.hidden),this.activeFilter=t.activeFilter,this.activeOrder=t.activeOrder}};var Tr=class e{_activities=new Map;_lastStartDate=new Map;_promotionSnapshot=new Map;_progressFallback=new Map;_links=new Map;_outgoing=new Map;_incoming=new Map;_hierarchy;_buildOrderComparator;_cache={ids:null,visualOrderIds:null,orderComparator:null};_writeCapture=new tn;_viewState=new _n;_filterProjection=null;_viewStateBefore=null;_lastStartDateBefore=null;_promotionSnapshotBefore=null;_calendar;_flags;_calendarSnapshot;constructor(t,r=()=>null){this._buildOrderComparator=r,this._calendarSnapshot=F(t.calendars);for(let i of t.activities)this._activities.set(i.id,i);for(let i of t.links){let n={...i,freeSlackHours:i.freeSlackHours??null,isCritical:i.isCritical===!0};this._links.set(String(i.id),n),this._indexLink(n)}this._calendar=new En(Ud(this._calendarSnapshot)),this._flags=kg(t),this._hierarchy=new Dn(this._activities),this._hierarchy.rebuild()}fork(){let t=new e({activities:this.getAllActivities().map(ae),links:this.getAllLinks().map(r=>({...r})),calendars:F(this._calendarSnapshot)},this._buildOrderComparator);return t._viewState.restore(F(this._viewState.snapshot())),t._lastStartDate=new Map(Array.from(this._lastStartDate,([r,i])=>[r,new Date(i)])),t._promotionSnapshot=new Map(Array.from(this._promotionSnapshot,([r,i])=>[r,F(i)])),t._progressFallback=new Map(this._progressFallback),t._flags=F(this._flags),t._filterProjection=F(this._filterProjection),t}getAllActivities(){return Array.from(this._activities.values())}getAllLinks(){return Array.from(this._links.values())}getAllIds(){return this._cache.ids?this._cache.ids:(this._cache.ids=Array.from(this._activities.keys()),this._cache.ids)}activityCount(){return this._activities.size}getVisualOrderIds(){return this._cache.visualOrderIds?this._cache.visualOrderIds:(this._cache.visualOrderIds=ys(this).map(t=>String(t.id)),this._cache.visualOrderIds)}invalidateVisualOrderIds(){this._cache.visualOrderIds=null}forEachActivity(t){for(let[r,i]of this._activities)t(i,r)}getParentId(t){return this._hierarchy.getParentId(t)}getActivity(t){return this._activities.get(String(t))??null}getLastStartDate(t){return this._lastStartDate.get(String(t))??null}setLastStartDate(t,r){this._captureLastStartDateOnce(),this._lastStartDate.set(String(t),r)}getPromotionSnapshot(t){return this._promotionSnapshot.get(String(t))??null}setPromotionSnapshot(t,r){this._capturePromotionSnapshotOnce(),this._promotionSnapshot.set(String(t),r)}getProgressFallback(t){return this._progressFallback.get(String(t))??null}setProgressFallback(t,r){let i=String(t),n=this._progressFallback.get(i)??null;Object.is(n,r)||(this._writeCapture.noteProgressFallback(i,n),r===null?this._progressFallback.delete(i):this._progressFallback.set(i,r))}_capturePromotionSnapshotOnce(){this._writeCapture.peek()!==null&&this._promotionSnapshotBefore===null&&(this._promotionSnapshotBefore=new Map(this._promotionSnapshot))}_captureLastStartDateOnce(){this._writeCapture.peek()!==null&&this._lastStartDateBefore===null&&(this._lastStartDateBefore=new Map(this._lastStartDate))}getLink(t){return this._links.get(String(t))??null}activityExists(t){return this._activities.has(String(t))}isChecked(t){return this._viewState.isChecked(String(t))}isVisible(t){return this._viewState.isVisible(String(t))}checkedIds(){return this._viewState.checkedIds()}hiddenIds(){return this._viewState.hiddenIds()}setChecked(t,r){return this._captureViewStateOnce(),this._viewState.setChecked(String(t),r)}setVisible(t,r){return this._captureViewStateOnce(),this._viewState.setVisible(String(t),r)}getActiveFilter(){return this._viewState.getActiveFilter()}setActiveFilter(t){this._captureViewStateOnce(),this._viewState.setActiveFilter(t),this._filterProjection=null}getFilterProjection(){return this._filterProjection}setFilterProjection(t){this._filterProjection=t}getActiveOrder(){return this._viewState.getActiveOrder()}setActiveOrder(t){this._captureViewStateOnce(),this._viewState.setActiveOrder(t),this.invalidateDerivedOrder()}getOrderComparator(){let t=this._viewState.getActiveOrder();return t===null?(this._cache.orderComparator=null,null):this._cache.orderComparator?this._cache.orderComparator:(this._cache.orderComparator=this._buildOrderComparator(t),this._cache.orderComparator)}invalidateDerivedOrder(){this._cache.orderComparator=null,this._cache.visualOrderIds=null}hydrateViewState(t){this._viewState.hydrate(t),this._filterProjection=null,this.invalidateDerivedOrder()}_captureViewStateOnce(){this._writeCapture.peek()!==null&&this._viewStateBefore===null&&(this._viewStateBefore=this._viewState.snapshot())}getOutgoingLinkIds(t){return this._outgoing.get(String(t))??Wd}getIncomingLinkIds(t){return this._incoming.get(String(t))??Wd}getChildren(t){return this._hierarchy.getChildren(t)}hasChildren(t){return this._hierarchy.hasChildren(t)}isChildOf(t,r){return this._hierarchy.isChildOf(t,r)}getParent(t){return this._hierarchy.getParent(t)}getRootIds(){return this._hierarchy.getRootIds()}getClosestWorkTime(t){return this._calendar.getClosestWorkTime(t)}calculateEndDate(t){return this._calendar.calculateEndDate(t)}calculateDuration(t){return this._calendar.calculateDuration(t)}clearCalendarCache(){this._calendar.clearCache()}get calendarReader(){return this._calendar.reader}batchUpdate(t){t()}updateActivity(t){}getLiveActivity(t){return this.getActivity(t)}getFlags(){return{...this._flags,allCheckedTaskIds:this._viewState.checkedIds()}}getProjectEnd(){return null}beginWriteCapture(){this._writeCapture.begin(),this._viewStateBefore=null,this._lastStartDateBefore=null,this._promotionSnapshotBefore=null}peekWriteCapture(){return this._writeCapture.peek()}endWriteCapture(){this._writeCapture.end(),this._viewStateBefore=null,this._lastStartDateBefore=null,this._promotionSnapshotBefore=null}setActivityField(t,r,i){let n=this.getActivity(t);n&&(this._writeCapture.note(String(t),n),n[r]=i,Da(n,r),r===x.PARENT&&this._hierarchy.markDirty(),Ea(r)&&(this._cache.visualOrderIds=null))}setActivityFieldDynamic(t,r,i){let n=this.getActivity(t);if(n){if(!Object.hasOwn(n,r))throw new Error(`setActivityFieldDynamic: unknown CoreActivity field "${r}"`);this._writeCapture.note(String(t),n),Reflect.set(n,r,vd(r,i)),Da(n,r),r===x.PARENT&&this._hierarchy.markDirty(),Ea(r)&&(this._cache.visualOrderIds=null)}}setActivityFields(t,r){let i=this.getActivity(t);if(!i)return;this._writeCapture.note(String(t),i);let n=!1;for(let o of Object.keys(r))Reflect.set(i,o,Reflect.get(r,o)),Da(i,o),o===x.PARENT&&(n=!0),Ea(o)&&(this._cache.visualOrderIds=null);n&&this._hierarchy.markDirty()}addLink(t){this._writeCapture.noteLinkAdd(String(t.id));let r=this._links.get(String(t.id));r&&this._deindexLink(r);let i={...t,freeSlackHours:t.freeSlackHours??null,isCritical:t.isCritical===!0};this._links.set(String(t.id),i),this._indexLink(i)}_indexLink(t){Kd(this._outgoing,String(t.source),t.id),Kd(this._incoming,String(t.target),t.id)}_deindexLink(t){let r=this._outgoing.get(String(t.source));r&&this._outgoing.set(String(t.source),Vd(r,t.id));let i=this._incoming.get(String(t.target));i&&this._incoming.set(String(t.target),Vd(i,t.id))}setLinkField(t,r,i){let n=this.getLink(t);n&&(this._writeCapture.noteLinkField(String(t),n),n[r]=i)}setLinkFieldDynamic(t,r,i){if(!_g(r))return;let n=this.getLink(t);n&&(this._writeCapture.noteLinkField(String(t),n),Reflect.set(n,r,i))}setLinkProplannerId(t,r){let i=this.getLink(t);i&&(this._writeCapture.noteLinkField(String(t),i),i.proplannerId=r)}removeLink(t){let r=this.getLink(t);r&&(this._writeCapture.noteLinkRemove(String(t),r),this._links.delete(String(t)),this._deindexLink(r))}addActivity(t){this._writeCapture.noteInsert(String(t.id)),this._activities.set(t.id,t),this._cache.ids=null,this._cache.visualOrderIds=null,this._hierarchy.addChild(t.parentId,t.id)}removeActivity(t){let r=this.getActivity(t);r&&this._writeCapture.noteRemove(String(t),r);let i=String(t);this.setProgressFallback(i,null),(this._viewState.isChecked(i)||!this._viewState.isVisible(i))&&this._captureViewStateOnce(),this._viewState.forget(i),this._activities.delete(t),this._lastStartDate.has(String(t))&&(this._captureLastStartDateOnce(),this._lastStartDate.delete(String(t))),this._outgoing.delete(String(t)),this._incoming.delete(String(t)),this._cache.ids=null,this._cache.visualOrderIds=null,this._hierarchy.markDirty()}noteCorrelativeBefore(t,r){this._writeCapture.noteCorrelativeBefore(t,r)}noteScheduledBefore(t,r){this._writeCapture.noteScheduledBefore(t,r)}restoreFromCapture(){let t=this._writeCapture.peek();if(!t)return;let{ops:r,before:i,correlativeBefore:n,scheduledBefore:o,progressFallbackBefore:a}=t;this._undoLinkAdds(r),this._undoInserts(r),this._reInsertRemovedActivities(r),this._reAddRemovedLinks(r),this._restoreLinkFields(r),this._restoreActivityFields(o),this._restoreActivityFields(i),this._restoreCorrelatives(n),this._restoreProgressFallbacks(a),this._viewStateBefore!==null&&(this._viewState.restore(this._viewStateBefore),this._filterProjection=null,this.invalidateDerivedOrder()),this._promotionSnapshotBefore!==null&&(this._promotionSnapshot=this._promotionSnapshotBefore),this._lastStartDateBefore!==null&&(this._lastStartDate=this._lastStartDateBefore),this._cache.ids=null,this._cache.visualOrderIds=null,this._hierarchy.markDirty()}_restoreProgressFallbacks(t){for(let[r,i]of t)i===null?this._progressFallback.delete(r):this._progressFallback.set(r,i)}_restoreCorrelatives(t){for(let[r,i]of t){let n=this._activities.get(r);n&&(n.correlativeId=i)}}_undoLinkAdds(t){for(let r of t)r.kind===Et.LINK_ADD&&this._detachLink(r.linkId)}_undoInserts(t){for(let r of t)r.kind===Et.INSERT&&this._activities.delete(r.activityId)}_reInsertRemovedActivities(t){for(let r of t)r.kind===Et.REMOVE&&this._activities.set(r.activityId,r.before)}_reAddRemovedLinks(t){for(let r of t)r.kind===Et.LINK_REMOVE&&this._attachLink(r.before)}_restoreLinkFields(t){for(let r of t)r.kind===Et.LINK_FIELD&&this._links.has(r.linkId)&&this._links.set(r.linkId,r.before)}_restoreActivityFields(t){for(let[r,i]of t){let n=this._activities.get(r);n&&this._restoreScalarFields(n,i)}}_restoreScalarFields(t,r){for(let i of Object.keys(t))Object.hasOwn(r,i)||Reflect.deleteProperty(t,i);for(let i of Object.keys(r))Reflect.set(t,i,Reflect.get(r,i))}_attachLink(t){this._links.set(String(t.id),{...t}),this._indexLink(t)}_detachLink(t){let r=this.getLink(t);r&&(this._links.delete(String(t)),this._deindexLink(r))}},Wd=[];function _g(e){return e===jr.LAG||e===jr.TYPE||e===jr.FREE_SLACK_HOURS||e===jr.IS_CRITICAL}function Ea(e){return e===x.PARENT||e===x.CORRELATIVE_ID}function Da(e,t){t!==x.START_DATE&&t!==x.END_DATE&&t!==x.TYPE||(e.calendarDuration=Qt(e))}function Vd(e,t){return e.filter(r=>String(r)!==String(t))}function Kd(e,t,r){let i=e.get(t);i?i.push(r):e.set(t,[r])}function kg(e){let t=e.runtimeFlags??{};return{isPasting:!!t.isPasting,isBulkOperation:!!t.isBulkOperation,dragWithMultiple:!!t.dragWithMultiple,draggingSingleMilestone:!!t.draggingSingleMilestone,creatingActivity:!1,avoidAutoScheduleBeforeDrag:!1,maxPerformance:!!t.maxPerformance,allCheckedTaskIds:[]}}function _a(e,t){let r=e.getActivity(t);return r?F(r):null}function jd(e){return e.getAllActivities().map(F)}function Yd(e){return e.getAllIds().map(String)}function Gd(e,t){e.forEachActivity((r,i)=>t(i))}function $d(e,t){let r=t==="0"?ka(e,"0"):e.getChildren(t),i=[];for(let n of r){let o=e.getActivity(n);o&&i.push(F(o))}return i.sort((n,o)=>(n.correlativeId??0)-(o.correlativeId??0)),i}function ka(e,t){return Ht(t,e)}function zd(e){return e.checkedIds().map(String)}function qd(e,t){if(t==="0"){let r=!1;return e.forEachActivity(i=>{r||=M(i.parentId)}),r}return e.getChildren(t).length>0}function Ra(e,t){let r=e.getLink(t);return r?bt(r):null}function Jd(e){return e.getAllLinks().map(t=>bt(t))}function kn(e){let[t,r]=e.split(":");return Number(t)*60+Number(r??0)}function Rg(e){return e.reduce((t,r)=>kn(r)<kn(t)?r:t)}function Pg(e){return e.reduce((t,r)=>kn(r)>kn(t)?r:t)}function Lg(e){return e.worktime.days.flatMap(t=>Array.isArray(t)?t:t===!0?e.worktime.hours:[])}function Xd(e){let t=[...e].find(o=>o.is_default);if(!t)return null;let r=Lg(t);if(r.length===0)return null;let i=r.map(o=>o.split("-")[0]),n=r.map(o=>o.split("-")[1]);return{startHour:Rg(i),endHour:Pg(n)}}function Pa(e,t){return{calendars:e.calendarReader,hierarchy:Bd(e),activityReader:Md(e),dateFormat:t.dateFormat??"YYYY-MM-DD",customHours:t.customHours??{},hoursPerDay:t.hoursPerDay}}function Zd(e){return We(e)}var Og=new Set(["freeSlackHours","isCritical"]);function Ng(e,t){let r=Object.fromEntries(Object.entries(e.fields??{}).filter(([i])=>!t.has(i)));return e.kind===N.UPDATED&&Object.keys(r).length===0?null:{...e,...e.fields===void 0?{}:{fields:r},after:null}}function ru(e){let t=e.activities.map(n=>({...n,after:null})),r=e.links.map(n=>Ng(n,Og)).filter(n=>n!==null),i=e.source.kind===ue?{...e.source,items:[],links:[]}:e.source;return F({...e,source:i,activities:t,links:r})}function La(e,t,r,i,n,o,a){return{changeSet:e,beforeSnap:t,beforeLinks:Qd(r),afterSnap:i,afterLinks:Qd(n),progressFallbackBefore:o,progressFallbackAfter:a}}function Qd(e){if(e)return new Map(Array.from(e,([t,r])=>[t,{...r,freeSlackHours:null,isCritical:!1}]))}function iu(e,t){let r=new Map,i=new Map;for(let n of t.activities){if(n.kind!==N.CREATED)continue;let o=e.getActivity(String(n.id));o&&r.set(String(n.id),et(o))}for(let n of t.links){if(n.kind===N.DELETED)continue;let o=e.getLink(String(n.id));o&&i.set(String(n.id),{...o})}return{afterSnap:r,afterLinks:i}}function nu(e){return e.kind!==m.INLINE_EDIT||!qr.has(e.column)?null:`inline-edit:${String(e.activityId)}:${e.column}`}function tu(e){return e.changeSet.activities.length===1&&e.changeSet.activities[0]?.kind===N.UPDATED&&e.changeSet.links.length===0&&!e.beforeSnap?.size&&!e.afterSnap?.size}function ou(e,t){if(!tu(e)||!tu(t))return!1;let r=e.changeSet.activities[0],i=t.changeSet.activities[0];return!!r&&!!i&&String(r.id)===String(i.id)}function au(e,t){let r=e.changeSet.activities[0],i=t.changeSet.activities[0];if(!r||!i)return t;let n=r.fields??{},o=i.fields??{},a={};for(let c of new Set([...Object.keys(n),...Object.keys(o)])){let l=n[c],d=o[c];a[c]={before:l?l.before:d?.before,after:d?d.after:l?.after}}let s={...t.changeSet,activities:[{...i,fields:a}]};return La(s)}var Er={RECORD:"record",SKIP:"skip",CHECKPOINT_ON_SUCCESS:"checkpoint-on-success"},ct={BEFORE:"before",AFTER:"after"};function su(e){return e.kind===m.PERSISTENCE_ACKNOWLEDGE?Er.CHECKPOINT_ON_SUCCESS:e.kind===m.SIR_SYNC||e.kind===m.CALENDAR_RECONCILE||e.kind===m.ACTIVITY_LOOKAHEAD_SYNC||e.kind===m.BASELINE_APPLY||e.kind===m.PONDERATOR_CRITERION_SET||e.kind===m.STATUS_CRITERIA_SET||e.kind===m.ACTIVITY_CLIPBOARD_CLEAR||e.kind===m.ACTIVITY_COPY||e.kind===m.SELECTION_TOGGLE||e.kind===m.SELECTION_REPLACE||e.kind===m.VISIBILITY_SET||e.kind===m.FILTER_SET||e.kind===m.SORT_SET?Er.SKIP:Er.RECORD}function Oa(e){for(let t of e.changeSet.activities)if(t.kind===N.CREATED||t.kind===N.DELETED||t.kind===N.UPDATED&&t.fields&&_.CUSTOM_ID in t.fields)return!0;return!1}function Na(e,t,r){let i=[],n=[];for(let a of t.changeSet.activities){let s=String(a.id);if(a.kind===N.UPDATED){let c=e.getActivity(s);i.push({id:s,kind:N.UPDATED,fields:eu(a.fields,r),after:c?et(c):null})}else if(a.kind===N.DELETED)if(r===ct.BEFORE){let c=e.getActivity(s);i.push({id:s,kind:N.CREATED,after:c?et(c):null})}else i.push({id:s,kind:N.DELETED,after:null});else if(r===ct.BEFORE)i.push({id:s,kind:N.DELETED,after:null});else{let c=e.getActivity(s);i.push({id:s,kind:N.CREATED,after:c?et(c):null})}}for(let a of t.changeSet.links){let s=String(a.id);if(a.kind===N.UPDATED){let c=e.getLink(s);n.push({id:s,kind:N.UPDATED,fields:eu(a.fields,r),after:c?bt(c):null})}else if(a.kind===N.DELETED)if(r===ct.BEFORE){let c=e.getLink(s);n.push({id:s,kind:N.CREATED,after:c?bt(c):null})}else n.push({id:s,kind:N.DELETED,after:null});else if(r===ct.BEFORE)n.push({id:s,kind:N.DELETED,after:null});else{let c=e.getLink(s);n.push({id:s,kind:N.CREATED,after:c?bt(c):null})}}let o=(t.changeSet.viewState??[]).map(a=>r===ct.BEFORE?bg(a):a);return{source:{kind:r===ct.BEFORE?oe.UNDO:oe.REDO},activities:i,links:n,calendars:[],trackingEvents:[],effects:[],viewState:o}}function eu(e,t){if(e!=null)return Object.fromEntries(Object.entries(e).map(([r,i])=>[r,t===ct.BEFORE?{before:F(i.after),after:F(i.before)}:{before:F(i.before),after:F(i.after)}]))}function bg(e){return{activityId:e.activityId,...e.checked?{checked:{before:e.checked.after,after:e.checked.before}}:{},...e.visible?{visible:{before:e.visible.after,after:e.visible.before}}:{}}}function ba(e){return e.activities.length>0||e.links.length>0||(e.viewState?.length??0)>0||(e.effects?.length??0)>0}function cu(e,t){du(e,t,ct.BEFORE)}function lu(e,t){du(e,t,ct.AFTER)}function du(e,t,r){let i=t.changeSet;for(let o of i.activities)if(o.kind===N.UPDATED){if(!o.fields)continue;for(let[a,s]of Object.entries(o.fields))yt(e,o.id,a,r===ct.BEFORE?s.before:s.after)}else if(o.kind===N.DELETED)if(r===ct.BEFORE){let a=t.beforeSnap?.get(String(o.id));if(!a)throw new Error(`undo: missing beforeSnap for resurrecting activity ${o.id}`);e.addActivity(et(a))}else e.removeActivity(String(o.id));else if(r===ct.BEFORE)e.removeActivity(String(o.id));else{let a=t.afterSnap?.get(String(o.id));if(!a)throw new Error(`redo: missing afterSnap for re-creating activity ${o.id}`);e.addActivity(et(a))}for(let o of i.links)if(o.kind===N.UPDATED){if(!o.fields)continue;if(Object.hasOwn(o.fields,"source")||Object.hasOwn(o.fields,"target")){let a=r===ct.BEFORE?t.beforeLinks?.get(String(o.id)):t.afterLinks?.get(String(o.id));if(!a)throw new Error(`${r===ct.BEFORE?"undo":"redo"}: missing link snapshot for ${o.id}`);e.removeLink(String(o.id)),e.addLink({...a});continue}for(let[a,s]of Object.entries(o.fields))Dc(e,String(o.id),a,r===ct.BEFORE?s.before:s.after)}else if(o.kind===N.DELETED)if(r===ct.BEFORE){let a=t.beforeLinks?.get(String(o.id));if(!a)throw new Error(`undo: missing beforeLinks for re-adding link ${o.id}`);e.addLink(a)}else e.removeLink(String(o.id));else if(r===ct.BEFORE)e.removeLink(String(o.id));else{let a=t.afterLinks?.get(String(o.id));if(!a)throw new Error(`redo: missing afterLinks for re-creating link ${o.id}`);e.addLink(a)}for(let o of i.viewState??[])o.checked&&e.setChecked(o.activityId,r===ct.BEFORE?o.checked.before:o.checked.after),o.visible&&e.setVisible(o.activityId,r===ct.BEFORE?o.visible.before:o.visible.after);let n=r===ct.BEFORE?t.progressFallbackBefore:t.progressFallbackAfter;for(let[o,a]of n??[])e.setProgressFallback(o,a)}var Fg=100,wg=600,Rn=class e{constructor(t=Fg){this.maxDepth=t}maxDepth;undoStack=[];redoStack=[];sequence=0;_lastKey=null;_lastTime=0;fork(){let t=new e(this.maxDepth);return t.undoStack.push(...F(this.undoStack)),t.redoStack.push(...F(this.redoStack)),t.sequence=this.sequence,t._lastKey=this._lastKey,t._lastTime=this._lastTime,t}record(t,r=null,i=0){let n=this.undoStack[this.undoStack.length-1];r!=null&&r===this._lastKey&&i-this._lastTime<=wg&&n!==void 0&&ou(n.entry,t)?(n.entry=au(n.entry,t),n.touchedAt=this.touch()):(this.undoStack.push({entry:t,touchedAt:this.touch()}),this.undoStack.length>this.maxDepth&&this.undoStack.splice(0,this.undoStack.length-this.maxDepth)),this._lastKey=r,this._lastTime=i,this.redoStack.length=0}resetCoalesce(){this._lastKey=null}takeUndo(){return this.undoStack.pop()?.entry??null}takeRedo(){return this.redoStack.pop()?.entry??null}pushRedo(t){this.redoStack.push({entry:t,touchedAt:this.touch()})}pushUndo(t){this.undoStack.push({entry:t,touchedAt:this.touch()})}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}undoDepth(){return this.undoStack.length}capturePersistenceBoundary(){return this.resetCoalesce(),this.sequence}discardThrough(t){this.removeEntriesThrough(this.undoStack,t),this.removeEntriesThrough(this.redoStack,t),this.resetCoalesce()}applyPersistedIdentities(t,r){let i=new Map(t.map(({id:o,proplannerId:a})=>[String(o),a])),n=new Map(r.map(({id:o,proplannerId:a})=>[String(o),a]));for(let o of[...this.undoStack,...this.redoStack])o.entry=this.withPersistedIdentities(o.entry,i,n)}clear(){this.undoStack.length=0,this.redoStack.length=0,this.resetCoalesce()}touch(){return this.sequence+=1,this.sequence}removeEntriesThrough(t,r){let i=t.filter(({touchedAt:n})=>n>r);t.splice(0,t.length,...i)}withPersistedIdentities(t,r,i){let n=a=>a===void 0?void 0:new Map(Array.from(a,([s,c])=>[s,r.has(s)?{...c,proplannerId:r.get(s)}:c])),o=a=>a===void 0?void 0:new Map(Array.from(a,([s,c])=>[s,i.has(s)?{...c,proplannerId:i.get(s)}:c]));return{...t,beforeSnap:n(t.beforeSnap),afterSnap:n(t.afterSnap),beforeLinks:o(t.beforeLinks),afterLinks:o(t.afterLinks)}}};var xg=["parentId","correlativeId"];function fu(e,t){let r=new Set,i=n=>{let o=t(n);r.add(o===null?"0":String(o))};for(let n of e.activities){let o=String(n.id);if(n.kind===N.CREATED){i(o);continue}if(n.kind===N.DELETED){let c=n.fields;c&&"parentId"in c&&r.add(uu(c.parentId?.before));continue}let a=n.fields;!a||!xg.some(c=>c in a)||(i(o),"parentId"in a&&r.add(uu(a.parentId?.before)))}return r}function uu(e){return e==null?"0":String(e)}function Mg(e){return{...e,id:String(e.id),source:String(e.source),target:String(e.target),type:e.type,lag:Number(e.lag)}}function Ug(e){return{days:e.days,hours:e.hours,...e.dates?{dates:e.dates}:{},...e.customWeeks?{customWeeks:e.customWeeks}:{}}}function pu(e){return{id:String(e.id),worktime:Ug(e.worktime)}}function Pn(e,t,r,i=[]){let n=t.map(Mg),o=[...r.map(pu),...i.map(pu)];return{activities:[...e],links:n,calendars:o}}var w={TRACKED:"tracked",IGNORED:"ignored"};var yu={id:w.IGNORED,proplannerId:w.IGNORED,parentId:w.TRACKED,name:w.TRACKED,description:w.TRACKED,type:w.TRACKED,startDate:w.TRACKED,endDate:w.TRACKED,durationHours:w.TRACKED,constraintType:w.TRACKED,constraintDate:w.TRACKED,autoScheduling:w.TRACKED,calendarId:w.TRACKED,assignedDefaultCalendar:w.IGNORED,dateOrigin:w.TRACKED,progress:w.TRACKED,cost:w.TRACKED,usedCost:w.TRACKED,realCost:w.TRACKED,workHours:w.TRACKED,realWorkHours:w.TRACKED,ponderator:w.TRACKED,hasCustomPonderator:w.TRACKED,correlativeId:w.TRACKED,uniqueCorrelativeId:w.TRACKED,customId:w.TRACKED,subcontractId:w.TRACKED,isLookahead:w.TRACKED,hasLookaheadTasks:w.IGNORED,newActivityIds:w.TRACKED,hasNewActivities:w.TRACKED,isNewActivity:w.IGNORED,pendingRequestIds:w.IGNORED,responsableIds:w.TRACKED,tagIds:w.TRACKED,baselinePoints:w.IGNORED,baselineSnapshot:w.IGNORED,recursiveDurationHours:w.IGNORED,isCritical:w.IGNORED,freeSlackHours:w.IGNORED,calendarDuration:w.IGNORED,expectedProgress:w.IGNORED,expectedProgressBaseline:w.IGNORED,status:w.IGNORED,criticalPath:w.IGNORED},hu=Object.keys(yu).filter(e=>yu[e]===w.TRACKED),mu=new Set(["startDate","endDate","constraintDate","dateOrigin"]),Iu=new Set(["newActivityIds","responsableIds","tagIds"]);function gu(e){let t=hu.map(r=>[r,Bg(r,e[r])]);return Object.fromEntries(t)}function Bg(e,t){return mu.has(e)?t instanceof Date?new Date(t):null:Iu.has(e)?Array.isArray(t)?[...t]:[]:t}function ei(e,t){return Fa(e,t).length>0}function Fa(e,t){return hu.filter(r=>!Hg(r,e[r],t[r]))}function Hg(e,t,r){return mu.has(e)?Wg(t,r):Iu.has(e)?Vg(t,r):(t??null)===(r??null)}function Wg(e,t){let r=e instanceof Date?e.getTime():null,i=t instanceof Date?t.getTime():null;return r===i}function Vg(e,t){let r=new Set(Array.isArray(e)?e.map(String):[]),i=new Set(Array.isArray(t)?t.map(String):[]);if(r.size!==i.size)return!1;for(let n of r)if(!i.has(n))return!1;return!0}var Au={id:w.IGNORED,source:w.TRACKED,target:w.TRACKED,type:w.TRACKED,lag:w.TRACKED,freeSlackHours:w.IGNORED,isCritical:w.IGNORED,ganttId:w.IGNORED,sectorId:w.IGNORED,proplannerId:w.IGNORED},Kg=Object.keys(Au).filter(e=>Au[e]===w.TRACKED);function Ln(e,t){return Kg.some(r=>e[r]!==t[r])}function vu(e,t){let r=new Map(e.map(i=>[String(i.id),i]));return t.filter(i=>{let n=r.get(String(i.id));return n?Ln(n,i):!1})}function Xt(e){if(e==null||e===0)return!1;if(!(typeof e=="number"&&Number.isSafeInteger(e)&&e>0))throw new Error(`invalid proplannerId ${String(e)}`);return!0}function Cu(e,t){for(let r of e)Xt(r.proplannerId);for(let r of t)Xt(r.proplannerId)}var On=class e{trackingEnabled;initialized=!1;dirtyActivityIds=new Set;dirtyLinkIds=new Set;initialCalendarRepairIds=new Set;linksAtLastSave=new Map;activitiesAtLastSave=new Map;constructor(t=!0){this.trackingEnabled=t}fork(){let t=new e(!1);t.initialized=this.initialized;for(let[r,i]of this.linksAtLastSave)t.linksAtLastSave.set(r,F(i));for(let[r,i]of this.activitiesAtLastSave)t.activitiesAtLastSave.set(r,F(i));return t}init(t,r){if(this.trackingEnabled){Cu(t,r),this.snapshotActivities(t),this.snapshotLinks(r);for(let i of t)if(i.assignedDefaultCalendar){let n=String(i.id);this.initialCalendarRepairIds.add(n),this.dirtyActivityIds.add(n)}this.initialized=!0}}acknowledge(t,r,i=[],n=[],o,a){if(!this.trackingEnabled)return;let s=new Map(i.map(({id:p,proplannerId:y})=>[String(p),y])),c=new Map(n.map(({id:p,proplannerId:y})=>[String(p),y])),l=t.map(p=>({...p,proplannerId:s.get(String(p.id))??p.proplannerId})),d=r.map(p=>{let y=c.get(String(p.id));return y===void 0?{...p}:{...p,proplannerId:y}});if(Cu(l,d),this.snapshotActivities(l),this.snapshotLinks(d),!o||!a)return;let u=new Map(o.map(p=>[String(p.id),p])),f=new Map(a.map(p=>[String(p.id),p]));for(let p of l){let y=String(p.id);this.activityIsDirty(y,u.get(y)??null)&&this.dirtyActivityIds.add(y)}for(let p of o){let y=String(p.id);this.activityIsDirty(y,p)&&this.dirtyActivityIds.add(y)}for(let p of d){let y=String(p.id);this.linkIsDirty(y,f.get(y)??null)&&this.dirtyLinkIds.add(y)}for(let p of a){let y=String(p.id);this.linkIsDirty(y,p)&&this.dirtyLinkIds.add(y)}}snapshotActivities(t){if(this.trackingEnabled){this.activitiesAtLastSave.clear(),this.dirtyActivityIds.clear(),this.initialCalendarRepairIds.clear();for(let r of t){let i=String(r.id);if(!Xt(r.proplannerId)){this.dirtyActivityIds.add(i);continue}let n=gu(r);this.activitiesAtLastSave.set(String(r.id),{persistable:n,deletedSnapshot:{id:r.id,proplannerId:r.proplannerId,parentId:r.parentId,hadBaseline:r.baselineSnapshot!==null||r.baselinePoints.length>0}}),ei(r,n)&&this.dirtyActivityIds.add(i)}}}snapshotLinks(t){if(this.trackingEnabled){this.linksAtLastSave.clear(),this.dirtyLinkIds.clear();for(let r of t){let i=String(r.id);if(!Xt(r.proplannerId)){this.dirtyLinkIds.add(i);continue}this.linksAtLastSave.set(String(r.id),{id:r.id,proplannerId:r.proplannerId,source:r.source,target:r.target,lag:r.lag,type:r.type})}}}recordChanges(t,r,i,n){if(!(!this.trackingEnabled||!this.initialized)){for(let o of t){let a=String(o.id),s=i(a);this.activityIsDirty(a,s)?this.dirtyActivityIds.add(a):this.dirtyActivityIds.delete(a)}for(let o of r){let a=String(o.id),s=n(a);this.linkIsDirty(a,s)?this.dirtyLinkIds.add(a):this.dirtyLinkIds.delete(a)}}}activityIsDirty(t,r){let i=this.activitiesAtLastSave.get(t);return r===null?i!==void 0:this.initialCalendarRepairIds.has(t)||!Xt(r.proplannerId)||i===void 0||ei(r,i.persistable)}linkIsDirty(t,r){let i=this.linksAtLastSave.get(t);return r===null?i!==void 0:!Xt(r.proplannerId)||i===void 0||Ln(i,r)}acknowledgePersistedLookahead(t,r){if(!this.trackingEnabled||!this.initialized)return;let i=t.map(n=>{let o=typeof n=="string"?n:String(n.id),a=r(o),s=this.activitiesAtLastSave.get(o);if(a===null||s===void 0)throw new Error(`unknown persisted activity "${o}"`);return{activityId:o,acknowledgesLookahead:typeof n=="string"||!!n.fields?.isLookahead,acknowledgesProgress:typeof n!="string"&&!!n.fields?.progress,current:a,saved:s}});for(let{activityId:n,acknowledgesLookahead:o,acknowledgesProgress:a,current:s,saved:c}of i){let l={...c.persistable,...o?{isLookahead:s.isLookahead}:{},...a?{progress:s.progress,autoScheduling:s.autoScheduling}:{}};this.activitiesAtLastSave.set(n,{...c,persistable:l}),this.initialCalendarRepairIds.has(n)||!Xt(s.proplannerId)||ei(s,l)?this.dirtyActivityIds.add(n):this.dirtyActivityIds.delete(n)}}hasCheckpointActivityId(t){return this.activitiesAtLastSave.has(t)}hasCheckpointLinkId(t){return this.linksAtLastSave.has(t)}hasUnsavedChanges(){return this.trackingEnabled&&this.initialized&&(this.dirtyActivityIds.size>0||this.dirtyLinkIds.size>0)}newActivities(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyActivityIds){let n=t(i);n!==null&&!Xt(n.proplannerId)&&r.push(n)}return r}newLinks(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyLinkIds){let n=t(i);n!==null&&!Xt(n.proplannerId)&&r.push(n)}return r}deletedActivities(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyActivityIds){let n=this.activitiesAtLastSave.get(i);n&&t(i)===null&&r.push({...n.deletedSnapshot})}return r}deletedLinks(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyLinkIds){let n=this.linksAtLastSave.get(i);n&&t(i)===null&&r.push({...n})}return r}modifiedActivities(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyActivityIds){let n=t(i);if(n===null||!Xt(n.proplannerId))continue;let o=this.activitiesAtLastSave.get(i);(o===void 0||this.initialCalendarRepairIds.has(i)||ei(n,o.persistable))&&r.push(n)}return r}modifiedActivityFields(t){let r=new Map;if(!this.trackingEnabled||!this.initialized)return r;for(let i of this.dirtyActivityIds){let n=t(i),o=this.activitiesAtLastSave.get(i);if(!n||!o)continue;let a=Fa(n,o.persistable);a.length>0&&r.set(i,a)}return r}modifiedLinks(t){if(!this.trackingEnabled||!this.initialized)return[];let r=[];for(let i of this.dirtyLinkIds){let n=t(i);if(n===null||!Xt(n.proplannerId))continue;let o=this.linksAtLastSave.get(i);(o===void 0||Ln(o,n))&&r.push(n)}return r}clear(){this.initialized=!1,this.dirtyActivityIds.clear(),this.dirtyLinkIds.clear(),this.initialCalendarRepairIds.clear(),this.linksAtLastSave.clear(),this.activitiesAtLastSave.clear()}};var Su=1440*60*1e3,Tu=/^(\d{4})[/-](\d{1,2})[/-](\d{1,2})/,Nn=7,wa=[!1,!0,!0,!0,!0,!0,!1],Eu=new Set(["1","true"]),xa=gt.DURATION,Du=A.ASAP,_u={ASAP:A.ASAP,ALAP:A.ALAP,SNET:A.SNET,SNLT:A.SNLT,FNET:A.FNET,FNLT:A.FNLT,MSO:A.MSO,MFO:A.MFO,"AS SOON AS POSSIBLE":A.ASAP,"AS LATE AS POSSIBLE":A.ALAP,"START NO EARLIER THAN":A.SNET,"START NO LATER THAN":A.SNLT,"FINISH NO EARLIER THAN":A.FNET,"FINISH NO LATER THAN":A.FNLT,"MUST START ON":A.MSO,"MUST FINISH ON":A.MFO};function ku(e,t){let r=[],i=e.map(o=>{let a=Qg(o,t);return o.should_be_showed===!1&&r.push(a.id),a});eA(i);let n=new Set(i.map(o=>o.id));return rA(i,n,t.reporter,t.recordDiagnostic),{activities:i,activityIds:n,hiddenIds:r}}function jg(e,t,r,i){if(!e)return null;let n=_u[e.toUpperCase()];return n===void 0?(r(Lt.UNKNOWN_CONSTRAINT,i),t.warn(`[parseFromBackend] unknown constraint label "${e}" \u2014 defaulting to "asap"`),Du):n}function Yg(e,t,r){let i=jg(e.constraint,t,r,String(e.unique_id)),o=i!==A.ASAP&&i!==A.ALAP&&e.constraint_date?se(e.constraint_date):null;return{constraintType:i,constraintDate:o}}function Gg(e,t,r){if(e==null)return r;let i=String(e);return t.has(i)?i:r}function $g(e){if(e==null||e==="")return[];if(Array.isArray(e))return e.map(String);if(typeof e!="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(String):[]}catch{return[]}}function zg(e){if(typeof e!="object"||e===null||!("id"in e))return!1;let t=e.id;return typeof t=="string"||typeof t=="number"}function Ma(e){if(!Array.isArray(e))return[];let t=[];for(let r of e)zg(r)&&t.push(String(r.id));return t}function qg(e){return e==="0"?null:String(e)}function Jg(e){if(e==null)return null;if(!(typeof e=="number"&&(e===0||Number.isSafeInteger(e)&&e>0)))throw new Error(`invalid activity proplannerId ${String(e)}`);return e}function Xg(e,t){return typeof e.is_critical=="boolean"?e.is_critical:(t.error("[parseFromBackend] invalid activity is_critical \u2014 defaulting to false",new TypeError(`activity "${e.unique_id}" received ${typeof e.is_critical}`)),!1)}function Zg(e,t,r,i,n){return Array.isArray(e)?e.map(o=>An(o,t,{record:r,sampleId:i},n)).filter(o=>o!==null):[]}function Qg(e,t){let r=Gg(e.calendarId,t.knownCalendarIds,t.defaultCalendarId),i=e.calendarId==null||!t.knownCalendarIds.has(String(e.calendarId)),n=Number(e.progress),{constraintType:o,constraintDate:a}=Yg(e,t.reporter,t.recordDiagnostic),s=e.type===D.MILESTONE,c=se(e.start_date),l=s?c:se(e.end_date),d=s?0:Number(e.duration),u=Xg(e,t.reporter);return{id:String(e.unique_id),proplannerId:Jg(e.id),parentId:qg(e.parent_id),name:e.name,description:e.description??"",type:e.type,startDate:c,endDate:l,durationHours:be(d,t.hoursPerDay),constraintType:o,constraintDate:a,autoScheduling:Le(n),calendarId:r,assignedDefaultCalendar:r!=null&&i,dateOrigin:e.date_origin==null?null:se(e.date_origin),progress:n,cost:Number(e.cost),usedCost:Number(e.used_cost??0),realCost:Number(e.real_cost??0),workHours:Number(e.hhWorkTime),realWorkHours:Number(e.real_work??0),ponderator:Number(e.ponderator??0),hasCustomPonderator:e.hasCustomPonderator,correlativeId:e.correlative_id,uniqueCorrelativeId:e.unique_correlative_id,customId:tA(e),subcontractId:e.subcontractId,isLookahead:e.isOnLookahead,hasLookaheadTasks:Array.isArray(e.tasks)&&e.tasks.length>0,newActivityIds:$g(e.newActivitiesArray),hasNewActivities:e.hasNewActivities??!1,...e.isNewActivity===!0?{isNewActivity:!0}:{},pendingRequestIds:Ma(e.pendingRequests),responsableIds:Ma(e.responsables),tagIds:Ma(e.tags),baselinePoints:Zg(e.baseline_points,t.reporter,t.recordDiagnostic,String(e.unique_id),s),baselineSnapshot:null,recursiveDurationHours:be(Number(e.sumOfDurationRecursively??0),t.hoursPerDay),calendarDuration:Qt({type:e.type,startDate:c,endDate:l}),isCritical:u,freeSlackHours:null,expectedProgress:null,expectedProgressBaseline:null,status:null,criticalPath:null}}function tA(e){return e.has_childs?null:e.custom_id}function eA(e){let t=e.find(r=>r.correlativeId===0&&r.type===D.PROJECT);t&&(t.parentId=null)}function rA(e,t,r,i){for(let n of e)n.parentId!==null&&(t.has(n.parentId)||(r.warn(`[parseFromBackend] activity "${n.id}" references unknown parent "${n.parentId}" \u2014 re-parenting to root (null)`),i(Lt.ORPHAN_ACTIVITY,n.id),n.parentId=null))}function Ou(e,t,r,i=null){let a=(e!==void 0&&e.length>0?e:t??[]).map(c=>nA(c,i)),s=(r??[]).map(c=>oA(c,i));return{calendars:a,baseCalendars:s,knownCalendarIds:new Set(a.map(c=>c.id)),defaultCalendarId:iA(a)}}function iA(e){let t=e.find(i=>i.is_default);if(t)return t.id;let r=e[0];return r?r.id:null}function Nu(e,t){let r=uA(e.working_days),{days:i,hours:n}=dA(e,r),o=aA(t.exceptionsSource,t.exceptionRange),a={days:i,hours:n};return o&&(a.dates=o),{id:`${String(e.id)}${t.idSuffix}`,name:e.name,is_default:t.isDefault,...t.baseDefault!==void 0?{baseDefault:t.baseDefault}:{},worktime:a}}function nA(e,t){let r=e.baseDefault,i=typeof r=="boolean"?r:void 0;return Nu(e,{idSuffix:"",isDefault:!!e.is_default,baseDefault:i,exceptionsSource:e.exceptiondays,exceptionRange:t})}function oA(e,t){return Nu(e,{idSuffix:"-base",isDefault:!1,baseDefault:!!e.is_default,exceptionsSource:e.baseexceptiondays??e.exceptiondays,exceptionRange:t})}function aA(e,t){if(!Array.isArray(e)||e.length===0)return null;let r={};for(let i of e){if(!i)continue;let n=sA(i.from_date,i.to_date,t);if(n.length===0)continue;let o=cA(i);if(o!==void 0)for(let a of n)r[a]=o}return Object.keys(r).length>0?r:null}function sA(e,t,r){let i=Ru(e),n=Ru(t);if(i===null||n===null)return[];if(r&&(n<r.start||i>r.end))return[];let o=[],a=r?Math.max(i,r.start):i,s=r?Math.min(n,r.end):n;for(;a<=s;)o.push(String(a)),a+=Su;return o}function Ru(e){if(typeof e!="string")return null;let t=Tu.exec(e.trim());if(!t)return null;let r=Number(t[1]),i=Number(t[2]),n=Number(t[3]);return Number.isFinite(r)&&Number.isFinite(i)&&Number.isFinite(n)?Date.UTC(r,i-1,n):null}function cA(e){if(e.workable===!1)return!1;let t=e.shifts;if(Array.isArray(t)&&t.length>0){let r=lA(t);if(r.length>0)return r}}var Pu=/^\d{1,2}:\d{2}$/;function lA(e){let t=[];for(let r of e){let i=wu(r?.shift_string);if(!i)continue;if(!i.startsCsv.includes(",")&&!i.endsCsv.includes(",")){let s=i.startsCsv.trim(),c=i.endsCsv.trim();!bn(s)&&!bn(c)&&Pu.test(s)&&Pu.test(c)&&t.push(`${s}-${c}`);continue}let a=Fu(i.startsCsv,i.endsCsv).find(s=>s!==null);a&&t.push(a)}return t.sort(bu),t}function Lu(e){let t=e.indexOf("-"),r=t>0?e.slice(0,t):e,[i,n]=r.split(":");return(Number(i)||0)*60+(Number(n)||0)}function bu(e,t){return Lu(e)-Lu(t)}function dA(e,t){let r=Array.from({length:7},()=>[]),i=(l,d)=>{let u=Fu(l,d);for(let f=0;f<7;f+=1){let p=u[f],y=r[f];p&&y&&y.push(p)}},n=Array.isArray(e.shifts)&&e.shifts.length>0,o=typeof e.shift_start=="string"&&typeof e.shift_end=="string";if(n)for(let l of e.shifts){let d=wu(l?.shift_string);d&&i(d.startsCsv,d.endsCsv)}else o&&i(e.shift_start,e.shift_end);for(let l of r)l.sort(bu);let s=r.find((l,d)=>!!t[d]&&l.length>0)??[];return{days:t.map((l,d)=>{if(!l)return!1;let u=r[d];return u&&u.length>0?u:s}),hours:s}}function Fu(e,t){let r=Array.from({length:Nn},()=>null);if(typeof e!="string"||typeof t!="string")return r;let i=e.split(",").map(s=>s.trim()),n=t.split(",").map(s=>s.trim());if(!(i.length===n.length&&i.length>0&&i.length<=Nn))return r;let a=[...r];for(let s=0;s<i.length;s+=1){let c=i[s],l=n[s];bn(c)||bn(l)||(a[s]=`${c}-${l}`)}return a}function wu(e){if(typeof e!="string")return null;let t=e.indexOf("-");return t<=0?null:{startsCsv:e.slice(0,t),endsCsv:e.slice(t+1)}}function uA(e){if(typeof e!="string")return[...wa];let t=e.split(",").map(r=>r.trim());return t.length!==Nn?[...wa]:t.map(r=>Eu.has(r))}var fA=new Set(["false","null"]);function bn(e){return!e||fA.has(e)}function pA(e){if(typeof e!="string")return null;let t=Bs(e);return t||(ai(e)?e:null)}function yA(e){if(e==null)return;if(!(typeof e=="number"&&(e===0||Number.isSafeInteger(e)&&e>0)))throw new Error(`invalid link proplannerId ${String(e)}`);return e}function Mu(e,t){let r=[];for(let i of e)try{r.push(hA(i,t.knownActivityIds,t.hoursPerDay))}catch(n){t.recordDiagnostic(Lt.INVALID_LINK,String(i.unique_id??i.id)),t.reporter.warn("[parseFromBackend] dropping invalid link",n)}return mA(r,t.recordDiagnostic)}function hA(e,t,r){let i=String(e.unique_id??e.id),n=String(e.source_id??e.source??""),o=String(e.target_id??e.target??"");if(!t.has(n))throw new Error(`[parseFromBackend] link "${i}" source "${n}" does not exist`);if(!t.has(o))throw new Error(`[parseFromBackend] link "${i}" target "${o}" does not exist`);let a=pA(e.type);if(a===null)throw new Error(`[parseFromBackend] link "${i}" has invalid type "${String(e.type)}"`);let s=e.ganttId,c=e.sectorId,l=yA(e.id);return{id:i,source:n,target:o,type:a,lag:Wt(Number(e.lag??0),r),freeSlackHours:null,isCritical:!1,...typeof s=="number"?{ganttId:s}:{},...typeof c=="number"?{sectorId:c}:{},...l===void 0?{}:{proplannerId:l}}}function mA(e,t){let r=new Map;for(let i of e){let n=`${i.source}-${i.target}-${i.type}`,o=r.get(n);if(!o){r.set(n,i);continue}let a=xu(i)>xu(o),s=a?o:i;t(Lt.DUPLICATE_LINK,s.id),a&&r.set(n,i)}return[...r.values()]}function xu(e){let t=Number(e.id);return Number.isFinite(t)?t:-1/0}function IA(e){if(typeof e!="string")return xa;switch(e.toUpperCase()){case gt.DURATION:return gt.DURATION;case gt.COST:return gt.COST;case gt.WORK_HOURS:return gt.WORK_HOURS;default:return xa}}function gA(e){let t=e.custom_id_prefix;return typeof t=="string"&&t.length>0?t:void 0}function AA(e){let t=e.custom_id_increment;return typeof t=="string"?t:typeof t=="number"&&Number.isFinite(t)?String(t):void 0}function Uu(e){let t=gA(e),r=AA(e),i=e.update_duration_for_primavera_for_end_date===!0;return{id:String(e.id),name:e.name,hoursPerDay:e.hoursPerDay,hoursPerWeek:e.hoursPerWeek,dateFormat:e.dateFormat,projectId:e.projectId,companyId:e.companyId,...t!==void 0?{customIdPrefix:t}:{},...r!==void 0?{customIdIncrement:r}:{},...i?{updateDurationForPrimaveraEndDate:!0}:{},activityCreter:IA(e.activity_creter),statusCriteria:So,ganttId:null}}function Fn(e,t=er,r=Cr){let i=Uu(e.sector),{calendars:n,baseCalendars:o,knownCalendarIds:a,defaultCalendarId:s}=Ou(e.calendars,e.sector.calendars,e.baseCalendars,vA(e.activities)),{activities:c,activityIds:l,hiddenIds:d}=ku(e.activities,{knownCalendarIds:a,defaultCalendarId:s,hoursPerDay:i.hoursPerDay,reporter:t,recordDiagnostic:r}),u=Mu(e.links,{knownActivityIds:l,hoursPerDay:i.hoursPerDay,reporter:t,recordDiagnostic:r});return{sector:i,activities:c,links:u,calendars:n,baseCalendars:o,viewStateSeed:{hiddenIds:d}}}function vA(e){let t=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY;for(let o of e){let a=new Date(o.start_date).getTime(),s=new Date(o.end_date).getTime();Number.isFinite(a)&&(t=Math.min(t,a)),Number.isFinite(s)&&(r=Math.max(r,s))}if(!Number.isFinite(t)||!Number.isFinite(r))return null;let i=new Date(t),n=new Date(r);return i.setFullYear(i.getFullYear()-1),n.setFullYear(n.getFullYear()+1),{start:i.getTime(),end:n.getTime()}}function Ua(e={}){let t=e.seed??0,r=i=>{i>t&&(t=i)};if(e.knownIds)for(let i of e.knownIds){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)}return{fork(){return Ua({seed:t})},next(){return t+=1,String(t)},bump(i){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)},snapshot(){return t},restore(i){t=i}}}function Ba(e={}){let t=e.seed??0,r=i=>{i>t&&(t=i)};if(e.knownIds)for(let i of e.knownIds){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)}return{fork(){return Ba({seed:t})},next(){return t+=1,String(t)},bump(i){let n=typeof i=="number"?i:Number(i);Number.isFinite(n)&&r(n)},snapshot(){return t},restore(i){t=i}}}function Ha(e={}){let t=e.seed??0,r=i=>{Number.isFinite(i)&&i>0&&i<=9999999&&i>t&&(t=i)};if(e.knownIds)for(let i of e.knownIds){if(i==null)continue;let n=typeof i=="number"?i:Number(i);r(n)}return{fork(){return Ha({seed:t})},next(){return t+=1,String(t)},bump(i){if(i==null)return;let n=typeof i=="number"?i:Number(i);r(n)},snapshot(){return t},restore(i){t=i}}}function Bu(e){return!!e&&typeof e=="string"&&e.trim().length>0}function wn(e){if(!e||typeof e!="string"||e.trim().length===0)return"";let t=e.match(/^(.*?)(\d+)$/);return t?t[1]??"":e}function xn(e){if(!e||typeof e!="string"||e.trim().length===0)return"";let t=e.match(/(\d+)$/);return t?t[1]??"":""}function Hu(e){if(!e||typeof e!="object")return"";let t=e.customId;return typeof t=="string"?t:""}function Wu(e,t){return!t&&Bu(e)}function Vu(e,t){return t&&Bu(e)}function ri(e){return typeof e=="string"&&e.length>0&&/^\d+$/.test(e)}function Mn(e){if(!ri(e))return 0n;try{return BigInt(e)}catch{return 0n}}function CA(e,t){if(typeof e!="bigint")return"";let r=e.toString();if(!ri(t))return r;let i=t.length;return r.padStart(i,"0")}function jt(e,t){let r=Mn(e),i=Mn(t),n=r+i;return CA(n,e)}function Un(e,t){let r=Mn(e),i=Mn(t);return r<i?-1:r>i?1:0}function Bn(e,t){return Un(e,t)<=0?e:t}function Hn(e,t){return Un(e,t)>=0?e:t}function Ku(e){if(!e||e.length===0)throw new Error("minSuffixFromArray requires non-empty array");return e.reduce((t,r)=>Bn(t,r))}function ju(e){if(!e||e.length===0)throw new Error("maxSuffixFromArray requires non-empty array");return e.reduce((t,r)=>Hn(t,r))}var le={PARENT_CONVERSION:"parentConversion",PASTE_REFERENCE:"pasteReference",NO_CONTEXT:"noContext"};function Yu(e){return{prefix:e,baseSuffix:null}}function Gu(e,t){let r=xn(e);return{prefix:wn(e),baseSuffix:jt(r,t)}}function $u(e){return{prefix:e,baseSuffix:null}}function zu(e,t){return Wu(e,t)?le.PARENT_CONVERSION:Vu(e,t)?le.PASTE_REFERENCE:le.NO_CONTEXT}function qu(e){return{...e,usedSuffixes:new Set(e.usedSuffixes)}}var Wn=class e{prefixMap=new Map;processedIds=new Set;_journalPrefixBefore=null;_journalIds=null;beginCustomIdTransaction(){this._journalPrefixBefore=new Map,this._journalIds=[]}commitCustomIdTransaction(){this._journalPrefixBefore=null,this._journalIds=null}rollbackCustomIdTransaction(){let t=this._journalPrefixBefore,r=this._journalIds;if(!(t===null||r===null)){for(let[i,n]of t)n===null?this.prefixMap.delete(i):this.prefixMap.set(i,n);for(let i of[...r].reverse())i.hadId?this.processedIds.add(i.customId):this.processedIds.delete(i.customId);this._journalPrefixBefore=null,this._journalIds=null}}_noteCustomIdBefore(t){if(this._journalPrefixBefore===null||this._journalIds===null)return;let{prefix:r}=this.analyzeCustomId(t);if(!this._journalPrefixBefore.has(r)){let i=this.prefixMap.get(r);this._journalPrefixBefore.set(r,i?qu(i):null)}this._journalIds.push({customId:t,hadId:this.processedIds.has(t)})}_ensureFreshBounds(t){let r=this.prefixMap.get(t);if(!r?.boundsDirty)return;r.boundsDirty=!1;let i=Array.from(r.usedSuffixes);r.min=Ku(i),r.max=ju(i),r.quantity=i.length,this._recalculateNext(t)}defaultPrefix;suffixIncrement;constructor(t={}){this.defaultPrefix=t.defaultPrefix??"A",this.suffixIncrement=t.suffixIncrement??"10"}fork(){let t=new e({defaultPrefix:this.defaultPrefix,suffixIncrement:this.suffixIncrement});for(let[r,i]of this.prefixMap)t.prefixMap.set(r,qu(i));for(let r of this.processedIds)t.processedIds.add(r);return t}extractPrefix(t){return wn(t)}extractSuffix(t){return xn(t)}analyzeCustomId(t){return{prefix:this.extractPrefix(t),suffix:this.extractSuffix(t)}}_updatePrefixStats(t,r){if(this._ensureFreshBounds(t),!this.prefixMap.has(t)){this.prefixMap.set(t,{min:r,max:r,next:r,quantity:1,usedSuffixes:new Set([r])}),this._recalculateNext(t);return}let i=this.prefixMap.get(t);i.usedSuffixes.has(r)||(i.usedSuffixes.add(r),i.min=Bn(r,i.min),i.max=Hn(r,i.max),i.quantity+=1,this._recalculateNext(t))}_recalculateNext(t){let r=this.prefixMap.get(t);if(!r)return;let i=this.getNextAvailableSuffix(t);r.next=i??this.suffixIncrement}getPrefixStats(t){this._ensureFreshBounds(t);let r=this.prefixMap.get(t);return r?{min:r.min,max:r.max,next:r.next,quantity:r.quantity}:null}getNextSuffix(t){this._ensureFreshBounds(t);let r=this.prefixMap.get(t);return r?r.next:this.suffixIncrement}getAllPrefixes(){return Array.from(this.prefixMap.keys())}registerCustomId(t){if(!t||typeof t!="string")return{prefix:"",suffix:""};let{prefix:r,suffix:i}=this.analyzeCustomId(t);if(!r&&!i)return{prefix:r,suffix:i};if(this._noteCustomIdBefore(t),this._ensureFreshBounds(r),this.prefixMap.has(r)){let n=this.prefixMap.get(r);n.usedSuffixes.has(i)||(n.usedSuffixes.add(i),n.min=Bn(i,n.min),n.max=Hn(i,n.max),n.quantity+=1,this._recalculateNext(r))}else this.prefixMap.set(r,{min:i,max:i,next:jt(i,this.suffixIncrement),quantity:1,usedSuffixes:new Set([i])});return this.processedIds.add(t),{prefix:r,suffix:i}}releaseCustomId(t=null){if(!t||typeof t!="string")return{prefix:"",suffix:""};let{prefix:r,suffix:i}=this.analyzeCustomId(t);if(!this.prefixMap.has(r))return{prefix:r,suffix:i};this._noteCustomIdBefore(t);let n=this.prefixMap.get(r);return n.usedSuffixes.has(i)&&(n.usedSuffixes.delete(i),n.quantity-=1,n.usedSuffixes.size===0?this.prefixMap.delete(r):n.boundsDirty=!0),this.processedIds.delete(t),{prefix:r,suffix:i}}trackCustomIdChange(t,r){let i=this.releaseCustomId(t),n=this.registerCustomId(r);return{oldPrefix:i.prefix,oldSuffix:i.suffix,newPrefix:n.prefix,newSuffix:n.suffix}}_exceedsMaxLength(t){return t.length>20}_shouldSearchForGaps(t){if(this._ensureFreshBounds(t),!this.prefixMap.has(t))return!1;let r=this.prefixMap.get(t);return`${t}${jt(r.max,this.suffixIncrement)}`.length>20}_suffixForUnknownPrefix(t,r){let i=r&&ri(r)?r:this.suffixIncrement;return`${t}${i}`.length>20?null:i}_findFirstAvailableGap(t){if(this._ensureFreshBounds(t),!this.prefixMap.has(t))return null;let r=this.prefixMap.get(t),i=this.suffixIncrement;for(;Un(i,r.max)<0;){if(`${t}${i}`.length>20)return null;if(!r.usedSuffixes.has(i))return i;i=jt(i,this.suffixIncrement)}return null}_generateDefaultCustomId(){let t=this.getNextAvailableSuffix(this.defaultPrefix);if(t===null){if(this._shouldSearchForGaps(this.defaultPrefix)){let r=this._findFirstAvailableGap(this.defaultPrefix);if(r!==null)return`${this.defaultPrefix}${r}`}return`${this.defaultPrefix}${this.suffixIncrement}`}return`${this.defaultPrefix}${t}`}getNextAvailableSuffix(t,r=null){if(this._ensureFreshBounds(t),!this.prefixMap.has(t))return this._suffixForUnknownPrefix(t,r);let i=this.prefixMap.get(t),n=this.suffixIncrement;if(!r||!ri(r)){let s=jt(i.max,n);return`${t}${s}`.length>20?null:s}let o=r;for(let s=0;s<100;s++){if(`${t}${o}`.length>20)return null;if(!i.usedSuffixes.has(o))return o;o=jt(o,n)}let a=jt(i.max,n);return`${t}${a}`.length>20?null:a}generateNextCustomId(t){let r=this.getNextAvailableSuffix(t);if(r===null)return this._generateDefaultCustomId();if(this.prefixMap.has(t)){let n=this.prefixMap.get(t),o=0;for(;n.usedSuffixes.has(r)&&o<1e4;){let a=this.getNextAvailableSuffix(t,jt(r,this.suffixIncrement));if(a===null)return this._generateDefaultCustomId();r=a,o++}}let i=`${t}${r}`;return this._exceedsMaxLength(i)&&(i=this._generateDefaultCustomId()),i}populateFromActivities(t){if(!Array.isArray(t))return this;let r=[...new Set(t.filter(i=>i&&typeof i.customId=="string"&&i.customId).map(i=>i.customId))];for(let i of r){if(this.processedIds.has(i))continue;let{prefix:n,suffix:o}=this.analyzeCustomId(i);(n||o)&&(this._updatePrefixStats(n,o),this.processedIds.add(i))}return this}getDefaults(){return{prefix:this.defaultPrefix,increment:this.suffixIncrement}}generateCustomIdForNewChild(t){let{activity:r,useActivityCustomIdAsReference:i=!1}=t,n=Hu(r),o=zu(n,i),{prefix:a,baseSuffix:s}=this._applyGenerationStrategy(o,n),c=null;if(o===le.PARENT_CONVERSION&&this.prefixMap.has(a)){this._ensureFreshBounds(a);let f=this.prefixMap.get(a).max;c=jt(f,this.suffixIncrement)}o===le.PARENT_CONVERSION&&this.releaseCustomId(n);let l=o===le.PARENT_CONVERSION&&c?c:s,d=this.getNextAvailableSuffix(a,l);if(d===null){let f=this._generateDefaultCustomId();return this.registerCustomId(f),f}let u=`${a}${d}`;return this._exceedsMaxLength(u)&&(u=this._generateDefaultCustomId()),this.registerCustomId(u),u}_applyGenerationStrategy(t,r){switch(t){case le.PARENT_CONVERSION:return Yu(this.defaultPrefix);case le.PASTE_REFERENCE:return Gu(r,this.suffixIncrement);default:return $u(this.defaultPrefix)}}generateCustomIdForRestoredChild(t=null){if(t){let i=t.trim();if(i.length>0){let n=this.extractPrefix(i),o=this.extractSuffix(i),a=jt(o,this.suffixIncrement),s=this.getNextAvailableSuffix(n,a);if(s===null){let l=this._generateDefaultCustomId();return this.registerCustomId(l),l}let c=`${n}${s}`;return this._exceedsMaxLength(c)&&(c=this._generateDefaultCustomId()),this.registerCustomId(c),c}}let r=this.generateNextCustomId(this.defaultPrefix);return this.registerCustomId(r),r}clear(){this.prefixMap.clear(),this.processedIds.clear()}getTotalPrefixes(){return this.prefixMap.size}hasPrefix(t){return this.prefixMap.has(t)}isCustomIdInUse(t,r=null){if(!t||typeof t!="string"||!t.trim())return!1;let i=t.trim();return r&&i===r.trim()?!1:this.processedIds.has(i)}};var SA=1,TA=-1;function EA(e,t){return!e&&!t?null:e&&t?0:e?SA:TA}function Ju(e){return e==null}function Xu(e,t){let r=t.indexOf(String(e));return r===-1?t.length:r}function DA(e,t,r){return e instanceof Date&&t instanceof Date?e.getTime()-t.getTime():typeof e=="number"&&typeof t=="number"?e-t:typeof e=="boolean"&&typeof t=="boolean"?Number(e)-Number(t):Array.isArray(e)&&Array.isArray(t)?e.length-t.length:String(e).localeCompare(String(t),r,{sensitivity:"base",numeric:!0})}function _A(e,t){let r=fe(e.field);return r===null?null:(i,n)=>{let o=r.extract(i,t),a=r.extract(n,t),s=EA(Ju(o),Ju(a));if(s!==null)return s;let c=r.valueKind===O.ENUM?Xu(o,r.order)-Xu(a,r.order):DA(o,a,t.locale);return e.direction===Pe.DESCENDING?-c:c}}function Zu(e,t){let r=e.rules.map(i=>_A(i,t)).filter(i=>i!==null);return r.length===0?null:(i,n)=>{for(let o of r){let a=o(i,n);if(a!==0)return a}return 0}}function Qu(e){let t=[];e.forEachActivity((r,i)=>{r.type===D.PROJECT&&e.getChildren(String(i)).length===0&&t.push(String(i))});for(let r of t)e.setActivityField(r,x.TYPE,tr),kA(e,r)}function kA(e,t){let r=e.getActivity(t);if(!r||!r.startDate||r.durationHours==null)return;let i=new Date(r.startDate);i.setUTCHours(0,0,0,0);let n=e.getClosestWorkTime({date:i,dir:K.FUTURE,task:r});if(n.getTime()===r.startDate.getTime())return;let o=e.calculateEndDate({startDate:n,durationHours:r.durationHours,task:r});e.setActivityField(t,x.START_DATE,n),e.setActivityField(t,x.END_DATE,o)}function tf(e){let t=[],r=[];e.forEachActivity((n,o)=>{n.parentId===null&&t.push(String(o))});let i=n=>{let o=e.getActivity(n);if(!o)return 0;let a=[...e.getChildren(n)],s=a.length===0?Nt(o.workHours,o.progress):a.reduce((c,l)=>c+i(String(l)),0);return e.setActivityField(n,x.REAL_WORK_HOURS,s),r.push(n),s};for(let n of t)i(n);return r}async function ef(e){let{state:t,sector:r,scheduler:i,skipAutoSchedule:n,now:o}=e;if(St(t),r.updateDurationForPrimaveraEndDate&&PA(t),LA(t),tf(t),n){Ur(t),o&&(Me(t,o),ce(t,r.statusCriteria));return}let a=await i.schedule({});Fr(t,a),OA(t),RA(t),await ir(t,void 0,!1),Ur(t),o&&(Me(t,o),ce(t,r.statusCriteria))}function RA(e){e.forEachActivity(t=>{t.autoScheduling||!t.startDate||t.durationHours==null||e.getChildren(t.id).length>0||(t.endDate=e.calculateEndDate({startDate:t.startDate,durationHours:t.durationHours,task:t}),t.calendarDuration=Qt(t))})}function PA(e){e.forEachActivity(t=>{!t.startDate||!t.endDate||(t.durationHours=e.calculateDuration({startDate:t.startDate,endDate:t.endDate,task:t}))})}function LA(e){e.forEachActivity(t=>{let r=t.constraintType;if(!r||!t.constraintDate)return;let i=t.constraintDate;if(t.type===D.MILESTONE&&(i.getUTCHours()!==0||i.getUTCMinutes()!==0))return;let n=e.calendarReader.getCalendar(String(t.calendarId));n&&(t.constraintDate=ne(t.constraintDate,n,r))})}function OA(e){e.forEachActivity(t=>{if(t.type!==D.MILESTONE)return;let r=t.constraintType;if(!r||!t.constraintDate)return;let i=e.calendarReader.getCalendar(String(t.calendarId));i&&(t.constraintDate=ne(t.constraintDate,i,r))})}var Zt={READY:"ready",DESTROYED:"destroyed",POISONED:"poisoned"};function rf(e){let t=e.clock??null,r=t?.()??null,i=r?xi(r):null,n=e.reporter??er,o=ed(),a=Fn({sector:e.sector,activities:e.activities,links:e.links,calendars:e.calendars,baseCalendars:e.baseCalendars},n,o.record),s=a.sector;s.statusCriteria=zi(e.statusCriteria),s.ganttId=e.ganttId??null;let c=a.calendars,l=a.baseCalendars??[],d=Pn(a.activities,a.links,a.calendars,l),u=E=>Zu(E,Re(s.hoursPerDay)),f=new Tr(d,u);f.hydrateViewState({hiddenIds:a.viewStateSeed.hiddenIds});let p=new rr(f,n);Qu(f);let y=Ua({knownIds:a.activities.map(E=>E.id)}),g=Ba({seed:r?.getTime()??0,knownIds:a.links.map(E=>E.id)}),C=Ha({knownIds:a.activities.map(E=>E.uniqueCorrelativeId)}),L=new Wn({defaultPrefix:s.customIdPrefix,suffixIncrement:s.customIdIncrement});if(L.populateFromActivities(a.activities),e.baselinePoints&&e.baselinePoints.length>0){let E=l.find(I=>I.baseDefault)?.id??null;vn(f,e.baselinePoints,i,n,E,o.record)}let T=ef({state:f,sector:s,scheduler:p,skipAutoSchedule:e.skipInitialAutoSchedule===!0,now:i??void 0});return{sector:s,state:f,scheduler:p,activityIdGen:y,linkIdGen:g,uidGen:C,customIdTracker:L,calendars:c,baseCalendars:l,clock:t,reporter:n,loadDiagnostics:o.snapshot,initPromise:T}}function Dr(e){if(e===void 0)return["undefined"];if(e===null)return["null"];if(typeof e=="string")return["string",e];if(typeof e=="boolean")return["boolean",e];if(typeof e=="number")return["number",Object.is(e,-0)?"-0":String(e)];if(typeof e=="bigint")return["bigint",String(e)];if(e instanceof Date)return["date",String(e.getTime())];if(Array.isArray(e))return["array",e.map(Dr)];if(e instanceof Map)return["map",Array.from(e,([t,r])=>[Dr(t),Dr(r)]).sort((t,r)=>JSON.stringify(t).localeCompare(JSON.stringify(r)))];if(e instanceof Set)return["set",Array.from(e,Dr).sort((t,r)=>JSON.stringify(t).localeCompare(JSON.stringify(r)))];if(typeof e=="object")return["object",Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,Dr(r)])];throw new TypeError(`Unsupported canonical value: ${typeof e}`)}function Ye(e){return JSON.stringify(Dr(e))}function Wa(e,t){let r=new Map(e.map(a=>[String(a.id),a])),i=new Map(t.map(a=>[String(a.id),a])),n=[...new Set([...r.keys(),...i.keys()])].sort(),o=[];for(let a of n){let s=i.get(a),c=r.get(a);if(c===void 0){o.push({id:a,kind:N.DELETED,after:null});continue}if(s===void 0){o.push({id:a,kind:N.CREATED,after:F(c)});continue}let l=NA(s,c);Object.keys(l).length>0&&o.push({id:a,kind:N.UPDATED,fields:l,after:F(c)})}return o}function NA(e,t){let r={},i=[...new Set([...Object.keys(e),...Object.keys(t)])].sort();for(let n of i)Ye(e[n])!==Ye(t[n])&&(r[n]={before:F(e[n]),after:F(t[n])});return r}function bA(e,t){let r=new Set(t.selectedIds.map(String)),i=new Set(e.selectedIds.map(String)),n=new Set(t.hiddenIds.map(String)),o=new Set(e.hiddenIds.map(String)),a=e.activities.map(({id:c})=>String(c)).sort(),s=[];for(let c of a){let l=r.has(c),d=i.has(c),u=!n.has(c),f=!o.has(c);l===d&&u===f||s.push({activityId:c,...l===d?{}:{checked:{before:l,after:d}},...u===f?{}:{visible:{before:u,after:f}}})}return s}function nf(e,t){let r=Ye(e.order)!==Ye(t.order);return{source:{kind:oe.INIT},activities:Wa(e.activities,t.activities),links:Wa(e.links,t.links),calendars:Wa(e.calendars,t.calendars),trackingEvents:[],effects:[],viewState:bA(e,t),...r?{order:F(e.order)}:{}}}var _r={MOVE:"move",RESIZE_START:"resize-start",RESIZE_END:"resize-end"},FA=()=>({constantStart:null,variableStartOffset:null,constantEnd:null,variableEndOffset:null}),Va=(e,t)=>e===null?t:Math.min(e,t),Ka=(e,t)=>e===null?t:Math.max(e,t);function af(e,t,r){let i=[...new Set(t.kind===_r.MOVE?t.activityIds.map(String):[String(t.activityId)])];if(i.length===0)throw new Error("[ScheduleCore] date gesture has no participants");let n=wA(e,t,i);return xA(e,i,n),{getDates(o,a){if(r(),!Number.isFinite(a))throw new Error("[ScheduleCore] invalid date gesture edge");let s=n.get(String(o));if(!s)return null;let c=UA(s,a),l=BA(s,a);if(c===null||l===null)throw new Error(`[ScheduleCore] incomplete date gesture bounds for ${String(o)}`);return{startTimeMs:c,endTimeMs:l}}}}function wA(e,t,r){let i=new Map,n=t.kind===_r.MOVE?String(t.anchorActivityId):null,o=n===null?null:of(e,n);if(n!==null&&!r.includes(n))throw new Error("[ScheduleCore] move anchor is not a participant");for(let a of r){let s=of(e,a);if(t.kind===_r.MOVE){let c=o.startDate.getTime();i.set(a,{constantStart:null,variableStartOffset:s.startDate.getTime()-c,constantEnd:null,variableEndOffset:s.endDate.getTime()-c})}else t.kind===_r.RESIZE_START?i.set(a,{constantStart:null,variableStartOffset:0,constantEnd:s.endDate.getTime(),variableEndOffset:null}):i.set(a,{constantStart:s.startDate.getTime(),variableStartOffset:null,constantEnd:null,variableEndOffset:0})}return i}function xA(e,t,r){let i=Hr(e,new Set(t));for(let n of i){let o=FA();for(let a of e.getChildren(n)){let s=r.get(a);if(s){MA(o,s);continue}let c=e.getActivity(a);if(!c)throw new Error(`[ScheduleCore] missing child ${a} while previewing parent ${n}`);o.constantStart=Va(o.constantStart,c.startDate.getTime()),o.constantEnd=Ka(o.constantEnd,c.endDate.getTime())}r.set(n,o)}}function of(e,t){let r=e.getActivity(t);if(!r)throw new Error(`[ScheduleCore] missing date gesture activity ${t}`);if(e.hasChildren(t))throw new Error(`[ScheduleCore] summary activity ${t} cannot be dragged directly`);return r}function MA(e,t){t.constantStart!==null&&(e.constantStart=Va(e.constantStart,t.constantStart)),t.variableStartOffset!==null&&(e.variableStartOffset=Va(e.variableStartOffset,t.variableStartOffset)),t.constantEnd!==null&&(e.constantEnd=Ka(e.constantEnd,t.constantEnd)),t.variableEndOffset!==null&&(e.variableEndOffset=Ka(e.variableEndOffset,t.variableEndOffset))}function UA(e,t){if(e.variableStartOffset===null)return e.constantStart;let r=t+e.variableStartOffset;return e.constantStart===null?r:Math.min(e.constantStart,r)}function BA(e,t){if(e.variableEndOffset===null)return e.constantEnd;let r=t+e.variableEndOffset;return e.constantEnd===null?r:Math.max(e.constantEnd,r)}var ja=Symbol("ScheduleCore.fork.source");function HA(e){return e.kind===m.PERSISTENCE_ACKNOWLEDGE||e.kind===m.ACTIVITY_LOOKAHEAD_SYNC&&e.acknowledgePersistedLookahead===!0}function WA(e){for(let t of e.activities)if(t.kind===N.DELETED||t.kind===N.UPDATED&&t.fields!==void 0&&"parentId"in t.fields)return!0;return!1}function VA(e,t){let r=[];for(let i of e.activities){let n=t.getActivity(i.id);if(n===null)return null;r.push(n)}return r}function KA(e,t,r){if(e===null||e.filter!==t)return!1;let i=e.context.hoursPerDay===r.hoursPerDay,n=e.context.locale===r.locale;return i&&n}var kr=class e{activities;links;calendars;selection;view;baselines;impactRequests;persistence;history;projection;criticalPath;diagnostics;_activityClipboard={value:null};_status=Zt.READY;coreRuntime;_isFork;_undo=new Rn;_opQueue=Promise.resolve();_scheduleRevision=0;_stateRevision=0;_pendingScheduleRevision=0;_criticalPathRevision=-1;_activeCriticalPath=null;constructor(t){if(Object.assign(this,Za(this)),ja in t){this._isFork=!0;let n=t[ja],o=n.coreRuntime.state.fork();this.coreRuntime={state:o,scheduler:new rr(o,n.coreRuntime.reporter),sector:F(n.coreRuntime.sector),activityIdGenerator:n.coreRuntime.activityIdGenerator.fork(),linkIdGenerator:n.coreRuntime.linkIdGenerator.fork(),uniqueCorrelativeIdGenerator:n.coreRuntime.uniqueCorrelativeIdGenerator.fork(),customIdTracker:n.coreRuntime.customIdTracker.fork(),calendars:new Map(Array.from(n.coreRuntime.calendars,([a,s])=>[a,F(s)])),baseCalendars:F(n.coreRuntime.baseCalendars),clock:n.coreRuntime.clock,reporter:n.coreRuntime.reporter,loadDiagnostics:n.coreRuntime.loadDiagnostics},this._activityClipboard.value=F(n._activityClipboard.value),this._undo=n._undo.fork(),this._saveTracker=n._saveTracker.fork(),this._scheduleRevision=n._scheduleRevision,this._stateRevision=n._stateRevision,this._pendingScheduleRevision=n._scheduleRevision,this._criticalPathRevision=n._criticalPathRevision,this._initPromise=Promise.resolve(),this._criticalPathReady=Promise.resolve(null),this._ready=this._initPromise;return}this._isFork=!1;let r=rf(t);this.coreRuntime={state:r.state,scheduler:r.scheduler,sector:r.sector,activityIdGenerator:r.activityIdGen,linkIdGenerator:r.linkIdGen,uniqueCorrelativeIdGenerator:r.uidGen,customIdTracker:r.customIdTracker,clock:r.clock,calendars:new Map(r.calendars.map(n=>[n.id,n])),baseCalendars:r.baseCalendars,reporter:r.reporter,loadDiagnostics:r.loadDiagnostics},this._initPromise=r.initPromise.then(()=>{this._status!==Zt.DESTROYED&&this._saveTracker.init(this.coreRuntime.state.getAllActivities(),this.getAllLinksView())}),this._criticalPathReady=this._initPromise.then(()=>this._startCriticalPathForCurrentRevision());let i=t.criticalPathOnLoad===!0;this._ready=i?this._criticalPathReady.then(()=>{}):this._initPromise}get ready(){return this._ready}fork(){return this._enqueue(async()=>(await this._ready,this.assertReady(),new e({[ja]:this})))}get criticalPathReady(){return this._criticalPathReady}get status(){return this._status}getSector(){return F(this.coreRuntime.sector)}getLoadDiagnostics(){return this.assertReady(),this.coreRuntime.loadDiagnostics()}getActivityView(t){return this.assertReady(),_a(this.coreRuntime.state,t)}getProgressEditability(t){this.assertReady();let r=_a(this.coreRuntime.state,t);if(!r)return null;let i=Pa(this.coreRuntime.state,{hoursPerDay:this.coreRuntime.sector.hoursPerDay,dateFormat:this.coreRuntime.sector.dateFormat});return Ui.canEdit(r,i.hierarchy)}createDateGesturePreview(t){this.assertReady();let r=this._scheduleRevision;return af(this.coreRuntime.state,t,()=>{if(this.assertReady(),this._scheduleRevision!==r)throw new Error("[ScheduleCore] date gesture preview is stale")})}getAllActivitiesView(){return this.assertReady(),jd(this.coreRuntime.state)}getIndentTargetParentIds(t){this.assertReady();let r=gn(t.map(i=>String(i)),this.coreRuntime.state);return[...new Set(r.allowedMoves.map(i=>String(i.newParentId)))]}getChildrenView(t){return this.assertReady(),$d(this.coreRuntime.state,t)}getLinkView(t){return this.assertReady(),Ra(this.coreRuntime.state,t)}getLinksForActivityView(t){this.assertReady();let r=this.coreRuntime.state,i=[],n=new Set,o=a=>{if(n.has(a))return;n.add(a);let s=Ra(r,a);s&&i.push(s)};for(let a of r.getOutgoingLinkIds(t))o(a);for(let a of r.getIncomingLinkIds(t))o(a);return i}getAllLinksView(){return this.assertReady(),Jd(this.coreRuntime.state)}auditEffectiveGraph(){this.assertReady();let t=this.coreRuntime.state,r=t.getAllLinks(),i=xr(t,r),n=Ci(i),o=0;for(let a of n)a.length>o&&(o=a.length);return{activityCount:t.getAllIds().length,logicalLinkCount:r.length,effectiveEdgeCount:i.length,circularComponents:n,largestComponentSize:o}}getProperty(t,r){this.assertReady();let i=this.coreRuntime.state.getActivity(t);return i?F(i[r]):null}getAllIds(){return this.assertReady(),Yd(this.coreRuntime.state)}forEachActivityId(t){this.assertReady(),Gd(this.coreRuntime.state,t)}getChildrenIds(t){return this.assertReady(),ka(this.coreRuntime.state,t)}getSelectedActivityIds(){return this.assertReady(),zd(this.coreRuntime.state)}getHiddenActivityIds(){return this.assertReady(),this.coreRuntime.state.hiddenIds().map(String)}getVisibleActivityIds(){this.assertReady();let t=new Set(this.coreRuntime.state.hiddenIds().map(String));return this.coreRuntime.state.getAllIds().map(String).filter(r=>!t.has(r))}getActiveFilter(){return this.assertReady(),F(this.coreRuntime.state.getActiveFilter())}getActiveOrder(){return this.assertReady(),F(this.coreRuntime.state.getActiveOrder())}getVisualOrderIds(){return this.assertReady(),[...this.coreRuntime.state.getVisualOrderIds()]}hasChild(t){return this.assertReady(),qd(this.coreRuntime.state,t)}getCalendar(t){this.assertReady();let r=this.coreRuntime.calendars.get(t);return r?F(r):null}getAllCalendars(){return this.assertReady(),Array.from(this.coreRuntime.calendars.values(),t=>F(t))}getBaseCalendars(){return this.assertReady(),this.coreRuntime.baseCalendars.map(t=>F(t))}isCustomIdInUse(t,r=null){return this.assertReady(),this.coreRuntime.customIdTracker.isCustomIdInUse(t,r)}getProjectWorkHours(){return this.assertReady(),Xd(this.coreRuntime.calendars.values())}getModifiedLinks(){return this.assertReady(),this._saveTracker.modifiedLinks(t=>this.coreRuntime.state.getLink(t)).map(F)}getNewLinks(){return this.assertReady(),this._saveTracker.newLinks(t=>this.coreRuntime.state.getLink(t)).map(F)}getModifiedActivities(){return this.assertReady(),this._saveTracker.modifiedActivities(t=>this.coreRuntime.state.getActivity(t)).map(F)}getModifiedActivityFields(){return this.assertReady(),F(this._saveTracker.modifiedActivityFields(t=>this.coreRuntime.state.getActivity(t)))}getNewActivities(){return this.assertReady(),this._saveTracker.newActivities(t=>this.coreRuntime.state.getActivity(t)).map(F)}hasUnsavedChanges(){return this.assertReady(),this._saveTracker.hasUnsavedChanges()}getScheduleRevision(){return this._scheduleRevision}getStateRevision(){return this._stateRevision}capturePersistenceHistoryBoundary(){return this.assertReady(),this._undo.capturePersistenceBoundary()}getCanonicalDigest(){this.assertReady();let t=(r,i)=>String(r.id).localeCompare(String(i.id));return Ye({sector:this.getSector(),activities:[...this.getAllActivitiesView()].sort(t),links:[...this.getAllLinksView()].sort(t),calendars:[...this.getAllCalendars()].sort(t),baseCalendars:[...this.getBaseCalendars()].sort(t)})}createProjectionChangeSetFrom(t){this.assertReady(),t.assertReady();let r=i=>({activities:i.getAllActivitiesView(),links:i.getAllLinksView(),calendars:i.getAllCalendars(),selectedIds:i.getSelectedActivityIds(),hiddenIds:i.getHiddenActivityIds(),order:Ze(i.coreRuntime.state)});return nf(r(this),r(t))}getDeletedActivitiesSinceLastSave(){return this.assertReady(),this._saveTracker.deletedActivities(t=>this.coreRuntime.state.getActivity(t)).map(F)}getDeletedLinksSinceLastSave(){return this.assertReady(),this._saveTracker.deletedLinks(t=>this.coreRuntime.state.getLink(t)).map(F)}_enqueue(t){let r=this._opQueue.then(t,t);return this._opQueue=r.then(()=>{},()=>{}),r}_beginScheduleMutation(t){return qo(t)?this._admitScheduleMutation():!1}_admitScheduleMutation(){return this._pendingScheduleRevision++,this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0),!0}_settleScheduleMutation(t,r){t&&(r||(this._pendingScheduleRevision=Math.max(this._pendingScheduleRevision-1,this._scheduleRevision),this._pendingScheduleRevision===this._scheduleRevision&&this._criticalPathRevision!==this._scheduleRevision&&this.recomputeCriticalPath().catch(i=>{this.coreRuntime.reporter.error("[ScheduleCore] Critical Path re-arm after a barren mutation failed",i)})))}async dispatch(t,r={}){let i=this._beginScheduleMutation(t);return this._enqueue(()=>this._dispatchInner(t,r,i))}async applyActivityBatch(t,r={}){let i=this._beginScheduleMutation(t);return this._enqueue(()=>this._dispatchInner(t,r,i))}planLookaheadConversion(t){return this.assertReady(),ca(t,{adapter:this.coreRuntime.state,stateRevision:this._stateRevision})}applyLookaheadConversion(t){return this.dispatch({...t,kind:m.ACTIVITY_LOOKAHEAD_CONVERT})}async _dispatchInner(t,r={},i=!1){let n=!1;try{let o=await this._runDispatch(t,r);return n=o.changedState,o.result}finally{this._settleScheduleMutation(i,n)}}async _runDispatch(t,r){if(this.assertReady(),this._isFork&&HA(t))return{result:{ok:!1,reason:S.SANDBOX_PERSISTENCE_FORBIDDEN},changedState:!1};let i=Pa(this.coreRuntime.state,{hoursPerDay:this.coreRuntime.sector.hoursPerDay,dateFormat:this.coreRuntime.sector.dateFormat}),n=su(t),o=[this.coreRuntime.activityIdGenerator.snapshot(),this.coreRuntime.linkIdGenerator.snapshot(),this.coreRuntime.uniqueCorrelativeIdGenerator.snapshot()];this.coreRuntime.state.beginWriteCapture(),this.coreRuntime.customIdTracker.beginCustomIdTransaction();let a,s;try{a=await Ad(t,r,{adapter:this.coreRuntime.state,ctx:i,scheduler:this.coreRuntime.scheduler,sector:this.coreRuntime.sector,calendars:this.coreRuntime.calendars,activityIdGen:this.coreRuntime.activityIdGenerator,linkIdGen:this.coreRuntime.linkIdGenerator,isActivityIdReserved:d=>this._saveTracker.hasCheckpointActivityId(d),isLinkIdReserved:d=>this._saveTracker.hasCheckpointLinkId(d),uidGen:this.coreRuntime.uniqueCorrelativeIdGenerator,customIdTracker:this.coreRuntime.customIdTracker,reporter:this.coreRuntime.reporter,activityClipboard:this._activityClipboard,stateRevision:this._stateRevision,defaultBaseCalendarId:this.coreRuntime.baseCalendars.find(d=>d.baseDefault)?.id??null,now:this.coreRuntime.clock?xi(this.coreRuntime.clock()):null});let l=this.coreRuntime.state.peekWriteCapture()?.progressFallbackBefore;l&&l.size>0&&(s=new Map(l)),a.ok||this._rollback(o)}catch(l){throw this._rollback(o),l}finally{this.coreRuntime.state.endWriteCapture(),this.coreRuntime.customIdTracker.commitCustomIdTransaction()}if(a.ok&&n===Er.RECORD&&ba(a.changes)){let l=iu(this.coreRuntime.state,a.changes),d=s?new Map(Array.from(s.keys(),u=>[u,this.coreRuntime.state.getProgressFallback(u)])):void 0;this._undo.record(La(ru(a.changes),a.__beforeSnap,a.__beforeLinks,l.afterSnap,l.afterLinks,s,d),nu(t),Date.now())}if(a.ok)if(n===Er.CHECKPOINT_ON_SUCCESS){if(t.kind!==m.PERSISTENCE_ACKNOWLEDGE)throw new Error("checkpoint-on-success requires persistence acknowledge");let l=this.coreRuntime.state.getAllActivities(),d=this.coreRuntime.state.getAllLinks(),u=t.checkpoint,f=u?.historyBoundary??this._undo.capturePersistenceBoundary();this._saveTracker.acknowledge(u?.activities??l,u?.links??d,t.activities,t.links,l,d),this._undo.discardThrough(f),this._undo.applyPersistedIdentities(t.activities??[],t.links??[])}else t.kind===m.ACTIVITY_LOOKAHEAD_SYNC&&t.acknowledgePersistedLookahead===!0?(this._saveTracker.acknowledgePersistedLookahead(a.changes.activities,l=>this.coreRuntime.state.getActivity(l)),t.persistedProgress!==void 0&&this._undo.clear()):this._saveTracker.recordChanges(a.changes.activities,a.changes.links,l=>this.coreRuntime.state.getActivity(l),l=>this.coreRuntime.state.getLink(l));if(a=this._withReappliedViewState(t,a),!a.ok)return{result:a,changedState:!1};let c=ba(a.changes);return c&&this._stateRevision++,qo(t)&&c?(this._recordScheduleMutation(r.skipAutoSchedule!==!0&&r.skipCriticalPath!==!0&&We(t)),{result:sf(a),changedState:!0}):{result:sf(a),changedState:!1}}recomputeCriticalPath(){let t=this._enqueue(async()=>({job:this._startCriticalPathForCurrentRevision()})).then(({job:r})=>r);return this._criticalPathReady=t,t}isCriticalPathSettled(){return this._criticalPathRevision===this._scheduleRevision&&this._pendingScheduleRevision===this._scheduleRevision&&this._activeCriticalPath===null}async whenCriticalPathSettled(){for(;!this.isCriticalPathSettled();)await this.recomputeCriticalPath()}_withReappliedViewState(t,r){if(!r.ok||(t.kind===m.VISIBILITY_SET&&this.coreRuntime.state.setFilterProjection(null),!sl(t)))return r;let i=this._reapplyViewState(r.changes);return i===null?r:{...r,changes:i}}_reapplyViewState(t){let r=this._reapplyActiveFilter(t),i=this._emitTouchedBranchOrder(r??t);return this._reapplyActiveOrder(i.changes??r??t,i.touchedParents)??i.changes??r}_emitTouchedBranchOrder(t){let r=this.coreRuntime.state,i=fu(t,o=>r.getParentId(o));if(r.getActiveOrder()!==null)return{changes:null,touchedParents:i};if(i.size===0)return{changes:null,touchedParents:i};let n=to(r,i);return n.length===0?{changes:null,touchedParents:i}:{changes:{...t,order:n},touchedParents:i}}_reapplyActiveOrder(t,r){let i=this.coreRuntime.state;if(i.getActiveOrder()===null)return null;if(i.invalidateDerivedOrder(),t.links.length>0||t.calendars.length>0)return{...t,order:Ze(i)};let o=new Set(r);for(let s of t.activities){if(s.kind===N.DELETED)return{...t,order:Ze(i)};let c=i.getParentId(s.id);o.add(c===null?"0":String(c))}let a=to(i,o);return a.length===0?null:{...t,order:a}}_reapplyActiveFilter(t){let r=this.coreRuntime.state,i=r.getActiveFilter();if(i===null)return null;let n=Re(this.coreRuntime.sector.hoursPerDay),o=r.getFilterProjection(),a=KA(o,i,n),s=WA(t)?null:VA(t,r),c,l;if(s===null||!a){let f=di({activities:r.getAllActivities(),parentOf:p=>r.getParentId(p),filter:i,context:n});r.setFilterProjection(f),l=f.visibleIds,c=r.getAllIds()}else c=cs(o,s,f=>r.getParentId(f)),l=o.visibleIds;let u=Xe(r,l,c);return u.length===0?null:{...t,viewState:[...t.viewState??[],...u]}}_recordScheduleMutation(t){this._scheduleRevision++,this._pendingScheduleRevision=Math.max(this._pendingScheduleRevision,this._scheduleRevision),this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0),t&&(this._criticalPathRevision=this._scheduleRevision)}_startCriticalPathForCurrentRevision(){if(this._status===Zt.DESTROYED)return Promise.resolve(null);let t=this._scheduleRevision;if(this._criticalPathRevision===t)return Promise.resolve(null);if(this._activeCriticalPath?.revision===t)return this._activeCriticalPath.promise;this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0);let r={cancelled:!1},i=new Tr(Pn(this.coreRuntime.state.getAllActivities().map(s=>et(s)),this.coreRuntime.state.getAllLinks().map(s=>({...s})),Array.from(this.coreRuntime.calendars.values()),this.coreRuntime.baseCalendars)),n=()=>!r.cancelled&&this._status!==Zt.DESTROYED&&this._scheduleRevision===t&&this._pendingScheduleRevision===this._scheduleRevision,o=(async()=>{let s=await $o(i,this.coreRuntime.sector.hoursPerDay,n);return!n()||s===null?null:this._enqueue(async()=>{if(!n())return null;this.coreRuntime.state.beginWriteCapture(),this.coreRuntime.customIdTracker.beginCustomIdTransaction();let c;try{for(let[l,d]of s.activities)Yo(this.coreRuntime.state,l,d);for(let[l,d]of s.links)Go(this.coreRuntime.state,l,d);c=await z(this.coreRuntime.state,{source:{kind:oe.INIT},beforeSnap:new Map,touchedIds:[],scheduledIds:[],hoursPerDay:this.coreRuntime.sector.hoursPerDay}),this._criticalPathRevision=t}catch(l){throw this._rollback(),l}finally{this.coreRuntime.state.endWriteCapture(),this.coreRuntime.customIdTracker.commitCustomIdTransaction()}return{changes:c}})})();this._activeCriticalPath={revision:t,cancellation:r,promise:o};let a=()=>{this._activeCriticalPath?.promise===o&&(this._activeCriticalPath=null)};return o.then(a,a),o}undo(t={}){let r=this._admitScheduleMutation(),i=!1,n=this._enqueue(async()=>{try{return await this._runUndo(t,o=>{i=o})}finally{this._settleScheduleMutation(r,i)}});return n.then(o=>{o&&t.skipCriticalPath!==!0&&this.recomputeCriticalPath().catch(a=>{this.coreRuntime.reporter.error("[ScheduleCore] Critical Path recompute after undo failed",a)})},()=>{}),n}async _runUndo(t,r){{if(this.assertReady(),t.expectedUndoDepth!==void 0&&this._undo.undoDepth()!==t.expectedUndoDepth)return null;let i=this._undo.takeUndo();if(!i)return null;cu(this.coreRuntime.state,i),this._recordScheduleMutation(!1),r(!0),Oa(i)&&this._resyncCustomIdTrackerFromModel(),this._undo.pushRedo(i),this._undo.resetCoalesce();let n=Na(this.coreRuntime.state,i,ct.BEFORE);return this._saveTracker.recordChanges(n.activities,n.links,o=>this.coreRuntime.state.getActivity(o),o=>this.coreRuntime.state.getLink(o)),this._reapplyViewState(n)??n}}redo(t={}){let r=this._admitScheduleMutation(),i=!1,n=this._enqueue(async()=>{try{return await this._runRedo(o=>{i=o})}finally{this._settleScheduleMutation(r,i)}});return n.then(o=>{o&&t.skipCriticalPath!==!0&&this.recomputeCriticalPath().catch(a=>{this.coreRuntime.reporter.error("[ScheduleCore] Critical Path recompute after redo failed",a)})},()=>{}),n}async _runRedo(t){this.assertReady();let r=this._undo.takeRedo();if(!r)return null;lu(this.coreRuntime.state,r),this._recordScheduleMutation(!1),t(!0),Oa(r)&&this._resyncCustomIdTrackerFromModel(),this._undo.pushUndo(r),this._undo.resetCoalesce();let i=Na(this.coreRuntime.state,r,ct.AFTER);return this._saveTracker.recordChanges(i.activities,i.links,n=>this.coreRuntime.state.getActivity(n),n=>this.coreRuntime.state.getLink(n)),this._reapplyViewState(i)??i}canUndo(){return this._undo.canUndo()}canRedo(){return this._undo.canRedo()}clearHistory(){this._undo.clear()}undoDepth(){return this._undo.undoDepth()}_resyncCustomIdTrackerFromModel(){this.coreRuntime.customIdTracker.clear(),this.coreRuntime.customIdTracker.populateFromActivities(this.coreRuntime.state.getAllActivities())}destroy(){this._activeCriticalPath&&(this._activeCriticalPath.cancellation.cancelled=!0),this.coreRuntime.calendars.clear(),this._saveTracker.clear(),this._status=Zt.DESTROYED}_initPromise;_criticalPathReady;_ready;_saveTracker=new On;assertReady(){if(this._status===Zt.DESTROYED)throw new Error("[ScheduleCore] instance is destroyed");if(this._status===Zt.POISONED)throw new Error("[ScheduleCore] instance is poisoned (a rollback failed) \u2014 reload from backend")}_rollback(t){try{this.coreRuntime.state.restoreFromCapture(),this.coreRuntime.scheduler.invalidateAllCaches(),this.coreRuntime.customIdTracker.rollbackCustomIdTransaction(),t&&(this.coreRuntime.activityIdGenerator.restore(t[0]),this.coreRuntime.linkIdGenerator.restore(t[1]),this.coreRuntime.uniqueCorrelativeIdGenerator.restore(t[2]))}catch(r){throw this._status=Zt.POISONED,this.coreRuntime.reporter.error("[ScheduleCore] rollback failed \u2014 core poisoned",r),r}}};function sf(e){let{__beforeSnap:t,__beforeLinks:r,...i}=e;return i}async function cf(e){let t=new kr(e);return await t.ready,t}var lf=(e=[])=>(e??[]).filter(t=>!t.proplannerId);var df={asap:"AS SOON AS POSSIBLE",alap:"AS LATE AS POSSIBLE",snet:"START NO EARLIER THAN",snlt:"START NO LATER THAN",fnet:"FINISH NO EARLIER THAN",fnlt:"FINISH NO LATER THAN",mso:"MUST START ON",mfo:"MUST FINISH ON"};var uf=8;var ff={CHILD:"child",CHILD_CONFIRMED:"child-confirmed",LINE:"line",ROOT:"root"};return Af(jA);})();
|
|
2
2
|
//# sourceMappingURL=schedule-core.global.js.map
|