courthive-components 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/courthive-components.es.js +51667 -0
- package/dist/courthive-components.umd.js +31 -0
- package/dist/vite.svg +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function(ti,As){typeof exports=="object"&&typeof module<"u"?As(exports):typeof define=="function"&&define.amd?define(["exports"],As):(ti=typeof globalThis<"u"?globalThis:ti||self,As(ti["courthive-components"]={}))})(this,function(ti){"use strict";var As,Pt="colors",Tr="sizes",Ee="space",eR={gap:Ee,gridGap:Ee,columnGap:Ee,gridColumnGap:Ee,rowGap:Ee,gridRowGap:Ee,inset:Ee,insetBlock:Ee,insetBlockEnd:Ee,insetBlockStart:Ee,insetInline:Ee,insetInlineEnd:Ee,insetInlineStart:Ee,margin:Ee,marginTop:Ee,marginRight:Ee,marginBottom:Ee,marginLeft:Ee,marginBlock:Ee,marginBlockEnd:Ee,marginBlockStart:Ee,marginInline:Ee,marginInlineEnd:Ee,marginInlineStart:Ee,padding:Ee,paddingTop:Ee,paddingRight:Ee,paddingBottom:Ee,paddingLeft:Ee,paddingBlock:Ee,paddingBlockEnd:Ee,paddingBlockStart:Ee,paddingInline:Ee,paddingInlineEnd:Ee,paddingInlineStart:Ee,top:Ee,right:Ee,bottom:Ee,left:Ee,scrollMargin:Ee,scrollMarginTop:Ee,scrollMarginRight:Ee,scrollMarginBottom:Ee,scrollMarginLeft:Ee,scrollMarginX:Ee,scrollMarginY:Ee,scrollMarginBlock:Ee,scrollMarginBlockEnd:Ee,scrollMarginBlockStart:Ee,scrollMarginInline:Ee,scrollMarginInlineEnd:Ee,scrollMarginInlineStart:Ee,scrollPadding:Ee,scrollPaddingTop:Ee,scrollPaddingRight:Ee,scrollPaddingBottom:Ee,scrollPaddingLeft:Ee,scrollPaddingX:Ee,scrollPaddingY:Ee,scrollPaddingBlock:Ee,scrollPaddingBlockEnd:Ee,scrollPaddingBlockStart:Ee,scrollPaddingInline:Ee,scrollPaddingInlineEnd:Ee,scrollPaddingInlineStart:Ee,fontSize:"fontSizes",background:Pt,backgroundColor:Pt,backgroundImage:Pt,borderImage:Pt,border:Pt,borderBlock:Pt,borderBlockEnd:Pt,borderBlockStart:Pt,borderBottom:Pt,borderBottomColor:Pt,borderColor:Pt,borderInline:Pt,borderInlineEnd:Pt,borderInlineStart:Pt,borderLeft:Pt,borderLeftColor:Pt,borderRight:Pt,borderRightColor:Pt,borderTop:Pt,borderTopColor:Pt,caretColor:Pt,color:Pt,columnRuleColor:Pt,fill:Pt,outline:Pt,outlineColor:Pt,stroke:Pt,textDecorationColor:Pt,fontFamily:"fonts",fontWeight:"fontWeights",lineHeight:"lineHeights",letterSpacing:"letterSpacings",blockSize:Tr,minBlockSize:Tr,maxBlockSize:Tr,inlineSize:Tr,minInlineSize:Tr,maxInlineSize:Tr,width:Tr,minWidth:Tr,maxWidth:Tr,height:Tr,minHeight:Tr,maxHeight:Tr,flexBasis:Tr,gridTemplateColumns:Tr,gridTemplateRows:Tr,borderWidth:"borderWidths",borderTopWidth:"borderWidths",borderRightWidth:"borderWidths",borderBottomWidth:"borderWidths",borderLeftWidth:"borderWidths",borderStyle:"borderStyles",borderTopStyle:"borderStyles",borderRightStyle:"borderStyles",borderBottomStyle:"borderStyles",borderLeftStyle:"borderStyles",borderRadius:"radii",borderTopLeftRadius:"radii",borderTopRightRadius:"radii",borderBottomRightRadius:"radii",borderBottomLeftRadius:"radii",boxShadow:"shadows",textShadow:"shadows",transition:"transitions",zIndex:"zIndices"},tR=(t,e)=>typeof e=="function"?{"()":Function.prototype.toString.call(e)}:e,Ba=()=>{const t=Object.create(null);return(e,r,...n)=>{const o=(i=>JSON.stringify(i,tR))(e);return o in t?t[o]:t[o]=r(e,...n)}},yl=Symbol.for("sxs.internal"),mp=(t,e)=>Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)),kg=t=>{for(const e in t)return!0;return!1},{hasOwnProperty:rR}=Object.prototype,gp=t=>t.includes("-")?t:t.replace(/[A-Z]/g,e=>"-"+e.toLowerCase()),nR=/\s+(?![^()]*\))/,Us=t=>e=>t(...typeof e=="string"?String(e).split(nR):[e]),Gg={appearance:t=>({WebkitAppearance:t,appearance:t}),backfaceVisibility:t=>({WebkitBackfaceVisibility:t,backfaceVisibility:t}),backdropFilter:t=>({WebkitBackdropFilter:t,backdropFilter:t}),backgroundClip:t=>({WebkitBackgroundClip:t,backgroundClip:t}),boxDecorationBreak:t=>({WebkitBoxDecorationBreak:t,boxDecorationBreak:t}),clipPath:t=>({WebkitClipPath:t,clipPath:t}),content:t=>({content:t.includes('"')||t.includes("'")||/^([A-Za-z]+\([^]*|[^]*-quote|inherit|initial|none|normal|revert|unset)$/.test(t)?t:`"${t}"`}),hyphens:t=>({WebkitHyphens:t,hyphens:t}),maskImage:t=>({WebkitMaskImage:t,maskImage:t}),maskSize:t=>({WebkitMaskSize:t,maskSize:t}),tabSize:t=>({MozTabSize:t,tabSize:t}),textSizeAdjust:t=>({WebkitTextSizeAdjust:t,textSizeAdjust:t}),userSelect:t=>({WebkitUserSelect:t,userSelect:t}),marginBlock:Us((t,e)=>({marginBlockStart:t,marginBlockEnd:e||t})),marginInline:Us((t,e)=>({marginInlineStart:t,marginInlineEnd:e||t})),maxSize:Us((t,e)=>({maxBlockSize:t,maxInlineSize:e||t})),minSize:Us((t,e)=>({minBlockSize:t,minInlineSize:e||t})),paddingBlock:Us((t,e)=>({paddingBlockStart:t,paddingBlockEnd:e||t})),paddingInline:Us((t,e)=>({paddingInlineStart:t,paddingInlineEnd:e||t}))},hp=/([\d.]+)([^]*)/,oR=(t,e)=>t.length?t.reduce((r,n)=>(r.push(...e.map(o=>o.includes("&")?o.replace(/&/g,/[ +>|~]/.test(n)&&/&.*&/.test(o)?`:is(${n})`:n):n+" "+o)),r),[]):e,iR=(t,e)=>t in sR&&typeof e=="string"?e.replace(/^((?:[^]*[^\w-])?)(fit-content|stretch)((?:[^\w-][^]*)?)$/,(r,n,o,i)=>n+(o==="stretch"?`-moz-available${i};${gp(t)}:${n}-webkit-fill-available`:`-moz-fit-content${i};${gp(t)}:${n}fit-content`)+i):String(e),sR={blockSize:1,height:1,inlineSize:1,maxBlockSize:1,maxHeight:1,maxInlineSize:1,maxWidth:1,minBlockSize:1,minHeight:1,minInlineSize:1,minWidth:1,width:1},wo=t=>t?t+"-":"",Wg=(t,e,r)=>t.replace(/([+-])?((?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)?(\$|--)([$\w-]+)/g,(n,o,i,s,a)=>s=="$"==!!i?n:(o||s=="--"?"calc(":"")+"var(--"+(s==="$"?wo(e)+(a.includes("$")?"":wo(r))+a.replace(/\$/g,"-"):a)+")"+(o||s=="--"?"*"+(o||"")+(i||"1")+")":"")),aR=/\s*,\s*(?![^()]*\))/,cR=Object.prototype.toString,Cs=(t,e,r,n,o)=>{let i,s,a;const c=(l,u,d)=>{let p,v;const f=m=>{for(p in m){const _=p.charCodeAt(0)===64,I=_&&Array.isArray(m[p])?m[p]:[m[p]];for(v of I){const P=/[A-Z]/.test(h=p)?h:h.replace(/-[^]/g,y=>y[1].toUpperCase()),O=typeof v=="object"&&v&&v.toString===cR&&(!n.utils[P]||!u.length);if(P in n.utils&&!O){const y=n.utils[P];if(y!==s){s=y,f(y(v)),s=null;continue}}else if(P in Gg){const y=Gg[P];if(y!==a){a=y,f(y(v)),a=null;continue}}if(_&&(g=p.slice(1)in n.media?"@media "+n.media[p.slice(1)]:p,p=g.replace(/\(\s*([\w-]+)\s*(=|<|<=|>|>=)\s*([\w-]+)\s*(?:(<|<=|>|>=)\s*([\w-]+)\s*)?\)/g,(y,S,T,E,b,N)=>{const w=hp.test(S),$=.0625*(w?-1:1),[U,A]=w?[E,S]:[S,E];return"("+(T[0]==="="?"":T[0]===">"===w?"max-":"min-")+U+":"+(T[0]!=="="&&T.length===1?A.replace(hp,(M,C,D)=>Number(C)+$*(T===">"?1:-1)+D):A)+(b?") and ("+(b[0]===">"?"min-":"max-")+U+":"+(b.length===1?N.replace(hp,(M,C,D)=>Number(C)+$*(b===">"?-1:1)+D):N):"")+")"})),O){const y=_?d.concat(p):[...d],S=_?[...u]:oR(u,p.split(aR));i!==void 0&&o(Hg(...i)),i=void 0,c(v,S,y)}else i===void 0&&(i=[[],u,d]),p=_||p.charCodeAt(0)!==36?p:`--${wo(n.prefix)}${p.slice(1).replace(/\$/g,"-")}`,v=O?v:typeof v=="number"?v&&P in lR?String(v)+"px":String(v):Wg(iR(P,v??""),n.prefix,n.themeMap[P]),i[0].push(`${_?`${p} `:`${gp(p)}:`}${v}`)}}var g,h};f(l),i!==void 0&&o(Hg(...i)),i=void 0};c(t,e,r)},Hg=(t,e,r)=>`${r.map(n=>`${n}{`).join("")}${e.length?`${e.join(",")}{`:""}${t.join(";")}${e.length?"}":""}${Array(r.length?r.length+1:0).join("}")}`,lR={animationDelay:1,animationDuration:1,backgroundSize:1,blockSize:1,border:1,borderBlock:1,borderBlockEnd:1,borderBlockEndWidth:1,borderBlockStart:1,borderBlockStartWidth:1,borderBlockWidth:1,borderBottom:1,borderBottomLeftRadius:1,borderBottomRightRadius:1,borderBottomWidth:1,borderEndEndRadius:1,borderEndStartRadius:1,borderInlineEnd:1,borderInlineEndWidth:1,borderInlineStart:1,borderInlineStartWidth:1,borderInlineWidth:1,borderLeft:1,borderLeftWidth:1,borderRadius:1,borderRight:1,borderRightWidth:1,borderSpacing:1,borderStartEndRadius:1,borderStartStartRadius:1,borderTop:1,borderTopLeftRadius:1,borderTopRightRadius:1,borderTopWidth:1,borderWidth:1,bottom:1,columnGap:1,columnRule:1,columnRuleWidth:1,columnWidth:1,containIntrinsicSize:1,flexBasis:1,fontSize:1,gap:1,gridAutoColumns:1,gridAutoRows:1,gridTemplateColumns:1,gridTemplateRows:1,height:1,inlineSize:1,inset:1,insetBlock:1,insetBlockEnd:1,insetBlockStart:1,insetInline:1,insetInlineEnd:1,insetInlineStart:1,left:1,letterSpacing:1,margin:1,marginBlock:1,marginBlockEnd:1,marginBlockStart:1,marginBottom:1,marginInline:1,marginInlineEnd:1,marginInlineStart:1,marginLeft:1,marginRight:1,marginTop:1,maxBlockSize:1,maxHeight:1,maxInlineSize:1,maxWidth:1,minBlockSize:1,minHeight:1,minInlineSize:1,minWidth:1,offsetDistance:1,offsetRotate:1,outline:1,outlineOffset:1,outlineWidth:1,overflowClipMargin:1,padding:1,paddingBlock:1,paddingBlockEnd:1,paddingBlockStart:1,paddingBottom:1,paddingInline:1,paddingInlineEnd:1,paddingInlineStart:1,paddingLeft:1,paddingRight:1,paddingTop:1,perspective:1,right:1,rowGap:1,scrollMargin:1,scrollMarginBlock:1,scrollMarginBlockEnd:1,scrollMarginBlockStart:1,scrollMarginBottom:1,scrollMarginInline:1,scrollMarginInlineEnd:1,scrollMarginInlineStart:1,scrollMarginLeft:1,scrollMarginRight:1,scrollMarginTop:1,scrollPadding:1,scrollPaddingBlock:1,scrollPaddingBlockEnd:1,scrollPaddingBlockStart:1,scrollPaddingBottom:1,scrollPaddingInline:1,scrollPaddingInlineEnd:1,scrollPaddingInlineStart:1,scrollPaddingLeft:1,scrollPaddingRight:1,scrollPaddingTop:1,shapeMargin:1,textDecoration:1,textDecorationThickness:1,textIndent:1,textUnderlineOffset:1,top:1,transitionDelay:1,transitionDuration:1,verticalAlign:1,width:1,wordSpacing:1},qg=t=>String.fromCharCode(t+(t>25?39:97)),Di=t=>(e=>{let r,n="";for(r=Math.abs(e);r>52;r=r/52|0)n=qg(r%52)+n;return qg(r%52)+n})(((e,r)=>{let n=r.length;for(;n;)e=33*e^r.charCodeAt(--n);return e})(5381,JSON.stringify(t))>>>0),ka=["themed","global","styled","onevar","resonevar","allvar","inline"],uR=t=>{if(t.href&&!t.href.startsWith(location.origin))return!1;try{return!!t.cssRules}catch{return!1}},dR=t=>{let e;const r=()=>{const{cssRules:o}=e.sheet;return[].map.call(o,(i,s)=>{const{cssText:a}=i;let c="";if(a.startsWith("--sxs"))return"";if(o[s-1]&&(c=o[s-1].cssText).startsWith("--sxs")){if(!i.cssRules.length)return"";for(const l in e.rules)if(e.rules[l].group===i)return`--sxs{--sxs:${[...e.rules[l].cache].join(" ")}}${a}`;return i.cssRules.length?`${c}${a}`:""}return a}).join("")},n=()=>{if(e){const{rules:a,sheet:c}=e;if(!c.deleteRule){for(;Object(Object(c.cssRules)[0]).type===3;)c.cssRules.splice(0,1);c.cssRules=[]}for(const l in a)delete a[l]}const o=Object(t).styleSheets||[];for(const a of o)if(uR(a)){for(let c=0,l=a.cssRules;l[c];++c){const u=Object(l[c]);if(u.type!==1)continue;const d=Object(l[c+1]);if(d.type!==4)continue;++c;const{cssText:p}=u;if(!p.startsWith("--sxs"))continue;const v=p.slice(14,-3).trim().split(/\s+/),f=ka[v[0]];f&&(e||(e={sheet:a,reset:n,rules:{},toString:r}),e.rules[f]={group:d,index:c,cache:new Set(v)})}if(e)break}if(!e){const a=(c,l)=>({type:l,cssRules:[],insertRule(u,d){this.cssRules.splice(d,0,a(u,{import:3,undefined:1}[(u.toLowerCase().match(/^@([a-z]+)/)||[])[1]]||4))},get cssText(){return c==="@media{}"?`@media{${[].map.call(this.cssRules,u=>u.cssText).join("")}}`:c}});e={sheet:t?(t.head||t).appendChild(document.createElement("style")).sheet:a("","text/css"),rules:{},reset:n,toString:r}}const{sheet:i,rules:s}=e;for(let a=ka.length-1;a>=0;--a){const c=ka[a];if(!s[c]){const l=ka[a+1],u=s[l]?s[l].index:i.cssRules.length;i.insertRule("@media{}",u),i.insertRule(`--sxs{--sxs:${a}}`,u),s[c]={group:i.cssRules[u+1],index:u,cache:new Set([a])}}pR(s[c])}};return n(),e},pR=t=>{const e=t.group;let r=e.cssRules.length;t.apply=n=>{try{e.insertRule(n,r),++r}catch{}}},Ga=Symbol(),fR=Ba(),vR=(t,e)=>fR(t,()=>(...r)=>{let n={type:null,composers:new Set};for(const o of r)if(o!=null)if(o[yl]){n.type==null&&(n.type=o[yl].type);for(const i of o[yl].composers)n.composers.add(i)}else o.constructor!==Object||o.$$typeof?n.type==null&&(n.type=o):n.composers.add(mR(o,t));return n.type==null&&(n.type="span"),n.composers.size||n.composers.add(["PJLV",{},[],[],{},[]]),gR(t,n,e)}),mR=({variants:t,compoundVariants:e,defaultVariants:r,...n},o)=>{const i=`${wo(o.prefix)}c-${Di(n)}`,s=[],a=[],c=Object.create(null),l=[];for(const p in r)c[p]=String(r[p]);if(typeof t=="object"&&t)for(const p in t){u=c,d=p,rR.call(u,d)||(c[p]="undefined");const v=t[p];for(const f in v){const m={[p]:String(f)};String(f)==="undefined"&&l.push(p);const g=v[f],h=[m,g,!kg(g)];s.push(h)}}var u,d;if(typeof e=="object"&&e)for(const p of e){let{css:v,...f}=p;v=typeof v=="object"&&v||{};for(const g in f)f[g]=String(f[g]);const m=[f,v,!kg(v)];a.push(m)}return[i,n,s,a,c,l]},gR=(t,e,r)=>{const[n,o,i,s]=hR(e.composers),a=typeof e.type=="function"||e.type.$$typeof?(d=>{function p(){for(let v=0;v<p[Ga].length;v++){const[f,m]=p[Ga][v];d.rules[f].apply(m)}return p[Ga]=[],null}return p[Ga]=[],p.rules={},ka.forEach(v=>p.rules[v]={apply:f=>p[Ga].push([v,f])}),p})(r):null,c=(a||r).rules,l=`.${n}${o.length>1?`:where(.${o.slice(1).join(".")})`:""}`,u=d=>{d=typeof d=="object"&&d||_R;const{css:p,...v}=d,f={};for(const h in i)if(delete v[h],h in d){let _=d[h];typeof _=="object"&&_?f[h]={"@initial":i[h],..._}:(_=String(_),f[h]=_!=="undefined"||s.has(h)?_:i[h])}else f[h]=i[h];const m=new Set([...o]);for(const[h,_,I,P]of e.composers){r.rules.styled.cache.has(h)||(r.rules.styled.cache.add(h),Cs(_,[`.${h}`],[],t,S=>{c.styled.apply(S)}));const O=Yg(I,f,t.media),y=Yg(P,f,t.media,!0);for(const S of O)if(S!==void 0)for(const[T,E,b]of S){const N=`${h}-${Di(E)}-${T}`;m.add(N);const w=(b?r.rules.resonevar:r.rules.onevar).cache,$=b?c.resonevar:c.onevar;w.has(N)||(w.add(N),Cs(E,[`.${N}`],[],t,U=>{$.apply(U)}))}for(const S of y)if(S!==void 0)for(const[T,E]of S){const b=`${h}-${Di(E)}-${T}`;m.add(b),r.rules.allvar.cache.has(b)||(r.rules.allvar.cache.add(b),Cs(E,[`.${b}`],[],t,N=>{c.allvar.apply(N)}))}}if(typeof p=="object"&&p){const h=`${n}-i${Di(p)}-css`;m.add(h),r.rules.inline.cache.has(h)||(r.rules.inline.cache.add(h),Cs(p,[`.${h}`],[],t,_=>{c.inline.apply(_)}))}for(const h of String(d.className||"").trim().split(/\s+/))h&&m.add(h);const g=v.className=[...m].join(" ");return{type:e.type,className:g,selector:l,props:v,toString:()=>g,deferredInjector:a}};return mp(u,{className:n,selector:l,[yl]:e,toString:()=>(r.rules.styled.cache.has(n)||u(),n)})},hR=t=>{let e="";const r=[],n={},o=[];for(const[i,,,,s,a]of t){e===""&&(e=i),r.push(i),o.push(...a);for(const c in s){const l=s[c];(n[c]===void 0||l!=="undefined"||a.includes(l))&&(n[c]=l)}}return[e,r,n,new Set(o)]},Yg=(t,e,r,n)=>{const o=[];e:for(let[i,s,a]of t){if(a)continue;let c,l=0,u=!1;for(c in i){const d=i[c];let p=e[c];if(p!==d){if(typeof p!="object"||!p)continue e;{let v,f,m=0;for(const g in p){if(d===String(p[g])){if(g!=="@initial"){const h=g.slice(1);(f=f||[]).push(h in r?r[h]:g.replace(/^@media ?/,"")),u=!0}l+=m,v=!0}++m}if(f&&f.length&&(s={["@media "+f.join(", ")]:s}),!v)continue e}}}(o[l]=o[l]||[]).push([n?"cv":`${c}-${i[c]}`,s,u])}return o},_R={},IR=Ba(),PR=(t,e)=>IR(t,()=>(...r)=>{const n=()=>{for(let o of r){o=typeof o=="object"&&o||{};let i=Di(o);if(!e.rules.global.cache.has(i)){if(e.rules.global.cache.add(i),"@import"in o){let s=[].indexOf.call(e.sheet.cssRules,e.rules.themed.group)-1;for(let a of[].concat(o["@import"]))a=a.includes('"')||a.includes("'")?a:`"${a}"`,e.sheet.insertRule(`@import ${a};`,s++);delete o["@import"]}Cs(o,[],[],t,s=>{e.rules.global.apply(s)})}}return""};return mp(n,{toString:n})}),yR=Ba(),SR=(t,e)=>yR(t,()=>r=>{const n=`${wo(t.prefix)}k-${Di(r)}`,o=()=>{if(!e.rules.global.cache.has(n)){e.rules.global.cache.add(n);const i=[];Cs(r,[],[],t,a=>i.push(a));const s=`@keyframes ${n}{${i.join("")}}`;e.rules.global.apply(s)}return n};return mp(o,{get name(){return o()},toString:o})}),OR=class{constructor(t,e,r,n){this.token=t==null?"":String(t),this.value=e==null?"":String(e),this.scale=r==null?"":String(r),this.prefix=n==null?"":String(n)}get computedValue(){return"var("+this.variable+")"}get variable(){return"--"+wo(this.prefix)+wo(this.scale)+this.token}toString(){return this.computedValue}},bR=Ba(),TR=(t,e)=>bR(t,()=>(r,n)=>{n=typeof r=="object"&&r||Object(n);const o=`.${r=(r=typeof r=="string"?r:"")||`${wo(t.prefix)}t-${Di(n)}`}`,i={},s=[];for(const c in n){i[c]={};for(const l in n[c]){const u=`--${wo(t.prefix)}${c}-${l}`,d=Wg(String(n[c][l]),t.prefix,c);i[c][l]=new OR(l,d,c,t.prefix),s.push(`${u}:${d}`)}}const a=()=>{if(s.length&&!e.rules.themed.cache.has(r)){e.rules.themed.cache.add(r);const c=`${n===t.theme?":root,":""}.${r}{${s.join(";")}}`;e.rules.themed.apply(c)}return r};return{...i,get className(){return a()},selector:o,toString:a}}),ER=Ba(),wR=t=>{let e=!1;const r=ER(t,n=>{e=!0;const o="prefix"in(n=typeof n=="object"&&n||{})?String(n.prefix):"",i=typeof n.media=="object"&&n.media||{},s=typeof n.root=="object"?n.root||null:globalThis.document||null,a=typeof n.theme=="object"&&n.theme||{},c={prefix:o,media:i,theme:a,themeMap:typeof n.themeMap=="object"&&n.themeMap||{...eR},utils:typeof n.utils=="object"&&n.utils||{}},l=dR(s),u={css:vR(c,l),globalCss:PR(c,l),keyframes:SR(c,l),createTheme:TR(c,l),reset(){l.reset(),u.theme.toString()},theme:{},sheet:l,config:c,prefix:o,getCssText:l.toString,toString:l.toString};return String(u.theme=u.createTheme(a)),u});return e||r.reset(),r},$R=()=>As||(As=wR()),dt=(...t)=>$R().css(...t);function NR({variant:t}){return dt({margin:"2.5px 0",variants:{variant:{showAddress:{lineHeight:"2.3em"}}}})({variant:t})}const zg=dt({justifyContent:"flex-start",alignItems:"center",whiteSpace:"nowrap",fontWeight:500,display:"flex"}),AR=dt({textTransform:"$participant$textTransform",fontSize:"0.875rem",fontWeight:500,variants:{variant:{winner:{fontWeight:700,color:"$winnerName"},loser:{fontWeight:500}}}}),UR=dt({"&::WebkitScrollbar":{display:"none"},justifyContent:"space-between",flexDirection:"column",marginInlineEnd:"0rem",scrollbarWidth:"none",overflowX:"scroll",fontWeight:500,display:"flex",width:"100%",variants:{variant:{doubles:{marginTop:"0.25rem",fontSize:"0.75rem",lineHeight:"1rem"}}}});function CR({drawPosition:t,sideNumber:e}){return dt({minHeight:"$participant$minHeight",justifyContent:"space-between",paddingInlineStart:"0.75rem",backgroundColor:"$matchUp",paddingInlineEnd:"0rem",boxSizing:"border-box",paddingBottom:".2rem",position:"relative",alignItems:"center",paddingTop:".2rem",minWidth:"15rem",cursor:"pointer",display:"flex",flexGrow:1,"& p":{fontFamily:"Sharp Sans, Arial, sans-serif",color:"$color"},variants:{sideNumber:{1:{borderBottom:"1px solid $internalDividers"}}}})({sideNumber:e,css:t&&{"&:before":{backgroundColor:"$backgroundColor",content:`${t}`,justifyContent:"center",alignContent:"center",insetInlineStart:-10,position:"absolute",color:"#55AFFE",display:"flex",width:20}}})}function MR({winnerChevron:t,isDoubles:e}){const r=(e?.4:.3)*2;return dt({variants:{variant:{winner:{"&::before":{borderTop:`${r}rem solid transparent`,borderBottom:`${r}rem solid transparent`,borderInlineStart:"8px solid #008f70",position:"absolute",insetInlineStart:0,display:"block",content:""}}}}})({variant:t?"winner":void 0})}const DR=dt({textTransform:"uppercase",fontSize:"0.75rem",lineHeight:"1rem",marginInlineStart:".5rem",color:"$participant$seed"}),Kg=dt({fontSize:"smaller",color:"gray"});function jR({className:t,composition:e,side:r}){const n=(r==null?void 0:r.seedValue)||(r==null?void 0:r.seedNumber);if(!n)return"";const o=(e==null?void 0:e.configuration)||{},{bracketedSeeds:i}=o,s=typeof i=="boolean"&&["(",")"]||i==="square"&&["[","]"]||["",""],a=`${s[0]}${n}${s[1]}`,c=o.seedingElement==="sup"?"sup":"span",l=document.createElement(c);return l.className=t,l.innerHTML=a,l}const RR=dt({WebkitBoxSizing:"border-box",display:"inline-block",boxSizing:"border-box",marginInlineStart:2,position:"relative",fontSize:"smaller",fontWeight:"bold",marginInlineEnd:2,borderRadius:2,width:"1.8rem",color:"blue"});var FR=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Qg(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Jg={exports:{}};/*!
|
|
2
|
+
Copyright (c) 2018 Jed Watson.
|
|
3
|
+
Licensed under the MIT License (MIT), see
|
|
4
|
+
http://jedwatson.github.io/classnames
|
|
5
|
+
*/(function(t){(function(){var e={}.hasOwnProperty;function r(){for(var n=[],o=0;o<arguments.length;o++){var i=arguments[o];if(i){var s=typeof i;if(s==="string"||s==="number")n.push(i);else if(Array.isArray(i)){if(i.length){var a=r.apply(null,i);a&&n.push(a)}}else if(s==="object"){if(i.toString!==Object.prototype.toString&&!i.toString.toString().includes("[native code]")){n.push(i.toString());continue}for(var c in i)e.call(i,c)&&i[c]&&n.push(c)}}}return n.join(" ")}t.exports?(r.default=r,t.exports=r):window.classNames=r})()})(Jg);var LR=Jg.exports;const Ms=Qg(LR);function VR({individualParticipant:t,composition:e,className:r,matchUp:n,spacer:o}){var f,m,g;const i=(n==null?void 0:n.matchUpType)||"SINGLES",s=(f=t==null?void 0:t.ratings)==null?void 0:f[i],a=(m=t==null?void 0:t.rankings)==null?void 0:m[i],c=(g=e==null?void 0:e.configuration)==null?void 0:g.scaleAttributes,l=c==null?void 0:c.scaleType,u=c==null?void 0:c.accessor,d=l==="RATING"?s:a,p=!o&&(d==null?void 0:d[u]),v=document.createElement("span");return(p||o)&&(v.className=Ms(r,RR())),v.innerHTML=p||"",v}const xR="normal",Zg="timed",BR="final",_p="NOAD",Sl="SET",kR={S:xR,F:BR};function Ip(t,e){if(typeof t=="object"){if(t.timed&&!isNaN(t.minutes))return Pp(t);if(t.bestOf&&t.setFormat)return GR(t,e)}}function Ol(t){return!isNaN(Number(t))&&Number(t)}function Pp(t){let e=`T${t.minutes}`;return t.based&&(e+=t.based),t.modifier&&(e+=`@${t.modifier}`),e}function GR(t,e){var r;const n=Ol(t.bestOf);if((r=t.setFormat)!=null&&r.timed&&t.simplified&&n===1)return Pp(t.setFormat);const o=n&&`${Sl}${n}`||"",i=Xg(t.setFormat,e),s=i&&`S:${i}`||"",a=Xg(t.finalSetFormat,e),c=n>1&&a&&i!==a&&`F:${a}`||"";if(o&&i)return[o,s,c].filter(u=>u).join("-")}function Xg(t,e){if(typeof t=="object"&&Object.keys(t).length){if(t.timed)return Pp(t);if(t.tiebreakSet)return eh(t.tiebreakSet);const r=Ol(t.setTo);if(r){const n=t.NoAD&&_p||"",o=eh(t.tiebreakFormat),i=o&&`/${o}`||"",s=Ol(t.tiebreakAt),a=s&&(s!==r||e)&&`@${s}`||"";if(o!==!1)return`${r}${n}${i}${a}`}}}function eh(t){if(t){if(typeof t=="object"&&!t.tiebreakTo)return"";if(typeof t=="object"&&Ol(t.tiebreakTo)){let e=`TB${t.tiebreakTo}${t.NoAD?_p:""}`;return t.modifier&&(e+=`@${t.modifier}`),e}else return!1}}function Vr(t){return isNaN(t)?!1:t&&(t&t-1)===0}function WR(t){if(!Vr(t))return!1;let e=t,r=1;for(;e!==2;)r+=1,e=e/2;return r}function yp(t){return isNaN(t)?0:t%2&&t+1||t}function Sp(t){return Math.pow(2,Math.round(Math.log(t)/Math.log(2)))}function Ot(t){return!isNaN(parseFloat(t))}function HR(t){const e=parseInt(t);if(!isNaN(e))return e===0?!1:(e&-e)===1}function Ds(t){if(isNaN(t))return!1;for(;!Vr(t);)t++;return t}function Er(t,e){return t=Math.ceil(t),e=Math.floor(e),Math.floor(Math.random()*(e-t+1))+t}function ut(t){return Number.isSafeInteger(typeof t=="string"?+t:t)}function qR(t=1,e=3,r=!0){let n=0;for(let o=0;o<e;o++)n+=Math.random()*(t/e);return r&&t>1?Math.round(n):n}function YR(t,e){e||(e=1);const r=1/e;return Math.round(t*r)/r}function th(t,e,r,n,o=2){const i=1-Math.random(),s=1-Math.random();let a=Math.sqrt(-2*Math.log(i))*Math.cos(2*Math.PI*s);return a=a/10+.5,a>1||a<0?a=th(t,e,r):(a=Math.pow(a,r),a*=e-t,a+=t),n&&(a=YR(a,n)),parseFloat(a.toFixed(o))}function _r(t){if(typeof t=="string"){const e=t.startsWith("T")&&Zg||t.startsWith(Sl)&&Sl||"";if(e===Zg){const n={simplified:!0,setFormat:ih(t),bestOf:1};if(n.setFormat)return n}if(e===Sl)return zR(t)}}function zR(t){const e=t.split("-"),r=Wa(e[0].slice(3)),n=e&&rh(e[1]),o=e&&rh(e[2]),i=r&&r<6,s=!e[2]||o,a=n,c={bestOf:r,setFormat:n};if(o&&(c.finalSetFormat=o),i&&a&&s)return c}function rh(t){if((t==null?void 0:t[1])===":"){const e=t.split(":"),r=kR[e[0]],n=e[1];if(r&&n){if(n.indexOf("TB")===0){const g=oh(n);return g===!1?!1:typeof g=="object"?{tiebreakSet:g}:void 0}if(n.indexOf("T")===0)return ih(n);const s=t.match(/^[FS]:(\d+)([A-Za-z]*)/),a=s&&sh(s[2])||!1,c=!(s!=null&&s[2])||a,l=s?Wa(s[1]):void 0,u=nh(n),d=u!==!1,p=d&&u||l,v=oh(n.split("/")[1]),f=v!==!1,m={setTo:l};return a&&(m.NoAD=!0),v?(m.tiebreakFormat=v,m.tiebreakAt=p):m.noTiebreak=!0,l&&c&&f&&d&&m||!1}}}function nh(t,e=!0){const r=(t==null?void 0:t.indexOf("@"))>0&&t.split("@");if(r)return(e?Wa(r[1]):r[1])||!1}function oh(t){if(t)if(t.startsWith("TB")){const e=nh(t,!1),r=t.match(/^TB(\d+)([A-Za-z]*)/),n=r==null?void 0:r[1],o=r&&sh(r[2]),i=!(r!=null&&r[2])||o,s=Wa(n);if(s&&i){const a={tiebreakTo:s};return e&&typeof e=="string"&&!ut(e)&&(a.modifier=e),o&&(a.NoAD=!0),a}else return!1}else return!1}function ih(t){var e;const r=t.slice(1),n=r.match(/^(\d+)(@?[A-Za-z]*)/),o=Wa(n==null?void 0:n[1]);if(!o)return;const i={timed:!0,minutes:o},s=n==null?void 0:n[2],a=[void 0,"P","G"].includes(s);if(s&&!a){const c=(e=r.match(/^(\d+)(@)([A-Za-z]+)$/))==null?void 0:e[3];return c?(i.modifier=c,i):void 0}return s&&(i.based=n[2]),i}function sh(t){return t&&t.indexOf(_p)>=0}function Wa(t){return isNaN(Number(t))?0:Number(t)}function xr(t){if(typeof t!="string")return!1;const e=_r(t),r=t.match(/-S:(\d+)+\/TB(\d+)@?(\d*)*/),n=r==null?void 0:r[1],o=r==null?void 0:r[2],i=r==null?void 0:r[3],s=t.match(/-F:(\d+)+\/TB(\d+)@?(\d*)*/),a=s==null?void 0:s[1],c=s==null?void 0:s[2],l=s==null?void 0:s[3];return Ip(e,r&&o&&n===i||s&&c&&a===l)===t}const KR={isValidMatchUpFormat:xr,stringify:Ip,isValid:xr,parse:_r};function so(){return"1.4.1"}function $o(t){if(!t)return;const{tieFormatId:e,tieFormats:r}=t;if(t.tieFormat)return t.tieFormat;if(e&&Array.isArray(r))return r.find(n=>n.tieFormatId===e)}function Ha({item:t,drawDefinition:e,structure:r,event:n}){var o,i,s;if(t){if(t.tieFormat)return t.tieFormat;if(t.tieFormatId){if(e.tieFormat)return e.tieFormat;const a=(o=e.tieFormats)==null?void 0:o.find(c=>t.tieFormatId===c.tieFormatId);return a||(n.tieFormat?n.tieFormat:(i=n.tieFormats)==null?void 0:i.find(c=>t.tieFormatId===c.tieFormatId))}if(r.tieFormat)return r.tieFormat;if(r.tieFormatId){const a=(s=e.tieFormats)==null?void 0:s.find(c=>r.tieFormatId===c.tieFormatId);if(a)return a}}}function Xt({drawDefinition:t,structure:e,matchUp:r,event:n}){return{tieFormat:Ha({item:r,drawDefinition:t,structure:e,event:n})||Ha({item:e,drawDefinition:t,structure:e,event:n})||$o(t)||$o(n)}}function Ve(t){return t.filter((e,r,n)=>n.lastIndexOf(e)===r)}function or(t){return t.map(e=>[Math.random(),e]).sort((e,r)=>e[0]-r[0]).map(e=>e[1])}function mr(t){return t.reduce((e,r)=>(e[r]||(e[r]=0),e[r]++,e),{})}function QR(t){return JR(mr(t))}function JR(t){return Object.keys(t).reduce((e,r)=>{const n=t[r];return e[n]?e[n].push(r):e[n]=[r],e},{})}function ZR(t,e,r){return r.indexOf(t)===e}function ah(t){return t.filter(ZR)}function ir(t){return Array.isArray(t)&&t.length?t.splice(Math.floor(Math.random()*t.length),1)[0]:void 0}function gr(t){const e=Math.floor(Math.random()*t.length);return t[e]}function le(t,e){return Array.from({length:e-t},(r,n)=>n+t)}function hn(t,e){return e.reduce((r,n,o)=>(n===t&&r.push(o),r),[])}function jt(t,e){return!Array.isArray(t)||!Array.isArray(e)?[]:t.filter(r=>e.indexOf(r)!==-1).filter((r,n,o)=>o.indexOf(r)===n)}function ch(t,e){return!Array.isArray(t)||!Array.isArray(e)?[]:t.filter(r=>!e.includes(r))}function Gt(t,e){return!Array.isArray(t)||!Array.isArray(e)?!1:t.some(r=>e.includes(r))}function Rt(t,e){return t.reduce((r,n,o)=>{const i=Math.floor(o/e);return r[i]=[].concat(r[i]||[],n),r},[])}function XR(t){return t.reduce((e,r)=>{const n=e[e.length-1];return(!n||n[n.length-1]!==r-1)&&e.push([]),e[e.length-1].push(r),e},[])}function eF(t){return t.reduce((e,r)=>!isNaN(parseInt(r))&&e,!0)}function tF(t){return t.reduce((e,r)=>isNaN(parseInt(r))&&e,!0)}function lh(t,e,r){return t.reduce((n,o,i)=>{const s=r?!!(Math.floor(i/e)%2):!1,a=i%e,c=s?e-1-a:a;return n[c]||(n[c]=[]),n[c].push(o),n},[])}const B={success:!0},uh={message:"Chronological error; time violation.",code:"ANACHRONISM"},rF={message:"Cannot remove main structure",code:"ERR_CANNOT_REMOVE_MAIN_STRUCTURE"},dh={message:"records must be an object with tournamentId keys",code:"ERR_INVALID_TOURNAMENTS"},Fe={message:"Missing tournamentRecords",code:"ERR_MISSING_TOURNAMENTS"},ee={message:"Missing tournamentRecord",code:"ERR_MISSING_TOURNAMENT"},bl={message:"Invalid tournamentRecord",code:"ERR_INVALID_TOURNAMENT"},ao={message:"Missing tournamentId",code:"ERR_MISSING_TOURNAMENT_ID"},ji={message:"Invalid drawDefinition",code:"ERR_INVALID_DRAWDEF"},pe={message:"Missing drawDefinition",code:"ERR_MISSING_DRAWDEF"},nF={message:"Existing drawDefinition(s)",code:"ERR_EXISTING_DRAWDEFS"},_n={message:"drawDefinition not found",code:"ERR_NOT_FOUND_DRAWDEF"},Ri={message:"Invalid structure",code:"ERR_INVALID_STRUCTURE"},ph={message:"Incomplete source structure",code:"ERR_INCOMPLETE_STRUCTURE"},fh={message:"Invalid drawPosition for seedAssignment",code:"ERR_INVALID_SEEDING_POSITION"},qa={message:"drawPosition already assigned",code:"ERR_EXISTING_POSITION_ASSIGNMENT"},oF={message:"Schedule not cleared",code:"ERR_UNCHANGED_SCHEDULE_NOT_CLEARED"},iF={message:"drawPosition not cleared",code:"ERR_FAILURE_POSITION_NOT_CLEARED"},vh={message:"Unrecognized drawType",code:"ERR_UNRECOGNIZED_DRAW_TYPE"},Op={message:"Missing drawPositions",code:"ERR_MISSING_DRAW_POSITIONS"},bp={message:"drawPosition is active",code:"ERR_ACTIVE_DRAW_POSITION"},js={message:"Invlid drawPosition",code:"ERR_INVALID_DRAW_POSITION"},Ya={message:"Missing drawPosition",code:"ERR_MISSING_DRAW_POSITION"},mh={message:"Invalid drawType",code:"ERR_INVALID_DRAW_TYPE"},Tp={message:"Invalid drawSize",code:"ERR_INVALID_DRAW_SIZE"},Tl={message:"Cannot set drawSize to be less than existing entries",code:"ERR_INVALID_DRAW_SIZE_MISMATCH"},El={message:"Missing drawSize",code:"ERR_MISSING_DRAW_SIZE"},wr={message:"Missing drawId",code:"ERR_MISSING_DRAW_ID"},sF={message:"drawId exists",code:"ERR_EXISTING_DRAW_ID"},aF={message:"participantId cannot be assigned to multiple seedNumbers",code:"INVALID_PARTICIPANT_SEEDING"},cF={message:"seedsCount greater than drawSize",code:"ERR_INVALID_SEED_COUNT"},lF={message:"Missing seedCountThresholds",code:"ERR_MISSING_SEED_COUNT_THRESHOLD"},uF={message:"Invalid action",code:"ERR_INVALID_ACTION"},gh={message:"Invalid assignment",code:"ERR_INVALID_ASSIGNMENT"},dF={message:"Missing seedAssignments",code:"ERR_MISSING_SEED_ASSIGNMENTS"},pF={message:"Invalid seedNumber",code:"ERR_INVALID_SEED_NUMBER"},fF={message:"Invalid seedPosition",code:"ERR_INVALID_SEED_POSITION"},hh={message:"Missing targetLink",code:"ERR_MISSING_LINK_TARGET"},vF={message:"Existing round",code:"ERR_EXISTING_ROUND"},ar={message:"Missing structureId",code:"ERR_MISSING_STRUCTURE_ID"},Br={message:"structure not found",code:"ERR_NOT_FOUND_STRUCTURE"},mF={message:"Missing structures",code:"ERR_MISSING_STRUCTURES"},Rs={message:"Missing structure",code:"ERR_MISSING_STRUCTURE"},gF={message:"drawDefinition contains unlinked structures",code:"ERR_MISSING_STRUCTURE_LINKS"},ri={message:"Invalid eventType",code:"ERR_INVALID_EVENT_TYPE"},Le={message:"Missing event / eventId",code:"ERR_MISSING_EVENT_ID"},Ir={message:"Event not found",code:"ERR_NOT_FOUND_EVENT"},hF={message:"Event exists",code:"ERR_EXISTING_EVENT"},_F={message:"Missing entries",code:"ERR_MISSING_ENTRIES"},IF={message:"Invalid entries",code:"ERR_INVALID_ENTRIES"},_h={message:"Missing assignments",code:"ERR_MISSING_ASSIGNMENTS"},Ih={message:"Missing stage",code:"ERR_MISSING_STAGE"},No={message:"Invalid stage",code:"ERR_INVALID_STAGE"},PF={message:"Missing positionAssignments",code:"ERR_MISSING_POSITION_ASSIGNMENTS"},yF={message:"Cannot Assign BYE status if no assignment: { bye: true }",code:"ERR_UNCHANGED_CANNOT_ASSIGN_BYE"},Ph={message:"Unrecognized matchUpStatus",code:"ERR_UNRECOGNIZED_MATCHUP_STATUS"},wl={message:"Unrecognized matchUpFormat",code:"ERR_UNRECOGNIZED_MATCHUP_FORMAT"},Ep={message:"Incompatible matchUpStatus",code:"ERR_INCOMPATIBLE_MATCHUP_STATUS"},za={message:"Invalid matchUpStatus",code:"ERR_INVALID_MATCHUP_STATUS"},ni={message:"Invalid tieFormat",code:"ERR_INVALID_TIE_FORMAT"},yh={message:"Invalid matchUpFormat",code:"ERR_INVALID_MATCHUP_FORMAT"},wp={message:"Missing matchUpFormat",code:"ERR_MISSING_MATCHUP_FORMAT"},SF={message:"Missing collectionDefinition",code:"ERR_MISSING_COLLECTION_DEFINITION"},$l={message:"Missing tieFormat",code:"ERR_MISSING_TIE_FORMAT"},Ut={message:"Missing matchUpId",code:"ERR_MISSING_MATCHUP_ID"},Ka={message:"Missing matchUpIds",code:"ERR_MISSING_MATCHUP_IDS"},kr={message:"matchUp not found",code:"ERR_NOT_FOUND_MATCHUP"},Ao={message:"Missing matchUps",code:"ERR_MISSING_MATCHUPS"},$r={message:"Missing matchUp",code:"ERR_MISSING_MATCHUP"},Gr={message:"Invalid matchUp",code:"ERR_INVALID_MATCHUP"},Sh={message:"Missing policyType",code:"ERR_MISSING_POLICY_TYPE"},Nl={message:"Missing policyDefinitions",code:"ERR_MISSING_POLICY_DEFINITIONS"},OF={message:"Missing avoidance policy",code:"ERR_MISSING_POLICY_AVOIDANCE"},Oh={message:"Missing policy attributes",code:"ERR_MISSING_POLICY_ATTRIBUTES"},bF={message:"Invalid policyDefinitions",code:"ERR_INVALID_POLICY_DEFINITIONS"},bh={message:"existing policyType",code:"ERR_EXISTING_POLICY_TYPE"},TF={message:"Policy not attached",code:"ERR_FAILURE_POLICY_NOT_ATTACHED"},$p={message:"Policy not found",code:"ERR_NOT_FOUND_POLICY"},EF={message:"Missing scoring policy / matchUpFormats",code:"ERR_MISSING_POLICY_SCORING_MATCHUP_FORMATS"},Th={message:"Invalid sideNumber",code:"ERR_INVALID_SIDE_NUMBER"},Np={message:"Missing setObject",code:"ERR_MISSING_SET_ATTRIBUTE"},Fs={message:"Missing courtId",code:"ERR_MISSING_COURT_ID"},Oe={message:"Missing value",code:"ERR_MISSING_VALUE"},Eh={message:"Missing date",code:"ERR_MISSING_DATE"},wF={message:"No valid dates",code:"ERR_NO_VALID_DATES"},Ap={message:"Invalid bookings",code:"ERR_INVALID_BOOKINGS"},Up={message:"Invalid dateAvailability",code:"ERR_INVALID_DATE_AVAILABILITY"},$F={message:"Missing dateAvailability",code:"ERR_MISSING_DATE_AVAILABILITY"},cr={message:"Invalid Date",code:"ERR_INVALID_DATE"},Wr={message:"Invalid time",code:"ERR_INVALID_TIME"},NF={message:"Invalid tournament dates",code:"ERR_INVALID_DATES_TOURNAMENT"},wh={message:"Invalid game scores",code:"ERR_INVALID_SCORES_GAME"},AF={message:"Invalid score",code:"ERR_INVALID_SCORE"},$h={message:"Invalid winningSide",code:"ERR_INVALID_WINNING_SIDE"},UF={message:"No participants generated",code:"ERR_NO_PARTICIPANTS_GENERATED"},Nh={message:"Cannot modify tieFormat",code:"ERR_UNCHANGED_CANNOT_MODIFY_TIEFORMAT"},CF={message:"Cannot modify participantType",code:"ERR_UNCHANGED_CANNOT_MODIFY_PARTICIPANT_TYPE"},Cp={message:"Cannot remove participants",code:"ERR_UNCHANGED_CANNOT_REMOVE_PARTICIPANTS"},Ah={message:"Cannot change winningSide",code:"ERR_UNCHANGED_CANNOT_CHANGE_WINNING_SIDE"},Mp={message:"Invalid participant",code:"ERR_INVALID_PARTICIPANT"},co={message:"Invalid participantId",code:"ERR_INVALID_PARTICIPANT_ID"},Qr={message:"Invalid participantIds",code:"ERR_INVALID_PARTICIPANT_IDS"},MF={message:"Invalid participantRole",code:"ERR_INVALID_PARTICIPANT_ROLE"},In={message:"Invalid participantType",code:"ERR_INVALID_PARTICIPANT_TYPE"},DF={message:"Missing participantRole",code:"ERR_MISSING_PARTICIPANT_ROLE"},Ls={message:"Missing participant",code:"ERR_MISSING_PARTICIPANT"},Qa={message:"Missing participants",code:"ERR_MISSING_PARTICIPANTS"},yt={message:"Missing participantId",code:"ERR_MISSING_PARTICIPANT_ID"},wt={message:"Participant Not Found",code:"ERR_NOT_FOUND_PARTICIPANT"},jF={message:"participantId exists",code:"ERR_EXISTING_PARTICIPANT_ID"},RF={message:"No participant removed",code:"ERR_UNCHANGED_NO_PARTICIPANT_REMOVED"},lo={message:"Missing participantIds",code:"ERR_MISSING_PARTICIPANT_IDS"},FF={message:"Missing participantCount",code:"ERR_MISSING_PARTICIPANT_COUNT"},LF={message:"Participant not checked in",code:"ERR_UNCHANGED_PARTICIPANT_NOT_CHECKED_IN"},Uh={message:"Participant already checked in",code:"ERR_UNCHANGED_PARTICIPANT_CHECKED_IN"},VF={message:"Missing person details",code:"ERR_MISSING_PERSON_DETAILS"},Vs={message:"Existing participant drawPosition assignment",code:"ERR_EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT"},Dp={message:"Existing participant",code:"ERR_EXISTING_PARTICIPANT"},Ch={message:"participantCount exceeds drawSize",code:"ERR_INVALID_PARTICIPANT_COUNT"},jp={message:"Invalid entry status",code:"ERR_INVALID_ENTRY_STATUS"},Mh={message:"Participant Entry Not Found",code:"ERR_NOT_FOUND_PARTICIPANT_ENTRY"},xF={message:"Participant not entered in stage",code:"ERR_UNCHANGED_PARTICIPANT_NOT_ENTERED"},BF={message:"Participant not found in stageSequence",code:"ERR_NOT_FOUND_PARTICIPANT_IN_STAGE"},kF={message:"entryStatus not allowed in stage",code:"ERR_INVALID_ENTRY_STATUS_IN_STAGE"},GF={message:"entryStatus not allowed for event",code:"ERR_INVALID_ENTRY_STATUS_IN_EVENT"},Dh={message:"No stage space available for entryStatus",code:"ERR_UNCHANGED_NO_AVAILABLE_STAGE_SPACE"},WF={message:"Insufficient drawPositions to accommodate qualifiers",code:"ERR_UNCHANGED_NO_DRAW_POSITIONS_FOR_QUALIFIERS"},jh={message:"Insufficient drawPositions to accommodate entries",code:"ERR_INSUFFICIENT_DRAW_POSITIONS"},HF={message:"Missing penaltyType",code:"ERR_MISSING_PENALTY_TYPE"},Rh={message:"Missing penaltyId",code:"ERR_MISSING_PENALTY_ID"},Al={message:"Penalty not found",code:"ERR_NOT_FOUND_PENALTY"},qF={message:"Missing courtsCount/courtNames",code:"ERR_MISSING_COURTS_INFO"},Rp={message:"Court not found",code:"ERR_NOT_FOUND_COURT"},YF={message:"Court exists",code:"ERR_EXISTING_COURT"},zF={message:"Venue exists",code:"ERR_EXISTING_VENUE"},oi={message:"Venue not found",code:"ERR_NOT_FOUND_VENUE"},Uo={message:"Missing venueId",code:"ERR_MISSING_VENUE_ID"},KF={message:"Invalid endTime",code:"ERR_INVALID_END_TIME"},Fh={message:"Existing endTime",code:"ERR_EXISTING_END_TIME"},QF={message:"Invalid stopTime",code:"ERR_INVALID_STOP_TIME"},JF={message:"Invalid startTime",code:"ERR_INVALID_START_TIME"},ZF={message:"Invalid resumeTime",code:"ERR_INVALID_RESUME_TIME"},Lh={message:"Invalid timeItem",code:"ERR_INVALID_TIME_ITEMS"},Vh={message:"Missing timeItem",code:"ERR_MISSING_TIME_ITEM"},xh={message:"Missing timeItems",code:"ERR_MISSING_TIME_ITEMS"},Ul={message:"Missing context",code:"ERR_MISSING_CONTEXT"},XF={message:"Missing schedule",code:"ERR_MISSING_SCHEDULE"},Cl={message:"Invalid scaleItem",code:"ERR_INVALID_SCALE_ITEM"},eL={message:"No scaleItem found",code:"ERR_NOT_FOUND_SCALE_ITEM"},tL={message:"Modifications failed",code:"ERR_FAILURE_MODIFICATIONS"},Ja={message:"No modifications applied",code:"ERR_UNCHANGED_NO_MODIFICATIONS_APPLIED"},rL={message:"Unable to assign court",code:"ERR_UNCHANGED_COURT_NOT_ASSIGNED"},Fp={message:"No Candidates",code:"ERR_UNCHANGED_NO_CANDIDATES"},nL={message:"Invalid configuration",code:"ERR_INVALID_CONFIG"},xn={message:"Invalid object",code:"ERR_INVALID_OBJECT"},Z={message:"Invalid values",code:"ERR_INVALID_VALUES"},oL={message:"Duplicate value",code:"ERR_DUPLICATE_VALUE"},Bh={message:"Team not found",code:"ERR_NOT_FOUND_TEAM"},iL={message:"No valid actions",code:"ERR_NO_VALID_ACTIONS"},Lp={message:"No valid attributes",code:"ERR_NO_VALID_ATTRIBUTES"},kh={message:"Value unchanged",code:"ABORT_UNCHANGED"},Yt={message:"Not found",code:"ERR_NOT_FOUND"},Gh={message:"Not implemented",code:"ERR_NOT_IMPLEMENTED"},sL={message:"Existing flight",code:"ERR_EXISTING_FLIGHT"},Wh={message:"Existing flight profile",code:"ERR_EXISTING_FLIGHT_PROFILE"},aL={message:"Existing outcome",code:"ERR_EXISTING_OUTCOME"},cL={message:"Existing matchUpId",code:"ERR_EXISTING_MATCHUP_ID"},Hh={message:"Existing stage",code:"ERR_EXISTING_STAGE"},lL={message:"Existing structure",code:"ERR_EXISTING_STRUCTURE"},qh={message:"Method not found",code:"ERR_NOT_FOUND_METHOD"},uL={message:"Scheduled matchUps",code:"ERR_SCHEDULED_MATCHUPS"};var dL=Object.defineProperty,Yh=Object.getOwnPropertySymbols,pL=Object.prototype.hasOwnProperty,fL=Object.prototype.propertyIsEnumerable,zh=(t,e,r)=>e in t?dL(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vL=(t,e)=>{for(var r in e||(e={}))pL.call(e,r)&&zh(t,r,e[r]);if(Yh)for(var r of Yh(e))fL.call(e,r)&&zh(t,r,e[r]);return t};const ft={disableNotifications:!1,tournamentId:void 0,tournamentRecords:{},subscriptions:{},modified:!1,notices:[]};var mL={addNotice:wL,callListener:CL,cycleMutationStatus:EL,deleteNotice:AL,deleteNotices:NL,disableNotifications:gL,enableNotifications:hL,getNotices:$L,getTopics:UL,getTournamentId:_L,getTournamentRecord:IL,getTournamentRecords:PL,removeTournamentRecord:bL,setSubscriptions:TL,setTournamentId:SL,setTournamentRecord:yL,setTournamentRecords:OL};function gL(){ft.disableNotifications=!0}function hL(){ft.disableNotifications=!1}function _L(){return ft.tournamentId}function IL(t){return ft.tournamentRecords[t]}function PL(){return ft.tournamentRecords}function yL(t){const e=t==null?void 0:t.tournamentId;return e?(ft.tournamentRecords[e]=t,{success:!0}):{error:bl}}function SL(t){return ft.tournamentRecords[t]?(ft.tournamentId=t,{success:!0}):{error:ee}}function OL(t){ft.tournamentRecords=t;const e=Object.keys(t);e.length===1?ft.tournamentId=e[0]:e.length||(ft.tournamentId=void 0)}function bL(t){if(typeof t!="string")return{error:Z};if(!ft.tournamentRecords[t])return{error:Yt};delete ft.tournamentRecords[t];const e=Object.keys(ft.tournamentRecords);return e.length===1?ft.tournamentId=e[0]:e.length||(ft.tournamentId=void 0),{success:!0}}function TL({subscriptions:t={}}={}){return typeof t!="object"?{error:Z}:(Object.keys(t).forEach(e=>{ft.subscriptions[e]=t[e]}),vL({},B))}function EL(){const t=ft.modified;return ft.modified=!1,t}function wL({topic:t,payload:e,key:r}){ft.modified=!0,!(typeof t!="string"||typeof e!="object")&&(ft.disableNotifications||!ft.subscriptions[t]||(r&&(ft.notices=ft.notices.filter(n=>!(n.topic===t&&n.key===r))),ft.notices.push({topic:t,payload:e,key:r})))}function $L({topic:t}){const e=ft.notices.filter(r=>r.topic===t).map(r=>r.payload);return e.length&&e}function NL(){ft.notices=[]}function AL({topic:t,key:e}){ft.notices=ft.notices.filter(r=>(!t||r.topic===t)&&r.key!==e)}function UL(){return{topics:Object.keys(ft.subscriptions)}}function CL({topic:t,notices:e}){const r=ft.subscriptions[t];r&&typeof r=="function"&&r(e)}var ML=Object.defineProperty,Kh=Object.getOwnPropertySymbols,DL=Object.prototype.hasOwnProperty,jL=Object.prototype.propertyIsEnumerable,Qh=(t,e,r)=>e in t?ML(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,RL=(t,e)=>{for(var r in e||(e={}))DL.call(e,r)&&Qh(t,r,e[r]);if(Kh)for(var r of Kh(e))jL.call(e,r)&&Qh(t,r,e[r]);return t};const Hr={tournamentFactoryVersion:"0.0.0",timers:{default:{elapsedTime:0}},iterators:{makeDeepCopy:0},deepCopyAttributes:{stringify:[],ignore:[],toJSON:[]},deepCopy:!0};let Pr=mL;function Ft(t){return!t||typeof t!="object"?Hr.devContext||!1:typeof Hr.devContext!="object"?!1:Object.keys(t).every(e=>{var r;return((r=Hr.devContext)==null?void 0:r[e])===t[e]})&&Hr.devContext}function xs(t){Hr.devContext=t}function FL(t){Hr.iterators.makeDeepCopy=t}function LL(){return Hr.iterators.makeDeepCopy}function VL(){Pr.disableNotifications()}function Vp(){Pr.enableNotifications()}function Fi(t,e){typeof t=="boolean"&&(Hr.deepCopy=t),typeof e=="object"&&(Array.isArray(e.ignore)&&(Hr.deepCopyAttributes.ignore=e.ignore),Array.isArray(e.toJSON)&&(Hr.deepCopyAttributes.toJSON=e.toJSON),Array.isArray(e.stringify)&&(Hr.deepCopyAttributes.stringify=e.stringify),e.threshold&&(Hr.deepCopyAttributes.threshold=e.threshold))}function Jh(){return RL({enabled:Hr.deepCopy},Hr.deepCopyAttributes)}function Za(){return Pr.cycleMutationStatus()}function xe(t){return Pr.addNotice(t)}function xL(t){return Pr.getNotices(t)}function Zh({key:t,topic:e}){return Pr.deleteNotice({key:t,topic:e})}function ii(){return Pr.deleteNotices()}function Pn(){return Pr.getTopics()}async function Xh(t){return Pr.callListener(t)}function yn(){return Pr.getTournamentId()}function Xa(t){return Pr.getTournamentRecord(t)}function Ml(){return Pr.getTournamentRecords()}function e_(t){return Pr.setTournamentRecord(t)}function ec(t){return Pr.setTournamentRecords(t)}function tc(t){return Pr.setTournamentId(t)}function xp(t){return Pr.removeTournamentRecord(t)}function Li(t){return typeof t=="object"}const BL=t=>e=>Object.keys(t).every(r=>e[r]===t[r]),kL=t=>e=>!t||typeof e!="object"?void 0:Array.isArray(t)&&t.map(r=>({[r]:e[r]}))||typeof t=="object"&&Object.keys(t).map(r=>({[r]:e[r]}))||typeof t=="string"&&GL(e,t);function GL(t,e){const r=e.split(".");for(const n of r)if(t=t==null?void 0:t[n],!t)return;return t}function _e(t,e,r,n){if(typeof t!="object"||t===null)return t;const o=Jh();o!=null&&o.enabled||(n=!0);const i=["",void 0,null];e&&i.push(!1);const s=Object.keys(t).filter(a=>!i.includes(t[a])&&(!r||(Array.isArray(t[a])?t[a].length:!0)));return Object.assign({},...s.map(a=>Array.isArray(t[a])?{[a]:n?t[a]:t[a].map(c=>_e(c))}:{[a]:n?t[a]:_e(t[a])}))}function Bp(t){return Array.isArray(t)?t.length+t.map(Bp).reduce((e,r)=>e+r,0):typeof t=="object"&&t!==null?Object.keys(t).length+Object.keys(t).map(e=>Bp(t[e])).reduce((e,r)=>e+r,0):0}function WL(t){if(t===null||typeof t!="object")return;const e=JSON.stringify(t),r=Bp(t),n=e.split("").reduce((o,i)=>o+i.charCodeAt(0),0);return[e.length,r,n].map(o=>o.toString(36)).join("")}function Dl(t){if(t===null)return{};const{source:e,template:r}=t||{};if(!r)return e;const n={};return o(e,r,n),n;function o(i,s,a){if(!i||!s)return;const c=Object.keys(i),l=Object.keys(s),u=Object.assign({},...l.filter(v=>v.indexOf("||")).map(v=>v.split("||").map(f=>({[f]:v}))).flat()),d=l.concat(...Object.keys(u)),p=d.includes("*");for(let v=0;v<c.length;v++)if(d.indexOf(c[v])>=0||p){const f=u[c[v]]||c[v],m=s[f]||p,g=i[c[v]];if(typeof m=="object"&&typeof g!="function"&&!Array.isArray(m))if(Array.isArray(g)){const h=g.map(_=>{const I={};if(o(_,m,I)!==!1)return I}).filter(Boolean);a[c[v]]=h}else g&&(a[c[v]]={},o(g,m,a[c[v]]));else{const h=i[c[v]];if(Array.isArray(m)&&!m.includes(h))return!1;(s[c[v]]||p&&s[c[v]]!==!1)&&(a[c[v]]=h)}}}}function t_(t=0){const e=new Date;return e.setHours(e.getHours()+t),e.getTime().toString(36).slice(-6).toUpperCase()}const jl=/^[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])$/,r_=/^((0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)([.,][0-9]{3})?$/,Sn=/^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))([ T](0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/,si=/^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))?([ T]?(0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;function Rl(t){let{scheduledDate:e,scheduledTime:r}=t;if(!e&&r&&(e=Ce(r)),!e)return;const n=rt(r);let o=Ce(e);return o&&n&&(o+=`T${n}`),o}function HL(t){return typeof t!="object"||Array.isArray(t)?!1:Object.prototype.toString.call(t)==="[object Date]"}function Bs(t){const e=typeof t=="string"&&(t==null?void 0:t.split(" "));return t&&(e==null?void 0:e.length)>1&&!["AM","PM"].includes(e[1].toUpperCase())?!1:!!(!t||si.test(Vi(t,!0,!0)))}function Nr(t){return ai(t)||jl.test(t)}function qL(t){const e=new Date(t),r=e.getSeconds()+60*e.getMinutes()+60*60*e.getHours();return YL(r,{displaySeconds:!1})}function YL(t,e){const r=parseInt(t,10),n=Math.floor(r/3600),o=Math.floor((r-n*3600)/60),i=r-n*3600-o*60;return(!e||e&&e.displaySeconds?n+":"+o+":"+i:n+":"+o).split(":").map(Bn).join(":")}const kp=t=>{const e=rc(t)||ai(t)?new Date(t):new Date,r=e.getUTCMonth()+1,n=r<10?`0${r}`:`${r}`;return`${e.getUTCFullYear()}-${Bn(n)}-${Bn(e.getUTCDate())}`};function zL(t){const e=rc(t)||ai(t)?new Date(t):new Date;return Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())}function On(t,e="-",r="YMD"){if(!t)return"";typeof t=="string"&&t.indexOf("T")<0&&(t=t+"T00:00");const n=new Date(t);let o=""+(n.getMonth()+1),i=""+n.getDate();const s=n.getFullYear();return o.length<2&&(o="0"+o),i.length<2&&(i="0"+i),r==="DMY"?[i,o,s].join(e):r==="MDY"?[o,i,s].join(e):r==="YDM"?[s,i,o].join(e):r==="DYM"?[i,s,o].join(e):r==="MYD"?[o,s,i].join(e):[s,o,i].join(e)}function Fl(t){const e=t?new Date(t):new Date,r=e.getTimezoneOffset();return new Date(e.getTime()-r*60*1e3)}function KL(t){return Fl(t).getTime()}function rc(t){if(typeof t=="boolean")return!1;const e=t instanceof Date&&t||!isNaN(t)&&new Date(t)||!1;return e&&!isNaN(e.valueOf())}function Gp(t,e){if(!Nr(t)||!Nr(e))return[];const r=Ce(t)+"T00:00",n=Ce(e)+"T00:00",o=new Date(r),i=new Date(n),s=!(rc(i)&&rc(o)&&l(o,i)),a=[];let c=0;if(!s){const u=o;for(;u<=i&&c<300;)c+=1,a.push(new Date(u)),u.setDate(u.getDate()+1)}return a.map(u=>On(u));function l(u,d){return u<=d}}const QL=/^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;function ai(t){return typeof t!="string"?!1:QL.test(t)}function n_(t){if(typeof t!="string")return!1;const r=t.split("Z")[0].split(":"),n=r.every(o=>!isNaN(o));return!(r.length<2||!n||parseInt(r[0])>23||parseInt(r[1])>60)}function Re(t){const e=rt(t);if(!e)return 0;const[r,n]=e.split(":").map(o=>parseInt(o));return r*60+n}function JL(t){let e=Math.floor(t/60);const r=t-e*60;return e>23&&(e=e%24),[Bn(e),Bn(r)].join(":")}function Ll(t){return n_(t)?t.split(":").slice(0,2).map(Bn).join(":"):void 0}function rt(t){return ai(t)&&t.indexOf("T")>0?Ll(t.split("T").reverse()[0]):Ll(t)}function Ce(t){return ai(t)||Sn.test(t)?t.split("T")[0]:void 0}function ZL(t,e){const r=new Date(t);return r.setDate(r.getDate()+e),Ce(r.toISOString())}function Vl(t){t=typeof t!="string"?"00:00":t;const e={},r={};return{0:e.time,1:e.ampm}=t.split(" ")||[],{0:r.hours,1:r.minutes}=e.time.split(":")||[],r.ampm=e.ampm,isNaN(r.hours)||isNaN(r.minutes)||r.ampm&&!["AM","PM"].includes(r.ampm.toUpperCase())?{}:r}function XL(t){const e=Vl(t);return e.ampm&&e.hours&&(e.ampm.toLowerCase()==="pm"&&parseInt(e.hours)<12&&(e.hours=(e.hours&&parseInt(e.hours)||0)+12),e.ampm.toLowerCase()==="am"&&e.hours==="12"&&(e.hours="00")),`${e.hours||"12"}:${e.minutes||"00"}`.split(":").map(Bn).join(":")}function eV(t){var e;const r=Vl(t);if(!(typeof r=="object"&&!Object.keys(r).length))return r.ampm?t:(r.hours>12?(r.hours-=12,r.ampm="PM"):r.hours==="12"?r.ampm="PM":(r.hours==="00"&&(r.hours="12"),r.ampm="AM"),((e=r.hours)==null?void 0:e[0])==="0"&&(r.hours=r.hours.slice(1)),`${r.hours||"12"}:${r.minutes||"00"} ${r.ampm}`)}function Vi(t,e,r){const n=Ce(t),o=rt(t),i=n?o:t;return t?e&&(n&&r&&t||XL(i))||eV(i):void 0}function o_(t,e){const r=Vl(t),n=Vl(e);if(parseInt(r.hours)<parseInt(n.hours))return-1;if(parseInt(r.hours)>parseInt(n.hours))return 1;if(r.hours===n.hours){if(parseInt(r.minutes)<parseInt(n.minutes))return-1;if(parseInt(r.minutes)>parseInt(n.minutes))return 1}return 0}function tV(t,e,r,n=!1){let o=new Date(e,0,1+(t-1)*7);const i=n?0:1;return o.setDate(o.getDate()+(i-o.getDay())),On(o,r)}function rV(t,e,r){const n=new Date(t,0);return On(new Date(n.setDate(e)),r)}function ht(t,e=void 0){const[r,n]=(t||"00:00").split(":").map(Bn),o=Fl(e).setHours(r,n,0,0);return Fl(o)}function nc(t,e,r=!0){const n=new Date(t),i=(new Date(e).getTime()-n.getTime())/1e3/60;return r?Math.abs(Math.round(i)):Math.round(i)}function lr(t,e){const r=rt(t);if(!r)return"00:00";const n=isNaN(e)?0:e;return rt(Wp(ht(r),n).toISOString())}function Wp(t,e){const r=new Date(t);return new Date(r.getTime()+e*6e4)}function Bn(t){return t.toString()[1]?t:"0"+t}function kn(t,e){const r=new Date(t),n=new Date(e);return r.getFullYear()===n.getFullYear()&&r.getMonth()===n.getMonth()&&r.getDate()===n.getDate()}const nV={addMinutesToTimeString:lr,convertTime:Vi,getIsoDateString:Rl,getUTCdateString:kp,DateHHMM:qL,extractDate:Ce,extractTime:rt,formatDate:On,getDateByWeek:tV,isISODateString:ai,isDate:rc,isTimeString:n_,offsetDate:Fl,offsetTime:KL,sameDay:kn,timeStringMinutes:Re,timeToDate:ht,timeUTC:zL,validTimeValue:Bs,validDateString:jl,timeValidation:si,dateValidation:Sn};function ue(t,e,r,n,o=0){const i=Jh(),{stringify:s,toJSON:a,ignore:c,modulate:l}=i||{};if(!(i!=null&&i.enabled)&&!r||typeof t!="object"||typeof t=="function"||t===null||typeof(i==null?void 0:i.threshold)=="number"&&o>=i.threshold)return t;const u=Ft({makeDeepCopy:!0});u&&(FL(o),typeof u=="object"&&(o>(u.iterationThreshold||15)||u.firstIteration&&o===0)&&u.log&&(!u.notInternalUse||u.notInternalUse&&!r)&&console.log({devContext:u,iteration:o,internalUse:r},t));const d=Array.isArray(t)?[]:{},p=Object.keys(t).filter(f=>!r||!c||Array.isArray(c)&&!c.includes(f)||typeof c=="function"&&!c(f)),v=(f,m)=>{d[f]=typeof(m==null?void 0:m.toString)=="function"?m.toString():JSON.stringify(m)};for(const f of p){const m=t[f],g=typeof l=="function"?l(m):void 0;if(g!==void 0)d[f]=g;else if(e&&f==="extensions"&&Array.isArray(m)){const h=i_(m);Object.assign(d,...h)}else n&&f==="extensions"?d[f]=[]:Array.isArray(s)&&s.includes(f)?v(f,m):Array.isArray(a)&&a.includes(f)&&typeof(m==null?void 0:m.toJSON)=="function"?d[f]=m.toJSON():m===null?d[f]=void 0:HL(m)?d[f]=new Date(m).toISOString():d[f]=ue(m,e,r,n,o+1)}return d}function i_(t){return t==null?void 0:t.map(e=>{const{name:r,value:n}=e;return r&&n&&{[`_${r}`]:n}}).filter(Boolean)}function Wt(t,e){return t-e}function oV(t,e){if(e&&typeof e!="object")return Z;let{columnTransform:r={}}=e||{};const{includeTransformAccessors:n,includeHeaderRow:o=!0,returnTransformedJSON:i,removeEmptyColumns:s,onlyHeaderRow:a,columnAccessors:c=[],functionMap:l={},columnMap:u={},valuesMap:d={},context:p={},delimiter:v='"',columnJoiner:f=",",rowJoiner:m=`\r
|
|
6
|
+
`,keyJoiner:g="."}=e||{};if(!Array.isArray(t)||!Array.isArray(c)||typeof p!="object"||typeof u!="object"||typeof r!="object"||typeof l!="object"||typeof d!="object"||typeof f!="string"||typeof m!="string"||typeof g!="string"||typeof v!="string")return Z;r=Object.assign({},...Object.keys(r).reverse().map(U=>({[U]:Array.isArray(r[U])?r[U]:[typeof r[U]=="string"&&r[U]].filter(Boolean)})));const h=t.filter(Boolean).map(U=>Hp(U,g)),_=Object.values(r).flat();n&&c.push(..._);const I=h.reduce((U,A)=>Object.keys(A).every(M=>!U.includes(M)&&U.push(M)||!0)&&U,[]).filter(U=>!(c!=null&&c.length)||c.includes(U)),P=Object.assign({},...Object.keys(r).reverse().map(U=>r[U].map(A=>({[A]:U})).flat()).flat()),O=(U,A)=>e!=null&&e.sortOrder?e.sortOrder.includes(U)&&e.sortOrder.includes(A)&&e.sortOrder.indexOf(U)-e.sortOrder.indexOf(A)||!e.sortOrder.includes(A)&&-1:0,y=I.reduce((U,A)=>{const M=P[A];return M?U.includes(M)||U.push(M):U.push(A),U},[]).sort(O);Object.keys(u).forEach(U=>!y.includes(U)&&y.unshift(U)),Object.keys(r).forEach(U=>!y.includes(U)&&y.unshift(U)),typeof p=="object"&&Object.keys(p).forEach(U=>!y.includes(U)&&y.unshift(U));let S=y.map(U=>u[U]||U);if(a)return[S];const T=U=>`${v}${U}${v}`,E=[],b=U=>Object.values(y.reduce((A,M,C)=>{var D;const F=r[M],R=(F!=null&&F.length?U[F.find(z=>U[z])]:U[M])||(p==null?void 0:p[M])||"",G=((D=d[M])==null?void 0:D[R])||R,x=typeof l[M]=="function"?l[M](G):G;return A[M]=T(x),x&&(E[C]=(E[C]||0)+1),A},{}));let N=h.map(b);const w=s&&[...E].map((U,A)=>!U&&A).filter(Ot).reverse();if(w){const U=A=>A.filter((M,C)=>!w.includes(C));N=N.map(U),S=U(S)}const $=N.map(U=>U.join(f));return i?$.map(U=>{const A=U.split(f);return Object.assign({},...A.map((M,C)=>({[S[C]]:M})))}):o?[S.map(T).join(f),...$].join(m):$.join(m)}function Hp(t,e,r=[]){return typeof t=="object"&&Object.keys(t).reduce((n,o)=>typeof t[o]!="object"?(n[r.concat(o).join(e)]=t[o],n):Object.assign(n,Hp(t[o],e,r.concat(o))),{})}function iV(t=1){return le(0,t).map(We)}function We(){const t=[];for(let i=0;i<256;i++)t[i]=(i<16?"0":"")+i.toString(16);const e=Math.random()*4294967295|0,r=Math.random()*4294967295|0,n=Math.random()*4294967295|0,o=Math.random()*4294967295|0;return t[e&255]+t[e>>8&255]+t[e>>16&255]+t[e>>24&255]+"-"+t[r&255]+t[r>>8&255]+"-"+t[r>>16&15|64]+t[r>>24&255]+"-"+t[n&63|128]+t[n>>8&255]+"-"+t[n>>16&255]+t[n>>24&255]+t[o&255]+t[o>>8&255]+t[o>>16&255]+t[o>>24&255]}var sV=Object.defineProperty,s_=Object.getOwnPropertySymbols,aV=Object.prototype.hasOwnProperty,cV=Object.prototype.propertyIsEnumerable,a_=(t,e,r)=>e in t?sV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lV=(t,e)=>{for(var r in e||(e={}))aV.call(e,r)&&a_(t,r,e[r]);if(s_)for(var r of s_(e))cV.call(e,r)&&a_(t,r,e[r]);return t};function W({context:t,result:e,stack:r,info:n}){return e&&!Array.isArray(e==null?void 0:e.stack)&&(e.stack=[]),e&&Array.isArray(e==null?void 0:e.stack)&&typeof r=="string"&&e.stack.push(r),n&&(e!=null&&e.error)&&(e.error.info=n),e&&typeof t=="object"&&Object.keys(t).length&&Object.assign(e,_e(t)),e&&!(e!=null&&e.error)&&!(e!=null&&e.success)&&Object.assign(e,lV({},B)),e??{success:!0}}function zt(t){return`${t} must be an array`}const ci="SINGLES",pt="SINGLES",Jr="DOUBLES",it="DOUBLES",Zr="TEAM",He="TEAM";var uV=Object.defineProperty,c_=Object.getOwnPropertySymbols,dV=Object.prototype.hasOwnProperty,pV=Object.prototype.propertyIsEnumerable,l_=(t,e,r)=>e in t?uV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fV=(t,e)=>{for(var r in e||(e={}))dV.call(e,r)&&l_(t,r,e[r]);if(c_)for(var r of c_(e))pV.call(e,r)&&l_(t,r,e[r]);return t};function ur({checkCollectionIds:t=!0,tieFormat:e}={}){var r,n,o,i;const s="validateTieFormat",a=[];if(typeof e!="object")return a.push("tieFormat must be an object"),W({result:{error:ni,stack:s,context:{tieFormat:e,errors:a}}});if(typeof e.winCriteria!="object")return a.push("tieFormat.winCriteria must be an object"),W({result:{error:ni,stack:s,context:{tieFormat:e,errors:a}}});if(!Array.isArray(e.collectionDefinitions))return a.push(zt("tieFormat.collectionDefinitions")),W({result:{error:ni,stack:s,context:{tieFormat:e,errors:a}}});let c;const l=e.collectionDefinitions.every(m=>{const{setValue:g,scoreValue:h,collectionValue:_}=m;(g||h)&&!_&&(c=!0);const{valid:I,errors:P}=u_({collectionDefinition:m,checkCollectionIds:t});return I?!0:(a.push(...P),!1)}),u=typeof((r=e.winCriteria)==null?void 0:r.valueGoal)=="number"&&((n=e.winCriteria)==null?void 0:n.valueGoal)>0&&!c||((o=e.winCriteria)==null?void 0:o.aggregateValue);if(!(u||(i=e.winCriteria)!=null&&i.aggregateValue))return c?a.push("aggregateValue is required"):a.push("Either non-zero valueGoal, or { aggregateValue: true } must be specified in winCriteria"),W({result:{context:{tieFormat:e,errors:a,aggregateValueImperative:c},error:ni,stack:s}});const d=e.collectionDefinitions.map(({collectionId:m})=>m),p=!t||d.length===Ve(d).length,v=l&&u&&p,f={valid:v,errors:a};return v?f:W({result:{context:{tieFormat:e,errors:a},error:ni,stack:s}})}function u_({checkValueDefinition:t=!0,collectionDefinition:e,checkCollectionIds:r}){const n=[];if(typeof e!="object")return n.push(`collectionDefinition must be an object: ${e}`),{errors:n};const{collectionValueProfile:o,collectionGroupNumber:i,collectionValue:s,collectionId:a,matchUpCount:c,matchUpFormat:l,matchUpValue:u,matchUpType:d,scoreValue:p,setValue:v}=e;if(r&&typeof a!="string")return n.push(`collectionId is not type string: ${a}`),{errors:n};if(typeof c!="number")return n.push(`matchUpCount is not type number: ${c}`),{errors:n};if(![pt,it].includes(d))return n.push(`matchUpType must be SINGLES or DOUBLES: ${d}`),{errors:n};if(t&&!u&&!s&&!o&&!p&&!v)return n.push("Missing value definition for matchUps: matchUpValue, collectionValue, or collectionValueProfile"),{errors:n};if(u&&typeof u!="number")return n.push(`matchUpValue is not type number: ${u}`),{errors:n};if(s&&typeof s!="number")return n.push(`collectionValue is not type number: ${s}`),{errors:n};if(o){const f=d_({collectionValueProfile:o,matchUpCount:c});if(f.errors)return n.push(...f.errors),{errors:n}}return i&&typeof i!="number"?(n.push(`collectionValue is not type number: ${s}`),{errors:n}):l&&!KR.isValid(l)?(n.push(`Invalid matchUpFormat: ${l}`),{errors:n}):{valid:!0}}function vV(t){const e=ur({tieFormat:t,checkCollectionIds:!1});if(e.error)return e;for(const r of t.collectionDefinitions)r.collectionId||(r.collectionId=We());return{tieFormat:t}}function d_({collectionValueProfile:t,matchUpCount:e}){const r=[];if(!Array.isArray(t))return r.push(`collectionValueProfile is not an array: ${t}`),{errors:r};if(t.length!==e)return r.push("collectionValueProfile does not align with matchUpsCount"),{errors:r};for(const o of t){if(typeof o!="object")return r.push(`valueProfile is not type object: ${o}`),{errors:r};const{value:i,collectionPosition:s}=o;if(typeof i!="number"||typeof s!="number"||s>e||s<1)return r.push("Invalid value profile: value and collectionPosition must be numeric. collectionPosition cannot be greater than matchUpCount"),{errors:r}}const n=t.map(o=>o.collectionPosition);return n.length!==Ve(n).length?(r.push("collectionPositions are not unique"),{errors:r}):fV({},B)}const yr="ABANDONED",ks="AWAITING_RESULT",qe="BYE",uo="CANCELLED",St="COMPLETED",Gs="DEAD_RUBBER",Be="DEFAULTED",bt="DOUBLE_DEFAULT",_t="DOUBLE_WALKOVER",Xr="IN_PROGRESS",Gn="INCOMPLETE",qp="NOT_PLAYED",er="RETIRED",li="SUSPENDED",vt="TO_BE_PLAYED",Ge="WALKOVER",mV=[ks,St,Be,_t,bt,Xr,Gn,er,li,Ge],gV=[yr,ks,qe,uo,St,Gs,Be,_t,bt,Xr,Gn,qp,er,li,vt,Ge],hV=[qe,_t,bt,St,Be,er,Ge],_V=[yr,ks,uo,Gs,Xr,Gn,qp,li,vt,void 0],Lt=[uo,yr,St,Gs,Be,_t,bt,er,Ge],p_=[yr,St,Be,_t,bt,Xr,er,Ge],IV=[Xr,Gn,li,vt],PV={ABANDONED:yr,AWAITING_RESULT:ks,BYE:qe,CANCELLED:uo,COMPLETED:St,DEAD_RUBBER:Gs,DEFAULTED:Be,DOUBLE_WALKOVER:_t,DOUBLE_DEFAULT:bt,IN_PROGRESS:Xr,INCOMPLETE:Gn,NOT_PLAYED:qp,RETIRED:er,SUSPENDED:li,TO_BE_PLAYED:vt,WALKOVER:Ge};function Ws({matchUp:t}){return Lt.includes(t==null?void 0:t.matchUpStatus)||(t==null?void 0:t.winningSide)}const xl="SET3-S:6/TB7",yV={FORMAT_STANDARD:xl,FORMAT_STANDARD_NOAD:"SET3-S:6NOAD",FORMAT_ATP_DOUBLES:"SET3-S:6/TB7-F:TB10",FORMAT_SHORT_SETS:"SET3-S:4/TB7",FORMAT_FAST4:"SET3-S:4/TB5@3",FORMAT_PRO_SET:"SET1-S:8/TB7",FORMAT_COLLEGE_PRO_SET:"SET1-S:8/TB7@7",TIMED20:"SET1-S:T20"};function f_({winningSide:t,matchUpFormat:e=xl,matchUpStatus:r,tallyPolicy:n,score:o}){const i=[0,0],{sets:s}=o||{},a=t-1,c=_r(e),l=Yp((c==null?void 0:c.bestOf)||1);if(r===Be&&(n!=null&&n.setsCreditForDefaults)||r===Ge&&(n!=null&&n.setsCreditForWalkovers))i[a]=l;else for(const u of s||[]){const{winningSide:d}=u;d&&(i[d-1]+=1)}return r===er&&(+i[1-a]===l&&(i[1-a]-=1),n!=null&&n.setsCreditForRetirements&&(i[a]=l)),i}function SV({winningSide:t,matchUpFormat:e=xl,matchUpStatus:r,tallyPolicy:n,score:o}){var i,s;const{sets:a}=o||{};if(!a)return[0,0];const c=t-1,l=_r(e),u=(l==null?void 0:l.bestOf)||1,d=Yp(u),p=((i=l==null?void 0:l.setFormat)==null?void 0:i.tiebreakAt)||0,v=[[],[]];if(r===Be&&(n!=null&&n.gamesCreditForDefaults)||r===Ge&&(n!=null&&n.gamesCreditForWalkovers)){const f=((s=l==null?void 0:l.setFormat)==null?void 0:s.setTo)||0,m=d*f;v[c].push(m)}else a.forEach((f,m)=>{var g;const _=(f.setNumber||m+1)>d&&(l!=null&&l.finalSetFormat)?"finalSetFormat":"setFormat",I=(g=l==null?void 0:l[_])==null?void 0:g.based;if(m_(I)){const{side1Score:P,side2Score:O}=f;v[0].push(parseInt(P||0)),v[1].push(parseInt(O||0))}});if(r===er){const f=a.length>d&&(l!=null&&l.finalSetFormat)?"finalSetFormat":"setFormat",m=l==null?void 0:l[f];if(m_(m.based)){const g=(m==null?void 0:m.setTo)||0,h=P=>{if(!(!l||P===""))return+P===p-1||+P===p?parseInt(p||0)+1:+P<p?g:p},_=f_({winningSide:t,matchUpStatus:r,matchUpFormat:e,sets:a});if(v.map(P=>P[c]<=P[1-c]).reduce((P,O)=>P+O,0)>_[1-c]){const P=v[c].length,O=h(v[1-c][P-1]);O&&(v[c][P-1]=O)}d>v[c].length&&(n!=null&&n.gamesCreditForRetirements)&&v[c].push(g)}}return[v[0].reduce((f,m)=>f+m,0),v[1].reduce((f,m)=>f+m,0)]}function OV({matchUpFormat:t,score:e}){var r;const n=_r(t),o=(n==null?void 0:n.bestOf)||1,i=Yp(o),s=[0,0];return(r=e==null?void 0:e.sets)==null||r.forEach((a,c)=>{var l;const d=(a.setNumber||c+1)>i&&(n!=null&&n.finalSetFormat)?"finalSetFormat":"setFormat",p=(l=n==null?void 0:n[d])==null?void 0:l.based;if(v_(p)){const{side1Score:v,side2Score:f}=a;v&&(s[0]+=parseInt(v||0)),f&&(s[1]+=parseInt(f||0))}else a.side1TiebreakScore&&(s[0]+=parseInt(a.side1TiebreakScore||0)),a.side2TiebreakScore&&(s[1]+=parseInt(a.side2TiebreakScore||0))}),s}function Yp(t){return t&&Math.ceil(t/2)||1}function v_(t){return t==="P"}function m_(t){return!v_(t)}function bV({participantResults:t,matchUpFormat:e,tallyPolicy:r,perPlayer:n,totalSets:o}){var i;const s=e&&_r(e)||{},a=s.bestOf,c=a&&Math.ceil(a/2)||1,l=(i=s.setFormat)==null?void 0:i.setTo;Object.keys(t).forEach(u=>{const d=t[u].setsWon,p=t[u].setsLost,v=r!=null&&r.groupTotalSetsPlayed?o:n*(c||0)||d+p;let f=Math.round(d/v*1e3)/1e3;(f===1/0||isNaN(f))&&(f=v);const m=t[u].tieMatchUpsWon,g=t[u].tieMatchUpsLost,h=m+g;let _=Math.round(m/h*1e3)/1e3;(_===1/0||isNaN(_))&&(_=m);const I=t[u].matchUpsWon,P=t[u].matchUpsLost,O=I+P;let y=Math.round(I/O*1e3)/1e3;(y===1/0||isNaN(y))&&(y=I);const S=t[u].gamesWon||0,T=t[u].gamesLost||0,E=(n||0)*(c||0)*(l||0),b=Math.max(E,S+T);let N=Math.round(S/b*1e3)/1e3;(N===1/0||isNaN(N))&&(N=0);let w=Math.round(t[u].pointsWon/t[u].pointsLost*1e3)/1e3;(w===1/0||isNaN(w))&&(w=0),t[u].setsWon=d,t[u].setsLost=p,t[u].setsPct=f,t[u].tieMatchUpsWon=m,t[u].tieMatchUpsPct=_,t[u].matchUpsPct=y,t[u].gamesWon=S,t[u].gamesLost=T,t[u].gamesPct=N,t[u].pointsPct=w,t[u].result=`${t[u].matchUpsWon}/${t[u].matchUpsLost}`})}function g_({participantIds:t,matchUpFormat:e,tallyPolicy:r,perPlayer:n,matchUps:o}){var i,s,a,c;const l={},u=(r==null?void 0:r.excludeMatchUpStatuses)||[],d=o.filter(f=>(f.tieMatchUps||!u.includes(f.matchUpStatus))&&(!(t!=null&&t.length)||jt(t,[Hs(f,0),Hs(f,1)]).length===2)),v=d.flatMap(({score:f,tieMatchUps:m})=>{var g;return m?m.filter(({matchUpStatus:h})=>!u.includes(h)).flatMap(({score:h})=>{var _;return((_=h==null?void 0:h.sets)==null?void 0:_.length)||0}):((g=f==null?void 0:f.sets)==null?void 0:g.length)||0}).reduce((f,m)=>f+m,0);for(const f of d){const{matchUpStatus:m,tieMatchUps:g,tieFormat:h,score:_,winningSide:I,sides:P}=f,O=h&&f._disableAutoCalc&&h.collectionDefinitions.every(({scoreValue:T})=>T),y=I&&TV(f),S=I&&EV(f);if(!y||!S)if(Lt.includes(m)){const T=Hs(f,0),E=Hs(f,1);T&&(Co(l,T),l[T].matchUpsCancelled+=1),E&&(Co(l,E),l[E].matchUpsCancelled+=1)}else if(g!=null&&g.length){n=0;for(const T of g){if(T.winningSide){const E=(i=P.find(({sideNumber:N})=>N===T.winningSide))==null?void 0:i.participantId,b=(s=P.find(({sideNumber:N})=>N===T.winningSide))==null?void 0:s.participantId;E&&b&&(Co(l,E),Co(l,b),l[E].tieMatchUpsWon+=1,l[b].tieMatchUpsLost+=1,T.matchUpType===pt?(l[E].tieSinglesWon+=1,l[b].tieSinglesLost+=1):T.matchUpType===it&&(l[E].tieDoublesWon+=1,l[b].tieDoublesLost+=1))}h_({score:T.score,manualGamesOverride:O,participantResults:l,sides:P})}}else h_({manualGamesOverride:O,participantResults:l,score:_,sides:P});else if(Co(l,y),Co(l,S),g!=null&&g.length){n=0;for(const T of g){const{matchUpType:E}=T,b=E===it,N=E===pt;T.winningSide&&(T.winningSide===I?(y&&(l[y].tieMatchUpsWon+=1,N&&(l[y].tieSinglesWon+=1),b&&(l[y].tieDoublesWon+=1)),S&&(l[S].tieMatchUpsLost+=1,N&&(l[S].tieSinglesLost+=1),b&&(l[S].tieDoublesLost+=1))):T.winningSide!==I&&(S&&(l[S].tieMatchUpsWon+=1,N&&(l[S].tieSinglesWon+=1),b&&(l[S].tieDoublesWon+=1)),y&&(l[y].tieMatchUpsLost+=1,N&&(l[y].tieSinglesLost+=1),b&&(l[y].tieDoublesLost+=1)))),__({matchUpFormat:T.matchUpFormat,matchUpStatus:T.matchUpStatus,score:T.score,winningParticipantId:y,losingParticipantId:S,participantResults:l,isTieMatchUp:!0,manualGamesOverride:O,tallyPolicy:r,winningSide:I})}I_({winningParticipantId:y,losingParticipantId:S,participantResults:l,matchUpStatus:m})}else __({matchUpFormat:f.matchUpFormat||e,winningParticipantId:y,losingParticipantId:S,participantResults:l,manualGamesOverride:O,matchUpStatus:m,tallyPolicy:r,winningSide:I,score:_});if(O){const T=(a=P.find(({sideNumber:w})=>w===1))==null?void 0:a.participantId,E=(c=P.find(({sideNumber:w})=>w===2))==null?void 0:c.participantId;Co(l,T),Co(l,E);const b=_.sets.reduce((w,$)=>w+$.side1Score,0),N=_.sets.reduce((w,$)=>w+$.side2Score,0);l[T].gamesWon+=b,l[E].gamesWon+=N,l[T].gamesLost+=N,l[E].gamesLost+=b}}return bV({participantResults:l,matchUpFormat:e,tallyPolicy:r,perPlayer:n,totalSets:v}),{participantResults:l}}function TV(t){const e=t.winningSide-1;return Hs(t,e)}function EV(t){const e=1-(t.winningSide-1);return Hs(t,e)}function Hs(t,e){if(!(t!=null&&t.sides))return console.log("no sides:",{matchUp:t}),"foo";const r=t.sides[e];return r?r.participantId:(console.log("No Side",{matchUp:t,index:e}),"foo")}function Co(t,e){e&&!t[e]&&(t[e]={allDefaults:0,defaults:0,defeats:[],gamesLost:0,gamesWon:0,matchUpsCancelled:0,matchUpsLost:0,matchUpsWon:0,pointsLost:0,pointsWon:0,retirements:0,setsLost:0,setsWon:0,tieSinglesWon:0,tieSinglesLost:0,tieDoublesWon:0,tieDoublesLost:0,tieMatchUpsLost:0,tieMatchUpsWon:0,victories:[],walkovers:0})}function h_({manualGamesOverride:t,participantResults:e,score:r,sides:n}){const{sets:o}=r||{},i=[[],[]],s=[0,0];for(const c of o||[]){const{winningSide:l,side1Score:u,side2Score:d}=c;l&&(s[l-1]+=1),i[0].push(parseInt(u||0)),i[1].push(parseInt(d||0))}const a=[i[0].reduce((c,l)=>c+l,0),i[1].reduce((c,l)=>c+l,0)];n.forEach((c,l)=>{const{participantId:u}=c;u&&(Co(e,u),e[u].setsWon+=s[l],e[u].setsLost+=s[1-l],t||(e[u].gamesWon+=a[l],e[u].gamesLost+=a[1-l]))})}function __({winningParticipantId:t,losingParticipantId:e,participantResults:r,manualGamesOverride:n,matchUpFormat:o,matchUpStatus:i,isTieMatchUp:s,tallyPolicy:a,winningSide:c,score:l}){const u=c&&c-1,d=1-u;s||I_({winningParticipantId:t,losingParticipantId:e,participantResults:r,matchUpStatus:i});const p=f_({matchUpStatus:i,matchUpFormat:o,tallyPolicy:a,winningSide:c,score:l}),v=SV({matchUpStatus:i,matchUpFormat:o,tallyPolicy:a,winningSide:c,score:l}),f=OV({score:l,matchUpFormat:o,tallyPolicy:a});t&&(r[t].setsWon+=p[u],r[t].setsLost+=p[d],n||(r[t].gamesWon+=v[u],r[t].gamesLost+=v[d]),r[t].pointsWon+=f[u],r[t].pointsLost+=f[d]),e&&(r[e].setsWon+=p[d],r[e].setsLost+=p[u],n||(r[e].gamesWon+=v[d],r[e].gamesLost+=v[u]),r[e].pointsWon+=f[d],r[e].pointsLost+=f[u])}function I_({winningParticipantId:t,losingParticipantId:e,participantResults:r,matchUpStatus:n}){e&&(n===Ge&&(r[e].walkovers+=1),n===Be&&(r[e].defaults+=1),n===er&&(r[e].retirements+=1),[Be,er,Ge].includes(n)&&(r[e].allDefaults+=1),r[e].matchUpsLost+=1),t&&(r[t].matchUpsWon+=1),e&&t&&(r[e].defeats.push(t),r[t].victories.push(e))}function wV({matchUps:t,order:e,report:r}){const n={};t.forEach(({sides:i})=>{i.forEach(s=>{s.participantId&&s.participant&&(n[s.participantId]=s.participant.participantName)})});const o=[];return Array.isArray(r)&&r.forEach((i,s)=>{var a;if((a=i.excludedDirectives)!=null&&a.length){const c=i.excludedDirectives.map(({attribute:d})=>d).join(", "),l=`${c.length} directives were excluded due to participants limit}`;o.push(l);const u=`Excluded: ${c}`;o.push(u)}else{const c=(v,f)=>parseFloat(i.reversed?v:f)-parseFloat(i.reversed?f:v),l=v=>{Object.keys(v.groups).sort(c).forEach(f=>{const m=v.groups[f].map(h=>n[h]).join(", "),g=`${f} ${v.attribute}: ${m}`;o.push(g)})},u=i.reversed?" in reverse order":"",d=Object.values(i.groups).flat(1/0).length,p=`Step ${s+1}: ${d} particiants were grouped${u} by ${i.attribute}`;if(o.push(p),i.idsFilter){const v=`${i.attribute} was calculated considering ONLY TIED PARTICIPANTS`;o.push(v)}l(i)}o.push("----------------------")}),o.push("Final Order:"),e.forEach(i=>{const{participantId:s,resolved:a}=i,c=i.groupOrder||i.provisionalOrder;o.push(`${c}: ${n[s]} => resolved: ${a}`)}),o.join(`\r
|
|
7
|
+
`)}var $V=Object.defineProperty,P_=Object.getOwnPropertySymbols,NV=Object.prototype.hasOwnProperty,AV=Object.prototype.propertyIsEnumerable,y_=(t,e,r)=>e in t?$V(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,UV=(t,e)=>{for(var r in e||(e={}))NV.call(e,r)&&y_(t,r,e[r]);if(P_)for(var r of P_(e))AV.call(e,r)&&y_(t,r,e[r]);return t};const CV=[{attribute:"matchUpsPct",idsFilter:!1},{attribute:"allDefaults",reversed:!0,idsFilter:!1},{attribute:"defaults",reversed:!0,idsFilter:!1},{attribute:"walkovers",reversed:!0,idsFilter:!1},{attribute:"retirements",reversed:!0,idsFilter:!1},{attribute:"setsPct",idsFilter:!1},{attribute:"gamesPct",idsFilter:!1},{attribute:"pointsPct",idsFilter:!1},{attribute:"matchUpsPct",idsFilter:!0},{attribute:"setsPct",idsFilter:!0},{attribute:"gamesPct",idsFilter:!0},{attribute:"pointsPct",idsFilter:!0}],zp={matchUpsPct:20,tieMatchUpsPct:16,setsPct:12,gamesPct:8,pointsPct:4};function S_(t){const{requireCompletion:e=!0,participantResults:r,subOrderMap:n,tallyPolicy:o}=t,i=[];if(e&&!MV(t))return{};const s=["tieMatchUpsWon","tieSinglesWon","tieDoublesWon","matchUpsWon","pointsWon","gamesWon","setsWon","gamesPct","setsPct","pointsPct","matchUpsPct"].includes(o==null?void 0:o.groupOrderKey)?o.groupOrderKey:"matchUpsWon",a=b_({participantResults:r,attribute:s});i.push({attribute:s,groups:a});const c=Object.keys(a).map(f=>parseFloat(f)).sort((f,m)=>m-f).map(f=>a[f]).map(f=>{const m=O_(UV({participantIds:f},t));return i.push(m.report),m.order}).flat(1/0);let l=1,u;c.forEach((f,m)=>{m&&(f.resolved||u&&!f.resolved)&&(l+=1),u=f.resolved,f.resolved?(f.position=m+1,l=f.position):f.position=l});const d=c.map(({position:f})=>f),p=mr(d);return c.forEach(f=>{const{participantId:m,position:g}=f||{},h=r[m];f.GEMscore=v(h);const _=p[g];(f==null?void 0:f.position)!==void 0&&(_>1&&(f.ties=_,n&&(f.subOrder=n[m])),f.rankOrder=g,f.groupOrder=g+(f.subOrder||1)-1)}),{groupOrder:c,report:i.flat(1/0).filter(Boolean)};function v(f){return(Array.isArray(o==null?void 0:o.GEMscore)?Object.keys(zp).filter(h=>o.GEMscore.includes(h)):Object.keys(zp)).map(h=>(f[h]||0)*Math.pow(10,zp[h].toFixed(3))).reduce((h,_)=>h+_,0)}}function MV({participantResults:t,participantsCount:e}){let n=T_({participantResults:t}).filter(o=>e-1===o.results.matchUpsWon+o.results.matchUpsLost+o.results.matchUpsCancelled);return e===n.length}function DV({disableHeadToHead:t,participantIds:e,matchUpFormat:r,tallyPolicy:n,attribute:o,idsFilter:i,matchUps:s,reversed:a}){const{participantResults:c}=g_({participantIds:i&&e,matchUpFormat:r,tallyPolicy:n,matchUps:s}),l=b_({participantResults:c,participantIds:e,attribute:o}),u=[{attribute:o,reversed:a,groups:l,idsFilter:i}];let d;return Object.keys(l).length>1&&e.length&&(d=Object.keys(l).map(p=>parseFloat(p)).sort((p,v)=>a?p-v:v-p).map(p=>l[p]).map(p=>{const v=O_({participantResults:c,disableHeadToHead:t,participantIds:p,matchUpFormat:r,tallyPolicy:n,matchUps:s});return u.push(v.report),v.order}).flat(1/0)),{order:d,report:u}}function O_({participantResults:t,disableHeadToHead:e,participantIds:r,matchUpFormat:n,tallyPolicy:o,matchUps:i}){if((r==null?void 0:r.length)===1)return{order:[{resolved:!0,participantId:r[0]}]};if((r==null?void 0:r.length)===2&&(!(o!=null&&o.headToHead)||!o.headToHead.disabled&&!e)){const d=jV({participantIds:r,participantResults:t});if(d)return{order:[d],headToHeadWinner:d[0].participantId}}const s=(o==null?void 0:o.tallyDirectives)||CV,a=[],c=[];let l;const u=s.filter(d=>{const p=!(Ot(d.maxParticipants)&&(r==null?void 0:r.length)>d.maxParticipants);return p||a.push(d),p});return a.length&&c.push({excludedDirectives:a,participantIds:r}),u.every(({attribute:d,reversed:p,idsFilter:v,disableHeadToHead:f})=>(l=DV({disableHeadToHead:f,participantIds:r,matchUpFormat:n,tallyPolicy:o,attribute:d,idsFilter:v,matchUps:i,reversed:p}),c.push(l.report),!l.order)),l.order?{order:l.order,report:c}:{order:r==null?void 0:r.map(d=>({participantId:d})),report:c}}function jV({participantIds:t,participantResults:e}){if(t){if(e[t[0]].victories.includes(t[1]))return t.map(r=>({resolved:!0,participantId:r}));if(e[t[1]].victories.includes(t[0]))return t.reverse().map(r=>({resolved:!0,participantId:r}))}}function b_({participantResults:t,participantIds:e,attribute:r}){return T_({participantResults:t,participantIds:e}).reduce((o,i)=>{const{participantId:s,results:a}=i,c=a==null?void 0:a[r];return!isNaN(c)&&s&&(o[c]?o[c].push(s):o[c]=[s]),o},{})}function T_({participantResults:t,participantIds:e}){return e=e||Object.keys(t),e.reduce((r,n,o)=>(r.push({participantId:n,i:o,results:t[n]}),r),[])}const E_="voluntaryConsolation",Mo="competitiveBands",w_="roundRobinTally",po="positionActions",xi="matchUpActions",Kp="rankingPoints",Qp="roundNaming",oc="participant",Bl="progression",Jp="scheduling",RV="avoidance",qs="seeding",Ys="scoring",kl="feedIn",FV="draws";function Zp({policyDefinitions:t,generateReport:e,matchUpFormat:r,matchUps:n=[],subOrderMap:o,perPlayer:i}){if(!Array.isArray(n))return{error:Ao};if(n.reduce((I,{structureId:P})=>I.includes(P)?I:I.concat(P),[]).length!==1)return{error:Z,info:"Maximum one structureId"};const a=n.filter(I=>I&&I.matchUpStatus!==qe),c=a.length&&Ve(a.map(({drawPositions:I})=>I).flat()).length,l=a.filter(I=>Ws({matchUp:I})).length===a.length;l||(i=0);const u=n.every(({matchUpType:I,tieMatchUps:P})=>I===He&&P.every(O=>Ws({matchUp:O}))),d=t==null?void 0:t[w_],p=n.filter(I=>Ws({matchUp:I})||I.matchUpType===He),{participantResults:v}=g_({matchUps:p,matchUpFormat:r,tallyPolicy:d,perPlayer:i});let f,m;const{groupOrder:g,report:h}=S_({matchUps:p,participantResults:v,participantsCount:c,matchUpFormat:r,tallyPolicy:d,subOrderMap:o});if(l&&g)f=h,m=g,g.forEach(I=>{const{participantId:P,groupOrder:O,rankOrder:y,subOrder:S,ties:T,GEMscore:E}=I,b=v[P];Object.assign(b,{groupOrder:O,rankOrder:y,GEMscore:E,subOrder:S,ties:T})});else{const{groupOrder:I,report:P}=S_({requireCompletion:!1,participantResults:v,participantsCount:c,matchUpFormat:r,tallyPolicy:d,subOrderMap:o,matchUps:n});f=P,m=I,I&&I.forEach(O=>{const{participantId:y,groupOrder:S,GEMscore:T}=O,E=v[y];Object.assign(E,{provisionalOrder:S,GEMscore:T})})}const _={completedTieMatchUps:u,participantResults:v,bracketComplete:l,report:f};if((l||u)&&(_.order=m),e||Ft({tally:!0})){const I=wV({matchUps:n,report:f,order:m});Ft({tally:!0})&&console.log(I),_.readableReport=I}return _}function LV({collectionDefinition:t,groupValueNumbers:e,groupValueGroups:r,sideTieValues:n,tieMatchUps:o}){const i=o.filter(_=>_.collectionId===t.collectionId),s=[0,0];let a=[0,0];const c=i.every(_=>Lt.includes(_.matchUpStatus)),{collectionValueProfiles:l,collectionGroupNumber:u,collectionValue:d,matchUpValue:p,winCriteria:v,scoreValue:f,setValue:m}=t,g=u&&e.includes(u),h=[0,0];if(i.forEach(_=>{_.winningSide&&(h[_.winningSide-1]+=1)}),p?i.forEach(_=>{_.winningSide&&(s[_.winningSide-1]+=p)}):m?i.forEach(_=>{var I,P;(P=(I=_.score)==null?void 0:I.sets)==null||P.forEach(O=>{O.winningSide&&(s[O.winningSide-1]+=m)})}):f?i.forEach(_=>{var I,P;(P=(I=_.score)==null?void 0:I.sets)==null||P.forEach(O=>{const{side1TiebreakScore:y=0,side2TiebreakScore:S=0,side1Score:T=0,side2Score:E=0}=O;(O.winningSide||_.winningSide)&&(T||E?(s[0]+=T,s[1]+=E):(y||S)&&O.winningSide&&(s[O.winningSide-1]+=1))})}):Array.isArray(l)&&i.forEach(_=>{if(_.winningSide){const I=_.collectionPosition,P=VV({collectionDefinition:t,collectionPosition:I});s[_.winningSide-1]+=P}}),d){let _;if(v!=null&&v.aggregateValue)c&&((p||m||f)&&s[0]!==s[1]?_=s[0]>s[1]?1:2:h[0]!==h[1]&&(_=h[0]>h[1]?1:2));else if(v!=null&&v.valueGoal)_=s.reduce((I,P,O)=>P>=v.valueGoal?O+1:I,void 0);else{const I=Math.floor(t.matchUpCount/2)+1;_=h.reduce((P,O,y)=>O>=I?y+1:P,void 0)}_&&(g?r[u].values[_-1]+=d:a[_-1]+=d)}else g?(r[u].values[0]+=s[0]||0,r[u].values[1]+=s[1]||0):a=s;g?(r[u].sideWins[0]+=h[0]||0,r[u].sideWins[1]+=h[1]||0,r[u].allGroupMatchUpsCompleted=r[u].allGroupMatchUpsCompleted&&c,r[u].matchUpsCount+=i.length):a.forEach((_,I)=>n[I]+=_)}function VV({collectionDefinition:t,collectionPosition:e}){const r=t.collectionValueProfiles||[],n=r==null?void 0:r.find(o=>o.collectionPosition===e);return n==null?void 0:n.matchUpValue}const Bi="appliedPolicies",Gl="positionActions",$_="context",Wl="delegatedOutcome",en="disabled",Hl="disableLinks",zs="disableAutoCalc",ql="drawDeletions",xV="drawProfile",Yl="entryProfile",BV="eventProfile",kV="factory",tn="flightProfile",Xp="groupingAttribute",bn="lineUps",ki="linkedTournamentsIds",zl="matchUpHistory",ef="participantRepresentatives",Ks="personRequests",N_="rankingPoints",Tn="roundTarget",Gi="scheduleLimits",En="scheduleTiming",Do="schedulingProfile",Qs="subOrder",jo="tally",Wi="tieFormatModification",A_={APPLIED_POLICIES:Bi,AUDIT_POSITION_ACTIONS:Gl,CONTEXT:$_,DELEGATED_OUTCOME:Wl,DISABLED:en,DISABLE_LINKS:Hl,DISABLE_AUTO_CALC:zs,DRAW_DELETIONS:ql,DRAW_PROFILE:xV,ENTRY_PROFILE:Yl,EVENT_PROFILE:BV,FLIGHT_PROFILE:tn,GROUPING_ATTRIBUTE:Xp,LINEUPS:bn,LINKED_TOURNAMENTS:ki,MATCHUP_HISTORY:zl,PARTICIPANT_REPRESENTATIVES:ef,PERSON_REQUESTS:Ks,RANKING_POINTS:N_,ROUND_TARGET:Tn,SCHEDULE_LIMITS:Gi,SCHEDULE_TIMING:En,SCHEDULING_PROFILE:Do,SUB_ORDER:Qs,TALLY:jo,TIE_FORMAT_MODIFICATIONS:Wi,FACTORY:kV},U_=[Wl,en,Hl,tn,bn,zl,ef,Ks,Tn,Gi,En,Do,Qs,jo];var GV=Object.defineProperty,C_=Object.getOwnPropertySymbols,WV=Object.prototype.hasOwnProperty,HV=Object.prototype.propertyIsEnumerable,M_=(t,e,r)=>e in t?GV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qV=(t,e)=>{for(var r in e||(e={}))WV.call(e,r)&&M_(t,r,e[r]);if(C_)for(var r of C_(e))HV.call(e,r)&&M_(t,r,e[r]);return t};function at({onlySpecifiedPolicyTypes:t=!1,policyTypes:e=[],tournamentRecord:r,drawDefinition:n,structure:o,event:i}){if(!Array.isArray(e))return{error:Sh};const s={};return r&&a(r),i&&a(i),n&&a(n),o&&a(o),qV({appliedPolicies:s},B);function a({extensions:c}){var l;const u=(l=c==null?void 0:c.find(d=>d.name===Bi))==null?void 0:l.value;if(u)for(const d of Object.keys(u))(t?e.includes(d):!e.length||e.includes(d))&&(s[d]=ue(u[d],!1,!0))}}function Hi({policyTypes:t=[],tournamentRecord:e,drawDefinition:r,structure:n,event:o}){if(!Array.isArray(t))return{error:Sh};const{appliedPolicies:i}=at({tournamentRecord:e,drawDefinition:r,structure:n,event:o}),s={};for(const a of t){const c=i[a];c&&(s[a]=c)}return Object.keys(s).length?{policyDefinitions:s}:{error:$p}}const D_="WALKOVER",j_="RETIRED",tf="COMPETITIVE",ic="ROUTINE",sc="DECISIVE",ac="winRatio",rf={[Mo]:{policyName:"Competitive Bands Default",competitiveProfile:{[sc]:20,[ic]:50}}};function fo({policyDefinitions:t,tournamentRecord:e,contextProfile:r,drawDefinition:n,event:o}){const i={policies:{}};if(!r)return i;const s=Hi({tournamentRecord:e,drawDefinition:n,event:o});if(r.withCompetitiveness){const a=(t==null?void 0:t[Mo])||(s==null?void 0:s[Mo])||rf[Mo];i.policies[Mo]=a}return i}function R_({matchUps:t,matchUpId:e}){return{matchUp:(t||[]).find(n=>n.matchUpId===e)}}function YV({matchUps:t}){const e=t.reduce((n,o)=>!o.collectionPosition||n.includes(o.collectionPosition)?n:n.concat(o.collectionPosition),[]).map(n=>({[n]:t.filter(o=>o.collectionPosition===n)}));return{collectionPositionMatchUps:Object.assign({},...e)}}const zV=(t,e)=>(t||0)+(e||0);function F_(t,e){return isNaN(t)&&D_||t<=e[sc]&&sc||t<=e[ic]&&ic||tf}function L_({score:t}){const e=(t==null?void 0:t.sets)||[],r=e.reduce((o,i)=>(o[0]+=i.side1Score||0,o[1]+=i.side2Score||0,o),[0,0]);let n=e.reduce((o,i)=>(o[0]+=i.side1TiebreakScore||0,o[1]+=i.side2TiebreakScore||0,o),[0,0]);return n.reduce(zV)&&(r[n[0]>n[1]?0:1]+=1),{sets:e,games:r,score:t}}function KV(t){const e=Math.min(...t.games),r=Math.max(...t.games);return Math.round(e/r*100)}function V_(t){return t.map(KV).sort().map(e=>e.toFixed(2))}function qi({tournamentRecord:t,drawDefinition:e,policyType:r,structure:n,event:o}){if(!t)return{error:ee};const{appliedPolicies:i}=at({tournamentRecord:t,drawDefinition:e,structure:n,event:o});return i!=null&&i[r]?{policy:i[r]}:{error:$p}}var QV=Object.defineProperty,JV=Object.defineProperties,ZV=Object.getOwnPropertyDescriptors,x_=Object.getOwnPropertySymbols,XV=Object.prototype.hasOwnProperty,ex=Object.prototype.propertyIsEnumerable,B_=(t,e,r)=>e in t?QV(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tx=(t,e)=>{for(var r in e||(e={}))XV.call(e,r)&&B_(t,r,e[r]);if(x_)for(var r of x_(e))ex.call(e,r)&&B_(t,r,e[r]);return t},rx=(t,e)=>JV(t,ZV(e));function k_({competitiveProfile:t,tournamentRecord:e,matchUp:r}){if(!r)return{error:$r};const{score:n,winningSide:o}=r;if(!o)return{error:Z};const i=!t&&qi({policyType:Mo,tournamentRecord:e}).policy,s=t||(i==null?void 0:i.competitiveProfile)||rf[Mo].competitiveProfile,a=L_({score:n}),c=V_([a]),l=F_(c,s);return rx(tx({},B),{competitiveness:l})}function cc({matchUpAverageTimes:t,matchUpFormat:e}={}){const r=(t==null?void 0:t.map(({matchUpFormatCodes:s})=>s==null?void 0:s.filter(a=>a===e)).flat().filter(Boolean).sort((s,a)=>((s==null?void 0:s.length)||0)-((a==null?void 0:a.length)||0)))||[],o=r.includes(e)?e:r[0],i=t==null?void 0:t.find(({matchUpFormatCodes:s,averageTimes:a})=>(s==null?void 0:s.find(c=>o===c))&&a);return i==null?void 0:i.averageTimes}function lc({matchUpRecoveryTimes:t,averageMinutes:e,matchUpFormat:r}={}){var n;return(n=t==null?void 0:t.find(({matchUpFormatCodes:o,averageTimes:i,recoveryTimes:s})=>{if(i&&e){const{greaterThan:a=0,lessThan:c=360}=i;if(e>a&&e<c)return!0}return(o==null?void 0:o.find(a=>a===r))&&s}))==null?void 0:n.recoveryTimes}function G_({categoryName:t,categoryType:e,timesBlockArray:r}){return r.filter(n=>Array.isArray(n)).map(n=>n.sort((o,i)=>{var s,a;return(((s=i.categoryNames)==null?void 0:s.length)||0)-(((a=o.categoryNames)==null?void 0:a.length)||0)}).find(({categoryTypes:o,categoryNames:i})=>!(i!=null&&i.length)&&!(o!=null&&o.length)||(i==null?void 0:i.includes(t))||(o==null?void 0:o.includes(e)))).find(Boolean)}var nx=Object.defineProperty,ox=Object.defineProperties,ix=Object.getOwnPropertyDescriptors,W_=Object.getOwnPropertySymbols,sx=Object.prototype.hasOwnProperty,ax=Object.prototype.propertyIsEnumerable,H_=(t,e,r)=>e in t?nx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,nf=(t,e)=>{for(var r in e||(e={}))sx.call(e,r)&&H_(t,r,e[r]);if(W_)for(var r of W_(e))ax.call(e,r)&&H_(t,r,e[r]);return t},of=(t,e)=>ox(t,ix(e));function cx({tournamentScheduling:t,eventScheduling:e,averageMinutes:r,defaultTiming:n,matchUpFormat:o,categoryName:i,categoryType:s,policy:a}){var c;const l=(e==null?void 0:e.matchUpRecoveryTimes)&&lc(of(nf({},e),{averageMinutes:r,matchUpFormat:o})),u=(t==null?void 0:t.matchUpRecoveryTimes)&&lc(of(nf({},t),{averageMinutes:r,matchUpFormat:o})),d=(a==null?void 0:a.matchUpRecoveryTimes)&&lc(of(nf({},a),{averageMinutes:r,matchUpFormat:o})),p=[l,u,d,(c=a==null?void 0:a.defaultTimes)==null?void 0:c.recoveryTimes,n==null?void 0:n.recoveryTimes];return G_({categoryName:i,categoryType:s,timesBlockArray:p})}var lx=Object.defineProperty,ux=Object.defineProperties,dx=Object.getOwnPropertyDescriptors,q_=Object.getOwnPropertySymbols,px=Object.prototype.hasOwnProperty,fx=Object.prototype.propertyIsEnumerable,Y_=(t,e,r)=>e in t?lx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sf=(t,e)=>{for(var r in e||(e={}))px.call(e,r)&&Y_(t,r,e[r]);if(q_)for(var r of q_(e))fx.call(e,r)&&Y_(t,r,e[r]);return t},af=(t,e)=>ux(t,dx(e));function vx({matchUpFormat:t,categoryName:e,categoryType:r,defaultTiming:n,tournamentScheduling:o,eventScheduling:i,policy:s}){var a;const c=(i==null?void 0:i.matchUpAverageTimes)&&cc(af(sf({},i),{matchUpFormat:t})),l=(o==null?void 0:o.matchUpAverageTimes)&&cc(af(sf({},o),{matchUpFormat:t})),u=(s==null?void 0:s.matchUpAverageTimes)&&cc(af(sf({},s),{matchUpFormat:t})),d=[c,l,u,(a=s==null?void 0:s.defaultTimes)==null?void 0:a.averageTimes,n==null?void 0:n.averageTimes];return G_({categoryName:e,categoryType:r,timesBlockArray:d})}const ui="RANKING",Yi="RATING",zi="SCALE",rn="SEEDING";var mx=Object.defineProperty,z_=Object.getOwnPropertySymbols,gx=Object.prototype.hasOwnProperty,hx=Object.prototype.propertyIsEnumerable,K_=(t,e,r)=>e in t?mx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Q_=(t,e)=>{for(var r in e||(e={}))gx.call(e,r)&&K_(t,r,e[r]);if(z_)for(var r of z_(e))hx.call(e,r)&&K_(t,r,e[r]);return t};function Js({participant:t}){var e;const r=(e=t.timeItems)==null?void 0:e.filter(({itemType:o})=>(o==null?void 0:o.startsWith(zi))&&[ui,Yi,rn].includes(o.split(".")[1])),n={ratings:{},rankings:{},seedings:{}};if(r!=null&&r.length){const o=s=>r.filter(a=>(a==null?void 0:a.itemType)===s).sort((a,c)=>new Date(a.createdAt||void 0)-new Date(c.createdAt||void 0)).pop(),i=Ve(r.map(({itemType:s})=>s));for(const s of i){const a=o(s);if(a){const[,c,l,u]=a.itemType.split("."),d=c===rn&&"seedings"||c===ui&&"rankings"||"ratings";n[d][l]||(n[d][l]=[]),n[d][l].push({scaleValue:a.itemValue,scaleDate:a.itemDate,scaleName:u})}}}return Q_(Q_({},B),n)}function vo({tournamentParticipants:t=[],policyDefinitions:e={},contextProfile:r,participantId:n,internalUse:o,personId:i}){const s=t.find(a=>n&&a.participantId===n||i&&a.person&&a.person.personId===i);if(s){const a=e==null?void 0:e[oc];if(r!=null&&r.withScaleValues){const{ratings:c,rankings:l}=Js({participant:s});s.ratings=c,s.rankings=l}if(a!=null&&a.participant){const c=Dl({template:a.participant,source:s});return ue(c,!1,o)}}return ue(s,!1,o)}function Ro({tournamentRecord:t,participantId:e}){return{participant:(t.participants||[]).reduce((o,i)=>i.participantId===e?i:o,void 0)}}function _x({tournamentRecord:t,policyDefinitions:e,convertExtensions:r,participantId:n,inContext:o,personId:i}){if(!t)return{error:ee};if(typeof n!="string"&&typeof i!="string")return{error:Oe};const s=t.participants||[],a=vo({tournamentParticipants:s,policyDefinitions:e,participantId:n,personId:i,inContext:o});return{participant:ue(a,r,!0)}}const uc="extensionQueries";function Vt({element:t,name:e}){if(!t||!e)return W({result:{error:Oe},stack:uc});if(!Array.isArray(t.extensions))return{info:Yt};const r=t.extensions.find(o=>(o==null?void 0:o.name)===e);return{extension:r,info:r?void 0:Yt}}function Sr({tournamentRecord:t,name:e}){return Vt({element:t,name:e})}function mo({event:t,name:e}){return t?Vt({element:t,name:e}):W({result:{error:Le},stack:uc})}function Kl({drawDefinition:t,name:e}){return t?Vt({element:t,name:e}):W({result:{error:pe},stack:uc})}function Ix({tournamentRecord:t,participantId:e,name:r}){if(!t)return W({result:{error:ee},stack:uc});if(!e)return W({result:{error:yt},stack:uc});const{participant:n}=Ro({tournamentRecord:t,participantId:e});return Vt({element:n,name:r})}function dc({tournamentRecord:t,categoryName:e,categoryType:r,event:n}){var o,i,s,a;e=e||((o=n==null?void 0:n.category)==null?void 0:o.categoryName)||((i=n==null?void 0:n.category)==null?void 0:i.ageCategoryCode),r=r||((s=n==null?void 0:n.category)==null?void 0:s.categoryType)||((a=n==null?void 0:n.category)==null?void 0:a.subType);const{policy:c}=qi({policyType:Jp,tournamentRecord:t,event:n}),{extension:l}=Sr({name:En,tournamentRecord:t}),u=l==null?void 0:l.value,{extension:d}=mo({name:En,event:n}),p=d==null?void 0:d.value;return{scheduleTiming:{tournamentScheduling:u,eventScheduling:p,categoryName:e,categoryType:r,policy:c}}}const Px="DOUBLES_SINGLES",yx="SINGLES_DOUBLES",nn="total",J_="participantConflict",di="matchUpConflict",Sx="ISSUE_IDS",Ki="CONFLICT",Qi="WARNING",Z_="ERROR",X_="ISSUE",cf="STATE";var Ox=Object.defineProperty,bx=Object.defineProperties,Tx=Object.getOwnPropertyDescriptors,eI=Object.getOwnPropertySymbols,Ex=Object.prototype.hasOwnProperty,wx=Object.prototype.propertyIsEnumerable,tI=(t,e,r)=>e in t?Ox(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,rI=(t,e)=>{for(var r in e||(e={}))Ex.call(e,r)&&tI(t,r,e[r]);if(eI)for(var r of eI(e))wx.call(e,r)&&tI(t,r,e[r]);return t},nI=(t,e)=>bx(t,Tx(e));function lf({defaultAverageMinutes:t=90,defaultRecoveryMinutes:e=0,tournamentRecord:r,matchUpFormat:n,categoryName:o,categoryType:i,eventType:s,event:a}){if(!r)return{error:ee};s=s||(a==null?void 0:a.eventType)||pt;const c={averageTimes:[{minutes:{default:t}}],recoveryTimes:[{minutes:{default:e}}]},{scheduleTiming:l}=dc({tournamentRecord:r,categoryName:o,categoryType:i,event:a}),u=nI(rI({},l),{matchUpFormat:n,categoryType:i,defaultTiming:c});return Ql({eventType:s,timingDetails:u})}function Ql({eventType:t,timingDetails:e}){const r=vx(e),n=Object.keys((r==null?void 0:r.minutes)||{}),o=(r==null?void 0:r.minutes)&&((n==null?void 0:n.includes(t))&&r.minutes[t]||r.minutes.default),i=cx(nI(rI({},e),{averageMinutes:o})),s=Object.keys((i==null?void 0:i.minutes)||{}),a=(i==null?void 0:i.minutes)&&((s==null?void 0:s.includes(t))&&i.minutes[t]||i.minutes.default),c=t===pt?yx:Px,l=(i==null?void 0:i.minutes)&&((s==null?void 0:s.includes(c))&&i.minutes[c]||a);return{averageMinutes:o,recoveryMinutes:a,typeChangeRecoveryMinutes:l}}function on({requiredAttributes:t=["name","value"],extension:e}){if(!e||typeof e!="object"||typeof e.name!="string")return!1;const r=Object.keys(e);return t.filter(n=>r.includes(n)).length===t.length}function It({event:t,eventId:e}){var r;if(!t)return{error:Le};const{extension:n}=mo({name:tn,event:t}),o=e?ue(n==null?void 0:n.value,!1,!0):n==null?void 0:n.value;return e&&((r=t.drawDefinitions)==null||r.forEach(i=>{var s;(s=o==null?void 0:o.flights)==null||s.forEach(a=>{a.drawId===i.drawId&&Object.assign(a,{drawDefinition:i})})})),{flightProfile:o}}var $x=Object.defineProperty,Nx=Object.defineProperties,Ax=Object.getOwnPropertyDescriptors,oI=Object.getOwnPropertySymbols,Ux=Object.prototype.hasOwnProperty,Cx=Object.prototype.propertyIsEnumerable,iI=(t,e,r)=>e in t?$x(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Mx=(t,e)=>{for(var r in e||(e={}))Ux.call(e,r)&&iI(t,r,e[r]);if(oI)for(var r of oI(e))Cx.call(e,r)&&iI(t,r,e[r]);return t},Dx=(t,e)=>Nx(t,Ax(e));function jx({tournamentRecord:t,drawDefinition:e,event:r,context:n}){var o;if(!t)return{error:ee};if(!r)return{error:Le};const i=ue(r);n&&Object.assign(i,n);const s=e&&((o=i.drawDefinitions)==null?void 0:o.find(({drawId:a})=>e.drawId===a));return _e({event:i,drawDefinition:s})}function Rx({tournamentRecord:t,context:e,inContext:r}){if(!t)return{error:ee};const{tournamentId:n}=t;return{events:(t.events||[]).map(i=>{const s=ue(i);return e&&Object.assign(s,e),r&&Object.assign(s,{tournamentId:n}),s})}}function xt({tournamentRecord:t,eventId:e,drawId:r}){const n="findEvent";if(!t)return W({result:{error:ee},stack:n});const o=(t==null?void 0:t.events)||[];if(r){let i;const s=o.find(a=>{var c;const u=((a==null?void 0:a.drawDefinitions)||[]).find(d=>d.drawId===r);if(u)i=u;else{const{flightProfile:d}=It({event:a}),p=(c=d==null?void 0:d.flights)==null?void 0:c.find(v=>v.drawId===r);if(p)return{drawId:r,entries:p.drawEntries,drawName:p.drawName}}return u});if(s)return{event:s,drawDefinition:i}}if(e){const i=o.find(s=>s.eventId===e);return i?{event:i}:W({result:{error:Ir},stack:n})}return W({result:{error:_n},context:{drawId:r,eventId:e},stack:n})}function Fo({tournamentRecord:t,drawId:e}){if(!t)return{error:ee};if(!e)return{error:wr};const r=(t.events||[]).reduce((n,o)=>{const i=(o.drawDefinitions||[]).reduce((s,a)=>a.drawId===e?a:s,void 0);return i&&i.drawId===e?{event:o,drawDefinition:i}:n},void 0);return r?Dx(Mx({},r),{SUCCESS:B}):W({result:{error:_n},stack:"getDrawDefinition"})}var Fx=Object.defineProperty,sI=Object.getOwnPropertySymbols,Lx=Object.prototype.hasOwnProperty,Vx=Object.prototype.propertyIsEnumerable,aI=(t,e,r)=>e in t?Fx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xx=(t,e)=>{for(var r in e||(e={}))Lx.call(e,r)&&aI(t,r,e[r]);if(sI)for(var r of sI(e))Vx.call(e,r)&&aI(t,r,e[r]);return t};function tt({element:t,extension:e,creationTime:r=!0}={}){const n="addExtension";if(!t)return W({result:{error:Oe},stack:n});if(typeof t!="object")return W({result:{error:Z},stack:n});if(!on({extension:e}))return W({result:{error:Z,info:"invalid extension"},stack:n});if(t.extensions||(t.extensions=[]),r){const i=new Date().toISOString();Object.assign(e,{createdAt:i})}const o=t.extensions.find(({name:i})=>i===e.name);return o?o.value=e.value:e.value&&t.extensions.push(e),xx({},B)}const uf="element required",df="missing name";var Bx=Object.defineProperty,kx=Object.defineProperties,Gx=Object.getOwnPropertyDescriptors,cI=Object.getOwnPropertySymbols,Wx=Object.prototype.hasOwnProperty,Hx=Object.prototype.propertyIsEnumerable,lI=(t,e,r)=>e in t?Bx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,uI=(t,e)=>{for(var r in e||(e={}))Wx.call(e,r)&&lI(t,r,e[r]);if(cI)for(var r of cI(e))Hx.call(e,r)&&lI(t,r,e[r]);return t},qx=(t,e)=>kx(t,Gx(e));function sn({element:t,name:e}={}){return t?typeof t!="object"?{error:Z}:e?t.extensions?(t.extensions=t.extensions.filter(r=>(r==null?void 0:r.name)!==e),uI({},B)):qx(uI({},B),{info:Yt}):{error:Oe,info:df}:{error:Oe,info:uf}}function pi({creationTime:t=!0,tournamentRecord:e,extension:r}={}){return e?tt({element:e,extension:r,creationTime:t}):{error:ee}}function pf({creationTime:t=!0,drawDefinition:e,extension:r}={}){return e?tt({element:e,extension:r,creationTime:t}):{error:_n}}function Wn({creationTime:t=!0,extension:e,event:r}={}){return r?tt({element:r,extension:e,creationTime:t}):{error:Le}}function Yx({creationTime:t=!0,tournamentRecord:e,participantId:r,extension:n}={}){if(!r)return{error:yt};const o=(e==null?void 0:e.participants)||[],i=vo({tournamentParticipants:o,participantId:r});return i?tt({element:i,extension:n,creationTime:t}):{error:wt}}function ff({tournamentRecord:t,name:e}={}){return t?sn({element:t,name:e}):{error:ee}}function zx({drawDefinition:t,name:e}={}){return t?sn({element:t,name:e}):{error:_n}}function Jl({event:t,name:e}={}){return t?sn({element:t,name:e}):{error:Ir}}function Kx({tournamentRecord:t,participantId:e,name:r}={}){if(!e)return{error:yt};const n=(t==null?void 0:t.participants)||[],o=vo({tournamentParticipants:n,participantId:e});return o?sn({element:o,name:r}):{error:wt}}var Qx=Object.defineProperty,Jx=Object.defineProperties,Zx=Object.getOwnPropertyDescriptors,dI=Object.getOwnPropertySymbols,Xx=Object.prototype.hasOwnProperty,eB=Object.prototype.propertyIsEnumerable,pI=(t,e,r)=>e in t?Qx(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fI=(t,e)=>{for(var r in e||(e={}))Xx.call(e,r)&&pI(t,r,e[r]);if(dI)for(var r of dI(e))eB.call(e,r)&&pI(t,r,e[r]);return t},tB=(t,e)=>Jx(t,Zx(e));function vf({tournamentRecords:t,extension:e}){if(!on({extension:e}))return{error:Z};const r="addExtension";for(const n of Object.values(t)){const o=pi({tournamentRecord:n,extension:e});if(o.error)return W({result:o,stack:r})}return fI({},B)}function Zl({tournamentRecords:t,name:e}){if(!e)return{error:Oe,info:df};let r;return Object.keys(t).find(o=>{const i=t[o],{extension:s}=Sr({tournamentRecord:i,name:e});return r=s,!!s})?{extension:r}:{error:Yt}}function Xl({tournamentRecords:t,name:e}){if(!e)return{error:Oe,info:df};let r=0;for(const n of Object.keys(t)){const o=t[n],i=ff({tournamentRecord:o,name:e});if(i.error)return W({result:i,stack:"removeExtension"});i.info!==Yt&&r++}return tB(fI({},B),{removed:r})}function rB({tournamentRecords:t,eventId:e,extension:r}){if(typeof e!="string")return{error:Le};if(!on({extension:r}))return{error:Z};for(const n of Object.values(t)){const{event:o}=xt({tournamentRecord:n,eventId:e});if(o)return Wn({event:o,extension:r})}return{error:Ir}}var nB=Object.defineProperty,vI=Object.getOwnPropertySymbols,oB=Object.prototype.hasOwnProperty,iB=Object.prototype.propertyIsEnumerable,mI=(t,e,r)=>e in t?nB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gI=(t,e)=>{for(var r in e||(e={}))oB.call(e,r)&&mI(t,r,e[r]);if(vI)for(var r of vI(e))iB.call(e,r)&&mI(t,r,e[r]);return t};function mf({tournamentRecords:t}){return typeof t!="object"||!Object.keys(t).length?{error:Fe}:{linkedTournamentIds:Object.assign({},...Object.keys(t).map(r=>{var n;const o=t[r],i=o==null?void 0:o.tournamentId,{extension:s}=Sr({tournamentRecord:o,name:ki}),a=(((n=s==null?void 0:s.value)==null?void 0:n.tournamentIds)||[]).filter(c=>c!==i);return{[r]:a}}))}}function sB({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const e=hI(t);if(e.error)return e;const{tournamentIds:r}=e;return(r==null?void 0:r.length)>1?vf({tournamentRecords:t,extension:{name:ki,value:{tournamentIds:r}}}):gI({},B)}function aB({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const e=Xl({name:ki,tournamentRecords:t});return W({result:e,stack:"unlinkTournaments"})}function cB({tournamentRecords:t,tournamentId:e}){if(typeof t!="object")return{error:Z};if(!e)return{error:ao};const r=hI(t);if(r.error)return r;const{tournamentIds:n}=r;if(!n.includes(e))return{error:ao};let o;return n.every(i=>{var s;const a=t[i],{extension:c}=Sr({tournamentRecord:a,name:ki});if(!c)return!0;let l=((s=c==null?void 0:c.value)==null?void 0:s.tournamentIds)||[];if(!(l!=null&&l.length)||l.length===1&&l.includes(e)||i===e){const p=ff({tournamentRecord:a,name:ki});return p.error&&(o=p.error),p.success}const u=l.filter(p=>p!==e);c.value={tournamentIds:u};const d=pi({tournamentRecord:a,extension:c});return d.error&&(o=d.error),d.success}),o?{error:o}:gI({},B)}function hI(t){return{tournamentIds:Object.keys(t).filter(Boolean)}}function _I({extension:t,dates:e=[]}){if(!t)return!1;if(typeof t.value=="boolean"&&t.value)return!0;if(typeof t.value=="object"&&Array.isArray(t.value.dates))return e.length?!!e.filter(n=>t.value.dates.includes(n)).length:!0}function Or({element:t,name:e}){const r="findExtension";if(!t||!e)return W({result:{error:Oe},stack:r});if(!Array.isArray(t.extensions))return W({result:{error:Yt},stack:r});const n=t.extensions.find(o=>(o==null?void 0:o.name)===e);return n?{extension:n}:W({result:{error:Yt},stack:r})}var lB=Object.defineProperty,uB=Object.defineProperties,dB=Object.getOwnPropertyDescriptors,II=Object.getOwnPropertySymbols,pB=Object.prototype.hasOwnProperty,fB=Object.prototype.propertyIsEnumerable,PI=(t,e,r)=>e in t?lB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vB=(t,e)=>{for(var r in e||(e={}))pB.call(e,r)&&PI(t,r,e[r]);if(II)for(var r of II(e))fB.call(e,r)&&PI(t,r,e[r]);return t},mB=(t,e)=>uB(t,dB(e));function yI({convertExtensions:t,ignoreDisabled:e,venue:r,court:n}){const o=mB(vB({},ue(n,t,!0)),{venueId:r.venueId}),{extension:i}=Or({name:en,element:n});if(e&&i){const s=typeof i.value=="object"&&i.value.dates||[],a=i.value===!0?[]:o.dateAvailability.map(c=>{const l=c.date;if(!(!l||s.includes(l)))return c}).filter(Boolean);o.dateAvailability=a}return{inContextCourt:o}}const SI="addDrawDefinition",gf="addMatchUps",fi="addParticipants",OI="addScaleItems",bI="addVenue",pc="audit",TI="deleteParticipants",EI="deleteVenue",wI="deletedDrawIds",$I="deletedMatchUpIds",NI="modifyDrawDefinition",gB="modifyDrawEntries",hB="modifyEventEntries",AI="modifyMatchUp",Ht="modifyParticipants",UI="modifyPositionAssignments",CI="modifySeedAssignments",_B="modifyTournamentDetail",Ji="modifyVenue",MI="mutations",IB="publishEvent",PB="publishEventSeeding",yB="publishOrderOfPlay",DI="unPublishEvent",jI="unPublishEventSeeding",RI="unPublishOrderOfPlay",hf="updateInContextMatchUp";var SB=Object.defineProperty,OB=Object.defineProperties,bB=Object.getOwnPropertyDescriptors,FI=Object.getOwnPropertySymbols,TB=Object.prototype.hasOwnProperty,EB=Object.prototype.propertyIsEnumerable,LI=(t,e,r)=>e in t?SB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wB=(t,e)=>{for(var r in e||(e={}))TB.call(e,r)&&LI(t,r,e[r]);if(FI)for(var r of FI(e))EB.call(e,r)&&LI(t,r,e[r]);return t},$B=(t,e)=>OB(t,bB(e));function fc({tournamentRecord:t,context:e,disableNotice:r,venue:n}){return t?n?(t.venues||(t.venues=[]),n.venueId||(n.venueId=We()),t.venues.reduce((i,s)=>i||s.venueId===n.venueId,void 0)?{error:zF}:(e&&tt({element:n,extension:{value:e,name:$_}}),t.venues.push(n),r||xe({payload:{venue:n,tournamentId:t.tournamentId},topic:bI}),$B(wB({},B),{venue:ue(n)}))):{error:Oe,info:"missing venue"}:{error:ee}}var NB=Object.defineProperty,AB=Object.defineProperties,UB=Object.getOwnPropertyDescriptors,eu=Object.getOwnPropertySymbols,VI=Object.prototype.hasOwnProperty,xI=Object.prototype.propertyIsEnumerable,BI=(t,e,r)=>e in t?NB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,kI=(t,e)=>{for(var r in e||(e={}))VI.call(e,r)&&BI(t,r,e[r]);if(eu)for(var r of eu(e))xI.call(e,r)&&BI(t,r,e[r]);return t},GI=(t,e)=>AB(t,UB(e)),CB=(t,e)=>{var r={};for(var n in t)VI.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&eu)for(var n of eu(t))e.indexOf(n)<0&&xI.call(t,n)&&(r[n]=t[n]);return r};function _f({convertExtensions:t,tournamentRecord:e,ignoreDisabled:r,dates:n}){if(!e)return{error:ee};const o=ue(e.venues||[],t).filter(s=>{if(!r)return s;const{extension:a}=Or({name:en,element:s});return!(a!=null&&a.value)&&s}).filter(Boolean),i=o.reduce((s,a)=>{const c=((a==null?void 0:a.courts)||[]).filter(l=>{if(!r&&!(n!=null&&n.length))return l;const{extension:u}=Or({name:en,element:l});return _I({extension:u,dates:n})}).filter(Boolean).map(l=>{const{inContextCourt:u}=yI({convertExtensions:t,ignoreDisabled:r,venue:a,court:l});return u});return c.length?s.concat(c):s},[]);return{venues:o,courts:i}}function Lo({tournamentRecords:t,tournamentRecord:e,venueId:r}){if(!e)return{error:ee};if(!r)return{error:Uo};let o=(e.venues||[]).reduce((i,s)=>s.venueId===r?s:i,void 0);if(!o&&t){const s=mf({tournamentRecords:t}).linkedTournamentIds[e.tournamentId];for(const a of s){const c=t[a],l=Lo({tournamentRecord:c,venueId:r});if(l.success)return fc({tournamentRecord:e,venue:l.venue}),GI(kI({},B),{venue:o})}}return o?GI(kI({},B),{venue:o}):{error:oi}}function MB(t){var e=t,{convertExtensions:r}=e,n=CB(e,["convertExtensions"]);return ue(Lo(n),r,!0)}var DB=Object.defineProperty,jB=Object.defineProperties,RB=Object.getOwnPropertyDescriptors,WI=Object.getOwnPropertySymbols,FB=Object.prototype.hasOwnProperty,LB=Object.prototype.propertyIsEnumerable,HI=(t,e,r)=>e in t?DB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qI=(t,e)=>{for(var r in e||(e={}))FB.call(e,r)&&HI(t,r,e[r]);if(WI)for(var r of WI(e))LB.call(e,r)&&HI(t,r,e[r]);return t},YI=(t,e)=>jB(t,RB(e));function Zi({tournamentRecords:t,tournamentRecord:e,courtId:r}){if(!e)return{error:ee};if(!r)return{error:Fs};const n="findCourt";let o,i;if((e.venues||[]).forEach(s=>{(s.courts||[]).forEach(a=>{a.courtId===r&&(o=a,i=s)})}),o)return YI(qI({},B),{court:o,venue:i});if(t){const a=mf({tournamentRecords:t}).linkedTournamentIds[e.tournamentId];for(const c of a){const l=t[c],u=Zi({tournamentRecord:l,courtId:r});if(u.success)return fc({tournamentRecord:e,venue:u.venue}),YI(qI({},B),{court:o,venue:i})}}return W({result:{error:Rp},stack:n})}function VB(t){return ue(Zi(t),!1,!0)}function xB({tournamentRecord:t,venueId:e,venueIds:r}){return t?{courts:(t.venues||[]).filter(o=>e?o.venueId===e:r?r.includes(o.venueId):!e&&!r).map(o=>{const{venueId:i}=o,s=ue(o.courts||[]);return s.forEach(a=>Object.assign(a,{venueId:i})),s}).flat()}:{error:ee}}var BB=Object.defineProperty,kB=Object.defineProperties,GB=Object.getOwnPropertyDescriptors,zI=Object.getOwnPropertySymbols,WB=Object.prototype.hasOwnProperty,HB=Object.prototype.propertyIsEnumerable,KI=(t,e,r)=>e in t?BB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qB=(t,e)=>{for(var r in e||(e={}))WB.call(e,r)&&KI(t,r,e[r]);if(zI)for(var r of zI(e))HB.call(e,r)&&KI(t,r,e[r]);return t},YB=(t,e)=>kB(t,GB(e));function QI({tournamentRecord:t,courtId:e,internalUse:r}){if(!t)return{error:ee};if(!e)return{error:Fs};const n=Zi({tournamentRecord:t,courtId:e});if(n.error)return n;const o=(({altitude:i,courtId:s,courtName:a,courtDimensions:c,latitude:l,longitude:u,surfaceCategory:d,surfaceType:p,surfaceDate:v,pace:f,notes:m})=>({altitude:i,courtId:s,courtName:a,courtDimensions:c,latitude:l,longitude:u,surfaceCategory:d,surfaceType:p,surfaceDate:v,pace:f,notes:m}))(n.court);return YB(qB({},B),{courtInfo:ue(o,!1,r)})}var zB=Object.defineProperty,KB=Object.defineProperties,QB=Object.getOwnPropertyDescriptors,JI=Object.getOwnPropertySymbols,JB=Object.prototype.hasOwnProperty,ZB=Object.prototype.propertyIsEnumerable,ZI=(t,e,r)=>e in t?zB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,If=(t,e)=>{for(var r in e||(e={}))JB.call(e,r)&&ZI(t,r,e[r]);if(JI)for(var r of JI(e))ZB.call(e,r)&&ZI(t,r,e[r]);return t},XI=(t,e)=>KB(t,QB(e));function tu({tournamentRecord:t,venueId:e}){if(!t)return{error:ee};if(!e)return{error:Uo};const r=Lo({tournamentRecord:t,venueId:e});if(r.error)return r;const o=(r.venue.courts||[]).map(a=>(({courtInfo:c})=>If({},c))(QI({courtId:a.courtId,internalUse:!0,tournamentRecord:t}))),i=(({venueId:a,venueName:c,venueAbbreviation:l})=>({venueId:a,venueName:c,venueAbbreviation:l}))(r.venue),s=XI(If({},i),{courtsInfo:o});return XI(If({},B),{venueData:ue(s,!1,!0)})}const Pf="CHECK_IN",yf="CHECK_OUT",vc="SCHEDULE.ASSIGNMENT.VENUE",Vo="SCHEDULE.ALLOCATION.COURTS",Xi="SCHEDULE.ASSIGNMENT.COURT",eP="SCHEDULE.COURT.ORDER",mc="SCHEDULE.DATE",XB="SCHEDULE.ASSIGN.OFFICIAL",gc="SCHEDULE.TIME.SCHEDULED",wn="SCHEDULE.TIME.START",xo="SCHEDULE.TIME.STOP",go="SCHEDULE.TIME.RESUME",Bo="SCHEDULE.TIME.END",tP="SCHEDULE.TIME.MODIFIERS",rP=["TO_BE_ANNOUNCED","NEXT_AVAILABLE","FOLLOWED_BY","AFTER_REST","RAIN_DELAY"],ek="SCALE",tk="RATING",rk="RANKING",nP="SEEDING",Ar="PUBLISH",$n="PUBLIC",Ur="STATUS";function ru(t){return t.createdAt?new Date(t.createdAt).getTime():0}function vi({timeItems:t,itemType:e,visibilityThreshold:r}){const n=t.filter(i=>i&&i.itemType===e&&(!r||ru(i)<r)).sort((i,s)=>ru(i)-ru(s)).pop(),o=n&&ru(n);return{itemValue:n==null?void 0:n.itemValue,timeStamp:o}}function Sf({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=vi({timeItems:(n==null?void 0:n.timeItems)||[],itemType:gc,visibilityThreshold:t});return!r||i&&e&&i>e?{scheduledTime:o}:r}function mi({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=vi({timeItems:(n==null?void 0:n.timeItems)||[],itemType:mc,visibilityThreshold:t});return!r||i&&e&&i>e?{scheduledDate:o}:r}function oP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=vi({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Vo,visibilityThreshold:t});return!r||i&&e&&i>e?{allocatedCourts:ue(o,!1,!0)}:r}function iP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=vi({timeItems:(n==null?void 0:n.timeItems)||[],itemType:Xi,visibilityThreshold:t});return!r||i&&e&&i>e?{courtId:o}:r}function sP({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=vi({timeItems:(n==null?void 0:n.timeItems)||[],itemType:vc,visibilityThreshold:t});return!r||i&&e&&i>e?{venueId:o}:r}function Of({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=vi({timeItems:(n==null?void 0:n.timeItems)||[],itemType:tP,visibilityThreshold:t});return!r||i&&e&&i>e?{timeModifiers:o}:r}function es(t){if(r_.test(t)){const e=kp();return new Date(`${e}T${t}`)}else return new Date(t)}function aP({matchUp:t}){if(!t)return{error:$r};if(!t.timeItems)return{error:xh};const e=t.timeItems.filter(n=>[wn,xo,go,Bo].includes(n==null?void 0:n.itemType)).sort((n,o)=>es(n.itemValue)-es(o.itemValue)),r=e.reduce((n,o)=>{var i,s;let a;const c=(i=o==null?void 0:o.itemType)==null?void 0:i.split("."),u=`SCHEDULE.TIME.${((s=o==null?void 0:o.itemType)==null?void 0:s.startsWith("SCHEDULE.TIME"))&&c[2]}`;switch(u){case wn:a=0;break;case Bo:if(n.lastValue&&[wn,go].includes(n.lastType)){const d=es(o.itemValue)-es(n.lastValue);a=n.milliseconds+d}else a=n.milliseconds;break;case xo:if([wn,"SCHECULE.TIME.RESUME"].includes(n.lastType)){const d=es(o.itemValue)-es(n.lastValue);a=n.milliseconds+d}else a=n.milliseconds;break;default:a=n.milliseconds;break}return{milliseconds:a,lastType:u,lastValue:o.itemValue}},{milliseconds:0,lastType:void 0,lastValue:void 0});if([wn,go].includes(r.lastType)){const n=new Date-es(r.lastValue);r.milliseconds+=n}return{milliseconds:r.milliseconds,time:nk(r.milliseconds),relevantTimeItems:e}}function nk(t){const e=(r,n=2)=>("00"+r).slice(-n);return e(t/36e5|0)+":"+e(t%36e5/6e4|0)+":"+e(t%6e4/1e3|0)}function ok({visibilityThreshold:t,timeStamp:e,schedule:r,matchUp:n}){const{itemValue:o,timeStamp:i}=vi({timeItems:(n==null?void 0:n.timeItems)||[],itemType:eP,visibilityThreshold:t});return!r||i&&e&&i>e?{courtOrder:o}:r}function ik({matchUp:t}){const e=(t==null?void 0:t.timeItems)||[],r=i=>i.createdAt?new Date(i.createdAt).getTime():0,n=e.reduce((i,s)=>{const a=s.itemType===wn&&s;return a&&(!i||r(a)<r(i))?a:i},void 0);return{startTime:n==null?void 0:n.itemValue}}function sk({matchUp:t}){const e=(t==null?void 0:t.timeItems)||[],r=i=>i.createdAt?new Date(i.createdAt).getTime():0,n=e.reduce((i,s)=>{const a=s.itemType===Bo&&s;return a&&(!i||r(a)>r(i))?a:i},void 0);return{endTime:n==null?void 0:n.itemValue}}const Hn="SINGLES",cP="SINGLES",br="DOUBLES",hc="DOUBLES",Tt="TEAM",Nn="TEAM";var ak=Object.defineProperty,lP=Object.getOwnPropertySymbols,ck=Object.prototype.hasOwnProperty,lk=Object.prototype.propertyIsEnumerable,uP=(t,e,r)=>e in t?ak(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,uk=(t,e)=>{for(var r in e||(e={}))ck.call(e,r)&&uP(t,r,e[r]);if(lP)for(var r of lP(e))lk.call(e,r)&&uP(t,r,e[r]);return t};function bf({scheduleVisibilityFilters:t,afterRecoveryTimes:e,tournamentRecord:r,scheduleTiming:n,matchUpFormat:o,matchUpType:i,matchUp:s,event:a}){var c,l,u,d;if(!s)return{error:$r};if(e&&!s.matchUpType&&!i&&(a||r)&&s.drawId){let T=a==null?void 0:a.drawDefinitions.find(b=>b.drawId===s.drawId);!T&&r&&({drawDefinition:T,event:a}=xt({tournamentRecord:r,drawId:s.drawId}));const E=s.structureId&&((c=T==null?void 0:T.structures)==null?void 0:c.find(({structureId:b})=>b===s.structureId));i=(E==null?void 0:E.matchUpType)||(T==null?void 0:T.matchUpType)||(a==null?void 0:a.eventType)!==Tt&&(a==null?void 0:a.eventType)}const{milliseconds:p,time:v}=aP({matchUp:s}),{startTime:f}=ik({matchUp:s}),{endTime:m}=sk({matchUp:s});let g;const{visibilityThreshold:h,eventIds:_,drawIds:I}=t||{};if((!_||_.includes(s.eventId))&&(!I||I.includes(s.drawId))){const T={matchUp:s,visibilityThreshold:h},{allocatedCourts:E}=oP(T),{scheduledTime:b}=Sf(T);let{scheduledDate:N}=mi(T);const{venueId:w}=sP(T),{courtId:$}=iP(T),{courtOrder:U}=ok(T),{timeModifiers:A}=Of(T);let M,C,D,F,R;if(n!=null&&n.policy&&b&&e){const H=uk({matchUpFormat:s.matchUpFormat||o},n);({averageMinutes:C=0,recoveryMinutes:D=0,typeChangeRecoveryMinutes:F=0}=Ql({eventType:s.matchUpType||i,timingDetails:H})),(C||D)&&(M=m?lr(rt(m),D):lr(b,C+D)),F&&(R=m?lr(rt(m),F):lr(b,C+F))}!N&&b&&(N=Ce(b));const G=Rl({scheduledDate:N,scheduledTime:b}),x={},z=((l=r&&w&&tu({tournamentRecord:r,venueId:w}))==null?void 0:l.venueData)||{};w&&(x[w]=z);const{venueName:j,venueAbbreviation:V,courtsInfo:L}=z,q=$&&(L==null?void 0:L.find(H=>H.courtId===$)),k=q==null?void 0:q.courtName;for(const H of E||[]){if(!r)break;H.venueId&&!x[H.venueid]&&(x[H.venueId]=(u=tu({venueId:H.venueId,tournamentRecord:r}))==null?void 0:u.venueData);const Q=x[H.venueId];H.venueName=Q==null?void 0:Q.venueName;const K=(d=Q==null?void 0:Q.courtsInfo)==null?void 0:d.find(Y=>Y.courtId===H.courtId);H.courtName=K==null?void 0:K.courtName}g=_e({typeChangeTimeAfterRecovery:R,timeAfterRecovery:M,scheduledDate:N,scheduledTime:b,isoDateString:G,allocatedCourts:E,timeModifiers:A,venueAbbreviation:V,venueName:j,venueId:w,courtOrder:U,courtName:k,courtId:$,typeChangeRecoveryMinutes:F,recoveryMinutes:D,averageMinutes:C,milliseconds:p,startTime:f,endTime:m,time:v})}else g=_e({time:v,startTime:f,endTime:m,milliseconds:p});const P=Lt.includes(s.matchUpStatus),{scheduledDate:O}=mi({matchUp:s}),{scheduledTime:y}=Sf({matchUp:s}),S=P&&(Ce(m)||Ce(O)||Ce(y))||void 0;return{schedule:g,endDate:S}}var dk=Object.defineProperty,dP=Object.getOwnPropertySymbols,pk=Object.prototype.hasOwnProperty,fk=Object.prototype.propertyIsEnumerable,pP=(t,e,r)=>e in t?dk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vk=(t,e)=>{for(var r in e||(e={}))pk.call(e,r)&&pP(t,r,e[r]);if(dP)for(var r of dP(e))fk.call(e,r)&&pP(t,r,e[r]);return t};function nu({collectionPosition:t,collectionId:e,lineUp:r}){let n=[];const o=[];if(r){const i=a=>a===void 0?-1:a,s=r.map(a=>{const{collectionAssignments:c,participantId:l}=a,u=c==null?void 0:c.find(d=>d.collectionPosition===t&&d.collectionId===e);return u&&vk({participantId:l},u)}).filter(Boolean).sort((a,c)=>i(a.substitutionOrder)-i(c.substitutionOrder));for(const a of s){const{participantId:c,previousParticipantId:l,substitutionOrder:u}=a;n.includes(c)||(l&&o.push({previousParticipantId:l,substitutionOrder:u,participantId:c}),n=n.filter(d=>d!==l),n.push(c))}}return{assignedParticipantIds:n,substitutions:o}}var Zs=(t=>(t.Group="GROUP",t.Individual="INDIVIDUAL",t.Pair="PAIR",t.Team="TEAM",t))(Zs||{});const _c="SIGN_IN_STATUS",Me=Zs.Individual,dr=Zs.Group,we=Zs.Pair,Ye=Zs.Team,An=Zs.Team,Ic="SIGNED_IN",mk="SIGNED_OUT",Pc={TEAM_PARTICIPANT:An,INDIVIDUAL:Me,GROUP:dr,TEAM:Ye,PAIR:we};var gk=Object.defineProperty,fP=Object.getOwnPropertySymbols,hk=Object.prototype.hasOwnProperty,_k=Object.prototype.propertyIsEnumerable,vP=(t,e,r)=>e in t?gk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ik=(t,e)=>{for(var r in e||(e={}))hk.call(e,r)&&vP(t,r,e[r]);if(fP)for(var r of fP(e))_k.call(e,r)&&vP(t,r,e[r]);return t};function Un({tournamentParticipants:t,tournamentRecord:e,participantIds:r}){const n="getPairedParticipant";if(!t&&!e)return{error:ee};if(!Array.isArray(r)||r.length>2)return{error:Qr};if(!r.length)return W({result:{error:lo},stack:n});t=t||(e==null?void 0:e.participants)||[];const o=t.filter(a=>a.participantType===we&&jt(r,a.individualParticipantIds).length===r.length&&a.individualParticipantIds.length===r.length),i=o[0];if(!i)return W({result:{error:wt},stack:n});const s=ue(o.slice(1),!1,!0);return Ik({participant:ue(i),duplicatedPairParticipants:s},B)}function yc({drawDefinition:t,participantId:e}){if(typeof t!="object")return{error:pe};if(typeof e!="string")return{error:yt};const{extension:r}=Vt({element:t,name:bn});return{lineUp:((r==null?void 0:r.value)||{})[e]}}function Pk({tournamentParticipants:t,positionAssignments:e,collectionPosition:r,drawPositions:n=[],drawDefinition:o,participantMap:i,collectionId:s,sideLineUps:a,matchUpType:c}){if(!s||!r)return;const l=(n==null?void 0:n.map(u=>{var d,p,v,f,m,g;const h=(d=e.find(S=>S.drawPosition===u))==null?void 0:d.participantId,_=a==null?void 0:a.find(S=>(S==null?void 0:S.drawPosition)===u),I=(_==null?void 0:_.teamParticipant)||((p=i==null?void 0:i[h])==null?void 0:p.participant)||(t==null?void 0:t.find(({participantId:S})=>S===h)),P=(_==null?void 0:_.lineUp)||((v=yc({participantId:h,drawDefinition:o}))==null?void 0:v.lineUp),{assignedParticipantIds:O,substitutions:y}=nu({collectionPosition:r,collectionId:s,lineUp:P});if(c===it){if((O==null?void 0:O.length)<=2){const S=(m=(f=i==null?void 0:i[O[0]])==null?void 0:f.pairIdMap)==null?void 0:m[O[1]],E=S&&((g=i[S])==null?void 0:g.participant)||Un({participantIds:O,tournamentParticipants:t}).participant,b=E==null?void 0:E.participantId;return{[u]:{participantId:b,teamParticipant:I,substitutions:y}}}else if((O==null?void 0:O.length)>2)return{[u]:{teamParticipant:I,substitutions:y}}}else{const S=O==null?void 0:O[0];return S&&{[u]:{participantId:S,teamParticipant:I,substitutions:y}}}}).filter(Boolean))||{};return Object.assign({},...l)}function pr({matchUps:t=[],interpolate:e}){var r;if(!Array.isArray(t))return{error:Z};const n=t.reduce((p,v)=>!v.roundNumber||p.includes(v.roundNumber)?p:p.concat(parseInt(v.roundNumber)),[]).sort(Wt).map(p=>{const v=t.filter(h=>h.roundNumber===p),m=v.find(({matchUpType:h})=>h===He)?v.filter(({matchUpType:h})=>h===He):v,g=h=>h.sort((_,I)=>Wt(_.roundPosition,I.roundPosition));return{[p]:g(m)}}),o=t.reduce((p,v)=>(p[v.roundNumber]||(p[v.roundNumber]=_e({abbreviatedRoundName:v.abbreviatedRoundName,finishingRound:v.finishingRound,roundName:v.roundName})),p),{}),i=Object.assign({},...n);if(e){const p=Math.max(...Object.keys(i).map(f=>parseInt(f)).filter(f=>!isNaN(f))),v=(r=i[p])==null?void 0:r.length;if(v>1&&Vr(v)){const f=p+1,m=f+v/2;le(f,m).forEach((h,_)=>{i[h]=le(0,v/(2+_*2)).map(()=>({}))})}}let s=0;const a=Object.assign({},...Object.keys(i).map(p=>{var v,f,m;const g=(v=i[p])==null?void 0:v.length,h=(m=(f=i[p])==null?void 0:f.filter(I=>{var P;return!Lt.includes(I.matchUpStatus)&&!((P=I.score)!=null&&P.scoreStringSide1)}))==null?void 0:m.length,_=g&&g===h;return s=Math.max(s,g),{[p]:{matchUpsCount:g,inactiveCount:h,inactiveRound:_}}}));let c=0,l=0;const u=Object.keys(i).map(p=>parseInt(p)).filter(p=>!isNaN(p));return u.forEach(p=>{var v,f,m;const g=i[p].sort((_,I)=>_.roundPosition-I.roundPosition),h=g.map(_=>(_==null?void 0:_.drawPositions)||[]).flat();if(a[p].roundNumber=p,a[p].roundFactor=a[p].matchUpsCount?s/a[p].matchUpsCount:1,a[p].finishingRound=(v=o[p])==null?void 0:v.finishingRound,a[p].roundName=(f=o[p])==null?void 0:f.roundName,a[p].abbreviatedRoundName=(m=o[p])==null?void 0:m.abbreviatedRoundName,a[p].finishingPositionRange=i[p][0].finishingPositionRange,p===1||!a[p-1]){const _=h.sort(Wt),I=Rt(_,2);a[p].drawPositions=_,a[p].pairedDrawPositions=I}else{const _=a[p-1],I=_.drawPositions,P=_.matchUpsCount/a[p].matchUpsCount,O=Rt(I,P),y=g.map(S=>{const{roundPosition:T}=S,E=[].concat(...S.drawPositions||[],void 0,void 0).slice(0,2);if(!T)return E;const b=(E==null?void 0:E.filter(Boolean))||[];if(!(b!=null&&b.length))return[void 0,void 0];if(p<3&&(b==null?void 0:b.length)===2)return E==null?void 0:E.slice().sort(Wt);const N=jt(I,b).length!==(b==null?void 0:b.length);if(b!=null&&b.length&&N)return(b==null?void 0:b.length)===1?[b[0],void 0]:E==null?void 0:E.slice().sort(Wt);const w=(T-1)*2;return O.slice(w,w+2).map(U=>b==null?void 0:b.find(A=>U.includes(A)))});a[p].drawPositions=y==null?void 0:y.flat(),a[p].pairedDrawPositions=y}a[p+1]&&a[p+1].matchUpsCount===a[p].matchUpsCount&&(a[p+1].feedRound=!0,a[p+1].feedRoundIndex=l,a[p].preFeedRound=!0,l+=1),a[p]&&!a[p].feedRound&&(a[p].roundIndex=c,c+=1)}),{hasOddMatchUpsCount:!!Object.values(a).find(({matchUpsCount:p})=>!Vr(p)),maxMatchUpsCount:s,roundMatchUps:i,roundNumbers:u,roundProfile:a}}function mP({matchUp:t={}}={}){var e;let r=t.matchUpType;if(!r&&((e=t.sides)!=null&&e.length)){const n=t.sides.find(({participant:s})=>s),o=n==null?void 0:n.participant,i=o==null?void 0:o.participantType;r=i===Me&&pt||i===we&&it||i===Ye&&Ye||void 0}return{matchUpType:r}}function Kt({drawDefinition:t,structure:e}){const r={},n=[];return((t==null?void 0:t.structures)||[e]).filter(o=>o&&typeof o=="object").forEach(o=>{const{structureId:i,matchUps:s,structures:a}=o,c=Array.isArray(a);if(c)c&&a.forEach(l=>{const{structureName:u}=l,d=l.matchUps;r[l.structureId]={matchUps:d,structureName:u},n.push(...d),d.forEach(p=>{p.tieMatchUps&&n.push(...p.tieMatchUps)}),r[i]||(r[i]={}),r[i].itemStructureIds||(r[i].itemStructureIds=[]),r[i].itemStructureIds.push(l.structureId)});else{const l=s;r[i]={matchUps:l},l.forEach(u=>{n.push(u),u.tieMatchUps&&n.push(...u.tieMatchUps)})}}),{mappedMatchUps:r,drawMatchUps:n}}function gi({mappedMatchUps:t,matchUpsMap:e,structureId:r,inContext:n}){t=(e==null?void 0:e.mappedMatchUps)||t;let o=t[r];const i=((o==null?void 0:o.itemStructureIds)||[]).map(s=>{const{matchUps:a,structureName:c}=t[s];return n?a.map(l=>Object.assign(ue(l,!0,!0),{containerStructureId:r,structureId:s,structureName:c})):a}).flat();return((o==null?void 0:o.matchUps)||[]).concat(...i)}function Sc({drawDefinition:t,attributes:e}){let{extension:r}=Kl({name:Yl,drawDefinition:t});const n=(r==null?void 0:r.value)||t.entryProfile||{};return e.forEach(o=>{Object.keys(o).forEach(i=>{n[i]?Object.assign(n[i],o[i]):n[i]=o[i]})}),r={name:Yl,value:n},pf({drawDefinition:t,extension:r}),{entryProfile:n}}function Oc({drawDefinition:t}){let{extension:e}=Kl({name:Yl,drawDefinition:t});return{entryProfile:(e==null?void 0:e.value)||t.entryProfile||{}}}const de="MAIN",Ie="QUALIFYING",$t="CONSOLATION",Ct="VOLUNTARY_CONSOLATION",st="PLAY_OFF",Tf=[de,Ie,$t,st,Ct],ts={[Ie]:1,[de]:2,[st]:3,[$t]:3,[Ct]:4},gP="finishingPositions",hP="aggregateEventStructures",_P={[de]:1,[st]:2,[$t]:3,[Ie]:4,[Ct]:5},yk={[st]:1,[de]:2,[$t]:3,[Ie]:4,[Ct]:5},Ef="CLUSTER",Sk="SEPARATE",wf="WATERFALL",ou="ITEM",tr="CONTAINER",an="DRAW",IP="RANDOM",Cn="TOP_DOWN",rs="BOTTOM_UP",ho="POSITION",_o="WINNER",qn="LOSER",Yn="FIRST_MATCHUP",cn="AD_HOC",Xs="FEED_IN",ea="COMPASS",ta="OLYMPIC",Ok="SINGLE_ELIMINATION",zn="SINGLE_ELIMINATION",bc="DOUBLE_ELIMINATION",ra="FIRST_MATCH_LOSER_CONSOLATION",Tc="FIRST_ROUND_LOSER_CONSOLATION",hi="LUCKY_DRAW",iu="CURTIS_CONSOLATION",bk="CURTIS_CONSOLATION",$f="FEED_IN_CHAMPIONSHIP_TO_SF",Ec="FEED_IN_CHAMPIONSHIP_TO_SF",Nf="FEED_IN_CHAMPIONSHIP_TO_QF",wc="FEED_IN_CHAMPIONSHIP_TO_QF",Af="FEED_IN_CHAMPIONSHIP_TO_R16",$c="FEED_IN_CHAMPIONSHIP_TO_R16",PP="MODIFIED_FEED_IN_CHAMPIONSHIP",Nc="MODIFIED_FEED_IN_CHAMPIONSHIP",Ac="FEED_IN_CHAMPIONSHIP",ln="ROUND_ROBIN",Io="ROUND_ROBIN_WITH_PLAYOFF",yP="DECIDER",SP="BACKDRAW",Uf={0:{name:"EAST",abbreviation:"E"},"0-1":{name:"WEST",abbreviation:"W"},"0-2":{name:"NORTH",abbreviation:"N"},"0-3":{name:"NORTHEAST",abbreviation:"NE"},"0-1-1":{name:"SOUTH",abbreviation:"S"},"0-1-2":{name:"SOUTHWEST",abbreviation:"SW"},"0-2-1":{name:"NORTHWEST",abbreviation:"NW"},"0-1-1-1":{name:"SOUTHEAST",abbreviation:"SE"}},Cf={0:{name:"EAST",abbreviation:"E"},"0-1":{name:"WEST",abbreviation:"W"},"0-2":{name:"NORTH",abbreviation:"N"},"0-1-1":{name:"SOUTH",abbreviation:"S"}},na="WIN_RATIO",_i="ROUND_OUTCOME",OP=[ea,iu,wc,$c,Ec,Ac,Nf,Af,$f,ra,Tc,hi,Nc,ta,st,Io],Tk={MAIN:de,QUALIFYING:Ie,CONSOLATION:$t,ITEM:ou,CONTAINER:tr,FIRST_MATCHUP:Yn,WINNER:_o,LOSER:qn,AD_HOC:cn,FEED_IN:Xs,COMPASS:ea,PLAY_OFF:st,OLYMPIC:ta,KNOCKOUT:Ok,SINGLE_ELIMINATION:zn,DOUBLE_ELIMINATION:bc,CURTIS:iu,FICSF:$f,FICQF:Nf,FICR16:Af,MFIC:PP,VOLUNTARY_CONSOLATION:Ct,FIRST_MATCH_LOSER_CONSOLATION:ra,FIRST_ROUND_LOSER_CONSOLATION:Tc,MODIFIED_FEED_IN_CHAMPIONSHIP:Nc,FEED_IN_CHAMPIONSHIP_TO_R16:$c,FEED_IN_CHAMPIONSHIP_TO_QF:wc,FEED_IN_CHAMPIONSHIP_TO_SF:Ec,FEED_IN_CHAMPIONSHIP:Ac,LUCKY_DRAW:hi,ROUND_ROBIN_WITH_PLAYOFF:Io,ROUND_ROBIN:ln,DECIDER:yP,BACKDRAW:SP,COMPASS_ATTRIBUTES:Uf,OLYMPIC_ATTRIBUTES:Cf,DRAW:an,RANDOM:IP,TOP_DOWN:Cn,BOTTOM_UP:rs,WATERFALL:wf,WIN_RATIO:na,ROUND_OUTCOME:_i,MULTI_STRUCTURE_DRAWS:OP,generatedDrawTypes:[cn,ea,iu,bc,wc,$c,Ec,Ac,Xs,ra,Tc,hi,Nc,ta,st,ln,Io,zn],stageOrder:ts,finishOrder:_P,AGGREGATE_EVENT_STRUCTURES:hP,FINISHING_POSITIONS:gP};function Ii(t,e,r={}){var n,o;const i=v=>{var f,m;return(m=(f=Vt({element:v,name:Tn}))==null?void 0:f.extension)==null?void 0:m.value},s=r==null?void 0:r.deprioritizeCompleted,a=(r==null?void 0:r.mode)===hP&&yk,c=(r==null?void 0:r.mode)===gP&&_P,l=c||a||ts,u=v=>(v==null?void 0:v.stage)===de&&(v==null?void 0:v.stageSequence)===1,d=v=>u(v)?-1:l[v==null?void 0:v.stage],p=v=>v==null?void 0:v.matchUps.every(({matchUpStatus:f})=>Lt.includes(f)?1:-1);return s&&p(t)-p(e)||a&&d(t)-d(e)||(l[t==null?void 0:t.stage]||0)-(l[e==null?void 0:e.stage]||0)||(i(t)||0)-(i(e)||0)||!c&&!a&&(((n=e==null?void 0:e.positionAssignments)==null?void 0:n.length)||1/0)-(((o=t==null?void 0:t.positionAssignments)==null?void 0:o.length)||1/0)||((t==null?void 0:t.stageSequence)||0)-((e==null?void 0:e.stageSequence)||0)||(bP(t)||0)-(bP(e)||0)}function bP(t){return((t==null?void 0:t.matchUps)||[]).reduce((e,r)=>{var n;const o=(((n=r.finishingPositionRange)==null?void 0:n.winner)||[]).reduce((i,s)=>i+s,0);return!e||o<e?o:e},void 0)}function Te({drawDefinition:t,structureId:e}){if(!t)return{error:pe};if(!e)return{error:ar};const{structures:r}=Cr({drawDefinition:t}),n=r.map(s=>s.structures?[].concat(...s.structures,s):s).flat(),o=n.find(s=>s.structureId===e);if(!o)return{error:Br};const i=o.structureType===ou&&n.find(s=>{var a;return(a=s.structures)==null?void 0:a.some(c=>c.structureId===e)});return{structure:o,containingStructure:i}}function Cr({withStageGrouping:t,drawDefinition:e,stageSequences:r,stageSequence:n,roundTarget:o,sortConfig:i,stages:s,stage:a}){var c;const l=!e&&pe||!e.structures&&mF||void 0;if(l)return W({result:{error:l},stack:"getDrawStructure"});const u=m=>{var g,h;const _=(h=(g=Vt({element:m,name:Tn}))==null?void 0:g.extension)==null?void 0:h.value;return!o||o===_},d=(c=e.structures)==null?void 0:c.filter(v).filter(f).filter(u).sort((m,g)=>Ii(m,g,i)),p=t&&Object.assign({},...Tf.map(m=>{const g=d.filter(h=>h.stage===m);return g.length&&{[m]:g}}).filter(Boolean));return{structures:d,stageStructures:p};function v(m){return!a&&!Array.isArray(s)||a&&m.stage===a||Array.isArray(s)&&s.includes(m.stage)}function f(m){return!n&&!Array.isArray(r)||n&&m.stageSequence===n||Array.isArray(r)&&r.includes(m.stageSequence)}}const un="ALTERNATE",su="CONFIRMED",Mr="DIRECT_ACCEPTANCE",Uc="FEED_IN",au="JUNIOR_EXEMPT",ko="LUCKY_LOSER",cu="ORGANISER_ACCEPTANCE",lu="QUALIFIER",Ek="REGISTERED",uu="SPECIAL_EXEMPT",qr="UNGROUPED",ns="UNPAIRED",oa="WILDCARD",Go="WITHDRAWN",Mf=[su,Mr,au,cu,uu],wk=[Uc,ko,lu],os=[su,Mr,Uc,au,cu,uu,oa],Wo=[su,Mr,Uc,au,ko,lu,cu,uu,oa],$k=[un,su,Mr,Uc,au,ko,cu,lu,Ek,uu,qr,ns,oa,Go],TP=Wo;function Cc({stage:t,drawDefinition:e}){const{entryProfile:r}=Oc({drawDefinition:e}),n=Object.keys(r).includes(t);if(!n&&Tf.includes(t)){const o=[{[t]:{drawSize:void 0,alternates:!0}}];return Sc({drawDefinition:e,attributes:o}),!0}return n}function Nk({stage:t,drawDefinition:e}){var r;const{entryProfile:n}=Oc({drawDefinition:e});return((r=n[t])==null?void 0:r.alternates)||0}function Ak({stage:t,drawDefinition:e}){var r;const{entryProfile:n}=Oc({drawDefinition:e});return((r=n[t])==null?void 0:r.wildcardsCount)||0}function du({stage:t,drawDefinition:e,entryStatus:r}){return e.entries.reduce((n,o)=>o.entryStage===t&&o.entryStatus===r?n+1:n,0)}function is({provisionalPositioning:t,drawDefinition:e,stageSequence:r,entryStatuses:n,structureId:o,roundTarget:i,stages:s,stage:a}){var c;const l=((c=e.entries)==null?void 0:c.reduce((u,d)=>{var p,v;const f=(v=(p=Vt({name:Tn,element:d}))==null?void 0:p.extension)==null?void 0:v.value,m=a&&d.entryStage===a||(s==null?void 0:s.length)&&s.includes(d.entryStage),g=!n||n.includes(d.entryStatus),h=d.entryStageSequence||1;return m&&(!r||h===r)&&g&&(!i||!f||i===f)?u.concat(d):u},[]))||[];if(o&&a===st){const{playoffEntries:u,error:d}=Uk({provisionalPositioning:t,drawDefinition:e,structureId:o});return d&&console.log("playoff entries error"),u!=null&&u.length?u:l}return l}function Uk({provisionalPositioning:t,drawDefinition:e,structureId:r}){const n=[],o=(e.links||[]).find(i=>i.linkType===ho&&i.target.structureId===r);if(o){const{finishingPositions:i,structureId:s}=o.source,{structure:a}=Te({drawDefinition:e,structureId:s});a.structureType===tr&&(a.structures||[]).forEach(l=>{const{positionAssignments:u}=l,{structureId:d}=l,p=d,v=Object.assign({},...u.map(h=>{var _;const{participantId:I}=h,P=(_=Vt({element:h,name:jo}).extension)==null?void 0:_.value;return P?{[I]:P}:void 0}).filter(Boolean)),m=Object.keys(v).reduce((h,_)=>{const I=v[_],P=I.groupOrder||t&&I.provisionalOrder;return h.includes(P)||h.push(P),h},[]).length===Object.keys(v).length,g=Object.keys(v).filter(h=>{const _=v[h],I=_.groupOrder||t&&_.provisionalOrder;return i.includes(I)});(!t||m)&&g.forEach(h=>{const _=v[h],{groupOrder:I,provisionalOrder:P,GEMscore:O}=_,y=I||t&&P,S=i.sort().indexOf(y)+1;n.push({entryStage:st,entryStatus:Uc,placementGroup:S,groupingValue:p,participantId:h,GEMscore:O})})})}return{playoffEntries:n}}function EP({stage:t,drawDefinition:e}){return os.reduce((r,n)=>(du({drawDefinition:e,entryStatus:n,stage:t})||0)+r,0)}function Ck({stage:t,drawDefinition:e}){return du({entryStatus:oa,drawDefinition:e,stage:t})}function dn({provisionalPositioning:t,drawDefinition:e,matchUpsMap:r,structureId:n,structure:o}){var i;let s,a=[];if(o||({structure:o,error:s}=Te({drawDefinition:e,structureId:n})),s||!o)return{seedAssignments:[],error:Br};n||(n=o.structureId);const{stage:c,stageSequence:l}=o,d=c===st&&e&&is({provisionalPositioning:t,drawDefinition:e,stageSequence:l,matchUpsMap:r,structureId:n,stage:c}),p=d?d.filter(f=>f.placementGroup===1).sort((f,m)=>f.GEMscore<m.GEMscore&&1||f.GEMscore>m.GEMscore&&-1||0).map((f,m)=>{const g=m+1;return{participantId:f.participantId,seedValue:g,seedNumber:g,seedProxy:!0}}):[];p.length?a=p:o.seedAssignments?a=o.seedAssignments:s=dF;const v=o.seedLimit||((i=o==null?void 0:o.positionAssignments)==null?void 0:i.length);return{seedAssignments:a,seedLimit:v,stage:c,stageSequence:l,error:s}}function Df({drawDefinition:t}){if(typeof t!="object")return{error:ji};const e={},{structures:r=[],links:n=[]}=t||{},o=r.reduce((s,a)=>{const{stage:c}=a;return s[c]?s[c].push(a):s[c]=[a],s},{});for(const s of Object.keys(o)){const a=o[s].find(({stageSequence:u})=>u===1);if(!a)continue;const{structureId:c}=a;i({aggregator:{},targetRound:0,exitProfiles:e,exitProfile:"0",structureId:c,stage:s})}return{exitProfiles:e};function i({exitProfiles:s,exitProfile:a,structureId:c,targetRound:l,aggregator:u,stage:d}){s[c]||(s[c]=[]),a==="0"&&[$t,st].includes(d)||s[c].push(a);const p=n.filter(v=>v.source.structureId===c&&v.source.roundNumber>=l);for(const v of p){const f=v.source.roundNumber,m=v.target.roundNumber,g=v.target.structureId,h=r.find(I=>I.structureId===g).stage,_=[h,g,m,f].join("|");if(u[_])return;u[_]=!0,i({exitProfile:`${a}-${f}`,structureId:g,exitProfiles:s,targetRound:m,aggregator:u,stage:h})}}}function wP({groupedOrder:t,roundPositionsCount:e}){if(!t||(t==null?void 0:t.length)<=e)return t;const n=Rt(t,t.length/e).map(i=>i.reduce((s,a)=>s+a)),o=n.slice().sort(Wt);return n.map(i=>o.indexOf(i)+1)}function pu(t){if(!Array.isArray(t))return"";const e=t.filter(Ot);return e.length?Ve([Math.min(...e),Math.max(...e)]).join("-"):""}function Mk({drawDefinition:t,structureId:e,matchUpsMap:r}){if(!t)return{error:pe};if(!e)return{error:ar};const{structure:n}=Te({drawDefinition:t,structureId:e});if(n.stage!==$t)return{error:No,info:"Structure is not CONSOLATION stage"};const{links:o}=t,i=(o==null?void 0:o.filter(d=>d.target.structureId===e))||[],s=(i==null?void 0:i.reduce((d,p)=>{const{structureId:v}=p.source;return d.includes(v)?d:d.concat(v)},[]))||[],a=Object.assign({},...s.map(d=>{const p=gi({matchUpsMap:r,structureId:d}),{roundProfile:v}=pr({matchUps:p});return{[d]:v}})),c=gi({matchUpsMap:r,structureId:e}),{roundProfile:l}=pr({matchUps:c}),u={};return i==null||i.forEach(d=>{var p;const{structureId:v,roundNumber:f}=d.source,{feedProfile:m,groupedOrder:g,positionInterleave:h,roundNumber:_}=d.target,I=a[v],P=(p=I[1])==null?void 0:p.drawPositions,O=I[f],y=O==null?void 0:O.matchUpsCount;if(!y)return;const S=y?P.length/y:0,T=P.length/S;let E=P.slice();const b=wP({roundPositionsCount:E.length,groupedOrder:g}),N=(b==null?void 0:b.length)||1;if(N<=T){const A=P.length/N,M=Rt(E,A);m===rs&&M.forEach(C=>C.reverse()),E=(b==null?void 0:b.length)&&(b==null?void 0:b.map(C=>M[C-1]).flat())||E}let w=Rt(E,S);if(!(b!=null&&b.length)&&m===rs&&w.reverse(),h){const A=le(0,h.interleave).map(()=>{}),M=le(0,h.offset).map(()=>{});w=w.map(D=>[D,...A]),w.unshift(M),w=w.flat(1);const C=w.length-h.offset;w=w.slice(0,C)}u[_]||(u[_]={});const $=l[_],U=$!=null&&$.feedRound?2:1;w.forEach((A,M)=>{const C=1+M*U;u[_][C]||(u[_][C]=pu(A))})}),{sourceDrawPositionRanges:u}}const jf=t=>e=>t[e],fu=(t=[])=>t.map(Mt).filter(Boolean),Kn=(t=[])=>t.map(Xe).filter(Boolean),Xe=(t={})=>jf(t)("participantId"),Dk=(t={})=>jf(t)("drawPosition"),Mt=(t={})=>jf(t)("matchUpId");function $P({drawDefinition:t}){if(!t)return{error:pe};const e={};return{allPositionedParticipantIds:(t.structures||[]).map(n=>{const o=n.stage;e[o]||(e[o]=[]);const{positionAssignments:i}=et({structure:n}),s=Kn(i);return e[o].push(...s),s}).flat(),stagePositionedParticipantIds:e}}function et({drawDefinition:t,structureId:e,structure:r}){let n,o=[];if(!r){if(!t)return{positionAssignments:o,error:pe};if({structure:r,error:n}=Te({drawDefinition:t,structureId:e}),n)return{positionAssignments:o,error:n}}return r.structures?o=[].concat(...r.structures.map(i=>et({structure:i}).positionAssignments)):r.positionAssignments?o=r.positionAssignments:n=PF,{positionAssignments:o,error:n}}function Et({drawDefinition:t,structureId:e,structure:r}){const{positionAssignments:n}=et({drawDefinition:t,structureId:e,structure:r}),o=n.filter(l=>l.participantId||l.bye||l.qualifier),i=n.length===o.length,s=n.filter(l=>!l.participantId&&!l.bye&&!l.qualifier),a=n.filter(l=>!l.participantId&&l.bye),c=n.filter(l=>!l.participantId&&l.qualifier);return{byePositions:a,assignedPositions:o,qualifierPositions:c,unassignedPositions:s,positionAssignments:n,allPositionsAssigned:i}}function jk({drawPositions:t,roundProfile:e,roundNumber:r}){const n=[void 0,void 0];if(tF(t))return{orderedDrawPositions:n,displayOrder:n};const o=e[r],i=o==null?void 0:o.pairedDrawPositions,s=(i==null?void 0:i.find(c=>Gt(c||[],t.filter(Boolean))))||n,a=o==null?void 0:o.feedRound;if(eF(t)){const c=t.sort(Wt);return{orderedDrawPositions:c.length===2?c:s,displayOrder:a?c:s}}if(a){const l=[t.find(u=>!isNaN(parseInt(u))),void 0];return{orderedDrawPositions:l,displayOrder:l}}return{orderedDrawPositions:s,displayOrder:s}}function Rk({drawDefinition:t,roundProfile:e,structureId:r,matchUpsMap:n}){var o;if(!t)return{error:pe};if(!r)return{error:ar};if(!e){const l=gi({matchUpsMap:n,structureId:r});({roundProfile:e}=pr({matchUps:l}))}const s=(Math.min(...((o=e[1])==null?void 0:o.drawPositions)||[])||1)-1,a=Object.keys(e);return{drawPositionsRanges:Object.assign({},...(a||[]).map(l=>{var u;const{matchUpsCount:d}=e[l],p=((u=e[1])==null?void 0:u.drawPositions)||[],v=Rt(p,p.length/d),f=v.map(pu),m=v.map(P=>P.map(O=>O-s)).map(pu),g=a.map(P=>{if(P>l)return;const{drawPositions:O}=e[P];return Rt(O,O.length/d)}).filter(Boolean),h=le(0,d).map(P=>g.map(O=>O[P]).flat().filter(Boolean).sort(Wt)).map(P=>Ve(P)),_=h.map(P=>XR(P).map(pu).join(", ")),I=Object.assign({},...le(0,d).map(P=>({[P+1]:{firstRoundDrawPositionsRange:f[P],firstRoundOffsetDrawPositionsRange:m[P],possibleDrawPositions:h[P],drawPositionsRange:_[P]}})));return{[l]:I}}))}}function Rf({matchUp:t}){let e,r=[],n=[],o=[],i=[];if(t||(e=$r),t&&!t.sides&&(e=Gr),t&&!t.hasContext&&(e=Ul),!e){r=t.sides.map(c=>c.participantId);const s=t.sides.filter(c=>c.participantType===Me).map(c=>c.participantId).filter(Boolean);i=t.sides.map(c=>{var l;return(l=c.participant)==null?void 0:l.individualParticipants}).filter(Boolean).map(c=>c.map(l=>l==null?void 0:l.participantId).filter(Boolean)),n=[].concat(...s,...i.flat()).filter(Boolean),o=Ve(n.concat(r)).filter(Boolean)}return{error:e,sideParticipantIds:r,individualParticipantIds:n,allRelevantParticipantIds:o,nestedIndividualParticipantIds:i}}function Mc({matchUp:t}){if(!t)return{error:$r};if(!t.hasContext)return{error:Ul};if(!t.sides||t.sides.filter(Boolean).length!==2)return{error:Gr};const{sideParticipantIds:e,nestedIndividualParticipantIds:r,allRelevantParticipantIds:n}=Rf({matchUp:t}),i=(t.timeItems||[]).filter(l=>[Pf,yf].includes(l==null?void 0:l.itemType)).sort((l,u)=>new Date(l.createdAt)-new Date(u.createdAt)),a=i.map(l=>l.itemValue).filter(l=>i.filter(u=>(u==null?void 0:u.itemValue)===l).reverse()[0].itemType===Pf);return r==null||r.forEach((l,u)=>{const d=e[u],p=(l==null?void 0:l.length)&&l.reduce((v,f)=>v&&f&&a.includes(f),!0);d&&p&&!a.includes(d)&&a.push(d)}),e.forEach((l,u)=>{a.includes(l)&&(r[u]||[]).forEach(d=>{d&&!a.includes(d)&&a.push(d)})}),{allParticipantsCheckedIn:e.reduce((l,u)=>a.includes(u)&&l,!0),checkedInParticipantIds:a,allRelevantParticipantIds:n}}function Fk({hasOddMatchUpsCount:t,drawDefinition:e,roundMatchUps:r,structure:n}){var o,i;if(!n)return!1;r||({hasOddMatchUpsCount:t,roundMatchUps:r}=pr({matchUps:n.matchUps||[]}));const s=!!((o=r==null?void 0:r[1])!=null&&o.find(({drawPositions:c})=>c)),a=!((i=r==null?void 0:r[2])!=null&&i.find(({drawPositions:c})=>c));return t&&!(n!=null&&n.structures)&&s&&a&&!(e!=null&&e.drawType&&e.drawType!==hi)}function Po({drawDefinition:t,structure:e}){var r;return e?!(e!=null&&e.structures)&&!(t!=null&&t.drawType&&t.drawType!==cn)&&!((r=e==null?void 0:e.matchUps)!=null&&r.find(({roundPosition:n})=>!!n)):!1}const NP={[Qp]:{policyName:"Round Naming Default",abbreviatedRoundNamingMap:{1:"F",2:"SF",4:"QF"},roundNamingMap:{1:"Final",2:"Semifinal",4:"Quarterfinal"},affixes:{roundNumber:"R",preFeedRound:"Q"},stageConstants:{[de]:"",[st]:"P",[Ie]:"Q",[$t]:"C"}}};function Lk({roundNamingPolicy:t,structure:e,matchUps:r}){const{hasOddMatchUpsCount:n,roundProfile:o,roundMatchUps:i}=pr({matchUps:r}),{structureAbbreviation:s,stage:a}=e,c=Po({structure:e}),l=Fk({hasOddMatchUpsCount:n,roundMatchUps:i,structure:e}),u=e.structures,d={},p=NP[Qp],v=(t==null?void 0:t.roundNamingMap)||p.roundNamingMap||{},f=(t==null?void 0:t.abbreviatedRoundNamingMap)||p.abbreviatedRoundNamingMap||{},m=(t==null?void 0:t.affixes)||p.affixes,g=a&&a!==de&&a[0],h=t==null?void 0:t.stageConstants,_=(h==null?void 0:h[a])||g;return u||c||l?Object.assign(d,...Object.keys(o).map(I=>{const P=`Round ${I}`,O=`R${I}`;return{[I]:{roundName:P,abbreviatedRoundName:O}}})):Object.assign(d,...Object.keys(o).map(I=>{const{matchUpsCount:P,preFeedRound:O}=o[I],y=P*2,S=v[P]||`${m.roundNumber}${y}`,T=O?`-${m.preFeedRound}`:"",E=`${S}${T}`,b=[_,s,E].filter(Boolean).join("-"),w=`${f[P]||`${m.roundNumber}${y}`}${T}`,$=[_,s,w].filter(Boolean).join("-");return{[I]:{abbreviatedRoundName:$,roundName:b}}})),{roundNamingProfile:d,roundProfile:o,roundMatchUps:i}}function ss(t){const{matchUps:e,isCollectionMatchUp:r,excludeMatchUpStatuses:n,matchUpStatuses:o,hasWinningSide:i,matchUpFormats:s,roundPositions:a,matchUpFormat:c,collectionIds:l,isMatchUpTie:u,roundNumbers:d,matchUpIds:p,roundNames:v,stageSequences:f,scheduledDates:m,scheduledDate:g,participantIds:h,processContext:_,tournamentIds:I,matchUpTypes:P,structureIds:O,readyToScore:y,courtIds:S,eventIds:T,venueIds:E,drawIds:b,stages:N,filterMatchUpIds:w=!0,filterMatchUpTypes:$=!0}=t,U=Array.isArray(h)?h.filter(Boolean):[],A=Array.isArray(o)?o.filter(Boolean):[],M=Array.isArray(n)?n.filter(Boolean):[],C=Array.isArray(N)?N.filter(Boolean):[],D=Array.isArray(f)?f.filter(Boolean):[],F=Array.isArray(l)?l.filter(Boolean):[],R=Array.isArray(v)?v.filter(Boolean):[],G=Array.isArray(d)?d.filter(Boolean):[],x=Array.isArray(a)?a.filter(Boolean):[],z=Array.isArray(p)&&w?p.filter(Boolean):[],j=Array.isArray(P)&&$?P.filter(Boolean):[],V=Array.isArray(S)?S.filter(Boolean):[],L=Array.isArray(E)?E.filter(Boolean):[],q=Array.isArray(s)&&s.filter(Boolean)||typeof c=="string"&&[c]||[],k=Array.isArray(m)&&m.filter(Boolean)||typeof g=="string"&&g.length&&[g]||[],H=Array.isArray(I)?I.filter(Boolean):[],Q=Array.isArray(T)?T.filter(Boolean):[],K=Array.isArray(b)?b.filter(Boolean):[],Y=Array.isArray(O)?O.filter(Boolean):[];return e.filter(J=>{var te;if(y&&J.matchUpType!==Zr&&!J.readyToScore||i&&![1,2].includes(J.winningSide)||u!==void 0&&(u&&!J.tieMatchUps||!u&&J.tieMatchUps)||r!==void 0&&(r&&!J.collectionId||!r&&J.collectionId)||C.length&&!C.includes(J.stage)||D.length&&!D.includes(J.stageSequence)||F.length&&!F.includes(J.collectionId)||R.length&&!R.includes(J.roundName)||G.length&&!d.includes(J.roundNumber)||x.length&&!a.includes(J.roundPosition)||A.length&&!A.includes(J.matchUpStatus)||M.length&&M.includes(J.matchUpStatus)||z.length&&!z.includes(J.matchUpId)||j.length&&!j.includes(J.matchUpType)||q.length&&!q.includes(J.matchUpFormat))return!1;if(k!=null&&k.length){const{scheduledTime:ne}=Sf({matchUp:J}),{scheduledDate:oe}=mi({matchUp:J}),ve=Ce(ne)||oe;if(!k.find(X=>kn(X,ve)))return!1}if(V.length){const{courtId:ne}=iP({matchUp:J}),{allocatedCourts:oe}=oP({matchUp:J}),se=oe==null?void 0:oe.map(({courtId:ve})=>ve);if(!S.filter(Boolean).includes(ne)||se!=null&&se.includes(ne))return!1}if(L.length){const{venueId:ne}=sP({matchUp:J});if(!E.filter(Boolean).includes(ne))return!1}if(_){if(H.length&&!H.includes(J.tournamentId)||Q.length&&!Q.includes(J.eventId)||K.length&&!K.includes(J.drawId)||Y.length&&!Y.includes(J.structureId))return!1;if(U.length){const ne=((te=J.sides)==null?void 0:te.map(({participantId:se})=>se).filter(Boolean))||[];if(!U.some(se=>ne.includes(se)))return!1}}return!0})}function Vk({drawPositionCollectionAssignment:t,positionAssignments:e,displaySideNumber:r,seedAssignments:n,drawPosition:o,isFeedRound:i,sideNumber:s}){var a,c,l,u;const d=e.find(h=>h.drawPosition===o),p=t?(a=t[o])==null?void 0:a.participantId:d==null?void 0:d.participantId,v=d?xk({displaySideNumber:r,seedAssignments:n,participantId:p,assignment:d,sideNumber:s}):{};i&&(s===1?Object.assign(v,{participantFed:!0}):Object.assign(v,{participantAdvanced:!0}));const f=(c=t==null?void 0:t[o])==null?void 0:c.teamParticipant,m=(l=t==null?void 0:t[o])==null?void 0:l.participant,g=(u=t==null?void 0:t[o])==null?void 0:u.substitutions;return m&&Object.assign(v,{participant:m}),g&&Object.assign(v,{substitutions:g}),f&&Object.assign(v,{teamParticipant:f}),v}function xk({displaySideNumber:t,seedAssignments:e,participantId:r,assignment:n,sideNumber:o}){const i={drawPosition:n.drawPosition,displaySideNumber:t,sideNumber:o};if(r){const s=Bk({seedAssignments:e,participantId:r});Object.assign(i,s,{participantId:r})}else n.bye&&Object.assign(i,{bye:!0});return n.qualifier&&Object.assign(i,{qualifier:!0}),i}function Bk({seedAssignments:t,participantId:e}){return t==null?void 0:t.find(r=>!r.seedProxy&&r.participantId===e)}const ia="ANY",ct="MALE",yo="MIXED",as="OTHER",mt="FEMALE",AP={ANY:ia,MALE:ct,FEMALE:mt,MIXED:yo,OTHER:as};var kk=Object.defineProperty,Gk=Object.defineProperties,Wk=Object.getOwnPropertyDescriptors,UP=Object.getOwnPropertySymbols,Hk=Object.prototype.hasOwnProperty,qk=Object.prototype.propertyIsEnumerable,CP=(t,e,r)=>e in t?kk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sa=(t,e)=>{for(var r in e||(e={}))Hk.call(e,r)&&CP(t,r,e[r]);if(UP)for(var r of UP(e))qk.call(e,r)&&CP(t,r,e[r]);return t},vu=(t,e)=>Gk(t,Wk(e));function ze({scheduleVisibilityFilters:t,tournamentAppliedPolicies:e,provisionalPositioning:r,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,seedAssignments:a,drawDefinition:c,contextFilters:l,contextProfile:u,contextContent:d,matchUpFilters:p,participantMap:v,scheduleTiming:f,exitProfiles:m,context:g={},matchUpsMap:h,structure:_,inContext:I,event:P}){var O,y,S,T,E;let b={},N={};if(n=n||(s==null?void 0:s.participants),!_)return{collectionPositionMatchUps:b,error:Rs,roundMatchUps:N,matchUps:[]};const w=Array.isArray(p==null?void 0:p.eventIds)?p.eventIds.filter(Boolean):[],$=Array.isArray(p==null?void 0:p.structureIds)?p.structureIds.filter(Boolean):[],U=Array.isArray(p==null?void 0:p.drawIds)?p.drawIds.filter(Boolean):[],A=!(g!=null&&g.eventId)||!w.length&&!((O=l==null?void 0:l.eventIds)!=null&&O.filter(Boolean).length)||w.includes(g.eventId)||((y=l==null?void 0:l.eventIds)==null?void 0:y.includes(g.eventId)),M=!$.length||$.includes(_.structureId),C=!c||!U.length||U.includes(c.drawId);if(!A||!M||!C)return{collectionPositionMatchUps:b,roundMatchUps:N,matchUps:[]};u&&!d&&(d=fo({tournamentRecord:s,contextProfile:u,drawDefinition:c}));const{appliedPolicies:D}=at({drawDefinition:c}),F=Object.assign({},e,D,i),R=(S=F==null?void 0:F.scoring)==null?void 0:S.structures,G=(R==null?void 0:R.stage)&&(R==null?void 0:R.stage[_.stage]),x=(G==null?void 0:G.stageSequence)&&G.stageSequence[_.stageSequence],z=((T=F==null?void 0:F.scoring)==null?void 0:T.requireAllPositionsAssigned)||(G==null?void 0:G.requireAllPositionsAssigned)||(x==null?void 0:x.requireAllPositionsAssigned);h||(h=Kt({drawDefinition:c,structure:_}));const{positionAssignments:j,allPositionsAssigned:V}=Et({structure:_}),L=!z||V,{seedAssignments:q}=dn({provisionalPositioning:r,drawDefinition:c,matchUpsMap:h,structure:_,event:P});a=a||q;const{roundOffset:k,structureId:H,structureName:Q,stage:K,stageSequence:Y}=_,{drawId:J,drawName:te,drawType:ne}=c||{};m=m||c&&Df({drawDefinition:c}).exitProfiles;const oe=m==null?void 0:m[H],se=(oe==null?void 0:oe.length)&&(oe[0].split("-").map(me=>parseInt(me)).reduce((me,Se)=>me+Se)||0),ve=!!_.structures;let X=gi({matchUpsMap:h,structureId:H,inContext:I});const ie=F==null?void 0:F[Qp],fe=Lk({roundNamingPolicy:ie,drawDefinition:c,structure:_,matchUps:X}),{roundNamingProfile:$e,roundProfile:re}=fe;if(N=fe.roundMatchUps,p&&(X=ss(vu(sa({matchUps:X},p),{filterMatchUpTypes:!1,filterMatchUpIds:!1}))),I){const{sourceDrawPositionRanges:me}=Mk({drawDefinition:c,matchUpsMap:h,structureId:H}),{drawPositionsRanges:Se}=Rk({drawDefinition:c,roundProfile:re,matchUpsMap:h,structureId:H});X=X.map(Pe=>ae({scheduleVisibilityFilters:t,sourceDrawPositionRanges:me,drawPositionsRanges:Se,roundNamingProfile:$e,initialRoundOfPlay:se,appliedPolicies:F,isRoundRobin:ve,roundProfile:re,matchUp:Pe,event:P})),(X==null?void 0:X.filter(Pe=>Array.isArray(Pe.tieMatchUps))).forEach(Pe=>{const Ae=Pe.tieMatchUps;X=X.concat(...Ae)}),l&&(X=ss(vu(sa({processContext:!0},l),{matchUps:X})))}else(X==null?void 0:X.filter(Se=>Array.isArray(Se.tieMatchUps))).forEach(Se=>{const ce=Se.tieMatchUps;X=X.concat(...ce)});return p&&(X=ss(vu(sa({matchUps:X},p),{filterMatchUpTypes:!1,filterMatchUpIds:!1}))),(p!=null&&p.matchUpTypes||p!=null&&p.matchUpIds)&&(X=ss({matchUpTypes:p.matchUpTypes,matchUpIds:p.matchUpIds,matchUps:X})),(p!=null&&p.matchUpTypes||p!=null&&p.matchUpIds||I)&&({roundMatchUps:N}=pr({matchUps:X})),(E=Xt({drawDefinition:c,structure:_,event:P}))!=null&&E.tieFormat&&({collectionPositionMatchUps:b}=YV({matchUps:X})),{matchUps:X,roundMatchUps:N,roundProfile:re,collectionPositionMatchUps:b};function ae({scheduleVisibilityFilters:me,sourceDrawPositionRanges:Se,additionalContext:ce={},drawPositionsRanges:Pe,roundNamingProfile:Ae,initialRoundOfPlay:ye,tieDrawPositions:Ue,appliedPolicies:be,isCollectionBye:ge,matchUpTieId:Ne,isRoundRobin:De,roundProfile:he,sideLineUps:ke,matchUp:je,event:Ze}){var ot,Ke,At,rr,Jt,To,io,Mi,Bj,kj,Gj,Wj,Hj,qj,Yj;const Lg=(ot=Xt({drawDefinition:c,structure:_,matchUp:je,event:Ze}))==null?void 0:ot.tieFormat,zj=Lg==null?void 0:Lg.collectionDefinitions,mn=je.collectionId&&(zj==null?void 0:zj.find(nr=>nr.collectionId===je.collectionId)),pp=je.collectionId?mn==null?void 0:mn.matchUpFormat:je.matchUpFormat||_.matchUpFormat||(c==null?void 0:c.matchUpFormat)||(Ze==null?void 0:Ze.matchUpFormat),Vg=je.matchUpType||(mn==null?void 0:mn.matchUpType)||_.matchUpType||(c==null?void 0:c.matchUpType)||(Ze==null?void 0:Ze.eventType)!==Tt&&(Ze==null?void 0:Ze.eventType),Pye=ge?qe:je.matchUpStatus,{schedule:yye,endDate:Sye}=bf({scheduleVisibilityFilters:me,afterRecoveryTimes:o,tournamentRecord:s,scheduleTiming:f,matchUpFormat:pp,matchUpType:Vg,matchUp:je,event:Ze}),Pl=Ue||je.drawPositions,{collectionPosition:Oye,collectionId:bye,roundPosition:xg}=je,Vn=je.roundNumber||ce.roundNumber,Tye=Pk({tournamentParticipants:n,positionAssignments:j,collectionPosition:Oye,drawDefinition:c,participantMap:v,drawPositions:Pl,collectionId:bye,sideLineUps:ke,matchUpType:Vg}),Kj=((Ke=Ae==null?void 0:Ae[Vn])==null?void 0:Ke.roundName)||ce.roundName,Qj=((At=Ae==null?void 0:Ae[Vn])==null?void 0:At.abbreviatedRoundName)||ce.abbreviatedRoundName,Eye=(rr=he==null?void 0:he[Vn])==null?void 0:rr.feedRound,wye=(Jt=he==null?void 0:he[Vn])==null?void 0:Jt.preFeedRound,$ye=(To=he==null?void 0:he[Vn])==null?void 0:To.roundFactor,Jj=Pe==null?void 0:Pe[Vn],Nye=Jj==null?void 0:Jj[xg],Zj=Se==null?void 0:Se[Vn],Aye=mn!=null&&mn.category?Object.assign({},(g==null?void 0:g.category)||{},mn.category):g==null?void 0:g.category,Uye=((io=je.processCodes)==null?void 0:io.length)&&je.processCodes||((Mi=mn==null?void 0:mn.processCodes)==null?void 0:Mi.length)&&(mn==null?void 0:mn.processCodes)||((Bj=_.processCodes)==null?void 0:Bj.length)&&_.processCodes||((kj=c==null?void 0:c.processCodes)==null?void 0:kj.length)&&(c==null?void 0:c.processCodes)||((Gj=Ze==null?void 0:Ze.processCodes)==null?void 0:Gj.length)&&(Ze==null?void 0:Ze.processCodes)||(s==null?void 0:s.processCodes),Cye=(u==null?void 0:u.withCompetitiveness)&&k_(vu(sa({},d),{matchUp:je})).competitiveness,Mye=je.finishingPositionRange||ce.finishingPositionRange,fp=nr=>_e(nr,void 0,!0),gt=Object.assign({},fp(g),fp({matchUpFormat:je.matchUpType===Tt?void 0:pp,tieFormat:je.matchUpType!==Tt?void 0:Lg,roundOfPlay:K!==Ie&&ut(ye)&&ye+(Vn||0),endDate:je.endDate||Sye,gender:mn==null?void 0:mn.gender,discipline:Ze==null?void 0:Ze.discipline,category:Aye,finishingPositionRange:Mye,abbreviatedRoundName:Qj,drawPositionsRange:Nye,competitiveness:Cye,structureName:Q,stageSequence:Y,drawPositions:Pl,matchUpStatus:Pye,processCodes:Uye,isRoundRobin:De,matchUpTieId:Ne,preFeedRound:wye,matchUpType:Vg,roundFactor:$ye,roundOffset:k,structureId:H,roundNumber:Vn,feedRound:Eye,roundName:Kj,drawName:te,drawType:ne,schedule:yye,drawId:J,stage:K}),ue(fp(je),!0,!0));if(pp&&((Wj=je.score)!=null&&Wj.scoreStringSide1)){const nr=_r(pp),{bestOf:Eo,finalSetFormat:Rr,setFormat:lt}=nr||{};(Rr!=null&&Rr.tiebreakSet||lt!=null&<.tiebreakSet||lt!=null&<.timed)&&(gt.score.sets=gt.score.sets.sort((Zt,vr)=>Zt.setNumber-vr.setNumber).map((Zt,vr)=>(vr+1===Eo?(Rr!=null&&Rr.tiebreakSet||Rr!=null&&Rr.timed)&&(Zt.tiebreakSet=!0):(lt!=null&<.tiebreakSet||lt!=null&<.timed)&&(Zt.tiebreakSet=!0),Zt)))}if(Array.isArray(Pl)){const{orderedDrawPositions:nr,displayOrder:Eo}=jk({drawPositions:Pl,roundPosition:xg,roundProfile:he,roundNumber:Vn}),Rr=(Hj=he[Vn])==null?void 0:Hj.feedRound,lt=Eo[0]!==nr[0],vr=nr.concat(void 0,void 0).slice(0,2).map((Fr,gn)=>{var Lr;const ei=gn+1,Bg=lt?3-ei:ei,vp=Vk({drawPositionCollectionAssignment:Tye,positionAssignments:j,displaySideNumber:Bg,seedAssignments:a,drawPosition:Fr,isFeedRound:Rr,sideNumber:ei}),jye=(Lr=je.sides)==null?void 0:Lr.find(Lye=>Lye.sideNumber===ei),Rye=(xg-1)*2+gn+1,Fye=Zj==null?void 0:Zj[Rye];return fp(sa(sa({sourceDrawPositionRange:Fye},jye),vp))});Object.assign(gt,ue({sides:vr},!0,!0))}if(n&>.sides){const nr=i==null?void 0:i[oc],Eo=lt=>{var Zt;const vr=(Zt=v==null?void 0:v[lt])==null?void 0:Zt.participant;return vr&&Dl({template:nr==null?void 0:nr.participant,source:vr})};if(gt.sides.filter(Boolean).forEach(lt=>{var Zt,vr,Fr;if(lt.participantId){const gn=ue(Eo(lt.participantId)||vo({policyDefinitions:be,participantId:lt.participantId,tournamentParticipants:n,internalUse:!0,contextProfile:u}),void 0,!0);if(gn){if(c!=null&&c.entries){const Lr=c.entries.find(ei=>ei.participantId===lt.participantId);Lr!=null&&Lr.entryStatus&&(gn.entryStatus=Lr.entryStatus),Lr!=null&&Lr.entryStage&&(gn.entryStage=Lr.entryStage)}Object.assign(lt,{participant:gn})}}if((vr=(Zt=lt==null?void 0:lt.participant)==null?void 0:Zt.individualParticipantIds)!=null&&vr.length&&!((Fr=lt.participant.individualParticipants)!=null&&Fr.length)){const gn=lt.participant.individualParticipantIds.map(Lr=>Eo(Lr)||vo({policyDefinitions:be,tournamentParticipants:n,internalUse:!0,contextProfile:u,participantId:Lr}));Object.assign(lt.participant,{individualParticipants:gn})}}),!gt.matchUpType){const{matchUpType:lt}=mP({matchUp:gt});lt&&Object.assign(gt,{matchUpType:lt})}if((u==null?void 0:u.inferGender)&&(!gt.gender||gt.gender===yo)&&((qj=gt.sides)==null?void 0:qj.length)===2&>.matchUpType!==Tt){const lt=gt.sides.map(Zt=>{var vr,Fr,gn,Lr;if(gt.matchUpType===pt)return(Fr=(vr=Zt.participant)==null?void 0:vr.person)==null?void 0:Fr.sex;if(((Lr=(gn=Zt.participant)==null?void 0:gn.individualParticipants)==null?void 0:Lr.length)===2){const ei=Ve(Zt.participant.individualParticipants.map(Bg=>{var vp;return(vp=Bg.person)==null?void 0:vp.sex})).filter(Boolean);if(ei.length===1)return ei[0]}});if(lt.filter(Boolean).length===2&&Ve(lt).length===1){const Zt=lt[0];gt.inferredGender=Zt}}}if(gt.tieMatchUps){const nr=gt.matchUpStatus===qe,Eo=(Yj=gt.sides)==null?void 0:Yj.map(({participant:Rr,drawPosition:lt,sideNumber:Zt,lineUp:vr})=>{const Fr=(Rr==null?void 0:Rr.participantType)===Tt&&Rr;return{teamParticipant:Fr&&_e({participantRoleResponsibilities:Fr.participantRoleResponsibilities,participantOtherName:Fr.participanOthertName,participantName:Fr.participantName,participantId:Fr.participantId,teamId:Fr.teamId}),drawPosition:lt,sideNumber:Zt,lineUp:vr}});gt.tieMatchUps=gt.tieMatchUps.map(Rr=>{const lt=gt.matchUpId,vr={finishingPositionRange:gt.finishingPositionRange,abbreviatedRoundName:Qj,roundNumber:Vn,roundName:Kj};return ae({tieDrawPositions:Pl,scheduleVisibilityFilters:me,sourceDrawPositionRanges:Se,sideLineUps:Eo,drawPositionsRanges:Pe,initialRoundOfPlay:ye,roundNamingProfile:Ae,additionalContext:vr,appliedPolicies:be,isCollectionBye:nr,matchUpTieId:lt,isRoundRobin:De,roundProfile:he,matchUp:Rr,event:Ze})})}const Xj=gt.sides&>.sides.filter(nr=>nr==null?void 0:nr.participantId).length===2,Dye=!gt.winningSide;if(Object.assign(gt,{readyToScore:L&&Xj&&Dye,hasContext:!0}),Xj){const{allParticipantsCheckedIn:nr,checkedInParticipantIds:Eo}=Mc({matchUp:gt});Object.assign(gt,{allParticipantsCheckedIn:nr,checkedInParticipantIds:Eo})}return Array.isArray(u==null?void 0:u.exclude)&&u.exclude.forEach(nr=>delete gt[nr]),gt}}function Yk(t){return Object.assign(t,{inContext:!0}),{matchUp:ue(nt(t).matchUp,!1,!0)}}function nt({tournamentParticipants:t,afterRecoveryTimes:e,contextContent:r,contextProfile:n,drawDefinition:o,matchUpsMap:i,matchUpId:s,inContext:a,context:c,event:l}){if(!o)return{error:pe};if(!s)return{error:Ut};if(typeof s!="string")return{error:Z};const{structures:u=[]}=Cr({drawDefinition:o});n&&!r&&(r=fo({contextProfile:n,drawDefinition:o}));for(const d of u){const{matchUps:p}=ze({tournamentParticipants:t,afterRecoveryTimes:e,contextContent:r,drawDefinition:o,contextProfile:n,matchUpsMap:i,inContext:a,structure:d,context:c,event:l}),{matchUp:v}=R_({matchUps:p,matchUpId:s});if(v)return{matchUp:v,structure:d}}return{error:kr}}var zk=Object.defineProperty,Kk=Object.defineProperties,Qk=Object.getOwnPropertyDescriptors,MP=Object.getOwnPropertySymbols,Jk=Object.prototype.hasOwnProperty,Zk=Object.prototype.propertyIsEnumerable,DP=(t,e,r)=>e in t?zk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xk=(t,e)=>{for(var r in e||(e={}))Jk.call(e,r)&&DP(t,r,e[r]);if(MP)for(var r of MP(e))Zk.call(e,r)&&DP(t,r,e[r]);return t},eG=(t,e)=>Kk(t,Qk(e));function jP({collectionGroups:t=[]}={}){const e=Object.assign({},...t.filter(n=>(n==null?void 0:n.groupValue)&&(n==null?void 0:n.groupNumber)).map(n=>({[n.groupNumber]:eG(Xk({},n),{allGroupMatchUpsCompleted:!0,matchUpsCount:0,sideWins:[0,0],values:[0,0]})}))),r=Object.keys(e).map(n=>parseInt(n));return{groupValueGroups:e,groupValueNumbers:r}}function Dc({sideAdjustments:t=[0,0],separator:e="-",drawDefinition:r,matchUpsMap:n,structure:o,tieFormat:i,matchUp:s,event:a}){var c,l,u;if(!Array.isArray(t)||t.length!==2||isNaN(t.reduce((y,S)=>y+S)))return{error:Z};if(!s)return{error:$r};if(i=((c=Xt({matchUp:s,drawDefinition:r,structure:o,event:a}))==null?void 0:c.tieFormat)||i,!i)return{error:$l};const d=ur({tieFormat:i});if(d.error)return d;const p=(i==null?void 0:i.collectionDefinitions)||[],v=(s==null?void 0:s.tieMatchUps)||[],f=[0,0],{groupValueGroups:m,groupValueNumbers:g}=jP(i);for(const y of p)LV({collectionDefinition:y,groupValueNumbers:g,groupValueGroups:m,sideTieValues:f,tieMatchUps:v});for(const y of g){const S=m[y];let{allGroupMatchUpsCompleted:T,groupValue:E,matchUpCount:b,sideWins:N,winCriteria:w,values:$}=S,U;if(w!=null&&w.aggregateValue)T&&$[0]!==$[1]&&(U=$[0]>$[1]?1:2);else if(w!=null&&w.valueGoal)U=$.reduce((A,M,C)=>M>=w.valueGoal?C+1:A,void 0);else{const A=Math.floor(b/2)+1;U=N.reduce((M,C,D)=>C>=A?D+1:M,void 0)}U&&(f[U-1]+=E)}const h=f.map((y,S)=>y+t[S]),_={side1Score:h[0],side2Score:h[1]},I=h.join(e),P=h.slice().reverse().join(e);let O;if(i!=null&&i.winCriteria){const{valueGoal:y,aggregateValue:S,tallyDirectives:T}=i.winCriteria;if(y){const E=h.map((b,N)=>({sideNumber:N+1,points:b})).find(({points:b})=>b>=y);O=E==null?void 0:E.sideNumber}else S&&v.every(b=>Lt.includes(b.matchUpStatus)||b.winningSide)&&h[0]!==h[1]&&(O=h[0]>h[1]?1:2);if(!O&&T){const E=s.matchUpId,b=s.hasContext?s:(n==null?void 0:n.matchUpId)||((l=nt({inContext:!0,drawDefinition:r,matchUpId:E}))==null?void 0:l.matchUp);if(b){const{completedTieMatchUps:N,order:w}=Zp({matchUps:[b]});if(N&&w.length){const $=w[0].participantId;O=(u=b.sides.find(({participantId:U})=>U===$))==null?void 0:u.sideNumber}}}}return O&&(_.winningSide=O),{scoreStringSide1:I,scoreStringSide2:P,winningSide:O,set:_}}function pn(t){return ue(t,!1,!0)}function Dt({matchUp:t,score:e}={}){var r,n;e=e||(t==null?void 0:t.score);const o=(r=e==null?void 0:e.sets)==null?void 0:r[0],{side1Score:i,side2Score:s,side1TiebreakScore:a,side2TiebreakScore:c,side1PointScore:l,side2PointScore:u}=o||{},d=i||s||a||c||l||u;return!!(((n=e==null?void 0:e.sets)==null?void 0:n.length)>1||d)}function jc({matchUpStatus:t}){return hV.includes(t)}function tG({matchUpStatus:t}){return p_.includes(t)}function Ff({matchUpStatus:t}){return _V.includes(t)}function Lf({matchUpStatus:t,winningSide:e,tieMatchUps:r,sides:n,score:o}){var i;const s=n==null?void 0:n.find(({participantId:l})=>l),a=(i=r==null?void 0:r.filter(Lf))==null?void 0:i.length;return Dt({score:o})||a||e&&s||tG({matchUpStatus:t})&&![Be,Ge,Xr].includes(t)}var rG=Object.defineProperty,RP=Object.getOwnPropertySymbols,nG=Object.prototype.hasOwnProperty,oG=Object.prototype.propertyIsEnumerable,FP=(t,e,r)=>e in t?rG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,LP=(t,e)=>{for(var r in e||(e={}))nG.call(e,r)&&FP(t,r,e[r]);if(RP)for(var r of RP(e))oG.call(e,r)&&FP(t,r,e[r]);return t};function Vf({element:t,notes:e}={}){return typeof t!="object"?{error:Z}:e?typeof e!="string"&&!(e!=null&&e.testing)?{error:Z}:(Object.assign(t,{notes:e}),LP({},B)):{error:Oe}}function iG({element:t}={}){return typeof t!="object"?{error:Z}:(t.notes&&delete t.notes,LP({},B))}function mu(t,e){var r;if(!t)return;let n=Date.now();n===new Date(t.updatedAt).getTime()&&(n+=1);const o=new Date(n).toISOString(),i=e==null?void 0:e.filter(Boolean);t.updatedAt=o,(r=t.structures)==null||r.filter(Boolean).forEach(s=>{(!(i!=null&&i.length)||i!=null&&i.includes(s.structureId))&&(s.updatedAt=o)})}function Pi({drawDefinition:t,tournamentId:e,matchUps:r,eventId:n}){t&&mu(t),xe({payload:{matchUps:r,tournamentId:e,eventId:n},topic:gf})}function yi({drawDefinition:t,tournamentId:e,matchUpIds:r,eventId:n,action:o}){t&&mu(t),xe({topic:$I,payload:{tournamentId:e,matchUpIds:r,eventId:n,action:o}});for(const i of r)Zh({key:i})}function Qe({drawDefinition:t,tournamentId:e,structureId:r,context:n,eventId:o,matchUp:i}){if(!i)return console.log($r),{error:$r};t&&Je({structureIds:[r],drawDefinition:t,tournamentId:e,eventId:o}),xe({topic:AI,payload:{matchUp:i,tournamentId:e,context:n},key:i.matchUpId})}function sG({tournamentId:t,inContextMatchUp:e}){if(!e)return{error:$r};xe({topic:hf,payload:{inContextMatchUp:e,tournamentId:t},key:e.matchUpId})}function Rc({tournamentId:t,eventId:e,drawDefinition:r}){if(!r)return console.log(pe),{error:pe};mu(r),xe({payload:{drawDefinition:r,tournamentId:t,eventId:e},topic:SI,key:r.drawId})}function aG({tournamentId:t,eventId:e,drawId:r}){xe({payload:{drawId:r,tournamentId:t,eventId:e},topic:wI,key:r}),Zh({key:r})}function Je({drawDefinition:t,tournamentId:e,structureIds:r,eventId:n}){if(!t)return{error:pe};mu(t,r),xe({payload:{tournamentId:e,eventId:n,drawDefinition:t},topic:NI,key:t.drawId})}function VP({drawDefinition:t,tournamentId:e,structure:r,eventId:n}){if(!t)return{error:pe};if(!r)return{error:Rs};const o=r.seedAssignments,i=r.structureId,s=t.drawId;xe({payload:{tournamentId:e,eventId:n,drawId:s,structureId:i,seedAssignments:o},topic:CI,key:t.drawId}),Je({sructureIds:[i],drawDefinition:t,tournamentId:e,eventId:n})}function Ho({drawDefinition:t,tournamentId:e,structure:r,event:n}){if(!t)return{error:pe};if(!r)return{error:Rs};const o=et({structure:r}),i=r.structureId,s=t.drawId,a=n==null?void 0:n.eventId;xe({topic:UI,payload:{positionAssignments:o,tournamentId:e,structureId:i,eventId:a,drawId:s},key:i}),Je({sructureIds:[i],drawDefinition:t,tournamentId:e,eventId:a})}const gu=t=>t==null?void 0:t.participantId;function cG({positionAssignments:t}){const e=(t||[]).filter(gu).map(i=>{const{extension:s}=Vt({element:i,name:Qs}),a=parseInt(s==null?void 0:s.value),c=!isNaN(a)&&a;return c&&{participantId:i.participantId,subOrder:c}}).filter(Boolean),r=e.map(({subOrder:i})=>i),n=mr(r);return{subOrderMap:Object.assign({},...e.filter(({subOrder:i})=>n[i]===1).map(({participantId:i,subOrder:s})=>({[i]:s})))}}var lG=Object.defineProperty,uG=Object.defineProperties,dG=Object.getOwnPropertyDescriptors,xP=Object.getOwnPropertySymbols,pG=Object.prototype.hasOwnProperty,fG=Object.prototype.propertyIsEnumerable,BP=(t,e,r)=>e in t?lG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vG=(t,e)=>{for(var r in e||(e={}))pG.call(e,r)&&BP(t,r,e[r]);if(xP)for(var r of xP(e))fG.call(e,r)&&BP(t,r,e[r]);return t},mG=(t,e)=>uG(t,dG(e));function kP({positionAssignments:t,tournamentRecord:e,drawDefinition:r,matchUpFormat:n,matchUps:o,event:i}){if(!Array.isArray(o))return{error:Z};if(!t)return{error:Z};const{policyDefinitions:s}=Hi({policyTypes:[w_],tournamentRecord:e,drawDefinition:r,event:i}),{subOrderMap:a}=cG({positionAssignments:t}),c=Zp({policyDefinitions:s,matchUpFormat:n,subOrderMap:a,matchUps:o});if(c.error)return c;const{participantResults:l,bracketComplete:u,report:d}=c,p=Object.keys(l);return t.forEach(v=>{const{participantId:f}=v;if(p.includes(f)){let m={value:l[f],name:jo};tt({element:v,extension:m}),l[f].ties||sn({element:v,name:Qs})}else sn({element:v,name:jo}),sn({element:v,name:Qs})}),Je({drawDefinition:r}),mG(vG({},B),{participantResults:l,bracketComplete:u,report:d})}function xf({participantsProfile:t,participants:e=[]}){const r=ue(e,t==null?void 0:t.convertExtensions,!0),n=r.filter(s=>s.participantType===Ye),o=r.filter(s=>s.participantType===dr),i=r.filter(s=>s.participantType===we);return r.forEach(s=>{if(s.participantType===Me){const{participantId:a}=s;s.groupParticipantIds=[],s.teamParticipantIds=[],s.pairParticipantIds=[],s.groups=[],s.teams=[],n.forEach(c=>{((c==null?void 0:c.individualParticipantIds)||[]).forEach(l=>{var u;l===a&&!((u=s.teamParticipantIds)!=null&&u.includes(c.participantId))&&(s.teamParticipantIds.push(c.participantId),s.teams.push({participantRoleResponsibilities:c.participantRoleResponsibilities,participantOtherName:c.participantOtherName,participantName:c.participantName,participantId:c.participantId,teamId:c.teamId}))})}),i.forEach(c=>{((c==null?void 0:c.individualParticipantIds)||[]).forEach(l=>{l===a&&!s.pairParticipantIds.includes(c.participantId)&&s.pairParticipantIds.push(c.participantId)})}),o.forEach(c=>{((c==null?void 0:c.individualParticipantIds)||[]).forEach(l=>{l===a&&!s.groupParticipantIds.includes(c.participantId)&&(s.groupParticipantIds.push(c.participantId),s.groups.push({participantRoleResponsibilities:c.participantRoleResponsibilities,participantOtherName:c.participantOtherName,participantName:c.participantName,participantId:c.participantId}))})})}}),r}function gG({structureMatchUps:t,matchUp:e}){const{roundNumber:r,roundPosition:n}=e,o=t.filter(s=>s.roundNumber===r&&!s.matchUpTieId),i=t.filter(s=>s.roundNumber===r+1&&!s.matchUpTieId);if(i.length){let s;return i.length===o.length?s=i.find(a=>a.roundPosition===n):i.length===o.length/2&&(s=i.find(a=>a.roundPosition===Math.ceil(n/2))),{matchUp:s}}return{message:"no progression found"}}function Bf({sourceRoundMatchUpCount:t,inContextDrawMatchUps:e,sourceRoundPosition:r,drawDefinition:n,targetLink:o}){var i;if(!o)return{error:hh};const{target:{structureId:s,feedProfile:a,groupedOrder:c,roundNumber:l,positionInterleave:u}}=o,{structure:d}=Te({drawDefinition:n,structureId:s}),{positionAssignments:p}=et({structure:d}),f=(e==null?void 0:e.filter(N=>N.structureId===d.structureId)).filter(N=>N.roundNumber===l&&!N.matchUpTieId),m=f.length,g=le(1,m+1),h=m/t;let _=Math.ceil(h*r),I=1-r%2;if(u!=null&&u.interleave&&h!==.5){const N=u.offset+(r-1)*u.interleave,w=r+N;_=Math.ceil(w/2),I=1-w%2}let P=g,O=g[_-1];const y=wP({groupedOrder:c,roundPositionsCount:g.length}),S=(y==null?void 0:y.length)||1;if(S<=g.length){const N=m/S,w=Rt(g,N);a===rs&&w.forEach($=>$.reverse()),P=(y==null?void 0:y.length)&&(y==null?void 0:y.map($=>w[$-1]).flat())||P}a===Cn?O=P[_-1]:a===rs?((!(y!=null&&y.length)||S>g.length)&&(_=f.length+1-_),O=P[_-1]):a===IP&&Ft()&&console.log(Gh,{feedProfile:a});const T=O&&f.reduce((N,w)=>w.roundPosition===O?w:N,void 0);let E;T!=null&&T.feedRound?(I=0,E=Math.min(...(T.drawPositions||[]).filter(Boolean))):E=((i=T==null?void 0:T.drawPositions)==null?void 0:i.length)===2&&(T==null?void 0:T.drawPositions[I]);const b=p.find(({drawPosition:N})=>N===E);if(b){const{extension:N}=Vt({element:b,name:Hl});if(N!=null&&N.value)return{disabledDrawPosition:E}}return{matchUp:T,targetDrawPosition:E,matchUpDrawPositionIndex:I}}function hG({drawDefinition:t,roundNumber:e,structureId:r}){if(!t)return{error:pe};if(!r)return{error:ar};const{links:n}=Fc({drawDefinition:t,structureId:r}),o=n.source.reduce((s,a)=>!a.source.roundNumber||a.source.roundNumber===e?s.concat(a):s,[]),i=n.target.reduce((s,a)=>!a.target.roundNumber||a.target.roundNumber===e?s.concat(a):s,[]);return{links:{source:o,target:i}}}function kf({finishingPositions:t,linkCondition:e,linkType:r,source:n}){var o;const i=n.find(s=>{var a,c;const l=!((a=s.source)!=null&&a.finishingPositions)||!t||Gt(t,(c=s.source)==null?void 0:c.finishingPositions);return e===s.linkCondition&&l&&s.linkType===r});return[_o,qn].includes(i==null?void 0:i.linkType)&&!((o=i==null?void 0:i.source)!=null&&o.roundNumber)?W({result:{error:Z},stack:"getTargetLink",context:i}):i}function Fc({drawDefinition:t,structureId:e,roundNumber:r}){return t?e?{links:(t.links||[]).filter(Boolean).reduce((i,s)=>{var a,c;return((a=s.source)==null?void 0:a.structureId)===e&&(!r||s.source.roundNumber===r)&&(i.source=i.source.concat(s)),((c=s.target)==null?void 0:c.structureId)===e&&(!r||s.target.roundNumber===r)&&(i.target=i.target.concat(s)),i},{source:[],target:[]})}:{error:ar}:{error:pe}}function sr({inContextDrawMatchUps:t=[],useTargetMatchUpIds:e,inContextMatchUp:r,drawDefinition:n,matchUpId:o}){let i=r;t.length&&!i&&(i=t.find(c=>c.matchUpId===o));const{structure:s}=Te({structureId:i.structureId,drawDefinition:n}),{finishingPosition:a}=s;return a===_i?_G({inContextDrawMatchUps:t,useTargetMatchUpIds:e,drawDefinition:n,structure:s,matchUp:i}):IG({drawDefinition:n,matchUp:i,structure:s})}function _G({inContextDrawMatchUps:t,useTargetMatchUpIds:e,drawDefinition:r,structure:n,matchUp:o}){var i,s,a;const{winnerMatchUpId:c,loserMatchUpId:l}=o,{links:u}=hG({roundNumber:o.roundNumber,structureId:n.structureId,drawDefinition:r}),d=u==null?void 0:u.source,p=kf({source:d,linkType:_o}),v=kf({linkCondition:Yn,linkType:qn,source:d});let f=kf({source:d,linkType:qn});const m=v&&f;f||(f=v);const g=(i=p==null?void 0:p.target)==null?void 0:i.feedProfile,h=(s=f==null?void 0:f.target)==null?void 0:s.feedProfile,_=(a=v==null?void 0:v.target)==null?void 0:a.feedProfile;let I,P,O,y,S,T,E,b,N,w;if(e&&(c||l)&&(E=c&&g!==an&&t.find(({matchUpId:A})=>A===c),y=l&&h!==an&&t.find(({matchUpId:A})=>A===l),E||y))return{matchUp:o,targetLinks:{loserTargetLink:f,winnerTargetLink:p},targetMatchUps:{loserMatchUp:y,winnerMatchUp:E}};const{roundPosition:$}=o;w=w||t.filter(A=>A.structureId===n.structureId);const U=w.reduce((A,M)=>M.roundNumber===o.roundNumber&&!M.matchUpTieId?A+1:A,0);return f&&!y&&h!==an&&({matchUpDrawPositionIndex:T,targetDrawPosition:S,matchUp:y}=Bf({targetLink:f,sourceRoundMatchUpCount:U,inContextDrawMatchUps:t,sourceRoundPosition:$,drawDefinition:r})),m&&_!==an&&({matchUpDrawPositionIndex:O,targetDrawPosition:P,matchUp:I}=Bf({targetLink:v,sourceRoundMatchUpCount:U,inContextDrawMatchUps:t,sourceRoundPosition:$,drawDefinition:r})),p&&!E&&g!==an&&({matchUpDrawPositionIndex:N,targetDrawPosition:b,matchUp:E}=Bf({targetLink:p,sourceRoundMatchUpCount:U,inContextDrawMatchUps:t,sourceRoundPosition:$,drawDefinition:r})),E||(w=w||t.filter(A=>A.structureId===n.structureId),{matchUp:E}=gG({structureMatchUps:w,matchUp:o})),_e({matchUp:o,targetLinks:{loserTargetLink:f,winnerTargetLink:p,byeTargetLink:v},targetMatchUps:{byeMatchUp:I,loserMatchUp:y,winnerMatchUp:E,byeTargetDrawPosition:P,loserTargetDrawPosition:S,winnerTargetDrawPosition:b,byeMatchUpDrawPositionIndex:O,loserMatchUpDrawPositionIndex:T,winnerMatchUpDrawPositionIndex:N},targetMatchUpIds:!!(c||l)})}function IG({matchUp:t}){return{matchUp:t,targetLinks:{loserTargetLink:void 0,winnerTargetLink:void 0},targetMatchUps:{loserMatchUp:void 0,winnerMatchUp:void 0}}}function PG({drawDefinition:t,inContextDrawMatchUps:e}){const r={};return e.forEach(n=>{var o,i,s,a,c;const{matchUpId:l,structureId:u,drawPositions:d=[]}=n,{structure:p}=Te({drawDefinition:t,structureId:u});if((p==null?void 0:p.finishingPosition)===na){const{roundNumber:v}=n,f=v&&parseInt(v)+1,m=p.matchUps||[],{roundMatchUps:g}=pr({matchUps:m});if(f&&g[f]){const h=d.sort().map((_,I)=>{const P=g[f].find(O=>{var y;return(y=O.drawPositions)==null?void 0:y.includes(_)});return{matchUpId:P==null?void 0:P.matchUpId,roundNumber:f,schedule:P==null?void 0:P.schedule,sideNumber:I+1,structureName:p.structureName}});Object.assign(n,{sidesTo:h})}}else{const v=sr({useTargetMatchUpIds:!0,inContextDrawMatchUps:e,inContextMatchUp:n,drawDefinition:t,matchUpId:l});let{winnerMatchUp:f,loserMatchUp:m}=v.targetMatchUps;!n.winnerMatchUpId&&f&&(n.winnerMatchUpId=f.matchUpId),!n.loserMatchUpId&&m&&(n.loserMatchUpId=m.matchUpId);const g=Gf({upcomingMatchUp:f});let h=Gf({upcomingMatchUp:m});if(n.matchUpStatus!==qe&&(m==null?void 0:m.matchUpStatus)===qe){const{matchUp:I}=GP({matchUp:m,drawDefinition:t,inContextDrawMatchUps:e})||{};h=I&&Gf({upcomingMatchUp:I})||h}const _=(o=n.schedule)==null?void 0:o.timeAfterRecovery;if(_&&((i=g==null?void 0:g.schedule)!=null&&i.scheduledTime&&Re(g.schedule.scheduledTime)<Re(_)&&(r[g.matchUpId]=n.matchUpId,g.schedule.scheduleConflict=n.matchUpId),(s=h==null?void 0:h.schedule)!=null&&s.scheduledTime&&Re(h.schedule.scheduledTime)<Re(_)&&(r[h.matchUpId]=n.matchUpId,h.schedule.scheduleConflict=n.matchUpId)),Object.assign(n,{winnerTo:g,loserTo:h}),(a=n.drawPositions)!=null&&a.filter(Boolean).length){const I=(c=v.targetLinks)==null?void 0:c.loserTargetLink,P=(I==null?void 0:I.linkCondition)===Yn,O=yG(n);if(O.length){const y=Kn(f==null?void 0:f.sides),S=Kn(m==null?void 0:m.sides),E=O.find(({participantId:w})=>y.includes(w))?[]:O,N=O.find(({participantId:w})=>S.includes(w))?[]:O;m&&P&&N.length<2&&N.push({bye:!0,tbd:!0}),E!=null&&E.length&&f&&(!v.targetMatchUpIds&&f&&(f=e.find(({matchUpId:w})=>w===f.matchUpId)),f.potentialParticipants||(f.potentialParticipants=[]),f.potentialParticipants.push(E)),N!=null&&N.length&&m&&(v.targetMatchUpIds||(f=e.find(({matchUpId:w})=>w===m.matchUpId)),m.potentialParticipants||(m.potentialParticipants=[]),m.potentialParticipants.push(N))}}}}),Object.keys(r).length&&e.forEach(n=>{Object.keys(r).includes(n.matchUpId)&&(n.schedule.scheduleConflict=r[n.matchUpId])}),{scheduleConflictMatchUpIds:r}}function yG(t){var e;return((e=t==null?void 0:t.sides)==null?void 0:e.map(({participant:r,participantId:n,qualifier:o})=>r||n&&{participantId:n}||o&&{qualifier:o}).filter(Boolean))||[]}function GP({matchUp:t,drawDefinition:e,inContextDrawMatchUps:r}){const{matchUpId:n,matchUpStatus:o,structureId:i}=t||{};if(!t||!i||(t==null?void 0:t.matchUpStatus)===vt)return{matchUp:t};if(o===qe){let s;if(t.winnerMatchUpId)s=r.find(({matchUpId:a})=>a===t.winnerMatchUpId);else{const a=sr({inContextDrawMatchUps:r,drawDefinition:e,matchUpId:n});({winnerMatchUp:s}=(a==null?void 0:a.targetMatchUps)||{})}return GP({matchUp:s,drawDefinition:e,inContextDrawMatchUps:r})}return{matchUp:void 0}}function Gf({upcomingMatchUp:t}={}){if(t)return(({matchUpId:e,structureId:r,schedule:n,roundNumber:o,roundPosition:i,structureName:s})=>({matchUpId:e,structureId:r,schedule:n,roundNumber:o,roundPosition:i,structureName:s}))(t)}function Lc({requireParticipants:t=!0,scheduleVisibilityFilters:e,tournamentAppliedPolicies:r,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,drawDefinition:a,matchUpFilters:c,contextFilters:l,contextProfile:u,contextContent:d,participantMap:p,scheduleTiming:v,exitProfiles:f,matchUpsMap:m,structureId:g,inContext:h,structure:_,context:I,event:P}){!_&&g&&({structure:_}=Te({drawDefinition:a,structureId:g}));const O=ze({tournamentAppliedPolicies:r,scheduleVisibilityFilters:e,tournamentParticipants:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:s,drawDefinition:a,matchUpFilters:c,contextFilters:l,contextProfile:u,contextContent:d,participantMap:p,scheduleTiming:v,exitProfiles:f,matchUpsMap:m,structure:_,inContext:h,context:I,event:P});if(O.error)return O;const{matchUps:y}=O,{assignedPositions:S}=Et({structure:_}),T=S.filter(A=>A.participantId).map(A=>A.drawPosition),E=[],b=[],N=[],w=[],$=[];let U;return y.filter(A=>{var M;const C=((M=c==null?void 0:c.matchUpTypes)==null?void 0:M.length)===1&&c.matchUpTypes[0]===He;return!(A.matchUpType!==He&&C)}).forEach(A=>{var M,C,D,F;if(A.matchUpStatus===yr){w.push(A);return}A.matchUpType===He&&(U=!0);const R=A.collectionId,G=R&&((M=A.sides)==null?void 0:M.every(k=>k.participantId)),x=!R&&((C=A.drawPositions)==null?void 0:C.filter(Boolean).length)===2,z=!R&&((D=A.drawPositions)==null?void 0:D.every(k=>T.includes(k))),j=S.filter(k=>k.bye).map(k=>k.drawPosition),V=!R&&((F=A.drawPositions)==null?void 0:F.find(k=>j.includes(k))),q=IV.includes(A.matchUpStatus)&&(G||x&&(!t||z));return V?E.push(A):Ws({matchUp:A})?$.push(A):q?N.push(A):b.push(A)}),{includesTeamMatchUps:U,abandonedMatchUps:w,completedMatchUps:$,upcomingMatchUps:N,pendingMatchUps:b,byeMatchUps:E,structure:_}}var SG=Object.defineProperty,OG=Object.defineProperties,bG=Object.getOwnPropertyDescriptors,WP=Object.getOwnPropertySymbols,TG=Object.prototype.hasOwnProperty,EG=Object.prototype.propertyIsEnumerable,HP=(t,e,r)=>e in t?SG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Wf=(t,e)=>{for(var r in e||(e={}))TG.call(e,r)&&HP(t,r,e[r]);if(WP)for(var r of WP(e))EG.call(e,r)&&HP(t,r,e[r]);return t},wG=(t,e)=>OG(t,bG(e));function Nt(t){const e="getAllDrawMatchUps";Object.assign(t,{requireParticipants:!1});const r=cs(t);if(r.error)return W({result:r,stack:e});const{abandonedMatchUps:n,completedMatchUps:o,upcomingMatchUps:i,pendingMatchUps:s,byeMatchUps:a,matchUpsMap:c}=r;return{matchUps:[].concat(...n,...o,...i,...s,...a),matchUpsMap:c}}function cs({scheduleVisibilityFilters:t,tournamentAppliedPolicies:e,tournamentParticipants:r,requireParticipants:n,participantsProfile:o,afterRecoveryTimes:i,includeByeMatchUps:s,policyDefinitions:a,tournamentRecord:c,contextContent:l,contextFilters:u,contextProfile:d,drawDefinition:p,matchUpFilters:v,scheduleTiming:f,participantMap:m,nextMatchUps:g,matchUpsMap:h,inContext:_,context:I,event:P}){if(!p)return{error:pe};let O=[],y=[],S=[],T=[],E=[];d&&!l&&(l=fo({policyDefinitions:a,tournamentRecord:c,contextProfile:d,event:P})),!(r!=null&&r.length)&&c&&(r=c==null?void 0:c.participants,(_||o!=null&&o.withGroupings)&&(r!=null&&r.length)&&(r=xf({participants:r,participantsProfile:o})));const{structures:b}=Cr({drawDefinition:p});h||(h=Kt({drawDefinition:p}));const N=p&&Df({drawDefinition:p}).exitProfiles;b.forEach(U=>{const{byeMatchUps:A=[],pendingMatchUps:M,upcomingMatchUps:C,completedMatchUps:D,abandonedMatchUps:F}=Lc({matchUpFilters:g?void 0:v,contextFilters:g?void 0:u,inContext:_||g||u,tournamentAppliedPolicies:e,scheduleVisibilityFilters:t,tournamentParticipants:r,requireParticipants:n,afterRecoveryTimes:i,includeByeMatchUps:s,policyDefinitions:a,tournamentRecord:c,contextProfile:d,contextContent:l,drawDefinition:p,participantMap:m,scheduleTiming:f,exitProfiles:N,matchUpsMap:h,structure:U,context:I,event:P});O=O.concat(...F),y=y.concat(...D),S=S.concat(...C),T=T.concat(...M),E=E.concat(...A)});const w=U=>(!v&&!g&&!u||(v&&(U=ss(Wf({matchUps:U},v))),u&&(U=ss(wG(Wf({matchUps:U},u),{processContext:!0})))),U),$=Wf({abandonedMatchUps:w(O),completedMatchUps:w(y),upcomingMatchUps:w(S),pendingMatchUps:w(T),byeMatchUps:w(E),matchUpsMap:h},B);if(g){const U=typeof g=="object"||{abandoned:!0,completed:!0,upcoming:!0,pending:!0,bye:!0},{abandoned:A,completed:M,upcoming:C,pending:D,bye:F}=U,R=[].concat(...A&&O||[],...M&&y||[],...C&&S||[],...D&&T||[],...F&&E||[]);PG({inContextDrawMatchUps:R,drawDefinition:p})}return $}const hu={matchUpStatus:vt,matchUpStatusCodes:[],score:{scoreStringSide1:"",scoreStringSide2:"",sets:void 0},matchUpFormat:void 0,winningSide:void 0};var $G=Object.defineProperty,qP=Object.getOwnPropertySymbols,NG=Object.prototype.hasOwnProperty,AG=Object.prototype.propertyIsEnumerable,YP=(t,e,r)=>e in t?$G(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zP=(t,e)=>{for(var r in e||(e={}))NG.call(e,r)&&YP(t,r,e[r]);if(qP)for(var r of qP(e))AG.call(e,r)&&YP(t,r,e[r]);return t};function Mn({matchUpStatusCodes:t,removeWinningSide:e,tournamentRecord:r,drawDefinition:n,matchUpFormat:o,matchUpStatus:i,removeScore:s,winningSide:a,matchUpId:c,matchUp:l,event:u,notes:d,score:p}){var v,f,m,g,h,_;const I="modifyMatchUpScore";let P;const O=l.matchUpType===He;O?c&&l.matchUpId!==c&&({matchUp:l,structure:P}=nt({drawDefinition:n,matchUpId:c,event:u})):l.matchUpId!==c&&console.log("!!!!!"),i&&[Ge,_t].includes(i)||s?Object.assign(l,zP({},hu)):p&&(l.score=p);const y=i&&(l==null?void 0:l.matchUpStatus)===Be&&i!==Be;i&&(l.matchUpStatus=i),o&&(l.matchUpFormat=o),t&&(l.matchUpStatusCodes=t),a&&(l.winningSide=a),e&&(l.winningSide=void 0),P||({structure:P}=nt({drawDefinition:n,matchUpId:c,event:u})),!l.winningSide&&Dt(l)&&!Lt.includes(i)&&![ks,li].includes(i)&&(l.matchUpStatus=Xr);let S;if(y&&((v=l==null?void 0:l.processCodes)!=null&&v.length)||i===Be){const w=(f=at({tournamentRecord:r,drawDefinition:n,structure:P,event:u}))==null?void 0:f.appliedPolicies;S=(g=(m=w==null?void 0:w[Ys])==null?void 0:m.processCodes)==null?void 0:g.incompleteAssignmentsOnDefault}if((P==null?void 0:P.structureType)===tr&&!l.collectionId){o=O?"SET1-S:T100":o||l.matchUpFormat||(P==null?void 0:P.matchUpFormat)||n.matchUpFormat||(u==null?void 0:u.matchUpFormat);const w=P.structures.find(M=>M==null?void 0:M.matchUps.find(C=>C.matchUpId===c)),$=O&&{matchUpTypes:[He]},{matchUps:U}=ze({afterRecoveryTimes:!1,structure:w,inContext:!0,matchUpFilters:$,event:u}),A=kP({positionAssignments:w.positionAssignments,tournamentRecord:r,drawDefinition:n,matchUpFormat:o,matchUps:U,event:u});if(A.error)return W({result:A,stack:I})}if(d){const w=Vf({element:l,notes:d});if(w.error)return W({result:w,stack:I})}const T=r==null?void 0:r.tournamentId,E=Pn().topics.includes(hf),b=(E||S)&&Kt({drawDefinition:n}),N=b&&((h=Nt({matchUpFilters:{matchUpIds:[c]},includeByeMatchUps:!0,nextMatchUps:!0,tournamentRecord:r,inContext:!0,drawDefinition:n,matchUpsMap:b}).matchUps)==null?void 0:h[0]);if(E&&N&&sG({tournamentId:T,inContextMatchUp:N}),Array.isArray(S)&&N&&!((_=N.sides)!=null&&_.every(({participantId:w})=>w)))if(i===Be)l.processCodes?l.processCodes.push(...S):l.processCodes=S;else for(const w of S||[]){const $=l.processCodes.lastIndexOf(w);l.processCodes.splice($,1)}return Qe({eventId:u==null?void 0:u.eventId,context:I,drawDefinition:n,tournamentId:T,matchUp:l}),zP({},B)}var UG=Object.defineProperty,CG=Object.defineProperties,MG=Object.getOwnPropertyDescriptors,KP=Object.getOwnPropertySymbols,DG=Object.prototype.hasOwnProperty,jG=Object.prototype.propertyIsEnumerable,QP=(t,e,r)=>e in t?UG(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Hf=(t,e)=>{for(var r in e||(e={}))DG.call(e,r)&&QP(t,r,e[r]);if(KP)for(var r of KP(e))jG.call(e,r)&&QP(t,r,e[r]);return t},JP=(t,e)=>CG(t,MG(e));function Qn({tournamentRecord:t,exitWhenNoValues:e,drawDefinition:r,matchUpStatus:n,removeScore:o,matchUpsMap:i,matchUpId:s,event:a}){var c,l;const u=nt({drawDefinition:r,event:a,matchUpId:s});if(u.error)return u;const{matchUp:d,structure:p}=u;if(!d.tieMatchUps)return{error:Gr};const{extension:v}=Or({name:zs,element:d});if(v!=null&&v.value)if(o)sn({element:d,name:zs});else return JP(Hf({},B),{score:d.score});const f=(c=Xt({drawDefinition:r,structure:p,matchUp:d,event:a}))==null?void 0:c.tieFormat;d.tieFormat=pn(f);const{winningSide:m,set:g,scoreStringSide1:h,scoreStringSide2:_}=Dc({drawDefinition:r,matchUpsMap:i,structure:p,matchUp:d,event:a}),I=(g==null?void 0:g.side1Score)||(g==null?void 0:g.side2Score);if(e&&!d.score&&!I)return Hf({},B);const P={scoreStringSide1:h,scoreStringSide2:_,sets:g?[g]:[]},O=[1,2].includes(m),y=O&&St||Lf({matchUpStatus:n||d.matchUpStatus,tieMatchUps:d.tieMatchUps,winningSide:d.winningSide,score:P})&&Xr||vt,S=d.winningSide&&!O,T=d.tieMatchUps.find(({score:b,winningSide:N,matchUpStatus:w})=>{var $;return(($=b==null?void 0:b.sets)==null?void 0:$.length)&&(b.sets[0].side1Score||b.sets[0].side2Score)||Lt.includes(w)||N});let E;if(d.tieFormat&&!O&&!T){const b=(l=Xt({drawDefinition:r,structure:p,event:a}))==null?void 0:l.tieFormat;b&&JSON.stringify(f)===JSON.stringify(b)&&(d.tieFormatId=void 0,d.tieFormat=void 0,E=!0)}return Mn({matchUpStatus:y,score:P,removeWinningSide:S,tournamentRecord:t,drawDefinition:r,removeScore:o,winningSide:m,matchUpId:s,matchUp:d,event:a}),JP(Hf({},B),{score:P,removeWinningSide:S,tieFormatRemoved:E,winningSide:m})}function Jn(t){const{winnerFirst:e=!0,addOutcomeString:r,reversed:n=!1,matchUpStatus:o,matchUpFormat:i,autoComplete:s,winningSide:a,sets:c}=t;if(!c)return{error:Oe,info:"missing sets"};const l=i&&_r(i),{bestOf:u,finalSetFormat:d,setFormat:p}=l||{},f=n||!(!e||!a||a===1),m=r?RG({matchUpStatus:o}):"",g=(c==null?void 0:c.sort(FG).map(h).filter(Boolean).join(" "))||"";if(!m)return g;if(a===2)return`${m} ${g}`;return`${g} ${m}`;function h(_){const P=u&&_.setNumber===u&&d?d:p,O=F=>Ot(F==null?void 0:F.side1Score)||Ot(F==null?void 0:F.side2Score),y=F=>Ot(F==null?void 0:F.side1TiebreakScore)||Ot(F==null?void 0:F.side2TiebreakScore),S=(P==null?void 0:P.tiebreakSet)||!O(_)&&y(_),{side1Score:T,side2Score:E,side1TiebreakScore:b,side2TiebreakScore:N}=_,w=b||(Ot(b)||s?0:""),$=N||(Ot(N)||s?0:"");if(S)return`[${(f?[$,w]:[w,$]).join("-")}]`;const U=Math.min(w,$),A=U?`(${U})`:"",M=T||(Ot(T)||s?0:""),C=E||(Ot(E)||s?0:"");let D=f?`${[C,M].join("-")}${A}`:`${[M,C].join("-")}${A}`;return["-"," "].includes(D)&&(D=""),D}}function RG({matchUpStatus:t}){const e={[er]:"RET",[Ge]:"WO",[bt]:"DF/DF",[_t]:"WO/WO",[li]:"SUS",[yr]:"ABN",[Be]:"DEF",[Gs]:"DR"};return t&&e[t]||""}function FG(t,e){return t.setNumber-e.setNumber}function LG({existingMatchUpStatus:t,matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}){const i=(o==null?void 0:o.sets)||[],a=((i==null?void 0:i.filter(y=>y==null?void 0:y.winningSide))||[]).reduce((y,S)=>{const{winningSide:T}=S,E=T-1;return y[E]++,y},[0,0]),c=n&&n-1,l=1-c,u=a[c],d=a[l],p=_r(e),v=Math.max(...a),f=mr(a)[v],{bestOf:m}=p||{},g=m&&Math.ceil(m/2)||1,h=r||t,_=[Be,er,Ge].includes(h),I=!p||!i.length||i.every((y,S)=>{const T=S+1,E=T===m,b=T===i.length,{side1Score:N,side2Score:w,side1TiebreakScore:$,side2TiebreakScore:U,winningSide:A}=y,M=Math.max(N||0,w||0),C=$||U,{finalSetFormat:D,setFormat:F}=p,R=E&&D||F;if(C){const{tiebreakTo:x,NoAD:z}=(R==null?void 0:R.tiebreakFormat)||{},j=Math.max($||0,U||0);if(z&&j>x||j<x&&A&&(b&&!_||!b))return!1}return R.setTo?!(!R.noTiebreak&&M>R.setTo+1):!0}),P=(!e||v===g)&&f===1&&a.indexOf(v)+1||void 0;return{valid:I&&(n&&u>d&&n===P||!n&&!P||_)}}function qf({existingMatchUpStatus:t,matchUpFormat:e,matchUpStatus:r,winningSide:n,score:o}){if(typeof o!="object")return{error:Z};const{sets:i,scoreStringSide1:s,scoreStringSide2:a}=o,c="scoreString must be a string!";if(s!==void 0&&typeof s!="string")return{error:Z,info:c};if(a!==void 0&&typeof a!="string")return{error:Z,info:c};if(i!==void 0&&!Array.isArray(i))return{error:Z,info:zt("sets")};if(i!=null&&i.length){const l=i.map(d=>d==null?void 0:d.setNumber).filter(Boolean);if(l.length!==Ve(l).length)return{error:Z,info:"setNumbers not unique"};for(const d of i){const{side1Score:p,side2Score:v,side1TiebreakScore:f,side2TiebreakScore:m,side1PointScore:g,side2PointScore:h,winningSide:_,setNumber:I}=d;if(![[p,v],[f,m],[g,h]].filter(y=>y.some(S=>S!==void 0)).every(y=>y.every(S=>ut(S))))return{error:Z,info:"non-numeric values"};if(![I,_].filter(y=>y!==void 0).every(y=>ut(y)))return{error:Z,info:"non-numeric values"};if(_&&![1,2].includes(_))return{error:Z,info:"winningSide must be 1 or 2"}}const{valid:u}=LG({existingMatchUpStatus:t,matchUpStatus:r,matchUpFormat:e,winningSide:n,score:o});if(!u)return{error:AF,info:"score is invalid for matchUpFormat or winningSide does not match calculated winningSide"}}return{valid:!0}}function Yf({analysis:t,set:e}){const r=zf({set:e}),{isDecidingSet:n,isTiebreakSet:o,matchUpScoringFormat:i}=t;return ZP({matchUpScoringFormat:i,isDecidingSet:n,isTiebreakSet:o,set:e})&&r}function ZP({ignoreTiebreak:t=!1,matchUpScoringFormat:e,matchUpFormat:r,isTiebreakSet:n,isDecidingSet:o,set:i}){if(!i)return{error:Oe};e=e||r;const s=o&&e.finalSetFormat||(e==null?void 0:e.setFormat)||{},{side1Score:a,side2Score:c}=i,{NoAD:l,setTo:u,tiebreakAt:d,tiebreakFormat:p}=s,v=p==null?void 0:p.NoAd,f=zf({set:i}),m=Math.abs(a-c),g=a>=u||c>=u,h=n||a>=u&&c>=u||d&&d<u&&(a===d||c===d),_=t||h&&(f===1&&i.side1TiebreakScore>i.side2TiebreakScore||f===2&&i.side2TiebreakScore>i.side1TiebreakScore),P=m>=(l||h&&(d&&!n||n&&v)?1:2);return(g&&(P||h)||n)&&(!h||_)}function zf({set:t}){if(t.side1Score||t.side2Score){if(t.side1Score>t.side2Score)return 1;if(t.side2Score>t.side1Score)return 2}else if(t.side1TiebreakScore||t.side2TiebreakScore){if(t.side1TiebreakScore>t.side2TiebreakScore)return 1;if(t.side2TiebreakScore>t.side1TiebreakScore)return 2}}const ls=" ",Kf="DEF",VG="COMPLETED",XP="WO",xG="WO/WO",ey="ABN",ty="SUS",ry="RET",ny="INT",oy=[ry,Kf,XP,xG,ey,ty,ny],Qf="DEFAULTED",iy="WALKOVER",sy="ABANDONED",ay="SUSPENDED",cy="RETIRED",ly="INTERRUPTED",BG=[cy,Qf,iy],us="()",Si="[]",kG=["up","left","shift+tab"],GG=["enter","down","tab","right"],_u="backspace",uy="r",dy="s",py="a",fy="d",vy="w",my="i",Jf=[uy,fy,vy,py,dy,my],Iu="space",Zf=["[","("],Pu=[...kG,...GG,Iu,"]"],gy="-",WG="/",ds=gy,Zn=gy,hy=[WG],HG=0,_y=["0","1","2","3","4","5","6","7","8","9"].concat(Jf),qG=_y.map(t=>`shift+${t}`),YG=[ds,_u].concat(Pu,hy),zG=[_y,qG,YG].join(",");function KG({analysis:t,scoreString:e,sets:r,value:n}){let o;if(!(r!=null&&r.length))return{sets:[]};const i=r[r.length-1];n=parseInt(n);const{validSide2Score:s,requiresTiebreak:a}=QG({analysis:t,set:i,value:n});if(s){o=!0,e=(e||"")+n,i.side2Score=n;const c=Yf({analysis:t,set:r[r.length-1]});if(i.winningSide=c||void 0,a){const l=us.split("")[0];e+=l}else t.isDecidingSet||(e+=ls)}return{sets:r,scoreString:e,updated:o}}function QG({analysis:t,set:e={},value:r}){const n=t.isDecidingSet&&t.matchUpScoringFormat.finalSetFormat||t.matchUpScoringFormat.setFormat,{tiebreakAt:o,setTo:i,NoAD:s}=n,{side1Score:a}=e;let c,l;return o&&o<i?a===o?c=r<=i:c=r<=o:a===i?s?c=r<i:c=r<=i+1:a===i-1?s?c=r<=i:c=r<=i+1:a===i+1?c=r===i||r===i-1:c=r<=i,c&&(o&&o<i?l=a===i&&r===o||a===o&&r===i:l=a>=i&&r>=i&&a!==r),{validSide2Score:c,requiresTiebreak:l}}function aa({scoreString:t,lowSide:e,outcome:r}){if({scoreString:t}=Iy({scoreString:t}),e===2){const o=(t&&t[t.length-1])!==ls?ls:"";return t+o+r}else return r+ls+t}function Iy({scoreString:t}){if(!t)return{scoreString:""};let e=!1;for(const r of oy){const n=t==null?void 0:t.indexOf(r);n===0?t=t.slice(r.length+1).trim()+ls:n>0&&(t=t.slice(0,n)),n>=0&&(e=!0)}return t!=null&&t.trim()||(t=""),{scoreString:t,removed:e}}function Xf({analysis:t,scoreString:e,sets:r,lowSide:n}){var o,i,s;let a,c;if(!e)return{scoreString:e,sets:r};const{scoreString:l,removed:u}=Iy({scoreString:e});if(e=l,u)return{scoreString:e,sets:r,outcomeRemoved:!0};let d=r[r.length-1]||{};const p=Object.values(d).filter(_=>_!==void 0).length;d.setNumber&&p===1&&(r=r.slice(0,r.length-1),d=r[r.length-1]||{});const{tiebreakSet:v}=t.setFormat,{tiebreakTo:f,NoAD:m}=v||{},{isTiebreakEntry:g}=ca({brackets:Si,scoreString:e}),h=ZG(e);if(h>=0){a=e.slice(0,h);const{isTiebreakEntry:_}=ca({brackets:us,scoreString:a}),{lastOpenBracketIndex:I,isTiebreakEntry:P}=ca({brackets:Si,scoreString:a}),O=a&&a[a.length-1].trim(),y=a&&!isNaN(O);let S=t.isIncompleteSetScore;if(g&&P){const E=a.slice(I+1).split(Zn),b=(E==null?void 0:E.length)>0&&E[0]!==void 0&&!isNaN(parseInt(E[0]))&&parseInt(E[0])||void 0,N=(E==null?void 0:E.length)>1&&E[1]!==void 0&&parseInt(E[1])||void 0,w=[b,N];if(N){const $=n===1?1:0;w[$]=w[1-$]+(m?1:2),w[$]<f&&(w[$]=f),a=e.slice(0,I+1),a+=w.join(Zn)}else b!==void 0?(a=e.slice(0,I+1),a+=b):(a=e.slice(0,I),S=!0);d.side1TiebreakScore=w[0]||0,d.side2TiebreakScore=w[1]||0}if(a.length||(a=void 0),S){const T=(o=d.side1Score)==null?void 0:o.toString();if(T){const E=T==null?void 0:T.slice(0,T.length-1);d.side1Score=!isNaN(E)&&parseInt(E)||void 0,d.side1Score===void 0&&(d.side2Score=void 0)}t.isTimedSet?(c=d.side1Score?r:(r==null?void 0:r.slice(0,r.length-1))||[],c[r.length-1]=d):c=(r==null?void 0:r.slice(0,r.length-1))||[]}else if(y){const T=(i=d.side2Score)==null?void 0:i.toString(),E=(s=d.side1Score)==null?void 0:s.toString();if(!t.isTiebreakEntry&&!t.isMatchTiebreak)if(d.side2Score){const b=T==null?void 0:T.slice(0,T.length-1);d.side2Score=!isNaN(b)&&parseInt(b)||void 0}else{const b=E==null?void 0:E.slice(0,E.length-1);d.side1Score=!isNaN(b)&&parseInt(b)||void 0}t.isTimedSet?d.side1Score?(c=r||[],c[r.length-1]=d):c=(r==null?void 0:r.slice(0,r.length-1))||[]:(c=r||[],c[r.length-1]=d),c[c.length-1]&&Object.assign(c[c.length-1],{winningSide:void 0})}else _?(c=r||[],Object.assign(c[c.length-1]||{},{winningSide:void 0,side1TiebreakScore:void 0,side2TiebreakScore:void 0})):(g&&!P?c=(r==null?void 0:r.slice(0,r.length-1))||[]:(c=r,c[r.length-1]=d),g||(c[c.length-1].side2Score=0,c[c.length-1].winningSide=void 0));return{scoreString:a,sets:c}}return{scoreString:e,sets:r}}function ca({brackets:t=us,scoreString:e}){if(!e)return{};const[r,n]=t.split(""),o=e.split(""),i=Math.max(...hn(r,o)),s=Math.max(...hn(n,o));return{isTiebreakEntry:i>s,lastOpenBracketIndex:i}}function JG({scoreString:t}){if(!t)return!1;const e=t&&t[t.length-1].trim(),r=t&&!isNaN(e),[n,o]=Si.split(""),i=t.split(""),s=Math.max(...hn(n,i)),a=Math.max(...hn(o,i)),c=Math.max(...hn(Zn,i));return r&&s>a&&c>s}function ZG(t){return t.split("").reduce((n,o,i)=>(o.match(/\d+/g)&&n.push(i),n),[]).pop()}function Py({lowValue:t=0,NoAD:e=!1,tiebreakTo:r}={}){const n=e?1:2;return t+1>=r?t+n:parseInt(r)}function yy({matchUpFormat:t,matchUpStatus:e,winningSide:r,sets:n}){const o=_r(t),{bestOf:i}=o,s=Math.ceil(i/2),a=n==null?void 0:n.reduce((l,u)=>{const{winningSide:d}=u;return d&&l[d-1]++,l},[0,0]);let c=(a==null?void 0:a.indexOf(s))+1||void 0;return BG.includes(e)&&r&&(c=r),{matchUpWinningSide:c}}function Sy({lowSide:t,value:e,sets:r,scoreString:n,winningSide:o,matchUpStatus:i}){let s;return e===uy?n?(s=!0,n=aa({scoreString:n,lowSide:t,outcome:ry}),o=t===2?1:2,i=cy):(s=!0,n=aa({scoreString:n,lowSide:t,outcome:Kf}),o=t===2?1:2,i=Qf):e===fy?(s=!0,n=aa({scoreString:n,lowSide:t,outcome:Kf}),o=t===2?1:2,i=Qf):e===vy?(s=!0,r=[],n=XP,o=t===2?1:2,i=iy):e===dy&&n?(s=!0,n=aa({scoreString:n,lowSide:t,outcome:ty}),i=ay,o=void 0):e===py?(s=!0,n=aa({scoreString:n,lowSide:t,outcome:ey}),i=sy,o=void 0):e===my&&n&&(s=!0,n=aa({scoreString:n,lowSide:t,outcome:ny}),i=ly,o=void 0),{updated:s,sets:r,scoreString:n,matchUpStatus:i,winningSide:o}}function XG({analysis:t,lowSide:e,scoreString:r,sets:n,winningSide:o,matchUpStatus:i,info:s,value:a}){let c,l;!(n!=null&&n.length)&&a!==_u&&(n=[{setNumber:1}]);const u=n.length-1;if(Jf.includes(a)){const d=n[n.length-1]||{},{side1Score:p,side2Score:v}=d;p&&!v?s="missing side2Score":t.finalSetIsComplete||o?s="final set is already complete":t.isIncompleteSetScore?s="incomplete set scoreString":t.isIncompleteSetScore||({sets:n,scoreString:r,winningSide:o,matchUpStatus:i,updated:c}=Sy({lowSide:e,value:a,sets:n,scoreString:r,matchUpStatus:i,winningSide:o}))}else if(a===_u){if({scoreString:r,sets:n,outcomeRemoved:l}=Xf({analysis:t,scoreString:r,sets:n}),(r==null?void 0:r.trim())===""&&(r=r.trim()),r||(n=[]),l){const d=n[n.length-1]||{},{side1Score:p,side2Score:v}=d;if(p&&v){const f=p>v&&1||v>p&&2||void 0;f&&(d.winningSide=f,n.push({setNumber:n.length+1}))}}i=void 0,o=void 0,c=!0}else if(t.hasOutcome)s="has outcome";else{if(o)return{sets:n,scoreString:r,winningSide:o,matchUpStatus:i,updated:!1,info:"matchUp is complete"};if(a===Iu){const d=n[n.length-1]||{},{side1Score:p,side2Score:v}=d,f=p>v&&1||v>p&&2||void 0;f&&!o&&!t.isIncompleteSetScore&&(n[n.length-1].winningSide=f,n.push({setNumber:n.length+1}),r+=" ",c=!0)}else if(a===ds&&n[u].side1Score!==void 0&&n[u].side2Score===void 0&&r&&t.isNumericEnding)r+="-",n[u].side2Score=0,i=void 0,o=void 0,c=!0;else if(!isNaN(a)){let d;if(n[u].side2Score===void 0){const p=parseInt((n[u].side1Score||0).toString()+a).toString().slice(0,2);n[u].side1Score=parseInt(p),d=n[u].side1Score.toString(),c=!0}else{const p=parseInt((n[u].side2Score||0).toString()+a).toString().slice(0,2);n[u].side2Score=parseInt(p),d=[n[u].side1Score,n[u].side2Score].join("-"),c=!0}if(c){const p=(n.slice(0,u)||[]).filter(v=>v).map(v=>{const{side1Score:f,side2Score:m}=v;return[f,m].join("-")}).join(" ");p?r=p+" "+d:r=d}}}return{sets:n,scoreString:r,winningSide:o,matchUpStatus:i,info:s,updated:c}}function e3({analysis:t,auto:e,lowSide:r,scoreString:n="",sets:o,value:i}){var s;let a,c;const{tiebreakSet:{tiebreakTo:l,NoAD:u}}=t.setFormat,[d]=Si.split("");if(t.isMatchTiebreakEntry||(n+=d),o[t.setNumber-1]){const{lastOpenBracketIndex:v}=ca({brackets:Si,scoreString:n}),m=(n.slice(v+1)+(e?"":i)).split(Zn);if((((s=m[r-1])==null?void 0:s.length)||0)>=2)c="tiebreak digit limit";else if(e){r===1&&(m[0]=(m[0]||"")+i),r===2&&(m[1]=(m[1]||"")+i);const h=[m[0]||0,m[1]||0].map(P=>parseInt(P)),_=r===1?1:0;h[_]=h[1-_]+(u?1:2),h[_]<l&&(h[_]=l);const I=o[o.length-1];I.side1TiebreakScore=h[0],I.side2TiebreakScore=h[1],n=n.slice(0,v+1),n+=h.join(Zn),a=!0}else{const h=[m[0]||0,m[1]||0].map(I=>parseInt(I)),_=o[o.length-1];_.side1TiebreakScore=h[0],_.side2TiebreakScore=h[1],n+=i,a=!0}}else{const v=Py({lowValue:parseInt(i||0),tiebreakTo:l,NoAD:u}),f=[parseInt(i),v];r===2&&f.reverse();const m={side1TiebreakScore:f[0],side2TiebreakScore:f[1],setNumber:(o==null?void 0:o.length)+1||1};o.push(m),n+=f.join(Zn),a=!0}return{info:c,scoreString:n,sets:o,updated:a}}function t3({analysis:t,lowSide:e,scoreString:r,value:n}){const{setTo:o,tiebreakAt:i,NoAD:s}=(t==null?void 0:t.setFormat)||{},a=n===parseInt(i||o);if(i&&i<o&&n>i)return{scoreString:r};if(s&&n===o||n>o)return{scoreString:r};const c=m(),l=[n,c];e===2&&l.reverse();const d=us.split("")[0],p=l.join(ds)+(a?d:ls);r=(r||"")+p;const v={side1Score:l[0],side2Score:l[1]},f=Yf({analysis:t,set:v});return v.winningSide=f||void 0,{scoreString:r,set:v};function m(){return a?n+1:n+1===o?n+(s?1:2):o}}function r3({matchUpFormat:t,scoreString:e,winningSide:r,value:n,sets:o}){var i,s,a;const l=(((i=o==null?void 0:o.filter(L=>L==null?void 0:L.winningSide))==null?void 0:i.length)||0)+(r?0:1),u=_r(t),d=l===(u==null?void 0:u.bestOf),p=d&&u.finalSetFormat||u.setFormat||{},v=(p==null?void 0:p.timed)||u.timed,f=d&&o[(u==null?void 0:u.bestOf)-1],m=f==null?void 0:f.winningSide,{isTiebreakEntry:g}=ca({brackets:us,scoreString:e}),{isTiebreakEntry:h}=ca({brackets:Si,scoreString:e}),_=g||h,I=!!p.tiebreakSet,P=(s=e==null?void 0:e[e.length-1])==null?void 0:s.trim(),O=e&&!isNaN(P),y=!_&&P===ds,S=g&&Zf.includes(P),T=h&&Zf.includes(P),E=h&&P===Zn,b=e==null?void 0:e.split(""),[N]=Si.split(""),w=b&&Math.max(...hn(N,b)),$=b&&Math.max(...hn(Zn,b)),U=b&&$>w,A=(a=o[o.length-1])==null?void 0:a.winningSide,M=(o==null?void 0:o.length)&&!A,C=oy.find(L=>(e==null?void 0:e.indexOf(L))>=0),D=!isNaN(n),F=n===Iu,R=Pu.includes(n),G=e==null?void 0:e.split("").find(L=>Zf.includes(L)),x=R&&h&&!T&&(E||!JG({scoreString:e}));return{isTiebreakSetValue:I&&D,matchUpScoringFormat:u,setNumber:l,setFormat:p,matchTiebreakHasJoiner:U,isGameScoreEntry:M,isSpace:F,isCloser:R,isTiebreakCloser:R&&G&&_&&O,isDecidingSet:d,isTiebreakSet:I,isTimedSet:v,isNumericEnding:O,isNumericValue:D,hasOpener:G,hasOutcome:C,finalSet:f,finalSetIsComplete:m,lastSetIsComplete:A,isInvalidSetTiebreakValue:F&&_&&S,isInvalidMatchTiebreakValue:x,isTiebreakEntry:_,isSetTiebreakEntry:g,isMatchTiebreakEntry:h,isIncompleteSetScore:y,isIncompleteSetTiebreak:S,isIncompleteMatchTiebreak:T,isPartialMatchTiebreakValue:E}}function n3(t){let{lowSide:e=1,value:r}=t,{scoreString:n,sets:o,winningSide:i,matchUpStatus:s}=t;const{matchUpFormat:a,shiftFirst:c,auto:l=!0}=t;let u,d;const p=c&&e===2||!c&&e===1;if(!zG.includes(r))return{updated:!1,info:"invalid key"};c&&(e=3-e);const{matchUpWinningSide:v}=yy({sets:o,winningSide:i,matchUpStatus:s,matchUpFormat:a});i=v;const f=r3({value:r,winningSide:i,scoreString:n,sets:o,matchUpFormat:a});if(hy.includes(r)&&(r=ds),f.hasOpener&&f.isTiebreakEntry&&!f.isTiebreakSet&&p&&parseInt(r)===0&&(f.isTiebreakCloser=!0),Pu.includes(r)&&f.hasOpener&&(r=""),Pu.includes(r)&&(r=Iu),f.lastSetIsComplete){const m=(n==null?void 0:n.length)&&n[n.length-1];n&&m!==" "&&(n+=" ")}if(f.isTimedSet)({info:d,sets:o,scoreString:n,updated:u,matchUpStatus:s,winningSide:i}=XG({analysis:f,lowSide:e,scoreString:n,sets:o,matchUpStatus:s,winningSide:i,value:r}));else if(Jf.includes(r))f.finalSetIsComplete||i?d="final set is already complete":!f.isTiebreakEntry&&!f.isIncompleteSetScore?{sets:o,scoreString:n,matchUpStatus:s,winningSide:i,updated:u}=Sy({lowSide:e,sets:o,scoreString:n,matchUpStatus:s,winningSide:i,value:r}):f.isTiebreakEntry||f.isIncompleteSetScore?d="incomplete set scoreString or tiebreak entry":console.log("handle case",{value:r});else if(r===_u)u=!0,{scoreString:n,sets:o}=Xf({analysis:f,scoreString:n,sets:o,lowSide:e,auto:l}),n||(o=[]),s=void 0,i=void 0;else if(f.hasOutcome)d="has outcome";else if(r===ds&&!f.isMatchTiebreakEntry)(!f.isSetTiebreakEntry||f.isSetTiebreakEntry&&!f.isNumericEnding)&&(u=!0,{scoreString:n,sets:o}=Xf({analysis:f,scoreString:n,sets:o,lowSide:e,auto:l}),s=void 0);else if(r===Zn&&f.isMatchTiebreakEntry&&!f.isSetTiebreakEntry)f.matchTiebreakHasJoiner?d="existing joiner":f.isNumericEnding&&(u=!0,n+=Zn);else if([ds,Zn].includes(r))d="invalid location for joiner";else{if(i)return{updated:!1,info:"matchUp is complete"};if(f.isIncompleteSetScore)f.isNumericValue&&({sets:o,scoreString:n,updated:u}=KG({analysis:f,scoreString:n,sets:o,value:r}));else if(f.isInvalidMatchTiebreakValue)d="invalid matchUp tiebreak character";else if(f.isInvalidSetTiebreakValue)d="invalid set tiebreak character";else if(f.isTiebreakCloser){const m=f.isSetTiebreakEntry?us:Si,g=m.split("").reverse()[0],h=m.split("")[0],_=o[o.length-1],{tiebreakFormat:I}=f.setFormat,{tiebreakTo:P,NoAD:O}=I||{},y=zf({set:_});if(!f.isTiebreakSet){const T=parseInt(n.split(h).reverse()[0]),E=Py({lowValue:T,tiebreakTo:P,NoAD:O});y===1?(_.side1TiebreakScore=E,_.side2TiebreakScore=T):(_.side1TiebreakScore=T,_.side2TiebreakScore=E)}n=(n||"")+g,f.isDecidingSet||(n+=ls);const S=Yf({analysis:f,set:_});_.winningSide=S||void 0,u=!0}else if(f.isTiebreakSetValue)({info:d,scoreString:n,sets:o,updated:u}=e3({analysis:f,auto:l,lowSide:e,scoreString:n,sets:o,value:r}));else if(f.isSetTiebreakEntry){const[m]=us.split(""),g=Math.max(...hn(m,n.split(""))),h=n.slice(g+1),_=h&&parseInt(h)===HG,I=parseInt(h?h+r:r),{tiebreakFormat:P}=f.setFormat,{tiebreakTo:O,NoAD:y}=P||{};!_&&h.length<2?y&&I>O-1?d="invalid low value for NoAD tiebreak":(u=!0,n=(n||"")+r):d=_?"tiebreak begins with zero":"tiebreak digit limit"}else if(f.isCloser)d=`invalid key: ${r}`;else if(f.isGameScoreEntry)d="game scoreString entry";else if(f.lastSetIsComplete||!o.length){u=!0;const{scoreString:m,set:g}=t3({analysis:f,lowSide:e,scoreString:n,value:parseInt(r)});g&&(g.setNumber=(o==null?void 0:o.length)+1||1),o=(o==null?void 0:o.concat(g).filter(Boolean))||[g],n=m||void 0}else console.log("error: unknown outcome")}if(u){o=o==null?void 0:o.filter(Boolean);const{matchUpWinningSide:m}=yy({sets:o,winningSide:i,matchUpStatus:s,matchUpFormat:a});return i=m,m&&(!s||[vt,Gn].includes(s))?(s=VG,o=o.filter(g=>{const{side1Score:h,side2Score:_,side1TiebreakScore:I,side2TiebreakScore:P}=g;return h||_||I||P})):n&&!i&&![ay,sy,ly].includes(s)&&(s=void 0),{updated:u,scoreString:n,sets:o,winningSide:i,matchUpStatus:s,info:d}}return{updated:u,scoreString:n,sets:o,winningSide:i,matchUpStatus:s,info:d}}function o3({matchUpScoringFormat:t,isDecidingSet:e,isTiebreakSet:r,setObject:n}){if(!n)return;const o=Oy({set:n});return i3({matchUpScoringFormat:t,isDecidingSet:e,isTiebreakSet:r,set:n})&&o||void 0}function i3({ignoreTiebreak:t=!1,matchUpScoringFormat:e,matchUpFormat:r,isTiebreakSet:n,isDecidingSet:o,set:i}){if(!i)return{error:Oe,info:"missing set"};e=e||r;const s=o&&e.finalSetFormat||(e==null?void 0:e.setFormat)||{},{side1Score:a,side2Score:c}=i,{setTo:l,tiebreakAt:u,tiebreakFormat:d}=s,p=d==null?void 0:d.NoAd,v=Oy({set:i}),f=Math.abs(a-c),m=a>=l||c>=l,g=n||a>=l&&c>=l||u&&u<l&&(a===u||c===u),h=t||g&&(v===1&&i.side1TiebreakScore>i.side2TiebreakScore||v===2&&i.side2TiebreakScore>i.side1TiebreakScore),I=f>=(g&&(u&&!n||n&&p)?1:2);return(m&&(I||g)||n)&&(!g||h)}function Oy({set:t}){if(t.side1Score||t.side2Score){if(t.side1Score>t.side2Score)return 1;if(t.side2Score>t.side1Score)return 2}else if(t.side1TiebreakScore||t.side2TiebreakScore){if(t.side1TiebreakScore>t.side2TiebreakScore)return 1;if(t.side2TiebreakScore>t.side1TiebreakScore)return 2}}function yu(t){const{setObject:e,matchUpScoringFormat:r}=t;if(!e)return{error:Np};const{setNumber:n}=e||{},{bestOf:o}=r||{},i=!!(n&&o&&n===o),s=i&&(r==null?void 0:r.finalSetFormat)||(r==null?void 0:r.setFormat),a=!!(s!=null&&s.tiebreakSet),c=!!(s!=null&&s.timed),l=!a&&!c,u=!!(n&&o&&n<=o),d=[e==null?void 0:e.side1Score,e==null?void 0:e.side2Score],p=[e==null?void 0:e.side1PointScore,e==null?void 0:e.side2PointScore],v=[e==null?void 0:e.side1TiebreakScore,e==null?void 0:e.side2TiebreakScore],f=d.filter(M=>M!==void 0).length,m=p.filter(M=>M!==void 0).length,g=v.filter(M=>M!==void 0).length,h=d==null?void 0:d.filter(M=>!isNaN(M)).length,_=v==null?void 0:v.filter(M=>!isNaN(M)).length,{tiebreakAt:I}=s||{},P=I&&d.filter(M=>M>=I).length===2,O=P&&(d[0]>d[1]&&1||d[1]>d[0]&&2||void 0),y=!!(_&&!h),S=!!(e!=null&&e.winningSide),{error:T,result:E}=s3({setObject:e,setFormat:s,sideGameScores:d,sideTiebreakScores:v}),{error:b,result:N}=a3({setObject:e,setFormat:s,sideTiebreakScores:v}),w=l&&!y&&E||a&&y&&N,$=u&&!(a&&!y)&&!(l&&y)&&(!S||w),U=o3({isDecidingSet:i,isTiebreakSet:y,matchUpScoringFormat:r,setObject:e}),A={expectTiebreakSet:a,expectTimedSet:c,hasTiebreakCondition:P,isCompletedSet:S,isDecidingSet:i,isTiebreakSet:y,isValidSet:$,isValidSetNumber:u,isValidSetOutcome:w,leadingSide:O,setFormat:s,sideGameScores:d,sideGameScoresCount:f,sidePointScores:p,sidePointScoresCount:m,sideTiebreakScores:v,sideTiebreakScoresCount:g,winningSide:U};return(e==null?void 0:e.winningSide)!==void 0&&(y?(A.isValidTiebreakSetOutcome=N,N||(A.tiebreakSetError=b)):(A.isValidStandardSetOutcome=E,E||(A.standardSetError=T))),A}function s3({setObject:t,setFormat:e,sideGameScores:r,sideTiebreakScores:n}){if(!t)return{result:!1,error:Np};const o=!!(e!=null&&e.tiebreakSet),i=!!(e!=null&&e.timed);if(!e||o||i)return{result:!1,error:Z};if(!((r==null?void 0:r.filter(N=>!isNaN(N)).length)===2))return{result:!1,error:wh};const{setTo:a,tiebreakAt:c,tiebreakFormat:l,NoAD:u}=e||{};if(!!!(a&&(r!=null&&r.find(N=>N>=a))))return{result:!1,error:wh};const p=[1,2].includes(t==null?void 0:t.winningSide);if(!t||!p)return{result:!1,error:$h};const v=(t==null?void 0:t.winningSide)-1,f=1-v,m=r[v],g=r[f],h=m-g;if(!(m>g))return{result:!1,error:{message:"winningSide game scoreString is not high"}};const I=c&&l,P=(n==null?void 0:n.filter(N=>!isNaN(N)).length)===2,O=n==null?void 0:n[v],y=n==null?void 0:n[f],S=c&&r.filter(N=>N>=c).length===2;if(I){const{NoAD:N,tiebreakTo:w}=l;if(S){if(h>1)return{result:!1,error:{message:"invalid winning game scoreString (5)"}};if(!P)return{result:!1,error:{message:"invalid tiebreak scores (1)"}};if(isNaN(w))return{result:!1,error:{message:"tiebreakTo error"}};if(!!!(w&&(n!=null&&n.find(R=>R>=w))))return{result:!1,error:{message:"invalid tiebreak scores (2)"}};const A=c<a?a:a+1;if(m>A)return{result:!1,error:{message:"invalid winning game scoreString (1)"}};if(!O||!y||O<y)return{result:!1,error:{message:"winningSide tiebreak value is not high"}};const M=N?1:2,C=O-y,D=y>=w-1;if(C&&D&&C<M)return{result:!1,error:{message:"invalid tiebreak scores (3)"}}}if(m>a&&!S)return{result:!1,error:{message:"invalid winning game scoreString (2)"}}}const T=u?1:2,E=g>=a-1;return h&&E&&!S&&h<T?{result:!1,error:{message:"invalid winning game scoreString (3)"}}:h>T&&m>a?{result:!1,error:{message:"invalid winning game scoreString (4)"}}:{result:!0}}function a3({setObject:t,setFormat:e,sideTiebreakScores:r}){if(!t)return{result:!1,error:Np};const n=!!(e!=null&&e.tiebreakSet),o=!!(e!=null&&e.timed);if(!e||!n||o)return{result:!1,error:{message:"not tiebreak set"}};const i=[1,2].includes(t==null?void 0:t.winningSide);if(!t||!i)return{result:!1,error:$h};const{tiebreakSet:s}=e||{},{NoAD:a,tiebreakTo:c}=s||{};if(!((r==null?void 0:r.filter(I=>!isNaN(I)).length)===2))return{result:!1,error:{message:"invalid tiebreak scores (1)"}};if(isNaN(c))return{result:!1,error:{message:"tiebreakTo error"}};if(!!!(r!=null&&r.find(I=>I>=c)))return{result:!1,error:{message:"invalid tiebreak scores (2)"}};const d=(t==null?void 0:t.winningSide)-1,p=1-d,v=r[d],f=r[p];if(!v||!f||v<f)return{result:!1,error:{message:"winningSide tiebreak value is not high"}};const m=a?1:2,g=v-f,h=f>=c-1;return g&&h&&g<m?{result:!1,error:{message:"invalid tiebreak scores (3)"}}:{result:!0}}var c3=Object.defineProperty,by=Object.getOwnPropertySymbols,l3=Object.prototype.hasOwnProperty,u3=Object.prototype.propertyIsEnumerable,Ty=(t,e,r)=>e in t?c3(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,d3=(t,e)=>{for(var r in e||(e={}))l3.call(e,r)&&Ty(t,r,e[r]);if(by)for(var r of by(e))u3.call(e,r)&&Ty(t,r,e[r]);return t};function p3({score:t}={}){if(!t)return{error:Oe};const{sets:e}=t,r=e.map(i=>{const{side1TiebreakScore:s,side2TiebreakScore:a,winningSide:c,side1Score:l,side2Score:u,setNumber:d}=i;return _e({winningSide:c?3-c:void 0,side1TiebreakScore:a,side2TiebreakScore:s,side1Score:u,side2Score:l,setNumber:d})}),n=Jn({sets:r}),o=Jn({sets:r,reversed:!0});return d3({reversedScore:{sets:r,scoreStringSide1:n,scoreStringSide2:o}},B)}const Ey=t=>{const{isSide1:e,lowValue:r,setTo:n,tiebreakAt:o,NoAD:i}=t;if(r===void 0)return!1;let s=typeof r=="string"?parseInt(r):r;(s==null?void 0:s.toString().length)>2&&(s=parseInt(s.toString().slice(0,2))),o&&o<n&&s>o&&(s=o);let a;return i&&!o?a=s<n?n:n-1:a=s+1<n&&n||o&&o<n&&s===o&&n||!o&&s+2||n+1,[e?s:a,e?a:s]},ev=t=>{const{isSide1:e,lowValue:r,tiebreakTo:n,tiebreakNoAd:o}=t;if(r===void 0)return!1;let i=typeof r=="string"?parseInt(r):r;(i==null?void 0:i.toString().length)>2&&(i=parseInt(i.toString().slice(0,2))),o&&i>n-1&&(i=n-1);const s=f3({lowValue:i,NoAD:o,tiebreakTo:n});return[e?i:s,e?s:i]};function f3(t){const{lowValue:e,NoAD:r,tiebreakTo:n}=t,o=r?1:2;return e+1>=n?e+o:n}const wy={stringifyMatchUpFormat:Ip,isValidMatchUpFormat:xr,parseMatchUpFormat:_r,generateTieMatchUpScore:Dc,getTiebreakComplement:ev,updateTieMatchUpScore:Qn,generateScoreString:Jn,checkSetIsComplete:ZP,validateTieFormat:ur,getSetComplement:Ey,scoreHasValue:Dt,keyValueScore:n3,validateScore:qf,reverseScore:p3,analyzeSet:yu};function $y(t){return t&&typeof String.fromCodePoint<"u"?t.toUpperCase().replace(/./g,e=>String.fromCodePoint(e.charCodeAt(0)+127397)):t}function v3(t){const e=Object.assign({},...qo.filter(r=>r.ioc).map(r=>({[r.ioc]:r.iso})));return $y(e[t])}const qo=[{ioc:"",iso2:"",iso:"",label:"NONE",phone:""},{ioc:"AND",iso2:"AD",iso:"AND",label:"Andorra",phone:"376"},{ioc:"UAE",iso2:"AE",iso:"ARE",label:"United Arab Emirates",phone:"971"},{ioc:"AFG",iso2:"AF",iso:"AFG",label:"Afghanistan",phone:"93"},{ioc:"ANT",iso2:"AG",iso:"ATG",label:"Antigua and Barbuda",phone:"1-268"},{ioc:"AIA",iso2:"AI",iso:"AIA",label:"Anguilla",phone:"1-264"},{ioc:"ALB",iso2:"AL",iso:"ALB",label:"Albania",phone:"355"},{ioc:"ARM",iso2:"AM",iso:"ARM",label:"Armenia",phone:"374"},{ioc:"ANG",iso2:"AO",iso:"AGO",label:"Angola",phone:"244"},{ioc:"",iso2:"AQ",iso:"ATA",label:"Antarctica",phone:"672"},{ioc:"ARG",iso2:"AR",iso:"ARG",label:"Argentina",phone:"54"},{ioc:"ASA",iso2:"AS",iso:"ASM",label:"American Samoa",phone:"1-684"},{ioc:"AUT",iso2:"AT",iso:"AUT",label:"Austria",phone:"43"},{ioc:"AUS",iso2:"AU",iso:"AUS",label:"Australia",phone:"61",suggested:!0},{ioc:"ARU",iso2:"AW",iso:"ABW",label:"Aruba",phone:"297"},{ioc:"AZE",iso2:"AZ",iso:"AZE",label:"Azerbaijan",phone:"994"},{ioc:"BIH",iso2:"BA",iso:"BIH",label:"Bosnia and Herzegovina",phone:"387"},{ioc:"BAR",iso2:"BB",iso:"BRB",label:"Barbados",phone:"1-246"},{ioc:"BAN",iso2:"BD",iso:"BGD",label:"Bangladesh",phone:"880"},{ioc:"BEL",iso2:"BE",iso:"BEL",label:"Belgium",phone:"32"},{ioc:"BUR",iso2:"BF",iso:"BFA",label:"Burkina Faso",phone:"226"},{ioc:"BUL",iso2:"BG",iso:"BGR",label:"Bulgaria",phone:"359"},{ioc:"BRN",iso2:"BH",iso:"BHR",label:"Bahrain",phone:"973"},{ioc:"BDI",iso2:"BI",iso:"BDI",label:"Burundi",phone:"257"},{ioc:"BEN",iso2:"BJ",iso:"BEN",label:"Benin",phone:"229"},{ioc:"",iso2:"BL",iso:"BLM",label:"Saint Barthelemy",phone:"590"},{ioc:"BER",iso2:"BM",iso:"BMU",label:"Bermuda",phone:"1-441"},{ioc:"BRU",iso2:"BN",iso:"BRN",label:"Brunei Darussalam",phone:"673"},{ioc:"BOL",iso2:"BO",iso:"BOL",label:"Bolivia",phone:"591"},{ioc:"BRA",iso2:"BR",iso:"BRA",label:"Brazil",phone:"55"},{ioc:"BAH",iso2:"BS",iso:"BHS",label:"Bahamas",phone:"1-242"},{ioc:"BHU",iso2:"BT",iso:"BTN",label:"Bhutan",phone:"975"},{ioc:"",iso2:"BV",iso:"BVT",label:"Bouvet Island",phone:"47"},{ioc:"BOT",iso2:"BW",iso:"BWA",label:"Botswana",phone:"267"},{ioc:"BLR",iso2:"BY",iso:"BLR",label:"Belarus",phone:"375"},{ioc:"BIZ",iso2:"BZ",iso:"BLZ",label:"Belize",phone:"501"},{ioc:"CAN",iso2:"CA",iso:"CAN",label:"Canada",phone:"1",suggested:!0},{ioc:"",iso2:"CC",iso:"CCK",label:"Cocos (Keeling) Islands",phone:"61"},{ioc:"CGO",iso2:"CD",iso:"COG",label:"Congo, Republic of the",phone:"242"},{ioc:"CAF",iso2:"CF",iso:"CAF",label:"Central African Republic",phone:"236"},{ioc:"COD",iso2:"CG",iso:"CGD",label:"Congo, Democratic Republic of the",phone:"243"},{ioc:"SUI",iso2:"CH",iso:"CHE",label:"Switzerland",phone:"41"},{ioc:"CIV",iso2:"CI",iso:"CIV",label:"Cote d'Ivoire",phone:"225"},{ioc:"COK",iso2:"CK",iso:"COK",label:"Cook Islands",phone:"682"},{ioc:"CHI",iso2:"CL",iso:"CHL",label:"Chile",phone:"56"},{ioc:"CMR",iso2:"CM",iso:"CMR",label:"Cameroon",phone:"237"},{ioc:"CHN",iso2:"CN",iso:"CHN",label:"China",phone:"86"},{ioc:"COL",iso2:"CO",iso:"COL",label:"Colombia",phone:"57"},{ioc:"CRC",iso2:"CR",iso:"CRI",label:"Costa Rica",phone:"506"},{ioc:"CUB",iso2:"CU",iso:"CUB",label:"Cuba",phone:"53"},{ioc:"CPV",iso2:"CV",iso:"CPV",label:"Cape Verde",phone:"238"},{ioc:"CUW",iso2:"CW",iso:"CUW",label:"Curacao",phone:"599"},{ioc:"CXR",iso2:"CX",iso:"CXR",label:"Christmas Island",phone:"61"},{ioc:"CYP",iso2:"CY",iso:"CYP",label:"Cyprus",phone:"357"},{ioc:"CZE",iso2:"CZ",iso:"CZE",label:"Czech Republic",phone:"420"},{ioc:"GER",iso2:"DE",iso:"DEU",label:"Germany",phone:"49",suggested:!0},{ioc:"DJI",iso2:"DJ",iso:"DJI",label:"Djibouti",phone:"253"},{ioc:"DEN",iso2:"DK",iso:"DNK",label:"Denmark",phone:"45"},{ioc:"DMA",iso2:"DM",iso:"DMA",label:"Dominica",phone:"1-767"},{ioc:"DOM",iso2:"DO",iso:"DOM",label:"Dominican Republic",phone:"1-809"},{ioc:"ALG",iso2:"DZ",iso:"DZA",label:"Algeria",phone:"213"},{ioc:"ECU",iso2:"EC",iso:"ECU",label:"Ecuador",phone:"593"},{ioc:"EST",iso2:"EE",iso:"ESE",label:"Estonia",phone:"372"},{ioc:"EGY",iso2:"EG",iso:"EGY",label:"Egypt",phone:"20"},{ioc:"",iso2:"EH",iso:"ESH",label:"Western Sahara",phone:"212"},{ioc:"ERI",iso2:"ER",iso:"ERI",label:"Eritrea",phone:"291"},{ioc:"ESP",iso2:"ES",iso:"ESP",label:"Spain",phone:"34"},{ioc:"ETH",iso2:"ET",iso:"ETH",label:"Ethiopia",phone:"251"},{ioc:"FIN",iso2:"FI",iso:"FIN",label:"Finland",phone:"358"},{ioc:"FIJ",iso2:"FJ",iso:"FJI",label:"Fiji",phone:"679"},{ioc:"FLK",iso2:"FK",iso:"FLK",label:"Falkland Islands (Malvinas)",phone:"500"},{ioc:"FSM",iso2:"FM",iso:"FSM",label:"Micronesia, Federated States of",phone:"691"},{ioc:"FAR",iso2:"FO",iso:"FRO",label:"Faroe Islands",phone:"298"},{ioc:"FRA",iso2:"FR",iso:"FRA",label:"France",phone:"33",suggested:!0},{ioc:"GAB",iso2:"GA",iso:"GAB",label:"Gabon",phone:"241"},{ioc:"GBR",iso2:"GB",iso:"GBR",label:"United Kingdom",phone:"44"},{ioc:"GRN",iso2:"GD",iso:"GRD",label:"Grenada",phone:"1-473"},{ioc:"GEO",iso2:"GE",iso:"GEO",label:"Georgia",phone:"995"},{ioc:"FGU",iso2:"GF",iso:"GUF",label:"French Guiana",phone:"594"},{ioc:"",iso2:"GG",iso:"GGY",label:"Guernsey",phone:"44"},{ioc:"",iso2:"GH",iso:"GHA",label:"Ghana",phone:"233"},{ioc:"GIB",iso2:"GI",iso:"GIB",label:"Gibraltar",phone:"350"},{ioc:"GRL",iso2:"GL",iso:"GRL",label:"Greenland",phone:"299"},{ioc:"GAM",iso2:"GM",iso:"GMB",label:"Gambia",phone:"220"},{ioc:"GUI",iso2:"GN",iso:"GIN",label:"Guinea",phone:"224"},{ioc:"GUD",iso2:"GP",iso:"GLP",label:"Guadeloupe",phone:"590"},{ioc:"GEQ",iso2:"GQ",iso:"GNQ",label:"Equatorial Guinea",phone:"240"},{ioc:"GRE",iso2:"GR",iso:"GRC",label:"Greece",phone:"30"},{ioc:"",iso2:"GS",iso:"SGS",label:"South Georgia and the South Sandwich Islands",phone:"500"},{ioc:"GUA",iso2:"GT",iso:"GTM",label:"Guatemala",phone:"502"},{ioc:"GUM",iso2:"GU",iso:"GUM",label:"Guam",phone:"1-671"},{ioc:"GBS",iso2:"GW",iso:"GNB",label:"Guinea-Bissau",phone:"245"},{ioc:"GUY",iso2:"GY",iso:"GUY",label:"Guyana",phone:"592"},{ioc:"HKG",iso2:"HK",iso:"HKG",label:"Hong Kong",phone:"852"},{ioc:"",iso2:"HM",iso:"HMD",label:"Heard Island and McDonald Islands",phone:"672"},{ioc:"HON",iso2:"HN",iso:"HND",label:"Honduras",phone:"504"},{ioc:"CRO",iso2:"HR",iso:"HRV",label:"Croatia",phone:"385"},{ioc:"HAI",iso2:"HT",iso:"HTI",label:"Haiti",phone:"509"},{ioc:"HUN",iso2:"HU",iso:"HUN",label:"Hungary",phone:"36"},{ioc:"INA",iso2:"ID",iso:"IDN",label:"Indonesia",phone:"62"},{ioc:"IRL",iso2:"IE",iso:"IRL",label:"Ireland",phone:"353"},{ioc:"ISR",iso2:"IL",iso:"ISR",label:"Israel",phone:"972"},{ioc:"",iso2:"IM",iso:"IMN",label:"Isle of Man",phone:"44"},{ioc:"IND",iso2:"IN",iso:"IND",label:"India",phone:"91"},{ioc:"",iso2:"IO",iso:"IOT",label:"British Indian Ocean Territory",phone:"246"},{ioc:"IRQ",iso2:"IQ",iso:"IRQ",label:"Iraq",phone:"964"},{ioc:"IRI",iso2:"IR",iso:"IRN",label:"Iran, Islamic Republic of",phone:"98"},{ioc:"ISL",iso2:"IS",iso:"ISL",label:"Iceland",phone:"354"},{ioc:"ITA",iso2:"IT",iso:"ITA",label:"Italy",phone:"39"},{ioc:"",iso2:"JE",iso:"JEY",label:"Jersey",phone:"44"},{ioc:"JAM",iso2:"JM",iso:"JAM",label:"Jamaica",phone:"1-876"},{ioc:"JOR",iso2:"JO",iso:"JOR",label:"Jordan",phone:"962"},{ioc:"JPN",iso2:"JP",iso:"JPN",label:"Japan",phone:"81",suggested:!0},{ioc:"KEN",iso2:"KE",iso:"KEN",label:"Kenya",phone:"254"},{ioc:"KGZ",iso2:"KG",iso:"KGZ",label:"Kyrgyzstan",phone:"996"},{ioc:"CAM",iso2:"KH",iso:"KHM",label:"Cambodia",phone:"855"},{ioc:"KIR",iso2:"KI",iso:"KIR",label:"Kiribati",phone:"686"},{ioc:"COM",iso2:"KM",iso:"COM",label:"Comoros",phone:"269"},{ioc:"SKN",iso2:"KN",iso:"KNA",label:"Saint Kitts and Nevis",phone:"1-869"},{ioc:"KOR",iso2:"KP",iso:"KOR",label:"Korea, Democratic People's Republic of",phone:"850"},{ioc:"PRK",iso2:"KR",iso:"PRK",label:"Korea, Republic of",phone:"82"},{ioc:"KUW",iso2:"KW",iso:"KWT",label:"Kuwait",phone:"965"},{ioc:"CAY",iso2:"KY",iso:"CYM",label:"Cayman Islands",phone:"1-345"},{ioc:"KAZ",iso2:"KZ",iso:"KAZ",label:"Kazakhstan",phone:"7"},{ioc:"LAO",iso2:"LA",iso:"LAO",label:"Lao People's Democratic Republic",phone:"856"},{ioc:"LIB",iso2:"LB",iso:"LBN",label:"Lebanon",phone:"961"},{ioc:"LCA",iso2:"LC",iso:"LCA",label:"Saint Lucia",phone:"1-758"},{ioc:"LIE",iso2:"LI",iso:"LIE",label:"Liechtenstein",phone:"423"},{ioc:"SRI",iso2:"LK",iso:"LKA",label:"Sri Lanka",phone:"94"},{ioc:"LBR",iso2:"LR",iso:"LBR",label:"Liberia",phone:"231"},{ioc:"LES",iso2:"LS",iso:"LSO",label:"Lesotho",phone:"266"},{ioc:"LTU",iso2:"LT",iso:"LTU",label:"Lithuania",phone:"370"},{ioc:"LUX",iso2:"LU",iso:"LUX",label:"Luxembourg",phone:"352"},{ioc:"LAT",iso2:"LV",iso:"LVA",label:"Latvia",phone:"371"},{ioc:"LBA",iso2:"LY",iso:"LBY",label:"Libya",phone:"218"},{ioc:"MAR",iso2:"MA",iso:"MAR",label:"Morocco",phone:"212"},{ioc:"MON",iso2:"MC",iso:"MCO",label:"Monaco",phone:"377"},{ioc:"MDA",iso2:"MD",iso:"MDA",label:"Moldova, Republic of",phone:"373"},{ioc:"MNE",iso2:"ME",iso:"MNE",label:"Montenegro",phone:"382"},{ioc:"",iso2:"MF",iso:"MAF",label:"Saint Martin (French part)",phone:"590"},{ioc:"MAD",iso2:"MG",iso:"MDG",label:"Madagascar",phone:"261"},{ioc:"MSH",iso2:"MH",iso:"MHL",label:"Marshall Islands",phone:"692"},{ioc:"MKD",iso2:"MK",iso:"MKD",label:"Macedonia, the Former Yugoslav Republic of",phone:"389"},{ioc:"MLI",iso2:"ML",iso:"MLI",label:"Mali",phone:"223"},{ioc:"MYA",iso2:"MM",iso:"MMR",label:"Myanmar",phone:"95"},{ioc:"MGL",iso2:"MN",iso:"MNG",label:"Mongolia",phone:"976"},{ioc:"MAC",iso2:"MO",iso:"MAC",label:"Macao",phone:"853"},{ioc:"NMA",iso2:"MP",iso:"NMP",label:"Northern Mariana Islands",phone:"1-670"},{ioc:"MRT",iso2:"MQ",iso:"MTQ",label:"Martinique",phone:"596"},{ioc:"MTN",iso2:"MR",iso:"MRT",label:"Mauritania",phone:"222"},{ioc:"MNT",iso2:"MS",iso:"MSR",label:"Montserrat",phone:"1-664"},{ioc:"MLT",iso2:"MT",iso:"MLT",label:"Malta",phone:"356"},{ioc:"MRI",iso2:"MU",iso:"MUS",label:"Mauritius",phone:"230"},{ioc:"MDV",iso2:"MV",iso:"MDV",label:"Maldives",phone:"960"},{ioc:"MAW",iso2:"MW",iso:"MWI",label:"Malawi",phone:"265"},{ioc:"MEX",iso2:"MX",iso:"MEX",label:"Mexico",phone:"52"},{ioc:"MAS",iso2:"MY",iso:"MYS",label:"Malaysia",phone:"60"},{ioc:"MOZ",iso2:"MZ",iso:"MOZ",label:"Mozambique",phone:"258"},{ioc:"NAM",iso2:"NA",iso:"NAM",label:"Namibia",phone:"264"},{ioc:"NCL",iso2:"NC",iso:"NCL",label:"New Caledonia",phone:"687"},{ioc:"NIG",iso2:"NE",iso:"NER",label:"Niger",phone:"227"},{ioc:"NFI",iso2:"NF",iso:"NFK",label:"Norfolk Island",phone:"672"},{ioc:"NGR",iso2:"NG",iso:"NGA",label:"Nigeria",phone:"234"},{ioc:"NCA",iso2:"NI",iso:"NIC",label:"Nicaragua",phone:"505"},{ioc:"NED",iso2:"NL",iso:"NLD",label:"Netherlands",phone:"31"},{ioc:"NOR",iso2:"NO",iso:"NOR",label:"Norway",phone:"47"},{ioc:"NEP",iso2:"NP",iso:"NPL",label:"Nepal",phone:"977"},{ioc:"NRU",iso2:"NR",iso:"NRU",label:"Nauru",phone:"674"},{ioc:"NIU",iso2:"NU",iso:"NIU",label:"Niue",phone:"683"},{ioc:"NZL",iso2:"NZ",iso:"NZL",label:"New Zealand",phone:"64"},{ioc:"OMA",iso2:"OM",iso:"OMN",label:"Oman",phone:"968"},{ioc:"PAN",iso2:"PA",iso:"PAN",label:"Panama",phone:"507"},{ioc:"PER",iso2:"PE",iso:"PER",label:"Peru",phone:"51"},{ioc:"FPO",iso2:"PF",iso:"PYF",label:"French Polynesia",phone:"689"},{ioc:"PNG",iso2:"PG",iso:"PNG",label:"Papua New Guinea",phone:"675"},{ioc:"PHI",iso2:"PH",iso:"PHL",label:"Philippines",phone:"63"},{ioc:"PAK",iso2:"PK",iso:"PAK",label:"Pakistan",phone:"92"},{ioc:"POL",iso2:"PL",iso:"POL",label:"Poland",phone:"48"},{ioc:"SPM",iso2:"PM",iso:"SPM",label:"Saint Pierre and Miquelon",phone:"508"},{ioc:"",iso2:"PN",iso:"PCN",label:"Pitcairn",phone:"870"},{ioc:"PUR",iso2:"PR",iso:"PRI",label:"Puerto Rico",phone:"1"},{ioc:"PLE",iso2:"PS",iso:"PSE",label:"Palestine, State of",phone:"970"},{ioc:"POR",iso2:"PT",iso:"PRT",label:"Portugal",phone:"351"},{ioc:"PLW",iso2:"PW",iso:"PLW",label:"Palau",phone:"680"},{ioc:"PAR",iso2:"PY",iso:"PRY",label:"Paraguay",phone:"595"},{ioc:"QAT",iso2:"QA",iso:"QAT",label:"Qatar",phone:"974"},{ioc:"REU",iso2:"RE",iso:"REU",label:"Reunion",phone:"262"},{ioc:"ROU",iso2:"RO",iso:"ROU",label:"Romania",phone:"40"},{ioc:"SRB",iso2:"RS",iso:"SRB",label:"Serbia",phone:"381"},{ioc:"RUS",iso2:"RU",iso:"RUS",label:"Russia",phone:"7"},{ioc:"RWA",iso2:"RW",iso:"RWA",label:"Rwanda",phone:"250"},{ioc:"KSA",iso2:"SA",iso:"SAU",label:"Saudi Arabia",phone:"966"},{ioc:"SOL",iso2:"SB",iso:"SLB",label:"Solomon Islands",phone:"677"},{ioc:"SEY",iso2:"SC",iso:"SYC",label:"Seychelles",phone:"248"},{ioc:"SUD",iso2:"SD",iso:"SDN",label:"Sudan",phone:"249"},{ioc:"SWE",iso2:"SE",iso:"SWE",label:"Sweden",phone:"46"},{ioc:"SIN",iso2:"SG",iso:"SGP",label:"Singapore",phone:"65"},{ioc:"HEL",iso2:"SH",iso:"SHN",label:"Saint Helena",phone:"290"},{ioc:"SLO",iso2:"SI",iso:"SVN",label:"Slovenia",phone:"386"},{ioc:"",iso2:"SJ",iso:"SJM",label:"Svalbard and Jan Mayen",phone:"47"},{ioc:"SVK",iso2:"SK",iso:"SVK",label:"Slovakia",phone:"421"},{ioc:"SLE",iso2:"SL",iso:"SLE",label:"Sierra Leone",phone:"232"},{ioc:"SMR",iso2:"SM",iso:"SMR",label:"San Marino",phone:"378"},{ioc:"SEN",iso2:"SN",iso:"SEN",label:"Senegal",phone:"221"},{ioc:"SOM",iso2:"SO",iso:"SOM",label:"Somalia",phone:"252"},{ioc:"SUR",iso2:"SR",iso:"SUR",label:"Suriname",phone:"597"},{ioc:"",iso2:"SS",iso:"SSD",label:"South Sudan",phone:"211"},{ioc:"STP",iso2:"ST",iso:"STP",label:"Sao Tome and Principe",phone:"239"},{ioc:"ESA",iso2:"SV",iso:"SLV",label:"El Salvador",phone:"503"},{ioc:"",iso2:"SX",iso:"SMX",label:"Sint Maarten",phone:"1-721"},{ioc:"SYR",iso2:"SY",iso:"SYR",label:"Syria",phone:"963"},{ioc:"",iso2:"SZ",iso:"SWZ",label:"Swaziland",phone:"268"},{ioc:"TKS",iso2:"TC",iso:"TCA",label:"Turks and Caicos Islands",phone:"1-649"},{ioc:"CHA",iso2:"TD",iso:"TCD",label:"Chad",phone:"235"},{ioc:"",iso2:"TF",iso:"ATF",label:"French Southern Territories",phone:"262"},{ioc:"TOG",iso2:"TG",iso:"TGO",label:"Togo",phone:"228"},{ioc:"THA",iso2:"TH",iso:"THA",label:"Thailand",phone:"66"},{ioc:"TJK",iso2:"TJ",iso:"TJK",label:"Tajikistan",phone:"992"},{ioc:"",iso2:"TK",iso:"TKL",label:"Tokelau",phone:"690"},{ioc:"TLS",iso2:"TL",iso:"TLS",label:"Timor-Leste",phone:"670"},{ioc:"TKM",iso2:"TM",iso:"TKM",label:"Turkmenistan",phone:"993"},{ioc:"TUN",iso2:"TN",iso:"TUN",label:"Tunisia",phone:"216"},{ioc:"TGA",iso2:"TO",iso:"TON",label:"Tonga",phone:"676"},{ioc:"TUR",iso2:"TR",iso:"TUR",label:"Turkey",phone:"90"},{ioc:"TTO",iso2:"TT",iso:"TTO",label:"Trinidad and Tobago",phone:"1-868"},{ioc:"TUV",iso2:"TV",iso:"TUV",label:"Tuvalu",phone:"688"},{ioc:"TPE",iso2:"TW",iso:"TWN",label:"Taiwan",phone:"886"},{ioc:"TAN",iso2:"TZ",iso:"TZA",label:"United Republic of Tanzania",phone:"255"},{ioc:"UKR",iso2:"UA",iso:"UKR",label:"Ukraine",phone:"380"},{ioc:"UGA",iso2:"UG",iso:"UGA",label:"Uganda",phone:"256"},{ioc:"USA",iso2:"US",label:"United States",phone:"1",suggested:!0,iso:"USA"},{ioc:"URU",iso2:"UY",iso:"URY",label:"Uruguay",phone:"598"},{ioc:"UZB",iso2:"UZ",iso:"UZB",label:"Uzbekistan",phone:"998"},{ioc:"",iso2:"VA",iso:"VAT",label:"Holy See (Vatican City State)",phone:"379"},{ioc:"VIN",iso2:"VC",iso:"VCT",label:"Saint Vincent and the Grenadines",phone:"1-784"},{ioc:"VEN",iso2:"VE",iso:"VEN",label:"Venezuela",phone:"58"},{ioc:"IVB",iso2:"VG",iso:"VGB",label:"British Virgin Islands",phone:"1-284"},{ioc:"ISV",iso2:"VI",iso:"VIR",label:"US Virgin Islands",phone:"1-340"},{ioc:"VIE",iso2:"VN",iso:"VNM",label:"Vietnam",phone:"84"},{ioc:"VAN",iso2:"VU",iso:"VUT",label:"Vanuatu",phone:"678"},{ioc:"WAF",iso2:"WF",iso:"WLF",label:"Wallis and Futuna",phone:"681"},{ioc:"SAM",iso2:"WS",iso:"WSM",label:"Samoa",phone:"685"},{ioc:"KOS",iso2:"XK",iso:"KOS",label:"Kosovo",phone:"383"},{ioc:"YEM",iso2:"YE",iso:"YEM",label:"Yemen",phone:"967"},{ioc:"MAY",iso2:"YT",iso:"MYT",label:"Mayotte",phone:"262"},{ioc:"RSA",iso2:"ZA",iso:"ZAF",label:"South Africa",phone:"27"},{ioc:"ZAM",iso2:"ZM",iso:"ZMB",label:"Zambia",phone:"260"},{ioc:"ZIM",iso2:"ZW",iso:"ZWE",label:"Zimbabwe",phone:"263"}],ps="ELO",m3="NTRP",g3="UTR",Ny="WTN",Xn={[ps]:{range:[0,3e3],decimalsCount:0,defaultInitialization:1500},[m3]:{range:[1,7],decimalsCount:1,defaultInitialization:3,accessor:"dntrpRatingHundredths",accessors:["ntrpRating","dntrpRatingHundredths"],attributes:{ustaRatingType:""}},[g3]:{range:[1,16],decimalsCount:2,defaultInitialization:6},[Ny]:{range:[40,1],decimalsCount:2,defaultInitialization:23,accessor:"wtnRating",accessors:["wtnRating"],attributes:{confidence:{generator:!0,range:[60,100]}}}};var h3=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],_3="COLLEGE_D3",I3={valueGoal:5},P3={collectionDefinitions:h3,tieFormatName:_3,winCriteria:I3},y3=[{collectionName:"Doubles",collectionValue:1,matchUpCount:3,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES"},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],S3="COLLEGE_DEFAULT",O3={valueGoal:5},b3={collectionDefinitions:y3,tieFormatName:S3,winCriteria:O3},T3=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1}],E3="COLLEGE_JUCO",w3={valueGoal:5},$3={collectionDefinitions:T3,tieFormatName:E3,winCriteria:w3},N3=[{collectionName:"Doubles",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],A3="DOMINANT_DUO",U3={valueGoal:2},Ay={collectionDefinitions:N3,tieFormatName:A3,winCriteria:U3},C3=[{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],M3="DOMINANT_DUO_MIXED",D3={valueGoal:2},Uy={collectionDefinitions:C3,tieFormatName:M3,winCriteria:D3},j3=[{collectionGroupNumber:1,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:1},{collectionGroupNumber:1,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:1},{collectionGroupNumber:2,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:2},{collectionGroupNumber:2,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:2},{collectionGroupNumber:3,matchUpType:"DOUBLES",matchUpCount:1,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:3},{collectionGroupNumber:3,matchUpType:"SINGLES",matchUpCount:3,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpValue:3}],R3=[{groupNumber:1,groupName:"Day 1"},{groupNumber:2,groupName:"Day 2"},{groupNumber:3,groupName:"Day 3"}],F3="LAVER_CUP",L3={valueGoal:13},Cy={collectionDefinitions:j3,collectionGroups:R3,tieFormatName:F3,winCriteria:L3},V3=[{collectionName:"Round 1",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Round 2",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Round 3",matchUpCount:3,matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],x3="Doubles Shuffle",B3=!0,k3={aggregateValue:!0},My={collectionDefinitions:V3,tieFormatName:x3,unrestrictedSelections:B3,winCriteria:k3},G3=[{category:{ageCategoryCode:"14U"},collectionName:"14U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Singles",matchUpCount:2,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Doubles",collectionGroupNumber:1,matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],W3=[{groupNumber:1,groupName:"Doubles",groupValue:1,winCriteria:{valueGoal:2}}],H3="USTA_BREWER_CUP",q3={valueGoal:4},Dy={collectionDefinitions:G3,collectionGroups:W3,tieFormatName:H3,winCriteria:q3},Y3={valueGoal:23},z3="USTA_OZAKI_CUP",K3=[{category:{ageCategoryCode:"18U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"18U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"18U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"18U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"18U"},collectionName:"18U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"16U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"16U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"16U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"16U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"16U"},collectionName:"16U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"14U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"14U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"14U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"14U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"14U"},collectionName:"14U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"14U"},collectionName:"14U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"12U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"12U Boys Singles",matchUpType:"SINGLES",matchUpCount:3,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"12U"},matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"12U Girls Singles",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:3,matchUpValue:1},{category:{ageCategoryCode:"12U"},collectionName:"12U Boys Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",matchUpCount:1,matchUpValue:1,gender:"MALE"},{category:{ageCategoryCode:"12U"},collectionName:"12U Girls Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:1,matchUpValue:1},{category:{ageCategoryCode:"12U"},collectionName:"12U Mixed Doubles",matchUpFormat:"SET1-S:8/TB8",matchUpType:"DOUBLES",gender:"MIXED",matchUpCount:1,matchUpValue:1}],jy={winCriteria:Y3,tieFormatName:z3,collectionDefinitions:K3},Q3=[{collectionName:"Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",collectionValue:1},{collectionName:"Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1}],J3="USTA_COLLEGE",Z3={valueGoal:4},Ry={collectionDefinitions:Q3,tieFormatName:J3,winCriteria:Z3},X3=[{collectionName:"Male Singles",matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpCount:4,matchUpValue:1,gender:"MALE"},{collectionName:"Female Singles",matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",gender:"FEMALE",matchUpCount:4,matchUpValue:1},{collectionName:"Male Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpCount:2,matchUpValue:1,gender:"MALE"},{collectionName:"Female Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",gender:"FEMALE",matchUpCount:2,matchUpValue:1},{collectionName:"Mixed Doubles",matchUpFormat:"SET1-S:8/TB7@7",matchUpType:"DOUBLES",matchUpCount:4,matchUpValue:1,gender:"MIXED"}],e4="USTA_GOLD_TEAM_CHALLENGE",t4={valueGoal:9},Fy={collectionDefinitions:X3,tieFormatName:e4,winCriteria:t4},r4=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],n4="USTA_INTERSECTIONAL",o4={valueGoal:8},Ly={collectionDefinitions:r4,tieFormatName:n4,winCriteria:o4},i4=[{collectionName:"Male Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],s4="USTA_LEVEL_1",a4={valueGoal:10},Vy={collectionDefinitions:i4,tieFormatName:s4,winCriteria:a4},c4=[{category:{ageCategoryCode:"16U"},collectionName:"16U Singles",matchUpCount:4,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Singles",matchUpCount:4,matchUpFormat:"SET3-S:6/TB7",matchUpType:"SINGLES",matchUpValue:1},{category:{ageCategoryCode:"16U"},collectionName:"16U Doubles",matchUpCount:2,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES",matchUpValue:1},{category:{ageCategoryCode:"18U"},collectionName:"18U Doubles",matchUpCount:2,matchUpFormat:"SET1-S:6/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Tiebreak Doubles",matchUpCount:1,matchUpFormat:"SET1-S:TB10",matchUpType:"DOUBLES",matchUpValue:1,processCodes:["RANKING.IGNORE"]}],l4="USTA_SECTION_BATTLE",u4={valueGoal:9},xy={collectionDefinitions:c4,tieFormatName:l4,winCriteria:u4},d4=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],p4="USTA_SOUTHERN_LEVEL_5",f4={valueGoal:8},By={collectionDefinitions:d4,tieFormatName:p4,winCriteria:f4},v4=[{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Overtime",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],m4="USTA_TOC",g4={aggregateValue:!0},ky={collectionDefinitions:v4,tieFormatName:m4,winCriteria:g4},h4=[{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:1,matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Male Singles",matchUpCount:1,gender:"MALE",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"SINGLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Mixed Doubles",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:6/TB5NOAD@5",matchUpType:"DOUBLES",scoreValue:1},{collectionName:"Overtime",matchUpCount:1,gender:"MIXED",matchUpFormat:"SET1-S:T20",matchUpType:"DOUBLES",scoreValue:1}],_4="USTA_WTT_ITT",I4={aggregateValue:!0},Gy={collectionDefinitions:h4,tieFormatName:_4,winCriteria:I4},P4=[{collectionName:"Male Singles",gender:"MALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Female Singles",gender:"FEMALE",matchUpCount:6,matchUpFormat:"SET3-S:6/TB7-F:TB10",matchUpType:"SINGLES",matchUpValue:1},{collectionName:"Male Doubles",gender:"MALE",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Female Doubles",gender:"FEMALE",matchUpCount:3,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1},{collectionName:"Mixed Doubles",gender:"MIXED",matchUpCount:1,matchUpFormat:"SET1-S:8/TB7",matchUpType:"DOUBLES",matchUpValue:1}],y4="USTA_ZONAL",S4={valueGoal:10},Wy={collectionDefinitions:P4,tieFormatName:y4,winCriteria:S4};const Hy={COLLEGE_D3:P3,COLLEGE_DEFAULT:b3,COLLEGE_JUCO:$3,DOMINANT_DUO:Ay,DOMINANT_DUO_MIXED:Uy,LAVER_CUP:Cy,TEAM_DOUBLES_3_AGGREGATION:My,USTA_BREWER_CUP:Dy,USTA_OZAKI_CUP:jy,USTA_COLLEGE:Ry,USTA_GOLD_TEAM_CHALLENGE:Fy,USTA_INTERSECTIONAL:Ly,USTA_LEVEL_1:Vy,USTA_SECTION_BATTLE:xy,USTA_SOUTHERN_LEVEL_5:By,USTA_TOC:ky,USTA_WTT_ITT:Gy,USTA_ZONAL:Wy},O4={[RV]:{roundsToSeparate:void 0,policyName:"Nationality Code",policyAttributes:[{key:"person.nationalityCode"},{key:"individualParticipants.person.nationalityCode"}]}},b4="qualifierDrawPositionAssignment",T4="withdrawParticipantAtDrawPosition",E4="alternateDrawPositionAssignment",w4="luckyLoserDrawPositionAssignment",qy="removeDrawPositionAssignment",$4="swapDrawPositionAssignments",N4="modifyPairAssignment",A4="modifyParticipantOtherName",Yy="assignMatchUpSideParticipant",zy="assignDrawPosition",U4="removeSeededParticipant",C4="assignDrawPositionBye",M4="modifySeedAssignment",Ky="addPenalty",Qy="MODIFY_PAIR",tv="QUALIFIER",Jy="ALTERNATE",Zy="WITHDRAW",la="ASSIGN",Xy="REMOVE",eS="LUCKY",Su="REMOVE_SEED",tS="SWAP",Ou="NICKNAME",ua="SEED_VALUE",da="PENALTY",rv="BYE",rS={[po]:{policyName:"positionActionsDefault",enabledStructures:[{stages:[Ie,de],stageSequences:[1],enabledActions:[],disabledActions:[]},{stages:[],stageSequences:[],enabledActions:[Ou,da,tv,ua],disabledActions:[]}],disbledStructures:[],otherFlightEntries:!1,activePositionOverrides:[]}},D4={[po]:{policyName:"positionActionsDisabled",enabledStructures:!1}},j4={[po]:{policyName:"positionActionsNoMovement",enabledStructures:[{stages:[],stageSequences:[],enabledActions:[ua,Ou,da],disabledActions:[]}]}},R4={[po]:{policyName:"positionActionsUnrestricted",enabledStructures:[],otherFlightEntries:!0,disableRoundRestrictions:!0,activePositionOverrides:[ua,Su]}},F4={[oc]:{policyName:"Participant Privacy Policy",participant:{contacts:!1,individualParticipants:{onlineResources:!1,participantName:!0,participantOtherName:!0,participantId:!0,participantRole:!0,participantStatus:!0,penalties:!1,representing:!0,participantRoleResponsibilities:!1,participantType:!0,person:{addresses:!1,biographicalInformation:!1,birthDate:!1,contacts:!1,nationalityCode:!0,nativeFamilyName:!1,nativeGivenName:!1,onlineResources:!1,otherNames:!0,parentOrganisationId:!1,passportFamilyName:!1,passportGivenName:!1,personId:!1,personOtherIds:!1,previousNames:!1,sex:!1,standardFamilyName:!0,standardGivenName:!0,status:!1,tennisId:!1,wheelchair:!0}},individualParticipantIds:!0,onlineResources:!1,participantName:!0,participantOtherName:!0,participantId:!0,participantRole:!0,participantStatus:!0,penalties:!1,representing:!0,participantRoleResponsibilities:!1,participantType:!0,person:{addresses:!1,biographicalInformation:!1,birthDate:!1,contacts:!1,nationalityCode:!0,nativeFamilyName:!1,nativeGivenName:!1,onlineResources:!1,otherNames:!0,parentOrganisationId:!1,passportFamilyName:!1,passportGivenName:!1,personId:!1,personOtherIds:!1,previousNames:!1,sex:!1,standardFamilyName:!0,standardGivenName:!0,status:!1,tennisId:!1,wheelchair:!0}}}},nv="ADULT",ov="JUNIOR",bu="WHEELCHAIR",L4={[Jp]:{defaultTimes:{averageTimes:[{categoryNames:[],minutes:{default:90}}],recoveryTimes:[{minutes:{[it]:30,default:60}}]},defaultDailyLimits:{[pt]:2,[it]:2,total:3},matchUpAverageTimes:[{matchUpFormatCodes:["SET3-S:6/TB7"],averageTimes:[{categoryNames:[],minutes:{default:90}},{categoryTypes:[bu],minutes:{default:120}}]},{matchUpFormatCodes:["SET3-S:6/TB7-F:TB10"],averageTimes:[{categoryNames:[],minutes:{default:85}}]},{matchUpFormatCodes:["SET3-S:6/TB7-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:70}}]},{matchUpFormatCodes:["SET3-S:4NOAD-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:55}}]},{matchUpFormatCodes:["SET3-S:4/TB7"],averageTimes:[{categoryNames:[],minutes:{default:60}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB7"],averageTimes:[{categoryNames:[],minutes:{default:50}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB10"],averageTimes:[{categoryNames:[],minutes:{default:55}}]},{matchUpFormatCodes:["SET3-S:4/TB5@3"],averageTimes:[{categoryNames:[],minutes:{default:45}}]},{matchUpFormatCodes:["SET1-S:8/TB7","SET1-S:8/TB7@7"],averageTimes:[{categoryNames:[],minutes:{default:40}}]},{matchUpFormatCodes:["SET1-S:5/TB9@4"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:6/TB7"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:6NOAD"],averageTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:4/TB7","SET1-S:4/TB5@3","SET3-S:TB10","SET1-S:T20"],averageTimes:[{categoryNames:[],minutes:{default:20}}]},{matchUpFormatCodes:["SET1-S:4NOAD"],averageTimes:[{categoryNames:[],minutes:{default:20}}]},{matchUpFormatCodes:["SET1-S:TB10"],averageTimes:[{categoryNames:[],minutes:{default:10}}]}],matchUpRecoveryTimes:[{matchUpFormatCodes:["SET3-S:6/TB7","SET3-S:6/TB7-F:TB10","SET3-S:6/TB7-F:TB7"],recoveryTimes:[{categoryTypes:[nv,bu],minutes:{default:60,[it]:30}},{categoryTypes:[ov],minutes:{default:60,[it]:60}}]},{matchUpFormatCodes:["SET3-S:4/TB7-F:TB7","SET3-S:4/TB7-F:TB10","SET3-S:4NOAD-F:TB7","SET3-S:4/TB7","SET3-S:4/TB5@3"],recoveryTimes:[{categoryTypes:[nv,bu],minutes:{default:30}},{categoryTypes:[ov],minutes:{default:60}}]},{matchUpFormatCodes:["SET1-S:8/TB7","SET1-S:8/TB7@7","SET1-S:5/TB9@4","SET1-S:6/TB7","SET1-S:6NOAD","SET1-S:4/TB7","SET1-S:4NOAD","SET3-S:TB10","SET1-S:T20"],recoveryTimes:[{categoryNames:[],minutes:{default:30}}]},{matchUpFormatCodes:["SET1-S:4/TB5@3"],recoveryTimes:[{categoryTypes:[nv,ov],minutes:{default:30}},{categoryTypes:[bu],minutes:{default:15}}]},{matchUpFormatCodes:["SET1-S:TB10"],recoveryTimes:[{categoryNames:[],minutes:{default:15}}]}],matchUpDailyLimits:[]}},V4={[Ys]:{requireAllPositionsAssigned:!1,stage:{[de]:{stageSequence:{1:{requireAllPositionsAssigned:!0}}}},defaultMatchUpFormat:"SET3-S:6/TB7",matchUpFormats:[{description:"Best of 3 tiebreak sets",matchUpFormat:"SET3-S:6/TB7",categoryNames:[],categoryTypes:[]},{description:"Two tiebreak sets, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:6/TB7-F:TB7"},{description:"Two tiebreak sets, 10-point match tiebreak at one set all",matchUpFormat:"SET3-S:6/TB7-F:TB10"},{description:"One standard tiebreak set to 6, 7-point tiebreak at 6 games all",matchUpFormat:"SET1-S:6/TB7"},{description:"Best of 3 sets to 4",matchUpFormat:"SET3-S:4/TB7"},{description:"Two out of three short sets to 4 with 5-point tiebreak at 3 games all",matchUpFormat:"SET3-S:4/TB5@3"},{description:"One short set to 4, 7-point tiebreak at 4 games all",matchUpFormat:"SET1-S:4/TB7"},{description:"One short set to 4, 5-point tiebreak at 3 games all",matchUpFormat:"SET1-S:4/TB5@3"},{description:"Two short sets to 4, 10-point match tiebreak at one set all",matchUpFormat:"SET3-S:4/TB7-F:TB10"},{description:"Two short sets to 4, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:4/TB7-F:TB7"},{description:"One no advantage set to 5, tiebreak to 9 at 4-4",matchUpFormat:"SET1-S:5/TB9@4"},{description:"One set to 6 with deciding game at 5 games all",matchUpFormat:"SET1-S:6NOAD"},{description:"One short set to 4, deciding game is played at 3 games all",matchUpFormat:"SET1-S:4NOAD"},{description:"Two short sets to 4 with deciding game at 3-3, 7-point match tiebreak at one set all",matchUpFormat:"SET3-S:4NOAD-F:TB7"},{description:"8 game pro-set with 7 point tiebreak at 8 games all",matchUpFormat:"SET1-S:8/TB7"},{description:"8 game pro-set with 7 point tiebreak at 7 games all",matchUpFormat:"SET1-S:8/TB7@7"},{description:"Best of 3 10-point tiebreak games",matchUpFormat:"SET3-S:TB10"},{description:"One 10-point tiebreak game",matchUpFormat:"SET1-S:TB10"},{description:"Timed 20 minute game - game based",matchUpFormat:"SET1-S:T20"}]}},x4={[Ys]:{defaultMatchUpFormat:"SET3-S:6/TB7",requireAllPositionsAssigned:!1,processCodes:{incompleteAssignmentsOnDefault:["RANKING.IGNORE"]},stage:{[de]:{stageSequence:{1:{requireAllPositionsAssigned:!0}}}}}},B4={[qs]:{seedingProfile:{positioning:Ef},validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,policyName:"ITF SEEDING",seedsCountThresholds:[{drawSize:4,minimumParticipantCount:3,seedsCount:2},{drawSize:16,minimumParticipantCount:12,seedsCount:4},{drawSize:32,minimumParticipantCount:24,seedsCount:8},{drawSize:64,minimumParticipantCount:48,seedsCount:16},{drawSize:128,minimumParticipantCount:97,seedsCount:32},{drawSize:256,minimumParticipantCount:192,seedsCount:64}]}},iv={[qs]:{validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,seedingProfile:Sk,policyName:"USTA SEEDING",seedsCountThresholds:[{drawSize:4,minimumParticipantCount:3,seedsCount:2},{drawSize:16,minimumParticipantCount:12,seedsCount:4},{drawSize:32,minimumParticipantCount:24,seedsCount:8},{drawSize:64,minimumParticipantCount:48,seedsCount:16},{drawSize:128,minimumParticipantCount:96,seedsCount:32},{drawSize:256,minimumParticipantCount:192,seedsCount:64}]}},k4={ratingsParameters:Xn,matchUpFormats:yV,countryToFlag:$y,tieFormats:Hy,countries:qo,policies:{POLICY_AVOIDANCE_COUNTRY:O4,POLICY_POSITION_ACTIONS_DEFAULT:rS,POLICY_POSITION_ACTIONS_DISABLED:D4,POLICY_POSITION_ACTIONS_NO_MOVEMENT:j4,POLICY_POSITION_ACTIONS_UNRESTRICTED:R4,POLICY_PRIVACY_DEFAULT:F4,POLICY_ROUND_NAMING_DEFAULT:NP,POLICY_SCHEDULING_USTA:L4,POLICY_SCORING_DEFAULT:x4,POLICY_SCORING_USTA:V4,POLICY_SEEDING_ITF:B4,POLICY_SEEDING_USTA:iv},flagIOC:v3};function pa({collectionDefinitions:t=[],collectionGroups:e=[]}={}){let r=0;const{groupValueNumbers:n}=jP({collectionGroups:e});let o;for(const s of t||[]){const{collectionValueProfiles:a,collectionGroupNumber:c,collectionValue:l,matchUpCount:u,matchUpValue:d,scoreValue:p,setValue:v}=s,f=c&&n.includes(c);if(v||p)o=!0;else{if(f)continue;if(l)r+=l;else if(a!=null&&a.length)for(const m of a)r+=m.matchUpValue;else d?r+=u*d:r+=u}}for(const s of e)r+=s.groupValue||0;return o||!r?{aggregateValue:!0}:{valueGoal:Math.floor(r/2)+1}}function Tu({participant:t,withISO2:e,withIOC:r}){const{person:n,individualParticipants:o}=t,i=[n,o==null?void 0:o.map(({person:a})=>a)].flat().filter(Boolean);function s(a){const{nationalityCode:c}=a||{};if(c){const l=qo.find(({iso:u})=>u===c);r&&(l!=null&&l.ioc)&&!a.iocNationalityCode&&(a.iocNationalityCode=l.ioc),e&&(l!=null&&l.iso2)&&!a.iso2NationalityCode&&(a.iso2NationalityCode=l.iso2),l!=null&&l.label&&!a.countryName&&(a.countryName=l.label)}}i.forEach(s)}var G4=Object.defineProperty,nS=Object.getOwnPropertySymbols,W4=Object.prototype.hasOwnProperty,H4=Object.prototype.propertyIsEnumerable,oS=(t,e,r)=>e in t?G4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,q4=(t,e)=>{for(var r in e||(e={}))W4.call(e,r)&&oS(t,r,e[r]);if(nS)for(var r of nS(e))H4.call(e,r)&&oS(t,r,e[r]);return t};function fn({returnPreviousValues:t,itemSubTypes:e,itemType:r,element:n}){if(!n)return{error:Oe,info:uf};if(e&&!Array.isArray(e))return{error:Z,context:{itemSubTypes:e}};if(!Array.isArray(n.timeItems))return{error:xh};const o=n.timeItems.filter(s=>(s==null?void 0:s.itemType)===r).filter(s=>!(e!=null&&e.length)||e.some(a=>{var c;return(c=s==null?void 0:s.itemSubTypes)==null?void 0:c.includes(a)})).sort((s,a)=>new Date(s.createdAt||void 0)-new Date(a.createdAt||void 0)),i=o.pop();if(i){const s=q4({timeItem:i},B);return t&&Object.assign(s,{previousItems:o}),s}else return{info:Yt}}function Y4({returnPreviousValues:t,drawDefinition:e,itemSubTypes:r,itemType:n}){if(!e)return{error:wr};if(!e.timeItems)return{info:Yt};const{timeItem:o,previousItems:i,info:s}=fn({element:e,returnPreviousValues:t,itemSubTypes:r,itemType:n});return o&&{timeItem:o,previousItems:i}||{info:s}}function So({returnPreviousValues:t,itemSubTypes:e,itemType:r,event:n}){if(!n)return{error:Le};if(!n.timeItems)return{info:Yt};const{timeItem:o,previousItems:i,info:s}=fn({returnPreviousValues:t,element:n,itemSubTypes:e,itemType:r});return o&&{timeItem:o,previousItems:i}||{info:s}}function Eu({returnPreviousValues:t,tournamentRecord:e,itemSubTypes:r,itemType:n}){if(!e)return{error:ee};if(!e.timeItems)return{info:Yt};const{timeItem:o,previousItems:i,info:s}=fn({element:e,returnPreviousValues:t,itemSubTypes:r,itemType:n});return o&&{timeItem:o,previousItems:i}||{info:s}}function z4({returnPreviousValues:t,tournamentRecord:e,participantId:r,itemSubTypes:n,itemType:o}){if(!e)return{error:ee};if(!r)return{error:yt};const i=Ro({tournamentRecord:e,participantId:r});if(i.error)return i;const{participant:s}=i;if(!(s!=null&&s.timeItems))return{info:Yt};const{timeItem:a,previousItems:c,info:l}=fn({element:i.participant,returnPreviousValues:t,itemSubTypes:n,itemType:o});return a&&{timeItem:a,previousItems:c}||{info:l}}var K4=Object.defineProperty,iS=Object.getOwnPropertySymbols,Q4=Object.prototype.hasOwnProperty,J4=Object.prototype.propertyIsEnumerable,sS=(t,e,r)=>e in t?K4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wu=(t,e)=>{for(var r in e||(e={}))Q4.call(e,r)&&sS(t,r,e[r]);if(iS)for(var r of iS(e))J4.call(e,r)&&sS(t,r,e[r]);return t};const Z4={[dr]:"groupParticipantIds",[we]:"pairParticipantIds",[Ye]:"teamParticipantIds"},X4={[dr]:"groups",[Ye]:"teams"};function aS({withIndividualParticipants:t,convertExtensions:e,policyDefinitions:r,tournamentRecord:n,withSignInStatus:o,withScaleValues:i,internalUse:s,withISO2:a,withIOC:c}){const l=r==null?void 0:r[oc],u=l==null?void 0:l.participant,d={};for(const p of n.participants||[]){const v=p==null?void 0:p.participantId;v&&nW({participantMap:d,participantId:v})}for(const p of n.participants||[]){const v=ue(p,e,s),f=u?Dl({template:l.participant,source:v}):v,{participantId:m,individualParticipantIds:g,participantType:h}=f;if(Object.assign(d[m].participant,f),g&&rW({individualParticipantIds:g,filteredParticipant:f,participantMap:d,participantType:h,participantId:m}),o&&(d[m].participant.signedIn=eW(v)),i){const{ratings:_,rankings:I,seedings:P}=Js({participant:v});d[m].participant.seedings=P,d[m].participant.rankings=I,d[m].participant.ratings=_}(c||a)&&Tu({participant:d[m].participant,withISO2:a,withIOC:c})}return t&&tW({participantMap:d}),{participantMap:d}}function eW(t){const{timeItem:e}=fn({itemType:_c,element:t});return(e==null?void 0:e.itemValue)===Ic}function tW({participantMap:t}){var e;for(const{participant:r}of Object.values(t))if((e=r.individualParticipantIds)!=null&&e.length){r.individualParticipants=[];for(const n of r.individualParticipantIds)r.individualParticipants.push(t[n].participant)}}function rW({individualParticipantIds:t,filteredParticipant:e,participantMap:r,participantType:n,participantId:o}){for(const i of t){const s=r[i].participant;if(s[Z4[n]].push(o),[Ye,dr].includes(n)){const{participantRoleResponsibilities:a,participantOtherName:c,participantName:l,participantId:u,teamId:d}=e,p=X4[n];s[p].push({participantRoleResponsibilities:a,participantOtherName:c,participantName:l,participantId:u,teamId:d})}if(n===we){const a=t.find(c=>c!==i);r[i].pairIdMap[o]=a,r[i].pairIdMap[a]=o}}}function nW({participantMap:t,participantId:e}){if(t[e])return;const r={walkoverWins:0,defaultWins:0,walkovers:0,defaults:0,losses:0,wins:0};t[e]={structureParticipation:{},potentialMatchUps:{},scheduleConflicts:[],scheduleItems:[],participant:{groupParticipantIds:[],pairParticipantIds:[],teamParticipantIds:[],groups:[],teams:[]},statistics:{},opponents:{},pairIdMap:{},matchUps:{},events:{},draws:{},counters:wu({[pt]:wu({},r),[it]:wu({},r),[Ye]:wu({},r)},r)}}var oW=Object.defineProperty,iW=Object.defineProperties,sW=Object.getOwnPropertyDescriptors,cS=Object.getOwnPropertySymbols,aW=Object.prototype.hasOwnProperty,cW=Object.prototype.propertyIsEnumerable,lS=(t,e,r)=>e in t?oW(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sv=(t,e)=>{for(var r in e||(e={}))aW.call(e,r)&&lS(t,r,e[r]);if(cS)for(var r of cS(e))cW.call(e,r)&&lS(t,r,e[r]);return t},lW=(t,e)=>iW(t,sW(e));function fs({participantsProfile:t,useParticipantMap:e,policyDefinitions:r,tournamentRecord:n,contextProfile:o,inContext:i}){var s;if(e)return{participantMap:(s=aS(lW(sv(sv({},t),o),{policyDefinitions:r,tournamentRecord:n,inContext:i})))==null?void 0:s.participantMap};let a=n.participants||[];if((t!=null&&t.withIOC||t!=null&&t.withISO2)&&a.forEach(c=>Tu(sv({participant:c},t))),(i||t!=null&&t.withGroupings)&&(a!=null&&a.length)&&(a=xf({participantsProfile:t,participants:a})),t!=null&&t.withScaleValues&&(a!=null&&a.length))for(const c of a){const{ratings:l,rankings:u}=Js({participant:c});c.rankings=u,c.ratings=l}return{participants:a}}var uW=Object.defineProperty,dW=Object.defineProperties,pW=Object.getOwnPropertyDescriptors,uS=Object.getOwnPropertySymbols,fW=Object.prototype.hasOwnProperty,vW=Object.prototype.propertyIsEnumerable,dS=(t,e,r)=>e in t?uW(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yo=(t,e)=>{for(var r in e||(e={}))fW.call(e,r)&&dS(t,r,e[r]);if(uS)for(var r of uS(e))vW.call(e,r)&&dS(t,r,e[r]);return t},pS=(t,e)=>dW(t,pW(e));function Bt({scheduleVisibilityFilters:t,participantsProfile:e,afterRecoveryTimes:r,useParticipantMap:n,policyDefinitions:o,tournamentRecord:i,inContext:s=!0,contextProfile:a,matchUpFilters:c,contextFilters:l,participantMap:u,nextMatchUps:d,participants:p,context:v}){var f;if(!i)return{error:ee};const m=((f=i.unifiedTournamentId)==null?void 0:f.tournamentId)||i.tournamentId,g=(i==null?void 0:i.events)||[];p||({participants:p,participantMap:u}=fs({participantsProfile:e,policyDefinitions:o,useParticipantMap:n,tournamentRecord:i,contextProfile:a,inContext:s}));const{appliedPolicies:h}=at({tournamentRecord:i}),_=pS(Yo({},v),{tournamentId:m,indoorOutDoor:i.indoorOutDoor,surfaceCategory:i.surfaceCategory,endDate:i.endDate}),I=fo({policyDefinitions:o,tournamentRecord:i,contextProfile:a});return{matchUps:g.map(O=>{var y;return _.eventDrawsCount=((y=O.drawDefinitions)==null?void 0:y.length)||0,Oi({context:_,scheduleVisibilityFilters:t,tournamentAppliedPolicies:h,participantsProfile:e,afterRecoveryTimes:r,policyDefinitions:o,tournamentRecord:i,contextContent:I,contextFilters:l,contextProfile:a,matchUpFilters:c,participantMap:u,nextMatchUps:d,participants:p,inContext:s,event:O}).matchUps}).flat(1/0).concat(...i.matchUps||[])}}function Dr({participants:t,scheduleVisibilityFilters:e,tournamentAppliedPolicies:r,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextContent:c,contextFilters:l,contextProfile:u,drawDefinition:d,matchUpFilters:p,participantMap:v,nextMatchUps:f,inContext:m,context:g,event:h}){const{eventId:_,eventName:I,eventType:P,category:O,gender:y,matchUpFormat:S}=h||{},T=pS(Yo({},g),{eventId:_,eventType:P,eventName:I,category:O,gender:y,matchUpFormat:S,indoorOutDoor:(h==null?void 0:h.indoorOutDoor)||(a==null?void 0:a.indoorOutDoor),surfaceCategory:(h==null?void 0:h.surfaceCategory)||(a==null?void 0:a.surfaceCategory),endDate:h==null?void 0:h.endDate});return!(t!=null&&t.length)&&!v&&a&&({participants:t=[],participantMap:v}=fs({participantsProfile:n,useParticipantMap:s,policyDefinitions:i,tournamentRecord:a,contextProfile:u,inContext:m})),u&&!c&&(c=fo({policyDefinitions:i,tournamentRecord:a,contextProfile:u,drawDefinition:d,event:h})),Nt({context:T,tournamentAppliedPolicies:r,scheduleVisibilityFilters:e,tournamentParticipants:t,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:a,drawDefinition:d,contextContent:c,contextFilters:l,contextProfile:u,matchUpFilters:p,participantMap:v,nextMatchUps:f,inContext:m,event:h})}function Oi({scheduleVisibilityFilters:t,tournamentAppliedPolicies:e,participantsProfile:r,afterRecoveryTimes:n,policyDefinitions:o,participants:i=[],useParticipantMap:s,tournamentRecord:a,contextContent:c,contextFilters:l,contextProfile:u,matchUpFilters:d,participantMap:p,nextMatchUps:v,inContext:f,context:m,event:g}){if(!g)return{error:Le};const{eventId:h,eventName:_,endDate:I,category:P,gender:O,matchUpFormat:y}=g,S=Yo(Yo({},m),_e({indoorOutDoor:g.indoorOutDoor||(a==null?void 0:a.indoorOutDoor),surfaceCategory:g.surfaceCategory||(a==null?void 0:a.surfaceCategory),endDate:g.endDate||(a==null?void 0:a.endDate),tournamentId:a==null?void 0:a.tournamentId,matchUpFormat:y,eventName:_,category:P,gender:O,eventId:h}));I&&(S.endDate=I),u&&!c&&(c=fo({policyDefinitions:o,tournamentRecord:a,contextProfile:u,event:g})),!(i!=null&&i.length)&&!p&&a&&({participants:i,participantMap:p}=fs({participantsProfile:r,useParticipantMap:s,policyDefinitions:o,tournamentRecord:a,contextProfile:u,inContext:f}));const T=g.drawDefinitions||[],E=dc({tournamentRecord:a,event:g}).scheduleTiming;return{matchUps:T.map(N=>{const{matchUps:w}=Nt({tournamentParticipants:i,tournamentAppliedPolicies:e,scheduleVisibilityFilters:t,context:S,participantsProfile:r,afterRecoveryTimes:n,policyDefinitions:o,tournamentRecord:a,contextFilters:l,contextProfile:u,drawDefinition:N,contextContent:c,matchUpFilters:d,participantMap:p,scheduleTiming:E,nextMatchUps:v,inContext:f,event:g});return w}).flat(1/0)}}function av({scheduleVisibilityFilters:t,participantsProfile:e,afterRecoveryTimes:r,policyDefinitions:n,useParticipantMap:o,tournamentRecord:i,inContext:s=!0,contextFilters:a,contextProfile:c,contextContent:l,matchUpFilters:u,nextMatchUps:d,context:p}){var v;if(!i)return{error:ee};const f=((v=i.unifiedTournamentId)==null?void 0:v.tournamentId)||i.tournamentId,m=(i==null?void 0:i.events)||[],{participants:g,participantMap:h}=fs({participantsProfile:e,policyDefinitions:n,useParticipantMap:o,tournamentRecord:i,contextProfile:c,inContext:s});c&&!l&&(l=fo({policyDefinitions:n,tournamentRecord:i,contextProfile:c}));const{appliedPolicies:_}=at({tournamentRecord:i}),I=(a==null?void 0:a.eventIds)||[];return m.filter(O=>!I.includes(O.eventId)).map(O=>{var y,S;const T=It({event:O}).flightProfile,E=Yo({eventDrawsCount:((y=T==null?void 0:T.flights)==null?void 0:y.length)||((S=O.drawDefinitions)==null?void 0:S.length)||0},p);return fS({context:E,tournamentAppliedPolicies:_,scheduleVisibilityFilters:t,participantsProfile:e,afterRecoveryTimes:r,policyDefinitions:n,tournamentRecord:i,contextFilters:a,contextProfile:c,contextContent:l,matchUpFilters:u,participantMap:h,participants:g,tournamentId:f,nextMatchUps:d,inContext:s,event:O})}).reduce((O,y)=>{const S=y&&Object.keys(y).filter(T=>!["success","matchUpsMap"].includes(T));return S==null||S.forEach(T=>{O[T]||(O[T]=[]),O[T]=O[T].concat(y[T]),O.matchUpsCount+=y[T].length}),O},{matchUpsCount:0})}function fS({participants:t,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextFilters:c,contextProfile:l,contextContent:u,matchUpFilters:d,participantMap:p,nextMatchUps:v,tournamentId:f,inContext:m,context:g,event:h}){if(!h)return{error:Le};const{eventId:_,eventName:I,endDate:P}=h,O=Yo(Yo({},g),_e({eventId:_,eventName:I,endDate:P||(a==null?void 0:a.endDate),tournamentId:f||(a==null?void 0:a.tournamentId),indoorOutDoor:h.indoorOutDoor||(a==null?void 0:a.indoorOutDoor),surfaceCategory:h.surfaceCategory||(a==null?void 0:a.surfaceCategory)}));return!t&&a&&({participants:t,participantMap:p}=fs({participantsProfile:n,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextProfile:l,inContext:m})),l&&!u&&(u=fo({policyDefinitions:i,tournamentRecord:a,contextProfile:l,event:h})),(h.drawDefinitions||[]).reduce((S,T)=>{const E=cs({context:O,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,tournamentParticipants:t,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:a,drawDefinition:T,contextContent:u,contextFilters:c,contextProfile:l,matchUpFilters:d,participantMap:p,nextMatchUps:v,inContext:m,event:h}),b=Object.keys(E);return b==null||b.forEach(N=>{S[N]||(S[N]=[]),S[N]=S[N].concat(E[N])}),S},{})}function mW({participants:t,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextFilters:c,contextProfile:l,contextContent:u,drawDefinition:d,matchUpFilters:p,participantMap:v,nextMatchUps:f,tournamentId:m,inContext:g,context:h,event:_}){if(!_)return{error:Le};const{eventId:I,eventName:P,endDate:O}=_||{},y=Yo(Yo({},h),_e({eventId:I,eventName:P,endDate:O||(_==null?void 0:_.endDate)||(a==null?void 0:a.endDate),tournamentId:m||(a==null?void 0:a.tournamentId),indoorOutDoor:(_==null?void 0:_.indoorOutDoor)||(a==null?void 0:a.indoorOutDoor),surfaceCategory:(_==null?void 0:_.surfaceCategory)||(a==null?void 0:a.surfaceCategory)}));return!(t!=null&&t.length)&&a&&({participants:t,participantMap:v}=fs({participantsProfile:n,policyDefinitions:i,useParticipantMap:s,tournamentRecord:a,contextProfile:l,inContext:g})),l&&!u&&(u=fo({policyDefinitions:i,tournamentRecord:a,contextProfile:l,drawDefinition:d,event:_})),cs({context:y,tournamentAppliedPolicies:e,scheduleVisibilityFilters:r,tournamentParticipants:t,participantsProfile:n,afterRecoveryTimes:o,policyDefinitions:i,tournamentRecord:a,participantMap:v,drawDefinition:d,matchUpFilters:p,contextFilters:c,contextProfile:l,contextContent:u,nextMatchUps:f,inContext:g,event:_})}function Vc({finishingPositionOffset:t=0,finishingPositionLimit:e,positionsFed:r,roundsCount:n,roundLimit:o,matchUps:i,lucky:s,fmlc:a}){var c;if(!Array.isArray(i))return[];const{roundProfile:l,roundNumbers:u}=pr({interpolate:!0,matchUps:i});n=n||Math.max(...u);const d=o?n-o:0,p=d&&((c=l[n-d])==null?void 0:c.matchUpsCount),v=Object.values(l).map(({matchUpsCount:h})=>h),f=(h,_)=>{let I=Math.min(...h);p&&_&&I===1&&(I=p);let P=Math.max(...h);return P>e&&(P=e),[I,P]},m=Object.assign({},...u.map(h=>{const _=n+1-h-d,I=l[h].matchUpsCount,P={finishingRound:_},O=v.slice(h-1).reduce(($,U)=>$+U,0),y=a&&h!==1,S=1+t+(y?r:0),T=1,E=le(S,s?S+I*2:O+S+T),b=O+T-I,N=f(E.slice(b)),w=f(E.slice(0,b),!0);return P.finishingPositionRange={loser:N,winner:w},{[h]:P}})),g=Ft({finishingRound:!0});return i.filter(Boolean).forEach(h=>{const _=m[h.roundNumber];g&&!_&&console.log({roundFinishingData:m,matchUp:h}),h.finishingRound=_==null?void 0:_.finishingRound,h.finishingPositionRange=_==null?void 0:_.finishingPositionRange}),i}function fa({inContextDrawMatchUps:t,drawDefinition:e,matchUpsMap:r}){if(!e)return{error:pe};const n={loserMatchUpIds:{},winnerMatchUpIds:[]};return t||({matchUps:t,matchUpsMap:r}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:e,matchUpsMap:r})),!r.drawMatchUps.some(i=>i.finishingPositionRange)&&e.structures.length===1&&!e.structures[0].structures&&Vc({matchUps:r.drawMatchUps}),(t||[]).filter(({collectionId:i})=>!i).forEach(i=>{const{matchUpId:s,structureId:a}=i,c=sr({inContextDrawMatchUps:t,drawDefinition:e,matchUpId:s}),{winnerMatchUp:l,loserMatchUp:u}=c.targetMatchUps,d=l==null?void 0:l.matchUpId,p=u==null?void 0:u.matchUpId,f=gi({matchUpsMap:r,structureId:a}).find(m=>m.matchUpId===s);if(f&&(d&&(n.winnerMatchUpIds[f.matchUpId]=d,Object.assign(f,{winnerMatchUpId:d}),Object.assign(i,{winnerMatchUpId:d})),p&&(n.loserMatchUpIds[f.matchUpId]=p,i.loserMatchUpId=p,f.loserMatchUpId=p,i.finishingPositionRange))){const m=u.finishingPositionRange&&[...i.finishingPositionRange.loser,...u.finishingPositionRange.loser],g=m&&[Math.min(...m),Math.max(...m)];i.finishingPositionRange.loser=g,f.finishingPositionRange.loser=g}}),{inContextDrawMatchUps:t,goesToMap:n}}function $u(t){var e;const{sides:r,matchUpType:n}=t||{},o=(e=t.potentialParticipants)!=null&&e.length?t.potentialParticipants.flat().map(a=>n===it?(a==null?void 0:a.individualParticipantIds)||[]:a.participantId).flat():[],i=(r||[]).map(a=>{var c;return n===it&&(((c=a==null?void 0:a.participant)==null?void 0:c.individualParticipantIds)||[])||(a==null?void 0:a.participantId)&&[a.participantId]||[]}).flat();return{individualParticipantIds:i.concat(o).flat(),enteredIndividualParticipantIds:i,potentialIndividualParticipantIds:o}}function Oo({scheduleVisibilityFilters:t,afterRecoveryTimes:e,tournamentRecords:r,matchUpFilters:n,contextFilters:o,nextMatchUps:i}){return typeof r!="object"||!Object.keys(r).length?{error:Fe}:{matchUps:Object.keys(r).map(c=>{const l=r[c],{matchUps:u}=Bt({scheduleVisibilityFilters:t,afterRecoveryTimes:e,tournamentRecord:l,matchUpFilters:n,contextFilters:o,nextMatchUps:i});return u}).flat()}}function cv({scheduleVisibilityFilters:t,participantsProfile:e,policyDefinitions:r,tournamentRecords:n,matchUpFilters:o,contextFilters:i,nextMatchUps:s}){return typeof n!="object"||!Object.keys(n).length?{error:Fe}:Object.keys(n).map(l=>{const u=n[l];return av({scheduleVisibilityFilters:t,participantsProfile:e,policyDefinitions:r,tournamentRecord:u,matchUpFilters:o,contextFilters:i,nextMatchUps:s})}).reduce((l,u)=>(Object.keys(u).forEach(p=>{l[p]||(l[p]=[]),l[p]=l[p].concat(u[p])}),l),{})}function vs(t,e){return gW(t,e)||((t==null?void 0:t.stageSequence)||0)-((e==null?void 0:e.stageSequence)||0)||(t==null?void 0:t.roundNumber)-(e==null?void 0:e.roundNumber)||((t==null?void 0:t.roundPosition)||0)-((e==null?void 0:e.roundPosition)||0)}function gW(t,e){return(ts[t==null?void 0:t.stage]||0)-(ts[e==null?void 0:e.stage]||0)}var hW=Object.defineProperty,vS=Object.getOwnPropertySymbols,_W=Object.prototype.hasOwnProperty,IW=Object.prototype.propertyIsEnumerable,mS=(t,e,r)=>e in t?hW(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,PW=(t,e)=>{for(var r in e||(e={}))_W.call(e,r)&&mS(t,r,e[r]);if(vS)for(var r of vS(e))IW.call(e,r)&&mS(t,r,e[r]);return t};function Yr({includeParticipantDependencies:t,tournamentRecords:e={},tournamentRecord:r,drawDefinition:n,matchUpIds:o=[],matchUps:i=[],drawIds:s=[]}){if(!Array.isArray(o))return{error:Ka};if(!Array.isArray(i))return{error:Ao};if(!Array.isArray(s))return{error:wr};o.length||(o=i.map(({matchUpId:h})=>h));const a={},c={},l={},u={};r&&!Object.keys(e).length&&(e={[r.tournamentId]:r});const d=Object.values(e),v=d.reduce((h,_)=>(_.events||[]).map(I=>(I.drawDefinitions||[]).map(P=>P.links||[])).flat(1/0),[]).filter(({linkType:h})=>h===ho);if(v.length){({matchUps:i}=Oo({nextMatchUps:!0,tournamentRecords:e}));const h=v.reduce((_,I)=>{var P,O;const y=(P=I.source)==null?void 0:P.structureId,S=(O=I.target)==null?void 0:O.structureId;return y&&S&&(l[S]=y),y&&!_.includes(y)&&_.push(y),_},[]);for(const _ of h)a[_]=[];for(const _ of i){const I=_.containerStructureId||_.structureId;h.includes(I)&&a[I].push(_.matchUpId)}}const f=h=>{c[h]||(c[h]={dependentMatchUpIds:[],participantIds:[],matchUpIds:[],sources:[]},u[h]=[])},m=(h,_)=>{c[h].matchUpIds.forEach(P=>{c[_].matchUpIds.push(P)}),c[_].matchUpIds.push(h),c[h].dependentMatchUpIds.push(_),t&&c[h].participantIds.forEach(P=>c[_].participantIds.push(P))},g=h=>{const _=Object.keys(a).length;for(const I of h){const{matchUpId:P,winnerMatchUpId:O,loserMatchUpId:y}=I;if(!o.length||o.includes(P)){if(f(P),t){const{individualParticipantIds:E}=$u(I);c[P].participantIds=E}O&&(f(O),m(P,O),u[O].push(P)),y&&(f(y),m(P,y),u[y].push(P)),c[P].sources.push(u[P]);const S=u[P].map(E=>c[E].sources[0]).flat(),T=u[P].map(E=>c[E].sources[1]).flat();if(c[P].sources.push(S,T),_){const E=I.containerStructureId||I.structureId,b=l[E];if(a[b])for(const N of a[b])f(N),m(N,P),u[N].push(P)}}}};if(n)fa({drawDefinition:n}),i.length||({matchUps:i}=Dr({drawDefinition:n})),g(i);else{i.length||({matchUps:i}=Oo({nextMatchUps:!0,tournamentRecords:e})),s.length||(s=d!=null&&d.length?d.map(({events:h=[]})=>h.map(({drawDefinitions:_=[]})=>_.map(({drawId:I})=>I))).flat(1/0):[]);for(const h of s){let _=i.filter(P=>P.drawId===h).sort(vs);if(!_.find(({roundPosition:P})=>!P)){const P=_.find(({tournamentId:y})=>y),{drawDefinition:O}=xt({tournamentRecord:e[P==null?void 0:P.tournamentId],drawId:h});O&&fa({drawDefinition:O})}g(_)}}return PW({positionDependencies:a,matchUpDependencies:c,sourceMatchUpIds:u,matchUps:i},B)}function gS({tournamentRecords:t,matchUps:e}={}){if(!Array.isArray(e))return{error:Ao};if(e.some(({matchUpId:f,hasContext:m})=>f&&!m))return{info:"matchUps must have { inContext: true, nextMatchUps: true }",error:Ul};const r=Math.max(...e.map(({schedule:f})=>(f==null?void 0:f.courtOrder)||1).map(f=>parseInt(f))),n=le(1,r+1).map(f=>e.filter(m=>{var g;return parseInt((g=m.schedule)==null?void 0:g.courtOrder)===f})),o={},i={},s={};n.flat().filter(Boolean).sort(vs).forEach(({schedule:f})=>delete f[cf]);const c=Ve(e.map(({drawId:f})=>f)),l=Yr({includeParticipantDependencies:!0,tournamentRecords:t,drawIds:c}).matchUpDependencies,u=n.map((f,m)=>f.reduce((g,h)=>{if(!h.matchUpId)return g;const{matchUpId:_,winnerMatchUpId:I,loserMatchUpId:P,schedule:O,sides:y,potentialParticipants:S}=h,T=O==null?void 0:O.courtId;s[_]=m,i[T]=[],g.matchUpIds.push(_),o[_]=h;const E=l[_].matchUpIds;E.length&&g.sourceMatchUpIds.push(...E);const b=(y==null?void 0:y.map(({participantId:w,participant:$})=>[$==null?void 0:$.individualParticipantIds,w]).flat().filter(Boolean))||[],N=(S==null?void 0:S.flat().map(({individualParticipantIds:w,participantId:$})=>[w,$]).flat().filter(Boolean))||[];return g.participantIds.push(...N,...b),I&&g.targetMatchUpIds.push(I),P&&g.targetMatchUpIds.push(P),g},{sourceMatchUpIds:[],targetMatchUpIds:[],participantIds:[],matchUpIds:[]})),d=(f,m)=>l[f].sources.reduce((g,h,_)=>h.includes(m)&&_+1||g,0),p=u.map(()=>[]),v=(f,m,g,h)=>{if(!o[f].schedule[cf]){o[f].schedule[cf]=m,o[f].schedule[Sx]=h,p[s[f]].push({matchUpId:f,issue:m,issueType:g,issueIds:h});const _=o[f].schedule.courtId;i[_]||(i[_]=[]),i[_].push({matchUpId:f,issue:m,issueType:g,issueIds:h})}};return u.forEach((f,m)=>{const g=m?u[m-1]:void 0,h=u.slice(m+1),_={},I=mr(f.participantIds),P=Object.keys(I).filter(S=>I[S]>1),O=f.matchUpIds.filter(S=>l[S].participantIds.some(T=>P.includes(T)));O.forEach(S=>{_[S]||(_[S]={}),_[S][Ki]||(_[S][Ki]=O.filter(T=>T!==S))});const y=g&&f.participantIds.filter(S=>g.participantIds.includes(S));y&&y.forEach(S=>{const T=f.matchUpIds.concat(g.matchUpIds).filter(E=>l[E].participantIds.includes(S));T.forEach(E=>{_[E]||(_[E]={}),_[E][Qi]||(_[E][Qi]=T.filter(b=>b!==E))})}),f.matchUpIds.forEach(S=>{var T,E,b,N;const w=l[S].matchUpIds;for(const U of h){const A=U.matchUpIds.filter(M=>w.includes(M));A!=null&&A.length&&(A.forEach(M=>v(M,Z_,di,[S])),v(S,Z_,di,A))}if((T=_[S])!=null&&T[Ki]&&v(S,Ki,J_,_[S][Ki]),f.sourceMatchUpIds.includes(S)){const U=f.matchUpIds.filter(A=>l[A].matchUpIds.includes(S));v(S,Ki,di,U),f.matchUpIds.filter(A=>l[A].matchUpIds.includes(S)).forEach(A=>v(A,Ki,di,[S]))}const $=(E=g==null?void 0:g.matchUpIds)==null?void 0:E.filter(U=>d(S,U)>1);if($!=null&&$.length&&(v(S,X_,di,$),$.forEach(U=>v(U,X_,di,[S]))),(b=_[S])!=null&&b[Qi]&&v(S,Qi,J_,_[S][Qi]),(N=g==null?void 0:g.targetMatchUpIds)!=null&&N.includes(S)){const U=o[S].schedule.courtId,A=w.filter(C=>g.matchUpIds.includes(C));A.some(C=>o[C].schedule.courtId===U)||(A.forEach(C=>v(C,Qi,di,[S])),v(S,Qi,di,A))}})}),{courtIssues:i,rowIssues:p}}function Nu(t){var e;if(!t)return{};const r=[],n=t.tieFormatName,o=(e=t.collectionDefinitions)==null?void 0:e.map(i=>{const{matchUpType:s,matchUpFormat:a,matchUpCount:c,category:l,gender:u}=i;r.includes(a)||r.push(a);const d=l==null?void 0:l.ageCategoryCode;return[c,s===Jr?"D":"S",d,a,u].join(";")}).join("|");return{tieFormatName:t&&n||"UNNAMED",matchUpFormats:r,tieFormatDesc:o}}var yW=Object.defineProperty,SW=Object.defineProperties,OW=Object.getOwnPropertyDescriptors,hS=Object.getOwnPropertySymbols,bW=Object.prototype.hasOwnProperty,TW=Object.prototype.propertyIsEnumerable,_S=(t,e,r)=>e in t?yW(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,EW=(t,e)=>{for(var r in e||(e={}))bW.call(e,r)&&_S(t,r,e[r]);if(hS)for(var r of hS(e))TW.call(e,r)&&_S(t,r,e[r]);return t},wW=(t,e)=>SW(t,OW(e));function Au({considerations:t={},descendant:e,ancestor:r}){var n,o;const i={},s={},{matchUpFormats:a,tieFormatDesc:c}=Nu(e),{matchUpFormats:l,tieFormatDesc:u}=Nu(r),d=Ve((a||[]).filter(I=>!(l||[]).includes(I)).concat((l||[]).filter(I=>!(a||[]).includes(I)))),p=!!(t!=null&&t.collectionName&&e.collectionDefinitions.map(({collectionName:I})=>I).join("|")!==r.collectionDefinitions.map(({collectionName:I})=>I).join("|")),v=!!(t!=null&&t.collectionOrder&&e.collectionDefinitions.map(({collectionOrder:I})=>I).join("|")!==r.collectionDefinitions.map(({collectionOrder:I})=>I).join("|")),f=p||v||u!==c,m=Object.assign({},...((e==null?void 0:e.collectionDefinitions)||[]).map(I=>({[I.collectionId]:I}))),g=Object.assign({},...((r==null?void 0:r.collectionDefinitions)||[]).map(I=>({[I.collectionId]:I})));i.collectionIds=ch(Object.keys(m),Object.keys(g)),s.collectionIds=ch(Object.keys(g),Object.keys(m)),i.collectionsValue=IS(m,i),s.collectionsValue=IS(g,s),i.groupsCount=((n=r==null?void 0:r.collectionGroups)==null?void 0:n.length)||0-((o=e==null?void 0:e.collectionGroups)==null?void 0:o.length)||0,s.groupsCount=i.groupsCount?-1*i.groupsCount:0;const h=i.collectionsValue.totalValue-s.collectionsValue.totalValue,_=i.collectionsValue.totalMatchUps-s.collectionsValue.totalMatchUps;return wW(EW({matchUpFormatDifferences:d,matchUpCountDifference:_,descendantDifferences:i,ancestorDifferences:s,orderDifference:v,valueDifference:h,nameDifference:p,descendantDesc:c,ancestorDesc:u},B),{different:f})}function IS(t,e){let r=0;return{totalValue:e.collectionIds.reduce((o,i)=>{const s=t[i],{collectionValueProfile:a,collectionValue:c,matchUpCount:l,matchUpValue:u}=s;return r+=l,a?a.reduce((d,p)=>d+p.value,0):u&&l?u*l:c},0),totalMatchUps:r}}var $W=Object.defineProperty,PS=Object.getOwnPropertySymbols,NW=Object.prototype.hasOwnProperty,AW=Object.prototype.propertyIsEnumerable,yS=(t,e,r)=>e in t?$W(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,UW=(t,e)=>{for(var r in e||(e={}))NW.call(e,r)&&yS(t,r,e[r]);if(PS)for(var r of PS(e))AW.call(e,r)&&yS(t,r,e[r]);return t};function CW({tournamentRecord:t}){if(!t)return{error:ee};if(typeof t!="object"||!t.tournamentId)return{error:Z};const{matchUps:e}=Bt({tournamentRecord:t,inContext:!1});if(e!=null&&e.length){const r=MW({tournamentRecord:t});jW(e,r)}return UW({},B)}function MW({tournamentRecord:t}){const e={};for(const r of t.events||[]){r.matchUpFormat&&(e[r.eventId]=r.matchUpFormat);for(const n of r.drawDefinitions||[]){n.matchUpFormat&&(e[n.drawId]=n.matchUpFormat);for(const o of n.structures||[]){o.matchUpFormat&&(e[o.structureId]=o.matchUpFormat);for(const i of o.structures||[])i.matchUpFormat&&(e[i.structureId]=i.matchUpFormat)}}}return e}const DW=["collectionId","collectionPosition","drawPositions","extensions","finishingPositionRange","finishingRound","isMock","matchUpId","matchUpStatus","matchUpStatusCodes","orderOfFinish","processCodes","roundNumber","tieFormat","tieMatchUps","roundPosition","score","sides","winnerMatchUpId","loserMatchUpId","matchUpDuration","winningSide"];function jW(t,e={}){for(const r of t){const{structureId:n,drawId:o,eventId:i}=r,s=e[n]||e[o]||e[i],a=r.matchUpFormat===s?void 0:r.matchUpFormat;for(const c of Object.keys(r))DW.includes(c)||delete r[c];r.sides&&r.drawPositions&&!r.tieMatchUps&&delete r.sides,a&&(r.matchUpFormat=a)}}function xc({court:t,date:e}){const r=e&&t.dateAvailability.find(o=>kn(o.date,e)),n=t.dateAvailability.find(o=>!o.date);return r||n}function va({courtDate:t,includeBookingTypes:e=[]}){const r=[];let n=ht(t.startTime);(t.bookings||[]).filter(i=>!i.bookingType||!e.includes(i.bookingType)).sort((i,s)=>Ll(i.startTime).localeCompare(Ll(s.startTime))).forEach(i=>{const s={startTime:rt(n.toISOString()),endTime:i.startTime};ht(i.startTime)>n&&r.push(s),ht(i.endTime)>n&&(n=ht(i.endTime))});const o={startTime:rt(n.toISOString()),endTime:t.endTime};return ht(t.endTime)>n&&r.push(o),r}function RW({includeBookingTypes:t,averageMatchUpMinutes:e,periodStartTime:r,periodEndTime:n,periodLength:o}){const i=a=>!!va({includeBookingTypes:t,periodLength:o,courtDate:a}).filter(s).length;function s(a){const c=ht(a.startTime),l=ht(a.endTime);return c>r||l<n?!1:nc(r,l)>=e}return{enoughTime:i}}function SS({averageMatchUpMinutes:t,includeBookingTypes:e,periodLength:r,periodStart:n,courts:o,date:i}){const s=ht(n),a=Wp(s,t),{enoughTime:c}=RW({averageMatchUpMinutes:t,includeBookingTypes:e,periodStartTime:s,periodEndTime:a,periodLength:r});return{availableToScheduleCount:((o==null?void 0:o.filter(u=>{if(!Array.isArray(u.dateAvailability))return!1;const d=xc({date:i,court:u});return!!(d&&c(d))}))||[]).length}}function lv({remainingScheduleTimes:t=[],clearScheduleDates:e,periodLength:r=30,bookings:n=[],scheduleDate:o,courts:i=[]}){if(!Array.isArray(i)||!i.length)return{error:Z,courts:i};if(!Array.isArray(n))return{error:Ap};if(!Nr(o))return{error:cr};e&&(Array.isArray(e)?e.includes(o)&&(n=[]):n=[]);const{courtBookings:s,unassignedBookings:a}=n.reduce((p,v)=>{const{courtId:f}=v;return f?p.courtBookings[f]?p.courtBookings[f].push(v):p.courtBookings[f]=[v]:p.unassignedBookings.push(v),p},{courtBookings:{},unassignedBookings:[]}),c=i.map((p,v)=>{const{courtId:f,courtName:m}=p,g=s[f]||[],h=xc({date:o,court:p})||{},{bookings:_=[],startTime:I,endTime:P,date:O}=h,S=[t[v]&&{startTime:I,endTime:t[v]},...ue(_,!1,!0),...g].filter(Boolean);return{courtId:f,courtName:m,dateAvailability:{bookings:S,startTime:I,endTime:P,date:O}}});a.sort((p,v)=>Re(p.startTime)-Re(v.startTime));const l=()=>c.map(p=>{const v=p.dateAvailability,f=va({courtDate:v});return{courtName:p.courtName,courtId:p.courtId,timeSlots:f}}).flat(),u=[];for(const p of a){const{startTime:v,endTime:f,averageMinutes:m,recoveryMinutes:g,matchUpId:h}=p,_=Re(v),I=Re(f),O=l().reduce((y,{courtId:S,courtName:T,timeSlots:E})=>{let b;return E.find(({startTime:w,endTime:$})=>{b=Re(w)-_;const U=_>=Re(w);return I<=Re($)&&y.startDifference!==0&&((b===0||b+r>=0)&&(y.startDifference===void 0||b<y.startDifference)||U)})?{courtName:T,courtId:S,startDifference:b}:y},{});if(O.courtId){const y={averageMinutes:m,recoveryMinutes:g,matchUpId:h,startTime:v,endTime:f};u.push(y),c.find(({courtId:T})=>T===O.courtId).dateAvailability.bookings.push(y)}else console.log({unassignedBooking:p})}return{virtualCourts:c.map(({courtId:p,courtName:v,dateAvailability:f})=>({dateAvailability:[f],courtName:v,courtId:p})),assignedBookings:u}}function Uu({averageMatchUpMinutes:t,periodLength:e=30,recoveryMinutes:r}){const n=(t||90)+(r||0);return e>n?n:e||30}function ma({scheduleDate:t,startTime:e,endTime:r,courts:n}){const o=e&&"startTime"||r&&"endTime"||void 0;return n.reduce((i,s)=>{const a=xc({date:t,court:s}),c=(a==null?void 0:a[o])||s[o];return c&&(!i||e&&Re(c)<Re(i)||Re(c)>Re(i))?c:i},void 0)}function FW({averageMinutes:t,startTime:e,endTime:r,courts:n,date:o}){e=e||ma({courts:n,scheduleDate:o,startTime:!0}),r=r||ma({courts:n,scheduleDate:o,endTime:!0});let i;if(e&&r){const s=ht(e),a=ht(r);for(const c of n||[]){if(!Array.isArray(c.dateAvailability))continue;const l=xc({court:c,date:o});va({courtDate:l}).forEach(d=>{const p=ht(d.startTime),v=ht(d.endTime);if(p>a||p<s||v<s)return!1;if(nc(p,v)>=t){const g=rt(p.toISOString());(!i||g<i)&&(i=g)}})}}return{firstTimeSlotStartTime:i}}function OS({startTime:t="8:00",endTime:e="20:30",count:r=10,date:n}={}){return le(0,r).map(()=>({dateAvailability:[{date:n,startTime:t,endTime:e}]}))}function uv({calculateStartTimeFromCourts:t=!0,remainingScheduleTimes:e,date:r=kp(),averageMatchUpMinutes:n,startTime:o="08:00",clearScheduleDates:i,endTime:s="19:00",periodLength:a,courtsCount:c,bookings:l,courts:u}={}){a=a||Uu({averageMatchUpMinutes:n}),r=Ce(r),o=rt(o),s=rt(s);let d=0,p=0,v=0,f=0,m=0;!u&&c&&(u=OS({startTime:o,endTime:s,count:c,date:r}));const{virtualCourts:g}=lv({remainingScheduleTimes:e,clearScheduleDates:i,scheduleDate:r,periodLength:a,bookings:l,courts:u}),{firstTimeSlotStartTime:h}=FW({averageMinutes:n,courts:g,startTime:o,endTime:s,date:r});t&&h&&(o=h||o);const _=Re(o),P=Re(s)-_,O=Math.floor(P/a),S=le(0,O+1).map(E=>{const b=_+E*a,N=JL(b),{availableToScheduleCount:w}=SS({courts:g,averageMatchUpMinutes:n,periodLength:a,periodStart:N,period:E,date:r}),$=w>p?w-p:0;m+=E?w:0;const U=E?m/E:w,M=a*U/n,C=E?M*(E-1)+U:U,D=w?p&&C-d||$:0;d=C,p=w,v+=D;const F=parseInt(v)-f;return f+=F,{periodStart:N,add:F,availableToScheduleCount:w,newCourts:$,totalMatchUps:f}});return{scheduleTimes:S.reduce((E,b)=>E.concat(...le(0,b.add).map(()=>({scheduleTime:b.periodStart}))),[]).flat(),timingProfile:S,totalMatchUps:f}}const LW={getCourtsAvailableAtPeriodStart:SS,generateTimeSlots:va,getScheduleTimes:uv,courtGenerator:OS},VW=(t,e)=>t.filter(Boolean).every(r=>typeof r===e),xW=t=>t.filter(Boolean).every(Ot);function bS({consideredDate:t,category:e}={}){const r={error:Z,ageMin:8,ageMax:99};if(typeof e!="object"||!Nr(t))return r;const n=parseInt(t.split("-")[0]),o=[];let i,{ageCategoryCode:s,categoryName:a,ageMaxDate:c,ageMinDate:l,ageMax:u,ageMin:d}=e;if(!VW([s,c,l,a],"string")||!xW([u,d]))return r;s=s||a;const p=/^([UO]?)(\d{1,2})([UO]?)$/,v=/^C(\d{1,2})-(\d{1,2})$/,f=(s==null?void 0:s.indexOf("-"))>0,m=f&&(s==null?void 0:s.match(v)),g=s==null?void 0:s.match(p),h=T=>T.match(/^\d{2}-\d{2}$/),_=(T,E,b)=>Nr(E)&&E||E&&h(E)&&`${T}-${E}`||`${T}-${b}`,I=T=>{const E=n-T;return l=_(E,l,"01-01"),u&&u!==T-1&&o.push(`Invalid ageMax: ${u}`),u||(u=T-1),{ageMinDate:l,ageMax:u}},P=T=>{const E=n-T-1;return l=_(E,l,"01-01"),u&&u!==T&&o.push(`Invalid ageMax: ${u}`),u||(u=T),{ageMinDate:l,ageMax:u}},O=T=>{const E=n-T-2;return c=_(E,c,"12-31"),d&&d!==T+1&&o.push(`Invalid ageMin: ${d}`),d||(d=T+1),{ageMaxDate:c,ageMin:d}},y=T=>{const E=n-T-1;return c=_(E,c,"12-31"),d&&d!==T&&o.push(`Invalid ageMin: ${d}`),d||(d=T),{ageMaxDate:c,ageMin:d}},S=T=>{const[E,b,N]=(T.match(p)||[]).slice(1),w=parseInt(b);E==="U"&&({ageMinDate:l,ageMax:u}=I(w)),N==="U"&&({ageMinDate:l,ageMax:u}=P(w)),E==="O"&&({ageMaxDate:c,ageMin:d}=O(w)),N==="O"&&({ageMaxDate:c,ageMin:d}=y(w))};if(m){const[T,E]=s.match(v).slice(1).map(b=>parseInt(b));T<=E?(d=d||T,u=u||E,i=!0):o.push(`Invalid combined age range ${s}`)}else f?s.split("-").forEach(S):g&&S(s);return o.length?{error:o,ageMin:8,ageMax:99}:_e({combinedAge:i,ageMaxDate:c,ageMinDate:l,ageMax:u,ageMin:d})}function Cu({tiebreakTo:t=7,scoreString:e}){return e.split(" ").filter(Boolean).map((n,o)=>r({set:n,setNumber:o+1}));function r({set:n,setNumber:o}){const i=(n==null?void 0:n.startsWith("["))&&n.split("[")[1].split("]")[0].split("-").map(g=>parseInt(g)),s=n.includes("(")&&n.split("(")[0]||n.includes("[")&&n.split("[")[0]||n,a=!i&&s.split("-").map(g=>parseInt(g)),c=i?i[0]>i[1]&&1||i[0]<i[1]&&2||void 0:a[0]>a[1]&&1||a[0]<a[1]&&2||void 0,l=n.includes("(")?n.split("(")[1].split(")")[0]:void 0,d=l&&ev({lowValue:l,isSide1:c===2,tiebreakTo:t})||[],[p,v]=a||[],[f,m]=i||d||[];return{side1Score:p,side2Score:v,side1TiebreakScore:f,side2TiebreakScore:m,winningSide:c,setNumber:o}}}const Mu="\\d+-\\d+",Bc="\\d+-\\d+\\(\\d+\\)",dv="\\[\\d+-\\d+\\]",BW="\\d+-\\d+\\(\\d+-\\d+\\)",kW=new RegExp(`(${Mu}),`,"g"),GW=new RegExp(`(${Bc}),`,"g"),WW=[Mu,Bc,dv,BW],HW=["0","1","2","00","01","10","11","002","012","102","112","000","001","010","100","011","101","110","111","002","012","102","112","0002","0012","0102","1002","0112","1012","1102","1112","3","03","13","013","103"].map(t=>{const r=t.split("").map(n=>WW[n]).join(" ");return new RegExp(`^${r}$`)});function TS(t){return!t||HW.some(e=>e.test(t))}function qW(t){const e="[];",r="()",n=e+r,o=[e[0],r[0]],i=Object.assign({},...n.split("").map(c=>({[c]:0})));let s="";const a=t.split("").map(c=>{const l=n.includes(c)&&c,u=o.includes(l);if(u&&l)return i[l]+=1,s=l,c;if(!u&&l&&s&&l!==s){i[s]-=1;const d=e.includes(s)&&e||r.includes(s)&&r,p=d.split("").find(v=>v!==s);if(d.includes(l))i[s]||(s="");else return i[l]||(s=""),p}return c}).join("");return t!==a?a:t}function Du(t){return/^\(\d+\)$/.test(t)||/^\(\d+$/.test(t)}function YW(t){return/^\(\d+-\d+\)$/.test(t)||/^\[\d+-\d+\]$/.test(t)}function ga(t){const r=(n=>n==null?void 0:n.split("-").join("").split("/").join(""))(t);if(/^\d+$/.test(r)&&r.length===2){const n=r.split("");return Math.abs(n.reduce((i,s)=>+i-+s))===1}}function ju(t,e){const r=[t.slice(e,e+2),e?t.slice(0,1):t.slice(2)].map(i=>parseInt(i.join(""))),n=e?r.reverse():r;if(Math.abs(n.reduce((i,s)=>+i-+s))>=2)return n.join("-")}function ES(t){return t.length===2?t.split("").join("-"):([", ",",","/"," "].forEach(e=>t=t.split(e).join("-")),t=t.replace(/-{2,}/,"-"),t)}function zW(t){return t.startsWith("(")&&t.endsWith(")")}function KW({score:t,applied:e}){t=qW(t);const r=/\)(\d+)/g;if(r.test(t))for(const y of t.match(r)){const S=y.replace(")",") ");t=t.replace(y,S)}t=t.replace(/\)\//g,") / "),t=t.replace(/\/\)/g,")");const n=/\(([\d- ]+)\)/g,o=/\(([\d- ]+)\)/,i=t.match(n);for(const y of i||[]){const[S]=y.match(o).slice(1),T=S.replace(/ /g,"");t=t.replace(y,`(${T})`)}let s=/\(\(\d-\d\)\)/g;if(s.test(t)){const y=t.match(s);y.length&&y.forEach(S=>{const T=S.match(/\((\(\d-\d\))\)/).slice(1)[0];t=t.replace(S,T)})}if(s=/\(\((\d)\)\)/g,s.test(t)){const y=t.match(s);y.length&&y.forEach(S=>{const T=S.match(/\((\(\d\))\)/).slice(1)[0];t=t.replace(S,T)})}/(^|\s)6-,/.test(t)&&(t=t.replace(/(^|\s)6-,/g,"6-0,"));const a=new RegExp(/[-,]{2,}/g);t=t.replace(a,"-"),["- "," -"].forEach(y=>{const S=new RegExp(`(\\d+)${y}(\\d+)`,"g"),T=t.match(S);T&&T.forEach(E=>t=t.replace(E,E.split(y).join("-")))}),/^[(-/,]+$/.test(t)&&(t=""),/\)[-/,]+$/.test(t)&&(t=t.slice(0,t.length-1)),/\d \/\d/.test(t)&&(t=t.replace(/ \//g,"/")),t.includes(" /")&&(t=t.replace(/ \//g," "));const c=/\(\d+, \)/g;c.test(t)&&t.match(c).forEach(S=>{const[T]=S.match(/\((\d+), \)/).slice(1);T.length===2?t=t.replace(S,`(${T})`):T.length===1&&T==="6"&&(t=t.replace(S,"(6-0)"))});const l=/\((\d+)\/\)/g;l.test(t)&&t.match(l).forEach(S=>{const[T]=S.match(/\((\d+)\/\)/).slice(1);T.length===2?t=t.replace(S,`(${T})`):T.length===1&&T==="6"?t=t.replace(S,"(6-0)"):t=t.replace(S,`(${T})`)});const u=/\d\/\d\/,/g;u.test(t)&&t.match(u).forEach(S=>{const[T]=S.match(/(\d\/\d)\/,/).slice(1);t=t.replace(S,`${T},`),e.push("slashComma")});const d=/\(\/(\d+)\)/g;d.test(t)&&t.match(d).forEach(S=>{const[T]=S.match(/\(\/(\d+)\)/).slice(1);T.length===2?t=t.replace(S,`(${T})`):T.length===1&&parseInt(T)<6?t=t.replace(S,`(6-${T})`):t=t.replace(S,`(${T})`)});let p,v,f,m,g;const h=()=>{g=mr(t.split("")),v=g["("]===(g[")"]||0)+1,p=(g["("]||0)+1===g[")"],f=g["["]===g["]"]+1,m=v&&!f};h();const _=/(\d+-\d+\(\d+)0,/;if(_.test(t)){const[y]=t.match(_).slice(1);t=t.replace(_,y+")")}if(g["("]===g[")"]&&g["("]>1){const y=t.split(")(").join(") (").split(" ");y.every(zW)?t=y.map(S=>{const T=S.slice(1,S.length-1);return T.length>2?T:S}).join(" "):t=y.join(" ")}h();const I=/[A-Za-z]+/.test(t),P=/\d+/.test(t);if(!I&&!P)return{score:""};if(/^\[.+\]$/.test(t)&&"()/,- ".split("").some(y=>g[y])&&(t=t.slice(1,t.length-1)),/^\(.+\)$/.test(t)&&g["("]===1&&g[")"]===1&&"[]/,".split("").some(y=>g[y]>1)&&(t=t.slice(1,t.length-1)),t.startsWith("(")&&t.endsWith("))")&&(t=t.slice(1,t.length-1)),g["("]>(g[")"]||0)&&t[t.length-1]==="("&&(t=t.slice(0,t.length-1)+")",h()),g["("]===1&&!g[")"]&&t[0]==="("&&(t=t+")",h()),g["("]>(g[")"]||0)&&t.slice(0,2)==="(("&&(t=t.slice(1)),p){if(/^9\d/.test(t))t="("+t.slice(1);else if(t[0]!=="(")t="("+t;else{let y=[],S=0;for(const T of t.split("").reverse())T===")"&&(S?y.push("("):S+=1),T==="("&&(S-=1),y.push(T);y.reverse(),t=y.join("")}h()}if(g[")"]>(g["("]||0)&&t[0]===")"&&(t="("+t.slice(1),h()),m&&(t.endsWith(9)||/\d+0$/.test(t))&&(t=t.slice(0,t.length-1)+")",h()),m&&(!t.endsWith(")")||t.startsWith("(("))&&(t=t+")",h()),m){let y="",S=0;for(const T of t.split(""))T==="("&&(S?y+=")":S+=1),T===")"&&(S-=1),y+=T;t=y}h(),f&&!v&&(t=t+"]"),t.includes("([")&&t.includes("])")&&(t=t.split("([").join("[").split("])").join("]"),h()),/\(\d+0$/.test(t)&&(t=t.slice(0,t.length-1)+")"),h(),g[")"]===1&&!g["("]&&t.endsWith(")")&&(t=t.slice(0,t.length-1)),t.startsWith("(")&&t.endsWith(")")&&g["("]===1&&g[")"]===1&&(t=t.slice(1,t.length-1),h());const O=y=>{const S=y.indexOf("("),T=y.indexOf(")");return S>=0&&T>=0&&S<T};if(/^\([\d ]+.*[\d ]+\)$/.test(t)&&g["("]===g[")"]){const y=t.slice(1,t.length-1);O(y)&&(t=y,h())}return{score:t,applied:e}}function Ru(t){if(!/^[\d-]+(\(\d\))*$/.test(t))return t;const e=hn("-",t.split(""));if(!e.length)return t;const r=t.split("-"),n=!(r.length%2),o=!!(e.length%2);return n&&o&&e.length>r.length/2&&e.filter((s,a)=>a%2).forEach(s=>{t=t.substring(0,s)+" "+t.substring(s+1)}),t}function QW({score:t,applied:e}){return t.includes("( ")&&(e.push("removeParenSpacingAfterOpen"),t=t.split("( ").map(r=>r.trim()).join("(")),t.includes(" )")&&(e.push("removeParenSpacingBeforeClose"),t=t.split(" )").map(r=>r.trim()).join(")")),[kW,GW].forEach(r=>{const n=t.match(r);n!=null&&n.length&&(n.forEach(o=>{t=t.replace(o,o.slice(0,o.length-1)+" ")}),e.push("setsEndComma"))}),t=t.split(" ").filter(Boolean).map(Ru).join(" "),{score:t,applied:e}}function JW({score:t}){if(typeof t!="string")return{score:t};const e=p=>p==null?void 0:p.split("-").join("").split("/").join(""),r=p=>p.split("[").join("(").split("]").join(")");t=t.split(", ").join(" ");let n=t.split(" ");t=n.map(p=>{const v=/^-(\d+)$/;if(v.test(p)){const[f]=p.match(v).slice(1);if(f.length===2)return f.split("").join("-")}return p}).join(" "),n=t.split(" ");const o=n.filter(Du);let i=0,s="";for(const p of o){const v=hn(p,n).filter(h=>!i||h>i)[0],f=n.slice(i,v-1),m=n[v-1],g=e(m);if(/^\d+$/.test(g)&&g.length===2){const h=g.split(""),_=Math.abs(h.reduce((I,P)=>+I-+P));if(_===1){const I=[f.join(" "),[m,p].join("")].join(" ");s+=I,i=v+1}else if(_===0){const I=Math.max(...h);if([4,5,6,7,8,9].includes(I)){const P=[6,4].includes(I)?I+1:I-1,O=[I,P].sort().reverse().join("-"),y=[f.join(" "),[O,p].join("")].join(" ");s+=y,i=v+1}}}}if(o.length&&s.length){const p=n.slice(i).join(" ");return s=[s,p].join(" "),{score:s.trim()}}if(n.length===2&&["(","["].some(p=>n[1].includes(p))){const v=e(n[0]).split("");if(Math.abs(v.reduce((m,g)=>+m-+g,0))===1)return n[1]=r(n[1]),{score:n.join("")}}const a=n.map(p=>YW(p)&&"bracket"||ga(p)&&"set");if(a.includes("set")&&a.includes("bracket")){let p,v="";return n.forEach((f,m)=>{a[m]==="bracket"&&p==="set"?(f=r(f),v+=f):v+=` ${f}`,p=a[m]}),{score:v.trim()}}n=t.split(" ");let c,l=n.map(p=>{const v=new RegExp(/^(\d+)-(\d+)$/);if(v.test(p)){const[f,m]=p.match(v).slice(1),g=Math.abs([f,m].reduce((_,I)=>+_-+I)),h=Math.max(f,m);if(g===1)return c="tiebreakSet",c;if(g>=2&&h>=7&&c==="tiebreakSet")return c="tiebreak",c}});const u=hn("tiebreak",l);if(u.length){let p="";n.forEach((v,f)=>{u.includes(f)?p+=`(${v}) `:u.includes(f+1)?p+=`${v}`:p+=`${v} `}),t=p.trim()}const d=/(\d+-\d+)\((\d+)-(\d+)\)$/;if(d.test(t)){const[p,v,f]=t.match(d).slice(1),g=Math.max(v,f)>=10;!ga(p)&&g&&(t=t.replace(d,`${p} [${v}-${f}]`))}return l=[],t=t.split(" ").map(p=>{const v=/^\((.*)\)$/,f=v.test(p),m=new RegExp(dv).test(p)&&"super"||new RegExp(Bc).test(p)&&"tiebreak"||new RegExp(Mu).test(p)&&"standard"||"unknown";return l.push(m),m==="standard"&&f?p.match(v)[1]:p}).join(" "),{score:t}}function ZW({score:t,applied:e}){for(const b of[".",","," ","/"]){const N=new RegExp(`^(\\d+)\\${b}(\\d+)$`);if(N.test(t)){const w=t.match(N).slice(1).map(U=>parseInt(U)),$=Math.abs(w[0]-w[1]);$<=10&&$>=2&&(t=t.split(b).join("-"),e.push("variedJoinerPattern"))}}t.includes(";")&&(t=t.split(";").join(" "),e.push("semicolon set separation"));const r=/(^|\s)(\d)\/(\d)(\d)\/(\d)(\(|$)/;if(r.test(t)){const[b,N,w,$,U,A]=t.match(r).slice(1);t=t.replace(r,`${b}${N}-${w} ${$}-${U}${A}`),e.push("smashSlashPattern")}/.*\s6[/-]+$/.test(t)&&(t+="0",e.push("incompleteFinalSetPattern"));const o=/\(6,\)/g;o.test(t)&&(t=t.replace(o,"(6, 0)"),e.push("missingZeroPattern1"));const i=/^\d{3,}\(/,s=/\(\d+\)\d+/;[i,s].forEach(()=>{t=t.split(" ").map(N=>(i.test(N)&&(N=N.replace("("," (")),s.test(N)&&(N=N.replace(")",") ")),N)).join(" "),e.push("spaceConsiderationPatterns")});let c=Ru(t);c!==t&&(t=c,e.push("deDashMash"));const l=/^(\d)[-/,]+(\d{2})[-/,]+(\d)$/;if(l.test(t)){const[b,N,w]=t.match(l).slice(1),[$,U]=N.split("");t=`${b}-${$} ${U}-${w}`,e.push("smashSetPattern")}const u=/^(\d+)[ -](\d+)$/,d=/^([\d -]+)\/([\d -]+)$/;if(d.test(t)){const[b,N]=t.match(d).slice(1),w=b.trim(),$=N.trim();if(u.test(w)&&u.test($)){const U=w.match(u).slice(1,3).join("-"),A=$.match(u).slice(1,3).join("-");t=`${U} ${A}`,e.push("slashSeparationPattern")}}const p=/^([\d -]+),([\d -]+)$/;if(p.test(t)){const[b,N]=t.match(p).slice(1),w=b.trim(),$=N.trim();if(u.test(w)&&u.test($)){const U=w.match(u).slice(1,3).join("-"),A=$.match(u).slice(1,3).join("-");t=`${U} ${A}`,e.push("commaSeparationPattern")}}const v=/^\d \d,/;if(v.test(t)){const b=t.match(v)[0],N=b.slice(0,b.length-1).split(" ").join("-");t=t.replace(b,N),e.push("singleSetCommaSeparationPattern")}let f=0;const m=/(\d+)-(\d{2})-(\d+)/;for(;m.test(t)&&f<3;){const[b,N,w]=t.match(m).slice(1),$=N.split(""),U=`${b}-${$[0]} ${$[1]}-${w}`;t=t.replace(m,U),e.push("noSetSeparationPattern"),f+=1}const g=/(^|\s)7-6\s(\d+)\s/g,h=t.match(g);if(h!=null&&h.length){const b=/(^|\s)7-6\s(\d+)\s/;h.forEach(N=>{const w=N.match(b).slice(2)[0];t=t.replace(N,`7-6(${w}) `),e.push("floatingTiebreakPattern1")})}let _=t.match(/\d \d /);_==null||_.forEach(b=>{const N=b.slice(0,b.length-1).split(" ").join("-");t=t.replace(b,N),e.push("spaceSeparatedSetPattern1")}),_=t.match(/ \d \d$/),_==null||_.forEach(b=>{const N=" "+b.slice(1).split(" ").join("-");t=t.replace(b,N),e.push("spaceSeparatedSetPattern2")});const I=/^\d, *\d\/\d, *\d/;if(I.test(t)){const b=t.match(I)[0],N=b.split("/").map(w=>`(${w})`).join(" ")+" ";t=t.replace(b,N),e.push("slashCommaSetPattern")}const P=/\(6-\)/g;P.test(t)&&(t=t.replace(P,"(6-0)"),e.push("missingZeroPattern2"));const O=new RegExp("(?<!-)(\\d+)\\/(\\d+)(?!-)","g");if(O.test(t)){const b=t.match(O),N=new RegExp("(?<!-)(\\d+)\\/(\\d+)(?!-)");let w=t;b.forEach($=>{const[U,A]=$.match(N).slice(1),M=`${U}-${A}`;w=w.replace($,M)}),t=w,e.push("slashSetPattern")}const y=/(.*)\s(1\d)\s(\d+)$/;if(y.test(t)){const[b,N,w]=t.match(y).slice(1);b.replace(/\D/g,"").length>=4&&(t=b+` ${N}${w}`,e.push("spaceSeparatedSuperPattern"))}const S=/(^|\s)(\d+-\d+)\s(\d+)(\s|$)/g;for(const b of t.match(S)||[]){const[N,w,$,U]=b.match(/(^|\s)(\d+-\d+)\s(\d+)(\s|$)/).slice(1),[A,M]=w.split("-").map(D=>parseInt(D));Math.abs(A-M)===1&&(t=t.replace(b,`${N}${w}(${$})${U}`),e.push("spaceSeparatedSetPattern"))}const T=/\d-\d \(\d{1,2}\)(\s|$|,)/g;for(const b of t.match(T)||[]){const N=/(\d-\d) \((\d{1,2})\)(\s|$|,)/,[w,$,U]=b.match(N).slice(1),[A,M]=w.split("-").map(D=>parseInt(D));Math.abs(A-M)===1&&(t=t.replace(b,`${w}(${$})${U}`),e.push("floatingTiebreakPattern2"))}const E=/(^|\s)(\d \d)\(/g;for(const b of t.match(E)||[]){const N=/(^|\s)(\d \d)\(/,[w,$]=b.match(N).slice(1);t=t.replace(b,`${w}${$.split(" ").join("-")}(`),e.push("spacedTiebreakPattern")}return{score:t,applied:e}}function XW({score:t,matchUpStatus:e}){var r;let n=t==null?void 0:t.split(" ");t=n.map(c=>{if(c.endsWith("]")){const l=c.split("[");if(ga(l[0]))return l[0]+`(${l[1].slice(0,l[1].length-1)})`}return c}).join(" ");const o=new RegExp(/(\([\d ]+\))/g);if(o.test(t))for(const c of t.match(o)){let u=(r=c.replace(" ","-").match(/\((.*)\)/))==null?void 0:r[1];if(Ot(u)&&(u==null?void 0:u[0])>2){if([2,4].includes(u.length))u=u.split("").join("-");else if(u.length===3){const d=u.indexOf("1");u=ju(u.split(""),d)}}t=t.replace(c,`(${u})`)}n=t==null?void 0:t.split(" ");let i=new RegExp(/^(\d[-/]+\d)\((\d+)[-/]+(\d+)\)$/);const s=n.length-1;t=n.map((c,l)=>{const u=[void 0,"","COMPLETED"].includes(e)||l!==s;if(i.test(c)&&u){const[d,p,v]=Array.from(c.match(i)).slice(1),f=Math.min(p,v);return`${d}(${f})`}return c}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^(\d{2})\((\d+)\)$/),t=n.map(c=>{if(i.test(c)){const[l,u]=Array.from(c.match(i)).slice(1),d=l.split("");return`${d[0]}-${d[1]}(${u})`}return c}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^\((\d[-/]+\d)\)(\d+)$/),t=n.map(c=>{if(i.test(c)){const[l,u]=Array.from(c.match(i)).slice(1);return ga(l)?`${l}(${u})`:l}return c}).join(" "),n=t==null?void 0:t.split(" "),i=new RegExp(/^1-0\((\d+)\)$/),t=n.map(c=>{if(i.test(c)){const[l]=c.match(i).slice(1);return`[${l<9?10:parseInt(l)+2}-${l}]`}return c}).join(" ");const a=/\((\d)+0 /;if(a.test(t)){const c=t.match(a)[1];t=t.replace(a,`(${c}) `)}return{score:t}}function eH({score:t,attributes:e,identifier:r}){if(typeof t!="string")return{score:t,identifier:r};const n=new RegExp(/\([\d,/ ]+\)/g),o=t.match(n);for(const d of o||[]){const[p]=d.match(/^\((.*)\)$/).slice(1),f=t.split(d)[0].split(")").reverse()[0].replace(/\D/g,"");if(p.length===2&&(f==null?void 0:f.length)>=2){const h=f.slice(f.length-2).split("").map(I=>parseInt(I));if(Math.abs(h[0]-h[1])===1)continue}const m=ES(p),g=Ru(m);t=t.replace(d,`(${g})`).trim()}const i=new RegExp(/\[[\d,/ ]+\]/g),s=t.match(i);s==null||s.forEach(d=>{const p=ES(d.match(/^\[(.*)\]$/)[1]);t=t.replace(d,`(${p}) `).trim()});const a=[")","]"],c=[")(","), (",") (",")[",") [","](","] ("];if(t.startsWith("(")&&a.some(d=>t.endsWith(d))&&c.some(d=>t.includes(d))){let d="";const p=t.split(/[)\]]/).filter(Boolean).map(h=>(h.startsWith(",")&&(h=h.slice(1)),h.trim())),v=p.every(h=>h.includes(",")||Du(h)),f=p.every(h=>h.includes("/")||Du(h)),m=p.every(h=>h.includes("-")||Du(h)),g=v&&","||m&&"-"||f&&"/";if(g){let h;p.forEach(_=>{if(_.startsWith("("))if(h==="set"&&(d+=" "),_.includes(g))d+=_.slice(1).split(g).map(I=>I.trim()).join("-"),h="set";else{const I=_.slice(1);d+=`(${I}) `,h="tiebreak"}else if(_.startsWith("[")){const I=_.slice(1).split(g).map(O=>parseInt(O.trim())),P=Math.min(...I);h==="set"?d+=`(${P}) `:d+=`[${I.join("-")}] `,h="tiebreak"}}),t=d.trim()}}let l=mr(t.split(""));l["("]===1&&l[")"]===1&&t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,t.length-1),l["-"]===1&&ga(t)&&Ot(e==null?void 0:e.removed)&&(t=t+`(${e.removed})`,e.removed=void 0));const u=/\(\)/g;return u.test(t)&&(t=t.replace(u,"").trim()),{score:t}}function wS({score:t}){const e=t.split(""),r=[];let n;const o=()=>n=[void 0,void 0,void 0],i=()=>{let a=`${n[0]}-${n[1]}`;return n[2]&&(a+=` (${n[2]})`),o(),n.push(n),a};o();const s=()=>n[0]!==void 0&&n[1]!==void 0&&Math.abs(parseInt(n[0])-parseInt(n[1]));for(;e.length;){const a=e.shift(),c=Ot(a)&&parseInt(a),l=n[0]!==void 0&&n[1]!==void 0;if(Ot(c)){if(n[0]===void 0){n[0]=c;continue}if(n[1]===void 0&&(n[1]=c,s()>1)){r.push(i()),n=[void 0,void 0];continue}if(l&&e.length===1&&Ot(e[0])){const u=e.pop();n[0]=n[0].toString()+n[1].toString(),n[1]=u,r.push(i()),n=[void 0,void 0]}l&&s()}}return{sets:r}}function pv(t){const e=t.indexOf("1"),r=t.split(""),n=r.every(o=>!isNaN(o));if(n&&t.length===3&&e===0){const o=ju(r,e);if(o)return o}if(n&&t.length===7&&e>3){const o=r.slice(4),i=ju(o,e-4);if(i)return`${r[0]}-${r[1]} ${r[2]}-${r[3]} ${i}`}}function $S({score:t,applied:e,matchUpStatus:r}){const n=t==null?void 0:t.toString().split(""),o=n==null?void 0:n.every(s=>Ot(s)),i=s=>Math.abs(s[0]-s[1]);if(typeof t=="number"||o){t=t.toString().toLowerCase(),o&&(t=n.join(""));const s=o?n.map(a=>parseInt(a)):t.split("").map(a=>parseInt(a));if(wS({score:t}),s.length,t.length===3&&i(s.slice(0,2))===1){const[a,c,l]=s;t=`${a}-${c}(${l})`,e.push("numericTiebreakPattern1")}else if(t.length===3&&s[0]===1){const[a,c,l]=s;t=`[${a}${c}-${l}]`,e.push("numericTiebreakPattern2")}else if(t.length===4&&i(s.slice(0,2))===1&&"987654".split("").includes(s[0].toString())){const[a,c,l,u]=s,d=Math.min(l,u);t=`${a}-${c}(${d})`,e.push("numericTiebreakPattern3")}else if(t.length===4&&s[0]===1&&s[2]===1){const[a,c,l,u]=s;t=`[${a}${c}-${l}${u}]`,e.push("bigSuper")}else if(t.length===4){const[a,c,l,u]=s;t=`${a}${c} ${l}${u}`,e.push("split4")}else if(t.length===5&&i(s.slice(0,2))===1){const[a,c,l,u,d]=s;t=`${a}-${c}(${l}) ${u}-${d}`,e.push("numericTiebreakPattern4")}else if(t.length===5&&i(s.slice(3))===1){const[a,c,l,u,d]=s;t=`${a}-${c} ${l}-${u}(${d})`,e.push("numericTiebreakPattern5")}else if(s.length===7)if(i(s.slice(0,2))>1&&i(s.slice(2,4))>1&&s[4]===1){const[a,c,l,u,d,p,v]=s;t=`${a}-${c} ${l}-${u} [${d}${p}-${v}]`,e.push("numericTiebreakPattern6")}else if(i(s.slice(0,2))===1&&i(s.slice(3,5))>1&&i(s.slice(5,7))>1){const[a,c,l,u,d,p,v]=s;t=`${a}-${c}(${l}) ${u}-${d} ${p}-${v}`,e.push("numericTiebreakPattern7")}else if(i(s.slice(0,2))>1&&i(s.slice(2,4))===1&&i(s.slice(5,7))>1){const[a,c,l,u,d,p,v]=s;t=`${a}-${c} ${l}-${u}(${d}) ${p}-${v}`,e.push("numericTiebreakPattern8")}else if(i(s.slice(0,2))>1&&i(s.slice(2,4))>1&&i(s.slice(4,6))===1){const[a,c,l,u,d,p,v]=s;t=`${a}-${c} ${l}-${u} ${d}-${p}(${v})`,e.push("numericTiebreakPattern9")}else t=t.slice(0,2)+" "+t.slice(2,4)+" "+t.slice(4),e.push("numericMatchTiebreakPattern");else if(t.length%2){const a=pv(t);a&&t!==a&&e.push("parsedSuperPattern"),t=a||t}else{const a=Rt(t.split(""),2).map(m=>m.join("")),c=a.map(m=>{const[g,h]=m.split("").map(P=>parseInt(P)),_=Math.abs(g-h),I=g>h?1:2;return _>1&&I||I*-1}),l=c.reduce((m,g)=>m>0&&g>0,1),u=mr(c),d=c.map(m=>Math.abs(m)),p=mr(d),v=c[0]<0,f=!v&&c[1]<0;if(c[0]>0&&c[1]>0&&c[0]!==c[1])t=[a.slice(0,2).join(" "),a.slice(2).join("-")].join(" "),e.push("numeric3rdSetTiebreakPattern");else if(l)t=a.join(" "),e.push("chunkSplit");else if(s.length==6){if(u[1]==2||u[2]===2)if(!Object.values(p).includes(3))t=a.join(" "),e.push("chunkSplit");else{const[m,g,h,_,I,P]=s,O=c.reduce((y,S,T)=>S<0?T:y,void 0);if(O===0){const y=Math.min(h,_);t=`${m}-${g}(${y}) ${I}-${P}`,e.push("chunkSplitTiebreak1")}else if(O===1){const y=Math.min(I,P);t=`${m}-${g} ${h}-${_}(${y})`,e.push("chunkSplitTiebreak2")}else t=`${m}-${g} ${h}-${_}`,e.push("chunkSplitTrimExtraneous")}}else if(s.length===8){const[m,g,h,_,I,P,O,y]=s;v||f?s[5]===1&&(v?t=`${m}-${g}(${h}) ${_}-${I} [${P}${O}-${y}]`:t=`${m}-${g} ${h}-${_}(${I}) [${P}${O}-${y}]`):(c[0],c[1])}}}return{score:t,applied:e,matchUpStatus:r}}function NS(t){const e=[0,0],r=[],n=t.split(" "),o=/(\d+)-(\d+)/;n.forEach(c=>{if(o.test(c)){const l=c.match(o).slice(1).map(d=>parseInt(d)),u=l[0]>l[1]&&1||l[1]>l[0]&&2;u&&(e[u-1]+=1,r.push(u))}});const i=e[0]>e[1]&&1||e[1]>e[0]&&2,s=e[0]>0&&e[0]===e[1],a=e.reduce((c,l)=>c+l,0);return{setsWon:e,setsTied:s,setWinners:r,totalSets:a,winningSide:i}}function tH({score:t,matchUpStatus:e,attributes:r}){const n=[];let o;const i=t.split(" "),s=i.length;t=i.map((u,d)=>{if(new RegExp(Bc).test(u)){const v=u.slice(3),f=u.slice(0,3),m=f.split("-");if(!ga(f)&&!e){const g=Math.max(...m),h=f.indexOf(g),_=[g,g-1];return(h?_.reverse().join("-"):_.join("-"))+v}}else if(u.length===2&&Ot(u))return u.split("").join("-");u=Ru(u);const p=new RegExp(`^${dv}$`).test(u)&&"super"||new RegExp(`^${Bc}$`).test(u)&&"tiebreak"||new RegExp(`^${Mu}$`).test(u)&&"standard"||"unknown";if(n.push(p),s>1&&p==="standard"&&d<2){const[v,f]=u.split("-"),m=Math.abs(parseInt(v)-parseInt(f)),g=Math.max(v,f),h=Math.min(v,f),_=[parseInt(v),parseInt(f)].indexOf(h);if(g>9&&m>2){const I=g.toString().split(""),P=I.find(O=>parseInt(O)>h||d&&parseInt(O)<=o)||I[0];P&&(u=_?[P,h].join("-"):[h,P].join("-"))}g>(o||0)&&(o=g)}if(p==="standard"){const[v,f]=u.split("-");if(!Math.abs(parseInt(v)-parseInt(f))&&e!=="RETIRED")return""}return u}).filter(Boolean).join(" ");const{setsWon:a,setWinners:c,totalSets:l}=NS(t);if(l===1&&(r==null?void 0:r.removed)==="6"&&(t+=" 6-0"),t.split(" ").length>2&&Math.max(...a)>=2&&c[0]===c[1]&&(t=t.split(" ").slice(0,2).join(" ")),Math.max(...a)>2){let u=[0,0];t=t.split(" ").map((d,p)=>(u[c[p]]+=1,Math.max(...u)>2?void 0:d)).filter(Boolean).join(" ")}return{score:t,profile:n}}function rH({score:t}){const{setsTied:e,winningSide:r}=NS(t),n=/\s\((\d+)\)$/;if(!r&&e&&n.test(t)){const a=t.match(n).slice(1)[0],c=a<=8?10:a+2;t=t.replace(n,` [${c}-${a}]`)}const o=t.split(" "),i=o[o.length-1];if(!i.includes("-")||i.indexOf("(")>0)return{score:t};let s=i.split("(").join("").split(")").join("").split("-");if(!s.every(a=>Ot(a)))return{score:t};if(s[0]==="76"){const a=s[1].length===2?Math.min(...s[1].split("").map(c=>parseInt(c))):s[1];t=[...o.slice(0,o.length-1),`7-6(${a})`].join(" ")}else{s=s.map(l=>parseInt(l));const a=Math.max(...s);let c=Math.abs(s[0]-s[1]);if(a>=10){if(c>2&&s.every(l=>+l>=10)){const l=s.map(u=>u===a?u-10:10).sort();c=Math.abs(l[0]-l[1]),c>2&&(s=l)}t=[...o.slice(0,o.length-1),`[${s.join("-")}]`].join(" ")}else o.length===3&&a>=7&&c>2&&(t=[...o.slice(0,o.length-1),`[${s.join("-")}]`].join(" "))}return{score:t}}function nH({score:t}){return t=(t==null?void 0:t.toString().toLowerCase())||"",{score:t}}function oH({score:t,applied:e}){return typeof t!="string"?{score:t}:(t.toLowerCase().includes("o")&&(t=t.toLowerCase().split(" ").map(r=>r.split("o").join("0")).join(" "),e.push("replaceOh")),{score:t,applied:e})}function iH({score:t,applied:e}){return typeof t!="string"?{score:t}:(t=t.toLowerCase().split(" ").map(r=>{if(/^\d+$/.test(r)&&r.length>2){const n=r.indexOf("1");if(r.length%2){if(r.length===3&&n===0){const o=ju(r.split(""),n);return e.push("getSuper"),o}}else{const{score:o,applied:i}=$S({score:r,applied:[]});o!==r&&(r=o,e.push(...i))}}return r}).join(" "),{score:t,applied:e})}function sH({score:t,applied:e}){return typeof t!="string"?{score:t}:[3,4].includes(t.length)&&pv(t)?{score:pv(t)}:(t=t.toLowerCase().split(" ").map(r=>{if(/^\d+$/.test(r)&&r.length===1){e.push("removeErroneous1");return}return r}).filter(Boolean).join(" "),{score:t,applied:e})}function aH({score:t,applied:e}){return["walkover","wo","w/o","w-o"].includes(t==null?void 0:t.toString().toLowerCase())?(e.push("handleWalkover"),{matchUpStatus:"walkover",score:"",applied:e}):{score:t}}function cH({score:t,profile:e,applied:r}){var n;t=t==null?void 0:t.toString().toLowerCase();const o=/^(.*\d+.*)(ret|con)+[A-Za-z ]*$/;if(o.test(t)){const[c]=t.match(o).slice(1);return r.push("handleRetired"),{score:c.trim(),matchUpStatus:"retired",applied:r}}const i=(n=e==null?void 0:e.matchUpStatuses)==null?void 0:n.retired,a=["rtd",...Array.isArray(i)?i:[i].filter(Boolean)].find(c=>t==null?void 0:t.endsWith(c));return a?(r.push("handleRetired"),{matchUpStatus:"retired",score:t==null?void 0:t.replace(a,"").trim(),applied:r}):{score:t}}function lH({score:t,attributes:e}){(t.endsWith(" am")||t.endsWith(" pm"))&&(t=""),t=t.replace(/[A-Za-z]+/g,"").trim(),[".",","].some(o=>t.endsWith(o))&&(t=t.slice(0,t.length-1));const r="()/-".split("").some(o=>t.includes(o));/ \d$/.test(t)&&r&&(e={removed:t.slice(t.length-2).trim()},t=t.slice(0,t.length-2));const n=/(.*)[A-Za-z]+$/;return n.test(t)&&(t=t.match(n).slice(1)[0].trim()),{score:t,attributes:e}}function uH({score:t}){return new RegExp(/-\d+\/\d+-/).test(t)&&(t=t.split("/").join(" ")),{score:t}}function dH({score:t}){const e=new RegExp(/^\d+\/\d+/),r=t.split(" ");r.some(o=>e.test(o))&&(t=r.map(o=>e.test(o)?o.replace("/","-"):o).join(" "));const n=/^(\d+), *(\d+)$/;if(n.test(t)){const[o,i]=t.match(n).slice(1);t=[o,i].join("-")}return{score:t}}function pH({score:t}){const e=new RegExp(/\(\d+\/\d+\)/g),r=t.match(e);for(const n of r||[]){const o=n.replace("/","-");t=t.replace(n,o)}return{score:t}}function fH({score:t}){if(t.includes(",")){const e=t.split(",").map(o=>o.trim()),r=o=>/\d \d/.test(o);e.every(r)&&(t=e.map(o=>{const i=/\d+ \d+/g;for(const s of o.match(i)){const[a,c]=s.match(/(\d+) (\d+)/).slice(1);o=o.replace(s,`${a}-${c}`)}return o}).join(" "))}if(t.includes(" ")){const e=t.replace(/[ ,]/g,"");e.split("").every(n=>Ot(n))&&e.length===4&&(t=e)}return{score:t}}function vH({score:t}){const e=new RegExp(/^\[\d+\](.*)$/);e.test(t)&&(t=t.match(e).slice(1)[0].trim());const r=/\(,/g;return r.test(t)&&(t=t.replace(r,"(")),{score:t}}const mH={handleTiebreakSlashSeparation:pH,handleSetSlashSeparation:uH,punctuationAdjustments:KW,handleGameSeparation:dH,joinFloatingTiebreak:JW,handleBracketSpacing:QW,handleSpaceSeparator:fH,separateScoreBlocks:iH,matchKnownPatterns:ZW,removeDanglingBits:lH,removeErroneous:sH,handleWalkover:aH,properTiebreak:XW,handleNumeric:$S,handleRetired:cH,containedSets:eH,sensibleSets:tH,stringScore:nH,superSquare:rH,setBuilder:wS,excisions:vH,replaceOh:oH};let fv={};const gH=["handleNumeric","handleWalkover","handleRetired","replaceOh","stringScore","punctuationAdjustments","excisions","handleSpaceSeparator","matchKnownPatterns","removeDanglingBits","handleBracketSpacing","matchKnownPatterns","containedSets","separateScoreBlocks","handleGameSeparation","removeErroneous","joinFloatingTiebreak","handleSetSlashSeparation","handleTiebreakSlashSeparation","properTiebreak","sensibleSets","superSquare"],hH=["handleNumeric","separateScoreBlocks","sensibleSets","superSquare"];function _H({score:t,stepLog:e,fullLog:r,profile:n,identifier:o,fileName:i,sheetName:s}){let a=[],c,l=[],u,d,p=t;const v=m=>{m.forEach(g=>{d=mH[g]({profile:n,identifier:o,matchUpStatus:c,attributes:u,applied:l,score:p});const h=d.score!==p;h&&a.push({method:g,score:d.score}),e&&(r||h||d.matchUpStatus!==c)&&console.log(c?{score:d.score,matchUpStatus:c}:{score:d.score},g),d.matchUpStatus&&(c=d.matchUpStatus),d.attributes&&(u=d.attributes),d.applied&&(l=d.applied),p=d.score})};v(gH);let f=TS(p);return f||(p=t.toString().replace(/\D/g,""),u!=null&&u.removed&&(u.removed=void 0),v(hH),f=TS(p),f||(p="")),l.forEach(m=>{fv[m]||(fv[m]=0),fv[m]+=1}),{score:p,matchUpStatus:c==null?void 0:c.toUpperCase(),modifications:a,isValid:f}}var IH=Object.defineProperty,AS=Object.getOwnPropertySymbols,PH=Object.prototype.hasOwnProperty,yH=Object.prototype.propertyIsEnumerable,US=(t,e,r)=>e in t?IH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,CS=(t,e)=>{for(var r in e||(e={}))PH.call(e,r)&&US(t,r,e[r]);if(AS)for(var r of AS(e))yH.call(e,r)&&US(t,r,e[r]);return t};const{FACTORY:MS}=A_;function Fu({tournamentRecord:t,value:e}){const{extension:r}=Or({element:t,name:MS}),n={name:MS,value:CS(CS({},r==null?void 0:r.value),e)};tt({element:t,extension:n})}function bi({mutationStatus:t,tournamentId:e,directives:r,timeStamp:n}={}){const{topics:o}=Pn();for(const i of[...o].sort(SH)){const s=xL({topic:i});s&&Xh({topic:i,notices:s})}t&&n&&o.includes(MI)&&Xh({notices:[{tournamentId:e,directives:r,timeStamp:n}],topic:MI})}const DS={[jI]:5,[DI]:5,[RI]:5,[CI]:5,[UI]:5,[NI]:5,[gB]:5,[hB]:5,[AI]:1,[hf]:1,[Ht]:5,[Ji]:5,[$I]:4,[TI]:4,[EI]:4,[wI]:4,[gf]:3,[SI]:2};function SH(t,e){return(DS[e]||0)-(DS[t]||0)}function ms({tournamentRecords:t,convertExtensions:e,ignoreDisabled:r,venueIds:n=[],dates:o}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const i=[],s=[],a=[],c=[];return Object.keys(t).forEach(u=>{const d=t[u];for(const p of d.venues||[])if(d.venues,!(n.length&&!n.includes(p.venueId))){if(r){const{extension:v}=Or({name:en,element:p});if(v!=null&&v.value)continue}i.includes(p.venueId)||(a.push(ue(p,e,!0)),i.push(p.venueId));for(const v of p.courts||[])if(!s.includes(v.courtId)){if(r&&o){const{extension:m}=Or({name:en,element:v});if(_I({extension:m,dates:o}))continue}const{inContextCourt:f}=yI({convertExtensions:e,ignoreDisabled:r,venue:p,court:v});c.push(f),s.push(v.courtId)}}}),{courts:c,venues:a}}function vv({tournamentRecords:t,requireCourts:e,dates:r}){return typeof t!="object"||!Object.keys(t).length?{error:Fe}:Object.keys(t).reduce((o,i)=>{const s=t[i],{venues:a}=_f({tournamentRecord:s,dates:r});return a.forEach(c=>{const{venueId:l,courts:u}=c;(!e||(u==null?void 0:u.length))&&!o.venueIds.includes(l)&&(o.venues.push(c),o.venueIds.push(l))}),o},{venues:[],venueIds:[]})}var OH=Object.defineProperty,jS=Object.getOwnPropertySymbols,bH=Object.prototype.hasOwnProperty,TH=Object.prototype.propertyIsEnumerable,RS=(t,e,r)=>e in t?OH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,FS=(t,e)=>{for(var r in e||(e={}))bH.call(e,r)&&RS(t,r,e[r]);if(jS)for(var r of jS(e))TH.call(e,r)&&RS(t,r,e[r]);return t};function kc({duplicateValues:t=!0,creationTime:e=!0,removePriorValues:r,timeItem:n,element:o}){if(!n)return{error:Vh};if(!o)return{error:Oe,info:uf};const i=n&&Object.keys(n),s=["itemType","itemValue"];if(!(s.filter(l=>i.includes(l)).length===s.length))return{error:Lh};if(!o.timeItems)o.timeItems=[];else{const{itemType:l,itemSubTypes:u,itemValue:d}=n,{timeItem:p}=fn({itemSubTypes:u,itemType:l,element:o});if(JSON.stringify(p==null?void 0:p.itemValue)===JSON.stringify(d)&&!t)return FS({},B)}if(n.itemSubTypes&&!n.itemSubTypes.length&&delete n.itemSubTypes,e){const l=new Date().toISOString();Object.assign(n,{createdAt:l})}return r&&(o.timeItems=o.timeItems.filter(({itemType:l})=>n.itemType!==l)),r&&!n.itemValue||o.timeItems.push(n),FS({},B)}function LS({creationTime:t=!0,removePriorValues:e,tournamentRecord:r,duplicateValues:n,participantId:o,timeItem:i}){if(!r)return{error:ee};if(!o)return{error:yt};const s=Ro({tournamentRecord:r,participantId:o});return s.error?s:kc({element:s.participant,removePriorValues:e,duplicateValues:n,creationTime:t,timeItem:i})}function bo({removePriorValues:t,tournamentRecord:e,duplicateValues:r,creationTime:n,timeItem:o}){return e?kc({element:e,removePriorValues:t,duplicateValues:r,creationTime:n,timeItem:o}):{error:ee}}function zo({removePriorValues:t,duplicateValues:e,creationTime:r,timeItem:n,event:o}){return o?kc({removePriorValues:t,duplicateValues:e,element:o,creationTime:r,timeItem:n}):{error:Ir}}var EH=Object.defineProperty,VS=Object.getOwnPropertySymbols,wH=Object.prototype.hasOwnProperty,$H=Object.prototype.propertyIsEnumerable,xS=(t,e,r)=>e in t?EH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,NH=(t,e)=>{for(var r in e||(e={}))wH.call(e,r)&&xS(t,r,e[r]);if(VS)for(var r of VS(e))$H.call(e,r)&&xS(t,r,e[r]);return t};function hr({removePriorValues:t,tournamentRecord:e,duplicateValues:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:s,event:a}){const{matchUp:c}=nt({drawDefinition:n,event:a,matchUpId:i});if(!c)return{error:kr};const l=kc({removePriorValues:t,element:c,duplicateValues:r,timeItem:s});return o||Qe({tournamentId:e==null?void 0:e.tournamentId,eventId:a==null?void 0:a.eventId,context:"addTimeItem",drawDefinition:n,matchUp:c}),l}function AH({tournamentRecord:t,drawDefinition:e,matchUpId:r,event:n}){const{matchUp:o}=nt({drawDefinition:e,event:n,matchUpId:r});return o?(o.timeItems=[],Qe({tournamentId:t==null?void 0:t.tournamentId,context:"resetTimeItems",eventId:n==null?void 0:n.eventId,drawDefinition:e,matchUp:o}),NH({},B)):{error:kr}}function Lu({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,courtDayDate:i,matchUpId:s,courtIds:a}){if(!r&&!e)return{error:ee};if(!s)return{error:Ut};const c=nt({drawDefinition:n,matchUpId:s});if(c.error)return c;if(c.matchUp.matchUpType!==Zr)return{error:Gr};if(!(a===void 0||Array.isArray(a)&&a.length&&a.every(p=>typeof p=="string")))return{error:Z,context:{courtIds:a}};let u;if(a){const p=e||{[r.tournamentId]:r},v=ms({tournamentRecords:p});if(v.error)return v;const f=v.courts.filter(m=>a.includes(m.courtId));if(f.length!==a.length)return{error:Z,context:{courtIds:a}};u=f.map(m=>({venueId:m.venueId,courtId:m.courtId}))}return hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,timeItem:{itemType:Vo,itemDate:i,itemValue:u}})}function ha({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,venueId:s}){if(!r)return{error:ee};if(!i)return{error:Ut};if(s){const c=Lo({tournamentRecords:e,tournamentRecord:r,venueId:s});if(c.error)return c}return hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:{itemType:vc,itemValue:s}})}function gs({removePriorValues:t,tournamentRecords:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,courtDayDate:i,matchUpId:s,courtId:a}){var c;if(!r&&!e)return{error:ee};if(!s)return{error:Ut};if(a){const u=Zi({tournamentRecords:e,tournamentRecord:r,courtId:a});if(u.error)return u;const d=(c=u.venue)==null?void 0:c.venueId;ha({tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,venueId:d})}return hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:s,timeItem:{itemType:Xi,itemDate:i,itemValue:a}})}function UH({matchUps:t,matchUpId:e}){if(!Array.isArray(t))return{error:Z};const r=t.find(a=>a.matchUpId===e),{drawId:n,eventId:o,structureId:i,tournamentId:s}=r||{};return{matchUpId:e,drawId:n,eventId:o,structureId:i,tournamentId:s}}var CH=Object.defineProperty,BS=Object.getOwnPropertySymbols,MH=Object.prototype.hasOwnProperty,DH=Object.prototype.propertyIsEnumerable,kS=(t,e,r)=>e in t?CH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jH=(t,e)=>{for(var r in e||(e={}))MH.call(e,r)&&kS(t,r,e[r]);if(BS)for(var r of BS(e))DH.call(e,r)&&kS(t,r,e[r]);return t};function Ti({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,scheduledTime:o,matchUpId:i,matchUp:s}){if(!i)return{error:Ut};if(!Bs(o))return{error:Wr};if(!s){const v=nt({drawDefinition:r,matchUpId:i});if(v.error)return v;s=v.matchUp}const a=Ce(o),c="addMatchUpScheduledTime";if(a){const v=mi({matchUp:s}).scheduledDate;if(v&&v!==a)return W({info:`date in time: ${a} does not corresponde to scheduledDate: ${v}`,result:{error:Wr},stack:c})}let l=Of({matchUp:s}).timeModifiers||[];if(l!=null&&l.length){const v=mv({disableNotice:!0,removePriorValues:t,tournamentRecord:e,timeModifiers:[],drawDefinition:r,matchUpId:i,matchUp:s});if(v!=null&&v.error)return v}const d=Vi(o,!0,!0);return hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:{itemType:gc,itemValue:d}})}function mv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,timeModifiers:o,matchUpId:i,matchUp:s}){if(!i)return{error:Ut};if(o!==void 0&&!Array.isArray(o))return{error:Z,info:zt("timeModifiers")};let a=Of({matchUp:s}).timeModifiers||[];const c=o.filter(p=>!a.includes(p));if(o.length&&!c.length)return jH({},B);if(c.some(p=>rP.includes(p))){a=a.filter(v=>!rP.includes(v));const p=Ti({disableNotice:!0,removePriorValues:t,scheduledTime:"",tournamentRecord:e,drawDefinition:r,matchUpId:i});if(p.error)return p}const u=o!=null&&o.length?[...c,...a]:void 0;return hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:{itemType:tP,itemValue:u}})}var RH=Object.defineProperty,FH=Object.defineProperties,LH=Object.getOwnPropertyDescriptors,GS=Object.getOwnPropertySymbols,VH=Object.prototype.hasOwnProperty,xH=Object.prototype.propertyIsEnumerable,WS=(t,e,r)=>e in t?RH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,HS=(t,e)=>{for(var r in e||(e={}))VH.call(e,r)&&WS(t,r,e[r]);if(GS)for(var r of GS(e))xH.call(e,r)&&WS(t,r,e[r]);return t},BH=(t,e)=>FH(t,LH(e));function Dn(t,e){const r=r_.test(t)?t:rt(t),n=Ce(t)||Ce(e)||On(new Date);return new Date(`${n}T${r}`)}function Vu({errorOnAnachronism:t=!1,checkChronology:e=!0,matchUpDependencies:r,inContextMatchUps:n,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,disableNotice:c,drawMatchUps:l,matchUpId:u,schedule:d,event:p}){var v;if(!d)return{error:Oe,info:"Missing schedule"};if(!a)return{error:pe};if(!u)return{error:Ut};const f="drawEngine.addMatchUpScheduleItems";let m,g;if(l)m=l.find($=>$.matchUpId===u);else{const $=nt({drawDefinition:a,event:p,matchUpId:u});if($.error)return $;m=$.matchUp}const{endTime:h,courtId:_,courtIds:I,courtOrder:P,resumeTime:O,scheduledDate:y,scheduledTime:S,startTime:T,stopTime:E,timeModifiers:b,venueId:N}=d;e&&(!r||!n)&&({matchUpDependencies:r,matchUps:n}=Yr({drawDefinition:a}));const w=(v=r==null?void 0:r[u])==null?void 0:v.matchUpIds;if(d.scheduledDate&&e&&w){const $=n.filter(U=>{var A,M;return(((A=U.schedule)==null?void 0:A.scheduledDate)||Ce((M=U.schedule)==null?void 0:M.scheduledTime))&&w.includes(U.matchUpId)}).map(({schedule:U})=>{const A=Rl(U);return new Date(A).getTime()});if($!=null&&$.length){const U=Rl(d),A=new Date(U).getTime();if(Math.max(...$)>=A){if(t)return W({result:{error:uh},stack:f});g=uh}}}if(y!==void 0){const $=gv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,scheduledDate:y,matchUpId:u});if($!=null&&$.error)return W({result:$,stack:f,context:{scheduledDate:y}})}if(S!==void 0){const $=Ti({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,scheduledTime:S,matchUpId:u,matchUp:m});if($!=null&&$.error)return W({result:$,stack:f,context:{scheduledTime:S}})}if(T!==void 0){const $=_v({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,startTime:T,matchUp:m,event:p});if($!=null&&$.error)return W({result:$,stack:f,context:{startTime:T}})}if(E!==void 0){const $=Pv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,stopTime:E,matchUp:m,event:p});if($!=null&&$.error)return W({result:$,stack:f,context:{stopTime:E}})}if(O!==void 0){const $=yv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,resumeTime:O,matchUpId:u,matchUp:m,event:p});if($!=null&&$.error)return W({result:$,stack:f,context:{resumeTime:O}})}if(h!==void 0){const $=Iv({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,endTime:h,matchUp:m,event:p});if($!=null&&$.error)return W({result:$,stack:f,context:{endTime:h}})}if(I!==void 0){const $=Lu({disableNotice:!0,removePriorValues:o,tournamentRecord:s,drawDefinition:a,matchUpId:u,courtIds:I});if($!=null&&$.error)return W({result:$,stack:f,context:{courtIds:I}})}if(_!==void 0&&y!==void 0){const $=gs({courtDayDate:y,disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,matchUpId:u,courtId:_});if($!=null&&$.error)return W({result:$,stack:f,context:{courtId:_}})}if(N!==void 0){const $=ha({disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,matchUpId:u,venueId:N});if($!=null&&$.error)return W({result:$,stack:f,context:{venueId:N}})}if(P!==void 0&&ut(P)){const $=hv({disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,courtOrder:P,matchUpId:u});if($!=null&&$.error)return W({result:$,stack:f,context:{courtOrder:P}})}if(b!==void 0){const $=mv({disableNotice:!0,removePriorValues:o,tournamentRecords:i,tournamentRecord:s,drawDefinition:a,timeModifiers:b,matchUpId:u,matchUp:m});if($!=null&&$.error)return W({result:$,stack:f,context:{timeModifiers:b}})}return c||Qe({tournamentId:s==null?void 0:s.tournamentId,eventId:p==null?void 0:p.eventId,context:f,drawDefinition:a,matchUp:m}),g?BH(HS({},B),{warnings:[g]}):HS({},B)}function gv({scheduledDate:t,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i}){if(!i)return{error:Ut};const s=Sn.test(t);if(t&&!s)return{error:cr};const c={itemValue:Ce(t),itemType:mc};return hr({duplicateValues:!1,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:c})}function hv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,courtOrder:o,matchUpId:i}){if(!i)return{error:Ut};if(o&&!ut(o))return{error:Z,info:"courtOrder must be numeric"};const s=parseInt(o);return hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:{itemType:eP,itemValue:s}})}function qS({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,participantId:o,officialType:i,matchUpId:s}){return s?hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:s,timeItem:{itemType:"SCHEDULE.ASSIGNMENT.OFFICIAL",itemSubTypes:[i],itemValue:o}}):{error:Ut}}function _v({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,startTime:i,event:s}){if(!o)return{error:Ut};if(!Bs(i))return{error:Wr};const{matchUp:a}=nt({drawDefinition:r,event:s,matchUpId:o}),{scheduledDate:c}=mi({matchUp:a}),u=(a.timeItems||[]).filter(d=>[xo,go,Bo].includes(d==null?void 0:d.itemType)).map(d=>Dn(d.itemValue,c)).reduce((d,p)=>!d||p<d?p:d,void 0);if(!u||Dn(i,c)<u){a.timeItems&&(a.timeItems=a.timeItems.filter(v=>v.itemType!==wn));const d=Vi(i,!0,!0);return hr({duplicateValues:!1,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,timeItem:{itemType:wn,itemValue:d}})}else return{error:JF}}function Iv({validateTimeSeries:t=!0,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,endTime:s,event:a}){if(!i)return{error:Ut};if(!Bs(s))return{error:Wr};const{matchUp:c}=nt({drawDefinition:n,event:a,matchUpId:i}),{scheduledDate:l}=mi({matchUp:c}),d=(c.timeItems||[]).filter(p=>[wn,go,xo].includes(p==null?void 0:p.itemType)).map(p=>Dn(p.itemValue,l)).reduce((p,v)=>!p||v>p?v:p,void 0);if(!t||!d||Dn(s,l)>d){c.timeItems&&(c.timeItems=c.timeItems.filter(f=>f.itemType!==Bo));const p=Vi(s,!0,!0);return hr({duplicateValues:!1,removePriorValues:e,tournamentRecord:r,drawDefinition:n,disableNotice:o,matchUpId:i,timeItem:{itemType:Bo,itemValue:p}})}else return{error:KF}}function Pv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,stopTime:i,event:s}){if(!o)return{error:Ut};if(!Bs(i))return{error:Wr};const{matchUp:a}=nt({drawDefinition:r,event:s,matchUpId:o}),{scheduledDate:c}=mi({matchUp:a}),l=a.timeItems||[];if(l.reduce((m,g)=>g.itemType===Bo||m,void 0))return{error:Fh};const d=l.filter(m=>[wn,go,xo].includes(m==null?void 0:m.itemType)).sort((m,g)=>Dn(m.itemValue,c)-Dn(g.itemValue,c)),p=d[d.length-1],v=p&&p.itemType===xo,f=d.filter(m=>!v||m.createdAt!==p.createdAt).map(m=>Dn(m.itemValue,c)).reduce((m,g)=>!m||g>m?g:m,void 0);if(Dn(i,c)>f){if(a.timeItems&&v){const h=p.createdAt;a.timeItems=a.timeItems.filter(_=>_.createdAt!==h)}const g={itemValue:Vi(i,!0,!0),itemType:xo};return hr({duplicateValues:!0,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:o,timeItem:g})}else return{error:QF}}function yv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,resumeTime:o,matchUpId:i,event:s}){if(!i)return{error:Ut};if(!Bs(o))return{error:Wr};const{matchUp:a}=nt({drawDefinition:r,event:s,matchUpId:i}),{scheduledDate:c}=mi({matchUp:a}),l=a.timeItems||[];if(l.reduce((m,g)=>g.itemType===Bo||m,void 0))return{error:Fh};const d=l.filter(m=>[wn,go,xo].includes(m==null?void 0:m.itemType)).sort((m,g)=>Dn(m.itemValue,c)-Dn(g.itemValue,c)),p=d[d.length-1],v=p&&p.itemType===go,f=d.filter(m=>!v||m.createdAt!==p.createdAt).map(m=>Dn(m.itemValue,c)).reduce((m,g)=>!m||g>m?g:m,void 0);if(Dn(o,c)>f){if(a.timeItems&&v){const h=p.createdAt;a.timeItems=a.timeItems.filter(_=>_.createdAt!==h)}const g={itemValue:Vi(o,!0,!0),itemType:go};return hr({duplicateValues:!0,removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,matchUpId:i,timeItem:g})}else return{error:ZF}}var kH=Object.defineProperty,GH=Object.defineProperties,WH=Object.getOwnPropertyDescriptors,YS=Object.getOwnPropertySymbols,HH=Object.prototype.hasOwnProperty,qH=Object.prototype.propertyIsEnumerable,zS=(t,e,r)=>e in t?kH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,KS=(t,e)=>{for(var r in e||(e={}))HH.call(e,r)&&zS(t,r,e[r]);if(YS)for(var r of YS(e))qH.call(e,r)&&zS(t,r,e[r]);return t},QS=(t,e)=>GH(t,WH(e));function JS({errorOnAnachronism:t=!1,checkChronology:e=!0,matchUpDependencies:r,tournamentRecords:n,tournamentRecord:o,matchUpDetails:i,matchUpIds:s,schedule:a}){var c,l,u;if(!o)return{error:ee};if(!i&&(!s||!Array.isArray(s)))return{error:Ka};if(!i&&(!a||typeof a!="object"))return{error:XF};let d;const p=[];let v=0;if(e&&!r){const g=Yr({tournamentRecords:n});r=g.matchUpDependencies,d=g.matchUps}d||(d=((c=Bt({tournamentRecord:o}))==null?void 0:c.matchUps)||[]);const f=d.reduce((g,h)=>{const{matchUpId:_,drawId:I}=h;return g[I]?g[I].push(_):g[I]=[_],g},{}),m=i==null?void 0:i.map(g=>g.matchUpId);for(const g of Object.keys(f)){const{drawDefinition:h}=Fo({tournamentRecord:o,drawId:g}),_=f[g].filter(P=>(s==null?void 0:s.includes(P))||(m==null?void 0:m.includes(P))),I=Dr({inContext:!1,drawDefinition:h}).matchUps;for(const P of _){const O=((l=i==null?void 0:i.find(S=>S.matchUpId===P))==null?void 0:l.schedule)||a,y=Vu({schedule:O,matchUpDependencies:r,errorOnAnachronism:t,inContextMatchUps:d,tournamentRecords:n,tournamentRecord:o,checkChronology:e,drawDefinition:h,drawMatchUps:I,matchUpId:P});if((u=y.warnings)!=null&&u.length&&p.push(...y.warnings),y.success&&(v+=1),y.error)return y}}return p.length?QS(KS({},B),{scheduled:v,warnings:p}):QS(KS({},B),{scheduled:v})}var YH=Object.defineProperty,zH=Object.defineProperties,KH=Object.getOwnPropertyDescriptors,ZS=Object.getOwnPropertySymbols,QH=Object.prototype.hasOwnProperty,JH=Object.prototype.propertyIsEnumerable,XS=(t,e,r)=>e in t?YH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eO=(t,e)=>{for(var r in e||(e={}))QH.call(e,r)&&XS(t,r,e[r]);if(ZS)for(var r of ZS(e))JH.call(e,r)&&XS(t,r,e[r]);return t},tO=(t,e)=>zH(t,KH(e));function rO({errorOnAnachronism:t,matchUpContextIds:e,tournamentRecords:r,checkChronology:n,matchUpDetails:o,schedule:i}){var s;if(!r)return{error:Fe};if(!Array.isArray(e)&&!Array.isArray(o))return{error:Z};if((!o||e)&&!i)return{error:Oe,info:"schedule is required"};const a=[];let c=0;const{matchUpDependencies:l}=Yr({tournamentRecords:r});for(const u of Object.values(r)){const{tournamentId:d}=u,p=e==null?void 0:e.filter(f=>f.tournamentId===d).map(Mt),v=o==null?void 0:o.filter(f=>(f==null?void 0:f.tournamentId)===d);if(p!=null&&p.length||v!=null&&v.length){const f=JS({matchUpDetails:v,matchUpDependencies:l,errorOnAnachronism:t,tournamentRecord:u,checkChronology:n,matchUpIds:p,schedule:i});if((s=f.warnings)!=null&&s.length&&a.push(...f.warnings),f.scheduled&&(c+=f.scheduled),f.error)return f}}return a.length?tO(eO({},B),{scheduled:c,warnings:a}):tO(eO({},B),{scheduled:c})}function xu({tournamentRecords:t}){return t?Object.keys(t).reduce((r,n)=>{r.tournamentIdMap[n]=[];const i=t[n].events||[],s=i.map(({eventId:c})=>c),a=i.map(c=>(c.drawDefinitions||[]).map(({drawId:l})=>l)).flat();return r.tournamentIdMap[n].push(...s,...a),r.eventIds.push(...s),r.drawIds.push(...a),r},{eventIds:[],drawIds:[],tournamentIdMap:{}}):{error:Fe}}function Sv({drawId:t,eventId:e,tournamentRecords:r}){const{tournamentIdMap:n}=xu({tournamentRecords:r});return Object.keys(n).find(o=>n[o].includes(e)||n[o].includes(t))}var ZH=Object.defineProperty,nO=Object.getOwnPropertySymbols,XH=Object.prototype.hasOwnProperty,eq=Object.prototype.propertyIsEnumerable,oO=(t,e,r)=>e in t?ZH(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tq=(t,e)=>{for(var r in e||(e={}))XH.call(e,r)&&oO(t,r,e[r]);if(nO)for(var r of nO(e))eq.call(e,r)&&oO(t,r,e[r]);return t};function rq({drawDefinition:t,matchUpStatus:e,matchUpsMap:r,winningSide:n,dualMatchUp:o,tieFormat:i,structure:s,matchUp:a,event:c,score:l}){var u;const d=ue(o,void 0,!0);for(const v of(d==null?void 0:d.tieMatchUps)||[])v.matchUpId===a.matchUpId&&(v.winningSide=n,v.score=l,!Dt({score:l})&&!e?Object.assign(v,tq({},hu)):e&&(v.matchUpStatus=e));i=i||((u=Xt({matchUp:a,structure:s,drawDefinition:t,event:c}))==null?void 0:u.tieFormat);const{winningSide:p}=Dc({matchUp:d,drawDefinition:t,matchUpsMap:r,structure:s,tieFormat:i,event:c});return{projectedWinningSide:p}}function hs({drawPosition:t,matchUps:e=[]}){return{initialRoundNumber:e.filter(({drawPositions:n})=>t&&(n==null?void 0:n.includes(t))).map(({roundNumber:n})=>parseInt(n)).sort(Wt)[0]}}function iO({structureId:t,matchUpsMap:e,matchUp:r}){const n=r==null?void 0:r.roundPosition,o=n%2?1:-1,i=n+o;return{pairedPreviousMatchUp:gi({matchUpsMap:e,structureId:t}).find(({roundNumber:c,roundPosition:l})=>c===(r==null?void 0:r.roundNumber)&&l===i)}}var nq=Object.defineProperty,oq=Object.defineProperties,iq=Object.getOwnPropertyDescriptors,sO=Object.getOwnPropertySymbols,sq=Object.prototype.hasOwnProperty,aq=Object.prototype.propertyIsEnumerable,aO=(t,e,r)=>e in t?nq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cq=(t,e)=>{for(var r in e||(e={}))sq.call(e,r)&&aO(t,r,e[r]);if(sO)for(var r of sO(e))aq.call(e,r)&&aO(t,r,e[r]);return t},lq=(t,e)=>oq(t,iq(e));function cO({inContextDrawMatchUps:t,sourceMatchUpStatus:e,sourceMatchUpId:r,matchUpsMap:n,matchUp:o}){const i=t.find(a=>a.matchUpId===r),{pairedPreviousMatchUp:s}=iO({structureId:i==null?void 0:i.structureId,matchUp:i,matchUpsMap:n});if(i&&s){const a=s==null?void 0:s.matchUpId,c=t.find(u=>u.matchUpId===a),l=(i==null?void 0:i.structureId)===(c==null?void 0:c.structureId)?(i==null?void 0:i.roundPosition)<(c==null?void 0:c.roundPosition)&&1||2:i.structureId===(c==null?void 0:c.structureId)&&2||1;o.matchUpStatusCodes=o.matchUpStatusCodes.map(u=>u.sideNumber===l?lq(cq({},u),{previousMatchUpStatus:e}):u)}}var uq=Object.defineProperty,lO=Object.getOwnPropertySymbols,dq=Object.prototype.hasOwnProperty,pq=Object.prototype.propertyIsEnumerable,uO=(t,e,r)=>e in t?uq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dO=(t,e)=>{for(var r in e||(e={}))dq.call(e,r)&&uO(t,r,e[r]);if(lO)for(var r of lO(e))pq.call(e,r)&&uO(t,r,e[r]);return t};function fq({inContextDrawMatchUps:t,sourceMatchUpStatus:e,targetDrawPosition:r,tournamentRecord:n,sourceMatchUpId:o,drawDefinition:i,structureId:s,dualMatchUp:a,roundNumber:c,matchUpsMap:l,event:u}){const{structure:d}=Te({drawDefinition:i,structureId:s});if(d.structureType===tr)return;l=l||Kt({drawDefinition:i});const v=((l==null?void 0:l.mappedMatchUps)||{})[s].matchUps,{initialRoundNumber:f}=hs({drawPosition:r,matchUps:v}),m=v==null?void 0:v.filter(h=>{var _;return h.roundNumber>=c&&h.roundNumber!==f&&((_=h.drawPositions)==null?void 0:_.includes(r))}),{positionAssignments:g}=et({drawDefinition:i,structureId:s});for(const h of m){const _=vq({inContextDrawMatchUps:t,sourceMatchUpStatus:e,positionAssignments:g,targetDrawPosition:r,tournamentRecord:n,sourceMatchUpId:o,drawDefinition:i,dualMatchUp:a,matchUpsMap:l,matchUp:h,event:u});if(_.error)return _}return dO({},B)}function vq({inContextDrawMatchUps:t,positionAssignments:e,sourceMatchUpStatus:r,targetDrawPosition:n,tournamentRecord:o,sourceMatchUpId:i,drawDefinition:s,dualMatchUp:a,matchUpsMap:c,matchUp:l,event:u}){var d,p,v;const f="removeSubsequentDrawPosition";if(a){const _=(p=(d=t.find(({matchUpId:P})=>l.matchUpId===P).sides)==null?void 0:d.find(P=>P.drawPosition===n))==null?void 0:p.sideNumber,I=(v=l.sides)==null?void 0:v.find(P=>P.sideNumber===_);I&&delete I.lineUp}l.drawPositions=(l.drawPositions||[]).map(h=>h===n?void 0:h).filter(Boolean);const g=e.filter(({drawPosition:h})=>{var _;return(_=l.drawPositions)==null?void 0:_.includes(h)}).filter(h=>h.bye).length;return l.matchUpStatus=g?qe:[Be,Ge].includes(l.matchUpStatus)?l.matchUpStatus:vt,[Ge,Be].includes(l.matchUpStatus)&&(l.winningSide=void 0),l.matchUpStatusCodes&&cO({inContextDrawMatchUps:t,sourceMatchUpStatus:r,sourceMatchUpId:i,matchUpsMap:c,matchUp:l}),Qe({tournamentId:o==null?void 0:o.tournamentId,eventId:u==null?void 0:u.eventId,context:`${f}-${n}`,drawDefinition:s,matchUp:l}),dO({},B)}function pO({positionAssignments:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:n,structure:o,event:i}){const{matchUps:s}=ze({drawDefinition:r,matchUpsMap:n,structure:o,event:i});s.forEach(a=>{const l=t.filter(({drawPosition:u})=>{var d;return(d=a.drawPositions)==null?void 0:d.includes(u)}).filter(u=>u.bye).length;a.winningSide||(Object.assign(a,{matchUpStatus:l?qe:vt}),Qe({tournamentId:e==null?void 0:e.tournamentId,context:"modifyRoundRobinMatchUpsStatus",eventId:i==null?void 0:i.eventId,drawDefinition:r,matchUp:a}))})}function _a({tournamentRecord:t,drawDefinition:e,event:r}){const n=(t==null?void 0:t.events)||r&&[r],o=(n==null?void 0:n.map(c=>c==null?void 0:c.drawDefinitions).flat().filter(Boolean))||e&&[e]||[],i={},s={},a=o.map(({structures:c})=>c==null?void 0:c.filter(l=>l==null?void 0:l.structures)).flat().filter(Boolean);for(const c of a){const{structures:l,structureId:u}=c||{};l&&(i[u]=l==null?void 0:l.map(d=>d.structureId))&&l.forEach(d=>s[d.structureId]=c.structureId)}return{containedStructures:i,containerStructures:s}}function Gc({drawDefinition:t,findContainer:e,structureId:r,structure:n}){var o;const i={isCollectionMatchUp:!1},{containedStructures:s}=_a({drawDefinition:t}),a=s[r]||[];if(!n){const y=Te({drawDefinition:t,structureId:r});if(y.error)return y;n=e&&y.containingStructure||y.structure}if(Po({drawDefinition:t,structure:n}))return{structure:n,isAdHoc:!0,error:js};const{matchUps:c}=Nt({inContext:!0,drawDefinition:t,matchUpFilters:i}),l=c.filter(y=>y.structureId===r||a.includes(y.structureId)),{matchUpDependencies:u}=Yr({drawIds:[t.drawId],matchUps:c,drawDefinition:t}),d=[],p={},v=[],f=[];for(const y of c){if(y.structureId===r||a.includes(y.structureId)){v.push(...y.drawPositions||[]);const S=y.roundNumber;for(const T of(y.drawPositions||[]).filter(Boolean))(!p[T]||p[T]>S)&&(p[T]=S)}Lf(y)&&(f.push(y),d.push(y.matchUpId,...((o=u==null?void 0:u[y==null?void 0:y.matchUpId])==null?void 0:o.matchUpIds)||[]))}const m=Ve(v.filter(Boolean)).sort(Wt),g=Ve(d),h=Ve(l.map(({matchUpId:y,drawPositions:S})=>g.includes(y)?S:[]).flat().filter(Boolean)).sort(Wt),{positionAssignments:_}=et({drawDefinition:t,structure:n}),I=_.filter(y=>y.bye).map(y=>y.drawPosition),P=_.filter(y=>y.qualifier).map(y=>y.drawPosition),O=(m==null?void 0:m.filter(y=>!h.includes(y)))||[];return{allDrawPositions:m,inContextStructureMatchUps:l,drawPositionInitialRounds:p,activeDependentMatchUpIds:g,qualifyingDrawPositions:P,inactiveDrawPositions:O,positionAssignments:_,activeDrawPositions:h,byeDrawPositions:I,activeMatchUps:f,structure:n}}function jn(t,e){e||Ft()}var mq=Object.defineProperty,gq=Object.defineProperties,hq=Object.getOwnPropertyDescriptors,fO=Object.getOwnPropertySymbols,_q=Object.prototype.hasOwnProperty,Iq=Object.prototype.propertyIsEnumerable,vO=(t,e,r)=>e in t?mq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Bu=(t,e)=>{for(var r in e||(e={}))_q.call(e,r)&&vO(t,r,e[r]);if(fO)for(var r of fO(e))Iq.call(e,r)&&vO(t,r,e[r]);return t},Pq=(t,e)=>gq(t,hq(e));function Ia({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,participantId:o,structureId:i,matchUpsMap:s,event:a}){const c="clearDrawPosition",{structure:l}=Te({drawDefinition:r,structureId:i}),{positionAssignments:u}=Et({drawDefinition:r,structure:l}),d=u.find(m=>o&&m.participantId===o||n&&m.drawPosition===n);if(o&&!n&&(n=d==null?void 0:d.drawPosition),!n)return{error:Ya};o||(o=d==null?void 0:d.participantId);const{activeDrawPositions:p}=Gc({drawDefinition:r,structureId:i});if(p.includes(n))return{error:bp};t||({matchUps:t}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:r,matchUpsMap:s}));const f=Ov({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,structureId:i,drawPosition:n,matchUpsMap:s,event:a});return f.error?f:f.drawPositionCleared?(Ho({tournamentId:e==null?void 0:e.tournamentId,drawDefinition:r,source:c,structure:l,event:a}),Pq(Bu({},B),{participantId:o})):{error:iF}}function Ov({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,matchUpsMap:o,structureId:i,event:s}){const{structure:a}=Te({drawDefinition:r,structureId:i}),{positionAssignments:c}=Et({drawDefinition:r,structure:a}),l=c.some(_=>{if(_.drawPosition===n)return delete _.participantId,delete _.qualifier,delete _.bye,!0});if(a.structureType===tr)return pO({positionAssignments:c,tournamentRecord:e,drawDefinition:r,matchUpsMap:o,structure:a}),Bu({drawPositionCleared:l},B);const u={isCollectionMatchUp:!1},{matchUps:d}=ze({drawDefinition:r,matchUpFilters:u,matchUpsMap:o,structure:a,event:s}),{roundProfile:p,roundMatchUps:v}=pr({matchUps:d}),f=Object.keys(p).map(_=>parseInt(_));let m=n;const h=f.map(_=>{var I;const P=p[_].pairedDrawPositions.find($=>$.includes(m)),O=P==null?void 0:P.find($=>$!==m),y=c.find($=>$.drawPosition===O),S=p[_+1],T=y==null?void 0:y.bye,E=S==null?void 0:S.pairedDrawPositions.find($=>$.includes(O)),b=T&&E&&S&&((I=S.drawPositions)==null?void 0:I.includes(O)),w=P&&{pairedDrawPositionByeAdvancedPair:!b&&E,pairedDrawPosition:O,targetDrawPosition:m,relevantPair:P,roundNumber:_};return b&&(m=O),w}).filter(_=>_==null?void 0:_.targetDrawPosition).reduce((_,I)=>{const{roundNumber:P,relevantPair:O,targetDrawPosition:y,pairedDrawPosition:S,pairedDrawPositionByeAdvancedPair:T}=I,E={roundNumber:P,targetDrawPosition:y,relevantPair:O},b=T&&{roundNumber:P+1,targetDrawPosition:S,relevantPair:T,subsequentRoundRemoval:!0},N=[E,b].filter(Boolean);return _.concat(...N)},[]);return h.forEach(({roundNumber:_,targetDrawPosition:I,relevantPair:P})=>{const O=v[_].find(y=>Gt(y.drawPositions.filter(Boolean),P.filter(Boolean)));O&&(yq({inContextDrawMatchUps:t,targetDrawPosition:I,tournamentRecord:e,drawDefinition:r,structureId:i,roundNumber:_,matchUpsMap:o,event:s}),mO({inContextDrawMatchUps:t,positionAssignments:c,tournamentRecord:e,drawDefinition:r,targetMatchUp:O,drawPosition:n,matchUpsMap:o,structure:a,event:s}))}),{tasks:h,drawPositionCleared:l,positionAssignments:c}}function yq({inContextDrawMatchUps:t,targetDrawPosition:e,tournamentRecord:r,drawDefinition:n,matchUpsMap:o,roundNumber:i,structureId:s}){const{structure:a}=Te({drawDefinition:n,structureId:s});if(a.structureType===tr)return;o=o||Kt({drawDefinition:n});const l=((o==null?void 0:o.mappedMatchUps)||{})[s].matchUps,{initialRoundNumber:u}=hs({drawPosition:e,matchUps:l}),d=l==null?void 0:l.filter(v=>{var f;return v.roundNumber>=i&&v.roundNumber!==u&&((f=v.drawPositions)==null?void 0:f.includes(e))}),{positionAssignments:p}=et({drawDefinition:n,structureId:s});d==null||d.forEach(v=>mO({drawPosition:e,targetMatchUp:v,inContextDrawMatchUps:t,positionAssignments:p,tournamentRecord:r,drawDefinition:n,matchUpsMap:o,structure:a}))}function mO({inContextDrawMatchUps:t,positionAssignments:e,tournamentRecord:r,drawDefinition:n,targetMatchUp:o,drawPosition:i,matchUpsMap:s,structure:a,event:c}){var l,u,d,p;const v="removeDrawPosition",f=o.drawPositions.slice(),m=o.matchUpStatus,g=o.winningSide;s=s||Kt({drawDefinition:n});const _=s.mappedMatchUps[a.structureId].matchUps,{initialRoundNumber:I}=hs({drawPosition:i,matchUps:_});if(o.roundNumber>I&&(o.drawPositions=(o.drawPositions||[]).map(A=>A===i?void 0:A)),o.matchUpType===He){const A=t==null?void 0:t.find(C=>C.matchUpId===o.matchUpId),M=(l=A==null?void 0:A.sides)==null?void 0:l.reduce((C,D,F)=>D.drawPosition===i?F:C,void 0);M!==void 0&&((d=(u=o.sides)==null?void 0:u[M])!=null&&d.lineUp)&&((p=o.sides)==null||delete p[M].lineUp,Qe({tournamentId:r==null?void 0:r.tournamentId,eventId:c==null?void 0:c.eventId,matchUp:o,context:`${v}-TEAM`,drawDefinition:n}))}const P=sr({matchUpId:o.matchUpId,inContextDrawMatchUps:t,drawDefinition:n,structure:a}),{targetLinks:{winnerTargetLink:O},targetMatchUps:{loserMatchUp:y,winnerMatchUp:S,loserMatchUpDrawPositionIndex:T,winnerMatchUpDrawPositionIndex:E}}=P,N=e.filter(({drawPosition:A})=>{var M;return(M=o.drawPositions)==null?void 0:M.includes(A)}).filter(A=>A.bye).length,w=N&&qe||[Be,Ge].includes(o.matchUpStatus)&&o.matcHUpStatus||o.drawPositions.length===2&&vt||void 0;o.matchUpStatus=w,[Ge,Be].includes(o.matchUpStatus)&&(o.winningSide=void 0);const $=f.find(A=>!o.drawPositions.includes(A));if(f.includes(i)&&m===o.matchUpStatus&&g===o.winningSide||($&&jn(),Qe({tournamentId:r==null?void 0:r.tournamentId,eventId:c==null?void 0:c.eventId,matchUp:o,context:`${v}-${i}`,drawDefinition:n})),y&&y.structureId!==P.matchUp.structureId&&!N){const{drawPositions:A,roundNumber:M}=y;if(M===1){const C=A[T];Ov({structureId:y.structureId,drawPosition:C,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,matchUpsMap:s})}else{const C=Math.min(...A.filter(Boolean)),D=Sq({loserMatchUpDrawPosition:C,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,loserMatchUp:y,matchUpsMap:s,event:c});if(D.error)return W({result:D,stack:v});const R=((s==null?void 0:s.mappedMatchUps)||{})[y.structureId].matchUps,{initialRoundNumber:G}=hs({drawPosition:C,matchUps:R});G===1&&(jn(),Ov({structureId:y.structureId,drawPosition:C,inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:n,matchUpsMap:s}))}}if(S&&S.structureId!==P.matchUp.structureId&&O.target.feedProfile!==an){const{structure:A}=Te({structureId:P.matchUp.structureId,drawDefinition:n});A.structureType!==Ie&&console.log("linked structure winnerMatchUp removal",{winnerMatchUpDrawPositionIndex:E,winnerTargetLink:O})}return Bu({},B)}function Sq({loserMatchUpDrawPosition:t,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,loserMatchUp:o,matchUpsMap:i,event:s}){const{structure:a}=Te({structureId:o.structureId,drawDefinition:n}),{positionAssignments:c}=et({structure:a});if(c.find(u=>u.drawPosition===t).bye){const u=Ia({drawPosition:t,structureId:o.structureId,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,matchUpsMap:i,event:s});if(u.error)return u}return Bu({},B)}function Oq({matchUpStatuses:t=[qe,Ge,Be],drawPositionMatchUps:e,loserDrawPosition:r,sourceMatchUps:n}){var o;const i=e==null?void 0:e.reduce((d,p)=>!d||p.roundNumber>d.roundNumber?p:d,void 0),s=(o=i==null?void 0:i.drawPositions)==null?void 0:o.find(d=>d!==r),a=n.filter(d=>{var p;return(p=d==null?void 0:d.drawPositions)==null?void 0:p.includes(s)}).map(d=>d.matchUpStatus),c=n.filter(d=>{var p;return(p=d==null?void 0:d.drawPositions)==null?void 0:p.includes(r)}).map(d=>d.matchUpStatus),l=Gt(a||[],t),u=Gt(c||[],t);return{sourceMatchUp:i,winnerHadMatchUpStatus:l,winnerMatchUpStatuses:a,loserHadMatchUpStatus:u,loserMatchUpStatuses:c}}var bq=Object.defineProperty,Tq=Object.defineProperties,Eq=Object.getOwnPropertyDescriptors,gO=Object.getOwnPropertySymbols,wq=Object.prototype.hasOwnProperty,$q=Object.prototype.propertyIsEnumerable,hO=(t,e,r)=>e in t?bq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ei=(t,e)=>{for(var r in e||(e={}))wq.call(e,r)&&hO(t,r,e[r]);if(gO)for(var r of gO(e))$q.call(e,r)&&hO(t,r,e[r]);return t},Nq=(t,e)=>Tq(t,Eq(e));function Pa(t){const{dualWinningSideChange:e,inContextDrawMatchUps:r,tournamentRecord:n,drawDefinition:o,matchUpStatus:i,matchUpsMap:s,dualMatchUp:a,targetData:c,matchUpId:l,structure:u,event:d}=t,p=!!t.matchUp.collectionId,v=Po({drawDefinition:o,structure:u}),{drawPositions:f,winningSide:m}=c.matchUp||{};if(!v&&!f)return{error:Op};const{targetLinks:{loserTargetLink:g,winnerTargetLink:h,byeTargetLink:_},targetMatchUps:{loserMatchUp:I,winnerMatchUp:P,byeMatchUp:O}}=c,y=Mn(Nq(Ei({},t),{matchUpStatus:i||vt,removeWinningSide:!0}));if(y.error)return y;let S;if(p){const{matchUpTieId:D,matchUpsMap:F}=t;if(S=Qn({matchUpId:D,tournamentRecord:n,drawDefinition:o,matchUpsMap:F,event:d}),!e&&!S.removeWinningSide)return Ei({},B)}if(v)return Ei({},B);const{matchUps:T}=ze({afterRecoveryTimes:!1,inContext:!0,drawDefinition:o,matchUpsMap:s,structure:u}),{positionAssignments:E}=Et({structure:u}),b=m-1,N=1-b,w=f[b],$=f[N],{winnerParticipantId:U,loserParticipantId:A}=E.reduce((D,F)=>(F.drawPosition===$&&(D.loserParticipantId=F.participantId),F.drawPosition===w&&(D.winnerParticipantId=F.participantId),D),{winnerParticipantId:void 0,loserParticipantId:void 0}),M=T.filter(D=>{var F;return(F=D.drawPositions)==null?void 0:F.includes($)});if(P){const D=_O({sourceMatchUpStatus:i,sourceMatchUpId:l,inContextDrawMatchUps:r,winningDrawPosition:w,winnerParticipantId:U,tournamentRecord:n,winnerTargetLink:h,drawDefinition:o,winnerMatchUp:P,dualMatchUp:a,matchUpsMap:s});if(D.error)return D}if(I){const{winnerHadMatchUpStatus:D}=Oq({drawPositionMatchUps:M,loserDrawPosition:$,sourceMatchUps:T}),R=g.linkCondition===Yn;if(D&&R){const x=Math.min(...I.drawPositions),z=bv({targetLink:g,inContextDrawMatchUps:r,drawDefinition:o,drawPosition:x,matchUpsMap:s,event:d});if(z.error)return z}const G=Aq({sourceMatchUpStatus:i,sourceMatchUpId:l,inContextDrawMatchUps:r,loserParticipantId:A,tournamentRecord:n,loserTargetLink:g,drawDefinition:o,loserMatchUp:I,dualMatchUp:a,matchUpsMap:s,event:d});if(G.error)return G}if(O){const D=Math.min(...O.drawPositions),F=bv({sourceMatchUpId:l,targetLink:_,inContextDrawMatchUps:r,drawDefinition:o,drawPosition:D,matchUpsMap:s,event:d});F.error&&console.log({removeByeResult:F})}const C=S&&{tieMatchUpResult:S};return Ei(Ei({},B),C)}function _O({inContextDrawMatchUps:t,winningDrawPosition:e,sourceMatchUpStatus:r,winnerParticipantId:n,tournamentRecord:o,winnerTargetLink:i,sourceMatchUpId:s,drawDefinition:a,winnerMatchUp:c,matchUpsMap:l,dualMatchUp:u,event:d}){var p;const{structureId:v,roundNumber:f}=c,m="removeDirectedWinner";if(i){const h=i.target.structureId,{structure:_}=Te({drawDefinition:a,structureId:h}),{positionAssignments:I}=Et({structure:_});_.seedAssignments=(_.seedAssignments||[]).filter(N=>N.participantId!==n);const P=I.find(N=>N.participantId===n),O=P==null?void 0:P.drawPosition,{matchUps:y}=ze({drawDefinition:a,structure:_,event:d}),S=y.map(N=>N.drawPositions).flat(1/0).filter(Boolean);if(mr(S)[O]===1)I.forEach(N=>{N.participantId===n&&delete N.participantId});else{const N=y.filter(({drawPositions:w})=>w.includes(O));console.log("not removing from position assignments since instances > 1",{drawPositionMatchUps:N,winnerTargetLink:i})}const b=(p=l==null?void 0:l.drawMatchUps)==null?void 0:p.find(({matchUpId:N})=>N===c.matchUpId);Qe({tournamentId:o==null?void 0:o.tournamentId,eventId:d==null?void 0:d.eventId,matchUp:b,context:m,drawDefinition:a})}const g=fq({targetDrawPosition:e,inContextDrawMatchUps:t,sourceMatchUpStatus:r,tournamentRecord:o,sourceMatchUpId:s,drawDefinition:a,dualMatchUp:u,matchUpsMap:l,roundNumber:f,structureId:v});return g.error?W({result:g,stack:m}):Ei({},B)}function Aq({sourceMatchUpStatus:t,loserParticipantId:e,tournamentRecord:r,loserTargetLink:n,sourceMatchUpId:o,drawDefinition:i,loserMatchUp:s,matchUpsMap:a,dualMatchUp:c,event:l}){var u,d,p;const v="removeDirectedLoser",f=n.target.structureId,{structure:m}=Te({drawDefinition:i,structureId:f}),{positionAssignments:g}=Et({structure:m}),h=(u=g.find(_=>_.participantId===e))==null?void 0:u.drawPosition;if(g.forEach(_=>{_.participantId===e&&delete _.participantId}),m.seedAssignments=(m.seedAssignments||[]).filter(_=>_.participantId!==e),c){const _=s==null?void 0:s.sides.reduce((O,y,S)=>y.drawPosition===h?S:O,void 0),I=(d=a==null?void 0:a.drawMatchUps)==null?void 0:d.find(({matchUpId:O})=>O===s.matchUpId),P=(p=I==null?void 0:I.sides)==null?void 0:p[_];P&&(delete P.lineUp,Qe({tournamentId:r==null?void 0:r.tournamentId,eventId:l==null?void 0:l.eventId,matchUp:I,context:v,drawDefinition:i}))}return Ei({},B)}function bv({inContextDrawMatchUps:t,tournamentRecord:e,sourceMatchUpId:r,drawDefinition:n,drawPosition:o,matchUpsMap:i,targetLink:s,event:a}){const c=s.target.structureId;return Ia({sourceMatchUpStatus:qe,inContextDrawMatchUps:t,tournamentRecord:e,sourceMatchUpId:r,drawDefinition:n,matchUpsMap:i,drawPosition:o,structureId:c,event:a}),Ei({},B)}function IO(t){let{sourceMatchUp:e}=t;const{targetMatchUp:r,structure:n,matchUpsMap:o,drawPosition:i}=t,s=r.roundNumber>1&&r.roundNumber-1,a=gi({structureId:n.structureId,matchUpsMap:o});!e&&i&&(e=a.find(({drawPositions:f,roundNumber:m})=>m===s&&(f==null?void 0:f.includes(i))));const c=e==null?void 0:e.roundPosition,l=c%2?1:-1,u=c+l,d=s&&a.find(({roundNumber:f,roundPosition:m})=>f===s&&m===u),p=d==null?void 0:d.matchUpStatus,v=[_t,bt].includes(p);return{pairedPreviousMatchUp:d,pairedPreviousMatchUpIsDoubleExit:v}}function Wc({drawDefinition:t,positionAction:e}){const{extension:r}=Or({name:Gl,element:t}),n=Array.isArray(r==null?void 0:r.value)?r.value:[];if(!n.length){const i=t.structures.find(s=>s.stage===de);if(i){const s=et({structure:i}).positionAssignments.map(({drawPosition:a,participantId:c,bye:l,qualifier:u})=>({drawPosition:a,participantId:c,qualifier:u,bye:l}));n.push({name:"initialMainAssignments",initialAssignments:s})}}const o={name:Gl,value:n.concat(e)};tt({element:t,extension:o})}var Uq=Object.defineProperty,PO=Object.getOwnPropertySymbols,Cq=Object.prototype.hasOwnProperty,Mq=Object.prototype.propertyIsEnumerable,yO=(t,e,r)=>e in t?Uq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ku=(t,e)=>{for(var r in e||(e={}))Cq.call(e,r)&&yO(t,r,e[r]);if(PO)for(var r of PO(e))Mq.call(e,r)&&yO(t,r,e[r]);return t};function jr({provisionalPositioning:t,isPositionAction:e,tournamentRecord:r,drawDefinition:n,drawPosition:o,matchUpsMap:i,structureId:s,structure:a,event:c}){var l;if(!n)return{error:pe};if(a||({structure:a}=Te({drawDefinition:n,structureId:s})),!a)return{error:Br};s||({structureId:s}=a);const u="assignDrawPositionBye";jn(),i||(i=Kt({drawDefinition:n}));const{positionAssignments:d}=et({structure:a}),{activeDrawPositions:p}=Gc({drawDefinition:n,structureId:s}),v=d.find(w=>w.drawPosition===o);if(v!=null&&v.bye)return ku({},B);if(p==null?void 0:p.includes(o))return{error:bp};const m=d.find(w=>w.drawPosition===o);if(!m)return{error:js};const{filled:g,containsBye:h,assignedParticipantId:_}=Dq(m);if(h)return ku({},B);if(g&&!h)return W({result:{error:qa},stack:u});const{matchUps:I}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:n,matchUpsMap:i}),P={isCollectionMatchUp:!1},{matchUps:O}=ze({provisionalPositioning:t,drawDefinition:n,matchUpFilters:P,matchUpsMap:i,structure:a});if(d.forEach(w=>{w.drawPosition===o&&(w.bye=!0)}),a.structureType===tr)return jq({tournamentRecord:r,drawDefinition:n,drawPosition:o,matchUps:O}),Ho({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:n,source:u,structure:a,event:c}),SO({assignedParticipantId:_,isPositionAction:e,drawDefinition:n,drawPosition:o,structureId:s,stack:u});const{roundProfile:y,roundMatchUps:S}=pr({matchUps:O}),E=Object.keys(y).map(w=>parseInt(w)).reverse().find(w=>{var $;return($=y[w].drawPositions)==null?void 0:$.includes(o)}),b=S[E].find(({drawPositions:w})=>w==null?void 0:w.includes(o));OO({tournamentRecord:r,drawDefinition:n,matchUp:b,event:c});const N=(l=b.drawPositions)==null?void 0:l.find(w=>w!==o);if(N){const w=Tv({sourceDrawPositions:b.drawPositions,matchUpId:b.matchUpId,inContextDrawMatchUps:I,drawPositionToAdvance:N,tournamentRecord:r,drawDefinition:n,matchUpsMap:i});if(w.error)return w}return Ho({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:n,source:u,structure:a,event:c}),SO({assignedParticipantId:_,isPositionAction:e,drawDefinition:n,drawPosition:o,structureId:s,stack:u})}function SO({assignedParticipantId:t,isPositionAction:e,drawDefinition:r,drawPosition:n,structureId:o,stack:i}){return e&&Wc({drawDefinition:r,positionAction:{removedParticipantId:t,drawPosition:n,structureId:o,name:i}}),W({result:ku({},B),stack:i})}function Dq(t){const e=t.bye,r=t.qualifier,n=t.participantId;return{containsBye:e,containsQualifier:r,assignedParticipantId:n,filled:e||r||n}}function OO({tournamentRecord:t,drawDefinition:e,matchUp:r,event:n}){Object.assign(r,{matchUpStatus:qe,score:void 0,winningSide:void 0}),Qe({tournamentId:t==null?void 0:t.tournamentId,context:"setMatchUpStatusBye",eventId:n==null?void 0:n.eventId,drawDefinition:e,matchUp:r})}function jq({tournamentRecord:t,drawDefinition:e,drawPosition:r,matchUps:n,event:o}){n.forEach(i=>{var s;(s=i.drawPositions)!=null&&s.includes(r)&&OO({eventId:o==null?void 0:o.eventId,tournamentRecord:t,drawDefinition:e,matchUp:i})})}function Tv({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,matchUpsMap:i,matchUpId:s,event:a}){jn();const c=i.drawMatchUps.find(P=>P.matchUpId===s),l=e.find(P=>P.matchUpId===s),u=l==null?void 0:l.structureId,{structure:d}=Te({drawDefinition:o,structureId:u}),{positionAssignments:p}=et({structure:d}),v=p.filter(P=>P.bye).map(P=>P.drawPosition),f=c.drawPositions.find(P=>P!==t),m=v==null?void 0:v.includes(f),{targetLinks:{loserTargetLink:g},targetMatchUps:{loserMatchUp:h,winnerMatchUp:_,loserTargetDrawPosition:I}}=sr({inContextDrawMatchUps:e,drawDefinition:o,matchUpId:s,structure:d});if(_&&_.structureId===d.structureId&&Rq({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,winnerMatchUp:_,matchUpsMap:i,event:a}),h&&m&&h.structureId!==d.structureId){const{roundNumber:P}=h;if(P===1){const O=jr({structureId:g.target.structureId,drawPosition:I,iterative:"brightyellow",tournamentRecord:n,drawDefinition:o,event:a});if(O.error)return O}else bO({loserTargetDrawPosition:I,tournamentRecord:n,loserTargetLink:g,drawDefinition:o,loserMatchUp:h,matchUpsMap:i,event:a})}return ku({},B)}function Rq({drawPositionToAdvance:t,inContextDrawMatchUps:e,sourceDrawPositions:r,tournamentRecord:n,drawDefinition:o,winnerMatchUp:i,matchUpsMap:s,event:a}){var c,l,u;const d="advanceWinner",p=s.drawMatchUps.find(R=>R.matchUpId===i.matchUpId),v=e.find(R=>R.matchUpId===i.matchUpId),f=v==null?void 0:v.structureId,{structure:m}=Te({drawDefinition:o,structureId:f}),{positionAssignments:g}=et({structure:m}),_=g.find(({drawPosition:R})=>R===t).bye,I=(c=p.drawPositions)==null?void 0:c.filter(Boolean),P=g.filter(R=>I==null?void 0:I.includes(R.drawPosition)),O=g.find(({drawPosition:R})=>R===t),y=r==null?void 0:r.find(R=>R!==t),S=y&&P.find(({drawPosition:R})=>R===y),T=S==null?void 0:S.bye,E=_&&T;if(E&&console.log({isByeAdvancedBye:E}),(I==null?void 0:I.length)>1&&_&&!T)return W({result:{error:qa},stack:d});const b=I==null?void 0:I.find(R=>R!==t);let N=E;const w=[].concat(...(p.drawPositions||[]).filter(Boolean),void 0,void 0).slice(0,2),$=w.map(R=>!R&&!N||R===t?(N=!0,t):R).sort(Wt);if(!N)return console.log("@@@@@@@",{advancingAssignmentIsBye:O,drawPositionToAdvance:t,existingAssignments:P}),W({result:{error:qa},stack:d});const U=(l=g.find(({drawPosition:R})=>R===b))==null?void 0:l.bye,A=(u=g.find(({drawPosition:R})=>R===t))==null?void 0:u.bye;Object.assign(p,{matchUpStatus:A||U?qe:vt,score:void 0,winningSide:void 0,drawPositions:$}),p.drawPositions.find(R=>!w.includes(R)),jn(),Qe({tournamentId:n==null?void 0:n.tournamentId,matchUp:p,eventId:a==null?void 0:a.eventId,context:d,drawDefinition:o});const{targetLinks:{loserTargetLink:C},targetMatchUps:{loserMatchUp:D,loserTargetDrawPosition:F}}=sr({matchUpId:i.matchUpId,inContextDrawMatchUps:e,drawDefinition:o,structure:m});if(U||A){const R=U?t:b;if(R)Tv({drawPositionToAdvance:R,matchUpId:i.matchUpId,inContextDrawMatchUps:e,tournamentRecord:n,drawDefinition:o,matchUpsMap:s});else if(A&&C&&D)if(D.feedRound)bO({loserTargetDrawPosition:F,tournamentRecord:n,loserTargetLink:C,drawDefinition:o,loserMatchUp:D,matchUpsMap:s});else{const x=1-i.roundPosition%2,z=D.drawPositions[x],j=jr({structureId:C.target.structureId,drawPosition:z,loserTargetDrawPosition:F,iterative:"brightgreen",tournamentRecord:n,drawDefinition:o,event:a});if(j.error)return j}}}function bO({loserTargetDrawPosition:t,tournamentRecord:e,loserTargetLink:r,drawDefinition:n,loserMatchUp:o,matchUpsMap:i,event:s}){const{roundNumber:a}=o;jn();const l=((i==null?void 0:i.mappedMatchUps)||{})[o.structureId].matchUps,{initialRoundNumber:u}=hs({drawPosition:t,matchUps:l});if(u===a){const d=jr({structureId:r.target.structureId,drawPosition:t,tournamentRecord:e,iterative:"red",drawDefinition:n,event:s});if(d.error)return d}}var Fq=Object.defineProperty,Lq=Object.defineProperties,Vq=Object.getOwnPropertyDescriptors,TO=Object.getOwnPropertySymbols,xq=Object.prototype.hasOwnProperty,Bq=Object.prototype.propertyIsEnumerable,EO=(t,e,r)=>e in t?Fq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,kq=(t,e)=>{for(var r in e||(e={}))xq.call(e,r)&&EO(t,r,e[r]);if(TO)for(var r of TO(e))Bq.call(e,r)&&EO(t,r,e[r]);return t},Gq=(t,e)=>Lq(t,Vq(e));function Ev({inContextTargetMatchUp:t,drawPositionSideIndex:e,teamParticipantId:r,tournamentRecord:n,drawDefinition:o,matchUp:i,event:s}){var a,c,l;const u=(c=(a=t==null?void 0:t.sides)==null?void 0:a[e])==null?void 0:c.sideNumber,d=u&&((l=i.sides)==null?void 0:l.find(m=>m.sideNumber===u)),{extension:p}=Vt({element:o,name:bn}),f=((p==null?void 0:p.value)||{})[r];if(d)i.sides.forEach(m=>{m.sideNumber===u&&(m.lineUp=f)});else{i.sides=[1,2].map(g=>{var h;const _=((h=i.sides)==null?void 0:h.find(I=>I.sideNumber===g))||{};return Gq(kq({},_),{sideNumber:g})});const m=i.sides.find(g=>g.sideNumber===u);m&&(m.lineUp=f)}Qe({tournamentId:n==null?void 0:n.tournamentId,context:"updateSidLineUps",eventId:s==null?void 0:s.eventId,drawDefinition:o,matchUp:i})}function Wq({drawPosition:t,drawPositions:e}){let r,n=e==null?void 0:e.includes(t);return{updatedDrawPositions:n?e||[]:[].concat(...e,void 0,void 0).slice(0,2).map(i=>!i&&!n?(n=!0,r=!0,t):i).sort(Wt).filter(Boolean),positionAdded:r,positionAssigned:n}}function Gu({inContextDrawMatchUps:t,drawPosition:e,matchUpId:r}){const n=t.filter(({winnerMatchUpId:s,loserMatchUpId:a})=>a===r||s===r).sort((s,a)=>s.roundPosition-a.roundPosition);return t.find(s=>s.matchUpId===r).feedRound?1:n.reduce((s,a,c)=>{var l;return(l=a.drawPositions)!=null&&l.includes(e)?c+1:s},void 0)}var Hq=Object.defineProperty,wO=Object.getOwnPropertySymbols,qq=Object.prototype.hasOwnProperty,Yq=Object.prototype.propertyIsEnumerable,$O=(t,e,r)=>e in t?Hq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zq=(t,e)=>{for(var r in e||(e={}))qq.call(e,r)&&$O(t,r,e[r]);if(wO)for(var r of wO(e))Yq.call(e,r)&&$O(t,r,e[r]);return t};function ya({inContextDrawMatchUps:t,sourceMatchUpStatus:e,tournamentRecord:r,sourceMatchUpId:n,drawDefinition:o,matchUpStatus:i,drawPosition:s,matchUpsMap:a,matchUpId:c,event:l}){var u,d,p,v;const f="assignMatchUpDrawPosition";a||(a=Kt({drawDefinition:o})),t||({matchUps:t}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:o,matchUpsMap:a}));const m=t.find(C=>C.matchUpId===c),g=m==null?void 0:m.structureId,h=(u=o==null?void 0:o.structures)==null?void 0:u.find(C=>C.structureId===g);if(!h)return{error:Br};const _=(d=a==null?void 0:a.drawMatchUps)==null?void 0:d.find(C=>C.matchUpId===c),I=_.drawPositions||[],{positionAdded:P,positionAssigned:O,updatedDrawPositions:y}=Wq({drawPosition:s,drawPositions:I}),{positionAssignments:S}=et({drawDefinition:o,structure:h}),E=S.filter(C=>y.includes(C.drawPosition)).find(({bye:C})=>C),b=[Ge,Be].includes(_.matchUpStatus)&&y.filter(Boolean).length<2;if(i=E&&qe||i||b&&_.matchUpStatus||[_t,bt].includes(_.matchUpStatus)&&_.matchUpStatus||vt,P){({matchUps:t}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:o,matchUpsMap:a}));const C=b&&Gu({inContextDrawMatchUps:t,drawPosition:s,matchUpId:c})||void 0;_.matchUpStatusCodes&&cO({inContextDrawMatchUps:t,sourceMatchUpStatus:e,sourceMatchUpId:n,matchUpsMap:a,matchUp:_}),Object.assign(_,{drawPositions:y,winningSide:C,matchUpStatus:i}),Qe({tournamentId:r==null?void 0:r.tournamentId,eventId:m==null?void 0:m.eventId,context:f,drawDefinition:o,matchUp:_})}const N=sr({inContextDrawMatchUps:t,inContextMatchUp:m,drawDefinition:o,matchUpId:c}),{targetMatchUps:{winnerMatchUp:w,loserMatchUp:$,loserTargetDrawPosition:U},targetLinks:{loserTargetLink:A}}=N,M=gi({structureId:h.structureId,matchUpsMap:a});if(O&&E){if(w)if([qe,_t,bt].includes(i)){const C=ya({matchUpId:w.matchUpId,iterative:"brightmagenta",inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:o,drawPosition:s,matchUpsMap:a});if(C.error)return C}else{const{structureId:C}=w;C!==h.structureId&&console.log("winnerMatchUp in different structure... participant is in different targetDrawPosition")}}else if(w&&!m.feedRound){const{pairedPreviousMatchUpIsDoubleExit:C}=IO({targetMatchUp:_,drawPosition:s,matchUpsMap:a,structure:h});if(C){const D=ya({matchUpId:w.matchUpId,iterative:"brightred",inContextDrawMatchUps:t,tournamentRecord:r,drawDefinition:o,drawPosition:s,matchUpsMap:a});if(D.error)return D}}if(_.matchUpType===He){const C=t==null?void 0:t.find(({matchUpId:R})=>R===_.matchUpId),D=(p=C==null?void 0:C.sides)==null?void 0:p.reduce((R,G,x)=>G.drawPosition===s?x:R,void 0),F=(v=S.find(R=>R.drawPosition===s))==null?void 0:v.participantId;F&&D!==void 0&&Ev({inContextTargetMatchUp:C,drawPositionSideIndex:D,teamParticipantId:F,tournamentRecord:r,drawDefinition:o,matchUp:_})}if((A==null?void 0:A.linkCondition)===Yn&&y.filter(Boolean).length===2&&!E&&M.filter(({drawPositions:F,roundNumber:R})=>R===1&&Gt(F,y)).every(({matchUpStatus:F})=>[St,er].includes(F))&&$){const{structureId:F}=$,R=jr({drawPosition:U,tournamentRecord:r,drawDefinition:o,structureId:F,matchUpsMap:a,event:l});if(R.error)return R}return O?zq({},B):W({result:{error:qa},context:{drawPosition:s},stack:f})}var Kq=Object.defineProperty,Qq=Object.defineProperties,Jq=Object.getOwnPropertyDescriptors,NO=Object.getOwnPropertySymbols,Zq=Object.prototype.hasOwnProperty,Xq=Object.prototype.propertyIsEnumerable,AO=(t,e,r)=>e in t?Kq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eo=(t,e)=>{for(var r in e||(e={}))Zq.call(e,r)&&AO(t,r,e[r]);if(NO)for(var r of NO(e))Xq.call(e,r)&&AO(t,r,e[r]);return t},Sa=(t,e)=>Qq(t,Jq(e));function Hc(t){var e;const{tournamentRecord:r,appliedPolicies:n,drawDefinition:o,matchUpsMap:i,targetData:s,structure:a,event:c}=t,l="doubleExitAdvancement";if(a.structureType===tr)return W({result:eo({},B),stack:l});const{matchUp:u,targetMatchUps:d,targetLinks:p}=s,{loserMatchUp:v,winnerMatchUp:f,loserTargetDrawPosition:m}=d;if(v&&v.matchUpStatus!==qe){const{loserTargetLink:g}=p;if((e=n==null?void 0:n.progression)!=null&&e.doubleExitPropagateBye){const h=CO({loserTargetDrawPosition:m,tournamentRecord:r,loserTargetLink:g,drawDefinition:o,loserMatchUp:v,matchUpsMap:i,event:c});if(h.error)return W({result:h,stack:l})}else{const{feedRound:h,drawPositions:_,matchUpId:I}=v,P=h?2:2-_.indexOf(m),O=UO(Sa(eo({},t),{targetMatchUp:v,walkoverWinningSide:P,tournamentRecord:r,sourceMatchUp:u,matchUpId:I}));if(O.error)return W({result:O,stack:l})}}if(f){const g=UO(Sa(eo({},t),{matchUpId:f.matchUpId,targetMatchUp:f,tournamentRecord:r,sourceMatchUp:u}));if(g.error)return W({result:g,stack:l})}return W({result:eo({},B),stack:l})}function UO(t){var e,r,n;const{inContextDrawMatchUps:o,tournamentRecord:i,drawDefinition:s,sourceMatchUp:a,targetMatchUp:c,matchUpsMap:l}=t,u=s.structures.find(({structureId:k})=>k===c.structureId),d=t.matchUpStatus===bt?bt:_t,p=t.matchUpStatus===bt?Be:Ge,v="conditionallyAdvanceDrawPosition",f=l.drawMatchUps.find(k=>k.matchUpId===c.matchUpId);if(!f)return{error:$r};const m=(a==null?void 0:a.drawPositions)||[];let g=(e=f.drawPositions)==null?void 0:e.filter(Boolean);const h=(a==null?void 0:a.structureId)===c.structureId;if(h&&Gt(m,g)&&(g=g.filter(k=>!m.includes(k))),h&&g.length>1)return W({result:{error:qa},stack:v});const{pairedPreviousMatchUpIsDoubleExit:_,pairedPreviousMatchUp:I}=IO(t),P=sr({matchUpId:c.matchUpId,inContextDrawMatchUps:o,drawDefinition:s,structure:u}),{targetMatchUps:O,targetLinks:y}=P,{loserTargetDrawPosition:S,winnerMatchUp:T,loserMatchUp:E}=O;if(E){const{loserTargetLink:k}=y,H=CO({loserTargetDrawPosition:S,loserMatchUp:E,tournamentRecord:i,loserTargetLink:k,drawDefinition:s,matchUpsMap:l});if(H.error)return W({result:H,stack:v})}const b=((r=f.drawPositions)==null?void 0:r.filter(Boolean))||[],N=b.length===1,w=t.walkoverWinningSide||N&&Gu({drawPosition:b[0],matchUpId:c.matchUpId,inContextDrawMatchUps:o})||void 0,$=[Ge,Be].includes(f.matchUpStatus)&&!b.length,U=f.finishingRound===1,A=$&&!U?d:p,M=o.find(k=>k.matchUpId===I.matchUpId);let C=[],D;a&&((a==null?void 0:a.structureId)===(M==null?void 0:M.structureId)?a.roundPosition<(I==null?void 0:I.roundPosition)?D=1:D=2:c.feedRound?a.structureId===c.structureId?D=2:D=1:w&&(D=3-w));const F=t.matchUpStatus,R=I==null?void 0:I.matchUpStatus;D===1?C=[{sideNumber:1,previousMatchUpStatus:F,matchUpStatus:Wu(F)},{sideNumber:2,previousMatchUpStatus:R,matchUpStatus:Wu(R)}]:D===2&&(C=[{sideNumber:1,previousMatchUpStatus:R,matchUpStatus:Wu(R)},{sideNumber:2,previousMatchUpStatus:F,matchUpStatus:Wu(F)}]),C.length&&(C=C.map(k=>_e(k)));const G=Mn(Sa(eo({},t),{matchUp:f,winningSide:w,matchUpStatusCodes:C,matchUpStatus:A}));if(G.error)return W({result:G,stack:v});if($)return Hc(Sa(eo({},t),{matchUpStatus:A,targetData:P}));if(!T)return W({result:eo({},B),stack:v});const x=g.length===2?g[w-1]:g[0],{positionAssignments:z}=et({structure:u}),j=z.find(k=>k.drawPosition===x),V=l.drawMatchUps.find(k=>k.matchUpId===T.matchUpId),L=(n=V==null?void 0:V.drawPositions)==null?void 0:n.filter(Boolean),q=L.length===1;if(x){if(j.bye){const k=sr({matchUpId:V.matchUpId,inContextDrawMatchUps:o,drawDefinition:s,structure:u});if(q){const H=L.filter(Boolean)[0],Q=Gu({drawPosition:H,matchUpId:V.matchUpId,inContextDrawMatchUps:o}),K=Mn({matchUpId:V.matchUpId,matchUp:V,matchUpStatus:p,matchUpStatusCodes:[],removeScore:!0,drawDefinition:s,winningSide:Q});return K.error?W({result:K,stack:v}):Tv({drawPositionToAdvance:H,matchUpId:V.matchUpId,inContextDrawMatchUps:o,drawDefinition:s,matchUpsMap:l})}else if([Ge,Be].includes(T.matchUpStatus)){const H=Hc(Sa(eo({},t),{matchUpId:V.matchUpId,matchUpStatus:A,targetData:k}));if(H.error)return W({result:H,stack:v})}return W({result:eo({},B),stack:v})}return ya({matchUpId:T.matchUpId,drawPosition:x,inContextDrawMatchUps:o,drawDefinition:s})}else if(_){if(!V)return{error:$r};if(q){const Q=L[0],K=Gu({matchUpId:c.matchUpId,inContextDrawMatchUps:o,drawPosition:Q});console.log("existing drawPosition is winningSide",{walkoverWinningSide:K})}const k=[Ge,Be].includes(V.matchUpStatus)?p:d,H=Mn({matchUpId:V.matchUpId,matchUp:V,matchUpStatusCodes:[],removeScore:!0,drawDefinition:s,matchUpStatus:k});if(H.error)return W({result:H,stack:v});if(k===d){const Q=Hc(Sa(eo({},t),{matchUpId:c.matchUpId,matchUpStatus:k,targetData:P}));if(Q.error)return Q}}return W({result:eo({},B),stack:v})}function CO(t){var e;const{loserTargetDrawPosition:r,tournamentRecord:n,loserTargetLink:o,drawDefinition:i,matchUpsMap:s,event:a}=t,c=(e=o==null?void 0:o.target)==null?void 0:e.structureId,{structure:l}=Te({drawDefinition:i,structureId:c});return l?jr({drawPosition:r,tournamentRecord:n,drawDefinition:i,structureId:c,matchUpsMap:s,event:a}):{error:Rs}}function Wu(t){return t===_t?Ge:t===bt?Be:t}var e6=Object.defineProperty,MO=Object.getOwnPropertySymbols,t6=Object.prototype.hasOwnProperty,r6=Object.prototype.propertyIsEnumerable,DO=(t,e,r)=>e in t?e6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,n6=(t,e)=>{for(var r in e||(e={}))t6.call(e,r)&&DO(t,r,e[r]);if(MO)for(var r of MO(e))r6.call(e,r)&&DO(t,r,e[r]);return t};function o6({tournamentRecord:t,drawDefinition:e,structure:r,matchUp:n}){var o;if(n!=null&&n.winningSide)return W({result:{error:za},context:{matchUpStatus:qe},stack:i});const i="attemptToSetMatchUpStatusBYE",{positionAssignments:s}=Et({structure:r}),a=s.filter(l=>l.bye).map(l=>l.drawPosition);return((o=n.drawPositions)==null?void 0:o.some(l=>a.includes(l)))?(n.matchUpStatus=qe,n.matchUpStatusCodes=[],Qe({tournamentId:t==null?void 0:t.tournamentId,drawDefinition:e,context:i,matchUp:n}),n6({},B)):W({result:{error:yF},info:"matchUp does not include BYE",stack:i})}var i6=Object.defineProperty,s6=Object.defineProperties,a6=Object.getOwnPropertyDescriptors,jO=Object.getOwnPropertySymbols,c6=Object.prototype.hasOwnProperty,l6=Object.prototype.propertyIsEnumerable,RO=(t,e,r)=>e in t?i6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,FO=(t,e)=>{for(var r in e||(e={}))c6.call(e,r)&&RO(t,r,e[r]);if(jO)for(var r of jO(e))l6.call(e,r)&&RO(t,r,e[r]);return t},LO=(t,e)=>s6(t,a6(e));function u6(t){const{tournamentRecord:e,drawDefinition:r,matchUpStatus:n,structure:o,matchUp:i}=t,s=!!(i.tieMatchUps&&!i.rondPosition&&t.inContextDrawMatchUps.find(h=>h.matchUpId===i.matchUpId).containerStructureId),a="attemptToSetMatchUpStatus",c=n===qe,l=i.winningSide,u=[_t,bt].includes(n),d=jc({matchUpStatus:n}),p=Ff({matchUpStatus:n}),v=!d&&!p,f=t.matchUpTieId||l&&d&&!u,m=l&&u,g=()=>Mn(LO(FO({},t),{removeScore:[uo,Ge].includes(n),matchUpStatus:n||vt}));return v&&{error:Ph}||f&&wv(t)||m&&d6(t)||l&&Pa(t)||p&&g()||c&&o6({tournamentRecord:e,drawDefinition:r,structure:o,matchUp:i})||!d&&{error:Ph}||u&&p6(t)||s&&wv(t)||W({result:{error:za},stack:a})}function d6(t){let e=Pa(t);return e.error?e:Hc(t)}function p6(t){const e=wv(LO(FO({},t),{removeScore:!0}));return e.error?e:Hc(t)}function wv(t){var e;const r="scoreModification";if(t.isCollectionMatchUp&&((e=t.dualMatchUp)==null?void 0:e.winningSide)&&!t.projectedWinningSide){const s=Pa(t);if(s.error)return W({result:s,stack:r})}const o=!!t.matchUp.collectionId,i=Mn(t);if(o){const{matchUpTieId:s,drawDefinition:a,matchUpsMap:c}=t,l=Qn({tournamentRecord:t.tournamentRecord,matchUpId:s,event:t.event,drawDefinition:a,matchUpsMap:c});if(l.error)return W({result:l,stack:r});Object.assign(i,{tieMatchUpResult:l})}return W({result:i,stack:r})}function f6({drawDefinition:t,structure:e,matchUp:r}){var n,o;const{drawPositions:i}=r,{positionAssignments:s}=et({drawDefinition:t,structure:e}),c=s.filter(({drawPosition:v})=>i==null?void 0:i.includes(v)).map(v=>{var f;const{extension:m}=Vt({element:v,name:jo});return(f=m==null?void 0:m.value)==null?void 0:f.groupOrder}),{containerStructures:l}=_a({drawDefinition:t}),u=l[e.structureId],d=(o=(n=Fc({drawDefinition:t,structureId:u}))==null?void 0:n.links)==null?void 0:o.source;return{structureIds:d==null?void 0:d.filter(v=>{var f;return Gt(c,((f=v.source)==null?void 0:f.finishingPositions)||[])}).map(v=>v.source.structureId)}}function VO({drawDefinition:t,structureId:e}){if(!t)return{error:pe};const{structure:r}=Te({drawDefinition:t,structureId:e}),n=((t==null?void 0:t.links)||[]).filter(i=>{var s;return((s=i.source)==null?void 0:s.structureId)===e}).map(i=>{var s;return(s=i.target)==null?void 0:s.structureId});return{playoffStructures:((t==null?void 0:t.structures)||[]).filter(i=>n.includes(i.structureId)&&i.stage===st),structure:r}}function xO({withStageGrouping:t,stageSequences:e,stageSequence:r,roundTarget:n,stages:o,event:i,stage:s}){if(!i)return{error:Le};const a={},c=[];for(const l of i.drawDefinitions||[]){const{structures:u,stageStructures:d}=Cr({withStageGrouping:t,stageSequences:e,drawDefinition:l,stageSequence:r,roundTarget:n,stages:o,stage:s});if(c.push(...u),d)for(const p of Object.keys(d))a[p]||(a[p]=[]),a[p].push(...d[p])}return{structures:c,stageStructures:a}}function v6({withStageGrouping:t,tournamentRecord:e,stageSequences:r,stageSequence:n,roundTarget:o,stages:i,stage:s}){if(!e)return{error:ee};const a={},c=[];for(const l of e.events||[]){const{structures:u,stageStructures:d}=xO({withStageGrouping:t,stageSequences:r,stageSequence:n,roundTarget:o,stages:i,event:l,stage:s});if(c.push(...u),d)for(const p of Object.keys(d))a[p]||(a[p]=[]),a[p].push(...d[p])}return{structures:c,stageStructures:a}}function m6(t){const e=[];if(!(t!=null&&t.drawDefinition))return{error:pe};const r=wi(t),n=BO(t);return{actions:e,state:{isComplete:r,hasPlayoffPositionsFilled:n}}}function wi(t){if(!(t!=null&&t.drawDefinition))return!1;const e=Lc(t);let{includesTeamMatchUps:r,completedMatchUps:n,pendingMatchUps:o,upcomingMatchUps:i}=e||{};return r&&(n=n.filter(({matchUpType:a})=>a===He),o=o.filter(({matchUpType:a})=>a===He),i=i.filter(({matchUpType:a})=>a===He)),!!((n==null?void 0:n.length)&&!(o!=null&&o.length)&&!i.length)}function BO(t){var e,r;const{drawDefinition:n,structureId:o}=t;if(!n)return{error:pe};const{playoffStructures:i}=VO({drawDefinition:n,structureId:o});if(!(i!=null&&i.length))return!1;const s=((r=(e=n==null?void 0:n.entries)==null?void 0:e.filter(u=>Wo.includes(u==null?void 0:u.entryStatus)))==null?void 0:r.length)||0;let a=0;return(i||[]).reduce((u,d)=>{var p;return!((p=d==null?void 0:d.positionAssignments)!=null&&p.filter(f=>(f.participantId&&a++,!(f!=null&&f.bye)&&!(f!=null&&f.participantId))).length)&&u},!0)||a===s}function kO({drawDefinition:t,matchUpsMap:e,structure:r,matchUp:n}){const o=[];if(r.finishingPosition===na&&wi({drawDefinition:t,structure:r})){const{structureIds:s}=f6({drawDefinition:t,matchUpsMap:e,structure:r,matchUp:n});s!=null&&s.length&&o.push(...s)}return{connectedStructureIds:o}}function $v(t){const{dualWinningSideChange:e,matchUpStatusCodes:r,tournamentRecord:n,drawDefinition:o,matchUpFormat:i,matchUpStatus:s,winningSide:a,matchUpId:c,structure:l,matchUp:u,event:d,score:p}=t,v=jc({matchUpStatus:s})||[uo,yr].includes(s)&&e,f="attemptToModifyScore",m=!!u.collectionId,g=Po({drawDefinition:o,structure:l});if(!(m||g||g6({structure:l,matchUp:u})))return{error:_h};const _=[Ge].includes(s),I=Mn({matchUpStatusCodes:v&&r||[],matchUpStatus:v&&s||St,tournamentRecord:n,drawDefinition:o,matchUpFormat:i,removeScore:_,winningSide:a,matchUpId:c,matchUp:u,event:d,score:p});return W({result:I,stack:f})}function g6({structure:t,matchUp:e}){const{drawPositions:r}=e,{positionAssignments:n}=Et({structure:t});return n.filter(i=>(r==null?void 0:r.includes(i.drawPosition))&&i.participantId).length===2}function Nv({lineUp:t}){if(!Array.isArray(t))return;const e={};return Ve(t.flatMap(({collectionAssignments:n})=>n.map(({collectionId:o,collectionPosition:i})=>[o,i].join("|")))).forEach(n=>{const[o,i]=n.split("|"),s=parseInt(i),{assignedParticipantIds:a}=nu({collectionPosition:s,collectionId:o,lineUp:t});a.forEach(c=>{e[c]||(e[c]=[]),e[c].push({collectionId:o,collectionPosition:s})})}),Object.keys(e).map(n=>({participantId:n,collectionAssignments:e[n]}))}function Hu({drawPositions:t,structure:e}){if([Ie,de].includes(e.stage)&&e.stageSequence===1)return;const{positionAssignments:r}=et({structure:e});r.filter(({drawPosition:o})=>t==null?void 0:t.includes(o)).forEach(o=>{tt({element:o,extension:{name:Hl,value:!0}})})}function Oa(t){if(!t)return;if(ut(t))return parseInt(t);const e=t.split("-")[0];if(ut(e))return parseInt(e)}const kt=({finishingPosition:t=_i,structureAbbreviation:e,seedAssignments:r=[],stageSequence:n=1,qualifyingRoundNumber:o,seedingProfile:i,matchUpFormat:s,structureType:a,structureName:c,matchUps:l=[],structureId:u,roundOffset:d,roundLimit:p,stageOrder:v,structures:f,stage:m})=>{const g={structureId:u||We(),structureAbbreviation:e,finishingPosition:t,seedAssignments:r,matchUpFormat:s,stageSequence:n,structureName:c};m&&(g.stage=m),v&&(g.stageOrder=v),p&&(g.roundLimit=p),d&&(g.roundOffset=d),a&&(g.structureType=a),i&&(g.seedingProfile=i),o&&(g.qualifyingRoundNumber=o);const h=[].concat(...l.map(_=>_.drawPositions)).filter(Boolean);return f?g.structures=f:(g.matchUps=l,g.positionAssignments=Ve(h).sort((_,I)=>_-I).map(_=>({drawPosition:_}))),g};function GO({drawPositions:t}){const e=o=>t.filter(i=>i!==o).map(i=>[o,i]),r=[].concat(...t.map(e)),n=Ve(r.map(Av)).map(o=>o.split("|").map(i=>+i));return{groupMatchUps:r,uniqueMatchUpGroupings:n}}function Av(t){return t.sort(Wt).join("|")}var h6=Object.defineProperty,_6=Object.defineProperties,I6=Object.getOwnPropertyDescriptors,WO=Object.getOwnPropertySymbols,P6=Object.prototype.hasOwnProperty,y6=Object.prototype.propertyIsEnumerable,HO=(t,e,r)=>e in t?h6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qO=(t,e)=>{for(var r in e||(e={}))P6.call(e,r)&&HO(t,r,e[r]);if(WO)for(var r of WO(e))y6.call(e,r)&&HO(t,r,e[r]);return t},S6=(t,e)=>_6(t,I6(e));function qc({structureName:t=de,stageSequence:e=1,structureOptions:r,appliedPolicies:n,seedingProfile:o,stage:i=de,matchUpType:s,roundTarget:a,structureId:c,drawSize:l,idPrefix:u,isMock:d,uuids:p}){const{groupCount:v,groupSize:f}=O6({structureOptions:r,appliedPolicies:n,drawSize:l}),m=na;let g;const h=le(1,v+1).map(I=>{const P=b6({groupSize:f,structureOrder:I,matchUpType:s,drawSize:l,idPrefix:u,isMock:d});return g=Math.max(...P.map(({roundNumber:O})=>O)),kt({structureName:`Group ${I}`,structureId:p==null?void 0:p.pop(),structureType:ou,finishingPosition:m,structureOrder:I,matchUpType:s,matchUps:P})}),_=kt({structureId:c||(p==null?void 0:p.pop()),structureType:tr,finishingPosition:m,seedingProfile:o,structureName:t,stageSequence:e,matchUpType:s,structures:h,stage:i});return a&&tt({extension:{name:Tn,value:a},element:_}),qO({structures:[_],maxRoundNumber:g,groupCount:v,links:[],groupSize:f},B)}function O6({appliedPolicies:t,structureOptions:e,drawSize:r}){let n=e==null?void 0:e.groupSize;const o=(e==null?void 0:e.groupSizeLimit)||8,{validGroupSizes:i}=Uv({groupSizeLimit:o,drawSize:r}),s=Math.max(...i);n&&i.includes(n)||(n&&n>4||!i.includes(4)?n=s:n=4);const c=Math.ceil(r/n);return{groupSize:n,groupCount:c}}function Uv({drawSize:t,groupSizeLimit:e=10}){const r=le(3,e+1).filter(n=>{const o=Math.ceil(t/n),i=o*n-t,s=Math.ceil(t/o),a=Math.ceil(i/o);return(!i||i<n)&&s===n&&s>=3&&a<2});return S6(qO({},B),{validGroupSizes:r})}function b6({structureOrder:t,matchUpType:e,groupSize:r,idPrefix:n,drawSize:o,isMock:i,uuids:s}){const a=(t-1)*r,c=le(1+a,r+1+a),{uniqueMatchUpGroupings:l}=GO({drawPositions:c}),u=E6({groupSize:r,drawPositionOffset:a});return l.map(v).sort((f,m)=>(f.roundNumber||1/0)-(m.roundNumber||1/0));function p(f){return u.reduce((m,g,h)=>g.includes(f)?h+1:m,void 0)}function v(f){const m=Av(f),g=p(m),h=[1,o],_=T6({structureOrder:t,drawPositions:f,roundNumber:g,idPrefix:n,uuids:s}),I={matchUpStatus:g?vt:qe,matchUpType:e,finishingPositionRange:{winner:h,loser:h},drawPositions:f,roundNumber:g,matchUpId:_};return i&&(I.isMock=!0),I}}function T6({structureOrder:t,drawPositions:e,roundNumber:r,idPrefix:n,uuids:o}){return n?`${n}-${t}-${r}-DP-${e.join("-")}`:(o==null?void 0:o.pop())||We()}function E6({groupSize:t,drawPositionOffset:e}){const r=d=>[...Array(d)].map((p,v)=>v),n=r(2*Math.round(t/2)+1).slice(1),o=r(n.length-1).map(()=>[]);let i=n.slice(0,n.length/2),s=n.slice(n.length/2);n.slice(1).forEach((d,p)=>{i.forEach((g,h)=>{o[p].push([i[h],s[h]])});const v=i.shift(),f=i.pop(),m=s.shift();i=[].concat(v,m,...i),s=[].concat(...s,f)});const a=i.shift(),c=i.pop(),l=s.shift();i=[].concat(a,l,...i),s=[].concat(...s,c);const u=d=>d[0].reduce((p,v)=>p+v);return o.reverse().sort((d,p)=>u(d)-u(p)).map(d=>d.filter(p=>p.every(v=>v<=t)).map(p=>{const v=p.map(f=>f+e);return Av(v)}))}var w6=Object.defineProperty,$6=Object.defineProperties,N6=Object.getOwnPropertyDescriptors,YO=Object.getOwnPropertySymbols,A6=Object.prototype.hasOwnProperty,U6=Object.prototype.propertyIsEnumerable,zO=(t,e,r)=>e in t?w6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Cv=(t,e)=>{for(var r in e||(e={}))A6.call(e,r)&&zO(t,r,e[r]);if(YO)for(var r of YO(e))U6.call(e,r)&&zO(t,r,e[r]);return t},Mv=(t,e)=>$6(t,N6(e));function qu({roundRobinGroupsCount:t,participantsCount:e,cluster:r}){if(!ut(e))return W({result:{error:Z},context:{participantsCount:e},stack:"getSeedBlocks"});const n=Ds(e);if(t){const p=Math.min(t,n),v=[];let f=1;for(le(0,p).forEach(()=>{v.push([f]),f++});f<n;){const m=le(f,f+p);f+=p,v.push(m)}return Mv(Cv({},B),{seedBlocks:v})}const o=le(1,n+1);let i=[],s=n/2;for(;s>1;){const p=Rt(o,s),v=p.length;p.forEach((f,m)=>{let g;const h=m<v/2,_=m%2===0,I=f[0],P=f[f.length-1];r&&v>4?v===8?g=h?P:I:g=_?I:P:g=h?I:P,Gt(f,i)||i.push(g)}),s=s/2}const a=o.filter(p=>!i.includes(p));for(;a.length;)a.length%2===0?i.push(a.pop()):i.push(a.shift());const c=le(0,20).map(p=>Math.pow(2,p));c.unshift(1);const l=c.indexOf(n);let u=0;const d=[];return le(0,l).forEach(p=>{d.push(i.slice(u,u+c[p])),u+=c[p]}),Mv(Cv({},B),{seedBlocks:d})}function Yu({drawSize:t,roundRobinGroupsCount:e}){const r="getSeedGroups";if(!ut(t))return W({result:{error:Z},context:{drawSize:t},stack:r});if(e){if(!ut(e))return W({result:{error:Z},context:{roundRobinGroupsCount:e},stack:r});let n=1;const o=Math.floor(t/e);return{seedGroups:le(0,o).map(()=>{const s=le(n,n+e);return n+=e,s})}}else{const{seedBlocks:n}=qu({participantsCount:t,roundRobinGroupsCount:e});let o=0;return{seedGroups:(n||[]).map(s=>(s||[]).map(()=>(o+=1,o)))}}}function C6({roundRobinGroupsCount:t,participantsCount:e}){if(t){const{validGroupSizes:o}=Uv({drawSize:e});if(!o.map(a=>Math.ceil(e/a)).includes(t))return W({result:{error:Z},context:{roundRobinGroupsCount:t}})}const{seedGroups:r}=Yu({drawSize:e,roundRobinGroupsCount:t}),n=(r==null?void 0:r.map(o=>Math.min(...o)))||[];return Mv(Cv({},B),{seedingThresholds:n})}function _s({provisionalPositioning:t,appliedPolicies:e,drawDefinition:r,allPositions:n,structure:o,event:i}){var s;let a=[];if(!o)return{error:Rs};const{roundMatchUps:c}=ze({matchUpFilters:{roundNumbers:[1]},provisionalPositioning:t,structure:o}),{seedAssignments:l}=dn({provisionalPositioning:t,drawDefinition:r,structure:o,event:i}),{positionAssignments:u}=Et({structure:o}),d=u.length,p=(l==null?void 0:l.length)||0;let v=[];const m=Object.keys(c).sort((D,F)=>D-F).map(D=>{const F=c[D].map(G=>G.drawPositions).flat(1/0).filter(Boolean),R=F.filter(G=>!v.includes(G));return v=v.concat(...F),R}).filter(D=>D.length).reverse(),g=m.pop(),h=g&&Math.min(...g)-1||0,_=(s=e==null?void 0:e.seeding)==null?void 0:s.seedingProfile,I=(g==null?void 0:g.length)||0,P=m.filter(D=>D.filter(F=>F<=p).length),{stage:O,structureType:y,roundLimit:S}=o,T=y===tr,E=!T&&(m==null?void 0:m.length),b=(g==null?void 0:g.length)&&!Vr(I),N=!T&&O===Ie&&S,w=P.flat(1/0),$=E?w==null?void 0:w.length:0,U=n?d:p,A=b?0:!E&&U||w.length<U&&U-w.length||0;if(N){const D=o.matchUps.filter(({roundNumber:R})=>R===o.roundLimit).length,F=g.length/D;if(!E){const R=Yc(_),G=Rt(g,F);let x=1;const z=le(0,G[0].length).map(()=>{const j=le(x,x+G.length);return x+=G.length,j});({validSeedBlocks:a}=KO({drawPositionBlocks:G,positioning:R,seedGroups:z}))}}else if(T){const D=M6({seedingProfile:_,structure:o});if(!D||D.error)return console.log(D),D;({validSeedBlocks:a}=D)}else E?a=P.map(D=>({seedNumbers:D,drawPositions:D})):b&&Rt(g,2).map((F,R)=>({drawPositions:[F[0]],seedNumbers:[R+1]})).forEach(F=>a.push(F));if(!T&&!b&&!N){const{blocks:D,error:F}=D6({drawPositionOffset:h,seedNumberOffset:$,seedCountGoal:A,seedingProfile:_,baseDrawSize:I});if(F)return{validSeedBlocks:[],isContainer:T,isFeedIn:E,error:F};D.forEach(R=>a.push(R))}const C=[].concat(...a.map(D=>D.drawPositions)).reduce((D,F)=>(g==null?void 0:g.includes(F))&&D,!0);return!b&&!E&&!T&&!C?{error:fF,validSeedBlocks:[],isContainer:T,isFeedIn:E}:{validSeedBlocks:a,isContainer:T,isFeedIn:E,isLucky:b}}function M6({seedingProfile:t,structure:e}){var r;const n=e.structures||[],o=n.length,i=(r=et({structure:e}))==null?void 0:r.positionAssignments,s=Yc(t),{seedGroups:a}=Yu({drawSize:i.length,roundRobinGroupsCount:o}),c=n.map(l=>et({structure:l}).positionAssignments.map(u=>u.drawPosition));return KO({drawPositionBlocks:c,positioning:s,seedGroups:a})}function KO({positioning:t,seedGroups:e,drawPositionBlocks:r}){const n=[],o=(a,c)=>a-c,i=(a,c)=>c-a,s=[];return e.forEach((a,c)=>{c&&t!==wf&&or(a),a.forEach((l,u)=>{const d=c%2?r.length-u-1:u,p=r[d].sort(c%2?i:o).find(v=>!s.includes(v));s.push(p),n.push({seedNumbers:[l],drawPositions:[p]})})}),{validSeedBlocks:n}}function D6({roundRobinGroupsCount:t,drawPositionOffset:e=0,seedNumberOffset:r=0,seedingProfile:n,seedCountGoal:o,baseDrawSize:i}){let s=1;const a=[],{seedBlocks:c}=qu({cluster:Yc(n)===Ef,participantsCount:i,roundRobinGroupsCount:t});s=0;for(const u of c){if(s+1>o)break;const d=u.map(v=>v+e),p=l(s+1,u.length).map(v=>+v+r);s+=u.length,a.push({drawPositions:d,seedNumbers:p})}return{blocks:a};function l(u,d){return Array.from(new Array(d),(p,v)=>v+u)}}function zu({drawDefinition:t,seedBlockInfo:e,drawPosition:r,structureId:n,seedNumber:o}){var i,s,a,c,l;const{structure:u}=Te({drawDefinition:t,structureId:n}),{appliedPolicies:d}=at({drawDefinition:t});let p=e==null?void 0:e.validSeedBlocks;if(p||(p=(i=_s({appliedPolicies:d,drawDefinition:t,structure:u}))==null?void 0:i.validSeedBlocks),(a=(s=d==null?void 0:d.seeding)==null?void 0:s.validSeedPositions)!=null&&a.ignore)return!0;if((l=(c=d==null?void 0:d.seeding)==null?void 0:c.validSeedPositions)!=null&&l.strict){const f=p.find(g=>g.seedNumbers.includes(o));return((f==null?void 0:f.drawPositions)||[]).includes(r)}return[].concat(...p.map(f=>f.drawPositions)).includes(r)}function Ku({provisionalPositioning:t,drawDefinition:e,seedBlockInfo:r,structureId:n,randomize:o,event:i}){var s,a;const{structure:c}=Te({drawDefinition:e,structureId:n}),{seedAssignments:l}=dn({provisionalPositioning:t,drawDefinition:e,structure:c,event:i}),{positionAssignments:u}=Et({structure:c}),p=u.filter(R=>R.participantId||R.bye||R.qualifier).map(R=>R.drawPosition).filter(Boolean),{appliedPolicies:v}=at({drawDefinition:e}),g=((r==null?void 0:r.validSeedBlocks)||((s=_s({provisionalPositioning:t,appliedPolicies:v,drawDefinition:e,structure:c,event:i}))==null?void 0:s.validSeedBlocks)||[]).filter(R=>R.drawPositions.filter(x=>!p.includes(x)).length)[0],h=l.map(R=>R.participantId).filter(Boolean),_=u.map(R=>R.participantId).filter(Boolean),I=h.filter(R=>_.includes(R)),P=h.filter(R=>!_.includes(R)),O=l.filter(R=>P.includes(R.participantId)),y=l.filter(R=>!R.participantId),T=(O.length||y.length)&&(g==null?void 0:g.drawPositions.filter(R=>!p.includes(R)))||[],E=o?or(T):T,b=[],N=E.map(()=>{const R=F(O,b),G=R==null?void 0:R.participantId;return G&&b.push(G),G}).filter(Boolean),w=l.filter(R=>I.includes(R.participantId)).map(R=>R.seedNumber),U=((g==null?void 0:g.seedNumbers)||[]).filter(R=>!w.includes(R)),A=l.filter(R=>U.includes(R.seedNumber)).map(R=>R.participantId),M=(a=v==null?void 0:v.seeding)==null?void 0:a.duplicateSeedNumbers;return{nextSeedBlock:g,unplacedSeedParticipantIds:(M!==void 0?M:!0)?N:A,unplacedSeedNumbers:U,unfilledPositions:E,unplacedSeedAssignments:O};function F(R,G){const x=R.filter(L=>!G.includes(L.participantId)),z=Math.min(...x.map(L=>Oa(L.seedValue))),j=x.filter(L=>Oa(L.seedValue)===z);return or(j).pop()}}function Yc(t){if(typeof t=="string")return t;if(typeof t=="object")return t.positioning}function Is({participantId:t,drawDefinition:e,entryStatus:r,entryStage:n}){var o;if(!e)return{error:pe};const i=(o=e.entries)==null?void 0:o.find(s=>s.participantId===t&&(!r||r===s.entryStatus)&&(!n||n===s.entryStage));return t&&i}var j6=Object.defineProperty,QO=Object.getOwnPropertySymbols,R6=Object.prototype.hasOwnProperty,F6=Object.prototype.propertyIsEnumerable,JO=(t,e,r)=>e in t?j6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L6=(t,e)=>{for(var r in e||(e={}))R6.call(e,r)&&JO(t,r,e[r]);if(QO)for(var r of QO(e))F6.call(e,r)&&JO(t,r,e[r]);return t};function Ps({provisionalPositioning:t,tournamentRecord:e,drawDefinition:r,seedingProfile:n,participantId:o,seedBlockInfo:i,structureId:s,seedNumber:a,seedValue:c,eventId:l,event:u}){var d,p;const v="assignSeed",{structure:f}=Te({drawDefinition:r,structureId:s}),{positionAssignments:m}=Et({structure:f}),{seedAssignments:g}=dn({provisionalPositioning:t,drawDefinition:r,structure:f,event:u}),h=g.map(T=>T.seedNumber),_=Is({drawDefinition:r,participantId:o});if(o&&!_)return W({result:{error:co},context:{participantId:o},stack:v});const I=(p=(d=It({event:u}).flightProfile)==null?void 0:d.flights)==null?void 0:p.length,P=I&&I>1,O=m.find(T=>T.participantId===o),y=O==null?void 0:O.drawPosition;if(y){const{appliedPolicies:T}=at({tournamentRecord:e,drawDefinition:r,event:u});if(!zu({drawPosition:y,appliedPolicies:T,drawDefinition:r,seedBlockInfo:i,structureId:s,seedNumber:a}))return W({result:{error:fh},context:{assignedDrawPosition:y},info:"invalid seed position",stack:v})}h.includes(a)||g.push({seedNumber:a,seedValue:c});let S;return g.forEach(T=>{T.participantId===o&&T.seedNumber!==a&&(T.participantId=void 0),T.seedNumber===a&&(T.participantId=o,!(n!=null&&n.groupSeedingThreshold)&&!P&&(T.seedValue=c||a),S=!0)}),S?(VP({tournamentId:e==null?void 0:e.tournamentId,structureIds:[s],drawDefinition:r,structure:f,eventId:l}),L6({},B)):W({result:{error:pF},stack:v})}function ZO({inContextDrawMatchUps:t,drawDefinition:e,assignments:r,matchUpsMap:n,structure:o}){var i,s,a;const c=(i=_a({drawDefinition:e}))==null?void 0:i.containedStructures,l=((s=c==null?void 0:c[o.structureId])==null?void 0:s.map(({structureId:f})=>f))||[];l.push(o==null?void 0:o.structureId);const u=(r==null?void 0:r.map(({drawPosition:f})=>f))||[],d=(t==null?void 0:t.filter(f=>l.includes(f.structureId)&&jt(f.drawPositions||[],u).length))||[],p=d.map(({matchUpId:f})=>f),v=((a=n==null?void 0:n.drawMatchUps)==null?void 0:a.filter(f=>p.includes(f.matchUpId)))||[];return{drawPositions:u,matchUps:v,targetMatchUps:d}}var V6=Object.defineProperty,XO=Object.getOwnPropertySymbols,x6=Object.prototype.hasOwnProperty,B6=Object.prototype.propertyIsEnumerable,e0=(t,e,r)=>e in t?V6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,k6=(t,e)=>{for(var r in e||(e={}))x6.call(e,r)&&e0(t,r,e[r]);if(XO)for(var r of XO(e))B6.call(e,r)&&e0(t,r,e[r]);return t};function Dv({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:n,assignments:o,structure:i,event:s}){const{drawPositions:a,matchUps:c,targetMatchUps:l}=ZO({inContextDrawMatchUps:t,matchUpsMap:n,assignments:o,structure:i});for(const u of l)u.matchUpType===Zr&&(u.sides||[]).forEach((d,p)=>{var v;if(d!=null&&d.drawPosition&&(a!=null&&a.includes(d.drawPosition))){const f=c.find(({matchUpId:m})=>m===u.matchUpId);(v=f.sides)!=null&&v[p]&&(delete f.sides[p].lineUp,Qe({tournamentId:e==null?void 0:e.tournamentId,context:"cleanupLineUps",eventId:s==null?void 0:s.eventId,drawDefinition:r,matchUp:f}))}});return k6({},B)}var G6=Object.defineProperty,W6=Object.defineProperties,H6=Object.getOwnPropertyDescriptors,t0=Object.getOwnPropertySymbols,q6=Object.prototype.hasOwnProperty,Y6=Object.prototype.propertyIsEnumerable,r0=(t,e,r)=>e in t?G6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,z6=(t,e)=>{for(var r in e||(e={}))q6.call(e,r)&&r0(t,r,e[r]);if(t0)for(var r of t0(e))Y6.call(e,r)&&r0(t,r,e[r]);return t},K6=(t,e)=>W6(t,H6(e));function vn({provisionalPositioning:t,inContextDrawMatchUps:e,isQualifierPosition:r,sourceMatchUpStatus:n,automaticPlacement:o,drawPositionIndex:i,tournamentRecord:s,drawDefinition:a,seedingProfile:c,participantId:l,seedBlockInfo:u,drawPosition:d,matchUpsMap:p,structureId:v,event:f}){var m;const g="assignDrawPosition";if(!l&&!r)return W({result:{error:yt},stack:g});p=p||Kt({drawDefinition:a}),e||({matchUps:e}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:a,matchUpsMap:p}));const h=Te({drawDefinition:a,structureId:v});if(h.error)return W({result:h,stack:g});const{structure:_}=h;if(Po({drawDefinition:a,structure:_}))return W({result:{error:Gr},stack:g});const{seedAssignments:I}=dn({provisionalPositioning:t,drawDefinition:a,structure:_,event:f}),P=I.find($=>$.participantId===l),O=P==null?void 0:P.seedNumber,{appliedPolicies:y}=at({tournamentRecord:s,drawDefinition:a,structure:_,event:f});if(O&&!zu({seedNumber:O,appliedPolicies:y,drawDefinition:a,seedBlockInfo:u,drawPosition:d,structureId:v}))return W({result:{error:fh},context:{drawPosition:d},stack:g});const{positionAssignments:S}=Et({structure:_}),T=S.find($=>$.drawPosition===d);if(!T)return W({result:{error:js},context:{drawPosition:d},stack:g});if(S.map(Xe).includes(l))return W({result:{error:Vs},context:{drawPosition:d},stack:g});const{containsParticipant:b,containsBye:N}=w(T);if(N){let $=Ia({inContextDrawMatchUps:e,tournamentRecord:s,drawDefinition:a,drawPosition:d,structureId:v,matchUpsMap:p,event:f});if($.error)return W({result:$,stack:g})}if(b&&T.participantId!==l){const{activeDrawPositions:$}=Gc({drawDefinition:a,structureId:v});if($.includes(d))return W({result:{error:bp},stack:g});Dv({assignments:[T],inContextDrawMatchUps:e,tournamentRecord:s,drawDefinition:a,matchUpsMap:p,structure:_})}if(T.participantId=l,r&&(T.qualifier=!0),(_==null?void 0:_.stageSequence)>1||[$t,st].includes(_.stage)){const $=_.stage===Ie?Ie:de,A=(a.structures.find(M=>M.stage===$&&M.stageSequence===1).seedAssignments||[]).find(M=>M.participantId===l);A&&Ps(K6(z6({eventId:f==null?void 0:f.eventId,provisionalPositioning:t,tournamentRecord:s,drawDefinition:a,seedingProfile:c},A),{structureId:v,event:f}))}if(_.structureType!==tr)Q6({provisionalPositioning:t,inContextDrawMatchUps:e,positionAssignments:S,sourceMatchUpStatus:n,automaticPlacement:o,drawPositionIndex:i,tournamentRecord:s,drawDefinition:a,drawPosition:d,matchUpsMap:p,structure:_,event:f});else{pO({inContextDrawMatchUps:e,positionAssignments:S,tournamentRecord:s,drawDefinition:a,matchUpsMap:p,structure:_});const{drawPositions:$,matchUps:U,targetMatchUps:A}=ZO({assignments:[T],inContextDrawMatchUps:e,drawDefinition:a,matchUpsMap:p,structure:_});if((U==null?void 0:U.length)===1&&U[0].matchUpType===He){const M=(m=A==null?void 0:A[0])==null?void 0:m.sides.reduce((C,D,F)=>$!=null&&$.includes(D.drawPosition)?F:C,void 0);Ev({inContextTargetMatchUp:A[0],teamParticipantId:l,matchUp:U[0],drawPositionSideIndex:M,tournamentRecord:s,drawDefinition:a})}}return o||(Hu({drawPositions:[d],structure:_}),Wc({drawDefinition:a,positionAction:{name:"positionAssignment",participantId:l,drawPosition:d,structureId:v}})),Ho({tournamentId:s==null?void 0:s.tournamentId,drawDefinition:a,source:g,structure:_,event:f}),Object.assign({positionAssignments:S},B);function w($){const U=$.bye,A=$.qualifier,M=$.participantId;return{containsBye:U,containsQualifier:A,containsParticipant:M,filled:U||A||M}}}function Q6({provisionalPositioning:t,inContextDrawMatchUps:e,sourceMatchUpStatus:r,automaticPlacement:n,drawPositionIndex:o,tournamentRecord:i,drawDefinition:s,drawPosition:a,matchUpsMap:c,structure:l,event:u}){const d={isCollectionMatchUp:!1},{matchUps:p}=ze({provisionalPositioning:t,inContextDrawMatchUps:e,drawDefinition:s,matchUpFilters:d,matchUpsMap:c,structure:l,event:u}),{roundMatchUps:v}=pr({matchUps:p}),{initialRoundNumber:f}=hs({drawPosition:a,matchUps:p}),m=v[f].find(g=>{var h;return(h=g.drawPositions)==null?void 0:h.includes(a)});if(m){const g=ya({matchUpId:m.matchUpId,inContextDrawMatchUps:e,sourceMatchUpStatus:r,automaticPlacement:n,drawPositionIndex:o,tournamentRecord:i,drawDefinition:s,drawPosition:a,matchUpsMap:c});if(g.error)return W({stack:"assignDrawPositionToMatchUps",context:{drawPosition:a},result:g})}}var J6=Object.defineProperty,Z6=Object.defineProperties,X6=Object.getOwnPropertyDescriptors,n0=Object.getOwnPropertySymbols,e5=Object.prototype.hasOwnProperty,t5=Object.prototype.propertyIsEnumerable,o0=(t,e,r)=>e in t?J6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jv=(t,e)=>{for(var r in e||(e={}))e5.call(e,r)&&o0(t,r,e[r]);if(n0)for(var r of n0(e))t5.call(e,r)&&o0(t,r,e[r]);return t},i0=(t,e)=>Z6(t,X6(e));function r5({winnerMatchUpDrawPositionIndex:t,inContextDrawMatchUps:e,projectedWinningSide:r,sourceMatchUpStatus:n,winningDrawPosition:o,tournamentRecord:i,winnerTargetLink:s,sourceMatchUpId:a,drawDefinition:c,winnerMatchUp:l,dualMatchUp:u,matchUpsMap:d,event:p}){var v,f,m;const g="directWinner";if(s){const h=l.drawPositions||[],_=h[t],I=s.source.structureId,P=Te({structureId:I,drawDefinition:c});if(P.error)return P;const{structure:O}=P,{positionAssignments:y}=Et({structureId:I,drawDefinition:c}),S=y.find(A=>A.drawPosition===o),T=S==null?void 0:S.participantId,E=s.target.structureId,{positionAssignments:b}=Et({structureId:E,drawDefinition:c}),N=b.find(A=>A.participantId===T),w=N==null?void 0:N.drawPosition,$=b.filter(A=>{const M=h.includes(A.drawPosition),C=!A.participantId&&!A.bye&&!A.qualifier;return M&&C}).map(A=>A.drawPosition),U=$.includes(_);if(s.target.roundNumber===1&&U)vn({drawPositionIndex:t,drawPosition:_,participantId:T,structureId:E,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:c,matchUpsMap:d,event:p});else if($.length){const A=$.pop();vn({drawPositionIndex:t,participantId:T,structureId:E,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:c,drawPosition:A,matchUpsMap:d,event:p})}else if(w){const A=ya({drawPositionIndex:t,drawPosition:w,matchUpId:l.matchUpId,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:c,matchUpsMap:d});if(A.error)return W({result:A,stack:g})}else if(O.stage!==Ie){const A="winner target position unavaiallble";return console.log(A),{error:A}}if(O!=null&&O.seedAssignments&&O.structureId!==E){const A=O.seedAssignments.find(({participantId:M})=>M===T);A&&Ps(i0(jv({eventId:l==null?void 0:l.eventId,structureId:E},A),{tournamentRecord:i,drawDefinition:c}))}}else{const h=ya({drawPositionIndex:t,matchUpId:l.matchUpId,drawPosition:o,inContextDrawMatchUps:e,sourceMatchUpStatus:n,tournamentRecord:i,sourceMatchUpId:a,drawDefinition:c,matchUpsMap:d});if(h.error)return h}if(u&&r){const h=(v=u.sides)==null?void 0:v.find(_=>_.sideNumber===r);if(h!=null&&h.lineUp){const _=u.roundPosition,I=l.roundPosition,P=_===I&&_!==1||Math.floor(_/2)===I?2:1,O=(f=d==null?void 0:d.drawMatchUps)==null?void 0:f.find(({matchUpId:T})=>T===l.matchUpId),y=[1,2].map(T=>{var E;const b=((E=O.sides)==null?void 0:E.find(N=>N.sideNumber===T))||{};return i0(jv({},b),{sideNumber:T})});O.sides=y;const S=O.sides.find(T=>T.sideNumber===P);if(S){const T=(m=h.lineUp)==null?void 0:m.filter(E=>E==null?void 0:E.participantId);S.lineUp=Nv({lineUp:T}),Qe({tournamentId:i==null?void 0:i.tournamentId,eventId:l==null?void 0:l.eventId,matchUp:O,context:g,drawDefinition:c})}}}return jv({},B)}var n5=Object.defineProperty,o5=Object.defineProperties,i5=Object.getOwnPropertyDescriptors,s0=Object.getOwnPropertySymbols,s5=Object.prototype.hasOwnProperty,a5=Object.prototype.propertyIsEnumerable,a0=(t,e,r)=>e in t?n5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qu=(t,e)=>{for(var r in e||(e={}))s5.call(e,r)&&a0(t,r,e[r]);if(s0)for(var r of s0(e))a5.call(e,r)&&a0(t,r,e[r]);return t},c0=(t,e)=>o5(t,i5(e));function c5(t){var e,r;const{loserMatchUpDrawPositionIndex:n,inContextDrawMatchUps:o,projectedWinningSide:i,sourceMatchUpStatus:s,loserDrawPosition:a,tournamentRecord:c,loserTargetLink:l,sourceMatchUpId:u,drawDefinition:d,loserMatchUp:p,dualMatchUp:v,matchUpsMap:f,event:m}=t,g="directLoser",h=l.linkCondition,_=p.drawPositions||[],I=h===Yn&&p.roundNumber===2&&Math.min(..._.filter(Boolean)),P=I||_[n],O=I||_[1-n],y=l.source.structureId,{structure:S}=Te({structureId:y,drawDefinition:d}),{matchUps:T}=ze({afterRecoveryTimes:!1,inContext:!0,drawDefinition:d,structure:S,event:m}),b=T.filter(L=>{var q;return(q=L.drawPositions)==null?void 0:q.includes(a)}).filter(L=>{const q=L.sides.find(H=>H.drawPosition===a),k=L.matchUpStatus===Ge||L.matchUpStatus===Be&&!Dt(L);return(q==null?void 0:q.sideNumber)===L.winningSide&&!k}),N=h===Yn&&b.length===0,{positionAssignments:w}=Et({structureId:y,drawDefinition:d}),$=w.find(L=>L.drawPosition===a),U=$==null?void 0:$.participantId,A=l.target.structureId,{positionAssignments:M}=Et({structureId:A,drawDefinition:d}),C=M.filter(({drawPosition:L})=>_.includes(L));if(C.some(L=>L.participantId===U))return Qu({},B);const F=C.filter(L=>{const q=_.includes(L.drawPosition),k=!L.participantId&&!L.bye&&!L.qualifier;return q&&k}).map(L=>L.drawPosition),R=F.includes(P),G=l.target.roundNumber>1&&F.length,x=l.target.roundNumber===1&&R;if(I){const L=z();if(L.error)return W({result:L,stack:g})}else if(x){const L=V();if(L.error)return W({result:L,stack:g})}else if(G){const L=F.sort(Wt)[0],q=vn({drawPositionIndex:n,participantId:U,structureId:A,drawPosition:L,automaticPlacement:!0,inContextDrawMatchUps:o,sourceMatchUpStatus:s,tournamentRecord:c,sourceMatchUpId:u,drawDefinition:d,matchUpsMap:f,event:m});if(q.error)return W({result:q,stack:g})}else return W({result:{error:js},context:{loserDrawPosition:a,loserTargetLink:l},stack:g});if(S!=null&&S.seedAssignments&&S.structureId!==A){const L=S.seedAssignments.find(({participantId:q})=>q===U);L&&Ps(c0(Qu({eventId:p==null?void 0:p.eventId,structureId:A},L),{tournamentRecord:c,drawDefinition:d}))}if(v&&i){const L=(e=v.sides)==null?void 0:e.find(q=>q.sideNumber===3-i);if(L!=null&&L.lineUp){const{roundNumber:q,eventId:k}=p,{roundPosition:H}=v,Q=q===1?2-H%2:1,K=(r=f==null?void 0:f.drawMatchUps)==null?void 0:r.find(({matchUpId:te})=>te===p.matchUpId),Y=[1,2].map(te=>{var ne;const oe=((ne=K.sides)==null?void 0:ne.find(se=>se.sideNumber===te))||{};return c0(Qu({},oe),{sideNumber:te})});K.sides=Y;const J=K.sides.find(te=>te.sideNumber===Q);J&&(J.lineUp=Nv({lineUp:L.lineUp}),Qe({tournamentId:c==null?void 0:c.tournamentId,matchUp:K,context:g,drawDefinition:d,eventId:k}))}}return Qu({},B);function z(){const L="loserLinkFedFMLC";return W(N?{result:V(),stack:L}:{result:j(),stack:L})}function j(){const L=jr({drawPositionIndex:n,drawPosition:O,structureId:A,tournamentRecord:c,sourceMatchUpId:u,drawDefinition:d,event:m});return W({result:L,stack:"assignLoserPositionBye"})}function V(){const L=vn({drawPositionIndex:n,drawPosition:P,participantId:U,structureId:A,automaticPlacement:!0,inContextDrawMatchUps:o,sourceMatchUpStatus:s,tournamentRecord:c,sourceMatchUpId:u,drawDefinition:d,matchUpsMap:f,event:m});return W({result:L,stack:"assignLoserDrawPosition"})}}var l5=Object.defineProperty,l0=Object.getOwnPropertySymbols,u5=Object.prototype.hasOwnProperty,d5=Object.prototype.propertyIsEnumerable,u0=(t,e,r)=>e in t?l5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ba=(t,e)=>{for(var r in e||(e={}))u5.call(e,r)&&u0(t,r,e[r]);if(l0)for(var r of l0(e))d5.call(e,r)&&u0(t,r,e[r]);return t};function d0(t){const e=$v(t);if(e.error)return e;const r=jc({matchUpStatus:t.matchUpStatus}),{dualWinningSideChange:n,projectedWinningSide:o,inContextDrawMatchUps:i,tournamentRecord:s,drawDefinition:a,matchUpStatus:c,dualMatchUp:l,matchUpsMap:u,winningSide:d,targetData:p,matchUpId:v,structure:f,matchUp:m,event:g}=t,h="directParticipants",_=!!m.collectionId,I=Po({drawDefinition:a,structure:f});let P=m.drawPositions,O;if(_){const{matchUpTieId:y,matchUpsMap:S}=t,T=Qn({matchUpId:y,tournamentRecord:s,drawDefinition:a,matchUpsMap:S,event:g});O=T&&{tieMatchUpResult:T};const E=i.find(({matchUpId:b})=>b===y);if(P=E==null?void 0:E.drawPositions,!n)return W({result:ba(ba({},B),O),stack:h})}if(I)return W({result:ba(ba({},B),O),stack:h});if(P){const y=o?o-1:d-1,S=1-y,T=P[y],E=P[S],{targetLinks:{loserTargetLink:b,winnerTargetLink:N,byeTargetLink:w},targetMatchUps:{winnerMatchUpDrawPositionIndex:$,loserMatchUpDrawPositionIndex:U,winnerMatchUp:A,loserMatchUp:M,byeMatchUp:C}}=p;if(A){const D=r5({sourceMatchUpStatus:r&&c||St,winnerMatchUpDrawPositionIndex:$,sourceMatchUpId:v,inContextDrawMatchUps:i,projectedWinningSide:o,winningDrawPosition:T,tournamentRecord:s,winnerTargetLink:N,drawDefinition:a,winnerMatchUp:A,dualMatchUp:l,matchUpsMap:u,event:g});if(D.error)return W({result:D,stack:h})}if(M){const D=c5({sourceMatchUpStatus:r&&c||St,loserMatchUpDrawPositionIndex:U,sourceMatchUpId:v,inContextDrawMatchUps:i,projectedWinningSide:o,loserDrawPosition:E,tournamentRecord:s,loserTargetLink:b,drawDefinition:a,loserMatchUp:M,winningSide:d,matchUpsMap:u,dualMatchUp:l,event:g});if(D.error)return W({result:D,stack:h})}if(C){const D=C.drawPositions||[],F=Math.min(...D.filter(Boolean)),R=w.target.structureId,G=jr({drawPosition:F,structureId:R,tournamentRecord:s,drawDefinition:a,event:g});if(G.error)return W({result:G,stack:h})}}else return W({result:{error:Op},stack:h});return W({result:ba(ba({},B),O),stack:h})}function $i(t){var e,r;const{inContextDrawMatchUps:n,targetData:o,drawDefinition:i,relevantLink:s}=t;if((s==null?void 0:s.linkCondition)===Yn&&((e=o==null?void 0:o.matchUp)==null?void 0:e.matchUpStatus)===qe)return!1;const{targetMatchUps:{loserMatchUp:c,winnerMatchUp:l},targetLinks:u}=o,d=[Be,Ge].includes(c==null?void 0:c.matchUpStatus),p=((r=l==null?void 0:l.drawPositions)==null?void 0:r.filter(Boolean).length)||0;if(c!=null&&c.winningSide&&!d||l!=null&&l.winningSide&&p===2&&(!l.feedRound||![Ge,Be].includes(l==null?void 0:l.matchUpStatus)))return!0;let v=c&&sr({matchUpId:c.matchUpId,inContextDrawMatchUps:n,drawDefinition:i}),f=l&&sr({matchUpId:l.matchUpId,inContextDrawMatchUps:n,drawDefinition:i});const m=v&&$i({relevantLink:u==null?void 0:u.loserTargetLink,targetData:v,inContextDrawMatchUps:n,drawDefinition:i});return!!(f&&$i({targetData:f,inContextDrawMatchUps:n,drawDefinition:i})||m)}var p5=Object.defineProperty,f5=Object.defineProperties,v5=Object.getOwnPropertyDescriptors,p0=Object.getOwnPropertySymbols,m5=Object.prototype.hasOwnProperty,g5=Object.prototype.propertyIsEnumerable,f0=(t,e,r)=>e in t?p5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,h5=(t,e)=>{for(var r in e||(e={}))m5.call(e,r)&&f0(t,r,e[r]);if(p0)for(var r of p0(e))g5.call(e,r)&&f0(t,r,e[r]);return t},_5=(t,e)=>f5(t,v5(e));function I5(t){var e,r;const n="replaceQualifier";let o;const{inContextDrawMatchUps:i,inContextMatchUp:s,drawDefinition:a,winningSide:c}=t,l=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(l.target.feedProfile===an){const u=s.sides.find(({sideNumber:p})=>p!==c).participantId,d=i.find(p=>p.structureId===l.target.structureId&&p.roundNumber===l.target.roundNumber&&p.sides.some(({participantId:v})=>v===u));if((d==null?void 0:d.matchUpStatus)===vt){const p=sr({matchUpId:d.matchUpId,inContextDrawMatchUps:i,drawDefinition:a});if(!$i({inContextDrawMatchUps:i,drawDefinition:a,targetData:p})){const{structure:f}=Te({structureId:d.structureId,drawDefinition:a}),m=et({structure:f}).positionAssignments;for(const g of m)if(g.participantId===u){const h=s.sides.find(({sideNumber:_})=>_===c).participantId;if(g.participantId=h,f.positionAssignments)f.positionAssignments=m;else if(f.structures){const _=Object.assign({},...m.map(I=>({[I.drawPosition]:I.participantId})));for(const I of f.structures)I.positionAssignments.forEach(P=>P.participantId=_[P.drawPosition])}Ho({tournamentId:(r=t.tournamentRecord)==null?void 0:r.tournamentId,event:t.event,drawDefinition:a,source:n,structure:f}),o=!0}}}}return _5(h5({},B),{qualifierReplaced:o})}var P5=Object.defineProperty,y5=Object.defineProperties,S5=Object.getOwnPropertyDescriptors,v0=Object.getOwnPropertySymbols,O5=Object.prototype.hasOwnProperty,b5=Object.prototype.propertyIsEnumerable,m0=(t,e,r)=>e in t?P5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,T5=(t,e)=>{for(var r in e||(e={}))O5.call(e,r)&&m0(t,r,e[r]);if(v0)for(var r of v0(e))b5.call(e,r)&&m0(t,r,e[r]);return t},E5=(t,e)=>y5(t,S5(e));function w5(t){var e,r,n,o;const i="placeQualifier";let s;const{inContextDrawMatchUps:a,inContextMatchUp:c,drawDefinition:l,winningSide:u}=t,d=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(d.target.feedProfile===an){const p=(r=c.sides.find(({sideNumber:m})=>m===u))==null?void 0:r.participantId,v=a.filter(m=>m.structureId===d.target.structureId&&m.roundNumber===d.target.roundNumber&&m.sides.some(({participantId:g,qualifier:h})=>h&&!g)),f=gr(v);if((f==null?void 0:f.matchUpStatus)===vt){const m=sr({matchUpId:f.matchUpId,inContextDrawMatchUps:a,drawDefinition:l});if(!$i({inContextDrawMatchUps:a,drawDefinition:l,targetData:m})){const h=(n=f.sides.find(P=>P.qualifier&&!P.participantId))==null?void 0:n.drawPosition,{structure:_}=Te({structureId:f.structureId,drawDefinition:l}),I=et({structure:_}).positionAssignments;for(const P of I)if(P.drawPosition===h&&!P.participantId){if(P.participantId=p,_.positionAssignments)_.positionAssignments=I;else if(_.structures){const O=Object.assign({},...I.map(y=>({[y.drawPosition]:y.participantId})));for(const y of _.structures)y.positionAssignments.forEach(S=>S.participantId=O[S.drawPosition])}Ho({tournamentId:(o=t.tournamentRecord)==null?void 0:o.tournamentId,event:t.event,drawDefinition:l,source:i,structure:_}),s=!0}}}}return E5(T5({},B),{qualifierPlaced:s})}var $5=Object.defineProperty,N5=Object.defineProperties,A5=Object.getOwnPropertyDescriptors,g0=Object.getOwnPropertySymbols,U5=Object.prototype.hasOwnProperty,C5=Object.prototype.propertyIsEnumerable,h0=(t,e,r)=>e in t?$5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_0=(t,e)=>{for(var r in e||(e={}))U5.call(e,r)&&h0(t,r,e[r]);if(g0)for(var r of g0(e))C5.call(e,r)&&h0(t,r,e[r]);return t},M5=(t,e)=>N5(t,A5(e));function D5(t){var e,r;const n="attemptToSetWinningSide";let o;const{appliedPolicies:i,disableAutoCalc:s,drawDefinition:a,matchUpsMap:c,dualMatchUp:l,winningSide:u,structure:d,matchUp:p}=t;if(l!=null&&l._disableAutoCalc&&s!==!1)return $v(t);if(p.winningSide&&p.winningSide!==u){const{connectedStructureIds:g}=kO({drawDefinition:a,matchUpsMap:c,structure:d,matchUp:p});g.length&&(console.log({connectedStructureIds:g}),o=!0);const h=Pa(t);if(h.error)return h}const v=d0(t);if(v.error)return W({result:v,stack:n});let f,m;return t.qualifierChanging&&((e=i==null?void 0:i[Bl])!=null&&e.autoReplaceQualifiers)&&(f=I5(t).qualifierReplaced),t.qualifierAdvancing&&((r=i==null?void 0:i[Bl])!=null&&r.autoPlaceQualifiers)&&(m=w5(t).qualifierPlaced),W({result:_e(M5(_0(_0({},B),v),{connectedStructures:o,qualifierReplaced:f,qualifierPlaced:m})),stack:n})}var j5=Object.defineProperty,R5=Object.defineProperties,F5=Object.getOwnPropertyDescriptors,I0=Object.getOwnPropertySymbols,L5=Object.prototype.hasOwnProperty,V5=Object.prototype.propertyIsEnumerable,P0=(t,e,r)=>e in t?j5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zc=(t,e)=>{for(var r in e||(e={}))L5.call(e,r)&&P0(t,r,e[r]);if(I0)for(var r of I0(e))V5.call(e,r)&&P0(t,r,e[r]);return t},Rv=(t,e)=>R5(t,F5(e));function y0(t){var e;const{inContextDrawMatchUps:r,appliedPolicies:n,drawDefinition:o,matchUpsMap:i,targetData:s,matchUp:a}=t;let{iteration:c=0}=t;c+=1;const l="removeDoubleExit";jn();const{targetLinks:{loserTargetLink:u},targetMatchUps:{loserMatchUp:d,winnerMatchUp:p,loserTargetDrawPosition:v}}=s;if(p&&p.matchUpStatus!==qe&&(jn(),S0(Rv(zc({},t),{targetMatchUp:p,sourceMatchUp:a,iteration:c}))),d&&d.matchUpStatus!==qe){const f=r.find(({matchUpId:g})=>g===d.matchUpId),{structure:m}=Te({drawDefinition:o,structureId:f.structureId});if(jn(),(e=n==null?void 0:n.progression)!=null&&e.doubleExitPropagateBye){const g=bv({targetLink:u,drawPosition:v,inContextDrawMatchUps:r,drawDefinition:o,matchUpsMap:i});if(g.error)return W({result:g,stack:l})}else{const g=S0(Rv(zc({},t),{structure:m,targetMatchUp:d,iteration:c}));if(g.error)return W({result:g,stack:l})}}return W({result:zc({},B),stack:l})}function S0(t){var e,r,n,o,i;const{inContextDrawMatchUps:s,appliedPolicies:a,drawDefinition:c,sourceMatchUp:l,targetMatchUp:u,matchUpsMap:d,structure:p,iteration:v}=t,f="conditionallyRemoveDrawPosition";jn();const m=sr({matchUpId:u.matchUpId,inContextDrawMatchUps:s,drawDefinition:c}),{targetMatchUps:{winnerMatchUp:g}}=m,h=d==null?void 0:d.drawMatchUps.find(E=>E.matchUpId===u.matchUpId);let _=[],I,P,O;if(u.feedRound){const E=(e=g==null?void 0:g.drawPositions)==null?void 0:e.filter(Boolean);O=E==null?void 0:E.find(b=>u.drawPositions.includes(b))}else if(!l)O=(r=jt((u==null?void 0:u.drawPositions)||[],(g==null?void 0:g.drawPositions)||[]))==null?void 0:r[0];else if(P=(n=iO({structureId:p.structureId,matchUp:l,matchUpsMap:d}))==null?void 0:n.pairedPreviousMatchUp,I=[_t,bt].includes(P==null?void 0:P.matchUpStatus),_=((o=P==null?void 0:P.drawPositions)==null?void 0:o.filter(Boolean))||[],[...Lt,qe].includes(P==null?void 0:P.matchUpStatus)||(P==null?void 0:P.winningSide)){const b=l.drawPositions||[];let N=(i=u.drawPositions)==null?void 0:i.filter(Boolean);Gt(b,N)&&(N=N==null?void 0:N.filter($=>!b.includes($))),O=b.concat(_).find($=>N==null?void 0:N.includes($))}if(g&&O){jn();const E=_O({winningDrawPosition:O,winnerMatchUp:g,inContextDrawMatchUps:s,drawDefinition:c,matchUpsMap:d});if(E.error)return W({result:E,stack:f})}let y=y0({targetData:m,matchUp:u,inContextDrawMatchUps:s,appliedPolicies:a,drawDefinition:c,matchUpsMap:d,structure:p,iteration:v});if(y.error)return W({result:y,stack:f});const S=x5({pairedPreviousDoubleExit:I,noContextTargetMatchUp:h}),T=!I;return y=Mn(Rv(zc({},t),{matchUpStatus:S,removeScore:T,score:{scoreStringSide1:"",scoreStringSide2:"",sets:void 0},removeWinningSide:!0,matchUp:h,matchUpId:u.matchUpId,matchUpStatusCodes:[]})),y.error?W({result:y,stack:f}):zc({},B)}function x5({pairedPreviousDoubleExit:t,noContextTargetMatchUp:e}){return e.matchUpStatus===qe?qe:t?[bt,Be].includes(e==null?void 0:e.matchUpStatus)?Be:Ge:vt}function B5(t){var e,r,n;const o="removeQualifier";let i;const{inContextDrawMatchUps:s,inContextMatchUp:a,drawDefinition:c}=t,l=(e=t.targetData.targetLinks)==null?void 0:e.winnerTargetLink;if(l.target.feedProfile===an){const u=(r=a.sides.find(({sideNumber:p})=>p===a.winningSide))==null?void 0:r.participantId,d=s.find(p=>p.structureId===l.target.structureId&&p.roundNumber===l.target.roundNumber&&p.sides.some(({participantId:v})=>v===u));if((d==null?void 0:d.matchUpStatus)===vt){const p=sr({matchUpId:d.matchUpId,inContextDrawMatchUps:s,drawDefinition:c});if(!$i({inContextDrawMatchUps:s,drawDefinition:c,targetData:p})){const{structure:f}=Te({structureId:d.structureId,drawDefinition:c}),m=et({structure:f}).positionAssignments;for(const g of m)if(g.participantId===u){if(g.participantId=void 0,f.positionAssignments)f.positionAssignments=m;else if(f.structures){const h=Object.assign({},...m.map(_=>({[_.drawPosition]:_.participantId})));for(const _ of f.structures)_.positionAssignments.forEach(I=>I.participantId=h[I.drawPosition])}Ho({tournamentId:(n=t.tournamentRecord)==null?void 0:n.tournamentId,event:t.event,drawDefinition:c,source:o,structure:f}),i=!0}}}}return{qualifierRemoved:i}}var k5=Object.defineProperty,G5=Object.defineProperties,W5=Object.getOwnPropertyDescriptors,O0=Object.getOwnPropertySymbols,H5=Object.prototype.hasOwnProperty,q5=Object.prototype.propertyIsEnumerable,b0=(t,e,r)=>e in t?k5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ta=(t,e)=>{for(var r in e||(e={}))H5.call(e,r)&&b0(t,r,e[r]);if(O0)for(var r of O0(e))q5.call(e,r)&&b0(t,r,e[r]);return t},Fv=(t,e)=>G5(t,W5(e));function Y5(t){const{matchUp:e,matchUpStatus:r,score:n,winningSide:o}=t,i="noDownStreamDependencies";if([_t,bt].includes(e==null?void 0:e.matchUpStatus)&&![_t,bt].includes(r)){const m=y0(t);if(m.error)return W({result:m,stack:i})}const a=r===_t,c=Dt({score:n})&&!a&&(t.isCollectionMatchUp&&!t.projectedWinningSide||!o),l=t.removeScore||![Gn,yr].includes(r||Gn),u=t.isCollectionMatchUp&&t.dualMatchUp.winningSide&&!t.projectedWinningSide||e.winningSide&&!o&&!Dt({score:n}),d=r&&r!==vt,p=({removeScore:m}={})=>{var g,h;let _;const{structure:I,drawDefinition:P,dualMatchUp:O,disableAutoCalc:y}=t;if(O!=null&&O._disableAutoCalc&&y!==!1)return $v(t);const{connectedStructureIds:S}=kO({drawDefinition:P,structure:I,matchUp:e});S.length&&(console.log({connectedStructureIds:S}),_=!0),Object.assign(t,{removeScore:m});const T=Pa(t);if(T.error)return T;if(t.removingQualifier&&((h=(g=t.appliedPolicies)==null?void 0:g[Bl])!=null&&h.autoRemoveQualifiers)){const E=B5(t);return E.error?E:Ta(Fv(Ta({},B),{connectedStructures:_}),E)}return Fv(Ta({},B),{connectedStructures:_})};if(u&&o&&t.isCollectionMatchUp)return T0(t);const v=[uo,yr].includes(r)&&t.dualWinningSideChange,f=(o||v)&&D5(t)||c&&p({removeScore:l})||d&&u6(t)||u&&p({removeScore:l})||e&&T0(Fv(Ta({},t),{removeScore:!0}))||console.log("unknown condition")&&Ta({},B);return W({result:f,stack:i})}function T0(t){var e;const r="scoreModification";if(t.isCollectionMatchUp&&((e=t.dualMatchUp)==null?void 0:e.winningSide)&&!t.projectedWinningSide){const i=Pa(t);if(i.error)return i}const o=Mn(Ta({},t));if(t.isCollectionMatchUp){const{matchUpTieId:i,drawDefinition:s,event:a,matchUpsMap:c}=t,{removeWinningSide:l}=Qn({tournamentRecord:t.tournamentRecord,matchUpId:i,drawDefinition:s,matchUpsMap:c,event:a});l&&console.log("REMOVE WINNING SIDE")}return W({result:o,stack:r})}function z5(t){var e;const{tournamentRecord:r,inContextMatchUp:n,structure:o,drawDefinition:i}=t,s=n.roundNumber,a=n.sides.find(S=>S.sideNumber===n.winningSide),c=n.sides.find(S=>S.sideNumber!==n.winningSide),{drawPosition:l,participantId:u}=a,{drawPosition:d,participantId:p}=c,v="swapWinnerLoser",{matchUps:f}=ze(t),m=f.filter(({drawPositions:S,roundNumber:T})=>(S==null?void 0:S.includes(l))&&T>s);Ft({changeWinner:!0})&&console.log({existingWinnerSubsequentMatchUps:m}),m.forEach(S=>{var T,E;S.drawPositions=((T=S.drawPositions)==null?void 0:T.map(b=>b===l?d:b))||[],Qe({tournamentId:r==null?void 0:r.tournamentId,eventId:(E=t.event)==null?void 0:E.eventId,context:v,drawDefinition:i,matchUp:S})});const{stage:g,stageSequence:h}=o,_=i.structures.filter(({stage:S,stageSequence:T})=>S===g&&T>h).map(({structureId:S})=>S),{targetLinks:{loserTargetLink:I,winnerTargetLink:P}}=t.targetData,O=[I==null?void 0:I.target.structureId,(e=P==null?void 0:P.target)==null?void 0:e.structureId].filter(Boolean);return i.structures.filter(({stage:S,structureId:T})=>S!==g&&O.includes(T)).forEach(({stage:S,stageSequence:T,structureId:E})=>{_.includes(E)||_.push(E),i.structures.filter(({stage:b,stageSequence:N})=>b===S&&N>T).forEach(({structureId:b})=>{_.includes(b)||_.push(b)})}),i.structures.filter(({structureId:S})=>_.includes(S)).forEach(S=>{const{positionAssignments:T}=et({structure:S}),E=T.find(({participantId:N})=>N===u),b=T.find(({participantId:N})=>N===p);E&&(E.participantId=p),b&&(b.participantId=u)}),Mn(t)}var K5=Object.defineProperty,Q5=Object.defineProperties,J5=Object.getOwnPropertyDescriptors,E0=Object.getOwnPropertySymbols,Z5=Object.prototype.hasOwnProperty,X5=Object.prototype.propertyIsEnumerable,w0=(t,e,r)=>e in t?K5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eY=(t,e)=>{for(var r in e||(e={}))Z5.call(e,r)&&w0(t,r,e[r]);if(E0)for(var r of E0(e))X5.call(e,r)&&w0(t,r,e[r]);return t},tY=(t,e)=>Q5(t,J5(e));function Kc(t){var e,r,n;const o="setMatchUpStatus";[Ge,_t].includes(t.matchUpStatus)&&(t.score=void 0);const{allowChangePropagation:i,disableScoreValidation:s,tournamentRecords:a,tournamentRecord:c,disableAutoCalc:l,enableAutoCalc:u,drawDefinition:d,matchUpStatus:p,winningSide:v,matchUpId:f,event:m,score:g}=t;if(!d)return{error:pe};if([uo,Gn,yr,vt].includes(p)&&v)return{error:Z,winningSide:v,matchUpStatus:p};if(![void 0,...gV].includes(p))return W({result:{error:za},info:"matchUpStatus does not exist",stack:"setMatchUpStatus"});const h=Kt({drawDefinition:d});let{matchUps:_}=Nt({includeByeMatchUps:!0,nextMatchUps:!0,inContext:!0,drawDefinition:d,matchUpsMap:h});const I=h.drawMatchUps.find(j=>j.matchUpId===f),P=_.find(j=>j.matchUpId===f);if(!I||!_)return{error:kr};if((I.winningSide||v)&&p===qe)return{context:"Cannot have Bye with winningSide",error:Ep,matchUpStatus:p};const O=P.structureId,{structure:y}=Te({drawDefinition:d,structureId:O}),S=(e=P.drawPositions)==null?void 0:e.filter(Boolean);let T;if(I.matchUpType===He){if(l)tt({extension:{name:zs,value:!0},element:I});else if(u){const j=I.winningSide;sn({name:zs,element:I});const{winningSide:V,scoreStringSide1:L,scoreStringSide2:q,set:k}=Dc({drawDefinition:d,matchUpsMap:h,structure:y,matchUp:I,event:m}),H={scoreStringSide1:L,scoreStringSide2:q,sets:k?[k]:[]};T=V!==j,Object.assign(t,{winningSide:V,dualWinningSideChange:T,projectedWinningSide:V,score:H})}}if(I.matchUpType===He&&[ks].includes(p))return{error:Z,info:"Not supported for matchUpType: TEAM"};const E=P.matchUpTieId,b=sr({matchUpId:E||f,inContextDrawMatchUps:_,drawDefinition:d});if(g&&I.matchUpType!==He&&!s){const j=I.matchUpFormat||(y==null?void 0:y.matchUpFormat)||(d==null?void 0:d.matchUpFormat)||(m==null?void 0:m.matchUpFormat),V=qf({existingMatchUpStatus:I.matchUpStatus,matchUpFormat:j,matchUpStatus:p,winningSide:v,score:g});if(V.error)return V}const N=I!=null&&I.sides?[]:et({drawDefinition:d,structureId:O}).positionAssignments,w=((r=I.sides)==null?void 0:r.map(j=>j.participantId).filter(Boolean).length)===2||(S==null?void 0:S.length)===2&&(N==null?void 0:N.filter(j=>S.includes(j.drawPosition)).every(j=>j.participantId));if(p&&mV.includes(p)&&!w)return W({result:{error:za},info:"present in participantRequiredMatchUpStatuses",context:{matchUpStatus:p,bothSideParticipants:w}});const{appliedPolicies:$}=at({policyTypes:[Bl],tournamentRecord:c,drawDefinition:d,event:m});typeof t.policyDefinitions=="object"&&Object.assign($,t.policyDefinitions);const U=P.stage===Ie&&P.finishingRound===1,A=U&&v,M=U&&I.winningSide&&!v&&(!t.matchUpStatus||Ff(t.matchUpStatus))&&!Dt(t.outcome),C=A&&v!==I.winningSide&&I.winningSide;if(Object.assign(t,{inContextDrawMatchUps:_,qualifierAdvancing:A,qualifierChanging:C,removingQualifier:M,inContextMatchUp:P,appliedPolicies:$,matchUpTieId:E,matchUpsMap:h,targetData:b,structure:y,matchUp:I}),E){const{matchUp:j}=nt({matchUpId:E,inContext:!0,drawDefinition:d,matchUpsMap:h,event:m}),V=(n=Xt({matchUp:j,drawDefinition:d,structure:y,event:m}))==null?void 0:n.tieFormat,{projectedWinningSide:L}=rq({matchUpStatus:p,dualMatchUp:j,matchUpsMap:h,winningSide:v,tieFormat:V,structure:y,matchUp:I,event:m,score:g}),q=j.winningSide;T=L!==q,Object.assign(t,{isCollectionMatchUp:!0,dualWinningSideChange:T,projectedWinningSide:L,matchUpTieId:E,dualMatchUp:j,tieFormat:V})}const D=$i(t),F=jc({matchUpStatus:p});if(!E){if(D&&!v&&(Ff({matchUpStatus:p})||[_t,bt].includes(p)))return{error:Ep,activeDownstream:D,winningSide:v};if(v&&v===I.winningSide&&p&&!F)return{context:"winningSide must include directing matchUpStatus",error:Ep,directingMatchUpStatus:F,matchUpStatus:p}}const{schedule:R}=t;if(R){const j=Vu({disableNotice:!0,tournamentRecords:a,tournamentRecord:c,drawDefinition:d,matchUpId:f,schedule:R});if(j.error)return j}const G=I.matchUpType!==He&&!T&&v&&I.winningSide&&I.winningSide!==v;if(i&&G&&I.roundPosition)return z5(t);const x=v&&!E||t.projectedWinningSide;jn();const z=!D&&Y5(t)||x&&rY(t)||F&&$0(t)||{error:iL};return W({result:z,stack:o})}function rY(t){const{matchUp:e,winningSide:r,matchUpTieId:n,dualWinningSideChange:o}=t;return r===e.winningSide||n&&!o?$0(t):W({result:{error:Ah},stack:"winningSideWithDownstreamDependencies",context:{winningSide:r,matchUp:e}})}function $0(t){const{tournamentRecord:e,matchUp:r,event:n}=t,o=t.isCollectionMatchUp&&r.winningSide&&!t.winningSide&&!Dt({score:t.score}),i=t.isCollectionMatchUp?t.matchUpStatus||o&&vt||St:t.matchUpStatus||St,s=t.removeScore||[uo,Ge].includes(i)&&![Gn,yr].includes(i),a=Mn(tY(eY({},t),{matchUpStatus:i,removeWinningSide:o,removeScore:s}));if(a.error)return a;if(t.isCollectionMatchUp){const{matchUpTieId:c,drawDefinition:l,matchUpsMap:u}=t,d=Qn({matchUpId:c,tournamentRecord:e,drawDefinition:l,matchUpsMap:u,event:n});if(d.error)return d;Object.assign(a,{tieMatchUpResult:d})}return a}var nY=Object.defineProperty,N0=Object.getOwnPropertySymbols,oY=Object.prototype.hasOwnProperty,iY=Object.prototype.propertyIsEnumerable,A0=(t,e,r)=>e in t?nY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sY=(t,e)=>{for(var r in e||(e={}))oY.call(e,r)&&A0(t,r,e[r]);if(N0)for(var r of N0(e))iY.call(e,r)&&A0(t,r,e[r]);return t};function Ju(t){let e=t.structureIds;const{tournamentRecord:r,drawDefinition:n,matchUpFormat:o,structureId:i,matchUpId:s,event:a}=t;if(!n)return{error:pe};if(!o)return{error:wp};if(!xr(o))return{error:wl};const c="setMatchUpFormat";if(s){const l=nt({drawDefinition:n,matchUpId:s,event:a});if(l.error)return l;const u=l.matchUp;if((u==null?void 0:u.matchUpType)===Tt)return{error:Gr,info:"Cannot set matchUpFormat when { matchUpType: TEAM }"};u.matchUpFormat=o,Qe({tournamentId:r==null?void 0:r.tournamentId,eventId:a==null?void 0:a.eventId,context:c,drawDefinition:n,matchUp:u})}else if(Array.isArray(e)){if((a==null?void 0:a.eventType)===Tt)return{error:ri};for(const l of e){const u=Te({drawDefinition:n,structureId:l});if(u.error)return u;if(u.structure)u.structure.matchUpFormat=o;else return{error:Br}}}else if(i){if((a==null?void 0:a.eventType)===Tt)return{error:ri};const l=Te({drawDefinition:n,structureId:i});if(l.error)return l;if(l.structure)l.structure.matchUpFormat=o;else return{error:Br}}else n&&(n.matchUpFormat=o);return e=e||(i?[i]:void 0),Je({drawDefinition:n,structureIds:e}),sY({},B)}function U0({matchUpFormat:t,matchUpStatus:e,winningSide:r,score:n}={}){if(!n)return{sets:[]};const o=n.sets||[];let i=Jn({winnerFirst:!1,matchUpFormat:t,matchUpStatus:e,sets:o}),s=Jn({winnerFirst:!1,reversed:!0,matchUpFormat:t,matchUpStatus:e,sets:o}),a=Jn({matchUpFormat:t,matchUpStatus:e,winningSide:r,sets:o}),c=i===a?s:i;return r&&(i=r===1?a:c,s=r===2?a:c),{score:{sets:o,scoreStringSide1:i,scoreStringSide2:s}}}var aY=Object.defineProperty,C0=Object.getOwnPropertySymbols,cY=Object.prototype.hasOwnProperty,lY=Object.prototype.propertyIsEnumerable,M0=(t,e,r)=>e in t?aY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,uY=(t,e)=>{for(var r in e||(e={}))cY.call(e,r)&&M0(t,r,e[r]);if(C0)for(var r of C0(e))lY.call(e,r)&&M0(t,r,e[r]);return t};function Qc(t){var e;const{policyDefinitions:r,tournamentRecords:n,tournamentRecord:o,disableAutoCalc:i,enableAutoCalc:s,drawDefinition:a,matchUpFormat:c,matchUpId:l,schedule:u,event:d,notes:p}=t;if(!a)return{error:wr};if(!l)return{error:Ut};const{policy:v}=qi({policyType:Ys,tournamentRecord:o,event:d}),f=t.allowChangePropagation!==void 0&&t.allowChangePropagation||(v==null?void 0:v.allowChangePropagation)!==void 0&&v.allowChangePropagation||void 0;let{outcome:m}=t;if(c){const g=Ju({tournamentRecord:o,drawDefinition:a,matchUpFormat:c,matchUpId:l,event:d});if(g.error)return g}if((e=m==null?void 0:m.score)!=null&&e.sets&&!m.score.scoreStringSide1){const{score:g}=U0(m);m.score=g,m.score.sets=m.score.sets.filter(h=>h.side1Score||h.side2Score||h.side1TiebreakScore||h.side2TiebreakScore)}return Kc({matchUpStatusCodes:m==null?void 0:m.matchUpStatusCodes,matchUpStatus:m==null?void 0:m.matchUpStatus,winningSide:m==null?void 0:m.winningSide,allowChangePropagation:f,score:m==null?void 0:m.score,policyDefinitions:r,tournamentRecords:n,tournamentRecord:o,disableAutoCalc:i,enableAutoCalc:s,drawDefinition:a,matchUpFormat:c,matchUpId:l,schedule:u,event:d,notes:p})}function D0(t){if(!t.tournamentRecord)return{error:ee};const{tournamentRecords:e,tournamentRecord:r,outcomes:n}=t,o={};n.forEach(i=>{const{eventId:s}=i;o[s]||(o[s]=[]),o[s].push(i)});for(const i of Object.keys(o)){const{event:s}=xt({tournamentRecord:r,eventId:i});for(const a of o[i]){const{drawId:c}=a,l=s.drawDefinitions.find(u=>u.drawId===c);if(l){const{matchUpFormat:u,matchUpId:d}=a,p=Qc({schedule:a==null?void 0:a.schedule,tournamentRecords:e,tournamentRecord:r,drawDefinition:l,matchUpFormat:u,matchUpId:d,outcome:a,drawId:c,event:s});if(p.error)return p}}}return uY({},B)}var dY=Object.defineProperty,pY=Object.defineProperties,fY=Object.getOwnPropertyDescriptors,j0=Object.getOwnPropertySymbols,vY=Object.prototype.hasOwnProperty,mY=Object.prototype.propertyIsEnumerable,R0=(t,e,r)=>e in t?dY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,F0=(t,e)=>{for(var r in e||(e={}))vY.call(e,r)&&R0(t,r,e[r]);if(j0)for(var r of j0(e))mY.call(e,r)&&R0(t,r,e[r]);return t},gY=(t,e)=>pY(t,fY(e));function hY(t){const e=t.tournamentRecords,r=t.tournamentId||Sv(t);if(typeof r!="string")return{error:ao};const n=e[r];if(!n)return{error:ee};const{drawDefinition:o,event:i}=xt({eventId:t.eventId,drawId:t.drawId,tournamentRecord:n});return Qc(gY(F0({tournamentRecord:n},t),{drawDefinition:o,event:i}))}function _Y(t){const{tournamentRecords:e,outcomes:r}=t;if(!Array.isArray(r))return{error:Oe,info:zt("outcomes")};const n=r.reduce((o,i)=>o.includes(i.tournamentId)?o:o.concat(i.tournamentId),[]);for(const o of n){const i=e[o];if(!i)return{error:ee};const s=r.filter(a=>a.tournamentId===o);if(s.length){const a=D0({tournamentRecord:i,outcomes:s});if(a.error)return a}}return F0({},B)}function L0({courtPrefix:t="C|",minRowsCount:e,courtsData:r}){if(!Array.isArray(r))return{error:Z};const n=r==null?void 0:r.reduce((s,a)=>{const c=a.matchUps||[],l=Math.max(0,...c.map(u=>u.schedule.courtOrder||0));return l>s?l:s},1),o=e?Math.max(e,n):n,i=le(0,o).map(s=>({matchUps:le(0,r.length).map(a=>{const c=r[a],{courtId:l,venueId:u}=c;return{schedule:{courtOrder:s+1,venueId:u,courtId:l}}})}));return r.forEach((s,a)=>{var c;for(const l of s.matchUps){const u=(c=l.schedule)==null?void 0:c.courtOrder;u&&(i[u-1].matchUps[a]=l)}}),{courtPrefix:t,rows:i.map((s,a)=>Object.assign({rowId:`rowId-${a+1}`},...s.matchUps.map((c,l)=>({[`${t}${l}`]:c}))))}}var IY=Object.defineProperty,PY=Object.defineProperties,yY=Object.getOwnPropertyDescriptors,V0=Object.getOwnPropertySymbols,SY=Object.prototype.hasOwnProperty,OY=Object.prototype.propertyIsEnumerable,x0=(t,e,r)=>e in t?IY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lv=(t,e)=>{for(var r in e||(e={}))SY.call(e,r)&&x0(t,r,e[r]);if(V0)for(var r of V0(e))OY.call(e,r)&&x0(t,r,e[r]);return t},Vv=(t,e)=>PY(t,yY(e));function Jc({flight:t,suppressNotifications:e,modifyEventEntries:r,existingDrawCount:n,allowReplacement:o,checkEntryStatus:i,tournamentRecord:s,drawDefinition:a,event:c}){var l,u,d,p,v,f,m,g,h,_,I;if(!a)return{error:wr};if(!c)return{error:Le};c.drawDefinitions||(c.drawDefinitions=[]);const{drawId:P,drawName:O,entries:y}=a,{entries:S}=c;let T=0;if(n!==void 0&&n!==c.drawDefinitions.length)return{error:Z,info:"drawDefintions count mismatch"};const{flightProfile:E}=It({event:c}),b=t&&((l=E==null?void 0:E.flights)==null?void 0:l.find(j=>j.flightNumber===t.flightNumber)),N=(p=(d=(u=E==null?void 0:E.links)==null?void 0:u.find(j=>{var V;return((V=j==null?void 0:j.target)==null?void 0:V.drawId)===P}))==null?void 0:d.source)==null?void 0:p.drawId;if(N&&!c.drawDefinitions.find(j=>j.drawId===N))return{error:pe,sourceDrawId:N};if(b&&b.drawId!==a.drawId)return{error:ji,relevantFlight:b};const U=y.every(({participantId:j,entryStatus:V})=>{const L=b==null?void 0:b.drawEntries.find(q=>q.participantId===j);return!V||(L==null?void 0:L.entryStatus)===V}),A=!i||S&&(y==null?void 0:y.every(({participantId:j,entryStatus:V,entryStage:L})=>{const q=S.find(k=>k.participantId===j&&(!k.entryStage||k.entryStage===L));return(q==null?void 0:q.entryStatus)===V}));if(b&&!U)return W({result:{error:ji,context:{drawEntriesPresentInFlight:U,matchingEventEntries:A,relevantFlight:b},info:"Draw entries are not present in flight or do not match entryStatuses"}});if(r&&y.filter(Boolean).forEach(j=>{if(Wo.includes(j==null?void 0:j.entryStatus)){const V=S.filter(Boolean).find(L=>L.participantId===j.participantId);j.entryStatus&&V.entryStatus!==j.entryStatus&&(V.entryStatus=j.entryStatus,T+=1)}}),S&&!A)return W({result:{error:ji,context:{matchingEventEntries:A,eventEntries:S},info:"Draw entries do not match event entryStatuses"}});const M=((f=(v=E==null?void 0:E.flights)==null?void 0:v.map(({flightNumber:j})=>!isNaN(j)&&parseInt(j)))==null?void 0:f.filter(Boolean))||[],C=((m=c.drawDefinitions.map(({drawOrder:j})=>!isNaN(j)&&parseInt(j)))==null?void 0:m.filter(Boolean))||[];let D=Math.max(0,...C,...M)+1;const F=(g=E==null?void 0:E.flights)==null?void 0:g.find(j=>j.drawId===P);let R;if(F){F.drawName=a.drawName,R={name:tn,value:Vv(Lv({},E),{flights:E.flights})};const j=F.flightNumber;j&&!C.includes(j)?D=j:F.flightNumber=D}else{const j=(E==null?void 0:E.flights)||[];j.push({manuallyAdded:!0,flightNumber:D,drawEntries:y,drawName:O,drawId:P}),R={name:tn,value:Vv(Lv({},E||{}),{flights:j})}}Wn({event:c,extension:R}),Object.assign(a,{drawOrder:D});const G=c.drawDefinitions.find(j=>j.drawId===P),x=s==null?void 0:s.tournamentId,z=c.eventId;if(G){if(!o)return{error:sF};const j=(h=Dr({drawDefinition:G}))==null?void 0:h.matchUps,V=j==null?void 0:j.map(Mt),L=(_=Dr({drawDefinition:a}))==null?void 0:_.matchUps;if(!e){V!=null&&V.length&&yi({matchUpIds:V,action:"modifyDrawDefinition",tournamentId:x,eventId:z}),L!=null&&L.length&&Pi({matchUps:L,tournamentId:x,eventId:z}),c.drawDefinitions=c.drawDefinitions.map(k=>k.drawId===P?a:k);const q=(I=a.structures)==null?void 0:I.map(({structureId:k})=>k);Je({drawDefinition:a,tournamentId:x,structureIds:q,eventId:z})}}else if(c.drawDefinitions.push(a),!e){const{matchUps:j}=Dr({drawDefinition:a,event:c});Pi({tournamentId:s==null?void 0:s.tournamentId,matchUps:j}),Rc({drawDefinition:a,tournamentId:x,eventId:z})}return Vv(Lv({},B),{modifiedEventEntryStatusCount:T})}function bY({tournamentRecords:t,existingDrawCount:e,allowReplacement:r,drawDefinition:n,tournamentId:o,eventId:i,flight:s}){if(!i)return{error:Le};if(o=o||Sv({tournamentRecords:t,eventId:i}),!o)return{error:ao};const a=t[o];if(!a)return{error:ee};const c=xt({tournamentRecord:a,eventId:i});return c.error?c:Jc({event:c.event,existingDrawCount:e,allowReplacement:r,drawDefinition:n,flight:s})}var TY=Object.defineProperty,EY=Object.defineProperties,wY=Object.getOwnPropertyDescriptors,B0=Object.getOwnPropertySymbols,$Y=Object.prototype.hasOwnProperty,NY=Object.prototype.propertyIsEnumerable,k0=(t,e,r)=>e in t?TY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zu=(t,e)=>{for(var r in e||(e={}))$Y.call(e,r)&&k0(t,r,e[r]);if(B0)for(var r of B0(e))NY.call(e,r)&&k0(t,r,e[r]);return t},AY=(t,e)=>EY(t,wY(e));function Rn({allowDuplicateParticipantIdPairs:t,returnParticipant:e,tournamentRecord:r,disableNotice:n,pairOverride:o,participant:i}){var s,a,c;const l="addParticipant";if(!r)return{error:ee};if(!i)return W({result:{error:Ls},stack:l});i.participantId||(i.participantId=We()),r.participants||(r.participants=[]);const{participantId:u,individualParticipantIds:d}=i;if(r.participants.reduce((_,I)=>I.participantId===u||_,!1))return{error:jF};const{participantType:v,participantRole:f}=i;if(!v||!Object.keys(Pc).includes(v))return{error:In,participantType:v};if(!f)return{error:DF};const m=r.participants||[],g=m.filter(_=>_.participantType===Me).map(_=>_.participantId);if(v!==Me&&i.person)return{error:Z,person:i.person};if(d&&!Array.isArray(d))return{error:Z,individualParticipantIds:d};if(v===we){if(i.person)return{error:Z,person:i.person};if(i.individualParticipantIds){if(i.individualParticipantIds.length!==2&&!o)return W({result:{error:Qr,info:"PAIR must be 2 individualParticipantIds"},stack:l});{const P=m.filter(y=>y.participantType===Me).map(y=>y.participantId);if(!Array.isArray(i.individualParticipantIds))return W({result:{error:Qr},stack:l});if(!i.individualParticipantIds.reduce((y,S)=>P.includes(S)&&y,!0))return W({result:{error:Qr},stack:l})}}else return W({result:{error:lo},stack:l});const _=m.filter(P=>P.participantType===we).map(P=>({individualParticipantIds:P.individualParticipantIds,participant:P})),I=i.participantType===we&&_.find(P=>jt(P.individualParticipantIds,i.individualParticipantIds).length===2);if(I&&!t)return AY(Zu({},B),{existingParticipant:!0,participant:e&&ue(I.participant)});if(!i.participantName){const P=m.filter(y=>{var S;return(S=i.individualParticipantIds)==null?void 0:S.includes(y.participantId)});let O=P.map(y=>{var S;return(S=y.person)==null?void 0:S.standardFamilyName}).filter(Boolean).join("/");P.length===1&&(O+="/Unknown"),i.participantName=O}}else if(v===Me){if(!((s=i.person)!=null&&s.standardFamilyName)||!((a=i.person)!=null&&a.standardGivenName))return{error:VF};if(!i.participantName){const _=`${i.person.standardFamilyName.toUpperCase()}, ${i.person.standardGivenName}`;i.participantName=_}}else if(v&&[Ye,dr].includes(v)){if(d||(i.individualParticipantIds=[]),(c=i.individualParticipantIds)!=null&&c.length)for(const _ of i.individualParticipantIds){if(typeof _!="string")return W({result:{participantId:_,error:Z},stack:l});if(!g.includes(_))return W({result:{participantId:_,error:wt},stack:l})}}else return{error:In};r.participants.push(i),n||xe({payload:{tournamentId:r.tournamentId,participants:[i]},topic:fi});const h=Zu({participant:e&&ue(i)},B);return _e(h)}function to({allowDuplicateParticipantIdPairs:t,returnParticipants:e,participants:r=[],tournamentRecord:n}){if(!n)return{error:ee};n.participants||(n.participants=[]);const i=n.participants.map(p=>p.participantId)||[];r.forEach(p=>{p.participantId||(p.participantId=We())});const s=r.filter(p=>!i.includes(p.participantId)),a=r.filter(p=>i.includes(p.participantId)),c=s.filter(p=>p.participantType===Me),l=s.filter(p=>p.participantType!==Me),u=c.concat(...l),d=[];if(u.length){for(const v of u){const f=Rn({allowDuplicateParticipantIdPairs:t,returnParticipant:!0,disableNotice:!0,tournamentRecord:n,participant:v});if(f.error)return f;f.success&&!f.existingParticipant&&d.push(f.participant)}d.length&&xe({topic:fi,payload:{tournamentId:n.tournamentId,participants:d}});const p=Zu({participants:e&&ue(d),addedCount:d.length},B);return a.length&&Object.assign(p,{notAdded:a,info:Dp}),_e(p)}else return Zu({info:"No new participants to add",addedCount:0},B)}function UY({tournamentRecords:t,returnParticipant:e,pairOverride:r,tournamentId:n,participant:o}){if(typeof n!="string")return{error:ao};const i=t[n];return i?Rn({returnParticipant:e,tournamentRecord:i,pairOverride:r,participant:o}):{error:ee}}function CY({event:t}){var e;const r=`${Ar}.${Ur}`,{timeItem:n}=fn({element:t,itemType:r});if((e=n==null?void 0:n.itemValue)!=null&&e.PUBLIC){const{drawIds:o=[],seeding:i}=n.itemValue.PUBLIC||{},s={published:void 0,seedingScaleNames:[],drawIds:[]};return i&&Object.assign(s,n.itemValue.PUBLIC.seeding),{publishedDrawIds:o,publishedSeeding:s}}}function Xu({element:t,accessor:e}){if(typeof e!="string")return{values:[]};const r=ue(t),n=e.split(".");let o,i=[];a({targetElement:r,attributes:n});const s={value:o};return i.length&&(s.values=i),s;function a({targetElement:c,attributes:l=[],significantCharacters:u}){for(const[p,v]of l.entries())if(c&&c[v])if(Array.isArray(c[v])){const f=c[v],m=l.slice(p);f.forEach(g=>a({targetElement:g,attributes:m}))}else c=c[v],d({targetElement:c,index:p});function d({targetElement:p,index:v}){if(p&&v===l.length-1&&["string","number"].includes(typeof p)){const f=u?p.slice(0,u):p;o?i.includes(f)||i.push(f):(o=f,i.push(f))}}}}function ro({requireTimeStamp:t,scaleAttributes:e,participant:r}){var n,o;if(!r)return{error:Ls};if(typeof e!="object")return{error:Z};if(r.timeItems||(r.timeItems=[]),r&&Array.isArray(r.timeItems)){const{accessor:i,scaleType:s,eventType:a,scaleName:c}=e,l=[zi,s,a,c].join("."),d=r.timeItems.filter(p=>(p==null?void 0:p.itemType)===l).filter(p=>!t||(p==null?void 0:p.itemDate)).sort((p,v)=>(p.createdAt?new Date(p.createdAt).getTime():0)-(v.createdAt?new Date(v.createdAt).getTime():0)).pop();if(d){const[p,v,f,m]=(o=(n=d.itemType)==null?void 0:n.split("."))!=null?o:[];if(p!==zi)return{error:Cl};const g=i&&Xu({element:d.itemValue,accessor:i}),h=(g==null?void 0:g.value)||d.itemValue;return{scaleItem:{scaleDate:d.itemDate,scaleName:m,scaleType:v,eventType:f,scaleValue:h}}}else return{error:eL}}return{error:Ls}}function MY({publishedSeeding:t,usePublishState:e,withSeeding:r,participant:n,event:o}){var i,s,a;const c={},l=f=>[zi,rn,o.eventType,f].join("."),u=Object.assign({},...(n.timeItems||[]).filter(({itemType:f})=>f.split(".")[1]===rn).map(({itemType:f,itemValue:m})=>({[f]:m}))),d=((t==null?void 0:t.stageSeedingScaleNames)&&Object.values(t==null?void 0:t.stageSeedingScaleNames)||Array.isArray(t==null?void 0:t.seedingScaleNames)&&t.seedingScaleNames||[]).map(l),p=jt(Object.keys(u),d);if(!!(!e||!Object.keys(u).length&&!((i=t==null?void 0:t.drawIds)!=null&&i.length)||p.length)&&p.length){if(t!=null&&t.stageSeedingScaleNames){const f=Object.keys(t.stageSeedingScaleNames).map(g=>{const h=l(t.stageSeedingScaleNames[g]),_=u[h];return[g,_]}).filter(g=>g[1]).map(g=>({[g[0]]:{seedValue:g[1]}})),m=Object.assign({},...f);c.seedAssignments=m}else if(p){const f=p.map(m=>u[m]);c.seedValue=f.pop()}}else if(!e&&typeof r=="object"){const f=Object.keys(r).map(g=>{const h=l(r[g]),_=u[h];return[g,_]}).filter(g=>g[1]).map(g=>({[g[0]]:{seedValue:g[1]}})),m=Object.assign({},...f);c.seedAssignments=m}else{const{categoryName:f,ageCategoryCode:m}=o.category||{};let g;for(const h of[m,o.eventId,f]){const _={eventType:o.eventType,scaleType:rn,scaleName:h},I=ro({scaleAttributes:_,participant:n});if(I.scaleItem){g=I.scaleItem;break}}if(g&&(!e||(t==null?void 0:t.published)&&!((a=(s=t==null?void 0:t.published)==null?void 0:s.drawIds)!=null&&a.length))){const _=g.scaleValue;c.seedValue=_}}return c}var DY=Object.defineProperty,jY=Object.defineProperties,RY=Object.getOwnPropertyDescriptors,G0=Object.getOwnPropertySymbols,FY=Object.prototype.hasOwnProperty,LY=Object.prototype.propertyIsEnumerable,W0=(t,e,r)=>e in t?DY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ed=(t,e)=>{for(var r in e||(e={}))FY.call(e,r)&&W0(t,r,e[r]);if(G0)for(var r of G0(e))LY.call(e,r)&&W0(t,r,e[r]);return t},td=(t,e)=>jY(t,RY(e));function H0({tournamentRecord:t,matchUpFormat:e,event:r}){if(!t)return{error:ee};if(!xr(e))return{error:wl};const{extension:n}=mo({event:r,name:En}),o=n==null?void 0:n.value,{extension:i}=Sr({tournamentRecord:t,name:En}),s=i==null?void 0:i.value,a=(o==null?void 0:o.matchUpAverageTimes)&&cc(td(ed({},o),{matchUpFormat:e})),c=(s==null?void 0:s.matchUpAverageTimes)&&cc(td(ed({},s),{matchUpFormat:e})),l=[a,c].find(v=>v),u=(o==null?void 0:o.matchUpRecoveryTimes)&&lc(td(ed({},o),{matchUpFormat:e})),d=(s==null?void 0:s.matchUpRecoveryTimes)&&lc(td(ed({},s),{matchUpFormat:e})),p=[u,d].find(v=>v);return{matchUpFormat:e,averageTimes:l,recoveryTimes:p}}var VY=Object.defineProperty,xY=Object.defineProperties,BY=Object.getOwnPropertyDescriptors,q0=Object.getOwnPropertySymbols,kY=Object.prototype.hasOwnProperty,GY=Object.prototype.propertyIsEnumerable,Y0=(t,e,r)=>e in t?VY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zc=(t,e)=>{for(var r in e||(e={}))kY.call(e,r)&&Y0(t,r,e[r]);if(q0)for(var r of q0(e))GY.call(e,r)&&Y0(t,r,e[r]);return t},rd=(t,e)=>xY(t,BY(e));function xv({tournamentRecord:t,matchUpFormat:e,averageTimes:r,recoveryTimes:n,event:o}){if(!t)return{error:ee};if(r&&!Array.isArray(r))return{error:Z};if(n&&!Array.isArray(n))return{error:Z};const i=En;if(o){const{extension:s}=mo({event:o,name:i}),a=(s==null?void 0:s.value)||{},c=z0(rd(Zc({},a),{matchUpFormat:e,averageTimes:r,recoveryTimes:n}));Wn({event:o,extension:{name:i,value:c}})}else{const{extension:s}=Sr({tournamentRecord:t,name:i}),a=(s==null?void 0:s.value)||{},c=z0(rd(Zc({},a),{matchUpFormat:e,averageTimes:r,recoveryTimes:n}));pi({tournamentRecord:t,extension:{name:i,value:c}})}return Zc({},B)}function z0({matchUpAverageTimes:t=[],matchUpRecoveryTimes:e=[],averageTimes:r,recoveryTimes:n,matchUpFormat:o}){r=(r||[]).filter(a=>{var c,l;return((c=a==null?void 0:a.categoryNames)==null?void 0:c.length)||((l=a==null?void 0:a.categoryTypes)==null?void 0:l.length)});const i=(r==null?void 0:r.length)&&t.map(a=>{var c;return a!=null&&a.matchUpFormatCodes.includes(o)?rd(Zc({},a),{matchUpFormatCodes:(c=a.matchUpFormatCodes)==null?void 0:c.filter(l=>l!==o)}):a}).filter(({matchUpFormatCodes:a})=>a==null?void 0:a.length).concat({matchUpFormatCodes:[o],averageTimes:r});n=(n||[]).filter(a=>{var c,l;return((c=a==null?void 0:a.categoryNames)==null?void 0:c.length)||((l=a==null?void 0:a.categoryTypes)==null?void 0:l.length)});const s=(n==null?void 0:n.length)&&e.map(a=>{var c;return a!=null&&a.matchUpFormatCodes.includes(o)?rd(Zc({},a),{matchUpFormatCodes:(c=a.matchUpFormatCodes)==null?void 0:c.filter(l=>l!==o)}):a}).filter(({matchUpFormatCodes:a,averageTimes:c})=>(a==null?void 0:a.length)||c).concat({matchUpFormatCodes:[o],recoveryTimes:n});return{matchUpAverageTimes:(i==null?void 0:i.length)&&i||t,matchUpRecoveryTimes:(s==null?void 0:s.length)&&s||e}}function K0({tournamentRecord:t,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,event:i}){if(!t)return{error:ee};if(!xr(n))return{error:Z};if(!i)return{error:Le};const{averageTimes:s=[],recoveryTimes:a=[]}=H0({tournamentRecord:t,matchUpFormat:n,event:i}),c=i.category,l=(c==null?void 0:c.categoryName)||(c==null?void 0:c.ageCategoryCode)||(i==null?void 0:i.eventId);let u={categoryNames:[l],minutes:{}},d={categoryNames:[l],minutes:{}};const p=h=>{var _,I;if((_=h.categoryTypes)!=null&&_.includes(o)&&console.log("encountered:",{categoryType:o}),!((I=h.categoryNames)!=null&&I.includes(l)&&(h.categoryNames=h.categoryNames.filter(P=>P!==l),u={minutes:h.minutes,categoryNames:[l]},!h.categoryNames.length)))return h},v=!isNaN(parseInt(r)),f=!isNaN(parseInt(e)),m=s.map(p).filter(h=>{var _;return(_=h==null?void 0:h.categoryNames)==null?void 0:_.length}),g=a.map(p).filter(h=>{var _;return(_=h==null?void 0:h.categoryNames)==null?void 0:_.length});return v&&(Object.assign(u.minutes,{[(i==null?void 0:i.eventType)||pt]:r}),m.push(u)),f&&(Object.assign(d.minutes,{[(i==null?void 0:i.eventType)||pt]:e}),g.push(d)),!v&&!f?{error:Z}:xv({tournamentRecord:t,event:i,matchUpFormat:n,averageTimes:v&&m,recoveryTimes:f&&g})}function WY({tournamentRecords:t,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,tournamentId:i,eventId:s}){if(!s)return{error:Le};const a=Object.keys(t).filter(c=>!i||i===c);if(i&&!a.includes(i))return{error:Z};for(const c of a){const l=t[c],{event:u}=xt({tournamentRecord:l,eventId:s});if(u)return K0({tournamentRecord:l,recoveryMinutes:e,averageMinutes:r,matchUpFormat:n,categoryType:o,event:u})}return{error:Ir}}const Xc=({scheduleAttributes:t=["scheduledDate","scheduledTime"],schedule:e={}})=>!!Object.keys(e).filter(n=>t.includes(n)).filter(n=>e[n]).length;var HY=Object.defineProperty,qY=Object.defineProperties,YY=Object.getOwnPropertyDescriptors,Q0=Object.getOwnPropertySymbols,zY=Object.prototype.hasOwnProperty,KY=Object.prototype.propertyIsEnumerable,J0=(t,e,r)=>e in t?HY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,QY=(t,e)=>{for(var r in e||(e={}))zY.call(e,r)&&J0(t,r,e[r]);if(Q0)for(var r of Q0(e))KY.call(e,r)&&J0(t,r,e[r]);return t},JY=(t,e)=>qY(t,YY(e));function el({tournamentRecord:t}){if(!t)return{error:ee};const e=(({tournamentId:r,tournamentRank:n,tournamentStatus:o,formalName:i,tournamentName:s,promotionalName:a,onlineResources:c,localTimeZone:l,startDate:u,endDate:d,hostCountryCode:p,tournamentContacts:v,tournamentAddresses:f})=>({tournamentId:r,tournamentRank:n,tournamentStatus:o,formalName:i,tournamentName:s,promotionalName:a,onlineResources:c,localTimeZone:l,startDate:u,endDate:d,hostCountryCode:p,tournamentContacts:v,tournamentAddresses:f}))(t);return JY(QY({},B),{tournamentInfo:ue(e,!1,!0)})}var ZY=Object.defineProperty,nd=Object.getOwnPropertySymbols,Z0=Object.prototype.hasOwnProperty,X0=Object.prototype.propertyIsEnumerable,eb=(t,e,r)=>e in t?ZY(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tb=(t,e)=>{for(var r in e||(e={}))Z0.call(e,r)&&eb(t,r,e[r]);if(nd)for(var r of nd(e))X0.call(e,r)&&eb(t,r,e[r]);return t},rb=(t,e)=>{var r={};for(var n in t)Z0.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&nd)for(var n of nd(t))e.indexOf(n)<0&&X0.call(t,n)&&(r[n]=t[n]);return r};function nb({derivedDrawInfo:t,participantId:e,drawId:r}){var n,o,i,s;const a=(o=(n=t[r])==null?void 0:n.mainPositionAssignments)==null?void 0:o.find(u=>u.participantId===e),c=(s=(i=t[r])==null?void 0:i.qualifyingPositionAssignments)==null?void 0:s.find(u=>u.participantId===e),l={};if(a){const u=a,{participantId:d}=u,p=rb(u,["participantId"]);d&&(l[de]=tb({},p))}if(c){const u=c,{participantId:d}=u,p=rb(u,["participantId"]);d&&(l[Ie]=tb({},p))}return Object.keys(l).length?l:void 0}function XY({processParticipantId:t,tournamentRecords:e,tournamentRecord:r}){if(typeof r!="object"&&typeof e!="object")return{error:ee};const n=e?Object.values(e).map(({participants:i=[]})=>i).flat():r.participants||[];return{relevantParticipantIdsMap:Object.assign({},...n.map(({participantId:i,participantType:s,individualParticipantIds:a})=>{typeof t=="function"&&t(i);const c=(a||[]).map(l=>({participantType:Me,relevantParticipantId:l}));return{[i]:c.concat({relevantParticipantId:i,participantType:s})}}))}}var ez=Object.defineProperty,od=Object.getOwnPropertySymbols,ob=Object.prototype.hasOwnProperty,ib=Object.prototype.propertyIsEnumerable,sb=(t,e,r)=>e in t?ez(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ab=(t,e)=>{for(var r in e||(e={}))ob.call(e,r)&&sb(t,r,e[r]);if(od)for(var r of od(e))ib.call(e,r)&&sb(t,r,e[r]);return t},cb=(t,e)=>{var r={};for(var n in t)ob.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&od)for(var n of od(t))e.indexOf(n)<0&&ib.call(t,n)&&(r[n]=t[n]);return r};function id({derivedDrawInfo:t,participantId:e,drawId:r}){var n,o,i,s;const a=(o=(n=t[r])==null?void 0:n.mainSeedAssignments)==null?void 0:o.find(u=>u.participantId===e),c=(s=(i=t[r])==null?void 0:i.qualifyingSeedAssignments)==null?void 0:s.find(u=>u.participantId===e),l={};if(a){const u=a,{participantId:d}=u,p=cb(u,["participantId"]);d&&(l[de]=ab({},p))}if(c){const u=c,{participantId:d}=u,p=cb(u,["participantId"]);d&&(l[Ie]=ab({},p))}return Object.keys(l).length?l:void 0}function lb({matchUps:t=[],scheduleAttributes:e=["scheduledDate","scheduledTime"]}){if(!Array.isArray(t))return{error:Ao};if(!Array.isArray(e))return{error:Z};const r=t.filter(Boolean).filter(({schedule:o})=>Xc({schedule:o,scheduleAttributes:e})).reduce((o,i)=>{const{schedule:s}=i,a=Ce(s==null?void 0:s.scheduledDate),c=rt(s==null?void 0:s.scheduledTime);return a&&c&&(o[a]?o[a].push(i):o[a]=[i]),o},{});return Object.keys(r).forEach(o=>{r[o].sort((i,s)=>{var a,c;return o_(rt((a=i.schedule)==null?void 0:a.scheduledTime),rt((c=s.schedule)==null?void 0:c.scheduledTime))})}),{scheduledMatchUps:r}}var tz=Object.defineProperty,rz=Object.defineProperties,nz=Object.getOwnPropertyDescriptors,ub=Object.getOwnPropertySymbols,oz=Object.prototype.hasOwnProperty,iz=Object.prototype.propertyIsEnumerable,db=(t,e,r)=>e in t?tz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sz=(t,e)=>{for(var r in e||(e={}))oz.call(e,r)&&db(t,r,e[r]);if(ub)for(var r of ub(e))iz.call(e,r)&&db(t,r,e[r]);return t},az=(t,e)=>rz(t,nz(e));function cz({withScaleValues:t=!0,eventsPublishStatuses:e,withEvents:r=!0,withDraws:n=!0,participantIdMap:o,scheduleAnalysis:i,derivedDrawInfo:s,usePublishState:a,withStatistics:c,withOpponents:l,withMatchUps:u,withSeeding:d,participant:p,withISO2:v,withIOC:f}){var m,g,h,_,I,P,O,y,S,T;const E=[],b=[];if((f||v)&&Tu({participant:p,withIOC:f,withISO2:v}),t){const{ratings:K,rankings:Y}=Js({participant:p});p.rankings=Y,p.ratings=K}const N=p==null?void 0:p.participantId;if(!N||!o[N])return{};const{potentialMatchUps:w,opponents:$,matchUps:U,events:A,losses:M,draws:C,wins:D}=o[N],F=D+M,R=D,G=F&&R/F,x={statCode:ac,denominator:F,numerator:R,statValue:G},z=Object.values(C),j=Object.values(A);if(n&&z){p.draws=z;for(const K of z){const Y=(m=e[K.eventId])==null?void 0:m.publishedSeeding;if(!a||(Y==null?void 0:Y.published)&&(((g=Y==null?void 0:Y.drawIds)==null?void 0:g.length)===0||((h=Y==null?void 0:Y.drawIds)==null?void 0:h.includes(K.drawId)))){const te=id({drawId:K.drawId,derivedDrawInfo:s,participantId:N});te&&(K.seedAssignments=te)}}}if(r&&j&&(p.events=j,d)){const K=Object.assign({},...(p.timeItems||[]).filter(({itemType:Y})=>Y.split(".")[1]===rn).map(({itemType:Y,itemValue:J})=>({[Y]:J})));for(const Y of j){const J=ve=>[zi,rn,Y.eventType,ve].join("."),te=(_=e[Y.eventId])==null?void 0:_.publishedSeeding,ne=((te==null?void 0:te.stageSeedingScaleNames)&&Object.values(te==null?void 0:te.stageSeedingScaleNames)||Array.isArray(te==null?void 0:te.seedingScaleNames)&&te.seedingScaleNames||[]).map(J),oe=jt(Object.keys(K),ne),se=!!(!a||!Object.keys(K).length&&!((I=te==null?void 0:te.drawIds)!=null&&I.length)||oe.length);if(se&&oe.length){if(te!=null&&te.stageSeedingScaleNames){const ve=Object.keys(te.stageSeedingScaleNames).map(ie=>{const fe=J(te.stageSeedingScaleNames[ie]),$e=K[fe];return[ie,$e]}).filter(ie=>ie[1]).map(ie=>({[ie[0]]:{seedValue:ie[1]}})),X=Object.assign({},...ve);Y.seedAssignments=X}else if(oe){const ve=oe.map(X=>K[X]);Y.seedValue=ve.pop()}}else if(!a&&typeof d=="object"){const ve=Object.keys(d).map(ie=>{const fe=J(d[ie]),$e=K[fe];return[ie,$e]}).filter(ie=>ie[1]).map(ie=>({[ie[0]]:{seedValue:ie[1]}})),X=Object.assign({},...ve);Y.seedAssignments=X}else{const{categoryName:ve,ageCategoryCode:X}=Y.category||{};let ie;for(const fe of[Y.eventId,X,ve]){const $e={eventType:Y.eventType,scaleType:rn,scaleName:fe},re=ro({scaleAttributes:$e,participant:p});if(re.scaleItem){ie=re.scaleItem;break}}if(ie){const fe=ie.scaleValue;(!a||(te==null?void 0:te.published)&&(((P=te==null?void 0:te.drawIds)==null?void 0:P.length)===0||((O=te==null?void 0:te.drawIds)==null?void 0:O.includes(Y.drawId))))&&(Y.seedValue=fe)}}if((y=Y.drawIds)!=null&&y.length)for(const ve of Y.drawIds||[]){const X=((S=te==null?void 0:te.drawIds)==null?void 0:S.length)&&!((T=te==null?void 0:te.drawIds)!=null&&T.includes(ve));if(se&&!X){const ie=id({drawId:ve,derivedDrawInfo:s,participantId:N});if(ie&&Y.seedAssignments)for(const fe of Object.keys(Y.seedAssignments))Y.seedAssignments[fe]=ie[fe];else Y.seedAssignments=ie}}}}const V=Object.values($).flat();l&&(V!=null&&V.length)&&(p.opponents=V,z==null||z.forEach(K=>{K.opponents=V.filter(Y=>Y.drawId===K.drawId)}));const L=Object.values(w),q=Object.values(U);u&&(p.potentialMatchUps=L,p.matchUps=q);const k=q.concat(L),{scheduledMatchUps:H}=lb({matchUps:k}),{scheduledMinutesDifference:Q}=i||{};return Object.keys(H).forEach(K=>{H[K].filter(Boolean).forEach((Y,J)=>{var te,ne,oe,se;const{schedule:{scheduledTime:ve,timeAfterRecovery:X,typeChangeTimeAfterRecovery:ie},matchUpStatus:fe,roundPosition:$e,structureName:re,matchUpType:ae,roundNumber:me,matchUpId:Se,drawId:ce,score:Pe}=Y;b.push(az(sz({},Y.schedule),{scheduledTime:rt((te=Y.schedule)==null?void 0:te.scheduledTime),roundPosition:$e,structureName:re,matchUpType:ae,roundNumber:me,matchUpId:Se,drawId:ce}));const Ae=fe===qe||[Ge,Be].includes(fe)&&!Dt({score:Pe});if(ve&&!Ae){const ye=Re(ve),Ue=H[K].slice(J+1);for(const be of Ue)if(!(be.matchUpStatus===qe||[Ge,Be].includes(be.matchUpStatus)&&!Dt(be))&&((ne=be.schedule)!=null&&ne.scheduledTime)){const De=Y.matchUpType!==be.matchUpType&&ie||X,he=Y.drawId===be.drawId,ke=Y.potential&&be.potential,Ze=Re((oe=be.schedule)==null?void 0:oe.scheduledTime)-ye;(Q&&!isNaN(Q)?Ze<=Q:Re(De)>Re((se=be.schedule)==null?void 0:se.scheduledTime))&&!(ke&&he)&&E.push({priorScheduledMatchUpId:be.matchUpId,matchUpIdWithConflict:Se})}}})}),c&&(p.statistics=[x]),{scheduleConflicts:E,scheduleItems:b}}function lz({event:t,eventEntries:e,sortConfig:r}){const n={},o=Object.assign({},...(t.drawDefinitions||[]).map(i=>{var s,a,c,l,u,d,p,v,f;const m=Object.assign({},...(e||[]).filter(N=>N.participantId).map(N=>({[N.participantId]:N})),...i.entries.filter(N=>N.participantId).map(N=>({[N.participantId]:N}))),g=Object.values(m),h=(a=(s=Cr({stageSequence:1,drawDefinition:i,stage:de}))==null?void 0:s.structures)==null?void 0:a[0],_=h&&((c=et({structure:h}))==null?void 0:c.positionAssignments),I=_==null?void 0:_.length,P=(u=(l=Cr({stageSequence:1,stage:Ie,drawDefinition:i}))==null?void 0:l.structures)==null?void 0:u[0],O=h&&((d=et({structure:P}))==null?void 0:d.positionAssignments),y=O==null?void 0:O.length,S=h==null?void 0:h.seedAssignments,T=P==null?void 0:P.seedAssignments,E=(i.structures||[]).sort((N,w)=>Ii(N,w,r)).map(({structureId:N,structures:w})=>[N,...(w||[]).map(({structureId:$})=>$)]).flat(1/0),b=(f=(v=(p=t==null?void 0:t._flightProfile)==null?void 0:p.flights)==null?void 0:v.find(N=>N.drawId===i.drawId))==null?void 0:f.flightNumber;return n[i.drawId]={qualifyingPositionAssignments:O,qualifyingSeedAssignments:T,mainPositionAssignments:_,mainSeedAssignments:S,orderedStructureIds:E,qualifyingDrawSize:y,flightNumber:b,drawSize:I},{[i.drawId]:{drawType:i.drawType,drawEntries:g}}}));return{derivedInfo:n,drawDetails:o}}function uz({relevantParticipantIdsMap:t,participantFilters:e,participantIdMap:r,derivedDrawInfo:n,eventDrawsCount:o,drawDetails:i,eventType:s,matchUp:a}){var c;const{collectionId:l,collectionPosition:u,drawId:d,drawName:p,eventId:v,eventName:f,finishingRound:m,finishingPositionRange:g,processCodes:h,loserTo:_,matchUpId:I,matchUpType:P,matchUpFormat:O,matchUpStatus:y,matchUpStatusCodes:S,matchUpTieId:T,roundName:E,roundNumber:b,roundPosition:N,score:w,sides:$,stage:U,stageSequence:A,schedule:M,structureName:C,structureId:D,tieFormat:F,tieMatchUps:R,tournamentId:G,winnerTo:x,winningSide:z}=a,j=e==null?void 0:e.participantIds,V=H=>{const Q=H&&t[H]||[];return Q.push(H),Q.some(K=>!j||j.includes(K.relevantParticipantId))?Q:[]},{winner:L,loser:q}=g||{},k=(R==null?void 0:R.length)&&R.filter(({matchUpType:H})=>H===Jr).map(({sides:H})=>H.map(({sideNumber:Q,participantId:K,participant:Y})=>Q&&K&&{sideNumber:Q,participantId:K,participant:Y})).flat().filter(Boolean)||[];if(s===Nn&&P===Jr){const H=(((c=a.sides)==null?void 0:c.filter(Boolean))||[]).map(({sideNumber:Q,participantId:K,participant:Y})=>Q&&K&&{sideNumber:Q,participantId:K,participant:Y}).filter(Boolean);k.push(...H)}if($==null||$.forEach(({participantId:H,sideNumber:Q}={})=>{if(!H)return;const{drawType:K,drawEntries:Y}=i[d],J=Q===1?w==null?void 0:w.scoreStringSide1:w==null?void 0:w.scoreStringSide2,te=z&&Q===z,ne=a.sides.find(({sideNumber:re}={})=>re===3-Q),oe=ne==null?void 0:ne.participantId,se=oe&&t[oe]||[],ve=te?L:q,X=Y.find(re=>re.participantId===H),ie=V(H),fe=[];k==null||k.filter(re=>re.sideNumber===Q).forEach(({participantId:re})=>{re&&!fe.includes(re)&&(ie.push({relevantParticipantId:re,participantType:we}),fe.push(re))});const $e=ie.filter(re=>s!==Nn||s===Nn&&[Jr,Zr].includes(P)&&[we,An].includes(re.participantType)||s===Nn&&[ci,Jr].includes(P)&&[Me].includes(re.participantType));$e==null||$e.forEach(({relevantParticipantId:re,participantType:ae})=>{var me,Se;const{entryStage:ce,entryStatus:Pe,entryPosition:Ae}=X||{};if(!r[re])return;if(!r[re].draws[d]){const De=nb({participantId:re,derivedDrawInfo:n,drawId:d}),he=id({participantId:re,derivedDrawInfo:n,drawId:d});r[re].draws[d]=_e({qualifyingDrawSize:(me=n[d])==null?void 0:me.qualifyingDrawSize,drawSize:(Se=n[d])==null?void 0:Se.drawSize,partnerParticipantIds:[],positionAssignments:De,seedAssignments:he,entryPosition:Ae,entryStatus:Pe,entryStage:ce,drawName:p,drawType:K,eventId:v,drawId:d})}r[re].events[v]||(r[re].events[v]={partnerParticipantIds:[],drawIds:[],eventName:f,eventId:v});const ye=r[re].events[v].drawIds;ye&&!(ye!=null&&ye.includes(d))&&r[re].events[v].drawIds.push(d);let Ue;if(ae===Me&&P===Jr){const De=$e.find(he=>he.relevantParticipantId!==re&&he.participantType===Me);Ue=De==null?void 0:De.relevantParticipantId}const be=(se==null?void 0:se.filter(De=>P===Zr&&ae===An&&De.participantType===An||P===ci&&De.participantType===Me||P===Jr&&(ae===Me?[Me,we].includes(De.participantType):De.participantType===we)))||[];be.forEach(({relevantParticipantId:De,participantType:he})=>{r[re].opponents||(r[re].opponents={}),r[re].opponents[De]={eventId:v,drawId:d,matchUpId:I,participantType:he,participantId:De}});const ge=be.map(({relevantParticipantId:De,participantType:he})=>({participantId:De,participantType:he}));(P!==Zr&&[Me,we].includes(ae)||P===Zr&&ae===An)&&(r[re].matchUps[I]=_e({collectionId:l,collectionPosition:u,drawId:d,eventId:v,eventType:s,eventDrawsCount:o,finishingRound:m,finishingPositionRange:ve,loserTo:_,matchUpId:I,matchUpType:P,matchUpFormat:O,matchUpStatus:y,matchUpStatusCodes:S,matchUpTieId:T,opponentParticipantInfo:ge,participantWon:te,partnerParticipantId:Ue,perspectiveScoreString:J,processCodes:h,roundName:E,roundNumber:b,roundPosition:N,schedule:M,score:w,sides:$,stage:U,stageSequence:A,structureName:C,structureId:D,tieFormat:F,tournamentId:G,winnerTo:x,winningSide:z})),Ue&&(r[re].events[v].partnerParticipantIds.push(Ue),r[re].draws[d].partnerParticipantIds.push(Ue),r[re].events[v].partnerParticipantId=Ue,r[re].draws[d].partnerParticipantId=Ue),z&&(te?r[re].wins++:r[re].losses++)})}),Array.isArray(a.potentialParticipants)){const H=Kn(a.potentialParticipants.flat());H==null||H.forEach(Q=>{const K=V(Q);K==null||K.forEach(({relevantParticipantId:Y})=>{r[Y].potentialMatchUps[I]=_e({drawId:d,eventId:v,eventType:s,matchUpId:I,matchUpType:P,matchUpFormat:O,roundName:E,roundNumber:b,roundPosition:N,schedule:M,tieFormat:F,structureName:C,tournamentId:G,potential:!0})})})}}var dz=Object.defineProperty,pz=Object.defineProperties,fz=Object.getOwnPropertyDescriptors,pb=Object.getOwnPropertySymbols,vz=Object.prototype.hasOwnProperty,mz=Object.prototype.propertyIsEnumerable,fb=(t,e,r)=>e in t?dz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Bv=(t,e)=>{for(var r in e||(e={}))vz.call(e,r)&&fb(t,r,e[r]);if(pb)for(var r of pb(e))mz.call(e,r)&&fb(t,r,e[r]);return t},kv=(t,e)=>pz(t,fz(e));function gz(t){var e,r;const n=[],o={},i={},s={},a=f=>{s[f]||(s[f]={groupParticipantIds:[],teamParticipantIds:[],pairParticipantIds:[],potentialMatchUps:{},scheduleItems:[],opponents:{},matchUps:{},events:{},groups:[],teams:[],draws:{},losses:0,wins:0})},{tournamentRecord:c,participantFilters:l,allTournamentParticipants:u}=t,{relevantParticipantIdsMap:d}=XY({processParticipantId:a,tournamentRecord:c}),p=l==null?void 0:l.participantIds,v=f=>{const m=f&&d[f]||[];return m.push(f),m.some(g=>!p||p.includes(g.relevantParticipantId))?m:[]};return t.withGroupings&&u.forEach(f=>{var m,g,h;if(f.participantType===dr){const _=f.participantId;(m=f==null?void 0:f.individualParticipantIds)==null||m.forEach(I=>{s[I].groupParticipantIds.includes(_)||(s[I].groupParticipantIds.push(_),s[I].groups.push({participantRoleResponsibilities:f.participantRoleResponsibilities,participantOtherName:f.participantOtherName,participantName:f.participantName,participantId:f.participantId}))})}if(f.participantType===He){const _=f.participantId;(g=f==null?void 0:f.individualParticipantIds)==null||g.forEach(I=>{var P,O,y,S;(O=(P=s[I])==null?void 0:P.teamParticipantIds)!=null&&O.includes(_)||((y=s[I])==null||y.teamParticipantIds.push(_),(S=s[I])==null||S.teams.push({participantRoleResponsibilities:f.participantRoleResponsibilities,participantOtherName:f.participantOtherName,participantName:f.participantName,participantId:f.participantId,teamId:f.teamId}))})}if(f.participantType===we){const _=f.participantId;(h=f==null?void 0:f.individualParticipantIds)==null||h.forEach(I=>{s[I]&&!s[I].pairParticipantIds.includes(_)&&s[I].pairParticipantIds.push(_)})}}),t.withMatchUps&&Yr({tournamentRecord:c}),(t.withScheduleItems||t.scheduleAnalysis||t.withStatistics||t.withOpponents||t.withMatchUps||t.withSeeding||t.withEvents||t.withDraws)&&((e=t.tournamentEvents)==null||e.forEach(f=>{var m,g,h,_,I,P,O;const y=ue(f,!0,!0),S=It({event:y}).flightProfile,T=((m=S==null?void 0:S.flights)==null?void 0:m.length)||((g=y.drawDefinitions)==null?void 0:g.length)||0;(y.drawDefinitions||[]).forEach((V,L)=>{if((y==null?void 0:y.eventType)===He){const{extension:q}=Vt({element:f.drawDefinitions[L],name:bn});q&&(V.extensions=[q])}});const{eventId:E,eventName:b,eventType:N,category:w}=y,$={eventId:E,eventName:b,eventType:N,category:w},U=y&&Object.keys(y).filter(V=>V.startsWith("_"));U==null||U.forEach(V=>$[V]=y[V]);const A=y.entries||[],M=`${Ar}.${Ur}`,{timeItem:C}=So({itemType:M,event:y});if((h=C==null?void 0:C.itemValue)!=null&&h.PUBLIC){const{drawIds:V=[],seeding:L}=C.itemValue.PUBLIC||{},q={published:void 0,seedingScaleNames:[],drawIds:[]};L&&Object.assign(q,C.itemValue.PUBLIC.seeding),o[E]={publishedDrawIds:V,publishedSeeding:q}}const F=[].concat(...Object.values(A_)).map(V=>`_${V}`),R=$&&Object.keys($).filter(V=>!F.includes(V)).reduce((V,L)=>(V[L]=$[L],V),{});A==null||A.filter(V=>V==null?void 0:V.participantId).forEach(V=>{const{participantId:L,entryStage:q,entryStatus:k,entryPosition:H}=V,Q=v(L);Q==null||Q.forEach(({relevantParticipantId:K})=>{s[K]||a(K),s[K].events[E]=kv(Bv({},R),{partnerParticipantIds:[],entryPosition:H,entryStatus:k,entryStage:q,drawIds:[],eventId:E})})});const G=({drawEntry:V,drawId:L})=>{const{participantId:q,entryStage:k,entryStatus:H,entryPosition:Q}=V,K=v(q);K==null||K.forEach(({relevantParticipantId:Y})=>{var J,te;if(s[Y].events[E]||(s[Y].events[E]=kv(Bv({},R),{partnerParticipantIds:[],entryPosition:Q,entryStatus:H,entryStage:k,drawIds:[],eventId:E})),!s[Y].draws[L]){const oe=nb({participantId:Y,derivedDrawInfo:i,drawId:L}),se=id({participantId:Y,derivedDrawInfo:i,drawId:L});s[Y].draws[L]=_e({qualifyingDrawSize:(J=i[L])==null?void 0:J.qualifyingDrawSize,drawSize:(te=i[L])==null?void 0:te.drawSize,partnerParticipantIds:[],positionAssignments:oe,eventDrawsCount:T,seedAssignments:se,entryPosition:Q,entryStatus:H,entryStage:k,eventId:E,drawId:L})}const ne=s[Y].events[E].drawIds;ne&&!(ne!=null&&ne.includes(L))&&s[Y].events[E].drawIds.push(L)})},x=((_=y.drawDefinitions)==null?void 0:_.map(({drawId:V})=>V))||[];(P=(I=$._flightProfile)==null?void 0:I.flights)==null||P.forEach(V=>{const{drawId:L,drawEntries:q}=V;x.includes(L)||q==null||q.forEach(k=>G({drawEntry:k,drawId:L}))});const{drawDetails:z,derivedInfo:j}=lz({eventEntries:A,event:y});if(Object.assign(i,j),y.eventType===He||t.withScheduleItems||t.scheduleAnalysis||t.withStatistics||t.withOpponents||t.withMatchUps||t.withDraws){const V=(O=Oi({afterRecoveryTimes:t.scheduleAnalysis,participants:u,nextMatchUps:!0,tournamentRecord:c,inContext:!0,event:y}))==null?void 0:O.matchUps;V==null||V.forEach(L=>uz({relevantParticipantIdsMap:d,participantFilters:l,participantIdMap:s,derivedDrawInfo:i,eventDrawsCount:T,drawDetails:z,eventType:N,matchUp:L}))}})),(r=t.tournamentParticipants)==null||r.forEach(f=>{const{scheduleConflicts:m,scheduleItems:g}=cz(kv(Bv({},t),{eventsPublishStatuses:o,participantIdMap:s,derivedDrawInfo:i,participant:f}));if(t.withSignInStatus){const{timeItem:h}=fn({itemType:_c,element:f});f.signedIn=(h==null?void 0:h.itemValue)===Ic}if(t.withScheduleItems&&(f.scheduleItems=g),t.scheduleAnalysis&&(f.scheduleConflicts=m,m!=null&&m.length&&!n.includes(f.participantId)&&n.push(f.participantId)),t.withGroupings!==!1){const h=s[f.participantId];f.groupParticipantIds=h==null?void 0:h.groupParticipantIds,f.pairParticipantIds=h==null?void 0:h.pairParticipantIds,f.teamParticipantIds=h==null?void 0:h.teamParticipantIds,f.groups=h==null?void 0:h.groups,f.teams=h==null?void 0:h.teams}t.withTeamMatchUps}),{participantIdsWithConflicts:n,eventsPublishStatuses:o}}function sd({participantFilters:t={},tournamentRecord:e,participants:r=[]}){var n;if(!Object.keys(t).length)return r;const{accessorValues:o,drawEntryStatuses:i,positionedParticipants:s,eventEntryStatuses:a,participantRoles:c,participantRoleResponsibilities:l,participantTypes:u,participantIds:d,signInStatus:p,enableOrFiltering:v,eventIds:f,genders:m}=t,g=no(f)&&((n=e==null?void 0:e.events)==null?void 0:n.filter(O=>f.includes(O.eventId)))||(e==null?void 0:e.events)||[],h=i&&hz({drawEntryStatuses:i,tournamentEvents:g}),_=a&&_z({eventEntryStatuses:a,tournamentEvents:g}),I=[!0,!1].includes(s)&&g.reduce((O,y)=>O.concat(...(y.drawDefinitions||[]).map(S=>$P({drawDefinition:S}).allPositionedParticipantIds).filter(Boolean)),[]),P=O=>o.reduce((y,S)=>{const{accessor:T,value:E}=S,{values:b}=Xu({element:O,accessor:T});return y&&(b==null?void 0:b.includes(E))},!0);if(r=r==null?void 0:r.filter(O=>{const y=fn({element:O,itemType:_c}),{participantRoleResponsibilities:S,participantType:T,participantRole:E,participantId:b,person:N}=O,w=Array.isArray(m)&&(m==null?void 0:m.length)&&(N==null?void 0:N.sex)&&m.includes(N.sex);return v?m&&w||s&&I.includes(b)||s===!1&&!I.includes(b)||(h==null?void 0:h.includes(b))||(_==null?void 0:_.includes(b))||(d==null?void 0:d.includes(b))||p&&y===p||u&&no(u)&&u.includes(T)||c&&no(c)&&c.includes(E)||l&&no(S)&&no(l)&&l.find($=>S==null?void 0:S.includes($))||(o==null?void 0:o.length)&&no(o)&&P(O):(!m||w)&&(s===void 0||s&&I.includes(b)||s===!1&&!I.includes(b))&&(!h||h.includes(b))&&(!_||_.includes(b))&&(!d||d.includes(b))&&(!p||y===p)&&(!u||no(u)&&u.includes(T))&&(!c||no(c)&&c.includes(E))&&(!l||no(S)&&no(l)&&l.find($=>S==null?void 0:S.includes($)))&&(!(o!=null&&o.length)||no(o)&&P(O))}),g.length&&f){const O=g.filter(y=>f.includes(y.eventId)).map(y=>{const S=(y.entries||[]).map(E=>E.participantId);if(y.eventType===Hn)return S;const T=((e==null?void 0:e.participants)||[]).filter(E=>S.includes(E.participantId)).map(E=>E.individualParticipantIds).flat(1);return S.concat(...T)}).flat(1);r=r==null?void 0:r.filter(y=>O.includes(y.participantId))}return r}function no(t){return t&&Array.isArray(t)&&t.length}function hz({drawEntryStatuses:t,tournamentEvents:e}){const r=({entryStatus:n})=>Array.isArray(t)?t.includes(n):!0;return Ve(e.reduce((n,o)=>{var i,s;const{flightProfile:a}=It({event:o}),c=((i=a==null?void 0:a.flights)==null?void 0:i.map(({drawEntries:u})=>Array.isArray(u)?u.filter(r).map(Xe):[]).flat())||[],l=((s=o.drawDefinitions)==null?void 0:s.map(({entries:u})=>u?u.filter(r).map(Xe):[]))||[];return n.concat(...c,...l)},[]))}function _z({eventEntryStatuses:t,tournamentEvents:e}){return Ve(e.reduce((r,n)=>{const o=(n.entries||[]).filter(({entryStatus:i})=>Array.isArray(t)?t.includes(i):!0).map(Xe);return r.concat(...o)},[]))}function Qt({participantFilters:t={},convertExtensions:e,policyDefinitions:r,withScheduleItems:n,scheduleAnalysis:o,withSignInStatus:i,withTeamMatchUps:s,tournamentRecord:a,usePublishState:c,withScaleValues:l,withStatistics:u,withGroupings:d,withOpponents:p,withMatchUps:v,withSeeding:f,withEvents:m,withDraws:g,inContext:h,withISO2:_,withIOC:I}){if(!a)return{error:ee};if(!a.participants)return{error:Qa};const P=a.participants.map(b=>ue(b,e));if(typeof t!="object")return{error:xn,participantFilters:t};h&&(P==null||P.forEach(b=>{var N;[we,Ye,dr].includes(b.participantType)&&(b.individualParticipants=(N=b.individualParticipantIds)==null?void 0:N.map(w=>{const $=a.participants.find(A=>A.participantId===w),U=ue($,e,!0);if(l){const{ratings:A,rankings:M}=Js({participant:U});U.ratings=A,U.rankings=M}return(I||_)&&Tu({participant:U,withISO2:_,withIOC:I}),U}))}));let O=t?sd({participants:P,participantFilters:t,tournamentRecord:a}):P,y,S;if(n||i||o||l||u||d||p||v||f||m||g||_||I){const b=gz({tournamentEvents:a.events,allTournamentParticipants:P,tournamentParticipants:O,participantFilters:t,withScheduleItems:n,withSignInStatus:i,tournamentRecord:a,scheduleAnalysis:o,withTeamMatchUps:s,usePublishState:c,withScaleValues:l,withStatistics:u,withGroupings:d,withOpponents:p,withMatchUps:v,withSeeding:f,withEvents:m,withDraws:g,withISO2:_,withIOC:I});y=b==null?void 0:b.participantIdsWithConflicts,S=b==null?void 0:b.eventsPublishStatuses}const E=r==null?void 0:r[oc];return E!=null&&E.participant&&(O=O.map(b=>Dl({template:E.participant,source:b}))),{participantIdsWithConflicts:y,tournamentParticipants:O,eventsPublishStatuses:S}}const Iz="ADMINISTRATION",Pz="CAPTAIN",yz="COACH",qt="COMPETITOR",Sz="MEDIA",Oz="MEDICAL",vb="OFFICIAL",mb="OTHER",gb={ADMINISTRATION:Iz,CAPTAIN:Pz,COACH:yz,COMPETITOR:qt,MEDIA:Sz,MEDICAL:Oz,OFFICIAL:vb,OTHER:mb,SECURITY:"SECURITY"};function hb(t){return Vu(t)}function Gv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,scheduledDate:o,matchUpId:i}){return gv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,disableNotice:n,scheduledDate:o,matchUpId:i})}function Wv({removePriorValues:t,tournamentRecord:e,drawDefinition:r,scheduledTime:n,disableNotice:o,matchUpId:i}){return Ti({removePriorValues:t,tournamentRecord:e,drawDefinition:r,scheduledTime:n,disableNotice:o,matchUpId:i})}function _b({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,startTime:o}){return _v({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,startTime:o})}function Ib({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,endTime:o}){return Iv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,endTime:o})}function Pb({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,stopTime:o}){return Pv({tournamentRecord:t,drawDefinition:e,disableNotice:r,matchUpId:n,stopTime:o})}function yb({tournamentRecord:t,drawDefinition:e,disableNotice:r,resumeTime:n,matchUpId:o}){return yv({tournamentRecord:t,drawDefinition:e,disableNotice:r,resumeTime:n,matchUpId:o})}function bz({tournamentRecord:t,drawDefinition:e,disableNotice:r,courtOrder:n,matchUpId:o}){return hv({tournamentRecord:t,drawDefinition:e,disableNotice:r,courtOrder:n,matchUpId:o})}function Sb({tournamentRecord:t,drawDefinition:e,disableNotice:r,participantId:n,officialType:o,matchUpId:i}){if(!n)return{error:yt};const{tournamentParticipants:s}=Qt({tournamentRecord:t,participantFilters:{participantTypes:[Me],participantRoles:[vb]}});return vo({tournamentParticipants:s,participantId:n})?qS({drawDefinition:e,disableNotice:r,participantId:n,officialType:o,matchUpId:i}):{error:wt}}var Tz=Object.defineProperty,Ez=Object.defineProperties,wz=Object.getOwnPropertyDescriptors,Ob=Object.getOwnPropertySymbols,$z=Object.prototype.hasOwnProperty,Nz=Object.prototype.propertyIsEnumerable,bb=(t,e,r)=>e in t?Tz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Hv=(t,e)=>{for(var r in e||(e={}))$z.call(e,r)&&bb(t,r,e[r]);if(Ob)for(var r of Ob(e))Nz.call(e,r)&&bb(t,r,e[r]);return t},Az=(t,e)=>Ez(t,wz(e));function Tb({tournamentRecord:t,scheduleChange:e,matchUpIds:r,dryRun:n}){if(!t)return{error:ee};if(!r||!Array.isArray(r))return{error:Ka};if(typeof e!="object")return{error:Z};const o=[],i=[],{minutesChange:s,daysChange:a}=e;if(!s&&!a)return Hv({},B);if(s&&isNaN(s))return{error:Z};if(a&&isNaN(a))return{error:Z};const{matchUps:c}=Bt({matchUpFilters:{matchUpIds:r},tournamentRecord:t}),l=({matchUpStatus:P})=>!Lt.includes(P),u=c==null?void 0:c.filter(Xc).filter(l);if(!u.length)return Hv({},B);const{tournamentInfo:d}=el({tournamentRecord:t}),{startDate:p,endDate:v}=d,f=u.reduce((P,O)=>{const{matchUpId:y,drawId:S}=O;return P[S]?P[S].push(y):P[S]=[y],P},{}),m=1440;for(const P of Object.keys(f)){const O=Fo({tournamentRecord:t,drawId:P});if(O.error)return O;const y=O.drawDefinition,S=f[P].filter(T=>r.includes(T));for(const T of S)if(T&&y){const b=u.find(M=>M.matchUpId===T).schedule,{scheduledTime:N,scheduledDate:w}=b;let $,U,A;if(!$&&a&&w){const M=Ce(w);A=ZL(M,a),$=new Date(A)<new Date(p)||new Date(A)>new Date(v)}if(s&&N){const M=Ce(N),D=Re(rt(N))+s;if($=D<0||D>m,!$){let F=lr(N,s);U=M&&A?`${A}T${F}`:F}}if($)i.push(T);else{if(!n){if(U){const M=Wv({scheduledTime:U,drawDefinition:y,matchUpId:T});if(M.error)return M}if(A){const M=Gv({scheduledDate:A,drawDefinition:y,matchUpId:T});if(M.error)return M}}(U||A)&&o.push(T)}}}const{matchUps:g}=Bt({matchUpFilters:{matchUpIds:r},tournamentRecord:t}),h=g.filter(({matchUpId:P})=>o.includes(P)),_=g.filter(({matchUpId:P})=>i.includes(P)),I=h.length&&!_.length;return Az(Hv({},B),{rescheduled:h,notRescheduled:_,allRescheduled:I})}var Uz=Object.defineProperty,Cz=Object.defineProperties,Mz=Object.getOwnPropertyDescriptors,Eb=Object.getOwnPropertySymbols,Dz=Object.prototype.hasOwnProperty,jz=Object.prototype.propertyIsEnumerable,wb=(t,e,r)=>e in t?Uz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rz=(t,e)=>{for(var r in e||(e={}))Dz.call(e,r)&&wb(t,r,e[r]);if(Eb)for(var r of Eb(e))jz.call(e,r)&&wb(t,r,e[r]);return t},Fz=(t,e)=>Cz(t,Mz(e));function Lz({tournamentRecords:t,scheduleChange:e,matchUpIds:r,dryRun:n}){var o,i;if(!r||!Array.isArray(r))return{error:Ka};if(typeof e!="object")return{error:Z};const s=[];let a=[];for(const l of Object.values(t)){const u=Tb({tournamentRecord:l,scheduleChange:e,matchUpIds:r,dryRun:n});if(u.error)return u;Array.isArray(u.notRescheduled)&&a.push(...u.notRescheduled);const d=fu(u.notRescheduled),p=[];(o=u.rescheduled)==null||o.forEach(v=>{const{matchUpId:f}=v;d.includes(f)&&p.push(f),s.push(v)}),p.length&&(a=((i=u==null?void 0:u.notRescheduled)==null?void 0:i.filter(({matchUpId:v})=>!p.includes(v)))||[])}const c=s.length&&!a.length;return Fz(Rz({},B),{rescheduled:s,notRescheduled:a,allRescheduled:c})}function $b({tournamentRecord:t,dailyLimits:e}){return t?typeof e!="object"?{error:xn}:pi({extension:{name:Gi,value:{dailyLimits:e}},tournamentRecord:t}):{error:ee}}var Vz=Object.defineProperty,Nb=Object.getOwnPropertySymbols,xz=Object.prototype.hasOwnProperty,Bz=Object.prototype.propertyIsEnumerable,Ab=(t,e,r)=>e in t?Vz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,kz=(t,e)=>{for(var r in e||(e={}))xz.call(e,r)&&Ab(t,r,e[r]);if(Nb)for(var r of Nb(e))Bz.call(e,r)&&Ab(t,r,e[r]);return t};function Gz({tournamentRecords:t,tournamentId:e,dailyLimits:r}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const n=Object.keys(t).filter(o=>!e||e===o);if(e&&!n.includes(e))return{error:Z};for(const o of n){const i=t[o],s=$b({tournamentRecord:i,dailyLimits:r});if(s.error)return s}return kz({},B)}var Wz=Object.defineProperty,Hz=Object.defineProperties,qz=Object.getOwnPropertyDescriptors,Ub=Object.getOwnPropertySymbols,Yz=Object.prototype.hasOwnProperty,zz=Object.prototype.propertyIsEnumerable,Cb=(t,e,r)=>e in t?Wz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kz=(t,e)=>{for(var r in e||(e={}))Yz.call(e,r)&&Cb(t,r,e[r]);if(Ub)for(var r of Ub(e))zz.call(e,r)&&Cb(t,r,e[r]);return t},Qz=(t,e)=>Hz(t,qz(e));function Jz({extensionConversions:t,seedAssignments:e,participant:r,withSeeding:n,seedValue:o,eventId:i,ranking:s,entry:a}){const{entryStatus:c,entryStage:l,entryPosition:u}=a;r.events[i]=_e(Qz(Kz({},t),{entryPosition:u,entryStatus:c,entryStage:l,ranking:s,eventId:i}),!1,!1,!0),n&&(e&&(r.events[i].seedAssignments=e),o&&(r.events[i].seedValue=o))}var Zz=Object.defineProperty,Xz=Object.defineProperties,e7=Object.getOwnPropertyDescriptors,Mb=Object.getOwnPropertySymbols,t7=Object.prototype.hasOwnProperty,r7=Object.prototype.propertyIsEnumerable,Db=(t,e,r)=>e in t?Zz(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,n7=(t,e)=>{for(var r in e||(e={}))t7.call(e,r)&&Db(t,r,e[r]);if(Mb)for(var r of Mb(e))r7.call(e,r)&&Db(t,r,e[r]);return t},o7=(t,e)=>Xz(t,e7(e));function jb({participantMap:t,participantId:e,matchUpStatus:r,roundPosition:n,structureId:o,matchUpType:i,roundNumber:s,matchUpId:a,potential:c,schedule:l,drawId:u,score:d}){if(!l||!Object.keys(l).length)return;r===qe||t[e].scheduleItems.push(o7(n7({},l),{scheduledDate:Ce(l==null?void 0:l.scheduledDate),scheduledTime:rt(l==null?void 0:l.scheduledTime),scoreHasValue:Dt({score:d}),matchUpStatus:r,roundPosition:n,structureId:o,matchUpType:i,roundNumber:s,matchUpId:a,potential:c,drawId:u}))}function i7({finishingPositionRange:t={},participantMap:e,finishingRound:r,participantWon:n,matchUpStatus:o,participantId:i,stageSequence:s,roundNumber:a,structureId:c,matchUpId:l,drawId:u,stage:d}){const p=e[i],v=_=>Math.abs(_[0]-_[1]);p.structureParticipation[c]||(p.structureParticipation[c]={structureId:c,rankingStage:d,walkoverWinCount:0,defaultWinCount:0,stageSequence:s,winCount:0,drawId:u});const f=p.structureParticipation[c],{winner:m,loser:g}=t,h=n?m:g;n&&(f.winCount+=1,o===Ge&&(f.walkoverWinCount+=1),o===Be&&(f.defaultWinCount+=1)),h&&(!f.finishingPositionRange||v(h)<v(f.finishingPositionRange))&&(f.finishingPositionRange=h),r&&((!f.finishingRound||r<f.finishingRound)&&(f.finishingMatchUpId=l,f.finishingRound=r,f.roundNumber=a),r===1&&(f.participantWon=n))}function Rb({withScheduleTimes:t,scheduleAnalysis:e,withTeamMatchUps:r,participantMap:n,withOpponents:o,withMatchUps:i,withEvents:s,withDraws:a,finishingPositionRange:c,finishingRound:l,matchUpStatus:u,stageSequence:d,roundNumber:p,structureId:v,score:f,stage:m,withRankingProfile:g,tieWinningSide:h,roundPosition:_,matchUpTieId:I,matchUpSides:P,collectionId:O,matchUpType:y,winningSide:S,matchUpId:T,schedule:E,eventId:b,drawId:N,sides:w}){var $,U,A,M,C,D,F,R,G,x;const z=o&&(w==null?void 0:w.length)===2&&Object.assign({},...w.map(({sideNumber:j},V)=>{const L=w[1-V].participantId;return j&&{[j]:L}}).filter(Boolean));for(const j of w){const{participantId:V,sideNumber:L,bye:q}=j;if(q)continue;const k=S===L,H=J=>{var te,ne;const oe=(te=n[J])==null?void 0:te.participant,se=oe==null?void 0:oe.participantType,ve=[{participantId:J,participantType:se}];if(se!==An)for(const X of(oe==null?void 0:oe.individualParticipantIds)||[]){const ie=(ne=n[X])==null?void 0:ne.participant;ve.push({participantType:ie==null?void 0:ie.participantType,participantId:X})}return ve},Q=(J,te)=>{if(i){if(n[J].matchUps[T]={participantWon:k,matchUpType:y,structureId:v,sideNumber:L,matchUpId:T,eventId:b,drawId:N},o){const ne=H(te);n[J].matchUps[T].opponentParticipantInfo=ne}O&&(n[J].matchUps[T].collectionId=O)}g&&i7({finishingPositionRange:c,participantMap:n,participantWon:k,finishingRound:l,matchUpStatus:u,participantId:J,stageSequence:d,roundNumber:p,structureId:v,matchUpId:T,drawId:N,stage:m}),(e||t)&&jb({participantMap:n,participantId:J,matchUpStatus:u,roundPosition:_,matchUpType:y,roundNumber:p,structureId:v,matchUpId:T,schedule:E,drawId:N,score:f})},K=(J,te)=>{J&&(J.partnerParticipantIds||(J.partnerParticipantIds=[]),J.partnerParticipantIds.includes(te)||J.partnerParticipantIds.push(te))},Y=({participantId:J,partnerParticipantId:te})=>{var ne,oe,se,ve,X,ie;a&&K((oe=(ne=n[J])==null?void 0:ne.draws)==null?void 0:oe[N],te),s&&K((ve=(se=n[J])==null?void 0:se.events)==null?void 0:ve[b],te),i&&K((ie=(X=n[J])==null?void 0:X.matchUps)==null?void 0:ie[T],te)};if(V&&n[V]){const J=z==null?void 0:z[L];Q(V,J),o&&J&&(n[V].opponents[J]={participantId:J,matchUpId:T,eventId:b,drawId:N});const te=(($=n[V])==null?void 0:$.participant.participantType)===we,ne=((U=n[V])==null?void 0:U.participant.individualParticipantIds)||[];if(I){if(r){const oe=se=>n[se].matchUps[I]={participantWon:h===L,matchUpType:Zr,matchUpId:I,sideNumber:L};oe(V),ne.forEach(oe)}if(a&&!n[V].draws[N]){const oe=(M=(A=P.find(X=>X.sideNumber===L))==null?void 0:A.participant)==null?void 0:M.participantId,se=(F=(D=(C=n[oe])==null?void 0:C.draws)==null?void 0:D[N])==null?void 0:F.entryStatus,ve=X=>n[X].draws[N]={entryStatus:se,eventId:b,drawId:N};ve(V),ne.forEach(ve)}}if(te&&(ne.forEach(oe=>n[oe]&&Q(oe,J)),ne.forEach((oe,se)=>{const ve=ne[1-se];Y({participantId:oe,partnerParticipantId:ve})}),s&&P)){const oe=(G=(R=P.find(se=>se.sideNumber===L))==null?void 0:R.participant)==null?void 0:G.participantId;if(oe){const se=(x=n[oe])==null?void 0:x.events[b];se?(n[V].events[b]=se,ne.forEach(ve=>n[ve].events[b]=se)):console.log("Missing teamEntry",{eventId:b,teamParticipantId:oe})}}if(S){const oe=se=>{k?(n[se].counters[y].wins+=1,n[se].counters.wins+=1,u===Ge&&(n[se].counters[y].walkoverWins+=1,n[se].counters.walkoverWins+=1),u===Be&&(n[se].counters[y].defaultWins+=1,n[se].counters.defaultWins+=1)):(n[se].counters[y].losses+=1,n[se].counters.losses+=1,u===Ge&&(n[se].counters[y].walkovers+=1,n[se].counters.walkovers+=1),u===Be&&(n[se].counters[y].defaults+=1,n[se].counters.defaults+=1))};oe(V),ne.forEach(oe)}}}}var s7=Object.defineProperty,a7=Object.defineProperties,c7=Object.getOwnPropertyDescriptors,Fb=Object.getOwnPropertySymbols,l7=Object.prototype.hasOwnProperty,u7=Object.prototype.propertyIsEnumerable,Lb=(t,e,r)=>e in t?s7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ea=(t,e)=>{for(var r in e||(e={}))l7.call(e,r)&&Lb(t,r,e[r]);if(Fb)for(var r of Fb(e))u7.call(e,r)&&Lb(t,r,e[r]);return t},ad=(t,e)=>a7(t,c7(e));function d7({participantFilters:t,convertExtensions:e,policyDefinitions:r,tournamentRecord:n,usePublishState:o,contextProfile:i,participantMap:s,withPotentialMatchUps:a,withRankingProfile:c,withScheduleTimes:l,scheduleAnalysis:u,withTeamMatchUps:d,withStatistics:p,withOpponents:v,withMatchUps:f,withSeeding:m,withEvents:g,withDraws:h}){var _,I,P,O,y;const S=t==null?void 0:t.participantIds,T=C=>{var D;const F=[C];return F.push(C),(D=s[C].participant.individualParticipantIds)==null||D.forEach(R=>F.push(R)),F.some(R=>!(S!=null&&S.length)||S.includes(R.relevantParticipantId))?F:[]},E={withMatchUps:f||c,withEvents:g||c,withDraws:h||c,withPotentialMatchUps:a,withRankingProfile:c,withScheduleTimes:l,scheduleAnalysis:u,withTeamMatchUps:d,withStatistics:p,participantMap:s,withOpponents:v,withSeeding:m},b=[],N={},w={},$={},U={};let A=[];const M=({eventType:C,scaleNames:D,participantId:F})=>{var R,G,x,z;return(z=(x=(G=(R=s[F].participant)==null?void 0:R.rankings)==null?void 0:G[C])==null?void 0:x.find(j=>D.includes(j.scaleName)))==null?void 0:z.scaleValue};for(const C of(n==null?void 0:n.events)||[]){if(t!=null&&t.eventIds&&!t.eventIds.includes(C.eventId))continue;const{drawDefinitions:D=[],extensions:F,eventType:R,eventName:G,category:x,entries:z,eventId:j,gender:V}=C,{flightProfile:L}=It({event:C}),q=L==null?void 0:L.flights,k=CY({event:C}),H=k==null?void 0:k.publishedSeeding;if(k&&(N[j]=k),g||m||c){const Q=e?Object.assign({},...i_(F)):{};w[j]=ad(Ea({},Q),{eventName:G,eventType:R,category:x,eventId:j,gender:V});const K=[x==null?void 0:x.categoryName,x==null?void 0:x.ageCategoryCode].filter(Boolean);for(const Y of z){const{participantId:J}=Y;if(!J||!s[J])continue;const te=M({eventType:R,scaleNames:K,participantId:J});let ne,oe;if(m){const X=s[J].participant;({seedAssignments:ne,seedValue:oe}=MY({publishedSeeding:H,usePublishState:o,withSeeding:m,participant:X,event:C}))}const se=X=>{var ie;if((ie=s[X])!=null&&ie.events[j])return;const fe=s[X];Jz({extensionConversions:Q,seedAssignments:ne,participant:fe,withSeeding:m,seedValue:oe,eventId:j,ranking:te,entry:Y})};se(J),(s[J].participant.individualParticipantIds||[]).forEach(se)}}if(h||c||m){const Q=K=>K?Object.assign({},...K.map(Y=>({[Y.participantId]:Y}))):void 0;for(const K of D){const{structures:Y=[],drawOrder:J,drawName:te,drawType:ne,entries:oe,drawId:se}=K,ve=(_=q==null?void 0:q.find(be=>be.drawId===se))==null?void 0:_.flightNumber,X=[x==null?void 0:x.categoryName,x==null?void 0:x.ageCategoryCode].filter(Boolean),ie=(K.structures||[]).sort((be,ge)=>Ii(be,ge)).map(({structureId:be,structures:ge})=>[be,...(ge||[]).map(({structureId:Ne})=>Ne)]).flat(1/0);let fe,$e,re,ae,me=0;const Se=Y.filter(({stage:be,stageSequence:ge})=>be===de&&ge===1||be===Ie).flatMap(be=>{const{seedAssignments:ge,stageSequence:Ne,stage:De}=be,{positionAssignments:he}=et({structure:be});return De===de?(me=(he==null?void 0:he.length)||0,re=he,ae=ge):Ne===1&&(fe=he,$e=ge),he}).map(({participantId:be})=>be).filter(Boolean),ce=Q(ae),Pe=Q($e),Ae=oe.filter(({participantId:be})=>Se.includes(be)),ye=(I=N[j])==null?void 0:I.publishedSeeding,Ue=!o||(ye==null?void 0:ye.published)&&(((P=ye==null?void 0:ye.drawIds)==null?void 0:P.length)===0||((O=ye==null?void 0:ye.drawIds)==null?void 0:O.includes(se)));for(const be of Ae){const{entryStatus:ge,entryStage:Ne,entryPosition:De,participantId:he}=be,ke=M({participantId:he,scaleNames:X,eventType:R}),je=Ze=>{var ot,Ke,At,rr;if(s[Ze].draws[se])return;const Jt=m&&Ue,To=Jt?{}:void 0,io=Jt?((ot=ce==null?void 0:ce[he])==null?void 0:ot.seedValue)||((Ke=ce==null?void 0:ce[he])==null?void 0:Ke.seedNumber):void 0,Mi=Jt?((At=Pe==null?void 0:Pe[he])==null?void 0:At.seedValue)||((rr=Pe==null?void 0:Pe[he])==null?void 0:rr.seedNumber):void 0;io&&(To[de]=io),Mi&&(To[Ie]=io),(g||c)&&(Jt?s[Ze].events[j].seedValue=io||Mi:s[Ze].events[j].seedValue&&(s[Ze].events[j].seedValue=void 0)),(h||c)&&(s[Ze].draws[se]=_e({seedAssignments:To,entryPosition:De,entryStatus:ge,entryStage:Ne,eventId:j,ranking:ke,drawId:se},!1,!1,!0))};if(![qr,ns].includes(ge)){je(he);const Ze=s[he].participant.individualParticipantIds||[];Ze==null||Ze.forEach(je)}}$[se]={qualifyingPositionAssignments:fe,qualifyingSeedAssignments:$e,mainPositionAssignments:re,qualifyingSeedingMap:Pe,mainSeedAssignments:ae,orderedStructureIds:ie,mainSeedingMap:ce,flightNumber:ve,drawOrder:J,drawName:te,drawType:ne,drawSize:me,drawId:se}}}if(c||u||d||p||v||f||h){const Q=!!u||a,K=(y=Oi({afterRecoveryTimes:!!u,policyDefinitions:r,tournamentRecord:n,inContext:!0,contextProfile:i,participantMap:s,nextMatchUps:Q,event:C}))==null?void 0:y.matchUps;for(const Y of K){const{finishingPositionRange:J,potentialParticipants:te,tieMatchUps:ne=[],sides:oe=[],winningSide:se,matchUpType:ve,matchUpId:X,eventId:ie,drawId:fe,collectionId:$e,stageSequence:re,finishingRound:ae,matchUpStatus:me,roundPosition:Se,roundNumber:ce,structureId:Pe,schedule:Ae,score:ye,stage:Ue}=Y;U[X]=Y;const be={finishingPositionRange:J,finishingRound:ae,stageSequence:re,roundPosition:Se,collectionId:$e,roundNumber:ce,structureId:Pe,schedule:Ae,eventId:ie,drawId:fe,score:ye,stage:Ue};Rb(ad(Ea(Ea({},be),E),{matchUpStatus:me,winningSide:se,matchUpType:ve,matchUpId:X,sides:oe}));for(const ge of ne){const{winningSide:Ne,sides:De=[],matchUpId:he,matchUpStatus:ke,matchUpType:je}=ge;Rb(ad(Ea(Ea({},be),E),{winningSide:Ne,tieWinningSide:se,matchUpTieId:X,matchUpId:he,sides:De,matchUpSides:oe,matchUpStatus:ke,matchUpType:je}))}if(Array.isArray(te)&&(Q||u||l)){const ge=Kn(te.flat());ge==null||ge.forEach(Ne=>{const De=T(Ne);De==null||De.forEach(he=>{s[he].potentialMatchUps[X]=_e({tournamentId:n==null?void 0:n.tournamentId,matchUpId:X,eventId:ie,drawId:fe})}),(u||l)&&jb({potential:!0,participantMap:s,participantId:Ne,matchUpStatus:me,roundPosition:Se,structureId:Pe,matchUpType:ve,roundNumber:ce,matchUpId:X,schedule:Ae,drawId:fe,score:ye})})}}A.push(...K)}}if(p||c||u)for(const C of Object.values(s)){const{wins:D,losses:F,[pt]:{wins:R,losses:G},[it]:{wins:x,losses:z}}=C.counters,j=(V,L,q)=>{const k=L+q,H=L,Q=k&&H/k;C.statistics[V]={denominator:k,numerator:H,statValue:Q,statCode:V}};if(p&&(j(ac,D,F),j(`${ac}.${pt}`,R,G),j(`${ac}.${it}`,x,z)),c){const V=(L=[])=>Math.abs(L[0]-L[1]);for(const L of Object.keys(C.draws)){const{orderedStructureIds:q=[],flightNumber:k}=$[L]||{};if(C.structureParticipation&&q.length){let H,Q=0;const K=q.map(Y=>{const J=C.structureParticipation[Y];if(!J)return;H||(H=J.finishingPositionRange),V(H)>V(J.finishingPositionRange)&&(H=J.finishingPositionRange);const te=J.stage!==Ie;te&&(Q+=1);const ne=te?Q:void 0;return _e(ad(Ea({},J),{participationOrder:ne,flightNumber:k}))}).filter(Boolean);C.draws[L].finishingPositionRange=H,C.draws[L].structureParticipation=K}}}if(u){const V=Li(u)?u.scheduledMinutesDifference:0,L=C.scheduleItems||[],q=C.potentialMatchUps||{},k=L.reduce((Q,K)=>{const{scheduledDate:Y,scheduledTime:J}=K;return Q[Y]||(Q[Y]=[]),J&&Q[Y].push(K),Q},{});Object.values(k).forEach(Q=>Q.sort(o_));for(const Q of L){const{typeChangeTimeAfterRecovery:K,timeAfterRecovery:Y,scheduledDate:J,scheduledTime:te}=Q,ne=k[J],oe=Re(te);for(const se of ne){if(se.matchUpId===Q.matchUpId||[Ge,Be].includes(se.matchUpStatus)&&!se.scoreHasValue)continue;const ie=Q.matchUpType!==se.matchUpType&&K||Y,fe=Q.drawId===se.drawId,$e=q[Q.matchUpId]&&q[se.matchUpId],re=Re(se.scheduledTime),ae=Math.abs(re-oe);(V&&!isNaN(V)?ae<=V:Re(ie)>Re(se.scheduledTime))&&!($e&&fe)&&C.scheduleConflicts.push({priorScheduledMatchUpId:se.matchUpId,matchUpIdWithConflict:Q.matchUpId})}}const H=C.participant.participantId;C.scheduleConflicts.length&&b.push(H),s[H].scheduleConflicts=C.scheduleConflicts}}return{participantIdsWithConflicts:b,eventsPublishStatuses:N,derivedEventInfo:w,derivedDrawInfo:$,mappedMatchUps:U,participantMap:s,matchUps:A}}var p7=Object.defineProperty,f7=Object.defineProperties,v7=Object.getOwnPropertyDescriptors,cd=Object.getOwnPropertySymbols,Vb=Object.prototype.hasOwnProperty,xb=Object.prototype.propertyIsEnumerable,Bb=(t,e,r)=>e in t?p7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,kb=(t,e)=>{for(var r in e||(e={}))Vb.call(e,r)&&Bb(t,r,e[r]);if(cd)for(var r of cd(e))xb.call(e,r)&&Bb(t,r,e[r]);return t},Gb=(t,e)=>f7(t,v7(e)),m7=(t,e)=>{var r={};for(var n in t)Vb.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&cd)for(var n of cd(t))e.indexOf(n)<0&&xb.call(t,n)&&(r[n]=t[n]);return r};function ys({withIndividualParticipants:t,participantFilters:e={},withPotentialMatchUps:r,withRankingProfile:n,convertExtensions:o,policyDefinitions:i,withScheduleItems:s,tournamentRecord:a,scheduleAnalysis:c,withSignInStatus:l,withTeamMatchUps:u,withScaleValues:d,usePublishState:p,contextProfile:v,withStatistics:f,withOpponents:m,withMatchUps:g,internalUse:h,withSeeding:_,withEvents:I,withDraws:P,withISO2:O,withIOC:y}){if(!a)return{error:ee};(g||n)&&Yr({tournamentRecord:a});let{participantMap:S}=aS({withIndividualParticipants:t,convertExtensions:o,policyDefinitions:i,tournamentRecord:a,withSignInStatus:l,withScaleValues:d,internalUse:h,withISO2:O,withIOC:y}),T,E,b,N,w,$;({participantIdsWithConflicts:T,eventsPublishStatuses:E,derivedEventInfo:b,derivedDrawInfo:N,participantMap:S,mappedMatchUps:w,matchUps:$}=d7({withMatchUps:g||n,withEvents:I||n,withDraws:P||n,withPotentialMatchUps:r,participantFilters:e,withRankingProfile:n,policyDefinitions:i,convertExtensions:o,withScheduleItems:s,tournamentRecord:a,scheduleAnalysis:c,withTeamMatchUps:u,usePublishState:p,withStatistics:f,contextProfile:v,participantMap:S,withOpponents:m,withSeeding:_}));const U=c||r,A=Object.values(S).map(C=>{var D=C,{potentialMatchUps:F,scheduleConflicts:R,statistics:G,opponents:x,matchUps:z,events:j,draws:V}=D,L=m7(D,["potentialMatchUps","scheduleConflicts","statistics","opponents","matchUps","events","draws"]);const q=Object.values(V),k=Object.values(x);return m&&(q==null||q.forEach(H=>{H.opponents=k.filter(Q=>Q.drawId===H.drawId)})),_e(Gb(kb({},L.participant),{scheduleConflicts:c?R:void 0,draws:P||n?q:void 0,events:I||n?Object.values(j):void 0,matchUps:g||n?Object.values(z):void 0,opponents:m?k:void 0,potentialMatchUps:U?Object.values(F):void 0,statistics:f?Object.values(G):void 0}),!1,!1,!0)});let M=sd({participants:A,participantFilters:e,tournamentRecord:a});return Gb(kb({participantIdsWithConflicts:T,eventsPublishStatuses:E,derivedEventInfo:b,derivedDrawInfo:N,mappedMatchUps:w,participantMap:S,participants:M},B),{matchUps:$})}function qv(t,e,r){return!t&&e?e:t&&!e||typeof t!="object"||typeof e!="object"?t:Ve(Object.keys(t).concat(Object.keys(e))).reduce((o,i)=>{if(!e[i])o[i]=t[i];else if(!t[i])o[i]=e[i];else if(typeof t[i]!=typeof e[i])o[i]=e[i];else if(Array.isArray(t[i]))if(r===!0||Array.isArray(r)&&r.includes(i)){const s=Ve(t[i].map(a=>JSON.stringify(a)).concat(e[i].map(a=>JSON.stringify(a)))).map(a=>JSON.parse(a));o[i]=s}else o[i]=e[i];else typeof t[i]=="object"?o[i]=qv(t[i],e[i],r):o[i]=e[i];return o},{})}var g7=Object.defineProperty,h7=Object.defineProperties,_7=Object.getOwnPropertyDescriptors,Wb=Object.getOwnPropertySymbols,I7=Object.prototype.hasOwnProperty,P7=Object.prototype.propertyIsEnumerable,Hb=(t,e,r)=>e in t?g7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tl=(t,e)=>{for(var r in e||(e={}))I7.call(e,r)&&Hb(t,r,e[r]);if(Wb)for(var r of Wb(e))P7.call(e,r)&&Hb(t,r,e[r]);return t},y7=(t,e)=>h7(t,_7(e));function S7(t){const{tournamentRecords:e}=t||{};if(typeof e!="object"||!Object.keys(e).length)return{error:Fe};const r={},n={},o={},i={},s=[],a=[],c=[];for(const l of Object.values(e)){const{participantIdsWithConflicts:u,mappedMatchUps:d,participantMap:p,participants:v,matchUps:f,derivedEventInfo:m,derivedDrawInfo:g}=ys(tl({tournamentRecord:l},t));Object.assign(i,d),Object.assign(o,p),Object.assign(r,m),Object.assign(n,g),s.push(...v),a.push(...f),u==null||u.forEach(h=>{c.includes(h)||c.push(h)})}return y7(tl({participantIdsWithConflicts:c,derivedEventInfo:r,derivedDrawInfo:n,participantMap:o,mappedMatchUps:i,participants:s},B),{matchUps:a})}function O7(t){const{tournamentRecords:e}=t||{};if(typeof e!="object"||!Object.keys(e).length)return{error:Fe};const r=[],n=[];let o=[];for(const i of Object.values(e)){const{tournamentParticipants:s,participantIdsWithConflicts:a}=Qt(tl({tournamentRecord:i},t));for(const c of s){const{participantId:l}=c;n.includes(l)?o=o.map(u=>u.participantId!==l?u:qv(u,c,!0)):(n.push(l),o.push(c))}a&&a.forEach(c=>{r.includes(c)||r.push(c)})}return tl({competitionParticipants:o,participantIdsWithConflicts:r},B)}function qb({policyDefinitions:t,tournamentRecords:e,participantId:r,inContext:n,personId:o}){if(!e)return{error:Fe};if(typeof r!="string"&&typeof o!="string")return{error:Oe,stack:"publicFindParticipant"};let i,s;for(const a of Object.values(e)){s=a.tournamentId;const{tournamentParticipants:c}=Qt({policyDefinitions:t,tournamentRecord:a,inContext:n});if(i=vo({tournamentParticipants:c,internalUse:!0,policyDefinitions:t,participantId:r,personId:o}),i)break}return tl({participant:i,tournamentId:s},B)}const Yb=({penaltyId:t=We()}={})=>({refereeParticipantId:void 0,penaltyCode:void 0,penaltyType:void 0,extensions:void 0,matchUpId:void 0,createdAt:void 0,issuedAt:void 0,notes:void 0,penaltyId:t});var b7=Object.defineProperty,T7=Object.defineProperties,E7=Object.getOwnPropertyDescriptors,zb=Object.getOwnPropertySymbols,w7=Object.prototype.hasOwnProperty,$7=Object.prototype.propertyIsEnumerable,Kb=(t,e,r)=>e in t?b7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ld=(t,e)=>{for(var r in e||(e={}))w7.call(e,r)&&Kb(t,r,e[r]);if(zb)for(var r of zb(e))$7.call(e,r)&&Kb(t,r,e[r]);return t},ud=(t,e)=>T7(t,E7(e));function Qb({refereeParticipantId:t,tournamentRecord:e,participantIds:r,penaltyCode:n,penaltyType:o,extensions:i,penaltyId:s,matchUpId:a,issuedAt:c,notes:l}){if(!e)return{error:ee};if(!r)return{error:yt};if(!o)return{error:HF};const d=((e==null?void 0:e.participants)||[]).filter(f=>r.includes(f.participantId));if(!d.length)return{error:wt};const p=new Date().toISOString(),v=Object.assign(Yb({penaltyId:s}),{refereeParticipantId:t,penaltyCode:n,penaltyType:o,matchUpId:a,notes:l,issuedAt:c,createdAt:p});return Array.isArray(i)&&i.forEach(f=>tt({element:v,extension:f})),d.forEach(f=>{f.penalties||(f.penalties=[]),f.penalties.push(v)}),xe({topic:Ht,payload:{tournamentId:e.tournamentId,participants:d}}),ud(ld({},B),{penaltyId:v.penaltyId})}function Jb({tournamentRecord:t,penaltyId:e}){if(!t)return{error:ee};if(!e)return{error:Rh};const r=(t==null?void 0:t.participants)||[],n=[];let o=!1,i;return r.forEach(s=>{let a=!1;s.penalties=(s.penalties||[]).filter(c=>(c.penaltyId===e&&(a=!0,o||(i=c,o=!0)),a&&n.push(s),c.penaltyId!==e))}),i&&xe({topic:Ht,payload:{tournamentId:t.tournamentId,participants:n}}),i?ud(ld({},B),{penalty:i}):{error:Al}}function Zb({tournamentRecord:t}){if(!t)return{error:ee};const r=((t==null?void 0:t.participants)||[]).reduce((n,o)=>{const{participantId:i}=o;return(o.penalties||[]).forEach(s=>{const{penaltyId:a}=s||{};n[a]?n[a].participants.push(i):n[a]=ud(ld({},s),{participantIds:[i]})}),n},{});return{penalties:Object.values(r)}}function Xb({tournamentRecord:t,penaltyId:e,modifications:r}){if(!t)return{error:ee};if(!r)return{error:Z,modifications:r};if(!e)return{error:Rh};const n=(t==null?void 0:t.participants)||[],o=Object.keys(Yb()).filter(c=>c!=="penaltyId"),i=Object.keys(r).filter(c=>o.includes(c));if(!i.length)return{error:Lp};let s;const a=[];return n.forEach(c=>{let l=!1;c.penalties=(c.penalties||[]).map(u=>(u.penaltyId===e&&(l=!0,i.forEach(d=>Object.assign(u,{[d]:r[d]})),s||(s=u)),u)),l&&a.push(c)}),s&&xe({topic:Ht,payload:{tournamentId:t.tournamentId,participants:a}}),s?ud(ld({},B),{penalty:s}):{error:Al}}var N7=Object.defineProperty,A7=Object.defineProperties,U7=Object.getOwnPropertyDescriptors,eT=Object.getOwnPropertySymbols,C7=Object.prototype.hasOwnProperty,M7=Object.prototype.propertyIsEnumerable,tT=(t,e,r)=>e in t?N7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wa=(t,e)=>{for(var r in e||(e={}))C7.call(e,r)&&tT(t,r,e[r]);if(eT)for(var r of eT(e))M7.call(e,r)&&tT(t,r,e[r]);return t},rT=(t,e)=>A7(t,U7(e));function D7(t){const{tournamentRecords:e,participantIds:r}=t;let n;for(const o of Object.values(e)){const{tournamentParticipants:i}=Qt({tournamentRecord:o}),s=Kn(i).filter(a=>r.includes(a));s.length&&(n=Qb(rT(wa({},t),{penaltyId:t.penaltyId||n,tournamentRecord:o,participantIds:s})).penaltyId)}return n?rT(wa({},B),{penaltyId:n}):{error:wt}}function j7(t){const{tournamentRecords:e}=t;if(typeof e!="object"||!Object.keys(e).length)return{error:Fe};for(const r of Object.values(e)){const n=Xb(wa({tournamentRecord:r},t));if(n.error&&n.error!==Al)return n}return wa({},B)}function R7(t){const{tournamentRecords:e}=t;if(typeof e!="object"||!Object.keys(e).length)return{error:Fe};for(const r of Object.values(e)){const n=Jb(wa({tournamentRecord:r},t));if(n.error&&n.error!==Al)return n}return wa({},B)}function F7({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const e=[];for(const r of Object.values(t)){const{penalties:n}=Zb({tournamentRecord:r});e.push(...n)}return{penalties:e}}const L7={addExtension:vf,findExtension:Zl,removeExtension:Xl,addEventExtension:rB,linkTournaments:sB,unlinkTournament:cB,unlinkTournaments:aB,getLinkedTournamentIds:mf,addDrawDefinition:bY,getCompetitionParticipants:O7,getParticipants:S7,addParticipant:UY,courtGridRows:L0,setMatchUpStatus:hY,bulkMatchUpStatusUpdate:_Y,bulkScheduleMatchUps:rO,addPenalty:D7,removePenalty:R7,modifyPenalty:j7,getCompetitionPenalties:F7,findParticipant:qb};var V7=Object.defineProperty,nT=Object.getOwnPropertySymbols,x7=Object.prototype.hasOwnProperty,B7=Object.prototype.propertyIsEnumerable,oT=(t,e,r)=>e in t?V7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,iT=(t,e)=>{for(var r in e||(e={}))x7.call(e,r)&&oT(t,r,e[r]);if(nT)for(var r of nT(e))B7.call(e,r)&&oT(t,r,e[r]);return t};function sT({removePriorValues:t=!0,tournamentRecord:e,status:r=$n}){if(!e)return{error:ee};const n=`${Ar}.${Ur}`,{timeItem:o}=Eu({itemType:n}),i=(o==null?void 0:o.itemValue)||{[r]:{}};return i[r]&&delete i[r].orderOfPlay,bo({timeItem:{itemValue:i,itemType:n},removePriorValues:t,tournamentRecord:e}),xe({topic:RI,payload:{tournamentId:e.tournamentId}}),iT({},B)}function aT({scheduledDates:t=[],removePriorValues:e,tournamentRecord:r,status:n=$n,eventIds:o=[]}){if(!r)return{error:ee};const i=`${Ar}.${Ur}`,{timeItem:s}=Eu({itemType:i}),a=(s==null?void 0:s.itemValue)||{[n]:{}};return a[n].orderOfPlay={published:!0,scheduledDates:t,eventIds:o},bo({timeItem:{itemValue:a,itemType:i},removePriorValues:e,tournamentRecord:r}),xe({topic:yB,payload:{tournamentId:r.tournamentId,scheduledDates:t,eventIds:o}}),iT({},B)}var k7=Object.defineProperty,cT=Object.getOwnPropertySymbols,G7=Object.prototype.hasOwnProperty,W7=Object.prototype.propertyIsEnumerable,lT=(t,e,r)=>e in t?k7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dd=(t,e)=>{for(var r in e||(e={}))G7.call(e,r)&&lT(t,r,e[r]);if(cT)for(var r of cT(e))W7.call(e,r)&&lT(t,r,e[r]);return t};function H7(t){const e=t==null?void 0:t.tournamentRecords;if(!e)return{error:Fe};for(const r of Object.values(e)){const n=sT(dd({tournamentRecord:r},t));if(n.error)return n}return dd({},B)}function q7(t){const e=t==null?void 0:t.tournamentRecords;if(!e)return{error:Fe};for(const r of Object.values(e)){const n=aT(dd({tournamentRecord:r},t));if(n.error)return n}return dd({},B)}const Y7={unPublishOrderOfPlay:H7,publishOrderOfPlay:q7};function uT({tournamentRecords:t,extensionName:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const r=[];let n;for(const o of Object.values(t)){const{extension:i}=Sr({name:e,tournamentRecord:o});i&&!n&&(r.push({method:"addExtension",params:{extension:i}}),n=!0);const s=o.events||[];for(const a of s){const{eventId:c}=a,{extension:l}=mo({name:e,event:a});l&&r.push({params:{eventId:c,extension:l},method:"addEventExtension"})}}return{methods:r}}function z7({tournamentRecords:t}){return uT({tournamentRecords:t,extensionName:En})}var K7=Object.defineProperty,Q7=Object.defineProperties,J7=Object.getOwnPropertyDescriptors,dT=Object.getOwnPropertySymbols,Z7=Object.prototype.hasOwnProperty,X7=Object.prototype.propertyIsEnumerable,pT=(t,e,r)=>e in t?K7(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eK=(t,e)=>{for(var r in e||(e={}))Z7.call(e,r)&&pT(t,r,e[r]);if(dT)for(var r of dT(e))X7.call(e,r)&&pT(t,r,e[r]);return t},tK=(t,e)=>Q7(t,J7(e));function fT({tournamentRecord:t,matchUpFormats:e,categoryType:r,event:n}){if(!t)return{error:ee};if(!n)return{error:Le};let o=[];if(e!=null&&e.length){const u=[];o=e.map(d=>{let p=typeof d=="string"?{matchUpFormat:d}:d;if(!u.includes(p==null?void 0:p.matchUpFormat)&&xr(p==null?void 0:p.matchUpFormat))return u.push(p.matchUpFormat),p}).filter(Boolean)}else{const{policy:u}=qi({policyType:Ys,tournamentRecord:t,event:n});if(u!=null&&u.matchUpFormats)o=u==null?void 0:u.matchUpFormats;else{const{extension:d}=mo({name:En,event:n});if(d!=null&&d.value)o=Ve([...(d.value.matchUpAverageTimes||[]).map(p=>p.matchUpFormatCodes),...(d.value.matchUpRecoveryTimes||[]).map(p=>p.matchUpFormatCodes)].flat()).map(p=>({matchUpFormat:p}));else return{error:EF}}}const{eventType:i,eventId:s,category:a}=n,c=(a==null?void 0:a.categoryName)||(a==null?void 0:a.ageCategoryCode)||s;return s?{eventMatchUpFormatTiming:o.map(({matchUpFormat:u,description:d})=>{const p=lf({tournamentRecord:t,matchUpFormat:u,categoryName:c,categoryType:r,eventType:i,event:n});return Object.assign({},tK(eK({},p),{description:d,matchUpFormat:u}))})}:{error:Le}}function rK({tournamentRecords:t,matchUpFormats:e,categoryType:r,tournamentId:n,eventId:o}){if(!o)return{error:Le};const i=Object.keys(t).filter(l=>!n||l===n);if(n&&!i.length)return{error:Z};let s,a,c;return i.forEach(l=>{const u=t[l],{event:d}=xt({tournamentRecord:u,eventId:o});if(!d)return!1;c=!0;const{eventMatchUpFormatTiming:p,error:v}=fT({tournamentRecord:u,matchUpFormats:e,categoryType:r,event:d});v&&(a=v),s=p}),!c&&{error:Ir}||a&&{error:a}||{eventMatchUpFormatTiming:s}}function pd({tournamentRecords:t,schedulingProfile:e}){if(!e)return{valid:!0};if(!Array.isArray(e))return{valid:!1,error:Z};const{venueIds:r,tournamentsMap:n}=nK({tournamentRecords:t});let o,i;const s=e.every(a=>{const{scheduleDate:c,venues:l}=a;return Nr(c)?l.every(u=>{const{venueId:d,rounds:p}=u;return typeof d!="string"?(i="venueId should be a string",!1):Array.isArray(p)?r.includes(d)?!!p.every(f=>{var m,g,h;if(!f)return i="empty round",!1;const{roundSegment:_,tournamentId:I,structureId:P,roundNumber:O,eventId:y,drawId:S}=f,T=(h=(g=(m=n==null?void 0:n[I])==null?void 0:m[y])==null?void 0:g[S])==null?void 0:h[P],E=T==null?void 0:T.includes(O);E||(i="Invalid rounds");const{segmentNumber:b,segmentsCount:N}=_||{},w=!_||ut(b)&&Vr(N)&&b<=N;return w||(i="Invalid segment"),E&&w}):(o=oi,!1):(i="rounds should be an array",!1)}):!1});return!s&&!o&&(o=Z),{valid:!!s,error:o,info:i}}function vT({tournamentRecord:t={},tournamentMap:e={},requireCourts:r}={}){const n=[],o=[],i=[],s=[],a=((t==null?void 0:t.venues)||[]).map(({venueId:l,courts:u})=>(!r||(u==null?void 0:u.length))&&l),c=t==null?void 0:t.tournamentId;return c&&(s.push(c),e[c]={},((t==null?void 0:t.events)||[]).forEach(u=>{const d=u.eventId;o.push(d),e[c][d]={},(u.drawDefinitions||[]).forEach(p=>{const v=p.drawId;n.push(v),e[c][d][v]={};const{structures:f}=Cr({drawDefinition:p});(f||[]).forEach(m=>{var g;const h=m.structureId,{matchUps:_}=ze({structure:m}),{roundMatchUps:I}=pr({matchUps:_}),P=I&&Object.keys(I).map(O=>parseInt(O));e[c][d][v][h]=P,i.push(h),(g=m.structures)!=null&&g.length&&m.structures.forEach(O=>{i.push(O.structureId),e[c][d][v][O.structureId]=P})})})})),{tournamentMap:e,tournamentIds:s,structureIds:i,venueIds:a,eventIds:o,drawIds:n}}function nK({tournamentRecords:t={}}={}){const e=t&&Object.values(t)||[],r={},{venueIds:n,eventIds:o,drawIds:i,structureIds:s,tournamentIds:a}=e.reduce((c,l)=>{const{tournamentIds:u,tournamentMap:d,structureIds:p,venueIds:v,eventIds:f,drawIds:m}=vT({tournamentRecord:l});return v.forEach(g=>{c.venueIds.includes(g)||c.venueIds.push(g)}),c.tournamentIds.push(...u),c.structureIds.push(...p),c.eventIds.push(...f),c.drawIds.push(...m),Object.assign(r,d),c},{tournamentIds:[],structureIds:[],venueIds:[],eventIds:[],drawIds:[]});return{tournamentsMap:r,tournamentIds:a,structureIds:s,venueIds:n,eventIds:o,drawIds:i}}var oK=Object.defineProperty,mT=Object.getOwnPropertySymbols,iK=Object.prototype.hasOwnProperty,sK=Object.prototype.propertyIsEnumerable,gT=(t,e,r)=>e in t?oK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,aK=(t,e)=>{for(var r in e||(e={}))iK.call(e,r)&&gT(t,r,e[r]);if(mT)for(var r of mT(e))sK.call(e,r)&&gT(t,r,e[r]);return t};function cK({tournamentRecords:t,matchUpFormat:e,recoveryTimes:r,averageTimes:n,tournamentId:o,eventId:i}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const s=Object.keys(t).filter(c=>!o||o===c);if(o&&!s.includes(o))return{error:Z};let a;for(const c of s){const l=t[c],{event:u}=xt({tournamentRecord:l,eventId:i});i&&u&&(a=!0);const d=xv({tournamentRecord:l,event:u,matchUpFormat:e,averageTimes:n,recoveryTimes:r});if(d.error)return d}return!i||a?aK({},B):{error:Ir}}function Yv({defaultRecoveryMinutes:t=0,defaultAverageMinutes:e,tournamentRecords:r,tournamentId:n,matchUpFormat:o,categoryName:i,categoryType:s,eventType:a,eventId:c}){if(!xr(o))return{error:wl};const l=Object.keys(r).filter(d=>!n||d===n);let u;return l.forEach(d=>{var p;if(u)return;const v=r[d],f=c&&((p=xt({tournamentRecord:v,eventId:c}))==null?void 0:p.event);return u=lf({tournamentRecord:v,matchUpFormat:o,categoryName:i,categoryType:s,eventType:a,event:f}),(u==null?void 0:u.averageMinutes)||(u==null?void 0:u.recoveryMinutes)}),{averageMinutes:(u==null?void 0:u.averageMinutes)||e,recoveryMinutes:(u==null?void 0:u.recoveryMinutes)||t,typeChangeRecoveryMinutes:(u==null?void 0:u.typeChangeRecoveryMinutes)||(u==null?void 0:u.recoveryMinutes)||t}}var lK=Object.defineProperty,uK=Object.defineProperties,dK=Object.getOwnPropertyDescriptors,hT=Object.getOwnPropertySymbols,pK=Object.prototype.hasOwnProperty,fK=Object.prototype.propertyIsEnumerable,_T=(t,e,r)=>e in t?lK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,IT=(t,e)=>{for(var r in e||(e={}))pK.call(e,r)&&_T(t,r,e[r]);if(hT)for(var r of hT(e))fK.call(e,r)&&_T(t,r,e[r]);return t},vK=(t,e)=>uK(t,dK(e));function zv({scheduleCompletedMatchUps:t,containedStructureIds:e,tournamentRecords:r,periodLength:n=30,matchUps:o,rounds:i}){if(typeof r!="object")return{error:Fe};if(!Array.isArray(i))return{error:Oe,info:zt("rounds")};const s=[],a=i.sort((v,f)=>(v.sortOrder||0)-(f.sortOrder||0));e=e||Object.assign({},...Object.values(r).map(v=>_a({tournamentRecord:v}).containedStructures)),o||({matchUps:o}=Oo({nextMatchUps:!0,tournamentRecords:r}));let c=0;const l={},u={},d={},p=a.flatMap(v=>{var f;const m=v.periodLength||n,g=e[v.structureId]||[v.structureId],h={tournamentIds:[v.tournamentId],roundNumbers:[v.roundNumber],matchUpIds:v.matchUpIds,eventIds:[v.eventId],drawIds:[v.drawId],structureIds:g};let _=ss(vK(IT({},h),{processContext:!0,matchUps:o})).sort(vs);const{segmentNumber:I,segmentsCount:P}=v.roundSegment||{};if(ut(I)&&Vr(_==null?void 0:_.length)&&Vr(P)&&I>0&&I<=P&&P<(_==null?void 0:_.length)&&!((f=v.matchUpIds)!=null&&f.length)){const E=_.length/P,b=E*(I-1);_=_.slice(b,b+E)}const O=r[v.tournamentId],{event:y}=xt({drawId:v.drawId,tournamentRecord:O}),S=[],T={};for(const E of _){const b=E.matchUpFormat;T[b]||(T[b]=[],S.push(b)),S.push(E)}for(const E of S){const{eventType:b,category:N,categoryType:w}=y||{},{categoryName:$,ageCategoryCode:U}=N||{},{typeChangeRecoveryMinutes:A,recoveryMinutes:M,averageMinutes:C,error:D}=Yv({categoryName:$||U,tournamentId:v.tournamentId,eventId:v.eventId,tournamentRecords:r,matchUpFormat:E,categoryType:w,eventType:b});if(D)return{error:D,round:v};const F=_.filter(({matchUpStatus:G})=>(t||!Lt.includes(G))&&G!==qe).map(Mt);F.forEach(G=>{d[G]={typeChangeRecoveryMinutes:A,recoveryMinutes:M,averageMinutes:C},l[G]=M,u[G]=C}),s.push(...F),c=Math.max(C||0,c);const R=`${C}|${m}`;return{roundPeriodLength:m,recoveryMinutes:M,averageMinutes:C,matchUpIds:F,hash:R}}});return IT({scheduledRoundsDetails:p,greatestAverageMinutes:c,recoveryMinutesMap:l,averageMinutesMap:u,orderedMatchUpIds:s,minutesMap:d},B)}function PT({tournamentRecords:t}){const r=Object.keys(t).reduce((i,s)=>{const a=t[s],{tournamentInfo:{startDate:c,endDate:l}}=el({tournamentRecord:a}),u=c&&new Date(Ce(c));(!i.startDate||u&&u<i.startDate)&&(i.startDate=u);const d=l&&new Date(Ce(l));return(!i.endDate||d&&d>i.endDate)&&(i.endDate=d),i},{startDate:void 0,endDate:void 0}),n=r.startDate&&Ce(r.startDate.toISOString()),o=r.endDate&&Ce(r.endDate.toISOString());return!n||!o?{error:Eh}:{startDate:n,endDate:o}}var mK=Object.defineProperty,gK=Object.defineProperties,hK=Object.getOwnPropertyDescriptors,yT=Object.getOwnPropertySymbols,_K=Object.prototype.hasOwnProperty,IK=Object.prototype.propertyIsEnumerable,ST=(t,e,r)=>e in t?mK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kv=(t,e)=>{for(var r in e||(e={}))_K.call(e,r)&&ST(t,r,e[r]);if(yT)for(var r of yT(e))IK.call(e,r)&&ST(t,r,e[r]);return t},PK=(t,e)=>gK(t,hK(e));function $a({tournamentRecords:t}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const{extension:e}=Zl({name:Do,tournamentRecords:t});let r=(e==null?void 0:e.value)||[];if(r.length){const{venueIds:n}=vv({tournamentRecords:t,requireCourts:!0}),{eventIds:o,drawIds:i}=xu({tournamentRecords:t}),{updatedSchedulingProfile:s,modifications:a,issues:c}=fd({schedulingProfile:r,venueIds:n,eventIds:o,drawIds:i});if(a){r=s;const l=rl({tournamentRecords:t,schedulingProfile:r});return l.error?l:{schedulingProfile:r,modifications:a,issues:c}}}return{schedulingProfile:r,modifications:0}}function rl({tournamentRecords:t,schedulingProfile:e}){const r=pd({tournamentRecords:t,schedulingProfile:e});return r.error?r:e?vf({tournamentRecords:t,extension:{name:Do,value:e}}):Xl({tournamentRecords:t,name:Do})}function OT({tournamentRecords:t,scheduleDate:e,venueId:r,round:n}){if(!Nr(e))return{error:cr};const o="addSchedulingProfileRound",{extension:i}=Zl({tournamentRecords:t,name:Do}),s=(i==null?void 0:i.value)||[];let a=s.find(v=>kn(e,v.scheduleDate));if(!a){const{startDate:v,endDate:f}=PT({tournamentRecords:t}),m=new Date(e);if(m<new Date(v)||m>new Date(f))return{error:cr};a={scheduleDate:e,venues:[]},s.push(a)}let c=a.venues.find(v=>v.venueId===r);c||(c={venueId:r,rounds:[]},a.venues.push(c));const l=["notBeforeTime"],u=v=>Object.keys(v).filter(f=>!l.includes(f)).sort().map(f=>Li(v[f])?u(v[f]):v[f]).flat().join("|");if(c.rounds.find(v=>u(v)===u(n)))return W({result:{error:vF},stack:o});c.rounds.push(n);const p=rl({tournamentRecords:t,schedulingProfile:s});return p.error?p:Kv({},B)}function fd({schedulingProfile:t,venueIds:e,eventIds:r,drawIds:n}){const o=[],i=t==null?void 0:t.map(a=>{const c=Ce(a==null?void 0:a.scheduleDate);if(!c){o.push(`Invalid date: ${a==null?void 0:a.scheduledDate}`);return}const l=((a==null?void 0:a.venues)||[]).map(u=>{const{rounds:d,venueId:p}=u;if(!e.includes(p)){o.push(`Missing venueId: ${p}`);return}const f=d.filter(m=>{const g=r.includes(m.eventId)&&n.includes(m.drawId);return g||o.push(`Invalid eventId: ${m.eventId} or drawId: ${m.drawId}`),g});if(f.length)return{venueId:p,rounds:f}}).filter(Boolean);return l.length&&c&&PK(Kv({},a),{venues:l})}).filter(Boolean),s=o.length;return{updatedSchedulingProfile:i,modifications:s,issues:o}}function bT({tournamentRecords:t}){const{schedulingProfile:e}=$a({tournamentRecords:t,requireCourts:!0});if(e){const{venueIds:r}=vv({tournamentRecords:t}),{eventIds:n,drawIds:o}=xu({tournamentRecords:t}),{updatedSchedulingProfile:i,modifications:s}=fd({schedulingProfile:e,venueIds:r,eventIds:n,drawIds:o});if(s)return rl({tournamentRecords:t,schedulingProfile:i})}return Kv({},B)}function vd({matchUps:t=[],schedulingProfile:e}){const r={},n=({eventId:a,drawId:c,structureId:l,roundNumber:u})=>`${a}|${c}|${l}${u}`;e!=null&&e.length&&e.map(({venues:c})=>c.map(({rounds:l})=>l)).flat().forEach(c=>{c.sort((u,d)=>(u.sortOrder||0)-(d.sortOrder||0)).forEach(({eventId:u,drawId:d,structureId:p,roundNumber:v},f)=>{const m=n({eventId:u,drawId:d,structureId:p,roundNumber:v});r[m]=f})});const o=[],i={noScheduledDate:[]};for(const a of t){const c=a.schedule||{},l=c.scheduledDate&&Ce(c.scheduledDate)||c.scheduledTime&&Ce(c.scheduledTime)||"noScheduledDate";i[l]||(i[l]=[]),i[l].push(a)}const s=Object.keys(i).sort();for(const a of s){const c=i[a],l={noScheduledTime:[]};for(const d of c){const p=d.schedule||{},v=p.scheduledTime&&rt(p.scheduledTime)||"noScheduledTime";l[v]||(l[v]=[]),l[v].push(d)}const u=Object.keys(l).sort();for(const d of u){const p=l[d];p.sort((v,f)=>{const m=r[n(v)]||0,g=r[n(f)]||0;return m-g}),o.push(...p)}}return o}var yK=Object.defineProperty,SK=Object.defineProperties,OK=Object.getOwnPropertyDescriptors,TT=Object.getOwnPropertySymbols,bK=Object.prototype.hasOwnProperty,TK=Object.prototype.propertyIsEnumerable,ET=(t,e,r)=>e in t?yK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,md=(t,e)=>{for(var r in e||(e={}))bK.call(e,r)&&ET(t,r,e[r]);if(TT)for(var r of TT(e))TK.call(e,r)&&ET(t,r,e[r]);return t},Qv=(t,e)=>SK(t,OK(e));function Jv(t){var e,r,n,o;if(typeof(t==null?void 0:t.tournamentRecords)!="object"||!Object.keys(t==null?void 0:t.tournamentRecords).length)return{error:Fe};const{courts:i,venues:s}=ms(t),a=$a(t).schedulingProfile,{matchUpFilters:c={},contextFilters:l={}}=t,{sortDateMatchUps:u=!0,courtCompletedMatchUps:d,alwaysReturnCompleted:p,activeTournamentId:v,tournamentRecords:f,withCourtGridRows:m,minCourtGridRows:g,usePublishState:h,status:_=$n,sortCourtsData:I}=t,P=h&&Eu({tournamentRecord:f[v],itemType:`${Ar}.${Ur}`}).timeItem,O=(e=P==null?void 0:P.itemValue)==null?void 0:e[_],y=p?cv(Qv(md({},t),{matchUpFilters:Qv(md({},c),{matchUpStatuses:[St]}),contextFilters:l})).completedMatchUps:[];if(h&&(!O||!Object.keys(O).length))return{completedMatchUps:y,dateMatchUps:[],courtsData:[],venues:s};const S=h&&EK({tournamentRecords:f}).drawIds;S!=null&&S.length&&(l.drawIds?l.drawIds=l.drawIds.filter(M=>S.includes(M)):l.drawIds=S),(r=O==null?void 0:O.eventIds)!=null&&r.length&&(c.eventIds&&c.eventIds.length?c.eventIds=c.eventIds.filter(M=>O.eventIds.includes(M)):c.eventIds=O.eventIds),(n=O==null?void 0:O.scheduledDates)!=null&&n.length&&(c.scheduledDates&&c.scheduledDates.length?c.scheduledDates=c.scheduledDates.filter(M=>O.scheduledDates.includes(M)):c.scheduledDates=O.scheduledDates),p&&((o=c.excludeMatchUpStatuses)!=null&&o.length?c.excludeMatchUpStatuses.includes(St)||c.excludeMatchUpStatuses.push(St):c.excludeMatchUpStatuses=[St]);const{completedMatchUps:T,upcomingMatchUps:E,pendingMatchUps:b}=cv(Qv(md({},t),{matchUpFilters:c,contextFilters:l})),N=[...E||[],...b||[]],w=u?vd({matchUps:N,schedulingProfile:a}):N,$=i.map(M=>{const C=A(M);return md({surfaceCategory:(M==null?void 0:M.surfaceCategory)||"",matchUps:C},M)}),U={courtsData:$,completedMatchUps:p?y:T,dateMatchUps:w,venues:s};if(m){const{rows:M,courtPrefix:C}=L0({minRowsCount:g,courtsData:$});U.courtPrefix=C,U.rows=M}return U;function A({courtId:M}){const D=(d?w.concat(T||[]):w).filter(F=>{var R,G,x;return((R=F.schedule)==null?void 0:R.courtId)===M||((x=(G=F.schedule)==null?void 0:G.allocatedCourts)==null?void 0:x.map(({courtId:z})=>z).includes(M))});return I?vd({matchUps:D,schedulingProfile:a}):D}}function EK({tournamentRecords:t}){var e,r;const n=[];for(const o of Object.values(t))for(const i of o.events||[]){const{timeItem:s}=So({itemType:`${Ar}.${Ur}`,event:i}),a=(e=s==null?void 0:s.itemValue)==null?void 0:e[$n];if((r=a==null?void 0:a.drawIds)!=null&&r.length)n.push(...a.drawIds);else{const c=(i.drawDefinitions||[]).map(({drawId:l})=>l).filter(Boolean);n.push(...c)}}return{drawIds:n}}var wK=Object.defineProperty,$K=Object.defineProperties,NK=Object.getOwnPropertyDescriptors,wT=Object.getOwnPropertySymbols,AK=Object.prototype.hasOwnProperty,UK=Object.prototype.propertyIsEnumerable,$T=(t,e,r)=>e in t?wK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,CK=(t,e)=>{for(var r in e||(e={}))AK.call(e,r)&&$T(t,r,e[r]);if(wT)for(var r of wT(e))UK.call(e,r)&&$T(t,r,e[r]);return t},MK=(t,e)=>$K(t,NK(e));function NT({calculateStartTimeFromCourts:t=!0,defaultRecoveryMinutes:e=0,averageMatchUpMinutes:r=90,remainingScheduleTimes:n,clearScheduleDates:o,tournamentRecords:i,periodLength:s,scheduleDate:a,startTime:c,venueIds:l,endTime:u}){if(typeof i!="object"||!Object.keys(i).length)return{error:Fe};s=s||Uu({recoveryMinutes:e,averageMatchUpMinutes:r});const{courts:d,venues:p}=ms({dates:[a],ignoreDisabled:!0,tournamentRecords:i}),v=d.filter(T=>!l||l.includes(T.venueId));c||(c=v.reduce((T,E)=>{var b;const N=(b=E.dateAvailability)==null?void 0:b.find($=>!$.date||kn(a,$.date)),w=(N==null?void 0:N.startTime)||E.startTime;return w&&(!T||Re(w)<Re(T))?w:T},void 0)),u||(u=v.reduce((T,E)=>{var b;const N=(b=E.dateAvailability)==null?void 0:b.find($=>!$.date||kn(a,$.date)),w=(N==null?void 0:N.endTime)||E.endTime;return w&&(!T||Re(w)>Re(T))?w:T},void 0));const f=Object.assign({},...Object.values(i).map(T=>(T.events||[]).map(E=>{const{scheduleTiming:b}=dc({tournamentRecord:T,event:E});return{[E.eventId]:{event:E,scheduleTiming:b}}})).flat()),g=Jv({afterRecoveryTimes:!0,sortDateMatchUps:!1,tournamentRecords:i,matchUpFilters:{scheduledDate:a,venueIds:l}}),h=[].concat(...g.dateMatchUps||[],...g.completedMatchUps||[]),_={averageTimes:[{minutes:{default:r}}],recoveryTimes:[{minutes:{default:e}}]},I=h==null?void 0:h.map(({eventId:T,schedule:E,matchUpFormat:b})=>{const{event:N,scheduleTiming:w}=f[T],$=N==null?void 0:N.eventType,U=MK(CK({},w),{defaultTiming:_,matchUpFormat:b}),{averageMinutes:A,recoveryMinutes:M}=Ql({eventType:$,timingDetails:U}),{courtId:C,venueId:D}=E,F=rt(E.scheduledTime),R=lr(F,A);return{recoveryMinutes:M,averageMinutes:A,periodLength:s,startTime:F,endTime:R,courtId:C,venueId:D}}),P={calculateStartTimeFromCourts:t,remainingScheduleTimes:n,averageMatchUpMinutes:r,date:a,clearScheduleDates:o,periodLength:s,startTime:c,endTime:u,bookings:I,courts:v},{scheduleTimes:O}=uv(P),y=(l==null?void 0:l.length)===1&&l[0]||(p==null?void 0:p.length)===1&&p[0].venueId||void 0,S=h.map(Mt);return{venueId:y,scheduleTimes:O,dateScheduledMatchUpIds:S}}function Zv({matchUpScheduleTimes:t,matchUpDependencies:e,allDateMatchUpIds:r,matchUp:n}){var o;const s=(((o=e==null?void 0:e[n.matchUpId])==null?void 0:o.matchUpIds)||[]).filter(c=>r.includes(c)).filter(c=>!t[c]);return{dependenciesScheduled:!(s!=null&&s.length),remainingDependencies:s}}function Na({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:e,timeAfterRecovery:r,matchUp:n}){var o,i,s,a;const{individualParticipantIds:c}=$u(n);r=r||((o=n.schedule)==null?void 0:o.timeAfterRecovery);const l=v=>{t[v]||(t[v]=[]),t[v]=Ve(t[v].concat(...c))},u=v=>{(!e[v]||r>e[v])&&(e[v]=r)},d=((i=n.winnerTo)==null?void 0:i.matchUpId)||n.winnerMatchUpId;d&&(r&&u(d),l(d));const p=((s=n.loserTo)==null?void 0:s.matchUpId)||n.loserMatchUpId;p&&(r&&u(p),l(p)),(a=n.sidesTo)!=null&&a.length&&n.sidesTo.forEach(({matchUpId:v})=>{v&&(r&&u(v),l(v))})}function nl({individualParticipantProfiles:t,participantId:e}){t[e]||(t[e]={typeChangeTimeAfterRecovery:void 0,timeAfterRecovery:void 0,priorMatchUpType:void 0,potentialRecovery:{},potentialCounted:{},potentialBookings:{},bookings:[],counters:{}})}function DK({individualParticipantProfiles:t,recoveryValue:e,participantId:r,scheduleTime:n,drawId:o}){t[r].potentialRecovery[o]||(t[r].potentialRecovery[o]=[]),t[r].potentialRecovery[o].push(e),t[r].potentialBookings[o]||(t[r].potentialBookings[o]=[]),t[r].potentialBookings[o].push({timeAfterRecovery:e,scheduleTime:n})}function ol({individualParticipantProfiles:t,matchUpPotentialParticipantIds:e,matchUpNotBeforeTimes:r,matchUpDependencies:n,averageMatchUpMinutes:o=0,typeChangeRecoveryMinutes:i,recoveryMinutes:s=0,scheduleTime:a,matchUp:c}){var l,u;const d=rt((l=c==null?void 0:c.schedule)==null?void 0:l.endTime),p=d?lr(d,parseInt(s)):lr(a,parseInt(o)+parseInt(s)),v=i&&(d?lr(rt(d),i):lr(a,parseInt(o)+parseInt(i))),f=((u=n==null?void 0:n[c.matchUpId])==null?void 0:u.participantIds)||[],m=(c.roundPosition&&e[c.matchUpId]||[]).flat();f.forEach(g=>{nl({individualParticipantProfiles:t,participantId:g});const _=t[g].priorMatchUpType!==c.matchUpType&&v||p;m.includes(g)?DK({individualParticipantProfiles:t,drawId:c.drawId,recoveryValue:_,participantId:g,scheduleTime:a}):(t[g].timeAfterRecovery=_,t[g].bookings.push({scheduleTime:a,timeAfterRecovery:_}))}),Na({matchUpPotentialParticipantIds:e,matchUpNotBeforeTimes:r,timeAfterRecovery:p,matchUp:c})}function AT({matchUpScheduleTimes:t,matchUpDependencies:e,scheduleTime:r,matchUpId:n,details:o}){var i,s,a,c,l;let u;const d=(s=(i=o.minutesMap)==null?void 0:i[n])==null?void 0:s.recoveryMinutes,v=(((c=(a=o.minutesMap)==null?void 0:a[n])==null?void 0:c.averageMinutes)||0)+(d||0),f=lr(r,v),m=((l=e==null?void 0:e[n])==null?void 0:l.dependentMatchUpIds)||[];if(m.length){const g=m.reduce((h,_)=>{const I=t[_];if(!I)return h;const P={scheduleTime:I,matchUpId:_};return I&&!h.matchUpId||Re(I)<Re(h.scheduleTime)?P:h},{});g.scheduleTime&&Re(f)>Re(g.scheduleTime)&&(u=g)}return{scheduledDependent:u}}function jK(t){const{sides:e,matchUpType:r}=t||{};return(e||[]).map(n=>{var o;return r===it&&(((o=n==null?void 0:n.participant)==null?void 0:o.individualParticipants)||[])||(n==null?void 0:n.participant)&&[n.participant]||[]}).flat()}const gd="DO_NOT_SCHEDULE";var RK=Object.defineProperty,FK=Object.defineProperties,LK=Object.getOwnPropertyDescriptors,UT=Object.getOwnPropertySymbols,VK=Object.prototype.hasOwnProperty,xK=Object.prototype.propertyIsEnumerable,CT=(t,e,r)=>e in t?RK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,BK=(t,e)=>{for(var r in e||(e={}))VK.call(e,r)&&CT(t,r,e[r]);if(UT)for(var r of UT(e))xK.call(e,r)&&CT(t,r,e[r]);return t},kK=(t,e)=>FK(t,LK(e));function Xv({averageMatchUpMinutes:t=90,requestConflicts:e={},potentials:r=!0,personRequests:n,scheduleTime:o,scheduleDate:i,matchUp:s}){const a=jK(s).map(({person:v})=>v==null?void 0:v.personId);if(r){const v=((s==null?void 0:s.potentialParticipants)||[]).flat().map(({person:f})=>f==null?void 0:f.personId);a.push(...v)}const c=a.map(v=>{var f;return(f=n[v])==null?void 0:f.map(m=>kK(BK({},m),{personId:v}))}).filter(Boolean).flat().filter(v=>v.requestType===gd&&kn(i,v.date)),l=[],u=s==null?void 0:s.matchUpId,d=ht(rt(o),Ce(i)),p=rt(Wp(d,t).toISOString());for(const v of c){const{requestId:f,startTime:m,endTime:g}=v;(o>m&&o<g||p>m&&p<g)&&(l.push({matchUpId:u,request:v,scheduleTime:o}),e[f]?(e[f].scheduleTimes.includes(o)||e[f].scheduleTimes.push(o),e[f].matchUpIds.includes(u)||e[f].matchUpIds.push(u)):e[f]={request:v,scheduleTimes:[o],matchUpIds:[u]})}return{conflicts:l}}function em({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,matchUp:r,value:n}){const{matchUpType:o}=r,{individualParticipantIds:i}=$u(r),a=(t[r.matchUpId]||[]).filter(l=>!Gt(l,i)).flat();[...i,...a].forEach(l=>{if(nl({individualParticipantProfiles:e,participantId:l}),!e[l].potentialCounted[r.drawId]){const u=e[l].counters;u[o]?u[o]+=n:n>0&&(u[o]=n),u[nn]?u[nn]+=n:n>0&&(u[nn]=n),a.includes(l)&&(e[l].potentialCounted[r.drawId]=!0)}})}function GK({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,dateScheduledMatchUpIds:r,greatestAverageMinutes:n,dateScheduledMatchUps:o,matchUpNotBeforeTimes:i,matchUpScheduleTimes:s,matchUpDependencies:a,clearScheduleDates:c,scheduleDate:l,minutesMap:u,matchUps:d}){var p,v;r||(o=d==null?void 0:d.filter(g=>Xc(g)&&(!l||g.schedule.scheduledDate===l)),r=o.map(Mt));const f=Array.isArray(c)?c.includes(l):c,m=f?[]:d.filter(({matchUpId:g})=>r.includes(g));for(const g of m){em({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,scheduleDate:l,matchUp:g,value:1});const h=(p=g.schedule)==null?void 0:p.scheduledTime;if(h){s[g.matchUpId]=h;const _=(v=u==null?void 0:u[g.matchUpId])==null?void 0:v.recoveryMinutes;ol({individualParticipantProfiles:e,matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:i,matchUpDependencies:a,recoveryMinutes:_,averageMatchUpMinutes:n,scheduleDate:l,scheduleTime:h,matchUp:g})}}return{clearDate:f,dateScheduledMatchUpIds:r,dateScheduledMatchUps:o}}function WK({scheduledRoundsDetails:t,greatestAverageMinutes:e,garmanSinglePass:r}){let n,o=[],i,s,a,c=[];for(const l of t.filter(Boolean))n||(n=l.hash),(l.hash===n||r)&&(o=o.concat(l.matchUpIds)),l.hash!==n&&!r&&(n=l.hash,c.push({averageMinutes:i,recoveryMinutes:s,roundPeriodLength:a,matchUpIds:o}),o=l.matchUpIds),i=r?e:l.averageMinutes,s=l.recoveryMinutes,a=l.roundPeriodLength;return o.length&&c.push({averageMinutes:i,recoveryMinutes:s,roundPeriodLength:a,matchUpIds:o}),{groupedRounds:c}}function HK({matchUpPotentialParticipantIds:t,scheduleCompletedMatchUps:e,dateScheduledMatchUpIds:r,matchUpNotBeforeTimes:n,orderedMatchUpIds:o,clearDate:i,matchUps:s}){const a=o.map(l=>s.find(u=>u.matchUpId===l)).filter(Boolean).filter(l=>{const u=!i&&r.includes(l.matchUpId),d=[qe,Be,St,yr,er,Ge,_t,bt].includes(l==null?void 0:l.matchUpStatus);return e||!u&&!l.winningSide&&!d}),{matchUpMap:c}=a.reduce((l,u)=>{const{drawId:d,tournamentId:p}=u;return l.matchUpMap[p]||(l.matchUpMap[p]={}),l.matchUpMap[p][d]?l.matchUpMap[p][d].push(u):l.matchUpMap[p][d]=[u],Na({matchUpPotentialParticipantIds:t,matchUpNotBeforeTimes:n,matchUp:u}),l},{matchUpMap:{}});return{matchUpsToSchedule:a,matchUpMap:c}}var qK=Object.defineProperty,YK=Object.defineProperties,zK=Object.getOwnPropertyDescriptors,MT=Object.getOwnPropertySymbols,KK=Object.prototype.hasOwnProperty,QK=Object.prototype.propertyIsEnumerable,DT=(t,e,r)=>e in t?qK(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,JK=(t,e)=>{for(var r in e||(e={}))KK.call(e,r)&&DT(t,r,e[r]);if(MT)for(var r of MT(e))QK.call(e,r)&&DT(t,r,e[r]);return t},ZK=(t,e)=>YK(t,zK(e));function tm({defaultRecoveryMinutes:t=0,averageMatchUpMinutes:e=90,dateScheduledMatchUps:r,tournamentRecords:n,venueIds:o=[],periodLength:i,scheduleDate:s,matchUps:a}){if(typeof n!="object")return{error:Fe};if(!Array.isArray(a)&&!Array.isArray(r))return{error:Ao};i=i||Uu({recoveryMinutes:t,averageMatchUpMinutes:e});const c=Object.assign({},...Object.values(n).map(p=>(p.events||[]).map(v=>{const{scheduleTiming:f}=dc({tournamentRecord:p,event:v});return{[v.eventId]:{event:v,scheduleTiming:f}}})).flat()),l={averageTimes:[{minutes:{default:e}}],recoveryTimes:[{minutes:{default:t}}]};r||(r=a==null?void 0:a.filter(p=>Xc(p)&&(!s||p.schedule.scheduledDate===s)));const u=r==null?void 0:r.filter(p=>!o.length||o.includes(p.schedule.venueId));return{bookings:u==null?void 0:u.map(({eventId:p,schedule:v,matchUpFormat:f})=>{const{event:m,scheduleTiming:g}=c[p],h=m==null?void 0:m.eventType,_=ZK(JK({},g),{defaultTiming:l,matchUpFormat:f}),{averageMinutes:I,recoveryMinutes:P}=Ql({timingDetails:_,eventType:h}),{courtId:O,venueId:y}=v,S=rt(v.scheduledTime),T=lr(S,I);return{recoveryMinutes:P,averageMinutes:I,periodLength:i,startTime:S,courtId:O,endTime:T,venueId:y}}).filter(Boolean),relevantMatchUps:u,dateScheduledMatchUps:r}}function XK({calculateStartTimeFromCourts:t=!0,remainingScheduleTimes:e,defaultRecoveryMinutes:r,averageMatchUpMinutes:n,clearScheduleDates:o,tournamentRecords:i,tournamentRecord:s,periodLength:a,scheduleDate:c,startTime:l,venueIds:u,matchUps:d,endTime:p}){if(s&&!i&&(i={[s.tournamentId]:s}),typeof i!="object"||!Object.keys(i).length)return{error:Fe};a=a||Uu({recoveryMinutes:r,averageMatchUpMinutes:n});const{courts:v,venues:f}=ms({dates:[c],ignoreDisabled:!0,tournamentRecords:i}),m=v.filter(y=>!u||u.includes(y.venueId));l=l||ma({courts:m,scheduleDate:c,startTime:!0}),p=p||ma({courts:m,scheduleDate:c,endTime:!0});const{bookings:g,dateScheduledMatchUps:h}=tm({defaultRecoveryMinutes:r,averageMatchUpMinutes:n,tournamentRecords:i,scheduleDate:c,periodLength:a,venueIds:u,matchUps:d}),_={calculateStartTimeFromCourts:t,remainingScheduleTimes:e,averageMatchUpMinutes:n,clearScheduleDates:o,date:c,periodLength:a,startTime:l,bookings:g,endTime:p,courts:m},{scheduleTimes:I}=uv(_),P=(u==null?void 0:u.length)===1&&u[0]||(f==null?void 0:f.length)===1&&f[0].venueId||void 0;return{dateScheduledMatchUpIds:h==null?void 0:h.map(Mt),dateScheduledMatchUps:h,scheduleTimes:I,venueId:P}}function jT({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,scheduleCompletedMatchUps:r,containedStructureIds:n,matchUpNotBeforeTimes:o,matchUpScheduleTimes:i,matchUpDependencies:s,clearScheduleDates:a,tournamentRecords:c,periodLength:l,scheduleDate:u,useGarman:d,matchUps:p,courts:v,venues:f}){var m;const g={},h=[],_=[];for(const I of f){const{rounds:P=[],venueId:O}=I,{scheduledRoundsDetails:y,greatestAverageMinutes:S,orderedMatchUpIds:T,minutesMap:E}=zv({scheduleCompletedMatchUps:r,containedStructureIds:n,tournamentRecords:c,periodLength:l,matchUps:p,rounds:P});_.push(...T);const{groupedRounds:b}=WK({scheduledRoundsDetails:y,greatestAverageMinutes:S,garmanSinglePass:!0});let N,w,$=[],U;d&&({scheduleTimes:$,dateScheduledMatchUpIds:N,dateScheduledMatchUps:w}=XK({averageMatchUpMinutes:(m=b[0])==null?void 0:m.averageMinutes,scheduleDate:Ce(u),venueIds:[I.venueId],clearScheduleDates:a,tournamentRecords:c,periodLength:l,matchUps:p})),{clearDate:U,dateScheduledMatchUpIds:N,dateScheduledMatchUps:w}=GK({matchUpPotentialParticipantIds:t,individualParticipantProfiles:e,dateScheduledMatchUpIds:N,greatestAverageMinutes:S,matchUpNotBeforeTimes:o,matchUpScheduleTimes:i,matchUpDependencies:s,clearScheduleDates:a,scheduleDate:u,minutesMap:E,matchUps:p});const{matchUpsToSchedule:A,matchUpMap:M}=HK({matchUpPotentialParticipantIds:t,scheduleCompletedMatchUps:r,dateScheduledMatchUpIds:N,matchUpNotBeforeTimes:o,orderedMatchUpIds:T,clearDate:U,matchUps:p}),C=v.filter(D=>D.venueId===O);g[O]={previousRemainingScheduleTimes:[],courtsCount:C.length,greatestAverageMinutes:S,scheduledRoundsDetails:y,dateScheduledMatchUps:w,matchUpsToSchedule:A,scheduleTimes:$,groupedRounds:b,venueCourts:C,minutesMap:E,matchUpMap:M},a||h.push(...N)}return{allDateScheduledMatchUpIds:h,venueScheduledRoundDetails:g,allDateMatchUpIds:_}}function e8(t,e){const r=Re(t.scheduleTime),n=Re(t.timeAfterRecovery),o=Re(e.scheduleTime),i=Re(e.timeAfterRecovery),s=r===o||n===i,a=r>o&&r<i,c=o>r&&o<n,l=n>o&&n<i,u=i>r&&i<n;return _e({hasOverlap:s||a||l||c||u,startAisContained:a,endAisContained:l,startBisContained:c,endBisContained:u},!0)}function rm({individualParticipantProfiles:t,matchUpNotBeforeTimes:e,matchUpDependencies:r,scheduleTime:n,matchUp:o,details:i}){var s,a,c,l,u;const d=(((s=r==null?void 0:r[o.matchUpId])==null?void 0:s.participantIds)||[]).flat(),p=((c=(a=i==null?void 0:i.minutesMap)==null?void 0:a[o.matchUpId])==null?void 0:c.averageMinutes)||0,v=((u=(l=i==null?void 0:i.minutesMap)==null?void 0:l[o.matchUpId])==null?void 0:u.recoveryMinutes)||0,f=d.every(I=>{var P;nl({individualParticipantProfiles:t,participantId:I});let O=t[I];if(!O.timeAfterRecovery)return!0;const y=rt((P=o==null?void 0:o.schedule)==null?void 0:P.endTime),S=y?lr(y,parseInt(v)):lr(n,parseInt(p)+parseInt(v));return!!![...Object.keys(O.potentialBookings).filter(N=>N!==o.drawId).map(N=>O.potentialBookings[N]).flat(),...O.bookings].find(N=>e8({scheduleTime:n,timeAfterRecovery:S},N).hasOverlap)}),m=e[o.matchUpId],h=(m?nc(ht(m),ht(n),!1):0)>=0;return{enoughTime:f&&h}}function nm({individualParticipantProfiles:t,matchUpPotentialParticipantIds:e,matchUpDailyLimits:r={},matchUp:n}){const{matchUpId:o,matchUpType:i}=n,{enteredIndividualParticipantIds:s}=$u(n),a=(n.roundPosition&&e[o]||[]).flat(),c=Ve(s.concat(...a));return c.forEach(u=>{nl({individualParticipantProfiles:t,participantId:u})}),{participantIdsAtLimit:c.filter(u=>{const d=t[u];if(d)return[i,nn].find(p=>{var v;const f=((v=d.counters)==null?void 0:v[p])||0,m=r[p]||0;return f&&m&&f>=m})}),relevantParticipantIds:c}}const t8="deleteDrawDefinitions",r8="autoSchedulingAudit",RT="deleteEvents";function FT({autoSchedulingAudit:t,tournamentRecords:e}){var r;xe({topic:pc,payload:t});const n=a=>a?Object.values(a).reduce((l,u)=>l+u.length||0,0):0,o=((t==null?void 0:t.schedulingProfile)||[]).reduce((a,c)=>a+c.venues.reduce((l,u)=>l+u.rounds.length,0),0),i={scheduledDatesCount:(r=t.scheduledDates)==null?void 0:r.length,noTimeMatchUpIdsCount:n(t==null?void 0:t.noTimeMatchUpIds),scheduledMatchUpIdsCount:n(t==null?void 0:t.scheduledMatchUpIds),overLimitMatchUpIdsCount:n(t==null?void 0:t.overLimitMatchUpIds),requestConflictsCount:n(t==null?void 0:t.requestConflicts),profileRoundsCount:o},s={itemType:r8,itemValue:i};for(const a of Object.values(e))bo({tournamentRecord:a,timeItem:s})}var n8=Object.defineProperty,o8=Object.defineProperties,i8=Object.getOwnPropertyDescriptors,LT=Object.getOwnPropertySymbols,s8=Object.prototype.hasOwnProperty,a8=Object.prototype.propertyIsEnumerable,VT=(t,e,r)=>e in t?n8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,c8=(t,e)=>{for(var r in e||(e={}))s8.call(e,r)&&VT(t,r,e[r]);if(LT)for(var r of LT(e))a8.call(e,r)&&VT(t,r,e[r]);return t},l8=(t,e)=>o8(t,i8(e));function u8({schedulingProfileModifications:t,checkPotentialRequestConflicts:e,scheduleCompletedMatchUps:r,schedulingProfileIssues:n,dateSchedulingProfiles:o,containedStructureIds:i,matchUpDependencies:s,matchUpDailyLimits:a,clearScheduleDates:c,schedulingProfile:l,tournamentRecords:u,personRequests:d,periodLength:p,matchUps:v,courts:f,dryRun:m}){var g,h,_,I,P,O,y;const S={},T={},E={},b={},N={},w={},$={},U={},A={},M={};for(const F of o){const R=Ce(F==null?void 0:F.scheduleDate),G=(F==null?void 0:F.venues)||[],x={},z={},j=(Y,J)=>{Y.forEach(te=>{const ne=z[te].counters;ne[J]?ne[J]+=1:ne[J]=1,ne[nn]?ne[nn]+=1:ne[nn]=1})};E[R]={},b[R]={},S[R]={},T[R]={},$[R]=[],U[R]=[],A[R]=[],M[R]=[];const V={};v.forEach(Y=>{var J;(J=Y.schedule)!=null&&J.scheduledDate&&kn(R,Ce(Y.schedule.scheduledDate))&&Na({matchUpPotentialParticipantIds:x,matchUpNotBeforeTimes:V,matchUp:Y})});const{venueScheduledRoundDetails:L,allDateMatchUpIds:q}=jT({matchUpPotentialParticipantIds:x,individualParticipantProfiles:z,scheduleCompletedMatchUps:r,containedStructureIds:i,matchUpNotBeforeTimes:V,matchUpScheduleTimes:w,matchUpDependencies:s,clearScheduleDates:c,tournamentRecords:u,useGarman:!0,periodLength:p,scheduleDate:R,matchUps:v,courts:f,venues:G}),k=10;let H,Q=0,K=10;for(;!H;){for(const{venueId:Y}of G){let J=0;const te=L[Y];for(;te.courtsCount&&((g=te.scheduleTimes)!=null&&g.length)&&((h=te.matchUpsToSchedule)!=null&&h.length)&&J<=te.courtsCount;){const{scheduleTime:ne,attempts:oe=0}=te.scheduleTimes.shift(),se=te.matchUpsToSchedule.find(ve=>{var X,ie;const{matchUpId:fe,matchUpType:$e}=ve,{participantIdsAtLimit:re,relevantParticipantIds:ae}=nm({matchUpPotentialParticipantIds:x,individualParticipantProfiles:z,matchUpDailyLimits:a,matchUp:ve});if(re.length)return U[R].includes(fe)||U[R].push(fe),!1;const{scheduledDependent:me}=AT({matchUpScheduleTimes:w,matchUpDependencies:s,scheduleTime:ne,matchUpId:fe,details:te});if(me)return!1;const{dependenciesScheduled:Se,remainingDependencies:ce}=Zv({matchUpScheduleTimes:w,matchUpDependencies:s,allDateMatchUpIds:q,matchUps:v,matchUp:ve});if(!Se)return b[R][fe]||(b[R][fe]=[]),b[R][fe].push({scheduleTime:ne,remainingDependencies:ce}),!1;const{enoughTime:Pe}=rm({individualParticipantProfiles:z,matchUpNotBeforeTimes:V,matchUpDependencies:s,scheduleTime:ne,details:te,matchUp:ve});if(!Pe)return E[R][fe]||(E[R][fe]=[]),E[R][fe].push({scheduleTime:ne}),!1;const Ae=te.greatestAverageMinutes,{conflicts:ye}=Xv({potentials:e,averageMatchUpMinutes:Ae,requestConflicts:M,personRequests:d,scheduleTime:ne,scheduleDate:R,matchUp:ve});if(ye!=null&&ye.length)return N[R]||(N[R]=[]),N[R].push(...ye),!1;j(ae,$e);const Ue=(ie=(X=te.minutesMap)==null?void 0:X[fe])==null?void 0:ie.recoveryMinutes;return ol({matchUpPotentialParticipantIds:x,individualParticipantProfiles:z,matchUpNotBeforeTimes:V,averageMatchUpMinutes:Ae,matchUpDependencies:s,recoveryMinutes:Ue,scheduleDate:R,scheduleTime:ne,matchUp:ve}),w[fe]=ne,!0});te.matchUpsToSchedule=te.matchUpsToSchedule.filter(({matchUpId:ve})=>ve!==(se==null?void 0:se.matchUpId)),se?J+=1:(T[R][Y]||(T[R][Y]=[]),T[R][Y].push({scheduleTime:ne,attempts:oe+1}))}(_=te.matchUpsToSchedule)!=null&&_.length&&(T[R][Y]=(I=T[R][Y])==null?void 0:I.filter(ne=>{const oe=ne.attempts<K;return oe&&te.scheduleTimes.push(ne),!oe})),(!((P=te.scheduleTimes)!=null&&P.length)||!((O=te.matchUpsToSchedule)!=null&&O.length))&&(te.complete=!0)}Q+=1,H=G.every(({venueId:Y})=>L[Y].complete)||Q===k}for(const{venueId:Y}of G){const J=L[Y].matchUpMap;Object.keys(J).forEach(te=>{const ne=u[te];ne&&Object.keys(J[te]).forEach(oe=>{const{drawDefinition:se}=Fo({tournamentRecord:ne,drawId:oe});se&&J[te][oe].forEach(({matchUpId:X})=>{const ie=w[X];if(ie){const fe=ie.split(":").map(Bn).join(":"),$e=`${Ce(R)}T${fe}`;m?$[R].push(X):(Ti({drawDefinition:se,scheduledTime:$e,matchUpId:X}).success&&$[R].push(X),Y&&ha({tournamentRecord:ne,drawDefinition:se,matchUpId:X,venueId:Y}))}})})}),A[R]=L[Y].matchUpsToSchedule.map(Mt),S[R][Y]=L[Y].scheduleTimes.sort((te,ne)=>Re(te.scheduleTime)-Re(ne.scheduleTime))}for(const Y of F.venues)for(const J of Y.rounds){const ne=(((y=J.matchUps)==null?void 0:y.map(({matchUpId:se})=>se))||[]).filter(se=>$[R].includes(se));J.canScheduledMatchUpIds=ne;let oe=Math.round(ne.length/J.matchUpsCount*1e4)/100;(oe===1/0||isNaN(oe))&&(oe=0),J.possibleToSchedulePct=oe,J.matchUpsCount===ne.length&&(J.possibleToSchedule=!0)}}const C=o.map(({scheduleDate:F})=>F),D={timeStamp:Date.now(),overLimitMatchUpIds:U,scheduledMatchUpIds:$,schedulingProfile:l,noTimeMatchUpIds:A,requestConflicts:M,scheduledDates:C};return FT({tournamentRecords:u,autoSchedulingAudit:D}),l8(c8({},B),{schedulingProfileModifications:t,schedulingProfileIssues:n,scheduleTimesRemaining:S,dateSchedulingProfiles:o,skippedScheduleTimes:T,recoveryTimeDeferredMatchUpIds:E,dependencyDeferredMatchUpIds:b,matchUpScheduleTimes:w,overLimitMatchUpIds:U,scheduledMatchUpIds:$,noTimeMatchUpIds:A,requestConflicts:M,scheduledDates:C})}function xT({averageMinutes:t,startTime:e,endTime:r,court:n,date:o}){if(!Array.isArray(n.dateAvailability))return{error:Oe,stack:"getEarliestCourtTime"};const i=ma({scheduleDate:o,courts:[n],startTime:!0}),s=ma({scheduleDate:o,courts:[n],endTime:!0});e=e||i,r=r||s;const a=xc({court:n,date:o}),c=va({courtDate:a}),l=ht(e),u=ht(r);return{earliestCourtTime:c.reduce((p,v)=>{const f=ht(v.startTime),m=ht(v.endTime);if(f>u||m<l)return p;const g=l>f?l:f;if(nc(g,m)>=t){const I=rt(g.toISOString());(!p||I<p)&&(p=I)}return p},void 0),courtStartTime:i,courtEndTime:s}}var d8=Object.defineProperty,p8=Object.defineProperties,f8=Object.getOwnPropertyDescriptors,BT=Object.getOwnPropertySymbols,v8=Object.prototype.hasOwnProperty,m8=Object.prototype.propertyIsEnumerable,kT=(t,e,r)=>e in t?d8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,g8=(t,e)=>{for(var r in e||(e={}))v8.call(e,r)&&kT(t,r,e[r]);if(BT)for(var r of BT(e))m8.call(e,r)&&kT(t,r,e[r]);return t},h8=(t,e)=>p8(t,f8(e));function _8({schedulingProfileModifications:t,checkPotentialRequestConflicts:e,scheduleCompletedMatchUps:r,schedulingProfileIssues:n,dateSchedulingProfiles:o,containedStructureIds:i,matchUpDependencies:s,matchUpDailyLimits:a,clearScheduleDates:c,tournamentRecords:l,periodLength:u=30,schedulingProfile:d,personRequests:p,matchUps:v,courts:f,dryRun:m}){var g;const h={},_={},I={},P={},O={},y={},S={},T={},E={};for(const w of o){const $=Ce(w==null?void 0:w.scheduleDate),U=(w==null?void 0:w.venues)||[],A={},M={},C=(K,Y)=>{K.forEach(J=>{const te=M[J].counters;te[Y]?te[Y]+=1:te[Y]=1,te[nn]?te[nn]+=1:te[nn]=1})};h[$]={},_[$]={},y[$]=[],S[$]=[],T[$]=[],E[$]=[];const D={};v.forEach(K=>{var Y;(Y=K.schedule)!=null&&Y.scheduledDate&&kn($,Ce(K.schedule.scheduledDate))&&Na({matchUpPotentialParticipantIds:A,matchUpNotBeforeTimes:D,matchUp:K})});const{allDateScheduledMatchUpIds:F,venueScheduledRoundDetails:R,allDateMatchUpIds:G}=jT({matchUpPotentialParticipantIds:A,individualParticipantProfiles:M,scheduleCompletedMatchUps:r,containedStructureIds:i,matchUpNotBeforeTimes:D,matchUpScheduleTimes:O,matchUpDependencies:s,clearScheduleDates:c,tournamentRecords:l,periodLength:u,scheduleDate:$,matchUps:v,courts:f,venues:U}),x=v.filter(({matchUpId:K})=>F.includes(K)),{bookings:z}=tm({dateScheduledMatchUps:x,tournamentRecords:l,scheduleDate:$,periodLength:u}),{virtualCourts:j}=lv({scheduleDate:$,periodLength:u,bookings:z,courts:f}),V=j.reduce((K,Y)=>{const{earliestCourtTime:J,courtEndTime:te}=xT({date:$,averageMinutes:0,court:Y});return(!K.startTime||ht(J)<ht(K.startTime))&&(K.startTime=J),(!K.endTime||ht(te)>ht(K.endTime))&&(K.endTime=te),K},{});let L=V.startTime;const q=({courtId:K,booking:Y})=>{var J;return(J=j.find(te=>te.courtId===K))==null?void 0:J.dateAvailability[0].bookings.push(Y)},k=10;let H=0,Q;for(;!Q;){for(const{venueId:K}of U){const Y=R[K],J=Y.matchUpsToSchedule.length,te=[],ne=[];let oe,se=0;for(;!oe;){for(const ve of Y.matchUpsToSchedule){if(ne.length===Y.courtsCount||te.length===Y.courtsCount){oe=!0;break}const{matchUpId:X,matchUpType:ie}=ve,{participantIdsAtLimit:fe,relevantParticipantIds:$e}=nm({matchUpPotentialParticipantIds:A,individualParticipantProfiles:M,matchUpDailyLimits:a,matchUp:ve});if(fe.length){S[$].includes(X)||S[$].push(X);continue}const{dependenciesScheduled:re,remainingDependencies:ae}=Zv({matchUpScheduleTimes:O,matchUpDependencies:s,allDateMatchUpIds:G,matchUps:v,matchUp:ve});if(!re){_[$][X]||(_[$][X]=[]),_[$][X].push({remainingDependencies:ae});continue}const me=[],Se=j.reduce((ce,Pe)=>{var Ae,ye,Ue,be;if(ne.includes(Pe.courtId))return ce;const{earliestCourtTime:ge}=xT({averageMinutes:Y.greatestAverageMinutes,startTime:L,date:$,court:Pe});if(ce.scheduleTime&&Re(ge)>=Re(ce.scheduleTime))return ce;const{scheduledDependent:Ne}=AT({matchUpScheduleTimes:O,matchUpDependencies:s,scheduleTime:ge,matchUpId:X,details:Y});if(Ne)return ce;const{enoughTime:De}=rm({individualParticipantProfiles:M,matchUpNotBeforeTimes:D,matchUpDependencies:s,scheduleTime:ge,details:Y,matchUp:ve});if(!De)return h[$][X]||(h[$][X]=[]),h[$][X].includes(ge)||h[$][X].push(ge),ce;const he=((ye=(Ae=Y.minutesMap)==null?void 0:Ae[X])==null?void 0:ye.averageMinutes)||Y.greatestAverageMinutes,{conflicts:ke}=Xv({potentials:e,averageMatchUpMinutes:he,requestConflicts:E,personRequests:p,scheduleTime:ge,scheduleDate:$,matchUp:ve});if(ke!=null&&ke.length)return me.push(...ke),!1;C($e,ie);const je=(be=(Ue=Y.minutesMap)==null?void 0:Ue[X])==null?void 0:be.recoveryMinutes;return ol({matchUpPotentialParticipantIds:A,individualParticipantProfiles:M,matchUpNotBeforeTimes:D,averageMatchUpMinutes:he,matchUpDependencies:s,recoveryMinutes:je,scheduleDate:$,scheduleTime:ge,matchUp:ve}),(!ce.scheduleTime||Re(ge)<Re(ce.scheduleTime))&&(ce.averageMatchUpMinutes=he,ce.recoveryMinutes=je,ce.scheduleTime=ge,ce.courtName=Pe.courtName,ce.courtId=Pe.courtId),ce},{});if(Se.scheduleTime){const{averageMatchUpMinutes:ce,recoveryMinutes:Pe,scheduleTime:Ae,courtId:ye}=Se;O[X]=Ae,P[X]=ye,te.push(X),ne.push(ye);const Ue=Ae,be=lr(Ue,ce);q({courtId:ye,booking:{averageMatchUpMinutes:ce,recoveryMinutes:Pe,periodLength:u,matchUpId:X,startTime:Ue,courtId:ye,endTime:be,venueId:K}}),Y.matchUpsToSchedule=Y.matchUpsToSchedule.filter(Ne=>Ne.matchUpId!==X)}else me!=null&&me.length&&(I[$]||(I[$]=[]),I[$].push(...me))}(ne.length===Y.courtsCount||te.length===Y.courtsCount||!Y.matchUpsToSchedule.length)&&(oe=!0),Y.matchUpsToSchedule.length&&te<Y.courtsCount&&(ht(L)<ht(V.endTime)?L=lr(L,u):(oe=!0,Y.complete=!0)),se+=1,!oe&&se>=J&&(oe=!0)}(g=Y.matchUpsToSchedule)!=null&&g.length||(Y.complete=!0)}H+=1,Q=U.every(({venueId:K})=>R[K].complete)||H===k}for(const{venueId:K}of U){const Y=R[K].matchUpMap;Object.keys(Y).forEach(J=>{const te=l[J];te&&Object.keys(Y[J]).forEach(ne=>{const{drawDefinition:oe}=Fo({tournamentRecord:te,drawId:ne});oe&&Y[J][ne].forEach(({matchUpId:ve})=>{const X=O[ve],ie=P[ve];if(X){const fe=X.split(":").map(Bn).join(":"),$e=`${Ce($)}T${fe}`;m||(Ti({drawDefinition:oe,scheduledTime:$e,matchUpId:ve}),gs({courtDayDate:$,tournamentRecords:l,tournamentRecord:te,drawDefinition:oe,matchUpId:ve,courtId:ie})),y[$].push(ve)}})})}),T[$]=R[K].matchUpsToSchedule.map(Mt)}for(const K of w.venues)for(const Y of K.rounds){const te=Y.matchUps.map(({matchUpId:oe})=>oe).filter(oe=>y[$].includes(oe));Y.canScheduledMatchUpIds=te;let ne=Math.round(te.length/Y.matchUpsCount*1e4)/100;(ne===1/0||isNaN(ne))&&(ne=0),Y.possibleToSchedulePct=ne,Y.matchUpsCount===te.length&&(Y.possibleToSchedule=!0)}}const b=o.map(({scheduleDate:w})=>w),N={timeStamp:Date.now(),overLimitMatchUpIds:S,scheduledMatchUpIds:y,schedulingProfile:d,noTimeMatchUpIds:T,requestConflicts:E,scheduledDates:b};return FT({tournamentRecords:l,autoSchedulingAudit:N}),h8(g8({},B),{schedulingProfileModifications:t,schedulingProfileIssues:n,dateSchedulingProfiles:o,recoveryTimeDeferredMatchUpIds:h,dependencyDeferredMatchUpIds:_,matchUpScheduleTimes:O,overLimitMatchUpIds:S,scheduledMatchUpIds:y,noTimeMatchUpIds:T,requestConflicts:E,scheduledDates:b})}var I8=Object.defineProperty,GT=Object.getOwnPropertySymbols,P8=Object.prototype.hasOwnProperty,y8=Object.prototype.propertyIsEnumerable,WT=(t,e,r)=>e in t?I8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,S8=(t,e)=>{for(var r in e||(e={}))P8.call(e,r)&&WT(t,r,e[r]);if(GT)for(var r of GT(e))y8.call(e,r)&&WT(t,r,e[r]);return t};function Aa({tournamentRecords:t,requestType:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const r={};for(const n of Object.values(t)){const{extension:o}=Sr({name:Ks,tournamentRecord:n}),i=(o==null?void 0:o.value)||[];for(const s of i){const{personId:a,requests:c}=s||{};r[a]||(r[a]=[]);for(const l of c)e&&l.requestType!==e||r[a].push(l)}}return{personRequests:r}}function om({tournamentRecords:t,personRequests:e}){if(!t)return{error:Fe};for(const r of Object.values(t)){const{participants:n}=r,o=[];for(const i of Object.keys(e))if(vo({tournamentParticipants:n,personId:i})){const s=e[i];s.length&&o.push({personId:i,requests:s})}Object.keys(o).length&&pi({tournamentRecord:r,extension:{name:Ks,value:o}})}return S8({},B)}function O8({tournamentRecords:t,personId:e,requests:r}){if(!t)return{error:Fe};if(typeof e!="string")return{error:Z};if(!Array.isArray(r))return{error:Z};const{personRequests:n}=Aa({tournamentRecords:t}),{mergeCount:o}=HT({personRequests:n,personId:e,requests:r});return o?om({tournamentRecords:t,personRequests:n}):{error:Z}}function HT({personRequests:t,personId:e,requests:r}){t[e]||(t[e]=[]);const n=r.filter(({requestType:o})=>o).map(o=>{let{date:i,requestType:s,startTime:a,endTime:c}=o;return s===gd&&(i=Ce(i),a=rt(a),c=rt(c),i&&a&&c)?{date:i,startTime:a,endTime:c,requestType:s}:o}).filter(Boolean);for(const o of n)o.requestId=t_(),t[e].push(o);return{mergeCount:n.length}}function b8({tournamentRecords:t,requestType:e,requestId:r,personId:n,date:o}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const{personRequests:i}=Aa({tournamentRecords:t}),s=c=>{i[c]=i[c].filter(l=>(!e||l.requestType!==e)&&(!r||l.requestId!==r)&&(!o||l.date!==o)),i[c].length||delete i[c]},a=!e&&!r&&!n&&!o;if(!a)if(n&&i[n])s(n);else for(const c of Object.keys(i))s(c);return a||!Object.keys(i).length?Xl({tournamentRecords:t,name:Ks}):om({tournamentRecords:t,personRequests:i})}function T8({tournamentRecords:t,requests:e,personId:r}){if(!t)return{error:Fe};if(!Array.isArray(e))return{error:Z};const n=e.map(({requestId:a})=>a).filter(Boolean),{personRequests:o}=Aa({tournamentRecords:t}),i=a=>{o[a]=o[a].map(c=>{if(!n.includes(c.requestId))return c;const l=e.find(u=>u.requestId===c.requestId);if(l.requestType)return Object.assign(c,l)}).filter(Boolean)};if(r&&o[r])i(r);else for(const a of Object.keys(o))i(a);const s=e.filter(a=>!a.requestId);return s.length&&HT({personRequests:o,personId:r,requests:s}),om({tournamentRecords:t,personRequests:o})}var E8=Object.defineProperty,w8=Object.defineProperties,$8=Object.getOwnPropertyDescriptors,qT=Object.getOwnPropertySymbols,N8=Object.prototype.hasOwnProperty,A8=Object.prototype.propertyIsEnumerable,YT=(t,e,r)=>e in t?E8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,U8=(t,e)=>{for(var r in e||(e={}))N8.call(e,r)&&YT(t,r,e[r]);if(qT)for(var r of qT(e))A8.call(e,r)&&YT(t,r,e[r]);return t},C8=(t,e)=>w8(t,$8(e));function im({scheduleAttributes:t=["scheduledDate","scheduledTime"],ignoreMatchUpStatuses:e=Lt,tournamentRecord:r,scheduledDates:n,venueIds:o=[]}){if(typeof r!="object")return{error:ee};if(!Array.isArray(e)||!Array.isArray(o))return{error:Z};o.length&&t.push("venueId");const{matchUps:i}=Bt({matchUpFilters:{scheduledDates:n},tournamentRecord:r}),s=i.filter(l=>!e.includes(l.matchUpStatus)&&Xc({schedule:l.schedule,scheduleAttributes:t})&&(!(o!=null&&o.length)||o.includes(l.schedule.venueId))).map(Mt),{matchUps:a}=Bt({tournamentRecord:r,inContext:!1});let c=0;for(const l of a)s.includes(l.matchUpId)&&(l.timeItems=(l.timeItems||[]).filter(u=>![Vo,Xi,vc,mc,gc].includes(u==null?void 0:u.itemType)),c+=1);return C8(U8({},B),{clearedScheduleCount:c})}var M8=Object.defineProperty,zT=Object.getOwnPropertySymbols,D8=Object.prototype.hasOwnProperty,j8=Object.prototype.propertyIsEnumerable,KT=(t,e,r)=>e in t?M8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,R8=(t,e)=>{for(var r in e||(e={}))D8.call(e,r)&&KT(t,r,e[r]);if(zT)for(var r of zT(e))j8.call(e,r)&&KT(t,r,e[r]);return t};function QT({scheduleAttributes:t=["scheduledDate","scheduledTime"],ignoreMatchUpStatuses:e=Lt,tournamentRecords:r,scheduledDates:n,venueIds:o}){const i=Li(r)&&Object.values(r).map(({tournamentId:s})=>s).filter(Boolean);if(!(i!=null&&i.length))return{error:Fe};for(const s of i){const a=r[s],c=im({ignoreMatchUpStatuses:e,scheduleAttributes:t,tournamentRecord:a,scheduledDates:n,venueIds:o});if(c.error)return c}return R8({},B)}function JT({tournamentRecord:t}){var e;if(!t)return{error:ee};const{policy:r}=qi({policyType:Jp,tournamentRecord:t}),{extension:n}=Sr({tournamentRecord:t,name:Gi}),o=(e=n==null?void 0:n.value)==null?void 0:e.dailyLimits,i=r==null?void 0:r.defaultDailyLimits;return{matchUpDailyLimits:o||i}}function ZT({tournamentRecords:t,tournamentId:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};const r=Object.keys(t).filter(o=>!e||o===e);let n;return r.forEach(o=>{const i=t[o],{matchUpDailyLimits:s}=JT({tournamentRecord:i});n=s}),{matchUpDailyLimits:n}}function sm({checkPotentialRequestConflicts:t=!0,scheduleCompletedMatchUps:e,clearScheduleDates:r,scheduleDates:n=[],tournamentRecords:o,periodLength:i,dryRun:s,pro:a}){if(!o)return{error:Fe};if(!Array.isArray(n))return{error:Z};const c=$a({tournamentRecords:o});if(c.error)return c;const{schedulingProfile:l=[],issues:u=[],modifications:d}=c,p=Object.assign({},...Object.values(o).map(y=>_a({tournamentRecord:y}).containedStructures)),v=n.map(y=>{if(Nr(y))return Ce(y)}).filter(Boolean),f=l.map(y=>y.scheduleDate).map(y=>Nr(y)&&Ce(y)).filter(y=>y&&(!n.length||v.includes(y)));if(!f.length)return{error:wF};if(r&&!s){const y=Array.isArray(r)?r:void 0;QT({tournamentRecords:o,scheduledDates:y})}const{courts:m}=ms({dates:n,ignoreDisabled:!0,tournamentRecords:o}),{matchUps:g}=Oo({matchUpFilters:{matchUpTypes:[pt,it]},afterRecoveryTimes:!0,nextMatchUps:!0,tournamentRecords:o}),{matchUpDependencies:h}=Yr({includeParticipantDependencies:!0,tournamentRecords:o,matchUps:g}),{matchUpDailyLimits:_}=ZT({tournamentRecords:o}),{personRequests:I}=Aa({requestType:gd,tournamentRecords:o}),P=l.filter(y=>{const S=Ce(y==null?void 0:y.scheduleDate);return f.includes(S)}).sort((y,S)=>new Date(y.scheduleDate).getTime()-new Date(S.scheduleDate).getTime()),O={schedulingProfileModifications:d,checkPotentialRequestConflicts:t,scheduleCompletedMatchUps:e,schedulingProfileIssues:u,dateSchedulingProfiles:P,containedStructureIds:p,matchUpDependencies:h,matchUpDailyLimits:_,clearScheduleDates:r,tournamentRecords:o,schedulingProfile:l,personRequests:I,periodLength:i,matchUps:g,dryRun:s,courts:m};return a?_8(O):u8(O)}function XT({event:t}){return t?Jl({event:t,name:En}):{error:Le}}function F8({tournamentRecords:t,eventId:e}){if(!t)return{error:Fe};if(typeof e!="string")return{error:Oe,info:"missing eventId"};for(const r of Object.values(t)){const{event:n}=xt({tournamentRecord:r,eventId:e});if(n)return XT({event:n})}return{error:Ir}}function L8(t){Object.assign(t,{inContext:!0});const{matchUp:e,error:r}=il(t);return{matchUp:ue(e,!0,!0),error:r}}function il({participantsProfile:t,afterRecoveryTimes:e,tournamentRecord:r,contextContent:n,contextProfile:o,drawDefinition:i,nextMatchUps:s,matchUpId:a,inContext:c,eventId:l,drawId:u,event:d}){if(!r)return{error:ee};if(typeof a!="string")return{error:Ut};if(!i||!d){const{matchUps:g}=Bt({tournamentRecord:r}),h=g.find(_=>_.matchUpId===a);if(!h)return{error:kr};({eventId:l,drawId:u}=h),{event:d,drawDefinition:i}=xt({tournamentRecord:r,eventId:l,drawId:u})}if(!i)return{error:_n};o&&!n&&(n=fo({tournamentRecord:r,contextProfile:o}));const p={surfaceCategory:(d==null?void 0:d.surfaceCategory)||r.surfaceCategory,indoorOutDoor:(d==null?void 0:d.indoorOutDoor)||r.indoorOutDoor,endDate:(d==null?void 0:d.endDate)||r.endDate,tournamentId:r.tournamentId,eventId:d.eventId,drawId:u},{participants:v=[]}=fs({participantsProfile:t,tournamentRecord:r,contextProfile:o,inContext:c}),{matchUp:f,structure:m}=nt({context:c&&p,tournamentParticipants:v,afterRecoveryTimes:e,contextContent:n,drawDefinition:i,contextProfile:o,nextMatchUps:s,matchUpId:a,inContext:c,event:d});return{matchUp:f,structure:m,drawDefinition:i}}function am({tournamentParticipants:t,tournamentRecord:e,drawDefinition:r,participantId:n,matchUpId:o,matchUp:i,event:s}){if(!n)return{error:yt};if(!o)return{error:$r};if(t=t||(e==null?void 0:e.participants),t!=null&&t.length){if(!i){const d=nt({tournamentParticipants:t,inContext:!0,drawDefinition:r,matchUpId:o,event:s});if(!d.matchUp)return{error:kr};i=d.matchUp}const c=Mc({matchUp:i});if(c.error)return c;const{checkedInParticipantIds:l,allRelevantParticipantIds:u}=c;if(!u.includes(n))return{error:co};if(l.includes(n))return{error:Uh}}return hr({tournamentRecord:e,drawDefinition:r,matchUpId:o,timeItem:{itemType:Pf,itemValue:n}})}function cm({tournamentParticipants:t,tournamentRecord:e,drawDefinition:r,participantId:n,matchUpId:o,matchUp:i,event:s}){if(!n)return{error:yt};if(!o&&!i)return{error:Ut};if(t=t||(e==null?void 0:e.participants),!i){const u=nt({tournamentParticipants:t,inContext:!0,drawDefinition:r,matchUpId:o,event:s});if(u.error)return u;i=u.matchUp}const{matchUpStatus:a,score:c}=i;if(p_.includes(a)||Lt.includes(a)||Dt({score:c}))return{error:uF};if(t!=null&&t.length){const{checkedInParticipantIds:u,allRelevantParticipantIds:d}=Mc({matchUp:i});if(!d.includes(n))return{error:co};if(!u.includes(n))return{error:LF};const{sideParticipantIds:p,nestedIndividualParticipantIds:v}=Rf({matchUp:i}),f=p.indexOf(n);[0,1].includes(f)&&(v[f]||[]).forEach(m=>{hr({drawDefinition:r,matchUpId:o,timeItem:{itemType:yf,itemValue:m}})})}return hr({tournamentRecord:e,drawDefinition:r,matchUpId:o,timeItem:{itemType:yf,itemValue:n}})}function eE(t){if(!(t!=null&&t.tournamentRecord))return{error:ee};const{tournamentRecord:e,participantId:r,matchUpId:n,drawDefinition:o,event:i}=t,s=e.participants||[],a=il({tournamentRecord:e,inContext:!0,drawDefinition:o,matchUpId:n,event:i});if(!a.matchUp)return{error:kr};const c=a.matchUp,{checkedInParticipantIds:l=[]}=Mc({matchUp:c});return l.includes(r)?cm({tournamentParticipants:s,tournamentRecord:e,drawDefinition:o,participantId:r,matchUpId:n,matchUp:c}):am({tournamentParticipants:s,tournamentRecord:e,drawDefinition:o,participantId:r,matchUpId:n,matchUp:c})}function V8(t){const{tournamentRecords:e}=t,{participantId:r,tournamentId:n,matchUpId:o,drawId:i}=t;if(!e||!n||!r||!o)return{error:Oe,stack:"toggleParticipantCheckInState"};const s=e[n],{drawDefinition:a,event:c}=Fo({tournamentRecord:s,drawId:i});return Object.assign(t,{drawDefinition:a,event:c,tournamentRecord:s}),eE(t)}function tE(t){const{tournamentRecords:e}=t;if(!e)return{error:Fe};const{removePriorValues:r,tournamentId:n,courtDayDate:o,matchUpId:i,courtId:s,drawId:a}=t,c=e[n];if(!c)return{error:ee};const{drawDefinition:l,event:u}=Fo({tournamentRecord:c,drawId:a}),d=nt({drawDefinition:l,event:u,matchUpId:i});if(d.error)return d;if(d.matchUp.matchUpType===Zr){const{itemValue:p}=vi({timeItems:d.matchUp.timeItems||[],itemType:Vo}),v=s&&p.filter(m=>m.courtId!==s);return hr({duplicateValues:!1,removePriorValues:r,tournamentRecord:c,drawDefinition:l,matchUpId:i,timeItem:{itemType:Vo,itemValue:v}})}else return gs({tournamentRecord:c,drawDefinition:l,courtDayDate:o,courtId:"",matchUpId:i})}function x8({tournamentRecords:t}){return uT({extensionName:Gi,tournamentRecords:t})}var B8=Object.defineProperty,k8=Object.defineProperties,G8=Object.getOwnPropertyDescriptors,rE=Object.getOwnPropertySymbols,W8=Object.prototype.hasOwnProperty,H8=Object.prototype.propertyIsEnumerable,nE=(t,e,r)=>e in t?B8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ss=(t,e)=>{for(var r in e||(e={}))W8.call(e,r)&&nE(t,r,e[r]);if(rE)for(var r of rE(e))H8.call(e,r)&&nE(t,r,e[r]);return t},hd=(t,e)=>k8(t,G8(e));const{stageOrder:oE}=Tk;function lm({schedulingProfile:t,tournamentRecords:e,tournamentRecord:r,withRoundId:n}){if(r&&!e){if(typeof r!="object")return{error:bl};e={[r.tournamentId]:r}}if(t){const s=pd({tournamentRecords:e,schedulingProfile:t});if(s.error)return s}if(!t){const s=$a({tournamentRecords:e});if(s.error)return s;t=s.schedulingProfile}if(!t)return{error:Yt};const o={};return{profileRounds:t.map(({venues:s,scheduleDate:a})=>s.map(({rounds:c})=>c.map(l=>{var u;const d=um(l);return(u=d.roundSegment)!=null&&u.segmentsCount&&(o[d.id]=d.roundSegment.segmentsCount),_e(Ss({id:n?d.id:void 0,scheduleDate:a},d))}))).flat(1/0),segmentedRounds:o}}function um(t){const{containerStructureId:e,roundSegment:r,isRoundRobin:n,tournamentId:o,roundNumber:i,structureId:s,eventId:a,drawId:c}=t,l=n?e:s,u=[o,a,c,l,i].join("|");return _e({id:u,roundSegment:r,tournamentId:o,eventId:a,drawId:c,structureId:l,roundNumber:i})}function iE(t){const e=t.length,r=t.filter(({sides:u})=>u==null?void 0:u.some(({bye:d})=>d)).length||0,n=t.filter(({winningSide:u,matchUpStatus:d})=>u||Lt.includes(d)).length||0,o=t.filter(({schedule:u})=>(u==null?void 0:u.scheduledDate)&&(u==null?void 0:u.scheduledTime)).length||0,i=e-r,s=i===n,a=i-o,c=i-o;return{unscheduledCount:a,incompleteCount:c,scheduledCount:o,completedCount:n,matchUpsCount:e,isScheduled:i===o,isComplete:s,byeCount:r}}function sE({excludeScheduleDateProfileRounds:t,excludeScheduledRounds:e,excludeCompletedRounds:r,inContextMatchUps:n,schedulingProfile:o,tournamentRecords:i,tournamentRecord:s,withSplitRounds:a,matchUpFilters:c,withRoundId:l,context:u}){var d;if(n&&!Array.isArray(n||typeof n[0]!="object"))return{error:Z,inContextMatchUps:n};if(s&&!i){if(typeof s!="object")return{error:bl};i={[s.tournamentId]:s}}const p=typeof i!="object"||!Object.keys(i).length;if((!n||!o&&(t||r||o||a))&&p)return{error:Fe};const f=Object.values(i||{}).map(({events:O})=>O).flat(),{segmentedRounds:m,profileRounds:g}=t||r||o||a?lm({tournamentRecords:i,schedulingProfile:o}):{},h=t&&Object.assign({},...g.map(O=>({[O.id]:O}))),_=n||((d=Oo({tournamentRecords:i,matchUpFilters:c}))==null?void 0:d.matchUps)||[],I=[];let P=_&&Object.values(_.reduce((O,y)=>{var S,T;const E=um(y).id,b=m==null?void 0:m[E],N=[...(T=(S=O[E])==null?void 0:S.matchUps)!=null?T:[],y],{containerStructureId:w,stageSequence:$,structureName:U,tournamentId:A,isRoundRobin:M,matchUpType:C,roundNumber:D,roundOffset:F,structureId:R,eventName:G,roundName:x,drawName:z,eventId:j,drawId:V}=y,L=M?w:R;return hd(Ss({},O),{[E]:{id:l?E:void 0,structureId:L,stageSequence:$,segmentsCount:b,structureName:U,tournamentId:A,matchUpType:C,roundNumber:D,roundOffset:F,eventName:G,roundName:x,drawName:z,matchUps:N,eventId:j,drawId:V}})},{})).map(O=>{const{minFinishingSum:y,winnerFinishingPositionRange:S}=Y8(O.matchUps),T=O.segmentsCount;if(T){const M=O.matchUps.length/T;return Rt(O.matchUps.sort((D,F)=>D.roundPosition-F.roundPosition),M).map((D,F)=>{const{unscheduledCount:R,incompleteCount:G,matchUpsCount:x,isScheduled:z,isComplete:j,byeCount:V}=iE(D),L=aE({matchUps:O.matchUps,tournamentRecords:i,events:f,round:O});return _e(hd(Ss(Ss({},O),u),{roundSegment:{segmentsCount:T,segmentNumber:F+1},winnerFinishingPositionRange:S,unscheduledCount:R,incompleteCount:G,minFinishingSum:y,matchUpsCount:x,isScheduled:z,roundTiming:L,isComplete:j,byeCount:V,matchUps:D}))})}const{unscheduledCount:E,incompleteCount:b,matchUpsCount:N,isScheduled:w,isComplete:$,byeCount:U}=iE(O.matchUps),A=aE({matchUps:O.matchUps,tournamentRecords:i,events:f,round:O});return _e(hd(Ss(Ss({},O),u),{winnerFinishingPositionRange:S,unscheduledCount:E,incompleteCount:b,minFinishingSum:y,matchUpsCount:N,isScheduled:w,roundTiming:A,isComplete:$,byeCount:U}))}).flat().filter(O=>{if(t){const N=Ce(t),w=l?O.id:um(O).id;if(N&&h[w]&&Ce(h[w].scheduleDate)===N)return!1}const{isComplete:y,isScheduled:S}=O,b=(!r||!y)&&(!e||!S);return b||I.push(O),b}).sort(q8)||[];return hd(Ss({},B),{rounds:P,excludedRounds:I})}function aE({round:t,matchUps:e,events:r,tournamentRecords:n}){const o=r.find(p=>p.eventId===t.eventId),{eventType:i,category:s,categoryType:a}=o||{},{categoryName:c,ageCategoryCode:l}=s||{},u=mr(e.map(({matchUpFormat:p})=>p));let d=0;return Object.keys(u).forEach(p=>{const v=u[p],f=Yv({categoryName:c||l,tournamentId:t.tournamentId,eventId:t.eventId,tournamentRecords:n,matchUpFormat:p,categoryType:a,eventType:i});if(f.error)return f;const m=f.averageMinutes*v;isNaN(d)||(d+=m)}),{roundMinutes:d}}function q8(t,e){return t.eventName.localeCompare(e.eventName)||t.eventId.localeCompare(e.eventId)||(oE[t==null?void 0:t.stage]||0)-(oE[e==null?void 0:e.stage]||0)||e.matchUpsCount-t.matchUpsCount||`${t.stageSequence}-${t.roundNumber}-${t.minFinishingSum}`.localeCompare(`${e.stageSequence}-${e.roundNumber}-${e.minFinishingSum}`)}function Y8(t){return(t||[]).reduce((e,r)=>{var n,o;const i=(((n=r.finishingPositionRange)==null?void 0:n.winner)||[]).reduce((a,c)=>a+c,0),s=(((o=r.finishingPositionRange)==null?void 0:o.winner)||[]).join("-")||"";return!e.minFinishingSum||i<e.minFinishingSum?{minFinishingSum:i,winnerFinishingPositionRange:s}:e},{minFinishingSum:0,winnerFinishingPositionRange:""})}function z8({tournamentRecords:t,courtAssignments:e,courtDayDate:r}){if(!t)return{error:Fe};if(!Array.isArray(e))return{error:Oe,info:zt("courtAssignments")};const n=e.reduce((s,a)=>{const{tournamentId:c}=a;return s[c]||(s[c]=[]),s[c].push(a),s},{});let o;return Object.keys(n).every(s=>{const a=t[s];if(!a)return o={error:ee},!1;const c=n[s].reduce((u,d)=>{const{drawId:p}=d;return u[p]||(u[p]=[]),u[p].push(d),u},{});Object.keys(c).every(u=>{const{drawDefinition:d}=xt({tournamentRecord:a,drawId:u});return d?(c[u].every(p=>{const{matchUpId:v,courtId:f}=p,m=gs({tournamentRecord:a,drawDefinition:d,courtDayDate:r,matchUpId:v,courtId:f});if(m.success)return m==null?void 0:m.success;o={error:rL}}),!0):(o={error:pe},!1)})}),o||B}var K8=Object.defineProperty,Q8=Object.defineProperties,J8=Object.getOwnPropertyDescriptors,cE=Object.getOwnPropertySymbols,Z8=Object.prototype.hasOwnProperty,X8=Object.prototype.propertyIsEnumerable,lE=(t,e,r)=>e in t?K8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,e9=(t,e)=>{for(var r in e||(e={}))Z8.call(e,r)&&lE(t,r,e[r]);if(cE)for(var r of cE(e))X8.call(e,r)&&lE(t,r,e[r]);return t},t9=(t,e)=>Q8(t,J8(e));function r9({tournamentRecords:t,competitionMatchUps:e,matchUpDependencies:r,allDateMatchUpIds:n=[],averageMatchUpMinutes:o=90,recoveryMinutes:i=0,recoveryMinutesMap:s,matchUpPotentialParticipantIds:a={},individualParticipantProfiles:c={},matchUpNotBeforeTimes:l={},matchUpDailyLimits:u={},checkPotentialRequestConflicts:d=!0,remainingScheduleTimes:p,clearScheduleDates:v,periodLength:f=30,scheduleDate:m,matchUpIds:g,venueIds:h,startTime:_,endTime:I,dryRun:P}){if(!t)return{error:Fe};if(!g)return{error:Ka};if(!Nr(m))return{error:cr};if(isNaN(f)||isNaN(o)||isNaN(i))return{error:Z};e||({matchUps:e}=Oo({tournamentRecords:t,nextMatchUps:!0})),r||({matchUpDependencies:r}=Yr({includeParticipantDependencies:!0,matchUps:e,tournamentRecords:t})),e.forEach(j=>{var V;(V=j.schedule)!=null&&V.scheduledDate&&kn(m,Ce(j.schedule.scheduledDate))&&Na({matchUp:j,matchUpNotBeforeTimes:l,matchUpPotentialParticipantIds:a})});const O=g.map(j=>e.find(V=>V.matchUpId===j)).filter(Boolean),{venueId:y,scheduleTimes:S,dateScheduledMatchUpIds:T}=NT({tournamentRecords:t,remainingScheduleTimes:p,startTime:rt(_),endTime:rt(I),scheduleDate:Ce(m),averageMatchUpMinutes:o,clearScheduleDates:v,periodLength:f,venueIds:h}),E={},b=[],N={},w={},$={};e.filter(({matchUpId:j})=>T.includes(j)).forEach(j=>{var V;em({matchUpPotentialParticipantIds:a,individualParticipantProfiles:c,scheduleDate:m,matchUp:j,value:1});const L=(V=j.schedule)==null?void 0:V.scheduledTime;if(L){N[j.matchUpId]=L;const q=s==null?void 0:s[j.matchUpId];ol({individualParticipantProfiles:c,matchUpPotentialParticipantIds:a,matchUpNotBeforeTimes:l,matchUpDependencies:r,recoveryMinutes:q||i,averageMatchUpMinutes:o,scheduleDate:m,scheduleTime:L,matchUp:j})}});let A=O.filter(j=>{const V=T.includes(j.matchUpId),L=[qe,Be,St,yr,er,Ge].includes(j==null?void 0:j.matchUpStatus);return!V&&!j.winningSide&&!L});const{matchUpMap:M,overLimitMatchUpIds:C,participantIdsAtLimit:D}=A.reduce((j,V)=>{const{drawId:L,tournamentId:q,matchUpType:k}=V,{participantIdsAtLimit:H,relevantParticipantIds:Q}=nm({individualParticipantProfiles:c,matchUpPotentialParticipantIds:a,matchUpDailyLimits:u,matchUp:V});return H!=null&&H.length?(j.overLimitMatchUpIds.push(V.matchUpId),j.participantIdsAtLimit.push(...H),j):(Q.forEach(K=>{nl({individualParticipantProfiles:c,participantId:K});const Y=c[K].counters;Y[k]?Y[k]+=1:Y[k]=1,Y[nn]?Y[nn]+=1:Y[nn]=1}),j.matchUpMap[q]||(j.matchUpMap[q]={}),j.matchUpMap[q][L]?j.matchUpMap[q][L].push(V):j.matchUpMap[q][L]=[V],Na({matchUp:V,matchUpNotBeforeTimes:l,matchUpPotentialParticipantIds:a}),j)},{matchUpMap:{},overLimitMatchUpIds:[],participantIdsAtLimit:[]});A=A.filter(({matchUpId:j})=>!C.includes(j));let F=0;const R=(S==null?void 0:S.length)||0,{personRequests:G}=Aa({tournamentRecords:t,requestType:gd});for(;S!=null&&S.length&&A.length&&F<=R;){F++;const{scheduleTime:j}=S.shift(),V=A.find(L=>{const{matchUpId:q}=L,{dependenciesScheduled:k,remainingDependencies:H}=Zv({matchUps:e,matchUpScheduleTimes:N,matchUpDependencies:r,allDateMatchUpIds:n,matchUp:L});if(!k)return $[q]||($[q]=[]),$[q].push({scheduleTime:j,remainingDependencies:H}),!1;const{enoughTime:Q}=rm({individualParticipantProfiles:c,matchUpNotBeforeTimes:l,matchUpDependencies:r,scheduleTime:j,matchUp:L});if(!Q)return w[q]||(w[q]=[]),w[q].push({scheduleTime:j}),!1;const{conflicts:K}=Xv({potentials:d,averageMatchUpMinutes:o,requestConflicts:E,personRequests:G,scheduleTime:j,scheduleDate:m,matchUp:L});if(K!=null&&K.length)return!1;const Y=s==null?void 0:s[L.matchUpId];return ol({recoveryMinutes:Y||i,matchUpPotentialParticipantIds:a,individualParticipantProfiles:c,matchUpNotBeforeTimes:l,averageMatchUpMinutes:o,matchUpDependencies:r,scheduleDate:m,scheduleTime:j,matchUp:L}),N[L.matchUpId]=j,!0});A=A.filter(({matchUpId:L})=>L!==(V==null?void 0:V.matchUpId)),V||b.push(j)}A.forEach(j=>{em({individualParticipantProfiles:c,matchUpPotentialParticipantIds:a,scheduleDate:m,value:-1,matchUp:j})});let x=[];Object.keys(M).forEach(j=>{const V=t[j];V?Object.keys(M[j]).forEach(L=>{const{drawDefinition:q}=Fo({tournamentRecord:V,drawId:L});q&&M[j][L].forEach(({matchUpId:H})=>{const Q=N[H];if(Q){const K=Q.split(":").map(Bn).join(":"),Y=`${Ce(m)}T${K}`;P?x.push(H):(Ti({drawDefinition:q,matchUpId:H,scheduledTime:Y}).success&&x.push(H),y&&ha({tournamentRecord:V,drawDefinition:q,matchUpId:H,venueId:y}))}})}):Ft()&&console.log(ao)});const z=fu(A);return t9(e9({},B),{requestConflicts:Object.values(E),remainingScheduleTimes:S.map(({scheduleTime:j})=>j),individualParticipantProfiles:c,matchUpNotBeforeTimes:l,participantIdsAtLimit:D,skippedScheduleTimes:b,overLimitMatchUpIds:C,scheduledMatchUpIds:x,noTimeMatchUpIds:z,recoveryTimeDeferred:w,dependencyDeferred:$})}var n9=Object.defineProperty,uE=Object.getOwnPropertySymbols,o9=Object.prototype.hasOwnProperty,i9=Object.prototype.propertyIsEnumerable,dE=(t,e,r)=>e in t?n9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s9=(t,e)=>{for(var r in e||(e={}))o9.call(e,r)&&dE(t,r,e[r]);if(uE)for(var r of uE(e))i9.call(e,r)&&dE(t,r,e[r]);return t};function a9(t){const e="reorderUpcomingMatchUps",{tournamentRecords:r}=t;if(typeof r!="object"||!Object.keys(r).length)return W({result:{error:Fe},stack:e});const{matchUpsContextIds:n,firstToLast:o}=t;if(!n)return W({result:{error:Oe},stack:e});const i=n==null?void 0:n.length;if(!i)return s9({},B);let s=0;return n.forEach((c,l)=>{const{tournamentId:u,drawId:d,matchUpId:p}=c;let v=l+(o?-1:1);v<0&&(v=i-1),v===i&&(v=0);const f=n[v].schedule.scheduledTime,m=a({tournamentId:u,scheduledTime:f,matchUpId:p,drawId:d});if(m.success)s++;else return m}),s===i?B:W({result:{error:tL},stack:e});function a({tournamentId:c,scheduledTime:l,matchUpId:u,drawId:d}){const p=r[c],{drawDefinition:v}=Fo({tournamentRecord:p,drawId:d});return Ti({drawDefinition:v,scheduledTime:l,matchUpId:u})}}var c9=Object.defineProperty,l9=Object.defineProperties,u9=Object.getOwnPropertyDescriptors,pE=Object.getOwnPropertySymbols,d9=Object.prototype.hasOwnProperty,p9=Object.prototype.propertyIsEnumerable,fE=(t,e,r)=>e in t?c9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vE=(t,e)=>{for(var r in e||(e={}))d9.call(e,r)&&fE(t,r,e[r]);if(pE)for(var r of pE(e))p9.call(e,r)&&fE(t,r,e[r]);return t},mE=(t,e)=>l9(t,u9(e));function f9({scheduleCompletedMatchUps:t,tournamentRecords:e,scheduledDate:r,matchUps:n}={}){if(!Array.isArray(n))return{error:Z};if(n.some(({hasContext:m})=>!m))return{info:"matchUps must have { inContext: true, nextMatchUps: true }",error:Ul};let i=Jv({courtCompletedMatchUps:!0,withCourtGridRows:!0,minCourtGridRows:10,nextMatchUps:!0,tournamentRecords:e,matchUpFilters:{localPerspective:!0,scheduledDate:r}});if(i.error)return i;const{rows:s}=i,a=[],c=m=>[(m.sides||[]).map(g=>{var h;return[g.participantId,(h=g.participant)==null?void 0:h.individualParticipantIds]}),(m.potentialParticipants||[]).flat().map(g=>[g.participantId,g.individualParticipantIds])].flat(1/0).filter(Boolean),l=s.reduce((m,g)=>{const h=[],_=[];Object.values(g).forEach(P=>{if(Li(P)&&(P.matchUpId&&(h.push(P.matchUpId),a.push(P)),P.sides)){const O=c(P);_.push(...O)}});const I=Object.values(g).filter(P=>Li(P)&&!P.matchUpId);return m.concat({matchUpIds:h,availableCourts:I,rowId:g.rowId,participantIds:_})},[]);n.filter(({matchUpStatus:m})=>m!==qe&&(t||!Lt.includes(m))).sort(vs);const u=Yr({matchUps:n.concat(a),includeParticipantDependencies:!0,tournamentRecords:e}).matchUpDependencies,d=[],p=[];for(;n.length&&l.length;){const m=l.shift(),g=[];for(;n.length&&m.availableCourts.length;){const h=n.concat(g).map(b=>b.matchUpId),_=n.shift(),{matchUpId:I}=_,P=u[I].matchUpIds.concat(u[I].dependentMatchUpIds),O=h.some(b=>u[I].matchUpIds.includes(b)),y=d.some(b=>u[I].dependentMatchUpIds.includes(b)),S=m.matchUpIds.some(b=>P.includes(b)),T=c(_),E=m.participantIds.some(b=>T.includes(b));if(!S&&!O&&!E&&!y){const b=m.availableCourts.shift();Object.assign(_.schedule,b.schedule),Object.assign(b,_),p.push(_),m.participantIds.push(...T),m.matchUpIds.push(I)}else g.push(_)}n.push(...g),d.push(...m.matchUpIds)}const v=p.map(({matchUpId:m,tournamentId:g,schedule:h,drawId:_})=>({tournamentId:g,matchUpId:m,drawId:_,schedule:mE(vE({},h),{scheduledDate:r})}));i=rO({tournamentRecords:e,matchUpDetails:v});const f=n;return mE(vE({},i),{scheduled:p,notScheduled:f})}var v9=Object.defineProperty,m9=Object.defineProperties,g9=Object.getOwnPropertyDescriptors,gE=Object.getOwnPropertySymbols,h9=Object.prototype.hasOwnProperty,_9=Object.prototype.propertyIsEnumerable,hE=(t,e,r)=>e in t?v9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_E=(t,e)=>{for(var r in e||(e={}))h9.call(e,r)&&hE(t,r,e[r]);if(gE)for(var r of gE(e))_9.call(e,r)&&hE(t,r,e[r]);return t},IE=(t,e)=>m9(t,g9(e));function I9(t){const e="matchUpScheduleChange",{tournamentRecords:r}=t;if(typeof r!="object"||!Object.keys(r).length)return{error:Fe};const{sourceMatchUpContextIds:n,targetMatchUpContextIds:o,sourceCourtId:i,targetCourtId:s,courtDayDate:a}=t||{},{drawId:c,matchUpId:l,tournamentId:u}=n||{},{drawId:d,matchUpId:p,tournamentId:v}=o||{};if(!l&&!p)return W({result:{error:Oe},stack:e});const{matchUps:f}=Oo({matchUpFilters:{matchUpIds:[l,p].filter(Boolean),drawIds:[c,d].filter(Boolean)},tournamentRecords:t.tournamentRecords}),m=f.find(({matchUpId:O})=>O===l),g=f.find(({matchUpId:O})=>O===p);let h=0;if(s&&l&&!p){const O=_({tournamentId:u,matchUpId:l,courtId:s,matchUp:m,drawId:c,tournamentRecords:r,sourceCourtId:i,courtDayDate:a});if(O!=null&&O.success&&h++,O.error)return W({result:O,stack:e})}else if(i&&s&&l&&p){const O=_({tournamentId:u,matchUpId:l,courtId:s,matchUp:m,drawId:c,tournamentRecords:r,sourceCourtId:i,courtDayDate:a});if(O.success&&h++,O.error)return W({result:O,stack:e,info:"source"});const y=_({tournamentId:v,sourceCourtId:s,matchUpId:p,matchUp:g,courtId:i,drawId:d,tournamentRecords:r,courtDayDate:a});if(y.success&&h++,y.error)return W({result:y,stack:e,info:"target"})}else return{error:Oe};return h?B:W({result:{error:Ja},stack:e});function _(O){const{tournamentRecords:y,tournamentId:S,matchUp:T,drawId:E}=O,b=y[S],{drawDefinition:N}=Fo({tournamentRecord:b,drawId:E});return T.matchUpType===He?I(IE(_E({},O),{tournamentRecord:b,drawDefinition:N})):P(IE(_E({},O),{tournamentRecord:b,drawDefinition:N}))}function I({removePriorValues:O,tournamentRecords:y,tournamentRecord:S,drawDefinition:T,sourceCourtId:E,courtDayDate:b,matchUpId:N,matchUp:w,courtId:$}){const U=[$].concat(w.schedule.allocatedCourts.map(({courtId:A})=>A).filter(A=>A!==E));return Lu({removePriorValues:O,tournamentRecords:y,tournamentRecord:S,drawDefinition:T,courtDayDate:b,matchUpId:N,courtIds:U})}function P({tournamentRecords:O,tournamentRecord:y,drawDefinition:S,courtDayDate:T,matchUpId:E,courtId:b}){return gs({tournamentRecords:O,tournamentRecord:y,drawDefinition:S,courtDayDate:T,matchUpId:E,courtId:b})}}var P9=Object.defineProperty,y9=Object.defineProperties,S9=Object.getOwnPropertyDescriptors,PE=Object.getOwnPropertySymbols,O9=Object.prototype.hasOwnProperty,b9=Object.prototype.propertyIsEnumerable,yE=(t,e,r)=>e in t?P9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,T9=(t,e)=>{for(var r in e||(e={}))O9.call(e,r)&&yE(t,r,e[r]);if(PE)for(var r of PE(e))b9.call(e,r)&&yE(t,r,e[r]);return t},E9=(t,e)=>y9(t,S9(e));function w9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e;return hb(E9(T9({},t),{tournamentRecord:r,drawDefinition:n}))}function $9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,scheduledDate:i,matchUpId:s,removePriorValues:a}=t;return Gv({removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:o,scheduledDate:i,matchUpId:s})}function N9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,scheduledTime:i,matchUpId:s,removePriorValues:a}=t;return Wv({removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:o,scheduledTime:i,matchUpId:s})}function A9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,startTime:i,matchUpId:s}=t;return _b({tournamentRecord:r,drawDefinition:n,disableNotice:o,startTime:i,matchUpId:s})}function U9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,endTime:i,matchUpId:s}=t;return Ib({tournamentRecord:r,drawDefinition:n,disableNotice:o,endTime:i,matchUpId:s})}function C9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,stopTime:i,matchUpId:s}=t;return Pb({tournamentRecord:r,drawDefinition:n,disableNotice:o,stopTime:i,matchUpId:s})}function M9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,resumeTime:i,matchUpId:s}=t;return yb({tournamentRecord:r,drawDefinition:n,disableNotice:o,resumeTime:i,matchUpId:s})}function D9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{disableNotice:o,participantId:i,officialType:s,matchUpId:a}=t;return Sb({tournamentRecord:r,drawDefinition:n,disableNotice:o,participantId:i,officialType:s,matchUpId:a})}function j9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{matchUpId:o,venueId:i,disableNotice:s,removePriorValues:a}=t;return ha({removePriorValues:a,tournamentRecord:r,drawDefinition:n,disableNotice:s,matchUpId:o,venueId:i})}function R9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{removePriorValues:o,tournamentRecords:i,disableNotice:s,courtDayDate:a,matchUpId:c,courtId:l}=t;return gs({removePriorValues:o,tournamentRecords:i,tournamentRecord:r,drawDefinition:n,disableNotice:s,courtDayDate:a,matchUpId:c,courtId:l})}function F9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{removePriorValues:o,tournamentRecords:i,disableNotice:s,courtDayDate:a,matchUpId:c,courtIds:l}=t;return Lu({removePriorValues:o,tournamentRecords:i,tournamentRecord:r,drawDefinition:n,disableNotice:s,courtDayDate:a,matchUpId:c,courtIds:l})}function L9(t){const e=Fn(t);if(e.error)return e;const{tournamentRecord:r,drawDefinition:n}=e,{removePriorValues:o,tournamentRecords:i,disableNotice:s,courtOrder:a,matchUpId:c,courtId:l}=t;return bz({removePriorValues:o,tournamentRecords:i,tournamentRecord:r,drawDefinition:n,disableNotice:s,courtOrder:a,matchUpId:c,courtId:l})}function Fn({tournamentRecords:t,tournamentId:e,drawId:r}){if(!t)return{error:Fe};if(!r)return{error:wr};if(typeof e!="string"&&(e=Sv({tournamentRecords:t,drawId:r}),!e))return{error:ao};const n=t[e];if(!n)return{error:ee};const o=xt({tournamentRecord:n,drawId:r});return o.error?W({stack:"addScheduleItems.getDrawDefinition",result:o}):{drawDefinition:o.drawDefinition,tournamentRecord:n}}const V9={scheduleMatchUps:r9,scheduleProfileRounds:sm,clearScheduledMatchUps:QT,bulkRescheduleMatchUps:Lz,getScheduledRoundsDetails:zv,getMatchUpDependencies:Yr,generateVirtualCourts:lv,generateBookings:tm,proAutoSchedule:f9,proConflicts:gS,matchUpScheduleChange:I9,calculateScheduleTimes:NT,reorderUpcomingMatchUps:a9,bulkUpdateCourtAssignments:z8,removeMatchUpCourtAssignment:tE,toggleParticipantCheckInState:V8,findMatchUpFormatTiming:Yv,modifyMatchUpFormatTiming:cK,modifyEventMatchUpFormatTiming:WY,getMatchUpFormatTimingUpdate:z7,getEventMatchUpFormatTiming:rK,removeEventMatchUpFormatTiming:F8,getMatchUpDailyLimitsUpdate:x8,getMatchUpDailyLimits:ZT,setMatchUpDailyLimits:Gz,getProfileRounds:lm,getRounds:sE,assignMatchUpVenue:j9,assignMatchUpCourt:R9,allocateTeamMatchUpCourts:F9,addMatchUpScheduleItems:w9,addMatchUpScheduledDate:$9,addMatchUpScheduledTime:N9,addMatchUpCourtOrder:L9,addMatchUpStartTime:A9,addMatchUpStopTime:C9,addMatchUpResumeTime:M9,addMatchUpEndTime:U9,addMatchUpOfficial:D9,getSchedulingProfile:$a,setSchedulingProfile:rl,addSchedulingProfileRound:OT,validateSchedulingProfile:pd,addPersonRequests:O8,getPersonRequests:Aa,modifyPersonRequests:T8,removePersonRequests:b8};var x9=Object.defineProperty,B9=Object.defineProperties,k9=Object.getOwnPropertyDescriptors,SE=Object.getOwnPropertySymbols,G9=Object.prototype.hasOwnProperty,W9=Object.prototype.propertyIsEnumerable,OE=(t,e,r)=>e in t?x9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,H9=(t,e)=>{for(var r in e||(e={}))G9.call(e,r)&&OE(t,r,e[r]);if(SE)for(var r of SE(e))W9.call(e,r)&&OE(t,r,e[r]);return t},q9=(t,e)=>B9(t,k9(e));function dm({tournamentRecord:t,policyDefinitions:e,allowReplacement:r}){if(!t)return{error:ee};if(!e||typeof e!="object")return{error:Nl};t.extensions||(t.extensions=[]);const{appliedPolicies:n}=at({tournamentRecord:t}),o=Object.keys(e).map(i=>{if(!n[i]||r)return n[i]=e[i],i}).filter(Boolean);if(o!=null&&o.length){const s=pi({tournamentRecord:t,extension:{name:Bi,value:n}});if(s.error)return s}return o!=null&&o.length?q9(H9({},B),{applied:o}):{error:bh}}function bE({policyDefinitions:t,allowReplacement:e,event:r}){if(!r)return{error:Le};if(!t)return{error:Nl};let n=0;r.extensions||(r.extensions=[]);const{appliedPolicies:o}=at({event:r});return Object.keys(t).forEach(i=>{(!o[i]||e)&&(o[i]=t[i],n++)}),n&&Wn({event:r,extension:{name:Bi,value:o}}),n?B:{error:TF}}function Y9({event:t,policyType:e}){if(!e)return{error:Oe};if(!t)return{error:Le};let r;if(t.extensions){const{appliedPolicies:n}=at({event:t});n!=null&&n[e]&&(delete n[e],r=!0,Object.keys(n).length?Wn({event:t,extension:{name:Bi,value:n}}):Jl({event:t,name:Bi}))}return r?B:{error:$p}}var z9=Object.defineProperty,TE=Object.getOwnPropertySymbols,K9=Object.prototype.hasOwnProperty,Q9=Object.prototype.propertyIsEnumerable,EE=(t,e,r)=>e in t?z9(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,J9=(t,e)=>{for(var r in e||(e={}))K9.call(e,r)&&EE(t,r,e[r]);if(TE)for(var r of TE(e))Q9.call(e,r)&&EE(t,r,e[r]);return t};function Z9({tournamentRecords:t,policyDefinitions:e}){if(typeof t!="object"||!Object.keys(t).length)return{error:Fe};for(const r of Object.values(t)){const n=dm({tournamentRecord:r,policyDefinitions:e,allowReplacement:!0});if(n.error)return n}return J9({},B)}const X9={attachPolicies:Z9};var eQ=Object.defineProperty,tQ=Object.defineProperties,rQ=Object.getOwnPropertyDescriptors,wE=Object.getOwnPropertySymbols,nQ=Object.prototype.hasOwnProperty,oQ=Object.prototype.propertyIsEnumerable,$E=(t,e,r)=>e in t?eQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,pm=(t,e)=>{for(var r in e||(e={}))nQ.call(e,r)&&$E(t,r,e[r]);if(wE)for(var r of wE(e))oQ.call(e,r)&&$E(t,r,e[r]);return t},NE=(t,e)=>tQ(t,rQ(e));function iQ({policyDefinitions:t,tournamentRecords:e,scaleAttributes:r,participantId:n,inContext:o,personId:i}){let s=qb({policyDefinitions:t,tournamentRecords:e,participantId:n,inContext:o,personId:i});if(s.error)return s;const{participant:a,tournamentId:c}=s;return s=ro({participant:a,scaleAttributes:r}),s.error?NE(pm({},s),{tournamentId:c}):pm(NE(pm({},B),{tournamentId:c}),s)}var sQ=Object.defineProperty,AE=Object.getOwnPropertySymbols,aQ=Object.prototype.hasOwnProperty,cQ=Object.prototype.propertyIsEnumerable,UE=(t,e,r)=>e in t?sQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,CE=(t,e)=>{for(var r in e||(e={}))aQ.call(e,r)&&UE(t,r,e[r]);if(AE)for(var r of AE(e))cQ.call(e,r)&&UE(t,r,e[r]);return t};function lQ({scheduleDates:t=[],tournamentRecords:e,periodLength:r=30}={}){if(typeof e!="object")return{error:bl};if(!Array.isArray(t))return{error:Z};if(!t.every(Nr))return{error:cr};const o=[];let i=0;const s={},{schedulingProfile:a}=$a({tournamentRecords:e});if(!a)return CE({issues:o},B);const{matchUps:c}=Oo({nextMatchUps:!0,tournamentRecords:e});for(const u of a){const{scheduleDate:d,venues:p=[]}=u;if(!(t!=null&&t.length)||t.includes(d)){for(const v of p||[])if(v){const{rounds:f}=v,m=[];let{orderedMatchUpIds:g,scheduledRoundsDetails:h}=zv({tournamentRecords:e,periodLength:r,matchUps:c,rounds:f});const{matchUpDependencies:_}=Yr({tournamentRecords:e,matchUps:c}),I=P=>{let O;return h.find((y,S)=>{const T=y.matchUpIds.includes(P);return T&&(O=S),T}),O};if(g.forEach((P,O)=>{var y;const S=g.slice(O+1),T=jt(S,((y=_==null?void 0:_[P])==null?void 0:y.matchUpIds)||[]);T.length&&m.push({matchUpId:P,shouldBeAfter:T})}),m.length){i+=m.length;const P=m.map(({matchUpId:O,shouldBeAfter:y})=>{const S=I(O),T=Ve(y.map(I));return s[d]||(s[d]={}),s[d][S]||(s[d][S]=[]),T.forEach(E=>{s[d][S].includes(E)||s[d][S].push(E)}),{matchUpId:O,matchUpRoundIndex:S,earlierRoundIndices:T,shouldBeAfter:y}});o.push(...P)}}}}const l={matchUpIdShouldBeAfter:Object.assign({},...o.map(u=>{const{matchUpId:d,shouldBeAfter:p,earlierRoundIndices:v}=u;return{[d]:{earlierRoundIndices:v,shouldBeAfter:p}}}))};return CE({issuesCount:i,profileIssues:l,roundIndexShouldBeAfter:s},B)}function _d(){return`
|
|
8
|
+
This project would not have been possible without the generous input and patience
|
|
9
|
+
of tournament organizers and directors who worked with early versions of CourtHive/TMX.
|
|
10
|
+
|
|
11
|
+
Thanks to Pavel, Ivan, Mladen, Zdenko, Antoina, Jakov, Kreso, Barry, Jeff, Bobby... to name just a few.
|
|
12
|
+
|
|
13
|
+
The project would not have even begun without the support of Miro, or the introduction by Sretchko.
|
|
14
|
+
The project would not have succeeded without the enthusiasm of Randy and Bruce.
|
|
15
|
+
Thanks to serendipity and Luca and the ensuing TODS conversations with ITF.
|
|
16
|
+
Thanks to Scott and Jake for sanity checks, suggestions, and challenging me.
|
|
17
|
+
Thanks to Zoran for inspiring the async support and getting into the weeds with subscriptions.
|
|
18
|
+
Thanks to Dave for backing the conversion of TMX 1.x source into the factory repository.
|
|
19
|
+
Thanks to Vuk and Pavle and Rich and Chris and Deepa for the direct engagement with the APIs.
|
|
20
|
+
Thanks to Shannon for the validation of the approach from his deep domain experience.
|
|
21
|
+
Thanks to Nikola for the ongoing camaraderie and explorations of what we can do with TODS.
|
|
22
|
+
|
|
23
|
+
And a special thanks to my family for putting up with the long days and weeks and months of coding
|
|
24
|
+
and conversations at all hours.
|
|
25
|
+
`}function uQ({tournamentParticipants:t=[],possiblyDisablingAction:e,activeDrawPositions:r,positionAssignments:n,returnParticipants:o,appliedPolicies:i,drawDefinition:s,drawPosition:a,validActions:c,structureId:l,structure:u,drawId:d,event:p}){var v,f,m,g;if(r.includes(a))return{};const h=(v=c.find(w=>w.type===la))==null?void 0:v.availableParticipantIds,_=(f=i==null?void 0:i[po])==null?void 0:f.otherFlightEntries,I=(m=i==null?void 0:i[po])==null?void 0:m.restrictQualifyingAlternates,P=(s.entries||[]).filter(({entryStage:w})=>!I||(u.stage===Ie?w===Ie:w!==Ie)).sort((w,$)=>(w.entryPosition||1/0)-($.entryPosition||1/0)).map(({participantId:w})=>w).filter(Boolean),{allPositionedParticipantIds:O}=$P({drawDefinition:s}),y=n.map(w=>w.participantId).filter(Boolean),S=P.filter(w=>[Ie,de,st].includes(u.stage)?!O.includes(w):!y.includes(w)),E=(p.entries||[]).filter(w=>w.entryStatus===un&&ME({restrictQualifyingAlternates:I,structure:u,entry:w})&&([Ie,de,st].includes(u.stage)?!O.includes(w.participantId):!y.includes(w.participantId))).sort((w,$)=>(w.entryPosition||1/0)-($.entryPosition||1/0)).map(w=>w.participantId);let b=Ve(S.concat(E));if(_){const{flightProfile:w}=It({event:p}),$=(g=w==null?void 0:w.flights)==null?void 0:g.filter(U=>U.drawId!==d).map(U=>U.drawEntries.filter(A=>A.participantId&&![Go,qr,ns].includes(A.entryStatus)&&!P.includes(A.participantId)).map(({participantId:A})=>A)).flat().filter(Boolean);$!=null&&$.length&&b.push(...$)}h!=null&&h.length&&(b=b.filter(w=>!h.includes(w)));const N=o?t==null?void 0:t.filter(w=>b.includes(w.participantId)):void 0;return N==null||N.forEach(w=>{const $=(s.entries||[]).find(U=>U.participantId===w.participantId);w.entryPosition=$==null?void 0:$.entryPosition}),N==null||N.sort((w,$)=>(w.entryPosition||1/0)-($.entryPosition||1/0)),b.length?{validAlternatesAction:_e({payload:{drawId:d,structureId:l,drawPosition:a},willDisableLinks:e,method:E4,availableAlternatesParticipantIds:b,type:Jy,availableAlternates:N})}:{}}function ME({restrictQualifyingAlternates:t,structure:e,entry:r}){const{stage:n}=e;if(!r.entryStage||r.entryStage===n||n===Ie&&!t||r.entryStage===de&&n===$t)return!0}const fm={[xi]:{policyName:"matchUpActionsDefault",enabledStructures:[{stages:[],stageSequences:[],enabledActions:[],disabledActions:[]}],processCodes:{substitution:["RANKING.IGNORE","RATING.IGNORE"]}}},Id="positionAction",vm="matchUpAction";function DE({actionType:t=Id,appliedPolicies:e,drawDefinition:r,structure:n}){var o;const i=t===Id&&po||t===vm&&xi,s=t===Id&&rS||t===vm&&fm,a=(e==null?void 0:e[i])||(s==null?void 0:s[i]),c=(o=r.links)==null?void 0:o.filter(v=>{var f;return((f=v==null?void 0:v.target)==null?void 0:f.structureId)===(n==null?void 0:n.structureId)}),l=(c==null?void 0:c.map(({target:v})=>v.feedProfile))||[],{enabledStructures:u,disabledStructures:d}=a||{},p=d==null?void 0:d.find(v=>{const{stages:f,stageSequences:m,structureTypes:g,feedProfiles:h}=v;return(!(h!=null&&h.length)||Array.isArray(h)&&h.some(_=>l.includes(_)))&&(!(f!=null&&f.length)||Array.isArray(f)&&(f==null?void 0:f.includes(n.stage)))&&(!(g!=null&&g.length)||Array.isArray(g)&&(g==null?void 0:g.includes(n.structureType)))&&(!(m!=null&&m.length)||Array.isArray(m)&&m.includes(n.stageSequence))});return{enabledStructures:u,actionsDisabled:p,actionsPolicy:a}}function jE({activePositionOverrides:t,activeDrawPositions:e,action:r}){return r&&t.includes(r)?!0:!e.length}function RE({enabledStructures:t,drawDefinition:e,structure:r}){var n;if(t===!1)return{};if(!(t!=null&&t.length))return{policyActions:{enabledActions:[],disabledActions:[]}};const{stage:o,stageSequence:i,structureType:s}=r||{},a=(n=e.links)==null?void 0:n.filter(u=>{var d;return((d=u==null?void 0:u.target)==null?void 0:d.structureId)===(r==null?void 0:r.structureId)}),c=(a==null?void 0:a.map(({target:u})=>u.feedProfile))||[];return{policyActions:t.find(u=>{const{stages:d,stageSequences:p,structureTypes:v,feedProfiles:f}=u||{},m=!(d!=null&&d.length)||Array.isArray(d)&&d.includes(o),g=!(p!=null&&p.length)||Array.isArray(p)&&p.includes(i),h=!(v!=null&&v.length)||Array.isArray(v)&&v.includes(s),_=!(f!=null&&f.length)||Array.isArray(f)&&f.some(I=>c.includes(I));if(g&&h&&_&&u&&m)return!0})}}function fr({action:t,policyActions:e}){var r;const n=!(e!=null&&e.enabledActions)||((r=e==null?void 0:e.disabledActions)==null?void 0:r.length)&&e.disabledActions.includes(t);return n?!1:!!(((e==null?void 0:e.enabledActions.length)===0||(e==null?void 0:e.enabledActions.includes(t)))&&!n)}const dQ="replaceTieMatchUpParticipantId",pQ="assignTieMatchUpParticipantId",FE="removeTieMatchUpParticipantId",fQ="substituteParticipant",LE="REMOVE_SUBSTITUTION",vQ="REPLACE_PARTICIPANT",mQ="REMOVE_PARTICIPANT",VE="setMatchUpStatus",xE="SUBSTITUTION",gQ="SCHEDULE",BE="REFEREE",hQ="STATUS",kE="START",_Q="SCORE",GE="END";function mm({restrictAdHocRoundParticipants:t=!0,policyDefinitions:e,tournamentParticipants:r=[],inContextDrawMatchUps:n,tournamentRecord:o,drawDefinition:i,participantId:s,matchUpsMap:a,sideNumber:c,matchUpId:l,event:u}){var d,p,v,f,m,g,h,_,I,P,O,y,S,T,E,b,N;if(!i)return{error:pe};if(!l)return{error:Ut};if(c&&![1,2].includes(c))return{error:Z,context:{sideNumber:c}};const w=(d=e==null?void 0:e[po])==null?void 0:d.otherFlightEntries,{drawId:$}=i,{matchUp:U,structure:A}=nt({drawDefinition:i,matchUpId:l,event:u});if(!U)return{error:kr};const{appliedPolicies:M}=at({tournamentRecord:o,drawDefinition:i,structure:A,event:u});Object.assign(M,e||{});const{enabledStructures:C}=DE({actionType:vm,appliedPolicies:M,drawDefinition:i,structure:A}),{policyActions:D}=RE({enabledStructures:C,drawDefinition:i,structure:A});a=a||Kt({drawDefinition:i}),n||({matchUps:n}=Nt({includeByeMatchUps:!0,tournamentParticipants:r,inContext:!0,drawDefinition:i,matchUpsMap:a,event:u}));const F=n.find(ae=>ae.matchUpId===l),R=c&&((p=F.sides)==null?void 0:p.find(ae=>ae.sideNumber===c)),G=((v=F.sides)==null?void 0:v.map(ae=>{var me;return ae.participantId||((me=ae.participant)==null?void 0:me.participantid)}).filter(Boolean))||[],{assignedPositions:x,allPositionsAssigned:z}=Et({structure:A}),{structureId:j}=A||{},V=[];if(!j)return{validActions:V};if(Po({drawDefinition:i,structure:A})){const ae=(A.matchUps||[]).filter(({roundNumber:ge})=>ge===U.roundNumber),me=(i==null?void 0:i.entries.filter(({entryStatus:ge})=>os.includes(ge)).map(Xe))||[],Se=ae.map(ge=>(ge.sides||[]).flatMap(Xe)).filter(Boolean),ce=me.filter(ge=>!G.includes(ge)&&(!t||!Se.includes(ge))),Pe=r==null?void 0:r.filter(ge=>ce==null?void 0:ce.includes(ge.participantId));Pe==null||Pe.forEach(ge=>{const Ne=(i.entries||[]).find(De=>De.participantId===ge.participantId);ge.entryPosition=Ne==null?void 0:Ne.entryPosition}),ce.length&&V.push({payload:{drawId:$,matchUpId:l,structureId:j,sideNumber:c},method:Yy,type:la,availableParticipantIds:ce,participantsAvailable:Pe});const Ae=(u==null?void 0:u.entries)||[],ye=IQ({eventEntries:Ae,structure:A});let Ue=Ve(me.concat(ye));if(w){const{flightProfile:ge}=It({event:u}),Ne=(f=ge==null?void 0:ge.flights)==null?void 0:f.filter(De=>De.drawId!==$).flatMap(De=>De.drawEntries.filter(he=>he.participantId&&![Go,qr,ns].includes(he.entryStatus)).map(({participantId:he})=>he)).filter(Boolean);Ne!=null&&Ne.length&&Ue.push(...Ne)}Ue=Ue.filter(ge=>!G.includes(ge)&&!ce.includes(ge)&&(!t||!Se.includes(ge)));const be=r==null?void 0:r.filter(ge=>Ue.includes(ge.participantId));be.forEach(ge=>{const Ne=(i.entries||[]).find(De=>De.participantId===ge.participantId);ge.entryPosition=Ne==null?void 0:Ne.entryPosition}),be.sort((ge,Ne)=>(ge.entryPosition||1/0)-(Ne.entryPosition||1/0)),Ue.length&&V.push({payload:{drawId:$,matchUpId:l,structureId:j,sideNumber:c},availableParticipantIds:Ue,participantsAvailable:be,method:Yy,type:un})}const L=wi({drawDefinition:i,structure:A}),q=x.filter(ae=>ae.participantId).map(ae=>ae.drawPosition),k=x.filter(ae=>ae.bye).map(ae=>ae.drawPosition),H=U.collectionId,Q=U.matchUpStatus===qe||!H&&((m=U.drawPositions)==null?void 0:m.reduce((ae,me)=>k.includes(me)||ae,!1));if(Q)return{validActions:V,isByeMatchUp:Q};fr({policyActions:D,action:BE})&&V.push({type:BE,payload:{matchUpId:l}});const K=!jc({matchUpStatus:U.matchUpStatus}),Y=(g=M==null?void 0:M.scoring)==null?void 0:g.structures,J=(Y==null?void 0:Y.stage)&&(Y==null?void 0:Y.stage[A.stage]),te=(J==null?void 0:J.stageSequence)&&J.stageSequence[A.stageSequence],oe=!(((h=M==null?void 0:M.scoring)==null?void 0:h.requireAllPositionsAssigned)||(J==null?void 0:J.requireAllPositionsAssigned)||(te==null?void 0:te.requireAllPositionsAssigned))||z,se=U.sides&&U.sides.filter(ae=>ae==null?void 0:ae.participantId).length===2;let ve;const X=[_t,bt].includes(U.matchUpStatus),ie=sr({inContextDrawMatchUps:n,drawDefinition:i,matchUpId:l});ve=$i({inContextDrawMatchUps:n,drawDefinition:i,targetData:ie});const $e=(((_=F==null?void 0:F.drawPositions)==null?void 0:_.length)===2&&F.drawPositions.every(ae=>q.includes(ae))&&((I=F==null?void 0:F.sides)==null?void 0:I.length)===2&&F.sides.every(({participantId:ae})=>ae)||se)&&!(X&&ve),re={type:da,method:Ky,payload:{drawId:$,matchUpId:l,penaltyCode:void 0,penaltyType:void 0,participantIds:[],notes:void 0}};if(K&&V.push({type:gQ,method:VE,payload:{drawId:$,matchUpId:l,schedule:{}}}),fr({policyActions:D,action:da})&&(R!=null&&R.participant||!c&&(G!=null&&G.length))&&V.push(re),K&&$e&&V.push({type:hQ}),oe&&$e){const{matchUpId:ae,matchUpFormat:me}=U,Se={drawId:$,matchUpId:ae,matchUpFormat:me,outcome:{scoreStringSide1:void 0,scoreStringSide2:void 0,sets:[]},winningSide:void 0};V.push({info:"set outcome and winningSide",method:VE,type:_Q,payload:Se}),fr({policyActions:D,action:kE})&&V.push({type:kE}),fr({policyActions:D,action:GE})&&V.push({type:GE})}if(H){const ae=F.gender===yo&&F.sideNumber&&F.sides.filter(({particiapntId:Ke})=>Ke).length===1&&((y=(O=(P=F.sides.find(Ke=>Ke.participant))==null?void 0:P.participant)==null?void 0:O.person)==null?void 0:y.sex),me=F.matchUpType,Se=F.gender,Pe=F.sides.flatMap(Ke=>{var At;return((At=Ke.participant)==null?void 0:At.individualParticipants)||Ke.participant}).filter(Boolean).map(Xe),Ae=F.sides.filter(Ke=>!c||Ke.sideNumber===c).flatMap(Ke=>{var At;return((At=Ke.participant)==null?void 0:At.individualParticipants)||Ke.participant}).filter(Boolean),ye=Ae.map(Xe),be=n.find(Ke=>Ke.matchUpId===F.matchUpTieId).sides.map(Ke=>Ke.participant.individualParticipants.filter(({participantId:At,person:rr})=>!ye.includes(At)&&(!Se||Se===ia||rr.sex===Se||Se===yo&&ae&&rr.sex!==ae))),ge=c?be[c-1]:be.map((Ke,At)=>({participants:Ke,sideNumber:At+1})),Ne=c?(S=be[c-1])==null?void 0:S.map(Xe):be.map((Ke,At)=>({participants:Ke==null?void 0:Ke.map(Xe),sideNumber:At+1})),De=c&&(me===ci&&!ye.length||me===Jr&&ye.length<2)||!c&&(me===ci&&ye.length<2||me===Jr&&ye.length<4),he=Ne.filter(Ke=>!Pe.includes(Ke)),ke=ge.filter(({participantId:Ke})=>he.includes(Ke));if(De&&he.length&&V.push({availableParticipantIds:he,method:pQ,availableParticipants:ke,type:la,payload:{participantId:void 0,tieMatchUpId:l,drawId:$}}),ye!=null&&ye.length&&(!Dt(U)||(T=R==null?void 0:R.substitutions)!=null&&T.length)&&V.push({method:FE,type:mQ,existingParticipantIds:ye,payload:{participantId:void 0,tieMatchUpId:l,drawId:$}}),(!c&&(ye!=null&&ye.length)||c&&(R!=null&&R.participant))&&V.push({availableParticipantIds:he,method:dQ,availableParticipants:ke,type:vQ,existingParticipantIds:ye,payload:{existingParticipantId:void 0,participantId:void 0,tieMatchUpId:l,drawId:$}}),fr({policyActions:D,action:LE})&&((E=R==null?void 0:R.substitutions)!=null&&E.length)){const Ke=((b=R.participant)==null?void 0:b.participantType)===Me&&[R.participantId]||((N=R.participant)==null?void 0:N.participantType)===we&&R.participant.individualParticipantIds||[],At=R.substitutions.map(rr=>rr.participantId).filter(rr=>Ke.includes(rr));(!s||At.includes(s))&&V.push({method:FE,type:LE,substitutedParticipantIds:At,payload:{participantId:void 0,tieMatchUpId:l,drawId:$}})}const je=e==null?void 0:e[xi],Ze=je==null?void 0:je.substituteWithoutScore,ot=je==null?void 0:je.substituteAfterCompleted;if(fr({policyActions:D,action:xE})&&G.length===2&&(!c&&(ye!=null&&ye.length)||c&&(R!=null&&R.participant))&&(Ze||Dt(U))&&(ot||!Lt.includes(U.matchUpStatus))&&Ae.length&&ge.length){const Ke=Ae.map(Xe);V.push({info:"list of team players available for substitution",method:fQ,availableParticipantIds:Ne,existingParticipantIds:Ke,availableParticipants:ge,existingParticipants:Ae,type:xE,payload:{substituteParticipantId:void 0,existingParticipantId:void 0,sideNumber:c,matchUpId:l,drawId:$}})}}return{structureIsComplete:L,validActions:V,isDoubleExit:X}}function IQ({eventEntries:t,structure:e}){const r=o=>o.entryStatus===un&&ME({structure:e,entry:o}),n=(o,i)=>(o.entryPosition||1/0)-(i.entryPosition||1/0);return t.filter(r).sort(n).map(Xe)}function WE({policyDefinitions:t,tournamentRecord:e,drawDefinition:r,participantId:n,sideNumber:o,matchUpId:i,drawId:s,event:a}){if(!e)return{error:ee};if(!s){const{matchUps:l}=Bt({tournamentRecord:e});s=l.reduce((p,v)=>v.matchUpId===i?v.drawId:p,void 0),r=(e.events||[]).map(p=>p.drawDefinitions||[]).flat().reduce((p,v)=>v.drawId===s?v:p,void 0)}const{policyDefinitions:c}=Hi({policyTypes:[po],tournamentRecord:e,drawDefinition:r,event:a});return t=t||c,s?mm({tournamentParticipants:e.participants,policyDefinitions:t,drawDefinition:r,participantId:n,sideNumber:o,matchUpId:i,drawId:s,event:a}):{error:_n}}function PQ({tournamentRecords:t,participantId:e,tournamentId:r,sideNumber:n,matchUpId:o,eventId:i,drawId:s}={}){if(typeof t!="object"||typeof r!="string"||typeof o!="string"||typeof s!="string")return{error:Z};const a=t[r];if(!a)return{error:ee};const c=xt({tournamentRecord:a,eventId:i,drawId:s});return c.error?c:WE({drawDefinition:c.drawDefinition,tournamentRecord:a,participantId:e,sideNumber:n,matchUpId:o,drawId:s})}function yQ({ignoreDisabled:t=!0,tournamentRecords:e,venueIds:r=[],dates:n=[]}){if(!Array.isArray(n))return{error:Z,dates:n};if(!Array.isArray(r))return{error:Z,venueIds:r};if(!n.every(Nr))return{error:cr};const i=ms({tournamentRecords:e,ignoreDisabled:t,dates:n});if(i.error)return i;const s=i.venues.filter(({venueId:d})=>!(r!=null&&r.length)||r.includes(d)),a=i.courts.reduce((d,p)=>(p.dateAvailability.forEach(({date:v})=>{d.includes(v)||d.push(v)}),d),[]).filter(d=>!n.length||n.includes(d)),c={venueIds:s.map(({venueId:d})=>d)},{matchUps:l}=Oo({afterRecoveryTimes:!0,tournamentRecords:e,matchUpFilters:c});return{venuesReport:s.map(d=>SQ(a,d,l))}}function SQ(t,e,r){const{venueId:n,courts:o,venueName:i}=e,s={};return t.forEach(a=>{let c=0,l=0,u=0;for(const v of o){const f=v.dateAvailability.find(h=>h.date===a),m=f&&va({courtDate:f}),g=m==null?void 0:m.reduce((h,_)=>{const{startTime:I,endTime:P}=_,O=Re(P)-Re(I);return h+O},0);g&&(u+=1),c+=g}const d=r.filter(({schedule:v})=>v.venueId===n&&kn(a,v.scheduledDate));d.forEach(({schedule:v})=>{const f=rt(v.scheduledTime),m=lr(f,v.averageMinutes),g=Re(m)-Re(f);l+=g});const p=c?(l/c*100).toFixed(2):"100";s[a]={scheduledMatchUpsCount:d.length,availableCourts:u,availableMinutes:c,scheduledMinutes:l,percentUtilization:p}}),{venueId:n,venueName:i,venueReport:s}}var OQ=Object.defineProperty,bQ=Object.defineProperties,TQ=Object.getOwnPropertyDescriptors,HE=Object.getOwnPropertySymbols,EQ=Object.prototype.hasOwnProperty,wQ=Object.prototype.propertyIsEnumerable,qE=(t,e,r)=>e in t?OQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$Q=(t,e)=>{for(var r in e||(e={}))EQ.call(e,r)&&qE(t,r,e[r]);if(HE)for(var r of HE(e))wQ.call(e,r)&&qE(t,r,e[r]);return t},NQ=(t,e)=>bQ(t,TQ(e));function AQ({tournamentRecords:t}){const e=Object.keys(t);return NQ($Q({},B),{tournamentIds:e})}const UQ={getParticipantScaleItem:iQ,getCompetitionDateRange:PT,getTournamentIds:AQ,competitionScheduleMatchUps:Jv,getSchedulingProfileIssues:lQ,allCompetitionMatchUps:Oo,competitionMatchUps:cv,matchUpActions:PQ,getCompetitionVenues:vv,getVenuesAndCourts:ms,getVenuesReport:yQ,credits:_d};var CQ=Object.defineProperty,YE=Object.getOwnPropertySymbols,MQ=Object.prototype.hasOwnProperty,DQ=Object.prototype.propertyIsEnumerable,zE=(t,e,r)=>e in t?CQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jQ=(t,e)=>{for(var r in e||(e={}))MQ.call(e,r)&&zE(t,r,e[r]);if(YE)for(var r of YE(e))DQ.call(e,r)&&zE(t,r,e[r]);return t};function KE({tournamentRecord:t,courtIds:e,dates:r}){if(!t)return{error:ee};if(!Array.isArray(e))return{info:zt("courtIds"),error:Oe};const n=Array.isArray(r)&&r.length?{dates:r}:!0,o=i=>tt({creationTime:!1,element:i,extension:{value:n,name:en}});for(const i of t.venues||[])for(const s of i.courts||[])if(e!=null&&e.includes(s.courtId)){const a=o(s);if(a.error)return a}return jQ({},B)}var RQ=Object.defineProperty,QE=Object.getOwnPropertySymbols,FQ=Object.prototype.hasOwnProperty,LQ=Object.prototype.propertyIsEnumerable,JE=(t,e,r)=>e in t?RQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,VQ=(t,e)=>{for(var r in e||(e={}))FQ.call(e,r)&&JE(t,r,e[r]);if(QE)for(var r of QE(e))LQ.call(e,r)&&JE(t,r,e[r]);return t};function xQ({tournamentRecords:t,courtIds:e,dates:r}){if(!t)return{error:Fe};if(!Array.isArray(e))return{error:Oe,info:zt("courtIds")};for(const n of Object.values(t))KE({tournamentRecord:n,courtIds:e,dates:r});return VQ({},B)}var BQ=Object.defineProperty,ZE=Object.getOwnPropertySymbols,kQ=Object.prototype.hasOwnProperty,GQ=Object.prototype.propertyIsEnumerable,XE=(t,e,r)=>e in t?BQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,WQ=(t,e)=>{for(var r in e||(e={}))kQ.call(e,r)&&XE(t,r,e[r]);if(ZE)for(var r of ZE(e))GQ.call(e,r)&&XE(t,r,e[r]);return t};function ew({tournamentRecord:t,venueIds:e}){if(!t)return{error:ee};if(!Array.isArray(e))return{error:Oe,info:zt("venueIds")};for(const r of t.venues||[])if(e!=null&&e.includes(r.venueId)){const n=tt({creationTime:!1,element:r,extension:{name:en,value:!0}});if(n.error)return n}return WQ({},B)}var HQ=Object.defineProperty,tw=Object.getOwnPropertySymbols,qQ=Object.prototype.hasOwnProperty,YQ=Object.prototype.propertyIsEnumerable,rw=(t,e,r)=>e in t?HQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zQ=(t,e)=>{for(var r in e||(e={}))qQ.call(e,r)&&rw(t,r,e[r]);if(tw)for(var r of tw(e))YQ.call(e,r)&&rw(t,r,e[r]);return t};function KQ({tournamentRecords:t,venueIds:e}){if(!t)return{error:Fe};if(!Array.isArray(e))return{error:Oe,info:zt("venueIds")};for(const r of Object.values(t))ew({tournamentRecord:r,venueIds:e});return zQ({},B)}var QQ=Object.defineProperty,nw=Object.getOwnPropertySymbols,JQ=Object.prototype.hasOwnProperty,ZQ=Object.prototype.propertyIsEnumerable,ow=(t,e,r)=>e in t?QQ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,XQ=(t,e)=>{for(var r in e||(e={}))JQ.call(e,r)&&ow(t,r,e[r]);if(nw)for(var r of nw(e))ZQ.call(e,r)&&ow(t,r,e[r]);return t};function iw({tournamentRecord:t,courtIds:e,enableAll:r,dates:n}){if(!t)return{error:ee};if(!Array.isArray(e)&&!r)return{error:Oe,info:zt("courtIds")};for(const o of t.venues||[])for(const i of o.courts||[])if(r||e!=null&&e.includes(i.courtId))if(Array.isArray(n)){const{extension:s}=Or({element:i,name:en});if(s){let a=s.value;Array.isArray(a.dates)&&(a.dates=a.dates.filter(c=>!n.includes(c))),tt({creationTime:!1,element:i,extension:{name:en,value:a}})}}else sn({element:i,name:en});return XQ({},B)}var eJ=Object.defineProperty,sw=Object.getOwnPropertySymbols,tJ=Object.prototype.hasOwnProperty,rJ=Object.prototype.propertyIsEnumerable,aw=(t,e,r)=>e in t?eJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,nJ=(t,e)=>{for(var r in e||(e={}))tJ.call(e,r)&&aw(t,r,e[r]);if(sw)for(var r of sw(e))rJ.call(e,r)&&aw(t,r,e[r]);return t};function oJ({tournamentRecords:t,enableAll:e,courtIds:r,dates:n}){if(!t)return{error:Fe};if(!e&&!Array.isArray(r))return{error:Oe,info:zt("courtIds")};for(const o of Object.values(t))iw({tournamentRecord:o,courtIds:r,enableAll:e,dates:n});return nJ({},B)}var iJ=Object.defineProperty,cw=Object.getOwnPropertySymbols,sJ=Object.prototype.hasOwnProperty,aJ=Object.prototype.propertyIsEnumerable,lw=(t,e,r)=>e in t?iJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cJ=(t,e)=>{for(var r in e||(e={}))sJ.call(e,r)&&lw(t,r,e[r]);if(cw)for(var r of cw(e))aJ.call(e,r)&&lw(t,r,e[r]);return t};function uw({tournamentRecord:t,venueIds:e,enableAll:r}){if(!t)return{error:ee};if(!Array.isArray(e)&&!r)return{error:Oe,info:zt("venueIds")};for(const n of t.venues||[])(r||e!=null&&e.includes(n.venueId))&&sn({element:n,name:en});return cJ({},B)}var lJ=Object.defineProperty,dw=Object.getOwnPropertySymbols,uJ=Object.prototype.hasOwnProperty,dJ=Object.prototype.propertyIsEnumerable,pw=(t,e,r)=>e in t?lJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,pJ=(t,e)=>{for(var r in e||(e={}))uJ.call(e,r)&&pw(t,r,e[r]);if(dw)for(var r of dw(e))dJ.call(e,r)&&pw(t,r,e[r]);return t};function fJ({tournamentRecords:t,venueIds:e,enableAll:r}){if(!t)return{error:Fe};if(!r&&!Array.isArray(e))return{error:Oe,info:zt("venueIds")};for(const n of Object.values(t))uw({tournamentRecord:n,venueIds:e,enableAll:r});return pJ({},B)}var vJ=Object.defineProperty,fw=Object.getOwnPropertySymbols,mJ=Object.prototype.hasOwnProperty,gJ=Object.prototype.propertyIsEnumerable,vw=(t,e,r)=>e in t?vJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hJ=(t,e)=>{for(var r in e||(e={}))mJ.call(e,r)&&vw(t,r,e[r]);if(fw)for(var r of fw(e))gJ.call(e,r)&&vw(t,r,e[r]);return t};function mw({tournamentRecord:t,drawDefinition:e,matchUpId:r,drawId:n}){const o="removeCourtAssignment";if(!r)return{error:Ut};if(!e&&!n)return{error:wr};let i;if(!e){if(!t)return{error:ee};({drawDefinition:e}=xt({tournamentRecord:t,drawId:n}))}if(e)({matchUp:i}=nt({drawDefinition:e,matchUpId:r}));else{if(!t)return{error:ee};const{matchUps:s}=av({tournamentRecord:t});({matchUp:i}=R_({matchUps:s,matchUpId:r}))}return i?(i.timeItems&&i.timeItems.find(a=>[Xi,Vo].includes(a.itemType))&&(i.timeItems=i.timeItems.filter(({itemType:a})=>![Xi,Vo].includes(a)),Qe({tournamentId:t==null?void 0:t.tournamentId,context:o,drawDefinition:e,matchUp:i})),hJ({},B)):{error:kr}}function gm({matchUpsCount:t=0}){const r=`Schedule would be deleted from ${t} ${t===1?"matchUp":"matchUps"}; use { force: true }`;return{error:uL,info:r}}var _J=Object.defineProperty,gw=Object.getOwnPropertySymbols,IJ=Object.prototype.hasOwnProperty,PJ=Object.prototype.propertyIsEnumerable,hw=(t,e,r)=>e in t?_J(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_w=(t,e)=>{for(var r in e||(e={}))IJ.call(e,r)&&hw(t,r,e[r]);if(gw)for(var r of gw(e))PJ.call(e,r)&&hw(t,r,e[r]);return t};function hm({tournamentRecord:t,venueId:e,force:r}){if(!t)return{error:ee};if(typeof e!="string")return{error:Uo};const n={venueIds:[e]},{matchUps:o}=Bt({tournamentRecord:t,contextFilters:n});if(!o.length||r)for(const s of o){const a=mw({matchUpId:s.matchUpId,drawId:s.drawId,tournamentRecord:t});if(a.error)return a}else return gm({matchUpsCount:o.length});let i;return t.venues=(t.venues||[]).filter(s=>{if(s.venueId!==e)return!0;i=!0}),i?(xe({payload:{venueId:e,tournamentId:t.tournamentId},topic:EI,key:e}),_w({},B)):{error:oi}}function yJ({tournamentRecord:t,venueIds:e,force:r}){if(!t)return{error:ee};if(!Array.isArray(e))return{error:Z};for(const n of t.venues||[]){const{venueId:o}=n;if(e.includes(o)){const{venueId:i}=n,s=hm({tournamentRecord:t,venueId:i,force:r});if(s.error)return s}}return _w({},B)}function SJ({tournamentRecords:t,venueId:e,force:r}){if(!t)return{error:Fe};if(typeof e!="string")return{error:Uo};let n;for(const o of Object.values(t)){const i=hm({tournamentRecord:o,venueId:e,force:r});if(i.error&&i.error!==oi)return i;i.success&&(n=!0)}return bT({tournamentRecords:t}),n?B:{error:oi}}function OJ({tournamentRecord:t,schedulingProfile:e}){return t?Array.isArray(e)?yd({tournamentRecord:t,schedulingProfile:e}):{error:Z}:{error:ee}}function bJ({tournamentRecord:t,schedulingProfile:e}){return pi({tournamentRecord:t,extension:{name:Do,value:e}})}function Pd({tournamentRecord:t}){var e;if(!t)return{error:ee};const r=t.tournamentId,{extension:n}=Sr({name:Do,tournamentRecord:t});let o=(n==null?void 0:n.value)||[];if(o.length){const i=(e=t.venues)==null?void 0:e.map(({venueId:d,courts:p})=>(p==null?void 0:p.length)&&d),{eventIds:s,drawIds:a}=xu({tournamentRecords:{[r]:t}}),{updatedSchedulingProfile:c,modifications:l,issues:u}=fd({schedulingProfile:o,venueIds:i,eventIds:s,drawIds:a});if(l){o=c;const d=bJ({tournamentRecord:t,schedulingProfile:o});return d.error?d:{schedulingProfile:o,modifications:l,issues:u}}}return{schedulingProfile:o,modifications:0}}function yd({tournamentRecord:t,schedulingProfile:e,requireCourts:r=!0}){if(!e){const{modifications:c,issues:l}=Pd({tournamentRecord:t});return{success:!c,modifications:c,issues:l}}const{venueIds:n,eventIds:o,drawIds:i}=vT({tournamentRecord:t,requireCourts:r}),{modifications:s,issues:a}=fd({schedulingProfile:e,venueIds:n,eventIds:o,drawIds:i});return{success:!s,modifications:s,issues:a}}function _m({scheduleVisibilityFilters:t,tournamentRecord:e,matchUpFilters:r,venueMatchUps:n,courtId:o}){if(!e&&!Array.isArray(n))return{error:ee};if(!o)return{error:Fs};const{schedulingProfile:i}=Pd({tournamentRecord:e});if(Array.isArray(n))return{matchUps:c({matchUps:n,courtId:o})};const{matchUps:s}=Bt({scheduleVisibilityFilters:t,tournamentRecord:e,matchUpFilters:r});return{matchUps:c({matchUps:s,courtId:o})};function c({matchUps:l,courtId:u}){const d=l.filter(p=>{var v,f,m;const g=(f=(v=p.schedule)==null?void 0:v.allocatedCourts)==null?void 0:f.map(({courtId:h})=>h);return((m=p.schedule)==null?void 0:m.courtId)===u||(g==null?void 0:g.includes(u))});return vd({matchUps:d,schedulingProfile:i})}}function TJ({scheduleVisibilityFilters:t,tournamentRecord:e,matchUpFilters:r,venueId:n}){if(!e)return{error:ee};if(!n)return{error:Uo};const{schedulingProfile:o}=Pd({tournamentRecord:e}),{matchUps:i}=Bt({scheduleVisibilityFilters:t,tournamentRecord:e,matchUpFilters:r});return{matchUps:a({matchUps:i,venueId:n})};function a({matchUps:c,venueId:l}){const u=c.filter(d=>{var p,v,f;const m=(v=(p=d.schedule)==null?void 0:p.allocatedCourts)==null?void 0:v.map(({venueId:g})=>g);return((f=d.schedule)==null?void 0:f.venueId)===l||(m==null?void 0:m.includes(l))});return vd({matchUps:u,schedulingProfile:o})}}var EJ=Object.defineProperty,Iw=Object.getOwnPropertySymbols,wJ=Object.prototype.hasOwnProperty,$J=Object.prototype.propertyIsEnumerable,Pw=(t,e,r)=>e in t?EJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,NJ=(t,e)=>{for(var r in e||(e={}))wJ.call(e,r)&&Pw(t,r,e[r]);if(Iw)for(var r of Iw(e))$J.call(e,r)&&Pw(t,r,e[r]);return t};function yw({tournamentRecord:t,drawDefinition:e,disableNotice:r,courtId:n,force:o}){const i=Zi({tournamentRecord:t,courtId:n});if(i.error)return i;const s=i.venue,{matchUps:a}=_m({tournamentRecord:t,courtId:n});if(!a.length||o){for(const c of a){const l=mw({matchUpId:c.matchUpId,drawId:c.drawId,tournamentRecord:t,drawDefinition:e});if(l.error)return l}s.courts=(s.courts||[]).filter(c=>c.courtId!==n),r||xe({topic:Ji,payload:{venue:s,tournamentId:t.tournamentId},key:s.venueId})}else return gm({matchUpsCount:a.length});return NJ({},B)}var AJ=Object.defineProperty,Sw=Object.getOwnPropertySymbols,UJ=Object.prototype.hasOwnProperty,CJ=Object.prototype.propertyIsEnumerable,Ow=(t,e,r)=>e in t?AJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,MJ=(t,e)=>{for(var r in e||(e={}))UJ.call(e,r)&&Ow(t,r,e[r]);if(Sw)for(var r of Sw(e))CJ.call(e,r)&&Ow(t,r,e[r]);return t};function DJ({tournamentRecords:t,courtId:e,force:r}){if(!t)return{error:Fe};if(typeof e!="string")return{error:Fs};let n,o;for(const i of Object.values(t)){if(o=yw({tournamentRecord:i,courtId:e,force:r}),o.error&&o.error!==Rp)return o;o.success&&(n=!0)}return n?MJ({},B):o}function Sd(t){return parseInt(t)}function bw({startTime:t,endTime:e}={}){if(!si.test(t)||!si.test(e))return!1;const[r,n]=t.split(":").map(Sd),[o,i]=e.split(":").map(Sd);return o<r?!1:!(r===o&&i<n)}function jJ(t,e){const[r,n]=t.startTime.split(":").map(Sd),[o,i]=e.startTime.split(":").map(Sd);return r<o?-1:r>o?1:n<i?-1:n>i?1:0}function Tw({dateAvailability:t}){if(!t)return{error:$F};if(!Array.isArray(t))return{error:Up};const e="Dates must be formated => YYYY-MM-DD",r="Times must be 24 hour => 00:00";for(const n of t){if(typeof n!="object")return{error:Up};const{date:o,startTime:i,endTime:s,bookings:a=[]}=n;if(!i||!s)return{error:Up};if(o&&!Sn.test(o))return{error:cr,dateAvailability:{date:o},info:e};if(!si.test(i))return{error:Wr,dateAvailability:{startTime:i},info:r};if(!si.test(s))return{error:Wr,dateAvailability:{endTime:s},info:r};if(i===s)return{error:Wr,dateAvailability:{startTime:i,endTime:s},info:"startTime and endTime are equivalent"};if(!bw({startTime:i,endTime:s}))return{error:Wr,dateAvailability:{startTime:i,endTime:s},info:"endTime must be after startTime"};if(a){if(!Array.isArray(a))return{error:Ap};for(const c of a){if(typeof c!="object")return{error:Ap};const{startTime:l,endTime:u}=c;if(!si.test(l))return{error:Wr,booking:{startTime:l},info:r};if(!si.test(u))return{error:Wr,booking:{endTime:u},info:r};if(l===u)return{error:Wr,dateAvailability:{startTime:l,endTime:u},info:"startTime and endTime are equivalent"};if(!bw({startTime:l,endTime:u}))return{error:Wr,dateAvailability:{startTime:l,endTime:u},info:"endTime must be after startTime"}}}}return{valid:!0}}var RJ=Object.defineProperty,FJ=Object.defineProperties,LJ=Object.getOwnPropertyDescriptors,Ew=Object.getOwnPropertySymbols,VJ=Object.prototype.hasOwnProperty,xJ=Object.prototype.propertyIsEnumerable,ww=(t,e,r)=>e in t?RJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$w=(t,e)=>{for(var r in e||(e={}))VJ.call(e,r)&&ww(t,r,e[r]);if(Ew)for(var r of Ew(e))xJ.call(e,r)&&ww(t,r,e[r]);return t},BJ=(t,e)=>FJ(t,LJ(e));function Nw({tournamentRecord:t,dateAvailability:e,disableNotice:r,venueMatchUps:n,courtId:o,force:i}){if(!t)return{error:ee};if(!o)return{error:Fs};let s=Tw({dateAvailability:e});if(s.error)return s;const{updatedDateAvailability:a,totalMergeCount:c}=kJ(e);if(e=a,s=Zi({tournamentRecord:t,courtId:o}),s.error)return s;const{court:l,venue:u}=s,{matchUps:d}=_m({tournamentRecord:t,venueMatchUps:n,courtId:o});return d!=null&&d.length&&console.log("scheduled court matchUps",d.length),l.dateAvailability=e,r||xe({payload:{venue:u,tournamentId:t.tournamentId},topic:Ji,key:u.venueId}),BJ($w({},B),{totalMergeCount:c})}function kJ(t){let e=0;const r=t.reduce((o,i)=>{const{date:s,startTime:a,endTime:c,bookings:l}=i;return o[s]||(o[s]=[]),o[s].push({startTime:a,endTime:c,bookings:l}),o},{}),n=[];return Object.keys(r).forEach(o=>{r[o].sort(jJ);const{mergedAvailability:i,mergeCount:s}=GJ(r[o]);n.push(...i.map(a=>$w({date:o},a))),e+=s}),{updatedDateAvailability:n,totalMergeCount:e}}function GJ(t){let e,r,n,o=t.length,i=0;const s=[];for(;t.length&&o;){const c=t.shift(),{startTime:l,endTime:u,bookings:d}=c;if(o-=1,!e)e=l,n=d,r=u;else if(nc(ht(r),ht(l),!1)>0){const v={startTime:e,endTime:r};n!=null&&n.length&&(v.bookings=n),s.push(v),e=l,n=d,r=u}else d&&(n?n.push(d):n=d),r=u,i+=1}const a={startTime:e,endTime:r};return n!=null&&n.length&&(a.bookings=n),s.push(a),{mergedAvailability:s,mergeCount:i}}const Aw=()=>({altitude:void 0,courtId:void 0,courtName:"",courtDimensions:void 0,latitude:void 0,longitude:void 0,surfaceCategory:void 0,surfaceType:void 0,surfaceDate:void 0,dateAvailability:[],onlineResources:[],pace:void 0,notes:void 0});var WJ=Object.defineProperty,HJ=Object.defineProperties,qJ=Object.getOwnPropertyDescriptors,Uw=Object.getOwnPropertySymbols,YJ=Object.prototype.hasOwnProperty,zJ=Object.prototype.propertyIsEnumerable,Cw=(t,e,r)=>e in t?WJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,KJ=(t,e)=>{for(var r in e||(e={}))YJ.call(e,r)&&Cw(t,r,e[r]);if(Uw)for(var r of Uw(e))zJ.call(e,r)&&Cw(t,r,e[r]);return t},QJ=(t,e)=>HJ(t,qJ(e));function Im({tournamentRecord:t,modifications:e,disableNotice:r,venueMatchUps:n,courtId:o,force:i}){if(!t)return{error:ee};if(!o)return{error:Fs};if(!e||typeof e!="object")return{error:xn};const s=Zi({tournamentRecord:t,courtId:o});if(s.error)return s;const{court:a,venue:c}=s,l=Object.keys(Aw()).filter(v=>v!=="courtId");if(!Object.keys(e).filter(v=>l.includes(v)).length)return{error:Lp};const d=l.filter(v=>!["dateAvailability"].includes(v));if(Object.keys(e).filter(v=>d.includes(v)).forEach(v=>Object.assign(a,{[v]:e[v]})),e.dateAvailability){const v=Nw({dateAvailability:e.dateAvailability,tournamentRecord:t,venueMatchUps:n,disableNotice:r,courtId:o,force:i});if(v.error)return v}return r||xe({payload:{venue:c,tournamentId:t.tournamentId},topic:Ji,key:c.venueId}),QJ(KJ({},B),{court:ue(a)})}var JJ=Object.defineProperty,Mw=Object.getOwnPropertySymbols,ZJ=Object.prototype.hasOwnProperty,XJ=Object.prototype.propertyIsEnumerable,Dw=(t,e,r)=>e in t?JJ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eZ=(t,e)=>{for(var r in e||(e={}))ZJ.call(e,r)&&Dw(t,r,e[r]);if(Mw)for(var r of Mw(e))XJ.call(e,r)&&Dw(t,r,e[r]);return t};function tZ({tournamentRecords:t,modifications:e,disableNotice:r,courtId:n,force:o}){if(!t)return{error:Fe};if(!n)return{error:Oe,info:"missing courtId"};let i,s;for(const a of Object.values(t)){const c=Im({tournamentRecord:a,modifications:e,disableNotice:r,courtId:n,force:o});c!=null&&c.error&&(s=c),i=!0}return i?eZ({},B):s}const rZ=()=>({venueId:void 0,venueName:"",venueAbbreviation:"",onlineResources:[],venueType:void 0,addresses:[],contacts:[],courts:[],roles:[]});var nZ=Object.defineProperty,oZ=Object.defineProperties,iZ=Object.getOwnPropertyDescriptors,jw=Object.getOwnPropertySymbols,sZ=Object.prototype.hasOwnProperty,aZ=Object.prototype.propertyIsEnumerable,Rw=(t,e,r)=>e in t?nZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sl=(t,e)=>{for(var r in e||(e={}))sZ.call(e,r)&&Rw(t,r,e[r]);if(jw)for(var r of jw(e))aZ.call(e,r)&&Rw(t,r,e[r]);return t},Od=(t,e)=>oZ(t,iZ(e));function Pm({tournamentRecord:t,disableNotice:e,venueId:r,courtId:n,court:o}){const{venue:i}=Lo({tournamentRecord:t,venueId:r});if(!i)return{error:oi};i.courts||(i.courts=[]);const s=Od(sl({},Aw()),{venueId:r,courtId:n});if(s.courtId||(s.courtId=We()),i.courts.reduce((c,l)=>c||l.courtId===s.courtId,void 0))return{error:YF};{const c=((o==null?void 0:o.dateAvailability)||[]).map(l=>{var u;return Od(sl({},l),{date:Ce(l.date),startTime:rt(l.startTime),endTime:rt(l.endTime),bookings:(u=l.bookings)==null?void 0:u.map(({startTime:d,endTime:p,bookingType:v})=>({startTime:rt(d),endTime:rt(p),bookingType:v}))})});for(const l of Object.keys(s))if(o[l])if(l==="dateAvailability"){const u=Tw({dateAvailability:c});if(!u.valid&&u.error)return u;s.dateAvailability=c}else s[l]=o[l];return i.courts.push(s),e||xe({payload:{venue:i,tournamentId:t.tournamentId},topic:Ji,key:i.venueId}),Od(sl({},B),{court:ue(s),venueId:r})}}function ym({courtNameRoot:t="Court",dateAvailability:e=[],venueAbbreviationRoot:r,tournamentRecord:n,courtNames:o=[],courtTimings:i,courtsCount:s,startTime:a,courtIds:c,endTime:l,idPrefix:u,venueId:d,dates:p}){if(!d)return{error:Uo};let v=Lo({tournamentRecord:n,venueId:d});if(v.error)return v;const{venue:f}=v;if(!Ot(s)||!o)return{error:qF};s=s||o.length,v=le(0,s).map(h=>{const _=i==null?void 0:i[h],I=_?p.map(P=>sl({date:On(P),startTime:a,endTime:l},_)):e;return _&&a&&l&&I.push({startTime:a,endTime:l}),{courtName:o[h]||r&&f.venueAbbreviation&&`${f.venueAbbreviation} ${h+1}`||`${t} ${h+1}`,dateAvailability:I}}).map((h,_)=>{const I=(c==null?void 0:c.pop())||u&&`${u}-${_+1}`;return Pm({disableNotice:!0,tournamentRecord:n,courtId:I,venueId:d,court:h})});const g=v.map(h=>h.court).filter(Boolean);return g.length!==parseInt(s)?{error:"Not all courts could be generated",result:v}:(xe({payload:{venue:f,tournamentId:n.tournamentId},topic:Ji,key:f.venueId}),Od(sl({},B),{courts:ue(g)}))}var cZ=Object.defineProperty,lZ=Object.defineProperties,uZ=Object.getOwnPropertyDescriptors,Fw=Object.getOwnPropertySymbols,dZ=Object.prototype.hasOwnProperty,pZ=Object.prototype.propertyIsEnumerable,Lw=(t,e,r)=>e in t?cZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fZ=(t,e)=>{for(var r in e||(e={}))dZ.call(e,r)&&Lw(t,r,e[r]);if(Fw)for(var r of Fw(e))pZ.call(e,r)&&Lw(t,r,e[r]);return t},vZ=(t,e)=>lZ(t,uZ(e));function Vw({tournamentRecord:t,modifications:e,venueId:r,force:n}){var o,i;if(!t)return{error:ee};if(!e||typeof e!="object")return{error:xn};if(!r)return{error:Uo};const{matchUps:s}=TJ({tournamentRecord:t,venueId:r}),a=Lo({tournamentRecord:t,venueId:r});if(a.error)return a;const c=a.venue,l=Object.keys(rZ()).filter(g=>g!=="venueId");if(!Object.keys(e).filter(g=>l.includes(g)).length)return{error:Lp};const d=l.filter(g=>!["courts","onlineResources"].includes(g));Object.keys(e).filter(g=>d.includes(g)).forEach(g=>Object.assign(c,{[g]:e[g]}));const v=((o=c==null?void 0:c.courts)==null?void 0:o.map(g=>g.courtId))||[],f=((i=e.courts)==null?void 0:i.map(g=>g.courtId))||[],m=v.filter(g=>!f.includes(g));if(m.length){const h=c.courts.filter(_=>m.includes(_.courtId)).map(_=>{var I;return((I=_m({courtId:_.courtId,tournamentRecord:t,venueMatchUps:s}).matchUps)==null?void 0:I.length)||0}).reduce((_,I)=>_+I);if(!h||n)c.courts=c.courts.filter(_=>f.includes(_.courtId));else return{error:gm({matchUpsCount:h})}}if(e.courts)for(const g of e.courts){const{courtId:h}=g||{};let _=Im({modifications:g,disableNotice:!0,tournamentRecord:t,venueMatchUps:s,courtId:h,force:n});if(_.error===Rp&&(_=Pm({disableNotice:!0,tournamentRecord:t,venueId:r,court:g})),_.error)return _}return yd({tournamentRecord:t}),xe({payload:{venue:c,tournamentId:t.tournamentId},topic:Ji,key:c.venueId}),vZ(fZ({},B),{venue:ue(c)})}var mZ=Object.defineProperty,xw=Object.getOwnPropertySymbols,gZ=Object.prototype.hasOwnProperty,hZ=Object.prototype.propertyIsEnumerable,Bw=(t,e,r)=>e in t?mZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_Z=(t,e)=>{for(var r in e||(e={}))gZ.call(e,r)&&Bw(t,r,e[r]);if(xw)for(var r of xw(e))hZ.call(e,r)&&Bw(t,r,e[r]);return t};function IZ({tournamentRecords:t,modifications:e,venueId:r,force:n}){if(!t)return{error:Fe};if(typeof r!="string")return{error:Uo};let o,i;for(const s of Object.values(t)){const a=Vw({tournamentRecord:s,modifications:e,venueId:r,force:n});if(a.success&&(i=!0),a.error&&(o=a.error),a.error&&a.error!==oi)return a}return bT({tournamentRecords:t}),i?_Z({},B):{error:o}}var PZ=Object.defineProperty,kw=Object.getOwnPropertySymbols,yZ=Object.prototype.hasOwnProperty,SZ=Object.prototype.propertyIsEnumerable,Gw=(t,e,r)=>e in t?PZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,OZ=(t,e)=>{for(var r in e||(e={}))yZ.call(e,r)&&Gw(t,r,e[r]);if(kw)for(var r of kw(e))SZ.call(e,r)&&Gw(t,r,e[r]);return t};function bZ(t){const{tournamentRecords:e,venueId:r}=t;if(typeof r!="string"||!r)return{error:Uo};let n;for(const o of Object.values(e)){const{venue:i}=Lo({tournamentRecord:o,venueId:r});if(i){const s=ym(OZ({tournamentRecord:o},t));if(s.error)return s;n=!0}}return n?B:{error:oi}}var TZ=Object.defineProperty,EZ=Object.defineProperties,wZ=Object.getOwnPropertyDescriptors,Ww=Object.getOwnPropertySymbols,$Z=Object.prototype.hasOwnProperty,NZ=Object.prototype.propertyIsEnumerable,Hw=(t,e,r)=>e in t?TZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,AZ=(t,e)=>{for(var r in e||(e={}))$Z.call(e,r)&&Hw(t,r,e[r]);if(Ww)for(var r of Ww(e))NZ.call(e,r)&&Hw(t,r,e[r]);return t},UZ=(t,e)=>EZ(t,wZ(e));function CZ({tournamentRecords:t,disableNotice:e,venue:r,context:n}){if(typeof r!="object")return{error:Z};r.venueId||(r.venueId=We());let o;for(const i of Object.values(t)){const s=fc({disableNotice:!0,tournamentRecord:i,context:n,venue:r});if(s!=null&&s.error)return s;o=s.venue}return e||xe({topic:bI,payload:{venue:r}}),_e(UZ(AZ({},B),{venue:o}))}const MZ={disableCourts:xQ,disableVenues:KQ,enableCourts:oJ,enableVenues:fJ,deleteCourt:DJ,deleteVenue:SJ,modifyCourt:tZ,modifyVenue:IZ,addCourts:bZ,addVenue:CZ};function DZ({convertExtensions:t,removeExtensions:e}){const r=Ml();return{tournamentId:yn(),tournamentRecords:ue(r,t,!1,e)}}function jZ(){var t;const e=Ml(),{extension:r}=Zl({name:ki,tournamentRecords:e}),n=((t=r==null?void 0:r.value)==null?void 0:t.tournamentIds)||[];return Object.keys(e).forEach(o=>{n.includes(o)||delete e[o]}),ec(e)}function RZ(t,e=!0){return typeof t!="object"||Array.isArray(t)?{error:xn}:t!=null&&t.tournamentId?e_(e?ue(t):t):{error:Z}}function Sm(t,e=!0){if(typeof t!="object")return{error:xn};if(Array.isArray(t)){if(!(t.filter(n=>n==null?void 0:n.tournamentId).length===t.length))return{error:dh};t=Object.assign({},...t.map(n=>({[n.tournamentId]:n})))}else if(t!=null&&t.tournamentId)t={[t.tournamentId]:t};else if(!Object.keys(t).every(n=>t[n].tournamentId===n))return{error:dh};return ec(e?ue(t):t)}var FZ=Object.defineProperty,LZ=Object.defineProperties,VZ=Object.getOwnPropertyDescriptors,qw=Object.getOwnPropertySymbols,xZ=Object.prototype.hasOwnProperty,BZ=Object.prototype.propertyIsEnumerable,Yw=(t,e,r)=>e in t?FZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,al=(t,e)=>{for(var r in e||(e={}))xZ.call(e,r)&&Yw(t,r,e[r]);if(qw)for(var r of qw(e))BZ.call(e,r)&&Yw(t,r,e[r]);return t},zw=(t,e)=>LZ(t,VZ(e));(function(){const t={getState:({convertExtensions:s,removeExtensions:a}={})=>DZ({convertExtensions:s,removeExtensions:a}),version:()=>so(),reset:()=>(ec({}),e())};return o([L7,X9,UQ,Y7,V9,MZ]),t.devContext=s=>(xs(s),e()),t.getDevContext=s=>Ft(s),t.setState=(s,a,c)=>{Fi(a,c);const l=Sm(s,a);return e(l)},t.setTournamentRecord=(s,a,c)=>{Fi(a,c);const l=RZ(s,a);return e(l)},t.removeTournamentRecord=s=>{const a=xp(s);return e(a)},t.removeUnlinkedTournamentRecords=()=>{const s=jZ();return e(s)},t.executionQueue=(s,a)=>i(s,a),t;function e(s){return s!=null&&s.error?(t.error=s.error,t.success=!1):(t.error=void 0,t.success=!0),t}function r(s,a,c,l){var u,d;delete t.success,delete t.error;const p=Date.now(),v=a(al({tournamentRecords:s},c)),f=Date.now()-p,m=Ft(),g={method:l},h=typeof m.result=="object"&&m.result.error;return![void 0,!1].includes(m.perf)&&(isNaN(m.perf)||f>m.perf)&&(g.elapsed=f),(h||m.params&&!Array.isArray(m.params)||Array.isArray(m.params)&&((u=m.params)!=null&&u.includes(l)))&&(g.params=c),(h||!h&&m.result&&!Array.isArray(m.result)||Array.isArray(m.result)&&((d=m.result)!=null&&d.includes(l)))&&(g.result=v),Object.keys(g).length>1&&console.log("ce:",g),v}function n(s,a,c){const l=Ml(),u=yn(),d=(a==null?void 0:a.rollbackOnError)&&ue(l,!1,!0),p=r(l,s,al({activeTournamentId:u},a),c);p!=null&&p.error&&d&&Sm(d);const v=(p==null?void 0:p.success)&&(a==null?void 0:a.delayNotify)!==!0&&(a==null?void 0:a.doNotNotify)!==!0,f=Za(),m=Date.now();return f&&(Object.values(l).forEach(g=>{Fu({tournamentRecord:g,value:{version:so(),timeStamp:m}})}),p.modificationsApplied=!0),v&&bi({directives:[{method:s,params:a}],mutationStatus:f,timeStamp:m}),(v||!(p!=null&&p.success)||a!=null&&a.doNotNotify)&&ii(),p}function o(s){s.forEach(a=>{Object.keys(a).forEach(c=>{t[c]=l=>{if(Ft())return n(a[c],l,c);try{return n(a[c],l,c)}catch(u){const d=yn(),p=u.toString();console.log("ERROR",{params:JSON.stringify(l),activeTournamentId:d,methodName:c,error:p})}}})})}function i(s,a){var c;if(!Array.isArray(s))return{error:Z};const l=Ml(),u=yn(),d=a&&ue(l,!1,!0);let p;const v=[];for(const g of s){if(typeof g!="object")return{error:Z};const{method:h,params:_}=g;if(!t[h]){const P={error:qh,methodName:h},O=Ft();return(O.result&&!Array.isArray(O.result)||Array.isArray(O.result)&&((c=O.result)!=null&&c.includes(h)))&&console.log("ce:",P),P}const I=r(l,t[h],al({activeTournamentId:u},_),h);if(I!=null&&I.error)return d&&Sm(d),zw(al({},I),{rolledBack:!!d});v.push(zw(al({},I),{methodName:h})),p=Date.now()}const f=Za();return f&&Object.values(l).forEach(g=>{Fu({tournamentRecord:g,value:{version:so(),timeStamp:p}})}),bi({directives:s,mutationStatus:f,timeStamp:p}),ii(),{success:v.every(g=>g.success),results:v}}})();var kZ=Object.defineProperty,Kw=Object.getOwnPropertySymbols,GZ=Object.prototype.hasOwnProperty,WZ=Object.prototype.propertyIsEnumerable,Qw=(t,e,r)=>e in t?kZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,HZ=(t,e)=>{for(var r in e||(e={}))GZ.call(e,r)&&Qw(t,r,e[r]);if(Kw)for(var r of Kw(e))WZ.call(e,r)&&Qw(t,r,e[r]);return t};function Om({structureName:t=Ct,structureAbbreviation:e,drawDefinition:r,matchUpType:n,structureId:o}){if(!r)return{error:pe};const i=kt({stage:Ct,structureAbbreviation:e,structureName:t,matchUps:[],structureId:o,matchUpType:n});return r.structures.push(i),Je({drawDefinition:r,structureIds:[o]}),HZ({},B)}function Ua({targetEntryRound:t=1,finishingPositions:e,sourceRoundNumber:r,sourceStructureId:n,targetStructureId:o,linkType:i=_o}){return!n||!o?{error:ar}:{link:_e({linkType:i,source:{roundNumber:r,structureId:n,finishingPositions:e},target:{feedProfile:an,roundNumber:t,structureId:o}})}}function bm({idPrefix:t,roundNumber:e,roundPosition:r,uuids:n}){return t?`${t}-${e}-${r}`:(n==null?void 0:n.pop())||We()}function bd({includeMatchUpType:t,matchUpType:e,roundNumber:r,matchUps:n,idPrefix:o,isMock:i,uuids:s,nodes:a}){let c=0;const l=[];let u=1;const d=r-1,p=a.length;for(;c<p;){const v=a[c],f=a[c+1];d&&(v.roundNumber=d),f&&d&&(f.roundNumber=d);const m=bm({roundPosition:u,roundNumber:r,idPrefix:o,uuids:s}),g={roundPosition:u,children:[v,f],matchUpId:m};l.push(g);const h={drawPositions:g.children.map(_=>_==null?void 0:_.drawPosition).filter(Boolean),matchUpStatus:vt,matchUpId:g.matchUpId,roundPosition:u,roundNumber:r};t&&(h.matchUpType=e),i&&(h.isMock=!0),n.push(h),u++,c+=2}return{roundNodes:l,matchUps:n}}function Ln({finishingPositionOffset:t,finishingPositionLimit:e,qualifyingRoundNumber:r,qualifyingPositions:n,matchUpType:o,roundLimit:i,idPrefix:s,drawSize:a,isMock:c,uuids:l}){if(isNaN(a)||a<2||n&&a<=n)return{matchUps:[],roundsCount:0};if(n&&(!Vr(a)||a%n)){let g=n;for(;g<a;)g=2*g;a=g}const u=!(a%2)&&(!isNaN(n)||!isNaN(r))&&(a/n===Math.round(a/n)||a/r===Math.round(a/r));if(!Vr(a)&&!u)return{matchUps:[],roundsCount:0};const d=le(1,parseInt(a)+1).map(g=>({drawPosition:g}));let p,v=[],f=1;for({roundNodes:p,matchUps:v}=bd({matchUpType:o,roundNumber:f,idPrefix:s,matchUps:v,isMock:c,nodes:d,uuids:l}),f++,i=i||r||(n>1?a/2/n:void 0);p.length>1;)n&&p.length===n&&(i=f-1),{roundNodes:p,matchUps:v}=bd({nodes:p,matchUpType:o,roundNumber:f,idPrefix:s,matchUps:v,isMock:c,uuids:l}),f++;const m=f-1;return v=Vc({finishingPositionOffset:t,finishingPositionLimit:e,roundsCount:m,roundLimit:i,matchUps:v}),i?v=v.filter(g=>g.roundNumber<=i):i=f-1,{drawSize:a,matchUps:v,roundsCount:m,roundLimit:i}}var qZ=Object.defineProperty,YZ=Object.defineProperties,zZ=Object.getOwnPropertyDescriptors,Jw=Object.getOwnPropertySymbols,KZ=Object.prototype.hasOwnProperty,QZ=Object.prototype.propertyIsEnumerable,Zw=(t,e,r)=>e in t?qZ(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,JZ=(t,e)=>{for(var r in e||(e={}))KZ.call(e,r)&&Zw(t,r,e[r]);if(Jw)for(var r of Jw(e))QZ.call(e,r)&&Zw(t,r,e[r]);return t},ZZ=(t,e)=>YZ(t,zZ(e));function Xw({qualifyingProfiles:t,appliedPolicies:e,idPrefix:r,isMock:n,uuids:o}){var i;const s="generateQualifyingSTructures",a=[],c=[],l=[],u=(g,h)=>g.stageSequence-h.stageSequence,d=(g,h)=>g.roundTarget-h.roundTarget;let p=0,v=0,f,m=1;for(const g of t.sort(d)){const h=g.structureProfiles||[];m=g.roundTarget||m;let _=1,I=0,P,O,y;for(const S of(h||[]).sort(u)){let T=S.drawSize||yp(S.participantsCount);const{qualifyingRoundNumber:E,qualifyingPositions:b,structureOptions:N,matchUpFormat:w,structureName:$,matchUpType:U,structureId:A,drawType:M}=S;let C,D,F;if(!ut(T))return W({result:{error:El},stack:s});const R=t.length>1?`${m}-`:"",G=h.length>1||R?_:"",x=$||(R||G?`${Ie} ${R}${G}`:Ie);if(M===ln){const{structures:z,groupCount:j,maxRoundNumber:V}=qc({structureName:S.structureName||x,structureId:A||(o==null?void 0:o.pop()),qualifyingPositions:b,stage:Ie,structureOptions:N,appliedPolicies:e,stageSequence:_,matchUpType:U,roundTarget:m,idPrefix:r,drawSize:T,isMock:n,uuids:o});I=j,C=V,D=z[0],f=[1]}else({drawSize:T,matchUps:F,roundLimit:C}=Ln({qualifyingRoundNumber:E,qualifyingPositions:b,matchUpType:U,idPrefix:r,drawSize:T,isMock:n,uuids:o})),D=kt({structureName:S.structureName||x,structureId:A||(o==null?void 0:o.pop()),qualifyingRoundNumber:C,stage:Ie,matchUpFormat:w,stageSequence:_,matchUpType:U,roundLimit:C,matchUps:F}),m&&tt({element:D,extension:{name:Tn,value:m}}),I=(i=F==null?void 0:F.filter(z=>z.roundNumber===C))==null?void 0:i.length;if(_>1){const{link:z}=Ua({sourceStructureId:O,sourceRoundNumber:P,targetStructureId:D.structureId,finishingPositions:y===ho?[1]:void 0,linkType:y});l.push(z),p+=T-I}else p+=T;y=M===ln?ho:_o,O=D.structureId,P=C,c.push(D),_+=1}v+=I,a.push({qualifiersCount:I,finalQualifyingRoundNumber:P,finalQualifyingStructureId:O,finishingPositions:f,roundTarget:m,linkType:y}),I=0,m+=1}return ZZ(JZ({qualifiersCount:v,qualifyingDrawPositionsCount:p,qualifyingDetails:a,structures:c},B),{links:l})}function Tm({drawDefinition:t,structureId:e}){const r=Te({drawDefinition:t,structureId:e});if(r.error)return r;const{matchUps:n}=ze({structure:r.structure});return pr({matchUps:n})}function e$({finishingPositions:t,drawDefinition:e,structureId:r}){const{roundProfile:n}=Tm({drawDefinition:e,structureId:r});return Object.keys(n).reduce((i,s)=>(t$(n[s]).forEach(c=>{t.forEach(l=>{XZ({position:l,rangeDefinition:c})&&(i[l]={roundNumber:s})})}),i),{})}function XZ({position:t,rangeDefinition:e}){if(!Array.isArray(e)||e.reduce((i,s)=>i||isNaN(s),!1))return!1;const[r,n]=e;return le(r,(n||r)+1).includes(t)}function t$(t){var e,r;return[Ve(((e=t==null?void 0:t.finishingPositionRange)==null?void 0:e.loser)||[]),Ve(((r=t==null?void 0:t.finishingPositionRange)==null?void 0:r.winner)||[])]}function eX(t){return t$(t).map(e=>le(e[0],e[1]&&e[1]+1||e[0]+1))}function Td({drawDefinition:t,structureIds:e}){if(e&&!Array.isArray(e))return{error:Z,context:{structureIds:e}};if(!t)return{error:pe};e=e||(t.structures||[]).filter(s=>s.structureType!==Ie).map(({structureId:s})=>s);const r=e.map(s=>{const{roundProfile:a}=Tm({drawDefinition:t,structureId:s});return Object.values(a).map(eX).flat()}).flat(),n=r.filter(s=>s.length===1).sort(Wt).flat();return{positionsNotPlayedOff:Ve(r.flat()).filter(s=>!n.includes(s)),positionsPlayedOff:n}}function Em({excludeRoundNumbers:t=[],playoffPositions:e=[],drawDefinition:r,structureId:n}){if(!r)return{error:pe};if(!n)return{error:ar};if(!e)return{error:Oe,info:"missing playoffPositions"};const o=Td({drawDefinition:r});if(o.error)return o;const i=o.positionsPlayedOff,s=e.filter(g=>!i.includes(g)),a=e$({finishingPositions:s,drawDefinition:r,structureId:n}),c=Object.values(a).reduce((g,h)=>g.includes(h.roundNumber)?g:g.concat(h.roundNumber),[]).map(g=>parseInt(g)).filter(g=>!t.includes(parseInt(g))),l=e$({finishingPositions:i,drawDefinition:r,structureId:n}),u=Object.values(l).reduce((g,h)=>g.includes(h.roundNumber)?g:g.concat(h.roundNumber),[]).map(g=>parseInt(g)),d=c.filter(g=>!u.includes(g)).sort(Wt),{roundProfile:p}=Tm({drawDefinition:r,structureId:n}),v=d.map(g=>{const h=p[g].finishingPositionRange.loser,[_,I]=h;return le(_,(I||_)+1)}).flat().sort(Wt),{playoffRoundsRanges:f}=tX({playoffSourceRounds:d,roundProfile:p}),m=[...d,...u];return{playoffPositionsReturned:v,playedOffSourceRounds:u,playoffRoundsRanges:f,playoffSourceRounds:d,roundProfile:p,sourceRounds:m}}function tX({playoffSourceRounds:t,roundProfile:e}){return{playoffRoundsRanges:t.map(n=>{const o=e[n].finishingPositionRange.loser,[i,s]=o,a=le(i,(s||i)+1);return{finishingPositionRange:o.join("-"),finishingPositions:a,roundNumber:n}})}}var rX=Object.defineProperty,Ed=Object.getOwnPropertySymbols,r$=Object.prototype.hasOwnProperty,n$=Object.prototype.propertyIsEnumerable,o$=(t,e,r)=>e in t?rX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,i$=(t,e)=>{for(var r in e||(e={}))r$.call(e,r)&&o$(t,r,e[r]);if(Ed)for(var r of Ed(e))n$.call(e,r)&&o$(t,r,e[r]);return t},nX=(t,e)=>{var r={};for(var n in t)r$.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Ed)for(var n of Ed(t))e.indexOf(n)<0&&n$.call(t,n)&&(r[n]=t[n]);return r};function cl({drawDefinition:t,structureId:e}){if(!t)return{error:pe};let{structures:r}=Cr({stageSeqence:1,drawDefinition:t,stage:de});const{positionsNotPlayedOff:n,positionsPlayedOff:o}=Td({drawDefinition:t});({structures:r}=Cr({drawDefinition:t}));const i=r.filter(c=>!e&&c.stage!==Ct||c.structureId===e),s={},a=Dr({inContext:!0,drawDefinition:t}).matchUps;for(const c of i){const l=c==null?void 0:c.structureId,u=oX({playoffPositions:n,drawDefinition:t,structure:c,matchUps:a}),d=u,{error:p}=d,v=nX(d,["error"]);if(p)return u;s[l]=i$({structureId:l},v)}return e?i$({positionsPlayedOff:o},s[e]):{availablePlayoffProfiles:Object.values(s),availablePlayoffRounds:Object.values(s),positionsPlayedOff:o}}function oX({playoffPositions:t,drawDefinition:e,structure:r,matchUps:n}){var o,i,s,a,c,l;const u=r==null?void 0:r.structureId,{links:d}=Fc({drawDefinition:e,structureId:u});if(r.structureType===tr||r.structures){const _=et({structure:r}).positionAssignments.length,I=r.structures.length,P=_/I,O=((o=d.source)==null?void 0:o.flatMap(({source:A})=>(A==null?void 0:A.finishingPositions)||[]))||[],y=le(1,P+1).filter(A=>!O.includes(A)),S=((s=(i=n.find(A=>A.containerStructureId===u&&A.finishingPositionRange))==null?void 0:i.finishingPositionRange)==null?void 0:s.winner)||[0,1],T=d==null?void 0:d.source.map(({target:A})=>A.structureId),{positionsPlayedOff:E,positionsNotPlayedOff:b}=Td({structureIds:T,drawDefinition:e}),N=[...E,...b],w=le(S[0],S[1]+1).filter(A=>!N.includes(A)),$=Rt(w,w.length/y.length),U=y.map((A,M)=>{const C=$[M],D=[Math.min(...C||[]),Math.max(...C||[])].join("-");return{finishingPosition:A,finishingPositions:C,finishingPositionRange:D}});return{positionsNotPlayedOff:w,playoffFinishingPositionRanges:U,finishingPositionsAvailable:y,finishingPositionsPlayedOff:O,positionsPlayedOff:E,groupCount:I,groupSize:P}}const p=((a=d==null?void 0:d.source)==null?void 0:a.filter(_=>_.linkCondition!==Yn).map(_=>{var I;return(I=_.source)==null?void 0:I.roundNumber}))||[],v=((c=d==null?void 0:d.source)==null?void 0:c.filter(_=>_.linkCondition===Yn).map(_=>{var I;return(I=_.source)==null?void 0:I.roundNumber}))||[],{playoffSourceRounds:f,playoffRoundsRanges:m,roundProfile:g,error:h}=Em({excludeRoundNumbers:p,playoffPositions:t,drawDefinition:e,structureId:u});for(const _ of v){const I=d==null?void 0:d.source.find(T=>T.source.roundNumber===_),P=I==null?void 0:I.target.roundNumber,O=I==null?void 0:I.target.structureId,y=n.filter(({roundNumber:T,structureId:E})=>E===O&&T===P),S=y.filter(({sides:T})=>T.find(E=>E.participantFed&&!E.participantId)).length;if(S===y.length){f.push(_);const T=(l=g[_].finishingPositionRange)==null?void 0:l.loser;if(T){const E=Math.min(...T),b=E+S,N=le(E,b),w={finishingPositionRange:[E,b-1].join("-"),finishingPositions:N,roundNumber:_};m.push(w)}}}return f.sort(Wt),m.sort((_,I)=>_.roundNumber-I.roundNumber),{playoffRounds:f,playoffRoundsRanges:m,error:h}}function iX({playoffGroups:t,drawDefinition:e,structureId:r}){var n;if(!e)return{error:pe};if(typeof r!="string"||!Array.isArray(t))return{error:Z};const o=t.map(({finishingPositions:c})=>c).flat(),s=(n=cl({drawDefinition:e,structureId:r}).playoffFinishingPositionRanges)==null?void 0:n.filter(c=>o.includes(c.finishingPosition));return{positionRangeMap:s==null?void 0:s.reduce((c,l)=>(c[l.finishingPosition]=l,c),{})}}function sX({includeMatchUpType:t,drawPosition:e,roundNumber:r,matchUpType:n,idPrefix:o,matchUps:i,isMock:s,uuids:a,nodes:c,fed:l}){const u=c.length,d=e?e-u:void 0,p=le(0,u).map(m=>d?d+m:void 0),v=[];for(let m=0;m<u;m++){const g=p.shift(),h={drawPosition:g,fed:l+1,feed:!0},_=c[m];_.roundNumber=r-1;const I=bm({roundPosition:_.roundPosition,roundNumber:r,idPrefix:o,uuids:a}),P={roundPosition:_.roundPosition,drawPositions:[g],matchUpStatus:vt,roundNumber:r,matchUpId:I};t&&(P.matchUpType=n),s&&(P.isMock=!0),i.push(P);const O={children:[_,h]};v.push(O)}const f=e?e-u:void 0;return{roundNodes:v,matchUps:i,drawPosition:f}}function Ko({linkFedFinishingRoundNumbers:t=[],linkFedRoundNumbers:e=[],finishingPositionOffset:r,feedRoundsProfile:n=[],feedRounds:o=0,skipRounds:i=0,feedsFromFinal:s,isConsolation:a,baseDrawSize:c,matchUpType:l,idPrefix:u,drawSize:d,isMock:p,uuids:v,fmlc:f}){c=c||M(d);const m=aX({drawSize:c}),g=m.length;let h=0;if(n.length)h=n.reduce((C,D)=>C+D,0);else if(d){let C=d-c;n=m.filter(D=>D<=C?(C-=D,!0):!1),h=n.reduce((D,F)=>D+F,0),o=n.length}else i>=g?o=0:s&&(o=g-s,i=0),n=m.filter((C,D)=>s&&!o||o&&D>=i+o||D<i?0:C),h=n.reduce((C,D)=>C+D,0),d=c+h,o=n.length;const _=[...m,...n].sort((C,D)=>D-C),I=_.length,O=[...e.map(C=>C-1),...t.map(C=>I-C)].map(C=>_[C]).reduce((C,D)=>C+D,0);h=h-O;let y=0,S=[],T,E=1,N=le(0,c).map((C,D)=>({drawPosition:D+1+h})),w=h+1;for(const C of m){if({roundNodes:T,matchUps:S}=bd({matchUpType:l,roundNumber:E,idPrefix:u,matchUps:S,isMock:p,nodes:N,uuids:v}),E++,n.includes(C)){const D=mr(n)[C],F=le(0,D),R=I+1-E,G=t.includes(R)||e.includes(E);for(const x of F)({roundNodes:T,matchUps:S,drawPosition:w}=sX({drawPosition:!G&&w||void 0,nodes:T,roundIteration:x,matchUpType:l,roundNumber:E,idPrefix:u,matchUps:S,isMock:p,uuids:v,fed:y})),E++,y+=1}N=T}I!==E-1&&console.log("ERROR");const $=c-h;S=Vc({finishingPositionOffset:a?$:r,positionsFed:h,roundsCount:I,matchUps:S,fmlc:f});const A=T!=null&&T.length?T[0]:T;return A&&(A.roundNumber=E-1,A.matchUps=S),{draw:A,matchUps:S,roundsCount:I};function M(C){const D=Sp(C);return D>C?D/2:D}}function aX({drawSize:t}){const e=Math.ceil(Math.log(t)/Math.log(2));return le(0,e).reverse().map(n=>Math.pow(2,n))}var cX=Object.defineProperty,lX=Object.defineProperties,uX=Object.getOwnPropertyDescriptors,s$=Object.getOwnPropertySymbols,dX=Object.prototype.hasOwnProperty,pX=Object.prototype.propertyIsEnumerable,a$=(t,e,r)=>e in t?cX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fX=(t,e)=>{for(var r in e||(e={}))dX.call(e,r)&&a$(t,r,e[r]);if(s$)for(var r of s$(e))pX.call(e,r)&&a$(t,r,e[r]);return t},vX=(t,e)=>lX(t,uX(e));function c$(t){const{finishingPositionOffset:e=0,stageSequence:r=1,staggeredEntry:n,structureName:o,stage:i=de,matchUpType:s,structureId:a,idPrefix:c,drawSize:l,isMock:u,uuids:d}=t,p={finishingPositionOffset:e,matchUpType:s,drawSize:l,idPrefix:c,isMock:u,uuids:d},{matchUps:v}=n?Ko(p):Ln(p),f=kt({structureId:a||(d==null?void 0:d.pop()),structureName:o||de,stageSequence:r,matchUpType:s,matchUps:v,stage:i}),m=[f],g=[];if(l>2){const h=l/2,{matchUps:_}=Ln({finishingPositionOffset:e+h,idPrefix:c&&`${c}-c`,drawSize:h,matchUpType:s,isMock:u}),I=t.consolationStructureName||(o?`${o} ${$t}`:$t),P=kt({structureName:I,matchUps:_,structureId:d==null?void 0:d.pop(),stage:$t,stageSequence:1,matchUpType:s});m.push(P);const O={linkType:qn,source:{roundNumber:1,structureId:f.structureId},target:{roundNumber:1,feedProfile:Cn,structureId:P.structureId}};g.push(O)}return vX(fX({},B),{structures:m,links:g})}function l$({consolationStructure:t,roundOffset:e=0,mainStructure:r,roundsCount:n,feedPolicy:o,fmlc:i}){const a=t.matchUps.reduce((u,d)=>(d.drawPositions||[]).filter(Boolean).length&&!u.includes(d.roundNumber)?u.concat(d.roundNumber):u,[]),c=(o==null?void 0:o.roundGroupedOrder)||[],l=o==null?void 0:o.roundFeedProfiles;return le(1+e,n+1+e).map(u=>{const d=l&&l[u-1]?l[u-1]:u%2?Cn:rs,p=u-e<=2?u-e:(u-e-2)*2+2,v={linkType:qn,source:{roundNumber:u,structureId:r.structureId},target:{feedProfile:d,roundNumber:p,structureId:t.structureId}},f=c[u-1];return f&&(v.target.groupedOrder=f),Ft()&&(v.source.structureName=r.structureName,v.target.structureName=t.structureName),u===2&&i&&(v.linkCondition=Yn,v.target.feedProfile=Cn),a.includes(p)?v:void 0}).filter(Boolean)}var mX=Object.defineProperty,u$=Object.getOwnPropertySymbols,gX=Object.prototype.hasOwnProperty,hX=Object.prototype.propertyIsEnumerable,d$=(t,e,r)=>e in t?mX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_X=(t,e)=>{for(var r in e||(e={}))gX.call(e,r)&&d$(t,r,e[r]);if(u$)for(var r of u$(e))hX.call(e,r)&&d$(t,r,e[r]);return t};function p$({finishingPositionOffset:t,structureName:e=de,stageSequence:r=1,staggeredEntry:n,matchUpType:o,structureId:i,idPrefix:s,drawSize:a,isMock:c,uuids:l}){const u={finishingPositionOffset:t,matchUpType:o,drawSize:a,idPrefix:s,isMock:c,uuids:l},{matchUps:d,roundsCount:p}=n?Ko(u):Ln(u),v=kt({structureId:i||(l==null?void 0:l.pop()),matchUps:d,matchUpType:o,stage:de,structureName:e,stageSequence:r}),f=[v],m=[];if(a>2){const _=[0,2].slice(0,a/16).map((I,P)=>{const O=P+1,{consolationStructure:y}=IX({structureId:l==null?void 0:l.pop(),idPrefix:s&&`${s}-c${P}`,stageSequence:O,roundOffset:I,matchUpType:o,drawSize:a,isMock:c,index:P,uuids:l});f.push(y);const S=l$({mainStructure:v,consolationStructure:y,roundsCount:2,roundOffset:I});return{consolationStructure:y,links:S}}).map(I=>I.links).flat();if(m.push(..._),a>=4&&a<=16||a>32){const{matchUps:I}=Ln({finishingPositionOffset:2,idPrefix:s&&`${s}-p3t4`,drawSize:2,matchUpType:o,isMock:c}),P=kt({structureId:l==null?void 0:l.pop(),matchUps:I,structureName:st,stageSequence:2,stage:st,matchUpType:o}),O={linkType:qn,source:{roundNumber:p-1,structureId:v.structureId},target:{roundNumber:1,feedProfile:Cn,structureId:P.structureId}};f.push(P),m.push(O)}}return _X({structures:f,links:m},B)}function IX({stageSequence:t=1,roundOffset:e=0,matchUpType:r,structureId:n,idPrefix:o,drawSize:i,isMock:s,index:a,uuids:c}){const l=i/(2*Math.pow(2,e)),{matchUps:u,roundsCount:d}=Ko({finishingPositionOffset:l,baseDrawSize:l,isConsolation:!0,feedRounds:1,matchUpType:r,idPrefix:o,isMock:s,uuids:c}),p=`${$t} ${a+1}`;return{consolationStructure:kt({matchUps:u,stage:$t,structureName:p,stageSequence:t,matchUpType:r,structureId:n}),consolationRoundsCount:d}}var PX=Object.defineProperty,f$=Object.getOwnPropertySymbols,yX=Object.prototype.hasOwnProperty,SX=Object.prototype.propertyIsEnumerable,v$=(t,e,r)=>e in t?PX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,OX=(t,e)=>{for(var r in e||(e={}))yX.call(e,r)&&v$(t,r,e[r]);if(f$)for(var r of f$(e))SX.call(e,r)&&v$(t,r,e[r]);return t};function Ca({finishingPositionOffset:t=0,addNameBaseToAttributeName:e,playoffStructureNameBase:r,finishingPositionNaming:n,finishingPositionLimit:o,playoffAttributes:i,stageSequence:s=1,exitProfile:a="0",exitProfileLimit:c,roundOffsetLimit:l,roundOffset:u=0,drawDefinition:d,staggeredEntry:p,sequenceLimit:v,stage:f=de,structureId:m,matchUpType:g,idPrefix:h,drawSize:_,isMock:I,uuids:P}){if(!(!i||!c||(i==null?void 0:i[a]))||_<2||v&&s>v)return{};const y=[],S=[],T=[];g=g||(d==null?void 0:d.matchUpType);const E=t+1,b=t+_,N=`${E}-${b}`,w=i==null?void 0:i[a],$=r&&`${r} `||"",U=n==null?void 0:n[N],A=(U==null?void 0:U.name)||(w==null?void 0:w.name)&&(e?`${$}${w==null?void 0:w.name}`:w.name)||`${$}${N}`,M=(U==null?void 0:U.abbreviation)||(w==null?void 0:w.abbreviation),C={idPrefix:h&&`${h}-${A}-RP`,finishingPositionOffset:t,matchUpType:g,drawSize:_,isMock:I,uuids:P},{matchUps:D}=p?Ko(C):Ln(C),F=kt({structureId:m||(P==null?void 0:P.pop()),structureAbbreviation:M,stageSequence:s,structureName:A,matchUpType:g,roundOffset:u,matchUps:D,stage:f});y.push(...D),S.push(F);const R=Math.ceil(Math.log(_)/Math.log(2)),G=l?Math.min(l-u,R):!o||E<o?R:0;return _>2&&le(1,G+1).forEach(z=>x(z)),OX({structureId:F.structureId,matchUps:y,structureName:A,structures:S,links:T},B);function x(z){const j=_/Math.pow(2,z);if(j<2)return;const V=_/Math.pow(2,z)+t;if(V+1>o)return;const{structures:L,structureId:q,matchUps:k,links:H}=Ca({finishingPositionOffset:V,exitProfile:`${a}-${z}`,roundOffset:u+z,stageSequence:s+1,drawSize:j,addNameBaseToAttributeName:e,playoffStructureNameBase:r,finishingPositionNaming:n,finishingPositionLimit:o,playoffAttributes:i,exitProfileLimit:c,roundOffsetLimit:l,drawDefinition:d,sequenceLimit:v,matchUpType:g,idPrefix:h,uuids:P,stage:f}),Q={linkType:qn,source:{roundNumber:z,structureId:F==null?void 0:F.structureId},target:{roundNumber:1,feedProfile:Cn,structureId:q}};return F&&q&&H.push(Q),H!=null&&H.length&&T.push(...H),L!=null&&L.length&&S.push(...L),k!=null&&k.length&&y.push(...k),{structureId:q,childLinks:H,structures:S}}}var bX=Object.defineProperty,TX=Object.defineProperties,EX=Object.getOwnPropertyDescriptors,m$=Object.getOwnPropertySymbols,wX=Object.prototype.hasOwnProperty,$X=Object.prototype.propertyIsEnumerable,g$=(t,e,r)=>e in t?bX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,NX=(t,e)=>{for(var r in e||(e={}))wX.call(e,r)&&g$(t,r,e[r]);if(m$)for(var r of m$(e))$X.call(e,r)&&g$(t,r,e[r]);return t},AX=(t,e)=>TX(t,EX(e));function Os(t={}){const{finishingPositionOffset:e,policyDefinitions:r,stageSequence:n=1,feedsFromFinal:o,staggeredEntry:i,structureName:s,structureId:a,matchUpType:c,skipRounds:l,feedRounds:u,idPrefix:d,drawSize:p,isMock:v,uuids:f,fmlc:m}=t,g=t.feedPolicy||(r==null?void 0:r[kl]),h={finishingPositionOffset:e,matchUpType:c,skipRounds:l,drawSize:p,idPrefix:d,isMock:v,uuids:f},{matchUps:_}=i?Ko(h):Ln(h),I=kt({structureId:a||(f==null?void 0:f.pop()),structureName:s||de,stageSequence:n,stage:de,matchUpType:c,matchUps:_}),P=[I],O=[],y=p/2,{matchUps:S,roundsCount:T}=Ko({finishingPositionOffset:y,idPrefix:d&&`${d}-c`,isConsolation:!0,feedsFromFinal:o,baseDrawSize:y,matchUpType:c,feedRounds:u,skipRounds:l,isMock:v,uuids:f,fmlc:m});if(p>2){const E=kt({matchUps:S,structureId:f==null?void 0:f.pop(),structureName:$t,stage:$t,stageSequence:1,matchUpType:c});P.push(E);const b=l$({consolationStructure:E,mainStructure:I,roundsCount:T,feedPolicy:g,fmlc:m});O.push(...b)}return AX(NX({},B),{structures:P,links:O})}var UX=Object.defineProperty,CX=Object.defineProperties,MX=Object.getOwnPropertyDescriptors,h$=Object.getOwnPropertySymbols,DX=Object.prototype.hasOwnProperty,jX=Object.prototype.propertyIsEnumerable,_$=(t,e,r)=>e in t?UX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,RX=(t,e)=>{for(var r in e||(e={}))DX.call(e,r)&&_$(t,r,e[r]);if(h$)for(var r of h$(e))jX.call(e,r)&&_$(t,r,e[r]);return t},FX=(t,e)=>CX(t,MX(e));function I$({compassAttributes:t=Uf,olympicAttributes:e=Cf,requireSequential:r=!0,playoffMatchUpFormat:n,sourceStructureId:o,policyDefinitions:i,stageSequence:s,drawDefinition:a,playoffGroups:c,matchUpType:l,feedPolicy:u,groupCount:d,idPrefix:p,isMock:v,uuids:f}){var m,g;u=u||(i==null?void 0:i[kl]);const h="processPlayoffGroups";let _=0;const I=[],P=[],O=[],{error:y,positionRangeMap:S}=iX({structureId:o,drawDefinition:a,playoffGroups:c});if(y)return W({result:{error:y},stack:h});if(!(!S||(c==null?void 0:c.every(E=>{const{finishingPositions:b=[]}=E;if(!b.length)return!1;const N=b.sort().map((w,$)=>(b[$+1]||w)-w).every(w=>w<2);return(!r||N)&&b.every(w=>S[w])}))))return W({context:{validFinishingPositions:Object.values(S)},result:{error:Z},stack:h});for(const E of c){const b=E.finishingPositions,N=S&&b.map(C=>{var D;return(D=S[C])==null?void 0:D.finishingPositions}).flat(),w=E.drawType||zn,$=d*b.length,U=Ds($);N&&(_=Math.min(...N)-1);const A={structureName:E.structureName,idPrefix:p&&`${p}-po`,appliedPolicies:i,structureId:f==null?void 0:f.pop(),finishingPositionOffset:_,stage:st,stageSequence:s,matchUpType:l,drawSize:U,isMock:v,uuids:f},M=({playoffStructures:C,playoffLinks:D})=>{const[F]=C,R=wd({playoffStructureId:F.structureId,finishingPositions:b,sourceStructureId:o});O.push(R),O.push(...D),P.push(...C),I.push({structureId:F.structureId,finishingPositions:b}),_+=$};if(w===zn){const{matchUps:C}=Ln({finishingPositionLimit:_+$,idPrefix:p&&`${p}-po`,finishingPositionOffset:_,matchUpType:l,drawSize:U,isMock:v,uuids:f}),D=kt({structureName:E.structureName,matchUpFormat:n,structureId:f==null?void 0:f.pop(),stage:st,stageSequence:s,matchUpType:l,matchUps:C});P.push(D);const F=wd({playoffStructureId:D.structureId,finishingPositions:b,sourceStructureId:o});O.push(F),_+=$,I.push({structureId:D.structureId,finishingPositions:b})}else if([ea,ta,st].includes(w)){const{structureName:C}=E,D={playoffStructureNameBase:C,idPrefix:p&&`${p}-po`,addNameBaseToAttributeName:!0,finishingPositionOffset:_,stage:st,roundOffset:0,stageSequence:s,drawSize:U,isMock:v,uuids:f};w===ea?Object.assign(D,{roundOffsetLimit:3,playoffAttributes:t}):w===ta&&Object.assign(D,{roundOffsetLimit:2,playoffAttributes:e});const F=Ca(D);if(F.error)return F;if((m=F.links)!=null&&m.length&&O.push(...F.links),(g=F.structures)!=null&&g.length&&P.push(...F.structures),P.sort(Ii),F.structureId){const R=wd({playoffStructureId:F.structureId,finishingPositions:b,sourceStructureId:o});O.push(R),I.push({structureId:F.structureId,finishingPositions:b})}_+=$}else if([ra,Ac,$c,wc,Ec,Nc].includes(w)){const C=[f==null?void 0:f.pop(),f==null?void 0:f.pop()],D={structureName:E.structureName,idPrefix:p&&`${p}-po`,finishingPositionOffset:_,uuids:C,stage:st,matchUpType:l,feedPolicy:u,drawSize:U,isMock:v},F={[ra]:{fmlc:!0,feedRounds:1},[Nc]:{feedRounds:1},[$c]:{feedsFromFinal:3},[wc]:{feedsFromFinal:2},[Ec]:{feedsFromFinal:1}};Object.assign(D,F[w]||{});const{structures:R,links:G}=Os(D),[x]=R,z=wd({playoffStructureId:x.structureId,finishingPositions:b,sourceStructureId:o});O.push(z),O.push(...G),P.push(...R),I.push({structureId:x.structureId,finishingPositions:b}),_+=$}else if([ln].includes(w)){const{structures:C,links:D}=qc(FX(RX({},A),{structureOptions:E.structureOptions||{groupSize:4}}));M({playoffStructures:C,playoffLinks:D})}else if([Tc].includes(w)){const{structures:C,links:D}=c$(A);M({playoffStructures:C,playoffLinks:D})}else if([bk].includes(w)){const{structures:C,links:D}=p$(A);M({playoffStructures:C,playoffLinks:D})}else if([cn].includes(w)){const C=kt({structureName:E.structureName,finishingPosition:ac,structureId:f==null?void 0:f.pop(),stage:st,stageSequence:s,matchUps:[],matchUpType:l});M({playoffStructures:[C],playoffLinks:[]})}}return{finishingPositionTargets:I,positionRangeMap:S,structures:P,links:O}}function wd({playoffStructureId:t,finishingPositions:e,sourceStructureId:r}){return{linkType:ho,source:{structureId:r,finishingPositions:e},target:{structureId:t,feedProfile:an,roundNumber:1}}}var LX=Object.defineProperty,VX=Object.defineProperties,xX=Object.getOwnPropertyDescriptors,P$=Object.getOwnPropertySymbols,BX=Object.prototype.hasOwnProperty,kX=Object.prototype.propertyIsEnumerable,y$=(t,e,r)=>e in t?LX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,S$=(t,e)=>{for(var r in e||(e={}))BX.call(e,r)&&y$(t,r,e[r]);if(P$)for(var r of P$(e))kX.call(e,r)&&y$(t,r,e[r]);return t},GX=(t,e)=>VX(t,xX(e));function WX(t){const{drawDefinition:e,structureOptions:r,requireSequential:n}=t,o=Object.assign({structureName:de},t,{stage:de}),{structures:i,groupCount:s,groupSize:a}=qc(o);s<1&&console.log(nL);const c=(r==null?void 0:r.playoffGroups)||[{finishingPositions:[1],structureName:st}],[l]=i,{structures:u,links:d}=I$(S$({sourceStructureId:l.structureId,requireSequential:n,drawDefinition:e,playoffGroups:c,groupCount:s,groupSize:a},t));return i.push(...u),GX(S$({},B),{structures:i,links:d})}function HX({mainStructure:t,consolationStructure:e,deciderStructure:r}){const o=e.matchUps.reduce((u,d)=>(d.drawPositions||[]).filter(Boolean).length&&!u.includes(d.roundNumber)?u.concat(d.roundNumber):u,[]),i=t.matchUps.reduce((u,d)=>!u||d.roundNumber>u?d.roundNumber:u,void 0),s=e.matchUps.reduce((u,d)=>!u||d.roundNumber>u?d.roundNumber:u,void 0),a=o.map((u,d)=>{const v=o.indexOf(u)%2?Cn:rs,f=1+d;return{linkType:qn,source:{roundNumber:f,structureId:t.structureId},target:{feedProfile:v,roundNumber:u,structureId:e.structureId}}}),c={linkType:_o,source:{roundNumber:s,structureId:e.structureId},target:{feedProfile:Cn,roundNumber:i,structureId:t.structureId}},l=[{linkType:_o,source:{roundNumber:i,structureId:t.structureId},target:{feedProfile:Cn,roundNumber:1,structureId:r.structureId}},{linkType:qn,source:{roundNumber:i,structureId:t.structureId},target:{feedProfile:Cn,roundNumber:1,structureId:r.structureId}}];return[...a,c,...l]}var qX=Object.defineProperty,O$=Object.getOwnPropertySymbols,YX=Object.prototype.hasOwnProperty,zX=Object.prototype.propertyIsEnumerable,b$=(t,e,r)=>e in t?qX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,KX=(t,e)=>{for(var r in e||(e={}))YX.call(e,r)&&b$(t,r,e[r]);if(O$)for(var r of O$(e))zX.call(e,r)&&b$(t,r,e[r]);return t};function QX({structureName:t,matchUpType:e,idPrefix:r,drawSize:n,isMock:o,uuids:i}){const s=[],{matchUps:a}=Ko({linkFedFinishingRoundNumbers:[1],drawSize:n+1,matchUpType:e,idPrefix:r,isMock:o}),c=kt({structureName:t||de,structureId:i==null?void 0:i.pop(),stageSequence:1,stage:de,matchUpType:e,matchUps:a});s.push(c);const l=n/2,{matchUps:u}=Ko({finishingPositionOffset:l,idPrefix:r&&`${r}-c`,drawSize:n-1,isConsolation:!0,matchUpType:e,isMock:o,uuids:i}),d=kt({matchUps:u,structureId:i==null?void 0:i.pop(),structureName:SP,stage:$t,stageSequence:2,matchUpType:e});s.push(d);const{matchUps:p}=Ln({idPrefix:r&&`${r}-p1t2`,drawSize:2,matchUpType:e,isMock:o}),v=kt({matchUps:p,structureId:i==null?void 0:i.pop(),structureName:yP,stageSequence:3,stage:st,matchUpType:e});s.push(v);const f=HX({mainStructure:c,consolationStructure:d,deciderStructure:v});return KX({structures:s,links:f},B)}function JX(t){const{qualifyingRoundNumber:e,finishingPositionOffset:r,qualifyingPositions:n,matchUpType:o,idPrefix:i,drawSize:s,isMock:a,uuids:c}=t;if(!ut(s)||s<2)return{matchUps:[],roundsCount:0};if(Vr(s))return Ln(t);const l=ZX(s),u=l.shift(),d=le(1,u.participantsCount+1).map(g=>({drawPosition:g}));let p=[],v=1;({matchUps:p}=bd({roundNumber:v,matchUpType:o,idPrefix:i,matchUps:p,isMock:a,nodes:d,uuids:c})),v++;let f=t.roundLimit||e;for(const g of l){const h=g.participantsCount/2,_=le(1,h+1);n&&h===n&&(f=v-1);const I=_.map(P=>{const O=bm({roundPosition:P,roundNumber:v,idPrefix:i,uuids:c});return{roundPosition:P,roundNumber:v,matchUpId:O}});p.push(...I),v++}const m=v-1;return p=Vc({finishingPositionOffset:r,lucky:!0,roundsCount:m,roundLimit:f,matchUps:p}),f&&(p=p.filter(g=>g.roundNumber<=f)),{matchUps:p,roundsCount:m,roundLimit:f}}function ZX(t){const e=parseInt(t);let r=e%2?e+1:e;const n=!!(Math.ceil(r/2)%2),o=[{participantsCount:r,preFeedRound:n}];for(;r>2;){const i=Math.ceil(r/2),s=i===1,a=!!(!s&&i%2);r=!s&&a?i+1:i;const c=!!(r!==2&&Math.ceil(r/2)%2);o.push({participantsCount:r,preFeedRound:c,feedRound:a})}return o}var XX=Object.defineProperty,eee=Object.defineProperties,tee=Object.getOwnPropertyDescriptors,T$=Object.getOwnPropertySymbols,ree=Object.prototype.hasOwnProperty,nee=Object.prototype.propertyIsEnumerable,E$=(t,e,r)=>e in t?XX(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,oo=(t,e)=>{for(var r in e||(e={}))ree.call(e,r)&&E$(t,r,e[r]);if(T$)for(var r of T$(e))nee.call(e,r)&&E$(t,r,e[r]);return t},bs=(t,e)=>eee(t,tee(e));function w$(t){var e;const{compassAttributes:r=Uf,olympicAttributes:n=Cf,stageSequence:o=1,structureName:i,structureId:s,stage:a=de,matchUpType:c,drawSize:l,uuids:u}=t,{appliedPolicies:d}=at(t),p=((e=t.policyDefinitions)==null?void 0:e[kl])||d[kl];t.skipRounds=t.skipRounds||l<=4&&(p!=null&&p.feedMainFinal?0:1)||0;const v=()=>{const{matchUps:m}=Ln(t),g=kt({structureName:i||de,structureId:s||(u==null?void 0:u.pop()),stageSequence:o,matchUpType:c,matchUps:m,stage:a});return oo({structures:[g],links:[]},B)};return{generators:{[cn]:()=>{const m=kt({structureName:i||de,structureId:s||(u==null?void 0:u.pop()),finishingPosition:na,stageSequence:o,matchUps:[],matchUpType:c,stage:a});return oo({structures:[m],links:[]},B)},[hi]:()=>{const{matchUps:m}=JX(t),g=kt({structureName:i||de,structureId:s||(u==null?void 0:u.pop()),stageSequence:o,matchUpType:c,matchUps:m,stage:a});return oo({structures:[g],links:[]},B)},[zn]:()=>v(),[bc]:()=>QX(t),[ea]:()=>Ca(bs(oo({},t),{roundOffsetLimit:3,playoffAttributes:r})),[ta]:()=>Ca(bs(oo({},t),{roundOffsetLimit:2,playoffAttributes:n})),[st]:()=>Ca(t),[Xs]:()=>{const{matchUps:m}=Ko({drawSize:l,uuids:u,matchUpType:c}),g=kt({structureName:i||de,structureId:s||(u==null?void 0:u.pop()),stageSequence:o,matchUpType:c,stage:de,matchUps:m});return oo({structures:[g],links:[]},B)},[Tc]:()=>c$(t),[ra]:()=>Os(bs(oo({},t),{feedRounds:1,fmlc:!0})),[PP]:()=>Os(bs(oo({},t),{feedRounds:1})),[$f]:()=>Os(bs(oo({},t),{feedsFromFinal:1})),[Nf]:()=>Os(bs(oo({},t),{feedsFromFinal:2})),[Af]:()=>Os(bs(oo({},t),{feedsFromFinal:3})),[Ac]:()=>Os(t),[iu]:()=>p$(t),[ln]:()=>qc(t),[Io]:()=>WX(t)}}}var oee=Object.defineProperty,iee=Object.defineProperties,see=Object.getOwnPropertyDescriptors,$$=Object.getOwnPropertySymbols,aee=Object.prototype.hasOwnProperty,cee=Object.prototype.propertyIsEnumerable,N$=(t,e,r)=>e in t?oee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lee=(t,e)=>{for(var r in e||(e={}))aee.call(e,r)&&N$(t,r,e[r]);if($$)for(var r of $$(e))cee.call(e,r)&&N$(t,r,e[r]);return t},uee=(t,e)=>iee(t,see(e));function wm(t={}){var e,r,n,o,i;const{enforceMinimumDrawSize:s=!0,overwriteExisting:a,drawTypeCoercion:c,appliedPolicies:l,staggeredEntry:u,drawDefinition:d,drawSize:p,isMock:v,uuids:f}=t,m="generateDrawStructuresAndLinks";let g=t.drawType||zn;const h=[],_=[];let{tieFormat:I,matchUpType:P}=t;P=P||pt;const O=(e=d==null?void 0:d.structures)==null?void 0:e.filter(({stage:q})=>q===Ie);O&&h.push(...O);const y=O==null?void 0:O.map(({structureId:q})=>q),S=(r=d==null?void 0:d.structures)==null?void 0:r.find(({stage:q,stageSequence:k})=>q===de&&k===1),T=(n=d==null?void 0:d.links)==null?void 0:n.filter(q=>q.target.structureId===(S==null?void 0:S.structureId)&&(y==null?void 0:y.includes(q.source.structureId))),E=(q,k)=>{var H;if(q.linkType===ho&&(k!=null&&k.structures)){const Q=q.source.finishingPositions||[];return k.structures.length*Q.length}else if(q.linkType===_o&&((H=k==null?void 0:k.matchUps)!=null&&H.length)){const Q=q.source.roundNumber;return k.matchUps.filter(({roundNumber:Y})=>Y===Q).length}},b=O==null?void 0:O.map(q=>{var k,H,Q;const K=T==null?void 0:T.find(oe=>oe.target.structureId===q.structureId),Y=((H=(k=et({structure:q}))==null?void 0:k.positionAssignments)==null?void 0:H.length)||0;if(!K)return Y;const J=K==null?void 0:K.source.structureId,te=(Q=d.structures)==null?void 0:Q.find(oe=>oe.structureId===J),ne=E(K,te)||0;return Y-ne}).filter(Boolean).reduce((q,k)=>q+k,0),N=T==null?void 0:T.map(q=>{const k=q.source.structureId,H=O==null?void 0:O.find(Q=>Q.structureId===k);return E(q,H)}).filter(Boolean).reduce((q,k)=>q+k,0),w=!!(S&&!((o=S==null?void 0:S.matchUps)!=null&&o.length));if(O!=null&&O.length&&!w)return{error:Hh};const $=!(O!=null&&O.length)&&t.qualifyingProfiles,U=($==null?void 0:$.length)&&Xw({idPrefix:t.idPrefix,qualifyingProfiles:$,appliedPolicies:l,matchUpType:P,isMock:v,uuids:f});if(U!=null&&U.error)return U;const{qualifyingDrawPositionsCount:A,qualifyingDetails:M,qualifiersCount:C}=U||{qualifyingDrawPositionsCount:b,qualifiersCount:N};A&&(U!=null&&U.structures&&h.push(...U.structures),U!=null&&U.links&&_.push(...U.links)),Object.assign(t,_e({drawSize:p,matchUpType:P,tieFormat:I}));const D=g!==cn&&(isNaN(p)||p<2||!u&&![Xs,hi].includes(g)&&([Io,ln].includes(g)&&p<3||![ln,Io].includes(g)&&!Vr(p)));if(D&&!A)return W({context:{drawSize:p,invalidDrawSize:D},result:{error:Tp},stack:m});const F=OP.includes(g);if(parseInt(p)<4&&F){if(c)g=zn;else if(s)return W({context:{enforceMinimumDrawSize:s,invalidDrawSize:D,drawSize:p,drawType:g},result:{error:Tp},stack:m})}const{generators:R,error:G}=w$(t);if(G)return{error:G};const x=R[g];if(!x)return{error:vh};const z=x==null?void 0:x();if(z.error)return z;const{structures:j,links:V}=z;if(j!=null&&j.length){const q=j.find(({stage:k,stageSequence:H})=>k===de&&H===1);if(S&&q){if(w){const k=q.structureId;if(q.structureId=S.structureId,V!=null&&V.length)for(const H of V)H.source.structureId===k&&(H.source.structureId=S.structureId),H.target.structureId===k&&(H.target.structureId=S.structureId)}else if(!a)return{error:Hh}}h.push(...j)}h.sort(Ii),V!=null&&V.length&&_.push(...V);const L=z.structures.find(({stage:q,stageSequence:k})=>q===de&&k===1);for(const q of M||[]){const{finalQualifyingRoundNumber:k,finalQualifyingStructureId:H,roundTarget:Q,finishingPositions:K,linkType:Y}=q,J=L&&((i=Ua({targetStructureId:L.structureId,sourceStructureId:H,sourceRoundNumber:k,finishingPositions:K,targetEntryRound:Q,linkType:Y}))==null?void 0:i.link);if(J!=null&&J.error)return J;J&&_.push(J)}return T&&_.push(...T),uee(lee({},B),{qualifyingResult:{qualifyingDrawPositionsCount:A,qualifiersCount:C},structures:h,links:_})}function Ni({provisionalPositioning:t,drawDefinition:e,stageSequence:r,structureId:n,stage:o}){var i,s,a,c,l,u,d,p;if(!e)return{error:pe};const{entryProfile:v}=Oc({drawDefinition:e}),f=((a=(s=(i=v==null?void 0:v[o])==null?void 0:i.stageSequence)==null?void 0:s[r])==null?void 0:a.qualifiersCount)||((c=v==null?void 0:v[o])==null?void 0:c.qualifiersCount)||0,m={};if(!n)return{qualifiersCount:f,roundQualifiersCounts:m};const{structure:g}=Te({drawDefinition:e,structureId:n}),h=(l=e.links)==null?void 0:l.filter(P=>{var O;return((O=P==null?void 0:P.target)==null?void 0:O.structureId)===(g==null?void 0:g.structureId)});let _=0;if(h!=null&&h.length)for(const P of h){const O=(u=Te({structureId:P.source.structureId,drawDefinition:e}))==null?void 0:u.structure;if(O.stage===Ie){const y=P.source.roundNumber,S=P.target.roundNumber;let T=0;if(O.structureType===tr){const E=((d=O.structures)==null?void 0:d.length)||0,b=((p=P.source.finishingPositions)==null?void 0:p.length)||0;T=E*b}else{const E=ze({matchUpFilters:{roundNumbers:[y]},provisionalPositioning:t,structure:O,afterRecoveryTimes:!1,inContext:!1}).matchUps;T=(E==null?void 0:E.length)||0}m[S]||(m[S]=0),m[S]+=T,_+=T}}const I=Object.keys(m);if(I.length<=1){const P=I[0]||1;m[P]=Math.max(m[P]||0,f)}return _=Math.max(_,f),{qualifiersCount:_,roundQualifiersCounts:m}}function ll({stage:t,drawDefinition:e}){var r;const{entryProfile:n}=Oc({drawDefinition:e});return((r=n==null?void 0:n[t])==null?void 0:r.drawSize)||0}function dee({provisionalPositioning:t,drawDefinition:e,stageSequence:r,stage:n}){const o=ll({stage:n,drawDefinition:e}),{qualifiersCount:i}=Ni({provisionalPositioning:t,drawDefinition:e,stageSequence:r,stage:n});return o&&o-i}function $d({tieFormat:t,uuids:e,isMock:r}){const{collectionDefinitions:n}=t||{};return{tieMatchUps:(n||[]).map(i=>Nd({collectionDefinition:i,uuids:e,isMock:r})).filter(Boolean).flat()}}function Nd({collectionDefinition:t,matchUpsLimit:e,isMock:r,uuids:n}){const{matchUpCount:o,matchUpType:i,collectionId:s,processCodes:a}=t||{};return le(0,e||o||0).map(l=>{const u=l+1;return{sides:[{sideNumber:1},{sideNumber:2}],matchUpId:(n==null?void 0:n.pop())||We(),matchUpStatus:vt,collectionPosition:u,collectionId:s,processCodes:a,matchUpType:i,isMock:r}})}var pee=Object.defineProperty,fee=Object.defineProperties,vee=Object.getOwnPropertyDescriptors,A$=Object.getOwnPropertySymbols,mee=Object.prototype.hasOwnProperty,gee=Object.prototype.propertyIsEnumerable,U$=(t,e,r)=>e in t?pee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ad=(t,e)=>{for(var r in e||(e={}))mee.call(e,r)&&U$(t,r,e[r]);if(A$)for(var r of A$(e))gee.call(e,r)&&U$(t,r,e[r]);return t},hee=(t,e)=>fee(t,vee(e));function ul({stageSequence:t=1,drawDefinition:e,drawSize:r,stage:n}){if(!e)return{error:pe};if(!Cc({drawDefinition:e,stage:n}))return{error:No};const o=EP({drawDefinition:e,stage:n}),{qualifiersCount:i}=Ni({drawDefinition:e,stageSequence:t,stage:n}),s=o+i;if(r<s)return{error:Tl};const{entryProfile:a}=Sc({attributes:[{[n]:{drawSize:r}}],drawDefinition:e});return Je({drawDefinition:e}),hee(Ad({},B),{entryProfile:a})}function _ee({alternatesCount:t,drawDefinition:e,stage:r}){var n;return e?Cc({drawDefinition:e,stage:r})?(Sc({attributes:[{[r]:{alternates:t}}],drawDefinition:e}),t||(e.entries=((n=e.entries)==null?void 0:n.filter(o=>o.entryStatus!==un))||[]),Je({drawDefinition:e}),Ad({},B)):{error:No}:{error:pe}}function Iee({wildcardsCount:t=0,drawDefinition:e,stageSequence:r,stage:n}){if(!e)return{error:pe};if(!Cc({drawDefinition:e,stage:n}))return{error:No};const o=ll({drawDefinition:e,stage:n}),{qualifiersCount:i}=Ni({drawDefinition:e,stageSequence:r,stage:n}),s=Ck({drawDefinition:e,stage:n}),a=EP({drawDefinition:e,stage:n});return t<s?{error:Object.assign(Tl,{message:"Number of Wildcards cannot be less than number of Wildcards already entered"})}:a+t+i>o?{error:Tl,info:"Total stage Entries cannot be greater than drawPositions"}:(Sc({attributes:[{[n]:{wildcardsCount:t}}],drawDefinition:e}),Je({drawDefinition:e}),Ad({},B))}function $m({qualifiersCount:t=0,drawDefinition:e,stage:r}){return e?Cc({drawDefinition:e,stage:r})?r!==de?{error:Tl,info:"qualifiersCount can only be set for main stage"}:(Sc({attributes:[{[r]:{qualifiersCount:t}}],drawDefinition:e}),Je({drawDefinition:e}),Ad({},B)):{error:No}:{error:pe}}var Pee=Object.defineProperty,yee=Object.defineProperties,See=Object.getOwnPropertyDescriptors,C$=Object.getOwnPropertySymbols,Oee=Object.prototype.hasOwnProperty,bee=Object.prototype.propertyIsEnumerable,M$=(t,e,r)=>e in t?Pee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tee=(t,e)=>{for(var r in e||(e={}))Oee.call(e,r)&&M$(t,r,e[r]);if(C$)for(var r of C$(e))bee.call(e,r)&&M$(t,r,e[r]);return t},Eee=(t,e)=>yee(t,See(e));function Nm(t={}){var e;const{modifyOriginal:r=!0,stageSequence:n=1,isMock:o}=t,i="generateDrawTypeAndModifyDrawDefinition";if(!t.drawDefinition)return W({result:{error:pe},stack:i});const s=r?t.drawDefinition:ue(t.drawDefinition,!1,!0);let{tieFormat:a,matchUpType:c}=t;if(a){const P=ur({tieFormat:a});if(P.error)return P}a=pn(a||((e=Xt({drawDefinition:s}))==null?void 0:e.tieFormat)),c=c||s.matchUpType||pt,t.tieFormat=a,t.matchUpType=c;const l=ll({drawDefinition:s,stage:de});t.drawSize=t.drawSize||l,!l&&t.drawSize&&ul({drawSize:t.drawSize,drawDefinition:s,stageSequence:n,stage:de});const u=Kt({drawDefinition:s}).drawMatchUps.map(Mt),d=wm(t);if(d.error)return W({result:d,stack:i});const{structures:p,links:v,qualifyingResult:f}=d;s.structures=p,s.links=v;const m=Math.max(t.qualifiersCount||0,(f==null?void 0:f.qualifiersCount)||0);if(f!=null&&f.qualifyingDrawPositionsCount&&!ll({stage:Ie,drawDefinition:s})){const O=ul({drawSize:f.qualifyingDrawPositionsCount,stage:Ie,drawDefinition:s});if(O.error)return O}if(m){const P=$m({qualifiersCount:m,drawDefinition:s,stage:de});if(P.error)return P}const g=t.drawSize||l;Object.assign(t,_e({drawSize:g,matchUpType:c,tieFormat:a}));const{matchUps:h,matchUpsMap:_}=Nt({drawDefinition:s});a&&h.forEach(P=>{if(!u.includes(P.matchUpId)){const{tieMatchUps:O}=$d({tieFormat:a,isMock:o});Object.assign(P,{tieMatchUps:O,matchUpType:c})}});const{inContextDrawMatchUps:I}=fa({drawDefinition:s,matchUpsMap:_});return Je({drawDefinition:s}),Eee(Tee({inContextDrawMatchUps:I,drawDefinition:s,matchUpsMap:_},B),{structures:p,matchUps:h,links:v})}function wee({targetParticipantIds:t,policyAttributes:e,idCollections:r,participants:n}){if(!Array.isArray(e))return{error:Oh};if(!Array.isArray(n))return{error:Qa};const o={};return t.forEach(i=>{const s=n.find(c=>c.participantId===i),{values:a}=D$({policyAttributes:e,idCollections:r,participants:n,participant:s});a&&a.forEach(c=>{o[c]||(o[c]=[]),o[c].includes(i)||o[c].push(i)})}),o}function D$({policyAttributes:t,idCollections:e,participants:r,participant:n}){if(!Array.isArray(t))return{error:Oh};if(!n)return{error:Ls};const o=[];return t.forEach(a=>{const{directive:c,groupings:l,key:u,significantCharacters:d}=a||{};if(u){const p=u.split(".");s({value:n,keys:p,significantCharacters:d})}else if(c){const p=a==null?void 0:a.includeIds,v=((e==null?void 0:e[c])||[]).filter(f=>!p||p.includes(f));v!=null&&v.length&&(r!=null&&r.length)&&v.forEach(f=>{var m;const g=r.find(h=>h.participantId===f);if((m=g==null?void 0:g.individualParticipantIds)!=null&&m.includes(n.participantId)){const h=g==null?void 0:g.participantId;o.push(h)}})}else l&&Object.keys(l).forEach(p=>{l[p].includes(n.participantId)&&o.push(p)})}),{values:Ve(o)};function s({value:a,keys:c=[],significantCharacters:l}){for(const[d,p]of c.entries())if(a!=null&&a[p])if(Array.isArray(a[p])){const v=a[p],f=c.slice(d);v.forEach(m=>s({value:m,keys:f,significantCharacters:l}))}else a=a[p],u({value:a,index:d});function u({value:d,index:p}){if(d&&p===c.length-1&&["string","number"].includes(typeof d)){const v=l?d.slice(0,l):d;o.push(v)}}}}var $ee=Object.defineProperty,Nee=Object.defineProperties,Aee=Object.getOwnPropertyDescriptors,j$=Object.getOwnPropertySymbols,Uee=Object.prototype.hasOwnProperty,Cee=Object.prototype.propertyIsEnumerable,R$=(t,e,r)=>e in t?$ee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Mee=(t,e)=>{for(var r in e||(e={}))Uee.call(e,r)&&R$(t,r,e[r]);if(j$)for(var r of j$(e))Cee.call(e,r)&&R$(t,r,e[r]);return t},Dee=(t,e)=>Nee(t,Aee(e));function F$({candidatePositionAssignments:t,participantsWithGroupings:e,policyAttributes:r,idCollections:n}){const o=Object.assign({},...e.map(i=>({[i.participantId]:i})));return t.map(i=>{const s=o[i.participantId],{values:a}=D$({participants:e,policyAttributes:r,idCollections:n,participant:s});return Dee(Mee({},i),{values:a})})}function L$({participantIdGroups:t,positionAssignments:e,groupsToAvoid:r}){return Object.assign({},...e.filter(n=>n==null?void 0:n.participantId).map(n=>{const{drawPosition:o,participantId:i}=n,s=t?t[i]||[]:[],a=!!r.some(c=>s.includes(c));return{[o]:{participantGroups:s,includesGroupsToAvoid:a}}}))}function jee(t){const{unfilledPositions:e,chunkedDrawPositions:r}=t,n=L$(t);return r.map(s=>{const a=e.filter(d=>s.includes(d)),c=i(a),u=a.filter(d=>!c.includes(d)).filter(d=>{var p;const v=V$(d);return!((p=n[v])!=null&&p.includesGroupsToAvoid)});return{unassigned:a,unpaired:c,pairedNoConflict:u}});function i(s){return s.filter(c=>!a(c));function a(c){const l=V$(c);return!s.includes(l)}}}function Ree(t){const{unfilledPositions:e,chunkedDrawPositions:r}=t,n=L$(t);return r.map(o=>{const i=e.filter(l=>o.includes(l)),s=i.length===o.length?i:[],a=o.filter(l=>{var u;return(u=n[l])==null?void 0:u.includesGroupsToAvoid}).length;return{unassigned:i,unpaired:s,pairedNoConflict:a?[]:i,conflictsCount:a}})}function V$(t){return Number(t%2?t+1:t-1)}function Fee({allGroups:t,participantId:e}){return Object.keys(t).filter(r=>t[r].includes(e))}function Lee({selectedParticipantGroups:t,participantIdGroups:e,positionAssignments:r,drawPositionChunks:n,unfilledPositions:o,isRoundRobin:i}){const s=n.map(a=>i?Ree({groupsToAvoid:t,chunkedDrawPositions:a,participantIdGroups:e,positionAssignments:r,unfilledPositions:o}):jee({groupsToAvoid:t,chunkedDrawPositions:a,participantIdGroups:e,positionAssignments:r,unfilledPositions:o}));if(i){const a=s.map(u=>u.map(d=>d.unassigned).filter(d=>d==null?void 0:d.length)).filter(u=>u==null?void 0:u.length).sort((u,d)=>(d.length||0)-(u.length||0)),c=s.map(u=>u.map(d=>d.unpaired).filter(d=>d==null?void 0:d.length)).filter(u=>u==null?void 0:u.length),l=s.map(u=>u.map(d=>d.pairedNoConflict).filter(d=>d==null?void 0:d.length)).filter(u=>u==null?void 0:u.length).sort((u,d)=>(d.length||0)-(u.length||0));return{unassigned:a,unpaired:c,pairedNoConflict:l}}else{const a=s.map(u=>u.map(d=>d.unassigned).filter(d=>d==null?void 0:d.length)).filter(u=>u==null?void 0:u.length),c=s.map(u=>u.map(d=>d.unpaired).filter(d=>d==null?void 0:d.length)).filter(u=>u==null?void 0:u.length),l=s.map(u=>u.map(d=>d.pairedNoConflict).filter(d=>d==null?void 0:d.length)).filter(u=>u==null?void 0:u.length);return{unassigned:a,unpaired:c,pairedNoConflict:l}}}function x$({participantIds:t,positionAssignments:e}){const r=e.map(n=>n.participantId);return t.filter(n=>!r.includes(n))}function Vee({groupKey:t,allGroups:e,largestFirst:r=!0,targetParticipantIds:n,useSpecifiedGroupKey:o=!1}){var i;const s=Object.assign({},...Object.keys(e).map(d=>[d,e[d].filter(p=>n.includes(p))]).filter(d=>d[1].length).map(([d,p])=>({[d]:p}))),a=Object.keys(s).reduce((d,p)=>s[p].length>d?s[p].length:d,0),c=Object.keys(s).filter(d=>s[d].length===a),l=gr(r?c:Object.keys(s));return t=o&&((i=s[t])!=null&&i.length)?t:l,{participantId:t&&s[t]?gr(s[t]):gr(n),groupKey:t}}function xee({drawPositionGroups:t,positionAssignments:e}){const r=Object.assign({},...e.map(n=>({[n.drawPosition]:n})));return t.map(n=>n.filter(Boolean).map(o=>r[o]).filter(Boolean).filter(o=>!o.participantId&&!o.bye).map(o=>o.drawPosition)).flat().filter(Boolean)}function Bee({candidatePositionAssignments:t,unseededParticipantIds:e,participantIdGroups:r,drawPositionChunks:n,drawPositionGroups:o,pairedPriority:i,allGroups:s,groupKey:a}){const c=o.reduce((E,b)=>b.length>E?b.length:E,0),l=c<=2,u=x$({positionAssignments:t,participantIds:e}),d=xee({positionAssignments:t,drawPositionGroups:o}),{participantId:p,groupKey:v}=Vee({targetParticipantIds:u,useSpecifiedGroupKey:l,allGroups:s,groupKey:a}),f=Fee({participantId:p,allGroups:s}),m=Lee({positionAssignments:t,isRoundRobin:l,selectedParticipantGroups:f,participantIdGroups:r,drawPositionChunks:n,unfilledPositions:d,largestGroupSize:c,allGroups:s}),{unassigned:g,unpaired:h,pairedNoConflict:_}=m,I=(_==null?void 0:_.length)&&_[0],P=(h==null?void 0:h.length)&&h[0],O=i&&I?I:P,y=i?P:I,S=(O==null?void 0:O.length)&&O||(y==null?void 0:y.length)&&y;let T;if(S!=null&&S.length){const E=ir(S);T=ir(E)}else{const E=ir(g[0]);T=ir(E)}return{newGroupKey:v,selectedParticipantId:p,targetDrawPosition:T}}function Ud({isRoundRobin:t,groupedParticipants:e}){const r=[];return t?e.forEach(n=>{const o=n.map(a=>a.drawPosition),{uniqueMatchUpGroupings:i}=GO({drawPositions:o}),s=Object.assign({},...n.map(a=>({[a.drawPosition]:a})));i.forEach(a=>{Gt(s[a[0]].values||[],s[a[1]].values||[])&&(r.push(a),n.conflict=!0)})}):e.forEach(n=>{var o,i;Gt(((o=n[0])==null?void 0:o.values)||[],((i=n[1])==null?void 0:i.values)||[])&&(r.push(n),n.conflict=!0)}),r}function kee({positionedParticipants:t,potentialDrawPositions:e,avoidanceConflicts:r,drawPositionGroups:n,isRoundRobin:o}){return r.map(i=>{const s=i.map(c=>c.drawPosition);return i.filter(c=>e.includes(c.drawPosition)).map(c=>{const u=e.filter(d=>!(s!=null&&s.includes(d))).filter(d=>{const p=n.find(I=>I.includes(d)).find(I=>I!==d),v=t.find(I=>I.drawPosition===p),m=Ud({isRoundRobin:o,groupedParticipants:[[c,v]]}),h=[t.find(I=>I.drawPosition===d),v],_=Ud({isRoundRobin:o,groupedParticipants:[h]});return!m.length&&!_.length});if(u.length)return{drawPosition:c.drawPosition,possibleDrawPositions:u}}).filter(Boolean)}).flat(1)}var Gee=Object.defineProperty,Wee=Object.defineProperties,Hee=Object.getOwnPropertyDescriptors,B$=Object.getOwnPropertySymbols,qee=Object.prototype.hasOwnProperty,Yee=Object.prototype.propertyIsEnumerable,k$=(t,e,r)=>e in t?Gee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,G$=(t,e)=>{for(var r in e||(e={}))qee.call(e,r)&&k$(t,r,e[r]);if(B$)for(var r of B$(e))Yee.call(e,r)&&k$(t,r,e[r]);return t},zee=(t,e)=>Wee(t,Hee(e));function W$(t){const{initialPositionAssignments:e,participantsWithGroupings:r,opponentsToPlaceCount:n,unseededByePositions:o,drawPositionGroups:i,policyAttributes:s,idCollections:a,allGroups:c}=t,l=[];let u;const d=Math.min(...(i||[]).map(I=>I==null?void 0:I.length).filter(Boolean)),p=d>2,v=ue(e,!1,!0).filter(I=>!I.qualifier),f=e.filter(I=>!I.participantId&&(!I.bye||(o==null?void 0:o.includes(I.drawPosition)))).map(I=>I.drawPosition);le(0,n).forEach(()=>{const{newGroupKey:I,selectedParticipantId:P,targetDrawPosition:O}=Bee(zee(G$({},t),{candidatePositionAssignments:v,allGroups:c,groupKey:u}));u=I,v.forEach(y=>{y.drawPosition===O&&(y.participantId=P)})});let m=F$({candidatePositionAssignments:v,participantsWithGroupings:r,policyAttributes:s,idCollections:a}),g=Rt(m,d),h=Ud({groupedParticipants:g,isRoundRobin:p}),_=0;for(;_<20&&h.length;){const I=kee({positionedParticipants:m,potentialDrawPositions:f,avoidanceConflicts:h,drawPositionGroups:i,isRoundRobin:p});if(I.length){const P=Kee({candidatePositionAssignments:v,swapOptions:I});P.error&&console.log({result:P}),m=F$({candidatePositionAssignments:v,participantsWithGroupings:r,policyAttributes:s,idCollections:a}),g=Rt(m,d),h=Ud({groupedParticipants:g,isRoundRobin:p}),_++}else _=20}return v.forEach(I=>{if(I.bye&&I.participantId){const P=gh;l.push(P)}if(I.qualifier&&I.participantId){const P=gh;l.push(P)}}),{positionAssignments:v,conflicts:h.length,groupedParticipants:g,errors:l}}function Kee({candidatePositionAssignments:t,swapOptions:e}){const r=ir(e);if(!r)return{error:{message:"No swap options"}};const n=r.drawPosition,o=ir(r.possibleDrawPositions),i=t.find(l=>l.drawPosition===n),s=t.find(l=>l.drawPosition===o),a={participantId:s.participantId,qualifier:s.qualifier,bye:s.bye},c={participantId:i.participantId,qualifier:i.qualifier,bye:i.bye};return Object.assign(i,a),Object.assign(s,c),G$({},B)}var Qee=Object.defineProperty,H$=Object.getOwnPropertySymbols,Jee=Object.prototype.hasOwnProperty,Zee=Object.prototype.propertyIsEnumerable,q$=(t,e,r)=>e in t?Qee(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Am=(t,e)=>{for(var r in e||(e={}))Jee.call(e,r)&&q$(t,r,e[r]);if(H$)for(var r of H$(e))Zee.call(e,r)&&q$(t,r,e[r]);return t};function Xee({provisionalPositioning:t,unseededParticipantIds:e,inContextDrawMatchUps:r,unseededByePositions:n,tournamentRecord:o,drawDefinition:i,seedBlockInfo:s,participants:a,matchUpsMap:c,structureId:l,avoidance:u,entries:d,event:p}){var v;if(!u)return{error:OF};const{candidatesCount:f=1,policyAttributes:m,targetDivisions:g}=u;let{roundsToSeparate:h}=u;const _="randomUnseededSeparation";let{structure:I}=Te({drawDefinition:i,structureId:l});const{matchUps:P}=ze({provisionalPositioning:t,matchUpsMap:c,structure:I,event:p});if(g&&Vr(g)&&!h){const x=WR(g),z=P.reduce((j,V)=>V.roundNumber>j?V.roundNumber:j,0);h=z<x?1:z-x+1}let{positionAssignments:O}=Et({structure:I});const y=xf({participantsProfile:{convertExtensions:!0},participants:a}),S=O.filter(x=>!x.participantId),T=O.map(x=>x.drawPosition),E=I.structureType===tr,b=E?{structure:I,matchUps:P,allDrawPositions:T,roundsToSeparate:h}:{matchUps:P,allDrawPositions:T,roundsToSeparate:h},{drawPositionGroups:N,drawPositionChunks:w}=E?ete(b):tte(b),$={};$.groupParticipants=a.filter(x=>x.participantType===dr).map(x=>x.participantId),$.teamParticipants=a.filter(x=>x.participantType===Ye).map(x=>x.participantId),$.pairParticipants=a.filter(x=>x.participantType===we).map(x=>x.participantId);const U=wee({targetParticipantIds:e,policyAttributes:m,idCollections:$,participants:a}),A=Object.assign({},...e.map(x=>{const z=Object.keys(U).filter(j=>U[j].includes(x));return{[x]:z}}));let M=x$({participantIds:e,positionAssignments:O});if(M.length>S.length)return{error:jh};let C;const D=M.length,F=le(0,f).map(()=>W$({initialPositionAssignments:O,participantsWithGroupings:y,unseededParticipantIds:e,opponentsToPlaceCount:D,pairedPriority:!1,unseededByePositions:n,participantIdGroups:A,drawPositionChunks:w,drawPositionGroups:N,policyAttributes:m,idCollections:$,allGroups:U}));if(C=F.reduce((x,z)=>!x||(z.conflicts||0)<(x.conflicts||0)?z:x,void 0),!C||C.conflicts){const x=le(0,f).map(()=>W$({initialPositionAssignments:O,participantsWithGroupings:y,unseededParticipantIds:e,opponentsToPlaceCount:D,pairedPriority:!0,unseededByePositions:n,participantIdGroups:A,drawPositionChunks:w,drawPositionGroups:N,policyAttributes:m,idCollections:$,allGroups:U,entries:d}));C=F.concat(...x).filter(j=>{var V;return!((V=j.errors)!=null&&V.length)}).reduce((j,V)=>!j||(V.conflicts||0)<(j.conflicts||0)?V:j,void 0)}if(!C)return{error:Fp};const R=(((v=et({structure:I}))==null?void 0:v.positionAssignments)||[]).filter(x=>x.participantId).map(x=>x.participantId),G=C.positionAssignments.filter(x=>!R.includes(x.participantId));for(const x of G)if(x.bye){const z=jr(Am({tournamentRecord:o,drawDefinition:i,seedBlockInfo:s,structureId:l,matchUpsMap:c,event:p},x));if(z.error)return W({result:z,stack:_})}else{const z=vn(Am({automaticPlacement:!0,inContextDrawMatchUps:r,tournamentRecord:o,drawDefinition:i,seedBlockInfo:s,structureId:l,matchUpsMap:c,event:p},x));if(z.error)return W({result:z,stack:_,context:{assignment:x}})}return Am({},B)}function ete(t){const{structure:{structures:e}}=t,r=e.map(n=>n.positionAssignments.map(o=>o.drawPosition));return{drawPositionGroups:r,drawPositionChunks:[r]}}function tte({allDrawPositions:t,roundsToSeparate:e,matchUps:r}){const n=r.filter(p=>p.roundNumber===1).map(p=>p.drawPositions),o=n.flat().sort(Wt),i=Math.max(...o),s=t.filter(p=>p>i),a=o.length,l=le(a===2?1:2,a).filter(p=>p===Sp(p)),d=l.slice(0,e||l.length).reverse().map(p=>Rt(o,p));return s.length&&console.log({fedDrawPositions:s}),{drawPositionGroups:n,drawPositionChunks:d}}var rte=Object.defineProperty,Y$=Object.getOwnPropertySymbols,nte=Object.prototype.hasOwnProperty,ote=Object.prototype.propertyIsEnumerable,z$=(t,e,r)=>e in t?rte(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ite=(t,e)=>{for(var r in e||(e={}))nte.call(e,r)&&z$(t,r,e[r]);if(Y$)for(var r of Y$(e))ote.call(e,r)&&z$(t,r,e[r]);return t};function ste({provisionalPositioning:t,inContextDrawMatchUps:e,unseededByePositions:r,multipleStructures:n,tournamentRecord:o,candidatesCount:i,drawDefinition:s,seedBlockInfo:a,participants:c,matchUpsMap:l,structureId:u,structure:d,event:p}){var v,f;const m="positionUnseededParticipants";d||({structure:d}=Te({drawDefinition:s,structureId:u})),u||({structureId:u}=d);const{positionAssignments:g}=Et({structure:d}),{seedAssignments:h}=dn({provisionalPositioning:t,drawDefinition:s,structure:d,event:p}),_=h.map($=>$.participantId).filter(Boolean),{stage:I,stageSequence:P}=d,O=I===Ie?(f=(v=Vt({element:d,name:Tn}))==null?void 0:v.extension)==null?void 0:f.value:void 0,S=is({provisionalPositioning:t,drawDefinition:s,stageSequence:P,entryStatuses:os,structureId:u,roundTarget:O,stage:I}),E=S.filter($=>!_.includes($.participantId)).map($=>$.participantId),b=g.filter($=>!$.participantId&&!$.bye&&!$.qualifier).map($=>$.drawPosition);if(!n&&E.length>b.length)return W({result:{error:jh},context:{unseededParticipantsCount:E.length,unfilledDrawPositionsCount:b.length},stack:m});const{appliedPolicies:N}=at({tournamentRecord:o,drawDefinition:s,event:p});let{avoidance:w}=N||{};if(d.stage===st){const $=S.reduce((U,A)=>(U[A.groupingValue]||(U[A.groupingValue]=[]),U[A.groupingValue].push(A.participantId),U),{});Object.keys($).length&&(w||(w={policyName:"Playoff Avoidance"}),w.policyAttributes||(w.policyAttributes=[]),w.policyAttributes.push({groupings:$}))}return w&&c?Xee({provisionalPositioning:t,unseededParticipantIds:E,inContextDrawMatchUps:e,unseededByePositions:r,tournamentRecord:o,candidatesCount:i,drawDefinition:s,seedBlockInfo:a,participants:c,matchUpsMap:l,structureId:u,avoidance:w,entries:S}):ate({provisionalPositioning:t,unseededParticipantIds:E,inContextDrawMatchUps:e,unfilledDrawPositions:b,multipleStructures:n,tournamentRecord:o,drawDefinition:s,seedBlockInfo:a,structureId:u,matchUpsMap:l,event:p})}function ate({provisionalPositioning:t,unseededParticipantIds:e,inContextDrawMatchUps:r,unfilledDrawPositions:n,multipleStructures:o,tournamentRecord:i,drawDefinition:s,seedBlockInfo:a,matchUpsMap:c,structureId:l,event:u}){const d=or(n);for(const p of e){const v=d.pop();if(!o||v){const f=vn({automaticPlacement:!0,provisionalPositioning:t,inContextDrawMatchUps:r,tournamentRecord:i,drawDefinition:s,seedBlockInfo:a,participantId:p,drawPosition:v,matchUpsMap:c,structureId:l,event:u});if(f!=null&&f.error&&console.log("!!!!!",{result:f}),f!=null&&f.error)return W({result:f,stack:"randomUnseededDistribution"})}}return ite({},B)}var cte=Object.defineProperty,lte=Object.defineProperties,ute=Object.getOwnPropertyDescriptors,K$=Object.getOwnPropertySymbols,dte=Object.prototype.hasOwnProperty,pte=Object.prototype.propertyIsEnumerable,Q$=(t,e,r)=>e in t?cte(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fte=(t,e)=>{for(var r in e||(e={}))dte.call(e,r)&&Q$(t,r,e[r]);if(K$)for(var r of K$(e))pte.call(e,r)&&Q$(t,r,e[r]);return t},vte=(t,e)=>lte(t,ute(e));function mte({provisionalPositioning:t,drawDefinition:e,structure:r,event:n}){const{positionAssignments:o}=Et({structure:r}),{seedAssignments:i}=dn({provisionalPositioning:t,drawDefinition:e,structure:r,event:n}),s=Object.assign({},...i.filter(a=>a.participantId).map(a=>({[a.participantId]:a})));return o.map(a=>s[a.participantId]?vte(fte({},a),{seedNumber:s[a.participantId].seedNumber,seedValue:s[a.participantId].seedValue}):"").filter(Boolean)}function gte({orderedSortedFirstRoundSeededDrawPositions:t,validSeedBlocks:e,byesToPlace:r}){const n=[];e.forEach(i=>{if(r-n.length>i.drawPositions.length)n.push(...i.drawPositions);else{const a=Um(Rt(i.drawPositions,2));let c,l=t[n.length];for(;c=dl(a,l);)n.push(c),l=t[n.length]}});const o=n.map(i=>Array.isArray(i)?or(i):i).flat(1/0);return HR(r)&&e.map(s=>s.seedNumbers[0]).includes(r)?t:o}function dl(t,e){if(Array.isArray(t)&&t.length!==2)return t.pop();if(!Array.isArray(t[0]))return t.includes(e)?t.indexOf(e)?t.pop():t.shift():Math.round(Math.random())?t.pop():t.shift();const r=t[0].flat(1/0).length,n=t[1].flat(1/0).length;if(r===n){const o=t[0].flat(1/0).includes(e)?t[0]:t[1];return dl(e?o:t[Math.round(Math.random())],e)}return r<n?dl(t[1],e):dl(t[0],e)}function Um(t){const e=Math.floor(t.length/2);return t.length>2?[Um(t.slice(0,e)),Um(t.slice(e))]:t}function hte({provisionalPositioning:t,relevantMatchUps:e,appliedPolicies:r,drawDefinition:n,seedBlockInfo:o,byesToPlace:i,structure:s,event:a}){var c;o||(o=_s({provisionalPositioning:t,appliedPolicies:r,drawDefinition:n,structure:s,event:a}));let{validSeedBlocks:l,isFeedIn:u,isLucky:d,isContainer:p}=o;(c=r==null?void 0:r.seeding)!=null&&c.containerByesIgnoreSeeding&&(l=[]);const v=mte({provisionalPositioning:t,drawDefinition:n,structure:s,event:a}),f=Ve([].concat(...e.map(y=>y.drawPositions))),m=v.filter(y=>f.includes(y.drawPosition)),g=(y,S)=>Oa(y.seedValue)-Oa(S.seedValue),_=l.reduce((y,S)=>{const T=m.filter(E=>{var b;return(b=S.drawPositions)==null?void 0:b.includes(E.drawPosition)}).sort(g);return y.concat(...T)},[]).map(y=>y.drawPosition),I=gte({orderedSortedFirstRoundSeededDrawPositions:_,validSeedBlocks:l,byesToPlace:i}),P=J$({orderedSeedDrawPositions:_,relevantMatchUps:e}).slice(0,v.length),O=J$({orderedSeedDrawPositions:I,relevantMatchUps:e}).slice(0,v.length);return{strictSeedOrderByePositions:P,blockSeedOrderByePositions:O,positionedSeeds:v,isContainer:p,isFeedIn:u,isLucky:d}}function J$({orderedSeedDrawPositions:t,relevantMatchUps:e}){const n=e.map(i=>i.drawPositions).map(i=>i==null?void 0:i.sort((s,a)=>s-a)).filter(i=>(i==null?void 0:i[0])+1===(i==null?void 0:i[1]));return t.map(i=>n.find(s=>s==null?void 0:s.includes(i))).filter(Boolean).map(i=>i==null?void 0:i.reduce((s,a)=>t.includes(a)?s:a,void 0)).filter(Boolean)}function _te({provisionalPositioning:t,seedOrderByePositions:e,appliedPolicies:r,drawDefinition:n,seedLimit:o,structure:i,isFeedIn:s,isLucky:a,event:c}){var l,u;const d=(l=r==null?void 0:r.seeding)==null?void 0:l.seedingProfile,p=i.stage===Ie,{positionAssignments:v}=Et({structure:i}),f=v.filter(D=>D.participantId).map(D=>D.drawPosition),m={isCollectionMatchUp:!1},{matchUps:g,roundMatchUps:h}=ze({provisionalPositioning:t,matchUpFilters:m,structure:i}),_=(h==null?void 0:h[1])||[],I=i.structureType===tr?g:_,P=Ve([].concat(...I.map(D=>D.drawPositions))),O=Math.min(...P)-1,y=f.filter(D=>P.includes(D)),S=D=>{const F=Math.ceil(D.length/2),R=[D.slice(0,F),D.slice(F)],G=R.map(H=>[].concat(...H.flat(1/0)).length),x=Math.min(...G.flat(1/0)),z=Math.max(...G.flat(1/0)),j=G.indexOf(z),V=x!==z,L=or(R),[q,k]=!x||V?[R[j],R[1-j]]:[L[0],L[1]];return{greaterHalf:q,lesserHalf:k}},T=D=>{const{greaterHalf:F,lesserHalf:R}=S(D),{greaterHalf:G,lesserHalf:x}=S(F),j=or(G.flat(1/0)).pop(),V=G.flat().filter(q=>q!==j);return{newlyFilteredChunks:[...R,...x,V],drawPosition:j}},E=D=>!e.includes(D),b=D=>!y.includes(D),N=D=>{let R=Rt(D.sort(Wt),Math.ceil(D.length/4)).map(z=>z.filter(b));const G=[].concat(...R.flat(1/0)).length,x=[];for(let z=0;z<G;z++){const{newlyFilteredChunks:j,drawPosition:V}=T(R);x.push(V),R=j}return x},{validSeedBlocks:w}=_s({provisionalPositioning:t,allPositions:!0,appliedPolicies:r,drawDefinition:n,structure:i,event:c}),$=w.map(D=>{var F;return(F=D.drawPositions)==null?void 0:F.map(R=>R+O)});let U;if(s){const D=P.length,{seedBlocks:F}=qu({cluster:Yc(d)===Ef,participantsCount:D});U=F.map(G=>G.map(x=>x+O)).map(N).filter(G=>G.length)}else p?U=$.map(D=>D.filter(b)):U=$.map(N).filter(D=>D.length);const A=I.map(D=>D.drawPositions).map(D=>D==null?void 0:D.sort((F,R)=>F-R)).filter(D=>(D==null?void 0:D[0])+1===(D==null?void 0:D[1])),M=D=>A.reduce((F,R)=>R.includes(D)?R.reduce((G,x)=>x!==D?x:G,void 0):F,void 0);let C=U.map(D=>D.map(M)).flat(1/0).filter(b).filter(E).filter(Boolean);if(p&&!i.structures){const D=o%4,F=C.slice(0,D),R=(u=h[i.roundLimit])==null?void 0:u.length,G=Rt(C.slice(D),R).map(or).flat();C=F.concat(G)}return{unseededByePositions:C}}function Ite({provisionalPositioning:t,drawDefinition:e,matchUpsMap:r,structure:n,event:o}){var i;const s={isCollectionMatchUp:!1},{matchUps:a,roundMatchUps:c}=ze({afterRecoveryTimes:!1,provisionalPositioning:t,drawDefinition:e,matchUpFilters:s,matchUpsMap:r,structure:n,event:o}),l=(c==null?void 0:c[1])||[],u=(n==null?void 0:n.structureType)===tr,d=u?a:l,p=u?((i=n==null?void 0:n.structures)==null?void 0:i.length)||0:a.length,{structureId:v,stage:f,stageSequence:m}=n,g=is({entryStatuses:Wo,provisionalPositioning:t,drawDefinition:e,stageSequence:m,structureId:v,stage:f}),{qualifiersCount:h}=Ni({provisionalPositioning:t,drawDefinition:e,stageSequence:m,structureId:v,stage:f}),_=g.length+h,{positionAssignments:I,unassignedPositions:P}=Et({structure:n}),O=P.map(N=>N.drawPosition),y=I.filter(N=>N.bye).length,S=I.filter(N=>N.bye).map(N=>N.drawPosition),T=d.map(N=>N.drawPositions).filter(N=>N==null?void 0:N.reduce((w,$)=>!S.includes($)&&w,!0)).flat(1/0).filter(N=>O.includes(N));let b=I.length-_;return b>p&&n.stageSequence===1&&n.stage!==$t&&(b=p),{placedByes:y,byesCount:b,relevantMatchUps:d,placedByePositions:S,roundMatchUps:c,positionsToAvoidDoubleBye:T}}var Pte=Object.defineProperty,yte=Object.defineProperties,Ste=Object.getOwnPropertyDescriptors,Z$=Object.getOwnPropertySymbols,Ote=Object.prototype.hasOwnProperty,bte=Object.prototype.propertyIsEnumerable,X$=(t,e,r)=>e in t?Pte(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eN=(t,e)=>{for(var r in e||(e={}))Ote.call(e,r)&&X$(t,r,e[r]);if(Z$)for(var r of Z$(e))bte.call(e,r)&&X$(t,r,e[r]);return t},Tte=(t,e)=>yte(t,Ste(e));function tN({provisionalPositioning:t,tournamentRecord:e,appliedPolicies:r,drawDefinition:n,seedBlockInfo:o,matchUpsMap:i,structureId:s,structure:a,seedLimit:c,seedsOnly:l,event:u}){var d;a||({structure:a}=Te({drawDefinition:n,structureId:s})),s||({structureId:s}=a);const p=!(a.structures||a.stage===Ie),{byesCount:v,placedByes:f,relevantMatchUps:m}=Ite({provisionalPositioning:t,drawDefinition:n,matchUpsMap:i,structure:a,event:u}),g=v-f;if(g<=0)return eN({},B);const{strictSeedOrderByePositions:h,blockSeedOrderByePositions:_,isFeedIn:I,isLucky:P}=hte({provisionalPositioning:t,relevantMatchUps:m,appliedPolicies:r,drawDefinition:n,seedBlockInfo:o,byesToPlace:g,structure:a,event:u}),O=[tr,ou].includes(a.structureType)&&((d=r==null?void 0:r.seeding)==null?void 0:d.containerByesIgnoreSeeding),y=p&&(_!=null&&_.length)?_:h;let{unseededByePositions:S}=_te({provisionalPositioning:t,seedOrderByePositions:y,ignoreSeededByes:O,appliedPolicies:r,drawDefinition:n,seedLimit:c,structure:a,isFeedIn:I,isLucky:P,event:u});const T=w=>w%2,E=(w,$)=>(w||[]).every(U=>T(U)?$!==U+1:$!==U-1);let b=[].concat(...y);if(!l)for(;S.length;){const w=S.find($=>E(b,$));w?(b.push(w),S=S.filter($=>$!==w)):(b.push(...S),S=[])}O&&(b=or(b),Ft({ignoreSeededByes:O})&&console.log({byePositions:b}));const N=b.slice(0,g);for(const w of N){const $=jr({provisionalPositioning:t,tournamentRecord:e,drawDefinition:n,seedBlockInfo:o,drawPosition:w,matchUpsMap:i,structureId:s,structure:a,event:u});if($!=null&&$.error)return $}return Tte(eN({},B),{unseededByePositions:S,byeDrawPositions:N})}var Ete=Object.defineProperty,wte=Object.defineProperties,$te=Object.getOwnPropertyDescriptors,rN=Object.getOwnPropertySymbols,Nte=Object.prototype.hasOwnProperty,Ate=Object.prototype.propertyIsEnumerable,nN=(t,e,r)=>e in t?Ete(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ute=(t,e)=>{for(var r in e||(e={}))Nte.call(e,r)&&nN(t,r,e[r]);if(rN)for(var r of rN(e))Ate.call(e,r)&&nN(t,r,e[r]);return t},Cte=(t,e)=>wte(t,$te(e));function Mte(t){let{structure:e,structureId:r}=t;e||({structure:e}=Te(t)),r||({structureId:r}=e);let n="positionQualifiers";const o=[];if(e.stage===$t)return W({result:{error:No},stack:n});const{unplacedRoundQualifierCounts:i,positionAssignments:s,roundDrawPositions:a}=Dte(t);for(const c of Object.keys(i)){const l=s.filter(u=>a[c].includes(u.drawPosition)&&!u.participantId&&!u.qualifier&&!u.bye).map(u=>u.drawPosition);if(i[c]>l)return W({result:{error:WF},context:{unfilledDrawPositions:l},stack:n});le(0,i[c]).forEach(()=>{const u=ir(l);o.push(u),s.forEach(d=>{d.drawPosition===u&&(d.qualifier=!0,delete d.participantId,delete d.bye)})})}return Cte(Ute({},B),{qualifierDrawPositions:o})}function Dte({drawDefinition:t,structure:e,structureId:r}){e||({structure:e}=Te({drawDefinition:t,structureId:r})),r||({structureId:r}=e);const{positionAssignments:n}=Et({structure:e}),{stage:o,stageSequence:i}=e,{qualifiersCount:s,roundQualifiersCounts:a}=Ni({drawDefinition:t,stageSequence:i,structureId:r,stage:o}),c=Object.keys(a),{matchUps:l}=ze({structure:e}),{roundProfile:u}=pr({matchUps:l}),d=Object.assign({},...c.filter(g=>u[g]).map(g=>{var h;return{[g]:(h=u[g])==null?void 0:h.drawPositions.filter(Boolean)}})),p=n.filter(g=>g.qualifier).map(g=>g.drawPosition),v=s-p.length,f=p.length;return{unplacedRoundQualifierCounts:Object.assign({},...c.map(g=>{const h=n.filter(_=>{var I,P;return _.qualifier&&((P=(I=d[g])==null?void 0:I.drawPositions)==null?void 0:P.includes(_.drawPosition))}).map(_=>_.drawPosition);return{[g]:a[g]-h.length}})),unplacedQualifiersCount:v,placedQualifiersCount:f,roundQualifiersCounts:a,positionAssignments:n,roundDrawPositions:d,qualifiersCount:s}}var jte=Object.defineProperty,Rte=Object.defineProperties,Fte=Object.getOwnPropertyDescriptors,oN=Object.getOwnPropertySymbols,Lte=Object.prototype.hasOwnProperty,Vte=Object.prototype.propertyIsEnumerable,iN=(t,e,r)=>e in t?jte(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sN=(t,e)=>{for(var r in e||(e={}))Lte.call(e,r)&&iN(t,r,e[r]);if(oN)for(var r of oN(e))Vte.call(e,r)&&iN(t,r,e[r]);return t},aN=(t,e)=>Rte(t,Fte(e));function cN({provisionalPositioning:t,inContextDrawMatchUps:e,tournamentRecord:r,appliedPolicies:n,validSeedBlocks:o,drawDefinition:i,seedingProfile:s,seedBlockInfo:a,participants:c,groupsCount:l,structureId:u,matchUpsMap:d,structure:p,event:v}){let f=0;const m=[],g=[];if(p||({structure:p}=Te({drawDefinition:i,structureId:u})),u||({structureId:u}=p),n||(n=at({drawDefinition:i}).appliedPolicies),!o){const h=_s({provisionalPositioning:t,appliedPolicies:n,drawDefinition:i,structure:p,event:v});h.error&&g.push(h.error),o=h.validSeedBlocks}return l=l||o.length,le(0,l).forEach(()=>{if(f<l){const h=xte({provisionalPositioning:t,inContextDrawMatchUps:e,tournamentRecord:r,validSeedBlocks:o,drawDefinition:i,seedingProfile:s,seedBlockInfo:a,participants:c,structureId:u,matchUpsMap:d,event:v});h!=null&&h.success&&(f++,m.push(...h.seedPositions)),h.error&&g.push({seedPositionError:h.error})}}),g.length?{error:g}:aN(sN({},B),{seedPositions:m})}function xte({provisionalPositioning:t,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,seedingProfile:o,seedBlockInfo:i,participants:s,structureId:a,matchUpsMap:c,event:l}){const{unplacedSeedParticipantIds:u,unfilledPositions:d}=Ku({provisionalPositioning:t,randomize:!0,drawDefinition:n,seedBlockInfo:i,structureId:a,event:l}),{appliedPolicies:p}=at({drawDefinition:n}),{avoidance:v}=p||{};v&&s&&(u==null?void 0:u.length)>2;const f=[];for(const m of u){const g=d.pop();if(!g)return{error:Ya};f.push(g);const h=vn({automaticPlacement:!0,provisionalPositioning:t,inContextDrawMatchUps:e,tournamentRecord:r,drawDefinition:n,seedingProfile:o,participantId:m,seedBlockInfo:i,drawPosition:g,matchUpsMap:c,structureId:a,event:l});if(!h.success)return h}return aN(sN({},B),{seedPositions:f})}var Bte=Object.defineProperty,kte=Object.defineProperties,Gte=Object.getOwnPropertyDescriptors,lN=Object.getOwnPropertySymbols,Wte=Object.prototype.hasOwnProperty,Hte=Object.prototype.propertyIsEnumerable,uN=(t,e,r)=>e in t?Bte(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dN=(t,e)=>{for(var r in e||(e={}))Wte.call(e,r)&&uN(t,r,e[r]);if(lN)for(var r of lN(e))Hte.call(e,r)&&uN(t,r,e[r]);return t},qte=(t,e)=>kte(t,Gte(e));function pl({applyPositioning:t=!0,provisionalPositioning:e,inContextDrawMatchUps:r,multipleStructures:n,placeByes:o=!0,tournamentRecord:i,appliedPolicies:s,candidatesCount:a,drawDefinition:c,seedingProfile:l,participants:u,structureId:d,matchUpsMap:p,seedLimit:v,seedsOnly:f,drawType:m,event:g}){var h;const _=[];t||(VL(),c=ue(c,!1,!0));const I=A=>(t||Vp(),W({result:A,stack:"automatedPositioning"})),P=A=>(t||Vp(),A);let O=Te({drawDefinition:c,structureId:d});if(O.error)return I(O);const{structure:y}=O;s||(s=(h=at({drawDefinition:c,structure:y,event:g}))==null?void 0:h.appliedPolicies);const{qualifiersCount:S}=Ni({stageSequence:y.stageSequence,provisionalPositioning:e,stage:y.stage,drawDefinition:c,structureId:d}),T=os,E=is({stageSequence:y.stageSequence,provisionalPositioning:e,stage:y.stage,drawDefinition:c,entryStatuses:T,structureId:d});if(!(E!=null&&E.length)&&!S)return P(dN({},B));p=p||Kt({drawDefinition:c}),r||({matchUps:r}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:c,matchUpsMap:p}));let b=[];const N=_s({provisionalPositioning:e,appliedPolicies:s,drawDefinition:c,structure:y,event:g});if(N.error)return N;const{validSeedBlocks:w}=N;if(_.push({validSeedBlocks:w}),Yc(y.seedingProfile||l)===wf){let A=o&&tN({provisionalPositioning:e,tournamentRecord:i,appliedPolicies:s,drawDefinition:c,seedBlockInfo:N,matchUpsMap:p,structure:y,seedLimit:v,seedsOnly:f,event:g});if(A!=null&&A.error||(b=A.unseededByePositions,_.push({action:"positionByes",unseededByePositions:b}),A=cN({seedingProfile:y.seedingProfile||l,provisionalPositioning:e,inContextDrawMatchUps:r,tournamentRecord:i,appliedPolicies:s,validSeedBlocks:w,drawDefinition:c,seedBlockInfo:N,participants:u,matchUpsMap:p,structure:y,event:g}),A.error))return I(A);_.push({action:"positionSeedBlocks",seedPositions:A.seedPositions})}else{if(m!==hi){let M=cN({seedingProfile:y.seedingProfile||l,provisionalPositioning:e,inContextDrawMatchUps:r,tournamentRecord:i,appliedPolicies:s,validSeedBlocks:w,drawDefinition:c,seedBlockInfo:N,participants:u,matchUpsMap:p,structure:y,event:g});if(M.error)return I(M);_.push({action:"positionSeedBlocks",seedPositions:M.seedPositions})}const A=o&&tN({provisionalPositioning:e,inContextDrawMatchUps:r,tournamentRecord:i,appliedPolicies:s,drawDefinition:c,seedBlockInfo:N,matchUpsMap:p,structure:y,seedLimit:v,seedsOnly:f,event:g});if(A!=null&&A.error)return console.log("positionByes",{result:A}),I(A);b=A.unseededByePositions,_.push({action:"positionByes",byeDrawPositions:A.byeDrawPositions,unseededByePositions:b})}const $={};if(!f){let A=Mte({inContextDrawMatchUps:r,tournamentRecord:i,appliedPolicies:s,validSeedBlocks:w,drawDefinition:c,seedBlockInfo:N,participants:u,matchUpsMap:p,structure:y});if(A.error||(A.conflicts&&($.qualifierConflicts=A.conflicts),_.push({action:"positionQualifiers",qualifierDrawPositions:A.qualifierDrawPositions}),A=ste({provisionalPositioning:e,inContextDrawMatchUps:r,unseededByePositions:b,multipleStructures:n,tournamentRecord:i,appliedPolicies:s,validSeedBlocks:w,candidatesCount:a,drawDefinition:c,seedBlockInfo:N,participants:u,matchUpsMap:p,structure:y,event:g}),A.error))return I(A);A.conflicts&&($.unseededConflicts=A.conflicts),_.push({action:"positionUnseededParticipants"})}const{positionAssignments:U}=et({drawDefinition:c,structure:y});return Je({drawDefinition:c,structureIds:[d]}),t||Vp(),qte(dN({positionAssignments:U,conflicts:$},B),{positioningReport:_})}var Yte=Object.defineProperty,zte=Object.defineProperties,Kte=Object.getOwnPropertyDescriptors,pN=Object.getOwnPropertySymbols,Qte=Object.prototype.hasOwnProperty,Jte=Object.prototype.propertyIsEnumerable,fN=(t,e,r)=>e in t?Yte(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zte=(t,e)=>{for(var r in e||(e={}))Qte.call(e,r)&&fN(t,r,e[r]);if(pN)for(var r of pN(e))Jte.call(e,r)&&fN(t,r,e[r]);return t},Xte=(t,e)=>zte(t,Kte(e));function ere({applyPositioning:t=!0,tournamentRecord:e,drawDefinition:r,seedingProfile:n,structureId:o,placeByes:i,seedsOnly:s,event:a}){if(!a)return{error:Ir};if(!r)return{error:_n};const c=e==null?void 0:e.participants;return pl({tournamentRecord:e,applyPositioning:t,drawDefinition:r,seedingProfile:n,participants:c,structureId:o,placeByes:i,seedsOnly:s})}function Cd({applyPositioning:t=!0,provisionalPositioning:e,candidatesCount:r=1,tournamentRecord:n,drawDefinition:o,seedingProfile:i,structureId:s,placeByes:a,seedsOnly:c,event:l}){if(!l)return{error:Ir};if(!o)return{error:_n};if(!wi({drawDefinition:o,structureId:s})&&!e)return{error:ph};const{playoffStructures:d}=VO({drawDefinition:o,structureId:s}),p=[],v=n==null?void 0:n.participants;if(d)for(const f of d){const{structureId:m}=f,g=pl({structureId:m,provisionalPositioning:e,applyPositioning:t,candidatesCount:r,drawDefinition:o,seedingProfile:i,participants:v,placeByes:a,seedsOnly:c});if(g.error)return g;g.positionAssignments&&p.push({positionAssignments:g.positionAssignments,structureId:m})}return Xte(Zte({},B),{structurePositionAssignments:p})}var tre=Object.defineProperty,vN=Object.getOwnPropertySymbols,rre=Object.prototype.hasOwnProperty,nre=Object.prototype.propertyIsEnumerable,mN=(t,e,r)=>e in t?tre(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gN=(t,e)=>{for(var r in e||(e={}))rre.call(e,r)&&mN(t,r,e[r]);if(vN)for(var r of vN(e))nre.call(e,r)&&mN(t,r,e[r]);return t};function ore(t){var e,r,n;const o="generateAndPopulateRRplayoffStructures";if(!t.playoffGroups)return W({result:{error:Oe},info:"playoffGroups required",stack:o});const{sourceStructureId:i,requireSequential:s,drawDefinition:a,playoffGroups:c,groupCount:l,groupSize:u,event:d}=t,{structures:p=[],links:v=[],finishingPositionTargets:f,positionRangeMap:m,error:g}=I$(gN({requireSequential:s,sourceStructureId:i,playoffGroups:c,groupCount:l,groupSize:u},t));if(g)return{error:g};const h=f==null?void 0:f.map(({finishingPositions:b})=>b).flat().map(b=>m[b].finishingPositions).flat();a.structures.push(...p),a.links.push(...v);const{matchUps:_,matchUpsMap:I}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:a}),P=p.map(({structureId:b})=>b),O=_.filter(({structureId:b})=>P.includes(b)).map(Mt),y=(e=I==null?void 0:I.drawMatchUps)==null?void 0:e.filter(({matchUpId:b})=>O.includes(b));if(y.length){const b=(r=Xt({drawDefinition:a,event:d}))==null?void 0:r.tieFormat;b&&y.forEach(N=>{const{tieMatchUps:w}=$d({isMock:t.isMock,tieFormat:b});Object.assign(N,{tieMatchUps:w,matchUpType:Zr})})}const{positionAssignments:S}=et({structureId:i,drawDefinition:a}),T={};S.forEach(b=>{var N;const w=Or({element:b,name:jo}),$=(N=w==null?void 0:w.extension)==null?void 0:N.value,U=$==null?void 0:$.groupOrder;U&&(T[U]||(T[U]=[]),T[U].push(b.participantId))});const E=Cd({provisionalPositioning:t.provisionalPositioning,structureId:i,applyPositioning:!0,event:t.event,drawDefinition:a});return E.error&&((n=E.error)==null?void 0:n.code)!==ph.code?W({result:E,stack:o}):gN({structures:p,links:v,positionsPlayedOff:h,drawDefinition:a},B)}var ire=Object.defineProperty,sre=Object.defineProperties,are=Object.getOwnPropertyDescriptors,hN=Object.getOwnPropertySymbols,cre=Object.prototype.hasOwnProperty,lre=Object.prototype.propertyIsEnumerable,_N=(t,e,r)=>e in t?ire(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Cm=(t,e)=>{for(var r in e||(e={}))cre.call(e,r)&&_N(t,r,e[r]);if(hN)for(var r of hN(e))lre.call(e,r)&&_N(t,r,e[r]);return t},ure=(t,e)=>sre(t,are(e));function Mm(t){var e,r;const n="genPlayoffStructure";if(!t.drawDefinition)return W({result:{error:pe},stack:n});const o=cl(t);if(o.error)return W({result:o,stack:n});const{structureId:i,addNameBaseToAttributeName:s,playoffStructureNameBase:a,tournamentRecord:c,playoffAttributes:l,playoffPositions:u,exitProfileLimit:d,roundProfiles:p,roundNumbers:v,idPrefix:f,isMock:m,event:g,uuids:h}=t,_=ue(t.drawDefinition,!1,!0),{structure:I}=Te({structureId:i,drawDefinition:_});if(!I)return W({result:{error:Br}});if(I.structureType===tr||I.structures)return ore(ure(Cm(Cm({sourceStructureId:I.structureId},t),o),{drawDefinition:_}));const{playoffRoundsRanges:P,playoffRounds:O}=o,{playoffPositionsReturned:y,error:S,playoffSourceRounds:T,playoffRoundsRanges:E}=Em(t);if(S)return W({result:{error:S},stack:n});const b=(p==null?void 0:p.length)&&Object.assign({},...p),N=v||typeof p=="object"&&p.map(q=>Object.keys(q)).flat(),w=Array.isArray(N)&&N.map(q=>!isNaN(q)&&parseInt(q)).filter(Boolean);if(w){if(!Array.isArray(w))return W({result:{error:Z},context:{validRoundNumbers:w},stack:n});w.forEach(q=>{if(!(O!=null&&O.includes(q)))return W({result:{error:Z},context:{roundNumber:q},stack:n})})}u&&u.forEach(q=>{if(!y.includes(q))return W({result:{error:Z},context:{playoffPosition:q},stack:n})});const $=w||T,U=w?P:E,A=[],M=[];for(const q of $){const k=U==null?void 0:U.find(oe=>oe.roundNumber===q);if(!k)return W({result:{error:Z},context:{roundNumber:q},stack:n});const H=k.finishingPositions.length,Q=Math.min(...k.finishingPositions)-1,K=2,Y=(b==null?void 0:b[q])&&K+b[q]-1,J=Ca({exitProfile:`0-${q}`,addNameBaseToAttributeName:s,playoffStructureNameBase:a,finishingPositionOffset:Q,playoffAttributes:l,exitProfileLimit:d,stage:st,drawDefinition:_,roundOffset:0,sequenceLimit:Y,stageSequence:K,drawSize:H,idPrefix:f,isMock:m,uuids:h});if(J.error)return W({result:J,stack:n});const{structures:te,links:ne}=J;if(te!=null&&te.length&&A.push(...te),ne!=null&&ne.length&&M.push(...ne),J.structureId){const oe={linkType:qn,source:{structureId:i,roundNumber:q},target:{structureId:J.structureId,feedProfile:Cn,roundNumber:1}};M.push(oe)}}if(!A.length)return W({result:{error:Z},info:"No structures generated",stack:n});_.structures.push(...A),_.links.push(...M);const{matchUps:C,matchUpsMap:D}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:_}),F=A.map(({structureId:q})=>q),R=C.filter(({structureId:q})=>F.includes(q)).map(Mt),G=(e=D==null?void 0:D.drawMatchUps)==null?void 0:e.filter(({matchUpId:q})=>R.includes(q));if(G.length){const q=(r=Xt({drawDefinition:_,event:g}))==null?void 0:r.tieFormat;q&&G.forEach(k=>{const{tieMatchUps:H}=$d({tieFormat:q,isMock:m});Object.assign(k,{tieMatchUps:H,matchUpType:He})})}C.filter(q=>Ws({matchUp:q})&&q.structureId===i).forEach(q=>{const{matchUpId:k,score:H,winningSide:Q}=q,K=sr({inContextDrawMatchUps:C,drawDefinition:_,matchUpId:k,structure:I}),Y=d0({inContextDrawMatchUps:C,tournamentRecord:c,drawDefinition:_,matchUpsMap:D,winningSide:Q,targetData:K,matchUpId:k,structure:I,matchUp:q,score:H,event:g});Y.error&&console.log(Y.error)});const z=[],j=fa({inContextDrawMatchUps:C,drawDefinition:_,matchUpsMap:D}).goesToMap,{structure:V}=Te({drawDefinition:t.drawDefinition,structureId:i}),{matchUps:L}=ze({structure:V});return L.forEach(q=>{var k,H;const Q=j.loserMatchUpIds[q.matchUpId];if(Q&&q.loserMatchUpId!==Q){q.loserMatchUpId=Q;const Y={tournamentId:c==null?void 0:c.tournamentId,eventId:(k=t.event)==null?void 0:k.eventId,context:n,matchUp:q};z.push(Y)}const K=j.winnerMatchUpIds[q.matchUpId];if(K&&q.winnerMatchUpId!==K){q.winnerMatchUpId=K;const Y={tournamentId:c==null?void 0:c.tournamentId,eventId:(H=t.event)==null?void 0:H.eventId,context:n,matchUp:q};z.push(Y)}}),Cm({structures:A,matchUpModifications:z,links:M,drawDefinition:_},B)}var dre=Object.defineProperty,IN=Object.getOwnPropertySymbols,pre=Object.prototype.hasOwnProperty,fre=Object.prototype.propertyIsEnumerable,PN=(t,e,r)=>e in t?dre(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vre=(t,e)=>{for(var r in e||(e={}))pre.call(e,r)&&PN(t,r,e[r]);if(IN)for(var r of IN(e))fre.call(e,r)&&PN(t,r,e[r]);return t};function yN({drawDefinition:t,drawSize:e}){if(!t)return{error:pe};const r=ul({stage:Ct,stageSequence:1,drawDefinition:t,drawSize:e});return r.error?r:(Je({drawDefinition:t}),vre({},B))}var mre=Object.defineProperty,SN=Object.getOwnPropertySymbols,gre=Object.prototype.hasOwnProperty,hre=Object.prototype.propertyIsEnumerable,ON=(t,e,r)=>e in t?mre(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_re=(t,e)=>{for(var r in e||(e={}))gre.call(e,r)&&ON(t,r,e[r]);if(SN)for(var r of SN(e))hre.call(e,r)&&ON(t,r,e[r]);return t};function bN(t={}){var e,r,n,o,i;const{drawType:s=zn,attachConsolation:a=!0,applyPositioning:c=!0,tournamentRecord:l,staggeredEntry:u,automated:d,placeByes:p,isMock:v,event:f}=t;let{drawDefinition:m}=t;if(!m)return{error:pe};const g=(e=Qt({tournamentRecord:l,inContext:!0}))==null?void 0:e.tournamentParticipants,h=Ct,_=is({stageSequence:1,drawDefinition:m,stage:h}),I=[ln,bc,Io].includes(s)?_.length:Ds(_.length);if(!u&&s===Xs&&_.length<2||s===ln&&_.length<3)return{error:Tp};let{tieFormat:P,matchUpType:O}=t;if(P){const D=ur({tieFormat:P});if(D.error)return D}P=pn(P||((r=Xt({drawDefinition:m}))==null?void 0:r.tieFormat)),O=O||m.matchUpType||pt;const{structures:y}=Cr({stageSequence:1,drawDefinition:m,stage:h});if(y.length>1)return{error:Ri};if((o=(n=y==null?void 0:y[0])==null?void 0:n.matchUps)!=null&&o.length)return{error:Ri};const T=(i=y==null?void 0:y[0])==null?void 0:i.structureId;Object.assign(t,_e({structureName:t.structureName||Ct,structureId:T,matchUpType:O,tieFormat:P,drawSize:I,stage:h}));const E=w$(t);if(E.error)return E;const b=E.generators[s];if(!b)return{error:vh};const N=b==null?void 0:b();if(N.error)return N;let{structures:w,links:$}=N;const U=w.map(D=>ze({structure:D}).matchUps).flat();P&&U.forEach(D=>{const{tieMatchUps:F}=$d({tieFormat:P,isMock:v});Object.assign(D,{tieMatchUps:F,matchUpType:O})}),(!c||!a)&&(m=ue(m,!1,!0)),$.length&&m.links.push(...$);const A=w.map(({structureId:D})=>D),M=m.structures.map(({structureId:D})=>D);m.structures=m.structures.map(D=>A.includes(D.structureId)?w.find(({structureId:F})=>F===D.structureId):D);const C=w.filter(({structureId:D})=>!M.includes(D));return C.length&&m.structures.push(...C),d&&pl({seedingProfile:t.seedingProfile,participants:g,applyPositioning:c,tournamentRecord:l,drawDefinition:m,structureId:T,placeByes:p,event:f}),a&&Je({drawDefinition:m}),_re({links:$,structures:w},B)}var Ire=Object.defineProperty,Pre=Object.defineProperties,yre=Object.getOwnPropertyDescriptors,TN=Object.getOwnPropertySymbols,Sre=Object.prototype.hasOwnProperty,Ore=Object.prototype.propertyIsEnumerable,EN=(t,e,r)=>e in t?Ire(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bre=(t,e)=>{for(var r in e||(e={}))Sre.call(e,r)&&EN(t,r,e[r]);if(TN)for(var r of TN(e))Ore.call(e,r)&&EN(t,r,e[r]);return t},Tre=(t,e)=>Pre(t,yre(e));function Dm(t){var e,r,n;if(!t.drawDefinition)return{error:pe};const o="generateQualifyingStructure";let i=t.drawSize||yp(t.participantsCount);const{qualifyingRoundNumber:s,qualifyingPositions:a,targetStructureId:c,structureOptions:l,appliedPolicies:u,drawDefinition:d,structureName:p,structureId:v,roundTarget:f,drawType:m,idPrefix:g,isMock:h,uuids:_}=t;let I,P,O,y,S,T=0,E,b=1;if(!ut(i))return W({result:{error:El},stack:o});const N=Te({structureId:c,drawDefinition:d});if(N.error)return W({context:{targetStructureId:c},result:N,stack:o});const w=N.structure,$=w.matchUpType;if(w.stage===Ie)if(w.stageSequence>1)b=w.stageSequence-1;else{let D=c,F=2,R;for(;!R&&D;){w.stageSequence=F;const G=(r=(e=d.links.find(x=>x.source.structureId===D))==null?void 0:e.target)==null?void 0:r.structureId;if(D=G,F+=1,!G)R=!0;else{const x=Te({structureId:G,drawDefinition:d});if(x.error)return W({context:{targetTargetStructureId:G},result:x,stack:o});x.structure.stage!==Ie&&(R=!0)}}}const U=f?`${f}-`:"",A=`${b}`,M=p||(U||A?`${Ie} ${U}${A}`:Ie);if(m===ln){const{maxRoundNumber:D,structures:F,groupCount:R}=qc({structureName:p||M,structureId:v||(_==null?void 0:_.pop()),stage:Ie,structureOptions:l,appliedPolicies:u,stageSequence:b,matchUpType:$,roundTarget:f,idPrefix:g,drawSize:i,isMock:h,uuids:_});T=R,I=D,O=F[0],E=[1]}else({drawSize:i,matchUps:S,roundLimit:I,roundsCount:P}=Ln({qualifyingRoundNumber:s,qualifyingPositions:a,matchUpType:$,idPrefix:g,drawSize:i,isMock:h,uuids:_})),I||(I=P),O=kt({structureName:p||M,structureId:v||(_==null?void 0:_.pop()),qualifyingRoundNumber:I,stage:Ie,stageSequence:b,matchUpType:$,roundLimit:I,matchUps:S}),f&&tt({element:O,extension:{name:Tn,value:f}}),T=(n=S==null?void 0:S.filter(D=>D.roundNumber===I))==null?void 0:n.length;const C=m===ln?ho:_o;return{link:y}=Ua({sourceStructureId:O.structureId,sourceRoundNumber:I,targetStructureId:c,finishingPositions:E,linkType:C}),Tre(bre({qualifyingDrawPositionsCount:i,qualifiersCount:T},B),{structure:O,link:y})}var Ere=Object.defineProperty,wN=Object.getOwnPropertySymbols,wre=Object.prototype.hasOwnProperty,$re=Object.prototype.propertyIsEnumerable,$N=(t,e,r)=>e in t?Ere(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Nre=(t,e)=>{for(var r in e||(e={}))wre.call(e,r)&&$N(t,r,e[r]);if(wN)for(var r of wN(e))$re.call(e,r)&&$N(t,r,e[r]);return t};function jm({tournamentRecord:t,drawDefinition:e,structure:r,eventId:n,link:o}){var i;if(!e)return{error:pe};if(!r)return{error:Rs};if(!o)return{error:hh};const s=o.target.structureId,a=Te({drawDefinition:e,structureId:s});if(a.error)return W({stack:"attachQualifyingStructure",context:{targetStructureId:s},result:a});e.structures.push(r),e.links.push(o);const c=((i=ze({structure:r}))==null?void 0:i.matchUps)||[];return Pi({tournamentId:t==null?void 0:t.tournamentId,drawDefinition:e,matchUps:c,eventId:n}),Je({drawDefinition:e,structureIds:[r.structureId]}),Nre({},B)}var Are=Object.defineProperty,Ure=Object.defineProperties,Cre=Object.getOwnPropertyDescriptors,NN=Object.getOwnPropertySymbols,Mre=Object.prototype.hasOwnProperty,Dre=Object.prototype.propertyIsEnumerable,AN=(t,e,r)=>e in t?Are(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ma=(t,e)=>{for(var r in e||(e={}))Mre.call(e,r)&&AN(t,r,e[r]);if(NN)for(var r of NN(e))Dre.call(e,r)&&AN(t,r,e[r]);return t},Da=(t,e)=>Ure(t,Cre(e));function jre({matchUps:t,matchUpType:e}){var r;if(!t)return{error:Ao};let n=0,o=[],i=[];e&&(t=t.filter(U=>U.matchUpType===e));const s=Ve(t.map(({matchUpType:U})=>U));if(s.length>1)if(s.includes(He))t=t.filter(U=>U.matchUpType===He);else if(s.includes(pt))t=t.filter(U=>U.matchUpType===pt);else if(s.includes(it))t=t.filter(U=>U.matchUpType===it);else return{};if(!Array.isArray(t)||!t.length)return{};const a=(U,A)=>parseInt(U)-parseInt(A),c=Ve(t.map(U=>U.drawPositions).flat().filter(Boolean)).sort(a),u=le(1,Math.max(...c)+1).filter(U=>!c.includes(U)).sort(a),{roundMatchUps:d}=pr({matchUps:t}),p=d[1],v=d[2]||[],[f]=p||[{}],m=f.drawId,g=f.structureId,h=Math.max(...Object.keys(d)),_=((r=d[h])==null?void 0:r.length)||0,I=Math.ceil(Math.log(_)/Math.log(2)),P=le(1,I+1).map(U=>{const A=Math.pow(2,U-1),M=h+I-U+1;return le(1,A+1).map(C=>({drawId:m,structureId:g,matchUpId:We(),drawPositions:[],sides:[],roundNumber:M,roundPosition:C,finishingRound:U}))});I&&(t=t.concat(...P.flat()));const y=p.map(U=>U.drawPositions).flat(1/0),T=v.map(U=>U.drawPositions).flat(1/0).filter(U=>!y.includes(U)).sort(a),E=v.filter(U=>{var A;return(A=U.drawPositions)==null?void 0:A.reduce((M,C)=>T.includes(C)||M,void 0)}).map(U=>{var A,M;const C=(A=U.drawPositions)==null?void 0:A.reduce((R,G)=>T.includes(G)?G:R,void 0),D=(M=U.drawPositions)==null?void 0:M.indexOf(C),F=U.sides[D];return{[C]:F}});if(u!=null&&u.length&&(T==null?void 0:T.length)===(u==null?void 0:u.length)){const U=T.map((D,F)=>[D,u[F]].sort(a)),A=Object.assign({},...E),M=ue(p[0].finishingRound,!1,!0),C=ue(p[0].finishingPositionRange,!1,!0);i=U.map((D,F)=>{const R=Math.max(...D||[])/2;return{sides:D==null?void 0:D.map(x=>A[x]||{bye:!0,drawPosition:x}),drawId:m,structureId:g,roundPosition:R,drawPositions:D,roundNumber:1,finishingRound:M,matchUpId:We(),matchUpStatus:"BYE",sideNumber:F+1,finishingPositionRange:C}}),t=t.concat(...i)}const b=h+I;return le(1,b+1).forEach(U=>{const A=[],M=$({matchUps:t,roundNumber:U}),D=$({matchUps:t,roundNumber:U-1}).map(Rre).filter(Boolean),F=(M==null?void 0:M.length)===(o==null?void 0:o.length),R=(M==null?void 0:M.length)===(o==null?void 0:o.length)/2;U===1&&M.forEach(G=>{const x=G.drawPositions||[],{matchUpId:z,structureId:j}=G,V=[Da(Ma({},G.sides[0]),{drawPosition:x[0],matchUpId:z,structureId:j}),Da(Ma({},G.sides[1]),{drawPosition:x[1],matchUpId:z,structureId:j})],L=Da(Ma({},G),{children:V});A.push(L)}),F?(n++,M.forEach((G,x)=>{const z=G.drawPositions||[],{matchUpId:j,structureId:V}=G,L=z.filter(Boolean).reduce((Q,K)=>y.includes(K)?Q:K,void 0),q=G.sides.filter(Boolean).reduce((Q,K)=>K.participantId&&!D.includes(K.participantId)?K:Q,void 0),k=[Da(Ma({},q),{drawPosition:L,feedRoundNumber:n,sides:G.sides,matchUpId:j,structureId:V}),o[x]],H=Da(Ma({},G),{children:k});A.push(H)})):R&&M.forEach((G,x)=>{const z=[o[x*2],o[x*2+1]],j=Da(Ma({},G),{children:z});A.push(j)}),o=A}),{hierarchy:o[0],missingMatchUps:i,maxRound:h,finalRound:b,matchUps:t};function $({matchUps:U,roundNumber:A}){return U.filter(M=>M.roundNumber===A).sort((M,C)=>M.roundPosition-C.roundPosition)}}function Rre(t){if(t.matchUpStatus===qe)return t.sides.reduce((e,r)=>r.participantId||e,void 0);if(t.winningSide)return t.sides.reduce((e,r)=>r.sideNumber===t.winningSide?r.participantId:e,void 0)}function UN(t){var e,r;const{structure:n,link:o}=Dm(t),i=t.drawDefinition;return jm({tournamentId:(e=t.tournamentRecord)==null?void 0:e.tournamentId,eventId:((r=t.event)==null?void 0:r.eventId)||t.eventId,drawDefinition:i,structure:n,link:o})}var Fre=Object.defineProperty,Md=Object.getOwnPropertySymbols,CN=Object.prototype.hasOwnProperty,MN=Object.prototype.propertyIsEnumerable,DN=(t,e,r)=>e in t?Fre(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lre=(t,e)=>{for(var r in e||(e={}))CN.call(e,r)&&DN(t,r,e[r]);if(Md)for(var r of Md(e))MN.call(e,r)&&DN(t,r,e[r]);return t},Vre=(t,e)=>{var r={};for(var n in t)CN.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Md)for(var n of Md(t))e.indexOf(n)<0&&MN.call(t,n)&&(r[n]=t[n]);return r};function jN(t){return RN(t)}function RN({matchUpModifications:t,tournamentRecord:e,drawDefinition:r,structures:n,links:o=[],event:i}){if(!r)return{error:pe};if(!Array.isArray(n)||!Array.isArray(o))return{error:Z};const s="attachStructures",a=m=>{var g;return[m.source.structureId,m.source.roundNumber||((g=m.source.finishingPositions)==null?void 0:g.join("|")),m.target.roundNumber].join("|")},c=r.links.map(a);if(o.some(m=>{const g=a(m);return c.includes(g)}))return W({result:{error:lL},info:"playoff structure exists",stack:s});o.length&&r.links.push(...o);const u=n.map(({structureId:m})=>m),d=r.structures.map(({structureId:m})=>m);r.structures=r.structures.map(m=>u.includes(m.structureId)?n.find(({structureId:g})=>g===m.structureId):m);const p=n.filter(({structureId:m})=>!d.includes(m));p.length&&r.structures.push(...p),fa({drawDefinition:r});const v=n.map(m=>{var g;return((g=ze({structure:m}))==null?void 0:g.matchUps)||[]}).flat();Pi({tournamentId:e==null?void 0:e.tournamentId,eventId:i==null?void 0:i.eventId,drawDefinition:r,matchUps:v});const f=n.map(({structureId:m})=>m);if(Je({drawDefinition:r,structureIds:f}),t!=null&&t.length){const m={};t.forEach(h=>{var _;const I=(_=h.matchUp)==null?void 0:_.matchUpId;I&&(m[I]=h)});const g=h=>{h.matchUps.forEach(_=>{if(m[_.matchUpId]){const I=m[_.matchUpId].matchUp,{tieMatchUps:P}=I,O=Vre(I,["tieMatchUps"]);if(Object.assign(_,O),P!=null&&P.length){const y={};P.forEach(S=>m[S.matchUpId]=S),_.tieMatchUps.forEach(S=>Object.assign(S,y[S.matchUpId]))}m[_.matchUpId].matchUp=_,Qe(m[_.matchUpId])}})};r.structures.forEach(h=>{if(d.includes(h.structureId))if(h.structures)for(const _ of h.structures)g(_);else g(h)})}return Lre({},B)}function Dd(t){var e,r;const{structures:n,links:o,matchUpModifications:i,error:s}=Mm(t);if(s)return{error:s};const a=t.drawDefinition;return jN({tournamentId:(e=t.tournamentRecord)==null?void 0:e.tournamentId,eventId:((r=t.event)==null?void 0:r.eventId)||t.eventId,matchUpModifications:i,drawDefinition:a,structures:n,links:o})}var xre=Object.defineProperty,Bre=Object.defineProperties,kre=Object.getOwnPropertyDescriptors,FN=Object.getOwnPropertySymbols,Gre=Object.prototype.hasOwnProperty,Wre=Object.prototype.propertyIsEnumerable,LN=(t,e,r)=>e in t?xre(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,VN=(t,e)=>{for(var r in e||(e={}))Gre.call(e,r)&&LN(t,r,e[r]);if(FN)for(var r of FN(e))Wre.call(e,r)&&LN(t,r,e[r]);return t},Hre=(t,e)=>Bre(t,kre(e));function xN({tournamentRecord:t,matchUpIds:e=[],drawDefinition:r,structureId:n,event:o}){var i;if(typeof r!="object")return{error:pe};if(typeof n!="string")return{error:ar};if(!Array.isArray(e))return{error:Z};const s=(i=r.structures)==null?void 0:i.find(p=>p.structureId===n);if(!s)return{error:Br};const a=s==null?void 0:s.matchUps,c=a.find(p=>!!p.roundPosition);if(s.structures||c||s.finishingPosition===_i)return{error:Ri};const l=a.filter(({matchUpId:p})=>e.includes(p)),u=fu(l),d=l.map(({drawPositions:p})=>p).flat();if(d.length){s.positionAssignments=s.positionAssignments.filter(({drawPosition:f})=>!d.includes(f)).sort((f,m)=>f.drawPosition-m.drawPosition),s.matchUps=s.matchUps.filter(({matchUpId:f})=>!u.includes(f));const p=Object.assign({},...s.positionAssignments.map(({drawPosition:f},m)=>({[f]:m+1})));s.positionAssignments=s.positionAssignments.map(f=>Hre(VN({},f),{drawPosition:p[f.drawPosition]}));const v=f=>{var m;return f.drawPositions=((m=f.drawPositions)==null?void 0:m.map(g=>p[g]))||[]};s.matchUps.forEach(v),yi({tournamentId:t==null?void 0:t.tournamentId,matchUpIds:u,action:"deleteAdHocMatchUps",eventId:o==null?void 0:o.eventId,drawDefinition:r}),Je({structureIds:[n],eventId:o==null?void 0:o.eventId,drawDefinition:r})}return VN({},B)}var qre=Object.defineProperty,Yre=Object.defineProperties,zre=Object.getOwnPropertyDescriptors,BN=Object.getOwnPropertySymbols,Kre=Object.prototype.hasOwnProperty,Qre=Object.prototype.propertyIsEnumerable,kN=(t,e,r)=>e in t?qre(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Jre=(t,e)=>{for(var r in e||(e={}))Kre.call(e,r)&&kN(t,r,e[r]);if(BN)for(var r of BN(e))Qre.call(e,r)&&kN(t,r,e[r]);return t},Zre=(t,e)=>Yre(t,zre(e));function GN({drawDefinition:t,structureDetails:e}){if(!Li(e))return{error:Z};if(!t)return{error:pe};const r=Object.assign({},...e.map(o=>{if(!Li(o))return;const{structureId:i,structureName:s}=o||{};if(!(!i||!s))return{[i]:s}}).filter(Boolean));if(!Object.values(r).length)return{error:Oe};let n=0;for(const o of t.structures||[]){const i=r[o.structureId];i&&(o.structureName=i,n+=1)}return Zre(Jre({},B),{modificationsApplied:n})}var Xre=Object.defineProperty,ene=Object.defineProperties,tne=Object.getOwnPropertyDescriptors,WN=Object.getOwnPropertySymbols,rne=Object.prototype.hasOwnProperty,nne=Object.prototype.propertyIsEnumerable,HN=(t,e,r)=>e in t?Xre(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,one=(t,e)=>{for(var r in e||(e={}))rne.call(e,r)&&HN(t,r,e[r]);if(WN)for(var r of WN(e))nne.call(e,r)&&HN(t,r,e[r]);return t},ine=(t,e)=>ene(t,tne(e));function qN({tournamentRecord:t,drawDefinition:e,structureId:r,event:n}){var o;if(typeof r!="string")return{error:Z};if(!e)return{error:pe};if(!r)return{error:ar};const i=e.structures||[],s=i.find(({stage:m,stageSequence:g})=>m===de&&g===1),a=r===s.structureId,c=i.find(({stage:m})=>m===Ie);if(a&&!c)return{error:rF};const l=[],u=[r],d=m=>{var g;return(g=e.links)==null?void 0:g.map(h=>h.source.structureId===m&&h.target.structureId!==s.structureId&&h.target.structureId).filter(Boolean)},p=i.map(({structureId:m})=>m),v=Object.assign({},...p.map(m=>({[m]:d(m)})));for(;u.length;){const m=u.pop(),{structure:g}=Te({structureId:m,drawDefinition:e}),{matchUps:h}=ze({structure:g}),_=fu(h);l.push(..._),(!a||m!==r)&&(e.links=((o=e.links)==null?void 0:o.filter(P=>P.source.structureId!==m&&P.target.structureId!==m))||[],e.structures=i.filter(P=>P.structureId!==m));const I=v[m];I!=null&&I.length&&u.push(...I)}const{matchUps:f}=Nt({drawDefinition:e});return f.forEach(m=>{l.includes(m.winnerMatchUpId)&&delete m.winnerMatchUpId,l.includes(m.loserMatchUpId)&&delete m.loserMatchUpId}),a&&(s.positionAssignments=[],s.seedAssignments=[],s.matchUps=[],s.extensions&&(s.extensions=[])),yi({tournamentId:t==null?void 0:t.tournamentId,matchUpIds:l,action:"removeStructure",eventId:n==null?void 0:n.eventId,drawDefinition:e}),Je({drawDefinition:e,eventId:n==null?void 0:n.eventId}),ine(one({},B),{removedMatchUpIds:l})}var sne=Object.defineProperty,YN=Object.getOwnPropertySymbols,ane=Object.prototype.hasOwnProperty,cne=Object.prototype.propertyIsEnumerable,zN=(t,e,r)=>e in t?sne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,KN=(t,e)=>{for(var r in e||(e={}))ane.call(e,r)&&zN(t,r,e[r]);if(YN)for(var r of YN(e))cne.call(e,r)&&zN(t,r,e[r]);return t};function Rm({participantIdPairings:t,addToStructure:e=!0,tournamentRecord:r,matchUpIds:n=[],drawDefinition:o,matchUpsCount:i,roundNumber:s,structureId:a,newRound:c}){var l,u,d,p;if(typeof o!="object")return{error:pe};if(!a&&((l=o.structures)==null?void 0:l.length)===1&&(a=(d=(u=o.structures)==null?void 0:u[0])==null?void 0:d.structureId),typeof a!="string")return{error:ar};if(t&&!Array.isArray(t)||i&&!ut(i)||n&&!Array.isArray(n)||!t&&!i)return{error:Z,info:"matchUpsCount or pairings error"};const v=(p=o==null?void 0:o.structures)==null?void 0:p.find(I=>I.structureId===a);let f;const g=(v==null?void 0:v.matchUps).reduce((I,P)=>(P.roundPosition&&(f=!0),P.roundNumber>I?P.roundNumber:I),0);if(v.structures||f||v.finishingPosition===_i)return{error:Ri};if(s&&s-1>g)return{error:Z,info:"roundNumber error"};const h=s||(c?g+1:g||1);t=t||le(0,i).map(()=>({participantIds:[]}));const _=t.map(I=>{const O=((I==null?void 0:I.participantIds)||[]).concat([void 0,void 0]).slice(0,2).map((y,S)=>_e({sideNumber:S+1,participantId:y}));return{matchUpId:n.pop()||We(),roundNumber:h,matchUpStatus:vt,sides:O}});if(e){const I=Fm({tournamentRecord:r,drawDefinition:o,structureId:a,matchUps:_});if(I.error)return I}return KN({matchUpsCount:_.length,matchUps:_},B)}function Fm({tournamentRecord:t,drawDefinition:e,structureId:r,matchUps:n}){var o,i,s,a,c,l;if(typeof e!="object")return{error:pe};if(!r&&((o=e.structures)==null?void 0:o.length)===1&&(r=(s=(i=e.structures)==null?void 0:i[0])==null?void 0:s.structureId),typeof r!="string")return{error:ar};if(!Array.isArray(n))return{error:Z,info:zt("matchUps")};const u=(a=e.structures)==null?void 0:a.find(m=>m.structureId===r);if(!u)return{error:Br};const p=(u==null?void 0:u.matchUps).find(m=>!!m.roundPosition);if(u.structures||p||u.finishingPosition===_i)return{error:Ri};if(u.structures||p||u.finishingPosition===_i)return{error:Ri};const v=((l=(c=Bt({tournamentRecord:t,inContext:!1}))==null?void 0:c.matchUps)==null?void 0:l.map(Mt))||[],f=n.map(Mt);return Gt(v,f)?{error:cL,info:"One or more matchUpIds already present in tournamentRecord"}:(u.matchUps.push(...n),Pi({tournamentId:t==null?void 0:t.tournamentId,drawDefinition:e,matchUps:n}),Je({drawDefinition:e,structureIds:[r]}),KN({},B))}const lne={generateAndPopulatePlayoffStructures:Mm,attachPlayoffStructures:jN,addPlayoffStructures:Dd,renameStructures:GN,generateQualifyingStructure:Dm,attachQualifyingStructure:jm,addQualifyingStructure:UN,getAvailablePlayoffRounds:cl,getAvailablePlayoffProfiles:cl,getSourceRounds:Em,getDrawStructures:Cr,getPositionsPlayedOff:Td,getQualifiersCount:Ni,removeStructure:qN,generateAdHocMatchUps:Rm,deleteAdHocMatchUps:xN,addAdHocMatchUps:Fm,addVoluntaryConsolationStage:yN,addVoluntaryConsolationStructure:Om,generateVoluntaryConsolation:bN,buildDrawHierarchy:jre,generateDrawTypeAndModifyDrawDefinition:Nm,generateDrawStructuresAndLinks:wm};function Lm({participantCount:t}){if(!t)return{error:Z};const e=Ds(t);return e?{drawSize:e}:W({result:{error:Z},stack:"getEliminationDrawSize",context:{participantCount:t}})}function Vm({requireParticipantCount:t=!0,drawSizeProgression:e=!1,policyDefinitions:r,participantCount:n,tournamentRecord:o,drawDefinition:i,drawSize:s,event:a}={}){const c="getSeedsCount";if(!r){const m=Hi({tournamentRecord:o,drawDefinition:i,event:a});if(m.error)return W({result:m,stack:c});r=m.policyDefinitions}const l=ut(n);if(n&&!l)return W({result:{error:Z},context:{participantCount:n},stack:c});if(t&&!l)return W({result:{error:FF},stack:c});if(isNaN(s))if(n)({drawSize:s}=Lm({participantCount:n}));else return W({result:{error:El},stack:c});if((t&&n||s)>s)return{error:Ch};const d=r[qs];if(!d)return{error:bF};const p=d.seedsCountThresholds;return p?(d.drawSizeProgression!==void 0&&(e=d.drawSizeProgression),{seedsCount:p.filter(m=>e?m.drawSize<=s:s===m.drawSize).reduce((m,g)=>n>=g.minimumParticipantCount?g.seedsCount:m,0)}):{error:lF}}var une=Object.defineProperty,dne=Object.defineProperties,pne=Object.getOwnPropertyDescriptors,QN=Object.getOwnPropertySymbols,fne=Object.prototype.hasOwnProperty,vne=Object.prototype.propertyIsEnumerable,JN=(t,e,r)=>e in t?une(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mne=(t,e)=>{for(var r in e||(e={}))fne.call(e,r)&&JN(t,r,e[r]);if(QN)for(var r of QN(e))vne.call(e,r)&&JN(t,r,e[r]);return t},gne=(t,e)=>dne(t,pne(e));function ZN({requireParticipantCount:t=!0,enforcePolicyLimits:e=!0,drawSizeProgression:r,participantCount:n,appliedPolicies:o,drawDefinition:i,seedingProfile:s,structureId:a,seedsCount:c}){var l,u,d,p,v;const f=Te({drawDefinition:i,structureId:a});if(f.error)return f;const m=f.structure,{positionAssignments:g}=Et({structure:m}),h=g.length;if(c>h)return{error:cF};const _=(l=m.structures)==null?void 0:l.length,I=(p=(d=(u=m.structures)==null?void 0:u[0])==null?void 0:d.matchUps)==null?void 0:p.reduce((S,{roundNumber:T})=>Math.max(T,S),0),P=ut(s==null?void 0:s.groupSeedingThreshold)&&s.groupSeedingThreshold,O=(v=Yu({roundRobinGroupsCount:_,roundsCount:I,drawSize:h}))==null?void 0:v.seedGroups,{seedsCount:y}=Vm({policyDefinitions:o,requireParticipantCount:t,drawSizeProgression:r,participantCount:n,drawSize:h});return o!=null&&o[qs]&&c>y&&e&&y&&(c=y),m.seedLimit=c,m.seedAssignments=le(1,c+1).map(S=>{const T=O==null?void 0:O.find(N=>N.includes(S)),E=T&&Math.min(...T),b=P&&S>=P?E:S;return{participantId:void 0,seedNumber:S,seedValue:b}}),Je({drawDefinition:i,structureIds:[a]}),gne(mne({},B),{seedLimit:c})}function hne({positionAssignments:t,participantFactors:e}){if(!e||!t)return{error:Oe};let r=ue(e,!1,!0);const n=t.map(({drawPosition:f})=>f),o=t.filter(f=>!f.participantId&&!f.bye&&!f.qualifier).map(Dk);let i,s=!0;for(;s;)({drawPositionResolutions:i,remainingPreferences:s,participantPreferences:r}=_ne({participantPreferences:r,drawPositionResolutions:i}));const a=Object.keys(i).map(f=>parseInt(f));let c=o.filter(f=>!a.includes(f)),l=Object.keys(r);const d=le(1,((f,m)=>Math.log(m)/Math.log(f))(2,(n==null?void 0:n.length)||0)+1).map(f=>Math.pow(2,f)),p={};for(const f of d){const m=Rt(n,f).filter(_=>Gt(_,c)),g={};if(l.forEach(_=>{m.forEach(I=>{const P=I.join("|");Gt(I,e[_].preferences)&&(g[P]||(g[P]=[]),g[P].push(_))})}),or(Object.keys(g)).forEach(_=>{const I=g[_].filter(P=>l.includes(P));for(;I.length;){const P=ir(I),O=_.split("|").map(y=>parseInt(y)).filter(y=>c.includes(parseInt(y)));if(O.length){const y=ir(O);c=c.filter(T=>T!==y),l=l.filter(T=>T!==P),i[y]=P;const S=_.split("|").length;p[S]||(p[S]=0),p[S]+=1}}}),!c.length)break}const v={chunkResolution:p};return l.length&&(l.forEach(f=>{const m=ir(c);m&&(i[m]=f)}),v.randomAssignment=l.length),{drawPositionResolutions:i,report:v}}function _ne({participantPreferences:t,drawPositionResolutions:e={}}){const r=Object.keys(t).reduce((s,a)=>{const l=t[a].preferences[0];return l&&(s[l]||(s[l]=[]),s[l].push(a)),s},{}),n=Math.min(...Object.values(r).filter(s=>s.length).map(s=>s.length)),o=Object.keys(r).filter(s=>r[s].length&&n&&r[s].length===n);o.forEach(s=>{const a=r[s],c=ir(a);e[s]=c,delete t[c]});let i;return Object.values(t).forEach(s=>{s.preferences=s.preferences.filter(a=>{const c=!o.includes(a.toString());return c&&(i=!0),c})}),{drawPositionResolutions:e,remainingPreferences:i,participantPreferences:t}}var Ine=Object.defineProperty,Pne=Object.defineProperties,yne=Object.getOwnPropertyDescriptors,XN=Object.getOwnPropertySymbols,Sne=Object.prototype.hasOwnProperty,One=Object.prototype.propertyIsEnumerable,eA=(t,e,r)=>e in t?Ine(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bne=(t,e)=>{for(var r in e||(e={}))Sne.call(e,r)&&eA(t,r,e[r]);if(XN)for(var r of XN(e))One.call(e,r)&&eA(t,r,e[r]);return t},Tne=(t,e)=>Pne(t,yne(e));function xm(t){const{participantIdAttributeName:e="participantId",isQualifierPosition:r,positionActionName:n,tournamentRecord:o,drawDefinition:i,participantId:s,drawPosition:a,structureId:c,event:l}=t,u="positionParticipantAction";if(!i)return{error:pe};let{inContextDrawMatchUps:d,matchUpsMap:p}=t;p||(p=Kt({drawDefinition:i}),Object.assign(t,{matchUpsMap:p})),d||({matchUps:d}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:i,matchUpsMap:p}),Object.assign(t,{inContextDrawMatchUps:d}));const{positionAssignments:v}=et({drawDefinition:i,structureId:c}),f=v.find(_=>_.drawPosition===a);if(f!=null&&f.participantId){const _=f.participantId;let I=vn({inContextDrawMatchUps:d,tournamentRecord:o,drawDefinition:i,participantId:s,drawPosition:a,structureId:c,matchUpsMap:p,event:l});return I.success?h({removedParticipantId:_}):W({result:I,stack:u})}let m=Ia({inContextDrawMatchUps:d,tournamentRecord:o,drawDefinition:i,drawPosition:a,structureId:c,matchUpsMap:p,event:l});if(m.error)return W({result:m,stack:u});const g=m.participantId;if(m=vn({inContextDrawMatchUps:d,isQualifierPosition:r,tournamentRecord:o,drawDefinition:i,participantId:s,drawPosition:a,structureId:c,matchUpsMap:p,event:l}),!m.success)return W({result:m,stack:u});return h({removedParticipantId:g});function h({removedParticipantId:_}){const{structure:I}=Te({drawDefinition:i,structureId:c});Hu({drawPositions:[a],structure:I});const P={[e]:s,name:n,drawPosition:a,structureId:c};return Wc({drawDefinition:i,positionAction:P}),W({result:Tne(bne({},B),{context:{removedParticipantId:_},stack:u})})}}function tA({alternateParticipantId:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,structureId:o}){return xm({positionActionName:"alternateDrawPositionAssignment",participantIdAttributeName:"alternateParticipantid",participantId:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,structureId:o})}var Ene=Object.defineProperty,rA=Object.getOwnPropertySymbols,wne=Object.prototype.hasOwnProperty,$ne=Object.prototype.propertyIsEnumerable,nA=(t,e,r)=>e in t?Ene(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Nne=(t,e)=>{for(var r in e||(e={}))wne.call(e,r)&&nA(t,r,e[r]);if(rA)for(var r of rA(e))$ne.call(e,r)&&nA(t,r,e[r]);return t};function oA({structurePositionAssignments:t,provisionalPositioning:e,tournamentRecord:r,drawDefinition:n,event:o}){var i;if(!n)return{error:pe};if(!Array.isArray(t))return{error:Z};const s="setPositionAssignments";for(const c of t){const{structureId:l,positionAssignments:u}=c;if(!u)continue;const d=Te({drawDefinition:n,structureId:l});if(d.error)return d;const p=d.structure;if(!p)return{error:Br};if(p.structures)return{error:Ri,info:"cannot be Round Robin group container"};const v=(i=p.positionAssignments)==null?void 0:i.map(({drawPosition:h})=>h),f=u==null?void 0:u.map(({drawPosition:h})=>h);if(jt(v,f).length!==v.length)return W({result:{error:Z},info:"drawPositions do not match",stack:s});const m=Kt({drawDefinition:n}),{matchUps:g}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:n,matchUpsMap:m});for(const h of u||[]){const{drawPosition:_,participantId:I,bye:P,qualifier:O}=h;if(P){const y=jr({tournamentRecord:r,drawDefinition:n,drawPosition:_,matchUpsMap:m,structureId:l,structure:p,event:o});if(y!=null&&y.error)return y}else if(O)u.forEach(y=>{y.drawPosition===_&&(y.qualifier=!0,delete y.participantId,delete y.bye)});else if(I){const y=vn({provisionalPositioning:e,automaticPlacement:!0,inContextDrawMatchUps:g,tournamentRecord:r,drawDefinition:n,participantId:I,drawPosition:_,matchUpsMap:m,structureId:l,event:o});if(y!=null&&y.error)return y}}Ho({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:n,source:s,structure:p,event:o})}const a=t.map(({structureId:c})=>c);return Je({eventId:o==null?void 0:o.eventId,tournamentRecord:r,drawDefinition:n,structureIds:a}),Nne({},B)}function jd({drawDefinition:t,stages:e}){return((t==null?void 0:t.structures)||[]).filter(n=>!(e!=null&&e.length)||e.includes(n.stage)).map(n=>{const{positionAssignments:o}=et({structure:n});return Kn(o)}).flat()}function zr({entries:t=[]}={}){const e=t.filter(Boolean).reduce((n,o)=>{const{entryStage:i,entryStatus:s}=o,a=`_${i||de}${s||""}`;return n[a]||(n[a]=[]),n[a].push(o),n},{}),r=n=>isNaN(n)?1/0:n;return Object.keys(e).map(n=>e[n].sort((o,i)=>r(o.entryPosition)-r(i.entryPosition)).map((o,i)=>{const s=i+1;return Object.assign(o,{entryPosition:s})})).flat()}function Ai(t){return[ns,qr].includes(t)}var Ane=Object.defineProperty,iA=Object.getOwnPropertySymbols,Une=Object.prototype.hasOwnProperty,Cne=Object.prototype.propertyIsEnumerable,sA=(t,e,r)=>e in t?Ane(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Bm=(t,e)=>{for(var r in e||(e={}))Une.call(e,r)&&sA(t,r,e[r]);if(iA)for(var r of iA(e))Cne.call(e,r)&&sA(t,r,e[r]);return t};function km({autoEntryPositions:t=!0,ignoreAssignment:e,tournamentRecord:r,drawDefinition:n,participantIds:o,entryStatus:i,entryStage:s,extension:a,eventSync:c,drawId:l,stage:u,event:d}){var p,v,f,m,g,h,_,I,P,O,y,S;if(!o||!Array.isArray(o))return{error:co,method:"modifyEntriesStatus",participantIds:o};if(!n&&!d)return{error:Le};if(i&&!$k.includes(i))return{error:jp};if(s&&!Tf.includes(s))return{error:No};const T="modifyEntriesStatus",E=[];if(!i&&!a)return W({result:{error:Oe},info:"Missing entryStatus",stack:T});if(a&&!on({extension:a,rquiredAttributes:["name"]}))return W({result:{error:Z},info:"Invalid extension",context:{extension:a},stack:T});const b=[];(p=d.drawDefinitions)==null||p.forEach(x=>{const z=jd({stages:u&&[u],drawDefinition:x});b.push(...z)});const N=(r==null?void 0:r.participants)||[];if(!o.every(x=>{const{participantType:z}=vo({tournamentParticipants:N,participantId:x});return!([we,Ye].includes(z)&&Ai(i))&&!(z===Me&&[br,Nn].includes(d.eventType)&&[un,...Mf].includes(i))}))return{error:jp};const{flightProfile:$}=It({event:d}),U=(v=$==null?void 0:$.flights)==null?void 0:v.find(x=>x.drawId===l),A=(x=[])=>{const z=x.filter(L=>!u||!L.entryStage||u===L.entryStage).filter(({participantId:L})=>o.includes(L)),j=L=>b.includes(L.participantId)&&!(Mf.includes(L.entryStatus)&&Mf.includes(i));return z.every(L=>j(L)&&!e?!1:(i&&(L.entryStatus=i,delete L.entryPosition),s&&(L.entryStage=s,delete L.entryPosition),a&&(a.value?tt({element:L,extension:a}):sn({element:L,name:a.name})),!0))?Bm({},B):{error:Vs}},M=({flight:x,drawDefinition:z})=>{d.entries=zr({entries:d.entries||[]}),x&&(x.drawEntries=zr({entries:x.drawEntries})),z&&(z.entries=zr({entries:z.entries}))},C=({flight:x,drawDefinition:z})=>{const j="updateDrawEntries";if(x){const V=A(x.drawEntries);if(V.error)return W({result:V,stack:j})}if(z){const V=A(z.entries);if(V.error)return W({result:V,stack:j});E.includes(z.drawId)||E.push(z.drawId)}return Bm({},B)},D=((f=d.entries)==null?void 0:f.find(({entryPosition:x})=>!isNaN(x)))||((m=U==null?void 0:U.drawEntries)==null?void 0:m.find(({entryPosition:x})=>!isNaN(x)))||((g=n==null?void 0:n.entries)==null?void 0:g.find(({entryPosition:x})=>!isNaN(x)));if(t&&!D&&M({flight:U,drawDefinition:n}),U||n){const x=C({flight:U,drawDefinition:n});if(x.error)return W({result:x,stack:T})}const F=((h=d.drawDefinitions)==null?void 0:h.map(({drawId:x})=>x))||[],R=((_=$==null?void 0:$.flights)==null?void 0:_.filter(x=>!F.includes(x.drawId)))||[];for(const x of R){const z=C({flight:x});if(z.error)return W({result:z,stack:T})}const G=((I=$==null?void 0:$.flights)==null?void 0:I.length)===1&&((P=d.drawDefinitions)==null?void 0:P.length)<=((O=$==null?void 0:$.flights)==null?void 0:O.length);if(!U&&!n&&wk.includes(i))return{error:GF};if(!U&&!n||i===Go||c&&G){const x=A(d.entries);if(x.error)return W({result:x,stack:T});let z;if(i===Go&&((y=$==null?void 0:$.flights)==null||y.every(j=>{const V=A(j.drawEntries);return V.error?(z=V.error,!1):(j.drawEntries=j.drawEntries.filter(({participantId:L})=>!o.includes(L)),!0)}),(S=d.drawDefinitions)==null||S.every(j=>{var V;const L=A(j.entries);return L.error?(z=L.error,!1):(j.entries=(V=j.entries)==null?void 0:V.filter(({participantId:q})=>!o.includes(q)),!0)})),z)return W({result:{error:z},stack:T})}t&&M({flight:U,drawDefinition:n});for(const x of d.drawDefinitions||[])E.length&&!E.includes(x.drawId)||Je({tournamentId:r.tournamentId,eventId:d.eventId,drawDefinition:x});return Bm({},B)}function aA({stage:t,drawDefinition:e}){return!!(t===Ct||Cc({stage:t,drawDefinition:e})&&ll({stage:t,drawDefinition:e}))}var Mne=Object.defineProperty,cA=Object.getOwnPropertySymbols,Dne=Object.prototype.hasOwnProperty,jne=Object.prototype.propertyIsEnumerable,lA=(t,e,r)=>e in t?Mne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rne=(t,e)=>{for(var r in e||(e={}))Dne.call(e,r)&&lA(t,r,e[r]);if(cA)for(var r of cA(e))jne.call(e,r)&&lA(t,r,e[r]);return t};function uA({entryStatus:t=Mr,drawDefinition:e,stageSequence:r,stage:n}){if(t===un)return Nk({stage:n,drawDefinition:e})?Object.assign({positionsAvailable:1/0},B):{error:kF};const o=dee({drawDefinition:e,stageSequence:r,stage:n}),i=Ak({drawDefinition:e,stageSequence:r,stage:n}),s=du({entryStatus:oa,drawDefinition:e,stageSequence:r,stage:n}),a=du({entryStatus:Mr,drawDefinition:e,stageSequence:r,stage:n}),c=s+a,l=c>=o,u=o-c;return n!==Ct&&l?{error:Dh}:t===oa?s<i?Rne({},B):{error:Dh}:Object.assign({positionsAvailable:u},B)}var Fne=Object.defineProperty,Lne=Object.defineProperties,Vne=Object.getOwnPropertyDescriptors,dA=Object.getOwnPropertySymbols,xne=Object.prototype.hasOwnProperty,Bne=Object.prototype.propertyIsEnumerable,pA=(t,e,r)=>e in t?Fne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rd=(t,e)=>{for(var r in e||(e={}))xne.call(e,r)&&pA(t,r,e[r]);if(dA)for(var r of dA(e))Bne.call(e,r)&&pA(t,r,e[r]);return t},kne=(t,e)=>Lne(t,Vne(e));function Gm({entryStatus:t=Mr,entryStageSequence:e,entryStage:r=de,ignoreStageSpace:n,drawDefinition:o,entryPosition:i,participantId:s,participant:a,roundTarget:c,extensions:l,extension:u}){const d="addDrawEntry";if(!o)return{error:pe};if(!r)return{error:Ih};if(!aA({stage:r,drawDefinition:o}))return W({result:{error:No},stack:d});const p=uA({stageSequence:e,stage:r,drawDefinition:o,entryStatus:t});if(!n&&!p.success)return{error:p.error};if(u&&!on({extension:u}))return W({result:{error:Z},info:"Invalid extension",context:{extension:u},stack:d});if(s=s||(a==null?void 0:a.participantId),!s)return W({result:{error:yt},stack:d});const v=t===ko&&Is({participantId:s,drawDefinition:o,entryStatus:t}),f=r===Ct&&Is({participantId:s,drawDefinition:o,entryStage:r}),m=t!==ko&&r!==Ct&&Is({drawDefinition:o,participantId:s});if(m||v||f)return W({context:{invalidEntry:m,invalidLuckyLoser:v,invalidVoluntaryConsolation:f},result:{error:Dp},stack:d});const g=_e(kne(Rd({},a),{entryStageSequence:e,participantId:s,entryPosition:i,entryStatus:t,entryStage:r,extensions:l}));return u&&tt({element:g,extension:u}),c&&tt({extension:{name:"roundEntry",value:c},element:g}),o.entries.push(g),Je({drawDefinition:o}),Rd({},B)}function fA({entryStatus:t=Mr,autoEntryPositions:e=!0,ignoreStageSpace:r,drawDefinition:n,participantIds:o,stageSequence:i,stage:s=de,roundTarget:a}){if(!s)return{error:Ih};if(!n)return{error:pe};if(!Array.isArray(o))return{error:Qr};if(!aA({stage:s,drawDefinition:n}))return{error:No};const c=uA({drawDefinition:n,stageSequence:i,entryStatus:t,stage:s});if(!r&&!c.success)return{error:c.error};const l=c.positionsAvailable||0;if(!r&&s!==Ct&&l<o.length)return{error:Ch};const u=o.reduce((d,p)=>{const v=t===ko&&Is({participantId:p,drawDefinition:n,entryStatus:t}),f=s===Ct&&Is({entryStage:s,drawDefinition:n,participantId:p});return t!==ko&&s!==Ct&&Is({drawDefinition:n,participantId:p})||v||f?d.concat(p):d},[]);return o.filter(d=>d&&!u.includes(d)).forEach(d=>{const p=Object.assign({participantId:d},{entryStage:s,entryStatus:t,entryStageSequence:i});a&&tt({element:p,extension:{name:Tn,value:a}}),n.entries.push(p)}),e&&(n.entries=zr({entries:n.entries})),Je({drawDefinition:n}),u!=null&&u.length?Rd({info:"some participantIds could not be added",participantIdsNotAdded:u},B):Rd({},B)}var Gne=Object.defineProperty,vA=Object.getOwnPropertySymbols,Wne=Object.prototype.hasOwnProperty,Hne=Object.prototype.propertyIsEnumerable,mA=(t,e,r)=>e in t?Gne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qne=(t,e)=>{for(var r in e||(e={}))Wne.call(e,r)&&mA(t,r,e[r]);if(vA)for(var r of vA(e))Hne.call(e,r)&&mA(t,r,e[r]);return t};function gA({autoEntryPositions:t=!0,entryStageSequence:e,ignoreStageSpace:r,drawDefinition:n,participantIds:o,entryStatus:i,roundTarget:s,entryStage:a,extension:c,drawId:l,event:u}){if(!(o!=null&&o.length))return{error:lo};if(!u)return{error:Ir};if(!l)return{error:wr};const d=(u.entries||[]).map(Xe);if(o.filter(m=>!d.includes(m)).length)return{error:_F};if(n){const m=fA({stageSequence:e,autoEntryPositions:t,stage:a,ignoreStageSpace:r,drawDefinition:n,participantIds:o,entryStatus:i,roundTarget:s,extension:c});if(m.error)return m}const{flightProfile:v}=It({event:u}),f=v==null?void 0:v.flights.find(m=>m.drawId===l);return f!=null&&f.drawEntries&&(o.forEach(m=>{const g=i===ko&&Wm({participantId:m,entryStatus:i,flight:f}),h=a===Ct&&Wm({participantId:m,entryStage:a,flight:f});!(i!==ko&&a!==Ct&&Wm({flight:f,participantId:m}))&&!g&&!h&&f.drawEntries.push({participantId:m,entryStatus:i,entryStage:a})}),t&&(f.drawEntries=zr({entries:f.drawEntries}))),qne({},B)}function Wm({participantId:t,entryStatus:e,entryStage:r,flight:n}){var o;const i=(o=n.drawEntries)==null?void 0:o.find(s=>s.participantId===t&&(!e||e===s.entryStatus)&&(!r||r===s.entryStage));return t&&i}var Yne=Object.defineProperty,zne=Object.defineProperties,Kne=Object.getOwnPropertyDescriptors,hA=Object.getOwnPropertySymbols,Qne=Object.prototype.hasOwnProperty,Jne=Object.prototype.propertyIsEnumerable,_A=(t,e,r)=>e in t?Yne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zne=(t,e)=>{for(var r in e||(e={}))Qne.call(e,r)&&_A(t,r,e[r]);if(hA)for(var r of hA(e))Jne.call(e,r)&&_A(t,r,e[r]);return t},Xne=(t,e)=>zne(t,Kne(e));function Fd({autoEntryPositions:t=!0,tournamentParticipants:e,tournamentRecord:r,participantIds:n,event:o}){var i,s;const a="removeEventEntries";if(!(o!=null&&o.eventId))return{error:Le};if(!Array.isArray(n))return W({result:{error:lo},stack:a});if(n=n==null?void 0:n.filter(Boolean),!(n!=null&&n.length))return W({result:{error:lo},stack:a});const{eventId:c}=o;if(e||(e=Qt({participantFilters:{participantIds:n},tournamentRecord:r,withEvents:!0,withDraws:!0}).tournamentParticipants),e==null?void 0:e.every(p=>{const v=p.events.find(m=>m.eventId===c),f=(v==null?void 0:v.drawIds)||[];return p.draws.filter(m=>f.includes(m.drawId)&&m.positionAssignments).length}))return W({result:{error:Vs},stack:a});const u=[];o.entries=(o.entries||[]).filter(p=>{const v=!n.includes(p==null?void 0:p.participantId);return v||u.push(p.participantId),v}),t&&(o.entries=zr({entries:o.entries}));const{flightProfile:d}=It({event:o});return(i=d==null?void 0:d.flights)==null||i.forEach(p=>{p.drawEntries=(p.drawEntries||[]).filter(v=>!n.includes(v.participantId))}),(s=o.drawDefinitions)==null||s.forEach(p=>{p.entries=(p.entries||[]).filter(v=>!n.includes(v.participantId))}),Xne(Zne({},B),{participantIdsRemoved:u})}var eoe=Object.defineProperty,toe=Object.defineProperties,roe=Object.getOwnPropertyDescriptors,IA=Object.getOwnPropertySymbols,noe=Object.prototype.hasOwnProperty,ooe=Object.prototype.propertyIsEnumerable,PA=(t,e,r)=>e in t?eoe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ioe=(t,e)=>{for(var r in e||(e={}))noe.call(e,r)&&PA(t,r,e[r]);if(IA)for(var r of IA(e))ooe.call(e,r)&&PA(t,r,e[r]);return t},soe=(t,e)=>toe(t,roe(e));function Qo(t){var e;const{entryStatus:r=Mr,autoEntryPositions:n=!0,participantIds:o=[],entryStageSequence:i,ignoreEventGender:s,entryStage:a=de,tournamentRecord:c,ignoreStageSpace:l,drawDefinition:u,roundTarget:d,extensions:p,extension:v,drawId:f,event:m}=t,g="addEventEntries";if(!m)return{error:Le};if(!(o!=null&&o.length))return W({result:{error:lo},stack:g});if(!(m!=null&&m.eventId))return{error:Ir};const h=[],_=[];if(p&&(!Array.isArray(p)||!p.every(on))||v&&!on({extension:v}))return W({result:{error:Z},context:_e({extension:v,extensions:p}),info:"Invalid extension(s)",stack:g});const I=!!c,P=[];let O;const y=((e=c==null?void 0:c.participants)==null?void 0:e.filter(N=>{var w,$,U;if(!o.includes(N.participantId))return!1;const A=m.eventType===pt&&N.participantType===Me&&!Ai(r),M=m.eventType===it&&N.participantType===we;return A&&(!m.gender||s||[yo,ia].includes(m.gender)||m.gender===((w=N.person)==null?void 0:w.sex))||M&&!Ai(r)||m.eventType===it&&N.participantType===Me&&Ai(r)?!0:A&&m.gender&&!s&&![yo,ia].includes(m.gender)&&m.gender!==(($=N.person)==null?void 0:$.sex)?(P.push({participantId:N.participantId,sex:(U=N.person)==null?void 0:U.sex}),!1):m.eventType===Ye&&(N.participantType===Ye||Ai(r)&&N.participantType===Me)}).map(N=>N.participantId))||[],S=o.filter(N=>!I||y.includes(N));m.entries||(m.entries=[]);const T=m.entries.map(N=>{var w;return N.participantId||((w=N.participant)==null?void 0:w.participantId)});if(S.forEach(N=>{if(!T.includes(N)){const w=_e({participantId:N,entryStatus:r,entryStage:a,extensions:p});v&&tt({element:w,extension:v}),d&&tt({extension:{name:Tn,value:d},element:w}),i&&(w.entryStageSequence=i),_.push(w.participantId),m.entries.push(w)}}),f&&!Ai(a)){const N=gA({participantIds:S,autoEntryPositions:n,entryStageSequence:i,ignoreStageSpace:l,drawDefinition:u,entryStatus:r,roundTarget:d,entryStage:a,extension:v,drawId:f,event:m});N.error&&(O=N.error)}if([it,Ye].includes(m.eventType)){const N=(m.entries||[]).map(M=>M.participantId),w=(m.entries||[]).filter(M=>Ai(M.entryStatus)).map(M=>M.participantId),U=((c==null?void 0:c.participants)||[]).filter(M=>N.includes(M.participantId)&&[we,Ye].includes(M.participantType)).map(M=>M.individualParticipantIds).flat(1/0),A=w.filter(M=>U.includes(M));A.length&&(h.push(...A),Fd({participantIds:A,autoEntryPositions:!1,tournamentRecord:c,event:m}))}if(S.length!==o.length)return W({result:{error:Qr},context:{misMatchedGender:P,gender:m.gender},stack:g});n&&(m.entries=zr({entries:m.entries||[]}));const b=_.length-h.length;return W({result:soe(ioe({},B),{addedEntriesCount:b}),stack:g,info:O})}var aoe=Object.defineProperty,coe=Object.defineProperties,loe=Object.getOwnPropertyDescriptors,yA=Object.getOwnPropertySymbols,uoe=Object.prototype.hasOwnProperty,doe=Object.prototype.propertyIsEnumerable,SA=(t,e,r)=>e in t?aoe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Hm=(t,e)=>{for(var r in e||(e={}))uoe.call(e,r)&&SA(t,r,e[r]);if(yA)for(var r of yA(e))doe.call(e,r)&&SA(t,r,e[r]);return t},poe=(t,e)=>coe(t,loe(e));function OA({addIndividualParticipantsToEvents:t,individualParticipantIds:e,groupingParticipantId:r,tournamentRecord:n,suppressErrors:o}){const i="removeIndividualParticipantIds";if(!n)return W({result:{error:ee},stack:i});if(!r||!e)return W({result:{error:Oe},stack:i});const a=(n.participants||[]).find(d=>d.participantId===r);if(!a)return W({result:{error:wt},stack:i});if(![Ye,dr].includes(a.participantType))return W({result:{participantType:a.participantType,error:In},stack:i});const c=bA({individualParticipantIds:e,groupingParticipant:a,tournamentRecord:n,suppressErrors:o}),{removed:l,error:u}=c;if(u)return W({result:c,stack:i});if(t)for(const d of n.events||[]){const p=(d.entries||[]).map(({participantId:v})=>v).filter(Boolean);if(p.includes(r)){const v=l.filter(f=>!p.includes(f));Qo({participantIds:v,entryStatus:qr,tournamentRecord:n,event:d})}}return l&&xe({topic:Ht,payload:{tournamentId:n.tournamentId,participants:[a]}}),Hm(Hm({},B),c)}function bA({individualParticipantIds:t=[],groupingParticipant:e,tournamentRecord:r,suppressErrors:n,mappedMatchUps:o,participants:i}){let s=[];if(!e)return{removed:s};let a=[],c=[];i||({participants:i,mappedMatchUps:o}=ys({withMatchUps:!0,tournamentRecord:r,withEvents:!0}));const u=i.find(({participantId:v})=>v===e.participantId).events.map(({eventId:v})=>v),d=(e.individualParticipantIds||[]).filter(v=>{var f;const m=t==null?void 0:t.includes(v),g=m&&((f=i.find(_=>_.participantId===v))==null?void 0:f.matchUps.filter(({eventId:_})=>u.includes(_)).map(({matchUpId:_})=>o[_]).filter(({winningSide:_,score:I})=>_||Dt({score:I}))),h=m&&!(g!=null&&g.length);if(m&&!h&&c.push(v),h){s.push(v);for(const _ of r.events||[])for(const I of _.drawDefinitions||[]){const{extension:P}=Vt({element:I,name:bn});let O=P==null?void 0:P.value[e.participantId];O&&(O=O.filter(S=>S.participantId!==v),tt({element:I,extension:P}),Rc({drawDefinition:I}));const y=Dr({drawDefinition:I,inContext:!1}).matchUps||[];for(const S of y){const T=S.sides||[];for(const E of T)(E.lineUp||[]).find(w=>w.participantId===v)&&(E.lineUp=E.lineUp.filter(w=>w.participantId!==v),Qe({tournamentId:r==null?void 0:r.tournamentId,drawDefinition:I,matchUp:S}))}}}else a.push(v);return!h});e.individualParticipantIds=d;const p={groupingParticipantId:e.participantId,cannotRemove:c,notRemoved:a,removed:s};return c.length&&!n&&poe(Hm({},p),{cannotRemove:c,error:Cp})||p}function qm({individualParticipantIds:t=[],groupingTypes:e=[Ye,dr],participantRole:r=qt,tournamentRecord:n}){if(!n)return{error:ee};const o=n.participants||[],{participants:i,mappedMatchUps:s}=ys({withMatchUps:!0,tournamentRecord:n,withEvents:!0});let a=0;return o.filter(c=>(c.participantRole===r||!c.participantRole)&&e.includes(c.participantType)).forEach(c=>{const{removed:l}=bA({groupingParticipant:c,individualParticipantIds:t,tournamentRecord:n,mappedMatchUps:s,participants:i});l&&a++}),a?B:{error:RF}}var foe=Object.defineProperty,voe=Object.defineProperties,moe=Object.getOwnPropertyDescriptors,TA=Object.getOwnPropertySymbols,goe=Object.prototype.hasOwnProperty,hoe=Object.prototype.propertyIsEnumerable,EA=(t,e,r)=>e in t?foe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wA=(t,e)=>{for(var r in e||(e={}))goe.call(e,r)&&EA(t,r,e[r]);if(TA)for(var r of TA(e))hoe.call(e,r)&&EA(t,r,e[r]);return t},_oe=(t,e)=>voe(t,moe(e));function ja({addIndividualParticipantsToEvents:t,tournamentRecord:e,participantIds:r}){var n,o;if(!e)return{error:ee};if(!(r!=null&&r.length))return{error:lo};const i=((n=e.participants)==null?void 0:n.length)||0;if(!i)return wA({},B);const s=(o=e.events||[])==null?void 0:o.filter(({eventType:f})=>f===Tt).map(f=>{var m;return(m=f==null?void 0:f.drawDefinitions)==null?void 0:m.map(({drawId:g})=>g)}).flat(1/0),{tournamentParticipants:a}=Qt({participantFilters:{participantIds:r},tournamentRecord:e,withDraws:!0}),c=()=>{const{matchUps:f}=Bt({matchUpFilters:{drawIds:s,matchUpTypes:[it]},tournamentRecord:e}),m=f.map(({sides:g})=>g.map(({participantId:h})=>h)).flat().filter(Boolean);return jt(m,r)},l=(s==null?void 0:s.length)&&c(),u=a.filter(f=>{var m;return(m=f.draws)==null?void 0:m.filter(g=>(!(s!=null&&s.length)||!(s!=null&&s.includes(g.drawId)))&&g.positionAssignments).length});if(l!=null&&l.length||u.length)return{error:Vs};const d={},p={};for(const f of e.events||[]){const m=Fd({tournamentParticipants:a,tournamentRecord:e,participantIds:r,event:f});if(m.error)return m;d[f.eventId]=m.participantIdsRemoved}e.participants=e.participants.filter(f=>{const m=r.includes(f.participantId)||f.participantType===we&&f.individualParticipantIds.some(g=>r.includes(g));if(!m&&f.participantType===Tt&&f.individualParticipantIds.some(g=>r.includes(g))&&(f.individualParticipantIds=f.individualParticipantIds.filter(g=>!r.includes(g))),m&&t&&[we,Ye].includes(f.participantType))for(const g of f.individualParticipantIds||[])r.includes(g)||(p[f.participantId]||(p[f.participantId]=[]),p[f.participantId].push(g));return!m});const v=i-e.participants.length;if(qm({individualParticipantIds:r,tournamentRecord:e}),t)for(const f of e.events||[]){const g=d[f.eventId].map(h=>p[h]||[]).flat();Qo({participantIds:g,entryStatus:qr,tournamentRecord:e,event:f})}return v&&xe({payload:{participantIds:r,tournamentId:e.tournamentId},topic:TI}),v?_oe(wA({},B),{participantsRemovedCount:v}):{error:Cp}}function $A({selected:t=!0,drawDefinition:e,entryStatuses:r,drawId:n,event:o,stage:i}){var s;let a=o.entries||[];if(n){const{flightProfile:l}=It({event:o}),u=(s=l==null?void 0:l.flights)==null?void 0:s.find(d=>d.drawId===n);u?a=u.drawEntries:a=e==null?void 0:e.entries}const c=a.filter(l=>(!(r!=null&&r.length)||!l.entryStatus||r.includes(l.entryStatus))&&(!i||!l.entryStage||l.entryStage===i)&&(!t||Wo.includes(l.entryStatus)));return{entries:a,stageEntries:c}}var Ioe=Object.defineProperty,Poe=Object.defineProperties,yoe=Object.getOwnPropertyDescriptors,NA=Object.getOwnPropertySymbols,Soe=Object.prototype.hasOwnProperty,Ooe=Object.prototype.propertyIsEnumerable,AA=(t,e,r)=>e in t?Ioe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,boe=(t,e)=>{for(var r in e||(e={}))Soe.call(e,r)&&AA(t,r,e[r]);if(NA)for(var r of NA(e))Ooe.call(e,r)&&AA(t,r,e[r]);return t},Toe=(t,e)=>Poe(t,yoe(e));function UA({removeGroupParticipant:t,tournamentRecord:e,drawDefinition:r,participantId:n,drawId:o,stage:i,event:s}){const a="destroyGroupEntry";if(!e)return{error:ee};if(!n)return W({result:{error:yt},stack:a});if(!s)return{error:Le};if(![br,Tt].includes(s.eventType))return W({result:{error:ri},stack:a});const c=e.participants||[],l=c.find(_=>_.participantId===n);if(!l)return W({result:{error:wt},stack:a});if(![we,Tt].includes(l.participantType)||l.participantType===Tt&&s.eventType!==Tt||l.participantType===we&&s.eventType!==br)return{error:In};const d=(s.entries||[]).find(_=>_.participantId===n);if(!d)return{error:Mh};const{stageEntries:p}=$A({entryStatusees:Wo,selected:!1,drawDefinition:r,drawId:o,event:s,stage:i}),v=p.map(Xe),f=c.filter(({participantId:_})=>v.includes(_)).map(({individualParticipantIds:_})=>_).flat().filter(Boolean),m=l.individualParticipantIds.filter(_=>hn(_,f).length===1);let g=Fd({participantIds:[n],tournamentRecord:e,drawDefinition:r,drawId:o,event:s});if(g.error||m.length&&(g=Qo({participantIds:m,entryStatus:qr,entryStage:d.entryStage,tournamentRecord:e,drawDefinition:r,drawId:o,event:s}),g.error))return g;let h;return t&&ja({tournamentRecord:e,participantIds:[n]}).success&&(h=!0),Toe(boe({},B),{participantRemoved:h})}var Eoe=Object.defineProperty,Ld=Object.getOwnPropertySymbols,CA=Object.prototype.hasOwnProperty,MA=Object.prototype.propertyIsEnumerable,DA=(t,e,r)=>e in t?Eoe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jA=(t,e)=>{for(var r in e||(e={}))CA.call(e,r)&&DA(t,r,e[r]);if(Ld)for(var r of Ld(e))MA.call(e,r)&&DA(t,r,e[r]);return t},woe=(t,e)=>{var r={};for(var n in t)CA.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Ld)for(var n of Ld(t))e.indexOf(n)<0&&MA.call(t,n)&&(r[n]=t[n]);return r};function RA({removeGroupParticipant:t,tournamentRecord:e,drawDefinition:r,participantId:n,drawId:o,event:i}){return UA({removeGroupParticipant:t,individualEntryStatus:qr,tournamentRecord:e,drawDefinition:r,participantId:n,drawId:o,event:i})}function $oe(t){if(!t.tournamentRecord)return{error:ee};const e=t,{participantIds:r}=e,n=woe(e,["participantIds"]);let o=0;const i=[];for(const s of r){const a=UA(jA({participantId:s},n));a.success&&(o+=1),a.error&&i.push(a.error)}return o?jA({destroyedCount:o},B):{error:i}}function Vd(t){const{tournamentRecord:e,replaceWithBye:r,drawDefinition:n,destroyPair:o,entryStatus:i,matchUpsMap:s,drawId:a}=t,c="removeDrawPositionAssignment",l=Ia(t);if(l.error)return W({result:l,stack:c});const{participantId:u}=l,{drawPosition:d,event:p,structureId:v}=t;if([un,Go].includes(i)&&u){const{tournamentRecord:g}=t,{participant:h}=Ro({tournamentRecord:g,participantId:u}),{participantType:_,individualParticipantIds:I}=h||{};if(o&&_===we){const P=RA({tournamentRecord:g,drawDefinition:n,participantId:u,event:p});if(P.error)return W({result:P,stack:c});km({participantIds:I,tournamentRecord:g,drawDefinition:n,entryStatus:i,drawId:a,event:p})}else km({participantIds:[u],tournamentRecord:g,drawDefinition:n,entryStatus:i,drawId:a,event:p})}if(r){const g=jr({tournamentRecord:e,drawDefinition:n,drawPosition:d,structureId:v,matchUpsMap:s,event:p});if(g.error)return W({result:g,stack:c})}const{structure:f}=Te({drawDefinition:n,structureId:v});return Hu({structure:f,drawPositions:[d]}),Wc({drawDefinition:n,positionAction:{name:"removeDrawPositionAssignment",replaceWithBye:r,drawPosition:d,entryStatus:i,structureId:v}}),l}var Noe=Object.defineProperty,Aoe=Object.defineProperties,Uoe=Object.getOwnPropertyDescriptors,FA=Object.getOwnPropertySymbols,Coe=Object.prototype.hasOwnProperty,Moe=Object.prototype.propertyIsEnumerable,LA=(t,e,r)=>e in t?Noe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Jo=(t,e)=>{for(var r in e||(e={}))Coe.call(e,r)&&LA(t,r,e[r]);if(FA)for(var r of FA(e))Moe.call(e,r)&&LA(t,r,e[r]);return t},Doe=(t,e)=>Aoe(t,Uoe(e));function VA({tournamentRecord:t,drawDefinition:e,drawPositions:r,structureId:n,event:o}){const i="swapDrawPositionAssignments";if(!e)return{error:pe};if(!n)return{error:ar};if((r==null?void 0:r.length)!==2)return{error:Z,drawPositions:r};let s=Kt({drawDefinition:e});const{matchUps:a}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:e,matchUpsMap:s}),{structure:c}=Te({drawDefinition:e,structureId:n});if(!c)return{error:Br};let l;if(c.structureType===tr?l=Foe({inContextDrawMatchUps:a,tournamentRecord:t,drawDefinition:e,drawPositions:r,matchUpsMap:s,structure:c,event:o}):l=joe({inContextDrawMatchUps:a,tournamentRecord:t,drawDefinition:e,drawPositions:r,matchUpsMap:s,structure:c,event:o}),l.error)return l;if(Hu({structure:c,drawPositions:r}),Wc({drawDefinition:e,positionAction:{name:"swapDrawPositionAssignments",drawPositions:r,structureId:n}}),Ho({tournamentId:t==null?void 0:t.tournamentId,drawDefinition:e,source:i,structure:c,event:o}),o.eventType===Nn){const d=ze({matchUpFilters:{matchUpTypes:[Zr]},inContext:!0,structure:c}).matchUps.filter(v=>{var f;return(f=v.drawPositions)==null?void 0:f.some(m=>r.includes(m))}),p=ze({structure:c,matchUpFilters:{matchUpTypes:[Zr]}}).matchUps;d.forEach(v=>{(v.sides||[]).forEach(f=>{var m;const g=f==null?void 0:f.drawPosition;if(r.includes(g)){const h=f.participantId,_=p.find(({matchUpId:P})=>P===v.matchUpId),I=(m=v==null?void 0:v.sides)==null?void 0:m.reduce((P,O,y)=>O.drawPosition===g?y:P,void 0);Ev({inContextTargetMatchUp:v,drawPositionSideIndex:I,teamParticipantId:h,tournamentRecord:t,drawDefinition:e,matchUp:_,event:o})}})})}return Je({drawDefinition:e,structureIds:[n]}),Jo({},B)}function joe({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPositions:n,matchUpsMap:o,structure:i,event:s}){const a=i==null?void 0:i.positionAssignments.filter(l=>n==null?void 0:n.includes(l.drawPosition));return a?a.filter(({bye:l})=>l).length===2?Jo({},B):a.filter(({qualifier:l})=>l).length===2?Jo({},B):a.some(({bye:l})=>l)?xA({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,assignments:a,matchUpsMap:o,structure:i,event:s}):Roe({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,assignments:a,matchUpsMap:o,structure:i,event:s}):{error:Z,structure:i,info:"Missing positionAssignments"}}function xA({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,assignments:n,matchUpsMap:o,structure:i,event:s}){const a=n.find(({bye:f})=>f),c=n.find(({participantId:f})=>f),l=a.drawPosition,{participantId:u,drawPosition:d}=c,{structureId:p}=i;let v=Vd({drawPosition:l,inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,structureId:p,matchUpsMap:o});return v.error||(v=Vd({drawPosition:d,inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,structureId:p,matchUpsMap:o}),v.error)||(v=jr({drawPosition:d,inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,structureId:p,matchUpsMap:o,event:s}),v=vn({drawPosition:l,inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,structureId:p,participantId:u,matchUpsMap:o,event:s}),v.error)?v:Jo({},B)}function Roe({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,assignments:n,matchUpsMap:o,structure:i,event:s}){const a=Object.assign({},...n.map((c,l)=>{const{drawPosition:u}=c,d=Doe(Jo({},n[1-l]),{drawPosition:u});return{[u]:d}}));return i.positionAssignments=i.positionAssignments.map(c=>a[c.drawPosition]||c),Dv({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:o,assignments:n,structure:i,event:s}),Jo({},B)}function Foe({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,drawPositions:n,matchUpsMap:o,structure:i,event:s}){var a;const c=(a=i.structures)==null?void 0:a.reduce((u,d)=>{const p=d==null?void 0:d.positionAssignments.filter(v=>n==null?void 0:n.includes(v.drawPosition));return p&&u.push(...p),u},[]);if(c.filter(({bye:u})=>u).length===2)return Jo({},B);if(c.filter(({qualifier:u})=>u).length===2)return Jo({},B);if(Dv({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,matchUpsMap:o,assignments:c,structure:i,event:s}),c.some(({bye:u})=>u))xA({inContextDrawMatchUps:t,tournamentRecord:e,drawDefinition:r,assignments:c,matchUpsMap:o,structure:i,event:s});else{const u=ue(c,!1,!0);c.forEach((d,p)=>{const v=u[1-p].participantId;d.qualifier=u[1-p].qualifier,d.participantId=v})}return Jo({},B)}var Loe=Object.defineProperty,BA=Object.getOwnPropertySymbols,Voe=Object.prototype.hasOwnProperty,xoe=Object.prototype.propertyIsEnumerable,kA=(t,e,r)=>e in t?Loe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Boe=(t,e)=>{for(var r in e||(e={}))Voe.call(e,r)&&kA(t,r,e[r]);if(BA)for(var r of BA(e))xoe.call(e,r)&&kA(t,r,e[r]);return t};function GA({tournamentRecord:t,drawDefinition:e,drawPosition:r,structureId:n,subOrder:o,event:i}){if(!e)return{error:pe};if(!n)return{error:ar};if(!r)return{error:Ya};const{structure:s}=Te({drawDefinition:e,structureId:n});let a=s;s.structureType===tr&&(a=s.structures.find(m=>m.positionAssignments.find(g=>g.drawPosition===r)));const c=a.positionAssignments,l=c.find(m=>m.drawPosition===r);l&&tt({element:l,extension:{name:Qs,value:o}});const p=((i==null?void 0:i.eventType)===He||e.matchUpType===He||(i==null?void 0:i.tieFormat)||(e==null?void 0:e.tieFormat)||(s==null?void 0:s.tieFormat))&&{matchUpTypes:[He]},{matchUps:v}=ze({structure:a,afterRecoveryTimes:!1,inContext:!0,matchUpFilters:p,event:i}),f=(s==null?void 0:s.matchUpFormat)||e.matchUpFormat;return kP({positionAssignments:c,tournamentRecord:t,drawDefinition:e,matchUpFormat:f,matchUps:v,event:i}),Je({drawDefinition:e,structureIds:[n]}),Boe({},B)}const koe={setSubOrder:GA,clearDrawPosition:Ia,assignDrawPosition:vn,setPositionAssignments:oA,automatedPositioning:pl,assignDrawPositionBye:jr,swapDrawPositionAssignments:VA,alternateDrawPositionAssignment:tA,resolveDrawPositions:hne,initializeStructureSeedAssignments:ZN,getNextSeedBlock:Ku};function WA({drawDefinition:t,event:e,matchUpId:r}){if(!t)return{error:pe};if(!r)return{error:Ut};const{matchUp:n}=nt({drawDefinition:t,event:e,matchUpId:r});return n?sn({element:n,name:Wl}):{error:kr}}function Goe({maxIterations:t=5e3,valueSortedPairings:e,pairingValues:r,deltaObjects:n}){const o=Object.assign({},...e.map(p=>({[p.pairing]:p.value})));let i=HA({rankedMatchUpValues:o,valueSortedPairings:e,deltaObjects:n}),s=i;const a=Object.keys(r);let c=0,l,u=a.length;do u-=1,l=a.length*u*e.length/2;while(l>t&&u>2);let d=[];return a.forEach(p=>{r[p].slice(0,u).forEach(f=>{const m=Ra(p,f.opponent);if(!d.includes(m)){const g=HA({stipulated:[[p,f.opponent]],rankedMatchUpValues:o,valueSortedPairings:e,deltaObjects:n});g.maxDelta<s.maxDelta&&(s=g),g.value<i.value&&(i=g),d.push(m),c+=1}})}),{candidate:i,deltaCandidate:s,candidatesCount:c,iterations:l}}function HA({rankedMatchUpValues:t,valueSortedPairings:e,stipulated:r=[],deltaObjects:n}){const o=[].concat(...r),i=[];let s=0;r.filter(Boolean).forEach(c=>{const l=Ra(...c),u=t[l];i.push({participantIds:c,value:u}),s+=t[l]}),e.forEach(c=>{const l=c.pairing.split("|");if(!l.reduce((d,p)=>o.includes(p)||d,!1)){o.push(...l);let d=c.value;s+=d,i.push({participantIds:l,value:d})}}),i.sort((c,l)=>c.value-l.value);const a=i.reduce((c,l)=>{const u=Ra(...l.participantIds),d=n[u];return d>c?d:c},0);return{value:s,participantIdPairings:i,maxDelta:a}}function Ra(t,e){return[t,e].sort().join("|")}var Woe=Object.defineProperty,Hoe=Object.defineProperties,qoe=Object.getOwnPropertyDescriptors,qA=Object.getOwnPropertySymbols,Yoe=Object.prototype.hasOwnProperty,zoe=Object.prototype.propertyIsEnumerable,YA=(t,e,r)=>e in t?Woe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Koe=(t,e)=>{for(var r in e||(e={}))Yoe.call(e,r)&&YA(t,r,e[r]);if(qA)for(var r of qA(e))zoe.call(e,r)&&YA(t,r,e[r]);return t},Qoe=(t,e)=>Hoe(t,qoe(e));const Joe=50,Zoe=60,Ym=0,Xoe=5e3;function eie({maxIterations:t=Xoe,generateMatchUps:e=!0,tournamentParticipants:r,tournamentRecord:n,addToStructure:o,drawDefinition:i,participantIds:s,adHocRatings:a,structureId:c,matchUpIds:l,eventType:u,structure:d}){if(!(s!=null&&s.length))return{error:lo};const{encounters:p}=nie({matchUps:d.matchUps}),v={};for(const S of p)v[S]||(v[S]=0),v[S]+=Joe;const f=r==null?void 0:r.filter(({participantType:S})=>S===Ye);if(f)for(const S of f){const T=S.individualParticipantIds||[],{uniquePairings:E}=zA({participantIds:T});for(const b of E)v[b]||(v[b]=0),v[b]+=Zoe}const{uniquePairings:m,possiblePairings:g,deltaObjects:h}=zA({participantIds:s}),_={tournamentParticipants:r,possiblePairings:g,drawDefinition:i,participantIds:s,uniquePairings:m,maxIterations:t,adHocRatings:a,deltaObjects:h,valueObjects:v,eventType:u,structure:d},{candidatesCount:I,participantIdPairings:P,iterations:O}=rie(_);if(!I)return{error:Fp};let y;if(e){const S=Rm({participantIdPairings:P,tournamentRecord:n,addToStructure:o,drawDefinition:i,newRound:!0,structureId:c,matchUpIds:l});if(S.error)return S;y=S.matchUps}return Qoe(Koe({},B),{participantIdPairings:P,candidatesCount:I,iterations:O,matchUps:y})}function tie({tournamentParticipants:t,adHocRatings:e,eventType:r,pairing:n}){return n.split("|").map(o=>{var i;if(r===br){const s=(i=t==null?void 0:t.find(a=>a.participantId===o))==null?void 0:i.individualParticipantIds;return s?s==null?void 0:s.map(a=>e[a||Ym]):Ym*2}else return e[o]||Ym})}function rie({tournamentParticipants:t,adHocRatings:e={},possiblePairings:r,uniquePairings:n,maxIterations:o,deltaObjects:i,valueObjects:s,eventType:a}){n.forEach(f=>{const m=tie({tournamentParticipants:t,adHocRatings:e,eventType:a,pairing:f}),g=Math.abs(m[0]-m[1])+1;i[f]=Math.abs(m[0]-m[1]),s[f]||(s[f]=0),s[f]+=Math.pow(g,2)});const c=n.map(f=>({pairing:f,value:s[f]})).sort((f,m)=>f.value-m.value),{pairingValues:l}=oie({possiblePairings:r,valueObjects:s}),{candidate:u,candidatesCount:d,iterations:p}=Goe({valueSortedPairings:c,maxIterations:o,pairingValues:l,deltaObjects:i}),{participantIdPairings:v}=u;return{candidatesCount:d,participantIdPairings:v,iterations:p}}function zA({participantIds:t}){const e={},r=[];t.forEach(o=>{e[o]=t.filter(i=>i!==o),e[o].forEach(i=>{const s=Ra(i,o);r.includes(s)||r.push(s)})});const n=Object.assign({},...r.map(o=>({[o]:0})));return{uniquePairings:r,possiblePairings:e,deltaObjects:n}}function nie({matchUps:t}){let e=[];for(const r of t){const n=r.sides.map(Xe);if(n.length===2){const o=Ra(...n);e.includes(o)||e.push(o)}}return{encounters:e}}function oie({possiblePairings:t,valueObjects:e}){let r={};for(const o of Object.keys(t)){let i=t[o].map(s=>n(o,s));r[o]=i.sort((s,a)=>s.value-a.value)}function n(o,i){let s=Ra(o,i);return{opponent:i,value:e[s]}}return{pairingValues:r}}function KA({tournamentParticipants:t,restrictEntryStatus:e,tournamentRecord:r,generateMatchUps:n,addToStructure:o,drawDefinition:i,participantIds:s,maxIterations:a,structureId:c,matchUpIds:l,scaleName:u,event:d}){var p,v,f;if(typeof i!="object"||i.drawType&&i.drawType!==cn)return{error:ji};if(!Array.isArray(i.entries)||s&&!Array.isArray(s))return{error:Z,info:"Missing Entries"};const{eventType:m}=d||{},g=i.entries.filter(({entryStatus:P})=>!e||Wo.includes(P)).map(Xe);if(s){const P=s.filter(O=>!g.includes(O));if(P!=null&&P.length)return{error:co,invalidParticipantIds:P}}else s=g;if(!c){const P=(v=(p=i.structures)==null?void 0:p.filter(O=>O.stageSequence===1))==null?void 0:v.reduce((O,y)=>{const S=ts[y.stage];return Po({drawDefinition:i,structure:y})&&S>(ts[O==null?void 0:O.stage]||1)?y:O},void 0);c=P==null?void 0:P.structureId}const h=(f=i.structures)==null?void 0:f.find(P=>P.structureId===c);if(!h)return{error:Br};if(!Po({drawDefinition:i,structure:h}))return{error:ji};const I={};for(const P of s){const O=t==null?void 0:t.find(S=>S.participantId===P);let y=QA({eventType:m,participant:O});!y&&u&&(y=QA({scaleValue:y,eventType:m,participant:O})),y&&(I[P]=y)}return eie({tournamentParticipants:t,tournamentRecord:r,generateMatchUps:n,addToStructure:o,drawDefinition:i,participantIds:s,maxIterations:a,adHocRatings:I,structureId:c,matchUpIds:l,structure:h,eventType:m})}function QA({scaleName:t="dynamic",eventType:e,participant:r}){var n;const i=r&&ro({scaleAttributes:{eventType:e||Hn,scaleType:Yi,scaleName:t},participant:r});return(n=i==null?void 0:i.scaleItem)==null?void 0:n.scaleValue}function JA({drawDefinition:t,matchUpId:e,outcome:r,matchUp:n}){var o,i;if(!n&&!t)return{error:pe};if(!r)return{error:Oe,info:"missing outcome"};if(!n&&!e)return{error:$r};if(!n){const a=nt({drawDefinition:t,matchUpId:e});if(a.error)return a;n=a.matchUp}return typeof r!="object"||!((o=r.score)!=null&&o.scoreStringSide1)||!((i=r.score)!=null&&i.scoreStringSide2)?{error:Z}:tt({element:n,extension:{name:Wl,value:r}})}function iie({matchUps:t}){if(!t)return{error:Ao};const e=t.map(o=>o.drawPositions).flat();Ft()&&t.forEach(o=>{var i;if(!Array.isArray(o.drawPositions)){console.log("drawPositions not an array",o);return}(i=o.drawPositions)==null||i.forEach(s=>{ZA(s)||console.log("invalid drawPosition",o)})});const r=e==null?void 0:e.every(ZA),n=t.find(o=>!Array.isArray(o.drawPositions));return r&&!n}function ZA(t){return t!==null&&(t===void 0||!isNaN(t))}function XA({drawDefinition:t,matchUpId:e,event:r}){if(!t)return{error:pe};const{matchUp:n}=nt({drawDefinition:t,matchUpId:e,event:r});return tt({extension:{name:zs,value:!0},element:n})}function e1({tournamentRecord:t,drawDefinition:e,matchUpId:r,event:n}){if(!e)return{error:pe};const{matchUp:o}=nt({drawDefinition:e,matchUpId:r,event:n});return(o==null?void 0:o.matchUpType)!==Zr?{error:Gr}:Kc({enableAutoCalc:!0,tournamentRecord:t,drawDefinition:e,matchUpId:r,event:n})}var sie=Object.defineProperty,t1=Object.getOwnPropertySymbols,aie=Object.prototype.hasOwnProperty,cie=Object.prototype.propertyIsEnumerable,r1=(t,e,r)=>e in t?sie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lie=(t,e)=>{for(var r in e||(e={}))aie.call(e,r)&&r1(t,r,e[r]);if(t1)for(var r of t1(e))cie.call(e,r)&&r1(t,r,e[r]);return t};function n1({drawDefinition:t,finishingOrder:e}){var r;if(!t)return{error:pe};const n="setOrderOfFinish";if(!Array.isArray(e))return W({result:{error:Z},info:zt("finishingOrder"),stack:n});const{completedMatchUps:o,matchUpsMap:i}=cs({inContext:!0,drawDefinition:t}),s=o.map(Mt),a=e.map(Mt),{matchUpTypes:c,roundNumbers:l,structureIds:u,matchUpTieIds:d}=o.filter(({matchUpId:I})=>a.includes(I)).reduce((I,P)=>{const{matchUpTieId:O,matchUpType:y,roundNumber:S,structureId:T}=P;return I.matchUpTypes.includes(y)||I.matchUpTypes.push(y),I.roundNumbers.includes(S)||I.roundNumbers.push(S),I.structureIds.includes(T)||I.structureIds.push(T),I.matchUpTieIds.includes(O)||I.matchUpTieIds.push(O),I},{matchUpTypes:[],roundNumbers:[],structureIds:[],matchUpTieIds:[]});if(c.length>1||d.length>1||l.length>1||u.length>1)return W({result:{error:Z},info:"matchUpType, structureId and roundNumber must be equivalent",stack:n});let p,v;const f={},m=[],g=[];if(!e.every(({orderOfFinish:I,matchUpId:P})=>(m.push(P),I&&g.push(I),f[P]=I,p=s.includes(P),v=I===void 0||ut(I)&&Math.floor(I)>0,p&&v)))return W({result:{error:p?Z:za},info:!p&&"matchUps must be completed"||!v&&"orderOfFinish must be integer > 0 or undefined"||void 0,stack:n});const _=o.filter(I=>I.structureId===u[0]&&I.roundNumber===l[0]&&I.matchUpType===c[0]&&I.matchUpTieId===d[0]&&!m.includes(I.matchUpId));for(const I of _){const{orderOfFinish:P}=I||{};if(P){if(!ut(P))return W({result:{error:Z},context:{orderOfFinish:P},matchUp:I,stack:n});g.push(P)}}if(ah(g).length!==g.length||Math.max(...g)>g.length)return W({result:{error:Z},info:"Values not unique or greater than expected number of values",stack:n});if(u.length){const I=Lc({matchUpFilters:{matchUpIds:a},structureId:u[0],drawDefinition:t,matchUpsMap:i});if(I.error)return W({result:I,stack:n});(r=I.completedMatchUps)==null||r.forEach(P=>P.orderOfFinish=f[P.matchUpId])}return lie({},B)}var uie=Object.defineProperty,die=Object.defineProperties,pie=Object.getOwnPropertyDescriptors,o1=Object.getOwnPropertySymbols,fie=Object.prototype.hasOwnProperty,vie=Object.prototype.propertyIsEnumerable,i1=(t,e,r)=>e in t?uie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s1=(t,e)=>{for(var r in e||(e={}))fie.call(e,r)&&i1(t,r,e[r]);if(o1)for(var r of o1(e))vie.call(e,r)&&i1(t,r,e[r]);return t},mie=(t,e)=>die(t,pie(e));function a1({tournamentRecord:t,drawDefinition:e,matchUpId:r,event:n,uuids:o}){var i;if(!t)return{error:ee};if(typeof r!="string")return{error:Ut};const s="resetTieFormat";let a=il({tournamentRecord:t,matchUpId:r});if(a.error)return a;const{matchUp:c,structure:l}=a;if(!c.tieMatchUps)return{error:Gr,info:"Must be a TEAM matchUp"};if(!c.tieFormat)return s1({},B);const u=(i=Xt({structure:l,drawDefinition:e,event:n}))==null?void 0:i.tieFormat;if(!u)return{error:Yt,info:"No inherited tieFormat"};const d=[],p=[],v=[],f=[];for(const m of u.collectionDefinitions){const{matchUpCount:g,collectionId:h}=m;p.push(h);const _=(c.tieMatchUps||[]).filter(I=>I.collectionId===h);if(_.length>g)_.sort((I,P)=>(I.matchUpStatus===vt?1:0)-(P.matchUpStatus===vt?1:0)),f.push(..._.slice(0,g)),d.push(..._.slice(3).map(Mt));else if(f.push(..._),_.length<g){const I=g-_.length,P=Nd({collectionDefinition:m,matchUpsLimit:I,uuids:o});v.push(...P)}}for(const m of c.tieMatchUps||[])p.includes(m.collectionId)||d.push(m.matchUpId);return v.length&&(f.push(...v),Pi({tournamentId:t==null?void 0:t.tournamentId,eventId:n.eventId,matchUps:v,drawDefinition:e})),d.length&&yi({tournamentId:t==null?void 0:t.tournamentId,matchUpIds:d,eventId:n==null?void 0:n.eventId,drawDefinition:e}),c.tieMatchUps=f,c.tieFormatId=void 0,c.tieFormat=void 0,Qe({tournamentId:t==null?void 0:t.tournamentId,structureId:l.structureId,eventId:n.eventId,context:s,drawDefinition:e,matchUp:c}),mie(s1({},B),{newMatchUps:v,deletedMatchUpIds:d})}var gie=Object.defineProperty,c1=Object.getOwnPropertySymbols,hie=Object.prototype.hasOwnProperty,_ie=Object.prototype.propertyIsEnumerable,l1=(t,e,r)=>e in t?gie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Iie=(t,e)=>{for(var r in e||(e={}))hie.call(e,r)&&l1(t,r,e[r]);if(c1)for(var r of c1(e))_ie.call(e,r)&&l1(t,r,e[r]);return t};function u1(t){var e;const{tournamentRecord:r,drawDefinition:n,matchUpId:o,event:i}=t,s="resetScorecard";if(!n)return W({result:{error:pe},stack:s});if(!o)return W({result:{error:Ut},stack:s});if(typeof o!="string")return W({result:{error:Z,matchUpId:o},stack:s});const a=Kt({drawDefinition:n});let{matchUps:c}=Nt({includeByeMatchUps:!0,nextMatchUps:!0,inContext:!0,drawDefinition:n,matchUpsMap:a});const l=a.drawMatchUps.find(g=>g.matchUpId===o),u=c.find(g=>g.matchUpId===o);if(!l||!c)return{error:kr};if(!l.matchUpType===He)return{error:Gr};const d=sr({inContextDrawMatchUps:c,drawDefinition:n,matchUpId:o}),p=u.structureId,{structure:v}=Te({drawDefinition:n,structureId:p});if(Object.assign(t,{inContextDrawMatchUps:c,inContextMatchUp:u,matchUpsMap:a,targetData:d,structure:v,matchUp:l}),$i(t))return{error:Ah};for(const g of l.tieMatchUps){const h=Kc({matchUpId:g.matchUpId,matchUpTieId:o,winningSide:void 0,removeScore:!0,tournamentRecord:r,drawDefinition:n,event:i});if(h.error)return W({result:h,stack:s})}let m=Qn({event:t.event,removeScore:!0,tournamentRecord:r,drawDefinition:n,matchUpsMap:a,matchUpId:o});if(m.error)return W({result:m,stack:s});if(t.tiebreakReset&&!m.tieFormatRemoved){const g=(e=Xt({drawDefinition:n,structure:v,event:i}))==null?void 0:e.tieFormat;if(g){const{matchUpCountDifference:h,descendantDifferences:_,ancestorDifferences:I,valueDifference:P}=Au({descendant:l.tieFormat,ancestor:g});if(_.collectionIds.length===1&&!I.collectionIds.length&&!I.groupsCount&&h===1&&P===1){const O=a1({tournamentRecord:r,drawDefinition:n,matchUpId:o,event:i});if(O.error)return O}}}return Iie({},B)}const Pie={resetScorecard:u1,setMatchUpStatus:Kc,setMatchUpFormat:Ju,updateTieMatchUpScore:Qn,isValidMatchUpFormat:xr,disableTieAutoCalc:XA,enableTieAutoCalc:e1,addFinishingRounds:Vc,addMatchUpTimeItem:hr,resetMatchUpTimeItems:AH,checkInParticipant:am,checkOutParticipant:cm,getCheckedInParticipantIds:Mc,addMatchUpScheduleItems:Vu,addMatchUpScheduledDate:gv,addMatchUpScheduledTime:Ti,addMatchUpStartTime:_v,addMatchUpEndTime:Iv,addMatchUpStopTime:Pv,addMatchUpResumeTime:yv,addMatchUpTimeModifiers:mv,addGoesTo:fa,setOrderOfFinish:n1,setDelegatedOutcome:JA,removeDelegatedOutcome:WA,drawMatic:KA,addMatchUpOfficial:qS,findMatchUp:Yk,getRoundMatchUps:pr,validDrawPositions:iie,validateScore:qf};var yie=Object.defineProperty,d1=Object.getOwnPropertySymbols,Sie=Object.prototype.hasOwnProperty,Oie=Object.prototype.propertyIsEnumerable,p1=(t,e,r)=>e in t?yie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bie=(t,e)=>{for(var r in e||(e={}))Sie.call(e,r)&&p1(t,r,e[r]);if(d1)for(var r of d1(e))Oie.call(e,r)&&p1(t,r,e[r]);return t};function zm({drawDefinition:t,policyDefinitions:e}){if(!t)return{error:pe};if(!e||typeof e!="object")return{error:Nl};t.extensions||(t.extensions=[]);const{appliedPolicies:r}=at({drawDefinition:t}),n=Object.keys(e).every(o=>r[o]?!1:(r[o]=e[o],!0));if(n){const i=tt({element:t,extension:{name:Bi,value:r}});if(i.error)return i}return Je({drawDefinition:t}),n?bie({},B):{error:bh}}const Tie={attachPolicies:zm};var Eie=Object.defineProperty,wie=Object.defineProperties,$ie=Object.getOwnPropertyDescriptors,f1=Object.getOwnPropertySymbols,Nie=Object.prototype.hasOwnProperty,Aie=Object.prototype.propertyIsEnumerable,v1=(t,e,r)=>e in t?Eie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,m1=(t,e)=>{for(var r in e||(e={}))Nie.call(e,r)&&v1(t,r,e[r]);if(f1)for(var r of f1(e))Aie.call(e,r)&&v1(t,r,e[r]);return t},Uie=(t,e)=>wie(t,$ie(e));function g1({excludedMatchUpStatuses:t=[],includeEventParticipants:e,includeQualifyingStage:r,finishingRoundLimit:n,policyDefinitions:o,roundNumberLimit:i,tournamentRecord:s,drawDefinition:a,matchUpsLimit:c,requirePlay:l,requireLoss:u,allEntries:d,winsLimit:p,event:v}){var f,m,g,h;if(!a)return{error:pe};const _=[de,st];r&&_.push(Ie);const I=e?((f=Oi({contextFilters:{stages:_},matchUpFilters:{matchUpTypes:[v.eventType]},tournamentRecord:s,inContext:!0,event:v}))==null?void 0:f.matchUps)||[]:((m=Dr({contextFilters:{stages:_},matchUpFilters:{matchUpTypes:[v.eventType]},tournamentRecord:s,inContext:!0,drawDefinition:a}))==null?void 0:m.matchUps)||[],O=is({stage:Ct,drawDefinition:a}).map(({participantId:G})=>G),y={},S={},T={},E={};o=o||Hi({policyTypes:[E_],tournamentRecord:s,drawDefinition:a,event:v});const b=o[E_];t=t.length&&t||(b==null?void 0:b.excludedMatchUpStatuses)||[],e=e!==void 0?e:b==null?void 0:b.includeEventParticipants,d=d!==void 0?d:b==null?void 0:b.allEntries,n=n||(b==null?void 0:b.finishingRoundLimit),i=i||(b==null?void 0:b.roundNumberLimit),c=c||(b==null?void 0:b.matchUpsLimit),l===void 0&&(l=(b==null?void 0:b.requirePlay)!==void 0?b.requirePlay:!0),u===void 0&&(u=(b==null?void 0:b.requireLoss)!==void 0?b.requireLoss:!0),p=p||(b==null?void 0:b.winsLimit);for(const G of I){if(l&&![1,2].includes(G.winningSide)&&G.matchUpStatus!==_t||!isNaN(n)&&G.finishingRound>=n||!isNaN(i)&&G.finishingRound<=i)continue;const x=(g=G.sides)==null?void 0:g.find(({sideNumber:j})=>j===3-G.winningSide),z=(h=G.sides)==null?void 0:h.find(({sideNumber:j})=>j===G.winningSide);if(G.sides.forEach(j=>{var V;const L=(V=j==null?void 0:j.participant)==null?void 0:V.participantId;L&&(T[L]=j.participant,G.matchUpStatus===_t&&!l&&(S[L]=j.participant,y[L]||(y[L]=0),t.includes(G.matchUpStatus)||(y[L]+=1)))}),x!=null&&x.participant){const j=x.participant.participantId;S[j]=x.participant,y[j]||(y[j]=0),t.includes(G.matchUpStatus)||(y[j]+=1)}if(z!=null&&z.participant){const j=z.participant.participantId;E[j]||(E[j]=0),E[j]+=1,y[j]||(y[j]=0),t.includes(G.matchUpStatus)||(y[j]+=1)}}const N=(s==null?void 0:s.participants)&&!l&&!u&&d,w=N&&(e&&v?v.entries:a.entries).filter(G=>![Go,qr].includes(G.entryStatus)).map(({participantId:G})=>G),$=Object.keys(S),U=N?s==null?void 0:s.participants.filter(({participantId:G})=>w.includes(G)):u&&Object.values(S)||Object.values(T),A=G=>!u||$.includes(G),M=G=>!l||(y[G]||0)>=0,C=G=>isNaN(p)||(E[G]||0)<=p,D=G=>!c||y[G]<=c,F=G=>!O.includes(G),R=U.filter(({participantId:G})=>A(G)&&M(G)&&C(G)&&D(G)&&F(G)).map(G=>{var x;return Uie(m1({},G),{individualParticipants:(x=G.individualParticipantIds)==null?void 0:x.map(z=>{var j;return(j=s.participants)==null?void 0:j.find(V=>V.participantId===z)})})});return m1({eligibleParticipants:R,losingParticipantIds:$},B)}function Cie({provisionalPositioning:t,drawDefinition:e,seedBlockInfo:r,structureId:n,event:o}){if(!e)return{error:pe,nextUnfilledDrawPositions:[]};if(!n)return{error:ar,nextUnfilledDrawPositions:[]};const i=Te({drawDefinition:e,structureId:n});if(i.error)return i;const{positionAssignments:s=[]}=Et({structure:i.structure}),{unfilledPositions:a}=Ku({provisionalPositioning:t,randomize:!0,drawDefinition:e,seedBlockInfo:r,structureId:n,event:o}),c=s.filter(l=>!l.participantId&&!l.bye&&!l.qualifier).map(l=>l.drawPosition);return a!=null&&a.length?{nextUnfilledDrawPositions:a}:{nextUnfilledDrawPositions:c}}function h1({tournamentParticipants:t,drawDefinition:e,event:r}){if(!e)return{error:pe};const n=Nt({tournamentParticipants:t,inContext:!0,drawDefinition:e,event:r}),o=ue(n.matchUps,!1,!0),i=Ve(o.reduce((a,c)=>a.concat(...c.sides.map(l=>l.participantId).filter(Boolean)),[])),s=Object.assign({},...i.map(a=>{const c=o.filter(l=>l.sides.map(d=>d.participantId).filter(Boolean).includes(a));return{[a]:c}}));return{participantIds:i,participantIdMatchUps:s}}function _1({byeAdvancements:t=!1,tournamentParticipants:e,drawDefinition:r}){if(!r)return{error:pe};const{participantIds:n,participantIdMatchUps:o}=h1({tournamentParticipants:e,drawDefinition:r}),i=n.map(s=>{const c=o[s].filter(p=>[St,qe].includes(p.matchUpStatus)||p.winningSide),l=c.map(p=>{const v=p.sides.find(g=>g.bye),f=p.sides.find(g=>g.participantId===s).sideNumber;return(p.winningSide||t&&v&&f)===f?p.finishingPositionRange.winner:p.finishingPositionRange.loser}),u=p=>Math.abs(p[0]-p[1]),d=l.reduce((p,v)=>p&&u(p)<u(v)?p:v,void 0);return{[s]:{relevantMatchUps:c,finishingPositionRanges:l,finishingPositionRange:d}}});return Object.assign({},...i)}function Km({finishingPosition:t,targetRoundNumber:e,drawDefinition:r,structureId:n,linkType:o}){const{links:i}=Fc({drawDefinition:r,structureId:n})||{},a=((i==null?void 0:i.target)||[]).filter(({linkType:l})=>l===o).filter(({target:l})=>!e||e===l.roundNumber).map(l=>{const u=l.source.structureId,{structure:d}=Te({structureId:u,drawDefinition:r});if(!(t&&d.finishingPosition!==t))return l}).filter(Boolean);return{sourceStructureIds:a.map(({source:l})=>l.structureId),relevantLinks:a}}function Mie({tournamentParticipants:t,returnParticipants:e,drawPosition:r,participant:n,drawId:o,event:i}){var s;const a=((s=i==null?void 0:i.entries)==null?void 0:s.filter(({entryStatus:c})=>[qr,ns].includes(c)).map(({participantId:c})=>c))||[];if(a.length){const c=n.individualParticipantIds,l=e?t.filter(({participantId:p})=>a.includes(p)):void 0,u=e?t.filter(({participantId:p})=>c.includes(p)):void 0;return{validModifyAssignedPairAction:_e({payload:{participantId:n.participantId,replacementIndividualParticipantId:void 0,existingIndividualParticipantId:void 0,drawPosition:r,drawId:o},method:N4,availableIndividualParticipantIds:a,availableIndividualParticipants:l,existingIndividualParticipantIds:c,existingIndividualParticipants:u,type:Qy},!1,!1,!0)}}return{}}function Die({tournamentParticipants:t=[],sourceStructuresComplete:e,possiblyDisablingAction:r,isWinRatioFedStructure:n,activeDrawPositions:o,positionAssignments:i,drawDefinition:s,drawPosition:a,structureId:c,structure:l,drawId:u,event:d}){var p,v,f,m,g;if(o.includes(a)||n&&!e)return{};const{sourceStructureIds:h,targetStructureIds:_}=((p=s.links)==null?void 0:p.reduce((y,S)=>{var T,E;const b=(T=S.source)==null?void 0:T.structureId,N=(E=S.target)==null?void 0:E.structureId;return y.sourceStructureIds.includes(b)||y.sourceStructureIds.push(b),y.targetStructureIds.includes(N)||y.targetStructureIds.push(N),y},{sourceStructureIds:[],targetStructureIds:[]}))||{},I=[];let P=((v=s.links)==null?void 0:v.filter(y=>{var S;return((S=y.target)==null?void 0:S.structureId)===l.structureId}))||[];for(const y of P){const S=(f=y==null?void 0:y.source)==null?void 0:f.structureId,{structure:T}=Te({structureId:S,drawDefinition:s}),E=(T==null?void 0:T.finishingPosition)===_i&&((h==null?void 0:h.length)!==1||(_==null?void 0:_.length)!==1),b={};if(E){const{matchUps:U}=ze({drawDefinition:s,structure:l,event:d}),{initialRoundNumber:A}=hs({drawPosition:a,matchUps:U}),M=(m=s.links)==null?void 0:m.find(D=>{var F;return((F=D.target)==null?void 0:F.structureId)===(l==null?void 0:l.structureId)&&D.target.roundNumber===A}),C=(g=M==null?void 0:M.source)==null?void 0:g.roundNumber;b.roundNumbers=[C]}const{completedMatchUps:N}=Lc({structureId:S,inContext:!0,matchUpFilters:b,drawDefinition:s}),w=i.map(U=>U.participantId).filter(Boolean);(N==null?void 0:N.filter(({matchUpType:U})=>(d==null?void 0:d.eventType)!==Tt||U===Tt).map(({winningSide:U,sides:A})=>A[1-(U-1)]).map(Xe).filter(U=>U&&!w.includes(U))).forEach(U=>{I.includes(U)||I.push(U)})}const O=t==null?void 0:t.filter(y=>I==null?void 0:I.includes(y.participantId));return O==null||O.forEach(y=>{const S=(s.entries||[]).find(T=>T.participantId===y.participantId);y.entryPosition=S==null?void 0:S.entryPosition}),I!=null&&I.length?{validLuckyLosersAction:{type:eS,method:w4,availableLuckyLosers:O,availableLuckyLoserParticipantIds:I,willDisableLinks:r,payload:{drawId:u,structureId:c,drawPosition:a}}}:{}}function jie({positionSourceStructureIds:t,unassignedParticipantIds:e,possiblyDisablingAction:r,provisionalPositioning:n,tournamentParticipants:o,isWinRatioFedStructure:i,positionAssignments:s,returnParticipants:a,appliedPolicies:c,drawDefinition:l,isByePosition:u,drawPosition:d,structureId:p,event:v}){var f,m,g;const{drawId:h}=l,_=[];let I,P,O=[];const y=(m=(f=c==null?void 0:c[qs])==null?void 0:f.validSeedPositions)==null?void 0:m.ignore;if(y||({unplacedSeedParticipantIds:I,unplacedSeedAssignments:P,unfilledPositions:O}=Ku({provisionalPositioning:n,randomize:!0,drawDefinition:l,structureId:p,event:v})),O!=null&&O.length||(O=s.filter(S=>!S.participantId&&!S.bye&&!S.qualifier).map(S=>S.drawPosition)),u||_.push({payload:{drawId:h,structureId:p,drawPosition:d,isPositionAction:!0},willDisableLinks:r,method:C4,type:rv}),i&&y){const S=s.map(w=>w.participantId).filter(Boolean),T={structureIds:t},{completedMatchUps:E}=cs({inContext:!0,matchUpFilters:T,drawDefinition:l}),b=Ve((g=(E||[]).filter(({matchUpType:w})=>(v==null?void 0:v.eventType)!==Tt||w===Tt))==null?void 0:g.map(({sides:w})=>w.map(Xe)).flat().filter(w=>w&&!S.includes(w))),N=a?o==null?void 0:o.filter(w=>b==null?void 0:b.includes(w.participantId)):void 0;return N==null||N.forEach(w=>{const $=(l.entries||[]).find(U=>U.participantId===w.participantId);w.entryPosition=$==null?void 0:$.entryPosition}),N!=null&&N.length&&_.push(_e({payload:{drawId:h,structureId:p,drawPosition:d},willDisableLinks:r,method:zy,type:la,availableParticipantIds:b,participantsAvailable:N})),{validAssignmentActions:_}}if(O.includes(d)||u){let S;if(P!=null&&P.length){const E=P.filter(b=>I==null?void 0:I.includes(b.participantId));E.sort(Rie),S=E.map(b=>b.participantId)}else S=e;const T=a?o==null?void 0:o.filter(E=>S.includes(E.participantId)):void 0;T!=null&&T.length&&_.push(_e({payload:{drawId:h,structureId:p,drawPosition:d},willDisableLinks:r,method:zy,type:la,availableParticipantIds:S,participantsAvailable:T}))}return{validAssignmentActions:_}}function Rie(t,e){return t.bye||Oa(t.seedValue)<Oa(e.seedValue)||t.seedValue&&!e.seedValue?-1:(t.seedNumber||0)-(e.seedNumber||0)}function Fie({drawPositionInitialRounds:t,tournamentParticipants:e,positionAssignments:r,returnParticipants:n,appliedPolicies:o,drawDefinition:i,drawPosition:s,structureId:a,drawId:c}){var l,u,d;const p=[],v=[],f=[],m=[],g=r.map(T=>T.participantId).filter(Boolean),h=o==null?void 0:o[po],_=!(h!=null&&h.disableRoundRestrictions)&&t[s],I=h==null?void 0:h.requireCompletedStructures,{sourceStructureIds:P,relevantLinks:O}=Km({targetRoundNumber:_,linkType:_o,drawDefinition:i,structureId:a})||{};P!=null&&P.length&&m.push(...P);const{sourceStructureIds:y,relevantLinks:S}=Km({targetRoundNumber:_,linkType:ho,drawDefinition:i,structureId:a})||{};y!=null&&y.length&&m.push(...y);for(const T of O){const E=(l=i.structures)==null?void 0:l.find(N=>N.structureId===T.source.structureId);if((E==null?void 0:E.stage)!==Ie)continue;const b=wi({structureId:T.source.structureId,drawDefinition:i});if(!I||b){const N=E.qualifyingRoundNumber,{matchUps:w}=ze({matchUpFilters:{roundNumbers:[N]},afterRecoveryTimes:!1,tournamentParticipants:e,hasWinningSide:!0,inContext:!0,structure:E});for(const $ of w){const U=$.sides.find(M=>(M==null?void 0:M.sideNumber)===$.winningSide),A=$.matchUpStatus===qe&&((u=$.sides)==null?void 0:u.find(({participantId:M})=>M));if(U||A){const{participantId:M,participant:C}=U||A||{};M&&!g.includes(M)&&(C&&n&&v.push(C),p.push(M))}}}}for(const T of S){const E=(d=i.structures)==null?void 0:d.find(N=>N.structureId===T.source.structureId);if((E==null?void 0:E.stage)!==Ie)continue;const b=wi({structureId:T.source.structureId,drawDefinition:i});if(!I||b){const{positionAssignments:N}=et({structure:E}),w=N.map($=>{var U;const A=$.participantId,M=(U=Vt({element:$,name:jo}).extension)==null?void 0:U.value;return M?{participantId:A,groupOrder:M==null?void 0:M.groupOrder}:{}}).filter(({groupOrder:$,participantId:U})=>$===1&&!g.includes(U)).map(({participantId:$})=>$);if(p.push(...w),n){const $=e.filter(({participantId:U})=>w.includes(U));v.push(...$)}}}return p.length&&f.push(_e({payload:{qualifyingParticipantId:void 0,drawPosition:s,structureId:a,drawId:c},method:b4,type:tv,qualifyingParticipantIds:p,qualifyingParticipants:n?v:void 0})),{validAssignmentActions:f,sourceStructureIds:m}}var Lie=Object.defineProperty,Vie=Object.defineProperties,xie=Object.getOwnPropertyDescriptors,I1=Object.getOwnPropertySymbols,Bie=Object.prototype.hasOwnProperty,kie=Object.prototype.propertyIsEnumerable,P1=(t,e,r)=>e in t?Lie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Gie=(t,e)=>{for(var r in e||(e={}))Bie.call(e,r)&&P1(t,r,e[r]);if(I1)for(var r of I1(e))kie.call(e,r)&&P1(t,r,e[r]);return t},Wie=(t,e)=>Vie(t,xie(e));function Hie({onlyAssignedPositions:t=!0,possiblyDisablingAction:e,tournamentParticipants:r,inactiveDrawPositions:n,activeDrawPositions:o,positionAssignments:i,returnParticipants:s,byeDrawPositions:a,drawDefinition:c,isByePosition:l,drawPosition:u,structureId:d,structure:p,drawId:v,event:f}){if(o.includes(u))return{};const m=b=>!t||b.participantId||b.qualifier||b.bye,g=n==null?void 0:n.filter(b=>b!==u&&!(l&&a.includes(b))),h=(i==null?void 0:i.filter(b=>m(b)&&(g==null?void 0:g.includes(b.drawPosition))))||[],_=h.map(({drawPosition:b})=>b),{matchUps:I}=ze({afterRecoveryTimes:!1,inContext:!0,drawDefinition:c,structure:p,event:f}),P=I.filter(({drawPositions:b})=>Gt(b,_)),O=Object.assign({},...P.map(b=>{var N;return(N=b.sides)==null?void 0:N.filter(({sourceDrawPositionRange:w})=>w).map(({drawPosition:w,sourceDrawPositionRange:$})=>({[w]:$}))}).flat()),y=h.map(b=>b.participantId).filter(Boolean),S=(r||[]).filter(b=>y.includes(b.participantId)),T=Object.assign({},...S.map(b=>({[b.participantId]:b}))),E=h.map(b=>{const N=T==null?void 0:T[b.participantId],w=O[b.drawPosition];return _e(Wie(Gie({},b),{participant:s?ue(N,!1,!0):void 0,sourceDrawPositionRange:w}))});return E.length?{validSwapAction:{payload:{drawId:v,structureId:d,drawPositions:[u]},willDisableLinks:e,method:$4,type:tS,availableAssignments:E}}:{}}function y1(t){const{policyDefinitions:e,tournamentParticipants:r=[],returnParticipants:n=!0,provisionalPositioning:o,tournamentRecord:i,drawDefinition:s,drawPosition:a,event:c}=t;if(!c)return{error:Le};if(!s)return{error:pe};if(!t.structureId)return{error:ar};let l=Te({structureId:t.structureId,drawDefinition:s});if(l.error)return l;const u=l.containingStructure||l.structure,d=u.structureId;if(l=Gc({tournamentRecord:i,drawDefinition:s,structureId:d}),a===void 0&&!l.isAdHoc)return{error:Ya};if(l.isAdHoc)return mm(t);if(l.error)return l;const{drawPositionInitialRounds:p,qualifyingDrawPositions:v,inactiveDrawPositions:f,activeDrawPositions:m,byeDrawPositions:g}=l,{appliedPolicies:h}=at({tournamentRecord:i,drawDefinition:s,structure:u,event:c});Object.assign(h,e||{});const{actionsPolicy:_,enabledStructures:I,actionsDisabled:P}=DE({actionType:Id,appliedPolicies:h,drawDefinition:s,structure:u}),O=(_==null?void 0:_.activePositionOverrides)||[],{sourceStructureIds:y}=Km({finishingPosition:na,targetRoundNumber:1,linkType:ho,drawDefinition:s,structureId:d})||{};let S;y!=null&&y.length&&(S=y.reduce((H,Q)=>wi({structureId:Q,drawDefinition:s})&&H,!0));const T=y.length,E=y.length&&!S,{policyActions:b}=RE({enabledStructures:I,drawDefinition:s,structure:u}),N=![Ie,de].includes(u.stage)||u.stageSequence!==1,{drawId:w}=s,$=[],{assignedPositions:U,positionAssignments:A}=Et({structure:u}),M=U.find(H=>H.drawPosition===a),C=A.map(H=>H.drawPosition);if(!(C!=null&&C.includes(a)))return{error:js};const{stage:D,stageSequence:F}=u,R=[D];D===$t&&R.push(de),D===de&&R.push($t);const G=is({entryStatuses:os,provisionalPositioning:o,drawDefinition:s,stageSequence:F,structureId:d,stages:R}),x=jd({drawDefinition:s,stages:R}),z=G.filter(H=>!x.includes(H.participantId)).map(H=>H.participantId),j=g.includes(a),V=v.includes(a),L=m.includes(a);if(P)return{info:"Actions Disabled for structure",isByePosition:j,isActiveDrawPosition:L,isDrawPosition:!0,hasPositionAssigned:!!M,validActions:[]};if(fr({policyActions:b,action:la})&&!L&&!E&&(!M||j)){const{validAssignmentActions:H}=jie({positionSourceStructureIds:y,unassignedParticipantIds:z,possiblyDisablingAction:N,isWinRatioFedStructure:T,tournamentParticipants:r,positionAssignments:A,activeDrawPositions:m,returnParticipants:n,appliedPolicies:h,drawDefinition:s,isByePosition:j,drawPosition:a,structureId:d,structure:u,event:c});H==null||H.forEach(Q=>$.push(Q))}if(fr({policyActions:b,action:tv})){const{validAssignmentActions:H}=Fie({drawPositionInitialRounds:p,isWinRatioFedStructure:T,tournamentParticipants:r,isQualifierPosition:V,positionAssignments:A,activeDrawPositions:m,returnParticipants:n,appliedPolicies:h,drawDefinition:s,drawPosition:a,structureId:d,structure:u,drawId:w});H==null||H.forEach(Q=>$.push(Q))}const{participantId:q}=M||{},k=q&&r.find(H=>H.participantId===q);if(M){fr({policyActions:b,action:Xy})&&!L&&($.push({type:Xy,method:qy,payload:{drawId:w,structureId:d,drawPosition:a},willDisableLinks:N}),j||$.push({type:Zy,method:T4,payload:{drawId:w,structureId:d,drawPosition:a},willDisableLinks:N}),fr({policyActions:b,action:rv})&&!j&&$.push({type:rv,method:qy,payload:{drawId:w,structureId:d,drawPosition:a,replaceWithBye:!0},willDisableLinks:N}));const H=u.stage===Ie||u.stage===de&&u.stageSequence===1;if(!j&&jE({activePositionOverrides:O,activeDrawPositions:m,action:ua})&&fr({policyActions:b,action:ua})&&zu({drawDefinition:s,structureId:d,drawPosition:a})&&H){const{seedAssignments:Q}=dn({drawDefinition:s,structure:u,event:c}),{seedNumber:K,seedValue:Y}=Q.find(J=>J.participantId===q)||{};$.push({type:ua,method:M4,participant:k,seedNumber:K,payload:{drawId:w,structureId:d,participantId:q,seedValue:Y}})}if(!j&&jE({activePositionOverrides:O,activeDrawPositions:m,action:Su})&&fr({policyActions:b,action:Su})&&zu({drawDefinition:s,structureId:d,drawPosition:a})&&H){const{seedAssignments:Q}=dn({drawDefinition:s,structure:u,event:c}),{seedNumber:K}=Q.find(Y=>Y.participantId===q)||{};$.push({type:Su,method:U4,participant:k,seedNumber:K,payload:{drawId:w,structureId:d,participantId:q}})}if(!j&&q){if(fr({policyActions:b,action:da})){const Q={type:da,method:Ky,participant:k,payload:{drawId:w,penaltyCode:void 0,penaltyType:void 0,participantIds:[],notes:void 0}};$.push(Q)}if(fr({policyActions:b,action:Ou})){const Q={type:Ou,method:A4,participant:k,payload:{participantId:q,otherName:void 0}};$.push(Q)}}if(fr({policyActions:b,action:tS})){const{validSwapAction:Q}=Hie({possiblyDisablingAction:N,tournamentParticipants:r,inactiveDrawPositions:f,activeDrawPositions:m,positionAssignments:A,returnParticipants:n,byeDrawPositions:g,drawDefinition:s,isByePosition:j,drawPosition:a,structureId:d,structure:u,drawId:w});Q&&$.push(Q)}}if(fr({policyActions:b,action:Jy})&&!E){const{validAlternatesAction:H}=uQ({possiblyDisablingAction:N,tournamentParticipants:r,positionAssignments:A,activeDrawPositions:m,returnParticipants:n,appliedPolicies:h,drawDefinition:s,drawPosition:a,validActions:$,structureId:d,structure:u,drawId:w,event:c});H&&$.push(H)}if(fr({policyActions:b,action:eS})&&!E){const{validLuckyLosersAction:H}=Die({sourceStructuresComplete:S,possiblyDisablingAction:N,isWinRatioFedStructure:T,tournamentParticipants:r,activeDrawPositions:m,positionAssignments:A,returnParticipants:n,appliedPolicies:h,drawDefinition:s,drawPosition:a,structureId:d,structure:u,drawId:w});H&&$.push(H)}if((k==null?void 0:k.participantType)===we&&fr({policyActions:b,action:Qy})){const{validModifyAssignedPairAction:H}=Mie({tournamentParticipants:r,positionAssignment:M,returnParticipants:n,drawDefinition:s,drawPosition:a,participant:k,structureId:d,structure:u,drawId:w,event:c});H&&$.push(H)}return{hasPositionAssigned:!!M,isActiveDrawPosition:L,isDrawPosition:!0,isByePosition:j,validActions:$}}function qie(t){return Object.assign(t,{inContext:!0}),cs(t)}function Yie(t){const{structure:e}=Te(t);return Object.assign(t,{structure:e,inContext:!0}),ze(t)}function zie(t){return Object.assign(t,{inContext:!0}),Nt(t)}const Kie={allPlayoffPositionsFilled:BO,isCompletedStructure:wi,getAllStructureMatchUps:ze,getStructureMatchUps:Lc,allStructureMatchUps:Yie,allDrawMatchUps:zie,drawMatchUps:qie,getEliminationDrawSize:Lm,getParticipantIdMatchUps:h1,getParticipantIdFinishingPositions:_1,getEligibleVoluntaryConsolationParticipants:g1,structureActions:m6,matchUpActions:mm,positionActions:y1,getStructureSeedAssignments:dn,getNextUnfilledDrawPositions:Cie,getExitProfiles:Df,getValidGroupSizes:Uv,getSeedingThresholds:C6,getSeedBlocks:qu,getSeedGroups:Yu,getMatchUpContextIds:UH,getMatchUpParticipantIds:Rf,getMatchUpScheduleDetails:bf,generateTieMatchUpScore:Dc,matchUpDuration:aP,credits:_d};var Qie=Object.defineProperty,S1=Object.getOwnPropertySymbols,Jie=Object.prototype.hasOwnProperty,Zie=Object.prototype.propertyIsEnumerable,O1=(t,e,r)=>e in t?Qie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xie=(t,e)=>{for(var r in e||(e={}))Jie.call(e,r)&&O1(t,r,e[r]);if(S1)for(var r of S1(e))Zie.call(e,r)&&O1(t,r,e[r]);return t};function b1({validation:t=!0,tournamentRecord:e,drawDefinition:r,participantId:n,structureId:o,seedValue:i,event:s}){if(!r)return{error:pe};if(!o)return{error:ar};const{structure:a}=Te({drawDefinition:r,structureId:o});if(!a)return{error:Br};if(!(!t||Ot(i)||[void 0,""].includes(i)||typeof i=="string"&&i.split("-").every(p=>Ot(p)&&p>0)))return{error:Z};const{seedAssignments:l}=dn({drawDefinition:r,structure:a,event:s}),u=l.map(p=>p.seedNumber),d=l.find(p=>p.participantId===n);if(d){const p=typeof i=="string"?i.includes("-")&&i.split("-").map(v=>parseInt(v)).join("-")||i>0&&parseInt(i)||"":i>0&&parseInt(i)||"";d.seedValue=p}else{const p=Math.max(0,...u)+1;a.seedAssignments.push({seedNumber:p,seedValue:i,participantId:n})}return VP({tournamentId:e==null?void 0:e.tournamentId,structureIds:[o],eventId:s==null?void 0:s.eventId,drawDefinition:r,structure:a}),Xie({},B)}var ese=Object.defineProperty,T1=Object.getOwnPropertySymbols,tse=Object.prototype.hasOwnProperty,rse=Object.prototype.propertyIsEnumerable,E1=(t,e,r)=>e in t?ese(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,nse=(t,e)=>{for(var r in e||(e={}))tse.call(e,r)&&E1(t,r,e[r]);if(T1)for(var r of T1(e))rse.call(e,r)&&E1(t,r,e[r]);return t};function ose({autoEntryPositions:t=!0,drawDefinition:e,participantId:r,stages:n}){return e?r?jd({drawDefinition:e,stages:n}).includes(r)?{error:Vs}:(e!=null&&e.entries&&(e.entries=e.entries.filter(s=>s.participantId!==r)),t&&(e.entries=zr({entries:e.entries})),Je({drawDefinition:e}),nse({},B)):{error:yt}:{error:pe}}const ise={setStageAlternatesCount:_ee,setStageWildcardsCount:Iee,setStageQualifiersCount:$m,modifySeedAssignment:b1,setStageDrawSize:ul,addDrawEntries:fA,addDrawEntry:Gm,removeEntry:ose,assignSeed:Ps},sse={generateQualifyingLink:Ua},ase=()=>({matchUpType:void 0,drawName:void 0,drawId:void 0,structures:[],entries:[],links:[]}),cse=["drawId","structures"];function w1(t,e=!0){return t?typeof t!="object"?{error:xn}:t.drawId?lse(t)?e?ue(t):t:{error:ji}:{error:wr,method:"setState"}:{error:pe}}function lse(t){const e=Object.keys(t);return cse.reduce((r,n)=>e.includes(n)?r:!1,!0)}function $1({drawId:t=We(),matchUpType:e,drawType:r}={}){const n=ase();return Object.assign(n,{drawId:t,drawType:r,matchUpType:e})}var use=Object.defineProperty,dse=Object.defineProperties,pse=Object.getOwnPropertyDescriptors,N1=Object.getOwnPropertySymbols,fse=Object.prototype.hasOwnProperty,vse=Object.prototype.propertyIsEnumerable,A1=(t,e,r)=>e in t?use(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xd=(t,e)=>{for(var r in e||(e={}))fse.call(e,r)&&A1(t,r,e[r]);if(N1)for(var r of N1(e))vse.call(e,r)&&A1(t,r,e[r]);return t},U1=(t,e)=>dse(t,pse(e));let Kr,C1=[];const mse=function(){const t={getState:({convertExtensions:o,removeExtensions:i}={})=>({drawDefinition:ue(Kr,o,!1,i)}),version:()=>so(),reset:()=>(Kr=void 0,xd({},B)),newDrawDefinition:({drawId:o,drawType:i}={})=>(Kr=$1({drawId:o,drawType:i}),Object.assign({drawId:Kr.drawId,drawDefinition:ue(Kr)},B)),setDrawDescription:({description:o}={})=>Kr?(Kr.description=o,Je({drawDefinition:Kr}),Object.assign({drawId:Kr.drawId},B)):{error:pe}};function e(o){return o!=null&&o.error?(t.error=o.error,t.success=!1):(t.error=void 0,t.success=!0,Kr=o,t.drawId=o.drawId),t}return r([sse,Kie,wy,ise,Tie,Pie,koe,lne]),t.devContext=o=>(xs(o),t),t.setParticipants=(o=[])=>(C1=o,t),t.setState=(o,i,s)=>{Fi(i,s);const a=w1(o);return e(a)},t;function r(o){o.forEach(i=>{Object.keys(i).forEach(s=>{t[s]=a=>{if(Ft())return n({params:a,governor:i,governorMethod:s});try{return n({params:a,governor:i,governorMethod:s})}catch(c){const l=c.toString();console.log("ERROR",{params:JSON.stringify(a),drawId:Kr==null?void 0:Kr.drawId,method:s,error:l})}}})})}function n({params:o,governor:i,governorMethod:s}){delete t.success,delete t.error;const a=(o==null?void 0:o.rollbackOnError)&&ue(Kr,!1,!0),c={};o=U1(xd(xd({},o),c),{tournamentParticipants:C1,drawDefinition:Kr});const l=i[s](o);if(l!=null&&l.error)return a&&w1(a),U1(xd({},l),{rolledBack:!!a});const u=(l==null?void 0:l.success)&&(o==null?void 0:o.delayNotify)!==!0&&(o==null?void 0:o.doNotNotify)!==!0;return u&&bi(),(u||!(l!=null&&l.success)||o!=null&&o.doNotNotify)&&ii(),l}}();var gse=Object.defineProperty,M1=Object.getOwnPropertySymbols,hse=Object.prototype.hasOwnProperty,_se=Object.prototype.propertyIsEnumerable,D1=(t,e,r)=>e in t?gse(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ise=(t,e)=>{for(var r in e||(e={}))hse.call(e,r)&&D1(t,r,e[r]);if(M1)for(var r of M1(e))_se.call(e,r)&&D1(t,r,e[r]);return t};function Fa({tieFormat:t,orderMap:e}){const r=pn(t);return r.collectionDefinitions.forEach(n=>{const o=e[n.collectionId];o&&(n.collectionOrder=o)}),r.collectionDefinitions.sort((n,o)=>n.collectionOrder-o.collectionOrder),r}function j1({tournamentRecord:t,drawDefinition:e,structureId:r,matchUpId:n,orderMap:o,eventId:i,matchUp:s,event:a}){if(typeof o!="object")return{error:Z,orderMap:o};if(i&&(a!=null&&a.tieFormat))R1({tournamentRecord:t,event:a,orderMap:o});else if(n){const c=e&&nt({drawDefinition:e,matchUpId:n});if(c!=null&&c.error)return c;if(s=c.matchUp,!s)return{error:$r};s!=null&&s.tieFormat&&(s.tieFormat=Fa({tieFormat:s.tieFormat,orderMap:o}),Qe({tournamentId:t==null?void 0:t.tournamentId,eventId:a==null?void 0:a.eventId,drawDefinition:e,matchUp:s}))}else if(r){const c=Te({drawDefinition:e,structureId:r});if(c.error)return c;const l=c.structure;if(l!=null&&l.tieFormat)l.tieFormat=Fa({tieFormat:l.tieFormat,orderMap:o}),F1({eventId:a==null?void 0:a.eventId,tournamentRecord:t,drawDefinition:e,structure:l,orderMap:o}),Je({drawDefinition:e,structureIds:[l.structureId]});else if(e.tieFormat)Qm({structureIds:[r],tournamentRecord:t,drawDefinition:e,orderMap:o,event:a});else if(a!=null&&a.tieFormat)R1({structureIds:[r],tournamentRecord:t,orderMap:o,event:a});else return{error:Yt}}else if(e!=null&&e.tieFormat)Qm({tournamentRecord:t,drawDefinition:e,orderMap:o,event:a});else return{error:Yt};return Ise({},B)}function R1({tournamentRecord:t,structureIds:e,orderMap:r,event:n}){const o=Fa({tieFormat:n.tieFormat,orderMap:r});e!=null&&e.length||(n.tieFormat=o);for(const i of n.drawDefinitions||[])Qm({tournamentRecord:t,drawDefinition:i,structureIds:e,orderMap:r,event:n})}function Qm({tournamentRecord:t,drawDefinition:e,structureIds:r,orderMap:n,event:o}){const i=e.tieFormat||o.tieFormat,s=Fa({tieFormat:i,orderMap:n});r!=null&&r.length||(e.tieFormat=s);const a=[];for(const c of e.structures||[])r!=null&&r.length&&!r.includes(c.structureId)||((c.tieFormat||r!=null&&r.includes(c.structureId))&&(c.tieFormat=Fa({tieFormat:c.tieFormat||e.tieFormat||o.tieFormat,orderMap:n})),F1({eventId:o==null?void 0:o.eventId,tournamentRecord:t,drawDefinition:e,structure:c,orderMap:n}),a.push(c.structureId));Je({drawDefinition:e,structureIds:a})}function F1({tournamentRecord:t,drawDefinition:e,structure:r,orderMap:n,eventId:o}){var i;const s=(i=ze({matchUpFilters:{matchUpTypes:[He]},structure:r}))==null?void 0:i.matchUps;for(const a of s)a.tieFormat&&(a.tieFormat=Fa({tieFormat:a.tieFormat,orderMap:n}),Qe({tournamentId:t==null?void 0:t.tournamentId,drawDefinition:e,eventId:o,matchUp:a}))}var Pse=Object.defineProperty,yse=Object.defineProperties,Sse=Object.getOwnPropertyDescriptors,L1=Object.getOwnPropertySymbols,Ose=Object.prototype.hasOwnProperty,bse=Object.prototype.propertyIsEnumerable,V1=(t,e,r)=>e in t?Pse(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tse=(t,e)=>{for(var r in e||(e={}))Ose.call(e,r)&&V1(t,r,e[r]);if(L1)for(var r of L1(e))bse.call(e,r)&&V1(t,r,e[r]);return t},Ese=(t,e)=>yse(t,Sse(e));function La({drawDefinition:t,structureId:e,matchUpId:r,structure:n,matchUp:o,eventId:i,event:s}){let a;if(e=(n==null?void 0:n.structureId)||e,r=(o==null?void 0:o.matchUpId)||r,(r||e)&&!t)return{error:pe};if(i&&s)a=$o(s);else if(r){if(!o||!n){const c=nt({drawDefinition:t,matchUpId:r});if(c.error)return c;n||(n=c.structure),o||(o=c.matchUp)}a=Ha({item:o,drawDefinition:t,structure:n,event:s})||Ha({item:n,drawDefinition:t,structure:n,event:s})||$o(t)||$o(s)}else if(t&&e){if(!n){const c=Te({drawDefinition:t,structureId:e});if(c.error)return c;n=c==null?void 0:c.structure}a=Ha({item:n,drawDefinition:t,structure:n,event:s})||$o(t)||$o(s)}else a=$o(t)||$o(s);return a?Ese(Tse({},B),{tieFormat:a,matchUp:o,structure:n}):{error:$l}}function Bd({drawDefinition:t,auditData:e}){const{extension:r}=Or({name:Wi,element:t}),n={name:Wi,value:Array.isArray(r==null?void 0:r.value)?r.value.concat(e):[e]};tt({element:t,extension:n})}var wse=Object.defineProperty,$se=Object.defineProperties,Nse=Object.getOwnPropertyDescriptors,kd=Object.getOwnPropertySymbols,x1=Object.prototype.hasOwnProperty,B1=Object.prototype.propertyIsEnumerable,k1=(t,e,r)=>e in t?wse(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ase=(t,e)=>{for(var r in e||(e={}))x1.call(e,r)&&k1(t,r,e[r]);if(kd)for(var r of kd(e))B1.call(e,r)&&k1(t,r,e[r]);return t},Use=(t,e)=>$se(t,Nse(e)),Cse=(t,e)=>{var r={};for(var n in t)x1.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&kd)for(var n of kd(t))e.indexOf(n)<0&&B1.call(t,n)&&(r[n]=t[n]);return r};function Jm({updateInProgressMatchUps:t=!0,tieFormatComparison:e,tournamentRecord:r,drawDefinition:n,tieFormatName:o,collectionId:i,structureId:s,matchUpId:a,eventId:c,matchUp:l,event:u}){var d,p,v,f,m;let g=!l&&La({drawDefinition:n,structureId:s,matchUpId:a,eventId:c,event:u});if(g.error)return g;const{structure:h}=g;l=l||g.matchUp;const _=g.tieFormat,I=pn(_);if(g=ur({tieFormat:I}),g.error)return g;const P=(d=I==null?void 0:I.collectionDefinitions)==null?void 0:d.find(A=>A.collectionId===i);if(!P)return{error:Yt,collectionId:i};const O="removeCollectionDefinition";I.collectionDefinitions=I.collectionDefinitions.filter(A=>A.collectionId!==i),P.collectionGroupNumber&&(I.collectionDefinitions=I.collectionDefinitions.map(A=>Cse(A,["collectionGroupNumber"])),I.collectionGroups=I.collectionGroups.filter(({groupNumber:A})=>A!==P.collectionGroupNumber));const{aggregateValue:y,valueGoal:S}=pa(I);I.winCriteria=_e({aggregateValue:y,valueGoal:S});const T=_.winCriteria.valueGoal,E=_.winCriteria.aggregateValue;(T&&T!==S||y&&!E)&&(o?I.tieFormatName=o:delete I.tieFormatName);let b=[];a&&l?b=[l]:s&&h?b=(p=ze({matchUpFilters:{matchUpTypes:[He]},structure:h}))==null?void 0:p.matchUps:n?b=(v=Dr({matchUpFilters:{matchUpTypes:[He]},drawDefinition:n}))==null?void 0:v.matchUps:u&&(b=(f=Oi({matchUpFilters:{matchUpTypes:[He]},drawDefinition:n}))==null?void 0:f.matchUps);const N=(b||[]).filter(A=>{var M;const D=A.tieMatchUps.filter(R=>R.collectionId===i).some(Dt),F=e&&A.tieFormat?(M=Au({descendant:A.tieFormat,ancestor:I}))==null?void 0:M.different:!1;return t&&!D||!A.winningSide&&A.matchUpStatus!==St&&(t||A.matchUpStatus!==Xr&&!Dt(A)&&!F)});if(!N.length)return{error:Ja};if(a&&l&&t){const A=l.tieMatchUps.filter(M=>M.collectionId===i);for(const M of A){let C=Kc({matchUpId:M.matchUpId,tieMatchUpId:l.matchUpId,winningSide:void 0,removeScore:!0,tournamentRecord:r,drawDefinition:n,event:u});if(C.error||(C=nt({drawDefinition:n,matchUpId:a}),C.error))return C;l=C.matchUp}}const w=[];for(const A of N){for(const M of(A==null?void 0:A.sides)||[])M.lineUp=(M.lineUp||[]).map(C=>({participantId:C.participantId,collectionAssignments:((C==null?void 0:C.collectionAssignments)||[]).filter(D=>D.collectionId!==i)}));if(A.tieMatchUps=(A.tieMatchUps||[]).filter(M=>{const C=M.collectionId===i;return C&&w.push(M.matchUpId),!C}),A.tieFormat&&(A.tieFormat=pn(I)),t){const M=Qn({matchUpId:A.matchUpId,exitWhenNoValues:!0,tournamentRecord:r,drawDefinition:n,event:u});if(M.error)return M}Qe({tournamentId:r==null?void 0:r.tournamentId,eventId:u==null?void 0:u.eventId,drawDefinition:n,context:O,matchUp:A})}w.length&&yi({tournamentId:r==null?void 0:r.tournamentId,matchUpIds:w,eventId:u==null?void 0:u.eventId,drawDefinition:n});const $=_e(I);if(g=ur({tieFormat:$}),g.error)return g;if(c)u.tieFormat=$;else if(a)l.tieFormat=$;else if(h)h.tieFormat=$;else if(n)n.tieFormat=$;else if(!l||!n)return{error:pe};Je({drawDefinition:n,eventId:u==null?void 0:u.eventId});const{appliedPolicies:U}=at({tournamentRecord:r});if((m=U==null?void 0:U.audit)!=null&&m[Wi]){const A=_e({drawId:n==null?void 0:n.drawId,action:O,collectionId:i,structureId:s,matchUpId:a,eventId:c});Bd({drawDefinition:n,auditData:A})}return Use(Ase({},B),{tieFormat:$,targetMatchUps:N,deletedMatchUpIds:w})}function Gd({matchUp:t,updateInProgressMatchUps:e}){return!t.winningSide&&![Lt].includes(t.matchUpStatus)&&(e||t.matchUpStatus!==Xr&&!Dt(t))}var Mse=Object.defineProperty,Dse=Object.defineProperties,jse=Object.getOwnPropertyDescriptors,G1=Object.getOwnPropertySymbols,Rse=Object.prototype.hasOwnProperty,Fse=Object.prototype.propertyIsEnumerable,W1=(t,e,r)=>e in t?Mse(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lse=(t,e)=>{for(var r in e||(e={}))Rse.call(e,r)&&W1(t,r,e[r]);if(G1)for(var r of G1(e))Fse.call(e,r)&&W1(t,r,e[r]);return t},Vse=(t,e)=>Dse(t,jse(e));function Zm(t,e){const r=Object.keys(t);return jt(r,Object.keys(e)).length===r.length}function xse({updateInProgressMatchUps:t,tournamentRecord:e,drawDefinition:r,structure:n,tieFormat:o,eventId:i,matchUp:s,event:a}){var c;const l="updateTieFormat";let u=0,d=0;const p=o==null?void 0:o.collectionDefinitions.reduce((_,I)=>(_[I.collectionId]=(_[I.collectionId]||0)+I.matchUpCount,_),{}),v=({tieFormat:_})=>{const I=_==null?void 0:_.collectionDefinitions.reduce((P,O)=>(P[O.collectionId]=(P[O.collectionId]||0)+O.matchUpCount,P),{});return Zm(p,I)},{drawDefaultTieFormat:f,eventDefaultTieFormat:m}=La({drawDefinition:r,event:a});if(a&&i){for(const _ of a.drawDefinitions||[])g({drawDefinition:_});a.tieFormat=o,d+=1}else if(s){if(!s.tieMatchUps)return W({result:{error:Gr},stack:l});const _=mr((c=s.tieMatchUps)==null?void 0:c.map(({collectionId:I})=>I));if(Zm(p,_))if(Gd({matchUp:s,updateInProgressMatchUps:t}))s.tieFormat=o,d+=1;else return W({result:{error:Nh},info:"matchUp is IN_PROGRESS or COMPLETE"});else return W({context:{collectionMap:p,matchUpMap:_},result:{error:ni},info:"on matchUp",stack:l});Qe({tournamentId:e==null?void 0:e.tournamentId,eventId:a==null?void 0:a.eventId,context:l,drawDefinition:r,matchUp:s})}else if(n){const I=h({inheritedTieFormat:f||m,structure:n});u+=I,n.tieFormat=o,d+=1,Je({structureIds:[n.structureId],eventId:a==null?void 0:a.eventId,drawDefinition:r})}else if(r)g({drawDefinition:r}),r.tieFormat=o,d+=1;else return{error:pe};return Vse(Lse({},B),{modifiedCount:d,modifiedStructuresCount:u,tieFormat:o});function g({drawDefinition:_}){const I=[];for(const P of _.structures||[]){if(P.tieFormat)continue;const y=h({inheritedTieFormat:m,structure:P});y&&(u+=y,I.push(P.structureId))}return Je({structureIds:I,eventId:a==null?void 0:a.eventId,drawDefinition:_}),I.length}function h({inheritedTieFormat:_,structure:I}){var P,O;let y=0;const S=((P=ze({matchUpFilters:{matchUpTypes:[He]},structure:I}))==null?void 0:P.matchUps)||[];for(const T of S){let E=!1;const b=mr((O=T.tieMatchUps)==null?void 0:O.map(({collectionId:N})=>N));if(Zm(p,b))T.tieFormat&&v(T)&&Gd({matchUp:T,updateInProgressMatchUps:t})&&(T.tieFormat=pn(o),E=!0);else if(_)T.tieFormat=_,E=!0;else return W({result:{error:$l},stack:l});E&&(y+=1,Qe({tournamentId:e==null?void 0:e.tournamentId,drawDefinition:r,context:l,eventId:i,matchUp:T}))}return y}}var H1=Object.getOwnPropertySymbols,Bse=Object.prototype.hasOwnProperty,kse=Object.prototype.propertyIsEnumerable,Gse=(t,e)=>{var r={};for(var n in t)Bse.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&H1)for(var n of H1(t))e.indexOf(n)<0&&kse.call(t,n)&&(r[n]=t[n]);return r};function Xm({updateInProgressMatchUps:t=!1,tournamentRecord:e,collectionOrder:r,collectionName:n,drawDefinition:o,matchUpFormat:i,tieFormatName:s,matchUpCount:a,collectionId:c,matchUpType:l,structureId:u,matchUpId:d,category:p,eventId:v,gender:f,event:m,collectionValueProfile:g,collectionValue:h,matchUpValue:_,scoreValue:I,setValue:P}){var O;if(i&&!xr(i))return{error:Z};if(n&&typeof n!="string")return{error:Z};if(f&&!Object.values(AP).includes(f))return{error:Z};if(p&&typeof p!="object")return{error:Z};const y="modifyCollectionDefinition",S={collectionValueProfile:g,collectionValue:h,matchUpValue:_,scoreValue:I,setValue:P};if(!Object.values(S).filter(Boolean).length&&!r&&!n&&!a&&!i)return W({result:{error:Oe},stack:y});if(Object.values(S).filter(Boolean).length>1)return W({result:{error:Z,info:"Only one value assignment allowed per collectionDefinition"},stack:y});let T=La({drawDefinition:o,structureId:u,matchUpId:d,eventId:v,event:m});if(T.error)return W({result:T,stack:y});const{matchUp:E,structure:b,tieFormat:N}=T,w=pn(N),$=w.collectionDefinitions.find(R=>R.collectionId===c);if(!$)return W({result:{error:Yt},stack:y});const U=h||_||I||P;if(U||g){if(U){if(!ut(U))return{error:Z,value:U}}else if(g){const R=d_({matchUpCount:$.matchUpCount,collectionValueProfile:g});if(R.errors)return W({result:{error:Z,info:R.errors},stack:y})}$.collectionValue=void 0,$.matchUpValue=void 0,$.scoreValue=void 0,$.setValue=void 0,Object.assign($,S)}if((I||P)&&$.collectionGroupNumber){const R=$.collectionGroupNumber;w.collectionDefinitions=w.collectionDefinitions.map(G=>{const x=G,{collectionGroupNumber:z}=x,j=Gse(x,["collectionGroupNumber"]);return z===R?j:G}),w.collectionGroups=w.collectionGroups.filter(({groupNumber:G})=>G!==R)}const{aggregateValue:A,valueGoal:M}=pa(w);w.winCriteria=_e({aggregateValue:A,valueGoal:M});const C=N.winCriteria.valueGoal,D=N.winCriteria.aggregateValue;(C&&C!==M||A&&!D)&&delete w.tieFormatName,s&&(w.tieFormatName=s),r&&($.collectionOrder=r),n&&($.collectionName=n),i&&($.matchUpFormat=i),l&&($.matchUpType=l),p&&($.category=p),f&&($.gender=f);const F=_e(w);if(T=ur({tieFormat:F}),T.error)return W({result:T,stack:y});if(T=xse({tieFormat:F,updateInProgressMatchUps:t,tournamentRecord:e,drawDefinition:o,structureId:u,structure:b,eventId:v,matchUp:E,event:m}),!T.error){const{appliedPolicies:R}=at({tournamentRecord:e});if((O=R==null?void 0:R.audit)!=null&&O[Wi]){const G=_e({drawId:o==null?void 0:o.drawId,collectionDefinition:$,action:y,structureId:u,matchUpId:d,eventId:v});Bd({drawDefinition:o,auditData:G})}}return W({result:T,stack:y})}var Wse=Object.defineProperty,Hse=Object.defineProperties,qse=Object.getOwnPropertyDescriptors,q1=Object.getOwnPropertySymbols,Yse=Object.prototype.hasOwnProperty,zse=Object.prototype.propertyIsEnumerable,Y1=(t,e,r)=>e in t?Wse(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kse=(t,e)=>{for(var r in e||(e={}))Yse.call(e,r)&&Y1(t,r,e[r]);if(q1)for(var r of q1(e))zse.call(e,r)&&Y1(t,r,e[r]);return t},Qse=(t,e)=>Hse(t,qse(e));function eg({updateInProgressMatchUps:t=!0,collectionDefinition:e,tournamentRecord:r,drawDefinition:n,tieFormatName:o,structureId:i,matchUpId:s,matchUp:a,eventId:c,uuids:l,event:u}){var d;const{valid:p,errors:v}=u_({collectionDefinition:e});if(!p)return{error:Z,errors:v};const f="addCollectionDefinition";let m=!a&&La({drawDefinition:n,structureId:i,matchUpId:s,eventId:c,event:u});if(m!=null&&m.error)return{error:m.error};const{structure:g}=m;a=a||m.matchUp;const h=m.tieFormat,_=pn(h);if(m=ur({tieFormat:_}),m!=null&&m.error)return{error:m.error};if(!e.collectionId)e.collectionId=We();else if(_.collectionDefinitions.map(({collectionId:$})=>$).includes(e.collectionId))return{collectionId:e.collectionId,error:oL};_.collectionDefinitions.push(e),_.collectionDefinitions.sort((w,$)=>(w.collectionOrder||0)-($.collectionOrder||0)).forEach((w,$)=>w.collectionOrder=$+1);const{aggregateValue:I,valueGoal:P}=pa(_);_.winCriteria=_e({aggregateValue:I,valueGoal:P});const O=h.winCriteria.valueGoal,y=h.winCriteria.aggregateValue;(O&&O!==P||I&&!y)&&(o?_.tieFormatName=o:delete _.tieFormatName);const S=[],T=[];let E=[];const b=_e(_);if(m=ur({tieFormat:b}),m!=null&&m.error)return{error:m.error};if(c){u.tieFormat=b;for(const w of u.drawDefinitions||[])if(!w.tieFormat)for(const $ of w.structures||[]){if($.tieFormat)continue;const U=tg({updateInProgressMatchUps:t,collectionDefinition:e,structure:$,uuids:l});T.push(...U.newMatchUps),E.push(...U.targetMatchUps),S.push($.structureId)}Wd({structureIds:S,modifiedMatchUps:E,eventId:u==null?void 0:u.eventId,tournamentRecord:r,drawDefinition:n,addedMatchUps:T,stack:f})}else if(i&&g){g.tieFormat=b;const w=tg({updateInProgressMatchUps:t,collectionDefinition:e,structure:g,uuids:l});T.push(...w.newMatchUps),E=w.targetMatchUps,Wd({modifiedMatchUps:E,structureIds:[i],eventId:u==null?void 0:u.eventId,tournamentRecord:r,drawDefinition:n,addedMatchUps:T,stack:f})}else if(s&&a){if(!Gd({matchUp:a,updateInProgressMatchUps:t}))return{error:Nh};a.tieFormat=b;const w=Nd({collectionDefinition:e,uuids:l});Array.isArray(a.tieMatchUps)||(a.tieMatchUps=[]),a.tieMatchUps.push(...w),T.push(...w),Wd({modifiedMatchUps:[a],eventId:u==null?void 0:u.eventId,tournamentRecord:r,drawDefinition:n,addedMatchUps:T,stack:f})}else if(n){n.tieFormat=b;for(const w of n.structures||[]){const $=tg({updateInProgressMatchUps:t,collectionDefinition:e,structure:w,uuids:l});S.push(i),T.push(...$.newMatchUps),E.push(...$.targetMatchUps)}Wd({structureIds:S,modifiedMatchUps:E,eventId:u==null?void 0:u.eventId,tournamentRecord:r,drawDefinition:n,addedMatchUps:T,stack:f})}else return{error:pe};const{appliedPolicies:N}=at({tournamentRecord:r});if((d=N==null?void 0:N.audit)!=null&&d[Wi]){const w=_e({drawId:n==null?void 0:n.drawId,collectionDefinition:e,action:f,structureId:i,matchUpId:s,eventId:c});Bd({drawDefinition:n,auditData:w})}return Qse(Kse({},B),{tieFormat:b,targetMatchUps:E,addedMatchUps:T})}function tg({updateInProgressMatchUps:t,collectionDefinition:e,structure:r,uuids:n}){var o;const i=[],a=((o=ze({matchUpFilters:{matchUpTypes:[He]},structure:r}))==null?void 0:o.matchUps).filter(c=>Gd({matchUp:c,updateInProgressMatchUps:t})&&!c.tieFormat);for(const c of a){const l=Nd({collectionDefinition:e,uuids:n});Array.isArray(c.tieMatchUps)||(c.tieMatchUps=[]),c.tieMatchUps.push(...l),i.push(...l)}return{newMatchUps:i,targetMatchUps:a}}function Wd({modifiedStructureIds:t,tournamentRecord:e,modifiedMatchUps:r,drawDefinition:n,addedMatchUps:o,eventId:i,stack:s}){Pi({tournamentId:e==null?void 0:e.tournamentId,matchUps:o,drawDefinition:n,eventId:i}),r==null||r.forEach(a=>{Qe({tournamentId:e==null?void 0:e.tournamentId,drawDefinition:n,context:s,matchUp:a,eventId:i})}),Je({structureIds:t,drawDefinition:n,eventId:i})}var Jse=Object.defineProperty,Zse=Object.defineProperties,Xse=Object.getOwnPropertyDescriptors,z1=Object.getOwnPropertySymbols,eae=Object.prototype.hasOwnProperty,tae=Object.prototype.propertyIsEnumerable,K1=(t,e,r)=>e in t?Jse(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,rae=(t,e)=>{for(var r in e||(e={}))eae.call(e,r)&&K1(t,r,e[r]);if(z1)for(var r of z1(e))tae.call(e,r)&&K1(t,r,e[r]);return t},nae=(t,e)=>Zse(t,Xse(e));function Q1({tournamentRecord:t,drawDefinition:e,structureId:r,matchUpId:n,structure:o,eventId:i,drawId:s,event:a}){var c,l,u,d,p;if(!t)return{error:ee};if(!s&&!a&&!r&&!n)return W({result:{error:Oe},stack:"getTieFormat"});i&&!a&&(a=(c=t.events)==null?void 0:c.find(_=>_.eventId===i));const v=il({tournamentRecord:t,drawDefinition:e,matchUpId:n,drawId:s,event:a});if(n&&(v!=null&&v.error))return v;if(!e&&(v!=null&&v.drawDefinition)&&(e=v==null?void 0:v.drawDefinition),o=o||(v==null?void 0:v.structure),!o&&r&&!n){if(!e)return{error:wr};const _=Te({drawDefinition:e,structureId:r});if(_.error)return _;o=_.structure}const f=((o==null?void 0:o.tieFormat)||(o==null?void 0:o.tieFormatId))&&((l=Xt({structure:o,drawDefinition:e,event:a}))==null?void 0:l.tieFormat),m=((e==null?void 0:e.tieFormat)||(e==null?void 0:e.tieFormatId))&&((u=Xt({drawDefinition:e,event:a}))==null?void 0:u.tieFormat),g=(d=Xt({event:a}))==null?void 0:d.tieFormat,h=(p=Xt({matchUp:v==null?void 0:v.matchUp,drawDefinition:e,structure:o,event:a}))==null?void 0:p.tieFormat;return nae(rae({},B),{structureDefaultTieFormat:f,eventDefaultTieFormat:g,drawDefaultTieFormat:m,tieFormat:h})}function oae({updateInProgressMatchUps:t,tournamentRecord:e,drawDefinition:r,targetMatchUps:n,tieFormat:o,event:i}){for(const s of n){const a=!!s.tieFormat;a&&(s.tieFormat=pn(o));let c;if(t){const l=Qn({matchUpId:s.matchUpId,exitWhenNoValues:!0,tournamentRecord:e,drawDefinition:r,event:i});if(l.error)return l;c=l.score}a&&!c&&Qe({tournamentId:e==null?void 0:e.tournamentId,context:"updateTargetTeamMatchUps",eventId:i==null?void 0:i.eventId,matchUp:s,drawDefinition:r})}}function iae({updateInProgressMatchUps:t,drawDefinition:e,structureId:r,structure:n,matchUpId:o,matchUp:i}){var s,a;let c=[];return o&&i?c=[i]:r&&n?c=(s=ze({matchUpFilters:{matchUpTypes:[He]},structure:n}))==null?void 0:s.matchUps:e&&(c=(a=Dr({matchUpFilters:{matchUpTypes:[He]},drawDefinition:e}))==null?void 0:a.matchUps),{targetMatchUps:c.filter(u=>!u.winningSide&&u.matchUpStatus!==St&&(t||u.matchUpStatus!==Xr&&!Dt(u)))}}var sae=Object.defineProperty,J1=Object.getOwnPropertySymbols,aae=Object.prototype.hasOwnProperty,cae=Object.prototype.propertyIsEnumerable,Z1=(t,e,r)=>e in t?sae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lae=(t,e)=>{for(var r in e||(e={}))aae.call(e,r)&&Z1(t,r,e[r]);if(J1)for(var r of J1(e))cae.call(e,r)&&Z1(t,r,e[r]);return t};function X1({updateInProgressMatchUps:t,originalValueGoal:e,tournamentRecord:r,wasAggregateValue:n,tieFormatName:o,drawDefinition:i,structureId:s,structure:a,tieFormat:c,matchUpId:l,matchUp:u,eventId:d,event:p}){const{aggregateValue:v,valueGoal:f}=pa(c);c.winCriteria=_e({aggregateValue:v,valueGoal:f}),(e&&e!==f||v&&!n)&&(o?c.tieFormatName=o:delete c.tieFormatName);const{targetMatchUps:m}=iae({updateInProgressMatchUps:t,drawDefinition:i,structureId:s,structure:a,matchUpId:l,matchUp:u});oae({updateInProgressMatchUps:t,tournamentRecord:r,drawDefinition:i,targetMatchUps:m,tieFormat:c,event:p});const g=_e(c),h=ur({tieFormat:g});if(h.error)return h;if(d)p.tieFormat=g;else if(l)u.tieFormat=c;else if(a)a.tieFormat=g;else if(i)i.tieFormat=g;else if(!u||!i)return{error:pe};return Je({drawDefinition:i,eventId:p==null?void 0:p.eventId}),lae({},B)}var uae=Object.defineProperty,dae=Object.defineProperties,pae=Object.getOwnPropertyDescriptors,Hd=Object.getOwnPropertySymbols,eU=Object.prototype.hasOwnProperty,tU=Object.prototype.propertyIsEnumerable,rU=(t,e,r)=>e in t?uae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fae=(t,e)=>{for(var r in e||(e={}))eU.call(e,r)&&rU(t,r,e[r]);if(Hd)for(var r of Hd(e))tU.call(e,r)&&rU(t,r,e[r]);return t},vae=(t,e)=>dae(t,pae(e)),mae=(t,e)=>{var r={};for(var n in t)eU.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Hd)for(var n of Hd(t))e.indexOf(n)<0&&tU.call(t,n)&&(r[n]=t[n]);return r};function nU({updateInProgressMatchUps:t=!0,collectionGroupNumber:e,tournamentRecord:r,drawDefinition:n,tieFormatName:o,structureId:i,matchUpId:s,matchUp:a,eventId:c,event:l}){var u;if(!e)return{error:Oe};if(isNaN(e))return{error:Z};const d="removeCollectionGroup";let p=!a&&Q1({tournamentRecord:r,drawDefinition:n,structureId:i,matchUpId:s,eventId:c,event:l});if(p.error)return W({result:p,stack:d});const{structure:v}=p;a=a||p.matchUp;const f=p.tieFormat,m=f.winCriteria.valueGoal,g=f.winCriteria.aggregateValue,h=pn(f);if(p=ur({tieFormat:h}),p.error)return W({result:p,stack:d});const _=[];if(h.collectionDefinitions=h.collectionDefinitions.map(I=>{const P=I,{collectionGroupNumber:O}=P,y=mae(P,["collectionGroupNumber"]);return O!==e?I:(_.push(I.collectionId),y)}),h.collectionGroups=h.collectionGroups.filter(({groupNumber:I})=>I!==e),p=X1({updateInProgressMatchUps:t,originalValueGoal:m,wasAggregateValue:g,tournamentRecord:r,drawDefinition:n,tieFormatName:o,structureId:i,structure:v,tieFormat:h,matchUpId:s,matchUp:a,eventId:c,event:l}),!p.error){const{appliedPolicies:I}=at({tournamentRecord:r});if((u=I==null?void 0:I.audit)!=null&&u[Wi]){const P=_e({drawId:n==null?void 0:n.drawId,collectionGroupNumber:e,action:d,structureId:i,matchUpId:s,eventId:c});Bd({drawDefinition:n,auditData:P})}}return W({result:vae(fae({},p),{modifiedCollectionIds:_}),stack:d})}var gae=Object.defineProperty,hae=Object.defineProperties,_ae=Object.getOwnPropertyDescriptors,oU=Object.getOwnPropertySymbols,Iae=Object.prototype.hasOwnProperty,Pae=Object.prototype.propertyIsEnumerable,iU=(t,e,r)=>e in t?gae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yae=(t,e)=>{for(var r in e||(e={}))Iae.call(e,r)&&iU(t,r,e[r]);if(oU)for(var r of oU(e))Pae.call(e,r)&&iU(t,r,e[r]);return t},Sae=(t,e)=>hae(t,_ae(e));function sU({updateInProgressMatchUps:t=!0,tournamentRecord:e,groupDefinition:r,drawDefinition:n,collectionIds:o,tieFormatName:i,structureId:s,matchUpId:a,matchUp:c,eventId:l,event:u}){const d="addCollectionGroup";if(!Array.isArray(o))return W({result:{error:Oe},stack:d});let p=!c&&La({tournamentRecord:e,drawDefinition:n,structureId:s,matchUpId:a,eventId:l,event:u});if(p.error)return W({result:p,stack:d});const{structure:v}=p;c=c||p.matchUp;const f=p.tieFormat,m=f.winCriteria.valueGoal,g=pn(f);if(p=ur({tieFormat:g}),p.error)return W({result:p,stack:d});for(const I of g.collectionDefinitions){const{collectionId:P,collectionGroupNumber:O}=I;if(O&&o.includes(P))return W({result:{error:Z,info:"collectionIds cannot be part of other collectionGroups"},stack:d})}const _=(g.collectionGroups||[]).reduce((I,P)=>P.groupNumber>I?P.groupNumber:I,0)+1;return r.groupNumber=_,g.collectionDefinitions=g.collectionDefinitions.map(I=>o.includes(I.collectionId)?Sae(yae({},I),{collectionGroupNumber:_}):I),g.collectionGroups=[...g.collecitonGroups||[],r],X1({updateInProgressMatchUps:t,originalValueGoal:m,tournamentRecord:e,drawDefinition:n,tieFormatName:i,structureId:s,structure:v,tieFormat:g,matchUpId:a,matchUp:c,eventId:l,event:u})}var Oae=Object.defineProperty,bae=Object.defineProperties,Tae=Object.getOwnPropertyDescriptors,aU=Object.getOwnPropertySymbols,Eae=Object.prototype.hasOwnProperty,wae=Object.prototype.propertyIsEnumerable,cU=(t,e,r)=>e in t?Oae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,rg=(t,e)=>{for(var r in e||(e={}))Eae.call(e,r)&&cU(t,r,e[r]);if(aU)for(var r of aU(e))wae.call(e,r)&&cU(t,r,e[r]);return t},ng=(t,e)=>bae(t,Tae(e));function lU({updateInProgressMatchUps:t=!1,tieFormatComparison:e,modifiedTieFormat:r,tournamentRecord:n,drawDefinition:o,structureId:i,matchUpId:s,eventId:a,uuids:c,event:l}){const u="updateTieFormat";if(!ur(r))return{error:ni};let d=La({drawDefinition:o,structureId:i,matchUpId:s,eventId:a,event:l});if(d.error)return W({result:d,stack:u});const{matchUp:p,tieFormat:v}=d,f=pn(v),m=f.collectionDefinitions.map(({collectionId:y})=>y),g=[],h=[],_=[];r.collectionDefinitions.forEach(y=>{var S;_.push(y.collectionId),m.includes(y.collectionId)?(S=Au({descendent:r,ancestor:f}))!=null&&S.different&&g.push(y):h.push(y)});const I=m.filter(y=>!_.includes(y)),P=r.tieFormatName;let O;for(const y of g){const S=Xm(ng(rg({updateInProgressMatchUps:t},y),{tournamentRecord:n,drawDefinition:o,tieFormatName:P,structureId:i,matchUpId:s,eventId:a,event:l}));if(S.error)return W({result:S,stack:u});S.tieFormat&&(O=S.tieFormat)}for(const y of h){const S=eg({updateInProgressMatchUps:t,collectionDefinition:y,tournamentRecord:n,drawDefinition:o,tieFormatName:P,structureId:i,matchUpId:s,matchUp:p,eventId:a,uuids:c,event:l});if(S.error)return W({result:S,stack:u});S.tieFormat&&(O=S.tieFormat)}for(const y of I){const S=Jm({updateInProgressMatchUps:t,tieFormatComparison:e,tournamentRecord:n,drawDefinition:o,tieFormatName:P,collectionId:y,structureId:i,matchUpId:s,eventId:a,matchUp:p,event:l});if(S.error)return W({result:S,stack:u});S.tieFormat&&(O=S.tieFormat)}return O.collectionDefinitions=O.collectionDefinitions.sort((y,S)=>(y.collectionOrder||1/0)-(S.collectionOrder||1/0)).map((y,S)=>ng(rg({},y),{collectionOrder:S+1})),ng(rg({},B),{processedTieFormat:O})}const $ae={modifyCollectionDefinition:Xm,orderCollectionDefinitions:j1,removeCollectionDefinition:Jm,addCollectionDefinition:eg,removeCollectionGroup:nU,calculateWinCriteria:pa,addCollectionGroup:sU,modifyTieFormat:lU};var Nae=Object.defineProperty,uU=Object.getOwnPropertySymbols,Aae=Object.prototype.hasOwnProperty,Uae=Object.prototype.propertyIsEnumerable,dU=(t,e,r)=>e in t?Nae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Cae=(t,e)=>{for(var r in e||(e={}))Aae.call(e,r)&&dU(t,r,e[r]);if(uU)for(var r of uU(e))Uae.call(e,r)&&dU(t,r,e[r]);return t};function Ui({matchUp:t}){const{extension:e}=Or({name:zl,element:t});if(!e)return{error:Yt};const{history:r=[],undoHistory:n=[]}=e.value;return Cae({history:r,undoHistory:n},B)}var Mae=Object.defineProperty,Dae=Object.defineProperties,jae=Object.getOwnPropertyDescriptors,qd=Object.getOwnPropertySymbols,pU=Object.prototype.hasOwnProperty,fU=Object.prototype.propertyIsEnumerable,vU=(t,e,r)=>e in t?Mae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,og=(t,e)=>{for(var r in e||(e={}))pU.call(e,r)&&vU(t,r,e[r]);if(qd)for(var r of qd(e))fU.call(e,r)&&vU(t,r,e[r]);return t},ig=(t,e)=>Dae(t,jae(e)),sg=(t,e)=>{var r={};for(var n in t)pU.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&qd)for(var n of qd(t))e.indexOf(n)<0&&fU.call(t,n)&&(r[n]=t[n]);return r};function Rae({matchUp:t,updateScore:e}){var r;const n=((r=Ui({matchUp:t}))==null?void 0:r.history)||[];if(!Array.isArray(n))return{error:Z,info:"history is not an array"};const{matchUpFormat:o}=t;if(!o)return{error:wp};if(!xr(o))return{error:yh};const i=_r(o),{bestOf:s,finalSetFormat:a,setFormat:c}=i,l=["0","15","30","40","A","G"],u={sets:[]};let d,p=[0,0],v=1,f=[],m=0,g,h=0;const _=b=>[1,2].includes(b),I=()=>(m+=1,{winningSide:void 0,side1Score:0,side2Score:0,setNumber:m,games:[]}),P=()=>({winningSide:void 0,points:[]}),O=()=>({winningSide:void 0,side1Score:"",side2Score:"",shots:[]});let y=O(),S=P(),T=I(),E=0;for(const b of n){E+=1,g=u.sets.length+1===s;const N=g&&a?a:c,{tiebreakAt:w,setTo:$,NoAD:U,tiebbreakFormat:A}=N,M=T.side1Score===w&&T.side1Score===T.side2Score,C=!!N.tiebreakSet,D=C?N.tiebreakSet:A,{tiebreakTo:F,NoAD:R}=D||{},G=()=>{d=void 0,p=[0,0],v=3-v,T.side1TiebreakScore=0,T.side2TiebreakScore=0,T.side1PointScore="",T.side2PointScore="",h=0},x=V=>{T.winningSide=V;const L=T,q=sg(L,["s"]);u.sets.push(q),y=O(),S=P(),T=I(),G()},z=V=>{S.winningSide=V;const L=S,q=sg(L,["g"]);T.games.push(q),y=O(),S=P(),G();const k=`side${V}Score`;T[k]+=1},j=V=>{y.winningSide=V;const L=y,q=sg(L,["p"]);S.points.push(q),y=O(),h=0;const k=()=>p.reduce((Y,J)=>Y+J)%4/4>.5?v:3-v,H=V-1;if(M||C){p[H]+=1,d=k(),T[`side${V}TiebreakScore`]=p[H],T[`side${3-V}TiebreakScore`]=p[1-H];const Q=R?1:2;if(p[H]>=F&&p[H]>=p[1-H]+Q)return z(V),{gameCompleted:!0}}else if(p[1-H]===4&&p[H]===3?p[1-H]-=1:p[H]+=1,T.side1PointScore=l[p[0]],T.side2PointScore=l[p[1]],p[H]===5||p[H]===4&&p[1-H]<3||U&&p[H]===4)return z(V),{gameCompleted:!0}};if(_(b.srv)&&(v=b.srv),["p","s","g","o"].includes(b.u)&&f.push(b.u),b.shotOutcome&&(y.shots.push(b),b.shotType==="SERVE"&&["OUT","NET"].includes(b.shotOutcome)&&(h+=1),h===2)){const L=3-v;j(L)}if(_(b.p)||ut(b.pointNumber)){const V=b.winningSide||b.p,L=j(V);if(L!=null&&L.gameCompleted)continue}if(_(b.g)||ut(b.gameNumber)){const V=b.winningSide||b.g;S.winningSide=V;const L=`side${V}Score`,q=`side${3-V}Score`;if(f.length&&(f.includes("p"),f=[]),z(V),T[L]===$&&T[L]-T[q]>=(U?1:2)&&(x(V),g))break}if(_(b.s)||ut(b.setNumber)){const V=b.winningSide||b.s;if(x(V),f.length&&(f.includes("p"),f.includes("g"),f=[]),g)break}}return E!==n.length&&console.log({error:"Match completed with excess history"}),(T.side1Score||T.side2Score||T.games.length||T.side1TiebreakScore||T.side2TiebreakScore)&&u.sets.push(T),u.scoreStringSide1=Jn(ig(og({},u),{matchUpFormat:o})),u.scoreStringSide2=Jn(ig(og({},u),{matchUpFormat:o,reversed:!0})),v=d||v,e&&(t.score=u),ig(og({},B),{servingSide:v,score:u})}function Ci({matchUp:t,history:e,undoHistory:r}){return tt({element:t,extension:{value:{history:e,undoHistory:r},name:zl}})}function Fae({matchUp:t,sideNumber:e}){if(![1,2].includes(e))return{error:Th};const{history:r=[]}=Ui({matchUp:t});return r.push({srv:e}),Ci({matchUp:t,history:r})}function Lae({matchUp:t}){return Ci({matchUp:t})}function Vae({matchUp:t,point:e}){if(!e)return{error:Oe};if(typeof e!="object")return{error:Z,context:{point:e}};const{history:r=[]}=Ui({matchUp:t});return r.push(e),Ci({matchUp:t,history:r})}function xae({matchUp:t,game:e}){if(typeof e!="object")return{error:Z,context:{game:e}};const{history:r=[]}=Ui({matchUp:t});return r.push(e),Ci({matchUp:t,history:r})}function Bae({matchUp:t,shot:e}){if(typeof e!="object")return{error:Oe};const{history:r=[]}=Ui({matchUp:t});return r.push(e),Ci({matchUp:t,history:r})}function kae({matchUp:t,set:e}){if(typeof e!="object")return{error:Oe};const{history:r=[]}=Ui({matchUp:t});return r.push(e),Ci({matchUp:t,history:r})}function Gae({matchUp:t}){const{history:e=[],undoHistory:r=[]}=Ui({matchUp:t});return r.length&&e.push(r.pop()),Ci({matchUp:t,history:e,undoHistory:r})}function Wae({matchUp:t}){const{history:e=[],undoHistory:r=[]}=Ui({matchUp:t});return r.push(e.pop()),Ci({matchUp:t,history:e,undoHistory:r})}const Hae={calculateHistoryScore:Rae,setServingSide:Fae,clearHistory:Lae,addPoint:Vae,addGame:xae,addShot:Bae,addSet:kae,redo:Gae,undo:Wae,umo:{scoreboard:()=>{},addPoints:()=>{},addPoint:()=>{}}};var qae=Object.defineProperty,mU=Object.getOwnPropertySymbols,Yae=Object.prototype.hasOwnProperty,zae=Object.prototype.propertyIsEnumerable,gU=(t,e,r)=>e in t?qae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Kae=(t,e)=>{for(var r in e||(e={}))Yae.call(e,r)&&gU(t,r,e[r]);if(mU)for(var r of mU(e))zae.call(e,r)&&gU(t,r,e[r]);return t};function ag(t){var e;const{matchUp:r,sideNumber:n,setNumber:o,isTiebreakValue:i,isPointValue:s}=t||{};let{matchUpFormat:a}=t||{};if(!r)return{error:$r};a=a||(r==null?void 0:r.matchUpFormat);const c=_r(a),l=!!(r!=null&&r.winningSide),u=(e=r.score)==null?void 0:e.sets,d=u==null?void 0:u.length,p=o&&o-1,v=!!(u!=null&&u.find((L,q)=>L.setNumber===o&&q===p)),f=(u==null?void 0:u.filter(L=>L==null?void 0:L.winningSide))||[],m=(f==null?void 0:f.length)||0,g=o&&(u==null?void 0:u.slice(o))||[],h=!!(d&&o&&(g!=null&&g.reduce((L,q)=>(!q||!q.side1Score&&!q.side2Score&&!q.side1TiebreakScore&&!q.side2TiebreakScore&&!q.side1PointScore&&!q.side2PointScore)&&L,!0))),_=o<=d&&u.find(L=>L.setNumber===o),I=_&&yu({setObject:_,matchUpScoringFormat:c}),{isCompletedSet:P,sideGameScores:O,sideTiebreakScores:y}=I||{},S=!!(_&&!P&&h||o&&o===d+1&&!l),T=[1,2].includes(n),E=T?n-1:0,b=_&&T&&(!i&&!s&&O[E]!==void 0&&O[E]||i&&y[E]!==void 0&&y[E]),N=!!b,w=f==null?void 0:f.map(L=>yu({setObject:L,matchUpScoringFormat:c}).isValidSetOutcome).reduce((L,q)=>L&&q,!0),$=f.reduce((L,q)=>{const{winningSide:k}=q,H=k-1;return L[H]++,L},[0,0]),U=r==null?void 0:r.winningSide,A=U&&U-1,M=1-A,C=$[A],D=$[M],F=Math.max(...$),R=mr($)[F],{bestOf:G}=c||{},x=G&&Math.ceil(G/2)||1,z=F===x&&R===1&&$.indexOf(F)+1||void 0,j=C>D&&U===z;return Kae({completedSetsHaveValidOutcomes:w,validMatchUpWinningSide:j,calculatedWinningSide:z,matchUpScoringFormat:c,validMatchUpOutcome:z&&w&&j,isLastSetWithValues:h,completedSetsCount:m,isCompletedMatchUp:l,isValidSideNumber:T,hasExistingValue:N,existingValue:b,isExistingSet:v,isActiveSet:S},I)}const Qae={tallyParticipantResults:Zp,matchUpIsComplete:Ws,analyzeMatchUp:ag,getMatchUpType:mP,scoreHasValue:Dt};let Ts={},Zo;function hU(t,e=!0){if(!t)return{error:Oe};if(typeof t!="object")return{error:xn};if(t.matchUpId)Zo=t.matchUpId,Ts[Zo]=e?ue(t):t;else if(Array.isArray(t))for(const r of t.reverse())r.matchUpId&&(Ts[r.matchUpId]=e?ue(r):r,Zo||(Zo=r.matchUpId));else for(const r of Object.values(t))r.matchUpId&&(Ts[r.matchUpId]=e?ue(r):r,Zo||(Zo=r.matchUpId));return e?ue(t):t}function Jae(){return Ts[Zo]}function Zae(){return Object.values(Ts)}function Xae(){Zo=void 0,Ts={}}function ece({convertExtensions:t,removeExtensions:e}={}){return ue(Ts[Zo],t,!1,e)}var tce=Object.defineProperty,rce=Object.defineProperties,nce=Object.getOwnPropertyDescriptors,_U=Object.getOwnPropertySymbols,oce=Object.prototype.hasOwnProperty,ice=Object.prototype.propertyIsEnumerable,IU=(t,e,r)=>e in t?tce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cg=(t,e)=>{for(var r in e||(e={}))oce.call(e,r)&&IU(t,r,e[r]);if(_U)for(var r of _U(e))ice.call(e,r)&&IU(t,r,e[r]);return t},PU=(t,e)=>rce(t,nce(e));(function(){const t={getState:()=>ece(),version:()=>so(),reset:()=>(Xae(),cg({},B))};function e(o){return o!=null&&o.error?(t.error=o.error,t.success=!1):(t.error=void 0,t.success=!0,t.drawId=o.drawId),t}return r([$ae,Hae,Qae,wy]),t.devContext=o=>(xs(o),t),t.setState=(o,i,s)=>{Fi(i,s);const a=hU(o);return e(a)},t;function r(o){o.forEach(i=>{Object.keys(i).forEach(s=>{t[s]=a=>{if(Ft())return n({params:a,governor:i,governorMethod:s});try{return n({params:a,governor:i,governorMethod:s})}catch(c){const l=c.toString();console.log("ERROR",{error:l,method:s,params:JSON.stringify(a)})}}})})}function n({params:o,governor:i,governorMethod:s}){delete t.success,delete t.error;const a=(o==null?void 0:o.matchUp)||Jae(),c=(o==null?void 0:o.matchUps)||Zae(),l=(o==null?void 0:o.rollbackOnError)&&ue(a,!1,!0);o=PU(cg({},o),{matchUpId:a==null?void 0:a.matchUpId,matchUps:c,matchUp:a});const u=i[s](o);if(u!=null&&u.error)return l&&hU(l),PU(cg({},u),{rolledBack:!!l});const d=(u==null?void 0:u.success)&&(o==null?void 0:o.delayNotify)!==!0&&(o==null?void 0:o.doNotNotify)!==!0;return d&&bi(),(d||!(u!=null&&u.success)||o!=null&&o.doNotNotify)&&ii(),u}})();var sce=Object.defineProperty,yU=Object.getOwnPropertySymbols,ace=Object.prototype.hasOwnProperty,cce=Object.prototype.propertyIsEnumerable,SU=(t,e,r)=>e in t?sce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lce=(t,e)=>{for(var r in e||(e={}))ace.call(e,r)&&SU(t,r,e[r]);if(yU)for(var r of yU(e))cce.call(e,r)&&SU(t,r,e[r]);return t};function lg(t={}){return t.tournamentId||Object.assign(t,{tournamentId:We()}),t.startDate&&!ai(t.startDate)&&!jl.test(t.startDate)?{error:cr}:t.endDate&&!ai(t.endDate)&&!jl.test(t.endDate)?{error:cr}:(t.extensions&&(t.extensions=t.extensions.filter(on)),lce({},t))}var uce=Object.defineProperty,dce=Object.defineProperties,pce=Object.getOwnPropertyDescriptors,OU=Object.getOwnPropertySymbols,fce=Object.prototype.hasOwnProperty,vce=Object.prototype.propertyIsEnumerable,bU=(t,e,r)=>e in t?uce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,TU=(t,e)=>{for(var r in e||(e={}))fce.call(e,r)&&bU(t,r,e[r]);if(OU)for(var r of OU(e))vce.call(e,r)&&bU(t,r,e[r]);return t},EU=(t,e)=>dce(t,pce(e));function ug(t,e){var r;if(typeof t!="object")return{error:xn};const n=((r=t.unifiedTournamentId)==null?void 0:r.tournamentId)||t.tournamentId;if(!n)return{error:ao};const o=e!==!1?ue(t):t;return ec({[n]:o}),tc(n),o}function mce({convertExtensions:t,removeExtensions:e,tournamentId:r}={}){if(typeof r!="string")return{};const n=Xa(r);return{tournamentRecord:ue(n,t,!1,e)}}function gce(t,e,r){var n;if(e){const o=e.drawId||((n=e.matchUp)==null?void 0:n.drawId);if(o){const{event:i,drawDefinition:s}=xt({tournamentRecord:t,drawId:o});if(e=EU(TU({},e),{event:i,drawDefinition:s}),r){const a=Kt({drawDefinition:s}),{matchUps:c}=Nt({includeByeMatchUps:!0,inContext:!0,drawDefinition:s,matchUpsMap:a});e.matchUpsMap=a,e.inContextDrawMatchUps=c}}if(e.eventId&&!e.event){const{event:i}=xt({eventId:e.eventId,tournamentRecord:t});i&&(e=EU(TU({},e),{event:i}))}}return e}function hce(t){return t.tournamentRecord?g1(t):{error:ee}}function _ce({tournamentRecord:t,participantId:e}){if(!t)return{error:ee};if(!e)return{error:yt};const r=[e].concat((t.participants||[]).filter(o=>{var i;return(o==null?void 0:o.participantType)&&[Ye,we].includes(o.participantType)&&((i=o.individualParticipantIds)==null?void 0:i.includes(e))}).map(o=>o.participantId));return{eventDetails:(t.events||[]).filter(o=>{const i=((o==null?void 0:o.entries)||[]).map(s=>s.participantId);return Gt(i,r)}).map(o=>({eventName:o.eventName,eventId:o.eventId}))}}function Ice({tournamentRecord:t,participantId:e}){if(!t)return{error:ee};if(!e)return{error:yt};const{tournamentParticipants:r}=Qt({participantFilters:{participantTypes:[Ye,we,dr]},tournamentRecord:t});return(r||[]).filter(o=>{var i;return(i=o.individualParticipantIds)==null?void 0:i.includes(e)}).reduce((o,i)=>{const{participantType:s}=i;return o[s]||(o[s]=[]),o[s].push(i),o},{})}var Pce=Object.defineProperty,wU=Object.getOwnPropertySymbols,yce=Object.prototype.hasOwnProperty,Sce=Object.prototype.propertyIsEnumerable,$U=(t,e,r)=>e in t?Pce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Oce=(t,e)=>{for(var r in e||(e={}))yce.call(e,r)&&$U(t,r,e[r]);if(wU)for(var r of wU(e))Sce.call(e,r)&&$U(t,r,e[r]);return t};function bce({participantFilters:t={},tournamentRecord:e}){if(!e)return{error:ee};if(typeof t!="object")return{error:xn,context:{participantFilters:t}};const r={eventIds:t.eventIds},n=Bt({tournamentRecord:e,contextFilters:r}).matchUps,o=Object.assign({},...n.map(l=>({[l.matchUpId]:l}))),i=n.filter(({schedule:l})=>l&&Object.keys(l).length),{sourceMatchUpIds:s}=Yr({tournamentRecord:e,matchUps:n}),a={};for(const l of i){const{sides:u}=l;let d;const p=(u==null?void 0:u.map(({participant:f})=>{if(f)return[f].concat(...f.individualParticipants||[]);s[l.matchUpId]&&!d&&(d=(s[l.matchUpId]||[]).map(m=>o[m]).filter(({winningSide:m,bye:g})=>!m&&!g))}).filter(Boolean).flat())||[];for(const f of p){const{participantId:m}=f;a[m]||(a[m]={potentialMatchUps:[],participant:f,matchUps:[]}),a[m].matchUps.push(l)}const v=(d==null?void 0:d.map(({sides:f})=>f).flat().map(({participant:f})=>f&&[f].concat(...f.individualParticipants||[])).filter(Boolean).flat())||[];for(const f of v){const{participantId:m}=f;a[m]||(a[m]={potentialMatchUps:[],participant:f,matchUps:[]}),a[m].potentialMatchUps.push(l)}}const c=Object.values(a).filter(({participant:l})=>!(t.participantIds&&!t.participantIds.includes(l.participantId)||t.participantTypes&&!t.participantTypes.includes(l.participantType)));return Oce({participantSchedules:c},B)}function Tce({tournamentRecord:t,drawDefinition:e,byeAdvancements:r=!1}){if(!t)return{error:ee};const n=t.participants;return _1({tournamentParticipants:n,byeAdvancements:r,drawDefinition:e})}var Ece=Object.defineProperty,wce=Object.defineProperties,$ce=Object.getOwnPropertyDescriptors,NU=Object.getOwnPropertySymbols,Nce=Object.prototype.hasOwnProperty,Ace=Object.prototype.propertyIsEnumerable,AU=(t,e,r)=>e in t?Ece(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Uce=(t,e)=>{for(var r in e||(e={}))Nce.call(e,r)&&AU(t,r,e[r]);if(NU)for(var r of NU(e))Ace.call(e,r)&&AU(t,r,e[r]);return t},Cce=(t,e)=>wce(t,$ce(e));function Mce({participantRole:t=qt,tournamentRecord:e,persons:r}){var n;if(!e)return{error:ee};if(!Array.isArray(r))return{error:Z};if(!Object.keys(gb).includes(t))return{error:MF};const o=(e.participants||[]).map(({person:m})=>m==null?void 0:m.personId).filter(Boolean),i=[],s=r.filter(m=>m&&(!m.personId||!o.includes(m.personId))).map(m=>(m.personId||(m.personId=We()),i.push(m.personId),m)),a=(m,g)=>Object.assign({},...Object.keys(m).filter(h=>!g.includes(h)).map(h=>({[h]:m[h]}))),c=s.map(m=>_e({extensions:m.participantExtensions,timeItems:m.participantTimeItems,participantType:Me,participantRole:t,person:a(m,["participantExtensions","participantTimeItems","pairedPersons"])}));let l=0,u=0,d=to({participants:c,tournamentRecord:e});if(d.error)return d;u=d.addedCount||0;const p=[],v=((n=Qt({participantFilters:{participantTypes:[Me]},tournamentRecord:e}))==null?void 0:n.tournamentParticipants)||[];if(t===qt&&r.filter(({pairedPersons:m})=>m).forEach(({personId:m,pairedPersons:g})=>{Array.isArray(g)&&g.forEach(h=>{const _=[m,h.personId].map(I=>vo({tournamentParticipants:v,personId:I})).filter(Boolean);if(_.length===2){const I=_.map(Xe);p.push(_e({extensions:h.participantExtensions,timeItems:h.timeItems,participantRole:qt,individualParticipantIds:I,participantType:we}))}})}),p.length){if(d=to({participants:p,tournamentRecord:e}),d.error)return d;l=d.addedCount||0}const f=u+l;return Cce(Uce({},B),{addedCount:f,newPersonIds:i})}var Dce=Object.defineProperty,UU=Object.getOwnPropertySymbols,jce=Object.prototype.hasOwnProperty,Rce=Object.prototype.propertyIsEnumerable,CU=(t,e,r)=>e in t?Dce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Fce=(t,e)=>{for(var r in e||(e={}))jce.call(e,r)&&CU(t,r,e[r]);if(UU)for(var r of UU(e))Rce.call(e,r)&&CU(t,r,e[r]);return t};function Lce({individualParticipantIds:t,groupingParticipantId:e,tournamentRecord:r}){var n,o;const i=(r.events||[]).filter(a=>{var c;return(a==null?void 0:a.eventType)===Tt&&((c=a==null?void 0:a.entries)==null?void 0:c.some(l=>l.participantId===e))}),s=a=>!t.includes(a.participantId);for(const a of i){a.entries=(a.entries||[]).filter(s);const{flightProfile:c}=It({event:a});(n=c==null?void 0:c.flights)==null||n.forEach(l=>{l.drawEntries=(l.drawEntries||[]).filter(s)}),(o=a==null?void 0:a.drawDefinitions)==null||o.forEach(l=>{l.entries=(l.entries||[]).filter(s)})}return Fce({},B)}var Vce=Object.defineProperty,MU=Object.getOwnPropertySymbols,xce=Object.prototype.hasOwnProperty,Bce=Object.prototype.propertyIsEnumerable,DU=(t,e,r)=>e in t?Vce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,kce=(t,e)=>{for(var r in e||(e={}))xce.call(e,r)&&DU(t,r,e[r]);if(MU)for(var r of MU(e))Bce.call(e,r)&&DU(t,r,e[r]);return t};function dg({individualParticipantIds:t,groupingParticipantId:e,removeFromOtherTeams:r,tournamentRecord:n}){const o="addIndividualParticipantIds";if(!n)return W({result:{error:ee},stack:o});if(!e||!t)return W({result:{error:Oe},stack:o});const i=n.participants||[],s=i.find(d=>d.participantId===e);if(!s)return W({result:{error:wt},stack:o});if(s!=null&&s.participantType&&![Ye,dr].includes(s.participantType))return W({result:{error:In},context:{participantType:s.participantType},stack:o});const a=t.filter(d=>{const p=i.find(v=>v.participantId===d);return(p==null?void 0:p.participantType)!==Me});if(a.length)return W({result:{error:Qr,invalidParticipantIds:a},stack:o});s.individualParticipantIds||(s.individualParticipantIds=[]);const c=s.individualParticipantIds,l=t.filter(d=>!c.includes(d));l.length&&(r&&qm({individualParticipantIds:l,tournamentRecord:n}),s.individualParticipantIds=s.individualParticipantIds.concat(...l));const{topics:u}=Pn();if(u.includes(Ht)){const d=i.find(({participantId:p})=>p===e);xe({topic:Ht,payload:{participants:[d]}})}return Lce({individualParticipantIds:t,groupingParticipantId:e,tournamentRecord:n}),kce({groupingParticipant:ue(s,!1,!0),added:l.length},B)}var Gce=Object.defineProperty,jU=Object.getOwnPropertySymbols,Wce=Object.prototype.hasOwnProperty,Hce=Object.prototype.propertyIsEnumerable,RU=(t,e,r)=>e in t?Gce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,FU=(t,e)=>{for(var r in e||(e={}))Wce.call(e,r)&&RU(t,r,e[r]);if(jU)for(var r of jU(e))Hce.call(e,r)&&RU(t,r,e[r]);return t};function qce({individualParticipantIds:t,groupingParticipantId:e,tournamentRecord:r}){const n="modifyIndividualParticipantIds";if(!r)return W({result:{error:ee},stack:n});if(!e||!t)return W({result:{error:Oe},stack:n});const o=r.participants||[],i=o.find(v=>v.participantId===e);if(!i)return W({result:{error:wt},stack:n});if(![Ye,dr].includes(i.participantType))return W({result:{error:In},context:{participantType:i.participantType},stack:n});const s=t.filter(v=>{const f=o.find(m=>m.participantId===v);return(f==null?void 0:f.participantType)!==Me});if(s.length)return W({result:{error:Qr,invalidParticipantIds:s},stack:n});const a=i.individualParticipantIds||[],c=t.filter(v=>!a.includes(v)),l=a.filter(v=>!t.includes(v)),u=dg({individualParticipantIds:c,groupingParticipantId:e,tournamentRecord:r});if(u.error)return W({result:u,stack:n});const d=OA({individualParticipantIds:l,groupingParticipantId:e,tournamentRecord:r});if(d.error)return W({result:d,stack:n});const{topics:p}=Pn();if(p.includes(Ht)){const v=o.find(({participantId:f})=>f===e);xe({topic:Ht,payload:{tournamentId:r.tournamentId,participants:[v]}})}return FU(FU({},u),d)}var Yce=Object.defineProperty,zce=Object.defineProperties,Kce=Object.getOwnPropertyDescriptors,LU=Object.getOwnPropertySymbols,Qce=Object.prototype.hasOwnProperty,Jce=Object.prototype.propertyIsEnumerable,VU=(t,e,r)=>e in t?Yce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xU=(t,e)=>{for(var r in e||(e={}))Qce.call(e,r)&&VU(t,r,e[r]);if(LU)for(var r of LU(e))Jce.call(e,r)&&VU(t,r,e[r]);return t},BU=(t,e)=>zce(t,Kce(e));function kU({addParticipants:t=!0,participantAttribute:e,tournamentRecord:r,personAttribute:n,teamNames:o,accessor:i,uuids:s}){var a;if(!r)return{error:ee};const c={},l=(r.participants||[]).filter(({participantType:m,participantRole:g})=>m===Me&&g===qt);let u=0;for(const m of l){const h=i&&((a=Xu({element:m,accessor:i}))==null?void 0:a.value)||(n?m.person[n]:m[e]);if(h){if(!Object.keys(c).includes(h)){c[h]={participantName:(o==null?void 0:o[u])||h,participantId:(s==null?void 0:s.pop())||We(),individualParticipantIds:[],participantRole:qt,participantType:Ye};const _={name:Xp,value:n||e};tt({element:c[h],extension:_}),u+=1}c[h].individualParticipantIds.push(m.participantId)}}const d=Object.keys(c),p=(r.participants||[]).map(m=>{if(m.participantType!==Ye||m.participantRole!==qt)return;const{extension:g}=Or({name:Xp,element:m}),h=g==null?void 0:g.value;if(d.includes(h))return m.participantId}).filter(Boolean);let v=0;const f=[];return Object.keys(c).forEach(m=>{const g=c[m],{participantId:h}=g;p.includes(h)||(t&&r.participants.push(g),f.push(g),v++)}),t&&v?(xe({payload:{tournamentId:r.tournamentId,participants:f},topic:fi}),BU(xU({},B),{participantsAdded:v})):f.length?BU(xU({},B),{newParticipants:f}):{error:UF}}var Zce=Object.defineProperty,GU=Object.getOwnPropertySymbols,Xce=Object.prototype.hasOwnProperty,ele=Object.prototype.propertyIsEnumerable,WU=(t,e,r)=>e in t?Zce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tle=(t,e)=>{for(var r in e||(e={}))Xce.call(e,r)&&WU(t,r,e[r]);if(GU)for(var r of GU(e))ele.call(e,r)&&WU(t,r,e[r]);return t};function rle({tournamentRecord:t,participantIds:e,signInState:r}){if(!t)return{error:ee};if(!Array.isArray(e))return{error:Oe};if(![Ic,mk].includes(r))return{error:Z,signInState:r};const o=t.participants||[];if(!o.length)return{error:Qa};const i=o.map(Xe),s=e.filter(u=>!i.includes(u));if(s.length)return{error:Z,context:{invalidParticipantIds:s}};const a=[],c=new Date().toISOString();for(const u of o){const{participantId:d}=u;if(e.includes(d)){const v=LS({tournamentRecord:t,duplicateValues:!1,participantId:d,timeItem:{itemType:_c,itemValue:r,createdAt:c}});if(v.error)return v;a.push(u)}}const{topics:l}=Pn();return a.length&&l.includes(Ht)&&xe({topic:Ht,payload:{tournamentId:t.tournamentId,participants:a}}),tle({},B)}var nle=Object.defineProperty,ole=Object.defineProperties,ile=Object.getOwnPropertyDescriptors,HU=Object.getOwnPropertySymbols,sle=Object.prototype.hasOwnProperty,ale=Object.prototype.propertyIsEnumerable,qU=(t,e,r)=>e in t?nle(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cle=(t,e)=>{for(var r in e||(e={}))sle.call(e,r)&&qU(t,r,e[r]);if(HU)for(var r of HU(e))ale.call(e,r)&&qU(t,r,e[r]);return t},lle=(t,e)=>ole(t,ile(e));function ule({clearExistingAssignments:t=!0,individualParticipantIds:e,reverseAssignmentOrder:r,initialTeamIndex:n=0,scaledParticipants:o=[],teamParticipantIds:i,tournamentRecord:s,scaleAttributes:a,teamNameBase:c,teamsCount:l,eventId:u,event:d}){var p,v;if(!s)return{error:ee};if(!Array.isArray(i)&&!ut(l)&&!u||!ut(n)||o&&!Array.isArray(o)||a&&(typeof a!="object"||!Object.keys(a).length))return{error:Z};if(!a&&!o.length||!o&&!(e&&a))return{error:Oe,info:"Missing scaling details"};if(u&&!i){if((d==null?void 0:d.eventType)!==Nn)return{error:ri};i=d.entries.filter(({entryStatus:I})=>I===Mr).map(Xe)}if(!(i!=null&&i.length)&&!l)return{info:"Missing teamParticipantIds or teamsCount",error:Oe};let f=e||o.map(({participantId:I})=>I);r&&(i.reverse(),n+=1),n>(i==null?void 0:i.length)-1&&(n=0);const m=(i==null?void 0:i.slice(n).concat(...i.slice(0,n)))||[],g=[];for(const I of s.participants||[]){const{participantId:P,participantType:O}=I;if(m.includes(P)){if(O!==An)return{error:In,participant:I};g.push(I)}}if(l&&g.length<l){const I=l-((g==null?void 0:g.length)||0),P=c||"Team";let O=le(0,I).map(E=>({participantName:`${P} ${E+1}`,participantType:An,participantRole:qt}));const{participants:y=[]}=to({participants:O,returnParticipants:!0,tournamentRecord:s}),S=y.map(Xe),T=s.participants.filter(({participantId:E})=>S.includes(E));g.push(...T)}if(!g.length)return{error:Bh};if(t)for(const I of g)I.individualParticipantIds=[];else{const I=g.map(P=>P).flat();e!=null&&e.length?f=f.filter(P=>!I.includes(P)):o=o==null?void 0:o.filter(({participantId:P})=>!I.includes(P))}if(!(e!=null&&e.length)&&!(o!=null&&o.length))return{error:Fp,info:"Nothing to be done"};if(!o.length){for(const I of s.participants||[]){const{participantId:P,participantType:O}=I;if(!f.includes(P))continue;if(O!==Me)return{error:In,participant:I};const y=(p=ro({scaleAttributes:a,participant:I}))==null?void 0:p.scaleItem,S=a!=null&&a.accessor?(v=y==null?void 0:y.scaleValue)==null?void 0:v[a==null?void 0:a.accessor]:y==null?void 0:y.scaleValue,T={participantId:P,scaleValue:S};o.push(T)}if(!o.length)return{error:wt}}o.sort((I,P)=>a!=null&&a.sortOrder?((P==null?void 0:P.scaleValue)||0)-((I==null?void 0:I.scaleValue)||0):((I==null?void 0:I.scaleValue)||1/0)-((P==null?void 0:P.scaleValue)||1/0));for(const I of o)if(!I.participantId)return{error:Z,scaledParticipant:I};let h=0;for(;h<o.length;){for(const I of g){if(h+1>o.length)break;const P=o[h];I.individualParticipantIds.push(P.participantId),h++}g.reverse()}const _=g.map(Xe);for(const I of s.events||[]){if(I.eventType!==Nn)continue;const P=(I.entries||[]).filter(O=>_.includes(O.participantId));for(const O of P){const y=O.participantId,S=g.find(b=>b.participantId===y),T=S==null?void 0:S.individualParticipantIds;I.entries=(I.entries||[]).filter(b=>!T.includes(b.participantId)),(I.drawDefinitions||[]).forEach(b=>{b.entries=(b.entries||[]).filter(N=>!T.includes(N.participantId))});const{flightProfile:E}=It({event:I});((E==null?void 0:E.flights)||[]).forEach(b=>{b.drawEntries=(b.drawEntries||[]).filter(N=>!T.includes(N.participantId))})}}return lle(cle({},B),{scaledParticipants:o})}var dle=Object.defineProperty,ple=Object.defineProperties,fle=Object.getOwnPropertyDescriptors,YU=Object.getOwnPropertySymbols,vle=Object.prototype.hasOwnProperty,mle=Object.prototype.propertyIsEnumerable,zU=(t,e,r)=>e in t?dle(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gle=(t,e)=>{for(var r in e||(e={}))vle.call(e,r)&&zU(t,r,e[r]);if(YU)for(var r of YU(e))mle.call(e,r)&&zU(t,r,e[r]);return t},hle=(t,e)=>ple(t,fle(e));function _le({individualParticipantIds:t=[],participantRoleResponsibilities:e,participantRole:r=mb,tournamentRecord:n,participantId:o,groupName:i}){if(!n)return{error:ee};if(!i)return{error:Oe,info:"Missing groupName"};if(!Array.isArray(t))return{info:"Invalid individualParticipantIds",error:Z};const{tournamentParticipants:s}=Qt({participantFilters:{participantTypes:[Me]},tournamentRecord:n}),a=s.map(d=>d.participantId);for(const d of t)if(!a.includes(d))return{error:In,participantId:d};const c=_e({participantId:o||We(),participantRoleResponsibilities:e,participantName:i,individualParticipantIds:t,participantType:dr,participantRole:r}),l=Rn({participant:c,tournamentRecord:n});if(l.error)return l;const{topics:u}=Pn();return u.includes(fi)&&xe({topic:fi,payload:{tournamentId:n.tournamentId,participants:[c]}}),hle(gle({},B),{participant:ue(c)})}var Ile=Object.defineProperty,KU=Object.getOwnPropertySymbols,Ple=Object.prototype.hasOwnProperty,yle=Object.prototype.propertyIsEnumerable,QU=(t,e,r)=>e in t?Ile(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Sle=(t,e)=>{for(var r in e||(e={}))Ple.call(e,r)&&QU(t,r,e[r]);if(KU)for(var r of KU(e))yle.call(e,r)&&QU(t,r,e[r]);return t};function Ole({tournamentRecord:t,participantId:e,participantOtherName:r}){if(!t)return{error:ee};if(!e)return{error:yt};const{participant:n}=Ro({tournamentRecord:t,participantId:e});if(!n)return{error:wt};n.participantOtherName=r;const{topics:o}=Pn();return o.includes(Ht)&&xe({topic:Ht,payload:{tournamentId:t.tournamentId,participants:[n]}}),Sle({},B)}var ble=Object.defineProperty,Tle=Object.defineProperties,Ele=Object.getOwnPropertyDescriptors,JU=Object.getOwnPropertySymbols,wle=Object.prototype.hasOwnProperty,$le=Object.prototype.propertyIsEnumerable,ZU=(t,e,r)=>e in t?ble(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Nle=(t,e)=>{for(var r in e||(e={}))wle.call(e,r)&&ZU(t,r,e[r]);if(JU)for(var r of JU(e))$le.call(e,r)&&ZU(t,r,e[r]);return t},Ale=(t,e)=>Tle(t,Ele(e));function Ule({tournamentRecord:t,participantFilters:e}){if(!t)return{error:ee};let r=t.participants||[];e&&(r=sd({participants:r,participantFilters:e,tournamentRecord:t}));const n={},o=i=>{if(i.person){const{personId:s}=i.person;n[s]?n[s].participantIds.push(i.participantId):n[s]=Ale(Nle({},i.person),{participantIds:[i.participantId]})}};return r.forEach(i=>{i.person&&o(i),i.individualParticipants&&i.individualParticipants.forEach(o)}),{tournamentPersons:Object.values(n)}}var Cle=Object.defineProperty,XU=Object.getOwnPropertySymbols,Mle=Object.prototype.hasOwnProperty,Dle=Object.prototype.propertyIsEnumerable,eC=(t,e,r)=>e in t?Cle(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jle=(t,e)=>{for(var r in e||(e={}))Mle.call(e,r)&&eC(t,r,e[r]);if(XU)for(var r of XU(e))Dle.call(e,r)&&eC(t,r,e[r]);return t};function Rle({tournamentRecord:t,participantName:e,participantId:r}){if(!t)return{error:ee};if(!r)return{error:yt};if(!e)return{error:Oe,info:"Missing participantName"};const{participant:n}=Ro({tournamentRecord:t,participantId:r});if(!n)return{error:wt};n.participantName=e;const{topics:o}=Pn();return o.includes(Ht)&&xe({topic:Ht,payload:{tournamentId:t.tournamentId,participants:[n]}}),jle({},B)}var Fle=Object.defineProperty,tC=Object.getOwnPropertySymbols,Lle=Object.prototype.hasOwnProperty,Vle=Object.prototype.propertyIsEnumerable,rC=(t,e,r)=>e in t?Fle(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xle=(t,e)=>{for(var r in e||(e={}))Lle.call(e,r)&&rC(t,r,e[r]);if(tC)for(var r of tC(e))Vle.call(e,r)&&rC(t,r,e[r]);return t};function Ble({tournamentRecord:t,participants:e=[],arraysToMerge:r}){if(!t)return{error:ee};t.participants||(t.participants=[]);const n=Object.assign(...e.filter(gu).map(c=>({[c.participantId]:c}))),o=[];t.participants=t.participants.map(c=>{if(n[c.participantId]){const l=qv(c,n[c.participantId],r);return o.push(l),l}else return c});const i=t.participants.map(Xe),s=e.filter(({participantId:c})=>!i.includes(c)),{topics:a}=Pn();if(s.length&&(t.participants=t.participants.concat(...s),a.includes(fi)&&xe({topic:fi,payload:{participants:s}})),o.length&&a.includes(Ht)&&xe({topic:Ht,payload:{tournamentId:t.tournamentId,participants:o}}),s.length||o.length)return xle({},B)}var kle=Object.defineProperty,nC=Object.getOwnPropertySymbols,Gle=Object.prototype.hasOwnProperty,Wle=Object.prototype.propertyIsEnumerable,oC=(t,e,r)=>e in t?kle(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Hle=(t,e)=>{for(var r in e||(e={}))Gle.call(e,r)&&oC(t,r,e[r]);if(nC)for(var r of nC(e))Wle.call(e,r)&&oC(t,r,e[r]);return t};function pg({updateParticipantName:t=!0,groupingParticipantId:e,removeFromOtherTeams:r,tournamentRecord:n,pairOverride:o,participant:i}){if(!n)return{error:ee};if(!i)return{error:Ls};if(!i.participantId)return Rn({tournamentRecord:n,participant:i});const{participant:s}=Ro({participantId:i.participantId,tournamentRecord:n});if(!s)return Rn({tournamentRecord:n,participant:i});const{participantRoleResponsibilties:a,individualParticipantIds:c,participantOtherName:l,participantName:u,participantRole:d,participantType:p,onlineResources:v,contacts:f,person:m}=i;if(p&&s.participantType!==p)return{error:CF};const g={};if(f&&(g.contacts=f),v&&(g.onlineResources=v),u&&typeof u=="string"&&(g.participantName=u),l&&typeof l=="string"&&(g.participantOtherName=l),Array.isArray(c)){const{tournamentParticipants:h}=Qt({participantFilters:{participantTypes:[Pc.INDIVIDUAL]},tournamentRecord:n}),_=h==null?void 0:h.map(Xe);if(_){const I=c.filter(P=>typeof P=="string"&&_.includes(P));([dr,He].includes(p||s.participantType)||p===we&&(I.length===2||o))&&(g.individualParticipantIds=I),s.participantType===Pc.PAIR&&t&&(g.participantName=qle({individualParticipants:h,newValues:g}))}}return Object.keys(gb).includes(d)&&(g.participantRole=d),Object.keys(Pc).includes(p)&&(g.participantType=p),Array.isArray(a)&&(g.participantRoleResponsibilties=a),s.participantType===Pc.INDIVIDUAL&&m&&Yle({updateParticipantName:t,existingParticipant:s,newValues:g,person:m}),Object.assign(s,_e(g)),e&&dg({individualParticipantIds:[s.participantId],groupingParticipantId:e,removeFromOtherTeams:r,tournamentRecord:n}),xe({topic:Ht,payload:{tournamentId:n.tournamentId,participants:[s]}}),Hle({participant:ue(s)},B)}function qle({individualParticipants:t,newValues:e}){const r=e.individualParticipantIds;let n=t.filter(({participantId:o})=>r.includes(o)).map(({person:o})=>o==null?void 0:o.standardFamilyName).filter(Boolean).sort().join("/");return r.length===1&&(n+="/Unknown"),n}function Yle({updateParticipantName:t,existingParticipant:e,newValues:r,person:n}){const o={},{standardFamilyName:i,standardGivenName:s,nationalityCode:a,personId:c,sex:l}=n;l&&Object.keys(AP).includes(l)&&(o.sex=l);let u;if(c&&typeof c=="string"&&(o.personId=c),a&&typeof a=="string"&&(zle(a)||a==="")&&(o.nationalityCode=a),i&&typeof i=="string"&&i.length>1&&(o.standardFamilyName=i,u=!0),s&&typeof s=="string"&&s.length>1&&(o.standardGivenName=s,u=!0),u&&t){const d=`${o.standardGivenName} ${o.standardFamilyName}`;r.participantName=d}Object.assign(e.person,o)}function zle(t){return qo.flatMap(({iso:e,ioc:r})=>[e,r]).filter(Boolean).includes(t)}var Kle=Object.defineProperty,iC=Object.getOwnPropertySymbols,Qle=Object.prototype.hasOwnProperty,Jle=Object.prototype.propertyIsEnumerable,sC=(t,e,r)=>e in t?Kle(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Zle=(t,e)=>{for(var r in e||(e={}))Qle.call(e,r)&&sC(t,r,e[r]);if(iC)for(var r of iC(e))Jle.call(e,r)&&sC(t,r,e[r]);return t};function aC({drawDefinition:t,timeItem:e}){if(!t)return{error:_n};if(!e)return{error:Vh};const r=e&&Object.keys(e),n=["itemType","itemValue"];if(!(n.filter(s=>r.includes(s)).length===n.length))return{error:Lh};t.timeItems||(t.timeItems=[]);const i=new Date().toISOString();return Object.assign(e,{createdAt:i}),t.timeItems.push(e),Rc({drawDefinition:t}),Zle({},B)}var Xle=Object.defineProperty,eue=Object.defineProperties,tue=Object.getOwnPropertyDescriptors,Yd=Object.getOwnPropertySymbols,cC=Object.prototype.hasOwnProperty,lC=Object.prototype.propertyIsEnumerable,uC=(t,e,r)=>e in t?Xle(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zd=(t,e)=>{for(var r in e||(e={}))cC.call(e,r)&&uC(t,r,e[r]);if(Yd)for(var r of Yd(e))lC.call(e,r)&&uC(t,r,e[r]);return t},Kd=(t,e)=>eue(t,tue(e)),rue=(t,e)=>{var r={};for(var n in t)cC.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Yd)for(var n of Yd(t))e.indexOf(n)<0&&lC.call(t,n)&&(r[n]=t[n]);return r};function fl({removePriorValues:t,tournamentRecord:e,participantId:r,scaleItem:n}){let o,i;if(!dC({scaleItem:n}))return{error:Cl};if(r&&Array.isArray(e.participants)&&(i=e.participants.find(s=>s.participantId===r),i)){const s=pC({removePriorValues:t,participant:i,scaleItem:n});if(s.error)return s;o=!s.valueChanged;const{topics:a}=Pn();a.includes(Ht)&&xe({topic:Ht,payload:{tournamentId:e.tournamentId,participants:[i]}})}return o&&Kd(zd({},B),{info:kh,existingValue:n.scaleValue})||i&&Kd(zd({},B),{newValue:n.scaleValue})||{error:wt}}function nue({scaleItemsWithParticipantIds:t=[],removePriorValues:e,tournamentRecord:r,auditData:n,context:o}){var i;if(!r)return{error:ee};if(!r.participants)return{error:Qa};let s=0;const a={},c=[];for(const d of t){const p=d==null?void 0:d.participantId;Array.isArray(d==null?void 0:d.scaleItems)&&d.scaleItems.forEach(v=>{if(dC({scaleItem:v}))Array.isArray(a[p])||(a[p]=[]),a[p].push(v);else return{error:Cl}})}r.participants.forEach(d=>{const{participantId:p}=d||{};Array.isArray(a[p])&&a[p].forEach(v=>{pC({participant:d,scaleItem:v,removePriorValues:e}),c.push(d),s++})});const l=s?void 0:Ja,{topics:u}=Pn();if(u.includes(Ht)&&s&&xe({topic:Ht,payload:{tournamentId:r.tournamentId,participants:c}}),o){const d=o,{eventId:p,drawId:v}=d,f=rue(d,["eventId","drawId"]),m=((i=f.scaleAttributes)==null?void 0:i.scaleType)&&[f.scaleAttributes.scaleType];if(Object.keys(f).length){const g={itemType:OI,itemValue:f};if(m&&(g.itemSubTypes=m),v||p){const{drawDefinition:h,event:_}=xt({tournamentRecord:r,eventId:p,drawId:v});v&&aC({drawDefinition:h,timeItem:g}),p&&zo({event:_,timeItem:g})}else bo({tournamentRecord:r,timeItem:g})}}return n&&u.includes(pc)&&xe({topic:pc,payload:n}),_e(Kd(zd({},B),{modificationsApplied:s,info:l}))}function dC({scaleItem:t}){const e=t&&Object.keys(t),r=["scaleType","eventType","scaleName"];return!!(r.filter(o=>e==null?void 0:e.includes(o)).length===r.length)}function pC({removePriorValues:t,participant:e,scaleItem:r}){if(!e)return{error:Ls};const n=r&&Object.keys(r),o=["scaleType","eventType","scaleName"];if(!(o.filter(u=>n.includes(u)&&r[u]).length===o.length))return{error:Cl};const s=new Date().toISOString();e.timeItems||(e.timeItems=[]);const{scaleItem:a}=ro({scaleAttributes:r,participant:e}),c=u=>[void 0,null,""].includes(u),l=!(c(a==null?void 0:a.scaleValue)&&c(r.scaleValue))&&JSON.stringify(a==null?void 0:a.scaleValue)!==JSON.stringify(r.scaleValue);if(l){const{scaleType:u,eventType:d,scaleName:p}=r,v=[zi,u,d,p].join("."),f=_e({itemValue:r.scaleValue,itemDate:r.scaleDate,createdAt:s,itemType:v});r.scaleId&&(f.itemSubTypes=[r.scaleId]),t&&(e.timeItems=e.timeItems.filter(m=>m.itemType!==v)),e.timeItems.push(f)}return Kd(zd({},B),{valueChanged:l,newValue:r.scaleValue})}const oue={getTournamentPenalties:Zb,modifyPenalty:Xb,removePenalty:Jb,addPenalty:Qb,createGroupParticipant:_le,scaledTeamAssignment:ule,deleteParticipants:ja,addParticipants:to,addParticipant:Rn,addPersons:Mce,addIndividualParticipantIds:dg,removeIndividualParticipantIds:OA,modifyIndividualParticipantIds:qce,removeParticipantIdsFromAllTeams:qm,getParticipantMembership:Ice,generateTeamsFromParticipantAttribute:kU,getParticipantIdFinishingPositions:Tce,modifyParticipant:pg,modifyParticipantName:Rle,modifyParticipantOtherName:Ole,mergeParticipants:Ble,getPairedParticipant:Un,filterParticipants:sd,setParticipantScaleItem:fl,setParticipantScaleItems:nue,modifyParticipantsSignInStatus:rle,getParticipantEventDetails:_ce,getEligibleVoluntaryConsolationParticipants:hce,findParticipant:_x,getTournamentParticipants:Qt,getParticipantSchedules:bce,getTournamentPersons:Ule,getParticipants:ys};var iue=Object.defineProperty,fC=Object.getOwnPropertySymbols,sue=Object.prototype.hasOwnProperty,aue=Object.prototype.propertyIsEnumerable,vC=(t,e,r)=>e in t?iue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Va=(t,e)=>{for(var r in e||(e={}))sue.call(e,r)&&vC(t,r,e[r]);if(fC)for(var r of fC(e))aue.call(e,r)&&vC(t,r,e[r]);return t};function cue({removePriorValues:t=!0,stageSeedingScaleNames:e,seedingScaleNames:r,tournamentRecord:n,status:o=$n,drawIds:i=[],event:s}){var a,c,l,u;if(!n)return{error:ee};if(!s)return{error:Le};const d=`${Ar}.${Ur}`,{timeItem:p}=So({itemType:d,event:s}),v=(p==null?void 0:p.itemValue)||{[o]:{}},f=(((a=v[o].seeding)==null?void 0:a.seedingScaleNames)||r)&&Va(Va({},(c=v[o].seeding)==null?void 0:c.seedingScaleNames),r),m=(((l=v[o].seeding)==null?void 0:l.stageSeedingScaleNames)||e)&&Va(Va({},(u=v[o].seeding)==null?void 0:u.stageSeedingScaleNames),e);return v[o].seeding=_e({stageSeedingScaleNames:m,seedingScaleNames:f,published:!0,drawIds:i}),zo({event:s,timeItem:{itemValue:v,itemType:d},removePriorValues:t}),xe({topic:PB,payload:{tournamentId:n.tournamentId,eventId:s.eventId,drawIds:i}}),Va({},B)}function lue({removePriorValues:t=!0,seedingScaleNames:e,tournamentRecord:r,status:n=$n,stages:o,event:i}){var s,a;if(!r)return{error:ee};if(!i)return{error:Le};const c=`${Ar}.${Ur}`,{timeItem:l}=So({itemType:c,event:i}),u=(l==null?void 0:l.itemValue)||{[n]:{}};if(u[n]){if(Array.isArray(o)&&((s=u[n].seeding)!=null&&s.stageSeedingScaleNames))for(const p of o)u[n].seeding.stageSeedingScaleNames[p]&&delete u[n].seeding.stageSeedingScaleNames[p];Array.isArray(e)&&((a=u[n].seeding)!=null&&a.seedingScaleNames)&&(u[n].seeding.seedingScaleNames=u[n].seeding.seedingScaleNames.filter(p=>!e.includes(p))),!o&&!e&&delete u[n].seeding}return zo({event:i,timeItem:{itemValue:u,itemType:c},removePriorValues:t}),xe({topic:jI,payload:{tournamentId:r.tournamentId,eventId:i.eventId}}),Va({},B)}function uue({tournamentRecord:t,policyDefinitions:e}){if(!t)return{error:ee};const r=t.events||[],n=(t==null?void 0:t.participants)||[],{tournamentInfo:o}=el({tournamentRecord:t}),{venues:i}=_f({tournamentRecord:t}),s=r.map(c=>{const{eventId:l}=c,u=(({eventId:f,eventName:m,eventType:g,eventLevel:h,surfaceCategory:_,matchUpFormat:I,category:P,gender:O,startDate:y,endDate:S,ballType:T,discipline:E})=>({eventId:f,eventName:m,eventType:g,eventLevel:h,surfaceCategory:_,matchUpFormat:I,category:P,gender:O,startDate:y,endDate:S,ballType:T,discipline:E}))(c),d=dc({tournamentRecord:t,event:c}).scheduleTiming,p=(c.drawDefinitions||[]).map(f=>{const m=(({drawId:P,drawName:O,matchUpFormat:y,updatedAt:S})=>({drawId:P,drawName:O,matchUpFormat:y,updatedAt:S}))(f),{pendingMatchUps:g,completedMatchUps:h,upcomingMatchUps:_,abandonedMatchUps:I}=cs({includeByeMatchUps:!1,requireParticipants:!0,tournamentParticipants:n,context:{eventId:l},policyDefinitions:e,tournamentRecord:t,inContext:!0,drawDefinition:f,scheduleTiming:d,event:c});return{drawInfo:m,matchUps:{abandonedMatchUps:I,completedMatchUps:h,upcomingMatchUps:_,pendingMatchUps:g}}}),{timeItem:v}=So({itemType:`${Ar}.${Ur}`,event:c});return Object.assign(u,{publish:v==null?void 0:v.itemValue,drawsData:p}),u});return{allEventData:{tournamentInfo:o,venuesData:i,eventsData:s}}}function due({removePriorValues:t=!0,tournamentRecord:e,status:r=$n,event:n}){if(!e)return{error:ee};if(!n)return{error:Le};const o=`${Ar}.${Ur}`,{timeItem:i}=So({itemType:o,event:n}),s=(i==null?void 0:i.itemValue)||{[r]:{}};return delete s[r].drawIds,delete s[r].structureIds,zo({event:n,timeItem:{itemValue:s,itemType:o},removePriorValues:t}),xe({topic:DI,payload:{tournamentId:e.tournamentId,eventId:n.eventId}}),Object.assign({eventId:n.eventId},B)}function mC({drawDefinition:t}){const e=t.links||[],r={},n={};let o=e.map(v=>{const f=v.source.structureId,m=v.target.structureId;return n[m]=n[m]||v.target.feedProfile===an,r[m]=Ve([...r[m]||[],f]).filter(Boolean),[v.source.structureId,v.target.structureId]});const i=o.length;le(0,Math.ceil(i/2)).forEach(()=>{o=le(0,i).map(v=>{const f=o[v],m=o.reduce((g,h)=>Gt(f,h)?g.concat(...h):g,[])||[];return Ve(f.concat(...m))})});const s=o[0],a=(v,f)=>jt(v,f).length===v.length,c=o.slice(1).reduce((v,f)=>v&&a(f,s),!0),l=[s].filter(Boolean),u=[s].filter(Boolean);return(t.structures||[]).forEach(v=>{const{structureId:f,stage:m}=v;l.find(h=>h.includes(f))||(l.push([f]),m!==Ct&&u.push(f))}),{allStructuresLinked:c&&u.length===1,sourceStructureIds:r,hasDrawFeedProfile:n,structureGroups:l}}var pue=Object.defineProperty,fue=Object.defineProperties,vue=Object.getOwnPropertyDescriptors,gC=Object.getOwnPropertySymbols,mue=Object.prototype.hasOwnProperty,gue=Object.prototype.propertyIsEnumerable,hC=(t,e,r)=>e in t?pue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fg=(t,e)=>{for(var r in e||(e={}))mue.call(e,r)&&hC(t,r,e[r]);if(gC)for(var r of gC(e))gue.call(e,r)&&hC(t,r,e[r]);return t},hue=(t,e)=>fue(t,vue(e));function _C({tournamentParticipants:t=[],includePositionAssignments:e,policyDefinitions:r,tournamentRecord:n,inContext:o=!0,drawDefinition:i,noDeepCopy:s,sortConfig:a,context:c,event:l}){if(!i)return{error:pe};const u=(({matchUpFormat:O,updatedAt:y,drawType:S,drawName:T,drawId:E})=>({matchUpFormat:O,updatedAt:y,drawName:T,drawType:S,drawId:E}))(i);let d,p;const{allStructuresLinked:v,sourceStructureIds:f,hasDrawFeedProfile:m,structureGroups:g}=mC({drawDefinition:i});if(!v)return{error:{error:gF}};let h=!1,_=!1;const P=g.map(O=>{const y={},S=O.map(T=>{const{structure:E}=Te({drawDefinition:i,structureId:T}),{seedAssignments:b}=dn({drawDefinition:i,structure:E,event:l});return E.stage===de&&E.stageSequence===1&&(d=b),E.stage===Ie&&E.stageSequence===1&&(p=b),E}).sort((T,E)=>Ii(T,E,a)).map(T=>{var E;const{structureId:b}=T;let N=[];[de,$t,st].includes(T.stage)&&(N=d),T.stage===Ie&&(N=p);const{matchUps:w,roundMatchUps:$,roundProfile:U}=ze({seedAssignments:(E=T==null?void 0:T.seedAssignments)!=null&&E.length?void 0:N,context:fg({drawId:u.drawId},c),tournamentParticipants:t,policyDefinitions:r,tournamentRecord:n,drawDefinition:i,structure:T,inContext:o,event:l}),{positionAssignments:A}=et({structure:T}),M=A.filter(gu).map(F=>{_=!0;const{drawPosition:R,participantId:G}=F,{extension:x}=Vt({element:F,name:jo});return x&&{drawPosition:R,participantId:G,participantResult:x.value}}).filter(F=>F==null?void 0:F.participantResult),C=(({stageSequence:F,structureName:R,structureType:G,matchUpFormat:x,stage:z})=>({stageSequence:F,structureName:R,structureType:G,matchUpFormat:x,stage:z}))(T);C.sourceStructureIds=f[b],C.hasDrawFeedProfile=m[b],C.positionAssignments=A,C.structureActive=w.reduce((F,R)=>{var G;const x=[St,uo,Be,er,Ge,Xr,bt,_t].includes(R.matchUpStatus);return F||x||!!R.winningSide||!!((G=R.score)!=null&&G.scoreStringSide1)},!1);const D=w.reduce((F,R)=>F&&[qe,St,er,Ge,Be,yr].includes(R.matchUpStatus),!!w.length);return C.structureCompleted=D,y[b]=D,C.structureActive&&(h=!0),hue(fg({},C),{participantResults:M,seedAssignments:N,roundMatchUps:$,roundProfile:U,structureId:b})});return S.forEach(T=>{var E;e||delete T.positionAssignments,T.sourceStructuresComplete=(E=T.sourceStructureIds)==null?void 0:E.every(b=>y[b])}),S}).flat();return u.drawActive=h,u.participantPlacements=_,u.drawGenerated=P==null?void 0:P.reduce((O,y)=>O||!!(y!=null&&y.roundMatchUps),!1),u.drawCompleted=P==null?void 0:P.reduce((O,y)=>O&&y.structureCompleted,!0),fg({structures:s?P:ue(P,!1,!0),drawInfo:s?u:ue(u,!1,!0)},B)}var _ue=Object.defineProperty,Iue=Object.defineProperties,Pue=Object.getOwnPropertyDescriptors,Qd=Object.getOwnPropertySymbols,IC=Object.prototype.hasOwnProperty,PC=Object.prototype.propertyIsEnumerable,yC=(t,e,r)=>e in t?_ue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vl=(t,e)=>{for(var r in e||(e={}))IC.call(e,r)&&yC(t,r,e[r]);if(Qd)for(var r of Qd(e))PC.call(e,r)&&yC(t,r,e[r]);return t},Jd=(t,e)=>Iue(t,Pue(e)),yue=(t,e)=>{var r={};for(var n in t)IC.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&Qd)for(var n of Qd(t))e.indexOf(n)<0&&PC.call(t,n)&&(r[n]=t[n]);return r};function SC({includePositionAssignments:t,tournamentRecord:e,participantsProfile:r,policyDefinitions:n,usePublishState:o,status:i=$n,sortConfig:s,event:a}){var c;const l=ue(e,!1,!0),u=ue(a,!1,!0);if(!l)return{error:ee};if(!u)return{error:Le};const{eventId:d}=u,{tournamentId:p,endDate:v}=l,{timeItem:f}=So({itemType:`${Ar}.${Ur}`,event:u}),m=(c=f==null?void 0:f.itemValue)==null?void 0:c[i],{tournamentParticipants:g}=Qt(Jd(vl({withGroupings:!0,withEvents:!1,withDraws:!1},r),{tournamentRecord:l})),h=({structureId:b})=>{var N;return!o||!((N=m==null?void 0:m.structureIds)!=null&&N.length)||m.structureIds.includes(b)},_=({drawId:b})=>{var N;return!o||!((N=m==null?void 0:m.drawIds)!=null&&N.length)||m.drawIds.includes(b)},P=(u.drawDefinitions||[]).filter(_).map(b=>(({drawInfo:N,structures:w})=>Jd(vl({},N),{structures:w}))(_C({context:{eventId:d,tournamentId:p,endDate:v},includePositionAssignments:t,tournamentParticipants:g,noDeepCopy:!0,policyDefinitions:n,tournamentRecord:l,drawDefinition:b,sortConfig:s,event:u}))).map(b=>{var N=b,{structures:w}=N,$=yue(N,["structures"]);return Jd(vl({},$),{structures:w==null?void 0:w.filter(h)})}).filter(b=>{var N;return(N=b.structures)==null?void 0:N.length}),{tournamentInfo:O}=el({tournamentRecord:l}),S=(l.venues||[]).map(b=>(({venueData:N})=>vl({},N))(tu({tournamentRecord:l,venueId:b.venueId}))),T=(({eventId:b,eventName:N,eventType:w,eventLevel:$,surfaceCategory:U,matchUpFormat:A,category:M,gender:C,startDate:D,endDate:F,ballType:R,discipline:G})=>({eventId:b,eventName:N,eventType:w,eventLevel:$,surfaceCategory:U,matchUpFormat:A,category:M,gender:C,startDate:D,endDate:F,ballType:R,discipline:G}))(u),E={tournamentInfo:O,venuesData:S,eventInfo:T,drawsData:P};return E.eventInfo.publish={createdAt:f==null?void 0:f.createdAt,state:f==null?void 0:f.itemValue},Jd(vl({},B),{eventData:E})}var Sue=Object.defineProperty,Oue=Object.defineProperties,bue=Object.getOwnPropertyDescriptors,OC=Object.getOwnPropertySymbols,Tue=Object.prototype.hasOwnProperty,Eue=Object.prototype.propertyIsEnumerable,bC=(t,e,r)=>e in t?Sue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wue=(t,e)=>{for(var r in e||(e={}))Tue.call(e,r)&&bC(t,r,e[r]);if(OC)for(var r of OC(e))Eue.call(e,r)&&bC(t,r,e[r]);return t},$ue=(t,e)=>Oue(t,bue(e));function ml({policyDefinitions:t,removePriorValues:e,tournamentRecord:r,status:n=$n,event:o,drawIdsToRemove:i,drawIdsToAdd:s,drawIds:a,includePositionAssignments:c,structureIdsToRemove:l,structureIdsToAdd:u,structureIds:d}){var p,v,f,m,g,h,_;if(!r)return{error:ee};if(!o)return{error:Le};if(!t){const{appliedPolicies:E}=at({tournamentRecord:r,event:o});t=E}const I=`${Ar}.${Ur}`,P=((p=o.drawDefinitions)==null?void 0:p.map(({drawId:E})=>E))||[],{timeItem:O}=So({itemType:I,event:o});!a&&!s&&!i?a=P:!a&&(s!=null&&s.length||i!=null&&i.length)&&(a=((f=(v=O==null?void 0:O.itemValue)==null?void 0:v.PUBLIC)==null?void 0:f.drawIds)||[]),a=(a||[]).filter(E=>!(i!=null&&i.length)||!i.includes(E)),s!=null&&s.length&&(a=Ve(a.concat(...s.filter(E=>P.includes(E))))),!d&&(u!=null&&u.length||l!=null&&l.length)&&(d=((g=(m=O==null?void 0:O.itemValue)==null?void 0:m.PUBLIC)==null?void 0:g.drawIds)||[]),d=(d||[]).filter(E=>!(l!=null&&l.length)||!l.includes(E)),u!=null&&u.length&&(d=Ve(d.push(...u)));const y={itemValue:{[n]:{drawIds:a,structureIds:d}},itemType:I};zo({event:o,timeItem:y,removePriorValues:e});const{eventData:S}=SC({includePositionAssignments:c,usePublishState:!0,policyDefinitions:t,tournamentRecord:r,event:o}),T=(_=(h=S==null?void 0:S.eventInfo)==null?void 0:h.publish)==null?void 0:_.state;return S.drawsData=S.drawsData.filter(({drawId:E})=>{var b;return(b=T==null?void 0:T.PUBLIC)==null?void 0:b.drawIds.includes(E)}),xe({payload:{eventData:S,tournamentId:r.tournamentId},topic:IB}),$ue(wue({},B),{eventData:S})}const Nue={getTournamentInfo:el,getVenueData:tu,getCourtInfo:QI,getAllEventData:uue,getEventData:SC,getDrawData:_C,unPublishEventSeeding:lue,publishEventSeeding:cue,unPublishEvent:due,publishEvent:ml,unPublishOrderOfPlay:sT,publishOrderOfPlay:aT};var Aue=Object.defineProperty,Uue=Object.defineProperties,Cue=Object.getOwnPropertyDescriptors,TC=Object.getOwnPropertySymbols,Mue=Object.prototype.hasOwnProperty,Due=Object.prototype.propertyIsEnumerable,EC=(t,e,r)=>e in t?Aue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jue=(t,e)=>{for(var r in e||(e={}))Mue.call(e,r)&&EC(t,r,e[r]);if(TC)for(var r of TC(e))Due.call(e,r)&&EC(t,r,e[r]);return t},Rue=(t,e)=>Uue(t,Cue(e));function Fue({tournament:t}){if(!t)return{error:ee};const{providerTournamentID:e,hostCountryCode:r,tournamentLevel:n,totalPrizeMoney:o,tournamentName:i,extensions:s,startDate:a,endDate:c}=t,l=lg({hostCountryCode:r,tournamentLevel:n,totalPrizeMoney:o,tournamentName:i,tournamentId:e,extensions:s,startDate:a,endDate:c});l.events=[];for(const u of t.events||[]){const{extensions:d,ageCategory:p,discipline:v,eventType:f,eventId:m,gender:g,stages:h}=u,_={drawDefinitions:Lue(h),category:{ageCategory:p},gender:["M",ct].includes(g)&&ct||["F",mt].includes(g)&&mt||void 0,eventType:["D",br].includes(f)&&br||["T",Tt].includes(f)?Tt:Hn,extensions:d,discipline:v,eventId:m};l.events.push(_)}return Rue(jue({},B),{tournamentRecord:l})}function Lue(t){const e=[];for(const r of t||[]){const{stageType:n}=r,o=["M",de].includes(n)&&de||["Q",Ie].includes(n)&&Ie||["C",$t].includes(n)&&$t||["P",st].includes(n)&&st||void 0;for(const i of r.draws||[]){const{drawId:s,drawSize:a,matchUps:c}=i,l={stage:o,drawId:s,drawSize:a};e.push(l),console.log(c.map(({roundNumber:u,roundPosition:d})=>({roundNumber:u,roundPosition:d})),{draw:i,drawDefinition:l})}}return e}const Vue={ABANDONED:"ABANDONED",ACTIVE:"ACTIVE",CANCELLED:"CANCELLED",COMPLETED:"COMPLETED",IN_PROGRESS:"IN_PROGRESS"};var xue=Object.defineProperty,wC=Object.getOwnPropertySymbols,Bue=Object.prototype.hasOwnProperty,kue=Object.prototype.propertyIsEnumerable,$C=(t,e,r)=>e in t?xue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Gue=(t,e)=>{for(var r in e||(e={}))Bue.call(e,r)&&$C(t,r,e[r]);if(wC)for(var r of wC(e))kue.call(e,r)&&$C(t,r,e[r]);return t};function Wue({tournamentRecord:t,status:e}){return t?e&&!Object.keys(Vue).includes(e)?{error:Z,info:"Unknown status"}:(t.tournamentStatus=e,Gue({},B)):{error:ee}}var Hue=Object.defineProperty,que=Object.defineProperties,Yue=Object.getOwnPropertyDescriptors,NC=Object.getOwnPropertySymbols,zue=Object.prototype.hasOwnProperty,Kue=Object.prototype.propertyIsEnumerable,AC=(t,e,r)=>e in t?Hue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Que=(t,e)=>{for(var r in e||(e={}))zue.call(e,r)&&AC(t,r,e[r]);if(NC)for(var r of NC(e))Kue.call(e,r)&&AC(t,r,e[r]);return t},Jue=(t,e)=>que(t,Yue(e));function vg({tournamentRecord:t}){var e;if(!t)return{error:ee};const r={positionsNoOutcomes:[],canBePruned:[],matchPlay:[],inactive:[],drawAnalysis:{}};return((e=t.events)==null?void 0:e.map(o=>o==null?void 0:o.drawDefinitions).flat().filter(Boolean)).forEach(o=>{let i=0,s=0,a=0;const{allStructuresLinked:c}=mC({drawDefinition:o}),u=((o==null?void 0:o.structures)||[]).map(I=>{const{stage:P,stageSequence:O,structureId:y}=I,S=ts[P],{inContextStructureMatchUps:T}=Gc({drawDefinition:o,structure:I}),E=T==null?void 0:T.filter(({winningSide:x})=>x),b=E.filter(Boolean).length||0;s+=b,a+=T.length-s;const N=Math.max(E.filter(({roundNumber:x})=>x===1).map(({roundPosition:x})=>x)),{positionAssignments:w}=et({structure:I}),$=w==null?void 0:w.filter(({participantId:x})=>x);i+=$.length;const U=((w==null?void 0:w.length)||0)-(($==null?void 0:$.length)||0),{roundMatchUps:A,roundProfile:M,roundNumbers:C,maxMatchUpsCount:D}=pr({matchUps:T}),F=Object.keys(M).filter(x=>!M[x].inactiveRound).map(x=>parseInt(x)),R=Object.keys(M).filter(x=>M[x].inactiveRound).map(x=>parseInt(x)),G=Object.values(M).every(x=>x.inactiveRound);return{positionsAssignedCount:($==null?void 0:$.length)||0,maxWinningSideFirstRoundPosition:N,unassignedPositionsCount:U,inactiveStructure:G,maxMatchUpsCount:D,inactiveRounds:R,roundMatchUps:A,activeRounds:F,roundNumbers:C,roundProfile:M,structureId:y,stageSequence:O,orderNumber:S,stage:P}}),d=u.find(I=>I.orderNumber===2&&I.stageSequence===1),p=u.filter(({inactiveStructure:I})=>!I).length,{links:v}=Fc({drawDefinition:o,structureId:d.structureId}),f=parseInt(d.activeRounds[0])===1&&d.activeRounds.length===1&&p===1,m=u==null?void 0:u.every(({inactiveStructure:I})=>I),g=!v.length&&d.activeRounds.length&&(d.roundProfile[1].inactiveCount||d.inactiveRounds.length),h=o.drawId;i&&!s&&r.positionsNoOutcomes.push(h),m&&r.inactive.push(h),f&&r.matchPlay.push(h),g&&r.canBePruned.push(h);const _={matchUpsWithWinningSideCount:s,matchUpsNoOutcomeCount:a,positionsAssignedCount:i,allStructuresLinked:c,structuresData:u,inactiveDraw:m,isMatchPlay:f,drawId:h};r.drawAnalysis[h]=_}),Jue(Que({},B),{drawsAnalysis:r})}function Zue(t){var e,r,n,o,i;const s=(e=t.participants)==null?void 0:e.filter(({participantType:p})=>p===Ye),a=(s==null?void 0:s.length)===2,c=((r=t.events)==null?void 0:r.length)===1&&t.events[0],l=((n=c==null?void 0:c.drawDefinitions)==null?void 0:n.length)===1&&c.drawDefinitions[0],u=((o=l==null?void 0:l.structures)==null?void 0:o.length)===1&&l.structures[0],d=((i=u==null?void 0:u.positionAssignments)==null?void 0:i.length)===2;return!!(c.tieFormat&&a&&d)}var Xue=Object.defineProperty,ede=Object.defineProperties,tde=Object.getOwnPropertyDescriptors,UC=Object.getOwnPropertySymbols,rde=Object.prototype.hasOwnProperty,nde=Object.prototype.propertyIsEnumerable,CC=(t,e,r)=>e in t?Xue(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ode=(t,e)=>{for(var r in e||(e={}))rde.call(e,r)&&CC(t,r,e[r]);if(UC)for(var r of UC(e))nde.call(e,r)&&CC(t,r,e[r]);return t},ide=(t,e)=>ede(t,tde(e));function sde({tournamentRecord:t}){if(!t)return{error:ee};const{drawsAnalysis:e}=vg({tournamentRecord:t}),r={isDual:Zue(t),drawsAnalysis:e};return ide(ode({},B),{analysis:r})}var ade=Object.defineProperty,MC=Object.getOwnPropertySymbols,cde=Object.prototype.hasOwnProperty,lde=Object.prototype.propertyIsEnumerable,DC=(t,e,r)=>e in t?ade(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jC=(t,e)=>{for(var r in e||(e={}))cde.call(e,r)&&DC(t,r,e[r]);if(MC)for(var r of MC(e))lde.call(e,r)&&DC(t,r,e[r]);return t};function ude({tournamentRecord:t,promotionalName:e,tournamentName:r,formalName:n}){return t?(r&&(t.tournamentName=r),e&&(t.promotionalName=e),n&&(t.formalName=n),t.promotionalName===t.tournamentName&&delete t.promotionalName,t.formalName===t.tournamentName&&delete t.formalName,jC({},B)):{error:ee}}function dde({tournamentRecord:t,notes:e}){return t?Vf({element:t,notes:e}):{error:ee}}function pde({tournamentRecord:t,categories:e}){return t?(e=(e||[]).filter(r=>r.categoryName&&r.type),t.tournamentCategories=e,jC({},B)):{error:ee}}var fde=Object.defineProperty,RC=Object.getOwnPropertySymbols,vde=Object.prototype.hasOwnProperty,mde=Object.prototype.propertyIsEnumerable,FC=(t,e,r)=>e in t?fde(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gde=(t,e)=>{for(var r in e||(e={}))vde.call(e,r)&&FC(t,r,e[r]);if(RC)for(var r of RC(e))mde.call(e,r)&&FC(t,r,e[r]);return t};function hde({tournamentRecord:t}){var e;if(!t)return{error:ee};const{startDate:r,endDate:n}=t,o=Gp(r,n),i=[];for(const s of t.venues||[])(e=s==null?void 0:s.courts)!=null&&e.length&&i.push(...s.courts);for(const s of i){const{startTime:a,endTime:c}=(s.dateAvailability||[]).reduce((u,d)=>{const p=Re(u.startTime),v=Re(u.endTime);return d.startTime&&Re(d.startTime)<p&&(u.startTime=d.startTime),d.endTime&&Re(d.endTime)>v&&(u.endTime=d.endTime),u},{startTime:"08:00",endTime:"18:00"}),l=o.map(u=>s.dateAvailability.find(p=>p.date===u)||{date:u,startTime:a,endTime:c});s.dateAvailability=l}return gde({},B)}var _de=Object.defineProperty,Ide=Object.defineProperties,Pde=Object.getOwnPropertyDescriptors,LC=Object.getOwnPropertySymbols,yde=Object.prototype.hasOwnProperty,Sde=Object.prototype.propertyIsEnumerable,VC=(t,e,r)=>e in t?_de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ode=(t,e)=>{for(var r in e||(e={}))yde.call(e,r)&&VC(t,r,e[r]);if(LC)for(var r of LC(e))Sde.call(e,r)&&VC(t,r,e[r]);return t},bde=(t,e)=>Ide(t,Pde(e));function mg({tournamentRecord:t,startDate:e,endDate:r}){var n;if(!t)return{error:ee};if(e&&!Sn.test(e)||r&&!Sn.test(r))return{error:cr};if(!e&&!r)return{error:Eh};if(r&&e&&new Date(r)<new Date(e))return{error:Z};let o;(e&&t.startDate&&new Date(e)>new Date(t.startDate)||r&&t.endDate&&new Date(r)<new Date(t.endDate))&&(o=!0),e&&(t.startDate=e),r&&(t.endDate=r),e&&t.endDate&&new Date(e)>new Date(t.endDate)&&(t.endDate=e),r&&t.startDate&&new Date(r)<new Date(t.startDate)&&(t.startDate=r);const i=o&&((n=wde({tournamentRecord:t}))==null?void 0:n.unscheduledMatchUpIds);return hde({tournamentRecord:t}),xe({topic:_B,payload:{startDate:e,endDate:r}}),bde(Ode({},B),{unscheduledMatchUpIds:i})}function Tde({tournamentRecord:t,startDate:e}){return mg({tournamentRecord:t,startDate:e})}function Ede({tournamentRecord:t,endDate:e}){return mg({tournamentRecord:t,endDate:e})}function wde({tournamentRecord:t}){const{matchUps:e}=Bt({tournamentRecord:t}),r=t.startDate&&new Date(t.startDate),n=t.endDate&&new Date(t.endDate),o=[],i=[];for(const s of e){const{schedule:a,matchUpId:c}=s;if(a&&a.scheduledDate){const l=new Date(a.scheduledDate);(r&&l<r||n&&l>n)&&(i.push(c),o.includes(a.scheduledDate)||o.push(a.scheduledDate))}}return o.length&&!im({scheduledDates:o,tournamentRecord:t}).clearedScheduleCount?{error:oF}:{unscheduledMatchUpIds:i}}const $de={addNotes:Vf,removeNotes:iG,analyzeDraws:vg,analyzeTournament:sde,getRounds:sE,getProfileRounds:lm,setTournamentName:ude,setTournamentNotes:dde,setTournamentDates:mg,setTournamentEndDate:Ede,setTournamentStartDate:Tde,setTournamentCategories:pde,addTimeItem:kc,addEventTimeItem:zo,addTournamentTimeItem:bo,addParticipantTimeItem:LS,addExtension:tt,addEventExtension:Wn,removeEventExtension:Jl,addTournamentExtension:pi,removeTournamentExtension:ff,addParticipantExtension:Yx,removeParticipantExtension:Kx,addDrawDefinitionExtension:pf,removeDrawDefinitionExtension:zx,setTournamentStatus:Wue,convertPointEight:Fue};function Nde({tournamentRecord:t}){if(!t)return{error:ee};const e=[],{extension:r}=Sr({tournamentRecord:t,name:En});r&&e.push({method:"addTournamentExtension",params:{extension:r}});const n=t.events||[];for(const o of n){const{eventId:i}=o,{extension:s}=mo({event:o,name:En});s&&e.push({method:"addEventExtension",params:{eventId:i,extension:s}})}return{methods:e}}function Ade({drawDefinition:t,courtDayDate:e,matchUpId:r}){return tE({drawDefinition:t,courtDayDate:e,matchUpId:r})}function Ude({tournamentRecord:t}){if(!t)return{error:ee};const e=[],{extension:r}=Sr({name:Gi,tournamentRecord:t});r&&e.push({method:"addTournamentExtension",params:{extension:r}});const n=t.events||[];for(const o of n){const{eventId:i}=o,{extension:s}=mo({name:Gi,event:o});s&&e.push({params:{eventId:i,extension:s},method:"addEventExtension"})}return{methods:e}}var Cde=Object.defineProperty,xC=Object.getOwnPropertySymbols,Mde=Object.prototype.hasOwnProperty,Dde=Object.prototype.propertyIsEnumerable,BC=(t,e,r)=>e in t?Cde(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jde=(t,e)=>{for(var r in e||(e={}))Mde.call(e,r)&&BC(t,r,e[r]);if(xC)for(var r of xC(e))Dde.call(e,r)&&BC(t,r,e[r]);return t};function Rde({scheduleAttributes:t=[Vo,Xi,vc,mc,gc,wn,Bo,go,xo],tournamentRecord:e,drawDefinition:r,matchUpId:n}){var o,i;const s="clearMatchUpSchedule",a=r?(o=Dr({matchUpFilters:{matchUpIds:[n]},inContext:!1,drawDefinition:r}).matchUps)==null?void 0:o[0]:(i=Bt({matchUpFilters:{matchUpIds:[n]},tournamentRecord:e,inContext:!1}).matchUps)==null?void 0:i[0];if(!a)return{error:kr};const c=(a.timeItems||[]).filter(l=>!t.includes(l==null?void 0:l.itemType));return a.timeItems=c,Qe({tournamentId:e.tournamentId,context:s,drawDefinition:r,matchUp:a}),jde({},B)}const Fde={allocateTeamMatchUpCourts:Lu,addMatchUpCourtOrder:hv,assignMatchUpCourt:gs,assignMatchUpVenue:ha,clearMatchUpSchedule:Rde,addMatchUpScheduleItems:hb,addMatchUpScheduledDate:Gv,addMatchUpScheduledTime:Wv,addMatchUpStartTime:_b,addMatchUpEndTime:Ib,addMatchUpStopTime:Pb,addMatchUpResumeTime:yb,addMatchUpOfficial:Sb,getMatchUpFormatTiming:lf,modifyMatchUpFormatTiming:xv,getModifiedMatchUpFormatTiming:H0,getEventMatchUpFormatTiming:fT,modifyEventMatchUpFormatTiming:K0,removeEventMatchUpFormatTiming:XT,getMatchUpFormatTimingUpdate:Nde,getMatchUpDependencies:Yr,getMatchUpDailyLimits:JT,setMatchUpDailyLimits:$b,getMatchUpDailyLimitsUpdate:Ude,validateSchedulingProfile:pd,setSchedulingProfile:OJ,getSchedulingProfile:Pd,removeMatchUpCourtAssignment:Ade,clearScheduledMatchUps:im,bulkScheduleMatchUps:JS,bulkRescheduleMatchUps:Tb};function Lde({tournamentRecord:t,categoryName:e,categoryType:r}){if(!t)return{error:ee};const{appliedPolicies:n}=at({tournamentRecord:t}),o=n==null?void 0:n[Ys];return((o==null?void 0:o.matchUpFormats)||[]).filter(({categoryNames:s,categoryTypes:a})=>!e&&!a||e&&(s==null?void 0:s.includes(e))||r&&(a==null?void 0:a.includes(r)))}function kC({tournamentRecord:t,categoryName:e,categoryType:r}){if(!t)return{error:ee};const{appliedPolicies:n}=at({tournamentRecord:t}),o=n==null?void 0:n[FV];return((o==null?void 0:o.allowedDrawTypes)||[]).filter(({categoryNames:s,categoryTypes:a})=>!e&&!a||e&&(s==null?void 0:s.includes(e))||r&&(a==null?void 0:a.includes(r)))}function GC({policyDefinitions:t,drawDefinition:e,drawSize:r,drawId:n,event:o,stage:i}){if(!o)return{error:Le};const{entries:s,stageEntries:a}=$A({drawDefinition:e,drawId:n,stage:i,event:o}),c=a.length,{drawSize:l}=Lm({participantCount:c}),u=Vm({drawSize:r||l,policyDefinitions:t,participantCount:c});if(u.error)return W({result:u,stack:"getEntriesAndSeedsCount"});const{seedsCount:d}=u;return{entries:s,seedsCount:d,stageEntries:a}}const Vde={attachPolicies:dm,attachEventPolicies:bE,removeEventPolicy:Y9,findPolicy:qi,getSeedsCount:Vm,getEntriesAndSeedsCount:GC,getAllowedDrawTypes:kC,getAllowedMatchUpFormats:Lde,getAppliedPolicies:at};function Zd({participant:t,eventType:e}){var r,n,o,i,s,a;const c=(r=t==null?void 0:t.person)==null?void 0:r.personId,l=(o=(n=t==null?void 0:t.person)==null?void 0:n.personOtherIds)==null?void 0:o[0],u=(i=t==null?void 0:t.person)==null?void 0:i.tennisId,d=(a=(s=t==null?void 0:t.ratings)==null?void 0:s[e])==null?void 0:a.find(({scaleName:m})=>m===Ny),p=d==null?void 0:d.scaleValue,{wtnRating:v,confidence:f}=p||{};return{timeStamp:d==null?void 0:d.scaleDate,personOtherId:l,confidence:f,wtnRating:v,personId:c,tennisId:u}}var xde=Object.defineProperty,Bde=Object.defineProperties,kde=Object.getOwnPropertyDescriptors,WC=Object.getOwnPropertySymbols,Gde=Object.prototype.hasOwnProperty,Wde=Object.prototype.propertyIsEnumerable,HC=(t,e,r)=>e in t?xde(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qC=(t,e)=>{for(var r in e||(e={}))Gde.call(e,r)&&HC(t,r,e[r]);if(WC)for(var r of WC(e))Wde.call(e,r)&&HC(t,r,e[r]);return t},Hde=(t,e)=>Bde(t,kde(e));function qde({tournamentRecord:t}){if(!t)return{error:ee};const e=t.tournamentId,{participantMap:r}=ys({withScaleValues:!0,withEvents:!0,withSeeding:!0,tournamentRecord:t,withDraws:!0}),o=Bt({matchUpFilters:{matchUpTypes:[ci,Jr]},tournamentRecord:t}).matchUps.flatMap(({sides:f,matchUpType:m})=>f.flatMap(({participant:g,participantId:h})=>m===Jr?g==null?void 0:g.individualParticipantIds:(g==null?void 0:g.participantId)||h).filter(Boolean)).filter(Boolean),i=[],s={},a={},c={};let l=0;const u=({id:f,entry:m,eventId:g,eventType:h})=>{var _;const{qualifyingSeeding:I,mainSeeding:P,entryStatus:O,entryStage:y,drawId:S}=m;s[f]||(s[f]=[]);const{participant:T,events:E}=r[f],b=Zd({participant:T,eventType:h}),N=(_=E==null?void 0:E[g])==null?void 0:_.ranking;O===Zy&&i.push(f),s[f].push(Hde(qC({participantType:T==null?void 0:T.participantType,participantId:f,tournamentId:e,eventType:h,eventId:g,drawId:S,entryStatus:O,entryStage:y},b),{ranking:N,mainSeeding:P,qualifyingSeeding:I}))};for(const f of t.events||[]){const m={},g=E=>{m[E]||(m[E]={count:0}),m[E].count+=1},{drawDefinitions:h=[],eventType:_,eventId:I}=f,P=h.flatMap(({drawId:E,entries:b,structures:N=[]})=>{l+=1;const w=({stage:M,stageSequence:C})=>M===de&&C===1||M===Ie,$=N.filter(w).flatMap(({positionAssignments:M})=>M).map(({participantId:M})=>M).filter(Boolean),U=({participantId:M})=>$.includes(M),A=({participantId:M,entryStatus:C,entryStage:D})=>{var F,R,G,x,z,j,V,L;g(C);const q=(x=(G=(R=(F=r[M])==null?void 0:F.draws)==null?void 0:R[E])==null?void 0:G.seedAssignments)==null?void 0:x[de];return{qualifyingSeeding:(L=(V=(j=(z=r[M])==null?void 0:z.draws)==null?void 0:j[E])==null?void 0:V.seedAssignments)==null?void 0:L[Ie],participantId:M,mainSeeding:q,entryStatus:C,entryStage:D,drawId:E}};return b.filter(U).map(A)}),O=E=>{const b=E.participantId,N=r[b].participant.individualParticipantIds.filter(w=>o.includes(w));return b&&{[b]:{individualParticipantIds:N}}};_===hc?(()=>{const E=Object.assign({},...P.map(O).filter(Boolean)),b=N=>{E[N.participantId].individualParticipantIds.forEach(w=>{u({id:w,eventType:_,eventId:I,entry:N})})};P.forEach(b)})():P.forEach(E=>{u({id:E.participantId,entry:E,eventId:I,eventType:_})});const S=Object.values(m).reduce((E,b)=>E+b.count,0);Object.keys(m).forEach(E=>{m[E].pct=m[E].count/S*100}),c[I]={tournamentId:e,eventId:I,entries:P,entryStatuses:m};const T=Object.assign({},...Wo.flatMap(E=>{var b,N;return[{[E+"_count"]:(b=m[E])==null?void 0:b.count},{[E+"_pct"]:(N=m[E])==null?void 0:N.pct}]}));a[I]=qC({tournamentId:e,eventId:I},T)}const d=Object.values(r).filter(({participant:{participantType:f,participantRole:m}})=>f===Me&&m===qt),v={nonParticipatingEntriesCount:d.filter(({participant:f})=>!o.includes(f.participantId)).map(({participant:f})=>f.participantId).length,individualParticipantsCount:d.length,eventsCount:Object.values(c).length,drawDefinitionsCount:l,tournamentId:e};return{entryStatusReports:Object.values(a).flat(),participantEntryReports:Object.values(s).flat(),eventReports:Object.values(c).flat(),withDrawnParticipantIds:i,tournamentEntryReport:v}}function Yde({matchUps:t,drawId:e,eventId:r,eventType:n}){const o={},i=({matchUpFormat:f})=>{f&&(o[f]||(o[f]=0),o[f]+=1)},s=t.filter(f=>r?f.eventId===r:f.drawId===e).reduce((f,m)=>(i(m),(m.sides||[]).flatMap(g=>{var h;return(((h=g==null?void 0:g.participant)==null?void 0:h.individualParticipants)||[g==null?void 0:g.participant]).filter(Boolean)}).forEach(g=>f[g.participantId]=g),f),{}),a=Object.values(s),c=a.map(f=>Zd({participant:f,eventType:n})).filter(({wtnRating:f})=>f),l=(a.length-c.length)/a.length*100,u=c.reduce((f,m)=>{const{wtnRating:g,confidence:h}=m;return f.totalWTN+=g,f.totalConfidence+=h,f},{totalWTN:0,totalConfidence:0}),d=c!=null&&c.length?u.totalWTN/c.length:0,p=c!=null&&c.length?u.totalConfidence/c.length:0,v=Object.values(o).reduce((f,m)=>f+=m||0,0);return{avgWTN:d,avgConfidence:p,matchUpFormats:o,matchUpsCount:v,pctNoRating:l}}var zde=Object.defineProperty,Kde=Object.defineProperties,Qde=Object.getOwnPropertyDescriptors,YC=Object.getOwnPropertySymbols,Jde=Object.prototype.hasOwnProperty,Zde=Object.prototype.propertyIsEnumerable,zC=(t,e,r)=>e in t?zde(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xde=(t,e)=>{for(var r in e||(e={}))Jde.call(e,r)&&zC(t,r,e[r]);if(YC)for(var r of YC(e))Zde.call(e,r)&&zC(t,r,e[r]);return t},epe=(t,e)=>Kde(t,Qde(e));function tpe({firstFlightOnly:t=!0,extensionProfiles:e,tournamentRecord:r}){var n;if(!r)return{error:ao};const o={},i=Object.assign({},...(e||[]).map(({name:d,label:p,accessor:v})=>{var f,m,g;const h=(m=(f=Sr({tournamentRecord:r,name:d}))==null?void 0:f.extension)==null?void 0:m.value,_=v?(g=Xu({element:h,accessor:v}))==null?void 0:g.value:h;return{[p||d]:_}})),s=r==null?void 0:r.tournamentId,c=Bt({participantsProfile:{withScaleValues:!0},tournamentRecord:r}).matchUps||[],l=d=>{var p,v;const f=(p=fn({itemType:OI,itemSubTypes:[rn],element:{timeItems:d}}))==null?void 0:p.timeItem;return(v=f==null?void 0:f.itemValue)==null?void 0:v.scaleBasis},u=(n=r==null?void 0:r.events)==null?void 0:n.flatMap(({timeItems:d,drawDefinitions:p=[],extensions:v,eventType:f,eventId:m,category:g})=>{var h,_,I,P;const O=v==null?void 0:v.find(N=>N.name===tn),y=(_=(h=O==null?void 0:O.value)==null?void 0:h.flights)==null?void 0:_.map(N=>({[N.drawId]:N.flightNumber})),S=y&&Object.assign({},...y),T=((P=(I=v==null?void 0:v.find(N=>N.name===ql))==null?void 0:I.value)==null?void 0:P.length)||0,E=S&&Math.min(...Object.values(S)),b=l(d);return o[m]={totalPositionManipulations:0,maxPositionManipulations:0,generatedDrawsCount:0,drawDeletionsCount:T,seedingBasis:b?JSON.stringify(b):void 0,tournamentId:s,eventId:m},p.filter(N=>!t||!y||S[N.drawId]===E).flatMap(({matchUpFormat:N,tieFormat:w,timeItems:$,extensions:U,structures:A,drawType:M,drawId:C})=>{const{avgConfidence:D,matchUpFormats:F,matchUpsCount:R,pctNoRating:G,avgWTN:x}=Yde({eventType:f,matchUps:c,drawId:C}),z=l($)||b,j=rpe({extensions:U}),V=(j==null?void 0:j.length)||0;return o[m].totalPositionManipulations+=V,o[m].generatedDrawsCount+=1,V>o[m].maxPositionManipulations&&(o[m].maxPositionManipulations=V),A==null?void 0:A.filter(L=>L.stageSequence===1&&[Ie,de,$t,st].includes(L.stage)).map(L=>{var q,k,H;const Q=[de,st].includes(L.stage)&&c.find(ot=>ot.structureId===L.structureId&&ot.finishingRound===1&&ot.winningSide),K=(k=(q=Q==null?void 0:Q.sides)==null?void 0:q.find(ot=>ot.sideNumber===Q.winningSide))==null?void 0:k.participant,Y=(K==null?void 0:K.participantType)===An&&K.participantId,{individualParticipants:J}=(K==null?void 0:K.participantType)===we&&K||{},te=Zd({participant:(J==null?void 0:J[0])||K,eventType:f}),{personId:ne,personOtherId:oe,tennisId:se,confidence:ve,wtnRating:X}=te||{},ie=Zd({participant:J==null?void 0:J[1],eventType:f}),{personId:fe,personOtherId:$e,tennisId:re,confidence:ae,wtnRating:me}=ie||{},{ageCategoryCode:Se,categoryName:ce,subType:Pe}=g||{},Ae=L.matchUpFormat||N,Ue=(F[Ae]||0)/R*100,{tieFormatName:be,tieFormatDesc:ge}=Nu(w),{tieFormatName:Ne,tieFormatDesc:De}=Nu(L.tieFormat),he=ge===De,ke=!he&&Ne,je=L.tieFormat&&!he&&De,Ze=((H=j==null?void 0:j.filter(ot=>ot.structureId===L.structureId))==null?void 0:H.length)||0;return epe(Xde({},i),{tournamentId:s,eventId:m,structureId:L.structureId,drawId:C,eventType:f,category:Pe,categoryName:ce,ageCategoryCode:Se,flightNumber:S[C],drawType:M,stage:L.stage,seedingBasis:z?JSON.stringify(z):void 0,winningPersonId:ne,winningPersonOtherId:oe,winningPersonTennisId:se,winningPersonWTNrating:X,winningPersonWTNconfidence:ve,winningPerson2Id:fe,winningPerson2OtherId:$e,winningPerson2TennisId:re,winningPerson2WTNrating:me,winningPerson2WTNconfidence:ae,winningTeamId:Y,positionManipulations:Ze,pctNoRating:G,matchUpFormat:Ae,pctInitialMatchUpFormat:Ue,matchUpsCount:R,drawTieFormatName:be,drawTieFormatDesc:ge,tieFormatName:ke,tieFormatDesc:je,avgConfidence:D,avgWTN:x})})})});return{eventStructureReports:Object.values(o),structureReports:u}}function rpe({extensions:t}){var e,r;return(r=(e=t==null?void 0:t.find(({name:n})=>n===Gl))==null?void 0:e.value)==null?void 0:r.slice(1)}const npe={getStructureReports:tpe,getEntryStatusReports:qde};function ope({representativeParticipantIds:t,drawDefinition:e}){if(!e)return{error:_n};if(!Array.isArray(t))return{error:Z};const r=Kn((e==null?void 0:e.entries)||[]);return t.length&&jt(t,r).length<t.length?{error:Z}:pf({drawDefinition:e,extension:{name:ef,value:t}})}function ipe({drawDefinition:t}){var e;const r=Kl({drawDefinition:t,name:"participantRepresentatives"});return r.error?r:{representativeParticipantIds:((e=r.extension)==null?void 0:e.value)||[]}}var spe=Object.defineProperty,ape=Object.defineProperties,cpe=Object.getOwnPropertyDescriptors,KC=Object.getOwnPropertySymbols,lpe=Object.prototype.hasOwnProperty,upe=Object.prototype.propertyIsEnumerable,QC=(t,e,r)=>e in t?spe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,JC=(t,e)=>{for(var r in e||(e={}))lpe.call(e,r)&&QC(t,r,e[r]);if(KC)for(var r of KC(e))upe.call(e,r)&&QC(t,r,e[r]);return t},ZC=(t,e)=>ape(t,cpe(e));function dpe({tournamentRecord:t,drawDefinition:e,participantId:r,sideNumber:n,matchUpId:o,event:i}){var s;if(r&&typeof r!="string")return{error:co};if(!e)return{error:pe};if(!o)return{error:Ut};const a=n===void 0;if(a&&(n=1),![1,2].includes(n))return{error:Z,sideNumber:n};const{matchUp:c,structure:l}=nt({drawDefinition:e,matchUpId:o,event:i});if(!(!(l!=null&&l.structures)&&!(e.drawType&&e.drawType!==cn)&&!(l!=null&&l.matchUps.find(({roundPosition:d})=>!!d))))return{error:mh};if(!r&&((s=c.score)!=null&&s.scoreStringSide1||Lt.includes(c.matchUpstatus)||[_t,bt].includes(c.matchUpStatus)))return{error:Cp,info:"matchUp has completed status or score"};if(c.sides=[1,2].map(d=>{var p;const v=((p=c.sides)==null?void 0:p.find(f=>f.sideNumber===d))||{sideNumber:d};return n===d?ZC(JC({},v),{participantId:r}):v}),a)for(const d of c.sides)d.sideNumber=3-d.sideNumber;return Qe({tournamentId:t==null?void 0:t.tournamentId,context:"assignSideParticipant",drawDefinition:e,matchUp:c}),ZC(JC({},B),{sidesSwapped:a})}function XC({lineUp:t,tieFormat:e}){let r=[];if(!Array.isArray(t))return r.push(zt("lineUp")),{valid:!1,errors:r,error:Z};const n=t.every(s=>{if(typeof s!="object")return r.push("lineUp entries must be objects"),!1;const{participantId:a,collectionAssignments:c}=s;return a?typeof a!="string"?(r.push("participantIds must be strings"),!1):Array.isArray(c)?c.every(l=>{if(typeof l!="object")return r.push("collectionAssignments must be objects"),!1;const{collectionPosition:u}=l;return typeof u!="number"?(r.push("collectionPosition must be a number"),!1):!0}):(r.push(zt("collectionAssignments")),!1):(r.push("Missing participantId"),!1)}),o=Ve(t.map(Xe)).length===t.length;return o||r.push("Duplicated participantId(s)"),{valid:n&&o,errors:r,error:r.length?Z:void 0}}var ppe=Object.defineProperty,eM=Object.getOwnPropertySymbols,fpe=Object.prototype.hasOwnProperty,vpe=Object.prototype.propertyIsEnumerable,tM=(t,e,r)=>e in t?ppe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mpe=(t,e)=>{for(var r in e||(e={}))fpe.call(e,r)&&tM(t,r,e[r]);if(eM)for(var r of eM(e))vpe.call(e,r)&&tM(t,r,e[r]);return t};function Xd({drawDefinition:t,participantId:e,tieFormat:r,lineUp:n}){if(typeof t!="object")return{error:pe};if(typeof e!="string")return{error:yt};const o=XC({lineUp:n,tieFormat:r});if(!o.valid)return o;const{extension:i}=Or({element:t,name:bn}),s=(i==null?void 0:i.value)||{};return s[e]=Nv({lineUp:n}),tt({element:t,extension:{name:bn,value:s}}),Rc({drawDefinition:t}),mpe({},B)}var gpe=Object.defineProperty,rM=Object.getOwnPropertySymbols,hpe=Object.prototype.hasOwnProperty,_pe=Object.prototype.propertyIsEnumerable,nM=(t,e,r)=>e in t?gpe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ipe=(t,e)=>{for(var r in e||(e={}))hpe.call(e,r)&&nM(t,r,e[r]);if(rM)for(var r of rM(e))_pe.call(e,r)&&nM(t,r,e[r]);return t};function gg({tournamentRecord:t,drawDefinition:e,tieMatchUpId:r,event:n}){var o;if(!t)return{error:ee};if(!e)return{error:wr};if(!n)return{error:Ir};const i=Kt({drawDefinition:e}),{matchUp:s}=nt({matchUpId:r,drawDefinition:e,matchUpsMap:i});if(!s)return{error:kr};const{matchUp:a,structure:c}=nt({tournamentParticipants:t.participants,matchUpId:r,inContext:!0,drawDefinition:e,matchUpsMap:i,event:n}),{collectionPosition:l,drawPositions:u,collectionId:d,matchUpTieId:p,matchUpType:v}=a;if(![pt,it].includes(v))return{error:Gr};const{positionAssignments:f}=et({structure:c}),m=f==null?void 0:f.filter(O=>u==null?void 0:u.includes(O.drawPosition)),g=Kn(m),{tournamentParticipants:h}=Qt({tournamentRecord:t,participantFilters:{participantTypes:[Ye],participantIds:g}}),{matchUp:_}=nt({matchUpId:p,drawDefinition:e,matchUpsMap:i}),{matchUp:I}=nt({matchUpId:p,inContext:!0,drawDefinition:e,matchUpsMap:i}),P=(o=Xt({matchUp:_,drawDefinition:e,structure:c,event:n}))==null?void 0:o.tieFormat;return Ipe({inContextDualMatchUp:I,inContextTieMatchUp:a,relevantAssignments:m,collectionPosition:l,teamParticipants:h,collectionId:d,matchUpType:v,dualMatchUp:_,tieMatchUp:s,tieFormat:P,structure:c},B)}var Ppe=Object.defineProperty,ype=Object.defineProperties,Spe=Object.getOwnPropertyDescriptors,oM=Object.getOwnPropertySymbols,Ope=Object.prototype.hasOwnProperty,bpe=Object.prototype.propertyIsEnumerable,iM=(t,e,r)=>e in t?Ppe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ep=(t,e)=>{for(var r in e||(e={}))Ope.call(e,r)&&iM(t,r,e[r]);if(oM)for(var r of oM(e))bpe.call(e,r)&&iM(t,r,e[r]);return t},hg=(t,e)=>ype(t,Spe(e));function sM(t){var e,r,n,o,i,s,a,c,l;const u=gg(t);if(u.error)return u;const d="replaceTieMatchUpParticipantid",{existingParticipantId:p,tournamentRecord:v,newParticipantId:f,drawDefinition:m,substitution:g,event:h}=t;if(!p||!f)return W({result:{error:yt},stack:d});if(p===f)return ep({},B);const{inContextDualMatchUp:_,inContextTieMatchUp:I,collectionPosition:P,collectionId:O,dualMatchUp:y,tieMatchUp:S,tieFormat:T}=u,{matchUpType:E}=I,b=(e=I.sides)==null?void 0:e.find(H=>{var Q,K,Y;return((Q=H.participant)==null?void 0:Q.participantId)===p||((Y=(K=H.participant)==null?void 0:K.individualParticipantIds)==null?void 0:Y.includes(p))});if(!b)return{error:wt};const{tournamentParticipants:N}=Qt({tournamentRecord:v,participantFilters:{participantIds:[p,f]}});if(N.length!==2)return W({result:{error:yt},stack:d});if(N[0].participantType!==N[1].participantType)return W({result:{error:In},stack:d});const{appliedPolicies:w}=at({tournamentRecord:v,drawDefinition:m,event:h}),$=(w==null?void 0:w[xi])||fm[xi],U=(r=$==null?void 0:$.processCodes)==null?void 0:r.substitution,{extension:A}=Vt({element:m,name:bn}),M=(A==null?void 0:A.value)||{};if(!((n=y.sides)!=null&&n.length)){const H=({displaySideNumber:Q,drawPosition:K,sideNumber:Y})=>({drawPosition:K,sideNumber:Y,displaySideNumber:Q});y.sides=_.sides.map(Q=>{const K=Q.participantId;return hg(ep({},H(Q)),{lineUp:K&&M[K]||[]})})}const C=y.sides.find(({sideNumber:H})=>H===b.sideNumber);if(!C)return W({result:{sideNumber:b.sideNumber,existingParticipantId:p,error:Yt},stack:d});if(((o=I.sides)==null?void 0:o.flatMap(({participant:H})=>(H==null?void 0:H.individualParticipantIds)||(H==null?void 0:H.participantId)||[])).includes(f))return W({result:{error:Dp},stack:d});const F=(s=(i=_.sides)==null?void 0:i.find(({sideNumber:H})=>H===b.sideNumber))==null?void 0:s.participantId,R=C.lineUp,G=R==null?void 0:R.find(({participantId:H})=>f===H),x=R==null?void 0:R.reduce((H,Q)=>Q.substitutionOrder>H?Q.substitutionOrder:H,0),z=(R==null?void 0:R.map(H=>{var Q;const K=ue(H,!1,!0);if(![p,f].includes(K.participantId))return K;if(!g&&[p,f].includes(K.participantId)&&(K.collectionAssignments=(Q=K.collectionAssignments)==null?void 0:Q.filter(Y=>!(Y.collectionPosition===P&&Y.collectionId===O))),g&&p===K.participantId&&(K.collectionAssignments=K.collectionAssignments.map(Y=>Y.collectionPosition===P&&Y.collectionId===O&&Y.substitutionOrder===void 0?hg(ep({},Y),{substitutionOrder:x}):Y)),K.participantId===f){K.collectionAssignments||(K.collectionAssignments=[]);const Y={collectionId:O,collectionPosition:P};g&&(Y.previousParticipantId=p,Y.substitutionOrder=x+1),K.collectionAssignments.push(Y)}return K}))||[];if(!G){const H={collectionId:O,collectionPosition:P};g&&(H.substitutionOrder=x+1,H.previousParticipantId=p);const Q={collectionAssignments:[H],participantId:f};z.push(Q)}const j=E===it,{assignedParticipantIds:V}=nu({lineUp:R,collectionPosition:P,collectionId:O}),{assignedParticipantIds:L}=nu({lineUp:z,collectionPosition:P,collectionId:O});if(C.lineUp=z,F){const H=Xd({participantId:F,lineUp:z,drawDefinition:m,tieFormat:T});if(H.error)return W({result:H,stack:d})}else console.log("team participantId not found");let q,k;if(j){const{tournamentRecord:H}=t;let Q=Un({participantIds:L,tournamentRecord:H});if(!Q.participant){const J=Rn({returnParticipant:!0,pairOverride:!0,tournamentRecord:H,participant:{participantRole:qt,individualParticipantIds:L,participantType:we}});if(J.error)return W({result:J,stack:d});q=(a=J.participant)==null?void 0:a.participantId}Q=Un({participantIds:V,tournamentRecord:H});const K=(c=Q.participant)==null?void 0:c.participantId;K&&ja({participantIds:[K],tournamentRecord:H}).success&&(k=K)}if(g||((l=b.substitutions)==null?void 0:l.length)===1){if(g){const H=S.processCodes||[];U&&H.push(...U),S.processCodes=H}else for(const H of U||[]){const Q=S.processCodes.lastIndexOf(H);S.processCodes.splice(Q,1)}Qe({tournamentId:v==null?void 0:v.tournamentId,matchUp:S,context:d,drawDefinition:m})}return Qe({tournamentId:v==null?void 0:v.tournamentId,matchUp:y,context:d,drawDefinition:m}),hg(ep({},B),{modifiedLineUp:z,participantRemoved:k,participantAdded:q})}function _g({tournamentRecord:t,drawDefinition:e,structureId:r,structure:n}){return t?!n&&!e?{error:pe}:!n&&!r?{error:ar}:et({drawDefinition:e,structureId:r,structure:n}):{error:ee}}var Tpe=Object.defineProperty,Epe=Object.defineProperties,wpe=Object.getOwnPropertyDescriptors,aM=Object.getOwnPropertySymbols,$pe=Object.prototype.hasOwnProperty,Npe=Object.prototype.propertyIsEnumerable,cM=(t,e,r)=>e in t?Tpe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tp=(t,e)=>{for(var r in e||(e={}))$pe.call(e,r)&&cM(t,r,e[r]);if(aM)for(var r of aM(e))Npe.call(e,r)&&cM(t,r,e[r]);return t},Ape=(t,e)=>Epe(t,wpe(e));function Ig({autoPublish:t=!0,policyDefinitions:e,tournamentRecord:r,drawIds:n=[],auditData:o,eventId:i,event:s}){var a,c,l;if(!r)return{error:ee};const u="deleteDrawDefinitions";if(!e){const{appliedPolicies:S}=at({tournamentRecord:r,event:s});e=S}const d=Array.isArray(n)&&n[0];if(!s){const S=xt({tournamentRecord:r,eventId:i,drawId:d});if(S.error)return S;s=S.event}const p=[],v=[],f=[];if(!s.drawDefinitions)return W({result:tp({},B),info:"event has no drawDefinition",stack:u});const m=s.drawDefinitions.map(({drawId:S})=>S);if(n.length||(n=m),n=n.filter(S=>m.includes(S)),!n.length)return W({result:tp({},B),info:"nothing to do; no matching drawIds in event.",stack:u});const g=ue(It({event:s}).flightProfile,!1,!0),h=({participantId:S,drawPosition:T,qualifier:E,bye:b})=>({bye:b,qualifier:E,drawPosition:T,participantId:S}),_=s.drawDefinitions.filter(S=>{var T,E,b,N,w,$;if(n.includes(S.drawId)){const{drawId:U,drawType:A,drawName:M}=S,C=(T=g==null?void 0:g.flights)==null?void 0:T.find(j=>j.drawId===S.drawId);C&&(C.drawEntries=(E=C.drawEntries)==null?void 0:E.filter(j=>TP.includes(j.entryStatus)));const D=(N=(b=Cr({stageSequence:1,drawDefinition:S,stage:de}))==null?void 0:b.structures)==null?void 0:N[0],F=D&&((w=_g({structureId:D.structureId,tournamentRecord:r,drawDefinition:S}))==null?void 0:w.positionAssignments.map(h)),R=($=Cr({stage:Ie,drawDefinition:S}))==null?void 0:$.structures,G=R!=null&&R.length?R.map(j=>{var V;const L=j.stageSequence;return{positionAssignments:(V=_g({structureId:j.structureId,tournamentRecord:r,drawDefinition:S}))==null?void 0:V.positionAssignments.map(h),stageSequence:L}}):void 0,x={action:t8,payload:{drawDefinitions:[S],eventId:s.eventId,auditData:o}};p.push(x),f.push(_e({tournamentId:r.tournamentId,qualifyingPositionAssignments:G,eventId:s.eventId,positionAssignments:F,auditData:o,drawType:A,drawName:M,drawId:U}));const{matchUps:z}=Dr({event:s,drawDefinition:S});z.forEach(({matchUpId:j})=>v.push(j))}return!n.includes(S.drawId)});s.drawDefinitions=_,g&&Wn({event:s,extension:{name:tn,value:g}}),yd({tournamentRecord:r});const I=`${Ar}.${Ur}`,{timeItem:P}=fn({element:s,itemType:I}),O=(a=P==null?void 0:P.itemValue)==null?void 0:a[$n];let y;for(const S of n)if((c=O==null?void 0:O.drawIds)==null?void 0:c.includes(S)){y=!0;const E=((l=O.drawIds)==null?void 0:l.filter(w=>w!==S))||[],b={itemType:`${Ar}.${Ur}`,itemValue:{[$n]:{drawIds:E}}},N=zo({event:s,timeItem:b});if(N.error)return{error:N.error}}if(p.length&&xe({topic:pc,payload:p}),v.length&&yi({tournamentId:r==null?void 0:r.tournamentId,matchUpIds:v}),n.forEach(S=>{aG({drawId:S})}),Upe({event:s,deletedDrawsDetail:f,auditData:o}),t&&y){const S=ml({tournamentRecord:r,event:s,policyDefinitions:e});S.error&&console.log("publish error",S)}return tp({},B)}function Upe({event:t,deletedDrawsDetail:e,auditData:r}){const{extension:n}=Or({name:ql,element:t}),o=Ape(tp({},r),{deletedDrawsDetail:e}),i={name:ql,value:Array.isArray(n==null?void 0:n.value)?n.value.concat(o):[o]};tt({element:t,extension:i})}var Cpe=Object.defineProperty,lM=Object.getOwnPropertySymbols,Mpe=Object.prototype.hasOwnProperty,Dpe=Object.prototype.propertyIsEnumerable,uM=(t,e,r)=>e in t?Cpe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jpe=(t,e)=>{for(var r in e||(e={}))Mpe.call(e,r)&&uM(t,r,e[r]);if(lM)for(var r of lM(e))Dpe.call(e,r)&&uM(t,r,e[r]);return t};function dM({collectionPosition:t,teamParticipantId:e,dualMatchUpSide:r,drawDefinition:n,participantIds:o,collectionId:i}){var s;if(!i||!t||!Array.isArray(o))return{modifiedLineUp:(r==null?void 0:r.lineUp)||[],error:Z};const a=(r==null?void 0:r.lineUp)||((s=yc({participantId:e,drawDefinition:n}))==null?void 0:s.lineUp),c=[],l=[];return{modifiedLineUp:(a==null?void 0:a.map(d=>{var p;if(!o.includes(d.participantId))return d;const v=(p=d.collectionAssignments)==null?void 0:p.filter(f=>{const m=f.collectionId===i&&f.collectionPosition===t;return m&&(f.previousParticipantId&&c.push(f.previousParticipantId),l.push(jpe({participantId:d.participantId},f))),!m});return{participantId:d.participantId,collectionAssignments:v}}).filter(Boolean))||[],assignmentsRemoved:l,previousParticipantIds:c}}var Rpe=Object.defineProperty,Fpe=Object.defineProperties,Lpe=Object.getOwnPropertyDescriptors,pM=Object.getOwnPropertySymbols,Vpe=Object.prototype.hasOwnProperty,xpe=Object.prototype.propertyIsEnumerable,fM=(t,e,r)=>e in t?Rpe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,rp=(t,e)=>{for(var r in e||(e={}))Vpe.call(e,r)&&fM(t,r,e[r]);if(pM)for(var r of pM(e))xpe.call(e,r)&&fM(t,r,e[r]);return t},Pg=(t,e)=>Fpe(t,Lpe(e));function yg(t){var e,r,n,o,i,s,a;const c=gg(t);if(c.error)return c;const l="assignTieMatchUpParticipantId";let u=t.teamParticipantId;const{tournamentRecord:d,drawDefinition:p,participantId:v}=t;if(!v)return W({result:{error:yt},stack:l});if(t.sideNumber&&![1,2].includes(t.sideNumber))return W({result:{error:Th},stack:l});const{inContextDualMatchUp:f,inContextTieMatchUp:m,relevantAssignments:g,collectionPosition:h,teamParticipants:_,collectionId:I,matchUpType:P,dualMatchUp:O,tieFormat:y}=c;if(((e=m.sides)==null?void 0:e.flatMap(({participant:k})=>(k==null?void 0:k.individualParticipantIds)||(k==null?void 0:k.participantId)||[])).includes(v))return W({result:rp({},B),stack:l});u=u||t.sideNumber&&((r=f.sides.find(k=>k.sideNumber===t.sideNumber))==null?void 0:r.participantId);const{tournamentParticipants:[T]}=Qt({tournamentRecord:d,participantFilters:{participantIds:[v]}});if(!T)return W({result:{error:wt},stack:l});if([ct,mt].includes(m.gender)&&m.gender!==((n=T.person)==null?void 0:n.sex))return{error:Mp,info:"Gender mismatch"};const{individualParticipantIds:E,participantType:b}=T;if(P===pt&&b!==Me)return{error:In};const N=b===Me?[v]:E,w=u&&_.find(({participantId:k})=>k===u)||_.find(({individualParticipantIds:k})=>Gt(N,k));if(!w)return{error:Bh};if(u||(u=w.participantId),!u)return{error:wt};const $=g==null?void 0:g.find(k=>k.participantId===(w==null?void 0:w.participantId)),U=$==null?void 0:$.drawPosition,A=(o=m.sides)==null?void 0:o.find(({drawPosition:k})=>k===U),M=t.sideNumber||(A==null?void 0:A.sideNumber);if(!y)return{error:$l};if(!((i=y.collectionDefinitions)==null?void 0:i.find(k=>k.collectionId===I)))return{error:SF};if(!((s=O.sides)!=null&&s.length)){const{extension:k}=Vt({element:p,name:bn}),H=ue((k==null?void 0:k.value)||{},!1,!0),Q=({displaySideNumber:K,drawPosition:Y,sideNumber:J})=>({drawPosition:Y,sideNumber:J,displaySideNumber:K});O.sides=f.sides.map(K=>{const Y=K.participantId;return Pg(rp({},Q(K)),{lineUp:Y&&H[Y]||[]})})}const D=O.sides.find(k=>k.sideNumber===M),F=m.sides.find(k=>k.sideNumber===M),R=(D==null?void 0:D.lineUp)||((a=yc({participantId:u,drawDefinition:p}))==null?void 0:a.lineUp),G=R==null?void 0:R.filter(k=>{var H;return(H=k.collectionAssignments)==null?void 0:H.find(Q=>Q.collectionPosition===h&&Q.collectionId===I&&!Q.previousParticipantId)}),x=G==null?void 0:G.map(k=>k==null?void 0:k.participantId),z=(x==null?void 0:x.length)>1&&x||(b===we?T.individualParticipantIds:[v]),j=dM({collectionPosition:h,teamParticipantId:u,dualMatchUpSide:D,participantType:b,drawDefinition:p,participantIds:z,collectionId:I,matchUpType:P});if(j.error)return W({result:j,stack:l});const{modifiedLineUp:V}=j;let L;if(P===it){if(b!==we){let k=Sg({collectionPosition:h,teamParticipantId:u,drawDefinition:p,modifiedLineUp:V,participantId:v,collectionId:I,tieFormat:y});if(k!=null&&k.error)return W({result:k,stack:l});if(k=q({side:F}),k.error)return k;L=k.deleteParticipantId,D.lineUp=V,Qe({tournamentId:d==null?void 0:d.tournamentId,matchUp:O,context:l,drawDefinition:p})}else if(b===we)for(const k of z)Sg({collectionPosition:h,teamParticipantId:u,drawDefinition:p,modifiedLineUp:V,participantId:k,collectionId:I,tieFormat:y})}else{const k=Sg({collectionPosition:h,teamParticipantId:u,drawDefinition:p,modifiedLineUp:V,participantId:v,collectionId:I,tieFormat:y});if(k!=null&&k.error)return k}if(D.lineUp=V,Qe({tournamentId:d==null?void 0:d.tournamentId,matchUp:O,context:l,drawDefinition:p}),L){const{error:k}=ja({participantIds:[L],tournamentRecord:d});k&&console.log("cleanup")}return Pg(rp({},B),{modifiedLineUp:V});function q({side:k}){let H;if(k.participant){const Q=k.participant.individualParticipantIds||[];if(Q.filter(Boolean).length===1){const{participant:Y}=Un({participantIds:Q,tournamentRecord:d});Q.push(v);const{participant:J}=Un({participantIds:Q,tournamentRecord:d});if(J)H=Y.participantId;else{Y.individualParticipantIds=Q;const te=pg({individualParticipantIds:Q,pairOverride:!0,tournamentRecord:d,participant:Y});if(te.error)return te}}}else{const K=Rn({participant:{individualParticipantIds:[v],participantRole:qt,participantType:we},pairOverride:!0,tournamentRecord:d});if(K.error)return K}return Pg(rp({},B),{deleteParticipantId:H})}}function Sg({collectionPosition:t,teamParticipantId:e,drawDefinition:r,modifiedLineUp:n,participantId:o,collectionId:i,tieFormat:s}){var a,c;const l=(a=yc({participantId:e,drawDefinition:r}))==null?void 0:a.lineUp,u=(c=n||l)==null?void 0:c.find(p=>(p==null?void 0:p.participantId)===o),d={collectionId:i,collectionPosition:t};if(u)u.collectionAssignments.push(d);else{const p={collectionAssignments:[d],participantId:o};n.push(p)}return Xd({participantId:e,lineUp:n,drawDefinition:r,tieFormat:s})}var Bpe=Object.defineProperty,kpe=Object.defineProperties,Gpe=Object.getOwnPropertyDescriptors,vM=Object.getOwnPropertySymbols,Wpe=Object.prototype.hasOwnProperty,Hpe=Object.prototype.propertyIsEnumerable,mM=(t,e,r)=>e in t?Bpe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gM=(t,e)=>{for(var r in e||(e={}))Wpe.call(e,r)&&mM(t,r,e[r]);if(vM)for(var r of vM(e))Hpe.call(e,r)&&mM(t,r,e[r]);return t},hM=(t,e)=>kpe(t,Gpe(e));function qpe(t){var e,r,n,o,i,s,a,c,l,u,d,p,v;const{tournamentRecord:f,drawDefinition:m,participantId:g,event:h}=t,_="removeTieMatchUpParticiapantId";if(!g)return W({result:{error:yt},stack:_});const I=gg(t);if(I.error)return I;const{appliedPolicies:P}=at({tournamentRecord:f,drawDefinition:m,event:h}),O=(P==null?void 0:P[xi])||fm[xi],y=(e=O==null?void 0:O.processCodes)==null?void 0:e.substitution,{inContextDualMatchUp:S,inContextTieMatchUp:T,relevantAssignments:E,collectionPosition:b,teamParticipants:N,collectionId:w,matchUpType:$,dualMatchUp:U,tieMatchUp:A,tieFormat:M}=I,C=(r=T.sides)==null?void 0:r.find(j=>{var V,L,q;return((V=j.participant)==null?void 0:V.participantId)===g||((q=(L=j.participant)==null?void 0:L.individualParticipantIds)==null?void 0:q.includes(g))});if(!C)return{error:wt};if(!((n=C.substitutions)!=null&&n.length)&&(Dt({score:T.score})||T.winningSide))return{error:aL};const D=(i=(o=S.sides)==null?void 0:o.find(({sideNumber:j})=>j===C.sideNumber))==null?void 0:i.participantId;if(!D)return{error:wt};const{tournamentParticipants:[F]}=Qt({tournamentRecord:f,participantFilters:{participantIds:[g]}});if(!F)return{error:wt};if($===pt&&F.participantType===we)return{error:Mp};const R=F.participantType===Me?[g]:F.individualParticipantIds;if(!((s=U.sides)!=null&&s.length)){const{extension:j}=Vt({element:m,name:bn}),V=(j==null?void 0:j.value)||{},L=({displaySideNumber:q,drawPosition:k,sideNumber:H})=>({drawPosition:k,sideNumber:H,displaySideNumber:q});U.sides=S.sides.map(q=>{const k=q.participantId;return hM(gM({},L(q)),{lineUp:k&&V[k]||[]})})}let G=(a=U.sides)==null?void 0:a.find(({sideNumber:j})=>j===C.sideNumber);if(!G&&(((c=U.sides)==null?void 0:c.filter(({lineUp:j})=>!j).length)||0)<2){const j=N.map(({participantId:V})=>{var L;return{drawPosition:(L=E.find(q=>q.participantId===V))==null?void 0:L.drawPosition,teamParticipantId:V}});G=(l=U.sides)==null?void 0:l.find(V=>{var L;return((L=j.find(({drawPosition:q})=>q===V.drawPosition))==null?void 0:L.teamParticipantId)===D})}if(!G)return console.log({teamParticipantId:D,teamParticipants:N}),{error:wt,participantId:g};const{modifiedLineUp:x,previousParticipantIds:z}=dM({collectionPosition:b,teamParticipantId:D,dualMatchUpSide:G,participantIds:R,drawDefinition:m,collectionId:w});if(G.lineUp=x,D&&Xd({participantId:D,lineUp:x,drawDefinition:m,tieFormat:M}),$===it&&F.participantType===Me){const j=(u=T.sides)==null?void 0:u.find(q=>q.sideNumber===G.sideNumber),{participantId:V}=j||{},{tournamentParticipants:[L]}=Qt({tournamentRecord:f,participantFilters:{participantIds:[V]},withEvents:!0});if(L){const q=L==null?void 0:L.individualParticipantIds.filter(k=>k!==g);if(q.push(...z),q.length>2)return{error:Qr};if(L.draws.length){if(q.length===1){const{participant:k}=Un({participantIds:q,tournamentRecord:f});if(!k){const Q=Rn({participant:{participantRole:qt,individualParticipantIds:q,participantType:we},pairOverride:!0,tournamentRecord:f});if(Q.error)return Q}}}else if(q.length){L.individualParticipantIds=q;const k=pg({participant:L,pairOverride:!0,tournamentRecord:f});if(k.error)return k}else{const k=ja({participantIds:[V],tournamentRecord:f});k.error&&console.log("cleanup",{result:k})}}else return{error:wt}}if(((d=C.substitutions)==null?void 0:d.length)===1){const j=T.sides.find(V=>V.sideNumber!==C.sideNumber);if(!((p=j==null?void 0:j.substitutions)!=null&&p.length)&&((v=A.processCodes)!=null&&v.length)){for(const V of y||[]){const L=A.processCodes.lastIndexOf(V);A.processCodes.splice(L,1)}Qe({tournamentId:f==null?void 0:f.tournamentId,matchUp:A,context:_,drawDefinition:m})}}return Qe({tournamentId:f==null?void 0:f.tournamentId,matchUp:U,context:_,drawDefinition:m}),hM(gM({},B),{modifiedLineUp:x})}var Ype=Object.defineProperty,_M=Object.getOwnPropertySymbols,zpe=Object.prototype.hasOwnProperty,Kpe=Object.prototype.propertyIsEnumerable,IM=(t,e,r)=>e in t?Ype(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qpe=(t,e)=>{for(var r in e||(e={}))zpe.call(e,r)&&IM(t,r,e[r]);if(_M)for(var r of _M(e))Kpe.call(e,r)&&IM(t,r,e[r]);return t};function Jpe({tournamentRecord:t,drawDefinition:e,participantId:r,drawPosition:n,structureId:o,qualifier:i,event:s,bye:a}){if(!e)return{error:pe};if(!n)return{error:Ya};if(!o)return{error:ar};if(a){const c=jr({tournamentRecord:t,drawDefinition:e,drawPosition:n,structureId:o,event:s});if(c.error)return c}else{if(i)return{error:Gh};{const c=vn({tournamentRecord:t,drawDefinition:e,participantId:r,drawPosition:n,structureId:o,event:s});if(c.error)return c}}return Qpe({},B)}var Zpe=Object.defineProperty,Xpe=Object.defineProperties,efe=Object.getOwnPropertyDescriptors,PM=Object.getOwnPropertySymbols,tfe=Object.prototype.hasOwnProperty,rfe=Object.prototype.propertyIsEnumerable,yM=(t,e,r)=>e in t?Zpe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,nfe=(t,e)=>{for(var r in e||(e={}))tfe.call(e,r)&&yM(t,r,e[r]);if(PM)for(var r of PM(e))rfe.call(e,r)&&yM(t,r,e[r]);return t},ofe=(t,e)=>Xpe(t,efe(e));function ife({allowDuplicateParticipantIdPairs:t,entryStatus:e=un,participantIdPairs:r=[],entryStage:n=de,tournamentRecord:o,drawDefinition:i,event:s,uuids:a}){if(!o)return{error:ee};if(!s)return{error:Le};if(s.eventType!==it)return{error:ri};const c=o.participants||[],l=c.filter(P=>P.participantType===Me).map(P=>P.participantId),u=l.filter(P=>!l.includes(P));if(u.length)return{error:Qr,invalidParticipantIds:u};const d=r.filter(P=>P.length!==2);if(d.length)return{error:Qr,invalidParticipantIdPairs:d};const p=c.filter(P=>P.participantType===we).map(P=>P.individualParticipantIds),v=r.map(P=>({participantId:(a==null?void 0:a.pop())||We(),participantType:we,participantRole:qt,individualParticipantIds:P})),f=t?v:v.filter(P=>!p.find(O=>jt(O,P.individualParticipantIds).length===2));let m,g=[];if(f){const P=to({allowDuplicateParticipantIdPairs:t,participants:f,returnParticipants:!0,tournamentRecord:o});if(P.error)return P;g=P.participants||[],m=P.info}const h=r.map(P=>{const O=g.find(S=>jt(S.individualParticipantIds,P).length===2);if(O)return O;const{participant:y}=Un({tournamentRecord:o,participantIds:P});return y}).map(P=>P.participantId),_=Qo({participantIds:h,tournamentRecord:o,drawDefinition:i,entryStatus:e,entryStage:n,event:s});f.length&&xe({topic:fi,participants:f});const I=f.map(Xe);return ofe(nfe({},_),{info:m,newParticipantIds:I})}var sfe=Object.defineProperty,SM=Object.getOwnPropertySymbols,afe=Object.prototype.hasOwnProperty,cfe=Object.prototype.propertyIsEnumerable,OM=(t,e,r)=>e in t?sfe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lfe=(t,e)=>{for(var r in e||(e={}))afe.call(e,r)&&OM(t,r,e[r]);if(SM)for(var r of SM(e))cfe.call(e,r)&&OM(t,r,e[r]);return t};function bM({event:t,participants:e,ignoreGender:r}){if(!e)return{error:Qa};if(!Array.isArray(e))return{error:Z};if(!t)return{error:Le};const{eventType:n,gender:o}=t,i=n===Nn&&Ye||n===hc&&we||Me,s=Object.assign({},...(t.entries||[]).map(u=>({[u.participantId]:u.entryStatus}))),a=Object.keys(s),l=e.filter(u=>a.includes(u.participantId)).filter(u=>{const d=s[u.participantId],p=[hc,Nn].includes(n)&&u.participantType===Me&&(Ai(d)||d===Go),v=u.participantType!==i&&!p,f=!r&&n===Me&&[ct,mt].includes(o)&&u.sex!==o;return v||f});if(l.length){const u=l.map(d=>d.participantId);return{error:IF,invalidParticipantIds:u}}return lfe({},B)}var ufe=Object.defineProperty,dfe=Object.defineProperties,pfe=Object.getOwnPropertyDescriptors,TM=Object.getOwnPropertySymbols,ffe=Object.prototype.hasOwnProperty,vfe=Object.prototype.propertyIsEnumerable,EM=(t,e,r)=>e in t?ufe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wM=(t,e)=>{for(var r in e||(e={}))ffe.call(e,r)&&EM(t,r,e[r]);if(TM)for(var r of TM(e))vfe.call(e,r)&&EM(t,r,e[r]);return t},$M=(t,e)=>dfe(t,pfe(e));function mfe(t){const{provisionalPositioning:e,useExistingSeedLimit:r,tournamentRecord:n,drawDefinition:o,seedingProfile:i,structureId:s,assignments:a,drawId:c,event:l}=t;let u=0;if(!(a!=null&&a.length))return{error:_h};if(!n)return{error:ee};if(!c)return{error:wr};const d=dn({provisionalPositioning:e,drawDefinition:o,structureId:s,event:l});if(d.error)return d;const{seedAssignments:p,seedLimit:v}=d,f=Object.assign({},...p.filter(h=>h.seedNumber).map(h=>({[h.seedNumber]:h})));a.forEach(h=>{const{seedNumber:_}=h;_<=v&&(!r||f[_])&&(f[_]=h)});const m=Object.values(f),g=m.map(h=>h==null?void 0:h.participantId).filter(Boolean);if(g.length!==ah(g).length)return{error:aF};for(const h of m){const _=Ps($M(wM({},h),{provisionalPositioning:e,tournamentRecord:n,drawDefinition:o,seedingProfile:i,structureId:s,event:l}));if(_!=null&&_.error)return _;_!=null&&_.success&&u++}return u?$M(wM({},B),{modifications:u}):{error:Ja}}var gfe=Object.defineProperty,NM=Object.getOwnPropertySymbols,hfe=Object.prototype.hasOwnProperty,_fe=Object.prototype.propertyIsEnumerable,AM=(t,e,r)=>e in t?gfe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ife=(t,e)=>{for(var r in e||(e={}))hfe.call(e,r)&&AM(t,r,e[r]);if(NM)for(var r of NM(e))_fe.call(e,r)&&AM(t,r,e[r]);return t};function Pfe({removePairParticipants:t,tournamentRecord:e,eventIds:r}){if(!e)return{error:ee};if(!e.events)return{error:Ir};if(!Array.isArray(r))return{error:Oe,info:zt("drawIds")};const n=[],o=[],i=[],s=[];if(e.events=(e.events||[]).filter(a=>{if(r.includes(a.eventId)){const u={action:RT,payload:{events:[a]}};n.push(u),o.push({tournamentId:e.tournamentId,eventName:a.eventName,eventType:a.eventType,category:a.category,eventId:a.eventId,gender:a.gender})}const c=a.eventType===br?(a.entries||[]).map(({entryStatus:u,participantId:d})=>u!==qr&&d).filter(Boolean):[],l=r.includes(a.eventId);return l?s.push(...c):i.push(...c),!l}),t){const a=s.filter(c=>!i.includes(c));e.participants=e.participants.filter(({participantId:c})=>!a.includes(c))}return yd({tournamentRecord:e}),n.length&&(xe({topic:pc,payload:n}),bo({tournamentRecord:e,timeItem:{itemType:RT,itemValue:o}})),Ife({},B)}const yfe="COLLEGE_DEFAULT",Sfe="COLLEGE_JUCO",Ofe="COLLEGE_D3",bfe="DOMINANT_DUO",Tfe="DOMINANT_DUO_MIXED",Efe="LAVER_CUP",wfe="TEAM_DOUBLES_3_AGGREGATION",$fe="USTA_BREWER_CUP",Nfe="USTA_OZAKI_CUP",Afe="USTA_COLLEGE",Ufe="USTA_GOLD_TEAM_CHALLENGE",Cfe="USTA_LEVEL_1",Mfe="USTA_INTERSECTIONAL",Dfe="USTA_SECTION_BATTLE",jfe="USTA_SOUTHERN_LEVEL_5",Rfe="USTA_TOC",Ffe="USTA_WTT_ITT",Lfe="USTA_ZONAL";var Vfe=Object.defineProperty,UM=Object.getOwnPropertySymbols,xfe=Object.prototype.hasOwnProperty,Bfe=Object.prototype.propertyIsEnumerable,CM=(t,e,r)=>e in t?Vfe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,MM=(t,e)=>{for(var r in e||(e={}))xfe.call(e,r)&&CM(t,r,e[r]);if(UM)for(var r of UM(e))Bfe.call(e,r)&&CM(t,r,e[r]);return t};const gl="SET3-S:6/TB7",DM={STANDARD:{hydrate:!0,doubles:{matchUpCount:3,matchUpValue:1},singles:{matchUpCount:6,matchUpValue:1},valueGoal:5},[Ofe]:{hydrate:!0,doubles:{matchUpCount:3,matchUpValue:1,matchUpFormat:"SET1-S:8/TB7@7"},singles:{matchUpCount:6,matchUpValue:1,matchUpFormat:gl},tieFormatName:"COLLEGE_D3",valueGoal:5},[yfe]:{hydrate:!0,doubles:{matchUpCount:3,collectionValue:1,matchUpFormat:gl},singles:{matchUpCount:6,matchUpValue:1,matchUpFormat:gl},tieFormatName:"COLLEGE_DEFAULT",valueGoal:4},[Sfe]:{hydrate:!0,doubles:{matchUpCount:3,matchUpValue:1,matchUpFormat:"SET1-S:8/TB7"},singles:{matchUpCount:6,matchUpValue:1,matchUpFormat:gl},tieFormatName:"COLLEGE_JUCO",valueGoal:5},[Efe]:Cy,[bfe]:Ay,[Tfe]:Uy,[wfe]:My,[$fe]:Dy,[Nfe]:jy,[Afe]:Ry,[Ufe]:Fy,[Mfe]:Ly,[Cfe]:Vy,[Dfe]:xy,[jfe]:By,[Ffe]:Gy,[Rfe]:ky,[Lfe]:Wy},Es=({hydrateCollections:t,namedFormat:e,event:r={},uuids:n=[]}={})=>{Object.keys(DM).includes(e)||(e="STANDARD"),Array.isArray(n)||(n=[]);let o;const{category:i,gender:s}=r,a=ue(DM[e],!1,!0);return a.hydrate?(o={winCriteria:{valueGoal:a.valueGoal},collectionDefinitions:[MM({collectionId:(n==null?void 0:n.pop())||We(),matchUpFormat:"SET3-S:6/TB7-F:TB10",collectionName:"Doubles",matchUpType:it},a.doubles),MM({collectionId:(n==null?void 0:n.pop())||We(),matchUpFormat:gl,collectionName:"Singles",matchUpType:pt},a.singles)]},a.tieFormatName&&(o.tieFormatName=a.tieFormatName)):(a.collectionDefinitions.forEach(c=>c.collectionId=We()),o=a),t&&o.collectionDefinitions.forEach(c=>{i&&!c.category&&(c.category=i),s&&!c.gender&&(c.gender=s)}),o};var kfe=Object.defineProperty,Gfe=Object.defineProperties,Wfe=Object.getOwnPropertyDescriptors,jM=Object.getOwnPropertySymbols,Hfe=Object.prototype.hasOwnProperty,qfe=Object.prototype.propertyIsEnumerable,RM=(t,e,r)=>e in t?kfe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yfe=(t,e)=>{for(var r in e||(e={}))Hfe.call(e,r)&&RM(t,r,e[r]);if(jM)for(var r of jM(e))qfe.call(e,r)&&RM(t,r,e[r]);return t},zfe=(t,e)=>Gfe(t,Wfe(e));function np({suppressNotifications:t,tournamentRecord:e,internalUse:r,event:n}){var o,i,s,a;if(!e)return{error:ee};if(e.events||(e.events=[]),!n)return{error:Le};const{startDate:c,endDate:l}=e;if(!r&&((o=n.entries)!=null&&o.length||(i=n.drawDefinitions)!=null&&i.length)){const p=_e({drawDefinitions:!!((s=n.drawDefinitions)!=null&&s.length),entries:!!((a=n.entries)!=null&&a.length)});return{info:"entries/drawDefinitions cannot exist",error:Z,context:p}}const u=Object.assign({},{drawDefinitions:[],eventType:Hn,entries:[],startDate:c,endDate:l},n);if(n.eventType===Tt){if(n.tieFormat){const p=ur({tieFormat:n.tieFormat});if(p.error)return p}else if(n.tieFormatName){if(!Hy[n.tieFormatName])return{context:{tieFormatName:n.tieFormatName},error:Z};const p=Es({namedFormat:n.tieFormatName});u.tieFormat=p}}if(u.eventId||(u.eventId=We()),e.events.reduce((p,v)=>p||v.eventId===u.eventId,void 0))return{error:hF};if(e.events.push(u),!t){const{topics:p}=Pn();if(p.includes(gf)){const{matchUps:v}=Oi({event:n});Pi({tournamentId:e==null?void 0:e.tournamentId,eventId:n.eventId,matchUps:v})}for(const v of n.drawDefinitions||[])Rc({drawDefinition:v})}return zfe(Yfe({},B),{event:u})}var Kfe=Object.defineProperty,FM=Object.getOwnPropertySymbols,Qfe=Object.prototype.hasOwnProperty,Jfe=Object.prototype.propertyIsEnumerable,LM=(t,e,r)=>e in t?Kfe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,VM=(t,e)=>{for(var r in e||(e={}))Qfe.call(e,r)&&LM(t,r,e[r]);if(FM)for(var r of FM(e))Jfe.call(e,r)&&LM(t,r,e[r]);return t};function Zfe({tournamentRecord:t,participantId:e,matchUpId:r,matchUp:n,drawId:o}){n&&!o&&({drawId:o}=n),n&&!r&&({matchUpId:r}=n);const{event:i,drawDefinition:s}=xt({tournamentRecord:t,drawId:o});if(i){const a=t.participants,c=am({tournamentParticipants:a,drawDefinition:s,participantId:e,matchUpId:r});if(c.error&&c.error!==Uh)return c}else return{error:Ir};return VM({},B)}function Xfe({tournamentRecord:t,participantId:e,matchUpId:r,matchUp:n,drawId:o}){n&&!o&&({drawId:o}=n),n&&!r&&({matchUpId:r}=n);const{event:i,drawDefinition:s}=xt({tournamentRecord:t,drawId:o});if(i){const a=t.participants,c=cm({drawDefinition:s,tournamentParticipants:a,matchUpId:r,participantId:e});if(c.error)return c}else return{error:Ir};return VM({},B)}var eve=Object.defineProperty,tve=Object.defineProperties,rve=Object.getOwnPropertyDescriptors,xM=Object.getOwnPropertySymbols,nve=Object.prototype.hasOwnProperty,ove=Object.prototype.propertyIsEnumerable,BM=(t,e,r)=>e in t?eve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,op=(t,e)=>{for(var r in e||(e={}))nve.call(e,r)&&BM(t,r,e[r]);if(xM)for(var r of xM(e))ove.call(e,r)&&BM(t,r,e[r]);return t},ive=(t,e)=>tve(t,rve(e));function sve(t){const{participantId:e}=t;return e&&typeof e!="string"?{error:Z,participantId:e}:kM(ive(op({},t),{participantIds:[e].filter(Boolean)}))}function kM({tournamentRecord:t,drawDefinition:e,participantIds:r,stageSequence:n,stage:o=de,eventId:i,event:s}){if(!t)return{error:ee};if(!Array.isArray(r))return{error:Z,participantIds:r};if(!s)return{error:Le};const a="promoteAlternates";if(s){const c=GM({element:s,participantIds:r,stageSequence:n,stage:o});if(c.error)return c}if(e){const c=GM({element:e,participantIds:r,stageSequence:n,stage:o});if(c.error)return i?W({context:{drawPromotionError:c.error,drawId:e.drawId},result:op({},B),stack:a}):c}return op({},B)}function GM({participantIds:t,stageSequence:e,element:r,stage:n}){const o=(r.entries||[]).filter(d=>d.entryStatus===un),i=(r.entries||[]).filter(d=>t.includes(d.participantId)),s=o.reduce((d,p)=>{const{entryPosition:v}=p;return isNaN(v)&&d||(!d||v<d.entryPosition)&&p||d},void 0),a=i.length?i:[s].filter(Boolean);if(!(a!=null&&a.length))return{error:Mh};const c=a.filter(({entryStatus:d})=>d!==un);if(c.length)return{error:jp,invalidEntryStatus:c};const l=a.filter(({entryStage:d})=>d&&d!==n);if(l.length)return{error:xF,invalidStage:l};const u=e&&a.filter(d=>d.stageSequence!==e);if(u!=null&&u.length)return{error:BF,invalidStageSequence:u};for(const d of a){d.entryStatus=Mr;const p=d==null?void 0:d.entryPosition;isNaN(p)||r.entries.forEach(f=>{f.entryStatus===un&&f.entryPosition>p&&(f.entryPosition=f.entryPosition-1)});let v=Math.max(...r.entries.filter(f=>f.entryStatus===Mr&&!isNaN(f.entryPosition)).map(({entryPosition:f})=>parseInt(f||0)),0);d.entryPosition=v||0}return op({},B)}function ave(t){return Object.assign(t,{entryStatus:Go}),Vd(t)}function cve({luckyLoserParticipantId:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,structureId:o}){return xm({positionActionName:"luckyLoserDrawPositionAssignment",participantId:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,structureId:o})}function lve(t){return cve(t)}function uve({qualifyingParticipantId:t,tournamentRecord:e,drawDefinition:r,drawPosition:n,structureId:o}){return xm({positionActionName:"qualifierDrawPositionAssignment",participantId:t,isQualifierPosition:!0,tournamentRecord:e,drawDefinition:r,drawPosition:n,structureId:o})}function dve(t){return uve(t)}function pve(t){return tA(t)}function fve(t){return VA(t)}function WM(t){return cl(t)}function vve(t){return oA(t)}function mve({tournamentRecord:t,drawDefinition:e,seedBlockInfo:r,drawPosition:n,structureId:o,event:i}){return jr({tournamentRecord:t,drawDefinition:e,seedBlockInfo:r,drawPosition:n,structureId:o,event:i})}var gve=Object.defineProperty,hve=Object.defineProperties,_ve=Object.getOwnPropertyDescriptors,HM=Object.getOwnPropertySymbols,Ive=Object.prototype.hasOwnProperty,Pve=Object.prototype.propertyIsEnumerable,qM=(t,e,r)=>e in t?gve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ws=(t,e)=>{for(var r in e||(e={}))Ive.call(e,r)&&qM(t,r,e[r]);if(HM)for(var r of HM(e))Pve.call(e,r)&&qM(t,r,e[r]);return t},$s=(t,e)=>hve(t,_ve(e));function yve({replacementIndividualParticipantId:t,existingIndividualParticipantId:e,tournamentRecord:r,drawDefinition:n,participantId:o,event:i,uuids:s}){var a,c;if(!i)return{error:Le};if((i==null?void 0:i.eventType)!==br)return{error:ri};if(s&&!Array.isArray(s))return{error:Z};if(!r)return{error:ee};if(![t,e,o].every(h=>typeof h=="string"))return{error:yt};if(!(((a=i==null?void 0:i.entries)==null?void 0:a.filter(({entryStatus:h})=>[qr,ns].includes(h)).map(({participantId:h})=>h))||[]).includes(t))return{error:co};const u=(r.participants||[]).find(h=>h.participantId===o);if((u==null?void 0:u.participantType)!==we)return{error:Mp,participant:u};const d=u.individualParticipantIds,p=[t,...d.filter(h=>h!==e)],{participant:v}=Un({participantIds:[p],tournamentRecord:r});let f;if(v)f=v.participantId;else{const h={participantId:s==null?void 0:s.pop(),participantRole:qt,individualParticipantIds:p,participantType:we},_=Rn({participant:h,returnParticipant:!0,tournamentRecord:r});if(_.error)return _;f=_.participant.participantId}const{flightProfile:m}=It({event:i});if(n){const h=(c=m==null?void 0:m.flights)==null?void 0:c.find(({drawId:_})=>_===n.drawId);h&&(h.drawEntries=h.drawEntries.map(_=>_.participantId===o?$s(ws({},_),{participantId:f}):_)),n.entries=n.entries.map(_=>_.participantId===o?$s(ws({},_),{participantId:f}):_);for(const _ of n.structures||[])if(_.positionAssignments)_.positionAssignments=_.positionAssignments.map(I=>I.participantId===o?$s(ws({},I),{participantId:f}):I);else if(_.structures)for(const I of _.structures)I.positionAssignments=I.positionAssignments.map(P=>P.participantId===o?$s(ws({},P),{participantId:f}):P)}i.entries=i.entries.map(h=>h.participantId===o&&$s(ws({},h),{participantId:f})||h.participantId===t&&$s(ws({},h),{participantId:e})||h);const g=r.events.some(({entries:h,eventId:_,drawDefinitions:I})=>i.eventId===_?I.some(({drawId:P,entries:O})=>P===(n==null?void 0:n.drawId)?!1:O==null?void 0:O.find(y=>y.participantId===o)):h==null?void 0:h.find(P=>P.participantId===o));if(!g){const h=ja({addIndividualParticipantsToEvents:!1,participantIds:[o],tournamentRecord:r});if(h.error)return h}return $s(ws({},B),{participantOtherEntries:g,newPairParticipantId:f})}var Sve=Object.defineProperty,YM=Object.getOwnPropertySymbols,Ove=Object.prototype.hasOwnProperty,bve=Object.prototype.propertyIsEnumerable,zM=(t,e,r)=>e in t?Sve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tve=(t,e)=>{for(var r in e||(e={}))Ove.call(e,r)&&zM(t,r,e[r]);if(YM)for(var r of YM(e))bve.call(e,r)&&zM(t,r,e[r]);return t};function Eve({autoEntryPositions:t=!0,participantIds:e,drawDefinition:r,drawId:n,stages:o,event:i}){var s;if(!i)return{error:Le};if(!n)return{error:wr};if(!(e!=null&&e.length))return{error:lo};const a=jd({drawDefinition:r,stages:o});if(Gt(a,e))return{error:Vs};const l=p=>{const v=p.participantId;return!e.includes(v)},{flightProfile:u}=It({event:i}),d=(s=u==null?void 0:u.flights)==null?void 0:s.find(p=>p.drawId===n);return d!=null&&d.drawEntries&&(d.drawEntries=d.drawEntries.filter(l),t&&(d.drawEntries=zr({entries:d.drawEntries}))),r!=null&&r.entries&&(r.entries=r.entries.filter(l),t&&(r.entries=zr({entries:r.entries}))),Tve({},B)}function wve(t){const e=t.tournamentRecord;if(!e)return{error:ee};const r=Dd(t);if(r.error)return r;const{playoffStructureNameBase:n,playoffPositions:o,roundNumbers:i,structureId:s}=t,c={itemType:"addPlayoffStructures",itemValue:_e({playoffStructureNameBase:n,playoffPositions:o,roundNumbers:i,structureId:s})};return bo({tournamentRecord:e,timeItem:c}),r}function $ve({tournamentRecord:t,drawDefinition:e,participantId:r,structureId:n,seedValue:o,event:i}){return t?(t.participants||[]).find(a=>a.participantId===r)?b1({tournamentRecord:t,drawDefinition:e,participantId:r,structureId:n,seedValue:o,event:i}):{error:co}:{error:ee}}var Nve=Object.defineProperty,Ave=Object.defineProperties,Uve=Object.getOwnPropertyDescriptors,KM=Object.getOwnPropertySymbols,Cve=Object.prototype.hasOwnProperty,Mve=Object.prototype.propertyIsEnumerable,QM=(t,e,r)=>e in t?Nve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,JM=(t,e)=>{for(var r in e||(e={}))Cve.call(e,r)&&QM(t,r,e[r]);if(KM)for(var r of KM(e))Mve.call(e,r)&&QM(t,r,e[r]);return t},ZM=(t,e)=>Ave(t,Uve(e));function Dve({tournamentRecord:t,drawDefinition:e,scheduledDates:r,stageSequences:n,matchUpFormat:o,structureIds:i,structureId:s,eventType:a,matchUpId:c,eventIds:l,eventId:u,drawIds:d,stages:p,drawId:v,event:f,force:m}){const g="setMatchUpFormat";if(!t)return{error:ee};if(!o)return{error:wp};if(o&&!xr(o))return W({result:{error:wl,matchUpFormat:o},stack:g});if(r&&!Array.isArray(r))return W({result:{error:Z,scheduledDates:r},stack:g});if(a&&![Hn,br].includes(a))return W({result:{error:ri},stack:g});let h=0;if((s||i)&&!e)return W({result:{error:pe},stack:g});if(v&&c){const I=Ju({tournamentRecord:t,drawDefinition:e,matchUpFormat:o,structureIds:i,structureId:s,matchUpId:c,force:m});if(I.error)return I;h+=1}const _=I=>{const P=[];for(const O of I.structures||[]){if(Array.isArray(p)&&!p.includes(O.stage)||Array.isArray(n)&&!n.includes(O.stageSequence)||i.length&&!i.includes(O.structureId))continue;i.length&&O.matchUpFormat!==o&&(O.matchUpFormat=o,P.push(O.structureId),h+=1);const y=(m||r)&&ze({matchUpFilters:{matchUpStatuses:[vt]},structure:O}),S=r&&ze({matchUpFilters:{matchUpStatuses:[vt]},contextFilters:{scheduledDates:r},afterRecoveryTimes:!1,inContext:!0,structure:O});if(y!=null&&y.length){const T=S?S.map(Mt):y.map(Mt);for(const E of y)T.includes(E.matchUpId)&&(E.matchUpFormat=r!=null&&r.length?o:void 0,Qe({tournamentId:t==null?void 0:t.tournamentId,eventId:f==null?void 0:f.eventId,context:g,drawDefinition:I,matchUp:E}))}}return!P.length&&I.matchUpFormat!==o&&(I.matchUpFormat=o,h+=1),P};i=i||[s].filter(Boolean),l=l||[u].filter(Boolean),d=d||[v].filter(Boolean);for(const I of t.events||[])if(!(l!=null&&l.length&&!l.includes(I.eventId)||a&&a!==I.eventType||a===Tt))if(Array.isArray(n)||Array.isArray(p)||i.length||d.length)for(const P of I.drawDefinitions||[]){if(Array.isArray(d)&&!d.includes(P.drawId))continue;const O=_(P);Je({structureIds:O,drawDefinition:P})}else I.matchUpFormat!==o&&(I.matchUpFormat=o,h+=1);return h?ZM(JM({},B),{modificationsCount:h}):ZM(JM({},B),{info:Ja})}var jve=Object.defineProperty,XM=Object.getOwnPropertySymbols,Rve=Object.prototype.hasOwnProperty,Fve=Object.prototype.propertyIsEnumerable,eD=(t,e,r)=>e in t?jve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,tD=(t,e)=>{for(var r in e||(e={}))Rve.call(e,r)&&eD(t,r,e[r]);if(XM)for(var r of XM(e))Fve.call(e,r)&&eD(t,r,e[r]);return t};function rD({tournamentRecord:t,drawDefinition:e,participantId:r,entryPosition:n,skipRefresh:o,event:i}){const s="setEntryPositions";return t?r?n!==void 0&&!Number.isSafeInteger(n)?{error:Z,entryPosition:n}:(((i==null?void 0:i.entries)||[]).forEach(a=>{a.participantId===r&&(a.entryPosition=n)}),((e==null?void 0:e.entries)||[]).forEach(a=>{a.participantId===r&&(a.entryPosition=n)}),o||(i!=null&&i.entries&&(i.entries=zr({entries:i.entries})),e!=null&&e.entries&&(e.entries=zr({entries:e.entries}))),tD({},B)):W({result:{error:yt},stack:s}):{error:ee}}function Lve({tournamentRecord:t,entryPositions:e,drawDefinition:r,event:n}){if(!t)return{error:ee};if(!Array.isArray(e))return{error:Z};for(const o of e){const{participantId:i,entryPosition:s}=o,a=rD({skipRefresh:!0,tournamentRecord:t,drawDefinition:r,participantId:i,entryPosition:s,event:n});if(a.error)return a}return n!=null&&n.entries&&(n.entries=zr({entries:n.entries})),r!=null&&r.entries&&(r.entries=zr({entries:r.entries})),tD({},B)}function Vve(t){return WA(t)}function nD({scaleAttributes:t,scaledEntries:e,stageEntries:r,seedsCount:n,scaleName:o}){if(!t)return{error:Oe,info:"missing scaleAttributes"};const i=Object.assign({},...(e||[]).slice(0,n).map(({participantId:c},l)=>({[c]:l+1})));o=o||t.scaleName;const s=new Date().toISOString();return{scaleItemsWithParticipantIds:r.map(({participantId:c})=>{const l={scaleValue:i[c],eventType:t.eventType,scaleType:rn,scaleName:o,scaleDate:s};return{participantId:c,scaleItems:[l]}})}}function xve(t){return JA(t)}var Bve=Object.defineProperty,oD=Object.getOwnPropertySymbols,kve=Object.prototype.hasOwnProperty,Gve=Object.prototype.propertyIsEnumerable,iD=(t,e,r)=>e in t?Bve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Wve=(t,e)=>{for(var r in e||(e={}))kve.call(e,r)&&iD(t,r,e[r]);if(oD)for(var r of oD(e))Gve.call(e,r)&&iD(t,r,e[r]);return t};function Hve({tournamentRecord:t,scaleAttributes:e,participantIds:r}){var n;if(!t)return{error:ee};if(!r)return{error:lo};if(!e)return{error:Oe,info:"scaleAttributes required"};const{scaleType:o,eventType:i,scaleName:s}=e,a=[ek,o,i,s].join(".");return(n=t.participants)==null||n.forEach(c=>{r.includes(c.participantId)&&c.timeItems&&(c.timeItems=c.timeItems.filter(l=>l&&(l==null?void 0:l.itemType)!==a))}),Wve({},B)}function sD({tournamentRecord:t,scaleAttributes:e,drawDefinition:r,entryStatuses:n,drawId:o,event:i,stage:s}){var a;if(!i)return{error:Le};if(n&&!Array.isArray(n))return W({result:{error:Z},info:zt("entryStatus"),stack:"removeScaleValues"});let c=i.entries;if(o){const{flightProfile:d}=It({event:i}),p=(a=d==null?void 0:d.flights)==null?void 0:a.find(v=>v.drawId===o);p?c=p.drawEntries:c=r==null?void 0:r.entries}const u=(c||[]).filter(d=>(!s||!d.entryStage||d.entryStage===s)&&(!n||n.includes(d.entryStatus))).map(Xe);return Hve({tournamentRecord:t,scaleAttributes:e,participantIds:u})}function ip({tournamentRecord:t,scaleAttributes:e,participantId:r}){if(!t)return{error:ee};if(!r)return{error:yt};const{participant:n}=Ro({tournamentRecord:t,participantId:r});return n?ro({participant:n,scaleAttributes:e}):{error:wt}}var qve=Object.defineProperty,aD=Object.getOwnPropertySymbols,Yve=Object.prototype.hasOwnProperty,zve=Object.prototype.propertyIsEnumerable,cD=(t,e,r)=>e in t?qve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lD=(t,e)=>{for(var r in e||(e={}))Yve.call(e,r)&&cD(t,r,e[r]);if(aD)for(var r of aD(e))zve.call(e,r)&&cD(t,r,e[r]);return t};function hl({sortDescending:t=!1,tournamentRecord:e,scaleAttributes:r,scaleSortMethod:n,stageSequence:o,entries:i,event:s,stage:a}){if(!e)return{error:ee};return i=i||(s==null?void 0:s.entries)||[],{scaledEntries:i.filter(p=>(!a||!p.entryStage||p.entryStage===a)&&(!o||!p.entryStageSequence||p.entryStageSequence===o)&&Wo.includes(p.entryStatus)).map(p=>{const{participantId:v}=p,{scaleItem:f}=ip({tournamentRecord:e,scaleAttributes:r,participantId:v});return lD(lD({},p),f)}).filter(p=>{const v=p.scaleValue;return!n&&(isNaN(v)||!parseFloat(v))?!1:v}).sort(n||u)};function u(p,v){return t?d(v)-d(p):d(p)-d(v)}function d(p){return parseFloat(p.scaleValue||(t?-1:1e5))}}function Kve({tournamentRecord:t,drawDefinition:e,entryStatuses:r,scaleName:n,drawId:o,event:i,stage:s}){var a,c;if(!t)return{error:ee};if(!i)return{error:Le};n=n||((a=i.category)==null?void 0:a.categoryName)||((c=i.category)==null?void 0:c.ageCategoryCode);const l={eventType:i.eventType,scaleType:rn,scaleName:n};return sD({tournamentRecord:t,scaleAttributes:l,drawDefinition:e,entryStatuses:r,drawId:o,event:i,stage:s})}function Qve({tournamentRecord:t,drawDefinition:e,policyDefinitions:r,scaleAttributes:n,scaleName:o,drawSize:i,drawId:s,event:a,stage:c,sortDescending:l,scaleSortMethod:u}){const d=GC({policyDefinitions:r,drawDefinition:e,drawSize:i,drawId:s,event:a,stage:c});if(d.error)return d;const{entries:p,seedsCount:v,stageEntries:f}=d,{scaledEntries:m}=hl({tournamentRecord:t,scaleAttributes:n,scaleSortMethod:u,sortDescending:l,entries:p,stage:c}),{scaleItemsWithParticipantIds:g}=nD({scaleAttributes:n,scaledEntries:m,stageEntries:f,seedsCount:v,scaleName:o});return{scaleItemsWithParticipantIds:g}}var Jve=Object.defineProperty,uD=Object.getOwnPropertySymbols,Zve=Object.prototype.hasOwnProperty,Xve=Object.prototype.propertyIsEnumerable,dD=(t,e,r)=>e in t?Jve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eme=(t,e)=>{for(var r in e||(e={}))Zve.call(e,r)&&dD(t,r,e[r]);if(uD)for(var r of uD(e))Xve.call(e,r)&&dD(t,r,e[r]);return t};function tme({tournamentRecord:t,drawDefinition:e,resetEntries:r,event:n}){var o,i;if(!e)return{error:pe};const s=(o=e.structures)==null?void 0:o.find(c=>c.stage===Ct);if(!s)return{error:Br};const a=((i=s.matchUps)==null?void 0:i.map(({matchUpId:c})=>c))||[];return s.positionAssignments=[],s.seedAssignments=[],s.matchUps=[],yi({tournamentId:t==null?void 0:t.tournamentId,action:"resetVoluntaryConsolationStructure",matchUpIds:a,drawDefinition:e}),r&&(e.entries=e.entries.filter(c=>c.entryStage!==Ct)),Je({tournamentId:t==null?void 0:t.tournamentId,eventId:n==null?void 0:n.eventId,drawDefinition:e,structureIds:[s.structureId]}),eme({},B)}var rme=Object.defineProperty,pD=Object.getOwnPropertySymbols,nme=Object.prototype.hasOwnProperty,ome=Object.prototype.propertyIsEnumerable,fD=(t,e,r)=>e in t?rme(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ime=(t,e)=>{for(var r in e||(e={}))nme.call(e,r)&&fD(t,r,e[r]);if(pD)for(var r of pD(e))ome.call(e,r)&&fD(t,r,e[r]);return t};function sme({autoPublish:t=!0,tournamentRecord:e,auditData:r,event:n}){var o;if(!e)return{error:ee};if(!n)return{error:Le};const{flightProfile:i}=It({event:n});if(i){const s=(o=i.flights)==null?void 0:o.map(({drawId:c})=>c).filter(Boolean),a=Ig({eventId:n.eventId,tournamentRecord:e,autoPublish:t,auditData:r,drawIds:s,event:n});return a.error?a:Jl({event:n,name:tn})}return ime({},B)}var ame=Object.defineProperty,vD=Object.getOwnPropertySymbols,cme=Object.prototype.hasOwnProperty,lme=Object.prototype.propertyIsEnumerable,mD=(t,e,r)=>e in t?ame(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ume=(t,e)=>{for(var r in e||(e={}))cme.call(e,r)&&mD(t,r,e[r]);if(vD)for(var r of vD(e))lme.call(e,r)&&mD(t,r,e[r]);return t};function gD({event:t,orderedDrawIdsMap:e}){var r,n;if(typeof t!="object")return{error:Le};if(!e)return{error:Oe,info:"Missing drawIdsOrderMap"};if(typeof e!="object")return{error:Z,info:"orderedDrawIdsMap must be an object"};const o=Object.values(e);if(!o.every(a=>!isNaN(a)))return{error:Z,info:"drawOrder must be numeric"};if(Ve(o).length!==o.length)return{error:Z,info:"drawOrder values must be unique"};if((r=t.drawDefinitions)!=null&&r.length){const a=(t.drawDefinitions||[]).map(({drawId:l})=>l),c=Object.keys(e);if(c!=null&&c.length&&jt(a,c).length!==a.length)return{error:Z,info:"Missing drawIds"};t.drawDefinitions.forEach(l=>{l.drawOrder=e[l.drawId]})}const{flightProfile:s}=It({event:t});return(n=s==null?void 0:s.flights)==null||n.forEach(a=>{a.flightNumber=e[a.drawId]}),ume({},B)}var dme=Object.defineProperty,hD=Object.getOwnPropertySymbols,pme=Object.prototype.hasOwnProperty,fme=Object.prototype.propertyIsEnumerable,_D=(t,e,r)=>e in t?dme(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vme=(t,e)=>{for(var r in e||(e={}))pme.call(e,r)&&_D(t,r,e[r]);if(hD)for(var r of hD(e))fme.call(e,r)&&_D(t,r,e[r]);return t};function ID({tournamentRecord:t,event:e}){var r;if(!t)return{error:ee};if(!e)return{error:Le};const{flightProfile:n}=It({event:e}),o=(n==null?void 0:n.flights)&&Object.assign({},...n.flights.sort((i,s)=>i.flightNumber-s.flightNumber).map((i,s)=>({[i.drawId]:s+1})))||((r=e.drawDefinitions)==null?void 0:r.length)&&Object.assign({},...e.drawDefinitions.sort((i,s)=>i.drawOrder-s.drawOrder).map((i,s)=>({[i.drawId]:s+1})))||void 0;return o?gD({event:e,orderedDrawIdsMap:o}):vme({},B)}var mme=Object.defineProperty,gme=Object.defineProperties,hme=Object.getOwnPropertyDescriptors,PD=Object.getOwnPropertySymbols,_me=Object.prototype.hasOwnProperty,Ime=Object.prototype.propertyIsEnumerable,yD=(t,e,r)=>e in t?mme(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Pme=(t,e)=>{for(var r in e||(e={}))_me.call(e,r)&&yD(t,r,e[r]);if(PD)for(var r of PD(e))Ime.call(e,r)&&yD(t,r,e[r]);return t},yme=(t,e)=>gme(t,hme(e));function Sme({autoPublish:t=!0,tournamentRecord:e,auditData:r,drawId:n,event:o}){var i,s;if(!e)return{error:ee};if(!n)return{error:wr};if(!o)return{error:Le};const{flightProfile:a}=It({event:o});if(a&&((i=a.flights)==null?void 0:i.find(u=>u.drawId===n))){const u=a.flights.filter(p=>p.drawId!==n),d={name:tn,value:yme(Pme({},a),{flights:u})};Wn({event:o,extension:d})}if((s=o.drawDefinitions)==null?void 0:s.find(l=>l.drawId===n)){const l=Ig({drawIds:[n],eventId:o.eventId,tournamentRecord:e,autoPublish:t,auditData:r,event:o});if(l.error)return l}return ID({tournamentRecord:e,event:o})}function Ome(t){return Rm(t)}function bme(t){return Fm(t)}var Tme=Object.defineProperty,SD=Object.getOwnPropertySymbols,Eme=Object.prototype.hasOwnProperty,wme=Object.prototype.propertyIsEnumerable,OD=(t,e,r)=>e in t?Tme(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$me=(t,e)=>{for(var r in e||(e={}))Eme.call(e,r)&&OD(t,r,e[r]);if(SD)for(var r of SD(e))wme.call(e,r)&&OD(t,r,e[r]);return t};function Og({deleteExisting:t,event:e,flightProfile:r}){var n;const o="attachFlightProfile";if(!r)return W({result:{error:Oe},stack:o});if(!e)return W({result:{error:Le},stack:o});const{flightProfile:i}=It({event:e});return i&&Og&&!t?W({result:{error:Wh},stack:o}):(n=e.drawDefinitions)!=null&&n.length?W({result:{error:nF},stack:o}):(Wn({event:e,extension:{name:tn,value:r}}),$me({flightProfile:ue(r,!1,!0)},B))}const Nme="splitWaterfall",Ame="splitShuttle";var Ume=Object.defineProperty,bD=Object.getOwnPropertySymbols,Cme=Object.prototype.hasOwnProperty,Mme=Object.prototype.propertyIsEnumerable,TD=(t,e,r)=>e in t?Ume(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ED=(t,e)=>{for(var r in e||(e={}))Cme.call(e,r)&&TD(t,r,e[r]);if(bD)for(var r of bD(e))Mme.call(e,r)&&TD(t,r,e[r]);return t};function Dme({drawNameRoot:t="Flight",attachFlightProfile:e,tournamentRecord:r,scaleAttributes:n,scaleSortMethod:o,deleteExisting:i,sortDescending:s,drawNames:a=[],scaledEntries:c,flightsCount:l,flightValues:u,splitMethod:d,uuids:p=[],event:v,stage:f}){if(!v)return{error:Le};const m=v.entries||[],{flightProfile:g}=It({event:v});if(g&&e&&!i)return{error:Wh};c||({scaledEntries:c}=hl({tournamentRecord:r,scaleAttributes:n,scaleSortMethod:o,sortDescending:s,event:v,stage:f}));const h=c.map(Xe),_=m.filter(({participantId:b})=>!h.includes(b)).filter(b=>(!f||!b.entryStage||b.entryStage===f)&&os.includes(b.entryStatus)),I=c.concat(..._),P=I.length,O=Math.ceil(P/l);let y=Rt(I,O);d===Nme?y=lh(I,l):d===Ame&&(y=lh(I,l,!0));function S(b){return(b||[]).map(({participantId:N,scaleValue:w})=>{const $=m.find(U=>U.participantId===N);return w&&($.scaleValue=w),$}).sort((N,w)=>N.scaleValue-w.scaleValue).map((N,w)=>(N.scaleValue&&(N.seedNumber=w+1),N))}const T=le(0,l).map(b=>{var N;const w=b+1,$={flightNumber:w,drawId:(p==null?void 0:p.pop())||We(),drawEntries:S(y[b]),drawName:(a==null?void 0:a.length)&&a[b]||`${t} ${w}`},U=(N=u==null?void 0:u.find(A=>A.flightNumber===w))==null?void 0:N.matchUpValue;return U&&($.matchUpValue=U),$}),E={scaleAttributes:n,splitMethod:d,flights:T};if(e){const b=Og({flightProfile:E,deleteExisting:i,event:v});return ED({splitEntries:Ft()&&y||void 0},b)}else return ED({flightProfile:E},B)}var jme=Object.defineProperty,wD=Object.getOwnPropertySymbols,Rme=Object.prototype.hasOwnProperty,Fme=Object.prototype.propertyIsEnumerable,$D=(t,e,r)=>e in t?jme(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lme=(t,e)=>{for(var r in e||(e={}))Rme.call(e,r)&&$D(t,r,e[r]);if(wD)for(var r of wD(e))Fme.call(e,r)&&$D(t,r,e[r]);return t};function Vme(t){const{tournamentRecord:e}=t;if(!e)return{error:ee};const r=e.participants;return bN(Lme({participants:r},t))}function xme(t){return yN(t)}function Bme({substituteParticipantId:t,existingParticipantId:e,tournamentRecord:r,drawDefinition:n,sideNumber:o,matchUpId:i,event:s}){const a="substituteParticipant";if(!n)return{error:pe};if(!i)return{error:Ut};if(!e||!t)return W({result:{error:yt},stack:a});const{matchUp:c}=nt({drawDefinition:n,matchUpId:i,event:s});if(!c)return{error:kr};if(!c.collectionId)return W({result:{error:Gr},stack:a});const l=Kt({drawDefinition:n}),{matchUps:u}=Nt({tournamentParticipants:r==null?void 0:r.participants,includeByeMatchUps:!0,inContext:!0,drawDefinition:n,matchUpsMap:l}),d=u.find(m=>m.matchUpId===i),v=u.find(m=>m.matchUpId===d.matchUpTieId).sides.find(m=>m.participant.individualParticipants.some(({participantId:g})=>g===e));return!v||o&&v.sideNumber!==o?{error:co}:v.participant.individualParticipants.map(Xe).filter(m=>m!==e).includes(t)?sM({newParticipantId:t,tieMatchUpId:i,existingParticipantId:e,substitution:!0,tournamentRecord:r,drawDefinition:n,event:s}):W({result:{error:co},stack:a})}function kme(t){return Bme(t)}function Gme(t){return xN(t)}var Wme=Object.defineProperty,ND=Object.getOwnPropertySymbols,Hme=Object.prototype.hasOwnProperty,qme=Object.prototype.propertyIsEnumerable,AD=(t,e,r)=>e in t?Wme(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yme=(t,e)=>{for(var r in e||(e={}))Hme.call(e,r)&&AD(t,r,e[r]);if(ND)for(var r of ND(e))qme.call(e,r)&&AD(t,r,e[r]);return t};function zme({tournamentRecord:t,removeScheduling:e,drawDefinition:r}){var n;if(!r)return{error:pe};const o=Kt({drawDefinition:r}),i=a=>{var c;return(c=o==null?void 0:o.drawMatchUps)==null?void 0:c.find(l=>l.matchUpId===a)};for(const a of r.structures||[]){const{positionAssignments:c,stage:l,stageSequence:u}=a;c&&(u!==1||![Ie,de].includes(l))&&(a.positionAssignments=c.map(p=>(delete p.participantId,p)),a.seedAssignments=[]);const{matchUps:d}=ze({afterRecoveryTimes:!1,inContext:!0,matchUpsMap:o,structure:a});for(const p of d){const{matchUpId:v,roundNumber:f,sides:m}=p,g=i(v);if(delete g.extensions,delete g.notes,g.matchUpStatus!==qe&&Object.assign(g,hu),f&&f>1&&g.drawPositions){const h=m==null?void 0:m.map(({drawPosition:_,participantFed:I})=>!I&&_).filter(Boolean);g.drawPositions=g.drawPositions.map(_=>h.includes(_)?void 0:_)}e?delete g.timeItems:(n=g.timeItems)!=null&&n.length&&(g.timeItems=g.timeItems.filter(h=>![Vo,Xi,vc,XB,mc,gc].includes(h.itemType))),Qe({tournamentId:t==null?void 0:t.tournamentId,context:"resetDrawDefiniton",drawDefinition:r,matchUp:g})}}const s=(r.structures||[]).map(({structureId:a})=>a);return Je({drawDefinition:r,structureIds:s}),Yme({},B)}var Kme=Object.defineProperty,Qme=Object.defineProperties,Jme=Object.getOwnPropertyDescriptors,UD=Object.getOwnPropertySymbols,Zme=Object.prototype.hasOwnProperty,Xme=Object.prototype.propertyIsEnumerable,CD=(t,e,r)=>e in t?Kme(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ege=(t,e)=>{for(var r in e||(e={}))Zme.call(e,r)&&CD(t,r,e[r]);if(UD)for(var r of UD(e))Xme.call(e,r)&&CD(t,r,e[r]);return t},tge=(t,e)=>Qme(t,Jme(e));function rge({matchPlayDrawPositions:t=!0,tournamentRecord:e,drawDefinition:r,drawId:n}){if(!e)return{error:ee};if(!r)return{error:pe};let o=[];const{drawsAnalysis:i}=vg({tournamentRecord:e});if(i.canBePruned.includes(n)){const s=i.matchPlay.includes(n),a=i.drawAnalysis[n],{structures:[c]}=Cr({stageSequence:1,drawDefinition:r,stage:de}),l=a.structuresData.find(({structureId:v})=>c.structureId===v),u=c.matchUps||[];o=u.sort((v,f)=>v.roundPosition-f.roundPosition).filter(({roundNumber:v})=>!l.inactiveRounds.includes(v));const d=o.map(Mt),p=u.map(Mt).filter(v=>!d.includes(v));if(s){const v=o.sort((I,P)=>I.roundPosition-P.roundPosition).filter(({roundNumber:I})=>!l.inactiveRounds.includes(I)).filter(({winningSide:I})=>I),f=v.map(Mt),m=d.filter(I=>!f.includes(I));p.push(...m);const h=v.map(({drawPositions:I})=>I).flat(),_=Object.assign({},...h.map((I,P)=>({[I]:P+1})));if(v.forEach(I=>{t?I.drawPositions=I.drawPositions.map(P=>_[P]):delete I.drawPositions}),t){const I=c.positionAssignments.filter(P=>h.includes(P.drawPosition)).map(P=>(P.drawPosition=_[P.drawPosition],P));c.positionAssignments=I}else c.positionAssignments=[];c.matchUps=v,o=v}yi({tournamentId:e==null?void 0:e.tournamentId,matchUpIds:p,drawDefinition:r}),Je({drawDefinition:r})}return tge(ege({},B),{matchUps:o})}function nge(t){return n1(t)}const oge="ASC",MD="DESC";var ige=Object.defineProperty,sge=Object.defineProperties,age=Object.getOwnPropertyDescriptors,DD=Object.getOwnPropertySymbols,cge=Object.prototype.hasOwnProperty,lge=Object.prototype.propertyIsEnumerable,jD=(t,e,r)=>e in t?ige(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,uge=(t,e)=>{for(var r in e||(e={}))cge.call(e,r)&&jD(t,r,e[r]);if(DD)for(var r of DD(e))lge.call(e,r)&&jD(t,r,e[r]);return t},dge=(t,e)=>sge(t,age(e));function RD({useDefaultEventRanking:t,tournamentRecord:e,drawDefinition:r,scaleAccessor:n,singlesOnly:o,tieFormat:i,attach:s,event:a}){var c,l,u;if((a==null?void 0:a.eventType)!==Nn)return{error:ri};if(!e)return{error:ee};if(!i&&!r)return{error:_n};if(i=i||((c=Xt({drawDefinition:r,event:a}))==null?void 0:c.tieFormat),ur({tieFormat:i}).error)return{error:ni};if(typeof n!="object"&&!t)return{error:Z,context:{scaleAccessor:n}};const d={},v=((r==null?void 0:r.entries)||a.entries).filter(U=>(U==null?void 0:U.entryStatus)===Mr).map(Xe),{participants:f=[]}=ys({withIndividualParticipants:!0,withScaleValues:!0,tournamentRecord:e}),m=f.filter(({participantId:U})=>v.includes(U)),g=U=>U===ui?"rankings":"ratings",h=((l=a==null?void 0:a.category)==null?void 0:l.categoryName)||((u=a==null?void 0:a.category)==null?void 0:u.ageCategoryCode),{scaleName:_=h,scaleType:I=ui,sortOrder:P,accessor:O}=n||{},y=g(I),S=(U,A)=>{var M,C,D;let F=(M=U[y])==null?void 0:M[A];if(!F&&t&&(F=(C=U[y])==null?void 0:C[ci]),Array.isArray(F)){const R=(D=F.find(G=>G.scaleName===_))==null?void 0:D.scaleValue;if(Ot(R))return R;if(O&&typeof R=="object")return R[O]}return 0},T=(U,A,M)=>{const C=P===MD?A:U,D=P===MD?U:A;return S(C,M)-S(D,M)},E=(U,A)=>T(U,A,ci),b=(U,A)=>T(U,A,Jr),N=[],w=i.collectionDefinitions||[];for(const U of m){const A=U.individualParticipants.sort(E),M=o?A:U.individualParticipants.sort(b),C={};for(const F of w){const R=[],{collectionId:G,matchUpCount:x,matchUpType:z,gender:j}=F,V=z===ci;le(0,x).forEach(L=>{const q=V?A:M,k=L+1,H=[];le(0,V?1:2).forEach(Q=>{const K=q.find(Y=>{const J=[ct,mt].includes(j)&&j||j===yo&&[ct,mt][Q];return(!J||J===Y.person.sex)&&!R.includes(Y.participantId)}).participantId;K&&(H.push(K),R.push(K),C[K]||(C[K]=[]),C[K].push({collectionPosition:k,collectionId:G}))}),V||N.push(H)})}const D=Object.keys(C).map(F=>({collectionAssignments:C[F],participantId:F}));d[U.participantId]=D}const $=[];for(const U of N){const{participant:A}=Un({tournamentParticipants:f,participantIds:U});if(!A){const M={individualParticipantIds:U,participantRole:qt,participantType:we};$.push(M)}}if(s){for(;$.length;)Rn({participant:$.pop(),tournamentRecord:e});tt({element:r,extension:{name:bn,value:d}})}return dge(uge({},B),{lineUps:d,participantsToAdd:$})}var pge=Object.defineProperty,fge=Object.defineProperties,vge=Object.getOwnPropertyDescriptors,FD=Object.getOwnPropertySymbols,mge=Object.prototype.hasOwnProperty,gge=Object.prototype.propertyIsEnumerable,LD=(t,e,r)=>e in t?pge(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,VD=(t,e)=>{for(var r in e||(e={}))mge.call(e,r)&&LD(t,r,e[r]);if(FD)for(var r of FD(e))gge.call(e,r)&&LD(t,r,e[r]);return t},hge=(t,e)=>fge(t,vge(e));function _ge({event:t,drawId:e,drawDefinition:r,drawName:n}){var o;if(!n||typeof n!="string")return{error:Z,drawName:n};const{flightProfile:i}=It({event:t}),s=(o=i==null?void 0:i.flights)==null?void 0:o.find(a=>a.drawId===e);if(s){s.drawName=n;const a={name:tn,value:hge(VD({},i),{flights:i.flights})};Wn({event:t,extension:a})}return r&&(r.drawName=n,Je({drawDefinition:r})),!s&&!r?{error:pe}:VD({},B)}var Ige=Object.defineProperty,xD=Object.getOwnPropertySymbols,Pge=Object.prototype.hasOwnProperty,yge=Object.prototype.propertyIsEnumerable,BD=(t,e,r)=>e in t?Ige(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Sge=(t,e)=>{for(var r in e||(e={}))Pge.call(e,r)&&BD(t,r,e[r]);if(xD)for(var r of xD(e))yge.call(e,r)&&BD(t,r,e[r]);return t};function Oge({event:t,tournamentRecord:e,entryStage:r=de,participantIdPairs:n=[],unpairedParticipantIds:o=[],entryStatus:i=Mr}){if(!e)return{error:ee};if(!t)return{error:Le};const s=e.participants||[],a=s.filter(h=>h.participantType===Me).map(h=>h.participantId),l=o.concat(...n).flat(1/0).filter(h=>!a.includes(h));if(l.length)return{error:Qr,invalidParticipantIds:l};const u=n.filter(h=>h.length!==2);if(u.length)return{error:Qr,invalidParticipantIdPairs:u};const d=s.filter(h=>h.participantType===we).map(h=>h.individualParticipantIds),v=n.filter(h=>!d.find(_=>jt(_,h).length===2)).map(h=>({participantType:we,participantRole:qt,individualParticipantIds:h})),f=to({tournamentRecord:e,participants:v});if(f.error)return f;const m=n.map(h=>{const{participant:_}=Un({tournamentRecord:e,participantIds:h});return _}).map(h=>({participantId:h,entryStatus:i,entryStage:r})),g=o.map(h=>({entryStatus:qr,participantId:h,entryStage:r}));return t.entries=(t.entries||[]).filter(h=>h.entryStage===r),t.entries=t.entries.concat(...m,...g),Sge({},B)}function bg(t){var e;const r=(e=t.tournamentRecord)==null?void 0:e.participants;return Object.assign(t,{tournamentParticipants:r}),KA(t)}var bge=Object.defineProperty,Tge=Object.defineProperties,Ege=Object.getOwnPropertyDescriptors,kD=Object.getOwnPropertySymbols,wge=Object.prototype.hasOwnProperty,$ge=Object.prototype.propertyIsEnumerable,GD=(t,e,r)=>e in t?bge(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Nge=(t,e)=>{for(var r in e||(e={}))wge.call(e,r)&&GD(t,r,e[r]);if(kD)for(var r of kD(e))$ge.call(e,r)&&GD(t,r,e[r]);return t},Age=(t,e)=>Tge(t,Ege(e));function Tg({qualifyingPositions:t,drawEntries:e=[],drawName:r,drawId:n,event:o,stage:i}){var s,a,c;const l="addFlight";if(!o)return W({result:{error:Le},stack:l});if(!r)return W({result:{error:Oe},stack:l});if(e!=null&&e.length){const _=Kn(o.entries||[]),I=Kn(e);if(jt(I,_).length!==I.length)return W({result:{error:Z},stack:l})}const u=(s=It({event:o}))==null?void 0:s.flightProfile,d=((c=(a=u==null?void 0:u.flights)==null?void 0:a.map(({flightNumber:_})=>!isNaN(_)&&parseInt(_)))==null?void 0:c.filter(Boolean))||[],p=Math.max(0,...d)+1,f={drawId:n||We(),flightNumber:p,drawEntries:e,drawName:r};if(i&&(f.stage=i),t&&(f.qualifyingPositions=t),((u==null?void 0:u.flights)||[]).find(({drawId:_})=>_===f.drawId))return W({result:{error:sL},stack:l});const g=((u==null?void 0:u.flights)||[]).concat(f),h={name:tn,value:Age(Nge({},u||{}),{flights:g})};return Wn({event:o,extension:h})}var Uge=Object.defineProperty,Cge=Object.defineProperties,Mge=Object.getOwnPropertyDescriptors,WD=Object.getOwnPropertySymbols,Dge=Object.prototype.hasOwnProperty,jge=Object.prototype.propertyIsEnumerable,HD=(t,e,r)=>e in t?Uge(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qD=(t,e)=>{for(var r in e||(e={}))Dge.call(e,r)&&HD(t,r,e[r]);if(WD)for(var r of WD(e))jge.call(e,r)&&HD(t,r,e[r]);return t},YD=(t,e)=>Cge(t,Mge(e));function Rge(t){return Eg(YD(qD({},t),{itemType:"attachConsolationStructures"}))}function Fge(t){return Eg(YD(qD({},t),{itemType:"attachPlayoffStructures"}))}function Eg({itemType:t="attachStructures",matchUpModifications:e,tournamentRecord:r,drawDefinition:n,structures:o,links:i}){if(!r)return{error:ee};if(!n)return{error:pe};const s=RN({matchUpModifications:e,tournamentRecord:r,drawDefinition:n,structures:o,links:i});if(s.error)return s;const l={itemValue:{structureIds:o==null?void 0:o.map(({structureId:u})=>u),drawId:n.drawId},itemType:t};return bo({tournamentRecord:r,timeItem:l}),s}var Lge=Object.defineProperty,zD=Object.getOwnPropertySymbols,Vge=Object.prototype.hasOwnProperty,xge=Object.prototype.propertyIsEnumerable,KD=(t,e,r)=>e in t?Lge(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wg=(t,e)=>{for(var r in e||(e={}))Vge.call(e,r)&&KD(t,r,e[r]);if(zD)for(var r of zD(e))xge.call(e,r)&&KD(t,r,e[r]);return t};function QD({tournamentRecord:t,event:e,startDate:r}){if(!t)return{error:ee};if(!e)return{error:Le};if(!Sn.test(r))return{error:cr};const n=ZD(t);if(n.error)return n;const{tournamentStartDate:o,tournamentEndDate:i}=n,s=new Date(Ce(r));if(s<o||s>i)return{error:cr};const a=e.endDate&&new Date(Ce(e.endDate));return a&&s>a&&(e.endDate=r),e.startDate=r,wg({},B)}function JD({tournamentRecord:t,event:e,endDate:r}){if(!t)return{error:ee};if(!e)return{error:Le};if(!Sn.test(r))return{error:cr};const n=ZD(t);if(n.error)return n;const{tournamentStartDate:o,tournamentEndDate:i}=n,s=new Date(Ce(r));if(s<o||s>i)return{error:cr};const a=e.startDate&&new Date(Ce(e.startDate));return a&&s<a&&(e.startDate=r),e.endDate=r,wg({},B)}function Bge({tournamentRecord:t,event:e,startDate:r,endDate:n}){if(!t)return{error:ee};if(!e)return{error:Le};if(!r&&!n)return{error:Oe,info:"missing date"};if(r&&!Sn.test(r))return{error:cr};if(n&&!Sn.test(n))return{error:cr};if(r&&n){const o=new Date(Ce(r)),i=new Date(Ce(n));if(o>i)return{error:Z}}if(r){const o=QD({tournamentRecord:t,event:e,startDate:r});if(o.error)return o}if(n){const o=JD({tournamentRecord:t,event:e,endDate:n});if(o.error)return o}return wg({},B)}function ZD(t){const{startDate:e,endDate:r}=t;return!Sn.test(e)||!Sn.test(r)?W({result:{error:NF},context:{startDate:e,endDate:r}}):{tournamentStartDate:new Date(Ce(e)),tournamentEndDate:new Date(Ce(r))}}var kge=Object.defineProperty,XD=Object.getOwnPropertySymbols,Gge=Object.prototype.hasOwnProperty,Wge=Object.prototype.propertyIsEnumerable,e2=(t,e,r)=>e in t?kge(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Hge=(t,e)=>{for(var r in e||(e={}))Gge.call(e,r)&&e2(t,r,e[r]);if(XD)for(var r of XD(e))Wge.call(e,r)&&e2(t,r,e[r]);return t};function qge({tournamentRecord:t,drawDefinition:e,drawPosition:r}){return t?e?ut(r)?Hge({},B):{error:js}:{error:pe}:{error:ee}}var Yge=Object.defineProperty,t2=Object.getOwnPropertySymbols,zge=Object.prototype.hasOwnProperty,Kge=Object.prototype.propertyIsEnumerable,r2=(t,e,r)=>e in t?Yge(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Qge=(t,e)=>{for(var r in e||(e={}))zge.call(e,r)&&r2(t,r,e[r]);if(t2)for(var r of t2(e))Kge.call(e,r)&&r2(t,r,e[r]);return t};function Jge({tournamentRecord:t,drawDefinition:e,matchUpId:r,lineUps:n,event:o}){var i,s,a,c;if(!t)return{error:ee};if(!e)return{error:_n};if(typeof r!="string")return{error:Gr};if(!Array.isArray(n))return{error:Z,lineUps:n};const l="applyLineUps",u=t.participants||[];let d=nt({tournamentParticipants:u,inContext:!0,drawDefinition:e,matchUpId:r});if(d.error)return d;const{matchUp:p,structure:v}=d,{drawPositions:f,matchUpType:m}=p;if(m!==He)return{error:Gr};if(!(f!=null&&f.length))return{error:Op};const g=(i=Xt({matchUp:p,drawDefinition:e,structure:v,event:o}))==null?void 0:i.tieFormat,h={};for(const I of n){if(!Array.isArray(I))return{error:Z,lineUp:I};const P={},O=[];for(const T of I){if(typeof T!="object")return{error:Z,lineUpAssignment:T};const{participantId:E,collectionAssignments:b=[]}=T;if(!Array.isArray(b))return{error:Z,collectionAssignments:b};const N=u.find($=>$.participantId===E);if(!N)return{error:wt};if(N.participantType!==Me)return{error:In};const w=(a=(s=p.sides)==null?void 0:s.find($=>{var U,A;return(A=(U=$.participant)==null?void 0:U.individualParticipantIds)==null?void 0:A.includes(E)}))==null?void 0:a.sideNumber;w&&O.push(w);for(const $ of b){if(typeof $!="object")return{error:Z,collectionAssignment:$};const{collectionId:U,collectionPosition:A}=$,M=(c=g==null?void 0:g.collectionDefinitions)==null?void 0:c.find(F=>F.collectionId===U);if(!M)return{error:Z,collectionId:U};const C=`${U}-${A}`;P[C]||(P[C]=[]);const D=P[C].length;if(M.matchUpType===pt&&D||M.matchUpType===it&&D>1)return{info:"Excessive collectionPosition assignments",error:Z};P[C].push(E)}}for(const T of Object.values(P))if(T.length===2){const{pairedParticipant:E}=Un({tournamentParticipants:u,participantIds:T});if(!E){const N=Rn({participant:{participantType:we,participantRole:qt,individualParticipantIds:T},pairOverride:!0,tournamentRecord:t});if(N.error)return N}}const y=mr(O),S=(y[1]||0)>(y[2]||0)&&1||(y[2]||0)>(y[1]||0)&&2||void 0;S&&!Object.keys(h).includes(S)&&(h[S]=I)}if(!Object.keys(h).length)return{error:kh};if(d=nt({drawDefinition:e,matchUpId:r}),d.error)return d;const{matchUp:_}=d;_.sides||(_.sides=[]);for(const I of[1,2]){const P=_.sides.find(y=>y.sideNumber===I),O=h[I];if(O)P?P.lineUp=O:_.sides.push({lineUp:O,sideNumber:I});else continue}return Qe({tournamentId:t==null?void 0:t.tournamentId,context:l,drawDefinition:e,matchUp:_}),Qge({},B)}function Zge(t){return u1(t)}function Xge(t){return Nm(t)}function ehe(t){return wm(t)}var the=Object.defineProperty,n2=Object.getOwnPropertySymbols,rhe=Object.prototype.hasOwnProperty,nhe=Object.prototype.propertyIsEnumerable,o2=(t,e,r)=>e in t?the(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ohe=(t,e)=>{for(var r in e||(e={}))rhe.call(e,r)&&o2(t,r,e[r]);if(n2)for(var r of n2(e))nhe.call(e,r)&&o2(t,r,e[r]);return t};function ihe(t){const{tournamentRecord:e}=t;if(!e)return{error:ee};const r=e.participants;return Dm(ohe({participants:r},t))}function she({tournamentRecord:t,drawDefinition:e,structure:r,link:n}){if(!t)return{error:ee};if(!e)return{error:pe};const o=jm({tournamentRecord:t,drawDefinition:e,structure:r,link:n});if(o.error)return o;const s={itemType:"attachQualifyingStructures",itemValue:{structureId:r.structureId,drawId:e.drawId}};return bo({tournamentRecord:t,timeItem:s}),o}function ahe(t){const e=t.tournamentRecord;if(!e)return{error:ee};const r=UN(t);if(r.error)return r;const{qualifyingRoundNumber:n,qualifyingPositions:o,targetStructureId:i,drawDefinition:s,structureName:a,matchUpType:c,drawSize:l,drawType:u}=t,p={itemType:"addQualifyingStructures",itemValue:_e({drawId:s.drawId,structureName:a,targetStructureId:i,qualifyingPositions:o,qualifyingRoundNumber:n,matchUpType:c,drawSize:l,drawType:u})};return bo({tournamentRecord:e,timeItem:p}),r}var che=Object.defineProperty,i2=Object.getOwnPropertySymbols,lhe=Object.prototype.hasOwnProperty,uhe=Object.prototype.propertyIsEnumerable,s2=(t,e,r)=>e in t?che(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dhe=(t,e)=>{for(var r in e||(e={}))lhe.call(e,r)&&s2(t,r,e[r]);if(i2)for(var r of i2(e))uhe.call(e,r)&&s2(t,r,e[r]);return t};function phe(t){const{tournamentRecord:e}=t;if(!e)return{error:ee};const r=e.participants;return Om(dhe({participants:r},t))}function a2({preparedStructureIds:t=[],provisionalPositioning:e,inContextDrawMatchUps:r,tournamentRecord:n,appliedPolicies:o,qualifyingOnly:i,drawDefinition:s,seedingProfile:a,participants:c,matchUpsMap:l,automated:u,placeByes:d,drawType:p,drawSize:v,entries:f,event:m,enforcePolicyLimits:g=!0,seedAssignmentProfile:h,seedByRanking:_=!0,seededParticipants:I,assignSeedsCount:P,seedingScaleName:O,seedsCount:y,stageSequence:S=1,roundTarget:T,stage:E}){const b=m==null?void 0:m.eventType,N=f.filter(x=>{var z,j;const V=(j=(z=Vt({name:Tn,element:x}))==null?void 0:z.extension)==null?void 0:j.value;return(!x.entryStage||x.entryStage===E)&&(!S||!x.entryStageSequence||x.entryStageSequence===S)&&(!T||!V||V===T)&&os.includes(x.entryStatus)});I&&(y=I.length),y>v&&(y=v),y>N.length&&(y=N.length);const{structures:w}=Cr({drawDefinition:s,stageSequence:S,roundTarget:T,stage:E}),$=w.length>1,U=w.find(({structureId:x})=>!t.includes(x)),{structureId:A}=U||{},M=_s({provisionalPositioning:e,appliedPolicies:o,drawDefinition:s,structure:U,event:m}),{seedLimit:C}=ZN({participantCount:N.length,enforcePolicyLimits:g,appliedPolicies:o,drawDefinition:s,seedingProfile:a,structureId:A,seedsCount:y});C&&C<y&&(y=C);const D=f.map(Xe);if(I)I.filter(({participantId:x})=>D.includes(x)).filter(x=>!x.seedNumber||x.seedNumber<=I.length).sort((x,z)=>x.seedNumber<z.seedNumber?-1:x.seedNumber<z.seedNumber?1:0).forEach(x=>{const{participantId:z,seedNumber:j,seedValue:V}=x;Ps({provisionalPositioning:e,tournamentRecord:n,drawDefinition:s,seedingProfile:a,participantId:z,seedBlockInfo:M,structureId:A,seedNumber:j,seedValue:V,event:m})});else if(m||O){const{categoryName:x,ageCategoryCode:z}=(m==null?void 0:m.category)||{},j={scaleType:rn,scaleName:O||x||z||m.eventId,eventType:b};let{scaledEntries:V}=hl({scaleAttributes:j,tournamentRecord:n,stageSequence:S,entries:f,stage:E});!(V!=null&&V.length)&&_&&({scaledEntries:V}=hl({scaleAttributes:{scaleType:ui,scaleName:x||z,eventType:b},tournamentRecord:n,stageSequence:S,entries:f,stage:E}));const L=(V==null?void 0:V.length)||0;L<y&&(y=L),V==null||V.filter(({participantId:q})=>D.includes(q)).slice(0,P||y).forEach((q,k)=>{const H=k+1,{participantId:Q,scaleValue:K}=q,Y=(h==null?void 0:h[H])||K||H;Ps({provisionalPositioning:e,tournamentRecord:n,drawDefinition:s,seedingProfile:a,participantId:Q,structureId:A,seedNumber:H,seedValue:Y,event:m})})}let F,R,G=[];if(u!==!1&&p!==cn&&!(i&&E!==Ie)){const x=typeof u=="object"&&u.seedsOnly,z=pl({inContextDrawMatchUps:r,multipleStructures:$,tournamentRecord:n,appliedPolicies:o,drawDefinition:s,seedingProfile:a,participants:c,structureId:A,matchUpsMap:l,placeByes:d,seedLimit:C,seedsOnly:x,drawType:p,event:m});if(G=z==null?void 0:z.conflicts,F=z==null?void 0:z.positionAssignments,R=z==null?void 0:z.positioningReport,z.error)return W({result:z,stack:"prepareStage"})}return{positionAssignments:F,positioningReport:R,stageEntries:N,structureId:A,seedsCount:y,conflicts:G}}var fhe=Object.defineProperty,vhe=Object.defineProperties,mhe=Object.getOwnPropertyDescriptors,c2=Object.getOwnPropertySymbols,ghe=Object.prototype.hasOwnProperty,hhe=Object.prototype.propertyIsEnumerable,l2=(t,e,r)=>e in t?fhe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Xo=(t,e)=>{for(var r in e||(e={}))ghe.call(e,r)&&l2(t,r,e[r]);if(c2)for(var r of c2(e))hhe.call(e,r)&&l2(t,r,e[r]);return t},Ns=(t,e)=>vhe(t,mhe(e));function $g(t){var e,r,n,o,i,s,a,c,l,u,d,p,v,f;const m="generateDrawDefinition",{drawType:g=zn,considerEventEntries:h=!0,ignoreAllowedDrawTypes:_,voluntaryConsolation:I,hydrateCollections:P,policyDefinitions:O,ignoreStageSpace:y,tournamentRecord:S,qualifyingOnly:T,tieFormatName:E,drawEntries:b,addToEvent:N,placeByes:w,event:$}=t,{tournamentParticipants:U}=Qt({tournamentRecord:S,inContext:!0}),A=$&&U&&bM({event:$,participants:U});if(A!=null&&A.error)return W({result:A,stack:m});const M=!_&&S&&kC({tournamentRecord:S,categoryType:$==null?void 0:$.categoryType,categoryName:$==null?void 0:$.categoryName});if(M!=null&&M.length&&!M.includes(g))return W({result:{error:mh},stack:m});const C=((e=$==null?void 0:$.entries)==null?void 0:e.filter(X=>[...TP,lu].includes(X.entryStatus)))||[],D=(T&&[]||b||(h?C:[])).filter(({entryStage:X})=>!X||X===de);let R=!t.drawSize&&D.length&&![cn,bc,Xs,ln,Io].includes(g)&&Ds(D.length)||ut(t.drawSize)&&parseInt(t.drawSize);if(isNaN(R)&&g!==cn)return W({result:{error:El},stack:m});let G=typeof t.seedsCount!="number"?parseInt(t.seedsCount||0):t.seedsCount||0;const x=$==null?void 0:$.eventType,z=t.matchUpType||x,j=t.drawId&&((r=$==null?void 0:$.drawDefinitions)==null?void 0:r.find(X=>X.drawId===t.drawId));let{tieFormat:V,matchUpFormat:L}=t;if(V){const X=ur({tieFormat:V});if(X.error)return W({result:X,stack:m})}if(z===He&&x===He){const X=(o=(n=j==null?void 0:j.structures)==null?void 0:n.find(({stage:ie})=>ie===de))==null?void 0:o.tieFormat;V=V||X||E&&((i=$==null?void 0:$.tieFormat)==null?void 0:i.tieFormatName)===E&&$.tieFormat||E&&Es({namedFormat:E,hydrateCollections:P,event:$})||($==null?void 0:$.tieFormat)||Es({event:$,hydrateCollections:P}),L=void 0}else L||(V=void 0,$!=null&&$.matchUpFormat||(L="SET3-S:6/TB7"));if(t.drawId&&typeof t.drawId!="string")return W({result:{error:Z},stack:m});j&&g!==j.drawType&&(j.drawType=g);let k=j||$1({drawType:g,drawId:t.drawId});if((L||V)&&!(L&&($==null?void 0:$.matchUpFormat)===L||($==null?void 0:$.tieFormat)&&V&&JSON.stringify($.tieFormat)===JSON.stringify(V))){if(V){const ie=vV(V);if(ie.error)return W({result:ie,stack:m});k.tieFormat=ie.tieFormat||V}else{let ie=Ju({tournamentRecord:S,drawDefinition:k,matchUpFormat:L,tieFormat:V,event:$});if(ie.error)return{error:ie.error,info:"matchUpFormat or tieFormat error"}}z&&(k.matchUpType=z)}const{appliedPolicies:H}=at({tournamentRecord:S,event:$});if(O){if(typeof O!="object")return W({result:{info:"policyDefinitions must be an object",error:Z}});{const X={};for(const ie of Object.keys(O))JSON.stringify(H[ie])!==JSON.stringify(O[ie])&&(X[ie]=O[ie]);Object.keys(X).length&&(zm({drawDefinition:k,policyDefinitions:X}),Object.assign(H,X))}}H[qs]||(zm({drawDefinition:k,policyDefinitions:iv}),Object.assign(H,iv));let Q=(a=(s=j==null?void 0:j.structures)==null?void 0:s.find(X=>X.stage===de&&X.stageSequence===1))==null?void 0:a.structureId;const K=b||C,Y=[];let J,te=[];const ne=t.qualifyingPlaceholder&&!((c=t.qualifyingProfiles)!=null&&c.length)&&!j,oe=j==null?void 0:j.structures.filter(X=>X.stage===Ie),se=(oe==null?void 0:oe.length)===1&&!((l=oe[0].matchUps)!=null&&l.length)&&oe[0].structureId;if(se){const X=t.qualifyingProfiles,ie=(X==null?void 0:X.length)&&Xw({idPrefix:t.idPrefix,isMock:t.isMock,uuids:t.uuids,qualifyingProfiles:X,appliedPolicies:H,matchUpType:z});if(ie!=null&&ie.error)return ie;k.structures=k.structures.filter(({structureId:Pe})=>Pe!==se),k.links=k.links.filter(({source:Pe})=>Pe.structureId!==se);const{qualifiersCount:fe,qualifyingDrawPositionsCount:$e,qualifyingDetails:re}=ie;$e&&(ie!=null&&ie.structures&&k.structures.push(...ie.structures),ie!=null&&ie.links&&k.links.push(...ie.links));const ae=k.structures.find(({stage:Pe,stageSequence:Ae})=>Pe===de&&Ae===1),{qualifiersCount:me}=Ni({stageSequence:1,drawDefinition:k,structureId:Q,stage:de}),Se=Math.max(fe||0,me||0);let ce=$m({qualifiersCount:Se,drawDefinition:k,stage:de});if(ce.error||(ce=ul({drawSize:$e,stage:Ie,drawDefinition:k}),ce.error))return ce;for(const Pe of(b||[]).filter(({entryStage:Ae})=>Ae===Ie)){const Ae=Ns(Xo({},Pe),{entryStage:Pe.entryStage||de,drawDefinition:k});Gm(Ae)}for(const Pe of re||[]){const{finalQualifyingRoundNumber:Ae,finalQualifyingStructureId:ye,roundTarget:Ue,finishingPositions:be,linkType:ge}=Pe,Ne=ae&&((u=Ua({targetStructureId:ae.structureId,sourceStructureId:ye,sourceRoundNumber:Ae,finishingPositions:be,targetEntryRound:Ue,linkType:ge}))==null?void 0:u.link);if(Ne!=null&&Ne.error)return Ne;Ne&&k.links.push(Ne)}J={drawDefinition:k}}else{if(J=Nm(Ns(Xo({},t),{modifyOriginal:!1,tournamentRecord:S,appliedPolicies:H,drawDefinition:k,matchUpFormat:L,matchUpType:z,tieFormat:V,drawSize:R})),J.error)return W({result:J,stack:m});k=J.drawDefinition;for(const ie of K){if(b&&ie.entryStage&&ie.entryStage!==de)continue;const fe=Ns(Xo({},ie),{entryStage:ie.entryStage||de,ignoreStageSpace:y,drawDefinition:k}),$e=Gm(fe);if(b&&$e.error)return W({result:$e,stack:m})}g===hi&&(G=0);const X=a2(Ns(Xo(Xo({},J),t),{qualifyingOnly:!R||T,appliedPolicies:H,drawDefinition:k,participants:U,stage:de,seedsCount:G,placeByes:w,drawSize:R,entries:K}));if(X.error&&!X.conflicts)return X;(d=X.positioningReport)!=null&&d.length&&Y.push({[de]:X.positioningReport}),Q=X.structureId,te=X.conflicts}const ve=[];if(t.qualifyingProfiles){const X=(re,ae)=>re.stageSequence-ae.stageSequence,ie=(re,ae)=>re.roundTarget-ae.roundTarget,fe=[];let $e=1;for(const re of t.qualifyingProfiles.sort(ie)){if(!Array.isArray(re.structureProfiles))return W({result:{error:Oe},info:zt("structureProfiles")});$e=re.roundTarget||$e;const ae=((p=re.structureProfiles)==null?void 0:p.sort(X))||[];let me=1;for(const Se of ae){const{qualifyingRoundNumber:ce,qualifyingPositions:Pe,seededParticipants:Ae,seedingScaleName:ye,seedsCount:Ue=0,seedingProfile:be,seedByRanking:ge,placeByes:Ne,drawSize:De}=Se,he=a2(Ns(Xo(Xo({},J),t),{stageSequence:me,qualifyingRoundNumber:ce,preparedStructureIds:fe,qualifyingPositions:Pe,seededParticipants:Ae,stage:Ie,seedingScaleName:ye,appliedPolicies:H,drawDefinition:k,qualifyingOnly:T,seedingProfile:be,seedByRanking:ge,participants:U,roundTarget:$e,seedsCount:Ue,placeByes:Ne,drawSize:De,entries:K}));if(he.error)return he;he.structureId&&fe.push(he.structureId),me+=1,(v=he.conflicts)!=null&&v.length&&ve.push(...he.conflicts),(f=he.positioningReport)!=null&&f.length&&Y.push({[Ie]:he.positioningReport})}$e+=1}}else if(ne){const X=kt({structureName:Ie,stage:Ie}),{link:ie}=Ua({sourceStructureId:X.structureId,targetStructureId:Q,sourceRoundNumber:0,linkType:ho});k.structures.push(X),k.links.push(ie)}return k.drawName=t.drawName||g,typeof I=="object"&&phe(Ns(Xo({},I),{tournamentRecord:S,appliedPolicies:H,drawDefinition:k,matchUpType:z})),N&&Jc({tournamentRecord:S,drawDefinition:k,event:$}),Ns(Xo({existingDrawDefinition:!!j,qualifyingConflicts:ve,positioningReports:Y,drawDefinition:k,structureId:Q},B),{conflicts:te})}function _he(t){return GN(t)}function Ihe(t){return t.tournamentRecord?Qn(t):{error:ee}}function Phe(t){return t.tournamentRecord?XA(t):{error:ee}}function yhe(t){return t.tournamentRecord?e1(t):{error:ee}}const She={generateQualifyingStructure:ihe,attachQualifyingStructure:she,attachPlayoffStructures:Fge,attachStructures:Eg,addQualifyingStructure:ahe,renameStructures:_he,disableTieAutoCalc:Phe,enableTieAutoCalc:yhe,modifyCollectionDefinition:Xm,orderCollectionDefinitions:j1,removeCollectionDefinition:Jm,addCollectionDefinition:eg,removeCollectionGroup:nU,addCollectionGroup:sU,modifyTieFormat:lU,resetScorecard:Zge,resetTieFormat:a1,addEvent:np,deleteEvents:Pfe,setEventDates:Bge,setEventStartDate:QD,setEventEndDate:JD,removeSeededParticipant:qge,removeScaleValues:sD,checkValidEntries:bM,addDrawEntries:gA,removeSeeding:Kve,autoSeeding:Qve,getAvailablePlayoffRounds:WM,getAvailablePlayoffProfiles:WM,deleteDrawDefinitions:Ig,addPlayoffStructures:wve,addDrawDefinition:Jc,removeStructure:qN,modifyDrawName:_ge,generateAndPopulatePlayoffStructures:Mm,generateSeedingScaleItems:nD,setSubOrder:GA,addEventEntries:Qo,promoteAlternate:sve,promoteAlternates:kM,destroyPairEntry:RA,destroyPairEntries:$oe,setEntryPosition:rD,setEntryPositions:Lve,addEventEntryPairs:ife,removeEventEntries:Fd,removeDrawEntries:Eve,modifyEventEntries:Oge,modifyEntriesStatus:km,modifySeedAssignment:$ve,modifyPairAssignment:yve,resetVoluntaryConsolationStructure:tme,deleteFlightProfileAndFlightDraws:sme,deleteFlightAndFlightDraw:Sme,generateFlightProfile:Dme,refreshEventDrawOrder:ID,attachFlightProfile:Og,resetDrawDefinition:zme,pruneDrawDefinition:rge,updateDrawIdsOrder:gD,getFlightProfile:It,getScaledEntries:hl,generateLineUps:RD,addFlight:Tg,generateAdHocMatchUps:Ome,deleteAdHocMatchUps:Gme,addAdHocMatchUps:bme,drawMatic:bg,setOrderOfFinish:nge,setDelegatedOutcome:xve,removeDelegatedOutcome:Vve,addVoluntaryConsolationStructure:Om,addVoluntaryConsolationStage:xme,generateVoluntaryConsolation:Vme,attachConsolationStructures:Rge,bulkMatchUpStatusUpdate:D0,updateTieMatchUpScore:Ihe,setMatchUpStatus:Qc,setMatchUpFormat:Dve,assignDrawPosition:Jpe,assignSeedPositions:mfe,assignDrawPositionBye:mve,substituteParticipant:kme,swapDrawPositionAssignments:fve,assignMatchUpSideParticipant:dpe,removeDrawPositionAssignment:Vd,alternateDrawPositionAssignment:pve,withdrawParticipantAtDrawPosition:ave,setDrawParticipantRepresentativeIds:ope,getDrawParticipantRepresentativeIds:ipe,luckyLoserDrawPositionAssignment:lve,qualifierDrawPositionAssignment:dve,setPositionAssignments:vve,automatedPositioning:ere,automatedPlayoffPositioning:Cd,checkInParticipant:Zfe,checkOutParticipant:Xfe,toggleParticipantCheckInState:eE,addDrawDefinitionTimeItem:aC,generateDrawDefinition:$g,generateDrawStructuresAndLinks:ehe,generateDrawTypeAndModifyDrawDefinition:Xge,applyLineUps:Jge,assignTieMatchUpParticipantId:yg,removeTieMatchUpParticipantId:qpe,replaceTieMatchUpParticipantId:sM,updateTeamLineUp:Xd,validateLineUp:XC,getTeamLineUp:yc};function Ohe({entries:t=[],entryStatus:e,stage:r}){return Math.max(...t.filter(n=>(!r||r===n.entryStage)&&(!e||n.entryStatus===e)&&!isNaN(n.entryPosition)).map(({entryPosition:n})=>parseInt(n||0)),0)}var bhe=Object.defineProperty,The=Object.defineProperties,Ehe=Object.getOwnPropertyDescriptors,u2=Object.getOwnPropertySymbols,whe=Object.prototype.hasOwnProperty,$he=Object.prototype.propertyIsEnumerable,d2=(t,e,r)=>e in t?bhe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Nhe=(t,e)=>{for(var r in e||(e={}))whe.call(e,r)&&d2(t,r,e[r]);if(u2)for(var r of u2(e))$he.call(e,r)&&d2(t,r,e[r]);return t},Ahe=(t,e)=>The(t,Ehe(e));function Uhe({tournamentRecord:t,ascending:e=!0,drawDefinition:r,excludeMargin:n,exclusionRule:o,valueAccessor:i,zoneDoubling:s,matchUpType:a,zoneMargin:c,scaleName:l,matchUps:u,eventId:d,drawId:p,event:v}){var f,m,g,h;if(!t&&!u)return{error:ee};if(a&&![pt,it].includes(a))return{error:Z,info:{matchUpType:a}};if(!Array.isArray(u)&&u)return{error:Z,context:{matchUps:u}};const _={withScaleValues:!0,withCompetitiveness:!0},I={matchUpTypes:a?[a]:[pt,it]},P=t==null?void 0:t.participants;(f=u==null?void 0:u[0])!=null&&f.hasContext?p?u=u.filter($=>$.drawId===p):d&&(u=u.filter($=>$.eventId===d)):u===void 0&&(u=p&&!r&&[]||!p&&d&&!v&&[]||p&&((m=Dr({inContext:!0,drawDefinition:r,contextFilters:I,contextProfile:_,participants:P}))==null?void 0:m.matchUps)||!p&&d&&((g=Oi({inContext:!0,contextFilters:I,contextProfile:_,participants:P,event:v}))==null?void 0:g.matchUps)||((h=Bt({tournamentRecord:t,contextFilters:I,contextProfile:_}))==null?void 0:h.matchUps)||[]),a&&(u=u.filter($=>$.matchUpType===a));const O=u.filter(({winningSide:$,score:U,sides:A,matchUpStatus:M})=>![er,Be,Ge,Gs,yr].includes(M)&&Dt({score:U})&&(A==null?void 0:A.length)===2&&$),y=Mhe({matchUps:O,excludeMargin:n,exclusionRule:o,valueAccessor:i,ascending:e,scaleName:l}),S=!s||a===pt?c:c*2,T=c&&O.map(({competitiveness:$,matchUpType:U,score:A,sides:M})=>{const C=p2({valueAccessor:i,matchUpType:U,scaleName:l,score:A,sides:M}),D=Math.abs(C[0].value-C[1].value);return{competitiveness:$,score:A,valuesGap:D}}).filter(({valuesGap:$})=>$<=S),E=(T==null?void 0:T.length)&&Che({zoneData:T}),b=E&&[].concat(Object.values(E)).flat().length,N=b&&Object.assign({},...Object.keys(E).map($=>({[$]:Math.round(1e4*E[$].length/b)/100}))),w=O.length-((T==null?void 0:T.length)||0);return Ahe(Nhe({},B),{relevantMatchUps:O,zoneDistribution:N,zoneData:T,accuracy:y,nonZone:w})}function Che({zoneData:t}){const e={[tf]:[],[ic]:[],[sc]:[]};for(const r of t){const{competitiveness:n,score:o,valuesGap:i}=r;e[n]&&e[n].push({score:o,valuesGap:i})}return e}function p2({exclusionRule:t,valueAccessor:e,matchUpType:r,scaleName:n,sides:o}){const i=t==null?void 0:t.range.sort(),s=a=>{const c=a==null?void 0:a[t==null?void 0:t.valueAccessor];return{exclude:t&&c>=i[0]&&c<=i[1],exclusionValue:c}};return o.sort((a,c)=>a.sideNumber-c.sideNumber).map(({participant:a})=>{const c=[],l=a==null?void 0:a.individualParticipants;if(l!=null&&l.length){let u=[],d=0;for(const p of l){const{scaleValue:v,value:f}=f2({valueAccessor:e,participant:p,matchUpType:r,scaleName:n}),{exclude:m,exclusionValue:g}=s(v);m&&c.push(g),u.push(v),f&&!isNaN(d)?d+=f:d=void 0}return{participantName:a.participantName,exclusionValues:c,scaleValues:u,value:d}}else if(a){const{scaleValue:u,value:d}=f2({valueAccessor:e,matchUpType:r,participant:a,scaleName:n}),{exclude:p,exclusionValue:v}=s(u);return p&&c.push(v),{participantName:a.participantName,exclusionValues:c,scaleValue:u,value:d}}else return{}})}function f2({participant:t,valueAccessor:e,matchUpType:r,scaleName:n}){var o,i,s,a,c;const l=(i=(o=t==null?void 0:t.rankings)==null?void 0:o[r])==null?void 0:i.find(v=>v.scaleName===n),d=(c=((a=(s=t==null?void 0:t.ratings)==null?void 0:s[r])==null?void 0:a.find(v=>v.scaleName===n))||l)==null?void 0:c.scaleValue,p=e?d==null?void 0:d[e]:d;return{scaleValue:d,value:p}}function Mhe({excludeMargin:t,exclusionRule:e,valueAccessor:r,ascending:n,scaleName:o,matchUps:i}){const s={affirmative:[],negative:[],excluded:[]};for(const l of i){const{matchUpType:u,sides:d,score:p,winningSide:v}=l;if(!v)continue;if(e&&(!e.valueAccessor||!e.range))return{info:"exclusionRule requires valueAccessor and range",error:Oe};const f=v-1,m=p2({exclusionRule:e,valueAccessor:r,matchUpType:u,scaleName:o,score:p,sides:d});if(e){const O=m.map(({exclusionValues:y})=>y).flat();if(O.length){s.excluded.push({scoreString:p==null?void 0:p.scoreStringSide1,exclusionValues:O,winningSide:v,sideValues:m});continue}}if(m.filter(O=>![void 0,"",null].includes(O.value)).length<2){s.excluded.push({scoreString:p==null?void 0:p.scoreStringSide1,missingValues:!0,winningSide:v,sideValues:m});continue}const g=m[f].value-m[1-f].value,h=parseFloat(t),_=h&&Math.abs(g)<h;if(_){s.excluded.push({scoreString:p==null?void 0:p.scoreStringSide1,excludeMargin:t,winningSide:v,excludeGap:_,sideValues:m,valuesGap:g});continue}const I=n?g*-1:g,P=v===1?p==null?void 0:p.scoreStringSide1:p==null?void 0:p.scoreStringSide2;I>0?s.affirmative.push({winningScoreString:P,winningSide:v,sideValues:m,valuesGap:g,score:p}):s.negative.push({winningScoreString:P,winningSide:v,sideValues:m,valuesGap:g,score:p})}const a=s.affirmative.length+s.negative.length,c=a&&s.affirmative.length/a*100;return s.percent=c?Math.round(100*c)/100:0,s}function Dhe({tournamentRecord:t,drawDefinition:e,structureId:r,matchUpId:n,drawId:o,event:i}){var s;if(!t)return{error:ee};if(!o&&!i&&!r&&!n)return W({result:{error:Oe},stack:"getMatchUpFormat"});const a=il({tournamentRecord:t,drawDefinition:e,matchUpId:n,drawId:o,event:i});if(n&&(a!=null&&a.error))return a;!e&&(a!=null&&a.drawDefinition)&&(e=a==null?void 0:a.drawDefinition);let c=a==null?void 0:a.structure;if(!c&&r&&!n){if(!e)return{error:wr};const v=Te({drawDefinition:e,structureId:r});if(v.error)return v;c=v.structure}const l=c==null?void 0:c.matchUpFormat,u=e==null?void 0:e.matchUpFormat,d=i==null?void 0:i.matchUpFormat,p=((s=a==null?void 0:a.matchUp)==null?void 0:s.matchUpFormat)||l||u||d;return{structureDefaultMatchUpFormat:l,eventDefaultMatchUpFormat:d,drawDefaultMatchUpFormat:u,matchUpFormat:p}}var jhe=Object.defineProperty,v2=Object.getOwnPropertySymbols,Rhe=Object.prototype.hasOwnProperty,Fhe=Object.prototype.propertyIsEnumerable,m2=(t,e,r)=>e in t?jhe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lhe=(t,e)=>{for(var r in e||(e={}))Rhe.call(e,r)&&m2(t,r,e[r]);if(v2)for(var r of v2(e))Fhe.call(e,r)&&m2(t,r,e[r]);return t};function Vhe({competitiveProfile:t,tournamentRecord:e,matchUps:r}){if(!Array.isArray(r))return{error:Ao};const n=!t&&qi({policyType:Mo,tournamentRecord:e}).policy,o=t||(n==null?void 0:n.competitiveProfile)||rf[Mo].competitiveProfile,i=r.filter(({winningSide:p})=>p),s=i.map(L_),a=(p,v)=>{const f=F_(v,o);return p[f]+=1,p},c=V_(s).reduce((p,v)=>a(p,v),{[tf]:0,[ic]:0,[sc]:0,[D_]:0}),l=Object.keys(c).reduce((p,v)=>(c[v]||0)+p,0),u=Object.keys(c).map(p=>({[p]:(c[p]/l).toFixed(4)*100})),d=i.filter(({matchUpStatus:p})=>p===j_);return u.push({[j_]:(d/l).toFixed(4)*100}),Lhe({competitiveBands:Object.assign({},...u)},B)}function xhe({tournamentRecord:t,outcomes:e}){var r;if(!t)return{error:ee};if(!(e!=null&&e.length))return{error:Oe,info:"Missing outcomes"};const n=e.reduce((a,c)=>{const{drawId:l,eventId:u}=c;return u&&l&&(a[u]?a[u].includes(l)||a[u].push(l):a[u]=[l]),a},{}),o=Object.keys(n);return{publishedEventIds:((r=t.events)==null?void 0:r.filter(a=>o.includes(a.eventId))).filter(a=>{const{timeItem:c}=So({itemType:`${Ar}.${Ur}`,event:a}),l=c==null?void 0:c.itemValue,{eventId:u}=a;return n[u].filter(p=>{var v,f;return(f=(v=l==null?void 0:l[$n])==null?void 0:v.drawIds)==null?void 0:f.includes(p)}).length}).map(a=>a.eventId),eventIdPublishedDrawIdsMap:n}}function Bhe({tournamentRecord:t,participantId:e}){if(!t)return{error:ee};if(!e)return{error:yt};const{participant:r}=Ro({tournamentRecord:t,participantId:e});if(!r)return{error:wt};const{timeItem:n}=fn({itemType:_c,element:r});return n&&n.itemValue===Ic&&Ic}function khe({tournamentRecord:t,event:e}){var r,n;if(!t)return{error:ee};if(!e)return{error:Le};const o=e.entries||[],i=t.participants||[],s=((r=e.category)==null?void 0:r.categoryName)||((n=e.category)==null?void 0:n.ageCategoryCode),{eventType:a}=e,c=o.map(f=>f.participantId),l=i.filter(f=>c.includes(f.participantId));let u,d,p;return{entryScaleAttributes:l.map(f=>{var m,g,h,_,I,P;const{participantId:O,participantName:y,name:S}=f;let T={scaleType:nP,eventType:a,scaleName:s};const E=(g=(m=ro({participant:f,scaleAttributes:T}))==null?void 0:m.scaleItem)==null?void 0:g.scaleValue;T={scaleType:rk,eventType:a,scaleName:s};const b=(_=(h=ro({participant:f,scaleAttributes:T}))==null?void 0:h.scaleItem)==null?void 0:_.scaleValue;T={scaleType:tk,eventType:a,scaleName:s};const N=(P=(I=ro({participant:f,scaleAttributes:T}))==null?void 0:I.scaleItem)==null?void 0:P.scaleValue;return u=!!(u||E),d=!!(d||b),p=!!(p||N),{participantId:O,participantName:y||S,seed:E,ranking:b,rating:N}}),hasSeededParticipants:u,hasRankedParticipants:d,hasRatedParticipants:p}}function Ghe(t){return pr(t)}var Whe=Object.defineProperty,g2=Object.getOwnPropertySymbols,Hhe=Object.prototype.hasOwnProperty,qhe=Object.prototype.propertyIsEnumerable,h2=(t,e,r)=>e in t?Whe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Yhe=(t,e)=>{for(var r in e||(e={}))Hhe.call(e,r)&&h2(t,r,e[r]);if(g2)for(var r of g2(e))qhe.call(e,r)&&h2(t,r,e[r]);return t};function zhe(t){const{tournamentRecord:e}=t;if(!e)return{error:ee};const{tournamentParticipants:r}=Qt({tournamentRecord:e,inContext:!0});return y1(Yhe({tournamentParticipants:r},t))}function Khe({tournamentRecord:t,drawDefinition:e}){return t?{drawDefinition:ue(e)}:{error:ee}}const Qhe={allTournamentMatchUps:Bt,tournamentMatchUps:av,allEventMatchUps:Oi,getRoundMatchUps:Ghe,allDrawMatchUps:Dr,eventMatchUps:fS,drawMatchUps:mW,credits:_d,getTournamentStructures:v6,getEventStructures:xO,getEvents:Rx,getEvent:jx,findDrawDefinitionExtension:Kl,findParticipantExtension:Ix,findTournamentExtension:Sr,findEventExtension:mo,findExtension:Or,getTieFormat:Q1,getMatchUpFormat:Dhe,getDrawDefinition:Khe,getEventProperties:khe,getPositionAssignments:_g,isValidMatchUpFormat:xr,getMaxEntryPosition:Ohe,getMatchUpCompetitiveness:k_,findVenue:Lo,getCourts:xB,getVenuesAndCourts:_f,findCourt:VB,getEventTimeItem:So,getTournamentTimeItem:Eu,getParticipantTimeItem:z4,getDrawDefinitionTimeItem:Y4,bulkUpdatePublishedEventIds:xhe,matchUpActions:WE,positionActions:zhe,findMatchUp:L8,participantScheduledMatchUps:lb,getPredictiveAccuracy:Uhe,getMatchUpsStats:Vhe,participantScaleItem:ro,getParticipantScaleItem:ip,getParticipantSignInStatus:Bhe,getPolicyDefinitions:Hi,getMatchUpScheduleDetails:bf},Jhe={addVenue:fc,deleteVenue:hm,deleteVenues:yJ,modifyVenue:Vw,enableCourts:iw,enableVenues:uw,disableCourts:KE,disableVenues:ew,addCourt:Pm,addCourts:ym,deleteCourt:yw,modifyCourt:Im,modifyCourtAvailability:Nw,findVenue:MB};var Zhe=Object.defineProperty,Xhe=Object.defineProperties,e_e=Object.getOwnPropertyDescriptors,_2=Object.getOwnPropertySymbols,t_e=Object.prototype.hasOwnProperty,r_e=Object.prototype.propertyIsEnumerable,I2=(t,e,r)=>e in t?Zhe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ng=(t,e)=>{for(var r in e||(e={}))t_e.call(e,r)&&I2(t,r,e[r]);if(_2)for(var r of _2(e))r_e.call(e,r)&&I2(t,r,e[r]);return t},Ag=(t,e)=>Xhe(t,e_e(e));(function(){const t={getState:({convertExtensions:s,removeExtensions:a}={})=>mce({convertExtensions:s,removeExtensions:a,tournamentId:yn()}),newTournamentRecord:(s={})=>{const a=lg(s);return a.error?a:(e_(a),tc(a.tournamentId),Object.assign({tournamentId:a.tournamentId},B))},setTournamentId:s=>tc(s)};t.version=()=>so(),t.reset=()=>{const s=xp(yn());return e(s)},t.setState=(s,a,c)=>{Fi(a,c);const l=ug(s,a);return e(l)},t.devContext=s=>(xs(s),t),t.getDevContext=s=>Ft(s),t.executionQueue=(s,a)=>i(s,a);function e(s){return s!=null&&s.error?(t.error=s.error,t.success=!1):(t.error=void 0,t.success=!0),t}return o([Qhe,She,Jhe,Vde,npe,Fde,Nue,$de,oue]),t;function r(s,a,c,l){var u,d;delete t.success,delete t.error;const p=Date.now(),v=gce(s,c),f=a(Ag(Ng({},v),{tournamentRecord:s})),m=Date.now()-p,g=Ft(),h={method:l},_=typeof g.result=="object"&&g.result.error;return![void 0,!1].includes(g.perf)&&(isNaN(g.perf)||m>g.perf)&&(h.elapsed=m),(_||g.params&&!Array.isArray(g.params)||Array.isArray(g.params)&&((u=g.params)!=null&&u.includes(l)))&&(h.params=c),(_||!_&&g.result&&!Array.isArray(g.result)||Array.isArray(g.result)&&((d=g.result)!=null&&d.includes(l)))&&(h.result=f),Object.keys(h).length>1&&console.log("te:",h),g.makeDeepCopy&&(f.deepCopyIterations=LL()),f}function n(s,a,c){const l=yn(),u=(a==null?void 0:a.sandBoxRecord)||(a==null?void 0:a.sandboxRecord)||(a==null?void 0:a.sandboxTournament)||Xa(l),d=(a==null?void 0:a.rollbackOnError)&&ue(u,!1,!0),p=r(u,s,a,c);p!=null&&p.error&&d&&ug(d);const v=(p==null?void 0:p.success)&&(a==null?void 0:a.delayNotify)!==!0&&(a==null?void 0:a.doNotNotify)!==!0,f=Za(),m=Date.now();return f&&(Fu({tournamentRecord:u,value:{version:so(),timeStamp:m}}),p.modificationsApplied=!0),v&&bi({directives:[{method:s,params:a}],mutationStatus:f,tournamentId:l,timeStamp:m}),(v||!(p!=null&&p.success)||a!=null&&a.doNotNotify)&&ii(),p}function o(s){s.forEach(a=>{Object.keys(a).forEach(c=>{t[c]=l=>{if(Ft())return n(a[c],l,c);try{return n(a[c],l,c)}catch(u){const d=yn(),p=u.toString();console.log("ERROR",{params:JSON.stringify(l),tournamentId:d,methodName:c,error:p})}}})})}function i(s,a){var c;if(!Array.isArray(s))return{error:Z};const l=yn(),u=Xa(l),d=a&&ue(u,!1,!0),p=[];for(const g of s){if(typeof g!="object")return{error:Z};const{method:h,params:_}=g;if(!t[h]){const P={error:qh,methodName:h},O=Ft();return(O.result&&!Array.isArray(O.result)||Array.isArray(O.result)&&((c=O.result)!=null&&c.includes(h)))&&console.log("te:",P),P}const I=r(u,t[h],_,h);if(I!=null&&I.error)return d&&ug(d),Ag(Ng({},I),{rolledBack:!!d});p.push(Ag(Ng({},I),{methodName:h}))}const v=Za(),f=Date.now();return v&&Fu({tournamentRecord:u,value:{version:so(),timeStamp:f}}),bi({directives:s,mutationStatus:v,timeStamp:f,tournamentId:l}),ii(),{success:p.every(g=>g.success),results:p}}})();var n_e=Object.defineProperty,P2=Object.getOwnPropertySymbols,o_e=Object.prototype.hasOwnProperty,i_e=Object.prototype.propertyIsEnumerable,y2=(t,e,r)=>e in t?n_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s_e=(t,e)=>{for(var r in e||(e={}))o_e.call(e,r)&&y2(t,r,e[r]);if(P2)for(var r of P2(e))i_e.call(e,r)&&y2(t,r,e[r]);return t};function S2(t,e){var r;if(typeof t!="object")return{error:xn};const n=((r=t.unifiedTournamentId)==null?void 0:r.tournamentId)||t.tournamentId;if(!n)return{error:ao};const o=e!==!1?ue(t):t;return ec({[n]:o}),tc(n),o}function a_e({convertExtensions:t,removeExtensions:e,tournamentId:r}={}){if(typeof r!="string")return{};const n=Xa(r);return{tournamentRecord:ue(n,t,!1,e)}}function c_e(t,e){return e!=null&&e.someParam&&(e=s_e({},e)),e}function O2(t,e){return t&&e&&Array.isArray(e)&&e[t-1]||typeof e=="object"&&e[t]}function l_e({participation:t={},awardProfiles:e,startDate:r,eventType:n,drawSize:o,drawType:i,category:s,endDate:a,level:c}){const{participationOrder:l,flightNumber:u,rankingStage:d}=t,p=f=>!r&&!a||!f.dateRanges?!0:f.dateRanges.some(m=>{const g=!r||!m.startDate||new Date(r)>new Date(m.startDate),h=!a||!m.endDate||new Date(a)<=new Date(m.endDate);return g&&h});return{awardProfile:e.find(f=>{var m,g,h,_,I,P,O,y,S,T;return p(f)&&(!f.maxFlightNumber||u<=f.maxFlightNumber)&&(!((m=f.drawTypes)!=null&&m.length)||((g=f.drawTypes)==null?void 0:g.includes(i)))&&(!((h=f.drawSizes)!=null&&h.length)||f.drawSizes.includes(o))&&(!((_=f.stages)!=null&&_.length)||f.stages.includes(d))&&(!((I=f.levels)!=null&&I.length)||f.levels.includes(c))&&(!f.maxDrawSize||o<=f.maxDrawSize)&&(!f.drawSize||f.drawSize===o)&&(!f.maxLevel||c<=f.maxLevel)&&(!u||!((O=(P=f.flights)==null?void 0:P.flightNumbers)!=null&&O.length)||f.flights.flightNumbers.includes(u))&&(!f.participationOrder||f.participationOrder===l)&&(!((y=f.category)!=null&&y.ageCategoryCodes)||f.category.ageCategoryCodes.includes(s==null?void 0:s.ageCategoryCode))&&(!((S=f.eventTypes)!=null&&S.length)||((T=f.eventTypes)==null?void 0:T.includes(n)))})}}function b2({participantWon:t,flightNumber:e,valueObj:r,drawSize:n,flights:o,level:i}){var s,a;const c=(g,h)=>{if(g){if(Array.isArray(h)){const _=h.find(I=>I.flight===g||I.f===g);return _.value||_.v}if(typeof h=="object"){const _=h.flights||h.f;if(Array.isArray(_))return _[g-1]}}},l=(g,h)=>{const _=(g==null?void 0:g.value)||(g==null?void 0:g.v)||(ut(g)?g:0),I=O2(i,g==null?void 0:g.level);return{value:c(h,I)||ut(I)&&I||_}};let u=0,d,p,v,f;const m=t&&"won"||t===!1&&"lost"||void 0;if(Array.isArray(r)){let g=r.find(I=>{var P;return I.drawSize===n||((P=I.drawSizes)==null?void 0:P.includes(n))}),h=r.find(I=>I.drawSize&&I.threshold&&n>I.drawSize),_=r.find(I=>{var P;return!I.drawSize&&!((P=I.drawSizes)!=null&&P.length)});m!==void 0&&(g=g==null?void 0:g[m],h=h==null?void 0:h[m],_=_==null?void 0:_[m]),p=l(g,e).value,v=l(h,e).value,f=l(_,e).value,u=p||v||f,d=p&&g.requireWin||v&&h.requireWin||(_==null?void 0:_.requireWin)}else if(typeof r=="object"){let g=(s=r==null?void 0:r.drawSizes)==null?void 0:s[n],h=r;m!==void 0&&(g=g==null?void 0:g[m],h=h==null?void 0:h[m]),p=l(g,e).value,f=l(h,e).value,u=p||f,d=p?g.requireWin:h==null?void 0:h.requireWin}else ut(r)&&m===void 0&&(u=r);return(a=o==null?void 0:o.pct)!=null&&a[e]&&(u=Math.round(u*o.pct[e])),{awardPoints:u,requireWin:d}}var u_e=Object.defineProperty,T2=Object.getOwnPropertySymbols,d_e=Object.prototype.hasOwnProperty,p_e=Object.prototype.propertyIsEnumerable,E2=(t,e,r)=>e in t?u_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,f_e=(t,e)=>{for(var r in e||(e={}))d_e.call(e,r)&&E2(t,r,e[r]);if(T2)for(var r of T2(e))p_e.call(e,r)&&E2(t,r,e[r]);return t};function v_e({participantFilters:t,policyDefinitions:e,tournamentRecord:r,saveRankings:n,level:o}){var i;if(!r)return{error:ee};const{policyDefinitions:s}=Hi({policyTypes:[Kp],tournamentRecord:r}),a=(e==null?void 0:e[Kp])||(s==null?void 0:s[Kp]);if(!a)return{error:Nl};const c=a.awardProfiles;let l=a.requireWinFirstRound,u=a.requireWinForPoints;const{participants:d,derivedEventInfo:p,derivedDrawInfo:v,mappedMatchUps:f}=ys({withRankingProfile:!0,participantFilters:t,tournamentRecord:r}),m=d.filter(I=>{var P;return(P=I.draws)==null?void 0:P.length}),g={},h={},_={};for(const I of m){const{participantType:P,participantId:O,person:y,draws:S}=I;for(const T of S){const{drawId:E,structureParticipation:b,eventId:N}=T,w=p[N],$=v[E],U=$==null?void 0:$.drawType,{category:A,eventType:M}=w||{},C=T.startDate||w.startDate||r.startDate,D=T.endDate||w.endDate||r.endDate;if(M===Nn&&O!==An)continue;let F;if(c){let R=u,G=0,x=0,z=0,j;for(const V of b){const{finishingPositionRange:L,participationOrder:q,participantWon:k,flightNumber:H,rankingStage:Q,winCount:K}=V;G+=K||0;const Y=$==null?void 0:$.drawSize,{awardProfile:J}=l_e({awardProfiles:c,participation:V,eventType:M,startDate:C,category:A,drawSize:Y,drawType:U,endDate:D,level:o});if(J){if(!Y)continue;const te=Array.isArray(L)&&Math.max(...L),ne=Ve(L||[]).join("-"),oe=te&&Q!==Ie&&(L==null?void 0:L.includes(Y));J.requireWinForPoints!==void 0&&(R=J.requireWinForPoints),J.requireWinFirstRound!==void 0&&(l=J.requireWinFirstRound);const{finishingPositionPoints:se={},finishingPositionRanges:ve,finishingRound:X,pointsPerWin:ie,flights:fe}=J,$e=Array.isArray(J.perWinPoints)?(i=J.perWinPoints)==null?void 0:i.find(ce=>{var Pe;return(Pe=ce.participationOrders)==null?void 0:Pe.includes(q)}):J.perWinPoints,re=se.participationOrders;let ae=0,me;if((!re||re.includes(q))&&ve){const ce=ve[te];ce&&({awardPoints:ae,requireWin:me}=b2({flightNumber:H,valueObj:ce,drawSize:Y,flights:fe,level:o}))}if(!ae&&X&&q===1){const ce=X[te];ce&&({awardPoints:ae,requireWin:me}=b2({participantWon:k,flightNumber:H,valueObj:ce,drawSize:Y,flights:fe,level:o}))}if(oe&&l!==void 0&&(R=l),me!==void 0&&(R=me),ae>x&&(!R||K)&&(x=ae,j=te),!ae&&ie&&K&&(z+=K*ie,j=ne),!ae&&K&&$e){const ce=O2(o,$e==null?void 0:$e.level);ce?z+=K*ce:$e.value&&(z+=K*$e.value)}}if(F=x+z,P===An){const te=(I.matchUps||[]).filter(({structureId:ne})=>ne===V.structureId);for(const{matchUpId:ne}of te){const oe=f[ne],se=oe.sides.find(ve=>ve.participantId===O).sideNumber;if(oe.winningSice===se)for(const ve of oe.tieMatchUps)ve.winningSide}}}if(z||x){const V={winCount:G,positionPoints:x,rangeAccessor:j,perWinPoints:z,eventType:M,drawId:E,points:F},L=y==null?void 0:y.personId;L?(g[L]||(g[L]=[]),g[L].push(V)):P===we?(_[O]||(_[O]=[]),_[O].push(V)):P===An&&(h[O]||(h[O]=[]),h[O].push(V))}}}}return n&&tt({element:r,extension:{name:N_,value:{personPoints:g,teamPoints:h,pairPoints:_}}}),f_e({participantsWithOutcomes:m,personPoints:g,pairPoints:_,teamPoints:h},B)}const m_e={getTournamentPoints:v_e},g_e=t=>250/Math.pow(t+5,.4),h_e=()=>1;function __e(t=3,e=2){let r=t/e;return isNaN(r)?xa.kDefault():r}const xa={nSpread:400,diffThreshold:.125,kCalc:g_e,kMultiplier:__e,kDefault:h_e};function w2({ratings:t=Xn,winnerCountables:e=1,loserCountables:r=0,ratingType:n=ps,maxCountables:o,winnerRating:i,loserRating:s,ratingRange:a,countables:c}={}){const l=t==null?void 0:t[n];if(!l)return{error:Oe};a=l.range||a,i=i||l.defaultInitialization,s=s||l.defaultInitialization;const u=a[0]>a[1],d=l.decimalsCount||0,p=u?a.slice().reverse():a,v=(M,C)=>parseFloat(C)>=Math.min(...M)&&parseFloat(C)<=Math.max(...M);(!v(a,i)||!v(a,s))&&(v(a,i)||(i=l.defaultInitialization),v(a,s)||(s=l.defaultInitialization));const f=({value:M,sourceRange:C,targetRange:D})=>(M-C[0])*(D[1]-D[0])/(C[1]-C[0])+D[0],m=f({targetRange:Xn[ps].range,sourceRange:p,value:u?a[0]-i:i}),g=f({targetRange:Xn[ps].range,sourceRange:p,value:u?a[0]-s:s}),h=(M,C)=>1/(1+Math.pow(10,(C-M)/xa.nSpread));let _=h(m,g),I=h(g,m),P=xa.kCalc(e),O=xa.kCalc(r),y=xa.kMultiplier(o,c),S=m+y*P*(1-_),T=g+y*O*(0-I),E=f({sourceRange:Xn[ps].range,value:S,targetRange:p}),b=f({sourceRange:Xn[ps].range,value:T,targetRange:p});const N=u?a[0]-E:E;let w=parseFloat(N).toFixed(d);const $=u?a[0]-b:b;let U=parseFloat($).toFixed(d);const A=Math.max(...a)?Math.abs(i-s)/Math.max(...a):0;return(E>b&&A>xa.diffThreshold||w<0||U<0)&&(w=i,U=s),{newWinnerRating:w,newLoserRating:U}}const I_e=t=>(t==null?void 0:t.reduce((e,r)=>(r.winningSide&&(e[r.winningSide-1]+=1),e),[0,0]))||[0,0];var P_e=Object.defineProperty,y_e=Object.defineProperties,S_e=Object.getOwnPropertyDescriptors,$2=Object.getOwnPropertySymbols,O_e=Object.prototype.hasOwnProperty,b_e=Object.prototype.propertyIsEnumerable,N2=(t,e,r)=>e in t?P_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_l=(t,e)=>{for(var r in e||(e={}))O_e.call(e,r)&&N2(t,r,e[r]);if($2)for(var r of $2(e))b_e.call(e,r)&&N2(t,r,e[r]);return t},Il=(t,e)=>y_e(t,S_e(e));function T_e({tournamentRecord:t,ratingType:e=ps,considerGames:r,matchUpIds:n,asDynamic:o}){var i,s;if(!t)return{error:ee};if(!Array.isArray(n))return{error:Ao};if(typeof e!="string")return{error:Z,ratingType:e};if(!Xn[e])return{error:Z};const a=Xn[e],{accessor:c}=a,l={},{matchUps:u}=Bt({matchUpFilters:{matchUpIds:n,matchUpStatuses:Lt},tournamentRecord:t,inContext:!0});for(const p of u.sort(vs)){const{endDate:v,matchUpFormat:f,matchUpType:m,score:g,sides:h,winningSide:_}=p,I={scaleType:Yi,eventType:m,scaleName:e},P=`${e}.DYNAMIC`,O={scaleType:Yi,eventType:m,scaleName:P},y=Object.assign({},...h.map(({sideNumber:M,participant:C})=>({[M]:[C==null?void 0:C.participantId,...(C==null?void 0:C.individualParticipantIds)||[]].filter(Boolean).flat()}))),S=o?P:e,T=Object.assign({},...Object.values(y).flat().map(M=>{const{scaleItem:C}=ip({scaleAttributes:O,tournamentRecord:t,participantId:M}),{scaleItem:D}=ip({tournamentRecord:t,scaleAttributes:I,participantId:M}),F=c?{[c]:void 0}:void 0;return{[M]:C||D||{scaleName:S,scaleType:Yi,eventType:m,scaleDate:v,scaleValue:F}}})),E=_r(f)||{},b=(E==null?void 0:E.bestOf)||1,N=(E==null?void 0:E.setsTo)||1,w=r?b&N:b,$=(g==null?void 0:g.sets)&&I_e(g.sets)||_===1&&[1,0]||[0,1],U=y[_],A=y[3-_];for(const M of U){const C=(i=T[M])==null?void 0:i.scaleValue,D=typeof C=="object"?C[c]:C;for(const F of A){const R=(s=T[F])==null?void 0:s.scaleValue,G=typeof R=="object"?R[c]:R,x=$[_],z=$[3-_],{newWinnerRating:j,newLoserRating:V}=w2({winnerCountables:x,loserCountables:z,maxCountables:w,winnerRating:D,loserRating:G,ratingType:e}),L=c?Il(_l({},C),{[c]:j}):j,q=c?Il(_l({},R),{[c]:V}):V;T[M].scaleValue=L,T[F].scaleValue=q;let k=fl({scaleItem:Il(_l({},T[M]),{scaleName:S}),participantId:M,tournamentRecord:t});if(k.error||(k=fl({scaleItem:Il(_l({},T[F]),{scaleName:S}),participantId:F,tournamentRecord:t}),k.error))return k}}Object.assign(l,T)}const d=u.map(({matchUpId:p})=>p);return Il(_l({},B),{modifiedScaleValues:l,processedMatchUpIds:d})}const E_e={calculateNewRatings:w2,processMatchUps:T_e};var w_e=Object.defineProperty,$_e=Object.defineProperties,N_e=Object.getOwnPropertyDescriptors,A2=Object.getOwnPropertySymbols,A_e=Object.prototype.hasOwnProperty,U_e=Object.prototype.propertyIsEnumerable,U2=(t,e,r)=>e in t?w_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,C_e=(t,e)=>{for(var r in e||(e={}))A_e.call(e,r)&&U2(t,r,e[r]);if(A2)for(var r of A2(e))U_e.call(e,r)&&U2(t,r,e[r]);return t},M_e=(t,e)=>$_e(t,N_e(e));(function(){const t={getState:({convertExtensions:i,removeExtensions:s}={})=>a_e({convertExtensions:i,removeExtensions:s,tournamentId:yn()}),setTournamentId:i=>tc(i)};t.version=()=>so(),t.reset=()=>{const i=xp(yn());return e(i)},t.setState=(i,s,a)=>{Fi(s,a);const c=S2(i,s);return e(c)};function e(i){return i!=null&&i.error?(t.error=i.error,t.success=!1):(t.error=void 0,t.success=!0),t}return o([m_e,E_e]),t;function r(i,s,a){delete t.success,delete t.error;const c=c_e(i,a);return s(M_e(C_e({},c),{tournamentRecord:i}))}function n(i,s){const a=(s==null?void 0:s.sandBoxRecord)||(s==null?void 0:s.sandboxRecord)||(s==null?void 0:s.sandboxTournament)||Xa(yn()),c=(s==null?void 0:s.rollbackOnError)&&ue(a,!1,!0),l=r(a,i,s);l!=null&&l.error&&c&&S2(c);const u=(l==null?void 0:l.success)&&(s==null?void 0:s.delayNotify)!==!0&&(s==null?void 0:s.doNotNotify)!==!0;return u&&bi(),(u||!(l!=null&&l.success)||s!=null&&s.doNotNotify)&&ii(),l}function o(i){i.forEach(s=>{Object.keys(s).forEach(a=>{t[a]=c=>{if(Ft())return n(s[a],c);try{return n(s[a],c)}catch(l){const u=l.toString();console.log("ERROR",{error:u,method:a,params:JSON.stringify(c)})}}})})}})();var D_e=["Abbey","Ahern","Ampleforth","Austen","Banks","Batty","Bauers","Beals","Beer","Bennett","Berry","Bonaparte","Brockovich","Bukowski","Cassidy","Catton","Calvino","Carson","Constant","Crane","Crowne","Cummings","Curie","Dallas","Diamond","Deckard","Earhart","Eisenstein","Eldritch","Elliot","Eyre","Faulkner","Frank","Godel","Goldstein","Greer","Holmgren","Humperdinck","Huxley","Illich","Jeffers","Jensen","Jevons","Johnson","Jovovich","Kingsnorth","Langer","Fernwright","Fuller","Le Guin","Lem","Lovelace","Midgely","Mond","Montoya","Murry","Nagle","Nearing","Ogden","Ophuls","Parks","Paz","Peet","Perfect","Pendejo","Pevensie","Postman","Ripley","Rodda","Rumfoord","Runciter","Rugen","Sale","Schumacher","Shaftoe","Shelley","Shepard","Smith","Stratton","Stewart","Swift","Tillich","Turing","Tyrell","Twain","Yeats","Veblen","Yates","Vonnegut","Waterhouse","Watson","Wirt","Wormwood"],j_e=["Ada","Amelia","Amelie","America","Anne","Antoina","Aravis","Astrid","Beatrice","Brienne","Buttercup","Cimorene","Cordelia","Desdemona","Ellen","Elizabeth","Emily","Emmie","Erin","Eva","Evelyn","Hermia","Hypatia","Imogen","Jane","Jasmine","Juliana","Juliet","Heather","Helen","Katniss","Leeloo","Lenina","Lilith","Linda","Lizzie","Louise","Lucy","Marie","Mary","Martha","Matilda","Milla","Miranda","Meg","Melba","Nicole","Ola","Portia","Pris","Rachael","Rachel","Rebecca","River","Rosa","Rosalind","Scout","Sharn","Susanne","Titania","Uhura","Ursula","Valentina","Viola","Virginia","Xena","Zoe"],R_e=["Alan","Aldous","August","Axel","Barda","Bill","Charles","Darwin","David","Derrick","Edward","Emmanuel","Ernst","Estlin","Fezzik","Filby","Frito","George","Glen","Helmholtz","Inigo","Italo","Ivan","James","Jared","Joe","John Michael","Jonathan","Korben","Kirkpatrick","Kurt","Lief","Malachi","Mark","Michael","Mustapha","Neil","Octavio","Palmer","Paul","Pierre","Robinson","Rick","Rincewind","Roy","Stafford","Stanislaw","Stanley","Syme","Thorstein","Tyrone","Vizzini","Walton","Walker","Warren","Wendell","Westley","William","Winston"],F_e={lastNames:D_e,firstFemale:j_e,firstMale:R_e};function Ug({count:t=100,sex:e}={}){if(!t||e&&![ct,mt].includes(e))return{personData:[],error:Z};const r=Math.ceil(t*1.3),{lastNames:n,firstFemale:o,firstMale:i}=F_e,s=qo.map(({iso:m})=>m).filter(Boolean),a=Math.ceil(r/n.length),c=Math.ceil(r/o.length),l=Math.ceil(r/i.length),u=le(0,a).flatMap(()=>{const m=ue(n,!1,!0);return le(0,n.length).map(()=>ir(m))}),d=le(0,c).flatMap(()=>{const m=ue(o,!1,!0);return le(0,o.length).map(()=>ir(m))}),p=le(0,l).flatMap(()=>{const m=ue(i,!1,!0);return le(0,i.length).map(()=>ir(m))}),v={};for(let m=0;m<r;m++){const g=u.pop(),h=e||gr([ct,mt]),_=h===ct?p.pop():d.pop(),I=gr(s);v[`${_}${g}`]={nationalityCode:I,sex:h,firstName:_,lastName:g}}return{personData:Object.values(v).slice(0,t)}}function C2({personExtensions:t,consideredDate:e,isMock:r=!0,gendersCount:n,personData:o,count:i=1,category:s,sex:a}={}){if(isNaN(i))return{error:Z};const c=(n==null?void 0:n[ct])||a===ct&&i||0,l=(n==null?void 0:n[mt])||a===mt&&i||0;i=Math.max(i,c+l);const u=i-(c+l),d=c&&Ug({count:c,sex:ct}).personData||[],p=l&&Ug({count:l,sex:mt}).personData||[],v=[...d,...p,...u&&Ug({count:u}).personData||[]];let f=v.filter(S=>!a||c&&l||S.sex===a),m=[];if(Array.isArray(o)){const S=o.filter(T=>typeof T.firstName!="string"||typeof T.lastName!="string"||![ct,mt].includes(T.sex)||T.nationalityCode&&(typeof T.nationalityCode!="string"||T.nationalityCode.length>3||!qo.find(({iso:E,ioc:b})=>[E,b].includes(T.nationalityCode)))?!1:(T.nationalityCode&&m.push(T.nationalityCode),!0));if(S.length)f=S;else return{error:Z}}const g=or(f);if(g.length<i){console.log("LESS",g.length,i);const{maleFirstNames:S,maleLastNames:T,femaleFirstNames:E,femaleLastNames:b,nationalityCodes:N}=v.reduce((w,$)=>{const{firstName:U,lastName:A,nationalityCode:M}=$;return $.sex===ct?(w.maleFirstNames.includes(U)||w.maleFirstNames.push(U),w.maleLastNames.includes(A)||w.maleLastNames.push(A)):(w.femaleFirstNames.includes(U)||w.femaleFirstNames.push(U),w.femaleLastNames.includes(A)||w.femaleLastNames.push(A)),w.nationalityCodes.includes(M)||w.nationalityCodes.push(M),w},{maleFirstNames:[],maleLastNames:[],femaleFirstNames:[],femaleLastNames:[],nationalityCodes:[]});le(0,i-g.length).forEach(()=>{const w=a||gr([ct,mt]),$=gr(N),U=gr(w===ct?S:E),A=gr(w===ct?T:b),M={firstName:U,lastName:A,sex:w,nationalityCode:$};g.push(M)})}const{ageMinDate:h,ageMaxDate:_}=bS({consideredDate:e,category:s}),I=parseInt((h==null?void 0:h.slice(0,4))||0)||parseInt((_==null?void 0:_.slice(0,4))||0)-3,P=parseInt((_==null?void 0:_.slice(0,4))||0)||parseInt((h==null?void 0:h.slice(0,4))||0)+3,O=(h||_)&&[I,P],y=g.slice(0,i).map((S,T)=>{const E=O&&ir(le(...O)),b=ir(le(0,365)),N=E&&rV(E,b);return Object.assign(_e({extensions:t||[{name:"regionCode",value:T+1}],birthDate:N,isMock:r}),S)});return{persons:y.length&&y||g[0],nationalityCodes:m}}function M2(t){const{cities:e,states:r,postalCodes:n,nationalityCode:o,participantIndex:i}=t;return{postalCode:n==null?void 0:n[i],state:r==null?void 0:r[i],city:e==null?void 0:e[i],countryCode:o}}var L_e=["Ace Academy","Avengers","Ball Bouncers","Baseliners","Captivators","Civil Disobedients","Continentals","Court Royal","Court Sharks","Diamond Dogs","Danger Zone","Doubles Dominators","Double Faults","Tricksters","Eliminators","Court Crusaders","Fuzz Busters","Game Changers","Goal Gurus","Good Volley","Green Machine","Hawk Eyes","Inside Outers","Killer Instinct","Line Toers","Masters of Mayhem","Matter Catchers","Cheap Shot","Mean Machines","Mindspace Invaders","Net Centric","Net Positive","Smash Mullet","Over Your Head","Spin Meisters","Aggressors","Racket Machine","Slice Happy","Refs Nightmare","Sandeaters","Sun Seekers","Slicer Dicers","Sparkle Soul Tribe","Stacked Deck","Cross Stringers","The Emergence","Total Demolition","Touch and Go","Upside Downers","Vertically Challenged","Visual Spectacle"];function Cg({nameRoot:t="TEAM",count:e=1}={}){const n=or(L_e).slice(0,e);return n.length<e&&le(0,e-n.length).forEach(o=>n.push(`${t} ${o+1}`)),{names:n}}var V_e=[{AA:"Annexia"},{BA:"Bacteria"},{BO:"Borduria"},{BM:"Bensalem"},{BS:"Basenji"},{BI:"Balnibarbi"},{BV:"Bartovia"},{BZ:"Berzerkistan"},{CA:"Caldonia"},{CC:"Concordia"},{CH:"Chula"},{DA:"Deltora"},{DW:"Discworld"},{EA:"Eastasia"},{EP:"Ecotopia"},{ER:"Erewhon"},{FA:"Freedonia"},{FN:"Florin"},{FG:"Fogg"},{FK:"Fourecks"},{GA:"Genovia"},{GL:"Gilead"},{GD:"Gilead"},{GL:"Gondal"},{GO:"Gondor"},{GR:"Gruzinia"},{GT:"Goritania"},{GU:"Guilder"},{HA:"Heldscalla"},{HO:"Hidalgo"},{IL:"Illyria"},{KA:"Kinakuta"},{KG:"Kangan"},{KN:"Kreplachistan"},{KS:"Kallipolis"},{LH:"Lugash"},{LI:"Listenbourg"},{LT:"Lilliput"},{LU:"Luggnagg"},{LV:"Lichtenslava"},{MR:"Moher"},{NA:"Narnia"},{NV:"Novaria"},{OA:"Oceania"},{OS:"Orsinia"},{OV:"Octavia"},{PA:"Palombia"},{PG:"Penguina"},{QA:"Qasha"},{PM:"Panem"},{SA:"Solymbria"},{SD:"Syldavia"},{SG:"San Glucose"},{SL:"San Lorenzo"},{SR:"Sontar"},{SY:"Sylvania"},{TF:"Tralfamadore"},{TH:"Themyscira"},{UA:"Utopia"},{VA:"Vespugia"},{WA:"Wakanda"},{WX:"Wessex"},{ZA:"Zamunda"},{ZK:"Zubrowka"}],x_e=["Amber","Ansul","Atlantis","Braavos","Busytown","Castle Rock","Centralia","Coober Pedy","Chefchaouen","Chronopolis","Damanhur","Diaspar","Dictionopolis","Diomira","El Dorado","Elista","Ephesus","Gotham","Hadleyburg","Hallstatt","Hierusalem","Ilium","Inverness","Kowloon","Laputa","Longyearbyen","Lys","Matmata","Maycomb","Metropolis","Miyake-jima","Monowi","Nagoro","Navarre","New New York","Nimbin","Pemberley","Pseudopolis","Rivendell","Roswell","Shangri-La","Springfield","Supilinn","Thneedville","Trantor","Wobegon","Yonwood","Xanadu","Xylar","Zion"];function D2({count:t=1,participantsCount:e=32}={}){const r=or(x_e),n=r.slice(0,t);return{cities:le(0,e).map(i=>i<Math.min(t,r.length)?n[i]:gr(n))}}function j2({count:t=1,participantsCount:e=32}={}){const r=or(V_e),n=r.slice(0,t).map(i=>Object.keys(i)).flat();return{states:le(0,e).map(i=>i<Math.min(t,r.length)?n[i]:gr(n))}}function R2({count:t=1,participantsCount:e=32}={}){const r=le(0,t).map(()=>le(0,5).map(()=>Er(0,9)).join(""));return{postalCodes:le(0,e).map(o=>o<t?r[o]:gr(r))}}var B_e=Object.defineProperty,k_e=Object.defineProperties,G_e=Object.getOwnPropertyDescriptors,F2=Object.getOwnPropertySymbols,W_e=Object.prototype.hasOwnProperty,H_e=Object.prototype.propertyIsEnumerable,L2=(t,e,r)=>e in t?B_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,V2=(t,e)=>{for(var r in e||(e={}))W_e.call(e,r)&&L2(t,r,e[r]);if(F2)for(var r of F2(e))H_e.call(e,r)&&L2(t,r,e[r]);return t},q_e=(t,e)=>k_e(t,G_e(e));function Y_e({keepExtensions:t=[],anonymizeParticipantNames:e=!0,tournamentRecord:r,tournamentName:n,personIds:o=[],tournamentId:i}){var s,a,c,l,u;if(!r)return{error:ee};const d=Array.isArray(t)?U_.concat(...t):U_,p=j=>{var V;return Array.isArray(t)?(V=j==null?void 0:j.extensions)==null?void 0:V.filter(L=>d.includes(L.name)):j==null?void 0:j.extensions},v={};r.extensions=p(r);const f=i||We();v[r.tournamentId]=f,r.tournamentId=f,r.createdAt=new Date().toISOString(),r.tournamentName=n||`Anonymized: ${On(new Date)}`,delete r.parentOrganisation;for(const j of r.participants||[]){const V=We();v[j.participantId]=V,j.participantId=V}for(const j of r.participants||[])Array.isArray(j.individualParticipantIds)&&(j.individualParticipantIds=j.individualParticipantIds.map(V=>v[V]));let m=0;for(const j of r.venues||[]){j.extensions=p(j),j.venueName=`Venue #${m}`,j.venueAbbreviation=`V${m}`;const V=We();v[j.venueId]=V,m+=1}let g=1;for(const j of r.events||[]){j.extensions=p(j);const V=We();v[j.eventId]=V,j.eventId=V;const L=((s=j.category)==null?void 0:s.categoryName)||((a=j.category)==null?void 0:a.ageCategoryCode)||((c=j.category)==null?void 0:c.ratingType)||j.gender;if(j.eventName=`Event ${g} ${L}`,Array.isArray(j.entries))for(const k of j.entries)k.participantId=v[k.participantId];for(const k of j.drawDefinitions||[]){k.extensions=p(k);const H=We();if(v[k.drawId]=H,k.drawId=H,Array.isArray(k.entries))for(const K of k.entries)K.participantId=v[K.participantId];const Q=K=>{K.extensions=p(K);const Y=We();v[K.structureId]=Y,K.structureId=Y;for(const J of K.positionAssignments||[])J.participantId&&(J.participantId=v[J.participantId]);for(const J of K.seedAssignments||[])J.participantId&&(J.participantId=v[J.participantId]);for(const J of K.matchUps||[])for(const te of J.sides||[])te.lineUp&&(te.lineUp=te.lineUp.map(({participantId:ne,collectionAssignments:oe})=>({participantId:v[ne],collectionAssignments:oe})))};for(const K of k.structures||[])if(Q(K),Array.isArray(K.structures))for(const Y of K.structures)Q(Y);for(const K of k.links||[])K.source.structureId=v[K.source.structureId],K.target.structureId=v[K.target.structureId]}const{extension:q}=mo({name:tn,event:j});Array.isArray((l=q==null?void 0:q.value)==null?void 0:l.flights)&&((u=q.value.flights)==null||u.forEach(k=>{if(k.drawId=v[k.drawId],Array.isArray(k.drawEntries))for(const H of k.drawEntries)H.participantId=v[H.participantId]})),g+=1}const h=r.startDate||On(new Date),_=(r.participants||[]).filter(({participantType:j})=>j===Me),I=_.reduce((j,V)=>{var L;const q=(L=V.person)==null?void 0:L.sex;return[ct,mt].includes(q)?j[q]+=1:j[as]+=1,j},{[ct]:0,[mt]:0,[as]:0}),P=Object.assign({},...Object.keys(I).map(j=>{var V;return{[j]:((V=C2({category:{ageCategoryCode:"O18"},count:I[j],addressProps:{citiesCount:10},personExtensions:[],consideredDate:h,sex:j}))==null?void 0:V.persons)||[]}})),O={[ct]:0,[mt]:0,[as]:0},y=_.length,S=_.reduce((j,V)=>{var L,q;const k=((q=(L=V.person)==null?void 0:L.addresses)==null?void 0:q[0])||{},{city:H,state:Q,postalCode:K}=k;return j.cities.includes(H)||j.cities.push(H),j.states.includes(Q)||j.states.push(Q),j.postalCodes.includes(K)||j.postalCodes.push(K),j},{cities:[],postalCodes:[],states:[]}),T=S.postalCodes.length,E=S.cities.length,b=S.states.length,{cities:N}=D2({count:E||y,participantsCount:y}),{states:w}=j2({count:b||y,participantsCount:y}),{postalCodes:$}=R2({count:T||y,participantsCount:y}),U={cities:N,states:w,postalCodes:$};_.forEach((j,V)=>{var L,q;const k=j==null?void 0:j.person,H=(k==null?void 0:k.sex)||as,Q=(L=Ce(k==null?void 0:k.birthDate))==null?void 0:L.split("-")[0],K=O[H],Y=P[H][K];if(O[H]+=1,Q){const[,J,te]=((q=Y==null?void 0:Y.birthDate)==null?void 0:q.split("-"))||[],ne=[Q,J,te].join("-");Y.birthDate=ne}if(k!=null&&k.addresses){const J=M2(q_e(V2({},U),{participantIndex:V,nationalityCode:Y.nationalityCode}));Y.addresses=[J]}Y.personId=(o==null?void 0:o[V])||We(),e?(Y.standardFamilyName=Y.lastName,Y.standardGivenName=Y.firstName,j.participantName=`${Y.standardGivenName} ${Y.standardFamilyName}`):(Y.standardFamilyName=k==null?void 0:k.standardFamilyName,Y.standardGivenName=k==null?void 0:k.standardGivenName),delete Y.firstName,delete Y.lastName,Y.extensions=p(k),j.person=Y,v[k==null?void 0:k.personId]=Y.personId}),(r.participants||[]).filter(({participantType:j})=>j===we).forEach(j=>{const{individualParticipantIds:V}=j;j.participantName=z_e({individualParticipantIds:V,individualParticipants:_})});const M=(r.participants||[]).filter(({participantType:j})=>j===Ye),C=M.length,D=Cg({count:C}).names;M.forEach((j,V)=>{j.participantName=D[V]});const F=(r.participants||[]).filter(({participantType:j})=>j===dr),R=F.length,G=Cg({count:R,nameRood:"Group"}).names;F.forEach((j,V)=>{j.participantName=G[V]});const{extension:x}=Sr({name:Do,tournamentRecord:r});Array.isArray(x==null?void 0:x.value)&&x.value.forEach(j=>{j.tournamentId=v[j.tournamentId],j.structureId=v[j.structureId],j.eventId=v[j.eventId],j.drawId=v[j.drawId]});const{extension:z}=Sr({name:Ks,tournamentRecord:r});return Array.isArray(z==null?void 0:z.value)&&z.value.forEach(j=>{j.personId=v[j.personId]}),V2({},B)}function z_e({individualParticipantIds:t,individualParticipants:e}){let r=e.filter(({participantId:n})=>t.includes(n)).map(({person:n})=>n==null?void 0:n.standardFamilyName).filter(Boolean).sort().join("/");return t.length===1&&(r+="/Unknown"),r}var K_e=Object.defineProperty,Q_e=Object.defineProperties,J_e=Object.getOwnPropertyDescriptors,x2=Object.getOwnPropertySymbols,Z_e=Object.prototype.hasOwnProperty,X_e=Object.prototype.propertyIsEnumerable,B2=(t,e,r)=>e in t?K_e(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,eIe=(t,e)=>{for(var r in e||(e={}))Z_e.call(e,r)&&B2(t,r,e[r]);if(x2)for(var r of x2(e))X_e.call(e,r)&&B2(t,r,e[r]);return t},tIe=(t,e)=>Q_e(t,J_e(e));function k2({matchUpFormat:t,matchUpStatus:e,winningSide:r,scoreString:n}){if(!n)return{outcome:tIe(eIe({},hu),{winningSide:r,matchUpStatus:e})};if(r&&![1,2,void 0].includes(r))return{error:Z,winningSide:r};const o=n&&Cu({scoreString:n}),i={},s=Jn({sets:o,matchUpFormat:t}),a=Jn({sets:o,reversed:!0,matchUpFormat:t});return r===2?(i.scoreStringSide1=a,i.scoreStringSide2=s):(i.scoreStringSide1=s,i.scoreStringSide2=a),i.sets=Cu({scoreString:i.scoreStringSide1}),_e({outcome:{matchUpStatus:e,winningSide:r,score:i}})}const rIe={[Ge]:2,[_t]:1,[bt]:1,[er]:1,[Be]:4};function G2({matchUpFormat:t="SET3-S:6/TB7",matchUpStatusProfile:e=rIe,pointsPerMinute:r=1,sideWeight:n=4,winningSide:o,defaultWithScorePercent:i=2}){if(!xr(t))return{error:yh};if(typeof e!="object")return{error:Z};if(i>100&&(i=100),isNaN(i)||isNaN(r)||isNaN(n))return{error:Z};const s=Object.keys(e).filter(b=>Object.keys(PV).includes(b)&&b!==St);if(Object.keys(s).reduce((b,N)=>b+e[N],0)>100)return{error:Z,matchUpStatusProfile:e};const c=s.reduce((b,N)=>(b.pointer=b.pointer+e[N],b.valueMap.push([b.pointer,N]),b),{pointer:0,valueMap:[]}),l=Er(1,100),u=(c.valueMap.find(b=>l<=b[0])||[100,St])[1],d={sets:[],scoreStringSide1:"",side2ScoreString:""};if([Ge,Be].includes(u)){o=o||Er(1,2);const b={score:d,winningSide:o,matchUpStatus:u};if(!(u===Be&&Er(1,100)>100-i))return{outcome:b}}else if([_t,bt].includes(u))return{outcome:{score:d,matchUpStatus:u}};const p=_r(t),{bestOf:v,setFormat:f,finalSetFormat:m}=p,g=[],h=Er(0,1),_=o?[o-1]:[...le(0,n).map(()=>h),1-h],P=[er,Be,Gn,li].includes(u)&&(ir(le(1,v))||1);let O;for(const b of le(1,v+1)){const N=b===v,{set:w,incomplete:$,winningSideNumber:U}=nIe({incomplete:P===b,matchUpStatus:u,pointsPerMinute:r,setFormat:N&&m||f,setNumber:b,weightedRange:_});if(g.push(w),$){O=U;break}if(ag({matchUp:{score:{sets:g},matchUpFormat:t}}).calculatedWinningSide)break}const y=ag({matchUp:{score:{sets:g},matchUpFormat:t}}),S=O?o||O:y.calculatedWinningSide,{score:T}=U0({score:{sets:g},winningSide:S,matchUpStatus:u});return{outcome:{score:T,winningSide:S,matchUpStatus:u}}}function nIe({weightedRange:t=[0,1],pointsPerMinute:e,matchUpStatus:r,incomplete:n,setFormat:o,setNumber:i}){const s={setNumber:i},{setTo:a,tiebreakFormat:c,tiebreakAt:l,tiebreakSet:u,timed:d,minutes:p}=o,v=Er(0,t.length-1),f=t[v];let m;if(d){const g=p*e,h=Math.round(g*.2),_=g+ir([1,-1])*h,I=qR(_,2),P=[I,_-I];f&&P.reverse(),m=t[v]+1;let O=P[0]>P[1]&&1||P[1]>P[0]&&2||0;if(n){const[T,E]=P;return Object.assign(s,{side1Score:T,side2Score:E}),Lt.includes(r)?{set:s,incomplete:n,winningSideNumber:m}:{set:s,incomplete:n}}O||(P[Er(0,1)]+=1),O=P[0]>P[1]?1:2,O!==m&&P.reverse();const[y,S]=P;return Object.assign(s,{side1Score:y,side2Score:S,winningSide:m}),{set:s}}else{if(n)return s.side1Score=Er(0,l),s.side2Score=Er(0,l),Lt.includes(r)&&(m=t[v]+1),{set:s,incomplete:n,winningSideNumber:m};{const g=le(1,a+1).map(S=>le(0,a+2-S).map(()=>S)).flat(),h=g[Er(0,g.length-1)],_=a&&Ey({isSide1:!0,tiebreakAt:l,lowValue:h,setTo:a}),I=!_,P=t.length===1&&t[v]+1;if(!I){P?(_[0]>_[1]?1:2)!==P&&_.reverse():f&&_.reverse();const[S,T]=_;Object.assign(s,{side1Score:S,side2Score:T})}const O=yu({matchUpScoringFormat:{setFormat:o},setObject:s});let y;if(O.hasTiebreakCondition||I){const{NoAD:S,tiebreakTo:T}=c||u||{},E=le(1,T+1).map(w=>le(0,T+2-w).map(()=>w)).flat(),b=E[Er(0,E.length-1)];let N=ev({isSide1:!0,tiebreakNoAd:S,tiebreakTo:T,lowValue:b});if(N)if(I){const w=N[0]>N[1]?1:2;P?w!==P&&N.reverse():f&&N.reverse(),[s.side1TiebreakScore,s.side2TiebreakScore]=N,y=N[0]>N[1]&&1||N[1]>N[0]&&2||void 0}else O.leadingSide===2?[s.side1TiebreakScore,s.side2TiebreakScore]=N:[s.side2TiebreakScore,s.side1TiebreakScore]=N}s.winningSide=O.winningSide||O.leadingSide||P||y}}return{set:s}}var oIe=Object.defineProperty,iIe=Object.defineProperties,sIe=Object.getOwnPropertyDescriptors,W2=Object.getOwnPropertySymbols,aIe=Object.prototype.hasOwnProperty,cIe=Object.prototype.propertyIsEnumerable,H2=(t,e,r)=>e in t?oIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lIe=(t,e)=>{for(var r in e||(e={}))aIe.call(e,r)&&H2(t,r,e[r]);if(W2)for(var r of W2(e))cIe.call(e,r)&&H2(t,r,e[r]);return t},uIe=(t,e)=>iIe(t,sIe(e));function sp({matchUpStatusProfile:t,completeAllMatchUps:e,randomWinningSide:r,tournamentRecord:n,drawDefinition:o,completionGoal:i,matchUpFormat:s,event:a}){var c,l,u;const d=o.structures.slice().sort(Ii);let p=0,{matchUps:v,matchUpsMap:f}=Nt({contextFilters:{stages:[de,Ie]},matchUpFilters:{matchUpTypes:[He],roundNumbers:[1]},inContext:!0,drawDefinition:o});if(v.length){const h=((c=a.category)==null?void 0:c.ageCategoryCode)||((l=a.category)==null?void 0:l.categoryName);if(h)RD({singlesOnly:!0,tournamentRecord:n,drawDefinition:o,scaleAccessor:{scaleName:h,sortOrder:oge,scaleType:ui},attach:!0,event:a});else{const _=(u=v[0])==null?void 0:u.structureId,{positionAssignments:I}=et({drawDefinition:o,structureId:_});if(I!=null&&I.length){let{tournamentParticipants:P}=Qt({participantFilters:{participantTypes:[He]},tournamentRecord:n});const O=y=>{const S=y.tieMatchUps.filter(({matchUpType:E})=>E===pt),T=y.tieMatchUps.filter(({matchUpType:E})=>E===it);S.forEach((E,b)=>{const N=E.matchUpId;E.sides.forEach(w=>{const{drawPosition:$}=w,U=P.find(A=>{const{participantId:M}=A,C=I.find(D=>D.participantId===M);return(C==null?void 0:C.drawPosition)===$});if(U){const A=U.individualParticipantIds[b];yg({teamParticipantId:U.participantId,participantId:A,tournamentRecord:n,drawDefinition:o,tieMatchUpId:N,event:a})}})}),T.forEach((E,b)=>{const N=E.matchUpId;E.sides.forEach(w=>{const{drawPosition:$}=w,U=P.find(A=>{const{participantId:M}=A,C=I.find(D=>D.participantId===M);return(C==null?void 0:C.drawPosition)===$});U&&U.individualParticipantIds.slice(b*2,b*2+2).forEach(M=>{yg({teamParticipantId:U.participantId,participantId:M,tournamentRecord:n,drawDefinition:o,tieMatchUpId:N,event:a})})})})};v.forEach(O)}}}const m=typeof e=="string"&&e,g=m&&St;for(const h of d){if(p>=i)break;const{matchUps:_}=ze({matchUpFilters:{matchUpTypes:[it,pt]},afterRecoveryTimes:!1,tournamentRecord:n,inContext:!0,drawDefinition:o,matchUpsMap:f,structure:h,event:a}),I=_.filter(({winningSide:P})=>!P).sort(vs).map(Mt);for(const P of I){if(!isNaN(i)&&p>=i)break;const{matchUps:O}=ze({matchUpFilters:{matchUpTypes:[it,pt]},afterRecoveryTimes:!1,tournamentRecord:n,inContext:!0,drawDefinition:o,matchUpsMap:f,structure:h,event:a}),y=O.find(T=>T.matchUpId===P),S=[_t,bt].includes(y.matchUpStatus);if(y!=null&&y.readyToScore&&!S){const T=dIe({winningSide:!r&&1,matchUpStatusProfile:t,tournamentRecord:n,drawDefinition:o,targetMatchUp:y,matchUpFormat:s,matchUpStatus:g,scoreString:m,event:a});if(T.error)return T;p+=1}}}return uIe(lIe({},B),{completedCount:p})}function q2({matchUpStatusCodes:t,tournamentRecord:e,drawDefinition:r,targetMatchUp:n,matchUpStatus:o,matchUpFormat:i,scoreString:s,winningSide:a,event:c}){if(!n||n.matchUpStatus===qe)return;const{matchUpId:l}=n||{},{outcome:u}=k2({matchUpFormat:i,matchUpStatus:o,scoreString:s,winningSide:a});return t&&(u.matchUpStatusCodes=t),Qc({tournamentRecord:e,drawDefinition:r,matchUpFormat:i,matchUpId:l,outcome:u,event:c})}function dIe(t){const{matchUpStatusProfile:e={},tournamentRecord:r,drawDefinition:n,matchUpStatus:o,matchUpFormat:i,targetMatchUp:s,scoreString:a,winningSide:c,event:l}=t;if(a||o)return q2(t);const{matchUpId:u}=s||{},{outcome:d}=G2({matchUpStatusProfile:e,matchUpFormat:i,winningSide:c});return Qc({tournamentRecord:r,drawDefinition:n,matchUpFormat:i,matchUpId:u,outcome:d,event:l})}var pIe=Object.defineProperty,fIe=Object.defineProperties,vIe=Object.getOwnPropertyDescriptors,Y2=Object.getOwnPropertySymbols,mIe=Object.prototype.hasOwnProperty,gIe=Object.prototype.propertyIsEnumerable,z2=(t,e,r)=>e in t?pIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Mg=(t,e)=>{for(var r in e||(e={}))mIe.call(e,r)&&z2(t,r,e[r]);if(Y2)for(var r of Y2(e))gIe.call(e,r)&&z2(t,r,e[r]);return t},Dg=(t,e)=>fIe(t,vIe(e));function K2({matchUpStatusProfile:t,completeAllMatchUps:e,randomWinningSide:r,tournamentRecord:n,drawProfiles:o,event:i}){var s,a;const{flightProfile:c}=It({event:i}),{eventName:l,eventType:u,category:d}=i,{startDate:p}=n,v=[],f=(d==null?void 0:d.categoryName)||(d==null?void 0:d.ageCategoryCode)||(d==null?void 0:d.ratingType),m=(s=i.drawDefinitions)==null?void 0:s.map(({drawId:g})=>g);if(Array.isArray(c==null?void 0:c.flights))for(const[g,h]of c.flights.entries()){const{drawId:_,stage:I,drawName:P,drawEntries:O}=h;v.push(h.drawId);const y=o[g],{seedsCount:S,generate:T=!0}=y||{};if(T){const E=O.filter(gu).map(Xe),b=f||l;if(n&&S&&S<=E.length&&le(1,S+1).forEach((C,D)=>{let F={scaleValue:C,scaleName:b,scaleType:rn,eventType:u,scaleDate:p};const R=E[D];fl({tournamentRecord:n,participantId:R,scaleItem:F})}),m!=null&&m.includes(_))break;let N=$g(Dg(Mg({},y),{matchUpType:u,seedingScaleName:b,tournamentRecord:n,isMock:!0,drawEntries:O,drawName:P,drawId:_,event:i,stage:I}));if(N.error)return N;const{drawDefinition:w}=N,$=(a=o[g])==null?void 0:a.drawExtensions;if(Array.isArray($)&&$.filter(on).forEach(M=>tt({element:w,extension:M})),N=Jc({suppressNotifications:!0,tournamentRecord:n,drawDefinition:w,event:i}),N.error)return N;if(y.drawType===cn&&y.drawMatic){const M=y.roundsCount||1;for(const C of le(1,M+1)){const D=bg({generateMatchUps:!0,tournamentRecord:n,drawDefinition:w,roundNumber:C});if(D.error)return D}}if(y!=null&&y.withPlayoffs){const M=w.structures[0].structureId,C=Dd(Dg(Mg({idPrefix:y.idPrefix},y.withPlayoffs),{tournamentRecord:n,drawDefinition:w,isMock:!0,structureId:M,event:i}));if(C!=null&&C.error)return C}const U=y==null?void 0:y.completionGoal;if(!((y==null?void 0:y.automated)===!1)&&(e||U)){const M=y==null?void 0:y.matchUpFormat,C=sp({completeAllMatchUps:!U&&e,matchUpStatusProfile:t,randomWinningSide:r,tournamentRecord:n,completionGoal:U,drawDefinition:w,matchUpFormat:M,event:i});if(C.error)return C;const D=C.completedCount;if((y==null?void 0:y.drawType)===Io){const F=w.structures.find(x=>x.stage===de);let R=Cd({structureId:F.structureId,tournamentRecord:n,drawDefinition:w,event:i});if(R.error)return R;const G=U?U-D:void 0;if(R=sp({completeAllMatchUps:!U&&e,completionGoal:U?G:void 0,matchUpStatusProfile:t,randomWinningSide:r,tournamentRecord:n,drawDefinition:w,matchUpFormat:M,event:i}),R.error)return R}}}}return Dg(Mg({},B),{drawIds:v})}var hIe=Object.defineProperty,_Ie=Object.defineProperties,IIe=Object.getOwnPropertyDescriptors,Q2=Object.getOwnPropertySymbols,PIe=Object.prototype.hasOwnProperty,yIe=Object.prototype.propertyIsEnumerable,J2=(t,e,r)=>e in t?hIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,SIe=(t,e)=>{for(var r in e||(e={}))PIe.call(e,r)&&J2(t,r,e[r]);if(Q2)for(var r of Q2(e))yIe.call(e,r)&&J2(t,r,e[r]);return t},OIe=(t,e)=>_Ie(t,IIe(e));function ap({ratingsParameters:t=Xn,valuesInstanceLimit:e,consideredDate:r,category:n,nationalityCodesCount:o,nationalityCodeType:i,nationalityCodes:s,participantsCount:a=32,participantType:c,personIds:l,idPrefix:u,uuids:d,personExtensions:p,addressProps:v,gendersCount:f,matchUpType:m,personData:g,sex:h,inContext:_,withISO2:I,withIOC:P,rankingRange:O,scaledParticipantsCount:y,scaleAllParticipants:S}){const T=c===we||m===Jr,E=c===Ye||m===Ye;O&&(!Array.isArray(O)||!O.every(X=>Ot(X))||O.length!==2)&&(O=void 0),y=S?a:y;const b=1e3,N=y&&y>b?y:b;O=O||[1,N],O[1]+=1;const w=a*(T?2:E?8:1),$=C2({count:w,personExtensions:p,consideredDate:r,gendersCount:f,personData:g,category:n,sex:h});if($.error)return $;const{nationalityCodes:U,persons:A}=$;let M=[],C=[],D=[],F=[];if(typeof n=="object"){const{categoryName:X,ageCategoryCode:ie,ratingType:fe}=n;if((X||ie)&&!fe&&(C=or(le(...O)).slice(0,y||Er(20,30)),[we,Ye].includes(c)&&(M=or(le(...O)).slice(0,y||Er(20,30)))),fe&&t[fe]){let{ratingMax:$e,ratingMin:re,ratingAttributes:ae}=n;const me=Object.assign({},t[fe],ae||{}),{attributes:Se={},decimalsCount:ce,accessors:Pe,range:Ae,step:ye}=me,Ue=ke=>{const je={};for(const Ze of Object.keys(ke)||{}){const ot=ke[Ze];if(typeof ot=="object"&&ot.generator){const{range:Ke}=ot,[At,rr]=Ke.slice().sort();je[Ze]=Er(At,rr)}else je[Ze]=ot}return je},ge=Ae[0]>Ae[1]?2:.5,[Ne,De]=Ae.slice().sort(),he=()=>le(0,2e3).map(()=>th(Ne,De,ge,ye,ce)).filter(ke=>(!$e||ke<=$e)&&(!re||ke>=re)).slice(0,y||Er(20,30)).map(ke=>Pe?Object.assign({},...Pe.map(je=>({[je]:ke})),Ue(Se)):ke);D=he(),[we,Ye].includes(c)&&(F=he())}}const R=qo.filter(X=>i==="IOC"&&X.ioc||X.iso);function G(X){const ie=Math.ceil(w/X);return e&&ie>e?Math.ceil(w/e):X}const{postalCodesProfile:x,postalCodesCount:z,statesProfile:j,citiesProfile:V,citiesCount:L,statesCount:q}=v||{},k=X=>Object.keys(X).map(ie=>le(0,j[ie]).map(()=>ie)).flat(),H=V&&k(V)||(v==null?void 0:v.cities)||D2({count:L||w,participantsCount:w}).cities,Q=j&&k(j)||(v==null?void 0:v.states)||j2({count:q||w,participantsCount:w}).states,K=x&&k(x)||(v==null?void 0:v.postalCodes)||R2({count:z||w,participantsCount:w}).postalCodes,Y={cities:H,states:Q,postalCodes:K},J=G(o),te=J?or(R).slice(0,o):s?R.filter(X=>s.includes(X.key)):R,ne=or(le(0,Math.ceil(w/(J||1))).map(()=>te).flat(1/0)),oe=Cg({count:a}).names;return{participants:le(0,a).map(X=>{const ie=T?2:E?8:1,fe=le(0,ie).map(Se=>{const ce=X*ie+Se;return ve(ce)}),$e=fe.map(Se=>Se.participantId),re=fe.map(Se=>Se.person.standardFamilyName).join("/"),ae=T?we:Ye,me={participantId:Z2({participantType:ae,idPrefix:u,index:X,uuids:d}),participantRole:qt,participantName:T?re:oe[X],individualParticipantIds:$e,participantType:ae};return _&&(me.individualParticipants=fe),T||E?[me,...fe]:fe}).flat()};function ve(X){const ie=A[X],{nationalityCode:fe,participantExtensions:$e,participantTimeItems:re,extensions:ae,firstName:me,birthDate:Se,lastName:ce,personId:Pe,sex:Ae}=ie||{},ye=me||"GivenName",Ue=ce||"FamilyName",be=`${ye} ${Ue}`,ge=ne[X],Ne=(U==null?void 0:U.length)&&fe||ge&&(i==="IOC"?ge.ioc||ge.iso:ge.iso||ge.ioc)||fe;ne!=null&&ne.length&&!Ne&&!fe&&console.log("%c Invalid Nationality Code",{participantIndex:X,country:ge});const De=M2(OIe(SIe({},Y),{participantIndex:X,nationalityCode:Ne})),he=_e({participantId:Z2({participantType:Me,index:X,idPrefix:u,uuids:d}),extensions:$e,timeItems:re,participantRole:qt,participantType:Me,participantName:be,person:{addresses:[De],personId:Pe||(l==null?void 0:l.length)&&l[X]||We(),standardFamilyName:Ue,standardGivenName:ye,nationalityCode:Ne,extensions:ae,birthDate:Nr(Se)?Se:void 0,sex:Ae}});if(P&&Ne){const ke=qo.find(({iso:je})=>je===Ne);ke!=null&&ke.ioc&&(he.person.iocNationalityCode=ke.ioc),ke!=null&&ke.label&&(he.person.countryName=ke.label)}if(I&&Ne){const ke=qo.find(({iso:je})=>je===Ne);ke!=null&&ke.iso2&&(he.person.iso2NationalityCode=ke.iso2),ke!=null&&ke.label&&(he.person.countryName=ke.label)}if(n){const ke=C[X],je=M[X];cp({scaleValue:ke,eventType:cP,scaleType:ui,participant:he,category:n}),cp({scaleValue:je,eventType:hc,scaleType:ui,participant:he,category:n});const Ze=D[X],ot=F[X];cp({scaleValue:Ze,eventType:cP,scaleType:Yi,participant:he,category:n}),cp({scaleValue:ot,eventType:hc,scaleType:Yi,participant:he,category:n})}return he}}function cp({scaleValue:t,participant:e,eventType:r,scaleType:n,category:o}){const i=o.categoryName||o.ratingType||o.ageCategoryCode,s=[zi,n,r,i].join("."),a={itemValue:t,itemType:s};i&&t&&(e.timeItems||(e.timeItems=[]),e.timeItems.push(a))}function Z2({idPrefix:t,participantType:e,index:r,uuids:n}){return t?`${t}-${e===Me?"I":we?"P":Ye?"T":dr?"G":"X"}-${r}`:(n==null?void 0:n.pop())||We()}function X2({alternatesCount:t=0,tieFormatName:e,tieFormat:r,drawSize:n}){var o;let i=0,s=0,a=0,c=0,l={};const u={[ct]:0,[mt]:0,[yo]:0,[as]:0,[ia]:0};r=typeof r=="object"?r:Es({namedFormat:e}),(o=r==null?void 0:r.collectionDefinitions)==null||o.filter(Boolean).forEach(f=>{const{category:m,collectionId:g,matchUpType:h,matchUpCount:_,gender:I}=f;if([ct,mt].includes(I)){const P=_*(h===it?2:1);u[I]<P&&(u[I]=P)}else I===yo&&(u[ct]<_&&(u[ct]=_),u[mt]<_&&(u[mt]=_));if(m){const P=JSON.stringify(m);l[P]=m}if(g||(f.collectionId=We()),h===it){const P=_;c+=_,i=Math.max(i,P)}if(h===pt){const P=_;a+=_,s=Math.max(s,P)}});const d=Object.keys(l).length?Math.max(a,c*2):Math.max(s,i*2),p=i*(n+t),v=s*(n+t);return{maxDoublesDraw:p,maxSinglesDraw:v,teamSize:d,genders:u}}var bIe=Object.defineProperty,TIe=Object.defineProperties,EIe=Object.getOwnPropertyDescriptors,ej=Object.getOwnPropertySymbols,wIe=Object.prototype.hasOwnProperty,$Ie=Object.prototype.propertyIsEnumerable,tj=(t,e,r)=>e in t?bIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,NIe=(t,e)=>{for(var r in e||(e={}))wIe.call(e,r)&&tj(t,r,e[r]);if(ej)for(var r of ej(e))$Ie.call(e,r)&&tj(t,r,e[r]);return t},AIe=(t,e)=>TIe(t,EIe(e));function UIe({participantsProfile:t,eventProfiles:e,drawProfiles:r}){let{participantsCount:n,participantType:o=Me}=t||{};const i=n||0,s={[mt]:0,[yo]:0,[as]:0,[ct]:0,[ia]:0};let a=0,c=0,l=0,u=0,d=0;const p=({alternatesCount:m=0,uniqueParticipants:g,tieFormatName:h,drawSize:_=0,eventType:I,tieFormat:P,category:O,gender:y,stage:S})=>{const T=I===br,E=I===Tt,b=!!(g||S===Ie||O||y);if(E){u=Math.max(u,_+m),P=typeof P=="object"?P:Es({namedFormat:h});const{teamSize:N,maxDoublesDraw:w,maxSinglesDraw:$,genders:U}=X2({alternatesCount:m,tieFormatName:h,tieFormat:P,drawSize:_});l=Math.max(l,N),c=Math.max(c,$),b||(a=Math.max(a,w)),Object.keys(U).forEach(A=>s[A]+=U[A])}else if(T)if(b){const N=(_+m)*2;d+=N,y&&(s[y]+=N)}else _+m&&_+m>a&&(a=_+m);else if(b){const N=_+m;y&&(s[y]+=N),d+=N}else _&&_>c&&(c=_+m)};let v=[];if(e==null||e.forEach(m=>{const{tieFormatName:g,tieFormat:h,drawProfiles:_,eventType:I,category:P,gender:O}=m;if(_)for(const y of _){const{tieFormatName:S,tieFormat:T}=y;p(AIe(NIe({},y),{tieFormatName:S||g,tieFormat:T||h,eventType:I,category:P,gender:O}))}else P&&(v.push(P),console.log({categories:v}))}),Array.isArray(r))for(const m of r)p(m);const f=Math.max(u*l,a*2,c);return a&&(o=we),(n||i)<f&&(n=f),n&&a&&[we,Tt].includes(o)&&(c&&Math.floor(c/2)>a?n=Math.floor(c/2):(!c||a*2>=c)&&(n=Math.ceil(n/2))),n===void 0&&(n=!(e!=null&&e.length)&&!(r!=null&&r.length)?32:0),n<i&&(n=i),{uniqueParticipantsCount:d,participantsCount:n,largestTeamDraw:u,largestTeamSize:l,participantType:o,gendersCount:s}}var CIe=Object.defineProperty,MIe=Object.defineProperties,DIe=Object.getOwnPropertyDescriptors,rj=Object.getOwnPropertySymbols,jIe=Object.prototype.hasOwnProperty,RIe=Object.prototype.propertyIsEnumerable,nj=(t,e,r)=>e in t?CIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,jg=(t,e)=>{for(var r in e||(e={}))jIe.call(e,r)&&nj(t,r,e[r]);if(rj)for(var r of rj(e))RIe.call(e,r)&&nj(t,r,e[r]);return t},FIe=(t,e)=>MIe(t,DIe(e));function oj({participantsProfile:t={},tournamentRecord:e,eventProfiles:r,drawProfiles:n,startDate:o,uuids:i}){const{participantsCount:s,participantType:a,largestTeamDraw:c,largestTeamSize:l,gendersCount:u}=UIe({participantsProfile:t,eventProfiles:r,drawProfiles:n}),{teamKey:d}=t||{},{participants:p}=ap(FIe(jg({uuids:i},t),{consideredDate:o,participantsCount:s,participantType:a,gendersCount:u}));let v=0,f=to({tournamentRecord:e,participants:p});if(f.error)return f;if(v+=f.addedCount,d){const h=kU(jg({tournamentRecord:e},d));if(h.error)return h}const m=p.filter(({participantType:h})=>h===Me).map(Xe),g=le(0,c).map(h=>{const _=m.slice(h*l,(h+1)*l);return{participantName:`Team ${h+1}`,participantRole:qt,participantType:Ye,participantId:We(),individualParticipantIds:_}});return f=to({participants:g,tournamentRecord:e}),f.error?f:(v+=f.addedCount,jg({addedCount:v},B))}var LIe=Object.defineProperty,VIe=Object.defineProperties,xIe=Object.getOwnPropertyDescriptors,ij=Object.getOwnPropertySymbols,BIe=Object.prototype.hasOwnProperty,kIe=Object.prototype.propertyIsEnumerable,sj=(t,e,r)=>e in t?LIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,GIe=(t,e)=>{for(var r in e||(e={}))BIe.call(e,r)&&sj(t,r,e[r]);if(ij)for(var r of ij(e))kIe.call(e,r)&&sj(t,r,e[r]);return t},WIe=(t,e)=>VIe(t,xIe(e));function aj({participantsProfile:t={},uniqueParticipantsCount:e,ratingsParameters:r,tournamentRecord:n,eventProfile:o,eventIndex:i,event:s,uuids:a}){const{category:c,gender:l,eventType:u}=s,d=u===Hn&&Me||u===br&&we||u,p=e[de]||0,v=e[Ie]||0,f=p+v,m=[ct,mt].includes(l)?l:void 0,g=t!=null&&t.idPrefix?`E-${i}-${t==null?void 0:t.idPrefix}`:void 0,{participants:h}=ap(WIe(GIe({uuids:o.uuids||a},t),{scaledParticipantsCount:o.scaledParticipantsCount,consideredDate:n==null?void 0:n.startDate,rankingRange:o.rankingRange,participantType:d,participantsCount:f,ratingsParameters:r,idPrefix:g,category:c,sex:m}));let _=to({participants:h,tournamentRecord:n});if(_.error)return _;const I=h.filter(({participantType:O})=>O===d),P=h.map(Xe);return{uniqueDrawParticipants:I,uniqueParticipantIds:P}}function cj({drawProfiles:t,category:e,gender:r}){const n={},o=t==null?void 0:t.reduce((s,a)=>{const{qualifyingPositions:c=0,participantsCount:l=0,uniqueParticipants:u,stage:d=de,drawSize:p=0}=a||{};Object.keys(s).includes(d)||(s[d]=0);const v=(l||p)-c;return u||r||e||d===Ie?(Object.keys(n).includes(d)||(n[d]=0),n[d]+=v):s[d]=Math.max(s[d],v),s},{}),i=Object.keys(n);return i.forEach(s=>o[s]+=n[s]),{stageParticipantsCount:o,uniqueParticipantsCount:n,uniqueParticipantStages:i}}function lj({allUniqueParticipantIds:t,stageParticipantsCount:e,eventParticipantType:r,targetParticipants:n}){const o=e[de]||0,i=e[Ie]||0;return{stageParticipants:{QUALIFYING:n.filter(({participantType:a})=>a===r).filter(({participantId:a})=>!t.includes(a)).slice(0,i),MAIN:n.filter(({participantType:a})=>a===r).filter(({participantId:a})=>!t.includes(a)).slice(i,i+o)}}}var HIe=Object.defineProperty,uj=Object.getOwnPropertySymbols,qIe=Object.prototype.hasOwnProperty,YIe=Object.prototype.propertyIsEnumerable,dj=(t,e,r)=>e in t?HIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zIe=(t,e)=>{for(var r in e||(e={}))qIe.call(e,r)&&dj(t,r,e[r]);if(uj)for(var r of uj(e))YIe.call(e,r)&&dj(t,r,e[r]);return t};function KIe({autoEntryPositions:t,tournamentRecord:e,drawParticipants:r,drawProfile:n,event:o}){const{drawType:i=zn,qualifyingPositions:s=0,stage:a=de,drawSize:c=0,drawName:l,drawId:u}=n,d=c-s,p=r.slice(0,d).map(Xe);if(p.length){const m=Qo({participantIds:p,autoEntryPositions:t,tournamentRecord:e,stage:a,event:o});if(m.error)return m}const v=p.map(m=>({entryStatus:Mr,entryStage:a,participantId:m})),f=Tg({drawName:l||i,qualifyingPositions:s,drawEntries:v,drawId:u,event:o,stage:a});return f.error?f:zIe({},B)}var QIe=Object.defineProperty,pj=Object.getOwnPropertySymbols,JIe=Object.prototype.hasOwnProperty,ZIe=Object.prototype.propertyIsEnumerable,fj=(t,e,r)=>e in t?QIe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,XIe=(t,e)=>{for(var r in e||(e={}))JIe.call(e,r)&&fj(t,r,e[r]);if(pj)for(var r of pj(e))ZIe.call(e,r)&&fj(t,r,e[r]);return t};function vj({uniqueDrawParticipants:t,autoEntryPositions:e,stageParticipants:r,tournamentRecord:n,drawProfiles:o,category:i,gender:s,event:a}){let c=0;for(const l of o){const{qualifyingPositions:u=0,uniqueParticipants:d,stage:p=de,drawSize:v=0}=l,f=v-u,m=d||s||i||p===Ie,g=m?t.slice(c,c+f):r[p||de]||[];m&&(c+=f);const h=KIe({autoEntryPositions:e,drawParticipants:g,tournamentRecord:n,drawProfile:l,event:a});if(h.error)return h}return XIe({},B)}var ePe=Object.defineProperty,tPe=Object.defineProperties,rPe=Object.getOwnPropertyDescriptors,mj=Object.getOwnPropertySymbols,nPe=Object.prototype.hasOwnProperty,oPe=Object.prototype.propertyIsEnumerable,gj=(t,e,r)=>e in t?ePe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,iPe=(t,e)=>{for(var r in e||(e={}))nPe.call(e,r)&&gj(t,r,e[r]);if(mj)for(var r of mj(e))oPe.call(e,r)&&gj(t,r,e[r]);return t},sPe=(t,e)=>tPe(t,rPe(e));function hj({allUniqueParticipantIds:t,matchUpStatusProfile:e,participantsProfile:r,completeAllMatchUps:n,autoEntryPositions:o,hydrateCollections:i,randomWinningSide:s,ratingsParameters:a,tournamentRecord:c,eventProfile:l,eventIndex:u,publish:d,uuids:p}){let v=l.gender,f=l.eventName;const{eventType:m=Hn,policyDefinitions:g,drawProfiles:h=[],eventExtensions:_,surfaceCategory:I,tieFormatName:P,discipline:O,eventLevel:y,timeItems:S,ballType:T,category:E}=l,b=l.tieFormat||(m===Tt?Es({namedFormat:P,event:{category:E,gender:v},hydrateCollections:i}):void 0);let N=c.participants;for(const L of h)!v&&L.gender&&(v=L==null?void 0:L.gender);const{stageParticipantsCount:w,uniqueParticipantsCount:$,uniqueParticipantStages:U}=cj({drawProfiles:h,category:E,gender:v}),A=m===Hn&&Me||m===br&&we||m,{uniqueDrawParticipants:M=[],uniqueParticipantIds:C=[]}=U?aj({event:{eventType:m,category:E,gender:v},uniqueParticipantsCount:$,participantsProfile:r,ratingsParameters:a,tournamentRecord:c,eventProfile:l,eventIndex:u,uuids:p}):{};let{eventAttributes:D}=l;typeof D!="object"&&(D={});const F=(E==null?void 0:E.categoryName)||(E==null?void 0:E.ageCategoryCode)||(E==null?void 0:E.ratingType),R=l.eventId||We();f=f||F||"Generated Event";const G=sPe(iPe({},D),{surfaceCategory:I,discipline:O,eventLevel:y,eventName:f,eventType:m,tieFormat:b,ballType:T,category:E,eventId:R,gender:v});if(_!=null&&_.length&&Array.isArray(_)){const L=_.filter(on);L!=null&&L.length&&Object.assign(G,{extensions:L})}if(Array.isArray(S)&&S.forEach(L=>zo({event:z,timeItem:L})),typeof g=="object")for(const L of Object.keys(g))bE({policyDefinitions:{[L]:g[L]},event:G});G.category&&(G.category.categoryName=F);let x=np({suppressNotifications:!1,internalUse:!0,tournamentRecord:c,event:G});if(x.error)return x;const{event:z}=x,{stageParticipants:j}=lj({allUniqueParticipantIds:t,stageParticipantsCount:w,eventParticipantType:A,targetParticipants:N});if(x=vj({uniqueDrawParticipants:M,autoEntryPositions:o,stageParticipants:j,tournamentRecord:c,drawProfiles:h,category:E,gender:v,event:z}),x.error||(x=K2({matchUpStatusProfile:e,completeAllMatchUps:n,randomWinningSide:s,tournamentRecord:c,drawProfiles:h,event:z}),x.error))return x;const V=x.drawIds;return d&&ml({tournamentRecord:c,event:z}),{drawIds:V,eventId:R,uniqueParticipantIds:C}}var aPe=Object.defineProperty,cPe=Object.defineProperties,lPe=Object.getOwnPropertyDescriptors,_j=Object.getOwnPropertySymbols,uPe=Object.prototype.hasOwnProperty,dPe=Object.prototype.propertyIsEnumerable,Ij=(t,e,r)=>e in t?aPe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lp=(t,e)=>{for(var r in e||(e={}))uPe.call(e,r)&&Ij(t,r,e[r]);if(_j)for(var r of _j(e))dPe.call(e,r)&&Ij(t,r,e[r]);return t},up=(t,e)=>cPe(t,lPe(e));function Rg({allUniqueParticipantIds:t=[],participantsProfile:e={},matchUpStatusProfile:r,completeAllMatchUps:n,autoEntryPositions:o,hydrateCollections:i,randomWinningSide:s,ratingsParameters:a,tournamentRecord:c,isMock:l=!0,drawProfile:u,startDate:d,drawIndex:p,uuids:v}){var f;const m=ue(u,!1,!0),{excessParticipantAlternates:g=!0,matchUpFormat:h=xl,drawType:_=zn,tournamentAlternates:I=0,alternatesCount:P=0,qualifyingPositions:O,qualifyingProfiles:y,generate:S=!0,eventExtensions:T,drawExtensions:E,completionGoal:b,tieFormatName:N,seedsCount:w,timeItems:$,drawName:U,category:A,idPrefix:M,publish:C,gender:D,stage:F}=m;let R=m.drawSize||(m.ignoreDefaults?void 0:32);const G=u.eventType||u.matchUpType||Hn,x=G===br?we:Me,z=typeof u.tieFormat=="object"&&u.tieFormat||G===Ye&&Es({namedFormat:N,event:{category:A,gender:D},hydrateCollections:i})||void 0,j=(A==null?void 0:A.categoryName)||(A==null?void 0:A.ageCategoryCode)||(A==null?void 0:A.ratingType);let V=u.eventName||j||`Generated ${G}`,L=(c==null?void 0:c.participants)||[];const q=((y==null?void 0:y.map(re=>re.structureProfiles||[]).flat().reduce((re,ae)=>{const me=!ae.participantsCount||ae.participantsCount>ae.drawSize?ae.drawSize:ae.participantsCount||0;return re+me},0))||0)*(x===br?2:1),k=(!u.participantsCount||u.participantsCount>R?R:u.participantsCount)||0,H=m.eventId||We();let Q={eventName:V,eventType:G,tieFormat:z,category:A,eventId:H,gender:D};Array.isArray($)&&$.forEach(re=>zo({event:Q,timeItem:re}));let{eventAttributes:K}=u;if(typeof K!="object"&&(K={}),Object.assign(Q,K),T!=null&&T.length&&Array.isArray(T)){const re=T.filter(on);re!=null&&re.length&&Object.assign(Q,{extensions:re})}const Y=[];if(q||u.uniqueParticipants||!c||D||A){const re=(k||0)+P+q;let ae=re;const me={[ct]:0,[mt]:0};let Se,ce;G===Ye&&({teamSize:Se,genders:ce}=X2({alternatesCount:P,tieFormatName:N,tieFormat:z,drawSize:R}),Object.keys(ce).forEach(Ue=>{[ct,mt].includes(Ue)&&ce[Ue]&&(me[Ue]=R*ce[Ue])}),ae=Se*((R||0)+q));const Pe=e!=null&&e.idPrefix?`D-${p}-${e==null?void 0:e.idPrefix}`:void 0,Ae=ap(up(lp({},e),{scaledParticipantsCount:u.scaledParticipantsCount||e.scaledParticipantsCount,participantsCount:ae,consideredDate:c==null?void 0:c.startDate,sex:D||(e==null?void 0:e.sex),rankingRange:u.rankingRange,uuids:u.uuids||v,ratingsParameters:a,participantType:x,gendersCount:me,idPrefix:Pe,category:A})),{participants:ye}=Ae;if(Q.category&&(Q.category.categoryName=j),c){const Ue=to({participants:ye,tournamentRecord:c});if(Ue.error)return Ue}if(ye.forEach(({participantId:Ue})=>Y.push(Ue)),L=ye,G===Ye){const Ue=ce[ct]?ye.filter(({participantType:ot,person:Ke})=>ot===Me&&Ke.sex===ct).map(Xe):[],be=ce[mt]?ye.filter(({participantType:ot,person:Ke})=>ot===Me&&Ke.sex===mt).map(Xe):[],ge=ye.filter(({participantType:ot})=>ot===Me).map(Xe).filter(ot=>!Ue.includes(ot)&&!be.includes(ot)),Ne=Se-(ce[ct]+ce[mt]);let De=0,he=0,ke=0;const je=le(0,re).map(ot=>{const Ke=be.slice(De,De+ce[mt]),At=Ue.slice(he,he+ce[ct]),rr=ge.slice(ke,ke+Ne);return De+=ce[mt],he+=ce[ct],ke+=Ne,{individualParticipantIds:[...Ke,...At,...rr],participantOtherName:`TM${ot+1}`,participantName:`Team ${ot+1}`,participantRole:qt,participantType:Ye,participantId:We()}}),Ze=to({participants:je,tournamentRecord:c});if(!Ze.success)return Ze;L=je}}const J=re=>{const{participantType:ae}=re;return G===Hn&&ae===Me||G===br&&ae===we?!0:G===Ye&&ae===Ye},te=re=>{var ae,me;if(!u.gender||((ae=re.person)==null?void 0:ae.sex)===u.gender||(me=re.individualParticipantIds)!=null&&me.some(Se=>{const ce=L.find(Pe=>Pe.participantId===Se);return ce&&te(ce)}))return!0},ne=L.filter(J).filter(te).filter(({participantId:re})=>!t.includes(re)),oe=ne.slice(0,k).map(re=>re.participantId);if(l&&(oe!=null&&oe.length)){const re=Qo({autoEntryPositions:o,entryStage:F,tournamentRecord:c,participantIds:oe,event:Q});if(re.error)return re}const se=q?ne.slice(k,k+q).map(re=>re.participantId):0;if(l&&(se!=null&&se.length)){let re=0,ae=1;const me=(ce,Pe)=>ce.stageSequence-Pe.stageSequence,Se=(ce,Pe)=>ce.roundTarget-Pe.roundTarget;for(const ce of y.sort(Se)){ae=ce.roundTarget||ae;let Pe=1,Ae;for(const ye of ce.structureProfiles.sort(me)){const be=(ye.drawSize||yp(ye.participantsCount))-(Ae||0),ge=se.slice(re,re+be),Ne=Qo({entryStage:Ie,entryStageSequence:Pe,autoEntryPositions:o,tournamentRecord:c,participantIds:ge,roundTarget:ae,event:Q});if(Ne.error)return Ne;Ae=ye.qualifyingPositions,re+=be,Pe+=1}ae+=1}}const ve=g&&((f=c==null?void 0:c.participants)==null?void 0:f.filter(({participantId:re})=>!oe.includes(re)).filter(J).filter(te).slice(0,P||R-k||I).map(re=>re.participantId));if(l&&(ve!=null&&ve.length)){const re=Qo({participantIds:ve,autoEntryPositions:!1,entryStatus:un,tournamentRecord:c,event:Q});if(re.error)return re.error}const X=j||V;c&&w&&w<=oe.length&&le(1,w+1).forEach((ae,me)=>{let Se={scaleName:X,scaleDate:d,scaleType:nP,scaleValue:ae,eventType:G};const ce=oe[me];fl({tournamentRecord:c,participantId:ce,scaleItem:Se})});const ie=$g(up(lp({},ue(u,!1,!0)),{tournamentRecord:c,seedingScaleName:X,matchUpFormat:h,eventId:H,isMock:l,event:Q}));if(ie.error)return ie;const{drawDefinition:fe}=ie,$e=fe.drawId;if(Array.isArray(E)&&E.filter(on).forEach(re=>tt({element:fe,extension:re})),S){if(Jc({drawDefinition:fe,event:Q,suppressNotifications:!0}),_===cn&&u.drawMatic){const ae=u.roundsCount||1;for(const me of le(1,ae+1)){const Se=bg({generateMatchUps:!0,tournamentRecord:c,drawDefinition:fe,roundNumber:me});if(Se.error)return Se}}if(u.withPlayoffs){const ae=fe.structures[0].structureId,me=Dd(up(lp({},u.withPlayoffs),{tournamentRecord:c,drawDefinition:fe,structureId:ae,idPrefix:M,isMock:l,event:Q}));if(me!=null&&me.error)return me}const re=u.automated===!1;if(l&&!re){const ae=({completionGoal:me,completeAllMatchUps:Se})=>{const ce=sp({matchUpStatusProfile:r,completeAllMatchUps:Se,qualifyingProfiles:y,randomWinningSide:s,tournamentRecord:c,completionGoal:me,drawDefinition:fe,matchUpFormat:h,event:Q});if(ce.error)return ce;const Pe=ce.completedCount;if(_===Io){const Ae=fe.structures.find(be=>be.stage===de);let ye=Cd({structureId:Ae.structureId,tournamentRecord:c,drawDefinition:fe,event:Q});const Ue=me?me-Pe:void 0;if(ye=sp({completionGoal:me?Ue:void 0,matchUpStatusProfile:r,completeAllMatchUps:Se,randomWinningSide:s,tournamentRecord:c,drawDefinition:fe,matchUpFormat:h,event:Q}),ye.error)return ye}};if(b&&ae({completionGoal:b}),u.outcomes){const{matchUps:me}=Dr({inContext:!0,drawDefinition:fe,event:Q});for(const Se of u.outcomes){const{matchUpStatus:ce=St,matchUpStatusCodes:Pe,stageSequence:Ae=1,matchUpIndex:ye=0,structureOrder:Ue,matchUpFormat:be,drawPositions:ge,roundPosition:Ne,stage:De=de,roundNumber:he,winningSide:ke,scoreString:je}=Se,Ze=me.reduce((Jt,To)=>{const{structureId:io,matchUpId:Mi}=To;return Jt[io]?Jt[io].push(Mi):Jt[io]=[Mi],Jt},{}),ot=Object.assign({},...Object.keys(Ze).map((Jt,To)=>({[Jt]:To+1}))),At=me.filter(Jt=>(!De||Jt.stage===De)&&(!Ae||Jt.stageSequence===Ae)&&(!he||Jt.roundNumber===he)&&(!Ne||Jt.roundPosition===Ne)&&(!Ue||ot[Jt.structureId]===Ue)&&(!ge||jt(ge,Jt.drawPositions).length===2))[ye],rr=q2({matchUpStatusCodes:Pe,tournamentRecord:c,drawDefinition:fe,targetMatchUp:At,matchUpFormat:be,matchUpStatus:ce,scoreString:je,winningSide:ke,drawId:$e});if(rr!=null&&rr.error)return rr}}n&&ae({completeAllMatchUps:n})}C&&ml({tournamentRecord:c,event:Q})}else{const re=Tg({drawEntries:fe.entries,drawName:U||_,qualifyingPositions:O,drawId:$e,event:Q,stage:F});if(re.error)return re}return up(lp({},B),{event:_e(Q),uniqueParticipantIds:Y,targetParticipants:L,drawDefinition:fe,eventId:H,drawId:$e})}function Pj({tournamentRecord:t,venueProfiles:e}){const{startDate:r,endDate:n}=t;let o=[];for(const[i,s]of e.entries()){let{venueAbbreviation:a,venueId:c=We(),dateAvailability:l,startTime:u="07:00",endTime:d="19:00",courtTimings:p,courtsCount:v,courtNames:f,venueName:m,idPrefix:g,courtIds:h}=s;const _={venueName:m||`Venue ${i+1}`,venueAbbreviation:a,venueId:c};let I=fc({tournamentRecord:t,venue:_});if(I.error)return I;o.push(c);const P=Gp(r,n),O=!Array.isArray(l)&&[{startTime:u,endTime:d}].concat(P.map(y=>({date:On(y),startTime:u,endTime:d})));if(I=ym({dateAvailability:l||O,tournamentRecord:t,courtTimings:p,courtsCount:v,courtNames:f,startTime:u,idPrefix:g,courtIds:h,endTime:d,venueId:c,dates:P}),I.error)return I}return o}var pPe=Object.defineProperty,fPe=Object.defineProperties,vPe=Object.getOwnPropertyDescriptors,yj=Object.getOwnPropertySymbols,mPe=Object.prototype.hasOwnProperty,gPe=Object.prototype.propertyIsEnumerable,Sj=(t,e,r)=>e in t?pPe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hPe=(t,e)=>{for(var r in e||(e={}))mPe.call(e,r)&&Sj(t,r,e[r]);if(yj)for(var r of yj(e))gPe.call(e,r)&&Sj(t,r,e[r]);return t},_Pe=(t,e)=>fPe(t,vPe(e));function IPe({ratingsParameters:t=Xn,participantsProfile:e={},matchUpStatusProfile:r,completeAllMatchUps:n,autoEntryPositions:o,hydrateCollections:i,randomWinningSide:s,schedulingProfile:a,tournamentRecord:c,eventProfiles:l,venueProfiles:u,autoSchedule:d,drawProfiles:p,uuids:v}){var f,m,g;if(!c)return{error:ee};const h=[],_=[],I=[];l==null||l.forEach(b=>{var N;const w=(N=c.events)==null?void 0:N.find(($,U)=>b.eventIndex!==void 0&&U===b.eventIndex||b.eventName&&$.eventName===b.eventName||b.eventId&&$.eventId===b.eventId);w!=null&&w.gender&&(b.gender=w.gender)});const P=((f=c.participants)==null?void 0:f.length)||void 0;P&&(e!=null&&e.idPrefix)&&(e.idPrefix=`${e.idPrefix}-${P}`);const O=oj({startDate:c.startDate,participantsProfile:e,tournamentRecord:c,eventProfiles:l,drawProfiles:p,uuids:v});if(!O.success)return O;if(l){let b=((m=c.events)==null?void 0:m.length)||0;for(const N of l){let{ratingsParameters:w}=N;const $=(g=c.events)==null?void 0:g.find((U,A)=>N.eventIndex!==void 0&&A===N.eventIndex||N.eventName&&U.eventName===N.eventName||N.eventId&&U.eventId===N.eventId);if($){const{gender:U,category:A,eventType:M}=$,{drawProfiles:C,publish:D}=N,F=M===Hn&&Me||M===br&&we||M;if(C){const{stageParticipantsCount:R,uniqueParticipantsCount:G,uniqueParticipantStages:x}=cj({drawProfiles:C,category:A,gender:U}),{uniqueDrawParticipants:z=[],uniqueParticipantIds:j=[]}=x?aj({event:{eventType:M,category:A,gender:U},uniqueParticipantsCount:G,participantsProfile:e,ratingsParameters:w,tournamentRecord:c,eventProfile:N,uuids:v}):{};h.push(...j);const{stageParticipants:V}=lj({targetParticipants:c.participants||[],allUniqueParticipantIds:h,stageParticipantsCount:R,eventParticipantType:F});let L=vj({uniqueDrawParticipants:z,autoEntryPositions:o,stageParticipants:V,tournamentRecord:c,drawProfiles:C,category:A,gender:U,event:$});if(L.error||(L=K2({matchUpStatusProfile:r,completeAllMatchUps:n,randomWinningSide:s,tournamentRecord:c,drawProfiles:C,event:$}),L.error))return L;I.push(...L.drawIds)}D&&ml({tournamentRecord:c,event:$})}else{const U=hj({startDate:c.startDate,allUniqueParticipantIds:h,matchUpStatusProfile:r,participantsProfile:e,completeAllMatchUps:n,autoEntryPositions:o,randomWinningSide:s,ratingsParameters:w,tournamentRecord:c,eventProfile:N,eventIndex:b,uuids:v});if(U.error)return U;const{eventId:A,drawIds:M,uniqueParticipantIds:C}=U;M&&I.push(...M),_.push(A),C!=null&&C.length&&h.push(...C),b+=1}}}if(p){let b=(c.events||[]).map(N=>{var w;return((w=N.drawDefinitions)==null?void 0:w.map(()=>1))||[]}).flat().reduce((N,w)=>N+w,0);for(const N of p){let w=Rg({startDate:c.startDate,allUniqueParticipantIds:h,matchUpStatusProfile:r,participantsProfile:e,completeAllMatchUps:n,autoEntryPositions:o,hydrateCollections:i,randomWinningSide:s,ratingsParameters:t,tournamentRecord:c,drawProfile:N,drawIndex:b,uuids:v});if(w.error)return w;const{drawId:$,eventId:U,event:A,uniqueParticipantIds:M}=w;if(w=np({tournamentRecord:c,event:A,internalUse:!0}),w.error)return w;$&&I.push($),_.push(U),M!=null&&M.length&&h.push(...M),b+=1}}const y=u!=null&&u.length?Pj({tournamentRecord:c,venueProfiles:u}):[];let S,T={};if(a!=null&&a.length){const b={[c.tournamentId]:c},N=rl({tournamentRecords:b,schedulingProfile:a});if(N.error)return N;if(d){const{tournamentId:w}=c,$={[w]:c};T=sm({tournamentRecords:$})}}const E=c.participants.length;return _Pe(hPe({totalParticipantsCount:E,scheduledRounds:S,schedulerResult:T},B),{eventIds:_,venueIds:y,drawIds:I})}const PPe={anonymizeTournamentRecord:Y_e,modifyTournamentRecord:IPe};var yPe=Object.defineProperty,Oj=Object.getOwnPropertySymbols,SPe=Object.prototype.hasOwnProperty,OPe=Object.prototype.propertyIsEnumerable,bj=(t,e,r)=>e in t?yPe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bPe=(t,e)=>{for(var r in e||(e={}))SPe.call(e,r)&&bj(t,r,e[r]);if(Oj)for(var r of Oj(e))OPe.call(e,r)&&bj(t,r,e[r]);return t};function TPe({schedulingProfile:t,tournamentRecord:e}){if(typeof t!="object")return{error:Z};const r=_a({tournamentRecord:e}).containedStructures,{matchUps:n}=Bt({tournamentRecord:e}),{tournamentId:o}=e,i=[];for(const s of t){const{scheduleDate:a,venues:c=[]}=s;for(const l of c){const{rounds:u,venueId:d}=l;for(const p of u){const{drawId:v,winnerFinishingPositionRange:f,roundSegment:m}=p,h=n.filter(_=>{var I;const P=(f==null?void 0:f.indexOf("-"))>0&&f.split("-").map(y=>+y),O=(I=_.finishingPositionRange)==null?void 0:I.winner;return _.drawId===v&&(!p.roundNumber||_.roundNumber===p.roundNumber)&&(!O||!P||jt(O,P).length===2||Ve(O).length===Ve(P).length&&jt(O,P).length===Ve(O).length)})[0];if(h){const{eventId:_,roundNumber:I,drawName:P,structureName:O,roundName:y}=h;let S=h.structureId;I&&!f&&(S=Object.keys(r).find(b=>r[b].includes(S))||S);const T={tournamentId:o,structureId:S,roundNumber:I,roundSegment:m,eventId:_,drawId:v};let E=OT({tournamentRecords:{[o]:e},round:T,scheduleDate:a,venueId:d});if(E.error)return E;i.push(bPe({structureName:O,roundName:y,drawName:P},T))}}}}return{scheduledRounds:i}}var EPe=Object.defineProperty,wPe=Object.defineProperties,$Pe=Object.getOwnPropertyDescriptors,Tj=Object.getOwnPropertySymbols,NPe=Object.prototype.hasOwnProperty,APe=Object.prototype.propertyIsEnumerable,Ej=(t,e,r)=>e in t?EPe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wj=(t,e)=>{for(var r in e||(e={}))NPe.call(e,r)&&Ej(t,r,e[r]);if(Tj)for(var r of Tj(e))APe.call(e,r)&&Ej(t,r,e[r]);return t},$j=(t,e)=>wPe(t,$Pe(e));function UPe({scheduleCompletedMatchUps:t,ratingsParameters:e=Xn,tournamentName:r="Mock Tournament",tournamentExtensions:n,tournamentAttributes:o,matchUpStatusProfile:i,participantsProfile:s,completeAllMatchUps:a,autoEntryPositions:c,hydrateCollections:l,randomWinningSide:u,policyDefinitions:d,schedulingProfile:p,eventProfiles:v,venueProfiles:f,drawProfiles:m,autoSchedule:g,startDate:h,endDate:_,uuids:I}={}){if(h&&!Nr(h)||_&&!Nr(_))return{error:cr};if(v&&!Array.isArray(v))return{error:Z};if(!h){const w=new Date;h=On(_||w),_=On(w.setDate(w.getDate()+7))}if(!_){const w=new Date(h);_=On(w.setDate(w.getDate()+7))}typeof o!="object"&&(o={});const P=lg($j(wj({},o),{tournamentName:r,startDate:h,endDate:_}));if(n!=null&&n.length&&Array.isArray(n)){const w=n.filter(on);w!=null&&w.length&&Object.assign(P,{extensions:w,isMock:!0})}if(typeof d=="object")for(const w of Object.keys(d))dm({policyDefinitions:{[w]:d[w]},tournamentRecord:P});const O=oj({participantsProfile:s,tournamentRecord:P,eventProfiles:v,drawProfiles:m,startDate:h,uuids:I});if(!O.success)return O;const y=[],S=[],T=[];if(Array.isArray(m)){let w=0;for(const $ of m){let U=Rg({allUniqueParticipantIds:T,matchUpStatusProfile:i,participantsProfile:s,completeAllMatchUps:a,autoEntryPositions:c,hydrateCollections:l,randomWinningSide:u,ratingsParameters:e,tournamentRecord:P,isMock:!0,drawProfile:$,startDate:h,drawIndex:w,uuids:I});if(U.error)return U;const{drawId:A,eventId:M,event:C,uniqueParticipantIds:D}=U;if(U=np({suppressNotifications:!1,internalUse:!0,tournamentRecord:P,event:C}),U.error)return U;A&&y.push(A),S.push(M),D!=null&&D.length&&T.push(...D),w+=1}}if(v){let w=0;for(const $ of v){const U=hj({allUniqueParticipantIds:T,matchUpStatusProfile:i,participantsProfile:s,completeAllMatchUps:a,autoEntryPositions:c,hydrateCollections:l,randomWinningSide:u,ratingsParameters:e,tournamentRecord:P,eventProfile:$,eventIndex:w,startDate:h,uuids:I});if(U.error)return U;const{eventId:A,drawIds:M,uniqueParticipantIds:C}=U;M&&y.push(...M),S.push(A),C!=null&&C.length&&T.push(...C),w+=1}}const E=f!=null&&f.length?Pj({tournamentRecord:P,venueProfiles:f,uuids:I}):[];let b,N={};if(p){const w=TPe({schedulingProfile:p,tournamentRecord:P});if(w.error)return w;if(b=w.scheduledRounds,g){const{tournamentId:$}=P,U={[$]:P};N=sm({scheduleCompletedMatchUps:t,tournamentRecords:U})}}return Za(),_e($j(wj({},B),{tournamentRecord:P,scheduledRounds:b,schedulerResult:N,eventIds:S,venueIds:E,drawIds:y}))}const CPe={generateOutcomeFromScoreString:k2,generateTournamentRecord:UPe,generateEventWithDraw:Rg,generateParticipants:ap,parseScoreString:Cu,generateOutcome:G2,credits:_d};var MPe=Object.defineProperty,Nj=Object.getOwnPropertySymbols,DPe=Object.prototype.hasOwnProperty,jPe=Object.prototype.propertyIsEnumerable,Aj=(t,e,r)=>e in t?MPe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,RPe=(t,e)=>{for(var r in e||(e={}))DPe.call(e,r)&&Aj(t,r,e[r]);if(Nj)for(var r of Nj(e))jPe.call(e,r)&&Aj(t,r,e[r]);return t};let Fg=!1;(function(){const t={version:()=>so(),setDeepCopy:(n,o)=>(Fi(n,o),t),devContext:n=>(xs(n),Fg=!0,t)};return r([PPe,CPe]),t;function e(n,o){const i=n(RPe({},o));return i!=null&&i.error||bi(),ii(),Fg&&(xs(!1),Fg=!1),i}function r(n){n.forEach(o=>{Object.keys(o).forEach(i=>{t[i]=s=>{try{return e(o[i],s)}catch(a){const c=a.toString();console.log("ERROR",{error:c,method:i,params:JSON.stringify(s)})}}})})}})();const Uj={hasAttributeValues:BL,extractAttributes:kL,structureSort:Ii,matchUpSort:vs,tidyScore:_H,generateScoreString:Jn,calculateWinCriteria:pa,compareTieFormats:Au,parseScoreString:Cu,scoreHasValue:Dt,getScaleValues:Js,proConflicts:gS,addExtension:tt,chunkArray:Rt,countValues:QR,dateRange:Gp,dateTime:nV,definedAttributes:_e,dehydrateMatchUps:CW,findExtension:Vt,garman:LW,getTimeItem:fn,generateHashCode:WL,generateRange:le,generateTimeCode:t_,instanceCount:mr,intersection:jt,isNumeric:Ot,isConvertableInteger:ut,isPowerOf2:Vr,JSON2CSV:oV,flattenJSON:Hp,makeDeepCopy:ue,nearestPowerOf2:Sp,nextPowerOf2:Ds,numericSort:Wt,overlap:Gt,parseAgeCategoryCode:bS,randomMember:gr,randomPop:ir,shuffleArray:or,isAdHoc:Po,unique:Ve,UUID:We,UUIDS:iV,validateTieFormat:ur},FPe=dt({WebkitBoxSizing:"border-box",display:"inline-block",boxSizing:"border-box",position:"relative",marginInlineStart:1,marginInlineEnd:2,borderRadius:2,variants:{variant:{doubles:{width:".75rem"},singles:{width:"1rem"}}}});function LPe({matchUp:t,individualParticipant:e,spacer:r}){var a,c,l;const n=((a=e==null?void 0:e.person)==null?void 0:a.iso2NationalityCode)||"",o=n?(c=k4.countryToFlag(n))==null?void 0:c.slice(0,4):"",i=document.createElement("span"),s=(l=t==null?void 0:t.matchUpType)==null?void 0:l.toLowerCase();return i.className=FPe({variant:s}),i.innerHTML=r?"":o,i}function dp({individualParticipant:t,composition:e,className:r,matchUp:n,spacer:o,side:i,type:s}){if(s==="scale")return VR({individualParticipant:t,composition:e,className:r,matchUp:n,spacer:o});const a=(e==null?void 0:e.configuration)||{},c=document.createElement("div");return s==="flag"&&a.flags&&LPe({className:r,matchUp:n,individualParticipant:t,spacer:o})||s==="seeding"&&jR({className:r,composition:e,matchUp:n,side:i})||c}function VPe({individualParticipant:t,composition:e,className:r,matchUp:n}){var l,u,d,p,v,f,m;const o=(l=e==null?void 0:e.configuration)==null?void 0:l.showAddress,i=(d=(u=t==null?void 0:t.person)==null?void 0:u.addresses)!=null&&d.length?Object.values(((v=(p=t.person)==null?void 0:p.addresses)==null?void 0:v[0])||{}).join(", "):" ";if(!o)return document.createElement("div");const s=(f=e==null?void 0:e.configuration)==null?void 0:f.scaleAttributes,a=(m=e==null?void 0:e.configuration)==null?void 0:m.flags,c=document.createElement("div");if(a||s){c.className=zg();const g=dp({type:a?"flag":"scale",individualParticipant:t,spacer:!0,composition:e,className:r,matchUp:n});c.appendChild(g);const h=document.createElement("div");h.className=Ms(Kg(),r),h.innerHTML=i,c.appendChild(h)}else c.className=Ms(Kg(),r),c.innerHTML=i;return c}const xPe="Qualifier",BPe="BYE",kPe="TBD";function Cj(t){var _;const{isWinningSide:e,side:r,individualParticipant:n,matchUp:o,composition:i}=t||{},s=e?"winner":void 0,a=t.eventHandlers||{},c=i==null?void 0:i.configuration,l=n==null?void 0:n.participantName,u=I=>{typeof(a==null?void 0:a.participantClick)=="function"&&(I.stopPropagation(),a.participantClick({individualParticipant:n,matchUp:o,event:I,side:r}))},d=document.createElement("div");d.onclick=u;const p=document.createElement("div");p.className=zg({variant:s});const f=(c==null?void 0:c.flags)&&dp({...t,type:"flag"});if(f)p.appendChild(f);else{const I=dp({type:"scale",...t});I&&p.appendChild(I)}const m=document.createElement("div");if(m.className=AR({variant:s}),l){const I=document.createElement("span");if(e&&(c!=null&&c.winnerColor))I.style.color=typeof c.winnerColor=="string"?c.winnerColor:"green";else if(c!=null&&c.genderColor){const P=(_=n==null?void 0:n.person)==null?void 0:_.sex,O=P==="MALE"&&"#2E86C1"||P==="FEMALE"&&"#AA336A"||"";I.style.color=typeof c.genderColor=="string"?c.genderColor:O}I.innerHTML=l,m.appendChild(I)}else{const I=document.createElement("abbr");I.className=NR({variant:c.showAddress?"showAddress":""}),I.innerHTML=(r==null?void 0:r.bye)&&BPe||(r==null?void 0:r.qualifier)&&xPe||kPe,m.appendChild(I)}const g=dp({...t,className:DR(),type:"seeding"});g&&m.appendChild(g),p.appendChild(m),d.appendChild(p);const h=VPe(t);return d.appendChild(h),d}const GPe=dt({width:"auto",display:"inline-block",textTransform:"uppercase",fontFamily:"Sharp Sans, Arial, sans-serif",fontSize:"0.625rem",lineHeight:"1rem",marginInline:"0.25rem 0.25rem",paddingInline:"0.25rem 0.25rem",fontWeight:700,borderRadius:"4px",color:"#fff",textAlign:"center",whiteSpace:"nowrap",variants:{variant:{defaulted:{backgroundColor:"#df164c"},retired:{backgroundColor:"#df164c"},walkover:{backgroundColor:"black"},double_walkover:{backgroundColor:"black"}}}});function WPe({matchUpStatus:t}){const e=t==null?void 0:t.toLowerCase(),r=["WALKOVER","DOUBLE_WALKOVER"].includes(t)?"WO":(t==null?void 0:t.slice(0,3))||"",n=document.createElement("div");n.className=GPe({variant:e});const o=document.createElement("abbr");return o.setAttribute("title",t),o.style.textDecoration="none",o.style.borderBottom="none",o.innerHTML=r,n.appendChild(o),n}const HPe=dt({marginInlineEnd:".5rem",backgroundColor:"pink",marginInlineStart:2,height:40,width:40});function qPe({teamLogo:t}){console.log({teamLogo:t});const e=document.createElement("div");return e.className=HPe(),e}const YPe=dt({flexDirection:"column",position:"relative",display:"flex"}),zPe=dt({alignItems:"stretch",display:"flex"}),KPe=dt({marginInlineEnd:".25rem",color:"green"});function QPe({dim:t="20px"}={}){const e=KPe();return`
|
|
26
|
+
<div style="line-height: 0;">
|
|
27
|
+
<svg height="${t}" viewBox="0 0 18 24" width="${t}" xmlns="http://www.w3.org/2000/svg" class="${e}" style="fill: currentcolor;">
|
|
28
|
+
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"></path>
|
|
29
|
+
</svg>
|
|
30
|
+
</div>
|
|
31
|
+
`}function Mj({eventHandlers:t,sideContainer:e,composition:r,sideNumber:n,matchUp:o,participant:i}){var E,b,N,w;const{winningSide:s,matchUpType:a,isRoundRobin:c,matchUpStatus:l}=o||{},u=r==null?void 0:r.configuration;let d,p;i||(p=(E=o==null?void 0:o.sides)==null?void 0:E.find($=>$.sideNumber===n),i=p==null?void 0:p.participant,d=u!=null&&u.allDrawPositions||u!=null&&u.drawPositions&&(p!=null&&p.drawPosition)&&((o==null?void 0:o.roundNumber)===1||p!=null&&p.participantFed||c)?p==null?void 0:p.drawPosition:"");const v=((b=i==null?void 0:i.individualParticipants)==null?void 0:b.length)===2||a==="DOUBLES",f=v?(N=i==null?void 0:i.individualParticipants)==null?void 0:N[0]:i,m=v&&((w=i==null?void 0:i.individualParticipants)==null?void 0:w[1]),g=n===s||l==="BYE"&&i,h=(u==null?void 0:u.winnerChevron)&&g,_=u==null?void 0:u.teamLogo,I=["RETIRED","DOUBLE_WALKOVER","WALKOVER","DEFAULTED"].includes(l)&&!g,P=u==null?void 0:u.gameScoreOnly,O=document.createElement("div");if(O.className=e&&CR({drawPosition:d,sideNumber:n}),_){const $=qPe({teamLogo:_});O.appendChild($)}const y=document.createElement("div");y.className=UR({variant:v?"doubles":"singles"});const S=document.createElement("div");S.className=MR({winnerChevron:h,isDoubles:v});const T=Cj({individualParticipant:f,eventHandlers:t,isWinningSide:g,composition:r,matchUp:o,side:p});if(S.appendChild(T),m){const $=Cj({individualParticipant:m,eventHandlers:t,isWinningSide:g,composition:r,matchUp:o,side:p});S.appendChild($)}if(y.appendChild(S),O.appendChild(y),e){const $=document.createElement("div");if(g&&!P){const U=QPe();typeof U=="string"?$.innerHTML=U:$.appendChild(U)}else if(I){const U=WPe({matchUpStatus:l});$.appendChild(U)}O.appendChild($)}return O}const JPe=dt({marginInlineStart:"1rem",overflowX:"auto",display:"flex"}),ZPe=dt({justifyContent:"space-around",marginInlineStart:"16px",marginInlineEnd:"16px",flexDirection:"column",display:"flex",width:"460px"}),Dj=dt({width:"$score$setWidth",display:"inline-block",fontSize:9,variants:{variant:{set:{textAlign:"center"},points:{marginInlineEnd:3}}}}),XPe=dt({transform:"translateY(-50%)",textTransform:"uppercase",backgroundColor:"#fff",position:"absolute",textAlign:"center",top:"calc(50%)",color:"#bbb",fontSize:0,right:4});function eye(){return dt({backgroundColor:"magenta",position:"absolute",opacity:"0.2",height:"100%",width:"100%",top:0})}const tye=dt({});function rye({configuration:t}){const e={backgroundColor:"$matchUpBackgroundColor",WebkitTransition:"all 0.30s linear",boxShadow:"$matchUp$boxShadow",transition:"all 0.30s linear",border:"solid $border",marginBottom:"$space$1",marginTop:"$space$1",position:"relative",display:"grid",width:"100%",borderInlineStartWidth:"$borderWidths$borderInlineStart"};if(t!=null&&t.matchUpHover){const r=typeof t.matchUpHover=="string"?t.matchUpHover:"cyan";e["&:hover"]={backgroundColor:r}}else e["&:hover"]={borderColor:"$borderHover"};return dt(e)}function nye({variant:t}){return dt({borderBottom:"solid 1px lightgray",backgroundColor:"$matchUp",position:"relative",width:"100%",height:"$lineHeights$centerInfo",variants:{variant:{1:{borderBottom:"solid 1px black"},2:{borderBottom:"solid 1px lightgray"}}}})({variant:t})}const oye=dt({justifyContent:"center",alignContent:"center",flexDirection:"column",height:"100%",display:"flex"}),iye=dt({fontFamily:"Lato,Arial,Helvetica,sans-serif",WebkitFontSmooting:"antialiased",marginInlineStart:"calc(20%)",WebkitBoxOrient:"horizontal",WebKitBoxDirection:"normal",WebkitBoxPack:"center",boxSizing:"inherit",flexDirection:"row",display:"flex"}),jj=dt({alignContent:"center",boxSizing:"inherit",fontFamily:"Lato",fontWeight:900,fontSize:9});function sye({eventHandlers:t,entryStatus:e,sideNumber:r,className:n}){const o=document.createElement("div");o.onclick=t==null?void 0:t.centerInfoClick,o.className=Ms(nye({variant:r}),n);const i=document.createElement("div");i.className=oye();const s=document.createElement("div");s.className=iye();const a=document.createElement("div");a.className=jj(),a.innerHTML=e?"Entry status: ":"",s.appendChild(a);const c=document.createElement("div");return c.className=jj(),c.innerHTML=e||"",s.appendChild(c),i.appendChild(s),o.appendChild(i),o}const Rj={scheduleInfo:1.8,centerInfo:1.5,gameScore:2};function aye({composition:t,isDoubles:e,roundFactor:r=1}){const n=parseInt(window.getComputedStyle(document.body).getPropertyValue("font-size")),o=(t==null?void 0:t.configuration)||{},i=(o==null?void 0:o.connectorWidth)||16,s=o.centerInfo?Rj.centerInfo*n:0,a=o.scheduleInfo?Rj.scheduleInfo*n:0,l=(60+(o.showAddress?n:0))*(e?1.3:1)+s,u=l*r,d=(l+a)*r;return dt({"&::before":{borderBlockStart:"$borderWidths$matchUp solid #999",left:-i,width:i,position:"absolute",borderRadius:2,top:-1},"&::after":{width:i,position:"absolute",borderRadius:2,left:"100%"},"&::after, &::before":{borderWidth:"$borderWidths$matchUp",borderColor:"$connector",display:"block",content:""},variants:{isFirstRound:{true:{"&::before":{height:0,width:0,borderWidth:0}}},link:{m1:{"&::after":{borderInlineEnd:"$borderWidths$matchUp solid $connector",borderTopStyle:"solid",height:u,top:-1}},m2:{"&::after":{bottom:"calc(100%)",borderInlineEnd:"$borderWidths$matchUp solid $connector",borderBottomStyle:"solid",height:d}},m0:{"&::after":{borderTopStyle:"solid",borderColor:"$connector",top:-1}},mr:{"&::before":{height:0,width:0,borderWidth:0},"&::after":{height:0,width:0,borderWidth:0}},noProgression:{true:{"&::after":{height:0,width:0,borderWidth:0}}}}}})}const Fj=t=>dt({display:"flex",alignItems:"center",height:t,justifyContent:"flex-end",backgroundColor:"$matchUp",variants:{sideNumber:{1:{borderBottom:"1px solid $internalDividers"}},fontSize:{small:{fontSize:"smaller",paddingRight:"1em",color:"blue"}}}}),cye=dt({letterSpacing:"-0.2em",lineHeight:"0.75rem",position:"absolute",fontSize:"0.625rem",left:"1.1rem",top:".4rem"}),lye=dt({lineHeight:"$lineHeights$gameScore",justifyContent:"center",width:"$score$setWidth",position:"relative",textAlign:"center",cursor:"pointer",fontWeight:500,fontSize:"$1",display:"flex",margin:0,variants:{variant:{winner:{color:"$winner!important",fontWeight:700},loser:{color:"$loser!important"}}}}),uye=dt({marginInlineEnd:"$space$gameMarginInlineEnd",justifyContent:"flex-end",alignItems:"center",display:"flex"});function dye({gameScoreOnly:t,scoreStripes:e,set:r,sideNumber:n}){const i=n===(r==null?void 0:r.winningSide)||r!=null&&r.winningSide?"loser":void 0,s=n===2?r.side2Score:r.side1Score,a=n===2?r.side2TiebreakScore:r.side1TiebreakScore,c=s===void 0&&a,l=c||s,u=e&&r.setNumber%2?"lightgray":"transparent",d=document.createElement("p");if(d.className=lye({variant:i}),d.style.backgroundColor=u,d.innerHTML=isNaN(l)?"":l,!t){const p=document.createElement("span");p.className=cye(),p.innerHTML=c?a:"",d.appendChild(p)}return d}function pye({participantHeight:t,eventHandlers:e,composition:r,sideNumber:n,matchUp:o}){var f,m,g,h;const i=(f=r==null?void 0:r.configuration)==null?void 0:f.winnerChevron,s=(m=r==null?void 0:r.configuration)==null?void 0:m.gameScoreOnly,a=((g=o==null?void 0:o.score)==null?void 0:g.sets)||[],c=(h=r==null?void 0:r.configuration)==null?void 0:h.scoreBox,l=n===2?t:t-1,u=Fj(l),d=_=>{typeof(e==null?void 0:e.scoreClick)=="function"&&(_.stopPropagation(),e.scoreClick({event:_,matchUp:o}))},p=document.createElement("div");p.className=u({sideNumber:!c&&n,fontSize:"5px"}),p.onclick=d;const v=document.createElement("div");v.className=uye();for(const _ of a||[]){const I=dye({gameScoreOnly:s,scoreStripes:i,sideNumber:n,set:_});v.appendChild(I)}return p.appendChild(v),p}const fye=dt({height:"$lineHeights$scheduleInfo",borderBottom:"1px solid darkgray",justifyContent:"space-between",backgroundColor:"#F8F9F9",boxSizing:"border-box",paddingRight:"0.5rem",paddingLeft:"0.5rem",alignItems:"center",cursor:"pointer",color:"#7F8080",display:"flex",width:"100%"});var Lj={exports:{}};(function(t,e){(function(r,n){t.exports=n()})(FR,function(){var r=1e3,n=6e4,o=36e5,i="millisecond",s="second",a="minute",c="hour",l="day",u="week",d="month",p="quarter",v="year",f="date",m="Invalid Date",g=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,h=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,_={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function($){var U=["th","st","nd","rd"],A=$%100;return"["+$+(U[(A-20)%10]||U[A]||U[0])+"]"}},I=function($,U,A){var M=String($);return!M||M.length>=U?$:""+Array(U+1-M.length).join(A)+$},P={s:I,z:function($){var U=-$.utcOffset(),A=Math.abs(U),M=Math.floor(A/60),C=A%60;return(U<=0?"+":"-")+I(M,2,"0")+":"+I(C,2,"0")},m:function $(U,A){if(U.date()<A.date())return-$(A,U);var M=12*(A.year()-U.year())+(A.month()-U.month()),C=U.clone().add(M,d),D=A-C<0,F=U.clone().add(M+(D?-1:1),d);return+(-(M+(A-C)/(D?C-F:F-C))||0)},a:function($){return $<0?Math.ceil($)||0:Math.floor($)},p:function($){return{M:d,y:v,w:u,d:l,D:f,h:c,m:a,s,ms:i,Q:p}[$]||String($||"").toLowerCase().replace(/s$/,"")},u:function($){return $===void 0}},O="en",y={};y[O]=_;var S=function($){return $ instanceof N},T=function $(U,A,M){var C;if(!U)return O;if(typeof U=="string"){var D=U.toLowerCase();y[D]&&(C=D),A&&(y[D]=A,C=D);var F=U.split("-");if(!C&&F.length>1)return $(F[0])}else{var R=U.name;y[R]=U,C=R}return!M&&C&&(O=C),C||!M&&O},E=function($,U){if(S($))return $.clone();var A=typeof U=="object"?U:{};return A.date=$,A.args=arguments,new N(A)},b=P;b.l=T,b.i=S,b.w=function($,U){return E($,{locale:U.$L,utc:U.$u,x:U.$x,$offset:U.$offset})};var N=function(){function $(A){this.$L=T(A.locale,null,!0),this.parse(A)}var U=$.prototype;return U.parse=function(A){this.$d=function(M){var C=M.date,D=M.utc;if(C===null)return new Date(NaN);if(b.u(C))return new Date;if(C instanceof Date)return new Date(C);if(typeof C=="string"&&!/Z$/i.test(C)){var F=C.match(g);if(F){var R=F[2]-1||0,G=(F[7]||"0").substring(0,3);return D?new Date(Date.UTC(F[1],R,F[3]||1,F[4]||0,F[5]||0,F[6]||0,G)):new Date(F[1],R,F[3]||1,F[4]||0,F[5]||0,F[6]||0,G)}}return new Date(C)}(A),this.$x=A.x||{},this.init()},U.init=function(){var A=this.$d;this.$y=A.getFullYear(),this.$M=A.getMonth(),this.$D=A.getDate(),this.$W=A.getDay(),this.$H=A.getHours(),this.$m=A.getMinutes(),this.$s=A.getSeconds(),this.$ms=A.getMilliseconds()},U.$utils=function(){return b},U.isValid=function(){return this.$d.toString()!==m},U.isSame=function(A,M){var C=E(A);return this.startOf(M)<=C&&C<=this.endOf(M)},U.isAfter=function(A,M){return E(A)<this.startOf(M)},U.isBefore=function(A,M){return this.endOf(M)<E(A)},U.$g=function(A,M,C){return b.u(A)?this[M]:this.set(C,A)},U.unix=function(){return Math.floor(this.valueOf()/1e3)},U.valueOf=function(){return this.$d.getTime()},U.startOf=function(A,M){var C=this,D=!!b.u(M)||M,F=b.p(A),R=function(k,H){var Q=b.w(C.$u?Date.UTC(C.$y,H,k):new Date(C.$y,H,k),C);return D?Q:Q.endOf(l)},G=function(k,H){return b.w(C.toDate()[k].apply(C.toDate("s"),(D?[0,0,0,0]:[23,59,59,999]).slice(H)),C)},x=this.$W,z=this.$M,j=this.$D,V="set"+(this.$u?"UTC":"");switch(F){case v:return D?R(1,0):R(31,11);case d:return D?R(1,z):R(0,z+1);case u:var L=this.$locale().weekStart||0,q=(x<L?x+7:x)-L;return R(D?j-q:j+(6-q),z);case l:case f:return G(V+"Hours",0);case c:return G(V+"Minutes",1);case a:return G(V+"Seconds",2);case s:return G(V+"Milliseconds",3);default:return this.clone()}},U.endOf=function(A){return this.startOf(A,!1)},U.$set=function(A,M){var C,D=b.p(A),F="set"+(this.$u?"UTC":""),R=(C={},C[l]=F+"Date",C[f]=F+"Date",C[d]=F+"Month",C[v]=F+"FullYear",C[c]=F+"Hours",C[a]=F+"Minutes",C[s]=F+"Seconds",C[i]=F+"Milliseconds",C)[D],G=D===l?this.$D+(M-this.$W):M;if(D===d||D===v){var x=this.clone().set(f,1);x.$d[R](G),x.init(),this.$d=x.set(f,Math.min(this.$D,x.daysInMonth())).$d}else R&&this.$d[R](G);return this.init(),this},U.set=function(A,M){return this.clone().$set(A,M)},U.get=function(A){return this[b.p(A)]()},U.add=function(A,M){var C,D=this;A=Number(A);var F=b.p(M),R=function(z){var j=E(D);return b.w(j.date(j.date()+Math.round(z*A)),D)};if(F===d)return this.set(d,this.$M+A);if(F===v)return this.set(v,this.$y+A);if(F===l)return R(1);if(F===u)return R(7);var G=(C={},C[a]=n,C[c]=o,C[s]=r,C)[F]||1,x=this.$d.getTime()+A*G;return b.w(x,this)},U.subtract=function(A,M){return this.add(-1*A,M)},U.format=function(A){var M=this,C=this.$locale();if(!this.isValid())return C.invalidDate||m;var D=A||"YYYY-MM-DDTHH:mm:ssZ",F=b.z(this),R=this.$H,G=this.$m,x=this.$M,z=C.weekdays,j=C.months,V=C.meridiem,L=function(H,Q,K,Y){return H&&(H[Q]||H(M,D))||K[Q].slice(0,Y)},q=function(H){return b.s(R%12||12,H,"0")},k=V||function(H,Q,K){var Y=H<12?"AM":"PM";return K?Y.toLowerCase():Y};return D.replace(h,function(H,Q){return Q||function(K){switch(K){case"YY":return String(M.$y).slice(-2);case"YYYY":return b.s(M.$y,4,"0");case"M":return x+1;case"MM":return b.s(x+1,2,"0");case"MMM":return L(C.monthsShort,x,j,3);case"MMMM":return L(j,x);case"D":return M.$D;case"DD":return b.s(M.$D,2,"0");case"d":return String(M.$W);case"dd":return L(C.weekdaysMin,M.$W,z,2);case"ddd":return L(C.weekdaysShort,M.$W,z,3);case"dddd":return z[M.$W];case"H":return String(R);case"HH":return b.s(R,2,"0");case"h":return q(1);case"hh":return q(2);case"a":return k(R,G,!0);case"A":return k(R,G,!1);case"m":return String(G);case"mm":return b.s(G,2,"0");case"s":return String(M.$s);case"ss":return b.s(M.$s,2,"0");case"SSS":return b.s(M.$ms,3,"0");case"Z":return F}return null}(H)||F.replace(":","")})},U.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},U.diff=function(A,M,C){var D,F=this,R=b.p(M),G=E(A),x=(G.utcOffset()-this.utcOffset())*n,z=this-G,j=function(){return b.m(F,G)};switch(R){case v:D=j()/12;break;case d:D=j();break;case p:D=j()/3;break;case u:D=(z-x)/6048e5;break;case l:D=(z-x)/864e5;break;case c:D=z/o;break;case a:D=z/n;break;case s:D=z/r;break;default:D=z}return C?D:b.a(D)},U.daysInMonth=function(){return this.endOf(d).$D},U.$locale=function(){return y[this.$L]},U.locale=function(A,M){if(!A)return this.$L;var C=this.clone(),D=T(A,M,!0);return D&&(C.$L=D),C},U.clone=function(){return b.w(this.$d,this)},U.toDate=function(){return new Date(this.valueOf())},U.toJSON=function(){return this.isValid()?this.toISOString():null},U.toISOString=function(){return this.$d.toISOString()},U.toString=function(){return this.$d.toUTCString()},$}(),w=N.prototype;return E.prototype=w,[["$ms",i],["$s",s],["$m",a],["$H",c],["$W",l],["$M",d],["$y",v],["$D",f]].forEach(function($){w[$[1]]=function(U){return this.$g(U,$[0],$[1])}}),E.extend=function($,U){return $.$i||($(U,N,E),$.$i=!0),E},E.locale=T,E.isDayjs=S,E.unix=function($){return E(1e3*$)},E.en=y[O],E.Ls=y,E.p={},E})})(Lj);var vye=Lj.exports;const mye=Qg(vye);function gye({matchUp:t,eventHandlers:e}){const{scheduledTime:r,scheduledDate:n,venueAbbreviation:o,courtName:i}=(t==null?void 0:t.schedule)||{},{dateTime:{extractDate:s,extractTime:a}}=Uj,c=a(r);let u=s(n),d="ddd D MMMM";c&&(d+=", hh:mm A",u+=`T${c}`);const p=n?mye(u).format(d):"Not scheduled",v=o&&(i==null?void 0:i.toString().startsWith(o))&&i||o&&i&&`${o} ${i}`||i||o||"",f=document.createElement("div");f.className=fye(),f.onclick=e==null?void 0:e.scheduleClick;const m=document.createElement("div");m.innerHTML=p,f.append(m);const g=_=>{typeof(e==null?void 0:e.venueClick)=="function"&&(_.stopPropagation(),e.venueClick({matchUp:t,event:_}))},h=document.createElement("div");return h.onclick=g,h.innerHTML=v,f.append(h),f}function Vj({eventHandlers:t,composition:e,sideNumber:r,className:n,matchUp:o}){var v,f;const i=(e==null?void 0:e.configuration)||{},s=i==null?void 0:i.scheduleInfo,a=(v=o==null?void 0:o.score)==null?void 0:v.scoreStringSide1,c=((f=e==null?void 0:e.configuration)==null?void 0:f.scoreBox)&&a,l=(o==null?void 0:o.readyToScore)&&(t==null?void 0:t.scoreClick)&&!Uj.scoreHasValue({matchUp:o}),u=document.createElement("div");if(u.className=Ms(YPe(),n),s&&r===1){const m=gye({matchUp:o,eventHandlers:t});u.appendChild(m)}const d=document.createElement("div");d.className=zPe();const p=Mj({sideContainer:!0,eventHandlers:t,composition:e,sideNumber:r,matchUp:o});if(d.appendChild(p),c){const m=document.createElement("div");m.style.border="1px solid lightgray",d.appendChild(m)}if(a){const m=pye({eventHandlers:t,composition:e,sideNumber:r,matchUp:o});d.appendChild(m)}if(l){const m=Fj(),g=_=>{typeof(t==null?void 0:t.scoreClick)=="function"&&(_.stopPropagation(),t.scoreClick({event:_,matchUp:o}))},h=document.createElement("div");h.className=m({sideNumber:!c&&r,fontSize:"small"}),h.onclick=g,h.innerHTML="[Score]",d.appendChild(h)}return u.appendChild(d),u}function xj(t){const{composition:e,matchUp:r,moeity:n,selectedMatchUpId:o,searchActive:i}=t,{roundFactor:s,roundNumber:a,finishingRound:c,matchUpType:l,preFeedRound:u,stage:d}=r,p=d==="QUALIFYING",v=parseInt(c)===1,f=d==="QUALIFYING"&&v,m=!p&&v,g=parseInt(a)===1,h=l==="DOUBLES",_=(i||r.isRoundRobin||r.collectionId||t.isLucky)&&"mr"||m&&"noProgression"||(f||u)&&"m0"||n&&"m1"||"m2",I=aye({composition:e,isDoubles:h,roundFactor:s})({isFirstRound:g,link:_}),P=(e==null?void 0:e.configuration)||{},{resultsInfo:O,centerInfo:y}=P||{},S=t.eventHandlers||{},T=U=>{typeof(S==null?void 0:S.matchUpClick)=="function"&&S.matchUpClick({event:U,matchUp:r})},E=document.createElement("div");E.className=Ms(e.theme,t==null?void 0:t.className,"matchup",tye()),E.onclick=T;const b=document.createElement("div");b.className=rye({configuration:P});const N=({sideNumber:U})=>{var C,D,F;const A=(F=(D=(C=r==null?void 0:r.sides.find(R=>R.sideNumber===U))==null?void 0:C.participant)==null?void 0:D.entryStatus)==null?void 0:F.replace("_"," ");return sye({eventHandlers:S,entryStatus:A,sideNumber:U,className:U===2&&I})},w=Vj({sideNumber:1,eventHandlers:S,composition:e,matchUp:r}),$=Vj({className:!y&&I,sideNumber:2,eventHandlers:S,composition:e,matchUp:r});if(b.appendChild(w),y&&(b.appendChild(N({sideNumber:1})),b.appendChild(N({sideNumber:2}))),b.appendChild($),O){const U=hye({score:r.score});b.appendChild(U)}if(E.appendChild(b),o===r.matchUpId){const U=document.createElement("div");U.className=eye(),E.appendChild(U)}return E}function hye({score:t}){var i;const e=(i=t==null?void 0:t.sets)==null?void 0:i.filter(Boolean).sort((s,a)=>(s.setNumber||0)-(a.setNumber||0)),r=e==null?void 0:e[e.length-1],n=(r==null?void 0:r.side1PointsScore)||(r==null?void 0:r.side2PointsScore),o=document.createElement("div");if(o.className=XPe(),n){const s=document.createElement("div");s.className=Dj({variant:"points"}),s.innerHTML="PTS",o.appendChild(s)}for(const s of e||[]){const a=document.createElement("div");a.setAttribute("key",s.setNumber),a.className=Dj({variant:"set"}),a.innerHTML=s.setNumber,o.appendChild(a)}return o}function _ye({selectedMatchUpId:t,eventHandlers:e,searchActive:r,composition:n,roundFactor:o,roundNumber:i,matchUps:s,isLucky:a}){const c=s.filter(u=>u.roundNumber===i).sort((u,d)=>(u.roundPosition||0)-(d.roundPosition||0)),l=document.createElement("div");return l.className=ZPe(),c.forEach((u,d)=>{const p=d%2===0;o&&(u.roundFactor=o);const v=xj({selectedMatchUpId:t,eventHandlers:e,searchActive:r,composition:n,matchUp:u,isLucky:a,moeity:p});l.appendChild(v)}),l}function Iye({selectedMatchUpId:t,eventHandlers:e,searchActive:r,composition:n,matchUps:o}){const{roundNumbers:i,hasOddMatchUpsCount:s}=mse.getRoundMatchUps({matchUps:o}),a=s,c=document.createElement("div");c.className=JPe();for(const l of i){const u=_ye({selectedMatchUpId:t,eventHandlers:e,searchActive:r,composition:n,roundNumber:l,matchUps:o,isLucky:a});c.appendChild(u)}return c}ti.renderMatchUp=xj,ti.renderParticipant=Mj,ti.renderStructure=Iye,Object.defineProperty(ti,Symbol.toStringTag,{value:"Module"})});
|