tods-competition-factory 2.0.0-beta.4 → 2.0.0-beta.6

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.0.0-beta.4';
6
+ return '2.0.0-beta.6';
7
7
  }
8
8
 
9
9
  /******************************************************************************
@@ -18229,17 +18229,6 @@ function assignMatchUpDrawPosition(_a) {
18229
18229
  }
18230
18230
  }
18231
18231
 
18232
- function getNumericSeedValue(seedValue) {
18233
- if (!seedValue)
18234
- return Infinity;
18235
- if (isConvertableInteger(seedValue))
18236
- return ensureInt(seedValue);
18237
- var firstValue = seedValue.split('-')[0];
18238
- if (isConvertableInteger(firstValue))
18239
- return ensureInt(firstValue);
18240
- return Infinity;
18241
- }
18242
-
18243
18232
  function getRoundRobinGroupMatchUps(_a) {
18244
18233
  var drawPositions = _a.drawPositions;
18245
18234
  var positionMatchUps = function (position) {
@@ -18592,6 +18581,17 @@ function getSeedingThresholds(_a) {
18592
18581
  return __assign(__assign({}, SUCCESS), { seedingThresholds: seedingThresholds });
18593
18582
  }
18594
18583
 
18584
+ function getNumericSeedValue(seedValue) {
18585
+ if (!seedValue)
18586
+ return Infinity;
18587
+ if (isConvertableInteger(seedValue))
18588
+ return ensureInt(seedValue);
18589
+ var firstValue = seedValue.split('-')[0];
18590
+ if (isConvertableInteger(firstValue))
18591
+ return ensureInt(firstValue);
18592
+ return Infinity;
18593
+ }
18594
+
18595
18595
  function getDivisions(_a) {
18596
18596
  var size = _a.size;
18597
18597
  var divisions = [size];
@@ -18641,7 +18641,7 @@ function generateBlockPattern(_a) {
18641
18641
  var firstMember = function (arr) { return arr[0]; };
18642
18642
  var lastMember = function (arr) { return arr[arr.length - 1]; };
18643
18643
  var getMember = function (arr, i) {
18644
- return (positioning === CLUSTER && i % 2 ? lastMember(arr) : firstMember(arr)) ||
18644
+ return (positioning && [CLUSTER, WATERFALL].includes(positioning) && i % 2 ? lastMember(arr) : firstMember(arr)) ||
18645
18645
  firstMember(arr);
18646
18646
  };
18647
18647
  var noneSelected = function (chunk, i) {
@@ -18756,9 +18756,7 @@ function getValidSeedBlocks(_a) {
18756
18756
  var firstRoundSeedsCount = isLuckyStructure
18757
18757
  ? 0
18758
18758
  : (!isFeedIn && countLimit) ||
18759
- (countLimit &&
18760
- fedSeedBlockPositions.length < countLimit &&
18761
- countLimit - fedSeedBlockPositions.length) ||
18759
+ (countLimit && fedSeedBlockPositions.length < countLimit && countLimit - fedSeedBlockPositions.length) ||
18762
18760
  0;
18763
18761
  if (qualifyingBlocks) {
18764
18762
  var seedingBlocksCount = (structure === null || structure === void 0 ? void 0 : structure.matchUps)
@@ -18883,9 +18881,7 @@ function getSeedBlockPattern(_a) {
18883
18881
  var block = drawPositionBlocks[blockIndex].slice();
18884
18882
  var consideredDrawPositions = block.filter(function (drawPosition, i) { return relativePositions.includes(i + 1) && drawPosition; });
18885
18883
  if (positioning !== WATERFALL) {
18886
- consideredDrawPositions = nonRandom
18887
- ? consideredDrawPositions
18888
- : shuffleArray(consideredDrawPositions);
18884
+ consideredDrawPositions = nonRandom ? consideredDrawPositions : shuffleArray(consideredDrawPositions);
18889
18885
  }
18890
18886
  else if (i % 2) {
18891
18887
  consideredDrawPositions.reverse();
@@ -18894,8 +18890,8 @@ function getSeedBlockPattern(_a) {
18894
18890
  if (drawPosition) {
18895
18891
  assignedPositions.push(drawPosition);
18896
18892
  validSeedBlocks.push({
18897
- seedNumbers: [seedNumber],
18898
18893
  drawPositions: [drawPosition],
18894
+ seedNumbers: [seedNumber],
18899
18895
  });
18900
18896
  }
18901
18897
  });
@@ -18954,9 +18950,7 @@ function isValidSeedPosition(_a) {
18954
18950
  if ((_d = (_c = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.seeding) === null || _c === void 0 ? void 0 : _c.validSeedPositions) === null || _d === void 0 ? void 0 : _d.ignore)
18955
18951
  return true;
18956
18952
  if ((_f = (_e = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.seeding) === null || _e === void 0 ? void 0 : _e.validSeedPositions) === null || _f === void 0 ? void 0 : _f.strict) {
18957
- var targetSeedBlock = validSeedBlocks.find(function (seedBlock) {
18958
- return seedBlock.seedNumbers.includes(seedNumber);
18959
- });
18953
+ var targetSeedBlock = validSeedBlocks.find(function (seedBlock) { return seedBlock.seedNumbers.includes(seedNumber); });
18960
18954
  var validSeedPositions_1 = (targetSeedBlock === null || targetSeedBlock === void 0 ? void 0 : targetSeedBlock.drawPositions) || [];
18961
18955
  return validSeedPositions_1.includes(drawPosition);
18962
18956
  }
@@ -19015,16 +19009,12 @@ function getNextSeedBlock(params) {
19015
19009
  return participantId;
19016
19010
  })
19017
19011
  .filter(Boolean);
19018
- var placedSeedNumbers = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) {
19019
- return placedSeedParticipantIds === null || placedSeedParticipantIds === void 0 ? void 0 : placedSeedParticipantIds.includes(assignment.participantId);
19020
- }).map(function (assignment) { return assignment.seedNumber; });
19012
+ var placedSeedNumbers = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) { return placedSeedParticipantIds === null || placedSeedParticipantIds === void 0 ? void 0 : placedSeedParticipantIds.includes(assignment.participantId); }).map(function (assignment) { return assignment.seedNumber; });
19021
19013
  var blockSeedNumbers = (nextSeedBlock === null || nextSeedBlock === void 0 ? void 0 : nextSeedBlock.seedNumbers) || [];
19022
19014
  // unplacedSeedNumbers and unplacedSeedNumberIds will only be used
19023
19015
  // when policy specifies that seedNumbers/seedValues must be unique
19024
19016
  var unplacedSeedNumbers = blockSeedNumbers.filter(function (seedNumber) { return !(placedSeedNumbers === null || placedSeedNumbers === void 0 ? void 0 : placedSeedNumbers.includes(seedNumber)); });
19025
- var unplacedSeedNumberIds = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) {
19026
- return unplacedSeedNumbers.includes(assignment.seedNumber);
19027
- }).map(function (assignment) { return assignment.participantId; });
19017
+ var unplacedSeedNumberIds = seedAssignments === null || seedAssignments === void 0 ? void 0 : seedAssignments.filter(function (assignment) { return unplacedSeedNumbers.includes(assignment.seedNumber); }).map(function (assignment) { return assignment.participantId; });
19028
19018
  var duplicateSeedNumbers = (_c = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.seeding) === null || _c === void 0 ? void 0 : _c.duplicateSeedNumbers;
19029
19019
  var allowsDuplicateSeedNumbers = duplicateSeedNumbers !== undefined ? duplicateSeedNumbers : true;
19030
19020
  var unplacedSeedParticipantIds = allowsDuplicateSeedNumbers
@@ -19039,12 +19029,8 @@ function getNextSeedBlock(params) {
19039
19029
  };
19040
19030
  function randomlySelectLowestSeedValue(assignments, selectedParticipantIds) {
19041
19031
  var filteredAssignments = assignments.filter(function (assignment) { return !selectedParticipantIds.includes(assignment.participantId); });
19042
- var lowestSeedValue = Math.min.apply(Math, __spreadArray([], __read(filteredAssignments.map(function (assignment) {
19043
- return getNumericSeedValue(assignment.seedValue);
19044
- })), false));
19045
- var assignmentsWithLowestSeedValue = filteredAssignments.filter(function (assignment) {
19046
- return getNumericSeedValue(assignment.seedValue) === lowestSeedValue;
19047
- });
19032
+ var lowestSeedValue = Math.min.apply(Math, __spreadArray([], __read(filteredAssignments.map(function (assignment) { return getNumericSeedValue(assignment.seedValue); })), false));
19033
+ var assignmentsWithLowestSeedValue = filteredAssignments.filter(function (assignment) { return getNumericSeedValue(assignment.seedValue) === lowestSeedValue; });
19048
19034
  var randomizedAssignments = shuffleArray(assignmentsWithLowestSeedValue);
19049
19035
  return randomizedAssignments.pop();
19050
19036
  }
@@ -19078,9 +19064,7 @@ function assignSeed(_a) {
19078
19064
  context: { participantId: participantId },
19079
19065
  stack: stack,
19080
19066
  });
19081
- var flightsCount = event
19082
- ? (_c = (_b = getFlightProfile({ event: event }).flightProfile) === null || _b === void 0 ? void 0 : _b.flights) === null || _c === void 0 ? void 0 : _c.length
19083
- : 0;
19067
+ var flightsCount = event ? (_c = (_b = getFlightProfile({ event: event }).flightProfile) === null || _b === void 0 ? void 0 : _b.flights) === null || _c === void 0 ? void 0 : _c.length : 0;
19084
19068
  var flighted = flightsCount && flightsCount > 1;
19085
19069
  var relevantAssignment = positionAssignments === null || positionAssignments === void 0 ? void 0 : positionAssignments.find(function (assignment) { return assignment.participantId === participantId; });
19086
19070
  var assignedDrawPosition = relevantAssignment === null || relevantAssignment === void 0 ? void 0 : relevantAssignment.drawPosition;
@@ -19106,8 +19090,7 @@ function assignSeed(_a) {
19106
19090
  var success;
19107
19091
  seedAssignments.forEach(function (assignment) {
19108
19092
  // ensure that this participantId is not assigned to any other seedNumber
19109
- if (assignment.participantId === participantId &&
19110
- assignment.seedNumber !== seedNumber) {
19093
+ if (assignment.participantId === participantId && assignment.seedNumber !== seedNumber) {
19111
19094
  assignment.participantId = undefined;
19112
19095
  }
19113
19096
  // assign participantId to target seedNumber
@@ -20262,7 +20245,11 @@ function ensureSideLineUps(_a) {
20262
20245
  var lineUps_1 = makeDeepCopy((extension === null || extension === void 0 ? void 0 : extension.value) || {}, false, true);
20263
20246
  var extractSideDetail_1 = function (_a) {
20264
20247
  var displaySideNumber = _a.displaySideNumber, drawPosition = _a.drawPosition, sideNumber = _a.sideNumber;
20265
- return ({ drawPosition: drawPosition, sideNumber: sideNumber, displaySideNumber: displaySideNumber });
20248
+ return ({
20249
+ drawPosition: drawPosition,
20250
+ sideNumber: sideNumber,
20251
+ displaySideNumber: displaySideNumber,
20252
+ });
20266
20253
  };
20267
20254
  dualMatchUp.sides = (_c = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _c === void 0 ? void 0 : _c.map(function (contextSide) {
20268
20255
  var _a, _b;
@@ -20272,9 +20259,7 @@ function ensureSideLineUps(_a) {
20272
20259
  var sideNumber = _a.sideNumber;
20273
20260
  return sideNumber === contextSide.sideNumber;
20274
20261
  })) !== null && _b !== void 0 ? _b : {}, noContextLineUp = _c.lineUp, noContextSideDetail = __rest(_c, ["lineUp"]);
20275
- var lineUp = (noContextLineUp === null || noContextLineUp === void 0 ? void 0 : noContextLineUp.length)
20276
- ? noContextLineUp
20277
- : referenceLineUp;
20262
+ var lineUp = (noContextLineUp === null || noContextLineUp === void 0 ? void 0 : noContextLineUp.length) ? noContextLineUp : referenceLineUp;
20278
20263
  return __assign(__assign(__assign({}, extractSideDetail_1(contextSide)), noContextSideDetail), { lineUp: lineUp });
20279
20264
  });
20280
20265
  modifyMatchUpNotice({
@@ -20849,7 +20834,7 @@ function validNationalityCode(code) {
20849
20834
 
20850
20835
  function assignTieMatchUpParticipantId(params) {
20851
20836
  var e_1, _a;
20852
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
20837
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
20853
20838
  var matchUpContext = getTieMatchUpContext(params);
20854
20839
  if (matchUpContext.error)
20855
20840
  return matchUpContext;
@@ -20863,12 +20848,7 @@ function assignTieMatchUpParticipantId(params) {
20863
20848
  return decorateResult({ result: { error: INVALID_SIDE_NUMBER }, stack: stack });
20864
20849
  }
20865
20850
  var inContextDualMatchUp = matchUpContext.inContextDualMatchUp, inContextTieMatchUp = matchUpContext.inContextTieMatchUp, relevantAssignments = matchUpContext.relevantAssignments, collectionPosition = matchUpContext.collectionPosition, teamParticipants = matchUpContext.teamParticipants, collectionId = matchUpContext.collectionId, matchUpType = matchUpContext.matchUpType, dualMatchUp = matchUpContext.dualMatchUp, tieFormat = matchUpContext.tieFormat;
20866
- var allTieIndividualParticipantIds = (_b = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _b === void 0 ? void 0 : _b.flatMap(function (side) {
20867
- var _a, _b;
20868
- return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipantIds) ||
20869
- ((_b = side.participant) === null || _b === void 0 ? void 0 : _b.participantId) ||
20870
- [];
20871
- });
20851
+ var allTieIndividualParticipantIds = (_b = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _b === void 0 ? void 0 : _b.flatMap(function (side) { var _a, _b; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipantIds) || ((_b = side.participant) === null || _b === void 0 ? void 0 : _b.participantId) || []; });
20872
20852
  if (allTieIndividualParticipantIds === null || allTieIndividualParticipantIds === void 0 ? void 0 : allTieIndividualParticipantIds.includes(participantId)) {
20873
20853
  return decorateResult({ result: __assign({}, SUCCESS), stack: stack });
20874
20854
  }
@@ -20901,11 +20881,10 @@ function assignTieMatchUpParticipantId(params) {
20901
20881
  return { error: INVALID_PARTICIPANT_TYPE };
20902
20882
  }
20903
20883
  var relevantParticipantIds = participantType === INDIVIDUAL ? [participantId] : individualParticipantIds;
20904
- var participantTeam = (teamParticipantId &&
20905
- (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20906
- var participantId = _a.participantId;
20907
- return participantId === teamParticipantId;
20908
- }))) ||
20884
+ var participantTeam = (teamParticipantId && (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20885
+ var participantId = _a.participantId;
20886
+ return participantId === teamParticipantId;
20887
+ }))) ||
20909
20888
  (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20910
20889
  var individualParticipantIds = _a.individualParticipantIds;
20911
20890
  return overlap(relevantParticipantIds, individualParticipantIds);
@@ -20918,12 +20897,13 @@ function assignTieMatchUpParticipantId(params) {
20918
20897
  return { error: PARTICIPANT_NOT_FOUND };
20919
20898
  var teamAssignment = relevantAssignments === null || relevantAssignments === void 0 ? void 0 : relevantAssignments.find(function (assignment) { return assignment.participantId === (participantTeam === null || participantTeam === void 0 ? void 0 : participantTeam.participantId); });
20920
20899
  var teamDrawPosition = teamAssignment === null || teamAssignment === void 0 ? void 0 : teamAssignment.drawPosition;
20921
- var teamSide = (_o = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _o === void 0 ? void 0 : _o.find(function (side) { return side.drawPosition === teamDrawPosition; });
20922
- var sideNumber = (_p = params.sideNumber) !== null && _p !== void 0 ? _p : teamSide === null || teamSide === void 0 ? void 0 : teamSide.sideNumber;
20900
+ var dualTeamSideNumber = (_p = (_o = dualMatchUp === null || dualMatchUp === void 0 ? void 0 : dualMatchUp.sides) === null || _o === void 0 ? void 0 : _o.find(function (side) { return side.participantId === teamParticipantId; })) === null || _p === void 0 ? void 0 : _p.sideNumber;
20901
+ var teamSideNumber = (_r = (_q = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _q === void 0 ? void 0 : _q.find(function (side) { return teamDrawPosition && side.drawPosition === teamDrawPosition; })) === null || _r === void 0 ? void 0 : _r.sideNumber;
20902
+ var sideNumber = (_s = dualTeamSideNumber !== null && dualTeamSideNumber !== void 0 ? dualTeamSideNumber : teamSideNumber) !== null && _s !== void 0 ? _s : params.sideNumber;
20923
20903
  if (!tieFormat) {
20924
20904
  return { error: MISSING_TIE_FORMAT };
20925
20905
  }
20926
- var collectionDefinition = (_q = tieFormat.collectionDefinitions) === null || _q === void 0 ? void 0 : _q.find(function (collectionDefinition) { return collectionDefinition.collectionId === collectionId; });
20906
+ var collectionDefinition = (_t = tieFormat.collectionDefinitions) === null || _t === void 0 ? void 0 : _t.find(function (collectionDefinition) { return collectionDefinition.collectionId === collectionId; });
20927
20907
  if (!collectionDefinition)
20928
20908
  return { error: MISSING_COLLECTION_DEFINITION };
20929
20909
  ensureSideLineUps({
@@ -20933,12 +20913,12 @@ function assignTieMatchUpParticipantId(params) {
20933
20913
  drawDefinition: drawDefinition,
20934
20914
  dualMatchUp: dualMatchUp,
20935
20915
  });
20936
- var dualMatchUpSide = (_r = dualMatchUp === null || dualMatchUp === void 0 ? void 0 : dualMatchUp.sides) === null || _r === void 0 ? void 0 : _r.find(function (side) { return side.sideNumber === sideNumber; });
20937
- var tieMatchUpSide = (_s = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _s === void 0 ? void 0 : _s.find(function (side) { return side.sideNumber === sideNumber; });
20938
- var lineUp = (_t = dualMatchUpSide === null || dualMatchUpSide === void 0 ? void 0 : dualMatchUpSide.lineUp) !== null && _t !== void 0 ? _t : (_u = getTeamLineUp({
20916
+ var dualMatchUpSide = (_u = dualMatchUp === null || dualMatchUp === void 0 ? void 0 : dualMatchUp.sides) === null || _u === void 0 ? void 0 : _u.find(function (side) { return side.sideNumber === sideNumber; });
20917
+ var tieMatchUpSide = (_v = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _v === void 0 ? void 0 : _v.find(function (side) { return side.sideNumber === sideNumber; });
20918
+ var lineUp = (_w = dualMatchUpSide === null || dualMatchUpSide === void 0 ? void 0 : dualMatchUpSide.lineUp) !== null && _w !== void 0 ? _w : (_x = getTeamLineUp({
20939
20919
  participantId: teamParticipantId,
20940
20920
  drawDefinition: drawDefinition,
20941
- })) === null || _u === void 0 ? void 0 : _u.lineUp;
20921
+ })) === null || _x === void 0 ? void 0 : _x.lineUp;
20942
20922
  var targetAssignments = lineUp === null || lineUp === void 0 ? void 0 : lineUp.filter(function (participantAssignment) {
20943
20923
  var _a;
20944
20924
  return (_a = participantAssignment.collectionAssignments) === null || _a === void 0 ? void 0 : _a.find(function (assignment) {
@@ -20950,9 +20930,7 @@ function assignTieMatchUpParticipantId(params) {
20950
20930
  var assignedParticipantIds = targetAssignments === null || targetAssignments === void 0 ? void 0 : targetAssignments.map(function (assignment) { return assignment === null || assignment === void 0 ? void 0 : assignment.participantId; });
20951
20931
  // participantIds is an array of ids for individual team participants whose assignments should be modified
20952
20932
  var participantIds = ((assignedParticipantIds === null || assignedParticipantIds === void 0 ? void 0 : assignedParticipantIds.length) > 1 && assignedParticipantIds) ||
20953
- (participantType === PAIR
20954
- ? participantToAssign.individualParticipantIds
20955
- : [participantId]);
20933
+ (participantType === PAIR ? participantToAssign.individualParticipantIds : [participantId]);
20956
20934
  // first filter out any collectionAssignment with equivalent collectionId/collectionPosition/participantId
20957
20935
  var removeResult = removeCollectionAssignments({
20958
20936
  collectionPosition: collectionPosition,
@@ -21156,8 +21134,7 @@ function removeTieMatchUpParticipantId(params) {
21156
21134
  if (!side)
21157
21135
  return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND }, stack: stack });
21158
21136
  if (!((_g = side.substitutions) === null || _g === void 0 ? void 0 : _g.length) &&
21159
- (checkScoreHasValue({ score: inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.score }) ||
21160
- (inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.winningSide)))
21137
+ (checkScoreHasValue({ score: inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.score }) || (inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.winningSide)))
21161
21138
  return decorateResult({ result: { error: EXISTING_OUTCOME }, stack: stack });
21162
21139
  var teamParticipantId = (_j = (_h = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _h === void 0 ? void 0 : _h.find(function (_a) {
21163
21140
  var sideNumber = _a.sideNumber;
@@ -21175,9 +21152,7 @@ function removeTieMatchUpParticipantId(params) {
21175
21152
  if (matchUpType === SINGLES && participantToRemove.participantType === PAIR) {
21176
21153
  return decorateResult({ result: { error: INVALID_PARTICIPANT }, stack: stack });
21177
21154
  }
21178
- var participantIds = participantToRemove.participantType === INDIVIDUAL
21179
- ? [participantId]
21180
- : participantToRemove.individualParticipantIds;
21155
+ var participantIds = participantToRemove.participantType === INDIVIDUAL ? [participantId] : participantToRemove.individualParticipantIds;
21181
21156
  ensureSideLineUps({
21182
21157
  tournamentId: tournamentRecord.tournamentId,
21183
21158
  eventId: event.eventId,
@@ -21189,11 +21164,10 @@ function removeTieMatchUpParticipantId(params) {
21189
21164
  var sideNumber = _a.sideNumber;
21190
21165
  return sideNumber === side.sideNumber;
21191
21166
  });
21192
- if (!dualMatchUpSide &&
21193
- (((_o = dualMatchUp.sides) === null || _o === void 0 ? void 0 : _o.filter(function (_a) {
21194
- var lineUp = _a.lineUp;
21195
- return !lineUp;
21196
- }).length) || 0) < 2) {
21167
+ if (!dualMatchUpSide && (((_o = dualMatchUp.sides) === null || _o === void 0 ? void 0 : _o.filter(function (_a) {
21168
+ var lineUp = _a.lineUp;
21169
+ return !lineUp;
21170
+ }).length) || 0) < 2) {
21197
21171
  var drawPositionMap_1 = teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.map(function (_a) {
21198
21172
  var _b;
21199
21173
  var teamParticipantId = _a.participantId;
@@ -21207,7 +21181,8 @@ function removeTieMatchUpParticipantId(params) {
21207
21181
  return ((_a = drawPositionMap_1 === null || drawPositionMap_1 === void 0 ? void 0 : drawPositionMap_1.find(function (_a) {
21208
21182
  var drawPosition = _a.drawPosition;
21209
21183
  return drawPosition === side.drawPosition;
21210
- })) === null || _a === void 0 ? void 0 : _a.teamParticipantId) === teamParticipantId;
21184
+ })) === null || _a === void 0 ? void 0 : _a.teamParticipantId) ===
21185
+ teamParticipantId;
21211
21186
  });
21212
21187
  }
21213
21188
  if (!dualMatchUpSide) {
@@ -21234,8 +21209,7 @@ function removeTieMatchUpParticipantId(params) {
21234
21209
  });
21235
21210
  // if an INDIVIDUAL participant is being removed from a DOUBLES matchUp
21236
21211
  // ...then the PAIR participant may need to be modified
21237
- if (matchUpType === DOUBLES &&
21238
- participantToRemove.participantType === INDIVIDUAL) {
21212
+ if (matchUpType === DOUBLES && participantToRemove.participantType === INDIVIDUAL) {
21239
21213
  var tieMatchUpSide = (_q = inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.sides) === null || _q === void 0 ? void 0 : _q.find(function (side) { return side.sideNumber === (dualMatchUpSide === null || dualMatchUpSide === void 0 ? void 0 : dualMatchUpSide.sideNumber); });
21240
21214
  var pairParticipantId = (tieMatchUpSide !== null && tieMatchUpSide !== void 0 ? tieMatchUpSide : {}).participantId;
21241
21215
  var pairParticipant = pairParticipantId &&
@@ -24868,7 +24842,9 @@ function getUnseededByePositions(_a) {
24868
24842
  var relevantMatchUps = structure.structureType === CONTAINER ? matchUps : firstRoundMatchUps;
24869
24843
  var relevantDrawPositions = unique([].concat.apply([], __spreadArray([], __read(relevantMatchUps.map(function (matchUp) { return matchUp.drawPositions; })), false)));
24870
24844
  var drawPositionOffset = Math.min.apply(Math, __spreadArray([], __read(relevantDrawPositions), false)) - 1;
24871
- var filledRelevantDrawPositions = filledDrawPositions === null || filledDrawPositions === void 0 ? void 0 : filledDrawPositions.filter(function (drawPosition) { return relevantDrawPositions.includes(drawPosition); });
24845
+ var filledRelevantDrawPositions = filledDrawPositions === null || filledDrawPositions === void 0 ? void 0 : filledDrawPositions.filter(function (drawPosition) {
24846
+ return relevantDrawPositions.includes(drawPosition);
24847
+ });
24872
24848
  var getHalves = function (chunk) {
24873
24849
  var halfLength = Math.ceil(chunk.length / 2);
24874
24850
  var halves = [chunk.slice(0, halfLength), chunk.slice(halfLength)];
@@ -24888,25 +24864,15 @@ function getUnseededByePositions(_a) {
24888
24864
  var _b = getHalves(greaterHalf), greaterQuarter = _b.greaterHalf, lesserQuarter = _b.lesserHalf;
24889
24865
  var shuffledQuarter = shuffleArray(greaterQuarter.flat(Infinity));
24890
24866
  var drawPosition = shuffledQuarter.pop();
24891
- var diminishedQuarter = greaterQuarter
24892
- .flat()
24893
- .filter(function (position) { return position !== drawPosition; });
24894
- var newlyFilteredChunks = __spreadArray(__spreadArray(__spreadArray([], __read(lesserHalf), false), __read(lesserQuarter), false), [
24895
- diminishedQuarter,
24896
- ], false);
24867
+ var diminishedQuarter = greaterQuarter.flat().filter(function (position) { return position !== drawPosition; });
24868
+ var newlyFilteredChunks = __spreadArray(__spreadArray(__spreadArray([], __read(lesserHalf), false), __read(lesserQuarter), false), [diminishedQuarter], false);
24897
24869
  return { newlyFilteredChunks: newlyFilteredChunks, drawPosition: drawPosition };
24898
24870
  };
24899
- var notSeedByePosition = function (drawPosition) {
24900
- return !seedOrderByePositions.includes(drawPosition);
24901
- };
24902
- var unfilledDrawPosition = function (drawPosition) {
24903
- return !(filledRelevantDrawPositions === null || filledRelevantDrawPositions === void 0 ? void 0 : filledRelevantDrawPositions.includes(drawPosition));
24904
- };
24871
+ var notSeedByePosition = function (drawPosition) { return !seedOrderByePositions.includes(drawPosition); };
24872
+ var unfilledDrawPosition = function (drawPosition) { return !(filledRelevantDrawPositions === null || filledRelevantDrawPositions === void 0 ? void 0 : filledRelevantDrawPositions.includes(drawPosition)); };
24905
24873
  var quarterSeparateBlock = function (block) {
24906
24874
  var sortedChunked = chunkArray(block.sort(numericSort), Math.ceil(block.length / 4));
24907
- var filteredChunks = sortedChunked.map(function (chunk) {
24908
- return chunk.filter(unfilledDrawPosition);
24909
- });
24875
+ var filteredChunks = sortedChunked.map(function (chunk) { return chunk.filter(unfilledDrawPosition); });
24910
24876
  var drawPositionCount = [].concat.apply([], __spreadArray([], __read(filteredChunks.flat(Infinity)), false)).length;
24911
24877
  var orderedDrawPositions = [];
24912
24878
  for (var i = 0; i < drawPositionCount; i++) {
@@ -24926,10 +24892,7 @@ function getUnseededByePositions(_a) {
24926
24892
  drawDefinition: drawDefinition,
24927
24893
  structure: structure,
24928
24894
  }).validSeedBlocks;
24929
- var validBlockDrawPositions = validSeedBlocks === null || validSeedBlocks === void 0 ? void 0 : validSeedBlocks.map(function (block) {
24930
- var _a;
24931
- return (_a = block.drawPositions) === null || _a === void 0 ? void 0 : _a.map(function (drawPosition) { return drawPosition + drawPositionOffset; });
24932
- });
24895
+ var validBlockDrawPositions = validSeedBlocks === null || validSeedBlocks === void 0 ? void 0 : validSeedBlocks.map(function (block) { var _a; return (_a = block.drawPositions) === null || _a === void 0 ? void 0 : _a.map(function (drawPosition) { return drawPosition + drawPositionOffset; }); });
24933
24896
  var unfilledSeedBlocks;
24934
24897
  if (isFeedIn) {
24935
24898
  // FEED_IN structures calculate seedDrawPositions uniquely
@@ -24942,15 +24905,10 @@ function getUnseededByePositions(_a) {
24942
24905
  var blockDrawPositions = seedBlocks.map(function (seedBlock) {
24943
24906
  return seedBlock.map(function (drawPosition) { return drawPosition + drawPositionOffset; });
24944
24907
  });
24945
- unfilledSeedBlocks = blockDrawPositions
24946
- .map(quarterSeparateBlock)
24947
- .filter(function (block) { return block.length; });
24908
+ unfilledSeedBlocks = blockDrawPositions.map(quarterSeparateBlock).filter(function (block) { return block.length; });
24948
24909
  }
24949
24910
  else if (isQualifying) {
24950
- // if qualifying don't quarter/halve separate because seeding is WATERFALL
24951
- unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(function (block) {
24952
- return block.filter(unfilledDrawPosition);
24953
- });
24911
+ unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(function (block) { return block.filter(unfilledDrawPosition); });
24954
24912
  }
24955
24913
  else {
24956
24914
  unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(quarterSeparateBlock).filter(function (block) { return block.length; });
@@ -54637,16 +54595,260 @@ var matchUpActionConstants = {
54637
54595
  END: END,
54638
54596
  };
54639
54597
 
54598
+ function collectionMatchUpActions(_a) {
54599
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
54600
+ var specifiedPolicyDefinitions = _a.specifiedPolicyDefinitions, inContextDrawMatchUps = _a.inContextDrawMatchUps, matchUpParticipantIds = _a.matchUpParticipantIds, matchUpActionsPolicy = _a.matchUpActionsPolicy, inContextMatchUp = _a.inContextMatchUp, policyActions = _a.policyActions, enforceGender = _a.enforceGender, participantId = _a.participantId, sideNumber = _a.sideNumber, matchUpId = _a.matchUpId, matchUp = _a.matchUp, drawId = _a.drawId, side = _a.side;
54601
+ var validActions = [];
54602
+ var firstFoundSide = (_b = inContextMatchUp.sides) === null || _b === void 0 ? void 0 : _b.find(function (side) { return side.participant; });
54603
+ var assignedGender = inContextMatchUp.gender === MIXED &&
54604
+ inContextMatchUp.sideNumber &&
54605
+ ((_c = inContextMatchUp.sides) === null || _c === void 0 ? void 0 : _c.filter(function (side) { return side.particiapntId; }).length) === 1 &&
54606
+ ((_e = (_d = firstFoundSide === null || firstFoundSide === void 0 ? void 0 : firstFoundSide.participant) === null || _d === void 0 ? void 0 : _d.person) === null || _e === void 0 ? void 0 : _e.sex);
54607
+ var matchUpType = inContextMatchUp.matchUpType;
54608
+ var genderEnforced = (enforceGender !== null && enforceGender !== void 0 ? enforceGender : (_f = matchUpActionsPolicy === null || matchUpActionsPolicy === void 0 ? void 0 : matchUpActionsPolicy.participants) === null || _f === void 0 ? void 0 : _f.enforceGender) !== false;
54609
+ var gender = genderEnforced ? inContextMatchUp.gender : undefined;
54610
+ var allParticipants = (_g = inContextMatchUp.sides) === null || _g === void 0 ? void 0 : _g.flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
54611
+ var allParticipantIds = allParticipants === null || allParticipants === void 0 ? void 0 : allParticipants.map(xa('participantId'));
54612
+ var existingParticipants = (_h = inContextMatchUp.sides) === null || _h === void 0 ? void 0 : _h.filter(function (side) { return !sideNumber || side.sideNumber === sideNumber; }).flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
54613
+ var existingParticipantIds = existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.map(xa('participantId'));
54614
+ var inContextDualMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (drawMatchUp) { return drawMatchUp.matchUpId === inContextMatchUp.matchUpTieId; });
54615
+ var availableIndividualParticipants = (_j = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _j === void 0 ? void 0 : _j.map(function (side) {
54616
+ var _a;
54617
+ return (_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants.filter(function (_a) {
54618
+ var participantId = _a.participantId, person = _a.person;
54619
+ return !(existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.includes(participantId)) &&
54620
+ (!gender ||
54621
+ gender === ANY ||
54622
+ person.sex === gender ||
54623
+ // case where one gendered member has been assigned
54624
+ (gender === MIXED && !assignedGender) ||
54625
+ (assignedGender && person.sex !== assignedGender));
54626
+ });
54627
+ });
54628
+ // if no sideNumber is provided, segregate available by sideNumber and specify sideNumber
54629
+ var availableParticipants = sideNumber
54630
+ ? availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]
54631
+ : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54632
+ participants: available,
54633
+ sideNumber: i + 1,
54634
+ }); });
54635
+ var availableParticipantIds = sideNumber
54636
+ ? (_k = availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]) === null || _k === void 0 ? void 0 : _k.map(getParticipantId)
54637
+ : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54638
+ participants: available === null || available === void 0 ? void 0 : available.map(getParticipantId),
54639
+ sideNumber: i + 1,
54640
+ }); });
54641
+ var assignmentAvailable = (sideNumber &&
54642
+ ((matchUpType === SINGLES_MATCHUP && !(existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) ||
54643
+ (matchUpType === DOUBLES_MATCHUP && ((_l = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _l !== void 0 ? _l : 0) < 2))) ||
54644
+ (!sideNumber &&
54645
+ ((matchUpType === SINGLES_MATCHUP && ((_m = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _m !== void 0 ? _m : 0) < 2) ||
54646
+ (matchUpType === DOUBLES_MATCHUP && ((_o = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _o !== void 0 ? _o : 0) < 4)));
54647
+ // extra step to avoid edge case where individual participant is part of both teams
54648
+ var availableIds = availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.filter(function (id) { return !(allParticipantIds === null || allParticipantIds === void 0 ? void 0 : allParticipantIds.includes(id)); });
54649
+ var available = availableParticipants === null || availableParticipants === void 0 ? void 0 : availableParticipants.filter(function (_a) {
54650
+ var participantId = _a.participantId;
54651
+ return availableIds.includes(participantId);
54652
+ });
54653
+ if (assignmentAvailable && (availableIds === null || availableIds === void 0 ? void 0 : availableIds.length)) {
54654
+ validActions.push({
54655
+ availableParticipantIds: availableIds,
54656
+ method: ASSIGN_TEAM_POSITION_METHOD,
54657
+ availableParticipants: available,
54658
+ type: ASSIGN_PARTICIPANT,
54659
+ payload: {
54660
+ participantId: undefined,
54661
+ tieMatchUpId: matchUpId,
54662
+ sideNumber: sideNumber,
54663
+ drawId: drawId,
54664
+ },
54665
+ });
54666
+ }
54667
+ if ((existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) && (!checkScoreHasValue(matchUp) || ((_p = side === null || side === void 0 ? void 0 : side.substitutions) === null || _p === void 0 ? void 0 : _p.length))) {
54668
+ validActions.push({
54669
+ method: REMOVE_TEAM_POSITION_METHOD,
54670
+ type: REMOVE_PARTICIPANT,
54671
+ existingParticipantIds: existingParticipantIds,
54672
+ payload: {
54673
+ participantId: undefined,
54674
+ tieMatchUpId: matchUpId,
54675
+ drawId: drawId,
54676
+ },
54677
+ });
54678
+ }
54679
+ if ((available === null || available === void 0 ? void 0 : available.length) && ((!sideNumber && (existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) || (sideNumber && (side === null || side === void 0 ? void 0 : side.participant)))) {
54680
+ validActions.push({
54681
+ availableParticipantIds: availableIds,
54682
+ method: REPLACE_TEAM_POSITION_METHOD,
54683
+ availableParticipants: available,
54684
+ type: REPLACE_PARTICIPANT,
54685
+ existingParticipantIds: existingParticipantIds,
54686
+ payload: {
54687
+ existingParticipantId: undefined,
54688
+ participantId: undefined,
54689
+ tieMatchUpId: matchUpId,
54690
+ drawId: drawId,
54691
+ },
54692
+ });
54693
+ }
54694
+ if (isAvailableAction({ policyActions: policyActions, action: REMOVE_SUBSTITUTION }) && ((_q = side === null || side === void 0 ? void 0 : side.substitutions) === null || _q === void 0 ? void 0 : _q.length)) {
54695
+ var sideIndividualParticipantIds_1 = (((_r = side.participant) === null || _r === void 0 ? void 0 : _r.participantType) === INDIVIDUAL && [side.participantId]) ||
54696
+ (((_s = side.participant) === null || _s === void 0 ? void 0 : _s.participantType) === PAIR && side.participant.individualParticipantIds) ||
54697
+ [];
54698
+ var substitutedParticipantIds = side.substitutions
54699
+ .map(function (sub) { return sub.participantId; })
54700
+ .filter(function (id) { return sideIndividualParticipantIds_1.includes(id); });
54701
+ if (!participantId || substitutedParticipantIds.includes(participantId)) {
54702
+ validActions.push({
54703
+ method: REMOVE_TEAM_POSITION_METHOD,
54704
+ type: REMOVE_SUBSTITUTION,
54705
+ substitutedParticipantIds: substitutedParticipantIds,
54706
+ payload: {
54707
+ participantId: undefined,
54708
+ tieMatchUpId: matchUpId,
54709
+ drawId: drawId,
54710
+ },
54711
+ });
54712
+ }
54713
+ }
54714
+ var matchUpActionPolicy = specifiedPolicyDefinitions === null || specifiedPolicyDefinitions === void 0 ? void 0 : specifiedPolicyDefinitions[POLICY_TYPE_MATCHUP_ACTIONS];
54715
+ var substituteWithoutScore = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteWithoutScore;
54716
+ var substituteAfterCompleted = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteAfterCompleted;
54717
+ // SUBSTITUTION
54718
+ // substitution is only possible when both sides are present; otherwise => nonsensical
54719
+ if (isAvailableAction({ policyActions: policyActions, action: SUBSTITUTION }) &&
54720
+ matchUpParticipantIds.length === 2 &&
54721
+ ((!sideNumber && (existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) || (sideNumber && (side === null || side === void 0 ? void 0 : side.participant))) &&
54722
+ (substituteWithoutScore || checkScoreHasValue(matchUp)) &&
54723
+ (substituteAfterCompleted ||
54724
+ (matchUp.matchUpStatus && !completedMatchUpStatuses.includes(matchUp.matchUpStatus))) &&
54725
+ (existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.length) &&
54726
+ availableParticipants.length) {
54727
+ // action is not valid if there are no existing assignments or no available substitutions
54728
+ var existingParticipantIds_1 = existingParticipants.map(getParticipantId);
54729
+ validActions.push({
54730
+ info: 'list of team players available for substitution',
54731
+ method: SUBSTITUTION_METHOD,
54732
+ availableParticipantIds: availableParticipantIds,
54733
+ existingParticipantIds: existingParticipantIds_1,
54734
+ availableParticipants: availableParticipants,
54735
+ existingParticipants: existingParticipants,
54736
+ type: SUBSTITUTION,
54737
+ payload: {
54738
+ substituteParticipantId: undefined,
54739
+ existingParticipantId: undefined,
54740
+ sideNumber: sideNumber,
54741
+ matchUpId: matchUpId,
54742
+ drawId: drawId,
54743
+ },
54744
+ });
54745
+ }
54746
+ return validActions;
54747
+ }
54748
+
54749
+ function getEventAlternateParticipantIds(_a) {
54750
+ var eventEntries = _a.eventEntries, structure = _a.structure;
54751
+ var eligibleAlternate = function (entry) { return entry.entryStatus === ALTERNATE && eligibleEntryStage({ structure: structure, entry: entry }); };
54752
+ var entryPositionSort = function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); };
54753
+ return eventEntries.filter(eligibleAlternate).sort(entryPositionSort).map(xa('participantId'));
54754
+ }
54755
+
54756
+ function adHocMatchUpActions(_a) {
54757
+ var _b, _c, _d, _e, _f, _g;
54758
+ var restrictAdHocRoundParticipants = _a.restrictAdHocRoundParticipants, tournamentParticipants = _a.tournamentParticipants, matchUpParticipantIds = _a.matchUpParticipantIds, otherFlightEntries = _a.otherFlightEntries, drawDefinition = _a.drawDefinition, structureId = _a.structureId, sideNumber = _a.sideNumber, matchUpId = _a.matchUpId, structure = _a.structure, matchUp = _a.matchUp, drawId = _a.drawId, event = _a.event;
54759
+ var validActions = [];
54760
+ var roundMatchUps = ((_b = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _b !== void 0 ? _b : []).filter(function (_a) {
54761
+ var roundNumber = _a.roundNumber;
54762
+ return roundNumber === matchUp.roundNumber;
54763
+ });
54764
+ var enteredParticipantIds = (_d = (_c = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _c === void 0 ? void 0 : _c.filter(function (_a) {
54765
+ var entryStatus = _a.entryStatus;
54766
+ return entryStatus && DIRECT_ENTRY_STATUSES.includes(entryStatus);
54767
+ }).map(xa('participantId'))) !== null && _d !== void 0 ? _d : [];
54768
+ var roundAssignedParticipantIds = roundMatchUps
54769
+ .map(function (matchUp) { var _a; return ((_a = matchUp.sides) !== null && _a !== void 0 ? _a : []).flatMap(xa('participantId')); })
54770
+ .flat()
54771
+ .filter(Boolean);
54772
+ var availableParticipantIds = enteredParticipantIds.filter(function (participantId) {
54773
+ return !matchUpParticipantIds.includes(participantId) &&
54774
+ (!restrictAdHocRoundParticipants || !roundAssignedParticipantIds.includes(participantId));
54775
+ });
54776
+ var participantsAvailable = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) { return availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.includes(participant.participantId); }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54777
+ participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
54778
+ var _a;
54779
+ var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === participant.participantId; });
54780
+ // used to sort available participants
54781
+ participant.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54782
+ });
54783
+ if (availableParticipantIds.length) {
54784
+ validActions.push({
54785
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54786
+ method: ASSIGN_SIDE_METHOD,
54787
+ type: ASSIGN_PARTICIPANT,
54788
+ availableParticipantIds: availableParticipantIds,
54789
+ participantsAvailable: participantsAvailable,
54790
+ });
54791
+ }
54792
+ var eventEntries = (_e = event === null || event === void 0 ? void 0 : event.entries) !== null && _e !== void 0 ? _e : [];
54793
+ var availableEventAlternatesParticipantIds = getEventAlternateParticipantIds({ eventEntries: eventEntries, structure: structure });
54794
+ var availableAlternatesParticipantIds = unique(enteredParticipantIds.concat(availableEventAlternatesParticipantIds));
54795
+ if (otherFlightEntries) {
54796
+ var flightProfile = event ? getFlightProfile({ event: event }) : undefined;
54797
+ var otherFlightEnteredParticipantIds = (_f = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _f === void 0 ? void 0 : _f.filter(function (flight) { return flight.drawId !== drawId; }).flatMap(function (flight) {
54798
+ return flight.drawEntries
54799
+ .filter(function (entry) { return entry.participantId && ![WITHDRAWN, UNGROUPED, UNPAIRED].includes(entry.entryStatus); })
54800
+ .map(function (_a) {
54801
+ var participantId = _a.participantId;
54802
+ return participantId;
54803
+ });
54804
+ }).filter(Boolean);
54805
+ if (otherFlightEnteredParticipantIds === null || otherFlightEnteredParticipantIds === void 0 ? void 0 : otherFlightEnteredParticipantIds.length) {
54806
+ // include direct acceptance participants from other flights
54807
+ availableAlternatesParticipantIds.push.apply(availableAlternatesParticipantIds, __spreadArray([], __read(otherFlightEnteredParticipantIds), false));
54808
+ }
54809
+ }
54810
+ availableAlternatesParticipantIds = availableAlternatesParticipantIds.filter(function (participantId) {
54811
+ return !matchUpParticipantIds.includes(participantId) &&
54812
+ !availableParticipantIds.includes(participantId) &&
54813
+ (!restrictAdHocRoundParticipants || !roundAssignedParticipantIds.includes(participantId));
54814
+ });
54815
+ var availableAlternates = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) { return availableAlternatesParticipantIds.includes(participant.participantId); }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54816
+ availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.forEach(function (alternate) {
54817
+ var _a;
54818
+ var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === alternate.participantId; });
54819
+ alternate.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54820
+ });
54821
+ availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.sort(function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); });
54822
+ if (availableAlternatesParticipantIds.length) {
54823
+ validActions.push({
54824
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54825
+ availableParticipantIds: availableAlternatesParticipantIds,
54826
+ participantsAvailable: availableAlternates,
54827
+ method: ASSIGN_SIDE_METHOD,
54828
+ type: ALTERNATE,
54829
+ });
54830
+ }
54831
+ if (!checkScoreHasValue(matchUp) && sideNumber) {
54832
+ var side = (_g = matchUp.sides) === null || _g === void 0 ? void 0 : _g.find(function (side) { return side.sideNumber === sideNumber; });
54833
+ if (side === null || side === void 0 ? void 0 : side.participantId) {
54834
+ validActions.push({
54835
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54836
+ method: REMOVE_SIDE_METHOD,
54837
+ type: REMOVE_PARTICIPANT,
54838
+ });
54839
+ }
54840
+ }
54841
+ return validActions;
54842
+ }
54843
+
54640
54844
  function matchUpActions(params) {
54641
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
54845
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
54642
54846
  if (!params)
54643
54847
  return { error: INVALID_VALUES };
54644
54848
  var drawDefinition, event;
54645
- var _16 = params.restrictAdHocRoundParticipants, restrictAdHocRoundParticipants = _16 === void 0 ? true : _16, // disallow the same participant being in the same round multiple times
54849
+ var _u = params.restrictAdHocRoundParticipants, restrictAdHocRoundParticipants = _u === void 0 ? true : _u, // disallow the same participant being in the same round multiple times
54646
54850
  specifiedPolicyDefinitions = params.policyDefinitions, enforceGender = params.enforceGender, participantId = params.participantId, sideNumber = params.sideNumber, matchUpId = params.matchUpId;
54647
- var tournamentRecord = (_a = params.tournamentRecord) !== null && _a !== void 0 ? _a : (params.tournamentId &&
54648
- isString(params.tournamentId) &&
54649
- ((_b = params.tournamentRecords) === null || _b === void 0 ? void 0 : _b[params.tournamentId]));
54851
+ var tournamentRecord = (_a = params.tournamentRecord) !== null && _a !== void 0 ? _a : (params.tournamentId && isString(params.tournamentId) && ((_b = params.tournamentRecords) === null || _b === void 0 ? void 0 : _b[params.tournamentId]));
54650
54852
  if (!tournamentRecord)
54651
54853
  return { error: MISSING_TOURNAMENT_RECORD };
54652
54854
  if (!matchUpId || !isString(matchUpId))
@@ -54670,11 +54872,11 @@ function matchUpActions(params) {
54670
54872
  withIndividualParticipants: true,
54671
54873
  }).participants;
54672
54874
  var drawId = drawDefinition.drawId;
54673
- var _17 = findDrawMatchUp({
54875
+ var _v = findDrawMatchUp({
54674
54876
  drawDefinition: drawDefinition,
54675
54877
  matchUpId: matchUpId,
54676
54878
  event: event,
54677
- }), matchUp = _17.matchUp, structure = _17.structure;
54879
+ }), matchUp = _v.matchUp, structure = _v.structure;
54678
54880
  if (!matchUp)
54679
54881
  return { error: MATCHUP_NOT_FOUND };
54680
54882
  var appliedPolicies = (_f = getAppliedPolicies({
@@ -54686,7 +54888,6 @@ function matchUpActions(params) {
54686
54888
  Object.assign(appliedPolicies, specifiedPolicyDefinitions !== null && specifiedPolicyDefinitions !== void 0 ? specifiedPolicyDefinitions : {});
54687
54889
  var otherFlightEntries = (_g = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_POSITION_ACTIONS]) === null || _g === void 0 ? void 0 : _g.otherFlightEntries;
54688
54890
  var matchUpActionsPolicy = (_h = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_MATCHUP_ACTIONS]) !== null && _h !== void 0 ? _h : POLICY_MATCHUP_ACTIONS_DEFAULT[POLICY_TYPE_MATCHUP_ACTIONS];
54689
- var isAdHocMatchUp = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
54690
54891
  var enabledStructures = getEnabledStructures({
54691
54892
  actionType: MATCHUP_ACTION,
54692
54893
  appliedPolicies: appliedPolicies,
@@ -54707,108 +54908,31 @@ function matchUpActions(params) {
54707
54908
  event: event,
54708
54909
  }).matchUps;
54709
54910
  var inContextMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (drawMatchUp) { return drawMatchUp.matchUpId === matchUpId; });
54710
- var side = sideNumber &&
54711
- ((_l = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _l === void 0 ? void 0 : _l.find(function (side) { return side.sideNumber === sideNumber; }));
54911
+ var side = sideNumber && ((_l = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _l === void 0 ? void 0 : _l.find(function (side) { return side.sideNumber === sideNumber; }));
54712
54912
  var matchUpParticipantIds = (_o = (_m = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _m === void 0 ? void 0 : _m.map(function (side) { var _a; return side.participantId || ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.participantid); }).filter(Boolean)) !== null && _o !== void 0 ? _o : [];
54713
- var _18 = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _18.assignedPositions, allPositionsAssigned = _18.allPositionsAssigned;
54913
+ var _w = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _w.assignedPositions, allPositionsAssigned = _w.allPositionsAssigned;
54714
54914
  var structureId = (structure !== null && structure !== void 0 ? structure : {}).structureId;
54715
54915
  var validActions = [];
54716
54916
  if (!structureId)
54717
54917
  return { validActions: validActions };
54718
- if (isAdHocMatchUp) {
54719
- var roundMatchUps = ((_p = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _p !== void 0 ? _p : []).filter(function (_a) {
54720
- var roundNumber = _a.roundNumber;
54721
- return roundNumber === matchUp.roundNumber;
54722
- });
54723
- var enteredParticipantIds = (_r = (_q = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _q === void 0 ? void 0 : _q.filter(function (_a) {
54724
- var entryStatus = _a.entryStatus;
54725
- return entryStatus && DIRECT_ENTRY_STATUSES.includes(entryStatus);
54726
- }).map(getParticipantId)) !== null && _r !== void 0 ? _r : [];
54727
- var roundAssignedParticipantIds_1 = roundMatchUps
54728
- .map(function (matchUp) { var _a; return ((_a = matchUp.sides) !== null && _a !== void 0 ? _a : []).flatMap(getParticipantId); })
54729
- .flat()
54730
- .filter(Boolean);
54731
- var availableParticipantIds_1 = enteredParticipantIds.filter(function (participantId) {
54732
- return !matchUpParticipantIds.includes(participantId) &&
54733
- (!restrictAdHocRoundParticipants ||
54734
- !roundAssignedParticipantIds_1.includes(participantId));
54735
- });
54736
- var participantsAvailable = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) {
54737
- return availableParticipantIds_1 === null || availableParticipantIds_1 === void 0 ? void 0 : availableParticipantIds_1.includes(participant.participantId);
54738
- }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54739
- participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
54740
- var _a;
54741
- var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === participant.participantId; });
54742
- // used to sort available participants
54743
- participant.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54744
- });
54745
- if (availableParticipantIds_1.length) {
54746
- validActions.push({
54747
- payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54748
- method: ASSIGN_SIDE_METHOD,
54749
- type: ASSIGN_PARTICIPANT,
54750
- availableParticipantIds: availableParticipantIds_1,
54751
- participantsAvailable: participantsAvailable,
54752
- });
54753
- }
54754
- var eventEntries = (_s = event === null || event === void 0 ? void 0 : event.entries) !== null && _s !== void 0 ? _s : [];
54755
- var availableEventAlternatesParticipantIds = getEventAlternateParticipantIds({ eventEntries: eventEntries, structure: structure });
54756
- var availableAlternatesParticipantIds_1 = unique(enteredParticipantIds.concat(availableEventAlternatesParticipantIds));
54757
- if (otherFlightEntries) {
54758
- var flightProfile = event
54759
- ? getFlightProfile({ event: event })
54760
- : undefined;
54761
- var otherFlightEnteredParticipantIds = (_t = flightProfile === null || flightProfile === void 0 ? void 0 : flightProfile.flights) === null || _t === void 0 ? void 0 : _t.filter(function (flight) { return flight.drawId !== drawId; }).flatMap(function (flight) {
54762
- return flight.drawEntries
54763
- .filter(function (entry) {
54764
- return entry.participantId &&
54765
- ![WITHDRAWN, UNGROUPED, UNPAIRED].includes(entry.entryStatus);
54766
- })
54767
- .map(function (_a) {
54768
- var participantId = _a.participantId;
54769
- return participantId;
54770
- });
54771
- }).filter(Boolean);
54772
- if (otherFlightEnteredParticipantIds === null || otherFlightEnteredParticipantIds === void 0 ? void 0 : otherFlightEnteredParticipantIds.length) {
54773
- // include direct acceptance participants from other flights
54774
- availableAlternatesParticipantIds_1.push.apply(availableAlternatesParticipantIds_1, __spreadArray([], __read(otherFlightEnteredParticipantIds), false));
54775
- }
54776
- }
54777
- availableAlternatesParticipantIds_1 =
54778
- availableAlternatesParticipantIds_1.filter(function (participantId) {
54779
- return !matchUpParticipantIds.includes(participantId) &&
54780
- !availableParticipantIds_1.includes(participantId) &&
54781
- (!restrictAdHocRoundParticipants ||
54782
- !roundAssignedParticipantIds_1.includes(participantId));
54783
- });
54784
- var availableAlternates = tournamentParticipants === null || tournamentParticipants === void 0 ? void 0 : tournamentParticipants.filter(function (participant) {
54785
- return availableAlternatesParticipantIds_1.includes(participant.participantId);
54786
- }).map(function (participant) { return makeDeepCopy(participant, undefined, true); });
54787
- availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.forEach(function (alternate) {
54788
- var _a;
54789
- var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === alternate.participantId; });
54790
- alternate.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54918
+ var isAdHocMatchUp = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
54919
+ var isCollectionMatchUp = matchUp.collectionId;
54920
+ if (isAdHocMatchUp && !isCollectionMatchUp) {
54921
+ var adHocValidActions = adHocMatchUpActions({
54922
+ restrictAdHocRoundParticipants: restrictAdHocRoundParticipants,
54923
+ tournamentParticipants: tournamentParticipants,
54924
+ matchUpParticipantIds: matchUpParticipantIds,
54925
+ otherFlightEntries: otherFlightEntries,
54926
+ drawDefinition: drawDefinition,
54927
+ structureId: structureId,
54928
+ sideNumber: sideNumber,
54929
+ matchUpId: matchUpId,
54930
+ structure: structure,
54931
+ matchUp: matchUp,
54932
+ drawId: drawId,
54933
+ event: event,
54791
54934
  });
54792
- availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.sort(function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); });
54793
- if (availableAlternatesParticipantIds_1.length) {
54794
- validActions.push({
54795
- payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54796
- availableParticipantIds: availableAlternatesParticipantIds_1,
54797
- participantsAvailable: availableAlternates,
54798
- method: ASSIGN_SIDE_METHOD,
54799
- type: ALTERNATE,
54800
- });
54801
- }
54802
- if (!checkScoreHasValue(matchUp) && sideNumber) {
54803
- var side_1 = (_u = matchUp.sides) === null || _u === void 0 ? void 0 : _u.find(function (side) { return side.sideNumber === sideNumber; });
54804
- if (side_1 === null || side_1 === void 0 ? void 0 : side_1.participantId) {
54805
- validActions.push({
54806
- payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54807
- method: REMOVE_SIDE_METHOD,
54808
- type: REMOVE_PARTICIPANT,
54809
- });
54810
- }
54811
- }
54935
+ validActions.push.apply(validActions, __spreadArray([], __read(adHocValidActions), false));
54812
54936
  }
54813
54937
  var structureIsComplete = isCompletedStructure({
54814
54938
  drawDefinition: drawDefinition,
@@ -54816,10 +54940,9 @@ function matchUpActions(params) {
54816
54940
  });
54817
54941
  var participantAssignedDrawPositions = assignedPositions === null || assignedPositions === void 0 ? void 0 : assignedPositions.filter(function (assignment) { return assignment.participantId; }).map(function (assignment) { return assignment.drawPosition; });
54818
54942
  var byeAssignedDrawPositions = assignedPositions === null || assignedPositions === void 0 ? void 0 : assignedPositions.filter(function (assignment) { return assignment.bye; }).map(function (assignment) { return assignment.drawPosition; });
54819
- var isCollectionMatchUp = matchUp.collectionId;
54820
54943
  var isByeMatchUp = matchUp.matchUpStatus === BYE ||
54821
54944
  (!isCollectionMatchUp &&
54822
- ((_v = matchUp.drawPositions) === null || _v === void 0 ? void 0 : _v.reduce(function (isByeMatchUp, drawPosition) {
54945
+ ((_p = matchUp.drawPositions) === null || _p === void 0 ? void 0 : _p.reduce(function (isByeMatchUp, drawPosition) {
54823
54946
  return (byeAssignedDrawPositions === null || byeAssignedDrawPositions === void 0 ? void 0 : byeAssignedDrawPositions.includes(drawPosition)) || isByeMatchUp;
54824
54947
  }, false)));
54825
54948
  if (isByeMatchUp)
@@ -54831,21 +54954,17 @@ function matchUpActions(params) {
54831
54954
  var isInComplete = !isDirectingMatchUpStatus({
54832
54955
  matchUpStatus: matchUp.matchUpStatus,
54833
54956
  });
54834
- var structureScoringPolicies = (_w = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _w === void 0 ? void 0 : _w.structures;
54835
- var stageSpecificPolicies = (structure === null || structure === void 0 ? void 0 : structure.stage) &&
54836
- (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage) &&
54837
- (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage[structure.stage]);
54957
+ var structureScoringPolicies = (_q = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _q === void 0 ? void 0 : _q.structures;
54958
+ var stageSpecificPolicies = (structure === null || structure === void 0 ? void 0 : structure.stage) && (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage) && (structureScoringPolicies === null || structureScoringPolicies === void 0 ? void 0 : structureScoringPolicies.stage[structure.stage]);
54838
54959
  var sequenceSpecificPolicies = (structure === null || structure === void 0 ? void 0 : structure.stageSequence) &&
54839
54960
  (stageSpecificPolicies === null || stageSpecificPolicies === void 0 ? void 0 : stageSpecificPolicies.stageSequence) &&
54840
54961
  stageSpecificPolicies.stageSequence[structure.stageSequence];
54841
- var requireAllPositionsAssigned = ((_x = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _x === void 0 ? void 0 : _x.requireAllPositionsAssigned) ||
54962
+ var requireAllPositionsAssigned = ((_r = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _r === void 0 ? void 0 : _r.requireAllPositionsAssigned) ||
54842
54963
  (stageSpecificPolicies === null || stageSpecificPolicies === void 0 ? void 0 : stageSpecificPolicies.requireAllPositionsAssigned) ||
54843
54964
  (sequenceSpecificPolicies === null || sequenceSpecificPolicies === void 0 ? void 0 : sequenceSpecificPolicies.requireAllPositionsAssigned);
54844
54965
  var scoringActive = !requireAllPositionsAssigned || allPositionsAssigned;
54845
- var hasParticipants = matchUp.sides &&
54846
- matchUp.sides.filter(function (side) { return side === null || side === void 0 ? void 0 : side.participantId; }).length === 2;
54847
- var isDoubleExit = matchUp.matchUpStatus &&
54848
- [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus);
54966
+ var hasParticipants = matchUp.sides && matchUp.sides.filter(function (side) { return side === null || side === void 0 ? void 0 : side.participantId; }).length === 2;
54967
+ var isDoubleExit = matchUp.matchUpStatus && [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus);
54849
54968
  var targetData = positionTargets({
54850
54969
  inContextDrawMatchUps: inContextDrawMatchUps,
54851
54970
  drawDefinition: drawDefinition,
@@ -54856,15 +54975,14 @@ function matchUpActions(params) {
54856
54975
  drawDefinition: drawDefinition,
54857
54976
  targetData: targetData,
54858
54977
  });
54859
- var matchUpDrawPositionsAreAssigned = ((_y = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.drawPositions) === null || _y === void 0 ? void 0 : _y.length) === 2 &&
54978
+ var matchUpDrawPositionsAreAssigned = ((_s = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.drawPositions) === null || _s === void 0 ? void 0 : _s.length) === 2 &&
54860
54979
  inContextMatchUp.drawPositions.every(function (drawPosition) { return participantAssignedDrawPositions === null || participantAssignedDrawPositions === void 0 ? void 0 : participantAssignedDrawPositions.includes(drawPosition); }) &&
54861
- ((_z = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _z === void 0 ? void 0 : _z.length) === 2 &&
54980
+ ((_t = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _t === void 0 ? void 0 : _t.length) === 2 &&
54862
54981
  inContextMatchUp.sides.every(function (_a) {
54863
54982
  var participantId = _a.participantId;
54864
54983
  return participantId;
54865
54984
  });
54866
- var readyToScore = (matchUpDrawPositionsAreAssigned || hasParticipants) &&
54867
- !(isDoubleExit && activeDownstream);
54985
+ var readyToScore = (matchUpDrawPositionsAreAssigned || hasParticipants) && !(isDoubleExit && activeDownstream);
54868
54986
  var addPenaltyAction = {
54869
54987
  method: ADD_PENALTY_METHOD,
54870
54988
  type: ADD_PENALTY,
@@ -54917,162 +55035,22 @@ function matchUpActions(params) {
54917
55035
  }
54918
55036
  }
54919
55037
  if (isCollectionMatchUp && inContextMatchUp) {
54920
- var firstFoundSide = (_0 = inContextMatchUp.sides) === null || _0 === void 0 ? void 0 : _0.find(function (side) { return side.participant; });
54921
- var assignedGender_1 = inContextMatchUp.gender === MIXED &&
54922
- inContextMatchUp.sideNumber &&
54923
- ((_1 = inContextMatchUp.sides) === null || _1 === void 0 ? void 0 : _1.filter(function (side) { return side.particiapntId; }).length) === 1 &&
54924
- ((_3 = (_2 = firstFoundSide === null || firstFoundSide === void 0 ? void 0 : firstFoundSide.participant) === null || _2 === void 0 ? void 0 : _2.person) === null || _3 === void 0 ? void 0 : _3.sex);
54925
- var matchUpType = inContextMatchUp.matchUpType;
54926
- var genderEnforced = (enforceGender !== null && enforceGender !== void 0 ? enforceGender : (_4 = matchUpActionsPolicy === null || matchUpActionsPolicy === void 0 ? void 0 : matchUpActionsPolicy.participants) === null || _4 === void 0 ? void 0 : _4.enforceGender) !==
54927
- false;
54928
- var gender_1 = genderEnforced ? inContextMatchUp.gender : undefined;
54929
- var allParticipants = (_5 = inContextMatchUp.sides) === null || _5 === void 0 ? void 0 : _5.flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
54930
- var allParticipantIds_1 = allParticipants === null || allParticipants === void 0 ? void 0 : allParticipants.map(getParticipantId);
54931
- var existingParticipants = (_6 = inContextMatchUp.sides) === null || _6 === void 0 ? void 0 : _6.filter(function (side) { return !sideNumber || side.sideNumber === sideNumber; }).flatMap(function (side) { var _a; return ((_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants) || side.participant; }).filter(Boolean);
54932
- var existingParticipantIds_1 = existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.map(getParticipantId);
54933
- var inContextDualMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (drawMatchUp) { return drawMatchUp.matchUpId === inContextMatchUp.matchUpTieId; });
54934
- var availableIndividualParticipants = (_7 = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _7 === void 0 ? void 0 : _7.map(function (side) {
54935
- var _a;
54936
- return (_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants.filter(function (_a) {
54937
- var participantId = _a.participantId, person = _a.person;
54938
- return !(existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.includes(participantId)) &&
54939
- (!gender_1 ||
54940
- gender_1 === ANY ||
54941
- person.sex === gender_1 ||
54942
- // case where one gendered member has been assigned
54943
- (gender_1 === MIXED && !assignedGender_1) ||
54944
- (assignedGender_1 && person.sex !== assignedGender_1));
54945
- });
54946
- });
54947
- // if no sideNumber is provided, segregate available by sideNumber and specify sideNumber
54948
- var availableParticipants = sideNumber
54949
- ? availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]
54950
- : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54951
- participants: available,
54952
- sideNumber: i + 1,
54953
- }); });
54954
- var availableParticipantIds = sideNumber
54955
- ? (_8 = availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]) === null || _8 === void 0 ? void 0 : _8.map(getParticipantId)
54956
- : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54957
- participants: available === null || available === void 0 ? void 0 : available.map(getParticipantId),
54958
- sideNumber: i + 1,
54959
- }); });
54960
- var assignmentAvailable = (sideNumber &&
54961
- ((matchUpType === SINGLES_MATCHUP && !(existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length)) ||
54962
- (matchUpType === DOUBLES_MATCHUP &&
54963
- ((_9 = existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) !== null && _9 !== void 0 ? _9 : 0) < 2))) ||
54964
- (!sideNumber &&
54965
- ((matchUpType === SINGLES_MATCHUP &&
54966
- ((_10 = existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) !== null && _10 !== void 0 ? _10 : 0) < 2) ||
54967
- (matchUpType === DOUBLES_MATCHUP &&
54968
- ((_11 = existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) !== null && _11 !== void 0 ? _11 : 0) < 4)));
54969
- // extra step to avoid edge case where individual participant is part of both teams
54970
- var availableIds_1 = availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.filter(function (id) { return !(allParticipantIds_1 === null || allParticipantIds_1 === void 0 ? void 0 : allParticipantIds_1.includes(id)); });
54971
- var available = availableParticipants === null || availableParticipants === void 0 ? void 0 : availableParticipants.filter(function (_a) {
54972
- var participantId = _a.participantId;
54973
- return availableIds_1.includes(participantId);
55038
+ var collectionValidActions = collectionMatchUpActions({
55039
+ specifiedPolicyDefinitions: specifiedPolicyDefinitions,
55040
+ inContextDrawMatchUps: inContextDrawMatchUps,
55041
+ matchUpParticipantIds: matchUpParticipantIds,
55042
+ matchUpActionsPolicy: matchUpActionsPolicy,
55043
+ inContextMatchUp: inContextMatchUp,
55044
+ policyActions: policyActions,
55045
+ enforceGender: enforceGender,
55046
+ participantId: participantId,
55047
+ sideNumber: sideNumber,
55048
+ matchUpId: matchUpId,
55049
+ matchUp: matchUp,
55050
+ drawId: drawId,
55051
+ side: side,
54974
55052
  });
54975
- if (assignmentAvailable && (availableIds_1 === null || availableIds_1 === void 0 ? void 0 : availableIds_1.length)) {
54976
- validActions.push({
54977
- availableParticipantIds: availableIds_1,
54978
- method: ASSIGN_TEAM_POSITION_METHOD,
54979
- availableParticipants: available,
54980
- type: ASSIGN_PARTICIPANT,
54981
- payload: {
54982
- participantId: undefined,
54983
- tieMatchUpId: matchUpId,
54984
- drawId: drawId,
54985
- },
54986
- });
54987
- }
54988
- if ((existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length) &&
54989
- (!checkScoreHasValue(matchUp) || ((_12 = side === null || side === void 0 ? void 0 : side.substitutions) === null || _12 === void 0 ? void 0 : _12.length))) {
54990
- validActions.push({
54991
- method: REMOVE_TEAM_POSITION_METHOD,
54992
- type: REMOVE_PARTICIPANT,
54993
- existingParticipantIds: existingParticipantIds_1,
54994
- payload: {
54995
- participantId: undefined,
54996
- tieMatchUpId: matchUpId,
54997
- drawId: drawId,
54998
- },
54999
- });
55000
- }
55001
- if ((available === null || available === void 0 ? void 0 : available.length) &&
55002
- ((!sideNumber && (existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length)) ||
55003
- (sideNumber && (side === null || side === void 0 ? void 0 : side.participant)))) {
55004
- validActions.push({
55005
- availableParticipantIds: availableIds_1,
55006
- method: REPLACE_TEAM_POSITION_METHOD,
55007
- availableParticipants: available,
55008
- type: REPLACE_PARTICIPANT,
55009
- existingParticipantIds: existingParticipantIds_1,
55010
- payload: {
55011
- existingParticipantId: undefined,
55012
- participantId: undefined,
55013
- tieMatchUpId: matchUpId,
55014
- drawId: drawId,
55015
- },
55016
- });
55017
- }
55018
- if (isAvailableAction({ policyActions: policyActions, action: REMOVE_SUBSTITUTION }) &&
55019
- ((_13 = side === null || side === void 0 ? void 0 : side.substitutions) === null || _13 === void 0 ? void 0 : _13.length)) {
55020
- var sideIndividualParticipantIds_1 = (((_14 = side.participant) === null || _14 === void 0 ? void 0 : _14.participantType) === INDIVIDUAL && [
55021
- side.participantId,
55022
- ]) ||
55023
- (((_15 = side.participant) === null || _15 === void 0 ? void 0 : _15.participantType) === PAIR &&
55024
- side.participant.individualParticipantIds) ||
55025
- [];
55026
- var substitutedParticipantIds = side.substitutions
55027
- .map(function (sub) { return sub.participantId; })
55028
- .filter(function (id) { return sideIndividualParticipantIds_1.includes(id); });
55029
- if (!participantId || substitutedParticipantIds.includes(participantId)) {
55030
- validActions.push({
55031
- method: REMOVE_TEAM_POSITION_METHOD,
55032
- type: REMOVE_SUBSTITUTION,
55033
- substitutedParticipantIds: substitutedParticipantIds,
55034
- payload: {
55035
- participantId: undefined,
55036
- tieMatchUpId: matchUpId,
55037
- drawId: drawId,
55038
- },
55039
- });
55040
- }
55041
- }
55042
- var matchUpActionPolicy = specifiedPolicyDefinitions === null || specifiedPolicyDefinitions === void 0 ? void 0 : specifiedPolicyDefinitions[POLICY_TYPE_MATCHUP_ACTIONS];
55043
- var substituteWithoutScore = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteWithoutScore;
55044
- var substituteAfterCompleted = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteAfterCompleted;
55045
- // SUBSTITUTION
55046
- // substitution is only possible when both sides are present; otherwise => nonsensical
55047
- if (isAvailableAction({ policyActions: policyActions, action: SUBSTITUTION }) &&
55048
- matchUpParticipantIds.length === 2 &&
55049
- ((!sideNumber && (existingParticipantIds_1 === null || existingParticipantIds_1 === void 0 ? void 0 : existingParticipantIds_1.length)) ||
55050
- (sideNumber && (side === null || side === void 0 ? void 0 : side.participant))) &&
55051
- (substituteWithoutScore || checkScoreHasValue(matchUp)) &&
55052
- (substituteAfterCompleted ||
55053
- (matchUp.matchUpStatus &&
55054
- !completedMatchUpStatuses.includes(matchUp.matchUpStatus))) &&
55055
- (existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.length) &&
55056
- availableParticipants.length) {
55057
- // action is not valid if there are no existing assignments or no available substitutions
55058
- var existingParticipantIds_2 = existingParticipants.map(getParticipantId);
55059
- validActions.push({
55060
- info: 'list of team players available for substitution',
55061
- method: SUBSTITUTION_METHOD,
55062
- availableParticipantIds: availableParticipantIds,
55063
- existingParticipantIds: existingParticipantIds_2,
55064
- availableParticipants: availableParticipants,
55065
- existingParticipants: existingParticipants,
55066
- type: SUBSTITUTION,
55067
- payload: {
55068
- substituteParticipantId: undefined,
55069
- existingParticipantId: undefined,
55070
- sideNumber: sideNumber,
55071
- matchUpId: matchUpId,
55072
- drawId: drawId,
55073
- },
55074
- });
55075
- }
55053
+ validActions.push.apply(validActions, __spreadArray([], __read(collectionValidActions), false));
55076
55054
  }
55077
55055
  return {
55078
55056
  structureIsComplete: structureIsComplete,
@@ -55080,19 +55058,6 @@ function matchUpActions(params) {
55080
55058
  isDoubleExit: isDoubleExit,
55081
55059
  };
55082
55060
  }
55083
- function getEventAlternateParticipantIds(_a) {
55084
- var eventEntries = _a.eventEntries, structure = _a.structure;
55085
- var eligibleAlternate = function (entry) {
55086
- return entry.entryStatus === ALTERNATE && eligibleEntryStage({ structure: structure, entry: entry });
55087
- };
55088
- var entryPositionSort = function (a, b) {
55089
- return (a.entryPosition || Infinity) - (b.entryPosition || Infinity);
55090
- };
55091
- return eventEntries
55092
- .filter(eligibleAlternate)
55093
- .sort(entryPositionSort)
55094
- .map(getParticipantId);
55095
- }
55096
55061
 
55097
55062
  /**
55098
55063
  * Calculates the valid actions for a draw position based on the provided parameters.
@@ -55178,8 +55143,7 @@ function positionActions(params) {
55178
55143
  drawDefinition: drawDefinition,
55179
55144
  structure: structure,
55180
55145
  }).policyActions;
55181
- var possiblyDisablingAction = ![QUALIFYING, MAIN].includes(structure.stage) ||
55182
- structure.stageSequence !== 1;
55146
+ var possiblyDisablingAction = ![QUALIFYING, MAIN].includes(structure.stage) || structure.stageSequence !== 1;
55183
55147
  var drawId = drawDefinition.drawId;
55184
55148
  var validActions = [];
55185
55149
  var _j = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _j.assignedPositions, positionAssignments = _j.positionAssignments;
@@ -55257,11 +55221,9 @@ function positionActions(params) {
55257
55221
  validAssignmentActions === null || validAssignmentActions === void 0 ? void 0 : validAssignmentActions.forEach(function (action) { return validActions.push(action); });
55258
55222
  }
55259
55223
  var participantId = (positionAssignment || {}).participantId;
55260
- var participant = participantId &&
55261
- tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
55224
+ var participant = participantId && tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
55262
55225
  if (positionAssignment) {
55263
- if (isAvailableAction({ policyActions: policyActions, action: REMOVE_ASSIGNMENT }) &&
55264
- !isActiveDrawPosition) {
55226
+ if (isAvailableAction({ policyActions: policyActions, action: REMOVE_ASSIGNMENT }) && !isActiveDrawPosition) {
55265
55227
  validActions.push({
55266
55228
  type: REMOVE_ASSIGNMENT,
55267
55229
  method: REMOVE_ASSIGNMENT_METHOD,
@@ -55278,8 +55240,7 @@ function positionActions(params) {
55278
55240
  }
55279
55241
  // in this case the ASSIGN_BYE_METHOD is called after removing assigned participant
55280
55242
  // option should not be available if exising assignment is a bye
55281
- if (isAvailableAction({ policyActions: policyActions, action: ASSIGN_BYE }) &&
55282
- !isByePosition) {
55243
+ if (isAvailableAction({ policyActions: policyActions, action: ASSIGN_BYE }) && !isByePosition) {
55283
55244
  validActions.push({
55284
55245
  type: ASSIGN_BYE,
55285
55246
  method: REMOVE_ASSIGNMENT_METHOD,
@@ -55288,8 +55249,7 @@ function positionActions(params) {
55288
55249
  });
55289
55250
  }
55290
55251
  }
55291
- var validToAssignSeed = structure.stage === QUALIFYING ||
55292
- (structure.stage === MAIN && structure.stageSequence === 1);
55252
+ var validToAssignSeed = structure.stage === QUALIFYING || (structure.stage === MAIN && structure.stageSequence === 1);
55293
55253
  if (!isByePosition &&
55294
55254
  // if any drawPositions are active, action is disabled unless override in policy
55295
55255
  activePositionsCheck({
@@ -55396,8 +55356,7 @@ function positionActions(params) {
55396
55356
  validActions.push(validSwapAction);
55397
55357
  }
55398
55358
  }
55399
- if (isAvailableAction({ policyActions: policyActions, action: ALTERNATE_PARTICIPANT }) &&
55400
- !disablePlacementActions) {
55359
+ if (isAvailableAction({ policyActions: policyActions, action: ALTERNATE_PARTICIPANT }) && !disablePlacementActions) {
55401
55360
  var validAlternatesAction = getValidAlternatesAction({
55402
55361
  possiblyDisablingAction: possiblyDisablingAction,
55403
55362
  tournamentParticipants: tournamentParticipants,
@@ -55435,8 +55394,7 @@ function positionActions(params) {
55435
55394
  if (validLuckyLosersAction)
55436
55395
  validActions.push(validLuckyLosersAction);
55437
55396
  }
55438
- if ((participant === null || participant === void 0 ? void 0 : participant.participantType) === PAIR &&
55439
- isAvailableAction({ policyActions: policyActions, action: MODIFY_PAIR_ASSIGNMENT })) {
55397
+ if ((participant === null || participant === void 0 ? void 0 : participant.participantType) === PAIR && isAvailableAction({ policyActions: policyActions, action: MODIFY_PAIR_ASSIGNMENT })) {
55440
55398
  var validModifyAssignedPairAction = getValidModifyAssignedPairAction({
55441
55399
  tournamentParticipants: tournamentParticipants,
55442
55400
  returnParticipants: returnParticipants,
@@ -65030,11 +64988,15 @@ function venueModify(_a) {
65030
64988
  var venue = result.venue;
65031
64989
  // not valid to modify a venueId
65032
64990
  var validAttributes = Object.keys(venueTemplate()).filter(function (attribute) { return attribute !== 'venueId'; });
65033
- var validModificationAttributes = Object.keys(modifications).filter(function (attribute) { return validAttributes.includes(attribute); });
64991
+ var validModificationAttributes = Object.keys(modifications).filter(function (attribute) {
64992
+ return validAttributes.includes(attribute);
64993
+ });
65034
64994
  if (!validModificationAttributes.length)
65035
64995
  return { error: NO_VALID_ATTRIBUTES };
65036
64996
  var validReplacements = validAttributes.filter(function (attribute) { return !['courts', 'onlineResources'].includes(attribute); });
65037
- var validReplacementAttributes = Object.keys(modifications).filter(function (attribute) { return validReplacements.includes(attribute); });
64997
+ var validReplacementAttributes = Object.keys(modifications).filter(function (attribute) {
64998
+ return validReplacements.includes(attribute);
64999
+ });
65038
65000
  venue &&
65039
65001
  validReplacementAttributes.forEach(function (attribute) {
65040
65002
  var _a;
@@ -65042,12 +65004,10 @@ function venueModify(_a) {
65042
65004
  });
65043
65005
  var existingCourtIds = (_g = (_f = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _f === void 0 ? void 0 : _f.map(function (court) { return court.courtId; })) !== null && _g !== void 0 ? _g : [];
65044
65006
  var courtIdsToModify = ((_h = modifications.courts) === null || _h === void 0 ? void 0 : _h.map(function (court) { return court.courtId; })) || [];
65045
- var courtIdsToDelete = existingCourtIds.filter(function (courtId) { return !courtIdsToModify.includes(courtId); });
65007
+ var courtIdsToDelete = courtIdsToModify.length && existingCourtIds.filter(function (courtId) { return !courtIdsToModify.includes(courtId); });
65046
65008
  var matchUpsWithCourtId = [];
65047
65009
  if (courtIdsToDelete.length) {
65048
- var courtsToDelete = (_j = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _j === void 0 ? void 0 : _j.filter(function (court) {
65049
- return courtIdsToDelete.includes(court.courtId);
65050
- });
65010
+ var courtsToDelete = (_j = venue === null || venue === void 0 ? void 0 : venue.courts) === null || _j === void 0 ? void 0 : _j.filter(function (court) { return courtIdsToDelete.includes(court.courtId); });
65051
65011
  var scheduleDeletionsCount = courtsToDelete === null || courtsToDelete === void 0 ? void 0 : courtsToDelete.map(function (court) {
65052
65012
  var e_3, _a;
65053
65013
  var _b, _c, _d;
@@ -65075,11 +65035,9 @@ function venueModify(_a) {
65075
65035
  }
65076
65036
  return (_d = (_c = result.matchUps) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
65077
65037
  }).reduce(function (a, b) { return a + b; });
65078
- if (venue &&
65079
- (!scheduleDeletionsCount || allowModificationWhenMatchUpsScheduled)) {
65080
- venue.courts = (_k = venue.courts) === null || _k === void 0 ? void 0 : _k.filter(function (court) {
65081
- return courtIdsToModify.includes(court.courtId);
65082
- });
65038
+ console.log({ scheduleDeletionsCount: scheduleDeletionsCount });
65039
+ if (venue && (!scheduleDeletionsCount || allowModificationWhenMatchUpsScheduled)) {
65040
+ venue.courts = (_k = venue.courts) === null || _k === void 0 ? void 0 : _k.filter(function (court) { return courtIdsToModify.includes(court.courtId); });
65083
65041
  bulkScheduleTournamentMatchUps({
65084
65042
  schedule: { courtId: '', scheduledDate: '' },
65085
65043
  matchUpDetails: matchUpsWithCourtId,