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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.5';
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
@@ -20863,12 +20846,7 @@ function assignTieMatchUpParticipantId(params) {
20863
20846
  return decorateResult({ result: { error: INVALID_SIDE_NUMBER }, stack: stack });
20864
20847
  }
20865
20848
  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
- });
20849
+ 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
20850
  if (allTieIndividualParticipantIds === null || allTieIndividualParticipantIds === void 0 ? void 0 : allTieIndividualParticipantIds.includes(participantId)) {
20873
20851
  return decorateResult({ result: __assign({}, SUCCESS), stack: stack });
20874
20852
  }
@@ -20901,11 +20879,10 @@ function assignTieMatchUpParticipantId(params) {
20901
20879
  return { error: INVALID_PARTICIPANT_TYPE };
20902
20880
  }
20903
20881
  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
- }))) ||
20882
+ var participantTeam = (teamParticipantId && (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20883
+ var participantId = _a.participantId;
20884
+ return participantId === teamParticipantId;
20885
+ }))) ||
20909
20886
  (teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.find(function (_a) {
20910
20887
  var individualParticipantIds = _a.individualParticipantIds;
20911
20888
  return overlap(relevantParticipantIds, individualParticipantIds);
@@ -20919,7 +20896,7 @@ function assignTieMatchUpParticipantId(params) {
20919
20896
  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
20897
  var teamDrawPosition = teamAssignment === null || teamAssignment === void 0 ? void 0 : teamAssignment.drawPosition;
20921
20898
  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;
20899
+ var sideNumber = (_p = teamSide === null || teamSide === void 0 ? void 0 : teamSide.sideNumber) !== null && _p !== void 0 ? _p : params.sideNumber;
20923
20900
  if (!tieFormat) {
20924
20901
  return { error: MISSING_TIE_FORMAT };
20925
20902
  }
@@ -20950,9 +20927,7 @@ function assignTieMatchUpParticipantId(params) {
20950
20927
  var assignedParticipantIds = targetAssignments === null || targetAssignments === void 0 ? void 0 : targetAssignments.map(function (assignment) { return assignment === null || assignment === void 0 ? void 0 : assignment.participantId; });
20951
20928
  // participantIds is an array of ids for individual team participants whose assignments should be modified
20952
20929
  var participantIds = ((assignedParticipantIds === null || assignedParticipantIds === void 0 ? void 0 : assignedParticipantIds.length) > 1 && assignedParticipantIds) ||
20953
- (participantType === PAIR
20954
- ? participantToAssign.individualParticipantIds
20955
- : [participantId]);
20930
+ (participantType === PAIR ? participantToAssign.individualParticipantIds : [participantId]);
20956
20931
  // first filter out any collectionAssignment with equivalent collectionId/collectionPosition/participantId
20957
20932
  var removeResult = removeCollectionAssignments({
20958
20933
  collectionPosition: collectionPosition,
@@ -21156,8 +21131,7 @@ function removeTieMatchUpParticipantId(params) {
21156
21131
  if (!side)
21157
21132
  return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND }, stack: stack });
21158
21133
  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)))
21134
+ (checkScoreHasValue({ score: inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.score }) || (inContextTieMatchUp === null || inContextTieMatchUp === void 0 ? void 0 : inContextTieMatchUp.winningSide)))
21161
21135
  return decorateResult({ result: { error: EXISTING_OUTCOME }, stack: stack });
21162
21136
  var teamParticipantId = (_j = (_h = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _h === void 0 ? void 0 : _h.find(function (_a) {
21163
21137
  var sideNumber = _a.sideNumber;
@@ -21175,9 +21149,7 @@ function removeTieMatchUpParticipantId(params) {
21175
21149
  if (matchUpType === SINGLES && participantToRemove.participantType === PAIR) {
21176
21150
  return decorateResult({ result: { error: INVALID_PARTICIPANT }, stack: stack });
21177
21151
  }
21178
- var participantIds = participantToRemove.participantType === INDIVIDUAL
21179
- ? [participantId]
21180
- : participantToRemove.individualParticipantIds;
21152
+ var participantIds = participantToRemove.participantType === INDIVIDUAL ? [participantId] : participantToRemove.individualParticipantIds;
21181
21153
  ensureSideLineUps({
21182
21154
  tournamentId: tournamentRecord.tournamentId,
21183
21155
  eventId: event.eventId,
@@ -21189,11 +21161,10 @@ function removeTieMatchUpParticipantId(params) {
21189
21161
  var sideNumber = _a.sideNumber;
21190
21162
  return sideNumber === side.sideNumber;
21191
21163
  });
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) {
21164
+ if (!dualMatchUpSide && (((_o = dualMatchUp.sides) === null || _o === void 0 ? void 0 : _o.filter(function (_a) {
21165
+ var lineUp = _a.lineUp;
21166
+ return !lineUp;
21167
+ }).length) || 0) < 2) {
21197
21168
  var drawPositionMap_1 = teamParticipants === null || teamParticipants === void 0 ? void 0 : teamParticipants.map(function (_a) {
21198
21169
  var _b;
21199
21170
  var teamParticipantId = _a.participantId;
@@ -21207,7 +21178,8 @@ function removeTieMatchUpParticipantId(params) {
21207
21178
  return ((_a = drawPositionMap_1 === null || drawPositionMap_1 === void 0 ? void 0 : drawPositionMap_1.find(function (_a) {
21208
21179
  var drawPosition = _a.drawPosition;
21209
21180
  return drawPosition === side.drawPosition;
21210
- })) === null || _a === void 0 ? void 0 : _a.teamParticipantId) === teamParticipantId;
21181
+ })) === null || _a === void 0 ? void 0 : _a.teamParticipantId) ===
21182
+ teamParticipantId;
21211
21183
  });
21212
21184
  }
21213
21185
  if (!dualMatchUpSide) {
@@ -21234,8 +21206,7 @@ function removeTieMatchUpParticipantId(params) {
21234
21206
  });
21235
21207
  // if an INDIVIDUAL participant is being removed from a DOUBLES matchUp
21236
21208
  // ...then the PAIR participant may need to be modified
21237
- if (matchUpType === DOUBLES &&
21238
- participantToRemove.participantType === INDIVIDUAL) {
21209
+ if (matchUpType === DOUBLES && participantToRemove.participantType === INDIVIDUAL) {
21239
21210
  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
21211
  var pairParticipantId = (tieMatchUpSide !== null && tieMatchUpSide !== void 0 ? tieMatchUpSide : {}).participantId;
21241
21212
  var pairParticipant = pairParticipantId &&
@@ -24868,7 +24839,9 @@ function getUnseededByePositions(_a) {
24868
24839
  var relevantMatchUps = structure.structureType === CONTAINER ? matchUps : firstRoundMatchUps;
24869
24840
  var relevantDrawPositions = unique([].concat.apply([], __spreadArray([], __read(relevantMatchUps.map(function (matchUp) { return matchUp.drawPositions; })), false)));
24870
24841
  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); });
24842
+ var filledRelevantDrawPositions = filledDrawPositions === null || filledDrawPositions === void 0 ? void 0 : filledDrawPositions.filter(function (drawPosition) {
24843
+ return relevantDrawPositions.includes(drawPosition);
24844
+ });
24872
24845
  var getHalves = function (chunk) {
24873
24846
  var halfLength = Math.ceil(chunk.length / 2);
24874
24847
  var halves = [chunk.slice(0, halfLength), chunk.slice(halfLength)];
@@ -24888,25 +24861,15 @@ function getUnseededByePositions(_a) {
24888
24861
  var _b = getHalves(greaterHalf), greaterQuarter = _b.greaterHalf, lesserQuarter = _b.lesserHalf;
24889
24862
  var shuffledQuarter = shuffleArray(greaterQuarter.flat(Infinity));
24890
24863
  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);
24864
+ var diminishedQuarter = greaterQuarter.flat().filter(function (position) { return position !== drawPosition; });
24865
+ var newlyFilteredChunks = __spreadArray(__spreadArray(__spreadArray([], __read(lesserHalf), false), __read(lesserQuarter), false), [diminishedQuarter], false);
24897
24866
  return { newlyFilteredChunks: newlyFilteredChunks, drawPosition: drawPosition };
24898
24867
  };
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
- };
24868
+ var notSeedByePosition = function (drawPosition) { return !seedOrderByePositions.includes(drawPosition); };
24869
+ var unfilledDrawPosition = function (drawPosition) { return !(filledRelevantDrawPositions === null || filledRelevantDrawPositions === void 0 ? void 0 : filledRelevantDrawPositions.includes(drawPosition)); };
24905
24870
  var quarterSeparateBlock = function (block) {
24906
24871
  var sortedChunked = chunkArray(block.sort(numericSort), Math.ceil(block.length / 4));
24907
- var filteredChunks = sortedChunked.map(function (chunk) {
24908
- return chunk.filter(unfilledDrawPosition);
24909
- });
24872
+ var filteredChunks = sortedChunked.map(function (chunk) { return chunk.filter(unfilledDrawPosition); });
24910
24873
  var drawPositionCount = [].concat.apply([], __spreadArray([], __read(filteredChunks.flat(Infinity)), false)).length;
24911
24874
  var orderedDrawPositions = [];
24912
24875
  for (var i = 0; i < drawPositionCount; i++) {
@@ -24926,10 +24889,7 @@ function getUnseededByePositions(_a) {
24926
24889
  drawDefinition: drawDefinition,
24927
24890
  structure: structure,
24928
24891
  }).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
- });
24892
+ 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
24893
  var unfilledSeedBlocks;
24934
24894
  if (isFeedIn) {
24935
24895
  // FEED_IN structures calculate seedDrawPositions uniquely
@@ -24942,15 +24902,10 @@ function getUnseededByePositions(_a) {
24942
24902
  var blockDrawPositions = seedBlocks.map(function (seedBlock) {
24943
24903
  return seedBlock.map(function (drawPosition) { return drawPosition + drawPositionOffset; });
24944
24904
  });
24945
- unfilledSeedBlocks = blockDrawPositions
24946
- .map(quarterSeparateBlock)
24947
- .filter(function (block) { return block.length; });
24905
+ unfilledSeedBlocks = blockDrawPositions.map(quarterSeparateBlock).filter(function (block) { return block.length; });
24948
24906
  }
24949
24907
  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
- });
24908
+ unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(function (block) { return block.filter(unfilledDrawPosition); });
24954
24909
  }
24955
24910
  else {
24956
24911
  unfilledSeedBlocks = validBlockDrawPositions === null || validBlockDrawPositions === void 0 ? void 0 : validBlockDrawPositions.map(quarterSeparateBlock).filter(function (block) { return block.length; });
@@ -54637,16 +54592,260 @@ var matchUpActionConstants = {
54637
54592
  END: END,
54638
54593
  };
54639
54594
 
54595
+ function collectionMatchUpActions(_a) {
54596
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
54597
+ 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;
54598
+ var validActions = [];
54599
+ var firstFoundSide = (_b = inContextMatchUp.sides) === null || _b === void 0 ? void 0 : _b.find(function (side) { return side.participant; });
54600
+ var assignedGender = inContextMatchUp.gender === MIXED &&
54601
+ inContextMatchUp.sideNumber &&
54602
+ ((_c = inContextMatchUp.sides) === null || _c === void 0 ? void 0 : _c.filter(function (side) { return side.particiapntId; }).length) === 1 &&
54603
+ ((_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);
54604
+ var matchUpType = inContextMatchUp.matchUpType;
54605
+ 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;
54606
+ var gender = genderEnforced ? inContextMatchUp.gender : undefined;
54607
+ 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);
54608
+ var allParticipantIds = allParticipants === null || allParticipants === void 0 ? void 0 : allParticipants.map(xa('participantId'));
54609
+ 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);
54610
+ var existingParticipantIds = existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.map(xa('participantId'));
54611
+ var inContextDualMatchUp = inContextDrawMatchUps === null || inContextDrawMatchUps === void 0 ? void 0 : inContextDrawMatchUps.find(function (drawMatchUp) { return drawMatchUp.matchUpId === inContextMatchUp.matchUpTieId; });
54612
+ var availableIndividualParticipants = (_j = inContextDualMatchUp === null || inContextDualMatchUp === void 0 ? void 0 : inContextDualMatchUp.sides) === null || _j === void 0 ? void 0 : _j.map(function (side) {
54613
+ var _a;
54614
+ return (_a = side.participant) === null || _a === void 0 ? void 0 : _a.individualParticipants.filter(function (_a) {
54615
+ var participantId = _a.participantId, person = _a.person;
54616
+ return !(existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.includes(participantId)) &&
54617
+ (!gender ||
54618
+ gender === ANY ||
54619
+ person.sex === gender ||
54620
+ // case where one gendered member has been assigned
54621
+ (gender === MIXED && !assignedGender) ||
54622
+ (assignedGender && person.sex !== assignedGender));
54623
+ });
54624
+ });
54625
+ // if no sideNumber is provided, segregate available by sideNumber and specify sideNumber
54626
+ var availableParticipants = sideNumber
54627
+ ? availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]
54628
+ : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54629
+ participants: available,
54630
+ sideNumber: i + 1,
54631
+ }); });
54632
+ var availableParticipantIds = sideNumber
54633
+ ? (_k = availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants[sideNumber - 1]) === null || _k === void 0 ? void 0 : _k.map(getParticipantId)
54634
+ : availableIndividualParticipants === null || availableIndividualParticipants === void 0 ? void 0 : availableIndividualParticipants.map(function (available, i) { return ({
54635
+ participants: available === null || available === void 0 ? void 0 : available.map(getParticipantId),
54636
+ sideNumber: i + 1,
54637
+ }); });
54638
+ var assignmentAvailable = (sideNumber &&
54639
+ ((matchUpType === SINGLES_MATCHUP && !(existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) ||
54640
+ (matchUpType === DOUBLES_MATCHUP && ((_l = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _l !== void 0 ? _l : 0) < 2))) ||
54641
+ (!sideNumber &&
54642
+ ((matchUpType === SINGLES_MATCHUP && ((_m = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _m !== void 0 ? _m : 0) < 2) ||
54643
+ (matchUpType === DOUBLES_MATCHUP && ((_o = existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length) !== null && _o !== void 0 ? _o : 0) < 4)));
54644
+ // extra step to avoid edge case where individual participant is part of both teams
54645
+ var availableIds = availableParticipantIds === null || availableParticipantIds === void 0 ? void 0 : availableParticipantIds.filter(function (id) { return !(allParticipantIds === null || allParticipantIds === void 0 ? void 0 : allParticipantIds.includes(id)); });
54646
+ var available = availableParticipants === null || availableParticipants === void 0 ? void 0 : availableParticipants.filter(function (_a) {
54647
+ var participantId = _a.participantId;
54648
+ return availableIds.includes(participantId);
54649
+ });
54650
+ if (assignmentAvailable && (availableIds === null || availableIds === void 0 ? void 0 : availableIds.length)) {
54651
+ validActions.push({
54652
+ availableParticipantIds: availableIds,
54653
+ method: ASSIGN_TEAM_POSITION_METHOD,
54654
+ availableParticipants: available,
54655
+ type: ASSIGN_PARTICIPANT,
54656
+ payload: {
54657
+ participantId: undefined,
54658
+ tieMatchUpId: matchUpId,
54659
+ sideNumber: sideNumber,
54660
+ drawId: drawId,
54661
+ },
54662
+ });
54663
+ }
54664
+ 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))) {
54665
+ validActions.push({
54666
+ method: REMOVE_TEAM_POSITION_METHOD,
54667
+ type: REMOVE_PARTICIPANT,
54668
+ existingParticipantIds: existingParticipantIds,
54669
+ payload: {
54670
+ participantId: undefined,
54671
+ tieMatchUpId: matchUpId,
54672
+ drawId: drawId,
54673
+ },
54674
+ });
54675
+ }
54676
+ 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)))) {
54677
+ validActions.push({
54678
+ availableParticipantIds: availableIds,
54679
+ method: REPLACE_TEAM_POSITION_METHOD,
54680
+ availableParticipants: available,
54681
+ type: REPLACE_PARTICIPANT,
54682
+ existingParticipantIds: existingParticipantIds,
54683
+ payload: {
54684
+ existingParticipantId: undefined,
54685
+ participantId: undefined,
54686
+ tieMatchUpId: matchUpId,
54687
+ drawId: drawId,
54688
+ },
54689
+ });
54690
+ }
54691
+ 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)) {
54692
+ var sideIndividualParticipantIds_1 = (((_r = side.participant) === null || _r === void 0 ? void 0 : _r.participantType) === INDIVIDUAL && [side.participantId]) ||
54693
+ (((_s = side.participant) === null || _s === void 0 ? void 0 : _s.participantType) === PAIR && side.participant.individualParticipantIds) ||
54694
+ [];
54695
+ var substitutedParticipantIds = side.substitutions
54696
+ .map(function (sub) { return sub.participantId; })
54697
+ .filter(function (id) { return sideIndividualParticipantIds_1.includes(id); });
54698
+ if (!participantId || substitutedParticipantIds.includes(participantId)) {
54699
+ validActions.push({
54700
+ method: REMOVE_TEAM_POSITION_METHOD,
54701
+ type: REMOVE_SUBSTITUTION,
54702
+ substitutedParticipantIds: substitutedParticipantIds,
54703
+ payload: {
54704
+ participantId: undefined,
54705
+ tieMatchUpId: matchUpId,
54706
+ drawId: drawId,
54707
+ },
54708
+ });
54709
+ }
54710
+ }
54711
+ var matchUpActionPolicy = specifiedPolicyDefinitions === null || specifiedPolicyDefinitions === void 0 ? void 0 : specifiedPolicyDefinitions[POLICY_TYPE_MATCHUP_ACTIONS];
54712
+ var substituteWithoutScore = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteWithoutScore;
54713
+ var substituteAfterCompleted = matchUpActionPolicy === null || matchUpActionPolicy === void 0 ? void 0 : matchUpActionPolicy.substituteAfterCompleted;
54714
+ // SUBSTITUTION
54715
+ // substitution is only possible when both sides are present; otherwise => nonsensical
54716
+ if (isAvailableAction({ policyActions: policyActions, action: SUBSTITUTION }) &&
54717
+ matchUpParticipantIds.length === 2 &&
54718
+ ((!sideNumber && (existingParticipantIds === null || existingParticipantIds === void 0 ? void 0 : existingParticipantIds.length)) || (sideNumber && (side === null || side === void 0 ? void 0 : side.participant))) &&
54719
+ (substituteWithoutScore || checkScoreHasValue(matchUp)) &&
54720
+ (substituteAfterCompleted ||
54721
+ (matchUp.matchUpStatus && !completedMatchUpStatuses.includes(matchUp.matchUpStatus))) &&
54722
+ (existingParticipants === null || existingParticipants === void 0 ? void 0 : existingParticipants.length) &&
54723
+ availableParticipants.length) {
54724
+ // action is not valid if there are no existing assignments or no available substitutions
54725
+ var existingParticipantIds_1 = existingParticipants.map(getParticipantId);
54726
+ validActions.push({
54727
+ info: 'list of team players available for substitution',
54728
+ method: SUBSTITUTION_METHOD,
54729
+ availableParticipantIds: availableParticipantIds,
54730
+ existingParticipantIds: existingParticipantIds_1,
54731
+ availableParticipants: availableParticipants,
54732
+ existingParticipants: existingParticipants,
54733
+ type: SUBSTITUTION,
54734
+ payload: {
54735
+ substituteParticipantId: undefined,
54736
+ existingParticipantId: undefined,
54737
+ sideNumber: sideNumber,
54738
+ matchUpId: matchUpId,
54739
+ drawId: drawId,
54740
+ },
54741
+ });
54742
+ }
54743
+ return validActions;
54744
+ }
54745
+
54746
+ function getEventAlternateParticipantIds(_a) {
54747
+ var eventEntries = _a.eventEntries, structure = _a.structure;
54748
+ var eligibleAlternate = function (entry) { return entry.entryStatus === ALTERNATE && eligibleEntryStage({ structure: structure, entry: entry }); };
54749
+ var entryPositionSort = function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); };
54750
+ return eventEntries.filter(eligibleAlternate).sort(entryPositionSort).map(xa('participantId'));
54751
+ }
54752
+
54753
+ function adHocMatchUpActions(_a) {
54754
+ var _b, _c, _d, _e, _f, _g;
54755
+ 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;
54756
+ var validActions = [];
54757
+ var roundMatchUps = ((_b = structure === null || structure === void 0 ? void 0 : structure.matchUps) !== null && _b !== void 0 ? _b : []).filter(function (_a) {
54758
+ var roundNumber = _a.roundNumber;
54759
+ return roundNumber === matchUp.roundNumber;
54760
+ });
54761
+ var enteredParticipantIds = (_d = (_c = drawDefinition === null || drawDefinition === void 0 ? void 0 : drawDefinition.entries) === null || _c === void 0 ? void 0 : _c.filter(function (_a) {
54762
+ var entryStatus = _a.entryStatus;
54763
+ return entryStatus && DIRECT_ENTRY_STATUSES.includes(entryStatus);
54764
+ }).map(xa('participantId'))) !== null && _d !== void 0 ? _d : [];
54765
+ var roundAssignedParticipantIds = roundMatchUps
54766
+ .map(function (matchUp) { var _a; return ((_a = matchUp.sides) !== null && _a !== void 0 ? _a : []).flatMap(xa('participantId')); })
54767
+ .flat()
54768
+ .filter(Boolean);
54769
+ var availableParticipantIds = enteredParticipantIds.filter(function (participantId) {
54770
+ return !matchUpParticipantIds.includes(participantId) &&
54771
+ (!restrictAdHocRoundParticipants || !roundAssignedParticipantIds.includes(participantId));
54772
+ });
54773
+ 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); });
54774
+ participantsAvailable === null || participantsAvailable === void 0 ? void 0 : participantsAvailable.forEach(function (participant) {
54775
+ var _a;
54776
+ var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === participant.participantId; });
54777
+ // used to sort available participants
54778
+ participant.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54779
+ });
54780
+ if (availableParticipantIds.length) {
54781
+ validActions.push({
54782
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54783
+ method: ASSIGN_SIDE_METHOD,
54784
+ type: ASSIGN_PARTICIPANT,
54785
+ availableParticipantIds: availableParticipantIds,
54786
+ participantsAvailable: participantsAvailable,
54787
+ });
54788
+ }
54789
+ var eventEntries = (_e = event === null || event === void 0 ? void 0 : event.entries) !== null && _e !== void 0 ? _e : [];
54790
+ var availableEventAlternatesParticipantIds = getEventAlternateParticipantIds({ eventEntries: eventEntries, structure: structure });
54791
+ var availableAlternatesParticipantIds = unique(enteredParticipantIds.concat(availableEventAlternatesParticipantIds));
54792
+ if (otherFlightEntries) {
54793
+ var flightProfile = event ? getFlightProfile({ event: event }) : undefined;
54794
+ 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) {
54795
+ return flight.drawEntries
54796
+ .filter(function (entry) { return entry.participantId && ![WITHDRAWN, UNGROUPED, UNPAIRED].includes(entry.entryStatus); })
54797
+ .map(function (_a) {
54798
+ var participantId = _a.participantId;
54799
+ return participantId;
54800
+ });
54801
+ }).filter(Boolean);
54802
+ if (otherFlightEnteredParticipantIds === null || otherFlightEnteredParticipantIds === void 0 ? void 0 : otherFlightEnteredParticipantIds.length) {
54803
+ // include direct acceptance participants from other flights
54804
+ availableAlternatesParticipantIds.push.apply(availableAlternatesParticipantIds, __spreadArray([], __read(otherFlightEnteredParticipantIds), false));
54805
+ }
54806
+ }
54807
+ availableAlternatesParticipantIds = availableAlternatesParticipantIds.filter(function (participantId) {
54808
+ return !matchUpParticipantIds.includes(participantId) &&
54809
+ !availableParticipantIds.includes(participantId) &&
54810
+ (!restrictAdHocRoundParticipants || !roundAssignedParticipantIds.includes(participantId));
54811
+ });
54812
+ 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); });
54813
+ availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.forEach(function (alternate) {
54814
+ var _a;
54815
+ var entry = ((_a = drawDefinition.entries) !== null && _a !== void 0 ? _a : []).find(function (entry) { return entry.participantId === alternate.participantId; });
54816
+ alternate.entryPosition = entry === null || entry === void 0 ? void 0 : entry.entryPosition;
54817
+ });
54818
+ availableAlternates === null || availableAlternates === void 0 ? void 0 : availableAlternates.sort(function (a, b) { return (a.entryPosition || Infinity) - (b.entryPosition || Infinity); });
54819
+ if (availableAlternatesParticipantIds.length) {
54820
+ validActions.push({
54821
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54822
+ availableParticipantIds: availableAlternatesParticipantIds,
54823
+ participantsAvailable: availableAlternates,
54824
+ method: ASSIGN_SIDE_METHOD,
54825
+ type: ALTERNATE,
54826
+ });
54827
+ }
54828
+ if (!checkScoreHasValue(matchUp) && sideNumber) {
54829
+ var side = (_g = matchUp.sides) === null || _g === void 0 ? void 0 : _g.find(function (side) { return side.sideNumber === sideNumber; });
54830
+ if (side === null || side === void 0 ? void 0 : side.participantId) {
54831
+ validActions.push({
54832
+ payload: { drawId: drawId, matchUpId: matchUpId, structureId: structureId, sideNumber: sideNumber },
54833
+ method: REMOVE_SIDE_METHOD,
54834
+ type: REMOVE_PARTICIPANT,
54835
+ });
54836
+ }
54837
+ }
54838
+ return validActions;
54839
+ }
54840
+
54640
54841
  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;
54842
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
54642
54843
  if (!params)
54643
54844
  return { error: INVALID_VALUES };
54644
54845
  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
54846
+ var _u = params.restrictAdHocRoundParticipants, restrictAdHocRoundParticipants = _u === void 0 ? true : _u, // disallow the same participant being in the same round multiple times
54646
54847
  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]));
54848
+ 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
54849
  if (!tournamentRecord)
54651
54850
  return { error: MISSING_TOURNAMENT_RECORD };
54652
54851
  if (!matchUpId || !isString(matchUpId))
@@ -54670,11 +54869,11 @@ function matchUpActions(params) {
54670
54869
  withIndividualParticipants: true,
54671
54870
  }).participants;
54672
54871
  var drawId = drawDefinition.drawId;
54673
- var _17 = findDrawMatchUp({
54872
+ var _v = findDrawMatchUp({
54674
54873
  drawDefinition: drawDefinition,
54675
54874
  matchUpId: matchUpId,
54676
54875
  event: event,
54677
- }), matchUp = _17.matchUp, structure = _17.structure;
54876
+ }), matchUp = _v.matchUp, structure = _v.structure;
54678
54877
  if (!matchUp)
54679
54878
  return { error: MATCHUP_NOT_FOUND };
54680
54879
  var appliedPolicies = (_f = getAppliedPolicies({
@@ -54686,7 +54885,6 @@ function matchUpActions(params) {
54686
54885
  Object.assign(appliedPolicies, specifiedPolicyDefinitions !== null && specifiedPolicyDefinitions !== void 0 ? specifiedPolicyDefinitions : {});
54687
54886
  var otherFlightEntries = (_g = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies[POLICY_TYPE_POSITION_ACTIONS]) === null || _g === void 0 ? void 0 : _g.otherFlightEntries;
54688
54887
  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
54888
  var enabledStructures = getEnabledStructures({
54691
54889
  actionType: MATCHUP_ACTION,
54692
54890
  appliedPolicies: appliedPolicies,
@@ -54707,108 +54905,31 @@ function matchUpActions(params) {
54707
54905
  event: event,
54708
54906
  }).matchUps;
54709
54907
  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; }));
54908
+ 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
54909
  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;
54910
+ var _w = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _w.assignedPositions, allPositionsAssigned = _w.allPositionsAssigned;
54714
54911
  var structureId = (structure !== null && structure !== void 0 ? structure : {}).structureId;
54715
54912
  var validActions = [];
54716
54913
  if (!structureId)
54717
54914
  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;
54915
+ var isAdHocMatchUp = isAdHoc({ drawDefinition: drawDefinition, structure: structure });
54916
+ var isCollectionMatchUp = matchUp.collectionId;
54917
+ if (isAdHocMatchUp && !isCollectionMatchUp) {
54918
+ var adHocValidActions = adHocMatchUpActions({
54919
+ restrictAdHocRoundParticipants: restrictAdHocRoundParticipants,
54920
+ tournamentParticipants: tournamentParticipants,
54921
+ matchUpParticipantIds: matchUpParticipantIds,
54922
+ otherFlightEntries: otherFlightEntries,
54923
+ drawDefinition: drawDefinition,
54924
+ structureId: structureId,
54925
+ sideNumber: sideNumber,
54926
+ matchUpId: matchUpId,
54927
+ structure: structure,
54928
+ matchUp: matchUp,
54929
+ drawId: drawId,
54930
+ event: event,
54791
54931
  });
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
- }
54932
+ validActions.push.apply(validActions, __spreadArray([], __read(adHocValidActions), false));
54812
54933
  }
54813
54934
  var structureIsComplete = isCompletedStructure({
54814
54935
  drawDefinition: drawDefinition,
@@ -54816,10 +54937,9 @@ function matchUpActions(params) {
54816
54937
  });
54817
54938
  var participantAssignedDrawPositions = assignedPositions === null || assignedPositions === void 0 ? void 0 : assignedPositions.filter(function (assignment) { return assignment.participantId; }).map(function (assignment) { return assignment.drawPosition; });
54818
54939
  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
54940
  var isByeMatchUp = matchUp.matchUpStatus === BYE ||
54821
54941
  (!isCollectionMatchUp &&
54822
- ((_v = matchUp.drawPositions) === null || _v === void 0 ? void 0 : _v.reduce(function (isByeMatchUp, drawPosition) {
54942
+ ((_p = matchUp.drawPositions) === null || _p === void 0 ? void 0 : _p.reduce(function (isByeMatchUp, drawPosition) {
54823
54943
  return (byeAssignedDrawPositions === null || byeAssignedDrawPositions === void 0 ? void 0 : byeAssignedDrawPositions.includes(drawPosition)) || isByeMatchUp;
54824
54944
  }, false)));
54825
54945
  if (isByeMatchUp)
@@ -54831,21 +54951,17 @@ function matchUpActions(params) {
54831
54951
  var isInComplete = !isDirectingMatchUpStatus({
54832
54952
  matchUpStatus: matchUp.matchUpStatus,
54833
54953
  });
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]);
54954
+ var structureScoringPolicies = (_q = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _q === void 0 ? void 0 : _q.structures;
54955
+ 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
54956
  var sequenceSpecificPolicies = (structure === null || structure === void 0 ? void 0 : structure.stageSequence) &&
54839
54957
  (stageSpecificPolicies === null || stageSpecificPolicies === void 0 ? void 0 : stageSpecificPolicies.stageSequence) &&
54840
54958
  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) ||
54959
+ var requireAllPositionsAssigned = ((_r = appliedPolicies === null || appliedPolicies === void 0 ? void 0 : appliedPolicies.scoring) === null || _r === void 0 ? void 0 : _r.requireAllPositionsAssigned) ||
54842
54960
  (stageSpecificPolicies === null || stageSpecificPolicies === void 0 ? void 0 : stageSpecificPolicies.requireAllPositionsAssigned) ||
54843
54961
  (sequenceSpecificPolicies === null || sequenceSpecificPolicies === void 0 ? void 0 : sequenceSpecificPolicies.requireAllPositionsAssigned);
54844
54962
  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);
54963
+ var hasParticipants = matchUp.sides && matchUp.sides.filter(function (side) { return side === null || side === void 0 ? void 0 : side.participantId; }).length === 2;
54964
+ var isDoubleExit = matchUp.matchUpStatus && [DOUBLE_WALKOVER, DOUBLE_DEFAULT].includes(matchUp.matchUpStatus);
54849
54965
  var targetData = positionTargets({
54850
54966
  inContextDrawMatchUps: inContextDrawMatchUps,
54851
54967
  drawDefinition: drawDefinition,
@@ -54856,15 +54972,14 @@ function matchUpActions(params) {
54856
54972
  drawDefinition: drawDefinition,
54857
54973
  targetData: targetData,
54858
54974
  });
54859
- var matchUpDrawPositionsAreAssigned = ((_y = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.drawPositions) === null || _y === void 0 ? void 0 : _y.length) === 2 &&
54975
+ var matchUpDrawPositionsAreAssigned = ((_s = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.drawPositions) === null || _s === void 0 ? void 0 : _s.length) === 2 &&
54860
54976
  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 &&
54977
+ ((_t = inContextMatchUp === null || inContextMatchUp === void 0 ? void 0 : inContextMatchUp.sides) === null || _t === void 0 ? void 0 : _t.length) === 2 &&
54862
54978
  inContextMatchUp.sides.every(function (_a) {
54863
54979
  var participantId = _a.participantId;
54864
54980
  return participantId;
54865
54981
  });
54866
- var readyToScore = (matchUpDrawPositionsAreAssigned || hasParticipants) &&
54867
- !(isDoubleExit && activeDownstream);
54982
+ var readyToScore = (matchUpDrawPositionsAreAssigned || hasParticipants) && !(isDoubleExit && activeDownstream);
54868
54983
  var addPenaltyAction = {
54869
54984
  method: ADD_PENALTY_METHOD,
54870
54985
  type: ADD_PENALTY,
@@ -54917,162 +55032,22 @@ function matchUpActions(params) {
54917
55032
  }
54918
55033
  }
54919
55034
  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);
55035
+ var collectionValidActions = collectionMatchUpActions({
55036
+ specifiedPolicyDefinitions: specifiedPolicyDefinitions,
55037
+ inContextDrawMatchUps: inContextDrawMatchUps,
55038
+ matchUpParticipantIds: matchUpParticipantIds,
55039
+ matchUpActionsPolicy: matchUpActionsPolicy,
55040
+ inContextMatchUp: inContextMatchUp,
55041
+ policyActions: policyActions,
55042
+ enforceGender: enforceGender,
55043
+ participantId: participantId,
55044
+ sideNumber: sideNumber,
55045
+ matchUpId: matchUpId,
55046
+ matchUp: matchUp,
55047
+ drawId: drawId,
55048
+ side: side,
54974
55049
  });
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
- }
55050
+ validActions.push.apply(validActions, __spreadArray([], __read(collectionValidActions), false));
55076
55051
  }
55077
55052
  return {
55078
55053
  structureIsComplete: structureIsComplete,
@@ -55080,19 +55055,6 @@ function matchUpActions(params) {
55080
55055
  isDoubleExit: isDoubleExit,
55081
55056
  };
55082
55057
  }
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
55058
 
55097
55059
  /**
55098
55060
  * Calculates the valid actions for a draw position based on the provided parameters.
@@ -55178,8 +55140,7 @@ function positionActions(params) {
55178
55140
  drawDefinition: drawDefinition,
55179
55141
  structure: structure,
55180
55142
  }).policyActions;
55181
- var possiblyDisablingAction = ![QUALIFYING, MAIN].includes(structure.stage) ||
55182
- structure.stageSequence !== 1;
55143
+ var possiblyDisablingAction = ![QUALIFYING, MAIN].includes(structure.stage) || structure.stageSequence !== 1;
55183
55144
  var drawId = drawDefinition.drawId;
55184
55145
  var validActions = [];
55185
55146
  var _j = structureAssignedDrawPositions({ structure: structure }), assignedPositions = _j.assignedPositions, positionAssignments = _j.positionAssignments;
@@ -55257,11 +55218,9 @@ function positionActions(params) {
55257
55218
  validAssignmentActions === null || validAssignmentActions === void 0 ? void 0 : validAssignmentActions.forEach(function (action) { return validActions.push(action); });
55258
55219
  }
55259
55220
  var participantId = (positionAssignment || {}).participantId;
55260
- var participant = participantId &&
55261
- tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
55221
+ var participant = participantId && tournamentParticipants.find(function (participant) { return participant.participantId === participantId; });
55262
55222
  if (positionAssignment) {
55263
- if (isAvailableAction({ policyActions: policyActions, action: REMOVE_ASSIGNMENT }) &&
55264
- !isActiveDrawPosition) {
55223
+ if (isAvailableAction({ policyActions: policyActions, action: REMOVE_ASSIGNMENT }) && !isActiveDrawPosition) {
55265
55224
  validActions.push({
55266
55225
  type: REMOVE_ASSIGNMENT,
55267
55226
  method: REMOVE_ASSIGNMENT_METHOD,
@@ -55278,8 +55237,7 @@ function positionActions(params) {
55278
55237
  }
55279
55238
  // in this case the ASSIGN_BYE_METHOD is called after removing assigned participant
55280
55239
  // option should not be available if exising assignment is a bye
55281
- if (isAvailableAction({ policyActions: policyActions, action: ASSIGN_BYE }) &&
55282
- !isByePosition) {
55240
+ if (isAvailableAction({ policyActions: policyActions, action: ASSIGN_BYE }) && !isByePosition) {
55283
55241
  validActions.push({
55284
55242
  type: ASSIGN_BYE,
55285
55243
  method: REMOVE_ASSIGNMENT_METHOD,
@@ -55288,8 +55246,7 @@ function positionActions(params) {
55288
55246
  });
55289
55247
  }
55290
55248
  }
55291
- var validToAssignSeed = structure.stage === QUALIFYING ||
55292
- (structure.stage === MAIN && structure.stageSequence === 1);
55249
+ var validToAssignSeed = structure.stage === QUALIFYING || (structure.stage === MAIN && structure.stageSequence === 1);
55293
55250
  if (!isByePosition &&
55294
55251
  // if any drawPositions are active, action is disabled unless override in policy
55295
55252
  activePositionsCheck({
@@ -55396,8 +55353,7 @@ function positionActions(params) {
55396
55353
  validActions.push(validSwapAction);
55397
55354
  }
55398
55355
  }
55399
- if (isAvailableAction({ policyActions: policyActions, action: ALTERNATE_PARTICIPANT }) &&
55400
- !disablePlacementActions) {
55356
+ if (isAvailableAction({ policyActions: policyActions, action: ALTERNATE_PARTICIPANT }) && !disablePlacementActions) {
55401
55357
  var validAlternatesAction = getValidAlternatesAction({
55402
55358
  possiblyDisablingAction: possiblyDisablingAction,
55403
55359
  tournamentParticipants: tournamentParticipants,
@@ -55435,8 +55391,7 @@ function positionActions(params) {
55435
55391
  if (validLuckyLosersAction)
55436
55392
  validActions.push(validLuckyLosersAction);
55437
55393
  }
55438
- if ((participant === null || participant === void 0 ? void 0 : participant.participantType) === PAIR &&
55439
- isAvailableAction({ policyActions: policyActions, action: MODIFY_PAIR_ASSIGNMENT })) {
55394
+ if ((participant === null || participant === void 0 ? void 0 : participant.participantType) === PAIR && isAvailableAction({ policyActions: policyActions, action: MODIFY_PAIR_ASSIGNMENT })) {
55440
55395
  var validModifyAssignedPairAction = getValidModifyAssignedPairAction({
55441
55396
  tournamentParticipants: tournamentParticipants,
55442
55397
  returnParticipants: returnParticipants,
@@ -65030,11 +64985,15 @@ function venueModify(_a) {
65030
64985
  var venue = result.venue;
65031
64986
  // not valid to modify a venueId
65032
64987
  var validAttributes = Object.keys(venueTemplate()).filter(function (attribute) { return attribute !== 'venueId'; });
65033
- var validModificationAttributes = Object.keys(modifications).filter(function (attribute) { return validAttributes.includes(attribute); });
64988
+ var validModificationAttributes = Object.keys(modifications).filter(function (attribute) {
64989
+ return validAttributes.includes(attribute);
64990
+ });
65034
64991
  if (!validModificationAttributes.length)
65035
64992
  return { error: NO_VALID_ATTRIBUTES };
65036
64993
  var validReplacements = validAttributes.filter(function (attribute) { return !['courts', 'onlineResources'].includes(attribute); });
65037
- var validReplacementAttributes = Object.keys(modifications).filter(function (attribute) { return validReplacements.includes(attribute); });
64994
+ var validReplacementAttributes = Object.keys(modifications).filter(function (attribute) {
64995
+ return validReplacements.includes(attribute);
64996
+ });
65038
64997
  venue &&
65039
64998
  validReplacementAttributes.forEach(function (attribute) {
65040
64999
  var _a;
@@ -65042,12 +65001,10 @@ function venueModify(_a) {
65042
65001
  });
65043
65002
  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
65003
  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); });
65004
+ var courtIdsToDelete = courtIdsToModify.length && existingCourtIds.filter(function (courtId) { return !courtIdsToModify.includes(courtId); });
65046
65005
  var matchUpsWithCourtId = [];
65047
65006
  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
- });
65007
+ 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
65008
  var scheduleDeletionsCount = courtsToDelete === null || courtsToDelete === void 0 ? void 0 : courtsToDelete.map(function (court) {
65052
65009
  var e_3, _a;
65053
65010
  var _b, _c, _d;
@@ -65075,11 +65032,9 @@ function venueModify(_a) {
65075
65032
  }
65076
65033
  return (_d = (_c = result.matchUps) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
65077
65034
  }).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
- });
65035
+ console.log({ scheduleDeletionsCount: scheduleDeletionsCount });
65036
+ if (venue && (!scheduleDeletionsCount || allowModificationWhenMatchUpsScheduled)) {
65037
+ venue.courts = (_k = venue.courts) === null || _k === void 0 ? void 0 : _k.filter(function (court) { return courtIdsToModify.includes(court.courtId); });
65083
65038
  bulkScheduleTournamentMatchUps({
65084
65039
  schedule: { courtId: '', scheduledDate: '' },
65085
65040
  matchUpDetails: matchUpsWithCourtId,