courthive-components 0.7.0 → 0.7.2

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.
@@ -4,7 +4,7 @@
4
4
  http://jedwatson.github.io/classnames
5
5
  */(function(t){(function(){var e={}.hasOwnProperty;function r(){for(var n=[],o=0;o<arguments.length;o++){var i=arguments[o];if(i){var s=typeof i;if(s==="string"||s==="number")n.push(i);else if(Array.isArray(i)){if(i.length){var a=r.apply(null,i);a&&n.push(a)}}else if(s==="object"){if(i.toString!==Object.prototype.toString&&!i.toString.toString().includes("[native code]")){n.push(i.toString());continue}for(var l in i)e.call(i,l)&&i[l]&&n.push(l)}}}return n.join(" ")}t.exports?(r.default=r,t.exports=r):window.classNames=r})()})($g);var UF=$g.exports;const Zi=Eg(UF);function AF({individualParticipant:t,composition:e,className:r,matchUp:n,spacer:o}){var f,m,h;const i=(n==null?void 0:n.matchUpType)||"SINGLES",s=(f=t==null?void 0:t.ratings)==null?void 0:f[i],a=(m=t==null?void 0:t.rankings)==null?void 0:m[i],l=(h=e==null?void 0:e.configuration)==null?void 0:h.scaleAttributes,c=l==null?void 0:l.scaleType,u=l==null?void 0:l.accessor,p=c==="RATING"?s:a,d=!o&&(p==null?void 0:p[u]),v=document.createElement("span");return(d||o)&&(v.className=Zi(r,$F())),v.innerHTML=d||"",v}const CF="normal",Ng="timed",MF="final",zp="NOAD",qc="SET",DF={S:CF,F:MF};function Yp(t,e){if(typeof t=="object"){if(t.timed&&!isNaN(t.minutes))return Kp(t);if(t.bestOf&&t.setFormat)return jF(t,e)}}function zc(t){return!isNaN(Number(t))&&Number(t)}function Kp(t){let e=`T${t.minutes}`;return t.based&&(e+=t.based),t.modifier&&(e+=`@${t.modifier}`),e}function jF(t,e){var r;const n=zc(t.bestOf);if((r=t.setFormat)!=null&&r.timed&&t.simplified&&n===1)return Kp(t.setFormat);const o=n&&`${qc}${n}`||"",i=Ug(t.setFormat,e),s=i&&`S:${i}`||"",a=Ug(t.finalSetFormat,e),l=n&&n>1&&a&&i!==a&&`F:${a}`||"";if(o&&i)return[o,s,l].filter(u=>u).join("-")}function Ug(t,e){if(typeof t=="object"&&Object.keys(t).length){if(t.timed)return Kp(t);if(t.tiebreakSet)return Ag(t.tiebreakSet);const r=zc(t.setTo);if(r){const n=t.NoAD&&zp||"",o=Ag(t.tiebreakFormat),i=o&&`/${o}`||"",s=zc(t.tiebreakAt),a=s&&(s!==r||e)&&`@${s}`||"";if(o!==!1)return`${r}${n}${i}${a}`}}}function Ag(t){if(t){if(typeof t=="object"&&!t.tiebreakTo)return"";if(typeof t=="object"&&zc(t.tiebreakTo)){let e=`TB${t.tiebreakTo}${t.NoAD?zp:""}`;return t.modifier&&(e+=`@${t.modifier}`),e}else return!1}}function Te(t){return parseInt(typeof t=="number"?t.toString():t)}function Zr(t){return isNaN(t)?!1:t&&(t&t-1)===0}function RF(t){if(!Zr(t))return!1;let e=t,r=1;for(;e!==2;)r+=1,e=e/2;return r}function Qp(t){return isNaN(t)?0:t%2&&t+1||t}function Jp(t){return Math.pow(2,Math.round(Math.log(t)/Math.log(2)))}function Ct(t){return!isNaN(parseFloat(t))}function FF(t){const e=Te(t);if(!isNaN(e))return e===0?!1:(e&-e)===1}function ea(t){if(isNaN(t))return!1;for(;!Zr(t);)t++;return t}function Br(t,e){return t=Math.ceil(t),e=Math.floor(e),Math.floor(Math.random()*(e-t+1))+t}function ht(t){return Number.isSafeInteger(typeof t=="string"?+t:t)}function xF(t=1,e=3,r=!0){let n=0;for(let o=0;o<e;o++)n+=Math.random()*(t/e);return r&&t>1?Math.round(n):n}function LF(t,e){e||(e=1);const r=1/e;return Math.round(t*r)/r}function Cg(t,e,r,n,o=2){const i=1-Math.random(),s=1-Math.random();let a=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*s);return a=a/10+.5,a>1||a<0?a=Cg(t,e,r):(a=Math.pow(a,r),a*=e-t,a+=t),n&&(a=LF(a,n)),parseFloat(a.toFixed(o))}function Pr(t){if(typeof t=="string"){const e=t.startsWith("T")&&Ng||t.startsWith(qc)&&qc||"";if(e===Ng){const n={simplified:!0,setFormat:Rg(t),bestOf:1};if(n.setFormat)return n}if(e===qc)return VF(t)}}function VF(t){const e=t.split("-"),r=cl(e[0].slice(3)),n=e&&Mg(e[1]),o=e&&Mg(e[2]),i=r&&r<6,s=!e[2]||o,a=n,l={bestOf:r,setFormat:n};if(o&&(l.finalSetFormat=o),i&&a&&s)return l}function Mg(t){if((t==null?void 0:t[1])===":"){const e=t.split(":"),r=DF[e[0]],n=e[1];if(r&&n){if(n.indexOf("TB")===0){const h=jg(n);return h===!1?!1:typeof h=="object"?{tiebreakSet:h}:void 0}if(n.indexOf("T")===0)return Rg(n);const s=t.match(/^[FS]:(\d+)([A-Za-z]*)/),a=s&&Fg(s[2])||!1,l=!(s!=null&&s[2])||a,c=s?cl(s[1]):void 0,u=Dg(n),p=u!==!1,d=p&&u||c,v=jg(n.split("/")[1]),f=v!==!1,m={setTo:c};return a&&(m.NoAD=!0),v?(m.tiebreakFormat=v,m.tiebreakAt=d):m.noTiebreak=!0,c&&l&&f&&p&&m||!1}}}function Dg(t,e=!0){const r=(t==null?void 0:t.indexOf("@"))>0&&t.split("@");if(r)return(e?cl(r[1]):r[1])||!1}function jg(t){if(t)if(t.startsWith("TB")){const e=Dg(t,!1),r=t.match(/^TB(\d+)([A-Za-z]*)/),n=r==null?void 0:r[1],o=r&&Fg(r[2]),i=!(r!=null&&r[2])||o,s=cl(n);if(s&&i){const a={tiebreakTo:s};return e&&typeof e=="string"&&!ht(e)&&(a.modifier=e),o&&(a.NoAD=!0),a}else return!1}else return!1}function Rg(t){var e;const r=t.slice(1),n=r.match(/^(\d+)(@?[A-Za-z]*)/),o=cl(n==null?void 0:n[1]);if(!o)return;const i={timed:!0,minutes:o},s=n==null?void 0:n[2],a=[void 0,"P","G"].includes(s);if(s&&!a){const l=(e=r.match(/^(\d+)(@)([A-Za-z]+)$/))==null?void 0:e[3];return l?(i.modifier=l,i):void 0}return s&&(i.based=n[2]),i}function Fg(t){return t&&t.indexOf(zp)>=0}function cl(t){return isNaN(Number(t))?0:Number(t)}function Xr(t){if(typeof t!="string")return!1;const e=Pr(t),r=t.match(/-S:(\d+)+\/TB(\d+)@?(\d*)*/),n=r==null?void 0:r[1],o=r==null?void 0:r[2],i=r==null?void 0:r[3],s=t.match(/-F:(\d+)+\/TB(\d+)@?(\d*)*/),a=s==null?void 0:s[1],l=s==null?void 0:s[2],c=s==null?void 0:s[3];return Yp(e,!!(r&&o&&n===i||s&&l&&a===c))===t}const BF={isValidMatchUpFormat:Xr,stringify:Yp,isValid:Xr,parse:Pr};function Po(){return"1.4.30"}function Vo(t){if(!t)return;const{tieFormatId:e,tieFormats:r}=t;if(t.tieFormat)return t.tieFormat;if(e&&Array.isArray(r))return r.find(n=>n.tieFormatId===e)}function ul({item:t,drawDefinition:e,structure:r,event:n}){var o,i,s;if(t){if(t.tieFormat)return t.tieFormat;if(t.tieFormatId){if(e.tieFormat)return e.tieFormat;const a=(o=e.tieFormats)==null?void 0:o.find(l=>t.tieFormatId===l.tieFormatId);return a||(n.tieFormat?n.tieFormat:(i=n.tieFormats)==null?void 0:i.find(l=>t.tieFormatId===l.tieFormatId))}if(r.tieFormat)return r.tieFormat;if(r.tieFormatId){const a=(s=e.tieFormats)==null?void 0:s.find(l=>r.tieFormatId===l.tieFormatId);if(a)return a}}}function vr({drawDefinition:t,structure:e,matchUp:r,event:n}){return{tieFormat:ul({item:r,drawDefinition:t,structure:e,event:n})||ul({item:e,drawDefinition:t,structure:e,event:n})||Vo(t)||Vo(n)}}function or(t){return`${t} must be an array`}function We(t){return t.filter((e,r,n)=>n.lastIndexOf(e)===r)}function mr(t){return t.map(e=>[Math.random(),e]).sort((e,r)=>e[0]-r[0]).map(e=>e[1])}function Nr(t){return t.reduce((e,r)=>(e[r]||(e[r]=0),e[r]++,e),{})}function kF(t){return GF(Nr(t))}function GF(t){return Object.keys(t).reduce((e,r)=>{const n=t[r];return e[n]?e[n].push(r):e[n]=[r],e},{})}function WF(t,e,r){return r.indexOf(t)===e}function xg(t){return t.filter(WF)}function hr(t){return Array.isArray(t)&&t.length?t.splice(Math.floor(Math.random()*t.length),1)[0]:void 0}function Ur(t){const e=Math.floor(Math.random()*t.length);return t[e]}function ce(t,e){return Array.from({length:e-t},(r,n)=>n+t)}function Dn(t,e){return e.reduce((r,n,o)=>(n===t&&r.push(o),r),[])}function Ht(t,e){return!Array.isArray(t)||!Array.isArray(e)?[]:t.filter(r=>e.indexOf(r)!==-1).filter((r,n,o)=>o.indexOf(r)===n)}function Lg(t,e){return!Array.isArray(t)||!Array.isArray(e)?[]:t.filter(r=>!e.includes(r))}function Xt(t,e){return!Array.isArray(t)||!Array.isArray(e)?!1:t.some(r=>e.includes(r))}function qt(t,e){return t.reduce((r,n,o)=>{const i=Math.floor(o/e);return r[i]=[].concat(r[i]||[],n),r},[])}function HF(t){return t.reduce((e,r)=>{const n=e[e.length-1];return(!n||n[n.length-1]!==r-1)&&e.push([]),e[e.length-1].push(r),e},[])}function qF(t){return t.reduce((e,r)=>!isNaN(parseInt(r))&&e,!0)}function zF(t){return t.reduce((e,r)=>isNaN(parseInt(r))&&e,!0)}function Vg(t,e,r){return t.reduce((n,o,i)=>{const s=r?!!(Math.floor(i/e)%2):!1,a=i%e,l=s?e-1-a:a;return n[l]||(n[l]=[]),n[l].push(o),n},[])}const V={success:!0},Bg={message:"Chronological error; time violation.",code:"ANACHRONISM"},YF={message:"Cannot remove main structure",code:"ERR_CANNOT_REMOVE_MAIN_STRUCTURE"},kg={message:"records must be an object with tournamentId keys",code:"ERR_INVALID_TOURNAMENTS"},ke={message:"Missing tournamentRecords",code:"ERR_MISSING_TOURNAMENTS"},re={message:"Missing tournamentRecord",code:"ERR_MISSING_TOURNAMENT"},Yc={message:"Invalid tournamentRecord",code:"ERR_INVALID_TOURNAMENT"},yo={message:"Missing tournamentId",code:"ERR_MISSING_TOURNAMENT_ID"},Xi={message:"Invalid drawDefinition",code:"ERR_INVALID_DRAWDEF"},ue={message:"Missing drawDefinition",code:"ERR_MISSING_DRAWDEF"},KF={message:"Existing drawDefinition(s)",code:"ERR_EXISTING_DRAWDEFS"},en={message:"drawDefinition not found",code:"ERR_NOT_FOUND_DRAWDEF"},es={message:"Invalid structure",code:"ERR_INVALID_STRUCTURE"},Gg={message:"Incomplete source structure",code:"ERR_INCOMPLETE_STRUCTURE"},Wg={message:"Invalid drawPosition for seedAssignment",code:"ERR_INVALID_SEEDING_POSITION"},dl={message:"drawPosition already assigned",code:"ERR_EXISTING_POSITION_ASSIGNMENT"},QF={message:"Schedule not cleared",code:"ERR_UNCHANGED_SCHEDULE_NOT_CLEARED"},JF={message:"drawPosition not cleared",code:"ERR_FAILURE_POSITION_NOT_CLEARED"},Hg={message:"Unrecognized drawType",code:"ERR_UNRECOGNIZED_DRAW_TYPE"},Zp={message:"Missing drawPositions",code:"ERR_MISSING_DRAW_POSITIONS"},Xp={message:"drawPosition is active",code:"ERR_ACTIVE_DRAW_POSITION"},ta={message:"Invlid drawPosition",code:"ERR_INVALID_DRAW_POSITION"},pl={message:"Missing drawPosition",code:"ERR_MISSING_DRAW_POSITION"},qg={message:"Invalid drawType",code:"ERR_INVALID_DRAW_TYPE"},ef={message:"Invalid drawSize",code:"ERR_INVALID_DRAW_SIZE"},Kc={message:"Cannot set drawSize to be less than existing entries",code:"ERR_INVALID_DRAW_SIZE_MISMATCH"},Qc={message:"Missing drawSize",code:"ERR_MISSING_DRAW_SIZE"},kr={message:"Missing drawId",code:"ERR_MISSING_DRAW_ID"},ZF={message:"drawId exists",code:"ERR_EXISTING_DRAW_ID"},XF={message:"participantId cannot be assigned to multiple seedNumbers",code:"INVALID_PARTICIPANT_SEEDING"},ex={message:"seedsCount greater than drawSize",code:"ERR_INVALID_SEED_COUNT"},tx={message:"Missing seedCountThresholds",code:"ERR_MISSING_SEED_COUNT_THRESHOLD"},rx={message:"Invalid action",code:"ERR_INVALID_ACTION"},zg={message:"Invalid assignment",code:"ERR_INVALID_ASSIGNMENT"},nx={message:"Missing seedAssignments",code:"ERR_MISSING_SEED_ASSIGNMENTS"},ox={message:"Invalid seedNumber",code:"ERR_INVALID_SEED_NUMBER"},ix={message:"Invalid seedPosition",code:"ERR_INVALID_SEED_POSITION"},Yg={message:"Missing targetLink",code:"ERR_MISSING_LINK_TARGET"},sx={message:"Existing round",code:"ERR_EXISTING_ROUND"},yr={message:"Missing structureId",code:"ERR_MISSING_STRUCTURE_ID"},bt={message:"structure not found",code:"ERR_NOT_FOUND_STRUCTURE"},ax={message:"Missing structures",code:"ERR_MISSING_STRUCTURES"},ra={message:"Missing structure",code:"ERR_MISSING_STRUCTURE"},lx={message:"drawDefinition contains unlinked structures",code:"ERR_MISSING_STRUCTURE_LINKS"},gi={message:"Invalid eventType",code:"ERR_INVALID_EVENT_TYPE"},Ge={message:"Missing event / eventId",code:"ERR_MISSING_EVENT_ID"},Ar={message:"Event not found",code:"ERR_NOT_FOUND_EVENT"},cx={message:"Event exists",code:"ERR_EXISTING_EVENT"},ux={message:"Missing entries",code:"ERR_MISSING_ENTRIES"},dx={message:"Invalid entries",code:"ERR_INVALID_ENTRIES"},Kg={message:"Missing assignments",code:"ERR_MISSING_ASSIGNMENTS"},Qg={message:"Missing stage",code:"ERR_MISSING_STAGE"},Bo={message:"Invalid stage",code:"ERR_INVALID_STAGE"},px={message:"Missing positionAssignments",code:"ERR_MISSING_POSITION_ASSIGNMENTS"},fx={message:"Cannot Assign BYE status if no assignment: { bye: true }",code:"ERR_UNCHANGED_CANNOT_ASSIGN_BYE"},Jg={message:"Unrecognized matchUpStatus",code:"ERR_UNRECOGNIZED_MATCHUP_STATUS"},Jc={message:"Unrecognized matchUpFormat",code:"ERR_UNRECOGNIZED_MATCHUP_FORMAT"},tf={message:"Incompatible matchUpStatus",code:"ERR_INCOMPATIBLE_MATCHUP_STATUS"},fl={message:"Invalid matchUpStatus",code:"ERR_INVALID_MATCHUP_STATUS"},_i={message:"Invalid tieFormat",code:"ERR_INVALID_TIE_FORMAT"},Zg={message:"Invalid matchUpFormat",code:"ERR_INVALID_MATCHUP_FORMAT"},rf={message:"Missing matchUpFormat",code:"ERR_MISSING_MATCHUP_FORMAT"},vx={message:"Missing collectionDefinition",code:"ERR_MISSING_COLLECTION_DEFINITION"},Zc={message:"Missing tieFormat",code:"ERR_MISSING_TIE_FORMAT"},Vt={message:"Missing matchUpId",code:"ERR_MISSING_MATCHUP_ID"},vl={message:"Missing matchUpIds",code:"ERR_MISSING_MATCHUP_IDS"},ir={message:"matchUp not found",code:"ERR_NOT_FOUND_MATCHUP"},ko={message:"Missing matchUps",code:"ERR_MISSING_MATCHUPS"},jr={message:"Missing matchUp",code:"ERR_MISSING_MATCHUP"},tn={message:"Invalid matchUp",code:"ERR_INVALID_MATCHUP"},Xg={message:"Missing policyType",code:"ERR_MISSING_POLICY_TYPE"},Xc={message:"Missing policyDefinitions",code:"ERR_MISSING_POLICY_DEFINITIONS"},mx={message:"Missing avoidance policy",code:"ERR_MISSING_POLICY_AVOIDANCE"},e_={message:"Missing policy attributes",code:"ERR_MISSING_POLICY_ATTRIBUTES"},hx={message:"Invalid policyDefinitions",code:"ERR_INVALID_POLICY_DEFINITIONS"},t_={message:"existing policyType",code:"ERR_EXISTING_POLICY_TYPE"},gx={message:"Policy not attached",code:"ERR_FAILURE_POLICY_NOT_ATTACHED"},nf={message:"Policy not found",code:"ERR_NOT_FOUND_POLICY"},_x={message:"Missing scoring policy / matchUpFormats",code:"ERR_MISSING_POLICY_SCORING_MATCHUP_FORMATS"},r_={message:"Invalid sideNumber",code:"ERR_INVALID_SIDE_NUMBER"},of={message:"Missing setObject",code:"ERR_MISSING_SET_ATTRIBUTE"},na={message:"Missing courtId",code:"ERR_MISSING_COURT_ID"},_e={message:"Missing value",code:"ERR_MISSING_VALUE"},n_={message:"Missing date",code:"ERR_MISSING_DATE"},Ix={message:"No valid dates",code:"ERR_NO_VALID_DATES"},sf={message:"Invalid bookings",code:"ERR_INVALID_BOOKINGS"},af={message:"Invalid dateAvailability",code:"ERR_INVALID_DATE_AVAILABILITY"},Px={message:"Missing dateAvailability",code:"ERR_MISSING_DATE_AVAILABILITY"},Sr={message:"Invalid Date",code:"ERR_INVALID_DATE"},rn={message:"Invalid time",code:"ERR_INVALID_TIME"},yx={message:"Invalid tournament dates",code:"ERR_INVALID_DATES_TOURNAMENT"},o_={message:"Invalid game scores",code:"ERR_INVALID_SCORES_GAME"},Sx={message:"Invalid score",code:"ERR_INVALID_SCORE"},i_={message:"Invalid winningSide",code:"ERR_INVALID_WINNING_SIDE"},Ox={message:"No participants generated",code:"ERR_NO_PARTICIPANTS_GENERATED"},s_={message:"Cannot modify tieFormat",code:"ERR_UNCHANGED_CANNOT_MODIFY_TIEFORMAT"},bx={message:"Cannot modify participantType",code:"ERR_UNCHANGED_CANNOT_MODIFY_PARTICIPANT_TYPE"},lf={message:"Cannot remove participants",code:"ERR_UNCHANGED_CANNOT_REMOVE_PARTICIPANTS"},a_={message:"Cannot change winningSide",code:"ERR_UNCHANGED_CANNOT_CHANGE_WINNING_SIDE"},eu={message:"Invalid participant",code:"ERR_INVALID_PARTICIPANT"},So={message:"Invalid participantId",code:"ERR_INVALID_PARTICIPANT_ID"},pn={message:"Invalid participantIds",code:"ERR_INVALID_PARTICIPANT_IDS"},Tx={message:"Invalid participantRole",code:"ERR_INVALID_PARTICIPANT_ROLE"},jn={message:"Invalid participantType",code:"ERR_INVALID_PARTICIPANT_TYPE"},wx={message:"Missing participantRole",code:"ERR_MISSING_PARTICIPANT_ROLE"},oa={message:"Missing participant",code:"ERR_MISSING_PARTICIPANT"},ml={message:"Missing participants",code:"ERR_MISSING_PARTICIPANTS"},Et={message:"Missing participantId",code:"ERR_MISSING_PARTICIPANT_ID"},jt={message:"Participant Not Found",code:"ERR_NOT_FOUND_PARTICIPANT"},Ex={message:"participantId exists",code:"ERR_EXISTING_PARTICIPANT_ID"},$x={message:"No participant removed",code:"ERR_UNCHANGED_NO_PARTICIPANT_REMOVED"},Oo={message:"Missing participantIds",code:"ERR_MISSING_PARTICIPANT_IDS"},Nx={message:"Missing participantsCount",code:"ERR_MISSING_PARTICIPANT_COUNT"},Ux={message:"Participant not checked in",code:"ERR_UNCHANGED_PARTICIPANT_NOT_CHECKED_IN"},l_={message:"Participant already checked in",code:"ERR_UNCHANGED_PARTICIPANT_CHECKED_IN"},Ax={message:"Missing person details",code:"ERR_MISSING_PERSON_DETAILS"},ia={message:"Existing participant drawPosition assignment",code:"ERR_EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT"},cf={message:"Existing participant",code:"ERR_EXISTING_PARTICIPANT"},c_={message:"participantsCount exceeds drawSize",code:"ERR_INVALID_PARTICIPANT_COUNT"},uf={message:"Invalid entry status",code:"ERR_INVALID_ENTRY_STATUS"},u_={message:"Participant Entry Not Found",code:"ERR_NOT_FOUND_PARTICIPANT_ENTRY"},Cx={message:"Participant not entered in stage",code:"ERR_UNCHANGED_PARTICIPANT_NOT_ENTERED"},Mx={message:"Participant not found in stageSequence",code:"ERR_NOT_FOUND_PARTICIPANT_IN_STAGE"},Dx={message:"entryStatus not allowed in stage",code:"ERR_INVALID_ENTRY_STATUS_IN_STAGE"},jx={message:"entryStatus not allowed for event",code:"ERR_INVALID_ENTRY_STATUS_IN_EVENT"},d_={message:"No stage space available for entryStatus",code:"ERR_UNCHANGED_NO_AVAILABLE_STAGE_SPACE"},Rx={message:"Insufficient drawPositions to accommodate qualifiers",code:"ERR_UNCHANGED_NO_DRAW_POSITIONS_FOR_QUALIFIERS"},p_={message:"Insufficient drawPositions to accommodate entries",code:"ERR_INSUFFICIENT_DRAW_POSITIONS"},Fx={message:"Missing penaltyType",code:"ERR_MISSING_PENALTY_TYPE"},f_={message:"Missing penaltyId",code:"ERR_MISSING_PENALTY_ID"},tu={message:"Penalty not found",code:"ERR_NOT_FOUND_PENALTY"},xx={message:"Missing courtsCount/courtNames",code:"ERR_MISSING_COURTS_INFO"},df={message:"Court not found",code:"ERR_NOT_FOUND_COURT"},Lx={message:"Court exists",code:"ERR_EXISTING_COURT"},Vx={message:"Venue exists",code:"ERR_EXISTING_VENUE"},Ii={message:"Venue not found",code:"ERR_NOT_FOUND_VENUE"},Go={message:"Missing venueId",code:"ERR_MISSING_VENUE_ID"},Bx={message:"Invalid endTime",code:"ERR_INVALID_END_TIME"},v_={message:"Existing endTime",code:"ERR_EXISTING_END_TIME"},kx={message:"Invalid stopTime",code:"ERR_INVALID_STOP_TIME"},Gx={message:"Invalid startTime",code:"ERR_INVALID_START_TIME"},Wx={message:"Invalid resumeTime",code:"ERR_INVALID_RESUME_TIME"},m_={message:"Invalid timeItem",code:"ERR_INVALID_TIME_ITEMS"},h_={message:"Missing timeItem",code:"ERR_MISSING_TIME_ITEM"},g_={message:"Missing timeItems",code:"ERR_MISSING_TIME_ITEMS"},ru={message:"Missing context",code:"ERR_MISSING_CONTEXT"},Hx={message:"Missing schedule",code:"ERR_MISSING_SCHEDULE"},nu={message:"Invalid scaleItem",code:"ERR_INVALID_SCALE_ITEM"},qx={message:"No scaleItem found",code:"ERR_NOT_FOUND_SCALE_ITEM"},zx={message:"Modifications failed",code:"ERR_FAILURE_MODIFICATIONS"},hl={message:"No modifications applied",code:"ERR_UNCHANGED_NO_MODIFICATIONS_APPLIED"},Yx={message:"Unable to assign court",code:"ERR_UNCHANGED_COURT_NOT_ASSIGNED"},pf={message:"No Candidates",code:"ERR_UNCHANGED_NO_CANDIDATES"},Kx={message:"Invalid configuration",code:"ERR_INVALID_CONFIG"},no={message:"Invalid object",code:"ERR_INVALID_OBJECT"},X={message:"Invalid values",code:"ERR_INVALID_VALUES"},Qx={message:"Duplicate value",code:"ERR_DUPLICATE_VALUE"},__={message:"Team not found",code:"ERR_NOT_FOUND_TEAM"},Jx={message:"No valid actions",code:"ERR_NO_VALID_ACTIONS"},ff={message:"No valid attributes",code:"ERR_NO_VALID_ATTRIBUTES"},I_={message:"Value unchanged",code:"ABORT_UNCHANGED"},sr={message:"Not found",code:"ERR_NOT_FOUND"},P_={message:"Not implemented",code:"ERR_NOT_IMPLEMENTED"},Zx={message:"Existing flight",code:"ERR_EXISTING_FLIGHT"},y_={message:"Existing flight profile",code:"ERR_EXISTING_FLIGHT_PROFILE"},Xx={message:"Existing outcome",code:"ERR_EXISTING_OUTCOME"},eL={message:"Existing matchUpId",code:"ERR_EXISTING_MATCHUP_ID"},S_={message:"Existing stage",code:"ERR_EXISTING_STAGE"},tL={message:"Existing structure",code:"ERR_EXISTING_STRUCTURE"},O_={message:"Method not found",code:"ERR_NOT_FOUND_METHOD"},rL={message:"Scheduled matchUps",code:"ERR_SCHEDULED_MATCHUPS"};var nL=Object.defineProperty,b_=Object.getOwnPropertySymbols,oL=Object.prototype.hasOwnProperty,iL=Object.prototype.propertyIsEnumerable,T_=(t,e,r)=>e in t?nL(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sL=(t,e)=>{for(var r in e||(e={}))oL.call(e,r)&&T_(t,r,e[r]);if(b_)for(var r of b_(e))iL.call(e,r)&&T_(t,r,e[r]);return t};const Pt={disableNotifications:!1,tournamentId:void 0,tournamentRecords:{},subscriptions:{},modified:!1,notices:[]};var aL={addNotice:IL,callListener:bL,cycleMutationStatus:_L,deleteNotice:SL,deleteNotices:yL,disableNotifications:lL,enableNotifications:cL,getNotices:PL,getTopics:OL,getTournamentId:uL,getTournamentRecord:dL,getTournamentRecords:pL,removeTournamentRecord:hL,setSubscriptions:gL,setTournamentId:vL,setTournamentRecord:fL,setTournamentRecords:mL};function lL(){Pt.disableNotifications=!0}function cL(){Pt.disableNotifications=!1}function uL(){return Pt.tournamentId}function dL(t){return Pt.tournamentRecords[t]}function pL(){return Pt.tournamentRecords}function fL(t){const e=t==null?void 0:t.tournamentId;return e?(Pt.tournamentRecords[e]=t,{success:!0}):{error:Yc}}function vL(t){return Pt.tournamentRecords[t]?(Pt.tournamentId=t,{success:!0}):{error:re}}function mL(t){Pt.tournamentRecords=t;const e=Object.keys(t);e.length===1?Pt.tournamentId=e[0]:e.length||(Pt.tournamentId=void 0)}function hL(t){if(typeof t!="string")return{error:X};if(!Pt.tournamentRecords[t])return{error:sr};delete Pt.tournamentRecords[t];const e=Object.keys(Pt.tournamentRecords);return e.length===1?Pt.tournamentId=e[0]:e.length||(Pt.tournamentId=void 0),{success:!0}}function gL(t){return typeof t.subscriptions!="object"?{error:X}:(Object.keys(t.subscriptions).forEach(e=>{Pt.subscriptions[e]=t.subscriptions[e]}),sL({},V))}function _L(){const t=Pt.modified;return Pt.modified=!1,t}function IL({topic:t,payload:e,key:r}){Pt.modified=!0,!(typeof t!="string"||typeof e!="object")&&(Pt.disableNotifications||!Pt.subscriptions[t]||(r&&(Pt.notices=Pt.notices.filter(n=>!(n.topic===t&&n.key===r))),Pt.notices.push({topic:t,payload:e,key:r})))}function PL({topic:t}){const e=Pt.notices.filter(r=>r.topic===t).map(r=>r.payload);return e.length&&e}function yL(){Pt.notices=[]}function SL({topic:t,key:e}){Pt.notices=Pt.notices.filter(r=>(!t||r.topic===t)&&r.key!==e)}function OL(){return{topics:Object.keys(Pt.subscriptions)}}function bL({topic:t,notices:e}){const r=Pt.subscriptions[t];r&&typeof r=="function"&&r(e)}var TL=Object.defineProperty,w_=Object.getOwnPropertySymbols,wL=Object.prototype.hasOwnProperty,EL=Object.prototype.propertyIsEnumerable,E_=(t,e,r)=>e in t?TL(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$L=(t,e)=>{for(var r in e||(e={}))wL.call(e,r)&&E_(t,r,e[r]);if(w_)for(var r of w_(e))EL.call(e,r)&&E_(t,r,e[r]);return t};const nn={tournamentFactoryVersion:"0.0.0",timers:{default:{elapsedTime:0}},iterators:{makeDeepCopy:0},deepCopyAttributes:{stringify:[],ignore:[],toJSON:[]},deepCopy:!0};let Rr=aL;function zt(t){var e;return!t||typeof t!="object"?(e=nn.devContext)!=null?e:!1:typeof nn.devContext!="object"?!1:Object.keys(t).every(r=>{var n;return((n=nn.devContext)==null?void 0:n[r])===t[r]})&&nn.devContext}function sa(t){nn.devContext=t}function NL(t){nn.iterators.makeDeepCopy=t}function UL(){return nn.iterators.makeDeepCopy}function AL(){Rr.disableNotifications()}function vf(){Rr.enableNotifications()}function ts(t,e){typeof t=="boolean"&&(nn.deepCopy=t),typeof e=="object"&&(Array.isArray(e.ignore)&&(nn.deepCopyAttributes.ignore=e.ignore),Array.isArray(e.toJSON)&&(nn.deepCopyAttributes.toJSON=e.toJSON),Array.isArray(e.stringify)&&(nn.deepCopyAttributes.stringify=e.stringify),e.threshold&&(nn.deepCopyAttributes.threshold=e.threshold))}function $_(){return $L({enabled:nn.deepCopy},nn.deepCopyAttributes)}function gl(){return Rr.cycleMutationStatus()}function He(t){return Rr.addNotice(t)}function CL(t){return Rr.getNotices(t)}function N_({key:t,topic:e}){return Rr.deleteNotice({key:t,topic:e})}function Pi(){return Rr.deleteNotices()}function Rn(){return Rr.getTopics()}async function U_(t){return Rr.callListener(t)}function fn(){return Rr.getTournamentId()}function _l(t){return Rr.getTournamentRecord(t)}function ou(){return Rr.getTournamentRecords()}function A_(t){return Rr.setTournamentRecord(t)}function Il(t){return Rr.setTournamentRecords(t)}function Pl(t){return Rr.setTournamentId(t)}function mf(t){return Rr.removeTournamentRecord(t)}function rs(t){return typeof t=="object"}const ML=t=>e=>Object.keys(t).every(r=>e[r]===t[r]),Fn=t=>e=>!t||typeof e!="object"?void 0:Array.isArray(t)&&t.map(r=>({[r]:e[r]}))||typeof t=="object"&&Object.keys(t).map(r=>({[r]:e[r]}))||typeof t=="string"&&DL(e,t);function DL(t,e){const r=e.split(".");for(const n of r)if(t=t==null?void 0:t[n],!t)return;return t}function Oe(t,e,r,n){if(typeof t!="object"||t===null)return t;const o=$_();o!=null&&o.enabled||(n=!0);const i=["",void 0,null];e&&i.push(!1);const s=Object.keys(t).filter(a=>!i.includes(t[a])&&(!r||(Array.isArray(t[a])?t[a].length:!0)));return Object.assign({},...s.map(a=>Array.isArray(t[a])?{[a]:n?t[a]:t[a].map(l=>Oe(l))}:{[a]:n?t[a]:Oe(t[a])}))}function hf(t){return Array.isArray(t)?t.length+t.map(hf).reduce((e,r)=>e+r,0):typeof t=="object"&&t!==null?Object.keys(t).length+Object.keys(t).map(e=>hf(t[e])).reduce((e,r)=>e+r,0):0}function jL(t){if(t===null||typeof t!="object")return;const e=JSON.stringify(t),r=hf(t),n=e.split("").reduce((o,i)=>o+i.charCodeAt(0),0);return[e.length,r,n].map(o=>o.toString(36)).join("")}function iu(t){if(t===null)return{};const{source:e,template:r}=t||{};if(!r)return e;const n={};return o(e,r,n),n;function o(i,s,a){if(!i||!s)return;const l=Object.keys(i),c=Object.keys(s),u=Object.assign({},...c.filter(v=>v.indexOf("||")).map(v=>v.split("||").map(f=>({[f]:v}))).flat()),p=c.concat(...Object.keys(u)),d=p.includes("*");for(const v of l)if(p.indexOf(v)>=0||d){const f=u[v]||v,m=s[f]||d,h=i[v];if(typeof m=="object"&&typeof h!="function"&&!Array.isArray(m))if(Array.isArray(h)){const g=h.map(_=>{const I={};return o(_,m,I)!==!1?I:void 0}).filter(Boolean);a[v]=g}else h&&(a[v]={},o(h,m,a[v]));else{const g=i[v];if(Array.isArray(m)&&!m.includes(g))return!1;(s[v]||d&&s[v]!==!1)&&(a[v]=g)}}}}function C_(t=0){const e=new Date;return e.setHours(e.getHours()+t),e.getTime().toString(36).slice(-6).toUpperCase()}const su=/^[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])$/,M_=/^((0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)([.,][0-9]{3})?$/,xn=/^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))([ T](0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/,yi=/^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))?([ T]?(0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;function au(t){let{scheduledDate:e}=t;if(!e&&t.scheduledTime&&(e=Re(t.scheduledTime)),!e)return;const r=at(t.scheduledTime);let n=Re(e);return n&&r&&(n+=`T${r}`),n}function RL(t){return typeof t!="object"||Array.isArray(t)?!1:Object.prototype.toString.call(t)==="[object Date]"}function aa(t){const e=typeof t=="string"?t==null?void 0:t.split(" "):[];return t&&(e==null?void 0:e.length)>1&&!["AM","PM"].includes(e[1].toUpperCase())?!1:!!(!t||yi.test(ns(t,!0,!0)))}function Gr(t){return Si(t)||su.test(t)}function FL(t){const e=new Date(t),r=e.getSeconds()+60*e.getMinutes()+60*60*e.getHours();return xL(r,{displaySeconds:!1})}function xL(t,e){const r=parseInt(t,10),n=Math.floor(r/3600),o=Math.floor((r-n*3600)/60),i=r-n*3600-o*60;return(!e||(e==null?void 0:e.displaySeconds)?n+":"+o+":"+i:n+":"+o).split(":").map(oo).join(":")}const gf=t=>{const e=yl(t)||Si(t)?new Date(t):new Date,r=e.getUTCMonth()+1,n=r<10?`0${r}`:`${r}`;return`${e.getUTCFullYear()}-${oo(n)}-${oo(e.getUTCDate())}`};function LL(t){const e=yl(t)||Si(t)?new Date(t):new Date;return Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())}function vn(t,e="-",r="YMD"){if(!t)return"";typeof t=="string"&&t.indexOf("T")<0&&(t=t+"T00:00");const n=new Date(t);let o=""+(n.getMonth()+1),i=""+n.getDate();const s=n.getFullYear();return o.length<2&&(o="0"+o),i.length<2&&(i="0"+i),r==="DMY"?[i,o,s].join(e):r==="MDY"?[o,i,s].join(e):r==="YDM"?[s,i,o].join(e):r==="DYM"?[i,s,o].join(e):r==="MYD"?[o,s,i].join(e):[s,o,i].join(e)}function lu(t){const e=t?new Date(t):new Date,r=e.getTimezoneOffset();return new Date(e.getTime()-r*60*1e3)}function VL(t){return lu(t).getTime()}function yl(t){if(typeof t=="boolean")return!1;const e=t instanceof Date&&t||!isNaN(t)&&new Date(t)||!1;return e&&!isNaN(e.valueOf())}function _f(t,e){if(!Gr(t)||!Gr(e))return[];const r=Re(t)+"T00:00",n=Re(e)+"T00:00",o=new Date(r),i=new Date(n),s=yl(i)&&yl(o)&&c(o,i),a=[];let l=0;if(s){const u=o;let p=u.getTime();for(;p<=i.getTime()&&l<300;)l+=1,a.push(new Date(u)),p=u.setDate(u.getDate()+1)}return a.map(u=>vn(u));function c(u,p){return u<=p}}const BL=/^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;function Si(t){return typeof t!="string"?!1:BL.test(t)}function D_(t){if(typeof t!="string")return!1;const r=t.split("Z")[0].split(":"),n=r.every(i=>!isNaN(parseInt(i)));return!(r.length<2||!n||parseInt(r[0])>23||parseInt(r[1])>60)}function Le(t){const e=at(t);if(!e)return 0;const[r,n]=e.split(":").map(o=>parseInt(o));return r*60+n}function kL(t){let e=Math.floor(t/60);const r=t-e*60;return e>23&&(e=e%24),[oo(e),oo(r)].join(":")}function cu(t){return D_(t)?t.split(":").slice(0,2).map(oo).join(":"):void 0}function at(t){return Si(t)&&t.indexOf("T")>0?cu(t.split("T").reverse()[0]):cu(t)}function Re(t){return Si(t)||xn.test(t)?t.split("T")[0]:void 0}function GL(t,e){const r=new Date(t);return r.setDate(r.getDate()+e),Re(r.toISOString())}function uu(t){t=typeof t!="string"?"00:00":t;const e={},r={};return{0:e.time,1:e.ampm}=t.split(" ")||[],{0:r.hours,1:r.minutes}=e.time.split(":")||[],r.ampm=e.ampm,isNaN(r.hours)||isNaN(r.minutes)||r.ampm&&!["AM","PM"].includes(r.ampm.toUpperCase())?{}:r}function WL(t){const e=uu(t);return e.ampm&&e.hours&&(e.ampm.toLowerCase()==="pm"&&parseInt(e.hours)<12&&(e.hours=(e.hours&&parseInt(e.hours)||0)+12),e.ampm.toLowerCase()==="am"&&e.hours==="12"&&(e.hours="00")),`${e.hours||"12"}:${e.minutes||"00"}`.split(":").map(oo).join(":")}function HL(t){var e;const r=uu(t);if(!(typeof r=="object"&&!Object.keys(r).length))return r.ampm?t:(r.hours>12?(r.hours-=12,r.ampm="PM"):r.hours==="12"?r.ampm="PM":(r.hours==="00"&&(r.hours="12"),r.ampm="AM"),((e=r.hours)==null?void 0:e[0])==="0"&&(r.hours=r.hours.slice(1)),`${r.hours||"12"}:${r.minutes||"00"} ${r.ampm}`)}function ns(t,e,r){const n=Re(t),o=at(t),i=n?o:t;return t?e&&(n&&r&&t||WL(i))||HL(i):void 0}function j_(t,e){const r=uu(t),n=uu(e);if(parseInt(r.hours)<parseInt(n.hours))return-1;if(parseInt(r.hours)>parseInt(n.hours))return 1;if(r.hours===n.hours){if(parseInt(r.minutes)<parseInt(n.minutes))return-1;if(parseInt(r.minutes)>parseInt(n.minutes))return 1}return 0}function R_(t,e=7){const r=Re(t)+"T00:00",n=new Date(r),o=new Date(n.setDate(n.getDate()+e));return vn(o)}function qL(t){return R_(t)}function zL(t,e,r,n=!1){const o=new Date(e,0,1+(t-1)*7),i=n?0:1;return o.setDate(o.getDate()+(i-o.getDay())),vn(o,r)}function YL(t,e,r){const n=new Date(t,0);return vn(new Date(n.setDate(e)),r)}function $t(t,e=void 0){const[r,n]=(t||"00:00").split(":").map(oo),o=lu(e).setHours(r,n,0,0);return lu(o)}function Sl(t,e,r=!0){const n=new Date(t),i=(new Date(e).getTime()-n.getTime())/1e3/60;return r?Math.abs(Math.round(i)):Math.round(i)}function Or(t,e){const r=at(t);if(!r)return"00:00";const n=isNaN(e)?0:e;return at(If($t(r),n).toISOString())}function If(t,e){const r=new Date(t);return new Date(r.getTime()+e*6e4)}function oo(t){return t.toString()[1]?t:"0"+t}function io(t,e){const r=new Date(t),n=new Date(e);return r.getFullYear()===n.getFullYear()&&r.getMonth()===n.getMonth()&&r.getDate()===n.getDate()}const KL={addDays:R_,addWeek:qL,addMinutesToTimeString:Or,convertTime:ns,getIsoDateString:au,getUTCdateString:gf,DateHHMM:FL,extractDate:Re,extractTime:at,formatDate:vn,getDateByWeek:zL,isISODateString:Si,isDate:yl,isTimeString:D_,offsetDate:lu,offsetTime:VL,sameDay:io,timeStringMinutes:Le,timeToDate:$t,timeUTC:LL,validTimeValue:aa,validDateString:su,timeValidation:yi,dateValidation:xn};function de(t,e,r,n,o=0){const i=$_(),{stringify:s,toJSON:a,ignore:l,modulate:c}=i||{};if(!(i!=null&&i.enabled)&&!r||typeof t!="object"||typeof t=="function"||t===null||typeof(i==null?void 0:i.threshold)=="number"&&o>=i.threshold)return t;const u=zt({makeDeepCopy:!0});u&&(NL(o),typeof u=="object"&&(o>(u.iterationThreshold||15)||u.firstIteration&&o===0)&&u.log&&(!u.notInternalUse||u.notInternalUse&&!r)&&console.log({devContext:u,iteration:o,internalUse:r},t));const p=Array.isArray(t)?[]:{},d=Object.keys(t).filter(f=>!r||!l||Array.isArray(l)&&!l.includes(f)||typeof l=="function"&&!l(f)),v=(f,m)=>{p[f]=typeof(m==null?void 0:m.toString)=="function"?m.toString():JSON.stringify(m)};for(const f of d){const m=t[f],h=typeof c=="function"?c(m):void 0;if(h!==void 0)p[f]=h;else if(e&&f==="extensions"&&Array.isArray(m)){const g=Pf(m);Object.assign(p,...g)}else n&&f==="extensions"?p[f]=[]:Array.isArray(s)&&s.includes(f)?v(f,m):Array.isArray(a)&&a.includes(f)&&typeof(m==null?void 0:m.toJSON)=="function"?p[f]=m.toJSON():m===null?p[f]=void 0:RL(m)?p[f]=new Date(m).toISOString():p[f]=de(m,e,r,n,o+1)}return p}function Pf(t){return t==null?void 0:t.map(e=>{const{name:r,value:n}=e;return r&&n&&{[`_${r}`]:n}}).filter(Boolean)}function er(t,e){return t-e}function QL(t,e){if(e&&typeof e!="object")return X;let{columnTransform:r={}}=e||{};const{includeTransformAccessors:n,includeHeaderRow:o=!0,returnTransformedJSON:i,removeEmptyColumns:s,onlyHeaderRow:a,columnAccessors:l=[],functionMap:c={},columnMap:u={},valuesMap:p={},context:d={},delimiter:v='"',columnJoiner:f=",",rowJoiner:m=`\r
6
6
  `,keyJoiner:h="."}=e||{};if(!Array.isArray(t)||!Array.isArray(l)||typeof d!="object"||typeof u!="object"||typeof r!="object"||typeof c!="object"||typeof p!="object"||typeof f!="string"||typeof m!="string"||typeof h!="string"||typeof v!="string")return X;r=Object.assign({},...Object.keys(r).reverse().map(A=>({[A]:Array.isArray(r[A])?r[A]:[typeof r[A]=="string"&&r[A]].filter(Boolean)})));const g=t.filter(Boolean).map(A=>yf(A,h)),_=Object.values(r).flat();n&&l.push(..._);const I=g.reduce((A,U)=>Object.keys(U).every(C=>!A.includes(C)&&A.push(C)||!0)&&A,[]).filter(A=>!(l!=null&&l.length)||l.includes(A)),P=Object.assign({},...Object.keys(r).reverse().map(A=>r[A].map(U=>({[U]:A})).flat()).flat()),y=(A,U)=>e!=null&&e.sortOrder?e.sortOrder.includes(A)&&e.sortOrder.includes(U)&&e.sortOrder.indexOf(A)-e.sortOrder.indexOf(U)||!e.sortOrder.includes(U)&&-1:0,S=I.reduce((A,U)=>{const C=P[U];return C?A.includes(C)||A.push(C):A.push(U),A},[]).sort(y);Object.keys(u).forEach(A=>!S.includes(A)&&S.unshift(A)),Object.keys(r).forEach(A=>!S.includes(A)&&S.unshift(A)),typeof d=="object"&&Object.keys(d).forEach(A=>!S.includes(A)&&S.unshift(A));let O=S.map(A=>u[A]||A);if(a)return[O];const b=A=>`${v}${A}${v}`,w=[],T=A=>Object.values(S.reduce((U,C,M)=>{var D;const R=r[C],j=(R!=null&&R.length?A[R.find(q=>A[q])]:A[C])||(d==null?void 0:d[C])||"",G=((D=p[C])==null?void 0:D[j])||j,W=typeof c[C]=="function"?c[C](G):G;return U[C]=b(W),W&&(w[M]=(w[M]||0)+1),U},{}));let $=g.map(T);const N=s&&[...w].map((A,U)=>!A&&U).filter(Ct).reverse();if(N){const A=U=>U.filter((C,M)=>!N.includes(M));$=$.map(A),O=A(O)}const E=$.map(A=>A.join(f));return i?E.map(A=>{const U=A.split(f);return Object.assign({},...U.map((C,M)=>({[O[M]]:C})))}):o?[O.map(b).join(f),...E].join(m):E.join(m)}function yf(t,e,r=[]){return typeof t=="object"&&Object.keys(t).reduce((n,o)=>typeof t[o]!="object"?(n[r.concat(o).join(e)]=t[o],n):Object.assign(n,yf(t[o],e,r.concat(o))),{})}function JL(t=1){return ce(0,t).map(Ye)}function Ye(){const t=[];for(let i=0;i<256;i++)t[i]=(i<16?"0":"")+i.toString(16);const e=Math.random()*4294967295|0,r=Math.random()*4294967295|0,n=Math.random()*4294967295|0,o=Math.random()*4294967295|0;return t[e&255]+t[e>>8&255]+t[e>>16&255]+t[e>>24&255]+"-"+t[r&255]+t[r>>8&255]+"-"+t[r>>16&15|64]+t[r>>24&255]+"-"+t[n&63|128]+t[n>>8&255]+"-"+t[n>>16&255]+t[n>>24&255]+t[o&255]+t[o>>8&255]+t[o>>16&255]+t[o>>24&255]}var ZL=Object.defineProperty,F_=Object.getOwnPropertySymbols,XL=Object.prototype.hasOwnProperty,eV=Object.prototype.propertyIsEnumerable,x_=(t,e,r)=>e in t?ZL(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tV=(t,e)=>{for(var r in e||(e={}))XL.call(e,r)&&x_(t,r,e[r]);if(F_)for(var r of F_(e))eV.call(e,r)&&x_(t,r,e[r]);return t};function k({context:t,result:e,stack:r,info:n}){return e&&!Array.isArray(e==null?void 0:e.stack)&&(e.stack=[]),e&&Array.isArray(e==null?void 0:e.stack)&&typeof r=="string"&&e.stack.push(r),n&&(e!=null&&e.error)&&(e.error.info=n),e&&typeof t=="object"&&Object.keys(t).length&&Object.assign(e,Oe(t)),e&&!(e!=null&&e.error)&&!(e!=null&&e.success)&&Object.assign(e,tV({},V)),e??{success:!0}}var L_=(t=>(t.AdHoc="AD_HOC",t.Compass="COMPASS",t.CurtisConsolation="CURTIS_CONSOLATION",t.DoubleElimination="DOUBLE_ELIMINATION",t.FeedIn="FEED_IN",t.FeedInChampionship="FEED_IN_CHAMPIONSHIP",t.FeedInChampionshipToQf="FEED_IN_CHAMPIONSHIP_TO_QF",t.FeedInChampionshipToR16="FEED_IN_CHAMPIONSHIP_TO_R16",t.FeedInChampionshipToSf="FEED_IN_CHAMPIONSHIP_TO_SF",t.FirstMatchLoserConsolation="FIRST_MATCH_LOSER_CONSOLATION",t.FirstRoundLoserConsolation="FIRST_ROUND_LOSER_CONSOLATION",t.ModifiedFeedInChampionship="MODIFIED_FEED_IN_CHAMPIONSHIP",t.Lucky="LUCKY_DRAW",t.Olympic="OLYMPIC",t.Other="OTHER",t.Playoff="PLAYOFF",t.RoundRobin="ROUND_ROBIN",t.RoundRobinWithPlayoff="ROUND_ROBIN_WITH_PLAYOFF",t.SingleElimination="SINGLE_ELIMINATION",t))(L_||{}),bo=(t=>(t.Consolation="CONSOLATION",t.Main="MAIN",t.PlayOff="PLAY_OFF",t.Qualifying="QUALIFYING",t.VoluntaryConsolation="VOLUNTARY_CONSOLATION",t))(bo||{}),ar=(t=>(t.Alternate="ALTERNATE",t.Confirmed="CONFIRMED",t.DirectAcceptance="DIRECT_ACCEPTANCE",t.FeedIn="FEED_IN",t.JuniorExempt="JUNIOR_EXEMPT",t.LuckyLoser="LUCKY_LOSER",t.OrganiserAcceptance="ORGANISER_ACCEPTANCE",t.Qualifier="QUALIFIER",t.SpecialExempt="SPECIAL_EXEMPT",t.Registered="Registered",t.Ungrouped="UNGROUPED",t.Unpaired="UNPAIRED",t.Wildcard="WILDCARD",t.Withdrawn="WITHDRAWN",t))(ar||{}),Wo=(t=>(t.Loser="LOSER",t.Position="POSITION",t.Winner="WINNER",t))(Wo||{}),Ol=(t=>(t.BottomUp="BOTTOM_UP",t.Draw="DRAW",t.LossPosition="LOSS_POSITION",t.Random="RANDOM",t.TopDown="TOP_DOWN",t.Waterfall="WATERFALL",t))(Ol||{}),Cr=(t=>(t.Doubles="DOUBLES",t.Singles="SINGLES",t.Team="TEAM",t))(Cr||{}),ut=(t=>(t.Abandoned="ABANDONED",t.AwaitingResult="AWAITING_RESULT",t.Bye="BYE",t.Cancelled="CANCELLED",t.Completed="COMPLETED",t.DeadRubber="DEAD_RUBBER",t.Defaulted="DEFAULTED",t.DoubleDefault="DOUBLE_DEFAULT",t.DoubleWalkover="DOUBLE_WALKOVER",t.InProgress="IN_PROGRESS",t.Incomplete="INCOMPLETE",t.NotPlayed="NOT_PLAYED",t.Retired="RETIRED",t.Suspended="SUSPENDED",t.ToBePlayed="TO_BE_PLAYED",t.Walkover="WALKOVER",t))(ut||{}),Sf=(t=>(t.Any="ANY",t.Female="FEMALE",t.Male="MALE",t.Mixed="MIXED",t))(Sf||{}),V_=(t=>(t.Administration="ADMINISTRATION",t.Captain="CAPTAIN",t.Coach="COACH",t.Competitor="COMPETITOR",t.Media="MEDIA",t.Medical="MEDICAL",t.Official="OFFICIAL",t.Other="OTHER",t.Security="SECURITY",t))(V_||{}),Ln=(t=>(t.Group="GROUP",t.Individual="INDIVIDUAL",t.Pair="PAIR",t.Team="TEAM",t))(Ln||{}),rV=Object.defineProperty,B_=Object.getOwnPropertySymbols,nV=Object.prototype.hasOwnProperty,oV=Object.prototype.propertyIsEnumerable,k_=(t,e,r)=>e in t?rV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,iV=(t,e)=>{for(var r in e||(e={}))nV.call(e,r)&&k_(t,r,e[r]);if(B_)for(var r of B_(e))oV.call(e,r)&&k_(t,r,e[r]);return t};function br(t){var e,r,n,o;const i=t==null?void 0:t.checkCollectionIds,s=t==null?void 0:t.tieFormat,a="validateTieFormat",l=[];if(typeof s!="object")return l.push("tieFormat must be an object"),k({result:{error:_i,stack:a,context:{tieFormat:s,errors:l}}});if(typeof s.winCriteria!="object")return l.push("tieFormat.winCriteria must be an object"),k({result:{error:_i,stack:a,context:{tieFormat:s,errors:l}}});if(!Array.isArray(s.collectionDefinitions))return l.push(or("tieFormat.collectionDefinitions")),k({result:{error:_i,stack:a,context:{tieFormat:s,errors:l}}});let c;const u=s.collectionDefinitions.every(h=>{const{setValue:g,scoreValue:_,collectionValue:I}=h;(g||_)&&!I&&(c=!0);const{valid:P,errors:y}=G_({collectionDefinition:h,checkCollectionIds:i});return P?!0:(Array.isArray(y)&&l.push(...y),!1)}),p=typeof((e=s.winCriteria)==null?void 0:e.valueGoal)=="number"&&((r=s.winCriteria)==null?void 0:r.valueGoal)>0&&!c||((n=s.winCriteria)==null?void 0:n.aggregateValue);if(!(p||(o=s.winCriteria)!=null&&o.aggregateValue))return c?l.push("aggregateValue is required"):l.push("Either non-zero valueGoal, or { aggregateValue: true } must be specified in winCriteria"),k({result:{context:{tieFormat:s,errors:l,aggregateValueImperative:c},error:_i,stack:a}});const d=s.collectionDefinitions.map(({collectionId:h})=>h),v=!i||d.length===We(d).length,f=u&&p&&v,m={valid:f,errors:l};return f?m:k({result:{context:{tieFormat:s,errors:l},error:_i,stack:a}})}function G_({checkValueDefinition:t=!0,collectionDefinition:e,checkCollectionIds:r}){const n=[];if(typeof e!="object")return n.push(`collectionDefinition must be an object: ${e}`),{errors:n};const{collectionValueProfiles:o,collectionGroupNumber:i,collectionValue:s,collectionId:a,matchUpCount:l,matchUpFormat:c,matchUpValue:u,matchUpType:p,scoreValue:d,setValue:v}=e;if(r&&typeof a!="string")return n.push(`collectionId is not type string: ${a}`),{errors:n};if(typeof l!="number")return n.push(`matchUpCount is not type number: ${l}`),{errors:n};if(p&&![Cr.Singles,Cr.Doubles].includes(p))return n.push(`matchUpType must be SINGLES or DOUBLES: ${p}`),{errors:n};if(t&&!u&&!s&&!o&&!d&&!v)return n.push("Missing value definition for matchUps: matchUpValue, collectionValue, or collectionValueProfiles"),{errors:n};if(u&&typeof u!="number")return n.push(`matchUpValue is not type number: ${u}`),{errors:n};if(s&&typeof s!="number")return n.push(`collectionValue is not type number: ${s}`),{errors:n};if(o){const f=W_({collectionValueProfiles:o,matchUpCount:l});if(f.errors)return n.push(...f.errors),{errors:n}}return i&&typeof i!="number"?(n.push(`collectionValue is not type number: ${s}`),{errors:n}):c&&!BF.isValid(c)?(n.push(`Invalid matchUpFormat: ${c}`),{errors:n}):{valid:!0}}function sV(t){const e=br({tieFormat:t,checkCollectionIds:!1});if(e.error)return e;for(const r of t.collectionDefinitions)r.collectionId||(r.collectionId=Ye());return{tieFormat:t}}function W_({collectionValueProfiles:t,matchUpCount:e}){const r=[];if(!Array.isArray(t))return r.push(`collectionValueProfiles is not an array: ${t}`),{errors:r};if(t.length&&t.length!==e)return r.push("collectionValueProfiles do not align with matchUpsCount"),{errors:r};for(const o of t){if(typeof o!="object")return r.push(`valueProfile is not type object: ${o}`),{errors:r};const{value:i,collectionPosition:s}=o;if(typeof i!="number"||typeof s!="number"||s>e||s<1)return r.push("Invalid value profile: value and collectionPosition must be numeric. collectionPosition cannot be greater than matchUpCount"),{errors:r}}const n=t.map(o=>o.collectionPosition);return n.length!==We(n).length?(r.push("collectionPositions are not unique"),{errors:r}):iV({},V)}const Wr="ABANDONED",la="AWAITING_RESULT",nt="BYE",Ho="CANCELLED",Mt="COMPLETED",bl="DEAD_RUBBER",Xe="DEFAULTED",tr="DOUBLE_DEFAULT",Rt="DOUBLE_WALKOVER",Vn="IN_PROGRESS",so="INCOMPLETE",Of="NOT_PLAYED",_r="RETIRED",Oi="SUSPENDED",Ft="TO_BE_PLAYED",ot="WALKOVER",aV=[la,Mt,Xe,Rt,tr,Vn,so,_r,Oi,ot],lV=[Wr,la,nt,Ho,Mt,bl,Xe,Rt,tr,Vn,so,Of,_r,Oi,Ft,ot],cV=[nt,Rt,tr,Mt,Xe,_r,ot],uV=[Wr,la,Ho,bl,Vn,so,Of,Oi,Ft,void 0],Yt=[ut.Cancelled,ut.Abandoned,ut.Completed,ut.DeadRubber,ut.Defaulted,ut.DoubleWalkover,ut.DoubleDefault,ut.Retired,ut.Walkover],H_=[Wr,Mt,Xe,Rt,tr,Vn,_r,ot],dV=[Vn,so,Oi,Ft],pV={ABANDONED:Wr,AWAITING_RESULT:la,BYE:nt,CANCELLED:Ho,COMPLETED:Mt,DEAD_RUBBER:bl,DEFAULTED:Xe,DOUBLE_WALKOVER:Rt,DOUBLE_DEFAULT:tr,IN_PROGRESS:Vn,INCOMPLETE:so,NOT_PLAYED:Of,RETIRED:_r,SUSPENDED:Oi,TO_BE_PLAYED:Ft,WALKOVER:ot};function ca({matchUp:t}){return Yt.includes(t==null?void 0:t.matchUpStatus)||(t==null?void 0:t.winningSide)}const du="SET3-S:6/TB7",fV={FORMAT_STANDARD:du,FORMAT_STANDARD_NOAD:"SET3-S:6NOAD",FORMAT_ATP_DOUBLES:"SET3-S:6/TB7-F:TB10",FORMAT_SHORT_SETS:"SET3-S:4/TB7",FORMAT_FAST4:"SET3-S:4/TB5@3",FORMAT_PRO_SET:"SET1-S:8/TB7",FORMAT_COLLEGE_PRO_SET:"SET1-S:8/TB7@7",TIMED20:"SET1-S:T20"};function q_({winningSide:t,matchUpFormat:e=du,matchUpStatus:r,tallyPolicy:n,score:o}){var i;const s=[0,0],{sets:a}=o||{},l=t-1,c=Pr(e),u=bf((i=c==null?void 0:c.bestOf)!=null?i:1);if(r===Xe&&(n!=null&&n.setsCreditForDefaults)||r===ot&&(n!=null&&n.setsCreditForWalkovers))s[l]=u;else for(const p of a||[]){const{winningSide:d}=p;d&&(s[d-1]+=1)}return r===_r&&(+s[1-l]===u&&(s[1-l]-=1),n!=null&&n.setsCreditForRetirements&&(s[l]=u)),s}function vV({matchUpFormat:t=du,winningSide:e,matchUpStatus:r,tallyPolicy:n,score:o}){var i,s,a;const{sets:l}=o||{};if(!l)return[0,0];const c=e-1,u=Pr(t),p=(i=u==null?void 0:u.bestOf)!=null?i:1,d=bf(p),v=((s=u==null?void 0:u.setFormat)==null?void 0:s.tiebreakAt)||0,f=[[],[]];if(r===Xe&&(n!=null&&n.gamesCreditForDefaults)||r===ot&&(n!=null&&n.gamesCreditForWalkovers)){const m=((a=u==null?void 0:u.setFormat)==null?void 0:a.setTo)||0,h=d*m;f[c].push(h)}else l.forEach((m,h)=>{var g;const I=(m.setNumber||h+1)>d&&(u!=null&&u.finalSetFormat)?"finalSetFormat":"setFormat",P=(g=u==null?void 0:u[I])==null?void 0:g.based,y=u==null?void 0:u[I].tiebreakSet,{side1Score:S,side2Score:O}=m;Y_(P)&&(f[0].push(Te(S||0)),f[1].push(Te(O||0))),y&&m.winningSide&&(n==null?void 0:n.gamesCreditForTiebreakSets)!==!1&&f[m.winningSide-1].push(1)});if(r===_r){const m=l.length>d&&(u!=null&&u.finalSetFormat)?"finalSetFormat":"setFormat",h=u==null?void 0:u[m];if(Y_(h.based)){const g=(h==null?void 0:h.setTo)||0,_=y=>{if(!(!u||y===""))return+y===v-1||+y===v?Te(v||0)+1:+y<v?g:v},I=q_({winningSide:e,score:{sets:l},matchUpStatus:r,matchUpFormat:t,tallyPolicy:n});if(f.map(y=>y[c]<=y[1-c]).reduce((y,S)=>y+(S?1:0),0)>I[1-c]){const y=f[c].length,S=_(f[1-c][y-1]);S&&(f[c][y-1]=S)}d>f[c].length&&(n!=null&&n.gamesCreditForRetirements)&&f[c].push(g)}}return[f[0].reduce((m,h)=>m+h,0),f[1].reduce((m,h)=>m+h,0)]}function mV({matchUpFormat:t,score:e}){var r,n;const o=Pr(t),i=(r=o==null?void 0:o.bestOf)!=null?r:1,s=bf(i),a=[0,0];return(n=e==null?void 0:e.sets)==null||n.forEach((l,c)=>{var u;const d=(l.setNumber||c+1)>s&&(o!=null&&o.finalSetFormat)?"finalSetFormat":"setFormat",v=(u=o==null?void 0:o[d])==null?void 0:u.based;if(z_(v)){const{side1Score:f,side2Score:m}=l;f&&(a[0]+=Te(f||0)),m&&(a[1]+=Te(m||0))}else l.side1TiebreakScore&&(a[0]+=Te(l.side1TiebreakScore||0)),l.side2TiebreakScore&&(a[1]+=Te(l.side2TiebreakScore||0))}),a}function bf(t){return t&&Math.ceil(t/2)||1}function z_(t){return t==="P"}function Y_(t){return!z_(t)}function hV({participantResults:t,matchUpFormat:e,tallyPolicy:r,perPlayer:n,totalSets:o}){var i;const s=e&&Pr(e)||{},a=s.bestOf,l=a&&Math.ceil(a/2)||1,c=(i=s.setFormat)==null?void 0:i.setTo;Object.keys(t).forEach(u=>{const p=t[u].setsWon,d=t[u].setsLost,v=r!=null&&r.groupTotalSetsPlayed?o:n*(l||0)||p+d;let f=Math.round(p/v*1e3)/1e3;(f===1/0||isNaN(f))&&(f=v);const m=t[u].tieMatchUpsWon,h=t[u].tieMatchUpsLost,g=m+h;let _=Math.round(m/g*1e3)/1e3;(_===1/0||isNaN(_))&&(_=m);const I=t[u].matchUpsWon,P=t[u].matchUpsLost,y=I+P;let S=Math.round(I/y*1e3)/1e3;(S===1/0||isNaN(S))&&(S=I);const O=t[u].gamesWon||0,b=t[u].gamesLost||0,w=(n||0)*(l||0)*(c||0),T=Math.max(w,O+b);let $=Math.round(O/T*1e3)/1e3;($===1/0||isNaN($))&&($=0);let N=Math.round(t[u].pointsWon/t[u].pointsLost*1e3)/1e3;(N===1/0||isNaN(N))&&(N=0),t[u].setsWon=p,t[u].setsLost=d,t[u].setsPct=f,t[u].tieMatchUpsWon=m,t[u].tieMatchUpsPct=_,t[u].matchUpsPct=S,t[u].gamesWon=O,t[u].gamesLost=b,t[u].gamesPct=$,t[u].pointsPct=N,t[u].result=`${t[u].matchUpsWon}/${t[u].matchUpsLost}`})}const bi="SINGLES",At="SINGLES",mn="DOUBLES",dt="DOUBLES",hn="TEAM",Qe="TEAM";function K_({participantIds:t,matchUpFormat:e,tallyPolicy:r,perPlayer:n,matchUps:o}){var i,s,a,l;const c={},u=(r==null?void 0:r.excludeMatchUpStatuses)||[],p=o.filter(f=>(f.tieMatchUps||!u.includes(f.matchUpStatus))&&(!(t!=null&&t.length)||Ht(t,[ua(f,0),ua(f,1)]).length===2)),v=p.flatMap(({score:f,tieMatchUps:m})=>{var h;return m?m.filter(({matchUpStatus:g})=>!u.includes(g)).flatMap(({score:g})=>{var _;return((_=g==null?void 0:g.sets)==null?void 0:_.length)||0}):((h=f==null?void 0:f.sets)==null?void 0:h.length)||0}).reduce((f,m)=>f+m,0);for(const f of p){const{matchUpStatus:m,tieMatchUps:h,tieFormat:g,score:_,winningSide:I,sides:P}=f,y=g&&f._disableAutoCalc&&g.collectionDefinitions.every(({scoreValue:b})=>b),S=I&&gV(f),O=I&&_V(f);if(!S||!O)if(Yt.includes(m)){const b=ua(f,0),w=ua(f,1);b&&(qo(c,b),c[b].matchUpsCancelled+=1),w&&(qo(c,w),c[w].matchUpsCancelled+=1)}else if(h!=null&&h.length){n=0;for(const b of h){if(b.winningSide){const w=(i=P.find(({sideNumber:$})=>$===b.winningSide))==null?void 0:i.participantId,T=(s=P.find(({sideNumber:$})=>$===b.winningSide))==null?void 0:s.participantId;w&&T&&(qo(c,w),qo(c,T),c[w].tieMatchUpsWon+=1,c[T].tieMatchUpsLost+=1,b.matchUpType===At?(c[w].tieSinglesWon+=1,c[T].tieSinglesLost+=1):b.matchUpType===dt&&(c[w].tieDoublesWon+=1,c[T].tieDoublesLost+=1))}Q_({score:b.score,manualGamesOverride:y,participantResults:c,sides:P})}}else Q_({manualGamesOverride:y,participantResults:c,score:_,sides:P});else if(qo(c,S),qo(c,O),h!=null&&h.length){n=0;for(const b of h){const{matchUpType:w}=b,T=w===dt,$=w===At;b.winningSide&&(b.winningSide===I?(S&&(c[S].tieMatchUpsWon+=1,$&&(c[S].tieSinglesWon+=1),T&&(c[S].tieDoublesWon+=1)),O&&(c[O].tieMatchUpsLost+=1,$&&(c[O].tieSinglesLost+=1),T&&(c[O].tieDoublesLost+=1))):b.winningSide!==I&&(O&&(c[O].tieMatchUpsWon+=1,$&&(c[O].tieSinglesWon+=1),T&&(c[O].tieDoublesWon+=1)),S&&(c[S].tieMatchUpsLost+=1,$&&(c[S].tieSinglesLost+=1),T&&(c[S].tieDoublesLost+=1)))),J_({matchUpFormat:b.matchUpFormat,matchUpStatus:b.matchUpStatus,score:b.score,winningParticipantId:S,losingParticipantId:O,participantResults:c,isTieMatchUp:!0,manualGamesOverride:y,tallyPolicy:r,winningSide:I})}Z_({winningParticipantId:S,losingParticipantId:O,participantResults:c,matchUpStatus:m})}else J_({matchUpFormat:f.matchUpFormat||e,isTieMatchUp:void 0,winningParticipantId:S,manualGamesOverride:y,losingParticipantId:O,participantResults:c,matchUpStatus:m,tallyPolicy:r,winningSide:I,score:_});if(y){const b=(a=P.find(({sideNumber:N})=>N===1))==null?void 0:a.participantId,w=(l=P.find(({sideNumber:N})=>N===2))==null?void 0:l.participantId;qo(c,b),qo(c,w);const T=_.sets.reduce((N,E)=>N+E.side1Score,0),$=_.sets.reduce((N,E)=>N+E.side2Score,0);c[b].gamesWon+=T,c[w].gamesWon+=$,c[b].gamesLost+=$,c[w].gamesLost+=T}}return hV({participantResults:c,matchUpFormat:e,tallyPolicy:r,perPlayer:n,totalSets:v}),{participantResults:c}}function gV(t){const e=t.winningSide-1;return ua(t,e)}function _V(t){const e=1-(t.winningSide-1);return ua(t,e)}function ua(t,e){if(!(t!=null&&t.sides))return console.log("no sides:",{matchUp:t}),"foo";const r=t.sides[e];return r?r.participantId:(console.log("No Side",{matchUp:t,index:e}),"foo")}function qo(t,e){e&&!t[e]&&(t[e]={allDefaults:0,defaults:0,defeats:[],gamesLost:0,gamesWon:0,matchUpsCancelled:0,matchUpsLost:0,matchUpsWon:0,pointsLost:0,pointsWon:0,retirements:0,setsLost:0,setsWon:0,tieSinglesWon:0,tieSinglesLost:0,tieDoublesWon:0,tieDoublesLost:0,tieMatchUpsLost:0,tieMatchUpsWon:0,victories:[],walkovers:0})}function Q_({manualGamesOverride:t,participantResults:e,score:r,sides:n}){const{sets:o}=r||{},i=[[],[]],s=[0,0];for(const l of o||[]){const{winningSide:c,side1Score:u,side2Score:p}=l;c&&(s[c-1]+=1),i[0].push(Te(u||0)),i[1].push(Te(p||0))}const a=[i[0].reduce((l,c)=>l+c,0),i[1].reduce((l,c)=>l+c,0)];n.forEach((l,c)=>{const{participantId:u}=l;u&&(qo(e,u),e[u].setsWon+=s[c],e[u].setsLost+=s[1-c],t||(e[u].gamesWon+=a[c],e[u].gamesLost+=a[1-c]))})}function J_({winningParticipantId:t,losingParticipantId:e,participantResults:r,manualGamesOverride:n,matchUpFormat:o,matchUpStatus:i,isTieMatchUp:s,tallyPolicy:a,winningSide:l,score:c}){const u=l&&l-1,p=1-u;s||Z_({winningParticipantId:t,losingParticipantId:e,participantResults:r,matchUpStatus:i});const d=q_({matchUpStatus:i,matchUpFormat:o,tallyPolicy:a,winningSide:l,score:c}),v=vV({matchUpStatus:i,matchUpFormat:o,tallyPolicy:a,winningSide:l,score:c}),f=mV({score:c,matchUpFormat:o});t&&(r[t].setsWon+=d[u],r[t].setsLost+=d[p],n||(r[t].gamesWon+=v[u],r[t].gamesLost+=v[p]),r[t].pointsWon+=f[u],r[t].pointsLost+=f[p]),e&&(r[e].setsWon+=d[p],r[e].setsLost+=d[u],n||(r[e].gamesWon+=v[p],r[e].gamesLost+=v[u]),r[e].pointsWon+=f[p],r[e].pointsLost+=f[u])}function Z_({winningParticipantId:t,losingParticipantId:e,participantResults:r,matchUpStatus:n}){e&&(n===ot&&(r[e].walkovers+=1),n===Xe&&(r[e].defaults+=1),n===_r&&(r[e].retirements+=1),[Xe,_r,ot].includes(n)&&(r[e].allDefaults+=1),r[e].matchUpsLost+=1),t&&(r[t].matchUpsWon+=1),e&&t&&(r[e].defeats.push(t),r[t].victories.push(e))}function IV({matchUps:t,order:e,report:r}){const n={};t.forEach(({sides:i})=>{i.forEach(s=>{s.participantId&&s.participant&&(n[s.participantId]=s.participant.participantName)})});const o=[];return Array.isArray(r)&&r.forEach((i,s)=>{var a;if((a=i.excludedDirectives)!=null&&a.length){const l=i.excludedDirectives.map(({attribute:p})=>p).join(", "),c=`${l.length} directives were excluded due to participants limit}`;o.push(c);const u=`Excluded: ${l}`;o.push(u)}else{const l=(v,f)=>parseFloat(i.reversed?v:f)-parseFloat(i.reversed?f:v),c=v=>{Object.keys(v.groups).sort(l).forEach(f=>{const m=v.groups[f].map(g=>n[g]).join(", "),h=`${f} ${v.attribute}: ${m}`;o.push(h)})},u=i.reversed?" in reverse order":"",p=Object.values(i.groups).flat(1/0).length,d=`Step ${s+1}: ${p} particiants were grouped${u} by ${i.attribute}`;if(o.push(d),i.idsFilter){const v=`${i.attribute} was calculated considering ONLY TIED PARTICIPANTS`;o.push(v)}c(i)}o.push("----------------------")}),o.push("Final Order:"),e.forEach(i=>{const{participantId:s,resolved:a}=i,l=i.groupOrder||i.provisionalOrder;o.push(`${l}: ${n[s]} => resolved: ${a}`)}),o.join(`\r
7
- `)}function X_({participantResults:t,participantIds:e,attribute:r}){return eI({participantResults:t,participantIds:e}).reduce((o,i)=>{const{participantId:s,results:a}=i,l=a==null?void 0:a[r];return!isNaN(l)&&s&&(o[l]?o[l].push(s):o[l]=[s]),o},{})}function eI(t){return(t.participantIds||Object.keys(t.participantResults)).reduce((r,n,o)=>(r.push({participantId:n,i:o,results:t.participantResults[n]}),r),[])}var PV=Object.defineProperty,tI=Object.getOwnPropertySymbols,yV=Object.prototype.hasOwnProperty,SV=Object.prototype.propertyIsEnumerable,rI=(t,e,r)=>e in t?PV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,OV=(t,e)=>{for(var r in e||(e={}))yV.call(e,r)&&rI(t,r,e[r]);if(tI)for(var r of tI(e))SV.call(e,r)&&rI(t,r,e[r]);return t};const bV=[{attribute:"matchUpsPct",idsFilter:!1},{attribute:"allDefaults",reversed:!0,idsFilter:!1},{attribute:"defaults",reversed:!0,idsFilter:!1},{attribute:"walkovers",reversed:!0,idsFilter:!1},{attribute:"retirements",reversed:!0,idsFilter:!1},{attribute:"setsPct",idsFilter:!1},{attribute:"gamesPct",idsFilter:!1},{attribute:"pointsPct",idsFilter:!1},{attribute:"matchUpsPct",idsFilter:!0},{attribute:"setsPct",idsFilter:!0},{attribute:"gamesPct",idsFilter:!0},{attribute:"pointsPct",idsFilter:!0}],Tf={matchUpsPct:20,tieMatchUpsPct:16,setsPct:12,gamesPct:8,pointsPct:4};function nI(t){const{requireCompletion:e=!0,participantResults:r,subOrderMap:n,tallyPolicy:o}=t,i=[];if(e&&!TV(t))return{};const s=["tieMatchUpsWon","tieSinglesWon","tieDoublesWon","matchUpsWon","pointsWon","gamesWon","setsWon","gamesPct","setsPct","pointsPct","matchUpsPct"].includes(o==null?void 0:o.groupOrderKey)?o.groupOrderKey:"matchUpsWon",a=X_({participantResults:r,attribute:s});i.push({attribute:s,groups:a});const l=Object.keys(a).map(f=>parseFloat(f)).sort((f,m)=>m-f).map(f=>a[f]).map(f=>{const m=oI(OV({participantIds:f},t));return i.push(m.report),m.order}).flat(1/0);let c=1,u;l.forEach((f,m)=>{m&&(f.resolved||u&&!f.resolved)&&(c+=1),u=f.resolved,f.resolved?(f.position=m+1,c=f.position):f.position=c});const p=l.map(({position:f})=>f),d=Nr(p);return l.forEach(f=>{const{participantId:m,position:h}=f||{},g=r[m];f.GEMscore=v(g);const _=d[h];(f==null?void 0:f.position)!==void 0&&(_>1&&(f.ties=_,n&&(f.subOrder=n[m])),f.rankOrder=h,f.groupOrder=h+(f.subOrder||1)-1)}),{groupOrder:l,report:i.flat(1/0).filter(Boolean)};function v(f){return(Array.isArray(o==null?void 0:o.GEMscore)?Object.keys(Tf).filter(g=>o.GEMscore.includes(g)):Object.keys(Tf)).map(g=>(f[g]||0)*Math.pow(10,Tf[g].toFixed(3))).reduce((g,_)=>g+_,0)}}function TV({participantResults:t,participantsCount:e}){const n=eI({participantResults:t}).filter(o=>e-1===o.results.matchUpsWon+o.results.matchUpsLost+o.results.matchUpsCancelled);return e===n.length}function wV({disableHeadToHead:t,participantIds:e,matchUpFormat:r,tallyPolicy:n,attribute:o,idsFilter:i,matchUps:s,reversed:a}){const{participantResults:l}=K_({participantIds:i&&e,matchUpFormat:r,tallyPolicy:n,matchUps:s}),c=X_({participantResults:l,participantIds:e,attribute:o}),u=[{attribute:o,reversed:a,groups:c,idsFilter:i}];let p;return Object.keys(c).length>1&&e.length&&(p=Object.keys(c).map(d=>parseFloat(d)).sort((d,v)=>a?d-v:v-d).map(d=>c[d]).map(d=>{const v=oI({participantResults:l,disableHeadToHead:t,participantIds:d,matchUpFormat:r,tallyPolicy:n,matchUps:s});return u.push(v.report),v.order}).flat(1/0)),{order:p,report:u}}function oI({participantResults:t,disableHeadToHead:e,participantIds:r,matchUpFormat:n,tallyPolicy:o,matchUps:i}){if((r==null?void 0:r.length)===1)return{order:[{resolved:!0,participantId:r[0]}]};if((r==null?void 0:r.length)===2&&(!(o!=null&&o.headToHead)||!o.headToHead.disabled&&!e)){const p=EV({participantIds:r,participantResults:t});if(p)return{order:[p],headToHeadWinner:p[0].participantId}}const s=(o==null?void 0:o.tallyDirectives)||bV,a=[],l=[];let c;const u=s.filter(p=>{const d=!(Ct(p.maxParticipants)&&(r==null?void 0:r.length)>p.maxParticipants);return d||a.push(p),d});return a.length&&l.push({excludedDirectives:a,participantIds:r}),u.every(({attribute:p,reversed:d,idsFilter:v,disableHeadToHead:f})=>(c=wV({disableHeadToHead:f,participantIds:r,matchUpFormat:n,tallyPolicy:o,attribute:p,idsFilter:v,matchUps:i,reversed:d}),l.push(c.report),!c.order)),c.order?{order:c.order,report:l}:{order:r==null?void 0:r.map(p=>({participantId:p})),report:l}}function EV({participantIds:t,participantResults:e}){if(t){if(e[t[0]].victories.includes(t[1]))return t.map(r=>({resolved:!0,participantId:r}));if(e[t[1]].victories.includes(t[0]))return t.reverse().map(r=>({resolved:!0,participantId:r}))}}const iI="voluntaryConsolation",zo="competitiveBands",sI="roundRobinTally",To="positionActions",Bn="matchUpActions",wf="rankingPoints",Ef="roundNaming",Tl="participant",pu="progression",$f="scheduling",$V="avoidance",da="scoring",pa="seeding",fu="feedIn",NV="draws";function Nf({policyDefinitions:t,generateReport:e,matchUpFormat:r,matchUps:n=[],subOrderMap:o,perPlayer:i}){if(!Array.isArray(n))return{error:ko};if(n.reduce((I,{structureId:P})=>I.includes(P)?I:I.concat(P),[]).length!==1)return{error:X,info:"Maximum one structureId"};const a=n.filter(I=>I&&I.matchUpStatus!==nt),l=a.length&&We(a.map(({drawPositions:I})=>I).flat()).length,c=a.filter(I=>ca({matchUp:I})).length===a.length;c||(i=0);const u=n.every(({matchUpType:I,tieMatchUps:P})=>I===Qe&&P.every(y=>ca({matchUp:y}))),p=t==null?void 0:t[sI],d=n.filter(I=>ca({matchUp:I})||I.matchUpType===Qe),{participantResults:v}=K_({matchUps:d,matchUpFormat:r,tallyPolicy:p,perPlayer:i});let f,m;const{groupOrder:h,report:g}=nI({matchUps:d,participantResults:v,participantsCount:l,matchUpFormat:r,tallyPolicy:p,subOrderMap:o});if(c&&h)f=g,m=h,h.forEach(I=>{const{participantId:P,groupOrder:y,rankOrder:S,subOrder:O,ties:b,GEMscore:w}=I,T=v[P];Object.assign(T,{groupOrder:y,rankOrder:S,GEMscore:w,subOrder:O,ties:b})});else{const{groupOrder:I,report:P}=nI({requireCompletion:!1,participantResults:v,participantsCount:l,matchUpFormat:r,tallyPolicy:p,subOrderMap:o,matchUps:n});f=P,m=I,I&&I.forEach(y=>{const{participantId:S,groupOrder:O,GEMscore:b}=y,w=v[S];Object.assign(w,{provisionalOrder:O,GEMscore:b})})}const _={completedTieMatchUps:u,readableReport:"",participantResults:v,bracketComplete:c,order:[],report:f};if((c||u)&&(_.order=m),e||zt({tally:!0})){const I=IV({matchUps:n,report:f,order:m});zt({tally:!0})&&console.log(I),_.readableReport=I}return _}function UV({collectionDefinition:t,groupValueNumbers:e,groupValueGroups:r,sideTieValues:n,tieMatchUps:o}){const i=o.filter(_=>_.collectionId===t.collectionId),s=[0,0];let a=[0,0];const l=i.every(_=>Yt.includes(_.matchUpStatus)),{collectionValueProfiles:c,collectionGroupNumber:u,collectionValue:p,matchUpValue:d,winCriteria:v,scoreValue:f,setValue:m}=t,h=u&&e.includes(u),g=[0,0];if(i.forEach(_=>{_.winningSide&&(g[_.winningSide-1]+=1)}),d?i.forEach(_=>{_.winningSide&&(s[_.winningSide-1]+=d)}):m?i.forEach(_=>{var I,P;(P=(I=_.score)==null?void 0:I.sets)==null||P.forEach(y=>{y.winningSide&&(s[y.winningSide-1]+=m)})}):f?i.forEach(_=>{var I,P;(P=(I=_.score)==null?void 0:I.sets)==null||P.forEach(y=>{const{side1TiebreakScore:S=0,side2TiebreakScore:O=0,side1Score:b=0,side2Score:w=0}=y;(_.matchUpStatus===Mt||_.winningSide||y.winningSide)&&(b||w?(s[0]+=b,s[1]+=w):(S||O)&&y.winningSide&&(s[y.winningSide-1]+=1))})}):Array.isArray(c)&&i.forEach(_=>{if(_.winningSide){const I=_.collectionPosition,P=AV({collectionDefinition:t,collectionPosition:I});s[_.winningSide-1]+=P}}),p){let _;if(v!=null&&v.aggregateValue)l&&((d||m||f)&&s[0]!==s[1]?_=s[0]>s[1]?1:2:g[0]!==g[1]&&(_=g[0]>g[1]?1:2));else if(v!=null&&v.valueGoal)_=s.reduce((I,P,y)=>P>=v.valueGoal?y+1:I,0);else{const I=Math.floor(t.matchUpCount/2)+1;_=g.reduce((P,y,S)=>y>=I?S+1:P,0)}_&&(h?r[u].values[_-1]+=p:a[_-1]+=p)}else h?(r[u].values[0]+=s[0]||0,r[u].values[1]+=s[1]||0):a=s;h?(r[u].sideWins[0]+=g[0]||0,r[u].sideWins[1]+=g[1]||0,r[u].allGroupMatchUpsCompleted=r[u].allGroupMatchUpsCompleted&&l,r[u].matchUpsCount+=i.length):a.forEach((_,I)=>n[I]+=_)}function AV({collectionDefinition:t,collectionPosition:e}){const r=t.collectionValueProfiles||[],n=r==null?void 0:r.find(o=>o.collectionPosition===e);return n==null?void 0:n.matchUpValue}const os="appliedPolicies",vu="positionActions",aI="context",mu="delegatedOutcome",gn="disabled",hu="disableLinks",fa="disableAutoCalc",gu="drawDeletions",CV="drawProfile",_u="entryProfile",MV="eventProfile",DV="factory",_n="flightProfile",Uf="groupingAttribute",kn="lineUps",is="linkedTournamentsIds",Iu="matchUpHistory",Af="participantRepresentatives",va="personRequests",lI="rankingPoints",Gn="roundTarget",ss="scheduleLimits",Wn="scheduleTiming",Yo="schedulingProfile",jV="statusDetail",ma="subOrder",Ko="tally",as="tieFormatModification",cI={APPLIED_POLICIES:os,AUDIT_POSITION_ACTIONS:vu,CONTEXT:aI,DELEGATED_OUTCOME:mu,DISABLED:gn,DISABLE_LINKS:hu,DISABLE_AUTO_CALC:fa,DRAW_DELETIONS:gu,DRAW_PROFILE:CV,ENTRY_PROFILE:_u,EVENT_PROFILE:MV,FLIGHT_PROFILE:_n,GROUPING_ATTRIBUTE:Uf,LINEUPS:kn,LINKED_TOURNAMENTS:is,MATCHUP_HISTORY:Iu,PARTICIPANT_REPRESENTATIVES:Af,PERSON_REQUESTS:va,RANKING_POINTS:lI,ROUND_TARGET:Gn,SCHEDULE_LIMITS:ss,SCHEDULE_TIMING:Wn,SCHEDULING_PROFILE:Yo,STATUS_DETAIL:jV,SUB_ORDER:ma,TALLY:Ko,TIE_FORMAT_MODIFICATIONS:as,FACTORY:DV},uI=[mu,gn,hu,_n,kn,Iu,Af,va,Gn,ss,Wn,Yo,ma,Ko];var RV=Object.defineProperty,dI=Object.getOwnPropertySymbols,FV=Object.prototype.hasOwnProperty,xV=Object.prototype.propertyIsEnumerable,pI=(t,e,r)=>e in t?RV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,LV=(t,e)=>{for(var r in e||(e={}))FV.call(e,r)&&pI(t,r,e[r]);if(dI)for(var r of dI(e))xV.call(e,r)&&pI(t,r,e[r]);return t};function pt({onlySpecifiedPolicyTypes:t=!1,policyTypes:e=[],tournamentRecord:r,drawDefinition:n,structure:o,event:i}){if(!Array.isArray(e))return{error:Xg};const s={};return r&&a(r),i&&a(i),n&&a(n),o&&a(o),LV({appliedPolicies:s},V);function a(l){var c;const u=l==null?void 0:l.extensions,p=(c=u==null?void 0:u.find(d=>d.name===os))==null?void 0:c.value;if(p)for(const d of Object.keys(p))(t?e.includes(d):!e.length||e.includes(d))&&(s[d]=de(p[d],!1,!0))}}function ls({policyTypes:t=[],tournamentRecord:e,drawDefinition:r,structure:n,event:o}){if(!Array.isArray(t))return{error:Xg};const{appliedPolicies:i}=pt({tournamentRecord:e,drawDefinition:r,structure:n,event:o}),s={};for(const a of t){const l=i==null?void 0:i[a];l&&(s[a]=l)}return Object.keys(s).length?{policyDefinitions:s}:{error:nf}}const fI="WALKOVER",vI="RETIRED",Cf="COMPETITIVE",wl="ROUTINE",El="DECISIVE",$l="winRatio",Mf={[zo]:{policyName:"Competitive Bands Default",competitiveProfile:{[El]:20,[wl]:50}}};function wo({policyDefinitions:t,tournamentRecord:e,contextProfile:r,drawDefinition:n,event:o}){const i={policies:{}};if(!r)return i;const s=ls({tournamentRecord:e,drawDefinition:n,event:o}).policyDefinitions;if(r.withCompetitiveness){const a=(t==null?void 0:t[zo])||(s==null?void 0:s[zo])||Mf[zo];i.policies[zo]=a}return i}function mI({matchUps:t,matchUpId:e}){return{matchUp:(t||[]).find(n=>n.matchUpId===e)}}function VV({matchUps:t}){const e=t.reduce((n,o)=>!o.collectionPosition||n.includes(o.collectionPosition)?n:n.concat(o.collectionPosition),[]).map(n=>({[n]:t.filter(o=>o.collectionPosition===n)}));return{collectionPositionMatchUps:Object.assign({},...e)}}const BV=(t,e)=>(t||0)+(e||0);function hI(t,e){return isNaN(t)&&fI||t<=e[El]&&El||t<=e[wl]&&wl||Cf}function gI({score:t}){const e=(t==null?void 0:t.sets)||[],r=e.reduce((o,i)=>(o[0]+=i.side1Score||0,o[1]+=i.side2Score||0,o),[0,0]),n=e.reduce((o,i)=>(o[0]+=i.side1TiebreakScore||0,o[1]+=i.side2TiebreakScore||0,o),[0,0]);return n.reduce(BV)&&(r[n[0]>n[1]?0:1]+=1),{sets:e,games:r,score:t}}function kV(t){const e=Math.min(...t.games),r=Math.max(...t.games);return Math.round(e/r*100)}function _I(t){return t.map(kV).sort().map(e=>e.toFixed(2))}function cs({tournamentRecord:t,drawDefinition:e,policyType:r,structure:n,event:o}){if(!t)return{error:re};const{appliedPolicies:i}=pt({tournamentRecord:t,drawDefinition:e,structure:n,event:o});return i!=null&&i[r]?{policy:i[r]}:{error:nf}}var GV=Object.defineProperty,WV=Object.defineProperties,HV=Object.getOwnPropertyDescriptors,II=Object.getOwnPropertySymbols,qV=Object.prototype.hasOwnProperty,zV=Object.prototype.propertyIsEnumerable,PI=(t,e,r)=>e in t?GV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,YV=(t,e)=>{for(var r in e||(e={}))qV.call(e,r)&&PI(t,r,e[r]);if(II)for(var r of II(e))zV.call(e,r)&&PI(t,r,e[r]);return t},KV=(t,e)=>WV(t,HV(e));function yI({competitiveProfile:t,tournamentRecord:e,matchUp:r}){if(!r)return{error:jr};const{score:n,winningSide:o}=r;if(!o)return{error:X};const i=!t&&e&&cs({policyType:zo,tournamentRecord:e}).policy,s=t||(i==null?void 0:i.competitiveProfile)||Mf[zo].competitiveProfile,a=gI({score:n}),l=_I([a]),c=hI(l,s);return KV(YV({},V),{competitiveness:c})}function Nl(t){const{matchUpAverageTimes:e,matchUpFormat:r}=t||{},n=(e==null?void 0:e.map(({matchUpFormatCodes:a})=>a==null?void 0:a.filter(l=>l===r)).flat().filter(Boolean).sort((a,l)=>((a==null?void 0:a.length)||0)-((l==null?void 0:l.length)||0)))||[],i=n.includes(r)?r:n[0],s=e==null?void 0:e.find(({matchUpFormatCodes:a,averageTimes:l})=>(a==null?void 0:a.find(c=>i===c))&&l);return s==null?void 0:s.averageTimes}function Ul(t){var e;const{matchUpRecoveryTimes:r,averageMinutes:n,matchUpFormat:o}=t||{};return(e=r==null?void 0:r.find(({matchUpFormatCodes:i,averageTimes:s,recoveryTimes:a})=>{if(s&&n){const{greaterThan:l=0,lessThan:c=360}=s;if(n>l&&n<c)return!0}return(i==null?void 0:i.find(l=>l===o))&&a}))==null?void 0:e.recoveryTimes}function SI({timesBlockArray:t,categoryName:e,categoryType:r}){return t.filter(n=>Array.isArray(n)).map(n=>n.sort((o,i)=>{var s,a;return(((s=i.categoryNames)==null?void 0:s.length)||0)-(((a=o.categoryNames)==null?void 0:a.length)||0)}).find(({categoryTypes:o,categoryNames:i})=>!(i!=null&&i.length)&&!(o!=null&&o.length)||(i==null?void 0:i.includes(e))||(o==null?void 0:o.includes(r)))).find(Boolean)}var QV=Object.defineProperty,JV=Object.defineProperties,ZV=Object.getOwnPropertyDescriptors,OI=Object.getOwnPropertySymbols,XV=Object.prototype.hasOwnProperty,eB=Object.prototype.propertyIsEnumerable,bI=(t,e,r)=>e in t?QV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Df=(t,e)=>{for(var r in e||(e={}))XV.call(e,r)&&bI(t,r,e[r]);if(OI)for(var r of OI(e))eB.call(e,r)&&bI(t,r,e[r]);return t},jf=(t,e)=>JV(t,ZV(e));function tB({tournamentScheduling:t,eventScheduling:e,averageMinutes:r,defaultTiming:n,matchUpFormat:o,categoryName:i,categoryType:s,policy:a}){var l;const c=(e==null?void 0:e.matchUpRecoveryTimes)&&Ul(jf(Df({},e),{averageMinutes:r,matchUpFormat:o})),u=(t==null?void 0:t.matchUpRecoveryTimes)&&Ul(jf(Df({},t),{averageMinutes:r,matchUpFormat:o})),p=(a==null?void 0:a.matchUpRecoveryTimes)&&Ul(jf(Df({},a),{averageMinutes:r,matchUpFormat:o})),d=[c,u,p,(l=a==null?void 0:a.defaultTimes)==null?void 0:l.recoveryTimes,n==null?void 0:n.recoveryTimes];return SI({categoryName:i,categoryType:s,timesBlockArray:d})}var rB=Object.defineProperty,nB=Object.defineProperties,oB=Object.getOwnPropertyDescriptors,TI=Object.getOwnPropertySymbols,iB=Object.prototype.hasOwnProperty,sB=Object.prototype.propertyIsEnumerable,wI=(t,e,r)=>e in t?rB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rf=(t,e)=>{for(var r in e||(e={}))iB.call(e,r)&&wI(t,r,e[r]);if(TI)for(var r of TI(e))sB.call(e,r)&&wI(t,r,e[r]);return t},Ff=(t,e)=>nB(t,oB(e));function aB({matchUpFormat:t,categoryName:e,categoryType:r,defaultTiming:n,tournamentScheduling:o,eventScheduling:i,policy:s}){var a;const l=(i==null?void 0:i.matchUpAverageTimes)&&Nl(Ff(Rf({},i),{matchUpFormat:t})),c=(o==null?void 0:o.matchUpAverageTimes)&&Nl(Ff(Rf({},o),{matchUpFormat:t})),u=(s==null?void 0:s.matchUpAverageTimes)&&Nl(Ff(Rf({},s),{matchUpFormat:t})),p=[l,c,u,(a=s==null?void 0:s.defaultTimes)==null?void 0:a.averageTimes,n==null?void 0:n.averageTimes];return SI({categoryName:e,categoryType:r,timesBlockArray:p})}const Ti="RANKING",us="RATING",ds="SCALE",In="SEEDING";var lB=Object.defineProperty,EI=Object.getOwnPropertySymbols,cB=Object.prototype.hasOwnProperty,uB=Object.prototype.propertyIsEnumerable,$I=(t,e,r)=>e in t?lB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,NI=(t,e)=>{for(var r in e||(e={}))cB.call(e,r)&&$I(t,r,e[r]);if(EI)for(var r of EI(e))uB.call(e,r)&&$I(t,r,e[r]);return t};function ha({participant:t}){var e;const r=(e=t.timeItems)==null?void 0:e.filter(({itemType:o})=>(o==null?void 0:o.startsWith(ds))&&[Ti,us,In].includes(o.split(".")[1])),n={ratings:{},rankings:{},seedings:{}};if(r!=null&&r.length){const o=s=>r.filter(a=>(a==null?void 0:a.itemType)===s).sort((a,l)=>new Date(a.createdAt||void 0).getTime()-new Date(l.createdAt||void 0).getTime()).pop(),i=We(r.map(({itemType:s})=>s));for(const s of i){const a=o(s);if(a){const[,l,c,u]=a.itemType.split("."),p=l===In&&"seedings"||l===Ti&&"rankings"||"ratings";n[p][c]||(n[p][c]=[]),n[p][c].push({scaleValue:a.itemValue,scaleDate:a.itemDate,scaleName:u})}}}return NI(NI({},V),n)}function Eo({tournamentParticipants:t=[],policyDefinitions:e={},contextProfile:r,participantId:n,internalUse:o,personId:i}){const s=t.find(l=>n&&l.participantId===n||i&&l.person&&l.person.personId===i),a=de(s,!1,o);if(a){const l=e==null?void 0:e[Tl];if(r!=null&&r.withScaleValues){const{ratings:c,rankings:u}=ha({participant:a});a.rankings=u,a.ratings=c}if(l!=null&&l.participant)return iu({template:l.participant,source:a})}return a}function Qo({tournamentRecord:t,participantId:e}){return{participant:(t.participants||[]).reduce((o,i)=>i.participantId===e?i:o,void 0)}}function dB({tournamentRecord:t,policyDefinitions:e,convertExtensions:r,participantId:n,personId:o}){if(!t)return{error:re};if(typeof n!="string"&&typeof o!="string")return{error:_e};const i=t.participants||[],s=Eo({tournamentParticipants:i,policyDefinitions:e,participantId:n,personId:o});return{participant:de(s,r,!0)}}const Al="extensionQueries";function Kt({element:t,name:e}){if(!t||!e)return k({result:{error:_e},stack:Al});if(!Array.isArray(t.extensions))return{info:sr};const r=t.extensions.find(o=>(o==null?void 0:o.name)===e);return{extension:r,info:r?void 0:sr}}function Fr({tournamentRecord:t,name:e}){return Kt({element:t,name:e})}function $o({event:t,name:e}){return t?Kt({element:t,name:e}):k({result:{error:Ge},stack:Al})}function Pu({drawDefinition:t,name:e}){return t?Kt({element:t,name:e}):k({result:{error:ue},stack:Al})}function pB({tournamentRecord:t,participantId:e,name:r}){if(!t)return k({result:{error:re},stack:Al});if(!e)return k({result:{error:Et},stack:Al});const{participant:n}=Qo({tournamentRecord:t,participantId:e});return Kt({element:n,name:r})}function Cl({tournamentRecord:t,categoryName:e,categoryType:r,event:n}){var o,i,s,a,l,c;e=(s=e??((o=n==null?void 0:n.category)==null?void 0:o.categoryName))!=null?s:(i=n==null?void 0:n.category)==null?void 0:i.ageCategoryCode,r=(c=r??((a=n==null?void 0:n.category)==null?void 0:a.categoryType))!=null?c:(l=n==null?void 0:n.category)==null?void 0:l.subType;const{policy:u}=cs({policyType:$f,tournamentRecord:t,event:n}),p=t?Fr({name:Wn,tournamentRecord:t}).extension:void 0,d=p==null?void 0:p.value,v=n&&$o({name:Wn,event:n}).extension,f=v==null?void 0:v.value;return{scheduleTiming:{tournamentScheduling:d,eventScheduling:f,categoryName:e,categoryType:r,policy:u}}}const fB="DOUBLES_SINGLES",vB="SINGLES_DOUBLES",Pn="total",UI="participantConflict",wi="matchUpConflict",mB="ISSUE_IDS",ps="CONFLICT",fs="WARNING",AI="ERROR",CI="ISSUE",xf="STATE";var hB=Object.defineProperty,gB=Object.defineProperties,_B=Object.getOwnPropertyDescriptors,MI=Object.getOwnPropertySymbols,IB=Object.prototype.hasOwnProperty,PB=Object.prototype.propertyIsEnumerable,DI=(t,e,r)=>e in t?hB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jI=(t,e)=>{for(var r in e||(e={}))IB.call(e,r)&&DI(t,r,e[r]);if(MI)for(var r of MI(e))PB.call(e,r)&&DI(t,r,e[r]);return t},RI=(t,e)=>gB(t,_B(e));function Lf({defaultAverageMinutes:t=90,defaultRecoveryMinutes:e=0,tournamentRecord:r,matchUpFormat:n,categoryName:o,categoryType:i,eventType:s,event:a}){if(!r)return{error:re};s=s||(a==null?void 0:a.eventType)||Cr.Singles;const l={averageTimes:[{minutes:{default:t}}],recoveryTimes:[{minutes:{default:e}}]},{scheduleTiming:c}=Cl({tournamentRecord:r,categoryName:o,categoryType:i,event:a}),u=RI(jI({},c),{matchUpFormat:n,categoryType:i,defaultTiming:l});return yu({eventType:s,timingDetails:u})}function yu({timingDetails:t,eventType:e}){const r=aB(t),n=Object.keys((r==null?void 0:r.minutes)||{}),o=(r==null?void 0:r.minutes)&&((n==null?void 0:n.includes(e))&&r.minutes[e]||r.minutes.default),i=tB(RI(jI({},t),{averageMinutes:o})),s=Object.keys((i==null?void 0:i.minutes)||{}),a=(i==null?void 0:i.minutes)&&((s==null?void 0:s.includes(e))&&i.minutes[e]||i.minutes.default),l=e===At?vB:fB,c=(i==null?void 0:i.minutes)&&((s==null?void 0:s.includes(l))&&i.minutes[l]||a);return{averageMinutes:o,recoveryMinutes:a,typeChangeRecoveryMinutes:c}}function on({requiredAttributes:t=["name","value"],extension:e}){if(!e||typeof e!="object"||typeof e.name!="string")return!1;const r=Object.keys(e);return t.filter(n=>r.includes(n)).length===t.length}function Nt({event:t,eventId:e}){var r;if(!t)return{error:Ge};const n=$o({name:_n,event:t}),o=n==null?void 0:n.extension,i=e?de(o==null?void 0:o.value,!1,!0):o==null?void 0:o.value;return e&&((r=t.drawDefinitions)==null||r.forEach(s=>{var a;(a=i==null?void 0:i.flights)==null||a.forEach(l=>{l.drawId===s.drawId&&Object.assign(l,{drawDefinition:s})})})),{flightProfile:i}}var yB=Object.defineProperty,SB=Object.defineProperties,OB=Object.getOwnPropertyDescriptors,FI=Object.getOwnPropertySymbols,bB=Object.prototype.hasOwnProperty,TB=Object.prototype.propertyIsEnumerable,xI=(t,e,r)=>e in t?yB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Su=(t,e)=>{for(var r in e||(e={}))bB.call(e,r)&&xI(t,r,e[r]);if(FI)for(var r of FI(e))TB.call(e,r)&&xI(t,r,e[r]);return t},wB=(t,e)=>SB(t,OB(e));function EB({tournamentRecord:t,drawDefinition:e,event:r,context:n}){var o;if(!t)return{error:re};if(!r)return{error:Ge};const i=de(r);n&&Object.assign(i,n);const s=e&&((o=i.drawDefinitions)==null?void 0:o.find(({drawId:a})=>e.drawId===a));return Oe({event:i,drawDefinition:s})}function $B({tournamentRecord:t,context:e,inContext:r}){if(!t)return{error:re};const{tournamentId:n}=t;return{events:(t.events||[]).map(i=>{const s=de(i);return e&&Object.assign(s,e),r&&Object.assign(s,{tournamentId:n}),s})}}function Qt({tournamentRecord:t,eventId:e,drawId:r}){const n="findEvent";if(!t)return Su({event:void 0,drawDefinition:void 0},k({result:{error:re},stack:n}));const o=(t==null?void 0:t.events)||[];if(r){let i;const s=o.find(a=>{var l;const u=((a==null?void 0:a.drawDefinitions)||[]).find(p=>p.drawId===r);if(u)i=u;else{const{flightProfile:p}=Nt({event:a}),d=(l=p==null?void 0:p.flights)==null?void 0:l.find(v=>v.drawId===r);if(d)return{drawId:r,entries:d.drawEntries,drawName:d.drawName}}return u});if(s)return{event:s,drawDefinition:i}}if(e){const i=o.find(s=>s.eventId===e);return i?{event:i,drawDefinition:void 0}:Su({event:void 0,drawDefinition:void 0},k({result:{error:Ar},stack:n}))}return Su({event:void 0,drawDefinition:void 0},k({result:{error:en},context:{drawId:r,eventId:e},stack:n}))}function Jo({tournamentRecord:t,drawId:e}){if(!t)return{error:re};if(!e)return{error:kr};const r=(t.events||[]).reduce((n,o)=>{const i=(o.drawDefinitions||[]).reduce((s,a)=>a.drawId===e?a:s,void 0);return i&&i.drawId===e?{event:o,drawDefinition:i}:n},void 0);return r?wB(Su({},r),{SUCCESS:V}):k({result:{error:en},stack:"getDrawDefinition"})}var NB=Object.defineProperty,LI=Object.getOwnPropertySymbols,UB=Object.prototype.hasOwnProperty,AB=Object.prototype.propertyIsEnumerable,VI=(t,e,r)=>e in t?NB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,CB=(t,e)=>{for(var r in e||(e={}))UB.call(e,r)&&VI(t,r,e[r]);if(LI)for(var r of LI(e))AB.call(e,r)&&VI(t,r,e[r]);return t};function it(t){if(typeof t!="object")return{error:_e};const e="addExtension";if(!(t!=null&&t.element))return k({result:{error:_e},stack:e});if(typeof t.element!="object")return k({result:{error:X},stack:e});if(!on({extension:t.extension}))return k({result:{error:X,info:"invalid extension"},stack:e});if(t.element.extensions||(t.element.extensions=[]),t.creationTime!==void 0?t.creationTime:!0){const o=new Date().toISOString();Object.assign(t.extension,{createdAt:o})}const n=t.element.extensions.find(({name:o})=>o===t.extension.name);return n?n.value=t.extension.value:t.extension.value&&t.element.extensions.push(t.extension),CB({},V)}const Vf="element required",Bf="missing name";var MB=Object.defineProperty,DB=Object.defineProperties,jB=Object.getOwnPropertyDescriptors,BI=Object.getOwnPropertySymbols,RB=Object.prototype.hasOwnProperty,FB=Object.prototype.propertyIsEnumerable,kI=(t,e,r)=>e in t?MB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,GI=(t,e)=>{for(var r in e||(e={}))RB.call(e,r)&&kI(t,r,e[r]);if(BI)for(var r of BI(e))FB.call(e,r)&&kI(t,r,e[r]);return t},xB=(t,e)=>DB(t,jB(e));function yn(t){return!t||typeof t!="object"?{error:_e}:t!=null&&t.element?typeof(t==null?void 0:t.element)!="object"?{error:X}:t!=null&&t.name?t!=null&&t.element.extensions?(t.element.extensions=t.element.extensions.filter(e=>(e==null?void 0:e.name)!==t.name),GI({},V)):xB(GI({},V),{info:sr}):{error:_e,info:Bf}:{error:_e,info:Vf}}function Ei(t){return!t||typeof t!="object"?{error:_e}:t.tournamentRecord?it({creationTime:t.creationTime,element:t.tournamentRecord,extension:t.extension}):{error:re}}function kf(t){return!t||typeof t!="object"?{error:_e}:t.drawDefinition?it({creationTime:t.creationTime,element:t.drawDefinition,extension:t.extension}):{error:en}}function ao(t){return!t||typeof t!="object"?{error:_e}:t.event?it({creationTime:t.creationTime,extension:t.extension,element:t.event}):{error:Ge}}function LB(t){var e;if(!t||typeof t!="object")return{error:_e};if(!t.participantId)return{error:Et};const r=((e=t.tournamentRecord)==null?void 0:e.participants)||[],n=Eo({participantId:t.participantId,tournamentParticipants:r});return n?it({creationTime:t.creationTime,extension:t.extension,element:n}):{error:jt}}function Gf(t){return!t||typeof t!="object"?{error:_e}:t.tournamentRecord?yn({element:t.tournamentRecord,name:t.name}):{error:re}}function VB(t){return!t||typeof t!="object"?{error:_e}:t.drawDefinition?yn({element:t.drawDefinition,name:t.name}):{error:en}}function Ou(t){return!t||typeof t!="object"?{error:_e}:t!=null&&t.event?yn({element:t.event,name:t.name}):{error:Ar}}function BB(t){var e;if(!t||typeof t!="object")return{error:_e};if(!t.participantId)return{error:Et};const r=((e=t.tournamentRecord)==null?void 0:e.participants)||[],n=Eo({participantId:t.participantId,tournamentParticipants:r});return n?yn({element:n,name:t.name}):{error:jt}}var kB=Object.defineProperty,GB=Object.defineProperties,WB=Object.getOwnPropertyDescriptors,WI=Object.getOwnPropertySymbols,HB=Object.prototype.hasOwnProperty,qB=Object.prototype.propertyIsEnumerable,HI=(t,e,r)=>e in t?kB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qI=(t,e)=>{for(var r in e||(e={}))HB.call(e,r)&&HI(t,r,e[r]);if(WI)for(var r of WI(e))qB.call(e,r)&&HI(t,r,e[r]);return t},zB=(t,e)=>GB(t,WB(e));function Wf({tournamentRecords:t,extension:e}){if(!on({extension:e}))return{error:X};const r="addExtension";for(const n of Object.values(t)){const o=Ei({tournamentRecord:n,extension:e});if(o.error)return k({result:o,stack:r})}return qI({},V)}function bu({tournamentRecords:t,name:e}){if(!e)return{error:_e,info:Bf};let r;return Object.keys(t).find(o=>{const i=t[o],{extension:s}=Fr({tournamentRecord:i,name:e});return r=s,!!s})?{extension:r}:{error:sr}}function Tu({tournamentRecords:t,name:e}){if(!e)return{error:_e,info:Bf};let r=0;for(const n of Object.keys(t)){const o=t[n],i=Gf({tournamentRecord:o,name:e});if(i.error)return k({result:i,stack:"removeExtension"});i.info!==sr&&r++}return zB(qI({},V),{removed:r})}function YB({tournamentRecords:t,eventId:e,extension:r}){if(typeof e!="string")return{error:Ge};if(!on({extension:r}))return{error:X};for(const n of Object.values(t)){const{event:o}=Qt({tournamentRecord:n,eventId:e});if(o)return ao({event:o,extension:r})}return{error:Ar}}var KB=Object.defineProperty,zI=Object.getOwnPropertySymbols,QB=Object.prototype.hasOwnProperty,JB=Object.prototype.propertyIsEnumerable,YI=(t,e,r)=>e in t?KB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,KI=(t,e)=>{for(var r in e||(e={}))QB.call(e,r)&&YI(t,r,e[r]);if(zI)for(var r of zI(e))JB.call(e,r)&&YI(t,r,e[r]);return t};function Hf({tournamentRecords:t}){return typeof t!="object"||!Object.keys(t).length?{error:ke}:{linkedTournamentIds:Object.assign({},...Object.keys(t).map(r=>{var n;const o=t[r],i=o==null?void 0:o.tournamentId,{extension:s}=Fr({tournamentRecord:o,name:is}),a=(((n=s==null?void 0:s.value)==null?void 0:n.tournamentIds)||[]).filter(l=>l!==i);return{[r]:a}}))}}function ZB({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const e=QI(t),{tournamentIds:r}=e;return(r==null?void 0:r.length)>1?Wf({tournamentRecords:t,extension:{name:is,value:{tournamentIds:r}}}):KI({},V)}function XB({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const e=Tu({name:is,tournamentRecords:t});return k({result:e,stack:"unlinkTournaments"})}function ek({tournamentRecords:t,tournamentId:e}){if(typeof t!="object")return{error:X};if(!e)return{error:yo};const r=QI(t),{tournamentIds:n}=r;if(!n.includes(e))return{error:yo};let o;return n.every(i=>{var s;const a=t[i],{extension:l}=Fr({tournamentRecord:a,name:is});if(!l)return!0;const c=((s=l==null?void 0:l.value)==null?void 0:s.tournamentIds)||[];if(!(c!=null&&c.length)||c.length===1&&c.includes(e)||i===e){const d=Gf({name:is,tournamentRecord:a});return d.error&&(o=d.error),d.success}const u=c.filter(d=>d!==e);l.value={tournamentIds:u};const p=Ei({tournamentRecord:a,extension:l});return p.error&&(o=p.error),p.success}),o?{error:o}:KI({},V)}function QI(t){return{tournamentIds:Object.keys(t).filter(Boolean)}}function JI({extension:t,dates:e=[]}){if(!t)return!1;if(typeof t.value=="boolean"&&t.value)return!0;if(typeof t.value=="object"&&Array.isArray(t.value.dates))return e.length?!!e.filter(n=>t.value.dates.includes(n)).length:!0}function xr({element:t,name:e}){const r="findExtension";if(!t||!e)return k({result:{error:_e},stack:r});if(!Array.isArray(t.extensions))return k({result:{error:sr},stack:r});const n=t.extensions.find(o=>(o==null?void 0:o.name)===e);return n?{extension:n}:k({result:{error:sr},stack:r})}var tk=Object.defineProperty,rk=Object.defineProperties,nk=Object.getOwnPropertyDescriptors,ZI=Object.getOwnPropertySymbols,ok=Object.prototype.hasOwnProperty,ik=Object.prototype.propertyIsEnumerable,XI=(t,e,r)=>e in t?tk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sk=(t,e)=>{for(var r in e||(e={}))ok.call(e,r)&&XI(t,r,e[r]);if(ZI)for(var r of ZI(e))ik.call(e,r)&&XI(t,r,e[r]);return t},ak=(t,e)=>rk(t,nk(e));function eP({convertExtensions:t,ignoreDisabled:e,venue:r,court:n}){const o=ak(sk({},de(n,t,!0)),{venueId:r.venueId}),{extension:i}=xr({name:gn,element:n});if(e&&i){const s=typeof i.value=="object"&&i.value.dates||[],a=i.value===!0?[]:o.dateAvailability.map(l=>{const c=l.date;if(!(!c||s.includes(c)))return l}).filter(Boolean);o.dateAvailability=a}return{inContextCourt:o}}const tP="addDrawDefinition",qf="addMatchUps",$i="addParticipants",rP="addScaleItems",nP="addVenue",Ml="audit",oP="deleteParticipants",iP="deleteVenue",sP="deletedDrawIds",aP="deletedMatchUpIds",lP="modifyDrawDefinition",lk="modifyDrawEntries",ck="modifyEventEntries",cP="modifyMatchUp",rr="modifyParticipants",uP="modifyPositionAssignments",dP="modifySeedAssignments",uk="modifyTournamentDetail",vs="modifyVenue",pP="mutations",dk="publishEvent",pk="publishEventSeeding",fk="publishOrderOfPlay",fP="unPublishEvent",vP="unPublishEventSeeding",mP="unPublishOrderOfPlay",zf="updateInContextMatchUp";var vk=Object.defineProperty,mk=Object.defineProperties,hk=Object.getOwnPropertyDescriptors,hP=Object.getOwnPropertySymbols,gk=Object.prototype.hasOwnProperty,_k=Object.prototype.propertyIsEnumerable,gP=(t,e,r)=>e in t?vk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ik=(t,e)=>{for(var r in e||(e={}))gk.call(e,r)&&gP(t,r,e[r]);if(hP)for(var r of hP(e))_k.call(e,r)&&gP(t,r,e[r]);return t},Pk=(t,e)=>mk(t,hk(e));function Dl({tournamentRecord:t,disableNotice:e,context:r,venue:n}){return t?n?(t.venues||(t.venues=[]),n.venueId||(n.venueId=Ye()),t.venues.reduce((i,s)=>i||s.venueId===n.venueId,void 0)?{error:Vx}:(r&&it({element:n,extension:{value:r,name:aI}}),t.venues.push(n),e||He({payload:{venue:n,tournamentId:t.tournamentId},topic:nP}),Pk(Ik({},V),{venue:de(n)}))):{error:_e,info:"missing venue"}:{error:re}}var yk=Object.defineProperty,Sk=Object.defineProperties,Ok=Object.getOwnPropertyDescriptors,wu=Object.getOwnPropertySymbols,_P=Object.prototype.hasOwnProperty,IP=Object.prototype.propertyIsEnumerable,PP=(t,e,r)=>e in t?yk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yP=(t,e)=>{for(var r in e||(e={}))_P.call(e,r)&&PP(t,r,e[r]);if(wu)for(var r of wu(e))IP.call(e,r)&&PP(t,r,e[r]);return t},SP=(t,e)=>Sk(t,Ok(e)),bk=(t,e)=>{var r={};for(var n in t)_P.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&wu)for(var n of wu(t))e.indexOf(n)<0&&IP.call(t,n)&&(r[n]=t[n]);return r};function Yf({convertExtensions:t,tournamentRecord:e,ignoreDisabled:r,dates:n}){var o;if(!e)return{error:re};const i=de((o=e.venues)!=null?o:[],t).filter(a=>{if(!r)return a;const{extension:l}=xr({name:gn,element:a});return!(l!=null&&l.value)&&a}).filter(Boolean),s=i.reduce((a,l)=>{const c=((l==null?void 0:l.courts)||[]).filter(u=>{if(!r&&!(n!=null&&n.length))return u;const{extension:p}=xr({name:gn,element:u});return JI({extension:p,dates:n})}).filter(Boolean).map(u=>{const{inContextCourt:p}=eP({convertExtensions:t,ignoreDisabled:r,venue:l,court:u});return p});return c.length?a.concat(c):a},[]);return{venues:i,courts:s}}function Zo({tournamentRecords:t,tournamentRecord:e,venueId:r}){var n;if(!e)return{error:re};if(!r)return{error:Go};const i=((n=e.venues)!=null?n:[]).reduce((s,a)=>a.venueId===r?a:s,void 0);if(!i&&t){const a=(Hf({tournamentRecords:t}).linkedTournamentIds||[])[e.tournamentId];for(const l of a){const c=t[l],u=Zo({tournamentRecord:c,venueId:r});if(u.success&&u.venue)return Dl({tournamentRecord:e,venue:u.venue}),SP(yP({},V),{venue:i})}}return i?SP(yP({},V),{venue:i}):{error:Ii}}function Tk(t){var e=t,{convertExtensions:r}=e,n=bk(e,["convertExtensions"]);const{tournamentRecords:o,tournamentRecord:i,venueId:s}=n,a=Zo({tournamentRecords:o,tournamentRecord:i,venueId:s});return de(a,r,!0)}var wk=Object.defineProperty,Ek=Object.defineProperties,$k=Object.getOwnPropertyDescriptors,OP=Object.getOwnPropertySymbols,Nk=Object.prototype.hasOwnProperty,Uk=Object.prototype.propertyIsEnumerable,bP=(t,e,r)=>e in t?wk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,TP=(t,e)=>{for(var r in e||(e={}))Nk.call(e,r)&&bP(t,r,e[r]);if(OP)for(var r of OP(e))Uk.call(e,r)&&bP(t,r,e[r]);return t},wP=(t,e)=>Ek(t,$k(e));function ms({tournamentRecords:t,tournamentRecord:e,courtId:r}){var n;if(!e)return{error:re};if(!r)return{error:na};const o="findCourt";let i,s;if(((n=e.venues)!=null?n:[]).forEach(a=>{var l;((l=a.courts)!=null?l:[]).forEach(c=>{c.courtId===r&&(i=c,s=a)})}),i)return wP(TP({},V),{court:i,venue:s});if(t){const l=(Hf({tournamentRecords:t}).linkedTournamentIds||[])[e.tournamentId];for(const c of l){const u=t[c],p=ms({tournamentRecord:u,courtId:r});if(p.success)return p.venue&&Dl({tournamentRecord:e,venue:p.venue}),wP(TP({},V),{court:i,venue:s})}}return k({result:{error:df},stack:o})}function Ak(t){return de(ms(t),!1,!0)}function Ck({tournamentRecord:t,venueId:e,venueIds:r}){return t?{courts:(t.venues||[]).filter(o=>e?o.venueId===e:r?r.includes(o.venueId):!0).map(o=>{const{venueId:i}=o,s=de(o.courts||[]);return s.forEach(a=>Object.assign(a,{venueId:i})),s}).flat()}:{error:re}}var Mk=Object.defineProperty,Dk=Object.defineProperties,jk=Object.getOwnPropertyDescriptors,EP=Object.getOwnPropertySymbols,Rk=Object.prototype.hasOwnProperty,Fk=Object.prototype.propertyIsEnumerable,$P=(t,e,r)=>e in t?Mk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xk=(t,e)=>{for(var r in e||(e={}))Rk.call(e,r)&&$P(t,r,e[r]);if(EP)for(var r of EP(e))Fk.call(e,r)&&$P(t,r,e[r]);return t},Lk=(t,e)=>Dk(t,jk(e));function NP({tournamentRecord:t,internalUse:e,courtId:r}){if(!t)return{error:re};if(!r)return{error:na};const n=ms({tournamentRecord:t,courtId:r});if(n.error)return n;const o=n.court&&(({altitude:i,courtId:s,courtName:a,courtDimensions:l,latitude:c,longitude:u,surfaceCategory:p,surfaceType:d,surfacedDate:v,pace:f,notes:m})=>({altitude:i,courtId:s,courtName:a,courtDimensions:l,latitude:c,longitude:u,surfaceCategory:p,surfaceType:d,surfacedDate:v,pace:f,notes:m}))(n.court);return Lk(xk({},V),{courtInfo:de(o,!1,e)})}var Vk=Object.defineProperty,Bk=Object.defineProperties,kk=Object.getOwnPropertyDescriptors,UP=Object.getOwnPropertySymbols,Gk=Object.prototype.hasOwnProperty,Wk=Object.prototype.propertyIsEnumerable,AP=(t,e,r)=>e in t?Vk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kf=(t,e)=>{for(var r in e||(e={}))Gk.call(e,r)&&AP(t,r,e[r]);if(UP)for(var r of UP(e))Wk.call(e,r)&&AP(t,r,e[r]);return t},CP=(t,e)=>Bk(t,kk(e));function Eu({tournamentRecord:t,venueId:e}){var r,n;if(!t)return{error:re};if(!e)return{error:Go};const o=Zo({tournamentRecord:t,venueId:e});if(o.error)return o;const s=((n=(r=o.venue)==null?void 0:r.courts)!=null?n:[]).map(c=>(({courtInfo:u})=>Kf({},u))(NP({courtId:c.courtId,internalUse:!0,tournamentRecord:t}))),a=o.venue&&(({venueId:c,venueName:u,venueAbbreviation:p})=>({venueAbbreviation:p,venueName:u,venueId:c}))(o.venue),l=a&&CP(Kf({},a),{courtsInfo:s});return CP(Kf({},V),{venueData:de(l,!1,!0)})}const Qf="CHECK_IN",Jf="CHECK_OUT",jl="SCHEDULE.ASSIGNMENT.VENUE",Xo="SCHEDULE.ALLOCATION.COURTS",hs="SCHEDULE.ASSIGNMENT.COURT",MP="SCHEDULE.COURT.ORDER",Rl="SCHEDULE.DATE",Hk="SCHEDULE.ASSIGN.OFFICIAL",Fl="SCHEDULE.TIME.SCHEDULED",Hn="SCHEDULE.TIME.START",ei="SCHEDULE.TIME.STOP",No="SCHEDULE.TIME.RESUME",ti="SCHEDULE.TIME.END",DP="SCHEDULE.TIME.MODIFIERS",jP=["TO_BE_ANNOUNCED","NEXT_AVAILABLE","FOLLOWED_BY","AFTER_REST","RAIN_DELAY"],qk="SCALE",zk="RATING",Yk="RANKING",RP="SEEDING",Hr="PUBLISH",qn="PUBLIC",qr="STATUS";function $u(t){return t.createdAt?new Date(t.createdAt).getTime():0}function Ni({visibilityThreshold:t,timeItems:e,itemType:r}){const n=e.filter(i=>i&&i.itemType===r&&(!t||$u(i)<new Date(t).getTime())).sort((i,s)=>$u(i)-$u(s)).pop(),o=n&&$u(n);return{itemValue:n==null?void 0:n.itemValue,timeStamp:o}}function Zf({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Fl,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{scheduledTime:o}:r}function Ui({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Rl,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{scheduledDate:o}:r}function FP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Xo,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{allocatedCourts:de(o,!1,!0)}:r}function xP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:hs,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{courtId:o}:r}function LP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:jl,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{venueId:o}:r}function Xf({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:DP,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{timeModifiers:o}:r}function gs(t){if(M_.test(t)){const e=gf();return new Date(`${e}T${t}`)}else return new Date(t)}function VP({matchUp:t}){if(!t)return{error:jr};if(!t.timeItems)return{error:g_};const e=t.timeItems.filter(n=>[Hn,ei,No,ti].includes(n==null?void 0:n.itemType)).sort((n,o)=>gs(n.itemValue).getTime()-gs(o.itemValue).getTime()),r=e.reduce((n,o)=>{var i,s;let a;const l=(i=o==null?void 0:o.itemType)==null?void 0:i.split("."),u=`SCHEDULE.TIME.${((s=o==null?void 0:o.itemType)==null?void 0:s.startsWith("SCHEDULE.TIME"))&&l[2]}`;switch(u){case Hn:a=0;break;case ti:if(n.lastValue&&[Hn,No].includes(n.lastType)){const p=gs(o.itemValue).getTime()-gs(n.lastValue).getTime();a=n.milliseconds+p}else a=n.milliseconds;break;case ei:if([Hn,"SCHECULE.TIME.RESUME"].includes(n.lastType)){const p=gs(o.itemValue).getTime()-gs(n.lastValue).getTime();a=n.milliseconds+p}else a=n.milliseconds;break;default:a=n.milliseconds;break}return{milliseconds:a,lastType:u,lastValue:o.itemValue}},{milliseconds:0,lastType:void 0,lastValue:void 0});if([Hn,No].includes(r.lastType)){const n=new Date().getTime()-gs(r.lastValue).getTime();r.milliseconds+=n}return{milliseconds:r.milliseconds,time:Kk(r.milliseconds),relevantTimeItems:e}}function Kk(t){const e=(r,n=2)=>("00"+r).slice(-n);return e(t/36e5|0)+":"+e(t%36e5/6e4|0)+":"+e(t%6e4/1e3|0)}function Qk({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:MP,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{courtOrder:o}:r}function Jk({matchUp:t}){const e=(t==null?void 0:t.timeItems)||[],r=i=>i.createdAt?new Date(i.createdAt).getTime():0,n=e.reduce((i,s)=>{const a=s.itemType===Hn&&s;return a&&(!i||r(a)<r(i))?a:i},void 0);return{startTime:n==null?void 0:n.itemValue}}function Zk({matchUp:t}){const e=(t==null?void 0:t.timeItems)||[],r=i=>i.createdAt?new Date(i.createdAt).getTime():0,n=e.reduce((i,s)=>{const a=s.itemType===ti&&s;return a&&(!i||r(a)>r(i))?a:i},void 0);return{endTime:n==null?void 0:n.itemValue}}const ri="SINGLES",BP="SINGLES",sn="DOUBLES",Nu="DOUBLES",Bt="TEAM",lo="TEAM";var Xk=Object.defineProperty,kP=Object.getOwnPropertySymbols,eG=Object.prototype.hasOwnProperty,tG=Object.prototype.propertyIsEnumerable,GP=(t,e,r)=>e in t?Xk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,rG=(t,e)=>{for(var r in e||(e={}))eG.call(e,r)&&GP(t,r,e[r]);if(kP)for(var r of kP(e))tG.call(e,r)&&GP(t,r,e[r]);return t};function ev({scheduleVisibilityFilters:t,afterRecoveryTimes:e,tournamentRecord:r,scheduleTiming:n,matchUpFormat:o,matchUpType:i,matchUp:s,event:a}){var l,c,u,p,d,v,f;if(!s)return{error:jr};if(e&&!s.matchUpType&&!i&&(a||r)&&s.drawId){let $=(l=a==null?void 0:a.drawDefinitions)==null?void 0:l.find(E=>E.drawId===s.drawId);!$&&r&&({drawDefinition:$,event:a}=Qt({tournamentRecord:r,drawId:s.drawId}));const N=s.structureId&&((c=$==null?void 0:$.structures)==null?void 0:c.find(({structureId:E})=>E===s.structureId));i=(N==null?void 0:N.matchUpType)||($==null?void 0:$.matchUpType)||(a==null?void 0:a.eventType)!==Bt&&(a==null?void 0:a.eventType)}const{milliseconds:m,time:h}=VP({matchUp:s}),{startTime:g}=Jk({matchUp:s}),{endTime:_}=Zk({matchUp:s});let I;const{visibilityThreshold:P,eventIds:y,drawIds:S}=t??{};if((!y||y.includes(s.eventId))&&(!S||S.includes(s.drawId))){const $={matchUp:s,visibilityThreshold:P},{allocatedCourts:N}=FP($),{scheduledTime:E}=Zf($);let{scheduledDate:A}=Ui($);const{venueId:U}=LP($),{courtId:C}=xP($),{courtOrder:M}=Qk($),{timeModifiers:D}=Xf($);let R,j,G,W,q;const F=(u=s.matchUpType)!=null?u:i;if(n&&E&&e&&F){const Q=rG({matchUpFormat:(p=s.matchUpFormat)!=null?p:o},n);({averageMinutes:j=0,recoveryMinutes:G=0,typeChangeRecoveryMinutes:W=0}=yu({timingDetails:Q,eventType:F})),(j||G)&&(R=_?Or(at(_),G):Or(E,j+G)),W&&(q=_?Or(at(_),W):Or(E,j+W))}!A&&E&&(A=Re(E));const L=au({scheduledDate:A,scheduledTime:E}),x={},B=((d=r&&U&&Eu({tournamentRecord:r,venueId:U}))==null?void 0:d.venueData)||{};U&&(x[U]=B);const{venueName:z,venueAbbreviation:H,courtsInfo:Y}=B,Z=C&&(Y==null?void 0:Y.find(Q=>Q.courtId===C)),K=Z==null?void 0:Z.courtName;for(const Q of N||[]){if(!r)break;Q.venueId&&!x[Q.venueid]&&(x[Q.venueId]=(v=Eu({venueId:Q.venueId,tournamentRecord:r}))==null?void 0:v.venueData);const J=x[Q.venueId];Q.venueName=J==null?void 0:J.venueName;const te=(f=J==null?void 0:J.courtsInfo)==null?void 0:f.find(ne=>ne.courtId===Q.courtId);Q.courtName=te==null?void 0:te.courtName}I=Oe({typeChangeTimeAfterRecovery:q,timeAfterRecovery:R,scheduledDate:A,scheduledTime:E,isoDateString:L,allocatedCourts:N,timeModifiers:D,venueAbbreviation:H,venueName:z,venueId:U,courtOrder:M,courtName:K,courtId:C,typeChangeRecoveryMinutes:W,recoveryMinutes:G,averageMinutes:j,milliseconds:m,startTime:g,endTime:_,time:h})}else I=Oe({time:h,startTime:g,endTime:_,milliseconds:m});const O=s.matchUpStatus&&Yt.includes(s.matchUpStatus),{scheduledDate:b}=Ui({matchUp:s}),{scheduledTime:w}=Zf({matchUp:s}),T=O&&(Re(_)||Re(b)||Re(w))||void 0;return{schedule:I,endDate:T}}var nG=Object.defineProperty,WP=Object.getOwnPropertySymbols,oG=Object.prototype.hasOwnProperty,iG=Object.prototype.propertyIsEnumerable,HP=(t,e,r)=>e in t?nG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sG=(t,e)=>{for(var r in e||(e={}))oG.call(e,r)&&HP(t,r,e[r]);if(WP)for(var r of WP(e))iG.call(e,r)&&HP(t,r,e[r]);return t};function Uu({collectionPosition:t,collectionId:e,lineUp:r}){let n=[];const o=[];if(r){const i=a=>a===void 0?-1:a,s=r.map(a=>{const{collectionAssignments:l,participantId:c}=a,u=l==null?void 0:l.find(p=>p.collectionPosition===t&&p.collectionId===e);return u&&sG({participantId:c},u)}).filter(Boolean).sort((a,l)=>i(a.substitutionOrder)-i(l.substitutionOrder));for(const a of s){const{participantId:l,previousParticipantId:c,substitutionOrder:u}=a;n.includes(l)||(c&&o.push({previousParticipantId:c,substitutionOrder:u,participantId:l}),n=n.filter(p=>p!==c),n.push(l))}}return{assignedParticipantIds:n,substitutions:o}}const xl="SIGN_IN_STATUS",Fe=Ln.Individual,Mr=Ln.Group,Ce=Ln.Pair,tt=Ln.Team,zn=Ln.Team,Ll="SIGNED_IN",aG="SIGNED_OUT",Vl={TEAM_PARTICIPANT:zn,INDIVIDUAL:Fe,GROUP:Mr,TEAM:tt,PAIR:Ce};var lG=Object.defineProperty,qP=Object.getOwnPropertySymbols,cG=Object.prototype.hasOwnProperty,uG=Object.prototype.propertyIsEnumerable,zP=(t,e,r)=>e in t?lG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dG=(t,e)=>{for(var r in e||(e={}))cG.call(e,r)&&zP(t,r,e[r]);if(qP)for(var r of qP(e))uG.call(e,r)&&zP(t,r,e[r]);return t};function Yn({tournamentParticipants:t,tournamentRecord:e,participantIds:r}){const n="getPairedParticipant";if(!t&&!e)return{error:re};if(!Array.isArray(r)||r.length>2)return{error:pn};if(!r.length)return k({result:{error:Oo},stack:n});t=t||(e==null?void 0:e.participants)||[];const o=t.filter(a=>a.participantType===Ce&&Ht(r,a.individualParticipantIds).length===r.length&&a.individualParticipantIds.length===r.length),i=o[0];if(!i)return k({result:{error:jt},stack:n});const s=de(o.slice(1),!1,!0);return dG({participant:de(i),duplicatedPairParticipants:s},V)}function Bl({drawDefinition:t,participantId:e}){if(typeof t!="object")return{error:ue};if(typeof e!="string")return{error:Et};const{extension:r}=Kt({element:t,name:kn});return{lineUp:((r==null?void 0:r.value)||{})[e]}}function pG({tournamentParticipants:t,positionAssignments:e,collectionPosition:r,drawPositions:n=[],participantMap:o,drawDefinition:i,collectionId:s,sideLineUps:a,matchUpType:l}){if(!s||!r)return;const c=(n==null?void 0:n.map(u=>{var p,d,v,f,m,h;const g=(p=e.find(O=>O.drawPosition===u))==null?void 0:p.participantId,_=a==null?void 0:a.find(O=>(O==null?void 0:O.drawPosition)===u),I=(_==null?void 0:_.teamParticipant)||g&&((d=o==null?void 0:o[g])==null?void 0:d.participant)||(t==null?void 0:t.find(({participantId:O})=>O===g)),P=(_==null?void 0:_.lineUp)||((v=Bl({participantId:g,drawDefinition:i}))==null?void 0:v.lineUp),{assignedParticipantIds:y,substitutions:S}=Uu({collectionPosition:r,collectionId:s,lineUp:P});if(l===dt){if((y==null?void 0:y.length)<=2){const O=(m=(f=o==null?void 0:o[y[0]])==null?void 0:f.pairIdMap)==null?void 0:m[y[1]],w=O&&((h=o[O])==null?void 0:h.participant)||Yn({participantIds:y,tournamentParticipants:t}).participant,T=w==null?void 0:w.participantId;return{[u]:{participantId:T,teamParticipant:I,substitutions:S}}}else if((y==null?void 0:y.length)>2)return{[u]:{teamParticipant:I,substitutions:S}}}else{const O=y==null?void 0:y[0];return O&&{[u]:{participantId:O,teamParticipant:I,substitutions:S}}}}).filter(Boolean))||{};return Object.assign({},...c)}function Tr({matchUps:t=[],interpolate:e}){var r;if(!Array.isArray(t))return{roundMatchUps:[],error:X};const n=t.reduce((d,v)=>{const f=typeof v.roundNumber=="string"?Te(v.roundNumber):v.roundNumber;return!v.roundNumber||d.includes(f)?d:d.concat(f)},[]).sort(er).map(d=>{const v=t.filter(g=>g.roundNumber===d),m=v.find(({matchUpType:g})=>g===Qe)?v.filter(({matchUpType:g})=>g===Qe):v,h=g=>g.sort((_,I)=>er(_.roundPosition,I.roundPosition));return{[d]:h(m)}}),o=t.reduce((d,v)=>{const f=typeof v.roundNumber=="string"?Te(v.roundNumber):v.roundNumber;return d[f]||(d[f]=Oe({abbreviatedRoundName:v.abbreviatedRoundName,finishingRound:v.finishingRound,roundName:v.roundName})),d},{}),i=Object.assign({},...n);if(e){const d=Math.max(...Object.keys(i).map(f=>Te(f)).filter(f=>!isNaN(f))),v=(r=i[d])==null?void 0:r.length;if(v>1&&Zr(v)){const f=d+1,m=f+v/2;ce(f,m).forEach((g,_)=>{i[g]=ce(0,v/(2+_*2)).map(()=>({}))})}}let s=0;const a=Object.assign({},...Object.keys(i).map(d=>{var v,f,m;const h=(v=i[d])==null?void 0:v.length,g=(m=(f=i[d])==null?void 0:f.filter(I=>{var P;return!Yt.includes(I.matchUpStatus)&&!((P=I.score)!=null&&P.scoreStringSide1)}))==null?void 0:m.length,_=h&&h===g;return s=Math.max(s,h),{[d]:{matchUpsCount:h,inactiveCount:g,inactiveRound:_}}}));let l=0,c=0;const u=Object.keys(i).map(d=>Te(d)).filter(d=>!isNaN(d));return u.forEach(d=>{var v,f,m;const h=i[d].sort((_,I)=>_.roundPosition-I.roundPosition),g=h.map(_=>(_==null?void 0:_.drawPositions)||[]).flat();if(a[d].roundNumber=d,a[d].roundFactor=a[d].matchUpsCount?s/a[d].matchUpsCount:1,a[d].finishingRound=(v=o[d])==null?void 0:v.finishingRound,a[d].roundName=(f=o[d])==null?void 0:f.roundName,a[d].abbreviatedRoundName=(m=o[d])==null?void 0:m.abbreviatedRoundName,a[d].finishingPositionRange=i[d][0].finishingPositionRange,d===1||!a[d-1]){const _=g.sort(er),I=qt(_,2);a[d].drawPositions=_,a[d].pairedDrawPositions=I}else{const _=a[d-1],I=_.drawPositions,P=_.matchUpsCount/a[d].matchUpsCount,y=qt(I,P),S=h.map(O=>{const{roundPosition:b}=O,w=[...O.drawPositions||[],void 0,void 0].slice(0,2);if(!b)return w;const T=(w==null?void 0:w.filter(Boolean))||[];if(!(T!=null&&T.length))return[void 0,void 0];if(d<3&&(T==null?void 0:T.length)===2)return w==null?void 0:w.slice().sort(er);const $=Ht(I,T).length!==(T==null?void 0:T.length);if(T!=null&&T.length&&$)return(T==null?void 0:T.length)===1?[T[0],void 0]:w==null?void 0:w.slice().sort(er);const N=(b-1)*2;return y.slice(N,N+2).map(A=>T==null?void 0:T.find(U=>A.includes(U)))});a[d].drawPositions=S==null?void 0:S.flat(),a[d].pairedDrawPositions=S}a[d+1]&&a[d+1].matchUpsCount===a[d].matchUpsCount&&(a[d+1].feedRound=!0,a[d+1].feedRoundIndex=c,a[d].preFeedRound=!0,c+=1),a[d]&&!a[d].feedRound&&(a[d].roundIndex=l,l+=1)}),{hasOddMatchUpsCount:!!Object.values(a).find(({matchUpsCount:d})=>!Zr(d)),maxMatchUpsCount:s,roundMatchUps:i,roundNumbers:u,roundProfile:a}}function YP(t){var e;const r=t==null?void 0:t.matchUp;let n=r==null?void 0:r.matchUpType;if(!n&&((e=r.sides)!=null&&e.length)){const o=r.sides.find(({participant:a})=>a),i=o==null?void 0:o.participant,s=i==null?void 0:i.participantType;n=s===Fe&&At||s===Ce&&dt||s===tt&&tt||void 0}return{matchUpType:n}}function kl({drawDefinition:t,attributes:e}){let{extension:r}=Pu({name:_u,drawDefinition:t});const n=(r==null?void 0:r.value)||{};return e.forEach(o=>{Object.keys(o).forEach(i=>{n[i]?Object.assign(n[i],o[i]):n[i]=o[i]})}),r={name:_u,value:n},kf({drawDefinition:t,extension:r}),{entryProfile:n}}function Gl({drawDefinition:t}){const{extension:e}=Pu({name:_u,drawDefinition:t});return{entryProfile:(e==null?void 0:e.value)||{}}}const he="MAIN",we="QUALIFYING",xt="CONSOLATION",kt="VOLUNTARY_CONSOLATION",ft="PLAY_OFF",tv=[he,we,xt,ft,kt],_s={[we]:1,[he]:2,[ft]:3,[xt]:3,[kt]:4},KP="finishingPositions",QP="aggregateEventStructures",JP={[he]:1,[ft]:2,[xt]:3,[we]:4,[kt]:5},fG={[ft]:1,[he]:2,[xt]:3,[we]:4,[kt]:5},rv="CLUSTER",vG="SEPARATE",nv="WATERFALL",Au="ITEM",gr="CONTAINER",Sn="DRAW",ZP="RANDOM",Ai="TOP_DOWN",Is="BOTTOM_UP",Ci="POSITION",Mi="WINNER",Ps="LOSER",co="FIRST_MATCHUP",On="AD_HOC",ga="FEED_IN",_a="COMPASS",Ia="OLYMPIC",mG="SINGLE_ELIMINATION",Uo="SINGLE_ELIMINATION",Wl="DOUBLE_ELIMINATION",Pa="FIRST_MATCH_LOSER_CONSOLATION",Hl="FIRST_ROUND_LOSER_CONSOLATION",Di="LUCKY_DRAW",Cu="CURTIS_CONSOLATION",hG="CURTIS_CONSOLATION",ov="FEED_IN_CHAMPIONSHIP_TO_SF",ql="FEED_IN_CHAMPIONSHIP_TO_SF",iv="FEED_IN_CHAMPIONSHIP_TO_QF",zl="FEED_IN_CHAMPIONSHIP_TO_QF",sv="FEED_IN_CHAMPIONSHIP_TO_R16",Yl="FEED_IN_CHAMPIONSHIP_TO_R16",XP="MODIFIED_FEED_IN_CHAMPIONSHIP",Kl="MODIFIED_FEED_IN_CHAMPIONSHIP",Ql="FEED_IN_CHAMPIONSHIP",bn="ROUND_ROBIN",Ao="ROUND_ROBIN_WITH_PLAYOFF",ey="DECIDER",ty="BACKDRAW",av={0:{name:"EAST",abbreviation:"E"},"0-1":{name:"WEST",abbreviation:"W"},"0-2":{name:"NORTH",abbreviation:"N"},"0-3":{name:"NORTHEAST",abbreviation:"NE"},"0-1-1":{name:"SOUTH",abbreviation:"S"},"0-1-2":{name:"SOUTHWEST",abbreviation:"SW"},"0-2-1":{name:"NORTHWEST",abbreviation:"NW"},"0-1-1-1":{name:"SOUTHEAST",abbreviation:"SE"}},lv={0:{name:"EAST",abbreviation:"E"},"0-1":{name:"WEST",abbreviation:"W"},"0-2":{name:"NORTH",abbreviation:"N"},"0-1-1":{name:"SOUTH",abbreviation:"S"}},ya="WIN_RATIO",ji="ROUND_OUTCOME",ry=[_a,Cu,zl,Yl,ql,Ql,iv,sv,ov,Pa,Hl,Di,Kl,Ia,ft,Ao],gG={MAIN:he,QUALIFYING:we,CONSOLATION:xt,ITEM:Au,CONTAINER:gr,FIRST_MATCHUP:co,WINNER:Mi,LOSER:Ps,AD_HOC:On,FEED_IN:ga,COMPASS:_a,PLAY_OFF:ft,OLYMPIC:Ia,KNOCKOUT:mG,SINGLE_ELIMINATION:Uo,DOUBLE_ELIMINATION:Wl,CURTIS:Cu,FICSF:ov,FICQF:iv,FICR16:sv,MFIC:XP,VOLUNTARY_CONSOLATION:kt,FIRST_MATCH_LOSER_CONSOLATION:Pa,FIRST_ROUND_LOSER_CONSOLATION:Hl,MODIFIED_FEED_IN_CHAMPIONSHIP:Kl,FEED_IN_CHAMPIONSHIP_TO_R16:Yl,FEED_IN_CHAMPIONSHIP_TO_QF:zl,FEED_IN_CHAMPIONSHIP_TO_SF:ql,FEED_IN_CHAMPIONSHIP:Ql,LUCKY_DRAW:Di,ROUND_ROBIN_WITH_PLAYOFF:Ao,ROUND_ROBIN:bn,DECIDER:ey,BACKDRAW:ty,COMPASS_ATTRIBUTES:av,OLYMPIC_ATTRIBUTES:lv,DRAW:Sn,RANDOM:ZP,TOP_DOWN:Ai,BOTTOM_UP:Is,WATERFALL:nv,WIN_RATIO:ya,ROUND_OUTCOME:ji,MULTI_STRUCTURE_DRAWS:ry,generatedDrawTypes:[On,_a,Cu,Wl,zl,Yl,ql,Ql,ga,Pa,Hl,Di,Kl,Ia,ft,bn,Ao,Uo],stageOrder:_s,finishOrder:JP,AGGREGATE_EVENT_STRUCTURES:QP,FINISHING_POSITIONS:KP};function Ri(t,e,r){var n,o;const i=v=>{var f,m;return(m=(f=Kt({element:v,name:Gn}))==null?void 0:f.extension)==null?void 0:m.value},s=r==null?void 0:r.deprioritizeCompleted,a=(r==null?void 0:r.mode)===QP&&fG,l=(r==null?void 0:r.mode)===KP&&JP,c=l||a||_s,u=v=>(v==null?void 0:v.stage)===he&&(v==null?void 0:v.stageSequence)===1,p=v=>u(v)?-1:c[v==null?void 0:v.stage],d=v=>v==null?void 0:v.matchUps.every(({matchUpStatus:f})=>Yt.includes(f)?1:-1);return s&&d(t)-d(e)||a&&p(t)-p(e)||((t==null?void 0:t.stage)&&c[t.stage]||0)-((e==null?void 0:e.stage)&&c[e.stage]||0)||(i(t)||0)-(i(e)||0)||!l&&!a&&(((n=e==null?void 0:e.positionAssignments)==null?void 0:n.length)||1/0)-(((o=t==null?void 0:t.positionAssignments)==null?void 0:o.length)||1/0)||((t==null?void 0:t.stageSequence)||0)-((e==null?void 0:e.stageSequence)||0)||(ny(t)||0)-(ny(e)||0)}function ny(t){return((t==null?void 0:t.matchUps)||[]).reduce((e,r)=>{var n;const o=(((n=r.finishingPositionRange)==null?void 0:n.winner)||[]).reduce((i,s)=>i+s,0);return!e||o<e?o:e},void 0)}function Ne({drawDefinition:t,structureId:e}){if(!t)return{error:ue};if(!e)return{error:yr};const{structures:r}=an({drawDefinition:t}),n=r==null?void 0:r.map(s=>s.structures?[...s.structures].concat(s):s).flat(),o=n==null?void 0:n.find(s=>s.structureId===e);if(!o)return{error:bt};const i=o.structureType===Au?n==null?void 0:n.find(s=>{var a;return(a=s.structures)==null?void 0:a.some(l=>l.structureId===e)}):void 0;return{structure:o,containingStructure:i}}function an({withStageGrouping:t,drawDefinition:e,stageSequences:r,stageSequence:n,roundTarget:o,sortConfig:i,stages:s,stage:a}){var l,c;const u=!e&&ue||!(e!=null&&e.structures)&&ax||void 0;if(u)return{error:u,structures:[],stageStructures:{}};const p=h=>{var g,_;const I=(_=(g=Kt({element:h,name:Gn}))==null?void 0:g.extension)==null?void 0:_.value;return!o||o===I},d=(c=(l=e==null?void 0:e.structures)==null?void 0:l.filter(f).filter(m).filter(p).sort((h,g)=>Ri(h,g,i)))!=null?c:[],v=t?Object.assign({},...tv.map(h=>{const g=d==null?void 0:d.filter(_=>_.stage===h);return(g==null?void 0:g.length)&&{[h]:g}}).filter(Boolean)):{};return{structures:d,stageStructures:v};function f(h){return!a&&!Array.isArray(s)||a&&h.stage===a||Array.isArray(s)&&s.includes(h.stage)}function m(h){return!n&&!Array.isArray(r)||n&&h.stageSequence===n||Array.isArray(r)&&r.includes(h.stageSequence)}}const Tn=ar.Alternate,Mu=ar.Confirmed,wn=ar.DirectAcceptance,Jl=ar.FeedIn,Du=ar.JuniorExempt,Zl=ar.LuckyLoser,ju=ar.OrganiserAcceptance,Ru=ar.Qualifier,_G=ar.Registered,Fu=ar.SpecialExempt,En=ar.Ungrouped,ys=ar.Unpaired,Sa=ar.Wildcard,ni=ar.Withdrawn,cv=[Mu,wn,Du,ju,Fu],IG=[Jl,Zl,Ru],Ss=[Mu,wn,Jl,Du,ju,Fu,Sa],Fi=[Mu,wn,Jl,Du,Zl,Ru,ju,Fu,Sa],PG=[Tn,Mu,wn,Jl,Du,Zl,ju,Ru,_G,Fu,En,ys,Sa,ni],oy=Fi;function Xl({stage:t,drawDefinition:e}){const{entryProfile:r}=Gl({drawDefinition:e}),n=Object.keys(r).includes(t);if(!n&&tv.includes(t)){const o=[{[t]:{drawSize:void 0,alternates:!0}}];return kl({drawDefinition:e,attributes:o}),!0}return n}function yG({stage:t,drawDefinition:e}){var r;const{entryProfile:n}=Gl({drawDefinition:e});return((r=n[t])==null?void 0:r.alternates)||0}function SG({stage:t,drawDefinition:e}){var r;const{entryProfile:n}=Gl({drawDefinition:e});return((r=n[t])==null?void 0:r.wildcardsCount)||0}function xu({stage:t,drawDefinition:e,entryStatus:r}){return e.entries.reduce((n,o)=>o.entryStage===t&&o.entryStatus===r?n+1:n,0)}function Os({provisionalPositioning:t,drawDefinition:e,stageSequence:r,entryStatuses:n,structureId:o,roundTarget:i,stages:s,stage:a}){var l,c;const u=(c=(l=e.entries)==null?void 0:l.reduce((p,d)=>{var v,f,m;const h=(f=(v=Kt({name:Gn,element:d}))==null?void 0:v.extension)==null?void 0:f.value,g=a&&d.entryStage===a||(s==null?void 0:s.length)&&d.entryStage&&s.includes(d.entryStage),_=!n||d.entryStatus&&n.includes(d.entryStatus),I=(m=d.entryStageSequence)!=null?m:1;return g&&(!r||I===r)&&_&&(!i||!h||i===h)?p.concat(d):p},[]))!=null?c:[];if(o&&a===ft){const{playoffEntries:p,error:d}=OG({provisionalPositioning:t,drawDefinition:e,structureId:o});return d&&console.log("playoff entries error"),p!=null&&p.length?p:u}return u}function OG({provisionalPositioning:t,drawDefinition:e,structureId:r}){var n;const o=[],i=((n=e.links)!=null?n:[]).find(s=>s.linkType===Ci&&s.target.structureId===r);if(i){const{finishingPositions:s,structureId:a}=i.source,{structure:l}=Ne({drawDefinition:e,structureId:a});(l==null?void 0:l.structureType)===gr&&(l.structures||[]).forEach(u=>{const p=u.positionAssignments||[],{structureId:d}=u,v=d,f=Object.assign({},...p.map(_=>{var I;const{participantId:P}=_,y=(I=Kt({element:_,name:Ko}).extension)==null?void 0:I.value;return y&&P?{[P]:y}:void 0}).filter(Boolean)),h=Object.keys(f).reduce((_,I)=>{const P=f[I],y=P.groupOrder||t&&P.provisionalOrder;return _.includes(y)||_.push(y),_},[]).length===Object.keys(f).length,g=Object.keys(f).filter(_=>{const I=f[_],P=I.groupOrder||t&&I.provisionalOrder;return s==null?void 0:s.includes(P)});(!t||h)&&g.forEach(_=>{const I=f[_],{groupOrder:P,provisionalOrder:y,GEMscore:S}=I,O=P||t&&y,b=(s??[]).sort().indexOf(O)+1;o.push({entryStage:ft,entryStatus:Jl,placementGroup:b,groupingValue:v,participantId:_,GEMscore:S})})})}return{playoffEntries:o}}function iy({stage:t,drawDefinition:e}){return Ss.reduce((r,n)=>(xu({drawDefinition:e,entryStatus:n,stage:t})||0)+r,0)}function bG({stage:t,drawDefinition:e}){return xu({entryStatus:Sa,drawDefinition:e,stage:t})}function $n({provisionalPositioning:t,drawDefinition:e,structureId:r,structure:n}){var o;let i,s=[];if(n||({structure:n,error:i}=Ne({drawDefinition:e,structureId:r})),i||!n)return{seedAssignments:[],error:bt};r||(r=n.structureId);const{stage:a,stageSequence:l}=n,u=a===ft&&e&&Os({provisionalPositioning:t,drawDefinition:e,stageSequence:l,structureId:r,stage:a}),p=u?u.filter(v=>v.placementGroup===1).sort((v,f)=>v.GEMscore<f.GEMscore&&1||v.GEMscore>f.GEMscore&&-1||0).map((v,f)=>{const m=f+1;return{participantId:v.participantId,seedValue:m,seedNumber:m,seedProxy:!0}}):[];p.length?s=p:n.seedAssignments?s=n.seedAssignments:i=nx;const d=n.seedLimit||((o=n==null?void 0:n.positionAssignments)==null?void 0:o.length);return{seedAssignments:s,seedLimit:d,stage:a,stageSequence:l,error:i}}function uv({drawDefinition:t}){if(typeof t!="object")return{error:Xi};const e={},{structures:r=[],links:n=[]}=t||{},o=r.reduce((s,a)=>{const{stage:l}=a;return s[l]?s[l].push(a):s[l]=[a],s},{});for(const s of Object.keys(o)){const a=o[s].find(({stageSequence:u})=>u===1);if(!a)continue;const{structureId:l}=a;i({aggregator:{},targetRound:0,exitProfiles:e,exitProfile:"0",structureId:l,stage:s})}return{exitProfiles:e};function i({exitProfiles:s,exitProfile:a,structureId:l,targetRound:c,aggregator:u,stage:p}){s[l]||(s[l]=[]),a==="0"&&[xt,ft].includes(p)||s[l].push(a);const d=n.filter(v=>v.source.structureId===l&&v.source.roundNumber>=c);for(const v of d){const f=v.source.roundNumber,m=v.target.roundNumber,h=v.target.structureId,g=r.find(I=>I.structureId===h).stage,_=[g,h,m,f].join("|");if(u[_])return;u[_]=!0,i({exitProfile:`${a}-${f}`,structureId:h,exitProfiles:s,targetRound:m,aggregator:u,stage:g})}}}function lr({drawDefinition:t,structure:e}){var r;const n={},o=[];return((r=t==null?void 0:t.structures)!=null?r:[e]).filter(i=>i&&typeof i=="object").forEach(i=>{if(!i)return;const{structureId:s,matchUps:a,structures:l}=i,c=Array.isArray(l);if(c)c&&l.forEach(u=>{const{structureName:p}=u,d=u.matchUps;n[u.structureId]={matchUps:d,itemStructureIds:[],structureName:p},d&&(o.push(...d),d.forEach(v=>{v.tieMatchUps&&o.push(...v.tieMatchUps)})),n[s]||(n[s]={itemStructureIds:[],matchUps:[]}),n[s].itemStructureIds||(n[s].itemStructureIds=[]),n[s].itemStructureIds.push(u.structureId)});else{const u=a;n[s]={matchUps:u,itemStructureIds:[]},u==null||u.forEach(p=>{o.push(p),p.tieMatchUps&&o.push(...p.tieMatchUps)})}}),{mappedMatchUps:n,drawMatchUps:o}}function xi({mappedMatchUps:t,matchUpsMap:e,structureId:r,inContext:n}){var o;t=(o=e==null?void 0:e.mappedMatchUps)!=null?o:t;const i=t[r],s=((i==null?void 0:i.itemStructureIds)||[]).map(a=>{const{matchUps:l,structureName:c}=t[a];return n?l.map(u=>Object.assign(de(u,!0,!0),{containerStructureId:r,structureId:a,structureName:c})):l}).flat();return((i==null?void 0:i.matchUps)||[]).concat(...s)}function sy({groupedOrder:t,roundPositionsCount:e}){if(!t||(t==null?void 0:t.length)<=e)return t;const n=qt(t,t.length/e).map(i=>i.reduce((s,a)=>s+a)),o=n.slice().sort(er);return n.map(i=>o.indexOf(i)+1)}function Lu(t){if(!Array.isArray(t))return"";const e=t.filter(Ct);return e.length?We([Math.min(...e),Math.max(...e)]).join("-"):""}function TG({drawDefinition:t,structureId:e,matchUpsMap:r}){if(!t)return{error:ue};if(!e)return{error:yr};const{structure:n}=Ne({drawDefinition:t,structureId:e});if((n==null?void 0:n.stage)!==xt)return{error:Bo,info:"Structure is not CONSOLATION stage"};const{links:o}=t,i=(o==null?void 0:o.filter(p=>p.target.structureId===e))||[],s=(i==null?void 0:i.reduce((p,d)=>{const{structureId:v}=d.source;return p.includes(v)?p:p.concat(v)},[]))||[],a=Object.assign({},...s.map(p=>{const d=xi({structureId:p,matchUpsMap:r}),{roundProfile:v}=Tr({matchUps:d});return{[p]:v}})),l=xi({matchUpsMap:r,structureId:e}),{roundProfile:c}=Tr({matchUps:l}),u={};return i==null||i.forEach(p=>{var d;const{structureId:v,roundNumber:f}=p.source,{feedProfile:m,groupedOrder:h,positionInterleave:g,roundNumber:_}=p.target,I=a[v],P=(d=I[1])==null?void 0:d.drawPositions,y=I[f],S=y==null?void 0:y.matchUpsCount;if(!S)return;const O=S?P.length/S:0,b=P.length/O;let w=P.slice();const T=sy({roundPositionsCount:w.length,groupedOrder:h}),$=(T==null?void 0:T.length)||1;if($<=b){const U=P.length/$,C=qt(w,U);m===Is&&C.forEach(M=>M.reverse()),w=(T==null?void 0:T.length)&&(T==null?void 0:T.map(M=>C[M-1]).flat())||w}let N=qt(w,O);if(!(T!=null&&T.length)&&m===Is&&N.reverse(),g){const U=ce(0,g.interleave).map(()=>{}),C=ce(0,g.offset).map(()=>{});N=N.map(D=>[D,...U]),N.unshift(C),N=N.flat(1);const M=N.length-g.offset;N=N.slice(0,M)}u[_]||(u[_]={});const E=c==null?void 0:c[_],A=E!=null&&E.feedRound?2:1;N.forEach((U,C)=>{const M=1+C*A;u[_][M]||(u[_][M]=Lu(U))})}),{sourceDrawPositionRanges:u}}function ay({drawDefinition:t}){if(!t)return{error:ue};const e={};return{allPositionedParticipantIds:(t.structures||[]).map(n=>{var o;const i=n.stage;e[i]||(e[i]=[]);const{positionAssignments:s}=st({structure:n}),a=(o=s==null?void 0:s.map(Fn("participantId")).filter(Boolean))!=null?o:[];return e[i].push(...a),a}).flat(),stagePositionedParticipantIds:e}}function st({drawDefinition:t,structureId:e,structure:r}){let n,o=[];if(!r){if(!t)return{positionAssignments:o,error:ue};if({structure:r,error:n}=Ne({drawDefinition:t,structureId:e}),n)return{positionAssignments:o,error:n}}return r.structures?o=[].concat(...r.structures.map(i=>st({structure:i}).positionAssignments)):r.positionAssignments?o=r.positionAssignments:n=px,{positionAssignments:o,error:n}}function Dt({drawDefinition:t,structureId:e,structure:r}){var n;const o=((n=st({drawDefinition:t,structureId:e,structure:r}))==null?void 0:n.positionAssignments)||[],i=o==null?void 0:o.filter(u=>{var p,d;return(d=(p=u.participantId)!=null?p:u.bye)!=null?d:u.qualifier}),s=o&&(o==null?void 0:o.length)===(i==null?void 0:i.length),a=o==null?void 0:o.filter(u=>!u.participantId&&!u.bye&&!u.qualifier),l=o==null?void 0:o.filter(u=>!u.participantId&&u.bye),c=o==null?void 0:o.filter(u=>!u.participantId&&u.qualifier);return{allPositionsAssigned:s,positionAssignments:o,unassignedPositions:a,assignedPositions:i,qualifierPositions:c,byePositions:l}}function wG({drawPositions:t,roundProfile:e,roundNumber:r}){const n=[void 0,void 0];if(zF(t))return{orderedDrawPositions:n,displayOrder:n};const o=e[r],i=o==null?void 0:o.pairedDrawPositions,s=(i==null?void 0:i.find(l=>Xt(l||[],t.filter(Boolean))))||n,a=o==null?void 0:o.feedRound;if(qF(t)){const l=t.sort(er);return{orderedDrawPositions:l.length===2?l:s,displayOrder:a?l:s}}if(a){const c=[t.find(u=>!isNaN(Te(u))),void 0];return{orderedDrawPositions:c,displayOrder:c}}return{orderedDrawPositions:s,displayOrder:s}}function EG({drawDefinition:t,roundProfile:e,structureId:r,matchUpsMap:n}){var o;if(!t)return{error:ue};if(!r)return{error:yr};if(!e){const c=xi({matchUpsMap:n,structureId:r});if({roundProfile:e}=Tr({matchUps:c}),!e)return{error:_e}}const s=(Math.min(...((o=e==null?void 0:e[1])==null?void 0:o.drawPositions)||[])||1)-1,a=Object.keys(e);return{drawPositionsRanges:Object.assign({},...(a||[]).map(c=>{var u,p;const d=(u=e==null?void 0:e[c])==null?void 0:u.matchUpsCount,v=((p=e==null?void 0:e[1])==null?void 0:p.drawPositions)||[],f=qt(v,v.length/d),m=f.map(Lu),h=f.map(y=>y.map(S=>S-s)).map(Lu),g=a.map(y=>{var S,O;if(y>c)return;const b=(O=(S=e==null?void 0:e[y])==null?void 0:S.drawPositions)!=null?O:[];return qt(b,b.length/d)}).filter(Boolean),_=ce(0,d).map(y=>g.map(S=>S[y]).flat().filter(Boolean).sort(er)).map(y=>We(y)),I=_.map(y=>HF(y).map(Lu).join(", ")),P=Object.assign({},...ce(0,d).map(y=>({[y+1]:{firstRoundDrawPositionsRange:m[y],firstRoundOffsetDrawPositionsRange:h[y],possibleDrawPositions:_[y],drawPositionsRange:I[y]}})));return{[c]:P}}))}}function dv({matchUp:t}){let e=[],r=[],n=[],o=[],i;if(t||(i=jr),t&&!t.sides&&(i=tn),t&&!t.hasContext&&(i=ru),!i){o=t.sides.map(l=>l.participantId);const s=t.sides.filter(l=>l.participantType===Fe).map(l=>l.participantId).filter(Boolean);e=t.sides.map(l=>{var c;return(c=l.participant)==null?void 0:c.individualParticipants}).filter(Boolean).map(l=>l.map(c=>c==null?void 0:c.participantId).filter(Boolean)),n=[...s,...e.flat()].filter(Boolean),r=We(n.concat(o)).filter(Boolean)}return{nestedIndividualParticipantIds:e,allRelevantParticipantIds:r,individualParticipantIds:n,sideParticipantIds:o,error:i}}function ec({matchUp:t}){if(!t)return{error:jr};if(!t.hasContext)return{error:ru};if(!t.sides||t.sides.filter(Boolean).length!==2)return{error:tn};const{nestedIndividualParticipantIds:e,allRelevantParticipantIds:r,sideParticipantIds:n}=dv({matchUp:t}),i=(t.timeItems||[]).filter(c=>[Qf,Jf].includes(c==null?void 0:c.itemType)).sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime()),a=i.map(c=>c.itemValue).filter(c=>i.filter(u=>(u==null?void 0:u.itemValue)===c).reverse()[0].itemType===Qf);return e==null||e.forEach((c,u)=>{const p=n[u],d=(c==null?void 0:c.length)&&c.every(v=>a.includes(v));p&&d&&!a.includes(p)&&a.push(p)}),n.forEach((c,u)=>{a.includes(c)&&((e==null?void 0:e[u])||[]).forEach(p=>{p&&!a.includes(p)&&a.push(p)})}),{allParticipantsCheckedIn:n.reduce((c,u)=>a.includes(u)&&c,!0),checkedInParticipantIds:a,allRelevantParticipantIds:r}}function bs(t){const{matchUps:e,isCollectionMatchUp:r,excludeMatchUpStatuses:n,matchUpStatuses:o,hasWinningSide:i,matchUpFormats:s,roundPositions:a,matchUpFormat:l,collectionIds:c,isMatchUpTie:u,roundNumbers:p,matchUpIds:d,roundNames:v,stageSequences:f,scheduledDates:m,scheduledDate:h,participantIds:g,processContext:_,tournamentIds:I,matchUpTypes:P,structureIds:y,readyToScore:S,courtIds:O,eventIds:b,venueIds:w,drawIds:T,stages:$,filterMatchUpIds:N=!0,filterMatchUpTypes:E=!0}=t,A=Array.isArray(g)?g.filter(Boolean):[],U=Array.isArray(o)?o.filter(Boolean):[],C=Array.isArray(n)?n.filter(Boolean):[],M=Array.isArray($)?$.filter(Boolean):[],D=Array.isArray(f)?f.filter(Boolean):[],R=Array.isArray(c)?c.filter(Boolean):[],j=Array.isArray(v)?v.filter(Boolean):[],G=Array.isArray(p)?p.filter(Boolean):[],W=Array.isArray(a)?a.filter(Boolean):[],q=Array.isArray(d)&&N?d.filter(Boolean):[],F=Array.isArray(P)&&E?P.filter(Boolean):[],L=Array.isArray(O)?O.filter(Boolean):[],x=Array.isArray(w)?w.filter(Boolean):[],B=Array.isArray(s)&&s.filter(Boolean)||typeof l=="string"&&[l]||[],z=Array.isArray(m)&&m.filter(Boolean)||typeof h=="string"&&h.length&&[h]||[],H=Array.isArray(I)?I.filter(Boolean):[],Y=Array.isArray(b)?b.filter(Boolean):[],Z=Array.isArray(T)?T.filter(Boolean):[],K=Array.isArray(y)?y.filter(Boolean):[];return e.filter(Q=>{var J,te;if(S&&Q.matchUpType!==hn&&!Q.readyToScore||Q.winningSide&&i&&![1,2].includes(Q.winningSide)||u!==void 0&&(u&&!Q.tieMatchUps||!u&&Q.tieMatchUps)||r!==void 0&&(r&&!Q.collectionId||!r&&Q.collectionId)||M.length&&!M.includes(Q.stage)||D.length&&!D.includes(Q.stageSequence)||R.length&&(!Q.collectionId||!R.includes(Q.collectionId))||j.length&&(!Q.roundName||!j.includes(Q.roundName))||G.length&&(!Q.roundNumber||!G.includes(Q.roundNumber))||W.length&&(!Q.roundPosition||!W.includes(Q.roundPosition))||U.length&&(!Q.matchUpStatus||!U.includes(Q.matchUpStatus))||C.length&&Q.matchUpStatus&&C.includes(Q.matchUpStatus)||q.length&&!q.includes(Q.matchUpId)||F.length&&(!Q.matchUpType||!F.includes(Q.matchUpType))||B.length&&(!Q.matchUpFormat||!B.includes(Q.matchUpFormat)))return!1;if(z!=null&&z.length){const{scheduledTime:ne}=Zf({matchUp:Q}),{scheduledDate:ee}=Ui({matchUp:Q}),ie=Re(ne)||ee;if(!z.find(ae=>io(ae,ie)))return!1}if(L.length){const{courtId:ne}=xP({matchUp:Q}),{allocatedCourts:ee}=FP({matchUp:Q}),oe=ee==null?void 0:ee.map(({courtId:ie})=>ie);if(!L.filter(Boolean).includes(ne)||oe!=null&&oe.includes(ne))return!1}if(x.length){const{venueId:ne}=LP({matchUp:Q});if(!x.filter(Boolean).includes(ne))return!1}if(_){if(H.length&&!H.includes(Q.tournamentId)||Y.length&&!Y.includes(Q.eventId)||Z.length&&!Z.includes(Q.drawId)||K.length&&!K.includes(Q.structureId))return!1;if(A.length){const ne=(te=(J=Q.sides)==null?void 0:J.map(({participantId:oe})=>oe).filter(Boolean))!=null?te:[];if(!A.some(oe=>ne.includes(oe)))return!1}}return!0})}function $G({hasOddMatchUpsCount:t,drawDefinition:e,roundMatchUps:r,structure:n}){var o,i,s;if(!n)return!1;r||({hasOddMatchUpsCount:t,roundMatchUps:r}=Tr({matchUps:(o=n.matchUps)!=null?o:[]}));const a=!!((i=r==null?void 0:r[1])!=null&&i.find(({drawPositions:c})=>c)),l=!((s=r==null?void 0:r[2])!=null&&s.find(({drawPositions:c})=>c));return t&&!(n!=null&&n.structures)&&a&&l&&!(e!=null&&e.drawType&&e.drawType!==Di)}function Co({drawDefinition:t,structure:e}){var r;return e?!(e!=null&&e.structures)&&!(t!=null&&t.drawType&&t.drawType!==On)&&!((r=e==null?void 0:e.matchUps)!=null&&r.find(({roundPosition:n})=>!!n)):!1}const ly={[Ef]:{policyName:"Round Naming Default",abbreviatedRoundNamingMap:{1:"F",2:"SF",4:"QF"},roundNamingMap:{1:"Final",2:"Semifinal",4:"Quarterfinal"},affixes:{roundNumber:"R",preFeedRound:"Q"},stageConstants:{[he]:"",[ft]:"P",[we]:"Q",[xt]:"C"}}};function NG({roundNamingPolicy:t,structure:e,matchUps:r}){const{hasOddMatchUpsCount:n,roundProfile:o,roundMatchUps:i}=Tr({matchUps:r}),{structureAbbreviation:s,stage:a}=e,l=Co({structure:e}),c=$G({hasOddMatchUpsCount:n,roundMatchUps:i,structure:e}),u=e.structures,p={},d=ly[Ef],v=(t==null?void 0:t.roundNamingMap)||d.roundNamingMap||{},f=(t==null?void 0:t.abbreviatedRoundNamingMap)||d.abbreviatedRoundNamingMap||{},m=(t==null?void 0:t.affixes)||d.affixes,h=a&&a!==he&&a[0],g=t==null?void 0:t.stageConstants,_=a&&(g==null?void 0:g[a])||h,I=o?Object.keys(o):[];return u||l||c?Object.assign(p,...I.map(P=>{const y=`Round ${P}`,S=`R${P}`;return{[P]:{roundName:y,abbreviatedRoundName:S}}})):Object.assign(p,...I.map(P=>{if(!(o!=null&&o[P]))return;const{matchUpsCount:y,preFeedRound:S}=o[P],O=y*2,b=v[y]||`${m.roundNumber}${O}`,w=S?`-${m.preFeedRound}`:"",T=`${b}${w}`,$=[_,s,T].filter(Boolean).join("-"),E=`${f[y]||`${m.roundNumber}${O}`}${w}`,A=[_,s,E].filter(Boolean).join("-");return{[P]:{abbreviatedRoundName:A,roundName:$}}})),{roundNamingProfile:p,roundProfile:o,roundMatchUps:i}}function UG({drawPositionCollectionAssignment:t,positionAssignments:e,displaySideNumber:r,seedAssignments:n,drawPosition:o,isFeedRound:i,sideNumber:s}){var a,l,c,u;const p=e.find(g=>g.drawPosition===o),d=t?(a=t[o])==null?void 0:a.participantId:p==null?void 0:p.participantId,v=p?AG({displaySideNumber:r,seedAssignments:n,participantId:d,assignment:p,sideNumber:s}):{};i&&(s===1?Object.assign(v,{participantFed:!0}):Object.assign(v,{participantAdvanced:!0}));const f=(l=t==null?void 0:t[o])==null?void 0:l.teamParticipant,m=(c=t==null?void 0:t[o])==null?void 0:c.participant,h=(u=t==null?void 0:t[o])==null?void 0:u.substitutions;return m&&Object.assign(v,{participant:m}),h&&Object.assign(v,{substitutions:h}),f&&Object.assign(v,{teamParticipant:f}),v}function AG({displaySideNumber:t,seedAssignments:e,participantId:r,assignment:n,sideNumber:o}){const i={drawPosition:n.drawPosition,displaySideNumber:t,sideNumber:o};if(r){const s=CG({seedAssignments:e,participantId:r});Object.assign(i,s,{participantId:r})}else n.bye&&Object.assign(i,{bye:!0});return n.qualifier&&Object.assign(i,{qualifier:!0}),i}function CG({seedAssignments:t,participantId:e}){return t==null?void 0:t.find(r=>!r.seedProxy&&r.participantId===e)}const Oa="ANY",vt="MALE",Mo="MIXED",Ts="OTHER",Tt="FEMALE",cy={ANY:Oa,MALE:vt,FEMALE:Tt,MIXED:Mo,OTHER:Ts};var MG=Object.defineProperty,DG=Object.defineProperties,jG=Object.getOwnPropertyDescriptors,uy=Object.getOwnPropertySymbols,RG=Object.prototype.hasOwnProperty,FG=Object.prototype.propertyIsEnumerable,dy=(t,e,r)=>e in t?MG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ln=(t,e)=>{for(var r in e||(e={}))RG.call(e,r)&&dy(t,r,e[r]);if(uy)for(var r of uy(e))FG.call(e,r)&&dy(t,r,e[r]);return t},Vu=(t,e)=>DG(t,jG(e));function Je({scheduleVisibilityFilters:t,tournamentAppliedPolicies:e,provisionalPositioning:r,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,seedAssignments:a,contextFilters:l,contextContent:c,matchUpFilters:u,participantMap:p,scheduleTiming:d,contextProfile:v,drawDefinition:f,context:m={},exitProfiles:h,matchUpsMap:g,structure:_,inContext:I,event:P}){var y,S,O,b,w,T,$;let N={},E={};if(n=n??(s==null?void 0:s.participants),!_)return{collectionPositionMatchUps:N,error:ra,roundMatchUps:E,matchUps:[]};const A=Array.isArray(u==null?void 0:u.eventIds)?u==null?void 0:u.eventIds.filter(Boolean):[],U=Array.isArray(u==null?void 0:u.structureIds)?u==null?void 0:u.structureIds.filter(Boolean):[],C=Array.isArray(u==null?void 0:u.drawIds)?u==null?void 0:u.drawIds.filter(Boolean):[],M=!(m!=null&&m.eventId)||!(A!=null&&A.length)&&!((y=l==null?void 0:l.eventIds)!=null&&y.filter(Boolean).length)||(A==null?void 0:A.includes(m.eventId))||((S=l==null?void 0:l.eventIds)==null?void 0:S.includes(m.eventId)),D=!(U!=null&&U.length)||U.includes(_.structureId),R=!f||!(C!=null&&C.length)||C.includes(f.drawId);if(!M||!D||!R)return{collectionPositionMatchUps:N,roundMatchUps:E,matchUps:[]};v&&!c&&(c=wo({tournamentRecord:s,contextProfile:v,drawDefinition:f}));const{appliedPolicies:j}=pt({drawDefinition:f}),G=ln(ln(ln({},e),j),i),W=(O=G==null?void 0:G.scoring)==null?void 0:O.structures,q=_.stage&&(W==null?void 0:W.stage)&&(W==null?void 0:W.stage[_.stage]),F=_.stageSequence&&(q==null?void 0:q.stageSequence)&&q.stageSequence[_.stageSequence],L=((b=G==null?void 0:G.scoring)==null?void 0:b.requireAllPositionsAssigned)||(q==null?void 0:q.requireAllPositionsAssigned)||(F==null?void 0:F.requireAllPositionsAssigned);g||(g=lr({drawDefinition:f,structure:_}));const{positionAssignments:x,allPositionsAssigned:B}=Dt({structure:_}),z=!L||B,{seedAssignments:H}=$n({provisionalPositioning:r,drawDefinition:f,structure:_});a=a??H;const{roundOffset:Y,structureId:Z,structureName:K,stage:Q,stageSequence:J}=_,{drawId:te,drawName:ne,drawType:ee}=f??{};h=h||f&&uv({drawDefinition:f}).exitProfiles;const oe=h==null?void 0:h[Z],ie=(oe==null?void 0:oe.length)&&(oe[0].split("-").map(le=>parseInt(le)).reduce((le,be)=>le+be)||0),ae=!!_.structures;let se=xi({matchUpsMap:g,structureId:Z,inContext:I});const ye=G==null?void 0:G[Ef],Ie=NG({roundNamingPolicy:ye,structure:_,matchUps:se}),{roundNamingProfile:pe,roundProfile:fe}=Ie;if(E=(w=Ie==null?void 0:Ie.roundMatchUps)!=null?w:[],u&&(se=bs(Vu(ln({matchUps:se},u),{filterMatchUpTypes:!1,filterMatchUpIds:!1}))),I){const{sourceDrawPositionRanges:le}=TG({drawDefinition:f,matchUpsMap:g,structureId:Z}),be=f?EG({drawDefinition:f,roundProfile:fe,matchUpsMap:g,structureId:Z}).drawPositionsRanges:void 0;se=se.map(Pe=>ve({scheduleVisibilityFilters:t,sourceDrawPositionRanges:le,drawPositionsRanges:be,roundNamingProfile:pe,initialRoundOfPlay:ie,appliedPolicies:G,isRoundRobin:ae,roundProfile:fe,matchUp:Pe,event:P})),(se==null?void 0:se.filter(Pe=>Array.isArray(Pe.tieMatchUps))).forEach(Pe=>{const xe=Pe.tieMatchUps;se=se.concat(...xe)}),l&&(se=bs(Vu(ln({processContext:!0},l),{matchUps:se})))}else(se==null?void 0:se.filter(be=>Array.isArray(be.tieMatchUps))).forEach(be=>{const Me=be.tieMatchUps;se=se.concat(...Me)});return u&&(se=bs(Vu(ln({matchUps:se},u),{filterMatchUpTypes:!1,filterMatchUpIds:!1}))),(u!=null&&u.matchUpTypes||u!=null&&u.matchUpIds)&&(se=bs({matchUpTypes:u.matchUpTypes,matchUpIds:u.matchUpIds,matchUps:se})),(u!=null&&u.matchUpTypes||u!=null&&u.matchUpIds||I)&&(E=(T=Tr({matchUps:se}).roundMatchUps)!=null?T:[]),($=vr({drawDefinition:f,structure:_,event:P}))!=null&&$.tieFormat&&({collectionPositionMatchUps:N}=VV({matchUps:se})),{matchUps:se,roundMatchUps:E,roundProfile:fe,collectionPositionMatchUps:N};function ve({scheduleVisibilityFilters:le,sourceDrawPositionRanges:be,drawPositionsRanges:Me,initialRoundOfPlay:Pe,additionalContext:xe,roundNamingProfile:Be,tieDrawPositions:qe,appliedPolicies:$e,isCollectionBye:De,matchUpTieId:me,isRoundRobin:ge,roundProfile:Se,sideLineUps:Ee,matchUp:Ae,event:je}){var gt,rt,yt,St,ze,_t,Ve,It,nr,dr,vi,Lr,Qs,xp,Lp,Ot;xe=xe||{};const Er=(gt=vr({drawDefinition:f,structure:_,matchUp:Ae,event:je}))==null?void 0:gt.tieFormat,mi=Er==null?void 0:Er.collectionDefinitions,Cn=Ae.collectionId&&(mi==null?void 0:mi.find(pr=>pr.collectionId===Ae.collectionId)),Vp=Ae.collectionId?Cn==null?void 0:Cn.matchUpFormat:Ae.matchUpFormat||(_==null?void 0:_.matchUpFormat)||(f==null?void 0:f.matchUpFormat)||(je==null?void 0:je.matchUpFormat),hg=Ae.matchUpType||(Cn==null?void 0:Cn.matchUpType)||(_==null?void 0:_.matchUpType)||(f==null?void 0:f.matchUpType)||(je==null?void 0:je.eventType)!==Bt&&(je==null?void 0:je.eventType),z0e=De?nt:Ae.matchUpStatus,{schedule:Y0e,endDate:K0e}=ev({scheduleVisibilityFilters:le,afterRecoveryTimes:o,tournamentRecord:s,scheduleTiming:d,matchUpFormat:Vp,matchUpType:hg,matchUp:Ae,event:je}),Wc=(rt=qe??Ae.drawPositions)!=null?rt:[],{collectionPosition:Q0e,collectionId:VR,roundPosition:Bp}=Ae,to=Ae.roundNumber||xe.roundNumber,J0e=VR?pG({tournamentParticipants:n,positionAssignments:x,collectionPosition:Q0e,drawDefinition:f,participantMap:p,drawPositions:Wc,collectionId:VR,sideLineUps:Ee,matchUpType:hg}):void 0,BR=((yt=Be==null?void 0:Be[to])==null?void 0:yt.roundName)||xe.roundName,kR=((St=Be==null?void 0:Be[to])==null?void 0:St.abbreviatedRoundName)||xe.abbreviatedRoundName,Z0e=(ze=Se==null?void 0:Se[to])==null?void 0:ze.feedRound,X0e=(_t=Se==null?void 0:Se[to])==null?void 0:_t.preFeedRound,eSe=(Ve=Se==null?void 0:Se[to])==null?void 0:Ve.roundFactor,GR=Me==null?void 0:Me[to],tSe=Bp?GR==null?void 0:GR[Bp]:void 0,WR=be==null?void 0:be[to],rSe=Cn!=null&&Cn.category?ln(ln({},(m==null?void 0:m.category)||{}),Cn.category):m==null?void 0:m.category,nSe=((It=Ae.processCodes)==null?void 0:It.length)&&Ae.processCodes||((nr=Cn==null?void 0:Cn.processCodes)==null?void 0:nr.length)&&(Cn==null?void 0:Cn.processCodes)||((dr=_==null?void 0:_.processCodes)==null?void 0:dr.length)&&(_==null?void 0:_.processCodes)||((vi=f==null?void 0:f.processCodes)==null?void 0:vi.length)&&(f==null?void 0:f.processCodes)||((Lr=je==null?void 0:je.processCodes)==null?void 0:Lr.length)&&(je==null?void 0:je.processCodes)||(s==null?void 0:s.processCodes),oSe=(v==null?void 0:v.withCompetitiveness)&&yI(Vu(ln({},c),{matchUp:Ae})).competitiveness,iSe=Ae.finishingPositionRange||xe.finishingPositionRange,kp=pr=>Oe(pr,void 0,!0),wt=ln(ln(ln({},kp(m)),kp({matchUpFormat:Ae.matchUpType===Bt?void 0:Vp,tieFormat:Ae.matchUpType!==Bt?void 0:Er,roundOfPlay:Q!==we&&ht(Pe)&&Pe+(to||0),endDate:Ae.endDate||K0e,gender:Cn==null?void 0:Cn.gender,discipline:je==null?void 0:je.discipline,category:rSe,finishingPositionRange:iSe,abbreviatedRoundName:kR,drawPositionsRange:tSe,competitiveness:oSe,structureName:K,stageSequence:J,drawPositions:Wc,matchUpStatus:z0e,processCodes:nSe,isRoundRobin:ge,matchUpTieId:me,preFeedRound:X0e,matchUpType:hg,roundFactor:eSe,roundOffset:Y,structureId:Z,roundNumber:to,feedRound:Z0e,roundName:BR,drawName:ne,drawType:ee,schedule:Y0e,drawId:te,stage:Q})),de(kp(Ae),!0,!0));if(Vp&&((Qs=Ae.score)!=null&&Qs.scoreStringSide1)){const pr=Pr(Vp),{bestOf:xo,finalSetFormat:Kr,setFormat:mt}=pr??{};(Kr!=null&&Kr.tiebreakSet||mt!=null&&mt.tiebreakSet||mt!=null&&mt.timed)&&(wt.score.sets=wt.score.sets.sort((fr,$r)=>fr.setNumber-$r.setNumber).map((fr,$r)=>($r+1===xo?(Kr!=null&&Kr.tiebreakSet||Kr!=null&&Kr.timed)&&(fr.tiebreakSet=!0):(mt!=null&&mt.tiebreakSet||mt!=null&&mt.timed)&&(fr.tiebreakSet=!0),fr)))}if(Array.isArray(Wc)){const{orderedDrawPositions:pr,displayOrder:xo}=wG({drawPositions:Wc,roundProfile:Se,roundNumber:to}),Kr=(xp=Se[to])==null?void 0:xp.feedRound,mt=xo[0]!==pr[0],$r=pr.concat(void 0,void 0).slice(0,2).map((Qr,Mn)=>{var Jr;const hi=Mn+1,gg=mt?3-hi:hi,Gp=UG({drawPositionCollectionAssignment:J0e,positionAssignments:x,displaySideNumber:gg,seedAssignments:a,drawPosition:Qr,isFeedRound:Kr,sideNumber:hi}),aSe=(Jr=Ae.sides)==null?void 0:Jr.find(cSe=>cSe.sideNumber===hi),qR=Bp?(Bp-1)*2+Mn+1:void 0,lSe=qR?WR==null?void 0:WR[qR]:void 0;return kp(ln(ln({sourceDrawPositionRange:lSe},aSe),Gp))});Object.assign(wt,de({sides:$r},!0,!0))}if(n&&wt.sides){const pr=i==null?void 0:i[Tl],xo=mt=>{var fr;const $r=(fr=p==null?void 0:p[mt])==null?void 0:fr.participant;return $r&&iu({template:pr==null?void 0:pr.participant,source:$r})};if(wt.sides.filter(Boolean).forEach(mt=>{var fr,$r,Qr;if(mt.participantId){const Mn=de(xo(mt.participantId)||n&&Eo({policyDefinitions:$e,participantId:mt.participantId,tournamentParticipants:n,internalUse:!0,contextProfile:v}),void 0,!0);if(Mn){if(f!=null&&f.entries){const Jr=f.entries.find(hi=>hi.participantId===mt.participantId);Jr!=null&&Jr.entryStatus&&(Mn.entryStatus=Jr.entryStatus),Jr!=null&&Jr.entryStage&&(Mn.entryStage=Jr.entryStage)}Object.assign(mt,{participant:Mn})}}if(($r=(fr=mt==null?void 0:mt.participant)==null?void 0:fr.individualParticipantIds)!=null&&$r.length&&!((Qr=mt.participant.individualParticipants)!=null&&Qr.length)){const Mn=mt.participant.individualParticipantIds.map(Jr=>xo(Jr)||n&&Eo({policyDefinitions:$e,tournamentParticipants:n,internalUse:!0,contextProfile:v,participantId:Jr}));Object.assign(mt.participant,{individualParticipants:Mn})}}),!wt.matchUpType){const{matchUpType:mt}=YP({matchUp:wt});mt&&Object.assign(wt,{matchUpType:mt})}if((v==null?void 0:v.inferGender)&&(!wt.gender||wt.gender===Mo)&&((Lp=wt.sides)==null?void 0:Lp.length)===2&&wt.matchUpType!==Bt){const mt=wt.sides.map(fr=>{var $r,Qr,Mn,Jr;if(wt.matchUpType===At)return(Qr=($r=fr.participant)==null?void 0:$r.person)==null?void 0:Qr.sex;if(((Jr=(Mn=fr.participant)==null?void 0:Mn.individualParticipants)==null?void 0:Jr.length)===2){const hi=We(fr.participant.individualParticipants.map(gg=>{var Gp;return(Gp=gg.person)==null?void 0:Gp.sex})).filter(Boolean);if(hi.length===1)return hi[0]}});if(mt.filter(Boolean).length===2&&We(mt).length===1){const fr=mt[0];wt.inferredGender=fr}}}if(wt.tieMatchUps){const pr=wt.matchUpStatus===nt,xo=(Ot=wt.sides)==null?void 0:Ot.map(({participant:Kr,drawPosition:mt,sideNumber:fr,lineUp:$r})=>{const Qr=(Kr==null?void 0:Kr.participantType)===Bt&&Kr;return{teamParticipant:Qr&&Oe({participantRoleResponsibilities:Qr.participantRoleResponsibilities,participantOtherName:Qr.participanOthertName,participantName:Qr.participantName,participantId:Qr.participantId,teamId:Qr.teamId}),drawPosition:mt,sideNumber:fr,lineUp:$r}});wt.tieMatchUps=wt.tieMatchUps.map(Kr=>{const mt=wt.matchUpId,$r={finishingPositionRange:wt.finishingPositionRange,abbreviatedRoundName:kR,roundNumber:to,roundName:BR};return ve({tieDrawPositions:Wc,scheduleVisibilityFilters:le,sourceDrawPositionRanges:be,sideLineUps:xo,drawPositionsRanges:Me,initialRoundOfPlay:Pe,roundNamingProfile:Be,additionalContext:$r,appliedPolicies:$e,isCollectionBye:pr,matchUpTieId:mt,isRoundRobin:ge,roundProfile:Se,matchUp:Kr,event:je})})}const HR=wt.sides&&wt.sides.filter(pr=>pr==null?void 0:pr.participantId).length===2,sSe=!wt.winningSide;if(Object.assign(wt,{readyToScore:z&&HR&&sSe,hasContext:!0}),HR){const{allParticipantsCheckedIn:pr,checkedInParticipantIds:xo}=ec({matchUp:wt});Object.assign(wt,{allParticipantsCheckedIn:pr,checkedInParticipantIds:xo})}return Array.isArray(v==null?void 0:v.exclude)&&(v==null||v.exclude.forEach(pr=>delete wt[pr])),wt}}function xG(t){return Object.assign(t,{inContext:!0}),{matchUp:de(lt(t).matchUp,!1,!0)}}function lt({tournamentParticipants:t,afterRecoveryTimes:e,contextContent:r,contextProfile:n,drawDefinition:o,matchUpsMap:i,matchUpId:s,inContext:a,context:l,event:c}){if(!o)return{error:ue};if(!s)return{error:Vt};if(typeof s!="string")return{error:X};const{structures:u=[]}=an({drawDefinition:o});n&&!r&&(r=wo({contextProfile:n,drawDefinition:o}));for(const p of u){const{matchUps:d}=Je({tournamentParticipants:t,afterRecoveryTimes:e,contextContent:r,drawDefinition:o,contextProfile:n,matchUpsMap:i,inContext:a,structure:p,context:l,event:c}),{matchUp:v}=mI({matchUps:d,matchUpId:s});if(v)return{matchUp:v,structure:p}}return{error:ir}}var LG=Object.defineProperty,VG=Object.defineProperties,BG=Object.getOwnPropertyDescriptors,py=Object.getOwnPropertySymbols,kG=Object.prototype.hasOwnProperty,GG=Object.prototype.propertyIsEnumerable,fy=(t,e,r)=>e in t?LG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,WG=(t,e)=>{for(var r in e||(e={}))kG.call(e,r)&&fy(t,r,e[r]);if(py)for(var r of py(e))GG.call(e,r)&&fy(t,r,e[r]);return t},HG=(t,e)=>VG(t,BG(e));function vy({collectionGroups:t=[]}){const e=Object.assign({},...t.filter(n=>(n==null?void 0:n.groupValue)&&(n==null?void 0:n.groupNumber)).map(n=>({[n.groupNumber]:HG(WG({},n),{allGroupMatchUpsCompleted:!0,matchUpsCount:0,sideWins:[0,0],values:[0,0]})}))),r=Object.keys(e).map(n=>Te(n));return{groupValueGroups:e,groupValueNumbers:r}}function tc(t){var e,r,n,o;const{sideAdjustments:i=[0,0],separator:s="-",drawDefinition:a,matchUpsMap:l,structure:c,matchUp:u,event:p}=t;if(!Array.isArray(i)||i.length!==2||isNaN(i.reduce((b,w)=>b+w)))return{error:X};if(!u)return{error:jr};const d=((e=vr({matchUp:u,drawDefinition:a,structure:c,event:p}))==null?void 0:e.tieFormat)||(t==null?void 0:t.tieFormat);if(!d)return{error:Zc};const v=br({tieFormat:d});if(v.error)return v;const f=(d==null?void 0:d.collectionDefinitions)||[],m=(u==null?void 0:u.tieMatchUps)||[],h=[0,0],{groupValueGroups:g,groupValueNumbers:_}=vy(d);for(const b of f)UV({collectionDefinition:b,groupValueNumbers:_,groupValueGroups:g,sideTieValues:h,tieMatchUps:m});for(const b of _){const w=g[b],{allGroupMatchUpsCompleted:T,matchUpCount:$,winCriteria:N,groupValue:E,sideWins:A,values:U}=w;let C;if(N!=null&&N.aggregateValue)T&&U[0]!==U[1]&&(C=U[0]>U[1]?1:2);else if(N!=null&&N.valueGoal)C=U.reduce((M,D,R)=>D>=N.valueGoal?R+1:M,void 0);else{const M=Math.floor($/2)+1;C=A.reduce((D,R,j)=>R>=M?j+1:D,void 0)}C&&(h[C-1]+=E)}const I=h.map((b,w)=>b+i[w]),P={side1Score:I[0],side2Score:I[1],winningSide:void 0},y=I.join(s),S=I.slice().reverse().join(s);let O;if(d!=null&&d.winCriteria){const{valueGoal:b,aggregateValue:w,tallyDirectives:T}=d.winCriteria;if(b){const $=I.map((N,E)=>({sideNumber:E+1,points:N})).find(({points:N})=>N>=b);O=$==null?void 0:$.sideNumber}else w&&m.every(N=>N.matchUpStatus&&Yt.includes(N.matchUpStatus)||N.winningSide)&&I[0]!==I[1]&&(O=I[0]>I[1]?1:2);if(!O&&T){const $=u.matchUpId,N=u.hasContext?u:((r=l==null?void 0:l.drawMatchUps)==null?void 0:r[$])||a&&((n=lt({inContext:!0,drawDefinition:a,matchUpId:$}))==null?void 0:n.matchUp);if(N){const{completedTieMatchUps:E,order:A}=Nf({matchUps:[N]});if(E&&(A!=null&&A.length)){const U=A[0].participantId;O=(o=N.sides.find(({participantId:C})=>C===U))==null?void 0:o.sideNumber}}}}return O&&(P.winningSide=O),{scoreStringSide1:y,scoreStringSide2:S,winningSide:O,set:P}}function Nn(t){if(t)return de(t,!1,!0)}function Gt(t){var e,r;const n=t==null?void 0:t.matchUp,o=(t==null?void 0:t.score)||(n==null?void 0:n.score),i=(e=o==null?void 0:o.sets)==null?void 0:e[0],{side1Score:s,side2Score:a,side1TiebreakScore:l,side2TiebreakScore:c,side1PointScore:u,side2PointScore:p}=i||{},d=s||a||l||c||u||p;return!!(((r=o==null?void 0:o.sets)==null?void 0:r.length)>1||d)}function rc({matchUpStatus:t}){return cV.includes(t)}function qG({matchUpStatus:t}){return H_.includes(t)}function pv({matchUpStatus:t}){return uV.includes(t)}function fv({matchUpStatus:t,winningSide:e,tieMatchUps:r,sides:n,score:o}){var i;const s=n==null?void 0:n.find(({participantId:c})=>c),a=(i=r==null?void 0:r.filter(fv))==null?void 0:i.length;return Gt({score:o})||a||e&&s||t&&qG({matchUpStatus:t})&&![Xe,ot,Vn].includes(t)}var zG=Object.defineProperty,my=Object.getOwnPropertySymbols,YG=Object.prototype.hasOwnProperty,KG=Object.prototype.propertyIsEnumerable,hy=(t,e,r)=>e in t?zG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gy=(t,e)=>{for(var r in e||(e={}))YG.call(e,r)&&hy(t,r,e[r]);if(my)for(var r of my(e))KG.call(e,r)&&hy(t,r,e[r]);return t};function vv(t){var e;return typeof t!="object"?{error:_e}:typeof t.element!="object"?{error:X}:t.notes?typeof t.notes!="string"&&!((e=t.notes)!=null&&e.testing)?{error:X}:(Object.assign(t.element,{notes:t.notes}),gy({},V)):{error:_e}}function QG(t){return typeof t!="object"?{error:_e}:typeof t.element!="object"?{error:X}:(t.element.notes&&delete t.element.notes,gy({},V))}var JG=Object.defineProperty,_y=Object.getOwnPropertySymbols,ZG=Object.prototype.hasOwnProperty,XG=Object.prototype.propertyIsEnumerable,Iy=(t,e,r)=>e in t?JG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Do=(t,e)=>{for(var r in e||(e={}))ZG.call(e,r)&&Iy(t,r,e[r]);if(_y)for(var r of _y(e))XG.call(e,r)&&Iy(t,r,e[r]);return t};function Bu(t,e){var r;if(!t)return{error:ue};let n=Date.now();t.updatedAt&&n===new Date(t.updatedAt).getTime()&&(n+=1);const o=new Date(n).toISOString(),i=e==null?void 0:e.filter(Boolean);return t.updatedAt=o,(r=t.structures)==null||r.filter(Boolean).forEach(s=>{(!(i!=null&&i.length)||i!=null&&i.includes(s.structureId))&&(s.updatedAt=o)}),Do({},V)}function Li({drawDefinition:t,tournamentId:e,matchUps:r,eventId:n}){return t&&Bu(t),He({payload:{matchUps:r,tournamentId:e,eventId:n},topic:qf}),Do({},V)}function Vi({drawDefinition:t,tournamentId:e,matchUpIds:r,eventId:n,action:o}){t&&Bu(t),He({topic:aP,payload:{tournamentId:e,matchUpIds:r,eventId:n,action:o}});for(const i of r)N_({key:i});return Do({},V)}function Ze({drawDefinition:t,tournamentId:e,structureId:r,context:n,eventId:o,matchUp:i}){return i?(t&&et({drawDefinition:t,structureIds:r?[r]:void 0,tournamentId:e,eventId:o}),He({topic:cP,payload:{matchUp:i,tournamentId:e,context:n},key:i.matchUpId}),Do({},V)):(console.log(jr),{error:jr})}function e3({tournamentId:t,inContextMatchUp:e}){return e?(He({topic:zf,payload:{inContextMatchUp:e,tournamentId:t},key:e.matchUpId}),Do({},V)):{error:jr}}function nc({tournamentId:t,eventId:e,drawDefinition:r}){return r?(Bu(r),He({payload:{drawDefinition:r,tournamentId:t,eventId:e},topic:tP,key:r.drawId}),Do({},V)):(console.log(ue),{error:ue})}function t3({tournamentId:t,eventId:e,drawId:r}){return He({payload:{drawId:r,tournamentId:t,eventId:e},topic:sP,key:r}),N_({key:r}),Do({},V)}function et({drawDefinition:t,tournamentId:e,structureIds:r,eventId:n}){return t?(Bu(t,r),He({payload:{tournamentId:e,eventId:n,drawDefinition:t},topic:lP,key:t.drawId}),Do({},V)):{error:ue}}function Py({drawDefinition:t,tournamentId:e,structure:r,eventId:n}){if(!t)return{error:ue};if(!r)return{error:ra};const o=r.seedAssignments,i=r.structureId,s=t.drawId;return He({payload:{tournamentId:e,eventId:n,drawId:s,structureId:i,seedAssignments:o},topic:dP,key:t.drawId}),et({structureIds:[i],drawDefinition:t,tournamentId:e,eventId:n}),Do({},V)}function oi({drawDefinition:t,tournamentId:e,structure:r,event:n}){if(!t)return{error:ue};if(!r)return{error:ra};const o=st({structure:r}),i=r.structureId,s=t.drawId,a=n==null?void 0:n.eventId;return He({topic:uP,payload:{positionAssignments:o,tournamentId:e,structureId:i,eventId:a,drawId:s},key:i}),et({structureIds:[i],drawDefinition:t,tournamentId:e,eventId:a}),Do({},V)}const ku=t=>t==null?void 0:t.participantId;function r3({positionAssignments:t}){const e=(t||[]).filter(ku).map(i=>{const{extension:s}=Kt({element:i,name:ma}),a=Te(s==null?void 0:s.value),l=!isNaN(a)&&a;return l&&{participantId:i.participantId,subOrder:l}}).filter(Boolean),r=e.map(({subOrder:i})=>i),n=Nr(r);return{subOrderMap:Object.assign({},...e.filter(({subOrder:i})=>n[i]===1).map(({participantId:i,subOrder:s})=>({[i]:s})))}}var n3=Object.defineProperty,o3=Object.defineProperties,i3=Object.getOwnPropertyDescriptors,yy=Object.getOwnPropertySymbols,s3=Object.prototype.hasOwnProperty,a3=Object.prototype.propertyIsEnumerable,Sy=(t,e,r)=>e in t?n3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l3=(t,e)=>{for(var r in e||(e={}))s3.call(e,r)&&Sy(t,r,e[r]);if(yy)for(var r of yy(e))a3.call(e,r)&&Sy(t,r,e[r]);return t},c3=(t,e)=>o3(t,i3(e));function Oy({positionAssignments:t,tournamentRecord:e,drawDefinition:r,matchUpFormat:n,matchUps:o,event:i}){if(!Array.isArray(o))return{error:X};if(!t)return{error:X};const{policyDefinitions:s}=ls({policyTypes:[sI],tournamentRecord:e,drawDefinition:r,event:i}),{subOrderMap:a}=r3({positionAssignments:t}),l=Nf({policyDefinitions:s,matchUpFormat:n,subOrderMap:a,matchUps:o});if(l.error)return l;const{participantResults:c,bracketComplete:u,report:p}=l,d=Object.keys(c);return t.forEach(v=>{const{participantId:f}=v;if(d.includes(f)){const m={value:c[f],name:Ko};it({element:v,extension:m}),c[f].ties||yn({element:v,name:ma})}else yn({element:v,name:Ko}),yn({element:v,name:ma})}),et({drawDefinition:r}),c3(l3({},V),{participantResults:c,bracketComplete:u,report:p})}function mv({participantsProfile:t,participants:e=[]}){const r=de(e,t==null?void 0:t.convertExtensions,!0),n=r.filter(s=>s.participantType===tt),o=r.filter(s=>s.participantType===Mr),i=r.filter(s=>s.participantType===Ce);return r.forEach(s=>{if(s.participantType===Fe){const{participantId:a}=s;s.groupParticipantIds=[],s.teamParticipantIds=[],s.pairParticipantIds=[],s.groups=[],s.teams=[],n.forEach(l=>{((l==null?void 0:l.individualParticipantIds)||[]).forEach(c=>{var u;c===a&&!((u=s.teamParticipantIds)!=null&&u.includes(l.participantId))&&(s.teamParticipantIds.push(l.participantId),s.teams.push({participantRoleResponsibilities:l.participantRoleResponsibilities,participantOtherName:l.participantOtherName,participantName:l.participantName,participantId:l.participantId,teamId:l.teamId}))})}),i.forEach(l=>{((l==null?void 0:l.individualParticipantIds)||[]).forEach(c=>{c===a&&!s.pairParticipantIds.includes(l.participantId)&&s.pairParticipantIds.push(l.participantId)})}),o.forEach(l=>{((l==null?void 0:l.individualParticipantIds)||[]).forEach(c=>{c===a&&!s.groupParticipantIds.includes(l.participantId)&&(s.groupParticipantIds.push(l.participantId),s.groups.push({participantRoleResponsibilities:l.participantRoleResponsibilities,participantOtherName:l.participantOtherName,participantName:l.participantName,participantId:l.participantId}))})})}}),r}const hv=t=>e=>t[e],gv=(t=[])=>t.map(Jt).filter(Boolean),oc=(t=[])=>t.map(ct).filter(Boolean),ct=(t={})=>hv(t)("participantId"),u3=(t={})=>hv(t)("drawPosition"),Jt=(t={})=>hv(t)("matchUpId");function d3({structureMatchUps:t,matchUp:e}){const{roundNumber:r,roundPosition:n}=e,o=t.filter(s=>s.roundNumber===r&&!s.matchUpTieId),i=t.filter(s=>s.roundNumber===r+1&&!s.matchUpTieId);if(i.length){let s;return i.length===o.length?s=i.find(a=>a.roundPosition===n):i.length===o.length/2&&(s=i.find(a=>a.roundPosition===Math.ceil(n/2))),{matchUp:s}}return{message:"no progression found"}}function _v({sourceRoundMatchUpCount:t,inContextDrawMatchUps:e,sourceRoundPosition:r,drawDefinition:n,targetLink:o}){var i;if(!o)return{error:Yg};const{target:{structureId:s,feedProfile:a,groupedOrder:l,roundNumber:c,positionInterleave:u}}=o,{structure:p}=Ne({drawDefinition:n,structureId:s}),{positionAssignments:d}=st({structure:p}),f=(e==null?void 0:e.filter($=>$.structureId===(p==null?void 0:p.structureId))).filter($=>$.roundNumber===c&&!$.matchUpTieId),m=f.length,h=ce(1,m+1),g=m/t;let _=Math.ceil(g*r),I=1-r%2;if(u!=null&&u.interleave&&g!==.5){const $=u.offset+(r-1)*u.interleave,N=r+$;_=Math.ceil(N/2),I=1-N%2}let P=h,y=h[_-1];const S=sy({groupedOrder:l,roundPositionsCount:h.length}),O=(S==null?void 0:S.length)||1;if(O<=h.length){const $=m/O,N=qt(h,$);a===Is&&N.forEach(E=>E.reverse()),P=(S==null?void 0:S.length)&&(S==null?void 0:S.map(E=>N[E-1]).flat())||P}a===Ai?y=P[_-1]:a===Is?((!(S!=null&&S.length)||O>h.length)&&(_=f.length+1-_),y=P[_-1]):a===ZP&&zt()&&console.log(P_,{feedProfile:a});const b=y&&f.reduce(($,N)=>N.roundPosition===y?N:$,void 0);let w;b!=null&&b.feedRound?(I=0,w=Math.min(...(b.drawPositions||[]).filter(Boolean))):w=((i=b==null?void 0:b.drawPositions)==null?void 0:i.length)===2&&(b==null?void 0:b.drawPositions[I]);const T=d==null?void 0:d.find(({drawPosition:$})=>$===w);if(T){const{extension:$}=Kt({element:T,name:hu});if($!=null&&$.value)return{disabledDrawPosition:w}}return{matchUp:b,targetDrawPosition:w,matchUpDrawPositionIndex:I}}function p3({drawDefinition:t,roundNumber:e,structureId:r}){if(!t)return{error:ue};if(!r)return{error:yr};const{links:n}=ic({drawDefinition:t,structureId:r}),o=n.source.reduce((s,a)=>!a.source.roundNumber||a.source.roundNumber===e?s.concat(a):s,[]),i=n.target.reduce((s,a)=>!a.target.roundNumber||a.target.roundNumber===e?s.concat(a):s,[]);return{links:{source:o,target:i}}}function Iv({finishingPositions:t,linkCondition:e,linkType:r,source:n}){var o;const i=n.find(s=>{var a,l;const c=!((a=s.source)!=null&&a.finishingPositions)||!t||Xt(t,(l=s.source)==null?void 0:l.finishingPositions);return e===s.linkCondition&&c&&s.linkType===r});return[Mi,Ps].includes(i==null?void 0:i.linkType)&&!((o=i==null?void 0:i.source)!=null&&o.roundNumber)?k({result:{error:X},stack:"getTargetLink",context:i}):i}function ic({drawDefinition:t,structureId:e,roundNumber:r}){return t?e?{links:(t.links||[]).filter(Boolean).reduce((i,s)=>{var a,l;return((a=s.source)==null?void 0:a.structureId)===e&&(!r||s.source.roundNumber===r)&&(i.source=i.source.concat(s)),((l=s.target)==null?void 0:l.structureId)===e&&(!r||s.target.roundNumber===r)&&(i.target=i.target.concat(s)),i},{source:[],target:[]})}:{error:yr}:{error:ue}}function Ir({inContextDrawMatchUps:t=[],useTargetMatchUpIds:e,inContextMatchUp:r,drawDefinition:n,matchUpId:o}){let i=r;t.length&&!i&&(i=t.find(l=>l.matchUpId===o));const{structure:s}=Ne({structureId:i==null?void 0:i.structureId,drawDefinition:n});return(s==null?void 0:s.finishingPosition)===ji?f3({inContextDrawMatchUps:t,useTargetMatchUpIds:e,drawDefinition:n,structure:s,matchUp:i}):v3({matchUp:i})}function f3({inContextDrawMatchUps:t,useTargetMatchUpIds:e,drawDefinition:r,structure:n,matchUp:o}){var i,s,a;const{winnerMatchUpId:l,loserMatchUpId:c}=o,{links:u}=p3({roundNumber:o.roundNumber,structureId:n.structureId,drawDefinition:r}),p=u==null?void 0:u.source,d=Iv({source:p,linkType:Mi}),v=Iv({linkCondition:co,linkType:Ps,source:p});let f=Iv({source:p,linkType:Ps});const m=v&&f;f||(f=v);const h=(i=d==null?void 0:d.target)==null?void 0:i.feedProfile,g=(s=f==null?void 0:f.target)==null?void 0:s.feedProfile,_=(a=v==null?void 0:v.target)==null?void 0:a.feedProfile;let I,P,y,S,O,b,w,T,$,N;if(e&&(l||c)&&(w=l&&h!==Sn&&t.find(({matchUpId:U})=>U===l),S=c&&g!==Sn&&t.find(({matchUpId:U})=>U===c),w||S))return{matchUp:o,targetLinks:{loserTargetLink:f,winnerTargetLink:d},targetMatchUps:{loserMatchUp:S,winnerMatchUp:w}};const{roundPosition:E}=o;N=N||t.filter(U=>U.structureId===n.structureId);const A=N.reduce((U,C)=>C.roundNumber===o.roundNumber&&!C.matchUpTieId?U+1:U,0);return f&&!S&&g!==Sn&&({matchUpDrawPositionIndex:b,targetDrawPosition:O,matchUp:S}=_v({targetLink:f,sourceRoundMatchUpCount:A,inContextDrawMatchUps:t,sourceRoundPosition:E,drawDefinition:r})),m&&_!==Sn&&({matchUpDrawPositionIndex:y,targetDrawPosition:P,matchUp:I}=_v({targetLink:v,sourceRoundMatchUpCount:A,inContextDrawMatchUps:t,sourceRoundPosition:E,drawDefinition:r})),d&&!w&&h!==Sn&&({matchUpDrawPositionIndex:$,targetDrawPosition:T,matchUp:w}=_v({targetLink:d,sourceRoundMatchUpCount:A,inContextDrawMatchUps:t,sourceRoundPosition:E,drawDefinition:r})),w||(N=N||t.filter(U=>U.structureId===n.structureId),{matchUp:w}=d3({structureMatchUps:N,matchUp:o})),Oe({matchUp:o,targetLinks:{loserTargetLink:f,winnerTargetLink:d,byeTargetLink:v},targetMatchUps:{byeMatchUp:I,loserMatchUp:S,winnerMatchUp:w,byeTargetDrawPosition:P,loserTargetDrawPosition:O,winnerTargetDrawPosition:T,byeMatchUpDrawPositionIndex:y,loserMatchUpDrawPositionIndex:b,winnerMatchUpDrawPositionIndex:$},targetMatchUpIds:!!(l||c)})}function v3({matchUp:t}){return{matchUp:t,targetLinks:{loserTargetLink:void 0,winnerTargetLink:void 0},targetMatchUps:{loserMatchUp:void 0,winnerMatchUp:void 0}}}function m3({drawDefinition:t,inContextDrawMatchUps:e}){const r={};return e.forEach(n=>{var o,i,s,a,l;const{matchUpId:c,structureId:u,drawPositions:p=[]}=n,{structure:d}=Ne({drawDefinition:t,structureId:u});if((d==null?void 0:d.finishingPosition)===ya){const{roundNumber:v}=n,f=v&&Te(v)+1,m=d.matchUps||[],{roundMatchUps:h}=Tr({matchUps:m});if(f&&(h!=null&&h[f])){const g=p.sort().map((_,I)=>{const P=h[f].find(y=>{var S;return(S=y.drawPositions)==null?void 0:S.includes(_)});return{matchUpId:P==null?void 0:P.matchUpId,roundNumber:f,schedule:P==null?void 0:P.schedule,sideNumber:I+1,structureName:d.structureName}});Object.assign(n,{sidesTo:g})}}else{const v=Ir({useTargetMatchUpIds:!0,inContextDrawMatchUps:e,inContextMatchUp:n,drawDefinition:t,matchUpId:c});let{winnerMatchUp:f}=v.targetMatchUps;const{loserMatchUp:m}=v.targetMatchUps;!n.winnerMatchUpId&&f&&(n.winnerMatchUpId=f.matchUpId),!n.loserMatchUpId&&m&&(n.loserMatchUpId=m.matchUpId);const h=Pv({upcomingMatchUp:f});let g=Pv({upcomingMatchUp:m});if(n.matchUpStatus!==nt&&(m==null?void 0:m.matchUpStatus)===nt){const{matchUp:I}=by({matchUp:m,drawDefinition:t,inContextDrawMatchUps:e})||{};g=I&&Pv({upcomingMatchUp:I})||g}const _=(o=n.schedule)==null?void 0:o.timeAfterRecovery;if(_&&((i=h==null?void 0:h.schedule)!=null&&i.scheduledTime&&Le(h.schedule.scheduledTime)<Le(_)&&(r[h.matchUpId]=n.matchUpId,h.schedule.scheduleConflict=n.matchUpId),(s=g==null?void 0:g.schedule)!=null&&s.scheduledTime&&Le(g.schedule.scheduledTime)<Le(_)&&(r[g.matchUpId]=n.matchUpId,g.schedule.scheduleConflict=n.matchUpId)),Object.assign(n,{winnerTo:h,loserTo:g}),(a=n.drawPositions)!=null&&a.filter(Boolean).length){const I=(l=v.targetLinks)==null?void 0:l.loserTargetLink,P=(I==null?void 0:I.linkCondition)===co,y=h3(n);if(y.length){const S=oc(f==null?void 0:f.sides),O=oc(m==null?void 0:m.sides),w=y.find(({participantId:N})=>S.includes(N))?[]:y,$=y.find(({participantId:N})=>O.includes(N))?[]:y;m&&P&&$.length<2&&$.push({bye:!0,tbd:!0}),w!=null&&w.length&&f&&(!v.targetMatchUpIds&&f&&(f=e.find(({matchUpId:N})=>N===f.matchUpId)),f.potentialParticipants||(f.potentialParticipants=[]),f.potentialParticipants.push(w)),$!=null&&$.length&&m&&(v.targetMatchUpIds||(f=e.find(({matchUpId:N})=>N===m.matchUpId)),m.potentialParticipants||(m.potentialParticipants=[]),m.potentialParticipants.push($))}}}}),Object.keys(r).length&&e.forEach(n=>{Object.keys(r).includes(n.matchUpId)&&(n.schedule.scheduleConflict=r[n.matchUpId])}),{scheduleConflictMatchUpIds:r}}function h3(t){var e;return((e=t==null?void 0:t.sides)==null?void 0:e.map(({participant:r,participantId:n,qualifier:o})=>r||n&&{participantId:n}||o&&{qualifier:o}).filter(Boolean))||[]}function by({matchUp:t,drawDefinition:e,inContextDrawMatchUps:r}){const{matchUpId:n,matchUpStatus:o,structureId:i}=t||{};if(!t||!i||(t==null?void 0:t.matchUpStatus)===Ft)return{matchUp:t};if(o===nt){let s;if(t.winnerMatchUpId)s=r.find(({matchUpId:a})=>a===t.winnerMatchUpId);else{const a=Ir({inContextDrawMatchUps:r,drawDefinition:e,matchUpId:n});({winnerMatchUp:s}=(a==null?void 0:a.targetMatchUps)||{})}return by({matchUp:s,drawDefinition:e,inContextDrawMatchUps:r})}return{matchUp:void 0}}function Pv(t){if(t!=null&&t.upcomingMatchUp)return(({matchUpId:e,structureId:r,schedule:n,roundNumber:o,roundPosition:i,structureName:s})=>({matchUpId:e,structureId:r,schedule:n,roundNumber:o,roundPosition:i,structureName:s}))(t.upcomingMatchUp)}function sc({requireParticipants:t=!0,scheduleVisibilityFilters:e,tournamentAppliedPolicies:r,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,matchUpFilters:a,contextFilters:l,contextContent:c,participantMap:u,scheduleTiming:p,contextProfile:d,drawDefinition:v,exitProfiles:f,matchUpsMap:m,structureId:h,inContext:g,structure:_,context:I,event:P}){!_&&h&&({structure:_}=Ne({drawDefinition:v,structureId:h}));const y=Je({tournamentAppliedPolicies:r,scheduleVisibilityFilters:e,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,drawDefinition:v,matchUpFilters:a,contextFilters:l,contextProfile:d,contextContent:c,participantMap:u,scheduleTiming:p,exitProfiles:f,matchUpsMap:m,structure:_,inContext:g,context:I,event:P}),S=[],O=[],b=[],w=[],T=[];if(y.error)return y;const{matchUps:$}=y,{assignedPositions:N}=Dt({structure:_}),E=N==null?void 0:N.filter(U=>U.participantId).map(U=>U.drawPosition);let A;return $.filter(U=>{var C;const M=((C=a==null?void 0:a.matchUpTypes)==null?void 0:C.length)===1&&a.matchUpTypes[0]===Qe;return!(U.matchUpType!==Qe&&M)}).forEach(U=>{var C,M,D,R;if(U.matchUpStatus===Wr){S.push(U);return}U.matchUpType===Qe&&(A=!0);const j=U.collectionId,G=j&&((C=U.sides)==null?void 0:C.every(z=>z.participantId)),W=!j&&((M=U.drawPositions)==null?void 0:M.filter(Boolean).length)===2,q=!j&&((D=U.drawPositions)==null?void 0:D.every(z=>E==null?void 0:E.includes(z))),F=N==null?void 0:N.filter(z=>z.bye).map(z=>z.drawPosition),L=!j&&((R=U.drawPositions)==null?void 0:R.find(z=>F==null?void 0:F.includes(z))),B=dV.includes(U.matchUpStatus)&&(G||W&&(!t||q));return L?T.push(U):ca({matchUp:U})?O.push(U):B?b.push(U):w.push(U)}),{includesTeamMatchUps:A,abandonedMatchUps:S,completedMatchUps:O,upcomingMatchUps:b,pendingMatchUps:w,byeMatchUps:T,structure:_}}var g3=Object.defineProperty,_3=Object.defineProperties,I3=Object.getOwnPropertyDescriptors,Ty=Object.getOwnPropertySymbols,P3=Object.prototype.hasOwnProperty,y3=Object.prototype.propertyIsEnumerable,wy=(t,e,r)=>e in t?g3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yv=(t,e)=>{for(var r in e||(e={}))P3.call(e,r)&&wy(t,r,e[r]);if(Ty)for(var r of Ty(e))y3.call(e,r)&&wy(t,r,e[r]);return t},S3=(t,e)=>_3(t,I3(e));function Lt(t){const e="getAllDrawMatchUps";Object.assign(t,{requireParticipants:!1});const r=ws(t);if(r.error)return k({result:r,stack:e});const{abandonedMatchUps:n,completedMatchUps:o,upcomingMatchUps:i,pendingMatchUps:s,byeMatchUps:a,matchUpsMap:l}=r;return{matchUps:(n??[]).concat(...o??[],...i??[],...s??[],...a??[]),matchUpsMap:l}}function ws(t){if(!(t!=null&&t.drawDefinition))return{error:ue};let{tournamentParticipants:e,contextContent:r,matchUpsMap:n}=t;const{scheduleVisibilityFilters:o,tournamentAppliedPolicies:i,requireParticipants:s,participantsProfile:a,afterRecoveryTimes:l,policyDefinitions:c,tournamentRecord:u,contextFilters:p,contextProfile:d,drawDefinition:v,matchUpFilters:f,scheduleTiming:m,participantMap:h,nextMatchUps:g,inContext:_,context:I,event:P}=t;let y=[],S=[],O=[],b=[],w=[];d&&!r&&(r=wo({policyDefinitions:c,tournamentRecord:u,contextProfile:d,event:P})),!(e!=null&&e.length)&&u&&(e=u==null?void 0:u.participants,(_||a!=null&&a.withGroupings)&&(e!=null&&e.length)&&(e=mv({participants:e,participantsProfile:a})));const{structures:T}=an({drawDefinition:v});if(!T)return{error:bt};n||(n=lr({drawDefinition:v}));const $=v&&uv({drawDefinition:v}).exitProfiles;T.forEach(A=>{const{byeMatchUps:U=[],pendingMatchUps:C=[],upcomingMatchUps:M=[],completedMatchUps:D=[],abandonedMatchUps:R=[]}=sc({matchUpFilters:g?void 0:f,contextFilters:g?void 0:p,inContext:_||g||p,tournamentAppliedPolicies:i,scheduleVisibilityFilters:o,tournamentParticipants:e,requireParticipants:s,afterRecoveryTimes:l,policyDefinitions:c,tournamentRecord:u,participantMap:h,scheduleTiming:m,contextContent:r,contextProfile:d,drawDefinition:v,exitProfiles:$,matchUpsMap:n,structure:A,context:I,event:P});y=y.concat(...R),S=S.concat(...D),O=O.concat(...M),b=b.concat(...C),w=w.concat(...U)});const N=A=>(!f&&!g&&!p||(f&&(A=bs(yv({matchUps:A},f))),p&&(A=bs(S3(yv({matchUps:A},p),{processContext:!0})))),A),E=yv({abandonedMatchUps:N(y),completedMatchUps:N(S),upcomingMatchUps:N(O),pendingMatchUps:N(b),byeMatchUps:N(w),matchUpsMap:n},V);if(g){const A=typeof g=="object"||{abandoned:!0,completed:!0,upcoming:!0,pending:!0,bye:!0},{abandoned:U,completed:C,upcoming:M,pending:D,bye:R}=A,j=[].concat(...U&&y||[],...C&&S||[],...M&&O||[],...D&&b||[],...R&&w||[]);m3({inContextDrawMatchUps:j,drawDefinition:v})}return E}const Gu={matchUpStatus:Ft,matchUpStatusCodes:[],score:{scoreStringSide1:"",scoreStringSide2:"",sets:void 0},matchUpFormat:void 0,winningSide:void 0};var O3=Object.defineProperty,Ey=Object.getOwnPropertySymbols,b3=Object.prototype.hasOwnProperty,T3=Object.prototype.propertyIsEnumerable,$y=(t,e,r)=>e in t?O3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ny=(t,e)=>{for(var r in e||(e={}))b3.call(e,r)&&$y(t,r,e[r]);if(Ey)for(var r of Ey(e))T3.call(e,r)&&$y(t,r,e[r]);return t};function Kn({matchUpStatusCodes:t,removeWinningSide:e,tournamentRecord:r,drawDefinition:n,matchUpFormat:o,matchUpStatus:i,removeScore:s,winningSide:a,matchUpId:l,matchUp:c,event:u,notes:p,score:d}){var v,f,m,h,g,_,I,P;const y="modifyMatchUpScore";let S;const O=c.matchUpType===Qe;if(O&&n){if(l&&c.matchUpId!==l){const A=lt({drawDefinition:n,matchUpId:l,event:u});if(!A.matchUp)return{error:ir};({matchUp:c,structure:S}=A)}}else c.matchUpId!==l&&console.log("!!!!!");i&&[ot,Rt].includes(i)||s?Object.assign(c,Ny({},Gu)):d&&(c.score=d);const b=i&&(c==null?void 0:c.matchUpStatus)===Xe&&i!==Xe;i&&(c.matchUpStatus=i),o&&(c.matchUpFormat=o),t&&(c.matchUpStatusCodes=t),a&&(c.winningSide=a),e&&(c.winningSide=void 0),!S&&n&&({structure:S}=lt({drawDefinition:n,matchUpId:l,event:u})),i&&!c.winningSide&&Gt(c)&&!Yt.includes(i)&&![la,Oi].includes(i)&&(c.matchUpStatus=ut.InProgress);let w;if(b&&((v=c==null?void 0:c.processCodes)!=null&&v.length)||i===Xe){const A=(f=pt({tournamentRecord:r,drawDefinition:n,structure:S,event:u}))==null?void 0:f.appliedPolicies;w=(h=(m=A==null?void 0:A[da])==null?void 0:m.processCodes)==null?void 0:h.incompleteAssignmentsOnDefault}if((S==null?void 0:S.structureType)===gr&&!c.collectionId){o=O?"SET1-S:T100":o||c.matchUpFormat||(S==null?void 0:S.matchUpFormat)||(n==null?void 0:n.matchUpFormat)||(u==null?void 0:u.matchUpFormat);const A=S.structures.find(D=>D==null?void 0:D.matchUps.find(R=>R.matchUpId===l)),U=O?{matchUpTypes:[Qe]}:void 0,{matchUps:C}=Je({afterRecoveryTimes:!1,structure:A,inContext:!0,matchUpFilters:U,event:u}),M=Oy({positionAssignments:A.positionAssignments,tournamentRecord:r,drawDefinition:n,matchUpFormat:o,matchUps:C,event:u});if(M.error)return k({result:M,stack:y})}if(p){const A=vv({element:c,notes:p});if(A.error)return k({result:A,stack:y})}const T=r==null?void 0:r.tournamentId,$=Rn().topics.includes(zf),N=($||w)&&lr({drawDefinition:n}),E=N&&((g=Lt({matchUpFilters:{matchUpIds:[l]},nextMatchUps:!0,tournamentRecord:r,inContext:!0,drawDefinition:n,matchUpsMap:N}).matchUps)==null?void 0:g[0]);if($&&E&&e3({tournamentId:T,inContextMatchUp:E}),Array.isArray(w)&&E&&!((_=E.sides)!=null&&_.every(({participantId:A})=>A)))if(i===Xe)c.processCodes?c.processCodes.push(...w):c.processCodes=w;else for(const A of w||[]){const U=A&&((I=c==null?void 0:c.processCodes)==null?void 0:I.lastIndexOf(A));(P=c==null?void 0:c.processCodes)==null||P.splice(U,1)}return Ze({eventId:u==null?void 0:u.eventId,context:y,drawDefinition:n,tournamentId:T,matchUp:c}),Ny({},V)}var w3=Object.defineProperty,E3=Object.defineProperties,$3=Object.getOwnPropertyDescriptors,Uy=Object.getOwnPropertySymbols,N3=Object.prototype.hasOwnProperty,U3=Object.prototype.propertyIsEnumerable,Ay=(t,e,r)=>e in t?w3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Sv=(t,e)=>{for(var r in e||(e={}))N3.call(e,r)&&Ay(t,r,e[r]);if(Uy)for(var r of Uy(e))U3.call(e,r)&&Ay(t,r,e[r]);return t},Cy=(t,e)=>E3(t,$3(e));function uo({tournamentRecord:t,exitWhenNoValues:e,drawDefinition:r,matchUpStatus:n,removeScore:o,matchUpsMap:i,matchUpId:s,event:a}){var l,c;const u=lt({drawDefinition:r,event:a,matchUpId:s});if(u.error)return u;if(!u.matchUp)return{error:ir};const{matchUp:p,structure:d}=u;if(!p.tieMatchUps)return{error:tn};const{extension:v}=xr({name:fa,element:p});if(v!=null&&v.value)if(o)yn({element:p,name:fa});else return Cy(Sv({},V),{score:p.score});const f=(l=vr({drawDefinition:r,structure:d,matchUp:p,event:a}))==null?void 0:l.tieFormat;p.tieFormat=Nn(f);const m=tc({drawDefinition:r,matchUpsMap:i,structure:d,matchUp:p,event:a}),{winningSide:h,set:g,scoreStringSide1:_,scoreStringSide2:I}=m,P=(g==null?void 0:g.side1Score)||(g==null?void 0:g.side2Score);if(e&&!p.score&&!P)return Sv({},V);const y={scoreStringSide1:_,scoreStringSide2:I,sets:g?[g]:[]},S=h&&[1,2].includes(h),O=S&&Mt||fv({matchUpStatus:n??p.matchUpStatus,tieMatchUps:p.tieMatchUps,winningSide:p.winningSide,score:y})&&Vn||Ft,b=!!(p.winningSide&&!S),w=p.tieMatchUps.find(({score:$,winningSide:N,matchUpStatus:E})=>{var A;return((A=$==null?void 0:$.sets)==null?void 0:A.length)&&($.sets[0].side1Score||$.sets[0].side2Score)||E&&Yt.includes(E)||N});let T;if(p.tieFormat&&!S&&!w){const $=(c=vr({drawDefinition:r,structure:d,event:a}))==null?void 0:c.tieFormat;$&&JSON.stringify(f)===JSON.stringify($)&&(p.tieFormatId=void 0,p.tieFormat=void 0,T=!0)}return Kn({matchUpStatus:O,score:y,removeWinningSide:b,tournamentRecord:t,drawDefinition:r,removeScore:o,winningSide:h,matchUpId:s,matchUp:p,event:a}),Cy(Sv({},V),{score:y,removeWinningSide:b,tieFormatRemoved:T,winningSide:h})}function po(t){const{winnerFirst:e=!0,addOutcomeString:r,reversed:n=!1,matchUpStatus:o,matchUpFormat:i,autoComplete:s,winningSide:a,sets:l}=t;if(!l)return{error:_e,info:"missing sets"};const c=i&&Pr(i),{bestOf:u,finalSetFormat:p,setFormat:d}=c||{},f=n||!(!e||!a||a===1),m=r?A3({matchUpStatus:o}):"",h=(l==null?void 0:l.sort(C3).map(g).filter(Boolean).join(" "))||"";if(!m)return h;if(a===2)return`${m} ${h}`;return`${h} ${m}`;function g(_){const P=u&&_.setNumber===u&&p?p:d,y=R=>Ct(R==null?void 0:R.side1Score)||Ct(R==null?void 0:R.side2Score),S=R=>Ct(R==null?void 0:R.side1TiebreakScore)||Ct(R==null?void 0:R.side2TiebreakScore),O=(P==null?void 0:P.tiebreakSet)||!y(_)&&S(_),{side1Score:b,side2Score:w,side1TiebreakScore:T,side2TiebreakScore:$}=_,N=T||(Ct(T)||s?0:""),E=$||(Ct($)||s?0:"");if(O)return`[${(f?[E,N]:[N,E]).join("-")}]`;const A=Math.min(N,E),U=A?`(${A})`:"",C=b||(Ct(b)||s?0:""),M=w||(Ct(w)||s?0:"");let D=f?`${[M,C].join("-")}${U}`:`${[C,M].join("-")}${U}`;return["-"," "].includes(D)&&(D=""),D}}function A3({matchUpStatus:t}){const e={[_r]:"RET",[ot]:"WO",[tr]:"DF/DF",[Rt]:"WO/WO",[Oi]:"SUS",[Wr]:"ABN",[Xe]:"DEF",[bl]:"DR"};return t&&e[t]||""}function C3(t,e){return t.setNumber-e.setNumber}function M3({existingMatchUpStatus:t,matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}){const i=(o==null?void 0:o.sets)||[],a=((i==null?void 0:i.filter(S=>S==null?void 0:S.winningSide))||[]).reduce((S,O)=>{const{winningSide:b}=O;if(!b)return S;const w=b-1;return S[w]++,S},[0,0]),l=n?n-1:void 0,c=l!==void 0?1-l:void 0,u=l!==void 0&&a[l],p=c!==void 0&&a[c],d=e?Pr(e):void 0,v=Math.max(...a),f=Nr(a)[v],m=d==null?void 0:d.bestOf,h=m&&Math.ceil(m/2)||1,g=r||t,_=g&&[Xe,_r,ot].includes(g),I=!d||!i.length||i.every((S,O)=>{const b=O+1,w=b===m,T=b===i.length,{side1Score:$,side2Score:N,side1TiebreakScore:E,side2TiebreakScore:A,winningSide:U}=S,C=Math.max($||0,N||0),M=E||A,{finalSetFormat:D,setFormat:R}=d,j=w&&D||R;if(M){const{tiebreakTo:W,NoAD:q}=(j==null?void 0:j.tiebreakFormat)||{},F=Math.max(E||0,A||0);if(q&&F>W||F<W&&U&&(T&&!_||!T))return!1}return j.setTo?!(!j.noTiebreak&&C>j.setTo+1):!0}),P=(!e||v===h)&&f===1&&a.indexOf(v)+1||void 0;return{valid:I&&(n&&u>p&&n===P||!n&&!P||_)}}function Ov({existingMatchUpStatus:t,matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}){if(typeof o!="object")return{error:X};const{sets:i,scoreStringSide1:s,scoreStringSide2:a}=o,l="scoreString must be a string!";if(s!==void 0&&typeof s!="string")return{error:X,info:l};if(a!==void 0&&typeof a!="string")return{error:X,info:l};if(i!==void 0&&!Array.isArray(i))return{error:X,info:or("sets")};if(i!=null&&i.length){const c=i.map(p=>p==null?void 0:p.setNumber).filter(Boolean);if(c.length!==We(c).length)return{error:X,info:"setNumbers not unique"};for(const p of i){const{side1Score:d,side2Score:v,side1TiebreakScore:f,side2TiebreakScore:m,side1PointScore:h,side2PointScore:g,winningSide:_,setNumber:I}=p;if(![[d,v],[f,m],[h,g]].filter(S=>S.some(O=>O!==void 0)).every(S=>S.every(O=>ht(O))))return{error:X,info:"non-numeric values"};if(![I,_].filter(S=>S!==void 0).every(S=>ht(S)))return{error:X,info:"non-numeric values"};if(_&&![1,2].includes(_))return{error:X,info:"winningSide must be 1 or 2"}}const{valid:u}=M3({existingMatchUpStatus:t,matchUpStatus:r,matchUpFormat:e,winningSide:n,score:o});if(!u)return{error:Sx,info:"score is invalid for matchUpFormat or winningSide does not match calculated winningSide"}}return{valid:!0}}function bv({analysis:t,set:e}){const r=Tv({set:e}),{isDecidingSet:n,isTiebreakSet:o,matchUpScoringFormat:i}=t;return My({matchUpScoringFormat:i,isDecidingSet:n,isTiebreakSet:o,set:e})&&r}function My(t){let e=t.matchUpScoringFormat;const{ignoreTiebreak:r=!1,matchUpFormat:n,isTiebreakSet:o,isDecidingSet:i,set:s}=t;if(!s)return{error:_e};e=e||n;const a=i&&e.finalSetFormat||(e==null?void 0:e.setFormat)||{},{side1Score:l,side2Score:c}=s,{NoAD:u,setTo:p,tiebreakAt:d,tiebreakFormat:v}=a,f=v==null?void 0:v.NoAd,m=Tv({set:s}),h=Math.abs(l-c),g=l>=p||c>=p,_=o||l>=p&&c>=p||d&&d<p&&(l===d||c===d),I=r||_&&(m===1&&s.side1TiebreakScore>s.side2TiebreakScore||m===2&&s.side2TiebreakScore>s.side1TiebreakScore),y=h>=(u||_&&(d&&!o||o&&f)?1:2);return(g&&(y||_)||o)&&(!_||I)}function Tv({set:t}){if(t.side1Score||t.side2Score){if(t.side1Score>t.side2Score)return 1;if(t.side2Score>t.side1Score)return 2}else if(t.side1TiebreakScore||t.side2TiebreakScore){if(t.side1TiebreakScore>t.side2TiebreakScore)return 1;if(t.side2TiebreakScore>t.side1TiebreakScore)return 2}}const Es=" ",wv="DEF",D3="COMPLETED",Dy="WO",j3="WO/WO",jy="ABN",Ry="SUS",Fy="RET",xy="INT",Ly=[Fy,wv,Dy,j3,jy,Ry,xy],Ev="DEFAULTED",Vy="WALKOVER",By="ABANDONED",ky="SUSPENDED",Gy="RETIRED",Wy="INTERRUPTED",R3=[Gy,Ev,Vy],$s="()",Bi="[]",F3=["up","left","shift+tab"],x3=["enter","down","tab","right"],Wu="backspace",Hy="r",qy="s",zy="a",Yy="d",Ky="w",Qy="i",$v=[Hy,Yy,Ky,zy,qy,Qy],Hu="space",Nv=["[","("],qu=[...F3,...x3,Hu,"]"],Jy="-",L3="/",Ns=Jy,fo=Jy,Zy=[L3],V3=0,Xy=["0","1","2","3","4","5","6","7","8","9"].concat($v),B3=Xy.map(t=>`shift+${t}`),k3=[Ns,Wu].concat(qu,Zy),G3=[Xy,B3,k3].join(",");function W3({analysis:t,scoreString:e,sets:r,value:n}){let o;if(!(r!=null&&r.length))return{sets:[]};const i=r[r.length-1];n=Te(n);const{validSide2Score:s,requiresTiebreak:a}=H3({analysis:t,set:i,value:n});if(s){o=!0,e=(e||"")+n,i.side2Score=n;const l=bv({analysis:t,set:r[r.length-1]});if(i.winningSide=l||void 0,a){const c=$s.split("")[0];e+=c}else t.isDecidingSet||(e+=Es)}return{sets:r,scoreString:e,updated:o}}function H3({analysis:t,set:e={},value:r}){const n=t.isDecidingSet&&t.matchUpScoringFormat.finalSetFormat||t.matchUpScoringFormat.setFormat,{tiebreakAt:o,setTo:i,NoAD:s}=n,{side1Score:a}=e;let l,c;return o&&o<i?a===o?l=r<=i:l=r<=o:a===i?s?l=r<i:l=r<=i+1:a===i-1?s?l=r<=i:l=r<=i+1:a===i+1?l=r===i||r===i-1:l=r<=i,l&&(o&&o<i?c=a===i&&r===o||a===o&&r===i:c=a>=i&&r>=i&&a!==r),{validSide2Score:l,requiresTiebreak:c}}function ba({scoreString:t,lowSide:e,outcome:r}){if({scoreString:t}=e0({scoreString:t}),e===2){const o=(t&&t[t.length-1])!==Es?Es:"";return t+o+r}else return r+Es+t}function e0({scoreString:t}){if(!t)return{scoreString:""};let e=!1;for(const r of Ly){const n=t==null?void 0:t.indexOf(r);n===0?t=t.slice(r.length+1).trim()+Es:n>0&&(t=t.slice(0,n)),n>=0&&(e=!0)}return t!=null&&t.trim()||(t=""),{scoreString:t,removed:e}}function Uv({analysis:t,scoreString:e,sets:r,lowSide:n}){var o,i,s;let a,l;if(!e)return{scoreString:e,sets:r};const{scoreString:c,removed:u}=e0({scoreString:e});if(e=c,u)return{scoreString:e,sets:r,outcomeRemoved:!0};let p=r[r.length-1]||{};const d=Object.values(p).filter(_=>_!==void 0).length;p.setNumber&&d===1&&(r=r.slice(0,r.length-1),p=r[r.length-1]||{});const{tiebreakSet:v}=t.setFormat,{tiebreakTo:f,NoAD:m}=v||{},{isTiebreakEntry:h}=Ta({brackets:Bi,scoreString:e}),g=z3(e);if(g>=0){a=e.slice(0,g);const{isTiebreakEntry:_}=Ta({brackets:$s,scoreString:a}),{lastOpenBracketIndex:I,isTiebreakEntry:P}=Ta({brackets:Bi,scoreString:a}),y=a&&a[a.length-1].trim(),S=a&&!isNaN(y);let O=t.isIncompleteSetScore;if(h&&P){const w=a.slice(I+1).split(fo),T=(w==null?void 0:w.length)>0&&w[0]!==void 0&&!isNaN(parseInt(w[0]))&&parseInt(w[0])||void 0,$=(w==null?void 0:w.length)>1&&w[1]!==void 0&&parseInt(w[1])||void 0,N=[T,$];if($){const E=n===1?1:0;N[E]=((N==null?void 0:N[1-E])||0)+(m?1:2),(N[E]||0)<f&&(N[E]=f),a=e.slice(0,I+1),a+=N.join(fo)}else T!==void 0?(a=e.slice(0,I+1),a+=T):(a=e.slice(0,I),O=!0);p.side1TiebreakScore=N[0]||0,p.side2TiebreakScore=N[1]||0}if(a.length||(a=void 0),O){const b=(o=p.side1Score)==null?void 0:o.toString();if(b){const w=b==null?void 0:b.slice(0,b.length-1);p.side1Score=!isNaN(w)&&parseInt(w)||void 0,p.side1Score===void 0&&(p.side2Score=void 0)}t.isTimedSet?(l=p.side1Score?r:(r==null?void 0:r.slice(0,r.length-1))||[],l[r.length-1]=p):l=(r==null?void 0:r.slice(0,r.length-1))||[]}else if(S){const b=(i=p.side2Score)==null?void 0:i.toString(),w=(s=p.side1Score)==null?void 0:s.toString();if(!t.isTiebreakEntry&&!t.isMatchTiebreak)if(p.side2Score){const T=b==null?void 0:b.slice(0,b.length-1);p.side2Score=!isNaN(T)&&parseInt(T)||void 0}else{const T=w==null?void 0:w.slice(0,w.length-1);p.side1Score=!isNaN(T)&&parseInt(T)||void 0}t.isTimedSet?p.side1Score?(l=r||[],l[r.length-1]=p):l=(r==null?void 0:r.slice(0,r.length-1))||[]:(l=r||[],l[r.length-1]=p),l[l.length-1]&&Object.assign(l[l.length-1],{winningSide:void 0})}else _?(l=r||[],Object.assign(l[l.length-1]||{},{winningSide:void 0,side1TiebreakScore:void 0,side2TiebreakScore:void 0})):(h&&!P?l=(r==null?void 0:r.slice(0,r.length-1))||[]:(l=r,l[r.length-1]=p),h||(l[l.length-1].side2Score=0,l[l.length-1].winningSide=void 0));return{scoreString:a,sets:l}}return{scoreString:e,sets:r}}function Ta({brackets:t=$s,scoreString:e}){if(!e)return{};const[r,n]=t.split(""),o=e.split(""),i=Math.max(...Dn(r,o)),s=Math.max(...Dn(n,o));return{isTiebreakEntry:i>s,lastOpenBracketIndex:i}}function q3({scoreString:t}){if(!t)return!1;const e=t&&t[t.length-1].trim(),r=t&&!isNaN(e),[n,o]=Bi.split(""),i=t.split(""),s=Math.max(...Dn(n,i)),a=Math.max(...Dn(o,i)),l=Math.max(...Dn(fo,i));return r&&s>a&&l>s}function z3(t){return t.split("").reduce((n,o,i)=>(o.match(/\d+/g)&&n.push(i),n),[]).pop()}function t0(t){const{lowValue:e=0,NoAD:r=!1,tiebreakTo:n}=t||{},o=r?1:2;return e+1>=n?e+o:parseInt(n)}function r0({matchUpFormat:t,matchUpStatus:e,winningSide:r,sets:n}){const o=Pr(t),{bestOf:i}=o,s=Math.ceil(i/2),a=n==null?void 0:n.reduce((c,u)=>{const{winningSide:p}=u;return p&&c[p-1]++,c},[0,0]);let l=(a==null?void 0:a.indexOf(s))+1||void 0;return R3.includes(e)&&r&&(l=r),{matchUpWinningSide:l}}function n0({lowSide:t,value:e,sets:r,scoreString:n,winningSide:o,matchUpStatus:i}){let s;return e===Hy?n?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:Fy}),o=t===2?1:2,i=Gy):(s=!0,n=ba({scoreString:n,lowSide:t,outcome:wv}),o=t===2?1:2,i=Ev):e===Yy?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:wv}),o=t===2?1:2,i=Ev):e===Ky?(s=!0,r=[],n=Dy,o=t===2?1:2,i=Vy):e===qy&&n?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:Ry}),i=ky,o=void 0):e===zy?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:jy}),i=By,o=void 0):e===Qy&&n&&(s=!0,n=ba({scoreString:n,lowSide:t,outcome:xy}),i=Wy,o=void 0),{updated:s,sets:r,scoreString:n,matchUpStatus:i,winningSide:o}}function Y3(t){let{sets:e,info:r,scoreString:n,winningSide:o,matchUpStatus:i}=t;const{analysis:s,lowSide:a,value:l}=t;let c,u;!(e!=null&&e.length)&&l!==Wu&&(e=[{setNumber:1}]);const p=e.length-1;if($v.includes(l)){const d=e[e.length-1]||{},{side1Score:v,side2Score:f}=d;v&&!f?r="missing side2Score":s.finalSetIsComplete||o?r="final set is already complete":s.isIncompleteSetScore?r="incomplete set scoreString":s.isIncompleteSetScore||({sets:e,scoreString:n,winningSide:o,matchUpStatus:i,updated:c}=n0({lowSide:a,value:l,sets:e,scoreString:n,matchUpStatus:i,winningSide:o}))}else if(l===Wu){if({scoreString:n,sets:e,outcomeRemoved:u}=Uv({analysis:s,scoreString:n,sets:e}),(n==null?void 0:n.trim())===""&&(n=n.trim()),n||(e=[]),u){const d=e[e.length-1]||{},{side1Score:v,side2Score:f}=d;if(v&&f){const m=v>f&&1||f>v&&2||void 0;m&&(d.winningSide=m,e.push({setNumber:e.length+1}))}}i=void 0,o=void 0,c=!0}else if(s.hasOutcome)r="has outcome";else{if(o)return{sets:e,scoreString:n,winningSide:o,matchUpStatus:i,updated:!1,info:"matchUp is complete"};if(l===Hu){const d=e[e.length-1]||{},{side1Score:v,side2Score:f}=d,m=v>f&&1||f>v&&2||void 0;m&&!o&&!s.isIncompleteSetScore&&(e[e.length-1].winningSide=m,e.push({setNumber:e.length+1}),n+=" ",c=!0)}else if(l===Ns&&e[p].side1Score!==void 0&&e[p].side2Score===void 0&&n&&s.isNumericEnding)n+="-",e[p].side2Score=0,i=void 0,o=void 0,c=!0;else if(!isNaN(l)){let d;if(e[p].side2Score===void 0){const v=Te((e[p].side1Score||0).toString()+l).toString().slice(0,2);e[p].side1Score=Te(v),d=e[p].side1Score.toString(),c=!0}else{const v=Te((e[p].side2Score||0).toString()+l).toString().slice(0,2);e[p].side2Score=Te(v),d=[e[p].side1Score,e[p].side2Score].join("-"),c=!0}if(c){const v=(e.slice(0,p)||[]).filter(f=>f).map(f=>{const{side1Score:m,side2Score:h}=f;return[m,h].join("-")}).join(" ");v?n=v+" "+d:n=d}}}return{sets:e,scoreString:n,winningSide:o,matchUpStatus:i,info:r,updated:c}}function K3({analysis:t,auto:e,lowSide:r,scoreString:n="",sets:o,value:i}){var s;let a,l;const{tiebreakSet:{tiebreakTo:c,NoAD:u}}=t.setFormat,[p]=Bi.split("");if(t.isMatchTiebreakEntry||(n+=p),o[t.setNumber-1]){const{lastOpenBracketIndex:v}=Ta({brackets:Bi,scoreString:n}),m=(n.slice((v??0)+1)+(e?"":i)).split(fo);if((((s=m[r-1])==null?void 0:s.length)||0)>=2)l="tiebreak digit limit";else if(e){r===1&&(m[0]=(m[0]||"")+i),r===2&&(m[1]=(m[1]||"")+i);const g=[m[0]||0,m[1]||0].map(P=>Te(P)),_=r===1?1:0;g[_]=g[1-_]+(u?1:2),g[_]<c&&(g[_]=c);const I=o[o.length-1];I.side1TiebreakScore=g[0],I.side2TiebreakScore=g[1],n=n.slice(0,(v??0)+1),n+=g.join(fo),a=!0}else{const g=[m[0]||0,m[1]||0].map(I=>Te(I)),_=o[o.length-1];_.side1TiebreakScore=g[0],_.side2TiebreakScore=g[1],n+=i,a=!0}}else{const v=t0({lowValue:Te(i||0),tiebreakTo:c,NoAD:u}),f=[Te(i),v];r===2&&f.reverse();const m={side1TiebreakScore:f[0],side2TiebreakScore:f[1],setNumber:(o==null?void 0:o.length)+1||1};o.push(m),n+=f.join(fo),a=!0}return{info:l,scoreString:n,sets:o,updated:a}}function Q3({analysis:t,lowSide:e,scoreString:r,value:n}){const{setTo:o,tiebreakAt:i,NoAD:s}=(t==null?void 0:t.setFormat)||{},a=n===parseInt(i||o);if(i&&i<o&&n>i)return{scoreString:r};if(s&&n===o||n>o)return{scoreString:r};const l=m(),c=[n,l];e===2&&c.reverse();const p=$s.split("")[0],d=c.join(Ns)+(a?p:Es);r=(r||"")+d;const v={side1Score:c[0],side2Score:c[1]},f=bv({analysis:t,set:v});return v.winningSide=f||void 0,{scoreString:r,set:v};function m(){return a?n+1:n+1===o?n+(s?1:2):o}}function J3({matchUpFormat:t,scoreString:e,winningSide:r,value:n,sets:o}){var i,s,a;const c=(((i=o==null?void 0:o.filter(x=>x==null?void 0:x.winningSide))==null?void 0:i.length)||0)+(r?0:1),u=Pr(t),p=c===(u==null?void 0:u.bestOf),d=p&&(u==null?void 0:u.finalSetFormat)||(u==null?void 0:u.setFormat)||{},v=(d==null?void 0:d.timed)||(u==null?void 0:u.timed),f=p&&o[(u==null?void 0:u.bestOf)-1],m=f==null?void 0:f.winningSide,{isTiebreakEntry:h}=Ta({brackets:$s,scoreString:e}),{isTiebreakEntry:g}=Ta({brackets:Bi,scoreString:e}),_=h||g,I=!!d.tiebreakSet,P=(s=e==null?void 0:e[e.length-1])==null?void 0:s.trim(),y=e&&!isNaN(P),S=!_&&P===Ns,O=h&&Nv.includes(P),b=g&&Nv.includes(P),w=g&&P===fo,T=e==null?void 0:e.split(""),[$]=Bi.split(""),N=T&&Math.max(...Dn($,T)),E=T&&Math.max(...Dn(fo,T)),A=T&&E>N,U=(a=o[o.length-1])==null?void 0:a.winningSide,C=(o==null?void 0:o.length)&&!U,M=Ly.find(x=>(e==null?void 0:e.indexOf(x))>=0),D=!isNaN(n),R=n===Hu,j=qu.includes(n),G=e==null?void 0:e.split("").find(x=>Nv.includes(x)),W=j&&g&&!b&&(w||!q3({scoreString:e}));return{isTiebreakSetValue:I&&D,matchUpScoringFormat:u,setNumber:c,setFormat:d,matchTiebreakHasJoiner:A,isGameScoreEntry:C,isSpace:R,isCloser:j,isTiebreakCloser:j&&G&&_&&y,isDecidingSet:p,isTiebreakSet:I,isTimedSet:v,isNumericEnding:y,isNumericValue:D,hasOpener:G,hasOutcome:M,finalSet:f,finalSetIsComplete:m,lastSetIsComplete:U,isInvalidSetTiebreakValue:R&&_&&O,isInvalidMatchTiebreakValue:W,isTiebreakEntry:_,isSetTiebreakEntry:h,isMatchTiebreakEntry:g,isIncompleteSetScore:S,isIncompleteSetTiebreak:O,isIncompleteMatchTiebreak:b,isPartialMatchTiebreakValue:w}}function Z3(t){let{lowSide:e=1,value:r}=t,{scoreString:n,sets:o,winningSide:i,matchUpStatus:s}=t;const{matchUpFormat:a,shiftFirst:l,auto:c=!0}=t;let u,p;const d=l&&e===2||!l&&e===1;if(!G3.includes(r))return{updated:!1,info:"invalid key"};l&&(e=3-e);const{matchUpWinningSide:v}=r0({sets:o,winningSide:i,matchUpStatus:s,matchUpFormat:a});i=v;const f=J3({value:r,winningSide:i,scoreString:n,sets:o,matchUpFormat:a});if(Zy.includes(r)&&(r=Ns),f.hasOpener&&f.isTiebreakEntry&&!f.isTiebreakSet&&d&&Te(r)===0&&(f.isTiebreakCloser=!0),qu.includes(r)&&f.hasOpener&&(r=""),qu.includes(r)&&(r=Hu),f.lastSetIsComplete){const m=(n==null?void 0:n.length)&&n[n.length-1];n&&m!==" "&&(n+=" ")}if(f.isTimedSet)({info:p,sets:o,scoreString:n,updated:u,matchUpStatus:s,winningSide:i}=Y3({analysis:f,lowSide:e,scoreString:n,sets:o,matchUpStatus:s,winningSide:i,value:r}));else if($v.includes(r))f.finalSetIsComplete||i?p="final set is already complete":!f.isTiebreakEntry&&!f.isIncompleteSetScore?{sets:o,scoreString:n,matchUpStatus:s,winningSide:i,updated:u}=n0({lowSide:e,sets:o,scoreString:n,matchUpStatus:s,winningSide:i,value:r}):f.isTiebreakEntry||f.isIncompleteSetScore?p="incomplete set scoreString or tiebreak entry":console.log("handle case",{value:r});else if(r===Wu)u=!0,{scoreString:n,sets:o}=Uv({analysis:f,scoreString:n,sets:o,lowSide:e}),n||(o=[]),s=void 0,i=void 0;else if(f.hasOutcome)p="has outcome";else if(r===Ns&&!f.isMatchTiebreakEntry)(!f.isSetTiebreakEntry||f.isSetTiebreakEntry&&!f.isNumericEnding)&&(u=!0,{scoreString:n,sets:o}=Uv({analysis:f,scoreString:n,sets:o,lowSide:e}),s=void 0);else if(r===fo&&f.isMatchTiebreakEntry&&!f.isSetTiebreakEntry)f.matchTiebreakHasJoiner?p="existing joiner":f.isNumericEnding&&(u=!0,n+=fo);else if([Ns,fo].includes(r))p="invalid location for joiner";else{if(i)return{updated:!1,info:"matchUp is complete"};if(f.isIncompleteSetScore)f.isNumericValue&&({sets:o,scoreString:n,updated:u}=W3({analysis:f,scoreString:n,sets:o,value:r}));else if(f.isInvalidMatchTiebreakValue)p="invalid matchUp tiebreak character";else if(f.isInvalidSetTiebreakValue)p="invalid set tiebreak character";else if(f.isTiebreakCloser){const m=f.isSetTiebreakEntry?$s:Bi,h=m.split("").reverse()[0],g=m.split("")[0],_=o[o.length-1],{tiebreakFormat:I}=f.setFormat,{tiebreakTo:P,NoAD:y}=I||{},S=Tv({set:_});if(!f.isTiebreakSet){const b=parseInt(n.split(g).reverse()[0]),w=t0({lowValue:b,tiebreakTo:P,NoAD:y});S===1?(_.side1TiebreakScore=w,_.side2TiebreakScore=b):(_.side1TiebreakScore=b,_.side2TiebreakScore=w)}n=(n||"")+h,f.isDecidingSet||(n+=Es);const O=bv({analysis:f,set:_});_.winningSide=O||void 0,u=!0}else if(f.isTiebreakSetValue)({info:p,scoreString:n,sets:o,updated:u}=K3({analysis:f,auto:c,lowSide:e,scoreString:n,sets:o,value:r}));else if(f.isSetTiebreakEntry){const[m]=$s.split(""),h=Math.max(...Dn(m,n.split(""))),g=n.slice(h+1),_=g&&Te(g)===V3,I=Te(g?g+r:r),{tiebreakFormat:P}=f.setFormat,{tiebreakTo:y,NoAD:S}=P||{};!_&&g.length<2?S&&I>y-1?p="invalid low value for NoAD tiebreak":(u=!0,n=(n||"")+r):p=_?"tiebreak begins with zero":"tiebreak digit limit"}else if(f.isCloser)p=`invalid key: ${r}`;else if(f.isGameScoreEntry)p="game scoreString entry";else if(f.lastSetIsComplete||!o.length){u=!0;const{scoreString:m,set:h}=Q3({analysis:f,lowSide:e,scoreString:n,value:Te(r)});h&&(h.setNumber=(o==null?void 0:o.length)+1||1),o=(o==null?void 0:o.concat(h).filter(Boolean))||[h],n=m||void 0}else console.log("error: unknown outcome")}if(u){o=o==null?void 0:o.filter(Boolean);const{matchUpWinningSide:m}=r0({sets:o,winningSide:i,matchUpStatus:s,matchUpFormat:a});return i=m,m&&(!s||[Ft,so].includes(s))?(s=D3,o=o.filter(h=>{const{side1Score:g,side2Score:_,side1TiebreakScore:I,side2TiebreakScore:P}=h;return g||_||I||P})):n&&!i&&![ky,By,Wy].includes(s)&&(s=void 0),{updated:u,scoreString:n,sets:o,winningSide:i,matchUpStatus:s,info:p}}return{updated:u,scoreString:n,sets:o,winningSide:i,matchUpStatus:s,info:p}}function X3({matchUpScoringFormat:t,isDecidingSet:e,isTiebreakSet:r,setObject:n}){if(!n)return;const o=o0({set:n});return eW({matchUpScoringFormat:t,isDecidingSet:e,isTiebreakSet:r,set:n})&&o||void 0}function eW({ignoreTiebreak:t=!1,matchUpScoringFormat:e,matchUpFormat:r,isTiebreakSet:n,isDecidingSet:o,set:i}){if(!i)return{error:_e,info:"missing set"};e=e||r&&Pr(r);const s=o&&e.finalSetFormat||(e==null?void 0:e.setFormat)||{},{side1Score:a,side2Score:l}=i,{setTo:c,tiebreakAt:u,tiebreakFormat:p}=s,d=p==null?void 0:p.NoAd,v=o0({set:i}),f=Math.abs(a-l),m=a>=c||l>=c,h=n||a>=c&&l>=c||u&&u<c&&(a===u||l===u),g=t||h&&(v===1&&i.side1TiebreakScore>i.side2TiebreakScore||v===2&&i.side2TiebreakScore>i.side1TiebreakScore),I=f>=(h&&(u&&!n||n&&d)?1:2);return(m&&(I||h)||n)&&(!h||g)}function o0({set:t}){if(t.side1Score||t.side2Score){if(t.side1Score>t.side2Score)return 1;if(t.side2Score>t.side1Score)return 2}else if(t.side1TiebreakScore||t.side2TiebreakScore){if(t.side1TiebreakScore>t.side2TiebreakScore)return 1;if(t.side2TiebreakScore>t.side1TiebreakScore)return 2}}function zu(t){const{setObject:e,matchUpScoringFormat:r}=t;if(!e)return{error:of};const{setNumber:n}=e||{},{bestOf:o}=r||{},i=!!(n&&o&&n===o),s=i&&(r==null?void 0:r.finalSetFormat)||(r==null?void 0:r.setFormat),a=!!(s!=null&&s.tiebreakSet),l=!!(s!=null&&s.timed),c=!a&&!l,u=!!(n&&o&&n<=o),p=[e==null?void 0:e.side1Score,e==null?void 0:e.side2Score],d=[e==null?void 0:e.side1PointScore,e==null?void 0:e.side2PointScore],v=[e==null?void 0:e.side1TiebreakScore,e==null?void 0:e.side2TiebreakScore],f=p.filter(C=>C!==void 0).length,m=d.filter(C=>C!==void 0).length,h=v.filter(C=>C!==void 0).length,g=p==null?void 0:p.filter(C=>!isNaN(C)).length,_=v==null?void 0:v.filter(C=>!isNaN(C)).length,{tiebreakAt:I}=s||{},P=I&&p.filter(C=>C>=I).length===2,y=P&&(p[0]>p[1]&&1||p[1]>p[0]&&2||void 0),S=!!(_&&!g),O=!!(e!=null&&e.winningSide),{error:b,result:w}=tW({setObject:e,setFormat:s,sideGameScores:p,sideTiebreakScores:v}),{error:T,result:$}=rW({setObject:e,setFormat:s,sideTiebreakScores:v}),N=c&&!S&&w||a&&S&&$,E=u&&!(a&&!S)&&!(c&&S)&&(!O||N),A=X3({isDecidingSet:i,isTiebreakSet:S,matchUpScoringFormat:r,setObject:e}),U={expectTiebreakSet:a,expectTimedSet:l,hasTiebreakCondition:P,isCompletedSet:O,isDecidingSet:i,isTiebreakSet:S,isValidSet:E,isValidSetNumber:u,isValidSetOutcome:N,leadingSide:y,setFormat:s,sideGameScores:p,sideGameScoresCount:f,sidePointScores:d,sidePointScoresCount:m,sideTiebreakScores:v,sideTiebreakScoresCount:h,winningSide:A};return(e==null?void 0:e.winningSide)!==void 0&&(S?(U.isValidTiebreakSetOutcome=$,$||(U.tiebreakSetError=T)):(U.isValidStandardSetOutcome=w,w||(U.standardSetError=b))),U}function tW({setObject:t,setFormat:e,sideGameScores:r,sideTiebreakScores:n}){if(!t)return{result:!1,error:of};const o=!!(e!=null&&e.tiebreakSet),i=!!(e!=null&&e.timed);if(!e||o||i)return{result:!1,error:X};if(!((r==null?void 0:r.filter($=>!isNaN($)).length)===2))return{result:!1,error:o_};const{setTo:a,tiebreakAt:l,tiebreakFormat:c,NoAD:u}=e||{};if(!!!(a&&(r!=null&&r.find($=>$>=a))))return{result:!1,error:o_};const d=[1,2].includes(t==null?void 0:t.winningSide);if(!t||!d)return{result:!1,error:i_};const v=(t==null?void 0:t.winningSide)-1,f=1-v,m=r[v],h=r[f],g=m-h;if(!(m>h))return{result:!1,error:{message:"winningSide game scoreString is not high"}};const I=l&&c,P=(n==null?void 0:n.filter($=>!isNaN($)).length)===2,y=n==null?void 0:n[v],S=n==null?void 0:n[f],O=l&&r.filter($=>$>=l).length===2;if(I){const{NoAD:$,tiebreakTo:N}=c;if(O){if(g>1)return{result:!1,error:{message:"invalid winning game scoreString (5)"}};if(!P)return{result:!1,error:{message:"invalid tiebreak scores (1)"}};if(isNaN(N))return{result:!1,error:{message:"tiebreakTo error"}};if(!!!(N&&(n!=null&&n.find(j=>j>=N))))return{result:!1,error:{message:"invalid tiebreak scores (2)"}};const U=l<a?a:a+1;if(m>U)return{result:!1,error:{message:"invalid winning game scoreString (1)"}};if(!y||!S||y<S)return{result:!1,error:{message:"winningSide tiebreak value is not high"}};const C=$?1:2,M=y-S,D=S>=N-1;if(M&&D&&M<C)return{result:!1,error:{message:"invalid tiebreak scores (3)"}}}if(m>a&&!O)return{result:!1,error:{message:"invalid winning game scoreString (2)"}}}const b=u?1:2,w=h>=a-1;return g&&w&&!O&&g<b?{result:!1,error:{message:"invalid winning game scoreString (3)"}}:g>b&&m>a?{result:!1,error:{message:"invalid winning game scoreString (4)"}}:{result:!0}}function rW({setObject:t,setFormat:e,sideTiebreakScores:r}){if(!t)return{result:!1,error:of};const n=!!(e!=null&&e.tiebreakSet),o=!!(e!=null&&e.timed);if(!e||!n||o)return{result:!1,error:{message:"not tiebreak set"}};const i=[1,2].includes(t==null?void 0:t.winningSide);if(!t||!i)return{result:!1,error:i_};const{tiebreakSet:s}=e||{},{NoAD:a,tiebreakTo:l}=s||{};if(!((r==null?void 0:r.filter(I=>!isNaN(I)).length)===2))return{result:!1,error:{message:"invalid tiebreak scores (1)"}};if(isNaN(l))return{result:!1,error:{message:"tiebreakTo error"}};if(!!!(r!=null&&r.find(I=>I>=l)))return{result:!1,error:{message:"invalid tiebreak scores (2)"}};const p=(t==null?void 0:t.winningSide)-1,d=1-p,v=r[p],f=r[d];if(!v||!f||v<f)return{result:!1,error:{message:"winningSide tiebreak value is not high"}};const m=a?1:2,h=v-f,g=f>=l-1;return h&&g&&h<m?{result:!1,error:{message:"invalid tiebreak scores (3)"}}:{result:!0}}var nW=Object.defineProperty,i0=Object.getOwnPropertySymbols,oW=Object.prototype.hasOwnProperty,iW=Object.prototype.propertyIsEnumerable,s0=(t,e,r)=>e in t?nW(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sW=(t,e)=>{for(var r in e||(e={}))oW.call(e,r)&&s0(t,r,e[r]);if(i0)for(var r of i0(e))iW.call(e,r)&&s0(t,r,e[r]);return t};function aW(t){if(!(t!=null&&t.score))return{error:_e};const{sets:e}=t.score,r=e.map(i=>{const{side1TiebreakScore:s,side2TiebreakScore:a,winningSide:l,side1Score:c,side2Score:u,setNumber:p}=i;return Oe({winningSide:l?3-l:void 0,side1TiebreakScore:a,side2TiebreakScore:s,side1Score:u,side2Score:c,setNumber:p})}),n=po({sets:r}),o=po({sets:r,reversed:!0});return sW({reversedScore:{sets:r,scoreStringSide1:n,scoreStringSide2:o}},V)}const a0=t=>{const{isSide1:e,lowValue:r,setTo:n,tiebreakAt:o,NoAD:i}=t;if(r===void 0)return!1;let s=Te(r);(s==null?void 0:s.toString().length)>2&&(s=parseInt(s.toString().slice(0,2))),o&&o<n&&s>o&&(s=o);let a;return i&&!o?a=s<n?n:n-1:a=s+1<n&&n||o&&o<n&&s===o&&n||!o&&s+2||n+1,[e?s:a,e?a:s]},Av=t=>{const{isSide1:e,lowValue:r,tiebreakTo:n,tiebreakNoAd:o}=t;if(r===void 0)return!1;let i=typeof r=="string"?parseInt(r):r;(i==null?void 0:i.toString().length)>2&&(i=parseInt(i.toString().slice(0,2))),o&&i>n-1&&(i=n-1);const s=lW({lowValue:i,NoAD:o,tiebreakTo:n});return[e?i:s,e?s:i]};function lW(t){const{lowValue:e,NoAD:r,tiebreakTo:n}=t,o=r?1:2;return e+1>=n?e+o:n}const l0={stringifyMatchUpFormat:Yp,isValidMatchUpFormat:Xr,parseMatchUpFormat:Pr,generateTieMatchUpScore:tc,getTiebreakComplement:Av,updateTieMatchUpScore:uo,generateScoreString:po,checkSetIsComplete:My,validateTieFormat:br,getSetComplement:a0,scoreHasValue:Gt,keyValueScore:Z3,validateScore:Ov,reverseScore:aW,analyzeSet:zu};function c0(t){return t&&typeof String.fromCodePoint<"u"?t.toUpperCase().replace(/./g,e=>String.fromCodePoint(e.charCodeAt(0)+127397)):t}function cW(t){const e=Object.assign({},...ii.filter(r=>r.ioc).map(r=>({[r.ioc]:r.iso})));return c0(e[t])}const ii=[{ioc:"",iso2:"",iso:"",label:"NONE",phone:""},{ioc:"AND",iso2:"AD",iso:"AND",label:"Andorra",phone:"376"},{ioc:"UAE",iso2:"AE",iso:"ARE",label:"United Arab Emirates",phone:"971"},{ioc:"AFG",iso2:"AF",iso:"AFG",label:"Afghanistan",phone:"93"},{ioc:"ANT",iso2:"AG",iso:"ATG",label:"Antigua and Barbuda",phone:"1-268"},{ioc:"AIA",iso2:"AI",iso:"AIA",label:"Anguilla",phone:"1-264"},{ioc:"ALB",iso2:"AL",iso:"ALB",label:"Albania",phone:"355"},{ioc:"ARM",iso2:"AM",iso:"ARM",label:"Armenia",phone:"374"},{ioc:"ANG",iso2:"AO",iso:"AGO",label:"Angola",phone:"244"},{ioc:"",iso2:"AQ",iso:"ATA",label:"Antarctica",phone:"672"},{ioc:"ARG",iso2:"AR",iso:"ARG",label:"Argentina",phone:"54"},{ioc:"ASA",iso2:"AS",iso:"ASM",label:"American Samoa",phone:"1-684"},{ioc:"AUT",iso2:"AT",iso:"AUT",label:"Austria",phone:"43"},{ioc:"AUS",iso2:"AU",iso:"AUS",label:"Australia",phone:"61",suggested:!0},{ioc:"ARU",iso2:"AW",iso:"ABW",label:"Aruba",phone:"297"},{ioc:"AZE",iso2:"AZ",iso:"AZE",label:"Azerbaijan",phone:"994"},{ioc:"BIH",iso2:"BA",iso:"BIH",label:"Bosnia and Herzegovina",phone:"387"},{ioc:"BAR",iso2:"BB",iso:"BRB",label:"Barbados",phone:"1-246"},{ioc:"BAN",iso2:"BD",iso:"BGD",label:"Bangladesh",phone:"880"},{ioc:"BEL",iso2:"BE",iso:"BEL",label:"Belgium",phone:"32"},{ioc:"BUR",iso2:"BF",iso:"BFA",label:"Burkina Faso",phone:"226"},{ioc:"BUL",iso2:"BG",iso:"BGR",label:"Bulgaria",phone:"359"},{ioc:"BRN",iso2:"BH",iso:"BHR",label:"Bahrain",phone:"973"},{ioc:"BDI",iso2:"BI",iso:"BDI",label:"Burundi",phone:"257"},{ioc:"BEN",iso2:"BJ",iso:"BEN",label:"Benin",phone:"229"},{ioc:"",iso2:"BL",iso:"BLM",label:"Saint Barthelemy",phone:"590"},{ioc:"BER",iso2:"BM",iso:"BMU",label:"Bermuda",phone:"1-441"},{ioc:"BRU",iso2:"BN",iso:"BRN",label:"Brunei Darussalam",phone:"673"},{ioc:"BOL",iso2:"BO",iso:"BOL",label:"Bolivia",phone:"591"},{ioc:"BRA",iso2:"BR",iso:"BRA",label:"Brazil",phone:"55"},{ioc:"BAH",iso2:"BS",iso:"BHS",label:"Bahamas",phone:"1-242"},{ioc:"BHU",iso2:"BT",iso:"BTN",label:"Bhutan",phone:"975"},{ioc:"",iso2:"BV",iso:"BVT",label:"Bouvet Island",phone:"47"},{ioc:"BOT",iso2:"BW",iso:"BWA",label:"Botswana",phone:"267"},{ioc:"BLR",iso2:"BY",iso:"BLR",label:"Belarus",phone:"375"},{ioc:"BIZ",iso2:"BZ",iso:"BLZ",label:"Belize",phone:"501"},{ioc:"CAN",iso2:"CA",iso:"CAN",label:"Canada",phone:"1",suggested:!0},{ioc:"",iso2:"CC",iso:"CCK",label:"Cocos (Keeling) Islands",phone:"61"},{ioc:"CGO",iso2:"CD",iso:"COG",label:"Congo, Republic of the",phone:"242"},{ioc:"CAF",iso2:"CF",iso:"CAF",label:"Central African Republic",phone:"236"},{ioc:"COD",iso2:"CG",iso:"CGD",label:"Congo, Democratic Republic of the",phone:"243"},{ioc:"SUI",iso2:"CH",iso:"CHE",label:"Switzerland",phone:"41"},{ioc:"CIV",iso2:"CI",iso:"CIV",label:"Cote d'Ivoire",phone:"225"},{ioc:"COK",iso2:"CK",iso:"COK",label:"Cook Islands",phone:"682"},{ioc:"CHI",iso2:"CL",iso:"CHL",label:"Chile",phone:"56"},{ioc:"CMR",iso2:"CM",iso:"CMR",label:"Cameroon",phone:"237"},{ioc:"CHN",iso2:"CN",iso:"CHN",label:"China",phone:"86"},{ioc:"COL",iso2:"CO",iso:"COL",label:"Colombia",phone:"57"},{ioc:"CRC",iso2:"CR",iso:"CRI",label:"Costa Rica",phone:"506"},{ioc:"CUB",iso2:"CU",iso:"CUB",label:"Cuba",phone:"53"},{ioc:"CPV",iso2:"CV",iso:"CPV",label:"Cape Verde",phone:"238"},{ioc:"CUW",iso2:"CW",iso:"CUW",label:"Curacao",phone:"599"},{ioc:"CXR",iso2:"CX",iso:"CXR",label:"Christmas Island",phone:"61"},{ioc:"CYP",iso2:"CY",iso:"CYP",label:"Cyprus",phone:"357"},{ioc:"CZE",iso2:"CZ",iso:"CZE",label:"Czech Republic",phone:"420"},{ioc:"GER",iso2:"DE",iso:"DEU",label:"Germany",phone:"49",suggested:!0},{ioc:"DJI",iso2:"DJ",iso:"DJI",label:"Djibouti",phone:"253"},{ioc:"DEN",iso2:"DK",iso:"DNK",label:"Denmark",phone:"45"},{ioc:"DMA",iso2:"DM",iso:"DMA",label:"Dominica",phone:"1-767"},{ioc:"DOM",iso2:"DO",iso:"DOM",label:"Dominican Republic",phone:"1-809"},{ioc:"ALG",iso2:"DZ",iso:"DZA",label:"Algeria",phone:"213"},{ioc:"ECU",iso2:"EC",iso:"ECU",label:"Ecuador",phone:"593"},{ioc:"EST",iso2:"EE",iso:"ESE",label:"Estonia",phone:"372"},{ioc:"EGY",iso2:"EG",iso:"EGY",label:"Egypt",phone:"20"},{ioc:"",iso2:"EH",iso:"ESH",label:"Western Sahara",phone:"212"},{ioc:"ERI",iso2:"ER",iso:"ERI",label:"Eritrea",phone:"291"},{ioc:"ESP",iso2:"ES",iso:"ESP",label:"Spain",phone:"34"},{ioc:"ETH",iso2:"ET",iso:"ETH",label:"Ethiopia",phone:"251"},{ioc:"FIN",iso2:"FI",iso:"FIN",label:"Finland",phone:"358"},{ioc:"FIJ",iso2:"FJ",iso:"FJI",label:"Fiji",phone:"679"},{ioc:"FLK",iso2:"FK",iso:"FLK",label:"Falkland Islands (Malvinas)",phone:"500"},{ioc:"FSM",iso2:"FM",iso:"FSM",label:"Micronesia, Federated States of",phone:"691"},{ioc:"FAR",iso2:"FO",iso:"FRO",label:"Faroe Islands",phone:"298"},{ioc:"FRA",iso2:"FR",iso:"FRA",label:"France",phone:"33",suggested:!0},{ioc:"GAB",iso2:"GA",iso:"GAB",label:"Gabon",phone:"241"},{ioc:"GBR",iso2:"GB",iso:"GBR",label:"United Kingdom",phone:"44"},{ioc:"GRN",iso2:"GD",iso:"GRD",label:"Grenada",phone:"1-473"},{ioc:"GEO",iso2:"GE",iso:"GEO",label:"Georgia",phone:"995"},{ioc:"FGU",iso2:"GF",iso:"GUF",label:"French Guiana",phone:"594"},{ioc:"",iso2:"GG",iso:"GGY",label:"Guernsey",phone:"44"},{ioc:"",iso2:"GH",iso:"GHA",label:"Ghana",phone:"233"},{ioc:"GIB",iso2:"GI",iso:"GIB",label:"Gibraltar",phone:"350"},{ioc:"GRL",iso2:"GL",iso:"GRL",label:"Greenland",phone:"299"},{ioc:"GAM",iso2:"GM",iso:"GMB",label:"Gambia",phone:"220"},{ioc:"GUI",iso2:"GN",iso:"GIN",label:"Guinea",phone:"224"},{ioc:"GUD",iso2:"GP",iso:"GLP",label:"Guadeloupe",phone:"590"},{ioc:"GEQ",iso2:"GQ",iso:"GNQ",label:"Equatorial Guinea",phone:"240"},{ioc:"GRE",iso2:"GR",iso:"GRC",label:"Greece",phone:"30"},{ioc:"",iso2:"GS",iso:"SGS",label:"South Georgia and the South Sandwich Islands",phone:"500"},{ioc:"GUA",iso2:"GT",iso:"GTM",label:"Guatemala",phone:"502"},{ioc:"GUM",iso2:"GU",iso:"GUM",label:"Guam",phone:"1-671"},{ioc:"GBS",iso2:"GW",iso:"GNB",label:"Guinea-Bissau",phone:"245"},{ioc:"GUY",iso2:"GY",iso:"GUY",label:"Guyana",phone:"592"},{ioc:"HKG",iso2:"HK",iso:"HKG",label:"Hong Kong",phone:"852"},{ioc:"",iso2:"HM",iso:"HMD",label:"Heard Island and McDonald Islands",phone:"672"},{ioc:"HON",iso2:"HN",iso:"HND",label:"Honduras",phone:"504"},{ioc:"CRO",iso2:"HR",iso:"HRV",label:"Croatia",phone:"385"},{ioc:"HAI",iso2:"HT",iso:"HTI",label:"Haiti",phone:"509"},{ioc:"HUN",iso2:"HU",iso:"HUN",label:"Hungary",phone:"36"},{ioc:"INA",iso2:"ID",iso:"IDN",label:"Indonesia",phone:"62"},{ioc:"IRL",iso2:"IE",iso:"IRL",label:"Ireland",phone:"353"},{ioc:"ISR",iso2:"IL",iso:"ISR",label:"Israel",phone:"972"},{ioc:"",iso2:"IM",iso:"IMN",label:"Isle of Man",phone:"44"},{ioc:"IND",iso2:"IN",iso:"IND",label:"India",phone:"91"},{ioc:"",iso2:"IO",iso:"IOT",label:"British Indian Ocean Territory",phone:"246"},{ioc:"IRQ",iso2:"IQ",iso:"IRQ",label:"Iraq",phone:"964"},{ioc:"IRI",iso2:"IR",iso:"IRN",label:"Iran, Islamic Republic of",phone:"98"},{ioc:"ISL",iso2:"IS",iso:"ISL",label:"Iceland",phone:"354"},{ioc:"ITA",iso2:"IT",iso:"ITA",label:"Italy",phone:"39"},{ioc:"",iso2:"JE",iso:"JEY",label:"Jersey",phone:"44"},{ioc:"JAM",iso2:"JM",iso:"JAM",label:"Jamaica",phone:"1-876"},{ioc:"JOR",iso2:"JO",iso:"JOR",label:"Jordan",phone:"962"},{ioc:"JPN",iso2:"JP",iso:"JPN",label:"Japan",phone:"81",suggested:!0},{ioc:"KEN",iso2:"KE",iso:"KEN",label:"Kenya",phone:"254"},{ioc:"KGZ",iso2:"KG",iso:"KGZ",label:"Kyrgyzstan",phone:"996"},{ioc:"CAM",iso2:"KH",iso:"KHM",label:"Cambodia",phone:"855"},{ioc:"KIR",iso2:"KI",iso:"KIR",label:"Kiribati",phone:"686"},{ioc:"COM",iso2:"KM",iso:"COM",label:"Comoros",phone:"269"},{ioc:"SKN",iso2:"KN",iso:"KNA",label:"Saint Kitts and Nevis",phone:"1-869"},{ioc:"KOR",iso2:"KP",iso:"KOR",label:"Korea, Democratic People's Republic of",phone:"850"},{ioc:"PRK",iso2:"KR",iso:"PRK",label:"Korea, Republic of",phone:"82"},{ioc:"KUW",iso2:"KW",iso:"KWT",label:"Kuwait",phone:"965"},{ioc:"CAY",iso2:"KY",iso:"CYM",label:"Cayman Islands",phone:"1-345"},{ioc:"KAZ",iso2:"KZ",iso:"KAZ",label:"Kazakhstan",phone:"7"},{ioc:"LAO",iso2:"LA",iso:"LAO",label:"Lao People's Democratic Republic",phone:"856"},{ioc:"LIB",iso2:"LB",iso:"LBN",label:"Lebanon",phone:"961"},{ioc:"LCA",iso2:"LC",iso:"LCA",label:"Saint Lucia",phone:"1-758"},{ioc:"LIE",iso2:"LI",iso:"LIE",label:"Liechtenstein",phone:"423"},{ioc:"SRI",iso2:"LK",iso:"LKA",label:"Sri Lanka",phone:"94"},{ioc:"LBR",iso2:"LR",iso:"LBR",label:"Liberia",phone:"231"},{ioc:"LES",iso2:"LS",iso:"LSO",label:"Lesotho",phone:"266"},{ioc:"LTU",iso2:"LT",iso:"LTU",label:"Lithuania",phone:"370"},{ioc:"LUX",iso2:"LU",iso:"LUX",label:"Luxembourg",phone:"352"},{ioc:"LAT",iso2:"LV",iso:"LVA",label:"Latvia",phone:"371"},{ioc:"LBA",iso2:"LY",iso:"LBY",label:"Libya",phone:"218"},{ioc:"MAR",iso2:"MA",iso:"MAR",label:"Morocco",phone:"212"},{ioc:"MON",iso2:"MC",iso:"MCO",label:"Monaco",phone:"377"},{ioc:"MDA",iso2:"MD",iso:"MDA",label:"Moldova, Republic of",phone:"373"},{ioc:"MNE",iso2:"ME",iso:"MNE",label:"Montenegro",phone:"382"},{ioc:"",iso2:"MF",iso:"MAF",label:"Saint Martin (French part)",phone:"590"},{ioc:"MAD",iso2:"MG",iso:"MDG",label:"Madagascar",phone:"261"},{ioc:"MSH",iso2:"MH",iso:"MHL",label:"Marshall Islands",phone:"692"},{ioc:"MKD",iso2:"MK",iso:"MKD",label:"Macedonia, the Former Yugoslav Republic of",phone:"389"},{ioc:"MLI",iso2:"ML",iso:"MLI",label:"Mali",phone:"223"},{ioc:"MYA",iso2:"MM",iso:"MMR",label:"Myanmar",phone:"95"},{ioc:"MGL",iso2:"MN",iso:"MNG",label:"Mongolia",phone:"976"},{ioc:"MAC",iso2:"MO",iso:"MAC",label:"Macao",phone:"853"},{ioc:"NMA",iso2:"MP",iso:"NMP",label:"Northern Mariana Islands",phone:"1-670"},{ioc:"MRT",iso2:"MQ",iso:"MTQ",label:"Martinique",phone:"596"},{ioc:"MTN",iso2:"MR",iso:"MRT",label:"Mauritania",phone:"222"},{ioc:"MNT",iso2:"MS",iso:"MSR",label:"Montserrat",phone:"1-664"},{ioc:"MLT",iso2:"MT",iso:"MLT",label:"Malta",phone:"356"},{ioc:"MRI",iso2:"MU",iso:"MUS",label:"Mauritius",phone:"230"},{ioc:"MDV",iso2:"MV",iso:"MDV",label:"Maldives",phone:"960"},{ioc:"MAW",iso2:"MW",iso:"MWI",label:"Malawi",phone:"265"},{ioc:"MEX",iso2:"MX",iso:"MEX",label:"Mexico",phone:"52"},{ioc:"MAS",iso2:"MY",iso:"MYS",label:"Malaysia",phone:"60"},{ioc:"MOZ",iso2:"MZ",iso:"MOZ",label:"Mozambique",phone:"258"},{ioc:"NAM",iso2:"NA",iso:"NAM",label:"Namibia",phone:"264"},{ioc:"NCL",iso2:"NC",iso:"NCL",label:"New Caledonia",phone:"687"},{ioc:"NIG",iso2:"NE",iso:"NER",label:"Niger",phone:"227"},{ioc:"NFI",iso2:"NF",iso:"NFK",label:"Norfolk Island",phone:"672"},{ioc:"NGR",iso2:"NG",iso:"NGA",label:"Nigeria",phone:"234"},{ioc:"NCA",iso2:"NI",iso:"NIC",label:"Nicaragua",phone:"505"},{ioc:"NED",iso2:"NL",iso:"NLD",label:"Netherlands",phone:"31"},{ioc:"NOR",iso2:"NO",iso:"NOR",label:"Norway",phone:"47"},{ioc:"NEP",iso2:"NP",iso:"NPL",label:"Nepal",phone:"977"},{ioc:"NRU",iso2:"NR",iso:"NRU",label:"Nauru",phone:"674"},{ioc:"NIU",iso2:"NU",iso:"NIU",label:"Niue",phone:"683"},{ioc:"NZL",iso2:"NZ",iso:"NZL",label:"New Zealand",phone:"64"},{ioc:"OMA",iso2:"OM",iso:"OMN",label:"Oman",phone:"968"},{ioc:"PAN",iso2:"PA",iso:"PAN",label:"Panama",phone:"507"},{ioc:"PER",iso2:"PE",iso:"PER",label:"Peru",phone:"51"},{ioc:"FPO",iso2:"PF",iso:"PYF",label:"French Polynesia",phone:"689"},{ioc:"PNG",iso2:"PG",iso:"PNG",label:"Papua New Guinea",phone:"675"},{ioc:"PHI",iso2:"PH",iso:"PHL",label:"Philippines",phone:"63"},{ioc:"PAK",iso2:"PK",iso:"PAK",label:"Pakistan",phone:"92"},{ioc:"POL",iso2:"PL",iso:"POL",label:"Poland",phone:"48"},{ioc:"SPM",iso2:"PM",iso:"SPM",label:"Saint Pierre and Miquelon",phone:"508"},{ioc:"",iso2:"PN",iso:"PCN",label:"Pitcairn",phone:"870"},{ioc:"PUR",iso2:"PR",iso:"PRI",label:"Puerto Rico",phone:"1"},{ioc:"PLE",iso2:"PS",iso:"PSE",label:"Palestine, State of",phone:"970"},{ioc:"POR",iso2:"PT",iso:"PRT",label:"Portugal",phone:"351"},{ioc:"PLW",iso2:"PW",iso:"PLW",label:"Palau",phone:"680"},{ioc:"PAR",iso2:"PY",iso:"PRY",label:"Paraguay",phone:"595"},{ioc:"QAT",iso2:"QA",iso:"QAT",label:"Qatar",phone:"974"},{ioc:"REU",iso2:"RE",iso:"REU",label:"Reunion",phone:"262"},{ioc:"ROU",iso2:"RO",iso:"ROU",label:"Romania",phone:"40"},{ioc:"SRB",iso2:"RS",iso:"SRB",label:"Serbia",phone:"381"},{ioc:"RUS",iso2:"RU",iso:"RUS",label:"Russia",phone:"7"},{ioc:"RWA",iso2:"RW",iso:"RWA",label:"Rwanda",phone:"250"},{ioc:"KSA",iso2:"SA",iso:"SAU",label:"Saudi Arabia",phone:"966"},{ioc:"SOL",iso2:"SB",iso:"SLB",label:"Solomon Islands",phone:"677"},{ioc:"SEY",iso2:"SC",iso:"SYC",label:"Seychelles",phone:"248"},{ioc:"SUD",iso2:"SD",iso:"SDN",label:"Sudan",phone:"249"},{ioc:"SWE",iso2:"SE",iso:"SWE",label:"Sweden",phone:"46"},{ioc:"SIN",iso2:"SG",iso:"SGP",label:"Singapore",phone:"65"},{ioc:"HEL",iso2:"SH",iso:"SHN",label:"Saint Helena",phone:"290"},{ioc:"SLO",iso2:"SI",iso:"SVN",label:"Slovenia",phone:"386"},{ioc:"",iso2:"SJ",iso:"SJM",label:"Svalbard and Jan Mayen",phone:"47"},{ioc:"SVK",iso2:"SK",iso:"SVK",label:"Slovakia",phone:"421"},{ioc:"SLE",iso2:"SL",iso:"SLE",label:"Sierra Leone",phone:"232"},{ioc:"SMR",iso2:"SM",iso:"SMR",label:"San Marino",phone:"378"},{ioc:"SEN",iso2:"SN",iso:"SEN",label:"Senegal",phone:"221"},{ioc:"SOM",iso2:"SO",iso:"SOM",label:"Somalia",phone:"252"},{ioc:"SUR",iso2:"SR",iso:"SUR",label:"Suriname",phone:"597"},{ioc:"",iso2:"SS",iso:"SSD",label:"South Sudan",phone:"211"},{ioc:"STP",iso2:"ST",iso:"STP",label:"Sao Tome and Principe",phone:"239"},{ioc:"ESA",iso2:"SV",iso:"SLV",label:"El Salvador",phone:"503"},{ioc:"",iso2:"SX",iso:"SMX",label:"Sint Maarten",phone:"1-721"},{ioc:"SYR",iso2:"SY",iso:"SYR",label:"Syria",phone:"963"},{ioc:"",iso2:"SZ",iso:"SWZ",label:"Swaziland",phone:"268"},{ioc:"TKS",iso2:"TC",iso:"TCA",label:"Turks and Caicos Islands",phone:"1-649"},{ioc:"CHA",iso2:"TD",iso:"TCD",label:"Chad",phone:"235"},{ioc:"",iso2:"TF",iso:"ATF",label:"French Southern Territories",phone:"262"},{ioc:"TOG",iso2:"TG",iso:"TGO",label:"Togo",phone:"228"},{ioc:"THA",iso2:"TH",iso:"THA",label:"Thailand",phone:"66"},{ioc:"TJK",iso2:"TJ",iso:"TJK",label:"Tajikistan",phone:"992"},{ioc:"",iso2:"TK",iso:"TKL",label:"Tokelau",phone:"690"},{ioc:"TLS",iso2:"TL",iso:"TLS",label:"Timor-Leste",phone:"670"},{ioc:"TKM",iso2:"TM",iso:"TKM",label:"Turkmenistan",phone:"993"},{ioc:"TUN",iso2:"TN",iso:"TUN",label:"Tunisia",phone:"216"},{ioc:"TGA",iso2:"TO",iso:"TON",label:"Tonga",phone:"676"},{ioc:"TUR",iso2:"TR",iso:"TUR",label:"Turkey",phone:"90"},{ioc:"TTO",iso2:"TT",iso:"TTO",label:"Trinidad and Tobago",phone:"1-868"},{ioc:"TUV",iso2:"TV",iso:"TUV",label:"Tuvalu",phone:"688"},{ioc:"TPE",iso2:"TW",iso:"TWN",label:"Taiwan",phone:"886"},{ioc:"TAN",iso2:"TZ",iso:"TZA",label:"United Republic of Tanzania",phone:"255"},{ioc:"UKR",iso2:"UA",iso:"UKR",label:"Ukraine",phone:"380"},{ioc:"UGA",iso2:"UG",iso:"UGA",label:"Uganda",phone:"256"},{ioc:"USA",iso2:"US",label:"United States",phone:"1",suggested:!0,iso:"USA"},{ioc:"URU",iso2:"UY",iso:"URY",label:"Uruguay",phone:"598"},{ioc:"UZB",iso2:"UZ",iso:"UZB",label:"Uzbekistan",phone:"998"},{ioc:"",iso2:"VA",iso:"VAT",label:"Holy See (Vatican City State)",phone:"379"},{ioc:"VIN",iso2:"VC",iso:"VCT",label:"Saint Vincent and the Grenadines",phone:"1-784"},{ioc:"VEN",iso2:"VE",iso:"VEN",label:"Venezuela",phone:"58"},{ioc:"IVB",iso2:"VG",iso:"VGB",label:"British Virgin Islands",phone:"1-284"},{ioc:"ISV",iso2:"VI",iso:"VIR",label:"US Virgin Islands",phone:"1-340"},{ioc:"VIE",iso2:"VN",iso:"VNM",label:"Vietnam",phone:"84"},{ioc:"VAN",iso2:"VU",iso:"VUT",label:"Vanuatu",phone:"678"},{ioc:"WAF",iso2:"WF",iso:"WLF",label:"Wallis and Futuna",phone:"681"},{ioc:"SAM",iso2:"WS",iso:"WSM",label:"Samoa",phone:"685"},{ioc:"KOS",iso2:"XK",iso:"KOS",label:"Kosovo",phone:"383"},{ioc:"YEM",iso2:"YE",iso:"YEM",label:"Yemen",phone:"967"},{ioc:"MAY",iso2:"YT",iso:"MYT",label:"Mayotte",phone:"262"},{ioc:"RSA",iso2:"ZA",iso:"ZAF",label:"South Africa",phone:"27"},{ioc:"ZAM",iso2:"ZM",iso:"ZMB",label:"Zambia",phone:"260"},{ioc:"ZIM",iso2:"ZW",iso:"ZWE",label:"Zimbabwe",phone:"263"}],Us="ELO",uW="NTRP",dW="UTR",u0="WTN",vo={[Us]:{range:[0,3e3],decimalsCount:0,defaultInitialization:1500},[uW]:{range:[1,7],decimalsCount:1,defaultInitialization:3,accessor:"dntrpRatingHundredths",accessors:["ntrpRating","dntrpRatingHundredths"],attributes:{ustaRatingType:""}},[dW]:{range:[1,16],decimalsCount:2,defaultInitialization:6},[u0]:{range:[40,1],decimalsCount:2,defaultInitialization:23,accessor:"wtnRating",accessors:["wtnRating"],attributes:{confidence:{generator:!0,range:[60,100]}}}};var pW=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],fW="COLLEGE_D3",vW={valueGoal:5},mW={collectionDefinitions:pW,tieFormatName:fW,winCriteria:vW},hW=[{collectionName:"Doubles",collectionValue:1,matchUpCount:3,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES"},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],gW="COLLEGE_DEFAULT",_W={valueGoal:5},IW={collectionDefinitions:hW,tieFormatName:gW,winCriteria:_W},PW=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],yW="COLLEGE_JUCO",SW={valueGoal:5},OW={collectionDefinitions:PW,tieFormatName:yW,winCriteria:SW},bW=[{collectionName:"Doubles",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],TW="DOMINANT_DUO",wW={valueGoal:2},d0={collectionDefinitions:bW,tieFormatName:TW,winCriteria:wW},EW=[{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],$W="DOMINANT_DUO_MIXED",NW={valueGoal:2},p0={collectionDefinitions:EW,tieFormatName:$W,winCriteria:NW},UW=[{collectionGroupNumber:1,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:1},{collectionGroupNumber:1,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:1},{collectionGroupNumber:2,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:2},{collectionGroupNumber:2,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:2},{collectionGroupNumber:3,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:3},{collectionGroupNumber:3,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:3}],AW=[{groupNumber:1,groupName:"Day 1"},{groupNumber:2,groupName:"Day 2"},{groupNumber:3,groupName:"Day 3"}],CW="LAVER_CUP",MW={valueGoal:13},f0={collectionDefinitions:UW,collectionGroups:AW,tieFormatName:CW,winCriteria:MW},DW=[{collectionName:"Round 1",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Round 2",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Round 3",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],jW="Doubles Shuffle",RW=!0,FW={aggregateValue:!0},v0={collectionDefinitions:DW,tieFormatName:jW,unrestrictedSelections:RW,winCriteria:FW},xW=[{category:{ageCategoryCode:"14U"},collectionName:"14U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],LW=[{groupNumber:1,groupName:"Doubles",groupValue:1,winCriteria:{valueGoal:2}}],VW="USTA_BREWER_CUP",BW={valueGoal:4},m0={collectionDefinitions:xW,collectionGroups:LW,tieFormatName:VW,winCriteria:BW},kW={valueGoal:23},GW="USTA_OZAKI_CUP",WW=[{category:{ageCategoryCode:"18U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"18U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"18U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"18U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"18U"},collectionName:"18U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"16U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"16U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"16U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"16U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"16U"},collectionName:"16U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"14U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"14U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"14U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"14U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"14U"},collectionName:"14U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"12U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"12U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"12U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"12U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"12U"},collectionName:"12U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"12U"},collectionName:"12U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"12U"},collectionName:"12U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1}],h0={winCriteria:kW,tieFormatName:GW,collectionDefinitions:WW},HW=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",collectionValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],qW="USTA_COLLEGE",zW={valueGoal:4},g0={collectionDefinitions:HW,tieFormatName:qW,winCriteria:zW},YW=[{collectionName:"Male Singles",matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpCount:4,matchUpValue:1,gender:"MALE"},{collectionName:"Female Singles",matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:4,matchUpValue:1},{collectionName:"Male Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpCount:2,matchUpValue:1,gender:"MALE"},{collectionName:"Female Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:2,matchUpValue:1},{collectionName:"Mixed Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpCount:4,matchUpValue:1,gender:"MIXED"}],KW="USTA_GOLD_TEAM_CHALLENGE",QW={valueGoal:9},_0={collectionDefinitions:YW,tieFormatName:KW,winCriteria:QW},JW=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],ZW="USTA_INTERSECTIONAL",XW={valueGoal:8},I0={collectionDefinitions:JW,tieFormatName:ZW,winCriteria:XW},e4=[{collectionName:"Male Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],t4="USTA_LEVEL_1",r4={valueGoal:10},P0={collectionDefinitions:e4,tieFormatName:t4,winCriteria:r4},n4=[{category:{ageCategoryCode:"16U"},collectionName:"16U Singles",matchUpCount:4,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Singles",matchUpCount:4,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Doubles",matchUpCount:2,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Doubles",matchUpCount:2,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Tiebreak Doubles",matchUpCount:1,matchUpFormat:"SET1-S:TB10",matchUpType:"DOUBLES",matchUpValue:1,processCodes:["RANKING.IGNORE"]}],o4="USTA_SECTION_BATTLE",i4={valueGoal:9},y0={collectionDefinitions:n4,tieFormatName:o4,winCriteria:i4},s4=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],a4="USTA_SOUTHERN_LEVEL_5",l4={valueGoal:8},S0={collectionDefinitions:s4,tieFormatName:a4,winCriteria:l4},c4=[{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Overtime",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],u4="USTA_TOC",d4={aggregateValue:!0},O0={collectionDefinitions:c4,tieFormatName:u4,winCriteria:d4},p4=[{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Overtime",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],f4="USTA_WTT_ITT",v4={aggregateValue:!0},b0={collectionDefinitions:p4,tieFormatName:f4,winCriteria:v4},m4=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],h4="USTA_ZONAL",g4={valueGoal:10},T0={collectionDefinitions:m4,tieFormatName:h4,winCriteria:g4};const w0={COLLEGE_D3:mW,COLLEGE_DEFAULT:IW,COLLEGE_JUCO:OW,DOMINANT_DUO:d0,DOMINANT_DUO_MIXED:p0,LAVER_CUP:f0,TEAM_DOUBLES_3_AGGREGATION:v0,USTA_BREWER_CUP:m0,USTA_OZAKI_CUP:h0,USTA_COLLEGE:g0,USTA_GOLD_TEAM_CHALLENGE:_0,USTA_INTERSECTIONAL:I0,USTA_LEVEL_1:P0,USTA_SECTION_BATTLE:y0,USTA_SOUTHERN_LEVEL_5:S0,USTA_TOC:O0,USTA_WTT_ITT:b0,USTA_ZONAL:T0},_4={[$V]:{roundsToSeparate:void 0,policyName:"Nationality Code",policyAttributes:[{key:"person.nationalityCode"},{key:"individualParticipants.person.nationalityCode"}]}},I4="qualifierDrawPositionAssignment",P4="withdrawParticipantAtDrawPosition",y4="alternateDrawPositionAssignment",S4="luckyLoserDrawPositionAssignment",E0="removeDrawPositionAssignment",O4="swapDrawPositionAssignments",b4="modifyPairAssignment",T4="modifyParticipantOtherName",$0="assignMatchUpSideParticipant",N0="assignDrawPosition",w4="removeSeededParticipant",E4="assignDrawPositionBye",$4="modifySeedAssignment",U0="addPenalty",A0="MODIFY_PAIR",Cv="QUALIFIER",C0="ALTERNATE",M0="WITHDRAW",wa="ASSIGN",D0="REMOVE",j0="LUCKY",Yu="REMOVE_SEED",R0="SWAP",Ku="NICKNAME",Ea="SEED_VALUE",$a="PENALTY",Mv="BYE",F0={[To]:{policyName:"positionActionsDefault",enabledStructures:[{stages:[we,he],stageSequences:[1],enabledActions:[],disabledActions:[]},{stages:[],stageSequences:[],enabledActions:[Ku,$a,Cv,Ea],disabledActions:[]}],disbledStructures:[],otherFlightEntries:!1,activePositionOverrides:[]}},N4={[To]:{policyName:"positionActionsDisabled",enabledStructures:!1}},U4={[To]:{policyName:"positionActionsNoMovement",enabledStructures:[{stages:[],stageSequences:[],enabledActions:[Ea,Ku,$a],disabledActions:[]}]}},A4={[To]:{policyName:"positionActionsUnrestricted",enabledStructures:[],otherFlightEntries:!0,disableRoundRestrictions:!0,activePositionOverrides:[Ea,Yu]}},C4={[Tl]:{policyName:"Participant Privacy Policy",participant:{contacts:!1,individualParticipants:{onlineResources:!1,participantName:!0,participantOtherName:!0,participantId:!0,participantRole:!0,participantStatus:!0,penalties:!1,representing:!0,participantRoleResponsibilities:!1,participantType:!0,person:{addresses:!1,biographicalInformation:!1,birthDate:!1,contacts:!1,nationalityCode:!0,nativeFamilyName:!1,nativeGivenName:!1,onlineResources:!1,otherNames:!0,parentOrganisationId:!1,passportFamilyName:!1,passportGivenName:!1,personId:!1,personOtherIds:!1,previousNames:!1,sex:!1,standardFamilyName:!0,standardGivenName:!0,status:!1,tennisId:!1,wheelchair:!0}},individualParticipantIds:!0,onlineResources:!1,participantName:!0,participantOtherName:!0,participantId:!0,participantRole:!0,participantStatus:!0,penalties:!1,representing:!0,participantRoleResponsibilities:!1,participantType:!0,person:{addresses:!1,biographicalInformation:!1,birthDate:!1,contacts:!1,nationalityCode:!0,nativeFamilyName:!1,nativeGivenName:!1,onlineResources:!1,otherNames:!0,parentOrganisationId:!1,passportFamilyName:!1,passportGivenName:!1,personId:!1,personOtherIds:!1,previousNames:!1,sex:!1,standardFamilyName:!0,standardGivenName:!0,status:!1,tennisId:!1,wheelchair:!0}}}},Dv="ADULT",jv="JUNIOR",Qu="WHEELCHAIR",M4={[$f]:{defaultTimes:{averageTimes:[{categoryNames:[],minutes:{default:90}}],recoveryTimes:[{minutes:{[dt]:30,default:60}}]},defaultDailyLimits:{[At]:2,[dt]:2,total:3},matchUpAverageTimes:[{matchUpFormatCodes:["SET3-S:6/TB7"],averageTimes:[{categoryNames:[],minutes:{default:90}},{categoryTypes:[Qu],minutes:{default:120}}]},{matchUpFormatCodes:["SET3-S:6/TB7-F:TB10"],averageTimes:[{categoryNames:[],minutes:{default:85}}]},{matchUpFormatCodes:["SET3-S:6/TB7-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:70}}]},{matchUpFormatCodes:["SET3-S:4NOAD-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:55}}]},{matchUpFormatCodes:["SET3-S:4/TB7"],averageTimes:[{categoryNames:[],minutes:{default:60}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:50}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB10"],averageTimes:[{categoryNames:[],minutes:{default:55}}]},{matchUpFormatCodes:["SET3-S:4/TB5@3"],averageTimes:[{categoryNames:[],minutes:{default:45}}]},{matchUpFormatCodes:["SET1-S:8/TB7","SET1-S:8/TB7@7"],averageTimes:[{categoryNames:[],minutes:{default:40}}]},{matchUpFormatCodes:["SET1-S:5/TB9@4"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:6/TB7"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:6NOAD"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:4/TB7","SET1-S:4/TB5@3","SET3-S:TB10","SET1-S:T20"],averageTimes:[{categoryNames:[],minutes:{default:20}}]},{matchUpFormatCodes:["SET1-S:4NOAD"],averageTimes:[{categoryNames:[],minutes:{default:20}}]},{matchUpFormatCodes:["SET1-S:TB10"],averageTimes:[{categoryNames:[],minutes:{default:10}}]}],matchUpRecoveryTimes:[{matchUpFormatCodes:["SET3-S:6/TB7","SET3-S:6/TB7-F:TB10","SET3-S:6/TB7-F:TB7"],recoveryTimes:[{categoryTypes:[Dv,Qu],minutes:{default:60,[dt]:30}},{categoryTypes:[jv],minutes:{default:60,[dt]:60}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB7","SET3-S:4/TB7-F:TB10","SET3-S:4NOAD-F:TB7","SET3-S:4/TB7","SET3-S:4/TB5@3"],recoveryTimes:[{categoryTypes:[Dv,Qu],minutes:{default:30}},{categoryTypes:[jv],minutes:{default:60}}]},{matchUpFormatCodes:["SET1-S:8/TB7","SET1-S:8/TB7@7","SET1-S:5/TB9@4","SET1-S:6/TB7","SET1-S:6NOAD","SET1-S:4/TB7","SET1-S:4NOAD","SET3-S:TB10","SET1-S:T20"],recoveryTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:4/TB5@3"],recoveryTimes:[{categoryTypes:[Dv,jv],minutes:{default:30}},{categoryTypes:[Qu],minutes:{default:15}}]},{matchUpFormatCodes:["SET1-S:TB10"],recoveryTimes:[{categoryNames:[],minutes:{default:15}}]}],matchUpDailyLimits:[]}},D4={[da]:{requireAllPositionsAssigned:!1,stage:{[he]:{stageSequence:{1:{requireAllPositionsAssigned:!0}}}},defaultMatchUpFormat:"SET3-S:6/TB7",matchUpFormats:[{description:"Best of 3 tiebreak sets",matchUpFormat:"SET3-S:6/TB7",categoryNames:[],categoryTypes:[]},{description:"Two tiebreak sets, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:6/TB7-F:TB7"},{description:"Two tiebreak sets, 10-point match tiebreak at one set all",matchUpFormat:"SET3-S:6/TB7-F:TB10"},{description:"One standard tiebreak set to 6, 7-point tiebreak at 6 games all",matchUpFormat:"SET1-S:6/TB7"},{description:"Best of 3 sets to 4",matchUpFormat:"SET3-S:4/TB7"},{description:"Two out of three short sets to 4 with 5-point tiebreak at 3 games all",matchUpFormat:"SET3-S:4/TB5@3"},{description:"One short set to 4, 7-point tiebreak at 4 games all",matchUpFormat:"SET1-S:4/TB7"},{description:"One short set to 4, 5-point tiebreak at 3 games all",matchUpFormat:"SET1-S:4/TB5@3"},{description:"Two short sets to 4, 10-point match tiebreak at one set all",matchUpFormat:"SET3-S:4/TB7-F:TB10"},{description:"Two short sets to 4, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:4/TB7-F:TB7"},{description:"One no advantage set to 5, tiebreak to 9 at 4-4",matchUpFormat:"SET1-S:5/TB9@4"},{description:"One set to 6 with deciding game at 5 games all",matchUpFormat:"SET1-S:6NOAD"},{description:"One short set to 4, deciding game is played at 3 games all",matchUpFormat:"SET1-S:4NOAD"},{description:"Two short sets to 4 with deciding game at 3-3, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:4NOAD-F:TB7"},{description:"8 game pro-set with 7 point tiebreak at 8 games all",matchUpFormat:"SET1-S:8/TB7"},{description:"8 game pro-set with 7 point tiebreak at 7 games all",matchUpFormat:"SET1-S:8/TB7@7"},{description:"Best of 3 10-point tiebreak games",matchUpFormat:"SET3-S:TB10"},{description:"One 10-point tiebreak game",matchUpFormat:"SET1-S:TB10"},{description:"Timed 20 minute game - game based",matchUpFormat:"SET1-S:T20"}]}},j4={[da]:{defaultMatchUpFormat:"SET3-S:6/TB7",requireAllPositionsAssigned:!1,processCodes:{incompleteAssignmentsOnDefault:["RANKING.IGNORE"]},stage:{[he]:{stageSequence:{1:{requireAllPositionsAssigned:!0}}}}}},R4={[pa]:{seedingProfile:{positioning:rv},validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,policyName:"ITF SEEDING",seedsCountThresholds:[{drawSize:4,minimumParticipantCount:3,seedsCount:2},{drawSize:16,minimumParticipantCount:12,seedsCount:4},{drawSize:32,minimumParticipantCount:24,seedsCount:8},{drawSize:64,minimumParticipantCount:48,seedsCount:16},{drawSize:128,minimumParticipantCount:97,seedsCount:32},{drawSize:256,minimumParticipantCount:192,seedsCount:64}]}},Rv={[pa]:{validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,seedingProfile:{positioning:vG},policyName:"USTA SEEDING",seedsCountThresholds:[{drawSize:4,minimumParticipantCount:3,seedsCount:2},{drawSize:16,minimumParticipantCount:12,seedsCount:4},{drawSize:32,minimumParticipantCount:24,seedsCount:8},{drawSize:64,minimumParticipantCount:48,seedsCount:16},{drawSize:128,minimumParticipantCount:96,seedsCount:32},{drawSize:256,minimumParticipantCount:192,seedsCount:64}]}},F4={ratingsParameters:vo,matchUpFormats:fV,countryToFlag:c0,tieFormats:w0,countries:ii,policies:{POLICY_AVOIDANCE_COUNTRY:_4,POLICY_POSITION_ACTIONS_DEFAULT:F0,POLICY_POSITION_ACTIONS_DISABLED:N4,POLICY_POSITION_ACTIONS_NO_MOVEMENT:U4,POLICY_POSITION_ACTIONS_UNRESTRICTED:A4,POLICY_PRIVACY_DEFAULT:C4,POLICY_ROUND_NAMING_DEFAULT:ly,POLICY_SCHEDULING_USTA:M4,POLICY_SCORING_DEFAULT:j4,POLICY_SCORING_USTA:D4,POLICY_SEEDING_ITF:R4,POLICY_SEEDING_USTA:Rv},flagIOC:cW};function Na({collectionDefinitions:t=[],collectionGroups:e=[]}){let r=0;const{groupValueNumbers:n}=vy({collectionGroups:e});let o;for(const s of t||[]){const{collectionValueProfiles:a,collectionGroupNumber:l,collectionValue:c,matchUpCount:u,matchUpValue:p,scoreValue:d,setValue:v}=s,f=l&&n.includes(l);if(v||d)o=!0;else{if(f)continue;if(c)r+=c;else if(a!=null&&a.length)for(const m of a)r+=m.matchUpValue;else p?r+=(u||0)*p:r+=u||0}}for(const s of e)r+=s.groupValue||0;return o||!r?{aggregateValue:!0}:{valueGoal:Math.floor(r/2)+1}}function Ju({participant:t,withISO2:e,withIOC:r}){const{person:n,individualParticipants:o}=t,i=[n,o==null?void 0:o.map(({person:a})=>a)].flat().filter(Boolean);function s(a){const{nationalityCode:l}=a||{};if(l){const c=ii.find(({iso:u})=>u===l);r&&(c!=null&&c.ioc)&&!a.iocNationalityCode&&(a.iocNationalityCode=c.ioc),e&&(c!=null&&c.iso2)&&!a.iso2NationalityCode&&(a.iso2NationalityCode=c.iso2),c!=null&&c.label&&!a.countryName&&(a.countryName=c.label)}}i.forEach(s)}var x4=Object.defineProperty,x0=Object.getOwnPropertySymbols,L4=Object.prototype.hasOwnProperty,V4=Object.prototype.propertyIsEnumerable,L0=(t,e,r)=>e in t?x4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,B4=(t,e)=>{for(var r in e||(e={}))L4.call(e,r)&&L0(t,r,e[r]);if(x0)for(var r of x0(e))V4.call(e,r)&&L0(t,r,e[r]);return t};function Un({returnPreviousValues:t,itemSubTypes:e,itemType:r,element:n}){if(!n)return{error:_e,info:Vf};if(e&&!Array.isArray(e))return{error:X,context:{itemSubTypes:e}};if(!Array.isArray(n.timeItems))return{error:g_};const o=n.timeItems.filter(s=>(s==null?void 0:s.itemType)===r).filter(s=>!(e!=null&&e.length)||e.some(a=>{var l;return(l=s==null?void 0:s.itemSubTypes)==null?void 0:l.includes(a)})).sort((s,a)=>{const l=new Date(s.createdAt||void 0).getTime(),c=new Date(a.createdAt||void 0).getTime();return l-c}),i=o.pop();if(i){const s=B4({timeItem:i},V);return t&&Object.assign(s,{previousItems:o}),s}else return{info:sr}}function k4({returnPreviousValues:t,drawDefinition:e,itemSubTypes:r,itemType:n}){if(!e)return{error:kr};if(!e.timeItems)return{info:sr};const{timeItem:o,previousItems:i,info:s}=Un({element:e,returnPreviousValues:t,itemSubTypes:r,itemType:n});return o&&{timeItem:o,previousItems:i}||{info:s}}function jo({returnPreviousValues:t,itemSubTypes:e,itemType:r,event:n}){if(!n)return{error:Ge};if(!n.timeItems)return{info:sr};const{timeItem:o,previousItems:i,info:s}=Un({returnPreviousValues:t,element:n,itemSubTypes:e,itemType:r});return o&&{timeItem:o,previousItems:i}||{info:s}}function Zu({returnPreviousValues:t,tournamentRecord:e,itemSubTypes:r,itemType:n}){if(!e)return{error:re};if(!e.timeItems)return{info:sr};const{timeItem:o,previousItems:i,info:s}=Un({element:e,returnPreviousValues:t,itemSubTypes:r,itemType:n});return o&&{timeItem:o,previousItems:i}||{info:s}}function G4({returnPreviousValues:t,tournamentRecord:e,participantId:r,itemSubTypes:n,itemType:o}){if(!e)return{error:re};if(!r)return{error:Et};const i=Qo({tournamentRecord:e,participantId:r});if(i.error)return i;const{participant:s}=i;if(!(s!=null&&s.timeItems))return{info:sr};const{timeItem:a,previousItems:l,info:c}=Un({element:i.participant,returnPreviousValues:t,itemSubTypes:n,itemType:o});return a&&{timeItem:a,previousItems:l}||{info:c}}var W4=Object.defineProperty,V0=Object.getOwnPropertySymbols,H4=Object.prototype.hasOwnProperty,q4=Object.prototype.propertyIsEnumerable,B0=(t,e,r)=>e in t?W4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xu=(t,e)=>{for(var r in e||(e={}))H4.call(e,r)&&B0(t,r,e[r]);if(V0)for(var r of V0(e))q4.call(e,r)&&B0(t,r,e[r]);return t};const z4={[Mr]:"groupParticipantIds",[Ce]:"pairParticipantIds",[tt]:"teamParticipantIds"},Y4={[Mr]:"groups",[tt]:"teams"};function k0({withIndividualParticipants:t,convertExtensions:e,policyDefinitions:r,tournamentRecord:n,withSignInStatus:o,withScaleValues:i,internalUse:s,withISO2:a,withIOC:l}){const c=r==null?void 0:r[Tl],u=c==null?void 0:c.participant,p={};for(const d of n.participants||[]){const v=d==null?void 0:d.participantId;v&&Z4({participantMap:p,participantId:v})}for(const d of n.participants||[]){const v=de(d,e,s),f=u?iu({template:c.participant,source:v}):v,{participantId:m,individualParticipantIds:h,participantType:g}=f;if(Object.assign(p[m].participant,f),h&&J4({individualParticipantIds:h,filteredParticipant:f,participantMap:p,participantType:g,participantId:m}),o&&(p[m].participant.signedIn=K4(v)),i){const{ratings:_,rankings:I,seedings:P}=ha({participant:v});p[m].participant.seedings=P,p[m].participant.rankings=I,p[m].participant.ratings=_}(l||a)&&Ju({participant:p[m].participant,withISO2:a,withIOC:l})}return t&&Q4({participantMap:p}),{participantMap:p}}function K4(t){const{timeItem:e}=Un({itemType:xl,element:t});return(e==null?void 0:e.itemValue)===Ll}function Q4({participantMap:t}){var e;const r=Object.values(t);for(const n of r){const o=n.participant;if((e=o.individualParticipantIds)!=null&&e.length){o.individualParticipants=[];for(const i of o.individualParticipantIds)o.individualParticipants.push(t[i].participant)}}}function J4({individualParticipantIds:t,filteredParticipant:e,participantMap:r,participantType:n,participantId:o}){for(const i of t){const s=r[i].participant;if(s[z4[n]].push(o),[tt,Mr].includes(n)){const{participantRoleResponsibilities:a,participantOtherName:l,participantName:c,participantId:u,teamId:p}=e,d=Y4[n];s[d].push({participantRoleResponsibilities:a,participantOtherName:l,participantName:c,participantId:u,teamId:p})}if(n===Ce){const a=t.find(l=>l!==i);r[i].pairIdMap[o]=a,r[i].pairIdMap[a]=o}}}function Z4({participantMap:t,participantId:e}){if(t[e])return;const r={walkoverWins:0,defaultWins:0,walkovers:0,defaults:0,losses:0,wins:0};t[e]={structureParticipation:{},potentialMatchUps:{},scheduleConflicts:[],scheduleItems:[],participant:{groupParticipantIds:[],pairParticipantIds:[],teamParticipantIds:[],groups:[],teams:[]},statistics:{},opponents:{},pairIdMap:{},matchUps:{},events:{},draws:{},counters:Xu({[At]:Xu({},r),[dt]:Xu({},r),[tt]:Xu({},r)},r)}}var X4=Object.defineProperty,eH=Object.defineProperties,tH=Object.getOwnPropertyDescriptors,G0=Object.getOwnPropertySymbols,rH=Object.prototype.hasOwnProperty,nH=Object.prototype.propertyIsEnumerable,W0=(t,e,r)=>e in t?X4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Fv=(t,e)=>{for(var r in e||(e={}))rH.call(e,r)&&W0(t,r,e[r]);if(G0)for(var r of G0(e))nH.call(e,r)&&W0(t,r,e[r]);return t},oH=(t,e)=>eH(t,tH(e));function As({participantsProfile:t,useParticipantMap:e,policyDefinitions:r,tournamentRecord:n,contextProfile:o,inContext:i}){var s;if(e)return{participantMap:(s=k0(oH(Fv(Fv({},t),o),{policyDefinitions:r,tournamentRecord:n})))==null?void 0:s.participantMap};let a=de(n.participants,!1,!0)||[];if((t!=null&&t.withIOC||t!=null&&t.withISO2)&&a.forEach(l=>Ju(Fv({participant:l},t))),(i||t!=null&&t.withGroupings)&&(a!=null&&a.length)&&(a=mv({participantsProfile:t,participants:a})),t!=null&&t.withScaleValues&&(a!=null&&a.length))for(const l of a){const{ratings:c,rankings:u}=ha({participant:l});l.rankings=u,l.ratings=c}return{participants:a}}var iH=Object.defineProperty,sH=Object.defineProperties,aH=Object.getOwnPropertyDescriptors,H0=Object.getOwnPropertySymbols,lH=Object.prototype.hasOwnProperty,cH=Object.prototype.propertyIsEnumerable,q0=(t,e,r)=>e in t?iH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,si=(t,e)=>{for(var r in e||(e={}))lH.call(e,r)&&q0(t,r,e[r]);if(H0)for(var r of H0(e))cH.call(e,r)&&q0(t,r,e[r]);return t},z0=(t,e)=>sH(t,aH(e));function Wt(t){var e,r,n;if(!(t!=null&&t.tournamentRecord))return{error:re};let{participantMap:o,participants:i}=t;const{scheduleVisibilityFilters:s,participantsProfile:a,afterRecoveryTimes:l,useParticipantMap:c,policyDefinitions:u,tournamentRecord:p,inContext:d=!0,contextProfile:v,matchUpFilters:f,contextFilters:m,nextMatchUps:h,context:g}=t,_=(e=t.tournamentId)!=null?e:p.tournamentId,I=(r=p==null?void 0:p.events)!=null?r:[];i||({participants:i,participantMap:o}=As({participantsProfile:a,policyDefinitions:u,useParticipantMap:c,tournamentRecord:p,contextProfile:v,inContext:d}));const{appliedPolicies:P}=pt({tournamentRecord:p}),y=z0(si({},g),{tournamentId:_,indoorOutDoor:p.indoorOutdoor,surfaceCategory:p.surfaceCategory,endDate:p.endDate}),S=wo({policyDefinitions:u,tournamentRecord:p,contextProfile:v});return{matchUps:I.flatMap(b=>{var w,T,$;return y.eventDrawsCount=(T=(w=b.drawDefinitions)==null?void 0:w.length)!=null?T:0,($=ai({context:y,scheduleVisibilityFilters:s,tournamentAppliedPolicies:P,participantsProfile:a,afterRecoveryTimes:l,policyDefinitions:u,tournamentRecord:p,contextContent:S,contextFilters:m,contextProfile:v,matchUpFilters:f,participantMap:o,nextMatchUps:h,participants:i,inContext:d,event:b}).matchUps)!=null?$:[]}).concat(...(n=p.matchUps)!=null?n:[])}}function zr(t){var e,r;let{participants:n,participantMap:o,contextContent:i}=t;const{scheduleVisibilityFilters:s,tournamentAppliedPolicies:a,participantsProfile:l,afterRecoveryTimes:c,policyDefinitions:u,useParticipantMap:p,tournamentRecord:d,contextFilters:v,contextProfile:f,drawDefinition:m,matchUpFilters:h,nextMatchUps:g,inContext:_,context:I,event:P}=t,{eventId:y,eventName:S,eventType:O,category:b,gender:w,matchUpFormat:T}=P??{},$=z0(si({},I),{eventId:y,eventType:O,eventName:S,category:b,gender:w,matchUpFormat:T,indoorOutDoor:(e=P==null?void 0:P.indoorOutdoor)!=null?e:d==null?void 0:d.indoorOutdoor,surfaceCategory:(r=P==null?void 0:P.surfaceCategory)!=null?r:d==null?void 0:d.surfaceCategory,endDate:P==null?void 0:P.endDate});return!(n!=null&&n.length)&&!o&&d&&({participants:n=[],participantMap:o}=As({participantsProfile:l,useParticipantMap:p,policyDefinitions:u,tournamentRecord:d,contextProfile:f,inContext:_})),f&&!i&&(i=wo({policyDefinitions:u,tournamentRecord:d,contextProfile:f,drawDefinition:m,event:P})),Lt({context:$,tournamentAppliedPolicies:a,scheduleVisibilityFilters:s,tournamentParticipants:n,participantsProfile:l,afterRecoveryTimes:c,policyDefinitions:u,tournamentRecord:d,drawDefinition:m,contextContent:i,contextFilters:v,contextProfile:f,matchUpFilters:h,participantMap:o,nextMatchUps:g,inContext:_,event:P})}function ai(t){var e,r,n,o,i;let{participants:s=[],contextContent:a,participantMap:l}=t;const{scheduleVisibilityFilters:c,tournamentAppliedPolicies:u,participantsProfile:p,afterRecoveryTimes:d,policyDefinitions:v,useParticipantMap:f,tournamentRecord:m,contextFilters:h,contextProfile:g,matchUpFilters:_,nextMatchUps:I,inContext:P,context:y,event:S}=t;if(!S)return{error:Ge};const{eventId:O,eventName:b,endDate:w,category:T,gender:$,matchUpFormat:N}=S,E=[],A=si(si({},y),Oe({indoorOutDoor:(e=S.indoorOutdoor)!=null?e:m==null?void 0:m.indoorOutdoor,surfaceCategory:(r=S.surfaceCategory)!=null?r:m==null?void 0:m.surfaceCategory,endDate:(n=S.endDate)!=null?n:m==null?void 0:m.endDate,tournamentId:m==null?void 0:m.tournamentId,matchUpFormat:N,eventName:b,category:T,gender:$,eventId:O}));if(w&&(A.endDate=w),g&&!a&&(a=wo({policyDefinitions:v,tournamentRecord:m,contextProfile:g,event:S})),!(s!=null&&s.length)&&!l&&m){const D=As({participantsProfile:p,useParticipantMap:f,policyDefinitions:v,tournamentRecord:m,contextProfile:g,inContext:P});l=D.participantMap,s=(o=D.participants)!=null?o:[]}const U=(i=S.drawDefinitions)!=null?i:[],C=Cl({tournamentRecord:m,event:S}).scheduleTiming;return{matchUps:U.flatMap(D=>{const{matchUps:R,matchUpsMap:j}=Lt({tournamentParticipants:s,tournamentAppliedPolicies:u,scheduleVisibilityFilters:c,context:A,participantsProfile:p,afterRecoveryTimes:d,policyDefinitions:v,tournamentRecord:m,contextFilters:h,contextProfile:g,drawDefinition:D,contextContent:a,matchUpFilters:_,participantMap:l,scheduleTiming:C,nextMatchUps:I,inContext:P,event:S});return j!=null&&j.drawMatchUps&&E.push(...j.drawMatchUps),R??[]}),eventMatchUps:E}}function Y0(t){var e,r,n;if(!(t!=null&&t.tournamentRecord))return{error:re};let o=t.contextContent;const{scheduleVisibilityFilters:i,participantsProfile:s,afterRecoveryTimes:a,policyDefinitions:l,useParticipantMap:c,tournamentRecord:u,inContext:p=!0,contextFilters:d,contextProfile:v,matchUpFilters:f,nextMatchUps:m,context:h}=t,g=(e=t.tournamentId)!=null?e:u.tournamentId,_=(r=u==null?void 0:u.events)!=null?r:[],{participants:I,participantMap:P}=As({participantsProfile:s,policyDefinitions:l,useParticipantMap:c,tournamentRecord:u,contextProfile:v,inContext:p});v&&!o&&(o=wo({policyDefinitions:l,tournamentRecord:u,contextProfile:v}));const{appliedPolicies:y}=pt({tournamentRecord:u}),S=(n=d==null?void 0:d.eventIds)!=null?n:[];return _.filter(b=>!S.includes(b.eventId)).map(b=>{var w,T;const $=Nt({event:b}).flightProfile,N=si({eventDrawsCount:((w=$==null?void 0:$.flights)==null?void 0:w.length)||((T=b.drawDefinitions)==null?void 0:T.length)||0},h);return K0({context:N,tournamentAppliedPolicies:y,scheduleVisibilityFilters:i,participantsProfile:s,afterRecoveryTimes:a,policyDefinitions:l,tournamentRecord:u,contextFilters:d,contextProfile:v,contextContent:o,matchUpFilters:f,participantMap:P,participants:I,tournamentId:g,nextMatchUps:m,inContext:p,event:b})}).reduce((b,w)=>{const T=w&&Object.keys(w).filter($=>!["success","matchUpsMap"].includes($));return T==null||T.forEach($=>{b[$]||(b[$]=[]),b[$]=b[$].concat(w[$]),b.matchUpsCount+=w[$].length}),b},{matchUpsCount:0})}function K0(t){var e,r,n;let{participants:o,contextContent:i,participantMap:s}=t;const{tournamentAppliedPolicies:a,scheduleVisibilityFilters:l,participantsProfile:c,afterRecoveryTimes:u,policyDefinitions:p,useParticipantMap:d,tournamentRecord:v,contextFilters:f,contextProfile:m,matchUpFilters:h,nextMatchUps:g,tournamentId:_,inContext:I,context:P,event:y}=t;if(!y)return{error:Ge};const{eventId:S,eventName:O,endDate:b}=y,w=si(si({},P),Oe({eventId:S,eventName:O,endDate:b??(v==null?void 0:v.endDate),tournamentId:_??(v==null?void 0:v.tournamentId),indoorOutDoor:(e=y.indoorOutdoor)!=null?e:v==null?void 0:v.indoorOutdoor,surfaceCategory:(r=y.surfaceCategory)!=null?r:v==null?void 0:v.surfaceCategory}));return!o&&v&&({participants:o,participantMap:s}=As({participantsProfile:c,policyDefinitions:p,useParticipantMap:d,tournamentRecord:v,contextProfile:m,inContext:I})),m&&!i&&(i=wo({policyDefinitions:p,tournamentRecord:v,contextProfile:m,event:y})),((n=y.drawDefinitions)!=null?n:[]).reduce(($,N)=>{const E=ws({context:w,tournamentAppliedPolicies:a,scheduleVisibilityFilters:l,tournamentParticipants:o,participantsProfile:c,afterRecoveryTimes:u,policyDefinitions:p,tournamentRecord:v,drawDefinition:N,contextContent:i,contextFilters:f,contextProfile:m,matchUpFilters:h,participantMap:s,nextMatchUps:g,inContext:I,event:y}),A=Object.keys(E);return A==null||A.forEach(U=>{$[U]||($[U]=[]),$[U]=$[U].concat(E[U])}),$},{})}function uH({participants:t,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextFilters:l,contextProfile:c,contextContent:u,drawDefinition:p,matchUpFilters:d,participantMap:v,nextMatchUps:f,tournamentId:m,inContext:h,context:g,event:_}){var I,P,y;const{eventId:S,eventName:O,endDate:b}=_??{},w=si(si({},g),Oe({eventId:S,eventName:O,endDate:(I=b??(_==null?void 0:_.endDate))!=null?I:a==null?void 0:a.endDate,tournamentId:m??(a==null?void 0:a.tournamentId),indoorOutDoor:(P=_==null?void 0:_.indoorOutdoor)!=null?P:a==null?void 0:a.indoorOutdoor,surfaceCategory:(y=_==null?void 0:_.surfaceCategory)!=null?y:a==null?void 0:a.surfaceCategory}));return!(t!=null&&t.length)&&a&&({participants:t,participantMap:v}=As({participantsProfile:n,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextProfile:c,inContext:h})),_&&c&&!u&&(u=wo({policyDefinitions:i,tournamentRecord:a,contextProfile:c,drawDefinition:p,event:_})),ws({context:w,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,tournamentParticipants:t,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:a,participantMap:v,drawDefinition:p,matchUpFilters:d,contextFilters:l,contextProfile:c,contextContent:u,nextMatchUps:f,inContext:h,event:_})}function ac({finishingPositionOffset:t=0,finishingPositionLimit:e,positionsFed:r,roundsCount:n,roundLimit:o,matchUps:i,lucky:s,fmlc:a}){var l;if(!Array.isArray(i))return[];const{roundProfile:c,roundNumbers:u=[]}=Tr({interpolate:!0,matchUps:i});n=n||Math.max(...u,0);const p=o?n-o:0,d=p&&((l=c==null?void 0:c[n-p])==null?void 0:l.matchUpsCount),v=c&&Object.values(c).map(Fn("matchUpsCount")),f=(g,_)=>{let I=Math.min(...g);d&&_&&I===1&&(I=d);let P=Math.max(...g);return e&&P>e&&(P=e),[I,P]},m=c&&Object.assign({},...u.map(g=>{const _=(n||0)+1-g-p,I=c[g].matchUpsCount,P={finishingPositionRange:{},finishingRound:_},y=v==null?void 0:v.slice(g-1).reduce((E,A)=>E+(A||0),0),S=a&&g!==1,O=1+t+(S&&r||0),b=1,w=ce(O,s?O+I*2:y+O+b),T=y+b-I,$=f(w.slice(T)),N=f(w.slice(0,T),!0);return P.finishingPositionRange={loser:$,winner:N},{[g]:P}})),h=zt({finishingRound:!0});return i.filter(Boolean).forEach(g=>{const _=g.roundNumber&&m[g.roundNumber];h&&!_&&console.log({roundFinishingData:m,matchUp:g}),g.finishingRound=_==null?void 0:_.finishingRound,g.finishingPositionRange=_==null?void 0:_.finishingPositionRange}),i}function Ua({inContextDrawMatchUps:t,drawDefinition:e,matchUpsMap:r}){var n;if(!e)return{error:ue};const o={loserMatchUpIds:{},winnerMatchUpIds:{}};if(t||({matchUps:t,matchUpsMap:r}=Lt({inContext:!0,drawDefinition:e,matchUpsMap:r})),!(r==null?void 0:r.drawMatchUps.some(s=>s.finishingPositionRange))&&((n=e==null?void 0:e.structures)==null?void 0:n.length)===1&&!(e!=null&&e.structures[0].structures)){const s=(r==null?void 0:r.drawMatchUps)||[];ac({matchUps:s})}return(t||[]).filter(({collectionId:s})=>!s).forEach(s=>{const{matchUpId:a,structureId:l}=s,c=Ir({inContextDrawMatchUps:t,drawDefinition:e,matchUpId:a}),{winnerMatchUp:u,loserMatchUp:p}=c.targetMatchUps,d=u==null?void 0:u.matchUpId,v=p==null?void 0:p.matchUpId,m=xi({matchUpsMap:r,structureId:l}).find(h=>h.matchUpId===a);if(m&&(d&&(o.winnerMatchUpIds[m.matchUpId]=d,Object.assign(m,{winnerMatchUpId:d}),Object.assign(s,{winnerMatchUpId:d})),v&&(o.loserMatchUpIds[m.matchUpId]=v,s.loserMatchUpId=v,m.loserMatchUpId=v,s.finishingPositionRange))){const h=p.finishingPositionRange&&[...s.finishingPositionRange.loser,...p.finishingPositionRange.loser],g=h&&[Math.min(...h),Math.max(...h)];s.finishingPositionRange.loser=g,m.finishingPositionRange.loser=g}}),{inContextDrawMatchUps:t,goesToMap:o}}function ed(t){var e;const{sides:r,matchUpType:n}=t||{},o=(e=t.potentialParticipants)!=null&&e.length?t.potentialParticipants.flat().map(a=>n===dt?(a==null?void 0:a.individualParticipantIds)||[]:a.participantId).flat():[],i=(r||[]).map(a=>{var l;return n===dt&&(((l=a==null?void 0:a.participant)==null?void 0:l.individualParticipantIds)||[])||(a==null?void 0:a.participantId)&&[a.participantId]||[]}).flat();return{individualParticipantIds:i.concat(o).flat(),enteredIndividualParticipantIds:i,potentialIndividualParticipantIds:o}}function Ro({scheduleVisibilityFilters:t,afterRecoveryTimes:e,participantsProfile:r,tournamentRecords:n,policyDefinitions:o,matchUpFilters:i,contextFilters:s,nextMatchUps:a,inContext:l}){return typeof n!="object"||!Object.keys(n).length?{error:ke}:{matchUps:Object.keys(n).map(p=>{var d;const v=n[p];return(d=Wt({scheduleVisibilityFilters:t,afterRecoveryTimes:e,participantsProfile:r,policyDefinitions:o,tournamentRecord:v,matchUpFilters:i,contextFilters:s,nextMatchUps:a,inContext:l}).matchUps)!=null?d:[]}).flat()}}function xv({scheduleVisibilityFilters:t,participantsProfile:e,tournamentRecords:r,policyDefinitions:n,matchUpFilters:o,contextFilters:i,nextMatchUps:s,inContext:a}){return typeof r!="object"||!Object.keys(r).length?{error:ke}:Object.keys(r).map(u=>{const p=r[u];return Y0({scheduleVisibilityFilters:t,participantsProfile:e,policyDefinitions:n,tournamentRecord:p,matchUpFilters:o,contextFilters:i,nextMatchUps:s,inContext:a})}).reduce((u,p)=>(Object.keys(p).forEach(v=>{u[v]||(u[v]=[]),u[v]=u[v].concat(p[v])}),u),{})}function Cs(t,e){return dH(t,e)||((t==null?void 0:t.stageSequence)||0)-((e==null?void 0:e.stageSequence)||0)||(t==null?void 0:t.roundNumber)&&e.roundNumber&&(t==null?void 0:t.roundNumber)-(e==null?void 0:e.roundNumber)||((t==null?void 0:t.roundPosition)||0)-((e==null?void 0:e.roundPosition)||0)}function dH(t,e){return(_s[t==null?void 0:t.stage]||0)-(_s[e==null?void 0:e.stage]||0)}var pH=Object.defineProperty,Q0=Object.getOwnPropertySymbols,fH=Object.prototype.hasOwnProperty,vH=Object.prototype.propertyIsEnumerable,J0=(t,e,r)=>e in t?pH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mH=(t,e)=>{for(var r in e||(e={}))fH.call(e,r)&&J0(t,r,e[r]);if(Q0)for(var r of Q0(e))vH.call(e,r)&&J0(t,r,e[r]);return t};function cn(t){var e,r,n,o;let i=(e=t.tournamentRecords)!=null?e:{};const s=(r=t.matchUps)!=null?r:[];let a=(n=t.drawIds)!=null?n:[];const{includeParticipantDependencies:l,tournamentRecord:c,drawDefinition:u}=t;if(!Array.isArray(s))return{error:ko};if(!Array.isArray(a))return{error:kr};const p=(o=t.matchUpIds)!=null&&o.length?t.matchUpIds:s.map(O=>O.matchUpId);if(!Array.isArray(p))return{error:vl};const d={},v={},f={},m={};c&&!Object.keys(i).length&&(i={[c.tournamentId]:c});const h=Object.values(i),_=h.reduce((O,b)=>O.concat(b.events||[]).map(w=>(w.drawDefinitions||[]).map(T=>T.links||[])).flat(1/0),[]).filter(({linkType:O})=>O===Ci);let I=s;if(_.length){I=Ro({nextMatchUps:!0,tournamentRecords:i}).matchUps;const O=_.reduce((b,w)=>{var T,$;const N=(T=w.source)==null?void 0:T.structureId,E=($=w.target)==null?void 0:$.structureId;return N&&E&&(f[E]=N),N&&!b.includes(N)&&b.push(N),b},[]);for(const b of O)d[b]=[];for(const b of I||[]){const w=b.containerStructureId||b.structureId;O.includes(w)&&d[w].push(b.matchUpId)}}const P=O=>{v[O]||(v[O]={dependentMatchUpIds:[],participantIds:[],matchUpIds:[],sources:[]},m[O]=[])},y=(O,b)=>{v[O].matchUpIds.forEach(T=>{v[b].matchUpIds.push(T)}),v[b].matchUpIds.push(O),v[O].dependentMatchUpIds.push(b),l&&v[O].participantIds.forEach(T=>v[b].participantIds.push(T))},S=O=>{const b=Object.keys(d).length;for(const w of O||[]){const{matchUpId:T,winnerMatchUpId:$,loserMatchUpId:N}=w;if(!p.length||p.includes(T)){if(P(T),l){const{individualParticipantIds:U}=ed(w);v[T].participantIds=U}$&&(P($),y(T,$),m[$].push(T)),N&&(P(N),y(T,N),m[N].push(T)),v[T].sources.push(m[T]);const E=m[T].map(U=>v[U].sources[0]).flat(),A=m[T].map(U=>v[U].sources[1]).flat();if(v[T].sources.push(E,A),b){const U=w.containerStructureId||w.structureId,C=f[U];if(d[C])for(const M of d[C])P(M),y(M,T),m[M].push(T)}}}};if(u)Ua({drawDefinition:u}),I!=null&&I.length||(I=zr({drawDefinition:u}).matchUps),S(I);else{if(I!=null&&I.length||(I=Ro({nextMatchUps:!0,tournamentRecords:i}).matchUps),!a.length){const O=h!=null&&h.length?h.map(({events:b=[]})=>b.map(({drawDefinitions:w=[]})=>w.map(({drawId:T})=>T))).flat(1/0):[];O&&(a=O)}for(const O of a){const b=I==null?void 0:I.filter(T=>T.drawId===O).sort(Cs);if(!(b==null?void 0:b.find(({roundPosition:T})=>!T))){const T=b==null?void 0:b.find(({tournamentId:N})=>N),{drawDefinition:$}=Qt({tournamentRecord:i[T==null?void 0:T.tournamentId],drawId:O});$&&Ua({drawDefinition:$})}S(b)}}return mH({positionDependencies:d,matchUpDependencies:v,sourceMatchUpIds:m,matchUps:I},V)}function Z0({tournamentRecords:t,matchUps:e}){if(!Array.isArray(e))return{error:ko};if(e.some(({matchUpId:f,hasContext:m})=>f&&!m))return{info:"matchUps must have { inContext: true, nextMatchUps: true }",error:ru};const r=Math.max(...e.map(({schedule:f})=>(f==null?void 0:f.courtOrder)||1).map(f=>Te(f))),n=ce(1,r+1).map(f=>e.filter(m=>{var h;return Te((h=m.schedule)==null?void 0:h.courtOrder)===f})),o={},i={},s={};n.flat().filter(Boolean).sort(Cs).forEach(({schedule:f})=>delete f[xf]);const l=We(e.map(({drawId:f})=>f)),c=cn({includeParticipantDependencies:!0,tournamentRecords:t,drawIds:l}).matchUpDependencies,u=n.map((f,m)=>f.reduce((h,g)=>{if(!g.matchUpId)return h;const{matchUpId:_,winnerMatchUpId:I,loserMatchUpId:P,schedule:y,sides:S,potentialParticipants:O}=g,b=y==null?void 0:y.courtId;o[_]=m,i[b]=[],h.matchUpIds.push(_),s[_]=g;const w=c[_].matchUpIds;w.length&&h.sourceMatchUpIds.push(...w);const T=(S==null?void 0:S.map(N=>{var E;return[(E=N.participant)==null?void 0:E.individualParticipantIds,N.participantId]}).flat().filter(Boolean))||[],$=(O==null?void 0:O.flat().map(({individualParticipantIds:N,participantId:E})=>[N,E]).flat().filter(Boolean))||[];return h.participantIds.push(...$,...T),I&&h.targetMatchUpIds.push(I),P&&h.targetMatchUpIds.push(P),h},{sourceMatchUpIds:[],targetMatchUpIds:[],participantIds:[],matchUpIds:[]})),p=(f,m)=>c[f].sources.reduce((h,g,_)=>g.includes(m)&&_+1||h,0),d=u.map(()=>[]),v=(f,m,h,g)=>{if(!s[f].schedule[xf]){s[f].schedule[xf]=m,s[f].schedule[mB]=g,d[o[f]].push({matchUpId:f,issueType:h,issueIds:g,issue:m});const _=s[f].schedule.courtId;i[_]||(i[_]=[]),i[_].push({matchUpId:f,issue:m,issueType:h,issueIds:g})}};return u.forEach((f,m)=>{const h=m?u[m-1]:void 0,g=u.slice(m+1),_={},I=Nr(f.participantIds),P=Object.keys(I).filter(O=>I[O]>1),y=f.matchUpIds.filter(O=>c[O].participantIds.some(b=>P.includes(b)));y.forEach(O=>{_[O]||(_[O]={}),_[O][ps]||(_[O][ps]=y.filter(b=>b!==O))});const S=h&&f.participantIds.filter(O=>h.participantIds.includes(O));S&&S.forEach(O=>{const b=f.matchUpIds.concat(h.matchUpIds).filter(w=>c[w].participantIds.includes(O));b.forEach(w=>{_[w]||(_[w]={}),_[w][fs]||(_[w][fs]=b.filter(T=>T!==w))})}),f.matchUpIds.forEach(O=>{var b,w,T,$;const N=c[O].matchUpIds;for(const A of g){const U=A.matchUpIds.filter(C=>N.includes(C));U!=null&&U.length&&(U.forEach(C=>v(C,AI,wi,[O])),v(O,AI,wi,U))}if((b=_[O])!=null&&b[ps]&&v(O,ps,UI,_[O][ps]),f.sourceMatchUpIds.includes(O)){const A=f.matchUpIds.filter(U=>c[U].matchUpIds.includes(O));v(O,ps,wi,A),f.matchUpIds.filter(U=>c[U].matchUpIds.includes(O)).forEach(U=>v(U,ps,wi,[O]))}const E=(w=h==null?void 0:h.matchUpIds)==null?void 0:w.filter(A=>p(O,A)>1);if(E!=null&&E.length&&(v(O,CI,wi,E),E.forEach(A=>v(A,CI,wi,[O]))),(T=_[O])!=null&&T[fs]&&v(O,fs,UI,_[O][fs]),($=h==null?void 0:h.targetMatchUpIds)!=null&&$.includes(O)){const A=s[O].schedule.courtId,U=N.filter(M=>h.matchUpIds.includes(M));U.some(M=>s[M].schedule.courtId===A)||(U.forEach(M=>v(M,fs,wi,[O])),v(O,fs,wi,U))}})}),{courtIssues:i,rowIssues:d}}function td(t){var e;if(!t)return{};const r=[],n=t.tieFormatName,o=(e=t.collectionDefinitions)==null?void 0:e.map(i=>{const{matchUpType:s,matchUpFormat:a,matchUpCount:l,category:c,gender:u}=i;r.includes(a)||r.push(a);const p=c==null?void 0:c.ageCategoryCode;return[l,s===mn?"D":"S",p,a,u].join(";")}).join("|");return{tieFormatName:t&&n||"UNNAMED",matchUpFormats:r,tieFormatDesc:o}}var hH=Object.defineProperty,gH=Object.defineProperties,_H=Object.getOwnPropertyDescriptors,X0=Object.getOwnPropertySymbols,IH=Object.prototype.hasOwnProperty,PH=Object.prototype.propertyIsEnumerable,eS=(t,e,r)=>e in t?hH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yH=(t,e)=>{for(var r in e||(e={}))IH.call(e,r)&&eS(t,r,e[r]);if(X0)for(var r of X0(e))PH.call(e,r)&&eS(t,r,e[r]);return t},SH=(t,e)=>gH(t,_H(e));function Aa({considerations:t={},descendant:e,ancestor:r}){var n,o,i,s;const a={},l={},{matchUpFormats:c,tieFormatDesc:u}=td(e),{matchUpFormats:p,tieFormatDesc:d}=td(r),v=We((c??[]).filter(y=>!(p??[]).includes(y)).concat((p??[]).filter(y=>!(c??[]).includes(y)))),f=!!(t!=null&&t.collectionName&&e.collectionDefinitions.map(({collectionName:y})=>y).join("|")!==r.collectionDefinitions.map(({collectionName:y})=>y).join("|")),m=!!(t!=null&&t.collectionOrder&&e.collectionDefinitions.map(({collectionOrder:y})=>y).join("|")!==r.collectionDefinitions.map(({collectionOrder:y})=>y).join("|")),h=f||m||d!==u,g=Object.assign({},...((e==null?void 0:e.collectionDefinitions)||[]).map(y=>({[y.collectionId]:y}))),_=Object.assign({},...((r==null?void 0:r.collectionDefinitions)||[]).map(y=>({[y.collectionId]:y})));a.collectionIds=Lg(Object.keys(g),Object.keys(_)),l.collectionIds=Lg(Object.keys(_),Object.keys(g)),a.collectionsValue=tS(g,a),l.collectionsValue=tS(_,l),a.groupsCount=(s=(n=r==null?void 0:r.collectionGroups)==null?void 0:n.length)!=null?s:0-((i=(o=e==null?void 0:e.collectionGroups)==null?void 0:o.length)!=null?i:0)||0,l.groupsCount=a.groupsCount?-1*a.groupsCount:0;const I=a.collectionsValue.totalValue-l.collectionsValue.totalValue,P=a.collectionsValue.totalMatchUps-l.collectionsValue.totalMatchUps;return SH(yH({matchUpFormatDifferences:v,matchUpCountDifference:P,descendantDifferences:a,ancestorDifferences:l,orderDifference:m,valueDifference:I,nameDifference:f,descendantDesc:u,ancestorDesc:d},V),{different:h})}function tS(t,e){let r=0;return{totalValue:e.collectionIds.reduce((o,i)=>{const s=t[i],{collectionValueProfiles:a,collectionValue:l,matchUpCount:c,matchUpValue:u}=s;return r+=c,a?o+a.reduce((p,d)=>p+d.value,0):u&&c?o+u*c:o+l},0),totalMatchUps:r}}var OH=Object.defineProperty,rS=Object.getOwnPropertySymbols,bH=Object.prototype.hasOwnProperty,TH=Object.prototype.propertyIsEnumerable,nS=(t,e,r)=>e in t?OH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wH=(t,e)=>{for(var r in e||(e={}))bH.call(e,r)&&nS(t,r,e[r]);if(rS)for(var r of rS(e))TH.call(e,r)&&nS(t,r,e[r]);return t};function EH({tournamentRecord:t}){if(!t)return{error:re};if(typeof t!="object"||!t.tournamentId)return{error:X};const{matchUps:e}=Wt({tournamentRecord:t,inContext:!1});if(e!=null&&e.length){const r=$H({tournamentRecord:t});UH(e,r)}return wH({},V)}function $H({tournamentRecord:t}){const e={};for(const r of t.events||[]){r.matchUpFormat&&(e[r.eventId]=r.matchUpFormat);for(const n of r.drawDefinitions||[]){n.matchUpFormat&&(e[n.drawId]=n.matchUpFormat);for(const o of n.structures||[]){o.matchUpFormat&&(e[o.structureId]=o.matchUpFormat);for(const i of o.structures||[])i.matchUpFormat&&(e[i.structureId]=i.matchUpFormat)}}}return e}const NH=["collectionId","collectionPosition","drawPositions","extensions","finishingPositionRange","finishingRound","isMock","matchUpId","matchUpStatus","matchUpStatusCodes","orderOfFinish","processCodes","roundNumber","tieFormat","tieMatchUps","roundPosition","score","sides","winnerMatchUpId","loserMatchUpId","matchUpDuration","winningSide"];function UH(t,e={}){for(const r of t){const{structureId:n,drawId:o,eventId:i}=r,s=e[n]||e[o]||e[i],a=r.matchUpFormat===s?void 0:r.matchUpFormat;for(const l of Object.keys(r))NH.includes(l)||delete r[l];r.sides&&r.drawPositions&&!r.tieMatchUps&&delete r.sides,a&&(r.matchUpFormat=a)}}function lc({court:t,date:e}){const r=e&&t.dateAvailability.find(o=>io(o.date,e)),n=t.dateAvailability.find(o=>!o.date);return r||n}function Ca({includeBookingTypes:t=[],courtDate:e}){const r=[];let n=$t(e.startTime);(e.bookings||[]).filter(i=>!i.bookingType||!t.includes(i.bookingType)).sort((i,s)=>cu(i.startTime).localeCompare(cu(s.startTime))).forEach(i=>{const s={startTime:at(n.toISOString()),endTime:i.startTime};$t(i.startTime)>n&&r.push(s),$t(i.endTime)>n&&(n=$t(i.endTime))});const o={startTime:at(n.toISOString()),endTime:e.endTime};return $t(e.endTime)>n&&r.push(o),r}function AH({averageMatchUpMinutes:t,includeBookingTypes:e,periodStartTime:r,periodEndTime:n}){const o=s=>!!Ca({includeBookingTypes:e,courtDate:s}).filter(i).length;function i(s){const a=$t(s.startTime),l=$t(s.endTime);return a>r||l<n?!1:Sl(r,l)>=t}return{enoughTime:o}}function oS(t){const{averageMatchUpMinutes:e,includeBookingTypes:r,periodStart:n,date:o}=t,i=t.courts,s=$t(n),a=If(s,e),{enoughTime:l}=AH({averageMatchUpMinutes:e,includeBookingTypes:r,periodStartTime:s,periodEndTime:a});return{availableToScheduleCount:((i==null?void 0:i.filter(u=>{if(!Array.isArray(u.dateAvailability))return!1;const p=lc({date:o,court:u});return!!(p&&l(p))}))||[]).length}}function Lv(t){const{remainingScheduleTimes:e=[],clearScheduleDates:r,periodLength:n=30,scheduleDate:o,courts:i=[]}=t;let{bookings:s=[]}=t;if(!Array.isArray(i)||!i.length)return{error:X,courts:i};if(!Array.isArray(s))return{error:sf};if(!Gr(o))return{error:Sr};r&&(Array.isArray(r)?r.includes(o)&&(s=[]):s=[]);const{courtBookings:a,unassignedBookings:l}=s.reduce((v,f)=>{const{courtId:m}=f;return m?v.courtBookings[m]?v.courtBookings[m].push(f):v.courtBookings[m]=[f]:v.unassignedBookings.push(f),v},{courtBookings:{},unassignedBookings:[]}),c=i.map((v,f)=>{const{courtId:m,courtName:h}=v,g=a[m]||[],_=lc({date:o,court:v})||{},{bookings:I=[],startTime:P,endTime:y,date:S}=_,b=[e[f]&&{startTime:P,endTime:e[f]},...de(I,!1,!0),...g].filter(Boolean);return{courtId:m,courtName:h,dateAvailability:{bookings:b,startTime:P,endTime:y,date:S}}});l.sort((v,f)=>Le(v.startTime)-Le(f.startTime));const u=()=>c.map(v=>{const f=v.dateAvailability,m=Ca({courtDate:f});return{courtName:v.courtName,courtId:v.courtId,timeSlots:m}}).flat(),p=[];for(const v of l){const{startTime:f,endTime:m,averageMinutes:h,recoveryMinutes:g,matchUpId:_}=v,I=Le(f),P=Le(m),S=u().reduce((O,{courtId:b,courtName:w,timeSlots:T})=>{let $;return T.find(({startTime:E,endTime:A})=>{$=Le(E)-I;const U=I>=Le(E);return P<=Le(A)&&O.startDifference!==0&&(($===0||$+n>=0)&&(O.startDifference===void 0||$<O.startDifference)||U)})?{courtName:w,courtId:b,startDifference:$}:O},{});if(S.courtId){const O={averageMinutes:h,recoveryMinutes:g,matchUpId:_,startTime:f,endTime:m};p.push(O);const b=c.find(({courtId:w})=>w===S.courtId);b==null||b.dateAvailability.bookings.push(O)}else console.log({unassignedBooking:v})}return{virtualCourts:c.map(({courtId:v,courtName:f,dateAvailability:m})=>({dateAvailability:[m],courtName:f,courtId:v})),assignedBookings:p}}function rd({averageMatchUpMinutes:t,periodLength:e=30,recoveryMinutes:r}){const n=(t||90)+(r||0);return e>n?n:e||30}function Ma({scheduleDate:t,startTime:e,endTime:r,courts:n}){const o=e&&"startTime"||r&&"endTime"||void 0;return n.reduce((i,s)=>{const a=lc({date:t,court:s}),l=o&&((a==null?void 0:a[o])||s[o]);return l&&(!i||e&&Le(l)<Le(i)||Le(l)>Le(i))?l:i},void 0)}function CH({averageMinutes:t,startTime:e,endTime:r,courts:n,date:o}){e=e||Ma({courts:n,scheduleDate:o,startTime:!0}),r=r||Ma({courts:n,scheduleDate:o,endTime:!0});let i;if(e&&r){const s=$t(e),a=$t(r);for(const l of n||[]){if(!Array.isArray(l.dateAvailability))continue;const c=lc({court:l,date:o});Ca({courtDate:c}).forEach(p=>{const d=$t(p.startTime),v=$t(p.endTime);if(d>a||d<s||v<s)return!1;if(Sl(d,v)>=t){const h=at(d.toISOString());(!i||h<i)&&(i=h)}})}}return{firstTimeSlotStartTime:i}}function iS(t){const{startTime:e="8:00",endTime:r="20:30",count:n=10,date:o}=t||{};return ce(0,n).map(()=>({dateAvailability:[{date:o,startTime:e,endTime:r}]}))}function Vv(t){let{date:e=gf(),startTime:r="08:00",endTime:n="19:00",periodLength:o,courts:i}=t;const{calculateStartTimeFromCourts:s=!0,remainingScheduleTimes:a,averageMatchUpMinutes:l,clearScheduleDates:c,courtsCount:u,bookings:p}=t;o=o||rd({averageMatchUpMinutes:l}),e=Re(e),r=at(r),n=at(n);let d=0,v=0,f=0,m=0,h=0;!i&&u&&(i=iS({startTime:r,endTime:n,count:u,date:e}));const{virtualCourts:g}=Lv({remainingScheduleTimes:a,clearScheduleDates:c,scheduleDate:e,periodLength:o,bookings:p,courts:i}),{firstTimeSlotStartTime:_}=CH({averageMinutes:l,courts:g,startTime:r,endTime:n,date:e});s&&_&&(r=_||r);const I=Le(r),y=Le(n)-I,S=Math.floor(y/o),b=ce(0,S+1).map(T=>{const $=I+T*o,N=kL($),{availableToScheduleCount:E}=oS({courts:g||[],averageMatchUpMinutes:l,periodStart:N,date:e}),A=E>v?E-v:0;h+=T?E:0;const U=T?h/T:E,M=o*U/l,D=T?M*(T-1)+U:U,R=E?v&&D-d||A:0;d=D,v=E,f+=R;const j=Te(f)-m;return m+=j,{periodStart:N,add:j,availableToScheduleCount:E,newCourts:A,totalMatchUps:m}});return{scheduleTimes:b.reduce((T,$)=>{const E=ce(0,$.add).map(()=>({scheduleTime:$.periodStart}));return T.concat(...E)},[]).flat(),timingProfile:b,totalMatchUps:m}}const MH={getCourtsAvailableAtPeriodStart:oS,generateTimeSlots:Ca,getScheduleTimes:Vv,courtGenerator:iS},DH=(t,e)=>t.filter(Boolean).every(r=>typeof r===e),jH=t=>t.filter(Boolean).every(Ct);function sS({consideredDate:t,category:e}={consideredDate:""}){var r;const n={error:X,ageMin:8,ageMax:99};if(typeof e!="object"||!Gr(t))return n;const o=parseInt(t.split("-")[0]),i=[];let{ageCategoryCode:s,ageMaxDate:a,ageMinDate:l,ageMax:c,ageMin:u}=e;const p=e.categoryName;let d;if(!DH([s,a,l,p],"string")||!jH([c,u]))return n;s=s??p;const v=/^([UO]?)(\d{1,2})([UO]?)$/,f=/^C(\d{1,2})-(\d{1,2})$/,m=s==null?void 0:s.includes("-"),h=m&&(s==null?void 0:s.match(f)),g=s==null?void 0:s.match(v),_=w=>w.match(/^\d{2}-\d{2}$/),I=(w,T,$)=>Gr(T)&&T||T&&_(T)&&`${w}-${T}`||`${w}-${$}`,P=w=>{const T=o-w;return l=I(T,l,"01-01"),c&&c!==w-1&&i.push(`Invalid ageMax: ${c}`),c||(c=w-1),{ageMinDate:l,ageMax:c}},y=w=>{const T=o-w-1;return l=I(T,l,"01-01"),c&&c!==w&&i.push(`Invalid ageMax: ${c}`),c||(c=w),{ageMinDate:l,ageMax:c}},S=w=>{const T=o-w-2;return a=I(T,a,"12-31"),u&&u!==w+1&&i.push(`Invalid ageMin: ${u}`),u||(u=w+1),{ageMaxDate:a,ageMin:u}},O=w=>{const T=o-w-1;return a=I(T,a,"12-31"),u&&u!==w&&i.push(`Invalid ageMin: ${u}`),u||(u=w),{ageMaxDate:a,ageMin:u}},b=w=>{const[T,$,N]=(w.match(v)||[]).slice(1),E=parseInt($);T==="U"&&({ageMinDate:l,ageMax:c}=P(E)),N==="U"&&({ageMinDate:l,ageMax:c}=y(E)),T==="O"&&({ageMaxDate:a,ageMin:u}=S(E)),N==="O"&&({ageMaxDate:a,ageMin:u}=O(E))};if(h){const[w,T]=((r=s==null?void 0:s.match(f))!=null?r:[]).slice(1).map($=>parseInt($));w<=T?(u=u??w,c=c??T,d=!0):i.push(`Invalid combined age range ${s}`)}else m?s==null||s.split("-").forEach(b):g&&b(s);return i.length?{error:i,ageMin:8,ageMax:99}:Oe({combinedAge:d,ageMaxDate:a,ageMinDate:l,ageMax:c,ageMin:u})}function nd({tiebreakTo:t=7,scoreString:e}){return e.split(" ").filter(Boolean).map((n,o)=>r({set:n,setNumber:o+1}));function r({set:n,setNumber:o}){const i=(n==null?void 0:n.startsWith("["))&&n.split("[")[1].split("]")[0].split("-").map(h=>parseInt(h)),s=n.includes("(")&&n.split("(")[0]||n.includes("[")&&n.split("[")[0]||n,a=!i&&s.split("-").map(h=>parseInt(h)),l=i?i[0]>i[1]&&1||i[0]<i[1]&&2||void 0:a[0]>a[1]&&1||a[0]<a[1]&&2||void 0,c=n.includes("(")?n.split("(")[1].split(")")[0]:void 0,p=c&&Av({lowValue:c,isSide1:l===2,tiebreakTo:t})||[],[d,v]=a||[],[f,m]=i||p||[];return{side1Score:d,side2Score:v,side1TiebreakScore:f,side2TiebreakScore:m,winningSide:l,setNumber:o}}}function Bv({drawPositions:t}){const e=o=>t.filter(i=>i!==o).map(i=>[o,i]),r=[].concat(...t.map(e)),n=We(r.map(od)).map(o=>o.split("|").map(i=>+i));return{groupMatchUps:r,uniqueMatchUpGroupings:n}}function od(t){return t.sort(er).join("|")}function aS({groupSize:t,drawPositionOffset:e}){const r=p=>[...Array(p)].map((d,v)=>v),n=r(2*Math.round(t/2)+1).slice(1),o=r(n.length-1).map(()=>[]);let i=n.slice(0,n.length/2),s=n.slice(n.length/2);n.slice(1).forEach((p,d)=>{i.forEach((h,g)=>{o[d].push([i[g],s[g]])});const v=i.shift(),f=i.pop(),m=s.shift();i=[v,m,...i].filter(Boolean),s=[...s,f].filter(Boolean)});const a=i.shift(),l=i.pop(),c=s.shift();i=[a,c,...i].filter(Boolean),s=[...s,l].filter(Boolean);const u=p=>p[0].reduce((d,v)=>d+v);return o.reverse().sort((p,d)=>u(p)-u(d)).map(p=>p.filter(d=>d.every(v=>v<=t)).map(d=>{const v=d.map(f=>f+e);return od(v)}))}function RH({rounds:t,hash:e}){return t.reduce((r,n,o)=>n.includes(e)?o+1:r,void 0)}const FH={getRoundRobinGroupMatchUps:Bv,determineRoundNumber:RH,drawPositionsHash:od,groupRounds:aS},id="\\d+-\\d+",cc="\\d+-\\d+\\(\\d+\\)",kv="\\[\\d+-\\d+\\]",xH="\\d+-\\d+\\(\\d+-\\d+\\)",LH=new RegExp(`(${id}),`,"g"),VH=new RegExp(`(${cc}),`,"g"),BH=[id,cc,kv,xH],kH=["0","1","2","00","01","10","11","002","012","102","112","000","001","010","100","011","101","110","111","002","012","102","112","0002","0012","0102","1002","0112","1012","1102","1112","3","03","13","013","103"].map(t=>{const r=t.split("").map(n=>BH[n]).join(" ");return new RegExp(`^${r}$`)});function lS(t){return!t||kH.some(e=>e.test(t))}function GH(t){const e="[];",r="()",n=e+r,o=[e[0],r[0]],i=Object.assign({},...n.split("").map(l=>({[l]:0})));let s="";const a=t.split("").map(l=>{const c=n.includes(l)&&l,u=o.includes(c);if(u&&c)return i[c]+=1,s=c,l;if(!u&&c&&s&&c!==s){i[s]-=1;const p=e.includes(s)&&e||r.includes(s)&&r||"",d=p.split("").find(v=>v!==s);if(p.includes(c))i[s]||(s="");else return i[c]||(s=""),d}return l}).join("");return t!==a?a:t}function sd(t){return/^\(\d+\)$/.test(t)||/^\(\d+$/.test(t)}function WH(t){return/^\(\d+-\d+\)$/.test(t)||/^\[\d+-\d+\]$/.test(t)}function Da(t){const r=(n=>n==null?void 0:n.split("-").join("").split("/").join(""))(t);if(/^\d+$/.test(r)&&r.length===2){const n=r.split("");return Math.abs(n.reduce((i,s)=>+i-+s))===1}return!1}function ad(t,e){const r=[t.slice(e,e+2),e?t.slice(0,1):t.slice(2)].map(i=>parseInt(i.join(""))),n=e?r.reverse():r;if(Math.abs(n.reduce((i,s)=>+i-+s))>=2)return n.join("-")}function cS(t){return t.length===2?t.split("").join("-"):([", ",",","/"," "].forEach(e=>t=t.split(e).join("-")),t=t.replace(/-{2,}/,"-"),t)}function HH(t){return t.startsWith("(")&&t.endsWith(")")}function qH({score:t,applied:e}){t=GH(t);const r=/\)(\d+)/g;if(r.test(t))for(const S of t.match(r)){const O=S.replace(")",") ");t=t.replace(S,O)}t=t.replace(/\)\//g,") / "),t=t.replace(/\/\)/g,")");const n=/\(([\d- ]+)\)/g,o=/\(([\d- ]+)\)/,i=t.match(n);for(const S of i||[]){const[O]=S.match(o).slice(1),b=O.replace(/ /g,"");t=t.replace(S,`(${b})`)}let s=/\(\(\d-\d\)\)/g;if(s.test(t)){const S=t.match(s);S.length&&S.forEach(O=>{const b=O.match(/\((\(\d-\d\))\)/).slice(1)[0];t=t.replace(O,b)})}if(s=/\(\((\d)\)\)/g,s.test(t)){const S=t.match(s);S.length&&S.forEach(O=>{const b=O.match(/\((\(\d\))\)/).slice(1)[0];t=t.replace(O,b)})}/(^|\s)6-,/.test(t)&&(t=t.replace(/(^|\s)6-,/g,"6-0,"));const a=new RegExp(/[-,]{2,}/g);t=t.replace(a,"-"),["- "," -"].forEach(S=>{const O=new RegExp(`(\\d+)${S}(\\d+)`,"g"),b=t.match(O);b&&b.forEach(w=>t=t.replace(w,w.split(S).join("-")))}),/^[(-/,]+$/.test(t)&&(t=""),/\)[-/,]+$/.test(t)&&(t=t.slice(0,t.length-1)),/\d \/\d/.test(t)&&(t=t.replace(/ \//g,"/")),t.includes(" /")&&(t=t.replace(/ \//g," "));const l=/\(\d+, \)/g;l.test(t)&&t.match(l).forEach(O=>{const[b]=O.match(/\((\d+), \)/).slice(1);b.length===2?t=t.replace(O,`(${b})`):b.length===1&&b==="6"&&(t=t.replace(O,"(6-0)"))});const c=/\((\d+)\/\)/g;c.test(t)&&t.match(c).forEach(O=>{const[b]=O.match(/\((\d+)\/\)/).slice(1);b.length===2?t=t.replace(O,`(${b})`):b.length===1&&b==="6"?t=t.replace(O,"(6-0)"):t=t.replace(O,`(${b})`)});const u=/\d\/\d\/,/g;u.test(t)&&t.match(u).forEach(O=>{const[b]=O.match(/(\d\/\d)\/,/).slice(1);t=t.replace(O,`${b},`),e.push("slashComma")});const p=/\(\/(\d+)\)/g;p.test(t)&&t.match(p).forEach(O=>{const[b]=O.match(/\(\/(\d+)\)/).slice(1);b.length===2?t=t.replace(O,`(${b})`):b.length===1&&parseInt(b)<6?t=t.replace(O,`(6-${b})`):t=t.replace(O,`(${b})`)});let d,v,f,m,h;const g=()=>{h=Nr(t.split("")),v=h["("]===(h[")"]||0)+1,d=(h["("]||0)+1===h[")"],f=h["["]===h["]"]+1,m=v&&!f};g();const _=/(\d+-\d+\(\d+)0,/;if(_.test(t)){const[S]=t.match(_).slice(1);t=t.replace(_,S+")")}if(h["("]===h[")"]&&h["("]>1){const S=t.split(")(").join(") (").split(" ");S.every(HH)?t=S.map(O=>{const b=O.slice(1,O.length-1);return b.length>2?b:O}).join(" "):t=S.join(" ")}g();const I=/[A-Za-z]+/.test(t),P=/\d+/.test(t);if(!I&&!P)return{score:""};if(/^\[.+\]$/.test(t)&&"()/,- ".split("").some(S=>h[S])&&(t=t.slice(1,t.length-1)),/^\(.+\)$/.test(t)&&h["("]===1&&h[")"]===1&&"[]/,".split("").some(S=>h[S]>1)&&(t=t.slice(1,t.length-1)),t.startsWith("(")&&t.endsWith("))")&&(t=t.slice(1,t.length-1)),h["("]>(h[")"]||0)&&t[t.length-1]==="("&&(t=t.slice(0,t.length-1)+")",g()),h["("]===1&&!h[")"]&&t[0]==="("&&(t=t+")",g()),h["("]>(h[")"]||0)&&t.slice(0,2)==="(("&&(t=t.slice(1)),d){if(/^9\d/.test(t))t="("+t.slice(1);else if(t[0]!=="(")t="("+t;else{const S=[];let O=0;for(const b of t.split("").reverse())b===")"&&(O?S.push("("):O+=1),b==="("&&(O-=1),S.push(b);S.reverse(),t=S.join("")}g()}if(h[")"]>(h["("]||0)&&t[0]===")"&&(t="("+t.slice(1),g()),m&&(t.endsWith(9)||/\d+0$/.test(t))&&(t=t.slice(0,t.length-1)+")",g()),m&&(!t.endsWith(")")||t.startsWith("(("))&&(t=t+")",g()),m){let S="",O=0;for(const b of t.split(""))b==="("&&(O?S+=")":O+=1),b===")"&&(O-=1),S+=b;t=S}g(),f&&!v&&(t=t+"]"),t.includes("([")&&t.includes("])")&&(t=t.split("([").join("[").split("])").join("]"),g()),/\(\d+0$/.test(t)&&(t=t.slice(0,t.length-1)+")"),g(),h[")"]===1&&!h["("]&&t.endsWith(")")&&(t=t.slice(0,t.length-1)),t.startsWith("(")&&t.endsWith(")")&&h["("]===1&&h[")"]===1&&(t=t.slice(1,t.length-1),g());const y=S=>{const O=S.indexOf("("),b=S.indexOf(")");return O>=0&&b>=0&&O<b};if(/^\([\d ]+.*[\d ]+\)$/.test(t)&&h["("]===h[")"]){const S=t.slice(1,t.length-1);y(S)&&(t=S,g())}return{score:t,applied:e}}function ld(t){if(!/^[\d-]+(\(\d\))*$/.test(t))return t;const e=Dn("-",t.split(""));if(!e.length)return t;const r=t.split("-"),n=!(r.length%2),o=!!(e.length%2);return n&&o&&e.length>r.length/2&&e.filter((s,a)=>a%2).forEach(s=>{t=t.substring(0,s)+" "+t.substring(s+1)}),t}function zH({score:t,applied:e}){return t.includes("( ")&&(e.push("removeParenSpacingAfterOpen"),t=t.split("( ").map(r=>r.trim()).join("(")),t.includes(" )")&&(e.push("removeParenSpacingBeforeClose"),t=t.split(" )").map(r=>r.trim()).join(")")),[LH,VH].forEach(r=>{const n=t.match(r);n!=null&&n.length&&(n.forEach(o=>{t=t.replace(o,o.slice(0,o.length-1)+" ")}),e.push("setsEndComma"))}),t=t.split(" ").filter(Boolean).map(ld).join(" "),{score:t,applied:e}}function YH({score:t}){if(typeof t!="string")return{score:t};const e=d=>d==null?void 0:d.split("-").join("").split("/").join(""),r=d=>d.split("[").join("(").split("]").join(")");t=t.split(", ").join(" ");let n=t.split(" ");t=n.map(d=>{const v=/^-(\d+)$/;if(v.test(d)){const[f]=d.match(v).slice(1);if(f.length===2)return f.split("").join("-")}return d}).join(" "),n=t.split(" ");const o=n.filter(sd);let i=0,s="";for(const d of o){const v=Dn(d,n).filter(g=>!i||g>i)[0],f=n.slice(i,v-1),m=n[v-1],h=e(m);if(/^\d+$/.test(h)&&h.length===2){const g=h.split(""),_=Math.abs(g.reduce((I,P)=>+I-+P));if(_===1){const I=[f.join(" "),[m,d].join("")].join(" ");s+=I,i=v+1}else if(_===0){const I=Math.max(...g);if([4,5,6,7,8,9].includes(I)){const P=[6,4].includes(I)?I+1:I-1,y=[I,P].sort().reverse().join("-"),S=[f.join(" "),[y,d].join("")].join(" ");s+=S,i=v+1}}}}if(o.length&&s.length){const d=n.slice(i).join(" ");return s=[s,d].join(" "),{score:s.trim()}}if(n.length===2&&["(","["].some(d=>n[1].includes(d))){const v=e(n[0]).split("");if(Math.abs(v.reduce((m,h)=>+m-+h,0))===1)return n[1]=r(n[1]),{score:n.join("")}}const a=n.map(d=>WH(d)&&"bracket"||Da(d)&&"set");if(a.includes("set")&&a.includes("bracket")){let d,v="";return n.forEach((f,m)=>{a[m]==="bracket"&&d==="set"?(f=r(f),v+=f):v+=` ${f}`,d=a[m]}),{score:v.trim()}}n=t.split(" ");let l,c=n.map(d=>{const v=new RegExp(/^(\d+)-(\d+)$/);if(v.test(d)){const[f,m]=d.match(v).slice(1),h=Math.abs([f,m].reduce((_,I)=>+_-+I)),g=Math.max(f,m);if(h===1)return l="tiebreakSet",l;if(h>=2&&g>=7&&l==="tiebreakSet")return l="tiebreak",l}});const u=Dn("tiebreak",c);if(u.length){let d="";n.forEach((v,f)=>{u.includes(f)?d+=`(${v}) `:u.includes(f+1)?d+=`${v}`:d+=`${v} `}),t=d.trim()}const p=/(\d+-\d+)\((\d+)-(\d+)\)$/;if(p.test(t)){const[d,v,f]=t.match(p).slice(1),h=Math.max(v,f)>=10;!Da(d)&&h&&(t=t.replace(p,`${d} [${v}-${f}]`))}return c=[],t=t.split(" ").map(d=>{const v=/^\((.*)\)$/,f=v.test(d),m=new RegExp(kv).test(d)&&"super"||new RegExp(cc).test(d)&&"tiebreak"||new RegExp(id).test(d)&&"standard"||"unknown";return c.push(m),m==="standard"&&f?d.match(v)[1]:d}).join(" "),{score:t}}function KH({score:t,applied:e}){for(const T of[".",","," ","/"]){const $=new RegExp(`^(\\d+)\\${T}(\\d+)$`);if($.test(t)){const N=t.match($).slice(1).map(A=>parseInt(A)),E=Math.abs(N[0]-N[1]);E<=10&&E>=2&&(t=t.split(T).join("-"),e.push("variedJoinerPattern"))}}t.includes(";")&&(t=t.split(";").join(" "),e.push("semicolon set separation"));const r=/(^|\s)(\d)\/(\d)(\d)\/(\d)(\(|$)/;if(r.test(t)){const[T,$,N,E,A,U]=t.match(r).slice(1);t=t.replace(r,`${T}${$}-${N} ${E}-${A}${U}`),e.push("smashSlashPattern")}/.*\s6[/-]+$/.test(t)&&(t+="0",e.push("incompleteFinalSetPattern"));const o=/\(6,\)/g;o.test(t)&&(t=t.replace(o,"(6, 0)"),e.push("missingZeroPattern1"));const i=/^\d{3,}\(/,s=/\(\d+\)\d+/;[i,s].forEach(()=>{t=t.split(" ").map($=>(i.test($)&&($=$.replace("("," (")),s.test($)&&($=$.replace(")",") ")),$)).join(" "),e.push("spaceConsiderationPatterns")});const l=ld(t);l!==t&&(t=l,e.push("deDashMash"));const c=/^(\d)[-/,]+(\d{2})[-/,]+(\d)$/;if(c.test(t)){const[T,$,N]=t.match(c).slice(1),[E,A]=$.split("");t=`${T}-${E} ${A}-${N}`,e.push("smashSetPattern")}const u=/^(\d+)[ -](\d+)$/,p=/^([\d -]+)\/([\d -]+)$/;if(p.test(t)){const[T,$]=t.match(p).slice(1),N=T.trim(),E=$.trim();if(u.test(N)&&u.test(E)){const A=N.match(u).slice(1,3).join("-"),U=E.match(u).slice(1,3).join("-");t=`${A} ${U}`,e.push("slashSeparationPattern")}}const d=/^([\d -]+),([\d -]+)$/;if(d.test(t)){const[T,$]=t.match(d).slice(1),N=T.trim(),E=$.trim();if(u.test(N)&&u.test(E)){const A=N.match(u).slice(1,3).join("-"),U=E.match(u).slice(1,3).join("-");t=`${A} ${U}`,e.push("commaSeparationPattern")}}const v=/^\d \d,/;if(v.test(t)){const T=t.match(v)[0],$=T.slice(0,T.length-1).split(" ").join("-");t=t.replace(T,$),e.push("singleSetCommaSeparationPattern")}let f=0;const m=/(\d+)-(\d{2})-(\d+)/;for(;m.test(t)&&f<3;){const[T,$,N]=t.match(m).slice(1),E=$.split(""),A=`${T}-${E[0]} ${E[1]}-${N}`;t=t.replace(m,A),e.push("noSetSeparationPattern"),f+=1}const h=/(^|\s)7-6\s(\d+)\s/g,g=t.match(h);if(g!=null&&g.length){const T=/(^|\s)7-6\s(\d+)\s/;g.forEach($=>{const N=$.match(T).slice(2)[0];t=t.replace($,`7-6(${N}) `),e.push("floatingTiebreakPattern1")})}let _=t.match(/\d \d /);_==null||_.forEach(T=>{const $=T.slice(0,T.length-1).split(" ").join("-");t=t.replace(T,$),e.push("spaceSeparatedSetPattern1")}),_=t.match(/ \d \d$/),_==null||_.forEach(T=>{const $=" "+T.slice(1).split(" ").join("-");t=t.replace(T,$),e.push("spaceSeparatedSetPattern2")});const I=/^\d, *\d\/\d, *\d/;if(I.test(t)){const T=t.match(I)[0],$=T.split("/").map(N=>`(${N})`).join(" ")+" ";t=t.replace(T,$),e.push("slashCommaSetPattern")}const P=/\(6-\)/g;P.test(t)&&(t=t.replace(P,"(6-0)"),e.push("missingZeroPattern2"));const y=new RegExp("(?<!-)(\\d+)\\/(\\d+)(?!-)","g");if(y.test(t)){const T=t.match(y),$=new RegExp("(?<!-)(\\d+)\\/(\\d+)(?!-)");let N=t;T.forEach(E=>{const[A,U]=E.match($).slice(1),C=`${A}-${U}`;N=N.replace(E,C)}),t=N,e.push("slashSetPattern")}const S=/(.*)\s(1\d)\s(\d+)$/;if(S.test(t)){const[T,$,N]=t.match(S).slice(1);T.replace(/\D/g,"").length>=4&&(t=T+` ${$}${N}`,e.push("spaceSeparatedSuperPattern"))}const O=/(^|\s)(\d+-\d+)\s(\d+)(\s|$)/g;for(const T of t.match(O)||[]){const[$,N,E,A]=T.match(/(^|\s)(\d+-\d+)\s(\d+)(\s|$)/).slice(1),[U,C]=N.split("-").map(D=>parseInt(D));Math.abs(U-C)===1&&(t=t.replace(T,`${$}${N}(${E})${A}`),e.push("spaceSeparatedSetPattern"))}const b=/\d-\d \(\d{1,2}\)(\s|$|,)/g;for(const T of t.match(b)||[]){const $=/(\d-\d) \((\d{1,2})\)(\s|$|,)/,[N,E,A]=T.match($).slice(1),[U,C]=N.split("-").map(D=>parseInt(D));Math.abs(U-C)===1&&(t=t.replace(T,`${N}(${E})${A}`),e.push("floatingTiebreakPattern2"))}const w=/(^|\s)(\d \d)\(/g;for(const T of t.match(w)||[]){const $=/(^|\s)(\d \d)\(/,[N,E]=T.match($).slice(1);t=t.replace(T,`${N}${E.split(" ").join("-")}(`),e.push("spacedTiebreakPattern")}return{score:t,applied:e}}function QH({score:t,matchUpStatus:e}){var r;let n=t==null?void 0:t.split(" ");t=n.map(l=>{if(l.endsWith("]")){const c=l.split("[");if(Da(c[0]))return c[0]+`(${c[1].slice(0,c[1].length-1)})`}return l}).join(" ");const o=new RegExp(/(\([\d ]+\))/g);if(o.test(t))for(const l of t.match(o)){let u=(r=l.replace(" ","-").match(/\((.*)\)/))==null?void 0:r[1];if(Ct(u)&&(u==null?void 0:u[0])>2){if([2,4].includes(u.length))u=u.split("").join("-");else if(u.length===3){const p=u.indexOf("1");u=ad(u.split(""),p)}}t=t.replace(l,`(${u})`)}n=t==null?void 0:t.split(" ");let i=new RegExp(/^(\d[-/]+\d)\((\d+)[-/]+(\d+)\)$/);const s=n.length-1;t=n.map((l,c)=>{const u=[void 0,"","COMPLETED"].includes(e)||c!==s;if(i.test(l)&&u){const[p,d,v]=Array.from(l.match(i)).slice(1),f=Math.min(d,v);return`${p}(${f})`}return l}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^(\d{2})\((\d+)\)$/),t=n.map(l=>{if(i.test(l)){const[c,u]=Array.from(l.match(i)).slice(1),p=c.split("");return`${p[0]}-${p[1]}(${u})`}return l}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^\((\d[-/]+\d)\)(\d+)$/),t=n.map(l=>{if(i.test(l)){const[c,u]=Array.from(l.match(i)).slice(1);return Da(c)?`${c}(${u})`:c}return l}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^1-0\((\d+)\)$/),t=n.map(l=>{if(i.test(l)){const[c]=l.match(i).slice(1);return`[${c<9?10:parseInt(c)+2}-${c}]`}return l}).join(" ");const a=/\((\d)+0 /;if(a.test(t)){const l=t.match(a)[1];t=t.replace(a,`(${l}) `)}return{score:t}}function JH({score:t,attributes:e,identifier:r}){var n;if(typeof t!="string")return{score:t,identifier:r};const o=new RegExp(/\([\d,/ ]+\)/g),i=t.match(o);for(const d of i||[]){const v=d.match(/^\((.*)\)$/),f=(n=v==null?void 0:v.slice(1))==null?void 0:n[0],h=t.split(d)[0].split(")").reverse()[0].replace(/\D/g,"");if((f==null?void 0:f.length)===2&&(h==null?void 0:h.length)>=2){const I=h.slice(h.length-2).split("").map(y=>parseInt(y));if(Math.abs(I[0]-I[1])===1)continue}const g=cS(f),_=ld(g);t=t.replace(d,`(${_})`).trim()}const s=new RegExp(/\[[\d,/ ]+\]/g),a=t.match(s);a==null||a.forEach(d=>{const v=cS(d.match(/^\[(.*)\]$/)[1]);t=t.replace(d,`(${v}) `).trim()});const l=[")","]"],c=[")(","), (",") (",")[",") [","](","] ("];if(t.startsWith("(")&&l.some(d=>t.endsWith(d))&&c.some(d=>t.includes(d))){let d="";const v=t.split(/[)\]]/).filter(Boolean).map(_=>(_.startsWith(",")&&(_=_.slice(1)),_.trim())),f=v.every(_=>_.includes(",")||sd(_)),m=v.every(_=>_.includes("/")||sd(_)),h=v.every(_=>_.includes("-")||sd(_)),g=f&&","||h&&"-"||m&&"/";if(g){let _;v.forEach(I=>{if(I.startsWith("("))if(_==="set"&&(d+=" "),I.includes(g))d+=I.slice(1).split(g).map(P=>P.trim()).join("-"),_="set";else{const P=I.slice(1);d+=`(${P}) `,_="tiebreak"}else if(I.startsWith("[")){const P=I.slice(1).split(g).map(S=>parseInt(S.trim())),y=Math.min(...P);_==="set"?d+=`(${y}) `:d+=`[${P.join("-")}] `,_="tiebreak"}}),t=d.trim()}}const u=Nr(t.split(""));u["("]===1&&u[")"]===1&&t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,t.length-1),u["-"]===1&&Da(t)&&Ct(e==null?void 0:e.removed)&&(t=t+`(${e.removed})`,e.removed=void 0));const p=/\(\)/g;return p.test(t)&&(t=t.replace(p,"").trim()),{score:t}}function uS({score:t}){const e=t.split(""),r=[];let n;const o=()=>n=[void 0,void 0,void 0],i=()=>{let a=`${n[0]}-${n[1]}`;return n[2]&&(a+=` (${n[2]})`),o(),n.push(n),a};o();const s=()=>n[0]!==void 0&&n[1]!==void 0&&Math.abs(parseInt(n[0])-parseInt(n[1]));for(;e.length;){const a=e.shift(),l=Ct(a)&&parseInt(a),c=n[0]!==void 0&&n[1]!==void 0;if(Ct(l)){if(n[0]===void 0){n[0]=l;continue}if(n[1]===void 0&&(n[1]=l,s()||0>1)){r.push(i()),n=[void 0,void 0];continue}if(c&&e.length===1&&Ct(e[0])){const u=e.pop();n[0]=n[0].toString()+n[1].toString(),n[1]=u,r.push(i()),n=[void 0,void 0]}c&&s()}}return{sets:r}}function Gv(t){const e=t.indexOf("1"),r=t.split(""),n=r.every(o=>!isNaN(o));if(n&&t.length===3&&e===0){const o=ad(r,e);if(o)return o}if(n&&t.length===7&&e>3){const o=r.slice(4),i=ad(o,e-4);if(i)return`${r[0]}-${r[1]} ${r[2]}-${r[3]} ${i}`}}function dS(t){let{score:e}=t;const{applied:r,matchUpStatus:n}=t,o=e==null?void 0:e.toString().split(""),i=o==null?void 0:o.every(a=>Ct(a)),s=a=>Math.abs(a[0]-a[1]);if(typeof e=="number"||i){e=e.toString().toLowerCase(),i&&(e=o.join(""));const a=i?o.map(l=>parseInt(l)):e.split("").map(l=>parseInt(l));if(uS({score:e}),a.length,e.length===3&&s(a.slice(0,2))===1){const[l,c,u]=a;e=`${l}-${c}(${u})`,r.push("numericTiebreakPattern1")}else if(e.length===3&&a[0]===1){const[l,c,u]=a;e=`[${l}${c}-${u}]`,r.push("numericTiebreakPattern2")}else if(e.length===4&&s(a.slice(0,2))===1&&"987654".split("").includes(a[0].toString())){const[l,c,u,p]=a,d=Math.min(u,p);e=`${l}-${c}(${d})`,r.push("numericTiebreakPattern3")}else if(e.length===4&&a[0]===1&&a[2]===1){const[l,c,u,p]=a;e=`[${l}${c}-${u}${p}]`,r.push("bigSuper")}else if(e.length===4){const[l,c,u,p]=a;e=`${l}${c} ${u}${p}`,r.push("split4")}else if(e.length===5&&s(a.slice(0,2))===1){const[l,c,u,p,d]=a;e=`${l}-${c}(${u}) ${p}-${d}`,r.push("numericTiebreakPattern4")}else if(e.length===5&&s(a.slice(3))===1){const[l,c,u,p,d]=a;e=`${l}-${c} ${u}-${p}(${d})`,r.push("numericTiebreakPattern5")}else if(a.length===7)if(s(a.slice(0,2))>1&&s(a.slice(2,4))>1&&a[4]===1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c} ${u}-${p} [${d}${v}-${f}]`,r.push("numericTiebreakPattern6")}else if(s(a.slice(0,2))===1&&s(a.slice(3,5))>1&&s(a.slice(5,7))>1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c}(${u}) ${p}-${d} ${v}-${f}`,r.push("numericTiebreakPattern7")}else if(s(a.slice(0,2))>1&&s(a.slice(2,4))===1&&s(a.slice(5,7))>1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c} ${u}-${p}(${d}) ${v}-${f}`,r.push("numericTiebreakPattern8")}else if(s(a.slice(0,2))>1&&s(a.slice(2,4))>1&&s(a.slice(4,6))===1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c} ${u}-${p} ${d}-${v}(${f})`,r.push("numericTiebreakPattern9")}else e=e.slice(0,2)+" "+e.slice(2,4)+" "+e.slice(4),r.push("numericMatchTiebreakPattern");else if(e.length%2){const l=Gv(e);l&&e!==l&&r.push("parsedSuperPattern"),e=l||e}else{const l=qt(e.split(""),2).map(h=>h.join("")),c=l.map(h=>{const[g,_]=h.split("").map(y=>parseInt(y)),I=Math.abs(g-_),P=g>_?1:2;return I>1&&P||P*-1}),u=c.reduce((h,g)=>h>0&&g>0,1),p=Nr(c),d=c.map(h=>Math.abs(h)),v=Nr(d),f=c[0]<0,m=!f&&c[1]<0;if(c[0]>0&&c[1]>0&&c[0]!==c[1])e=[l.slice(0,2).join(" "),l.slice(2).join("-")].join(" "),r.push("numeric3rdSetTiebreakPattern");else if(u)e=l.join(" "),r.push("chunkSplit");else if(a.length==6){if(p[1]==2||p[2]===2)if(!Object.values(v).includes(3))e=l.join(" "),r.push("chunkSplit");else{const[h,g,_,I,P,y]=a,S=c.reduce((O,b,w)=>b<0?w:O,void 0);if(S===0){const O=Math.min(_,I);e=`${h}-${g}(${O}) ${P}-${y}`,r.push("chunkSplitTiebreak1")}else if(S===1){const O=Math.min(P,y);e=`${h}-${g} ${_}-${I}(${O})`,r.push("chunkSplitTiebreak2")}else e=`${h}-${g} ${_}-${I}`,r.push("chunkSplitTrimExtraneous")}}else if(a.length===8){const[h,g,_,I,P,y,S,O]=a;f||m?a[5]===1&&(f?e=`${h}-${g}(${_}) ${I}-${P} [${y}${S}-${O}]`:e=`${h}-${g} ${_}-${I}(${P}) [${y}${S}-${O}]`):(c[0],c[1])}}}return{score:e,applied:r,matchUpStatus:n}}function pS(t){const e=[0,0],r=[],n=t.split(" "),o=/(\d+)-(\d+)/;n.forEach(l=>{if(o.test(l)){const c=l.match(o).slice(1).map(p=>parseInt(p)),u=c[0]>c[1]&&1||c[1]>c[0]&&2;u&&(e[u-1]+=1,r.push(u))}});const i=e[0]>e[1]&&1||e[1]>e[0]&&2,s=e[0]>0&&e[0]===e[1],a=e.reduce((l,c)=>l+c,0);return{setsWon:e,setsTied:s,setWinners:r,totalSets:a,winningSide:i}}function ZH({score:t,matchUpStatus:e,attributes:r}){const n=[];let o;const i=t.split(" "),s=i.length;t=i.map((u,p)=>{if(new RegExp(cc).test(u)){const v=u.slice(3),f=u.slice(0,3),m=f.split("-");if(!Da(f)&&!e){const h=Math.max(...m),g=f.indexOf(h),_=[h,h-1];return(g?_.reverse().join("-"):_.join("-"))+v}}else if(u.length===2&&Ct(u))return u.split("").join("-");u=ld(u);const d=new RegExp(`^${kv}$`).test(u)&&"super"||new RegExp(`^${cc}$`).test(u)&&"tiebreak"||new RegExp(`^${id}$`).test(u)&&"standard"||"unknown";if(n.push(d),s>1&&d==="standard"&&p<2){const[v,f]=u.split("-"),m=Math.abs(parseInt(v)-parseInt(f)),h=Math.max(v,f),g=Math.min(v,f),_=[parseInt(v),parseInt(f)].indexOf(g);if(h>9&&m>2){const I=h.toString().split(""),P=I.find(y=>parseInt(y)>g||p&&parseInt(y)<=o)||I[0];P&&(u=_?[P,g].join("-"):[g,P].join("-"))}h>(o||0)&&(o=h)}if(d==="standard"){const[v,f]=u.split("-");if(!Math.abs(parseInt(v)-parseInt(f))&&e!=="RETIRED")return""}return u}).filter(Boolean).join(" ");const{setsWon:a,setWinners:l,totalSets:c}=pS(t);if(c===1&&(r==null?void 0:r.removed)==="6"&&(t+=" 6-0"),t.split(" ").length>2&&Math.max(...a)>=2&&l[0]===l[1]&&(t=t.split(" ").slice(0,2).join(" ")),Math.max(...a)>2){const u=[0,0];t=t.split(" ").map((p,d)=>(u[l[d]]+=1,Math.max(...u)>2?void 0:p)).filter(Boolean).join(" ")}return{score:t,profile:n}}function XH({score:t}){const{setsTied:e,winningSide:r}=pS(t),n=/\s\((\d+)\)$/;if(!r&&e&&n.test(t)){const a=t.match(n).slice(1)[0],l=a<=8?10:a+2;t=t.replace(n,` [${l}-${a}]`)}const o=t.split(" "),i=o[o.length-1];if(!i.includes("-")||i.indexOf("(")>0)return{score:t};let s=i.split("(").join("").split(")").join("").split("-");if(!s.every(a=>Ct(a)))return{score:t};if(s[0]==="76"){const a=s[1].length===2?Math.min(...s[1].split("").map(l=>parseInt(l))):s[1];t=[...o.slice(0,o.length-1),`7-6(${a})`].join(" ")}else{s=s.map(c=>parseInt(c));const a=Math.max(...s);let l=Math.abs(s[0]-s[1]);if(a>=10){if(l>2&&s.every(c=>+c>=10)){const c=s.map(u=>u===a?u-10:10).sort();l=Math.abs(c[0]-c[1]),l>2&&(s=c)}t=[...o.slice(0,o.length-1),`[${s.join("-")}]`].join(" ")}else o.length===3&&a>=7&&l>2&&(t=[...o.slice(0,o.length-1),`[${s.join("-")}]`].join(" "))}return{score:t}}function eq({score:t}){return t=(t==null?void 0:t.toString().toLowerCase())||"",{score:t}}function tq({score:t,applied:e}){return typeof t!="string"?{score:t}:(t.toLowerCase().includes("o")&&(t=t.toLowerCase().split(" ").map(r=>r.split("o").join("0")).join(" "),e.push("replaceOh")),{score:t,applied:e})}function rq({score:t,applied:e}){return typeof t!="string"?{score:t}:(t=t.toLowerCase().split(" ").map(r=>{if(/^\d+$/.test(r)&&r.length>2){const n=r.indexOf("1");if(r.length%2){if(r.length===3&&n===0){const o=ad(r.split(""),n);return e.push("getSuper"),o}}else{const{score:o,applied:i}=dS({score:r,applied:[]});o!==r&&(r=o,e.push(...i))}}return r}).join(" "),{score:t,applied:e})}function nq({score:t,applied:e}){return typeof t!="string"?{score:t}:[3,4].includes(t.length)&&Gv(t)?{score:Gv(t)}:(t=t.toLowerCase().split(" ").map(r=>{if(/^\d+$/.test(r)&&r.length===1){e.push("removeErroneous1");return}return r}).filter(Boolean).join(" "),{score:t,applied:e})}function oq({score:t,applied:e}){return["walkover","wo","w/o","w-o"].includes(t==null?void 0:t.toString().toLowerCase())?(e.push("handleWalkover"),{matchUpStatus:"walkover",score:"",applied:e}):{score:t}}function iq({score:t,profile:e,applied:r}){var n;t=t==null?void 0:t.toString().toLowerCase();const o=/^(.*\d+.*)(ret|con)+[A-Za-z ]*$/;if(o.test(t)){const[l]=t.match(o).slice(1);return r.push("handleRetired"),{score:l.trim(),matchUpStatus:"retired",applied:r}}const i=(n=e==null?void 0:e.matchUpStatuses)==null?void 0:n.retired,a=["rtd",...Array.isArray(i)?i:[i].filter(Boolean)].find(l=>t==null?void 0:t.endsWith(l));return a?(r.push("handleRetired"),{matchUpStatus:"retired",score:t==null?void 0:t.replace(a,"").trim(),applied:r}):{score:t}}function sq({score:t,attributes:e}){(t.endsWith(" am")||t.endsWith(" pm"))&&(t=""),t=t.replace(/[A-Za-z]+/g,"").trim(),[".",","].some(o=>t.endsWith(o))&&(t=t.slice(0,t.length-1));const r="()/-".split("").some(o=>t.includes(o));/ \d$/.test(t)&&r&&(e={removed:t.slice(t.length-2).trim()},t=t.slice(0,t.length-2));const n=/(.*)[A-Za-z]+$/;return n.test(t)&&(t=t.match(n).slice(1)[0].trim()),{score:t,attributes:e}}function aq({score:t}){return new RegExp(/-\d+\/\d+-/).test(t)&&(t=t.split("/").join(" ")),{score:t}}function lq({score:t}){const e=new RegExp(/^\d+\/\d+/),r=t.split(" ");r.some(o=>e.test(o))&&(t=r.map(o=>e.test(o)?o.replace("/","-"):o).join(" "));const n=/^(\d+), *(\d+)$/;if(n.test(t)){const[o,i]=t.match(n).slice(1);t=[o,i].join("-")}return{score:t}}function cq({score:t}){const e=new RegExp(/\(\d+\/\d+\)/g),r=t.match(e);for(const n of r||[]){const o=n.replace("/","-");t=t.replace(n,o)}return{score:t}}function uq({score:t}){if(t.includes(",")){const e=t.split(",").map(o=>o.trim()),r=o=>/\d \d/.test(o);e.every(r)&&(t=e.map(o=>{const i=/\d+ \d+/g;for(const s of o.match(i)){const[a,l]=s.match(/(\d+) (\d+)/).slice(1);o=o.replace(s,`${a}-${l}`)}return o}).join(" "))}if(t.includes(" ")){const e=t.replace(/[ ,]/g,"");e.split("").every(n=>Ct(n))&&e.length===4&&(t=e)}return{score:t}}function dq({score:t}){const e=new RegExp(/^\[\d+\](.*)$/);e.test(t)&&(t=t.match(e).slice(1)[0].trim());const r=/\(,/g;return r.test(t)&&(t=t.replace(r,"(")),{score:t}}const pq={handleTiebreakSlashSeparation:cq,handleSetSlashSeparation:aq,punctuationAdjustments:qH,handleGameSeparation:lq,joinFloatingTiebreak:YH,handleBracketSpacing:zH,handleSpaceSeparator:uq,separateScoreBlocks:rq,matchKnownPatterns:KH,removeDanglingBits:sq,removeErroneous:nq,handleWalkover:oq,properTiebreak:QH,handleNumeric:dS,handleRetired:iq,containedSets:JH,sensibleSets:ZH,stringScore:eq,superSquare:XH,setBuilder:uS,excisions:dq,replaceOh:tq};let Wv={};const fq=["handleNumeric","handleWalkover","handleRetired","replaceOh","stringScore","punctuationAdjustments","excisions","handleSpaceSeparator","matchKnownPatterns","removeDanglingBits","handleBracketSpacing","matchKnownPatterns","containedSets","separateScoreBlocks","handleGameSeparation","removeErroneous","joinFloatingTiebreak","handleSetSlashSeparation","handleTiebreakSlashSeparation","properTiebreak","sensibleSets","superSquare"],vq=["handleNumeric","separateScoreBlocks","sensibleSets","superSquare"];function mq(t){const{score:e,sheetName:r,identifier:n,fileName:o,stepLog:i,fullLog:s,profile:a}=t,l=[];let c,u=[],p,d,v=e;const f=h=>{h.forEach(g=>{d=pq[g]({profile:a,identifier:n,matchUpStatus:c,attributes:p,applied:u,score:v});const _=d.score!==v;_&&l.push({method:g,score:d.score}),i&&(s||_||d.matchUpStatus!==c)&&console.log(c?{score:d.score,matchUpStatus:c}:{score:d.score},g),d.matchUpStatus&&(c=d.matchUpStatus),d.attributes&&(p=d.attributes),d.applied&&(u=d.applied),v=d.score})};f(fq);let m=lS(v);return m||(v=e.toString().replace(/\D/g,""),p!=null&&p.removed&&(p.removed=void 0),f(vq),m=lS(v),m||(v="")),u.forEach(h=>{Wv[h]||(Wv[h]=0),Wv[h]+=1}),{matchUpStatus:c==null?void 0:c.toUpperCase(),modifications:l,attributes:p,isValid:m,score:v}}var hq=Object.defineProperty,fS=Object.getOwnPropertySymbols,gq=Object.prototype.hasOwnProperty,_q=Object.prototype.propertyIsEnumerable,vS=(t,e,r)=>e in t?hq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mS=(t,e)=>{for(var r in e||(e={}))gq.call(e,r)&&vS(t,r,e[r]);if(fS)for(var r of fS(e))_q.call(e,r)&&vS(t,r,e[r]);return t};const{FACTORY:hS}=cI;function cd({tournamentRecord:t,value:e}){const{extension:r}=xr({element:t,name:hS}),n={name:hS,value:mS(mS({},r==null?void 0:r.value),e)};it({element:t,extension:n})}function ki(t){const{mutationStatus:e,tournamentId:r,directives:n,timeStamp:o}=t||{},{topics:i}=Rn();for(const s of[...i].sort(Iq)){const a=CL({topic:s});a&&U_({topic:s,notices:a})}e&&o&&i.includes(pP)&&U_({notices:[{tournamentId:r,directives:n,timeStamp:o}],topic:pP})}const gS={[vP]:5,[fP]:5,[mP]:5,[dP]:5,[uP]:5,[lP]:5,[lk]:5,[ck]:5,[cP]:1,[zf]:1,[rr]:5,[vs]:5,[aP]:4,[oP]:4,[iP]:4,[sP]:4,[qf]:3,[tP]:2};function Iq(t,e){return(gS[e]||0)-(gS[t]||0)}function Ms({tournamentRecords:t,convertExtensions:e,ignoreDisabled:r,venueIds:n=[],dates:o}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const i=[],s=[],a=[],l=[];return Object.keys(t).forEach(u=>{const p=t[u];for(const d of p.venues||[])if(p.venues,!(n.length&&!n.includes(d.venueId))){if(r){const{extension:v}=xr({name:gn,element:d});if(v!=null&&v.value)continue}i.includes(d.venueId)||(l.push(de(d,e,!0)),i.push(d.venueId));for(const v of d.courts||[])if(!s.includes(v.courtId)){if(r&&o){const{extension:m}=xr({name:gn,element:v});if(JI({extension:m,dates:o}))continue}const{inContextCourt:f}=eP({convertExtensions:e,ignoreDisabled:r,venue:d,court:v});a.push(f),s.push(v.courtId)}}}),{courts:a,venues:l}}function Hv({tournamentRecords:t,requireCourts:e,dates:r}){return typeof t!="object"||!Object.keys(t).length?{error:ke}:Object.keys(t).reduce((o,i)=>{const s=t[i],{venues:a}=Yf({tournamentRecord:s,dates:r});return a==null||a.forEach(l=>{const{venueId:c,courts:u}=l;(!e||(u==null?void 0:u.length))&&!o.venueIds.includes(c)&&(o.venues.push(l),o.venueIds.push(c))}),o},{venues:[],venueIds:[]})}var Pq=Object.defineProperty,_S=Object.getOwnPropertySymbols,yq=Object.prototype.hasOwnProperty,Sq=Object.prototype.propertyIsEnumerable,IS=(t,e,r)=>e in t?Pq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,PS=(t,e)=>{for(var r in e||(e={}))yq.call(e,r)&&IS(t,r,e[r]);if(_S)for(var r of _S(e))Sq.call(e,r)&&IS(t,r,e[r]);return t};function uc({duplicateValues:t=!0,creationTime:e=!0,removePriorValues:r,timeItem:n,element:o}){if(!n)return{error:h_};if(!o)return{error:_e,info:Vf};const i=n&&Object.keys(n),s=["itemType","itemValue"];if(!(s.filter(c=>i.includes(c)).length===s.length))return{error:m_};if(!o.timeItems)o.timeItems=[];else{const{itemType:c,itemSubTypes:u,itemValue:p}=n,{timeItem:d}=Un({itemSubTypes:u,itemType:c,element:o});if(JSON.stringify(d==null?void 0:d.itemValue)===JSON.stringify(p)&&!t)return PS({},V)}if(n.itemSubTypes&&!n.itemSubTypes.length&&delete n.itemSubTypes,e){const c=new Date().toISOString();Object.assign(n,{createdAt:c})}return r&&(o.timeItems=o.timeItems.filter(({itemType:c})=>n.itemType!==c)),r&&!n.itemValue||o.timeItems.push(n),PS({},V)}function yS({creationTime:t=!0,removePriorValues:e,tournamentRecord:r,duplicateValues:n,participantId:o,timeItem:i}){if(!r)return{error:re};if(!o)return{error:Et};const s=Qo({tournamentRecord:r,participantId:o});return s.error?s:uc({element:s.participant,removePriorValues:e,duplicateValues:n,creationTime:t,timeItem:i})}function Fo(t){const{removePriorValues:e,tournamentRecord:r,duplicateValues:n,creationTime:o,timeItem:i}=t;return r?uc({element:r,removePriorValues:e,duplicateValues:n,creationTime:o,timeItem:i}):{error:re}}function li(t){const{removePriorValues:e,duplicateValues:r,creationTime:n,timeItem:o,event:i}=t;return i?uc({removePriorValues:e,duplicateValues:r,element:i,creationTime:n,timeItem:o}):{error:Ar}}var Oq=Object.defineProperty,SS=Object.getOwnPropertySymbols,bq=Object.prototype.hasOwnProperty,Tq=Object.prototype.propertyIsEnumerable,OS=(t,e,r)=>e in t?Oq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wq=(t,e)=>{for(var r in e||(e={}))bq.call(e,r)&&OS(t,r,e[r]);if(SS)for(var r of SS(e))Tq.call(e,r)&&OS(t,r,e[r]);return t};function Dr({removePriorValues:t,tournamentRecord:e,duplicateValues:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:s,event:a}){const{matchUp:l}=lt({drawDefinition:n,event:a,matchUpId:i});if(!l)return{error:ir};const c=uc({removePriorValues:t,element:l,duplicateValues:r,timeItem:s});return o||Ze({tournamentId:e==null?void 0:e.tournamentId,eventId:a==null?void 0:a.eventId,context:"addTimeItem",drawDefinition:n,matchUp:l}),c}function Eq({tournamentRecord:t,drawDefinition:e,matchUpId:r,event:n}){const{matchUp:o}=lt({drawDefinition:e,event:n,matchUpId:r});return o?(o.timeItems=[],Ze({tournamentId:t==null?void 0:t.tournamentId,context:"resetTimeItems",eventId:n==null?void 0:n.eventId,drawDefinition:e,matchUp:o}),wq({},V)):{error:ir}}function ud({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,courtDayDate:i,matchUpId:s,courtIds:a}){var l,c;if(!r&&!e)return{error:re};if(!s)return{error:Vt};const u=lt({drawDefinition:n,matchUpId:s});if(u.error)return u;if(((l=u==null?void 0:u.matchUp)==null?void 0:l.matchUpType)!==hn)return{error:tn};if(!(a===void 0||Array.isArray(a)&&a.length&&a.every(f=>typeof f=="string")))return{error:X,context:{courtIds:a}};let d;if(a){const f=e?r:r&&{[r.tournamentId]:r},m=Ms({tournamentRecords:f});if(m.error)return m;const h=(c=m.courts)==null?void 0:c.filter(g=>a.includes(g.courtId));if((h==null?void 0:h.length)!==a.length)return{error:X,context:{courtIds:a}};d=h==null?void 0:h.map(g=>({venueId:g.venueId,courtId:g.courtId}))}return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,timeItem:{itemType:Xo,itemDate:i,itemValue:d}})}function ja({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,venueId:s}){if(!r)return{error:re};if(!i)return{error:Vt};if(s){const l=Zo({tournamentRecords:e,tournamentRecord:r,venueId:s});if(l.error)return l}return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:{itemType:jl,itemValue:s}})}function Ds({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,courtDayDate:i,matchUpId:s,courtId:a}){var l;if(!r&&!e)return{error:re};if(!s)return{error:Vt};if(a){const u=ms({tournamentRecords:e,tournamentRecord:r,courtId:a});if(u.error)return u;const p=(l=u.venue)==null?void 0:l.venueId;ja({tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,venueId:p})}return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,timeItem:{itemType:hs,itemDate:i,itemValue:a}})}function $q({matchUps:t,matchUpId:e}){if(!Array.isArray(t))return{error:X};const r=t.find(a=>a.matchUpId===e),{drawId:n,eventId:o,structureId:i,tournamentId:s}=r||{};return{matchUpId:e,drawId:n,eventId:o,structureId:i,tournamentId:s}}var Nq=Object.defineProperty,bS=Object.getOwnPropertySymbols,Uq=Object.prototype.hasOwnProperty,Aq=Object.prototype.propertyIsEnumerable,TS=(t,e,r)=>e in t?Nq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Cq=(t,e)=>{for(var r in e||(e={}))Uq.call(e,r)&&TS(t,r,e[r]);if(bS)for(var r of bS(e))Aq.call(e,r)&&TS(t,r,e[r]);return t};function Gi(t){let e=t.matchUp;const{removePriorValues:r,tournamentRecord:n,drawDefinition:o,disableNotice:i,scheduledTime:s,matchUpId:a}=t;if(!a)return{error:Vt};if(!aa(s))return{error:rn};if(!e){const f=lt({drawDefinition:o,matchUpId:a});if(f.error)return f;e=f.matchUp}const l=Re(s),c="addMatchUpScheduledTime";if(l){const f=Ui({matchUp:e}).scheduledDate;if(f&&f!==l)return k({info:`date in time: ${l} does not corresponde to scheduledDate: ${f}`,result:{error:rn},stack:c})}const u=Xf({matchUp:e}).timeModifiers||[];if(u!=null&&u.length){const f=qv({disableNotice:!0,removePriorValues:r,tournamentRecord:n,timeModifiers:[],drawDefinition:o,matchUpId:a,matchUp:e});if(f!=null&&f.error)return f}const d=ns(s,!0,!0);return Dr({duplicateValues:!1,removePriorValues:r,tournamentRecord:n,drawDefinition:o,disableNotice:i,matchUpId:a,timeItem:{itemType:Fl,itemValue:d}})}function qv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,timeModifiers:o,matchUpId:i,matchUp:s}){if(!i)return{error:Vt};if(o!==void 0&&!Array.isArray(o))return{error:X,info:or("timeModifiers")};if(!s){const d=lt({drawDefinition:r,matchUpId:i});if(d.error)return d;s=d.matchUp}let a=Xf({matchUp:s}).timeModifiers||[];const l=o.filter(d=>!a.includes(d));if(o.length&&!l.length)return Cq({},V);if(l.some(d=>jP.includes(d))){a=a.filter(v=>!jP.includes(v));const d=Gi({disableNotice:!0,removePriorValues:t,scheduledTime:"",tournamentRecord:e,drawDefinition:r,matchUpId:i});if(d.error)return d}const u=o!=null&&o.length?[...l,...a]:void 0;return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:{itemType:DP,itemValue:u}})}var Mq=Object.defineProperty,Dq=Object.defineProperties,jq=Object.getOwnPropertyDescriptors,wS=Object.getOwnPropertySymbols,Rq=Object.prototype.hasOwnProperty,Fq=Object.prototype.propertyIsEnumerable,ES=(t,e,r)=>e in t?Mq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$S=(t,e)=>{for(var r in e||(e={}))Rq.call(e,r)&&ES(t,r,e[r]);if(wS)for(var r of wS(e))Fq.call(e,r)&&ES(t,r,e[r]);return t},xq=(t,e)=>Dq(t,jq(e));function Qn(t,e){const r=M_.test(t)?t:at(t),n=Re(t)||Re(e)||vn(new Date);return new Date(`${n}T${r}`).getTime()}function dd({errorOnAnachronism:t=!1,checkChronology:e=!0,matchUpDependencies:r,inContextMatchUps:n,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,disableNotice:l,drawMatchUps:c,matchUpId:u,schedule:p,event:d}){var v;if(!p)return{error:_e,info:"Missing schedule"};if(!a)return{error:ue};if(!u)return{error:Vt};const f="drawEngine.addMatchUpScheduleItems";let m,h;if(c)m=c.find(E=>E.matchUpId===u);else{const E=lt({drawDefinition:a,event:d,matchUpId:u});if(E.error)return E;m=E.matchUp}const{endTime:g,courtId:_,courtIds:I,courtOrder:P,resumeTime:y,scheduledDate:S,scheduledTime:O,startTime:b,stopTime:w,timeModifiers:T,venueId:$}=p;e&&(!r||!n)&&({matchUpDependencies:r,matchUps:n}=cn({drawDefinition:a}));const N=(v=r==null?void 0:r[u])==null?void 0:v.matchUpIds;if(p.scheduledDate&&e&&N){const E=n==null?void 0:n.filter(A=>{var U,C;return(((U=A.schedule)==null?void 0:U.scheduledDate)||Re((C=A.schedule)==null?void 0:C.scheduledTime))&&N.includes(A.matchUpId)}).map(({schedule:A})=>{const U=au(A);return new Date(U).getTime()});if(E!=null&&E.length){const A=au(p),U=new Date(A).getTime();if(Math.max(...E)>=U){if(t)return k({result:{error:Bg},stack:f});h=Bg}}}if(S!==void 0){const E=zv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,scheduledDate:S,matchUpId:u});if(E!=null&&E.error)return k({result:E,stack:f,context:{scheduledDate:S}})}if(O!==void 0){const E=Gi({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,scheduledTime:O,matchUpId:u,matchUp:m});if(E!=null&&E.error)return k({result:E,stack:f,context:{scheduledTime:O}})}if(b!==void 0){const E=Kv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,startTime:b,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{startTime:b}})}if(w!==void 0){const E=Jv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,stopTime:w,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{stopTime:w}})}if(y!==void 0){const E=Zv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,resumeTime:y,matchUpId:u,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{resumeTime:y}})}if(g!==void 0){const E=Qv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,endTime:g,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{endTime:g}})}if(I!==void 0){const E=ud({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,courtIds:I});if(E!=null&&E.error)return k({result:E,stack:f,context:{courtIds:I}})}if(_!==void 0&&S!==void 0){const E=Ds({courtDayDate:S,disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,matchUpId:u,courtId:_});if(E!=null&&E.error)return k({result:E,stack:f,context:{courtId:_}})}if($!==void 0){const E=ja({disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,matchUpId:u,venueId:$});if(E!=null&&E.error)return k({result:E,stack:f,context:{venueId:$}})}if(P!==void 0&&ht(P)){const E=Yv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,courtOrder:P,matchUpId:u});if(E!=null&&E.error)return k({result:E,stack:f,context:{courtOrder:P}})}if(T!==void 0){const E=qv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,timeModifiers:T,matchUpId:u,matchUp:m});if(E!=null&&E.error)return k({result:E,stack:f,context:{timeModifiers:T}})}return l||Ze({tournamentId:s==null?void 0:s.tournamentId,eventId:d==null?void 0:d.eventId,context:f,drawDefinition:a,matchUp:m}),h?xq($S({},V),{warnings:[h]}):$S({},V)}function zv({scheduledDate:t,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i}){if(!i)return{error:Vt};const s=t&&xn.test(t);if(t&&!s)return{error:Sr};const l={itemValue:Re(t),itemType:Rl};return Dr({duplicateValues:!1,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:l})}function Yv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,courtOrder:o,matchUpId:i}){if(!i)return{error:Vt};if(o&&!ht(o))return{error:X,info:"courtOrder must be numeric"};const s=o&&Te(o);return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:{itemType:MP,itemValue:s}})}function NS({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,participantId:o,officialType:i,matchUpId:s}){if(!s)return{error:Vt};const a={itemType:"SCHEDULE.ASSIGNMENT.OFFICIAL",itemValue:o};return i&&(a.itemSubTypes=[i]),Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:s,timeItem:a})}function Kv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,startTime:i,event:s}){var a;if(!o)return{error:Vt};if(!aa(i))return{error:rn};const{matchUp:l}=lt({drawDefinition:r,event:s,matchUpId:o}),{scheduledDate:c}=Ui({matchUp:l}),p=((a=l==null?void 0:l.timeItems)!=null?a:[]).filter(d=>[ei,No,ti].includes(d==null?void 0:d.itemType)).map(d=>Qn(d.itemValue,c)).reduce((d,v)=>!d||v<d?v:d,void 0);if(!p||Qn(i,c)<p){l!=null&&l.timeItems&&(l.timeItems=l.timeItems.filter(f=>f.itemType!==Hn));const d=ns(i,!0,!0);return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,timeItem:{itemType:Hn,itemValue:d}})}else return{error:Gx}}function Qv({validateTimeSeries:t=!0,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,endTime:s,event:a}){var l;if(!i)return{error:Vt};if(!aa(s))return{error:rn};const{matchUp:c}=lt({drawDefinition:n,event:a,matchUpId:i}),{scheduledDate:u}=Ui({matchUp:c}),d=((l=c==null?void 0:c.timeItems)!=null?l:[]).filter(v=>[Hn,No,ei].includes(v==null?void 0:v.itemType)).map(v=>Qn(v.itemValue,u)).reduce((v,f)=>!v||f>v?f:v,void 0);if(!t||!d||Qn(s,u)>d){c!=null&&c.timeItems&&(c.timeItems=c.timeItems.filter(m=>m.itemType!==ti));const v=ns(s,!0,!0);return Dr({duplicateValues:!1,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:{itemType:ti,itemValue:v}})}else return{error:Bx}}function Jv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,stopTime:i,event:s}){var a;if(!o)return{error:Vt};if(!aa(i))return{error:rn};const{matchUp:l}=lt({drawDefinition:r,event:s,matchUpId:o}),{scheduledDate:c}=Ui({matchUp:l}),u=(a=l==null?void 0:l.timeItems)!=null?a:[];if(u.reduce((h,g)=>g.itemType===ti||h,void 0))return{error:v_};const d=u.filter(h=>[Hn,No,ei].includes(h==null?void 0:h.itemType)).sort((h,g)=>Qn(h.itemValue,c)-Qn(g.itemValue,c)),v=d[d.length-1],f=v&&v.itemType===ei,m=d.filter(h=>!f||h.createdAt!==v.createdAt).map(h=>Qn(h.itemValue,c)).reduce((h,g)=>!h||g>h?g:h,void 0);if(Qn(i,c)>m){if(l!=null&&l.timeItems&&f){const _=v.createdAt;l.timeItems=l.timeItems.filter(I=>I.createdAt!==_)}const g={itemValue:ns(i,!0,!0),itemType:ei};return Dr({duplicateValues:!0,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,timeItem:g})}else return{error:kx}}function Zv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,resumeTime:o,matchUpId:i,event:s}){var a;if(!i)return{error:Vt};if(!aa(o))return{error:rn};const{matchUp:l}=lt({drawDefinition:r,event:s,matchUpId:i}),{scheduledDate:c}=Ui({matchUp:l}),u=(a=l==null?void 0:l.timeItems)!=null?a:[];if(u.reduce((h,g)=>g.itemType===ti||h,void 0))return{error:v_};const d=u.filter(h=>[Hn,No,ei].includes(h==null?void 0:h.itemType)).sort((h,g)=>Qn(h.itemValue,c)-Qn(g.itemValue,c)),v=d[d.length-1],f=v&&v.itemType===No,m=d.filter(h=>!f||h.createdAt!==v.createdAt).map(h=>Qn(h.itemValue,c)).reduce((h,g)=>!h||g>h?g:h,void 0);if(Qn(o,c)>m){if(l!=null&&l.timeItems&&f){const _=v.createdAt;l.timeItems=l.timeItems.filter(I=>I.createdAt!==_)}const g={itemValue:ns(o,!0,!0),itemType:No};return Dr({duplicateValues:!0,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:g})}else return{error:Wx}}var Lq=Object.defineProperty,Vq=Object.defineProperties,Bq=Object.getOwnPropertyDescriptors,US=Object.getOwnPropertySymbols,kq=Object.prototype.hasOwnProperty,Gq=Object.prototype.propertyIsEnumerable,AS=(t,e,r)=>e in t?Lq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,CS=(t,e)=>{for(var r in e||(e={}))kq.call(e,r)&&AS(t,r,e[r]);if(US)for(var r of US(e))Gq.call(e,r)&&AS(t,r,e[r]);return t},MS=(t,e)=>Vq(t,Bq(e));function DS({errorOnAnachronism:t=!1,checkChronology:e=!0,matchUpDependencies:r,tournamentRecords:n,tournamentRecord:o,matchUpDetails:i,matchUpIds:s,schedule:a}){var l,c,u;if(!o)return{error:re};if(!i&&(!s||!Array.isArray(s)))return{error:vl};if(!i&&(!a||typeof a!="object"))return{error:Hx};let p;const d=[];let v=0;if(e&&!r){const h=cn({tournamentRecords:n});r=h.matchUpDependencies,p=h.matchUps}p||(p=((l=Wt({tournamentRecord:o}))==null?void 0:l.matchUps)||[]);const f=p.reduce((h,g)=>{const{matchUpId:_,drawId:I}=g;return h[I]?h[I].push(_):h[I]=[_],h},{}),m=i==null?void 0:i.map(h=>h.matchUpId);for(const h of Object.keys(f)){const{drawDefinition:g}=Jo({tournamentRecord:o,drawId:h}),_=f[h].filter(P=>(s==null?void 0:s.includes(P))||(m==null?void 0:m.includes(P))),I=zr({inContext:!1,drawDefinition:g}).matchUps;for(const P of _){const y=((c=i==null?void 0:i.find(O=>O.matchUpId===P))==null?void 0:c.schedule)||a,S=dd({schedule:y,matchUpDependencies:r,errorOnAnachronism:t,inContextMatchUps:p,tournamentRecords:n,tournamentRecord:o,checkChronology:e,drawDefinition:g,drawMatchUps:I,matchUpId:P});if((u=S==null?void 0:S.warnings)!=null&&u.length&&d.push(...S.warnings),S!=null&&S.success&&(v+=1),S.error)return S}}return d.length?MS(CS({},V),{scheduled:v,warnings:d}):MS(CS({},V),{scheduled:v})}var Wq=Object.defineProperty,Hq=Object.defineProperties,qq=Object.getOwnPropertyDescriptors,jS=Object.getOwnPropertySymbols,zq=Object.prototype.hasOwnProperty,Yq=Object.prototype.propertyIsEnumerable,RS=(t,e,r)=>e in t?Wq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,FS=(t,e)=>{for(var r in e||(e={}))zq.call(e,r)&&RS(t,r,e[r]);if(jS)for(var r of jS(e))Yq.call(e,r)&&RS(t,r,e[r]);return t},xS=(t,e)=>Hq(t,qq(e));function LS({errorOnAnachronism:t,matchUpContextIds:e,tournamentRecords:r,checkChronology:n,matchUpDetails:o,schedule:i}){var s;if(!r)return{error:ke};if(!Array.isArray(e)&&!Array.isArray(o))return{error:X};if((!o||e)&&!i)return{error:_e,info:"schedule is required"};const a=[];let l=0;const{matchUpDependencies:c}=cn({tournamentRecords:r});for(const u of Object.values(r)){const{tournamentId:p}=u,d=e==null?void 0:e.filter(f=>f.tournamentId===p).map(Jt),v=o==null?void 0:o.filter(f=>(f==null?void 0:f.tournamentId)===p);if(d!=null&&d.length||v!=null&&v.length){const f=DS({matchUpDetails:v,matchUpDependencies:c,errorOnAnachronism:t,tournamentRecords:r,tournamentRecord:u,checkChronology:n,matchUpIds:d,schedule:i});if((s=f.warnings)!=null&&s.length&&a.push(...f.warnings),f.scheduled&&(l+=f.scheduled),f.error)return f}}return a.length?xS(FS({},V),{scheduled:l,warnings:a}):xS(FS({},V),{scheduled:l})}function pd({tournamentRecords:t}){return t?Object.keys(t).reduce((r,n)=>{r.tournamentIdMap[n]=[];const i=t[n].events||[],s=i.map(({eventId:l})=>l),a=i.map(l=>(l.drawDefinitions||[]).map(({drawId:c})=>c)).flat();return r.tournamentIdMap[n].push(...s,...a),r.eventIds.push(...s),r.drawIds.push(...a),r},{eventIds:[],drawIds:[],tournamentIdMap:{}}):{error:ke}}function Xv({tournamentRecords:t,eventId:e,drawId:r}){const{tournamentIdMap:n}=pd({tournamentRecords:t});return(n?Object.keys(n):[]).find(i=>e&&(n==null?void 0:n[i].includes(e))||r&&(n==null?void 0:n[i].includes(r)))}var Kq=Object.defineProperty,VS=Object.getOwnPropertySymbols,Qq=Object.prototype.hasOwnProperty,Jq=Object.prototype.propertyIsEnumerable,BS=(t,e,r)=>e in t?Kq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zq=(t,e)=>{for(var r in e||(e={}))Qq.call(e,r)&&BS(t,r,e[r]);if(VS)for(var r of VS(e))Jq.call(e,r)&&BS(t,r,e[r]);return t};function Xq({drawDefinition:t,matchUpStatus:e,matchUpsMap:r,winningSide:n,dualMatchUp:o,tieFormat:i,structure:s,matchUp:a,event:l,score:c}){var u;const p=de(o,void 0,!0);for(const v of(p==null?void 0:p.tieMatchUps)||[])v.matchUpId===a.matchUpId&&(v.winningSide=n,v.score=c,!Gt({score:c})&&!e?Object.assign(v,Zq({},Gu)):e&&(v.matchUpStatus=e));i=i||((u=vr({matchUp:a,structure:s,drawDefinition:t,event:l}))==null?void 0:u.tieFormat);const{winningSide:d}=tc({matchUp:p,drawDefinition:t,matchUpsMap:r,structure:s,tieFormat:i,event:l});return{projectedWinningSide:d}}function e6(t){var e;const{matchUpFormat:r,score:n}=t,o=(e=n==null?void 0:n.sets)==null?void 0:e.length,i=r&&Pr(r),{setFormat:s,finalSetFormat:a,bestOf:l}=i||{},u=l&&o===l&&a||s;return(u==null?void 0:u.timed)||!1}function js({drawPosition:t,matchUps:e=[]}){return{initialRoundNumber:e.filter(({drawPositions:n})=>t&&(n==null?void 0:n.includes(t))).map(({roundNumber:n})=>n).sort(er)[0]}}function kS({structureId:t,matchUpsMap:e,matchUp:r}){const n=r==null?void 0:r.roundPosition,o=n%2?1:-1,i=n+o;return{pairedPreviousMatchUp:xi({matchUpsMap:e,structureId:t}).find(({roundNumber:l,roundPosition:c})=>l===(r==null?void 0:r.roundNumber)&&c===i)}}var t6=Object.defineProperty,r6=Object.defineProperties,n6=Object.getOwnPropertyDescriptors,GS=Object.getOwnPropertySymbols,o6=Object.prototype.hasOwnProperty,i6=Object.prototype.propertyIsEnumerable,WS=(t,e,r)=>e in t?t6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s6=(t,e)=>{for(var r in e||(e={}))o6.call(e,r)&&WS(t,r,e[r]);if(GS)for(var r of GS(e))i6.call(e,r)&&WS(t,r,e[r]);return t},a6=(t,e)=>r6(t,n6(e));function HS({inContextDrawMatchUps:t,sourceMatchUpStatus:e,sourceMatchUpId:r,matchUpsMap:n,matchUp:o}){var i;const s=t.find(l=>l.matchUpId===r),{pairedPreviousMatchUp:a}=kS({structureId:s==null?void 0:s.structureId,matchUp:s,matchUpsMap:n});if(s&&a){const l=a==null?void 0:a.matchUpId,c=t.find(p=>p.matchUpId===l),u=(s==null?void 0:s.structureId)===(c==null?void 0:c.structureId)?(s==null?void 0:s.roundPosition)<(c==null?void 0:c.roundPosition)&&1||2:s.structureId===(c==null?void 0:c.structureId)&&2||1;o.matchUpStatusCodes=((i=o.matchUpStatusCodes)!=null?i:[]).map(p=>p.sideNumber===u?a6(s6({},p),{previousMatchUpStatus:e}):p)}}var l6=Object.defineProperty,qS=Object.getOwnPropertySymbols,c6=Object.prototype.hasOwnProperty,u6=Object.prototype.propertyIsEnumerable,zS=(t,e,r)=>e in t?l6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,em=(t,e)=>{for(var r in e||(e={}))c6.call(e,r)&&zS(t,r,e[r]);if(qS)for(var r of qS(e))u6.call(e,r)&&zS(t,r,e[r]);return t};function d6({inContextDrawMatchUps:t,sourceMatchUpStatus:e,targetDrawPosition:r,tournamentRecord:n,sourceMatchUpId:o,drawDefinition:i,structureId:s,dualMatchUp:a,roundNumber:l,matchUpsMap:c,event:u}){const{structure:p}=Ne({drawDefinition:i,structureId:s});if((p==null?void 0:p.structureType)===gr)return em({},V);c=c||lr({drawDefinition:i});const v=((c==null?void 0:c.mappedMatchUps)||{})[s].matchUps,{initialRoundNumber:f}=js({drawPosition:r,matchUps:v}),m=v==null?void 0:v.filter(g=>{var _;return g.roundNumber>=l&&g.roundNumber!==f&&((_=g.drawPositions)==null?void 0:_.includes(r))}),{positionAssignments:h}=st({drawDefinition:i,structureId:s});for(const g of m||[])p6({inContextDrawMatchUps:t,sourceMatchUpStatus:e,positionAssignments:h,targetDrawPosition:r,tournamentRecord:n,sourceMatchUpId:o,drawDefinition:i,dualMatchUp:a,matchUpsMap:c,matchUp:g,event:u});return em({},V)}function p6({inContextDrawMatchUps:t,positionAssignments:e,sourceMatchUpStatus:r,targetDrawPosition:n,tournamentRecord:o,sourceMatchUpId:i,drawDefinition:s,dualMatchUp:a,matchUpsMap:l,matchUp:c,event:u}){var p,d,v;const f="removeSubsequentDrawPosition";if(a){const _=(d=(p=t.find(({matchUpId:P})=>c.matchUpId===P).sides)==null?void 0:p.find(P=>P.drawPosition===n))==null?void 0:d.sideNumber,I=(v=c.sides)==null?void 0:v.find(P=>P.sideNumber===_);I&&delete I.lineUp}c.drawPositions=(c.drawPositions||[]).map(g=>g===n?void 0:g).filter(Boolean);const h=e.filter(({drawPosition:g})=>{var _;return(_=c.drawPositions)==null?void 0:_.includes(g)}).filter(g=>g.bye).length;return c.matchUpStatus=h&&nt||[Xe,ot].includes(c.matchUpStatus)&&c.matchUpStatus||Ft,[ot,Xe].includes(c.matchUpStatus)&&(c.winningSide=void 0),c.matchUpStatusCodes&&HS({inContextDrawMatchUps:t,sourceMatchUpStatus:r,sourceMatchUpId:i,matchUpsMap:l,matchUp:c}),Ze({tournamentId:o==null?void 0:o.tournamentId,eventId:u==null?void 0:u.eventId,context:`${f}-${n}`,drawDefinition:s,matchUp:c}),em({},V)}function YS({positionAssignments:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:n,structure:o,event:i}){const{matchUps:s}=Je({drawDefinition:r,matchUpsMap:n,structure:o,event:i});s.forEach(a=>{const c=t.filter(({drawPosition:u})=>{var p;return(p=a.drawPositions)==null?void 0:p.includes(u)}).filter(u=>u.bye).length;a.winningSide||(Object.assign(a,{matchUpStatus:c?nt:Ft}),Ze({tournamentId:e==null?void 0:e.tournamentId,context:"modifyRoundRobinMatchUpsStatus",eventId:i==null?void 0:i.eventId,drawDefinition:r,matchUp:a}))})}function Ra({tournamentRecord:t,drawDefinition:e,event:r}){const n=(t==null?void 0:t.events)||r&&[r],o=(n==null?void 0:n.map(l=>l==null?void 0:l.drawDefinitions).flat().filter(Boolean))||e&&[e]||[],i={},s={},a=o.map(l=>{var c;return(c=l==null?void 0:l.structures)==null?void 0:c.filter(u=>u==null?void 0:u.structures)}).flat().filter(Boolean);for(const l of a){const{structures:c,structureId:u}=l||{};c&&u&&(i[u]=c==null?void 0:c.map(p=>p.structureId))&&c.forEach(p=>s[p.structureId]=l==null?void 0:l.structureId)}return{containedStructures:i,containerStructures:s}}function dc(t){var e;const{drawDefinition:r,findContainer:n,structureId:o,event:i}=t;let s=t.structure;const a={isCollectionMatchUp:!1},{containedStructures:l}=Ra({drawDefinition:r}),c=o?l[o]||[]:[];if(!s){const b=Ne({drawDefinition:r,structureId:o});if(b.error)return b;s=n&&b.containingStructure||b.structure}if(Co({drawDefinition:r,structure:s}))return{structure:s,isAdHoc:!0,error:ta};const{matchUps:u}=Lt({inContext:!0,matchUpFilters:a,drawDefinition:r,event:i}),p=u==null?void 0:u.filter(b=>b.structureId===o||c.includes(b.structureId)),{matchUpDependencies:d}=cn({drawIds:[r.drawId],matchUps:u,drawDefinition:r}),v=[],f=[],m={},h=[];for(const b of u||[]){if(b.structureId===o||c.includes(b.structureId)){f.push(...b.drawPositions||[]);const w=b.roundNumber;for(const T of(b.drawPositions||[]).filter(Boolean))(!m[T]||w&&m[T]>w)&&(m[T]=w)}fv(b)&&(h.push(b),v.push(b.matchUpId,...((e=d==null?void 0:d[b==null?void 0:b.matchUpId])==null?void 0:e.matchUpIds)||[]))}const g=We(f.filter(Boolean)).sort(er),_=We(v),I=We(p==null?void 0:p.map(({matchUpId:b,drawPositions:w})=>_.includes(b)?w:[]).flat().filter(Boolean)).sort(er),{positionAssignments:P}=st({drawDefinition:r,structure:s}),y=P==null?void 0:P.filter(b=>b.bye).map(b=>b.drawPosition),S=P==null?void 0:P.filter(b=>b.qualifier).map(b=>b.drawPosition),O=(g==null?void 0:g.filter(b=>!I.includes(b)))||[];return{allDrawPositions:g,inContextStructureMatchUps:p,drawPositionInitialRounds:m,activeDependentMatchUpIds:_,qualifyingDrawPositions:S,inactiveDrawPositions:O,positionAssignments:P,activeDrawPositions:I,byeDrawPositions:y,activeMatchUps:h,structure:s}}function Jn(t,e){e||zt()}var f6=Object.defineProperty,v6=Object.defineProperties,m6=Object.getOwnPropertyDescriptors,KS=Object.getOwnPropertySymbols,h6=Object.prototype.hasOwnProperty,g6=Object.prototype.propertyIsEnumerable,QS=(t,e,r)=>e in t?f6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,pc=(t,e)=>{for(var r in e||(e={}))h6.call(e,r)&&QS(t,r,e[r]);if(KS)for(var r of KS(e))g6.call(e,r)&&QS(t,r,e[r]);return t},_6=(t,e)=>v6(t,m6(e));function Fa(t){let{inContextDrawMatchUps:e,participantId:r,drawPosition:n}=t;const{tournamentRecord:o,drawDefinition:i,structureId:s,matchUpsMap:a,event:l}=t,{structure:c}=Ne({drawDefinition:i,structureId:s}),p=(Dt({drawDefinition:i,structure:c}).positionAssignments||[]).find(m=>r&&m.participantId===r||n&&m.drawPosition===n);if(p&&r&&!n&&(n=p==null?void 0:p.drawPosition),!n)return{error:pl};r||(r=p==null?void 0:p.participantId);const{activeDrawPositions:d}=dc({drawDefinition:i,structureId:s});return d.includes(n)?{error:Xp}:(e||({matchUps:e}=Lt({inContext:!0,drawDefinition:i,matchUpsMap:a})),tm({inContextDrawMatchUps:e,tournamentRecord:o,drawDefinition:i,structureId:s,drawPosition:n,matchUpsMap:a,event:l}).drawPositionCleared?(oi({tournamentId:o==null?void 0:o.tournamentId,drawDefinition:i,structure:c,event:l}),_6(pc({},V),{participantId:r})):{error:JF})}function tm({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,matchUpsMap:o,structureId:i,event:s}){const{structure:a}=Ne({drawDefinition:r,structureId:i});if(!a)return{error:bt};const l=Dt({drawDefinition:r,structure:a}).positionAssignments||[],c=l.some(I=>{if(I.drawPosition===n)return delete I.participantId,delete I.qualifier,delete I.bye,!0});if(a.structureType===gr)return YS({positionAssignments:l,tournamentRecord:e,drawDefinition:r,matchUpsMap:o,structure:a}),pc({drawPositionCleared:c},V);const u={isCollectionMatchUp:!1},{matchUps:p}=Je({drawDefinition:r,matchUpFilters:u,matchUpsMap:o,structure:a,event:s}),{roundProfile:d,roundMatchUps:v}=Tr({matchUps:p}),f=d&&Object.keys(d),m=f==null?void 0:f.map(I=>Te(I));let h=n;const g=m==null?void 0:m.map(I=>{var P,y,S;const O=d==null?void 0:d[I],b=(P=O==null?void 0:O.pairedDrawPositions)==null?void 0:P.find(M=>M.includes(h)),w=b==null?void 0:b.find(M=>M!==h),T=l.find(M=>M.drawPosition===w),$=d==null?void 0:d[I+1],N=T==null?void 0:T.bye,E=(y=$==null?void 0:$.pairedDrawPositions)==null?void 0:y.find(M=>M.includes(w)),A=N&&E&&$&&((S=$.drawPositions)==null?void 0:S.includes(w)),C=b&&{pairedDrawPositionByeAdvancedPair:!A&&E,pairedDrawPosition:w,targetDrawPosition:h,relevantPair:b,roundNumber:I};return A&&(h=w),C}).filter(I=>I==null?void 0:I.targetDrawPosition),_=g==null?void 0:g.reduce((I,P)=>{const{roundNumber:y,relevantPair:S,targetDrawPosition:O,pairedDrawPosition:b,pairedDrawPositionByeAdvancedPair:w}=P,T={roundNumber:y,targetDrawPosition:O,relevantPair:S},$=w&&{roundNumber:y+1,targetDrawPosition:b,relevantPair:w,subsequentRoundRemoval:!0},N=[T,$].filter(Boolean);return I.concat(...N)},[]);return _==null||_.forEach(({roundNumber:I,targetDrawPosition:P,relevantPair:y})=>{const S=v==null?void 0:v[I].find(O=>Xt(O.drawPositions.filter(Boolean),y.filter(Boolean)));S&&(I6({inContextDrawMatchUps:t,targetDrawPosition:P,tournamentRecord:e,drawDefinition:r,structureId:i,roundNumber:I,matchUpsMap:o}),JS({inContextDrawMatchUps:t,positionAssignments:l,tournamentRecord:e,drawDefinition:r,targetMatchUp:S,drawPosition:n,matchUpsMap:o,structure:a,event:s}))}),{tasks:_,drawPositionCleared:c,positionAssignments:l}}function I6({inContextDrawMatchUps:t,targetDrawPosition:e,tournamentRecord:r,drawDefinition:n,matchUpsMap:o,roundNumber:i,structureId:s}){const{structure:a}=Ne({drawDefinition:n,structureId:s});if(!a)return{error:bt};if(a.structureType===gr)return;o=o||lr({drawDefinition:n});const c=((o==null?void 0:o.mappedMatchUps)||{})[s].matchUps,{initialRoundNumber:u}=js({drawPosition:e,matchUps:c}),p=c==null?void 0:c.filter(v=>{var f;return v.roundNumber>=i&&v.roundNumber!==u&&((f=v.drawPositions)==null?void 0:f.includes(e))}),d=st({drawDefinition:n,structureId:s}).positionAssignments||[];return p==null||p.forEach(v=>JS({drawPosition:e,targetMatchUp:v,inContextDrawMatchUps:t,positionAssignments:d,tournamentRecord:r,drawDefinition:n,matchUpsMap:o,structure:a})),pc({},V)}function JS({inContextDrawMatchUps:t,positionAssignments:e,tournamentRecord:r,drawDefinition:n,targetMatchUp:o,drawPosition:i,matchUpsMap:s,structure:a,event:l}){var c,u,p,d,v;const f="removeDrawPosition",m=(c=o.drawPositions)==null?void 0:c.slice(),h=o.matchUpStatus,g=o.winningSide;s=s||lr({drawDefinition:n});const I=s.mappedMatchUps[a.structureId].matchUps,{initialRoundNumber:P}=js({drawPosition:i,matchUps:I});if(o.roundNumber&&P&&o.roundNumber>P){const U=(o.drawPositions||[]).map(C=>C===i?void 0:C);o.drawPositions=U}if(o.matchUpType===Qe){const U=t==null?void 0:t.find(D=>D.matchUpId===o.matchUpId),M=((U==null?void 0:U.sides)||[]).reduce((D,R,j)=>R.drawPosition===i?j:D,void 0);M!==void 0&&((p=(u=o.sides)==null?void 0:u[M])!=null&&p.lineUp)&&((d=o.sides)==null||delete d[M].lineUp,Ze({tournamentId:r==null?void 0:r.tournamentId,context:`${f}-TEAM`,eventId:l==null?void 0:l.eventId,matchUp:o,drawDefinition:n}))}const y=Ir({matchUpId:o.matchUpId,inContextDrawMatchUps:t,drawDefinition:n}),{targetLinks:{winnerTargetLink:S},targetMatchUps:{loserMatchUp:O,winnerMatchUp:b,loserMatchUpDrawPositionIndex:w}}=y,$=e.filter(({drawPosition:U})=>{var C;return(C=o.drawPositions)==null?void 0:C.includes(U)}).filter(U=>U.bye).length,N=$&&nt||o.matchUpStatus&&[Xe,ot].includes(o.matchUpStatus)&&o.matcHUpStatus||((v=o.drawPositions)==null?void 0:v.length)===2&&Ft||void 0;o.matchUpStatus=N,o.matchUpStatus&&[ot,Xe].includes(o.matchUpStatus)&&(o.winningSide=void 0);const E=m==null?void 0:m.find(U=>{var C;return!((C=o.drawPositions)!=null&&C.includes(U))});if((m==null?void 0:m.includes(i))&&h===o.matchUpStatus&&g===o.winningSide||(E&&Jn(),Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:l==null?void 0:l.eventId,matchUp:o,context:`${f}-${i}`,drawDefinition:n})),O&&O.structureId!==y.matchUp.structureId&&!$){const{drawPositions:U,roundNumber:C}=O;if(C===1){const M=U[w];tm({structureId:O.structureId,drawPosition:M,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,matchUpsMap:s})}else{const M=Math.min(...U.filter(Boolean)),D=P6({loserMatchUpDrawPosition:M,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,loserMatchUp:O,matchUpsMap:s,event:l});if(D.error)return k({result:D,stack:f});const j=((s==null?void 0:s.mappedMatchUps)||{})[O.structureId].matchUps,{initialRoundNumber:G}=js({drawPosition:M,matchUps:j});G===1&&(Jn(),tm({structureId:O.structureId,drawPosition:M,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,matchUpsMap:s}))}}return b&&b.structureId!==y.matchUp.structureId&&S.target.feedProfile,pc({},V)}function P6({loserMatchUpDrawPosition:t,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,loserMatchUp:o,matchUpsMap:i,event:s}){const{structure:a}=Ne({structureId:o.structureId,drawDefinition:n}),{positionAssignments:l}=st({structure:a}),c=l==null?void 0:l.find(u=>u.drawPosition===t);if(c!=null&&c.bye){const u=Fa({drawPosition:t,structureId:o.structureId,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,matchUpsMap:i,event:s});if(u.error)return u}return pc({},V)}function y6({matchUpStatuses:t=[nt,ot,Xe],drawPositionMatchUps:e,loserDrawPosition:r,sourceMatchUps:n}){var o;const i=e==null?void 0:e.reduce((p,d)=>!p||d.roundNumber>p.roundNumber?d:p,void 0),s=(o=i==null?void 0:i.drawPositions)==null?void 0:o.find(p=>p!==r),a=n.filter(p=>{var d;return(d=p==null?void 0:p.drawPositions)==null?void 0:d.includes(s)}).map(p=>p.matchUpStatus),l=n.filter(p=>{var d;return(d=p==null?void 0:p.drawPositions)==null?void 0:d.includes(r)}).map(p=>p.matchUpStatus),c=Xt(a||[],t),u=Xt(l||[],t);return{sourceMatchUp:i,winnerHadMatchUpStatus:c,winnerMatchUpStatuses:a,loserHadMatchUpStatus:u,loserMatchUpStatuses:l}}var S6=Object.defineProperty,O6=Object.defineProperties,b6=Object.getOwnPropertyDescriptors,ZS=Object.getOwnPropertySymbols,T6=Object.prototype.hasOwnProperty,w6=Object.prototype.propertyIsEnumerable,XS=(t,e,r)=>e in t?S6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Wi=(t,e)=>{for(var r in e||(e={}))T6.call(e,r)&&XS(t,r,e[r]);if(ZS)for(var r of ZS(e))w6.call(e,r)&&XS(t,r,e[r]);return t},E6=(t,e)=>O6(t,b6(e));function xa(t){const{dualWinningSideChange:e,inContextDrawMatchUps:r,tournamentRecord:n,drawDefinition:o,matchUpStatus:i,matchUpsMap:s,dualMatchUp:a,targetData:l,matchUpId:c,structure:u,event:p}=t,d=!!t.matchUp.collectionId,v=Co({drawDefinition:o,structure:u}),{drawPositions:f,winningSide:m}=l.matchUp||{};if(!v&&!f)return{error:Zp};const{targetLinks:{loserTargetLink:h,winnerTargetLink:g,byeTargetLink:_},targetMatchUps:{loserMatchUp:I,winnerMatchUp:P,byeMatchUp:y}}=l,S=Kn(E6(Wi({},t),{matchUpStatus:i||Ft,removeWinningSide:!0}));if(S.error)return S;let O;if(d){const{matchUpTieId:D,matchUpsMap:R}=t;if(O=uo({matchUpId:D,tournamentRecord:n,drawDefinition:o,matchUpsMap:R,event:p}),!e&&!O.removeWinningSide)return Wi({},V)}if(v)return Wi({},V);const{matchUps:b}=Je({afterRecoveryTimes:!1,inContext:!0,drawDefinition:o,matchUpsMap:s,structure:u}),{positionAssignments:w}=Dt({structure:u}),T=m-1,$=1-T,N=f[T],E=f[$],{winnerParticipantId:A,loserParticipantId:U}=(w==null?void 0:w.reduce((D,R)=>(R.drawPosition===E&&(D.loserParticipantId=R.participantId),R.drawPosition===N&&(D.winnerParticipantId=R.participantId),D),{winnerParticipantId:void 0,loserParticipantId:void 0}))||{},C=b.filter(D=>{var R;return(R=D.drawPositions)==null?void 0:R.includes(E)});if(P&&eO({sourceMatchUpStatus:i,sourceMatchUpId:c,inContextDrawMatchUps:r,winningDrawPosition:N,winnerParticipantId:A,tournamentRecord:n,winnerTargetLink:g,drawDefinition:o,winnerMatchUp:P,dualMatchUp:a,matchUpsMap:s}),I){const{winnerHadMatchUpStatus:D}=y6({drawPositionMatchUps:C,loserDrawPosition:E,sourceMatchUps:b}),j=h.linkCondition===co;if(D&&j){const W=Math.min(...I.drawPositions);rm({targetLink:h,inContextDrawMatchUps:r,drawDefinition:o,drawPosition:W,matchUpsMap:s,event:p})}const G=$6({sourceMatchUpStatus:i,sourceMatchUpId:c,loserParticipantId:U,tournamentRecord:n,loserTargetLink:h,drawDefinition:o,loserMatchUp:I,dualMatchUp:a,matchUpsMap:s,event:p});if(G.error)return G}if(y){const D=Math.min(...y.drawPositions);rm({sourceMatchUpId:c,targetLink:_,inContextDrawMatchUps:r,drawDefinition:o,drawPosition:D,matchUpsMap:s,event:p})}const M=O&&{tieMatchUpResult:O};return Wi(Wi({},V),M)}function eO({inContextDrawMatchUps:t,winningDrawPosition:e,sourceMatchUpStatus:r,winnerParticipantId:n,tournamentRecord:o,winnerTargetLink:i,sourceMatchUpId:s,drawDefinition:a,winnerMatchUp:l,matchUpsMap:c,dualMatchUp:u,event:p}){var d;const{structureId:v,roundNumber:f}=l,m="removeDirectedWinner";if(i){const h=i.target.structureId,{structure:g}=Ne({drawDefinition:a,structureId:h});if(!g)return{error:bt};const{positionAssignments:_}=Dt({structure:g});g.seedAssignments=(g.seedAssignments||[]).filter(T=>T.participantId!==n);const I=_==null?void 0:_.find(T=>T.participantId===n),P=I==null?void 0:I.drawPosition,{matchUps:y}=Je({drawDefinition:a,structure:g,event:p}),S=y.map(T=>T.drawPositions).flat(1/0).filter(Boolean),O=Nr(S);if((P?O[P]:void 0)===1)_==null||_.forEach(T=>{T.participantId===n&&delete T.participantId});else{const T=y.filter(({drawPositions:$})=>$.includes(P));console.log("not removing from position assignments since instances > 1",{drawPositionMatchUps:T,winnerTargetLink:i})}const w=(d=c==null?void 0:c.drawMatchUps)==null?void 0:d.find(({matchUpId:T})=>T===l.matchUpId);w&&Ze({tournamentId:o==null?void 0:o.tournamentId,eventId:p==null?void 0:p.eventId,matchUp:w,context:m,drawDefinition:a})}return f&&d6({targetDrawPosition:e,inContextDrawMatchUps:t,sourceMatchUpStatus:r,tournamentRecord:o,sourceMatchUpId:s,drawDefinition:a,dualMatchUp:u,matchUpsMap:c,roundNumber:f,structureId:v}),Wi({},V)}function $6({sourceMatchUpStatus:t,loserParticipantId:e,tournamentRecord:r,loserTargetLink:n,sourceMatchUpId:o,drawDefinition:i,loserMatchUp:s,matchUpsMap:a,dualMatchUp:l,event:c}){var u,p,d;const v="removeDirectedLoser",f=n.target.structureId,{structure:m}=Ne({drawDefinition:i,structureId:f});if(!m)return{error:bt};const{positionAssignments:h}=Dt({structure:m}),g=(u=h==null?void 0:h.find(_=>_.participantId===e))==null?void 0:u.drawPosition;if(h==null||h.forEach(_=>{_.participantId===e&&delete _.participantId}),m.seedAssignments=(m.seedAssignments||[]).filter(_=>_.participantId!==e),l){const _=s==null?void 0:s.sides.reduce((y,S,O)=>S.drawPosition===g?O:y,void 0),I=(p=a==null?void 0:a.drawMatchUps)==null?void 0:p.find(({matchUpId:y})=>y===s.matchUpId),P=(d=I==null?void 0:I.sides)==null?void 0:d[_];P&&(delete P.lineUp,Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:c==null?void 0:c.eventId,matchUp:I,context:v,drawDefinition:i}))}return Wi({},V)}function rm({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,matchUpsMap:o,targetLink:i,event:s}){const a=i.target.structureId;return Fa({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:o,drawPosition:n,structureId:a,event:s}),Wi({},V)}function tO(t){let{sourceMatchUp:e}=t;const{targetMatchUp:r,structure:n,matchUpsMap:o,drawPosition:i}=t,s=r.roundNumber>1&&r.roundNumber-1,a=xi({structureId:n.structureId,matchUpsMap:o});!e&&i&&(e=a.find(({drawPositions:f,roundNumber:m})=>m===s&&(f==null?void 0:f.includes(i))));const l=e==null?void 0:e.roundPosition,c=l%2?1:-1,u=l+c,p=s&&a.find(({roundNumber:f,roundPosition:m})=>f===s&&m===u),d=p==null?void 0:p.matchUpStatus,v=[Rt,tr].includes(d);return{pairedPreviousMatchUp:p,pairedPreviousMatchUpIsDoubleExit:v}}function fd({drawDefinition:t,positionAction:e}){var r;const{extension:n}=xr({name:vu,element:t}),o=Array.isArray(n==null?void 0:n.value)?(n==null?void 0:n.value)||[]:[];if(!(o!=null&&o.length)){const s=t.structures.find(a=>a.stage===he);if(s){const a=(r=st({structure:s}).positionAssignments)==null?void 0:r.map(({drawPosition:l,participantId:c,bye:u,qualifier:p})=>({drawPosition:l,participantId:c,qualifier:p,bye:u}));o.push({name:"initialMainAssignments",initialAssignments:a})}}const i={name:vu,value:o.concat(e)};it({element:t,extension:i})}var N6=Object.defineProperty,rO=Object.getOwnPropertySymbols,U6=Object.prototype.hasOwnProperty,A6=Object.prototype.propertyIsEnumerable,nO=(t,e,r)=>e in t?N6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vd=(t,e)=>{for(var r in e||(e={}))U6.call(e,r)&&nO(t,r,e[r]);if(rO)for(var r of rO(e))A6.call(e,r)&&nO(t,r,e[r]);return t};function Yr({provisionalPositioning:t,isPositionAction:e,tournamentRecord:r,drawDefinition:n,drawPosition:o,matchUpsMap:i,structureId:s,structure:a,event:l}){var c;if(!n)return{error:ue};if(a||({structure:a}=Ne({drawDefinition:n,structureId:s})),!a)return{error:bt};s||({structureId:s}=a);const u="assignDrawPositionBye";Jn(),i||(i=lr({drawDefinition:n}));const{positionAssignments:p}=st({structure:a}),{activeDrawPositions:d}=dc({drawDefinition:n,structureId:s}),v=p==null?void 0:p.find(N=>N.drawPosition===o);if(v!=null&&v.bye)return vd({},V);if(d==null?void 0:d.includes(o))return{error:Xp};const m=p==null?void 0:p.find(N=>N.drawPosition===o);if(!m)return{error:ta};const{filled:h,containsBye:g,assignedParticipantId:_}=C6(m);if(g)return vd({},V);if(h&&!g)return k({result:{error:dl},stack:u});const I=Lt({inContext:!0,drawDefinition:n,matchUpsMap:i}).matchUps||[],P={isCollectionMatchUp:!1},{matchUps:y}=Je({provisionalPositioning:t,drawDefinition:n,matchUpFilters:P,matchUpsMap:i,structure:a});if(p==null||p.forEach(N=>{N.drawPosition===o&&(N.bye=!0)}),a.structureType===gr)return M6({tournamentRecord:r,drawDefinition:n,drawPosition:o,matchUps:y}),oi({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:n,structure:a,event:l}),oO({assignedParticipantId:_,isPositionAction:e,drawDefinition:n,drawPosition:o,structureId:s,stack:u});const{roundProfile:S,roundMatchUps:O}=Tr({matchUps:y}),b=S&&Object.keys(S).map(N=>parseInt(N)).reverse(),w=b==null?void 0:b.find(N=>{var E;return(E=S==null?void 0:S[N].drawPositions)==null?void 0:E.includes(o)}),T=w&&(O==null?void 0:O[w].find(({drawPositions:N})=>N==null?void 0:N.includes(o)));iO({tournamentRecord:r,drawDefinition:n,matchUp:T,event:l});const $=(c=T.drawPositions)==null?void 0:c.find(N=>N!==o);if($){const N=nm({sourceDrawPositions:T.drawPositions,matchUpId:T.matchUpId,inContextDrawMatchUps:I,drawPositionToAdvance:$,tournamentRecord:r,drawDefinition:n,matchUpsMap:i});if(N.error)return N}return oi({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:n,structure:a,event:l}),oO({assignedParticipantId:_,isPositionAction:e,drawDefinition:n,drawPosition:o,structureId:s,stack:u})}function oO({assignedParticipantId:t,isPositionAction:e,drawDefinition:r,drawPosition:n,structureId:o,stack:i}){return e&&fd({drawDefinition:r,positionAction:{removedParticipantId:t,drawPosition:n,structureId:o,name:i}}),k({result:vd({},V),stack:i})}function C6(t){const e=t.bye,r=t.qualifier,n=t.participantId;return{containsBye:e,containsQualifier:r,assignedParticipantId:n,filled:e||r||n}}function iO({tournamentRecord:t,drawDefinition:e,eventId:r,matchUp:n,event:o}){Object.assign(n,{matchUpStatus:nt,score:void 0,winningSide:void 0}),Ze({tournamentId:t==null?void 0:t.tournamentId,eventId:r??(o==null?void 0:o.eventId),context:"setMatchUpStatusBye",drawDefinition:e,matchUp:n})}function M6({tournamentRecord:t,drawDefinition:e,drawPosition:r,matchUps:n,event:o}){n.forEach(i=>{var s;(s=i.drawPositions)!=null&&s.includes(r)&&iO({eventId:o==null?void 0:o.eventId,tournamentRecord:t,drawDefinition:e,matchUp:i})})}function nm({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,matchUpsMap:i,matchUpId:s,event:a}){var l;Jn();const c=i.drawMatchUps.find(y=>y.matchUpId===s),u=e.find(y=>y.matchUpId===s),p=u==null?void 0:u.structureId,{structure:d}=Ne({drawDefinition:o,structureId:p}),{positionAssignments:v}=st({structure:d}),f=v==null?void 0:v.filter(y=>y.bye).map(y=>y.drawPosition),m=(l=c==null?void 0:c.drawPositions)==null?void 0:l.find(y=>y!==t),h=m&&(f==null?void 0:f.includes(m)),{targetLinks:{loserTargetLink:g},targetMatchUps:{loserMatchUp:_,winnerMatchUp:I,loserTargetDrawPosition:P}}=Ir({inContextDrawMatchUps:e,drawDefinition:o,matchUpId:s});if(I&&I.structureId===(d==null?void 0:d.structureId)&&D6({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,winnerMatchUp:I,matchUpsMap:i,event:a}),_&&h&&_.structureId!==(d==null?void 0:d.structureId)){const{roundNumber:y}=_;if(y===1){const S=Yr({structureId:g.target.structureId,drawPosition:P,tournamentRecord:n,drawDefinition:o,event:a});if(S.error)return S}else sO({loserTargetDrawPosition:P,tournamentRecord:n,loserTargetLink:g,drawDefinition:o,loserMatchUp:_,matchUpsMap:i,event:a})}return vd({},V)}function D6({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,winnerMatchUp:i,matchUpsMap:s,event:a}){var l,c,u;const p="advanceWinner",d=s.drawMatchUps.find(j=>j.matchUpId===i.matchUpId),v=e.find(j=>j.matchUpId===i.matchUpId),f=v==null?void 0:v.structureId,{structure:m}=Ne({drawDefinition:o,structureId:f}),{positionAssignments:h}=st({structure:m}),g=h==null?void 0:h.find(({drawPosition:j})=>j===t),_=g==null?void 0:g.bye,I=(l=d.drawPositions)==null?void 0:l.filter(Boolean),P=h==null?void 0:h.filter(j=>I==null?void 0:I.includes(j.drawPosition)),y=h==null?void 0:h.find(({drawPosition:j})=>j===t),S=r==null?void 0:r.find(j=>j!==t),O=S&&(P==null?void 0:P.find(({drawPosition:j})=>j===S)),b=O==null?void 0:O.bye,w=_&&b;if(w&&console.log({isByeAdvancedBye:w}),(I==null?void 0:I.length)>1&&_&&!b)return k({result:{error:dl},stack:p});const T=I==null?void 0:I.find(j=>j!==t);let $=w;const N=[...(d.drawPositions||[]).filter(Boolean),void 0,void 0].slice(0,2),E=N.map(j=>!j&&!$||j===t?($=!0,t):j).sort(er);if(!$)return console.log("@@@@@@@",{advancingAssignmentIsBye:y,drawPositionToAdvance:t,existingAssignments:P}),k({result:{error:dl},stack:p});const A=(c=h==null?void 0:h.find(({drawPosition:j})=>j===T))==null?void 0:c.bye,U=(u=h==null?void 0:h.find(({drawPosition:j})=>j===t))==null?void 0:u.bye;Object.assign(d,{matchUpStatus:U||A?nt:Ft,score:void 0,winningSide:void 0,drawPositions:E}),d.drawPositions.find(j=>!N.includes(j)),Jn(),Ze({tournamentId:n==null?void 0:n.tournamentId,matchUp:d,eventId:a==null?void 0:a.eventId,context:p,drawDefinition:o});const{targetLinks:{loserTargetLink:M},targetMatchUps:{loserMatchUp:D,loserTargetDrawPosition:R}}=Ir({matchUpId:i.matchUpId,inContextDrawMatchUps:e,drawDefinition:o});if(A||U){const j=A?t:T;if(j)nm({drawPositionToAdvance:j,matchUpId:i.matchUpId,inContextDrawMatchUps:e,tournamentRecord:n,drawDefinition:o,matchUpsMap:s});else if(U&&M&&D)if(D.feedRound)sO({loserTargetDrawPosition:R,tournamentRecord:n,loserTargetLink:M,drawDefinition:o,loserMatchUp:D,matchUpsMap:s});else{const W=1-i.roundPosition%2,q=D.drawPositions[W],F=Yr({structureId:M.target.structureId,drawPosition:q,tournamentRecord:n,drawDefinition:o,event:a});if(F.error)return F}}}function sO({loserTargetDrawPosition:t,tournamentRecord:e,loserTargetLink:r,drawDefinition:n,loserMatchUp:o,matchUpsMap:i,event:s}){const{roundNumber:a}=o;Jn();const c=((i==null?void 0:i.mappedMatchUps)||{})[o.structureId].matchUps,{initialRoundNumber:u}=js({drawPosition:t,matchUps:c});if(u===a){const p=Yr({structureId:r.target.structureId,drawPosition:t,tournamentRecord:e,drawDefinition:n,event:s});if(p.error)return p}}var j6=Object.defineProperty,R6=Object.defineProperties,F6=Object.getOwnPropertyDescriptors,aO=Object.getOwnPropertySymbols,x6=Object.prototype.hasOwnProperty,L6=Object.prototype.propertyIsEnumerable,lO=(t,e,r)=>e in t?j6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,V6=(t,e)=>{for(var r in e||(e={}))x6.call(e,r)&&lO(t,r,e[r]);if(aO)for(var r of aO(e))L6.call(e,r)&&lO(t,r,e[r]);return t},B6=(t,e)=>R6(t,F6(e));function om({inContextTargetMatchUp:t,drawPositionSideIndex:e,teamParticipantId:r,tournamentRecord:n,drawDefinition:o,matchUp:i,event:s}){var a,l,c,u;const p=(l=(a=t==null?void 0:t.sides)==null?void 0:a[e])==null?void 0:l.sideNumber,d=p&&((c=i.sides)==null?void 0:c.find(h=>h.sideNumber===p)),{extension:v}=Kt({element:o,name:kn}),m=((v==null?void 0:v.value)||{})[r];if(d)(u=i==null?void 0:i.sides)==null||u.forEach(h=>{h.sideNumber===p&&(h.lineUp=m)});else{i.sides=[1,2].map(g=>{var _;const I=((_=i.sides)==null?void 0:_.find(P=>P.sideNumber===g))||{};return B6(V6({},I),{sideNumber:g})});const h=i.sides.find(g=>g.sideNumber===p);h&&(h.lineUp=m)}Ze({tournamentId:n==null?void 0:n.tournamentId,context:"updateSidLineUps",eventId:s==null?void 0:s.eventId,drawDefinition:o,matchUp:i})}function k6({drawPosition:t,drawPositions:e}){let r=!1,n=!!(e!=null&&e.includes(t));return{updatedDrawPositions:n?e||[]:[...e,void 0,void 0].slice(0,2).map(s=>!s&&!n?(n=!0,r=!0,t):s).sort(er).filter(Boolean),positionAdded:r,positionAssigned:n}}function md({inContextDrawMatchUps:t,drawPosition:e,matchUpId:r}){const n=t.filter(({winnerMatchUpId:s,loserMatchUpId:a})=>a===r||s===r).sort((s,a)=>s.roundPosition-a.roundPosition);return t.find(s=>s.matchUpId===r).feedRound?1:n.reduce((s,a,l)=>{var c;return(c=a.drawPositions)!=null&&c.includes(e)?l+1:s},void 0)}var G6=Object.defineProperty,cO=Object.getOwnPropertySymbols,W6=Object.prototype.hasOwnProperty,H6=Object.prototype.propertyIsEnumerable,uO=(t,e,r)=>e in t?G6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,q6=(t,e)=>{for(var r in e||(e={}))W6.call(e,r)&&uO(t,r,e[r]);if(cO)for(var r of cO(e))H6.call(e,r)&&uO(t,r,e[r]);return t};function La({inContextDrawMatchUps:t,sourceMatchUpStatus:e,tournamentRecord:r,sourceMatchUpId:n,drawDefinition:o,matchUpStatus:i,drawPosition:s,matchUpsMap:a,matchUpId:l,event:c}){var u,p,d;const v="assignMatchUpDrawPosition";a||(a=lr({drawDefinition:o})),t||(t=Lt({inContext:!0,drawDefinition:o,matchUpsMap:a}).matchUps||[]);const f=t.find(C=>C.matchUpId===l),m=f==null?void 0:f.structureId,h=(u=o==null?void 0:o.structures)==null?void 0:u.find(C=>C.structureId===m);if(!h)return{error:bt};const g=(p=a==null?void 0:a.drawMatchUps)==null?void 0:p.find(C=>C.matchUpId===l),_=(g==null?void 0:g.drawPositions)||[],{positionAdded:I,positionAssigned:P,updatedDrawPositions:y}=k6({drawPosition:s,drawPositions:_}),{positionAssignments:S}=st({drawDefinition:o,structure:h}),O=S==null?void 0:S.filter(C=>y.includes(C.drawPosition)),b=O==null?void 0:O.find(({bye:C})=>C),w=(g==null?void 0:g.matchUpStatus)&&[ot,Xe].includes(g.matchUpStatus)&&y.filter(Boolean).length<2;if(i=b&&nt||i||w&&g.matchUpStatus||(g==null?void 0:g.matchUpStatus)&&[Rt,tr].includes(g.matchUpStatus)&&g.matchUpStatus||Ft,g&&I){t=Lt({inContext:!0,drawDefinition:o,matchUpsMap:a}).matchUps||[];const C=w&&md({inContextDrawMatchUps:t,drawPosition:s,matchUpId:l})||void 0;g!=null&&g.matchUpStatusCodes&&HS({inContextDrawMatchUps:t,sourceMatchUpStatus:e,sourceMatchUpId:n,matchUpsMap:a,matchUp:g}),Object.assign(g,{drawPositions:y,winningSide:C,matchUpStatus:i}),Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:f==null?void 0:f.eventId,context:v,drawDefinition:o,matchUp:g})}const T=Ir({inContextDrawMatchUps:t,inContextMatchUp:f,drawDefinition:o,matchUpId:l}),{targetMatchUps:{winnerMatchUp:$,loserMatchUp:N,loserTargetDrawPosition:E},targetLinks:{loserTargetLink:A}}=T,U=xi({structureId:h.structureId,matchUpsMap:a});if(P&&b){if($)if([nt,Rt,tr].includes(i)){const C=La({matchUpId:$.matchUpId,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:o,drawPosition:s,matchUpsMap:a});if(C.error)return C}else{const{structureId:C}=$;C!==h.structureId&&console.log("winnerMatchUp in different structure... participant is in different targetDrawPosition")}}else if($&&f&&!f.feedRound){const{pairedPreviousMatchUpIsDoubleExit:C}=tO({targetMatchUp:g,drawPosition:s,matchUpsMap:a,structure:h});if(C){const M=La({matchUpId:$.matchUpId,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:o,drawPosition:s,matchUpsMap:a});if(M.error)return M}}if((g==null?void 0:g.matchUpType)===Qe){const C=t==null?void 0:t.find(({matchUpId:j})=>j===g.matchUpId),D=((C==null?void 0:C.sides)||[]).reduce((j,G,W)=>G.drawPosition===s?W:j,void 0),R=(d=S==null?void 0:S.find(j=>j.drawPosition===s))==null?void 0:d.participantId;R&&D!==void 0&&om({inContextTargetMatchUp:C,drawPositionSideIndex:D,teamParticipantId:R,tournamentRecord:r,drawDefinition:o,matchUp:g})}if((A==null?void 0:A.linkCondition)===co&&y.filter(Boolean).length===2&&!b&&U.filter(({drawPositions:D,roundNumber:R})=>R===1&&Xt(D,y)).every(({matchUpStatus:D})=>[Mt,_r].includes(D))&&N){const{structureId:D}=N,R=Yr({drawPosition:E,tournamentRecord:r,drawDefinition:o,structureId:D,matchUpsMap:a,event:c});if(R.error)return R}return P?q6({},V):k({result:{error:dl},context:{drawPosition:s},stack:v})}var z6=Object.defineProperty,Y6=Object.defineProperties,K6=Object.getOwnPropertyDescriptors,dO=Object.getOwnPropertySymbols,Q6=Object.prototype.hasOwnProperty,J6=Object.prototype.propertyIsEnumerable,pO=(t,e,r)=>e in t?z6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mo=(t,e)=>{for(var r in e||(e={}))Q6.call(e,r)&&pO(t,r,e[r]);if(dO)for(var r of dO(e))J6.call(e,r)&&pO(t,r,e[r]);return t},Va=(t,e)=>Y6(t,K6(e));function fc(t){var e;const{tournamentRecord:r,appliedPolicies:n,drawDefinition:o,matchUpsMap:i,targetData:s,structure:a,event:l}=t,c="doubleExitAdvancement";if(a.structureType===gr)return k({result:mo({},V),stack:c});const{matchUp:u,targetMatchUps:p,targetLinks:d}=s,{loserMatchUp:v,winnerMatchUp:f,loserTargetDrawPosition:m}=p;if(v&&v.matchUpStatus!==ut.Bye){const{loserTargetLink:h}=d;if((e=n==null?void 0:n.progression)!=null&&e.doubleExitPropagateBye){const g=vO({loserTargetDrawPosition:m,tournamentRecord:r,loserTargetLink:h,drawDefinition:o,loserMatchUp:v,matchUpsMap:i,event:l});if(g.error)return k({result:g,stack:c})}else{const{feedRound:g,drawPositions:_,matchUpId:I}=v,P=g?2:2-_.indexOf(m),y=fO(Va(mo({},t),{targetMatchUp:v,walkoverWinningSide:P,tournamentRecord:r,sourceMatchUp:u,matchUpId:I}));if(y.error)return k({result:y,stack:c})}}if(f){const h=fO(Va(mo({},t),{matchUpId:f.matchUpId,targetMatchUp:f,tournamentRecord:r,sourceMatchUp:u}));if(h.error)return k({result:h,stack:c})}return k({result:mo({},V),stack:c})}function fO(t){var e,r,n;const{inContextDrawMatchUps:o,tournamentRecord:i,drawDefinition:s,sourceMatchUp:a,targetMatchUp:l,matchUpsMap:c}=t,u=s.structures.find(({structureId:z})=>z===l.structureId),p=t.matchUpStatus===ut.DoubleDefault?ut.DoubleDefault:ut.DoubleWalkover,d=t.matchUpStatus===ut.DoubleDefault?ut.Defaulted:ut.Walkover,v="conditionallyAdvanceDrawPosition",f=c.drawMatchUps.find(z=>z.matchUpId===l.matchUpId);if(!f)return{error:jr};const m=(a==null?void 0:a.drawPositions)||[];let h=(e=f.drawPositions)==null?void 0:e.filter(Boolean);const g=(a==null?void 0:a.structureId)===l.structureId;if(g&&Xt(m,h)&&(h=h.filter(z=>!m.includes(z))),g&&h.length>1)return k({result:{error:dl},stack:v});const{pairedPreviousMatchUpIsDoubleExit:_,pairedPreviousMatchUp:I}=tO(t),P=Ir({matchUpId:l.matchUpId,inContextDrawMatchUps:o,drawDefinition:s}),{targetMatchUps:y,targetLinks:S}=P,{loserTargetDrawPosition:O,winnerMatchUp:b,loserMatchUp:w}=y;if(w){const{loserTargetLink:z}=S,H=vO({loserTargetDrawPosition:O,loserMatchUp:w,tournamentRecord:i,loserTargetLink:z,drawDefinition:s,matchUpsMap:c});if(H.error)return k({result:H,stack:v})}const T=((r=f.drawPositions)==null?void 0:r.filter(Boolean))||[],$=T.length===1,N=t.walkoverWinningSide||$&&md({drawPosition:T[0],matchUpId:l.matchUpId,inContextDrawMatchUps:o})||void 0,E=[ut.Walkover,ut.Defaulted].includes(f.matchUpStatus)&&!T.length,A=f.finishingRound===1,U=E&&!A?p:d,C=o.find(z=>z.matchUpId===I.matchUpId);let M=[],D;a&&((a==null?void 0:a.structureId)===(C==null?void 0:C.structureId)?a.roundPosition<(I==null?void 0:I.roundPosition)?D=1:D=2:l.feedRound?a.structureId===l.structureId?D=2:D=1:N&&(D=3-N));const R=t.matchUpStatus,j=I==null?void 0:I.matchUpStatus;D===1?M=[{matchUpStatus:hd(R),previousMatchUpStatus:R,sideNumber:1},{matchUpStatus:hd(j),previousMatchUpStatus:j,sideNumber:2}]:D===2&&(M=[{matchUpStatus:hd(j),previousMatchUpStatus:j,sideNumber:1},{matchUpStatus:hd(R),previousMatchUpStatus:R,sideNumber:2}]),M.length&&(M=M.map(z=>Oe(z)));const G=Kn(Va(mo({},t),{matchUp:f,winningSide:N,matchUpStatusCodes:M,matchUpStatus:U}));if(G.error)return k({result:G,stack:v});if(E)return fc(Va(mo({},t),{matchUpStatus:U,targetData:P}));if(!b)return k({result:mo({},V),stack:v});const W=h.length===2?h[N-1]:h[0],{positionAssignments:q}=st({structure:u}),F=q==null?void 0:q.find(z=>z.drawPosition===W),L=c.drawMatchUps.find(z=>z.matchUpId===b.matchUpId),x=(n=L==null?void 0:L.drawPositions)==null?void 0:n.filter(Boolean),B=x.length===1;if(W){if(F!=null&&F.bye){const z=Ir({matchUpId:L.matchUpId,inContextDrawMatchUps:o,drawDefinition:s});if(B){const H=x.filter(Boolean)[0],Y=md({drawPosition:H,matchUpId:L.matchUpId,inContextDrawMatchUps:o}),Z=Kn({matchUpId:L.matchUpId,matchUp:L,matchUpStatus:d,matchUpStatusCodes:[],removeScore:!0,drawDefinition:s,winningSide:Y});return Z.error?k({result:Z,stack:v}):nm({drawPositionToAdvance:H,matchUpId:L.matchUpId,inContextDrawMatchUps:o,drawDefinition:s,matchUpsMap:c})}else if([ut.Walkover,ut.Defaulted].includes(b.matchUpStatus)){const H=fc(Va(mo({},t),{matchUpId:L.matchUpId,matchUpStatus:U,targetData:z}));if(H.error)return k({result:H,stack:v})}return k({result:mo({},V),stack:v})}return La({matchUpId:b.matchUpId,drawPosition:W,inContextDrawMatchUps:o,drawDefinition:s})}else if(_){if(!L)return{error:jr};if(B){const Y=x[0],Z=md({matchUpId:l.matchUpId,inContextDrawMatchUps:o,drawPosition:Y});console.log("existing drawPosition is winningSide",{walkoverWinningSide:Z})}const z=[ut.Walkover,ut.Defaulted].includes(L.matchUpStatus)?d:p,H=Kn({matchUpId:L.matchUpId,matchUp:L,matchUpStatusCodes:[],removeScore:!0,drawDefinition:s,matchUpStatus:z});if(H.error)return k({result:H,stack:v});if(z===p){const Y=fc(Va(mo({},t),{matchUpId:l.matchUpId,matchUpStatus:z,targetData:P}));if(Y.error)return Y}}return k({result:mo({},V),stack:v})}function vO(t){var e;const{loserTargetDrawPosition:r,tournamentRecord:n,loserTargetLink:o,drawDefinition:i,matchUpsMap:s,event:a}=t,l=(e=o==null?void 0:o.target)==null?void 0:e.structureId,{structure:c}=Ne({drawDefinition:i,structureId:l});return c?Yr({drawPosition:r,tournamentRecord:n,drawDefinition:i,structureId:l,matchUpsMap:s,event:a}):{error:ra}}function hd(t){return t===ut.DoubleWalkover?ut.Walkover:t===ut.DoubleDefault?ut.Defaulted:t}var Z6=Object.defineProperty,mO=Object.getOwnPropertySymbols,X6=Object.prototype.hasOwnProperty,e5=Object.prototype.propertyIsEnumerable,hO=(t,e,r)=>e in t?Z6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,t5=(t,e)=>{for(var r in e||(e={}))X6.call(e,r)&&hO(t,r,e[r]);if(mO)for(var r of mO(e))e5.call(e,r)&&hO(t,r,e[r]);return t};function r5({tournamentRecord:t,drawDefinition:e,structure:r,matchUp:n}){var o;const i="attemptToSetMatchUpStatusBYE";if(n!=null&&n.winningSide)return k({result:{error:fl},context:{matchUpStatus:nt},stack:i});const{positionAssignments:s}=Dt({structure:r}),a=s==null?void 0:s.filter(c=>c.bye).map(c=>c.drawPosition);return((o=n.drawPositions)==null?void 0:o.some(c=>a==null?void 0:a.includes(c)))?(n.matchUpStatus=nt,n.matchUpStatusCodes=[],Ze({tournamentId:t==null?void 0:t.tournamentId,context:i,drawDefinition:e,matchUp:n}),t5({},V)):k({result:{error:fx},info:"matchUp does not include BYE",stack:i})}var n5=Object.defineProperty,o5=Object.defineProperties,i5=Object.getOwnPropertyDescriptors,gO=Object.getOwnPropertySymbols,s5=Object.prototype.hasOwnProperty,a5=Object.prototype.propertyIsEnumerable,_O=(t,e,r)=>e in t?n5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,IO=(t,e)=>{for(var r in e||(e={}))s5.call(e,r)&&_O(t,r,e[r]);if(gO)for(var r of gO(e))a5.call(e,r)&&_O(t,r,e[r]);return t},PO=(t,e)=>o5(t,i5(e));function l5(t){const{tournamentRecord:e,drawDefinition:r,matchUpStatus:n,structure:o,matchUp:i}=t,s=!!(i.tieMatchUps&&!i.rondPosition&&t.inContextDrawMatchUps.find(g=>g.matchUpId===i.matchUpId).containerStructureId),a="attemptToSetMatchUpStatus",l=n===nt,c=i.winningSide,u=[Rt,tr].includes(n),p=rc({matchUpStatus:n}),d=pv({matchUpStatus:n}),v=!p&&!d,f=t.matchUpTieId||c&&p&&!u,m=c&&u,h=()=>Kn(PO(IO({},t),{removeScore:[Ho,ot].includes(n),matchUpStatus:n||Ft}));return v&&{error:Jg}||f&&im(t)||m&&c5(t)||c&&xa(t)||d&&h()||l&&r5({tournamentRecord:e,drawDefinition:r,structure:o,matchUp:i})||!p&&{error:Jg}||u&&u5(t)||s&&im(t)||k({result:{error:fl},stack:a})}function c5(t){const e=xa(t);return e.error?e:fc(t)}function u5(t){const e=im(PO(IO({},t),{removeScore:!0}));return e.error?e:fc(t)}function im(t){var e;const r="scoreModification";if(t.isCollectionMatchUp&&((e=t.dualMatchUp)==null?void 0:e.winningSide)&&!t.projectedWinningSide){const s=xa(t);if(s.error)return k({result:s,stack:r})}const o=!!t.matchUp.collectionId,i=Kn(t);if(o){const{matchUpTieId:s,drawDefinition:a,matchUpsMap:l}=t,c=uo({tournamentRecord:t.tournamentRecord,matchUpId:s,event:t.event,drawDefinition:a,matchUpsMap:l});if(c.error)return k({result:c,stack:r});Object.assign(i,{tieMatchUpResult:c})}return k({result:i,stack:r})}function d5({drawDefinition:t,structure:e,matchUp:r}){var n,o;const{drawPositions:i}=r,{positionAssignments:s}=st({drawDefinition:t,structure:e}),a=s==null?void 0:s.filter(({drawPosition:v})=>i==null?void 0:i.includes(v)),l=a==null?void 0:a.map(v=>{var f;const{extension:m}=Kt({element:v,name:Ko});return(f=m==null?void 0:m.value)==null?void 0:f.groupOrder}),{containerStructures:c}=Ra({drawDefinition:t}),u=c[e.structureId],p=(o=(n=ic({drawDefinition:t,structureId:u}))==null?void 0:n.links)==null?void 0:o.source;return{structureIds:p==null?void 0:p.filter(v=>{var f;return Xt(l,((f=v.source)==null?void 0:f.finishingPositions)||[])}).map(v=>v.source.structureId)}}function yO({drawDefinition:t,structureId:e}){if(!t)return{error:ue};const{structure:r}=Ne({drawDefinition:t,structureId:e}),n=((t==null?void 0:t.links)||[]).filter(i=>{var s;return((s=i.source)==null?void 0:s.structureId)===e}).map(i=>{var s;return(s=i.target)==null?void 0:s.structureId});return{playoffStructures:((t==null?void 0:t.structures)||[]).filter(i=>n.includes(i.structureId)&&i.stage===ft),structure:r}}function SO({withStageGrouping:t,stageSequences:e,stageSequence:r,roundTarget:n,stages:o,event:i,stage:s}){if(!i)return{error:Ge};const a={},l=[];for(const c of i.drawDefinitions||[]){const{structures:u,stageStructures:p}=an({withStageGrouping:t,stageSequences:e,drawDefinition:c,stageSequence:r,roundTarget:n,stages:o,stage:s});if(l.push(...u),p)for(const d of Object.keys(p))a[d]||(a[d]=[]),a[d].push(...p[d])}return{structures:l,stageStructures:a}}function p5({withStageGrouping:t,tournamentRecord:e,stageSequences:r,stageSequence:n,roundTarget:o,stages:i,stage:s}){if(!e)return{error:re};const a={},l=[];for(const c of e.events||[]){const{structures:u,stageStructures:p}=SO({withStageGrouping:t,stageSequences:r,stageSequence:n,roundTarget:o,stages:i,event:c,stage:s});if(u&&l.push(...u),p)for(const d of Object.keys(p))a[d]||(a[d]=[]),a[d].push(...p[d])}return{structures:l,stageStructures:a}}function f5(t){const e=[];if(!(t!=null&&t.drawDefinition))return{error:ue};const r=Hi(t),n=OO(t);return{actions:e,state:{isComplete:r,hasPlayoffPositionsFilled:n}}}function Hi(t){if(!(t!=null&&t.drawDefinition))return!1;const e=sc(t),r=e==null?void 0:e.includesTeamMatchUps;let{completedMatchUps:n,pendingMatchUps:o,upcomingMatchUps:i}=e||{};return r&&(n=n==null?void 0:n.filter(({matchUpType:a})=>a===Qe),o=o==null?void 0:o.filter(({matchUpType:a})=>a===Qe),i=i==null?void 0:i.filter(({matchUpType:a})=>a===Qe)),!!((n==null?void 0:n.length)&&!(o!=null&&o.length)&&!(i!=null&&i.length))}function OO(t){var e,r;const{drawDefinition:n,structureId:o}=t;if(!n)return{error:ue};const{playoffStructures:i}=yO({drawDefinition:n,structureId:o});if(!(i!=null&&i.length))return!1;const s=((r=(e=n==null?void 0:n.entries)==null?void 0:e.filter(u=>Fi.includes(u==null?void 0:u.entryStatus)))==null?void 0:r.length)||0;let a=0;return(i||[]).reduce((u,p)=>{var d;return!((d=p==null?void 0:p.positionAssignments)!=null&&d.filter(f=>(f.participantId&&a++,!(f!=null&&f.bye)&&!(f!=null&&f.participantId))).length)&&u},!0)||a===s}function bO({drawDefinition:t,structure:e,matchUp:r}){const n=[];if(e.finishingPosition===ya&&Hi({drawDefinition:t,structure:e})){const{structureIds:i}=d5({drawDefinition:t,structure:e,matchUp:r});i!=null&&i.length&&n.push(...i)}return{connectedStructureIds:n}}function sm(t){const{dualWinningSideChange:e,matchUpStatusCodes:r,tournamentRecord:n,drawDefinition:o,matchUpFormat:i,matchUpStatus:s,winningSide:a,matchUpId:l,structure:c,matchUp:u,event:p,score:d}=t,v=rc({matchUpStatus:s})||[Ho,Wr].includes(s)&&e,f="attemptToModifyScore",m=!!u.collectionId,h=Co({drawDefinition:o,structure:c});if(!(m||h||v5({structure:c,matchUp:u})))return{error:Kg};const _=[ot].includes(s),I=Kn({matchUpStatusCodes:v&&r||[],matchUpStatus:v&&s||Mt,tournamentRecord:n,drawDefinition:o,matchUpFormat:i,removeScore:_,winningSide:a,matchUpId:l,matchUp:u,event:p,score:d});return k({result:I,stack:f})}function v5({structure:t,matchUp:e}){const{drawPositions:r}=e,{positionAssignments:n}=Dt({structure:t}),o=n==null?void 0:n.filter(i=>(r==null?void 0:r.includes(i.drawPosition))&&i.participantId);return(o==null?void 0:o.length)===2}function am({lineUp:t}){if(!Array.isArray(t))return;const e={};return We(t.flatMap(({collectionAssignments:n})=>n.map(({collectionId:o,collectionPosition:i})=>[o,i].join("|")))).forEach(n=>{const[o,i]=n.split("|"),s=parseInt(i),{assignedParticipantIds:a}=Uu({collectionPosition:s,collectionId:o,lineUp:t});a.forEach(l=>{e[l]||(e[l]=[]),e[l].push({collectionId:o,collectionPosition:s})})}),Object.keys(e).map(n=>({participantId:n,collectionAssignments:e[n]}))}function Ba(t){if(!t)return 1/0;if(ht(t))return Te(t);const e=t.split("-")[0];return ht(e)?Te(e):1/0}const Zt=({finishingPosition:t=ji,qualifyingRoundNumber:e,structureAbbreviation:r,seedAssignments:n=[],stageSequence:o=1,structureOrder:i,seedingProfile:s,matchUpFormat:a,structureType:l,structureName:c,matchUpType:u,matchUps:p=[],structureId:d,roundOffset:v,roundLimit:f,stageOrder:m,structures:h,stage:g})=>{const _={structureId:d??Ye(),structureAbbreviation:r,finishingPosition:t,seedAssignments:n,matchUpFormat:a,stageSequence:o,structureName:c};i&&(_.structureOrder=i),l&&(_.structureType=l),s&&(typeof s=="string"?_.seedingProfile=s:typeof s=="object"&&typeof s.positioning=="string"&&(_.seedingProfile=s.positioning)),u&&(_.matchUpType=u),v&&(_.roundOffset=v),m&&(_.stageOrder=m),f&&(_.roundLimit=f),g&&(_.stage=g),e&&(_.qualifyingRoundNumber=e);const I=p.flatMap(({drawPositions:P})=>P).filter(Boolean);return h?_.structures=h:(_.matchUps=p,_.positionAssignments=We(I).sort((P,y)=>P-y).map(P=>({drawPosition:P}))),_};var m5=Object.defineProperty,h5=Object.defineProperties,g5=Object.getOwnPropertyDescriptors,TO=Object.getOwnPropertySymbols,_5=Object.prototype.hasOwnProperty,I5=Object.prototype.propertyIsEnumerable,wO=(t,e,r)=>e in t?m5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,EO=(t,e)=>{for(var r in e||(e={}))_5.call(e,r)&&wO(t,r,e[r]);if(TO)for(var r of TO(e))I5.call(e,r)&&wO(t,r,e[r]);return t},P5=(t,e)=>h5(t,g5(e));function vc({structureName:t=he,stageSequence:e=1,structureOptions:r,appliedPolicies:n,seedingProfile:o,stage:i=he,matchUpType:s,roundTarget:a,structureId:l,drawSize:c,idPrefix:u,isMock:p,uuids:d}){const{groupCount:v,groupSize:f}=y5({structureOptions:r,appliedPolicies:n,drawSize:c}),m=ya;let h;const g=ce(1,v+1).map(I=>{const P=S5({groupSize:f,structureOrder:I,matchUpType:s,drawSize:c,idPrefix:u,isMock:p});return h=Math.max(...P.map(({roundNumber:y})=>y)),Zt({structureName:`Group ${I}`,structureId:d==null?void 0:d.pop(),structureType:Au,finishingPosition:m,structureOrder:I,matchUps:P})}),_=Zt({structureId:l||(d==null?void 0:d.pop()),structureType:gr,finishingPosition:m,seedingProfile:o,structureName:t,stageSequence:e,structures:g,stage:i});return a&&it({extension:{name:Gn,value:a},element:_}),EO({structures:[_],maxRoundNumber:h,groupCount:v,links:[],groupSize:f},V)}function y5({appliedPolicies:t,structureOptions:e,drawSize:r}){let n=e==null?void 0:e.groupSize;const o=(e==null?void 0:e.groupSizeLimit)||8,{validGroupSizes:i}=lm({groupSizeLimit:o,drawSize:r}),s=i&&Math.max(...i);n&&(i==null?void 0:i.includes(n))||(n&&n>4||!(i!=null&&i.includes(4))?n=s:n=4);const l=Math.ceil(r/n);return{groupSize:n,groupCount:l}}function lm({drawSize:t,groupSizeLimit:e=10}){const r=ce(3,e+1).filter(n=>{const o=Math.ceil(t/n),i=o*n-t,s=Math.ceil(t/o),a=Math.ceil(i/o);return(!i||i<n)&&s===n&&s>=3&&a<2});return P5(EO({},V),{validGroupSizes:r})}function S5({structureOrder:t,matchUpType:e,groupSize:r,drawSize:n,idPrefix:o,isMock:i,uuids:s}){const a=(t-1)*r,l=ce(1+a,r+1+a),{uniqueMatchUpGroupings:c}=Bv({drawPositions:l}),u=aS({groupSize:r,drawPositionOffset:a});return c.map(v).sort((f,m)=>(f.roundNumber||1/0)-(m.roundNumber||1/0));function d(f){return u.reduce((m,h,g)=>h.includes(f)?g+1:m,void 0)}function v(f){const m=od(f),h=d(m),g=[1,n],_=O5({structureOrder:t,drawPositions:f,roundNumber:h,idPrefix:o,uuids:s}),I={matchUpStatus:h?ut.ToBePlayed:ut.Bye,matchUpType:e,finishingPositionRange:{winner:g,loser:g},drawPositions:f,roundNumber:h,matchUpId:_};return i&&(I.isMock=!0),I}}function O5({structureOrder:t,drawPositions:e,roundNumber:r,idPrefix:n,uuids:o}){return n?`${n}-${t}-${r}-DP-${e.join("-")}`:(o==null?void 0:o.pop())||Ye()}var b5=Object.defineProperty,T5=Object.defineProperties,w5=Object.getOwnPropertyDescriptors,$O=Object.getOwnPropertySymbols,E5=Object.prototype.hasOwnProperty,$5=Object.prototype.propertyIsEnumerable,NO=(t,e,r)=>e in t?b5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ka=(t,e)=>{for(var r in e||(e={}))E5.call(e,r)&&NO(t,r,e[r]);if($O)for(var r of $O(e))$5.call(e,r)&&NO(t,r,e[r]);return t},cm=(t,e)=>T5(t,w5(e));function gd(t){const{roundRobinGroupsCount:e,participantsCount:r,cluster:n}=t;if(!ht(r))return ka({seedBlocks:void 0},k({result:{error:X},context:{participantsCount:r},stack:"getSeedBlocks"}));const o=ea(r);if(e){const v=Math.min(e,o),f=[];let m=1;for(ce(0,v).forEach(()=>{f.push([m]),m++});m<o;){const h=ce(m,m+v);m+=v,f.push(h)}return cm(ka({},V),{seedBlocks:f})}const i=ce(1,o+1),s=[];let a=o/2;for(;a>1;){const v=qt(i,a),f=v.length;v.forEach((m,h)=>{let g;const _=h<f/2,I=h%2===0,P=m[0],y=m[m.length-1];n&&f>4?f===8?g=_?y:P:g=I?P:y:g=_?P:y,Xt(m,s)||s.push(g)}),a=a/2}const l=i.filter(v=>!s.includes(v));for(;l.length;)l.length%2===0?s.push(l.pop()):s.push(l.shift());const c=ce(0,20).map(v=>Math.pow(2,v));c.unshift(1);const u=c.indexOf(o);let p=0;const d=[];return ce(0,u).forEach(v=>{d.push(s.slice(p,p+c[v])),p+=c[v]}),cm(ka({},V),{seedBlocks:d})}function _d({roundRobinGroupsCount:t,drawSize:e}){const r="getSeedGroups";if(!ht(e))return ka({seedGroups:void 0},k({result:{error:X},context:{drawSize:e},stack:r}));if(t){if(!ht(t))return ka({seedGroups:void 0},k({result:{error:X},context:{roundRobinGroupsCount:t},stack:r}));let n=1;const o=Math.floor(e/t);return{seedGroups:ce(0,o).map(()=>{const s=ce(n,n+t);return n+=t,s})}}else{const{seedBlocks:n}=gd({participantsCount:e,roundRobinGroupsCount:t});let o=0;return{seedGroups:(n||[]).map(s=>(s||[]).map(()=>(o+=1,o)))}}}function N5({roundRobinGroupsCount:t,participantsCount:e}){if(t){const{validGroupSizes:o}=lm({drawSize:e}),i=o==null?void 0:o.map(a=>Math.ceil(e/a));if(!(i!=null&&i.includes(t)))return k({result:{error:X},context:{roundRobinGroupsCount:t}})}const{seedGroups:r}=_d({drawSize:e,roundRobinGroupsCount:t}),n=(r==null?void 0:r.map(o=>Math.min(...o)))||[];return cm(ka({},V),{seedingThresholds:n})}function Rs({provisionalPositioning:t,appliedPolicies:e,drawDefinition:r,allPositions:n,structure:o}){var i;let s=[];if(!o)return{error:ra};const{roundMatchUps:a}=Je({matchUpFilters:{roundNumbers:[1]},provisionalPositioning:t,structure:o}),{seedAssignments:l}=$n({provisionalPositioning:t,drawDefinition:r,structure:o}),{positionAssignments:c}=Dt({structure:o}),u=c==null?void 0:c.length,p=(l==null?void 0:l.length)||0;let d=[];const f=Object.keys(a).map(M=>parseInt(M)).sort((M,D)=>M-D).map(M=>{const D=a[M].map(j=>j.drawPositions).flat(1/0).filter(Boolean),R=D.filter(j=>!d.includes(j));return d=d.concat(...D),R}).filter(M=>M.length).reverse(),m=f.pop(),h=m&&Math.min(...m)-1||0,g=(i=e==null?void 0:e.seeding)==null?void 0:i.seedingProfile,_=(m==null?void 0:m.length)||0,I=f.filter(M=>M.filter(D=>D<=p).length),{stage:P,structureType:y,roundLimit:S}=o,O=y===gr,b=!O&&(f==null?void 0:f.length),w=(m==null?void 0:m.length)&&!Zr(_),T=!O&&P===we&&S,$=I.flat(1/0),N=b?$==null?void 0:$.length:0,E=n?u:p,A=w?0:!b&&E||E&&$.length<E&&E-$.length||0;if(T){const M=o!=null&&o.matchUps?o.matchUps.filter(({roundNumber:R})=>R===o.roundLimit).length:0,D=m.length/M;if(!b){const R=mc(g),j=qt(m,D);let G=1;const W=ce(0,j[0].length).map(()=>{const q=ce(G,G+j.length);return G+=j.length,q});({validSeedBlocks:s}=UO({drawPositionBlocks:j,positioning:R,seedGroups:W}))}}else O?{validSeedBlocks:s}=U5({seedingProfile:g,structure:o}):b?s=I.map(M=>({seedNumbers:M,drawPositions:M})):w&&qt(m,2).map((D,R)=>({drawPositions:[D[0]],seedNumbers:[R+1]})).forEach(D=>s.push(D));if(!O&&!w&&!T){const{blocks:M}=A5({drawPositionOffset:h,seedNumberOffset:N,seedCountGoal:A,seedingProfile:g,baseDrawSize:_});M.forEach(D=>s.push(D))}const C=s.flatMap(M=>M.drawPositions).reduce((M,D)=>(m==null?void 0:m.includes(D))&&M,!0);return!w&&!b&&!O&&!C?{error:ix,validSeedBlocks:[],isContainer:O,isFeedIn:b}:{validSeedBlocks:s,isContainer:O,isFeedIn:b,isLucky:w}}function U5({seedingProfile:t,structure:e}){var r,n;const o=e.structures||[],i=o.length,s=(r=st({structure:e}))==null?void 0:r.positionAssignments,a=mc(t),l=(n=s==null?void 0:s.length)!=null?n:0,{seedGroups:c}=_d({roundRobinGroupsCount:i,drawSize:l}),u=o.map(p=>{var d;return(d=st({structure:p}).positionAssignments)==null?void 0:d.map(v=>v.drawPosition)});return UO({drawPositionBlocks:u,positioning:a,seedGroups:c})}function UO({positioning:t,seedGroups:e,drawPositionBlocks:r}){const n=[],o=(a,l)=>a-l,i=(a,l)=>l-a,s=[];return e.forEach((a,l)=>{l&&t!==nv&&mr(a),a.forEach((c,u)=>{const p=l%2?r.length-u-1:u,d=r[p].sort(l%2?i:o).find(v=>!s.includes(v));s.push(d),n.push({seedNumbers:[c],drawPositions:[d]})})}),{validSeedBlocks:n}}function A5(t){const{drawPositionOffset:e=0,roundRobinGroupsCount:r,seedNumberOffset:n=0,seedingProfile:o,seedCountGoal:i,baseDrawSize:s}=t;let a=1;const l=[],{seedBlocks:c}=gd({cluster:mc(o)===rv,participantsCount:s,roundRobinGroupsCount:r});a=0;for(const p of c){if(a+1>i)break;const d=p.map(f=>f+e),v=u(a+1,p.length).map(f=>+f+n);a+=p.length,l.push({drawPositions:d,seedNumbers:v})}return{blocks:l};function u(p,d){return Array.from(new Array(d),(v,f)=>f+p)}}function Id({appliedPolicies:t,drawDefinition:e,seedBlockInfo:r,drawPosition:n,structureId:o,seedNumber:i}){var s,a,l,c,u;const{structure:p}=Ne({drawDefinition:e,structureId:o});t||(t=pt({drawDefinition:e}).appliedPolicies);let d=r==null?void 0:r.validSeedBlocks;if(!d&&p&&(d=(s=Rs({appliedPolicies:t,drawDefinition:e,structure:p}))==null?void 0:s.validSeedBlocks),(l=(a=t==null?void 0:t.seeding)==null?void 0:a.validSeedPositions)!=null&&l.ignore)return!0;if((u=(c=t==null?void 0:t.seeding)==null?void 0:c.validSeedPositions)!=null&&u.strict){const f=d.find(h=>h.seedNumbers.includes(i));return((f==null?void 0:f.drawPositions)||[]).includes(n)}return[].concat(...d.map(f=>f.drawPositions)).includes(n)}function Pd(t){var e,r;const{provisionalPositioning:n,drawDefinition:o,seedBlockInfo:i,structureId:s,randomize:a}=t,{structure:l}=Ne({drawDefinition:o,structureId:s}),{seedAssignments:c}=$n({provisionalPositioning:n,drawDefinition:o,structure:l}),{positionAssignments:u}=Dt({structure:l}),p=u==null?void 0:u.filter(j=>{var G,W;return(W=(G=j.participantId)!=null?G:j.bye)!=null?W:j.qualifier}),d=p==null?void 0:p.map(j=>j.drawPosition).filter(Boolean),{appliedPolicies:v}=pt({drawDefinition:o}),h=((i==null?void 0:i.validSeedBlocks)||l&&((e=Rs({provisionalPositioning:n,appliedPolicies:v,drawDefinition:o,structure:l}))==null?void 0:e.validSeedBlocks)||[]).filter(j=>j.drawPositions.filter(W=>!(d!=null&&d.includes(W))).length)[0],g=c==null?void 0:c.map(j=>j.participantId).filter(Boolean),_=u==null?void 0:u.map(j=>j.participantId).filter(Boolean),I=g==null?void 0:g.filter(j=>_==null?void 0:_.includes(j)),P=g==null?void 0:g.filter(j=>!(_!=null&&_.includes(j))),y=c==null?void 0:c.filter(j=>P==null?void 0:P.includes(j.participantId)),S=c==null?void 0:c.filter(j=>!j.participantId),b=((y==null?void 0:y.length)||(S==null?void 0:S.length))&&(h==null?void 0:h.drawPositions.filter(j=>!(d!=null&&d.includes(j))))||[],w=a?mr(b):b,T=[],$=w.map(()=>{const j=R(y,T),G=j==null?void 0:j.participantId;return G&&T.push(G),G}).filter(Boolean),N=c==null?void 0:c.filter(j=>I==null?void 0:I.includes(j.participantId)).map(j=>j.seedNumber),A=((h==null?void 0:h.seedNumbers)||[]).filter(j=>!(N!=null&&N.includes(j))),U=c==null?void 0:c.filter(j=>A.includes(j.seedNumber)).map(j=>j.participantId),C=(r=v==null?void 0:v.seeding)==null?void 0:r.duplicateSeedNumbers;return{nextSeedBlock:h,unplacedSeedParticipantIds:(C!==void 0?C:!0)?$:U,unplacedSeedNumbers:A,unfilledPositions:w,unplacedSeedAssignments:y};function R(j,G){const W=j.filter(x=>!G.includes(x.participantId)),q=Math.min(...W.map(x=>Ba(x.seedValue))),F=W.filter(x=>Ba(x.seedValue)===q);return mr(F).pop()}}function mc(t){if(typeof t=="string")return t;if(typeof t=="object")return t.positioning}function Fs({participantId:t,drawDefinition:e,entryStatus:r,entryStage:n}){var o;if(!e)return{error:ue};const i=(o=e.entries)==null?void 0:o.find(s=>s.participantId===t&&(!r||r===s.entryStatus)&&(!n||n===s.entryStage));return t&&i}var C5=Object.defineProperty,AO=Object.getOwnPropertySymbols,M5=Object.prototype.hasOwnProperty,D5=Object.prototype.propertyIsEnumerable,CO=(t,e,r)=>e in t?C5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,j5=(t,e)=>{for(var r in e||(e={}))M5.call(e,r)&&CO(t,r,e[r]);if(AO)for(var r of AO(e))D5.call(e,r)&&CO(t,r,e[r]);return t};function xs({provisionalPositioning:t,tournamentRecord:e,drawDefinition:r,seedingProfile:n,participantId:o,seedBlockInfo:i,structureId:s,seedNumber:a,seedValue:l,eventId:c,event:u}){var p,d;const v="assignSeed",{structure:f}=Ne({drawDefinition:r,structureId:s}),{positionAssignments:m}=Dt({structure:f}),h=$n({provisionalPositioning:t,drawDefinition:r,structure:f}).seedAssignments,g=h.map(b=>b.seedNumber),_=Fs({drawDefinition:r,participantId:o});if(o&&!_)return k({result:{error:So},context:{participantId:o},stack:v});const I=u?(d=(p=Nt({event:u}).flightProfile)==null?void 0:p.flights)==null?void 0:d.length:0,P=I&&I>1,y=m==null?void 0:m.find(b=>b.participantId===o),S=y==null?void 0:y.drawPosition;if(S&&!Id({drawPosition:S,drawDefinition:r,seedBlockInfo:i,structureId:s,seedNumber:a}))return k({result:{error:Wg},context:{assignedDrawPosition:S},info:"invalid seed position",stack:v});g.includes(a)||h.push({seedNumber:a,seedValue:l});let O;return h.forEach(b=>{b.participantId===o&&b.seedNumber!==a&&(b.participantId=void 0),b.seedNumber===a&&(b.participantId=o,!(n!=null&&n.groupSeedingThreshold)&&!P&&(b.seedValue=l||a),O=!0)}),O?(Py({tournamentId:e==null?void 0:e.tournamentId,drawDefinition:r,structure:f,eventId:c}),j5({},V)):k({result:{error:ox},stack:v})}function MO({inContextDrawMatchUps:t,drawDefinition:e,assignments:r,matchUpsMap:n,structure:o}){var i,s,a;const l=(i=Ra({drawDefinition:e}))==null?void 0:i.containedStructures,c=((s=l==null?void 0:l[o.structureId])==null?void 0:s.map(({structureId:f})=>f))||[];c.push(o==null?void 0:o.structureId);const u=(r==null?void 0:r.map(({drawPosition:f})=>f))||[],p=(t==null?void 0:t.filter(f=>c.includes(f.structureId)&&Ht(f.drawPositions||[],u).length))||[],d=p.map(({matchUpId:f})=>f),v=((a=n==null?void 0:n.drawMatchUps)==null?void 0:a.filter(f=>d.includes(f.matchUpId)))||[];return{drawPositions:u,matchUps:v,targetMatchUps:p}}var R5=Object.defineProperty,DO=Object.getOwnPropertySymbols,F5=Object.prototype.hasOwnProperty,x5=Object.prototype.propertyIsEnumerable,jO=(t,e,r)=>e in t?R5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L5=(t,e)=>{for(var r in e||(e={}))F5.call(e,r)&&jO(t,r,e[r]);if(DO)for(var r of DO(e))x5.call(e,r)&&jO(t,r,e[r]);return t};function um({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:n,assignments:o,structure:i,event:s}){const{drawPositions:a,matchUps:l,targetMatchUps:c}=MO({inContextDrawMatchUps:t,matchUpsMap:n,assignments:o,structure:i});for(const u of c)u.matchUpType===hn&&(u.sides||[]).forEach((p,d)=>{var v;if(p!=null&&p.drawPosition&&(a!=null&&a.includes(p.drawPosition))){const f=l.find(({matchUpId:m})=>m===u.matchUpId);(v=f==null?void 0:f.sides)!=null&&v[d]&&(f==null||delete f.sides[d].lineUp,Ze({tournamentId:e==null?void 0:e.tournamentId,context:"cleanupLineUps",eventId:s==null?void 0:s.eventId,drawDefinition:r,matchUp:f}))}});return L5({},V)}var V5=Object.defineProperty,RO=Object.getOwnPropertySymbols,B5=Object.prototype.hasOwnProperty,k5=Object.prototype.propertyIsEnumerable,FO=(t,e,r)=>e in t?V5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xO=(t,e)=>{for(var r in e||(e={}))B5.call(e,r)&&FO(t,r,e[r]);if(RO)for(var r of RO(e))k5.call(e,r)&&FO(t,r,e[r]);return t};function An({provisionalPositioning:t,inContextDrawMatchUps:e,isQualifierPosition:r,sourceMatchUpStatus:n,tournamentRecord:o,drawDefinition:i,seedingProfile:s,participantId:a,seedBlockInfo:l,drawPosition:c,matchUpsMap:u,structureId:p,event:d}){var v;const f="assignDrawPosition";if(!a&&!r)return k({result:{error:Et},stack:f});u=u||lr({drawDefinition:i}),e||({matchUps:e}=Lt({inContext:!0,drawDefinition:i,matchUpsMap:u}));const m=Ne({drawDefinition:i,structureId:p});if(m.error)return k({result:m,stack:f});const{structure:h}=m;if(!h)return{error:bt};if(Co({drawDefinition:i,structure:h}))return k({result:{error:tn},stack:f});const{seedAssignments:g}=$n({provisionalPositioning:t,drawDefinition:i,structure:h}),_=g==null?void 0:g.find(N=>N.participantId===a),I=_==null?void 0:_.seedNumber,{appliedPolicies:P}=pt({tournamentRecord:o,drawDefinition:i,structure:h,event:d});if(I&&!Id({seedNumber:I,appliedPolicies:P,drawDefinition:i,seedBlockInfo:l,drawPosition:c,structureId:p}))return k({result:{error:Wg},context:{drawPosition:c},stack:f});const S=Dt({structure:h}).positionAssignments||[],O=S==null?void 0:S.find(N=>N.drawPosition===c);if(!O)return k({result:{error:ta},context:{drawPosition:c},stack:f});if(S==null?void 0:S.map(ct).includes(a))return k({result:{error:ia},context:{drawPosition:c},stack:f});const{containsParticipant:w,containsBye:T}=$(O);if(T){const N=Fa({inContextDrawMatchUps:e,tournamentRecord:o,drawDefinition:i,drawPosition:c,structureId:p,matchUpsMap:u,event:d});if(N.error)return k({result:N,stack:f})}if(w&&O.participantId!==a){const{activeDrawPositions:N}=dc({drawDefinition:i,structureId:p});if(N.includes(c))return k({result:{error:Xp},stack:f});um({assignments:[O],inContextDrawMatchUps:e,tournamentRecord:o,drawDefinition:i,matchUpsMap:u,structure:h})}if(O.participantId=a,r&&(O.qualifier=!0),((h==null?void 0:h.stageSequence)||0)>1||h.stage&&[xt,ft].includes(h.stage)){const N=h.stage===we?we:he,E=(v=i.structures)==null?void 0:v.find(C=>(C==null?void 0:C.stage)===N&&(C==null?void 0:C.stageSequence)===1),U=((E==null?void 0:E.seedAssignments)||[]).find(C=>C.participantId===a);if(U!=null&&U.participantId){const{participantId:C,seedNumber:M,seedValue:D}=U;xs({eventId:d==null?void 0:d.eventId,provisionalPositioning:t,tournamentRecord:o,drawDefinition:i,seedingProfile:s,participantId:C,seedNumber:M,seedValue:D,structureId:p,event:d})}}if(h.structureType!==gr)G5({provisionalPositioning:t,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:o,drawDefinition:i,drawPosition:c,matchUpsMap:u,structure:h,event:d});else{YS({positionAssignments:S,tournamentRecord:o,drawDefinition:i,matchUpsMap:u,structure:h});const{drawPositions:N,matchUps:E,targetMatchUps:A}=MO({assignments:[O],inContextDrawMatchUps:e,drawDefinition:i,matchUpsMap:u,structure:h});if(N&&(E==null?void 0:E.length)===1&&E[0].matchUpType===Qe){const C=((A==null?void 0:A[0].sides)||[]).reduce((M,D,R)=>N!=null&&N.includes(D.drawPosition)?R:M,void 0);om({inContextTargetMatchUp:A[0],teamParticipantId:a,matchUp:E[0],drawPositionSideIndex:C,tournamentRecord:o,drawDefinition:i})}}return oi({tournamentId:o==null?void 0:o.tournamentId,drawDefinition:i,structure:h,event:d}),xO({positionAssignments:S},V);function $(N){const E=N.bye,A=N.qualifier,U=N.participantId;return{containsBye:E,containsQualifier:A,containsParticipant:U,filled:E||A||U}}}function G5({provisionalPositioning:t,inContextDrawMatchUps:e,sourceMatchUpStatus:r,tournamentRecord:n,drawDefinition:o,drawPosition:i,matchUpsMap:s,structure:a,event:l}){const c={isCollectionMatchUp:!1},{matchUps:u}=Je({provisionalPositioning:t,matchUpFilters:c,drawDefinition:o,matchUpsMap:s,structure:a,event:l}),{roundMatchUps:p}=Tr({matchUps:u}),{initialRoundNumber:d}=js({drawPosition:i,matchUps:u}),v=d&&(p==null?void 0:p[d].find(f=>{var m;return(m=f.drawPositions)==null?void 0:m.includes(i)}));if(v){const f=La({matchUpId:v.matchUpId,inContextDrawMatchUps:e,sourceMatchUpStatus:r,tournamentRecord:n,drawDefinition:o,drawPosition:i,matchUpsMap:s});if(f.error)return k({stack:"assignDrawPositionToMatchUps",context:{drawPosition:i},result:f})}return xO({},V)}var W5=Object.defineProperty,H5=Object.defineProperties,q5=Object.getOwnPropertyDescriptors,LO=Object.getOwnPropertySymbols,z5=Object.prototype.hasOwnProperty,Y5=Object.prototype.propertyIsEnumerable,VO=(t,e,r)=>e in t?W5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dm=(t,e)=>{for(var r in e||(e={}))z5.call(e,r)&&VO(t,r,e[r]);if(LO)for(var r of LO(e))Y5.call(e,r)&&VO(t,r,e[r]);return t},BO=(t,e)=>H5(t,q5(e));function K5({winnerMatchUpDrawPositionIndex:t,inContextDrawMatchUps:e,projectedWinningSide:r,sourceMatchUpStatus:n,winningDrawPosition:o,tournamentRecord:i,winnerTargetLink:s,sourceMatchUpId:a,drawDefinition:l,winnerMatchUp:c,dualMatchUp:u,matchUpsMap:p,event:d}){var v,f,m;const h="directWinner";if(s){const g=c.drawPositions||[],_=g[t],I=s.source.structureId,P=Ne({structureId:I,drawDefinition:l});if(P.error)return P;const{structure:y}=P,{positionAssignments:S}=Dt({structureId:I,drawDefinition:l}),O=S==null?void 0:S.find(U=>U.drawPosition===o),b=O==null?void 0:O.participantId,w=s.target.structureId,{positionAssignments:T}=Dt({structureId:w,drawDefinition:l}),$=T==null?void 0:T.find(U=>U.participantId===b),N=$==null?void 0:$.drawPosition,E=T==null?void 0:T.filter(U=>{const C=g.includes(U.drawPosition),M=!U.participantId&&!U.bye&&!U.qualifier;return C&&M}).map(U=>U.drawPosition),A=E==null?void 0:E.includes(_);if(b&&s.target.roundNumber===1&&A)An({drawPosition:_,participantId:b,structureId:w,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,drawDefinition:l,matchUpsMap:p,event:d});else if(b&&(E!=null&&E.length)){const U=E.pop();U&&An({participantId:b,structureId:w,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,drawDefinition:l,drawPosition:U,matchUpsMap:p,event:d})}else if(N){const U=La({drawPosition:N,matchUpId:c.matchUpId,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:l,matchUpsMap:p});if(U.error)return k({result:U,stack:h})}else if((y==null?void 0:y.stage)!==we){const U="winner target position unavaiallble";return console.log(U),{error:U}}if(y!=null&&y.seedAssignments&&y.structureId!==w){const U=y.seedAssignments.find(({participantId:M})=>M===b),C=U==null?void 0:U.participantId;U&&C&&xs(BO(dm({eventId:c==null?void 0:c.eventId,structureId:w},U),{tournamentRecord:i,drawDefinition:l,participantId:C}))}}else{const g=La({matchUpId:c.matchUpId,drawPosition:o,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:l,matchUpsMap:p});if(g.error)return g}if(u&&r){const g=(v=u.sides)==null?void 0:v.find(_=>_.sideNumber===r);if(g!=null&&g.lineUp){const _=u.roundPosition,I=c.roundPosition,P=_===I&&_!==1||Math.floor(_/2)===I?2:1,y=(f=p==null?void 0:p.drawMatchUps)==null?void 0:f.find(({matchUpId:b})=>b===c.matchUpId),S=[1,2].map(b=>{var w;const T=((w=y.sides)==null?void 0:w.find($=>$.sideNumber===b))||{};return BO(dm({},T),{sideNumber:b})});y.sides=S;const O=y.sides.find(b=>b.sideNumber===P);if(O){const b=(m=g.lineUp)==null?void 0:m.filter(w=>w==null?void 0:w.participantId);O.lineUp=am({lineUp:b}),Ze({tournamentId:i==null?void 0:i.tournamentId,eventId:c==null?void 0:c.eventId,matchUp:y,context:h,drawDefinition:l})}}}return dm({},V)}var Q5=Object.defineProperty,J5=Object.defineProperties,Z5=Object.getOwnPropertyDescriptors,kO=Object.getOwnPropertySymbols,X5=Object.prototype.hasOwnProperty,ez=Object.prototype.propertyIsEnumerable,GO=(t,e,r)=>e in t?Q5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yd=(t,e)=>{for(var r in e||(e={}))X5.call(e,r)&&GO(t,r,e[r]);if(kO)for(var r of kO(e))ez.call(e,r)&&GO(t,r,e[r]);return t},WO=(t,e)=>J5(t,Z5(e));function tz(t){var e,r;const{loserMatchUpDrawPositionIndex:n,inContextDrawMatchUps:o,projectedWinningSide:i,sourceMatchUpStatus:s,loserDrawPosition:a,tournamentRecord:l,loserTargetLink:c,drawDefinition:u,loserMatchUp:p,dualMatchUp:d,matchUpsMap:v,event:f}=t,m="directLoser",h=c.linkCondition,g=p.drawPositions||[],_=h===co&&p.roundNumber===2&&Math.min(...g.filter(Boolean)),I=_||g[n],P=_||g[1-n],y=c.source.structureId,{structure:S}=Ne({structureId:y,drawDefinition:u}),{matchUps:O}=Je({afterRecoveryTimes:!1,inContext:!0,drawDefinition:u,structure:S,event:f}),w=O.filter(L=>{var x;return(x=L.drawPositions)==null?void 0:x.includes(a)}).filter(L=>{const x=L.sides.find(z=>z.drawPosition===a),B=L.matchUpStatus===ot||L.matchUpStatus===Xe&&!Gt(L);return(x==null?void 0:x.sideNumber)===L.winningSide&&!B}),T=h===co&&w.length===0,{positionAssignments:$}=Dt({structureId:y,drawDefinition:u}),N=$==null?void 0:$.find(L=>L.drawPosition===a),E=N==null?void 0:N.participantId,A=c.target.structureId,{positionAssignments:U}=Dt({structureId:A,drawDefinition:u}),C=U==null?void 0:U.filter(({drawPosition:L})=>g.includes(L));if(C==null?void 0:C.some(L=>L.participantId===E))return yd({},V);const D=C==null?void 0:C.filter(L=>{const x=g.includes(L.drawPosition),B=!L.participantId&&!L.bye&&!L.qualifier;return x&&B}).map(L=>L.drawPosition),R=D==null?void 0:D.includes(I),j=c.target.roundNumber>1&&(D==null?void 0:D.length),G=c.target.roundNumber===1&&R;if(_){const L=W();if(L.error)return k({result:L,stack:m})}else if(G){const L=F();if(L.error)return k({result:L,stack:m})}else if(E&&j){const L=D.sort(er)[0],x=An({participantId:E,structureId:A,drawPosition:L,inContextDrawMatchUps:o,sourceMatchUpStatus:s,tournamentRecord:l,drawDefinition:u,matchUpsMap:v,event:f});if(x.error)return k({result:x,stack:m})}else return k({result:{error:ta},context:{loserDrawPosition:a,loserTargetLink:c},stack:m});if(S!=null&&S.seedAssignments&&S.structureId!==A){const L=S.seedAssignments.find(({participantId:B})=>B===E),x=L==null?void 0:L.participantId;L&&x&&xs(WO(yd({eventId:p==null?void 0:p.eventId,structureId:A},L),{tournamentRecord:l,drawDefinition:u,participantId:x}))}if(d&&i){const L=(e=d.sides)==null?void 0:e.find(x=>x.sideNumber===3-i);if(L!=null&&L.lineUp){const{roundNumber:x,eventId:B}=p,{roundPosition:z}=d,H=x===1?2-z%2:1,Y=(r=v==null?void 0:v.drawMatchUps)==null?void 0:r.find(({matchUpId:Q})=>Q===p.matchUpId),Z=[1,2].map(Q=>{var J;const te=((J=Y.sides)==null?void 0:J.find(ne=>ne.sideNumber===Q))||{};return WO(yd({},te),{sideNumber:Q})});Y.sides=Z;const K=Y.sides.find(Q=>Q.sideNumber===H);K&&(K.lineUp=am({lineUp:L.lineUp}),Ze({tournamentId:l==null?void 0:l.tournamentId,matchUp:Y,context:m,drawDefinition:u,eventId:B}))}}return yd({},V);function W(){const L="loserLinkFedFMLC";return k(T?{result:F(),stack:L}:{result:q(),stack:L})}function q(){const L=Yr({drawPosition:P,structureId:A,tournamentRecord:l,drawDefinition:u,event:f});return k({result:L,stack:"assignLoserPositionBye"})}function F(){const L=E?An({drawPosition:I,participantId:E,structureId:A,inContextDrawMatchUps:o,sourceMatchUpStatus:s,tournamentRecord:l,drawDefinition:u,matchUpsMap:v,event:f}):{error:Et};return k({result:L,stack:"assignLoserDrawPosition"})}}var rz=Object.defineProperty,HO=Object.getOwnPropertySymbols,nz=Object.prototype.hasOwnProperty,oz=Object.prototype.propertyIsEnumerable,qO=(t,e,r)=>e in t?rz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ga=(t,e)=>{for(var r in e||(e={}))nz.call(e,r)&&qO(t,r,e[r]);if(HO)for(var r of HO(e))oz.call(e,r)&&qO(t,r,e[r]);return t};function zO(t){const e=sm(t);if(e.error)return e;const r=rc({matchUpStatus:t.matchUpStatus}),{dualWinningSideChange:n,projectedWinningSide:o,inContextDrawMatchUps:i,tournamentRecord:s,drawDefinition:a,matchUpStatus:l,dualMatchUp:c,matchUpsMap:u,winningSide:p,targetData:d,matchUpId:v,structure:f,matchUp:m,event:h}=t,g="directParticipants",_=!!m.collectionId,I=Co({drawDefinition:a,structure:f});let P=m.drawPositions,y;if(_){const{matchUpTieId:S,matchUpsMap:O}=t,b=uo({matchUpId:S,tournamentRecord:s,drawDefinition:a,matchUpsMap:O,event:h});y=b&&{tieMatchUpResult:b};const w=i.find(({matchUpId:T})=>T===S);if(P=w==null?void 0:w.drawPositions,!n)return k({result:Ga(Ga({},V),y),stack:g})}if(I)return k({result:Ga(Ga({},V),y),stack:g});if(P){const S=o?o-1:p-1,O=1-S,b=P[S],w=P[O],{targetLinks:{loserTargetLink:T,winnerTargetLink:$,byeTargetLink:N},targetMatchUps:{winnerMatchUpDrawPositionIndex:E,loserMatchUpDrawPositionIndex:A,winnerMatchUp:U,loserMatchUp:C,byeMatchUp:M}}=d;if(U){const D=K5({sourceMatchUpStatus:r&&l||Mt,winnerMatchUpDrawPositionIndex:E,sourceMatchUpId:v,inContextDrawMatchUps:i,projectedWinningSide:o,winningDrawPosition:b,tournamentRecord:s,winnerTargetLink:$,drawDefinition:a,winnerMatchUp:U,dualMatchUp:c,matchUpsMap:u,event:h});if(D.error)return k({result:D,stack:g})}if(C){const D=tz({sourceMatchUpStatus:r&&l||Mt,loserMatchUpDrawPositionIndex:A,sourceMatchUpId:v,inContextDrawMatchUps:i,projectedWinningSide:o,loserDrawPosition:w,tournamentRecord:s,loserTargetLink:T,drawDefinition:a,loserMatchUp:C,winningSide:p,matchUpsMap:u,dualMatchUp:c,event:h});if(D.error)return k({result:D,stack:g})}if(M){const D=M.drawPositions||[],R=Math.min(...D.filter(Boolean)),j=N.target.structureId,G=Yr({drawPosition:R,structureId:j,tournamentRecord:s,drawDefinition:a,event:h});if(G.error)return k({result:G,stack:g})}}else return k({result:{error:Zp},stack:g});return k({result:Ga(Ga({},V),y),stack:g})}function qi(t){var e,r;const{inContextDrawMatchUps:n,targetData:o,drawDefinition:i,relevantLink:s}=t;if((s==null?void 0:s.linkCondition)===co&&((e=o==null?void 0:o.matchUp)==null?void 0:e.matchUpStatus)===nt)return!1;const{targetMatchUps:{loserMatchUp:l,winnerMatchUp:c},targetLinks:u}=o,p=[Xe,ot].includes(l==null?void 0:l.matchUpStatus),d=((r=c==null?void 0:c.drawPositions)==null?void 0:r.filter(Boolean).length)||0;if(l!=null&&l.winningSide&&!p||c!=null&&c.winningSide&&d===2&&(!c.feedRound||![ot,Xe].includes(c==null?void 0:c.matchUpStatus)))return!0;const v=l&&Ir({matchUpId:l.matchUpId,inContextDrawMatchUps:n,drawDefinition:i}),f=c&&Ir({matchUpId:c.matchUpId,inContextDrawMatchUps:n,drawDefinition:i}),m=v&&qi({relevantLink:u==null?void 0:u.loserTargetLink,targetData:v,inContextDrawMatchUps:n,drawDefinition:i});return!!(f&&qi({targetData:f,inContextDrawMatchUps:n,drawDefinition:i})||m)}var iz=Object.defineProperty,sz=Object.defineProperties,az=Object.getOwnPropertyDescriptors,YO=Object.getOwnPropertySymbols,lz=Object.prototype.hasOwnProperty,cz=Object.prototype.propertyIsEnumerable,KO=(t,e,r)=>e in t?iz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,uz=(t,e)=>{for(var r in e||(e={}))lz.call(e,r)&&KO(t,r,e[r]);if(YO)for(var r of YO(e))cz.call(e,r)&&KO(t,r,e[r]);return t},dz=(t,e)=>sz(t,az(e));function pz(t){var e,r,n;let o;const{inContextDrawMatchUps:i,inContextMatchUp:s,drawDefinition:a,winningSide:l}=t,c=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(c.target.feedProfile===Sn){const u=s.sides.find(({sideNumber:d})=>d!==l).participantId,p=i.find(d=>d.structureId===c.target.structureId&&d.roundNumber===c.target.roundNumber&&d.sides.some(({participantId:v})=>v===u));if((p==null?void 0:p.matchUpStatus)===Ft){const d=Ir({matchUpId:p.matchUpId,inContextDrawMatchUps:i,drawDefinition:a});if(!qi({inContextDrawMatchUps:i,drawDefinition:a,targetData:d})){const{structure:f}=Ne({structureId:p.structureId,drawDefinition:a}),m=st({structure:f}).positionAssignments;for(const h of m||[])if(h.participantId===u){const g=s.sides.find(({sideNumber:_})=>_===l).participantId;if(h.participantId=g,f!=null&&f.positionAssignments)f.positionAssignments=m;else if(f!=null&&f.structures){const _=Object.assign({},...(m||[]).map(I=>({[I.drawPosition]:I.participantId})));for(const I of f.structures)(r=I.positionAssignments)==null||r.forEach(P=>P.participantId=_[P.drawPosition])}oi({tournamentId:(n=t.tournamentRecord)==null?void 0:n.tournamentId,event:t.event,drawDefinition:a,structure:f}),o=!0}}}}return dz(uz({},V),{qualifierReplaced:o})}var fz=Object.defineProperty,vz=Object.defineProperties,mz=Object.getOwnPropertyDescriptors,QO=Object.getOwnPropertySymbols,hz=Object.prototype.hasOwnProperty,gz=Object.prototype.propertyIsEnumerable,JO=(t,e,r)=>e in t?fz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_z=(t,e)=>{for(var r in e||(e={}))hz.call(e,r)&&JO(t,r,e[r]);if(QO)for(var r of QO(e))gz.call(e,r)&&JO(t,r,e[r]);return t},Iz=(t,e)=>vz(t,mz(e));function Pz(t){var e,r,n,o,i;let s;const{inContextDrawMatchUps:a,inContextMatchUp:l,drawDefinition:c,winningSide:u}=t,p=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(p.target.feedProfile===Sn){const d=(r=l.sides.find(({sideNumber:m})=>m===u))==null?void 0:r.participantId,v=a.filter(m=>m.structureId===p.target.structureId&&m.roundNumber===p.target.roundNumber&&m.sides.some(({participantId:h,qualifier:g})=>g&&!h)),f=Ur(v);if((f==null?void 0:f.matchUpStatus)===Ft){const m=Ir({matchUpId:f.matchUpId,inContextDrawMatchUps:a,drawDefinition:c});if(!qi({inContextDrawMatchUps:a,drawDefinition:c,targetData:m})){const g=(n=f.sides.find(P=>P.qualifier&&!P.participantId))==null?void 0:n.drawPosition,{structure:_}=Ne({structureId:f.structureId,drawDefinition:c});if(!_)return{error:bt};const I=st({structure:_}).positionAssignments;for(const P of I||[])if(P.drawPosition===g&&!P.participantId){if(P.participantId=d,_.positionAssignments)_.positionAssignments=I;else if(_.structures){const y=Object.assign({},...(I||[]).map(S=>({[S.drawPosition]:S.participantId})));for(const S of _.structures)(o=S.positionAssignments)==null||o.forEach(O=>O.participantId=y[O.drawPosition])}oi({tournamentId:(i=t.tournamentRecord)==null?void 0:i.tournamentId,event:t.event,drawDefinition:c,structure:_}),s=!0}}}}return Iz(_z({},V),{qualifierPlaced:s})}var yz=Object.defineProperty,Sz=Object.defineProperties,Oz=Object.getOwnPropertyDescriptors,ZO=Object.getOwnPropertySymbols,bz=Object.prototype.hasOwnProperty,Tz=Object.prototype.propertyIsEnumerable,XO=(t,e,r)=>e in t?yz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eb=(t,e)=>{for(var r in e||(e={}))bz.call(e,r)&&XO(t,r,e[r]);if(ZO)for(var r of ZO(e))Tz.call(e,r)&&XO(t,r,e[r]);return t},wz=(t,e)=>Sz(t,Oz(e));function Ez(t){var e,r;const n="attemptToSetWinningSide";let o;const{appliedPolicies:i,disableAutoCalc:s,drawDefinition:a,dualMatchUp:l,winningSide:c,structure:u,matchUp:p}=t;if(l!=null&&l._disableAutoCalc&&s!==!1)return sm(t);if(p.winningSide&&p.winningSide!==c){const{connectedStructureIds:m}=bO({drawDefinition:a,structure:u,matchUp:p});m.length&&(console.log({connectedStructureIds:m}),o=!0);const h=xa(t);if(h.error)return h}const d=zO(t);if(d.error)return k({result:d,stack:n});let v,f;return t.qualifierChanging&&((e=i==null?void 0:i[pu])!=null&&e.autoReplaceQualifiers)&&(v=pz(t).qualifierReplaced),t.qualifierAdvancing&&((r=i==null?void 0:i[pu])!=null&&r.autoPlaceQualifiers)&&(f=Pz(t).qualifierPlaced),k({result:Oe(wz(eb(eb({},V),d),{connectedStructures:o,qualifierReplaced:v,qualifierPlaced:f})),stack:n})}var $z=Object.defineProperty,Nz=Object.defineProperties,Uz=Object.getOwnPropertyDescriptors,tb=Object.getOwnPropertySymbols,Az=Object.prototype.hasOwnProperty,Cz=Object.prototype.propertyIsEnumerable,rb=(t,e,r)=>e in t?$z(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hc=(t,e)=>{for(var r in e||(e={}))Az.call(e,r)&&rb(t,r,e[r]);if(tb)for(var r of tb(e))Cz.call(e,r)&&rb(t,r,e[r]);return t},pm=(t,e)=>Nz(t,Uz(e));function nb(t){var e;const{inContextDrawMatchUps:r,appliedPolicies:n,drawDefinition:o,matchUpsMap:i,targetData:s,matchUp:a}=t;let{iteration:l=0}=t;l+=1;const c="removeDoubleExit";Jn();const{targetLinks:{loserTargetLink:u},targetMatchUps:{loserMatchUp:p,winnerMatchUp:d,loserTargetDrawPosition:v}}=s;if(d&&d.matchUpStatus!==nt&&(Jn(),ob(pm(hc({},t),{targetMatchUp:d,sourceMatchUp:a,iteration:l}))),p&&p.matchUpStatus!==nt){const f=r.find(({matchUpId:h})=>h===p.matchUpId),{structure:m}=Ne({drawDefinition:o,structureId:f.structureId});if(Jn(),(e=n==null?void 0:n.progression)!=null&&e.doubleExitPropagateBye)rm({drawPosition:v,targetLink:u,inContextDrawMatchUps:r,drawDefinition:o,matchUpsMap:i});else{const h=ob(pm(hc({},t),{structure:m,targetMatchUp:p,iteration:l}));if(h.error)return k({result:h,stack:c})}}return k({result:hc({},V),stack:c})}function ob(t){var e,r,n,o,i;const{inContextDrawMatchUps:s,appliedPolicies:a,drawDefinition:l,sourceMatchUp:c,targetMatchUp:u,matchUpsMap:p,structure:d,iteration:v}=t,f="conditionallyRemoveDrawPosition";Jn();const m=Ir({matchUpId:u.matchUpId,inContextDrawMatchUps:s,drawDefinition:l}),{targetMatchUps:{winnerMatchUp:h}}=m,g=p==null?void 0:p.drawMatchUps.find(w=>w.matchUpId===u.matchUpId);let _=[],I,P,y;if(u.feedRound){const w=(e=h==null?void 0:h.drawPositions)==null?void 0:e.filter(Boolean);y=w==null?void 0:w.find(T=>u.drawPositions.includes(T))}else if(!c)y=(r=Ht((u==null?void 0:u.drawPositions)||[],(h==null?void 0:h.drawPositions)||[]))==null?void 0:r[0];else if(P=(n=kS({structureId:d.structureId,matchUp:c,matchUpsMap:p}))==null?void 0:n.pairedPreviousMatchUp,I=[Rt,tr].includes(P==null?void 0:P.matchUpStatus),_=((o=P==null?void 0:P.drawPositions)==null?void 0:o.filter(Boolean))||[],[...Yt,nt].includes(P==null?void 0:P.matchUpStatus)||(P==null?void 0:P.winningSide)){const T=c.drawPositions||[];let $=(i=u.drawPositions)==null?void 0:i.filter(Boolean);Xt(T,$)&&($=$==null?void 0:$.filter(E=>!T.includes(E))),y=T.concat(_).find(E=>$==null?void 0:$.includes(E))}h&&y&&(Jn(),eO({winningDrawPosition:y,winnerMatchUp:h,inContextDrawMatchUps:s,drawDefinition:l,matchUpsMap:p}));let S=nb({targetData:m,matchUp:u,inContextDrawMatchUps:s,appliedPolicies:a,drawDefinition:l,matchUpsMap:p,structure:d,iteration:v});if(S.error)return k({result:S,stack:f});const O=Mz({pairedPreviousDoubleExit:I,noContextTargetMatchUp:g}),b=!I;return S=Kn(pm(hc({},t),{matchUpStatus:O,removeScore:b,score:{scoreStringSide1:"",scoreStringSide2:"",sets:void 0},removeWinningSide:!0,matchUp:g,matchUpId:u.matchUpId,matchUpStatusCodes:[]})),S.error?k({result:S,stack:f}):hc({},V)}function Mz({pairedPreviousDoubleExit:t,noContextTargetMatchUp:e}){return e.matchUpStatus===nt?nt:t?[tr,Xe].includes(e==null?void 0:e.matchUpStatus)?Xe:ot:Ft}function Dz(t){var e,r,n,o,i;let s;const{inContextDrawMatchUps:a,inContextMatchUp:l,drawDefinition:c}=t,u=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(u.target.feedProfile===Sn){const p=(n=(r=l.sides)==null?void 0:r.find(({sideNumber:v})=>v===l.winningSide))==null?void 0:n.participantId,d=a.find(v=>{var f;return v.structureId===u.target.structureId&&v.roundNumber===u.target.roundNumber&&((f=v.sides)==null?void 0:f.some(({participantId:m})=>m===p))});if((d==null?void 0:d.matchUpStatus)===Ft){const v=Ir({matchUpId:d.matchUpId,inContextDrawMatchUps:a,drawDefinition:c});if(!qi({inContextDrawMatchUps:a,drawDefinition:c,targetData:v})){const{structure:m}=Ne({structureId:d.structureId,drawDefinition:c}),h=st({structure:m}).positionAssignments;for(const g of h||[])if(g.participantId===p){if(g.participantId=void 0,m!=null&&m.positionAssignments)m.positionAssignments=h;else if(m!=null&&m.structures){const _=Object.assign({},...(h||[]).map(I=>({[I.drawPosition]:I.participantId})));for(const I of(m==null?void 0:m.structures)||[])(o=I.positionAssignments)==null||o.forEach(P=>P.participantId=_[P.drawPosition])}oi({tournamentId:(i=t.tournamentRecord)==null?void 0:i.tournamentId,event:t.event,drawDefinition:c,structure:m}),s=!0}}}}return{qualifierRemoved:s}}var jz=Object.defineProperty,Rz=Object.defineProperties,Fz=Object.getOwnPropertyDescriptors,ib=Object.getOwnPropertySymbols,xz=Object.prototype.hasOwnProperty,Lz=Object.prototype.propertyIsEnumerable,sb=(t,e,r)=>e in t?jz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Wa=(t,e)=>{for(var r in e||(e={}))xz.call(e,r)&&sb(t,r,e[r]);if(ib)for(var r of ib(e))Lz.call(e,r)&&sb(t,r,e[r]);return t},fm=(t,e)=>Rz(t,Fz(e));function Vz(t){var e;const{matchUp:r,matchUpStatus:n,score:o,winningSide:i}=t,s="noDownStreamDependencies";if([Rt,tr].includes(r==null?void 0:r.matchUpStatus)&&![Rt,tr].includes(n)){const g=nb(t);if(g.error)return k({result:g,stack:s})}const l=n===Rt,c=Gt({score:o})&&!l&&(t.isCollectionMatchUp&&!t.projectedWinningSide||!i),u=((e=t==null?void 0:t.inContextMatchUp)==null?void 0:e.collectionId)&&e6(t.inContextMatchUp),p=t.removeScore||!u&&![so,Wr].includes(n||so),d=t.isCollectionMatchUp&&t.dualMatchUp.winningSide&&!t.projectedWinningSide||r.winningSide&&!i&&!Gt({score:o}),v=n&&n!==Ft,f=g=>{var _,I;let P;const{structure:y,drawDefinition:S,dualMatchUp:O,disableAutoCalc:b}=t;if(O!=null&&O._disableAutoCalc&&b!==!1)return sm(t);const{connectedStructureIds:w}=bO({drawDefinition:S,structure:y,matchUp:r});w.length&&(console.log({connectedStructureIds:w}),P=!0),Object.assign(t,{removeScore:g});const T=xa(t);if(T.error)return T;if(t.removingQualifier&&((I=(_=t.appliedPolicies)==null?void 0:_[pu])!=null&&I.autoRemoveQualifiers)){const $=Dz(t);return Wa(fm(Wa({},V),{connectedStructures:P}),$)}return fm(Wa({},V),{connectedStructures:P})};if(d&&i&&t.isCollectionMatchUp)return ab(t);const m=[Ho,Wr].includes(n)&&t.dualWinningSideChange,h=(i||m)&&Ez(t)||c&&f(p)||v&&l5(t)||d&&f(p)||r&&ab(fm(Wa({},t),{removeScore:!0}))||Wa({},V);return k({result:h,stack:s})}function ab(t){var e;const r="scoreModification";if(t.isCollectionMatchUp&&((e=t.dualMatchUp)==null?void 0:e.winningSide)&&!t.projectedWinningSide){const i=xa(t);if(i.error)return i}const o=Kn(Wa({},t));if(t.isCollectionMatchUp){const{matchUpTieId:i,drawDefinition:s,event:a,matchUpsMap:l}=t,{removeWinningSide:c}=uo({tournamentRecord:t.tournamentRecord,matchUpId:i,drawDefinition:s,matchUpsMap:l,event:a});c&&console.log("REMOVE WINNING SIDE")}return k({result:o,stack:r})}function Bz(t){var e;const{tournamentRecord:r,inContextMatchUp:n,structure:o,drawDefinition:i}=t,s=n.roundNumber,a=n.sides.find(O=>O.sideNumber===n.winningSide),l=n.sides.find(O=>O.sideNumber!==n.winningSide),{drawPosition:c,participantId:u}=a,{drawPosition:p,participantId:d}=l,v="swapWinnerLoser",{matchUps:f}=Je(t),m=f.filter(({drawPositions:O,roundNumber:b})=>(O==null?void 0:O.includes(c))&&b>s);zt({changeWinner:!0})&&console.log({existingWinnerSubsequentMatchUps:m}),m.forEach(O=>{var b,w;O.drawPositions=((b=O.drawPositions)==null?void 0:b.map(T=>T===c?p:T))||[],Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:(w=t.event)==null?void 0:w.eventId,context:v,drawDefinition:i,matchUp:O})});const{stage:h,stageSequence:g}=o,_=i.structures.filter(({stage:O,stageSequence:b})=>O===h&&b>g).map(({structureId:O})=>O),{targetLinks:{loserTargetLink:I,winnerTargetLink:P}}=t.targetData,y=[I==null?void 0:I.target.structureId,(e=P==null?void 0:P.target)==null?void 0:e.structureId].filter(Boolean);return i.structures.filter(({stage:O,structureId:b})=>O!==h&&y.includes(b)).forEach(({stage:O,stageSequence:b,structureId:w})=>{_.includes(w)||_.push(w),i.structures.filter(({stage:T,stageSequence:$})=>T===O&&$>b).forEach(({structureId:T})=>{_.includes(T)||_.push(T)})}),i.structures.filter(({structureId:O})=>_.includes(O)).forEach(O=>{const{positionAssignments:b}=st({structure:O}),w=b==null?void 0:b.find(({participantId:$})=>$===u),T=b==null?void 0:b.find(({participantId:$})=>$===d);w&&(w.participantId=d),T&&(T.participantId=u)}),Kn(t)}var kz=Object.defineProperty,Gz=Object.defineProperties,Wz=Object.getOwnPropertyDescriptors,lb=Object.getOwnPropertySymbols,Hz=Object.prototype.hasOwnProperty,qz=Object.prototype.propertyIsEnumerable,cb=(t,e,r)=>e in t?kz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zz=(t,e)=>{for(var r in e||(e={}))Hz.call(e,r)&&cb(t,r,e[r]);if(lb)for(var r of lb(e))qz.call(e,r)&&cb(t,r,e[r]);return t},Yz=(t,e)=>Gz(t,Wz(e));function gc(t){var e,r,n,o,i;const s="setMatchUpStatus";t.matchUpStatus&&[ot,Rt].includes(t.matchUpStatus)&&(t.score=void 0);const{allowChangePropagation:a,disableScoreValidation:l,tournamentRecords:c,tournamentRecord:u,disableAutoCalc:p,enableAutoCalc:d,drawDefinition:v,matchUpStatus:f,winningSide:m,matchUpId:h,event:g,score:_}=t;if(!v)return{error:ue};if(f&&[Ho,so,Wr,Ft].includes(f)&&m)return{error:X,winningSide:m,matchUpStatus:f};if(![void 0,...lV].includes(f))return k({result:{error:fl},info:"matchUpStatus does not exist",stack:"setMatchUpStatus"});const I=lr({drawDefinition:v}),{matchUps:P}=Lt({nextMatchUps:!0,inContext:!0,drawDefinition:v,matchUpsMap:I,event:g}),y=I.drawMatchUps.find(x=>x.matchUpId===h),S=P==null?void 0:P.find(x=>x.matchUpId===h);if(!y||!P)return{error:ir};if((y.winningSide||m)&&f===nt)return{context:"Cannot have Bye with winningSide",error:tf,matchUpStatus:f};const O=S==null?void 0:S.structureId,{structure:b}=Ne({drawDefinition:v,structureId:O}),w=(e=S==null?void 0:S.drawPositions)==null?void 0:e.filter(Boolean);let T;if(y.matchUpType===Qe){if(p)it({extension:{name:fa,value:!0},element:y});else if(d){const x=y.winningSide;yn({name:fa,element:y});const{winningSide:B,scoreStringSide1:z,scoreStringSide2:H,set:Y}=tc({drawDefinition:v,matchUpsMap:I,structure:b,matchUp:y,event:g}),Z={scoreStringSide1:z,scoreStringSide2:H,sets:Y?[Y]:[]};T=B!==x,Object.assign(t,{winningSide:B,dualWinningSideChange:T,projectedWinningSide:B,score:Z})}}if(y.matchUpType===Qe&&f&&[la].includes(f))return{error:X,info:"Not supported for matchUpType: TEAM"};const $=S==null?void 0:S.matchUpTieId,N=Ir({matchUpId:$||h,inContextDrawMatchUps:P,drawDefinition:v});if(_&&y.matchUpType!==Qe&&!l){const x=y.matchUpFormat||(b==null?void 0:b.matchUpFormat)||(v==null?void 0:v.matchUpFormat)||(g==null?void 0:g.matchUpFormat),B=Ov({existingMatchUpStatus:y.matchUpStatus,matchUpFormat:x,matchUpStatus:f,winningSide:m,score:_});if(B.error)return B}const E=y!=null&&y.sides?[]:st({drawDefinition:v,structureId:O}).positionAssignments,A=((r=y.sides)==null?void 0:r.map(x=>x.participantId).filter(Boolean).length)===2||(w==null?void 0:w.length)===2&&(E==null?void 0:E.filter(x=>w.includes(x.drawPosition)).every(x=>x.participantId));if(f&&aV.includes(f)&&!A)return k({result:{error:fl},info:"present in participantRequiredMatchUpStatuses",context:{matchUpStatus:f,bothSideParticipants:A}});const U=(o=(n=pt({policyTypes:[pu],tournamentRecord:u,drawDefinition:v,event:g}))==null?void 0:n.appliedPolicies)!=null?o:{};typeof t.policyDefinitions=="object"&&Object.assign(U,t.policyDefinitions);const C=(S==null?void 0:S.stage)===we&&S.finishingRound===1,M=C&&m,D=C&&y.winningSide&&!m&&(!t.matchUpStatus||t.matchUpStatus&&pv({matchUpStatus:t.matchUpStatus}))&&(!t.outcome||!Gt({outcome:t.outcome})),R=M&&m!==y.winningSide&&y.winningSide;if(Object.assign(t,{inContextDrawMatchUps:P,qualifierAdvancing:M,qualifierChanging:R,removingQualifier:D,inContextMatchUp:S,appliedPolicies:U,matchUpTieId:$,matchUpsMap:I,targetData:N,structure:b,matchUp:y}),$){const{matchUp:x}=lt({matchUpId:$,inContext:!0,drawDefinition:v,matchUpsMap:I,event:g});if(x){const B=(i=vr({matchUp:x,drawDefinition:v,structure:b,event:g}))==null?void 0:i.tieFormat,{projectedWinningSide:z}=Xq({drawDefinition:v,matchUpStatus:f,dualMatchUp:x,matchUpsMap:I,winningSide:m,tieFormat:B,structure:b,matchUp:y,event:g,score:_}),H=x.winningSide;T=z!==H,Object.assign(t,{isCollectionMatchUp:!0,dualWinningSideChange:T,projectedWinningSide:z,matchUpTieId:$,dualMatchUp:x,tieFormat:B})}}const j=qi(t),G=rc({matchUpStatus:f});if(!$){if(j&&!m&&(f&&pv({matchUpStatus:f})||f&&[Rt,tr].includes(f)))return{error:tf,activeDownstream:j,winningSide:m};if(m&&m===y.winningSide&&f&&!G)return{context:"winningSide must include directing matchUpStatus",error:tf,directingMatchUpStatus:G,matchUpStatus:f}}const{schedule:W}=t;if(W){const x=dd({disableNotice:!0,tournamentRecords:c,tournamentRecord:u,drawDefinition:v,matchUpId:h,schedule:W});if(x.error)return x}const q=y.matchUpType!==Qe&&!T&&m&&y.winningSide&&y.winningSide!==m;if(a&&q&&y.roundPosition)return Bz(t);const F=m&&!$||t.projectedWinningSide;Jn();const L=!j&&Vz(t)||F&&Kz(t)||G&&ub(t)||{error:Jx};return k({result:L,stack:s})}function Kz(t){const{matchUp:e,winningSide:r,matchUpTieId:n,dualWinningSideChange:o}=t;return r===e.winningSide||n&&!o?ub(t):k({result:{error:a_},stack:"winningSideWithDownstreamDependencies",context:{winningSide:r,matchUp:e}})}function ub(t){const{tournamentRecord:e,matchUp:r,event:n}=t,o=t.isCollectionMatchUp&&r.winningSide&&!t.winningSide&&!Gt({score:t.score}),i=t.isCollectionMatchUp?t.matchUpStatus||o&&Ft||Mt:t.matchUpStatus||Mt,s=t.removeScore||[Ho,ot].includes(i)&&![so,Wr].includes(i),a=Kn(Yz(zz({},t),{matchUpStatus:i,removeWinningSide:o,removeScore:s}));if(a.error)return a;if(t.isCollectionMatchUp){const{matchUpTieId:l,drawDefinition:c,matchUpsMap:u}=t,p=uo({matchUpId:l,tournamentRecord:e,drawDefinition:c,matchUpsMap:u,event:n});if(p.error)return p;Object.assign(a,{tieMatchUpResult:p})}return a}var Qz=Object.defineProperty,db=Object.getOwnPropertySymbols,Jz=Object.prototype.hasOwnProperty,Zz=Object.prototype.propertyIsEnumerable,pb=(t,e,r)=>e in t?Qz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xz=(t,e)=>{for(var r in e||(e={}))Jz.call(e,r)&&pb(t,r,e[r]);if(db)for(var r of db(e))Zz.call(e,r)&&pb(t,r,e[r]);return t};function Sd(t){let e=t.structureIds;const{tournamentRecord:r,drawDefinition:n,matchUpFormat:o,structureId:i,matchUpId:s,event:a}=t;if(!n)return{error:ue};if(!o)return{error:rf};if(!Xr(o))return{error:Jc};const l="setMatchUpFormat";if(s){const c=lt({drawDefinition:n,matchUpId:s,event:a});if(c.error)return c;if(!c.matchUp)return{error:ir};const u=c.matchUp;if((u==null?void 0:u.matchUpType)===Bt)return{error:tn,info:"Cannot set matchUpFormat when { matchUpType: TEAM }"};u.matchUpFormat=o,Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:a==null?void 0:a.eventId,context:l,drawDefinition:n,matchUp:u})}else if(Array.isArray(e)){if((a==null?void 0:a.eventType)===Bt)return{error:gi};for(const c of e){const u=Ne({drawDefinition:n,structureId:c});if(u.error)return u;if(u.structure)u.structure.matchUpFormat=o;else return{error:bt}}}else if(i){if((a==null?void 0:a.eventType)===Bt)return{error:gi};const c=Ne({drawDefinition:n,structureId:i});if(c.error)return c;if(c.structure)c.structure.matchUpFormat=o;else return{error:bt}}else n&&(n.matchUpFormat=o);return e=e||(i?[i]:void 0),et({drawDefinition:n,structureIds:e}),Xz({},V)}function fb(t){const{matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}=t;if(!o)return{sets:[]};const i=o.sets||[];let s=po({winnerFirst:!1,matchUpFormat:e,matchUpStatus:r,sets:i}),a=po({winnerFirst:!1,reversed:!0,matchUpFormat:e,matchUpStatus:r,sets:i});const l=po({matchUpFormat:e,matchUpStatus:r,winningSide:n,sets:i}),c=s===l?a:s;return n&&(s=n===1?l:c,a=n===2?l:c),{score:{sets:i,scoreStringSide1:s,scoreStringSide2:a}}}var eY=Object.defineProperty,vb=Object.getOwnPropertySymbols,tY=Object.prototype.hasOwnProperty,rY=Object.prototype.propertyIsEnumerable,mb=(t,e,r)=>e in t?eY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,nY=(t,e)=>{for(var r in e||(e={}))tY.call(e,r)&&mb(t,r,e[r]);if(vb)for(var r of vb(e))rY.call(e,r)&&mb(t,r,e[r]);return t};function _c(t){var e;const{tournamentRecords:r,policyDefinitions:n,tournamentRecord:o,disableAutoCalc:i,enableAutoCalc:s,drawDefinition:a,matchUpFormat:l,matchUpId:c,schedule:u,event:p,notes:d}=t;if(!a)return{error:kr};if(!c)return{error:Vt};const{policy:v}=cs({policyType:da,tournamentRecord:o,event:p}),f=t.allowChangePropagation!==void 0&&t.allowChangePropagation||(v==null?void 0:v.allowChangePropagation)!==void 0&&v.allowChangePropagation||void 0,{outcome:m}=t;if(l){const h=Sd({tournamentRecord:o,drawDefinition:a,matchUpFormat:l,matchUpId:c,event:p});if(h.error)return h}if((e=m==null?void 0:m.score)!=null&&e.sets&&!m.score.scoreStringSide1){const{score:h}=fb(m);m.score=h,m.score.sets=m.score.sets.filter(g=>g.side1Score||g.side2Score||g.side1TiebreakScore||g.side2TiebreakScore)}return gc({matchUpStatusCodes:m==null?void 0:m.matchUpStatusCodes,matchUpStatus:m==null?void 0:m.matchUpStatus,winningSide:m==null?void 0:m.winningSide,allowChangePropagation:f,score:m==null?void 0:m.score,tournamentRecords:r,policyDefinitions:n,tournamentRecord:o,disableAutoCalc:i,enableAutoCalc:s,drawDefinition:a,matchUpFormat:l,matchUpId:c,schedule:u,event:p,notes:d})}function hb(t){var e;if(!t.tournamentRecord)return{error:re};const{tournamentRecords:r,tournamentRecord:n,outcomes:o,policyDefinitions:i}=t,s={};o.forEach(a=>{const{eventId:l}=a;s[l]||(s[l]=[]),s[l].push(a)});for(const a of Object.keys(s)){const{event:l}=Qt({tournamentRecord:n,eventId:a});for(const c of s[a]){const{drawId:u}=c,p=(e=l==null?void 0:l.drawDefinitions)==null?void 0:e.find(d=>d.drawId===u);if(p&&u){const{matchUpFormat:d,matchUpId:v}=c,f=_c({schedule:c==null?void 0:c.schedule,tournamentRecords:r,policyDefinitions:i,tournamentRecord:n,drawDefinition:p,matchUpFormat:d,matchUpId:v,outcome:c,drawId:u,event:l});if(f.error)return f}}}return nY({},V)}var oY=Object.defineProperty,iY=Object.defineProperties,sY=Object.getOwnPropertyDescriptors,gb=Object.getOwnPropertySymbols,aY=Object.prototype.hasOwnProperty,lY=Object.prototype.propertyIsEnumerable,_b=(t,e,r)=>e in t?oY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ib=(t,e)=>{for(var r in e||(e={}))aY.call(e,r)&&_b(t,r,e[r]);if(gb)for(var r of gb(e))lY.call(e,r)&&_b(t,r,e[r]);return t},cY=(t,e)=>iY(t,sY(e));function uY(t){const e=t.tournamentRecords,r=t.tournamentId||Xv(t);if(typeof r!="string")return{error:yo};const n=e[r];if(!n)return{error:re};const{drawDefinition:o,event:i}=Qt({eventId:t.eventId,drawId:t.drawId,tournamentRecord:n});return _c(cY(Ib({tournamentRecord:n},t),{drawDefinition:o,event:i}))}function dY(t){const{tournamentRecords:e,outcomes:r}=t;if(!Array.isArray(r))return{error:_e,info:or("outcomes")};const n=r.reduce((o,i)=>o.includes(i.tournamentId)?o:o.concat(i.tournamentId),[]);for(const o of n){const i=e[o];if(!i)return{error:re};const s=r.filter(a=>a.tournamentId===o);if(s.length){const a=hb({tournamentRecord:i,outcomes:s});if(a.error)return a}}return Ib({},V)}function Pb({courtPrefix:t="C|",minRowsCount:e,courtsData:r}){if(!Array.isArray(r))return{error:X};const n=r==null?void 0:r.reduce((s,a)=>{const l=a.matchUps||[],c=Math.max(0,...l.map(u=>u.schedule.courtOrder||0));return c>s?c:s},1),o=e?Math.max(e,n):n,i=ce(0,o).map(s=>({matchUps:ce(0,r.length).map(a=>{const l=r[a],{courtId:c,venueId:u}=l;return{schedule:{courtOrder:s+1,venueId:u,courtId:c}}})}));return r.forEach((s,a)=>{var l;for(const c of s.matchUps){const u=(l=c.schedule)==null?void 0:l.courtOrder;u&&(i[u-1].matchUps[a]=c)}}),{courtPrefix:t,rows:i.map((s,a)=>Object.assign({rowId:`rowId-${a+1}`},...s.matchUps.map((l,c)=>({[`${t}${c}`]:l}))))}}var pY=Object.defineProperty,fY=Object.defineProperties,vY=Object.getOwnPropertyDescriptors,yb=Object.getOwnPropertySymbols,mY=Object.prototype.hasOwnProperty,hY=Object.prototype.propertyIsEnumerable,Sb=(t,e,r)=>e in t?pY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vm=(t,e)=>{for(var r in e||(e={}))mY.call(e,r)&&Sb(t,r,e[r]);if(yb)for(var r of yb(e))hY.call(e,r)&&Sb(t,r,e[r]);return t},mm=(t,e)=>fY(t,vY(e));function Ic(t){var e,r,n,o,i,s,a,l,c,u,p,d;const{flight:v,suppressNotifications:f,modifyEventEntries:m,existingDrawCount:h,allowReplacement:g,checkEntryStatus:_,tournamentRecord:I,drawDefinition:P,event:y}=t;if(!P)return{error:kr};if(!y)return{error:Ge};y.drawDefinitions||(y.drawDefinitions=[]);const{drawId:S,drawName:O,entries:b}=P,{entries:w}=y;let T=0;if(h!==void 0&&h!==y.drawDefinitions.length)return{error:X,info:"drawDefintions count mismatch"};const{flightProfile:$}=Nt({event:y}),N=v&&((e=$==null?void 0:$.flights)==null?void 0:e.find(x=>x.flightNumber===v.flightNumber)),E=(o=(n=(r=$==null?void 0:$.links)==null?void 0:r.find(x=>{var B;return((B=x==null?void 0:x.target)==null?void 0:B.drawId)===S}))==null?void 0:n.source)==null?void 0:o.drawId;if(E&&!y.drawDefinitions.find(x=>x.drawId===E))return k({result:{error:ue},info:{sourceDrawId:E}});if(N&&N.drawId!==P.drawId)return k({result:{error:Xi},info:{relevantFlight:N}});const C=b==null?void 0:b.every(({participantId:x,entryStatus:B})=>{const z=N==null?void 0:N.drawEntries.find(H=>H.participantId===x);return!B||(z==null?void 0:z.entryStatus)===B}),M=!_||w&&(b==null?void 0:b.every(({participantId:x,entryStatus:B,entryStage:z})=>{const H=w.find(Y=>Y.participantId===x&&(!Y.entryStage||Y.entryStage===z));return(H==null?void 0:H.entryStatus)===B}));if(N&&!C)return k({result:{error:Xi,context:{drawEntriesPresentInFlight:C,matchingEventEntries:M,relevantFlight:N},info:"Draw entries are not present in flight or do not match entryStatuses"}});if(m&&(b==null||b.filter(Boolean).forEach(x=>{if(x!=null&&x.entryStatus&&Fi.includes(x==null?void 0:x.entryStatus)){const B=w==null?void 0:w.filter(Boolean).find(z=>z.participantId===x.participantId);B&&x.entryStatus&&(B==null?void 0:B.entryStatus)!==x.entryStatus&&(B.entryStatus=x.entryStatus,T+=1)}})),w&&!M)return k({result:{error:Xi,context:{matchingEventEntries:M,eventEntries:w},info:"Draw entries do not match event entryStatuses"}});const D=((s=(i=$==null?void 0:$.flights)==null?void 0:i.map(({flightNumber:x})=>!isNaN(x)&&Te(x)))==null?void 0:s.filter(Boolean))||[],R=((a=y.drawDefinitions.map(({drawOrder:x})=>x&&Te(x)))==null?void 0:a.filter(Boolean))||[];let j=Math.max(0,...R,...D)+1;const G=(l=$==null?void 0:$.flights)==null?void 0:l.find(x=>x.drawId===S);let W;if(G){G.drawName=P.drawName,W={name:_n,value:mm(vm({},$),{flights:$.flights})};const x=G.flightNumber;x&&!R.includes(x)?j=x:G.flightNumber=j}else{const x=($==null?void 0:$.flights)||[];x.push({manuallyAdded:!0,flightNumber:j,drawEntries:b,drawName:O,drawId:S}),W={name:_n,value:mm(vm({},$||{}),{flights:x})}}ao({event:y,extension:W}),Object.assign(P,{drawOrder:j});const q=y.drawDefinitions.find(x=>x.drawId===S),F=I==null?void 0:I.tournamentId,L=y.eventId;if(q){if(!g)return{error:ZF};const x=(c=zr({drawDefinition:q}))==null?void 0:c.matchUps,B=(u=x==null?void 0:x.map(Jt))!=null?u:[],z=(p=zr({drawDefinition:P}))==null?void 0:p.matchUps;if(!f){B!=null&&B.length&&Vi({matchUpIds:B,action:"modifyDrawDefinition",tournamentId:F,eventId:L}),z!=null&&z.length&&Li({matchUps:z,tournamentId:F,eventId:L}),y.drawDefinitions=y.drawDefinitions.map(Y=>Y.drawId===S?P:Y);const H=(d=P.structures)==null?void 0:d.map(({structureId:Y})=>Y);et({drawDefinition:P,tournamentId:F,structureIds:H,eventId:L})}}else if(y.drawDefinitions.push(P),!f){const{matchUps:x}=zr({drawDefinition:P,event:y});x&&Li({tournamentId:I==null?void 0:I.tournamentId,matchUps:x}),nc({drawDefinition:P,tournamentId:F,eventId:L})}return mm(vm({},V),{modifiedEventEntryStatusCount:T})}function gY({tournamentRecords:t,existingDrawCount:e,allowReplacement:r,drawDefinition:n,tournamentId:o,eventId:i,flight:s}){if(!i)return{error:Ge};if(o=o??Xv({tournamentRecords:t,eventId:i}),!o)return{error:yo};const a=t[o];if(!a)return{error:re};const l=Qt({tournamentRecord:a,eventId:i});return l.event?l.error?l:Ic({event:l.event,existingDrawCount:e,allowReplacement:r,drawDefinition:n,flight:s}):{error:Ar}}var _Y=Object.defineProperty,IY=Object.defineProperties,PY=Object.getOwnPropertyDescriptors,Ob=Object.getOwnPropertySymbols,yY=Object.prototype.hasOwnProperty,SY=Object.prototype.propertyIsEnumerable,bb=(t,e,r)=>e in t?_Y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Od=(t,e)=>{for(var r in e||(e={}))yY.call(e,r)&&bb(t,r,e[r]);if(Ob)for(var r of Ob(e))SY.call(e,r)&&bb(t,r,e[r]);return t},OY=(t,e)=>IY(t,PY(e));function Zn({allowDuplicateParticipantIdPairs:t,returnParticipant:e,tournamentRecord:r,disableNotice:n,pairOverride:o,participant:i}){var s,a,l;const c="addParticipant";if(!r)return{error:re};if(!i)return k({result:{error:oa},stack:c});i.participantId||(i.participantId=Ye()),r.participants||(r.participants=[]);const{participantId:u,individualParticipantIds:p}=i;if(r.participants.reduce((_,I)=>I.participantId===u||_,!1))return{error:Ex};const{participantType:v,participantRole:f}=i;if(!v||!Object.keys(Vl).includes(v))return{error:jn,participantType:v};if(!f)return{error:wx};const m=r.participants||[],h=m.filter(_=>_.participantType===Fe).map(_=>_.participantId);if(v!==Fe&&i.person)return{error:X,person:i.person};if(p&&!Array.isArray(p))return{error:X,individualParticipantIds:p};if(v===Ce){if(i.person)return{error:X,person:i.person};if(i.individualParticipantIds){if(i.individualParticipantIds.length!==2&&!o)return k({result:{error:pn,info:"PAIR must be 2 individualParticipantIds"},stack:c});{const P=m.filter(S=>S.participantType===Fe).map(S=>S.participantId);if(!Array.isArray(i.individualParticipantIds))return k({result:{error:pn},stack:c});if(!i.individualParticipantIds.reduce((S,O)=>P.includes(O)&&S,!0))return k({result:{error:pn},stack:c})}}else return k({result:{error:Oo},stack:c});const _=m.filter(P=>P.participantType===Ce).map(P=>({individualParticipantIds:P.individualParticipantIds,participant:P})),I=i.participantType===Ce&&_.find(P=>Ht(P.individualParticipantIds,i.individualParticipantIds).length===2);if(I&&!t)return OY(Od({},V),{existingParticipant:!0,participant:e&&de(I.participant)});if(!i.participantName){const P=m.filter(S=>{var O;return(O=i.individualParticipantIds)==null?void 0:O.includes(S.participantId)});let y=P.map(S=>{var O;return(O=S.person)==null?void 0:O.standardFamilyName}).filter(Boolean).join("/");P.length===1&&(y+="/Unknown"),i.participantName=y}}else if(v===Fe){if(!((s=i.person)!=null&&s.standardFamilyName)||!((a=i.person)!=null&&a.standardGivenName))return{error:Ax};if(!i.participantName){const _=`${i.person.standardFamilyName.toUpperCase()}, ${i.person.standardGivenName}`;i.participantName=_}}else if(v&&[tt,Mr].includes(v)){if(p||(i.individualParticipantIds=[]),(l=i.individualParticipantIds)!=null&&l.length)for(const _ of i.individualParticipantIds){if(typeof _!="string")return k({result:{participantId:_,error:X},stack:c});if(!h.includes(_))return k({result:{participantId:_,error:jt},stack:c})}}else return{error:jn};r.participants.push(i),n||He({payload:{tournamentId:r.tournamentId,participants:[i]},topic:$i});const g=Od({participant:e&&de(i)},V);return Oe(g)}function ho({allowDuplicateParticipantIdPairs:t,returnParticipants:e,participants:r,tournamentRecord:n}){if(!n)return{error:re};n.participants||(n.participants=[]);const i=n.participants.map(d=>d.participantId)||[];r.forEach(d=>{d.participantId||(d.participantId=Ye())});const s=r.filter(d=>!i.includes(d.participantId)),a=r.filter(d=>i.includes(d.participantId)),l=s.filter(d=>d.participantType===Fe),c=s.filter(d=>d.participantType!==Fe),u=l.concat(...c),p=[];if(u.length){for(const v of u){const f=Zn({allowDuplicateParticipantIdPairs:t,returnParticipant:!0,disableNotice:!0,tournamentRecord:n,participant:v});if(f.error)return f;f.success&&!f.existingParticipant&&p.push(f.participant)}p.length&&He({topic:$i,payload:{tournamentId:n.tournamentId,participants:p}});const d=Od({participants:e&&de(p),addedCount:p.length},V);return a.length&&Object.assign(d,{notAdded:a,info:cf}),Oe(d)}else return Od({info:"No new participants to add",addedCount:0},V)}function bY({tournamentRecords:t,returnParticipant:e,pairOverride:r,tournamentId:n,participant:o}){if(typeof n!="string")return{error:yo};const i=t[n];return i?Zn({returnParticipant:e,tournamentRecord:i,pairOverride:r,participant:o}):{error:re}}function TY({event:t}){var e;const r=`${Hr}.${qr}`,{timeItem:n}=Un({element:t,itemType:r});if((e=n==null?void 0:n.itemValue)!=null&&e.PUBLIC){const{drawIds:o=[],seeding:i}=n.itemValue.PUBLIC||{},s={published:void 0,seedingScaleNames:[],drawIds:[]};return i&&Object.assign(s,n.itemValue.PUBLIC.seeding),{publishedDrawIds:o,publishedSeeding:s}}}function bd({element:t,accessor:e}){if(typeof e!="string")return{values:[]};const r=de(t),n=e.split("."),o=[];let i;a({targetElement:r,attributes:n});const s={value:i};return o.length&&(s.values=o),s;function a({targetElement:l,attributes:c=[],significantCharacters:u}){for(const[d,v]of c.entries())if(l!=null&&l[v])if(Array.isArray(l[v])){const f=l[v],m=c.slice(d);f.forEach(h=>a({targetElement:h,attributes:m}))}else l=l[v],p({targetElement:l,index:d});function p({targetElement:d,index:v}){if(d&&v===c.length-1&&["string","number"].includes(typeof d)){const f=u?d.slice(0,u):d;i?o.includes(f)||o.push(f):(i=f,o.push(f))}}}}function go({requireTimeStamp:t,scaleAttributes:e,participant:r}){var n,o;if(!r)return{error:oa};if(typeof e!="object")return{error:X};if(r.timeItems||(r.timeItems=[]),r&&Array.isArray(r.timeItems)){const{accessor:i,scaleType:s,eventType:a,scaleName:l}=e,c=[ds,s,a,l].join("."),p=r.timeItems.filter(d=>(d==null?void 0:d.itemType)===c).filter(d=>!t||(d==null?void 0:d.itemDate)).sort((d,v)=>(d.createdAt?new Date(d.createdAt).getTime():0)-(v.createdAt?new Date(v.createdAt).getTime():0)).pop();if(p){const[d,v,f,m]=(o=(n=p.itemType)==null?void 0:n.split("."))!=null?o:[];if(d!==ds)return{error:nu};const h=i&&bd({element:p.itemValue,accessor:i}),g=(h==null?void 0:h.value)||p.itemValue;return{scaleItem:{eventType:f,scaleDate:p.itemDate,scaleValue:g,scaleName:m,scaleType:v}}}else return{error:qx}}return{error:oa}}function wY({publishedSeeding:t,usePublishState:e,withSeeding:r,participant:n,event:o}){var i,s,a;const l={},c=f=>[ds,In,o.eventType,f].join("."),u=Object.assign({},...(n.timeItems||[]).filter(({itemType:f})=>f.split(".")[1]===In).map(({itemType:f,itemValue:m})=>({[f]:m}))),p=((t==null?void 0:t.stageSeedingScaleNames)&&Object.values(t==null?void 0:t.stageSeedingScaleNames)||Array.isArray(t==null?void 0:t.seedingScaleNames)&&t.seedingScaleNames||[]).map(c),d=Ht(Object.keys(u),p);if(!!(!e||!Object.keys(u).length&&!((i=t==null?void 0:t.drawIds)!=null&&i.length)||d.length)&&d.length){if(t!=null&&t.stageSeedingScaleNames){const f=Object.keys(t.stageSeedingScaleNames).map(h=>{const g=c(t.stageSeedingScaleNames[h]),_=u[g];return[h,_]}).filter(h=>h[1]).map(h=>({[h[0]]:{seedValue:h[1]}})),m=Object.assign({},...f);l.seedAssignments=m}else if(d){const f=d.map(m=>u[m]);l.seedValue=f.pop()}}else if(!e&&typeof r=="object"){const f=Object.keys(r).map(h=>{const g=c(r[h]),_=u[g];return[h,_]}).filter(h=>h[1]).map(h=>({[h[0]]:{seedValue:h[1]}})),m=Object.assign({},...f);l.seedAssignments=m}else{const{categoryName:f,ageCategoryCode:m}=o.category||{};let h;for(const g of[m,o.eventId,f]){const _={eventType:o.eventType,scaleType:In,scaleName:g},I=go({scaleAttributes:_,participant:n});if(I.scaleItem){h=I.scaleItem;break}}if(h&&(!e||(t==null?void 0:t.published)&&!((a=(s=t==null?void 0:t.published)==null?void 0:s.drawIds)!=null&&a.length))){const _=h.scaleValue;l.seedValue=_}}return l}var EY=Object.defineProperty,$Y=Object.defineProperties,NY=Object.getOwnPropertyDescriptors,Tb=Object.getOwnPropertySymbols,UY=Object.prototype.hasOwnProperty,AY=Object.prototype.propertyIsEnumerable,wb=(t,e,r)=>e in t?EY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Td=(t,e)=>{for(var r in e||(e={}))UY.call(e,r)&&wb(t,r,e[r]);if(Tb)for(var r of Tb(e))AY.call(e,r)&&wb(t,r,e[r]);return t},wd=(t,e)=>$Y(t,NY(e));function Eb({tournamentRecord:t,matchUpFormat:e,event:r}){if(!t)return{error:re};if(!Xr(e))return{error:Jc};const{extension:n}=$o({event:r,name:Wn}),o=n==null?void 0:n.value,{extension:i}=Fr({tournamentRecord:t,name:Wn}),s=i==null?void 0:i.value,a=(o==null?void 0:o.matchUpAverageTimes)&&Nl(wd(Td({},o),{matchUpFormat:e})),l=(s==null?void 0:s.matchUpAverageTimes)&&Nl(wd(Td({},s),{matchUpFormat:e})),c=[a,l].find(v=>v),u=(o==null?void 0:o.matchUpRecoveryTimes)&&Ul(wd(Td({},o),{matchUpFormat:e})),p=(s==null?void 0:s.matchUpRecoveryTimes)&&Ul(wd(Td({},s),{matchUpFormat:e})),d=[u,p].find(v=>v);return{matchUpFormat:e,averageTimes:c,recoveryTimes:d}}var CY=Object.defineProperty,MY=Object.defineProperties,DY=Object.getOwnPropertyDescriptors,$b=Object.getOwnPropertySymbols,jY=Object.prototype.hasOwnProperty,RY=Object.prototype.propertyIsEnumerable,Nb=(t,e,r)=>e in t?CY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Pc=(t,e)=>{for(var r in e||(e={}))jY.call(e,r)&&Nb(t,r,e[r]);if($b)for(var r of $b(e))RY.call(e,r)&&Nb(t,r,e[r]);return t},Ed=(t,e)=>MY(t,DY(e));function hm({tournamentRecord:t,recoveryTimes:e,matchUpFormat:r,averageTimes:n,event:o}){if(!t)return{error:re};if(n&&!Array.isArray(n))return{error:X};if(e&&!Array.isArray(e))return{error:X};const i=Wn;if(o){const{extension:s}=$o({event:o,name:i}),a=(s==null?void 0:s.value)||{},l=Ub(Ed(Pc({},a),{matchUpFormat:r,averageTimes:n,recoveryTimes:e}));ao({event:o,extension:{name:i,value:l}})}else{const{extension:s}=Fr({tournamentRecord:t,name:i}),a=(s==null?void 0:s.value)||{},l=Ub(Ed(Pc({},a),{matchUpFormat:r,averageTimes:n,recoveryTimes:e}));Ei({tournamentRecord:t,extension:{name:i,value:l}})}return Pc({},V)}function Ub(t){const{matchUpRecoveryTimes:e=[],matchUpAverageTimes:r=[],matchUpFormat:n}=t;let{averageTimes:o,recoveryTimes:i}=t;o=(o||[]).filter(l=>{var c,u;return((c=l==null?void 0:l.categoryNames)==null?void 0:c.length)||((u=l==null?void 0:l.categoryTypes)==null?void 0:u.length)});const s=(o==null?void 0:o.length)&&r.map(l=>{var c;return l!=null&&l.matchUpFormatCodes.includes(n)?Ed(Pc({},l),{matchUpFormatCodes:(c=l.matchUpFormatCodes)==null?void 0:c.filter(u=>u!==n)}):l}).filter(({matchUpFormatCodes:l})=>l==null?void 0:l.length).concat({matchUpFormatCodes:[n],averageTimes:o});i=(i||[]).filter(l=>{var c,u;return((c=l==null?void 0:l.categoryNames)==null?void 0:c.length)||((u=l==null?void 0:l.categoryTypes)==null?void 0:u.length)});const a=(i==null?void 0:i.length)&&e.map(l=>{var c;return l!=null&&l.matchUpFormatCodes.includes(n)?Ed(Pc({},l),{matchUpFormatCodes:(c=l.matchUpFormatCodes)==null?void 0:c.filter(u=>u!==n)}):l}).filter(({matchUpFormatCodes:l,averageTimes:c})=>(l==null?void 0:l.length)||c).concat({matchUpFormatCodes:[n],recoveryTimes:i});return{matchUpAverageTimes:(s==null?void 0:s.length)&&s||r,matchUpRecoveryTimes:(a==null?void 0:a.length)&&a||e}}function Ab({tournamentRecord:t,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,event:i}){if(!t)return{error:re};if(!Xr(n))return{error:X};if(!i)return{error:Ge};const{averageTimes:s=[],recoveryTimes:a=[]}=Eb({tournamentRecord:t,matchUpFormat:n,event:i}),l=i.category,c=(l==null?void 0:l.categoryName)||(l==null?void 0:l.ageCategoryCode)||(i==null?void 0:i.eventId);let u={categoryNames:[c],minutes:{}};const p={categoryNames:[c],minutes:{}},d=g=>{var _,I;if((_=g.categoryTypes)!=null&&_.includes(o)&&console.log("encountered:",{categoryType:o}),!((I=g.categoryNames)!=null&&I.includes(c)&&(g.categoryNames=g.categoryNames.filter(P=>P!==c),u={minutes:g.minutes,categoryNames:[c]},!g.categoryNames.length)))return g},v=!isNaN(Te(r)),f=!isNaN(Te(e)),m=s.map(d).filter(g=>{var _;return(_=g==null?void 0:g.categoryNames)==null?void 0:_.length}),h=a.map(d).filter(g=>{var _;return(_=g==null?void 0:g.categoryNames)==null?void 0:_.length});return v&&(Object.assign(u.minutes,{[(i==null?void 0:i.eventType)||At]:r}),m.push(u)),f&&(Object.assign(p.minutes,{[(i==null?void 0:i.eventType)||At]:e}),h.push(p)),!v&&!f?{error:X}:hm({averageTimes:v&&m,recoveryTimes:f&&h,tournamentRecord:t,matchUpFormat:n,event:i})}function FY({tournamentRecords:t,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,tournamentId:i,eventId:s}){if(!s)return{error:Ge};const a=Object.keys(t).filter(l=>!i||i===l);if(i&&!a.includes(i))return{error:X};for(const l of a){const c=t[l],{event:u}=Qt({tournamentRecord:c,eventId:s});if(u)return Ab({tournamentRecord:c,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,event:u})}return{error:Ar}}const yc=({scheduleAttributes:t=["scheduledDate","scheduledTime"],schedule:e={}})=>!!Object.keys(e).filter(n=>t.includes(n)).filter(n=>e[n]).length;var xY=Object.defineProperty,LY=Object.defineProperties,VY=Object.getOwnPropertyDescriptors,Cb=Object.getOwnPropertySymbols,BY=Object.prototype.hasOwnProperty,kY=Object.prototype.propertyIsEnumerable,Mb=(t,e,r)=>e in t?xY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,GY=(t,e)=>{for(var r in e||(e={}))BY.call(e,r)&&Mb(t,r,e[r]);if(Cb)for(var r of Cb(e))kY.call(e,r)&&Mb(t,r,e[r]);return t},WY=(t,e)=>LY(t,VY(e));function Sc({tournamentRecord:t}){if(!t)return{error:re};const e=(({tournamentId:r,tournamentRank:n,tournamentStatus:o,formalName:i,tournamentName:s,promotionalName:a,onlineResources:l,localTimeZone:c,startDate:u,endDate:p,hostCountryCode:d,tournamentContacts:v,tournamentAddresses:f})=>({tournamentId:r,tournamentRank:n,tournamentStatus:o,formalName:i,tournamentName:s,promotionalName:a,onlineResources:l,localTimeZone:c,startDate:u,endDate:p,hostCountryCode:d,tournamentContacts:v,tournamentAddresses:f}))(t);return WY(GY({},V),{tournamentInfo:de(e,!1,!0)})}var HY=Object.defineProperty,$d=Object.getOwnPropertySymbols,Db=Object.prototype.hasOwnProperty,jb=Object.prototype.propertyIsEnumerable,Rb=(t,e,r)=>e in t?HY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Fb=(t,e)=>{for(var r in e||(e={}))Db.call(e,r)&&Rb(t,r,e[r]);if($d)for(var r of $d(e))jb.call(e,r)&&Rb(t,r,e[r]);return t},xb=(t,e)=>{var r={};for(var n in t)Db.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&$d)for(var n of $d(t))e.indexOf(n)<0&&jb.call(t,n)&&(r[n]=t[n]);return r};function Lb({derivedDrawInfo:t,participantId:e,drawId:r}){var n,o,i,s;const a=(o=(n=t[r])==null?void 0:n.mainPositionAssignments)==null?void 0:o.find(u=>u.participantId===e),l=(s=(i=t[r])==null?void 0:i.qualifyingPositionAssignments)==null?void 0:s.find(u=>u.participantId===e),c={};if(a){const u=a,{participantId:p}=u,d=xb(u,["participantId"]);p&&(c[he]=Fb({},d))}if(l){const u=l,{participantId:p}=u,d=xb(u,["participantId"]);p&&(c[we]=Fb({},d))}return Object.keys(c).length?c:void 0}function qY({processParticipantId:t,tournamentRecords:e,tournamentRecord:r}){if(typeof r!="object"&&typeof e!="object")return{error:re};const n=e?Object.values(e).map(i=>(i==null?void 0:i.participants)||[]).flat():(r==null?void 0:r.participants)||[];return{relevantParticipantIdsMap:Object.assign({},...n.map(({participantId:i,participantType:s,individualParticipantIds:a})=>{typeof t=="function"&&t(i);const l=(a||[]).map(c=>({participantType:Fe,relevantParticipantId:c}));return{[i]:l.concat({relevantParticipantId:i,participantType:s})}}))}}var zY=Object.defineProperty,Nd=Object.getOwnPropertySymbols,Vb=Object.prototype.hasOwnProperty,Bb=Object.prototype.propertyIsEnumerable,kb=(t,e,r)=>e in t?zY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Gb=(t,e)=>{for(var r in e||(e={}))Vb.call(e,r)&&kb(t,r,e[r]);if(Nd)for(var r of Nd(e))Bb.call(e,r)&&kb(t,r,e[r]);return t},Wb=(t,e)=>{var r={};for(var n in t)Vb.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Nd)for(var n of Nd(t))e.indexOf(n)<0&&Bb.call(t,n)&&(r[n]=t[n]);return r};function Ud({derivedDrawInfo:t,participantId:e,drawId:r}){var n,o,i,s;const a=(o=(n=t[r])==null?void 0:n.mainSeedAssignments)==null?void 0:o.find(u=>u.participantId===e),l=(s=(i=t[r])==null?void 0:i.qualifyingSeedAssignments)==null?void 0:s.find(u=>u.participantId===e),c={};if(a){const u=a,{participantId:p}=u,d=Wb(u,["participantId"]);p&&(c[he]=Gb({},d))}if(l){const u=l,{participantId:p}=u,d=Wb(u,["participantId"]);p&&(c[we]=Gb({},d))}return Object.keys(c).length?c:void 0}function Hb({scheduleAttributes:t=["scheduledDate","scheduledTime"],matchUps:e=[]}){if(!Array.isArray(e))return{error:ko};if(!Array.isArray(t))return{error:X};const r=e.filter(Boolean).filter(({schedule:o})=>yc({schedule:o,scheduleAttributes:t})).reduce((o,i)=>{const{schedule:s}=i,a=Re(s==null?void 0:s.scheduledDate),l=at(s==null?void 0:s.scheduledTime);return a&&l&&(o[a]?o[a].push(i):o[a]=[i]),o},{});return Object.keys(r).forEach(o=>{r[o].sort((i,s)=>{var a,l;return j_(at((a=i.schedule)==null?void 0:a.scheduledTime),at((l=s.schedule)==null?void 0:l.scheduledTime))})}),{scheduledMatchUps:r}}var YY=Object.defineProperty,KY=Object.defineProperties,QY=Object.getOwnPropertyDescriptors,qb=Object.getOwnPropertySymbols,JY=Object.prototype.hasOwnProperty,ZY=Object.prototype.propertyIsEnumerable,zb=(t,e,r)=>e in t?YY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,XY=(t,e)=>{for(var r in e||(e={}))JY.call(e,r)&&zb(t,r,e[r]);if(qb)for(var r of qb(e))ZY.call(e,r)&&zb(t,r,e[r]);return t},e7=(t,e)=>KY(t,QY(e));function t7(t){var e,r,n,o,i,s,a,l,c,u,p;const{withScaleValues:d=!0,eventsPublishStatuses:v,withEvents:f=!0,withDraws:m=!0,participantIdMap:h,scheduleAnalysis:g,derivedDrawInfo:_,usePublishState:I,withStatistics:P,withOpponents:y,withMatchUps:S,withSeeding:O,participant:b,withISO2:w,withIOC:T}=t,$=[],N=[];if((T||w)&&Ju({participant:b,withIOC:T,withISO2:w}),d){const{ratings:J,rankings:te}=ha({participant:b});b.rankings=te,b.ratings=J}const E=b==null?void 0:b.participantId;if(!E||!h[E])return{};const{potentialMatchUps:A,opponents:U,matchUps:C,events:M,losses:D,draws:R,wins:j}=h[E],G=j+D,W=j,q=G&&W/G,F={statCode:$l,denominator:G,numerator:W,statValue:q},L=Object.values(R),x=Object.values(M);if(m&&L){b.draws=L;for(const J of L){const te=(e=v[J.eventId])==null?void 0:e.publishedSeeding;if(!I||(te==null?void 0:te.published)&&(((r=te==null?void 0:te.drawIds)==null?void 0:r.length)===0||((n=te==null?void 0:te.drawIds)==null?void 0:n.includes(J.drawId)))){const ee=Ud({drawId:J.drawId,derivedDrawInfo:_,participantId:E});ee&&(J.seedAssignments=ee)}}}if(f&&x&&(b.events=x,O)){const J=Object.assign({},...(b.timeItems||[]).filter(({itemType:te})=>te.split(".")[1]===In).map(({itemType:te,itemValue:ne})=>({[te]:ne})));for(const te of x){const ne=se=>[ds,In,te.eventType,se].join("."),ee=(o=v[te.eventId])==null?void 0:o.publishedSeeding,oe=((ee==null?void 0:ee.stageSeedingScaleNames)&&Object.values(ee==null?void 0:ee.stageSeedingScaleNames)||Array.isArray(ee==null?void 0:ee.seedingScaleNames)&&ee.seedingScaleNames||[]).map(ne),ie=Ht(Object.keys(J),oe),ae=!!(!I||!Object.keys(J).length&&!((i=ee==null?void 0:ee.drawIds)!=null&&i.length)||ie.length);if(ae&&ie.length){if(ee!=null&&ee.stageSeedingScaleNames){const se=Object.keys(ee.stageSeedingScaleNames).map(Ie=>{const pe=ne(ee.stageSeedingScaleNames[Ie]),fe=J[pe];return[Ie,fe]}).filter(Ie=>Ie[1]).map(Ie=>({[Ie[0]]:{seedValue:Ie[1]}})),ye=Object.assign({},...se);te.seedAssignments=ye}else if(ie){const se=ie.map(ye=>J[ye]);te.seedValue=se.pop()}}else if(!I&&typeof O=="object"){const se=Object.keys(O).map(Ie=>{const pe=ne(O[Ie]),fe=J[pe];return[Ie,fe]}).filter(Ie=>Ie[1]).map(Ie=>({[Ie[0]]:{seedValue:Ie[1]}})),ye=Object.assign({},...se);te.seedAssignments=ye}else{const{categoryName:se,ageCategoryCode:ye}=te.category||{};let Ie;for(const pe of[te.eventId,ye,se]){const fe={eventType:te.eventType,scaleType:In,scaleName:pe},ve=go({scaleAttributes:fe,participant:b});if(ve.scaleItem){Ie=ve.scaleItem;break}}if(Ie){const pe=Ie.scaleValue;(!I||(ee==null?void 0:ee.published)&&(((s=ee==null?void 0:ee.drawIds)==null?void 0:s.length)===0||((a=ee==null?void 0:ee.drawIds)==null?void 0:a.includes(te.drawId))))&&(te.seedValue=pe)}}if((l=te.drawIds)!=null&&l.length)for(const se of te.drawIds||[]){const ye=((c=ee==null?void 0:ee.drawIds)==null?void 0:c.length)&&!((u=ee==null?void 0:ee.drawIds)!=null&&u.includes(se));if(ae&&!ye){const Ie=Ud({drawId:se,derivedDrawInfo:_,participantId:E});if(Ie&&te.seedAssignments)for(const pe of Object.keys(te.seedAssignments))te.seedAssignments[pe]=Ie[pe];else te.seedAssignments=Ie}}}}const B=Object.values(U).flat();y&&(B!=null&&B.length)&&(b.opponents=B,L==null||L.forEach(J=>{J.opponents=B.filter(te=>te.drawId===J.drawId)}));const z=Object.values(A),H=Object.values(C);S&&(b.potentialMatchUps=z,b.matchUps=H);const Y=H.concat(z),Z=((p=Hb({matchUps:Y}))==null?void 0:p.scheduledMatchUps)||[],{scheduledMinutesDifference:K}=g||{};return Object.keys(Z).forEach(J=>{Z[J].filter(Boolean).forEach((te,ne)=>{var ee,oe,ie,ae;const{schedule:{scheduledTime:se,timeAfterRecovery:ye,typeChangeTimeAfterRecovery:Ie},matchUpStatus:pe,roundPosition:fe,structureName:ve,matchUpType:le,roundNumber:be,matchUpId:Me,drawId:Pe,score:xe}=te;N.push(e7(XY({},te.schedule),{scheduledTime:at((ee=te.schedule)==null?void 0:ee.scheduledTime),roundPosition:fe,structureName:ve,matchUpType:le,roundNumber:be,matchUpId:Me,drawId:Pe}));const Be=pe===nt||[ot,Xe].includes(pe)&&!Gt({score:xe});if(se&&!Be){const qe=Le(se),$e=Z[J].slice(ne+1);for(const De of $e)if(!(De.matchUpStatus===nt||[ot,Xe].includes(De.matchUpStatus)&&!Gt(De))&&((oe=De.schedule)!=null&&oe.scheduledTime)){const Se=te.matchUpType!==De.matchUpType&&Ie||ye,Ee=te.drawId===De.drawId,Ae=te.potential&&De.potential,gt=Le((ie=De.schedule)==null?void 0:ie.scheduledTime)-qe;(K&&!isNaN(K)?gt<=K:Le(Se)>Le((ae=De.schedule)==null?void 0:ae.scheduledTime))&&!(Ae&&Ee)&&$.push({priorScheduledMatchUpId:De.matchUpId,matchUpIdWithConflict:Me})}}})}),P&&(b.statistics=[F]),{scheduleConflicts:$,scheduleItems:N}}function r7({eventEntries:t,sortConfig:e,event:r}){var n;const o={},i=Object.assign({},...((n=r.drawDefinitions)!=null?n:[]).map(s=>{var a,l,c,u,p,d,v,f,m;const h=Object.assign({},...(t??[]).filter(N=>N.participantId).map(N=>({[N.participantId]:N})),...s.entries.filter(N=>N.participantId).map(N=>({[N.participantId]:N}))),g=Object.values(h),_=(l=(a=an({stageSequence:1,drawDefinition:s,stage:he}))==null?void 0:a.structures)==null?void 0:l[0],I=_&&((c=st({structure:_}))==null?void 0:c.positionAssignments),P=I==null?void 0:I.length,y=(p=(u=an({stageSequence:1,stage:we,drawDefinition:s}))==null?void 0:u.structures)==null?void 0:p[0],S=_&&((d=st({structure:y}))==null?void 0:d.positionAssignments),O=S==null?void 0:S.length,b=_==null?void 0:_.seedAssignments,w=y==null?void 0:y.seedAssignments,T=(s.structures||[]).sort((N,E)=>Ri(N,E,e)).map(({structureId:N,structures:E})=>[N,...(E||[]).map(({structureId:A})=>A)]).flat(1/0),$=(m=(f=(v=r==null?void 0:r._flightProfile)==null?void 0:v.flights)==null?void 0:f.find(N=>N.drawId===s.drawId))==null?void 0:m.flightNumber;return o[s.drawId]={qualifyingPositionAssignments:S,qualifyingSeedAssignments:w,mainPositionAssignments:I,mainSeedAssignments:b,orderedStructureIds:T,qualifyingDrawSize:O,flightNumber:$,drawSize:P},{[s.drawId]:{drawType:s.drawType,drawEntries:g}}}));return{derivedInfo:o,drawDetails:i}}function n7({relevantParticipantIdsMap:t,participantFilters:e,participantIdMap:r,derivedDrawInfo:n,eventDrawsCount:o,drawDetails:i,eventType:s,matchUp:a}){var l;const{collectionId:c,collectionPosition:u,drawId:p,drawName:d,eventId:v,eventName:f,finishingRound:m,finishingPositionRange:h,processCodes:g,loserTo:_,matchUpId:I,matchUpType:P,matchUpFormat:y,matchUpStatus:S,matchUpStatusCodes:O,matchUpTieId:b,roundName:w,roundNumber:T,roundPosition:$,score:N,sides:E,stage:A,stageSequence:U,schedule:C,structureName:M,structureId:D,tieFormat:R,tieMatchUps:j,tournamentId:G,winnerTo:W,winningSide:q}=a,F=e==null?void 0:e.participantIds,L=H=>{const Y=H&&t[H]||[];return Y.push(H),Y.some(Z=>!F||F.includes(Z.relevantParticipantId))?Y:[]},{winner:x,loser:B}=h||{},z=(j==null?void 0:j.length)&&j.filter(({matchUpType:H})=>H===mn).map(({sides:H})=>H.map(({sideNumber:Y,participantId:Z,participant:K})=>Y&&Z&&{sideNumber:Y,participantId:Z,participant:K})).flat().filter(Boolean)||[];if(s===lo&&P===mn){const H=(((l=a.sides)==null?void 0:l.filter(Boolean))||[]).map(({sideNumber:Y,participantId:Z,participant:K})=>Y&&Z&&{sideNumber:Y,participantId:Z,participant:K}).filter(Boolean);z.push(...H)}if(E==null||E.forEach(H=>{const{participantId:Y,sideNumber:Z}=H;if(!Y)return;const{drawType:K,drawEntries:Q}=i[p],J=Z===1?N==null?void 0:N.scoreStringSide1:N==null?void 0:N.scoreStringSide2,te=q&&Z===q,ne=a.sides.find(pe=>pe.sideNumber===3-Z),ee=ne==null?void 0:ne.participantId,oe=ee&&t[ee]||[],ie=te?x:B,ae=Q.find(pe=>pe.participantId===Y),se=L(Y),ye=[];z==null||z.filter(pe=>pe.sideNumber===Z).forEach(pe=>{const fe=pe.participantId;fe&&!ye.includes(fe)&&(se.push({relevantParticipantId:fe,participantType:Ce}),ye.push(fe))});const Ie=se.filter(pe=>s!==lo||s===lo&&[mn,hn].includes(P)&&[Ce,zn].includes(pe.participantType)||s===lo&&[bi,mn].includes(P)&&[Fe].includes(pe.participantType));Ie==null||Ie.forEach(({relevantParticipantId:pe,participantType:fe})=>{var ve,le;const{entryStage:be,entryStatus:Me,entryPosition:Pe}=ae||{};if(!r[pe])return;if(!r[pe].draws[p]){const me=Lb({participantId:pe,derivedDrawInfo:n,drawId:p}),ge=Ud({participantId:pe,derivedDrawInfo:n,drawId:p});r[pe].draws[p]=Oe({qualifyingDrawSize:(ve=n[p])==null?void 0:ve.qualifyingDrawSize,drawSize:(le=n[p])==null?void 0:le.drawSize,partnerParticipantIds:[],positionAssignments:me,seedAssignments:ge,entryPosition:Pe,entryStatus:Me,entryStage:be,drawName:d,drawType:K,eventId:v,drawId:p})}r[pe].events[v]||(r[pe].events[v]={partnerParticipantIds:[],drawIds:[],eventName:f,eventId:v});const xe=r[pe].events[v].drawIds;xe&&!(xe!=null&&xe.includes(p))&&r[pe].events[v].drawIds.push(p);let Be;if(fe===Fe&&P===mn){const me=Ie.find(ge=>ge.relevantParticipantId!==pe&&ge.participantType===Fe);Be=me==null?void 0:me.relevantParticipantId}const qe=(oe==null?void 0:oe.filter(me=>P===hn&&fe===zn&&me.participantType===zn||P===bi&&me.participantType===Fe||P===mn&&(fe===Fe?[Fe,Ce].includes(me.participantType):me.participantType===Ce)))||[];qe.forEach(({relevantParticipantId:me,participantType:ge})=>{r[pe].opponents||(r[pe].opponents={}),r[pe].opponents[me]={eventId:v,drawId:p,matchUpId:I,participantType:ge,participantId:me}});const $e=qe.map(({relevantParticipantId:me,participantType:ge})=>({participantId:me,participantType:ge}));(P!==hn&&[Fe,Ce].includes(fe)||P===hn&&fe===zn)&&(r[pe].matchUps[I]=Oe({collectionId:c,collectionPosition:u,drawId:p,eventId:v,eventType:s,eventDrawsCount:o,finishingRound:m,finishingPositionRange:ie,loserTo:_,matchUpId:I,matchUpType:P,matchUpFormat:y,matchUpStatus:S,matchUpStatusCodes:O,matchUpTieId:b,opponentParticipantInfo:$e,participantWon:te,partnerParticipantId:Be,perspectiveScoreString:J,processCodes:g,roundName:w,roundNumber:T,roundPosition:$,schedule:C,score:N,sides:E,stage:A,stageSequence:U,structureName:M,structureId:D,tieFormat:R,tournamentId:G,winnerTo:W,winningSide:q})),Be&&(r[pe].events[v].partnerParticipantIds.push(Be),r[pe].draws[p].partnerParticipantIds.push(Be),r[pe].events[v].partnerParticipantId=Be,r[pe].draws[p].partnerParticipantId=Be),q&&(te?r[pe].wins++:r[pe].losses++)})}),Array.isArray(a.potentialParticipants)){const H=oc(a.potentialParticipants.flat());H==null||H.forEach(Y=>{const Z=L(Y);Z==null||Z.forEach(({relevantParticipantId:K})=>{r[K].potentialMatchUps[I]=Oe({drawId:p,eventId:v,eventType:s,matchUpId:I,matchUpType:P,matchUpFormat:y,roundName:w,roundNumber:T,roundPosition:$,schedule:C,tieFormat:R,structureName:M,tournamentId:G,potential:!0})})})}}var o7=Object.defineProperty,i7=Object.defineProperties,s7=Object.getOwnPropertyDescriptors,Yb=Object.getOwnPropertySymbols,a7=Object.prototype.hasOwnProperty,l7=Object.prototype.propertyIsEnumerable,Kb=(t,e,r)=>e in t?o7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gm=(t,e)=>{for(var r in e||(e={}))a7.call(e,r)&&Kb(t,r,e[r]);if(Yb)for(var r of Yb(e))l7.call(e,r)&&Kb(t,r,e[r]);return t},_m=(t,e)=>i7(t,s7(e));function c7(t){var e,r;const n=[],o={},i={},s={},a=f=>{s[f]||(s[f]={groupParticipantIds:[],teamParticipantIds:[],pairParticipantIds:[],potentialMatchUps:{},scheduleItems:[],opponents:{},matchUps:{},events:{},groups:[],teams:[],draws:{},losses:0,wins:0})},{tournamentRecord:l,participantFilters:c,allTournamentParticipants:u}=t,{relevantParticipantIdsMap:p}=qY({processParticipantId:a,tournamentRecord:l}),d=c==null?void 0:c.participantIds,v=f=>{const m=f&&p[f]||[];return m.push(f),m.some(h=>!d||d.includes(h.relevantParticipantId))?m:[]};return t.withGroupings&&u.forEach(f=>{var m,h,g;if(f.participantType===Mr){const _=f.participantId;(m=f==null?void 0:f.individualParticipantIds)==null||m.forEach(I=>{s[I].groupParticipantIds.includes(_)||(s[I].groupParticipantIds.push(_),s[I].groups.push({participantRoleResponsibilities:f.participantRoleResponsibilities,participantOtherName:f.participantOtherName,participantName:f.participantName,participantId:f.participantId}))})}if(f.participantType===Qe){const _=f.participantId;(h=f==null?void 0:f.individualParticipantIds)==null||h.forEach(I=>{var P,y,S,O;(y=(P=s[I])==null?void 0:P.teamParticipantIds)!=null&&y.includes(_)||((S=s[I])==null||S.teamParticipantIds.push(_),(O=s[I])==null||O.teams.push({participantRoleResponsibilities:f.participantRoleResponsibilities,participantOtherName:f.participantOtherName,participantName:f.participantName,participantId:f.participantId,teamId:f.teamId}))})}if(f.participantType===Ce){const _=f.participantId;(g=f==null?void 0:f.individualParticipantIds)==null||g.forEach(I=>{s[I]&&!s[I].pairParticipantIds.includes(_)&&s[I].pairParticipantIds.push(_)})}}),t.withMatchUps&&cn({tournamentRecord:l}),(t.withScheduleItems||t.scheduleAnalysis||t.withStatistics||t.withOpponents||t.withMatchUps||t.withSeeding||t.withEvents||t.withDraws)&&((e=t.tournamentEvents)==null||e.forEach(f=>{var m,h,g,_,I,P,y;const S=de(f,!0,!0),O=Nt({event:S}).flightProfile,b=((m=O==null?void 0:O.flights)==null?void 0:m.length)||((h=S.drawDefinitions)==null?void 0:h.length)||0;(S.drawDefinitions||[]).forEach((L,x)=>{if((S==null?void 0:S.eventType)===Qe){const{extension:B}=Kt({element:f.drawDefinitions[x],name:kn});B&&(L.extensions=[B])}});const{eventId:w,eventName:T,eventType:$,category:N}=S,E={eventId:w,eventName:T,eventType:$,category:N},A=S&&Object.keys(S).filter(L=>L.startsWith("_"));A==null||A.forEach(L=>E[L]=S[L]);const U=S.entries||[],C=`${Hr}.${qr}`,{timeItem:M}=jo({itemType:C,event:S});if((g=M==null?void 0:M.itemValue)!=null&&g.PUBLIC){const{drawIds:L=[],seeding:x}=M.itemValue.PUBLIC||{},B={published:void 0,seedingScaleNames:[],drawIds:[]};x&&Object.assign(B,M.itemValue.PUBLIC.seeding),o[w]={publishedDrawIds:L,publishedSeeding:B}}const R=[...Object.values(cI)].map(L=>`_${L}`),j=E&&Object.keys(E).filter(L=>!R.includes(L)).reduce((L,x)=>(L[x]=E[x],L),{});U==null||U.filter(L=>L==null?void 0:L.participantId).forEach(L=>{const{participantId:x,entryStage:B,entryStatus:z,entryPosition:H}=L,Y=v(x);Y==null||Y.forEach(({relevantParticipantId:Z})=>{s[Z]||a(Z),s[Z].events[w]=_m(gm({},j),{partnerParticipantIds:[],entryPosition:H,entryStatus:z,entryStage:B,drawIds:[],eventId:w})})});const G=({drawEntry:L,drawId:x})=>{const{participantId:B,entryStage:z,entryStatus:H,entryPosition:Y}=L,Z=v(B);Z==null||Z.forEach(({relevantParticipantId:K})=>{var Q,J;if(s[K].events[w]||(s[K].events[w]=_m(gm({},j),{partnerParticipantIds:[],entryPosition:Y,entryStatus:H,entryStage:z,drawIds:[],eventId:w})),!s[K].draws[x]){const ne=Lb({participantId:K,derivedDrawInfo:i,drawId:x}),ee=Ud({participantId:K,derivedDrawInfo:i,drawId:x});s[K].draws[x]=Oe({qualifyingDrawSize:(Q=i[x])==null?void 0:Q.qualifyingDrawSize,drawSize:(J=i[x])==null?void 0:J.drawSize,partnerParticipantIds:[],positionAssignments:ne,eventDrawsCount:b,seedAssignments:ee,entryPosition:Y,entryStatus:H,entryStage:z,eventId:w,drawId:x})}const te=s[K].events[w].drawIds;te&&!(te!=null&&te.includes(x))&&s[K].events[w].drawIds.push(x)})},W=((_=S.drawDefinitions)==null?void 0:_.map(({drawId:L})=>L))||[];(P=(I=E._flightProfile)==null?void 0:I.flights)==null||P.forEach(L=>{const{drawId:x,drawEntries:B}=L;W.includes(x)||B==null||B.forEach(z=>G({drawEntry:z,drawId:x}))});const{drawDetails:q,derivedInfo:F}=r7({eventEntries:U,event:S});if(Object.assign(i,F),S.eventType===Qe||t.withScheduleItems||t.scheduleAnalysis||t.withStatistics||t.withOpponents||t.withMatchUps||t.withDraws){const L=(y=ai({afterRecoveryTimes:t.scheduleAnalysis,participants:u,nextMatchUps:!0,tournamentRecord:l,inContext:!0,event:S}))==null?void 0:y.matchUps;L==null||L.forEach(x=>n7({relevantParticipantIdsMap:p,participantFilters:c,participantIdMap:s,derivedDrawInfo:i,eventDrawsCount:b,drawDetails:q,eventType:$,matchUp:x}))}})),(r=t.tournamentParticipants)==null||r.forEach(f=>{const{scheduleConflicts:m,scheduleItems:h}=t7(_m(gm({},t),{eventsPublishStatuses:o,participantIdMap:s,derivedDrawInfo:i,participant:f}));if(t.withSignInStatus){const{timeItem:g}=Un({itemType:xl,element:f});f.signedIn=(g==null?void 0:g.itemValue)===Ll}if(t.withScheduleItems&&(f.scheduleItems=h),t.scheduleAnalysis&&(f.scheduleConflicts=m,m!=null&&m.length&&!n.includes(f.participantId)&&n.push(f.participantId)),t.withGroupings!==!1){const g=s[f.participantId];f.groupParticipantIds=g==null?void 0:g.groupParticipantIds,f.pairParticipantIds=g==null?void 0:g.pairParticipantIds,f.teamParticipantIds=g==null?void 0:g.teamParticipantIds,f.groups=g==null?void 0:g.groups,f.teams=g==null?void 0:g.teams}t.withTeamMatchUps}),{participantIdsWithConflicts:n,eventsPublishStatuses:o}}function Ad({participantFilters:t={},tournamentRecord:e,participants:r=[]}){var n;if(!Object.keys(t).length)return r;const{accessorValues:o,drawEntryStatuses:i,positionedParticipants:s,eventEntryStatuses:a,participantRoles:l,participantRoleResponsibilities:c,participantTypes:u,participantIds:p,signInStatus:d,enableOrFiltering:v,eventIds:f,genders:m}=t,h=_o(f)&&((n=e==null?void 0:e.events)==null?void 0:n.filter(y=>f==null?void 0:f.includes(y.eventId)))||(e==null?void 0:e.events)||[],g=i&&u7({drawEntryStatuses:i,tournamentEvents:h}),_=a&&d7({eventEntryStatuses:a,tournamentEvents:h}),I=s!==void 0&&[!0,!1].includes(s)&&h.reduce((y,S)=>y.concat(...(S.drawDefinitions||[]).map(O=>ay({drawDefinition:O}).allPositionedParticipantIds).filter(Boolean)),[]),P=y=>o==null?void 0:o.reduce((S,O)=>{const{accessor:b,value:w}=O,{values:T}=bd({element:y,accessor:b});return S&&(T==null?void 0:T.includes(w))},!0);if(r=r==null?void 0:r.filter(y=>{var S,O;const b=(O=(S=Un({element:y,itemType:xl}))==null?void 0:S.timeItem)==null?void 0:O.itemValue,{participantRoleResponsibilities:w,participantType:T,participantRole:$,participantId:N,person:E}=y,A=Array.isArray(m)&&(m==null?void 0:m.length)&&(E==null?void 0:E.sex)&&m.includes(E.sex);return v?m&&A||s&&I.includes(N)||s===!1&&!I.includes(N)||(g==null?void 0:g.includes(N))||(_==null?void 0:_.includes(N))||(p==null?void 0:p.includes(N))||d&&b===d||u&&T&&_o(u)&&u.includes(T)||l&&$&&_o(l)&&l.includes($)||c&&_o(w)&&_o(c)&&c.find(U=>w==null?void 0:w.includes(U))||(o==null?void 0:o.length)&&_o(o)&&P(y):(!m||A)&&(s===void 0||s&&I.includes(N)||s===!1&&!I.includes(N))&&(!g||g.includes(N))&&(!_||_.includes(N))&&(!p||p.includes(N))&&(!d||b===d)&&(!u||T&&_o(u)&&u.includes(T))&&(!l||$&&_o(l)&&l.includes($))&&(!c||_o(w)&&_o(c)&&c.find(U=>w==null?void 0:w.includes(U)))&&(!(o!=null&&o.length)||_o(o)&&P(y))}),h.length&&f){const y=h.filter(S=>f.includes(S.eventId)).map(S=>{const O=(S.entries||[]).map(w=>w.participantId);if(S.eventType===ri)return O;const b=((e==null?void 0:e.participants)||[]).filter(w=>O.includes(w.participantId)).map(w=>w.individualParticipantIds).flat(1);return O.concat(...b)}).flat(1);r=r==null?void 0:r.filter(S=>y.includes(S.participantId))}return r}function _o(t){return t&&Array.isArray(t)&&t.length}function u7({drawEntryStatuses:t,tournamentEvents:e}){const r=({entryStatus:n})=>Array.isArray(t)?t.includes(n):!0;return We(e.reduce((n,o)=>{var i,s;const{flightProfile:a}=Nt({event:o}),l=((i=a==null?void 0:a.flights)==null?void 0:i.map(({drawEntries:u})=>Array.isArray(u)?u.filter(r).map(ct):[]).flat())||[],c=((s=o.drawDefinitions)==null?void 0:s.map(({entries:u})=>u?u.filter(r).map(ct):[]))||[];return n.concat(...l,...c)},[]))}function d7({eventEntryStatuses:t,tournamentEvents:e}){return We(e.reduce((r,n)=>{const o=(n.entries||[]).filter(({entryStatus:i})=>Array.isArray(t)?t.includes(i):!0).map(ct);return r.concat(...o)},[]))}function cr(t){const{participantFilters:e={},convertExtensions:r,policyDefinitions:n,withScheduleItems:o,scheduleAnalysis:i,withSignInStatus:s,withTeamMatchUps:a,tournamentRecord:l,usePublishState:c,withScaleValues:u,withStatistics:p,withGroupings:d,withOpponents:v,withMatchUps:f,withSeeding:m,withEvents:h,withDraws:g,inContext:_,withISO2:I,withIOC:P}=t;if(!l)return{error:re};if(!l.participants)return{error:ml};const y=l.participants.map($=>de($,r));if(typeof e!="object")return{error:no,participantFilters:e};_&&(y==null||y.forEach($=>{var N;[Ce,tt,Mr].includes($.participantType)&&($.individualParticipants=(N=$.individualParticipantIds)==null?void 0:N.map(E=>{const A=l.participants.find(C=>C.participantId===E),U=de(A,r,!0);if(u){const{ratings:C,rankings:M}=ha({participant:U});U.ratings=C,U.rankings=M}return(P||I)&&Ju({participant:U,withISO2:I,withIOC:P}),U}))}));let S=e?Ad({participants:y,participantFilters:e,tournamentRecord:l}):y,O,b;if(o||s||i||u||p||d||v||f||m||h||g||I||P){const $=c7({tournamentEvents:l.events,allTournamentParticipants:y,tournamentParticipants:S,participantFilters:e,withScheduleItems:o,withSignInStatus:s,tournamentRecord:l,scheduleAnalysis:i,withTeamMatchUps:a,usePublishState:c,withScaleValues:u,withStatistics:p,withGroupings:d,withOpponents:v,withMatchUps:f,withSeeding:m,withEvents:h,withDraws:g,withISO2:I,withIOC:P});O=$==null?void 0:$.participantIdsWithConflicts,b=$==null?void 0:$.eventsPublishStatuses}const T=n==null?void 0:n[Tl];return T!=null&&T.participant&&(S=S.map($=>iu({template:T.participant,source:$}))),{participantIdsWithConflicts:O,tournamentParticipants:S,eventsPublishStatuses:b}}const p7="ADMINISTRATION",f7="CAPTAIN",v7="COACH",ur="COMPETITOR",m7="MEDIA",h7="MEDICAL",Qb="OFFICIAL",Jb="OTHER",Zb={ADMINISTRATION:p7,CAPTAIN:f7,COACH:v7,COMPETITOR:ur,MEDIA:m7,MEDICAL:h7,OFFICIAL:Qb,OTHER:Jb,SECURITY:"SECURITY"};function Xb(t){return dd(t)}function Im({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,scheduledDate:o,matchUpId:i}){return zv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,scheduledDate:o,matchUpId:i})}function Pm({removePriorValues:t,tournamentRecord:e,drawDefinition:r,scheduledTime:n,disableNotice:o,matchUpId:i}){return Gi({removePriorValues:t,tournamentRecord:e,drawDefinition:r,scheduledTime:n,disableNotice:o,matchUpId:i})}function eT({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,startTime:o}){return Kv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,startTime:o})}function tT({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,endTime:o}){return Qv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,endTime:o})}function rT({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,stopTime:o}){return Jv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,stopTime:o})}function nT({tournamentRecord:t,drawDefinition:e,disableNotice:r,resumeTime:n,matchUpId:o}){return Zv({tournamentRecord:t,drawDefinition:e,disableNotice:r,resumeTime:n,matchUpId:o})}function g7({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,courtOrder:o,matchUpId:i}){return Yv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,courtOrder:o,matchUpId:i})}function oT({tournamentRecord:t,drawDefinition:e,disableNotice:r,participantId:n,officialType:o,matchUpId:i}){if(!n)return{error:Et};const{tournamentParticipants:s}=cr({tournamentRecord:t,participantFilters:{participantTypes:[Fe],participantRoles:[Qb]}});return Eo({tournamentParticipants:s,participantId:n})?NS({drawDefinition:e,disableNotice:r,participantId:n,officialType:o,matchUpId:i}):{error:jt}}var _7=Object.defineProperty,I7=Object.defineProperties,P7=Object.getOwnPropertyDescriptors,iT=Object.getOwnPropertySymbols,y7=Object.prototype.hasOwnProperty,S7=Object.prototype.propertyIsEnumerable,sT=(t,e,r)=>e in t?_7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ym=(t,e)=>{for(var r in e||(e={}))y7.call(e,r)&&sT(t,r,e[r]);if(iT)for(var r of iT(e))S7.call(e,r)&&sT(t,r,e[r]);return t},O7=(t,e)=>I7(t,P7(e));function aT({tournamentRecord:t,scheduleChange:e,matchUpIds:r,dryRun:n}){if(!t)return{error:re};if(!r||!Array.isArray(r))return{error:vl};if(typeof e!="object")return{error:X};const o=[],i=[],{minutesChange:s,daysChange:a}=e;if(!s&&!a)return ym({},V);if(s&&isNaN(s))return{error:X};if(a&&isNaN(a))return{error:X};const{matchUps:l}=Wt({matchUpFilters:{matchUpIds:r},tournamentRecord:t}),c=({matchUpStatus:P})=>!Yt.includes(P),u=l==null?void 0:l.filter(P=>yc({schedule:P.schedule})).filter(P=>c({matchUpStatus:P.matchUpStatus}));if(!(u!=null&&u.length))return ym({},V);const{tournamentInfo:p}=Sc({tournamentRecord:t}),{startDate:d,endDate:v}=p,f=u==null?void 0:u.reduce((P,y)=>{const{matchUpId:S,drawId:O}=y;return P[O]?P[O].push(S):P[O]=[S],P},{}),m=1440;for(const P of Object.keys(f)){const y=Jo({tournamentRecord:t,drawId:P});if(y.error)return y;const S=y.drawDefinition,O=f[P].filter(b=>r.includes(b));for(const b of O)if(b&&S){const w=u.find(C=>C.matchUpId===b),T=w==null?void 0:w.schedule,{scheduledTime:$,scheduledDate:N}=T;let E,A,U;if(!E&&a&&N){const C=Re(N);U=GL(C,a),E=new Date(U)<new Date(d)||new Date(U)>new Date(v)}if(s&&$){const C=Re($),D=Le(at($))+s;if(E=D<0||D>m,!E){const R=Or($,s);A=C&&U?`${U}T${R}`:R}}if(E)i.push(b);else{if(!n){if(A){const C=Pm({scheduledTime:A,drawDefinition:S,matchUpId:b});if(C.error)return C}if(U){const C=Im({scheduledDate:U,drawDefinition:S,matchUpId:b});if(C.error)return C}}(A||U)&&o.push(b)}}}const h=Wt({matchUpFilters:{matchUpIds:r},tournamentRecord:t}).matchUps||[],g=h.filter(({matchUpId:P})=>o.includes(P)),_=h.filter(({matchUpId:P})=>i.includes(P)),I=g.length&&!_.length;return O7(ym({},V),{rescheduled:g,notRescheduled:_,allRescheduled:I})}var b7=Object.defineProperty,T7=Object.defineProperties,w7=Object.getOwnPropertyDescriptors,lT=Object.getOwnPropertySymbols,E7=Object.prototype.hasOwnProperty,$7=Object.prototype.propertyIsEnumerable,cT=(t,e,r)=>e in t?b7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,N7=(t,e)=>{for(var r in e||(e={}))E7.call(e,r)&&cT(t,r,e[r]);if(lT)for(var r of lT(e))$7.call(e,r)&&cT(t,r,e[r]);return t},U7=(t,e)=>T7(t,w7(e));function A7({tournamentRecords:t,scheduleChange:e,matchUpIds:r,dryRun:n}){var o,i;if(!r||!Array.isArray(r))return{error:vl};if(typeof e!="object")return{error:X};const s=[];let a=[];for(const c of Object.values(t)){const u=aT({tournamentRecord:c,scheduleChange:e,matchUpIds:r,dryRun:n});if(u.error)return u;Array.isArray(u.notRescheduled)&&a.push(...u.notRescheduled);const p=gv(u.notRescheduled),d=[];(o=u.rescheduled)==null||o.forEach(v=>{const{matchUpId:f}=v;p.includes(f)&&d.push(f),s.push(v)}),d.length&&(a=((i=u==null?void 0:u.notRescheduled)==null?void 0:i.filter(({matchUpId:v})=>!d.includes(v)))||[])}const l=!!(s.length&&!a.length);return U7(N7({},V),{rescheduled:s,notRescheduled:a,allRescheduled:l})}function uT({tournamentRecord:t,dailyLimits:e}){return t?typeof e!="object"?{error:no}:Ei({extension:{name:ss,value:{dailyLimits:e}},tournamentRecord:t}):{error:re}}var C7=Object.defineProperty,dT=Object.getOwnPropertySymbols,M7=Object.prototype.hasOwnProperty,D7=Object.prototype.propertyIsEnumerable,pT=(t,e,r)=>e in t?C7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,j7=(t,e)=>{for(var r in e||(e={}))M7.call(e,r)&&pT(t,r,e[r]);if(dT)for(var r of dT(e))D7.call(e,r)&&pT(t,r,e[r]);return t};function R7({tournamentRecords:t,tournamentId:e,dailyLimits:r}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const n=Object.keys(t).filter(o=>!e||e===o);if(e&&!n.includes(e))return{error:X};for(const o of n){const i=t[o],s=uT({tournamentRecord:i,dailyLimits:r});if(s.error)return s}return j7({},V)}var F7=Object.defineProperty,x7=Object.defineProperties,L7=Object.getOwnPropertyDescriptors,fT=Object.getOwnPropertySymbols,V7=Object.prototype.hasOwnProperty,B7=Object.prototype.propertyIsEnumerable,vT=(t,e,r)=>e in t?F7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,k7=(t,e)=>{for(var r in e||(e={}))V7.call(e,r)&&vT(t,r,e[r]);if(fT)for(var r of fT(e))B7.call(e,r)&&vT(t,r,e[r]);return t},G7=(t,e)=>x7(t,L7(e));function W7({extensionConversions:t,seedAssignments:e,participant:r,withSeeding:n,seedValue:o,eventId:i,ranking:s,entry:a}){const{entryStatus:l,entryStage:c,entryPosition:u,extensions:p}=a,d=p!=null&&p.length?Object.assign({},...Pf(p)):{},v=Object.assign(d,G7(k7({},t),{entryPosition:u,entryStatus:l,entryStage:c,ranking:s,eventId:i}));r.events[i]=Oe(v,!1,!1,!0),n&&(e&&(r.events[i].seedAssignments=e),o&&(r.events[i].seedValue=o))}var H7=Object.defineProperty,q7=Object.defineProperties,z7=Object.getOwnPropertyDescriptors,mT=Object.getOwnPropertySymbols,Y7=Object.prototype.hasOwnProperty,K7=Object.prototype.propertyIsEnumerable,hT=(t,e,r)=>e in t?H7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Q7=(t,e)=>{for(var r in e||(e={}))Y7.call(e,r)&&hT(t,r,e[r]);if(mT)for(var r of mT(e))K7.call(e,r)&&hT(t,r,e[r]);return t},J7=(t,e)=>q7(t,z7(e));function gT(t){const{participantMap:e,participantId:r,matchUpStatus:n,roundPosition:o,structureId:i,matchUpType:s,roundNumber:a,matchUpId:l,potential:c,schedule:u,drawId:p,score:d}=t;if(!u||!Object.keys(u).length)return;n===nt||e[r].scheduleItems.push(J7(Q7({},u),{scheduledDate:Re(u==null?void 0:u.scheduledDate),scheduledTime:at(u==null?void 0:u.scheduledTime),scoreHasValue:Gt({score:d}),matchUpStatus:n,roundPosition:o,structureId:i,matchUpType:s,roundNumber:a,matchUpId:l,potential:c,drawId:p}))}function Z7({finishingPositionRange:t={},participantMap:e,finishingRound:r,participantWon:n,matchUpStatus:o,participantId:i,stageSequence:s,roundNumber:a,structureId:l,matchUpId:c,drawId:u,stage:p}){const d=e[i],v=_=>Math.abs(_[0]-_[1]);d.structureParticipation[l]||(d.structureParticipation[l]={rankingStage:p,walkoverWinCount:0,defaultWinCount:0,stageSequence:s,winCount:0,structureId:l,drawId:u});const f=d.structureParticipation[l],{winner:m,loser:h}=t,g=n?m:h;n&&(f.winCount+=1,o===ot&&(f.walkoverWinCount+=1),o===Xe&&(f.defaultWinCount+=1)),g&&(!f.finishingPositionRange||v(g)<v(f.finishingPositionRange))&&(f.finishingPositionRange=g),r&&((!f.finishingRound||r<f.finishingRound)&&(f.finishingMatchUpId=c,f.finishingRound=r,f.roundNumber=a),r===1&&(f.participantWon=n))}function _T(t){var e,r,n,o,i,s,a,l,c,u;const{withScheduleTimes:p,scheduleAnalysis:d,withTeamMatchUps:v,participantMap:f,withOpponents:m,withMatchUps:h,withEvents:g,withDraws:_,finishingPositionRange:I,finishingRound:P,matchUpStatus:y,stageSequence:S,roundNumber:O,structureId:b,score:w,stage:T,withRankingProfile:$,tieWinningSide:N,roundPosition:E,matchUpTieId:A,matchUpSides:U,collectionId:C,matchUpType:M,winningSide:D,matchUpId:R,schedule:j,eventId:G,drawId:W,sides:q}=t,F=m&&(q==null?void 0:q.length)===2&&Object.assign({},...q.map(({sideNumber:L},x)=>{const B=q[1-x].participantId;return L&&{[L]:B}}).filter(Boolean));for(const L of q){const{participantId:x,sideNumber:B,bye:z}=L;if(z)continue;const H=D===B,Y=J=>{var te,ne;const ee=(te=f[J])==null?void 0:te.participant,oe=ee==null?void 0:ee.participantType,ie=[{participantId:J,participantType:oe}];if(oe!==zn)for(const ae of(ee==null?void 0:ee.individualParticipantIds)||[]){const se=(ne=f[ae])==null?void 0:ne.participant;ie.push({participantType:se==null?void 0:se.participantType,participantId:ae})}return ie},Z=(J,te)=>{if(h){if(f[J].matchUps[R]={participantWon:H,matchUpType:M,structureId:b,sideNumber:B,matchUpId:R,eventId:G,drawId:W},m){const ne=Y(te);f[J].matchUps[R].opponentParticipantInfo=ne}C&&(f[J].matchUps[R].collectionId=C)}$&&Z7({finishingPositionRange:I,participantMap:f,participantWon:H,finishingRound:P,matchUpStatus:y,participantId:J,stageSequence:S,roundNumber:O,structureId:b,matchUpId:R,drawId:W,stage:T}),(d||p)&&gT({participantMap:f,participantId:J,matchUpStatus:y,roundPosition:E,matchUpType:M,roundNumber:O,structureId:b,matchUpId:R,schedule:j,drawId:W,score:w})},K=(J,te)=>{J&&(J.partnerParticipantIds||(J.partnerParticipantIds=[]),J.partnerParticipantIds.includes(te)||J.partnerParticipantIds.push(te))},Q=({participantId:J,partnerParticipantId:te})=>{var ne,ee,oe,ie,ae,se;_&&K((ee=(ne=f[J])==null?void 0:ne.draws)==null?void 0:ee[W],te),g&&K((ie=(oe=f[J])==null?void 0:oe.events)==null?void 0:ie[G],te),h&&K((se=(ae=f[J])==null?void 0:ae.matchUps)==null?void 0:se[R],te)};if(x&&f[x]){const J=F==null?void 0:F[B];Z(x,J),m&&J&&(f[x].opponents[J]={participantId:J,matchUpId:R,eventId:G,drawId:W});const te=((e=f[x])==null?void 0:e.participant.participantType)===Ce,ne=((r=f[x])==null?void 0:r.participant.individualParticipantIds)||[];if(A){if(v){const ee=oe=>f[oe].matchUps[A]={participantWon:N===B,matchUpType:Cr.Team,matchUpId:A,sideNumber:B};ee(x),ne.forEach(ee)}if(_&&!f[x].draws[W]){const ee=(o=(n=U.find(ae=>ae.sideNumber===B))==null?void 0:n.participant)==null?void 0:o.participantId,oe=(a=(s=(i=f[ee])==null?void 0:i.draws)==null?void 0:s[W])==null?void 0:a.entryStatus,ie=ae=>f[ae].draws[W]={entryStatus:oe,eventId:G,drawId:W};ie(x),ne.forEach(ie)}}if(te&&(ne.forEach(ee=>f[ee]&&Z(ee,J)),ne.forEach((ee,oe)=>{const ie=ne[1-oe];Q({participantId:ee,partnerParticipantId:ie})}),g&&U)){const ee=(c=(l=U.find(oe=>oe.sideNumber===B))==null?void 0:l.participant)==null?void 0:c.participantId;if(ee){const oe=(u=f[ee])==null?void 0:u.events[G];oe?(f[x].events[G]=oe,ne.forEach(ie=>f[ie].events[G]=oe)):console.log("Missing teamEntry",{eventId:G,teamParticipantId:ee})}}if(D){const ee=oe=>{H?(f[oe].counters[M].wins+=1,f[oe].counters.wins+=1,y===ot&&(f[oe].counters[M].walkoverWins+=1,f[oe].counters.walkoverWins+=1),y===Xe&&(f[oe].counters[M].defaultWins+=1,f[oe].counters.defaultWins+=1)):(f[oe].counters[M].losses+=1,f[oe].counters.losses+=1,y===ot&&(f[oe].counters[M].walkovers+=1,f[oe].counters.walkovers+=1),y===Xe&&(f[oe].counters[M].defaults+=1,f[oe].counters.defaults+=1))};ee(x),ne.forEach(ee)}}}}var X7=Object.defineProperty,eK=Object.defineProperties,tK=Object.getOwnPropertyDescriptors,IT=Object.getOwnPropertySymbols,rK=Object.prototype.hasOwnProperty,nK=Object.prototype.propertyIsEnumerable,PT=(t,e,r)=>e in t?X7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ha=(t,e)=>{for(var r in e||(e={}))rK.call(e,r)&&PT(t,r,e[r]);if(IT)for(var r of IT(e))nK.call(e,r)&&PT(t,r,e[r]);return t},Cd=(t,e)=>eK(t,tK(e));function oK(t){var e,r,n,o,i;const{participantFilters:s,convertExtensions:a,policyDefinitions:l,tournamentRecord:c,usePublishState:u,contextProfile:p,participantMap:d,withPotentialMatchUps:v,withRankingProfile:f,withScheduleTimes:m,withScheduleItems:h,scheduleAnalysis:g,withTeamMatchUps:_,withStatistics:I,withOpponents:P,withMatchUps:y,withSeeding:S,withEvents:O,withDraws:b}=t;h&&console.log({withScheduleItems:h});const w=s==null?void 0:s.participantIds,T=R=>{var j,G;const W=[R];return W.push(R),(G=(j=d[R])==null?void 0:j.participant.individualParticipantIds)==null||G.forEach(q=>W.push(q)),W.some(q=>!(w!=null&&w.length)||w.includes(q.relevantParticipantId))?W:[]},$={withMatchUps:y||f,withEvents:O||f,withDraws:b||f,withPotentialMatchUps:v,withRankingProfile:f,withScheduleTimes:m,scheduleAnalysis:g,withTeamMatchUps:_,withStatistics:I,participantMap:d,withOpponents:P,withSeeding:S},N=[],E={},A=[],U={},C={},M={},D=({eventType:R,scaleNames:j,participantId:G})=>{var W,q,F,L;return(L=(F=(q=(W=d[G].participant)==null?void 0:W.rankings)==null?void 0:q[R])==null?void 0:F.find(x=>j.includes(x.scaleName)))==null?void 0:L.scaleValue};for(const R of(c==null?void 0:c.events)||[]){if(s!=null&&s.eventIds&&!s.eventIds.includes(R.eventId))continue;const{drawDefinitions:j=[],extensions:G,eventType:W,eventName:q,category:F,entries:L,eventId:x,gender:B}=R,{flightProfile:z}=Nt({event:R}),H=z==null?void 0:z.flights,Y=TY({event:R}),Z=Y==null?void 0:Y.publishedSeeding;if(Y&&(U[x]=Y),O||S||f){const K=a?Object.assign({},...Pf(G)):{};C[x]=Cd(Ha({},K),{eventName:q,eventType:W,category:F,eventId:x,gender:B});const Q=[F==null?void 0:F.categoryName,F==null?void 0:F.ageCategoryCode].filter(Boolean);for(const J of L){const{participantId:te}=J;if(!te||!d[te])continue;const ne=D({eventType:W,scaleNames:Q,participantId:te});let ee,oe;if(S){const se=d[te].participant;({seedAssignments:ee,seedValue:oe}=wY({publishedSeeding:Z,usePublishState:u,withSeeding:S,participant:se,event:R}))}const ie=se=>{var ye;if((ye=d[se])!=null&&ye.events[x])return;const Ie=d[se];W7({extensionConversions:K,seedAssignments:ee,participant:Ie,withSeeding:S,seedValue:oe,eventId:x,ranking:ne,entry:J})};ie(te),(d[te].participant.individualParticipantIds||[]).forEach(ie)}}if(b||f||S){const K=Q=>Q?Object.assign({},...Q.map(J=>({[J.participantId]:J}))):void 0;for(const Q of j){const{structures:J=[],drawOrder:te,drawName:ne,drawType:ee,entries:oe,drawId:ie}=Q,ae=(e=H==null?void 0:H.find($e=>$e.drawId===ie))==null?void 0:e.flightNumber,se=[F==null?void 0:F.categoryName,F==null?void 0:F.ageCategoryCode].filter(Boolean),ye=(Q.structures||[]).sort(($e,De)=>Ri($e,De)).map(({structureId:$e,structures:De})=>[$e,...(De||[]).map(({structureId:me})=>me)]).flat(1/0);let Ie,pe,fe,ve,le=0;const be=J.filter(({stage:$e,stageSequence:De})=>$e===he&&De===1||$e===we).flatMap($e=>{const{seedAssignments:De,stageSequence:me,stage:ge}=$e,{positionAssignments:Se}=st({structure:$e});return ge===he?(le=(Se==null?void 0:Se.length)||0,fe=Se,ve=De):me===1&&(Ie=Se,pe=De),Se}).map(({participantId:$e})=>$e).filter(Boolean),Me=K(ve),Pe=K(pe),xe=oe.filter(({participantId:$e})=>be.includes($e)),Be=(r=U[x])==null?void 0:r.publishedSeeding,qe=!u||(Be==null?void 0:Be.published)&&(((n=Be==null?void 0:Be.drawIds)==null?void 0:n.length)===0||((o=Be==null?void 0:Be.drawIds)==null?void 0:o.includes(ie)));for(const $e of xe){const{entryStatus:De,entryStage:me,entryPosition:ge,participantId:Se}=$e,Ee=D({participantId:Se,scaleNames:se,eventType:W}),Ae=je=>{var gt,rt,yt,St;if(d[je].draws[ie])return;const ze=S&&qe,_t=ze?{}:void 0,Ve=ze?((gt=Me==null?void 0:Me[Se])==null?void 0:gt.seedValue)||((rt=Me==null?void 0:Me[Se])==null?void 0:rt.seedNumber):void 0,It=ze?((yt=Pe==null?void 0:Pe[Se])==null?void 0:yt.seedValue)||((St=Pe==null?void 0:Pe[Se])==null?void 0:St.seedNumber):void 0;_t&&Ve&&(_t[he]=Ve),_t&&It&&(_t[we]=Ve),(O||f)&&(ze?d[je].events[x].seedValue=Ve||It:d[je].events[x].seedValue&&(d[je].events[x].seedValue=void 0)),(b||f)&&(d[je].draws[ie]=Oe({seedAssignments:_t,entryPosition:ge,entryStatus:De,entryStage:me,eventId:x,ranking:Ee,drawId:ie},!1,!1,!0))};if(![En,ys].includes(De)){Ae(Se);const je=d[Se].participant.individualParticipantIds||[];je==null||je.forEach(Ae)}}M[ie]={qualifyingPositionAssignments:Ie,qualifyingSeedAssignments:pe,mainPositionAssignments:fe,qualifyingSeedingMap:Pe,mainSeedAssignments:ve,orderedStructureIds:ye,mainSeedingMap:Me,flightNumber:ae,drawOrder:te,drawName:ne,drawType:ee,drawSize:le,drawId:ie}}}if(f||g||_||I||P||y||b){const K=!!g||v,Q=((i=ai({afterRecoveryTimes:!!g,policyDefinitions:l,tournamentRecord:c,inContext:!0,contextProfile:p,participantMap:d,nextMatchUps:K,event:R}))==null?void 0:i.matchUps)||[];for(const J of Q){const{finishingPositionRange:te,potentialParticipants:ne,tieMatchUps:ee=[],sides:oe=[],winningSide:ie,matchUpType:ae,matchUpId:se,eventId:ye,drawId:Ie,collectionId:pe,stageSequence:fe,finishingRound:ve,matchUpStatus:le,roundPosition:be,roundNumber:Me,structureId:Pe,schedule:xe,score:Be,stage:qe}=J;E[se]=J;const $e={finishingPositionRange:te,finishingRound:ve,stageSequence:fe,roundPosition:be,collectionId:pe,roundNumber:Me,structureId:Pe,schedule:xe,eventId:ye,drawId:Ie,score:Be,stage:qe};_T(Cd(Ha(Ha({},$e),$),{matchUpStatus:le,winningSide:ie,matchUpType:ae,matchUpId:se,sides:oe}));for(const De of ee){const{winningSide:me,sides:ge=[],matchUpId:Se,matchUpStatus:Ee,matchUpType:Ae}=De;_T(Cd(Ha(Ha({},$e),$),{winningSide:me,tieWinningSide:ie,matchUpTieId:se,matchUpId:Se,sides:ge,matchUpSides:oe,matchUpStatus:Ee,matchUpType:Ae}))}if(Array.isArray(ne)&&(K||g||m)){const De=ne.flat().map(Fn("participantId")).filter(Boolean);De==null||De.forEach(me=>{const ge=T(me);ge==null||ge.forEach(Se=>{d[Se]&&(d[Se].potentialMatchUps[se]=Oe({tournamentId:c==null?void 0:c.tournamentId,matchUpId:se,eventId:ye,drawId:Ie}))}),(g||m)&&gT({potential:!0,participantMap:d,participantId:me,matchUpStatus:le,roundPosition:be,structureId:Pe,matchUpType:ae,roundNumber:Me,matchUpId:se,schedule:xe,drawId:Ie,score:Be})})}}A.push(...Q)}}if(I||f||g){const R=Object.values(d);for(const j of R){const{wins:G,losses:W,[At]:{wins:q,losses:F},[dt]:{wins:L,losses:x}}=j.counters,B=(z,H,Y)=>{const Z=H+Y,K=H,Q=Z&&K/Z;j.statistics[z]={denominator:Z,numerator:K,statValue:Q,statCode:z}};if(I&&(B($l,G,W),B(`${$l}.${At}`,q,F),B(`${$l}.${dt}`,L,x)),f){const z=(H=[])=>Math.abs(H[0]-H[1]);for(const H of Object.keys(j.draws)){const{orderedStructureIds:Y=[],flightNumber:Z}=M[H]||{};if(j.structureParticipation&&Y.length){let K,Q=0;const J=Y.map(te=>{const ne=j.structureParticipation[te];if(!ne)return;K||(K=ne.finishingPositionRange),z(K)>z(ne.finishingPositionRange)&&(K=ne.finishingPositionRange);const ee=ne.stage!==we;ee&&(Q+=1);const oe=ee?Q:void 0;return Oe(Cd(Ha({},ne),{participationOrder:oe,flightNumber:Z}))}).filter(Boolean);j.draws[H].finishingPositionRange=K,j.draws[H].structureParticipation=J}}}if(g){const z=rs(g)?g.scheduledMinutesDifference:0,H=j.scheduleItems||[],Y=j.potentialMatchUps||{},Z=H.reduce((Q,J)=>{const{scheduledDate:te,scheduledTime:ne}=J;return Q[te]||(Q[te]=[]),ne&&Q[te].push(J),Q},{});Object.values(Z).forEach(Q=>Q.sort(j_));for(const Q of H){const{typeChangeTimeAfterRecovery:J,timeAfterRecovery:te,scheduledDate:ne,scheduledTime:ee}=Q,oe=Z[ne],ie=Le(ee);for(const ae of oe){if(ae.matchUpId===Q.matchUpId||[ot,Xe].includes(ae.matchUpStatus)&&!ae.scoreHasValue)continue;const Ie=Q.matchUpType!==ae.matchUpType&&J||te,pe=Q.drawId===ae.drawId,fe=Y[Q.matchUpId]&&Y[ae.matchUpId],ve=Le(ae.scheduledTime),le=Math.abs(ve-ie);(z&&!isNaN(z)?le<=z:Le(Ie)>Le(ae.scheduledTime))&&!(fe&&pe)&&j.scheduleConflicts.push({priorScheduledMatchUpId:ae.matchUpId,matchUpIdWithConflict:Q.matchUpId})}}const K=j.participant.participantId;j.scheduleConflicts.length&&N.push(K),d[K].scheduleConflicts=j.scheduleConflicts}}}return{participantIdsWithConflicts:N,eventsPublishStatuses:U,derivedEventInfo:C,derivedDrawInfo:M,mappedMatchUps:E,participantMap:d,matchUps:A}}var iK=Object.defineProperty,sK=Object.defineProperties,aK=Object.getOwnPropertyDescriptors,yT=Object.getOwnPropertySymbols,lK=Object.prototype.hasOwnProperty,cK=Object.prototype.propertyIsEnumerable,ST=(t,e,r)=>e in t?iK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,OT=(t,e)=>{for(var r in e||(e={}))lK.call(e,r)&&ST(t,r,e[r]);if(yT)for(var r of yT(e))cK.call(e,r)&&ST(t,r,e[r]);return t},bT=(t,e)=>sK(t,aK(e));function Ls(t){const{withIndividualParticipants:e,participantFilters:r={},withPotentialMatchUps:n,withRankingProfile:o,convertExtensions:i,policyDefinitions:s,withScheduleItems:a,tournamentRecord:l,scheduleAnalysis:c,withSignInStatus:u,withTeamMatchUps:p,withScaleValues:d,usePublishState:v,contextProfile:f,withStatistics:m,withOpponents:h,withMatchUps:g,internalUse:_,withSeeding:I,withEvents:P,withDraws:y,withISO2:S,withIOC:O}=t;if(!l)return{error:re};(g||o)&&cn({tournamentRecord:l});let{participantMap:b}=k0({withIndividualParticipants:e,convertExtensions:i,policyDefinitions:s,tournamentRecord:l,withSignInStatus:u,withScaleValues:d,internalUse:_,withISO2:S,withIOC:O});const w=oK({withMatchUps:g||o,withEvents:P||o,withDraws:y||o,withPotentialMatchUps:n,participantFilters:r,withRankingProfile:o,convertExtensions:i,withScheduleItems:a,policyDefinitions:s,tournamentRecord:l,scheduleAnalysis:c,withTeamMatchUps:p,usePublishState:v,withStatistics:m,participantMap:b,withOpponents:h,contextProfile:f,withSeeding:I}),{participantIdsWithConflicts:T,eventsPublishStatuses:$,derivedEventInfo:N,derivedDrawInfo:E,mappedMatchUps:A}=w,U=w.matchUps;b=w.participantMap;const C=c||n,M=Object.values(b).map(({potentialMatchUps:R,scheduleConflicts:j,participant:G,statistics:W,opponents:q,matchUps:F,events:L,draws:x})=>{const B=Object.values(x),z=Object.values(q);return h&&(B==null||B.forEach(H=>{H.opponents=z.filter(Y=>Y.drawId===H.drawId)})),Oe(bT(OT({},G),{scheduleConflicts:c?j:void 0,draws:y||o?B:void 0,events:P||o?Object.values(L):void 0,matchUps:g||o?Object.values(F):void 0,opponents:h?z:void 0,potentialMatchUps:C?Object.values(R):void 0,statistics:m?Object.values(W):void 0}),!1,!1,!0)}),D=Ad({participants:M,participantFilters:r,tournamentRecord:l});return bT(OT({participantIdsWithConflicts:T,eventsPublishStatuses:$,derivedEventInfo:N,derivedDrawInfo:E,mappedMatchUps:A,participantMap:b,participants:D},V),{matchUps:U})}function Sm(t,e,r){return!t&&e?e:t&&!e||typeof t!="object"||typeof e!="object"?t:We(Object.keys(t).concat(Object.keys(e))).reduce((o,i)=>{if(!e[i])o[i]=t[i];else if(!t[i])o[i]=e[i];else if(typeof t[i]!=typeof e[i])o[i]=e[i];else if(Array.isArray(t[i]))if(r===!0||Array.isArray(r)&&r.includes(i)){const s=We(t[i].map(a=>JSON.stringify(a)).concat(e[i].map(a=>JSON.stringify(a)))).map(a=>JSON.parse(a));o[i]=s}else o[i]=e[i];else typeof t[i]=="object"?o[i]=Sm(t[i],e[i],r):o[i]=e[i];return o},{})}var uK=Object.defineProperty,dK=Object.defineProperties,pK=Object.getOwnPropertyDescriptors,TT=Object.getOwnPropertySymbols,fK=Object.prototype.hasOwnProperty,vK=Object.prototype.propertyIsEnumerable,wT=(t,e,r)=>e in t?uK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Oc=(t,e)=>{for(var r in e||(e={}))fK.call(e,r)&&wT(t,r,e[r]);if(TT)for(var r of TT(e))vK.call(e,r)&&wT(t,r,e[r]);return t},mK=(t,e)=>dK(t,pK(e));function hK(t){const{tournamentRecords:e}=t||{};if(typeof e!="object"||!Object.keys(e).length)return{error:ke};const r={},n=[],o={},i={},s=[],a={},l=[];for(const c of Object.values(e)){const{participantIdsWithConflicts:u,mappedMatchUps:p,participantMap:d,participants:v,matchUps:f,derivedEventInfo:m,derivedDrawInfo:h}=Ls(Oc({tournamentRecord:c},t));Object.assign(a,p),Object.assign(r,d),Object.assign(o,m),Object.assign(i,h),n.push(...v??[]),s.push(...f??[]),u==null||u.forEach(g=>{l.includes(g)||l.push(g)})}return mK(Oc({participantIdsWithConflicts:l,derivedEventInfo:o,derivedDrawInfo:i,participantMap:r,mappedMatchUps:a,participants:n},V),{matchUps:s})}function gK(t){const{tournamentRecords:e}=t||{};if(typeof e!="object"||!Object.keys(e).length)return{error:ke};let r=[];const n=[],o=[];for(const i of Object.values(e)){const{tournamentParticipants:s,participantIdsWithConflicts:a}=cr(Oc({tournamentRecord:i},t));for(const l of s){const{participantId:c}=l;o.includes(c)?r=r.map(u=>u.participantId!==c?u:Sm(u,l,!0)):(o.push(c),r.push(l))}a==null||a.forEach(l=>{n.includes(l)||n.push(l)})}return Oc({competitionParticipants:r,participantIdsWithConflicts:n},V)}function ET({policyDefinitions:t,tournamentRecords:e,participantId:r,inContext:n,personId:o}){if(!e)return{error:ke};if(typeof r!="string"&&typeof o!="string")return{error:_e,stack:"publicFindParticipant"};let i,s;for(const a of Object.values(e)){s=a.tournamentId;const{tournamentParticipants:l}=cr({policyDefinitions:t,tournamentRecord:a,inContext:n});if(i=Eo({tournamentParticipants:l,internalUse:!0,policyDefinitions:t,participantId:r,personId:o}),i)break}return Oc({participant:i,tournamentId:s},V)}const $T=({penaltyId:t=Ye()}={})=>({refereeParticipantId:void 0,penaltyCode:void 0,penaltyType:void 0,extensions:void 0,matchUpId:void 0,createdAt:void 0,issuedAt:void 0,notes:void 0,penaltyId:t});var _K=Object.defineProperty,IK=Object.defineProperties,PK=Object.getOwnPropertyDescriptors,NT=Object.getOwnPropertySymbols,yK=Object.prototype.hasOwnProperty,SK=Object.prototype.propertyIsEnumerable,UT=(t,e,r)=>e in t?_K(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Md=(t,e)=>{for(var r in e||(e={}))yK.call(e,r)&&UT(t,r,e[r]);if(NT)for(var r of NT(e))SK.call(e,r)&&UT(t,r,e[r]);return t},Dd=(t,e)=>IK(t,PK(e));function AT({refereeParticipantId:t,tournamentRecord:e,participantIds:r,penaltyCode:n,penaltyType:o,extensions:i,penaltyId:s,matchUpId:a,issuedAt:l,notes:c}){if(!e)return{error:re};if(!r)return{error:Et};if(!o)return{error:Fx};const p=((e==null?void 0:e.participants)||[]).filter(f=>r.includes(f.participantId));if(!p.length)return{error:jt};const d=new Date().toISOString(),v=Object.assign($T({penaltyId:s}),{refereeParticipantId:t,penaltyCode:n,penaltyType:o,matchUpId:a,notes:c,issuedAt:l,createdAt:d});return Array.isArray(i)&&i.forEach(f=>it({element:v,extension:f})),p.forEach(f=>{f.penalties||(f.penalties=[]),f.penalties.push(v)}),He({topic:rr,payload:{tournamentId:e.tournamentId,participants:p}}),Dd(Md({},V),{penaltyId:v.penaltyId})}function CT({tournamentRecord:t,penaltyId:e}){if(!t)return{error:re};if(!e)return{error:f_};const r=(t==null?void 0:t.participants)||[],n=[];let o=!1,i;return r.forEach(s=>{let a=!1;s.penalties=(s.penalties||[]).filter(l=>(l.penaltyId===e&&(a=!0,o||(i=l,o=!0)),a&&n.push(s),l.penaltyId!==e))}),i&&He({topic:rr,payload:{tournamentId:t.tournamentId,participants:n}}),i?Dd(Md({},V),{penalty:i}):{error:tu}}function MT({tournamentRecord:t}){if(!t)return{error:re};const r=((t==null?void 0:t.participants)||[]).reduce((n,o)=>{const{participantId:i}=o;return(o.penalties||[]).forEach(s=>{const{penaltyId:a}=s||{};n[a]?n[a].participants.push(i):n[a]=Dd(Md({},s),{participantIds:[i]})}),n},{});return{penalties:Object.values(r)}}function DT({tournamentRecord:t,modifications:e,penaltyId:r}){if(!t)return{error:re};if(!e)return{error:X,modifications:e};if(!r)return{error:f_};const n=(t==null?void 0:t.participants)||[],o=Object.keys($T()).filter(l=>l!=="penaltyId"),i=Object.keys(e).filter(l=>o.includes(l));if(!i.length)return{error:ff};let s;const a=[];return n.forEach(l=>{let c=!1;l.penalties=(l.penalties||[]).map(u=>(u.penaltyId===r&&(c=!0,i.forEach(p=>Object.assign(u,{[p]:e[p]})),s||(s=u)),u)),c&&a.push(l)}),s&&He({topic:rr,payload:{tournamentId:t.tournamentId,participants:a}}),s?Dd(Md({},V),{penalty:s}):{error:tu}}var OK=Object.defineProperty,bK=Object.defineProperties,TK=Object.getOwnPropertyDescriptors,jT=Object.getOwnPropertySymbols,wK=Object.prototype.hasOwnProperty,EK=Object.prototype.propertyIsEnumerable,RT=(t,e,r)=>e in t?OK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qa=(t,e)=>{for(var r in e||(e={}))wK.call(e,r)&&RT(t,r,e[r]);if(jT)for(var r of jT(e))EK.call(e,r)&&RT(t,r,e[r]);return t},FT=(t,e)=>bK(t,TK(e));function $K(t){const{tournamentRecords:e,participantIds:r}=t;let n;for(const o of Object.values(e)){const{tournamentParticipants:i}=cr({tournamentRecord:o}),s=oc(i).filter(a=>r.includes(a));s.length&&(n=AT(FT(qa({},t),{penaltyId:t.penaltyId||n,tournamentRecord:o,participantIds:s})).penaltyId)}return n?FT(qa({},V),{penaltyId:n}):{error:jt}}function NK(t){const{tournamentRecords:e}=t;if(typeof e!="object"||!Object.keys(e).length)return{error:ke};for(const r of Object.values(e)){const n=DT(qa({tournamentRecord:r},t));if(n.error&&n.error!==tu)return n}return qa({},V)}function UK(t){const{tournamentRecords:e}=t;if(typeof e!="object"||!Object.keys(e).length)return{error:ke};for(const r of Object.values(e)){const n=CT(qa({tournamentRecord:r},t));if(n.error&&n.error!==tu)return n}return qa({},V)}function AK({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const e=[];for(const r of Object.values(t)){const{penalties:n}=MT({tournamentRecord:r});e.push(...n||[])}return{penalties:e}}const CK={addExtension:Wf,findExtension:bu,removeExtension:Tu,addEventExtension:YB,linkTournaments:ZB,unlinkTournament:ek,unlinkTournaments:XB,getLinkedTournamentIds:Hf,addDrawDefinition:gY,getCompetitionParticipants:gK,getParticipants:hK,addParticipant:bY,courtGridRows:Pb,setMatchUpStatus:uY,bulkMatchUpStatusUpdate:dY,bulkScheduleMatchUps:LS,addPenalty:$K,removePenalty:UK,modifyPenalty:NK,getCompetitionPenalties:AK,findParticipant:ET};var MK=Object.defineProperty,xT=Object.getOwnPropertySymbols,DK=Object.prototype.hasOwnProperty,jK=Object.prototype.propertyIsEnumerable,LT=(t,e,r)=>e in t?MK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,VT=(t,e)=>{for(var r in e||(e={}))DK.call(e,r)&&LT(t,r,e[r]);if(xT)for(var r of xT(e))jK.call(e,r)&&LT(t,r,e[r]);return t};function BT({removePriorValues:t=!0,tournamentRecord:e,status:r=qn}){if(!e)return{error:re};const n=`${Hr}.${qr}`,{timeItem:o}=Zu({tournamentRecord:e,itemType:n}),i=(o==null?void 0:o.itemValue)||{[r]:{}};return i[r]&&delete i[r].orderOfPlay,Fo({timeItem:{itemValue:i,itemType:n},removePriorValues:t,tournamentRecord:e}),He({topic:mP,payload:{tournamentId:e.tournamentId}}),VT({},V)}function kT({scheduledDates:t=[],removePriorValues:e,tournamentRecord:r,status:n=qn,eventIds:o=[]}){if(!r)return{error:re};const i=`${Hr}.${qr}`,{timeItem:s}=Zu({tournamentRecord:r,itemType:i}),a=(s==null?void 0:s.itemValue)||{[n]:{}};return a[n].orderOfPlay={published:!0,scheduledDates:t,eventIds:o},Fo({timeItem:{itemValue:a,itemType:i},removePriorValues:e,tournamentRecord:r}),He({topic:fk,payload:{tournamentId:r.tournamentId,scheduledDates:t,eventIds:o}}),VT({},V)}var RK=Object.defineProperty,GT=Object.getOwnPropertySymbols,FK=Object.prototype.hasOwnProperty,xK=Object.prototype.propertyIsEnumerable,WT=(t,e,r)=>e in t?RK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jd=(t,e)=>{for(var r in e||(e={}))FK.call(e,r)&&WT(t,r,e[r]);if(GT)for(var r of GT(e))xK.call(e,r)&&WT(t,r,e[r]);return t};function LK(t){const e=t==null?void 0:t.tournamentRecords;if(!e)return{error:ke};for(const r of Object.values(e)){const n=BT(jd({tournamentRecord:r},t));if(n.error)return n}return jd({},V)}function VK(t){const e=t==null?void 0:t.tournamentRecords;if(!e)return{error:ke};for(const r of Object.values(e)){const n=kT(jd({tournamentRecord:r},t));if(n.error)return n}return jd({},V)}const BK={unPublishOrderOfPlay:LK,publishOrderOfPlay:VK};function HT({tournamentRecords:t,extensionName:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const r=[];let n;for(const o of Object.values(t)){const{extension:i}=Fr({name:e,tournamentRecord:o});i&&!n&&(r.push({method:"addExtension",params:{extension:i}}),n=!0);const s=o.events||[];for(const a of s){const{eventId:l}=a,{extension:c}=$o({name:e,event:a});c&&r.push({params:{eventId:l,extension:c},method:"addEventExtension"})}}return{methods:r}}function kK({tournamentRecords:t}){return HT({extensionName:Wn,tournamentRecords:t})}var GK=Object.defineProperty,WK=Object.defineProperties,HK=Object.getOwnPropertyDescriptors,qT=Object.getOwnPropertySymbols,qK=Object.prototype.hasOwnProperty,zK=Object.prototype.propertyIsEnumerable,zT=(t,e,r)=>e in t?GK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,YK=(t,e)=>{for(var r in e||(e={}))qK.call(e,r)&&zT(t,r,e[r]);if(qT)for(var r of qT(e))zK.call(e,r)&&zT(t,r,e[r]);return t},KK=(t,e)=>WK(t,HK(e));function YT({tournamentRecord:t,matchUpFormats:e,categoryType:r,event:n}){if(!t)return{error:re};if(!n)return{error:Ge};let o=[];if(e!=null&&e.length){const u=[];o=e.map(p=>{const d=typeof p=="string"?{matchUpFormat:p}:p;if(!u.includes(d==null?void 0:d.matchUpFormat)&&Xr(d==null?void 0:d.matchUpFormat))return u.push(d.matchUpFormat),d}).filter(Boolean)}else{const{policy:u}=cs({policyType:da,tournamentRecord:t,event:n});if(u!=null&&u.matchUpFormats)o=u==null?void 0:u.matchUpFormats;else{const{extension:p}=$o({name:Wn,event:n});if(p!=null&&p.value)o=We([...(p.value.matchUpAverageTimes||[]).map(d=>d.matchUpFormatCodes),...(p.value.matchUpRecoveryTimes||[]).map(d=>d.matchUpFormatCodes)].flat()).map(d=>({matchUpFormat:d}));else return{error:_x}}}const{eventType:i,eventId:s,category:a}=n,l=(a==null?void 0:a.categoryName)||(a==null?void 0:a.ageCategoryCode)||s;return s?{eventMatchUpFormatTiming:o.map(({matchUpFormat:u,description:p})=>{const d=Lf({tournamentRecord:t,matchUpFormat:u,categoryName:l,categoryType:r,eventType:i,event:n});return Object.assign({},KK(YK({},d),{description:p,matchUpFormat:u}))})}:{error:Ge}}function QK({tournamentRecords:t,matchUpFormats:e,categoryType:r,tournamentId:n,eventId:o}){if(!o)return{error:Ge};const i=Object.keys(t).filter(c=>!n||c===n);if(n&&!i.length)return{error:X};let s,a,l;return i.forEach(c=>{const u=t[c],{event:p}=Qt({tournamentRecord:u,eventId:o});if(!p)return!1;l=!0;const{eventMatchUpFormatTiming:d,error:v}=YT({tournamentRecord:u,matchUpFormats:e,categoryType:r,event:p});v&&(a=v),s=d}),!l&&{error:Ar}||a&&{error:a}||{eventMatchUpFormatTiming:s}}function Rd({tournamentRecords:t,schedulingProfile:e}){if(!e)return{valid:!0};if(!Array.isArray(e))return{valid:!1,error:X};const{venueIds:r,tournamentsMap:n}=JK({tournamentRecords:t});let o,i;const s=e.every(a=>{const{scheduleDate:l,venues:c}=a;return Gr(l)?c.every(u=>{const{venueId:p,rounds:d}=u;return typeof p!="string"?(i="venueId should be a string",!1):Array.isArray(d)?r.includes(p)?!!d.every(f=>{var m,h,g;if(!f)return i="empty round",!1;const{roundSegment:_,tournamentId:I,structureId:P,roundNumber:y,eventId:S,drawId:O}=f,b=(g=(h=(m=n==null?void 0:n[I])==null?void 0:m[S])==null?void 0:h[O])==null?void 0:g[P],w=b==null?void 0:b.includes(y);w||(i="Invalid rounds");const{segmentNumber:T,segmentsCount:$}=_||{},N=!_||ht(T)&&Zr($)&&T<=$;return N||(i="Invalid segment"),w&&N}):(o=Ii,!1):(i="rounds should be an array",!1)}):!1});return!s&&!o&&(o=X),{valid:!!s,error:o,info:i}}function KT(t){const{tournamentRecord:e={},tournamentMap:r={},requireCourts:n}=t,o=[],i=[],s=[],a=[],l=((e==null?void 0:e.venues)||[]).map(({venueId:u,courts:p})=>(!n||(p==null?void 0:p.length))&&u),c=e==null?void 0:e.tournamentId;return c&&(o.push(c),r[c]={},((e==null?void 0:e.events)||[]).forEach(p=>{const d=p.eventId;s.push(d),r[c][d]={},(p.drawDefinitions||[]).forEach(v=>{const f=v.drawId;a.push(f),r[c][d][f]={};const{structures:m}=an({drawDefinition:v});(m||[]).forEach(h=>{var g;const _=h.structureId,{matchUps:I}=Je({structure:h}),{roundMatchUps:P}=Tr({matchUps:I}),y=P&&Object.keys(P).map(S=>parseInt(S));r[c][d][f][_]=y,i.push(_),(g=h.structures)!=null&&g.length&&h.structures.forEach(S=>{i.push(S.structureId),r[c][d][f][S.structureId]=y})})})})),{tournamentMap:r,tournamentIds:o,structureIds:i,venueIds:l,eventIds:s,drawIds:a}}function JK(t){const e=(t==null?void 0:t.tournamentRecords)&&Object.values(t==null?void 0:t.tournamentRecords)||[],r={},{venueIds:n,eventIds:o,drawIds:i,structureIds:s,tournamentIds:a}=e.reduce((l,c)=>{const{tournamentIds:u,tournamentMap:p,structureIds:d,venueIds:v,eventIds:f,drawIds:m}=KT({tournamentRecord:c});return v.forEach(h=>{l.venueIds.includes(h)||l.venueIds.push(h)}),l.tournamentIds.push(...u),l.structureIds.push(...d),l.eventIds.push(...f),l.drawIds.push(...m),Object.assign(r,p),l},{tournamentIds:[],structureIds:[],venueIds:[],eventIds:[],drawIds:[]});return{tournamentsMap:r,tournamentIds:a,structureIds:s,venueIds:n,eventIds:o,drawIds:i}}var ZK=Object.defineProperty,QT=Object.getOwnPropertySymbols,XK=Object.prototype.hasOwnProperty,e8=Object.prototype.propertyIsEnumerable,JT=(t,e,r)=>e in t?ZK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,t8=(t,e)=>{for(var r in e||(e={}))XK.call(e,r)&&JT(t,r,e[r]);if(QT)for(var r of QT(e))e8.call(e,r)&&JT(t,r,e[r]);return t};function r8({tournamentRecords:t,matchUpFormat:e,recoveryTimes:r,averageTimes:n,tournamentId:o,eventId:i}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const s=Object.keys(t).filter(l=>!o||o===l);if(o&&!s.includes(o))return{error:X};let a;for(const l of s){const c=t[l],{event:u}=Qt({tournamentRecord:c,eventId:i});i&&u&&(a=!0);const p=hm({tournamentRecord:c,event:u,matchUpFormat:e,averageTimes:n,recoveryTimes:r});if(p.error)return p}return!i||a?t8({},V):{error:Ar}}function Om({defaultRecoveryMinutes:t=0,defaultAverageMinutes:e,tournamentRecords:r,matchUpFormat:n,categoryName:o,categoryType:i,tournamentId:s,eventType:a,eventId:l}){if(!Xr(n))return{error:Jc};const c=Object.keys(r).filter(p=>!s||p===s);let u;return c.forEach(p=>{var d;if(u)return;const v=r[p],f=l?(d=Qt({tournamentRecord:v,eventId:l}))==null?void 0:d.event:void 0;return u=Lf({tournamentRecord:v,matchUpFormat:n,categoryName:o,categoryType:i,eventType:a,event:f}),(u==null?void 0:u.averageMinutes)||(u==null?void 0:u.recoveryMinutes)}),{recoveryMinutes:(u==null?void 0:u.recoveryMinutes)||t,averageMinutes:(u==null?void 0:u.averageMinutes)||e,typeChangeRecoveryMinutes:(u==null?void 0:u.typeChangeRecoveryMinutes)||(u==null?void 0:u.recoveryMinutes)||t}}var n8=Object.defineProperty,ZT=Object.getOwnPropertySymbols,o8=Object.prototype.hasOwnProperty,i8=Object.prototype.propertyIsEnumerable,XT=(t,e,r)=>e in t?n8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s8=(t,e)=>{for(var r in e||(e={}))o8.call(e,r)&&XT(t,r,e[r]);if(ZT)for(var r of ZT(e))i8.call(e,r)&&XT(t,r,e[r]);return t};function bm({scheduleCompletedMatchUps:t,containedStructureIds:e,tournamentRecords:r,periodLength:n=30,matchUps:o,rounds:i}){if(typeof r!="object")return{error:ke};if(!Array.isArray(i))return{error:_e,info:or("rounds")};const s={},a=[];i.sort((v,f)=>{var m,h;return((m=v.sortOrder)!=null?m:0)-((h=f.sortOrder)!=null?h:0)}),e=e??Object.assign({},...Object.values(r).map(v=>Ra({tournamentRecord:v}).containedStructures)),o||({matchUps:o}=Ro({nextMatchUps:!0,tournamentRecords:r}));let l=0;const c={},u={},p={},d=i.flatMap(v=>{var f;const m=v.periodLength||n,h=[];e!=null&&e[v.structureId]?h.push(...e[v.structureId]):h.push(v.structureId);let g=o?bs({tournamentIds:[v.tournamentId],roundNumbers:[v.roundNumber],matchUpIds:v.matchUpIds,eventIds:[v.eventId],drawIds:[v.drawId],processContext:!0,structureIds:h,matchUps:o}).sort(Cs):[];const{segmentNumber:_,segmentsCount:I}=v.roundSegment||{};if(ht(_)&&Zr(g==null?void 0:g.length)&&Zr(I)&&_>0&&_<=I&&I<(g==null?void 0:g.length)&&!((f=v.matchUpIds)!=null&&f.length)){const O=g.length/I,b=O*(_-1);g=g.slice(b,b+O)}const P=r[v.tournamentId],y=Qt({drawId:v.drawId,tournamentRecord:P}).event,S=[];for(const O of g){const b=O.matchUpFormat;b&&(s[b]||(s[b]=[],s[b].push(O)),S.push(b))}for(const O of S){const{eventType:b,category:w}=y??{},{categoryName:T,ageCategoryCode:$}=w??{},{typeChangeRecoveryMinutes:N,recoveryMinutes:E,averageMinutes:A,error:U}=Om({categoryName:T??$,categoryType:w==null?void 0:w.categoryType,tournamentId:v.tournamentId,eventId:v.eventId,tournamentRecords:r,matchUpFormat:O,eventType:b});if(U)return{error:U,round:v};const C=g.filter(D=>(t||!Yt.includes(D.matchUpStatus))&&D.matchUpStatus!==nt).map(Jt);C.forEach(D=>{p[D]={typeChangeRecoveryMinutes:N,recoveryMinutes:E,averageMinutes:A},c[D]=E,u[D]=A}),a.push(...C),l=Math.max(A||0,l);const M=`${A}|${m}`;return{roundPeriodLength:m,recoveryMinutes:E,averageMinutes:A,matchUpIds:C,hash:M}}});return s8({scheduledRoundsDetails:d,greatestAverageMinutes:l,matchUpFormatCohorts:s,recoveryMinutesMap:c,averageMinutesMap:u,orderedMatchUpIds:a,minutesMap:p},V)}function ew({tournamentRecords:t}){const r=Object.keys(t).reduce((i,s)=>{const a=t[s],{tournamentInfo:{startDate:l,endDate:c}}=Sc({tournamentRecord:a}),u=l&&new Date(Re(l));(!i.startDate||u&&u<i.startDate)&&(i.startDate=u);const p=c&&new Date(Re(c));return(!i.endDate||p&&p>i.endDate)&&(i.endDate=p),i},{startDate:void 0,endDate:void 0}),n=r.startDate&&Re(r.startDate.toISOString()),o=r.endDate&&Re(r.endDate.toISOString());return!n||!o?{error:n_}:{startDate:n,endDate:o}}var a8=Object.defineProperty,l8=Object.defineProperties,c8=Object.getOwnPropertyDescriptors,tw=Object.getOwnPropertySymbols,u8=Object.prototype.hasOwnProperty,d8=Object.prototype.propertyIsEnumerable,rw=(t,e,r)=>e in t?a8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tm=(t,e)=>{for(var r in e||(e={}))u8.call(e,r)&&rw(t,r,e[r]);if(tw)for(var r of tw(e))d8.call(e,r)&&rw(t,r,e[r]);return t},p8=(t,e)=>l8(t,c8(e));function za({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const{extension:e}=bu({name:Yo,tournamentRecords:t});let r=(e==null?void 0:e.value)||[];if(r.length){const{venueIds:n}=Hv({requireCourts:!0,tournamentRecords:t}),{eventIds:o,drawIds:i}=pd({tournamentRecords:t}),{updatedSchedulingProfile:s,modifications:a,issues:l}=Fd({schedulingProfile:r,venueIds:n,eventIds:o,drawIds:i});if(a){r=s;const c=bc({tournamentRecords:t,schedulingProfile:r});return c.error?c:{schedulingProfile:r,modifications:a,issues:l}}}return{schedulingProfile:r,modifications:0}}function bc({tournamentRecords:t,schedulingProfile:e}){const r=Rd({tournamentRecords:t,schedulingProfile:e});return r.error?r:e?Wf({tournamentRecords:t,extension:{name:Yo,value:e}}):Tu({tournamentRecords:t,name:Yo})}function nw({tournamentRecords:t,scheduleDate:e,venueId:r,round:n}){if(!Gr(e))return{error:Sr};const o="addSchedulingProfileRound",{extension:i}=bu({tournamentRecords:t,name:Yo}),s=(i==null?void 0:i.value)||[];let a=s.find(v=>io(e,v.scheduleDate));if(!a){const{startDate:v,endDate:f}=ew({tournamentRecords:t}),m=new Date(e);if(v&&m<new Date(v)||f&&m>new Date(f))return{error:Sr};a={scheduleDate:e,venues:[]},s.push(a)}let l=a.venues.find(v=>v.venueId===r);l||(l={venueId:r,rounds:[]},a.venues.push(l));const c=["notBeforeTime"],u=v=>Object.keys(v).filter(f=>!c.includes(f)).sort().map(f=>rs(v[f])?u(v[f]):v[f]).flat().join("|");if(l.rounds.find(v=>u(v)===u(n)))return k({result:{error:sx},stack:o});l.rounds.push(n);const d=bc({tournamentRecords:t,schedulingProfile:s});return d.error?d:Tm({},V)}function Fd({schedulingProfile:t,venueIds:e,eventIds:r,drawIds:n}){const o=[],i=t==null?void 0:t.map(a=>{const l=Re(a==null?void 0:a.scheduleDate);if(!l){o.push(`Invalid date: ${a==null?void 0:a.scheduledDate}`);return}const c=((a==null?void 0:a.venues)||[]).map(u=>{const{rounds:p,venueId:d}=u;if(!e.includes(d)){o.push(`Missing venueId: ${d}`);return}const f=p.filter(m=>{const h=r.includes(m.eventId)&&n.includes(m.drawId);return h||o.push(`Invalid eventId: ${m.eventId} or drawId: ${m.drawId}`),h});if(f.length)return{venueId:d,rounds:f}}).filter(Boolean);return c.length&&l&&p8(Tm({},a),{venues:c})}).filter(Boolean),s=o.length;return{updatedSchedulingProfile:i,modifications:s,issues:o}}function ow({tournamentRecords:t}){const{schedulingProfile:e}=za({tournamentRecords:t});if(e){const{venueIds:r}=Hv({tournamentRecords:t}),{eventIds:n,drawIds:o}=pd({tournamentRecords:t}),{updatedSchedulingProfile:i,modifications:s}=Fd({schedulingProfile:e,venueIds:r,eventIds:n,drawIds:o});if(s)return bc({tournamentRecords:t,schedulingProfile:i})}return Tm({},V)}function xd({matchUps:t=[],schedulingProfile:e}){const r={},n=({eventId:a,drawId:l,structureId:c,roundNumber:u})=>`${a}|${l}|${c}${u}`;e!=null&&e.length&&e.map(({venues:l})=>l.map(({rounds:c})=>c)).flat().forEach(l=>{l.sort((u,p)=>(u.sortOrder||0)-(p.sortOrder||0)).forEach(({eventId:u,drawId:p,structureId:d,roundNumber:v},f)=>{const m=n({eventId:u,drawId:p,structureId:d,roundNumber:v});r[m]=f})});const o=[],i={noScheduledDate:[]};for(const a of t){const l=a.schedule||{},c=l.scheduledDate&&Re(l.scheduledDate)||l.scheduledTime&&Re(l.scheduledTime)||"noScheduledDate";i[c]||(i[c]=[]),i[c].push(a)}const s=Object.keys(i).sort();for(const a of s){const l=i[a],c={noScheduledTime:[]};for(const p of l){const d=p.schedule||{},v=d.scheduledTime&&at(d.scheduledTime)||"noScheduledTime";c[v]||(c[v]=[]),c[v].push(p)}const u=Object.keys(c).sort();for(const p of u){const d=c[p];d.sort((v,f)=>{const m=r[n(v)]||0,h=r[n(f)]||0;return m-h}),o.push(...d)}}return o}var f8=Object.defineProperty,v8=Object.defineProperties,m8=Object.getOwnPropertyDescriptors,iw=Object.getOwnPropertySymbols,h8=Object.prototype.hasOwnProperty,g8=Object.prototype.propertyIsEnumerable,sw=(t,e,r)=>e in t?f8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ld=(t,e)=>{for(var r in e||(e={}))h8.call(e,r)&&sw(t,r,e[r]);if(iw)for(var r of iw(e))g8.call(e,r)&&sw(t,r,e[r]);return t},wm=(t,e)=>v8(t,m8(e));function Em(t){var e,r,n,o,i,s,a;if(typeof(t==null?void 0:t.tournamentRecords)!="object"||!Object.keys(t==null?void 0:t.tournamentRecords).length)return{error:ke};const{courts:l,venues:c}=Ms(t),p=za(t).schedulingProfile,{sortDateMatchUps:d=!0,courtCompletedMatchUps:v,alwaysReturnCompleted:f,activeTournamentId:m,tournamentRecords:h,withCourtGridRows:g,minCourtGridRows:_,usePublishState:I,status:P=qn,sortCourtsData:y}=t,S=I?Zu({tournamentRecord:h[m??fn()],itemType:`${Hr}.${qr}`}).timeItem:void 0,O=(e=S==null?void 0:S.itemValue)==null?void 0:e[P],b=f?xv(wm(Ld({},t),{matchUpFilters:wm(Ld({},t.matchUpFilters),{matchUpStatuses:[ut.Completed]}),contextFilters:t.contextFilters})).completedMatchUps:[];if(I&&(!O||!Object.keys(O).length))return{completedMatchUps:b,dateMatchUps:[],courtsData:[],venues:c};const w=I?_8({tournamentRecords:h}).drawIds:void 0;w!=null&&w.length&&(t.contextFilters||(t.contextFilters={}),(r=t.contextFilters)!=null&&r.drawIds?t.contextFilters.drawIds=t.contextFilters.drawIds.filter(D=>w.includes(D)):t.contextFilters.drawIds=w),(n=O==null?void 0:O.eventIds)!=null&&n.length&&(t.matchUpFilters||(t.matchUpFilters={}),(o=t.matchUpFilters)!=null&&o.eventIds&&t.matchUpFilters.eventIds.length?t.matchUpFilters.eventIds=t.matchUpFilters.eventIds.filter(D=>O.eventIds.includes(D)):t.matchUpFilters.eventIds=O.eventIds),(i=O==null?void 0:O.scheduledDates)!=null&&i.length&&(t.matchUpFilters||(t.matchUpFilters={}),t.matchUpFilters.scheduledDates&&t.matchUpFilters.scheduledDates.length?t.matchUpFilters.scheduledDates=t.matchUpFilters.scheduledDates.filter(D=>O.scheduledDates.includes(D)):t.matchUpFilters.scheduledDates=O.scheduledDates),f&&(t.matchUpFilters||(t.matchUpFilters={}),(a=(s=t.matchUpFilters)==null?void 0:s.excludeMatchUpStatuses)!=null&&a.length?t.matchUpFilters.excludeMatchUpStatuses.includes(Mt)||t.matchUpFilters.excludeMatchUpStatuses.push(Mt):t.matchUpFilters.excludeMatchUpStatuses=[Mt]);const{completedMatchUps:T,upcomingMatchUps:$,pendingMatchUps:N}=xv(wm(Ld({},t),{matchUpFilters:t.matchUpFilters,contextFilters:t.contextFilters})),E=[...$??[],...N??[]],A=d?xd({matchUps:E,schedulingProfile:p}):E,U=l==null?void 0:l.map(D=>{var R;const j=M(D);return Ld({surfaceCategory:(R=D==null?void 0:D.surfaceCategory)!=null?R:"",matchUps:j},D)}),C={courtsData:U,completedMatchUps:f?b:T,dateMatchUps:A,venues:c};if(g){const{rows:D,courtPrefix:R}=Pb({minRowsCount:_,courtsData:U});C.courtPrefix=R,C.rows=D}return C;function M({courtId:D}){const j=(v?A.concat(T??[]):A).filter(G=>{var W,q,F;return((W=G.schedule)==null?void 0:W.courtId)===D||((F=(q=G.schedule)==null?void 0:q.allocatedCourts)==null?void 0:F.map(({courtId:L})=>L).includes(D))});return y?xd({matchUps:j,schedulingProfile:p}):j}}function _8({tournamentRecords:t}){var e,r,n,o;const i=[];for(const s of Object.values(t))for(const a of(e=s.events)!=null?e:[]){const{timeItem:l}=jo({itemType:`${Hr}.${qr}`,event:a}),c=(r=l==null?void 0:l.itemValue)==null?void 0:r[qn];if((n=c==null?void 0:c.drawIds)!=null&&n.length)i.push(...c.drawIds);else{const u=((o=a.drawDefinitions)!=null?o:[]).map(({drawId:p})=>p).filter(Boolean);i.push(...u)}}return{drawIds:i}}var I8=Object.defineProperty,P8=Object.defineProperties,y8=Object.getOwnPropertyDescriptors,aw=Object.getOwnPropertySymbols,S8=Object.prototype.hasOwnProperty,O8=Object.prototype.propertyIsEnumerable,lw=(t,e,r)=>e in t?I8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,b8=(t,e)=>{for(var r in e||(e={}))S8.call(e,r)&&lw(t,r,e[r]);if(aw)for(var r of aw(e))O8.call(e,r)&&lw(t,r,e[r]);return t},T8=(t,e)=>P8(t,y8(e));function cw({calculateStartTimeFromCourts:t=!0,defaultRecoveryMinutes:e=0,averageMatchUpMinutes:r=90,remainingScheduleTimes:n,clearScheduleDates:o,tournamentRecords:i,periodLength:s,scheduleDate:a,startTime:l,venueIds:c,endTime:u}){if(typeof i!="object"||!Object.keys(i).length)return{error:ke};s=s||rd({recoveryMinutes:e,averageMatchUpMinutes:r});const{courts:p,venues:d}=Ms({dates:[a],ignoreDisabled:!0,tournamentRecords:i}),v=p==null?void 0:p.filter($=>!c||c.includes($.venueId));l||(l=v==null?void 0:v.reduce(($,N)=>{var E;const A=(E=N.dateAvailability)==null?void 0:E.find(C=>!C.date||io(a,C.date)),U=(A==null?void 0:A.startTime)||N.startTime;return U&&(!$||Le(U)<Le($))?U:$},void 0)),u||(u=v==null?void 0:v.reduce(($,N)=>{var E;const A=(E=N.dateAvailability)==null?void 0:E.find(C=>!C.date||io(a,C.date)),U=(A==null?void 0:A.endTime)||N.endTime;return U&&(!$||Le(U)>Le($))?U:$},void 0));const f=Object.values(i),m=Object.assign({},...f.map($=>($.events||[]).map(N=>{const{scheduleTiming:E}=Cl({tournamentRecord:$,event:N});return{[N.eventId]:{event:N,scheduleTiming:E}}})).flat()),g=Em({sortDateMatchUps:!1,tournamentRecords:i,matchUpFilters:{scheduledDate:a,venueIds:c}}),_=(g==null?void 0:g.dateMatchUps)||[],I=(g==null?void 0:g.completedMatchUps)||[],P=[];P.push(..._),P.push(...I);const y={averageTimes:[{minutes:{default:r}}],recoveryTimes:[{minutes:{default:e}}]},S=P==null?void 0:P.map(({eventId:$,schedule:N,matchUpFormat:E})=>{const{event:A,scheduleTiming:U}=m[$],C=A==null?void 0:A.eventType,M=T8(b8({},U),{defaultTiming:y,matchUpFormat:E}),{averageMinutes:D,recoveryMinutes:R}=yu({eventType:C,timingDetails:M}),{courtId:j,venueId:G}=N,W=at(N.scheduledTime),q=Or(W,D);return{recoveryMinutes:R,averageMinutes:D,periodLength:s,startTime:W,endTime:q,courtId:j,venueId:G}}),O={calculateStartTimeFromCourts:t,remainingScheduleTimes:n,averageMatchUpMinutes:r,date:a,clearScheduleDates:o,periodLength:s,startTime:l,endTime:u,bookings:S,courts:v},{scheduleTimes:b}=Vv(O),w=(c==null?void 0:c.length)===1&&c[0]||(d==null?void 0:d.length)===1&&d[0].venueId||void 0,T=P.map(Jt);return{venueId:w,scheduleTimes:b,dateScheduledMatchUpIds:T}}function $m({matchUpScheduleTimes:t,matchUpDependencies:e,allDateMatchUpIds:r,matchUp:n}){var o;const s=(((o=e==null?void 0:e[n.matchUpId])==null?void 0:o.matchUpIds)||[]).filter(l=>r.includes(l)).filter(l=>!t[l]);return{dependenciesScheduled:!(s!=null&&s.length),remainingDependencies:s}}function Ya({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:e,timeAfterRecovery:r,matchUp:n}){var o,i,s,a;const{individualParticipantIds:l}=ed(n);r=r||((o=n.schedule)==null?void 0:o.timeAfterRecovery);const c=v=>{t[v]||(t[v]=[]),t[v]=We(t[v].concat(...l))},u=v=>{r&&(!e[v]||r>e[v])&&(e[v]=r)},p=((i=n.winnerTo)==null?void 0:i.matchUpId)||n.winnerMatchUpId;p&&(r&&u(p),c(p));const d=((s=n.loserTo)==null?void 0:s.matchUpId)||n.loserMatchUpId;d&&(r&&u(d),c(d)),(a=n.sidesTo)!=null&&a.length&&n.sidesTo.forEach(({matchUpId:v})=>{v&&(r&&u(v),c(v))})}function Tc({individualParticipantProfiles:t,participantId:e}){t[e]||(t[e]={typeChangeTimeAfterRecovery:void 0,timeAfterRecovery:void 0,priorMatchUpType:void 0,potentialRecovery:{},potentialCounted:{},potentialBookings:{},bookings:[],counters:{}})}function w8({individualParticipantProfiles:t,recoveryValue:e,participantId:r,scheduleTime:n,drawId:o}){t[r].potentialRecovery[o]||(t[r].potentialRecovery[o]=[]),t[r].potentialRecovery[o].push(e),t[r].potentialBookings[o]||(t[r].potentialBookings[o]=[]),t[r].potentialBookings[o].push({timeAfterRecovery:e,scheduleTime:n})}function wc({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,typeChangeRecoveryMinutes:r,averageMatchUpMinutes:n=0,matchUpNotBeforeTimes:o,matchUpDependencies:i,recoveryMinutes:s=0,scheduleTime:a,matchUp:l}){var c,u;const p=at((c=l==null?void 0:l.schedule)==null?void 0:c.endTime),d=p?Or(p,Te(s)):Or(a,Te(n)+Te(s)),v=r&&(p?Or(at(p),r):Or(a,Te(n)+Te(r))),f=((u=i==null?void 0:i[l.matchUpId])==null?void 0:u.participantIds)||[],m=(l.roundPosition&&t[l.matchUpId]||[]).flat();f.forEach(h=>{Tc({individualParticipantProfiles:e,participantId:h});const _=e[h].priorMatchUpType!==l.matchUpType&&v||d;m.includes(h)?w8({individualParticipantProfiles:e,drawId:l.drawId,recoveryValue:_,participantId:h,scheduleTime:a}):(e[h].timeAfterRecovery=_,e[h].bookings.push({scheduleTime:a,timeAfterRecovery:_}))}),Ya({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:o,timeAfterRecovery:d,matchUp:l})}function uw({matchUpScheduleTimes:t,matchUpDependencies:e,scheduleTime:r,matchUpId:n,details:o}){var i,s,a,l,c;let u;const p=(s=(i=o.minutesMap)==null?void 0:i[n])==null?void 0:s.recoveryMinutes,v=(((l=(a=o.minutesMap)==null?void 0:a[n])==null?void 0:l.averageMinutes)||0)+(p||0),f=Or(r,v),m=((c=e==null?void 0:e[n])==null?void 0:c.dependentMatchUpIds)||[];if(m.length){const h=m.reduce((g,_)=>{const I=t[_];if(!I)return g;const P={scheduleTime:I,matchUpId:_};return I&&!g.matchUpId||Le(I)<Le(g.scheduleTime)?P:g},{});h.scheduleTime&&Le(f)>Le(h.scheduleTime)&&(u=h)}return{scheduledDependent:u}}function E8(t){const{sides:e,matchUpType:r}=t||{};return(e||[]).map(n=>{var o;return r===dt&&(((o=n==null?void 0:n.participant)==null?void 0:o.individualParticipants)||[])||(n==null?void 0:n.participant)&&[n.participant]||[]}).flat()}const Vd="DO_NOT_SCHEDULE";var $8=Object.defineProperty,N8=Object.defineProperties,U8=Object.getOwnPropertyDescriptors,dw=Object.getOwnPropertySymbols,A8=Object.prototype.hasOwnProperty,C8=Object.prototype.propertyIsEnumerable,pw=(t,e,r)=>e in t?$8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,M8=(t,e)=>{for(var r in e||(e={}))A8.call(e,r)&&pw(t,r,e[r]);if(dw)for(var r of dw(e))C8.call(e,r)&&pw(t,r,e[r]);return t},D8=(t,e)=>N8(t,U8(e));function Nm({averageMatchUpMinutes:t=90,requestConflicts:e={},potentials:r=!0,personRequests:n,scheduleTime:o,scheduleDate:i,matchUp:s}){const a=E8(s).map(({person:v})=>v==null?void 0:v.personId);if(r){const v=((s==null?void 0:s.potentialParticipants)||[]).flat().map(({person:f})=>f==null?void 0:f.personId);a.push(...v)}const l=a.map(v=>{var f;return(f=n[v])==null?void 0:f.map(m=>D8(M8({},m),{personId:v}))}).filter(Boolean).flat().filter(v=>v.requestType===Vd&&io(i,v.date)),c=[],u=s==null?void 0:s.matchUpId,p=$t(at(o),Re(i)),d=at(If(p,t).toISOString());for(const v of l){const{requestId:f,startTime:m,endTime:h}=v;(o>m&&o<h||d>m&&d<h)&&(c.push({matchUpId:u,request:v,scheduleTime:o}),e[f]?(e[f].scheduleTimes.includes(o)||e[f].scheduleTimes.push(o),e[f].matchUpIds.includes(u)||e[f].matchUpIds.push(u)):e[f]={request:v,scheduleTimes:[o],matchUpIds:[u]})}return{conflicts:c}}function Um({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,matchUp:r,value:n}){const{matchUpType:o}=r,{individualParticipantIds:i}=ed(r),a=(t[r.matchUpId]||[]).filter(c=>!Xt(c,i)).flat();[...i,...a].forEach(c=>{if(Tc({individualParticipantProfiles:e,participantId:c}),!e[c].potentialCounted[r.drawId]){const u=e[c].counters;u[o]?u[o]+=n:n>0&&(u[o]=n),u[Pn]?u[Pn]+=n:n>0&&(u[Pn]=n),a.includes(c)&&(e[c].potentialCounted[r.drawId]=!0)}})}function j8({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,dateScheduledMatchUpIds:r,greatestAverageMinutes:n,dateScheduledMatchUps:o,matchUpNotBeforeTimes:i,matchUpScheduleTimes:s,matchUpDependencies:a,clearScheduleDates:l,scheduleDate:c,minutesMap:u,matchUps:p}){var d,v;r||(o=p==null?void 0:p.filter(h=>{const g=h.schedule||{};return yc({schedule:g})&&(!c||h.schedule.scheduledDate===c)}),r=o.map(Jt));const f=Array.isArray(l)?l.includes(c):l,m=f?[]:p.filter(({matchUpId:h})=>r.includes(h));for(const h of m){Um({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,value:1,matchUp:h});const g=(d=h.schedule)==null?void 0:d.scheduledTime;if(g){s[h.matchUpId]=g;const _=(v=u==null?void 0:u[h.matchUpId])==null?void 0:v.recoveryMinutes;wc({individualParticipantProfiles:e,matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:i,matchUpDependencies:a,averageMatchUpMinutes:n,recoveryMinutes:_,scheduleTime:g,matchUp:h})}}return{clearDate:f,dateScheduledMatchUpIds:r,dateScheduledMatchUps:o}}function R8({scheduledRoundsDetails:t,greatestAverageMinutes:e,garmanSinglePass:r}){const n=[];let o=[],i,s,a,l;for(const c of t.filter(Boolean))l||(l=c.hash),(c.hash===l||r)&&(o=o.concat(c.matchUpIds)),c.hash!==l&&!r&&(l=c.hash,n.push({averageMinutes:a,recoveryMinutes:s,roundPeriodLength:i,matchUpIds:o}),o=c.matchUpIds),a=r?e:c.averageMinutes,s=c.recoveryMinutes,i=c.roundPeriodLength;return o.length&&n.push({averageMinutes:a,recoveryMinutes:s,roundPeriodLength:i,matchUpIds:o}),{groupedRounds:n}}function F8({matchUpPotentialParticipantIds:t,scheduleCompletedMatchUps:e,dateScheduledMatchUpIds:r,matchUpNotBeforeTimes:n,orderedMatchUpIds:o,clearDate:i,matchUps:s}){const a=o.map(c=>s.find(u=>u.matchUpId===c)).filter(Boolean).filter(c=>{const u=!i&&r.includes(c.matchUpId),p=[nt,Xe,Mt,Wr,_r,ot,Rt,tr].includes(c==null?void 0:c.matchUpStatus);return e||!u&&!c.winningSide&&!p}),{matchUpMap:l}=a.reduce((c,u)=>{const{drawId:p,tournamentId:d}=u;return c.matchUpMap[d]||(c.matchUpMap[d]={}),c.matchUpMap[d][p]?c.matchUpMap[d][p].push(u):c.matchUpMap[d][p]=[u],Ya({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:n,matchUp:u}),c},{matchUpMap:{}});return{matchUpsToSchedule:a,matchUpMap:l}}var x8=Object.defineProperty,L8=Object.defineProperties,V8=Object.getOwnPropertyDescriptors,fw=Object.getOwnPropertySymbols,B8=Object.prototype.hasOwnProperty,k8=Object.prototype.propertyIsEnumerable,vw=(t,e,r)=>e in t?x8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,G8=(t,e)=>{for(var r in e||(e={}))B8.call(e,r)&&vw(t,r,e[r]);if(fw)for(var r of fw(e))k8.call(e,r)&&vw(t,r,e[r]);return t},W8=(t,e)=>L8(t,V8(e));function Am({defaultRecoveryMinutes:t=0,averageMatchUpMinutes:e=90,dateScheduledMatchUps:r,tournamentRecords:n,venueIds:o=[],periodLength:i,scheduleDate:s,matchUps:a}){if(typeof n!="object")return{error:ke};if(!Array.isArray(a)&&!Array.isArray(r))return{error:ko};i=i||rd({recoveryMinutes:t,averageMatchUpMinutes:e});const l=Object.assign({},...Object.values(n).map(d=>(d.events||[]).map(v=>{const{scheduleTiming:f}=Cl({tournamentRecord:d,event:v});return{[v.eventId]:{event:v,scheduleTiming:f}}})).flat()),c={averageTimes:[{minutes:{default:e}}],recoveryTimes:[{minutes:{default:t}}]};r||(r=a==null?void 0:a.filter(d=>{const v=d.schedule;return yc({schedule:v})&&(!s||d.schedule.scheduledDate===s)}));const u=r==null?void 0:r.filter(d=>!o.length||o.includes(d.schedule.venueId));return{bookings:u==null?void 0:u.map(({eventId:d,schedule:v,matchUpFormat:f})=>{const{event:m,scheduleTiming:h}=l[d],g=m==null?void 0:m.eventType,_=W8(G8({},h),{defaultTiming:c,matchUpFormat:f}),{averageMinutes:I,recoveryMinutes:P}=yu({timingDetails:_,eventType:g}),{courtId:y,venueId:S}=v,O=at(v.scheduledTime),b=Or(O,I);return{recoveryMinutes:P,averageMinutes:I,periodLength:i,startTime:O,courtId:y,endTime:b,venueId:S}}).filter(Boolean),relevantMatchUps:u,dateScheduledMatchUps:r}}function H8({calculateStartTimeFromCourts:t=!0,remainingScheduleTimes:e,defaultRecoveryMinutes:r,averageMatchUpMinutes:n,clearScheduleDates:o,tournamentRecords:i,tournamentRecord:s,periodLength:a,scheduleDate:l,startTime:c,venueIds:u,matchUps:p,endTime:d}){if(s&&!i&&(i={[s.tournamentId]:s}),typeof i!="object"||!Object.keys(i).length)return{error:ke};a=a||rd({recoveryMinutes:r,averageMatchUpMinutes:n});const{courts:v,venues:f}=Ms({dates:[l],ignoreDisabled:!0,tournamentRecords:i}),m=(v==null?void 0:v.filter(S=>!u||u.includes(S.venueId)))||[];c=c||Ma({courts:m,scheduleDate:l,startTime:!0}),d=d||Ma({courts:m,scheduleDate:l,endTime:!0});const{bookings:h,dateScheduledMatchUps:g}=Am({defaultRecoveryMinutes:r,averageMatchUpMinutes:n,tournamentRecords:i,scheduleDate:l,periodLength:a,venueIds:u,matchUps:p}),_={calculateStartTimeFromCourts:t,remainingScheduleTimes:e,averageMatchUpMinutes:n,clearScheduleDates:o,date:l,periodLength:a,startTime:c,bookings:h,endTime:d,courts:m},{scheduleTimes:I}=Vv(_),P=(u==null?void 0:u.length)===1&&u[0]||(f==null?void 0:f.length)===1&&f[0].venueId||void 0;return{dateScheduledMatchUpIds:g==null?void 0:g.map(Fn("matchUpId")),dateScheduledMatchUps:g,scheduleTimes:I,venueId:P}}function mw({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,scheduleCompletedMatchUps:r,containedStructureIds:n,matchUpNotBeforeTimes:o,matchUpScheduleTimes:i,matchUpDependencies:s,clearScheduleDates:a,tournamentRecords:l,periodLength:c,scheduleDate:u,useGarman:p,matchUps:d,courts:v,venues:f}){var m;const h={},g=[],_=[];for(const I of f){const{rounds:P=[],venueId:y}=I,{scheduledRoundsDetails:S,greatestAverageMinutes:O,orderedMatchUpIds:b,minutesMap:w}=bm({scheduleCompletedMatchUps:r,containedStructureIds:n,tournamentRecords:l,periodLength:c,matchUps:d,rounds:P});_.push(...b||[]);const{groupedRounds:T}=R8({scheduledRoundsDetails:S,greatestAverageMinutes:O,garmanSinglePass:!0});let $,N,E=[];p&&({scheduleTimes:E,dateScheduledMatchUpIds:$,dateScheduledMatchUps:N}=H8({averageMatchUpMinutes:(m=T[0])==null?void 0:m.averageMinutes,scheduleDate:Re(u),venueIds:[I.venueId],clearScheduleDates:a,tournamentRecords:l,periodLength:c,matchUps:d}));const A=j8({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,dateScheduledMatchUpIds:$,greatestAverageMinutes:O,matchUpNotBeforeTimes:o,matchUpScheduleTimes:i,matchUpDependencies:s,clearScheduleDates:a,scheduleDate:u,minutesMap:w,matchUps:d}),U=A.clearDate;({dateScheduledMatchUpIds:$,dateScheduledMatchUps:N}=A);const{matchUpsToSchedule:C,matchUpMap:M}=F8({matchUpPotentialParticipantIds:t,scheduleCompletedMatchUps:r,dateScheduledMatchUpIds:$,matchUpNotBeforeTimes:o,orderedMatchUpIds:b,clearDate:U,matchUps:d}),D=v.filter(R=>R.venueId===y);h[y]={previousRemainingScheduleTimes:[],courtsCount:D.length,greatestAverageMinutes:O,scheduledRoundsDetails:S,dateScheduledMatchUps:N,matchUpsToSchedule:C,scheduleTimes:E,groupedRounds:T,venueCourts:D,minutesMap:w,matchUpMap:M},a||g.push(...$)}return{allDateScheduledMatchUpIds:g,venueScheduledRoundDetails:h,allDateMatchUpIds:_}}function q8(t,e){const r=Le(t.scheduleTime),n=Le(t.timeAfterRecovery),o=Le(e.scheduleTime),i=Le(e.timeAfterRecovery),s=r===o||n===i,a=r>o&&r<i,l=o>r&&o<n,c=n>o&&n<i,u=i>r&&i<n;return Oe({hasOverlap:s||a||c||l||u,startAisContained:a,endAisContained:c,startBisContained:l,endBisContained:u},!0)}function Cm({individualParticipantProfiles:t,matchUpNotBeforeTimes:e,matchUpDependencies:r,scheduleTime:n,matchUp:o,details:i}){var s,a,l,c,u;const p=(((s=r==null?void 0:r[o.matchUpId])==null?void 0:s.participantIds)||[]).flat(),d=((l=(a=i==null?void 0:i.minutesMap)==null?void 0:a[o.matchUpId])==null?void 0:l.averageMinutes)||0,v=((u=(c=i==null?void 0:i.minutesMap)==null?void 0:c[o.matchUpId])==null?void 0:u.recoveryMinutes)||0,f=p.every(I=>{var P;Tc({individualParticipantProfiles:t,participantId:I});const y=t[I];if(!y.timeAfterRecovery)return!0;const S=at((P=o==null?void 0:o.schedule)==null?void 0:P.endTime),O=S?Or(S,Te(v)):Or(n,Te(d)+Te(v));return!!![...Object.keys(y.potentialBookings).filter($=>$!==o.drawId).map($=>y.potentialBookings[$]).flat(),...y.bookings].find($=>q8({scheduleTime:n,timeAfterRecovery:O},$).hasOverlap)}),m=e[o.matchUpId],g=(m?Sl($t(m),$t(n),!1):0)>=0;return{enoughTime:f&&g}}function Mm({individualParticipantProfiles:t,matchUpPotentialParticipantIds:e,matchUpDailyLimits:r={},matchUp:n}){const{matchUpId:o,matchUpType:i}=n,{enteredIndividualParticipantIds:s}=ed(n),a=(n.roundPosition&&e[o]||[]).flat(),l=We(s.concat(...a));return l.forEach(u=>{Tc({individualParticipantProfiles:t,participantId:u})}),{participantIdsAtLimit:l.filter(u=>{const p=t[u];if(p)return[i,Pn].find(d=>{var v;const f=((v=p.counters)==null?void 0:v[d])||0,m=r[d]||0;return f&&m&&f>=m})}),relevantParticipantIds:l}}const z8="deleteDrawDefinitions",Y8="autoSchedulingAudit",hw="deleteEvents";function gw({autoSchedulingAudit:t,tournamentRecords:e}){var r;He({topic:Ml,payload:t});const n=a=>a?Object.values(a).reduce((c,u)=>c+u.length||0,0):0,o=((t==null?void 0:t.schedulingProfile)||[]).reduce((a,l)=>a+l.venues.reduce((c,u)=>c+u.rounds.length,0),0),i={scheduledDatesCount:(r=t.scheduledDates)==null?void 0:r.length,noTimeMatchUpIdsCount:n(t==null?void 0:t.noTimeMatchUpIds),scheduledMatchUpIdsCount:n(t==null?void 0:t.scheduledMatchUpIds),overLimitMatchUpIdsCount:n(t==null?void 0:t.overLimitMatchUpIds),requestConflictsCount:n(t==null?void 0:t.requestConflicts),profileRoundsCount:o},s={itemType:Y8,itemValue:i};for(const a of Object.values(e))Fo({tournamentRecord:a,timeItem:s})}var K8=Object.defineProperty,Q8=Object.defineProperties,J8=Object.getOwnPropertyDescriptors,_w=Object.getOwnPropertySymbols,Z8=Object.prototype.hasOwnProperty,X8=Object.prototype.propertyIsEnumerable,Iw=(t,e,r)=>e in t?K8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,e9=(t,e)=>{for(var r in e||(e={}))Z8.call(e,r)&&Iw(t,r,e[r]);if(_w)for(var r of _w(e))X8.call(e,r)&&Iw(t,r,e[r]);return t},t9=(t,e)=>Q8(t,J8(e));function r9({schedulingProfileModifications:t,checkPotentialRequestConflicts:e,scheduleCompletedMatchUps:r,schedulingProfileIssues:n,dateSchedulingProfiles:o,containedStructureIds:i,matchUpDependencies:s,matchUpDailyLimits:a,clearScheduleDates:l,schedulingProfile:c,tournamentRecords:u,personRequests:p,periodLength:d,matchUps:v,courts:f,dryRun:m}){var h,g,_,I,P,y,S;const O={},b={},w={},T={},$={},N={},E={},A={},U={},C={};for(const R of o){const j=Re(R==null?void 0:R.scheduleDate),G=(R==null?void 0:R.venues)||[],W={},q={},F=(K,Q)=>{K.forEach(J=>{const te=q[J].counters;te[Q]?te[Q]+=1:te[Q]=1,te[Pn]?te[Pn]+=1:te[Pn]=1})};w[j]={},T[j]={},O[j]={},b[j]={},E[j]=[],A[j]=[],U[j]=[],C[j]=[];const L={};v.forEach(K=>{var Q;(Q=K.schedule)!=null&&Q.scheduledDate&&io(j,Re(K.schedule.scheduledDate))&&Ya({matchUpPotentialParticipantIds:W,matchUpNotBeforeTimes:L,matchUp:K})});const{venueScheduledRoundDetails:x,allDateMatchUpIds:B}=mw({matchUpPotentialParticipantIds:W,individualParticipantProfiles:q,scheduleCompletedMatchUps:r,containedStructureIds:i,matchUpNotBeforeTimes:L,matchUpScheduleTimes:N,matchUpDependencies:s,clearScheduleDates:l,tournamentRecords:u,useGarman:!0,periodLength:d,scheduleDate:j,matchUps:v,courts:f,venues:G}),z=10;let H=0,Y;const Z=10;for(;!Y;){for(const{venueId:K}of G){let Q=0;const J=x[K];for(;J.courtsCount&&((h=J.scheduleTimes)!=null&&h.length)&&((g=J.matchUpsToSchedule)!=null&&g.length)&&Q<=J.courtsCount;){const{scheduleTime:te,attempts:ne=0}=J.scheduleTimes.shift(),ee=J.matchUpsToSchedule.find(oe=>{var ie,ae;const{matchUpId:se,matchUpType:ye}=oe,{participantIdsAtLimit:Ie,relevantParticipantIds:pe}=Mm({matchUpPotentialParticipantIds:W,individualParticipantProfiles:q,matchUpDailyLimits:a,matchUp:oe});if(Ie.length)return A[j].includes(se)||A[j].push(se),!1;const{scheduledDependent:fe}=uw({matchUpScheduleTimes:N,matchUpDependencies:s,scheduleTime:te,matchUpId:se,details:J});if(fe)return!1;const{dependenciesScheduled:ve,remainingDependencies:le}=$m({matchUpScheduleTimes:N,matchUpDependencies:s,allDateMatchUpIds:B,matchUp:oe});if(!ve)return T[j][se]||(T[j][se]=[]),T[j][se].push({scheduleTime:te,remainingDependencies:le}),!1;const{enoughTime:be}=Cm({individualParticipantProfiles:q,matchUpNotBeforeTimes:L,matchUpDependencies:s,scheduleTime:te,details:J,matchUp:oe});if(!be)return w[j][se]||(w[j][se]=[]),w[j][se].push({scheduleTime:te}),!1;const Me=J.greatestAverageMinutes,{conflicts:Pe}=Nm({potentials:e,averageMatchUpMinutes:Me,requestConflicts:C,personRequests:p,scheduleTime:te,scheduleDate:j,matchUp:oe});if(Pe!=null&&Pe.length)return $[j]||($[j]=[]),$[j].push(...Pe),!1;F(pe,ye);const xe=(ae=(ie=J.minutesMap)==null?void 0:ie[se])==null?void 0:ae.recoveryMinutes;return wc({matchUpPotentialParticipantIds:W,individualParticipantProfiles:q,matchUpNotBeforeTimes:L,averageMatchUpMinutes:Me,matchUpDependencies:s,recoveryMinutes:xe,scheduleTime:te,matchUp:oe}),N[se]=te,!0});J.matchUpsToSchedule=J.matchUpsToSchedule.filter(({matchUpId:oe})=>oe!==(ee==null?void 0:ee.matchUpId)),ee?Q+=1:(b[j][K]||(b[j][K]=[]),b[j][K].push({scheduleTime:te,attempts:ne+1}))}(_=J.matchUpsToSchedule)!=null&&_.length&&(b[j][K]=(I=b[j][K])==null?void 0:I.filter(te=>{const ne=te.attempts<z;return ne&&J.scheduleTimes.push(te),!ne})),(!((P=J.scheduleTimes)!=null&&P.length)||!((y=J.matchUpsToSchedule)!=null&&y.length))&&(J.complete=!0)}H+=1,Y=G.every(({venueId:K})=>x[K].complete)||H===Z}for(const{venueId:K}of G){const Q=x[K].matchUpMap;Object.keys(Q).forEach(J=>{const te=u[J];te&&Object.keys(Q[J]).forEach(ne=>{const{drawDefinition:ee}=Jo({tournamentRecord:te,drawId:ne});ee&&Q[J][ne].forEach(({matchUpId:ie})=>{const ae=N[ie];if(ae){const se=ae.split(":").map(oo).join(":"),ye=`${Re(j)}T${se}`;m?E[j].push(ie):(Gi({drawDefinition:ee,scheduledTime:ye,matchUpId:ie}).success&&E[j].push(ie),K&&ja({tournamentRecord:te,drawDefinition:ee,matchUpId:ie,venueId:K}))}})})}),U[j]=x[K].matchUpsToSchedule.map(Jt),O[j][K]=x[K].scheduleTimes.sort((J,te)=>Le(J.scheduleTime)-Le(te.scheduleTime))}for(const K of R.venues)for(const Q of K.rounds){const te=(((S=Q.matchUps)==null?void 0:S.map(({matchUpId:ee})=>ee))||[]).filter(ee=>E[j].includes(ee));Q.canScheduledMatchUpIds=te;let ne=Math.round(te.length/Q.matchUpsCount*1e4)/100;(ne===1/0||isNaN(ne))&&(ne=0),Q.possibleToSchedulePct=ne,Q.matchUpsCount===te.length&&(Q.possibleToSchedule=!0)}}const M=o.map(({scheduleDate:R})=>R),D={timeStamp:Date.now(),overLimitMatchUpIds:A,scheduledMatchUpIds:E,schedulingProfile:c,noTimeMatchUpIds:U,requestConflicts:C,scheduledDates:M};return gw({tournamentRecords:u,autoSchedulingAudit:D}),t9(e9({},V),{schedulingProfileModifications:t,schedulingProfileIssues:n,scheduleTimesRemaining:O,dateSchedulingProfiles:o,skippedScheduleTimes:b,recoveryTimeDeferredMatchUpIds:w,dependencyDeferredMatchUpIds:T,matchUpScheduleTimes:N,overLimitMatchUpIds:A,scheduledMatchUpIds:E,noTimeMatchUpIds:U,requestConflicts:C,scheduledDates:M})}function Pw({averageMinutes:t,startTime:e,endTime:r,court:n,date:o}){if(!Array.isArray(n.dateAvailability))return{error:_e,stack:"getEarliestCourtTime"};const i=Ma({scheduleDate:o,courts:[n],startTime:!0}),s=Ma({scheduleDate:o,courts:[n],endTime:!0});e=e||i,r=r||s;const a=lc({court:n,date:o}),l=Ca({courtDate:a}),c=$t(e),u=$t(r);return{earliestCourtTime:l.reduce((d,v)=>{const f=$t(v.startTime),m=$t(v.endTime);if(f>u||m<c)return d;const h=c>f?c:f;if(Sl(h,m)>=t){const I=at(h.toISOString());(!d||I<d)&&(d=I)}return d},void 0),courtStartTime:i,courtEndTime:s}}var n9=Object.defineProperty,o9=Object.defineProperties,i9=Object.getOwnPropertyDescriptors,yw=Object.getOwnPropertySymbols,s9=Object.prototype.hasOwnProperty,a9=Object.prototype.propertyIsEnumerable,Sw=(t,e,r)=>e in t?n9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l9=(t,e)=>{for(var r in e||(e={}))s9.call(e,r)&&Sw(t,r,e[r]);if(yw)for(var r of yw(e))a9.call(e,r)&&Sw(t,r,e[r]);return t},c9=(t,e)=>o9(t,i9(e));function u9({schedulingProfileModifications:t,checkPotentialRequestConflicts:e,scheduleCompletedMatchUps:r,schedulingProfileIssues:n,dateSchedulingProfiles:o,containedStructureIds:i,matchUpDependencies:s,matchUpDailyLimits:a,clearScheduleDates:l,tournamentRecords:c,periodLength:u=30,schedulingProfile:p,personRequests:d,matchUps:v,courts:f,dryRun:m}){var h;const g={},_={},I={},P={},y={},S={},O={},b={},w={};for(const N of o){const E=Re(N==null?void 0:N.scheduleDate),A=(N==null?void 0:N.venues)||[],U={},C={},M=(Z,K)=>{Z.forEach(Q=>{const J=C[Q].counters;J[K]?J[K]+=1:J[K]=1,J[Pn]?J[Pn]+=1:J[Pn]=1})};g[E]={},_[E]={},S[E]=[],O[E]=[],b[E]=[],w[E]=[];const D={};v.forEach(Z=>{var K;(K=Z.schedule)!=null&&K.scheduledDate&&io(E,Re(Z.schedule.scheduledDate))&&Ya({matchUpPotentialParticipantIds:U,matchUpNotBeforeTimes:D,matchUp:Z})});const{allDateScheduledMatchUpIds:R,venueScheduledRoundDetails:j,allDateMatchUpIds:G}=mw({matchUpPotentialParticipantIds:U,individualParticipantProfiles:C,scheduleCompletedMatchUps:r,containedStructureIds:i,matchUpNotBeforeTimes:D,matchUpScheduleTimes:y,matchUpDependencies:s,clearScheduleDates:l,tournamentRecords:c,periodLength:u,scheduleDate:E,matchUps:v,courts:f,venues:A}),W=v.filter(({matchUpId:Z})=>R.includes(Z)),{bookings:q}=Am({dateScheduledMatchUps:W,tournamentRecords:c,scheduleDate:E,periodLength:u}),{virtualCourts:F}=Lv({scheduleDate:E,periodLength:u,bookings:q,courts:f}),L=F==null?void 0:F.reduce((Z,K)=>{const{earliestCourtTime:Q,courtEndTime:J}=Pw({date:E,averageMinutes:0,court:K});return(!Z.startTime||$t(Q)<$t(Z.startTime))&&(Z.startTime=Q),(!Z.endTime||$t(J)>$t(Z.endTime))&&(Z.endTime=J),Z},{});let x=L.startTime;const B=({courtId:Z,booking:K})=>{var Q;return(Q=F==null?void 0:F.find(J=>J.courtId===Z))==null?void 0:Q.dateAvailability[0].bookings.push(K)},z=10;let H=0,Y;for(;!Y;){for(const{venueId:Z}of A){const K=j[Z],Q=K.matchUpsToSchedule.length,J=[],te=[];let ne,ee=0;for(;!ne;){for(const oe of K.matchUpsToSchedule){if(te.length===K.courtsCount||J.length===K.courtsCount){ne=!0;break}const{matchUpId:ie,matchUpType:ae}=oe,{participantIdsAtLimit:se,relevantParticipantIds:ye}=Mm({matchUpPotentialParticipantIds:U,individualParticipantProfiles:C,matchUpDailyLimits:a,matchUp:oe});if(se.length){O[E].includes(ie)||O[E].push(ie);continue}const{dependenciesScheduled:Ie,remainingDependencies:pe}=$m({matchUpScheduleTimes:y,matchUpDependencies:s,allDateMatchUpIds:G,matchUp:oe});if(!Ie){_[E][ie]||(_[E][ie]=[]),_[E][ie].push({remainingDependencies:pe});continue}const fe=[],ve=F==null?void 0:F.reduce((le,be)=>{var Me,Pe,xe,Be;if(te.includes(be.courtId))return le;const{earliestCourtTime:qe}=Pw({averageMinutes:K.greatestAverageMinutes,startTime:x,date:E,court:be});if(le.scheduleTime&&Le(qe)>=Le(le.scheduleTime))return le;const{scheduledDependent:$e}=uw({matchUpScheduleTimes:y,matchUpDependencies:s,scheduleTime:qe,matchUpId:ie,details:K});if($e)return le;const{enoughTime:De}=Cm({individualParticipantProfiles:C,matchUpNotBeforeTimes:D,matchUpDependencies:s,scheduleTime:qe,details:K,matchUp:oe});if(!De)return g[E][ie]||(g[E][ie]=[]),g[E][ie].includes(qe)||g[E][ie].push(qe),le;const me=((Pe=(Me=K.minutesMap)==null?void 0:Me[ie])==null?void 0:Pe.averageMinutes)||K.greatestAverageMinutes,{conflicts:ge}=Nm({potentials:e,averageMatchUpMinutes:me,requestConflicts:w,personRequests:d,scheduleTime:qe,scheduleDate:E,matchUp:oe});if(ge!=null&&ge.length)return fe.push(...ge),!1;M(ye,ae);const Se=(Be=(xe=K.minutesMap)==null?void 0:xe[ie])==null?void 0:Be.recoveryMinutes;return wc({matchUpPotentialParticipantIds:U,individualParticipantProfiles:C,matchUpNotBeforeTimes:D,averageMatchUpMinutes:me,matchUpDependencies:s,recoveryMinutes:Se,scheduleTime:qe,matchUp:oe}),(!le.scheduleTime||Le(qe)<Le(le.scheduleTime))&&(le.averageMatchUpMinutes=me,le.recoveryMinutes=Se,le.scheduleTime=qe,le.courtName=be.courtName,le.courtId=be.courtId),le},{});if(ve.scheduleTime){const{averageMatchUpMinutes:le,recoveryMinutes:be,scheduleTime:Me,courtId:Pe}=ve;y[ie]=Me,P[ie]=Pe,J.push(ie),te.push(Pe);const xe=Me,Be=Or(xe,le);B({courtId:Pe,booking:{averageMatchUpMinutes:le,recoveryMinutes:be,periodLength:u,matchUpId:ie,startTime:xe,courtId:Pe,endTime:Be,venueId:Z}}),K.matchUpsToSchedule=K.matchUpsToSchedule.filter($e=>$e.matchUpId!==ie)}else fe!=null&&fe.length&&(I[E]||(I[E]=[]),I[E].push(...fe))}(te.length===K.courtsCount||J.length===K.courtsCount||!K.matchUpsToSchedule.length)&&(ne=!0),K.matchUpsToSchedule.length&&J<K.courtsCount&&($t(x)<$t(L.endTime)?x=Or(x,u):(ne=!0,K.complete=!0)),ee+=1,!ne&&ee>=Q&&(ne=!0)}(h=K.matchUpsToSchedule)!=null&&h.length||(K.complete=!0)}H+=1,Y=A.every(({venueId:Z})=>j[Z].complete)||H===z}for(const{venueId:Z}of A){const K=j[Z].matchUpMap;Object.keys(K).forEach(Q=>{const J=c[Q];J&&Object.keys(K[Q]).forEach(te=>{const{drawDefinition:ne}=Jo({tournamentRecord:J,drawId:te});ne&&K[Q][te].forEach(({matchUpId:oe})=>{const ie=y[oe],ae=P[oe];if(ie){const se=ie.split(":").map(oo).join(":"),ye=`${Re(E)}T${se}`;m||(Gi({drawDefinition:ne,scheduledTime:ye,matchUpId:oe}),Ds({courtDayDate:E,tournamentRecords:c,tournamentRecord:J,drawDefinition:ne,matchUpId:oe,courtId:ae})),S[E].push(oe)}})})}),b[E]=j[Z].matchUpsToSchedule.map(Jt)}for(const Z of N.venues)for(const K of Z.rounds){const J=K.matchUps.map(({matchUpId:ne})=>ne).filter(ne=>S[E].includes(ne));K.canScheduledMatchUpIds=J;let te=Math.round(J.length/K.matchUpsCount*1e4)/100;(te===1/0||isNaN(te))&&(te=0),K.possibleToSchedulePct=te,K.matchUpsCount===J.length&&(K.possibleToSchedule=!0)}}const T=o.map(({scheduleDate:N})=>N),$={timeStamp:Date.now(),overLimitMatchUpIds:O,scheduledMatchUpIds:S,schedulingProfile:p,noTimeMatchUpIds:b,requestConflicts:w,scheduledDates:T};return gw({tournamentRecords:c,autoSchedulingAudit:$}),c9(l9({},V),{schedulingProfileModifications:t,schedulingProfileIssues:n,dateSchedulingProfiles:o,recoveryTimeDeferredMatchUpIds:g,dependencyDeferredMatchUpIds:_,matchUpScheduleTimes:y,overLimitMatchUpIds:O,scheduledMatchUpIds:S,noTimeMatchUpIds:b,requestConflicts:w,scheduledDates:T})}var d9=Object.defineProperty,Ow=Object.getOwnPropertySymbols,p9=Object.prototype.hasOwnProperty,f9=Object.prototype.propertyIsEnumerable,bw=(t,e,r)=>e in t?d9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tw=(t,e)=>{for(var r in e||(e={}))p9.call(e,r)&&bw(t,r,e[r]);if(Ow)for(var r of Ow(e))f9.call(e,r)&&bw(t,r,e[r]);return t};function Ka({tournamentRecords:t,requestType:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const r={};for(const n of Object.values(t)){const{extension:o}=Fr({name:va,tournamentRecord:n}),i=(o==null?void 0:o.value)||[];for(const s of i){const{personId:a,requests:l}=s||{};r[a]||(r[a]=[]);for(const c of l)e&&c.requestType!==e||r[a].push(c)}}return{personRequests:r}}function Dm({tournamentRecords:t,personRequests:e}){var r;if(!t)return{error:ke};if(!e)return Tw({},V);const n=Object.values(t);for(const o of n){const i=(r=o.participants)!=null?r:[],s=[];for(const a of Object.keys(e))if(Eo({tournamentParticipants:i,personId:a})){const l=e[a];l.length&&s.push({personId:a,requests:l})}Object.keys(s).length&&Ei({tournamentRecord:o,extension:{name:va,value:s}})}return Tw({},V)}function v9({tournamentRecords:t,personId:e,requests:r}){if(!t)return{error:ke};if(typeof e!="string")return{error:X};if(!Array.isArray(r))return{error:X};const{personRequests:n}=Ka({tournamentRecords:t}),{mergeCount:o}=ww({personRequests:n,personId:e,requests:r});return o&&n?Dm({tournamentRecords:t,personRequests:n}):{error:X}}function ww({personRequests:t,personId:e,requests:r}){t[e]||(t[e]=[]);const n=r.filter(({requestType:o})=>o).map(o=>{let{date:i,startTime:s,endTime:a}=o;return o.requestType===Vd&&(i=Re(i),s=at(s),a=at(a),i&&s&&a)?{date:i,startTime:s,endTime:a,requestType:o.requestType}:o}).filter(Boolean);for(const o of n)o.requestId=C_(),t[e].push(o);return{mergeCount:n.length}}function m9({tournamentRecords:t,requestType:e,requestId:r,personId:n,date:o}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const{personRequests:i}=Ka({tournamentRecords:t}),s=l=>{var c;i&&(i[l]=i[l].filter(u=>(!e||u.requestType!==e)&&(!r||u.requestId!==r)&&(!o||u.date!==o)),(c=i==null?void 0:i[l])!=null&&c.length||delete i[l])},a=!e&&!r&&!n&&!o;if(!a){if(n&&(i!=null&&i[n]))s(n);else if(i)for(const l of Object.keys(i))s(l)}return a||!i||!Object.keys(i).length?Tu({tournamentRecords:t,name:va}):Dm({tournamentRecords:t,personRequests:i})}function h9({tournamentRecords:t,requests:e,personId:r}){if(!t)return{error:ke};if(!Array.isArray(e))return{error:X};const n=e.map(({requestId:a})=>a).filter(Boolean),{personRequests:o}=Ka({tournamentRecords:t}),i=a=>{o&&(o[a]=o[a].map(l=>{if(!n.includes(l.requestId))return l;const c=e.find(u=>u.requestId===l.requestId);if(c.requestType)return Object.assign(l,c)}).filter(Boolean))};if(r&&(o!=null&&o[r]))i(r);else if(o)for(const a of Object.keys(o))i(a);const s=e.filter(a=>!a.requestId);return s.length&&ww({personRequests:o,personId:r,requests:s}),Dm({tournamentRecords:t,personRequests:o})}var g9=Object.defineProperty,_9=Object.defineProperties,I9=Object.getOwnPropertyDescriptors,Ew=Object.getOwnPropertySymbols,P9=Object.prototype.hasOwnProperty,y9=Object.prototype.propertyIsEnumerable,$w=(t,e,r)=>e in t?g9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,S9=(t,e)=>{for(var r in e||(e={}))P9.call(e,r)&&$w(t,r,e[r]);if(Ew)for(var r of Ew(e))y9.call(e,r)&&$w(t,r,e[r]);return t},O9=(t,e)=>_9(t,I9(e));function jm({scheduleAttributes:t=["scheduledDate","scheduledTime"],ignoreMatchUpStatuses:e=Yt,tournamentRecord:r,scheduledDates:n,venueIds:o=[]}){if(typeof r!="object")return{error:re};if(!Array.isArray(e)||!Array.isArray(o))return{error:X};o.length&&t.push("venueId");const s=(Wt({matchUpFilters:{scheduledDates:n},tournamentRecord:r}).matchUps||[]).filter(c=>c.matchUpStatus&&!e.includes(c.matchUpStatus)&&yc({schedule:c.schedule,scheduleAttributes:t})&&(!(o!=null&&o.length)||o.includes(c.schedule.venueId))).map(Jt),a=Wt({tournamentRecord:r,inContext:!1}).matchUps||[];let l=0;for(const c of a)s.includes(c.matchUpId)&&(c.timeItems=(c.timeItems||[]).filter(u=>(u==null?void 0:u.itemType)&&![Xo,hs,jl,Rl,Fl].includes(u==null?void 0:u.itemType)),l+=1);return O9(S9({},V),{clearedScheduleCount:l})}var b9=Object.defineProperty,Nw=Object.getOwnPropertySymbols,T9=Object.prototype.hasOwnProperty,w9=Object.prototype.propertyIsEnumerable,Uw=(t,e,r)=>e in t?b9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,E9=(t,e)=>{for(var r in e||(e={}))T9.call(e,r)&&Uw(t,r,e[r]);if(Nw)for(var r of Nw(e))w9.call(e,r)&&Uw(t,r,e[r]);return t};function Aw({scheduleAttributes:t=["scheduledDate","scheduledTime"],ignoreMatchUpStatuses:e=Yt,tournamentRecords:r,scheduledDates:n,venueIds:o}){const i=rs(r)?Object.values(r).map(({tournamentId:s})=>s).filter(Boolean):[];if(!(i!=null&&i.length))return{error:ke};for(const s of i){const a=r[s],l=jm({ignoreMatchUpStatuses:e,scheduleAttributes:t,tournamentRecord:a,scheduledDates:n,venueIds:o});if(l.error)return l}return E9({},V)}function Cw({tournamentRecord:t}){var e;if(!t)return{error:re};const{policy:r}=cs({policyType:$f,tournamentRecord:t}),{extension:n}=Fr({name:ss,tournamentRecord:t}),o=(e=n==null?void 0:n.value)==null?void 0:e.dailyLimits,i=r==null?void 0:r.defaultDailyLimits;return{matchUpDailyLimits:o||i}}function Mw({tournamentRecords:t,tournamentId:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const r=Object.keys(t).filter(o=>!e||o===e);let n;return r.forEach(o=>{const i=t[o],{matchUpDailyLimits:s}=Cw({tournamentRecord:i});n=s}),{matchUpDailyLimits:n}}function Rm({checkPotentialRequestConflicts:t=!0,scheduleCompletedMatchUps:e,clearScheduleDates:r,scheduleDates:n=[],tournamentRecords:o,periodLength:i,dryRun:s,pro:a}){if(!o)return{error:ke};if(!Array.isArray(n))return{error:X};const l=za({tournamentRecords:o});if(l.error)return l;const{schedulingProfile:c=[],issues:u=[],modifications:p}=l,d=Object.assign({},...Object.values(o).map(S=>Ra({tournamentRecord:S}).containedStructures)),v=n.map(S=>{if(Gr(S))return Re(S)}).filter(Boolean),f=c.map(S=>S.scheduleDate).map(S=>Gr(S)&&Re(S)).filter(S=>S&&(!n.length||v.includes(S)));if(!f.length)return{error:Ix};if(r&&!s){const S=Array.isArray(r)?r:[];Aw({tournamentRecords:o,scheduledDates:S})}const{courts:m}=Ms({dates:n,ignoreDisabled:!0,tournamentRecords:o}),{matchUps:h}=Ro({matchUpFilters:{matchUpTypes:[At,dt]},afterRecoveryTimes:!0,nextMatchUps:!0,tournamentRecords:o}),{matchUpDependencies:g}=cn({includeParticipantDependencies:!0,tournamentRecords:o,matchUps:h}),{matchUpDailyLimits:_}=Mw({tournamentRecords:o}),{personRequests:I}=Ka({requestType:Vd,tournamentRecords:o}),P=c.filter(S=>{const O=Re(S==null?void 0:S.scheduleDate);return f.includes(O)}).sort((S,O)=>new Date(S.scheduleDate).getTime()-new Date(O.scheduleDate).getTime()),y={schedulingProfileModifications:p,checkPotentialRequestConflicts:t,scheduleCompletedMatchUps:e,schedulingProfileIssues:u,dateSchedulingProfiles:P,containedStructureIds:d,matchUpDependencies:g,matchUpDailyLimits:_,clearScheduleDates:r,tournamentRecords:o,schedulingProfile:c,personRequests:I,periodLength:i,matchUps:h,dryRun:s,courts:m};return a?u9(y):r9(y)}function Dw({event:t}){return t?Ou({event:t,name:Wn}):{error:Ge}}function $9({tournamentRecords:t,eventId:e}){if(!t)return{error:ke};if(typeof e!="string")return{error:_e,info:"missing eventId"};for(const r of Object.values(t)){const{event:n}=Qt({tournamentRecord:r,eventId:e});if(n)return Dw({event:n})}return{error:Ar}}function N9(t){Object.assign(t,{inContext:!0});const{matchUp:e,error:r}=Ec(t);return{matchUp:de(e,!0,!0),error:r}}function Ec({participantsProfile:t,afterRecoveryTimes:e,tournamentRecord:r,contextContent:n,contextProfile:o,drawDefinition:i,matchUpId:s,inContext:a,eventId:l,drawId:c,event:u}){if(!r)return{error:re};if(typeof s!="string")return{error:Vt};if(!i||!u){const h=(Wt({tournamentRecord:r}).matchUps||[]).find(g=>g.matchUpId===s);if(!h)return{error:ir};({eventId:l,drawId:c}=h),{event:u,drawDefinition:i}=Qt({tournamentRecord:r,eventId:l,drawId:c})}if(!i)return{error:en};o&&!n&&(n=wo({tournamentRecord:r,contextProfile:o}));const p={surfaceCategory:(u==null?void 0:u.surfaceCategory)||r.surfaceCategory,indoorOutDoor:(u==null?void 0:u.indoorOutdoor)||r.indoorOutdoor,endDate:(u==null?void 0:u.endDate)||r.endDate,tournamentId:r.tournamentId,eventId:l||(u==null?void 0:u.eventId),drawId:c},{participants:d=[]}=As({participantsProfile:t,tournamentRecord:r,contextProfile:o,inContext:a}),{matchUp:v,structure:f}=lt({context:a?p:void 0,tournamentParticipants:d,afterRecoveryTimes:e,contextContent:n,drawDefinition:i,contextProfile:o,matchUpId:s,inContext:a,event:u});return{matchUp:v,structure:f,drawDefinition:i}}function Fm({tournamentParticipants:t,tournamentRecord:e,drawDefinition:r,participantId:n,matchUpId:o,matchUp:i,event:s}){if(!n)return{error:Et};if(!o)return{error:jr};if(t=t??(e==null?void 0:e.participants),t!=null&&t.length){if(!i&&r){const p=lt({tournamentParticipants:t,inContext:!0,drawDefinition:r,matchUpId:o,event:s});if(!p.matchUp)return{error:ir};i=p.matchUp}const l=ec({matchUp:i});if(l.error)return l;const{checkedInParticipantIds:c,allRelevantParticipantIds:u}=l;if(!u.includes(n))return{error:So};if(c.includes(n))return{error:l_}}return Dr({tournamentRecord:e,drawDefinition:r,matchUpId:o,timeItem:{itemType:Qf,itemValue:n}})}function xm({tournamentParticipants:t,tournamentRecord:e,drawDefinition:r,participantId:n,matchUpId:o,matchUp:i,event:s}){if(!n)return{error:Et};if(!o&&!i)return{error:Vt};if(t=t??(e==null?void 0:e.participants),!i){const u=lt({tournamentParticipants:t,inContext:!0,drawDefinition:r,matchUpId:o,event:s});if(u.error)return u;if(!u.matchUp)return{error:ir};i=u.matchUp}const{matchUpStatus:a,score:l}=i;if(a&&H_.includes(a)||a&&Yt.includes(a)||Gt({score:l}))return{error:rx};if(t!=null&&t.length){const{checkedInParticipantIds:u,allRelevantParticipantIds:p}=ec({matchUp:i});if(!(p!=null&&p.includes(n)))return{error:So};if(!u.includes(n))return{error:Ux};const{sideParticipantIds:d,nestedIndividualParticipantIds:v}=dv({matchUp:i}),f=d.indexOf(n);[0,1].includes(f)&&(v[f]||[]).forEach(m=>{Dr({drawDefinition:r,matchUpId:o,timeItem:{itemType:Jf,itemValue:m}})})}return Dr({tournamentRecord:e,drawDefinition:r,matchUpId:o,timeItem:{itemType:Jf,itemValue:n}})}function jw(t){if(!(t!=null&&t.tournamentRecord))return{error:re};const{tournamentRecord:e,participantId:r,matchUpId:n,drawDefinition:o,event:i}=t,s=e.participants||[],a=Ec({tournamentRecord:e,inContext:!0,drawDefinition:o,matchUpId:n,event:i});if(!a.matchUp)return{error:ir};const l=a.matchUp,{checkedInParticipantIds:c=[]}=ec({matchUp:l});return c.includes(r)?xm({tournamentParticipants:s,tournamentRecord:e,drawDefinition:o,participantId:r,matchUpId:n,matchUp:l}):Fm({tournamentParticipants:s,tournamentRecord:e,drawDefinition:o,participantId:r,matchUpId:n,matchUp:l})}function U9(t){const{tournamentRecords:e}=t,{participantId:r,tournamentId:n,matchUpId:o,drawId:i}=t;if(!e||!n||!r||!o)return{error:_e,stack:"toggleParticipantCheckInState"};const s=e[n],{drawDefinition:a,event:l}=Jo({tournamentRecord:s,drawId:i});return Object.assign(t,{drawDefinition:a,event:l,tournamentRecord:s}),jw(t)}function Rw(t){var e;const{tournamentRecords:r}=t;if(!r)return{error:ke};const{removePriorValues:n,tournamentId:o,courtDayDate:i,matchUpId:s,courtId:a,drawId:l}=t,c=r[o];if(!c)return{error:re};const{drawDefinition:u,event:p}=Jo({tournamentRecord:c,drawId:l}),d=lt({drawDefinition:u,event:p,matchUpId:s});if(d.error)return d;if(((e=d==null?void 0:d.matchUp)==null?void 0:e.matchUpType)===hn){const{itemValue:v}=Ni({timeItems:d.matchUp.timeItems||[],itemType:Xo}),f=a&&v.filter(h=>h.courtId!==a);return Dr({duplicateValues:!1,removePriorValues:n,tournamentRecord:c,drawDefinition:u,matchUpId:s,timeItem:{itemType:Xo,itemValue:f}})}else return Ds({tournamentRecord:c,drawDefinition:u,courtDayDate:i,courtId:"",matchUpId:s})}function A9({tournamentRecords:t}){return HT({extensionName:ss,tournamentRecords:t})}var C9=Object.defineProperty,M9=Object.defineProperties,D9=Object.getOwnPropertyDescriptors,Fw=Object.getOwnPropertySymbols,j9=Object.prototype.hasOwnProperty,R9=Object.prototype.propertyIsEnumerable,xw=(t,e,r)=>e in t?C9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Vs=(t,e)=>{for(var r in e||(e={}))j9.call(e,r)&&xw(t,r,e[r]);if(Fw)for(var r of Fw(e))R9.call(e,r)&&xw(t,r,e[r]);return t},Bd=(t,e)=>M9(t,D9(e));const{stageOrder:Lw}=gG;function Lm({tournamentRecords:t,schedulingProfile:e,tournamentRecord:r,withRoundId:n}){if(r&&!t){if(typeof r!="object")return{error:Yc};t={[r.tournamentId]:r}}if(e){const s=Rd({tournamentRecords:t,schedulingProfile:e});if(s.error)return s}if(!e&&t){const s=za({tournamentRecords:t});if(s.error)return s;e=s.schedulingProfile}if(!e)return{error:sr};const o={};return{profileRounds:e.map(({venues:s,scheduleDate:a})=>s.map(({rounds:l})=>l.map(c=>{var u;const p=Vm(c);return(u=p.roundSegment)!=null&&u.segmentsCount&&(o[p.id]=p.roundSegment.segmentsCount),Oe(Vs({id:n?p.id:void 0,scheduleDate:a},p))}))).flat(1/0),segmentedRounds:o}}function Vm(t){const{containerStructureId:e,roundSegment:r,isRoundRobin:n,tournamentId:o,roundNumber:i,structureId:s,eventId:a,drawId:l}=t,c=n?e:s,u=[o,a,l,c,i].join("|");return Oe({id:u,roundSegment:r,tournamentId:o,eventId:a,drawId:l,structureId:c,roundNumber:i})}function Vw(t){const e=t.length,r=t.filter(({sides:u})=>u==null?void 0:u.some(({bye:p})=>p)).length||0,n=t.filter(({winningSide:u,matchUpStatus:p})=>u||Yt.includes(p)).length||0,o=t.filter(({schedule:u})=>(u==null?void 0:u.scheduledDate)&&(u==null?void 0:u.scheduledTime)).length||0,i=e-r,s=i===n,a=i-o,l=i-o;return{unscheduledCount:a,incompleteCount:l,scheduledCount:o,completedCount:n,matchUpsCount:e,isScheduled:i===o,isComplete:s,byeCount:r}}function Bw({excludeScheduleDateProfileRounds:t,excludeScheduledRounds:e,excludeCompletedRounds:r,inContextMatchUps:n,tournamentRecords:o,schedulingProfile:i,tournamentRecord:s,withSplitRounds:a,matchUpFilters:l,withRoundId:c,context:u}){var p;if(n&&!Array.isArray(n||typeof n[0]!="object"))return{error:X,inContextMatchUps:n};if(s&&!o){if(typeof s!="object")return{error:Yc};o={[s.tournamentId]:s}}const d=typeof o!="object"||!Object.keys(o).length;if((!n||!i&&(t||r||i||a))&&d)return{error:ke};const f=Object.values(o??{}).map(({events:y})=>y).flat(),{segmentedRounds:m,profileRounds:h}=o&&(t||r||i||a)&&Lm({tournamentRecords:o,schedulingProfile:i})||{},g=t&&Object.assign({},...h.map(y=>({[y.id]:y}))),_=n||o&&((p=Ro({tournamentRecords:o,matchUpFilters:l}))==null?void 0:p.matchUps)||[],I=[],P=_&&Object.values(_.reduce((y,S)=>{var O,b;const w=Vm(S).id,T=m==null?void 0:m[w],$=[...(b=(O=y[w])==null?void 0:O.matchUps)!=null?b:[],S],{containerStructureId:N,stageSequence:E,structureName:A,tournamentId:U,isRoundRobin:C,matchUpType:M,roundNumber:D,roundOffset:R,structureId:j,eventName:G,roundName:W,drawName:q,eventId:F,drawId:L}=S,x=C?N:j;return Bd(Vs({},y),{[w]:{id:c?w:void 0,structureId:x,stageSequence:E,segmentsCount:T,structureName:A,tournamentId:U,matchUpType:M,roundNumber:D,roundOffset:R,eventName:G,roundName:W,drawName:q,matchUps:$,eventId:F,drawId:L}})},{})).map(y=>{const{minFinishingSum:S,winnerFinishingPositionRange:O}=x9(y.matchUps),b=y.segmentsCount;if(b){const C=y.matchUps.length/b;return qt(y.matchUps.sort((D,R)=>D.roundPosition-R.roundPosition),C).map((D,R)=>{const{unscheduledCount:j,incompleteCount:G,matchUpsCount:W,isScheduled:q,isComplete:F,byeCount:L}=Vw(D),x=kw({matchUps:y.matchUps,tournamentRecords:o,events:f,round:y});return Oe(Bd(Vs(Vs({},y),u),{roundSegment:{segmentsCount:b,segmentNumber:R+1},winnerFinishingPositionRange:O,unscheduledCount:j,incompleteCount:G,minFinishingSum:S,matchUpsCount:W,isScheduled:q,roundTiming:x,isComplete:F,byeCount:L,matchUps:D}))})}const{unscheduledCount:w,incompleteCount:T,matchUpsCount:$,isScheduled:N,isComplete:E,byeCount:A}=Vw(y.matchUps),U=kw({matchUps:y.matchUps,tournamentRecords:o,events:f,round:y});return Oe(Bd(Vs(Vs({},y),u),{winnerFinishingPositionRange:O,unscheduledCount:w,incompleteCount:T,minFinishingSum:S,matchUpsCount:$,isScheduled:N,roundTiming:U,isComplete:E,byeCount:A}))}).flat().filter(y=>{if(t){const $=Re(t),N=c?y.id:Vm(y).id;if($&&g[N]&&Re(g[N].scheduleDate)===$)return!1}const{isComplete:S,isScheduled:O}=y,T=(!r||!S)&&(!e||!O);return T||I.push(y),T}).sort(F9)||[];return Bd(Vs({},V),{rounds:P,excludedRounds:I})}function kw({round:t,matchUps:e,events:r,tournamentRecords:n}){const o=r.find(d=>d.eventId===t.eventId),{eventType:i,category:s,categoryType:a}=o||{},{categoryName:l,ageCategoryCode:c}=s||{},u=Nr(e.map(({matchUpFormat:d})=>d));let p=0;return Object.keys(u).forEach(d=>{const v=u[d],f=Om({categoryName:l||c,tournamentId:t.tournamentId,eventId:t.eventId,tournamentRecords:n,matchUpFormat:d,categoryType:a,eventType:i});if(f.error)return f;const m=f.averageMinutes*v;isNaN(p)||(p+=m)}),{roundMinutes:p}}function F9(t,e){return t.eventName.localeCompare(e.eventName)||t.eventId.localeCompare(e.eventId)||(Lw[t==null?void 0:t.stage]||0)-(Lw[e==null?void 0:e.stage]||0)||e.matchUpsCount-t.matchUpsCount||`${t.stageSequence}-${t.roundNumber}-${t.minFinishingSum}`.localeCompare(`${e.stageSequence}-${e.roundNumber}-${e.minFinishingSum}`)}function x9(t){return(t||[]).reduce((e,r)=>{var n,o;const i=(((n=r.finishingPositionRange)==null?void 0:n.winner)||[]).reduce((a,l)=>a+l,0),s=(((o=r.finishingPositionRange)==null?void 0:o.winner)||[]).join("-")||"";return!e.minFinishingSum||i<e.minFinishingSum?{minFinishingSum:i,winnerFinishingPositionRange:s}:e},{minFinishingSum:0,winnerFinishingPositionRange:""})}function L9({tournamentRecords:t,courtAssignments:e,courtDayDate:r}){if(!t)return{error:ke};if(!Array.isArray(e))return{error:_e,info:or("courtAssignments")};const n=e.reduce((s,a)=>{const{tournamentId:l}=a;return s[l]||(s[l]=[]),s[l].push(a),s},{});let o;return Object.keys(n).every(s=>{const a=t[s];if(!a)return o={error:re},!1;const l=n[s].reduce((u,p)=>{const{drawId:d}=p;return u[d]||(u[d]=[]),u[d].push(p),u},{});Object.keys(l).every(u=>{const{drawDefinition:p}=Qt({tournamentRecord:a,drawId:u});return p?(l[u].every(d=>{const{matchUpId:v,courtId:f}=d,m=Ds({tournamentRecord:a,drawDefinition:p,courtDayDate:r,matchUpId:v,courtId:f});if(m.success)return m==null?void 0:m.success;o={error:Yx}}),!0):(o={error:ue},!1)})}),o||V}var V9=Object.defineProperty,B9=Object.defineProperties,k9=Object.getOwnPropertyDescriptors,Gw=Object.getOwnPropertySymbols,G9=Object.prototype.hasOwnProperty,W9=Object.prototype.propertyIsEnumerable,Ww=(t,e,r)=>e in t?V9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,H9=(t,e)=>{for(var r in e||(e={}))G9.call(e,r)&&Ww(t,r,e[r]);if(Gw)for(var r of Gw(e))W9.call(e,r)&&Ww(t,r,e[r]);return t},q9=(t,e)=>B9(t,k9(e));function z9({tournamentRecords:t,competitionMatchUps:e,matchUpDependencies:r,allDateMatchUpIds:n=[],averageMatchUpMinutes:o=90,recoveryMinutes:i=0,recoveryMinutesMap:s,matchUpPotentialParticipantIds:a={},individualParticipantProfiles:l={},matchUpNotBeforeTimes:c={},matchUpDailyLimits:u={},checkPotentialRequestConflicts:p=!0,remainingScheduleTimes:d,clearScheduleDates:v,periodLength:f=30,scheduleDate:m,matchUpIds:h,venueIds:g,startTime:_,endTime:I,dryRun:P}){if(!t)return{error:ke};if(!h)return{error:vl};if(!Gr(m))return{error:Sr};if(isNaN(f)||isNaN(o)||isNaN(i))return{error:X};e||({matchUps:e}=Ro({tournamentRecords:t,nextMatchUps:!0})),r||({matchUpDependencies:r}=cn({includeParticipantDependencies:!0,matchUps:e,tournamentRecords:t})),e.forEach(F=>{var L;(L=F.schedule)!=null&&L.scheduledDate&&io(m,Re(F.schedule.scheduledDate))&&Ya({matchUpPotentialParticipantIds:a,matchUpNotBeforeTimes:c,matchUp:F})});const y=h.map(F=>e.find(L=>L.matchUpId===F)).filter(Boolean),{venueId:S,scheduleTimes:O,dateScheduledMatchUpIds:b}=cw({tournamentRecords:t,remainingScheduleTimes:d,startTime:at(_),endTime:at(I),scheduleDate:Re(m),averageMatchUpMinutes:o,clearScheduleDates:v,periodLength:f,venueIds:g}),w={},T=[],$={},N={},E={};e.filter(({matchUpId:F})=>b==null?void 0:b.includes(F)).forEach(F=>{var L;Um({matchUpPotentialParticipantIds:a,individualParticipantProfiles:l,matchUp:F,value:1});const x=(L=F.schedule)==null?void 0:L.scheduledTime;if(x){$[F.matchUpId]=x;const B=s==null?void 0:s[F.matchUpId];wc({recoveryMinutes:B||i,matchUpPotentialParticipantIds:a,individualParticipantProfiles:l,matchUpNotBeforeTimes:c,averageMatchUpMinutes:o,matchUpDependencies:r,scheduleTime:x,matchUp:F})}});let U=y.filter(F=>{const L=b==null?void 0:b.includes(F.matchUpId),x=[nt,Xe,Mt,Wr,_r,ot].includes(F==null?void 0:F.matchUpStatus);return!L&&!F.winningSide&&!x});const{matchUpMap:C,overLimitMatchUpIds:M,participantIdsAtLimit:D}=U.reduce((F,L)=>{const{drawId:x,tournamentId:B,matchUpType:z}=L,{participantIdsAtLimit:H,relevantParticipantIds:Y}=Mm({individualParticipantProfiles:l,matchUpPotentialParticipantIds:a,matchUpDailyLimits:u,matchUp:L});return H!=null&&H.length?(F.overLimitMatchUpIds.push(L.matchUpId),F.participantIdsAtLimit.push(...H),F):(Y.forEach(Z=>{Tc({individualParticipantProfiles:l,participantId:Z});const K=l[Z].counters;K[z]?K[z]+=1:K[z]=1,K[Pn]?K[Pn]+=1:K[Pn]=1}),F.matchUpMap[B]||(F.matchUpMap[B]={}),F.matchUpMap[B][x]?F.matchUpMap[B][x].push(L):F.matchUpMap[B][x]=[L],Ya({matchUpPotentialParticipantIds:a,matchUpNotBeforeTimes:c,matchUp:L}),F)},{matchUpMap:{},overLimitMatchUpIds:[],participantIdsAtLimit:[]});U=U.filter(({matchUpId:F})=>!M.includes(F));let R=0;const j=(O==null?void 0:O.length)||0,{personRequests:G}=Ka({tournamentRecords:t,requestType:Vd});for(;O!=null&&O.length&&U.length&&R<=j;){R++;const{scheduleTime:F}=O.shift(),L=U.find(x=>{const{matchUpId:B}=x,{dependenciesScheduled:z,remainingDependencies:H}=$m({matchUpScheduleTimes:$,matchUpDependencies:r,allDateMatchUpIds:n,matchUp:x});if(!z)return E[B]||(E[B]=[]),E[B].push({scheduleTime:F,remainingDependencies:H}),!1;const{enoughTime:Y}=Cm({individualParticipantProfiles:l,matchUpNotBeforeTimes:c,matchUpDependencies:r,scheduleTime:F,matchUp:x});if(!Y)return N[B]||(N[B]=[]),N[B].push({scheduleTime:F}),!1;const{conflicts:Z}=Nm({potentials:p,averageMatchUpMinutes:o,requestConflicts:w,personRequests:G,scheduleTime:F,scheduleDate:m,matchUp:x});if(Z!=null&&Z.length)return!1;const K=s==null?void 0:s[x.matchUpId];return wc({recoveryMinutes:K||i,matchUpPotentialParticipantIds:a,individualParticipantProfiles:l,matchUpNotBeforeTimes:c,averageMatchUpMinutes:o,matchUpDependencies:r,scheduleTime:F,matchUp:x}),$[x.matchUpId]=F,!0});U=U.filter(({matchUpId:x})=>x!==(L==null?void 0:L.matchUpId)),L||T.push(F)}U.forEach(F=>{Um({individualParticipantProfiles:l,matchUpPotentialParticipantIds:a,value:-1,matchUp:F})});const W=[];Object.keys(C).forEach(F=>{const L=t[F];L?Object.keys(C[F]).forEach(x=>{const{drawDefinition:B}=Jo({tournamentRecord:L,drawId:x});B&&C[F][x].forEach(({matchUpId:H})=>{const Y=$[H];if(Y){const Z=Y.split(":").map(oo).join(":"),K=`${Re(m)}T${Z}`;P?W.push(H):(Gi({drawDefinition:B,matchUpId:H,scheduledTime:K}).success&&W.push(H),S&&ja({tournamentRecords:t,tournamentRecord:L,drawDefinition:B,matchUpId:H,venueId:S}))}})}):zt()&&console.log(yo)});const q=gv(U);return q9(H9({},V),{requestConflicts:Object.values(w),remainingScheduleTimes:O==null?void 0:O.map(({scheduleTime:F})=>F),individualParticipantProfiles:l,matchUpNotBeforeTimes:c,participantIdsAtLimit:D,skippedScheduleTimes:T,overLimitMatchUpIds:M,scheduledMatchUpIds:W,noTimeMatchUpIds:q,recoveryTimeDeferred:N,dependencyDeferred:E})}var Y9=Object.defineProperty,Hw=Object.getOwnPropertySymbols,K9=Object.prototype.hasOwnProperty,Q9=Object.prototype.propertyIsEnumerable,qw=(t,e,r)=>e in t?Y9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,J9=(t,e)=>{for(var r in e||(e={}))K9.call(e,r)&&qw(t,r,e[r]);if(Hw)for(var r of Hw(e))Q9.call(e,r)&&qw(t,r,e[r]);return t};function Z9(t){const e="reorderUpcomingMatchUps",{tournamentRecords:r}=t;if(typeof r!="object"||!Object.keys(r).length)return k({result:{error:ke},stack:e});const{matchUpsContextIds:n,firstToLast:o}=t;if(!n)return k({result:{error:_e},stack:e});const i=n==null?void 0:n.length;if(!i)return J9({},V);let s=0;return n.forEach((l,c)=>{const{tournamentId:u,drawId:p,matchUpId:d}=l;let v=c+(o?-1:1);v<0&&(v=i-1),v===i&&(v=0);const f=n[v].schedule.scheduledTime,m=a({tournamentId:u,scheduledTime:f,matchUpId:d,drawId:p});if(m.success)s++;else return m}),s===i?V:k({result:{error:zx},stack:e});function a({tournamentId:l,scheduledTime:c,matchUpId:u,drawId:p}){const d=r[l],{drawDefinition:v}=Jo({tournamentRecord:d,drawId:p});return Gi({drawDefinition:v,scheduledTime:c,matchUpId:u})}}var X9=Object.defineProperty,eQ=Object.defineProperties,tQ=Object.getOwnPropertyDescriptors,zw=Object.getOwnPropertySymbols,rQ=Object.prototype.hasOwnProperty,nQ=Object.prototype.propertyIsEnumerable,Yw=(t,e,r)=>e in t?X9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kw=(t,e)=>{for(var r in e||(e={}))rQ.call(e,r)&&Yw(t,r,e[r]);if(zw)for(var r of zw(e))nQ.call(e,r)&&Yw(t,r,e[r]);return t},Qw=(t,e)=>eQ(t,tQ(e));function oQ({scheduleCompletedMatchUps:t,tournamentRecords:e,scheduledDate:r,matchUps:n}){if(!Array.isArray(n))return{error:X};if(n.some(({hasContext:m})=>!m))return{info:"matchUps must have { inContext: true, nextMatchUps: true }",error:ru};let i=Em({courtCompletedMatchUps:!0,withCourtGridRows:!0,minCourtGridRows:10,tournamentRecords:e,matchUpFilters:{localPerspective:!0,scheduledDate:r}});if(i.error)return i;const{rows:s}=i,a=[],l=m=>[(m.sides||[]).map(h=>{var g;return[h.participantId,(g=h.participant)==null?void 0:g.individualParticipantIds]}),(m.potentialParticipants||[]).flat().map(h=>[h.participantId,h.individualParticipantIds])].flat(1/0).filter(Boolean),c=s==null?void 0:s.reduce((m,h)=>{const g=[],_=[];Object.values(h).forEach(P=>{if(rs(P)&&(P.matchUpId&&(g.push(P.matchUpId),a.push(P)),P.sides)){const y=l(P);_.push(...y)}});const I=Object.values(h).filter(P=>rs(P)&&!P.matchUpId);return m.concat({matchUpIds:g,availableCourts:I,rowId:h.rowId,participantIds:_})},[]);n.filter(({matchUpStatus:m})=>m&&m!==ut.Bye&&(t||!Yt.includes(m))).sort(Cs);const u=cn({matchUps:n.concat(a),includeParticipantDependencies:!0,tournamentRecords:e}).matchUpDependencies,p=[],d=[];for(;n.length&&c.length;){const m=c.shift(),h=[];for(;n.length&&m.availableCourts.length;){const g=n.concat(h).map(T=>T.matchUpId),_=n.shift(),I=_==null?void 0:_.matchUpId,P=I&&u[I].matchUpIds.concat(u[I].dependentMatchUpIds),y=I&&g.some(T=>u[I].matchUpIds.includes(T)),S=I&&d.some(T=>u[I].dependentMatchUpIds.includes(T)),O=m.matchUpIds.some(T=>P.includes(T)),b=l(_),w=m.participantIds.some(T=>b.includes(T));if(_&&!O&&!y&&!w&&!S){const T=m.availableCourts.shift();Object.assign(_.schedule,T.schedule),Object.assign(T,_),p.push(_),m.participantIds.push(...b),m.matchUpIds.push(I)}else _&&h.push(_)}n.push(...h),d.push(...m.matchUpIds)}const v=p.map(({matchUpId:m,tournamentId:h,schedule:g,drawId:_})=>({tournamentId:h,matchUpId:m,drawId:_,schedule:Qw(Kw({},g),{scheduledDate:r})}));i=LS({tournamentRecords:e,matchUpDetails:v});const f=n;return Qw(Kw({},i),{scheduled:p,notScheduled:f})}var iQ=Object.defineProperty,sQ=Object.defineProperties,aQ=Object.getOwnPropertyDescriptors,Jw=Object.getOwnPropertySymbols,lQ=Object.prototype.hasOwnProperty,cQ=Object.prototype.propertyIsEnumerable,Zw=(t,e,r)=>e in t?iQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xw=(t,e)=>{for(var r in e||(e={}))lQ.call(e,r)&&Zw(t,r,e[r]);if(Jw)for(var r of Jw(e))cQ.call(e,r)&&Zw(t,r,e[r]);return t},eE=(t,e)=>sQ(t,aQ(e));function uQ(t){const e="matchUpScheduleChange",{tournamentRecords:r}=t;if(typeof r!="object"||!Object.keys(r).length)return{error:ke};const{sourceMatchUpContextIds:n,targetMatchUpContextIds:o,sourceCourtId:i,targetCourtId:s,courtDayDate:a}=t||{},{drawId:l,matchUpId:c,tournamentId:u}=n||{},{drawId:p,matchUpId:d,tournamentId:v}=o||{};if(!c&&!d)return k({result:{error:_e},stack:e});const{matchUps:f}=Ro({matchUpFilters:{matchUpIds:[c,d].filter(Boolean),drawIds:[l,p].filter(Boolean)},tournamentRecords:t.tournamentRecords}),m=f==null?void 0:f.find(({matchUpId:y})=>y===c),h=f==null?void 0:f.find(({matchUpId:y})=>y===d);let g=0;if(s&&c&&!d){const y=_({tournamentId:u,matchUpId:c,courtId:s,matchUp:m,drawId:l,tournamentRecords:r,sourceCourtId:i,courtDayDate:a});if(y!=null&&y.success&&g++,y.error)return k({result:y,stack:e})}else if(i&&s&&c&&d){const y=_({tournamentId:u,matchUpId:c,courtId:s,matchUp:m,drawId:l,tournamentRecords:r,sourceCourtId:i,courtDayDate:a});if(y.success&&g++,y.error)return k({result:y,stack:e,info:"source"});const S=_({tournamentId:v,sourceCourtId:s,matchUpId:d,matchUp:h,courtId:i,drawId:p,tournamentRecords:r,courtDayDate:a});if(S.success&&g++,S.error)return k({result:S,stack:e,info:"target"})}else return{error:_e};return g?V:k({result:{error:hl},stack:e});function _(y){const{tournamentRecords:S,tournamentId:O,matchUp:b,drawId:w}=y,T=S[O],{drawDefinition:$}=Jo({tournamentRecord:T,drawId:w});return b.matchUpType===Qe?I(eE(Xw({},y),{tournamentRecord:T,drawDefinition:$})):P(eE(Xw({},y),{tournamentRecord:T,drawDefinition:$}))}function I({removePriorValues:y,tournamentRecords:S,tournamentRecord:O,drawDefinition:b,sourceCourtId:w,courtDayDate:T,matchUpId:$,matchUp:N,courtId:E}){const A=[E].concat(N.schedule.allocatedCourts.map(({courtId:U})=>U).filter(U=>U!==w));return ud({removePriorValues:y,tournamentRecords:S,tournamentRecord:O,drawDefinition:b,courtDayDate:T,matchUpId:$,courtIds:A})}function P({tournamentRecords:y,tournamentRecord:S,drawDefinition:O,courtDayDate:b,matchUpId:w,courtId:T}){return Ds({tournamentRecords:y,tournamentRecord:S,drawDefinition:O,courtDayDate:b,matchUpId:w,courtId:T})}}var dQ=Object.defineProperty,pQ=Object.defineProperties,fQ=Object.getOwnPropertyDescriptors,tE=Object.getOwnPropertySymbols,vQ=Object.prototype.hasOwnProperty,mQ=Object.prototype.propertyIsEnumerable,rE=(t,e,r)=>e in t?dQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hQ=(t,e)=>{for(var r in e||(e={}))vQ.call(e,r)&&rE(t,r,e[r]);if(tE)for(var r of tE(e))mQ.call(e,r)&&rE(t,r,e[r]);return t},gQ=(t,e)=>pQ(t,fQ(e));function _Q(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;return Xb(gQ(hQ({},t),{tournamentRecord:r,drawDefinition:n}))}function IQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;if(!n)return{error:ue};const{disableNotice:o,scheduledDate:i,matchUpId:s,removePriorValues:a}=t;return Im({removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:o,scheduledDate:i,matchUpId:s})}function PQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,scheduledTime:i,matchUpId:s,removePriorValues:a}=t;return n?Pm({removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:o,scheduledTime:i,matchUpId:s}):{error:ue}}function yQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,startTime:i,matchUpId:s}=t;return eT({tournamentRecord:r,drawDefinition:n,disableNotice:o,startTime:i,matchUpId:s})}function SQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,endTime:i,matchUpId:s}=t;return tT({tournamentRecord:r,drawDefinition:n,disableNotice:o,endTime:i,matchUpId:s})}function OQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,stopTime:i,matchUpId:s}=t;return rT({tournamentRecord:r,drawDefinition:n,disableNotice:o,stopTime:i,matchUpId:s})}function bQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,resumeTime:i,matchUpId:s}=t;return nT({tournamentRecord:r,drawDefinition:n,disableNotice:o,resumeTime:i,matchUpId:s})}function TQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,participantId:i,officialType:s,matchUpId:a}=t;return oT({tournamentRecord:r,drawDefinition:n,disableNotice:o,participantId:i,officialType:s,matchUpId:a})}function wQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{matchUpId:o,venueId:i,disableNotice:s,removePriorValues:a}=t;return n?ja({tournamentRecords:t.tournamentRecords,removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:s,matchUpId:o,venueId:i}):{error:ue}}function EQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;if(!r)return{error:re};if(!n)return{error:ue};const{removePriorValues:o,tournamentRecords:i,disableNotice:s,courtDayDate:a,matchUpId:l,courtId:c}=t;return Ds({removePriorValues:o,tournamentRecords:i,tournamentRecord:r,drawDefinition:n,disableNotice:s,courtDayDate:a,matchUpId:l,courtId:c})}function $Q(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;if(!n)return{error:ue};const{removePriorValues:o,tournamentRecords:i,disableNotice:s,courtDayDate:a,matchUpId:l,courtIds:c}=t;return ud({removePriorValues:o,tournamentRecords:i,tournamentRecord:r,drawDefinition:n,disableNotice:s,courtDayDate:a,matchUpId:l,courtIds:c})}function NQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{removePriorValues:o,disableNotice:i,courtOrder:s,matchUpId:a}=t;return g7({removePriorValues:o,tournamentRecord:r,drawDefinition:n,disableNotice:i,courtOrder:s,matchUpId:a})}function Xn({tournamentRecords:t,tournamentId:e,drawId:r}){if(!t)return{error:ke};if(!r)return{error:kr};if(typeof e!="string"&&(e=Xv({tournamentRecords:t,drawId:r}),!e))return{error:yo};const n=t[e];if(!n)return{error:re};const o=Qt({tournamentRecord:n,drawId:r});return o.error?k({stack:"addScheduleItems.getDrawDefinition",result:o}):{drawDefinition:o.drawDefinition,tournamentRecord:n}}const UQ={scheduleMatchUps:z9,scheduleProfileRounds:Rm,clearScheduledMatchUps:Aw,bulkRescheduleMatchUps:A7,getScheduledRoundsDetails:bm,getMatchUpDependencies:cn,generateVirtualCourts:Lv,generateBookings:Am,proAutoSchedule:oQ,proConflicts:Z0,matchUpScheduleChange:uQ,calculateScheduleTimes:cw,reorderUpcomingMatchUps:Z9,bulkUpdateCourtAssignments:L9,removeMatchUpCourtAssignment:Rw,toggleParticipantCheckInState:U9,findMatchUpFormatTiming:Om,modifyMatchUpFormatTiming:r8,modifyEventMatchUpFormatTiming:FY,getMatchUpFormatTimingUpdate:kK,getEventMatchUpFormatTiming:QK,removeEventMatchUpFormatTiming:$9,getMatchUpDailyLimitsUpdate:A9,getMatchUpDailyLimits:Mw,setMatchUpDailyLimits:R7,getProfileRounds:Lm,getRounds:Bw,assignMatchUpVenue:wQ,assignMatchUpCourt:EQ,allocateTeamMatchUpCourts:$Q,addMatchUpScheduleItems:_Q,addMatchUpScheduledDate:IQ,addMatchUpScheduledTime:PQ,addMatchUpCourtOrder:NQ,addMatchUpStartTime:yQ,addMatchUpStopTime:OQ,addMatchUpResumeTime:bQ,addMatchUpEndTime:SQ,addMatchUpOfficial:TQ,getSchedulingProfile:za,setSchedulingProfile:bc,addSchedulingProfileRound:nw,validateSchedulingProfile:Rd,addPersonRequests:v9,getPersonRequests:Ka,modifyPersonRequests:h9,removePersonRequests:m9};var AQ=Object.defineProperty,CQ=Object.defineProperties,MQ=Object.getOwnPropertyDescriptors,nE=Object.getOwnPropertySymbols,DQ=Object.prototype.hasOwnProperty,jQ=Object.prototype.propertyIsEnumerable,oE=(t,e,r)=>e in t?AQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,RQ=(t,e)=>{for(var r in e||(e={}))DQ.call(e,r)&&oE(t,r,e[r]);if(nE)for(var r of nE(e))jQ.call(e,r)&&oE(t,r,e[r]);return t},FQ=(t,e)=>CQ(t,MQ(e));function Bm({tournamentRecord:t,policyDefinitions:e,allowReplacement:r}){var n;if(!t)return{error:re};if(!e||typeof e!="object")return{error:Xc};t.extensions||(t.extensions=[]);const o=(n=pt({tournamentRecord:t}).appliedPolicies)!=null?n:{},i=Object.keys(e).map(s=>{if(!o[s]||r)return o[s]=e[s],s}).filter(Boolean);if(i!=null&&i.length){const a=Ei({tournamentRecord:t,extension:{name:os,value:o}});if(a.error)return a}return i!=null&&i.length?FQ(RQ({},V),{applied:i}):{error:t_}}function iE({policyDefinitions:t,allowReplacement:e,event:r}){var n;if(!r)return{error:Ge};if(!t)return{error:Xc};let o=0;r.extensions||(r.extensions=[]);const i=(n=pt({event:r}).appliedPolicies)!=null?n:{};return Object.keys(t).forEach(s=>{(!i[s]||e)&&(i[s]=t[s],o++)}),o&&ao({event:r,extension:{name:os,value:i}}),o?V:{error:gx}}function xQ({event:t,policyType:e}){if(!e)return{error:_e};if(!t)return{error:Ge};let r;if(t.extensions){const{appliedPolicies:n}=pt({event:t});n!=null&&n[e]&&(delete n[e],r=!0,Object.keys(n).length?ao({event:t,extension:{name:os,value:n}}):Ou({event:t,name:os}))}return r?V:{error:nf}}var LQ=Object.defineProperty,sE=Object.getOwnPropertySymbols,VQ=Object.prototype.hasOwnProperty,BQ=Object.prototype.propertyIsEnumerable,aE=(t,e,r)=>e in t?LQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,kQ=(t,e)=>{for(var r in e||(e={}))VQ.call(e,r)&&aE(t,r,e[r]);if(sE)for(var r of sE(e))BQ.call(e,r)&&aE(t,r,e[r]);return t};function GQ({tournamentRecords:t,policyDefinitions:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};for(const r of Object.values(t)){const n=Bm({allowReplacement:!0,tournamentRecord:r,policyDefinitions:e});if(n.error)return n}return kQ({},V)}const WQ={attachPolicies:GQ};var HQ=Object.defineProperty,qQ=Object.defineProperties,zQ=Object.getOwnPropertyDescriptors,lE=Object.getOwnPropertySymbols,YQ=Object.prototype.hasOwnProperty,KQ=Object.prototype.propertyIsEnumerable,cE=(t,e,r)=>e in t?HQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,km=(t,e)=>{for(var r in e||(e={}))YQ.call(e,r)&&cE(t,r,e[r]);if(lE)for(var r of lE(e))KQ.call(e,r)&&cE(t,r,e[r]);return t},uE=(t,e)=>qQ(t,zQ(e));function QQ({tournamentRecords:t,policyDefinitions:e,scaleAttributes:r,participantId:n,inContext:o,personId:i}){let s=ET({tournamentRecords:t,policyDefinitions:e,participantId:n,inContext:o,personId:i});if(s.error)return s;const{participant:a,tournamentId:l}=s;return s=go({participant:a,scaleAttributes:r}),s.error?uE(km({},s),{tournamentId:l}):km(uE(km({},V),{tournamentId:l}),s)}var JQ=Object.defineProperty,dE=Object.getOwnPropertySymbols,ZQ=Object.prototype.hasOwnProperty,XQ=Object.prototype.propertyIsEnumerable,pE=(t,e,r)=>e in t?JQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fE=(t,e)=>{for(var r in e||(e={}))ZQ.call(e,r)&&pE(t,r,e[r]);if(dE)for(var r of dE(e))XQ.call(e,r)&&pE(t,r,e[r]);return t};function eJ(t){const{scheduleDates:e=[],tournamentRecords:r,periodLength:n=30}=t||{};if(typeof r!="object")return{error:Yc};if(!Array.isArray(e))return{error:X};if(!e.every(Gr))return{error:Sr};const i=[];let s=0;const a={},{schedulingProfile:l}=za({tournamentRecords:r});if(!l)return fE({issues:i},V);const{matchUps:c}=Ro({nextMatchUps:!0,tournamentRecords:r});for(const p of l){const{scheduleDate:d,venues:v=[]}=p;if(!(e!=null&&e.length)||e.includes(d)){for(const f of v||[])if(f){const{rounds:m}=f,h=[],{orderedMatchUpIds:g,scheduledRoundsDetails:_}=bm({tournamentRecords:r,periodLength:n,matchUps:c,rounds:m}),{matchUpDependencies:I}=cn({tournamentRecords:r,matchUps:c}),P=y=>{let S;return _==null||_.find((O,b)=>{const w=O.matchUpIds.includes(y);return w&&(S=b),w}),S};if(g==null||g.forEach((y,S)=>{var O;const b=g.slice(S+1),w=Ht(b,((O=I==null?void 0:I[y])==null?void 0:O.matchUpIds)||[]);w.length&&h.push({matchUpId:y,shouldBeAfter:w})}),h.length){s+=h.length;const y=h.map(({matchUpId:S,shouldBeAfter:O})=>{const b=P(S),w=We(O.map(P));return a[d]||(a[d]={}),a[d][b]||(a[d][b]=[]),w.forEach(T=>{a[d][b].includes(T)||a[d][b].push(T)}),{matchUpId:S,matchUpRoundIndex:b,earlierRoundIndices:w,shouldBeAfter:O}});i.push(...y)}}}}const u={matchUpIdShouldBeAfter:Object.assign({},...i.map(p=>{const{matchUpId:d,shouldBeAfter:v,earlierRoundIndices:f}=p;return{[d]:{earlierRoundIndices:f,shouldBeAfter:v}}}))};return fE({issuesCount:s,profileIssues:u,roundIndexShouldBeAfter:a},V)}function kd(){return`
7
+ `)}function X_({participantResults:t,participantIds:e,attribute:r}){return eI({participantResults:t,participantIds:e}).reduce((o,i)=>{const{participantId:s,results:a}=i,l=a==null?void 0:a[r];return!isNaN(l)&&s&&(o[l]?o[l].push(s):o[l]=[s]),o},{})}function eI(t){return(t.participantIds||Object.keys(t.participantResults)).reduce((r,n,o)=>(r.push({participantId:n,i:o,results:t.participantResults[n]}),r),[])}var PV=Object.defineProperty,tI=Object.getOwnPropertySymbols,yV=Object.prototype.hasOwnProperty,SV=Object.prototype.propertyIsEnumerable,rI=(t,e,r)=>e in t?PV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,OV=(t,e)=>{for(var r in e||(e={}))yV.call(e,r)&&rI(t,r,e[r]);if(tI)for(var r of tI(e))SV.call(e,r)&&rI(t,r,e[r]);return t};const bV=[{attribute:"matchUpsPct",idsFilter:!1},{attribute:"allDefaults",reversed:!0,idsFilter:!1},{attribute:"defaults",reversed:!0,idsFilter:!1},{attribute:"walkovers",reversed:!0,idsFilter:!1},{attribute:"retirements",reversed:!0,idsFilter:!1},{attribute:"setsPct",idsFilter:!1},{attribute:"gamesPct",idsFilter:!1},{attribute:"pointsPct",idsFilter:!1},{attribute:"matchUpsPct",idsFilter:!0},{attribute:"setsPct",idsFilter:!0},{attribute:"gamesPct",idsFilter:!0},{attribute:"pointsPct",idsFilter:!0}],Tf={matchUpsPct:20,tieMatchUpsPct:16,setsPct:12,gamesPct:8,pointsPct:4};function nI(t){const{requireCompletion:e=!0,participantResults:r,subOrderMap:n,tallyPolicy:o}=t,i=[];if(e&&!TV(t))return{};const s=["tieMatchUpsWon","tieSinglesWon","tieDoublesWon","matchUpsWon","pointsWon","gamesWon","setsWon","gamesPct","setsPct","pointsPct","matchUpsPct"].includes(o==null?void 0:o.groupOrderKey)?o.groupOrderKey:"matchUpsWon",a=X_({participantResults:r,attribute:s});i.push({attribute:s,groups:a});const l=Object.keys(a).map(f=>parseFloat(f)).sort((f,m)=>m-f).map(f=>a[f]).map(f=>{const m=oI(OV({participantIds:f},t));return i.push(m.report),m.order}).flat(1/0);let c=1,u;l.forEach((f,m)=>{m&&(f.resolved||u&&!f.resolved)&&(c+=1),u=f.resolved,f.resolved?(f.position=m+1,c=f.position):f.position=c});const p=l.map(({position:f})=>f),d=Nr(p);return l.forEach(f=>{const{participantId:m,position:h}=f||{},g=r[m];f.GEMscore=v(g);const _=d[h];(f==null?void 0:f.position)!==void 0&&(_>1&&(f.ties=_,n&&(f.subOrder=n[m])),f.rankOrder=h,f.groupOrder=h+(f.subOrder||1)-1)}),{groupOrder:l,report:i.flat(1/0).filter(Boolean)};function v(f){return(Array.isArray(o==null?void 0:o.GEMscore)?Object.keys(Tf).filter(g=>o.GEMscore.includes(g)):Object.keys(Tf)).map(g=>(f[g]||0)*Math.pow(10,Tf[g].toFixed(3))).reduce((g,_)=>g+_,0)}}function TV({participantResults:t,participantsCount:e}){const n=eI({participantResults:t}).filter(o=>e-1===o.results.matchUpsWon+o.results.matchUpsLost+o.results.matchUpsCancelled);return e===n.length}function wV({disableHeadToHead:t,participantIds:e,matchUpFormat:r,tallyPolicy:n,attribute:o,idsFilter:i,matchUps:s,reversed:a}){const{participantResults:l}=K_({participantIds:i&&e,matchUpFormat:r,tallyPolicy:n,matchUps:s}),c=X_({participantResults:l,participantIds:e,attribute:o}),u=[{attribute:o,reversed:a,groups:c,idsFilter:i}];let p;return Object.keys(c).length>1&&e.length&&(p=Object.keys(c).map(d=>parseFloat(d)).sort((d,v)=>a?d-v:v-d).map(d=>c[d]).map(d=>{const v=oI({participantResults:l,disableHeadToHead:t,participantIds:d,matchUpFormat:r,tallyPolicy:n,matchUps:s});return u.push(v.report),v.order}).flat(1/0)),{order:p,report:u}}function oI({participantResults:t,disableHeadToHead:e,participantIds:r,matchUpFormat:n,tallyPolicy:o,matchUps:i}){if((r==null?void 0:r.length)===1)return{order:[{resolved:!0,participantId:r[0]}]};if((r==null?void 0:r.length)===2&&(!(o!=null&&o.headToHead)||!o.headToHead.disabled&&!e)){const p=EV({participantIds:r,participantResults:t});if(p)return{order:[p],headToHeadWinner:p[0].participantId}}const s=(o==null?void 0:o.tallyDirectives)||bV,a=[],l=[];let c;const u=s.filter(p=>{const d=!(Ct(p.maxParticipants)&&(r==null?void 0:r.length)>p.maxParticipants);return d||a.push(p),d});return a.length&&l.push({excludedDirectives:a,participantIds:r}),u.every(({attribute:p,reversed:d,idsFilter:v,disableHeadToHead:f})=>(c=wV({disableHeadToHead:f,participantIds:r,matchUpFormat:n,tallyPolicy:o,attribute:p,idsFilter:v,matchUps:i,reversed:d}),l.push(c.report),!c.order)),c.order?{order:c.order,report:l}:{order:r==null?void 0:r.map(p=>({participantId:p})),report:l}}function EV({participantIds:t,participantResults:e}){if(t){if(e[t[0]].victories.includes(t[1]))return t.map(r=>({resolved:!0,participantId:r}));if(e[t[1]].victories.includes(t[0]))return t.reverse().map(r=>({resolved:!0,participantId:r}))}}const iI="voluntaryConsolation",zo="competitiveBands",sI="roundRobinTally",To="positionActions",Bn="matchUpActions",wf="rankingPoints",Ef="roundNaming",Tl="participant",pu="progression",$f="scheduling",$V="avoidance",da="scoring",pa="seeding",fu="feedIn",NV="draws";function Nf({policyDefinitions:t,generateReport:e,matchUpFormat:r,matchUps:n=[],subOrderMap:o,perPlayer:i}){if(!Array.isArray(n))return{error:ko};if(n.reduce((I,{structureId:P})=>I.includes(P)?I:I.concat(P),[]).length!==1)return{error:X,info:"Maximum one structureId"};const a=n.filter(I=>I&&I.matchUpStatus!==nt),l=a.length&&We(a.map(({drawPositions:I})=>I).flat()).length,c=a.filter(I=>ca({matchUp:I})).length===a.length;c||(i=0);const u=n.every(({matchUpType:I,tieMatchUps:P})=>I===Qe&&P.every(y=>ca({matchUp:y}))),p=t==null?void 0:t[sI],d=n.filter(I=>ca({matchUp:I})||I.matchUpType===Qe),{participantResults:v}=K_({matchUps:d,matchUpFormat:r,tallyPolicy:p,perPlayer:i});let f,m;const{groupOrder:h,report:g}=nI({matchUps:d,participantResults:v,participantsCount:l,matchUpFormat:r,tallyPolicy:p,subOrderMap:o});if(c&&h)f=g,m=h,h.forEach(I=>{const{participantId:P,groupOrder:y,rankOrder:S,subOrder:O,ties:b,GEMscore:w}=I,T=v[P];Object.assign(T,{groupOrder:y,rankOrder:S,GEMscore:w,subOrder:O,ties:b})});else{const{groupOrder:I,report:P}=nI({requireCompletion:!1,participantResults:v,participantsCount:l,matchUpFormat:r,tallyPolicy:p,subOrderMap:o,matchUps:n});f=P,m=I,I&&I.forEach(y=>{const{participantId:S,groupOrder:O,GEMscore:b}=y,w=v[S];Object.assign(w,{provisionalOrder:O,GEMscore:b})})}const _={completedTieMatchUps:u,readableReport:"",participantResults:v,bracketComplete:c,order:[],report:f};if((c||u)&&(_.order=m),e||zt({tally:!0})){const I=IV({matchUps:n,report:f,order:m});zt({tally:!0})&&console.log(I),_.readableReport=I}return _}function UV({collectionDefinition:t,groupValueNumbers:e,groupValueGroups:r,sideTieValues:n,tieMatchUps:o}){const i=o.filter(_=>_.collectionId===t.collectionId),s=[0,0];let a=[0,0];const l=i.every(_=>Yt.includes(_.matchUpStatus)),{collectionValueProfiles:c,collectionGroupNumber:u,collectionValue:p,matchUpValue:d,winCriteria:v,scoreValue:f,setValue:m}=t,h=u&&e.includes(u),g=[0,0];if(i.forEach(_=>{_.winningSide&&(g[_.winningSide-1]+=1)}),d?i.forEach(_=>{_.winningSide&&(s[_.winningSide-1]+=d)}):m?i.forEach(_=>{var I,P;(P=(I=_.score)==null?void 0:I.sets)==null||P.forEach(y=>{y.winningSide&&(s[y.winningSide-1]+=m)})}):f?i.forEach(_=>{var I,P;(P=(I=_.score)==null?void 0:I.sets)==null||P.forEach(y=>{const{side1TiebreakScore:S=0,side2TiebreakScore:O=0,side1Score:b=0,side2Score:w=0}=y;(_.matchUpStatus===Mt||_.winningSide||y.winningSide)&&(b||w?(s[0]+=b,s[1]+=w):(S||O)&&y.winningSide&&(s[y.winningSide-1]+=1))})}):Array.isArray(c)&&i.forEach(_=>{if(_.winningSide){const I=_.collectionPosition,P=AV({collectionDefinition:t,collectionPosition:I});s[_.winningSide-1]+=P}}),p){let _;if(v!=null&&v.aggregateValue)l&&((d||m||f)&&s[0]!==s[1]?_=s[0]>s[1]?1:2:g[0]!==g[1]&&(_=g[0]>g[1]?1:2));else if(v!=null&&v.valueGoal)_=s.reduce((I,P,y)=>P>=v.valueGoal?y+1:I,0);else{const I=Math.floor(t.matchUpCount/2)+1;_=g.reduce((P,y,S)=>y>=I?S+1:P,0)}_&&(h?r[u].values[_-1]+=p:a[_-1]+=p)}else h?(r[u].values[0]+=s[0]||0,r[u].values[1]+=s[1]||0):a=s;h?(r[u].sideWins[0]+=g[0]||0,r[u].sideWins[1]+=g[1]||0,r[u].allGroupMatchUpsCompleted=r[u].allGroupMatchUpsCompleted&&l,r[u].matchUpsCount+=i.length):a.forEach((_,I)=>n[I]+=_)}function AV({collectionDefinition:t,collectionPosition:e}){const r=t.collectionValueProfiles||[],n=r==null?void 0:r.find(o=>o.collectionPosition===e);return n==null?void 0:n.matchUpValue}const os="appliedPolicies",vu="positionActions",aI="context",mu="delegatedOutcome",gn="disabled",hu="disableLinks",fa="disableAutoCalc",gu="drawDeletions",CV="drawProfile",_u="entryProfile",MV="eventProfile",DV="factory",_n="flightProfile",Uf="groupingAttribute",kn="lineUps",is="linkedTournamentsIds",Iu="matchUpHistory",Af="participantRepresentatives",va="personRequests",lI="rankingPoints",Gn="roundTarget",ss="scheduleLimits",Wn="scheduleTiming",Yo="schedulingProfile",jV="statusDetail",ma="subOrder",Ko="tally",as="tieFormatModification",cI={APPLIED_POLICIES:os,AUDIT_POSITION_ACTIONS:vu,CONTEXT:aI,DELEGATED_OUTCOME:mu,DISABLED:gn,DISABLE_LINKS:hu,DISABLE_AUTO_CALC:fa,DRAW_DELETIONS:gu,DRAW_PROFILE:CV,ENTRY_PROFILE:_u,EVENT_PROFILE:MV,FLIGHT_PROFILE:_n,GROUPING_ATTRIBUTE:Uf,LINEUPS:kn,LINKED_TOURNAMENTS:is,MATCHUP_HISTORY:Iu,PARTICIPANT_REPRESENTATIVES:Af,PERSON_REQUESTS:va,RANKING_POINTS:lI,ROUND_TARGET:Gn,SCHEDULE_LIMITS:ss,SCHEDULE_TIMING:Wn,SCHEDULING_PROFILE:Yo,STATUS_DETAIL:jV,SUB_ORDER:ma,TALLY:Ko,TIE_FORMAT_MODIFICATIONS:as,FACTORY:DV},uI=[mu,gn,hu,_n,kn,Iu,Af,va,Gn,ss,Wn,Yo,ma,Ko];var RV=Object.defineProperty,dI=Object.getOwnPropertySymbols,FV=Object.prototype.hasOwnProperty,xV=Object.prototype.propertyIsEnumerable,pI=(t,e,r)=>e in t?RV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,LV=(t,e)=>{for(var r in e||(e={}))FV.call(e,r)&&pI(t,r,e[r]);if(dI)for(var r of dI(e))xV.call(e,r)&&pI(t,r,e[r]);return t};function pt({onlySpecifiedPolicyTypes:t=!1,policyTypes:e=[],tournamentRecord:r,drawDefinition:n,structure:o,event:i}){if(!Array.isArray(e))return{error:Xg};const s={};return r&&a(r),i&&a(i),n&&a(n),o&&a(o),LV({appliedPolicies:s},V);function a(l){var c;const u=l==null?void 0:l.extensions,p=(c=u==null?void 0:u.find(d=>d.name===os))==null?void 0:c.value;if(p)for(const d of Object.keys(p))(t?e.includes(d):!e.length||e.includes(d))&&(s[d]=de(p[d],!1,!0))}}function ls({policyTypes:t=[],tournamentRecord:e,drawDefinition:r,structure:n,event:o}){if(!Array.isArray(t))return{error:Xg};const{appliedPolicies:i}=pt({tournamentRecord:e,drawDefinition:r,structure:n,event:o}),s={};for(const a of t){const l=i==null?void 0:i[a];l&&(s[a]=l)}return Object.keys(s).length?{policyDefinitions:s}:{error:nf}}const fI="WALKOVER",vI="RETIRED",Cf="COMPETITIVE",wl="ROUTINE",El="DECISIVE",$l="winRatio",Mf={[zo]:{policyName:"Competitive Bands Default",competitiveProfile:{[El]:20,[wl]:50}}};function wo({policyDefinitions:t,tournamentRecord:e,contextProfile:r,drawDefinition:n,event:o}){const i={policies:{}};if(!r)return i;const s=ls({tournamentRecord:e,drawDefinition:n,event:o}).policyDefinitions;if(r.withCompetitiveness){const a=(t==null?void 0:t[zo])||(s==null?void 0:s[zo])||Mf[zo];i.policies[zo]=a}return i}function mI({matchUps:t,matchUpId:e}){return{matchUp:(t||[]).find(n=>n.matchUpId===e)}}function VV({matchUps:t}){const e=t.reduce((n,o)=>!o.collectionPosition||n.includes(o.collectionPosition)?n:n.concat(o.collectionPosition),[]).map(n=>({[n]:t.filter(o=>o.collectionPosition===n)}));return{collectionPositionMatchUps:Object.assign({},...e)}}const BV=(t,e)=>(t||0)+(e||0);function hI(t,e){return isNaN(t)&&fI||t<=e[El]&&El||t<=e[wl]&&wl||Cf}function gI({score:t}){const e=(t==null?void 0:t.sets)||[],r=e.reduce((o,i)=>(o[0]+=i.side1Score||0,o[1]+=i.side2Score||0,o),[0,0]),n=e.reduce((o,i)=>(o[0]+=i.side1TiebreakScore||0,o[1]+=i.side2TiebreakScore||0,o),[0,0]);return n.reduce(BV)&&(r[n[0]>n[1]?0:1]+=1),{sets:e,games:r,score:t}}function kV(t){const e=Math.min(...t.games),r=Math.max(...t.games);return Math.round(e/r*100)}function _I(t){return t.map(kV).sort().map(e=>e.toFixed(2))}function cs({tournamentRecord:t,drawDefinition:e,policyType:r,structure:n,event:o}){if(!t)return{error:re};const{appliedPolicies:i}=pt({tournamentRecord:t,drawDefinition:e,structure:n,event:o});return i!=null&&i[r]?{policy:i[r]}:{error:nf}}var GV=Object.defineProperty,WV=Object.defineProperties,HV=Object.getOwnPropertyDescriptors,II=Object.getOwnPropertySymbols,qV=Object.prototype.hasOwnProperty,zV=Object.prototype.propertyIsEnumerable,PI=(t,e,r)=>e in t?GV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,YV=(t,e)=>{for(var r in e||(e={}))qV.call(e,r)&&PI(t,r,e[r]);if(II)for(var r of II(e))zV.call(e,r)&&PI(t,r,e[r]);return t},KV=(t,e)=>WV(t,HV(e));function yI({competitiveProfile:t,tournamentRecord:e,matchUp:r}){if(!r)return{error:jr};const{score:n,winningSide:o}=r;if(!o)return{error:X};const i=!t&&e&&cs({policyType:zo,tournamentRecord:e}).policy,s=t||(i==null?void 0:i.competitiveProfile)||Mf[zo].competitiveProfile,a=gI({score:n}),l=_I([a]),c=hI(l,s);return KV(YV({},V),{competitiveness:c})}function Nl(t){const{matchUpAverageTimes:e,matchUpFormat:r}=t||{},n=(e==null?void 0:e.map(({matchUpFormatCodes:a})=>a==null?void 0:a.filter(l=>l===r)).flat().filter(Boolean).sort((a,l)=>((a==null?void 0:a.length)||0)-((l==null?void 0:l.length)||0)))||[],i=n.includes(r)?r:n[0],s=e==null?void 0:e.find(({matchUpFormatCodes:a,averageTimes:l})=>(a==null?void 0:a.find(c=>i===c))&&l);return s==null?void 0:s.averageTimes}function Ul(t){var e;const{matchUpRecoveryTimes:r,averageMinutes:n,matchUpFormat:o}=t||{};return(e=r==null?void 0:r.find(({matchUpFormatCodes:i,averageTimes:s,recoveryTimes:a})=>{if(s&&n){const{greaterThan:l=0,lessThan:c=360}=s;if(n>l&&n<c)return!0}return(i==null?void 0:i.find(l=>l===o))&&a}))==null?void 0:e.recoveryTimes}function SI({timesBlockArray:t,categoryName:e,categoryType:r}){return t.filter(n=>Array.isArray(n)).map(n=>n.sort((o,i)=>{var s,a;return(((s=i.categoryNames)==null?void 0:s.length)||0)-(((a=o.categoryNames)==null?void 0:a.length)||0)}).find(({categoryTypes:o,categoryNames:i})=>!(i!=null&&i.length)&&!(o!=null&&o.length)||(i==null?void 0:i.includes(e))||(o==null?void 0:o.includes(r)))).find(Boolean)}var QV=Object.defineProperty,JV=Object.defineProperties,ZV=Object.getOwnPropertyDescriptors,OI=Object.getOwnPropertySymbols,XV=Object.prototype.hasOwnProperty,eB=Object.prototype.propertyIsEnumerable,bI=(t,e,r)=>e in t?QV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Df=(t,e)=>{for(var r in e||(e={}))XV.call(e,r)&&bI(t,r,e[r]);if(OI)for(var r of OI(e))eB.call(e,r)&&bI(t,r,e[r]);return t},jf=(t,e)=>JV(t,ZV(e));function tB({tournamentScheduling:t,eventScheduling:e,averageMinutes:r,defaultTiming:n,matchUpFormat:o,categoryName:i,categoryType:s,policy:a}){var l;const c=(e==null?void 0:e.matchUpRecoveryTimes)&&Ul(jf(Df({},e),{averageMinutes:r,matchUpFormat:o})),u=(t==null?void 0:t.matchUpRecoveryTimes)&&Ul(jf(Df({},t),{averageMinutes:r,matchUpFormat:o})),p=(a==null?void 0:a.matchUpRecoveryTimes)&&Ul(jf(Df({},a),{averageMinutes:r,matchUpFormat:o})),d=[c,u,p,(l=a==null?void 0:a.defaultTimes)==null?void 0:l.recoveryTimes,n==null?void 0:n.recoveryTimes];return SI({categoryName:i,categoryType:s,timesBlockArray:d})}var rB=Object.defineProperty,nB=Object.defineProperties,oB=Object.getOwnPropertyDescriptors,TI=Object.getOwnPropertySymbols,iB=Object.prototype.hasOwnProperty,sB=Object.prototype.propertyIsEnumerable,wI=(t,e,r)=>e in t?rB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rf=(t,e)=>{for(var r in e||(e={}))iB.call(e,r)&&wI(t,r,e[r]);if(TI)for(var r of TI(e))sB.call(e,r)&&wI(t,r,e[r]);return t},Ff=(t,e)=>nB(t,oB(e));function aB({matchUpFormat:t,categoryName:e,categoryType:r,defaultTiming:n,tournamentScheduling:o,eventScheduling:i,policy:s}){var a;const l=(i==null?void 0:i.matchUpAverageTimes)&&Nl(Ff(Rf({},i),{matchUpFormat:t})),c=(o==null?void 0:o.matchUpAverageTimes)&&Nl(Ff(Rf({},o),{matchUpFormat:t})),u=(s==null?void 0:s.matchUpAverageTimes)&&Nl(Ff(Rf({},s),{matchUpFormat:t})),p=[l,c,u,(a=s==null?void 0:s.defaultTimes)==null?void 0:a.averageTimes,n==null?void 0:n.averageTimes];return SI({categoryName:e,categoryType:r,timesBlockArray:p})}const Ti="RANKING",us="RATING",ds="SCALE",In="SEEDING";var lB=Object.defineProperty,EI=Object.getOwnPropertySymbols,cB=Object.prototype.hasOwnProperty,uB=Object.prototype.propertyIsEnumerable,$I=(t,e,r)=>e in t?lB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,NI=(t,e)=>{for(var r in e||(e={}))cB.call(e,r)&&$I(t,r,e[r]);if(EI)for(var r of EI(e))uB.call(e,r)&&$I(t,r,e[r]);return t};function ha({participant:t}){var e;const r=(e=t.timeItems)==null?void 0:e.filter(({itemType:o})=>(o==null?void 0:o.startsWith(ds))&&[Ti,us,In].includes(o.split(".")[1])),n={ratings:{},rankings:{},seedings:{}};if(r!=null&&r.length){const o=s=>r.filter(a=>(a==null?void 0:a.itemType)===s).sort((a,l)=>new Date(a.createdAt||void 0).getTime()-new Date(l.createdAt||void 0).getTime()).pop(),i=We(r.map(({itemType:s})=>s));for(const s of i){const a=o(s);if(a){const[,l,c,u]=a.itemType.split("."),p=l===In&&"seedings"||l===Ti&&"rankings"||"ratings";n[p][c]||(n[p][c]=[]),n[p][c].push({scaleValue:a.itemValue,scaleDate:a.itemDate,scaleName:u})}}}return NI(NI({},V),n)}function Eo({tournamentParticipants:t=[],policyDefinitions:e={},contextProfile:r,participantId:n,internalUse:o,personId:i}){const s=t.find(l=>n&&l.participantId===n||i&&l.person&&l.person.personId===i),a=de(s,!1,o);if(a){const l=e==null?void 0:e[Tl];if(r!=null&&r.withScaleValues){const{ratings:c,rankings:u}=ha({participant:a});a.rankings=u,a.ratings=c}if(l!=null&&l.participant)return iu({template:l.participant,source:a})}return a}function Qo({tournamentRecord:t,participantId:e}){return{participant:(t.participants||[]).reduce((o,i)=>i.participantId===e?i:o,void 0)}}function dB({tournamentRecord:t,policyDefinitions:e,convertExtensions:r,participantId:n,personId:o}){if(!t)return{error:re};if(typeof n!="string"&&typeof o!="string")return{error:_e};const i=t.participants||[],s=Eo({tournamentParticipants:i,policyDefinitions:e,participantId:n,personId:o});return{participant:de(s,r,!0)}}const Al="extensionQueries";function Kt({element:t,name:e}){if(!t||!e)return k({result:{error:_e},stack:Al});if(!Array.isArray(t.extensions))return{info:sr};const r=t.extensions.find(o=>(o==null?void 0:o.name)===e);return{extension:r,info:r?void 0:sr}}function Fr({tournamentRecord:t,name:e}){return Kt({element:t,name:e})}function $o({event:t,name:e}){return t?Kt({element:t,name:e}):k({result:{error:Ge},stack:Al})}function Pu({drawDefinition:t,name:e}){return t?Kt({element:t,name:e}):k({result:{error:ue},stack:Al})}function pB({tournamentRecord:t,participantId:e,name:r}){if(!t)return k({result:{error:re},stack:Al});if(!e)return k({result:{error:Et},stack:Al});const{participant:n}=Qo({tournamentRecord:t,participantId:e});return Kt({element:n,name:r})}function Cl({tournamentRecord:t,categoryName:e,categoryType:r,event:n}){var o,i,s,a,l,c;e=(s=e??((o=n==null?void 0:n.category)==null?void 0:o.categoryName))!=null?s:(i=n==null?void 0:n.category)==null?void 0:i.ageCategoryCode,r=(c=r??((a=n==null?void 0:n.category)==null?void 0:a.categoryType))!=null?c:(l=n==null?void 0:n.category)==null?void 0:l.subType;const{policy:u}=cs({policyType:$f,tournamentRecord:t,event:n}),p=t?Fr({name:Wn,tournamentRecord:t}).extension:void 0,d=p==null?void 0:p.value,v=n&&$o({name:Wn,event:n}).extension,f=v==null?void 0:v.value;return{scheduleTiming:{tournamentScheduling:d,eventScheduling:f,categoryName:e,categoryType:r,policy:u}}}const fB="DOUBLES_SINGLES",vB="SINGLES_DOUBLES",Pn="total",UI="participantConflict",wi="matchUpConflict",mB="ISSUE_IDS",ps="CONFLICT",fs="WARNING",AI="ERROR",CI="ISSUE",xf="STATE";var hB=Object.defineProperty,gB=Object.defineProperties,_B=Object.getOwnPropertyDescriptors,MI=Object.getOwnPropertySymbols,IB=Object.prototype.hasOwnProperty,PB=Object.prototype.propertyIsEnumerable,DI=(t,e,r)=>e in t?hB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jI=(t,e)=>{for(var r in e||(e={}))IB.call(e,r)&&DI(t,r,e[r]);if(MI)for(var r of MI(e))PB.call(e,r)&&DI(t,r,e[r]);return t},RI=(t,e)=>gB(t,_B(e));function Lf({defaultAverageMinutes:t=90,defaultRecoveryMinutes:e=0,tournamentRecord:r,matchUpFormat:n,categoryName:o,categoryType:i,eventType:s,event:a}){if(!r)return{error:re};s=s||(a==null?void 0:a.eventType)||Cr.Singles;const l={averageTimes:[{minutes:{default:t}}],recoveryTimes:[{minutes:{default:e}}]},{scheduleTiming:c}=Cl({tournamentRecord:r,categoryName:o,categoryType:i,event:a}),u=RI(jI({},c),{matchUpFormat:n,categoryType:i,defaultTiming:l});return yu({eventType:s,timingDetails:u})}function yu({timingDetails:t,eventType:e}){const r=aB(t),n=Object.keys((r==null?void 0:r.minutes)||{}),o=(r==null?void 0:r.minutes)&&((n==null?void 0:n.includes(e))&&r.minutes[e]||r.minutes.default),i=tB(RI(jI({},t),{averageMinutes:o})),s=Object.keys((i==null?void 0:i.minutes)||{}),a=(i==null?void 0:i.minutes)&&((s==null?void 0:s.includes(e))&&i.minutes[e]||i.minutes.default),l=e===At?vB:fB,c=(i==null?void 0:i.minutes)&&((s==null?void 0:s.includes(l))&&i.minutes[l]||a);return{averageMinutes:o,recoveryMinutes:a,typeChangeRecoveryMinutes:c}}function on({requiredAttributes:t=["name","value"],extension:e}){if(!e||typeof e!="object"||typeof e.name!="string")return!1;const r=Object.keys(e);return t.filter(n=>r.includes(n)).length===t.length}function Nt({event:t,eventId:e}){var r;if(!t)return{error:Ge};const n=$o({name:_n,event:t}),o=n==null?void 0:n.extension,i=e?de(o==null?void 0:o.value,!1,!0):o==null?void 0:o.value;return e&&((r=t.drawDefinitions)==null||r.forEach(s=>{var a;(a=i==null?void 0:i.flights)==null||a.forEach(l=>{l.drawId===s.drawId&&Object.assign(l,{drawDefinition:s})})})),{flightProfile:i}}var yB=Object.defineProperty,SB=Object.defineProperties,OB=Object.getOwnPropertyDescriptors,FI=Object.getOwnPropertySymbols,bB=Object.prototype.hasOwnProperty,TB=Object.prototype.propertyIsEnumerable,xI=(t,e,r)=>e in t?yB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Su=(t,e)=>{for(var r in e||(e={}))bB.call(e,r)&&xI(t,r,e[r]);if(FI)for(var r of FI(e))TB.call(e,r)&&xI(t,r,e[r]);return t},wB=(t,e)=>SB(t,OB(e));function EB({tournamentRecord:t,drawDefinition:e,event:r,context:n}){var o;if(!t)return{error:re};if(!r)return{error:Ge};const i=de(r);n&&Object.assign(i,n);const s=e&&((o=i.drawDefinitions)==null?void 0:o.find(({drawId:a})=>e.drawId===a));return Oe({event:i,drawDefinition:s})}function $B({tournamentRecord:t,context:e,inContext:r}){if(!t)return{error:re};const{tournamentId:n}=t;return{events:(t.events||[]).map(i=>{const s=de(i);return e&&Object.assign(s,e),r&&Object.assign(s,{tournamentId:n}),s})}}function Qt({tournamentRecord:t,eventId:e,drawId:r}){const n="findEvent";if(!t)return Su({event:void 0,drawDefinition:void 0},k({result:{error:re},stack:n}));const o=(t==null?void 0:t.events)||[];if(r){let i;const s=o.find(a=>{var l;const u=((a==null?void 0:a.drawDefinitions)||[]).find(p=>p.drawId===r);if(u)i=u;else{const{flightProfile:p}=Nt({event:a}),d=(l=p==null?void 0:p.flights)==null?void 0:l.find(v=>v.drawId===r);if(d)return{drawId:r,entries:d.drawEntries,drawName:d.drawName}}return u});if(s)return{event:s,drawDefinition:i}}if(e){const i=o.find(s=>s.eventId===e);return i?{event:i,drawDefinition:void 0}:Su({event:void 0,drawDefinition:void 0},k({result:{error:Ar},stack:n}))}return Su({event:void 0,drawDefinition:void 0},k({result:{error:en},context:{drawId:r,eventId:e},stack:n}))}function Jo({tournamentRecord:t,drawId:e}){if(!t)return{error:re};if(!e)return{error:kr};const r=(t.events||[]).reduce((n,o)=>{const i=(o.drawDefinitions||[]).reduce((s,a)=>a.drawId===e?a:s,void 0);return i&&i.drawId===e?{event:o,drawDefinition:i}:n},void 0);return r?wB(Su({},r),{SUCCESS:V}):k({result:{error:en},stack:"getDrawDefinition"})}var NB=Object.defineProperty,LI=Object.getOwnPropertySymbols,UB=Object.prototype.hasOwnProperty,AB=Object.prototype.propertyIsEnumerable,VI=(t,e,r)=>e in t?NB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,CB=(t,e)=>{for(var r in e||(e={}))UB.call(e,r)&&VI(t,r,e[r]);if(LI)for(var r of LI(e))AB.call(e,r)&&VI(t,r,e[r]);return t};function it(t){if(typeof t!="object")return{error:_e};const e="addExtension";if(!(t!=null&&t.element))return k({result:{error:_e},stack:e});if(typeof t.element!="object")return k({result:{error:X},stack:e});if(!on({extension:t.extension}))return k({result:{error:X,info:"invalid extension"},stack:e});if(t.element.extensions||(t.element.extensions=[]),t.creationTime!==void 0?t.creationTime:!0){const o=new Date().toISOString();Object.assign(t.extension,{createdAt:o})}const n=t.element.extensions.find(({name:o})=>o===t.extension.name);return n?n.value=t.extension.value:t.extension.value&&t.element.extensions.push(t.extension),CB({},V)}const Vf="element required",Bf="missing name";var MB=Object.defineProperty,DB=Object.defineProperties,jB=Object.getOwnPropertyDescriptors,BI=Object.getOwnPropertySymbols,RB=Object.prototype.hasOwnProperty,FB=Object.prototype.propertyIsEnumerable,kI=(t,e,r)=>e in t?MB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,GI=(t,e)=>{for(var r in e||(e={}))RB.call(e,r)&&kI(t,r,e[r]);if(BI)for(var r of BI(e))FB.call(e,r)&&kI(t,r,e[r]);return t},xB=(t,e)=>DB(t,jB(e));function yn(t){return!t||typeof t!="object"?{error:_e}:t!=null&&t.element?typeof(t==null?void 0:t.element)!="object"?{error:X}:t!=null&&t.name?t!=null&&t.element.extensions?(t.element.extensions=t.element.extensions.filter(e=>(e==null?void 0:e.name)!==t.name),GI({},V)):xB(GI({},V),{info:sr}):{error:_e,info:Bf}:{error:_e,info:Vf}}function Ei(t){return!t||typeof t!="object"?{error:_e}:t.tournamentRecord?it({creationTime:t.creationTime,element:t.tournamentRecord,extension:t.extension}):{error:re}}function kf(t){return!t||typeof t!="object"?{error:_e}:t.drawDefinition?it({creationTime:t.creationTime,element:t.drawDefinition,extension:t.extension}):{error:en}}function ao(t){return!t||typeof t!="object"?{error:_e}:t.event?it({creationTime:t.creationTime,extension:t.extension,element:t.event}):{error:Ge}}function LB(t){var e;if(!t||typeof t!="object")return{error:_e};if(!t.participantId)return{error:Et};const r=((e=t.tournamentRecord)==null?void 0:e.participants)||[],n=Eo({participantId:t.participantId,tournamentParticipants:r});return n?it({creationTime:t.creationTime,extension:t.extension,element:n}):{error:jt}}function Gf(t){return!t||typeof t!="object"?{error:_e}:t.tournamentRecord?yn({element:t.tournamentRecord,name:t.name}):{error:re}}function VB(t){return!t||typeof t!="object"?{error:_e}:t.drawDefinition?yn({element:t.drawDefinition,name:t.name}):{error:en}}function Ou(t){return!t||typeof t!="object"?{error:_e}:t!=null&&t.event?yn({element:t.event,name:t.name}):{error:Ar}}function BB(t){var e;if(!t||typeof t!="object")return{error:_e};if(!t.participantId)return{error:Et};const r=((e=t.tournamentRecord)==null?void 0:e.participants)||[],n=Eo({participantId:t.participantId,tournamentParticipants:r});return n?yn({element:n,name:t.name}):{error:jt}}var kB=Object.defineProperty,GB=Object.defineProperties,WB=Object.getOwnPropertyDescriptors,WI=Object.getOwnPropertySymbols,HB=Object.prototype.hasOwnProperty,qB=Object.prototype.propertyIsEnumerable,HI=(t,e,r)=>e in t?kB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qI=(t,e)=>{for(var r in e||(e={}))HB.call(e,r)&&HI(t,r,e[r]);if(WI)for(var r of WI(e))qB.call(e,r)&&HI(t,r,e[r]);return t},zB=(t,e)=>GB(t,WB(e));function Wf({tournamentRecords:t,extension:e}){if(!on({extension:e}))return{error:X};const r="addExtension";for(const n of Object.values(t)){const o=Ei({tournamentRecord:n,extension:e});if(o.error)return k({result:o,stack:r})}return qI({},V)}function bu({tournamentRecords:t,name:e}){if(!e)return{error:_e,info:Bf};let r;return Object.keys(t).find(o=>{const i=t[o],{extension:s}=Fr({tournamentRecord:i,name:e});return r=s,!!s})?{extension:r}:{error:sr}}function Tu({tournamentRecords:t,name:e}){if(!e)return{error:_e,info:Bf};let r=0;for(const n of Object.keys(t)){const o=t[n],i=Gf({tournamentRecord:o,name:e});if(i.error)return k({result:i,stack:"removeExtension"});i.info!==sr&&r++}return zB(qI({},V),{removed:r})}function YB({tournamentRecords:t,eventId:e,extension:r}){if(typeof e!="string")return{error:Ge};if(!on({extension:r}))return{error:X};for(const n of Object.values(t)){const{event:o}=Qt({tournamentRecord:n,eventId:e});if(o)return ao({event:o,extension:r})}return{error:Ar}}var KB=Object.defineProperty,zI=Object.getOwnPropertySymbols,QB=Object.prototype.hasOwnProperty,JB=Object.prototype.propertyIsEnumerable,YI=(t,e,r)=>e in t?KB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,KI=(t,e)=>{for(var r in e||(e={}))QB.call(e,r)&&YI(t,r,e[r]);if(zI)for(var r of zI(e))JB.call(e,r)&&YI(t,r,e[r]);return t};function Hf({tournamentRecords:t}){return typeof t!="object"||!Object.keys(t).length?{error:ke}:{linkedTournamentIds:Object.assign({},...Object.keys(t).map(r=>{var n;const o=t[r],i=o==null?void 0:o.tournamentId,{extension:s}=Fr({tournamentRecord:o,name:is}),a=(((n=s==null?void 0:s.value)==null?void 0:n.tournamentIds)||[]).filter(l=>l!==i);return{[r]:a}}))}}function ZB({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const e=QI(t),{tournamentIds:r}=e;return(r==null?void 0:r.length)>1?Wf({tournamentRecords:t,extension:{name:is,value:{tournamentIds:r}}}):KI({},V)}function XB({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const e=Tu({name:is,tournamentRecords:t});return k({result:e,stack:"unlinkTournaments"})}function ek({tournamentRecords:t,tournamentId:e}){if(typeof t!="object")return{error:X};if(!e)return{error:yo};const r=QI(t),{tournamentIds:n}=r;if(!n.includes(e))return{error:yo};let o;return n.every(i=>{var s;const a=t[i],{extension:l}=Fr({tournamentRecord:a,name:is});if(!l)return!0;const c=((s=l==null?void 0:l.value)==null?void 0:s.tournamentIds)||[];if(!(c!=null&&c.length)||c.length===1&&c.includes(e)||i===e){const d=Gf({name:is,tournamentRecord:a});return d.error&&(o=d.error),d.success}const u=c.filter(d=>d!==e);l.value={tournamentIds:u};const p=Ei({tournamentRecord:a,extension:l});return p.error&&(o=p.error),p.success}),o?{error:o}:KI({},V)}function QI(t){return{tournamentIds:Object.keys(t).filter(Boolean)}}function JI({extension:t,dates:e=[]}){if(!t)return!1;if(typeof t.value=="boolean"&&t.value)return!0;if(typeof t.value=="object"&&Array.isArray(t.value.dates))return e.length?!!e.filter(n=>t.value.dates.includes(n)).length:!0}function xr({element:t,name:e}){const r="findExtension";if(!t||!e)return k({result:{error:_e},stack:r});if(!Array.isArray(t.extensions))return k({result:{error:sr},stack:r});const n=t.extensions.find(o=>(o==null?void 0:o.name)===e);return n?{extension:n}:k({result:{error:sr},stack:r})}var tk=Object.defineProperty,rk=Object.defineProperties,nk=Object.getOwnPropertyDescriptors,ZI=Object.getOwnPropertySymbols,ok=Object.prototype.hasOwnProperty,ik=Object.prototype.propertyIsEnumerable,XI=(t,e,r)=>e in t?tk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sk=(t,e)=>{for(var r in e||(e={}))ok.call(e,r)&&XI(t,r,e[r]);if(ZI)for(var r of ZI(e))ik.call(e,r)&&XI(t,r,e[r]);return t},ak=(t,e)=>rk(t,nk(e));function eP({convertExtensions:t,ignoreDisabled:e,venue:r,court:n}){const o=ak(sk({},de(n,t,!0)),{venueId:r.venueId}),{extension:i}=xr({name:gn,element:n});if(e&&i){const s=typeof i.value=="object"&&i.value.dates||[],a=i.value===!0?[]:o.dateAvailability.map(l=>{const c=l.date;if(!(!c||s.includes(c)))return l}).filter(Boolean);o.dateAvailability=a}return{inContextCourt:o}}const tP="addDrawDefinition",qf="addMatchUps",$i="addParticipants",rP="addScaleItems",nP="addVenue",Ml="audit",oP="deleteParticipants",iP="deleteVenue",sP="deletedDrawIds",aP="deletedMatchUpIds",lP="modifyDrawDefinition",lk="modifyDrawEntries",ck="modifyEventEntries",cP="modifyMatchUp",rr="modifyParticipants",uP="modifyPositionAssignments",dP="modifySeedAssignments",uk="modifyTournamentDetail",vs="modifyVenue",pP="mutations",dk="publishEvent",pk="publishEventSeeding",fk="publishOrderOfPlay",fP="unPublishEvent",vP="unPublishEventSeeding",mP="unPublishOrderOfPlay",zf="updateInContextMatchUp";var vk=Object.defineProperty,mk=Object.defineProperties,hk=Object.getOwnPropertyDescriptors,hP=Object.getOwnPropertySymbols,gk=Object.prototype.hasOwnProperty,_k=Object.prototype.propertyIsEnumerable,gP=(t,e,r)=>e in t?vk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ik=(t,e)=>{for(var r in e||(e={}))gk.call(e,r)&&gP(t,r,e[r]);if(hP)for(var r of hP(e))_k.call(e,r)&&gP(t,r,e[r]);return t},Pk=(t,e)=>mk(t,hk(e));function Dl({tournamentRecord:t,disableNotice:e,context:r,venue:n}){return t?n?(t.venues||(t.venues=[]),n.venueId||(n.venueId=Ye()),t.venues.reduce((i,s)=>i||s.venueId===n.venueId,void 0)?{error:Vx}:(r&&it({element:n,extension:{value:r,name:aI}}),t.venues.push(n),e||He({payload:{venue:n,tournamentId:t.tournamentId},topic:nP}),Pk(Ik({},V),{venue:de(n)}))):{error:_e,info:"missing venue"}:{error:re}}var yk=Object.defineProperty,Sk=Object.defineProperties,Ok=Object.getOwnPropertyDescriptors,wu=Object.getOwnPropertySymbols,_P=Object.prototype.hasOwnProperty,IP=Object.prototype.propertyIsEnumerable,PP=(t,e,r)=>e in t?yk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yP=(t,e)=>{for(var r in e||(e={}))_P.call(e,r)&&PP(t,r,e[r]);if(wu)for(var r of wu(e))IP.call(e,r)&&PP(t,r,e[r]);return t},SP=(t,e)=>Sk(t,Ok(e)),bk=(t,e)=>{var r={};for(var n in t)_P.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&wu)for(var n of wu(t))e.indexOf(n)<0&&IP.call(t,n)&&(r[n]=t[n]);return r};function Yf({convertExtensions:t,tournamentRecord:e,ignoreDisabled:r,dates:n}){var o;if(!e)return{error:re};const i=de((o=e.venues)!=null?o:[],t).filter(a=>{if(!r)return a;const{extension:l}=xr({name:gn,element:a});return!(l!=null&&l.value)&&a}).filter(Boolean),s=i.reduce((a,l)=>{const c=((l==null?void 0:l.courts)||[]).filter(u=>{if(!r&&!(n!=null&&n.length))return u;const{extension:p}=xr({name:gn,element:u});return JI({extension:p,dates:n})}).filter(Boolean).map(u=>{const{inContextCourt:p}=eP({convertExtensions:t,ignoreDisabled:r,venue:l,court:u});return p});return c.length?a.concat(c):a},[]);return{venues:i,courts:s}}function Zo({tournamentRecords:t,tournamentRecord:e,venueId:r}){var n;if(!e)return{error:re};if(!r)return{error:Go};const i=((n=e.venues)!=null?n:[]).reduce((s,a)=>a.venueId===r?a:s,void 0);if(!i&&t){const a=(Hf({tournamentRecords:t}).linkedTournamentIds||[])[e.tournamentId];for(const l of a){const c=t[l],u=Zo({tournamentRecord:c,venueId:r});if(u.success&&u.venue)return Dl({tournamentRecord:e,venue:u.venue}),SP(yP({},V),{venue:i})}}return i?SP(yP({},V),{venue:i}):{error:Ii}}function Tk(t){var e=t,{convertExtensions:r}=e,n=bk(e,["convertExtensions"]);const{tournamentRecords:o,tournamentRecord:i,venueId:s}=n,a=Zo({tournamentRecords:o,tournamentRecord:i,venueId:s});return de(a,r,!0)}var wk=Object.defineProperty,Ek=Object.defineProperties,$k=Object.getOwnPropertyDescriptors,OP=Object.getOwnPropertySymbols,Nk=Object.prototype.hasOwnProperty,Uk=Object.prototype.propertyIsEnumerable,bP=(t,e,r)=>e in t?wk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,TP=(t,e)=>{for(var r in e||(e={}))Nk.call(e,r)&&bP(t,r,e[r]);if(OP)for(var r of OP(e))Uk.call(e,r)&&bP(t,r,e[r]);return t},wP=(t,e)=>Ek(t,$k(e));function ms({tournamentRecords:t,tournamentRecord:e,courtId:r}){var n;if(!e)return{error:re};if(!r)return{error:na};const o="findCourt";let i,s;if(((n=e.venues)!=null?n:[]).forEach(a=>{var l;((l=a.courts)!=null?l:[]).forEach(c=>{c.courtId===r&&(i=c,s=a)})}),i)return wP(TP({},V),{court:i,venue:s});if(t){const l=(Hf({tournamentRecords:t}).linkedTournamentIds||[])[e.tournamentId];for(const c of l){const u=t[c],p=ms({tournamentRecord:u,courtId:r});if(p.success)return p.venue&&Dl({tournamentRecord:e,venue:p.venue}),wP(TP({},V),{court:i,venue:s})}}return k({result:{error:df},stack:o})}function Ak(t){return de(ms(t),!1,!0)}function Ck({tournamentRecord:t,venueId:e,venueIds:r}){return t?{courts:(t.venues||[]).filter(o=>e?o.venueId===e:r?r.includes(o.venueId):!0).map(o=>{const{venueId:i}=o,s=de(o.courts||[]);return s.forEach(a=>Object.assign(a,{venueId:i})),s}).flat()}:{error:re}}var Mk=Object.defineProperty,Dk=Object.defineProperties,jk=Object.getOwnPropertyDescriptors,EP=Object.getOwnPropertySymbols,Rk=Object.prototype.hasOwnProperty,Fk=Object.prototype.propertyIsEnumerable,$P=(t,e,r)=>e in t?Mk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xk=(t,e)=>{for(var r in e||(e={}))Rk.call(e,r)&&$P(t,r,e[r]);if(EP)for(var r of EP(e))Fk.call(e,r)&&$P(t,r,e[r]);return t},Lk=(t,e)=>Dk(t,jk(e));function NP({tournamentRecord:t,internalUse:e,courtId:r}){if(!t)return{error:re};if(!r)return{error:na};const n=ms({tournamentRecord:t,courtId:r});if(n.error)return n;const o=n.court&&(({altitude:i,courtId:s,courtName:a,courtDimensions:l,latitude:c,longitude:u,surfaceCategory:p,surfaceType:d,surfacedDate:v,pace:f,notes:m})=>({altitude:i,courtId:s,courtName:a,courtDimensions:l,latitude:c,longitude:u,surfaceCategory:p,surfaceType:d,surfacedDate:v,pace:f,notes:m}))(n.court);return Lk(xk({},V),{courtInfo:de(o,!1,e)})}var Vk=Object.defineProperty,Bk=Object.defineProperties,kk=Object.getOwnPropertyDescriptors,UP=Object.getOwnPropertySymbols,Gk=Object.prototype.hasOwnProperty,Wk=Object.prototype.propertyIsEnumerable,AP=(t,e,r)=>e in t?Vk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kf=(t,e)=>{for(var r in e||(e={}))Gk.call(e,r)&&AP(t,r,e[r]);if(UP)for(var r of UP(e))Wk.call(e,r)&&AP(t,r,e[r]);return t},CP=(t,e)=>Bk(t,kk(e));function Eu({tournamentRecord:t,venueId:e}){var r,n;if(!t)return{error:re};if(!e)return{error:Go};const o=Zo({tournamentRecord:t,venueId:e});if(o.error)return o;const s=((n=(r=o.venue)==null?void 0:r.courts)!=null?n:[]).map(c=>(({courtInfo:u})=>Kf({},u))(NP({courtId:c.courtId,internalUse:!0,tournamentRecord:t}))),a=o.venue&&(({venueId:c,venueName:u,venueAbbreviation:p})=>({venueAbbreviation:p,venueName:u,venueId:c}))(o.venue),l=a&&CP(Kf({},a),{courtsInfo:s});return CP(Kf({},V),{venueData:de(l,!1,!0)})}const Qf="CHECK_IN",Jf="CHECK_OUT",jl="SCHEDULE.ASSIGNMENT.VENUE",Xo="SCHEDULE.ALLOCATION.COURTS",hs="SCHEDULE.ASSIGNMENT.COURT",MP="SCHEDULE.COURT.ORDER",Rl="SCHEDULE.DATE",Hk="SCHEDULE.ASSIGN.OFFICIAL",Fl="SCHEDULE.TIME.SCHEDULED",Hn="SCHEDULE.TIME.START",ei="SCHEDULE.TIME.STOP",No="SCHEDULE.TIME.RESUME",ti="SCHEDULE.TIME.END",DP="SCHEDULE.TIME.MODIFIERS",jP=["TO_BE_ANNOUNCED","NEXT_AVAILABLE","FOLLOWED_BY","AFTER_REST","RAIN_DELAY"],qk="SCALE",zk="RATING",Yk="RANKING",RP="SEEDING",Hr="PUBLISH",qn="PUBLIC",qr="STATUS";function $u(t){return t.createdAt?new Date(t.createdAt).getTime():0}function Ni({visibilityThreshold:t,timeItems:e,itemType:r}){const n=e.filter(i=>i&&i.itemType===r&&(!t||$u(i)<new Date(t).getTime())).sort((i,s)=>$u(i)-$u(s)).pop(),o=n&&$u(n);return{itemValue:n==null?void 0:n.itemValue,timeStamp:o}}function Zf({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Fl,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{scheduledTime:o}:r}function Ui({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Rl,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{scheduledDate:o}:r}function FP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Xo,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{allocatedCourts:de(o,!1,!0)}:r}function xP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:hs,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{courtId:o}:r}function LP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:jl,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{venueId:o}:r}function Xf({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:DP,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{timeModifiers:o}:r}function gs(t){if(M_.test(t)){const e=gf();return new Date(`${e}T${t}`)}else return new Date(t)}function VP({matchUp:t}){if(!t)return{error:jr};if(!t.timeItems)return{error:g_};const e=t.timeItems.filter(n=>[Hn,ei,No,ti].includes(n==null?void 0:n.itemType)).sort((n,o)=>gs(n.itemValue).getTime()-gs(o.itemValue).getTime()),r=e.reduce((n,o)=>{var i,s;let a;const l=(i=o==null?void 0:o.itemType)==null?void 0:i.split("."),u=`SCHEDULE.TIME.${((s=o==null?void 0:o.itemType)==null?void 0:s.startsWith("SCHEDULE.TIME"))&&l[2]}`;switch(u){case Hn:a=0;break;case ti:if(n.lastValue&&[Hn,No].includes(n.lastType)){const p=gs(o.itemValue).getTime()-gs(n.lastValue).getTime();a=n.milliseconds+p}else a=n.milliseconds;break;case ei:if([Hn,"SCHECULE.TIME.RESUME"].includes(n.lastType)){const p=gs(o.itemValue).getTime()-gs(n.lastValue).getTime();a=n.milliseconds+p}else a=n.milliseconds;break;default:a=n.milliseconds;break}return{milliseconds:a,lastType:u,lastValue:o.itemValue}},{milliseconds:0,lastType:void 0,lastValue:void 0});if([Hn,No].includes(r.lastType)){const n=new Date().getTime()-gs(r.lastValue).getTime();r.milliseconds+=n}return{milliseconds:r.milliseconds,time:Kk(r.milliseconds),relevantTimeItems:e}}function Kk(t){const e=(r,n=2)=>("00"+r).slice(-n);return e(t/36e5|0)+":"+e(t%36e5/6e4|0)+":"+e(t%6e4/1e3|0)}function Qk({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=Ni({timeItems:(n==null?void 0:n.timeItems)||[],itemType:MP,visibilityThreshold:t});return!r||i&&e&&new Date(i).getTime()>new Date(e).getTime()?{courtOrder:o}:r}function Jk({matchUp:t}){const e=(t==null?void 0:t.timeItems)||[],r=i=>i.createdAt?new Date(i.createdAt).getTime():0,n=e.reduce((i,s)=>{const a=s.itemType===Hn&&s;return a&&(!i||r(a)<r(i))?a:i},void 0);return{startTime:n==null?void 0:n.itemValue}}function Zk({matchUp:t}){const e=(t==null?void 0:t.timeItems)||[],r=i=>i.createdAt?new Date(i.createdAt).getTime():0,n=e.reduce((i,s)=>{const a=s.itemType===ti&&s;return a&&(!i||r(a)>r(i))?a:i},void 0);return{endTime:n==null?void 0:n.itemValue}}const ri="SINGLES",BP="SINGLES",sn="DOUBLES",Nu="DOUBLES",Bt="TEAM",lo="TEAM";var Xk=Object.defineProperty,kP=Object.getOwnPropertySymbols,eG=Object.prototype.hasOwnProperty,tG=Object.prototype.propertyIsEnumerable,GP=(t,e,r)=>e in t?Xk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,rG=(t,e)=>{for(var r in e||(e={}))eG.call(e,r)&&GP(t,r,e[r]);if(kP)for(var r of kP(e))tG.call(e,r)&&GP(t,r,e[r]);return t};function ev({scheduleVisibilityFilters:t,afterRecoveryTimes:e,tournamentRecord:r,scheduleTiming:n,matchUpFormat:o,matchUpType:i,matchUp:s,event:a}){var l,c,u,p,d,v,f;if(!s)return{error:jr};if(e&&!s.matchUpType&&!i&&(a||r)&&s.drawId){let $=(l=a==null?void 0:a.drawDefinitions)==null?void 0:l.find(E=>E.drawId===s.drawId);!$&&r&&({drawDefinition:$,event:a}=Qt({tournamentRecord:r,drawId:s.drawId}));const N=s.structureId&&((c=$==null?void 0:$.structures)==null?void 0:c.find(({structureId:E})=>E===s.structureId));i=(N==null?void 0:N.matchUpType)||($==null?void 0:$.matchUpType)||(a==null?void 0:a.eventType)!==Bt&&(a==null?void 0:a.eventType)}const{milliseconds:m,time:h}=VP({matchUp:s}),{startTime:g}=Jk({matchUp:s}),{endTime:_}=Zk({matchUp:s});let I;const{visibilityThreshold:P,eventIds:y,drawIds:S}=t??{};if((!y||y.includes(s.eventId))&&(!S||S.includes(s.drawId))){const $={matchUp:s,visibilityThreshold:P},{allocatedCourts:N}=FP($),{scheduledTime:E}=Zf($);let{scheduledDate:A}=Ui($);const{venueId:U}=LP($),{courtId:C}=xP($),{courtOrder:M}=Qk($),{timeModifiers:D}=Xf($);let R,j,G,W,q;const F=(u=s.matchUpType)!=null?u:i;if(n&&E&&e&&F){const Q=rG({matchUpFormat:(p=s.matchUpFormat)!=null?p:o},n);({averageMinutes:j=0,recoveryMinutes:G=0,typeChangeRecoveryMinutes:W=0}=yu({timingDetails:Q,eventType:F})),(j||G)&&(R=_?Or(at(_),G):Or(E,j+G)),W&&(q=_?Or(at(_),W):Or(E,j+W))}!A&&E&&(A=Re(E));const L=au({scheduledDate:A,scheduledTime:E}),x={},B=((d=r&&U&&Eu({tournamentRecord:r,venueId:U}))==null?void 0:d.venueData)||{};U&&(x[U]=B);const{venueName:z,venueAbbreviation:H,courtsInfo:Y}=B,Z=C&&(Y==null?void 0:Y.find(Q=>Q.courtId===C)),K=Z==null?void 0:Z.courtName;for(const Q of N||[]){if(!r)break;Q.venueId&&!x[Q.venueid]&&(x[Q.venueId]=(v=Eu({venueId:Q.venueId,tournamentRecord:r}))==null?void 0:v.venueData);const J=x[Q.venueId];Q.venueName=J==null?void 0:J.venueName;const te=(f=J==null?void 0:J.courtsInfo)==null?void 0:f.find(ne=>ne.courtId===Q.courtId);Q.courtName=te==null?void 0:te.courtName}I=Oe({typeChangeTimeAfterRecovery:q,timeAfterRecovery:R,scheduledDate:A,scheduledTime:E,isoDateString:L,allocatedCourts:N,timeModifiers:D,venueAbbreviation:H,venueName:z,venueId:U,courtOrder:M,courtName:K,courtId:C,typeChangeRecoveryMinutes:W,recoveryMinutes:G,averageMinutes:j,milliseconds:m,startTime:g,endTime:_,time:h})}else I=Oe({time:h,startTime:g,endTime:_,milliseconds:m});const O=s.matchUpStatus&&Yt.includes(s.matchUpStatus),{scheduledDate:b}=Ui({matchUp:s}),{scheduledTime:w}=Zf({matchUp:s}),T=O&&(Re(_)||Re(b)||Re(w))||void 0;return{schedule:I,endDate:T}}var nG=Object.defineProperty,WP=Object.getOwnPropertySymbols,oG=Object.prototype.hasOwnProperty,iG=Object.prototype.propertyIsEnumerable,HP=(t,e,r)=>e in t?nG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sG=(t,e)=>{for(var r in e||(e={}))oG.call(e,r)&&HP(t,r,e[r]);if(WP)for(var r of WP(e))iG.call(e,r)&&HP(t,r,e[r]);return t};function Uu({collectionPosition:t,collectionId:e,lineUp:r}){let n=[];const o=[];if(r){const i=a=>a===void 0?-1:a,s=r.map(a=>{const{collectionAssignments:l,participantId:c}=a,u=l==null?void 0:l.find(p=>p.collectionPosition===t&&p.collectionId===e);return u&&sG({participantId:c},u)}).filter(Boolean).sort((a,l)=>i(a.substitutionOrder)-i(l.substitutionOrder));for(const a of s){const{participantId:l,previousParticipantId:c,substitutionOrder:u}=a;n.includes(l)||(c&&o.push({previousParticipantId:c,substitutionOrder:u,participantId:l}),n=n.filter(p=>p!==c),n.push(l))}}return{assignedParticipantIds:n,substitutions:o}}const xl="SIGN_IN_STATUS",Fe=Ln.Individual,Mr=Ln.Group,Ce=Ln.Pair,tt=Ln.Team,zn=Ln.Team,Ll="SIGNED_IN",aG="SIGNED_OUT",Vl={TEAM_PARTICIPANT:zn,INDIVIDUAL:Fe,GROUP:Mr,TEAM:tt,PAIR:Ce};var lG=Object.defineProperty,qP=Object.getOwnPropertySymbols,cG=Object.prototype.hasOwnProperty,uG=Object.prototype.propertyIsEnumerable,zP=(t,e,r)=>e in t?lG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dG=(t,e)=>{for(var r in e||(e={}))cG.call(e,r)&&zP(t,r,e[r]);if(qP)for(var r of qP(e))uG.call(e,r)&&zP(t,r,e[r]);return t};function Yn({tournamentParticipants:t,tournamentRecord:e,participantIds:r}){const n="getPairedParticipant";if(!t&&!e)return{error:re};if(!Array.isArray(r)||r.length>2)return{error:pn};if(!r.length)return k({result:{error:Oo},stack:n});t=t||(e==null?void 0:e.participants)||[];const o=t.filter(a=>a.participantType===Ce&&Ht(r,a.individualParticipantIds).length===r.length&&a.individualParticipantIds.length===r.length),i=o[0];if(!i)return k({result:{error:jt},stack:n});const s=de(o.slice(1),!1,!0);return dG({participant:de(i),duplicatedPairParticipants:s},V)}function Bl({drawDefinition:t,participantId:e}){if(typeof t!="object")return{error:ue};if(typeof e!="string")return{error:Et};const{extension:r}=Kt({element:t,name:kn});return{lineUp:((r==null?void 0:r.value)||{})[e]}}function pG({tournamentParticipants:t,positionAssignments:e,collectionPosition:r,drawPositions:n=[],participantMap:o,drawDefinition:i,collectionId:s,sideLineUps:a,matchUpType:l}){if(!s||!r)return;const c=(n==null?void 0:n.map(u=>{var p,d,v,f,m,h;const g=(p=e.find(O=>O.drawPosition===u))==null?void 0:p.participantId,_=a==null?void 0:a.find(O=>(O==null?void 0:O.drawPosition)===u),I=(_==null?void 0:_.teamParticipant)||g&&((d=o==null?void 0:o[g])==null?void 0:d.participant)||(t==null?void 0:t.find(({participantId:O})=>O===g)),P=(_==null?void 0:_.lineUp)||((v=Bl({participantId:g,drawDefinition:i}))==null?void 0:v.lineUp),{assignedParticipantIds:y,substitutions:S}=Uu({collectionPosition:r,collectionId:s,lineUp:P});if(l===dt){if((y==null?void 0:y.length)<=2){const O=(m=(f=o==null?void 0:o[y[0]])==null?void 0:f.pairIdMap)==null?void 0:m[y[1]],w=O&&((h=o[O])==null?void 0:h.participant)||Yn({participantIds:y,tournamentParticipants:t}).participant,T=w==null?void 0:w.participantId;return{[u]:{participantId:T,teamParticipant:I,substitutions:S}}}else if((y==null?void 0:y.length)>2)return{[u]:{teamParticipant:I,substitutions:S}}}else{const O=y==null?void 0:y[0];return O&&{[u]:{participantId:O,teamParticipant:I,substitutions:S}}}}).filter(Boolean))||{};return Object.assign({},...c)}function Tr({matchUps:t=[],interpolate:e}){var r;if(!Array.isArray(t))return{roundMatchUps:[],error:X};const n=t.reduce((d,v)=>{const f=typeof v.roundNumber=="string"?Te(v.roundNumber):v.roundNumber;return!v.roundNumber||d.includes(f)?d:d.concat(f)},[]).sort(er).map(d=>{const v=t.filter(g=>g.roundNumber===d),m=v.find(({matchUpType:g})=>g===Qe)?v.filter(({matchUpType:g})=>g===Qe):v,h=g=>g.sort((_,I)=>er(_.roundPosition,I.roundPosition));return{[d]:h(m)}}),o=t.reduce((d,v)=>{const f=typeof v.roundNumber=="string"?Te(v.roundNumber):v.roundNumber;return d[f]||(d[f]=Oe({abbreviatedRoundName:v.abbreviatedRoundName,finishingRound:v.finishingRound,roundName:v.roundName})),d},{}),i=Object.assign({},...n);if(e){const d=Math.max(...Object.keys(i).map(f=>Te(f)).filter(f=>!isNaN(f))),v=(r=i[d])==null?void 0:r.length;if(v>1&&Zr(v)){const f=d+1,m=f+v/2;ce(f,m).forEach((g,_)=>{i[g]=ce(0,v/(2+_*2)).map(()=>({}))})}}let s=0;const a=Object.assign({},...Object.keys(i).map(d=>{var v,f,m;const h=(v=i[d])==null?void 0:v.length,g=(m=(f=i[d])==null?void 0:f.filter(I=>{var P;return!Yt.includes(I.matchUpStatus)&&!((P=I.score)!=null&&P.scoreStringSide1)}))==null?void 0:m.length,_=h&&h===g;return s=Math.max(s,h),{[d]:{matchUpsCount:h,inactiveCount:g,inactiveRound:_}}}));let l=0,c=0;const u=Object.keys(i).map(d=>Te(d)).filter(d=>!isNaN(d));return u.forEach(d=>{var v,f,m;const h=i[d].sort((_,I)=>_.roundPosition-I.roundPosition),g=h.map(_=>(_==null?void 0:_.drawPositions)||[]).flat();if(a[d].roundNumber=d,a[d].roundFactor=a[d].matchUpsCount?s/a[d].matchUpsCount:1,a[d].finishingRound=(v=o[d])==null?void 0:v.finishingRound,a[d].roundName=(f=o[d])==null?void 0:f.roundName,a[d].abbreviatedRoundName=(m=o[d])==null?void 0:m.abbreviatedRoundName,a[d].finishingPositionRange=i[d][0].finishingPositionRange,d===1||!a[d-1]){const _=g.sort(er),I=qt(_,2);a[d].drawPositions=_,a[d].pairedDrawPositions=I}else{const _=a[d-1],I=_.drawPositions,P=_.matchUpsCount/a[d].matchUpsCount,y=qt(I,P),S=h.map(O=>{const{roundPosition:b}=O,w=[...O.drawPositions||[],void 0,void 0].slice(0,2);if(!b)return w;const T=(w==null?void 0:w.filter(Boolean))||[];if(!(T!=null&&T.length))return[void 0,void 0];if(d<3&&(T==null?void 0:T.length)===2)return w==null?void 0:w.slice().sort(er);const $=Ht(I,T).length!==(T==null?void 0:T.length);if(T!=null&&T.length&&$)return(T==null?void 0:T.length)===1?[T[0],void 0]:w==null?void 0:w.slice().sort(er);const N=(b-1)*2;return y.slice(N,N+2).map(A=>T==null?void 0:T.find(U=>A.includes(U)))});a[d].drawPositions=S==null?void 0:S.flat(),a[d].pairedDrawPositions=S}a[d+1]&&a[d+1].matchUpsCount===a[d].matchUpsCount&&(a[d+1].feedRound=!0,a[d+1].feedRoundIndex=c,a[d].preFeedRound=!0,c+=1),a[d]&&!a[d].feedRound&&(a[d].roundIndex=l,l+=1)}),{hasOddMatchUpsCount:!!Object.values(a).find(({matchUpsCount:d})=>!Zr(d)),maxMatchUpsCount:s,roundMatchUps:i,roundNumbers:u,roundProfile:a}}function YP(t){var e;const r=t==null?void 0:t.matchUp;let n=r==null?void 0:r.matchUpType;if(!n&&((e=r.sides)!=null&&e.length)){const o=r.sides.find(({participant:a})=>a),i=o==null?void 0:o.participant,s=i==null?void 0:i.participantType;n=s===Fe&&At||s===Ce&&dt||s===tt&&tt||void 0}return{matchUpType:n}}function kl({drawDefinition:t,attributes:e}){let{extension:r}=Pu({name:_u,drawDefinition:t});const n=(r==null?void 0:r.value)||{};return e.forEach(o=>{Object.keys(o).forEach(i=>{n[i]?Object.assign(n[i],o[i]):n[i]=o[i]})}),r={name:_u,value:n},kf({drawDefinition:t,extension:r}),{entryProfile:n}}function Gl({drawDefinition:t}){const{extension:e}=Pu({name:_u,drawDefinition:t});return{entryProfile:(e==null?void 0:e.value)||{}}}const he="MAIN",we="QUALIFYING",xt="CONSOLATION",kt="VOLUNTARY_CONSOLATION",ft="PLAY_OFF",tv=[he,we,xt,ft,kt],_s={[we]:1,[he]:2,[ft]:3,[xt]:3,[kt]:4},KP="finishingPositions",QP="aggregateEventStructures",JP={[he]:1,[ft]:2,[xt]:3,[we]:4,[kt]:5},fG={[ft]:1,[he]:2,[xt]:3,[we]:4,[kt]:5},rv="CLUSTER",vG="SEPARATE",nv="WATERFALL",Au="ITEM",gr="CONTAINER",Sn="DRAW",ZP="RANDOM",Ai="TOP_DOWN",Is="BOTTOM_UP",Ci="POSITION",Mi="WINNER",Ps="LOSER",co="FIRST_MATCHUP",On="AD_HOC",ga="FEED_IN",_a="COMPASS",Ia="OLYMPIC",mG="SINGLE_ELIMINATION",Uo="SINGLE_ELIMINATION",Wl="DOUBLE_ELIMINATION",Pa="FIRST_MATCH_LOSER_CONSOLATION",Hl="FIRST_ROUND_LOSER_CONSOLATION",Di="LUCKY_DRAW",Cu="CURTIS_CONSOLATION",hG="CURTIS_CONSOLATION",ov="FEED_IN_CHAMPIONSHIP_TO_SF",ql="FEED_IN_CHAMPIONSHIP_TO_SF",iv="FEED_IN_CHAMPIONSHIP_TO_QF",zl="FEED_IN_CHAMPIONSHIP_TO_QF",sv="FEED_IN_CHAMPIONSHIP_TO_R16",Yl="FEED_IN_CHAMPIONSHIP_TO_R16",XP="MODIFIED_FEED_IN_CHAMPIONSHIP",Kl="MODIFIED_FEED_IN_CHAMPIONSHIP",Ql="FEED_IN_CHAMPIONSHIP",bn="ROUND_ROBIN",Ao="ROUND_ROBIN_WITH_PLAYOFF",ey="DECIDER",ty="BACKDRAW",av={0:{name:"EAST",abbreviation:"E"},"0-1":{name:"WEST",abbreviation:"W"},"0-2":{name:"NORTH",abbreviation:"N"},"0-3":{name:"NORTHEAST",abbreviation:"NE"},"0-1-1":{name:"SOUTH",abbreviation:"S"},"0-1-2":{name:"SOUTHWEST",abbreviation:"SW"},"0-2-1":{name:"NORTHWEST",abbreviation:"NW"},"0-1-1-1":{name:"SOUTHEAST",abbreviation:"SE"}},lv={0:{name:"EAST",abbreviation:"E"},"0-1":{name:"WEST",abbreviation:"W"},"0-2":{name:"NORTH",abbreviation:"N"},"0-1-1":{name:"SOUTH",abbreviation:"S"}},ya="WIN_RATIO",ji="ROUND_OUTCOME",ry=[_a,Cu,zl,Yl,ql,Ql,iv,sv,ov,Pa,Hl,Di,Kl,Ia,ft,Ao],gG={MAIN:he,QUALIFYING:we,CONSOLATION:xt,ITEM:Au,CONTAINER:gr,FIRST_MATCHUP:co,WINNER:Mi,LOSER:Ps,AD_HOC:On,FEED_IN:ga,COMPASS:_a,PLAY_OFF:ft,OLYMPIC:Ia,KNOCKOUT:mG,SINGLE_ELIMINATION:Uo,DOUBLE_ELIMINATION:Wl,CURTIS:Cu,FICSF:ov,FICQF:iv,FICR16:sv,MFIC:XP,VOLUNTARY_CONSOLATION:kt,FIRST_MATCH_LOSER_CONSOLATION:Pa,FIRST_ROUND_LOSER_CONSOLATION:Hl,MODIFIED_FEED_IN_CHAMPIONSHIP:Kl,FEED_IN_CHAMPIONSHIP_TO_R16:Yl,FEED_IN_CHAMPIONSHIP_TO_QF:zl,FEED_IN_CHAMPIONSHIP_TO_SF:ql,FEED_IN_CHAMPIONSHIP:Ql,LUCKY_DRAW:Di,ROUND_ROBIN_WITH_PLAYOFF:Ao,ROUND_ROBIN:bn,DECIDER:ey,BACKDRAW:ty,COMPASS_ATTRIBUTES:av,OLYMPIC_ATTRIBUTES:lv,DRAW:Sn,RANDOM:ZP,TOP_DOWN:Ai,BOTTOM_UP:Is,WATERFALL:nv,WIN_RATIO:ya,ROUND_OUTCOME:ji,MULTI_STRUCTURE_DRAWS:ry,generatedDrawTypes:[On,_a,Cu,Wl,zl,Yl,ql,Ql,ga,Pa,Hl,Di,Kl,Ia,ft,bn,Ao,Uo],stageOrder:_s,finishOrder:JP,AGGREGATE_EVENT_STRUCTURES:QP,FINISHING_POSITIONS:KP};function Ri(t,e,r){var n,o;const i=v=>{var f,m;return(m=(f=Kt({element:v,name:Gn}))==null?void 0:f.extension)==null?void 0:m.value},s=r==null?void 0:r.deprioritizeCompleted,a=(r==null?void 0:r.mode)===QP&&fG,l=(r==null?void 0:r.mode)===KP&&JP,c=l||a||_s,u=v=>(v==null?void 0:v.stage)===he&&(v==null?void 0:v.stageSequence)===1,p=v=>u(v)?-1:c[v==null?void 0:v.stage],d=v=>v==null?void 0:v.matchUps.every(({matchUpStatus:f})=>Yt.includes(f)?1:-1);return s&&d(t)-d(e)||a&&p(t)-p(e)||((t==null?void 0:t.stage)&&c[t.stage]||0)-((e==null?void 0:e.stage)&&c[e.stage]||0)||(i(t)||0)-(i(e)||0)||!l&&!a&&(((n=e==null?void 0:e.positionAssignments)==null?void 0:n.length)||1/0)-(((o=t==null?void 0:t.positionAssignments)==null?void 0:o.length)||1/0)||((t==null?void 0:t.stageSequence)||0)-((e==null?void 0:e.stageSequence)||0)||(ny(t)||0)-(ny(e)||0)}function ny(t){return((t==null?void 0:t.matchUps)||[]).reduce((e,r)=>{var n;const o=(((n=r.finishingPositionRange)==null?void 0:n.winner)||[]).reduce((i,s)=>i+s,0);return!e||o<e?o:e},void 0)}function Ne({drawDefinition:t,structureId:e}){if(!t)return{error:ue};if(!e)return{error:yr};const{structures:r}=an({drawDefinition:t}),n=r==null?void 0:r.map(s=>s.structures?[...s.structures].concat(s):s).flat(),o=n==null?void 0:n.find(s=>s.structureId===e);if(!o)return{error:bt};const i=o.structureType===Au?n==null?void 0:n.find(s=>{var a;return(a=s.structures)==null?void 0:a.some(l=>l.structureId===e)}):void 0;return{structure:o,containingStructure:i}}function an({withStageGrouping:t,drawDefinition:e,stageSequences:r,stageSequence:n,roundTarget:o,sortConfig:i,stages:s,stage:a}){var l,c;const u=!e&&ue||!(e!=null&&e.structures)&&ax||void 0;if(u)return{error:u,structures:[],stageStructures:{}};const p=h=>{var g,_;const I=(_=(g=Kt({element:h,name:Gn}))==null?void 0:g.extension)==null?void 0:_.value;return!o||o===I},d=(c=(l=e==null?void 0:e.structures)==null?void 0:l.filter(f).filter(m).filter(p).sort((h,g)=>Ri(h,g,i)))!=null?c:[],v=t?Object.assign({},...tv.map(h=>{const g=d==null?void 0:d.filter(_=>_.stage===h);return(g==null?void 0:g.length)&&{[h]:g}}).filter(Boolean)):{};return{structures:d,stageStructures:v};function f(h){return!a&&!Array.isArray(s)||a&&h.stage===a||Array.isArray(s)&&s.includes(h.stage)}function m(h){return!n&&!Array.isArray(r)||n&&h.stageSequence===n||Array.isArray(r)&&r.includes(h.stageSequence)}}const Tn=ar.Alternate,Mu=ar.Confirmed,wn=ar.DirectAcceptance,Jl=ar.FeedIn,Du=ar.JuniorExempt,Zl=ar.LuckyLoser,ju=ar.OrganiserAcceptance,Ru=ar.Qualifier,_G=ar.Registered,Fu=ar.SpecialExempt,En=ar.Ungrouped,ys=ar.Unpaired,Sa=ar.Wildcard,ni=ar.Withdrawn,cv=[Mu,wn,Du,ju,Fu],IG=[Jl,Zl,Ru],Ss=[Mu,wn,Jl,Du,ju,Fu,Sa],Fi=[Mu,wn,Jl,Du,Zl,Ru,ju,Fu,Sa],PG=[Tn,Mu,wn,Jl,Du,Zl,ju,Ru,_G,Fu,En,ys,Sa,ni],oy=Fi;function Xl({stage:t,drawDefinition:e}){const{entryProfile:r}=Gl({drawDefinition:e}),n=Object.keys(r).includes(t);if(!n&&tv.includes(t)){const o=[{[t]:{drawSize:void 0,alternates:!0}}];return kl({drawDefinition:e,attributes:o}),!0}return n}function yG({stage:t,drawDefinition:e}){var r;const{entryProfile:n}=Gl({drawDefinition:e});return((r=n[t])==null?void 0:r.alternates)||0}function SG({stage:t,drawDefinition:e}){var r;const{entryProfile:n}=Gl({drawDefinition:e});return((r=n[t])==null?void 0:r.wildcardsCount)||0}function xu({stage:t,drawDefinition:e,entryStatus:r}){return e.entries.reduce((n,o)=>o.entryStage===t&&o.entryStatus===r?n+1:n,0)}function Os({provisionalPositioning:t,drawDefinition:e,stageSequence:r,entryStatuses:n,structureId:o,roundTarget:i,stages:s,stage:a}){var l,c;const u=(c=(l=e.entries)==null?void 0:l.reduce((p,d)=>{var v,f,m;const h=(f=(v=Kt({name:Gn,element:d}))==null?void 0:v.extension)==null?void 0:f.value,g=a&&d.entryStage===a||(s==null?void 0:s.length)&&d.entryStage&&s.includes(d.entryStage),_=!n||d.entryStatus&&n.includes(d.entryStatus),I=(m=d.entryStageSequence)!=null?m:1;return g&&(!r||I===r)&&_&&(!i||!h||i===h)?p.concat(d):p},[]))!=null?c:[];if(o&&a===ft){const{playoffEntries:p,error:d}=OG({provisionalPositioning:t,drawDefinition:e,structureId:o});return d&&console.log("playoff entries error"),p!=null&&p.length?p:u}return u}function OG({provisionalPositioning:t,drawDefinition:e,structureId:r}){var n;const o=[],i=((n=e.links)!=null?n:[]).find(s=>s.linkType===Ci&&s.target.structureId===r);if(i){const{finishingPositions:s,structureId:a}=i.source,{structure:l}=Ne({drawDefinition:e,structureId:a});(l==null?void 0:l.structureType)===gr&&(l.structures||[]).forEach(u=>{const p=u.positionAssignments||[],{structureId:d}=u,v=d,f=Object.assign({},...p.map(_=>{var I;const{participantId:P}=_,y=(I=Kt({element:_,name:Ko}).extension)==null?void 0:I.value;return y&&P?{[P]:y}:void 0}).filter(Boolean)),h=Object.keys(f).reduce((_,I)=>{const P=f[I],y=P.groupOrder||t&&P.provisionalOrder;return _.includes(y)||_.push(y),_},[]).length===Object.keys(f).length,g=Object.keys(f).filter(_=>{const I=f[_],P=I.groupOrder||t&&I.provisionalOrder;return s==null?void 0:s.includes(P)});(!t||h)&&g.forEach(_=>{const I=f[_],{groupOrder:P,provisionalOrder:y,GEMscore:S}=I,O=P||t&&y,b=(s??[]).sort().indexOf(O)+1;o.push({entryStage:ft,entryStatus:Jl,placementGroup:b,groupingValue:v,participantId:_,GEMscore:S})})})}return{playoffEntries:o}}function iy({stage:t,drawDefinition:e}){return Ss.reduce((r,n)=>(xu({drawDefinition:e,entryStatus:n,stage:t})||0)+r,0)}function bG({stage:t,drawDefinition:e}){return xu({entryStatus:Sa,drawDefinition:e,stage:t})}function $n({provisionalPositioning:t,drawDefinition:e,structureId:r,structure:n}){var o;let i,s=[];if(n||({structure:n,error:i}=Ne({drawDefinition:e,structureId:r})),i||!n)return{seedAssignments:[],error:bt};r||(r=n.structureId);const{stage:a,stageSequence:l}=n,u=a===ft&&e&&Os({provisionalPositioning:t,drawDefinition:e,stageSequence:l,structureId:r,stage:a}),p=u?u.filter(v=>v.placementGroup===1).sort((v,f)=>v.GEMscore<f.GEMscore&&1||v.GEMscore>f.GEMscore&&-1||0).map((v,f)=>{const m=f+1;return{participantId:v.participantId,seedValue:m,seedNumber:m,seedProxy:!0}}):[];p.length?s=p:n.seedAssignments?s=n.seedAssignments:i=nx;const d=n.seedLimit||((o=n==null?void 0:n.positionAssignments)==null?void 0:o.length);return{seedAssignments:s,seedLimit:d,stage:a,stageSequence:l,error:i}}function uv({drawDefinition:t}){if(typeof t!="object")return{error:Xi};const e={},{structures:r=[],links:n=[]}=t||{},o=r.reduce((s,a)=>{const{stage:l}=a;return s[l]?s[l].push(a):s[l]=[a],s},{});for(const s of Object.keys(o)){const a=o[s].find(({stageSequence:u})=>u===1);if(!a)continue;const{structureId:l}=a;i({aggregator:{},targetRound:0,exitProfiles:e,exitProfile:"0",structureId:l,stage:s})}return{exitProfiles:e};function i({exitProfiles:s,exitProfile:a,structureId:l,targetRound:c,aggregator:u,stage:p}){s[l]||(s[l]=[]),a==="0"&&[xt,ft].includes(p)||s[l].push(a);const d=n.filter(v=>v.source.structureId===l&&v.source.roundNumber>=c);for(const v of d){const f=v.source.roundNumber,m=v.target.roundNumber,h=v.target.structureId,g=r.find(I=>I.structureId===h).stage,_=[g,h,m,f].join("|");if(u[_])return;u[_]=!0,i({exitProfile:`${a}-${f}`,structureId:h,exitProfiles:s,targetRound:m,aggregator:u,stage:g})}}}function lr({drawDefinition:t,structure:e}){var r;const n={},o=[];return((r=t==null?void 0:t.structures)!=null?r:[e]).filter(i=>i&&typeof i=="object").forEach(i=>{if(!i)return;const{structureId:s,matchUps:a,structures:l}=i,c=Array.isArray(l);if(c)c&&l.forEach(u=>{const{structureName:p}=u,d=u.matchUps;n[u.structureId]={matchUps:d,itemStructureIds:[],structureName:p},d&&(o.push(...d),d.forEach(v=>{v.tieMatchUps&&o.push(...v.tieMatchUps)})),n[s]||(n[s]={itemStructureIds:[],matchUps:[]}),n[s].itemStructureIds||(n[s].itemStructureIds=[]),n[s].itemStructureIds.push(u.structureId)});else{const u=a;n[s]={matchUps:u,itemStructureIds:[]},u==null||u.forEach(p=>{o.push(p),p.tieMatchUps&&o.push(...p.tieMatchUps)})}}),{mappedMatchUps:n,drawMatchUps:o}}function xi({mappedMatchUps:t,matchUpsMap:e,structureId:r,inContext:n}){var o;t=(o=e==null?void 0:e.mappedMatchUps)!=null?o:t;const i=t[r],s=((i==null?void 0:i.itemStructureIds)||[]).map(a=>{const{matchUps:l,structureName:c}=t[a];return n?l.map(u=>Object.assign(de(u,!0,!0),{containerStructureId:r,structureId:a,structureName:c})):l}).flat();return((i==null?void 0:i.matchUps)||[]).concat(...s)}function sy({groupedOrder:t,roundPositionsCount:e}){if(!t||(t==null?void 0:t.length)<=e)return t;const n=qt(t,t.length/e).map(i=>i.reduce((s,a)=>s+a)),o=n.slice().sort(er);return n.map(i=>o.indexOf(i)+1)}function Lu(t){if(!Array.isArray(t))return"";const e=t.filter(Ct);return e.length?We([Math.min(...e),Math.max(...e)]).join("-"):""}function TG({drawDefinition:t,structureId:e,matchUpsMap:r}){if(!t)return{error:ue};if(!e)return{error:yr};const{structure:n}=Ne({drawDefinition:t,structureId:e});if((n==null?void 0:n.stage)!==xt)return{error:Bo,info:"Structure is not CONSOLATION stage"};const{links:o}=t,i=(o==null?void 0:o.filter(p=>p.target.structureId===e))||[],s=(i==null?void 0:i.reduce((p,d)=>{const{structureId:v}=d.source;return p.includes(v)?p:p.concat(v)},[]))||[],a=Object.assign({},...s.map(p=>{const d=xi({structureId:p,matchUpsMap:r}),{roundProfile:v}=Tr({matchUps:d});return{[p]:v}})),l=xi({matchUpsMap:r,structureId:e}),{roundProfile:c}=Tr({matchUps:l}),u={};return i==null||i.forEach(p=>{var d;const{structureId:v,roundNumber:f}=p.source,{feedProfile:m,groupedOrder:h,positionInterleave:g,roundNumber:_}=p.target,I=a[v],P=(d=I[1])==null?void 0:d.drawPositions,y=I[f],S=y==null?void 0:y.matchUpsCount;if(!S)return;const O=S?P.length/S:0,b=P.length/O;let w=P.slice();const T=sy({roundPositionsCount:w.length,groupedOrder:h}),$=(T==null?void 0:T.length)||1;if($<=b){const U=P.length/$,C=qt(w,U);m===Is&&C.forEach(M=>M.reverse()),w=(T==null?void 0:T.length)&&(T==null?void 0:T.map(M=>C[M-1]).flat())||w}let N=qt(w,O);if(!(T!=null&&T.length)&&m===Is&&N.reverse(),g){const U=ce(0,g.interleave).map(()=>{}),C=ce(0,g.offset).map(()=>{});N=N.map(D=>[D,...U]),N.unshift(C),N=N.flat(1);const M=N.length-g.offset;N=N.slice(0,M)}u[_]||(u[_]={});const E=c==null?void 0:c[_],A=E!=null&&E.feedRound?2:1;N.forEach((U,C)=>{const M=1+C*A;u[_][M]||(u[_][M]=Lu(U))})}),{sourceDrawPositionRanges:u}}function ay({drawDefinition:t}){if(!t)return{error:ue};const e={};return{allPositionedParticipantIds:(t.structures||[]).map(n=>{var o;const i=n.stage;e[i]||(e[i]=[]);const{positionAssignments:s}=st({structure:n}),a=(o=s==null?void 0:s.map(Fn("participantId")).filter(Boolean))!=null?o:[];return e[i].push(...a),a}).flat(),stagePositionedParticipantIds:e}}function st({drawDefinition:t,structureId:e,structure:r}){let n,o=[];if(!r){if(!t)return{positionAssignments:o,error:ue};if({structure:r,error:n}=Ne({drawDefinition:t,structureId:e}),n)return{positionAssignments:o,error:n}}return r.structures?o=[].concat(...r.structures.map(i=>st({structure:i}).positionAssignments)):r.positionAssignments?o=r.positionAssignments:n=px,{positionAssignments:o,error:n}}function Dt({drawDefinition:t,structureId:e,structure:r}){var n;const o=((n=st({drawDefinition:t,structureId:e,structure:r}))==null?void 0:n.positionAssignments)||[],i=o==null?void 0:o.filter(u=>{var p,d;return(d=(p=u.participantId)!=null?p:u.bye)!=null?d:u.qualifier}),s=o&&(o==null?void 0:o.length)===(i==null?void 0:i.length),a=o==null?void 0:o.filter(u=>!u.participantId&&!u.bye&&!u.qualifier),l=o==null?void 0:o.filter(u=>!u.participantId&&u.bye),c=o==null?void 0:o.filter(u=>!u.participantId&&u.qualifier);return{allPositionsAssigned:s,positionAssignments:o,unassignedPositions:a,assignedPositions:i,qualifierPositions:c,byePositions:l}}function wG({drawPositions:t,roundProfile:e,roundNumber:r}){const n=[void 0,void 0];if(zF(t))return{orderedDrawPositions:n,displayOrder:n};const o=e[r],i=o==null?void 0:o.pairedDrawPositions,s=(i==null?void 0:i.find(l=>Xt(l||[],t.filter(Boolean))))||n,a=o==null?void 0:o.feedRound;if(qF(t)){const l=t.sort(er);return{orderedDrawPositions:l.length===2?l:s,displayOrder:a?l:s}}if(a){const c=[t.find(u=>!isNaN(Te(u))),void 0];return{orderedDrawPositions:c,displayOrder:c}}return{orderedDrawPositions:s,displayOrder:s}}function EG({drawDefinition:t,roundProfile:e,structureId:r,matchUpsMap:n}){var o;if(!t)return{error:ue};if(!r)return{error:yr};if(!e){const c=xi({matchUpsMap:n,structureId:r});if({roundProfile:e}=Tr({matchUps:c}),!e)return{error:_e}}const s=(Math.min(...((o=e==null?void 0:e[1])==null?void 0:o.drawPositions)||[])||1)-1,a=Object.keys(e);return{drawPositionsRanges:Object.assign({},...(a||[]).map(c=>{var u,p;const d=(u=e==null?void 0:e[c])==null?void 0:u.matchUpsCount,v=((p=e==null?void 0:e[1])==null?void 0:p.drawPositions)||[],f=qt(v,v.length/d),m=f.map(Lu),h=f.map(y=>y.map(S=>S-s)).map(Lu),g=a.map(y=>{var S,O;if(y>c)return;const b=(O=(S=e==null?void 0:e[y])==null?void 0:S.drawPositions)!=null?O:[];return qt(b,b.length/d)}).filter(Boolean),_=ce(0,d).map(y=>g.map(S=>S[y]).flat().filter(Boolean).sort(er)).map(y=>We(y)),I=_.map(y=>HF(y).map(Lu).join(", ")),P=Object.assign({},...ce(0,d).map(y=>({[y+1]:{firstRoundDrawPositionsRange:m[y],firstRoundOffsetDrawPositionsRange:h[y],possibleDrawPositions:_[y],drawPositionsRange:I[y]}})));return{[c]:P}}))}}function dv({matchUp:t}){let e=[],r=[],n=[],o=[],i;if(t||(i=jr),t&&!t.sides&&(i=tn),t&&!t.hasContext&&(i=ru),!i){o=t.sides.map(l=>l.participantId);const s=t.sides.filter(l=>l.participantType===Fe).map(l=>l.participantId).filter(Boolean);e=t.sides.map(l=>{var c;return(c=l.participant)==null?void 0:c.individualParticipants}).filter(Boolean).map(l=>l.map(c=>c==null?void 0:c.participantId).filter(Boolean)),n=[...s,...e.flat()].filter(Boolean),r=We(n.concat(o)).filter(Boolean)}return{nestedIndividualParticipantIds:e,allRelevantParticipantIds:r,individualParticipantIds:n,sideParticipantIds:o,error:i}}function ec({matchUp:t}){if(!t)return{error:jr};if(!t.hasContext)return{error:ru};if(!t.sides||t.sides.filter(Boolean).length!==2)return{error:tn};const{nestedIndividualParticipantIds:e,allRelevantParticipantIds:r,sideParticipantIds:n}=dv({matchUp:t}),i=(t.timeItems||[]).filter(c=>[Qf,Jf].includes(c==null?void 0:c.itemType)).sort((c,u)=>new Date(c.createdAt).getTime()-new Date(u.createdAt).getTime()),a=i.map(c=>c.itemValue).filter(c=>i.filter(u=>(u==null?void 0:u.itemValue)===c).reverse()[0].itemType===Qf);return e==null||e.forEach((c,u)=>{const p=n[u],d=(c==null?void 0:c.length)&&c.every(v=>a.includes(v));p&&d&&!a.includes(p)&&a.push(p)}),n.forEach((c,u)=>{a.includes(c)&&((e==null?void 0:e[u])||[]).forEach(p=>{p&&!a.includes(p)&&a.push(p)})}),{allParticipantsCheckedIn:n.reduce((c,u)=>a.includes(u)&&c,!0),checkedInParticipantIds:a,allRelevantParticipantIds:r}}function bs(t){const{matchUps:e,isCollectionMatchUp:r,excludeMatchUpStatuses:n,matchUpStatuses:o,hasWinningSide:i,matchUpFormats:s,roundPositions:a,matchUpFormat:l,collectionIds:c,isMatchUpTie:u,roundNumbers:p,matchUpIds:d,roundNames:v,stageSequences:f,scheduledDates:m,scheduledDate:h,participantIds:g,processContext:_,tournamentIds:I,matchUpTypes:P,structureIds:y,readyToScore:S,courtIds:O,eventIds:b,venueIds:w,drawIds:T,stages:$,filterMatchUpIds:N=!0,filterMatchUpTypes:E=!0}=t,A=Array.isArray(g)?g.filter(Boolean):[],U=Array.isArray(o)?o.filter(Boolean):[],C=Array.isArray(n)?n.filter(Boolean):[],M=Array.isArray($)?$.filter(Boolean):[],D=Array.isArray(f)?f.filter(Boolean):[],R=Array.isArray(c)?c.filter(Boolean):[],j=Array.isArray(v)?v.filter(Boolean):[],G=Array.isArray(p)?p.filter(Boolean):[],W=Array.isArray(a)?a.filter(Boolean):[],q=Array.isArray(d)&&N?d.filter(Boolean):[],F=Array.isArray(P)&&E?P.filter(Boolean):[],L=Array.isArray(O)?O.filter(Boolean):[],x=Array.isArray(w)?w.filter(Boolean):[],B=Array.isArray(s)&&s.filter(Boolean)||typeof l=="string"&&[l]||[],z=Array.isArray(m)&&m.filter(Boolean)||typeof h=="string"&&h.length&&[h]||[],H=Array.isArray(I)?I.filter(Boolean):[],Y=Array.isArray(b)?b.filter(Boolean):[],Z=Array.isArray(T)?T.filter(Boolean):[],K=Array.isArray(y)?y.filter(Boolean):[];return e.filter(Q=>{var J,te;if(S&&Q.matchUpType!==hn&&!Q.readyToScore||Q.winningSide&&i&&![1,2].includes(Q.winningSide)||u!==void 0&&(u&&!Q.tieMatchUps||!u&&Q.tieMatchUps)||r!==void 0&&(r&&!Q.collectionId||!r&&Q.collectionId)||M.length&&!M.includes(Q.stage)||D.length&&!D.includes(Q.stageSequence)||R.length&&(!Q.collectionId||!R.includes(Q.collectionId))||j.length&&(!Q.roundName||!j.includes(Q.roundName))||G.length&&(!Q.roundNumber||!G.includes(Q.roundNumber))||W.length&&(!Q.roundPosition||!W.includes(Q.roundPosition))||U.length&&(!Q.matchUpStatus||!U.includes(Q.matchUpStatus))||C.length&&Q.matchUpStatus&&C.includes(Q.matchUpStatus)||q.length&&!q.includes(Q.matchUpId)||F.length&&(!Q.matchUpType||!F.includes(Q.matchUpType))||B.length&&(!Q.matchUpFormat||!B.includes(Q.matchUpFormat)))return!1;if(z!=null&&z.length){const{scheduledTime:ne}=Zf({matchUp:Q}),{scheduledDate:ee}=Ui({matchUp:Q}),ie=Re(ne)||ee;if(!z.find(ae=>io(ae,ie)))return!1}if(L.length){const{courtId:ne}=xP({matchUp:Q}),{allocatedCourts:ee}=FP({matchUp:Q}),oe=ee==null?void 0:ee.map(({courtId:ie})=>ie);if(!L.filter(Boolean).includes(ne)||oe!=null&&oe.includes(ne))return!1}if(x.length){const{venueId:ne}=LP({matchUp:Q});if(!x.filter(Boolean).includes(ne))return!1}if(_){if(H.length&&!H.includes(Q.tournamentId)||Y.length&&!Y.includes(Q.eventId)||Z.length&&!Z.includes(Q.drawId)||K.length&&!K.includes(Q.structureId))return!1;if(A.length){const ne=(te=(J=Q.sides)==null?void 0:J.map(({participantId:oe})=>oe).filter(Boolean))!=null?te:[];if(!A.some(oe=>ne.includes(oe)))return!1}}return!0})}function $G({hasOddMatchUpsCount:t,drawDefinition:e,roundMatchUps:r,structure:n}){var o,i,s;if(!n)return!1;r||({hasOddMatchUpsCount:t,roundMatchUps:r}=Tr({matchUps:(o=n.matchUps)!=null?o:[]}));const a=!!((i=r==null?void 0:r[1])!=null&&i.find(({drawPositions:c})=>c)),l=!((s=r==null?void 0:r[2])!=null&&s.find(({drawPositions:c})=>c));return t&&!(n!=null&&n.structures)&&a&&l&&!(e!=null&&e.drawType&&e.drawType!==Di)}function Co({drawDefinition:t,structure:e}){var r;return e?!(e!=null&&e.structures)&&!(t!=null&&t.drawType&&t.drawType!==On)&&!((r=e==null?void 0:e.matchUps)!=null&&r.find(({roundPosition:n})=>!!n)):!1}const ly={[Ef]:{policyName:"Round Naming Default",abbreviatedRoundNamingMap:{1:"F",2:"SF",4:"QF"},roundNamingMap:{1:"Final",2:"Semifinal",4:"Quarterfinal"},affixes:{roundNumber:"R",preFeedRound:"Q"},stageConstants:{[he]:"",[ft]:"P",[we]:"Q",[xt]:"C"}}};function NG({roundNamingPolicy:t,structure:e,matchUps:r}){const{hasOddMatchUpsCount:n,roundProfile:o,roundMatchUps:i}=Tr({matchUps:r}),{structureAbbreviation:s,stage:a}=e,l=Co({structure:e}),c=$G({hasOddMatchUpsCount:n,roundMatchUps:i,structure:e}),u=e.structures,p={},d=ly[Ef],v=(t==null?void 0:t.roundNamingMap)||d.roundNamingMap||{},f=(t==null?void 0:t.abbreviatedRoundNamingMap)||d.abbreviatedRoundNamingMap||{},m=(t==null?void 0:t.affixes)||d.affixes,h=a&&a!==he&&a[0],g=t==null?void 0:t.stageConstants,_=a&&(g==null?void 0:g[a])||h,I=o?Object.keys(o):[];return u||l||c?Object.assign(p,...I.map(P=>{const y=`Round ${P}`,S=`R${P}`;return{[P]:{roundName:y,abbreviatedRoundName:S}}})):Object.assign(p,...I.map(P=>{if(!(o!=null&&o[P]))return;const{matchUpsCount:y,preFeedRound:S}=o[P],O=y*2,b=v[y]||`${m.roundNumber}${O}`,w=S?`-${m.preFeedRound}`:"",T=`${b}${w}`,$=[_,s,T].filter(Boolean).join("-"),E=`${f[y]||`${m.roundNumber}${O}`}${w}`,A=[_,s,E].filter(Boolean).join("-");return{[P]:{abbreviatedRoundName:A,roundName:$}}})),{roundNamingProfile:p,roundProfile:o,roundMatchUps:i}}function UG({drawPositionCollectionAssignment:t,positionAssignments:e,displaySideNumber:r,seedAssignments:n,drawPosition:o,isFeedRound:i,sideNumber:s}){var a,l,c,u;const p=e.find(g=>g.drawPosition===o),d=t?(a=t[o])==null?void 0:a.participantId:p==null?void 0:p.participantId,v=p?AG({displaySideNumber:r,seedAssignments:n,participantId:d,assignment:p,sideNumber:s}):{};i&&(s===1?Object.assign(v,{participantFed:!0}):Object.assign(v,{participantAdvanced:!0}));const f=(l=t==null?void 0:t[o])==null?void 0:l.teamParticipant,m=(c=t==null?void 0:t[o])==null?void 0:c.participant,h=(u=t==null?void 0:t[o])==null?void 0:u.substitutions;return m&&Object.assign(v,{participant:m}),h&&Object.assign(v,{substitutions:h}),f&&Object.assign(v,{teamParticipant:f}),v}function AG({displaySideNumber:t,seedAssignments:e,participantId:r,assignment:n,sideNumber:o}){const i={drawPosition:n.drawPosition,displaySideNumber:t,sideNumber:o};if(r){const s=CG({seedAssignments:e,participantId:r});Object.assign(i,s,{participantId:r})}else n.bye&&Object.assign(i,{bye:!0});return n.qualifier&&Object.assign(i,{qualifier:!0}),i}function CG({seedAssignments:t,participantId:e}){return t==null?void 0:t.find(r=>!r.seedProxy&&r.participantId===e)}const Oa="ANY",vt="MALE",Mo="MIXED",Ts="OTHER",Tt="FEMALE",cy={ANY:Oa,MALE:vt,FEMALE:Tt,MIXED:Mo,OTHER:Ts};var MG=Object.defineProperty,DG=Object.defineProperties,jG=Object.getOwnPropertyDescriptors,uy=Object.getOwnPropertySymbols,RG=Object.prototype.hasOwnProperty,FG=Object.prototype.propertyIsEnumerable,dy=(t,e,r)=>e in t?MG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ln=(t,e)=>{for(var r in e||(e={}))RG.call(e,r)&&dy(t,r,e[r]);if(uy)for(var r of uy(e))FG.call(e,r)&&dy(t,r,e[r]);return t},Vu=(t,e)=>DG(t,jG(e));function Je({scheduleVisibilityFilters:t,tournamentAppliedPolicies:e,provisionalPositioning:r,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,seedAssignments:a,contextFilters:l,contextContent:c,matchUpFilters:u,participantMap:p,scheduleTiming:d,contextProfile:v,drawDefinition:f,context:m={},exitProfiles:h,matchUpsMap:g,structure:_,inContext:I,event:P}){var y,S,O,b,w,T,$;let N={},E={};if(n=n??(s==null?void 0:s.participants),!_)return{collectionPositionMatchUps:N,error:ra,roundMatchUps:E,matchUps:[]};const A=Array.isArray(u==null?void 0:u.eventIds)?u==null?void 0:u.eventIds.filter(Boolean):[],U=Array.isArray(u==null?void 0:u.structureIds)?u==null?void 0:u.structureIds.filter(Boolean):[],C=Array.isArray(u==null?void 0:u.drawIds)?u==null?void 0:u.drawIds.filter(Boolean):[],M=!(m!=null&&m.eventId)||!(A!=null&&A.length)&&!((y=l==null?void 0:l.eventIds)!=null&&y.filter(Boolean).length)||(A==null?void 0:A.includes(m.eventId))||((S=l==null?void 0:l.eventIds)==null?void 0:S.includes(m.eventId)),D=!(U!=null&&U.length)||U.includes(_.structureId),R=!f||!(C!=null&&C.length)||C.includes(f.drawId);if(!M||!D||!R)return{collectionPositionMatchUps:N,roundMatchUps:E,matchUps:[]};v&&!c&&(c=wo({tournamentRecord:s,contextProfile:v,drawDefinition:f}));const{appliedPolicies:j}=pt({drawDefinition:f}),G=ln(ln(ln({},e),j),i),W=(O=G==null?void 0:G.scoring)==null?void 0:O.structures,q=_.stage&&(W==null?void 0:W.stage)&&(W==null?void 0:W.stage[_.stage]),F=_.stageSequence&&(q==null?void 0:q.stageSequence)&&q.stageSequence[_.stageSequence],L=((b=G==null?void 0:G.scoring)==null?void 0:b.requireAllPositionsAssigned)||(q==null?void 0:q.requireAllPositionsAssigned)||(F==null?void 0:F.requireAllPositionsAssigned);g||(g=lr({drawDefinition:f,structure:_}));const{positionAssignments:x,allPositionsAssigned:B}=Dt({structure:_}),z=!L||B,{seedAssignments:H}=$n({provisionalPositioning:r,drawDefinition:f,structure:_});a=a??H;const{roundOffset:Y,structureId:Z,structureName:K,stage:Q,stageSequence:J}=_,{drawId:te,drawName:ne,drawType:ee}=f??{};h=h||f&&uv({drawDefinition:f}).exitProfiles;const oe=h==null?void 0:h[Z],ie=(oe==null?void 0:oe.length)&&(oe[0].split("-").map(le=>parseInt(le)).reduce((le,be)=>le+be)||0),ae=!!_.structures;let se=xi({matchUpsMap:g,structureId:Z,inContext:I});const ye=G==null?void 0:G[Ef],Ie=NG({roundNamingPolicy:ye,structure:_,matchUps:se}),{roundNamingProfile:pe,roundProfile:fe}=Ie;if(E=(w=Ie==null?void 0:Ie.roundMatchUps)!=null?w:[],u&&(se=bs(Vu(ln({matchUps:se},u),{filterMatchUpTypes:!1,filterMatchUpIds:!1}))),I){const{sourceDrawPositionRanges:le}=TG({drawDefinition:f,matchUpsMap:g,structureId:Z}),be=f?EG({drawDefinition:f,roundProfile:fe,matchUpsMap:g,structureId:Z}).drawPositionsRanges:void 0;se=se.map(Pe=>ve({scheduleVisibilityFilters:t,sourceDrawPositionRanges:le,drawPositionsRanges:be,roundNamingProfile:pe,initialRoundOfPlay:ie,appliedPolicies:G,isRoundRobin:ae,roundProfile:fe,matchUp:Pe,event:P})),(se==null?void 0:se.filter(Pe=>Array.isArray(Pe.tieMatchUps))).forEach(Pe=>{const xe=Pe.tieMatchUps;se=se.concat(...xe)}),l&&(se=bs(Vu(ln({processContext:!0},l),{matchUps:se})))}else(se==null?void 0:se.filter(be=>Array.isArray(be.tieMatchUps))).forEach(be=>{const Me=be.tieMatchUps;se=se.concat(...Me)});return u&&(se=bs(Vu(ln({matchUps:se},u),{filterMatchUpTypes:!1,filterMatchUpIds:!1}))),(u!=null&&u.matchUpTypes||u!=null&&u.matchUpIds)&&(se=bs({matchUpTypes:u.matchUpTypes,matchUpIds:u.matchUpIds,matchUps:se})),(u!=null&&u.matchUpTypes||u!=null&&u.matchUpIds||I)&&(E=(T=Tr({matchUps:se}).roundMatchUps)!=null?T:[]),($=vr({drawDefinition:f,structure:_,event:P}))!=null&&$.tieFormat&&({collectionPositionMatchUps:N}=VV({matchUps:se})),{matchUps:se,roundMatchUps:E,roundProfile:fe,collectionPositionMatchUps:N};function ve({scheduleVisibilityFilters:le,sourceDrawPositionRanges:be,drawPositionsRanges:Me,initialRoundOfPlay:Pe,additionalContext:xe,roundNamingProfile:Be,tieDrawPositions:qe,appliedPolicies:$e,isCollectionBye:De,matchUpTieId:me,isRoundRobin:ge,roundProfile:Se,sideLineUps:Ee,matchUp:Ae,event:je}){var gt,rt,yt,St,ze,_t,Ve,It,nr,dr,vi,Lr,Qs,xp,Lp,Ot;xe=xe||{};const Er=(gt=vr({drawDefinition:f,structure:_,matchUp:Ae,event:je}))==null?void 0:gt.tieFormat,mi=Er==null?void 0:Er.collectionDefinitions,Cn=Ae.collectionId&&(mi==null?void 0:mi.find(pr=>pr.collectionId===Ae.collectionId)),Vp=Ae.collectionId?Cn==null?void 0:Cn.matchUpFormat:Ae.matchUpFormat||(_==null?void 0:_.matchUpFormat)||(f==null?void 0:f.matchUpFormat)||(je==null?void 0:je.matchUpFormat),hg=Ae.matchUpType||(Cn==null?void 0:Cn.matchUpType)||(_==null?void 0:_.matchUpType)||(f==null?void 0:f.matchUpType)||(je==null?void 0:je.eventType)!==Bt&&(je==null?void 0:je.eventType),Y0e=De?nt:Ae.matchUpStatus,{schedule:K0e,endDate:Q0e}=ev({scheduleVisibilityFilters:le,afterRecoveryTimes:o,tournamentRecord:s,scheduleTiming:d,matchUpFormat:Vp,matchUpType:hg,matchUp:Ae,event:je}),Wc=(rt=qe??Ae.drawPositions)!=null?rt:[],{collectionPosition:J0e,collectionId:VR,roundPosition:Bp}=Ae,to=Ae.roundNumber||xe.roundNumber,Z0e=VR?pG({tournamentParticipants:n,positionAssignments:x,collectionPosition:J0e,drawDefinition:f,participantMap:p,drawPositions:Wc,collectionId:VR,sideLineUps:Ee,matchUpType:hg}):void 0,BR=((yt=Be==null?void 0:Be[to])==null?void 0:yt.roundName)||xe.roundName,kR=((St=Be==null?void 0:Be[to])==null?void 0:St.abbreviatedRoundName)||xe.abbreviatedRoundName,X0e=(ze=Se==null?void 0:Se[to])==null?void 0:ze.feedRound,eSe=(_t=Se==null?void 0:Se[to])==null?void 0:_t.preFeedRound,tSe=(Ve=Se==null?void 0:Se[to])==null?void 0:Ve.roundFactor,GR=Me==null?void 0:Me[to],rSe=Bp?GR==null?void 0:GR[Bp]:void 0,WR=be==null?void 0:be[to],nSe=Cn!=null&&Cn.category?ln(ln({},(m==null?void 0:m.category)||{}),Cn.category):m==null?void 0:m.category,oSe=((It=Ae.processCodes)==null?void 0:It.length)&&Ae.processCodes||((nr=Cn==null?void 0:Cn.processCodes)==null?void 0:nr.length)&&(Cn==null?void 0:Cn.processCodes)||((dr=_==null?void 0:_.processCodes)==null?void 0:dr.length)&&(_==null?void 0:_.processCodes)||((vi=f==null?void 0:f.processCodes)==null?void 0:vi.length)&&(f==null?void 0:f.processCodes)||((Lr=je==null?void 0:je.processCodes)==null?void 0:Lr.length)&&(je==null?void 0:je.processCodes)||(s==null?void 0:s.processCodes),iSe=(v==null?void 0:v.withCompetitiveness)&&yI(Vu(ln({},c),{matchUp:Ae})).competitiveness,sSe=Ae.finishingPositionRange||xe.finishingPositionRange,kp=pr=>Oe(pr,void 0,!0),wt=ln(ln(ln({},kp(m)),kp({matchUpFormat:Ae.matchUpType===Bt?void 0:Vp,tieFormat:Ae.matchUpType!==Bt?void 0:Er,roundOfPlay:Q!==we&&ht(Pe)&&Pe+(to||0),endDate:Ae.endDate||Q0e,gender:Cn==null?void 0:Cn.gender,discipline:je==null?void 0:je.discipline,category:nSe,finishingPositionRange:sSe,abbreviatedRoundName:kR,drawPositionsRange:rSe,competitiveness:iSe,structureName:K,stageSequence:J,drawPositions:Wc,matchUpStatus:Y0e,processCodes:oSe,isRoundRobin:ge,matchUpTieId:me,preFeedRound:eSe,matchUpType:hg,roundFactor:tSe,roundOffset:Y,structureId:Z,roundNumber:to,feedRound:X0e,roundName:BR,drawName:ne,drawType:ee,schedule:K0e,drawId:te,stage:Q})),de(kp(Ae),!0,!0));if(Vp&&((Qs=Ae.score)!=null&&Qs.scoreStringSide1)){const pr=Pr(Vp),{bestOf:xo,finalSetFormat:Kr,setFormat:mt}=pr??{};(Kr!=null&&Kr.tiebreakSet||mt!=null&&mt.tiebreakSet||mt!=null&&mt.timed)&&(wt.score.sets=wt.score.sets.sort((fr,$r)=>fr.setNumber-$r.setNumber).map((fr,$r)=>($r+1===xo?(Kr!=null&&Kr.tiebreakSet||Kr!=null&&Kr.timed)&&(fr.tiebreakSet=!0):(mt!=null&&mt.tiebreakSet||mt!=null&&mt.timed)&&(fr.tiebreakSet=!0),fr)))}if(Array.isArray(Wc)){const{orderedDrawPositions:pr,displayOrder:xo}=wG({drawPositions:Wc,roundProfile:Se,roundNumber:to}),Kr=(xp=Se[to])==null?void 0:xp.feedRound,mt=xo[0]!==pr[0],$r=pr.concat(void 0,void 0).slice(0,2).map((Qr,Mn)=>{var Jr;const hi=Mn+1,gg=mt?3-hi:hi,Gp=UG({drawPositionCollectionAssignment:Z0e,positionAssignments:x,displaySideNumber:gg,seedAssignments:a,drawPosition:Qr,isFeedRound:Kr,sideNumber:hi}),lSe=(Jr=Ae.sides)==null?void 0:Jr.find(uSe=>uSe.sideNumber===hi),qR=Bp?(Bp-1)*2+Mn+1:void 0,cSe=qR?WR==null?void 0:WR[qR]:void 0;return kp(ln(ln({sourceDrawPositionRange:cSe},lSe),Gp))});Object.assign(wt,de({sides:$r},!0,!0))}if(n&&wt.sides){const pr=i==null?void 0:i[Tl],xo=mt=>{var fr;const $r=(fr=p==null?void 0:p[mt])==null?void 0:fr.participant;return $r&&iu({template:pr==null?void 0:pr.participant,source:$r})};if(wt.sides.filter(Boolean).forEach(mt=>{var fr,$r,Qr;if(mt.participantId){const Mn=de(xo(mt.participantId)||n&&Eo({policyDefinitions:$e,participantId:mt.participantId,tournamentParticipants:n,internalUse:!0,contextProfile:v}),void 0,!0);if(Mn){if(f!=null&&f.entries){const Jr=f.entries.find(hi=>hi.participantId===mt.participantId);Jr!=null&&Jr.entryStatus&&(Mn.entryStatus=Jr.entryStatus),Jr!=null&&Jr.entryStage&&(Mn.entryStage=Jr.entryStage)}Object.assign(mt,{participant:Mn})}}if(($r=(fr=mt==null?void 0:mt.participant)==null?void 0:fr.individualParticipantIds)!=null&&$r.length&&!((Qr=mt.participant.individualParticipants)!=null&&Qr.length)){const Mn=mt.participant.individualParticipantIds.map(Jr=>xo(Jr)||n&&Eo({policyDefinitions:$e,tournamentParticipants:n,internalUse:!0,contextProfile:v,participantId:Jr}));Object.assign(mt.participant,{individualParticipants:Mn})}}),!wt.matchUpType){const{matchUpType:mt}=YP({matchUp:wt});mt&&Object.assign(wt,{matchUpType:mt})}if((v==null?void 0:v.inferGender)&&(!wt.gender||wt.gender===Mo)&&((Lp=wt.sides)==null?void 0:Lp.length)===2&&wt.matchUpType!==Bt){const mt=wt.sides.map(fr=>{var $r,Qr,Mn,Jr;if(wt.matchUpType===At)return(Qr=($r=fr.participant)==null?void 0:$r.person)==null?void 0:Qr.sex;if(((Jr=(Mn=fr.participant)==null?void 0:Mn.individualParticipants)==null?void 0:Jr.length)===2){const hi=We(fr.participant.individualParticipants.map(gg=>{var Gp;return(Gp=gg.person)==null?void 0:Gp.sex})).filter(Boolean);if(hi.length===1)return hi[0]}});if(mt.filter(Boolean).length===2&&We(mt).length===1){const fr=mt[0];wt.inferredGender=fr}}}if(wt.tieMatchUps){const pr=wt.matchUpStatus===nt,xo=(Ot=wt.sides)==null?void 0:Ot.map(({participant:Kr,drawPosition:mt,sideNumber:fr,lineUp:$r})=>{const Qr=(Kr==null?void 0:Kr.participantType)===Bt&&Kr;return{teamParticipant:Qr&&Oe({participantRoleResponsibilities:Qr.participantRoleResponsibilities,participantOtherName:Qr.participanOthertName,participantName:Qr.participantName,participantId:Qr.participantId,teamId:Qr.teamId}),drawPosition:mt,sideNumber:fr,lineUp:$r}});wt.tieMatchUps=wt.tieMatchUps.map(Kr=>{const mt=wt.matchUpId,$r={finishingPositionRange:wt.finishingPositionRange,abbreviatedRoundName:kR,roundNumber:to,roundName:BR};return ve({tieDrawPositions:Wc,scheduleVisibilityFilters:le,sourceDrawPositionRanges:be,sideLineUps:xo,drawPositionsRanges:Me,initialRoundOfPlay:Pe,roundNamingProfile:Be,additionalContext:$r,appliedPolicies:$e,isCollectionBye:pr,matchUpTieId:mt,isRoundRobin:ge,roundProfile:Se,matchUp:Kr,event:je})})}const HR=wt.sides&&wt.sides.filter(pr=>pr==null?void 0:pr.participantId).length===2,aSe=!wt.winningSide;if(Object.assign(wt,{readyToScore:z&&HR&&aSe,hasContext:!0}),HR){const{allParticipantsCheckedIn:pr,checkedInParticipantIds:xo}=ec({matchUp:wt});Object.assign(wt,{allParticipantsCheckedIn:pr,checkedInParticipantIds:xo})}return Array.isArray(v==null?void 0:v.exclude)&&(v==null||v.exclude.forEach(pr=>delete wt[pr])),wt}}function xG(t){return Object.assign(t,{inContext:!0}),{matchUp:de(lt(t).matchUp,!1,!0)}}function lt({tournamentParticipants:t,afterRecoveryTimes:e,contextContent:r,contextProfile:n,drawDefinition:o,matchUpsMap:i,matchUpId:s,inContext:a,context:l,event:c}){if(!o)return{error:ue};if(!s)return{error:Vt};if(typeof s!="string")return{error:X};const{structures:u=[]}=an({drawDefinition:o});n&&!r&&(r=wo({contextProfile:n,drawDefinition:o}));for(const p of u){const{matchUps:d}=Je({tournamentParticipants:t,afterRecoveryTimes:e,contextContent:r,drawDefinition:o,contextProfile:n,matchUpsMap:i,inContext:a,structure:p,context:l,event:c}),{matchUp:v}=mI({matchUps:d,matchUpId:s});if(v)return{matchUp:v,structure:p}}return{error:ir}}var LG=Object.defineProperty,VG=Object.defineProperties,BG=Object.getOwnPropertyDescriptors,py=Object.getOwnPropertySymbols,kG=Object.prototype.hasOwnProperty,GG=Object.prototype.propertyIsEnumerable,fy=(t,e,r)=>e in t?LG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,WG=(t,e)=>{for(var r in e||(e={}))kG.call(e,r)&&fy(t,r,e[r]);if(py)for(var r of py(e))GG.call(e,r)&&fy(t,r,e[r]);return t},HG=(t,e)=>VG(t,BG(e));function vy({collectionGroups:t=[]}){const e=Object.assign({},...t.filter(n=>(n==null?void 0:n.groupValue)&&(n==null?void 0:n.groupNumber)).map(n=>({[n.groupNumber]:HG(WG({},n),{allGroupMatchUpsCompleted:!0,matchUpsCount:0,sideWins:[0,0],values:[0,0]})}))),r=Object.keys(e).map(n=>Te(n));return{groupValueGroups:e,groupValueNumbers:r}}function tc(t){var e,r,n,o;const{sideAdjustments:i=[0,0],separator:s="-",drawDefinition:a,matchUpsMap:l,structure:c,matchUp:u,event:p}=t;if(!Array.isArray(i)||i.length!==2||isNaN(i.reduce((b,w)=>b+w)))return{error:X};if(!u)return{error:jr};const d=((e=vr({matchUp:u,drawDefinition:a,structure:c,event:p}))==null?void 0:e.tieFormat)||(t==null?void 0:t.tieFormat);if(!d)return{error:Zc};const v=br({tieFormat:d});if(v.error)return v;const f=(d==null?void 0:d.collectionDefinitions)||[],m=(u==null?void 0:u.tieMatchUps)||[],h=[0,0],{groupValueGroups:g,groupValueNumbers:_}=vy(d);for(const b of f)UV({collectionDefinition:b,groupValueNumbers:_,groupValueGroups:g,sideTieValues:h,tieMatchUps:m});for(const b of _){const w=g[b],{allGroupMatchUpsCompleted:T,matchUpCount:$,winCriteria:N,groupValue:E,sideWins:A,values:U}=w;let C;if(N!=null&&N.aggregateValue)T&&U[0]!==U[1]&&(C=U[0]>U[1]?1:2);else if(N!=null&&N.valueGoal)C=U.reduce((M,D,R)=>D>=N.valueGoal?R+1:M,void 0);else{const M=Math.floor($/2)+1;C=A.reduce((D,R,j)=>R>=M?j+1:D,void 0)}C&&(h[C-1]+=E)}const I=h.map((b,w)=>b+i[w]),P={side1Score:I[0],side2Score:I[1],winningSide:void 0},y=I.join(s),S=I.slice().reverse().join(s);let O;if(d!=null&&d.winCriteria){const{valueGoal:b,aggregateValue:w,tallyDirectives:T}=d.winCriteria;if(b){const $=I.map((N,E)=>({sideNumber:E+1,points:N})).find(({points:N})=>N>=b);O=$==null?void 0:$.sideNumber}else w&&m.every(N=>N.matchUpStatus&&Yt.includes(N.matchUpStatus)||N.winningSide)&&I[0]!==I[1]&&(O=I[0]>I[1]?1:2);if(!O&&T){const $=u.matchUpId,N=u.hasContext?u:((r=l==null?void 0:l.drawMatchUps)==null?void 0:r[$])||a&&((n=lt({inContext:!0,drawDefinition:a,matchUpId:$}))==null?void 0:n.matchUp);if(N){const{completedTieMatchUps:E,order:A}=Nf({matchUps:[N]});if(E&&(A!=null&&A.length)){const U=A[0].participantId;O=(o=N.sides.find(({participantId:C})=>C===U))==null?void 0:o.sideNumber}}}}return O&&(P.winningSide=O),{scoreStringSide1:y,scoreStringSide2:S,winningSide:O,set:P}}function Nn(t){if(t)return de(t,!1,!0)}function Gt(t){var e,r;const n=t==null?void 0:t.matchUp,o=(t==null?void 0:t.score)||(n==null?void 0:n.score),i=(e=o==null?void 0:o.sets)==null?void 0:e[0],{side1Score:s,side2Score:a,side1TiebreakScore:l,side2TiebreakScore:c,side1PointScore:u,side2PointScore:p}=i||{},d=s||a||l||c||u||p;return!!(((r=o==null?void 0:o.sets)==null?void 0:r.length)>1||d)}function rc({matchUpStatus:t}){return cV.includes(t)}function qG({matchUpStatus:t}){return H_.includes(t)}function pv({matchUpStatus:t}){return uV.includes(t)}function fv({matchUpStatus:t,winningSide:e,tieMatchUps:r,sides:n,score:o}){var i;const s=n==null?void 0:n.find(({participantId:c})=>c),a=(i=r==null?void 0:r.filter(fv))==null?void 0:i.length;return Gt({score:o})||a||e&&s||t&&qG({matchUpStatus:t})&&![Xe,ot,Vn].includes(t)}var zG=Object.defineProperty,my=Object.getOwnPropertySymbols,YG=Object.prototype.hasOwnProperty,KG=Object.prototype.propertyIsEnumerable,hy=(t,e,r)=>e in t?zG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gy=(t,e)=>{for(var r in e||(e={}))YG.call(e,r)&&hy(t,r,e[r]);if(my)for(var r of my(e))KG.call(e,r)&&hy(t,r,e[r]);return t};function vv(t){var e;return typeof t!="object"?{error:_e}:typeof t.element!="object"?{error:X}:t.notes?typeof t.notes!="string"&&!((e=t.notes)!=null&&e.testing)?{error:X}:(Object.assign(t.element,{notes:t.notes}),gy({},V)):{error:_e}}function QG(t){return typeof t!="object"?{error:_e}:typeof t.element!="object"?{error:X}:(t.element.notes&&delete t.element.notes,gy({},V))}var JG=Object.defineProperty,_y=Object.getOwnPropertySymbols,ZG=Object.prototype.hasOwnProperty,XG=Object.prototype.propertyIsEnumerable,Iy=(t,e,r)=>e in t?JG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Do=(t,e)=>{for(var r in e||(e={}))ZG.call(e,r)&&Iy(t,r,e[r]);if(_y)for(var r of _y(e))XG.call(e,r)&&Iy(t,r,e[r]);return t};function Bu(t,e){var r;if(!t)return{error:ue};let n=Date.now();t.updatedAt&&n===new Date(t.updatedAt).getTime()&&(n+=1);const o=new Date(n).toISOString(),i=e==null?void 0:e.filter(Boolean);return t.updatedAt=o,(r=t.structures)==null||r.filter(Boolean).forEach(s=>{(!(i!=null&&i.length)||i!=null&&i.includes(s.structureId))&&(s.updatedAt=o)}),Do({},V)}function Li({drawDefinition:t,tournamentId:e,matchUps:r,eventId:n}){return t&&Bu(t),He({payload:{matchUps:r,tournamentId:e,eventId:n},topic:qf}),Do({},V)}function Vi({drawDefinition:t,tournamentId:e,matchUpIds:r,eventId:n,action:o}){t&&Bu(t),He({topic:aP,payload:{tournamentId:e,matchUpIds:r,eventId:n,action:o}});for(const i of r)N_({key:i});return Do({},V)}function Ze({drawDefinition:t,tournamentId:e,structureId:r,context:n,eventId:o,matchUp:i}){return i?(t&&et({drawDefinition:t,structureIds:r?[r]:void 0,tournamentId:e,eventId:o}),He({topic:cP,payload:{matchUp:i,tournamentId:e,context:n},key:i.matchUpId}),Do({},V)):(console.log(jr),{error:jr})}function e3({tournamentId:t,inContextMatchUp:e}){return e?(He({topic:zf,payload:{inContextMatchUp:e,tournamentId:t},key:e.matchUpId}),Do({},V)):{error:jr}}function nc({tournamentId:t,eventId:e,drawDefinition:r}){return r?(Bu(r),He({payload:{drawDefinition:r,tournamentId:t,eventId:e},topic:tP,key:r.drawId}),Do({},V)):(console.log(ue),{error:ue})}function t3({tournamentId:t,eventId:e,drawId:r}){return He({payload:{drawId:r,tournamentId:t,eventId:e},topic:sP,key:r}),N_({key:r}),Do({},V)}function et({drawDefinition:t,tournamentId:e,structureIds:r,eventId:n}){return t?(Bu(t,r),He({payload:{tournamentId:e,eventId:n,drawDefinition:t},topic:lP,key:t.drawId}),Do({},V)):{error:ue}}function Py({drawDefinition:t,tournamentId:e,structure:r,eventId:n}){if(!t)return{error:ue};if(!r)return{error:ra};const o=r.seedAssignments,i=r.structureId,s=t.drawId;return He({payload:{tournamentId:e,eventId:n,drawId:s,structureId:i,seedAssignments:o},topic:dP,key:t.drawId}),et({structureIds:[i],drawDefinition:t,tournamentId:e,eventId:n}),Do({},V)}function oi({drawDefinition:t,tournamentId:e,structure:r,event:n}){if(!t)return{error:ue};if(!r)return{error:ra};const o=st({structure:r}),i=r.structureId,s=t.drawId,a=n==null?void 0:n.eventId;return He({topic:uP,payload:{positionAssignments:o,tournamentId:e,structureId:i,eventId:a,drawId:s},key:i}),et({structureIds:[i],drawDefinition:t,tournamentId:e,eventId:a}),Do({},V)}const ku=t=>t==null?void 0:t.participantId;function r3({positionAssignments:t}){const e=(t||[]).filter(ku).map(i=>{const{extension:s}=Kt({element:i,name:ma}),a=Te(s==null?void 0:s.value),l=!isNaN(a)&&a;return l&&{participantId:i.participantId,subOrder:l}}).filter(Boolean),r=e.map(({subOrder:i})=>i),n=Nr(r);return{subOrderMap:Object.assign({},...e.filter(({subOrder:i})=>n[i]===1).map(({participantId:i,subOrder:s})=>({[i]:s})))}}var n3=Object.defineProperty,o3=Object.defineProperties,i3=Object.getOwnPropertyDescriptors,yy=Object.getOwnPropertySymbols,s3=Object.prototype.hasOwnProperty,a3=Object.prototype.propertyIsEnumerable,Sy=(t,e,r)=>e in t?n3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l3=(t,e)=>{for(var r in e||(e={}))s3.call(e,r)&&Sy(t,r,e[r]);if(yy)for(var r of yy(e))a3.call(e,r)&&Sy(t,r,e[r]);return t},c3=(t,e)=>o3(t,i3(e));function Oy({positionAssignments:t,tournamentRecord:e,drawDefinition:r,matchUpFormat:n,matchUps:o,event:i}){if(!Array.isArray(o))return{error:X};if(!t)return{error:X};const{policyDefinitions:s}=ls({policyTypes:[sI],tournamentRecord:e,drawDefinition:r,event:i}),{subOrderMap:a}=r3({positionAssignments:t}),l=Nf({policyDefinitions:s,matchUpFormat:n,subOrderMap:a,matchUps:o});if(l.error)return l;const{participantResults:c,bracketComplete:u,report:p}=l,d=Object.keys(c);return t.forEach(v=>{const{participantId:f}=v;if(d.includes(f)){const m={value:c[f],name:Ko};it({element:v,extension:m}),c[f].ties||yn({element:v,name:ma})}else yn({element:v,name:Ko}),yn({element:v,name:ma})}),et({drawDefinition:r}),c3(l3({},V),{participantResults:c,bracketComplete:u,report:p})}function mv({participantsProfile:t,participants:e=[]}){const r=de(e,t==null?void 0:t.convertExtensions,!0),n=r.filter(s=>s.participantType===tt),o=r.filter(s=>s.participantType===Mr),i=r.filter(s=>s.participantType===Ce);return r.forEach(s=>{if(s.participantType===Fe){const{participantId:a}=s;s.groupParticipantIds=[],s.teamParticipantIds=[],s.pairParticipantIds=[],s.groups=[],s.teams=[],n.forEach(l=>{((l==null?void 0:l.individualParticipantIds)||[]).forEach(c=>{var u;c===a&&!((u=s.teamParticipantIds)!=null&&u.includes(l.participantId))&&(s.teamParticipantIds.push(l.participantId),s.teams.push({participantRoleResponsibilities:l.participantRoleResponsibilities,participantOtherName:l.participantOtherName,participantName:l.participantName,participantId:l.participantId,teamId:l.teamId}))})}),i.forEach(l=>{((l==null?void 0:l.individualParticipantIds)||[]).forEach(c=>{c===a&&!s.pairParticipantIds.includes(l.participantId)&&s.pairParticipantIds.push(l.participantId)})}),o.forEach(l=>{((l==null?void 0:l.individualParticipantIds)||[]).forEach(c=>{c===a&&!s.groupParticipantIds.includes(l.participantId)&&(s.groupParticipantIds.push(l.participantId),s.groups.push({participantRoleResponsibilities:l.participantRoleResponsibilities,participantOtherName:l.participantOtherName,participantName:l.participantName,participantId:l.participantId}))})})}}),r}const hv=t=>e=>t[e],gv=(t=[])=>t.map(Jt).filter(Boolean),oc=(t=[])=>t.map(ct).filter(Boolean),ct=(t={})=>hv(t)("participantId"),u3=(t={})=>hv(t)("drawPosition"),Jt=(t={})=>hv(t)("matchUpId");function d3({structureMatchUps:t,matchUp:e}){const{roundNumber:r,roundPosition:n}=e,o=t.filter(s=>s.roundNumber===r&&!s.matchUpTieId),i=t.filter(s=>s.roundNumber===r+1&&!s.matchUpTieId);if(i.length){let s;return i.length===o.length?s=i.find(a=>a.roundPosition===n):i.length===o.length/2&&(s=i.find(a=>a.roundPosition===Math.ceil(n/2))),{matchUp:s}}return{message:"no progression found"}}function _v({sourceRoundMatchUpCount:t,inContextDrawMatchUps:e,sourceRoundPosition:r,drawDefinition:n,targetLink:o}){var i;if(!o)return{error:Yg};const{target:{structureId:s,feedProfile:a,groupedOrder:l,roundNumber:c,positionInterleave:u}}=o,{structure:p}=Ne({drawDefinition:n,structureId:s}),{positionAssignments:d}=st({structure:p}),f=(e==null?void 0:e.filter($=>$.structureId===(p==null?void 0:p.structureId))).filter($=>$.roundNumber===c&&!$.matchUpTieId),m=f.length,h=ce(1,m+1),g=m/t;let _=Math.ceil(g*r),I=1-r%2;if(u!=null&&u.interleave&&g!==.5){const $=u.offset+(r-1)*u.interleave,N=r+$;_=Math.ceil(N/2),I=1-N%2}let P=h,y=h[_-1];const S=sy({groupedOrder:l,roundPositionsCount:h.length}),O=(S==null?void 0:S.length)||1;if(O<=h.length){const $=m/O,N=qt(h,$);a===Is&&N.forEach(E=>E.reverse()),P=(S==null?void 0:S.length)&&(S==null?void 0:S.map(E=>N[E-1]).flat())||P}a===Ai?y=P[_-1]:a===Is?((!(S!=null&&S.length)||O>h.length)&&(_=f.length+1-_),y=P[_-1]):a===ZP&&zt()&&console.log(P_,{feedProfile:a});const b=y&&f.reduce(($,N)=>N.roundPosition===y?N:$,void 0);let w;b!=null&&b.feedRound?(I=0,w=Math.min(...(b.drawPositions||[]).filter(Boolean))):w=((i=b==null?void 0:b.drawPositions)==null?void 0:i.length)===2&&(b==null?void 0:b.drawPositions[I]);const T=d==null?void 0:d.find(({drawPosition:$})=>$===w);if(T){const{extension:$}=Kt({element:T,name:hu});if($!=null&&$.value)return{disabledDrawPosition:w}}return{matchUp:b,targetDrawPosition:w,matchUpDrawPositionIndex:I}}function p3({drawDefinition:t,roundNumber:e,structureId:r}){if(!t)return{error:ue};if(!r)return{error:yr};const{links:n}=ic({drawDefinition:t,structureId:r}),o=n.source.reduce((s,a)=>!a.source.roundNumber||a.source.roundNumber===e?s.concat(a):s,[]),i=n.target.reduce((s,a)=>!a.target.roundNumber||a.target.roundNumber===e?s.concat(a):s,[]);return{links:{source:o,target:i}}}function Iv({finishingPositions:t,linkCondition:e,linkType:r,source:n}){var o;const i=n.find(s=>{var a,l;const c=!((a=s.source)!=null&&a.finishingPositions)||!t||Xt(t,(l=s.source)==null?void 0:l.finishingPositions);return e===s.linkCondition&&c&&s.linkType===r});return[Mi,Ps].includes(i==null?void 0:i.linkType)&&!((o=i==null?void 0:i.source)!=null&&o.roundNumber)?k({result:{error:X},stack:"getTargetLink",context:i}):i}function ic({drawDefinition:t,structureId:e,roundNumber:r}){return t?e?{links:(t.links||[]).filter(Boolean).reduce((i,s)=>{var a,l;return((a=s.source)==null?void 0:a.structureId)===e&&(!r||s.source.roundNumber===r)&&(i.source=i.source.concat(s)),((l=s.target)==null?void 0:l.structureId)===e&&(!r||s.target.roundNumber===r)&&(i.target=i.target.concat(s)),i},{source:[],target:[]})}:{error:yr}:{error:ue}}function Ir({inContextDrawMatchUps:t=[],useTargetMatchUpIds:e,inContextMatchUp:r,drawDefinition:n,matchUpId:o}){let i=r;t.length&&!i&&(i=t.find(l=>l.matchUpId===o));const{structure:s}=Ne({structureId:i==null?void 0:i.structureId,drawDefinition:n});return(s==null?void 0:s.finishingPosition)===ji?f3({inContextDrawMatchUps:t,useTargetMatchUpIds:e,drawDefinition:n,structure:s,matchUp:i}):v3({matchUp:i})}function f3({inContextDrawMatchUps:t,useTargetMatchUpIds:e,drawDefinition:r,structure:n,matchUp:o}){var i,s,a;const{winnerMatchUpId:l,loserMatchUpId:c}=o,{links:u}=p3({roundNumber:o.roundNumber,structureId:n.structureId,drawDefinition:r}),p=u==null?void 0:u.source,d=Iv({source:p,linkType:Mi}),v=Iv({linkCondition:co,linkType:Ps,source:p});let f=Iv({source:p,linkType:Ps});const m=v&&f;f||(f=v);const h=(i=d==null?void 0:d.target)==null?void 0:i.feedProfile,g=(s=f==null?void 0:f.target)==null?void 0:s.feedProfile,_=(a=v==null?void 0:v.target)==null?void 0:a.feedProfile;let I,P,y,S,O,b,w,T,$,N;if(e&&(l||c)&&(w=l&&h!==Sn&&t.find(({matchUpId:U})=>U===l),S=c&&g!==Sn&&t.find(({matchUpId:U})=>U===c),w||S))return{matchUp:o,targetLinks:{loserTargetLink:f,winnerTargetLink:d},targetMatchUps:{loserMatchUp:S,winnerMatchUp:w}};const{roundPosition:E}=o;N=N||t.filter(U=>U.structureId===n.structureId);const A=N.reduce((U,C)=>C.roundNumber===o.roundNumber&&!C.matchUpTieId?U+1:U,0);return f&&!S&&g!==Sn&&({matchUpDrawPositionIndex:b,targetDrawPosition:O,matchUp:S}=_v({targetLink:f,sourceRoundMatchUpCount:A,inContextDrawMatchUps:t,sourceRoundPosition:E,drawDefinition:r})),m&&_!==Sn&&({matchUpDrawPositionIndex:y,targetDrawPosition:P,matchUp:I}=_v({targetLink:v,sourceRoundMatchUpCount:A,inContextDrawMatchUps:t,sourceRoundPosition:E,drawDefinition:r})),d&&!w&&h!==Sn&&({matchUpDrawPositionIndex:$,targetDrawPosition:T,matchUp:w}=_v({targetLink:d,sourceRoundMatchUpCount:A,inContextDrawMatchUps:t,sourceRoundPosition:E,drawDefinition:r})),w||(N=N||t.filter(U=>U.structureId===n.structureId),{matchUp:w}=d3({structureMatchUps:N,matchUp:o})),Oe({matchUp:o,targetLinks:{loserTargetLink:f,winnerTargetLink:d,byeTargetLink:v},targetMatchUps:{byeMatchUp:I,loserMatchUp:S,winnerMatchUp:w,byeTargetDrawPosition:P,loserTargetDrawPosition:O,winnerTargetDrawPosition:T,byeMatchUpDrawPositionIndex:y,loserMatchUpDrawPositionIndex:b,winnerMatchUpDrawPositionIndex:$},targetMatchUpIds:!!(l||c)})}function v3({matchUp:t}){return{matchUp:t,targetLinks:{loserTargetLink:void 0,winnerTargetLink:void 0},targetMatchUps:{loserMatchUp:void 0,winnerMatchUp:void 0}}}function m3({drawDefinition:t,inContextDrawMatchUps:e}){const r={};return e.forEach(n=>{var o,i,s,a,l;const{matchUpId:c,structureId:u,drawPositions:p=[]}=n,{structure:d}=Ne({drawDefinition:t,structureId:u});if((d==null?void 0:d.finishingPosition)===ya){const{roundNumber:v}=n,f=v&&Te(v)+1,m=d.matchUps||[],{roundMatchUps:h}=Tr({matchUps:m});if(f&&(h!=null&&h[f])){const g=p.sort().map((_,I)=>{const P=h[f].find(y=>{var S;return(S=y.drawPositions)==null?void 0:S.includes(_)});return{matchUpId:P==null?void 0:P.matchUpId,roundNumber:f,schedule:P==null?void 0:P.schedule,sideNumber:I+1,structureName:d.structureName}});Object.assign(n,{sidesTo:g})}}else{const v=Ir({useTargetMatchUpIds:!0,inContextDrawMatchUps:e,inContextMatchUp:n,drawDefinition:t,matchUpId:c});let{winnerMatchUp:f}=v.targetMatchUps;const{loserMatchUp:m}=v.targetMatchUps;!n.winnerMatchUpId&&f&&(n.winnerMatchUpId=f.matchUpId),!n.loserMatchUpId&&m&&(n.loserMatchUpId=m.matchUpId);const h=Pv({upcomingMatchUp:f});let g=Pv({upcomingMatchUp:m});if(n.matchUpStatus!==nt&&(m==null?void 0:m.matchUpStatus)===nt){const{matchUp:I}=by({matchUp:m,drawDefinition:t,inContextDrawMatchUps:e})||{};g=I&&Pv({upcomingMatchUp:I})||g}const _=(o=n.schedule)==null?void 0:o.timeAfterRecovery;if(_&&((i=h==null?void 0:h.schedule)!=null&&i.scheduledTime&&Le(h.schedule.scheduledTime)<Le(_)&&(r[h.matchUpId]=n.matchUpId,h.schedule.scheduleConflict=n.matchUpId),(s=g==null?void 0:g.schedule)!=null&&s.scheduledTime&&Le(g.schedule.scheduledTime)<Le(_)&&(r[g.matchUpId]=n.matchUpId,g.schedule.scheduleConflict=n.matchUpId)),Object.assign(n,{winnerTo:h,loserTo:g}),(a=n.drawPositions)!=null&&a.filter(Boolean).length){const I=(l=v.targetLinks)==null?void 0:l.loserTargetLink,P=(I==null?void 0:I.linkCondition)===co,y=h3(n);if(y.length){const S=oc(f==null?void 0:f.sides),O=oc(m==null?void 0:m.sides),w=y.find(({participantId:N})=>S.includes(N))?[]:y,$=y.find(({participantId:N})=>O.includes(N))?[]:y;m&&P&&$.length<2&&$.push({bye:!0,tbd:!0}),w!=null&&w.length&&f&&(!v.targetMatchUpIds&&f&&(f=e.find(({matchUpId:N})=>N===f.matchUpId)),f.potentialParticipants||(f.potentialParticipants=[]),f.potentialParticipants.push(w)),$!=null&&$.length&&m&&(v.targetMatchUpIds||(f=e.find(({matchUpId:N})=>N===m.matchUpId)),m.potentialParticipants||(m.potentialParticipants=[]),m.potentialParticipants.push($))}}}}),Object.keys(r).length&&e.forEach(n=>{Object.keys(r).includes(n.matchUpId)&&(n.schedule.scheduleConflict=r[n.matchUpId])}),{scheduleConflictMatchUpIds:r}}function h3(t){var e;return((e=t==null?void 0:t.sides)==null?void 0:e.map(({participant:r,participantId:n,qualifier:o})=>r||n&&{participantId:n}||o&&{qualifier:o}).filter(Boolean))||[]}function by({matchUp:t,drawDefinition:e,inContextDrawMatchUps:r}){const{matchUpId:n,matchUpStatus:o,structureId:i}=t||{};if(!t||!i||(t==null?void 0:t.matchUpStatus)===Ft)return{matchUp:t};if(o===nt){let s;if(t.winnerMatchUpId)s=r.find(({matchUpId:a})=>a===t.winnerMatchUpId);else{const a=Ir({inContextDrawMatchUps:r,drawDefinition:e,matchUpId:n});({winnerMatchUp:s}=(a==null?void 0:a.targetMatchUps)||{})}return by({matchUp:s,drawDefinition:e,inContextDrawMatchUps:r})}return{matchUp:void 0}}function Pv(t){if(t!=null&&t.upcomingMatchUp)return(({matchUpId:e,structureId:r,schedule:n,roundNumber:o,roundPosition:i,structureName:s})=>({matchUpId:e,structureId:r,schedule:n,roundNumber:o,roundPosition:i,structureName:s}))(t.upcomingMatchUp)}function sc({requireParticipants:t=!0,scheduleVisibilityFilters:e,tournamentAppliedPolicies:r,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,matchUpFilters:a,contextFilters:l,contextContent:c,participantMap:u,scheduleTiming:p,contextProfile:d,drawDefinition:v,exitProfiles:f,matchUpsMap:m,structureId:h,inContext:g,structure:_,context:I,event:P}){!_&&h&&({structure:_}=Ne({drawDefinition:v,structureId:h}));const y=Je({tournamentAppliedPolicies:r,scheduleVisibilityFilters:e,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,drawDefinition:v,matchUpFilters:a,contextFilters:l,contextProfile:d,contextContent:c,participantMap:u,scheduleTiming:p,exitProfiles:f,matchUpsMap:m,structure:_,inContext:g,context:I,event:P}),S=[],O=[],b=[],w=[],T=[];if(y.error)return y;const{matchUps:$}=y,{assignedPositions:N}=Dt({structure:_}),E=N==null?void 0:N.filter(U=>U.participantId).map(U=>U.drawPosition);let A;return $.filter(U=>{var C;const M=((C=a==null?void 0:a.matchUpTypes)==null?void 0:C.length)===1&&a.matchUpTypes[0]===Qe;return!(U.matchUpType!==Qe&&M)}).forEach(U=>{var C,M,D,R;if(U.matchUpStatus===Wr){S.push(U);return}U.matchUpType===Qe&&(A=!0);const j=U.collectionId,G=j&&((C=U.sides)==null?void 0:C.every(z=>z.participantId)),W=!j&&((M=U.drawPositions)==null?void 0:M.filter(Boolean).length)===2,q=!j&&((D=U.drawPositions)==null?void 0:D.every(z=>E==null?void 0:E.includes(z))),F=N==null?void 0:N.filter(z=>z.bye).map(z=>z.drawPosition),L=!j&&((R=U.drawPositions)==null?void 0:R.find(z=>F==null?void 0:F.includes(z))),B=dV.includes(U.matchUpStatus)&&(G||W&&(!t||q));return L?T.push(U):ca({matchUp:U})?O.push(U):B?b.push(U):w.push(U)}),{includesTeamMatchUps:A,abandonedMatchUps:S,completedMatchUps:O,upcomingMatchUps:b,pendingMatchUps:w,byeMatchUps:T,structure:_}}var g3=Object.defineProperty,_3=Object.defineProperties,I3=Object.getOwnPropertyDescriptors,Ty=Object.getOwnPropertySymbols,P3=Object.prototype.hasOwnProperty,y3=Object.prototype.propertyIsEnumerable,wy=(t,e,r)=>e in t?g3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yv=(t,e)=>{for(var r in e||(e={}))P3.call(e,r)&&wy(t,r,e[r]);if(Ty)for(var r of Ty(e))y3.call(e,r)&&wy(t,r,e[r]);return t},S3=(t,e)=>_3(t,I3(e));function Lt(t){const e="getAllDrawMatchUps";Object.assign(t,{requireParticipants:!1});const r=ws(t);if(r.error)return k({result:r,stack:e});const{abandonedMatchUps:n,completedMatchUps:o,upcomingMatchUps:i,pendingMatchUps:s,byeMatchUps:a,matchUpsMap:l}=r;return{matchUps:(n??[]).concat(...o??[],...i??[],...s??[],...a??[]),matchUpsMap:l}}function ws(t){if(!(t!=null&&t.drawDefinition))return{error:ue};let{tournamentParticipants:e,contextContent:r,matchUpsMap:n}=t;const{scheduleVisibilityFilters:o,tournamentAppliedPolicies:i,requireParticipants:s,participantsProfile:a,afterRecoveryTimes:l,policyDefinitions:c,tournamentRecord:u,contextFilters:p,contextProfile:d,drawDefinition:v,matchUpFilters:f,scheduleTiming:m,participantMap:h,nextMatchUps:g,inContext:_,context:I,event:P}=t;let y=[],S=[],O=[],b=[],w=[];d&&!r&&(r=wo({policyDefinitions:c,tournamentRecord:u,contextProfile:d,event:P})),!(e!=null&&e.length)&&u&&(e=u==null?void 0:u.participants,(_||a!=null&&a.withGroupings)&&(e!=null&&e.length)&&(e=mv({participants:e,participantsProfile:a})));const{structures:T}=an({drawDefinition:v});if(!T)return{error:bt};n||(n=lr({drawDefinition:v}));const $=v&&uv({drawDefinition:v}).exitProfiles;T.forEach(A=>{const{byeMatchUps:U=[],pendingMatchUps:C=[],upcomingMatchUps:M=[],completedMatchUps:D=[],abandonedMatchUps:R=[]}=sc({matchUpFilters:g?void 0:f,contextFilters:g?void 0:p,inContext:_||g||p,tournamentAppliedPolicies:i,scheduleVisibilityFilters:o,tournamentParticipants:e,requireParticipants:s,afterRecoveryTimes:l,policyDefinitions:c,tournamentRecord:u,participantMap:h,scheduleTiming:m,contextContent:r,contextProfile:d,drawDefinition:v,exitProfiles:$,matchUpsMap:n,structure:A,context:I,event:P});y=y.concat(...R),S=S.concat(...D),O=O.concat(...M),b=b.concat(...C),w=w.concat(...U)});const N=A=>(!f&&!g&&!p||(f&&(A=bs(yv({matchUps:A},f))),p&&(A=bs(S3(yv({matchUps:A},p),{processContext:!0})))),A),E=yv({abandonedMatchUps:N(y),completedMatchUps:N(S),upcomingMatchUps:N(O),pendingMatchUps:N(b),byeMatchUps:N(w),matchUpsMap:n},V);if(g){const A=typeof g=="object"||{abandoned:!0,completed:!0,upcoming:!0,pending:!0,bye:!0},{abandoned:U,completed:C,upcoming:M,pending:D,bye:R}=A,j=[].concat(...U&&y||[],...C&&S||[],...M&&O||[],...D&&b||[],...R&&w||[]);m3({inContextDrawMatchUps:j,drawDefinition:v})}return E}const Gu={matchUpStatus:Ft,matchUpStatusCodes:[],score:{scoreStringSide1:"",scoreStringSide2:"",sets:void 0},matchUpFormat:void 0,winningSide:void 0};var O3=Object.defineProperty,Ey=Object.getOwnPropertySymbols,b3=Object.prototype.hasOwnProperty,T3=Object.prototype.propertyIsEnumerable,$y=(t,e,r)=>e in t?O3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ny=(t,e)=>{for(var r in e||(e={}))b3.call(e,r)&&$y(t,r,e[r]);if(Ey)for(var r of Ey(e))T3.call(e,r)&&$y(t,r,e[r]);return t};function Kn({matchUpStatusCodes:t,removeWinningSide:e,tournamentRecord:r,drawDefinition:n,matchUpFormat:o,matchUpStatus:i,removeScore:s,winningSide:a,matchUpId:l,matchUp:c,event:u,notes:p,score:d}){var v,f,m,h,g,_,I,P;const y="modifyMatchUpScore";let S;const O=c.matchUpType===Qe;if(O&&n){if(l&&c.matchUpId!==l){const A=lt({drawDefinition:n,matchUpId:l,event:u});if(!A.matchUp)return{error:ir};({matchUp:c,structure:S}=A)}}else c.matchUpId!==l&&console.log("!!!!!");i&&[ot,Rt].includes(i)||s?Object.assign(c,Ny({},Gu)):d&&(c.score=d);const b=i&&(c==null?void 0:c.matchUpStatus)===Xe&&i!==Xe;i&&(c.matchUpStatus=i),o&&(c.matchUpFormat=o),t&&(c.matchUpStatusCodes=t),a&&(c.winningSide=a),e&&(c.winningSide=void 0),!S&&n&&({structure:S}=lt({drawDefinition:n,matchUpId:l,event:u})),i&&!c.winningSide&&Gt(c)&&!Yt.includes(i)&&![la,Oi].includes(i)&&(c.matchUpStatus=ut.InProgress);let w;if(b&&((v=c==null?void 0:c.processCodes)!=null&&v.length)||i===Xe){const A=(f=pt({tournamentRecord:r,drawDefinition:n,structure:S,event:u}))==null?void 0:f.appliedPolicies;w=(h=(m=A==null?void 0:A[da])==null?void 0:m.processCodes)==null?void 0:h.incompleteAssignmentsOnDefault}if((S==null?void 0:S.structureType)===gr&&!c.collectionId){o=O?"SET1-S:T100":o||c.matchUpFormat||(S==null?void 0:S.matchUpFormat)||(n==null?void 0:n.matchUpFormat)||(u==null?void 0:u.matchUpFormat);const A=S.structures.find(D=>D==null?void 0:D.matchUps.find(R=>R.matchUpId===l)),U=O?{matchUpTypes:[Qe]}:void 0,{matchUps:C}=Je({afterRecoveryTimes:!1,structure:A,inContext:!0,matchUpFilters:U,event:u}),M=Oy({positionAssignments:A.positionAssignments,tournamentRecord:r,drawDefinition:n,matchUpFormat:o,matchUps:C,event:u});if(M.error)return k({result:M,stack:y})}if(p){const A=vv({element:c,notes:p});if(A.error)return k({result:A,stack:y})}const T=r==null?void 0:r.tournamentId,$=Rn().topics.includes(zf),N=($||w)&&lr({drawDefinition:n}),E=N&&((g=Lt({matchUpFilters:{matchUpIds:[l]},nextMatchUps:!0,tournamentRecord:r,inContext:!0,drawDefinition:n,matchUpsMap:N}).matchUps)==null?void 0:g[0]);if($&&E&&e3({tournamentId:T,inContextMatchUp:E}),Array.isArray(w)&&E&&!((_=E.sides)!=null&&_.every(({participantId:A})=>A)))if(i===Xe)c.processCodes?c.processCodes.push(...w):c.processCodes=w;else for(const A of w||[]){const U=A&&((I=c==null?void 0:c.processCodes)==null?void 0:I.lastIndexOf(A));(P=c==null?void 0:c.processCodes)==null||P.splice(U,1)}return Ze({eventId:u==null?void 0:u.eventId,context:y,drawDefinition:n,tournamentId:T,matchUp:c}),Ny({},V)}var w3=Object.defineProperty,E3=Object.defineProperties,$3=Object.getOwnPropertyDescriptors,Uy=Object.getOwnPropertySymbols,N3=Object.prototype.hasOwnProperty,U3=Object.prototype.propertyIsEnumerable,Ay=(t,e,r)=>e in t?w3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Sv=(t,e)=>{for(var r in e||(e={}))N3.call(e,r)&&Ay(t,r,e[r]);if(Uy)for(var r of Uy(e))U3.call(e,r)&&Ay(t,r,e[r]);return t},Cy=(t,e)=>E3(t,$3(e));function uo({tournamentRecord:t,exitWhenNoValues:e,drawDefinition:r,matchUpStatus:n,removeScore:o,matchUpsMap:i,matchUpId:s,event:a}){var l,c;const u=lt({drawDefinition:r,event:a,matchUpId:s});if(u.error)return u;if(!u.matchUp)return{error:ir};const{matchUp:p,structure:d}=u;if(!p.tieMatchUps)return{error:tn};const{extension:v}=xr({name:fa,element:p});if(v!=null&&v.value)if(o)yn({element:p,name:fa});else return Cy(Sv({},V),{score:p.score});const f=(l=vr({drawDefinition:r,structure:d,matchUp:p,event:a}))==null?void 0:l.tieFormat;p.tieFormat=Nn(f);const m=tc({drawDefinition:r,matchUpsMap:i,structure:d,matchUp:p,event:a}),{winningSide:h,set:g,scoreStringSide1:_,scoreStringSide2:I}=m,P=(g==null?void 0:g.side1Score)||(g==null?void 0:g.side2Score);if(e&&!p.score&&!P)return Sv({},V);const y={scoreStringSide1:_,scoreStringSide2:I,sets:g?[g]:[]},S=h&&[1,2].includes(h),O=S&&Mt||fv({matchUpStatus:n??p.matchUpStatus,tieMatchUps:p.tieMatchUps,winningSide:p.winningSide,score:y})&&Vn||Ft,b=!!(p.winningSide&&!S),w=p.tieMatchUps.find(({score:$,winningSide:N,matchUpStatus:E})=>{var A;return((A=$==null?void 0:$.sets)==null?void 0:A.length)&&($.sets[0].side1Score||$.sets[0].side2Score)||E&&Yt.includes(E)||N});let T;if(p.tieFormat&&!S&&!w){const $=(c=vr({drawDefinition:r,structure:d,event:a}))==null?void 0:c.tieFormat;$&&JSON.stringify(f)===JSON.stringify($)&&(p.tieFormatId=void 0,p.tieFormat=void 0,T=!0)}return Kn({matchUpStatus:O,score:y,removeWinningSide:b,tournamentRecord:t,drawDefinition:r,removeScore:o,winningSide:h,matchUpId:s,matchUp:p,event:a}),Cy(Sv({},V),{score:y,removeWinningSide:b,tieFormatRemoved:T,winningSide:h})}function po(t){const{winnerFirst:e=!0,addOutcomeString:r,reversed:n=!1,matchUpStatus:o,matchUpFormat:i,autoComplete:s,winningSide:a,sets:l}=t;if(!l)return{error:_e,info:"missing sets"};const c=i&&Pr(i),{bestOf:u,finalSetFormat:p,setFormat:d}=c||{},f=n||!(!e||!a||a===1),m=r?A3({matchUpStatus:o}):"",h=(l==null?void 0:l.sort(C3).map(g).filter(Boolean).join(" "))||"";if(!m)return h;if(a===2)return`${m} ${h}`;return`${h} ${m}`;function g(_){const P=u&&_.setNumber===u&&p?p:d,y=R=>Ct(R==null?void 0:R.side1Score)||Ct(R==null?void 0:R.side2Score),S=R=>Ct(R==null?void 0:R.side1TiebreakScore)||Ct(R==null?void 0:R.side2TiebreakScore),O=(P==null?void 0:P.tiebreakSet)||!y(_)&&S(_),{side1Score:b,side2Score:w,side1TiebreakScore:T,side2TiebreakScore:$}=_,N=T||(Ct(T)||s?0:""),E=$||(Ct($)||s?0:"");if(O)return`[${(f?[E,N]:[N,E]).join("-")}]`;const A=Math.min(N,E),U=A?`(${A})`:"",C=b||(Ct(b)||s?0:""),M=w||(Ct(w)||s?0:"");let D=f?`${[M,C].join("-")}${U}`:`${[C,M].join("-")}${U}`;return["-"," "].includes(D)&&(D=""),D}}function A3({matchUpStatus:t}){const e={[_r]:"RET",[ot]:"WO",[tr]:"DF/DF",[Rt]:"WO/WO",[Oi]:"SUS",[Wr]:"ABN",[Xe]:"DEF",[bl]:"DR"};return t&&e[t]||""}function C3(t,e){return t.setNumber-e.setNumber}function M3({existingMatchUpStatus:t,matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}){const i=(o==null?void 0:o.sets)||[],a=((i==null?void 0:i.filter(S=>S==null?void 0:S.winningSide))||[]).reduce((S,O)=>{const{winningSide:b}=O;if(!b)return S;const w=b-1;return S[w]++,S},[0,0]),l=n?n-1:void 0,c=l!==void 0?1-l:void 0,u=l!==void 0&&a[l],p=c!==void 0&&a[c],d=e?Pr(e):void 0,v=Math.max(...a),f=Nr(a)[v],m=d==null?void 0:d.bestOf,h=m&&Math.ceil(m/2)||1,g=r||t,_=g&&[Xe,_r,ot].includes(g),I=!d||!i.length||i.every((S,O)=>{const b=O+1,w=b===m,T=b===i.length,{side1Score:$,side2Score:N,side1TiebreakScore:E,side2TiebreakScore:A,winningSide:U}=S,C=Math.max($||0,N||0),M=E||A,{finalSetFormat:D,setFormat:R}=d,j=w&&D||R;if(M){const{tiebreakTo:W,NoAD:q}=(j==null?void 0:j.tiebreakFormat)||{},F=Math.max(E||0,A||0);if(q&&F>W||F<W&&U&&(T&&!_||!T))return!1}return j.setTo?!(!j.noTiebreak&&C>j.setTo+1):!0}),P=(!e||v===h)&&f===1&&a.indexOf(v)+1||void 0;return{valid:I&&(n&&u>p&&n===P||!n&&!P||_)}}function Ov({existingMatchUpStatus:t,matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}){if(typeof o!="object")return{error:X};const{sets:i,scoreStringSide1:s,scoreStringSide2:a}=o,l="scoreString must be a string!";if(s!==void 0&&typeof s!="string")return{error:X,info:l};if(a!==void 0&&typeof a!="string")return{error:X,info:l};if(i!==void 0&&!Array.isArray(i))return{error:X,info:or("sets")};if(i!=null&&i.length){const c=i.map(p=>p==null?void 0:p.setNumber).filter(Boolean);if(c.length!==We(c).length)return{error:X,info:"setNumbers not unique"};for(const p of i){const{side1Score:d,side2Score:v,side1TiebreakScore:f,side2TiebreakScore:m,side1PointScore:h,side2PointScore:g,winningSide:_,setNumber:I}=p;if(![[d,v],[f,m],[h,g]].filter(S=>S.some(O=>O!==void 0)).every(S=>S.every(O=>ht(O))))return{error:X,info:"non-numeric values"};if(![I,_].filter(S=>S!==void 0).every(S=>ht(S)))return{error:X,info:"non-numeric values"};if(_&&![1,2].includes(_))return{error:X,info:"winningSide must be 1 or 2"}}const{valid:u}=M3({existingMatchUpStatus:t,matchUpStatus:r,matchUpFormat:e,winningSide:n,score:o});if(!u)return{error:Sx,info:"score is invalid for matchUpFormat or winningSide does not match calculated winningSide"}}return{valid:!0}}function bv({analysis:t,set:e}){const r=Tv({set:e}),{isDecidingSet:n,isTiebreakSet:o,matchUpScoringFormat:i}=t;return My({matchUpScoringFormat:i,isDecidingSet:n,isTiebreakSet:o,set:e})&&r}function My(t){let e=t.matchUpScoringFormat;const{ignoreTiebreak:r=!1,matchUpFormat:n,isTiebreakSet:o,isDecidingSet:i,set:s}=t;if(!s)return{error:_e};e=e||n;const a=i&&e.finalSetFormat||(e==null?void 0:e.setFormat)||{},{side1Score:l,side2Score:c}=s,{NoAD:u,setTo:p,tiebreakAt:d,tiebreakFormat:v}=a,f=v==null?void 0:v.NoAd,m=Tv({set:s}),h=Math.abs(l-c),g=l>=p||c>=p,_=o||l>=p&&c>=p||d&&d<p&&(l===d||c===d),I=r||_&&(m===1&&s.side1TiebreakScore>s.side2TiebreakScore||m===2&&s.side2TiebreakScore>s.side1TiebreakScore),y=h>=(u||_&&(d&&!o||o&&f)?1:2);return(g&&(y||_)||o)&&(!_||I)}function Tv({set:t}){if(t.side1Score||t.side2Score){if(t.side1Score>t.side2Score)return 1;if(t.side2Score>t.side1Score)return 2}else if(t.side1TiebreakScore||t.side2TiebreakScore){if(t.side1TiebreakScore>t.side2TiebreakScore)return 1;if(t.side2TiebreakScore>t.side1TiebreakScore)return 2}}const Es=" ",wv="DEF",D3="COMPLETED",Dy="WO",j3="WO/WO",jy="ABN",Ry="SUS",Fy="RET",xy="INT",Ly=[Fy,wv,Dy,j3,jy,Ry,xy],Ev="DEFAULTED",Vy="WALKOVER",By="ABANDONED",ky="SUSPENDED",Gy="RETIRED",Wy="INTERRUPTED",R3=[Gy,Ev,Vy],$s="()",Bi="[]",F3=["up","left","shift+tab"],x3=["enter","down","tab","right"],Wu="backspace",Hy="r",qy="s",zy="a",Yy="d",Ky="w",Qy="i",$v=[Hy,Yy,Ky,zy,qy,Qy],Hu="space",Nv=["[","("],qu=[...F3,...x3,Hu,"]"],Jy="-",L3="/",Ns=Jy,fo=Jy,Zy=[L3],V3=0,Xy=["0","1","2","3","4","5","6","7","8","9"].concat($v),B3=Xy.map(t=>`shift+${t}`),k3=[Ns,Wu].concat(qu,Zy),G3=[Xy,B3,k3].join(",");function W3({analysis:t,scoreString:e,sets:r,value:n}){let o;if(!(r!=null&&r.length))return{sets:[]};const i=r[r.length-1];n=Te(n);const{validSide2Score:s,requiresTiebreak:a}=H3({analysis:t,set:i,value:n});if(s){o=!0,e=(e||"")+n,i.side2Score=n;const l=bv({analysis:t,set:r[r.length-1]});if(i.winningSide=l||void 0,a){const c=$s.split("")[0];e+=c}else t.isDecidingSet||(e+=Es)}return{sets:r,scoreString:e,updated:o}}function H3({analysis:t,set:e={},value:r}){const n=t.isDecidingSet&&t.matchUpScoringFormat.finalSetFormat||t.matchUpScoringFormat.setFormat,{tiebreakAt:o,setTo:i,NoAD:s}=n,{side1Score:a}=e;let l,c;return o&&o<i?a===o?l=r<=i:l=r<=o:a===i?s?l=r<i:l=r<=i+1:a===i-1?s?l=r<=i:l=r<=i+1:a===i+1?l=r===i||r===i-1:l=r<=i,l&&(o&&o<i?c=a===i&&r===o||a===o&&r===i:c=a>=i&&r>=i&&a!==r),{validSide2Score:l,requiresTiebreak:c}}function ba({scoreString:t,lowSide:e,outcome:r}){if({scoreString:t}=e0({scoreString:t}),e===2){const o=(t&&t[t.length-1])!==Es?Es:"";return t+o+r}else return r+Es+t}function e0({scoreString:t}){if(!t)return{scoreString:""};let e=!1;for(const r of Ly){const n=t==null?void 0:t.indexOf(r);n===0?t=t.slice(r.length+1).trim()+Es:n>0&&(t=t.slice(0,n)),n>=0&&(e=!0)}return t!=null&&t.trim()||(t=""),{scoreString:t,removed:e}}function Uv({analysis:t,scoreString:e,sets:r,lowSide:n}){var o,i,s;let a,l;if(!e)return{scoreString:e,sets:r};const{scoreString:c,removed:u}=e0({scoreString:e});if(e=c,u)return{scoreString:e,sets:r,outcomeRemoved:!0};let p=r[r.length-1]||{};const d=Object.values(p).filter(_=>_!==void 0).length;p.setNumber&&d===1&&(r=r.slice(0,r.length-1),p=r[r.length-1]||{});const{tiebreakSet:v}=t.setFormat,{tiebreakTo:f,NoAD:m}=v||{},{isTiebreakEntry:h}=Ta({brackets:Bi,scoreString:e}),g=z3(e);if(g>=0){a=e.slice(0,g);const{isTiebreakEntry:_}=Ta({brackets:$s,scoreString:a}),{lastOpenBracketIndex:I,isTiebreakEntry:P}=Ta({brackets:Bi,scoreString:a}),y=a&&a[a.length-1].trim(),S=a&&!isNaN(y);let O=t.isIncompleteSetScore;if(h&&P){const w=a.slice(I+1).split(fo),T=(w==null?void 0:w.length)>0&&w[0]!==void 0&&!isNaN(parseInt(w[0]))&&parseInt(w[0])||void 0,$=(w==null?void 0:w.length)>1&&w[1]!==void 0&&parseInt(w[1])||void 0,N=[T,$];if($){const E=n===1?1:0;N[E]=((N==null?void 0:N[1-E])||0)+(m?1:2),(N[E]||0)<f&&(N[E]=f),a=e.slice(0,I+1),a+=N.join(fo)}else T!==void 0?(a=e.slice(0,I+1),a+=T):(a=e.slice(0,I),O=!0);p.side1TiebreakScore=N[0]||0,p.side2TiebreakScore=N[1]||0}if(a.length||(a=void 0),O){const b=(o=p.side1Score)==null?void 0:o.toString();if(b){const w=b==null?void 0:b.slice(0,b.length-1);p.side1Score=!isNaN(w)&&parseInt(w)||void 0,p.side1Score===void 0&&(p.side2Score=void 0)}t.isTimedSet?(l=p.side1Score?r:(r==null?void 0:r.slice(0,r.length-1))||[],l[r.length-1]=p):l=(r==null?void 0:r.slice(0,r.length-1))||[]}else if(S){const b=(i=p.side2Score)==null?void 0:i.toString(),w=(s=p.side1Score)==null?void 0:s.toString();if(!t.isTiebreakEntry&&!t.isMatchTiebreak)if(p.side2Score){const T=b==null?void 0:b.slice(0,b.length-1);p.side2Score=!isNaN(T)&&parseInt(T)||void 0}else{const T=w==null?void 0:w.slice(0,w.length-1);p.side1Score=!isNaN(T)&&parseInt(T)||void 0}t.isTimedSet?p.side1Score?(l=r||[],l[r.length-1]=p):l=(r==null?void 0:r.slice(0,r.length-1))||[]:(l=r||[],l[r.length-1]=p),l[l.length-1]&&Object.assign(l[l.length-1],{winningSide:void 0})}else _?(l=r||[],Object.assign(l[l.length-1]||{},{winningSide:void 0,side1TiebreakScore:void 0,side2TiebreakScore:void 0})):(h&&!P?l=(r==null?void 0:r.slice(0,r.length-1))||[]:(l=r,l[r.length-1]=p),h||(l[l.length-1].side2Score=0,l[l.length-1].winningSide=void 0));return{scoreString:a,sets:l}}return{scoreString:e,sets:r}}function Ta({brackets:t=$s,scoreString:e}){if(!e)return{};const[r,n]=t.split(""),o=e.split(""),i=Math.max(...Dn(r,o)),s=Math.max(...Dn(n,o));return{isTiebreakEntry:i>s,lastOpenBracketIndex:i}}function q3({scoreString:t}){if(!t)return!1;const e=t&&t[t.length-1].trim(),r=t&&!isNaN(e),[n,o]=Bi.split(""),i=t.split(""),s=Math.max(...Dn(n,i)),a=Math.max(...Dn(o,i)),l=Math.max(...Dn(fo,i));return r&&s>a&&l>s}function z3(t){return t.split("").reduce((n,o,i)=>(o.match(/\d+/g)&&n.push(i),n),[]).pop()}function t0(t){const{lowValue:e=0,NoAD:r=!1,tiebreakTo:n}=t||{},o=r?1:2;return e+1>=n?e+o:parseInt(n)}function r0({matchUpFormat:t,matchUpStatus:e,winningSide:r,sets:n}){const o=Pr(t),{bestOf:i}=o,s=Math.ceil(i/2),a=n==null?void 0:n.reduce((c,u)=>{const{winningSide:p}=u;return p&&c[p-1]++,c},[0,0]);let l=(a==null?void 0:a.indexOf(s))+1||void 0;return R3.includes(e)&&r&&(l=r),{matchUpWinningSide:l}}function n0({lowSide:t,value:e,sets:r,scoreString:n,winningSide:o,matchUpStatus:i}){let s;return e===Hy?n?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:Fy}),o=t===2?1:2,i=Gy):(s=!0,n=ba({scoreString:n,lowSide:t,outcome:wv}),o=t===2?1:2,i=Ev):e===Yy?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:wv}),o=t===2?1:2,i=Ev):e===Ky?(s=!0,r=[],n=Dy,o=t===2?1:2,i=Vy):e===qy&&n?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:Ry}),i=ky,o=void 0):e===zy?(s=!0,n=ba({scoreString:n,lowSide:t,outcome:jy}),i=By,o=void 0):e===Qy&&n&&(s=!0,n=ba({scoreString:n,lowSide:t,outcome:xy}),i=Wy,o=void 0),{updated:s,sets:r,scoreString:n,matchUpStatus:i,winningSide:o}}function Y3(t){let{sets:e,info:r,scoreString:n,winningSide:o,matchUpStatus:i}=t;const{analysis:s,lowSide:a,value:l}=t;let c,u;!(e!=null&&e.length)&&l!==Wu&&(e=[{setNumber:1}]);const p=e.length-1;if($v.includes(l)){const d=e[e.length-1]||{},{side1Score:v,side2Score:f}=d;v&&!f?r="missing side2Score":s.finalSetIsComplete||o?r="final set is already complete":s.isIncompleteSetScore?r="incomplete set scoreString":s.isIncompleteSetScore||({sets:e,scoreString:n,winningSide:o,matchUpStatus:i,updated:c}=n0({lowSide:a,value:l,sets:e,scoreString:n,matchUpStatus:i,winningSide:o}))}else if(l===Wu){if({scoreString:n,sets:e,outcomeRemoved:u}=Uv({analysis:s,scoreString:n,sets:e}),(n==null?void 0:n.trim())===""&&(n=n.trim()),n||(e=[]),u){const d=e[e.length-1]||{},{side1Score:v,side2Score:f}=d;if(v&&f){const m=v>f&&1||f>v&&2||void 0;m&&(d.winningSide=m,e.push({setNumber:e.length+1}))}}i=void 0,o=void 0,c=!0}else if(s.hasOutcome)r="has outcome";else{if(o)return{sets:e,scoreString:n,winningSide:o,matchUpStatus:i,updated:!1,info:"matchUp is complete"};if(l===Hu){const d=e[e.length-1]||{},{side1Score:v,side2Score:f}=d,m=v>f&&1||f>v&&2||void 0;m&&!o&&!s.isIncompleteSetScore&&(e[e.length-1].winningSide=m,e.push({setNumber:e.length+1}),n+=" ",c=!0)}else if(l===Ns&&e[p].side1Score!==void 0&&e[p].side2Score===void 0&&n&&s.isNumericEnding)n+="-",e[p].side2Score=0,i=void 0,o=void 0,c=!0;else if(!isNaN(l)){let d;if(e[p].side2Score===void 0){const v=Te((e[p].side1Score||0).toString()+l).toString().slice(0,2);e[p].side1Score=Te(v),d=e[p].side1Score.toString(),c=!0}else{const v=Te((e[p].side2Score||0).toString()+l).toString().slice(0,2);e[p].side2Score=Te(v),d=[e[p].side1Score,e[p].side2Score].join("-"),c=!0}if(c){const v=(e.slice(0,p)||[]).filter(f=>f).map(f=>{const{side1Score:m,side2Score:h}=f;return[m,h].join("-")}).join(" ");v?n=v+" "+d:n=d}}}return{sets:e,scoreString:n,winningSide:o,matchUpStatus:i,info:r,updated:c}}function K3({analysis:t,auto:e,lowSide:r,scoreString:n="",sets:o,value:i}){var s;let a,l;const{tiebreakSet:{tiebreakTo:c,NoAD:u}}=t.setFormat,[p]=Bi.split("");if(t.isMatchTiebreakEntry||(n+=p),o[t.setNumber-1]){const{lastOpenBracketIndex:v}=Ta({brackets:Bi,scoreString:n}),m=(n.slice((v??0)+1)+(e?"":i)).split(fo);if((((s=m[r-1])==null?void 0:s.length)||0)>=2)l="tiebreak digit limit";else if(e){r===1&&(m[0]=(m[0]||"")+i),r===2&&(m[1]=(m[1]||"")+i);const g=[m[0]||0,m[1]||0].map(P=>Te(P)),_=r===1?1:0;g[_]=g[1-_]+(u?1:2),g[_]<c&&(g[_]=c);const I=o[o.length-1];I.side1TiebreakScore=g[0],I.side2TiebreakScore=g[1],n=n.slice(0,(v??0)+1),n+=g.join(fo),a=!0}else{const g=[m[0]||0,m[1]||0].map(I=>Te(I)),_=o[o.length-1];_.side1TiebreakScore=g[0],_.side2TiebreakScore=g[1],n+=i,a=!0}}else{const v=t0({lowValue:Te(i||0),tiebreakTo:c,NoAD:u}),f=[Te(i),v];r===2&&f.reverse();const m={side1TiebreakScore:f[0],side2TiebreakScore:f[1],setNumber:(o==null?void 0:o.length)+1||1};o.push(m),n+=f.join(fo),a=!0}return{info:l,scoreString:n,sets:o,updated:a}}function Q3({analysis:t,lowSide:e,scoreString:r,value:n}){const{setTo:o,tiebreakAt:i,NoAD:s}=(t==null?void 0:t.setFormat)||{},a=n===parseInt(i||o);if(i&&i<o&&n>i)return{scoreString:r};if(s&&n===o||n>o)return{scoreString:r};const l=m(),c=[n,l];e===2&&c.reverse();const p=$s.split("")[0],d=c.join(Ns)+(a?p:Es);r=(r||"")+d;const v={side1Score:c[0],side2Score:c[1]},f=bv({analysis:t,set:v});return v.winningSide=f||void 0,{scoreString:r,set:v};function m(){return a?n+1:n+1===o?n+(s?1:2):o}}function J3({matchUpFormat:t,scoreString:e,winningSide:r,value:n,sets:o}){var i,s,a;const c=(((i=o==null?void 0:o.filter(x=>x==null?void 0:x.winningSide))==null?void 0:i.length)||0)+(r?0:1),u=Pr(t),p=c===(u==null?void 0:u.bestOf),d=p&&(u==null?void 0:u.finalSetFormat)||(u==null?void 0:u.setFormat)||{},v=(d==null?void 0:d.timed)||(u==null?void 0:u.timed),f=p&&o[(u==null?void 0:u.bestOf)-1],m=f==null?void 0:f.winningSide,{isTiebreakEntry:h}=Ta({brackets:$s,scoreString:e}),{isTiebreakEntry:g}=Ta({brackets:Bi,scoreString:e}),_=h||g,I=!!d.tiebreakSet,P=(s=e==null?void 0:e[e.length-1])==null?void 0:s.trim(),y=e&&!isNaN(P),S=!_&&P===Ns,O=h&&Nv.includes(P),b=g&&Nv.includes(P),w=g&&P===fo,T=e==null?void 0:e.split(""),[$]=Bi.split(""),N=T&&Math.max(...Dn($,T)),E=T&&Math.max(...Dn(fo,T)),A=T&&E>N,U=(a=o[o.length-1])==null?void 0:a.winningSide,C=(o==null?void 0:o.length)&&!U,M=Ly.find(x=>(e==null?void 0:e.indexOf(x))>=0),D=!isNaN(n),R=n===Hu,j=qu.includes(n),G=e==null?void 0:e.split("").find(x=>Nv.includes(x)),W=j&&g&&!b&&(w||!q3({scoreString:e}));return{isTiebreakSetValue:I&&D,matchUpScoringFormat:u,setNumber:c,setFormat:d,matchTiebreakHasJoiner:A,isGameScoreEntry:C,isSpace:R,isCloser:j,isTiebreakCloser:j&&G&&_&&y,isDecidingSet:p,isTiebreakSet:I,isTimedSet:v,isNumericEnding:y,isNumericValue:D,hasOpener:G,hasOutcome:M,finalSet:f,finalSetIsComplete:m,lastSetIsComplete:U,isInvalidSetTiebreakValue:R&&_&&O,isInvalidMatchTiebreakValue:W,isTiebreakEntry:_,isSetTiebreakEntry:h,isMatchTiebreakEntry:g,isIncompleteSetScore:S,isIncompleteSetTiebreak:O,isIncompleteMatchTiebreak:b,isPartialMatchTiebreakValue:w}}function Z3(t){let{lowSide:e=1,value:r}=t,{scoreString:n,sets:o,winningSide:i,matchUpStatus:s}=t;const{matchUpFormat:a,shiftFirst:l,auto:c=!0}=t;let u,p;const d=l&&e===2||!l&&e===1;if(!G3.includes(r))return{updated:!1,info:"invalid key"};l&&(e=3-e);const{matchUpWinningSide:v}=r0({sets:o,winningSide:i,matchUpStatus:s,matchUpFormat:a});i=v;const f=J3({value:r,winningSide:i,scoreString:n,sets:o,matchUpFormat:a});if(Zy.includes(r)&&(r=Ns),f.hasOpener&&f.isTiebreakEntry&&!f.isTiebreakSet&&d&&Te(r)===0&&(f.isTiebreakCloser=!0),qu.includes(r)&&f.hasOpener&&(r=""),qu.includes(r)&&(r=Hu),f.lastSetIsComplete){const m=(n==null?void 0:n.length)&&n[n.length-1];n&&m!==" "&&(n+=" ")}if(f.isTimedSet)({info:p,sets:o,scoreString:n,updated:u,matchUpStatus:s,winningSide:i}=Y3({analysis:f,lowSide:e,scoreString:n,sets:o,matchUpStatus:s,winningSide:i,value:r}));else if($v.includes(r))f.finalSetIsComplete||i?p="final set is already complete":!f.isTiebreakEntry&&!f.isIncompleteSetScore?{sets:o,scoreString:n,matchUpStatus:s,winningSide:i,updated:u}=n0({lowSide:e,sets:o,scoreString:n,matchUpStatus:s,winningSide:i,value:r}):f.isTiebreakEntry||f.isIncompleteSetScore?p="incomplete set scoreString or tiebreak entry":console.log("handle case",{value:r});else if(r===Wu)u=!0,{scoreString:n,sets:o}=Uv({analysis:f,scoreString:n,sets:o,lowSide:e}),n||(o=[]),s=void 0,i=void 0;else if(f.hasOutcome)p="has outcome";else if(r===Ns&&!f.isMatchTiebreakEntry)(!f.isSetTiebreakEntry||f.isSetTiebreakEntry&&!f.isNumericEnding)&&(u=!0,{scoreString:n,sets:o}=Uv({analysis:f,scoreString:n,sets:o,lowSide:e}),s=void 0);else if(r===fo&&f.isMatchTiebreakEntry&&!f.isSetTiebreakEntry)f.matchTiebreakHasJoiner?p="existing joiner":f.isNumericEnding&&(u=!0,n+=fo);else if([Ns,fo].includes(r))p="invalid location for joiner";else{if(i)return{updated:!1,info:"matchUp is complete"};if(f.isIncompleteSetScore)f.isNumericValue&&({sets:o,scoreString:n,updated:u}=W3({analysis:f,scoreString:n,sets:o,value:r}));else if(f.isInvalidMatchTiebreakValue)p="invalid matchUp tiebreak character";else if(f.isInvalidSetTiebreakValue)p="invalid set tiebreak character";else if(f.isTiebreakCloser){const m=f.isSetTiebreakEntry?$s:Bi,h=m.split("").reverse()[0],g=m.split("")[0],_=o[o.length-1],{tiebreakFormat:I}=f.setFormat,{tiebreakTo:P,NoAD:y}=I||{},S=Tv({set:_});if(!f.isTiebreakSet){const b=parseInt(n.split(g).reverse()[0]),w=t0({lowValue:b,tiebreakTo:P,NoAD:y});S===1?(_.side1TiebreakScore=w,_.side2TiebreakScore=b):(_.side1TiebreakScore=b,_.side2TiebreakScore=w)}n=(n||"")+h,f.isDecidingSet||(n+=Es);const O=bv({analysis:f,set:_});_.winningSide=O||void 0,u=!0}else if(f.isTiebreakSetValue)({info:p,scoreString:n,sets:o,updated:u}=K3({analysis:f,auto:c,lowSide:e,scoreString:n,sets:o,value:r}));else if(f.isSetTiebreakEntry){const[m]=$s.split(""),h=Math.max(...Dn(m,n.split(""))),g=n.slice(h+1),_=g&&Te(g)===V3,I=Te(g?g+r:r),{tiebreakFormat:P}=f.setFormat,{tiebreakTo:y,NoAD:S}=P||{};!_&&g.length<2?S&&I>y-1?p="invalid low value for NoAD tiebreak":(u=!0,n=(n||"")+r):p=_?"tiebreak begins with zero":"tiebreak digit limit"}else if(f.isCloser)p=`invalid key: ${r}`;else if(f.isGameScoreEntry)p="game scoreString entry";else if(f.lastSetIsComplete||!o.length){u=!0;const{scoreString:m,set:h}=Q3({analysis:f,lowSide:e,scoreString:n,value:Te(r)});h&&(h.setNumber=(o==null?void 0:o.length)+1||1),o=(o==null?void 0:o.concat(h).filter(Boolean))||[h],n=m||void 0}else console.log("error: unknown outcome")}if(u){o=o==null?void 0:o.filter(Boolean);const{matchUpWinningSide:m}=r0({sets:o,winningSide:i,matchUpStatus:s,matchUpFormat:a});return i=m,m&&(!s||[Ft,so].includes(s))?(s=D3,o=o.filter(h=>{const{side1Score:g,side2Score:_,side1TiebreakScore:I,side2TiebreakScore:P}=h;return g||_||I||P})):n&&!i&&![ky,By,Wy].includes(s)&&(s=void 0),{updated:u,scoreString:n,sets:o,winningSide:i,matchUpStatus:s,info:p}}return{updated:u,scoreString:n,sets:o,winningSide:i,matchUpStatus:s,info:p}}function X3({matchUpScoringFormat:t,isDecidingSet:e,isTiebreakSet:r,setObject:n}){if(!n)return;const o=o0({set:n});return eW({matchUpScoringFormat:t,isDecidingSet:e,isTiebreakSet:r,set:n})&&o||void 0}function eW({ignoreTiebreak:t=!1,matchUpScoringFormat:e,matchUpFormat:r,isTiebreakSet:n,isDecidingSet:o,set:i}){if(!i)return{error:_e,info:"missing set"};e=e||r&&Pr(r);const s=o&&e.finalSetFormat||(e==null?void 0:e.setFormat)||{},{side1Score:a,side2Score:l}=i,{setTo:c,tiebreakAt:u,tiebreakFormat:p}=s,d=p==null?void 0:p.NoAd,v=o0({set:i}),f=Math.abs(a-l),m=a>=c||l>=c,h=n||a>=c&&l>=c||u&&u<c&&(a===u||l===u),g=t||h&&(v===1&&i.side1TiebreakScore>i.side2TiebreakScore||v===2&&i.side2TiebreakScore>i.side1TiebreakScore),I=f>=(h&&(u&&!n||n&&d)?1:2);return(m&&(I||h)||n)&&(!h||g)}function o0({set:t}){if(t.side1Score||t.side2Score){if(t.side1Score>t.side2Score)return 1;if(t.side2Score>t.side1Score)return 2}else if(t.side1TiebreakScore||t.side2TiebreakScore){if(t.side1TiebreakScore>t.side2TiebreakScore)return 1;if(t.side2TiebreakScore>t.side1TiebreakScore)return 2}}function zu(t){const{setObject:e,matchUpScoringFormat:r}=t;if(!e)return{error:of};const{setNumber:n}=e||{},{bestOf:o}=r||{},i=!!(n&&o&&n===o),s=i&&(r==null?void 0:r.finalSetFormat)||(r==null?void 0:r.setFormat),a=!!(s!=null&&s.tiebreakSet),l=!!(s!=null&&s.timed),c=!a&&!l,u=!!(n&&o&&n<=o),p=[e==null?void 0:e.side1Score,e==null?void 0:e.side2Score],d=[e==null?void 0:e.side1PointScore,e==null?void 0:e.side2PointScore],v=[e==null?void 0:e.side1TiebreakScore,e==null?void 0:e.side2TiebreakScore],f=p.filter(C=>C!==void 0).length,m=d.filter(C=>C!==void 0).length,h=v.filter(C=>C!==void 0).length,g=p==null?void 0:p.filter(C=>!isNaN(C)).length,_=v==null?void 0:v.filter(C=>!isNaN(C)).length,{tiebreakAt:I}=s||{},P=I&&p.filter(C=>C>=I).length===2,y=P&&(p[0]>p[1]&&1||p[1]>p[0]&&2||void 0),S=!!(_&&!g),O=!!(e!=null&&e.winningSide),{error:b,result:w}=tW({setObject:e,setFormat:s,sideGameScores:p,sideTiebreakScores:v}),{error:T,result:$}=rW({setObject:e,setFormat:s,sideTiebreakScores:v}),N=c&&!S&&w||a&&S&&$,E=u&&!(a&&!S)&&!(c&&S)&&(!O||N),A=X3({isDecidingSet:i,isTiebreakSet:S,matchUpScoringFormat:r,setObject:e}),U={expectTiebreakSet:a,expectTimedSet:l,hasTiebreakCondition:P,isCompletedSet:O,isDecidingSet:i,isTiebreakSet:S,isValidSet:E,isValidSetNumber:u,isValidSetOutcome:N,leadingSide:y,setFormat:s,sideGameScores:p,sideGameScoresCount:f,sidePointScores:d,sidePointScoresCount:m,sideTiebreakScores:v,sideTiebreakScoresCount:h,winningSide:A};return(e==null?void 0:e.winningSide)!==void 0&&(S?(U.isValidTiebreakSetOutcome=$,$||(U.tiebreakSetError=T)):(U.isValidStandardSetOutcome=w,w||(U.standardSetError=b))),U}function tW({setObject:t,setFormat:e,sideGameScores:r,sideTiebreakScores:n}){if(!t)return{result:!1,error:of};const o=!!(e!=null&&e.tiebreakSet),i=!!(e!=null&&e.timed);if(!e||o||i)return{result:!1,error:X};if(!((r==null?void 0:r.filter($=>!isNaN($)).length)===2))return{result:!1,error:o_};const{setTo:a,tiebreakAt:l,tiebreakFormat:c,NoAD:u}=e||{};if(!!!(a&&(r!=null&&r.find($=>$>=a))))return{result:!1,error:o_};const d=[1,2].includes(t==null?void 0:t.winningSide);if(!t||!d)return{result:!1,error:i_};const v=(t==null?void 0:t.winningSide)-1,f=1-v,m=r[v],h=r[f],g=m-h;if(!(m>h))return{result:!1,error:{message:"winningSide game scoreString is not high"}};const I=l&&c,P=(n==null?void 0:n.filter($=>!isNaN($)).length)===2,y=n==null?void 0:n[v],S=n==null?void 0:n[f],O=l&&r.filter($=>$>=l).length===2;if(I){const{NoAD:$,tiebreakTo:N}=c;if(O){if(g>1)return{result:!1,error:{message:"invalid winning game scoreString (5)"}};if(!P)return{result:!1,error:{message:"invalid tiebreak scores (1)"}};if(isNaN(N))return{result:!1,error:{message:"tiebreakTo error"}};if(!!!(N&&(n!=null&&n.find(j=>j>=N))))return{result:!1,error:{message:"invalid tiebreak scores (2)"}};const U=l<a?a:a+1;if(m>U)return{result:!1,error:{message:"invalid winning game scoreString (1)"}};if(!y||!S||y<S)return{result:!1,error:{message:"winningSide tiebreak value is not high"}};const C=$?1:2,M=y-S,D=S>=N-1;if(M&&D&&M<C)return{result:!1,error:{message:"invalid tiebreak scores (3)"}}}if(m>a&&!O)return{result:!1,error:{message:"invalid winning game scoreString (2)"}}}const b=u?1:2,w=h>=a-1;return g&&w&&!O&&g<b?{result:!1,error:{message:"invalid winning game scoreString (3)"}}:g>b&&m>a?{result:!1,error:{message:"invalid winning game scoreString (4)"}}:{result:!0}}function rW({setObject:t,setFormat:e,sideTiebreakScores:r}){if(!t)return{result:!1,error:of};const n=!!(e!=null&&e.tiebreakSet),o=!!(e!=null&&e.timed);if(!e||!n||o)return{result:!1,error:{message:"not tiebreak set"}};const i=[1,2].includes(t==null?void 0:t.winningSide);if(!t||!i)return{result:!1,error:i_};const{tiebreakSet:s}=e||{},{NoAD:a,tiebreakTo:l}=s||{};if(!((r==null?void 0:r.filter(I=>!isNaN(I)).length)===2))return{result:!1,error:{message:"invalid tiebreak scores (1)"}};if(isNaN(l))return{result:!1,error:{message:"tiebreakTo error"}};if(!!!(r!=null&&r.find(I=>I>=l)))return{result:!1,error:{message:"invalid tiebreak scores (2)"}};const p=(t==null?void 0:t.winningSide)-1,d=1-p,v=r[p],f=r[d];if(!v||!f||v<f)return{result:!1,error:{message:"winningSide tiebreak value is not high"}};const m=a?1:2,h=v-f,g=f>=l-1;return h&&g&&h<m?{result:!1,error:{message:"invalid tiebreak scores (3)"}}:{result:!0}}var nW=Object.defineProperty,i0=Object.getOwnPropertySymbols,oW=Object.prototype.hasOwnProperty,iW=Object.prototype.propertyIsEnumerable,s0=(t,e,r)=>e in t?nW(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sW=(t,e)=>{for(var r in e||(e={}))oW.call(e,r)&&s0(t,r,e[r]);if(i0)for(var r of i0(e))iW.call(e,r)&&s0(t,r,e[r]);return t};function aW(t){if(!(t!=null&&t.score))return{error:_e};const{sets:e}=t.score,r=e.map(i=>{const{side1TiebreakScore:s,side2TiebreakScore:a,winningSide:l,side1Score:c,side2Score:u,setNumber:p}=i;return Oe({winningSide:l?3-l:void 0,side1TiebreakScore:a,side2TiebreakScore:s,side1Score:u,side2Score:c,setNumber:p})}),n=po({sets:r}),o=po({sets:r,reversed:!0});return sW({reversedScore:{sets:r,scoreStringSide1:n,scoreStringSide2:o}},V)}const a0=t=>{const{isSide1:e,lowValue:r,setTo:n,tiebreakAt:o,NoAD:i}=t;if(r===void 0)return!1;let s=Te(r);(s==null?void 0:s.toString().length)>2&&(s=parseInt(s.toString().slice(0,2))),o&&o<n&&s>o&&(s=o);let a;return i&&!o?a=s<n?n:n-1:a=s+1<n&&n||o&&o<n&&s===o&&n||!o&&s+2||n+1,[e?s:a,e?a:s]},Av=t=>{const{isSide1:e,lowValue:r,tiebreakTo:n,tiebreakNoAd:o}=t;if(r===void 0)return!1;let i=typeof r=="string"?parseInt(r):r;(i==null?void 0:i.toString().length)>2&&(i=parseInt(i.toString().slice(0,2))),o&&i>n-1&&(i=n-1);const s=lW({lowValue:i,NoAD:o,tiebreakTo:n});return[e?i:s,e?s:i]};function lW(t){const{lowValue:e,NoAD:r,tiebreakTo:n}=t,o=r?1:2;return e+1>=n?e+o:n}const l0={stringifyMatchUpFormat:Yp,isValidMatchUpFormat:Xr,parseMatchUpFormat:Pr,generateTieMatchUpScore:tc,getTiebreakComplement:Av,updateTieMatchUpScore:uo,generateScoreString:po,checkSetIsComplete:My,validateTieFormat:br,getSetComplement:a0,scoreHasValue:Gt,keyValueScore:Z3,validateScore:Ov,reverseScore:aW,analyzeSet:zu};function c0(t){return t&&typeof String.fromCodePoint<"u"?t.toUpperCase().replace(/./g,e=>String.fromCodePoint(e.charCodeAt(0)+127397)):t}function cW(t){const e=Object.assign({},...ii.filter(r=>r.ioc).map(r=>({[r.ioc]:r.iso})));return c0(e[t])}const ii=[{ioc:"",iso2:"",iso:"",label:"NONE",phone:""},{ioc:"AND",iso2:"AD",iso:"AND",label:"Andorra",phone:"376"},{ioc:"UAE",iso2:"AE",iso:"ARE",label:"United Arab Emirates",phone:"971"},{ioc:"AFG",iso2:"AF",iso:"AFG",label:"Afghanistan",phone:"93"},{ioc:"ANT",iso2:"AG",iso:"ATG",label:"Antigua and Barbuda",phone:"1-268"},{ioc:"AIA",iso2:"AI",iso:"AIA",label:"Anguilla",phone:"1-264"},{ioc:"ALB",iso2:"AL",iso:"ALB",label:"Albania",phone:"355"},{ioc:"ARM",iso2:"AM",iso:"ARM",label:"Armenia",phone:"374"},{ioc:"ANG",iso2:"AO",iso:"AGO",label:"Angola",phone:"244"},{ioc:"",iso2:"AQ",iso:"ATA",label:"Antarctica",phone:"672"},{ioc:"ARG",iso2:"AR",iso:"ARG",label:"Argentina",phone:"54"},{ioc:"ASA",iso2:"AS",iso:"ASM",label:"American Samoa",phone:"1-684"},{ioc:"AUT",iso2:"AT",iso:"AUT",label:"Austria",phone:"43"},{ioc:"AUS",iso2:"AU",iso:"AUS",label:"Australia",phone:"61",suggested:!0},{ioc:"ARU",iso2:"AW",iso:"ABW",label:"Aruba",phone:"297"},{ioc:"AZE",iso2:"AZ",iso:"AZE",label:"Azerbaijan",phone:"994"},{ioc:"BIH",iso2:"BA",iso:"BIH",label:"Bosnia and Herzegovina",phone:"387"},{ioc:"BAR",iso2:"BB",iso:"BRB",label:"Barbados",phone:"1-246"},{ioc:"BAN",iso2:"BD",iso:"BGD",label:"Bangladesh",phone:"880"},{ioc:"BEL",iso2:"BE",iso:"BEL",label:"Belgium",phone:"32"},{ioc:"BUR",iso2:"BF",iso:"BFA",label:"Burkina Faso",phone:"226"},{ioc:"BUL",iso2:"BG",iso:"BGR",label:"Bulgaria",phone:"359"},{ioc:"BRN",iso2:"BH",iso:"BHR",label:"Bahrain",phone:"973"},{ioc:"BDI",iso2:"BI",iso:"BDI",label:"Burundi",phone:"257"},{ioc:"BEN",iso2:"BJ",iso:"BEN",label:"Benin",phone:"229"},{ioc:"",iso2:"BL",iso:"BLM",label:"Saint Barthelemy",phone:"590"},{ioc:"BER",iso2:"BM",iso:"BMU",label:"Bermuda",phone:"1-441"},{ioc:"BRU",iso2:"BN",iso:"BRN",label:"Brunei Darussalam",phone:"673"},{ioc:"BOL",iso2:"BO",iso:"BOL",label:"Bolivia",phone:"591"},{ioc:"BRA",iso2:"BR",iso:"BRA",label:"Brazil",phone:"55"},{ioc:"BAH",iso2:"BS",iso:"BHS",label:"Bahamas",phone:"1-242"},{ioc:"BHU",iso2:"BT",iso:"BTN",label:"Bhutan",phone:"975"},{ioc:"",iso2:"BV",iso:"BVT",label:"Bouvet Island",phone:"47"},{ioc:"BOT",iso2:"BW",iso:"BWA",label:"Botswana",phone:"267"},{ioc:"BLR",iso2:"BY",iso:"BLR",label:"Belarus",phone:"375"},{ioc:"BIZ",iso2:"BZ",iso:"BLZ",label:"Belize",phone:"501"},{ioc:"CAN",iso2:"CA",iso:"CAN",label:"Canada",phone:"1",suggested:!0},{ioc:"",iso2:"CC",iso:"CCK",label:"Cocos (Keeling) Islands",phone:"61"},{ioc:"CGO",iso2:"CD",iso:"COG",label:"Congo, Republic of the",phone:"242"},{ioc:"CAF",iso2:"CF",iso:"CAF",label:"Central African Republic",phone:"236"},{ioc:"COD",iso2:"CG",iso:"CGD",label:"Congo, Democratic Republic of the",phone:"243"},{ioc:"SUI",iso2:"CH",iso:"CHE",label:"Switzerland",phone:"41"},{ioc:"CIV",iso2:"CI",iso:"CIV",label:"Cote d'Ivoire",phone:"225"},{ioc:"COK",iso2:"CK",iso:"COK",label:"Cook Islands",phone:"682"},{ioc:"CHI",iso2:"CL",iso:"CHL",label:"Chile",phone:"56"},{ioc:"CMR",iso2:"CM",iso:"CMR",label:"Cameroon",phone:"237"},{ioc:"CHN",iso2:"CN",iso:"CHN",label:"China",phone:"86"},{ioc:"COL",iso2:"CO",iso:"COL",label:"Colombia",phone:"57"},{ioc:"CRC",iso2:"CR",iso:"CRI",label:"Costa Rica",phone:"506"},{ioc:"CUB",iso2:"CU",iso:"CUB",label:"Cuba",phone:"53"},{ioc:"CPV",iso2:"CV",iso:"CPV",label:"Cape Verde",phone:"238"},{ioc:"CUW",iso2:"CW",iso:"CUW",label:"Curacao",phone:"599"},{ioc:"CXR",iso2:"CX",iso:"CXR",label:"Christmas Island",phone:"61"},{ioc:"CYP",iso2:"CY",iso:"CYP",label:"Cyprus",phone:"357"},{ioc:"CZE",iso2:"CZ",iso:"CZE",label:"Czech Republic",phone:"420"},{ioc:"GER",iso2:"DE",iso:"DEU",label:"Germany",phone:"49",suggested:!0},{ioc:"DJI",iso2:"DJ",iso:"DJI",label:"Djibouti",phone:"253"},{ioc:"DEN",iso2:"DK",iso:"DNK",label:"Denmark",phone:"45"},{ioc:"DMA",iso2:"DM",iso:"DMA",label:"Dominica",phone:"1-767"},{ioc:"DOM",iso2:"DO",iso:"DOM",label:"Dominican Republic",phone:"1-809"},{ioc:"ALG",iso2:"DZ",iso:"DZA",label:"Algeria",phone:"213"},{ioc:"ECU",iso2:"EC",iso:"ECU",label:"Ecuador",phone:"593"},{ioc:"EST",iso2:"EE",iso:"ESE",label:"Estonia",phone:"372"},{ioc:"EGY",iso2:"EG",iso:"EGY",label:"Egypt",phone:"20"},{ioc:"",iso2:"EH",iso:"ESH",label:"Western Sahara",phone:"212"},{ioc:"ERI",iso2:"ER",iso:"ERI",label:"Eritrea",phone:"291"},{ioc:"ESP",iso2:"ES",iso:"ESP",label:"Spain",phone:"34"},{ioc:"ETH",iso2:"ET",iso:"ETH",label:"Ethiopia",phone:"251"},{ioc:"FIN",iso2:"FI",iso:"FIN",label:"Finland",phone:"358"},{ioc:"FIJ",iso2:"FJ",iso:"FJI",label:"Fiji",phone:"679"},{ioc:"FLK",iso2:"FK",iso:"FLK",label:"Falkland Islands (Malvinas)",phone:"500"},{ioc:"FSM",iso2:"FM",iso:"FSM",label:"Micronesia, Federated States of",phone:"691"},{ioc:"FAR",iso2:"FO",iso:"FRO",label:"Faroe Islands",phone:"298"},{ioc:"FRA",iso2:"FR",iso:"FRA",label:"France",phone:"33",suggested:!0},{ioc:"GAB",iso2:"GA",iso:"GAB",label:"Gabon",phone:"241"},{ioc:"GBR",iso2:"GB",iso:"GBR",label:"United Kingdom",phone:"44"},{ioc:"GRN",iso2:"GD",iso:"GRD",label:"Grenada",phone:"1-473"},{ioc:"GEO",iso2:"GE",iso:"GEO",label:"Georgia",phone:"995"},{ioc:"FGU",iso2:"GF",iso:"GUF",label:"French Guiana",phone:"594"},{ioc:"",iso2:"GG",iso:"GGY",label:"Guernsey",phone:"44"},{ioc:"",iso2:"GH",iso:"GHA",label:"Ghana",phone:"233"},{ioc:"GIB",iso2:"GI",iso:"GIB",label:"Gibraltar",phone:"350"},{ioc:"GRL",iso2:"GL",iso:"GRL",label:"Greenland",phone:"299"},{ioc:"GAM",iso2:"GM",iso:"GMB",label:"Gambia",phone:"220"},{ioc:"GUI",iso2:"GN",iso:"GIN",label:"Guinea",phone:"224"},{ioc:"GUD",iso2:"GP",iso:"GLP",label:"Guadeloupe",phone:"590"},{ioc:"GEQ",iso2:"GQ",iso:"GNQ",label:"Equatorial Guinea",phone:"240"},{ioc:"GRE",iso2:"GR",iso:"GRC",label:"Greece",phone:"30"},{ioc:"",iso2:"GS",iso:"SGS",label:"South Georgia and the South Sandwich Islands",phone:"500"},{ioc:"GUA",iso2:"GT",iso:"GTM",label:"Guatemala",phone:"502"},{ioc:"GUM",iso2:"GU",iso:"GUM",label:"Guam",phone:"1-671"},{ioc:"GBS",iso2:"GW",iso:"GNB",label:"Guinea-Bissau",phone:"245"},{ioc:"GUY",iso2:"GY",iso:"GUY",label:"Guyana",phone:"592"},{ioc:"HKG",iso2:"HK",iso:"HKG",label:"Hong Kong",phone:"852"},{ioc:"",iso2:"HM",iso:"HMD",label:"Heard Island and McDonald Islands",phone:"672"},{ioc:"HON",iso2:"HN",iso:"HND",label:"Honduras",phone:"504"},{ioc:"CRO",iso2:"HR",iso:"HRV",label:"Croatia",phone:"385"},{ioc:"HAI",iso2:"HT",iso:"HTI",label:"Haiti",phone:"509"},{ioc:"HUN",iso2:"HU",iso:"HUN",label:"Hungary",phone:"36"},{ioc:"INA",iso2:"ID",iso:"IDN",label:"Indonesia",phone:"62"},{ioc:"IRL",iso2:"IE",iso:"IRL",label:"Ireland",phone:"353"},{ioc:"ISR",iso2:"IL",iso:"ISR",label:"Israel",phone:"972"},{ioc:"",iso2:"IM",iso:"IMN",label:"Isle of Man",phone:"44"},{ioc:"IND",iso2:"IN",iso:"IND",label:"India",phone:"91"},{ioc:"",iso2:"IO",iso:"IOT",label:"British Indian Ocean Territory",phone:"246"},{ioc:"IRQ",iso2:"IQ",iso:"IRQ",label:"Iraq",phone:"964"},{ioc:"IRI",iso2:"IR",iso:"IRN",label:"Iran, Islamic Republic of",phone:"98"},{ioc:"ISL",iso2:"IS",iso:"ISL",label:"Iceland",phone:"354"},{ioc:"ITA",iso2:"IT",iso:"ITA",label:"Italy",phone:"39"},{ioc:"",iso2:"JE",iso:"JEY",label:"Jersey",phone:"44"},{ioc:"JAM",iso2:"JM",iso:"JAM",label:"Jamaica",phone:"1-876"},{ioc:"JOR",iso2:"JO",iso:"JOR",label:"Jordan",phone:"962"},{ioc:"JPN",iso2:"JP",iso:"JPN",label:"Japan",phone:"81",suggested:!0},{ioc:"KEN",iso2:"KE",iso:"KEN",label:"Kenya",phone:"254"},{ioc:"KGZ",iso2:"KG",iso:"KGZ",label:"Kyrgyzstan",phone:"996"},{ioc:"CAM",iso2:"KH",iso:"KHM",label:"Cambodia",phone:"855"},{ioc:"KIR",iso2:"KI",iso:"KIR",label:"Kiribati",phone:"686"},{ioc:"COM",iso2:"KM",iso:"COM",label:"Comoros",phone:"269"},{ioc:"SKN",iso2:"KN",iso:"KNA",label:"Saint Kitts and Nevis",phone:"1-869"},{ioc:"KOR",iso2:"KP",iso:"KOR",label:"Korea, Democratic People's Republic of",phone:"850"},{ioc:"PRK",iso2:"KR",iso:"PRK",label:"Korea, Republic of",phone:"82"},{ioc:"KUW",iso2:"KW",iso:"KWT",label:"Kuwait",phone:"965"},{ioc:"CAY",iso2:"KY",iso:"CYM",label:"Cayman Islands",phone:"1-345"},{ioc:"KAZ",iso2:"KZ",iso:"KAZ",label:"Kazakhstan",phone:"7"},{ioc:"LAO",iso2:"LA",iso:"LAO",label:"Lao People's Democratic Republic",phone:"856"},{ioc:"LIB",iso2:"LB",iso:"LBN",label:"Lebanon",phone:"961"},{ioc:"LCA",iso2:"LC",iso:"LCA",label:"Saint Lucia",phone:"1-758"},{ioc:"LIE",iso2:"LI",iso:"LIE",label:"Liechtenstein",phone:"423"},{ioc:"SRI",iso2:"LK",iso:"LKA",label:"Sri Lanka",phone:"94"},{ioc:"LBR",iso2:"LR",iso:"LBR",label:"Liberia",phone:"231"},{ioc:"LES",iso2:"LS",iso:"LSO",label:"Lesotho",phone:"266"},{ioc:"LTU",iso2:"LT",iso:"LTU",label:"Lithuania",phone:"370"},{ioc:"LUX",iso2:"LU",iso:"LUX",label:"Luxembourg",phone:"352"},{ioc:"LAT",iso2:"LV",iso:"LVA",label:"Latvia",phone:"371"},{ioc:"LBA",iso2:"LY",iso:"LBY",label:"Libya",phone:"218"},{ioc:"MAR",iso2:"MA",iso:"MAR",label:"Morocco",phone:"212"},{ioc:"MON",iso2:"MC",iso:"MCO",label:"Monaco",phone:"377"},{ioc:"MDA",iso2:"MD",iso:"MDA",label:"Moldova, Republic of",phone:"373"},{ioc:"MNE",iso2:"ME",iso:"MNE",label:"Montenegro",phone:"382"},{ioc:"",iso2:"MF",iso:"MAF",label:"Saint Martin (French part)",phone:"590"},{ioc:"MAD",iso2:"MG",iso:"MDG",label:"Madagascar",phone:"261"},{ioc:"MSH",iso2:"MH",iso:"MHL",label:"Marshall Islands",phone:"692"},{ioc:"MKD",iso2:"MK",iso:"MKD",label:"Macedonia, the Former Yugoslav Republic of",phone:"389"},{ioc:"MLI",iso2:"ML",iso:"MLI",label:"Mali",phone:"223"},{ioc:"MYA",iso2:"MM",iso:"MMR",label:"Myanmar",phone:"95"},{ioc:"MGL",iso2:"MN",iso:"MNG",label:"Mongolia",phone:"976"},{ioc:"MAC",iso2:"MO",iso:"MAC",label:"Macao",phone:"853"},{ioc:"NMA",iso2:"MP",iso:"NMP",label:"Northern Mariana Islands",phone:"1-670"},{ioc:"MRT",iso2:"MQ",iso:"MTQ",label:"Martinique",phone:"596"},{ioc:"MTN",iso2:"MR",iso:"MRT",label:"Mauritania",phone:"222"},{ioc:"MNT",iso2:"MS",iso:"MSR",label:"Montserrat",phone:"1-664"},{ioc:"MLT",iso2:"MT",iso:"MLT",label:"Malta",phone:"356"},{ioc:"MRI",iso2:"MU",iso:"MUS",label:"Mauritius",phone:"230"},{ioc:"MDV",iso2:"MV",iso:"MDV",label:"Maldives",phone:"960"},{ioc:"MAW",iso2:"MW",iso:"MWI",label:"Malawi",phone:"265"},{ioc:"MEX",iso2:"MX",iso:"MEX",label:"Mexico",phone:"52"},{ioc:"MAS",iso2:"MY",iso:"MYS",label:"Malaysia",phone:"60"},{ioc:"MOZ",iso2:"MZ",iso:"MOZ",label:"Mozambique",phone:"258"},{ioc:"NAM",iso2:"NA",iso:"NAM",label:"Namibia",phone:"264"},{ioc:"NCL",iso2:"NC",iso:"NCL",label:"New Caledonia",phone:"687"},{ioc:"NIG",iso2:"NE",iso:"NER",label:"Niger",phone:"227"},{ioc:"NFI",iso2:"NF",iso:"NFK",label:"Norfolk Island",phone:"672"},{ioc:"NGR",iso2:"NG",iso:"NGA",label:"Nigeria",phone:"234"},{ioc:"NCA",iso2:"NI",iso:"NIC",label:"Nicaragua",phone:"505"},{ioc:"NED",iso2:"NL",iso:"NLD",label:"Netherlands",phone:"31"},{ioc:"NOR",iso2:"NO",iso:"NOR",label:"Norway",phone:"47"},{ioc:"NEP",iso2:"NP",iso:"NPL",label:"Nepal",phone:"977"},{ioc:"NRU",iso2:"NR",iso:"NRU",label:"Nauru",phone:"674"},{ioc:"NIU",iso2:"NU",iso:"NIU",label:"Niue",phone:"683"},{ioc:"NZL",iso2:"NZ",iso:"NZL",label:"New Zealand",phone:"64"},{ioc:"OMA",iso2:"OM",iso:"OMN",label:"Oman",phone:"968"},{ioc:"PAN",iso2:"PA",iso:"PAN",label:"Panama",phone:"507"},{ioc:"PER",iso2:"PE",iso:"PER",label:"Peru",phone:"51"},{ioc:"FPO",iso2:"PF",iso:"PYF",label:"French Polynesia",phone:"689"},{ioc:"PNG",iso2:"PG",iso:"PNG",label:"Papua New Guinea",phone:"675"},{ioc:"PHI",iso2:"PH",iso:"PHL",label:"Philippines",phone:"63"},{ioc:"PAK",iso2:"PK",iso:"PAK",label:"Pakistan",phone:"92"},{ioc:"POL",iso2:"PL",iso:"POL",label:"Poland",phone:"48"},{ioc:"SPM",iso2:"PM",iso:"SPM",label:"Saint Pierre and Miquelon",phone:"508"},{ioc:"",iso2:"PN",iso:"PCN",label:"Pitcairn",phone:"870"},{ioc:"PUR",iso2:"PR",iso:"PRI",label:"Puerto Rico",phone:"1"},{ioc:"PLE",iso2:"PS",iso:"PSE",label:"Palestine, State of",phone:"970"},{ioc:"POR",iso2:"PT",iso:"PRT",label:"Portugal",phone:"351"},{ioc:"PLW",iso2:"PW",iso:"PLW",label:"Palau",phone:"680"},{ioc:"PAR",iso2:"PY",iso:"PRY",label:"Paraguay",phone:"595"},{ioc:"QAT",iso2:"QA",iso:"QAT",label:"Qatar",phone:"974"},{ioc:"REU",iso2:"RE",iso:"REU",label:"Reunion",phone:"262"},{ioc:"ROU",iso2:"RO",iso:"ROU",label:"Romania",phone:"40"},{ioc:"SRB",iso2:"RS",iso:"SRB",label:"Serbia",phone:"381"},{ioc:"RUS",iso2:"RU",iso:"RUS",label:"Russia",phone:"7"},{ioc:"RWA",iso2:"RW",iso:"RWA",label:"Rwanda",phone:"250"},{ioc:"KSA",iso2:"SA",iso:"SAU",label:"Saudi Arabia",phone:"966"},{ioc:"SOL",iso2:"SB",iso:"SLB",label:"Solomon Islands",phone:"677"},{ioc:"SEY",iso2:"SC",iso:"SYC",label:"Seychelles",phone:"248"},{ioc:"SUD",iso2:"SD",iso:"SDN",label:"Sudan",phone:"249"},{ioc:"SWE",iso2:"SE",iso:"SWE",label:"Sweden",phone:"46"},{ioc:"SIN",iso2:"SG",iso:"SGP",label:"Singapore",phone:"65"},{ioc:"HEL",iso2:"SH",iso:"SHN",label:"Saint Helena",phone:"290"},{ioc:"SLO",iso2:"SI",iso:"SVN",label:"Slovenia",phone:"386"},{ioc:"",iso2:"SJ",iso:"SJM",label:"Svalbard and Jan Mayen",phone:"47"},{ioc:"SVK",iso2:"SK",iso:"SVK",label:"Slovakia",phone:"421"},{ioc:"SLE",iso2:"SL",iso:"SLE",label:"Sierra Leone",phone:"232"},{ioc:"SMR",iso2:"SM",iso:"SMR",label:"San Marino",phone:"378"},{ioc:"SEN",iso2:"SN",iso:"SEN",label:"Senegal",phone:"221"},{ioc:"SOM",iso2:"SO",iso:"SOM",label:"Somalia",phone:"252"},{ioc:"SUR",iso2:"SR",iso:"SUR",label:"Suriname",phone:"597"},{ioc:"",iso2:"SS",iso:"SSD",label:"South Sudan",phone:"211"},{ioc:"STP",iso2:"ST",iso:"STP",label:"Sao Tome and Principe",phone:"239"},{ioc:"ESA",iso2:"SV",iso:"SLV",label:"El Salvador",phone:"503"},{ioc:"",iso2:"SX",iso:"SMX",label:"Sint Maarten",phone:"1-721"},{ioc:"SYR",iso2:"SY",iso:"SYR",label:"Syria",phone:"963"},{ioc:"",iso2:"SZ",iso:"SWZ",label:"Swaziland",phone:"268"},{ioc:"TKS",iso2:"TC",iso:"TCA",label:"Turks and Caicos Islands",phone:"1-649"},{ioc:"CHA",iso2:"TD",iso:"TCD",label:"Chad",phone:"235"},{ioc:"",iso2:"TF",iso:"ATF",label:"French Southern Territories",phone:"262"},{ioc:"TOG",iso2:"TG",iso:"TGO",label:"Togo",phone:"228"},{ioc:"THA",iso2:"TH",iso:"THA",label:"Thailand",phone:"66"},{ioc:"TJK",iso2:"TJ",iso:"TJK",label:"Tajikistan",phone:"992"},{ioc:"",iso2:"TK",iso:"TKL",label:"Tokelau",phone:"690"},{ioc:"TLS",iso2:"TL",iso:"TLS",label:"Timor-Leste",phone:"670"},{ioc:"TKM",iso2:"TM",iso:"TKM",label:"Turkmenistan",phone:"993"},{ioc:"TUN",iso2:"TN",iso:"TUN",label:"Tunisia",phone:"216"},{ioc:"TGA",iso2:"TO",iso:"TON",label:"Tonga",phone:"676"},{ioc:"TUR",iso2:"TR",iso:"TUR",label:"Turkey",phone:"90"},{ioc:"TTO",iso2:"TT",iso:"TTO",label:"Trinidad and Tobago",phone:"1-868"},{ioc:"TUV",iso2:"TV",iso:"TUV",label:"Tuvalu",phone:"688"},{ioc:"TPE",iso2:"TW",iso:"TWN",label:"Taiwan",phone:"886"},{ioc:"TAN",iso2:"TZ",iso:"TZA",label:"United Republic of Tanzania",phone:"255"},{ioc:"UKR",iso2:"UA",iso:"UKR",label:"Ukraine",phone:"380"},{ioc:"UGA",iso2:"UG",iso:"UGA",label:"Uganda",phone:"256"},{ioc:"USA",iso2:"US",label:"United States",phone:"1",suggested:!0,iso:"USA"},{ioc:"URU",iso2:"UY",iso:"URY",label:"Uruguay",phone:"598"},{ioc:"UZB",iso2:"UZ",iso:"UZB",label:"Uzbekistan",phone:"998"},{ioc:"",iso2:"VA",iso:"VAT",label:"Holy See (Vatican City State)",phone:"379"},{ioc:"VIN",iso2:"VC",iso:"VCT",label:"Saint Vincent and the Grenadines",phone:"1-784"},{ioc:"VEN",iso2:"VE",iso:"VEN",label:"Venezuela",phone:"58"},{ioc:"IVB",iso2:"VG",iso:"VGB",label:"British Virgin Islands",phone:"1-284"},{ioc:"ISV",iso2:"VI",iso:"VIR",label:"US Virgin Islands",phone:"1-340"},{ioc:"VIE",iso2:"VN",iso:"VNM",label:"Vietnam",phone:"84"},{ioc:"VAN",iso2:"VU",iso:"VUT",label:"Vanuatu",phone:"678"},{ioc:"WAF",iso2:"WF",iso:"WLF",label:"Wallis and Futuna",phone:"681"},{ioc:"SAM",iso2:"WS",iso:"WSM",label:"Samoa",phone:"685"},{ioc:"KOS",iso2:"XK",iso:"KOS",label:"Kosovo",phone:"383"},{ioc:"YEM",iso2:"YE",iso:"YEM",label:"Yemen",phone:"967"},{ioc:"MAY",iso2:"YT",iso:"MYT",label:"Mayotte",phone:"262"},{ioc:"RSA",iso2:"ZA",iso:"ZAF",label:"South Africa",phone:"27"},{ioc:"ZAM",iso2:"ZM",iso:"ZMB",label:"Zambia",phone:"260"},{ioc:"ZIM",iso2:"ZW",iso:"ZWE",label:"Zimbabwe",phone:"263"}],Us="ELO",uW="NTRP",dW="UTR",u0="WTN",vo={[Us]:{range:[0,3e3],decimalsCount:0,defaultInitialization:1500},[uW]:{range:[1,7],decimalsCount:1,defaultInitialization:3,accessor:"dntrpRatingHundredths",accessors:["ntrpRating","dntrpRatingHundredths"],attributes:{ustaRatingType:""}},[dW]:{range:[1,16],decimalsCount:2,defaultInitialization:6},[u0]:{range:[40,1],decimalsCount:2,defaultInitialization:23,accessor:"wtnRating",accessors:["wtnRating"],attributes:{confidence:{generator:!0,range:[60,100]}}}};var pW=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],fW="COLLEGE_D3",vW={valueGoal:5},mW={collectionDefinitions:pW,tieFormatName:fW,winCriteria:vW},hW=[{collectionName:"Doubles",collectionValue:1,matchUpCount:3,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES"},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],gW="COLLEGE_DEFAULT",_W={valueGoal:5},IW={collectionDefinitions:hW,tieFormatName:gW,winCriteria:_W},PW=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],yW="COLLEGE_JUCO",SW={valueGoal:5},OW={collectionDefinitions:PW,tieFormatName:yW,winCriteria:SW},bW=[{collectionName:"Doubles",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],TW="DOMINANT_DUO",wW={valueGoal:2},d0={collectionDefinitions:bW,tieFormatName:TW,winCriteria:wW},EW=[{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],$W="DOMINANT_DUO_MIXED",NW={valueGoal:2},p0={collectionDefinitions:EW,tieFormatName:$W,winCriteria:NW},UW=[{collectionGroupNumber:1,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:1},{collectionGroupNumber:1,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:1},{collectionGroupNumber:2,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:2},{collectionGroupNumber:2,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:2},{collectionGroupNumber:3,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:3},{collectionGroupNumber:3,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:3}],AW=[{groupNumber:1,groupName:"Day 1"},{groupNumber:2,groupName:"Day 2"},{groupNumber:3,groupName:"Day 3"}],CW="LAVER_CUP",MW={valueGoal:13},f0={collectionDefinitions:UW,collectionGroups:AW,tieFormatName:CW,winCriteria:MW},DW=[{collectionName:"Round 1",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Round 2",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Round 3",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],jW="Doubles Shuffle",RW=!0,FW={aggregateValue:!0},v0={collectionDefinitions:DW,tieFormatName:jW,unrestrictedSelections:RW,winCriteria:FW},xW=[{category:{ageCategoryCode:"14U"},collectionName:"14U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],LW=[{groupNumber:1,groupName:"Doubles",groupValue:1,winCriteria:{valueGoal:2}}],VW="USTA_BREWER_CUP",BW={valueGoal:4},m0={collectionDefinitions:xW,collectionGroups:LW,tieFormatName:VW,winCriteria:BW},kW={valueGoal:23},GW="USTA_OZAKI_CUP",WW=[{category:{ageCategoryCode:"18U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"18U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"18U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"18U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"18U"},collectionName:"18U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"16U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"16U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"16U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"16U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"16U"},collectionName:"16U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"14U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"14U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"14U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"14U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"14U"},collectionName:"14U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"12U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"12U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"12U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"12U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"12U"},collectionName:"12U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"12U"},collectionName:"12U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"12U"},collectionName:"12U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1}],h0={winCriteria:kW,tieFormatName:GW,collectionDefinitions:WW},HW=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",collectionValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],qW="USTA_COLLEGE",zW={valueGoal:4},g0={collectionDefinitions:HW,tieFormatName:qW,winCriteria:zW},YW=[{collectionName:"Male Singles",matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpCount:4,matchUpValue:1,gender:"MALE"},{collectionName:"Female Singles",matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:4,matchUpValue:1},{collectionName:"Male Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpCount:2,matchUpValue:1,gender:"MALE"},{collectionName:"Female Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:2,matchUpValue:1},{collectionName:"Mixed Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpCount:4,matchUpValue:1,gender:"MIXED"}],KW="USTA_GOLD_TEAM_CHALLENGE",QW={valueGoal:9},_0={collectionDefinitions:YW,tieFormatName:KW,winCriteria:QW},JW=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],ZW="USTA_INTERSECTIONAL",XW={valueGoal:8},I0={collectionDefinitions:JW,tieFormatName:ZW,winCriteria:XW},e4=[{collectionName:"Male Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],t4="USTA_LEVEL_1",r4={valueGoal:10},P0={collectionDefinitions:e4,tieFormatName:t4,winCriteria:r4},n4=[{category:{ageCategoryCode:"16U"},collectionName:"16U Singles",matchUpCount:4,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Singles",matchUpCount:4,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Doubles",matchUpCount:2,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Doubles",matchUpCount:2,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Tiebreak Doubles",matchUpCount:1,matchUpFormat:"SET1-S:TB10",matchUpType:"DOUBLES",matchUpValue:1,processCodes:["RANKING.IGNORE"]}],o4="USTA_SECTION_BATTLE",i4={valueGoal:9},y0={collectionDefinitions:n4,tieFormatName:o4,winCriteria:i4},s4=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],a4="USTA_SOUTHERN_LEVEL_5",l4={valueGoal:8},S0={collectionDefinitions:s4,tieFormatName:a4,winCriteria:l4},c4=[{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Overtime",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],u4="USTA_TOC",d4={aggregateValue:!0},O0={collectionDefinitions:c4,tieFormatName:u4,winCriteria:d4},p4=[{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Overtime",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],f4="USTA_WTT_ITT",v4={aggregateValue:!0},b0={collectionDefinitions:p4,tieFormatName:f4,winCriteria:v4},m4=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],h4="USTA_ZONAL",g4={valueGoal:10},T0={collectionDefinitions:m4,tieFormatName:h4,winCriteria:g4};const w0={COLLEGE_D3:mW,COLLEGE_DEFAULT:IW,COLLEGE_JUCO:OW,DOMINANT_DUO:d0,DOMINANT_DUO_MIXED:p0,LAVER_CUP:f0,TEAM_DOUBLES_3_AGGREGATION:v0,USTA_BREWER_CUP:m0,USTA_OZAKI_CUP:h0,USTA_COLLEGE:g0,USTA_GOLD_TEAM_CHALLENGE:_0,USTA_INTERSECTIONAL:I0,USTA_LEVEL_1:P0,USTA_SECTION_BATTLE:y0,USTA_SOUTHERN_LEVEL_5:S0,USTA_TOC:O0,USTA_WTT_ITT:b0,USTA_ZONAL:T0},_4={[$V]:{roundsToSeparate:void 0,policyName:"Nationality Code",policyAttributes:[{key:"person.nationalityCode"},{key:"individualParticipants.person.nationalityCode"}]}},I4="qualifierDrawPositionAssignment",P4="withdrawParticipantAtDrawPosition",y4="alternateDrawPositionAssignment",S4="luckyLoserDrawPositionAssignment",E0="removeDrawPositionAssignment",O4="swapDrawPositionAssignments",b4="modifyPairAssignment",T4="modifyParticipantOtherName",$0="assignMatchUpSideParticipant",N0="assignDrawPosition",w4="removeSeededParticipant",E4="assignDrawPositionBye",$4="modifySeedAssignment",U0="addPenalty",A0="MODIFY_PAIR",Cv="QUALIFIER",C0="ALTERNATE",M0="WITHDRAW",wa="ASSIGN",D0="REMOVE",j0="LUCKY",Yu="REMOVE_SEED",R0="SWAP",Ku="NICKNAME",Ea="SEED_VALUE",$a="PENALTY",Mv="BYE",F0={[To]:{policyName:"positionActionsDefault",enabledStructures:[{stages:[we,he],stageSequences:[1],enabledActions:[],disabledActions:[]},{stages:[],stageSequences:[],enabledActions:[Ku,$a,Cv,Ea],disabledActions:[]}],disbledStructures:[],otherFlightEntries:!1,activePositionOverrides:[]}},N4={[To]:{policyName:"positionActionsDisabled",enabledStructures:!1}},U4={[To]:{policyName:"positionActionsNoMovement",enabledStructures:[{stages:[],stageSequences:[],enabledActions:[Ea,Ku,$a],disabledActions:[]}]}},A4={[To]:{policyName:"positionActionsUnrestricted",enabledStructures:[],otherFlightEntries:!0,disableRoundRestrictions:!0,activePositionOverrides:[Ea,Yu]}},C4={[Tl]:{policyName:"Participant Privacy Policy",participant:{contacts:!1,individualParticipants:{onlineResources:!1,participantName:!0,participantOtherName:!0,participantId:!0,participantRole:!0,participantStatus:!0,penalties:!1,representing:!0,participantRoleResponsibilities:!1,participantType:!0,person:{addresses:!1,biographicalInformation:!1,birthDate:!1,contacts:!1,nationalityCode:!0,nativeFamilyName:!1,nativeGivenName:!1,onlineResources:!1,otherNames:!0,parentOrganisationId:!1,passportFamilyName:!1,passportGivenName:!1,personId:!1,personOtherIds:!1,previousNames:!1,sex:!1,standardFamilyName:!0,standardGivenName:!0,status:!1,tennisId:!1,wheelchair:!0}},individualParticipantIds:!0,onlineResources:!1,participantName:!0,participantOtherName:!0,participantId:!0,participantRole:!0,participantStatus:!0,penalties:!1,representing:!0,participantRoleResponsibilities:!1,participantType:!0,person:{addresses:!1,biographicalInformation:!1,birthDate:!1,contacts:!1,nationalityCode:!0,nativeFamilyName:!1,nativeGivenName:!1,onlineResources:!1,otherNames:!0,parentOrganisationId:!1,passportFamilyName:!1,passportGivenName:!1,personId:!1,personOtherIds:!1,previousNames:!1,sex:!1,standardFamilyName:!0,standardGivenName:!0,status:!1,tennisId:!1,wheelchair:!0}}}},Dv="ADULT",jv="JUNIOR",Qu="WHEELCHAIR",M4={[$f]:{defaultTimes:{averageTimes:[{categoryNames:[],minutes:{default:90}}],recoveryTimes:[{minutes:{[dt]:30,default:60}}]},defaultDailyLimits:{[At]:2,[dt]:2,total:3},matchUpAverageTimes:[{matchUpFormatCodes:["SET3-S:6/TB7"],averageTimes:[{categoryNames:[],minutes:{default:90}},{categoryTypes:[Qu],minutes:{default:120}}]},{matchUpFormatCodes:["SET3-S:6/TB7-F:TB10"],averageTimes:[{categoryNames:[],minutes:{default:85}}]},{matchUpFormatCodes:["SET3-S:6/TB7-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:70}}]},{matchUpFormatCodes:["SET3-S:4NOAD-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:55}}]},{matchUpFormatCodes:["SET3-S:4/TB7"],averageTimes:[{categoryNames:[],minutes:{default:60}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:50}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB10"],averageTimes:[{categoryNames:[],minutes:{default:55}}]},{matchUpFormatCodes:["SET3-S:4/TB5@3"],averageTimes:[{categoryNames:[],minutes:{default:45}}]},{matchUpFormatCodes:["SET1-S:8/TB7","SET1-S:8/TB7@7"],averageTimes:[{categoryNames:[],minutes:{default:40}}]},{matchUpFormatCodes:["SET1-S:5/TB9@4"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:6/TB7"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:6NOAD"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:4/TB7","SET1-S:4/TB5@3","SET3-S:TB10","SET1-S:T20"],averageTimes:[{categoryNames:[],minutes:{default:20}}]},{matchUpFormatCodes:["SET1-S:4NOAD"],averageTimes:[{categoryNames:[],minutes:{default:20}}]},{matchUpFormatCodes:["SET1-S:TB10"],averageTimes:[{categoryNames:[],minutes:{default:10}}]}],matchUpRecoveryTimes:[{matchUpFormatCodes:["SET3-S:6/TB7","SET3-S:6/TB7-F:TB10","SET3-S:6/TB7-F:TB7"],recoveryTimes:[{categoryTypes:[Dv,Qu],minutes:{default:60,[dt]:30}},{categoryTypes:[jv],minutes:{default:60,[dt]:60}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB7","SET3-S:4/TB7-F:TB10","SET3-S:4NOAD-F:TB7","SET3-S:4/TB7","SET3-S:4/TB5@3"],recoveryTimes:[{categoryTypes:[Dv,Qu],minutes:{default:30}},{categoryTypes:[jv],minutes:{default:60}}]},{matchUpFormatCodes:["SET1-S:8/TB7","SET1-S:8/TB7@7","SET1-S:5/TB9@4","SET1-S:6/TB7","SET1-S:6NOAD","SET1-S:4/TB7","SET1-S:4NOAD","SET3-S:TB10","SET1-S:T20"],recoveryTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:4/TB5@3"],recoveryTimes:[{categoryTypes:[Dv,jv],minutes:{default:30}},{categoryTypes:[Qu],minutes:{default:15}}]},{matchUpFormatCodes:["SET1-S:TB10"],recoveryTimes:[{categoryNames:[],minutes:{default:15}}]}],matchUpDailyLimits:[]}},D4={[da]:{requireAllPositionsAssigned:!1,stage:{[he]:{stageSequence:{1:{requireAllPositionsAssigned:!0}}}},defaultMatchUpFormat:"SET3-S:6/TB7",matchUpFormats:[{description:"Best of 3 tiebreak sets",matchUpFormat:"SET3-S:6/TB7",categoryNames:[],categoryTypes:[]},{description:"Two tiebreak sets, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:6/TB7-F:TB7"},{description:"Two tiebreak sets, 10-point match tiebreak at one set all",matchUpFormat:"SET3-S:6/TB7-F:TB10"},{description:"One standard tiebreak set to 6, 7-point tiebreak at 6 games all",matchUpFormat:"SET1-S:6/TB7"},{description:"Best of 3 sets to 4",matchUpFormat:"SET3-S:4/TB7"},{description:"Two out of three short sets to 4 with 5-point tiebreak at 3 games all",matchUpFormat:"SET3-S:4/TB5@3"},{description:"One short set to 4, 7-point tiebreak at 4 games all",matchUpFormat:"SET1-S:4/TB7"},{description:"One short set to 4, 5-point tiebreak at 3 games all",matchUpFormat:"SET1-S:4/TB5@3"},{description:"Two short sets to 4, 10-point match tiebreak at one set all",matchUpFormat:"SET3-S:4/TB7-F:TB10"},{description:"Two short sets to 4, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:4/TB7-F:TB7"},{description:"One no advantage set to 5, tiebreak to 9 at 4-4",matchUpFormat:"SET1-S:5/TB9@4"},{description:"One set to 6 with deciding game at 5 games all",matchUpFormat:"SET1-S:6NOAD"},{description:"One short set to 4, deciding game is played at 3 games all",matchUpFormat:"SET1-S:4NOAD"},{description:"Two short sets to 4 with deciding game at 3-3, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:4NOAD-F:TB7"},{description:"8 game pro-set with 7 point tiebreak at 8 games all",matchUpFormat:"SET1-S:8/TB7"},{description:"8 game pro-set with 7 point tiebreak at 7 games all",matchUpFormat:"SET1-S:8/TB7@7"},{description:"Best of 3 10-point tiebreak games",matchUpFormat:"SET3-S:TB10"},{description:"One 10-point tiebreak game",matchUpFormat:"SET1-S:TB10"},{description:"Timed 20 minute game - game based",matchUpFormat:"SET1-S:T20"}]}},j4={[da]:{defaultMatchUpFormat:"SET3-S:6/TB7",requireAllPositionsAssigned:!1,processCodes:{incompleteAssignmentsOnDefault:["RANKING.IGNORE"]},stage:{[he]:{stageSequence:{1:{requireAllPositionsAssigned:!0}}}}}},R4={[pa]:{seedingProfile:{positioning:rv},validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,policyName:"ITF SEEDING",seedsCountThresholds:[{drawSize:4,minimumParticipantCount:3,seedsCount:2},{drawSize:16,minimumParticipantCount:12,seedsCount:4},{drawSize:32,minimumParticipantCount:24,seedsCount:8},{drawSize:64,minimumParticipantCount:48,seedsCount:16},{drawSize:128,minimumParticipantCount:97,seedsCount:32},{drawSize:256,minimumParticipantCount:192,seedsCount:64}]}},Rv={[pa]:{validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,seedingProfile:{positioning:vG},policyName:"USTA SEEDING",seedsCountThresholds:[{drawSize:4,minimumParticipantCount:3,seedsCount:2},{drawSize:16,minimumParticipantCount:12,seedsCount:4},{drawSize:32,minimumParticipantCount:24,seedsCount:8},{drawSize:64,minimumParticipantCount:48,seedsCount:16},{drawSize:128,minimumParticipantCount:96,seedsCount:32},{drawSize:256,minimumParticipantCount:192,seedsCount:64}]}},F4={ratingsParameters:vo,matchUpFormats:fV,countryToFlag:c0,tieFormats:w0,countries:ii,policies:{POLICY_AVOIDANCE_COUNTRY:_4,POLICY_POSITION_ACTIONS_DEFAULT:F0,POLICY_POSITION_ACTIONS_DISABLED:N4,POLICY_POSITION_ACTIONS_NO_MOVEMENT:U4,POLICY_POSITION_ACTIONS_UNRESTRICTED:A4,POLICY_PRIVACY_DEFAULT:C4,POLICY_ROUND_NAMING_DEFAULT:ly,POLICY_SCHEDULING_USTA:M4,POLICY_SCORING_DEFAULT:j4,POLICY_SCORING_USTA:D4,POLICY_SEEDING_ITF:R4,POLICY_SEEDING_USTA:Rv},flagIOC:cW};function Na({collectionDefinitions:t=[],collectionGroups:e=[]}){let r=0;const{groupValueNumbers:n}=vy({collectionGroups:e});let o;for(const s of t||[]){const{collectionValueProfiles:a,collectionGroupNumber:l,collectionValue:c,matchUpCount:u,matchUpValue:p,scoreValue:d,setValue:v}=s,f=l&&n.includes(l);if(v||d)o=!0;else{if(f)continue;if(c)r+=c;else if(a!=null&&a.length)for(const m of a)r+=m.matchUpValue;else p?r+=(u||0)*p:r+=u||0}}for(const s of e)r+=s.groupValue||0;return o||!r?{aggregateValue:!0}:{valueGoal:Math.floor(r/2)+1}}function Ju({participant:t,withISO2:e,withIOC:r}){const{person:n,individualParticipants:o}=t,i=[n,o==null?void 0:o.map(({person:a})=>a)].flat().filter(Boolean);function s(a){const{nationalityCode:l}=a||{};if(l){const c=ii.find(({iso:u})=>u===l);r&&(c!=null&&c.ioc)&&!a.iocNationalityCode&&(a.iocNationalityCode=c.ioc),e&&(c!=null&&c.iso2)&&!a.iso2NationalityCode&&(a.iso2NationalityCode=c.iso2),c!=null&&c.label&&!a.countryName&&(a.countryName=c.label)}}i.forEach(s)}var x4=Object.defineProperty,x0=Object.getOwnPropertySymbols,L4=Object.prototype.hasOwnProperty,V4=Object.prototype.propertyIsEnumerable,L0=(t,e,r)=>e in t?x4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,B4=(t,e)=>{for(var r in e||(e={}))L4.call(e,r)&&L0(t,r,e[r]);if(x0)for(var r of x0(e))V4.call(e,r)&&L0(t,r,e[r]);return t};function Un({returnPreviousValues:t,itemSubTypes:e,itemType:r,element:n}){if(!n)return{error:_e,info:Vf};if(e&&!Array.isArray(e))return{error:X,context:{itemSubTypes:e}};if(!Array.isArray(n.timeItems))return{error:g_};const o=n.timeItems.filter(s=>(s==null?void 0:s.itemType)===r).filter(s=>!(e!=null&&e.length)||e.some(a=>{var l;return(l=s==null?void 0:s.itemSubTypes)==null?void 0:l.includes(a)})).sort((s,a)=>{const l=new Date(s.createdAt||void 0).getTime(),c=new Date(a.createdAt||void 0).getTime();return l-c}),i=o.pop();if(i){const s=B4({timeItem:i},V);return t&&Object.assign(s,{previousItems:o}),s}else return{info:sr}}function k4({returnPreviousValues:t,drawDefinition:e,itemSubTypes:r,itemType:n}){if(!e)return{error:kr};if(!e.timeItems)return{info:sr};const{timeItem:o,previousItems:i,info:s}=Un({element:e,returnPreviousValues:t,itemSubTypes:r,itemType:n});return o&&{timeItem:o,previousItems:i}||{info:s}}function jo({returnPreviousValues:t,itemSubTypes:e,itemType:r,event:n}){if(!n)return{error:Ge};if(!n.timeItems)return{info:sr};const{timeItem:o,previousItems:i,info:s}=Un({returnPreviousValues:t,element:n,itemSubTypes:e,itemType:r});return o&&{timeItem:o,previousItems:i}||{info:s}}function Zu({returnPreviousValues:t,tournamentRecord:e,itemSubTypes:r,itemType:n}){if(!e)return{error:re};if(!e.timeItems)return{info:sr};const{timeItem:o,previousItems:i,info:s}=Un({element:e,returnPreviousValues:t,itemSubTypes:r,itemType:n});return o&&{timeItem:o,previousItems:i}||{info:s}}function G4({returnPreviousValues:t,tournamentRecord:e,participantId:r,itemSubTypes:n,itemType:o}){if(!e)return{error:re};if(!r)return{error:Et};const i=Qo({tournamentRecord:e,participantId:r});if(i.error)return i;const{participant:s}=i;if(!(s!=null&&s.timeItems))return{info:sr};const{timeItem:a,previousItems:l,info:c}=Un({element:i.participant,returnPreviousValues:t,itemSubTypes:n,itemType:o});return a&&{timeItem:a,previousItems:l}||{info:c}}var W4=Object.defineProperty,V0=Object.getOwnPropertySymbols,H4=Object.prototype.hasOwnProperty,q4=Object.prototype.propertyIsEnumerable,B0=(t,e,r)=>e in t?W4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xu=(t,e)=>{for(var r in e||(e={}))H4.call(e,r)&&B0(t,r,e[r]);if(V0)for(var r of V0(e))q4.call(e,r)&&B0(t,r,e[r]);return t};const z4={[Mr]:"groupParticipantIds",[Ce]:"pairParticipantIds",[tt]:"teamParticipantIds"},Y4={[Mr]:"groups",[tt]:"teams"};function k0({withIndividualParticipants:t,convertExtensions:e,policyDefinitions:r,tournamentRecord:n,withSignInStatus:o,withScaleValues:i,internalUse:s,withISO2:a,withIOC:l}){const c=r==null?void 0:r[Tl],u=c==null?void 0:c.participant,p={};for(const d of n.participants||[]){const v=d==null?void 0:d.participantId;v&&Z4({participantMap:p,participantId:v})}for(const d of n.participants||[]){const v=de(d,e,s),f=u?iu({template:c.participant,source:v}):v,{participantId:m,individualParticipantIds:h,participantType:g}=f;if(Object.assign(p[m].participant,f),h&&J4({individualParticipantIds:h,filteredParticipant:f,participantMap:p,participantType:g,participantId:m}),o&&(p[m].participant.signedIn=K4(v)),i){const{ratings:_,rankings:I,seedings:P}=ha({participant:v});p[m].participant.seedings=P,p[m].participant.rankings=I,p[m].participant.ratings=_}(l||a)&&Ju({participant:p[m].participant,withISO2:a,withIOC:l})}return t&&Q4({participantMap:p}),{participantMap:p}}function K4(t){const{timeItem:e}=Un({itemType:xl,element:t});return(e==null?void 0:e.itemValue)===Ll}function Q4({participantMap:t}){var e;const r=Object.values(t);for(const n of r){const o=n.participant;if((e=o.individualParticipantIds)!=null&&e.length){o.individualParticipants=[];for(const i of o.individualParticipantIds)o.individualParticipants.push(t[i].participant)}}}function J4({individualParticipantIds:t,filteredParticipant:e,participantMap:r,participantType:n,participantId:o}){for(const i of t){const s=r[i].participant;if(s[z4[n]].push(o),[tt,Mr].includes(n)){const{participantRoleResponsibilities:a,participantOtherName:l,participantName:c,participantId:u,teamId:p}=e,d=Y4[n];s[d].push({participantRoleResponsibilities:a,participantOtherName:l,participantName:c,participantId:u,teamId:p})}if(n===Ce){const a=t.find(l=>l!==i);r[i].pairIdMap[o]=a,r[i].pairIdMap[a]=o}}}function Z4({participantMap:t,participantId:e}){if(t[e])return;const r={walkoverWins:0,defaultWins:0,walkovers:0,defaults:0,losses:0,wins:0};t[e]={structureParticipation:{},potentialMatchUps:{},scheduleConflicts:[],scheduleItems:[],participant:{groupParticipantIds:[],pairParticipantIds:[],teamParticipantIds:[],groups:[],teams:[]},statistics:{},opponents:{},pairIdMap:{},matchUps:{},events:{},draws:{},counters:Xu({[At]:Xu({},r),[dt]:Xu({},r),[tt]:Xu({},r)},r)}}var X4=Object.defineProperty,eH=Object.defineProperties,tH=Object.getOwnPropertyDescriptors,G0=Object.getOwnPropertySymbols,rH=Object.prototype.hasOwnProperty,nH=Object.prototype.propertyIsEnumerable,W0=(t,e,r)=>e in t?X4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Fv=(t,e)=>{for(var r in e||(e={}))rH.call(e,r)&&W0(t,r,e[r]);if(G0)for(var r of G0(e))nH.call(e,r)&&W0(t,r,e[r]);return t},oH=(t,e)=>eH(t,tH(e));function As({participantsProfile:t,useParticipantMap:e,policyDefinitions:r,tournamentRecord:n,contextProfile:o,inContext:i}){var s;if(e)return{participantMap:(s=k0(oH(Fv(Fv({},t),o),{policyDefinitions:r,tournamentRecord:n})))==null?void 0:s.participantMap};let a=de(n.participants,!1,!0)||[];if((t!=null&&t.withIOC||t!=null&&t.withISO2)&&a.forEach(l=>Ju(Fv({participant:l},t))),(i||t!=null&&t.withGroupings)&&(a!=null&&a.length)&&(a=mv({participantsProfile:t,participants:a})),t!=null&&t.withScaleValues&&(a!=null&&a.length))for(const l of a){const{ratings:c,rankings:u}=ha({participant:l});l.rankings=u,l.ratings=c}return{participants:a}}var iH=Object.defineProperty,sH=Object.defineProperties,aH=Object.getOwnPropertyDescriptors,H0=Object.getOwnPropertySymbols,lH=Object.prototype.hasOwnProperty,cH=Object.prototype.propertyIsEnumerable,q0=(t,e,r)=>e in t?iH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,si=(t,e)=>{for(var r in e||(e={}))lH.call(e,r)&&q0(t,r,e[r]);if(H0)for(var r of H0(e))cH.call(e,r)&&q0(t,r,e[r]);return t},z0=(t,e)=>sH(t,aH(e));function Wt(t){var e,r,n;if(!(t!=null&&t.tournamentRecord))return{error:re};let{participantMap:o,participants:i}=t;const{scheduleVisibilityFilters:s,participantsProfile:a,afterRecoveryTimes:l,useParticipantMap:c,policyDefinitions:u,tournamentRecord:p,inContext:d=!0,contextProfile:v,matchUpFilters:f,contextFilters:m,nextMatchUps:h,context:g}=t,_=(e=t.tournamentId)!=null?e:p.tournamentId,I=(r=p==null?void 0:p.events)!=null?r:[];i||({participants:i,participantMap:o}=As({participantsProfile:a,policyDefinitions:u,useParticipantMap:c,tournamentRecord:p,contextProfile:v,inContext:d}));const{appliedPolicies:P}=pt({tournamentRecord:p}),y=z0(si({},g),{tournamentId:_,indoorOutDoor:p.indoorOutdoor,surfaceCategory:p.surfaceCategory,endDate:p.endDate}),S=wo({policyDefinitions:u,tournamentRecord:p,contextProfile:v});return{matchUps:I.flatMap(b=>{var w,T,$;return y.eventDrawsCount=(T=(w=b.drawDefinitions)==null?void 0:w.length)!=null?T:0,($=ai({context:y,scheduleVisibilityFilters:s,tournamentAppliedPolicies:P,participantsProfile:a,afterRecoveryTimes:l,policyDefinitions:u,tournamentRecord:p,contextContent:S,contextFilters:m,contextProfile:v,matchUpFilters:f,participantMap:o,nextMatchUps:h,participants:i,inContext:d,event:b}).matchUps)!=null?$:[]}).concat(...(n=p.matchUps)!=null?n:[])}}function zr(t){var e,r;let{participants:n,participantMap:o,contextContent:i}=t;const{scheduleVisibilityFilters:s,tournamentAppliedPolicies:a,participantsProfile:l,afterRecoveryTimes:c,policyDefinitions:u,useParticipantMap:p,tournamentRecord:d,contextFilters:v,contextProfile:f,drawDefinition:m,matchUpFilters:h,nextMatchUps:g,inContext:_,context:I,event:P}=t,{eventId:y,eventName:S,eventType:O,category:b,gender:w,matchUpFormat:T}=P??{},$=z0(si({},I),{eventId:y,eventType:O,eventName:S,category:b,gender:w,matchUpFormat:T,indoorOutDoor:(e=P==null?void 0:P.indoorOutdoor)!=null?e:d==null?void 0:d.indoorOutdoor,surfaceCategory:(r=P==null?void 0:P.surfaceCategory)!=null?r:d==null?void 0:d.surfaceCategory,endDate:P==null?void 0:P.endDate});return!(n!=null&&n.length)&&!o&&d&&({participants:n=[],participantMap:o}=As({participantsProfile:l,useParticipantMap:p,policyDefinitions:u,tournamentRecord:d,contextProfile:f,inContext:_})),f&&!i&&(i=wo({policyDefinitions:u,tournamentRecord:d,contextProfile:f,drawDefinition:m,event:P})),Lt({context:$,tournamentAppliedPolicies:a,scheduleVisibilityFilters:s,tournamentParticipants:n,participantsProfile:l,afterRecoveryTimes:c,policyDefinitions:u,tournamentRecord:d,drawDefinition:m,contextContent:i,contextFilters:v,contextProfile:f,matchUpFilters:h,participantMap:o,nextMatchUps:g,inContext:_,event:P})}function ai(t){var e,r,n,o,i;let{participants:s=[],contextContent:a,participantMap:l}=t;const{scheduleVisibilityFilters:c,tournamentAppliedPolicies:u,participantsProfile:p,afterRecoveryTimes:d,policyDefinitions:v,useParticipantMap:f,tournamentRecord:m,contextFilters:h,contextProfile:g,matchUpFilters:_,nextMatchUps:I,inContext:P,context:y,event:S}=t;if(!S)return{error:Ge};const{eventId:O,eventName:b,endDate:w,category:T,gender:$,matchUpFormat:N}=S,E=[],A=si(si({},y),Oe({indoorOutDoor:(e=S.indoorOutdoor)!=null?e:m==null?void 0:m.indoorOutdoor,surfaceCategory:(r=S.surfaceCategory)!=null?r:m==null?void 0:m.surfaceCategory,endDate:(n=S.endDate)!=null?n:m==null?void 0:m.endDate,tournamentId:m==null?void 0:m.tournamentId,matchUpFormat:N,eventName:b,category:T,gender:$,eventId:O}));if(w&&(A.endDate=w),g&&!a&&(a=wo({policyDefinitions:v,tournamentRecord:m,contextProfile:g,event:S})),!(s!=null&&s.length)&&!l&&m){const D=As({participantsProfile:p,useParticipantMap:f,policyDefinitions:v,tournamentRecord:m,contextProfile:g,inContext:P});l=D.participantMap,s=(o=D.participants)!=null?o:[]}const U=(i=S.drawDefinitions)!=null?i:[],C=Cl({tournamentRecord:m,event:S}).scheduleTiming;return{matchUps:U.flatMap(D=>{const{matchUps:R,matchUpsMap:j}=Lt({tournamentParticipants:s,tournamentAppliedPolicies:u,scheduleVisibilityFilters:c,context:A,participantsProfile:p,afterRecoveryTimes:d,policyDefinitions:v,tournamentRecord:m,contextFilters:h,contextProfile:g,drawDefinition:D,contextContent:a,matchUpFilters:_,participantMap:l,scheduleTiming:C,nextMatchUps:I,inContext:P,event:S});return j!=null&&j.drawMatchUps&&E.push(...j.drawMatchUps),R??[]}),eventMatchUps:E}}function Y0(t){var e,r,n;if(!(t!=null&&t.tournamentRecord))return{error:re};let o=t.contextContent;const{scheduleVisibilityFilters:i,participantsProfile:s,afterRecoveryTimes:a,policyDefinitions:l,useParticipantMap:c,tournamentRecord:u,inContext:p=!0,contextFilters:d,contextProfile:v,matchUpFilters:f,nextMatchUps:m,context:h}=t,g=(e=t.tournamentId)!=null?e:u.tournamentId,_=(r=u==null?void 0:u.events)!=null?r:[],{participants:I,participantMap:P}=As({participantsProfile:s,policyDefinitions:l,useParticipantMap:c,tournamentRecord:u,contextProfile:v,inContext:p});v&&!o&&(o=wo({policyDefinitions:l,tournamentRecord:u,contextProfile:v}));const{appliedPolicies:y}=pt({tournamentRecord:u}),S=(n=d==null?void 0:d.eventIds)!=null?n:[];return _.filter(b=>!S.includes(b.eventId)).map(b=>{var w,T;const $=Nt({event:b}).flightProfile,N=si({eventDrawsCount:((w=$==null?void 0:$.flights)==null?void 0:w.length)||((T=b.drawDefinitions)==null?void 0:T.length)||0},h);return K0({context:N,tournamentAppliedPolicies:y,scheduleVisibilityFilters:i,participantsProfile:s,afterRecoveryTimes:a,policyDefinitions:l,tournamentRecord:u,contextFilters:d,contextProfile:v,contextContent:o,matchUpFilters:f,participantMap:P,participants:I,tournamentId:g,nextMatchUps:m,inContext:p,event:b})}).reduce((b,w)=>{const T=w&&Object.keys(w).filter($=>!["success","matchUpsMap"].includes($));return T==null||T.forEach($=>{b[$]||(b[$]=[]),b[$]=b[$].concat(w[$]),b.matchUpsCount+=w[$].length}),b},{matchUpsCount:0})}function K0(t){var e,r,n;let{participants:o,contextContent:i,participantMap:s}=t;const{tournamentAppliedPolicies:a,scheduleVisibilityFilters:l,participantsProfile:c,afterRecoveryTimes:u,policyDefinitions:p,useParticipantMap:d,tournamentRecord:v,contextFilters:f,contextProfile:m,matchUpFilters:h,nextMatchUps:g,tournamentId:_,inContext:I,context:P,event:y}=t;if(!y)return{error:Ge};const{eventId:S,eventName:O,endDate:b}=y,w=si(si({},P),Oe({eventId:S,eventName:O,endDate:b??(v==null?void 0:v.endDate),tournamentId:_??(v==null?void 0:v.tournamentId),indoorOutDoor:(e=y.indoorOutdoor)!=null?e:v==null?void 0:v.indoorOutdoor,surfaceCategory:(r=y.surfaceCategory)!=null?r:v==null?void 0:v.surfaceCategory}));return!o&&v&&({participants:o,participantMap:s}=As({participantsProfile:c,policyDefinitions:p,useParticipantMap:d,tournamentRecord:v,contextProfile:m,inContext:I})),m&&!i&&(i=wo({policyDefinitions:p,tournamentRecord:v,contextProfile:m,event:y})),((n=y.drawDefinitions)!=null?n:[]).reduce(($,N)=>{const E=ws({context:w,tournamentAppliedPolicies:a,scheduleVisibilityFilters:l,tournamentParticipants:o,participantsProfile:c,afterRecoveryTimes:u,policyDefinitions:p,tournamentRecord:v,drawDefinition:N,contextContent:i,contextFilters:f,contextProfile:m,matchUpFilters:h,participantMap:s,nextMatchUps:g,inContext:I,event:y}),A=Object.keys(E);return A==null||A.forEach(U=>{$[U]||($[U]=[]),$[U]=$[U].concat(E[U])}),$},{})}function uH({participants:t,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextFilters:l,contextProfile:c,contextContent:u,drawDefinition:p,matchUpFilters:d,participantMap:v,nextMatchUps:f,tournamentId:m,inContext:h,context:g,event:_}){var I,P,y;const{eventId:S,eventName:O,endDate:b}=_??{},w=si(si({},g),Oe({eventId:S,eventName:O,endDate:(I=b??(_==null?void 0:_.endDate))!=null?I:a==null?void 0:a.endDate,tournamentId:m??(a==null?void 0:a.tournamentId),indoorOutDoor:(P=_==null?void 0:_.indoorOutdoor)!=null?P:a==null?void 0:a.indoorOutdoor,surfaceCategory:(y=_==null?void 0:_.surfaceCategory)!=null?y:a==null?void 0:a.surfaceCategory}));return!(t!=null&&t.length)&&a&&({participants:t,participantMap:v}=As({participantsProfile:n,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextProfile:c,inContext:h})),_&&c&&!u&&(u=wo({policyDefinitions:i,tournamentRecord:a,contextProfile:c,drawDefinition:p,event:_})),ws({context:w,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,tournamentParticipants:t,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:a,participantMap:v,drawDefinition:p,matchUpFilters:d,contextFilters:l,contextProfile:c,contextContent:u,nextMatchUps:f,inContext:h,event:_})}function ac({finishingPositionOffset:t=0,finishingPositionLimit:e,positionsFed:r,roundsCount:n,roundLimit:o,matchUps:i,lucky:s,fmlc:a}){var l;if(!Array.isArray(i))return[];const{roundProfile:c,roundNumbers:u=[]}=Tr({interpolate:!0,matchUps:i});n=n||Math.max(...u,0);const p=o?n-o:0,d=p&&((l=c==null?void 0:c[n-p])==null?void 0:l.matchUpsCount),v=c&&Object.values(c).map(Fn("matchUpsCount")),f=(g,_)=>{let I=Math.min(...g);d&&_&&I===1&&(I=d);let P=Math.max(...g);return e&&P>e&&(P=e),[I,P]},m=c&&Object.assign({},...u.map(g=>{const _=(n||0)+1-g-p,I=c[g].matchUpsCount,P={finishingPositionRange:{},finishingRound:_},y=v==null?void 0:v.slice(g-1).reduce((E,A)=>E+(A||0),0),S=a&&g!==1,O=1+t+(S&&r||0),b=1,w=ce(O,s?O+I*2:y+O+b),T=y+b-I,$=f(w.slice(T)),N=f(w.slice(0,T),!0);return P.finishingPositionRange={loser:$,winner:N},{[g]:P}})),h=zt({finishingRound:!0});return i.filter(Boolean).forEach(g=>{const _=g.roundNumber&&m[g.roundNumber];h&&!_&&console.log({roundFinishingData:m,matchUp:g}),g.finishingRound=_==null?void 0:_.finishingRound,g.finishingPositionRange=_==null?void 0:_.finishingPositionRange}),i}function Ua({inContextDrawMatchUps:t,drawDefinition:e,matchUpsMap:r}){var n;if(!e)return{error:ue};const o={loserMatchUpIds:{},winnerMatchUpIds:{}};if(t||({matchUps:t,matchUpsMap:r}=Lt({inContext:!0,drawDefinition:e,matchUpsMap:r})),!(r==null?void 0:r.drawMatchUps.some(s=>s.finishingPositionRange))&&((n=e==null?void 0:e.structures)==null?void 0:n.length)===1&&!(e!=null&&e.structures[0].structures)){const s=(r==null?void 0:r.drawMatchUps)||[];ac({matchUps:s})}return(t||[]).filter(({collectionId:s})=>!s).forEach(s=>{const{matchUpId:a,structureId:l}=s,c=Ir({inContextDrawMatchUps:t,drawDefinition:e,matchUpId:a}),{winnerMatchUp:u,loserMatchUp:p}=c.targetMatchUps,d=u==null?void 0:u.matchUpId,v=p==null?void 0:p.matchUpId,m=xi({matchUpsMap:r,structureId:l}).find(h=>h.matchUpId===a);if(m&&(d&&(o.winnerMatchUpIds[m.matchUpId]=d,Object.assign(m,{winnerMatchUpId:d}),Object.assign(s,{winnerMatchUpId:d})),v&&(o.loserMatchUpIds[m.matchUpId]=v,s.loserMatchUpId=v,m.loserMatchUpId=v,s.finishingPositionRange))){const h=p.finishingPositionRange&&[...s.finishingPositionRange.loser,...p.finishingPositionRange.loser],g=h&&[Math.min(...h),Math.max(...h)];s.finishingPositionRange.loser=g,m.finishingPositionRange.loser=g}}),{inContextDrawMatchUps:t,goesToMap:o}}function ed(t){var e;const{sides:r,matchUpType:n}=t||{},o=(e=t.potentialParticipants)!=null&&e.length?t.potentialParticipants.flat().map(a=>n===dt?(a==null?void 0:a.individualParticipantIds)||[]:a.participantId).flat():[],i=(r||[]).map(a=>{var l;return n===dt&&(((l=a==null?void 0:a.participant)==null?void 0:l.individualParticipantIds)||[])||(a==null?void 0:a.participantId)&&[a.participantId]||[]}).flat();return{individualParticipantIds:i.concat(o).flat(),enteredIndividualParticipantIds:i,potentialIndividualParticipantIds:o}}function Ro({scheduleVisibilityFilters:t,afterRecoveryTimes:e,participantsProfile:r,tournamentRecords:n,policyDefinitions:o,matchUpFilters:i,contextFilters:s,nextMatchUps:a,inContext:l}){return typeof n!="object"||!Object.keys(n).length?{error:ke}:{matchUps:Object.keys(n).map(p=>{var d;const v=n[p];return(d=Wt({scheduleVisibilityFilters:t,afterRecoveryTimes:e,participantsProfile:r,policyDefinitions:o,tournamentRecord:v,matchUpFilters:i,contextFilters:s,nextMatchUps:a,inContext:l}).matchUps)!=null?d:[]}).flat()}}function xv({scheduleVisibilityFilters:t,participantsProfile:e,tournamentRecords:r,policyDefinitions:n,matchUpFilters:o,contextFilters:i,nextMatchUps:s,inContext:a}){return typeof r!="object"||!Object.keys(r).length?{error:ke}:Object.keys(r).map(u=>{const p=r[u];return Y0({scheduleVisibilityFilters:t,participantsProfile:e,policyDefinitions:n,tournamentRecord:p,matchUpFilters:o,contextFilters:i,nextMatchUps:s,inContext:a})}).reduce((u,p)=>(Object.keys(p).forEach(v=>{u[v]||(u[v]=[]),u[v]=u[v].concat(p[v])}),u),{})}function Cs(t,e){return dH(t,e)||((t==null?void 0:t.stageSequence)||0)-((e==null?void 0:e.stageSequence)||0)||(t==null?void 0:t.roundNumber)&&e.roundNumber&&(t==null?void 0:t.roundNumber)-(e==null?void 0:e.roundNumber)||((t==null?void 0:t.roundPosition)||0)-((e==null?void 0:e.roundPosition)||0)}function dH(t,e){return(_s[t==null?void 0:t.stage]||0)-(_s[e==null?void 0:e.stage]||0)}var pH=Object.defineProperty,Q0=Object.getOwnPropertySymbols,fH=Object.prototype.hasOwnProperty,vH=Object.prototype.propertyIsEnumerable,J0=(t,e,r)=>e in t?pH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mH=(t,e)=>{for(var r in e||(e={}))fH.call(e,r)&&J0(t,r,e[r]);if(Q0)for(var r of Q0(e))vH.call(e,r)&&J0(t,r,e[r]);return t};function cn(t){var e,r,n,o;let i=(e=t.tournamentRecords)!=null?e:{};const s=(r=t.matchUps)!=null?r:[];let a=(n=t.drawIds)!=null?n:[];const{includeParticipantDependencies:l,tournamentRecord:c,drawDefinition:u}=t;if(!Array.isArray(s))return{error:ko};if(!Array.isArray(a))return{error:kr};const p=(o=t.matchUpIds)!=null&&o.length?t.matchUpIds:s.map(O=>O.matchUpId);if(!Array.isArray(p))return{error:vl};const d={},v={},f={},m={};c&&!Object.keys(i).length&&(i={[c.tournamentId]:c});const h=Object.values(i),_=h.reduce((O,b)=>O.concat(b.events||[]).map(w=>(w.drawDefinitions||[]).map(T=>T.links||[])).flat(1/0),[]).filter(({linkType:O})=>O===Ci);let I=s;if(_.length){I=Ro({nextMatchUps:!0,tournamentRecords:i}).matchUps;const O=_.reduce((b,w)=>{var T,$;const N=(T=w.source)==null?void 0:T.structureId,E=($=w.target)==null?void 0:$.structureId;return N&&E&&(f[E]=N),N&&!b.includes(N)&&b.push(N),b},[]);for(const b of O)d[b]=[];for(const b of I||[]){const w=b.containerStructureId||b.structureId;O.includes(w)&&d[w].push(b.matchUpId)}}const P=O=>{v[O]||(v[O]={dependentMatchUpIds:[],participantIds:[],matchUpIds:[],sources:[]},m[O]=[])},y=(O,b)=>{v[O].matchUpIds.forEach(T=>{v[b].matchUpIds.push(T)}),v[b].matchUpIds.push(O),v[O].dependentMatchUpIds.push(b),l&&v[O].participantIds.forEach(T=>v[b].participantIds.push(T))},S=O=>{const b=Object.keys(d).length;for(const w of O||[]){const{matchUpId:T,winnerMatchUpId:$,loserMatchUpId:N}=w;if(!p.length||p.includes(T)){if(P(T),l){const{individualParticipantIds:U}=ed(w);v[T].participantIds=U}$&&(P($),y(T,$),m[$].push(T)),N&&(P(N),y(T,N),m[N].push(T)),v[T].sources.push(m[T]);const E=m[T].map(U=>v[U].sources[0]).flat(),A=m[T].map(U=>v[U].sources[1]).flat();if(v[T].sources.push(E,A),b){const U=w.containerStructureId||w.structureId,C=f[U];if(d[C])for(const M of d[C])P(M),y(M,T),m[M].push(T)}}}};if(u)Ua({drawDefinition:u}),I!=null&&I.length||(I=zr({drawDefinition:u}).matchUps),S(I);else{if(I!=null&&I.length||(I=Ro({nextMatchUps:!0,tournamentRecords:i}).matchUps),!a.length){const O=h!=null&&h.length?h.map(({events:b=[]})=>b.map(({drawDefinitions:w=[]})=>w.map(({drawId:T})=>T))).flat(1/0):[];O&&(a=O)}for(const O of a){const b=I==null?void 0:I.filter(T=>T.drawId===O).sort(Cs);if(!(b==null?void 0:b.find(({roundPosition:T})=>!T))){const T=b==null?void 0:b.find(({tournamentId:N})=>N),{drawDefinition:$}=Qt({tournamentRecord:i[T==null?void 0:T.tournamentId],drawId:O});$&&Ua({drawDefinition:$})}S(b)}}return mH({positionDependencies:d,matchUpDependencies:v,sourceMatchUpIds:m,matchUps:I},V)}function Z0({tournamentRecords:t,matchUps:e}){if(!Array.isArray(e))return{error:ko};if(e.some(({matchUpId:f,hasContext:m})=>f&&!m))return{info:"matchUps must have { inContext: true, nextMatchUps: true }",error:ru};const r=Math.max(...e.map(({schedule:f})=>(f==null?void 0:f.courtOrder)||1).map(f=>Te(f))),n=ce(1,r+1).map(f=>e.filter(m=>{var h;return Te((h=m.schedule)==null?void 0:h.courtOrder)===f})),o={},i={},s={};n.flat().filter(Boolean).sort(Cs).forEach(({schedule:f})=>delete f[xf]);const l=We(e.map(({drawId:f})=>f)),c=cn({includeParticipantDependencies:!0,tournamentRecords:t,drawIds:l}).matchUpDependencies,u=n.map((f,m)=>f.reduce((h,g)=>{if(!g.matchUpId)return h;const{matchUpId:_,winnerMatchUpId:I,loserMatchUpId:P,schedule:y,sides:S,potentialParticipants:O}=g,b=y==null?void 0:y.courtId;o[_]=m,i[b]=[],h.matchUpIds.push(_),s[_]=g;const w=c[_].matchUpIds;w.length&&h.sourceMatchUpIds.push(...w);const T=(S==null?void 0:S.map(N=>{var E;return[(E=N.participant)==null?void 0:E.individualParticipantIds,N.participantId]}).flat().filter(Boolean))||[],$=(O==null?void 0:O.flat().map(({individualParticipantIds:N,participantId:E})=>[N,E]).flat().filter(Boolean))||[];return h.participantIds.push(...$,...T),I&&h.targetMatchUpIds.push(I),P&&h.targetMatchUpIds.push(P),h},{sourceMatchUpIds:[],targetMatchUpIds:[],participantIds:[],matchUpIds:[]})),p=(f,m)=>c[f].sources.reduce((h,g,_)=>g.includes(m)&&_+1||h,0),d=u.map(()=>[]),v=(f,m,h,g)=>{if(!s[f].schedule[xf]){s[f].schedule[xf]=m,s[f].schedule[mB]=g,d[o[f]].push({matchUpId:f,issueType:h,issueIds:g,issue:m});const _=s[f].schedule.courtId;i[_]||(i[_]=[]),i[_].push({matchUpId:f,issue:m,issueType:h,issueIds:g})}};return u.forEach((f,m)=>{const h=m?u[m-1]:void 0,g=u.slice(m+1),_={},I=Nr(f.participantIds),P=Object.keys(I).filter(O=>I[O]>1),y=f.matchUpIds.filter(O=>c[O].participantIds.some(b=>P.includes(b)));y.forEach(O=>{_[O]||(_[O]={}),_[O][ps]||(_[O][ps]=y.filter(b=>b!==O))});const S=h&&f.participantIds.filter(O=>h.participantIds.includes(O));S&&S.forEach(O=>{const b=f.matchUpIds.concat(h.matchUpIds).filter(w=>c[w].participantIds.includes(O));b.forEach(w=>{_[w]||(_[w]={}),_[w][fs]||(_[w][fs]=b.filter(T=>T!==w))})}),f.matchUpIds.forEach(O=>{var b,w,T,$;const N=c[O].matchUpIds;for(const A of g){const U=A.matchUpIds.filter(C=>N.includes(C));U!=null&&U.length&&(U.forEach(C=>v(C,AI,wi,[O])),v(O,AI,wi,U))}if((b=_[O])!=null&&b[ps]&&v(O,ps,UI,_[O][ps]),f.sourceMatchUpIds.includes(O)){const A=f.matchUpIds.filter(U=>c[U].matchUpIds.includes(O));v(O,ps,wi,A),f.matchUpIds.filter(U=>c[U].matchUpIds.includes(O)).forEach(U=>v(U,ps,wi,[O]))}const E=(w=h==null?void 0:h.matchUpIds)==null?void 0:w.filter(A=>p(O,A)>1);if(E!=null&&E.length&&(v(O,CI,wi,E),E.forEach(A=>v(A,CI,wi,[O]))),(T=_[O])!=null&&T[fs]&&v(O,fs,UI,_[O][fs]),($=h==null?void 0:h.targetMatchUpIds)!=null&&$.includes(O)){const A=s[O].schedule.courtId,U=N.filter(M=>h.matchUpIds.includes(M));U.some(M=>s[M].schedule.courtId===A)||(U.forEach(M=>v(M,fs,wi,[O])),v(O,fs,wi,U))}})}),{courtIssues:i,rowIssues:d}}function td(t){var e;if(!t)return{};const r=[],n=t.tieFormatName,o=(e=t.collectionDefinitions)==null?void 0:e.map(i=>{const{matchUpType:s,matchUpFormat:a,matchUpCount:l,category:c,gender:u}=i;r.includes(a)||r.push(a);const p=c==null?void 0:c.ageCategoryCode;return[l,s===mn?"D":"S",p,a,u].join(";")}).join("|");return{tieFormatName:t&&n||"UNNAMED",matchUpFormats:r,tieFormatDesc:o}}var hH=Object.defineProperty,gH=Object.defineProperties,_H=Object.getOwnPropertyDescriptors,X0=Object.getOwnPropertySymbols,IH=Object.prototype.hasOwnProperty,PH=Object.prototype.propertyIsEnumerable,eS=(t,e,r)=>e in t?hH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yH=(t,e)=>{for(var r in e||(e={}))IH.call(e,r)&&eS(t,r,e[r]);if(X0)for(var r of X0(e))PH.call(e,r)&&eS(t,r,e[r]);return t},SH=(t,e)=>gH(t,_H(e));function Aa({considerations:t={},descendant:e,ancestor:r}){var n,o,i,s;const a={},l={},{matchUpFormats:c,tieFormatDesc:u}=td(e),{matchUpFormats:p,tieFormatDesc:d}=td(r),v=We((c??[]).filter(y=>!(p??[]).includes(y)).concat((p??[]).filter(y=>!(c??[]).includes(y)))),f=!!(t!=null&&t.collectionName&&e.collectionDefinitions.map(({collectionName:y})=>y).join("|")!==r.collectionDefinitions.map(({collectionName:y})=>y).join("|")),m=!!(t!=null&&t.collectionOrder&&e.collectionDefinitions.map(({collectionOrder:y})=>y).join("|")!==r.collectionDefinitions.map(({collectionOrder:y})=>y).join("|")),h=f||m||d!==u,g=Object.assign({},...((e==null?void 0:e.collectionDefinitions)||[]).map(y=>({[y.collectionId]:y}))),_=Object.assign({},...((r==null?void 0:r.collectionDefinitions)||[]).map(y=>({[y.collectionId]:y})));a.collectionIds=Lg(Object.keys(g),Object.keys(_)),l.collectionIds=Lg(Object.keys(_),Object.keys(g)),a.collectionsValue=tS(g,a),l.collectionsValue=tS(_,l),a.groupsCount=(s=(n=r==null?void 0:r.collectionGroups)==null?void 0:n.length)!=null?s:0-((i=(o=e==null?void 0:e.collectionGroups)==null?void 0:o.length)!=null?i:0)||0,l.groupsCount=a.groupsCount?-1*a.groupsCount:0;const I=a.collectionsValue.totalValue-l.collectionsValue.totalValue,P=a.collectionsValue.totalMatchUps-l.collectionsValue.totalMatchUps;return SH(yH({matchUpFormatDifferences:v,matchUpCountDifference:P,descendantDifferences:a,ancestorDifferences:l,orderDifference:m,valueDifference:I,nameDifference:f,descendantDesc:u,ancestorDesc:d},V),{different:h})}function tS(t,e){let r=0;return{totalValue:e.collectionIds.reduce((o,i)=>{const s=t[i],{collectionValueProfiles:a,collectionValue:l,matchUpCount:c,matchUpValue:u}=s;return r+=c,a?o+a.reduce((p,d)=>p+d.value,0):u&&c?o+u*c:o+l},0),totalMatchUps:r}}var OH=Object.defineProperty,rS=Object.getOwnPropertySymbols,bH=Object.prototype.hasOwnProperty,TH=Object.prototype.propertyIsEnumerable,nS=(t,e,r)=>e in t?OH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wH=(t,e)=>{for(var r in e||(e={}))bH.call(e,r)&&nS(t,r,e[r]);if(rS)for(var r of rS(e))TH.call(e,r)&&nS(t,r,e[r]);return t};function EH({tournamentRecord:t}){if(!t)return{error:re};if(typeof t!="object"||!t.tournamentId)return{error:X};const{matchUps:e}=Wt({tournamentRecord:t,inContext:!1});if(e!=null&&e.length){const r=$H({tournamentRecord:t});UH(e,r)}return wH({},V)}function $H({tournamentRecord:t}){const e={};for(const r of t.events||[]){r.matchUpFormat&&(e[r.eventId]=r.matchUpFormat);for(const n of r.drawDefinitions||[]){n.matchUpFormat&&(e[n.drawId]=n.matchUpFormat);for(const o of n.structures||[]){o.matchUpFormat&&(e[o.structureId]=o.matchUpFormat);for(const i of o.structures||[])i.matchUpFormat&&(e[i.structureId]=i.matchUpFormat)}}}return e}const NH=["collectionId","collectionPosition","drawPositions","extensions","finishingPositionRange","finishingRound","isMock","matchUpId","matchUpStatus","matchUpStatusCodes","orderOfFinish","processCodes","roundNumber","tieFormat","tieMatchUps","roundPosition","score","sides","winnerMatchUpId","loserMatchUpId","matchUpDuration","winningSide"];function UH(t,e={}){for(const r of t){const{structureId:n,drawId:o,eventId:i}=r,s=e[n]||e[o]||e[i],a=r.matchUpFormat===s?void 0:r.matchUpFormat;for(const l of Object.keys(r))NH.includes(l)||delete r[l];r.sides&&r.drawPositions&&!r.tieMatchUps&&delete r.sides,a&&(r.matchUpFormat=a)}}function lc({court:t,date:e}){const r=e&&t.dateAvailability.find(o=>io(o.date,e)),n=t.dateAvailability.find(o=>!o.date);return r||n}function Ca({includeBookingTypes:t=[],courtDate:e}){const r=[];let n=$t(e.startTime);(e.bookings||[]).filter(i=>!i.bookingType||!t.includes(i.bookingType)).sort((i,s)=>cu(i.startTime).localeCompare(cu(s.startTime))).forEach(i=>{const s={startTime:at(n.toISOString()),endTime:i.startTime};$t(i.startTime)>n&&r.push(s),$t(i.endTime)>n&&(n=$t(i.endTime))});const o={startTime:at(n.toISOString()),endTime:e.endTime};return $t(e.endTime)>n&&r.push(o),r}function AH({averageMatchUpMinutes:t,includeBookingTypes:e,periodStartTime:r,periodEndTime:n}){const o=s=>!!Ca({includeBookingTypes:e,courtDate:s}).filter(i).length;function i(s){const a=$t(s.startTime),l=$t(s.endTime);return a>r||l<n?!1:Sl(r,l)>=t}return{enoughTime:o}}function oS(t){const{averageMatchUpMinutes:e,includeBookingTypes:r,periodStart:n,date:o}=t,i=t.courts,s=$t(n),a=If(s,e),{enoughTime:l}=AH({averageMatchUpMinutes:e,includeBookingTypes:r,periodStartTime:s,periodEndTime:a});return{availableToScheduleCount:((i==null?void 0:i.filter(u=>{if(!Array.isArray(u.dateAvailability))return!1;const p=lc({date:o,court:u});return!!(p&&l(p))}))||[]).length}}function Lv(t){const{remainingScheduleTimes:e=[],clearScheduleDates:r,periodLength:n=30,scheduleDate:o,courts:i=[]}=t;let{bookings:s=[]}=t;if(!Array.isArray(i)||!i.length)return{error:X,courts:i};if(!Array.isArray(s))return{error:sf};if(!Gr(o))return{error:Sr};r&&(Array.isArray(r)?r.includes(o)&&(s=[]):s=[]);const{courtBookings:a,unassignedBookings:l}=s.reduce((v,f)=>{const{courtId:m}=f;return m?v.courtBookings[m]?v.courtBookings[m].push(f):v.courtBookings[m]=[f]:v.unassignedBookings.push(f),v},{courtBookings:{},unassignedBookings:[]}),c=i.map((v,f)=>{const{courtId:m,courtName:h}=v,g=a[m]||[],_=lc({date:o,court:v})||{},{bookings:I=[],startTime:P,endTime:y,date:S}=_,b=[e[f]&&{startTime:P,endTime:e[f]},...de(I,!1,!0),...g].filter(Boolean);return{courtId:m,courtName:h,dateAvailability:{bookings:b,startTime:P,endTime:y,date:S}}});l.sort((v,f)=>Le(v.startTime)-Le(f.startTime));const u=()=>c.map(v=>{const f=v.dateAvailability,m=Ca({courtDate:f});return{courtName:v.courtName,courtId:v.courtId,timeSlots:m}}).flat(),p=[];for(const v of l){const{startTime:f,endTime:m,averageMinutes:h,recoveryMinutes:g,matchUpId:_}=v,I=Le(f),P=Le(m),S=u().reduce((O,{courtId:b,courtName:w,timeSlots:T})=>{let $;return T.find(({startTime:E,endTime:A})=>{$=Le(E)-I;const U=I>=Le(E);return P<=Le(A)&&O.startDifference!==0&&(($===0||$+n>=0)&&(O.startDifference===void 0||$<O.startDifference)||U)})?{courtName:w,courtId:b,startDifference:$}:O},{});if(S.courtId){const O={averageMinutes:h,recoveryMinutes:g,matchUpId:_,startTime:f,endTime:m};p.push(O);const b=c.find(({courtId:w})=>w===S.courtId);b==null||b.dateAvailability.bookings.push(O)}else console.log({unassignedBooking:v})}return{virtualCourts:c.map(({courtId:v,courtName:f,dateAvailability:m})=>({dateAvailability:[m],courtName:f,courtId:v})),assignedBookings:p}}function rd({averageMatchUpMinutes:t,periodLength:e=30,recoveryMinutes:r}){const n=(t||90)+(r||0);return e>n?n:e||30}function Ma({scheduleDate:t,startTime:e,endTime:r,courts:n}){const o=e&&"startTime"||r&&"endTime"||void 0;return n.reduce((i,s)=>{const a=lc({date:t,court:s}),l=o&&((a==null?void 0:a[o])||s[o]);return l&&(!i||e&&Le(l)<Le(i)||Le(l)>Le(i))?l:i},void 0)}function CH({averageMinutes:t,startTime:e,endTime:r,courts:n,date:o}){e=e||Ma({courts:n,scheduleDate:o,startTime:!0}),r=r||Ma({courts:n,scheduleDate:o,endTime:!0});let i;if(e&&r){const s=$t(e),a=$t(r);for(const l of n||[]){if(!Array.isArray(l.dateAvailability))continue;const c=lc({court:l,date:o});Ca({courtDate:c}).forEach(p=>{const d=$t(p.startTime),v=$t(p.endTime);if(d>a||d<s||v<s)return!1;if(Sl(d,v)>=t){const h=at(d.toISOString());(!i||h<i)&&(i=h)}})}}return{firstTimeSlotStartTime:i}}function iS(t){const{startTime:e="8:00",endTime:r="20:30",count:n=10,date:o}=t||{};return ce(0,n).map(()=>({dateAvailability:[{date:o,startTime:e,endTime:r}]}))}function Vv(t){let{date:e=gf(),startTime:r="08:00",endTime:n="19:00",periodLength:o,courts:i}=t;const{calculateStartTimeFromCourts:s=!0,remainingScheduleTimes:a,averageMatchUpMinutes:l,clearScheduleDates:c,courtsCount:u,bookings:p}=t;o=o||rd({averageMatchUpMinutes:l}),e=Re(e),r=at(r),n=at(n);let d=0,v=0,f=0,m=0,h=0;!i&&u&&(i=iS({startTime:r,endTime:n,count:u,date:e}));const{virtualCourts:g}=Lv({remainingScheduleTimes:a,clearScheduleDates:c,scheduleDate:e,periodLength:o,bookings:p,courts:i}),{firstTimeSlotStartTime:_}=CH({averageMinutes:l,courts:g,startTime:r,endTime:n,date:e});s&&_&&(r=_||r);const I=Le(r),y=Le(n)-I,S=Math.floor(y/o),b=ce(0,S+1).map(T=>{const $=I+T*o,N=kL($),{availableToScheduleCount:E}=oS({courts:g||[],averageMatchUpMinutes:l,periodStart:N,date:e}),A=E>v?E-v:0;h+=T?E:0;const U=T?h/T:E,M=o*U/l,D=T?M*(T-1)+U:U,R=E?v&&D-d||A:0;d=D,v=E,f+=R;const j=Te(f)-m;return m+=j,{periodStart:N,add:j,availableToScheduleCount:E,newCourts:A,totalMatchUps:m}});return{scheduleTimes:b.reduce((T,$)=>{const E=ce(0,$.add).map(()=>({scheduleTime:$.periodStart}));return T.concat(...E)},[]).flat(),timingProfile:b,totalMatchUps:m}}const MH={getCourtsAvailableAtPeriodStart:oS,generateTimeSlots:Ca,getScheduleTimes:Vv,courtGenerator:iS},DH=(t,e)=>t.filter(Boolean).every(r=>typeof r===e),jH=t=>t.filter(Boolean).every(Ct);function sS({consideredDate:t,category:e}={consideredDate:""}){var r;const n={error:X,ageMin:8,ageMax:99};if(typeof e!="object"||!Gr(t))return n;const o=parseInt(t.split("-")[0]),i=[];let{ageCategoryCode:s,ageMaxDate:a,ageMinDate:l,ageMax:c,ageMin:u}=e;const p=e.categoryName;let d;if(!DH([s,a,l,p],"string")||!jH([c,u]))return n;s=s??p;const v=/^([UO]?)(\d{1,2})([UO]?)$/,f=/^C(\d{1,2})-(\d{1,2})$/,m=s==null?void 0:s.includes("-"),h=m&&(s==null?void 0:s.match(f)),g=s==null?void 0:s.match(v),_=w=>w.match(/^\d{2}-\d{2}$/),I=(w,T,$)=>Gr(T)&&T||T&&_(T)&&`${w}-${T}`||`${w}-${$}`,P=w=>{const T=o-w;return l=I(T,l,"01-01"),c&&c!==w-1&&i.push(`Invalid ageMax: ${c}`),c||(c=w-1),{ageMinDate:l,ageMax:c}},y=w=>{const T=o-w-1;return l=I(T,l,"01-01"),c&&c!==w&&i.push(`Invalid ageMax: ${c}`),c||(c=w),{ageMinDate:l,ageMax:c}},S=w=>{const T=o-w-2;return a=I(T,a,"12-31"),u&&u!==w+1&&i.push(`Invalid ageMin: ${u}`),u||(u=w+1),{ageMaxDate:a,ageMin:u}},O=w=>{const T=o-w-1;return a=I(T,a,"12-31"),u&&u!==w&&i.push(`Invalid ageMin: ${u}`),u||(u=w),{ageMaxDate:a,ageMin:u}},b=w=>{const[T,$,N]=(w.match(v)||[]).slice(1),E=parseInt($);T==="U"&&({ageMinDate:l,ageMax:c}=P(E)),N==="U"&&({ageMinDate:l,ageMax:c}=y(E)),T==="O"&&({ageMaxDate:a,ageMin:u}=S(E)),N==="O"&&({ageMaxDate:a,ageMin:u}=O(E))};if(h){const[w,T]=((r=s==null?void 0:s.match(f))!=null?r:[]).slice(1).map($=>parseInt($));w<=T?(u=u??w,c=c??T,d=!0):i.push(`Invalid combined age range ${s}`)}else m?s==null||s.split("-").forEach(b):g&&b(s);return i.length?{error:i,ageMin:8,ageMax:99}:Oe({combinedAge:d,ageMaxDate:a,ageMinDate:l,ageMax:c,ageMin:u})}function nd({tiebreakTo:t=7,scoreString:e}){return e.split(" ").filter(Boolean).map((n,o)=>r({set:n,setNumber:o+1}));function r({set:n,setNumber:o}){const i=(n==null?void 0:n.startsWith("["))&&n.split("[")[1].split("]")[0].split("-").map(h=>parseInt(h)),s=n.includes("(")&&n.split("(")[0]||n.includes("[")&&n.split("[")[0]||n,a=!i&&s.split("-").map(h=>parseInt(h)),l=i?i[0]>i[1]&&1||i[0]<i[1]&&2||void 0:a[0]>a[1]&&1||a[0]<a[1]&&2||void 0,c=n.includes("(")?n.split("(")[1].split(")")[0]:void 0,p=c&&Av({lowValue:c,isSide1:l===2,tiebreakTo:t})||[],[d,v]=a||[],[f,m]=i||p||[];return{side1Score:d,side2Score:v,side1TiebreakScore:f,side2TiebreakScore:m,winningSide:l,setNumber:o}}}function Bv({drawPositions:t}){const e=o=>t.filter(i=>i!==o).map(i=>[o,i]),r=[].concat(...t.map(e)),n=We(r.map(od)).map(o=>o.split("|").map(i=>+i));return{groupMatchUps:r,uniqueMatchUpGroupings:n}}function od(t){return t.sort(er).join("|")}function aS({groupSize:t,drawPositionOffset:e}){const r=p=>[...Array(p)].map((d,v)=>v),n=r(2*Math.round(t/2)+1).slice(1),o=r(n.length-1).map(()=>[]);let i=n.slice(0,n.length/2),s=n.slice(n.length/2);n.slice(1).forEach((p,d)=>{i.forEach((h,g)=>{o[d].push([i[g],s[g]])});const v=i.shift(),f=i.pop(),m=s.shift();i=[v,m,...i].filter(Boolean),s=[...s,f].filter(Boolean)});const a=i.shift(),l=i.pop(),c=s.shift();i=[a,c,...i].filter(Boolean),s=[...s,l].filter(Boolean);const u=p=>p[0].reduce((d,v)=>d+v);return o.reverse().sort((p,d)=>u(p)-u(d)).map(p=>p.filter(d=>d.every(v=>v<=t)).map(d=>{const v=d.map(f=>f+e);return od(v)}))}function RH({rounds:t,hash:e}){return t.reduce((r,n,o)=>n.includes(e)?o+1:r,void 0)}const FH={getRoundRobinGroupMatchUps:Bv,determineRoundNumber:RH,drawPositionsHash:od,groupRounds:aS},id="\\d+-\\d+",cc="\\d+-\\d+\\(\\d+\\)",kv="\\[\\d+-\\d+\\]",xH="\\d+-\\d+\\(\\d+-\\d+\\)",LH=new RegExp(`(${id}),`,"g"),VH=new RegExp(`(${cc}),`,"g"),BH=[id,cc,kv,xH],kH=["0","1","2","00","01","10","11","002","012","102","112","000","001","010","100","011","101","110","111","002","012","102","112","0002","0012","0102","1002","0112","1012","1102","1112","3","03","13","013","103"].map(t=>{const r=t.split("").map(n=>BH[n]).join(" ");return new RegExp(`^${r}$`)});function lS(t){return!t||kH.some(e=>e.test(t))}function GH(t){const e="[];",r="()",n=e+r,o=[e[0],r[0]],i=Object.assign({},...n.split("").map(l=>({[l]:0})));let s="";const a=t.split("").map(l=>{const c=n.includes(l)&&l,u=o.includes(c);if(u&&c)return i[c]+=1,s=c,l;if(!u&&c&&s&&c!==s){i[s]-=1;const p=e.includes(s)&&e||r.includes(s)&&r||"",d=p.split("").find(v=>v!==s);if(p.includes(c))i[s]||(s="");else return i[c]||(s=""),d}return l}).join("");return t!==a?a:t}function sd(t){return/^\(\d+\)$/.test(t)||/^\(\d+$/.test(t)}function WH(t){return/^\(\d+-\d+\)$/.test(t)||/^\[\d+-\d+\]$/.test(t)}function Da(t){const r=(n=>n==null?void 0:n.split("-").join("").split("/").join(""))(t);if(/^\d+$/.test(r)&&r.length===2){const n=r.split("");return Math.abs(n.reduce((i,s)=>+i-+s))===1}return!1}function ad(t,e){const r=[t.slice(e,e+2),e?t.slice(0,1):t.slice(2)].map(i=>parseInt(i.join(""))),n=e?r.reverse():r;if(Math.abs(n.reduce((i,s)=>+i-+s))>=2)return n.join("-")}function cS(t){return t.length===2?t.split("").join("-"):([", ",",","/"," "].forEach(e=>t=t.split(e).join("-")),t=t.replace(/-{2,}/,"-"),t)}function HH(t){return t.startsWith("(")&&t.endsWith(")")}function qH({score:t,applied:e}){t=GH(t);const r=/\)(\d+)/g;if(r.test(t))for(const S of t.match(r)){const O=S.replace(")",") ");t=t.replace(S,O)}t=t.replace(/\)\//g,") / "),t=t.replace(/\/\)/g,")");const n=/\(([\d- ]+)\)/g,o=/\(([\d- ]+)\)/,i=t.match(n);for(const S of i||[]){const[O]=S.match(o).slice(1),b=O.replace(/ /g,"");t=t.replace(S,`(${b})`)}let s=/\(\(\d-\d\)\)/g;if(s.test(t)){const S=t.match(s);S.length&&S.forEach(O=>{const b=O.match(/\((\(\d-\d\))\)/).slice(1)[0];t=t.replace(O,b)})}if(s=/\(\((\d)\)\)/g,s.test(t)){const S=t.match(s);S.length&&S.forEach(O=>{const b=O.match(/\((\(\d\))\)/).slice(1)[0];t=t.replace(O,b)})}/(^|\s)6-,/.test(t)&&(t=t.replace(/(^|\s)6-,/g,"6-0,"));const a=new RegExp(/[-,]{2,}/g);t=t.replace(a,"-"),["- "," -"].forEach(S=>{const O=new RegExp(`(\\d+)${S}(\\d+)`,"g"),b=t.match(O);b&&b.forEach(w=>t=t.replace(w,w.split(S).join("-")))}),/^[(-/,]+$/.test(t)&&(t=""),/\)[-/,]+$/.test(t)&&(t=t.slice(0,t.length-1)),/\d \/\d/.test(t)&&(t=t.replace(/ \//g,"/")),t.includes(" /")&&(t=t.replace(/ \//g," "));const l=/\(\d+, \)/g;l.test(t)&&t.match(l).forEach(O=>{const[b]=O.match(/\((\d+), \)/).slice(1);b.length===2?t=t.replace(O,`(${b})`):b.length===1&&b==="6"&&(t=t.replace(O,"(6-0)"))});const c=/\((\d+)\/\)/g;c.test(t)&&t.match(c).forEach(O=>{const[b]=O.match(/\((\d+)\/\)/).slice(1);b.length===2?t=t.replace(O,`(${b})`):b.length===1&&b==="6"?t=t.replace(O,"(6-0)"):t=t.replace(O,`(${b})`)});const u=/\d\/\d\/,/g;u.test(t)&&t.match(u).forEach(O=>{const[b]=O.match(/(\d\/\d)\/,/).slice(1);t=t.replace(O,`${b},`),e.push("slashComma")});const p=/\(\/(\d+)\)/g;p.test(t)&&t.match(p).forEach(O=>{const[b]=O.match(/\(\/(\d+)\)/).slice(1);b.length===2?t=t.replace(O,`(${b})`):b.length===1&&parseInt(b)<6?t=t.replace(O,`(6-${b})`):t=t.replace(O,`(${b})`)});let d,v,f,m,h;const g=()=>{h=Nr(t.split("")),v=h["("]===(h[")"]||0)+1,d=(h["("]||0)+1===h[")"],f=h["["]===h["]"]+1,m=v&&!f};g();const _=/(\d+-\d+\(\d+)0,/;if(_.test(t)){const[S]=t.match(_).slice(1);t=t.replace(_,S+")")}if(h["("]===h[")"]&&h["("]>1){const S=t.split(")(").join(") (").split(" ");S.every(HH)?t=S.map(O=>{const b=O.slice(1,O.length-1);return b.length>2?b:O}).join(" "):t=S.join(" ")}g();const I=/[A-Za-z]+/.test(t),P=/\d+/.test(t);if(!I&&!P)return{score:""};if(/^\[.+\]$/.test(t)&&"()/,- ".split("").some(S=>h[S])&&(t=t.slice(1,t.length-1)),/^\(.+\)$/.test(t)&&h["("]===1&&h[")"]===1&&"[]/,".split("").some(S=>h[S]>1)&&(t=t.slice(1,t.length-1)),t.startsWith("(")&&t.endsWith("))")&&(t=t.slice(1,t.length-1)),h["("]>(h[")"]||0)&&t[t.length-1]==="("&&(t=t.slice(0,t.length-1)+")",g()),h["("]===1&&!h[")"]&&t[0]==="("&&(t=t+")",g()),h["("]>(h[")"]||0)&&t.slice(0,2)==="(("&&(t=t.slice(1)),d){if(/^9\d/.test(t))t="("+t.slice(1);else if(t[0]!=="(")t="("+t;else{const S=[];let O=0;for(const b of t.split("").reverse())b===")"&&(O?S.push("("):O+=1),b==="("&&(O-=1),S.push(b);S.reverse(),t=S.join("")}g()}if(h[")"]>(h["("]||0)&&t[0]===")"&&(t="("+t.slice(1),g()),m&&(t.endsWith(9)||/\d+0$/.test(t))&&(t=t.slice(0,t.length-1)+")",g()),m&&(!t.endsWith(")")||t.startsWith("(("))&&(t=t+")",g()),m){let S="",O=0;for(const b of t.split(""))b==="("&&(O?S+=")":O+=1),b===")"&&(O-=1),S+=b;t=S}g(),f&&!v&&(t=t+"]"),t.includes("([")&&t.includes("])")&&(t=t.split("([").join("[").split("])").join("]"),g()),/\(\d+0$/.test(t)&&(t=t.slice(0,t.length-1)+")"),g(),h[")"]===1&&!h["("]&&t.endsWith(")")&&(t=t.slice(0,t.length-1)),t.startsWith("(")&&t.endsWith(")")&&h["("]===1&&h[")"]===1&&(t=t.slice(1,t.length-1),g());const y=S=>{const O=S.indexOf("("),b=S.indexOf(")");return O>=0&&b>=0&&O<b};if(/^\([\d ]+.*[\d ]+\)$/.test(t)&&h["("]===h[")"]){const S=t.slice(1,t.length-1);y(S)&&(t=S,g())}return{score:t,applied:e}}function ld(t){if(!/^[\d-]+(\(\d\))*$/.test(t))return t;const e=Dn("-",t.split(""));if(!e.length)return t;const r=t.split("-"),n=!(r.length%2),o=!!(e.length%2);return n&&o&&e.length>r.length/2&&e.filter((s,a)=>a%2).forEach(s=>{t=t.substring(0,s)+" "+t.substring(s+1)}),t}function zH({score:t,applied:e}){return t.includes("( ")&&(e.push("removeParenSpacingAfterOpen"),t=t.split("( ").map(r=>r.trim()).join("(")),t.includes(" )")&&(e.push("removeParenSpacingBeforeClose"),t=t.split(" )").map(r=>r.trim()).join(")")),[LH,VH].forEach(r=>{const n=t.match(r);n!=null&&n.length&&(n.forEach(o=>{t=t.replace(o,o.slice(0,o.length-1)+" ")}),e.push("setsEndComma"))}),t=t.split(" ").filter(Boolean).map(ld).join(" "),{score:t,applied:e}}function YH({score:t}){if(typeof t!="string")return{score:t};const e=d=>d==null?void 0:d.split("-").join("").split("/").join(""),r=d=>d.split("[").join("(").split("]").join(")");t=t.split(", ").join(" ");let n=t.split(" ");t=n.map(d=>{const v=/^-(\d+)$/;if(v.test(d)){const[f]=d.match(v).slice(1);if(f.length===2)return f.split("").join("-")}return d}).join(" "),n=t.split(" ");const o=n.filter(sd);let i=0,s="";for(const d of o){const v=Dn(d,n).filter(g=>!i||g>i)[0],f=n.slice(i,v-1),m=n[v-1],h=e(m);if(/^\d+$/.test(h)&&h.length===2){const g=h.split(""),_=Math.abs(g.reduce((I,P)=>+I-+P));if(_===1){const I=[f.join(" "),[m,d].join("")].join(" ");s+=I,i=v+1}else if(_===0){const I=Math.max(...g);if([4,5,6,7,8,9].includes(I)){const P=[6,4].includes(I)?I+1:I-1,y=[I,P].sort().reverse().join("-"),S=[f.join(" "),[y,d].join("")].join(" ");s+=S,i=v+1}}}}if(o.length&&s.length){const d=n.slice(i).join(" ");return s=[s,d].join(" "),{score:s.trim()}}if(n.length===2&&["(","["].some(d=>n[1].includes(d))){const v=e(n[0]).split("");if(Math.abs(v.reduce((m,h)=>+m-+h,0))===1)return n[1]=r(n[1]),{score:n.join("")}}const a=n.map(d=>WH(d)&&"bracket"||Da(d)&&"set");if(a.includes("set")&&a.includes("bracket")){let d,v="";return n.forEach((f,m)=>{a[m]==="bracket"&&d==="set"?(f=r(f),v+=f):v+=` ${f}`,d=a[m]}),{score:v.trim()}}n=t.split(" ");let l,c=n.map(d=>{const v=new RegExp(/^(\d+)-(\d+)$/);if(v.test(d)){const[f,m]=d.match(v).slice(1),h=Math.abs([f,m].reduce((_,I)=>+_-+I)),g=Math.max(f,m);if(h===1)return l="tiebreakSet",l;if(h>=2&&g>=7&&l==="tiebreakSet")return l="tiebreak",l}});const u=Dn("tiebreak",c);if(u.length){let d="";n.forEach((v,f)=>{u.includes(f)?d+=`(${v}) `:u.includes(f+1)?d+=`${v}`:d+=`${v} `}),t=d.trim()}const p=/(\d+-\d+)\((\d+)-(\d+)\)$/;if(p.test(t)){const[d,v,f]=t.match(p).slice(1),h=Math.max(v,f)>=10;!Da(d)&&h&&(t=t.replace(p,`${d} [${v}-${f}]`))}return c=[],t=t.split(" ").map(d=>{const v=/^\((.*)\)$/,f=v.test(d),m=new RegExp(kv).test(d)&&"super"||new RegExp(cc).test(d)&&"tiebreak"||new RegExp(id).test(d)&&"standard"||"unknown";return c.push(m),m==="standard"&&f?d.match(v)[1]:d}).join(" "),{score:t}}function KH({score:t,applied:e}){for(const T of[".",","," ","/"]){const $=new RegExp(`^(\\d+)\\${T}(\\d+)$`);if($.test(t)){const N=t.match($).slice(1).map(A=>parseInt(A)),E=Math.abs(N[0]-N[1]);E<=10&&E>=2&&(t=t.split(T).join("-"),e.push("variedJoinerPattern"))}}t.includes(";")&&(t=t.split(";").join(" "),e.push("semicolon set separation"));const r=/(^|\s)(\d)\/(\d)(\d)\/(\d)(\(|$)/;if(r.test(t)){const[T,$,N,E,A,U]=t.match(r).slice(1);t=t.replace(r,`${T}${$}-${N} ${E}-${A}${U}`),e.push("smashSlashPattern")}/.*\s6[/-]+$/.test(t)&&(t+="0",e.push("incompleteFinalSetPattern"));const o=/\(6,\)/g;o.test(t)&&(t=t.replace(o,"(6, 0)"),e.push("missingZeroPattern1"));const i=/^\d{3,}\(/,s=/\(\d+\)\d+/;[i,s].forEach(()=>{t=t.split(" ").map($=>(i.test($)&&($=$.replace("("," (")),s.test($)&&($=$.replace(")",") ")),$)).join(" "),e.push("spaceConsiderationPatterns")});const l=ld(t);l!==t&&(t=l,e.push("deDashMash"));const c=/^(\d)[-/,]+(\d{2})[-/,]+(\d)$/;if(c.test(t)){const[T,$,N]=t.match(c).slice(1),[E,A]=$.split("");t=`${T}-${E} ${A}-${N}`,e.push("smashSetPattern")}const u=/^(\d+)[ -](\d+)$/,p=/^([\d -]+)\/([\d -]+)$/;if(p.test(t)){const[T,$]=t.match(p).slice(1),N=T.trim(),E=$.trim();if(u.test(N)&&u.test(E)){const A=N.match(u).slice(1,3).join("-"),U=E.match(u).slice(1,3).join("-");t=`${A} ${U}`,e.push("slashSeparationPattern")}}const d=/^([\d -]+),([\d -]+)$/;if(d.test(t)){const[T,$]=t.match(d).slice(1),N=T.trim(),E=$.trim();if(u.test(N)&&u.test(E)){const A=N.match(u).slice(1,3).join("-"),U=E.match(u).slice(1,3).join("-");t=`${A} ${U}`,e.push("commaSeparationPattern")}}const v=/^\d \d,/;if(v.test(t)){const T=t.match(v)[0],$=T.slice(0,T.length-1).split(" ").join("-");t=t.replace(T,$),e.push("singleSetCommaSeparationPattern")}let f=0;const m=/(\d+)-(\d{2})-(\d+)/;for(;m.test(t)&&f<3;){const[T,$,N]=t.match(m).slice(1),E=$.split(""),A=`${T}-${E[0]} ${E[1]}-${N}`;t=t.replace(m,A),e.push("noSetSeparationPattern"),f+=1}const h=/(^|\s)7-6\s(\d+)\s/g,g=t.match(h);if(g!=null&&g.length){const T=/(^|\s)7-6\s(\d+)\s/;g.forEach($=>{const N=$.match(T).slice(2)[0];t=t.replace($,`7-6(${N}) `),e.push("floatingTiebreakPattern1")})}let _=t.match(/\d \d /);_==null||_.forEach(T=>{const $=T.slice(0,T.length-1).split(" ").join("-");t=t.replace(T,$),e.push("spaceSeparatedSetPattern1")}),_=t.match(/ \d \d$/),_==null||_.forEach(T=>{const $=" "+T.slice(1).split(" ").join("-");t=t.replace(T,$),e.push("spaceSeparatedSetPattern2")});const I=/^\d, *\d\/\d, *\d/;if(I.test(t)){const T=t.match(I)[0],$=T.split("/").map(N=>`(${N})`).join(" ")+" ";t=t.replace(T,$),e.push("slashCommaSetPattern")}const P=/\(6-\)/g;P.test(t)&&(t=t.replace(P,"(6-0)"),e.push("missingZeroPattern2"));const y=new RegExp("(?<!-)(\\d+)\\/(\\d+)(?!-)","g");if(y.test(t)){const T=t.match(y),$=new RegExp("(?<!-)(\\d+)\\/(\\d+)(?!-)");let N=t;T.forEach(E=>{const[A,U]=E.match($).slice(1),C=`${A}-${U}`;N=N.replace(E,C)}),t=N,e.push("slashSetPattern")}const S=/(.*)\s(1\d)\s(\d+)$/;if(S.test(t)){const[T,$,N]=t.match(S).slice(1);T.replace(/\D/g,"").length>=4&&(t=T+` ${$}${N}`,e.push("spaceSeparatedSuperPattern"))}const O=/(^|\s)(\d+-\d+)\s(\d+)(\s|$)/g;for(const T of t.match(O)||[]){const[$,N,E,A]=T.match(/(^|\s)(\d+-\d+)\s(\d+)(\s|$)/).slice(1),[U,C]=N.split("-").map(D=>parseInt(D));Math.abs(U-C)===1&&(t=t.replace(T,`${$}${N}(${E})${A}`),e.push("spaceSeparatedSetPattern"))}const b=/\d-\d \(\d{1,2}\)(\s|$|,)/g;for(const T of t.match(b)||[]){const $=/(\d-\d) \((\d{1,2})\)(\s|$|,)/,[N,E,A]=T.match($).slice(1),[U,C]=N.split("-").map(D=>parseInt(D));Math.abs(U-C)===1&&(t=t.replace(T,`${N}(${E})${A}`),e.push("floatingTiebreakPattern2"))}const w=/(^|\s)(\d \d)\(/g;for(const T of t.match(w)||[]){const $=/(^|\s)(\d \d)\(/,[N,E]=T.match($).slice(1);t=t.replace(T,`${N}${E.split(" ").join("-")}(`),e.push("spacedTiebreakPattern")}return{score:t,applied:e}}function QH({score:t,matchUpStatus:e}){var r;let n=t==null?void 0:t.split(" ");t=n.map(l=>{if(l.endsWith("]")){const c=l.split("[");if(Da(c[0]))return c[0]+`(${c[1].slice(0,c[1].length-1)})`}return l}).join(" ");const o=new RegExp(/(\([\d ]+\))/g);if(o.test(t))for(const l of t.match(o)){let u=(r=l.replace(" ","-").match(/\((.*)\)/))==null?void 0:r[1];if(Ct(u)&&(u==null?void 0:u[0])>2){if([2,4].includes(u.length))u=u.split("").join("-");else if(u.length===3){const p=u.indexOf("1");u=ad(u.split(""),p)}}t=t.replace(l,`(${u})`)}n=t==null?void 0:t.split(" ");let i=new RegExp(/^(\d[-/]+\d)\((\d+)[-/]+(\d+)\)$/);const s=n.length-1;t=n.map((l,c)=>{const u=[void 0,"","COMPLETED"].includes(e)||c!==s;if(i.test(l)&&u){const[p,d,v]=Array.from(l.match(i)).slice(1),f=Math.min(d,v);return`${p}(${f})`}return l}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^(\d{2})\((\d+)\)$/),t=n.map(l=>{if(i.test(l)){const[c,u]=Array.from(l.match(i)).slice(1),p=c.split("");return`${p[0]}-${p[1]}(${u})`}return l}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^\((\d[-/]+\d)\)(\d+)$/),t=n.map(l=>{if(i.test(l)){const[c,u]=Array.from(l.match(i)).slice(1);return Da(c)?`${c}(${u})`:c}return l}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^1-0\((\d+)\)$/),t=n.map(l=>{if(i.test(l)){const[c]=l.match(i).slice(1);return`[${c<9?10:parseInt(c)+2}-${c}]`}return l}).join(" ");const a=/\((\d)+0 /;if(a.test(t)){const l=t.match(a)[1];t=t.replace(a,`(${l}) `)}return{score:t}}function JH({score:t,attributes:e,identifier:r}){var n;if(typeof t!="string")return{score:t,identifier:r};const o=new RegExp(/\([\d,/ ]+\)/g),i=t.match(o);for(const d of i||[]){const v=d.match(/^\((.*)\)$/),f=(n=v==null?void 0:v.slice(1))==null?void 0:n[0],h=t.split(d)[0].split(")").reverse()[0].replace(/\D/g,"");if((f==null?void 0:f.length)===2&&(h==null?void 0:h.length)>=2){const I=h.slice(h.length-2).split("").map(y=>parseInt(y));if(Math.abs(I[0]-I[1])===1)continue}const g=cS(f),_=ld(g);t=t.replace(d,`(${_})`).trim()}const s=new RegExp(/\[[\d,/ ]+\]/g),a=t.match(s);a==null||a.forEach(d=>{const v=cS(d.match(/^\[(.*)\]$/)[1]);t=t.replace(d,`(${v}) `).trim()});const l=[")","]"],c=[")(","), (",") (",")[",") [","](","] ("];if(t.startsWith("(")&&l.some(d=>t.endsWith(d))&&c.some(d=>t.includes(d))){let d="";const v=t.split(/[)\]]/).filter(Boolean).map(_=>(_.startsWith(",")&&(_=_.slice(1)),_.trim())),f=v.every(_=>_.includes(",")||sd(_)),m=v.every(_=>_.includes("/")||sd(_)),h=v.every(_=>_.includes("-")||sd(_)),g=f&&","||h&&"-"||m&&"/";if(g){let _;v.forEach(I=>{if(I.startsWith("("))if(_==="set"&&(d+=" "),I.includes(g))d+=I.slice(1).split(g).map(P=>P.trim()).join("-"),_="set";else{const P=I.slice(1);d+=`(${P}) `,_="tiebreak"}else if(I.startsWith("[")){const P=I.slice(1).split(g).map(S=>parseInt(S.trim())),y=Math.min(...P);_==="set"?d+=`(${y}) `:d+=`[${P.join("-")}] `,_="tiebreak"}}),t=d.trim()}}const u=Nr(t.split(""));u["("]===1&&u[")"]===1&&t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,t.length-1),u["-"]===1&&Da(t)&&Ct(e==null?void 0:e.removed)&&(t=t+`(${e.removed})`,e.removed=void 0));const p=/\(\)/g;return p.test(t)&&(t=t.replace(p,"").trim()),{score:t}}function uS({score:t}){const e=t.split(""),r=[];let n;const o=()=>n=[void 0,void 0,void 0],i=()=>{let a=`${n[0]}-${n[1]}`;return n[2]&&(a+=` (${n[2]})`),o(),n.push(n),a};o();const s=()=>n[0]!==void 0&&n[1]!==void 0&&Math.abs(parseInt(n[0])-parseInt(n[1]));for(;e.length;){const a=e.shift(),l=Ct(a)&&parseInt(a),c=n[0]!==void 0&&n[1]!==void 0;if(Ct(l)){if(n[0]===void 0){n[0]=l;continue}if(n[1]===void 0&&(n[1]=l,s()||0>1)){r.push(i()),n=[void 0,void 0];continue}if(c&&e.length===1&&Ct(e[0])){const u=e.pop();n[0]=n[0].toString()+n[1].toString(),n[1]=u,r.push(i()),n=[void 0,void 0]}c&&s()}}return{sets:r}}function Gv(t){const e=t.indexOf("1"),r=t.split(""),n=r.every(o=>!isNaN(o));if(n&&t.length===3&&e===0){const o=ad(r,e);if(o)return o}if(n&&t.length===7&&e>3){const o=r.slice(4),i=ad(o,e-4);if(i)return`${r[0]}-${r[1]} ${r[2]}-${r[3]} ${i}`}}function dS(t){let{score:e}=t;const{applied:r,matchUpStatus:n}=t,o=e==null?void 0:e.toString().split(""),i=o==null?void 0:o.every(a=>Ct(a)),s=a=>Math.abs(a[0]-a[1]);if(typeof e=="number"||i){e=e.toString().toLowerCase(),i&&(e=o.join(""));const a=i?o.map(l=>parseInt(l)):e.split("").map(l=>parseInt(l));if(uS({score:e}),a.length,e.length===3&&s(a.slice(0,2))===1){const[l,c,u]=a;e=`${l}-${c}(${u})`,r.push("numericTiebreakPattern1")}else if(e.length===3&&a[0]===1){const[l,c,u]=a;e=`[${l}${c}-${u}]`,r.push("numericTiebreakPattern2")}else if(e.length===4&&s(a.slice(0,2))===1&&"987654".split("").includes(a[0].toString())){const[l,c,u,p]=a,d=Math.min(u,p);e=`${l}-${c}(${d})`,r.push("numericTiebreakPattern3")}else if(e.length===4&&a[0]===1&&a[2]===1){const[l,c,u,p]=a;e=`[${l}${c}-${u}${p}]`,r.push("bigSuper")}else if(e.length===4){const[l,c,u,p]=a;e=`${l}${c} ${u}${p}`,r.push("split4")}else if(e.length===5&&s(a.slice(0,2))===1){const[l,c,u,p,d]=a;e=`${l}-${c}(${u}) ${p}-${d}`,r.push("numericTiebreakPattern4")}else if(e.length===5&&s(a.slice(3))===1){const[l,c,u,p,d]=a;e=`${l}-${c} ${u}-${p}(${d})`,r.push("numericTiebreakPattern5")}else if(a.length===7)if(s(a.slice(0,2))>1&&s(a.slice(2,4))>1&&a[4]===1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c} ${u}-${p} [${d}${v}-${f}]`,r.push("numericTiebreakPattern6")}else if(s(a.slice(0,2))===1&&s(a.slice(3,5))>1&&s(a.slice(5,7))>1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c}(${u}) ${p}-${d} ${v}-${f}`,r.push("numericTiebreakPattern7")}else if(s(a.slice(0,2))>1&&s(a.slice(2,4))===1&&s(a.slice(5,7))>1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c} ${u}-${p}(${d}) ${v}-${f}`,r.push("numericTiebreakPattern8")}else if(s(a.slice(0,2))>1&&s(a.slice(2,4))>1&&s(a.slice(4,6))===1){const[l,c,u,p,d,v,f]=a;e=`${l}-${c} ${u}-${p} ${d}-${v}(${f})`,r.push("numericTiebreakPattern9")}else e=e.slice(0,2)+" "+e.slice(2,4)+" "+e.slice(4),r.push("numericMatchTiebreakPattern");else if(e.length%2){const l=Gv(e);l&&e!==l&&r.push("parsedSuperPattern"),e=l||e}else{const l=qt(e.split(""),2).map(h=>h.join("")),c=l.map(h=>{const[g,_]=h.split("").map(y=>parseInt(y)),I=Math.abs(g-_),P=g>_?1:2;return I>1&&P||P*-1}),u=c.reduce((h,g)=>h>0&&g>0,1),p=Nr(c),d=c.map(h=>Math.abs(h)),v=Nr(d),f=c[0]<0,m=!f&&c[1]<0;if(c[0]>0&&c[1]>0&&c[0]!==c[1])e=[l.slice(0,2).join(" "),l.slice(2).join("-")].join(" "),r.push("numeric3rdSetTiebreakPattern");else if(u)e=l.join(" "),r.push("chunkSplit");else if(a.length==6){if(p[1]==2||p[2]===2)if(!Object.values(v).includes(3))e=l.join(" "),r.push("chunkSplit");else{const[h,g,_,I,P,y]=a,S=c.reduce((O,b,w)=>b<0?w:O,void 0);if(S===0){const O=Math.min(_,I);e=`${h}-${g}(${O}) ${P}-${y}`,r.push("chunkSplitTiebreak1")}else if(S===1){const O=Math.min(P,y);e=`${h}-${g} ${_}-${I}(${O})`,r.push("chunkSplitTiebreak2")}else e=`${h}-${g} ${_}-${I}`,r.push("chunkSplitTrimExtraneous")}}else if(a.length===8){const[h,g,_,I,P,y,S,O]=a;f||m?a[5]===1&&(f?e=`${h}-${g}(${_}) ${I}-${P} [${y}${S}-${O}]`:e=`${h}-${g} ${_}-${I}(${P}) [${y}${S}-${O}]`):(c[0],c[1])}}}return{score:e,applied:r,matchUpStatus:n}}function pS(t){const e=[0,0],r=[],n=t.split(" "),o=/(\d+)-(\d+)/;n.forEach(l=>{if(o.test(l)){const c=l.match(o).slice(1).map(p=>parseInt(p)),u=c[0]>c[1]&&1||c[1]>c[0]&&2;u&&(e[u-1]+=1,r.push(u))}});const i=e[0]>e[1]&&1||e[1]>e[0]&&2,s=e[0]>0&&e[0]===e[1],a=e.reduce((l,c)=>l+c,0);return{setsWon:e,setsTied:s,setWinners:r,totalSets:a,winningSide:i}}function ZH({score:t,matchUpStatus:e,attributes:r}){const n=[];let o;const i=t.split(" "),s=i.length;t=i.map((u,p)=>{if(new RegExp(cc).test(u)){const v=u.slice(3),f=u.slice(0,3),m=f.split("-");if(!Da(f)&&!e){const h=Math.max(...m),g=f.indexOf(h),_=[h,h-1];return(g?_.reverse().join("-"):_.join("-"))+v}}else if(u.length===2&&Ct(u))return u.split("").join("-");u=ld(u);const d=new RegExp(`^${kv}$`).test(u)&&"super"||new RegExp(`^${cc}$`).test(u)&&"tiebreak"||new RegExp(`^${id}$`).test(u)&&"standard"||"unknown";if(n.push(d),s>1&&d==="standard"&&p<2){const[v,f]=u.split("-"),m=Math.abs(parseInt(v)-parseInt(f)),h=Math.max(v,f),g=Math.min(v,f),_=[parseInt(v),parseInt(f)].indexOf(g);if(h>9&&m>2){const I=h.toString().split(""),P=I.find(y=>parseInt(y)>g||p&&parseInt(y)<=o)||I[0];P&&(u=_?[P,g].join("-"):[g,P].join("-"))}h>(o||0)&&(o=h)}if(d==="standard"){const[v,f]=u.split("-");if(!Math.abs(parseInt(v)-parseInt(f))&&e!=="RETIRED")return""}return u}).filter(Boolean).join(" ");const{setsWon:a,setWinners:l,totalSets:c}=pS(t);if(c===1&&(r==null?void 0:r.removed)==="6"&&(t+=" 6-0"),t.split(" ").length>2&&Math.max(...a)>=2&&l[0]===l[1]&&(t=t.split(" ").slice(0,2).join(" ")),Math.max(...a)>2){const u=[0,0];t=t.split(" ").map((p,d)=>(u[l[d]]+=1,Math.max(...u)>2?void 0:p)).filter(Boolean).join(" ")}return{score:t,profile:n}}function XH({score:t}){const{setsTied:e,winningSide:r}=pS(t),n=/\s\((\d+)\)$/;if(!r&&e&&n.test(t)){const a=t.match(n).slice(1)[0],l=a<=8?10:a+2;t=t.replace(n,` [${l}-${a}]`)}const o=t.split(" "),i=o[o.length-1];if(!i.includes("-")||i.indexOf("(")>0)return{score:t};let s=i.split("(").join("").split(")").join("").split("-");if(!s.every(a=>Ct(a)))return{score:t};if(s[0]==="76"){const a=s[1].length===2?Math.min(...s[1].split("").map(l=>parseInt(l))):s[1];t=[...o.slice(0,o.length-1),`7-6(${a})`].join(" ")}else{s=s.map(c=>parseInt(c));const a=Math.max(...s);let l=Math.abs(s[0]-s[1]);if(a>=10){if(l>2&&s.every(c=>+c>=10)){const c=s.map(u=>u===a?u-10:10).sort();l=Math.abs(c[0]-c[1]),l>2&&(s=c)}t=[...o.slice(0,o.length-1),`[${s.join("-")}]`].join(" ")}else o.length===3&&a>=7&&l>2&&(t=[...o.slice(0,o.length-1),`[${s.join("-")}]`].join(" "))}return{score:t}}function eq({score:t}){return t=(t==null?void 0:t.toString().toLowerCase())||"",{score:t}}function tq({score:t,applied:e}){return typeof t!="string"?{score:t}:(t.toLowerCase().includes("o")&&(t=t.toLowerCase().split(" ").map(r=>r.split("o").join("0")).join(" "),e.push("replaceOh")),{score:t,applied:e})}function rq({score:t,applied:e}){return typeof t!="string"?{score:t}:(t=t.toLowerCase().split(" ").map(r=>{if(/^\d+$/.test(r)&&r.length>2){const n=r.indexOf("1");if(r.length%2){if(r.length===3&&n===0){const o=ad(r.split(""),n);return e.push("getSuper"),o}}else{const{score:o,applied:i}=dS({score:r,applied:[]});o!==r&&(r=o,e.push(...i))}}return r}).join(" "),{score:t,applied:e})}function nq({score:t,applied:e}){return typeof t!="string"?{score:t}:[3,4].includes(t.length)&&Gv(t)?{score:Gv(t)}:(t=t.toLowerCase().split(" ").map(r=>{if(/^\d+$/.test(r)&&r.length===1){e.push("removeErroneous1");return}return r}).filter(Boolean).join(" "),{score:t,applied:e})}function oq({score:t,applied:e}){return["walkover","wo","w/o","w-o"].includes(t==null?void 0:t.toString().toLowerCase())?(e.push("handleWalkover"),{matchUpStatus:"walkover",score:"",applied:e}):{score:t}}function iq({score:t,profile:e,applied:r}){var n;t=t==null?void 0:t.toString().toLowerCase();const o=/^(.*\d+.*)(ret|con)+[A-Za-z ]*$/;if(o.test(t)){const[l]=t.match(o).slice(1);return r.push("handleRetired"),{score:l.trim(),matchUpStatus:"retired",applied:r}}const i=(n=e==null?void 0:e.matchUpStatuses)==null?void 0:n.retired,a=["rtd",...Array.isArray(i)?i:[i].filter(Boolean)].find(l=>t==null?void 0:t.endsWith(l));return a?(r.push("handleRetired"),{matchUpStatus:"retired",score:t==null?void 0:t.replace(a,"").trim(),applied:r}):{score:t}}function sq({score:t,attributes:e}){(t.endsWith(" am")||t.endsWith(" pm"))&&(t=""),t=t.replace(/[A-Za-z]+/g,"").trim(),[".",","].some(o=>t.endsWith(o))&&(t=t.slice(0,t.length-1));const r="()/-".split("").some(o=>t.includes(o));/ \d$/.test(t)&&r&&(e={removed:t.slice(t.length-2).trim()},t=t.slice(0,t.length-2));const n=/(.*)[A-Za-z]+$/;return n.test(t)&&(t=t.match(n).slice(1)[0].trim()),{score:t,attributes:e}}function aq({score:t}){return new RegExp(/-\d+\/\d+-/).test(t)&&(t=t.split("/").join(" ")),{score:t}}function lq({score:t}){const e=new RegExp(/^\d+\/\d+/),r=t.split(" ");r.some(o=>e.test(o))&&(t=r.map(o=>e.test(o)?o.replace("/","-"):o).join(" "));const n=/^(\d+), *(\d+)$/;if(n.test(t)){const[o,i]=t.match(n).slice(1);t=[o,i].join("-")}return{score:t}}function cq({score:t}){const e=new RegExp(/\(\d+\/\d+\)/g),r=t.match(e);for(const n of r||[]){const o=n.replace("/","-");t=t.replace(n,o)}return{score:t}}function uq({score:t}){if(t.includes(",")){const e=t.split(",").map(o=>o.trim()),r=o=>/\d \d/.test(o);e.every(r)&&(t=e.map(o=>{const i=/\d+ \d+/g;for(const s of o.match(i)){const[a,l]=s.match(/(\d+) (\d+)/).slice(1);o=o.replace(s,`${a}-${l}`)}return o}).join(" "))}if(t.includes(" ")){const e=t.replace(/[ ,]/g,"");e.split("").every(n=>Ct(n))&&e.length===4&&(t=e)}return{score:t}}function dq({score:t}){const e=new RegExp(/^\[\d+\](.*)$/);e.test(t)&&(t=t.match(e).slice(1)[0].trim());const r=/\(,/g;return r.test(t)&&(t=t.replace(r,"(")),{score:t}}const pq={handleTiebreakSlashSeparation:cq,handleSetSlashSeparation:aq,punctuationAdjustments:qH,handleGameSeparation:lq,joinFloatingTiebreak:YH,handleBracketSpacing:zH,handleSpaceSeparator:uq,separateScoreBlocks:rq,matchKnownPatterns:KH,removeDanglingBits:sq,removeErroneous:nq,handleWalkover:oq,properTiebreak:QH,handleNumeric:dS,handleRetired:iq,containedSets:JH,sensibleSets:ZH,stringScore:eq,superSquare:XH,setBuilder:uS,excisions:dq,replaceOh:tq};let Wv={};const fq=["handleNumeric","handleWalkover","handleRetired","replaceOh","stringScore","punctuationAdjustments","excisions","handleSpaceSeparator","matchKnownPatterns","removeDanglingBits","handleBracketSpacing","matchKnownPatterns","containedSets","separateScoreBlocks","handleGameSeparation","removeErroneous","joinFloatingTiebreak","handleSetSlashSeparation","handleTiebreakSlashSeparation","properTiebreak","sensibleSets","superSquare"],vq=["handleNumeric","separateScoreBlocks","sensibleSets","superSquare"];function mq(t){const{score:e,sheetName:r,identifier:n,fileName:o,stepLog:i,fullLog:s,profile:a}=t,l=[];let c,u=[],p,d,v=e;const f=h=>{h.forEach(g=>{d=pq[g]({profile:a,identifier:n,matchUpStatus:c,attributes:p,applied:u,score:v});const _=d.score!==v;_&&l.push({method:g,score:d.score}),i&&(s||_||d.matchUpStatus!==c)&&console.log(c?{score:d.score,matchUpStatus:c}:{score:d.score},g),d.matchUpStatus&&(c=d.matchUpStatus),d.attributes&&(p=d.attributes),d.applied&&(u=d.applied),v=d.score})};f(fq);let m=lS(v);return m||(v=e.toString().replace(/\D/g,""),p!=null&&p.removed&&(p.removed=void 0),f(vq),m=lS(v),m||(v="")),u.forEach(h=>{Wv[h]||(Wv[h]=0),Wv[h]+=1}),{matchUpStatus:c==null?void 0:c.toUpperCase(),modifications:l,attributes:p,isValid:m,score:v}}var hq=Object.defineProperty,fS=Object.getOwnPropertySymbols,gq=Object.prototype.hasOwnProperty,_q=Object.prototype.propertyIsEnumerable,vS=(t,e,r)=>e in t?hq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mS=(t,e)=>{for(var r in e||(e={}))gq.call(e,r)&&vS(t,r,e[r]);if(fS)for(var r of fS(e))_q.call(e,r)&&vS(t,r,e[r]);return t};const{FACTORY:hS}=cI;function cd({tournamentRecord:t,value:e}){const{extension:r}=xr({element:t,name:hS}),n={name:hS,value:mS(mS({},r==null?void 0:r.value),e)};it({element:t,extension:n})}function ki(t){const{mutationStatus:e,tournamentId:r,directives:n,timeStamp:o}=t||{},{topics:i}=Rn();for(const s of[...i].sort(Iq)){const a=CL({topic:s});a&&U_({topic:s,notices:a})}e&&o&&i.includes(pP)&&U_({notices:[{tournamentId:r,directives:n,timeStamp:o}],topic:pP})}const gS={[vP]:5,[fP]:5,[mP]:5,[dP]:5,[uP]:5,[lP]:5,[lk]:5,[ck]:5,[cP]:1,[zf]:1,[rr]:5,[vs]:5,[aP]:4,[oP]:4,[iP]:4,[sP]:4,[qf]:3,[tP]:2};function Iq(t,e){return(gS[e]||0)-(gS[t]||0)}function Ms({tournamentRecords:t,convertExtensions:e,ignoreDisabled:r,venueIds:n=[],dates:o}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const i=[],s=[],a=[],l=[];return Object.keys(t).forEach(u=>{const p=t[u];for(const d of p.venues||[])if(p.venues,!(n.length&&!n.includes(d.venueId))){if(r){const{extension:v}=xr({name:gn,element:d});if(v!=null&&v.value)continue}i.includes(d.venueId)||(l.push(de(d,e,!0)),i.push(d.venueId));for(const v of d.courts||[])if(!s.includes(v.courtId)){if(r&&o){const{extension:m}=xr({name:gn,element:v});if(JI({extension:m,dates:o}))continue}const{inContextCourt:f}=eP({convertExtensions:e,ignoreDisabled:r,venue:d,court:v});a.push(f),s.push(v.courtId)}}}),{courts:a,venues:l}}function Hv({tournamentRecords:t,requireCourts:e,dates:r}){return typeof t!="object"||!Object.keys(t).length?{error:ke}:Object.keys(t).reduce((o,i)=>{const s=t[i],{venues:a}=Yf({tournamentRecord:s,dates:r});return a==null||a.forEach(l=>{const{venueId:c,courts:u}=l;(!e||(u==null?void 0:u.length))&&!o.venueIds.includes(c)&&(o.venues.push(l),o.venueIds.push(c))}),o},{venues:[],venueIds:[]})}var Pq=Object.defineProperty,_S=Object.getOwnPropertySymbols,yq=Object.prototype.hasOwnProperty,Sq=Object.prototype.propertyIsEnumerable,IS=(t,e,r)=>e in t?Pq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,PS=(t,e)=>{for(var r in e||(e={}))yq.call(e,r)&&IS(t,r,e[r]);if(_S)for(var r of _S(e))Sq.call(e,r)&&IS(t,r,e[r]);return t};function uc({duplicateValues:t=!0,creationTime:e=!0,removePriorValues:r,timeItem:n,element:o}){if(!n)return{error:h_};if(!o)return{error:_e,info:Vf};const i=n&&Object.keys(n),s=["itemType","itemValue"];if(!(s.filter(c=>i.includes(c)).length===s.length))return{error:m_};if(!o.timeItems)o.timeItems=[];else{const{itemType:c,itemSubTypes:u,itemValue:p}=n,{timeItem:d}=Un({itemSubTypes:u,itemType:c,element:o});if(JSON.stringify(d==null?void 0:d.itemValue)===JSON.stringify(p)&&!t)return PS({},V)}if(n.itemSubTypes&&!n.itemSubTypes.length&&delete n.itemSubTypes,e){const c=new Date().toISOString();Object.assign(n,{createdAt:c})}return r&&(o.timeItems=o.timeItems.filter(({itemType:c})=>n.itemType!==c)),r&&!n.itemValue||o.timeItems.push(n),PS({},V)}function yS({creationTime:t=!0,removePriorValues:e,tournamentRecord:r,duplicateValues:n,participantId:o,timeItem:i}){if(!r)return{error:re};if(!o)return{error:Et};const s=Qo({tournamentRecord:r,participantId:o});return s.error?s:uc({element:s.participant,removePriorValues:e,duplicateValues:n,creationTime:t,timeItem:i})}function Fo(t){const{removePriorValues:e,tournamentRecord:r,duplicateValues:n,creationTime:o,timeItem:i}=t;return r?uc({element:r,removePriorValues:e,duplicateValues:n,creationTime:o,timeItem:i}):{error:re}}function li(t){const{removePriorValues:e,duplicateValues:r,creationTime:n,timeItem:o,event:i}=t;return i?uc({removePriorValues:e,duplicateValues:r,element:i,creationTime:n,timeItem:o}):{error:Ar}}var Oq=Object.defineProperty,SS=Object.getOwnPropertySymbols,bq=Object.prototype.hasOwnProperty,Tq=Object.prototype.propertyIsEnumerable,OS=(t,e,r)=>e in t?Oq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wq=(t,e)=>{for(var r in e||(e={}))bq.call(e,r)&&OS(t,r,e[r]);if(SS)for(var r of SS(e))Tq.call(e,r)&&OS(t,r,e[r]);return t};function Dr({removePriorValues:t,tournamentRecord:e,duplicateValues:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:s,event:a}){const{matchUp:l}=lt({drawDefinition:n,event:a,matchUpId:i});if(!l)return{error:ir};const c=uc({removePriorValues:t,element:l,duplicateValues:r,timeItem:s});return o||Ze({tournamentId:e==null?void 0:e.tournamentId,eventId:a==null?void 0:a.eventId,context:"addTimeItem",drawDefinition:n,matchUp:l}),c}function Eq({tournamentRecord:t,drawDefinition:e,matchUpId:r,event:n}){const{matchUp:o}=lt({drawDefinition:e,event:n,matchUpId:r});return o?(o.timeItems=[],Ze({tournamentId:t==null?void 0:t.tournamentId,context:"resetTimeItems",eventId:n==null?void 0:n.eventId,drawDefinition:e,matchUp:o}),wq({},V)):{error:ir}}function ud({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,courtDayDate:i,matchUpId:s,courtIds:a}){var l,c;if(!r&&!e)return{error:re};if(!s)return{error:Vt};const u=lt({drawDefinition:n,matchUpId:s});if(u.error)return u;if(((l=u==null?void 0:u.matchUp)==null?void 0:l.matchUpType)!==hn)return{error:tn};if(!(a===void 0||Array.isArray(a)&&a.length&&a.every(f=>typeof f=="string")))return{error:X,context:{courtIds:a}};let d;if(a){const f=e?r:r&&{[r.tournamentId]:r},m=Ms({tournamentRecords:f});if(m.error)return m;const h=(c=m.courts)==null?void 0:c.filter(g=>a.includes(g.courtId));if((h==null?void 0:h.length)!==a.length)return{error:X,context:{courtIds:a}};d=h==null?void 0:h.map(g=>({venueId:g.venueId,courtId:g.courtId}))}return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,timeItem:{itemType:Xo,itemDate:i,itemValue:d}})}function ja({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,venueId:s}){if(!r)return{error:re};if(!i)return{error:Vt};if(s){const l=Zo({tournamentRecords:e,tournamentRecord:r,venueId:s});if(l.error)return l}return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:{itemType:jl,itemValue:s}})}function Ds({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,courtDayDate:i,matchUpId:s,courtId:a}){var l;if(!r&&!e)return{error:re};if(!s)return{error:Vt};if(a){const u=ms({tournamentRecords:e,tournamentRecord:r,courtId:a});if(u.error)return u;const p=(l=u.venue)==null?void 0:l.venueId;ja({tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,venueId:p})}return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,timeItem:{itemType:hs,itemDate:i,itemValue:a}})}function $q({matchUps:t,matchUpId:e}){if(!Array.isArray(t))return{error:X};const r=t.find(a=>a.matchUpId===e),{drawId:n,eventId:o,structureId:i,tournamentId:s}=r||{};return{matchUpId:e,drawId:n,eventId:o,structureId:i,tournamentId:s}}var Nq=Object.defineProperty,bS=Object.getOwnPropertySymbols,Uq=Object.prototype.hasOwnProperty,Aq=Object.prototype.propertyIsEnumerable,TS=(t,e,r)=>e in t?Nq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Cq=(t,e)=>{for(var r in e||(e={}))Uq.call(e,r)&&TS(t,r,e[r]);if(bS)for(var r of bS(e))Aq.call(e,r)&&TS(t,r,e[r]);return t};function Gi(t){let e=t.matchUp;const{removePriorValues:r,tournamentRecord:n,drawDefinition:o,disableNotice:i,scheduledTime:s,matchUpId:a}=t;if(!a)return{error:Vt};if(!aa(s))return{error:rn};if(!e){const f=lt({drawDefinition:o,matchUpId:a});if(f.error)return f;e=f.matchUp}const l=Re(s),c="addMatchUpScheduledTime";if(l){const f=Ui({matchUp:e}).scheduledDate;if(f&&f!==l)return k({info:`date in time: ${l} does not corresponde to scheduledDate: ${f}`,result:{error:rn},stack:c})}const u=Xf({matchUp:e}).timeModifiers||[];if(u!=null&&u.length){const f=qv({disableNotice:!0,removePriorValues:r,tournamentRecord:n,timeModifiers:[],drawDefinition:o,matchUpId:a,matchUp:e});if(f!=null&&f.error)return f}const d=ns(s,!0,!0);return Dr({duplicateValues:!1,removePriorValues:r,tournamentRecord:n,drawDefinition:o,disableNotice:i,matchUpId:a,timeItem:{itemType:Fl,itemValue:d}})}function qv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,timeModifiers:o,matchUpId:i,matchUp:s}){if(!i)return{error:Vt};if(o!==void 0&&!Array.isArray(o))return{error:X,info:or("timeModifiers")};if(!s){const d=lt({drawDefinition:r,matchUpId:i});if(d.error)return d;s=d.matchUp}let a=Xf({matchUp:s}).timeModifiers||[];const l=o.filter(d=>!a.includes(d));if(o.length&&!l.length)return Cq({},V);if(l.some(d=>jP.includes(d))){a=a.filter(v=>!jP.includes(v));const d=Gi({disableNotice:!0,removePriorValues:t,scheduledTime:"",tournamentRecord:e,drawDefinition:r,matchUpId:i});if(d.error)return d}const u=o!=null&&o.length?[...l,...a]:void 0;return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:{itemType:DP,itemValue:u}})}var Mq=Object.defineProperty,Dq=Object.defineProperties,jq=Object.getOwnPropertyDescriptors,wS=Object.getOwnPropertySymbols,Rq=Object.prototype.hasOwnProperty,Fq=Object.prototype.propertyIsEnumerable,ES=(t,e,r)=>e in t?Mq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$S=(t,e)=>{for(var r in e||(e={}))Rq.call(e,r)&&ES(t,r,e[r]);if(wS)for(var r of wS(e))Fq.call(e,r)&&ES(t,r,e[r]);return t},xq=(t,e)=>Dq(t,jq(e));function Qn(t,e){const r=M_.test(t)?t:at(t),n=Re(t)||Re(e)||vn(new Date);return new Date(`${n}T${r}`).getTime()}function dd({errorOnAnachronism:t=!1,checkChronology:e=!0,matchUpDependencies:r,inContextMatchUps:n,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,disableNotice:l,drawMatchUps:c,matchUpId:u,schedule:p,event:d}){var v;if(!p)return{error:_e,info:"Missing schedule"};if(!a)return{error:ue};if(!u)return{error:Vt};const f="drawEngine.addMatchUpScheduleItems";let m,h;if(c)m=c.find(E=>E.matchUpId===u);else{const E=lt({drawDefinition:a,event:d,matchUpId:u});if(E.error)return E;m=E.matchUp}const{endTime:g,courtId:_,courtIds:I,courtOrder:P,resumeTime:y,scheduledDate:S,scheduledTime:O,startTime:b,stopTime:w,timeModifiers:T,venueId:$}=p;e&&(!r||!n)&&({matchUpDependencies:r,matchUps:n}=cn({drawDefinition:a}));const N=(v=r==null?void 0:r[u])==null?void 0:v.matchUpIds;if(p.scheduledDate&&e&&N){const E=n==null?void 0:n.filter(A=>{var U,C;return(((U=A.schedule)==null?void 0:U.scheduledDate)||Re((C=A.schedule)==null?void 0:C.scheduledTime))&&N.includes(A.matchUpId)}).map(({schedule:A})=>{const U=au(A);return new Date(U).getTime()});if(E!=null&&E.length){const A=au(p),U=new Date(A).getTime();if(Math.max(...E)>=U){if(t)return k({result:{error:Bg},stack:f});h=Bg}}}if(S!==void 0){const E=zv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,scheduledDate:S,matchUpId:u});if(E!=null&&E.error)return k({result:E,stack:f,context:{scheduledDate:S}})}if(O!==void 0){const E=Gi({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,scheduledTime:O,matchUpId:u,matchUp:m});if(E!=null&&E.error)return k({result:E,stack:f,context:{scheduledTime:O}})}if(b!==void 0){const E=Kv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,startTime:b,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{startTime:b}})}if(w!==void 0){const E=Jv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,stopTime:w,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{stopTime:w}})}if(y!==void 0){const E=Zv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,resumeTime:y,matchUpId:u,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{resumeTime:y}})}if(g!==void 0){const E=Qv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,endTime:g,event:d});if(E!=null&&E.error)return k({result:E,stack:f,context:{endTime:g}})}if(I!==void 0){const E=ud({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,courtIds:I});if(E!=null&&E.error)return k({result:E,stack:f,context:{courtIds:I}})}if(_!==void 0&&S!==void 0){const E=Ds({courtDayDate:S,disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,matchUpId:u,courtId:_});if(E!=null&&E.error)return k({result:E,stack:f,context:{courtId:_}})}if($!==void 0){const E=ja({disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,matchUpId:u,venueId:$});if(E!=null&&E.error)return k({result:E,stack:f,context:{venueId:$}})}if(P!==void 0&&ht(P)){const E=Yv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,courtOrder:P,matchUpId:u});if(E!=null&&E.error)return k({result:E,stack:f,context:{courtOrder:P}})}if(T!==void 0){const E=qv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,timeModifiers:T,matchUpId:u,matchUp:m});if(E!=null&&E.error)return k({result:E,stack:f,context:{timeModifiers:T}})}return l||Ze({tournamentId:s==null?void 0:s.tournamentId,eventId:d==null?void 0:d.eventId,context:f,drawDefinition:a,matchUp:m}),h?xq($S({},V),{warnings:[h]}):$S({},V)}function zv({scheduledDate:t,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i}){if(!i)return{error:Vt};const s=t&&xn.test(t);if(t&&!s)return{error:Sr};const l={itemValue:Re(t),itemType:Rl};return Dr({duplicateValues:!1,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:l})}function Yv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,courtOrder:o,matchUpId:i}){if(!i)return{error:Vt};if(o&&!ht(o))return{error:X,info:"courtOrder must be numeric"};const s=o&&Te(o);return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:{itemType:MP,itemValue:s}})}function NS({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,participantId:o,officialType:i,matchUpId:s}){if(!s)return{error:Vt};const a={itemType:"SCHEDULE.ASSIGNMENT.OFFICIAL",itemValue:o};return i&&(a.itemSubTypes=[i]),Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:s,timeItem:a})}function Kv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,startTime:i,event:s}){var a;if(!o)return{error:Vt};if(!aa(i))return{error:rn};const{matchUp:l}=lt({drawDefinition:r,event:s,matchUpId:o}),{scheduledDate:c}=Ui({matchUp:l}),p=((a=l==null?void 0:l.timeItems)!=null?a:[]).filter(d=>[ei,No,ti].includes(d==null?void 0:d.itemType)).map(d=>Qn(d.itemValue,c)).reduce((d,v)=>!d||v<d?v:d,void 0);if(!p||Qn(i,c)<p){l!=null&&l.timeItems&&(l.timeItems=l.timeItems.filter(f=>f.itemType!==Hn));const d=ns(i,!0,!0);return Dr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,timeItem:{itemType:Hn,itemValue:d}})}else return{error:Gx}}function Qv({validateTimeSeries:t=!0,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,endTime:s,event:a}){var l;if(!i)return{error:Vt};if(!aa(s))return{error:rn};const{matchUp:c}=lt({drawDefinition:n,event:a,matchUpId:i}),{scheduledDate:u}=Ui({matchUp:c}),d=((l=c==null?void 0:c.timeItems)!=null?l:[]).filter(v=>[Hn,No,ei].includes(v==null?void 0:v.itemType)).map(v=>Qn(v.itemValue,u)).reduce((v,f)=>!v||f>v?f:v,void 0);if(!t||!d||Qn(s,u)>d){c!=null&&c.timeItems&&(c.timeItems=c.timeItems.filter(m=>m.itemType!==ti));const v=ns(s,!0,!0);return Dr({duplicateValues:!1,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:{itemType:ti,itemValue:v}})}else return{error:Bx}}function Jv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,stopTime:i,event:s}){var a;if(!o)return{error:Vt};if(!aa(i))return{error:rn};const{matchUp:l}=lt({drawDefinition:r,event:s,matchUpId:o}),{scheduledDate:c}=Ui({matchUp:l}),u=(a=l==null?void 0:l.timeItems)!=null?a:[];if(u.reduce((h,g)=>g.itemType===ti||h,void 0))return{error:v_};const d=u.filter(h=>[Hn,No,ei].includes(h==null?void 0:h.itemType)).sort((h,g)=>Qn(h.itemValue,c)-Qn(g.itemValue,c)),v=d[d.length-1],f=v&&v.itemType===ei,m=d.filter(h=>!f||h.createdAt!==v.createdAt).map(h=>Qn(h.itemValue,c)).reduce((h,g)=>!h||g>h?g:h,void 0);if(Qn(i,c)>m){if(l!=null&&l.timeItems&&f){const _=v.createdAt;l.timeItems=l.timeItems.filter(I=>I.createdAt!==_)}const g={itemValue:ns(i,!0,!0),itemType:ei};return Dr({duplicateValues:!0,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,timeItem:g})}else return{error:kx}}function Zv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,resumeTime:o,matchUpId:i,event:s}){var a;if(!i)return{error:Vt};if(!aa(o))return{error:rn};const{matchUp:l}=lt({drawDefinition:r,event:s,matchUpId:i}),{scheduledDate:c}=Ui({matchUp:l}),u=(a=l==null?void 0:l.timeItems)!=null?a:[];if(u.reduce((h,g)=>g.itemType===ti||h,void 0))return{error:v_};const d=u.filter(h=>[Hn,No,ei].includes(h==null?void 0:h.itemType)).sort((h,g)=>Qn(h.itemValue,c)-Qn(g.itemValue,c)),v=d[d.length-1],f=v&&v.itemType===No,m=d.filter(h=>!f||h.createdAt!==v.createdAt).map(h=>Qn(h.itemValue,c)).reduce((h,g)=>!h||g>h?g:h,void 0);if(Qn(o,c)>m){if(l!=null&&l.timeItems&&f){const _=v.createdAt;l.timeItems=l.timeItems.filter(I=>I.createdAt!==_)}const g={itemValue:ns(o,!0,!0),itemType:No};return Dr({duplicateValues:!0,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:g})}else return{error:Wx}}var Lq=Object.defineProperty,Vq=Object.defineProperties,Bq=Object.getOwnPropertyDescriptors,US=Object.getOwnPropertySymbols,kq=Object.prototype.hasOwnProperty,Gq=Object.prototype.propertyIsEnumerable,AS=(t,e,r)=>e in t?Lq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,CS=(t,e)=>{for(var r in e||(e={}))kq.call(e,r)&&AS(t,r,e[r]);if(US)for(var r of US(e))Gq.call(e,r)&&AS(t,r,e[r]);return t},MS=(t,e)=>Vq(t,Bq(e));function DS({errorOnAnachronism:t=!1,checkChronology:e=!0,matchUpDependencies:r,tournamentRecords:n,tournamentRecord:o,matchUpDetails:i,matchUpIds:s,schedule:a}){var l,c,u;if(!o)return{error:re};if(!i&&(!s||!Array.isArray(s)))return{error:vl};if(!i&&(!a||typeof a!="object"))return{error:Hx};let p;const d=[];let v=0;if(e&&!r){const h=cn({tournamentRecords:n});r=h.matchUpDependencies,p=h.matchUps}p||(p=((l=Wt({tournamentRecord:o}))==null?void 0:l.matchUps)||[]);const f=p.reduce((h,g)=>{const{matchUpId:_,drawId:I}=g;return h[I]?h[I].push(_):h[I]=[_],h},{}),m=i==null?void 0:i.map(h=>h.matchUpId);for(const h of Object.keys(f)){const{drawDefinition:g}=Jo({tournamentRecord:o,drawId:h}),_=f[h].filter(P=>(s==null?void 0:s.includes(P))||(m==null?void 0:m.includes(P))),I=zr({inContext:!1,drawDefinition:g}).matchUps;for(const P of _){const y=((c=i==null?void 0:i.find(O=>O.matchUpId===P))==null?void 0:c.schedule)||a,S=dd({schedule:y,matchUpDependencies:r,errorOnAnachronism:t,inContextMatchUps:p,tournamentRecords:n,tournamentRecord:o,checkChronology:e,drawDefinition:g,drawMatchUps:I,matchUpId:P});if((u=S==null?void 0:S.warnings)!=null&&u.length&&d.push(...S.warnings),S!=null&&S.success&&(v+=1),S.error)return S}}return d.length?MS(CS({},V),{scheduled:v,warnings:d}):MS(CS({},V),{scheduled:v})}var Wq=Object.defineProperty,Hq=Object.defineProperties,qq=Object.getOwnPropertyDescriptors,jS=Object.getOwnPropertySymbols,zq=Object.prototype.hasOwnProperty,Yq=Object.prototype.propertyIsEnumerable,RS=(t,e,r)=>e in t?Wq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,FS=(t,e)=>{for(var r in e||(e={}))zq.call(e,r)&&RS(t,r,e[r]);if(jS)for(var r of jS(e))Yq.call(e,r)&&RS(t,r,e[r]);return t},xS=(t,e)=>Hq(t,qq(e));function LS({errorOnAnachronism:t,matchUpContextIds:e,tournamentRecords:r,checkChronology:n,matchUpDetails:o,schedule:i}){var s;if(!r)return{error:ke};if(!Array.isArray(e)&&!Array.isArray(o))return{error:X};if((!o||e)&&!i)return{error:_e,info:"schedule is required"};const a=[];let l=0;const{matchUpDependencies:c}=cn({tournamentRecords:r});for(const u of Object.values(r)){const{tournamentId:p}=u,d=e==null?void 0:e.filter(f=>f.tournamentId===p).map(Jt),v=o==null?void 0:o.filter(f=>(f==null?void 0:f.tournamentId)===p);if(d!=null&&d.length||v!=null&&v.length){const f=DS({matchUpDetails:v,matchUpDependencies:c,errorOnAnachronism:t,tournamentRecords:r,tournamentRecord:u,checkChronology:n,matchUpIds:d,schedule:i});if((s=f.warnings)!=null&&s.length&&a.push(...f.warnings),f.scheduled&&(l+=f.scheduled),f.error)return f}}return a.length?xS(FS({},V),{scheduled:l,warnings:a}):xS(FS({},V),{scheduled:l})}function pd({tournamentRecords:t}){return t?Object.keys(t).reduce((r,n)=>{r.tournamentIdMap[n]=[];const i=t[n].events||[],s=i.map(({eventId:l})=>l),a=i.map(l=>(l.drawDefinitions||[]).map(({drawId:c})=>c)).flat();return r.tournamentIdMap[n].push(...s,...a),r.eventIds.push(...s),r.drawIds.push(...a),r},{eventIds:[],drawIds:[],tournamentIdMap:{}}):{error:ke}}function Xv({tournamentRecords:t,eventId:e,drawId:r}){const{tournamentIdMap:n}=pd({tournamentRecords:t});return(n?Object.keys(n):[]).find(i=>e&&(n==null?void 0:n[i].includes(e))||r&&(n==null?void 0:n[i].includes(r)))}var Kq=Object.defineProperty,VS=Object.getOwnPropertySymbols,Qq=Object.prototype.hasOwnProperty,Jq=Object.prototype.propertyIsEnumerable,BS=(t,e,r)=>e in t?Kq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zq=(t,e)=>{for(var r in e||(e={}))Qq.call(e,r)&&BS(t,r,e[r]);if(VS)for(var r of VS(e))Jq.call(e,r)&&BS(t,r,e[r]);return t};function Xq({drawDefinition:t,matchUpStatus:e,matchUpsMap:r,winningSide:n,dualMatchUp:o,tieFormat:i,structure:s,matchUp:a,event:l,score:c}){var u;const p=de(o,void 0,!0);for(const v of(p==null?void 0:p.tieMatchUps)||[])v.matchUpId===a.matchUpId&&(v.winningSide=n,v.score=c,!Gt({score:c})&&!e?Object.assign(v,Zq({},Gu)):e&&(v.matchUpStatus=e));i=i||((u=vr({matchUp:a,structure:s,drawDefinition:t,event:l}))==null?void 0:u.tieFormat);const{winningSide:d}=tc({matchUp:p,drawDefinition:t,matchUpsMap:r,structure:s,tieFormat:i,event:l});return{projectedWinningSide:d}}function e6(t){var e;const{matchUpFormat:r,score:n}=t,o=(e=n==null?void 0:n.sets)==null?void 0:e.length,i=r&&Pr(r),{setFormat:s,finalSetFormat:a,bestOf:l}=i||{},u=l&&o===l&&a||s;return(u==null?void 0:u.timed)||!1}function js({drawPosition:t,matchUps:e=[]}){return{initialRoundNumber:e.filter(({drawPositions:n})=>t&&(n==null?void 0:n.includes(t))).map(({roundNumber:n})=>n).sort(er)[0]}}function kS({structureId:t,matchUpsMap:e,matchUp:r}){const n=r==null?void 0:r.roundPosition,o=n%2?1:-1,i=n+o;return{pairedPreviousMatchUp:xi({matchUpsMap:e,structureId:t}).find(({roundNumber:l,roundPosition:c})=>l===(r==null?void 0:r.roundNumber)&&c===i)}}var t6=Object.defineProperty,r6=Object.defineProperties,n6=Object.getOwnPropertyDescriptors,GS=Object.getOwnPropertySymbols,o6=Object.prototype.hasOwnProperty,i6=Object.prototype.propertyIsEnumerable,WS=(t,e,r)=>e in t?t6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s6=(t,e)=>{for(var r in e||(e={}))o6.call(e,r)&&WS(t,r,e[r]);if(GS)for(var r of GS(e))i6.call(e,r)&&WS(t,r,e[r]);return t},a6=(t,e)=>r6(t,n6(e));function HS({inContextDrawMatchUps:t,sourceMatchUpStatus:e,sourceMatchUpId:r,matchUpsMap:n,matchUp:o}){var i;const s=t.find(l=>l.matchUpId===r),{pairedPreviousMatchUp:a}=kS({structureId:s==null?void 0:s.structureId,matchUp:s,matchUpsMap:n});if(s&&a){const l=a==null?void 0:a.matchUpId,c=t.find(p=>p.matchUpId===l),u=(s==null?void 0:s.structureId)===(c==null?void 0:c.structureId)?(s==null?void 0:s.roundPosition)<(c==null?void 0:c.roundPosition)&&1||2:s.structureId===(c==null?void 0:c.structureId)&&2||1;o.matchUpStatusCodes=((i=o.matchUpStatusCodes)!=null?i:[]).map(p=>p.sideNumber===u?a6(s6({},p),{previousMatchUpStatus:e}):p)}}var l6=Object.defineProperty,qS=Object.getOwnPropertySymbols,c6=Object.prototype.hasOwnProperty,u6=Object.prototype.propertyIsEnumerable,zS=(t,e,r)=>e in t?l6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,em=(t,e)=>{for(var r in e||(e={}))c6.call(e,r)&&zS(t,r,e[r]);if(qS)for(var r of qS(e))u6.call(e,r)&&zS(t,r,e[r]);return t};function d6({inContextDrawMatchUps:t,sourceMatchUpStatus:e,targetDrawPosition:r,tournamentRecord:n,sourceMatchUpId:o,drawDefinition:i,structureId:s,dualMatchUp:a,roundNumber:l,matchUpsMap:c,event:u}){const{structure:p}=Ne({drawDefinition:i,structureId:s});if((p==null?void 0:p.structureType)===gr)return em({},V);c=c||lr({drawDefinition:i});const v=((c==null?void 0:c.mappedMatchUps)||{})[s].matchUps,{initialRoundNumber:f}=js({drawPosition:r,matchUps:v}),m=v==null?void 0:v.filter(g=>{var _;return g.roundNumber>=l&&g.roundNumber!==f&&((_=g.drawPositions)==null?void 0:_.includes(r))}),{positionAssignments:h}=st({drawDefinition:i,structureId:s});for(const g of m||[])p6({inContextDrawMatchUps:t,sourceMatchUpStatus:e,positionAssignments:h,targetDrawPosition:r,tournamentRecord:n,sourceMatchUpId:o,drawDefinition:i,dualMatchUp:a,matchUpsMap:c,matchUp:g,event:u});return em({},V)}function p6({inContextDrawMatchUps:t,positionAssignments:e,sourceMatchUpStatus:r,targetDrawPosition:n,tournamentRecord:o,sourceMatchUpId:i,drawDefinition:s,dualMatchUp:a,matchUpsMap:l,matchUp:c,event:u}){var p,d,v;const f="removeSubsequentDrawPosition";if(a){const _=(d=(p=t.find(({matchUpId:P})=>c.matchUpId===P).sides)==null?void 0:p.find(P=>P.drawPosition===n))==null?void 0:d.sideNumber,I=(v=c.sides)==null?void 0:v.find(P=>P.sideNumber===_);I&&delete I.lineUp}c.drawPositions=(c.drawPositions||[]).map(g=>g===n?void 0:g).filter(Boolean);const h=e.filter(({drawPosition:g})=>{var _;return(_=c.drawPositions)==null?void 0:_.includes(g)}).filter(g=>g.bye).length;return c.matchUpStatus=h&&nt||[Xe,ot].includes(c.matchUpStatus)&&c.matchUpStatus||Ft,[ot,Xe].includes(c.matchUpStatus)&&(c.winningSide=void 0),c.matchUpStatusCodes&&HS({inContextDrawMatchUps:t,sourceMatchUpStatus:r,sourceMatchUpId:i,matchUpsMap:l,matchUp:c}),Ze({tournamentId:o==null?void 0:o.tournamentId,eventId:u==null?void 0:u.eventId,context:`${f}-${n}`,drawDefinition:s,matchUp:c}),em({},V)}function YS({positionAssignments:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:n,structure:o,event:i}){const{matchUps:s}=Je({drawDefinition:r,matchUpsMap:n,structure:o,event:i});s.forEach(a=>{const c=t.filter(({drawPosition:u})=>{var p;return(p=a.drawPositions)==null?void 0:p.includes(u)}).filter(u=>u.bye).length;a.winningSide||(Object.assign(a,{matchUpStatus:c?nt:Ft}),Ze({tournamentId:e==null?void 0:e.tournamentId,context:"modifyRoundRobinMatchUpsStatus",eventId:i==null?void 0:i.eventId,drawDefinition:r,matchUp:a}))})}function Ra({tournamentRecord:t,drawDefinition:e,event:r}){const n=(t==null?void 0:t.events)||r&&[r],o=(n==null?void 0:n.map(l=>l==null?void 0:l.drawDefinitions).flat().filter(Boolean))||e&&[e]||[],i={},s={},a=o.map(l=>{var c;return(c=l==null?void 0:l.structures)==null?void 0:c.filter(u=>u==null?void 0:u.structures)}).flat().filter(Boolean);for(const l of a){const{structures:c,structureId:u}=l||{};c&&u&&(i[u]=c==null?void 0:c.map(p=>p.structureId))&&c.forEach(p=>s[p.structureId]=l==null?void 0:l.structureId)}return{containedStructures:i,containerStructures:s}}function dc(t){var e;const{drawDefinition:r,findContainer:n,structureId:o,event:i}=t;let s=t.structure;const a={isCollectionMatchUp:!1},{containedStructures:l}=Ra({drawDefinition:r}),c=o?l[o]||[]:[];if(!s){const b=Ne({drawDefinition:r,structureId:o});if(b.error)return b;s=n&&b.containingStructure||b.structure}if(Co({drawDefinition:r,structure:s}))return{structure:s,isAdHoc:!0,error:ta};const{matchUps:u}=Lt({inContext:!0,matchUpFilters:a,drawDefinition:r,event:i}),p=u==null?void 0:u.filter(b=>b.structureId===o||c.includes(b.structureId)),{matchUpDependencies:d}=cn({drawIds:[r.drawId],matchUps:u,drawDefinition:r}),v=[],f=[],m={},h=[];for(const b of u||[]){if(b.structureId===o||c.includes(b.structureId)){f.push(...b.drawPositions||[]);const w=b.roundNumber;for(const T of(b.drawPositions||[]).filter(Boolean))(!m[T]||w&&m[T]>w)&&(m[T]=w)}fv(b)&&(h.push(b),v.push(b.matchUpId,...((e=d==null?void 0:d[b==null?void 0:b.matchUpId])==null?void 0:e.matchUpIds)||[]))}const g=We(f.filter(Boolean)).sort(er),_=We(v),I=We(p==null?void 0:p.map(({matchUpId:b,drawPositions:w})=>_.includes(b)?w:[]).flat().filter(Boolean)).sort(er),{positionAssignments:P}=st({drawDefinition:r,structure:s}),y=P==null?void 0:P.filter(b=>b.bye).map(b=>b.drawPosition),S=P==null?void 0:P.filter(b=>b.qualifier).map(b=>b.drawPosition),O=(g==null?void 0:g.filter(b=>!I.includes(b)))||[];return{allDrawPositions:g,inContextStructureMatchUps:p,drawPositionInitialRounds:m,activeDependentMatchUpIds:_,qualifyingDrawPositions:S,inactiveDrawPositions:O,positionAssignments:P,activeDrawPositions:I,byeDrawPositions:y,activeMatchUps:h,structure:s}}function Jn(t,e){e||zt()}var f6=Object.defineProperty,v6=Object.defineProperties,m6=Object.getOwnPropertyDescriptors,KS=Object.getOwnPropertySymbols,h6=Object.prototype.hasOwnProperty,g6=Object.prototype.propertyIsEnumerable,QS=(t,e,r)=>e in t?f6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,pc=(t,e)=>{for(var r in e||(e={}))h6.call(e,r)&&QS(t,r,e[r]);if(KS)for(var r of KS(e))g6.call(e,r)&&QS(t,r,e[r]);return t},_6=(t,e)=>v6(t,m6(e));function Fa(t){let{inContextDrawMatchUps:e,participantId:r,drawPosition:n}=t;const{tournamentRecord:o,drawDefinition:i,structureId:s,matchUpsMap:a,event:l}=t,{structure:c}=Ne({drawDefinition:i,structureId:s}),p=(Dt({drawDefinition:i,structure:c}).positionAssignments||[]).find(m=>r&&m.participantId===r||n&&m.drawPosition===n);if(p&&r&&!n&&(n=p==null?void 0:p.drawPosition),!n)return{error:pl};r||(r=p==null?void 0:p.participantId);const{activeDrawPositions:d}=dc({drawDefinition:i,structureId:s});return d.includes(n)?{error:Xp}:(e||({matchUps:e}=Lt({inContext:!0,drawDefinition:i,matchUpsMap:a})),tm({inContextDrawMatchUps:e,tournamentRecord:o,drawDefinition:i,structureId:s,drawPosition:n,matchUpsMap:a,event:l}).drawPositionCleared?(oi({tournamentId:o==null?void 0:o.tournamentId,drawDefinition:i,structure:c,event:l}),_6(pc({},V),{participantId:r})):{error:JF})}function tm({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,matchUpsMap:o,structureId:i,event:s}){const{structure:a}=Ne({drawDefinition:r,structureId:i});if(!a)return{error:bt};const l=Dt({drawDefinition:r,structure:a}).positionAssignments||[],c=l.some(I=>{if(I.drawPosition===n)return delete I.participantId,delete I.qualifier,delete I.bye,!0});if(a.structureType===gr)return YS({positionAssignments:l,tournamentRecord:e,drawDefinition:r,matchUpsMap:o,structure:a}),pc({drawPositionCleared:c},V);const u={isCollectionMatchUp:!1},{matchUps:p}=Je({drawDefinition:r,matchUpFilters:u,matchUpsMap:o,structure:a,event:s}),{roundProfile:d,roundMatchUps:v}=Tr({matchUps:p}),f=d&&Object.keys(d),m=f==null?void 0:f.map(I=>Te(I));let h=n;const g=m==null?void 0:m.map(I=>{var P,y,S;const O=d==null?void 0:d[I],b=(P=O==null?void 0:O.pairedDrawPositions)==null?void 0:P.find(M=>M.includes(h)),w=b==null?void 0:b.find(M=>M!==h),T=l.find(M=>M.drawPosition===w),$=d==null?void 0:d[I+1],N=T==null?void 0:T.bye,E=(y=$==null?void 0:$.pairedDrawPositions)==null?void 0:y.find(M=>M.includes(w)),A=N&&E&&$&&((S=$.drawPositions)==null?void 0:S.includes(w)),C=b&&{pairedDrawPositionByeAdvancedPair:!A&&E,pairedDrawPosition:w,targetDrawPosition:h,relevantPair:b,roundNumber:I};return A&&(h=w),C}).filter(I=>I==null?void 0:I.targetDrawPosition),_=g==null?void 0:g.reduce((I,P)=>{const{roundNumber:y,relevantPair:S,targetDrawPosition:O,pairedDrawPosition:b,pairedDrawPositionByeAdvancedPair:w}=P,T={roundNumber:y,targetDrawPosition:O,relevantPair:S},$=w&&{roundNumber:y+1,targetDrawPosition:b,relevantPair:w,subsequentRoundRemoval:!0},N=[T,$].filter(Boolean);return I.concat(...N)},[]);return _==null||_.forEach(({roundNumber:I,targetDrawPosition:P,relevantPair:y})=>{const S=v==null?void 0:v[I].find(O=>Xt(O.drawPositions.filter(Boolean),y.filter(Boolean)));S&&(I6({inContextDrawMatchUps:t,targetDrawPosition:P,tournamentRecord:e,drawDefinition:r,structureId:i,roundNumber:I,matchUpsMap:o}),JS({inContextDrawMatchUps:t,positionAssignments:l,tournamentRecord:e,drawDefinition:r,targetMatchUp:S,drawPosition:n,matchUpsMap:o,structure:a,event:s}))}),{tasks:_,drawPositionCleared:c,positionAssignments:l}}function I6({inContextDrawMatchUps:t,targetDrawPosition:e,tournamentRecord:r,drawDefinition:n,matchUpsMap:o,roundNumber:i,structureId:s}){const{structure:a}=Ne({drawDefinition:n,structureId:s});if(!a)return{error:bt};if(a.structureType===gr)return;o=o||lr({drawDefinition:n});const c=((o==null?void 0:o.mappedMatchUps)||{})[s].matchUps,{initialRoundNumber:u}=js({drawPosition:e,matchUps:c}),p=c==null?void 0:c.filter(v=>{var f;return v.roundNumber>=i&&v.roundNumber!==u&&((f=v.drawPositions)==null?void 0:f.includes(e))}),d=st({drawDefinition:n,structureId:s}).positionAssignments||[];return p==null||p.forEach(v=>JS({drawPosition:e,targetMatchUp:v,inContextDrawMatchUps:t,positionAssignments:d,tournamentRecord:r,drawDefinition:n,matchUpsMap:o,structure:a})),pc({},V)}function JS({inContextDrawMatchUps:t,positionAssignments:e,tournamentRecord:r,drawDefinition:n,targetMatchUp:o,drawPosition:i,matchUpsMap:s,structure:a,event:l}){var c,u,p,d,v;const f="removeDrawPosition",m=(c=o.drawPositions)==null?void 0:c.slice(),h=o.matchUpStatus,g=o.winningSide;s=s||lr({drawDefinition:n});const I=s.mappedMatchUps[a.structureId].matchUps,{initialRoundNumber:P}=js({drawPosition:i,matchUps:I});if(o.roundNumber&&P&&o.roundNumber>P){const U=(o.drawPositions||[]).map(C=>C===i?void 0:C);o.drawPositions=U}if(o.matchUpType===Qe){const U=t==null?void 0:t.find(D=>D.matchUpId===o.matchUpId),M=((U==null?void 0:U.sides)||[]).reduce((D,R,j)=>R.drawPosition===i?j:D,void 0);M!==void 0&&((p=(u=o.sides)==null?void 0:u[M])!=null&&p.lineUp)&&((d=o.sides)==null||delete d[M].lineUp,Ze({tournamentId:r==null?void 0:r.tournamentId,context:`${f}-TEAM`,eventId:l==null?void 0:l.eventId,matchUp:o,drawDefinition:n}))}const y=Ir({matchUpId:o.matchUpId,inContextDrawMatchUps:t,drawDefinition:n}),{targetLinks:{winnerTargetLink:S},targetMatchUps:{loserMatchUp:O,winnerMatchUp:b,loserMatchUpDrawPositionIndex:w}}=y,$=e.filter(({drawPosition:U})=>{var C;return(C=o.drawPositions)==null?void 0:C.includes(U)}).filter(U=>U.bye).length,N=$&&nt||o.matchUpStatus&&[Xe,ot].includes(o.matchUpStatus)&&o.matcHUpStatus||((v=o.drawPositions)==null?void 0:v.length)===2&&Ft||void 0;o.matchUpStatus=N,o.matchUpStatus&&[ot,Xe].includes(o.matchUpStatus)&&(o.winningSide=void 0);const E=m==null?void 0:m.find(U=>{var C;return!((C=o.drawPositions)!=null&&C.includes(U))});if((m==null?void 0:m.includes(i))&&h===o.matchUpStatus&&g===o.winningSide||(E&&Jn(),Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:l==null?void 0:l.eventId,matchUp:o,context:`${f}-${i}`,drawDefinition:n})),O&&O.structureId!==y.matchUp.structureId&&!$){const{drawPositions:U,roundNumber:C}=O;if(C===1){const M=U[w];tm({structureId:O.structureId,drawPosition:M,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,matchUpsMap:s})}else{const M=Math.min(...U.filter(Boolean)),D=P6({loserMatchUpDrawPosition:M,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,loserMatchUp:O,matchUpsMap:s,event:l});if(D.error)return k({result:D,stack:f});const j=((s==null?void 0:s.mappedMatchUps)||{})[O.structureId].matchUps,{initialRoundNumber:G}=js({drawPosition:M,matchUps:j});G===1&&(Jn(),tm({structureId:O.structureId,drawPosition:M,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,matchUpsMap:s}))}}return b&&b.structureId!==y.matchUp.structureId&&S.target.feedProfile,pc({},V)}function P6({loserMatchUpDrawPosition:t,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,loserMatchUp:o,matchUpsMap:i,event:s}){const{structure:a}=Ne({structureId:o.structureId,drawDefinition:n}),{positionAssignments:l}=st({structure:a}),c=l==null?void 0:l.find(u=>u.drawPosition===t);if(c!=null&&c.bye){const u=Fa({drawPosition:t,structureId:o.structureId,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,matchUpsMap:i,event:s});if(u.error)return u}return pc({},V)}function y6({matchUpStatuses:t=[nt,ot,Xe],drawPositionMatchUps:e,loserDrawPosition:r,sourceMatchUps:n}){var o;const i=e==null?void 0:e.reduce((p,d)=>!p||d.roundNumber>p.roundNumber?d:p,void 0),s=(o=i==null?void 0:i.drawPositions)==null?void 0:o.find(p=>p!==r),a=n.filter(p=>{var d;return(d=p==null?void 0:p.drawPositions)==null?void 0:d.includes(s)}).map(p=>p.matchUpStatus),l=n.filter(p=>{var d;return(d=p==null?void 0:p.drawPositions)==null?void 0:d.includes(r)}).map(p=>p.matchUpStatus),c=Xt(a||[],t),u=Xt(l||[],t);return{sourceMatchUp:i,winnerHadMatchUpStatus:c,winnerMatchUpStatuses:a,loserHadMatchUpStatus:u,loserMatchUpStatuses:l}}var S6=Object.defineProperty,O6=Object.defineProperties,b6=Object.getOwnPropertyDescriptors,ZS=Object.getOwnPropertySymbols,T6=Object.prototype.hasOwnProperty,w6=Object.prototype.propertyIsEnumerable,XS=(t,e,r)=>e in t?S6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Wi=(t,e)=>{for(var r in e||(e={}))T6.call(e,r)&&XS(t,r,e[r]);if(ZS)for(var r of ZS(e))w6.call(e,r)&&XS(t,r,e[r]);return t},E6=(t,e)=>O6(t,b6(e));function xa(t){const{dualWinningSideChange:e,inContextDrawMatchUps:r,tournamentRecord:n,drawDefinition:o,matchUpStatus:i,matchUpsMap:s,dualMatchUp:a,targetData:l,matchUpId:c,structure:u,event:p}=t,d=!!t.matchUp.collectionId,v=Co({drawDefinition:o,structure:u}),{drawPositions:f,winningSide:m}=l.matchUp||{};if(!v&&!f)return{error:Zp};const{targetLinks:{loserTargetLink:h,winnerTargetLink:g,byeTargetLink:_},targetMatchUps:{loserMatchUp:I,winnerMatchUp:P,byeMatchUp:y}}=l,S=Kn(E6(Wi({},t),{matchUpStatus:i||Ft,removeWinningSide:!0}));if(S.error)return S;let O;if(d){const{matchUpTieId:D,matchUpsMap:R}=t;if(O=uo({matchUpId:D,tournamentRecord:n,drawDefinition:o,matchUpsMap:R,event:p}),!e&&!O.removeWinningSide)return Wi({},V)}if(v)return Wi({},V);const{matchUps:b}=Je({afterRecoveryTimes:!1,inContext:!0,drawDefinition:o,matchUpsMap:s,structure:u}),{positionAssignments:w}=Dt({structure:u}),T=m-1,$=1-T,N=f[T],E=f[$],{winnerParticipantId:A,loserParticipantId:U}=(w==null?void 0:w.reduce((D,R)=>(R.drawPosition===E&&(D.loserParticipantId=R.participantId),R.drawPosition===N&&(D.winnerParticipantId=R.participantId),D),{winnerParticipantId:void 0,loserParticipantId:void 0}))||{},C=b.filter(D=>{var R;return(R=D.drawPositions)==null?void 0:R.includes(E)});if(P&&eO({sourceMatchUpStatus:i,sourceMatchUpId:c,inContextDrawMatchUps:r,winningDrawPosition:N,winnerParticipantId:A,tournamentRecord:n,winnerTargetLink:g,drawDefinition:o,winnerMatchUp:P,dualMatchUp:a,matchUpsMap:s}),I){const{winnerHadMatchUpStatus:D}=y6({drawPositionMatchUps:C,loserDrawPosition:E,sourceMatchUps:b}),j=h.linkCondition===co;if(D&&j){const W=Math.min(...I.drawPositions);rm({targetLink:h,inContextDrawMatchUps:r,drawDefinition:o,drawPosition:W,matchUpsMap:s,event:p})}const G=$6({sourceMatchUpStatus:i,sourceMatchUpId:c,loserParticipantId:U,tournamentRecord:n,loserTargetLink:h,drawDefinition:o,loserMatchUp:I,dualMatchUp:a,matchUpsMap:s,event:p});if(G.error)return G}if(y){const D=Math.min(...y.drawPositions);rm({sourceMatchUpId:c,targetLink:_,inContextDrawMatchUps:r,drawDefinition:o,drawPosition:D,matchUpsMap:s,event:p})}const M=O&&{tieMatchUpResult:O};return Wi(Wi({},V),M)}function eO({inContextDrawMatchUps:t,winningDrawPosition:e,sourceMatchUpStatus:r,winnerParticipantId:n,tournamentRecord:o,winnerTargetLink:i,sourceMatchUpId:s,drawDefinition:a,winnerMatchUp:l,matchUpsMap:c,dualMatchUp:u,event:p}){var d;const{structureId:v,roundNumber:f}=l,m="removeDirectedWinner";if(i){const h=i.target.structureId,{structure:g}=Ne({drawDefinition:a,structureId:h});if(!g)return{error:bt};const{positionAssignments:_}=Dt({structure:g});g.seedAssignments=(g.seedAssignments||[]).filter(T=>T.participantId!==n);const I=_==null?void 0:_.find(T=>T.participantId===n),P=I==null?void 0:I.drawPosition,{matchUps:y}=Je({drawDefinition:a,structure:g,event:p}),S=y.map(T=>T.drawPositions).flat(1/0).filter(Boolean),O=Nr(S);if((P?O[P]:void 0)===1)_==null||_.forEach(T=>{T.participantId===n&&delete T.participantId});else{const T=y.filter(({drawPositions:$})=>$.includes(P));console.log("not removing from position assignments since instances > 1",{drawPositionMatchUps:T,winnerTargetLink:i})}const w=(d=c==null?void 0:c.drawMatchUps)==null?void 0:d.find(({matchUpId:T})=>T===l.matchUpId);w&&Ze({tournamentId:o==null?void 0:o.tournamentId,eventId:p==null?void 0:p.eventId,matchUp:w,context:m,drawDefinition:a})}return f&&d6({targetDrawPosition:e,inContextDrawMatchUps:t,sourceMatchUpStatus:r,tournamentRecord:o,sourceMatchUpId:s,drawDefinition:a,dualMatchUp:u,matchUpsMap:c,roundNumber:f,structureId:v}),Wi({},V)}function $6({sourceMatchUpStatus:t,loserParticipantId:e,tournamentRecord:r,loserTargetLink:n,sourceMatchUpId:o,drawDefinition:i,loserMatchUp:s,matchUpsMap:a,dualMatchUp:l,event:c}){var u,p,d;const v="removeDirectedLoser",f=n.target.structureId,{structure:m}=Ne({drawDefinition:i,structureId:f});if(!m)return{error:bt};const{positionAssignments:h}=Dt({structure:m}),g=(u=h==null?void 0:h.find(_=>_.participantId===e))==null?void 0:u.drawPosition;if(h==null||h.forEach(_=>{_.participantId===e&&delete _.participantId}),m.seedAssignments=(m.seedAssignments||[]).filter(_=>_.participantId!==e),l){const _=s==null?void 0:s.sides.reduce((y,S,O)=>S.drawPosition===g?O:y,void 0),I=(p=a==null?void 0:a.drawMatchUps)==null?void 0:p.find(({matchUpId:y})=>y===s.matchUpId),P=(d=I==null?void 0:I.sides)==null?void 0:d[_];P&&(delete P.lineUp,Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:c==null?void 0:c.eventId,matchUp:I,context:v,drawDefinition:i}))}return Wi({},V)}function rm({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,matchUpsMap:o,targetLink:i,event:s}){const a=i.target.structureId;return Fa({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:o,drawPosition:n,structureId:a,event:s}),Wi({},V)}function tO(t){let{sourceMatchUp:e}=t;const{targetMatchUp:r,structure:n,matchUpsMap:o,drawPosition:i}=t,s=r.roundNumber>1&&r.roundNumber-1,a=xi({structureId:n.structureId,matchUpsMap:o});!e&&i&&(e=a.find(({drawPositions:f,roundNumber:m})=>m===s&&(f==null?void 0:f.includes(i))));const l=e==null?void 0:e.roundPosition,c=l%2?1:-1,u=l+c,p=s&&a.find(({roundNumber:f,roundPosition:m})=>f===s&&m===u),d=p==null?void 0:p.matchUpStatus,v=[Rt,tr].includes(d);return{pairedPreviousMatchUp:p,pairedPreviousMatchUpIsDoubleExit:v}}function fd({drawDefinition:t,positionAction:e}){var r;const{extension:n}=xr({name:vu,element:t}),o=Array.isArray(n==null?void 0:n.value)?(n==null?void 0:n.value)||[]:[];if(!(o!=null&&o.length)){const s=t.structures.find(a=>a.stage===he);if(s){const a=(r=st({structure:s}).positionAssignments)==null?void 0:r.map(({drawPosition:l,participantId:c,bye:u,qualifier:p})=>({drawPosition:l,participantId:c,qualifier:p,bye:u}));o.push({name:"initialMainAssignments",initialAssignments:a})}}const i={name:vu,value:o.concat(e)};it({element:t,extension:i})}var N6=Object.defineProperty,rO=Object.getOwnPropertySymbols,U6=Object.prototype.hasOwnProperty,A6=Object.prototype.propertyIsEnumerable,nO=(t,e,r)=>e in t?N6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vd=(t,e)=>{for(var r in e||(e={}))U6.call(e,r)&&nO(t,r,e[r]);if(rO)for(var r of rO(e))A6.call(e,r)&&nO(t,r,e[r]);return t};function Yr({provisionalPositioning:t,isPositionAction:e,tournamentRecord:r,drawDefinition:n,drawPosition:o,matchUpsMap:i,structureId:s,structure:a,event:l}){var c;if(!n)return{error:ue};if(a||({structure:a}=Ne({drawDefinition:n,structureId:s})),!a)return{error:bt};s||({structureId:s}=a);const u="assignDrawPositionBye";Jn(),i||(i=lr({drawDefinition:n}));const{positionAssignments:p}=st({structure:a}),{activeDrawPositions:d}=dc({drawDefinition:n,structureId:s}),v=p==null?void 0:p.find(N=>N.drawPosition===o);if(v!=null&&v.bye)return vd({},V);if(d==null?void 0:d.includes(o))return{error:Xp};const m=p==null?void 0:p.find(N=>N.drawPosition===o);if(!m)return{error:ta};const{filled:h,containsBye:g,assignedParticipantId:_}=C6(m);if(g)return vd({},V);if(h&&!g)return k({result:{error:dl},stack:u});const I=Lt({inContext:!0,drawDefinition:n,matchUpsMap:i}).matchUps||[],P={isCollectionMatchUp:!1},{matchUps:y}=Je({provisionalPositioning:t,drawDefinition:n,matchUpFilters:P,matchUpsMap:i,structure:a});if(p==null||p.forEach(N=>{N.drawPosition===o&&(N.bye=!0)}),a.structureType===gr)return M6({tournamentRecord:r,drawDefinition:n,drawPosition:o,matchUps:y}),oi({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:n,structure:a,event:l}),oO({assignedParticipantId:_,isPositionAction:e,drawDefinition:n,drawPosition:o,structureId:s,stack:u});const{roundProfile:S,roundMatchUps:O}=Tr({matchUps:y}),b=S&&Object.keys(S).map(N=>parseInt(N)).reverse(),w=b==null?void 0:b.find(N=>{var E;return(E=S==null?void 0:S[N].drawPositions)==null?void 0:E.includes(o)}),T=w&&(O==null?void 0:O[w].find(({drawPositions:N})=>N==null?void 0:N.includes(o)));iO({tournamentRecord:r,drawDefinition:n,matchUp:T,event:l});const $=(c=T.drawPositions)==null?void 0:c.find(N=>N!==o);if($){const N=nm({sourceDrawPositions:T.drawPositions,matchUpId:T.matchUpId,inContextDrawMatchUps:I,drawPositionToAdvance:$,tournamentRecord:r,drawDefinition:n,matchUpsMap:i});if(N.error)return N}return oi({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:n,structure:a,event:l}),oO({assignedParticipantId:_,isPositionAction:e,drawDefinition:n,drawPosition:o,structureId:s,stack:u})}function oO({assignedParticipantId:t,isPositionAction:e,drawDefinition:r,drawPosition:n,structureId:o,stack:i}){return e&&fd({drawDefinition:r,positionAction:{removedParticipantId:t,drawPosition:n,structureId:o,name:i}}),k({result:vd({},V),stack:i})}function C6(t){const e=t.bye,r=t.qualifier,n=t.participantId;return{containsBye:e,containsQualifier:r,assignedParticipantId:n,filled:e||r||n}}function iO({tournamentRecord:t,drawDefinition:e,eventId:r,matchUp:n,event:o}){Object.assign(n,{matchUpStatus:nt,score:void 0,winningSide:void 0}),Ze({tournamentId:t==null?void 0:t.tournamentId,eventId:r??(o==null?void 0:o.eventId),context:"setMatchUpStatusBye",drawDefinition:e,matchUp:n})}function M6({tournamentRecord:t,drawDefinition:e,drawPosition:r,matchUps:n,event:o}){n.forEach(i=>{var s;(s=i.drawPositions)!=null&&s.includes(r)&&iO({eventId:o==null?void 0:o.eventId,tournamentRecord:t,drawDefinition:e,matchUp:i})})}function nm({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,matchUpsMap:i,matchUpId:s,event:a}){var l;Jn();const c=i.drawMatchUps.find(y=>y.matchUpId===s),u=e.find(y=>y.matchUpId===s),p=u==null?void 0:u.structureId,{structure:d}=Ne({drawDefinition:o,structureId:p}),{positionAssignments:v}=st({structure:d}),f=v==null?void 0:v.filter(y=>y.bye).map(y=>y.drawPosition),m=(l=c==null?void 0:c.drawPositions)==null?void 0:l.find(y=>y!==t),h=m&&(f==null?void 0:f.includes(m)),{targetLinks:{loserTargetLink:g},targetMatchUps:{loserMatchUp:_,winnerMatchUp:I,loserTargetDrawPosition:P}}=Ir({inContextDrawMatchUps:e,drawDefinition:o,matchUpId:s});if(I&&I.structureId===(d==null?void 0:d.structureId)&&D6({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,winnerMatchUp:I,matchUpsMap:i,event:a}),_&&h&&_.structureId!==(d==null?void 0:d.structureId)){const{roundNumber:y}=_;if(y===1){const S=Yr({structureId:g.target.structureId,drawPosition:P,tournamentRecord:n,drawDefinition:o,event:a});if(S.error)return S}else sO({loserTargetDrawPosition:P,tournamentRecord:n,loserTargetLink:g,drawDefinition:o,loserMatchUp:_,matchUpsMap:i,event:a})}return vd({},V)}function D6({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,winnerMatchUp:i,matchUpsMap:s,event:a}){var l,c,u;const p="advanceWinner",d=s.drawMatchUps.find(j=>j.matchUpId===i.matchUpId),v=e.find(j=>j.matchUpId===i.matchUpId),f=v==null?void 0:v.structureId,{structure:m}=Ne({drawDefinition:o,structureId:f}),{positionAssignments:h}=st({structure:m}),g=h==null?void 0:h.find(({drawPosition:j})=>j===t),_=g==null?void 0:g.bye,I=(l=d.drawPositions)==null?void 0:l.filter(Boolean),P=h==null?void 0:h.filter(j=>I==null?void 0:I.includes(j.drawPosition)),y=h==null?void 0:h.find(({drawPosition:j})=>j===t),S=r==null?void 0:r.find(j=>j!==t),O=S&&(P==null?void 0:P.find(({drawPosition:j})=>j===S)),b=O==null?void 0:O.bye,w=_&&b;if(w&&console.log({isByeAdvancedBye:w}),(I==null?void 0:I.length)>1&&_&&!b)return k({result:{error:dl},stack:p});const T=I==null?void 0:I.find(j=>j!==t);let $=w;const N=[...(d.drawPositions||[]).filter(Boolean),void 0,void 0].slice(0,2),E=N.map(j=>!j&&!$||j===t?($=!0,t):j).sort(er);if(!$)return console.log("@@@@@@@",{advancingAssignmentIsBye:y,drawPositionToAdvance:t,existingAssignments:P}),k({result:{error:dl},stack:p});const A=(c=h==null?void 0:h.find(({drawPosition:j})=>j===T))==null?void 0:c.bye,U=(u=h==null?void 0:h.find(({drawPosition:j})=>j===t))==null?void 0:u.bye;Object.assign(d,{matchUpStatus:U||A?nt:Ft,score:void 0,winningSide:void 0,drawPositions:E}),d.drawPositions.find(j=>!N.includes(j)),Jn(),Ze({tournamentId:n==null?void 0:n.tournamentId,matchUp:d,eventId:a==null?void 0:a.eventId,context:p,drawDefinition:o});const{targetLinks:{loserTargetLink:M},targetMatchUps:{loserMatchUp:D,loserTargetDrawPosition:R}}=Ir({matchUpId:i.matchUpId,inContextDrawMatchUps:e,drawDefinition:o});if(A||U){const j=A?t:T;if(j)nm({drawPositionToAdvance:j,matchUpId:i.matchUpId,inContextDrawMatchUps:e,tournamentRecord:n,drawDefinition:o,matchUpsMap:s});else if(U&&M&&D)if(D.feedRound)sO({loserTargetDrawPosition:R,tournamentRecord:n,loserTargetLink:M,drawDefinition:o,loserMatchUp:D,matchUpsMap:s});else{const W=1-i.roundPosition%2,q=D.drawPositions[W],F=Yr({structureId:M.target.structureId,drawPosition:q,tournamentRecord:n,drawDefinition:o,event:a});if(F.error)return F}}}function sO({loserTargetDrawPosition:t,tournamentRecord:e,loserTargetLink:r,drawDefinition:n,loserMatchUp:o,matchUpsMap:i,event:s}){const{roundNumber:a}=o;Jn();const c=((i==null?void 0:i.mappedMatchUps)||{})[o.structureId].matchUps,{initialRoundNumber:u}=js({drawPosition:t,matchUps:c});if(u===a){const p=Yr({structureId:r.target.structureId,drawPosition:t,tournamentRecord:e,drawDefinition:n,event:s});if(p.error)return p}}var j6=Object.defineProperty,R6=Object.defineProperties,F6=Object.getOwnPropertyDescriptors,aO=Object.getOwnPropertySymbols,x6=Object.prototype.hasOwnProperty,L6=Object.prototype.propertyIsEnumerable,lO=(t,e,r)=>e in t?j6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,V6=(t,e)=>{for(var r in e||(e={}))x6.call(e,r)&&lO(t,r,e[r]);if(aO)for(var r of aO(e))L6.call(e,r)&&lO(t,r,e[r]);return t},B6=(t,e)=>R6(t,F6(e));function om({inContextTargetMatchUp:t,drawPositionSideIndex:e,teamParticipantId:r,tournamentRecord:n,drawDefinition:o,matchUp:i,event:s}){var a,l,c,u;const p=(l=(a=t==null?void 0:t.sides)==null?void 0:a[e])==null?void 0:l.sideNumber,d=p&&((c=i.sides)==null?void 0:c.find(h=>h.sideNumber===p)),{extension:v}=Kt({element:o,name:kn}),m=((v==null?void 0:v.value)||{})[r];if(d)(u=i==null?void 0:i.sides)==null||u.forEach(h=>{h.sideNumber===p&&(h.lineUp=m)});else{i.sides=[1,2].map(g=>{var _;const I=((_=i.sides)==null?void 0:_.find(P=>P.sideNumber===g))||{};return B6(V6({},I),{sideNumber:g})});const h=i.sides.find(g=>g.sideNumber===p);h&&(h.lineUp=m)}Ze({tournamentId:n==null?void 0:n.tournamentId,context:"updateSidLineUps",eventId:s==null?void 0:s.eventId,drawDefinition:o,matchUp:i})}function k6({drawPosition:t,drawPositions:e}){let r=!1,n=!!(e!=null&&e.includes(t));return{updatedDrawPositions:n?e||[]:[...e,void 0,void 0].slice(0,2).map(s=>!s&&!n?(n=!0,r=!0,t):s).sort(er).filter(Boolean),positionAdded:r,positionAssigned:n}}function md({inContextDrawMatchUps:t,drawPosition:e,matchUpId:r}){const n=t.filter(({winnerMatchUpId:s,loserMatchUpId:a})=>a===r||s===r).sort((s,a)=>s.roundPosition-a.roundPosition);return t.find(s=>s.matchUpId===r).feedRound?1:n.reduce((s,a,l)=>{var c;return(c=a.drawPositions)!=null&&c.includes(e)?l+1:s},void 0)}var G6=Object.defineProperty,cO=Object.getOwnPropertySymbols,W6=Object.prototype.hasOwnProperty,H6=Object.prototype.propertyIsEnumerable,uO=(t,e,r)=>e in t?G6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,q6=(t,e)=>{for(var r in e||(e={}))W6.call(e,r)&&uO(t,r,e[r]);if(cO)for(var r of cO(e))H6.call(e,r)&&uO(t,r,e[r]);return t};function La({inContextDrawMatchUps:t,sourceMatchUpStatus:e,tournamentRecord:r,sourceMatchUpId:n,drawDefinition:o,matchUpStatus:i,drawPosition:s,matchUpsMap:a,matchUpId:l,event:c}){var u,p,d;const v="assignMatchUpDrawPosition";a||(a=lr({drawDefinition:o})),t||(t=Lt({inContext:!0,drawDefinition:o,matchUpsMap:a}).matchUps||[]);const f=t.find(C=>C.matchUpId===l),m=f==null?void 0:f.structureId,h=(u=o==null?void 0:o.structures)==null?void 0:u.find(C=>C.structureId===m);if(!h)return{error:bt};const g=(p=a==null?void 0:a.drawMatchUps)==null?void 0:p.find(C=>C.matchUpId===l),_=(g==null?void 0:g.drawPositions)||[],{positionAdded:I,positionAssigned:P,updatedDrawPositions:y}=k6({drawPosition:s,drawPositions:_}),{positionAssignments:S}=st({drawDefinition:o,structure:h}),O=S==null?void 0:S.filter(C=>y.includes(C.drawPosition)),b=O==null?void 0:O.find(({bye:C})=>C),w=(g==null?void 0:g.matchUpStatus)&&[ot,Xe].includes(g.matchUpStatus)&&y.filter(Boolean).length<2;if(i=b&&nt||i||w&&g.matchUpStatus||(g==null?void 0:g.matchUpStatus)&&[Rt,tr].includes(g.matchUpStatus)&&g.matchUpStatus||Ft,g&&I){t=Lt({inContext:!0,drawDefinition:o,matchUpsMap:a}).matchUps||[];const C=w&&md({inContextDrawMatchUps:t,drawPosition:s,matchUpId:l})||void 0;g!=null&&g.matchUpStatusCodes&&HS({inContextDrawMatchUps:t,sourceMatchUpStatus:e,sourceMatchUpId:n,matchUpsMap:a,matchUp:g}),Object.assign(g,{drawPositions:y,winningSide:C,matchUpStatus:i}),Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:f==null?void 0:f.eventId,context:v,drawDefinition:o,matchUp:g})}const T=Ir({inContextDrawMatchUps:t,inContextMatchUp:f,drawDefinition:o,matchUpId:l}),{targetMatchUps:{winnerMatchUp:$,loserMatchUp:N,loserTargetDrawPosition:E},targetLinks:{loserTargetLink:A}}=T,U=xi({structureId:h.structureId,matchUpsMap:a});if(P&&b){if($)if([nt,Rt,tr].includes(i)){const C=La({matchUpId:$.matchUpId,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:o,drawPosition:s,matchUpsMap:a});if(C.error)return C}else{const{structureId:C}=$;C!==h.structureId&&console.log("winnerMatchUp in different structure... participant is in different targetDrawPosition")}}else if($&&f&&!f.feedRound){const{pairedPreviousMatchUpIsDoubleExit:C}=tO({targetMatchUp:g,drawPosition:s,matchUpsMap:a,structure:h});if(C){const M=La({matchUpId:$.matchUpId,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:o,drawPosition:s,matchUpsMap:a});if(M.error)return M}}if((g==null?void 0:g.matchUpType)===Qe){const C=t==null?void 0:t.find(({matchUpId:j})=>j===g.matchUpId),D=((C==null?void 0:C.sides)||[]).reduce((j,G,W)=>G.drawPosition===s?W:j,void 0),R=(d=S==null?void 0:S.find(j=>j.drawPosition===s))==null?void 0:d.participantId;R&&D!==void 0&&om({inContextTargetMatchUp:C,drawPositionSideIndex:D,teamParticipantId:R,tournamentRecord:r,drawDefinition:o,matchUp:g})}if((A==null?void 0:A.linkCondition)===co&&y.filter(Boolean).length===2&&!b&&U.filter(({drawPositions:D,roundNumber:R})=>R===1&&Xt(D,y)).every(({matchUpStatus:D})=>[Mt,_r].includes(D))&&N){const{structureId:D}=N,R=Yr({drawPosition:E,tournamentRecord:r,drawDefinition:o,structureId:D,matchUpsMap:a,event:c});if(R.error)return R}return P?q6({},V):k({result:{error:dl},context:{drawPosition:s},stack:v})}var z6=Object.defineProperty,Y6=Object.defineProperties,K6=Object.getOwnPropertyDescriptors,dO=Object.getOwnPropertySymbols,Q6=Object.prototype.hasOwnProperty,J6=Object.prototype.propertyIsEnumerable,pO=(t,e,r)=>e in t?z6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mo=(t,e)=>{for(var r in e||(e={}))Q6.call(e,r)&&pO(t,r,e[r]);if(dO)for(var r of dO(e))J6.call(e,r)&&pO(t,r,e[r]);return t},Va=(t,e)=>Y6(t,K6(e));function fc(t){var e;const{tournamentRecord:r,appliedPolicies:n,drawDefinition:o,matchUpsMap:i,targetData:s,structure:a,event:l}=t,c="doubleExitAdvancement";if(a.structureType===gr)return k({result:mo({},V),stack:c});const{matchUp:u,targetMatchUps:p,targetLinks:d}=s,{loserMatchUp:v,winnerMatchUp:f,loserTargetDrawPosition:m}=p;if(v&&v.matchUpStatus!==ut.Bye){const{loserTargetLink:h}=d;if((e=n==null?void 0:n.progression)!=null&&e.doubleExitPropagateBye){const g=vO({loserTargetDrawPosition:m,tournamentRecord:r,loserTargetLink:h,drawDefinition:o,loserMatchUp:v,matchUpsMap:i,event:l});if(g.error)return k({result:g,stack:c})}else{const{feedRound:g,drawPositions:_,matchUpId:I}=v,P=g?2:2-_.indexOf(m),y=fO(Va(mo({},t),{targetMatchUp:v,walkoverWinningSide:P,tournamentRecord:r,sourceMatchUp:u,matchUpId:I}));if(y.error)return k({result:y,stack:c})}}if(f){const h=fO(Va(mo({},t),{matchUpId:f.matchUpId,targetMatchUp:f,tournamentRecord:r,sourceMatchUp:u}));if(h.error)return k({result:h,stack:c})}return k({result:mo({},V),stack:c})}function fO(t){var e,r,n;const{inContextDrawMatchUps:o,tournamentRecord:i,drawDefinition:s,sourceMatchUp:a,targetMatchUp:l,matchUpsMap:c}=t,u=s.structures.find(({structureId:z})=>z===l.structureId),p=t.matchUpStatus===ut.DoubleDefault?ut.DoubleDefault:ut.DoubleWalkover,d=t.matchUpStatus===ut.DoubleDefault?ut.Defaulted:ut.Walkover,v="conditionallyAdvanceDrawPosition",f=c.drawMatchUps.find(z=>z.matchUpId===l.matchUpId);if(!f)return{error:jr};const m=(a==null?void 0:a.drawPositions)||[];let h=(e=f.drawPositions)==null?void 0:e.filter(Boolean);const g=(a==null?void 0:a.structureId)===l.structureId;if(g&&Xt(m,h)&&(h=h.filter(z=>!m.includes(z))),g&&h.length>1)return k({result:{error:dl},stack:v});const{pairedPreviousMatchUpIsDoubleExit:_,pairedPreviousMatchUp:I}=tO(t),P=Ir({matchUpId:l.matchUpId,inContextDrawMatchUps:o,drawDefinition:s}),{targetMatchUps:y,targetLinks:S}=P,{loserTargetDrawPosition:O,winnerMatchUp:b,loserMatchUp:w}=y;if(w){const{loserTargetLink:z}=S,H=vO({loserTargetDrawPosition:O,loserMatchUp:w,tournamentRecord:i,loserTargetLink:z,drawDefinition:s,matchUpsMap:c});if(H.error)return k({result:H,stack:v})}const T=((r=f.drawPositions)==null?void 0:r.filter(Boolean))||[],$=T.length===1,N=t.walkoverWinningSide||$&&md({drawPosition:T[0],matchUpId:l.matchUpId,inContextDrawMatchUps:o})||void 0,E=[ut.Walkover,ut.Defaulted].includes(f.matchUpStatus)&&!T.length,A=f.finishingRound===1,U=E&&!A?p:d,C=o.find(z=>z.matchUpId===I.matchUpId);let M=[],D;a&&((a==null?void 0:a.structureId)===(C==null?void 0:C.structureId)?a.roundPosition<(I==null?void 0:I.roundPosition)?D=1:D=2:l.feedRound?a.structureId===l.structureId?D=2:D=1:N&&(D=3-N));const R=t.matchUpStatus,j=I==null?void 0:I.matchUpStatus;D===1?M=[{matchUpStatus:hd(R),previousMatchUpStatus:R,sideNumber:1},{matchUpStatus:hd(j),previousMatchUpStatus:j,sideNumber:2}]:D===2&&(M=[{matchUpStatus:hd(j),previousMatchUpStatus:j,sideNumber:1},{matchUpStatus:hd(R),previousMatchUpStatus:R,sideNumber:2}]),M.length&&(M=M.map(z=>Oe(z)));const G=Kn(Va(mo({},t),{matchUp:f,winningSide:N,matchUpStatusCodes:M,matchUpStatus:U}));if(G.error)return k({result:G,stack:v});if(E)return fc(Va(mo({},t),{matchUpStatus:U,targetData:P}));if(!b)return k({result:mo({},V),stack:v});const W=h.length===2?h[N-1]:h[0],{positionAssignments:q}=st({structure:u}),F=q==null?void 0:q.find(z=>z.drawPosition===W),L=c.drawMatchUps.find(z=>z.matchUpId===b.matchUpId),x=(n=L==null?void 0:L.drawPositions)==null?void 0:n.filter(Boolean),B=x.length===1;if(W){if(F!=null&&F.bye){const z=Ir({matchUpId:L.matchUpId,inContextDrawMatchUps:o,drawDefinition:s});if(B){const H=x.filter(Boolean)[0],Y=md({drawPosition:H,matchUpId:L.matchUpId,inContextDrawMatchUps:o}),Z=Kn({matchUpId:L.matchUpId,matchUp:L,matchUpStatus:d,matchUpStatusCodes:[],removeScore:!0,drawDefinition:s,winningSide:Y});return Z.error?k({result:Z,stack:v}):nm({drawPositionToAdvance:H,matchUpId:L.matchUpId,inContextDrawMatchUps:o,drawDefinition:s,matchUpsMap:c})}else if([ut.Walkover,ut.Defaulted].includes(b.matchUpStatus)){const H=fc(Va(mo({},t),{matchUpId:L.matchUpId,matchUpStatus:U,targetData:z}));if(H.error)return k({result:H,stack:v})}return k({result:mo({},V),stack:v})}return La({matchUpId:b.matchUpId,drawPosition:W,inContextDrawMatchUps:o,drawDefinition:s})}else if(_){if(!L)return{error:jr};if(B){const Y=x[0],Z=md({matchUpId:l.matchUpId,inContextDrawMatchUps:o,drawPosition:Y});console.log("existing drawPosition is winningSide",{walkoverWinningSide:Z})}const z=[ut.Walkover,ut.Defaulted].includes(L.matchUpStatus)?d:p,H=Kn({matchUpId:L.matchUpId,matchUp:L,matchUpStatusCodes:[],removeScore:!0,drawDefinition:s,matchUpStatus:z});if(H.error)return k({result:H,stack:v});if(z===p){const Y=fc(Va(mo({},t),{matchUpId:l.matchUpId,matchUpStatus:z,targetData:P}));if(Y.error)return Y}}return k({result:mo({},V),stack:v})}function vO(t){var e;const{loserTargetDrawPosition:r,tournamentRecord:n,loserTargetLink:o,drawDefinition:i,matchUpsMap:s,event:a}=t,l=(e=o==null?void 0:o.target)==null?void 0:e.structureId,{structure:c}=Ne({drawDefinition:i,structureId:l});return c?Yr({drawPosition:r,tournamentRecord:n,drawDefinition:i,structureId:l,matchUpsMap:s,event:a}):{error:ra}}function hd(t){return t===ut.DoubleWalkover?ut.Walkover:t===ut.DoubleDefault?ut.Defaulted:t}var Z6=Object.defineProperty,mO=Object.getOwnPropertySymbols,X6=Object.prototype.hasOwnProperty,e5=Object.prototype.propertyIsEnumerable,hO=(t,e,r)=>e in t?Z6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,t5=(t,e)=>{for(var r in e||(e={}))X6.call(e,r)&&hO(t,r,e[r]);if(mO)for(var r of mO(e))e5.call(e,r)&&hO(t,r,e[r]);return t};function r5({tournamentRecord:t,drawDefinition:e,structure:r,matchUp:n}){var o;const i="attemptToSetMatchUpStatusBYE";if(n!=null&&n.winningSide)return k({result:{error:fl},context:{matchUpStatus:nt},stack:i});const{positionAssignments:s}=Dt({structure:r}),a=s==null?void 0:s.filter(c=>c.bye).map(c=>c.drawPosition);return((o=n.drawPositions)==null?void 0:o.some(c=>a==null?void 0:a.includes(c)))?(n.matchUpStatus=nt,n.matchUpStatusCodes=[],Ze({tournamentId:t==null?void 0:t.tournamentId,context:i,drawDefinition:e,matchUp:n}),t5({},V)):k({result:{error:fx},info:"matchUp does not include BYE",stack:i})}var n5=Object.defineProperty,o5=Object.defineProperties,i5=Object.getOwnPropertyDescriptors,gO=Object.getOwnPropertySymbols,s5=Object.prototype.hasOwnProperty,a5=Object.prototype.propertyIsEnumerable,_O=(t,e,r)=>e in t?n5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,IO=(t,e)=>{for(var r in e||(e={}))s5.call(e,r)&&_O(t,r,e[r]);if(gO)for(var r of gO(e))a5.call(e,r)&&_O(t,r,e[r]);return t},PO=(t,e)=>o5(t,i5(e));function l5(t){const{tournamentRecord:e,drawDefinition:r,matchUpStatus:n,structure:o,matchUp:i}=t,s=!!(i.tieMatchUps&&!i.rondPosition&&t.inContextDrawMatchUps.find(g=>g.matchUpId===i.matchUpId).containerStructureId),a="attemptToSetMatchUpStatus",l=n===nt,c=i.winningSide,u=[Rt,tr].includes(n),p=rc({matchUpStatus:n}),d=pv({matchUpStatus:n}),v=!p&&!d,f=t.matchUpTieId||c&&p&&!u,m=c&&u,h=()=>Kn(PO(IO({},t),{removeScore:[Ho,ot].includes(n),matchUpStatus:n||Ft}));return v&&{error:Jg}||f&&im(t)||m&&c5(t)||c&&xa(t)||d&&h()||l&&r5({tournamentRecord:e,drawDefinition:r,structure:o,matchUp:i})||!p&&{error:Jg}||u&&u5(t)||s&&im(t)||k({result:{error:fl},stack:a})}function c5(t){const e=xa(t);return e.error?e:fc(t)}function u5(t){const e=im(PO(IO({},t),{removeScore:!0}));return e.error?e:fc(t)}function im(t){var e;const r="scoreModification";if(t.isCollectionMatchUp&&((e=t.dualMatchUp)==null?void 0:e.winningSide)&&!t.projectedWinningSide){const s=xa(t);if(s.error)return k({result:s,stack:r})}const o=!!t.matchUp.collectionId,i=Kn(t);if(o){const{matchUpTieId:s,drawDefinition:a,matchUpsMap:l}=t,c=uo({tournamentRecord:t.tournamentRecord,matchUpId:s,event:t.event,drawDefinition:a,matchUpsMap:l});if(c.error)return k({result:c,stack:r});Object.assign(i,{tieMatchUpResult:c})}return k({result:i,stack:r})}function d5({drawDefinition:t,structure:e,matchUp:r}){var n,o;const{drawPositions:i}=r,{positionAssignments:s}=st({drawDefinition:t,structure:e}),a=s==null?void 0:s.filter(({drawPosition:v})=>i==null?void 0:i.includes(v)),l=a==null?void 0:a.map(v=>{var f;const{extension:m}=Kt({element:v,name:Ko});return(f=m==null?void 0:m.value)==null?void 0:f.groupOrder}),{containerStructures:c}=Ra({drawDefinition:t}),u=c[e.structureId],p=(o=(n=ic({drawDefinition:t,structureId:u}))==null?void 0:n.links)==null?void 0:o.source;return{structureIds:p==null?void 0:p.filter(v=>{var f;return Xt(l,((f=v.source)==null?void 0:f.finishingPositions)||[])}).map(v=>v.source.structureId)}}function yO({drawDefinition:t,structureId:e}){if(!t)return{error:ue};const{structure:r}=Ne({drawDefinition:t,structureId:e}),n=((t==null?void 0:t.links)||[]).filter(i=>{var s;return((s=i.source)==null?void 0:s.structureId)===e}).map(i=>{var s;return(s=i.target)==null?void 0:s.structureId});return{playoffStructures:((t==null?void 0:t.structures)||[]).filter(i=>n.includes(i.structureId)&&i.stage===ft),structure:r}}function SO({withStageGrouping:t,stageSequences:e,stageSequence:r,roundTarget:n,stages:o,event:i,stage:s}){if(!i)return{error:Ge};const a={},l=[];for(const c of i.drawDefinitions||[]){const{structures:u,stageStructures:p}=an({withStageGrouping:t,stageSequences:e,drawDefinition:c,stageSequence:r,roundTarget:n,stages:o,stage:s});if(l.push(...u),p)for(const d of Object.keys(p))a[d]||(a[d]=[]),a[d].push(...p[d])}return{structures:l,stageStructures:a}}function p5({withStageGrouping:t,tournamentRecord:e,stageSequences:r,stageSequence:n,roundTarget:o,stages:i,stage:s}){if(!e)return{error:re};const a={},l=[];for(const c of e.events||[]){const{structures:u,stageStructures:p}=SO({withStageGrouping:t,stageSequences:r,stageSequence:n,roundTarget:o,stages:i,event:c,stage:s});if(u&&l.push(...u),p)for(const d of Object.keys(p))a[d]||(a[d]=[]),a[d].push(...p[d])}return{structures:l,stageStructures:a}}function f5(t){const e=[];if(!(t!=null&&t.drawDefinition))return{error:ue};const r=Hi(t),n=OO(t);return{actions:e,state:{isComplete:r,hasPlayoffPositionsFilled:n}}}function Hi(t){if(!(t!=null&&t.drawDefinition))return!1;const e=sc(t),r=e==null?void 0:e.includesTeamMatchUps;let{completedMatchUps:n,pendingMatchUps:o,upcomingMatchUps:i}=e||{};return r&&(n=n==null?void 0:n.filter(({matchUpType:a})=>a===Qe),o=o==null?void 0:o.filter(({matchUpType:a})=>a===Qe),i=i==null?void 0:i.filter(({matchUpType:a})=>a===Qe)),!!((n==null?void 0:n.length)&&!(o!=null&&o.length)&&!(i!=null&&i.length))}function OO(t){var e,r;const{drawDefinition:n,structureId:o}=t;if(!n)return{error:ue};const{playoffStructures:i}=yO({drawDefinition:n,structureId:o});if(!(i!=null&&i.length))return!1;const s=((r=(e=n==null?void 0:n.entries)==null?void 0:e.filter(u=>Fi.includes(u==null?void 0:u.entryStatus)))==null?void 0:r.length)||0;let a=0;return(i||[]).reduce((u,p)=>{var d;return!((d=p==null?void 0:p.positionAssignments)!=null&&d.filter(f=>(f.participantId&&a++,!(f!=null&&f.bye)&&!(f!=null&&f.participantId))).length)&&u},!0)||a===s}function bO({drawDefinition:t,structure:e,matchUp:r}){const n=[];if(e.finishingPosition===ya&&Hi({drawDefinition:t,structure:e})){const{structureIds:i}=d5({drawDefinition:t,structure:e,matchUp:r});i!=null&&i.length&&n.push(...i)}return{connectedStructureIds:n}}function sm(t){const{dualWinningSideChange:e,matchUpStatusCodes:r,tournamentRecord:n,drawDefinition:o,matchUpFormat:i,matchUpStatus:s,winningSide:a,matchUpId:l,structure:c,matchUp:u,event:p,score:d}=t,v=rc({matchUpStatus:s})||[Ho,Wr].includes(s)&&e,f="attemptToModifyScore",m=!!u.collectionId,h=Co({drawDefinition:o,structure:c});if(!(m||h||v5({structure:c,matchUp:u})))return{error:Kg};const _=[ot].includes(s),I=Kn({matchUpStatusCodes:v&&r||[],matchUpStatus:v&&s||Mt,tournamentRecord:n,drawDefinition:o,matchUpFormat:i,removeScore:_,winningSide:a,matchUpId:l,matchUp:u,event:p,score:d});return k({result:I,stack:f})}function v5({structure:t,matchUp:e}){const{drawPositions:r}=e,{positionAssignments:n}=Dt({structure:t}),o=n==null?void 0:n.filter(i=>(r==null?void 0:r.includes(i.drawPosition))&&i.participantId);return(o==null?void 0:o.length)===2}function am({lineUp:t}){if(!Array.isArray(t))return;const e={};return We(t.flatMap(({collectionAssignments:n})=>n.map(({collectionId:o,collectionPosition:i})=>[o,i].join("|")))).forEach(n=>{const[o,i]=n.split("|"),s=parseInt(i),{assignedParticipantIds:a}=Uu({collectionPosition:s,collectionId:o,lineUp:t});a.forEach(l=>{e[l]||(e[l]=[]),e[l].push({collectionId:o,collectionPosition:s})})}),Object.keys(e).map(n=>({participantId:n,collectionAssignments:e[n]}))}function Ba(t){if(!t)return 1/0;if(ht(t))return Te(t);const e=t.split("-")[0];return ht(e)?Te(e):1/0}const Zt=({finishingPosition:t=ji,qualifyingRoundNumber:e,structureAbbreviation:r,seedAssignments:n=[],stageSequence:o=1,structureOrder:i,seedingProfile:s,matchUpFormat:a,structureType:l,structureName:c,matchUpType:u,matchUps:p=[],structureId:d,roundOffset:v,roundLimit:f,stageOrder:m,structures:h,stage:g})=>{const _={structureId:d??Ye(),structureAbbreviation:r,finishingPosition:t,seedAssignments:n,matchUpFormat:a,stageSequence:o,structureName:c};i&&(_.structureOrder=i),l&&(_.structureType=l),s&&(typeof s=="string"?_.seedingProfile=s:typeof s=="object"&&typeof s.positioning=="string"&&(_.seedingProfile=s.positioning)),u&&(_.matchUpType=u),v&&(_.roundOffset=v),m&&(_.stageOrder=m),f&&(_.roundLimit=f),g&&(_.stage=g),e&&(_.qualifyingRoundNumber=e);const I=p.flatMap(({drawPositions:P})=>P).filter(Boolean);return h?_.structures=h:(_.matchUps=p,_.positionAssignments=We(I).sort((P,y)=>P-y).map(P=>({drawPosition:P}))),_};var m5=Object.defineProperty,h5=Object.defineProperties,g5=Object.getOwnPropertyDescriptors,TO=Object.getOwnPropertySymbols,_5=Object.prototype.hasOwnProperty,I5=Object.prototype.propertyIsEnumerable,wO=(t,e,r)=>e in t?m5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,EO=(t,e)=>{for(var r in e||(e={}))_5.call(e,r)&&wO(t,r,e[r]);if(TO)for(var r of TO(e))I5.call(e,r)&&wO(t,r,e[r]);return t},P5=(t,e)=>h5(t,g5(e));function vc({structureName:t=he,stageSequence:e=1,structureOptions:r,appliedPolicies:n,seedingProfile:o,stage:i=he,matchUpType:s,roundTarget:a,structureId:l,drawSize:c,idPrefix:u,isMock:p,uuids:d}){const{groupCount:v,groupSize:f}=y5({structureOptions:r,appliedPolicies:n,drawSize:c}),m=ya;let h;const g=ce(1,v+1).map(I=>{const P=S5({groupSize:f,structureOrder:I,matchUpType:s,drawSize:c,idPrefix:u,isMock:p});return h=Math.max(...P.map(({roundNumber:y})=>y)),Zt({structureName:`Group ${I}`,structureId:d==null?void 0:d.pop(),structureType:Au,finishingPosition:m,structureOrder:I,matchUps:P})}),_=Zt({structureId:l||(d==null?void 0:d.pop()),structureType:gr,finishingPosition:m,seedingProfile:o,structureName:t,stageSequence:e,structures:g,stage:i});return a&&it({extension:{name:Gn,value:a},element:_}),EO({structures:[_],maxRoundNumber:h,groupCount:v,links:[],groupSize:f},V)}function y5({appliedPolicies:t,structureOptions:e,drawSize:r}){let n=e==null?void 0:e.groupSize;const o=(e==null?void 0:e.groupSizeLimit)||8,{validGroupSizes:i}=lm({groupSizeLimit:o,drawSize:r}),s=i&&Math.max(...i);n&&(i==null?void 0:i.includes(n))||(n&&n>4||!(i!=null&&i.includes(4))?n=s:n=4);const l=Math.ceil(r/n);return{groupSize:n,groupCount:l}}function lm({drawSize:t,groupSizeLimit:e=10}){const r=ce(3,e+1).filter(n=>{const o=Math.ceil(t/n),i=o*n-t,s=Math.ceil(t/o),a=Math.ceil(i/o);return(!i||i<n)&&s===n&&s>=3&&a<2});return P5(EO({},V),{validGroupSizes:r})}function S5({structureOrder:t,matchUpType:e,groupSize:r,drawSize:n,idPrefix:o,isMock:i,uuids:s}){const a=(t-1)*r,l=ce(1+a,r+1+a),{uniqueMatchUpGroupings:c}=Bv({drawPositions:l}),u=aS({groupSize:r,drawPositionOffset:a});return c.map(v).sort((f,m)=>(f.roundNumber||1/0)-(m.roundNumber||1/0));function d(f){return u.reduce((m,h,g)=>h.includes(f)?g+1:m,void 0)}function v(f){const m=od(f),h=d(m),g=[1,n],_=O5({structureOrder:t,drawPositions:f,roundNumber:h,idPrefix:o,uuids:s}),I={matchUpStatus:h?ut.ToBePlayed:ut.Bye,matchUpType:e,finishingPositionRange:{winner:g,loser:g},drawPositions:f,roundNumber:h,matchUpId:_};return i&&(I.isMock=!0),I}}function O5({structureOrder:t,drawPositions:e,roundNumber:r,idPrefix:n,uuids:o}){return n?`${n}-${t}-${r}-DP-${e.join("-")}`:(o==null?void 0:o.pop())||Ye()}var b5=Object.defineProperty,T5=Object.defineProperties,w5=Object.getOwnPropertyDescriptors,$O=Object.getOwnPropertySymbols,E5=Object.prototype.hasOwnProperty,$5=Object.prototype.propertyIsEnumerable,NO=(t,e,r)=>e in t?b5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ka=(t,e)=>{for(var r in e||(e={}))E5.call(e,r)&&NO(t,r,e[r]);if($O)for(var r of $O(e))$5.call(e,r)&&NO(t,r,e[r]);return t},cm=(t,e)=>T5(t,w5(e));function gd(t){const{roundRobinGroupsCount:e,participantsCount:r,cluster:n}=t;if(!ht(r))return ka({seedBlocks:void 0},k({result:{error:X},context:{participantsCount:r},stack:"getSeedBlocks"}));const o=ea(r);if(e){const v=Math.min(e,o),f=[];let m=1;for(ce(0,v).forEach(()=>{f.push([m]),m++});m<o;){const h=ce(m,m+v);m+=v,f.push(h)}return cm(ka({},V),{seedBlocks:f})}const i=ce(1,o+1),s=[];let a=o/2;for(;a>1;){const v=qt(i,a),f=v.length;v.forEach((m,h)=>{let g;const _=h<f/2,I=h%2===0,P=m[0],y=m[m.length-1];n&&f>4?f===8?g=_?y:P:g=I?P:y:g=_?P:y,Xt(m,s)||s.push(g)}),a=a/2}const l=i.filter(v=>!s.includes(v));for(;l.length;)l.length%2===0?s.push(l.pop()):s.push(l.shift());const c=ce(0,20).map(v=>Math.pow(2,v));c.unshift(1);const u=c.indexOf(o);let p=0;const d=[];return ce(0,u).forEach(v=>{d.push(s.slice(p,p+c[v])),p+=c[v]}),cm(ka({},V),{seedBlocks:d})}function _d({roundRobinGroupsCount:t,drawSize:e}){const r="getSeedGroups";if(!ht(e))return ka({seedGroups:void 0},k({result:{error:X},context:{drawSize:e},stack:r}));if(t){if(!ht(t))return ka({seedGroups:void 0},k({result:{error:X},context:{roundRobinGroupsCount:t},stack:r}));let n=1;const o=Math.floor(e/t);return{seedGroups:ce(0,o).map(()=>{const s=ce(n,n+t);return n+=t,s})}}else{const{seedBlocks:n}=gd({participantsCount:e,roundRobinGroupsCount:t});let o=0;return{seedGroups:(n||[]).map(s=>(s||[]).map(()=>(o+=1,o)))}}}function N5({roundRobinGroupsCount:t,participantsCount:e}){if(t){const{validGroupSizes:o}=lm({drawSize:e}),i=o==null?void 0:o.map(a=>Math.ceil(e/a));if(!(i!=null&&i.includes(t)))return k({result:{error:X},context:{roundRobinGroupsCount:t}})}const{seedGroups:r}=_d({drawSize:e,roundRobinGroupsCount:t}),n=(r==null?void 0:r.map(o=>Math.min(...o)))||[];return cm(ka({},V),{seedingThresholds:n})}function Rs({provisionalPositioning:t,appliedPolicies:e,drawDefinition:r,allPositions:n,structure:o}){var i;let s=[];if(!o)return{error:ra};const{roundMatchUps:a}=Je({matchUpFilters:{roundNumbers:[1]},provisionalPositioning:t,structure:o}),{seedAssignments:l}=$n({provisionalPositioning:t,drawDefinition:r,structure:o}),{positionAssignments:c}=Dt({structure:o}),u=c==null?void 0:c.length,p=(l==null?void 0:l.length)||0;let d=[];const f=Object.keys(a).map(M=>parseInt(M)).sort((M,D)=>M-D).map(M=>{const D=a[M].map(j=>j.drawPositions).flat(1/0).filter(Boolean),R=D.filter(j=>!d.includes(j));return d=d.concat(...D),R}).filter(M=>M.length).reverse(),m=f.pop(),h=m&&Math.min(...m)-1||0,g=(i=e==null?void 0:e.seeding)==null?void 0:i.seedingProfile,_=(m==null?void 0:m.length)||0,I=f.filter(M=>M.filter(D=>D<=p).length),{stage:P,structureType:y,roundLimit:S}=o,O=y===gr,b=!O&&(f==null?void 0:f.length),w=(m==null?void 0:m.length)&&!Zr(_),T=!O&&P===we&&S,$=I.flat(1/0),N=b?$==null?void 0:$.length:0,E=n?u:p,A=w?0:!b&&E||E&&$.length<E&&E-$.length||0;if(T){const M=o!=null&&o.matchUps?o.matchUps.filter(({roundNumber:R})=>R===o.roundLimit).length:0,D=m.length/M;if(!b){const R=mc(g),j=qt(m,D);let G=1;const W=ce(0,j[0].length).map(()=>{const q=ce(G,G+j.length);return G+=j.length,q});({validSeedBlocks:s}=UO({drawPositionBlocks:j,positioning:R,seedGroups:W}))}}else O?{validSeedBlocks:s}=U5({seedingProfile:g,structure:o}):b?s=I.map(M=>({seedNumbers:M,drawPositions:M})):w&&qt(m,2).map((D,R)=>({drawPositions:[D[0]],seedNumbers:[R+1]})).forEach(D=>s.push(D));if(!O&&!w&&!T){const{blocks:M}=A5({drawPositionOffset:h,seedNumberOffset:N,seedCountGoal:A,seedingProfile:g,baseDrawSize:_});M.forEach(D=>s.push(D))}const C=s.flatMap(M=>M.drawPositions).reduce((M,D)=>(m==null?void 0:m.includes(D))&&M,!0);return!w&&!b&&!O&&!C?{error:ix,validSeedBlocks:[],isContainer:O,isFeedIn:b}:{validSeedBlocks:s,isContainer:O,isFeedIn:b,isLucky:w}}function U5({seedingProfile:t,structure:e}){var r,n;const o=e.structures||[],i=o.length,s=(r=st({structure:e}))==null?void 0:r.positionAssignments,a=mc(t),l=(n=s==null?void 0:s.length)!=null?n:0,{seedGroups:c}=_d({roundRobinGroupsCount:i,drawSize:l}),u=o.map(p=>{var d;return(d=st({structure:p}).positionAssignments)==null?void 0:d.map(v=>v.drawPosition)});return UO({drawPositionBlocks:u,positioning:a,seedGroups:c})}function UO({positioning:t,seedGroups:e,drawPositionBlocks:r}){const n=[],o=(a,l)=>a-l,i=(a,l)=>l-a,s=[];return e.forEach((a,l)=>{l&&t!==nv&&mr(a),a.forEach((c,u)=>{const p=l%2?r.length-u-1:u,d=r[p].sort(l%2?i:o).find(v=>!s.includes(v));s.push(d),n.push({seedNumbers:[c],drawPositions:[d]})})}),{validSeedBlocks:n}}function A5(t){const{drawPositionOffset:e=0,roundRobinGroupsCount:r,seedNumberOffset:n=0,seedingProfile:o,seedCountGoal:i,baseDrawSize:s}=t;let a=1;const l=[],{seedBlocks:c}=gd({cluster:mc(o)===rv,participantsCount:s,roundRobinGroupsCount:r});a=0;for(const p of c){if(a+1>i)break;const d=p.map(f=>f+e),v=u(a+1,p.length).map(f=>+f+n);a+=p.length,l.push({drawPositions:d,seedNumbers:v})}return{blocks:l};function u(p,d){return Array.from(new Array(d),(v,f)=>f+p)}}function Id({appliedPolicies:t,drawDefinition:e,seedBlockInfo:r,drawPosition:n,structureId:o,seedNumber:i}){var s,a,l,c,u;const{structure:p}=Ne({drawDefinition:e,structureId:o});t||(t=pt({drawDefinition:e}).appliedPolicies);let d=r==null?void 0:r.validSeedBlocks;if(!d&&p&&(d=(s=Rs({appliedPolicies:t,drawDefinition:e,structure:p}))==null?void 0:s.validSeedBlocks),(l=(a=t==null?void 0:t.seeding)==null?void 0:a.validSeedPositions)!=null&&l.ignore)return!0;if((u=(c=t==null?void 0:t.seeding)==null?void 0:c.validSeedPositions)!=null&&u.strict){const f=d.find(h=>h.seedNumbers.includes(i));return((f==null?void 0:f.drawPositions)||[]).includes(n)}return[].concat(...d.map(f=>f.drawPositions)).includes(n)}function Pd(t){var e,r;const{provisionalPositioning:n,drawDefinition:o,seedBlockInfo:i,structureId:s,randomize:a}=t,{structure:l}=Ne({drawDefinition:o,structureId:s}),{seedAssignments:c}=$n({provisionalPositioning:n,drawDefinition:o,structure:l}),{positionAssignments:u}=Dt({structure:l}),p=u==null?void 0:u.filter(j=>{var G,W;return(W=(G=j.participantId)!=null?G:j.bye)!=null?W:j.qualifier}),d=p==null?void 0:p.map(j=>j.drawPosition).filter(Boolean),{appliedPolicies:v}=pt({drawDefinition:o}),h=((i==null?void 0:i.validSeedBlocks)||l&&((e=Rs({provisionalPositioning:n,appliedPolicies:v,drawDefinition:o,structure:l}))==null?void 0:e.validSeedBlocks)||[]).filter(j=>j.drawPositions.filter(W=>!(d!=null&&d.includes(W))).length)[0],g=c==null?void 0:c.map(j=>j.participantId).filter(Boolean),_=u==null?void 0:u.map(j=>j.participantId).filter(Boolean),I=g==null?void 0:g.filter(j=>_==null?void 0:_.includes(j)),P=g==null?void 0:g.filter(j=>!(_!=null&&_.includes(j))),y=c==null?void 0:c.filter(j=>P==null?void 0:P.includes(j.participantId)),S=c==null?void 0:c.filter(j=>!j.participantId),b=((y==null?void 0:y.length)||(S==null?void 0:S.length))&&(h==null?void 0:h.drawPositions.filter(j=>!(d!=null&&d.includes(j))))||[],w=a?mr(b):b,T=[],$=w.map(()=>{const j=R(y,T),G=j==null?void 0:j.participantId;return G&&T.push(G),G}).filter(Boolean),N=c==null?void 0:c.filter(j=>I==null?void 0:I.includes(j.participantId)).map(j=>j.seedNumber),A=((h==null?void 0:h.seedNumbers)||[]).filter(j=>!(N!=null&&N.includes(j))),U=c==null?void 0:c.filter(j=>A.includes(j.seedNumber)).map(j=>j.participantId),C=(r=v==null?void 0:v.seeding)==null?void 0:r.duplicateSeedNumbers;return{nextSeedBlock:h,unplacedSeedParticipantIds:(C!==void 0?C:!0)?$:U,unplacedSeedNumbers:A,unfilledPositions:w,unplacedSeedAssignments:y};function R(j,G){const W=j.filter(x=>!G.includes(x.participantId)),q=Math.min(...W.map(x=>Ba(x.seedValue))),F=W.filter(x=>Ba(x.seedValue)===q);return mr(F).pop()}}function mc(t){if(typeof t=="string")return t;if(typeof t=="object")return t.positioning}function Fs({participantId:t,drawDefinition:e,entryStatus:r,entryStage:n}){var o;if(!e)return{error:ue};const i=(o=e.entries)==null?void 0:o.find(s=>s.participantId===t&&(!r||r===s.entryStatus)&&(!n||n===s.entryStage));return t&&i}var C5=Object.defineProperty,AO=Object.getOwnPropertySymbols,M5=Object.prototype.hasOwnProperty,D5=Object.prototype.propertyIsEnumerable,CO=(t,e,r)=>e in t?C5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,j5=(t,e)=>{for(var r in e||(e={}))M5.call(e,r)&&CO(t,r,e[r]);if(AO)for(var r of AO(e))D5.call(e,r)&&CO(t,r,e[r]);return t};function xs({provisionalPositioning:t,tournamentRecord:e,drawDefinition:r,seedingProfile:n,participantId:o,seedBlockInfo:i,structureId:s,seedNumber:a,seedValue:l,eventId:c,event:u}){var p,d;const v="assignSeed",{structure:f}=Ne({drawDefinition:r,structureId:s}),{positionAssignments:m}=Dt({structure:f}),h=$n({provisionalPositioning:t,drawDefinition:r,structure:f}).seedAssignments,g=h.map(b=>b.seedNumber),_=Fs({drawDefinition:r,participantId:o});if(o&&!_)return k({result:{error:So},context:{participantId:o},stack:v});const I=u?(d=(p=Nt({event:u}).flightProfile)==null?void 0:p.flights)==null?void 0:d.length:0,P=I&&I>1,y=m==null?void 0:m.find(b=>b.participantId===o),S=y==null?void 0:y.drawPosition;if(S&&!Id({drawPosition:S,drawDefinition:r,seedBlockInfo:i,structureId:s,seedNumber:a}))return k({result:{error:Wg},context:{assignedDrawPosition:S},info:"invalid seed position",stack:v});g.includes(a)||h.push({seedNumber:a,seedValue:l});let O;return h.forEach(b=>{b.participantId===o&&b.seedNumber!==a&&(b.participantId=void 0),b.seedNumber===a&&(b.participantId=o,!(n!=null&&n.groupSeedingThreshold)&&!P&&(b.seedValue=l||a),O=!0)}),O?(Py({tournamentId:e==null?void 0:e.tournamentId,drawDefinition:r,structure:f,eventId:c}),j5({},V)):k({result:{error:ox},stack:v})}function MO({inContextDrawMatchUps:t,drawDefinition:e,assignments:r,matchUpsMap:n,structure:o}){var i,s,a;const l=(i=Ra({drawDefinition:e}))==null?void 0:i.containedStructures,c=((s=l==null?void 0:l[o.structureId])==null?void 0:s.map(({structureId:f})=>f))||[];c.push(o==null?void 0:o.structureId);const u=(r==null?void 0:r.map(({drawPosition:f})=>f))||[],p=(t==null?void 0:t.filter(f=>c.includes(f.structureId)&&Ht(f.drawPositions||[],u).length))||[],d=p.map(({matchUpId:f})=>f),v=((a=n==null?void 0:n.drawMatchUps)==null?void 0:a.filter(f=>d.includes(f.matchUpId)))||[];return{drawPositions:u,matchUps:v,targetMatchUps:p}}var R5=Object.defineProperty,DO=Object.getOwnPropertySymbols,F5=Object.prototype.hasOwnProperty,x5=Object.prototype.propertyIsEnumerable,jO=(t,e,r)=>e in t?R5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L5=(t,e)=>{for(var r in e||(e={}))F5.call(e,r)&&jO(t,r,e[r]);if(DO)for(var r of DO(e))x5.call(e,r)&&jO(t,r,e[r]);return t};function um({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:n,assignments:o,structure:i,event:s}){const{drawPositions:a,matchUps:l,targetMatchUps:c}=MO({inContextDrawMatchUps:t,matchUpsMap:n,assignments:o,structure:i});for(const u of c)u.matchUpType===hn&&(u.sides||[]).forEach((p,d)=>{var v;if(p!=null&&p.drawPosition&&(a!=null&&a.includes(p.drawPosition))){const f=l.find(({matchUpId:m})=>m===u.matchUpId);(v=f==null?void 0:f.sides)!=null&&v[d]&&(f==null||delete f.sides[d].lineUp,Ze({tournamentId:e==null?void 0:e.tournamentId,context:"cleanupLineUps",eventId:s==null?void 0:s.eventId,drawDefinition:r,matchUp:f}))}});return L5({},V)}var V5=Object.defineProperty,RO=Object.getOwnPropertySymbols,B5=Object.prototype.hasOwnProperty,k5=Object.prototype.propertyIsEnumerable,FO=(t,e,r)=>e in t?V5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xO=(t,e)=>{for(var r in e||(e={}))B5.call(e,r)&&FO(t,r,e[r]);if(RO)for(var r of RO(e))k5.call(e,r)&&FO(t,r,e[r]);return t};function An({provisionalPositioning:t,inContextDrawMatchUps:e,isQualifierPosition:r,sourceMatchUpStatus:n,tournamentRecord:o,drawDefinition:i,seedingProfile:s,participantId:a,seedBlockInfo:l,drawPosition:c,matchUpsMap:u,structureId:p,event:d}){var v;const f="assignDrawPosition";if(!a&&!r)return k({result:{error:Et},stack:f});u=u||lr({drawDefinition:i}),e||({matchUps:e}=Lt({inContext:!0,drawDefinition:i,matchUpsMap:u}));const m=Ne({drawDefinition:i,structureId:p});if(m.error)return k({result:m,stack:f});const{structure:h}=m;if(!h)return{error:bt};if(Co({drawDefinition:i,structure:h}))return k({result:{error:tn},stack:f});const{seedAssignments:g}=$n({provisionalPositioning:t,drawDefinition:i,structure:h}),_=g==null?void 0:g.find(N=>N.participantId===a),I=_==null?void 0:_.seedNumber,{appliedPolicies:P}=pt({tournamentRecord:o,drawDefinition:i,structure:h,event:d});if(I&&!Id({seedNumber:I,appliedPolicies:P,drawDefinition:i,seedBlockInfo:l,drawPosition:c,structureId:p}))return k({result:{error:Wg},context:{drawPosition:c},stack:f});const S=Dt({structure:h}).positionAssignments||[],O=S==null?void 0:S.find(N=>N.drawPosition===c);if(!O)return k({result:{error:ta},context:{drawPosition:c},stack:f});if(S==null?void 0:S.map(ct).includes(a))return k({result:{error:ia},context:{drawPosition:c},stack:f});const{containsParticipant:w,containsBye:T}=$(O);if(T){const N=Fa({inContextDrawMatchUps:e,tournamentRecord:o,drawDefinition:i,drawPosition:c,structureId:p,matchUpsMap:u,event:d});if(N.error)return k({result:N,stack:f})}if(w&&O.participantId!==a){const{activeDrawPositions:N}=dc({drawDefinition:i,structureId:p});if(N.includes(c))return k({result:{error:Xp},stack:f});um({assignments:[O],inContextDrawMatchUps:e,tournamentRecord:o,drawDefinition:i,matchUpsMap:u,structure:h})}if(O.participantId=a,r&&(O.qualifier=!0),((h==null?void 0:h.stageSequence)||0)>1||h.stage&&[xt,ft].includes(h.stage)){const N=h.stage===we?we:he,E=(v=i.structures)==null?void 0:v.find(C=>(C==null?void 0:C.stage)===N&&(C==null?void 0:C.stageSequence)===1),U=((E==null?void 0:E.seedAssignments)||[]).find(C=>C.participantId===a);if(U!=null&&U.participantId){const{participantId:C,seedNumber:M,seedValue:D}=U;xs({eventId:d==null?void 0:d.eventId,provisionalPositioning:t,tournamentRecord:o,drawDefinition:i,seedingProfile:s,participantId:C,seedNumber:M,seedValue:D,structureId:p,event:d})}}if(h.structureType!==gr)G5({provisionalPositioning:t,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:o,drawDefinition:i,drawPosition:c,matchUpsMap:u,structure:h,event:d});else{YS({positionAssignments:S,tournamentRecord:o,drawDefinition:i,matchUpsMap:u,structure:h});const{drawPositions:N,matchUps:E,targetMatchUps:A}=MO({assignments:[O],inContextDrawMatchUps:e,drawDefinition:i,matchUpsMap:u,structure:h});if(N&&(E==null?void 0:E.length)===1&&E[0].matchUpType===Qe){const C=((A==null?void 0:A[0].sides)||[]).reduce((M,D,R)=>N!=null&&N.includes(D.drawPosition)?R:M,void 0);om({inContextTargetMatchUp:A[0],teamParticipantId:a,matchUp:E[0],drawPositionSideIndex:C,tournamentRecord:o,drawDefinition:i})}}return oi({tournamentId:o==null?void 0:o.tournamentId,drawDefinition:i,structure:h,event:d}),xO({positionAssignments:S},V);function $(N){const E=N.bye,A=N.qualifier,U=N.participantId;return{containsBye:E,containsQualifier:A,containsParticipant:U,filled:E||A||U}}}function G5({provisionalPositioning:t,inContextDrawMatchUps:e,sourceMatchUpStatus:r,tournamentRecord:n,drawDefinition:o,drawPosition:i,matchUpsMap:s,structure:a,event:l}){const c={isCollectionMatchUp:!1},{matchUps:u}=Je({provisionalPositioning:t,matchUpFilters:c,drawDefinition:o,matchUpsMap:s,structure:a,event:l}),{roundMatchUps:p}=Tr({matchUps:u}),{initialRoundNumber:d}=js({drawPosition:i,matchUps:u}),v=d&&(p==null?void 0:p[d].find(f=>{var m;return(m=f.drawPositions)==null?void 0:m.includes(i)}));if(v){const f=La({matchUpId:v.matchUpId,inContextDrawMatchUps:e,sourceMatchUpStatus:r,tournamentRecord:n,drawDefinition:o,drawPosition:i,matchUpsMap:s});if(f.error)return k({stack:"assignDrawPositionToMatchUps",context:{drawPosition:i},result:f})}return xO({},V)}var W5=Object.defineProperty,H5=Object.defineProperties,q5=Object.getOwnPropertyDescriptors,LO=Object.getOwnPropertySymbols,z5=Object.prototype.hasOwnProperty,Y5=Object.prototype.propertyIsEnumerable,VO=(t,e,r)=>e in t?W5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dm=(t,e)=>{for(var r in e||(e={}))z5.call(e,r)&&VO(t,r,e[r]);if(LO)for(var r of LO(e))Y5.call(e,r)&&VO(t,r,e[r]);return t},BO=(t,e)=>H5(t,q5(e));function K5({winnerMatchUpDrawPositionIndex:t,inContextDrawMatchUps:e,projectedWinningSide:r,sourceMatchUpStatus:n,winningDrawPosition:o,tournamentRecord:i,winnerTargetLink:s,sourceMatchUpId:a,drawDefinition:l,winnerMatchUp:c,dualMatchUp:u,matchUpsMap:p,event:d}){var v,f,m;const h="directWinner";if(s){const g=c.drawPositions||[],_=g[t],I=s.source.structureId,P=Ne({structureId:I,drawDefinition:l});if(P.error)return P;const{structure:y}=P,{positionAssignments:S}=Dt({structureId:I,drawDefinition:l}),O=S==null?void 0:S.find(U=>U.drawPosition===o),b=O==null?void 0:O.participantId,w=s.target.structureId,{positionAssignments:T}=Dt({structureId:w,drawDefinition:l}),$=T==null?void 0:T.find(U=>U.participantId===b),N=$==null?void 0:$.drawPosition,E=T==null?void 0:T.filter(U=>{const C=g.includes(U.drawPosition),M=!U.participantId&&!U.bye&&!U.qualifier;return C&&M}).map(U=>U.drawPosition),A=E==null?void 0:E.includes(_);if(b&&s.target.roundNumber===1&&A)An({drawPosition:_,participantId:b,structureId:w,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,drawDefinition:l,matchUpsMap:p,event:d});else if(b&&(E!=null&&E.length)){const U=E.pop();U&&An({participantId:b,structureId:w,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,drawDefinition:l,drawPosition:U,matchUpsMap:p,event:d})}else if(N){const U=La({drawPosition:N,matchUpId:c.matchUpId,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:l,matchUpsMap:p});if(U.error)return k({result:U,stack:h})}else if((y==null?void 0:y.stage)!==we){const U="winner target position unavaiallble";return console.log(U),{error:U}}if(y!=null&&y.seedAssignments&&y.structureId!==w){const U=y.seedAssignments.find(({participantId:M})=>M===b),C=U==null?void 0:U.participantId;U&&C&&xs(BO(dm({eventId:c==null?void 0:c.eventId,structureId:w},U),{tournamentRecord:i,drawDefinition:l,participantId:C}))}}else{const g=La({matchUpId:c.matchUpId,drawPosition:o,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:l,matchUpsMap:p});if(g.error)return g}if(u&&r){const g=(v=u.sides)==null?void 0:v.find(_=>_.sideNumber===r);if(g!=null&&g.lineUp){const _=u.roundPosition,I=c.roundPosition,P=_===I&&_!==1||Math.floor(_/2)===I?2:1,y=(f=p==null?void 0:p.drawMatchUps)==null?void 0:f.find(({matchUpId:b})=>b===c.matchUpId),S=[1,2].map(b=>{var w;const T=((w=y.sides)==null?void 0:w.find($=>$.sideNumber===b))||{};return BO(dm({},T),{sideNumber:b})});y.sides=S;const O=y.sides.find(b=>b.sideNumber===P);if(O){const b=(m=g.lineUp)==null?void 0:m.filter(w=>w==null?void 0:w.participantId);O.lineUp=am({lineUp:b}),Ze({tournamentId:i==null?void 0:i.tournamentId,eventId:c==null?void 0:c.eventId,matchUp:y,context:h,drawDefinition:l})}}}return dm({},V)}var Q5=Object.defineProperty,J5=Object.defineProperties,Z5=Object.getOwnPropertyDescriptors,kO=Object.getOwnPropertySymbols,X5=Object.prototype.hasOwnProperty,ez=Object.prototype.propertyIsEnumerable,GO=(t,e,r)=>e in t?Q5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yd=(t,e)=>{for(var r in e||(e={}))X5.call(e,r)&&GO(t,r,e[r]);if(kO)for(var r of kO(e))ez.call(e,r)&&GO(t,r,e[r]);return t},WO=(t,e)=>J5(t,Z5(e));function tz(t){var e,r;const{loserMatchUpDrawPositionIndex:n,inContextDrawMatchUps:o,projectedWinningSide:i,sourceMatchUpStatus:s,loserDrawPosition:a,tournamentRecord:l,loserTargetLink:c,drawDefinition:u,loserMatchUp:p,dualMatchUp:d,matchUpsMap:v,event:f}=t,m="directLoser",h=c.linkCondition,g=p.drawPositions||[],_=h===co&&p.roundNumber===2&&Math.min(...g.filter(Boolean)),I=_||g[n],P=_||g[1-n],y=c.source.structureId,{structure:S}=Ne({structureId:y,drawDefinition:u}),{matchUps:O}=Je({afterRecoveryTimes:!1,inContext:!0,drawDefinition:u,structure:S,event:f}),w=O.filter(L=>{var x;return(x=L.drawPositions)==null?void 0:x.includes(a)}).filter(L=>{const x=L.sides.find(z=>z.drawPosition===a),B=L.matchUpStatus===ot||L.matchUpStatus===Xe&&!Gt(L);return(x==null?void 0:x.sideNumber)===L.winningSide&&!B}),T=h===co&&w.length===0,{positionAssignments:$}=Dt({structureId:y,drawDefinition:u}),N=$==null?void 0:$.find(L=>L.drawPosition===a),E=N==null?void 0:N.participantId,A=c.target.structureId,{positionAssignments:U}=Dt({structureId:A,drawDefinition:u}),C=U==null?void 0:U.filter(({drawPosition:L})=>g.includes(L));if(C==null?void 0:C.some(L=>L.participantId===E))return yd({},V);const D=C==null?void 0:C.filter(L=>{const x=g.includes(L.drawPosition),B=!L.participantId&&!L.bye&&!L.qualifier;return x&&B}).map(L=>L.drawPosition),R=D==null?void 0:D.includes(I),j=c.target.roundNumber>1&&(D==null?void 0:D.length),G=c.target.roundNumber===1&&R;if(_){const L=W();if(L.error)return k({result:L,stack:m})}else if(G){const L=F();if(L.error)return k({result:L,stack:m})}else if(E&&j){const L=D.sort(er)[0],x=An({participantId:E,structureId:A,drawPosition:L,inContextDrawMatchUps:o,sourceMatchUpStatus:s,tournamentRecord:l,drawDefinition:u,matchUpsMap:v,event:f});if(x.error)return k({result:x,stack:m})}else return k({result:{error:ta},context:{loserDrawPosition:a,loserTargetLink:c},stack:m});if(S!=null&&S.seedAssignments&&S.structureId!==A){const L=S.seedAssignments.find(({participantId:B})=>B===E),x=L==null?void 0:L.participantId;L&&x&&xs(WO(yd({eventId:p==null?void 0:p.eventId,structureId:A},L),{tournamentRecord:l,drawDefinition:u,participantId:x}))}if(d&&i){const L=(e=d.sides)==null?void 0:e.find(x=>x.sideNumber===3-i);if(L!=null&&L.lineUp){const{roundNumber:x,eventId:B}=p,{roundPosition:z}=d,H=x===1?2-z%2:1,Y=(r=v==null?void 0:v.drawMatchUps)==null?void 0:r.find(({matchUpId:Q})=>Q===p.matchUpId),Z=[1,2].map(Q=>{var J;const te=((J=Y.sides)==null?void 0:J.find(ne=>ne.sideNumber===Q))||{};return WO(yd({},te),{sideNumber:Q})});Y.sides=Z;const K=Y.sides.find(Q=>Q.sideNumber===H);K&&(K.lineUp=am({lineUp:L.lineUp}),Ze({tournamentId:l==null?void 0:l.tournamentId,matchUp:Y,context:m,drawDefinition:u,eventId:B}))}}return yd({},V);function W(){const L="loserLinkFedFMLC";return k(T?{result:F(),stack:L}:{result:q(),stack:L})}function q(){const L=Yr({drawPosition:P,structureId:A,tournamentRecord:l,drawDefinition:u,event:f});return k({result:L,stack:"assignLoserPositionBye"})}function F(){const L=E?An({drawPosition:I,participantId:E,structureId:A,inContextDrawMatchUps:o,sourceMatchUpStatus:s,tournamentRecord:l,drawDefinition:u,matchUpsMap:v,event:f}):{error:Et};return k({result:L,stack:"assignLoserDrawPosition"})}}var rz=Object.defineProperty,HO=Object.getOwnPropertySymbols,nz=Object.prototype.hasOwnProperty,oz=Object.prototype.propertyIsEnumerable,qO=(t,e,r)=>e in t?rz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ga=(t,e)=>{for(var r in e||(e={}))nz.call(e,r)&&qO(t,r,e[r]);if(HO)for(var r of HO(e))oz.call(e,r)&&qO(t,r,e[r]);return t};function zO(t){const e=sm(t);if(e.error)return e;const r=rc({matchUpStatus:t.matchUpStatus}),{dualWinningSideChange:n,projectedWinningSide:o,inContextDrawMatchUps:i,tournamentRecord:s,drawDefinition:a,matchUpStatus:l,dualMatchUp:c,matchUpsMap:u,winningSide:p,targetData:d,matchUpId:v,structure:f,matchUp:m,event:h}=t,g="directParticipants",_=!!m.collectionId,I=Co({drawDefinition:a,structure:f});let P=m.drawPositions,y;if(_){const{matchUpTieId:S,matchUpsMap:O}=t,b=uo({matchUpId:S,tournamentRecord:s,drawDefinition:a,matchUpsMap:O,event:h});y=b&&{tieMatchUpResult:b};const w=i.find(({matchUpId:T})=>T===S);if(P=w==null?void 0:w.drawPositions,!n)return k({result:Ga(Ga({},V),y),stack:g})}if(I)return k({result:Ga(Ga({},V),y),stack:g});if(P){const S=o?o-1:p-1,O=1-S,b=P[S],w=P[O],{targetLinks:{loserTargetLink:T,winnerTargetLink:$,byeTargetLink:N},targetMatchUps:{winnerMatchUpDrawPositionIndex:E,loserMatchUpDrawPositionIndex:A,winnerMatchUp:U,loserMatchUp:C,byeMatchUp:M}}=d;if(U){const D=K5({sourceMatchUpStatus:r&&l||Mt,winnerMatchUpDrawPositionIndex:E,sourceMatchUpId:v,inContextDrawMatchUps:i,projectedWinningSide:o,winningDrawPosition:b,tournamentRecord:s,winnerTargetLink:$,drawDefinition:a,winnerMatchUp:U,dualMatchUp:c,matchUpsMap:u,event:h});if(D.error)return k({result:D,stack:g})}if(C){const D=tz({sourceMatchUpStatus:r&&l||Mt,loserMatchUpDrawPositionIndex:A,sourceMatchUpId:v,inContextDrawMatchUps:i,projectedWinningSide:o,loserDrawPosition:w,tournamentRecord:s,loserTargetLink:T,drawDefinition:a,loserMatchUp:C,winningSide:p,matchUpsMap:u,dualMatchUp:c,event:h});if(D.error)return k({result:D,stack:g})}if(M){const D=M.drawPositions||[],R=Math.min(...D.filter(Boolean)),j=N.target.structureId,G=Yr({drawPosition:R,structureId:j,tournamentRecord:s,drawDefinition:a,event:h});if(G.error)return k({result:G,stack:g})}}else return k({result:{error:Zp},stack:g});return k({result:Ga(Ga({},V),y),stack:g})}function qi(t){var e,r;const{inContextDrawMatchUps:n,targetData:o,drawDefinition:i,relevantLink:s}=t;if((s==null?void 0:s.linkCondition)===co&&((e=o==null?void 0:o.matchUp)==null?void 0:e.matchUpStatus)===nt)return!1;const{targetMatchUps:{loserMatchUp:l,winnerMatchUp:c},targetLinks:u}=o,p=[Xe,ot].includes(l==null?void 0:l.matchUpStatus),d=((r=c==null?void 0:c.drawPositions)==null?void 0:r.filter(Boolean).length)||0;if(l!=null&&l.winningSide&&!p||c!=null&&c.winningSide&&d===2&&(!c.feedRound||![ot,Xe].includes(c==null?void 0:c.matchUpStatus)))return!0;const v=l&&Ir({matchUpId:l.matchUpId,inContextDrawMatchUps:n,drawDefinition:i}),f=c&&Ir({matchUpId:c.matchUpId,inContextDrawMatchUps:n,drawDefinition:i}),m=v&&qi({relevantLink:u==null?void 0:u.loserTargetLink,targetData:v,inContextDrawMatchUps:n,drawDefinition:i});return!!(f&&qi({targetData:f,inContextDrawMatchUps:n,drawDefinition:i})||m)}var iz=Object.defineProperty,sz=Object.defineProperties,az=Object.getOwnPropertyDescriptors,YO=Object.getOwnPropertySymbols,lz=Object.prototype.hasOwnProperty,cz=Object.prototype.propertyIsEnumerable,KO=(t,e,r)=>e in t?iz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,uz=(t,e)=>{for(var r in e||(e={}))lz.call(e,r)&&KO(t,r,e[r]);if(YO)for(var r of YO(e))cz.call(e,r)&&KO(t,r,e[r]);return t},dz=(t,e)=>sz(t,az(e));function pz(t){var e,r,n;let o;const{inContextDrawMatchUps:i,inContextMatchUp:s,drawDefinition:a,winningSide:l}=t,c=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(c.target.feedProfile===Sn){const u=s.sides.find(({sideNumber:d})=>d!==l).participantId,p=i.find(d=>d.structureId===c.target.structureId&&d.roundNumber===c.target.roundNumber&&d.sides.some(({participantId:v})=>v===u));if((p==null?void 0:p.matchUpStatus)===Ft){const d=Ir({matchUpId:p.matchUpId,inContextDrawMatchUps:i,drawDefinition:a});if(!qi({inContextDrawMatchUps:i,drawDefinition:a,targetData:d})){const{structure:f}=Ne({structureId:p.structureId,drawDefinition:a}),m=st({structure:f}).positionAssignments;for(const h of m||[])if(h.participantId===u){const g=s.sides.find(({sideNumber:_})=>_===l).participantId;if(h.participantId=g,f!=null&&f.positionAssignments)f.positionAssignments=m;else if(f!=null&&f.structures){const _=Object.assign({},...(m||[]).map(I=>({[I.drawPosition]:I.participantId})));for(const I of f.structures)(r=I.positionAssignments)==null||r.forEach(P=>P.participantId=_[P.drawPosition])}oi({tournamentId:(n=t.tournamentRecord)==null?void 0:n.tournamentId,event:t.event,drawDefinition:a,structure:f}),o=!0}}}}return dz(uz({},V),{qualifierReplaced:o})}var fz=Object.defineProperty,vz=Object.defineProperties,mz=Object.getOwnPropertyDescriptors,QO=Object.getOwnPropertySymbols,hz=Object.prototype.hasOwnProperty,gz=Object.prototype.propertyIsEnumerable,JO=(t,e,r)=>e in t?fz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_z=(t,e)=>{for(var r in e||(e={}))hz.call(e,r)&&JO(t,r,e[r]);if(QO)for(var r of QO(e))gz.call(e,r)&&JO(t,r,e[r]);return t},Iz=(t,e)=>vz(t,mz(e));function Pz(t){var e,r,n,o,i;let s;const{inContextDrawMatchUps:a,inContextMatchUp:l,drawDefinition:c,winningSide:u}=t,p=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(p.target.feedProfile===Sn){const d=(r=l.sides.find(({sideNumber:m})=>m===u))==null?void 0:r.participantId,v=a.filter(m=>m.structureId===p.target.structureId&&m.roundNumber===p.target.roundNumber&&m.sides.some(({participantId:h,qualifier:g})=>g&&!h)),f=Ur(v);if((f==null?void 0:f.matchUpStatus)===Ft){const m=Ir({matchUpId:f.matchUpId,inContextDrawMatchUps:a,drawDefinition:c});if(!qi({inContextDrawMatchUps:a,drawDefinition:c,targetData:m})){const g=(n=f.sides.find(P=>P.qualifier&&!P.participantId))==null?void 0:n.drawPosition,{structure:_}=Ne({structureId:f.structureId,drawDefinition:c});if(!_)return{error:bt};const I=st({structure:_}).positionAssignments;for(const P of I||[])if(P.drawPosition===g&&!P.participantId){if(P.participantId=d,_.positionAssignments)_.positionAssignments=I;else if(_.structures){const y=Object.assign({},...(I||[]).map(S=>({[S.drawPosition]:S.participantId})));for(const S of _.structures)(o=S.positionAssignments)==null||o.forEach(O=>O.participantId=y[O.drawPosition])}oi({tournamentId:(i=t.tournamentRecord)==null?void 0:i.tournamentId,event:t.event,drawDefinition:c,structure:_}),s=!0}}}}return Iz(_z({},V),{qualifierPlaced:s})}var yz=Object.defineProperty,Sz=Object.defineProperties,Oz=Object.getOwnPropertyDescriptors,ZO=Object.getOwnPropertySymbols,bz=Object.prototype.hasOwnProperty,Tz=Object.prototype.propertyIsEnumerable,XO=(t,e,r)=>e in t?yz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eb=(t,e)=>{for(var r in e||(e={}))bz.call(e,r)&&XO(t,r,e[r]);if(ZO)for(var r of ZO(e))Tz.call(e,r)&&XO(t,r,e[r]);return t},wz=(t,e)=>Sz(t,Oz(e));function Ez(t){var e,r;const n="attemptToSetWinningSide";let o;const{appliedPolicies:i,disableAutoCalc:s,drawDefinition:a,dualMatchUp:l,winningSide:c,structure:u,matchUp:p}=t;if(l!=null&&l._disableAutoCalc&&s!==!1)return sm(t);if(p.winningSide&&p.winningSide!==c){const{connectedStructureIds:m}=bO({drawDefinition:a,structure:u,matchUp:p});m.length&&(console.log({connectedStructureIds:m}),o=!0);const h=xa(t);if(h.error)return h}const d=zO(t);if(d.error)return k({result:d,stack:n});let v,f;return t.qualifierChanging&&((e=i==null?void 0:i[pu])!=null&&e.autoReplaceQualifiers)&&(v=pz(t).qualifierReplaced),t.qualifierAdvancing&&((r=i==null?void 0:i[pu])!=null&&r.autoPlaceQualifiers)&&(f=Pz(t).qualifierPlaced),k({result:Oe(wz(eb(eb({},V),d),{connectedStructures:o,qualifierReplaced:v,qualifierPlaced:f})),stack:n})}var $z=Object.defineProperty,Nz=Object.defineProperties,Uz=Object.getOwnPropertyDescriptors,tb=Object.getOwnPropertySymbols,Az=Object.prototype.hasOwnProperty,Cz=Object.prototype.propertyIsEnumerable,rb=(t,e,r)=>e in t?$z(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hc=(t,e)=>{for(var r in e||(e={}))Az.call(e,r)&&rb(t,r,e[r]);if(tb)for(var r of tb(e))Cz.call(e,r)&&rb(t,r,e[r]);return t},pm=(t,e)=>Nz(t,Uz(e));function nb(t){var e;const{inContextDrawMatchUps:r,appliedPolicies:n,drawDefinition:o,matchUpsMap:i,targetData:s,matchUp:a}=t;let{iteration:l=0}=t;l+=1;const c="removeDoubleExit";Jn();const{targetLinks:{loserTargetLink:u},targetMatchUps:{loserMatchUp:p,winnerMatchUp:d,loserTargetDrawPosition:v}}=s;if(d&&d.matchUpStatus!==nt&&(Jn(),ob(pm(hc({},t),{targetMatchUp:d,sourceMatchUp:a,iteration:l}))),p&&p.matchUpStatus!==nt){const f=r.find(({matchUpId:h})=>h===p.matchUpId),{structure:m}=Ne({drawDefinition:o,structureId:f.structureId});if(Jn(),(e=n==null?void 0:n.progression)!=null&&e.doubleExitPropagateBye)rm({drawPosition:v,targetLink:u,inContextDrawMatchUps:r,drawDefinition:o,matchUpsMap:i});else{const h=ob(pm(hc({},t),{structure:m,targetMatchUp:p,iteration:l}));if(h.error)return k({result:h,stack:c})}}return k({result:hc({},V),stack:c})}function ob(t){var e,r,n,o,i;const{inContextDrawMatchUps:s,appliedPolicies:a,drawDefinition:l,sourceMatchUp:c,targetMatchUp:u,matchUpsMap:p,structure:d,iteration:v}=t,f="conditionallyRemoveDrawPosition";Jn();const m=Ir({matchUpId:u.matchUpId,inContextDrawMatchUps:s,drawDefinition:l}),{targetMatchUps:{winnerMatchUp:h}}=m,g=p==null?void 0:p.drawMatchUps.find(w=>w.matchUpId===u.matchUpId);let _=[],I,P,y;if(u.feedRound){const w=(e=h==null?void 0:h.drawPositions)==null?void 0:e.filter(Boolean);y=w==null?void 0:w.find(T=>u.drawPositions.includes(T))}else if(!c)y=(r=Ht((u==null?void 0:u.drawPositions)||[],(h==null?void 0:h.drawPositions)||[]))==null?void 0:r[0];else if(P=(n=kS({structureId:d.structureId,matchUp:c,matchUpsMap:p}))==null?void 0:n.pairedPreviousMatchUp,I=[Rt,tr].includes(P==null?void 0:P.matchUpStatus),_=((o=P==null?void 0:P.drawPositions)==null?void 0:o.filter(Boolean))||[],[...Yt,nt].includes(P==null?void 0:P.matchUpStatus)||(P==null?void 0:P.winningSide)){const T=c.drawPositions||[];let $=(i=u.drawPositions)==null?void 0:i.filter(Boolean);Xt(T,$)&&($=$==null?void 0:$.filter(E=>!T.includes(E))),y=T.concat(_).find(E=>$==null?void 0:$.includes(E))}h&&y&&(Jn(),eO({winningDrawPosition:y,winnerMatchUp:h,inContextDrawMatchUps:s,drawDefinition:l,matchUpsMap:p}));let S=nb({targetData:m,matchUp:u,inContextDrawMatchUps:s,appliedPolicies:a,drawDefinition:l,matchUpsMap:p,structure:d,iteration:v});if(S.error)return k({result:S,stack:f});const O=Mz({pairedPreviousDoubleExit:I,noContextTargetMatchUp:g}),b=!I;return S=Kn(pm(hc({},t),{matchUpStatus:O,removeScore:b,score:{scoreStringSide1:"",scoreStringSide2:"",sets:void 0},removeWinningSide:!0,matchUp:g,matchUpId:u.matchUpId,matchUpStatusCodes:[]})),S.error?k({result:S,stack:f}):hc({},V)}function Mz({pairedPreviousDoubleExit:t,noContextTargetMatchUp:e}){return e.matchUpStatus===nt?nt:t?[tr,Xe].includes(e==null?void 0:e.matchUpStatus)?Xe:ot:Ft}function Dz(t){var e,r,n,o,i;let s;const{inContextDrawMatchUps:a,inContextMatchUp:l,drawDefinition:c}=t,u=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(u.target.feedProfile===Sn){const p=(n=(r=l.sides)==null?void 0:r.find(({sideNumber:v})=>v===l.winningSide))==null?void 0:n.participantId,d=a.find(v=>{var f;return v.structureId===u.target.structureId&&v.roundNumber===u.target.roundNumber&&((f=v.sides)==null?void 0:f.some(({participantId:m})=>m===p))});if((d==null?void 0:d.matchUpStatus)===Ft){const v=Ir({matchUpId:d.matchUpId,inContextDrawMatchUps:a,drawDefinition:c});if(!qi({inContextDrawMatchUps:a,drawDefinition:c,targetData:v})){const{structure:m}=Ne({structureId:d.structureId,drawDefinition:c}),h=st({structure:m}).positionAssignments;for(const g of h||[])if(g.participantId===p){if(g.participantId=void 0,m!=null&&m.positionAssignments)m.positionAssignments=h;else if(m!=null&&m.structures){const _=Object.assign({},...(h||[]).map(I=>({[I.drawPosition]:I.participantId})));for(const I of(m==null?void 0:m.structures)||[])(o=I.positionAssignments)==null||o.forEach(P=>P.participantId=_[P.drawPosition])}oi({tournamentId:(i=t.tournamentRecord)==null?void 0:i.tournamentId,event:t.event,drawDefinition:c,structure:m}),s=!0}}}}return{qualifierRemoved:s}}var jz=Object.defineProperty,Rz=Object.defineProperties,Fz=Object.getOwnPropertyDescriptors,ib=Object.getOwnPropertySymbols,xz=Object.prototype.hasOwnProperty,Lz=Object.prototype.propertyIsEnumerable,sb=(t,e,r)=>e in t?jz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Wa=(t,e)=>{for(var r in e||(e={}))xz.call(e,r)&&sb(t,r,e[r]);if(ib)for(var r of ib(e))Lz.call(e,r)&&sb(t,r,e[r]);return t},fm=(t,e)=>Rz(t,Fz(e));function Vz(t){var e;const{matchUp:r,matchUpStatus:n,score:o,winningSide:i}=t,s="noDownStreamDependencies";if([Rt,tr].includes(r==null?void 0:r.matchUpStatus)&&![Rt,tr].includes(n)){const g=nb(t);if(g.error)return k({result:g,stack:s})}const l=n===Rt,c=Gt({score:o})&&!l&&(t.isCollectionMatchUp&&!t.projectedWinningSide||!i),u=((e=t==null?void 0:t.inContextMatchUp)==null?void 0:e.collectionId)&&e6(t.inContextMatchUp),p=t.removeScore||!u&&![so,Wr].includes(n||so),d=t.isCollectionMatchUp&&t.dualMatchUp.winningSide&&!t.projectedWinningSide||r.winningSide&&!i&&!Gt({score:o}),v=n&&n!==Ft,f=g=>{var _,I;let P;const{structure:y,drawDefinition:S,dualMatchUp:O,disableAutoCalc:b}=t;if(O!=null&&O._disableAutoCalc&&b!==!1)return sm(t);const{connectedStructureIds:w}=bO({drawDefinition:S,structure:y,matchUp:r});w.length&&(console.log({connectedStructureIds:w}),P=!0),Object.assign(t,{removeScore:g});const T=xa(t);if(T.error)return T;if(t.removingQualifier&&((I=(_=t.appliedPolicies)==null?void 0:_[pu])!=null&&I.autoRemoveQualifiers)){const $=Dz(t);return Wa(fm(Wa({},V),{connectedStructures:P}),$)}return fm(Wa({},V),{connectedStructures:P})};if(d&&i&&t.isCollectionMatchUp)return ab(t);const m=[Ho,Wr].includes(n)&&t.dualWinningSideChange,h=(i||m)&&Ez(t)||c&&f(p)||v&&l5(t)||d&&f(p)||r&&ab(fm(Wa({},t),{removeScore:!0}))||Wa({},V);return k({result:h,stack:s})}function ab(t){var e;const r="scoreModification";if(t.isCollectionMatchUp&&((e=t.dualMatchUp)==null?void 0:e.winningSide)&&!t.projectedWinningSide){const i=xa(t);if(i.error)return i}const o=Kn(Wa({},t));if(t.isCollectionMatchUp){const{matchUpTieId:i,drawDefinition:s,event:a,matchUpsMap:l}=t,{removeWinningSide:c}=uo({tournamentRecord:t.tournamentRecord,matchUpId:i,drawDefinition:s,matchUpsMap:l,event:a});c&&console.log("REMOVE WINNING SIDE")}return k({result:o,stack:r})}function Bz(t){var e;const{tournamentRecord:r,inContextMatchUp:n,structure:o,drawDefinition:i}=t,s=n.roundNumber,a=n.sides.find(O=>O.sideNumber===n.winningSide),l=n.sides.find(O=>O.sideNumber!==n.winningSide),{drawPosition:c,participantId:u}=a,{drawPosition:p,participantId:d}=l,v="swapWinnerLoser",{matchUps:f}=Je(t),m=f.filter(({drawPositions:O,roundNumber:b})=>(O==null?void 0:O.includes(c))&&b>s);zt({changeWinner:!0})&&console.log({existingWinnerSubsequentMatchUps:m}),m.forEach(O=>{var b,w;O.drawPositions=((b=O.drawPositions)==null?void 0:b.map(T=>T===c?p:T))||[],Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:(w=t.event)==null?void 0:w.eventId,context:v,drawDefinition:i,matchUp:O})});const{stage:h,stageSequence:g}=o,_=i.structures.filter(({stage:O,stageSequence:b})=>O===h&&b>g).map(({structureId:O})=>O),{targetLinks:{loserTargetLink:I,winnerTargetLink:P}}=t.targetData,y=[I==null?void 0:I.target.structureId,(e=P==null?void 0:P.target)==null?void 0:e.structureId].filter(Boolean);return i.structures.filter(({stage:O,structureId:b})=>O!==h&&y.includes(b)).forEach(({stage:O,stageSequence:b,structureId:w})=>{_.includes(w)||_.push(w),i.structures.filter(({stage:T,stageSequence:$})=>T===O&&$>b).forEach(({structureId:T})=>{_.includes(T)||_.push(T)})}),i.structures.filter(({structureId:O})=>_.includes(O)).forEach(O=>{const{positionAssignments:b}=st({structure:O}),w=b==null?void 0:b.find(({participantId:$})=>$===u),T=b==null?void 0:b.find(({participantId:$})=>$===d);w&&(w.participantId=d),T&&(T.participantId=u)}),Kn(t)}var kz=Object.defineProperty,Gz=Object.defineProperties,Wz=Object.getOwnPropertyDescriptors,lb=Object.getOwnPropertySymbols,Hz=Object.prototype.hasOwnProperty,qz=Object.prototype.propertyIsEnumerable,cb=(t,e,r)=>e in t?kz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zz=(t,e)=>{for(var r in e||(e={}))Hz.call(e,r)&&cb(t,r,e[r]);if(lb)for(var r of lb(e))qz.call(e,r)&&cb(t,r,e[r]);return t},Yz=(t,e)=>Gz(t,Wz(e));function gc(t){var e,r,n,o,i;const s="setMatchUpStatus";t.matchUpStatus&&[ot,Rt].includes(t.matchUpStatus)&&(t.score=void 0);const{allowChangePropagation:a,disableScoreValidation:l,tournamentRecords:c,tournamentRecord:u,disableAutoCalc:p,enableAutoCalc:d,drawDefinition:v,matchUpStatus:f,winningSide:m,matchUpId:h,event:g,score:_}=t;if(!v)return{error:ue};if(f&&[Ho,so,Wr,Ft].includes(f)&&m)return{error:X,winningSide:m,matchUpStatus:f};if(![void 0,...lV].includes(f))return k({result:{error:fl},info:"matchUpStatus does not exist",stack:"setMatchUpStatus"});const I=lr({drawDefinition:v}),{matchUps:P}=Lt({nextMatchUps:!0,inContext:!0,drawDefinition:v,matchUpsMap:I,event:g}),y=I.drawMatchUps.find(x=>x.matchUpId===h),S=P==null?void 0:P.find(x=>x.matchUpId===h);if(!y||!P)return{error:ir};if((y.winningSide||m)&&f===nt)return{context:"Cannot have Bye with winningSide",error:tf,matchUpStatus:f};const O=S==null?void 0:S.structureId,{structure:b}=Ne({drawDefinition:v,structureId:O}),w=(e=S==null?void 0:S.drawPositions)==null?void 0:e.filter(Boolean);let T;if(y.matchUpType===Qe){if(p)it({extension:{name:fa,value:!0},element:y});else if(d){const x=y.winningSide;yn({name:fa,element:y});const{winningSide:B,scoreStringSide1:z,scoreStringSide2:H,set:Y}=tc({drawDefinition:v,matchUpsMap:I,structure:b,matchUp:y,event:g}),Z={scoreStringSide1:z,scoreStringSide2:H,sets:Y?[Y]:[]};T=B!==x,Object.assign(t,{winningSide:B,dualWinningSideChange:T,projectedWinningSide:B,score:Z})}}if(y.matchUpType===Qe&&f&&[la].includes(f))return{error:X,info:"Not supported for matchUpType: TEAM"};const $=S==null?void 0:S.matchUpTieId,N=Ir({matchUpId:$||h,inContextDrawMatchUps:P,drawDefinition:v});if(_&&y.matchUpType!==Qe&&!l){const x=y.matchUpFormat||(b==null?void 0:b.matchUpFormat)||(v==null?void 0:v.matchUpFormat)||(g==null?void 0:g.matchUpFormat),B=Ov({existingMatchUpStatus:y.matchUpStatus,matchUpFormat:x,matchUpStatus:f,winningSide:m,score:_});if(B.error)return B}const E=y!=null&&y.sides?[]:st({drawDefinition:v,structureId:O}).positionAssignments,A=((r=y.sides)==null?void 0:r.map(x=>x.participantId).filter(Boolean).length)===2||(w==null?void 0:w.length)===2&&(E==null?void 0:E.filter(x=>w.includes(x.drawPosition)).every(x=>x.participantId));if(f&&aV.includes(f)&&!A)return k({result:{error:fl},info:"present in participantRequiredMatchUpStatuses",context:{matchUpStatus:f,bothSideParticipants:A}});const U=(o=(n=pt({policyTypes:[pu],tournamentRecord:u,drawDefinition:v,event:g}))==null?void 0:n.appliedPolicies)!=null?o:{};typeof t.policyDefinitions=="object"&&Object.assign(U,t.policyDefinitions);const C=(S==null?void 0:S.stage)===we&&S.finishingRound===1,M=C&&m,D=C&&y.winningSide&&!m&&(!t.matchUpStatus||t.matchUpStatus&&pv({matchUpStatus:t.matchUpStatus}))&&(!t.outcome||!Gt({outcome:t.outcome})),R=M&&m!==y.winningSide&&y.winningSide;if(Object.assign(t,{inContextDrawMatchUps:P,qualifierAdvancing:M,qualifierChanging:R,removingQualifier:D,inContextMatchUp:S,appliedPolicies:U,matchUpTieId:$,matchUpsMap:I,targetData:N,structure:b,matchUp:y}),$){const{matchUp:x}=lt({matchUpId:$,inContext:!0,drawDefinition:v,matchUpsMap:I,event:g});if(x){const B=(i=vr({matchUp:x,drawDefinition:v,structure:b,event:g}))==null?void 0:i.tieFormat,{projectedWinningSide:z}=Xq({drawDefinition:v,matchUpStatus:f,dualMatchUp:x,matchUpsMap:I,winningSide:m,tieFormat:B,structure:b,matchUp:y,event:g,score:_}),H=x.winningSide;T=z!==H,Object.assign(t,{isCollectionMatchUp:!0,dualWinningSideChange:T,projectedWinningSide:z,matchUpTieId:$,dualMatchUp:x,tieFormat:B})}}const j=qi(t),G=rc({matchUpStatus:f});if(!$){if(j&&!m&&(f&&pv({matchUpStatus:f})||f&&[Rt,tr].includes(f)))return{error:tf,activeDownstream:j,winningSide:m};if(m&&m===y.winningSide&&f&&!G)return{context:"winningSide must include directing matchUpStatus",error:tf,directingMatchUpStatus:G,matchUpStatus:f}}const{schedule:W}=t;if(W){const x=dd({disableNotice:!0,tournamentRecords:c,tournamentRecord:u,drawDefinition:v,matchUpId:h,schedule:W});if(x.error)return x}const q=y.matchUpType!==Qe&&!T&&m&&y.winningSide&&y.winningSide!==m;if(a&&q&&y.roundPosition)return Bz(t);const F=m&&!$||t.projectedWinningSide;Jn();const L=!j&&Vz(t)||F&&Kz(t)||G&&ub(t)||{error:Jx};return k({result:L,stack:s})}function Kz(t){const{matchUp:e,winningSide:r,matchUpTieId:n,dualWinningSideChange:o}=t;return r===e.winningSide||n&&!o?ub(t):k({result:{error:a_},stack:"winningSideWithDownstreamDependencies",context:{winningSide:r,matchUp:e}})}function ub(t){const{tournamentRecord:e,matchUp:r,event:n}=t,o=t.isCollectionMatchUp&&r.winningSide&&!t.winningSide&&!Gt({score:t.score}),i=t.isCollectionMatchUp?t.matchUpStatus||o&&Ft||Mt:t.matchUpStatus||Mt,s=t.removeScore||[Ho,ot].includes(i)&&![so,Wr].includes(i),a=Kn(Yz(zz({},t),{matchUpStatus:i,removeWinningSide:o,removeScore:s}));if(a.error)return a;if(t.isCollectionMatchUp){const{matchUpTieId:l,drawDefinition:c,matchUpsMap:u}=t,p=uo({matchUpId:l,tournamentRecord:e,drawDefinition:c,matchUpsMap:u,event:n});if(p.error)return p;Object.assign(a,{tieMatchUpResult:p})}return a}var Qz=Object.defineProperty,db=Object.getOwnPropertySymbols,Jz=Object.prototype.hasOwnProperty,Zz=Object.prototype.propertyIsEnumerable,pb=(t,e,r)=>e in t?Qz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xz=(t,e)=>{for(var r in e||(e={}))Jz.call(e,r)&&pb(t,r,e[r]);if(db)for(var r of db(e))Zz.call(e,r)&&pb(t,r,e[r]);return t};function Sd(t){let e=t.structureIds;const{tournamentRecord:r,drawDefinition:n,matchUpFormat:o,structureId:i,matchUpId:s,event:a}=t;if(!n)return{error:ue};if(!o)return{error:rf};if(!Xr(o))return{error:Jc};const l="setMatchUpFormat";if(s){const c=lt({drawDefinition:n,matchUpId:s,event:a});if(c.error)return c;if(!c.matchUp)return{error:ir};const u=c.matchUp;if((u==null?void 0:u.matchUpType)===Bt)return{error:tn,info:"Cannot set matchUpFormat when { matchUpType: TEAM }"};u.matchUpFormat=o,Ze({tournamentId:r==null?void 0:r.tournamentId,eventId:a==null?void 0:a.eventId,context:l,drawDefinition:n,matchUp:u})}else if(Array.isArray(e)){if((a==null?void 0:a.eventType)===Bt)return{error:gi};for(const c of e){const u=Ne({drawDefinition:n,structureId:c});if(u.error)return u;if(u.structure)u.structure.matchUpFormat=o;else return{error:bt}}}else if(i){if((a==null?void 0:a.eventType)===Bt)return{error:gi};const c=Ne({drawDefinition:n,structureId:i});if(c.error)return c;if(c.structure)c.structure.matchUpFormat=o;else return{error:bt}}else n&&(n.matchUpFormat=o);return e=e||(i?[i]:void 0),et({drawDefinition:n,structureIds:e}),Xz({},V)}function fb(t){const{matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}=t;if(!o)return{sets:[]};const i=o.sets||[];let s=po({winnerFirst:!1,matchUpFormat:e,matchUpStatus:r,sets:i}),a=po({winnerFirst:!1,reversed:!0,matchUpFormat:e,matchUpStatus:r,sets:i});const l=po({matchUpFormat:e,matchUpStatus:r,winningSide:n,sets:i}),c=s===l?a:s;return n&&(s=n===1?l:c,a=n===2?l:c),{score:{sets:i,scoreStringSide1:s,scoreStringSide2:a}}}var eY=Object.defineProperty,vb=Object.getOwnPropertySymbols,tY=Object.prototype.hasOwnProperty,rY=Object.prototype.propertyIsEnumerable,mb=(t,e,r)=>e in t?eY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,nY=(t,e)=>{for(var r in e||(e={}))tY.call(e,r)&&mb(t,r,e[r]);if(vb)for(var r of vb(e))rY.call(e,r)&&mb(t,r,e[r]);return t};function _c(t){var e;const{tournamentRecords:r,policyDefinitions:n,tournamentRecord:o,disableAutoCalc:i,enableAutoCalc:s,drawDefinition:a,matchUpFormat:l,matchUpId:c,schedule:u,event:p,notes:d}=t;if(!a)return{error:kr};if(!c)return{error:Vt};const{policy:v}=cs({policyType:da,tournamentRecord:o,event:p}),f=t.allowChangePropagation!==void 0&&t.allowChangePropagation||(v==null?void 0:v.allowChangePropagation)!==void 0&&v.allowChangePropagation||void 0,{outcome:m}=t;if(l){const h=Sd({tournamentRecord:o,drawDefinition:a,matchUpFormat:l,matchUpId:c,event:p});if(h.error)return h}if((e=m==null?void 0:m.score)!=null&&e.sets&&!m.score.scoreStringSide1){const{score:h}=fb(m);m.score=h,m.score.sets=m.score.sets.filter(g=>g.side1Score||g.side2Score||g.side1TiebreakScore||g.side2TiebreakScore)}return gc({matchUpStatusCodes:m==null?void 0:m.matchUpStatusCodes,matchUpStatus:m==null?void 0:m.matchUpStatus,winningSide:m==null?void 0:m.winningSide,allowChangePropagation:f,score:m==null?void 0:m.score,tournamentRecords:r,policyDefinitions:n,tournamentRecord:o,disableAutoCalc:i,enableAutoCalc:s,drawDefinition:a,matchUpFormat:l,matchUpId:c,schedule:u,event:p,notes:d})}function hb(t){var e;if(!t.tournamentRecord)return{error:re};const{tournamentRecords:r,tournamentRecord:n,outcomes:o,policyDefinitions:i}=t,s={};o.forEach(a=>{const{eventId:l}=a;s[l]||(s[l]=[]),s[l].push(a)});for(const a of Object.keys(s)){const{event:l}=Qt({tournamentRecord:n,eventId:a});for(const c of s[a]){const{drawId:u}=c,p=(e=l==null?void 0:l.drawDefinitions)==null?void 0:e.find(d=>d.drawId===u);if(p&&u){const{matchUpFormat:d,matchUpId:v}=c,f=_c({schedule:c==null?void 0:c.schedule,tournamentRecords:r,policyDefinitions:i,tournamentRecord:n,drawDefinition:p,matchUpFormat:d,matchUpId:v,outcome:c,drawId:u,event:l});if(f.error)return f}}}return nY({},V)}var oY=Object.defineProperty,iY=Object.defineProperties,sY=Object.getOwnPropertyDescriptors,gb=Object.getOwnPropertySymbols,aY=Object.prototype.hasOwnProperty,lY=Object.prototype.propertyIsEnumerable,_b=(t,e,r)=>e in t?oY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ib=(t,e)=>{for(var r in e||(e={}))aY.call(e,r)&&_b(t,r,e[r]);if(gb)for(var r of gb(e))lY.call(e,r)&&_b(t,r,e[r]);return t},cY=(t,e)=>iY(t,sY(e));function uY(t){const e=t.tournamentRecords,r=t.tournamentId||Xv(t);if(typeof r!="string")return{error:yo};const n=e[r];if(!n)return{error:re};const{drawDefinition:o,event:i}=Qt({eventId:t.eventId,drawId:t.drawId,tournamentRecord:n});return _c(cY(Ib({tournamentRecord:n},t),{drawDefinition:o,event:i}))}function dY(t){const{tournamentRecords:e,outcomes:r}=t;if(!Array.isArray(r))return{error:_e,info:or("outcomes")};const n=r.reduce((o,i)=>o.includes(i.tournamentId)?o:o.concat(i.tournamentId),[]);for(const o of n){const i=e[o];if(!i)return{error:re};const s=r.filter(a=>a.tournamentId===o);if(s.length){const a=hb({tournamentRecord:i,outcomes:s});if(a.error)return a}}return Ib({},V)}function Pb({courtPrefix:t="C|",minRowsCount:e,courtsData:r}){if(!Array.isArray(r))return{error:X};const n=r==null?void 0:r.reduce((s,a)=>{const l=a.matchUps||[],c=Math.max(0,...l.map(u=>u.schedule.courtOrder||0));return c>s?c:s},1),o=e?Math.max(e,n):n,i=ce(0,o).map(s=>({matchUps:ce(0,r.length).map(a=>{const l=r[a],{courtId:c,venueId:u}=l;return{schedule:{courtOrder:s+1,venueId:u,courtId:c}}})}));return r.forEach((s,a)=>{var l;for(const c of s.matchUps){const u=(l=c.schedule)==null?void 0:l.courtOrder;u&&(i[u-1].matchUps[a]=c)}}),{courtPrefix:t,rows:i.map((s,a)=>Object.assign({rowId:`rowId-${a+1}`},...s.matchUps.map((l,c)=>({[`${t}${c}`]:l}))))}}var pY=Object.defineProperty,fY=Object.defineProperties,vY=Object.getOwnPropertyDescriptors,yb=Object.getOwnPropertySymbols,mY=Object.prototype.hasOwnProperty,hY=Object.prototype.propertyIsEnumerable,Sb=(t,e,r)=>e in t?pY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vm=(t,e)=>{for(var r in e||(e={}))mY.call(e,r)&&Sb(t,r,e[r]);if(yb)for(var r of yb(e))hY.call(e,r)&&Sb(t,r,e[r]);return t},mm=(t,e)=>fY(t,vY(e));function Ic(t){var e,r,n,o,i,s,a,l,c,u,p,d;const{flight:v,suppressNotifications:f,modifyEventEntries:m,existingDrawCount:h,allowReplacement:g,checkEntryStatus:_,tournamentRecord:I,drawDefinition:P,event:y}=t;if(!P)return{error:kr};if(!y)return{error:Ge};y.drawDefinitions||(y.drawDefinitions=[]);const{drawId:S,drawName:O,entries:b}=P,{entries:w}=y;let T=0;if(h!==void 0&&h!==y.drawDefinitions.length)return{error:X,info:"drawDefintions count mismatch"};const{flightProfile:$}=Nt({event:y}),N=v&&((e=$==null?void 0:$.flights)==null?void 0:e.find(x=>x.flightNumber===v.flightNumber)),E=(o=(n=(r=$==null?void 0:$.links)==null?void 0:r.find(x=>{var B;return((B=x==null?void 0:x.target)==null?void 0:B.drawId)===S}))==null?void 0:n.source)==null?void 0:o.drawId;if(E&&!y.drawDefinitions.find(x=>x.drawId===E))return k({result:{error:ue},info:{sourceDrawId:E}});if(N&&N.drawId!==P.drawId)return k({result:{error:Xi},info:{relevantFlight:N}});const C=b==null?void 0:b.every(({participantId:x,entryStatus:B})=>{const z=N==null?void 0:N.drawEntries.find(H=>H.participantId===x);return!B||(z==null?void 0:z.entryStatus)===B}),M=!_||w&&(b==null?void 0:b.every(({participantId:x,entryStatus:B,entryStage:z})=>{const H=w.find(Y=>Y.participantId===x&&(!Y.entryStage||Y.entryStage===z));return(H==null?void 0:H.entryStatus)===B}));if(N&&!C)return k({result:{error:Xi,context:{drawEntriesPresentInFlight:C,matchingEventEntries:M,relevantFlight:N},info:"Draw entries are not present in flight or do not match entryStatuses"}});if(m&&(b==null||b.filter(Boolean).forEach(x=>{if(x!=null&&x.entryStatus&&Fi.includes(x==null?void 0:x.entryStatus)){const B=w==null?void 0:w.filter(Boolean).find(z=>z.participantId===x.participantId);B&&x.entryStatus&&(B==null?void 0:B.entryStatus)!==x.entryStatus&&(B.entryStatus=x.entryStatus,T+=1)}})),w&&!M)return k({result:{error:Xi,context:{matchingEventEntries:M,eventEntries:w},info:"Draw entries do not match event entryStatuses"}});const D=((s=(i=$==null?void 0:$.flights)==null?void 0:i.map(({flightNumber:x})=>!isNaN(x)&&Te(x)))==null?void 0:s.filter(Boolean))||[],R=((a=y.drawDefinitions.map(({drawOrder:x})=>x&&Te(x)))==null?void 0:a.filter(Boolean))||[];let j=Math.max(0,...R,...D)+1;const G=(l=$==null?void 0:$.flights)==null?void 0:l.find(x=>x.drawId===S);let W;if(G){G.drawName=P.drawName,W={name:_n,value:mm(vm({},$),{flights:$.flights})};const x=G.flightNumber;x&&!R.includes(x)?j=x:G.flightNumber=j}else{const x=($==null?void 0:$.flights)||[];x.push({manuallyAdded:!0,flightNumber:j,drawEntries:b,drawName:O,drawId:S}),W={name:_n,value:mm(vm({},$||{}),{flights:x})}}ao({event:y,extension:W}),Object.assign(P,{drawOrder:j});const q=y.drawDefinitions.find(x=>x.drawId===S),F=I==null?void 0:I.tournamentId,L=y.eventId;if(q){if(!g)return{error:ZF};const x=(c=zr({drawDefinition:q}))==null?void 0:c.matchUps,B=(u=x==null?void 0:x.map(Jt))!=null?u:[],z=(p=zr({drawDefinition:P}))==null?void 0:p.matchUps;if(!f){B!=null&&B.length&&Vi({matchUpIds:B,action:"modifyDrawDefinition",tournamentId:F,eventId:L}),z!=null&&z.length&&Li({matchUps:z,tournamentId:F,eventId:L}),y.drawDefinitions=y.drawDefinitions.map(Y=>Y.drawId===S?P:Y);const H=(d=P.structures)==null?void 0:d.map(({structureId:Y})=>Y);et({drawDefinition:P,tournamentId:F,structureIds:H,eventId:L})}}else if(y.drawDefinitions.push(P),!f){const{matchUps:x}=zr({drawDefinition:P,event:y});x&&Li({tournamentId:I==null?void 0:I.tournamentId,matchUps:x}),nc({drawDefinition:P,tournamentId:F,eventId:L})}return mm(vm({},V),{modifiedEventEntryStatusCount:T})}function gY({tournamentRecords:t,existingDrawCount:e,allowReplacement:r,drawDefinition:n,tournamentId:o,eventId:i,flight:s}){if(!i)return{error:Ge};if(o=o??Xv({tournamentRecords:t,eventId:i}),!o)return{error:yo};const a=t[o];if(!a)return{error:re};const l=Qt({tournamentRecord:a,eventId:i});return l.event?l.error?l:Ic({event:l.event,existingDrawCount:e,allowReplacement:r,drawDefinition:n,flight:s}):{error:Ar}}var _Y=Object.defineProperty,IY=Object.defineProperties,PY=Object.getOwnPropertyDescriptors,Ob=Object.getOwnPropertySymbols,yY=Object.prototype.hasOwnProperty,SY=Object.prototype.propertyIsEnumerable,bb=(t,e,r)=>e in t?_Y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Od=(t,e)=>{for(var r in e||(e={}))yY.call(e,r)&&bb(t,r,e[r]);if(Ob)for(var r of Ob(e))SY.call(e,r)&&bb(t,r,e[r]);return t},OY=(t,e)=>IY(t,PY(e));function Zn({allowDuplicateParticipantIdPairs:t,returnParticipant:e,tournamentRecord:r,disableNotice:n,pairOverride:o,participant:i}){var s,a,l;const c="addParticipant";if(!r)return{error:re};if(!i)return k({result:{error:oa},stack:c});i.participantId||(i.participantId=Ye()),r.participants||(r.participants=[]);const{participantId:u,individualParticipantIds:p}=i;if(r.participants.reduce((_,I)=>I.participantId===u||_,!1))return{error:Ex};const{participantType:v,participantRole:f}=i;if(!v||!Object.keys(Vl).includes(v))return{error:jn,participantType:v};if(!f)return{error:wx};const m=r.participants||[],h=m.filter(_=>_.participantType===Fe).map(_=>_.participantId);if(v!==Fe&&i.person)return{error:X,person:i.person};if(p&&!Array.isArray(p))return{error:X,individualParticipantIds:p};if(v===Ce){if(i.person)return{error:X,person:i.person};if(i.individualParticipantIds){if(i.individualParticipantIds.length!==2&&!o)return k({result:{error:pn,info:"PAIR must be 2 individualParticipantIds"},stack:c});{const P=m.filter(S=>S.participantType===Fe).map(S=>S.participantId);if(!Array.isArray(i.individualParticipantIds))return k({result:{error:pn},stack:c});if(!i.individualParticipantIds.reduce((S,O)=>P.includes(O)&&S,!0))return k({result:{error:pn},stack:c})}}else return k({result:{error:Oo},stack:c});const _=m.filter(P=>P.participantType===Ce).map(P=>({individualParticipantIds:P.individualParticipantIds,participant:P})),I=i.participantType===Ce&&_.find(P=>Ht(P.individualParticipantIds,i.individualParticipantIds).length===2);if(I&&!t)return OY(Od({},V),{existingParticipant:!0,participant:e&&de(I.participant)});if(!i.participantName){const P=m.filter(S=>{var O;return(O=i.individualParticipantIds)==null?void 0:O.includes(S.participantId)});let y=P.map(S=>{var O;return(O=S.person)==null?void 0:O.standardFamilyName}).filter(Boolean).join("/");P.length===1&&(y+="/Unknown"),i.participantName=y}}else if(v===Fe){if(!((s=i.person)!=null&&s.standardFamilyName)||!((a=i.person)!=null&&a.standardGivenName))return{error:Ax};if(!i.participantName){const _=`${i.person.standardFamilyName.toUpperCase()}, ${i.person.standardGivenName}`;i.participantName=_}}else if(v&&[tt,Mr].includes(v)){if(p||(i.individualParticipantIds=[]),(l=i.individualParticipantIds)!=null&&l.length)for(const _ of i.individualParticipantIds){if(typeof _!="string")return k({result:{participantId:_,error:X},stack:c});if(!h.includes(_))return k({result:{participantId:_,error:jt},stack:c})}}else return{error:jn};r.participants.push(i),n||He({payload:{tournamentId:r.tournamentId,participants:[i]},topic:$i});const g=Od({participant:e&&de(i)},V);return Oe(g)}function ho({allowDuplicateParticipantIdPairs:t,returnParticipants:e,participants:r,tournamentRecord:n}){if(!n)return{error:re};n.participants||(n.participants=[]);const i=n.participants.map(d=>d.participantId)||[];r.forEach(d=>{d.participantId||(d.participantId=Ye())});const s=r.filter(d=>!i.includes(d.participantId)),a=r.filter(d=>i.includes(d.participantId)),l=s.filter(d=>d.participantType===Fe),c=s.filter(d=>d.participantType!==Fe),u=l.concat(...c),p=[];if(u.length){for(const v of u){const f=Zn({allowDuplicateParticipantIdPairs:t,returnParticipant:!0,disableNotice:!0,tournamentRecord:n,participant:v});if(f.error)return f;f.success&&!f.existingParticipant&&p.push(f.participant)}p.length&&He({topic:$i,payload:{tournamentId:n.tournamentId,participants:p}});const d=Od({participants:e&&de(p),addedCount:p.length},V);return a.length&&Object.assign(d,{notAdded:a,info:cf}),Oe(d)}else return Od({info:"No new participants to add",addedCount:0},V)}function bY({tournamentRecords:t,returnParticipant:e,pairOverride:r,tournamentId:n,participant:o}){if(typeof n!="string")return{error:yo};const i=t[n];return i?Zn({returnParticipant:e,tournamentRecord:i,pairOverride:r,participant:o}):{error:re}}function TY({event:t}){var e;const r=`${Hr}.${qr}`,{timeItem:n}=Un({element:t,itemType:r});if((e=n==null?void 0:n.itemValue)!=null&&e.PUBLIC){const{drawIds:o=[],seeding:i}=n.itemValue.PUBLIC||{},s={published:void 0,seedingScaleNames:[],drawIds:[]};return i&&Object.assign(s,n.itemValue.PUBLIC.seeding),{publishedDrawIds:o,publishedSeeding:s}}}function bd({element:t,accessor:e}){if(typeof e!="string")return{values:[]};const r=de(t),n=e.split("."),o=[];let i;a({targetElement:r,attributes:n});const s={value:i};return o.length&&(s.values=o),s;function a({targetElement:l,attributes:c=[],significantCharacters:u}){for(const[d,v]of c.entries())if(l!=null&&l[v])if(Array.isArray(l[v])){const f=l[v],m=c.slice(d);f.forEach(h=>a({targetElement:h,attributes:m}))}else l=l[v],p({targetElement:l,index:d});function p({targetElement:d,index:v}){if(d&&v===c.length-1&&["string","number"].includes(typeof d)){const f=u?d.slice(0,u):d;i?o.includes(f)||o.push(f):(i=f,o.push(f))}}}}function go({requireTimeStamp:t,scaleAttributes:e,participant:r}){var n,o;if(!r)return{error:oa};if(typeof e!="object")return{error:X};if(r.timeItems||(r.timeItems=[]),r&&Array.isArray(r.timeItems)){const{accessor:i,scaleType:s,eventType:a,scaleName:l}=e,c=[ds,s,a,l].join("."),p=r.timeItems.filter(d=>(d==null?void 0:d.itemType)===c).filter(d=>!t||(d==null?void 0:d.itemDate)).sort((d,v)=>(d.createdAt?new Date(d.createdAt).getTime():0)-(v.createdAt?new Date(v.createdAt).getTime():0)).pop();if(p){const[d,v,f,m]=(o=(n=p.itemType)==null?void 0:n.split("."))!=null?o:[];if(d!==ds)return{error:nu};const h=i&&bd({element:p.itemValue,accessor:i}),g=(h==null?void 0:h.value)||p.itemValue;return{scaleItem:{eventType:f,scaleDate:p.itemDate,scaleValue:g,scaleName:m,scaleType:v}}}else return{error:qx}}return{error:oa}}function wY({publishedSeeding:t,usePublishState:e,withSeeding:r,participant:n,event:o}){var i,s,a;const l={},c=f=>[ds,In,o.eventType,f].join("."),u=Object.assign({},...(n.timeItems||[]).filter(({itemType:f})=>f.split(".")[1]===In).map(({itemType:f,itemValue:m})=>({[f]:m}))),p=((t==null?void 0:t.stageSeedingScaleNames)&&Object.values(t==null?void 0:t.stageSeedingScaleNames)||Array.isArray(t==null?void 0:t.seedingScaleNames)&&t.seedingScaleNames||[]).map(c),d=Ht(Object.keys(u),p);if(!!(!e||!Object.keys(u).length&&!((i=t==null?void 0:t.drawIds)!=null&&i.length)||d.length)&&d.length){if(t!=null&&t.stageSeedingScaleNames){const f=Object.keys(t.stageSeedingScaleNames).map(h=>{const g=c(t.stageSeedingScaleNames[h]),_=u[g];return[h,_]}).filter(h=>h[1]).map(h=>({[h[0]]:{seedValue:h[1]}})),m=Object.assign({},...f);l.seedAssignments=m}else if(d){const f=d.map(m=>u[m]);l.seedValue=f.pop()}}else if(!e&&typeof r=="object"){const f=Object.keys(r).map(h=>{const g=c(r[h]),_=u[g];return[h,_]}).filter(h=>h[1]).map(h=>({[h[0]]:{seedValue:h[1]}})),m=Object.assign({},...f);l.seedAssignments=m}else{const{categoryName:f,ageCategoryCode:m}=o.category||{};let h;for(const g of[m,o.eventId,f]){const _={eventType:o.eventType,scaleType:In,scaleName:g},I=go({scaleAttributes:_,participant:n});if(I.scaleItem){h=I.scaleItem;break}}if(h&&(!e||(t==null?void 0:t.published)&&!((a=(s=t==null?void 0:t.published)==null?void 0:s.drawIds)!=null&&a.length))){const _=h.scaleValue;l.seedValue=_}}return l}var EY=Object.defineProperty,$Y=Object.defineProperties,NY=Object.getOwnPropertyDescriptors,Tb=Object.getOwnPropertySymbols,UY=Object.prototype.hasOwnProperty,AY=Object.prototype.propertyIsEnumerable,wb=(t,e,r)=>e in t?EY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Td=(t,e)=>{for(var r in e||(e={}))UY.call(e,r)&&wb(t,r,e[r]);if(Tb)for(var r of Tb(e))AY.call(e,r)&&wb(t,r,e[r]);return t},wd=(t,e)=>$Y(t,NY(e));function Eb({tournamentRecord:t,matchUpFormat:e,event:r}){if(!t)return{error:re};if(!Xr(e))return{error:Jc};const{extension:n}=$o({event:r,name:Wn}),o=n==null?void 0:n.value,{extension:i}=Fr({tournamentRecord:t,name:Wn}),s=i==null?void 0:i.value,a=(o==null?void 0:o.matchUpAverageTimes)&&Nl(wd(Td({},o),{matchUpFormat:e})),l=(s==null?void 0:s.matchUpAverageTimes)&&Nl(wd(Td({},s),{matchUpFormat:e})),c=[a,l].find(v=>v),u=(o==null?void 0:o.matchUpRecoveryTimes)&&Ul(wd(Td({},o),{matchUpFormat:e})),p=(s==null?void 0:s.matchUpRecoveryTimes)&&Ul(wd(Td({},s),{matchUpFormat:e})),d=[u,p].find(v=>v);return{matchUpFormat:e,averageTimes:c,recoveryTimes:d}}var CY=Object.defineProperty,MY=Object.defineProperties,DY=Object.getOwnPropertyDescriptors,$b=Object.getOwnPropertySymbols,jY=Object.prototype.hasOwnProperty,RY=Object.prototype.propertyIsEnumerable,Nb=(t,e,r)=>e in t?CY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Pc=(t,e)=>{for(var r in e||(e={}))jY.call(e,r)&&Nb(t,r,e[r]);if($b)for(var r of $b(e))RY.call(e,r)&&Nb(t,r,e[r]);return t},Ed=(t,e)=>MY(t,DY(e));function hm({tournamentRecord:t,recoveryTimes:e,matchUpFormat:r,averageTimes:n,event:o}){if(!t)return{error:re};if(n&&!Array.isArray(n))return{error:X};if(e&&!Array.isArray(e))return{error:X};const i=Wn;if(o){const{extension:s}=$o({event:o,name:i}),a=(s==null?void 0:s.value)||{},l=Ub(Ed(Pc({},a),{matchUpFormat:r,averageTimes:n,recoveryTimes:e}));ao({event:o,extension:{name:i,value:l}})}else{const{extension:s}=Fr({tournamentRecord:t,name:i}),a=(s==null?void 0:s.value)||{},l=Ub(Ed(Pc({},a),{matchUpFormat:r,averageTimes:n,recoveryTimes:e}));Ei({tournamentRecord:t,extension:{name:i,value:l}})}return Pc({},V)}function Ub(t){const{matchUpRecoveryTimes:e=[],matchUpAverageTimes:r=[],matchUpFormat:n}=t;let{averageTimes:o,recoveryTimes:i}=t;o=(o||[]).filter(l=>{var c,u;return((c=l==null?void 0:l.categoryNames)==null?void 0:c.length)||((u=l==null?void 0:l.categoryTypes)==null?void 0:u.length)});const s=(o==null?void 0:o.length)&&r.map(l=>{var c;return l!=null&&l.matchUpFormatCodes.includes(n)?Ed(Pc({},l),{matchUpFormatCodes:(c=l.matchUpFormatCodes)==null?void 0:c.filter(u=>u!==n)}):l}).filter(({matchUpFormatCodes:l})=>l==null?void 0:l.length).concat({matchUpFormatCodes:[n],averageTimes:o});i=(i||[]).filter(l=>{var c,u;return((c=l==null?void 0:l.categoryNames)==null?void 0:c.length)||((u=l==null?void 0:l.categoryTypes)==null?void 0:u.length)});const a=(i==null?void 0:i.length)&&e.map(l=>{var c;return l!=null&&l.matchUpFormatCodes.includes(n)?Ed(Pc({},l),{matchUpFormatCodes:(c=l.matchUpFormatCodes)==null?void 0:c.filter(u=>u!==n)}):l}).filter(({matchUpFormatCodes:l,averageTimes:c})=>(l==null?void 0:l.length)||c).concat({matchUpFormatCodes:[n],recoveryTimes:i});return{matchUpAverageTimes:(s==null?void 0:s.length)&&s||r,matchUpRecoveryTimes:(a==null?void 0:a.length)&&a||e}}function Ab({tournamentRecord:t,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,event:i}){if(!t)return{error:re};if(!Xr(n))return{error:X};if(!i)return{error:Ge};const{averageTimes:s=[],recoveryTimes:a=[]}=Eb({tournamentRecord:t,matchUpFormat:n,event:i}),l=i.category,c=(l==null?void 0:l.categoryName)||(l==null?void 0:l.ageCategoryCode)||(i==null?void 0:i.eventId);let u={categoryNames:[c],minutes:{}};const p={categoryNames:[c],minutes:{}},d=g=>{var _,I;if((_=g.categoryTypes)!=null&&_.includes(o)&&console.log("encountered:",{categoryType:o}),!((I=g.categoryNames)!=null&&I.includes(c)&&(g.categoryNames=g.categoryNames.filter(P=>P!==c),u={minutes:g.minutes,categoryNames:[c]},!g.categoryNames.length)))return g},v=!isNaN(Te(r)),f=!isNaN(Te(e)),m=s.map(d).filter(g=>{var _;return(_=g==null?void 0:g.categoryNames)==null?void 0:_.length}),h=a.map(d).filter(g=>{var _;return(_=g==null?void 0:g.categoryNames)==null?void 0:_.length});return v&&(Object.assign(u.minutes,{[(i==null?void 0:i.eventType)||At]:r}),m.push(u)),f&&(Object.assign(p.minutes,{[(i==null?void 0:i.eventType)||At]:e}),h.push(p)),!v&&!f?{error:X}:hm({averageTimes:v&&m,recoveryTimes:f&&h,tournamentRecord:t,matchUpFormat:n,event:i})}function FY({tournamentRecords:t,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,tournamentId:i,eventId:s}){if(!s)return{error:Ge};const a=Object.keys(t).filter(l=>!i||i===l);if(i&&!a.includes(i))return{error:X};for(const l of a){const c=t[l],{event:u}=Qt({tournamentRecord:c,eventId:s});if(u)return Ab({tournamentRecord:c,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,event:u})}return{error:Ar}}const yc=({scheduleAttributes:t=["scheduledDate","scheduledTime"],schedule:e={}})=>!!Object.keys(e).filter(n=>t.includes(n)).filter(n=>e[n]).length;var xY=Object.defineProperty,LY=Object.defineProperties,VY=Object.getOwnPropertyDescriptors,Cb=Object.getOwnPropertySymbols,BY=Object.prototype.hasOwnProperty,kY=Object.prototype.propertyIsEnumerable,Mb=(t,e,r)=>e in t?xY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,GY=(t,e)=>{for(var r in e||(e={}))BY.call(e,r)&&Mb(t,r,e[r]);if(Cb)for(var r of Cb(e))kY.call(e,r)&&Mb(t,r,e[r]);return t},WY=(t,e)=>LY(t,VY(e));function Sc({tournamentRecord:t}){if(!t)return{error:re};const e=(({tournamentId:r,tournamentRank:n,tournamentStatus:o,formalName:i,tournamentName:s,promotionalName:a,onlineResources:l,localTimeZone:c,startDate:u,endDate:p,hostCountryCode:d,tournamentContacts:v,tournamentAddresses:f})=>({tournamentId:r,tournamentRank:n,tournamentStatus:o,formalName:i,tournamentName:s,promotionalName:a,onlineResources:l,localTimeZone:c,startDate:u,endDate:p,hostCountryCode:d,tournamentContacts:v,tournamentAddresses:f}))(t);return WY(GY({},V),{tournamentInfo:de(e,!1,!0)})}var HY=Object.defineProperty,$d=Object.getOwnPropertySymbols,Db=Object.prototype.hasOwnProperty,jb=Object.prototype.propertyIsEnumerable,Rb=(t,e,r)=>e in t?HY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Fb=(t,e)=>{for(var r in e||(e={}))Db.call(e,r)&&Rb(t,r,e[r]);if($d)for(var r of $d(e))jb.call(e,r)&&Rb(t,r,e[r]);return t},xb=(t,e)=>{var r={};for(var n in t)Db.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&$d)for(var n of $d(t))e.indexOf(n)<0&&jb.call(t,n)&&(r[n]=t[n]);return r};function Lb({derivedDrawInfo:t,participantId:e,drawId:r}){var n,o,i,s;const a=(o=(n=t[r])==null?void 0:n.mainPositionAssignments)==null?void 0:o.find(u=>u.participantId===e),l=(s=(i=t[r])==null?void 0:i.qualifyingPositionAssignments)==null?void 0:s.find(u=>u.participantId===e),c={};if(a){const u=a,{participantId:p}=u,d=xb(u,["participantId"]);p&&(c[he]=Fb({},d))}if(l){const u=l,{participantId:p}=u,d=xb(u,["participantId"]);p&&(c[we]=Fb({},d))}return Object.keys(c).length?c:void 0}function qY({processParticipantId:t,tournamentRecords:e,tournamentRecord:r}){if(typeof r!="object"&&typeof e!="object")return{error:re};const n=e?Object.values(e).map(i=>(i==null?void 0:i.participants)||[]).flat():(r==null?void 0:r.participants)||[];return{relevantParticipantIdsMap:Object.assign({},...n.map(({participantId:i,participantType:s,individualParticipantIds:a})=>{typeof t=="function"&&t(i);const l=(a||[]).map(c=>({participantType:Fe,relevantParticipantId:c}));return{[i]:l.concat({relevantParticipantId:i,participantType:s})}}))}}var zY=Object.defineProperty,Nd=Object.getOwnPropertySymbols,Vb=Object.prototype.hasOwnProperty,Bb=Object.prototype.propertyIsEnumerable,kb=(t,e,r)=>e in t?zY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Gb=(t,e)=>{for(var r in e||(e={}))Vb.call(e,r)&&kb(t,r,e[r]);if(Nd)for(var r of Nd(e))Bb.call(e,r)&&kb(t,r,e[r]);return t},Wb=(t,e)=>{var r={};for(var n in t)Vb.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Nd)for(var n of Nd(t))e.indexOf(n)<0&&Bb.call(t,n)&&(r[n]=t[n]);return r};function Ud({derivedDrawInfo:t,participantId:e,drawId:r}){var n,o,i,s;const a=(o=(n=t[r])==null?void 0:n.mainSeedAssignments)==null?void 0:o.find(u=>u.participantId===e),l=(s=(i=t[r])==null?void 0:i.qualifyingSeedAssignments)==null?void 0:s.find(u=>u.participantId===e),c={};if(a){const u=a,{participantId:p}=u,d=Wb(u,["participantId"]);p&&(c[he]=Gb({},d))}if(l){const u=l,{participantId:p}=u,d=Wb(u,["participantId"]);p&&(c[we]=Gb({},d))}return Object.keys(c).length?c:void 0}function Hb({scheduleAttributes:t=["scheduledDate","scheduledTime"],matchUps:e=[]}){if(!Array.isArray(e))return{error:ko};if(!Array.isArray(t))return{error:X};const r=e.filter(Boolean).filter(({schedule:o})=>yc({schedule:o,scheduleAttributes:t})).reduce((o,i)=>{const{schedule:s}=i,a=Re(s==null?void 0:s.scheduledDate),l=at(s==null?void 0:s.scheduledTime);return a&&l&&(o[a]?o[a].push(i):o[a]=[i]),o},{});return Object.keys(r).forEach(o=>{r[o].sort((i,s)=>{var a,l;return j_(at((a=i.schedule)==null?void 0:a.scheduledTime),at((l=s.schedule)==null?void 0:l.scheduledTime))})}),{scheduledMatchUps:r}}var YY=Object.defineProperty,KY=Object.defineProperties,QY=Object.getOwnPropertyDescriptors,qb=Object.getOwnPropertySymbols,JY=Object.prototype.hasOwnProperty,ZY=Object.prototype.propertyIsEnumerable,zb=(t,e,r)=>e in t?YY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,XY=(t,e)=>{for(var r in e||(e={}))JY.call(e,r)&&zb(t,r,e[r]);if(qb)for(var r of qb(e))ZY.call(e,r)&&zb(t,r,e[r]);return t},e7=(t,e)=>KY(t,QY(e));function t7(t){var e,r,n,o,i,s,a,l,c,u,p;const{withScaleValues:d=!0,eventsPublishStatuses:v,withEvents:f=!0,withDraws:m=!0,participantIdMap:h,scheduleAnalysis:g,derivedDrawInfo:_,usePublishState:I,withStatistics:P,withOpponents:y,withMatchUps:S,withSeeding:O,participant:b,withISO2:w,withIOC:T}=t,$=[],N=[];if((T||w)&&Ju({participant:b,withIOC:T,withISO2:w}),d){const{ratings:J,rankings:te}=ha({participant:b});b.rankings=te,b.ratings=J}const E=b==null?void 0:b.participantId;if(!E||!h[E])return{};const{potentialMatchUps:A,opponents:U,matchUps:C,events:M,losses:D,draws:R,wins:j}=h[E],G=j+D,W=j,q=G&&W/G,F={statCode:$l,denominator:G,numerator:W,statValue:q},L=Object.values(R),x=Object.values(M);if(m&&L){b.draws=L;for(const J of L){const te=(e=v[J.eventId])==null?void 0:e.publishedSeeding;if(!I||(te==null?void 0:te.published)&&(((r=te==null?void 0:te.drawIds)==null?void 0:r.length)===0||((n=te==null?void 0:te.drawIds)==null?void 0:n.includes(J.drawId)))){const ee=Ud({drawId:J.drawId,derivedDrawInfo:_,participantId:E});ee&&(J.seedAssignments=ee)}}}if(f&&x&&(b.events=x,O)){const J=Object.assign({},...(b.timeItems||[]).filter(({itemType:te})=>te.split(".")[1]===In).map(({itemType:te,itemValue:ne})=>({[te]:ne})));for(const te of x){const ne=se=>[ds,In,te.eventType,se].join("."),ee=(o=v[te.eventId])==null?void 0:o.publishedSeeding,oe=((ee==null?void 0:ee.stageSeedingScaleNames)&&Object.values(ee==null?void 0:ee.stageSeedingScaleNames)||Array.isArray(ee==null?void 0:ee.seedingScaleNames)&&ee.seedingScaleNames||[]).map(ne),ie=Ht(Object.keys(J),oe),ae=!!(!I||!Object.keys(J).length&&!((i=ee==null?void 0:ee.drawIds)!=null&&i.length)||ie.length);if(ae&&ie.length){if(ee!=null&&ee.stageSeedingScaleNames){const se=Object.keys(ee.stageSeedingScaleNames).map(Ie=>{const pe=ne(ee.stageSeedingScaleNames[Ie]),fe=J[pe];return[Ie,fe]}).filter(Ie=>Ie[1]).map(Ie=>({[Ie[0]]:{seedValue:Ie[1]}})),ye=Object.assign({},...se);te.seedAssignments=ye}else if(ie){const se=ie.map(ye=>J[ye]);te.seedValue=se.pop()}}else if(!I&&typeof O=="object"){const se=Object.keys(O).map(Ie=>{const pe=ne(O[Ie]),fe=J[pe];return[Ie,fe]}).filter(Ie=>Ie[1]).map(Ie=>({[Ie[0]]:{seedValue:Ie[1]}})),ye=Object.assign({},...se);te.seedAssignments=ye}else{const{categoryName:se,ageCategoryCode:ye}=te.category||{};let Ie;for(const pe of[te.eventId,ye,se]){const fe={eventType:te.eventType,scaleType:In,scaleName:pe},ve=go({scaleAttributes:fe,participant:b});if(ve.scaleItem){Ie=ve.scaleItem;break}}if(Ie){const pe=Ie.scaleValue;(!I||(ee==null?void 0:ee.published)&&(((s=ee==null?void 0:ee.drawIds)==null?void 0:s.length)===0||((a=ee==null?void 0:ee.drawIds)==null?void 0:a.includes(te.drawId))))&&(te.seedValue=pe)}}if((l=te.drawIds)!=null&&l.length)for(const se of te.drawIds||[]){const ye=((c=ee==null?void 0:ee.drawIds)==null?void 0:c.length)&&!((u=ee==null?void 0:ee.drawIds)!=null&&u.includes(se));if(ae&&!ye){const Ie=Ud({drawId:se,derivedDrawInfo:_,participantId:E});if(Ie&&te.seedAssignments)for(const pe of Object.keys(te.seedAssignments))te.seedAssignments[pe]=Ie[pe];else te.seedAssignments=Ie}}}}const B=Object.values(U).flat();y&&(B!=null&&B.length)&&(b.opponents=B,L==null||L.forEach(J=>{J.opponents=B.filter(te=>te.drawId===J.drawId)}));const z=Object.values(A),H=Object.values(C);S&&(b.potentialMatchUps=z,b.matchUps=H);const Y=H.concat(z),Z=((p=Hb({matchUps:Y}))==null?void 0:p.scheduledMatchUps)||[],{scheduledMinutesDifference:K}=g||{};return Object.keys(Z).forEach(J=>{Z[J].filter(Boolean).forEach((te,ne)=>{var ee,oe,ie,ae;const{schedule:{scheduledTime:se,timeAfterRecovery:ye,typeChangeTimeAfterRecovery:Ie},matchUpStatus:pe,roundPosition:fe,structureName:ve,matchUpType:le,roundNumber:be,matchUpId:Me,drawId:Pe,score:xe}=te;N.push(e7(XY({},te.schedule),{scheduledTime:at((ee=te.schedule)==null?void 0:ee.scheduledTime),roundPosition:fe,structureName:ve,matchUpType:le,roundNumber:be,matchUpId:Me,drawId:Pe}));const Be=pe===nt||[ot,Xe].includes(pe)&&!Gt({score:xe});if(se&&!Be){const qe=Le(se),$e=Z[J].slice(ne+1);for(const De of $e)if(!(De.matchUpStatus===nt||[ot,Xe].includes(De.matchUpStatus)&&!Gt(De))&&((oe=De.schedule)!=null&&oe.scheduledTime)){const Se=te.matchUpType!==De.matchUpType&&Ie||ye,Ee=te.drawId===De.drawId,Ae=te.potential&&De.potential,gt=Le((ie=De.schedule)==null?void 0:ie.scheduledTime)-qe;(K&&!isNaN(K)?gt<=K:Le(Se)>Le((ae=De.schedule)==null?void 0:ae.scheduledTime))&&!(Ae&&Ee)&&$.push({priorScheduledMatchUpId:De.matchUpId,matchUpIdWithConflict:Me})}}})}),P&&(b.statistics=[F]),{scheduleConflicts:$,scheduleItems:N}}function r7({eventEntries:t,sortConfig:e,event:r}){var n;const o={},i=Object.assign({},...((n=r.drawDefinitions)!=null?n:[]).map(s=>{var a,l,c,u,p,d,v,f,m;const h=Object.assign({},...(t??[]).filter(N=>N.participantId).map(N=>({[N.participantId]:N})),...s.entries.filter(N=>N.participantId).map(N=>({[N.participantId]:N}))),g=Object.values(h),_=(l=(a=an({stageSequence:1,drawDefinition:s,stage:he}))==null?void 0:a.structures)==null?void 0:l[0],I=_&&((c=st({structure:_}))==null?void 0:c.positionAssignments),P=I==null?void 0:I.length,y=(p=(u=an({stageSequence:1,stage:we,drawDefinition:s}))==null?void 0:u.structures)==null?void 0:p[0],S=_&&((d=st({structure:y}))==null?void 0:d.positionAssignments),O=S==null?void 0:S.length,b=_==null?void 0:_.seedAssignments,w=y==null?void 0:y.seedAssignments,T=(s.structures||[]).sort((N,E)=>Ri(N,E,e)).map(({structureId:N,structures:E})=>[N,...(E||[]).map(({structureId:A})=>A)]).flat(1/0),$=(m=(f=(v=r==null?void 0:r._flightProfile)==null?void 0:v.flights)==null?void 0:f.find(N=>N.drawId===s.drawId))==null?void 0:m.flightNumber;return o[s.drawId]={qualifyingPositionAssignments:S,qualifyingSeedAssignments:w,mainPositionAssignments:I,mainSeedAssignments:b,orderedStructureIds:T,qualifyingDrawSize:O,flightNumber:$,drawSize:P},{[s.drawId]:{drawType:s.drawType,drawEntries:g}}}));return{derivedInfo:o,drawDetails:i}}function n7({relevantParticipantIdsMap:t,participantFilters:e,participantIdMap:r,derivedDrawInfo:n,eventDrawsCount:o,drawDetails:i,eventType:s,matchUp:a}){var l;const{collectionId:c,collectionPosition:u,drawId:p,drawName:d,eventId:v,eventName:f,finishingRound:m,finishingPositionRange:h,processCodes:g,loserTo:_,matchUpId:I,matchUpType:P,matchUpFormat:y,matchUpStatus:S,matchUpStatusCodes:O,matchUpTieId:b,roundName:w,roundNumber:T,roundPosition:$,score:N,sides:E,stage:A,stageSequence:U,schedule:C,structureName:M,structureId:D,tieFormat:R,tieMatchUps:j,tournamentId:G,winnerTo:W,winningSide:q}=a,F=e==null?void 0:e.participantIds,L=H=>{const Y=H&&t[H]||[];return Y.push(H),Y.some(Z=>!F||F.includes(Z.relevantParticipantId))?Y:[]},{winner:x,loser:B}=h||{},z=(j==null?void 0:j.length)&&j.filter(({matchUpType:H})=>H===mn).map(({sides:H})=>H.map(({sideNumber:Y,participantId:Z,participant:K})=>Y&&Z&&{sideNumber:Y,participantId:Z,participant:K})).flat().filter(Boolean)||[];if(s===lo&&P===mn){const H=(((l=a.sides)==null?void 0:l.filter(Boolean))||[]).map(({sideNumber:Y,participantId:Z,participant:K})=>Y&&Z&&{sideNumber:Y,participantId:Z,participant:K}).filter(Boolean);z.push(...H)}if(E==null||E.forEach(H=>{const{participantId:Y,sideNumber:Z}=H;if(!Y)return;const{drawType:K,drawEntries:Q}=i[p],J=Z===1?N==null?void 0:N.scoreStringSide1:N==null?void 0:N.scoreStringSide2,te=q&&Z===q,ne=a.sides.find(pe=>pe.sideNumber===3-Z),ee=ne==null?void 0:ne.participantId,oe=ee&&t[ee]||[],ie=te?x:B,ae=Q.find(pe=>pe.participantId===Y),se=L(Y),ye=[];z==null||z.filter(pe=>pe.sideNumber===Z).forEach(pe=>{const fe=pe.participantId;fe&&!ye.includes(fe)&&(se.push({relevantParticipantId:fe,participantType:Ce}),ye.push(fe))});const Ie=se.filter(pe=>s!==lo||s===lo&&[mn,hn].includes(P)&&[Ce,zn].includes(pe.participantType)||s===lo&&[bi,mn].includes(P)&&[Fe].includes(pe.participantType));Ie==null||Ie.forEach(({relevantParticipantId:pe,participantType:fe})=>{var ve,le;const{entryStage:be,entryStatus:Me,entryPosition:Pe}=ae||{};if(!r[pe])return;if(!r[pe].draws[p]){const me=Lb({participantId:pe,derivedDrawInfo:n,drawId:p}),ge=Ud({participantId:pe,derivedDrawInfo:n,drawId:p});r[pe].draws[p]=Oe({qualifyingDrawSize:(ve=n[p])==null?void 0:ve.qualifyingDrawSize,drawSize:(le=n[p])==null?void 0:le.drawSize,partnerParticipantIds:[],positionAssignments:me,seedAssignments:ge,entryPosition:Pe,entryStatus:Me,entryStage:be,drawName:d,drawType:K,eventId:v,drawId:p})}r[pe].events[v]||(r[pe].events[v]={partnerParticipantIds:[],drawIds:[],eventName:f,eventId:v});const xe=r[pe].events[v].drawIds;xe&&!(xe!=null&&xe.includes(p))&&r[pe].events[v].drawIds.push(p);let Be;if(fe===Fe&&P===mn){const me=Ie.find(ge=>ge.relevantParticipantId!==pe&&ge.participantType===Fe);Be=me==null?void 0:me.relevantParticipantId}const qe=(oe==null?void 0:oe.filter(me=>P===hn&&fe===zn&&me.participantType===zn||P===bi&&me.participantType===Fe||P===mn&&(fe===Fe?[Fe,Ce].includes(me.participantType):me.participantType===Ce)))||[];qe.forEach(({relevantParticipantId:me,participantType:ge})=>{r[pe].opponents||(r[pe].opponents={}),r[pe].opponents[me]={eventId:v,drawId:p,matchUpId:I,participantType:ge,participantId:me}});const $e=qe.map(({relevantParticipantId:me,participantType:ge})=>({participantId:me,participantType:ge}));(P!==hn&&[Fe,Ce].includes(fe)||P===hn&&fe===zn)&&(r[pe].matchUps[I]=Oe({collectionId:c,collectionPosition:u,drawId:p,eventId:v,eventType:s,eventDrawsCount:o,finishingRound:m,finishingPositionRange:ie,loserTo:_,matchUpId:I,matchUpType:P,matchUpFormat:y,matchUpStatus:S,matchUpStatusCodes:O,matchUpTieId:b,opponentParticipantInfo:$e,participantWon:te,partnerParticipantId:Be,perspectiveScoreString:J,processCodes:g,roundName:w,roundNumber:T,roundPosition:$,schedule:C,score:N,sides:E,stage:A,stageSequence:U,structureName:M,structureId:D,tieFormat:R,tournamentId:G,winnerTo:W,winningSide:q})),Be&&(r[pe].events[v].partnerParticipantIds.push(Be),r[pe].draws[p].partnerParticipantIds.push(Be),r[pe].events[v].partnerParticipantId=Be,r[pe].draws[p].partnerParticipantId=Be),q&&(te?r[pe].wins++:r[pe].losses++)})}),Array.isArray(a.potentialParticipants)){const H=oc(a.potentialParticipants.flat());H==null||H.forEach(Y=>{const Z=L(Y);Z==null||Z.forEach(({relevantParticipantId:K})=>{r[K].potentialMatchUps[I]=Oe({drawId:p,eventId:v,eventType:s,matchUpId:I,matchUpType:P,matchUpFormat:y,roundName:w,roundNumber:T,roundPosition:$,schedule:C,tieFormat:R,structureName:M,tournamentId:G,potential:!0})})})}}var o7=Object.defineProperty,i7=Object.defineProperties,s7=Object.getOwnPropertyDescriptors,Yb=Object.getOwnPropertySymbols,a7=Object.prototype.hasOwnProperty,l7=Object.prototype.propertyIsEnumerable,Kb=(t,e,r)=>e in t?o7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gm=(t,e)=>{for(var r in e||(e={}))a7.call(e,r)&&Kb(t,r,e[r]);if(Yb)for(var r of Yb(e))l7.call(e,r)&&Kb(t,r,e[r]);return t},_m=(t,e)=>i7(t,s7(e));function c7(t){var e,r;const n=[],o={},i={},s={},a=f=>{s[f]||(s[f]={groupParticipantIds:[],teamParticipantIds:[],pairParticipantIds:[],potentialMatchUps:{},scheduleItems:[],opponents:{},matchUps:{},events:{},groups:[],teams:[],draws:{},losses:0,wins:0})},{tournamentRecord:l,participantFilters:c,allTournamentParticipants:u}=t,{relevantParticipantIdsMap:p}=qY({processParticipantId:a,tournamentRecord:l}),d=c==null?void 0:c.participantIds,v=f=>{const m=f&&p[f]||[];return m.push(f),m.some(h=>!d||d.includes(h.relevantParticipantId))?m:[]};return t.withGroupings&&u.forEach(f=>{var m,h,g;if(f.participantType===Mr){const _=f.participantId;(m=f==null?void 0:f.individualParticipantIds)==null||m.forEach(I=>{s[I].groupParticipantIds.includes(_)||(s[I].groupParticipantIds.push(_),s[I].groups.push({participantRoleResponsibilities:f.participantRoleResponsibilities,participantOtherName:f.participantOtherName,participantName:f.participantName,participantId:f.participantId}))})}if(f.participantType===Qe){const _=f.participantId;(h=f==null?void 0:f.individualParticipantIds)==null||h.forEach(I=>{var P,y,S,O;(y=(P=s[I])==null?void 0:P.teamParticipantIds)!=null&&y.includes(_)||((S=s[I])==null||S.teamParticipantIds.push(_),(O=s[I])==null||O.teams.push({participantRoleResponsibilities:f.participantRoleResponsibilities,participantOtherName:f.participantOtherName,participantName:f.participantName,participantId:f.participantId,teamId:f.teamId}))})}if(f.participantType===Ce){const _=f.participantId;(g=f==null?void 0:f.individualParticipantIds)==null||g.forEach(I=>{s[I]&&!s[I].pairParticipantIds.includes(_)&&s[I].pairParticipantIds.push(_)})}}),t.withMatchUps&&cn({tournamentRecord:l}),(t.withScheduleItems||t.scheduleAnalysis||t.withStatistics||t.withOpponents||t.withMatchUps||t.withSeeding||t.withEvents||t.withDraws)&&((e=t.tournamentEvents)==null||e.forEach(f=>{var m,h,g,_,I,P,y;const S=de(f,!0,!0),O=Nt({event:S}).flightProfile,b=((m=O==null?void 0:O.flights)==null?void 0:m.length)||((h=S.drawDefinitions)==null?void 0:h.length)||0;(S.drawDefinitions||[]).forEach((L,x)=>{if((S==null?void 0:S.eventType)===Qe){const{extension:B}=Kt({element:f.drawDefinitions[x],name:kn});B&&(L.extensions=[B])}});const{eventId:w,eventName:T,eventType:$,category:N}=S,E={eventId:w,eventName:T,eventType:$,category:N},A=S&&Object.keys(S).filter(L=>L.startsWith("_"));A==null||A.forEach(L=>E[L]=S[L]);const U=S.entries||[],C=`${Hr}.${qr}`,{timeItem:M}=jo({itemType:C,event:S});if((g=M==null?void 0:M.itemValue)!=null&&g.PUBLIC){const{drawIds:L=[],seeding:x}=M.itemValue.PUBLIC||{},B={published:void 0,seedingScaleNames:[],drawIds:[]};x&&Object.assign(B,M.itemValue.PUBLIC.seeding),o[w]={publishedDrawIds:L,publishedSeeding:B}}const R=[...Object.values(cI)].map(L=>`_${L}`),j=E&&Object.keys(E).filter(L=>!R.includes(L)).reduce((L,x)=>(L[x]=E[x],L),{});U==null||U.filter(L=>L==null?void 0:L.participantId).forEach(L=>{const{participantId:x,entryStage:B,entryStatus:z,entryPosition:H}=L,Y=v(x);Y==null||Y.forEach(({relevantParticipantId:Z})=>{s[Z]||a(Z),s[Z].events[w]=_m(gm({},j),{partnerParticipantIds:[],entryPosition:H,entryStatus:z,entryStage:B,drawIds:[],eventId:w})})});const G=({drawEntry:L,drawId:x})=>{const{participantId:B,entryStage:z,entryStatus:H,entryPosition:Y}=L,Z=v(B);Z==null||Z.forEach(({relevantParticipantId:K})=>{var Q,J;if(s[K].events[w]||(s[K].events[w]=_m(gm({},j),{partnerParticipantIds:[],entryPosition:Y,entryStatus:H,entryStage:z,drawIds:[],eventId:w})),!s[K].draws[x]){const ne=Lb({participantId:K,derivedDrawInfo:i,drawId:x}),ee=Ud({participantId:K,derivedDrawInfo:i,drawId:x});s[K].draws[x]=Oe({qualifyingDrawSize:(Q=i[x])==null?void 0:Q.qualifyingDrawSize,drawSize:(J=i[x])==null?void 0:J.drawSize,partnerParticipantIds:[],positionAssignments:ne,eventDrawsCount:b,seedAssignments:ee,entryPosition:Y,entryStatus:H,entryStage:z,eventId:w,drawId:x})}const te=s[K].events[w].drawIds;te&&!(te!=null&&te.includes(x))&&s[K].events[w].drawIds.push(x)})},W=((_=S.drawDefinitions)==null?void 0:_.map(({drawId:L})=>L))||[];(P=(I=E._flightProfile)==null?void 0:I.flights)==null||P.forEach(L=>{const{drawId:x,drawEntries:B}=L;W.includes(x)||B==null||B.forEach(z=>G({drawEntry:z,drawId:x}))});const{drawDetails:q,derivedInfo:F}=r7({eventEntries:U,event:S});if(Object.assign(i,F),S.eventType===Qe||t.withScheduleItems||t.scheduleAnalysis||t.withStatistics||t.withOpponents||t.withMatchUps||t.withDraws){const L=(y=ai({afterRecoveryTimes:t.scheduleAnalysis,participants:u,nextMatchUps:!0,tournamentRecord:l,inContext:!0,event:S}))==null?void 0:y.matchUps;L==null||L.forEach(x=>n7({relevantParticipantIdsMap:p,participantFilters:c,participantIdMap:s,derivedDrawInfo:i,eventDrawsCount:b,drawDetails:q,eventType:$,matchUp:x}))}})),(r=t.tournamentParticipants)==null||r.forEach(f=>{const{scheduleConflicts:m,scheduleItems:h}=t7(_m(gm({},t),{eventsPublishStatuses:o,participantIdMap:s,derivedDrawInfo:i,participant:f}));if(t.withSignInStatus){const{timeItem:g}=Un({itemType:xl,element:f});f.signedIn=(g==null?void 0:g.itemValue)===Ll}if(t.withScheduleItems&&(f.scheduleItems=h),t.scheduleAnalysis&&(f.scheduleConflicts=m,m!=null&&m.length&&!n.includes(f.participantId)&&n.push(f.participantId)),t.withGroupings!==!1){const g=s[f.participantId];f.groupParticipantIds=g==null?void 0:g.groupParticipantIds,f.pairParticipantIds=g==null?void 0:g.pairParticipantIds,f.teamParticipantIds=g==null?void 0:g.teamParticipantIds,f.groups=g==null?void 0:g.groups,f.teams=g==null?void 0:g.teams}t.withTeamMatchUps}),{participantIdsWithConflicts:n,eventsPublishStatuses:o}}function Ad({participantFilters:t={},tournamentRecord:e,participants:r=[]}){var n;if(!Object.keys(t).length)return r;const{accessorValues:o,drawEntryStatuses:i,positionedParticipants:s,eventEntryStatuses:a,participantRoles:l,participantRoleResponsibilities:c,participantTypes:u,participantIds:p,signInStatus:d,enableOrFiltering:v,eventIds:f,genders:m}=t,h=_o(f)&&((n=e==null?void 0:e.events)==null?void 0:n.filter(y=>f==null?void 0:f.includes(y.eventId)))||(e==null?void 0:e.events)||[],g=i&&u7({drawEntryStatuses:i,tournamentEvents:h}),_=a&&d7({eventEntryStatuses:a,tournamentEvents:h}),I=s!==void 0&&[!0,!1].includes(s)&&h.reduce((y,S)=>y.concat(...(S.drawDefinitions||[]).map(O=>ay({drawDefinition:O}).allPositionedParticipantIds).filter(Boolean)),[]),P=y=>o==null?void 0:o.reduce((S,O)=>{const{accessor:b,value:w}=O,{values:T}=bd({element:y,accessor:b});return S&&(T==null?void 0:T.includes(w))},!0);if(r=r==null?void 0:r.filter(y=>{var S,O;const b=(O=(S=Un({element:y,itemType:xl}))==null?void 0:S.timeItem)==null?void 0:O.itemValue,{participantRoleResponsibilities:w,participantType:T,participantRole:$,participantId:N,person:E}=y,A=Array.isArray(m)&&(m==null?void 0:m.length)&&(E==null?void 0:E.sex)&&m.includes(E.sex);return v?m&&A||s&&I.includes(N)||s===!1&&!I.includes(N)||(g==null?void 0:g.includes(N))||(_==null?void 0:_.includes(N))||(p==null?void 0:p.includes(N))||d&&b===d||u&&T&&_o(u)&&u.includes(T)||l&&$&&_o(l)&&l.includes($)||c&&_o(w)&&_o(c)&&c.find(U=>w==null?void 0:w.includes(U))||(o==null?void 0:o.length)&&_o(o)&&P(y):(!m||A)&&(s===void 0||s&&I.includes(N)||s===!1&&!I.includes(N))&&(!g||g.includes(N))&&(!_||_.includes(N))&&(!p||p.includes(N))&&(!d||b===d)&&(!u||T&&_o(u)&&u.includes(T))&&(!l||$&&_o(l)&&l.includes($))&&(!c||_o(w)&&_o(c)&&c.find(U=>w==null?void 0:w.includes(U)))&&(!(o!=null&&o.length)||_o(o)&&P(y))}),h.length&&f){const y=h.filter(S=>f.includes(S.eventId)).map(S=>{const O=(S.entries||[]).map(w=>w.participantId);if(S.eventType===ri)return O;const b=((e==null?void 0:e.participants)||[]).filter(w=>O.includes(w.participantId)).map(w=>w.individualParticipantIds).flat(1);return O.concat(...b)}).flat(1);r=r==null?void 0:r.filter(S=>y.includes(S.participantId))}return r}function _o(t){return t&&Array.isArray(t)&&t.length}function u7({drawEntryStatuses:t,tournamentEvents:e}){const r=({entryStatus:n})=>Array.isArray(t)?t.includes(n):!0;return We(e.reduce((n,o)=>{var i,s;const{flightProfile:a}=Nt({event:o}),l=((i=a==null?void 0:a.flights)==null?void 0:i.map(({drawEntries:u})=>Array.isArray(u)?u.filter(r).map(ct):[]).flat())||[],c=((s=o.drawDefinitions)==null?void 0:s.map(({entries:u})=>u?u.filter(r).map(ct):[]))||[];return n.concat(...l,...c)},[]))}function d7({eventEntryStatuses:t,tournamentEvents:e}){return We(e.reduce((r,n)=>{const o=(n.entries||[]).filter(({entryStatus:i})=>Array.isArray(t)?t.includes(i):!0).map(ct);return r.concat(...o)},[]))}function cr(t){const{participantFilters:e={},convertExtensions:r,policyDefinitions:n,withScheduleItems:o,scheduleAnalysis:i,withSignInStatus:s,withTeamMatchUps:a,tournamentRecord:l,usePublishState:c,withScaleValues:u,withStatistics:p,withGroupings:d,withOpponents:v,withMatchUps:f,withSeeding:m,withEvents:h,withDraws:g,inContext:_,withISO2:I,withIOC:P}=t;if(!l)return{error:re};if(!l.participants)return{error:ml};const y=l.participants.map($=>de($,r));if(typeof e!="object")return{error:no,participantFilters:e};_&&(y==null||y.forEach($=>{var N;[Ce,tt,Mr].includes($.participantType)&&($.individualParticipants=(N=$.individualParticipantIds)==null?void 0:N.map(E=>{const A=l.participants.find(C=>C.participantId===E),U=de(A,r,!0);if(u){const{ratings:C,rankings:M}=ha({participant:U});U.ratings=C,U.rankings=M}return(P||I)&&Ju({participant:U,withISO2:I,withIOC:P}),U}))}));let S=e?Ad({participants:y,participantFilters:e,tournamentRecord:l}):y,O,b;if(o||s||i||u||p||d||v||f||m||h||g||I||P){const $=c7({tournamentEvents:l.events,allTournamentParticipants:y,tournamentParticipants:S,participantFilters:e,withScheduleItems:o,withSignInStatus:s,tournamentRecord:l,scheduleAnalysis:i,withTeamMatchUps:a,usePublishState:c,withScaleValues:u,withStatistics:p,withGroupings:d,withOpponents:v,withMatchUps:f,withSeeding:m,withEvents:h,withDraws:g,withISO2:I,withIOC:P});O=$==null?void 0:$.participantIdsWithConflicts,b=$==null?void 0:$.eventsPublishStatuses}const T=n==null?void 0:n[Tl];return T!=null&&T.participant&&(S=S.map($=>iu({template:T.participant,source:$}))),{participantIdsWithConflicts:O,tournamentParticipants:S,eventsPublishStatuses:b}}const p7="ADMINISTRATION",f7="CAPTAIN",v7="COACH",ur="COMPETITOR",m7="MEDIA",h7="MEDICAL",Qb="OFFICIAL",Jb="OTHER",Zb={ADMINISTRATION:p7,CAPTAIN:f7,COACH:v7,COMPETITOR:ur,MEDIA:m7,MEDICAL:h7,OFFICIAL:Qb,OTHER:Jb,SECURITY:"SECURITY"};function Xb(t){return dd(t)}function Im({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,scheduledDate:o,matchUpId:i}){return zv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,scheduledDate:o,matchUpId:i})}function Pm({removePriorValues:t,tournamentRecord:e,drawDefinition:r,scheduledTime:n,disableNotice:o,matchUpId:i}){return Gi({removePriorValues:t,tournamentRecord:e,drawDefinition:r,scheduledTime:n,disableNotice:o,matchUpId:i})}function eT({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,startTime:o}){return Kv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,startTime:o})}function tT({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,endTime:o}){return Qv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,endTime:o})}function rT({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,stopTime:o}){return Jv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,stopTime:o})}function nT({tournamentRecord:t,drawDefinition:e,disableNotice:r,resumeTime:n,matchUpId:o}){return Zv({tournamentRecord:t,drawDefinition:e,disableNotice:r,resumeTime:n,matchUpId:o})}function g7({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,courtOrder:o,matchUpId:i}){return Yv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,courtOrder:o,matchUpId:i})}function oT({tournamentRecord:t,drawDefinition:e,disableNotice:r,participantId:n,officialType:o,matchUpId:i}){if(!n)return{error:Et};const{tournamentParticipants:s}=cr({tournamentRecord:t,participantFilters:{participantTypes:[Fe],participantRoles:[Qb]}});return Eo({tournamentParticipants:s,participantId:n})?NS({drawDefinition:e,disableNotice:r,participantId:n,officialType:o,matchUpId:i}):{error:jt}}var _7=Object.defineProperty,I7=Object.defineProperties,P7=Object.getOwnPropertyDescriptors,iT=Object.getOwnPropertySymbols,y7=Object.prototype.hasOwnProperty,S7=Object.prototype.propertyIsEnumerable,sT=(t,e,r)=>e in t?_7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ym=(t,e)=>{for(var r in e||(e={}))y7.call(e,r)&&sT(t,r,e[r]);if(iT)for(var r of iT(e))S7.call(e,r)&&sT(t,r,e[r]);return t},O7=(t,e)=>I7(t,P7(e));function aT({tournamentRecord:t,scheduleChange:e,matchUpIds:r,dryRun:n}){if(!t)return{error:re};if(!r||!Array.isArray(r))return{error:vl};if(typeof e!="object")return{error:X};const o=[],i=[],{minutesChange:s,daysChange:a}=e;if(!s&&!a)return ym({},V);if(s&&isNaN(s))return{error:X};if(a&&isNaN(a))return{error:X};const{matchUps:l}=Wt({matchUpFilters:{matchUpIds:r},tournamentRecord:t}),c=({matchUpStatus:P})=>!Yt.includes(P),u=l==null?void 0:l.filter(P=>yc({schedule:P.schedule})).filter(P=>c({matchUpStatus:P.matchUpStatus}));if(!(u!=null&&u.length))return ym({},V);const{tournamentInfo:p}=Sc({tournamentRecord:t}),{startDate:d,endDate:v}=p,f=u==null?void 0:u.reduce((P,y)=>{const{matchUpId:S,drawId:O}=y;return P[O]?P[O].push(S):P[O]=[S],P},{}),m=1440;for(const P of Object.keys(f)){const y=Jo({tournamentRecord:t,drawId:P});if(y.error)return y;const S=y.drawDefinition,O=f[P].filter(b=>r.includes(b));for(const b of O)if(b&&S){const w=u.find(C=>C.matchUpId===b),T=w==null?void 0:w.schedule,{scheduledTime:$,scheduledDate:N}=T;let E,A,U;if(!E&&a&&N){const C=Re(N);U=GL(C,a),E=new Date(U)<new Date(d)||new Date(U)>new Date(v)}if(s&&$){const C=Re($),D=Le(at($))+s;if(E=D<0||D>m,!E){const R=Or($,s);A=C&&U?`${U}T${R}`:R}}if(E)i.push(b);else{if(!n){if(A){const C=Pm({scheduledTime:A,drawDefinition:S,matchUpId:b});if(C.error)return C}if(U){const C=Im({scheduledDate:U,drawDefinition:S,matchUpId:b});if(C.error)return C}}(A||U)&&o.push(b)}}}const h=Wt({matchUpFilters:{matchUpIds:r},tournamentRecord:t}).matchUps||[],g=h.filter(({matchUpId:P})=>o.includes(P)),_=h.filter(({matchUpId:P})=>i.includes(P)),I=g.length&&!_.length;return O7(ym({},V),{rescheduled:g,notRescheduled:_,allRescheduled:I})}var b7=Object.defineProperty,T7=Object.defineProperties,w7=Object.getOwnPropertyDescriptors,lT=Object.getOwnPropertySymbols,E7=Object.prototype.hasOwnProperty,$7=Object.prototype.propertyIsEnumerable,cT=(t,e,r)=>e in t?b7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,N7=(t,e)=>{for(var r in e||(e={}))E7.call(e,r)&&cT(t,r,e[r]);if(lT)for(var r of lT(e))$7.call(e,r)&&cT(t,r,e[r]);return t},U7=(t,e)=>T7(t,w7(e));function A7({tournamentRecords:t,scheduleChange:e,matchUpIds:r,dryRun:n}){var o,i;if(!r||!Array.isArray(r))return{error:vl};if(typeof e!="object")return{error:X};const s=[];let a=[];for(const c of Object.values(t)){const u=aT({tournamentRecord:c,scheduleChange:e,matchUpIds:r,dryRun:n});if(u.error)return u;Array.isArray(u.notRescheduled)&&a.push(...u.notRescheduled);const p=gv(u.notRescheduled),d=[];(o=u.rescheduled)==null||o.forEach(v=>{const{matchUpId:f}=v;p.includes(f)&&d.push(f),s.push(v)}),d.length&&(a=((i=u==null?void 0:u.notRescheduled)==null?void 0:i.filter(({matchUpId:v})=>!d.includes(v)))||[])}const l=!!(s.length&&!a.length);return U7(N7({},V),{rescheduled:s,notRescheduled:a,allRescheduled:l})}function uT({tournamentRecord:t,dailyLimits:e}){return t?typeof e!="object"?{error:no}:Ei({extension:{name:ss,value:{dailyLimits:e}},tournamentRecord:t}):{error:re}}var C7=Object.defineProperty,dT=Object.getOwnPropertySymbols,M7=Object.prototype.hasOwnProperty,D7=Object.prototype.propertyIsEnumerable,pT=(t,e,r)=>e in t?C7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,j7=(t,e)=>{for(var r in e||(e={}))M7.call(e,r)&&pT(t,r,e[r]);if(dT)for(var r of dT(e))D7.call(e,r)&&pT(t,r,e[r]);return t};function R7({tournamentRecords:t,tournamentId:e,dailyLimits:r}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const n=Object.keys(t).filter(o=>!e||e===o);if(e&&!n.includes(e))return{error:X};for(const o of n){const i=t[o],s=uT({tournamentRecord:i,dailyLimits:r});if(s.error)return s}return j7({},V)}var F7=Object.defineProperty,x7=Object.defineProperties,L7=Object.getOwnPropertyDescriptors,fT=Object.getOwnPropertySymbols,V7=Object.prototype.hasOwnProperty,B7=Object.prototype.propertyIsEnumerable,vT=(t,e,r)=>e in t?F7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,k7=(t,e)=>{for(var r in e||(e={}))V7.call(e,r)&&vT(t,r,e[r]);if(fT)for(var r of fT(e))B7.call(e,r)&&vT(t,r,e[r]);return t},G7=(t,e)=>x7(t,L7(e));function W7({extensionConversions:t,seedAssignments:e,participant:r,withSeeding:n,seedValue:o,eventId:i,ranking:s,entry:a}){const{entryStatus:l,entryStage:c,entryPosition:u,extensions:p}=a,d=p!=null&&p.length?Object.assign({},...Pf(p)):{},v=Object.assign(d,G7(k7({},t),{entryPosition:u,entryStatus:l,entryStage:c,ranking:s,eventId:i}));r.events[i]=Oe(v,!1,!1,!0),n&&(e&&(r.events[i].seedAssignments=e),o&&(r.events[i].seedValue=o))}var H7=Object.defineProperty,q7=Object.defineProperties,z7=Object.getOwnPropertyDescriptors,mT=Object.getOwnPropertySymbols,Y7=Object.prototype.hasOwnProperty,K7=Object.prototype.propertyIsEnumerable,hT=(t,e,r)=>e in t?H7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Q7=(t,e)=>{for(var r in e||(e={}))Y7.call(e,r)&&hT(t,r,e[r]);if(mT)for(var r of mT(e))K7.call(e,r)&&hT(t,r,e[r]);return t},J7=(t,e)=>q7(t,z7(e));function gT(t){const{participantMap:e,participantId:r,matchUpStatus:n,roundPosition:o,structureId:i,matchUpType:s,roundNumber:a,matchUpId:l,potential:c,schedule:u,drawId:p,score:d}=t;if(!u||!Object.keys(u).length)return;n===nt||e[r].scheduleItems.push(J7(Q7({},u),{scheduledDate:Re(u==null?void 0:u.scheduledDate),scheduledTime:at(u==null?void 0:u.scheduledTime),scoreHasValue:Gt({score:d}),matchUpStatus:n,roundPosition:o,structureId:i,matchUpType:s,roundNumber:a,matchUpId:l,potential:c,drawId:p}))}function Z7({finishingPositionRange:t={},participantMap:e,finishingRound:r,participantWon:n,matchUpStatus:o,participantId:i,stageSequence:s,roundNumber:a,structureId:l,matchUpId:c,drawId:u,stage:p}){const d=e[i],v=_=>Math.abs(_[0]-_[1]);d.structureParticipation[l]||(d.structureParticipation[l]={rankingStage:p,walkoverWinCount:0,defaultWinCount:0,stageSequence:s,winCount:0,structureId:l,drawId:u});const f=d.structureParticipation[l],{winner:m,loser:h}=t,g=n?m:h;n&&(f.winCount+=1,o===ot&&(f.walkoverWinCount+=1),o===Xe&&(f.defaultWinCount+=1)),g&&(!f.finishingPositionRange||v(g)<v(f.finishingPositionRange))&&(f.finishingPositionRange=g),r&&((!f.finishingRound||r<f.finishingRound)&&(f.finishingMatchUpId=c,f.finishingRound=r,f.roundNumber=a),r===1&&(f.participantWon=n))}function _T(t){var e,r,n,o,i,s,a,l,c,u;const{withScheduleTimes:p,scheduleAnalysis:d,withTeamMatchUps:v,participantMap:f,withOpponents:m,withMatchUps:h,withEvents:g,withDraws:_,finishingPositionRange:I,finishingRound:P,matchUpStatus:y,stageSequence:S,roundNumber:O,structureId:b,score:w,stage:T,withRankingProfile:$,tieWinningSide:N,roundPosition:E,matchUpTieId:A,matchUpSides:U,collectionId:C,matchUpType:M,winningSide:D,matchUpId:R,schedule:j,eventId:G,drawId:W,sides:q}=t,F=m&&(q==null?void 0:q.length)===2&&Object.assign({},...q.map(({sideNumber:L},x)=>{const B=q[1-x].participantId;return L&&{[L]:B}}).filter(Boolean));for(const L of q){const{participantId:x,sideNumber:B,bye:z}=L;if(z)continue;const H=D===B,Y=J=>{var te,ne;const ee=(te=f[J])==null?void 0:te.participant,oe=ee==null?void 0:ee.participantType,ie=[{participantId:J,participantType:oe}];if(oe!==zn)for(const ae of(ee==null?void 0:ee.individualParticipantIds)||[]){const se=(ne=f[ae])==null?void 0:ne.participant;ie.push({participantType:se==null?void 0:se.participantType,participantId:ae})}return ie},Z=(J,te)=>{if(h){if(f[J].matchUps[R]={participantWon:H,matchUpType:M,structureId:b,sideNumber:B,matchUpId:R,eventId:G,drawId:W},m){const ne=Y(te);f[J].matchUps[R].opponentParticipantInfo=ne}C&&(f[J].matchUps[R].collectionId=C)}$&&Z7({finishingPositionRange:I,participantMap:f,participantWon:H,finishingRound:P,matchUpStatus:y,participantId:J,stageSequence:S,roundNumber:O,structureId:b,matchUpId:R,drawId:W,stage:T}),(d||p)&&gT({participantMap:f,participantId:J,matchUpStatus:y,roundPosition:E,matchUpType:M,roundNumber:O,structureId:b,matchUpId:R,schedule:j,drawId:W,score:w})},K=(J,te)=>{J&&(J.partnerParticipantIds||(J.partnerParticipantIds=[]),J.partnerParticipantIds.includes(te)||J.partnerParticipantIds.push(te))},Q=({participantId:J,partnerParticipantId:te})=>{var ne,ee,oe,ie,ae,se;_&&K((ee=(ne=f[J])==null?void 0:ne.draws)==null?void 0:ee[W],te),g&&K((ie=(oe=f[J])==null?void 0:oe.events)==null?void 0:ie[G],te),h&&K((se=(ae=f[J])==null?void 0:ae.matchUps)==null?void 0:se[R],te)};if(x&&f[x]){const J=F==null?void 0:F[B];Z(x,J),m&&J&&(f[x].opponents[J]={participantId:J,matchUpId:R,eventId:G,drawId:W});const te=((e=f[x])==null?void 0:e.participant.participantType)===Ce,ne=((r=f[x])==null?void 0:r.participant.individualParticipantIds)||[];if(A){if(v){const ee=oe=>f[oe].matchUps[A]={participantWon:N===B,matchUpType:Cr.Team,matchUpId:A,sideNumber:B};ee(x),ne.forEach(ee)}if(_&&!f[x].draws[W]){const ee=(o=(n=U.find(ae=>ae.sideNumber===B))==null?void 0:n.participant)==null?void 0:o.participantId,oe=(a=(s=(i=f[ee])==null?void 0:i.draws)==null?void 0:s[W])==null?void 0:a.entryStatus,ie=ae=>f[ae].draws[W]={entryStatus:oe,eventId:G,drawId:W};ie(x),ne.forEach(ie)}}if(te&&(ne.forEach(ee=>f[ee]&&Z(ee,J)),ne.forEach((ee,oe)=>{const ie=ne[1-oe];Q({participantId:ee,partnerParticipantId:ie})}),g&&U)){const ee=(c=(l=U.find(oe=>oe.sideNumber===B))==null?void 0:l.participant)==null?void 0:c.participantId;if(ee){const oe=(u=f[ee])==null?void 0:u.events[G];oe?(f[x].events[G]=oe,ne.forEach(ie=>f[ie].events[G]=oe)):console.log("Missing teamEntry",{eventId:G,teamParticipantId:ee})}}if(D){const ee=oe=>{H?(f[oe].counters[M].wins+=1,f[oe].counters.wins+=1,y===ot&&(f[oe].counters[M].walkoverWins+=1,f[oe].counters.walkoverWins+=1),y===Xe&&(f[oe].counters[M].defaultWins+=1,f[oe].counters.defaultWins+=1)):(f[oe].counters[M].losses+=1,f[oe].counters.losses+=1,y===ot&&(f[oe].counters[M].walkovers+=1,f[oe].counters.walkovers+=1),y===Xe&&(f[oe].counters[M].defaults+=1,f[oe].counters.defaults+=1))};ee(x),ne.forEach(ee)}}}}var X7=Object.defineProperty,eK=Object.defineProperties,tK=Object.getOwnPropertyDescriptors,IT=Object.getOwnPropertySymbols,rK=Object.prototype.hasOwnProperty,nK=Object.prototype.propertyIsEnumerable,PT=(t,e,r)=>e in t?X7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ha=(t,e)=>{for(var r in e||(e={}))rK.call(e,r)&&PT(t,r,e[r]);if(IT)for(var r of IT(e))nK.call(e,r)&&PT(t,r,e[r]);return t},Cd=(t,e)=>eK(t,tK(e));function oK(t){var e,r,n,o,i;const{participantFilters:s,convertExtensions:a,policyDefinitions:l,tournamentRecord:c,usePublishState:u,contextProfile:p,participantMap:d,withPotentialMatchUps:v,withRankingProfile:f,withScheduleTimes:m,withScheduleItems:h,scheduleAnalysis:g,withTeamMatchUps:_,withStatistics:I,withOpponents:P,withMatchUps:y,withSeeding:S,withEvents:O,withDraws:b}=t;h&&console.log({withScheduleItems:h});const w=s==null?void 0:s.participantIds,T=R=>{var j,G;const W=[R];return W.push(R),(G=(j=d[R])==null?void 0:j.participant.individualParticipantIds)==null||G.forEach(q=>W.push(q)),W.some(q=>!(w!=null&&w.length)||w.includes(q.relevantParticipantId))?W:[]},$={withMatchUps:y||f,withEvents:O||f,withDraws:b||f,withPotentialMatchUps:v,withRankingProfile:f,withScheduleTimes:m,scheduleAnalysis:g,withTeamMatchUps:_,withStatistics:I,participantMap:d,withOpponents:P,withSeeding:S},N=[],E={},A=[],U={},C={},M={},D=({eventType:R,scaleNames:j,participantId:G})=>{var W,q,F,L;return(L=(F=(q=(W=d[G].participant)==null?void 0:W.rankings)==null?void 0:q[R])==null?void 0:F.find(x=>j.includes(x.scaleName)))==null?void 0:L.scaleValue};for(const R of(c==null?void 0:c.events)||[]){if(s!=null&&s.eventIds&&!s.eventIds.includes(R.eventId))continue;const{drawDefinitions:j=[],extensions:G,eventType:W,eventName:q,category:F,entries:L,eventId:x,gender:B}=R,{flightProfile:z}=Nt({event:R}),H=z==null?void 0:z.flights,Y=TY({event:R}),Z=Y==null?void 0:Y.publishedSeeding;if(Y&&(U[x]=Y),O||S||f){const K=a?Object.assign({},...Pf(G)):{};C[x]=Cd(Ha({},K),{eventName:q,eventType:W,category:F,eventId:x,gender:B});const Q=[F==null?void 0:F.categoryName,F==null?void 0:F.ageCategoryCode].filter(Boolean);for(const J of L){const{participantId:te}=J;if(!te||!d[te])continue;const ne=D({eventType:W,scaleNames:Q,participantId:te});let ee,oe;if(S){const se=d[te].participant;({seedAssignments:ee,seedValue:oe}=wY({publishedSeeding:Z,usePublishState:u,withSeeding:S,participant:se,event:R}))}const ie=se=>{var ye;if((ye=d[se])!=null&&ye.events[x])return;const Ie=d[se];W7({extensionConversions:K,seedAssignments:ee,participant:Ie,withSeeding:S,seedValue:oe,eventId:x,ranking:ne,entry:J})};ie(te),(d[te].participant.individualParticipantIds||[]).forEach(ie)}}if(b||f||S){const K=Q=>Q?Object.assign({},...Q.map(J=>({[J.participantId]:J}))):void 0;for(const Q of j){const{structures:J=[],drawOrder:te,drawName:ne,drawType:ee,entries:oe,drawId:ie}=Q,ae=(e=H==null?void 0:H.find($e=>$e.drawId===ie))==null?void 0:e.flightNumber,se=[F==null?void 0:F.categoryName,F==null?void 0:F.ageCategoryCode].filter(Boolean),ye=(Q.structures||[]).sort(($e,De)=>Ri($e,De)).map(({structureId:$e,structures:De})=>[$e,...(De||[]).map(({structureId:me})=>me)]).flat(1/0);let Ie,pe,fe,ve,le=0;const be=J.filter(({stage:$e,stageSequence:De})=>$e===he&&De===1||$e===we).flatMap($e=>{const{seedAssignments:De,stageSequence:me,stage:ge}=$e,{positionAssignments:Se}=st({structure:$e});return ge===he?(le=(Se==null?void 0:Se.length)||0,fe=Se,ve=De):me===1&&(Ie=Se,pe=De),Se}).map(({participantId:$e})=>$e).filter(Boolean),Me=K(ve),Pe=K(pe),xe=oe.filter(({participantId:$e})=>be.includes($e)),Be=(r=U[x])==null?void 0:r.publishedSeeding,qe=!u||(Be==null?void 0:Be.published)&&(((n=Be==null?void 0:Be.drawIds)==null?void 0:n.length)===0||((o=Be==null?void 0:Be.drawIds)==null?void 0:o.includes(ie)));for(const $e of xe){const{entryStatus:De,entryStage:me,entryPosition:ge,participantId:Se}=$e,Ee=D({participantId:Se,scaleNames:se,eventType:W}),Ae=je=>{var gt,rt,yt,St;if(d[je].draws[ie])return;const ze=S&&qe,_t=ze?{}:void 0,Ve=ze?((gt=Me==null?void 0:Me[Se])==null?void 0:gt.seedValue)||((rt=Me==null?void 0:Me[Se])==null?void 0:rt.seedNumber):void 0,It=ze?((yt=Pe==null?void 0:Pe[Se])==null?void 0:yt.seedValue)||((St=Pe==null?void 0:Pe[Se])==null?void 0:St.seedNumber):void 0;_t&&Ve&&(_t[he]=Ve),_t&&It&&(_t[we]=Ve),(O||f)&&(ze?d[je].events[x].seedValue=Ve||It:d[je].events[x].seedValue&&(d[je].events[x].seedValue=void 0)),(b||f)&&(d[je].draws[ie]=Oe({seedAssignments:_t,entryPosition:ge,entryStatus:De,entryStage:me,eventId:x,ranking:Ee,drawId:ie},!1,!1,!0))};if(![En,ys].includes(De)){Ae(Se);const je=d[Se].participant.individualParticipantIds||[];je==null||je.forEach(Ae)}}M[ie]={qualifyingPositionAssignments:Ie,qualifyingSeedAssignments:pe,mainPositionAssignments:fe,qualifyingSeedingMap:Pe,mainSeedAssignments:ve,orderedStructureIds:ye,mainSeedingMap:Me,flightNumber:ae,drawOrder:te,drawName:ne,drawType:ee,drawSize:le,drawId:ie}}}if(f||g||_||I||P||y||b){const K=!!g||v,Q=((i=ai({afterRecoveryTimes:!!g,policyDefinitions:l,tournamentRecord:c,inContext:!0,contextProfile:p,participantMap:d,nextMatchUps:K,event:R}))==null?void 0:i.matchUps)||[];for(const J of Q){const{finishingPositionRange:te,potentialParticipants:ne,tieMatchUps:ee=[],sides:oe=[],winningSide:ie,matchUpType:ae,matchUpId:se,eventId:ye,drawId:Ie,collectionId:pe,stageSequence:fe,finishingRound:ve,matchUpStatus:le,roundPosition:be,roundNumber:Me,structureId:Pe,schedule:xe,score:Be,stage:qe}=J;E[se]=J;const $e={finishingPositionRange:te,finishingRound:ve,stageSequence:fe,roundPosition:be,collectionId:pe,roundNumber:Me,structureId:Pe,schedule:xe,eventId:ye,drawId:Ie,score:Be,stage:qe};_T(Cd(Ha(Ha({},$e),$),{matchUpStatus:le,winningSide:ie,matchUpType:ae,matchUpId:se,sides:oe}));for(const De of ee){const{winningSide:me,sides:ge=[],matchUpId:Se,matchUpStatus:Ee,matchUpType:Ae}=De;_T(Cd(Ha(Ha({},$e),$),{winningSide:me,tieWinningSide:ie,matchUpTieId:se,matchUpId:Se,sides:ge,matchUpSides:oe,matchUpStatus:Ee,matchUpType:Ae}))}if(Array.isArray(ne)&&(K||g||m)){const De=ne.flat().map(Fn("participantId")).filter(Boolean);De==null||De.forEach(me=>{const ge=T(me);ge==null||ge.forEach(Se=>{d[Se]&&(d[Se].potentialMatchUps[se]=Oe({tournamentId:c==null?void 0:c.tournamentId,matchUpId:se,eventId:ye,drawId:Ie}))}),(g||m)&&gT({potential:!0,participantMap:d,participantId:me,matchUpStatus:le,roundPosition:be,structureId:Pe,matchUpType:ae,roundNumber:Me,matchUpId:se,schedule:xe,drawId:Ie,score:Be})})}}A.push(...Q)}}if(I||f||g){const R=Object.values(d);for(const j of R){const{wins:G,losses:W,[At]:{wins:q,losses:F},[dt]:{wins:L,losses:x}}=j.counters,B=(z,H,Y)=>{const Z=H+Y,K=H,Q=Z&&K/Z;j.statistics[z]={denominator:Z,numerator:K,statValue:Q,statCode:z}};if(I&&(B($l,G,W),B(`${$l}.${At}`,q,F),B(`${$l}.${dt}`,L,x)),f){const z=(H=[])=>Math.abs(H[0]-H[1]);for(const H of Object.keys(j.draws)){const{orderedStructureIds:Y=[],flightNumber:Z}=M[H]||{};if(j.structureParticipation&&Y.length){let K,Q=0;const J=Y.map(te=>{const ne=j.structureParticipation[te];if(!ne)return;K||(K=ne.finishingPositionRange),z(K)>z(ne.finishingPositionRange)&&(K=ne.finishingPositionRange);const ee=ne.stage!==we;ee&&(Q+=1);const oe=ee?Q:void 0;return Oe(Cd(Ha({},ne),{participationOrder:oe,flightNumber:Z}))}).filter(Boolean);j.draws[H].finishingPositionRange=K,j.draws[H].structureParticipation=J}}}if(g){const z=rs(g)?g.scheduledMinutesDifference:0,H=j.scheduleItems||[],Y=j.potentialMatchUps||{},Z=H.reduce((Q,J)=>{const{scheduledDate:te,scheduledTime:ne}=J;return Q[te]||(Q[te]=[]),ne&&Q[te].push(J),Q},{});Object.values(Z).forEach(Q=>Q.sort(j_));for(const Q of H){const{typeChangeTimeAfterRecovery:J,timeAfterRecovery:te,scheduledDate:ne,scheduledTime:ee}=Q,oe=Z[ne],ie=Le(ee);for(const ae of oe){if(ae.matchUpId===Q.matchUpId||[ot,Xe].includes(ae.matchUpStatus)&&!ae.scoreHasValue)continue;const Ie=Q.matchUpType!==ae.matchUpType&&J||te,pe=Q.drawId===ae.drawId,fe=Y[Q.matchUpId]&&Y[ae.matchUpId],ve=Le(ae.scheduledTime),le=Math.abs(ve-ie);(z&&!isNaN(z)?le<=z:Le(Ie)>Le(ae.scheduledTime))&&!(fe&&pe)&&j.scheduleConflicts.push({priorScheduledMatchUpId:ae.matchUpId,matchUpIdWithConflict:Q.matchUpId})}}const K=j.participant.participantId;j.scheduleConflicts.length&&N.push(K),d[K].scheduleConflicts=j.scheduleConflicts}}}return{participantIdsWithConflicts:N,eventsPublishStatuses:U,derivedEventInfo:C,derivedDrawInfo:M,mappedMatchUps:E,participantMap:d,matchUps:A}}var iK=Object.defineProperty,sK=Object.defineProperties,aK=Object.getOwnPropertyDescriptors,yT=Object.getOwnPropertySymbols,lK=Object.prototype.hasOwnProperty,cK=Object.prototype.propertyIsEnumerable,ST=(t,e,r)=>e in t?iK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,OT=(t,e)=>{for(var r in e||(e={}))lK.call(e,r)&&ST(t,r,e[r]);if(yT)for(var r of yT(e))cK.call(e,r)&&ST(t,r,e[r]);return t},bT=(t,e)=>sK(t,aK(e));function Ls(t){const{withIndividualParticipants:e,participantFilters:r={},withPotentialMatchUps:n,withRankingProfile:o,convertExtensions:i,policyDefinitions:s,withScheduleItems:a,tournamentRecord:l,scheduleAnalysis:c,withSignInStatus:u,withTeamMatchUps:p,withScaleValues:d,usePublishState:v,contextProfile:f,withStatistics:m,withOpponents:h,withMatchUps:g,internalUse:_,withSeeding:I,withEvents:P,withDraws:y,withISO2:S,withIOC:O}=t;if(!l)return{error:re};(g||o)&&cn({tournamentRecord:l});let{participantMap:b}=k0({withIndividualParticipants:e,convertExtensions:i,policyDefinitions:s,tournamentRecord:l,withSignInStatus:u,withScaleValues:d,internalUse:_,withISO2:S,withIOC:O});const w=oK({withMatchUps:g||o,withEvents:P||o,withDraws:y||o,withPotentialMatchUps:n,participantFilters:r,withRankingProfile:o,convertExtensions:i,withScheduleItems:a,policyDefinitions:s,tournamentRecord:l,scheduleAnalysis:c,withTeamMatchUps:p,usePublishState:v,withStatistics:m,participantMap:b,withOpponents:h,contextProfile:f,withSeeding:I}),{participantIdsWithConflicts:T,eventsPublishStatuses:$,derivedEventInfo:N,derivedDrawInfo:E,mappedMatchUps:A}=w,U=w.matchUps;b=w.participantMap;const C=c||n,M=Object.values(b).map(({potentialMatchUps:R,scheduleConflicts:j,participant:G,statistics:W,opponents:q,matchUps:F,events:L,draws:x})=>{const B=Object.values(x),z=Object.values(q);return h&&(B==null||B.forEach(H=>{H.opponents=z.filter(Y=>Y.drawId===H.drawId)})),Oe(bT(OT({},G),{scheduleConflicts:c?j:void 0,draws:y||o?B:void 0,events:P||o?Object.values(L):void 0,matchUps:g||o?Object.values(F):void 0,opponents:h?z:void 0,potentialMatchUps:C?Object.values(R):void 0,statistics:m?Object.values(W):void 0}),!1,!1,!0)}),D=Ad({participants:M,participantFilters:r,tournamentRecord:l});return bT(OT({participantIdsWithConflicts:T,eventsPublishStatuses:$,derivedEventInfo:N,derivedDrawInfo:E,mappedMatchUps:A,participantMap:b,participants:D},V),{matchUps:U})}function Sm(t,e,r){return!t&&e?e:t&&!e||typeof t!="object"||typeof e!="object"?t:We(Object.keys(t).concat(Object.keys(e))).reduce((o,i)=>{if(!e[i])o[i]=t[i];else if(!t[i])o[i]=e[i];else if(typeof t[i]!=typeof e[i])o[i]=e[i];else if(Array.isArray(t[i]))if(r===!0||Array.isArray(r)&&r.includes(i)){const s=We(t[i].map(a=>JSON.stringify(a)).concat(e[i].map(a=>JSON.stringify(a)))).map(a=>JSON.parse(a));o[i]=s}else o[i]=e[i];else typeof t[i]=="object"?o[i]=Sm(t[i],e[i],r):o[i]=e[i];return o},{})}var uK=Object.defineProperty,dK=Object.defineProperties,pK=Object.getOwnPropertyDescriptors,TT=Object.getOwnPropertySymbols,fK=Object.prototype.hasOwnProperty,vK=Object.prototype.propertyIsEnumerable,wT=(t,e,r)=>e in t?uK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Oc=(t,e)=>{for(var r in e||(e={}))fK.call(e,r)&&wT(t,r,e[r]);if(TT)for(var r of TT(e))vK.call(e,r)&&wT(t,r,e[r]);return t},mK=(t,e)=>dK(t,pK(e));function hK(t){const{tournamentRecords:e}=t||{};if(typeof e!="object"||!Object.keys(e).length)return{error:ke};const r={},n=[],o={},i={},s=[],a={},l=[];for(const c of Object.values(e)){const{participantIdsWithConflicts:u,mappedMatchUps:p,participantMap:d,participants:v,matchUps:f,derivedEventInfo:m,derivedDrawInfo:h}=Ls(Oc({tournamentRecord:c},t));Object.assign(a,p),Object.assign(r,d),Object.assign(o,m),Object.assign(i,h),n.push(...v??[]),s.push(...f??[]),u==null||u.forEach(g=>{l.includes(g)||l.push(g)})}return mK(Oc({participantIdsWithConflicts:l,derivedEventInfo:o,derivedDrawInfo:i,participantMap:r,mappedMatchUps:a,participants:n},V),{matchUps:s})}function gK(t){const{tournamentRecords:e}=t||{};if(typeof e!="object"||!Object.keys(e).length)return{error:ke};let r=[];const n=[],o=[];for(const i of Object.values(e)){const{tournamentParticipants:s,participantIdsWithConflicts:a}=cr(Oc({tournamentRecord:i},t));for(const l of s){const{participantId:c}=l;o.includes(c)?r=r.map(u=>u.participantId!==c?u:Sm(u,l,!0)):(o.push(c),r.push(l))}a==null||a.forEach(l=>{n.includes(l)||n.push(l)})}return Oc({competitionParticipants:r,participantIdsWithConflicts:n},V)}function ET({policyDefinitions:t,tournamentRecords:e,participantId:r,inContext:n,personId:o}){if(!e)return{error:ke};if(typeof r!="string"&&typeof o!="string")return{error:_e,stack:"publicFindParticipant"};let i,s;for(const a of Object.values(e)){s=a.tournamentId;const{tournamentParticipants:l}=cr({policyDefinitions:t,tournamentRecord:a,inContext:n});if(i=Eo({tournamentParticipants:l,internalUse:!0,policyDefinitions:t,participantId:r,personId:o}),i)break}return Oc({participant:i,tournamentId:s},V)}const $T=({penaltyId:t=Ye()}={})=>({refereeParticipantId:void 0,penaltyCode:void 0,penaltyType:void 0,extensions:void 0,matchUpId:void 0,createdAt:void 0,issuedAt:void 0,notes:void 0,penaltyId:t});var _K=Object.defineProperty,IK=Object.defineProperties,PK=Object.getOwnPropertyDescriptors,NT=Object.getOwnPropertySymbols,yK=Object.prototype.hasOwnProperty,SK=Object.prototype.propertyIsEnumerable,UT=(t,e,r)=>e in t?_K(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Md=(t,e)=>{for(var r in e||(e={}))yK.call(e,r)&&UT(t,r,e[r]);if(NT)for(var r of NT(e))SK.call(e,r)&&UT(t,r,e[r]);return t},Dd=(t,e)=>IK(t,PK(e));function AT({refereeParticipantId:t,tournamentRecord:e,participantIds:r,penaltyCode:n,penaltyType:o,extensions:i,penaltyId:s,matchUpId:a,issuedAt:l,notes:c}){if(!e)return{error:re};if(!r)return{error:Et};if(!o)return{error:Fx};const p=((e==null?void 0:e.participants)||[]).filter(f=>r.includes(f.participantId));if(!p.length)return{error:jt};const d=new Date().toISOString(),v=Object.assign($T({penaltyId:s}),{refereeParticipantId:t,penaltyCode:n,penaltyType:o,matchUpId:a,notes:c,issuedAt:l,createdAt:d});return Array.isArray(i)&&i.forEach(f=>it({element:v,extension:f})),p.forEach(f=>{f.penalties||(f.penalties=[]),f.penalties.push(v)}),He({topic:rr,payload:{tournamentId:e.tournamentId,participants:p}}),Dd(Md({},V),{penaltyId:v.penaltyId})}function CT({tournamentRecord:t,penaltyId:e}){if(!t)return{error:re};if(!e)return{error:f_};const r=(t==null?void 0:t.participants)||[],n=[];let o=!1,i;return r.forEach(s=>{let a=!1;s.penalties=(s.penalties||[]).filter(l=>(l.penaltyId===e&&(a=!0,o||(i=l,o=!0)),a&&n.push(s),l.penaltyId!==e))}),i&&He({topic:rr,payload:{tournamentId:t.tournamentId,participants:n}}),i?Dd(Md({},V),{penalty:i}):{error:tu}}function MT({tournamentRecord:t}){if(!t)return{error:re};const r=((t==null?void 0:t.participants)||[]).reduce((n,o)=>{const{participantId:i}=o;return(o.penalties||[]).forEach(s=>{const{penaltyId:a}=s||{};n[a]?n[a].participants.push(i):n[a]=Dd(Md({},s),{participantIds:[i]})}),n},{});return{penalties:Object.values(r)}}function DT({tournamentRecord:t,modifications:e,penaltyId:r}){if(!t)return{error:re};if(!e)return{error:X,modifications:e};if(!r)return{error:f_};const n=(t==null?void 0:t.participants)||[],o=Object.keys($T()).filter(l=>l!=="penaltyId"),i=Object.keys(e).filter(l=>o.includes(l));if(!i.length)return{error:ff};let s;const a=[];return n.forEach(l=>{let c=!1;l.penalties=(l.penalties||[]).map(u=>(u.penaltyId===r&&(c=!0,i.forEach(p=>Object.assign(u,{[p]:e[p]})),s||(s=u)),u)),c&&a.push(l)}),s&&He({topic:rr,payload:{tournamentId:t.tournamentId,participants:a}}),s?Dd(Md({},V),{penalty:s}):{error:tu}}var OK=Object.defineProperty,bK=Object.defineProperties,TK=Object.getOwnPropertyDescriptors,jT=Object.getOwnPropertySymbols,wK=Object.prototype.hasOwnProperty,EK=Object.prototype.propertyIsEnumerable,RT=(t,e,r)=>e in t?OK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qa=(t,e)=>{for(var r in e||(e={}))wK.call(e,r)&&RT(t,r,e[r]);if(jT)for(var r of jT(e))EK.call(e,r)&&RT(t,r,e[r]);return t},FT=(t,e)=>bK(t,TK(e));function $K(t){const{tournamentRecords:e,participantIds:r}=t;let n;for(const o of Object.values(e)){const{tournamentParticipants:i}=cr({tournamentRecord:o}),s=oc(i).filter(a=>r.includes(a));s.length&&(n=AT(FT(qa({},t),{penaltyId:t.penaltyId||n,tournamentRecord:o,participantIds:s})).penaltyId)}return n?FT(qa({},V),{penaltyId:n}):{error:jt}}function NK(t){const{tournamentRecords:e}=t;if(typeof e!="object"||!Object.keys(e).length)return{error:ke};for(const r of Object.values(e)){const n=DT(qa({tournamentRecord:r},t));if(n.error&&n.error!==tu)return n}return qa({},V)}function UK(t){const{tournamentRecords:e}=t;if(typeof e!="object"||!Object.keys(e).length)return{error:ke};for(const r of Object.values(e)){const n=CT(qa({tournamentRecord:r},t));if(n.error&&n.error!==tu)return n}return qa({},V)}function AK({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const e=[];for(const r of Object.values(t)){const{penalties:n}=MT({tournamentRecord:r});e.push(...n||[])}return{penalties:e}}const CK={addExtension:Wf,findExtension:bu,removeExtension:Tu,addEventExtension:YB,linkTournaments:ZB,unlinkTournament:ek,unlinkTournaments:XB,getLinkedTournamentIds:Hf,addDrawDefinition:gY,getCompetitionParticipants:gK,getParticipants:hK,addParticipant:bY,courtGridRows:Pb,setMatchUpStatus:uY,bulkMatchUpStatusUpdate:dY,bulkScheduleMatchUps:LS,addPenalty:$K,removePenalty:UK,modifyPenalty:NK,getCompetitionPenalties:AK,findParticipant:ET};var MK=Object.defineProperty,xT=Object.getOwnPropertySymbols,DK=Object.prototype.hasOwnProperty,jK=Object.prototype.propertyIsEnumerable,LT=(t,e,r)=>e in t?MK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,VT=(t,e)=>{for(var r in e||(e={}))DK.call(e,r)&&LT(t,r,e[r]);if(xT)for(var r of xT(e))jK.call(e,r)&&LT(t,r,e[r]);return t};function BT({removePriorValues:t=!0,tournamentRecord:e,status:r=qn}){if(!e)return{error:re};const n=`${Hr}.${qr}`,{timeItem:o}=Zu({tournamentRecord:e,itemType:n}),i=(o==null?void 0:o.itemValue)||{[r]:{}};return i[r]&&delete i[r].orderOfPlay,Fo({timeItem:{itemValue:i,itemType:n},removePriorValues:t,tournamentRecord:e}),He({topic:mP,payload:{tournamentId:e.tournamentId}}),VT({},V)}function kT({scheduledDates:t=[],removePriorValues:e,tournamentRecord:r,status:n=qn,eventIds:o=[]}){if(!r)return{error:re};const i=`${Hr}.${qr}`,{timeItem:s}=Zu({tournamentRecord:r,itemType:i}),a=(s==null?void 0:s.itemValue)||{[n]:{}};return a[n].orderOfPlay={published:!0,scheduledDates:t,eventIds:o},Fo({timeItem:{itemValue:a,itemType:i},removePriorValues:e,tournamentRecord:r}),He({topic:fk,payload:{tournamentId:r.tournamentId,scheduledDates:t,eventIds:o}}),VT({},V)}var RK=Object.defineProperty,GT=Object.getOwnPropertySymbols,FK=Object.prototype.hasOwnProperty,xK=Object.prototype.propertyIsEnumerable,WT=(t,e,r)=>e in t?RK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jd=(t,e)=>{for(var r in e||(e={}))FK.call(e,r)&&WT(t,r,e[r]);if(GT)for(var r of GT(e))xK.call(e,r)&&WT(t,r,e[r]);return t};function LK(t){const e=t==null?void 0:t.tournamentRecords;if(!e)return{error:ke};for(const r of Object.values(e)){const n=BT(jd({tournamentRecord:r},t));if(n.error)return n}return jd({},V)}function VK(t){const e=t==null?void 0:t.tournamentRecords;if(!e)return{error:ke};for(const r of Object.values(e)){const n=kT(jd({tournamentRecord:r},t));if(n.error)return n}return jd({},V)}const BK={unPublishOrderOfPlay:LK,publishOrderOfPlay:VK};function HT({tournamentRecords:t,extensionName:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const r=[];let n;for(const o of Object.values(t)){const{extension:i}=Fr({name:e,tournamentRecord:o});i&&!n&&(r.push({method:"addExtension",params:{extension:i}}),n=!0);const s=o.events||[];for(const a of s){const{eventId:l}=a,{extension:c}=$o({name:e,event:a});c&&r.push({params:{eventId:l,extension:c},method:"addEventExtension"})}}return{methods:r}}function kK({tournamentRecords:t}){return HT({extensionName:Wn,tournamentRecords:t})}var GK=Object.defineProperty,WK=Object.defineProperties,HK=Object.getOwnPropertyDescriptors,qT=Object.getOwnPropertySymbols,qK=Object.prototype.hasOwnProperty,zK=Object.prototype.propertyIsEnumerable,zT=(t,e,r)=>e in t?GK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,YK=(t,e)=>{for(var r in e||(e={}))qK.call(e,r)&&zT(t,r,e[r]);if(qT)for(var r of qT(e))zK.call(e,r)&&zT(t,r,e[r]);return t},KK=(t,e)=>WK(t,HK(e));function YT({tournamentRecord:t,matchUpFormats:e,categoryType:r,event:n}){if(!t)return{error:re};if(!n)return{error:Ge};let o=[];if(e!=null&&e.length){const u=[];o=e.map(p=>{const d=typeof p=="string"?{matchUpFormat:p}:p;if(!u.includes(d==null?void 0:d.matchUpFormat)&&Xr(d==null?void 0:d.matchUpFormat))return u.push(d.matchUpFormat),d}).filter(Boolean)}else{const{policy:u}=cs({policyType:da,tournamentRecord:t,event:n});if(u!=null&&u.matchUpFormats)o=u==null?void 0:u.matchUpFormats;else{const{extension:p}=$o({name:Wn,event:n});if(p!=null&&p.value)o=We([...(p.value.matchUpAverageTimes||[]).map(d=>d.matchUpFormatCodes),...(p.value.matchUpRecoveryTimes||[]).map(d=>d.matchUpFormatCodes)].flat()).map(d=>({matchUpFormat:d}));else return{error:_x}}}const{eventType:i,eventId:s,category:a}=n,l=(a==null?void 0:a.categoryName)||(a==null?void 0:a.ageCategoryCode)||s;return s?{eventMatchUpFormatTiming:o.map(({matchUpFormat:u,description:p})=>{const d=Lf({tournamentRecord:t,matchUpFormat:u,categoryName:l,categoryType:r,eventType:i,event:n});return Object.assign({},KK(YK({},d),{description:p,matchUpFormat:u}))})}:{error:Ge}}function QK({tournamentRecords:t,matchUpFormats:e,categoryType:r,tournamentId:n,eventId:o}){if(!o)return{error:Ge};const i=Object.keys(t).filter(c=>!n||c===n);if(n&&!i.length)return{error:X};let s,a,l;return i.forEach(c=>{const u=t[c],{event:p}=Qt({tournamentRecord:u,eventId:o});if(!p)return!1;l=!0;const{eventMatchUpFormatTiming:d,error:v}=YT({tournamentRecord:u,matchUpFormats:e,categoryType:r,event:p});v&&(a=v),s=d}),!l&&{error:Ar}||a&&{error:a}||{eventMatchUpFormatTiming:s}}function Rd({tournamentRecords:t,schedulingProfile:e}){if(!e)return{valid:!0};if(!Array.isArray(e))return{valid:!1,error:X};const{venueIds:r,tournamentsMap:n}=JK({tournamentRecords:t});let o,i;const s=e.every(a=>{const{scheduleDate:l,venues:c}=a;return Gr(l)?c.every(u=>{const{venueId:p,rounds:d}=u;return typeof p!="string"?(i="venueId should be a string",!1):Array.isArray(d)?r.includes(p)?!!d.every(f=>{var m,h,g;if(!f)return i="empty round",!1;const{roundSegment:_,tournamentId:I,structureId:P,roundNumber:y,eventId:S,drawId:O}=f,b=(g=(h=(m=n==null?void 0:n[I])==null?void 0:m[S])==null?void 0:h[O])==null?void 0:g[P],w=b==null?void 0:b.includes(y);w||(i="Invalid rounds");const{segmentNumber:T,segmentsCount:$}=_||{},N=!_||ht(T)&&Zr($)&&T<=$;return N||(i="Invalid segment"),w&&N}):(o=Ii,!1):(i="rounds should be an array",!1)}):!1});return!s&&!o&&(o=X),{valid:!!s,error:o,info:i}}function KT(t){const{tournamentRecord:e={},tournamentMap:r={},requireCourts:n}=t,o=[],i=[],s=[],a=[],l=((e==null?void 0:e.venues)||[]).map(({venueId:u,courts:p})=>(!n||(p==null?void 0:p.length))&&u),c=e==null?void 0:e.tournamentId;return c&&(o.push(c),r[c]={},((e==null?void 0:e.events)||[]).forEach(p=>{const d=p.eventId;s.push(d),r[c][d]={},(p.drawDefinitions||[]).forEach(v=>{const f=v.drawId;a.push(f),r[c][d][f]={};const{structures:m}=an({drawDefinition:v});(m||[]).forEach(h=>{var g;const _=h.structureId,{matchUps:I}=Je({structure:h}),{roundMatchUps:P}=Tr({matchUps:I}),y=P&&Object.keys(P).map(S=>parseInt(S));r[c][d][f][_]=y,i.push(_),(g=h.structures)!=null&&g.length&&h.structures.forEach(S=>{i.push(S.structureId),r[c][d][f][S.structureId]=y})})})})),{tournamentMap:r,tournamentIds:o,structureIds:i,venueIds:l,eventIds:s,drawIds:a}}function JK(t){const e=(t==null?void 0:t.tournamentRecords)&&Object.values(t==null?void 0:t.tournamentRecords)||[],r={},{venueIds:n,eventIds:o,drawIds:i,structureIds:s,tournamentIds:a}=e.reduce((l,c)=>{const{tournamentIds:u,tournamentMap:p,structureIds:d,venueIds:v,eventIds:f,drawIds:m}=KT({tournamentRecord:c});return v.forEach(h=>{l.venueIds.includes(h)||l.venueIds.push(h)}),l.tournamentIds.push(...u),l.structureIds.push(...d),l.eventIds.push(...f),l.drawIds.push(...m),Object.assign(r,p),l},{tournamentIds:[],structureIds:[],venueIds:[],eventIds:[],drawIds:[]});return{tournamentsMap:r,tournamentIds:a,structureIds:s,venueIds:n,eventIds:o,drawIds:i}}var ZK=Object.defineProperty,QT=Object.getOwnPropertySymbols,XK=Object.prototype.hasOwnProperty,e8=Object.prototype.propertyIsEnumerable,JT=(t,e,r)=>e in t?ZK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,t8=(t,e)=>{for(var r in e||(e={}))XK.call(e,r)&&JT(t,r,e[r]);if(QT)for(var r of QT(e))e8.call(e,r)&&JT(t,r,e[r]);return t};function r8({tournamentRecords:t,matchUpFormat:e,recoveryTimes:r,averageTimes:n,tournamentId:o,eventId:i}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const s=Object.keys(t).filter(l=>!o||o===l);if(o&&!s.includes(o))return{error:X};let a;for(const l of s){const c=t[l],{event:u}=Qt({tournamentRecord:c,eventId:i});i&&u&&(a=!0);const p=hm({tournamentRecord:c,event:u,matchUpFormat:e,averageTimes:n,recoveryTimes:r});if(p.error)return p}return!i||a?t8({},V):{error:Ar}}function Om({defaultRecoveryMinutes:t=0,defaultAverageMinutes:e,tournamentRecords:r,matchUpFormat:n,categoryName:o,categoryType:i,tournamentId:s,eventType:a,eventId:l}){if(!Xr(n))return{error:Jc};const c=Object.keys(r).filter(p=>!s||p===s);let u;return c.forEach(p=>{var d;if(u)return;const v=r[p],f=l?(d=Qt({tournamentRecord:v,eventId:l}))==null?void 0:d.event:void 0;return u=Lf({tournamentRecord:v,matchUpFormat:n,categoryName:o,categoryType:i,eventType:a,event:f}),(u==null?void 0:u.averageMinutes)||(u==null?void 0:u.recoveryMinutes)}),{recoveryMinutes:(u==null?void 0:u.recoveryMinutes)||t,averageMinutes:(u==null?void 0:u.averageMinutes)||e,typeChangeRecoveryMinutes:(u==null?void 0:u.typeChangeRecoveryMinutes)||(u==null?void 0:u.recoveryMinutes)||t}}var n8=Object.defineProperty,ZT=Object.getOwnPropertySymbols,o8=Object.prototype.hasOwnProperty,i8=Object.prototype.propertyIsEnumerable,XT=(t,e,r)=>e in t?n8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s8=(t,e)=>{for(var r in e||(e={}))o8.call(e,r)&&XT(t,r,e[r]);if(ZT)for(var r of ZT(e))i8.call(e,r)&&XT(t,r,e[r]);return t};function bm({scheduleCompletedMatchUps:t,containedStructureIds:e,tournamentRecords:r,periodLength:n=30,matchUps:o,rounds:i}){if(typeof r!="object")return{error:ke};if(!Array.isArray(i))return{error:_e,info:or("rounds")};const s={},a=[];i.sort((v,f)=>{var m,h;return((m=v.sortOrder)!=null?m:0)-((h=f.sortOrder)!=null?h:0)}),e=e??Object.assign({},...Object.values(r).map(v=>Ra({tournamentRecord:v}).containedStructures)),o||({matchUps:o}=Ro({nextMatchUps:!0,tournamentRecords:r}));let l=0;const c={},u={},p={},d=i.flatMap(v=>{var f;const m=v.periodLength||n,h=[];e!=null&&e[v.structureId]?h.push(...e[v.structureId]):h.push(v.structureId);let g=o?bs({tournamentIds:[v.tournamentId],roundNumbers:[v.roundNumber],matchUpIds:v.matchUpIds,eventIds:[v.eventId],drawIds:[v.drawId],processContext:!0,structureIds:h,matchUps:o}).sort(Cs):[];const{segmentNumber:_,segmentsCount:I}=v.roundSegment||{};if(ht(_)&&Zr(g==null?void 0:g.length)&&Zr(I)&&_>0&&_<=I&&I<(g==null?void 0:g.length)&&!((f=v.matchUpIds)!=null&&f.length)){const O=g.length/I,b=O*(_-1);g=g.slice(b,b+O)}const P=r[v.tournamentId],y=Qt({drawId:v.drawId,tournamentRecord:P}).event,S=[];for(const O of g){const b=O.matchUpFormat;b&&(s[b]||(s[b]=[],s[b].push(O)),S.push(b))}for(const O of S){const{eventType:b,category:w}=y??{},{categoryName:T,ageCategoryCode:$}=w??{},{typeChangeRecoveryMinutes:N,recoveryMinutes:E,averageMinutes:A,error:U}=Om({categoryName:T??$,categoryType:w==null?void 0:w.categoryType,tournamentId:v.tournamentId,eventId:v.eventId,tournamentRecords:r,matchUpFormat:O,eventType:b});if(U)return{error:U,round:v};const C=g.filter(D=>(t||!Yt.includes(D.matchUpStatus))&&D.matchUpStatus!==nt).map(Jt);C.forEach(D=>{p[D]={typeChangeRecoveryMinutes:N,recoveryMinutes:E,averageMinutes:A},c[D]=E,u[D]=A}),a.push(...C),l=Math.max(A||0,l);const M=`${A}|${m}`;return{roundPeriodLength:m,recoveryMinutes:E,averageMinutes:A,matchUpIds:C,hash:M}}});return s8({scheduledRoundsDetails:d,greatestAverageMinutes:l,matchUpFormatCohorts:s,recoveryMinutesMap:c,averageMinutesMap:u,orderedMatchUpIds:a,minutesMap:p},V)}function ew({tournamentRecords:t}){const r=Object.keys(t).reduce((i,s)=>{const a=t[s],{tournamentInfo:{startDate:l,endDate:c}}=Sc({tournamentRecord:a}),u=l&&new Date(Re(l));(!i.startDate||u&&u<i.startDate)&&(i.startDate=u);const p=c&&new Date(Re(c));return(!i.endDate||p&&p>i.endDate)&&(i.endDate=p),i},{startDate:void 0,endDate:void 0}),n=r.startDate&&Re(r.startDate.toISOString()),o=r.endDate&&Re(r.endDate.toISOString());return!n||!o?{error:n_}:{startDate:n,endDate:o}}var a8=Object.defineProperty,l8=Object.defineProperties,c8=Object.getOwnPropertyDescriptors,tw=Object.getOwnPropertySymbols,u8=Object.prototype.hasOwnProperty,d8=Object.prototype.propertyIsEnumerable,rw=(t,e,r)=>e in t?a8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tm=(t,e)=>{for(var r in e||(e={}))u8.call(e,r)&&rw(t,r,e[r]);if(tw)for(var r of tw(e))d8.call(e,r)&&rw(t,r,e[r]);return t},p8=(t,e)=>l8(t,c8(e));function za({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const{extension:e}=bu({name:Yo,tournamentRecords:t});let r=(e==null?void 0:e.value)||[];if(r.length){const{venueIds:n}=Hv({requireCourts:!0,tournamentRecords:t}),{eventIds:o,drawIds:i}=pd({tournamentRecords:t}),{updatedSchedulingProfile:s,modifications:a,issues:l}=Fd({schedulingProfile:r,venueIds:n,eventIds:o,drawIds:i});if(a){r=s;const c=bc({tournamentRecords:t,schedulingProfile:r});return c.error?c:{schedulingProfile:r,modifications:a,issues:l}}}return{schedulingProfile:r,modifications:0}}function bc({tournamentRecords:t,schedulingProfile:e}){const r=Rd({tournamentRecords:t,schedulingProfile:e});return r.error?r:e?Wf({tournamentRecords:t,extension:{name:Yo,value:e}}):Tu({tournamentRecords:t,name:Yo})}function nw({tournamentRecords:t,scheduleDate:e,venueId:r,round:n}){if(!Gr(e))return{error:Sr};const o="addSchedulingProfileRound",{extension:i}=bu({tournamentRecords:t,name:Yo}),s=(i==null?void 0:i.value)||[];let a=s.find(v=>io(e,v.scheduleDate));if(!a){const{startDate:v,endDate:f}=ew({tournamentRecords:t}),m=new Date(e);if(v&&m<new Date(v)||f&&m>new Date(f))return{error:Sr};a={scheduleDate:e,venues:[]},s.push(a)}let l=a.venues.find(v=>v.venueId===r);l||(l={venueId:r,rounds:[]},a.venues.push(l));const c=["notBeforeTime"],u=v=>Object.keys(v).filter(f=>!c.includes(f)).sort().map(f=>rs(v[f])?u(v[f]):v[f]).flat().join("|");if(l.rounds.find(v=>u(v)===u(n)))return k({result:{error:sx},stack:o});l.rounds.push(n);const d=bc({tournamentRecords:t,schedulingProfile:s});return d.error?d:Tm({},V)}function Fd({schedulingProfile:t,venueIds:e,eventIds:r,drawIds:n}){const o=[],i=t==null?void 0:t.map(a=>{const l=Re(a==null?void 0:a.scheduleDate);if(!l){o.push(`Invalid date: ${a==null?void 0:a.scheduledDate}`);return}const c=((a==null?void 0:a.venues)||[]).map(u=>{const{rounds:p,venueId:d}=u;if(!e.includes(d)){o.push(`Missing venueId: ${d}`);return}const f=p.filter(m=>{const h=r.includes(m.eventId)&&n.includes(m.drawId);return h||o.push(`Invalid eventId: ${m.eventId} or drawId: ${m.drawId}`),h});if(f.length)return{venueId:d,rounds:f}}).filter(Boolean);return c.length&&l&&p8(Tm({},a),{venues:c})}).filter(Boolean),s=o.length;return{updatedSchedulingProfile:i,modifications:s,issues:o}}function ow({tournamentRecords:t}){const{schedulingProfile:e}=za({tournamentRecords:t});if(e){const{venueIds:r}=Hv({tournamentRecords:t}),{eventIds:n,drawIds:o}=pd({tournamentRecords:t}),{updatedSchedulingProfile:i,modifications:s}=Fd({schedulingProfile:e,venueIds:r,eventIds:n,drawIds:o});if(s)return bc({tournamentRecords:t,schedulingProfile:i})}return Tm({},V)}function xd({matchUps:t=[],schedulingProfile:e}){const r={},n=({eventId:a,drawId:l,structureId:c,roundNumber:u})=>`${a}|${l}|${c}${u}`;e!=null&&e.length&&e.map(({venues:l})=>l.map(({rounds:c})=>c)).flat().forEach(l=>{l.sort((u,p)=>(u.sortOrder||0)-(p.sortOrder||0)).forEach(({eventId:u,drawId:p,structureId:d,roundNumber:v},f)=>{const m=n({eventId:u,drawId:p,structureId:d,roundNumber:v});r[m]=f})});const o=[],i={noScheduledDate:[]};for(const a of t){const l=a.schedule||{},c=l.scheduledDate&&Re(l.scheduledDate)||l.scheduledTime&&Re(l.scheduledTime)||"noScheduledDate";i[c]||(i[c]=[]),i[c].push(a)}const s=Object.keys(i).sort();for(const a of s){const l=i[a],c={noScheduledTime:[]};for(const p of l){const d=p.schedule||{},v=d.scheduledTime&&at(d.scheduledTime)||"noScheduledTime";c[v]||(c[v]=[]),c[v].push(p)}const u=Object.keys(c).sort();for(const p of u){const d=c[p];d.sort((v,f)=>{const m=r[n(v)]||0,h=r[n(f)]||0;return m-h}),o.push(...d)}}return o}var f8=Object.defineProperty,v8=Object.defineProperties,m8=Object.getOwnPropertyDescriptors,iw=Object.getOwnPropertySymbols,h8=Object.prototype.hasOwnProperty,g8=Object.prototype.propertyIsEnumerable,sw=(t,e,r)=>e in t?f8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ld=(t,e)=>{for(var r in e||(e={}))h8.call(e,r)&&sw(t,r,e[r]);if(iw)for(var r of iw(e))g8.call(e,r)&&sw(t,r,e[r]);return t},wm=(t,e)=>v8(t,m8(e));function Em(t){var e,r,n,o,i,s,a;if(typeof(t==null?void 0:t.tournamentRecords)!="object"||!Object.keys(t==null?void 0:t.tournamentRecords).length)return{error:ke};const{courts:l,venues:c}=Ms(t),p=za(t).schedulingProfile,{sortDateMatchUps:d=!0,courtCompletedMatchUps:v,alwaysReturnCompleted:f,activeTournamentId:m,tournamentRecords:h,withCourtGridRows:g,minCourtGridRows:_,usePublishState:I,status:P=qn,sortCourtsData:y}=t,S=I?Zu({tournamentRecord:h[m??fn()],itemType:`${Hr}.${qr}`}).timeItem:void 0,O=(e=S==null?void 0:S.itemValue)==null?void 0:e[P],b=f?xv(wm(Ld({},t),{matchUpFilters:wm(Ld({},t.matchUpFilters),{matchUpStatuses:[ut.Completed]}),contextFilters:t.contextFilters})).completedMatchUps:[];if(I&&(!O||!Object.keys(O).length))return{completedMatchUps:b,dateMatchUps:[],courtsData:[],venues:c};const w=I?_8({tournamentRecords:h}).drawIds:void 0;w!=null&&w.length&&(t.contextFilters||(t.contextFilters={}),(r=t.contextFilters)!=null&&r.drawIds?t.contextFilters.drawIds=t.contextFilters.drawIds.filter(D=>w.includes(D)):t.contextFilters.drawIds=w),(n=O==null?void 0:O.eventIds)!=null&&n.length&&(t.matchUpFilters||(t.matchUpFilters={}),(o=t.matchUpFilters)!=null&&o.eventIds&&t.matchUpFilters.eventIds.length?t.matchUpFilters.eventIds=t.matchUpFilters.eventIds.filter(D=>O.eventIds.includes(D)):t.matchUpFilters.eventIds=O.eventIds),(i=O==null?void 0:O.scheduledDates)!=null&&i.length&&(t.matchUpFilters||(t.matchUpFilters={}),t.matchUpFilters.scheduledDates&&t.matchUpFilters.scheduledDates.length?t.matchUpFilters.scheduledDates=t.matchUpFilters.scheduledDates.filter(D=>O.scheduledDates.includes(D)):t.matchUpFilters.scheduledDates=O.scheduledDates),f&&(t.matchUpFilters||(t.matchUpFilters={}),(a=(s=t.matchUpFilters)==null?void 0:s.excludeMatchUpStatuses)!=null&&a.length?t.matchUpFilters.excludeMatchUpStatuses.includes(Mt)||t.matchUpFilters.excludeMatchUpStatuses.push(Mt):t.matchUpFilters.excludeMatchUpStatuses=[Mt]);const{completedMatchUps:T,upcomingMatchUps:$,pendingMatchUps:N}=xv(wm(Ld({},t),{matchUpFilters:t.matchUpFilters,contextFilters:t.contextFilters})),E=[...$??[],...N??[]],A=d?xd({matchUps:E,schedulingProfile:p}):E,U=l==null?void 0:l.map(D=>{var R;const j=M(D);return Ld({surfaceCategory:(R=D==null?void 0:D.surfaceCategory)!=null?R:"",matchUps:j},D)}),C={courtsData:U,completedMatchUps:f?b:T,dateMatchUps:A,venues:c};if(g){const{rows:D,courtPrefix:R}=Pb({minRowsCount:_,courtsData:U});C.courtPrefix=R,C.rows=D}return C;function M({courtId:D}){const j=(v?A.concat(T??[]):A).filter(G=>{var W,q,F;return((W=G.schedule)==null?void 0:W.courtId)===D||((F=(q=G.schedule)==null?void 0:q.allocatedCourts)==null?void 0:F.map(({courtId:L})=>L).includes(D))});return y?xd({matchUps:j,schedulingProfile:p}):j}}function _8({tournamentRecords:t}){var e,r,n,o;const i=[];for(const s of Object.values(t))for(const a of(e=s.events)!=null?e:[]){const{timeItem:l}=jo({itemType:`${Hr}.${qr}`,event:a}),c=(r=l==null?void 0:l.itemValue)==null?void 0:r[qn];if((n=c==null?void 0:c.drawIds)!=null&&n.length)i.push(...c.drawIds);else{const u=((o=a.drawDefinitions)!=null?o:[]).map(({drawId:p})=>p).filter(Boolean);i.push(...u)}}return{drawIds:i}}var I8=Object.defineProperty,P8=Object.defineProperties,y8=Object.getOwnPropertyDescriptors,aw=Object.getOwnPropertySymbols,S8=Object.prototype.hasOwnProperty,O8=Object.prototype.propertyIsEnumerable,lw=(t,e,r)=>e in t?I8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,b8=(t,e)=>{for(var r in e||(e={}))S8.call(e,r)&&lw(t,r,e[r]);if(aw)for(var r of aw(e))O8.call(e,r)&&lw(t,r,e[r]);return t},T8=(t,e)=>P8(t,y8(e));function cw({calculateStartTimeFromCourts:t=!0,defaultRecoveryMinutes:e=0,averageMatchUpMinutes:r=90,remainingScheduleTimes:n,clearScheduleDates:o,tournamentRecords:i,periodLength:s,scheduleDate:a,startTime:l,venueIds:c,endTime:u}){if(typeof i!="object"||!Object.keys(i).length)return{error:ke};s=s||rd({recoveryMinutes:e,averageMatchUpMinutes:r});const{courts:p,venues:d}=Ms({dates:[a],ignoreDisabled:!0,tournamentRecords:i}),v=p==null?void 0:p.filter($=>!c||c.includes($.venueId));l||(l=v==null?void 0:v.reduce(($,N)=>{var E;const A=(E=N.dateAvailability)==null?void 0:E.find(C=>!C.date||io(a,C.date)),U=(A==null?void 0:A.startTime)||N.startTime;return U&&(!$||Le(U)<Le($))?U:$},void 0)),u||(u=v==null?void 0:v.reduce(($,N)=>{var E;const A=(E=N.dateAvailability)==null?void 0:E.find(C=>!C.date||io(a,C.date)),U=(A==null?void 0:A.endTime)||N.endTime;return U&&(!$||Le(U)>Le($))?U:$},void 0));const f=Object.values(i),m=Object.assign({},...f.map($=>($.events||[]).map(N=>{const{scheduleTiming:E}=Cl({tournamentRecord:$,event:N});return{[N.eventId]:{event:N,scheduleTiming:E}}})).flat()),g=Em({sortDateMatchUps:!1,tournamentRecords:i,matchUpFilters:{scheduledDate:a,venueIds:c}}),_=(g==null?void 0:g.dateMatchUps)||[],I=(g==null?void 0:g.completedMatchUps)||[],P=[];P.push(..._),P.push(...I);const y={averageTimes:[{minutes:{default:r}}],recoveryTimes:[{minutes:{default:e}}]},S=P==null?void 0:P.map(({eventId:$,schedule:N,matchUpFormat:E})=>{const{event:A,scheduleTiming:U}=m[$],C=A==null?void 0:A.eventType,M=T8(b8({},U),{defaultTiming:y,matchUpFormat:E}),{averageMinutes:D,recoveryMinutes:R}=yu({eventType:C,timingDetails:M}),{courtId:j,venueId:G}=N,W=at(N.scheduledTime),q=Or(W,D);return{recoveryMinutes:R,averageMinutes:D,periodLength:s,startTime:W,endTime:q,courtId:j,venueId:G}}),O={calculateStartTimeFromCourts:t,remainingScheduleTimes:n,averageMatchUpMinutes:r,date:a,clearScheduleDates:o,periodLength:s,startTime:l,endTime:u,bookings:S,courts:v},{scheduleTimes:b}=Vv(O),w=(c==null?void 0:c.length)===1&&c[0]||(d==null?void 0:d.length)===1&&d[0].venueId||void 0,T=P.map(Jt);return{venueId:w,scheduleTimes:b,dateScheduledMatchUpIds:T}}function $m({matchUpScheduleTimes:t,matchUpDependencies:e,allDateMatchUpIds:r,matchUp:n}){var o;const s=(((o=e==null?void 0:e[n.matchUpId])==null?void 0:o.matchUpIds)||[]).filter(l=>r.includes(l)).filter(l=>!t[l]);return{dependenciesScheduled:!(s!=null&&s.length),remainingDependencies:s}}function Ya({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:e,timeAfterRecovery:r,matchUp:n}){var o,i,s,a;const{individualParticipantIds:l}=ed(n);r=r||((o=n.schedule)==null?void 0:o.timeAfterRecovery);const c=v=>{t[v]||(t[v]=[]),t[v]=We(t[v].concat(...l))},u=v=>{r&&(!e[v]||r>e[v])&&(e[v]=r)},p=((i=n.winnerTo)==null?void 0:i.matchUpId)||n.winnerMatchUpId;p&&(r&&u(p),c(p));const d=((s=n.loserTo)==null?void 0:s.matchUpId)||n.loserMatchUpId;d&&(r&&u(d),c(d)),(a=n.sidesTo)!=null&&a.length&&n.sidesTo.forEach(({matchUpId:v})=>{v&&(r&&u(v),c(v))})}function Tc({individualParticipantProfiles:t,participantId:e}){t[e]||(t[e]={typeChangeTimeAfterRecovery:void 0,timeAfterRecovery:void 0,priorMatchUpType:void 0,potentialRecovery:{},potentialCounted:{},potentialBookings:{},bookings:[],counters:{}})}function w8({individualParticipantProfiles:t,recoveryValue:e,participantId:r,scheduleTime:n,drawId:o}){t[r].potentialRecovery[o]||(t[r].potentialRecovery[o]=[]),t[r].potentialRecovery[o].push(e),t[r].potentialBookings[o]||(t[r].potentialBookings[o]=[]),t[r].potentialBookings[o].push({timeAfterRecovery:e,scheduleTime:n})}function wc({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,typeChangeRecoveryMinutes:r,averageMatchUpMinutes:n=0,matchUpNotBeforeTimes:o,matchUpDependencies:i,recoveryMinutes:s=0,scheduleTime:a,matchUp:l}){var c,u;const p=at((c=l==null?void 0:l.schedule)==null?void 0:c.endTime),d=p?Or(p,Te(s)):Or(a,Te(n)+Te(s)),v=r&&(p?Or(at(p),r):Or(a,Te(n)+Te(r))),f=((u=i==null?void 0:i[l.matchUpId])==null?void 0:u.participantIds)||[],m=(l.roundPosition&&t[l.matchUpId]||[]).flat();f.forEach(h=>{Tc({individualParticipantProfiles:e,participantId:h});const _=e[h].priorMatchUpType!==l.matchUpType&&v||d;m.includes(h)?w8({individualParticipantProfiles:e,drawId:l.drawId,recoveryValue:_,participantId:h,scheduleTime:a}):(e[h].timeAfterRecovery=_,e[h].bookings.push({scheduleTime:a,timeAfterRecovery:_}))}),Ya({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:o,timeAfterRecovery:d,matchUp:l})}function uw({matchUpScheduleTimes:t,matchUpDependencies:e,scheduleTime:r,matchUpId:n,details:o}){var i,s,a,l,c;let u;const p=(s=(i=o.minutesMap)==null?void 0:i[n])==null?void 0:s.recoveryMinutes,v=(((l=(a=o.minutesMap)==null?void 0:a[n])==null?void 0:l.averageMinutes)||0)+(p||0),f=Or(r,v),m=((c=e==null?void 0:e[n])==null?void 0:c.dependentMatchUpIds)||[];if(m.length){const h=m.reduce((g,_)=>{const I=t[_];if(!I)return g;const P={scheduleTime:I,matchUpId:_};return I&&!g.matchUpId||Le(I)<Le(g.scheduleTime)?P:g},{});h.scheduleTime&&Le(f)>Le(h.scheduleTime)&&(u=h)}return{scheduledDependent:u}}function E8(t){const{sides:e,matchUpType:r}=t||{};return(e||[]).map(n=>{var o;return r===dt&&(((o=n==null?void 0:n.participant)==null?void 0:o.individualParticipants)||[])||(n==null?void 0:n.participant)&&[n.participant]||[]}).flat()}const Vd="DO_NOT_SCHEDULE";var $8=Object.defineProperty,N8=Object.defineProperties,U8=Object.getOwnPropertyDescriptors,dw=Object.getOwnPropertySymbols,A8=Object.prototype.hasOwnProperty,C8=Object.prototype.propertyIsEnumerable,pw=(t,e,r)=>e in t?$8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,M8=(t,e)=>{for(var r in e||(e={}))A8.call(e,r)&&pw(t,r,e[r]);if(dw)for(var r of dw(e))C8.call(e,r)&&pw(t,r,e[r]);return t},D8=(t,e)=>N8(t,U8(e));function Nm({averageMatchUpMinutes:t=90,requestConflicts:e={},potentials:r=!0,personRequests:n,scheduleTime:o,scheduleDate:i,matchUp:s}){const a=E8(s).map(({person:v})=>v==null?void 0:v.personId);if(r){const v=((s==null?void 0:s.potentialParticipants)||[]).flat().map(({person:f})=>f==null?void 0:f.personId);a.push(...v)}const l=a.map(v=>{var f;return(f=n[v])==null?void 0:f.map(m=>D8(M8({},m),{personId:v}))}).filter(Boolean).flat().filter(v=>v.requestType===Vd&&io(i,v.date)),c=[],u=s==null?void 0:s.matchUpId,p=$t(at(o),Re(i)),d=at(If(p,t).toISOString());for(const v of l){const{requestId:f,startTime:m,endTime:h}=v;(o>m&&o<h||d>m&&d<h)&&(c.push({matchUpId:u,request:v,scheduleTime:o}),e[f]?(e[f].scheduleTimes.includes(o)||e[f].scheduleTimes.push(o),e[f].matchUpIds.includes(u)||e[f].matchUpIds.push(u)):e[f]={request:v,scheduleTimes:[o],matchUpIds:[u]})}return{conflicts:c}}function Um({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,matchUp:r,value:n}){const{matchUpType:o}=r,{individualParticipantIds:i}=ed(r),a=(t[r.matchUpId]||[]).filter(c=>!Xt(c,i)).flat();[...i,...a].forEach(c=>{if(Tc({individualParticipantProfiles:e,participantId:c}),!e[c].potentialCounted[r.drawId]){const u=e[c].counters;u[o]?u[o]+=n:n>0&&(u[o]=n),u[Pn]?u[Pn]+=n:n>0&&(u[Pn]=n),a.includes(c)&&(e[c].potentialCounted[r.drawId]=!0)}})}function j8({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,dateScheduledMatchUpIds:r,greatestAverageMinutes:n,dateScheduledMatchUps:o,matchUpNotBeforeTimes:i,matchUpScheduleTimes:s,matchUpDependencies:a,clearScheduleDates:l,scheduleDate:c,minutesMap:u,matchUps:p}){var d,v;r||(o=p==null?void 0:p.filter(h=>{const g=h.schedule||{};return yc({schedule:g})&&(!c||h.schedule.scheduledDate===c)}),r=o.map(Jt));const f=Array.isArray(l)?l.includes(c):l,m=f?[]:p.filter(({matchUpId:h})=>r.includes(h));for(const h of m){Um({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,value:1,matchUp:h});const g=(d=h.schedule)==null?void 0:d.scheduledTime;if(g){s[h.matchUpId]=g;const _=(v=u==null?void 0:u[h.matchUpId])==null?void 0:v.recoveryMinutes;wc({individualParticipantProfiles:e,matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:i,matchUpDependencies:a,averageMatchUpMinutes:n,recoveryMinutes:_,scheduleTime:g,matchUp:h})}}return{clearDate:f,dateScheduledMatchUpIds:r,dateScheduledMatchUps:o}}function R8({scheduledRoundsDetails:t,greatestAverageMinutes:e,garmanSinglePass:r}){const n=[];let o=[],i,s,a,l;for(const c of t.filter(Boolean))l||(l=c.hash),(c.hash===l||r)&&(o=o.concat(c.matchUpIds)),c.hash!==l&&!r&&(l=c.hash,n.push({averageMinutes:a,recoveryMinutes:s,roundPeriodLength:i,matchUpIds:o}),o=c.matchUpIds),a=r?e:c.averageMinutes,s=c.recoveryMinutes,i=c.roundPeriodLength;return o.length&&n.push({averageMinutes:a,recoveryMinutes:s,roundPeriodLength:i,matchUpIds:o}),{groupedRounds:n}}function F8({matchUpPotentialParticipantIds:t,scheduleCompletedMatchUps:e,dateScheduledMatchUpIds:r,matchUpNotBeforeTimes:n,orderedMatchUpIds:o,clearDate:i,matchUps:s}){const a=o.map(c=>s.find(u=>u.matchUpId===c)).filter(Boolean).filter(c=>{const u=!i&&r.includes(c.matchUpId),p=[nt,Xe,Mt,Wr,_r,ot,Rt,tr].includes(c==null?void 0:c.matchUpStatus);return e||!u&&!c.winningSide&&!p}),{matchUpMap:l}=a.reduce((c,u)=>{const{drawId:p,tournamentId:d}=u;return c.matchUpMap[d]||(c.matchUpMap[d]={}),c.matchUpMap[d][p]?c.matchUpMap[d][p].push(u):c.matchUpMap[d][p]=[u],Ya({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:n,matchUp:u}),c},{matchUpMap:{}});return{matchUpsToSchedule:a,matchUpMap:l}}var x8=Object.defineProperty,L8=Object.defineProperties,V8=Object.getOwnPropertyDescriptors,fw=Object.getOwnPropertySymbols,B8=Object.prototype.hasOwnProperty,k8=Object.prototype.propertyIsEnumerable,vw=(t,e,r)=>e in t?x8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,G8=(t,e)=>{for(var r in e||(e={}))B8.call(e,r)&&vw(t,r,e[r]);if(fw)for(var r of fw(e))k8.call(e,r)&&vw(t,r,e[r]);return t},W8=(t,e)=>L8(t,V8(e));function Am({defaultRecoveryMinutes:t=0,averageMatchUpMinutes:e=90,dateScheduledMatchUps:r,tournamentRecords:n,venueIds:o=[],periodLength:i,scheduleDate:s,matchUps:a}){if(typeof n!="object")return{error:ke};if(!Array.isArray(a)&&!Array.isArray(r))return{error:ko};i=i||rd({recoveryMinutes:t,averageMatchUpMinutes:e});const l=Object.assign({},...Object.values(n).map(d=>(d.events||[]).map(v=>{const{scheduleTiming:f}=Cl({tournamentRecord:d,event:v});return{[v.eventId]:{event:v,scheduleTiming:f}}})).flat()),c={averageTimes:[{minutes:{default:e}}],recoveryTimes:[{minutes:{default:t}}]};r||(r=a==null?void 0:a.filter(d=>{const v=d.schedule;return yc({schedule:v})&&(!s||d.schedule.scheduledDate===s)}));const u=r==null?void 0:r.filter(d=>!o.length||o.includes(d.schedule.venueId));return{bookings:u==null?void 0:u.map(({eventId:d,schedule:v,matchUpFormat:f})=>{const{event:m,scheduleTiming:h}=l[d],g=m==null?void 0:m.eventType,_=W8(G8({},h),{defaultTiming:c,matchUpFormat:f}),{averageMinutes:I,recoveryMinutes:P}=yu({timingDetails:_,eventType:g}),{courtId:y,venueId:S}=v,O=at(v.scheduledTime),b=Or(O,I);return{recoveryMinutes:P,averageMinutes:I,periodLength:i,startTime:O,courtId:y,endTime:b,venueId:S}}).filter(Boolean),relevantMatchUps:u,dateScheduledMatchUps:r}}function H8({calculateStartTimeFromCourts:t=!0,remainingScheduleTimes:e,defaultRecoveryMinutes:r,averageMatchUpMinutes:n,clearScheduleDates:o,tournamentRecords:i,tournamentRecord:s,periodLength:a,scheduleDate:l,startTime:c,venueIds:u,matchUps:p,endTime:d}){if(s&&!i&&(i={[s.tournamentId]:s}),typeof i!="object"||!Object.keys(i).length)return{error:ke};a=a||rd({recoveryMinutes:r,averageMatchUpMinutes:n});const{courts:v,venues:f}=Ms({dates:[l],ignoreDisabled:!0,tournamentRecords:i}),m=(v==null?void 0:v.filter(S=>!u||u.includes(S.venueId)))||[];c=c||Ma({courts:m,scheduleDate:l,startTime:!0}),d=d||Ma({courts:m,scheduleDate:l,endTime:!0});const{bookings:h,dateScheduledMatchUps:g}=Am({defaultRecoveryMinutes:r,averageMatchUpMinutes:n,tournamentRecords:i,scheduleDate:l,periodLength:a,venueIds:u,matchUps:p}),_={calculateStartTimeFromCourts:t,remainingScheduleTimes:e,averageMatchUpMinutes:n,clearScheduleDates:o,date:l,periodLength:a,startTime:c,bookings:h,endTime:d,courts:m},{scheduleTimes:I}=Vv(_),P=(u==null?void 0:u.length)===1&&u[0]||(f==null?void 0:f.length)===1&&f[0].venueId||void 0;return{dateScheduledMatchUpIds:g==null?void 0:g.map(Fn("matchUpId")),dateScheduledMatchUps:g,scheduleTimes:I,venueId:P}}function mw({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,scheduleCompletedMatchUps:r,containedStructureIds:n,matchUpNotBeforeTimes:o,matchUpScheduleTimes:i,matchUpDependencies:s,clearScheduleDates:a,tournamentRecords:l,periodLength:c,scheduleDate:u,useGarman:p,matchUps:d,courts:v,venues:f}){var m;const h={},g=[],_=[];for(const I of f){const{rounds:P=[],venueId:y}=I,{scheduledRoundsDetails:S,greatestAverageMinutes:O,orderedMatchUpIds:b,minutesMap:w}=bm({scheduleCompletedMatchUps:r,containedStructureIds:n,tournamentRecords:l,periodLength:c,matchUps:d,rounds:P});_.push(...b||[]);const{groupedRounds:T}=R8({scheduledRoundsDetails:S,greatestAverageMinutes:O,garmanSinglePass:!0});let $,N,E=[];p&&({scheduleTimes:E,dateScheduledMatchUpIds:$,dateScheduledMatchUps:N}=H8({averageMatchUpMinutes:(m=T[0])==null?void 0:m.averageMinutes,scheduleDate:Re(u),venueIds:[I.venueId],clearScheduleDates:a,tournamentRecords:l,periodLength:c,matchUps:d}));const A=j8({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,dateScheduledMatchUpIds:$,greatestAverageMinutes:O,matchUpNotBeforeTimes:o,matchUpScheduleTimes:i,matchUpDependencies:s,clearScheduleDates:a,scheduleDate:u,minutesMap:w,matchUps:d}),U=A.clearDate;({dateScheduledMatchUpIds:$,dateScheduledMatchUps:N}=A);const{matchUpsToSchedule:C,matchUpMap:M}=F8({matchUpPotentialParticipantIds:t,scheduleCompletedMatchUps:r,dateScheduledMatchUpIds:$,matchUpNotBeforeTimes:o,orderedMatchUpIds:b,clearDate:U,matchUps:d}),D=v.filter(R=>R.venueId===y);h[y]={previousRemainingScheduleTimes:[],courtsCount:D.length,greatestAverageMinutes:O,scheduledRoundsDetails:S,dateScheduledMatchUps:N,matchUpsToSchedule:C,scheduleTimes:E,groupedRounds:T,venueCourts:D,minutesMap:w,matchUpMap:M},a||g.push(...$)}return{allDateScheduledMatchUpIds:g,venueScheduledRoundDetails:h,allDateMatchUpIds:_}}function q8(t,e){const r=Le(t.scheduleTime),n=Le(t.timeAfterRecovery),o=Le(e.scheduleTime),i=Le(e.timeAfterRecovery),s=r===o||n===i,a=r>o&&r<i,l=o>r&&o<n,c=n>o&&n<i,u=i>r&&i<n;return Oe({hasOverlap:s||a||c||l||u,startAisContained:a,endAisContained:c,startBisContained:l,endBisContained:u},!0)}function Cm({individualParticipantProfiles:t,matchUpNotBeforeTimes:e,matchUpDependencies:r,scheduleTime:n,matchUp:o,details:i}){var s,a,l,c,u;const p=(((s=r==null?void 0:r[o.matchUpId])==null?void 0:s.participantIds)||[]).flat(),d=((l=(a=i==null?void 0:i.minutesMap)==null?void 0:a[o.matchUpId])==null?void 0:l.averageMinutes)||0,v=((u=(c=i==null?void 0:i.minutesMap)==null?void 0:c[o.matchUpId])==null?void 0:u.recoveryMinutes)||0,f=p.every(I=>{var P;Tc({individualParticipantProfiles:t,participantId:I});const y=t[I];if(!y.timeAfterRecovery)return!0;const S=at((P=o==null?void 0:o.schedule)==null?void 0:P.endTime),O=S?Or(S,Te(v)):Or(n,Te(d)+Te(v));return!!![...Object.keys(y.potentialBookings).filter($=>$!==o.drawId).map($=>y.potentialBookings[$]).flat(),...y.bookings].find($=>q8({scheduleTime:n,timeAfterRecovery:O},$).hasOverlap)}),m=e[o.matchUpId],g=(m?Sl($t(m),$t(n),!1):0)>=0;return{enoughTime:f&&g}}function Mm({individualParticipantProfiles:t,matchUpPotentialParticipantIds:e,matchUpDailyLimits:r={},matchUp:n}){const{matchUpId:o,matchUpType:i}=n,{enteredIndividualParticipantIds:s}=ed(n),a=(n.roundPosition&&e[o]||[]).flat(),l=We(s.concat(...a));return l.forEach(u=>{Tc({individualParticipantProfiles:t,participantId:u})}),{participantIdsAtLimit:l.filter(u=>{const p=t[u];if(p)return[i,Pn].find(d=>{var v;const f=((v=p.counters)==null?void 0:v[d])||0,m=r[d]||0;return f&&m&&f>=m})}),relevantParticipantIds:l}}const z8="deleteDrawDefinitions",Y8="autoSchedulingAudit",hw="deleteEvents";function gw({autoSchedulingAudit:t,tournamentRecords:e}){var r;He({topic:Ml,payload:t});const n=a=>a?Object.values(a).reduce((c,u)=>c+u.length||0,0):0,o=((t==null?void 0:t.schedulingProfile)||[]).reduce((a,l)=>a+l.venues.reduce((c,u)=>c+u.rounds.length,0),0),i={scheduledDatesCount:(r=t.scheduledDates)==null?void 0:r.length,noTimeMatchUpIdsCount:n(t==null?void 0:t.noTimeMatchUpIds),scheduledMatchUpIdsCount:n(t==null?void 0:t.scheduledMatchUpIds),overLimitMatchUpIdsCount:n(t==null?void 0:t.overLimitMatchUpIds),requestConflictsCount:n(t==null?void 0:t.requestConflicts),profileRoundsCount:o},s={itemType:Y8,itemValue:i};for(const a of Object.values(e))Fo({tournamentRecord:a,timeItem:s})}var K8=Object.defineProperty,Q8=Object.defineProperties,J8=Object.getOwnPropertyDescriptors,_w=Object.getOwnPropertySymbols,Z8=Object.prototype.hasOwnProperty,X8=Object.prototype.propertyIsEnumerable,Iw=(t,e,r)=>e in t?K8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,e9=(t,e)=>{for(var r in e||(e={}))Z8.call(e,r)&&Iw(t,r,e[r]);if(_w)for(var r of _w(e))X8.call(e,r)&&Iw(t,r,e[r]);return t},t9=(t,e)=>Q8(t,J8(e));function r9({schedulingProfileModifications:t,checkPotentialRequestConflicts:e,scheduleCompletedMatchUps:r,schedulingProfileIssues:n,dateSchedulingProfiles:o,containedStructureIds:i,matchUpDependencies:s,matchUpDailyLimits:a,clearScheduleDates:l,schedulingProfile:c,tournamentRecords:u,personRequests:p,periodLength:d,matchUps:v,courts:f,dryRun:m}){var h,g,_,I,P,y,S;const O={},b={},w={},T={},$={},N={},E={},A={},U={},C={};for(const R of o){const j=Re(R==null?void 0:R.scheduleDate),G=(R==null?void 0:R.venues)||[],W={},q={},F=(K,Q)=>{K.forEach(J=>{const te=q[J].counters;te[Q]?te[Q]+=1:te[Q]=1,te[Pn]?te[Pn]+=1:te[Pn]=1})};w[j]={},T[j]={},O[j]={},b[j]={},E[j]=[],A[j]=[],U[j]=[],C[j]=[];const L={};v.forEach(K=>{var Q;(Q=K.schedule)!=null&&Q.scheduledDate&&io(j,Re(K.schedule.scheduledDate))&&Ya({matchUpPotentialParticipantIds:W,matchUpNotBeforeTimes:L,matchUp:K})});const{venueScheduledRoundDetails:x,allDateMatchUpIds:B}=mw({matchUpPotentialParticipantIds:W,individualParticipantProfiles:q,scheduleCompletedMatchUps:r,containedStructureIds:i,matchUpNotBeforeTimes:L,matchUpScheduleTimes:N,matchUpDependencies:s,clearScheduleDates:l,tournamentRecords:u,useGarman:!0,periodLength:d,scheduleDate:j,matchUps:v,courts:f,venues:G}),z=10;let H=0,Y;const Z=10;for(;!Y;){for(const{venueId:K}of G){let Q=0;const J=x[K];for(;J.courtsCount&&((h=J.scheduleTimes)!=null&&h.length)&&((g=J.matchUpsToSchedule)!=null&&g.length)&&Q<=J.courtsCount;){const{scheduleTime:te,attempts:ne=0}=J.scheduleTimes.shift(),ee=J.matchUpsToSchedule.find(oe=>{var ie,ae;const{matchUpId:se,matchUpType:ye}=oe,{participantIdsAtLimit:Ie,relevantParticipantIds:pe}=Mm({matchUpPotentialParticipantIds:W,individualParticipantProfiles:q,matchUpDailyLimits:a,matchUp:oe});if(Ie.length)return A[j].includes(se)||A[j].push(se),!1;const{scheduledDependent:fe}=uw({matchUpScheduleTimes:N,matchUpDependencies:s,scheduleTime:te,matchUpId:se,details:J});if(fe)return!1;const{dependenciesScheduled:ve,remainingDependencies:le}=$m({matchUpScheduleTimes:N,matchUpDependencies:s,allDateMatchUpIds:B,matchUp:oe});if(!ve)return T[j][se]||(T[j][se]=[]),T[j][se].push({scheduleTime:te,remainingDependencies:le}),!1;const{enoughTime:be}=Cm({individualParticipantProfiles:q,matchUpNotBeforeTimes:L,matchUpDependencies:s,scheduleTime:te,details:J,matchUp:oe});if(!be)return w[j][se]||(w[j][se]=[]),w[j][se].push({scheduleTime:te}),!1;const Me=J.greatestAverageMinutes,{conflicts:Pe}=Nm({potentials:e,averageMatchUpMinutes:Me,requestConflicts:C,personRequests:p,scheduleTime:te,scheduleDate:j,matchUp:oe});if(Pe!=null&&Pe.length)return $[j]||($[j]=[]),$[j].push(...Pe),!1;F(pe,ye);const xe=(ae=(ie=J.minutesMap)==null?void 0:ie[se])==null?void 0:ae.recoveryMinutes;return wc({matchUpPotentialParticipantIds:W,individualParticipantProfiles:q,matchUpNotBeforeTimes:L,averageMatchUpMinutes:Me,matchUpDependencies:s,recoveryMinutes:xe,scheduleTime:te,matchUp:oe}),N[se]=te,!0});J.matchUpsToSchedule=J.matchUpsToSchedule.filter(({matchUpId:oe})=>oe!==(ee==null?void 0:ee.matchUpId)),ee?Q+=1:(b[j][K]||(b[j][K]=[]),b[j][K].push({scheduleTime:te,attempts:ne+1}))}(_=J.matchUpsToSchedule)!=null&&_.length&&(b[j][K]=(I=b[j][K])==null?void 0:I.filter(te=>{const ne=te.attempts<z;return ne&&J.scheduleTimes.push(te),!ne})),(!((P=J.scheduleTimes)!=null&&P.length)||!((y=J.matchUpsToSchedule)!=null&&y.length))&&(J.complete=!0)}H+=1,Y=G.every(({venueId:K})=>x[K].complete)||H===Z}for(const{venueId:K}of G){const Q=x[K].matchUpMap;Object.keys(Q).forEach(J=>{const te=u[J];te&&Object.keys(Q[J]).forEach(ne=>{const{drawDefinition:ee}=Jo({tournamentRecord:te,drawId:ne});ee&&Q[J][ne].forEach(({matchUpId:ie})=>{const ae=N[ie];if(ae){const se=ae.split(":").map(oo).join(":"),ye=`${Re(j)}T${se}`;m?E[j].push(ie):(Gi({drawDefinition:ee,scheduledTime:ye,matchUpId:ie}).success&&E[j].push(ie),K&&ja({tournamentRecord:te,drawDefinition:ee,matchUpId:ie,venueId:K}))}})})}),U[j]=x[K].matchUpsToSchedule.map(Jt),O[j][K]=x[K].scheduleTimes.sort((J,te)=>Le(J.scheduleTime)-Le(te.scheduleTime))}for(const K of R.venues)for(const Q of K.rounds){const te=(((S=Q.matchUps)==null?void 0:S.map(({matchUpId:ee})=>ee))||[]).filter(ee=>E[j].includes(ee));Q.canScheduledMatchUpIds=te;let ne=Math.round(te.length/Q.matchUpsCount*1e4)/100;(ne===1/0||isNaN(ne))&&(ne=0),Q.possibleToSchedulePct=ne,Q.matchUpsCount===te.length&&(Q.possibleToSchedule=!0)}}const M=o.map(({scheduleDate:R})=>R),D={timeStamp:Date.now(),overLimitMatchUpIds:A,scheduledMatchUpIds:E,schedulingProfile:c,noTimeMatchUpIds:U,requestConflicts:C,scheduledDates:M};return gw({tournamentRecords:u,autoSchedulingAudit:D}),t9(e9({},V),{schedulingProfileModifications:t,schedulingProfileIssues:n,scheduleTimesRemaining:O,dateSchedulingProfiles:o,skippedScheduleTimes:b,recoveryTimeDeferredMatchUpIds:w,dependencyDeferredMatchUpIds:T,matchUpScheduleTimes:N,overLimitMatchUpIds:A,scheduledMatchUpIds:E,noTimeMatchUpIds:U,requestConflicts:C,scheduledDates:M})}function Pw({averageMinutes:t,startTime:e,endTime:r,court:n,date:o}){if(!Array.isArray(n.dateAvailability))return{error:_e,stack:"getEarliestCourtTime"};const i=Ma({scheduleDate:o,courts:[n],startTime:!0}),s=Ma({scheduleDate:o,courts:[n],endTime:!0});e=e||i,r=r||s;const a=lc({court:n,date:o}),l=Ca({courtDate:a}),c=$t(e),u=$t(r);return{earliestCourtTime:l.reduce((d,v)=>{const f=$t(v.startTime),m=$t(v.endTime);if(f>u||m<c)return d;const h=c>f?c:f;if(Sl(h,m)>=t){const I=at(h.toISOString());(!d||I<d)&&(d=I)}return d},void 0),courtStartTime:i,courtEndTime:s}}var n9=Object.defineProperty,o9=Object.defineProperties,i9=Object.getOwnPropertyDescriptors,yw=Object.getOwnPropertySymbols,s9=Object.prototype.hasOwnProperty,a9=Object.prototype.propertyIsEnumerable,Sw=(t,e,r)=>e in t?n9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l9=(t,e)=>{for(var r in e||(e={}))s9.call(e,r)&&Sw(t,r,e[r]);if(yw)for(var r of yw(e))a9.call(e,r)&&Sw(t,r,e[r]);return t},c9=(t,e)=>o9(t,i9(e));function u9({schedulingProfileModifications:t,checkPotentialRequestConflicts:e,scheduleCompletedMatchUps:r,schedulingProfileIssues:n,dateSchedulingProfiles:o,containedStructureIds:i,matchUpDependencies:s,matchUpDailyLimits:a,clearScheduleDates:l,tournamentRecords:c,periodLength:u=30,schedulingProfile:p,personRequests:d,matchUps:v,courts:f,dryRun:m}){var h;const g={},_={},I={},P={},y={},S={},O={},b={},w={};for(const N of o){const E=Re(N==null?void 0:N.scheduleDate),A=(N==null?void 0:N.venues)||[],U={},C={},M=(Z,K)=>{Z.forEach(Q=>{const J=C[Q].counters;J[K]?J[K]+=1:J[K]=1,J[Pn]?J[Pn]+=1:J[Pn]=1})};g[E]={},_[E]={},S[E]=[],O[E]=[],b[E]=[],w[E]=[];const D={};v.forEach(Z=>{var K;(K=Z.schedule)!=null&&K.scheduledDate&&io(E,Re(Z.schedule.scheduledDate))&&Ya({matchUpPotentialParticipantIds:U,matchUpNotBeforeTimes:D,matchUp:Z})});const{allDateScheduledMatchUpIds:R,venueScheduledRoundDetails:j,allDateMatchUpIds:G}=mw({matchUpPotentialParticipantIds:U,individualParticipantProfiles:C,scheduleCompletedMatchUps:r,containedStructureIds:i,matchUpNotBeforeTimes:D,matchUpScheduleTimes:y,matchUpDependencies:s,clearScheduleDates:l,tournamentRecords:c,periodLength:u,scheduleDate:E,matchUps:v,courts:f,venues:A}),W=v.filter(({matchUpId:Z})=>R.includes(Z)),{bookings:q}=Am({dateScheduledMatchUps:W,tournamentRecords:c,scheduleDate:E,periodLength:u}),{virtualCourts:F}=Lv({scheduleDate:E,periodLength:u,bookings:q,courts:f}),L=F==null?void 0:F.reduce((Z,K)=>{const{earliestCourtTime:Q,courtEndTime:J}=Pw({date:E,averageMinutes:0,court:K});return(!Z.startTime||$t(Q)<$t(Z.startTime))&&(Z.startTime=Q),(!Z.endTime||$t(J)>$t(Z.endTime))&&(Z.endTime=J),Z},{});let x=L.startTime;const B=({courtId:Z,booking:K})=>{var Q;return(Q=F==null?void 0:F.find(J=>J.courtId===Z))==null?void 0:Q.dateAvailability[0].bookings.push(K)},z=10;let H=0,Y;for(;!Y;){for(const{venueId:Z}of A){const K=j[Z],Q=K.matchUpsToSchedule.length,J=[],te=[];let ne,ee=0;for(;!ne;){for(const oe of K.matchUpsToSchedule){if(te.length===K.courtsCount||J.length===K.courtsCount){ne=!0;break}const{matchUpId:ie,matchUpType:ae}=oe,{participantIdsAtLimit:se,relevantParticipantIds:ye}=Mm({matchUpPotentialParticipantIds:U,individualParticipantProfiles:C,matchUpDailyLimits:a,matchUp:oe});if(se.length){O[E].includes(ie)||O[E].push(ie);continue}const{dependenciesScheduled:Ie,remainingDependencies:pe}=$m({matchUpScheduleTimes:y,matchUpDependencies:s,allDateMatchUpIds:G,matchUp:oe});if(!Ie){_[E][ie]||(_[E][ie]=[]),_[E][ie].push({remainingDependencies:pe});continue}const fe=[],ve=F==null?void 0:F.reduce((le,be)=>{var Me,Pe,xe,Be;if(te.includes(be.courtId))return le;const{earliestCourtTime:qe}=Pw({averageMinutes:K.greatestAverageMinutes,startTime:x,date:E,court:be});if(le.scheduleTime&&Le(qe)>=Le(le.scheduleTime))return le;const{scheduledDependent:$e}=uw({matchUpScheduleTimes:y,matchUpDependencies:s,scheduleTime:qe,matchUpId:ie,details:K});if($e)return le;const{enoughTime:De}=Cm({individualParticipantProfiles:C,matchUpNotBeforeTimes:D,matchUpDependencies:s,scheduleTime:qe,details:K,matchUp:oe});if(!De)return g[E][ie]||(g[E][ie]=[]),g[E][ie].includes(qe)||g[E][ie].push(qe),le;const me=((Pe=(Me=K.minutesMap)==null?void 0:Me[ie])==null?void 0:Pe.averageMinutes)||K.greatestAverageMinutes,{conflicts:ge}=Nm({potentials:e,averageMatchUpMinutes:me,requestConflicts:w,personRequests:d,scheduleTime:qe,scheduleDate:E,matchUp:oe});if(ge!=null&&ge.length)return fe.push(...ge),!1;M(ye,ae);const Se=(Be=(xe=K.minutesMap)==null?void 0:xe[ie])==null?void 0:Be.recoveryMinutes;return wc({matchUpPotentialParticipantIds:U,individualParticipantProfiles:C,matchUpNotBeforeTimes:D,averageMatchUpMinutes:me,matchUpDependencies:s,recoveryMinutes:Se,scheduleTime:qe,matchUp:oe}),(!le.scheduleTime||Le(qe)<Le(le.scheduleTime))&&(le.averageMatchUpMinutes=me,le.recoveryMinutes=Se,le.scheduleTime=qe,le.courtName=be.courtName,le.courtId=be.courtId),le},{});if(ve.scheduleTime){const{averageMatchUpMinutes:le,recoveryMinutes:be,scheduleTime:Me,courtId:Pe}=ve;y[ie]=Me,P[ie]=Pe,J.push(ie),te.push(Pe);const xe=Me,Be=Or(xe,le);B({courtId:Pe,booking:{averageMatchUpMinutes:le,recoveryMinutes:be,periodLength:u,matchUpId:ie,startTime:xe,courtId:Pe,endTime:Be,venueId:Z}}),K.matchUpsToSchedule=K.matchUpsToSchedule.filter($e=>$e.matchUpId!==ie)}else fe!=null&&fe.length&&(I[E]||(I[E]=[]),I[E].push(...fe))}(te.length===K.courtsCount||J.length===K.courtsCount||!K.matchUpsToSchedule.length)&&(ne=!0),K.matchUpsToSchedule.length&&J<K.courtsCount&&($t(x)<$t(L.endTime)?x=Or(x,u):(ne=!0,K.complete=!0)),ee+=1,!ne&&ee>=Q&&(ne=!0)}(h=K.matchUpsToSchedule)!=null&&h.length||(K.complete=!0)}H+=1,Y=A.every(({venueId:Z})=>j[Z].complete)||H===z}for(const{venueId:Z}of A){const K=j[Z].matchUpMap;Object.keys(K).forEach(Q=>{const J=c[Q];J&&Object.keys(K[Q]).forEach(te=>{const{drawDefinition:ne}=Jo({tournamentRecord:J,drawId:te});ne&&K[Q][te].forEach(({matchUpId:oe})=>{const ie=y[oe],ae=P[oe];if(ie){const se=ie.split(":").map(oo).join(":"),ye=`${Re(E)}T${se}`;m||(Gi({drawDefinition:ne,scheduledTime:ye,matchUpId:oe}),Ds({courtDayDate:E,tournamentRecords:c,tournamentRecord:J,drawDefinition:ne,matchUpId:oe,courtId:ae})),S[E].push(oe)}})})}),b[E]=j[Z].matchUpsToSchedule.map(Jt)}for(const Z of N.venues)for(const K of Z.rounds){const J=K.matchUps.map(({matchUpId:ne})=>ne).filter(ne=>S[E].includes(ne));K.canScheduledMatchUpIds=J;let te=Math.round(J.length/K.matchUpsCount*1e4)/100;(te===1/0||isNaN(te))&&(te=0),K.possibleToSchedulePct=te,K.matchUpsCount===J.length&&(K.possibleToSchedule=!0)}}const T=o.map(({scheduleDate:N})=>N),$={timeStamp:Date.now(),overLimitMatchUpIds:O,scheduledMatchUpIds:S,schedulingProfile:p,noTimeMatchUpIds:b,requestConflicts:w,scheduledDates:T};return gw({tournamentRecords:c,autoSchedulingAudit:$}),c9(l9({},V),{schedulingProfileModifications:t,schedulingProfileIssues:n,dateSchedulingProfiles:o,recoveryTimeDeferredMatchUpIds:g,dependencyDeferredMatchUpIds:_,matchUpScheduleTimes:y,overLimitMatchUpIds:O,scheduledMatchUpIds:S,noTimeMatchUpIds:b,requestConflicts:w,scheduledDates:T})}var d9=Object.defineProperty,Ow=Object.getOwnPropertySymbols,p9=Object.prototype.hasOwnProperty,f9=Object.prototype.propertyIsEnumerable,bw=(t,e,r)=>e in t?d9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tw=(t,e)=>{for(var r in e||(e={}))p9.call(e,r)&&bw(t,r,e[r]);if(Ow)for(var r of Ow(e))f9.call(e,r)&&bw(t,r,e[r]);return t};function Ka({tournamentRecords:t,requestType:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const r={};for(const n of Object.values(t)){const{extension:o}=Fr({name:va,tournamentRecord:n}),i=(o==null?void 0:o.value)||[];for(const s of i){const{personId:a,requests:l}=s||{};r[a]||(r[a]=[]);for(const c of l)e&&c.requestType!==e||r[a].push(c)}}return{personRequests:r}}function Dm({tournamentRecords:t,personRequests:e}){var r;if(!t)return{error:ke};if(!e)return Tw({},V);const n=Object.values(t);for(const o of n){const i=(r=o.participants)!=null?r:[],s=[];for(const a of Object.keys(e))if(Eo({tournamentParticipants:i,personId:a})){const l=e[a];l.length&&s.push({personId:a,requests:l})}Object.keys(s).length&&Ei({tournamentRecord:o,extension:{name:va,value:s}})}return Tw({},V)}function v9({tournamentRecords:t,personId:e,requests:r}){if(!t)return{error:ke};if(typeof e!="string")return{error:X};if(!Array.isArray(r))return{error:X};const{personRequests:n}=Ka({tournamentRecords:t}),{mergeCount:o}=ww({personRequests:n,personId:e,requests:r});return o&&n?Dm({tournamentRecords:t,personRequests:n}):{error:X}}function ww({personRequests:t,personId:e,requests:r}){t[e]||(t[e]=[]);const n=r.filter(({requestType:o})=>o).map(o=>{let{date:i,startTime:s,endTime:a}=o;return o.requestType===Vd&&(i=Re(i),s=at(s),a=at(a),i&&s&&a)?{date:i,startTime:s,endTime:a,requestType:o.requestType}:o}).filter(Boolean);for(const o of n)o.requestId=C_(),t[e].push(o);return{mergeCount:n.length}}function m9({tournamentRecords:t,requestType:e,requestId:r,personId:n,date:o}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const{personRequests:i}=Ka({tournamentRecords:t}),s=l=>{var c;i&&(i[l]=i[l].filter(u=>(!e||u.requestType!==e)&&(!r||u.requestId!==r)&&(!o||u.date!==o)),(c=i==null?void 0:i[l])!=null&&c.length||delete i[l])},a=!e&&!r&&!n&&!o;if(!a){if(n&&(i!=null&&i[n]))s(n);else if(i)for(const l of Object.keys(i))s(l)}return a||!i||!Object.keys(i).length?Tu({tournamentRecords:t,name:va}):Dm({tournamentRecords:t,personRequests:i})}function h9({tournamentRecords:t,requests:e,personId:r}){if(!t)return{error:ke};if(!Array.isArray(e))return{error:X};const n=e.map(({requestId:a})=>a).filter(Boolean),{personRequests:o}=Ka({tournamentRecords:t}),i=a=>{o&&(o[a]=o[a].map(l=>{if(!n.includes(l.requestId))return l;const c=e.find(u=>u.requestId===l.requestId);if(c.requestType)return Object.assign(l,c)}).filter(Boolean))};if(r&&(o!=null&&o[r]))i(r);else if(o)for(const a of Object.keys(o))i(a);const s=e.filter(a=>!a.requestId);return s.length&&ww({personRequests:o,personId:r,requests:s}),Dm({tournamentRecords:t,personRequests:o})}var g9=Object.defineProperty,_9=Object.defineProperties,I9=Object.getOwnPropertyDescriptors,Ew=Object.getOwnPropertySymbols,P9=Object.prototype.hasOwnProperty,y9=Object.prototype.propertyIsEnumerable,$w=(t,e,r)=>e in t?g9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,S9=(t,e)=>{for(var r in e||(e={}))P9.call(e,r)&&$w(t,r,e[r]);if(Ew)for(var r of Ew(e))y9.call(e,r)&&$w(t,r,e[r]);return t},O9=(t,e)=>_9(t,I9(e));function jm({scheduleAttributes:t=["scheduledDate","scheduledTime"],ignoreMatchUpStatuses:e=Yt,tournamentRecord:r,scheduledDates:n,venueIds:o=[]}){if(typeof r!="object")return{error:re};if(!Array.isArray(e)||!Array.isArray(o))return{error:X};o.length&&t.push("venueId");const s=(Wt({matchUpFilters:{scheduledDates:n},tournamentRecord:r}).matchUps||[]).filter(c=>c.matchUpStatus&&!e.includes(c.matchUpStatus)&&yc({schedule:c.schedule,scheduleAttributes:t})&&(!(o!=null&&o.length)||o.includes(c.schedule.venueId))).map(Jt),a=Wt({tournamentRecord:r,inContext:!1}).matchUps||[];let l=0;for(const c of a)s.includes(c.matchUpId)&&(c.timeItems=(c.timeItems||[]).filter(u=>(u==null?void 0:u.itemType)&&![Xo,hs,jl,Rl,Fl].includes(u==null?void 0:u.itemType)),l+=1);return O9(S9({},V),{clearedScheduleCount:l})}var b9=Object.defineProperty,Nw=Object.getOwnPropertySymbols,T9=Object.prototype.hasOwnProperty,w9=Object.prototype.propertyIsEnumerable,Uw=(t,e,r)=>e in t?b9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,E9=(t,e)=>{for(var r in e||(e={}))T9.call(e,r)&&Uw(t,r,e[r]);if(Nw)for(var r of Nw(e))w9.call(e,r)&&Uw(t,r,e[r]);return t};function Aw({scheduleAttributes:t=["scheduledDate","scheduledTime"],ignoreMatchUpStatuses:e=Yt,tournamentRecords:r,scheduledDates:n,venueIds:o}){const i=rs(r)?Object.values(r).map(({tournamentId:s})=>s).filter(Boolean):[];if(!(i!=null&&i.length))return{error:ke};for(const s of i){const a=r[s],l=jm({ignoreMatchUpStatuses:e,scheduleAttributes:t,tournamentRecord:a,scheduledDates:n,venueIds:o});if(l.error)return l}return E9({},V)}function Cw({tournamentRecord:t}){var e;if(!t)return{error:re};const{policy:r}=cs({policyType:$f,tournamentRecord:t}),{extension:n}=Fr({name:ss,tournamentRecord:t}),o=(e=n==null?void 0:n.value)==null?void 0:e.dailyLimits,i=r==null?void 0:r.defaultDailyLimits;return{matchUpDailyLimits:o||i}}function Mw({tournamentRecords:t,tournamentId:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};const r=Object.keys(t).filter(o=>!e||o===e);let n;return r.forEach(o=>{const i=t[o],{matchUpDailyLimits:s}=Cw({tournamentRecord:i});n=s}),{matchUpDailyLimits:n}}function Rm({checkPotentialRequestConflicts:t=!0,scheduleCompletedMatchUps:e,clearScheduleDates:r,scheduleDates:n=[],tournamentRecords:o,periodLength:i,dryRun:s,pro:a}){if(!o)return{error:ke};if(!Array.isArray(n))return{error:X};const l=za({tournamentRecords:o});if(l.error)return l;const{schedulingProfile:c=[],issues:u=[],modifications:p}=l,d=Object.assign({},...Object.values(o).map(S=>Ra({tournamentRecord:S}).containedStructures)),v=n.map(S=>{if(Gr(S))return Re(S)}).filter(Boolean),f=c.map(S=>S.scheduleDate).map(S=>Gr(S)&&Re(S)).filter(S=>S&&(!n.length||v.includes(S)));if(!f.length)return{error:Ix};if(r&&!s){const S=Array.isArray(r)?r:[];Aw({tournamentRecords:o,scheduledDates:S})}const{courts:m}=Ms({dates:n,ignoreDisabled:!0,tournamentRecords:o}),{matchUps:h}=Ro({matchUpFilters:{matchUpTypes:[At,dt]},afterRecoveryTimes:!0,nextMatchUps:!0,tournamentRecords:o}),{matchUpDependencies:g}=cn({includeParticipantDependencies:!0,tournamentRecords:o,matchUps:h}),{matchUpDailyLimits:_}=Mw({tournamentRecords:o}),{personRequests:I}=Ka({requestType:Vd,tournamentRecords:o}),P=c.filter(S=>{const O=Re(S==null?void 0:S.scheduleDate);return f.includes(O)}).sort((S,O)=>new Date(S.scheduleDate).getTime()-new Date(O.scheduleDate).getTime()),y={schedulingProfileModifications:p,checkPotentialRequestConflicts:t,scheduleCompletedMatchUps:e,schedulingProfileIssues:u,dateSchedulingProfiles:P,containedStructureIds:d,matchUpDependencies:g,matchUpDailyLimits:_,clearScheduleDates:r,tournamentRecords:o,schedulingProfile:c,personRequests:I,periodLength:i,matchUps:h,dryRun:s,courts:m};return a?u9(y):r9(y)}function Dw({event:t}){return t?Ou({event:t,name:Wn}):{error:Ge}}function $9({tournamentRecords:t,eventId:e}){if(!t)return{error:ke};if(typeof e!="string")return{error:_e,info:"missing eventId"};for(const r of Object.values(t)){const{event:n}=Qt({tournamentRecord:r,eventId:e});if(n)return Dw({event:n})}return{error:Ar}}function N9(t){Object.assign(t,{inContext:!0});const{matchUp:e,error:r}=Ec(t);return{matchUp:de(e,!0,!0),error:r}}function Ec({participantsProfile:t,afterRecoveryTimes:e,tournamentRecord:r,contextContent:n,contextProfile:o,drawDefinition:i,matchUpId:s,inContext:a,eventId:l,drawId:c,event:u}){if(!r)return{error:re};if(typeof s!="string")return{error:Vt};if(!i||!u){const h=(Wt({tournamentRecord:r}).matchUps||[]).find(g=>g.matchUpId===s);if(!h)return{error:ir};({eventId:l,drawId:c}=h),{event:u,drawDefinition:i}=Qt({tournamentRecord:r,eventId:l,drawId:c})}if(!i)return{error:en};o&&!n&&(n=wo({tournamentRecord:r,contextProfile:o}));const p={surfaceCategory:(u==null?void 0:u.surfaceCategory)||r.surfaceCategory,indoorOutDoor:(u==null?void 0:u.indoorOutdoor)||r.indoorOutdoor,endDate:(u==null?void 0:u.endDate)||r.endDate,tournamentId:r.tournamentId,eventId:l||(u==null?void 0:u.eventId),drawId:c},{participants:d=[]}=As({participantsProfile:t,tournamentRecord:r,contextProfile:o,inContext:a}),{matchUp:v,structure:f}=lt({context:a?p:void 0,tournamentParticipants:d,afterRecoveryTimes:e,contextContent:n,drawDefinition:i,contextProfile:o,matchUpId:s,inContext:a,event:u});return{matchUp:v,structure:f,drawDefinition:i}}function Fm({tournamentParticipants:t,tournamentRecord:e,drawDefinition:r,participantId:n,matchUpId:o,matchUp:i,event:s}){if(!n)return{error:Et};if(!o)return{error:jr};if(t=t??(e==null?void 0:e.participants),t!=null&&t.length){if(!i&&r){const p=lt({tournamentParticipants:t,inContext:!0,drawDefinition:r,matchUpId:o,event:s});if(!p.matchUp)return{error:ir};i=p.matchUp}const l=ec({matchUp:i});if(l.error)return l;const{checkedInParticipantIds:c,allRelevantParticipantIds:u}=l;if(!u.includes(n))return{error:So};if(c.includes(n))return{error:l_}}return Dr({tournamentRecord:e,drawDefinition:r,matchUpId:o,timeItem:{itemType:Qf,itemValue:n}})}function xm({tournamentParticipants:t,tournamentRecord:e,drawDefinition:r,participantId:n,matchUpId:o,matchUp:i,event:s}){if(!n)return{error:Et};if(!o&&!i)return{error:Vt};if(t=t??(e==null?void 0:e.participants),!i){const u=lt({tournamentParticipants:t,inContext:!0,drawDefinition:r,matchUpId:o,event:s});if(u.error)return u;if(!u.matchUp)return{error:ir};i=u.matchUp}const{matchUpStatus:a,score:l}=i;if(a&&H_.includes(a)||a&&Yt.includes(a)||Gt({score:l}))return{error:rx};if(t!=null&&t.length){const{checkedInParticipantIds:u,allRelevantParticipantIds:p}=ec({matchUp:i});if(!(p!=null&&p.includes(n)))return{error:So};if(!u.includes(n))return{error:Ux};const{sideParticipantIds:d,nestedIndividualParticipantIds:v}=dv({matchUp:i}),f=d.indexOf(n);[0,1].includes(f)&&(v[f]||[]).forEach(m=>{Dr({drawDefinition:r,matchUpId:o,timeItem:{itemType:Jf,itemValue:m}})})}return Dr({tournamentRecord:e,drawDefinition:r,matchUpId:o,timeItem:{itemType:Jf,itemValue:n}})}function jw(t){if(!(t!=null&&t.tournamentRecord))return{error:re};const{tournamentRecord:e,participantId:r,matchUpId:n,drawDefinition:o,event:i}=t,s=e.participants||[],a=Ec({tournamentRecord:e,inContext:!0,drawDefinition:o,matchUpId:n,event:i});if(!a.matchUp)return{error:ir};const l=a.matchUp,{checkedInParticipantIds:c=[]}=ec({matchUp:l});return c.includes(r)?xm({tournamentParticipants:s,tournamentRecord:e,drawDefinition:o,participantId:r,matchUpId:n,matchUp:l}):Fm({tournamentParticipants:s,tournamentRecord:e,drawDefinition:o,participantId:r,matchUpId:n,matchUp:l})}function U9(t){const{tournamentRecords:e}=t,{participantId:r,tournamentId:n,matchUpId:o,drawId:i}=t;if(!e||!n||!r||!o)return{error:_e,stack:"toggleParticipantCheckInState"};const s=e[n],{drawDefinition:a,event:l}=Jo({tournamentRecord:s,drawId:i});return Object.assign(t,{drawDefinition:a,event:l,tournamentRecord:s}),jw(t)}function Rw(t){var e;const{tournamentRecords:r}=t;if(!r)return{error:ke};const{removePriorValues:n,tournamentId:o,courtDayDate:i,matchUpId:s,courtId:a,drawId:l}=t,c=r[o];if(!c)return{error:re};const{drawDefinition:u,event:p}=Jo({tournamentRecord:c,drawId:l}),d=lt({drawDefinition:u,event:p,matchUpId:s});if(d.error)return d;if(((e=d==null?void 0:d.matchUp)==null?void 0:e.matchUpType)===hn){const{itemValue:v}=Ni({timeItems:d.matchUp.timeItems||[],itemType:Xo}),f=a&&v.filter(h=>h.courtId!==a);return Dr({duplicateValues:!1,removePriorValues:n,tournamentRecord:c,drawDefinition:u,matchUpId:s,timeItem:{itemType:Xo,itemValue:f}})}else return Ds({tournamentRecord:c,drawDefinition:u,courtDayDate:i,courtId:"",matchUpId:s})}function A9({tournamentRecords:t}){return HT({extensionName:ss,tournamentRecords:t})}var C9=Object.defineProperty,M9=Object.defineProperties,D9=Object.getOwnPropertyDescriptors,Fw=Object.getOwnPropertySymbols,j9=Object.prototype.hasOwnProperty,R9=Object.prototype.propertyIsEnumerable,xw=(t,e,r)=>e in t?C9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Vs=(t,e)=>{for(var r in e||(e={}))j9.call(e,r)&&xw(t,r,e[r]);if(Fw)for(var r of Fw(e))R9.call(e,r)&&xw(t,r,e[r]);return t},Bd=(t,e)=>M9(t,D9(e));const{stageOrder:Lw}=gG;function Lm({tournamentRecords:t,schedulingProfile:e,tournamentRecord:r,withRoundId:n}){if(r&&!t){if(typeof r!="object")return{error:Yc};t={[r.tournamentId]:r}}if(e){const s=Rd({tournamentRecords:t,schedulingProfile:e});if(s.error)return s}if(!e&&t){const s=za({tournamentRecords:t});if(s.error)return s;e=s.schedulingProfile}if(!e)return{error:sr};const o={};return{profileRounds:e.map(({venues:s,scheduleDate:a})=>s.map(({rounds:l})=>l.map(c=>{var u;const p=Vm(c);return(u=p.roundSegment)!=null&&u.segmentsCount&&(o[p.id]=p.roundSegment.segmentsCount),Oe(Vs({id:n?p.id:void 0,scheduleDate:a},p))}))).flat(1/0),segmentedRounds:o}}function Vm(t){const{containerStructureId:e,roundSegment:r,isRoundRobin:n,tournamentId:o,roundNumber:i,structureId:s,eventId:a,drawId:l}=t,c=n?e:s,u=[o,a,l,c,i].join("|");return Oe({id:u,roundSegment:r,tournamentId:o,eventId:a,drawId:l,structureId:c,roundNumber:i})}function Vw(t){const e=t.length,r=t.filter(({sides:u})=>u==null?void 0:u.some(({bye:p})=>p)).length||0,n=t.filter(({winningSide:u,matchUpStatus:p})=>u||Yt.includes(p)).length||0,o=t.filter(({schedule:u})=>(u==null?void 0:u.scheduledDate)&&(u==null?void 0:u.scheduledTime)).length||0,i=e-r,s=i===n,a=i-o,l=i-o;return{unscheduledCount:a,incompleteCount:l,scheduledCount:o,completedCount:n,matchUpsCount:e,isScheduled:i===o,isComplete:s,byeCount:r}}function Bw({excludeScheduleDateProfileRounds:t,excludeScheduledRounds:e,excludeCompletedRounds:r,inContextMatchUps:n,tournamentRecords:o,schedulingProfile:i,tournamentRecord:s,withSplitRounds:a,matchUpFilters:l,withRoundId:c,context:u}){var p;if(n&&!Array.isArray(n||typeof n[0]!="object"))return{error:X,inContextMatchUps:n};if(s&&!o){if(typeof s!="object")return{error:Yc};o={[s.tournamentId]:s}}const d=typeof o!="object"||!Object.keys(o).length;if((!n||!i&&(t||r||i||a))&&d)return{error:ke};const f=Object.values(o??{}).map(({events:y})=>y).flat(),{segmentedRounds:m,profileRounds:h}=o&&(t||r||i||a)&&Lm({tournamentRecords:o,schedulingProfile:i})||{},g=t&&Object.assign({},...h.map(y=>({[y.id]:y}))),_=n||o&&((p=Ro({tournamentRecords:o,matchUpFilters:l}))==null?void 0:p.matchUps)||[],I=[],P=_&&Object.values(_.reduce((y,S)=>{var O,b;const w=Vm(S).id,T=m==null?void 0:m[w],$=[...(b=(O=y[w])==null?void 0:O.matchUps)!=null?b:[],S],{containerStructureId:N,stageSequence:E,structureName:A,tournamentId:U,isRoundRobin:C,matchUpType:M,roundNumber:D,roundOffset:R,structureId:j,eventName:G,roundName:W,drawName:q,eventId:F,drawId:L}=S,x=C?N:j;return Bd(Vs({},y),{[w]:{id:c?w:void 0,structureId:x,stageSequence:E,segmentsCount:T,structureName:A,tournamentId:U,matchUpType:M,roundNumber:D,roundOffset:R,eventName:G,roundName:W,drawName:q,matchUps:$,eventId:F,drawId:L}})},{})).map(y=>{const{minFinishingSum:S,winnerFinishingPositionRange:O}=x9(y.matchUps),b=y.segmentsCount;if(b){const C=y.matchUps.length/b;return qt(y.matchUps.sort((D,R)=>D.roundPosition-R.roundPosition),C).map((D,R)=>{const{unscheduledCount:j,incompleteCount:G,matchUpsCount:W,isScheduled:q,isComplete:F,byeCount:L}=Vw(D),x=kw({matchUps:y.matchUps,tournamentRecords:o,events:f,round:y});return Oe(Bd(Vs(Vs({},y),u),{roundSegment:{segmentsCount:b,segmentNumber:R+1},winnerFinishingPositionRange:O,unscheduledCount:j,incompleteCount:G,minFinishingSum:S,matchUpsCount:W,isScheduled:q,roundTiming:x,isComplete:F,byeCount:L,matchUps:D}))})}const{unscheduledCount:w,incompleteCount:T,matchUpsCount:$,isScheduled:N,isComplete:E,byeCount:A}=Vw(y.matchUps),U=kw({matchUps:y.matchUps,tournamentRecords:o,events:f,round:y});return Oe(Bd(Vs(Vs({},y),u),{winnerFinishingPositionRange:O,unscheduledCount:w,incompleteCount:T,minFinishingSum:S,matchUpsCount:$,isScheduled:N,roundTiming:U,isComplete:E,byeCount:A}))}).flat().filter(y=>{if(t){const $=Re(t),N=c?y.id:Vm(y).id;if($&&g[N]&&Re(g[N].scheduleDate)===$)return!1}const{isComplete:S,isScheduled:O}=y,T=(!r||!S)&&(!e||!O);return T||I.push(y),T}).sort(F9)||[];return Bd(Vs({},V),{rounds:P,excludedRounds:I})}function kw({round:t,matchUps:e,events:r,tournamentRecords:n}){const o=r.find(d=>d.eventId===t.eventId),{eventType:i,category:s,categoryType:a}=o||{},{categoryName:l,ageCategoryCode:c}=s||{},u=Nr(e.map(({matchUpFormat:d})=>d));let p=0;return Object.keys(u).forEach(d=>{const v=u[d],f=Om({categoryName:l||c,tournamentId:t.tournamentId,eventId:t.eventId,tournamentRecords:n,matchUpFormat:d,categoryType:a,eventType:i});if(f.error)return f;const m=f.averageMinutes*v;isNaN(p)||(p+=m)}),{roundMinutes:p}}function F9(t,e){return t.eventName.localeCompare(e.eventName)||t.eventId.localeCompare(e.eventId)||(Lw[t==null?void 0:t.stage]||0)-(Lw[e==null?void 0:e.stage]||0)||e.matchUpsCount-t.matchUpsCount||`${t.stageSequence}-${t.roundNumber}-${t.minFinishingSum}`.localeCompare(`${e.stageSequence}-${e.roundNumber}-${e.minFinishingSum}`)}function x9(t){return(t||[]).reduce((e,r)=>{var n,o;const i=(((n=r.finishingPositionRange)==null?void 0:n.winner)||[]).reduce((a,l)=>a+l,0),s=(((o=r.finishingPositionRange)==null?void 0:o.winner)||[]).join("-")||"";return!e.minFinishingSum||i<e.minFinishingSum?{minFinishingSum:i,winnerFinishingPositionRange:s}:e},{minFinishingSum:0,winnerFinishingPositionRange:""})}function L9({tournamentRecords:t,courtAssignments:e,courtDayDate:r}){if(!t)return{error:ke};if(!Array.isArray(e))return{error:_e,info:or("courtAssignments")};const n=e.reduce((s,a)=>{const{tournamentId:l}=a;return s[l]||(s[l]=[]),s[l].push(a),s},{});let o;return Object.keys(n).every(s=>{const a=t[s];if(!a)return o={error:re},!1;const l=n[s].reduce((u,p)=>{const{drawId:d}=p;return u[d]||(u[d]=[]),u[d].push(p),u},{});Object.keys(l).every(u=>{const{drawDefinition:p}=Qt({tournamentRecord:a,drawId:u});return p?(l[u].every(d=>{const{matchUpId:v,courtId:f}=d,m=Ds({tournamentRecord:a,drawDefinition:p,courtDayDate:r,matchUpId:v,courtId:f});if(m.success)return m==null?void 0:m.success;o={error:Yx}}),!0):(o={error:ue},!1)})}),o||V}var V9=Object.defineProperty,B9=Object.defineProperties,k9=Object.getOwnPropertyDescriptors,Gw=Object.getOwnPropertySymbols,G9=Object.prototype.hasOwnProperty,W9=Object.prototype.propertyIsEnumerable,Ww=(t,e,r)=>e in t?V9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,H9=(t,e)=>{for(var r in e||(e={}))G9.call(e,r)&&Ww(t,r,e[r]);if(Gw)for(var r of Gw(e))W9.call(e,r)&&Ww(t,r,e[r]);return t},q9=(t,e)=>B9(t,k9(e));function z9({tournamentRecords:t,competitionMatchUps:e,matchUpDependencies:r,allDateMatchUpIds:n=[],averageMatchUpMinutes:o=90,recoveryMinutes:i=0,recoveryMinutesMap:s,matchUpPotentialParticipantIds:a={},individualParticipantProfiles:l={},matchUpNotBeforeTimes:c={},matchUpDailyLimits:u={},checkPotentialRequestConflicts:p=!0,remainingScheduleTimes:d,clearScheduleDates:v,periodLength:f=30,scheduleDate:m,matchUpIds:h,venueIds:g,startTime:_,endTime:I,dryRun:P}){if(!t)return{error:ke};if(!h)return{error:vl};if(!Gr(m))return{error:Sr};if(isNaN(f)||isNaN(o)||isNaN(i))return{error:X};e||({matchUps:e}=Ro({tournamentRecords:t,nextMatchUps:!0})),r||({matchUpDependencies:r}=cn({includeParticipantDependencies:!0,matchUps:e,tournamentRecords:t})),e.forEach(F=>{var L;(L=F.schedule)!=null&&L.scheduledDate&&io(m,Re(F.schedule.scheduledDate))&&Ya({matchUpPotentialParticipantIds:a,matchUpNotBeforeTimes:c,matchUp:F})});const y=h.map(F=>e.find(L=>L.matchUpId===F)).filter(Boolean),{venueId:S,scheduleTimes:O,dateScheduledMatchUpIds:b}=cw({tournamentRecords:t,remainingScheduleTimes:d,startTime:at(_),endTime:at(I),scheduleDate:Re(m),averageMatchUpMinutes:o,clearScheduleDates:v,periodLength:f,venueIds:g}),w={},T=[],$={},N={},E={};e.filter(({matchUpId:F})=>b==null?void 0:b.includes(F)).forEach(F=>{var L;Um({matchUpPotentialParticipantIds:a,individualParticipantProfiles:l,matchUp:F,value:1});const x=(L=F.schedule)==null?void 0:L.scheduledTime;if(x){$[F.matchUpId]=x;const B=s==null?void 0:s[F.matchUpId];wc({recoveryMinutes:B||i,matchUpPotentialParticipantIds:a,individualParticipantProfiles:l,matchUpNotBeforeTimes:c,averageMatchUpMinutes:o,matchUpDependencies:r,scheduleTime:x,matchUp:F})}});let U=y.filter(F=>{const L=b==null?void 0:b.includes(F.matchUpId),x=[nt,Xe,Mt,Wr,_r,ot].includes(F==null?void 0:F.matchUpStatus);return!L&&!F.winningSide&&!x});const{matchUpMap:C,overLimitMatchUpIds:M,participantIdsAtLimit:D}=U.reduce((F,L)=>{const{drawId:x,tournamentId:B,matchUpType:z}=L,{participantIdsAtLimit:H,relevantParticipantIds:Y}=Mm({individualParticipantProfiles:l,matchUpPotentialParticipantIds:a,matchUpDailyLimits:u,matchUp:L});return H!=null&&H.length?(F.overLimitMatchUpIds.push(L.matchUpId),F.participantIdsAtLimit.push(...H),F):(Y.forEach(Z=>{Tc({individualParticipantProfiles:l,participantId:Z});const K=l[Z].counters;K[z]?K[z]+=1:K[z]=1,K[Pn]?K[Pn]+=1:K[Pn]=1}),F.matchUpMap[B]||(F.matchUpMap[B]={}),F.matchUpMap[B][x]?F.matchUpMap[B][x].push(L):F.matchUpMap[B][x]=[L],Ya({matchUpPotentialParticipantIds:a,matchUpNotBeforeTimes:c,matchUp:L}),F)},{matchUpMap:{},overLimitMatchUpIds:[],participantIdsAtLimit:[]});U=U.filter(({matchUpId:F})=>!M.includes(F));let R=0;const j=(O==null?void 0:O.length)||0,{personRequests:G}=Ka({tournamentRecords:t,requestType:Vd});for(;O!=null&&O.length&&U.length&&R<=j;){R++;const{scheduleTime:F}=O.shift(),L=U.find(x=>{const{matchUpId:B}=x,{dependenciesScheduled:z,remainingDependencies:H}=$m({matchUpScheduleTimes:$,matchUpDependencies:r,allDateMatchUpIds:n,matchUp:x});if(!z)return E[B]||(E[B]=[]),E[B].push({scheduleTime:F,remainingDependencies:H}),!1;const{enoughTime:Y}=Cm({individualParticipantProfiles:l,matchUpNotBeforeTimes:c,matchUpDependencies:r,scheduleTime:F,matchUp:x});if(!Y)return N[B]||(N[B]=[]),N[B].push({scheduleTime:F}),!1;const{conflicts:Z}=Nm({potentials:p,averageMatchUpMinutes:o,requestConflicts:w,personRequests:G,scheduleTime:F,scheduleDate:m,matchUp:x});if(Z!=null&&Z.length)return!1;const K=s==null?void 0:s[x.matchUpId];return wc({recoveryMinutes:K||i,matchUpPotentialParticipantIds:a,individualParticipantProfiles:l,matchUpNotBeforeTimes:c,averageMatchUpMinutes:o,matchUpDependencies:r,scheduleTime:F,matchUp:x}),$[x.matchUpId]=F,!0});U=U.filter(({matchUpId:x})=>x!==(L==null?void 0:L.matchUpId)),L||T.push(F)}U.forEach(F=>{Um({individualParticipantProfiles:l,matchUpPotentialParticipantIds:a,value:-1,matchUp:F})});const W=[];Object.keys(C).forEach(F=>{const L=t[F];L?Object.keys(C[F]).forEach(x=>{const{drawDefinition:B}=Jo({tournamentRecord:L,drawId:x});B&&C[F][x].forEach(({matchUpId:H})=>{const Y=$[H];if(Y){const Z=Y.split(":").map(oo).join(":"),K=`${Re(m)}T${Z}`;P?W.push(H):(Gi({drawDefinition:B,matchUpId:H,scheduledTime:K}).success&&W.push(H),S&&ja({tournamentRecords:t,tournamentRecord:L,drawDefinition:B,matchUpId:H,venueId:S}))}})}):zt()&&console.log(yo)});const q=gv(U);return q9(H9({},V),{requestConflicts:Object.values(w),remainingScheduleTimes:O==null?void 0:O.map(({scheduleTime:F})=>F),individualParticipantProfiles:l,matchUpNotBeforeTimes:c,participantIdsAtLimit:D,skippedScheduleTimes:T,overLimitMatchUpIds:M,scheduledMatchUpIds:W,noTimeMatchUpIds:q,recoveryTimeDeferred:N,dependencyDeferred:E})}var Y9=Object.defineProperty,Hw=Object.getOwnPropertySymbols,K9=Object.prototype.hasOwnProperty,Q9=Object.prototype.propertyIsEnumerable,qw=(t,e,r)=>e in t?Y9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,J9=(t,e)=>{for(var r in e||(e={}))K9.call(e,r)&&qw(t,r,e[r]);if(Hw)for(var r of Hw(e))Q9.call(e,r)&&qw(t,r,e[r]);return t};function Z9(t){const e="reorderUpcomingMatchUps",{tournamentRecords:r}=t;if(typeof r!="object"||!Object.keys(r).length)return k({result:{error:ke},stack:e});const{matchUpsContextIds:n,firstToLast:o}=t;if(!n)return k({result:{error:_e},stack:e});const i=n==null?void 0:n.length;if(!i)return J9({},V);let s=0;return n.forEach((l,c)=>{const{tournamentId:u,drawId:p,matchUpId:d}=l;let v=c+(o?-1:1);v<0&&(v=i-1),v===i&&(v=0);const f=n[v].schedule.scheduledTime,m=a({tournamentId:u,scheduledTime:f,matchUpId:d,drawId:p});if(m.success)s++;else return m}),s===i?V:k({result:{error:zx},stack:e});function a({tournamentId:l,scheduledTime:c,matchUpId:u,drawId:p}){const d=r[l],{drawDefinition:v}=Jo({tournamentRecord:d,drawId:p});return Gi({drawDefinition:v,scheduledTime:c,matchUpId:u})}}var X9=Object.defineProperty,eQ=Object.defineProperties,tQ=Object.getOwnPropertyDescriptors,zw=Object.getOwnPropertySymbols,rQ=Object.prototype.hasOwnProperty,nQ=Object.prototype.propertyIsEnumerable,Yw=(t,e,r)=>e in t?X9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kw=(t,e)=>{for(var r in e||(e={}))rQ.call(e,r)&&Yw(t,r,e[r]);if(zw)for(var r of zw(e))nQ.call(e,r)&&Yw(t,r,e[r]);return t},Qw=(t,e)=>eQ(t,tQ(e));function oQ({scheduleCompletedMatchUps:t,tournamentRecords:e,scheduledDate:r,matchUps:n}){if(!Array.isArray(n))return{error:X};if(n.some(({hasContext:m})=>!m))return{info:"matchUps must have { inContext: true, nextMatchUps: true }",error:ru};let i=Em({courtCompletedMatchUps:!0,withCourtGridRows:!0,minCourtGridRows:10,tournamentRecords:e,matchUpFilters:{localPerspective:!0,scheduledDate:r}});if(i.error)return i;const{rows:s}=i,a=[],l=m=>[(m.sides||[]).map(h=>{var g;return[h.participantId,(g=h.participant)==null?void 0:g.individualParticipantIds]}),(m.potentialParticipants||[]).flat().map(h=>[h.participantId,h.individualParticipantIds])].flat(1/0).filter(Boolean),c=s==null?void 0:s.reduce((m,h)=>{const g=[],_=[];Object.values(h).forEach(P=>{if(rs(P)&&(P.matchUpId&&(g.push(P.matchUpId),a.push(P)),P.sides)){const y=l(P);_.push(...y)}});const I=Object.values(h).filter(P=>rs(P)&&!P.matchUpId);return m.concat({matchUpIds:g,availableCourts:I,rowId:h.rowId,participantIds:_})},[]);n.filter(({matchUpStatus:m})=>m&&m!==ut.Bye&&(t||!Yt.includes(m))).sort(Cs);const u=cn({matchUps:n.concat(a),includeParticipantDependencies:!0,tournamentRecords:e}).matchUpDependencies,p=[],d=[];for(;n.length&&c.length;){const m=c.shift(),h=[];for(;n.length&&m.availableCourts.length;){const g=n.concat(h).map(T=>T.matchUpId),_=n.shift(),I=_==null?void 0:_.matchUpId,P=I&&u[I].matchUpIds.concat(u[I].dependentMatchUpIds),y=I&&g.some(T=>u[I].matchUpIds.includes(T)),S=I&&d.some(T=>u[I].dependentMatchUpIds.includes(T)),O=m.matchUpIds.some(T=>P.includes(T)),b=l(_),w=m.participantIds.some(T=>b.includes(T));if(_&&!O&&!y&&!w&&!S){const T=m.availableCourts.shift();Object.assign(_.schedule,T.schedule),Object.assign(T,_),p.push(_),m.participantIds.push(...b),m.matchUpIds.push(I)}else _&&h.push(_)}n.push(...h),d.push(...m.matchUpIds)}const v=p.map(({matchUpId:m,tournamentId:h,schedule:g,drawId:_})=>({tournamentId:h,matchUpId:m,drawId:_,schedule:Qw(Kw({},g),{scheduledDate:r})}));i=LS({tournamentRecords:e,matchUpDetails:v});const f=n;return Qw(Kw({},i),{scheduled:p,notScheduled:f})}var iQ=Object.defineProperty,sQ=Object.defineProperties,aQ=Object.getOwnPropertyDescriptors,Jw=Object.getOwnPropertySymbols,lQ=Object.prototype.hasOwnProperty,cQ=Object.prototype.propertyIsEnumerable,Zw=(t,e,r)=>e in t?iQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xw=(t,e)=>{for(var r in e||(e={}))lQ.call(e,r)&&Zw(t,r,e[r]);if(Jw)for(var r of Jw(e))cQ.call(e,r)&&Zw(t,r,e[r]);return t},eE=(t,e)=>sQ(t,aQ(e));function uQ(t){const e="matchUpScheduleChange",{tournamentRecords:r}=t;if(typeof r!="object"||!Object.keys(r).length)return{error:ke};const{sourceMatchUpContextIds:n,targetMatchUpContextIds:o,sourceCourtId:i,targetCourtId:s,courtDayDate:a}=t||{},{drawId:l,matchUpId:c,tournamentId:u}=n||{},{drawId:p,matchUpId:d,tournamentId:v}=o||{};if(!c&&!d)return k({result:{error:_e},stack:e});const{matchUps:f}=Ro({matchUpFilters:{matchUpIds:[c,d].filter(Boolean),drawIds:[l,p].filter(Boolean)},tournamentRecords:t.tournamentRecords}),m=f==null?void 0:f.find(({matchUpId:y})=>y===c),h=f==null?void 0:f.find(({matchUpId:y})=>y===d);let g=0;if(s&&c&&!d){const y=_({tournamentId:u,matchUpId:c,courtId:s,matchUp:m,drawId:l,tournamentRecords:r,sourceCourtId:i,courtDayDate:a});if(y!=null&&y.success&&g++,y.error)return k({result:y,stack:e})}else if(i&&s&&c&&d){const y=_({tournamentId:u,matchUpId:c,courtId:s,matchUp:m,drawId:l,tournamentRecords:r,sourceCourtId:i,courtDayDate:a});if(y.success&&g++,y.error)return k({result:y,stack:e,info:"source"});const S=_({tournamentId:v,sourceCourtId:s,matchUpId:d,matchUp:h,courtId:i,drawId:p,tournamentRecords:r,courtDayDate:a});if(S.success&&g++,S.error)return k({result:S,stack:e,info:"target"})}else return{error:_e};return g?V:k({result:{error:hl},stack:e});function _(y){const{tournamentRecords:S,tournamentId:O,matchUp:b,drawId:w}=y,T=S[O],{drawDefinition:$}=Jo({tournamentRecord:T,drawId:w});return b.matchUpType===Qe?I(eE(Xw({},y),{tournamentRecord:T,drawDefinition:$})):P(eE(Xw({},y),{tournamentRecord:T,drawDefinition:$}))}function I({removePriorValues:y,tournamentRecords:S,tournamentRecord:O,drawDefinition:b,sourceCourtId:w,courtDayDate:T,matchUpId:$,matchUp:N,courtId:E}){const A=[E].concat(N.schedule.allocatedCourts.map(({courtId:U})=>U).filter(U=>U!==w));return ud({removePriorValues:y,tournamentRecords:S,tournamentRecord:O,drawDefinition:b,courtDayDate:T,matchUpId:$,courtIds:A})}function P({tournamentRecords:y,tournamentRecord:S,drawDefinition:O,courtDayDate:b,matchUpId:w,courtId:T}){return Ds({tournamentRecords:y,tournamentRecord:S,drawDefinition:O,courtDayDate:b,matchUpId:w,courtId:T})}}var dQ=Object.defineProperty,pQ=Object.defineProperties,fQ=Object.getOwnPropertyDescriptors,tE=Object.getOwnPropertySymbols,vQ=Object.prototype.hasOwnProperty,mQ=Object.prototype.propertyIsEnumerable,rE=(t,e,r)=>e in t?dQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hQ=(t,e)=>{for(var r in e||(e={}))vQ.call(e,r)&&rE(t,r,e[r]);if(tE)for(var r of tE(e))mQ.call(e,r)&&rE(t,r,e[r]);return t},gQ=(t,e)=>pQ(t,fQ(e));function _Q(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;return Xb(gQ(hQ({},t),{tournamentRecord:r,drawDefinition:n}))}function IQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;if(!n)return{error:ue};const{disableNotice:o,scheduledDate:i,matchUpId:s,removePriorValues:a}=t;return Im({removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:o,scheduledDate:i,matchUpId:s})}function PQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,scheduledTime:i,matchUpId:s,removePriorValues:a}=t;return n?Pm({removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:o,scheduledTime:i,matchUpId:s}):{error:ue}}function yQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,startTime:i,matchUpId:s}=t;return eT({tournamentRecord:r,drawDefinition:n,disableNotice:o,startTime:i,matchUpId:s})}function SQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,endTime:i,matchUpId:s}=t;return tT({tournamentRecord:r,drawDefinition:n,disableNotice:o,endTime:i,matchUpId:s})}function OQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,stopTime:i,matchUpId:s}=t;return rT({tournamentRecord:r,drawDefinition:n,disableNotice:o,stopTime:i,matchUpId:s})}function bQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,resumeTime:i,matchUpId:s}=t;return nT({tournamentRecord:r,drawDefinition:n,disableNotice:o,resumeTime:i,matchUpId:s})}function TQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,participantId:i,officialType:s,matchUpId:a}=t;return oT({tournamentRecord:r,drawDefinition:n,disableNotice:o,participantId:i,officialType:s,matchUpId:a})}function wQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{matchUpId:o,venueId:i,disableNotice:s,removePriorValues:a}=t;return n?ja({tournamentRecords:t.tournamentRecords,removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:s,matchUpId:o,venueId:i}):{error:ue}}function EQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;if(!r)return{error:re};if(!n)return{error:ue};const{removePriorValues:o,tournamentRecords:i,disableNotice:s,courtDayDate:a,matchUpId:l,courtId:c}=t;return Ds({removePriorValues:o,tournamentRecords:i,tournamentRecord:r,drawDefinition:n,disableNotice:s,courtDayDate:a,matchUpId:l,courtId:c})}function $Q(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;if(!n)return{error:ue};const{removePriorValues:o,tournamentRecords:i,disableNotice:s,courtDayDate:a,matchUpId:l,courtIds:c}=t;return ud({removePriorValues:o,tournamentRecords:i,tournamentRecord:r,drawDefinition:n,disableNotice:s,courtDayDate:a,matchUpId:l,courtIds:c})}function NQ(t){const e=Xn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{removePriorValues:o,disableNotice:i,courtOrder:s,matchUpId:a}=t;return g7({removePriorValues:o,tournamentRecord:r,drawDefinition:n,disableNotice:i,courtOrder:s,matchUpId:a})}function Xn({tournamentRecords:t,tournamentId:e,drawId:r}){if(!t)return{error:ke};if(!r)return{error:kr};if(typeof e!="string"&&(e=Xv({tournamentRecords:t,drawId:r}),!e))return{error:yo};const n=t[e];if(!n)return{error:re};const o=Qt({tournamentRecord:n,drawId:r});return o.error?k({stack:"addScheduleItems.getDrawDefinition",result:o}):{drawDefinition:o.drawDefinition,tournamentRecord:n}}const UQ={scheduleMatchUps:z9,scheduleProfileRounds:Rm,clearScheduledMatchUps:Aw,bulkRescheduleMatchUps:A7,getScheduledRoundsDetails:bm,getMatchUpDependencies:cn,generateVirtualCourts:Lv,generateBookings:Am,proAutoSchedule:oQ,proConflicts:Z0,matchUpScheduleChange:uQ,calculateScheduleTimes:cw,reorderUpcomingMatchUps:Z9,bulkUpdateCourtAssignments:L9,removeMatchUpCourtAssignment:Rw,toggleParticipantCheckInState:U9,findMatchUpFormatTiming:Om,modifyMatchUpFormatTiming:r8,modifyEventMatchUpFormatTiming:FY,getMatchUpFormatTimingUpdate:kK,getEventMatchUpFormatTiming:QK,removeEventMatchUpFormatTiming:$9,getMatchUpDailyLimitsUpdate:A9,getMatchUpDailyLimits:Mw,setMatchUpDailyLimits:R7,getProfileRounds:Lm,getRounds:Bw,assignMatchUpVenue:wQ,assignMatchUpCourt:EQ,allocateTeamMatchUpCourts:$Q,addMatchUpScheduleItems:_Q,addMatchUpScheduledDate:IQ,addMatchUpScheduledTime:PQ,addMatchUpCourtOrder:NQ,addMatchUpStartTime:yQ,addMatchUpStopTime:OQ,addMatchUpResumeTime:bQ,addMatchUpEndTime:SQ,addMatchUpOfficial:TQ,getSchedulingProfile:za,setSchedulingProfile:bc,addSchedulingProfileRound:nw,validateSchedulingProfile:Rd,addPersonRequests:v9,getPersonRequests:Ka,modifyPersonRequests:h9,removePersonRequests:m9};var AQ=Object.defineProperty,CQ=Object.defineProperties,MQ=Object.getOwnPropertyDescriptors,nE=Object.getOwnPropertySymbols,DQ=Object.prototype.hasOwnProperty,jQ=Object.prototype.propertyIsEnumerable,oE=(t,e,r)=>e in t?AQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,RQ=(t,e)=>{for(var r in e||(e={}))DQ.call(e,r)&&oE(t,r,e[r]);if(nE)for(var r of nE(e))jQ.call(e,r)&&oE(t,r,e[r]);return t},FQ=(t,e)=>CQ(t,MQ(e));function Bm({tournamentRecord:t,policyDefinitions:e,allowReplacement:r}){var n;if(!t)return{error:re};if(!e||typeof e!="object")return{error:Xc};t.extensions||(t.extensions=[]);const o=(n=pt({tournamentRecord:t}).appliedPolicies)!=null?n:{},i=Object.keys(e).map(s=>{if(!o[s]||r)return o[s]=e[s],s}).filter(Boolean);if(i!=null&&i.length){const a=Ei({tournamentRecord:t,extension:{name:os,value:o}});if(a.error)return a}return i!=null&&i.length?FQ(RQ({},V),{applied:i}):{error:t_}}function iE({policyDefinitions:t,allowReplacement:e,event:r}){var n;if(!r)return{error:Ge};if(!t)return{error:Xc};let o=0;r.extensions||(r.extensions=[]);const i=(n=pt({event:r}).appliedPolicies)!=null?n:{};return Object.keys(t).forEach(s=>{(!i[s]||e)&&(i[s]=t[s],o++)}),o&&ao({event:r,extension:{name:os,value:i}}),o?V:{error:gx}}function xQ({event:t,policyType:e}){if(!e)return{error:_e};if(!t)return{error:Ge};let r;if(t.extensions){const{appliedPolicies:n}=pt({event:t});n!=null&&n[e]&&(delete n[e],r=!0,Object.keys(n).length?ao({event:t,extension:{name:os,value:n}}):Ou({event:t,name:os}))}return r?V:{error:nf}}var LQ=Object.defineProperty,sE=Object.getOwnPropertySymbols,VQ=Object.prototype.hasOwnProperty,BQ=Object.prototype.propertyIsEnumerable,aE=(t,e,r)=>e in t?LQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,kQ=(t,e)=>{for(var r in e||(e={}))VQ.call(e,r)&&aE(t,r,e[r]);if(sE)for(var r of sE(e))BQ.call(e,r)&&aE(t,r,e[r]);return t};function GQ({tournamentRecords:t,policyDefinitions:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:ke};for(const r of Object.values(t)){const n=Bm({allowReplacement:!0,tournamentRecord:r,policyDefinitions:e});if(n.error)return n}return kQ({},V)}const WQ={attachPolicies:GQ};var HQ=Object.defineProperty,qQ=Object.defineProperties,zQ=Object.getOwnPropertyDescriptors,lE=Object.getOwnPropertySymbols,YQ=Object.prototype.hasOwnProperty,KQ=Object.prototype.propertyIsEnumerable,cE=(t,e,r)=>e in t?HQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,km=(t,e)=>{for(var r in e||(e={}))YQ.call(e,r)&&cE(t,r,e[r]);if(lE)for(var r of lE(e))KQ.call(e,r)&&cE(t,r,e[r]);return t},uE=(t,e)=>qQ(t,zQ(e));function QQ({tournamentRecords:t,policyDefinitions:e,scaleAttributes:r,participantId:n,inContext:o,personId:i}){let s=ET({tournamentRecords:t,policyDefinitions:e,participantId:n,inContext:o,personId:i});if(s.error)return s;const{participant:a,tournamentId:l}=s;return s=go({participant:a,scaleAttributes:r}),s.error?uE(km({},s),{tournamentId:l}):km(uE(km({},V),{tournamentId:l}),s)}var JQ=Object.defineProperty,dE=Object.getOwnPropertySymbols,ZQ=Object.prototype.hasOwnProperty,XQ=Object.prototype.propertyIsEnumerable,pE=(t,e,r)=>e in t?JQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fE=(t,e)=>{for(var r in e||(e={}))ZQ.call(e,r)&&pE(t,r,e[r]);if(dE)for(var r of dE(e))XQ.call(e,r)&&pE(t,r,e[r]);return t};function eJ(t){const{scheduleDates:e=[],tournamentRecords:r,periodLength:n=30}=t||{};if(typeof r!="object")return{error:Yc};if(!Array.isArray(e))return{error:X};if(!e.every(Gr))return{error:Sr};const i=[];let s=0;const a={},{schedulingProfile:l}=za({tournamentRecords:r});if(!l)return fE({issues:i},V);const{matchUps:c}=Ro({nextMatchUps:!0,tournamentRecords:r});for(const p of l){const{scheduleDate:d,venues:v=[]}=p;if(!(e!=null&&e.length)||e.includes(d)){for(const f of v||[])if(f){const{rounds:m}=f,h=[],{orderedMatchUpIds:g,scheduledRoundsDetails:_}=bm({tournamentRecords:r,periodLength:n,matchUps:c,rounds:m}),{matchUpDependencies:I}=cn({tournamentRecords:r,matchUps:c}),P=y=>{let S;return _==null||_.find((O,b)=>{const w=O.matchUpIds.includes(y);return w&&(S=b),w}),S};if(g==null||g.forEach((y,S)=>{var O;const b=g.slice(S+1),w=Ht(b,((O=I==null?void 0:I[y])==null?void 0:O.matchUpIds)||[]);w.length&&h.push({matchUpId:y,shouldBeAfter:w})}),h.length){s+=h.length;const y=h.map(({matchUpId:S,shouldBeAfter:O})=>{const b=P(S),w=We(O.map(P));return a[d]||(a[d]={}),a[d][b]||(a[d][b]=[]),w.forEach(T=>{a[d][b].includes(T)||a[d][b].push(T)}),{matchUpId:S,matchUpRoundIndex:b,earlierRoundIndices:w,shouldBeAfter:O}});i.push(...y)}}}}const u={matchUpIdShouldBeAfter:Object.assign({},...i.map(p=>{const{matchUpId:d,shouldBeAfter:v,earlierRoundIndices:f}=p;return{[d]:{earlierRoundIndices:f,shouldBeAfter:v}}}))};return fE({issuesCount:s,profileIssues:u,roundIndexShouldBeAfter:a},V)}function kd(){return`
8
8
  This project would not have been possible without the generous input and patience
9
9
  of tournament organizers and directors who worked with early versions of CourtHive/TMX.
10
10
 
@@ -29,4 +29,4 @@
29
29
  <path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path>
30
30
  </svg>
31
31
  </div>
32
- `}function wR({eventHandlers:t,sideContainer:e,composition:r,sideNumber:n,matchUp:o,participant:i}){var w,T,$,N;const{winningSide:s,matchUpType:a,isRoundRobin:l,matchUpStatus:c}=o||{},u=r==null?void 0:r.configuration;let p;const d=n?(w=o==null?void 0:o.sides)==null?void 0:w.find(E=>E.sideNumber===n):void 0;i||(i=d==null?void 0:d.participant,p=u!=null&&u.allDrawPositions||u!=null&&u.drawPositions&&(d!=null&&d.drawPosition)&&((o==null?void 0:o.roundNumber)===1||d!=null&&d.participantFed||l)?d==null?void 0:d.drawPosition:"");const v=((T=i==null?void 0:i.individualParticipants)==null?void 0:T.length)===2||a==="DOUBLES",f=v?($=i==null?void 0:i.individualParticipants)==null?void 0:$[0]:i,m=v&&((N=i==null?void 0:i.individualParticipants)==null?void 0:N[1]),h=n===s||c==="BYE"&&i,g=(u==null?void 0:u.winnerChevron)&&h,_=u==null?void 0:u.teamLogo,I=["RETIRED","DOUBLE_WALKOVER","WALKOVER","DEFAULTED"].includes(c)&&!h,P=u==null?void 0:u.gameScoreOnly,y=document.createElement("div");if(y.className=e&&bF({drawPosition:p,sideNumber:n}),_){const E=e0e({teamLogo:_});y.appendChild(E)}const S=document.createElement("div");S.className=OF({variant:v?"doubles":"singles"});const O=document.createElement("div");O.className=TF({winnerChevron:g,isDoubles:v});const b=TR({individualParticipant:f,eventHandlers:t,isWinningSide:h,composition:r,matchUp:o,side:d});if(O.appendChild(b),m){const E=TR({individualParticipant:m,eventHandlers:t,isWinningSide:h,composition:r,matchUp:o,side:d});O.appendChild(E)}if(S.appendChild(O),y.appendChild(S),e){const E=document.createElement("div");if(h&&!P){const A=o0e();typeof A=="string"?E.innerHTML=A:E.appendChild(A)}else if(I){const A=Zye({matchUpStatus:c});E.appendChild(A)}y.appendChild(E)}return y}const i0e=Ke({marginInlineStart:"1rem",overflowX:"auto",display:"flex"}),s0e=Ke({paddingTop:"1em",marginTop:".5em",borderTop:"solid 1px black",height:"1em",width:"100%",variants:{variant:{0:{marginTop:"1em",borderTop:"none",paddingTop:"0px"}}}}),a0e=Ke({flexDirection:"column",display:"flex"}),l0e=Ke({borderBottom:"solid 1px black",marginInlineStart:"16px",marginInlineEnd:"16px",width:"460px",height:"1em"});function c0e({eventHandlers:t,roundProfile:e,roundNumber:r}){var i;const n=document.createElement("div");n.className=l0e(),n.onclick=t==null?void 0:t.roundHeaderClick;const o=(i=e==null?void 0:e[r])==null?void 0:i.roundName;return n.innerHTML=o||"",n}const u0e=Ke({justifyContent:"space-around",marginInlineStart:"16px",marginInlineEnd:"16px",flexDirection:"column",height:"100%",display:"flex",width:"460px"}),ER=Ke({width:"$score$setWidth",display:"inline-block",fontSize:9,variants:{variant:{set:{textAlign:"center"},points:{marginInlineEnd:3}}}}),d0e=Ke({transform:"translateY(-50%)",textTransform:"uppercase",backgroundColor:"#fff",position:"absolute",textAlign:"center",top:"calc(50%)",color:"#bbb",fontSize:0,right:4});function p0e(){return Ke({backgroundColor:"magenta",position:"absolute",opacity:"0.2",height:"100%",width:"100%",top:0})}const f0e=Ke({});function v0e({configuration:t}){const e={backgroundColor:"$matchUpBackgroundColor",WebkitTransition:"all 0.30s linear",boxShadow:"$matchUp$boxShadow",transition:"all 0.30s linear",border:"solid $border",marginBottom:"$space$1",marginTop:"$space$1",position:"relative",display:"grid",width:"100%",borderInlineStartWidth:"$borderWidths$borderInlineStart"};if(t!=null&&t.matchUpHover){const r=typeof t.matchUpHover=="string"?t.matchUpHover:"cyan";e["&:hover"]={backgroundColor:r}}else e["&:hover"]={borderColor:"$borderHover"};return Ke(e)}function m0e({variant:t}){return Ke({borderBottom:"solid 1px lightgray",backgroundColor:"$matchUp",position:"relative",width:"100%",height:"$lineHeights$centerInfo",variants:{variant:{1:{borderBottom:"solid 1px black"},2:{borderBottom:"solid 1px lightgray"}}}})({variant:t})}const h0e=Ke({justifyContent:"center",alignContent:"center",flexDirection:"column",height:"100%",display:"flex"}),g0e=Ke({fontFamily:"Lato,Arial,Helvetica,sans-serif",WebkitFontSmooting:"antialiased",marginInlineStart:"calc(20%)",WebkitBoxOrient:"horizontal",WebKitBoxDirection:"normal",WebkitBoxPack:"center",boxSizing:"inherit",flexDirection:"row",display:"flex"}),$R=Ke({alignContent:"center",boxSizing:"inherit",fontFamily:"Lato",fontWeight:900,fontSize:9});function _0e({eventHandlers:t,entryStatus:e,sideNumber:r,className:n}){const o=document.createElement("div");o.onclick=t==null?void 0:t.centerInfoClick,o.className=Zi(m0e({variant:r}),n);const i=document.createElement("div");i.className=h0e();const s=document.createElement("div");s.className=g0e();const a=document.createElement("div");a.className=$R(),a.innerHTML=e?"Entry status:&nbsp;":"",s.appendChild(a);const l=document.createElement("div");return l.className=$R(),l.innerHTML=e||"",s.appendChild(l),i.appendChild(s),o.appendChild(i),o}const Gc={scheduleInfo:1.8,centerInfo:1.5,gameScore:2};function I0e({composition:t,isDoubles:e,roundFactor:r=1}){const n=parseInt(window.getComputedStyle(document.body).getPropertyValue("font-size")),o=(t==null?void 0:t.configuration)||{},i=(o==null?void 0:o.connectorWidth)||16,s=o.centerInfo?Gc.centerInfo*n:0,a=o.scheduleInfo?Gc.scheduleInfo*n:0,c=(60+(o.showAddress?n:0))*(e?1.3:1)+s,u=c*r,p=(c+a)*r;return Ke({"&::before":{borderBlockStart:"$borderWidths$matchUp solid #999",left:-i,width:i,position:"absolute",borderRadius:2,top:-1},"&::after":{width:i,position:"absolute",borderRadius:2,left:"100%"},"&::after, &::before":{borderWidth:"$borderWidths$matchUp",borderColor:"$connector",display:"block",content:""},variants:{isFirstRound:{true:{"&::before":{height:0,width:0,borderWidth:0}}},link:{m1:{"&::after":{borderInlineEnd:"$borderWidths$matchUp solid $connector",borderTopStyle:"solid",height:u,top:-1}},m2:{"&::after":{bottom:"calc(100%)",borderInlineEnd:"$borderWidths$matchUp solid $connector",borderBottomStyle:"solid",height:p}},m0:{"&::after":{borderTopStyle:"solid",borderColor:"$connector",top:-1}},mr:{"&::before":{height:0,width:0,borderWidth:0},"&::after":{height:0,width:0,borderWidth:0}},noProgression:{true:{"&::after":{height:0,width:0,borderWidth:0}}}}}})}const NR=t=>Ke({display:"flex",alignItems:"center",height:t,justifyContent:"flex-end",backgroundColor:"$matchUp",variants:{sideNumber:{1:{borderBottom:"1px solid $internalDividers"}},fontSize:{small:{fontSize:"smaller",paddingRight:"1em",color:"blue"}}}}),P0e=Ke({letterSpacing:"-0.2em",lineHeight:"0.75rem",position:"absolute",fontSize:"0.625rem",left:"1.1rem",top:".4rem"}),UR=Ke({lineHeight:"$lineHeights$gameScore",justifyContent:"center",width:"$score$setWidth",position:"relative",textAlign:"center",cursor:"pointer",fontWeight:500,fontSize:"$1",display:"flex",margin:0,variants:{variant:{winner:{color:"$winner!important",fontWeight:700},loser:{color:"$loser!important"}}}}),y0e=Ke({marginInlineEnd:"$space$gameMarginInlineEnd",justifyContent:"flex-end",alignItems:"center",display:"flex"});function S0e({value:t}={}){const e=document.createElement("input");return e.onclick=r=>r.target.select(),e.className=UR(),e.value=t,e}function O0e({gameScoreOnly:t,scoreStripes:e,set:r,sideNumber:n}){const i=n===(r==null?void 0:r.winningSide)||r!=null&&r.winningSide?"loser":void 0,s=n===2?r.side2Score:r.side1Score,a=n===2?r.side2TiebreakScore:r.side1TiebreakScore,l=s===void 0&&a,c=l||s,u=e&&r.setNumber%2?"lightgray":"transparent",d=r.editing?r.editing===n:void 0;let v;if(d)v=S0e({value:c});else if(v=document.createElement("p"),v.className=UR({variant:i}),v.style.backgroundColor=u,v.innerHTML=isNaN(c)?"":c,!t){const f=document.createElement("span");f.className=P0e(),f.innerHTML=l?a:"",v.appendChild(f)}return v}function b0e({participantHeight:t,eventHandlers:e,composition:r,sideNumber:n,matchUp:o}){var f,m,h,g;const i=(f=r==null?void 0:r.configuration)==null?void 0:f.winnerChevron,s=(m=r==null?void 0:r.configuration)==null?void 0:m.gameScoreOnly,a=((h=o==null?void 0:o.score)==null?void 0:h.sets)||[],l=(g=r==null?void 0:r.configuration)==null?void 0:g.scoreBox,c=n===2?t:t-1,u=NR(c),p=_=>{typeof(e==null?void 0:e.scoreClick)=="function"&&(_.stopPropagation(),e.scoreClick({event:_,matchUp:o}))},d=document.createElement("div");d.className=u({sideNumber:!l&&n,fontSize:"5px"}),d.classList.add("sideScore"),d.onclick=p;const v=document.createElement("div");v.className=y0e();for(const _ of a||[]){const I=O0e({gameScoreOnly:s,scoreStripes:i,sideNumber:n,set:_});v.appendChild(I)}return d.appendChild(v),d}const T0e=Ke({height:"$lineHeights$scheduleInfo",borderBottom:"1px solid darkgray",justifyContent:"space-between",backgroundColor:"#F8F9F9",boxSizing:"border-box",paddingRight:"0.5rem",paddingLeft:"0.5rem",alignItems:"center",cursor:"pointer",color:"#7F8080",display:"flex",width:"100%"});var AR={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(NF,function(){var r=1e3,n=6e4,o=36e5,i="millisecond",s="second",a="minute",l="hour",c="day",u="week",p="month",d="quarter",v="year",f="date",m="Invalid Date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,_={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(E){var A=["th","st","nd","rd"],U=E%100;return"["+E+(A[(U-20)%10]||A[U]||A[0])+"]"}},I=function(E,A,U){var C=String(E);return!C||C.length>=A?E:""+Array(A+1-C.length).join(U)+E},P={s:I,z:function(E){var A=-E.utcOffset(),U=Math.abs(A),C=Math.floor(U/60),M=U%60;return(A<=0?"+":"-")+I(C,2,"0")+":"+I(M,2,"0")},m:function E(A,U){if(A.date()<U.date())return-E(U,A);var C=12*(U.year()-A.year())+(U.month()-A.month()),M=A.clone().add(C,p),D=U-M<0,R=A.clone().add(C+(D?-1:1),p);return+(-(C+(U-M)/(D?M-R:R-M))||0)},a:function(E){return E<0?Math.ceil(E)||0:Math.floor(E)},p:function(E){return{M:p,y:v,w:u,d:c,D:f,h:l,m:a,s,ms:i,Q:d}[E]||String(E||"").toLowerCase().replace(/s$/,"")},u:function(E){return E===void 0}},y="en",S={};S[y]=_;var O=function(E){return E instanceof $},b=function E(A,U,C){var M;if(!A)return y;if(typeof A=="string"){var D=A.toLowerCase();S[D]&&(M=D),U&&(S[D]=U,M=D);var R=A.split("-");if(!M&&R.length>1)return E(R[0])}else{var j=A.name;S[j]=A,M=j}return!C&&M&&(y=M),M||!C&&y},w=function(E,A){if(O(E))return E.clone();var U=typeof A=="object"?A:{};return U.date=E,U.args=arguments,new $(U)},T=P;T.l=b,T.i=O,T.w=function(E,A){return w(E,{locale:A.$L,utc:A.$u,x:A.$x,$offset:A.$offset})};var $=function(){function E(U){this.$L=b(U.locale,null,!0),this.parse(U)}var A=E.prototype;return A.parse=function(U){this.$d=function(C){var M=C.date,D=C.utc;if(M===null)return new Date(NaN);if(T.u(M))return new Date;if(M instanceof Date)return new Date(M);if(typeof M=="string"&&!/Z$/i.test(M)){var R=M.match(h);if(R){var j=R[2]-1||0,G=(R[7]||"0").substring(0,3);return D?new Date(Date.UTC(R[1],j,R[3]||1,R[4]||0,R[5]||0,R[6]||0,G)):new Date(R[1],j,R[3]||1,R[4]||0,R[5]||0,R[6]||0,G)}}return new Date(M)}(U),this.$x=U.x||{},this.init()},A.init=function(){var U=this.$d;this.$y=U.getFullYear(),this.$M=U.getMonth(),this.$D=U.getDate(),this.$W=U.getDay(),this.$H=U.getHours(),this.$m=U.getMinutes(),this.$s=U.getSeconds(),this.$ms=U.getMilliseconds()},A.$utils=function(){return T},A.isValid=function(){return this.$d.toString()!==m},A.isSame=function(U,C){var M=w(U);return this.startOf(C)<=M&&M<=this.endOf(C)},A.isAfter=function(U,C){return w(U)<this.startOf(C)},A.isBefore=function(U,C){return this.endOf(C)<w(U)},A.$g=function(U,C,M){return T.u(U)?this[C]:this.set(M,U)},A.unix=function(){return Math.floor(this.valueOf()/1e3)},A.valueOf=function(){return this.$d.getTime()},A.startOf=function(U,C){var M=this,D=!!T.u(C)||C,R=T.p(U),j=function(z,H){var Y=T.w(M.$u?Date.UTC(M.$y,H,z):new Date(M.$y,H,z),M);return D?Y:Y.endOf(c)},G=function(z,H){return T.w(M.toDate()[z].apply(M.toDate("s"),(D?[0,0,0,0]:[23,59,59,999]).slice(H)),M)},W=this.$W,q=this.$M,F=this.$D,L="set"+(this.$u?"UTC":"");switch(R){case v:return D?j(1,0):j(31,11);case p:return D?j(1,q):j(0,q+1);case u:var x=this.$locale().weekStart||0,B=(W<x?W+7:W)-x;return j(D?F-B:F+(6-B),q);case c:case f:return G(L+"Hours",0);case l:return G(L+"Minutes",1);case a:return G(L+"Seconds",2);case s:return G(L+"Milliseconds",3);default:return this.clone()}},A.endOf=function(U){return this.startOf(U,!1)},A.$set=function(U,C){var M,D=T.p(U),R="set"+(this.$u?"UTC":""),j=(M={},M[c]=R+"Date",M[f]=R+"Date",M[p]=R+"Month",M[v]=R+"FullYear",M[l]=R+"Hours",M[a]=R+"Minutes",M[s]=R+"Seconds",M[i]=R+"Milliseconds",M)[D],G=D===c?this.$D+(C-this.$W):C;if(D===p||D===v){var W=this.clone().set(f,1);W.$d[j](G),W.init(),this.$d=W.set(f,Math.min(this.$D,W.daysInMonth())).$d}else j&&this.$d[j](G);return this.init(),this},A.set=function(U,C){return this.clone().$set(U,C)},A.get=function(U){return this[T.p(U)]()},A.add=function(U,C){var M,D=this;U=Number(U);var R=T.p(C),j=function(q){var F=w(D);return T.w(F.date(F.date()+Math.round(q*U)),D)};if(R===p)return this.set(p,this.$M+U);if(R===v)return this.set(v,this.$y+U);if(R===c)return j(1);if(R===u)return j(7);var G=(M={},M[a]=n,M[l]=o,M[s]=r,M)[R]||1,W=this.$d.getTime()+U*G;return T.w(W,this)},A.subtract=function(U,C){return this.add(-1*U,C)},A.format=function(U){var C=this,M=this.$locale();if(!this.isValid())return M.invalidDate||m;var D=U||"YYYY-MM-DDTHH:mm:ssZ",R=T.z(this),j=this.$H,G=this.$m,W=this.$M,q=M.weekdays,F=M.months,L=M.meridiem,x=function(H,Y,Z,K){return H&&(H[Y]||H(C,D))||Z[Y].slice(0,K)},B=function(H){return T.s(j%12||12,H,"0")},z=L||function(H,Y,Z){var K=H<12?"AM":"PM";return Z?K.toLowerCase():K};return D.replace(g,function(H,Y){return Y||function(Z){switch(Z){case"YY":return String(C.$y).slice(-2);case"YYYY":return T.s(C.$y,4,"0");case"M":return W+1;case"MM":return T.s(W+1,2,"0");case"MMM":return x(M.monthsShort,W,F,3);case"MMMM":return x(F,W);case"D":return C.$D;case"DD":return T.s(C.$D,2,"0");case"d":return String(C.$W);case"dd":return x(M.weekdaysMin,C.$W,q,2);case"ddd":return x(M.weekdaysShort,C.$W,q,3);case"dddd":return q[C.$W];case"H":return String(j);case"HH":return T.s(j,2,"0");case"h":return B(1);case"hh":return B(2);case"a":return z(j,G,!0);case"A":return z(j,G,!1);case"m":return String(G);case"mm":return T.s(G,2,"0");case"s":return String(C.$s);case"ss":return T.s(C.$s,2,"0");case"SSS":return T.s(C.$ms,3,"0");case"Z":return R}return null}(H)||R.replace(":","")})},A.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},A.diff=function(U,C,M){var D,R=this,j=T.p(C),G=w(U),W=(G.utcOffset()-this.utcOffset())*n,q=this-G,F=function(){return T.m(R,G)};switch(j){case v:D=F()/12;break;case p:D=F();break;case d:D=F()/3;break;case u:D=(q-W)/6048e5;break;case c:D=(q-W)/864e5;break;case l:D=q/o;break;case a:D=q/n;break;case s:D=q/r;break;default:D=q}return M?D:T.a(D)},A.daysInMonth=function(){return this.endOf(p).$D},A.$locale=function(){return S[this.$L]},A.locale=function(U,C){if(!U)return this.$L;var M=this.clone(),D=b(U,C,!0);return D&&(M.$L=D),M},A.clone=function(){return T.w(this.$d,this)},A.toDate=function(){return new Date(this.valueOf())},A.toJSON=function(){return this.isValid()?this.toISOString():null},A.toISOString=function(){return this.$d.toISOString()},A.toString=function(){return this.$d.toUTCString()},E}(),N=$.prototype;return w.prototype=N,[["$ms",i],["$s",s],["$m",a],["$H",l],["$W",c],["$M",p],["$y",v],["$D",f]].forEach(function(E){N[E[1]]=function(A){return this.$g(A,E[0],E[1])}}),w.extend=function(E,A){return E.$i||(E(A,$,w),E.$i=!0),w},w.locale=b,w.isDayjs=O,w.unix=function(E){return w(1e3*E)},w.en=S[y],w.Ls=S,w.p={},w})})(AR);var w0e=AR.exports;const E0e=Eg(w0e);function $0e({matchUp:t,eventHandlers:e}){const{scheduledTime:r,scheduledDate:n,venueAbbreviation:o,courtName:i}=(t==null?void 0:t.schedule)||{},{dateTime:{extractDate:s,extractTime:a}}=fg,l=a(r);let u=s(n),p="ddd D MMMM";l&&(p+=", hh:mm A",u+=`T${l}`);const d=n?E0e(u).format(p):"Not scheduled",v=o&&(i==null?void 0:i.toString().startsWith(o))&&i||o&&i&&`${o} ${i}`||i||o||"",f=document.createElement("div");f.className=T0e(),f.onclick=e==null?void 0:e.scheduleClick;const m=document.createElement("div");m.innerHTML=d,f.append(m);const h=_=>{typeof(e==null?void 0:e.venueClick)=="function"&&(_.stopPropagation(),e.venueClick({matchUp:t,event:_}))},g=document.createElement("div");return g.onclick=h,g.innerHTML=v,f.append(g),f}function CR({eventHandlers:t,composition:e,sideNumber:r,className:n,matchUp:o}){var v,f;const i=(e==null?void 0:e.configuration)||{},s=i==null?void 0:i.scheduleInfo,a=(v=o==null?void 0:o.score)==null?void 0:v.scoreStringSide1,l=((f=e==null?void 0:e.configuration)==null?void 0:f.scoreBox)&&a,c=(o==null?void 0:o.readyToScore)&&(t==null?void 0:t.scoreClick)&&!fg.scoreHasValue({matchUp:o}),u=document.createElement("div");if(u.className=Zi(t0e(),n),s&&r===1){const m=$0e({matchUp:o,eventHandlers:t});u.appendChild(m)}const p=document.createElement("div");p.className=r0e();const d=wR({sideContainer:!0,eventHandlers:t,composition:e,sideNumber:r,matchUp:o});if(p.appendChild(d),l){const m=document.createElement("div");m.style.border="1px solid lightgray",p.appendChild(m)}if(a){const m=b0e({eventHandlers:t,composition:e,sideNumber:r,matchUp:o});p.appendChild(m)}if(c){const m=NR(),h=_=>{typeof(t==null?void 0:t.scoreClick)=="function"&&(_.stopPropagation(),t.scoreClick({event:_,matchUp:o}))},g=document.createElement("div");g.className=m({sideNumber:!l&&r,fontSize:"small"}),g.onclick=h,g.innerHTML="[Score]",p.appendChild(g)}return u.appendChild(p),u}function MR(t){const{composition:e,matchUp:r,moeity:n,selectedMatchUpId:o,searchActive:i}=t,{roundFactor:s,roundNumber:a,finishingRound:l,matchUpType:c,preFeedRound:u,stage:p}=r,d=p==="QUALIFYING",v=parseInt(l)===1,f=p==="QUALIFYING"&&v,m=!d&&v,h=parseInt(a)===1,g=c==="DOUBLES",_=(i||r.isRoundRobin||r.collectionId||t.isLucky)&&"mr"||m&&"noProgression"||(f||u)&&"m0"||n&&"m1"||"m2",I=I0e({composition:e,isDoubles:g,roundFactor:s})({isFirstRound:h,link:_}),P=(e==null?void 0:e.configuration)||{},{resultsInfo:y,centerInfo:S}=P||{},O=t.eventHandlers||{},b=A=>{typeof(O==null?void 0:O.matchUpClick)=="function"&&O.matchUpClick({event:A,matchUp:r})},w=document.createElement("div");w.className=Zi(e.theme,t==null?void 0:t.className,"matchup",f0e()),w.onclick=b;const T=document.createElement("div");T.className=v0e({configuration:P});const $=({sideNumber:A})=>{var M,D,R;const U=(R=(D=(M=r==null?void 0:r.sides.find(j=>j.sideNumber===A))==null?void 0:M.participant)==null?void 0:D.entryStatus)==null?void 0:R.replace("_"," ");return _0e({eventHandlers:O,entryStatus:U,sideNumber:A,className:A===2&&I})},N=CR({sideNumber:1,eventHandlers:O,composition:e,matchUp:r}),E=CR({className:!S&&I,sideNumber:2,eventHandlers:O,composition:e,matchUp:r});if(T.appendChild(N),S&&(T.appendChild($({sideNumber:1})),T.appendChild($({sideNumber:2}))),T.appendChild(E),y){const A=N0e({score:r.score});T.appendChild(A)}if(w.appendChild(T),o===r.matchUpId){const A=document.createElement("div");A.className=p0e(),w.appendChild(A)}return w}function N0e({score:t}){var i;const e=(i=t==null?void 0:t.sets)==null?void 0:i.filter(Boolean).sort((s,a)=>(s.setNumber||0)-(a.setNumber||0)),r=e==null?void 0:e[e.length-1],n=(r==null?void 0:r.side1PointsScore)||(r==null?void 0:r.side2PointsScore),o=document.createElement("div");if(o.className=d0e(),n){const s=document.createElement("div");s.className=ER({variant:"points"}),s.innerHTML="PTS",o.appendChild(s)}for(const s of e||[]){const a=document.createElement("div");a.setAttribute("key",s.setNumber),a.className=ER({variant:"set"}),a.innerHTML=s.setNumber,o.appendChild(a)}return o}function U0e({selectedMatchUpId:t,eventHandlers:e,isRoundRobin:r,searchActive:n,composition:o,roundFactor:i,roundNumber:s,roundProfile:a,matchUps:l,isLucky:c}){const u=l.filter(g=>g.roundNumber===s).sort((g,_)=>(g.roundPosition||0)-(_.roundPosition||0)),p=(o==null?void 0:o.configuration)||{},d=document.createElement("div");if(d.className=a0e(),p.roundHeader){const g=c0e({roundProfile:a,roundNumber:s,eventHandlers:e});d.appendChild(g)}const v=document.createElement("div");v.className=u0e();let f,m;if(r){const g=_=>_.reduce((I,P)=>P+I,0);u.sort((_,I)=>g(_.drawPositions)-g(I.drawPositions)),f=Object.values(u.reduce((_,I)=>(_[I.structureId]=I.structureName,_),{})),m=Object.keys(fg.instanceCount(u.map(({structureId:_})=>_))).length}const h=m&&u.length/m;return u.forEach((g,_)=>{const I=h&&!(_%h),P=h&&Math.floor(_/h),y=h&&f[P];if(I){const b=document.createElement("div");b.className=s0e({variant:P}),s===1&&(b.innerHTML=y),v.appendChild(b)}const S=_%2===0;i&&(g.roundFactor=i);const O=MR({selectedMatchUpId:t,eventHandlers:e,searchActive:n,composition:o,matchUp:g,isLucky:c,moeity:S});v.appendChild(O)}),d.appendChild(v),d}function A0e({selectedMatchUpId:t,eventHandlers:e,searchActive:r,composition:n,matchUps:o}){const{roundNumbers:i,roundProfile:s,hasOddMatchUpsCount:a}=pae.getRoundMatchUps({matchUps:o}),l=o.some(({isRoundRobin:p})=>p),c=a,u=document.createElement("div");u.className=i0e();for(const p of i){const d=U0e({selectedMatchUpId:t,eventHandlers:e,isRoundRobin:l,searchActive:r,composition:n,roundNumber:p,roundProfile:s,matchUps:o,isLucky:c});u.appendChild(d)}return u}const DR=Ke({backgroundColor:"$colors$backgroundColor",color:"$colors$color",height:1e3});function C0e({content:t,theme:e}){const r=document.createElement("div");return r.className=e?Zi(DR(),e):DR(),e&&r.classList.add(e),typeof t=="string"?r.innerHTML=t:r.appendChild(t),r}const{createTheme:Ks}=bg({theme:{lineHeights:{scheduleInfo:`${Gc.scheduleInfo}rem`,centerInfo:`${Gc.centerInfo}rem`,gameScore:`${Gc.gameScore}rem`},borderWidths:{matchUpInline:"1px 1px",matchUp:"1px"},space:{1:"10px",2:"0.375rem",gameMarginInlineEnd:"0.25rem"},fontSizes:{1:"0.875rem"},colors:{internalDividers:"lightgray",backgroundColor:"white",connector:"lightgray",border:"darkgray",color:"black"},participant:{textTransform:"capitalize",minHeight:"2rem",seed:"gray"},score:{setWidth:"1.3rem"}}}),jR=Ks("australian-theme",{colors:{borderHover:"#0091d2",connector:"#999"}}),M0e=Ks("wimbledon-theme",{borderWidths:{borderInlineStart:"10px"},colors:{connector:"transparent",borderHover:"darkgrey",border:"#00703c",matchUp:"#fff"},participant:{textTransform:"uppercase"}}),D0e=Ks("french-theme",{colors:{winnerName:"#01503d!important",winner:"#01503d!important",borderHover:"#0091d2",border:"#F8F9F9"},matchUp:{boxShadow:"0 0 30px 0 hsla(0,0%,89%,9)"}}),j0e=Ks("usopen-theme",{colors:{matchUpBackgroundColor:"#F8F9F9",internalDividers:"darkgray",borderHover:"#0091d2",connector:"#999"}}),RR=Ks("basic-theme",{colors:{internalDividers:"transparent",winner:"#50B649!important",loser:"#E61A1A!important",connector:"#999"},space:{gameMarginInlineEnd:"0.75rem"},participant:{seed:"transparent"},fontSizes:{1:"1.5rem"}}),R0e=Ks("dark-theme",{colors:{backgroundColor:"#333333",borderHover:"#0091d2",color:"white"},participant:{seed:"cyan"}}),F0e=Ks("itf-theme",{colors:{borderHover:"#0091d2",connector:"#999",matchUp:"#fff"},participant:{textTransform:"uppercase",seed:"gray"}}),x0e={Australian:{configuration:{flags:!0},theme:jR},Basic:{configuration:{gameScoreOnly:!0,teamLogo:!1,roundHeader:!0},theme:RR},DrawPositions:{configuration:{gameScoreOnly:!0,drawPositions:!0,teamLogo:!1},theme:RR},French:{configuration:{bracketedSeeds:!0,flags:!0},theme:D0e},Wimbledon:{configuration:{resultsInfo:!0,flags:!0},theme:M0e},"US Open":{configuration:{scoreBox:!0,flags:!0},theme:j0e},ITF:{configuration:{winnerChevron:!0,centerInfo:!0,flags:!0,roundHeader:!0},theme:F0e},National:{configuration:{bracketedSeeds:"square",allDrawPositions:!0,drawPositions:!0,scheduleInfo:!0,roundHeader:!0,showAddress:!0},theme:jR},Night:{configuration:{flags:!0},theme:R0e}},L0e=Ke({willChange:"opacity",position:"fixed",zIndex:9998,bottom:0,right:0,left:0,top:0}),V0e=Ke({display:"block"}),B0e=Ke({position:"fixed",right:0,left:0}),k0e=Ke({paddingRight:"15px",alignItems:"center",margin:"30px auto",paddingLeft:"15px",position:"fixed",height:"100vh",display:"flex",width:"100%",zIndex:9999,bottom:0,right:0,left:0,top:0}),G0e=Ke({boxShadow:"0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23)",backgroundColor:"white",position:"relative",borderRadius:"3px",minHeight:"auto",width:"100%"}),W0e=Ke({borderBottom:"1px solid rgba(0, 0, 0, 0.1)",alignItems:"center",position:"relative",display:"flex"}),H0e=Ke({fontWeight:"600",fontSize:"20px"}),FR=Ke({borderTop:"1px solid rgba(0, 0, 0, 0.1)",justifyContent:"right",alignItems:"center",position:"relative",display:"flex"}),xR="Nothing to see here";function Rp(t){return typeof t=="function"}function Fp(t){return typeof t=="string"}function LR(t){return Array.isArray(t)}function vg(t){return typeof t=="object"&&!Array.isArray(t)}function q0e(t){if(t)for(;t.firstChild;)t.removeChild(t.firstChild)}const mg=(()=>{const t=B0e(),e={},r=".5";let n=[],o,i=[],s=[],a;const l=g=>{if(g){let _;s=s.filter(I=>(I.id===g&&(_=I),I.id!==g)),_&&document.body.removeChild(_)}else{const _=s.pop();_&&document.body.removeChild(_)}},c=()=>{a&&(a.style.opacity=0,a.style.display="none")},u=g=>{const _=s.length;if(g&&e[_]===!1)return;const I=i.pop(),P=n.pop();Rp(I)&&I({content:P}),document.body.classList.remove(t),document.body.style.top=null,window.scrollTo({top:o,behavior:"instant"}),c(),l()},p=()=>{a=document.createElement("div"),a.className=L0e(),a.id="cmdl-backdrop",a.onclick=()=>u(!0),document.body.appendChild(a)},d=({config:g})=>{o=window.scrollY,document.body.classList.add(t),document.body.style.top=`-${o}px`,a||p(),a.style.display="",(g==null?void 0:g.backdrop)!==!1&&(a.style.backgroundColor="rgba(0, 0, 0, 0.2)",a.style.transition="opacity 0.15s linear",a.style.opacity=1)},v=({config:g,attr:_})=>{if(!Fp(_))return;const I=_.split(".");for(const P of I)if(g=g==null?void 0:g[P],!g)return;return g},f=({config:g,attr:_,attrs:I,unit:P="em",value:y})=>{var O;let S;return Fp(_)?S=v({config:g,attr:_}):LR(I)&&(S=(O=I.map(b=>v({config:g,attr:b})).filter(Boolean))==null?void 0:O[0]),S!==void 0&&(y=S),isNaN(y)?y:`${y}${P}`},m=({buttons:g,config:_,modalNumber:I})=>{var S,O;const P=document.createElement("div");P.className=FR(),P.style.padding=f({config:_,attrs:["footer.padding","padding"],value:r});const y={label:((S=_==null?void 0:_.dictionary)==null?void 0:S.close)||"Close",onClick:mg.close,intent:"is-info"};for(const b of g){if(b.hide)continue;const w=Object.assign({},y);vg(b)&&Object.assign(w,b);const T=document.createElement("button");w.disabled!==void 0&&(T.disabled=w.disabled),w.id&&(T.id=w.id),T.className=((O=w==null?void 0:w.footer)==null?void 0:O.className)||"button font-medium",T.classList.add(w.intent),T.style="margin-right: .5em;",T.innerHTML=w.label||w.text,T.onclick=$=>{$.stopPropagation(),Rp(w.onClick)&&w.onClick({e:$,content:n[I]}),w.close!==!1&&(Rp(w.close)&&w.close(),mg.close())},P.appendChild(T)}return P};return{close:u,open:({title:g="",content:_,buttons:I,footer:P,config:y,onClose:S}={})=>{d({config:y}),i.push(S);const O=s.length+1;e[O]=y==null?void 0:y.clickAway;const b=document.createElement("section"),w=`cmdl-${O}`;b.className=V0e(),b.role="dialog",b.tabIndex=-1,b.id=w;const T=document.createElement("div");T.className=k0e(),T.style.maxWidth=`${(y==null?void 0:y.maxWidth)||450}px`,T.onclick=()=>u(!0);const $=document.createElement("div");$.className=G0e(),$.onclick=j=>j.stopPropagation();const N=document.createElement("div"),E=document.createElement("div");N.appendChild(E),$.appendChild(N);const A=({title:j,config:G})=>{N.className=j?W0e():"",N.style.padding=f({config:G,attrs:["title.padding","padding"],value:r}),E.className=j?H0e():"",E.innerHTML=j};g&&A({title:g});const U=document.createElement("div");$.appendChild(U);const C=({content:j,config:G})=>{U.style.fontSize=f({config:G,attr:"fontSize",value:"15px"}),U.style.position="relative",U.style.padding=f({config:G,attrs:["content.padding","padding"],value:r}),Rp(j)?n[O]=j(U):vg(j)?U.appendChild(j):Fp(j)?U.innerHTML=j:U.innerHTML=xR};if(C({content:_,config:y}),LR(I))P=m({buttons:I,config:y,modalNumber:O}),$.appendChild(P);else if(P){const j=document.createElement("div");j.className=FR(),j.style.padding=f({config:y,attrs:["footer.padding","padding"]}),vg(P)?j.appendChild(P):Fp(P)?j.innerHTML=P:j.innerHTML=xR,$.appendChild(j)}T.appendChild($),b.appendChild(T),document.body.appendChild(b),s.push(b);const M=({content:j,config:G})=>{n[O]=void 0,q0e(U),C({content:j,config:G})},D=({buttons:j,config:G})=>{$.removeChild(P),P=m({buttons:j,config:G,modalNumber:O}),$.appendChild(P)};return{setContent:M,setButtons:D,update:({content:j,buttons:G,title:W,config:q})=>{y=q||y,j&&M({content:j,config:y}),G&&D({buttons:G,config:y}),W&&A({title:W,config:y})}}}}})();ro.cModal=mg,ro.compositions=x0e,ro.renderContainer=C0e,ro.renderMatchUp=MR,ro.renderParticipant=wR,ro.renderStructure=A0e,Object.defineProperty(ro,Symbol.toStringTag,{value:"Module"})});
32
+ `}function wR({eventHandlers:t,sideContainer:e,composition:r,sideNumber:n,matchUp:o,participant:i}){var w,T,$,N;const{winningSide:s,matchUpType:a,isRoundRobin:l,matchUpStatus:c}=o||{},u=r==null?void 0:r.configuration;let p;const d=n?(w=o==null?void 0:o.sides)==null?void 0:w.find(E=>E.sideNumber===n):void 0;i||(i=d==null?void 0:d.participant,p=u!=null&&u.allDrawPositions||u!=null&&u.drawPositions&&(d!=null&&d.drawPosition)&&((o==null?void 0:o.roundNumber)===1||d!=null&&d.participantFed||l)?d==null?void 0:d.drawPosition:"");const v=((T=i==null?void 0:i.individualParticipants)==null?void 0:T.length)===2||a==="DOUBLES",f=v?($=i==null?void 0:i.individualParticipants)==null?void 0:$[0]:i,m=v&&((N=i==null?void 0:i.individualParticipants)==null?void 0:N[1]),h=n===s||c==="BYE"&&i,g=(u==null?void 0:u.winnerChevron)&&h,_=u==null?void 0:u.teamLogo,I=["RETIRED","DOUBLE_WALKOVER","WALKOVER","DEFAULTED"].includes(c)&&!h,P=u==null?void 0:u.gameScoreOnly,y=document.createElement("div");if(y.className=e&&bF({drawPosition:p,sideNumber:n}),_){const E=e0e({teamLogo:_});y.appendChild(E)}const S=document.createElement("div");S.className=OF({variant:v?"doubles":"singles"});const O=document.createElement("div");O.className=TF({winnerChevron:g,isDoubles:v});const b=TR({individualParticipant:f,eventHandlers:t,isWinningSide:h,composition:r,matchUp:o,side:d});if(O.appendChild(b),m){const E=TR({individualParticipant:m,eventHandlers:t,isWinningSide:h,composition:r,matchUp:o,side:d});O.appendChild(E)}if(S.appendChild(O),y.appendChild(S),e){const E=document.createElement("div");if(h&&!P){const A=o0e();typeof A=="string"?E.innerHTML=A:E.appendChild(A)}else if(I){const A=Zye({matchUpStatus:c});E.appendChild(A)}y.appendChild(E)}return y}const i0e=Ke({marginInlineStart:"1rem",overflowX:"auto",display:"flex"}),s0e=Ke({borderTop:"solid 1px black",marginRight:"-1em",marginLeft:"-1em",paddingTop:".5em",marginTop:".2em",variants:{variant:{0:{marginTop:"1em",borderTop:"none",paddingTop:"0px"}},roundOrder:{first:{marginLeft:"0em"},last:{marginRight:"0em"}}}}),a0e=Ke({flexDirection:"column",display:"flex"}),l0e=Ke({fontWeight:"bold",color:"blue",height:"1em"}),c0e=Ke({borderBottom:"solid 1px black",marginInlineStart:"16px",marginInlineEnd:"16px",fontWeight:"bold",width:"460px",height:"1.5em"});function u0e({eventHandlers:t,roundProfile:e,roundNumber:r}){var i;const n=document.createElement("div");n.className=c0e(),n.onclick=t==null?void 0:t.roundHeaderClick;const o=(i=e==null?void 0:e[r])==null?void 0:i.roundName;return n.innerHTML=o||"",n}const d0e=Ke({justifyContent:"space-around",marginInlineStart:"16px",marginInlineEnd:"16px",flexDirection:"column",height:"100%",display:"flex",width:"460px"}),ER=Ke({width:"$score$setWidth",display:"inline-block",fontSize:9,variants:{variant:{set:{textAlign:"center"},points:{marginInlineEnd:3}}}}),p0e=Ke({transform:"translateY(-50%)",textTransform:"uppercase",backgroundColor:"#fff",position:"absolute",textAlign:"center",top:"calc(50%)",color:"#bbb",fontSize:0,right:4});function f0e(){return Ke({backgroundColor:"magenta",position:"absolute",opacity:"0.2",height:"100%",width:"100%",top:0})}const v0e=Ke({});function m0e({configuration:t}){const e={backgroundColor:"$matchUpBackgroundColor",WebkitTransition:"all 0.30s linear",boxShadow:"$matchUp$boxShadow",transition:"all 0.30s linear",border:"solid $border",marginBottom:"$space$1",marginTop:"$space$1",position:"relative",display:"grid",width:"100%",borderInlineStartWidth:"$borderWidths$borderInlineStart"};if(t!=null&&t.matchUpHover){const r=typeof t.matchUpHover=="string"?t.matchUpHover:"cyan";e["&:hover"]={backgroundColor:r}}else e["&:hover"]={borderColor:"$borderHover"};return Ke(e)}function h0e({variant:t}){return Ke({borderBottom:"solid 1px lightgray",backgroundColor:"$matchUp",position:"relative",width:"100%",height:"$lineHeights$centerInfo",variants:{variant:{1:{borderBottom:"solid 1px black"},2:{borderBottom:"solid 1px lightgray"}}}})({variant:t})}const g0e=Ke({justifyContent:"center",alignContent:"center",flexDirection:"column",height:"100%",display:"flex"}),_0e=Ke({fontFamily:"Lato,Arial,Helvetica,sans-serif",WebkitFontSmooting:"antialiased",marginInlineStart:"calc(20%)",WebkitBoxOrient:"horizontal",WebKitBoxDirection:"normal",WebkitBoxPack:"center",boxSizing:"inherit",flexDirection:"row",display:"flex"}),$R=Ke({alignContent:"center",boxSizing:"inherit",fontFamily:"Lato",fontWeight:900,fontSize:9});function I0e({eventHandlers:t,entryStatus:e,sideNumber:r,className:n}){const o=document.createElement("div");o.onclick=t==null?void 0:t.centerInfoClick,o.className=Zi(h0e({variant:r}),n);const i=document.createElement("div");i.className=g0e();const s=document.createElement("div");s.className=_0e();const a=document.createElement("div");a.className=$R(),a.innerHTML=e?"Entry status:&nbsp;":"",s.appendChild(a);const l=document.createElement("div");return l.className=$R(),l.innerHTML=e||"",s.appendChild(l),i.appendChild(s),o.appendChild(i),o}const Gc={scheduleInfo:1.8,centerInfo:1.5,gameScore:2};function P0e({composition:t,isDoubles:e,roundFactor:r=1}){const n=parseInt(window.getComputedStyle(document.body).getPropertyValue("font-size")),o=(t==null?void 0:t.configuration)||{},i=(o==null?void 0:o.connectorWidth)||16,s=o.centerInfo?Gc.centerInfo*n:0,a=o.scheduleInfo?Gc.scheduleInfo*n:0,c=(60+(o.showAddress?n:0))*(e?1.3:1)+s,u=c*r,p=(c+a)*r;return Ke({"&::before":{borderBlockStart:"$borderWidths$matchUp solid #999",left:-i,width:i,position:"absolute",borderRadius:2,top:-1},"&::after":{width:i,position:"absolute",borderRadius:2,left:"100%"},"&::after, &::before":{borderWidth:"$borderWidths$matchUp",borderColor:"$connector",display:"block",content:""},variants:{isFirstRound:{true:{"&::before":{height:0,width:0,borderWidth:0}}},link:{m1:{"&::after":{borderInlineEnd:"$borderWidths$matchUp solid $connector",borderTopStyle:"solid",height:u,top:-1}},m2:{"&::after":{bottom:"calc(100%)",borderInlineEnd:"$borderWidths$matchUp solid $connector",borderBottomStyle:"solid",height:p}},m0:{"&::after":{borderTopStyle:"solid",borderColor:"$connector",top:-1}},mr:{"&::before":{height:0,width:0,borderWidth:0},"&::after":{height:0,width:0,borderWidth:0}},noProgression:{true:{"&::after":{height:0,width:0,borderWidth:0}}}}}})}const NR=t=>Ke({display:"flex",alignItems:"center",height:t,justifyContent:"flex-end",backgroundColor:"$matchUp",variants:{sideNumber:{1:{borderBottom:"1px solid $internalDividers"}},fontSize:{small:{fontSize:"smaller",paddingRight:"1em",color:"blue"}}}}),y0e=Ke({letterSpacing:"-0.2em",lineHeight:"0.75rem",position:"absolute",fontSize:"0.625rem",left:"1.1rem",top:".4rem"}),UR=Ke({lineHeight:"$lineHeights$gameScore",justifyContent:"center",width:"$score$setWidth",position:"relative",textAlign:"center",cursor:"pointer",fontWeight:500,fontSize:"$1",display:"flex",margin:0,variants:{variant:{winner:{color:"$winner!important",fontWeight:700},loser:{color:"$loser!important"}}}}),S0e=Ke({marginInlineEnd:"$space$gameMarginInlineEnd",justifyContent:"flex-end",alignItems:"center",display:"flex"});function O0e({value:t}={}){const e=document.createElement("input");return e.onclick=r=>r.target.select(),e.className=UR(),e.value=t,e}function b0e({gameScoreOnly:t,scoreStripes:e,set:r,sideNumber:n}){const i=n===(r==null?void 0:r.winningSide)||r!=null&&r.winningSide?"loser":void 0,s=n===2?r.side2Score:r.side1Score,a=n===2?r.side2TiebreakScore:r.side1TiebreakScore,l=s===void 0&&a,c=l||s,u=e&&r.setNumber%2?"lightgray":"transparent",d=r.editing?r.editing===n:void 0;let v;if(d)v=O0e({value:c});else if(v=document.createElement("p"),v.className=UR({variant:i}),v.style.backgroundColor=u,v.innerHTML=isNaN(c)?"":c,!t){const f=document.createElement("span");f.className=y0e(),f.innerHTML=l?a:"",v.appendChild(f)}return v}function T0e({participantHeight:t,eventHandlers:e,composition:r,sideNumber:n,matchUp:o}){var f,m,h,g;const i=(f=r==null?void 0:r.configuration)==null?void 0:f.winnerChevron,s=(m=r==null?void 0:r.configuration)==null?void 0:m.gameScoreOnly,a=((h=o==null?void 0:o.score)==null?void 0:h.sets)||[],l=(g=r==null?void 0:r.configuration)==null?void 0:g.scoreBox,c=n===2?t:t-1,u=NR(c),p=_=>{typeof(e==null?void 0:e.scoreClick)=="function"&&(_.stopPropagation(),e.scoreClick({event:_,matchUp:o}))},d=document.createElement("div");d.className=u({sideNumber:!l&&n,fontSize:"5px"}),d.classList.add("sideScore"),d.onclick=p;const v=document.createElement("div");v.className=S0e();for(const _ of a||[]){const I=b0e({gameScoreOnly:s,scoreStripes:i,sideNumber:n,set:_});v.appendChild(I)}return d.appendChild(v),d}const w0e=Ke({height:"$lineHeights$scheduleInfo",borderBottom:"1px solid darkgray",justifyContent:"space-between",backgroundColor:"#F8F9F9",boxSizing:"border-box",paddingRight:"0.5rem",paddingLeft:"0.5rem",alignItems:"center",cursor:"pointer",color:"#7F8080",display:"flex",width:"100%"});var AR={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(NF,function(){var r=1e3,n=6e4,o=36e5,i="millisecond",s="second",a="minute",l="hour",c="day",u="week",p="month",d="quarter",v="year",f="date",m="Invalid Date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,g=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,_={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(E){var A=["th","st","nd","rd"],U=E%100;return"["+E+(A[(U-20)%10]||A[U]||A[0])+"]"}},I=function(E,A,U){var C=String(E);return!C||C.length>=A?E:""+Array(A+1-C.length).join(U)+E},P={s:I,z:function(E){var A=-E.utcOffset(),U=Math.abs(A),C=Math.floor(U/60),M=U%60;return(A<=0?"+":"-")+I(C,2,"0")+":"+I(M,2,"0")},m:function E(A,U){if(A.date()<U.date())return-E(U,A);var C=12*(U.year()-A.year())+(U.month()-A.month()),M=A.clone().add(C,p),D=U-M<0,R=A.clone().add(C+(D?-1:1),p);return+(-(C+(U-M)/(D?M-R:R-M))||0)},a:function(E){return E<0?Math.ceil(E)||0:Math.floor(E)},p:function(E){return{M:p,y:v,w:u,d:c,D:f,h:l,m:a,s,ms:i,Q:d}[E]||String(E||"").toLowerCase().replace(/s$/,"")},u:function(E){return E===void 0}},y="en",S={};S[y]=_;var O=function(E){return E instanceof $},b=function E(A,U,C){var M;if(!A)return y;if(typeof A=="string"){var D=A.toLowerCase();S[D]&&(M=D),U&&(S[D]=U,M=D);var R=A.split("-");if(!M&&R.length>1)return E(R[0])}else{var j=A.name;S[j]=A,M=j}return!C&&M&&(y=M),M||!C&&y},w=function(E,A){if(O(E))return E.clone();var U=typeof A=="object"?A:{};return U.date=E,U.args=arguments,new $(U)},T=P;T.l=b,T.i=O,T.w=function(E,A){return w(E,{locale:A.$L,utc:A.$u,x:A.$x,$offset:A.$offset})};var $=function(){function E(U){this.$L=b(U.locale,null,!0),this.parse(U)}var A=E.prototype;return A.parse=function(U){this.$d=function(C){var M=C.date,D=C.utc;if(M===null)return new Date(NaN);if(T.u(M))return new Date;if(M instanceof Date)return new Date(M);if(typeof M=="string"&&!/Z$/i.test(M)){var R=M.match(h);if(R){var j=R[2]-1||0,G=(R[7]||"0").substring(0,3);return D?new Date(Date.UTC(R[1],j,R[3]||1,R[4]||0,R[5]||0,R[6]||0,G)):new Date(R[1],j,R[3]||1,R[4]||0,R[5]||0,R[6]||0,G)}}return new Date(M)}(U),this.$x=U.x||{},this.init()},A.init=function(){var U=this.$d;this.$y=U.getFullYear(),this.$M=U.getMonth(),this.$D=U.getDate(),this.$W=U.getDay(),this.$H=U.getHours(),this.$m=U.getMinutes(),this.$s=U.getSeconds(),this.$ms=U.getMilliseconds()},A.$utils=function(){return T},A.isValid=function(){return this.$d.toString()!==m},A.isSame=function(U,C){var M=w(U);return this.startOf(C)<=M&&M<=this.endOf(C)},A.isAfter=function(U,C){return w(U)<this.startOf(C)},A.isBefore=function(U,C){return this.endOf(C)<w(U)},A.$g=function(U,C,M){return T.u(U)?this[C]:this.set(M,U)},A.unix=function(){return Math.floor(this.valueOf()/1e3)},A.valueOf=function(){return this.$d.getTime()},A.startOf=function(U,C){var M=this,D=!!T.u(C)||C,R=T.p(U),j=function(z,H){var Y=T.w(M.$u?Date.UTC(M.$y,H,z):new Date(M.$y,H,z),M);return D?Y:Y.endOf(c)},G=function(z,H){return T.w(M.toDate()[z].apply(M.toDate("s"),(D?[0,0,0,0]:[23,59,59,999]).slice(H)),M)},W=this.$W,q=this.$M,F=this.$D,L="set"+(this.$u?"UTC":"");switch(R){case v:return D?j(1,0):j(31,11);case p:return D?j(1,q):j(0,q+1);case u:var x=this.$locale().weekStart||0,B=(W<x?W+7:W)-x;return j(D?F-B:F+(6-B),q);case c:case f:return G(L+"Hours",0);case l:return G(L+"Minutes",1);case a:return G(L+"Seconds",2);case s:return G(L+"Milliseconds",3);default:return this.clone()}},A.endOf=function(U){return this.startOf(U,!1)},A.$set=function(U,C){var M,D=T.p(U),R="set"+(this.$u?"UTC":""),j=(M={},M[c]=R+"Date",M[f]=R+"Date",M[p]=R+"Month",M[v]=R+"FullYear",M[l]=R+"Hours",M[a]=R+"Minutes",M[s]=R+"Seconds",M[i]=R+"Milliseconds",M)[D],G=D===c?this.$D+(C-this.$W):C;if(D===p||D===v){var W=this.clone().set(f,1);W.$d[j](G),W.init(),this.$d=W.set(f,Math.min(this.$D,W.daysInMonth())).$d}else j&&this.$d[j](G);return this.init(),this},A.set=function(U,C){return this.clone().$set(U,C)},A.get=function(U){return this[T.p(U)]()},A.add=function(U,C){var M,D=this;U=Number(U);var R=T.p(C),j=function(q){var F=w(D);return T.w(F.date(F.date()+Math.round(q*U)),D)};if(R===p)return this.set(p,this.$M+U);if(R===v)return this.set(v,this.$y+U);if(R===c)return j(1);if(R===u)return j(7);var G=(M={},M[a]=n,M[l]=o,M[s]=r,M)[R]||1,W=this.$d.getTime()+U*G;return T.w(W,this)},A.subtract=function(U,C){return this.add(-1*U,C)},A.format=function(U){var C=this,M=this.$locale();if(!this.isValid())return M.invalidDate||m;var D=U||"YYYY-MM-DDTHH:mm:ssZ",R=T.z(this),j=this.$H,G=this.$m,W=this.$M,q=M.weekdays,F=M.months,L=M.meridiem,x=function(H,Y,Z,K){return H&&(H[Y]||H(C,D))||Z[Y].slice(0,K)},B=function(H){return T.s(j%12||12,H,"0")},z=L||function(H,Y,Z){var K=H<12?"AM":"PM";return Z?K.toLowerCase():K};return D.replace(g,function(H,Y){return Y||function(Z){switch(Z){case"YY":return String(C.$y).slice(-2);case"YYYY":return T.s(C.$y,4,"0");case"M":return W+1;case"MM":return T.s(W+1,2,"0");case"MMM":return x(M.monthsShort,W,F,3);case"MMMM":return x(F,W);case"D":return C.$D;case"DD":return T.s(C.$D,2,"0");case"d":return String(C.$W);case"dd":return x(M.weekdaysMin,C.$W,q,2);case"ddd":return x(M.weekdaysShort,C.$W,q,3);case"dddd":return q[C.$W];case"H":return String(j);case"HH":return T.s(j,2,"0");case"h":return B(1);case"hh":return B(2);case"a":return z(j,G,!0);case"A":return z(j,G,!1);case"m":return String(G);case"mm":return T.s(G,2,"0");case"s":return String(C.$s);case"ss":return T.s(C.$s,2,"0");case"SSS":return T.s(C.$ms,3,"0");case"Z":return R}return null}(H)||R.replace(":","")})},A.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},A.diff=function(U,C,M){var D,R=this,j=T.p(C),G=w(U),W=(G.utcOffset()-this.utcOffset())*n,q=this-G,F=function(){return T.m(R,G)};switch(j){case v:D=F()/12;break;case p:D=F();break;case d:D=F()/3;break;case u:D=(q-W)/6048e5;break;case c:D=(q-W)/864e5;break;case l:D=q/o;break;case a:D=q/n;break;case s:D=q/r;break;default:D=q}return M?D:T.a(D)},A.daysInMonth=function(){return this.endOf(p).$D},A.$locale=function(){return S[this.$L]},A.locale=function(U,C){if(!U)return this.$L;var M=this.clone(),D=b(U,C,!0);return D&&(M.$L=D),M},A.clone=function(){return T.w(this.$d,this)},A.toDate=function(){return new Date(this.valueOf())},A.toJSON=function(){return this.isValid()?this.toISOString():null},A.toISOString=function(){return this.$d.toISOString()},A.toString=function(){return this.$d.toUTCString()},E}(),N=$.prototype;return w.prototype=N,[["$ms",i],["$s",s],["$m",a],["$H",l],["$W",c],["$M",p],["$y",v],["$D",f]].forEach(function(E){N[E[1]]=function(A){return this.$g(A,E[0],E[1])}}),w.extend=function(E,A){return E.$i||(E(A,$,w),E.$i=!0),w},w.locale=b,w.isDayjs=O,w.unix=function(E){return w(1e3*E)},w.en=S[y],w.Ls=S,w.p={},w})})(AR);var E0e=AR.exports;const $0e=Eg(E0e);function N0e({matchUp:t,eventHandlers:e}){const{scheduledTime:r,scheduledDate:n,venueAbbreviation:o,courtName:i}=(t==null?void 0:t.schedule)||{},{dateTime:{extractDate:s,extractTime:a}}=fg,l=a(r);let u=s(n),p="ddd D MMMM";l&&(p+=", hh:mm A",u+=`T${l}`);const d=n?$0e(u).format(p):"Not scheduled",v=o&&(i==null?void 0:i.toString().startsWith(o))&&i||o&&i&&`${o} ${i}`||i||o||"",f=document.createElement("div");f.className=w0e(),f.onclick=e==null?void 0:e.scheduleClick;const m=document.createElement("div");m.innerHTML=d,f.append(m);const h=_=>{typeof(e==null?void 0:e.venueClick)=="function"&&(_.stopPropagation(),e.venueClick({matchUp:t,event:_}))},g=document.createElement("div");return g.onclick=h,g.innerHTML=v,f.append(g),f}function CR({eventHandlers:t,composition:e,sideNumber:r,className:n,matchUp:o}){var v,f;const i=(e==null?void 0:e.configuration)||{},s=i==null?void 0:i.scheduleInfo,a=(v=o==null?void 0:o.score)==null?void 0:v.scoreStringSide1,l=((f=e==null?void 0:e.configuration)==null?void 0:f.scoreBox)&&a,c=(o==null?void 0:o.readyToScore)&&(t==null?void 0:t.scoreClick)&&!fg.scoreHasValue({matchUp:o}),u=document.createElement("div");if(u.className=Zi(t0e(),n),s&&r===1){const m=N0e({matchUp:o,eventHandlers:t});u.appendChild(m)}const p=document.createElement("div");p.className=r0e();const d=wR({sideContainer:!0,eventHandlers:t,composition:e,sideNumber:r,matchUp:o});if(p.appendChild(d),l){const m=document.createElement("div");m.style.border="1px solid lightgray",p.appendChild(m)}if(a){const m=T0e({eventHandlers:t,composition:e,sideNumber:r,matchUp:o});p.appendChild(m)}if(c){const m=NR(),h=_=>{typeof(t==null?void 0:t.scoreClick)=="function"&&(_.stopPropagation(),t.scoreClick({event:_,matchUp:o}))},g=document.createElement("div");g.className=m({sideNumber:!l&&r,fontSize:"small"}),g.onclick=h,g.innerHTML="[Score]",p.appendChild(g)}return u.appendChild(p),u}function MR(t){const{composition:e,matchUp:r,moeity:n,selectedMatchUpId:o,searchActive:i}=t,{roundFactor:s,roundNumber:a,finishingRound:l,matchUpType:c,preFeedRound:u,stage:p}=r,d=p==="QUALIFYING",v=parseInt(l)===1,f=p==="QUALIFYING"&&v,m=!d&&v,h=parseInt(a)===1,g=c==="DOUBLES",_=(i||r.isRoundRobin||r.collectionId||t.isLucky)&&"mr"||m&&"noProgression"||(f||u)&&"m0"||n&&"m1"||"m2",I=P0e({composition:e,isDoubles:g,roundFactor:s})({isFirstRound:h,link:_}),P=(e==null?void 0:e.configuration)||{},{resultsInfo:y,centerInfo:S}=P||{},O=t.eventHandlers||{},b=A=>{typeof(O==null?void 0:O.matchUpClick)=="function"&&O.matchUpClick({event:A,matchUp:r})},w=document.createElement("div");w.className=Zi(e.theme,t==null?void 0:t.className,"matchup",v0e()),w.onclick=b;const T=document.createElement("div");T.className=m0e({configuration:P});const $=({sideNumber:A})=>{var M,D,R;const U=(R=(D=(M=r==null?void 0:r.sides.find(j=>j.sideNumber===A))==null?void 0:M.participant)==null?void 0:D.entryStatus)==null?void 0:R.replace("_"," ");return I0e({eventHandlers:O,entryStatus:U,sideNumber:A,className:A===2&&I})},N=CR({sideNumber:1,eventHandlers:O,composition:e,matchUp:r}),E=CR({className:!S&&I,sideNumber:2,eventHandlers:O,composition:e,matchUp:r});if(T.appendChild(N),S&&(T.appendChild($({sideNumber:1})),T.appendChild($({sideNumber:2}))),T.appendChild(E),y){const A=U0e({score:r.score});T.appendChild(A)}if(w.appendChild(T),o===r.matchUpId){const A=document.createElement("div");A.className=f0e(),w.appendChild(A)}return w}function U0e({score:t}){var i;const e=(i=t==null?void 0:t.sets)==null?void 0:i.filter(Boolean).sort((s,a)=>(s.setNumber||0)-(a.setNumber||0)),r=e==null?void 0:e[e.length-1],n=(r==null?void 0:r.side1PointsScore)||(r==null?void 0:r.side2PointsScore),o=document.createElement("div");if(o.className=p0e(),n){const s=document.createElement("div");s.className=ER({variant:"points"}),s.innerHTML="PTS",o.appendChild(s)}for(const s of e||[]){const a=document.createElement("div");a.setAttribute("key",s.setNumber),a.className=ER({variant:"set"}),a.innerHTML=s.setNumber,o.appendChild(a)}return o}function A0e({selectedMatchUpId:t,eventHandlers:e,isRoundRobin:r,searchActive:n,composition:o,roundFactor:i,roundNumber:s,roundProfile:a,matchUps:l,isLucky:c}){const u=l.filter(P=>P.roundNumber===s).sort((P,y)=>(P.roundPosition||0)-(y.roundPosition||0)),p=(o==null?void 0:o.configuration)||{},d=document.createElement("div");if(d.className=a0e(),p.roundHeader){const P=u0e({roundProfile:a,roundNumber:s,eventHandlers:e});d.appendChild(P)}const v=document.createElement("div");v.className=d0e();let f,m;if(r){const P=y=>y.reduce((S,O)=>O+S,0);u.sort((y,S)=>P(y.drawPositions)-P(S.drawPositions)),f=Object.values(u.reduce((y,S)=>(y[S.structureId]=S.structureName,y),{})),m=Object.keys(fg.instanceCount(u.map(({structureId:y})=>y))).length}const h=m&&u.length/m,g=Object.keys(a).map(P=>parseInt(P)),_=g.indexOf(s),I=_===0&&"first"||_===g.length-1&&"last";return u.forEach((P,y)=>{const S=h&&!(y%h),O=h&&Math.floor(y/h),b=h&&f[O];if(S){const $=document.createElement("div");$.className=s0e({variant:O,roundOrder:I}),v.appendChild($);const N=document.createElement("div");N.className=l0e(),s===1&&(N.innerHTML=b),v.appendChild(N)}const w=y%2===0;i&&(P.roundFactor=i);const T=MR({selectedMatchUpId:t,eventHandlers:e,searchActive:n,composition:o,matchUp:P,isLucky:c,moeity:w});v.appendChild(T)}),d.appendChild(v),d}function C0e({selectedMatchUpId:t,eventHandlers:e,searchActive:r,composition:n,matchUps:o}){const{roundNumbers:i,roundProfile:s,hasOddMatchUpsCount:a}=pae.getRoundMatchUps({matchUps:o}),l=o.some(({isRoundRobin:p})=>p),c=a,u=document.createElement("div");u.className=i0e();for(const p of i){const d=A0e({selectedMatchUpId:t,eventHandlers:e,isRoundRobin:l,searchActive:r,composition:n,roundNumber:p,roundProfile:s,matchUps:o,isLucky:c});u.appendChild(d)}return u}const DR=Ke({backgroundColor:"$colors$backgroundColor",color:"$colors$color",height:1e3});function M0e({content:t,theme:e}){const r=document.createElement("div");return r.className=e?Zi(DR(),e):DR(),e&&r.classList.add(e),typeof t=="string"?r.innerHTML=t:r.appendChild(t),r}const{createTheme:Ks}=bg({theme:{lineHeights:{scheduleInfo:`${Gc.scheduleInfo}rem`,centerInfo:`${Gc.centerInfo}rem`,gameScore:`${Gc.gameScore}rem`},borderWidths:{matchUpInline:"1px 1px",matchUp:"1px"},space:{1:"10px",2:"0.375rem",gameMarginInlineEnd:"0.25rem"},fontSizes:{1:"0.875rem"},colors:{internalDividers:"lightgray",backgroundColor:"white",connector:"lightgray",border:"darkgray",color:"black"},participant:{textTransform:"capitalize",minHeight:"2rem",seed:"gray"},score:{setWidth:"1.3rem"}}}),jR=Ks("australian-theme",{colors:{borderHover:"#0091d2",connector:"#999"}}),D0e=Ks("wimbledon-theme",{borderWidths:{borderInlineStart:"10px"},colors:{connector:"transparent",borderHover:"darkgrey",border:"#00703c",matchUp:"#fff"},participant:{textTransform:"uppercase"}}),j0e=Ks("french-theme",{colors:{winnerName:"#01503d!important",winner:"#01503d!important",borderHover:"#0091d2",border:"#F8F9F9"},matchUp:{boxShadow:"0 0 30px 0 hsla(0,0%,89%,9)"}}),R0e=Ks("usopen-theme",{colors:{matchUpBackgroundColor:"#F8F9F9",internalDividers:"darkgray",borderHover:"#0091d2",connector:"#999"}}),RR=Ks("basic-theme",{colors:{internalDividers:"transparent",winner:"#50B649!important",loser:"#E61A1A!important",connector:"#999"},space:{gameMarginInlineEnd:"0.75rem"},participant:{seed:"transparent"},fontSizes:{1:"1.5rem"}}),F0e=Ks("dark-theme",{colors:{backgroundColor:"#333333",borderHover:"#0091d2",color:"white"},participant:{seed:"cyan"}}),x0e=Ks("itf-theme",{colors:{borderHover:"#0091d2",connector:"#999",matchUp:"#fff"},participant:{textTransform:"uppercase",seed:"gray"}}),L0e={Australian:{configuration:{flags:!0},theme:jR},Basic:{configuration:{gameScoreOnly:!0,teamLogo:!1,roundHeader:!0},theme:RR},DrawPositions:{configuration:{gameScoreOnly:!0,drawPositions:!0,teamLogo:!1},theme:RR},French:{configuration:{bracketedSeeds:!0,flags:!0},theme:j0e},Wimbledon:{configuration:{resultsInfo:!0,flags:!0},theme:D0e},"US Open":{configuration:{scoreBox:!0,flags:!0},theme:R0e},ITF:{configuration:{winnerChevron:!0,centerInfo:!0,flags:!0,roundHeader:!0},theme:x0e},National:{configuration:{bracketedSeeds:"square",allDrawPositions:!0,drawPositions:!0,scheduleInfo:!0,roundHeader:!0,showAddress:!0},theme:jR},Night:{configuration:{flags:!0},theme:F0e}},V0e=Ke({willChange:"opacity",position:"fixed",zIndex:9998,bottom:0,right:0,left:0,top:0}),B0e=Ke({display:"block"}),k0e=Ke({position:"fixed",right:0,left:0}),G0e=Ke({paddingRight:"15px",alignItems:"center",margin:"30px auto",paddingLeft:"15px",position:"fixed",height:"100vh",display:"flex",width:"100%",zIndex:9999,bottom:0,right:0,left:0,top:0}),W0e=Ke({boxShadow:"0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23)",backgroundColor:"white",position:"relative",borderRadius:"3px",minHeight:"auto",width:"100%"}),H0e=Ke({borderBottom:"1px solid rgba(0, 0, 0, 0.1)",alignItems:"center",position:"relative",display:"flex"}),q0e=Ke({fontWeight:"600",fontSize:"20px"}),FR=Ke({borderTop:"1px solid rgba(0, 0, 0, 0.1)",justifyContent:"right",alignItems:"center",position:"relative",display:"flex"}),xR="Nothing to see here";function Rp(t){return typeof t=="function"}function Fp(t){return typeof t=="string"}function LR(t){return Array.isArray(t)}function vg(t){return typeof t=="object"&&!Array.isArray(t)}function z0e(t){if(t)for(;t.firstChild;)t.removeChild(t.firstChild)}const mg=(()=>{const t=k0e(),e={},r=".5";let n=[],o,i=[],s=[],a;const l=g=>{if(g){let _;s=s.filter(I=>(I.id===g&&(_=I),I.id!==g)),_&&document.body.removeChild(_)}else{const _=s.pop();_&&document.body.removeChild(_)}},c=()=>{a&&(a.style.opacity=0,a.style.display="none")},u=g=>{const _=s.length;if(g&&e[_]===!1)return;const I=i.pop(),P=n.pop();Rp(I)&&I({content:P}),document.body.classList.remove(t),document.body.style.top=null,window.scrollTo({top:o,behavior:"instant"}),c(),l()},p=()=>{a=document.createElement("div"),a.className=V0e(),a.id="cmdl-backdrop",a.onclick=()=>u(!0),document.body.appendChild(a)},d=({config:g})=>{o=window.scrollY,document.body.classList.add(t),document.body.style.top=`-${o}px`,a||p(),a.style.display="",(g==null?void 0:g.backdrop)!==!1&&(a.style.backgroundColor="rgba(0, 0, 0, 0.2)",a.style.transition="opacity 0.15s linear",a.style.opacity=1)},v=({config:g,attr:_})=>{if(!Fp(_))return;const I=_.split(".");for(const P of I)if(g=g==null?void 0:g[P],!g)return;return g},f=({config:g,attr:_,attrs:I,unit:P="em",value:y})=>{var O;let S;return Fp(_)?S=v({config:g,attr:_}):LR(I)&&(S=(O=I.map(b=>v({config:g,attr:b})).filter(Boolean))==null?void 0:O[0]),S!==void 0&&(y=S),isNaN(y)?y:`${y}${P}`},m=({buttons:g,config:_,modalNumber:I})=>{var S,O;const P=document.createElement("div");P.className=FR(),P.style.padding=f({config:_,attrs:["footer.padding","padding"],value:r});const y={label:((S=_==null?void 0:_.dictionary)==null?void 0:S.close)||"Close",onClick:mg.close,intent:"is-info"};for(const b of g){if(b.hide)continue;const w=Object.assign({},y);vg(b)&&Object.assign(w,b);const T=document.createElement("button");w.disabled!==void 0&&(T.disabled=w.disabled),w.id&&(T.id=w.id),T.className=((O=w==null?void 0:w.footer)==null?void 0:O.className)||"button font-medium",T.classList.add(w.intent),T.style="margin-right: .5em;",T.innerHTML=w.label||w.text,T.onclick=$=>{$.stopPropagation(),Rp(w.onClick)&&w.onClick({e:$,content:n[I]}),w.close!==!1&&(Rp(w.close)&&w.close(),mg.close())},P.appendChild(T)}return P};return{close:u,open:({title:g="",content:_,buttons:I,footer:P,config:y,onClose:S}={})=>{d({config:y}),i.push(S);const O=s.length+1;e[O]=y==null?void 0:y.clickAway;const b=document.createElement("section"),w=`cmdl-${O}`;b.className=B0e(),b.role="dialog",b.tabIndex=-1,b.id=w;const T=document.createElement("div");T.className=G0e(),T.style.maxWidth=`${(y==null?void 0:y.maxWidth)||450}px`,T.onclick=()=>u(!0);const $=document.createElement("div");$.className=W0e(),$.onclick=j=>j.stopPropagation();const N=document.createElement("div"),E=document.createElement("div");N.appendChild(E),$.appendChild(N);const A=({title:j,config:G})=>{N.className=j?H0e():"",N.style.padding=f({config:G,attrs:["title.padding","padding"],value:r}),E.className=j?q0e():"",E.innerHTML=j};g&&A({title:g});const U=document.createElement("div");$.appendChild(U);const C=({content:j,config:G})=>{U.style.fontSize=f({config:G,attr:"fontSize",value:"15px"}),U.style.position="relative",U.style.padding=f({config:G,attrs:["content.padding","padding"],value:r}),Rp(j)?n[O]=j(U):vg(j)?U.appendChild(j):Fp(j)?U.innerHTML=j:U.innerHTML=xR};if(C({content:_,config:y}),LR(I))P=m({buttons:I,config:y,modalNumber:O}),$.appendChild(P);else if(P){const j=document.createElement("div");j.className=FR(),j.style.padding=f({config:y,attrs:["footer.padding","padding"]}),vg(P)?j.appendChild(P):Fp(P)?j.innerHTML=P:j.innerHTML=xR,$.appendChild(j)}T.appendChild($),b.appendChild(T),document.body.appendChild(b),s.push(b);const M=({content:j,config:G})=>{n[O]=void 0,z0e(U),C({content:j,config:G})},D=({buttons:j,config:G})=>{$.removeChild(P),P=m({buttons:j,config:G,modalNumber:O}),$.appendChild(P)};return{setContent:M,setButtons:D,update:({content:j,buttons:G,title:W,config:q})=>{y=q||y,j&&M({content:j,config:y}),G&&D({buttons:G,config:y}),W&&A({title:W,config:y})}}}}})();ro.cModal=mg,ro.compositions=L0e,ro.renderContainer=M0e,ro.renderMatchUp=MR,ro.renderParticipant=wR,ro.renderStructure=C0e,Object.defineProperty(ro,Symbol.toStringTag,{value:"Module"})});