courthive-components 3.12.2 → 3.13.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.
@@ -211,24 +211,24 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
211
211
  `,`Instead, pass the .innerHTML of the element, or use a function that`,`returns a cloned version of the element instead.`,`
212
212
 
213
213
  `,`1) content: element.innerHTML
214
- `,`2) content: () => element.cloneNode(true)`].join(` `))}var s=i.reduce(function(e,t){var n=t&&Om(t,r);return n&&e.push(n),e},[]);return Rp(e)?s[0]:s}km.defaultProps=fm,km.setDefaultProps=mm,km.currentInput=Yp,Object.assign({},Hd,{effect:function(e){var t=e.state,n={popper:{position:t.options.strategy,left:`0`,top:`0`,margin:`0`},arrow:{position:`absolute`},reference:{}};Object.assign(t.elements.popper.style,n.popper),t.styles=n,t.elements.arrow&&Object.assign(t.elements.arrow.style,n.arrow)}}),km.setDefaultProps({render:wm});var Am=`#000000.#434343.#666666.#999999.#b7b7b7.#cccccc.#d9d9d9.#ffffff.#980000.#ff0000.#ff9900.#ffff00.#00ff00.#00ffff.#4a86e8.#0000ff.#9900ff.#ff00ff.#e6b8af.#f4cccc.#fce5cd.#fff2cc.#d9ead3.#d0e0e3.#c9daf8.#cfe2f3.#d9d2e9.#ead1dc`.split(`.`),jm=`notes-toolbar-recent-colors`,Mm=8;function Nm(){try{return JSON.parse(localStorage.getItem(jm)||`[]`)}catch{return[]}}function Pm(e){let t=Nm().filter(t=>t!==e);t.unshift(e),t.length>Mm&&(t=t.slice(0,Mm)),localStorage.setItem(jm,JSON.stringify(t))}function Fm(e={}){let t=document.createElement(`div`);return t.className=`notes-toolbar`,t.appendChild(Bm(e)),t.appendChild(Vm(e)),t.appendChild(Hm(e)),t.appendChild(Km(e)),t.appendChild(Ym(e)),t.appendChild(Xm(e)),t.appendChild(Qm(e)),t}function Im(e,t){for(let[n,r]of Object.entries(t)){let t=e.querySelector(`[data-action="${n}"]`);t&&t.classList.toggle(`is-active`,r)}}function Lm(e,t){let n=e.querySelector(`[data-action="heading"]`);n&&(n.value=t===!1?`0`:String(t))}function Rm(){let e=document.createElement(`div`);return e.className=`notes-toolbar-group`,e}function zm(e,t,n,r){let i=document.createElement(`button`);return i.className=`notes-toolbar-btn`,i.dataset.action=e,i.title=n,i.type=`button`,i.innerHTML=t,r&&i.addEventListener(`click`,r),i}function Bm(e){let t=Rm(),n=document.createElement(`select`);n.dataset.action=`heading`,n.title=`Text style`;for(let e of[{value:`0`,label:`Paragraph`},{value:`1`,label:`Heading 1`},{value:`2`,label:`Heading 2`},{value:`3`,label:`Heading 3`},{value:`4`,label:`Heading 4`},{value:`5`,label:`Heading 5`},{value:`6`,label:`Heading 6`}]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,n.appendChild(t)}return n.addEventListener(`change`,()=>{let t=parseInt(n.value,10);e.onHeading?.(t!==0&&t)}),t.appendChild(n),t}function Vm(e){let t=Rm();return t.appendChild(zm(`bold`,`<b>B</b>`,`Bold`,e.onBold)),t.appendChild(zm(`italic`,`<i>I</i>`,`Italic`,e.onItalic)),t.appendChild(zm(`underline`,`<u>U</u>`,`Underline`,e.onUnderline)),t.appendChild(zm(`strike`,`<s>S</s>`,`Strikethrough`,e.onStrike)),t}function Hm(e){let t=Rm();return t.appendChild(Um(`color`,`A`,`Text color`,`#000000`,t=>{Pm(t),e.onColor?.(t)})),t.appendChild(Um(`background`,`A`,`Background color`,`#ffff00`,t=>{Pm(t),e.onBackground?.(t)})),t}function Um(e,t,n,r,i){let a=document.createElement(`button`);a.className=`notes-toolbar-btn notes-toolbar-color-btn`,a.dataset.action=e,a.title=n,a.type=`button`;let o=document.createElement(`span`);o.className=`notes-toolbar-color-letter`,o.textContent=t,a.appendChild(o);let s=document.createElement(`span`);s.className=`notes-toolbar-color-bar`,s.style.backgroundColor=r,a.appendChild(s);let c;return a.addEventListener(`click`,()=>{if(c){c.destroy(),c=void 0;return}let e=Wm(r,e=>{s.style.backgroundColor=e,i(e),c?.destroy(),c=void 0});c=km(a,{content:e,theme:`light-border`,trigger:`manual`,interactive:!0,placement:`bottom-start`,onHidden:()=>{c?.destroy(),c=void 0}}),c.show()}),a}function Wm(e,t){let n=document.createElement(`div`);n.className=`notes-color-panel`;let r=document.createElement(`div`);r.className=`notes-color-swatches`;for(let n of Am)r.appendChild(Gm(n,n===e,t));n.appendChild(r);let i=Nm();if(i.length){let r=document.createElement(`div`);r.className=`notes-color-section-label`,r.textContent=`Recent`,n.appendChild(r);let a=document.createElement(`div`);a.className=`notes-color-swatches`;for(let n of i)a.appendChild(Gm(n,n===e,t));n.appendChild(a)}let a=document.createElement(`div`);a.className=`notes-color-custom-row`;let o=document.createElement(`input`);o.type=`color`,o.value=e,o.className=`notes-color-custom-input`;let s=document.createElement(`label`);return s.className=`notes-color-custom-label`,s.textContent=`Custom...`,s.addEventListener(`click`,()=>o.click()),o.addEventListener(`input`,()=>t(o.value)),a.appendChild(o),a.appendChild(s),n.appendChild(a),n}function Gm(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`notes-color-swatch`,t&&r.classList.add(`is-selected`),r.style.backgroundColor=e,(e===`#ffffff`||e===`#fff`)&&(r.style.border=`1px solid var(--chc-border-secondary)`),r.title=e,r.addEventListener(`click`,()=>n(e)),r}function Km(e){let t=Rm();return t.appendChild(zm(`orderedList`,qm(16,16,`<path d="M3 2h12v2H3zm0 5h12v2H3zm0 5h12v2H3z" fill="currentColor"/><text x="0" y="4" font-size="3.5" fill="currentColor">1</text><text x="0" y="9" font-size="3.5" fill="currentColor">2</text><text x="0" y="14" font-size="3.5" fill="currentColor">3</text>`),`Ordered list`,e.onOrderedList)),t.appendChild(zm(`bulletList`,qm(16,16,`<circle cx="1.5" cy="3" r="1.5" fill="currentColor"/><circle cx="1.5" cy="8" r="1.5" fill="currentColor"/><circle cx="1.5" cy="13" r="1.5" fill="currentColor"/><path d="M5 2h10v2H5zm0 5h10v2H5zm0 5h10v2H5z" fill="currentColor"/>`),`Bullet list`,e.onBulletList)),t}function qm(e,t,n){return`<svg width="${e}" height="${t}" viewBox="0 0 ${e} ${t}" xmlns="http://www.w3.org/2000/svg">${n}</svg>`}var Jm={alignLeft:qm(16,16,`<path d="M1 2h14v2H1zm0 4h9v2H1zm0 4h14v2H1zm0 4h9v2H1z" fill="currentColor"/>`),alignCenter:qm(16,16,`<path d="M1 2h14v2H1zm3.5 4h7v2h-7zM1 10h14v2H1zm3.5 4h7v2h-7z" fill="currentColor"/>`),alignRight:qm(16,16,`<path d="M1 2h14v2H1zm6 4h8v2H7zM1 10h14v2H1zm6 4h8v2H7z" fill="currentColor"/>`),alignJustify:qm(16,16,`<path d="M1 2h14v2H1zm0 4h14v2H1zm0 4h14v2H1zm0 4h14v2H1z" fill="currentColor"/>`)};function Ym(e){let t=Rm();return t.appendChild(zm(`alignLeft`,Jm.alignLeft,`Align left`,()=>e.onAlign?.(`left`))),t.appendChild(zm(`alignCenter`,Jm.alignCenter,`Align center`,()=>e.onAlign?.(`center`))),t.appendChild(zm(`alignRight`,Jm.alignRight,`Align right`,()=>e.onAlign?.(`right`))),t.appendChild(zm(`alignJustify`,Jm.alignJustify,`Justify`,()=>e.onAlign?.(`justify`))),t}function Xm(e){let t=Rm();t.appendChild(zm(`blockquote`,`“`,`Blockquote`,e.onBlockquote)),t.appendChild(zm(`codeBlock`,`</>`,`Code block`,e.onCodeBlock));let n=zm(`link`,`⇗`,`Insert link`);Zm(n,`Enter URL`,`https://`,t=>e.onLink?.(t)),t.appendChild(n);let r=zm(`video`,`▷`,`Insert video`);return Zm(r,`YouTube URL`,`https://youtube.com/...`,t=>e.onVideo?.(t)),t.appendChild(r),t}function Zm(e,t,n,r){let i;e.addEventListener(`click`,()=>{if(i){i.destroy(),i=void 0;return}let a=document.createElement(`div`);a.className=`notes-url-panel`;let o=document.createElement(`div`);o.className=`notes-url-label`,o.textContent=t,a.appendChild(o);let s=document.createElement(`input`);s.type=`url`,s.className=`notes-url-input`,s.placeholder=n,a.appendChild(s);let c=document.createElement(`div`);c.className=`notes-url-actions`;let l=document.createElement(`button`);l.type=`button`,l.className=`button notes-url-cancel`,l.textContent=`Cancel`,l.addEventListener(`click`,()=>{i?.destroy(),i=void 0});let u=document.createElement(`button`);u.type=`button`,u.className=`button is-info notes-url-confirm`,u.textContent=`Insert`,u.addEventListener(`click`,()=>{let e=s.value.trim();e&&r(e),i?.destroy(),i=void 0}),c.appendChild(l),c.appendChild(u),a.appendChild(c),s.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),u.click()):e.key===`Escape`&&l.click()}),i=km(e,{content:a,theme:`light-border`,trigger:`manual`,interactive:!0,placement:`bottom-start`,onShown:()=>setTimeout(()=>s.focus(),0),onHidden:()=>{i?.destroy(),i=void 0}}),i.show()})}function Qm(e){let t=Rm();return t.appendChild(zm(`clearFormatting`,`⊘`,`Clear formatting`,e.onClearFormatting)),t}function $m(e={}){let t=document.createElement(`div`);t.className=`notes-editor-content`;let l={toolbar:void 0,editorElement:t,editor:void 0,getHtml:()=>l.editor&&!l.editor.isEmpty?l.editor.getHTML():``,isEmpty:()=>!l.editor||l.editor.isEmpty,destroy:()=>{l.editor?.destroy(),l.editor=void 0}};l.toolbar=Fm({onHeading:e=>{l.editor&&(e===!1?l.editor.chain().focus().setParagraph().run():l.editor.chain().focus().toggleHeading({level:e}).run())},onBold:()=>l.editor?.chain().focus().toggleBold().run(),onItalic:()=>l.editor?.chain().focus().toggleItalic().run(),onUnderline:()=>l.editor?.chain().focus().toggleUnderline().run(),onStrike:()=>l.editor?.chain().focus().toggleStrike().run(),onColor:e=>l.editor?.chain().focus().setColor(e).run(),onBackground:e=>l.editor?.chain().focus().setHighlight({color:e}).run(),onBulletList:()=>l.editor?.chain().focus().toggleBulletList().run(),onOrderedList:()=>l.editor?.chain().focus().toggleOrderedList().run(),onAlign:e=>l.editor?.chain().focus().setTextAlign(e).run(),onBlockquote:()=>l.editor?.chain().focus().toggleBlockquote().run(),onCodeBlock:()=>l.editor?.chain().focus().toggleCodeBlock().run(),onLink:e=>l.editor?.chain().focus().setLink({href:e}).run(),onVideo:e=>l.editor?.commands.setYoutubeVideo({src:e}),onClearFormatting:()=>l.editor?.chain().focus().clearNodes().unsetAllMarks().run()});let u=()=>{if(l.editor){Im(l.toolbar,{bold:l.editor.isActive(`bold`),italic:l.editor.isActive(`italic`),underline:l.editor.isActive(`underline`),strike:l.editor.isActive(`strike`),orderedList:l.editor.isActive(`orderedList`),bulletList:l.editor.isActive(`bulletList`),blockquote:l.editor.isActive(`blockquote`),codeBlock:l.editor.isActive(`codeBlock`),alignLeft:l.editor.isActive({textAlign:`left`}),alignCenter:l.editor.isActive({textAlign:`center`}),alignRight:l.editor.isActive({textAlign:`right`}),alignJustify:l.editor.isActive({textAlign:`justify`})});for(let e=1;e<=6;e++)if(l.editor.isActive(`heading`,{level:e})){Lm(l.toolbar,e);return}Lm(l.toolbar,!1)}};return requestAnimationFrame(()=>{l.editor=new r.Editor({element:t,extensions:[o.default,i.TextStyle,n.Color,a.default.configure({multicolor:!0}),s.default.configure({types:[`heading`,`paragraph`]}),c.default.configure({inline:!1})],content:e.initialHtml||``,onSelectionUpdate:u,onTransaction:u})}),l}function eh(e,t,n){if(!e)return{};let r=document.createElement(`aside`);r.classList.add(`menu`);let i={},a=e=>n&&e.close!==!1?t=>{t.stopPropagation(),n(),e.onClick()}:t=>{t.stopPropagation(),e.onClick()},o=0,s=()=>(o+=1,o),c=e=>e?.heading||e?.text||e?.label||`Item ${s()}`,l=e=>{let t=document.createElement(`li`);if(t.className=`font-medium`,e.style&&(t.style.cssText=e.style),e.onClick){let n=e.fontSize||`1em`;if(e.divider){let e=document.createElement(`hr`);e.classList.add(`dropdown-divider`),t.appendChild(e)}else{let r=document.createElement(`a`),i=e.disabled?`0.4`:`1`;r.style.cssText=`text-decoration: none; opacity: ${i}; font-size: ${n}`,e.class&&r.classList.add(e.class),e.color&&(r.style.color=e.color),e.heading&&(r.style.fontWeight=`bold`),e.disabled||(r.onclick=a(e)),r.innerHTML=c(e),t.appendChild(r)}}else t.innerHTML=c(e),e.disabled||(t.onclick=e.onClick);return t},u;for(let e of t||[])if(!e.hide){if(e.items){if(e.text){let t=document.createElement(`p`);t.className=`menu-label font-medium`,t.innerHTML=e.text,r.appendChild(t)}let t=document.createElement(`ul`);t.className=`menu-list`;for(let n of e.items)n.hide||t.appendChild(l(n));r.appendChild(t)}else if(e.type===`input`){let{field:t,inputElement:n}=gn(e);e.focus&&(u=n),i[e.field]=n,r.appendChild(t)}else if(e.type===`divider`){let e=document.createElement(`hr`);e.classList.add(`dropdown-divider`),r.appendChild(e)}}return e.appendChild(r),{focusElement:u}}function th(e){return typeof e==`function`}var nh;function rh(e){nh&&=(nh?.destroy(!0),void 0),e?.remove&&e.remove()}function ih(e){let{title:t,options:n,menuItems:r=[],coords:i,callback:a,config:o}=e,{target:s,items:c}=e;if(!n?.length&&!c?.length&&!r)return;rh();let l=document.createElement(`div`),u;return s||=i?.evt?.target,s&&(nh=km(s,{content:()=>{c=c?.filter(e=>!e.hide&&!e.disabled).map(e=>({...e,onClick:()=>{rh(l),th(e.onClick)&&e.onClick()}}))||n?.filter(e=>!e.hide&&!e.disabled).map(e=>({text:typeof e==`object`?e.option:e,style:e.style,onClick:()=>{e.subMenu?nh.setContent(`IMPLEMENT SUB MENU`):th(e.onClick)?(rh(l),e.onClick()):th(a)&&a&&(rh(l),a(typeof e==`object`?{...e,coords:i}:e))}}));let e=[{text:t,items:c},...r];return u=eh(l,e).focusElement,l},theme:`light-border`,trigger:`click`,onShown:()=>{u&&setTimeout(()=>u?.focus(),0)},...o}),nh.show(),nh.setProps({interactive:!0})),nh}var Y=`court-line`;function X(e,t){let n=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);return n}function ah(e,t){let n=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);return n.setAttribute(`viewBox`,e),n.setAttribute(`class`,t),n.setAttribute(`fill`,`none`),n.style.width=`100%`,n.style.height=`auto`,n.style.display=`block`,n}function oh(e){let t=ah(`0 0 360 780`,e);for(let e of[`M 0 0 L 360 0 L 360 780 L 0 780 Z`,`M 45 0 L 45 780`,`M 315 0 L 315 780`,`M 0 390 L 360 390`,`M 45 210 L 315 210`,`M 45 570 L 315 570`,`M 180 210 L 180 570`,`M 180 0 L 180 20`,`M 180 760 L 180 780`])t.appendChild(X(`path`,{d:e,class:Y}));return t}function sh(e){let t=ah(`0 0 500 470`,e),n=[X(`rect`,{x:`0`,y:`0`,width:`500`,height:`470`,class:Y}),X(`circle`,{cx:`250`,cy:`470`,r:`60`,class:Y}),X(`line`,{x1:`0`,y1:`470`,x2:`500`,y2:`470`,class:Y}),X(`rect`,{x:`170`,y:`0`,width:`160`,height:`190`,class:Y}),X(`circle`,{cx:`250`,cy:`190`,r:`60`,class:Y}),X(`line`,{x1:`220`,y1:`40`,x2:`280`,y2:`40`,class:Y}),X(`circle`,{cx:`250`,cy:`52`,r:`12`,class:Y}),X(`path`,{d:`M 30 0 L 30 90 A 220 220 0 0 0 470 90 L 470 0`,class:Y})];for(let e of n)t.appendChild(e);return t}function ch(e){let t=ah(`0 0 500 440`,e),n=[X(`path`,{d:`M 20 170 A 350 400 0 0 1 480 170`,class:Y}),X(`line`,{x1:`250`,y1:`400`,x2:`20`,y2:`170`,class:Y}),X(`line`,{x1:`250`,y1:`400`,x2:`480`,y2:`170`,class:Y}),X(`path`,{d:`M 250 400 L 314 336 L 250 273 L 186 336 Z`,class:Y}),X(`path`,{d:`M 340 355 A 100 100 0 0 1 160 355`,class:Y}),X(`line`,{x1:`340`,y1:`355`,x2:`265`,y2:`405`,class:Y}),X(`line`,{x1:`160`,y1:`355`,x2:`235`,y2:`405`,class:Y}),X(`path`,{d:`M 235 405 A 18 18 0 0 1 265 405`,class:Y}),X(`circle`,{cx:`250`,cy:`340`,r:`9`,class:Y}),X(`line`,{x1:`247`,y1:`339`,x2:`253`,y2:`339`,class:Y}),X(`path`,{d:`M 244 398 L 244 404 L 250 408 L 256 404 L 256 398 Z`,class:Y}),X(`rect`,{x:`310`,y:`332`,width:`8`,height:`8`,transform:`rotate(45 314 336)`,class:Y}),X(`rect`,{x:`246`,y:`269`,width:`8`,height:`8`,transform:`rotate(45 250 273)`,class:Y}),X(`rect`,{x:`182`,y:`332`,width:`8`,height:`8`,transform:`rotate(45 186 336)`,class:Y}),X(`rect`,{x:`230`,y:`393`,width:`8`,height:`18`,class:Y}),X(`rect`,{x:`262`,y:`393`,width:`8`,height:`18`,class:Y})];for(let e of n)t.appendChild(e);return t}function lh(e){let t=ah(`0 0 850 2000`,e),n=[X(`rect`,{x:`0`,y:`0`,width:`850`,height:`2000`,rx:`280`,ry:`280`,class:Y}),X(`line`,{x1:`0`,y1:`1000`,x2:`850`,y2:`1000`,class:Y}),X(`circle`,{cx:`425`,cy:`1000`,r:`60`,class:Y}),X(`line`,{x1:`0`,y1:`650`,x2:`850`,y2:`650`,class:Y}),X(`line`,{x1:`0`,y1:`1350`,x2:`850`,y2:`1350`,class:Y}),X(`line`,{x1:`140`,y1:`300`,x2:`710`,y2:`300`,class:Y}),X(`line`,{x1:`140`,y1:`1700`,x2:`710`,y2:`1700`,class:Y}),X(`path`,{d:`M 395 300 A 40 40 0 0 1 455 300`,class:Y}),X(`path`,{d:`M 395 1700 A 40 40 0 0 0 455 1700`,class:Y}),X(`circle`,{cx:`270`,cy:`650`,r:`50`,class:Y}),X(`circle`,{cx:`580`,cy:`650`,r:`50`,class:Y}),X(`circle`,{cx:`270`,cy:`1350`,r:`50`,class:Y}),X(`circle`,{cx:`580`,cy:`1350`,r:`50`,class:Y})];for(let e of n)t.appendChild(e);return t}function uh(e){let t=ah(`0 0 200 440`,e);for(let e of[`M 0 0 L 200 0 L 200 440 L 0 440 Z`,`M 0 220 L 200 220`,`M 0 150 L 200 150`,`M 0 290 L 200 290`,`M 100 0 L 100 150`,`M 100 290 L 100 440`])t.appendChild(X(`path`,{d:e,class:Y}));return t}function dh(e){let t=ah(`0 0 200 440`,e);for(let e of[`M 0 0 L 200 0 L 200 440 L 0 440 Z`,`M 18 0 L 18 440`,`M 182 0 L 182 440`,`M 0 220 L 200 220`,`M 0 146 L 200 146`,`M 0 294 L 200 294`,`M 0 30 L 200 30`,`M 0 410 L 200 410`,`M 100 146 L 100 220`,`M 100 220 L 100 294`])t.appendChild(X(`path`,{d:e,class:Y}));return t}function fh(e){let t=ah(`0 0 100 200`,e);for(let e of[`M 0 0 L 100 0 L 100 200 L 0 200 Z`,`M 0 100 L 100 100`,`M 0 69.5 L 100 69.5`,`M 0 130.5 L 100 130.5`,`M 50 69.5 L 50 67.5`,`M 50 130.5 L 50 132.5`])t.appendChild(X(`path`,{d:e,class:Y}));return t}var ph=`COURT_SVG`,mh={tennis:oh,basketball:sh,baseball:ch,hockey:lh,pickleball:uh,badminton:dh,padel:fh},hh={TENNIS:`tennis`,PADEL:`padel`,PICKLEBALL:`pickleball`,BADMINTON:`badminton`},gh={HAL:`basketball`,INN:`baseball`,PER:`hockey`};function _h(e){if(e){for(let[t,n]of Object.entries(gh))if(e.startsWith(t))return n;if(e.startsWith(`SET`)||e.startsWith(`T`))return e.includes(`@RALLY`)?`pickleball`:`tennis`}}function vh(e){let t=e?.competitionFormat?.sport;return t&&hh[t]?hh[t]:_h(e?.matchUpFormat)}function yh(e){let t=e.getAttribute(`viewBox`);if(!t)return e;let n=t.split(/\s+/).map(Number);if(n.length!==4)return e;let[r,i,a,o]=n;if(o<=a)return e;e.setAttribute(`viewBox`,`${r} ${i} ${o} ${a}`);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);for(s.setAttribute(`transform`,`translate(${o}, 0) rotate(90)`);e.firstChild;)s.appendChild(e.firstChild);return e.appendChild(s),e}function bh(e,t=``){let n=e?mh[e]:void 0;if(n)return yh(n(t?`court--${e} ${t}`:`court--${e}`))}function xh(e){let t=[];return e.city&&t.push(e.city),(e.state||e.region)&&t.push(e.state||e.region),e.countryCode?t.push(e.countryCode):e.country&&t.push(e.country),t.join(`, `)}function Sh(e){if(!e)return;let t=xh(e);return t.length?t:void 0}function Ch(e){let t=e?.find(Boolean);if(!t)return;let n=t.addresses?.find(Boolean);return n?Sh(n)??t.venueName:t.venueName}var wh=/^(\d{4})-(\d{2})-(\d{2})/,Th=864e5;function Eh(e){if(!e)return null;let t=wh.exec(e);if(!t)return null;let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?null:{year:n,month:r,day:i}}function Dh(e,t){if(!t)return new Date(e.year,e.month-1,e.day);let n=Date.UTC(e.year,e.month-1,e.day,0,0,0,0),r=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`}),i=new Date(n);for(let e=0;e<2;e++){let e=r.formatToParts(i),t=t=>Number(e.find(e=>e.type===t)?.value??0),a=Date.UTC(t(`year`),t(`month`)-1,t(`day`),t(`hour`),t(`minute`),t(`second`))-i.getTime();i=new Date(n-a)}return i}function Oh(e,t){if(!t)return new Date(e.year,e.month-1,e.day+1);let n=Dh(e,t),r=new Date(n.getTime()+Th),i=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}).formatToParts(r),a=e=>Number(i.find(t=>t.type===e)?.value??0);return Dh({year:a(`year`),month:a(`month`),day:a(`day`)},t)}function kh(e){if(!e)return null;let t=Eh(e);if(t)return new Date(t.year,t.month-1,t.day);let n=new Date(e);return Number.isNaN(n.getTime())?null:n}function Ah(e){return e.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}function jh(e){return e.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})}function Mh(e,t){if(!e&&!t)return;let n=kh(e),r=kh(t),i=!!n&&!Number.isNaN(n.getTime()),a=!!r&&!Number.isNaN(r.getTime());if(!(!i&&!a))return i&&a&&n.getTime()===r.getTime()?jh(n):i&&a?n.getFullYear()===r.getFullYear()?`${Ah(n)} – ${Ah(r)}, ${r.getFullYear()}`:`${jh(n)} – ${jh(r)}`:jh(i?n:r)}var Nh=`URL`;function Ph(e,t){if(!Array.isArray(e))return;let n=e.find(e=>e?.name===t&&e?.resourceType===Nh);return n?.url??n?.identifier}function Fh(e,t){if(Array.isArray(e))return e.find(e=>e?.resourceSubType===`COURT_SVG`&&(!t||e?.name===t))?.identifier}function Ih(e){let t=document.createElement(`div`);if(t.className=e.cardClass,t.setAttribute(`aria-busy`,`true`),e.showImage){let n=document.createElement(`div`);n.className=e.imageClass;let r=document.createElement(`div`);r.className=e.blockClass,n.appendChild(r),t.appendChild(n)}if(e.bodyLines>0){let n=document.createElement(`div`);n.className=e.bodyClass;for(let t=0;t<e.bodyLines;t++){let r=document.createElement(`div`);r.className=e.lineClass,r.style.width=t===0?`90%`:`${60+t*10}%`,n.appendChild(r)}t.appendChild(n)}if(e.showFooter){let n=document.createElement(`div`);n.className=e.footerClass;let r=document.createElement(`div`);r.className=e.lineClass,r.style.width=`40%`,n.appendChild(r),t.appendChild(n)}return t}var Lh={showImage:!0,cornerBadges:[`status`],body:[`title`,`tier`,`location`,`dateRange`],footer:[`feeBadge`,`playerCount`]};function Rh(e){return e?{showImage:e.showImage??Lh.showImage,cornerBadges:e.cornerBadges??Lh.cornerBadges,body:e.body??Lh.body,footer:e.footer??Lh.footer}:Lh}var zh=()=>`chc-tc-card`,Bh=()=>`chc-tc-card--clickable`,Vh=()=>`chc-tc-card--offline`,Hh=()=>`chc-tc-image`,Uh=()=>`chc-tc-image-img`,Wh=()=>`chc-tc-image-svg`,Gh=()=>`chc-tc-image-placeholder`,Kh=()=>`chc-tc-corner-badges`,qh=()=>`chc-tc-status-pill`,Jh=()=>`chc-tc-offline-badge`,Yh=()=>`chc-tc-body`,Xh=()=>`chc-tc-title`,Zh=()=>`chc-tc-location`,Qh=()=>`chc-tc-date-range`,$h=()=>`chc-tc-organizer`,eg=()=>`chc-tc-updated-at`,tg=()=>`chc-tc-footer`,ng=()=>`chc-tc-fee-badge`,rg=()=>`chc-tc-player-count`,ig=()=>`chc-tc-event-count`,ag=()=>`chc-tc-tier-badge`,og=()=>`chc-tc-card chc-tc-skeleton`,sg=()=>`chc-tc-skeleton-line`,cg=()=>`chc-tc-skeleton-block`;function lg(e,t,n){let r=Rh(t),i=document.createElement(`div`);return i.className=zh(),i.dataset.tournamentId=e.tournamentId,e.offline&&i.classList.add(Vh()),n?.onClick&&(i.classList.add(Bh()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showImage!==!1&&i.appendChild(ug(e,r)),r.body.length&&i.appendChild(hg(e,r)),r.footer.length&&i.appendChild(Cg(e,r)),i}function ug(e,t){let n=document.createElement(`div`);if(n.className=Hh(),e.tournamentImageURL){let t=document.createElement(`img`);t.className=Uh(),t.src=e.tournamentImageURL,t.alt=e.tournamentName||``,t.loading=`lazy`,t.addEventListener(`error`,()=>fg(n,e)),n.appendChild(t)}else dg(n,e);if(t.cornerBadges.length){let r=pg(e,t.cornerBadges);r&&n.appendChild(r)}return n}function dg(e,t){let n=bh(t.courtSvgSport,Wh());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=Gh(),e.appendChild(r)}function fg(e,t){e.querySelector(`.${Uh()}`)?.remove(),dg(e,t)}function pg(e,t){let n=[];for(let r of t){let t=mg(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=Kh();for(let e of n)r.appendChild(e);return r}function mg(e,t){if(e===`status`){if(!t.status)return null;let e=document.createElement(`div`);return e.className=qh(),e.dataset.kind=t.status.kind,e.textContent=t.status.label,e}if(e===`offline`){if(!t.offline)return null;let e=document.createElement(`div`);return e.className=Jh(),e.textContent=`Offline`,e}return null}function hg(e,t){let n=document.createElement(`div`);n.className=Yh();for(let r of t.body){let t=gg(r,e);t&&n.appendChild(t)}return n}function gg(e,t){switch(e){case`title`:return _g(t);case`tier`:return vg(t);case`location`:return yg(t);case`dateRange`:return bg(t);case`organizerName`:return xg(t);case`updatedAt`:return Sg(t);default:return null}}function _g(e){if(!e.tournamentName)return null;let t=document.createElement(`div`);return t.className=Xh(),t.textContent=e.tournamentName,t.title=e.tournamentName,t}function vg(e){let t=e.tournamentTier?.value;if(!t)return null;let n=document.createElement(`div`);return n.className=ag(),n.textContent=t,n.title=e.tournamentTier?.system?`${e.tournamentTier.system}: ${t}`:t,n}function yg(e){if(!e.location)return null;let t=document.createElement(`div`);return t.className=Zh(),t.textContent=e.location,t.title=e.location,t}function bg(e){if(!e.dateRangeFormatted)return null;let t=document.createElement(`div`);return t.className=Qh(),t.textContent=e.dateRangeFormatted,t}function xg(e){if(!e.organizerName)return null;let t=document.createElement(`div`);return t.className=$h(),t.textContent=e.organizerName,t}function Sg(e){if(!e.updatedAt)return null;let t=document.createElement(`div`);t.className=eg();let n=new Date(e.updatedAt);return t.textContent=Number.isNaN(n.getTime())?e.updatedAt:n.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`}),t}function Cg(e,t){let n=document.createElement(`div`);n.className=tg();for(let r of t.footer){let t=wg(r,e);t&&n.appendChild(t)}return n}function wg(e,t){switch(e){case`feeBadge`:return Tg(t);case`playerCount`:return Eg(t);case`eventCount`:return Dg(t);default:return null}}function Tg(e){if(!e.feeFormatted)return null;let t=document.createElement(`div`);return t.className=ng(),t.textContent=e.feeFormatted,t}function Eg(e){if(typeof e.participantCount!=`number`)return null;let t=document.createElement(`div`);return t.className=rg(),t.textContent=`${e.participantCount} ${e.participantCount===1?`player`:`players`}`,t}function Dg(e){if(typeof e.eventCount!=`number`)return null;let t=document.createElement(`div`);return t.className=ig(),t.textContent=`${e.eventCount} ${e.eventCount===1?`event`:`events`}`,t}function Og(e){let t=Rh(e);return Ih({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:og(),imageClass:Hh(),bodyClass:Yh(),footerClass:tg(),blockClass:cg(),lineClass:sg()})}var kg=6048e5;function Ag(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function jg(e,t,n){return!t||!n?!1:t.getTime()<=e.getTime()&&e.getTime()<n.getTime()}function Mg(e){return`Opens ${e.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`}function Ng(e,t=new Date){let n=e.tournamentStatus?.toUpperCase();if(n===`CANCELLED`||n===`ABANDONDED`||n===`ABANDONED`)return{kind:`cancelled`,label:`Cancelled`};let r=e.timeZone,i=Eh(e.endDate),a=i?Oh(i,r):null;if(n===`COMPLETED`||a&&t.getTime()>=a.getTime())return{kind:`completed`,label:`Completed`};let o=Eh(e.startDate);if(jg(t,o?Dh(o,r):null,a))return{kind:`live`,label:`Live`};let s=Ag(e.entriesClose);if(s){let e=s.getTime()-t.getTime();if(e>0&&e<=kg)return{kind:`closing-soon`,label:`Closing Soon`}}let c=Ag(e.entriesOpen);return c&&c.getTime()>t.getTime()?{kind:`registration-opens`,label:Mg(c)}:null}var Pg=`USD`,Fg=`–`;function Ig(e,t){try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t}).format(e)}catch{return`$${e.toFixed(2)}`}}function Lg(e){let t=new Set;for(let n of e)t.add(n.currencyCode||Pg);return[...t]}function Rg(e){return[...e].sort((e,t)=>e.amount-t.amount).find(Boolean)}function zg(e){if(!e||e.length===0)return null;let t=e.filter(e=>typeof e.amount==`number`&&!Number.isNaN(e.amount));if(t.length===0)return null;if(t.length===1){let e=t[0],n=e.currencyCode||Pg;return`${n} ${Ig(e.amount,n)}`}let n=Lg(t);if(n.length>1){let e=Rg(t);if(!e)return null;let n=e.currencyCode||Pg;return`From ${n} ${Ig(e.amount,n)}`}let r=n[0],i=t.map(e=>e.amount).sort((e,t)=>e-t),a=i[0],o=i.at(-1)??a;return a===o?`${r} ${Ig(a,r)}`:`${r} ${Ig(a,r)} ${Fg} ${Ig(o,r)}`}var Bg=`tournamentImage`;function Vg(e){let t=e?.registrationProfile?.entryFees;return Array.isArray(t)?t.filter(e=>e&&typeof e.amount==`number`):[]}function Hg(e){let t=e?.timeItems;if(Array.isArray(t))return t.find(e=>e?.itemType===`TMX`)?.itemValue?.offline}function Ug(e,t){let n=Array.isArray(e?.onlineResources)?e.onlineResources:void 0,r=Array.isArray(e?.venues)?e.venues:[],i=Array.isArray(e?.participants)?e.participants:[],a=Array.isArray(e?.events)?e.events:[],o=t?.statusOverride===void 0?Ng({tournamentStatus:e?.tournamentStatus,startDate:e?.startDate,endDate:e?.endDate,entriesOpen:e?.registrationProfile?.entriesOpen,entriesClose:e?.registrationProfile?.entriesClose,timeZone:e?.localTimeZone||e?.timeZone},t?.now):t.statusOverride,s=e?.tournamentImageURL??Ph(n,Bg),c=e?.courtSvgSport??Fh(n);return{tournamentId:e?.tournamentId??``,tournamentName:e?.tournamentName??``,startDate:e?.startDate,endDate:e?.endDate,dateRangeFormatted:Mh(e?.startDate,e?.endDate),location:Ch(r),tournamentImageURL:s,courtSvgSport:c,participantCount:i.length||void 0,eventCount:a.length||void 0,organizerName:e?.tournamentOrganizers?.find?.(Boolean)?.organizerName,status:o,feeFormatted:zg(Vg(e)),updatedAt:e?.updatedAt,offline:Hg(e),tournamentTier:Wg(e)}}function Wg(e){let t=e?.tournamentTier;if(!t||typeof t!=`object`||typeof t.system!=`string`||typeof t.value!=`string`)return;let n={system:t.system,value:t.value};return typeof t.numericRank==`number`&&Number.isFinite(t.numericRank)&&(n.numericRank=t.numericRank),n}var Gg={showImage:!0,showMap:!0,cornerBadges:[`primaryBadge`],body:[`title`,`address`,`courtBreakdown`],footer:[`amenityRow`]};function Kg(e){return e?{showImage:e.showImage??Gg.showImage,showMap:e.showMap??Gg.showMap,cornerBadges:e.cornerBadges??Gg.cornerBadges,body:e.body??Gg.body,footer:e.footer??Gg.footer}:Gg}var qg=()=>`chc-vc-card`,Jg=()=>`chc-vc-card--clickable`,Yg=()=>`chc-vc-image`,Xg=()=>`chc-vc-image-img`,Zg=()=>`chc-vc-image-svg`,Qg=()=>`chc-vc-image-map`,$g=()=>`chc-vc-image-placeholder`,e_=()=>`chc-vc-corner-badges`,t_=()=>`chc-vc-primary-badge`,n_=()=>`chc-vc-body`,r_=()=>`chc-vc-title`,i_=()=>`chc-vc-address`,a_=()=>`chc-vc-court-breakdown`,o_=()=>`chc-vc-footer`,s_=()=>`chc-vc-amenity-row`,c_=()=>`chc-vc-amenity`,l_=()=>`chc-vc-card chc-vc-skeleton`,u_=()=>`chc-vc-skeleton-line`,d_=()=>`chc-vc-skeleton-block`;function f_(e,t,n){let r=Kg(t),i=document.createElement(`div`);i.className=qg(),i.dataset.venueId=e.venueId;let a=null;r.showImage!==!1&&(a=g_(e,r,()=>f()),i.appendChild(a));let o=r.body.length?w_(e,r):null;o&&i.appendChild(o);let s=r.footer.length?O_(e,r):null;s&&i.appendChild(s);function c(){return!!a?.querySelector(`iframe`)}let l=new Map;function u(e,t){if(l.has(e))return;let n=e=>{e.stopPropagation(),t()},r=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),t())};e.classList.add(Jg()),e.tabIndex=0,e.addEventListener(`click`,n),e.addEventListener(`keydown`,r),l.set(e,{click:n,keydown:r})}function d(e){let t=l.get(e);t&&(e.removeEventListener(`click`,t.click),e.removeEventListener(`keydown`,t.keydown),e.classList.remove(Jg()),e.removeAttribute(`tabindex`),l.delete(e))}function f(){if(!n?.onClick)return;let t=()=>n.onClick(e);c()?(d(i),o&&u(o,t),s&&u(s,t)):(o&&d(o),s&&d(s),u(i,t))}return f(),i}function p_(e){return typeof e.latitude==`number`&&typeof e.longitude==`number`}function m_(e){let t=e.latitude,n=e.longitude,r=.01,i=`https://www.openstreetmap.org/export/embed.html?bbox=${`${n-r},${t-r},${n+r},${t+r}`}&marker=${t},${n}&layer=mapnik`,a=document.createElement(`iframe`);return a.className=Qg(),a.src=i,a.loading=`lazy`,a.title=`Map of ${e.venueName}`,a}function h_(e,t){let n=bh(t.courtSvgSport,Zg());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=$g(),e.appendChild(r)}function g_(e,t,n){let r=document.createElement(`div`);if(r.className=Yg(),e.venueImageURL){let i=document.createElement(`img`);i.className=Xg(),i.src=e.venueImageURL,i.alt=e.venueName||``,i.loading=`lazy`,i.addEventListener(`error`,()=>{i.remove(),t.showMap!==!1&&p_(e)?r.appendChild(m_(e)):h_(r,e),n?.()}),r.appendChild(i)}else t.showMap!==!1&&p_(e)?r.appendChild(m_(e)):h_(r,e);if(t.cornerBadges.length){let n=v_(e,t.cornerBadges);n&&r.appendChild(n)}return r}function __(e,t){if(e===`primaryBadge`){if(!t.isPrimary)return null;let e=document.createElement(`div`);return e.className=t_(),e.textContent=`Primary`,e}return null}function v_(e,t){let n=[];for(let r of t){let t=__(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=e_();for(let e of n)r.appendChild(e);return r}function y_(e){if(!e.venueName)return null;let t=document.createElement(`div`);return t.className=r_(),t.textContent=e.venueName,t.title=e.notes?`${e.venueName}\n${e.notes}`:e.venueName,t}function b_(e){if(!e.addressFormatted)return null;let t=document.createElement(`div`);return t.className=i_(),t.textContent=e.addressFormatted,t.title=e.addressFormatted,t}function x_(e){if(!e.courtBreakdown)return null;let t=document.createElement(`div`);return t.className=a_(),t.textContent=e.courtBreakdown,t}function S_(e){if(!e.venueAbbreviation)return null;let t=document.createElement(`div`);return t.className=a_(),t.textContent=e.venueAbbreviation,t}function C_(e,t){return e===`title`?y_(t):e===`address`?b_(t):e===`courtBreakdown`?x_(t):e===`venueAbbreviation`?S_(t):null}function w_(e,t){let n=document.createElement(`div`);n.className=n_();for(let r of t.body){let t=C_(r,e);t&&n.appendChild(t)}return n}function T_(e){let t=document.createElement(`span`);return t.className=c_(),t.textContent=e,t}function E_(e){let t=[];if(typeof e.courtCount==`number`&&t.push(T_(`${e.courtCount} ${e.courtCount===1?`court`:`courts`}`)),e.indoorCount&&t.push(T_(`${e.indoorCount} indoor`)),e.outdoorCount&&t.push(T_(`${e.outdoorCount} outdoor`)),e.floodlitCount&&t.push(T_(`${e.floodlitCount} lit`)),!t.length)return null;let n=document.createElement(`div`);n.className=s_();for(let e of t)n.appendChild(e);return n}function D_(e,t){return e===`amenityRow`?E_(t):e===`address`?b_(t):e===`courtBreakdown`?x_(t):null}function O_(e,t){let n=document.createElement(`div`);n.className=o_();for(let r of t.footer){let t=D_(r,e);t&&n.appendChild(t)}return n}function k_(e){let t=Kg(e);return Ih({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:l_(),imageClass:Yg(),bodyClass:n_(),footerClass:o_(),blockClass:d_(),lineClass:u_()})}var A_=`venueImage`;function j_(e){let t=[];return e.indoorOutdoor&&t.push(e.indoorOutdoor.toLowerCase()),e.surfaceCategory&&t.push(e.surfaceCategory.toLowerCase()),t.length?t.join(` `):`court`}function M_(e){if(!e.length)return;let t=new Map;for(let n of e){let e=j_(n);t.set(e,(t.get(e)??0)+1)}return[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e,t])=>`${t} ${e}`).join(`, `)}function N_(e,t){let n=0;for(let r of e)t(r)&&(n+=1);return n}function P_(e,t){let n=Array.isArray(e?.courts)?e.courts:[],r=Array.isArray(e?.onlineResources)?e.onlineResources:void 0,i=e?.addresses?.find(e=>e);return{venueId:e?.venueId??``,venueName:e?.venueName??``,venueAbbreviation:e?.venueAbbreviation,addressFormatted:Sh(i),latitude:typeof i?.latitude==`number`?i.latitude:void 0,longitude:typeof i?.longitude==`number`?i.longitude:void 0,courtCount:n.length||void 0,courtBreakdown:M_(n),indoorCount:N_(n,e=>e.indoorOutdoor===`INDOOR`)||void 0,outdoorCount:N_(n,e=>e.indoorOutdoor===`OUTDOOR`)||void 0,floodlitCount:N_(n,e=>!!e.floodlit)||void 0,isPrimary:!!e?.isPrimary,venueImageURL:e?.venueImageURL??Ph(r,A_),courtSvgSport:e?.courtSvgSport??Fh(r)??t?.sport,notes:e?.notes}}var F_={showImage:!0,cornerBadges:[`indoorOutdoor`,`floodlit`],body:[`title`,`surface`],footer:[`amenityRow`]};function I_(e){return e?{showImage:e.showImage??F_.showImage,cornerBadges:e.cornerBadges??F_.cornerBadges,body:e.body??F_.body,footer:e.footer??F_.footer}:F_}var L_=()=>`chc-cc-card`,R_=()=>`chc-cc-card--clickable`,z_=()=>`chc-cc-image`,B_=()=>`chc-cc-image-svg`,V_=()=>`chc-cc-image-placeholder`,H_=()=>`chc-cc-corner-badges`,U_=()=>`chc-cc-indoor-badge`,W_=()=>`chc-cc-floodlit-badge`,G_=()=>`chc-cc-body`,K_=()=>`chc-cc-title`,q_=()=>`chc-cc-surface`,J_=()=>`chc-cc-availability`,Y_=()=>`chc-cc-abbr`,X_=()=>`chc-cc-footer`,Z_=()=>`chc-cc-amenity-row`,Q_=()=>`chc-cc-card chc-cc-skeleton`,$_=()=>`chc-cc-skeleton-line`,ev=()=>`chc-cc-skeleton-block`;function tv(e,t,n){let r=I_(t),i=document.createElement(`div`);return i.className=L_(),i.dataset.courtId=e.courtId,n?.onClick&&(i.classList.add(R_()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showImage!==!1&&i.appendChild(rv(e,r)),r.body.length&&i.appendChild(pv(e,r)),r.footer.length&&i.appendChild(gv(e,r)),i}function nv(e,t){let n=bh(t.courtSvgSport,B_());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=V_(),e.appendChild(r)}function rv(e,t){let n=document.createElement(`div`);if(n.className=z_(),e.surfaceCategory&&(n.dataset.surface=e.surfaceCategory),nv(n,e),t.cornerBadges.length){let r=sv(e,t.cornerBadges);r&&n.appendChild(r)}return n}function iv(e){if(!e.indoorOutdoor)return null;let t=document.createElement(`div`);return t.className=U_(),t.dataset.kind=e.indoorOutdoor,t.textContent=e.indoorOutdoor===`INDOOR`?`Indoor`:`Outdoor`,t}function av(e){if(!e.floodlit)return null;let t=document.createElement(`div`);return t.className=W_(),t.textContent=`Lit`,t}function ov(e,t){return e===`indoorOutdoor`?iv(t):e===`floodlit`?av(t):null}function sv(e,t){let n=[];for(let r of t){let t=ov(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=H_();for(let e of n)r.appendChild(e);return r}function cv(e){if(!e.courtName)return null;let t=document.createElement(`div`);return t.className=K_(),t.textContent=e.courtName,t.title=e.notes?`${e.courtName}\n${e.notes}`:e.courtName,t}function lv(e){if(!e.surfaceLabel)return null;let t=document.createElement(`div`);return t.className=q_(),t.textContent=e.surfaceLabel,t}function uv(e){if(!e.availabilitySummary)return null;let t=document.createElement(`div`);return t.className=J_(),t.textContent=e.availabilitySummary,t}function dv(e){if(!e.courtAbbreviation)return null;let t=document.createElement(`div`);return t.className=Y_(),t.textContent=e.courtAbbreviation,t}function fv(e,t){return e===`title`?cv(t):e===`surface`?lv(t):e===`availability`?uv(t):e===`abbreviation`?dv(t):null}function pv(e,t){let n=document.createElement(`div`);n.className=G_();for(let r of t.body){let t=fv(r,e);t&&n.appendChild(t)}return n}function mv(e){let t=[];if(e.indoorOutdoor&&t.push(e.indoorOutdoor===`INDOOR`?`indoor`:`outdoor`),e.surfaceCategory&&t.push(e.surfaceCategory.toLowerCase()),e.floodlit&&t.push(`floodlit`),!t.length)return null;let n=document.createElement(`div`);return n.className=Z_(),n.textContent=t.join(` · `),n}function hv(e,t){return e===`amenityRow`?mv(t):e===`availability`?uv(t):e===`surface`?lv(t):null}function gv(e,t){let n=document.createElement(`div`);n.className=X_();for(let r of t.footer){let t=hv(r,e);t&&n.appendChild(t)}return n}function _v(e){let t=I_(e);return Ih({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:Q_(),imageClass:z_(),bodyClass:G_(),footerClass:X_(),blockClass:ev(),lineClass:$_()})}var vv=`INDOOR`,yv=`OUTDOOR`,bv=new Set([`HARD`,`CLAY`,`GRASS`,`ARTIFICIAL`,`CARPET`]);function xv(e){if(!e)return;let t=String(e).toUpperCase();if(t===vv)return vv;if(t===yv)return yv}function Sv(e){let t=e?.surfaceCategory?String(e.surfaceCategory).toUpperCase():void 0;if(t&&bv.has(t))return t;let n=e?.surfaceType?String(e.surfaceType).toUpperCase():void 0;return n&&bv.has(n)?n:t}function Cv(e,t){let n=[];return e&&n.push(e.charAt(0)+e.slice(1).toLowerCase()),t&&n.push(t.charAt(0)+t.slice(1).toLowerCase()),n.length?n.join(` · `):void 0}function wv(e,t){let n=xv(e?.indoorOutdoor),r=Sv(e);return{courtId:e?.courtId??``,courtName:e?.courtName??``,courtAbbreviation:e?.courtAbbreviation,surfaceLabel:Cv(n,r),indoorOutdoor:n,surfaceCategory:r,floodlit:!!e?.floodlit,courtSvgSport:t?.sport,notes:e?.notes}}var Tv=()=>`chc-team-card`,Ev=()=>`chc-team-card--clickable`,Dv=()=>`chc-team-card__title-row`,Ov=()=>`chc-team-card__name`,kv=()=>`chc-team-card__nickname`,Av=()=>`chc-team-card__counts`,jv=` · `;function Mv(e,t){let n=document.createElement(`div`);n.className=Tv(),e.teamId&&(n.dataset.teamId=e.teamId),t?.onClick&&(n.classList.add(Ev()),n.tabIndex=0,n.setAttribute(`role`,`button`),n.addEventListener(`click`,n=>{n.stopPropagation(),t.onClick(e)}),n.addEventListener(`keydown`,n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),n.stopPropagation(),t.onClick(e))})),n.appendChild(Nv(e));let r=(e.countSegments??[]).map(e=>(e??``).trim()).filter(Boolean);return r.length&&n.appendChild(Pv(r)),n}function Nv(e){let t=document.createElement(`div`);t.className=Dv();let n=document.createElement(`span`);if(n.className=Ov(),n.textContent=e.teamName,t.appendChild(n),e.nickname){let n=document.createElement(`span`);n.className=kv(),n.textContent=`"${e.nickname}"`,t.appendChild(n)}return t}function Pv(e){let t=document.createElement(`div`);return t.className=Av(),t.textContent=e.join(jv),t}var Fv=[`COMPETITIVE`,`ROUTINE`,`DECISIVE`,`WALKOVER`],Iv=new Set([`WALKOVER`,`DOUBLE_WALKOVER`,`DEFAULTED`,`DOUBLE_DEFAULT`]);function Lv(){return{COMPETITIVE:0,ROUTINE:0,DECISIVE:0,WALKOVER:0}}function Rv(e){let t=Lv();if(!Array.isArray(e))return t;for(let n of e){let e=typeof n?.getData==`function`?n.getData():n;if(!e)continue;if(e.matchUpStatus&&Iv.has(e.matchUpStatus)){t.WALKOVER+=1;continue}let r=e.competitiveProfile?.competitiveness;r&&r!==`WALKOVER`&&Fv.includes(r)&&(t[r]+=1)}return t}function zv(e){return Fv.reduce((t,n)=>t+e[n],0)}var Bv={COMPETITIVE:`Competitive`,ROUTINE:`Routine`,DECISIVE:`Decisive`,WALKOVER:`Walkover / Defaulted`};function Vv(e={}){let{onSegmentClick:t}=e,n=document.createElement(`div`);n.className=`chc-cb`;let r={};for(let e of Fv){let i=document.createElement(`div`);i.className=`chc-cb__seg`,i.dataset.bucket=e,t&&(i.classList.add(`is-clickable`),i.setAttribute(`role`,`button`),i.addEventListener(`click`,()=>t(e))),r[e]=i,n.appendChild(i)}return{element:n,update:e=>{let t=zv(e);if(n.style.display=t>0?`flex`:`none`,t)for(let t of Fv){let n=r[t],i=e[t];i===0?(n.style.flex=`0 0 0`,n.style.padding=`0`,n.textContent=``,n.removeAttribute(`title`)):(n.style.flex=`${i} 1 0`,n.style.padding=`0 4px`,n.textContent=String(i),n.title=`${Bv[t]}: ${i}`)}},setActive:e=>{n.classList.toggle(`has-active`,!!e);for(let t of Fv)r[t].classList.toggle(`is-active`,t===e)}}}var Hv={COMPETITIVE:`Competitive`,ROUTINE:`Routine`,DECISIVE:`Decisive`,WALKOVER:`Walkover / Defaulted`},Uv=`http://www.w3.org/2000/svg`,Wv=96,Gv=Wv/2,Kv=47,qv=31;function Jv(e,t){return{x:Gv+t*Math.cos(e),y:Gv+t*Math.sin(e)}}function Yv(e,t){let n=Jv(e,Kv),r=Jv(t,Kv),i=Jv(t,qv),a=Jv(e,qv),o=+(t-e>Math.PI);return[`M ${n.x} ${n.y}`,`A ${Kv} ${Kv} 0 ${o} 1 ${r.x} ${r.y}`,`L ${i.x} ${i.y}`,`A ${qv} ${qv} 0 ${o} 0 ${a.x} ${a.y}`,`Z`].join(` `)}function Xv(){let e=Jv(-Math.PI/2,Kv),t=Jv(Math.PI/2,Kv),n=Jv(-Math.PI/2,qv),r=Jv(Math.PI/2,qv);return[`M ${e.x} ${e.y}`,`A ${Kv} ${Kv} 0 1 1 ${t.x} ${t.y}`,`A ${Kv} ${Kv} 0 1 1 ${e.x} ${e.y}`,`L ${n.x} ${n.y}`,`A ${qv} ${qv} 0 1 0 ${r.x} ${r.y}`,`A ${qv} ${qv} 0 1 0 ${n.x} ${n.y}`,`Z`].join(` `)}function Zv(){let e=document.createElement(`div`);e.className=`chc-cd`;let t=document.createElementNS(Uv,`svg`);t.setAttribute(`viewBox`,`0 0 ${Wv} ${Wv}`),t.setAttribute(`class`,`chc-cd__svg`),t.setAttribute(`role`,`img`);let n={};for(let e of Fv){let r=document.createElementNS(Uv,`path`);r.setAttribute(`class`,`chc-cd__arc`),r.setAttribute(`data-bucket`,e),t.appendChild(r);let i=document.createElementNS(Uv,`title`);r.appendChild(i),n[e]=r}let r=document.createElement(`div`);return r.className=`chc-cd__total`,e.appendChild(t),e.appendChild(r),{element:e,update:i=>{let a=zv(i);if(e.style.display=a>0?`inline-flex`:`none`,!a)return;let o=Fv.filter(e=>i[e]>0),s=-Math.PI/2;for(let e of Fv){let t=i[e],r=n[e],c=r.querySelector(`title`);if(t===0){r.removeAttribute(`d`),c&&(c.textContent=``);continue}if(o.length===1)r.setAttribute(`d`,Xv());else{let e=t/a,n=s+e*Math.PI*2;r.setAttribute(`d`,Yv(s,n)),s=n}c&&(c.textContent=`${Hv[e]}: ${t}`)}r.textContent=String(a),t.setAttribute(`aria-label`,`Competitiveness across ${a} matches`)}}}function Qv(e){let{segments:t,onSegmentClick:n}=e,r=document.createElement(`div`);r.className=`chc-sb`;let i={},a={};for(let{key:e,label:o,color:s}of t){i[e]=o;let t=document.createElement(`div`);t.className=`chc-sb__seg`,t.dataset.key=e,t.style.setProperty(`--seg-bg`,s),n&&(t.classList.add(`is-clickable`),t.setAttribute(`role`,`button`),t.addEventListener(`click`,()=>n(e))),a[e]=t,r.appendChild(t)}return{element:r,update:e=>{let n=t.reduce((t,n)=>t+(e[n.key]||0),0);if(r.style.display=n>0?`flex`:`none`,n)for(let{key:n}of t){let t=a[n],r=e[n]||0;r===0?(t.style.flex=`0 0 0`,t.style.padding=`0`,t.textContent=``,t.removeAttribute(`title`)):(t.style.flex=`${r} 1 0`,t.style.padding=`0 4px`,t.textContent=String(r),t.title=`${i[n]}: ${r}`)}},setActive:e=>{r.classList.toggle(`has-active`,!!e);for(let{key:n}of t)a[n].classList.toggle(`is-active`,n===e)}}}var $v={cornerBadges:[`status`,`publishedBadge`,`embargoBadge`],body:[`title`,`drawTypeLabel`,`matchUpProgress`],footer:[`drawSize`,`entries`,`matchUpFormat`,`flightNumber`,`ratings`],showVisualization:!1};function ey(e){return e?{cornerBadges:e.cornerBadges??$v.cornerBadges,body:e.body??$v.body,footer:e.footer??$v.footer,showVisualization:e.showVisualization??$v.showVisualization}:$v}var ty=()=>`chc-dc-card`,ny=()=>`chc-dc-card--clickable`,ry=()=>`chc-dc-corner-badges`,iy=()=>`chc-dc-status-pill`,ay=()=>`chc-dc-secondary-badge`,oy=()=>`chc-dc-body`,sy=()=>`chc-dc-viz`,cy=()=>`chc-dc-title-row`,ly=()=>`chc-dc-title`,uy=()=>`chc-dc-draw-type`,dy=()=>`chc-dc-meta`,fy=()=>`chc-dc-footer`,py=()=>`chc-dc-chip`,my=()=>`chc-dc-progress`,hy=()=>`chc-dc-progress-bar`,gy=()=>`chc-dc-progress-fill`,_y=()=>`chc-dc-card chc-dc-skeleton`,vy=()=>`chc-dc-skeleton-line`;function yy(e,t,n){let r=ey(t),i=document.createElement(`div`);if(i.className=ty(),i.dataset.drawId=e.drawId,e.eventId&&(i.dataset.eventId=e.eventId),n?.onClick&&(i.classList.add(ny()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showVisualization&&e.visualization){let t=document.createElement(`div`);t.className=sy(),t.appendChild(e.visualization),i.appendChild(t)}return(r.body.length||r.cornerBadges.length)&&i.appendChild(Iy(e,r)),r.footer.length&&i.appendChild(Ly(e,r)),i}function by(e){if(!e.status)return null;let t=document.createElement(`div`);return t.className=iy(),t.dataset.kind=e.status.kind,t.textContent=e.status.label,t}function xy(e){if(!e.published)return null;let t=document.createElement(`div`);return t.className=ay(),t.dataset.kind=`published`,t.textContent=`Published`,t}function Sy(e){if(!e.embargoActive)return null;let t=document.createElement(`div`);return t.className=ay(),t.dataset.kind=`embargo`,t.textContent=`Embargo`,t}function Cy(e,t){return e===`status`?by(t):e===`publishedBadge`?xy(t):e===`embargoBadge`?Sy(t):null}function wy(e,t){let n=[];for(let r of t){let t=Cy(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=ry();for(let e of n)r.appendChild(e);return r}function Ty(e){if(!e.drawName)return null;let t=document.createElement(`div`);return t.className=ly(),t.textContent=e.drawName,t.title=e.drawName,t}function Ey(e){if(!e.drawTypeLabel)return null;let t=document.createElement(`div`);return t.className=uy(),t.textContent=e.drawTypeLabel,t}function Dy(e){let t=document.createElement(`span`);return t.className=py(),t.textContent=e,t}function Oy(e){return typeof e.drawSize==`number`?Dy(`Size ${e.drawSize}`):null}function ky(e){return typeof e.entryCount==`number`?Dy(`${e.entryCount} ${e.entryCount===1?`entry`:`entries`}`):null}function Ay(e){return e.matchUpFormat?Dy(e.matchUpFormat):null}function jy(e){return typeof e.flightNumber==`number`?Dy(`Flight ${e.flightNumber}`):null}function My(e){let t=[];if(typeof e.utrAvg==`number`&&t.push(`UTR ${e.utrAvg.toFixed(2)}`),typeof e.wtnAvg==`number`&&t.push(`WTN ${e.wtnAvg.toFixed(2)}`),!t.length)return null;let n=document.createElement(`div`);return n.className=dy(),n.textContent=t.join(` · `),n}function Ny(e){if(!e.matchUpCounts||e.matchUpCounts.total===0)return null;let{total:t,completed:n}=e.matchUpCounts,r=Math.round(n/t*100),i=document.createElement(`div`);i.className=my();let a=document.createElement(`div`);a.className=dy(),a.textContent=`${n}/${t} matches · ${r}%`,i.appendChild(a);let o=document.createElement(`div`);o.className=hy();let s=document.createElement(`div`);return s.className=gy(),s.style.right=`${100-r}%`,o.appendChild(s),i.appendChild(o),i}function Py(e,t){return e===`title`?Ty(t):e===`drawTypeLabel`?Ey(t):e===`drawSize`?Oy(t):e===`entries`?ky(t):e===`matchUpFormat`?Ay(t):e===`flightNumber`?jy(t):e===`ratings`?My(t):e===`matchUpProgress`?Ny(t):null}function Fy(e,t){let n=document.createElement(`div`);n.className=cy();let r=Ty(e);r&&n.appendChild(r);let i=wy(e,t);return i&&n.appendChild(i),n}function Iy(e,t){let n=document.createElement(`div`);n.className=oy();let r=t.body.includes(`title`),i=t.cornerBadges.length>0;if(i&&!r){let r=wy(e,t.cornerBadges);r&&n.appendChild(r)}for(let r of t.body){if(r===`title`&&i){n.appendChild(Fy(e,t.cornerBadges));continue}let a=Py(r,e);a&&n.appendChild(a)}return n}function Ly(e,t){let n=document.createElement(`div`);n.className=fy();for(let r of t.footer){let t=Py(r,e);t&&n.appendChild(t)}return n}function Ry(){let e=document.createElement(`div`);e.className=_y();let t=document.createElement(`div`);t.className=oy();for(let e of[`70%`,`40%`,`85%`]){let n=document.createElement(`div`);n.className=vy(),n.style.width=e,t.appendChild(n)}return e.appendChild(t),e}var zy={SINGLE_ELIMINATION:`Single Elimination`,DOUBLE_ELIMINATION:`Double Elimination`,ELIMINATION:`Elimination`,ROUND_ROBIN:`Round Robin`,ROUND_ROBIN_WITH_PLAYOFF:`Round Robin + Playoff`,COMPASS:`Compass`,FEED_IN_CHAMPIONSHIP:`Feed-In Championship`,FIRST_MATCH_LOSER_CONSOLATION:`First Match Loser Consolation`,FIRST_ROUND_LOSER_CONSOLATION:`First Round Loser Consolation`,PLAY_OFF:`Play-Off`,CURTIS_CONSOLATION:`Curtis Consolation`,AD_HOC:`Ad-Hoc`,OLYMPIC:`Olympic`,LUCKY_DRAW:`Lucky Draw`,STAGGERED_ENTRY:`Staggered Entry`};function By(e){if(e)return zy[e]?zy[e]:e.toLowerCase().split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Vy(e){let{matchUps:n=[]}=t.tournamentEngine.getAllDrawMatchUps({drawDefinition:e}),r=0,i=0,a=0,o=0;for(let e of n)e?.matchUpStatus!==`BYE`&&e?.matchUpStatus!==`DOUBLE_BYE`&&(r+=1,e?.winningSide?i+=1:e?.schedule?.scheduledTime&&(a+=1),e?.matchUpStatus===`IN_PROGRESS`&&(o+=1));return{total:r,completed:i,scheduled:a,inProgress:o}}function Hy(e){let t=e?.drawSize;if(typeof t==`number`)return t;let n=(e?.structures?.find(e=>e?.stage===`MAIN`))?.positionAssignments?.length;return typeof n==`number`?n:void 0}function Uy(e){if(e.cancelled)return{kind:`cancelled`,label:`Cancelled`};if(!e.generated)return{kind:`ungenerated`,label:`Not generated`};let t=e.matchUpCounts;return!t||t.total===0?{kind:`ready`,label:`Ready`}:t.completed===t.total?{kind:`completed`,label:`Completed`}:t.inProgress>0||t.completed>0?{kind:`in-progress`,label:`In progress`}:{kind:`ready`,label:`Ready`}}function Wy(e,t){let n=Array.isArray(e?.structures)&&e.structures.length>0,r=t?.matchUpStats??(t?.lightMode||!n?void 0:Vy(e)),i=e?.drawStatus===`CANCELLED`,a=t?.statusOverride===void 0?Uy({generated:n,cancelled:i,matchUpCounts:r}):t.statusOverride;return{drawId:e?.drawId??``,drawName:e?.drawName??``,drawType:e?.drawType,drawTypeLabel:By(e?.drawType),drawSize:Hy(e),entryCount:t?.entryCount,matchUpFormat:e?.matchUpFormat,flightNumber:e?.flightNumber,matchUpCounts:r,generated:n,published:t?.published,embargoActive:t?.embargoActive,utrAvg:t?.utrAvg,wtnAvg:t?.wtnAvg,status:a,eventId:t?.eventId}}var Gy={showImage:!0,cornerBadges:[`status`,`eventTypeBadge`,`genderBadge`],body:[`title`,`categoryLabel`,`drawSummary`],footer:[`playerCount`,`matchUpProgress`]},Ky=15;function qy(e){return e?{showImage:e.showImage??Gy.showImage,cornerBadges:e.cornerBadges??Gy.cornerBadges,body:e.body??Gy.body,footer:e.footer??Gy.footer}:Gy}var Jy=()=>`chc-ec-card`,Yy=()=>`chc-ec-card--clickable`,Xy=()=>`chc-ec-image`,Zy=()=>`chc-ec-image-img`,Qy=()=>`chc-ec-image-svg`,$y=()=>`chc-ec-image-placeholder`,eb=()=>`chc-ec-corner-badges`,tb=()=>`chc-ec-status-pill`,nb=()=>`chc-ec-eventtype-badge`,rb=()=>`chc-ec-gender-badge`,ib=()=>`chc-ec-body`,ab=()=>`chc-ec-title`,ob=()=>`chc-ec-category`,sb=()=>`chc-ec-draw-summary`,cb=()=>`chc-ec-date-range`,lb=()=>`chc-ec-footer`,ub=()=>`chc-ec-player-count`,db=()=>`chc-ec-progress`,fb=()=>`chc-ec-progress-meta`,pb=()=>`chc-ec-progress-bar`,mb=()=>`chc-ec-progress-fill`,hb=()=>`chc-ec-updated-at`,gb=()=>`chc-ec-card chc-ec-skeleton`,_b=()=>`chc-ec-skeleton-line`,vb=()=>`chc-ec-skeleton-block`;function yb(e,t,n){let r=qy(t),i=document.createElement(`div`);return i.className=Jy(),i.dataset.eventId=e.eventId,n?.onClick&&(i.classList.add(Yy()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showImage!==!1&&i.appendChild(xb(e,r)),r.body.length&&i.appendChild(Fb(e,r)),r.footer.length&&i.appendChild(Ib(e,r)),i}function bb(e,t){let n=bh(t.courtSvgSport,Qy());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=$y(),e.appendChild(r)}function xb(e,t){let n=document.createElement(`div`);if(n.className=Xy(),e.eventImageURL){let t=document.createElement(`img`);t.className=Zy(),t.src=e.eventImageURL,t.alt=e.eventName||``,t.loading=`lazy`,t.addEventListener(`error`,()=>{t.remove(),bb(n,e)}),n.appendChild(t)}else bb(n,e);if(t.cornerBadges.length){let r=Eb(e,t.cornerBadges);r&&n.appendChild(r)}return n}function Sb(e){if(!e.status)return null;let t=document.createElement(`div`);return t.className=tb(),t.dataset.kind=e.status.kind,t.textContent=e.status.label,t}function Cb(e){if(!e.eventType)return null;let t=document.createElement(`div`);return t.className=nb(),t.dataset.kind=e.eventType,t.textContent=e.eventType,t}function wb(e){if(!e.gender)return null;let t=document.createElement(`div`);return t.className=rb(),t.dataset.kind=e.gender,t.textContent=e.gender===`MALE`?`M`:e.gender===`FEMALE`?`W`:`X`,t}function Tb(e,t){return e===`status`?Sb(t):e===`eventTypeBadge`?Cb(t):e===`genderBadge`?wb(t):null}function Eb(e,t){let n=[];for(let r of t){let t=Tb(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=eb();for(let e of n)r.appendChild(e);return r}function Db(e){if(!e.eventName)return null;let t=document.createElement(`div`);return t.className=ab(),t.textContent=e.eventName,t.title=e.eventName,t}function Ob(e){if(!e.categoryLabel)return null;let t=document.createElement(`div`);return t.className=ob(),t.textContent=e.categoryLabel,t}function kb(e){if(!e.drawSummary)return null;let t=document.createElement(`div`);return t.className=sb(),t.textContent=e.drawSummary,t}function Ab(e){if(!e.dateRangeFormatted)return null;let t=document.createElement(`div`);return t.className=cb(),t.textContent=e.dateRangeFormatted,t}function jb(e){if(!e.updatedAt)return null;let t=document.createElement(`div`);t.className=hb();let n=new Date(e.updatedAt);return t.textContent=Number.isNaN(n.getTime())?e.updatedAt:n.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`}),t}function Mb(e){if(typeof e.entryCount!=`number`)return null;let t=document.createElement(`div`);return t.className=ub(),t.textContent=`${e.entryCount} ${e.entryCount===1?`player`:`players`}`,t}function Nb(e){if(!e.matchUpCounts||e.matchUpCounts.total===0)return null;let{total:t,completed:n}=e.matchUpCounts,r=Math.round(n/t*100),i=document.createElement(`div`);i.className=db();let a=document.createElement(`div`);a.className=fb(),a.textContent=`${n}/${t} matches · ${r}%`,i.appendChild(a);let o=document.createElement(`div`);o.className=pb();let s=document.createElement(`div`);return s.className=mb(),s.style.right=`${100-r}%`,o.appendChild(s),i.appendChild(o),i}function Pb(e,t){return e===`title`?Db(t):e===`categoryLabel`?Ob(t):e===`drawSummary`?kb(t):e===`dateRange`?Ab(t):e===`updatedAt`?jb(t):e===`playerCount`?Mb(t):e===`matchUpProgress`?Nb(t):null}function Fb(e,t){let n=document.createElement(`div`);n.className=ib();for(let r of t.body){let t=Pb(r,e);t&&n.appendChild(t)}return n}function Ib(e,t){let n=document.createElement(`div`);n.className=lb();for(let r of t.footer){let t=Pb(r,e);t&&n.appendChild(t)}return n}function Lb(e){let t=qy(e);return Ih({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:gb(),imageClass:Xy(),bodyClass:ib(),footerClass:lb(),blockClass:vb(),lineClass:_b()})}function Rb(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function zb(e,t,n){return!t||!n?!1:t.getTime()<=e.getTime()&&e.getTime()<=n.getTime()}function Bb(e,t=new Date){if(e.allDrawsCancelled)return{kind:`cancelled`,label:`Cancelled`};let n=e.matchUpCounts;if(n&&n.total>0&&n.completed===n.total)return{kind:`completed`,label:`Completed`};let r=Rb(e.startDate),i=Rb(e.endDate);if(n&&(n.inProgress>0||zb(t,r,i)&&n.total>0))return{kind:`live`,label:`Live`};let a=e.drawCount??0;return a>0&&(e.hasDraftState||e.hasSeedsOnlyDraw)?{kind:`drawing`,label:`Drawing`}:a===0&&(e.entryCount??0)>0?{kind:`entries-open`,label:`Entries Open`}:r&&t.getTime()<r.getTime()?{kind:`upcoming`,label:`Upcoming`}:null}var Vb=`eventImage`,Hb=`DRAFT_STATE`;function Ub(e){if(!e)return;let t=String(e).toUpperCase();if(t===`SINGLES`||t===`DOUBLES`||t===`TEAM`||t===`HYBRID`)return t}function Wb(e){if(!e)return;let t=String(e).toUpperCase();if(t===`M`||t===`MALE`)return`MALE`;if(t===`F`||t===`FEMALE`)return`FEMALE`;if(t===`MIXED`||t===`X`)return`MIXED`}function Gb(e){if(!e)return;let t=Kb(e.categoryName);if(t)return t;if(typeof e.ageMin==`number`&&typeof e.ageMax==`number`)return e.ageMin===e.ageMax?`Age ${e.ageMin}`:`Age ${e.ageMin}–${e.ageMax}`;let n=Kb(e.ageCategoryCode);if(n)return n;if(e.ratingMin&&e.ratingMax)return`Rating ${e.ratingMin}–${e.ratingMax}`}function Kb(e){if(typeof e!=`string`)return;let t=e.trim();if(t&&!/^[-—–_]+$/.test(t))return t}function qb(e){if(!e.length)return;let t=e.find(Boolean);if(!t)return;let n=[];return typeof t.drawSize==`number`&&n.push(String(t.drawSize)),t.drawType&&n.push(String(t.drawType)),e.length>1&&n.push(`+${e.length-1}`),n.length?n.join(` `):void 0}function Jb(e){let{matchUps:n=[]}=t.tournamentEngine.allEventMatchUps({event:e,inContext:!1})??{},r=0,i=0,a=0,o=0;for(let e of n)e?.matchUpStatus!==`BYE`&&e?.matchUpStatus!==`DOUBLE_BYE`&&(r+=1,e?.winningSide?i+=1:e?.schedule?.scheduledTime&&(a+=1),e?.matchUpStatus===`IN_PROGRESS`&&(o+=1));return{total:r,completed:i,scheduled:a,inProgress:o}}function Yb(e){if(e?.draftState!=null)return!0;let t=e?.extensions;return Array.isArray(t)?t.some(e=>e?.name===Hb):!1}function Xb(e){return e.some(e=>e?.automated?.seedsOnly===!0||Yb(e))}function Zb(e){return e.length!==0&&e.every(e=>e?.drawStatus===`CANCELLED`)}var Qb=new Set([`DIRECT_ACCEPTANCE`,`DA`,`DIRECT_CONFIRMED`,`DC`,`ACCEPTED`,`A`,`ENTERED`,`PE`,`QUALIFIER`,`Q`,`WILDCARD`,`WC`]);function $b(e){if(!e.length)return 0;let t=0;for(let n of e)Qb.has(String(n?.entryStatus))&&(t+=1);return t}function ex(e,t){let n=Array.isArray(e?.drawDefinitions)?e.drawDefinitions:[],r=Array.isArray(e?.entries)?e.entries:[],i=Array.isArray(e?.onlineResources)?e.onlineResources:void 0,a=t?.matchUpStats??(t?.lightMode?void 0:Jb(e)),o=t?.statusOverride===void 0?Bb({allDrawsCancelled:Zb(n),drawCount:n.length,entryCount:$b(r),startDate:e?.startDate,endDate:e?.endDate,matchUpCounts:a,hasDraftState:n.some(Yb),hasSeedsOnlyDraw:Xb(n)},t?.now):t.statusOverride;return{eventId:e?.eventId??``,eventName:e?.eventName??``,eventAbbreviation:e?.eventAbbreviation,categoryLabel:Gb(e?.category),eventType:Ub(e?.eventType),gender:Wb(e?.gender),drawCount:n.length||void 0,drawSummary:qb(n),entryCount:$b(r)||void 0,matchUpCounts:a,startDate:e?.startDate,endDate:e?.endDate,dateRangeFormatted:Mh(e?.startDate,e?.endDate),status:o,eventImageURL:e?.eventImageURL??Ph(i,Vb),courtSvgSport:e?.courtSvgSport??Fh(i)??t?.sport,updatedAt:e?.updatedAt}}var tx=()=>`chc-hil-container`,nx=()=>`chc-hil-form`,rx=()=>`chc-hil-header`,ix=()=>`chc-hil-title`,ax=()=>`chc-hil-tabs`,ox=()=>`chc-hil-tab`,sx=()=>`chc-hil-tab--active`,cx=()=>`chc-hil-field`,lx=()=>`chc-hil-label`,ux=()=>`chc-hil-input`,dx=()=>`chc-hil-row`,fx=()=>`chc-hil-submit`,px=()=>`chc-hil-message`,mx=()=>`chc-hil-message--error`,hx=()=>`chc-hil-message--success`,gx=()=>`chc-hil-switch-mode`;function _x(e){return e.replace(/\/+$/,``)}async function vx(e,t,n,r=fetch){let i=_x(e)+t,a;try{a=await r(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})}catch(e){throw{kind:`network`,cause:e}}let o=null;try{o=await a.json()}catch(e){if(a.ok)throw{kind:`parse`,cause:e}}if(!a.ok)throw{kind:`http`,status:a.status,body:o};return o}function yx(e,t,n){return vx(e,`/auth/hiveid/signup`,t,n)}function bx(e,t,n){return vx(e,`/auth/hiveid/verify-existing`,t,n)}function xx(e,t,n){return vx(e,`/auth/hiveid/magic-link`,t,n)}function Sx(e,t,n){return vx(e,`/auth/hiveid/magic-link/consume`,t,n)}function Cx(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind!==`http`||t.status!==409?!1:t.body?.code===`EXISTING_USER`}var wx=[{value:`M`,label:`Male`},{value:`F`,label:`Female`}],Tx=`signup`,Ex=`login`,Dx=`magic-link`,Ox=[Tx,Ex,Dx],kx=`hiveid:authenticated`,Ax={[Tx]:`Sign up`,[Ex]:`Log in`,[Dx]:`Email link`},jx={[Tx]:`Create your CourtHive identity`,[Ex]:`Log in to CourtHive`,[Dx]:`Email me a sign-in link`};function Mx(e){if(!e?.cfsBaseUrl)throw Error(`buildHiveIDLogin: cfsBaseUrl is required`);let t=e.mode??`signup`,n=!1,r=document.createElement(`div`);r.className=tx(),r.dataset.hiveidLogin=`true`;let i=document.createElement(`div`);i.className=rx();let a=document.createElement(`h2`);a.className=ix(),i.appendChild(a);let o=document.createElement(`div`);o.className=ax(),i.appendChild(o);let s={};Ox.forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=ox(),t.textContent=Ax[e],t.dataset.mode=e,t.onclick=()=>w(e),o.appendChild(t),s[e]=t}),r.appendChild(i);let c=document.createElement(`form`);c.className=nx(),c.noValidate=!0,r.appendChild(c);let l=document.createElement(`div`);l.className=px(),l.hidden=!0,r.appendChild(l);function u(e,t=`info`){l.textContent=e,l.className=px(),t===`error`&&l.classList.add(mx()),t===`success`&&l.classList.add(hx()),l.hidden=!e}function d(){u(``)}function f(e,t,n=`text`,r=``){let i=document.createElement(`div`);i.className=cx();let a=document.createElement(`label`);a.className=lx(),a.textContent=t,a.htmlFor=`chc-hil-${e}`;let o=document.createElement(`input`);return o.id=`chc-hil-${e}`,o.name=e,o.type=n,o.value=r,o.className=ux(),o.required=!0,i.appendChild(a),i.appendChild(o),c.appendChild(i),o}function p(){let e=document.createElement(`div`);return e.className=dx(),c.appendChild(e),e}function m(e){let t=document.createElement(`button`);return t.type=`submit`,t.className=fx(),t.textContent=e,c.appendChild(t),t}function h(e,t,n){let r=document.createElement(`div`);r.className=gx();let i=document.createElement(`button`);i.type=`button`,i.textContent=n,i.onclick=()=>w(t),r.append(e+` `,i),c.appendChild(r)}function g(e){if(e.note){let t=document.createElement(`p`);t.className=lx(),t.textContent=e.note,c.appendChild(t)}let t=null;if(e.providers.length>1){let n=document.createElement(`div`);n.className=cx();let r=document.createElement(`label`);r.className=lx(),r.textContent=`Provider`,r.htmlFor=`chc-hil-fedProvider`;let i=document.createElement(`select`);i.id=`chc-hil-fedProvider`,i.className=ux(),e.providers.forEach(e=>{let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,i.appendChild(t)}),n.append(r,i),c.appendChild(n),t=i}let n=document.createElement(`div`);n.className=cx();let r=document.createElement(`label`);r.className=lx(),r.textContent=e.idLabel??`Player ID`,r.htmlFor=`chc-hil-federationId`;let i=document.createElement(`input`);i.id=`chc-hil-federationId`,i.type=`text`,i.className=ux(),n.append(r,i),c.appendChild(n);let a=e.providers[0]?.value??``;return()=>{let e=i.value.trim();if(!e)return null;let n=t?t.value:a;return n?{provider:n,externalId:e}:null}}function _(e){if(e.note){let t=document.createElement(`p`);t.className=lx(),t.textContent=e.note,c.appendChild(t)}let t=e.required!==!1,n=document.createElement(`div`);n.className=cx();let r=document.createElement(`label`);r.className=lx(),r.textContent=e.dobLabel??`Date of birth`,r.htmlFor=`chc-hil-birthDate`;let i=document.createElement(`input`);i.id=`chc-hil-birthDate`,i.type=`date`,i.required=t,i.className=ux(),n.append(r,i),c.appendChild(n);let a=document.createElement(`div`);a.className=cx();let o=document.createElement(`label`);o.className=lx(),o.textContent=e.sexLabel??`Sex`,o.htmlFor=`chc-hil-sex`;let s=document.createElement(`select`);s.id=`chc-hil-sex`,s.required=t,s.className=ux();let l=document.createElement(`option`);return l.value=``,l.textContent=`Select…`,s.appendChild(l),(e.sexOptions??wx).forEach(e=>{let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,s.appendChild(t)}),a.append(o,s),c.appendChild(a),()=>Fx({birthDate:i.value,sex:s.value})}function v(e){r.dispatchEvent(new CustomEvent(kx,{detail:e,bubbles:!0}))}function y(e,t){return async r=>{if(r.preventDefault(),!n){n=!0,e.disabled=!0,d();try{await t()}finally{n=!1,e.disabled=!1}}}}async function b(t,n,r,i={}){let a=t.value.trim(),o=n.value.trim(),s=r.value.trim();if(!a||!o||!s){u(`Email, first name, and last name are required.`,`error`);return}let{federationIds:c,birthDate:l,sex:d,provider:f,requirePii:p}=i;if(p&&(!l||!d)){u(`Date of birth and sex are required.`,`error`);return}try{let t=await yx(e.cfsBaseUrl,{email:a,firstName:o,lastName:s,federationIds:c,birthDate:l,sex:d,provider:f},e.fetchImpl);if(t.status===`candidate`){u(`We found possible matches — please log in with your existing account.`,`info`),w(`login`);return}v({token:t.token,refreshToken:t.refreshToken,personId:t.personId,cached:t.cached}),u(`Welcome to CourtHive.`,`success`)}catch(e){if(Cx(e)){u(`That email already has a CourtHive account — please verify your password.`,`info`),w(`login`);return}u(Lx(e)??`Sign-up failed. Please try again.`,`error`)}}async function x(t,n){let r=t.value.trim(),i=n.value;if(!r||!i){u(`Email and password are required.`,`error`);return}try{let t=await bx(e.cfsBaseUrl,{email:r,password:i},e.fetchImpl);v({token:t.token,refreshToken:t.refreshToken,personId:t.personId,cached:t.cached??Ix()}),u(`Signed in.`,`success`)}catch(e){u(Lx(e)??`Sign-in failed. Please check your password.`,`error`)}}async function S(t){let n=t.value.trim();if(!n){u(`Email is required.`,`error`);return}try{await xx(e.cfsBaseUrl,{email:n},e.fetchImpl),u(`If ${n} is registered, a sign-in link is on its way.`,`success`)}catch(e){u(Lx(e)??`Could not send link. Please try again.`,`error`)}}function C(){if(c.replaceChildren(),a.textContent=jx[t],Ox.forEach(e=>{s[e].classList.toggle(sx(),e===t)}),t===`signup`){let t=p(),n=document.createElement(`input`);n.id=`chc-hil-firstName`,n.type=`text`,n.placeholder=`First name`,n.required=!0,n.className=ux();let r=document.createElement(`input`);r.id=`chc-hil-lastName`,r.type=`text`,r.placeholder=`Last name`,r.required=!0,r.className=ux();let i=document.createElement(`div`);i.className=cx();let a=document.createElement(`label`);a.textContent=`First name`,a.className=lx(),a.htmlFor=n.id,i.append(a,n);let o=document.createElement(`div`);o.className=cx();let s=document.createElement(`label`);s.textContent=`Last name`,s.className=lx(),s.htmlFor=r.id,o.append(s,r),t.append(i,o);let l=f(`email`,`Email`,`email`,e.defaultEmail??``),u=e.federationIdCapture?g(e.federationIdCapture):()=>null,d=e.dobSexCapture?_(e.dobSexCapture):()=>({}),v=!!e.dobSexCapture&&e.dobSexCapture.required!==!1,x=m(`Create account`);c.onsubmit=y(x,()=>b(l,n,r,{federationIds:Px(u(),e.federationIds),...d(),provider:e.provider,requirePii:v})),h(`Already have an account?`,`login`,`Log in`)}else if(t===`login`){let t=f(`email`,`Email`,`email`,e.defaultEmail??``),n=f(`password`,`Password`,`password`),r=m(`Log in`);c.onsubmit=y(r,()=>x(t,n)),h(`Forgot your password?`,`magic-link`,`Email me a link`)}else{let t=f(`email`,`Email`,`email`,e.defaultEmail??``),n=m(`Send link`);c.onsubmit=y(n,()=>S(t)),h(`Have a password?`,`login`,`Log in instead`)}}function w(e){e!==t&&(t=e,d(),C())}function T(){return t}function E(e){let t=t=>e(t.detail);return r.addEventListener(kx,t),()=>r.removeEventListener(kx,t)}return C(),{root:r,setMode:w,getMode:T,onAuthenticated:E}}async function Nx(e,t,n){let r=await Sx(e,{code:t},n);return{token:r.token,refreshToken:r.refreshToken,personId:r.personId,cached:r.cached??Ix()}}function Px(e,t){let n=[],r=new Set,i=e=>{if(!e?.provider||!e?.externalId)return;let t=`${e.provider}::${e.externalId}`;r.has(t)||(r.add(t),n.push({provider:e.provider,externalId:e.externalId}))};return(t??[]).forEach(i),i(e),n.length?n:void 0}function Fx(e){let t={},n=e.birthDate?.trim(),r=e.sex?.trim();return n&&(t.birthDate=n),r&&(t.sex=r),t}function Ix(){return{standardFamilyName:null,standardGivenName:null,birthDate:null,sex:null,nationalityCode:null}}function Lx(e){if(!e||typeof e!=`object`)return null;if(e.kind===`http`){let t=e.body;if(t?.message&&typeof t.message==`string`)return t.message;if(typeof t?.status==`string`&&t.status===`incomplete`)return`We need a bit more information to identify you.`}return e.kind===`network`?`Could not reach CourtHive. Check your connection.`:null}var Rx={name:`courthive-components`,packageManager:`pnpm@11.20.0`,version:`3.12.2`,engines:{node:`>=22`},description:`Components for competitions projects`,files:[`dist`],main:`./dist/courthive-components.umd.js`,module:`./dist/courthive-components.es.js`,types:`./dist/index.d.ts`,exports:{".":{types:`./dist/index.d.ts`,import:`./dist/courthive-components.es.js`,require:`./dist/courthive-components.umd.js`},"./dist/*":`./dist/*`},repository:{type:`git`,url:`git+https://github.com/CourtHive/courthive-components.git`},keywords:[`tournament`,`match`,`score`,`vanillajs`,`bracket`],author:`Charles Allen`,license:`MIT`,bugs:{url:`https://github.com/CourtHive/courthive-components/issues`},homepage:`https://courthive.github.io/courthive-component`,scripts:{commits:`git log $(git describe --tags --abbrev=0)..HEAD --oneline --no-merges --pretty=format:'%s: %h' | sed '/courthive-components/d'`,release:`npm run release:patch`,test:`vitest run`,"test:watch":`vitest`,"test:ui":`vitest --ui`,dev:`vite`,build:`tsc && vite build`,"check-types":`tsc --noEmit`,prepublishOnly:`pnpm build`,preview:`vite preview`,storybook:`storybook dev -p 6006`,"build-storybook":`storybook build`,"test-storybook":`test-storybook --url http://localhost:6006`,"deploy-storybook":`gh-pages -d storybook-static`,"pre-commit":`lint-staged`,predeploy:`pnpm build-storybook`,lint:`eslint src --cache --max-warnings 0`,"lint:fix":`eslint src --fix --cache`,"lint:report":`eslint src & eslint --cache src -f json > eslint-report.json`,format:`prettier --write src`,"release:major":`npm run commits && npm version $(semver $npm_package_version -i major) && git push && git push --tags`,"release:minor":`npm run commits && npm version $(semver $npm_package_version -i minor) && git push && git push --tags`,"release:patch":`npm run commits && npm version $(semver $npm_package_version -i patch) && git push && git push --tags`,"release:beta":`npm run commits && npm version $(semver $npm_package_version -i prerelease --preid beta) && git push && git push --tags`,"patch:beta":`npm run commits && npm version $(semver $npm_package_version -i prerelease --preid beta) && npm publish --tag beta`},"lint-staged":{"*.{js,ts}":`eslint --cache --fix`,"*":`prettier --ignore-unknown --write`},devDependencies:{"@chromatic-com/storybook":`^5.0.0`,"@commitlint/cli":`21.2.1`,"@commitlint/config-conventional":`21.2.0`,"@eslint/js":`^10.0.1`,"@fortawesome/fontawesome-free":`^7.2.0`,"@storybook/addon-docs":`^10.2.17`,"@storybook/html-vite":`^10.2.17`,"@storybook/test-runner":`^0.24.0`,"@types/d3":`^7.4.3`,"@types/vanillajs-datepicker":`^1.3.5`,"@typescript-eslint/eslint-plugin":`8.66.0`,"@typescript-eslint/parser":`8.66.0`,"@vitest/browser-playwright":`^4.0.16`,"@vitest/coverage-v8":`^4.0.16`,"@vitest/ui":`^4.0.16`,eslint:`10.8.0`,"eslint-plugin-sonarjs":`4.2.0`,"eslint-plugin-storybook":`^10.2.17`,"gh-pages":`6.3.0`,globals:`^17.3.0`,"happy-dom":`^20.8.3`,husky:`9.1.7`,"lint-staged":`17.3.0`,playwright:`^1.57.0`,prettier:`^3.8.1`,semver:`7.8.5`,storybook:`^10.2.17`,"tabulator-tables":`6.5.2`,"tods-competition-factory":`6.19.0`,typescript:`^6.0.2`,vite:`8.2.0`,"vite-plugin-dts":`^5.0.0`,vitest:`^4.0.16`},dependencies:{"@tiptap/core":`^3.22.2`,"@tiptap/extension-color":`^3.22.2`,"@tiptap/extension-highlight":`^3.22.2`,"@tiptap/extension-text-align":`^3.22.2`,"@tiptap/extension-text-style":`^3.22.2`,"@tiptap/extension-youtube":`^3.22.2`,"@tiptap/starter-kit":`^3.22.2`,awesomplete:`1.1.7`,"class-variance-authority":`0.7.1`,classnames:`2.5.1`,d3:`^7.9.0`,dayjs:`1.11.21`,"focus-trap":`^8.0.0`,"timepicker-ui":`^4.1.2`,"tippy.js":`6.3.7`,"vanillajs-datepicker":`1.3.4`},peerDependencies:{"tods-competition-factory":`^6.0.0`}};function zx(){return Rx.version}var Bx={SET3_S6_TB7:`SET3-S:6/TB7`,SET3_S6_TB7_F_TB10:`SET3-S:6/TB7-F:TB10`,SET3_S6_TB10:`SET3-S:6/TB10`,SET3_S6_F_TB10:`SET3-S:6-F:TB10`,SET3_S6_TB7_NOAD:`SET3-S:6/TB7NOAD`,SET3_S8_TB7:`SET3-S:8/TB7`,SET3_S8_TB7_AT7:`SET3-S:8/TB7@7`,SET3_S4_TB7:`SET3-S:4/TB7`,SET3_S4_TB7_F_TB10:`SET3-S:4/TB7-F:TB10`,SET3_S4_TB5_AT3_F_TB10:`SET3-S:4/TB5@3-F:TB10`,SET5_S6_TB7:`SET5-S:6/TB7`,SET5_S6_TB7_F_TB10:`SET5-S:6/TB7-F:TB10`,SET1_S6_TB7:`SET1-S:6/TB7`,SET1_S6_TB10:`SET1-S:6/TB10`,SET1_S6_TB7_AT5:`SET1-S:6/TB7@5`,SET1_S8_TB7:`SET1-S:8/TB7`,SET1_S4_TB7:`SET1-S:4/TB7`,SET1_S5_TB9_AT4:`SET1-S:5/TB9@4`,SET1_S_TB7:`SET1-S:T7`,SET1_S_TB10:`SET1-S:TB10`,SET1_S_TB21:`SET1-S:T21`,SET1_S8:`SET1-S:8`,SET1_S10:`SET1-S:10`,FAST4:`SET5-S:4/NOAD`,SET3X_T10A_TB1:`SET3XA-S:T10-F:TB1`,SET3X_T10A_TB1_NOAD:`SET3XA-S:T10-F:TB1NOAD`,SET4X_T10A_TB1:`SET4XA-S:T10-F:TB1`};function Vx(e,t,n){if(!e)return{elements:{}};let r={};for(let i of t||[]){if(!i?.label||i.hide)continue;let t=document.createElement(`button`);i.id&&(r[i.id]=t,t.id=i.id),t.style.marginRight=`.5em`,t.className=`button font-medium`,i.intent&&t.classList.add(i.intent),t.innerHTML=i.label,i.disabled&&(t.disabled=!0),t.onclick=e=>{e.stopPropagation(),!e.target.disabled&&V(i.onClick)&&i.onClick(),n&&V(n)&&n()},e.appendChild(t)}return{elements:r}}var Hx=(e,t)=>n=>n?.trim().length>=e&&(!t||n?.trim().length<=t);function Ux(e){return t.tools.isConvertableInteger(e)&&parseInt(e.toString())>=0}var Wx=(e,t)=>n=>Ux(n)&&Number(n)>=e&&Number(n)<=t,Gx=e=>/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)(?=.*?[#?!@$%^&*-]).{8,12}$/.test(e);function Kx(e){return t.tools.dateTime.dateValidation.test(e)}var qx=(e,t)=>n=>{let r=(n||``).trim().split(` `).length;return r>=e&&(!t||r<=t)},Jx=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,Yx=e=>Jx.exec(e),Xx=_({dateValidator:()=>Kx,emailValidator:()=>Yx,nameValidator:()=>Hx,numericRange:()=>Wx,numericValidator:()=>Ux,passwordValidator:()=>Gx,wordValidator:()=>qx}),Zx=class{constructor({tournamentRecord:e,drawId:n,structureId:r,eventId:i}){this.tournamentRecord=e,this.drawId=n,this.structureId=r,this.eventId=i||e.events?.[0]?.eventId,t.tournamentEngine.setState(e)}setRenderCallback(e){this.renderCallback=e}getDrawEntryParticipantIds(){let{event:e,drawDefinition:n}=t.tournamentEngine.getEvent({drawId:this.drawId})||{};if(!e)return[];let{flightProfile:r}=t.tournamentEngine.getFlightProfile({eventId:this.eventId})||{};return(r?.flights?.find(e=>e.drawId===this.drawId)?.drawEntries||n?.entries||[]).map(e=>e.participantId).filter(Boolean)}getAllParticipants(){t.tournamentEngine.setState(this.tournamentRecord);let e=this.getDrawEntryParticipantIds();if(!e.length)return[];let{participants:n=[]}=t.tournamentEngine.getParticipants({participantFilters:{participantIds:e}})||{};return n.map(e=>({participantId:e.participantId,participantName:e.participantName,participantType:e.participantType,person:e.person,individualParticipants:e.individualParticipants}))}getAvailableParticipants(){t.tournamentEngine.setState(this.tournamentRecord);let e=this.getAllParticipants(),{assignedParticipantIds:n=[]}=t.tournamentEngine.getAssignedParticipantIds({drawId:this.drawId})||{};return e.filter(e=>!n.includes(e.participantId))}removeAssignment({drawPosition:e}){t.tournamentEngine.setState(this.tournamentRecord);let n=this.getMatchUps().find(t=>t.sides?.some(t=>t.drawPosition===e))?.sides?.find(t=>t.drawPosition===e)?.bye===!0,r=t.tournamentEngine.removeDrawPositionAssignment({drawId:this.drawId,structureId:this.structureId,drawPosition:e});if(r.error)return{success:!1,error:r.error};let{tournamentRecord:i}=t.tournamentEngine.getState()||{};return this.tournamentRecord=i,n&&this.renderCallback&&this.renderCallback(),{success:!0}}assignParticipant({drawPosition:e,participantId:n}){t.tournamentEngine.setState(this.tournamentRecord);let r=t.tournamentEngine.assignDrawPosition({drawId:this.drawId,structureId:this.structureId,drawPosition:e,participantId:n});if(r.error)return{success:!1,error:r.error};let{tournamentRecord:i}=t.tournamentEngine.getState()||{};return this.tournamentRecord=i,this.focusDrawPosition=e+1,this.renderCallback&&this.renderCallback(),{success:!0}}getAndClearFocusDrawPosition(){let e=this.focusDrawPosition;return this.focusDrawPosition=void 0,e}assignBye({drawPosition:e}){t.tournamentEngine.setState(this.tournamentRecord);let n=t.tournamentEngine.assignDrawPositionBye({drawId:this.drawId,structureId:this.structureId,drawPosition:e});if(n.error)return{success:!1,error:n.error};let{tournamentRecord:r}=t.tournamentEngine.getState()||{};return this.tournamentRecord=r,this.focusDrawPosition=e+1,this.renderCallback&&this.renderCallback(),{success:!0}}assignQualifier({drawPosition:e}){t.tournamentEngine.setState(this.tournamentRecord);let n=t.tournamentEngine.assignDrawPosition({drawId:this.drawId,structureId:this.structureId,drawPosition:e,qualifier:!0});if(n.error)return{success:!1,error:n.error};let{tournamentRecord:r}=t.tournamentEngine.getState()||{};return this.tournamentRecord=r,this.focusDrawPosition=e+1,this.renderCallback&&this.renderCallback(),{success:!0}}getMatchUps(){t.tournamentEngine.setState(this.tournamentRecord);let{eventData:e}=t.tournamentEngine.getEventData({eventId:this.eventId})||{},n=(e?.drawsData?.find(e=>e.drawId===this.drawId))?.structures?.find(e=>e.structureId===this.structureId)?.roundMatchUps;return n?Object.values(n).flat():[]}getState(){return this.tournamentRecord}getContext(){return{drawId:this.drawId,structureId:this.structureId}}},Qx=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="14" height="14" fill="currentColor"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"/></svg>`,$x=new WeakMap;function eS(e,t){let n=document.createElement(`div`);n.style.cssText=`position: relative; flex: 1; display: flex; min-width: 0;`,e.style.paddingRight=`28px`,n.appendChild(e);let r=document.createElement(`button`);r.type=`button`,r.setAttribute(`aria-label`,`Clear search`),r.style.cssText=[`position: absolute`,`right: 8px`,`top: 50%`,`transform: translateY(-50%)`,`background: transparent`,`border: 0`,`padding: 2px`,`cursor: pointer`,`display: none`,`align-items: center`,`justify-content: center`,`line-height: 0`,`opacity: 0.55`,`color: currentColor`].join(`; `),r.innerHTML=Qx,r.addEventListener(`mouseenter`,()=>r.style.opacity=`0.9`),r.addEventListener(`mouseleave`,()=>r.style.opacity=`0.55`),r.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),t(),i()});let i=()=>{r.style.display=e.value?`inline-flex`:`none`};return e.addEventListener(`keyup`,n=>{n.key===`Escape`&&e.value&&(t(),i())}),e.addEventListener(`input`,i),$x.set(n,i),n.appendChild(r),n}function tS(e){$x.get(e)?.()}function nS(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function rS(e,t){return e==null||t==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function iS(e){let t,n,r;e.length===2?(t=e===nS||e===rS?e:aS,n=e,r=e):(t=nS,n=(t,n)=>nS(e(t),n),r=(t,n)=>e(t)-n);function i(e,r,i=0,a=e.length){if(i<a){if(t(r,r)!==0)return a;do{let t=i+a>>>1;n(e[t],r)<0?i=t+1:a=t}while(i<a)}return i}function a(e,r,i=0,a=e.length){if(i<a){if(t(r,r)!==0)return a;do{let t=i+a>>>1;n(e[t],r)<=0?i=t+1:a=t}while(i<a)}return i}function o(e,t,n=0,a=e.length){let o=i(e,t,n,a-1);return o>n&&r(e[o-1],t)>-r(e[o],t)?o-1:o}return{left:i,center:o,right:a}}function aS(){return 0}function oS(e){return e===null?NaN:+e}var sS=iS(nS),cS=sS.right;sS.left,iS(oS).center;function lS(e,t){let n,r;if(t===void 0)for(let t of e)t!=null&&(n===void 0?t>=t&&(n=r=t):(n>t&&(n=t),r<t&&(r=t)));else{let i=-1;for(let a of e)(a=t(a,++i,e))!=null&&(n===void 0?a>=a&&(n=r=a):(n>a&&(n=a),r<a&&(r=a)))}return[n,r]}var uS=class extends Map{constructor(e,t=mS){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:t}}),e!=null)for(let[t,n]of e)this.set(t,n)}get(e){return super.get(dS(this,e))}has(e){return super.has(dS(this,e))}set(e,t){return super.set(fS(this,e),t)}delete(e){return super.delete(pS(this,e))}};function dS({_intern:e,_key:t},n){let r=t(n);return e.has(r)?e.get(r):n}function fS({_intern:e,_key:t},n){let r=t(n);return e.has(r)?e.get(r):(e.set(r,n),n)}function pS({_intern:e,_key:t},n){let r=t(n);return e.has(r)&&(n=e.get(r),e.delete(r)),n}function mS(e){return typeof e==`object`&&e?e.valueOf():e}var hS=Math.sqrt(50),gS=Math.sqrt(10),_S=Math.sqrt(2);function vS(e,t,n){let r=(t-e)/Math.max(0,n),i=Math.floor(Math.log10(r)),a=r/10**i,o=a>=hS?10:a>=gS?5:a>=_S?2:1,s,c,l;return i<0?(l=10**-i/o,s=Math.round(e*l),c=Math.round(t*l),s/l<e&&++s,c/l>t&&--c,l=-l):(l=10**i*o,s=Math.round(e/l),c=Math.round(t/l),s*l<e&&++s,c*l>t&&--c),c<s&&.5<=n&&n<2?vS(e,t,n*2):[s,c,l]}function yS(e,t,n){if(t=+t,e=+e,n=+n,!(n>0))return[];if(e===t)return[e];let r=t<e,[i,a,o]=r?vS(t,e,n):vS(e,t,n);if(!(a>=i))return[];let s=a-i+1,c=Array(s);if(r){if(o<0)for(let e=0;e<s;++e)c[e]=(a-e)/-o;else for(let e=0;e<s;++e)c[e]=(a-e)*o}else if(o<0)for(let e=0;e<s;++e)c[e]=(i+e)/-o;else for(let e=0;e<s;++e)c[e]=(i+e)*o;return c}function bS(e,t,n){return t=+t,e=+e,n=+n,vS(e,t,n)[2]}function xS(e,t,n){t=+t,e=+e,n=+n;let r=t<e,i=r?bS(t,e,n):bS(e,t,n);return(r?-1:1)*(i<0?1/-i:i)}function SS(e,t){let n;if(t===void 0)for(let t of e)t!=null&&(n<t||n===void 0&&t>=t)&&(n=t);else{let r=-1;for(let i of e)(i=t(i,++r,e))!=null&&(n<i||n===void 0&&i>=i)&&(n=i)}return n}function CS(e,t,n){e=+e,t=+t,n=(i=arguments.length)<2?(t=e,e=0,1):i<3?1:+n;for(var r=-1,i=Math.max(0,Math.ceil((t-e)/n))|0,a=Array(i);++r<i;)a[r]=e+r*n;return a}function wS(e){return e}var TS=1,ES=2,DS=3,OS=4,kS=1e-6;function AS(e){return`translate(`+e+`,0)`}function jS(e){return`translate(0,`+e+`)`}function MS(e){return t=>+e(t)}function NS(e,t){return t=Math.max(0,e.bandwidth()-t*2)/2,e.round()&&(t=Math.round(t)),n=>+e(n)+t}function PS(){return!this.__axis}function FS(e,t){var n=[],r=null,i=null,a=6,o=6,s=3,c=typeof window<`u`&&window.devicePixelRatio>1?0:.5,l=e===TS||e===OS?-1:1,u=e===OS||e===ES?`x`:`y`,d=e===TS||e===DS?AS:jS;function f(f){var p=r??(t.ticks?t.ticks.apply(t,n):t.domain()),m=i??(t.tickFormat?t.tickFormat.apply(t,n):wS),h=Math.max(a,0)+s,g=t.range(),_=+g[0]+c,v=+g[g.length-1]+c,y=(t.bandwidth?NS:MS)(t.copy(),c),b=f.selection?f.selection():f,x=b.selectAll(`.domain`).data([null]),S=b.selectAll(`.tick`).data(p,t).order(),C=S.exit(),w=S.enter().append(`g`).attr(`class`,`tick`),T=S.select(`line`),E=S.select(`text`);x=x.merge(x.enter().insert(`path`,`.tick`).attr(`class`,`domain`).attr(`stroke`,`currentColor`)),S=S.merge(w),T=T.merge(w.append(`line`).attr(`stroke`,`currentColor`).attr(u+`2`,l*a)),E=E.merge(w.append(`text`).attr(`fill`,`currentColor`).attr(u,l*h).attr(`dy`,e===TS?`0em`:e===DS?`0.71em`:`0.32em`)),f!==b&&(x=x.transition(f),S=S.transition(f),T=T.transition(f),E=E.transition(f),C=C.transition(f).attr(`opacity`,kS).attr(`transform`,function(e){return isFinite(e=y(e))?d(e+c):this.getAttribute(`transform`)}),w.attr(`opacity`,kS).attr(`transform`,function(e){var t=this.parentNode.__axis;return d((t&&isFinite(t=t(e))?t:y(e))+c)})),C.remove(),x.attr(`d`,e===OS||e===ES?o?`M`+l*o+`,`+_+`H`+c+`V`+v+`H`+l*o:`M`+c+`,`+_+`V`+v:o?`M`+_+`,`+l*o+`V`+c+`H`+v+`V`+l*o:`M`+_+`,`+c+`H`+v),S.attr(`opacity`,1).attr(`transform`,function(e){return d(y(e)+c)}),T.attr(u+`2`,l*a),E.attr(u,l*h).text(m),b.filter(PS).attr(`fill`,`none`).attr(`font-size`,10).attr(`font-family`,`sans-serif`).attr(`text-anchor`,e===ES?`start`:e===OS?`end`:`middle`),b.each(function(){this.__axis=y})}return f.scale=function(e){return arguments.length?(t=e,f):t},f.ticks=function(){return n=Array.from(arguments),f},f.tickArguments=function(e){return arguments.length?(n=e==null?[]:Array.from(e),f):n.slice()},f.tickValues=function(e){return arguments.length?(r=e==null?null:Array.from(e),f):r&&r.slice()},f.tickFormat=function(e){return arguments.length?(i=e,f):i},f.tickSize=function(e){return arguments.length?(a=o=+e,f):a},f.tickSizeInner=function(e){return arguments.length?(a=+e,f):a},f.tickSizeOuter=function(e){return arguments.length?(o=+e,f):o},f.tickPadding=function(e){return arguments.length?(s=+e,f):s},f.offset=function(e){return arguments.length?(c=+e,f):c},f}function IS(e){return FS(DS,e)}function LS(e){return FS(OS,e)}var RS={value:()=>{}};function zS(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new BS(n)}function BS(e){this._=e}function VS(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}BS.prototype=zS.prototype={constructor:BS,on:function(e,t){var n=this._,r=VS(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=HS(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=US(n[i],e.name,t);else if(t==null)for(i in n)n[i]=US(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new BS(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function HS(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function US(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=RS,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var WS={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function GS(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),WS.hasOwnProperty(t)?{space:WS[t],local:e}:e}function KS(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function qS(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function JS(e){var t=GS(e);return(t.local?qS:KS)(t)}function YS(){}function XS(e){return e==null?YS:function(){return this.querySelector(e)}}function ZS(e){typeof e!=`function`&&(e=XS(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new zw(r,this._parents)}function QS(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function $S(){return[]}function eC(e){return e==null?$S:function(){return this.querySelectorAll(e)}}function tC(e){return function(){return QS(e.apply(this,arguments))}}function nC(e){e=typeof e==`function`?tC(e):eC(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new zw(r,i)}function rC(e){return function(){return this.matches(e)}}function iC(e){return function(t){return t.matches(e)}}var aC=Array.prototype.find;function oC(e){return function(){return aC.call(this.children,e)}}function sC(){return this.firstElementChild}function cC(e){return this.select(e==null?sC:oC(typeof e==`function`?e:iC(e)))}var lC=Array.prototype.filter;function uC(){return Array.from(this.children)}function dC(e){return function(){return lC.call(this.children,e)}}function fC(e){return this.selectAll(e==null?uC:dC(typeof e==`function`?e:iC(e)))}function pC(e){typeof e!=`function`&&(e=rC(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new zw(r,this._parents)}function mC(e){return Array(e.length)}function hC(){return new zw(this._enter||this._groups.map(mC),this._parents)}function gC(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}gC.prototype={constructor:gC,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function _C(e){return function(){return e}}function vC(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new gC(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function yC(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new gC(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function bC(e){return e.__data__}function xC(e,t){if(!arguments.length)return Array.from(this,bC);var n=t?yC:vC,r=this._parents,i=this._groups;typeof e!=`function`&&(e=_C(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=SC(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new zw(o,r),o._enter=s,o._exit=c,o}function SC(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function CC(){return new zw(this._exit||this._groups.map(mC),this._parents)}function wC(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function TC(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new zw(s,this._parents)}function EC(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function DC(e){e||=OC;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new zw(i,this._parents).order()}function OC(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function kC(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function AC(){return Array.from(this)}function jC(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function MC(){let e=0;for(let t of this)++e;return e}function NC(){return!this.node()}function PC(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function FC(e){return function(){this.removeAttribute(e)}}function IC(e){return function(){this.removeAttributeNS(e.space,e.local)}}function LC(e,t){return function(){this.setAttribute(e,t)}}function RC(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function zC(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function BC(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function VC(e,t){var n=GS(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?IC:FC:typeof t==`function`?n.local?BC:zC:n.local?RC:LC)(n,t))}function HC(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function UC(e){return function(){this.style.removeProperty(e)}}function WC(e,t,n){return function(){this.style.setProperty(e,t,n)}}function GC(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function KC(e,t,n){return arguments.length>1?this.each((t==null?UC:typeof t==`function`?GC:WC)(e,t,n??``)):qC(this.node(),e)}function qC(e,t){return e.style.getPropertyValue(t)||HC(e).getComputedStyle(e,null).getPropertyValue(t)}function JC(e){return function(){delete this[e]}}function YC(e,t){return function(){this[e]=t}}function XC(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function ZC(e,t){return arguments.length>1?this.each((t==null?JC:typeof t==`function`?XC:YC)(e,t)):this.node()[e]}function QC(e){return e.trim().split(/^|\s+/)}function $C(e){return e.classList||new ew(e)}function ew(e){this._node=e,this._names=QC(e.getAttribute(`class`)||``)}ew.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function tw(e,t){for(var n=$C(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function nw(e,t){for(var n=$C(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function rw(e){return function(){tw(this,e)}}function iw(e){return function(){nw(this,e)}}function aw(e,t){return function(){(t.apply(this,arguments)?tw:nw)(this,e)}}function ow(e,t){var n=QC(e+``);if(arguments.length<2){for(var r=$C(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?aw:t?rw:iw)(n,t))}function sw(){this.textContent=``}function cw(e){return function(){this.textContent=e}}function lw(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function uw(e){return arguments.length?this.each(e==null?sw:(typeof e==`function`?lw:cw)(e)):this.node().textContent}function dw(){this.innerHTML=``}function fw(e){return function(){this.innerHTML=e}}function pw(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function mw(e){return arguments.length?this.each(e==null?dw:(typeof e==`function`?pw:fw)(e)):this.node().innerHTML}function hw(){this.nextSibling&&this.parentNode.appendChild(this)}function gw(){return this.each(hw)}function _w(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function vw(){return this.each(_w)}function yw(e){var t=typeof e==`function`?e:JS(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function bw(){return null}function xw(e,t){var n=typeof e==`function`?e:JS(e),r=t==null?bw:typeof t==`function`?t:XS(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function Sw(){var e=this.parentNode;e&&e.removeChild(this)}function Cw(){return this.each(Sw)}function ww(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Tw(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Ew(e){return this.select(e?Tw:ww)}function Dw(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function Ow(e){return function(t){e.call(this,t,this.__data__)}}function kw(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function Aw(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function jw(e,t,n){return function(){var r=this.__on,i,a=Ow(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function Mw(e,t,n){var r=kw(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?jw:Aw,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function Nw(e,t,n){var r=HC(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function Pw(e,t){return function(){return Nw(this,e,t)}}function Fw(e,t){return function(){return Nw(this,e,t.apply(this,arguments))}}function Iw(e,t){return this.each((typeof t==`function`?Fw:Pw)(e,t))}function*Lw(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var Rw=[null];function zw(e,t){this._groups=e,this._parents=t}function Bw(){return new zw([[document.documentElement]],Rw)}function Vw(){return this}zw.prototype=Bw.prototype={constructor:zw,select:ZS,selectAll:nC,selectChild:cC,selectChildren:fC,filter:pC,data:xC,enter:hC,exit:CC,join:wC,merge:TC,selection:Vw,order:EC,sort:DC,call:kC,nodes:AC,node:jC,size:MC,empty:NC,each:PC,attr:VC,style:KC,property:ZC,classed:ow,text:uw,html:mw,raise:gw,lower:vw,append:yw,insert:xw,remove:Cw,clone:Ew,datum:Dw,on:Mw,dispatch:Iw,[Symbol.iterator]:Lw};function Hw(e){return typeof e==`string`?new zw([[document.querySelector(e)]],[document.documentElement]):new zw([[e]],Rw)}function Uw(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Ww(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function Gw(){}var Kw=.7,qw=1/Kw,Jw=`\\s*([+-]?\\d+)\\s*`,Yw=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,Xw=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,Zw=/^#([0-9a-f]{3,8})$/,Qw=RegExp(`^rgb\\(${Jw},${Jw},${Jw}\\)$`),$w=RegExp(`^rgb\\(${Xw},${Xw},${Xw}\\)$`),eT=RegExp(`^rgba\\(${Jw},${Jw},${Jw},${Yw}\\)$`),tT=RegExp(`^rgba\\(${Xw},${Xw},${Xw},${Yw}\\)$`),nT=RegExp(`^hsl\\(${Yw},${Xw},${Xw}\\)$`),rT=RegExp(`^hsla\\(${Yw},${Xw},${Xw},${Yw}\\)$`),iT={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Uw(Gw,lT,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:aT,formatHex:aT,formatHex8:oT,formatHsl:sT,formatRgb:cT,toString:cT});function aT(){return this.rgb().formatHex()}function oT(){return this.rgb().formatHex8()}function sT(){return ST(this).formatHsl()}function cT(){return this.rgb().formatRgb()}function lT(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=Zw.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?uT(t):n===3?new mT(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?dT(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?dT(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Qw.exec(e))?new mT(t[1],t[2],t[3],1):(t=$w.exec(e))?new mT(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=eT.exec(e))?dT(t[1],t[2],t[3],t[4]):(t=tT.exec(e))?dT(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=nT.exec(e))?xT(t[1],t[2]/100,t[3]/100,1):(t=rT.exec(e))?xT(t[1],t[2]/100,t[3]/100,t[4]):iT.hasOwnProperty(e)?uT(iT[e]):e===`transparent`?new mT(NaN,NaN,NaN,0):null}function uT(e){return new mT(e>>16&255,e>>8&255,e&255,1)}function dT(e,t,n,r){return r<=0&&(e=t=n=NaN),new mT(e,t,n,r)}function fT(e){return e instanceof Gw||(e=lT(e)),e?(e=e.rgb(),new mT(e.r,e.g,e.b,e.opacity)):new mT}function pT(e,t,n,r){return arguments.length===1?fT(e):new mT(e,t,n,r??1)}function mT(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}Uw(mT,pT,Ww(Gw,{brighter(e){return e=e==null?qw:qw**+e,new mT(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Kw:Kw**+e,new mT(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new mT(yT(this.r),yT(this.g),yT(this.b),vT(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:hT,formatHex:hT,formatHex8:gT,formatRgb:_T,toString:_T}));function hT(){return`#${bT(this.r)}${bT(this.g)}${bT(this.b)}`}function gT(){return`#${bT(this.r)}${bT(this.g)}${bT(this.b)}${bT((isNaN(this.opacity)?1:this.opacity)*255)}`}function _T(){let e=vT(this.opacity);return`${e===1?`rgb(`:`rgba(`}${yT(this.r)}, ${yT(this.g)}, ${yT(this.b)}${e===1?`)`:`, ${e})`}`}function vT(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function yT(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function bT(e){return e=yT(e),(e<16?`0`:``)+e.toString(16)}function xT(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new wT(e,t,n,r)}function ST(e){if(e instanceof wT)return new wT(e.h,e.s,e.l,e.opacity);if(e instanceof Gw||(e=lT(e)),!e)return new wT;if(e instanceof wT)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new wT(o,s,c,e.opacity)}function CT(e,t,n,r){return arguments.length===1?ST(e):new wT(e,t,n,r??1)}function wT(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}Uw(wT,CT,Ww(Gw,{brighter(e){return e=e==null?qw:qw**+e,new wT(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Kw:Kw**+e,new wT(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new mT(DT(e>=240?e-240:e+120,i,r),DT(e,i,r),DT(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new wT(TT(this.h),ET(this.s),ET(this.l),vT(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=vT(this.opacity);return`${e===1?`hsl(`:`hsla(`}${TT(this.h)}, ${ET(this.s)*100}%, ${ET(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function TT(e){return e=(e||0)%360,e<0?e+360:e}function ET(e){return Math.max(0,Math.min(1,e||0))}function DT(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var OT=e=>()=>e;function kT(e,t){return function(n){return e+n*t}}function AT(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function jT(e){return(e=+e)==1?MT:function(t,n){return n-t?AT(t,n,e):OT(isNaN(t)?n:t)}}function MT(e,t){var n=t-e;return n?kT(e,n):OT(isNaN(e)?t:e)}var NT=(function e(t){var n=jT(t);function r(e,t){var r=n((e=pT(e)).r,(t=pT(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=MT(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function PT(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function FT(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function IT(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=GT(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function LT(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function RT(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function zT(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=GT(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var BT=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,VT=new RegExp(BT.source,`g`);function HT(e){return function(){return e}}function UT(e){return function(t){return e(t)+``}}function WT(e,t){var n=BT.lastIndex=VT.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=BT.exec(e))&&(i=VT.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:RT(r,i)})),n=VT.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?UT(c[0].x):HT(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function GT(e,t){var n=typeof t,r;return t==null||n===`boolean`?OT(t):(n===`number`?RT:n===`string`?(r=lT(t))?(t=r,NT):WT:t instanceof lT?NT:t instanceof Date?LT:FT(t)?PT:Array.isArray(t)?IT:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?zT:RT)(e,t)}function KT(e,t){return e=+e,t=+t,function(n){return Math.round(e*(1-n)+t*n)}}var qT=180/Math.PI,JT={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function YT(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*qT,skewX:Math.atan(c)*qT,scaleX:o,scaleY:s}}var XT;function ZT(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?JT:YT(t.a,t.b,t.c,t.d,t.e,t.f)}function QT(e){return e==null||(XT||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),XT.setAttribute(`transform`,e),!(e=XT.transform.baseVal.consolidate()))?JT:(e=e.matrix,YT(e.a,e.b,e.c,e.d,e.e,e.f))}function $T(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:RT(e,i)},{i:c-2,x:RT(r,a)})}else(i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:RT(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:RT(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:RT(e,n)},{i:s-2,x:RT(t,r)})}else(n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var eE=$T(ZT,`px, `,`px)`,`deg)`),tE=$T(QT,`, `,`)`,`)`),nE=0,rE=0,iE=0,aE=1e3,oE,sE,cE=0,lE=0,uE=0,dE=typeof performance==`object`&&performance.now?performance:Date,fE=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function pE(){return lE||=(fE(mE),dE.now()+uE)}function mE(){lE=0}function hE(){this._call=this._time=this._next=null}hE.prototype=gE.prototype={constructor:hE,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?pE():+n)+(t==null?0:+t),!this._next&&sE!==this&&(sE?sE._next=this:oE=this,sE=this),this._call=e,this._time=n,xE()},stop:function(){this._call&&(this._call=null,this._time=1/0,xE())}};function gE(e,t,n){var r=new hE;return r.restart(e,t,n),r}function _E(){pE(),++nE;for(var e=oE,t;e;)(t=lE-e._time)>=0&&e._call.call(void 0,t),e=e._next;--nE}function vE(){lE=(cE=dE.now())+uE,nE=rE=0;try{_E()}finally{nE=0,bE(),lE=0}}function yE(){var e=dE.now(),t=e-cE;t>aE&&(uE-=t,cE=e)}function bE(){for(var e,t=oE,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:oE=n);sE=e,xE(r)}function xE(e){nE||(rE&&=clearTimeout(rE),e-lE>24?(e<1/0&&(rE=setTimeout(vE,e-dE.now()-uE)),iE&&=clearInterval(iE)):(iE||=(cE=dE.now(),setInterval(yE,aE)),nE=1,fE(vE)))}function SE(e,t,n){var r=new hE;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var CE=zS(`start`,`end`,`cancel`,`interrupt`),wE=[];function TE(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;kE(e,n,{name:t,index:r,group:i,on:CE,tween:wE,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function EE(e,t){var n=OE(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function DE(e,t){var n=OE(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function OE(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function kE(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=gE(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return SE(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(SE(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function AE(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function jE(e){return this.each(function(){AE(this,e)})}function ME(e,t){var n,r;return function(){var i=DE(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function NE(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=DE(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function PE(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=OE(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?ME:NE)(n,e,t))}function FE(e,t,n){var r=e._id;return e.each(function(){var e=DE(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return OE(e,r).value[t]}}function IE(e,t){var n;return(typeof t==`number`?RT:t instanceof lT?NT:(n=lT(t))?(t=n,NT):WT)(e,t)}function LE(e){return function(){this.removeAttribute(e)}}function RE(e){return function(){this.removeAttributeNS(e.space,e.local)}}function zE(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function BE(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function VE(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function HE(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function UE(e,t){var n=GS(e),r=n===`transform`?tE:IE;return this.attrTween(e,typeof t==`function`?(n.local?HE:VE)(n,r,FE(this,`attr.`+e,t)):t==null?(n.local?RE:LE)(n):(n.local?BE:zE)(n,r,t))}function WE(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function GE(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function KE(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&GE(e,i)),n}return i._value=t,i}function qE(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&WE(e,i)),n}return i._value=t,i}function JE(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=GS(e);return this.tween(n,(r.local?KE:qE)(r,t))}function YE(e,t){return function(){EE(this,e).delay=+t.apply(this,arguments)}}function XE(e,t){return t=+t,function(){EE(this,e).delay=t}}function ZE(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?YE:XE)(t,e)):OE(this.node(),t).delay}function QE(e,t){return function(){DE(this,e).duration=+t.apply(this,arguments)}}function $E(e,t){return t=+t,function(){DE(this,e).duration=t}}function eD(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?QE:$E)(t,e)):OE(this.node(),t).duration}function tD(e,t){if(typeof t!=`function`)throw Error();return function(){DE(this,e).ease=t}}function nD(e){var t=this._id;return arguments.length?this.each(tD(t,e)):OE(this.node(),t).ease}function rD(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();DE(this,e).ease=n}}function iD(e){if(typeof e!=`function`)throw Error();return this.each(rD(this._id,e))}function aD(e){typeof e!=`function`&&(e=rC(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new PD(r,this._parents,this._name,this._id)}function oD(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new PD(o,this._parents,this._name,this._id)}function sD(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function cD(e,t,n){var r,i,a=sD(t)?EE:DE;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function lD(e,t){var n=this._id;return arguments.length<2?OE(this.node(),n).on.on(e):this.each(cD(n,e,t))}function uD(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function dD(){return this.on(`end.remove`,uD(this._id))}function fD(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=XS(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,TE(l[f],t,n,f,l,OE(u,n)));return new PD(a,this._parents,t,n)}function pD(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=eC(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=OE(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&TE(p,t,n,h,f,m);a.push(f),o.push(u)}return new PD(a,o,t,n)}var mD=Bw.prototype.constructor;function hD(){return new mD(this._groups,this._parents)}function gD(e,t){var n,r,i;return function(){var a=qC(this,e),o=(this.style.removeProperty(e),qC(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function _D(e){return function(){this.style.removeProperty(e)}}function vD(e,t,n){var r,i=n+``,a;return function(){var o=qC(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function yD(e,t,n){var r,i,a;return function(){var o=qC(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),qC(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function bD(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=DE(this,e),l=c.on,u=c.value[a]==null?s||=_D(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function xD(e,t,n){var r=(e+=``)==`transform`?eE:IE;return t==null?this.styleTween(e,gD(e,r)).on(`end.style.`+e,_D(e)):typeof t==`function`?this.styleTween(e,yD(e,r,FE(this,`style.`+e,t))).each(bD(this._id,e)):this.styleTween(e,vD(e,r,t),n).on(`end.style.`+e,null)}function SD(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function CD(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&SD(e,a,n)),r}return a._value=t,a}function wD(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,CD(e,t,n??``))}function TD(e){return function(){this.textContent=e}}function ED(e){return function(){var t=e(this);this.textContent=t??``}}function DD(e){return this.tween(`text`,typeof e==`function`?ED(FE(this,`text`,e)):TD(e==null?``:e+``))}function OD(e){return function(t){this.textContent=e.call(this,t)}}function kD(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&OD(r)),t}return r._value=e,r}function AD(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,kD(e))}function jD(){for(var e=this._name,t=this._id,n=FD(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=OE(c,t);TE(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new PD(r,this._parents,e,n)}function MD(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=DE(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var ND=0;function PD(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function FD(){return++ND}var ID=Bw.prototype;PD.prototype={constructor:PD,select:fD,selectAll:pD,selectChild:ID.selectChild,selectChildren:ID.selectChildren,filter:aD,merge:oD,selection:hD,transition:jD,call:ID.call,nodes:ID.nodes,node:ID.node,size:ID.size,empty:ID.empty,each:ID.each,on:lD,attr:UE,attrTween:JE,style:xD,styleTween:wD,text:DD,textTween:AD,remove:dD,tween:PE,delay:ZE,duration:eD,ease:nD,easeVarying:iD,end:MD,[Symbol.iterator]:ID[Symbol.iterator]};function LD(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var RD={time:null,delay:0,duration:250,ease:LD};function zD(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function BD(e){var t,n;e instanceof PD?(t=e._id,e=e._name):(t=FD(),(n=RD).time=pE(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&TE(c,e,t,l,o,n||zD(c,t));return new PD(r,this._parents,e,t)}Bw.prototype.interrupt=jE,Bw.prototype.transition=BD;var{abs:VD,max:HD,min:UD}=Math;[`w`,`e`].map(WD),[`n`,`s`].map(WD),[`n`,`w`,`e`,`s`,`nw`,`ne`,`sw`,`se`].map(WD);function WD(e){return{type:e}}var GD=Math.PI,KD=2*GD,qD=1e-6,JD=KD-qD;function YD(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function XD(e){let t=Math.floor(e);if(!(t>=0))throw Error(`invalid digits: ${e}`);if(t>15)return YD;let n=10**t;return function(e){this._+=e[0];for(let t=1,r=e.length;t<r;++t)this._+=Math.round(arguments[t]*n)/n+e[t]}}var ZD=class{constructor(e){this._x0=this._y0=this._x1=this._y1=null,this._=``,this._append=e==null?YD:XD(e)}moveTo(e,t){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(e,t){this._append`L${this._x1=+e},${this._y1=+t}`}quadraticCurveTo(e,t,n,r){this._append`Q${+e},${+t},${this._x1=+n},${this._y1=+r}`}bezierCurveTo(e,t,n,r,i,a){this._append`C${+e},${+t},${+n},${+r},${this._x1=+i},${this._y1=+a}`}arcTo(e,t,n,r,i){if(e=+e,t=+t,n=+n,r=+r,i=+i,i<0)throw Error(`negative radius: ${i}`);let a=this._x1,o=this._y1,s=n-e,c=r-t,l=a-e,u=o-t,d=l*l+u*u;if(this._x1===null)this._append`M${this._x1=e},${this._y1=t}`;else if(d>qD){if(!(Math.abs(u*s-c*l)>qD)||!i)this._append`L${this._x1=e},${this._y1=t}`;else{let f=n-a,p=r-o,m=s*s+c*c,h=f*f+p*p,g=Math.sqrt(m),_=Math.sqrt(d),v=i*Math.tan((GD-Math.acos((m+d-h)/(2*g*_)))/2),y=v/_,b=v/g;Math.abs(y-1)>qD&&this._append`L${e+y*l},${t+y*u}`,this._append`A${i},${i},0,0,${+(u*f>l*p)},${this._x1=e+b*s},${this._y1=t+b*c}`}}}arc(e,t,n,r,i,a){if(e=+e,t=+t,n=+n,a=!!a,n<0)throw Error(`negative radius: ${n}`);let o=n*Math.cos(r),s=n*Math.sin(r),c=e+o,l=t+s,u=1^a,d=a?r-i:i-r;this._x1===null?this._append`M${c},${l}`:(Math.abs(this._x1-c)>qD||Math.abs(this._y1-l)>qD)&&this._append`L${c},${l}`,n&&(d<0&&(d=d%KD+KD),d>JD?this._append`A${n},${n},0,1,${u},${e-o},${t-s}A${n},${n},0,1,${u},${this._x1=c},${this._y1=l}`:d>qD&&this._append`A${n},${n},0,${+(d>=GD)},${u},${this._x1=e+n*Math.cos(i)},${this._y1=t+n*Math.sin(i)}`)}rect(e,t,n,r){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}};ZD.prototype;function QD(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString(`en`).replace(/,/g,``):e.toString(10)}function $D(e,t){if(!isFinite(e)||e===0)return null;var n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf(`e`),r=e.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+e.slice(n+1)]}function eO(e){return e=$D(Math.abs(e)),e?e[1]:NaN}function tO(e,t){return function(n,r){for(var i=n.length,a=[],o=0,s=e[0],c=0;i>0&&s>0&&(c+s+1>r&&(s=Math.max(1,r-c)),a.push(n.substring(i-=s,i+s)),!((c+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(t)}}function nO(e){return function(t){return t.replace(/[0-9]/g,function(t){return e[+t]})}}var rO=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function iO(e){if(!(t=rO.exec(e)))throw Error(`invalid format: `+e);var t;return new aO({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}iO.prototype=aO.prototype;function aO(e){this.fill=e.fill===void 0?` `:e.fill+``,this.align=e.align===void 0?`>`:e.align+``,this.sign=e.sign===void 0?`-`:e.sign+``,this.symbol=e.symbol===void 0?``:e.symbol+``,this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?``:e.type+``}aO.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?`0`:``)+(this.width===void 0?``:Math.max(1,this.width|0))+(this.comma?`,`:``)+(this.precision===void 0?``:`.`+Math.max(0,this.precision|0))+(this.trim?`~`:``)+this.type};function oO(e){out:for(var t=e.length,n=1,r=-1,i;n<t;++n)switch(e[n]){case`.`:r=i=n;break;case`0`:r===0&&(r=n),i=n;break;default:if(!+e[n])break out;r>0&&(r=0)}return r>0?e.slice(0,r)+e.slice(i+1):e}var sO;function cO(e,t){var n=$D(e,t);if(!n)return sO=void 0,e.toPrecision(t);var r=n[0],i=n[1],a=i-(sO=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,o=r.length;return a===o?r:a>o?r+Array(a-o+1).join(`0`):a>0?r.slice(0,a)+`.`+r.slice(a):`0.`+Array(1-a).join(`0`)+$D(e,Math.max(0,t+a-1))[0]}function lO(e,t){var n=$D(e,t);if(!n)return e+``;var r=n[0],i=n[1];return i<0?`0.`+Array(-i).join(`0`)+r:r.length>i+1?r.slice(0,i+1)+`.`+r.slice(i+1):r+Array(i-r.length+2).join(`0`)}var uO={"%":(e,t)=>(e*100).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+``,d:QD,e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>lO(e*100,t),r:lO,s:cO,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function dO(e){return e}var fO=Array.prototype.map,pO=[`y`,`z`,`a`,`f`,`p`,`n`,`µ`,`m`,``,`k`,`M`,`G`,`T`,`P`,`E`,`Z`,`Y`];function mO(e){var t=e.grouping===void 0||e.thousands===void 0?dO:tO(fO.call(e.grouping,Number),e.thousands+``),n=e.currency===void 0?``:e.currency[0]+``,r=e.currency===void 0?``:e.currency[1]+``,i=e.decimal===void 0?`.`:e.decimal+``,a=e.numerals===void 0?dO:nO(fO.call(e.numerals,String)),o=e.percent===void 0?`%`:e.percent+``,s=e.minus===void 0?`−`:e.minus+``,c=e.nan===void 0?`NaN`:e.nan+``;function l(e,l){e=iO(e);var u=e.fill,d=e.align,f=e.sign,p=e.symbol,m=e.zero,h=e.width,g=e.comma,_=e.precision,v=e.trim,y=e.type;y===`n`?(g=!0,y=`g`):uO[y]||(_===void 0&&(_=12),v=!0,y=`g`),(m||u===`0`&&d===`=`)&&(m=!0,u=`0`,d=`=`);var b=(l&&l.prefix!==void 0?l.prefix:``)+(p===`$`?n:p===`#`&&/[boxX]/.test(y)?`0`+y.toLowerCase():``),x=(p===`$`?r:/[%p]/.test(y)?o:``)+(l&&l.suffix!==void 0?l.suffix:``),S=uO[y],C=/[defgprs%]/.test(y);_=_===void 0?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,_)):Math.max(0,Math.min(20,_));function w(e){var n=b,r=x,o,l,p;if(y===`c`)r=S(e)+r,e=``;else{e=+e;var w=e<0||1/e<0;if(e=isNaN(e)?c:S(Math.abs(e),_),v&&(e=oO(e)),w&&+e==0&&f!==`+`&&(w=!1),n=(w?f===`(`?f:s:f===`-`||f===`(`?``:f)+n,r=(y===`s`&&!isNaN(e)&&sO!==void 0?pO[8+sO/3]:``)+r+(w&&f===`(`?`)`:``),C){for(o=-1,l=e.length;++o<l;)if(p=e.charCodeAt(o),48>p||p>57){r=(p===46?i+e.slice(o+1):e.slice(o))+r,e=e.slice(0,o);break}}}g&&!m&&(e=t(e,1/0));var T=n.length+e.length+r.length,E=T<h?Array(h-T+1).join(u):``;switch(g&&m&&(e=t(E+e,E.length?h-r.length:1/0),E=``),d){case`<`:e=n+e+r+E;break;case`=`:e=n+E+e+r;break;case`^`:e=E.slice(0,T=E.length>>1)+n+e+r+E.slice(T);break;default:e=E+n+e+r}return a(e)}return w.toString=function(){return e+``},w}function u(e,t){var n=Math.max(-8,Math.min(8,Math.floor(eO(t)/3)))*3,r=10**-n,i=l((e=iO(e),e.type=`f`,e),{suffix:pO[8+n/3]});return function(e){return i(r*e)}}return{format:l,formatPrefix:u}}var hO,gO,_O;vO({thousands:`,`,grouping:[3],currency:[`$`,``]});function vO(e){return hO=mO(e),gO=hO.format,_O=hO.formatPrefix,hO}function yO(e){return Math.max(0,-eO(Math.abs(e)))}function bO(e,t){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(eO(t)/3)))*3-eO(Math.abs(e)))}function xO(e,t){return e=Math.abs(e),t=Math.abs(t)-e,Math.max(0,eO(t)-eO(e))+1}function SO(e){var t=0,n=e.children,r=n&&n.length;if(!r)t=1;else for(;--r>=0;)t+=n[r].value;e.value=t}function CO(){return this.eachAfter(SO)}function wO(e,t){let n=-1;for(let r of this)e.call(t,r,++n,this);return this}function TO(e,t){for(var n=this,r=[n],i,a,o=-1;n=r.pop();)if(e.call(t,n,++o,this),i=n.children)for(a=i.length-1;a>=0;--a)r.push(i[a]);return this}function EO(e,t){for(var n=this,r=[n],i=[],a,o,s,c=-1;n=r.pop();)if(i.push(n),a=n.children)for(o=0,s=a.length;o<s;++o)r.push(a[o]);for(;n=i.pop();)e.call(t,n,++c,this);return this}function DO(e,t){let n=-1;for(let r of this)if(e.call(t,r,++n,this))return r}function OO(e){return this.eachAfter(function(t){for(var n=+e(t.data)||0,r=t.children,i=r&&r.length;--i>=0;)n+=r[i].value;t.value=n})}function kO(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function AO(e){for(var t=this,n=jO(t,e),r=[t];t!==n;)t=t.parent,r.push(t);for(var i=r.length;e!==n;)r.splice(i,0,e),e=e.parent;return r}function jO(e,t){if(e===t)return e;var n=e.ancestors(),r=t.ancestors(),i=null;for(e=n.pop(),t=r.pop();e===t;)i=e,e=n.pop(),t=r.pop();return i}function MO(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function NO(){return Array.from(this)}function PO(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function FO(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*IO(){var e=this,t,n=[e],r,i,a;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,r=e.children)for(i=0,a=r.length;i<a;++i)n.push(r[i]);while(n.length)}function LO(e,t){e instanceof Map?(e=[void 0,e],t===void 0&&(t=BO)):t===void 0&&(t=zO);for(var n=new UO(e),r,i=[n],a,o,s,c;r=i.pop();)if((o=t(r.data))&&(c=(o=Array.from(o)).length))for(r.children=o,s=c-1;s>=0;--s)i.push(a=o[s]=new UO(o[s])),a.parent=r,a.depth=r.depth+1;return n.eachBefore(HO)}function RO(){return LO(this).eachBefore(VO)}function zO(e){return e.children}function BO(e){return Array.isArray(e)?e[1]:null}function VO(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function HO(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function UO(e){this.data=e,this.depth=this.height=0,this.parent=null}UO.prototype=LO.prototype={constructor:UO,count:CO,each:wO,eachAfter:EO,eachBefore:TO,find:DO,sum:OO,sort:kO,path:AO,ancestors:MO,descendants:NO,leaves:PO,links:FO,copy:RO,[Symbol.iterator]:IO};function WO(e){e.x0=Math.round(e.x0),e.y0=Math.round(e.y0),e.x1=Math.round(e.x1),e.y1=Math.round(e.y1)}function GO(e,t,n,r,i){for(var a=e.children,o,s=-1,c=a.length,l=e.value&&(r-t)/e.value;++s<c;)o=a[s],o.y0=n,o.y1=i,o.x0=t,o.x1=t+=o.value*l}function KO(){var e=1,t=1,n=0,r=!1;function i(i){var o=i.height+1;return i.x0=i.y0=n,i.x1=e,i.y1=t/o,i.eachBefore(a(t,o)),r&&i.eachBefore(WO),i}function a(e,t){return function(r){r.children&&GO(r,r.x0,e*(r.depth+1)/t,r.x1,e*(r.depth+2)/t);var i=r.x0,a=r.y0,o=r.x1-n,s=r.y1-n;o<i&&(i=o=(i+o)/2),s<a&&(a=s=(a+s)/2),r.x0=i,r.y0=a,r.x1=o,r.y1=s}}return i.round=function(e){return arguments.length?(r=!!e,i):r},i.size=function(n){return arguments.length?(e=+n[0],t=+n[1],i):[e,t]},i.padding=function(e){return arguments.length?(n=+e,i):n},i}function qO(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e)}return this}var JO=Symbol(`implicit`);function YO(){var e=new uS,t=[],n=[],r=JO;function i(i){let a=e.get(i);if(a===void 0){if(r!==JO)return r;e.set(i,a=t.push(i)-1)}return n[a%n.length]}return i.domain=function(n){if(!arguments.length)return t.slice();t=[],e=new uS;for(let r of n)e.has(r)||e.set(r,t.push(r)-1);return i},i.range=function(e){return arguments.length?(n=Array.from(e),i):n.slice()},i.unknown=function(e){return arguments.length?(r=e,i):r},i.copy=function(){return YO(t,n).unknown(r)},qO.apply(i,arguments),i}function XO(){var e=YO().unknown(void 0),t=e.domain,n=e.range,r=0,i=1,a,o,s=!1,c=0,l=0,u=.5;delete e.unknown;function d(){var e=t().length,d=i<r,f=d?i:r,p=d?r:i;a=(p-f)/Math.max(1,e-c+l*2),s&&(a=Math.floor(a)),f+=(p-f-a*(e-c))*u,o=a*(1-c),s&&(f=Math.round(f),o=Math.round(o));var m=CS(e).map(function(e){return f+a*e});return n(d?m.reverse():m)}return e.domain=function(e){return arguments.length?(t(e),d()):t()},e.range=function(e){return arguments.length?([r,i]=e,r=+r,i=+i,d()):[r,i]},e.rangeRound=function(e){return[r,i]=e,r=+r,i=+i,s=!0,d()},e.bandwidth=function(){return o},e.step=function(){return a},e.round=function(e){return arguments.length?(s=!!e,d()):s},e.padding=function(e){return arguments.length?(c=Math.min(1,l=+e),d()):c},e.paddingInner=function(e){return arguments.length?(c=Math.min(1,e),d()):c},e.paddingOuter=function(e){return arguments.length?(l=+e,d()):l},e.align=function(e){return arguments.length?(u=Math.max(0,Math.min(1,e)),d()):u},e.copy=function(){return XO(t(),[r,i]).round(s).paddingInner(c).paddingOuter(l).align(u)},qO.apply(d(),arguments)}function ZO(e){var t=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,delete e.paddingOuter,e.copy=function(){return ZO(t())},e}function QO(){return ZO(XO.apply(null,arguments).paddingInner(1))}function $O(e){return function(){return e}}function ek(e){return+e}var tk=[0,1];function nk(e){return e}function rk(e,t){return(t-=e=+e)?function(n){return(n-e)/t}:$O(isNaN(t)?NaN:.5)}function ik(e,t){var n;return e>t&&(n=e,e=t,t=n),function(n){return Math.max(e,Math.min(t,n))}}function ak(e,t,n){var r=e[0],i=e[1],a=t[0],o=t[1];return i<r?(r=rk(i,r),a=n(o,a)):(r=rk(r,i),a=n(a,o)),function(e){return a(r(e))}}function ok(e,t,n){var r=Math.min(e.length,t.length)-1,i=Array(r),a=Array(r),o=-1;for(e[r]<e[0]&&(e=e.slice().reverse(),t=t.slice().reverse());++o<r;)i[o]=rk(e[o],e[o+1]),a[o]=n(t[o],t[o+1]);return function(t){var n=cS(e,t,1,r)-1;return a[n](i[n](t))}}function sk(e,t){return t.domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown())}function ck(){var e=tk,t=tk,n=GT,r,i,a,o=nk,s,c,l;function u(){var n=Math.min(e.length,t.length);return o!==nk&&(o=ik(e[0],e[n-1])),s=n>2?ok:ak,c=l=null,d}function d(i){return i==null||isNaN(i=+i)?a:(c||=s(e.map(r),t,n))(r(o(i)))}return d.invert=function(n){return o(i((l||=s(t,e.map(r),RT))(n)))},d.domain=function(t){return arguments.length?(e=Array.from(t,ek),u()):e.slice()},d.range=function(e){return arguments.length?(t=Array.from(e),u()):t.slice()},d.rangeRound=function(e){return t=Array.from(e),n=KT,u()},d.clamp=function(e){return arguments.length?(o=e?!0:nk,u()):o!==nk},d.interpolate=function(e){return arguments.length?(n=e,u()):n},d.unknown=function(e){return arguments.length?(a=e,d):a},function(e,t){return r=e,i=t,u()}}function lk(){return ck()(nk,nk)}function uk(e,t,n,r){var i=xS(e,t,n),a;switch(r=iO(r??`,f`),r.type){case`s`:var o=Math.max(Math.abs(e),Math.abs(t));return r.precision==null&&!isNaN(a=bO(i,o))&&(r.precision=a),_O(r,o);case``:case`e`:case`g`:case`p`:case`r`:r.precision==null&&!isNaN(a=xO(i,Math.max(Math.abs(e),Math.abs(t))))&&(r.precision=a-(r.type===`e`));break;case`f`:case`%`:r.precision==null&&!isNaN(a=yO(i))&&(r.precision=a-(r.type===`%`)*2)}return gO(r)}function dk(e){var t=e.domain;return e.ticks=function(e){var n=t();return yS(n[0],n[n.length-1],e??10)},e.tickFormat=function(e,n){var r=t();return uk(r[0],r[r.length-1],e??10,n)},e.nice=function(n){n??=10;var r=t(),i=0,a=r.length-1,o=r[i],s=r[a],c,l,u=10;for(s<o&&(l=o,o=s,s=l,l=i,i=a,a=l);u-->0;){if(l=bS(o,s,n),l===c)return r[i]=o,r[a]=s,t(r);if(l>0)o=Math.floor(o/l)*l,s=Math.ceil(s/l)*l;else if(l<0)o=Math.ceil(o*l)/l,s=Math.floor(s*l)/l;else break;c=l}return e},e}function fk(){var e=lk();return e.copy=function(){return sk(e,fk())},qO.apply(e,arguments),dk(e)}function pk(e,t){e=e.slice();var n=0,r=e.length-1,i=e[n],a=e[r],o;return a<i&&(o=n,n=r,r=o,o=i,i=a,a=o),e[n]=t.floor(i),e[r]=t.ceil(a),e}var mk=new Date,hk=new Date;function gk(e,t,n,r){function i(t){return e(t=arguments.length===0?new Date:new Date(+t)),t}return i.floor=t=>(e(t=new Date(+t)),t),i.ceil=n=>(e(n=new Date(n-1)),t(n,1),e(n),n),i.round=e=>{let t=i(e),n=i.ceil(e);return e-t<n-e?t:n},i.offset=(e,n)=>(t(e=new Date(+e),n==null?1:Math.floor(n)),e),i.range=(n,r,a)=>{let o=[];if(n=i.ceil(n),a=a==null?1:Math.floor(a),!(n<r)||!(a>0))return o;let s;do o.push(s=new Date(+n)),t(n,a),e(n);while(s<n&&n<r);return o},i.filter=n=>gk(t=>{if(t>=t)for(;e(t),!n(t);)t.setTime(t-1)},(e,r)=>{if(e>=e){if(r<0)for(;++r<=0;)for(;t(e,-1),!n(e););else for(;--r>=0;)for(;t(e,1),!n(e););}}),n&&(i.count=(t,r)=>(mk.setTime(+t),hk.setTime(+r),e(mk),e(hk),Math.floor(n(mk,hk))),i.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?i.filter(r?t=>r(t)%e===0:t=>i.count(0,t)%e===0):i)),i}var _k=gk(()=>{},(e,t)=>{e.setTime(+e+t)},(e,t)=>t-e);_k.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?gk(t=>{t.setTime(Math.floor(t/e)*e)},(t,n)=>{t.setTime(+t+n*e)},(t,n)=>(n-t)/e):_k),_k.range;var vk=1e3,yk=vk*60,bk=yk*60,xk=bk*24,Sk=xk*7,Ck=xk*30,wk=xk*365,Tk=gk(e=>{e.setTime(e-e.getMilliseconds())},(e,t)=>{e.setTime(+e+t*vk)},(e,t)=>(t-e)/vk,e=>e.getUTCSeconds());Tk.range;var Ek=gk(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*vk)},(e,t)=>{e.setTime(+e+t*yk)},(e,t)=>(t-e)/yk,e=>e.getMinutes());Ek.range;var Dk=gk(e=>{e.setUTCSeconds(0,0)},(e,t)=>{e.setTime(+e+t*yk)},(e,t)=>(t-e)/yk,e=>e.getUTCMinutes());Dk.range;var Ok=gk(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*vk-e.getMinutes()*yk)},(e,t)=>{e.setTime(+e+t*bk)},(e,t)=>(t-e)/bk,e=>e.getHours());Ok.range;var kk=gk(e=>{e.setUTCMinutes(0,0,0)},(e,t)=>{e.setTime(+e+t*bk)},(e,t)=>(t-e)/bk,e=>e.getUTCHours());kk.range;var Ak=gk(e=>e.setHours(0,0,0,0),(e,t)=>e.setDate(e.getDate()+t),(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*yk)/xk,e=>e.getDate()-1);Ak.range;var jk=gk(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/xk,e=>e.getUTCDate()-1);jk.range;var Mk=gk(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/xk,e=>Math.floor(e/xk));Mk.range;function Nk(e){return gk(t=>{t.setDate(t.getDate()-(t.getDay()+7-e)%7),t.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*yk)/Sk)}var Pk=Nk(0),Fk=Nk(1),Ik=Nk(2),Lk=Nk(3),Rk=Nk(4),zk=Nk(5),Bk=Nk(6);Pk.range,Fk.range,Ik.range,Lk.range,Rk.range,zk.range,Bk.range;function Vk(e){return gk(t=>{t.setUTCDate(t.getUTCDate()-(t.getUTCDay()+7-e)%7),t.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/Sk)}var Hk=Vk(0),Uk=Vk(1),Wk=Vk(2),Gk=Vk(3),Kk=Vk(4),qk=Vk(5),Jk=Vk(6);Hk.range,Uk.range,Wk.range,Gk.range,Kk.range,qk.range,Jk.range;var Yk=gk(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,t)=>{e.setMonth(e.getMonth()+t)},(e,t)=>t.getMonth()-e.getMonth()+(t.getFullYear()-e.getFullYear())*12,e=>e.getMonth());Yk.range;var Xk=gk(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCMonth(e.getUTCMonth()+t)},(e,t)=>t.getUTCMonth()-e.getUTCMonth()+(t.getUTCFullYear()-e.getUTCFullYear())*12,e=>e.getUTCMonth());Xk.range;var Zk=gk(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t)},(e,t)=>t.getFullYear()-e.getFullYear(),e=>e.getFullYear());Zk.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:gk(t=>{t.setFullYear(Math.floor(t.getFullYear()/e)*e),t.setMonth(0,1),t.setHours(0,0,0,0)},(t,n)=>{t.setFullYear(t.getFullYear()+n*e)}),Zk.range;var Qk=gk(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t)},(e,t)=>t.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());Qk.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:gk(t=>{t.setUTCFullYear(Math.floor(t.getUTCFullYear()/e)*e),t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCFullYear(t.getUTCFullYear()+n*e)}),Qk.range;function $k(e,t,n,r,i,a){let o=[[Tk,1,vk],[Tk,5,5*vk],[Tk,15,15*vk],[Tk,30,30*vk],[a,1,yk],[a,5,5*yk],[a,15,15*yk],[a,30,30*yk],[i,1,bk],[i,3,3*bk],[i,6,6*bk],[i,12,12*bk],[r,1,xk],[r,2,2*xk],[n,1,Sk],[t,1,Ck],[t,3,3*Ck],[e,1,wk]];function s(e,t,n){let r=t<e;r&&([e,t]=[t,e]);let i=n&&typeof n.range==`function`?n:c(e,t,n),a=i?i.range(e,+t+1):[];return r?a.reverse():a}function c(t,n,r){let i=Math.abs(n-t)/r,a=iS(([,,e])=>e).right(o,i);if(a===o.length)return e.every(xS(t/wk,n/wk,r));if(a===0)return _k.every(Math.max(xS(t,n,r),1));let[s,c]=o[i/o[a-1][2]<o[a][2]/i?a-1:a];return s.every(c)}return[s,c]}var[eA,tA]=$k(Qk,Xk,Hk,Mk,kk,Dk),[nA,rA]=$k(Zk,Yk,Pk,Ak,Ok,Ek);function iA(e){if(0<=e.y&&e.y<100){var t=new Date(-1,e.m,e.d,e.H,e.M,e.S,e.L);return t.setFullYear(e.y),t}return new Date(e.y,e.m,e.d,e.H,e.M,e.S,e.L)}function aA(e){if(0<=e.y&&e.y<100){var t=new Date(Date.UTC(-1,e.m,e.d,e.H,e.M,e.S,e.L));return t.setUTCFullYear(e.y),t}return new Date(Date.UTC(e.y,e.m,e.d,e.H,e.M,e.S,e.L))}function oA(e,t,n){return{y:e,m:t,d:n,H:0,M:0,S:0,L:0}}function sA(e){var t=e.dateTime,n=e.date,r=e.time,i=e.periods,a=e.days,o=e.shortDays,s=e.months,c=e.shortMonths,l=pA(i),u=mA(i),d=pA(a),f=mA(a),p=pA(o),m=mA(o),h=pA(s),g=mA(s),_=pA(c),v=mA(c),y={a:N,A:P,b:F,B:ee,c:null,d:FA,e:FA,f:BA,g:ZA,G:$A,H:IA,I:LA,j:RA,L:zA,m:VA,M:HA,p:te,q:I,Q:Sj,s:Cj,S:UA,u:WA,U:GA,V:qA,w:JA,W:YA,x:null,X:null,y:XA,Y:QA,Z:ej,"%":xj},b={a:L,A:R,b:ne,B:z,c:null,d:tj,e:tj,f:oj,g:_j,G:yj,H:nj,I:rj,j:ij,L:aj,m:sj,M:cj,p:re,q:B,Q:Sj,s:Cj,S:lj,u:uj,U:dj,V:pj,w:mj,W:hj,x:null,X:null,y:gj,Y:vj,Z:bj,"%":xj},x={a:E,A:D,b:O,B:k,c:A,d:TA,e:TA,f:jA,g:xA,G:bA,H:DA,I:DA,j:EA,L:AA,m:wA,M:OA,p:T,q:CA,Q:NA,s:PA,S:kA,u:gA,U:_A,V:vA,w:hA,W:yA,x:j,X:M,y:xA,Y:bA,Z:SA,"%":MA};y.x=S(n,y),y.X=S(r,y),y.c=S(t,y),b.x=S(n,b),b.X=S(r,b),b.c=S(t,b);function S(e,t){return function(n){var r=[],i=-1,a=0,o=e.length,s,c,l;for(n instanceof Date||(n=new Date(+n));++i<o;)e.charCodeAt(i)===37&&(r.push(e.slice(a,i)),(c=cA[s=e.charAt(++i)])==null?c=s===`e`?` `:`0`:s=e.charAt(++i),(l=t[s])&&(s=l(n,c)),r.push(s),a=i+1);return r.push(e.slice(a,i)),r.join(``)}}function C(e,t){return function(n){var r=oA(1900,void 0,1),i=w(r,e,n+=``,0),a,o;if(i!=n.length)return null;if(`Q`in r)return new Date(r.Q);if(`s`in r)return new Date(r.s*1e3+(`L`in r?r.L:0));if(t&&!(`Z`in r)&&(r.Z=0),`p`in r&&(r.H=r.H%12+r.p*12),r.m===void 0&&(r.m=`q`in r?r.q:0),`V`in r){if(r.V<1||r.V>53)return null;`w`in r||(r.w=1),`Z`in r?(a=aA(oA(r.y,0,1)),o=a.getUTCDay(),a=o>4||o===0?Uk.ceil(a):Uk(a),a=jk.offset(a,(r.V-1)*7),r.y=a.getUTCFullYear(),r.m=a.getUTCMonth(),r.d=a.getUTCDate()+(r.w+6)%7):(a=iA(oA(r.y,0,1)),o=a.getDay(),a=o>4||o===0?Fk.ceil(a):Fk(a),a=Ak.offset(a,(r.V-1)*7),r.y=a.getFullYear(),r.m=a.getMonth(),r.d=a.getDate()+(r.w+6)%7)}else(`W`in r||`U`in r)&&(`w`in r||(r.w=`u`in r?r.u%7:+(`W`in r)),o=`Z`in r?aA(oA(r.y,0,1)).getUTCDay():iA(oA(r.y,0,1)).getDay(),r.m=0,r.d=`W`in r?(r.w+6)%7+r.W*7-(o+5)%7:r.w+r.U*7-(o+6)%7);return`Z`in r?(r.H+=r.Z/100|0,r.M+=r.Z%100,aA(r)):iA(r)}}function w(e,t,n,r){for(var i=0,a=t.length,o=n.length,s,c;i<a;){if(r>=o)return-1;if(s=t.charCodeAt(i++),s===37){if(s=t.charAt(i++),c=x[s in cA?t.charAt(i++):s],!c||(r=c(e,n,r))<0)return-1}else if(s!=n.charCodeAt(r++))return-1}return r}function T(e,t,n){var r=l.exec(t.slice(n));return r?(e.p=u.get(r[0].toLowerCase()),n+r[0].length):-1}function E(e,t,n){var r=p.exec(t.slice(n));return r?(e.w=m.get(r[0].toLowerCase()),n+r[0].length):-1}function D(e,t,n){var r=d.exec(t.slice(n));return r?(e.w=f.get(r[0].toLowerCase()),n+r[0].length):-1}function O(e,t,n){var r=_.exec(t.slice(n));return r?(e.m=v.get(r[0].toLowerCase()),n+r[0].length):-1}function k(e,t,n){var r=h.exec(t.slice(n));return r?(e.m=g.get(r[0].toLowerCase()),n+r[0].length):-1}function A(e,n,r){return w(e,t,n,r)}function j(e,t,r){return w(e,n,t,r)}function M(e,t,n){return w(e,r,t,n)}function N(e){return o[e.getDay()]}function P(e){return a[e.getDay()]}function F(e){return c[e.getMonth()]}function ee(e){return s[e.getMonth()]}function te(e){return i[+(e.getHours()>=12)]}function I(e){return 1+~~(e.getMonth()/3)}function L(e){return o[e.getUTCDay()]}function R(e){return a[e.getUTCDay()]}function ne(e){return c[e.getUTCMonth()]}function z(e){return s[e.getUTCMonth()]}function re(e){return i[+(e.getUTCHours()>=12)]}function B(e){return 1+~~(e.getUTCMonth()/3)}return{format:function(e){var t=S(e+=``,y);return t.toString=function(){return e},t},parse:function(e){var t=C(e+=``,!1);return t.toString=function(){return e},t},utcFormat:function(e){var t=S(e+=``,b);return t.toString=function(){return e},t},utcParse:function(e){var t=C(e+=``,!0);return t.toString=function(){return e},t}}}var cA={"-":``,_:` `,0:`0`},lA=/^\s*\d+/,uA=/^%/,dA=/[\\^$*+?|[\]().{}]/g;function Z(e,t,n){var r=e<0?`-`:``,i=(r?-e:e)+``,a=i.length;return r+(a<n?Array(n-a+1).join(t)+i:i)}function fA(e){return e.replace(dA,`\\$&`)}function pA(e){return RegExp(`^(?:`+e.map(fA).join(`|`)+`)`,`i`)}function mA(e){return new Map(e.map((e,t)=>[e.toLowerCase(),t]))}function hA(e,t,n){var r=lA.exec(t.slice(n,n+1));return r?(e.w=+r[0],n+r[0].length):-1}function gA(e,t,n){var r=lA.exec(t.slice(n,n+1));return r?(e.u=+r[0],n+r[0].length):-1}function _A(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.U=+r[0],n+r[0].length):-1}function vA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.V=+r[0],n+r[0].length):-1}function yA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.W=+r[0],n+r[0].length):-1}function bA(e,t,n){var r=lA.exec(t.slice(n,n+4));return r?(e.y=+r[0],n+r[0].length):-1}function xA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function SA(e,t,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(t.slice(n,n+6));return r?(e.Z=r[1]?0:-(r[2]+(r[3]||`00`)),n+r[0].length):-1}function CA(e,t,n){var r=lA.exec(t.slice(n,n+1));return r?(e.q=r[0]*3-3,n+r[0].length):-1}function wA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.m=r[0]-1,n+r[0].length):-1}function TA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.d=+r[0],n+r[0].length):-1}function EA(e,t,n){var r=lA.exec(t.slice(n,n+3));return r?(e.m=0,e.d=+r[0],n+r[0].length):-1}function DA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.H=+r[0],n+r[0].length):-1}function OA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.M=+r[0],n+r[0].length):-1}function kA(e,t,n){var r=lA.exec(t.slice(n,n+2));return r?(e.S=+r[0],n+r[0].length):-1}function AA(e,t,n){var r=lA.exec(t.slice(n,n+3));return r?(e.L=+r[0],n+r[0].length):-1}function jA(e,t,n){var r=lA.exec(t.slice(n,n+6));return r?(e.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function MA(e,t,n){var r=uA.exec(t.slice(n,n+1));return r?n+r[0].length:-1}function NA(e,t,n){var r=lA.exec(t.slice(n));return r?(e.Q=+r[0],n+r[0].length):-1}function PA(e,t,n){var r=lA.exec(t.slice(n));return r?(e.s=+r[0],n+r[0].length):-1}function FA(e,t){return Z(e.getDate(),t,2)}function IA(e,t){return Z(e.getHours(),t,2)}function LA(e,t){return Z(e.getHours()%12||12,t,2)}function RA(e,t){return Z(1+Ak.count(Zk(e),e),t,3)}function zA(e,t){return Z(e.getMilliseconds(),t,3)}function BA(e,t){return zA(e,t)+`000`}function VA(e,t){return Z(e.getMonth()+1,t,2)}function HA(e,t){return Z(e.getMinutes(),t,2)}function UA(e,t){return Z(e.getSeconds(),t,2)}function WA(e){var t=e.getDay();return t===0?7:t}function GA(e,t){return Z(Pk.count(Zk(e)-1,e),t,2)}function KA(e){var t=e.getDay();return t>=4||t===0?Rk(e):Rk.ceil(e)}function qA(e,t){return e=KA(e),Z(Rk.count(Zk(e),e)+(Zk(e).getDay()===4),t,2)}function JA(e){return e.getDay()}function YA(e,t){return Z(Fk.count(Zk(e)-1,e),t,2)}function XA(e,t){return Z(e.getFullYear()%100,t,2)}function ZA(e,t){return e=KA(e),Z(e.getFullYear()%100,t,2)}function QA(e,t){return Z(e.getFullYear()%1e4,t,4)}function $A(e,t){var n=e.getDay();return e=n>=4||n===0?Rk(e):Rk.ceil(e),Z(e.getFullYear()%1e4,t,4)}function ej(e){var t=e.getTimezoneOffset();return(t>0?`-`:(t*=-1,`+`))+Z(t/60|0,`0`,2)+Z(t%60,`0`,2)}function tj(e,t){return Z(e.getUTCDate(),t,2)}function nj(e,t){return Z(e.getUTCHours(),t,2)}function rj(e,t){return Z(e.getUTCHours()%12||12,t,2)}function ij(e,t){return Z(1+jk.count(Qk(e),e),t,3)}function aj(e,t){return Z(e.getUTCMilliseconds(),t,3)}function oj(e,t){return aj(e,t)+`000`}function sj(e,t){return Z(e.getUTCMonth()+1,t,2)}function cj(e,t){return Z(e.getUTCMinutes(),t,2)}function lj(e,t){return Z(e.getUTCSeconds(),t,2)}function uj(e){var t=e.getUTCDay();return t===0?7:t}function dj(e,t){return Z(Hk.count(Qk(e)-1,e),t,2)}function fj(e){var t=e.getUTCDay();return t>=4||t===0?Kk(e):Kk.ceil(e)}function pj(e,t){return e=fj(e),Z(Kk.count(Qk(e),e)+(Qk(e).getUTCDay()===4),t,2)}function mj(e){return e.getUTCDay()}function hj(e,t){return Z(Uk.count(Qk(e)-1,e),t,2)}function gj(e,t){return Z(e.getUTCFullYear()%100,t,2)}function _j(e,t){return e=fj(e),Z(e.getUTCFullYear()%100,t,2)}function vj(e,t){return Z(e.getUTCFullYear()%1e4,t,4)}function yj(e,t){var n=e.getUTCDay();return e=n>=4||n===0?Kk(e):Kk.ceil(e),Z(e.getUTCFullYear()%1e4,t,4)}function bj(){return`+0000`}function xj(){return`%`}function Sj(e){return+e}function Cj(e){return Math.floor(e/1e3)}var wj,Tj;Ej({dateTime:`%x, %X`,date:`%-m/%-d/%Y`,time:`%-I:%M:%S %p`,periods:[`AM`,`PM`],days:[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],shortDays:[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],months:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],shortMonths:[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`]});function Ej(e){return wj=sA(e),Tj=wj.format,wj.parse,wj.utcFormat,wj.utcParse,wj}function Dj(e){return new Date(e)}function Oj(e){return e instanceof Date?+e:+new Date(+e)}function kj(e,t,n,r,i,a,o,s,c,l){var u=lk(),d=u.invert,f=u.domain,p=l(`.%L`),m=l(`:%S`),h=l(`%I:%M`),g=l(`%I %p`),_=l(`%a %d`),v=l(`%b %d`),y=l(`%B`),b=l(`%Y`);function x(e){return(c(e)<e?p:s(e)<e?m:o(e)<e?h:a(e)<e?g:r(e)<e?i(e)<e?_:v:n(e)<e?y:b)(e)}return u.invert=function(e){return new Date(d(e))},u.domain=function(e){return arguments.length?f(Array.from(e,Oj)):f().map(Dj)},u.ticks=function(t){var n=f();return e(n[0],n[n.length-1],t??10)},u.tickFormat=function(e,t){return t==null?x:l(t)},u.nice=function(e){var n=f();return(!e||typeof e.range!=`function`)&&(e=t(n[0],n[n.length-1],e??10)),e?f(pk(n,e)):u},u.copy=function(){return sk(u,kj(e,t,n,r,i,a,o,s,c,l))},u}function Aj(){return qO.apply(kj(nA,rA,Zk,Yk,Pk,Ak,Ok,Ek,Tk,Tj).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}function jj(e){return function(){return e}}var Mj=Math.abs,Nj=Math.atan2,Pj=Math.cos,Fj=Math.max,Ij=Math.min,Lj=Math.sin,Rj=Math.sqrt,zj=Math.PI,Bj=zj/2,Vj=2*zj;function Hj(e){return e>1?0:e<-1?zj:Math.acos(e)}function Uj(e){return e>=1?Bj:e<=-1?-Bj:Math.asin(e)}function Wj(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{let e=Math.floor(n);if(!(e>=0))throw RangeError(`invalid digits: ${n}`);t=e}return e},()=>new ZD(t)}function Gj(e){return e.innerRadius}function Kj(e){return e.outerRadius}function qj(e){return e.startAngle}function Jj(e){return e.endAngle}function Yj(e){return e&&e.padAngle}function Xj(e,t,n,r,i,a,o,s){var c=n-e,l=r-t,u=o-i,d=s-a,f=d*c-u*l;if(!(f*f<1e-12))return f=(u*(t-a)-d*(e-i))/f,[e+f*c,t+f*l]}function Zj(e,t,n,r,i,a,o){var s=e-n,c=t-r,l=(o?a:-a)/Rj(s*s+c*c),u=l*c,d=-l*s,f=e+u,p=t+d,m=n+u,h=r+d,g=(f+m)/2,_=(p+h)/2,v=m-f,y=h-p,b=v*v+y*y,x=i-a,S=f*h-m*p,C=(y<0?-1:1)*Rj(Fj(0,x*x*b-S*S)),w=(S*y-v*C)/b,T=(-S*v-y*C)/b,E=(S*y+v*C)/b,D=(-S*v+y*C)/b,O=w-g,k=T-_,A=E-g,j=D-_;return O*O+k*k>A*A+j*j&&(w=E,T=D),{cx:w,cy:T,x01:-u,y01:-d,x11:w*(i/x-1),y11:T*(i/x-1)}}function Qj(){var e=Gj,t=Kj,n=jj(0),r=null,i=qj,a=Jj,o=Yj,s=null,c=Wj(l);function l(){var l,u,d=+e.apply(this,arguments),f=+t.apply(this,arguments),p=i.apply(this,arguments)-Bj,m=a.apply(this,arguments)-Bj,h=Mj(m-p),g=m>p;if(s||=l=c(),f<d&&(u=f,f=d,d=u),!(f>1e-12))s.moveTo(0,0);else if(h>Vj-1e-12)s.moveTo(f*Pj(p),f*Lj(p)),s.arc(0,0,f,p,m,!g),d>1e-12&&(s.moveTo(d*Pj(m),d*Lj(m)),s.arc(0,0,d,m,p,g));else{var _=p,v=m,y=p,b=m,x=h,S=h,C=o.apply(this,arguments)/2,w=C>1e-12&&(r?+r.apply(this,arguments):Rj(d*d+f*f)),T=Ij(Mj(f-d)/2,+n.apply(this,arguments)),E=T,D=T,O,k;if(w>1e-12){var A=Uj(w/d*Lj(C)),j=Uj(w/f*Lj(C));(x-=A*2)>1e-12?(A*=g?1:-1,y+=A,b-=A):(x=0,y=b=(p+m)/2),(S-=j*2)>1e-12?(j*=g?1:-1,_+=j,v-=j):(S=0,_=v=(p+m)/2)}var M=f*Pj(_),N=f*Lj(_),P=d*Pj(b),F=d*Lj(b);if(T>1e-12){var ee=f*Pj(v),te=f*Lj(v),I=d*Pj(y),L=d*Lj(y),R;if(h<zj){if(R=Xj(M,N,I,L,ee,te,P,F)){var ne=M-R[0],z=N-R[1],re=ee-R[0],B=te-R[1],ie=1/Lj(Hj((ne*re+z*B)/(Rj(ne*ne+z*z)*Rj(re*re+B*B)))/2),ae=Rj(R[0]*R[0]+R[1]*R[1]);E=Ij(T,(d-ae)/(ie-1)),D=Ij(T,(f-ae)/(ie+1))}else E=D=0}}S>1e-12?D>1e-12?(O=Zj(I,L,M,N,f,D,g),k=Zj(ee,te,P,F,f,D,g),s.moveTo(O.cx+O.x01,O.cy+O.y01),D<T?s.arc(O.cx,O.cy,D,Nj(O.y01,O.x01),Nj(k.y01,k.x01),!g):(s.arc(O.cx,O.cy,D,Nj(O.y01,O.x01),Nj(O.y11,O.x11),!g),s.arc(0,0,f,Nj(O.cy+O.y11,O.cx+O.x11),Nj(k.cy+k.y11,k.cx+k.x11),!g),s.arc(k.cx,k.cy,D,Nj(k.y11,k.x11),Nj(k.y01,k.x01),!g))):(s.moveTo(M,N),s.arc(0,0,f,_,v,!g)):s.moveTo(M,N),!(d>1e-12)||!(x>1e-12)?s.lineTo(P,F):E>1e-12?(O=Zj(P,F,ee,te,d,-E,g),k=Zj(M,N,I,L,d,-E,g),s.lineTo(O.cx+O.x01,O.cy+O.y01),E<T?s.arc(O.cx,O.cy,E,Nj(O.y01,O.x01),Nj(k.y01,k.x01),!g):(s.arc(O.cx,O.cy,E,Nj(O.y01,O.x01),Nj(O.y11,O.x11),!g),s.arc(0,0,d,Nj(O.cy+O.y11,O.cx+O.x11),Nj(k.cy+k.y11,k.cx+k.x11),g),s.arc(k.cx,k.cy,E,Nj(k.y11,k.x11),Nj(k.y01,k.x01),!g))):s.arc(0,0,d,b,y,g)}if(s.closePath(),l)return s=null,l+``||null}return l.centroid=function(){var n=(+e.apply(this,arguments)+ +t.apply(this,arguments))/2,r=(+i.apply(this,arguments)+ +a.apply(this,arguments))/2-zj/2;return[Pj(r)*n,Lj(r)*n]},l.innerRadius=function(t){return arguments.length?(e=typeof t==`function`?t:jj(+t),l):e},l.outerRadius=function(e){return arguments.length?(t=typeof e==`function`?e:jj(+e),l):t},l.cornerRadius=function(e){return arguments.length?(n=typeof e==`function`?e:jj(+e),l):n},l.padRadius=function(e){return arguments.length?(r=e==null?null:typeof e==`function`?e:jj(+e),l):r},l.startAngle=function(e){return arguments.length?(i=typeof e==`function`?e:jj(+e),l):i},l.endAngle=function(e){return arguments.length?(a=typeof e==`function`?e:jj(+e),l):a},l.padAngle=function(e){return arguments.length?(o=typeof e==`function`?e:jj(+e),l):o},l.context=function(e){return arguments.length?(s=e??null,l):s},l}Array.prototype.slice;function $j(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function eM(e){this._context=e}eM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t)}}};function tM(e){return new eM(e)}function nM(e){return e[0]}function rM(e){return e[1]}function iM(e,t){var n=jj(!0),r=null,i=tM,a=null,o=Wj(s);e=typeof e==`function`?e:e===void 0?nM:jj(e),t=typeof t==`function`?t:t===void 0?rM:jj(t);function s(s){var c,l=(s=$j(s)).length,u,d=!1,f;for(r??(a=i(f=o())),c=0;c<=l;++c)!(c<l&&n(u=s[c],c,s))===d&&((d=!d)?a.lineStart():a.lineEnd()),d&&a.point(+e(u,c,s),+t(u,c,s));if(f)return a=null,f+``||null}return s.x=function(t){return arguments.length?(e=typeof t==`function`?t:jj(+t),s):e},s.y=function(e){return arguments.length?(t=typeof e==`function`?e:jj(+e),s):t},s.defined=function(e){return arguments.length?(n=typeof e==`function`?e:jj(!!e),s):n},s.curve=function(e){return arguments.length?(i=e,r!=null&&(a=i(r)),s):i},s.context=function(e){return arguments.length?(e==null?r=a=null:a=i(r=e),s):r},s}function aM(e,t){this._context=e,this._t=t}aM.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}}this._x=e,this._y=t}};function oM(e){return new aM(e,1)}function sM(e,t,n){this.k=e,this.x=t,this.y=n}sM.prototype={constructor:sM,scale:function(e){return e===1?this:new sM(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new sM(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var cM=new sM(1,0,0);lM.prototype=sM.prototype;function lM(e){for(;!e.__zoom;)if(!(e=e.parentNode))return cM;return e.__zoom}function uM(e,t=15){let n=e.split(` `),r=[],i=[],a=0;return n.forEach(e=>{a+e.length>t?(i.length&&r.push(i.join(` `)),i=[e],a=e.length):(i.push(e),a+=e.length+ +(i.length>0))}),i.length&&r.push(i.join(` `)),r}var dM={DECISIVE:20,ROUTINE:50},fM=new Set([`WALKOVER`,`DOUBLE_WALKOVER`,`DEFAULTED`,`DOUBLE_DEFAULT`]),pM={COMPETITIVE:`#16a34a`,ROUTINE:`#3b82f6`,DECISIVE:`#8e44ad`,WALKOVER:`#6b7280`},mM=`#cfd8dc`,hM=`COMPETITIVE`,gM=`ROUTINE`,_M=`DECISIVE`,vM=`WALKOVER`;function yM(e,t=dM){if(!e?.length)return;let n=[0,0],r=[0,0];for(let t of e)n[0]+=t.side1Score||0,n[1]+=t.side2Score||0,r[0]+=t.side1TiebreakScore||0,r[1]+=t.side2TiebreakScore||0;r[0]+r[1]&&(n[r[0]>r[1]?0:1]+=1);let i=Math.max(n[0],n[1]);if(i===0)return;let a=Math.round(Math.min(n[0],n[1])/i*100);return Number.isNaN(a)?vM:a<=t.DECISIVE?_M:a<=t.ROUTINE?gM:hM}function bM(e,n=dM){if(e)return yM(t.scoreGovernor.parseScoreString({scoreString:e}),n)}function xM({winningSide:e,matchUpStatus:t,sets:n,scoreString:r,bands:i}){if(t&&fM.has(t))return vM;if(e)return n?.length?yM(n,i):bM(r,i)}function SM(e,t){return e?t?.[e]??pM[e]:mM}var{WILDCARD:CM,QUALIFIER:wM,LUCKY_LOSER:TM}=t.entryStatusConstants,EM=`text-anchor`,DM=`dominant-baseline`,OM=`fill-opacity`,kM=Object.assign({},...t.fixtures.countries.filter(e=>e.ioc).map(e=>({[e.ioc]:e.iso2})),...t.fixtures.countries.filter(e=>e.iso).map(e=>({[e.iso]:e.iso2})));function AM(e){let t=Math.floor(e.length/2),n=e.slice(0,t),r=e.slice(t).reverse();return[...n,...r]}function jM(e){if(e)switch(e){case CM:return`WC`;case wM:return`Q`;case TM:return`LL`;default:return e}}function MM(e,t){let n=[];for(let r of e)for(let e of r.sides){let i=r.matchUpStatus===`BYE`&&!e.participantName;n.push({name:e.participantName||(i?`BYE`:``),participantName:e.participantName||(i?`BYE`:void 0),drawPosition:e.drawPosition,seedNumber:e.seedNumber,entryStatus:jM(e.entryStatus),nationalityCode:e.nationalityCode,matchUp:r,depth:t,value:1})}return n}function NM(e,t){let n=e.winningSide!==void 0&&e.winningSide!==null?e.sides.find(t=>t.sideNumber===e.winningSide):void 0;!n&&e.matchUpStatus===`BYE`&&(n=e.sides.find(e=>e.participantName));let r=n?.participantName,i=r?t.get(r):void 0;return{winnerName:r,winnerSide:n,winnerLookup:i}}function PM(e,t,n,r){return e.map((e,i)=>{let a=i*2,o=[t[a],t[a+1]].filter(Boolean),{winnerName:s,winnerSide:c,winnerLookup:l}=NM(e,r);return{name:s||``,participantName:s,drawPosition:l?.drawPosition??c?.drawPosition,seedNumber:c?.seedNumber??l?.seedNumber,entryStatus:jM(c?.entryStatus)??l?.entryStatus,nationalityCode:c?.nationalityCode??l?.nationalityCode,scoreString:e.scoreString,matchUpStatus:e.matchUpStatus,competitiveness:e.competitiveness,matchUp:e,depth:n,children:o.length>0?o:void 0}})}function FM(e){let{roundMatchUps:t}=e,n=Object.keys(t).map(Number).sort((e,t)=>e-t);if(n.length===0)throw Error(`No round data found in draw`);let r=t[n[0]],i=AM(MM(r,n.length)),a=new Map;for(let e of i)e.participantName&&e.participantName!==`BYE`&&a.set(e.participantName,e);let o=PM(AM(r),i,n.length-1,a);for(let e=1;e<n.length;e++)o=PM(AM(t[n[e]]),o,n.length-1-e,a);return o.length===1?o[0]:{name:`Tournament`,depth:0,children:o}}function IM(e,t){if(!e)return;let{seedNumber:n,entryStatus:r,drawPosition:i,participantName:a}=e,o;if(a?.trim().toUpperCase()===`BYE`)o=`#B0BEC5`;else if(n){let e=Number(n),t=fk().domain([1,32]).range([`0`,`1`]);o=fk().domain(CS(0,1,1/7)).range([`#81D4FA`,`#42A5F5`,`#1E88E5`,`#1565C0`,`#5C6BC0`,`#673AB7`,`#9C27B0`])(Number(t(e)))}else if(r?.toUpperCase()===`WC`)o=`red`;else if(r&&(r===`Q`||r===`LL`))o=fk().domain(CS(0,1,1/3)).range([`#FFF176`,`#FBC02D`,`#FF9800`])(t(i));else{let e=[`#C8E6C9`,`#81C784`,`#66BB6A`,`#4CAF50`,`#43A047`,`#388E3C`,`#2E7D32`,`#1B5E20`,`#A5D6A7`,`#90CAF9`,`#64B5F6`,`#42A5F5`,`#2196F3`,`#1E88E5`,`#1976D2`,`#1565C0`];o=fk().domain(CS(0,1,1/e.length)).range(e)(t(i))}e.color=o,e.children&&e.children.forEach(n=>{n.participantName===e.participantName&&(n.color=o),IM(n,t)})}function LM(e,t){e&&(e.competitivenessColor=e.children?.length&&e.competitiveness?SM(e.competitiveness,t):mM,e.children?.forEach(e=>LM(e,t)))}function RM(e,t){let n=[];return e.seedNumber?n.push(`Seed ${e.seedNumber}`):e.entryStatus&&n.push(e.entryStatus),t===7&&e.drawPosition&&n.push(`Draw ${e.drawPosition}`),n.length>0?n.join(` • `):void 0}function zM(e,t){let n=e.find(e=>e.data.participantName&&e.data.participantName!==t);return n?.data.participantName?n.data:void 0}function BM(e,t){let n=[e.participantName],r;if(t.children&&t.children.length>0)e.scoreString&&n.push(e.scoreString),r=zM(t.children,e.participantName),r&&n.push(r.participantName);else{let r=RM(e,t.depth);r&&n.push(r)}return{messageLines:n,opponentData:r}}function VM(e,t){return-(e*t/2)+t/2}function HM(e,t,n){let r=Hw(e).append(`svg`).attr(`width`,t).attr(`height`,n).style(`display`,`block`),i=r.append(`g`).attr(`transform`,`translate(${t/2}, ${n/2})`);return{svg:r,g:i,flagsGroup:i.append(`g`).attr(`class`,`flags-group`),winningFlagsGroup:i.append(`g`).attr(`class`,`winning-flags-group`),losingFlagsGroup:i.append(`g`).attr(`class`,`losing-flags-group`)}}function UM(e,t,n,r,i){let a=e.append(`text`).attr(`x`,t/2).attr(`y`,n/2).attr(EM,`middle`).attr(DM,`middle`).attr(`font-size`,`${r}px`).attr(`font-weight`,`bold`).style(`fill`,`var(--chc-text-primary, #333)`).attr(`pointer-events`,`none`),o=r+i*.5;return{centerText:a,centerText2:e.append(`text`).attr(`x`,t/2).attr(`y`,n/2+o).attr(EM,`middle`).attr(DM,`middle`).attr(`font-size`,`${i}px`).style(`fill`,`var(--chc-text-secondary, #666)`).attr(`pointer-events`,`none`)}}function WM(e,t,n,r,i,a,o){n&&(i?(t.flagsGroup.selectAll(`text`).remove(),t.winningFlagsGroup.selectAll(`text`).remove(),t.losingFlagsGroup.selectAll(`text`).remove()):e.selectAll(`text`).remove(),e.append(`text`).attr(`font-size`,`${o}px`).attr(EM,`middle`).attr(DM,`middle`).attr(`transform`,`translate(0, ${r*a})`).text(JM(n)))}function GM(e,n,r,i={}){let a=i.width||800,o=i.height||800,s=Math.min(a,o)/800*(i.textScaleFactor??1),c=28*s,l=24*s,u=30*s,d=r||i.title||`Tournament`,f=Object.assign({},...t.fixtures.countries.filter(e=>e.label).map(e=>({[e.ioc]:e.label})));if(!Object.keys(n?.roundMatchUps??{}).length)return{highlightPlayer:()=>0,hide:()=>void 0,setColorMode:()=>void 0};let p=FM(n),m=LO(p,e=>e.children).sum(e=>e.value||0),h=Math.min(a,o)/2,g=h/2,_=e=>e*h/200;KO().size([2*Math.PI,h-g])(m),IM(p,fk().domain([0,n.drawSize||128]).range([0,1])),LM(p,i.competitivenessColors);let v=i.colorMode??`default`,y=e=>v===`competitiveness`?e.competitivenessColor||`#cfd8dc`:e.color||`#ccc`,b=m.descendants(),x=Qj().startAngle(e=>e.x0).endAngle(e=>e.x1).innerRadius(e=>e.y0+g).outerRadius(e=>e.y1+g),{svg:S,g:C,flagsGroup:w,winningFlagsGroup:T,losingFlagsGroup:E}=HM(e,a,o),D=new Set,O=e=>{e.nationalityCode&&D.add(e.nationalityCode),e.children&&e.children.forEach(O)};O(p);let k=Array.from(D),{centerText:A,centerText2:j}=UM(S,a,o,c,l);function M(){let e=uM(d,15);A.text(``),A.selectAll(`tspan`).remove(),j.text(``),j.selectAll(`tspan`).remove(),A.selectAll(`tspan`).data(e).join(`tspan`).attr(`x`,a/2).attr(`dy`,(e,t)=>t===0?0:u).text(e=>e);let t=-(e.length*u/2)+u/2;A.attr(`y`,o/2+t),A.style(`display`,`block`),j.style(`display`,`none`)}function N(){if(w.selectAll(`text`).remove(),T.selectAll(`text`).remove(),E.selectAll(`text`).remove(),k.length===0)return;let e=fk().domain([0,k.length]).range([0,Math.PI*2]),t=_(20),n=g-t+10;w.selectAll(`text`).data(k).join(`text`).attr(`font-size`,`${t}px`).attr(EM,`middle`).attr(DM,`middle`).attr(`transform`,(t,r)=>{let i=e(r);return`translate(${Math.cos(i)*n}, ${Math.sin(i)*n})`}).text(e=>JM(e)).style(`cursor`,`pointer`).on(`mouseover`,function(e,t){let n=f[t]||t;A.selectAll(`tspan`).remove(),A.attr(`y`,o/2),A.text(n).style(`display`,`block`),j.selectAll(`tspan`).remove(),j.text(``).style(`display`,`none`),F||C.selectAll(`path`).attr(OM,e=>e.data.nationalityCode===t?.9:.3)}).on(`mouseout`,function(){F||C.selectAll(`path`).attr(OM,.8),M()})}N(),M();let P=i.eventHandlers?.clickCenter;P&&C.insert(`circle`,`:first-child`).attr(`r`,g).attr(`fill`,`transparent`).style(`cursor`,`pointer`).on(`click`,P);let F=!1,ee;function te(e,t){let n=t.data;if(n.participantName){let{messageLines:e,opponentData:r}=BM(n,t);r&&(n.opponent=r),A.selectAll(`tspan`).remove(),A.text(``),A.selectAll(`tspan`).data(e).join(`tspan`).attr(`x`,a/2).attr(`dy`,(e,t)=>t===0?0:u).text(e=>e);let i=VM(e.length,u);A.attr(`y`,o/2+i),A.style(`display`,`block`),j.style(`display`,`none`)}F?n.participantName?.toLowerCase()!==ee?.toLowerCase()&&Hw(e.currentTarget).attr(OM,.9):C.selectAll(`path`).attr(OM,e=>e.data.participantName===t.data.participantName?.9:.3);let r=_(30),i=g-r-10,s={flagsGroup:w,winningFlagsGroup:T,losingFlagsGroup:E};WM(T,s,n.nationalityCode,-1,!0,i,r),n.opponent&&WM(E,s,n.opponent.nationalityCode,1,!1,i,r)}function I(e,t){if(F){let n=t.data.participantName?.toLowerCase()===ee?.toLowerCase();Hw(e.currentTarget).attr(OM,n?1:.2)}else C.selectAll(`path`).attr(OM,.8);N(),M()}let L=i.eventHandlers?.clickSegment;function R(e,t){if(!L)return;let n=t.data;L({participantName:n.participantName,drawPosition:n.drawPosition,seedNumber:n.seedNumber,entryStatus:n.entryStatus,nationalityCode:n.nationalityCode,scoreString:n.scoreString,matchUpStatus:n.matchUpStatus,competitiveness:n.competitiveness,roundName:n.roundName,depth:n.depth,matchUp:n.matchUp})}let ne=C.selectAll(`path`).data(b).join(`path`).attr(`d`,e=>x(e)).attr(`fill`,e=>y(e.data)).attr(OM,.8).attr(`stroke`,`#fff`).attr(`stroke-width`,1).on(`mouseover`,te).on(`mouseout`,I);L&&ne.style(`cursor`,`pointer`).on(`click`,R),ne.append(`title`).text(e=>{let t=e.data;if(t.participantName){let e=[t.participantName,`Draw: ${t.drawPosition||`N/A`}`];return t.competitiveness&&e.push(`Competitiveness: ${t.competitiveness}`),e.join(`
215
- `)}return`${t.name}\nDepth: ${e.depth}`});function z(e){let t=0;return F=!!e,ee=e,C.selectAll(`path`).attr(OM,n=>e?n.data.participantName?.toLowerCase()===e.toLowerCase()?(t+=1,1):.2:.8),t}function re(e){S.style(`display`,e?`none`:`block`)}function B(e){v=e,C.selectAll(`path`).attr(`fill`,e=>y(e.data))}return{highlightPlayer:z,hide:re,setColorMode:B}}function KM(e={}){return{render:(t,n,r)=>GM(t,n,r,e)}}function qM(e){return e?.length===2?e&&String.fromCodePoint!==void 0?e.toUpperCase().replaceAll(/./g,e=>String.fromCodePoint((e.codePointAt(0)??0)+127397)):e:``}function JM(e){return qM(kM[e]||e)}var{LUCKY_LOSER:YM,WILDCARD:XM,QUALIFIER:ZM}=t.entryStatusConstants,{WIN_RATIO:QM,ROUND_OUTCOME:$M,MAIN:eN,CONTAINER:tN}=t.drawDefinitionConstants;function nN(e){return e?.finishingPosition===$M&&e?.structureType!==tN}function rN(e){return e?.finishingPosition===QM||e?.structureType===tN}function iN(e){if(!e?.length)return;let t=e.filter(nN);if(t.length)return t.find(e=>e.stage===eN)??t[0]}function aN(e){if(rN(e))return{drawSize:0,roundMatchUps:{}};let t={};for(let[n,r]of Object.entries(e.roundMatchUps))t[Number(n)]=r.map(e=>({...e,winningSide:e.winningSide,drawPositions:e.drawPositions||[],competitiveness:xM({winningSide:e.winningSide,matchUpStatus:e.matchUpStatus,sets:e.score?.sets}),scoreString:e.winningSide===1?e.score?.scoreStringSide1:e.winningSide===2?e.score?.scoreStringSide2:void 0,sides:(e.sides||[]).map(e=>({sideNumber:e.sideNumber,drawPosition:e.drawPosition,participantName:e.participant?.participantName,nationalityCode:e.participant?.person?.nationalityCode,seedNumber:e.seedNumber,entryStatus:e.participant?.entryStatus}))}));return{drawSize:(t[1]?.length||0)*2,roundMatchUps:t,seedAssignments:e.seedAssignments}}var oN={LL:YM,WC:XM,Q:ZM},sN=[`R128`,`R64`,`R32`,`R16`,`QF`,`SF`,`F`];function cN(e){let t=lN(e);if(t.length===0)return{drawSize:0,roundMatchUps:{}};let n=t[0].data,r=n.length,i=uN(n),a=dN(t,e),o={};o[1]=pN(n,a,t);for(let e=1;e<t.length;e++)o[e+1]=mN(e,t,a,i);return{drawSize:r,roundMatchUps:o}}function lN(e){let t=[],n=!1;for(let r of sN){let i=e[r];i&&i.length>0&&(n=!0),n&&i&&i.length>0&&t.push({key:r,data:i})}return t}function uN(e){let t=new Map;return e.forEach((e,n)=>{let r=hN(e.player);r&&r!==`BYE`&&t.set(r,{drawPosition:e.Draw??n+1,country:e.country,seed:e.seed,entry:e.entry})}),t}function dN(e,t){let n=new Map;for(let r=0;r<e.length;r++){let i=r+1<e.length?e[r+1].data:t.W||[],a=new Set;for(let e of i){let t=hN(e.player);t&&a.add(t)}n.set(e[r].key,a)}return n}function fN(e,t,n){if(e===`BYE`||t===`BYE`)return e===`BYE`?2:1;if(n.has(e))return 1;if(n.has(t))return 2}function pN(e,t,n){let r=[],i=t.get(n[0].key)||new Set;for(let t=0;t<e.length;t+=2){let a=e[t],o=e[t+1],s=hN(a?.player),c=hN(o?.player),l=s===`BYE`||c===`BYE`,u=fN(s,c,i),d;if(!l&&n.length>1){let e=n[1].data,t=u===1?s:c;d=e.find(e=>hN(e.player)===t)?.score}let f=l?`BYE`:u?`COMPLETED`:`TO_BE_PLAYED`;r.push({roundNumber:1,matchUpStatus:f,winningSide:u,drawPositions:[a?.Draw??t+1,o?.Draw??t+2],competitiveness:xM({winningSide:u,matchUpStatus:f,scoreString:d}),scoreString:d,sides:[_N(1,a,t+1),_N(2,o,t+2)]})}return r}function mN(e,t,n,r){let i=e+1,a=t[e].data,o=n.get(t[e].key)||new Set,s=[];for(let e=0;e<a.length;e+=2){let t=a[e],n=a[e+1],c=hN(t?.player),l=hN(n?.player),u=o.has(c)?1:o.has(l)?2:void 0,d=(u===1?t:u===2?n:void 0)?.score,f=u?`COMPLETED`:`TO_BE_PLAYED`;s.push({roundNumber:i,matchUpStatus:f,winningSide:u,drawPositions:[r.get(c)?.drawPosition??0,r.get(l)?.drawPosition??0],competitiveness:xM({winningSide:u,matchUpStatus:f,scoreString:d}),scoreString:d,sides:[vN(1,t,r),vN(2,n,r)]})}return s}function hN(e){if(!e)return``;let t=e.trim();return t.toUpperCase()===`BYE`?`BYE`:t}function gN(e){if(e)return oN[e.toUpperCase()]||e}function _N(e,t,n){if(!t)return{sideNumber:e,drawPosition:n};let r=hN(t.player);return{sideNumber:e,drawPosition:t.Draw??n,participantName:r||void 0,nationalityCode:t.country||void 0,seedNumber:t.seed?Number(t.seed):void 0,entryStatus:gN(t.entry)}}function vN(e,t,n){if(!t)return{sideNumber:e,drawPosition:0};let r=hN(t.player),i=n.get(r);return{sideNumber:e,drawPosition:i?.drawPosition??0,participantName:r||void 0,nationalityCode:t.country||i?.country||void 0,seedNumber:t.seed?Number(t.seed):i?.seed?Number(i.seed):void 0,entryStatus:gN(t.entry||i?.entry)}}var yN=480,bN=200,xN=280,SN={top:12,right:12,bottom:28,left:32},CN={top:12,right:12,bottom:12,left:12},wN=.6,TN=.9,EN=`http://www.w3.org/2000/svg`,DN=`middle`,ON=`text-anchor`,kN=`dominant-baseline`,AN=[`var(--chc-rating-low, #5b8ff9)`,`var(--chc-rating-high, #00b894)`];function jN(e,t,n){let r=document.createElementNS(EN,`svg`);return r.setAttribute(`width`,String(e)),r.setAttribute(`height`,String(t)),r.setAttribute(`viewBox`,`0 0 ${e} ${t}`),r.setAttribute(`class`,`chc-rating-distribution-chart`),n&&r.setAttribute(`aria-label`,n),r}function MN(e,t,n){return n<=1||t/(n-1)<.5?AN[0]:AN[1]}function NN(e,t,n,r){return r?r(e,t):MN(e,t,n)}function PN(e){return`${e.binStart.toFixed(1)}–${e.binEnd.toFixed(1)}`}function FN(e){let{stats:t,width:n,height:r,margin:i,showAxis:a,showCounts:o,showMean:s,binColor:c,ariaLabel:l}=e,u=jN(n,r,l),d=Hw(u).append(`g`).attr(`class`,`chc-rdc-histogram`).attr(`transform`,`translate(${i.left}, ${i.top})`),f=Math.max(0,n-i.left-i.right),p=Math.max(0,r-i.top-i.bottom);if(t.histogram.length===0||f===0||p===0)return u;let m=XO().domain(t.histogram.map(PN)).range([0,f]).padding(.12),h=fk().domain([0,SS(t.histogram,e=>e.count)??0]).nice().range([p,0]),g=t.histogram.length;if(d.selectAll(`rect.chc-rdc-bar`).data(t.histogram).enter().append(`rect`).attr(`class`,`chc-rdc-bar`).attr(`x`,e=>m(PN(e))??0).attr(`y`,e=>h(e.count)).attr(`width`,m.bandwidth()).attr(`height`,e=>p-h(e.count)).attr(`fill`,(e,t)=>NN(e,t,g,c)).append(`title`).text(e=>`${PN(e)}: ${e.count}`),o&&d.selectAll(`text.chc-rdc-count`).data(t.histogram).enter().append(`text`).attr(`class`,`chc-rdc-count`).attr(`x`,e=>(m(PN(e))??0)+m.bandwidth()/2).attr(`y`,e=>h(e.count)-4).attr(ON,DN).attr(`font-size`,`11`).attr(`fill`,`var(--chc-rdc-count-color, var(--chc-text-primary, #111827))`).text(e=>e.count>0?String(e.count):``),a){let e=t.histogram.map(PN),n=f/g>=55?e:[e[0],e.at(-1)].filter((e,t,n)=>n.indexOf(e)===t);d.append(`g`).attr(`class`,`chc-rdc-axis`).attr(`transform`,`translate(0, ${p})`).call(IS(m).tickValues(n).tickSize(0)).call(e=>e.select(`.domain`).remove()).call(e=>e.selectAll(`text`).attr(`font-size`,`10`).attr(`dy`,`0.9em`))}if(s&&Number.isFinite(t.mean)&&t.histogram.length>0){let e=t.histogram[0],n=t.histogram.at(-1),r=(t.mean-e.binStart)/(n.binEnd-e.binStart);if(r>=0&&r<=1){let e=r*f;d.append(`line`).attr(`class`,`chc-rdc-mean`).attr(`x1`,e).attr(`x2`,e).attr(`y1`,0).attr(`y2`,p).attr(`stroke`,`var(--chc-rating-mean, #d63031)`).attr(`stroke-dasharray`,`4 3`).attr(`stroke-width`,1.5)}}return u}function IN(e,t,n,r){return[e+n*Math.sin(r),t-n*Math.cos(r)]}function LN(e,t,n,r,i,a){let[o,s]=IN(e,t,n,i),[c,l]=IN(e,t,n,a),[u,d]=IN(e,t,r,a),[f,p]=IN(e,t,r,i),m=+(a-i>Math.PI);return[`M ${o} ${s}`,`A ${n} ${n} 0 ${m} 1 ${c} ${l}`,`L ${u} ${d}`,`A ${r} ${r} 0 ${m} 0 ${f} ${p}`,`Z`].join(` `)}function RN(e){let{stats:t,size:n,margin:r,showCounts:i,binColor:a,ariaLabel:o}=e,s=jN(n,n,o);if(t.histogram.length===0||t.count===0)return s;let c=(n-Math.max(r.left+r.right,r.top+r.bottom))/2,l=n/2,u=n/2,d=c*TN,f=c*wN,p=0,m=t.histogram.length;for(let e=0;e<m;e++){let n=t.histogram[e];if(n.count===0)continue;let r=n.count/t.count*2*Math.PI,o=p,c=p+r,h=document.createElementNS(EN,`path`);if(h.setAttribute(`class`,`chc-rdc-slice`),h.setAttribute(`d`,LN(l,u,d,f,o,c)),h.setAttribute(`fill`,NN(n,e,m,a)),s.appendChild(h),i){let e=o+r/2,[t,i]=IN(l,u,(d+f)/2,e),a=document.createElementNS(EN,`text`);a.setAttribute(`class`,`chc-rdc-slice-label`),a.setAttribute(`x`,String(t)),a.setAttribute(`y`,String(i)),a.setAttribute(ON,DN),a.setAttribute(kN,DN),a.setAttribute(`font-size`,`11`),a.setAttribute(`fill`,`var(--chc-rating-label, #2d3436)`),a.textContent=String(n.count),s.appendChild(a)}p=c}let h=document.createElementNS(EN,`text`);return h.setAttribute(`class`,`chc-rdc-center-count`),h.setAttribute(`x`,String(l)),h.setAttribute(`y`,String(u)),h.setAttribute(ON,DN),h.setAttribute(kN,DN),h.setAttribute(`font-size`,`20`),h.setAttribute(`font-weight`,`600`),h.textContent=String(t.count),s.appendChild(h),s}function zN(e,t={}){let n=t.mode??`HISTOGRAM`,r=t.ariaLabel??`Participant rating distribution`;return n===`DONUT`?RN({stats:e,size:t.width??t.height??xN,margin:t.margin??CN,showCounts:t.showCounts??!0,binColor:t.binColor,ariaLabel:r}):FN({stats:e,width:t.width??yN,height:t.height??bN,margin:t.margin??SN,showAxis:t.showAxis??!0,showCounts:t.showCounts??!0,showMean:t.showMean??!0,binColor:t.binColor,ariaLabel:r})}var BN=`http://www.w3.org/2000/svg`,VN={top:36,right:16,bottom:28,left:56},HN=600,UN=260,WN=6,GN=8;function KN(e,t){let n=document.createElementNS(BN,`svg`);n.classList.add(`lc-svg`),e.appendChild(n);let r={container:e,svg:n,config:{...t},destroyed:!1};return qN(r),{element:n,update(e){r.destroyed||(r.config={...r.config,...e},qN(r))},destroy(){r.destroyed||(r.destroyed=!0,n.parentNode===e&&e.removeChild(n))}}}function qN(e){let{svg:t,container:n,config:r}=e,i={...VN,...r.margins||{}},a=n.clientWidth||HN,o=r.width??a,s=r.height??UN;for(;t.firstChild;)t.removeChild(t.firstChild);t.setAttribute(`width`,String(o)),t.setAttribute(`height`,String(s)),t.setAttribute(`viewBox`,`0 0 ${o} ${s}`);let c=Math.max(0,o-i.left-i.right),l=Math.max(0,s-i.top-i.bottom),u=(r.data||[]).map(e=>({...e,_dateValue:e.date instanceof Date?e.date:new Date(e.date),_rung:Math.max(0,Math.min(r.rungs.length-1,e.rung))})).filter(e=>!Number.isNaN(e._dateValue.getTime())).sort((e,t)=>e._dateValue.getTime()-t._dateValue.getTime());if(r.title){let e=document.createElementNS(BN,`text`);e.setAttribute(`class`,`lc-title`),e.setAttribute(`x`,String(i.left)),e.setAttribute(`y`,String(Math.max(16,i.top-12))),e.textContent=r.title,t.appendChild(e)}if(!u.length){let e=document.createElementNS(BN,`text`);e.setAttribute(`class`,`lc-empty`),e.setAttribute(`x`,String(o/2)),e.setAttribute(`y`,String(s/2)),e.setAttribute(`text-anchor`,`middle`),e.textContent=`No data`,t.appendChild(e);return}let d=lS(u,e=>e._dateValue),f=Math.max(3,(d[1].getTime()-d[0].getTime())/864e5*.04),p=new Date(d[0].getTime()-f*864e5),m=new Date(d[1].getTime()+f*864e5),h=Aj().domain([p,m]).range([0,c]),g=QO().domain([...r.rungs].reverse()).range([0,l]).padding(.5),_=document.createElementNS(BN,`g`);_.setAttribute(`transform`,`translate(${i.left},${i.top})`),t.appendChild(_);let v=document.createElementNS(BN,`g`);v.setAttribute(`class`,`lc-axis lc-axis-y`),_.appendChild(v),Hw(v).call(LS(g).tickSize(-c).tickPadding(8));let y=document.createElementNS(BN,`g`);y.setAttribute(`class`,`lc-axis lc-axis-x`),y.setAttribute(`transform`,`translate(0,${l})`),_.appendChild(y);let b=d[1].getFullYear()-d[0].getFullYear()>=1?`%Y`:`%b`,x=r.xTickFormat??b;if(Hw(y).call(IS(h).ticks(r.xMaxTicks??GN).tickFormat(Tj(x))),r.showConnector!==!1&&u.length>1){let e=iM().x(e=>h(e._dateValue)).y(e=>g(r.rungs[e._rung])??0).curve(oM),t=document.createElementNS(BN,`path`);t.setAttribute(`class`,`lc-connector`),t.setAttribute(`d`,e(u)||``),r.connectorColor&&(t.style.stroke=r.connectorColor),_.appendChild(t)}let S=document.createElementNS(BN,`g`);S.setAttribute(`class`,`lc-marks`),_.appendChild(S);for(let e of u){let t=h(e._dateValue),n=g(r.rungs[e._rung])??0,i=e.radius??r.markRadius??WN,a=document.createElementNS(BN,`circle`);if(a.setAttribute(`class`,`lc-mark`),a.setAttribute(`cx`,String(t)),a.setAttribute(`cy`,String(n)),a.setAttribute(`r`,String(i)),(e.color||r.markColor)&&(a.style.fill=e.color??r.markColor),e.label){let t=[e.label,e.detail].filter(Boolean).join(` — `);a.setAttribute(`aria-label`,t);let n=document.createElementNS(BN,`title`);n.textContent=t,a.appendChild(n)}r.onMarkClick&&(a.style.cursor=`pointer`,a.addEventListener(`click`,t=>r.onMarkClick(e,t))),r.onMarkHover&&(a.addEventListener(`mouseenter`,t=>r.onMarkHover(e,t)),a.addEventListener(`mouseleave`,e=>r.onMarkHover(null,e))),S.appendChild(a)}if(r.source){let e=document.createElementNS(BN,`text`);e.setAttribute(`class`,`lc-source`),e.setAttribute(`x`,String(o-i.right)),e.setAttribute(`y`,String(s-6)),e.setAttribute(`text-anchor`,`end`),e.textContent=`Source: ${r.source}`,t.appendChild(e)}}var JN=`right`,YN=`font-medium`;function XN({target:e,button:t,stateChange:n}){let r=0,i=()=>(r+=1,`Item${r}`),a=document.createElement(`div`);t.class&&a.classList.add(t.class),a.classList.add(`dropdown`),t.id&&(a.id=t.id),t.align===JN&&a.classList.add(`is-right`);let o=e=>e.classList.contains(`is-active`),s=()=>{o(a)&&a.classList.remove(`is-active`)},c=e=>o(e)?(e.classList.remove(`is-active`),!1):(e.classList.add(`is-active`),!0);a.onmouseleave=s,a.onclick=()=>c(a);let l=document.createElement(`div`);l.classList.add(`dropdown-trigger`);let u=document.createElement(`button`);u.className=`button font-medium`,t.intent&&u.classList.add(t.intent),u.setAttribute(`aria-haspopup`,`true`);let d=document.createElement(`span`);V(t.onClick)&&(d.onclick=t.onClick),d.style.cssText=`margin-right: 1em`,d.innerHTML=t.label,u.appendChild(d);let f=document.createElement(`span`);V(t.onClick)&&(f.onclick=t.onClick),f.innerHTML=`
214
+ `,`2) content: () => element.cloneNode(true)`].join(` `))}var s=i.reduce(function(e,t){var n=t&&Om(t,r);return n&&e.push(n),e},[]);return Rp(e)?s[0]:s}km.defaultProps=fm,km.setDefaultProps=mm,km.currentInput=Yp,Object.assign({},Hd,{effect:function(e){var t=e.state,n={popper:{position:t.options.strategy,left:`0`,top:`0`,margin:`0`},arrow:{position:`absolute`},reference:{}};Object.assign(t.elements.popper.style,n.popper),t.styles=n,t.elements.arrow&&Object.assign(t.elements.arrow.style,n.arrow)}}),km.setDefaultProps({render:wm});var Am=`#000000.#434343.#666666.#999999.#b7b7b7.#cccccc.#d9d9d9.#ffffff.#980000.#ff0000.#ff9900.#ffff00.#00ff00.#00ffff.#4a86e8.#0000ff.#9900ff.#ff00ff.#e6b8af.#f4cccc.#fce5cd.#fff2cc.#d9ead3.#d0e0e3.#c9daf8.#cfe2f3.#d9d2e9.#ead1dc`.split(`.`),jm=`notes-toolbar-recent-colors`,Mm=8;function Nm(){try{return JSON.parse(localStorage.getItem(jm)||`[]`)}catch{return[]}}function Pm(e){let t=Nm().filter(t=>t!==e);t.unshift(e),t.length>Mm&&(t=t.slice(0,Mm)),localStorage.setItem(jm,JSON.stringify(t))}function Fm(e={}){let t=document.createElement(`div`);return t.className=`notes-toolbar`,t.appendChild(Bm(e)),t.appendChild(Vm(e)),t.appendChild(Hm(e)),t.appendChild(Km(e)),t.appendChild(Ym(e)),t.appendChild(Xm(e)),t.appendChild(Qm(e)),t}function Im(e,t){for(let[n,r]of Object.entries(t)){let t=e.querySelector(`[data-action="${n}"]`);t&&t.classList.toggle(`is-active`,r)}}function Lm(e,t){let n=e.querySelector(`[data-action="heading"]`);n&&(n.value=t===!1?`0`:String(t))}function Rm(){let e=document.createElement(`div`);return e.className=`notes-toolbar-group`,e}function zm(e,t,n,r){let i=document.createElement(`button`);return i.className=`notes-toolbar-btn`,i.dataset.action=e,i.title=n,i.type=`button`,i.innerHTML=t,r&&i.addEventListener(`click`,r),i}function Bm(e){let t=Rm(),n=document.createElement(`select`);n.dataset.action=`heading`,n.title=`Text style`;for(let e of[{value:`0`,label:`Paragraph`},{value:`1`,label:`Heading 1`},{value:`2`,label:`Heading 2`},{value:`3`,label:`Heading 3`},{value:`4`,label:`Heading 4`},{value:`5`,label:`Heading 5`},{value:`6`,label:`Heading 6`}]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,n.appendChild(t)}return n.addEventListener(`change`,()=>{let t=parseInt(n.value,10);e.onHeading?.(t!==0&&t)}),t.appendChild(n),t}function Vm(e){let t=Rm();return t.appendChild(zm(`bold`,`<b>B</b>`,`Bold`,e.onBold)),t.appendChild(zm(`italic`,`<i>I</i>`,`Italic`,e.onItalic)),t.appendChild(zm(`underline`,`<u>U</u>`,`Underline`,e.onUnderline)),t.appendChild(zm(`strike`,`<s>S</s>`,`Strikethrough`,e.onStrike)),t}function Hm(e){let t=Rm();return t.appendChild(Um(`color`,`A`,`Text color`,`#000000`,t=>{Pm(t),e.onColor?.(t)})),t.appendChild(Um(`background`,`A`,`Background color`,`#ffff00`,t=>{Pm(t),e.onBackground?.(t)})),t}function Um(e,t,n,r,i){let a=document.createElement(`button`);a.className=`notes-toolbar-btn notes-toolbar-color-btn`,a.dataset.action=e,a.title=n,a.type=`button`;let o=document.createElement(`span`);o.className=`notes-toolbar-color-letter`,o.textContent=t,a.appendChild(o);let s=document.createElement(`span`);s.className=`notes-toolbar-color-bar`,s.style.backgroundColor=r,a.appendChild(s);let c;return a.addEventListener(`click`,()=>{if(c){c.destroy(),c=void 0;return}let e=Wm(r,e=>{s.style.backgroundColor=e,i(e),c?.destroy(),c=void 0});c=km(a,{content:e,theme:`light-border`,trigger:`manual`,interactive:!0,placement:`bottom-start`,onHidden:()=>{c?.destroy(),c=void 0}}),c.show()}),a}function Wm(e,t){let n=document.createElement(`div`);n.className=`notes-color-panel`;let r=document.createElement(`div`);r.className=`notes-color-swatches`;for(let n of Am)r.appendChild(Gm(n,n===e,t));n.appendChild(r);let i=Nm();if(i.length){let r=document.createElement(`div`);r.className=`notes-color-section-label`,r.textContent=`Recent`,n.appendChild(r);let a=document.createElement(`div`);a.className=`notes-color-swatches`;for(let n of i)a.appendChild(Gm(n,n===e,t));n.appendChild(a)}let a=document.createElement(`div`);a.className=`notes-color-custom-row`;let o=document.createElement(`input`);o.type=`color`,o.value=e,o.className=`notes-color-custom-input`;let s=document.createElement(`label`);return s.className=`notes-color-custom-label`,s.textContent=`Custom...`,s.addEventListener(`click`,()=>o.click()),o.addEventListener(`input`,()=>t(o.value)),a.appendChild(o),a.appendChild(s),n.appendChild(a),n}function Gm(e,t,n){let r=document.createElement(`button`);return r.type=`button`,r.className=`notes-color-swatch`,t&&r.classList.add(`is-selected`),r.style.backgroundColor=e,(e===`#ffffff`||e===`#fff`)&&(r.style.border=`1px solid var(--chc-border-secondary)`),r.title=e,r.addEventListener(`click`,()=>n(e)),r}function Km(e){let t=Rm();return t.appendChild(zm(`orderedList`,qm(16,16,`<path d="M3 2h12v2H3zm0 5h12v2H3zm0 5h12v2H3z" fill="currentColor"/><text x="0" y="4" font-size="3.5" fill="currentColor">1</text><text x="0" y="9" font-size="3.5" fill="currentColor">2</text><text x="0" y="14" font-size="3.5" fill="currentColor">3</text>`),`Ordered list`,e.onOrderedList)),t.appendChild(zm(`bulletList`,qm(16,16,`<circle cx="1.5" cy="3" r="1.5" fill="currentColor"/><circle cx="1.5" cy="8" r="1.5" fill="currentColor"/><circle cx="1.5" cy="13" r="1.5" fill="currentColor"/><path d="M5 2h10v2H5zm0 5h10v2H5zm0 5h10v2H5z" fill="currentColor"/>`),`Bullet list`,e.onBulletList)),t}function qm(e,t,n){return`<svg width="${e}" height="${t}" viewBox="0 0 ${e} ${t}" xmlns="http://www.w3.org/2000/svg">${n}</svg>`}var Jm={alignLeft:qm(16,16,`<path d="M1 2h14v2H1zm0 4h9v2H1zm0 4h14v2H1zm0 4h9v2H1z" fill="currentColor"/>`),alignCenter:qm(16,16,`<path d="M1 2h14v2H1zm3.5 4h7v2h-7zM1 10h14v2H1zm3.5 4h7v2h-7z" fill="currentColor"/>`),alignRight:qm(16,16,`<path d="M1 2h14v2H1zm6 4h8v2H7zM1 10h14v2H1zm6 4h8v2H7z" fill="currentColor"/>`),alignJustify:qm(16,16,`<path d="M1 2h14v2H1zm0 4h14v2H1zm0 4h14v2H1zm0 4h14v2H1z" fill="currentColor"/>`)};function Ym(e){let t=Rm();return t.appendChild(zm(`alignLeft`,Jm.alignLeft,`Align left`,()=>e.onAlign?.(`left`))),t.appendChild(zm(`alignCenter`,Jm.alignCenter,`Align center`,()=>e.onAlign?.(`center`))),t.appendChild(zm(`alignRight`,Jm.alignRight,`Align right`,()=>e.onAlign?.(`right`))),t.appendChild(zm(`alignJustify`,Jm.alignJustify,`Justify`,()=>e.onAlign?.(`justify`))),t}function Xm(e){let t=Rm();t.appendChild(zm(`blockquote`,`“`,`Blockquote`,e.onBlockquote)),t.appendChild(zm(`codeBlock`,`</>`,`Code block`,e.onCodeBlock));let n=zm(`link`,`⇗`,`Insert link`);Zm(n,`Enter URL`,`https://`,t=>e.onLink?.(t)),t.appendChild(n);let r=zm(`video`,`▷`,`Insert video`);return Zm(r,`YouTube URL`,`https://youtube.com/...`,t=>e.onVideo?.(t)),t.appendChild(r),t}function Zm(e,t,n,r){let i;e.addEventListener(`click`,()=>{if(i){i.destroy(),i=void 0;return}let a=document.createElement(`div`);a.className=`notes-url-panel`;let o=document.createElement(`div`);o.className=`notes-url-label`,o.textContent=t,a.appendChild(o);let s=document.createElement(`input`);s.type=`url`,s.className=`notes-url-input`,s.placeholder=n,a.appendChild(s);let c=document.createElement(`div`);c.className=`notes-url-actions`;let l=document.createElement(`button`);l.type=`button`,l.className=`button notes-url-cancel`,l.textContent=`Cancel`,l.addEventListener(`click`,()=>{i?.destroy(),i=void 0});let u=document.createElement(`button`);u.type=`button`,u.className=`button is-info notes-url-confirm`,u.textContent=`Insert`,u.addEventListener(`click`,()=>{let e=s.value.trim();e&&r(e),i?.destroy(),i=void 0}),c.appendChild(l),c.appendChild(u),a.appendChild(c),s.addEventListener(`keydown`,e=>{e.key===`Enter`?(e.preventDefault(),u.click()):e.key===`Escape`&&l.click()}),i=km(e,{content:a,theme:`light-border`,trigger:`manual`,interactive:!0,placement:`bottom-start`,onShown:()=>setTimeout(()=>s.focus(),0),onHidden:()=>{i?.destroy(),i=void 0}}),i.show()})}function Qm(e){let t=Rm();return t.appendChild(zm(`clearFormatting`,`⊘`,`Clear formatting`,e.onClearFormatting)),t}function $m(e={}){let t=document.createElement(`div`);t.className=`notes-editor-content`;let l={toolbar:void 0,editorElement:t,editor:void 0,getHtml:()=>l.editor&&!l.editor.isEmpty?l.editor.getHTML():``,isEmpty:()=>!l.editor||l.editor.isEmpty,destroy:()=>{l.editor?.destroy(),l.editor=void 0}};l.toolbar=Fm({onHeading:e=>{l.editor&&(e===!1?l.editor.chain().focus().setParagraph().run():l.editor.chain().focus().toggleHeading({level:e}).run())},onBold:()=>l.editor?.chain().focus().toggleBold().run(),onItalic:()=>l.editor?.chain().focus().toggleItalic().run(),onUnderline:()=>l.editor?.chain().focus().toggleUnderline().run(),onStrike:()=>l.editor?.chain().focus().toggleStrike().run(),onColor:e=>l.editor?.chain().focus().setColor(e).run(),onBackground:e=>l.editor?.chain().focus().setHighlight({color:e}).run(),onBulletList:()=>l.editor?.chain().focus().toggleBulletList().run(),onOrderedList:()=>l.editor?.chain().focus().toggleOrderedList().run(),onAlign:e=>l.editor?.chain().focus().setTextAlign(e).run(),onBlockquote:()=>l.editor?.chain().focus().toggleBlockquote().run(),onCodeBlock:()=>l.editor?.chain().focus().toggleCodeBlock().run(),onLink:e=>l.editor?.chain().focus().setLink({href:e}).run(),onVideo:e=>l.editor?.commands.setYoutubeVideo({src:e}),onClearFormatting:()=>l.editor?.chain().focus().clearNodes().unsetAllMarks().run()});let u=()=>{if(l.editor){Im(l.toolbar,{bold:l.editor.isActive(`bold`),italic:l.editor.isActive(`italic`),underline:l.editor.isActive(`underline`),strike:l.editor.isActive(`strike`),orderedList:l.editor.isActive(`orderedList`),bulletList:l.editor.isActive(`bulletList`),blockquote:l.editor.isActive(`blockquote`),codeBlock:l.editor.isActive(`codeBlock`),alignLeft:l.editor.isActive({textAlign:`left`}),alignCenter:l.editor.isActive({textAlign:`center`}),alignRight:l.editor.isActive({textAlign:`right`}),alignJustify:l.editor.isActive({textAlign:`justify`})});for(let e=1;e<=6;e++)if(l.editor.isActive(`heading`,{level:e})){Lm(l.toolbar,e);return}Lm(l.toolbar,!1)}};return requestAnimationFrame(()=>{l.editor=new r.Editor({element:t,extensions:[o.default,i.TextStyle,n.Color,a.default.configure({multicolor:!0}),s.default.configure({types:[`heading`,`paragraph`]}),c.default.configure({inline:!1})],content:e.initialHtml||``,onSelectionUpdate:u,onTransaction:u})}),l}function eh(e,t,n){if(!e)return{};let r=document.createElement(`aside`);r.classList.add(`menu`);let i={},a=e=>n&&e.close!==!1?t=>{t.stopPropagation(),n(),e.onClick()}:t=>{t.stopPropagation(),e.onClick()},o=0,s=()=>(o+=1,o),c=e=>e?.heading||e?.text||e?.label||`Item ${s()}`,l=e=>{let t=document.createElement(`li`);if(t.className=`font-medium`,e.style&&(t.style.cssText=e.style),e.onClick){let n=e.fontSize||`1em`;if(e.divider){let e=document.createElement(`hr`);e.classList.add(`dropdown-divider`),t.appendChild(e)}else{let r=document.createElement(`a`),i=e.disabled?`0.4`:`1`;r.style.cssText=`text-decoration: none; opacity: ${i}; font-size: ${n}`,e.class&&r.classList.add(e.class),e.color&&(r.style.color=e.color),e.heading&&(r.style.fontWeight=`bold`),e.disabled||(r.onclick=a(e)),r.innerHTML=c(e),t.appendChild(r)}}else t.innerHTML=c(e),e.disabled||(t.onclick=e.onClick);return t},u;for(let e of t||[])if(!e.hide){if(e.items){if(e.text){let t=document.createElement(`p`);t.className=`menu-label font-medium`,t.innerHTML=e.text,r.appendChild(t)}let t=document.createElement(`ul`);t.className=`menu-list`;for(let n of e.items)n.hide||t.appendChild(l(n));r.appendChild(t)}else if(e.type===`input`){let{field:t,inputElement:n}=gn(e);e.focus&&(u=n),i[e.field]=n,r.appendChild(t)}else if(e.type===`divider`){let e=document.createElement(`hr`);e.classList.add(`dropdown-divider`),r.appendChild(e)}}return e.appendChild(r),{focusElement:u}}function th(e){return typeof e==`function`}var nh;function rh(e){nh&&=(nh?.destroy(!0),void 0),e?.remove&&e.remove()}function ih(e){let{title:t,options:n,menuItems:r=[],coords:i,callback:a,config:o}=e,{target:s,items:c}=e;if(!n?.length&&!c?.length&&!r)return;rh();let l=document.createElement(`div`),u;return s||=i?.evt?.target,s&&(nh=km(s,{content:()=>{c=c?.filter(e=>!e.hide&&!e.disabled).map(e=>({...e,onClick:()=>{rh(l),th(e.onClick)&&e.onClick()}}))||n?.filter(e=>!e.hide&&!e.disabled).map(e=>({text:typeof e==`object`?e.option:e,style:e.style,onClick:()=>{e.subMenu?nh.setContent(`IMPLEMENT SUB MENU`):th(e.onClick)?(rh(l),e.onClick()):th(a)&&a&&(rh(l),a(typeof e==`object`?{...e,coords:i}:e))}}));let e=[{text:t,items:c},...r];return u=eh(l,e).focusElement,l},theme:`light-border`,trigger:`click`,onShown:()=>{u&&setTimeout(()=>u?.focus(),0)},...o}),nh.show(),nh.setProps({interactive:!0})),nh}var Y=`court-line`;function X(e,t){let n=document.createElementNS(`http://www.w3.org/2000/svg`,e);for(let[e,r]of Object.entries(t))n.setAttribute(e,r);return n}function ah(e,t){let n=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);return n.setAttribute(`viewBox`,e),n.setAttribute(`class`,t),n.setAttribute(`fill`,`none`),n.style.width=`100%`,n.style.height=`auto`,n.style.display=`block`,n}function oh(e){let t=ah(`0 0 360 780`,e);for(let e of[`M 0 0 L 360 0 L 360 780 L 0 780 Z`,`M 45 0 L 45 780`,`M 315 0 L 315 780`,`M 0 390 L 360 390`,`M 45 210 L 315 210`,`M 45 570 L 315 570`,`M 180 210 L 180 570`,`M 180 0 L 180 20`,`M 180 760 L 180 780`])t.appendChild(X(`path`,{d:e,class:Y}));return t}function sh(e){let t=ah(`0 0 500 470`,e),n=[X(`rect`,{x:`0`,y:`0`,width:`500`,height:`470`,class:Y}),X(`circle`,{cx:`250`,cy:`470`,r:`60`,class:Y}),X(`line`,{x1:`0`,y1:`470`,x2:`500`,y2:`470`,class:Y}),X(`rect`,{x:`170`,y:`0`,width:`160`,height:`190`,class:Y}),X(`circle`,{cx:`250`,cy:`190`,r:`60`,class:Y}),X(`line`,{x1:`220`,y1:`40`,x2:`280`,y2:`40`,class:Y}),X(`circle`,{cx:`250`,cy:`52`,r:`12`,class:Y}),X(`path`,{d:`M 30 0 L 30 90 A 220 220 0 0 0 470 90 L 470 0`,class:Y})];for(let e of n)t.appendChild(e);return t}function ch(e){let t=ah(`0 0 500 440`,e),n=[X(`path`,{d:`M 20 170 A 350 400 0 0 1 480 170`,class:Y}),X(`line`,{x1:`250`,y1:`400`,x2:`20`,y2:`170`,class:Y}),X(`line`,{x1:`250`,y1:`400`,x2:`480`,y2:`170`,class:Y}),X(`path`,{d:`M 250 400 L 314 336 L 250 273 L 186 336 Z`,class:Y}),X(`path`,{d:`M 340 355 A 100 100 0 0 1 160 355`,class:Y}),X(`line`,{x1:`340`,y1:`355`,x2:`265`,y2:`405`,class:Y}),X(`line`,{x1:`160`,y1:`355`,x2:`235`,y2:`405`,class:Y}),X(`path`,{d:`M 235 405 A 18 18 0 0 1 265 405`,class:Y}),X(`circle`,{cx:`250`,cy:`340`,r:`9`,class:Y}),X(`line`,{x1:`247`,y1:`339`,x2:`253`,y2:`339`,class:Y}),X(`path`,{d:`M 244 398 L 244 404 L 250 408 L 256 404 L 256 398 Z`,class:Y}),X(`rect`,{x:`310`,y:`332`,width:`8`,height:`8`,transform:`rotate(45 314 336)`,class:Y}),X(`rect`,{x:`246`,y:`269`,width:`8`,height:`8`,transform:`rotate(45 250 273)`,class:Y}),X(`rect`,{x:`182`,y:`332`,width:`8`,height:`8`,transform:`rotate(45 186 336)`,class:Y}),X(`rect`,{x:`230`,y:`393`,width:`8`,height:`18`,class:Y}),X(`rect`,{x:`262`,y:`393`,width:`8`,height:`18`,class:Y})];for(let e of n)t.appendChild(e);return t}function lh(e){let t=ah(`0 0 850 2000`,e),n=[X(`rect`,{x:`0`,y:`0`,width:`850`,height:`2000`,rx:`280`,ry:`280`,class:Y}),X(`line`,{x1:`0`,y1:`1000`,x2:`850`,y2:`1000`,class:Y}),X(`circle`,{cx:`425`,cy:`1000`,r:`60`,class:Y}),X(`line`,{x1:`0`,y1:`650`,x2:`850`,y2:`650`,class:Y}),X(`line`,{x1:`0`,y1:`1350`,x2:`850`,y2:`1350`,class:Y}),X(`line`,{x1:`140`,y1:`300`,x2:`710`,y2:`300`,class:Y}),X(`line`,{x1:`140`,y1:`1700`,x2:`710`,y2:`1700`,class:Y}),X(`path`,{d:`M 395 300 A 40 40 0 0 1 455 300`,class:Y}),X(`path`,{d:`M 395 1700 A 40 40 0 0 0 455 1700`,class:Y}),X(`circle`,{cx:`270`,cy:`650`,r:`50`,class:Y}),X(`circle`,{cx:`580`,cy:`650`,r:`50`,class:Y}),X(`circle`,{cx:`270`,cy:`1350`,r:`50`,class:Y}),X(`circle`,{cx:`580`,cy:`1350`,r:`50`,class:Y})];for(let e of n)t.appendChild(e);return t}function uh(e){let t=ah(`0 0 200 440`,e);for(let e of[`M 0 0 L 200 0 L 200 440 L 0 440 Z`,`M 0 220 L 200 220`,`M 0 150 L 200 150`,`M 0 290 L 200 290`,`M 100 0 L 100 150`,`M 100 290 L 100 440`])t.appendChild(X(`path`,{d:e,class:Y}));return t}function dh(e){let t=ah(`0 0 200 440`,e);for(let e of[`M 0 0 L 200 0 L 200 440 L 0 440 Z`,`M 18 0 L 18 440`,`M 182 0 L 182 440`,`M 0 220 L 200 220`,`M 0 146 L 200 146`,`M 0 294 L 200 294`,`M 0 30 L 200 30`,`M 0 410 L 200 410`,`M 100 146 L 100 220`,`M 100 220 L 100 294`])t.appendChild(X(`path`,{d:e,class:Y}));return t}function fh(e){let t=ah(`0 0 100 200`,e);for(let e of[`M 0 0 L 100 0 L 100 200 L 0 200 Z`,`M 0 100 L 100 100`,`M 0 69.5 L 100 69.5`,`M 0 130.5 L 100 130.5`,`M 50 69.5 L 50 67.5`,`M 50 130.5 L 50 132.5`])t.appendChild(X(`path`,{d:e,class:Y}));return t}var ph=`COURT_SVG`,mh={tennis:oh,basketball:sh,baseball:ch,hockey:lh,pickleball:uh,badminton:dh,padel:fh},hh={TENNIS:`tennis`,PADEL:`padel`,PICKLEBALL:`pickleball`,BADMINTON:`badminton`},gh={HAL:`basketball`,INN:`baseball`,PER:`hockey`};function _h(e){if(e){for(let[t,n]of Object.entries(gh))if(e.startsWith(t))return n;if(e.startsWith(`SET`)||e.startsWith(`T`))return e.includes(`@RALLY`)?`pickleball`:`tennis`}}function vh(e){let t=e?.competitionFormat?.sport;return t&&hh[t]?hh[t]:_h(e?.matchUpFormat)}function yh(e){let t=e.getAttribute(`viewBox`);if(!t)return e;let n=t.split(/\s+/).map(Number);if(n.length!==4)return e;let[r,i,a,o]=n;if(o<=a)return e;e.setAttribute(`viewBox`,`${r} ${i} ${o} ${a}`);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`g`);for(s.setAttribute(`transform`,`translate(${o}, 0) rotate(90)`);e.firstChild;)s.appendChild(e.firstChild);return e.appendChild(s),e}function bh(e,t=``){let n=e?mh[e]:void 0;if(n)return yh(n(t?`court--${e} ${t}`:`court--${e}`))}function xh(e){let t=[];return e.city&&t.push(e.city),(e.state||e.region)&&t.push(e.state||e.region),e.countryCode?t.push(e.countryCode):e.country&&t.push(e.country),t.join(`, `)}function Sh(e){if(!e)return;let t=xh(e);return t.length?t:void 0}function Ch(e){let t=e?.find(Boolean);if(!t)return;let n=t.addresses?.find(Boolean);return n?Sh(n)??t.venueName:t.venueName}var wh=/^(\d{4})-(\d{2})-(\d{2})/,Th=864e5;function Eh(e){if(!e)return null;let t=wh.exec(e);if(!t)return null;let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?null:{year:n,month:r,day:i}}function Dh(e,t){if(!t)return new Date(e.year,e.month-1,e.day);let n=Date.UTC(e.year,e.month-1,e.day,0,0,0,0),r=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`}),i=new Date(n);for(let e=0;e<2;e++){let e=r.formatToParts(i),t=t=>Number(e.find(e=>e.type===t)?.value??0),a=Date.UTC(t(`year`),t(`month`)-1,t(`day`),t(`hour`),t(`minute`),t(`second`))-i.getTime();i=new Date(n-a)}return i}function Oh(e,t){if(!t)return new Date(e.year,e.month-1,e.day+1);let n=Dh(e,t),r=new Date(n.getTime()+Th),i=new Intl.DateTimeFormat(`en-US`,{timeZone:t,year:`numeric`,month:`2-digit`,day:`2-digit`}).formatToParts(r),a=e=>Number(i.find(t=>t.type===e)?.value??0);return Dh({year:a(`year`),month:a(`month`),day:a(`day`)},t)}function kh(e){if(!e)return null;let t=Eh(e);if(t)return new Date(t.year,t.month-1,t.day);let n=new Date(e);return Number.isNaN(n.getTime())?null:n}function Ah(e){return e.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}function jh(e){return e.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})}function Mh(e,t){if(!e&&!t)return;let n=kh(e),r=kh(t),i=!!n&&!Number.isNaN(n.getTime()),a=!!r&&!Number.isNaN(r.getTime());if(!(!i&&!a))return i&&a&&n.getTime()===r.getTime()?jh(n):i&&a?n.getFullYear()===r.getFullYear()?`${Ah(n)} – ${Ah(r)}, ${r.getFullYear()}`:`${jh(n)} – ${jh(r)}`:jh(i?n:r)}function Nh(e){return e.slice().sort((e,t)=>{let n=e.courtOrder,r=t.courtOrder;return Number.isFinite(n)&&Number.isFinite(r)&&n!==r?n-r:Number.isFinite(n)&&!Number.isFinite(r)?-1:!Number.isFinite(n)&&Number.isFinite(r)?1:e.courtName.localeCompare(t.courtName,void 0,{numeric:!0})})}var Ph=`URL`;function Fh(e,t){if(!Array.isArray(e))return;let n=e.find(e=>e?.name===t&&e?.resourceType===Ph);return n?.url??n?.identifier}function Ih(e,t){if(Array.isArray(e))return e.find(e=>e?.resourceSubType===`COURT_SVG`&&(!t||e?.name===t))?.identifier}function Lh(e){let t=document.createElement(`div`);if(t.className=e.cardClass,t.setAttribute(`aria-busy`,`true`),e.showImage){let n=document.createElement(`div`);n.className=e.imageClass;let r=document.createElement(`div`);r.className=e.blockClass,n.appendChild(r),t.appendChild(n)}if(e.bodyLines>0){let n=document.createElement(`div`);n.className=e.bodyClass;for(let t=0;t<e.bodyLines;t++){let r=document.createElement(`div`);r.className=e.lineClass,r.style.width=t===0?`90%`:`${60+t*10}%`,n.appendChild(r)}t.appendChild(n)}if(e.showFooter){let n=document.createElement(`div`);n.className=e.footerClass;let r=document.createElement(`div`);r.className=e.lineClass,r.style.width=`40%`,n.appendChild(r),t.appendChild(n)}return t}var Rh={showImage:!0,cornerBadges:[`status`],body:[`title`,`tier`,`location`,`dateRange`],footer:[`feeBadge`,`playerCount`]};function zh(e){return e?{showImage:e.showImage??Rh.showImage,cornerBadges:e.cornerBadges??Rh.cornerBadges,body:e.body??Rh.body,footer:e.footer??Rh.footer}:Rh}var Bh=()=>`chc-tc-card`,Vh=()=>`chc-tc-card--clickable`,Hh=()=>`chc-tc-card--offline`,Uh=()=>`chc-tc-image`,Wh=()=>`chc-tc-image-img`,Gh=()=>`chc-tc-image-svg`,Kh=()=>`chc-tc-image-placeholder`,qh=()=>`chc-tc-corner-badges`,Jh=()=>`chc-tc-status-pill`,Yh=()=>`chc-tc-offline-badge`,Xh=()=>`chc-tc-body`,Zh=()=>`chc-tc-title`,Qh=()=>`chc-tc-location`,$h=()=>`chc-tc-date-range`,eg=()=>`chc-tc-organizer`,tg=()=>`chc-tc-updated-at`,ng=()=>`chc-tc-footer`,rg=()=>`chc-tc-fee-badge`,ig=()=>`chc-tc-player-count`,ag=()=>`chc-tc-event-count`,og=()=>`chc-tc-tier-badge`,sg=()=>`chc-tc-card chc-tc-skeleton`,cg=()=>`chc-tc-skeleton-line`,lg=()=>`chc-tc-skeleton-block`;function ug(e,t,n){let r=zh(t),i=document.createElement(`div`);return i.className=Bh(),i.dataset.tournamentId=e.tournamentId,e.offline&&i.classList.add(Hh()),n?.onClick&&(i.classList.add(Vh()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showImage!==!1&&i.appendChild(dg(e,r)),r.body.length&&i.appendChild(gg(e,r)),r.footer.length&&i.appendChild(wg(e,r)),i}function dg(e,t){let n=document.createElement(`div`);if(n.className=Uh(),e.tournamentImageURL){let t=document.createElement(`img`);t.className=Wh(),t.src=e.tournamentImageURL,t.alt=e.tournamentName||``,t.loading=`lazy`,t.addEventListener(`error`,()=>pg(n,e)),n.appendChild(t)}else fg(n,e);if(t.cornerBadges.length){let r=mg(e,t.cornerBadges);r&&n.appendChild(r)}return n}function fg(e,t){let n=bh(t.courtSvgSport,Gh());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=Kh(),e.appendChild(r)}function pg(e,t){e.querySelector(`.${Wh()}`)?.remove(),fg(e,t)}function mg(e,t){let n=[];for(let r of t){let t=hg(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=qh();for(let e of n)r.appendChild(e);return r}function hg(e,t){if(e===`status`){if(!t.status)return null;let e=document.createElement(`div`);return e.className=Jh(),e.dataset.kind=t.status.kind,e.textContent=t.status.label,e}if(e===`offline`){if(!t.offline)return null;let e=document.createElement(`div`);return e.className=Yh(),e.textContent=`Offline`,e}return null}function gg(e,t){let n=document.createElement(`div`);n.className=Xh();for(let r of t.body){let t=_g(r,e);t&&n.appendChild(t)}return n}function _g(e,t){switch(e){case`title`:return vg(t);case`tier`:return yg(t);case`location`:return bg(t);case`dateRange`:return xg(t);case`organizerName`:return Sg(t);case`updatedAt`:return Cg(t);default:return null}}function vg(e){if(!e.tournamentName)return null;let t=document.createElement(`div`);return t.className=Zh(),t.textContent=e.tournamentName,t.title=e.tournamentName,t}function yg(e){let t=e.tournamentTier?.value;if(!t)return null;let n=document.createElement(`div`);return n.className=og(),n.textContent=t,n.title=e.tournamentTier?.system?`${e.tournamentTier.system}: ${t}`:t,n}function bg(e){if(!e.location)return null;let t=document.createElement(`div`);return t.className=Qh(),t.textContent=e.location,t.title=e.location,t}function xg(e){if(!e.dateRangeFormatted)return null;let t=document.createElement(`div`);return t.className=$h(),t.textContent=e.dateRangeFormatted,t}function Sg(e){if(!e.organizerName)return null;let t=document.createElement(`div`);return t.className=eg(),t.textContent=e.organizerName,t}function Cg(e){if(!e.updatedAt)return null;let t=document.createElement(`div`);t.className=tg();let n=new Date(e.updatedAt);return t.textContent=Number.isNaN(n.getTime())?e.updatedAt:n.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`}),t}function wg(e,t){let n=document.createElement(`div`);n.className=ng();for(let r of t.footer){let t=Tg(r,e);t&&n.appendChild(t)}return n}function Tg(e,t){switch(e){case`feeBadge`:return Eg(t);case`playerCount`:return Dg(t);case`eventCount`:return Og(t);default:return null}}function Eg(e){if(!e.feeFormatted)return null;let t=document.createElement(`div`);return t.className=rg(),t.textContent=e.feeFormatted,t}function Dg(e){if(typeof e.participantCount!=`number`)return null;let t=document.createElement(`div`);return t.className=ig(),t.textContent=`${e.participantCount} ${e.participantCount===1?`player`:`players`}`,t}function Og(e){if(typeof e.eventCount!=`number`)return null;let t=document.createElement(`div`);return t.className=ag(),t.textContent=`${e.eventCount} ${e.eventCount===1?`event`:`events`}`,t}function kg(e){let t=zh(e);return Lh({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:sg(),imageClass:Uh(),bodyClass:Xh(),footerClass:ng(),blockClass:lg(),lineClass:cg()})}var Ag=6048e5;function jg(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function Mg(e,t,n){return!t||!n?!1:t.getTime()<=e.getTime()&&e.getTime()<n.getTime()}function Ng(e){return`Opens ${e.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})}`}function Pg(e,t=new Date){let n=e.tournamentStatus?.toUpperCase();if(n===`CANCELLED`||n===`ABANDONDED`||n===`ABANDONED`)return{kind:`cancelled`,label:`Cancelled`};let r=e.timeZone,i=Eh(e.endDate),a=i?Oh(i,r):null;if(n===`COMPLETED`||a&&t.getTime()>=a.getTime())return{kind:`completed`,label:`Completed`};let o=Eh(e.startDate);if(Mg(t,o?Dh(o,r):null,a))return{kind:`live`,label:`Live`};let s=jg(e.entriesClose);if(s){let e=s.getTime()-t.getTime();if(e>0&&e<=Ag)return{kind:`closing-soon`,label:`Closing Soon`}}let c=jg(e.entriesOpen);return c&&c.getTime()>t.getTime()?{kind:`registration-opens`,label:Ng(c)}:null}var Fg=`USD`,Ig=`–`;function Lg(e,t){try{return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t}).format(e)}catch{return`$${e.toFixed(2)}`}}function Rg(e){let t=new Set;for(let n of e)t.add(n.currencyCode||Fg);return[...t]}function zg(e){return[...e].sort((e,t)=>e.amount-t.amount).find(Boolean)}function Bg(e){if(!e||e.length===0)return null;let t=e.filter(e=>typeof e.amount==`number`&&!Number.isNaN(e.amount));if(t.length===0)return null;if(t.length===1){let e=t[0],n=e.currencyCode||Fg;return`${n} ${Lg(e.amount,n)}`}let n=Rg(t);if(n.length>1){let e=zg(t);if(!e)return null;let n=e.currencyCode||Fg;return`From ${n} ${Lg(e.amount,n)}`}let r=n[0],i=t.map(e=>e.amount).sort((e,t)=>e-t),a=i[0],o=i.at(-1)??a;return a===o?`${r} ${Lg(a,r)}`:`${r} ${Lg(a,r)} ${Ig} ${Lg(o,r)}`}var Vg=`tournamentImage`;function Hg(e){let t=e?.registrationProfile?.entryFees;return Array.isArray(t)?t.filter(e=>e&&typeof e.amount==`number`):[]}function Ug(e){let t=e?.timeItems;if(Array.isArray(t))return t.find(e=>e?.itemType===`TMX`)?.itemValue?.offline}function Wg(e,t){let n=Array.isArray(e?.onlineResources)?e.onlineResources:void 0,r=Array.isArray(e?.venues)?e.venues:[],i=Array.isArray(e?.participants)?e.participants:[],a=Array.isArray(e?.events)?e.events:[],o=t?.statusOverride===void 0?Pg({tournamentStatus:e?.tournamentStatus,startDate:e?.startDate,endDate:e?.endDate,entriesOpen:e?.registrationProfile?.entriesOpen,entriesClose:e?.registrationProfile?.entriesClose,timeZone:e?.localTimeZone||e?.timeZone},t?.now):t.statusOverride,s=e?.tournamentImageURL??Fh(n,Vg),c=e?.courtSvgSport??Ih(n);return{tournamentId:e?.tournamentId??``,tournamentName:e?.tournamentName??``,startDate:e?.startDate,endDate:e?.endDate,dateRangeFormatted:Mh(e?.startDate,e?.endDate),location:Ch(r),tournamentImageURL:s,courtSvgSport:c,participantCount:i.length||void 0,eventCount:a.length||void 0,organizerName:e?.tournamentOrganizers?.find?.(Boolean)?.organizerName,status:o,feeFormatted:Bg(Hg(e)),updatedAt:e?.updatedAt,offline:Ug(e),tournamentTier:Gg(e)}}function Gg(e){let t=e?.tournamentTier;if(!t||typeof t!=`object`||typeof t.system!=`string`||typeof t.value!=`string`)return;let n={system:t.system,value:t.value};return typeof t.numericRank==`number`&&Number.isFinite(t.numericRank)&&(n.numericRank=t.numericRank),n}var Kg={showImage:!0,showMap:!0,cornerBadges:[`primaryBadge`],body:[`title`,`address`,`courtBreakdown`],footer:[`amenityRow`]};function qg(e){return e?{showImage:e.showImage??Kg.showImage,showMap:e.showMap??Kg.showMap,cornerBadges:e.cornerBadges??Kg.cornerBadges,body:e.body??Kg.body,footer:e.footer??Kg.footer}:Kg}var Jg=()=>`chc-vc-card`,Yg=()=>`chc-vc-card--clickable`,Xg=()=>`chc-vc-image`,Zg=()=>`chc-vc-image-img`,Qg=()=>`chc-vc-image-svg`,$g=()=>`chc-vc-image-map`,e_=()=>`chc-vc-image-placeholder`,t_=()=>`chc-vc-corner-badges`,n_=()=>`chc-vc-primary-badge`,r_=()=>`chc-vc-body`,i_=()=>`chc-vc-title`,a_=()=>`chc-vc-address`,o_=()=>`chc-vc-court-breakdown`,s_=()=>`chc-vc-footer`,c_=()=>`chc-vc-amenity-row`,l_=()=>`chc-vc-amenity`,u_=()=>`chc-vc-card chc-vc-skeleton`,d_=()=>`chc-vc-skeleton-line`,f_=()=>`chc-vc-skeleton-block`;function p_(e,t,n){let r=qg(t),i=document.createElement(`div`);i.className=Jg(),i.dataset.venueId=e.venueId;let a=null;r.showImage!==!1&&(a=__(e,r,()=>f()),i.appendChild(a));let o=r.body.length?T_(e,r):null;o&&i.appendChild(o);let s=r.footer.length?k_(e,r):null;s&&i.appendChild(s);function c(){return!!a?.querySelector(`iframe`)}let l=new Map;function u(e,t){if(l.has(e))return;let n=e=>{e.stopPropagation(),t()},r=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),t())};e.classList.add(Yg()),e.tabIndex=0,e.addEventListener(`click`,n),e.addEventListener(`keydown`,r),l.set(e,{click:n,keydown:r})}function d(e){let t=l.get(e);t&&(e.removeEventListener(`click`,t.click),e.removeEventListener(`keydown`,t.keydown),e.classList.remove(Yg()),e.removeAttribute(`tabindex`),l.delete(e))}function f(){if(!n?.onClick)return;let t=()=>n.onClick(e);c()?(d(i),o&&u(o,t),s&&u(s,t)):(o&&d(o),s&&d(s),u(i,t))}return f(),i}function m_(e){return typeof e.latitude==`number`&&typeof e.longitude==`number`}function h_(e){let t=e.latitude,n=e.longitude,r=.01,i=`https://www.openstreetmap.org/export/embed.html?bbox=${`${n-r},${t-r},${n+r},${t+r}`}&marker=${t},${n}&layer=mapnik`,a=document.createElement(`iframe`);return a.className=$g(),a.src=i,a.loading=`lazy`,a.title=`Map of ${e.venueName}`,a}function g_(e,t){let n=bh(t.courtSvgSport,Qg());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=e_(),e.appendChild(r)}function __(e,t,n){let r=document.createElement(`div`);if(r.className=Xg(),e.venueImageURL){let i=document.createElement(`img`);i.className=Zg(),i.src=e.venueImageURL,i.alt=e.venueName||``,i.loading=`lazy`,i.addEventListener(`error`,()=>{i.remove(),t.showMap!==!1&&m_(e)?r.appendChild(h_(e)):g_(r,e),n?.()}),r.appendChild(i)}else t.showMap!==!1&&m_(e)?r.appendChild(h_(e)):g_(r,e);if(t.cornerBadges.length){let n=y_(e,t.cornerBadges);n&&r.appendChild(n)}return r}function v_(e,t){if(e===`primaryBadge`){if(!t.isPrimary)return null;let e=document.createElement(`div`);return e.className=n_(),e.textContent=`Primary`,e}return null}function y_(e,t){let n=[];for(let r of t){let t=v_(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=t_();for(let e of n)r.appendChild(e);return r}function b_(e){if(!e.venueName)return null;let t=document.createElement(`div`);return t.className=i_(),t.textContent=e.venueName,t.title=e.notes?`${e.venueName}\n${e.notes}`:e.venueName,t}function x_(e){if(!e.addressFormatted)return null;let t=document.createElement(`div`);return t.className=a_(),t.textContent=e.addressFormatted,t.title=e.addressFormatted,t}function S_(e){if(!e.courtBreakdown)return null;let t=document.createElement(`div`);return t.className=o_(),t.textContent=e.courtBreakdown,t}function C_(e){if(!e.venueAbbreviation)return null;let t=document.createElement(`div`);return t.className=o_(),t.textContent=e.venueAbbreviation,t}function w_(e,t){return e===`title`?b_(t):e===`address`?x_(t):e===`courtBreakdown`?S_(t):e===`venueAbbreviation`?C_(t):null}function T_(e,t){let n=document.createElement(`div`);n.className=r_();for(let r of t.body){let t=w_(r,e);t&&n.appendChild(t)}return n}function E_(e){let t=document.createElement(`span`);return t.className=l_(),t.textContent=e,t}function D_(e){let t=[];if(typeof e.courtCount==`number`&&t.push(E_(`${e.courtCount} ${e.courtCount===1?`court`:`courts`}`)),e.indoorCount&&t.push(E_(`${e.indoorCount} indoor`)),e.outdoorCount&&t.push(E_(`${e.outdoorCount} outdoor`)),e.floodlitCount&&t.push(E_(`${e.floodlitCount} lit`)),!t.length)return null;let n=document.createElement(`div`);n.className=c_();for(let e of t)n.appendChild(e);return n}function O_(e,t){return e===`amenityRow`?D_(t):e===`address`?x_(t):e===`courtBreakdown`?S_(t):null}function k_(e,t){let n=document.createElement(`div`);n.className=s_();for(let r of t.footer){let t=O_(r,e);t&&n.appendChild(t)}return n}function A_(e){let t=qg(e);return Lh({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:u_(),imageClass:Xg(),bodyClass:r_(),footerClass:s_(),blockClass:f_(),lineClass:d_()})}var j_=`venueImage`;function M_(e){let t=[];return e.indoorOutdoor&&t.push(e.indoorOutdoor.toLowerCase()),e.surfaceCategory&&t.push(e.surfaceCategory.toLowerCase()),t.length?t.join(` `):`court`}function N_(e){if(!e.length)return;let t=new Map;for(let n of e){let e=M_(n);t.set(e,(t.get(e)??0)+1)}return[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e,t])=>`${t} ${e}`).join(`, `)}function P_(e,t){let n=0;for(let r of e)t(r)&&(n+=1);return n}function F_(e,t){let n=Array.isArray(e?.courts)?e.courts:[],r=Array.isArray(e?.onlineResources)?e.onlineResources:void 0,i=e?.addresses?.find(e=>e);return{venueId:e?.venueId??``,venueName:e?.venueName??``,venueAbbreviation:e?.venueAbbreviation,addressFormatted:Sh(i),latitude:typeof i?.latitude==`number`?i.latitude:void 0,longitude:typeof i?.longitude==`number`?i.longitude:void 0,courtCount:n.length||void 0,courtBreakdown:N_(n),indoorCount:P_(n,e=>e.indoorOutdoor===`INDOOR`)||void 0,outdoorCount:P_(n,e=>e.indoorOutdoor===`OUTDOOR`)||void 0,floodlitCount:P_(n,e=>!!e.floodlit)||void 0,isPrimary:!!e?.isPrimary,venueImageURL:e?.venueImageURL??Fh(r,j_),courtSvgSport:e?.courtSvgSport??Ih(r)??t?.sport,notes:e?.notes}}var I_={showImage:!0,cornerBadges:[`indoorOutdoor`,`floodlit`],body:[`title`,`surface`],footer:[`amenityRow`]};function L_(e){return e?{showImage:e.showImage??I_.showImage,cornerBadges:e.cornerBadges??I_.cornerBadges,body:e.body??I_.body,footer:e.footer??I_.footer}:I_}var R_=()=>`chc-cc-card`,z_=()=>`chc-cc-card--clickable`,B_=()=>`chc-cc-image`,V_=()=>`chc-cc-image-svg`,H_=()=>`chc-cc-image-placeholder`,U_=()=>`chc-cc-corner-badges`,W_=()=>`chc-cc-indoor-badge`,G_=()=>`chc-cc-floodlit-badge`,K_=()=>`chc-cc-body`,q_=()=>`chc-cc-title`,J_=()=>`chc-cc-surface`,Y_=()=>`chc-cc-availability`,X_=()=>`chc-cc-abbr`,Z_=()=>`chc-cc-footer`,Q_=()=>`chc-cc-amenity-row`,$_=()=>`chc-cc-card chc-cc-skeleton`,ev=()=>`chc-cc-skeleton-line`,tv=()=>`chc-cc-skeleton-block`;function nv(e,t,n){let r=L_(t),i=document.createElement(`div`);return i.className=R_(),i.dataset.courtId=e.courtId,n?.onClick&&(i.classList.add(z_()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showImage!==!1&&i.appendChild(iv(e,r)),r.body.length&&i.appendChild(mv(e,r)),r.footer.length&&i.appendChild(_v(e,r)),i}function rv(e,t){let n=bh(t.courtSvgSport,V_());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=H_(),e.appendChild(r)}function iv(e,t){let n=document.createElement(`div`);if(n.className=B_(),e.surfaceCategory&&(n.dataset.surface=e.surfaceCategory),rv(n,e),t.cornerBadges.length){let r=cv(e,t.cornerBadges);r&&n.appendChild(r)}return n}function av(e){if(!e.indoorOutdoor)return null;let t=document.createElement(`div`);return t.className=W_(),t.dataset.kind=e.indoorOutdoor,t.textContent=e.indoorOutdoor===`INDOOR`?`Indoor`:`Outdoor`,t}function ov(e){if(!e.floodlit)return null;let t=document.createElement(`div`);return t.className=G_(),t.textContent=`Lit`,t}function sv(e,t){return e===`indoorOutdoor`?av(t):e===`floodlit`?ov(t):null}function cv(e,t){let n=[];for(let r of t){let t=sv(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=U_();for(let e of n)r.appendChild(e);return r}function lv(e){if(!e.courtName)return null;let t=document.createElement(`div`);return t.className=q_(),t.textContent=e.courtName,t.title=e.notes?`${e.courtName}\n${e.notes}`:e.courtName,t}function uv(e){if(!e.surfaceLabel)return null;let t=document.createElement(`div`);return t.className=J_(),t.textContent=e.surfaceLabel,t}function dv(e){if(!e.availabilitySummary)return null;let t=document.createElement(`div`);return t.className=Y_(),t.textContent=e.availabilitySummary,t}function fv(e){if(!e.courtAbbreviation)return null;let t=document.createElement(`div`);return t.className=X_(),t.textContent=e.courtAbbreviation,t}function pv(e,t){return e===`title`?lv(t):e===`surface`?uv(t):e===`availability`?dv(t):e===`abbreviation`?fv(t):null}function mv(e,t){let n=document.createElement(`div`);n.className=K_();for(let r of t.body){let t=pv(r,e);t&&n.appendChild(t)}return n}function hv(e){let t=[];if(e.indoorOutdoor&&t.push(e.indoorOutdoor===`INDOOR`?`indoor`:`outdoor`),e.surfaceCategory&&t.push(e.surfaceCategory.toLowerCase()),e.floodlit&&t.push(`floodlit`),!t.length)return null;let n=document.createElement(`div`);return n.className=Q_(),n.textContent=t.join(` · `),n}function gv(e,t){return e===`amenityRow`?hv(t):e===`availability`?dv(t):e===`surface`?uv(t):null}function _v(e,t){let n=document.createElement(`div`);n.className=Z_();for(let r of t.footer){let t=gv(r,e);t&&n.appendChild(t)}return n}function vv(e){let t=L_(e);return Lh({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:$_(),imageClass:B_(),bodyClass:K_(),footerClass:Z_(),blockClass:tv(),lineClass:ev()})}var yv=`INDOOR`,bv=`OUTDOOR`,xv=new Set([`HARD`,`CLAY`,`GRASS`,`ARTIFICIAL`,`CARPET`]);function Sv(e){if(!e)return;let t=String(e).toUpperCase();if(t===yv)return yv;if(t===bv)return bv}function Cv(e){let t=e?.surfaceCategory?String(e.surfaceCategory).toUpperCase():void 0;if(t&&xv.has(t))return t;let n=e?.surfaceType?String(e.surfaceType).toUpperCase():void 0;return n&&xv.has(n)?n:t}function wv(e,t){let n=[];return e&&n.push(e.charAt(0)+e.slice(1).toLowerCase()),t&&n.push(t.charAt(0)+t.slice(1).toLowerCase()),n.length?n.join(` · `):void 0}function Tv(e,t){let n=Sv(e?.indoorOutdoor),r=Cv(e);return{courtId:e?.courtId??``,courtName:e?.courtName??``,courtAbbreviation:e?.courtAbbreviation,surfaceLabel:wv(n,r),indoorOutdoor:n,surfaceCategory:r,floodlit:!!e?.floodlit,courtSvgSport:t?.sport,notes:e?.notes}}var Ev={grouping:`setting`,sport:`tennis`,showGroupHeadings:!0,showSummary:!0,minCardWidth:`11rem`,emptyMessage:`No courts recorded for this venue`};function Dv(e){return e?{grouping:e.grouping??Ev.grouping,sport:e.sport??Ev.sport,showGroupHeadings:e.showGroupHeadings??Ev.showGroupHeadings,showSummary:e.showSummary??Ev.showSummary,minCardWidth:e.minCardWidth??Ev.minCardWidth,emptyMessage:e.emptyMessage??Ev.emptyMessage}:Ev}var Ov=()=>`chc-cl`,kv=()=>`chc-cl-summary`,Av=()=>`chc-cl-summary-count`,jv=()=>`chc-cl-group`,Mv=()=>`chc-cl-group-heading`,Nv=()=>`chc-cl-group-count`,Pv=()=>`chc-cl-grid`,Fv=()=>`chc-cl-empty`,Iv=`Unspecified`,Lv=`Unspecified surface`;function Rv(e){return e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function zv(e){let t=typeof e.indoorOutdoor==`string`?e.indoorOutdoor.trim():``;return t?Rv(t):Iv}function Bv(e){let t=typeof e.surfaceCategory==`string`?e.surfaceCategory.trim():``;return t?Rv(t):Lv}function Vv(e,t){let n=Nh(e);if(t===`none`)return[{key:`all`,label:`All courts`,courts:n}];let r=e=>t===`setting`?zv(e):t===`surface`?Bv(e):`${zv(e)} · ${Bv(e)}`,i=new Map;for(let e of n){let t=r(e),n=i.get(t);n?n.courts.push(e):i.set(t,{key:t,label:t,courts:[e]})}return[...i.values()]}function Hv(e){let t=new Map;for(let n of e){let e=zv(n),r=Bv(n),i=`${e===Iv?``:e.toLowerCase()} ${r===Lv?``:r.toLowerCase()}`.trim()||`court`;t.set(i,(t.get(i)??0)+1)}return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).map(([e,t])=>`${t} ${e}`).join(`, `)}function Uv(e,t,n){let r=Dv(t),i=e.courts??[],a=document.createElement(`div`);if(a.className=Ov(),e.venueId&&(a.dataset.venueId=e.venueId),!i.length){let e=document.createElement(`div`);return e.className=Fv(),e.textContent=r.emptyMessage,a.appendChild(e),a}r.showSummary&&a.appendChild(Wv(i));for(let e of Vv(i,r.grouping))a.appendChild(Gv(e,r,n));return a}function Wv(e){let t=document.createElement(`div`);t.className=kv();let n=document.createElement(`span`);n.className=Av(),n.textContent=`${e.length} ${e.length===1?`court`:`courts`}`;let r=document.createElement(`span`);return r.textContent=Hv(e),t.append(n,r),t}function Gv(e,t,n){let r=document.createElement(`div`);if(r.className=jv(),r.dataset.group=e.key,t.showGroupHeadings&&t.grouping!==`none`){let t=document.createElement(`div`);t.className=Mv();let n=document.createElement(`span`);n.textContent=e.label;let i=document.createElement(`span`);i.className=Nv(),i.textContent=String(e.courts.length),t.append(n,i),r.appendChild(t)}let i=document.createElement(`div`);i.className=Pv(),i.style.setProperty(`--chc-cl-min-card`,t.minCardWidth);for(let r of e.courts)i.appendChild(qv(r,t,n));return r.appendChild(i),r}function Kv(e){if(e===`setting`||e===`both`)return{cornerBadges:[`floodlit`]}}function qv(e,t,n){let r=Tv(e,{sport:t.sport}),i=n?.onCourtClick?{onClick:()=>n.onCourtClick?.(e)}:void 0;return nv(r,Kv(t.grouping),i)}var Jv={tiles:{map:{tileLayer:`https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png`,attribution:`&copy; <a href="https://openstreetmap.org">OpenStreetMap</a> Contributors`,maxZoom:18},satellite:{tileLayer:`https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}`,attribution:`Tiles &copy; Esri`}},darkTileLayer:{tileLayer:`https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png`,attribution:`&copy; <a href="https://openstreetmap.org">OpenStreetMap</a> Contributors &copy; <a href="https://carto.com/attributions">CARTO</a>`,maxZoom:20},view:`map`,showViewToggle:!0,zoom:16,height:`320px`,courtsLayout:`side`,showHeader:!0,showPopup:!0,scrollWheelZoom:!1,darkTiles:`auto`};function Yv(e){return e?{tiles:e.tiles??Jv.tiles,darkTileLayer:e.darkTileLayer===void 0?Jv.darkTileLayer:e.darkTileLayer,view:e.view??Jv.view,showViewToggle:e.showViewToggle??Jv.showViewToggle,zoom:e.zoom??Jv.zoom,height:e.height??Jv.height,courtsLayout:e.courtsLayout??Jv.courtsLayout,showHeader:e.showHeader??Jv.showHeader,showPopup:e.showPopup??Jv.showPopup,scrollWheelZoom:e.scrollWheelZoom??Jv.scrollWheelZoom,darkTiles:e.darkTiles??Jv.darkTiles}:Jv}var Xv=()=>`chc-vl`,Zv=()=>`chc-vl-header`,Qv=()=>`chc-vl-title`,$v=()=>`chc-vl-address`,ey=()=>`chc-vl-notes`,ty=()=>`chc-vl-body`,ny=()=>`chc-vl-body--below`,ry=()=>`chc-vl-mapwrap`,iy=()=>`chc-vl-map`,ay=()=>`chc-vl-map--invertible`,oy=()=>`chc-vl-toggle`,sy=()=>`chc-vl-toggle-btn`,cy=()=>`chc-vl-fallback`,ly=()=>`chc-vl-fallback-icon`,uy=()=>`chc-vl-courts`,dy=()=>`chc-vl-courts-title`,fy=()=>`chc-vl-court-list`,py=()=>`chc-vl-court`,my=()=>`chc-vl-court--clickable`,hy=()=>`chc-vl-court-name`,gy=()=>`chc-vl-court-meta`,_y=()=>`chc-vl-pip`,vy=()=>`chc-vl-marker`,yy=()=>`chc-vl-popup-title`,by=()=>`chc-vl-popup-address`,xy=`No coordinates for this venue`,Sy=`Map unavailable`,Cy=new WeakMap;function wy(e){return Number.isFinite(e.latitude)&&Number.isFinite(e.longitude)}function Ty(e){return Nh(e)}function Ey(e){let t=[];return e.indoorOutdoor&&t.push(e.indoorOutdoor.toLowerCase()),e.surfaceCategory&&t.push(e.surfaceCategory.toLowerCase()),t.join(` · `)}function Dy(e,t,n){let r=Yv(t),i=document.createElement(`div`);i.className=Xv(),i.dataset.venueId=e.venueId,r.showHeader&&i.appendChild(ky(e));let a=document.createElement(`div`);a.className=r.courtsLayout===`side`?ty():`${ty()} ${ny()}`;let{wrap:o,mapEl:s}=jy(e,r,n);a.appendChild(o);let c=e.courts??[];return r.courtsLayout!==`none`&&c.length&&a.appendChild(Py(c,e,n)),i.appendChild(a),s&&wy(e)&&Iy({root:i,mapEl:s,data:e,cfg:r,callbacks:n}),i}function Oy(e){let t=Cy.get(e);t&&(t(),Cy.delete(e))}function ky(e){let t=document.createElement(`div`);t.className=Zv();let n=document.createElement(`div`);if(n.className=Qv(),n.textContent=e.venueName,t.appendChild(n),e.addressFormatted){let n=document.createElement(`div`);n.className=$v(),n.textContent=e.addressFormatted,t.appendChild(n)}if(e.notes){let n=document.createElement(`div`);n.className=ey(),n.textContent=e.notes,t.appendChild(n)}return t}function Ay(e){let t=document.createElement(`div`);t.className=cy();let n=document.createElement(`div`);n.className=ly(),n.textContent=`📍`,n.setAttribute(`aria-hidden`,`true`);let r=document.createElement(`div`);return r.textContent=e,t.append(n,r),t}function jy(e,t,n){let r=document.createElement(`div`);if(r.className=ry(),r.style.height=t.height,!wy(e))return r.appendChild(Ay(xy)),{wrap:r,mapEl:null};let i=document.createElement(`div`);i.className=iy(),i.appendChild(Ay(``)),r.appendChild(i);let a=Object.keys(t.tiles);return t.showViewToggle&&a.length>1&&r.appendChild(My(a,t,n)),{wrap:r,mapEl:i}}function My(e,t,n){let r=document.createElement(`div`);r.className=oy(),r.dataset.viewToggle=`true`;let i=[];for(let a of e){let e=document.createElement(`button`);e.type=`button`,e.className=sy(),e.dataset.view=a,e.textContent=a===`satellite`?`Satellite`:`Map`,e.setAttribute(`aria-pressed`,String(a===t.view)),e.addEventListener(`click`,()=>{for(let t of i)t.setAttribute(`aria-pressed`,String(t===e));n?.onViewChange?.(a)}),i.push(e),r.appendChild(e)}return r}function Ny(e,t,n){let r=!!n?.onCourtClick,i=document.createElement(r?`button`:`div`);i.className=r?`${py()} ${my()}`:py(),i.dataset.courtId=e.courtId,r&&(i.type=`button`,i.addEventListener(`click`,()=>n?.onCourtClick?.(e,t)));let a=document.createElement(`span`);a.className=hy(),a.textContent=e.courtName;let o=document.createElement(`span`);o.className=gy();let s=Ey(e);if(s&&o.append(document.createTextNode(s)),e.floodlit){let e=document.createElement(`span`);e.className=_y(),e.title=`floodlit`,o.appendChild(e)}return i.append(a,o),i}function Py(e,t,n){let r=document.createElement(`div`);r.className=uy();let i=document.createElement(`div`);i.className=dy(),i.textContent=`Courts (${e.length})`,r.appendChild(i);let a=document.createElement(`div`);a.className=fy();for(let r of Ty(e))a.appendChild(Ny(r,t,n));return r.appendChild(a),r}function Fy(e){let t=e=>e.replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e]),n=e.addressFormatted?`<div class="${by()}">${t(e.addressFormatted)}</div>`:``;return`<div class="${yy()}">${t(e.venueName)}</div>${n}`}async function Iy({root:e,mapEl:t,data:n,cfg:r,callbacks:i}){let a;try{a=await import(`leaflet`)}catch(e){t.replaceChildren(Ay(Sy)),i?.onMapUnavailable?.(Error(`leaflet is an optional peerDependency of courthive-components and is not installed`,{cause:e}));return}let o=a.default??a;try{t.replaceChildren();let a=o.map(t,{scrollWheelZoom:r.scrollWheelZoom,attributionControl:!0});a.setView([n.latitude,n.longitude],r.zoom);let s=r.view,c=Hy(o,a,r,s);Uy(t,r,s);let l=e=>{s=e,a.removeLayer(c),c=Hy(o,a,r,e),Uy(t,r,e)},u=o.divIcon({className:``,html:`<div class="${vy()}"></div>`,iconSize:[14,14]}),d=o.marker([n.latitude,n.longitude],{icon:u}).addTo(a);r.showPopup&&d.bindPopup(Fy(n)),d.on(`click`,()=>i?.onVenueClick?.(n)),e.querySelector(`[data-view-toggle]`)?.addEventListener(`click`,e=>{let t=e.target?.closest(`button[data-view]`);t&&l(t.dataset.view)}),zy(t);let f=new ResizeObserver(()=>a.invalidateSize());f.observe(t);let p,m=globalThis.document?.documentElement;if(m&&r.darkTiles!==`never`&&r.darkTileLayer){let e=By();p=new MutationObserver(()=>{let t=By();t!==e&&(e=t,s!==`satellite`&&l(s))}),p.observe(m,{attributes:!0,attributeFilter:[`data-theme`]})}Cy.set(e,()=>{f.disconnect(),p?.disconnect(),a.remove()})}catch(e){t.replaceChildren(Ay(Sy)),i?.onMapUnavailable?.(Error(`Leaflet map failed to initialize`,{cause:e}))}}var Ly=!1;function Ry(e){return e?e!==`relative`&&e!==`absolute`:!1}function zy(e){Ly||Ry(globalThis.getComputedStyle?.(e)?.position)&&(Ly=!0,console.warn("[courthive-components] venue-locator: leaflet's stylesheet is missing — the map will render incorrectly. Add `import 'leaflet/dist/leaflet.css';` to the host application."))}function By(){return globalThis.document?.documentElement?.getAttribute(`data-theme`)===`dark`}function Vy(e,t,n){let r=e.tiles[t]??e.tiles.map;return t===`satellite`||e.darkTiles===`never`||!n?r:e.darkTileLayer??r}function Hy(e,t,n,r){let i=Vy(n,r,By());return e.tileLayer(i.tileLayer,{attribution:i.attribution,maxZoom:i.maxZoom??19}).addTo(t)}function Uy(e,t,n){let r=t.darkTiles===`auto`&&n!==`satellite`&&!t.darkTileLayer;e.classList.toggle(ay(),r)}function Wy(...e){for(let t of e)if(typeof t==`number`&&Number.isFinite(t))return t}function Gy(e,t){let n=typeof e?.indoorOutdoor==`string`?e.indoorOutdoor.toUpperCase():void 0;return{courtId:e?.courtId??`court-${t+1}`,courtName:e?.courtName??`Court ${t+1}`,indoorOutdoor:n===`INDOOR`||n===`OUTDOOR`?n:void 0,surfaceCategory:e?.surfaceCategory,floodlit:e?.floodlit,courtOrder:Wy(e?.courtOrder),latitude:Wy(e?.latitude),longitude:Wy(e?.longitude)}}function Ky(e){let t=Array.isArray(e?.courts)?e.courts:[],n=e?.addresses?.find(e=>e);return{venueId:e?.venueId??``,venueName:e?.venueName??e?.venueAbbreviation??``,venueAbbreviation:e?.venueAbbreviation,addressFormatted:Sh(n),latitude:Wy(e?.latitude,n?.latitude),longitude:Wy(e?.longitude,n?.longitude),courts:t.map(Gy),notes:e?.notes}}var qy=()=>`chc-team-card`,Jy=()=>`chc-team-card--clickable`,Yy=()=>`chc-team-card__title-row`,Xy=()=>`chc-team-card__name`,Zy=()=>`chc-team-card__nickname`,Qy=()=>`chc-team-card__counts`,$y=` · `;function eb(e,t){let n=document.createElement(`div`);n.className=qy(),e.teamId&&(n.dataset.teamId=e.teamId),t?.onClick&&(n.classList.add(Jy()),n.tabIndex=0,n.setAttribute(`role`,`button`),n.addEventListener(`click`,n=>{n.stopPropagation(),t.onClick(e)}),n.addEventListener(`keydown`,n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),n.stopPropagation(),t.onClick(e))})),n.appendChild(tb(e));let r=(e.countSegments??[]).map(e=>(e??``).trim()).filter(Boolean);return r.length&&n.appendChild(nb(r)),n}function tb(e){let t=document.createElement(`div`);t.className=Yy();let n=document.createElement(`span`);if(n.className=Xy(),n.textContent=e.teamName,t.appendChild(n),e.nickname){let n=document.createElement(`span`);n.className=Zy(),n.textContent=`"${e.nickname}"`,t.appendChild(n)}return t}function nb(e){let t=document.createElement(`div`);return t.className=Qy(),t.textContent=e.join($y),t}var rb=[`COMPETITIVE`,`ROUTINE`,`DECISIVE`,`WALKOVER`],ib=new Set([`WALKOVER`,`DOUBLE_WALKOVER`,`DEFAULTED`,`DOUBLE_DEFAULT`]);function ab(){return{COMPETITIVE:0,ROUTINE:0,DECISIVE:0,WALKOVER:0}}function ob(e){let t=ab();if(!Array.isArray(e))return t;for(let n of e){let e=typeof n?.getData==`function`?n.getData():n;if(!e)continue;if(e.matchUpStatus&&ib.has(e.matchUpStatus)){t.WALKOVER+=1;continue}let r=e.competitiveProfile?.competitiveness;r&&r!==`WALKOVER`&&rb.includes(r)&&(t[r]+=1)}return t}function sb(e){return rb.reduce((t,n)=>t+e[n],0)}var cb={COMPETITIVE:`Competitive`,ROUTINE:`Routine`,DECISIVE:`Decisive`,WALKOVER:`Walkover / Defaulted`};function lb(e={}){let{onSegmentClick:t}=e,n=document.createElement(`div`);n.className=`chc-cb`;let r={};for(let e of rb){let i=document.createElement(`div`);i.className=`chc-cb__seg`,i.dataset.bucket=e,t&&(i.classList.add(`is-clickable`),i.setAttribute(`role`,`button`),i.addEventListener(`click`,()=>t(e))),r[e]=i,n.appendChild(i)}return{element:n,update:e=>{let t=sb(e);if(n.style.display=t>0?`flex`:`none`,t)for(let t of rb){let n=r[t],i=e[t];i===0?(n.style.flex=`0 0 0`,n.style.padding=`0`,n.textContent=``,n.removeAttribute(`title`)):(n.style.flex=`${i} 1 0`,n.style.padding=`0 4px`,n.textContent=String(i),n.title=`${cb[t]}: ${i}`)}},setActive:e=>{n.classList.toggle(`has-active`,!!e);for(let t of rb)r[t].classList.toggle(`is-active`,t===e)}}}var ub={COMPETITIVE:`Competitive`,ROUTINE:`Routine`,DECISIVE:`Decisive`,WALKOVER:`Walkover / Defaulted`},db=`http://www.w3.org/2000/svg`,fb=96,pb=fb/2,mb=47,hb=31;function gb(e,t){return{x:pb+t*Math.cos(e),y:pb+t*Math.sin(e)}}function _b(e,t){let n=gb(e,mb),r=gb(t,mb),i=gb(t,hb),a=gb(e,hb),o=+(t-e>Math.PI);return[`M ${n.x} ${n.y}`,`A ${mb} ${mb} 0 ${o} 1 ${r.x} ${r.y}`,`L ${i.x} ${i.y}`,`A ${hb} ${hb} 0 ${o} 0 ${a.x} ${a.y}`,`Z`].join(` `)}function vb(){let e=gb(-Math.PI/2,mb),t=gb(Math.PI/2,mb),n=gb(-Math.PI/2,hb),r=gb(Math.PI/2,hb);return[`M ${e.x} ${e.y}`,`A ${mb} ${mb} 0 1 1 ${t.x} ${t.y}`,`A ${mb} ${mb} 0 1 1 ${e.x} ${e.y}`,`L ${n.x} ${n.y}`,`A ${hb} ${hb} 0 1 0 ${r.x} ${r.y}`,`A ${hb} ${hb} 0 1 0 ${n.x} ${n.y}`,`Z`].join(` `)}function yb(){let e=document.createElement(`div`);e.className=`chc-cd`;let t=document.createElementNS(db,`svg`);t.setAttribute(`viewBox`,`0 0 ${fb} ${fb}`),t.setAttribute(`class`,`chc-cd__svg`),t.setAttribute(`role`,`img`);let n={};for(let e of rb){let r=document.createElementNS(db,`path`);r.setAttribute(`class`,`chc-cd__arc`),r.setAttribute(`data-bucket`,e),t.appendChild(r);let i=document.createElementNS(db,`title`);r.appendChild(i),n[e]=r}let r=document.createElement(`div`);return r.className=`chc-cd__total`,e.appendChild(t),e.appendChild(r),{element:e,update:i=>{let a=sb(i);if(e.style.display=a>0?`inline-flex`:`none`,!a)return;let o=rb.filter(e=>i[e]>0),s=-Math.PI/2;for(let e of rb){let t=i[e],r=n[e],c=r.querySelector(`title`);if(t===0){r.removeAttribute(`d`),c&&(c.textContent=``);continue}if(o.length===1)r.setAttribute(`d`,vb());else{let e=t/a,n=s+e*Math.PI*2;r.setAttribute(`d`,_b(s,n)),s=n}c&&(c.textContent=`${ub[e]}: ${t}`)}r.textContent=String(a),t.setAttribute(`aria-label`,`Competitiveness across ${a} matches`)}}}function bb(e){let{segments:t,onSegmentClick:n}=e,r=document.createElement(`div`);r.className=`chc-sb`;let i={},a={};for(let{key:e,label:o,color:s}of t){i[e]=o;let t=document.createElement(`div`);t.className=`chc-sb__seg`,t.dataset.key=e,t.style.setProperty(`--seg-bg`,s),n&&(t.classList.add(`is-clickable`),t.setAttribute(`role`,`button`),t.addEventListener(`click`,()=>n(e))),a[e]=t,r.appendChild(t)}return{element:r,update:e=>{let n=t.reduce((t,n)=>t+(e[n.key]||0),0);if(r.style.display=n>0?`flex`:`none`,n)for(let{key:n}of t){let t=a[n],r=e[n]||0;r===0?(t.style.flex=`0 0 0`,t.style.padding=`0`,t.textContent=``,t.removeAttribute(`title`)):(t.style.flex=`${r} 1 0`,t.style.padding=`0 4px`,t.textContent=String(r),t.title=`${i[n]}: ${r}`)}},setActive:e=>{r.classList.toggle(`has-active`,!!e);for(let{key:n}of t)a[n].classList.toggle(`is-active`,n===e)}}}var xb={cornerBadges:[`status`,`publishedBadge`,`embargoBadge`],body:[`title`,`drawTypeLabel`,`matchUpProgress`],footer:[`drawSize`,`entries`,`matchUpFormat`,`flightNumber`,`ratings`],showVisualization:!1};function Sb(e){return e?{cornerBadges:e.cornerBadges??xb.cornerBadges,body:e.body??xb.body,footer:e.footer??xb.footer,showVisualization:e.showVisualization??xb.showVisualization}:xb}var Cb=()=>`chc-dc-card`,wb=()=>`chc-dc-card--clickable`,Tb=()=>`chc-dc-corner-badges`,Eb=()=>`chc-dc-status-pill`,Db=()=>`chc-dc-secondary-badge`,Ob=()=>`chc-dc-body`,kb=()=>`chc-dc-viz`,Ab=()=>`chc-dc-title-row`,jb=()=>`chc-dc-title`,Mb=()=>`chc-dc-draw-type`,Nb=()=>`chc-dc-meta`,Pb=()=>`chc-dc-footer`,Fb=()=>`chc-dc-chip`,Ib=()=>`chc-dc-progress`,Lb=()=>`chc-dc-progress-bar`,Rb=()=>`chc-dc-progress-fill`,zb=()=>`chc-dc-card chc-dc-skeleton`,Bb=()=>`chc-dc-skeleton-line`;function Vb(e,t,n){let r=Sb(t),i=document.createElement(`div`);if(i.className=Cb(),i.dataset.drawId=e.drawId,e.eventId&&(i.dataset.eventId=e.eventId),n?.onClick&&(i.classList.add(wb()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showVisualization&&e.visualization){let t=document.createElement(`div`);t.className=kb(),t.appendChild(e.visualization),i.appendChild(t)}return(r.body.length||r.cornerBadges.length)&&i.appendChild(ix(e,r)),r.footer.length&&i.appendChild(ax(e,r)),i}function Hb(e){if(!e.status)return null;let t=document.createElement(`div`);return t.className=Eb(),t.dataset.kind=e.status.kind,t.textContent=e.status.label,t}function Ub(e){if(!e.published)return null;let t=document.createElement(`div`);return t.className=Db(),t.dataset.kind=`published`,t.textContent=`Published`,t}function Wb(e){if(!e.embargoActive)return null;let t=document.createElement(`div`);return t.className=Db(),t.dataset.kind=`embargo`,t.textContent=`Embargo`,t}function Gb(e,t){return e===`status`?Hb(t):e===`publishedBadge`?Ub(t):e===`embargoBadge`?Wb(t):null}function Kb(e,t){let n=[];for(let r of t){let t=Gb(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=Tb();for(let e of n)r.appendChild(e);return r}function qb(e){if(!e.drawName)return null;let t=document.createElement(`div`);return t.className=jb(),t.textContent=e.drawName,t.title=e.drawName,t}function Jb(e){if(!e.drawTypeLabel)return null;let t=document.createElement(`div`);return t.className=Mb(),t.textContent=e.drawTypeLabel,t}function Yb(e){let t=document.createElement(`span`);return t.className=Fb(),t.textContent=e,t}function Xb(e){return typeof e.drawSize==`number`?Yb(`Size ${e.drawSize}`):null}function Zb(e){return typeof e.entryCount==`number`?Yb(`${e.entryCount} ${e.entryCount===1?`entry`:`entries`}`):null}function Qb(e){return e.matchUpFormat?Yb(e.matchUpFormat):null}function $b(e){return typeof e.flightNumber==`number`?Yb(`Flight ${e.flightNumber}`):null}function ex(e){let t=[];if(typeof e.utrAvg==`number`&&t.push(`UTR ${e.utrAvg.toFixed(2)}`),typeof e.wtnAvg==`number`&&t.push(`WTN ${e.wtnAvg.toFixed(2)}`),!t.length)return null;let n=document.createElement(`div`);return n.className=Nb(),n.textContent=t.join(` · `),n}function tx(e){if(!e.matchUpCounts||e.matchUpCounts.total===0)return null;let{total:t,completed:n}=e.matchUpCounts,r=Math.round(n/t*100),i=document.createElement(`div`);i.className=Ib();let a=document.createElement(`div`);a.className=Nb(),a.textContent=`${n}/${t} matches · ${r}%`,i.appendChild(a);let o=document.createElement(`div`);o.className=Lb();let s=document.createElement(`div`);return s.className=Rb(),s.style.right=`${100-r}%`,o.appendChild(s),i.appendChild(o),i}function nx(e,t){return e===`title`?qb(t):e===`drawTypeLabel`?Jb(t):e===`drawSize`?Xb(t):e===`entries`?Zb(t):e===`matchUpFormat`?Qb(t):e===`flightNumber`?$b(t):e===`ratings`?ex(t):e===`matchUpProgress`?tx(t):null}function rx(e,t){let n=document.createElement(`div`);n.className=Ab();let r=qb(e);r&&n.appendChild(r);let i=Kb(e,t);return i&&n.appendChild(i),n}function ix(e,t){let n=document.createElement(`div`);n.className=Ob();let r=t.body.includes(`title`),i=t.cornerBadges.length>0;if(i&&!r){let r=Kb(e,t.cornerBadges);r&&n.appendChild(r)}for(let r of t.body){if(r===`title`&&i){n.appendChild(rx(e,t.cornerBadges));continue}let a=nx(r,e);a&&n.appendChild(a)}return n}function ax(e,t){let n=document.createElement(`div`);n.className=Pb();for(let r of t.footer){let t=nx(r,e);t&&n.appendChild(t)}return n}function ox(){let e=document.createElement(`div`);e.className=zb();let t=document.createElement(`div`);t.className=Ob();for(let e of[`70%`,`40%`,`85%`]){let n=document.createElement(`div`);n.className=Bb(),n.style.width=e,t.appendChild(n)}return e.appendChild(t),e}var sx={SINGLE_ELIMINATION:`Single Elimination`,DOUBLE_ELIMINATION:`Double Elimination`,ELIMINATION:`Elimination`,ROUND_ROBIN:`Round Robin`,ROUND_ROBIN_WITH_PLAYOFF:`Round Robin + Playoff`,COMPASS:`Compass`,FEED_IN_CHAMPIONSHIP:`Feed-In Championship`,FIRST_MATCH_LOSER_CONSOLATION:`First Match Loser Consolation`,FIRST_ROUND_LOSER_CONSOLATION:`First Round Loser Consolation`,PLAY_OFF:`Play-Off`,CURTIS_CONSOLATION:`Curtis Consolation`,AD_HOC:`Ad-Hoc`,OLYMPIC:`Olympic`,LUCKY_DRAW:`Lucky Draw`,STAGGERED_ENTRY:`Staggered Entry`};function cx(e){if(e)return sx[e]?sx[e]:e.toLowerCase().split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function lx(e){let{matchUps:n=[]}=t.tournamentEngine.getAllDrawMatchUps({drawDefinition:e}),r=0,i=0,a=0,o=0;for(let e of n)e?.matchUpStatus!==`BYE`&&e?.matchUpStatus!==`DOUBLE_BYE`&&(r+=1,e?.winningSide?i+=1:e?.schedule?.scheduledTime&&(a+=1),e?.matchUpStatus===`IN_PROGRESS`&&(o+=1));return{total:r,completed:i,scheduled:a,inProgress:o}}function ux(e){let t=e?.drawSize;if(typeof t==`number`)return t;let n=(e?.structures?.find(e=>e?.stage===`MAIN`))?.positionAssignments?.length;return typeof n==`number`?n:void 0}function dx(e){if(e.cancelled)return{kind:`cancelled`,label:`Cancelled`};if(!e.generated)return{kind:`ungenerated`,label:`Not generated`};let t=e.matchUpCounts;return!t||t.total===0?{kind:`ready`,label:`Ready`}:t.completed===t.total?{kind:`completed`,label:`Completed`}:t.inProgress>0||t.completed>0?{kind:`in-progress`,label:`In progress`}:{kind:`ready`,label:`Ready`}}function fx(e,t){let n=Array.isArray(e?.structures)&&e.structures.length>0,r=t?.matchUpStats??(t?.lightMode||!n?void 0:lx(e)),i=e?.drawStatus===`CANCELLED`,a=t?.statusOverride===void 0?dx({generated:n,cancelled:i,matchUpCounts:r}):t.statusOverride;return{drawId:e?.drawId??``,drawName:e?.drawName??``,drawType:e?.drawType,drawTypeLabel:cx(e?.drawType),drawSize:ux(e),entryCount:t?.entryCount,matchUpFormat:e?.matchUpFormat,flightNumber:e?.flightNumber,matchUpCounts:r,generated:n,published:t?.published,embargoActive:t?.embargoActive,utrAvg:t?.utrAvg,wtnAvg:t?.wtnAvg,status:a,eventId:t?.eventId}}var px={showImage:!0,cornerBadges:[`status`,`eventTypeBadge`,`genderBadge`],body:[`title`,`categoryLabel`,`drawSummary`],footer:[`playerCount`,`matchUpProgress`]},mx=15;function hx(e){return e?{showImage:e.showImage??px.showImage,cornerBadges:e.cornerBadges??px.cornerBadges,body:e.body??px.body,footer:e.footer??px.footer}:px}var gx=()=>`chc-ec-card`,_x=()=>`chc-ec-card--clickable`,vx=()=>`chc-ec-image`,yx=()=>`chc-ec-image-img`,bx=()=>`chc-ec-image-svg`,xx=()=>`chc-ec-image-placeholder`,Sx=()=>`chc-ec-corner-badges`,Cx=()=>`chc-ec-status-pill`,wx=()=>`chc-ec-eventtype-badge`,Tx=()=>`chc-ec-gender-badge`,Ex=()=>`chc-ec-body`,Dx=()=>`chc-ec-title`,Ox=()=>`chc-ec-category`,kx=()=>`chc-ec-draw-summary`,Ax=()=>`chc-ec-date-range`,jx=()=>`chc-ec-footer`,Mx=()=>`chc-ec-player-count`,Nx=()=>`chc-ec-progress`,Px=()=>`chc-ec-progress-meta`,Fx=()=>`chc-ec-progress-bar`,Ix=()=>`chc-ec-progress-fill`,Lx=()=>`chc-ec-updated-at`,Rx=()=>`chc-ec-card chc-ec-skeleton`,zx=()=>`chc-ec-skeleton-line`,Bx=()=>`chc-ec-skeleton-block`;function Vx(e,t,n){let r=hx(t),i=document.createElement(`div`);return i.className=gx(),i.dataset.eventId=e.eventId,n?.onClick&&(i.classList.add(_x()),i.tabIndex=0,i.addEventListener(`click`,t=>{t.stopPropagation(),n.onClick(e)}),i.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),n.onClick(e))})),r.showImage!==!1&&i.appendChild(Ux(e,r)),r.body.length&&i.appendChild(rS(e,r)),r.footer.length&&i.appendChild(iS(e,r)),i}function Hx(e,t){let n=bh(t.courtSvgSport,bx());if(n){e.appendChild(n);return}let r=document.createElement(`div`);r.className=xx(),e.appendChild(r)}function Ux(e,t){let n=document.createElement(`div`);if(n.className=vx(),e.eventImageURL){let t=document.createElement(`img`);t.className=yx(),t.src=e.eventImageURL,t.alt=e.eventName||``,t.loading=`lazy`,t.addEventListener(`error`,()=>{t.remove(),Hx(n,e)}),n.appendChild(t)}else Hx(n,e);if(t.cornerBadges.length){let r=Jx(e,t.cornerBadges);r&&n.appendChild(r)}return n}function Wx(e){if(!e.status)return null;let t=document.createElement(`div`);return t.className=Cx(),t.dataset.kind=e.status.kind,t.textContent=e.status.label,t}function Gx(e){if(!e.eventType)return null;let t=document.createElement(`div`);return t.className=wx(),t.dataset.kind=e.eventType,t.textContent=e.eventType,t}function Kx(e){if(!e.gender)return null;let t=document.createElement(`div`);return t.className=Tx(),t.dataset.kind=e.gender,t.textContent=e.gender===`MALE`?`M`:e.gender===`FEMALE`?`W`:`X`,t}function qx(e,t){return e===`status`?Wx(t):e===`eventTypeBadge`?Gx(t):e===`genderBadge`?Kx(t):null}function Jx(e,t){let n=[];for(let r of t){let t=qx(r,e);t&&n.push(t)}if(!n.length)return null;let r=document.createElement(`div`);r.className=Sx();for(let e of n)r.appendChild(e);return r}function Yx(e){if(!e.eventName)return null;let t=document.createElement(`div`);return t.className=Dx(),t.textContent=e.eventName,t.title=e.eventName,t}function Xx(e){if(!e.categoryLabel)return null;let t=document.createElement(`div`);return t.className=Ox(),t.textContent=e.categoryLabel,t}function Zx(e){if(!e.drawSummary)return null;let t=document.createElement(`div`);return t.className=kx(),t.textContent=e.drawSummary,t}function Qx(e){if(!e.dateRangeFormatted)return null;let t=document.createElement(`div`);return t.className=Ax(),t.textContent=e.dateRangeFormatted,t}function $x(e){if(!e.updatedAt)return null;let t=document.createElement(`div`);t.className=Lx();let n=new Date(e.updatedAt);return t.textContent=Number.isNaN(n.getTime())?e.updatedAt:n.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`}),t}function eS(e){if(typeof e.entryCount!=`number`)return null;let t=document.createElement(`div`);return t.className=Mx(),t.textContent=`${e.entryCount} ${e.entryCount===1?`player`:`players`}`,t}function tS(e){if(!e.matchUpCounts||e.matchUpCounts.total===0)return null;let{total:t,completed:n}=e.matchUpCounts,r=Math.round(n/t*100),i=document.createElement(`div`);i.className=Nx();let a=document.createElement(`div`);a.className=Px(),a.textContent=`${n}/${t} matches · ${r}%`,i.appendChild(a);let o=document.createElement(`div`);o.className=Fx();let s=document.createElement(`div`);return s.className=Ix(),s.style.right=`${100-r}%`,o.appendChild(s),i.appendChild(o),i}function nS(e,t){return e===`title`?Yx(t):e===`categoryLabel`?Xx(t):e===`drawSummary`?Zx(t):e===`dateRange`?Qx(t):e===`updatedAt`?$x(t):e===`playerCount`?eS(t):e===`matchUpProgress`?tS(t):null}function rS(e,t){let n=document.createElement(`div`);n.className=Ex();for(let r of t.body){let t=nS(r,e);t&&n.appendChild(t)}return n}function iS(e,t){let n=document.createElement(`div`);n.className=jx();for(let r of t.footer){let t=nS(r,e);t&&n.appendChild(t)}return n}function aS(e){let t=hx(e);return Lh({showImage:t.showImage!==!1,bodyLines:t.body.length,showFooter:t.footer.length>0,cardClass:Rx(),imageClass:vx(),bodyClass:Ex(),footerClass:jx(),blockClass:Bx(),lineClass:zx()})}function oS(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function sS(e,t,n){return!t||!n?!1:t.getTime()<=e.getTime()&&e.getTime()<=n.getTime()}function cS(e,t=new Date){if(e.allDrawsCancelled)return{kind:`cancelled`,label:`Cancelled`};let n=e.matchUpCounts;if(n&&n.total>0&&n.completed===n.total)return{kind:`completed`,label:`Completed`};let r=oS(e.startDate),i=oS(e.endDate);if(n&&(n.inProgress>0||sS(t,r,i)&&n.total>0))return{kind:`live`,label:`Live`};let a=e.drawCount??0;return a>0&&(e.hasDraftState||e.hasSeedsOnlyDraw)?{kind:`drawing`,label:`Drawing`}:a===0&&(e.entryCount??0)>0?{kind:`entries-open`,label:`Entries Open`}:r&&t.getTime()<r.getTime()?{kind:`upcoming`,label:`Upcoming`}:null}var lS=`eventImage`,uS=`DRAFT_STATE`;function dS(e){if(!e)return;let t=String(e).toUpperCase();if(t===`SINGLES`||t===`DOUBLES`||t===`TEAM`||t===`HYBRID`)return t}function fS(e){if(!e)return;let t=String(e).toUpperCase();if(t===`M`||t===`MALE`)return`MALE`;if(t===`F`||t===`FEMALE`)return`FEMALE`;if(t===`MIXED`||t===`X`)return`MIXED`}function pS(e){if(!e)return;let t=mS(e.categoryName);if(t)return t;if(typeof e.ageMin==`number`&&typeof e.ageMax==`number`)return e.ageMin===e.ageMax?`Age ${e.ageMin}`:`Age ${e.ageMin}–${e.ageMax}`;let n=mS(e.ageCategoryCode);if(n)return n;if(e.ratingMin&&e.ratingMax)return`Rating ${e.ratingMin}–${e.ratingMax}`}function mS(e){if(typeof e!=`string`)return;let t=e.trim();if(t&&!/^[-—–_]+$/.test(t))return t}function hS(e){if(!e.length)return;let t=e.find(Boolean);if(!t)return;let n=[];return typeof t.drawSize==`number`&&n.push(String(t.drawSize)),t.drawType&&n.push(String(t.drawType)),e.length>1&&n.push(`+${e.length-1}`),n.length?n.join(` `):void 0}function gS(e){let{matchUps:n=[]}=t.tournamentEngine.allEventMatchUps({event:e,inContext:!1})??{},r=0,i=0,a=0,o=0;for(let e of n)e?.matchUpStatus!==`BYE`&&e?.matchUpStatus!==`DOUBLE_BYE`&&(r+=1,e?.winningSide?i+=1:e?.schedule?.scheduledTime&&(a+=1),e?.matchUpStatus===`IN_PROGRESS`&&(o+=1));return{total:r,completed:i,scheduled:a,inProgress:o}}function _S(e){if(e?.draftState!=null)return!0;let t=e?.extensions;return Array.isArray(t)?t.some(e=>e?.name===uS):!1}function vS(e){return e.some(e=>e?.automated?.seedsOnly===!0||_S(e))}function yS(e){return e.length!==0&&e.every(e=>e?.drawStatus===`CANCELLED`)}var bS=new Set([`DIRECT_ACCEPTANCE`,`DA`,`DIRECT_CONFIRMED`,`DC`,`ACCEPTED`,`A`,`ENTERED`,`PE`,`QUALIFIER`,`Q`,`WILDCARD`,`WC`]);function xS(e){if(!e.length)return 0;let t=0;for(let n of e)bS.has(String(n?.entryStatus))&&(t+=1);return t}function SS(e,t){let n=Array.isArray(e?.drawDefinitions)?e.drawDefinitions:[],r=Array.isArray(e?.entries)?e.entries:[],i=Array.isArray(e?.onlineResources)?e.onlineResources:void 0,a=t?.matchUpStats??(t?.lightMode?void 0:gS(e)),o=t?.statusOverride===void 0?cS({allDrawsCancelled:yS(n),drawCount:n.length,entryCount:xS(r),startDate:e?.startDate,endDate:e?.endDate,matchUpCounts:a,hasDraftState:n.some(_S),hasSeedsOnlyDraw:vS(n)},t?.now):t.statusOverride;return{eventId:e?.eventId??``,eventName:e?.eventName??``,eventAbbreviation:e?.eventAbbreviation,categoryLabel:pS(e?.category),eventType:dS(e?.eventType),gender:fS(e?.gender),drawCount:n.length||void 0,drawSummary:hS(n),entryCount:xS(r)||void 0,matchUpCounts:a,startDate:e?.startDate,endDate:e?.endDate,dateRangeFormatted:Mh(e?.startDate,e?.endDate),status:o,eventImageURL:e?.eventImageURL??Fh(i,lS),courtSvgSport:e?.courtSvgSport??Ih(i)??t?.sport,updatedAt:e?.updatedAt}}var CS=()=>`chc-hil-container`,wS=()=>`chc-hil-form`,TS=()=>`chc-hil-header`,ES=()=>`chc-hil-title`,DS=()=>`chc-hil-tabs`,OS=()=>`chc-hil-tab`,kS=()=>`chc-hil-tab--active`,AS=()=>`chc-hil-field`,jS=()=>`chc-hil-label`,MS=()=>`chc-hil-input`,NS=()=>`chc-hil-row`,PS=()=>`chc-hil-submit`,FS=()=>`chc-hil-message`,IS=()=>`chc-hil-message--error`,LS=()=>`chc-hil-message--success`,RS=()=>`chc-hil-switch-mode`;function zS(e){return e.replace(/\/+$/,``)}async function BS(e,t,n,r=fetch){let i=zS(e)+t,a;try{a=await r(i,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})}catch(e){throw{kind:`network`,cause:e}}let o=null;try{o=await a.json()}catch(e){if(a.ok)throw{kind:`parse`,cause:e}}if(!a.ok)throw{kind:`http`,status:a.status,body:o};return o}function VS(e,t,n){return BS(e,`/auth/hiveid/signup`,t,n)}function HS(e,t,n){return BS(e,`/auth/hiveid/verify-existing`,t,n)}function US(e,t,n){return BS(e,`/auth/hiveid/magic-link`,t,n)}function WS(e,t,n){return BS(e,`/auth/hiveid/magic-link/consume`,t,n)}function GS(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.kind!==`http`||t.status!==409?!1:t.body?.code===`EXISTING_USER`}var KS=[{value:`M`,label:`Male`},{value:`F`,label:`Female`}],qS=`signup`,JS=`login`,YS=`magic-link`,XS=[qS,JS,YS],ZS=`hiveid:authenticated`,QS={[qS]:`Sign up`,[JS]:`Log in`,[YS]:`Email link`},$S={[qS]:`Create your CourtHive identity`,[JS]:`Log in to CourtHive`,[YS]:`Email me a sign-in link`};function eC(e){if(!e?.cfsBaseUrl)throw Error(`buildHiveIDLogin: cfsBaseUrl is required`);let t=e.mode??`signup`,n=!1,r=document.createElement(`div`);r.className=CS(),r.dataset.hiveidLogin=`true`;let i=document.createElement(`div`);i.className=TS();let a=document.createElement(`h2`);a.className=ES(),i.appendChild(a);let o=document.createElement(`div`);o.className=DS(),i.appendChild(o);let s={};XS.forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=OS(),t.textContent=QS[e],t.dataset.mode=e,t.onclick=()=>w(e),o.appendChild(t),s[e]=t}),r.appendChild(i);let c=document.createElement(`form`);c.className=wS(),c.noValidate=!0,r.appendChild(c);let l=document.createElement(`div`);l.className=FS(),l.hidden=!0,r.appendChild(l);function u(e,t=`info`){l.textContent=e,l.className=FS(),t===`error`&&l.classList.add(IS()),t===`success`&&l.classList.add(LS()),l.hidden=!e}function d(){u(``)}function f(e,t,n=`text`,r=``){let i=document.createElement(`div`);i.className=AS();let a=document.createElement(`label`);a.className=jS(),a.textContent=t,a.htmlFor=`chc-hil-${e}`;let o=document.createElement(`input`);return o.id=`chc-hil-${e}`,o.name=e,o.type=n,o.value=r,o.className=MS(),o.required=!0,i.appendChild(a),i.appendChild(o),c.appendChild(i),o}function p(){let e=document.createElement(`div`);return e.className=NS(),c.appendChild(e),e}function m(e){let t=document.createElement(`button`);return t.type=`submit`,t.className=PS(),t.textContent=e,c.appendChild(t),t}function h(e,t,n){let r=document.createElement(`div`);r.className=RS();let i=document.createElement(`button`);i.type=`button`,i.textContent=n,i.onclick=()=>w(t),r.append(e+` `,i),c.appendChild(r)}function g(e){if(e.note){let t=document.createElement(`p`);t.className=jS(),t.textContent=e.note,c.appendChild(t)}let t=null;if(e.providers.length>1){let n=document.createElement(`div`);n.className=AS();let r=document.createElement(`label`);r.className=jS(),r.textContent=`Provider`,r.htmlFor=`chc-hil-fedProvider`;let i=document.createElement(`select`);i.id=`chc-hil-fedProvider`,i.className=MS(),e.providers.forEach(e=>{let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,i.appendChild(t)}),n.append(r,i),c.appendChild(n),t=i}let n=document.createElement(`div`);n.className=AS();let r=document.createElement(`label`);r.className=jS(),r.textContent=e.idLabel??`Player ID`,r.htmlFor=`chc-hil-federationId`;let i=document.createElement(`input`);i.id=`chc-hil-federationId`,i.type=`text`,i.className=MS(),n.append(r,i),c.appendChild(n);let a=e.providers[0]?.value??``;return()=>{let e=i.value.trim();if(!e)return null;let n=t?t.value:a;return n?{provider:n,externalId:e}:null}}function _(e){if(e.note){let t=document.createElement(`p`);t.className=jS(),t.textContent=e.note,c.appendChild(t)}let t=e.required!==!1,n=document.createElement(`div`);n.className=AS();let r=document.createElement(`label`);r.className=jS(),r.textContent=e.dobLabel??`Date of birth`,r.htmlFor=`chc-hil-birthDate`;let i=document.createElement(`input`);i.id=`chc-hil-birthDate`,i.type=`date`,i.required=t,i.className=MS(),n.append(r,i),c.appendChild(n);let a=document.createElement(`div`);a.className=AS();let o=document.createElement(`label`);o.className=jS(),o.textContent=e.sexLabel??`Sex`,o.htmlFor=`chc-hil-sex`;let s=document.createElement(`select`);s.id=`chc-hil-sex`,s.required=t,s.className=MS();let l=document.createElement(`option`);return l.value=``,l.textContent=`Select…`,s.appendChild(l),(e.sexOptions??KS).forEach(e=>{let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,s.appendChild(t)}),a.append(o,s),c.appendChild(a),()=>rC({birthDate:i.value,sex:s.value})}function v(e){r.dispatchEvent(new CustomEvent(ZS,{detail:e,bubbles:!0}))}function y(e,t){return async r=>{if(r.preventDefault(),!n){n=!0,e.disabled=!0,d();try{await t()}finally{n=!1,e.disabled=!1}}}}async function b(t,n,r,i={}){let a=t.value.trim(),o=n.value.trim(),s=r.value.trim();if(!a||!o||!s){u(`Email, first name, and last name are required.`,`error`);return}let{federationIds:c,birthDate:l,sex:d,provider:f,requirePii:p}=i;if(p&&(!l||!d)){u(`Date of birth and sex are required.`,`error`);return}try{let t=await VS(e.cfsBaseUrl,{email:a,firstName:o,lastName:s,federationIds:c,birthDate:l,sex:d,provider:f},e.fetchImpl);if(t.status===`candidate`){u(`We found possible matches — please log in with your existing account.`,`info`),w(`login`);return}v({token:t.token,refreshToken:t.refreshToken,personId:t.personId,cached:t.cached}),u(`Welcome to CourtHive.`,`success`)}catch(e){if(GS(e)){u(`That email already has a CourtHive account — please verify your password.`,`info`),w(`login`);return}u(aC(e)??`Sign-up failed. Please try again.`,`error`)}}async function x(t,n){let r=t.value.trim(),i=n.value;if(!r||!i){u(`Email and password are required.`,`error`);return}try{let t=await HS(e.cfsBaseUrl,{email:r,password:i},e.fetchImpl);v({token:t.token,refreshToken:t.refreshToken,personId:t.personId,cached:t.cached??iC()}),u(`Signed in.`,`success`)}catch(e){u(aC(e)??`Sign-in failed. Please check your password.`,`error`)}}async function S(t){let n=t.value.trim();if(!n){u(`Email is required.`,`error`);return}try{await US(e.cfsBaseUrl,{email:n},e.fetchImpl),u(`If ${n} is registered, a sign-in link is on its way.`,`success`)}catch(e){u(aC(e)??`Could not send link. Please try again.`,`error`)}}function C(){if(c.replaceChildren(),a.textContent=$S[t],XS.forEach(e=>{s[e].classList.toggle(kS(),e===t)}),t===`signup`){let t=p(),n=document.createElement(`input`);n.id=`chc-hil-firstName`,n.type=`text`,n.placeholder=`First name`,n.required=!0,n.className=MS();let r=document.createElement(`input`);r.id=`chc-hil-lastName`,r.type=`text`,r.placeholder=`Last name`,r.required=!0,r.className=MS();let i=document.createElement(`div`);i.className=AS();let a=document.createElement(`label`);a.textContent=`First name`,a.className=jS(),a.htmlFor=n.id,i.append(a,n);let o=document.createElement(`div`);o.className=AS();let s=document.createElement(`label`);s.textContent=`Last name`,s.className=jS(),s.htmlFor=r.id,o.append(s,r),t.append(i,o);let l=f(`email`,`Email`,`email`,e.defaultEmail??``),u=e.federationIdCapture?g(e.federationIdCapture):()=>null,d=e.dobSexCapture?_(e.dobSexCapture):()=>({}),v=!!e.dobSexCapture&&e.dobSexCapture.required!==!1,x=m(`Create account`);c.onsubmit=y(x,()=>b(l,n,r,{federationIds:nC(u(),e.federationIds),...d(),provider:e.provider,requirePii:v})),h(`Already have an account?`,`login`,`Log in`)}else if(t===`login`){let t=f(`email`,`Email`,`email`,e.defaultEmail??``),n=f(`password`,`Password`,`password`),r=m(`Log in`);c.onsubmit=y(r,()=>x(t,n)),h(`Forgot your password?`,`magic-link`,`Email me a link`)}else{let t=f(`email`,`Email`,`email`,e.defaultEmail??``),n=m(`Send link`);c.onsubmit=y(n,()=>S(t)),h(`Have a password?`,`login`,`Log in instead`)}}function w(e){e!==t&&(t=e,d(),C())}function T(){return t}function E(e){let t=t=>e(t.detail);return r.addEventListener(ZS,t),()=>r.removeEventListener(ZS,t)}return C(),{root:r,setMode:w,getMode:T,onAuthenticated:E}}async function tC(e,t,n){let r=await WS(e,{code:t},n);return{token:r.token,refreshToken:r.refreshToken,personId:r.personId,cached:r.cached??iC()}}function nC(e,t){let n=[],r=new Set,i=e=>{if(!e?.provider||!e?.externalId)return;let t=`${e.provider}::${e.externalId}`;r.has(t)||(r.add(t),n.push({provider:e.provider,externalId:e.externalId}))};return(t??[]).forEach(i),i(e),n.length?n:void 0}function rC(e){let t={},n=e.birthDate?.trim(),r=e.sex?.trim();return n&&(t.birthDate=n),r&&(t.sex=r),t}function iC(){return{standardFamilyName:null,standardGivenName:null,birthDate:null,sex:null,nationalityCode:null}}function aC(e){if(!e||typeof e!=`object`)return null;if(e.kind===`http`){let t=e.body;if(t?.message&&typeof t.message==`string`)return t.message;if(typeof t?.status==`string`&&t.status===`incomplete`)return`We need a bit more information to identify you.`}return e.kind===`network`?`Could not reach CourtHive. Check your connection.`:null}var oC={name:`courthive-components`,packageManager:`pnpm@11.20.0`,version:`3.13.0`,engines:{node:`>=22`},description:`Components for competitions projects`,files:[`dist`],main:`./dist/courthive-components.umd.js`,module:`./dist/courthive-components.es.js`,types:`./dist/index.d.ts`,exports:{".":{types:`./dist/index.d.ts`,import:`./dist/courthive-components.es.js`,require:`./dist/courthive-components.umd.js`},"./dist/*":`./dist/*`},repository:{type:`git`,url:`git+https://github.com/CourtHive/courthive-components.git`},keywords:[`tournament`,`match`,`score`,`vanillajs`,`bracket`],author:`Charles Allen`,license:`MIT`,bugs:{url:`https://github.com/CourtHive/courthive-components/issues`},homepage:`https://courthive.github.io/courthive-component`,scripts:{commits:`git log $(git describe --tags --abbrev=0)..HEAD --oneline --no-merges --pretty=format:'%s: %h' | sed '/courthive-components/d'`,release:`npm run release:patch`,test:`vitest run`,"test:watch":`vitest`,"test:ui":`vitest --ui`,dev:`vite`,build:`tsc && vite build`,"check-types":`tsc --noEmit`,prepublishOnly:`pnpm build`,preview:`vite preview`,storybook:`storybook dev -p 6006`,"build-storybook":`storybook build`,"test-storybook":`test-storybook --url http://localhost:6006`,"deploy-storybook":`gh-pages -d storybook-static`,"pre-commit":`lint-staged`,predeploy:`pnpm build-storybook`,lint:`eslint src --cache --max-warnings 0`,"lint:fix":`eslint src --fix --cache`,"lint:report":`eslint src & eslint --cache src -f json > eslint-report.json`,format:`prettier --write src`,"release:major":`npm run commits && npm version $(semver $npm_package_version -i major) && git push && git push --tags`,"release:minor":`npm run commits && npm version $(semver $npm_package_version -i minor) && git push && git push --tags`,"release:patch":`npm run commits && npm version $(semver $npm_package_version -i patch) && git push && git push --tags`,"release:beta":`npm run commits && npm version $(semver $npm_package_version -i prerelease --preid beta) && git push && git push --tags`,"patch:beta":`npm run commits && npm version $(semver $npm_package_version -i prerelease --preid beta) && npm publish --tag beta`},"lint-staged":{"*.{js,ts}":`eslint --cache --fix`,"*":`prettier --ignore-unknown --write`},devDependencies:{"@chromatic-com/storybook":`^5.0.0`,"@commitlint/cli":`21.2.1`,"@commitlint/config-conventional":`21.2.0`,"@eslint/js":`^10.0.1`,"@fortawesome/fontawesome-free":`^7.2.0`,"@storybook/addon-docs":`^10.2.17`,"@storybook/html-vite":`^10.2.17`,"@storybook/test-runner":`^0.24.0`,"@types/d3":`^7.4.3`,"@types/leaflet":`^1.9.12`,"@types/vanillajs-datepicker":`^1.3.5`,"@typescript-eslint/eslint-plugin":`8.66.0`,"@typescript-eslint/parser":`8.66.0`,"@vitest/browser-playwright":`^4.0.16`,"@vitest/coverage-v8":`^4.0.16`,"@vitest/ui":`^4.0.16`,eslint:`10.8.0`,"eslint-plugin-sonarjs":`4.2.0`,"eslint-plugin-storybook":`^10.2.17`,"gh-pages":`6.3.0`,globals:`^17.3.0`,"happy-dom":`^20.8.3`,husky:`9.1.7`,leaflet:`1.9.4`,"lint-staged":`17.3.0`,playwright:`^1.57.0`,prettier:`^3.8.1`,semver:`7.8.5`,storybook:`^10.2.17`,"tabulator-tables":`6.5.2`,"tods-competition-factory":`6.21.0`,typescript:`^6.0.2`,vite:`8.2.0`,"vite-plugin-dts":`^5.0.0`,vitest:`^4.0.16`},dependencies:{"@tiptap/core":`^3.22.2`,"@tiptap/extension-color":`^3.22.2`,"@tiptap/extension-highlight":`^3.22.2`,"@tiptap/extension-text-align":`^3.22.2`,"@tiptap/extension-text-style":`^3.22.2`,"@tiptap/extension-youtube":`^3.22.2`,"@tiptap/starter-kit":`^3.22.2`,awesomplete:`1.1.7`,"class-variance-authority":`0.7.1`,classnames:`2.5.1`,d3:`^7.9.0`,dayjs:`1.11.21`,"focus-trap":`^8.0.0`,"timepicker-ui":`^4.1.2`,"tippy.js":`6.3.7`,"vanillajs-datepicker":`1.3.4`},peerDependencies:{"tods-competition-factory":`^6.0.0`,leaflet:`^1.9.4`},peerDependenciesMeta:{leaflet:{optional:!0}}};function sC(){return oC.version}var cC={SET3_S6_TB7:`SET3-S:6/TB7`,SET3_S6_TB7_F_TB10:`SET3-S:6/TB7-F:TB10`,SET3_S6_TB10:`SET3-S:6/TB10`,SET3_S6_F_TB10:`SET3-S:6-F:TB10`,SET3_S6_TB7_NOAD:`SET3-S:6/TB7NOAD`,SET3_S8_TB7:`SET3-S:8/TB7`,SET3_S8_TB7_AT7:`SET3-S:8/TB7@7`,SET3_S4_TB7:`SET3-S:4/TB7`,SET3_S4_TB7_F_TB10:`SET3-S:4/TB7-F:TB10`,SET3_S4_TB5_AT3_F_TB10:`SET3-S:4/TB5@3-F:TB10`,SET5_S6_TB7:`SET5-S:6/TB7`,SET5_S6_TB7_F_TB10:`SET5-S:6/TB7-F:TB10`,SET1_S6_TB7:`SET1-S:6/TB7`,SET1_S6_TB10:`SET1-S:6/TB10`,SET1_S6_TB7_AT5:`SET1-S:6/TB7@5`,SET1_S8_TB7:`SET1-S:8/TB7`,SET1_S4_TB7:`SET1-S:4/TB7`,SET1_S5_TB9_AT4:`SET1-S:5/TB9@4`,SET1_S_TB7:`SET1-S:T7`,SET1_S_TB10:`SET1-S:TB10`,SET1_S_TB21:`SET1-S:T21`,SET1_S8:`SET1-S:8`,SET1_S10:`SET1-S:10`,FAST4:`SET5-S:4/NOAD`,SET3X_T10A_TB1:`SET3XA-S:T10-F:TB1`,SET3X_T10A_TB1_NOAD:`SET3XA-S:T10-F:TB1NOAD`,SET4X_T10A_TB1:`SET4XA-S:T10-F:TB1`};function lC(e,t,n){if(!e)return{elements:{}};let r={};for(let i of t||[]){if(!i?.label||i.hide)continue;let t=document.createElement(`button`);i.id&&(r[i.id]=t,t.id=i.id),t.style.marginRight=`.5em`,t.className=`button font-medium`,i.intent&&t.classList.add(i.intent),t.innerHTML=i.label,i.disabled&&(t.disabled=!0),t.onclick=e=>{e.stopPropagation(),!e.target.disabled&&V(i.onClick)&&i.onClick(),n&&V(n)&&n()},e.appendChild(t)}return{elements:r}}var uC=(e,t)=>n=>n?.trim().length>=e&&(!t||n?.trim().length<=t);function dC(e){return t.tools.isConvertableInteger(e)&&parseInt(e.toString())>=0}var fC=(e,t)=>n=>dC(n)&&Number(n)>=e&&Number(n)<=t,pC=e=>/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\d)(?=.*?[#?!@$%^&*-]).{8,12}$/.test(e);function mC(e){return t.tools.dateTime.dateValidation.test(e)}var hC=(e,t)=>n=>{let r=(n||``).trim().split(` `).length;return r>=e&&(!t||r<=t)},gC=/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,_C=e=>gC.exec(e),vC=_({dateValidator:()=>mC,emailValidator:()=>_C,nameValidator:()=>uC,numericRange:()=>fC,numericValidator:()=>dC,passwordValidator:()=>pC,wordValidator:()=>hC}),yC=class{constructor({tournamentRecord:e,drawId:n,structureId:r,eventId:i}){this.tournamentRecord=e,this.drawId=n,this.structureId=r,this.eventId=i||e.events?.[0]?.eventId,t.tournamentEngine.setState(e)}setRenderCallback(e){this.renderCallback=e}getDrawEntryParticipantIds(){let{event:e,drawDefinition:n}=t.tournamentEngine.getEvent({drawId:this.drawId})||{};if(!e)return[];let{flightProfile:r}=t.tournamentEngine.getFlightProfile({eventId:this.eventId})||{};return(r?.flights?.find(e=>e.drawId===this.drawId)?.drawEntries||n?.entries||[]).map(e=>e.participantId).filter(Boolean)}getAllParticipants(){t.tournamentEngine.setState(this.tournamentRecord);let e=this.getDrawEntryParticipantIds();if(!e.length)return[];let{participants:n=[]}=t.tournamentEngine.getParticipants({participantFilters:{participantIds:e}})||{};return n.map(e=>({participantId:e.participantId,participantName:e.participantName,participantType:e.participantType,person:e.person,individualParticipants:e.individualParticipants}))}getAvailableParticipants(){t.tournamentEngine.setState(this.tournamentRecord);let e=this.getAllParticipants(),{assignedParticipantIds:n=[]}=t.tournamentEngine.getAssignedParticipantIds({drawId:this.drawId})||{};return e.filter(e=>!n.includes(e.participantId))}removeAssignment({drawPosition:e}){t.tournamentEngine.setState(this.tournamentRecord);let n=this.getMatchUps().find(t=>t.sides?.some(t=>t.drawPosition===e))?.sides?.find(t=>t.drawPosition===e)?.bye===!0,r=t.tournamentEngine.removeDrawPositionAssignment({drawId:this.drawId,structureId:this.structureId,drawPosition:e});if(r.error)return{success:!1,error:r.error};let{tournamentRecord:i}=t.tournamentEngine.getState()||{};return this.tournamentRecord=i,n&&this.renderCallback&&this.renderCallback(),{success:!0}}assignParticipant({drawPosition:e,participantId:n}){t.tournamentEngine.setState(this.tournamentRecord);let r=t.tournamentEngine.assignDrawPosition({drawId:this.drawId,structureId:this.structureId,drawPosition:e,participantId:n});if(r.error)return{success:!1,error:r.error};let{tournamentRecord:i}=t.tournamentEngine.getState()||{};return this.tournamentRecord=i,this.focusDrawPosition=e+1,this.renderCallback&&this.renderCallback(),{success:!0}}getAndClearFocusDrawPosition(){let e=this.focusDrawPosition;return this.focusDrawPosition=void 0,e}assignBye({drawPosition:e}){t.tournamentEngine.setState(this.tournamentRecord);let n=t.tournamentEngine.assignDrawPositionBye({drawId:this.drawId,structureId:this.structureId,drawPosition:e});if(n.error)return{success:!1,error:n.error};let{tournamentRecord:r}=t.tournamentEngine.getState()||{};return this.tournamentRecord=r,this.focusDrawPosition=e+1,this.renderCallback&&this.renderCallback(),{success:!0}}assignQualifier({drawPosition:e}){t.tournamentEngine.setState(this.tournamentRecord);let n=t.tournamentEngine.assignDrawPosition({drawId:this.drawId,structureId:this.structureId,drawPosition:e,qualifier:!0});if(n.error)return{success:!1,error:n.error};let{tournamentRecord:r}=t.tournamentEngine.getState()||{};return this.tournamentRecord=r,this.focusDrawPosition=e+1,this.renderCallback&&this.renderCallback(),{success:!0}}getMatchUps(){t.tournamentEngine.setState(this.tournamentRecord);let{eventData:e}=t.tournamentEngine.getEventData({eventId:this.eventId})||{},n=(e?.drawsData?.find(e=>e.drawId===this.drawId))?.structures?.find(e=>e.structureId===this.structureId)?.roundMatchUps;return n?Object.values(n).flat():[]}getState(){return this.tournamentRecord}getContext(){return{drawId:this.drawId,structureId:this.structureId}}},bC=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="14" height="14" fill="currentColor"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"/></svg>`,xC=new WeakMap;function SC(e,t){let n=document.createElement(`div`);n.style.cssText=`position: relative; flex: 1; display: flex; min-width: 0;`,e.style.paddingRight=`28px`,n.appendChild(e);let r=document.createElement(`button`);r.type=`button`,r.setAttribute(`aria-label`,`Clear search`),r.style.cssText=[`position: absolute`,`right: 8px`,`top: 50%`,`transform: translateY(-50%)`,`background: transparent`,`border: 0`,`padding: 2px`,`cursor: pointer`,`display: none`,`align-items: center`,`justify-content: center`,`line-height: 0`,`opacity: 0.55`,`color: currentColor`].join(`; `),r.innerHTML=bC,r.addEventListener(`mouseenter`,()=>r.style.opacity=`0.9`),r.addEventListener(`mouseleave`,()=>r.style.opacity=`0.55`),r.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),t(),i()});let i=()=>{r.style.display=e.value?`inline-flex`:`none`};return e.addEventListener(`keyup`,n=>{n.key===`Escape`&&e.value&&(t(),i())}),e.addEventListener(`input`,i),xC.set(n,i),n.appendChild(r),n}function CC(e){xC.get(e)?.()}function wC(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function TC(e,t){return e==null||t==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function EC(e){let t,n,r;e.length===2?(t=e===wC||e===TC?e:DC,n=e,r=e):(t=wC,n=(t,n)=>wC(e(t),n),r=(t,n)=>e(t)-n);function i(e,r,i=0,a=e.length){if(i<a){if(t(r,r)!==0)return a;do{let t=i+a>>>1;n(e[t],r)<0?i=t+1:a=t}while(i<a)}return i}function a(e,r,i=0,a=e.length){if(i<a){if(t(r,r)!==0)return a;do{let t=i+a>>>1;n(e[t],r)<=0?i=t+1:a=t}while(i<a)}return i}function o(e,t,n=0,a=e.length){let o=i(e,t,n,a-1);return o>n&&r(e[o-1],t)>-r(e[o],t)?o-1:o}return{left:i,center:o,right:a}}function DC(){return 0}function OC(e){return e===null?NaN:+e}var kC=EC(wC),AC=kC.right;kC.left,EC(OC).center;function jC(e,t){let n,r;if(t===void 0)for(let t of e)t!=null&&(n===void 0?t>=t&&(n=r=t):(n>t&&(n=t),r<t&&(r=t)));else{let i=-1;for(let a of e)(a=t(a,++i,e))!=null&&(n===void 0?a>=a&&(n=r=a):(n>a&&(n=a),r<a&&(r=a)))}return[n,r]}var MC=class extends Map{constructor(e,t=IC){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:t}}),e!=null)for(let[t,n]of e)this.set(t,n)}get(e){return super.get(NC(this,e))}has(e){return super.has(NC(this,e))}set(e,t){return super.set(PC(this,e),t)}delete(e){return super.delete(FC(this,e))}};function NC({_intern:e,_key:t},n){let r=t(n);return e.has(r)?e.get(r):n}function PC({_intern:e,_key:t},n){let r=t(n);return e.has(r)?e.get(r):(e.set(r,n),n)}function FC({_intern:e,_key:t},n){let r=t(n);return e.has(r)&&(n=e.get(r),e.delete(r)),n}function IC(e){return typeof e==`object`&&e?e.valueOf():e}var LC=Math.sqrt(50),RC=Math.sqrt(10),zC=Math.sqrt(2);function BC(e,t,n){let r=(t-e)/Math.max(0,n),i=Math.floor(Math.log10(r)),a=r/10**i,o=a>=LC?10:a>=RC?5:a>=zC?2:1,s,c,l;return i<0?(l=10**-i/o,s=Math.round(e*l),c=Math.round(t*l),s/l<e&&++s,c/l>t&&--c,l=-l):(l=10**i*o,s=Math.round(e/l),c=Math.round(t/l),s*l<e&&++s,c*l>t&&--c),c<s&&.5<=n&&n<2?BC(e,t,n*2):[s,c,l]}function VC(e,t,n){if(t=+t,e=+e,n=+n,!(n>0))return[];if(e===t)return[e];let r=t<e,[i,a,o]=r?BC(t,e,n):BC(e,t,n);if(!(a>=i))return[];let s=a-i+1,c=Array(s);if(r){if(o<0)for(let e=0;e<s;++e)c[e]=(a-e)/-o;else for(let e=0;e<s;++e)c[e]=(a-e)*o}else if(o<0)for(let e=0;e<s;++e)c[e]=(i+e)/-o;else for(let e=0;e<s;++e)c[e]=(i+e)*o;return c}function HC(e,t,n){return t=+t,e=+e,n=+n,BC(e,t,n)[2]}function UC(e,t,n){t=+t,e=+e,n=+n;let r=t<e,i=r?HC(t,e,n):HC(e,t,n);return(r?-1:1)*(i<0?1/-i:i)}function WC(e,t){let n;if(t===void 0)for(let t of e)t!=null&&(n<t||n===void 0&&t>=t)&&(n=t);else{let r=-1;for(let i of e)(i=t(i,++r,e))!=null&&(n<i||n===void 0&&i>=i)&&(n=i)}return n}function GC(e,t,n){e=+e,t=+t,n=(i=arguments.length)<2?(t=e,e=0,1):i<3?1:+n;for(var r=-1,i=Math.max(0,Math.ceil((t-e)/n))|0,a=Array(i);++r<i;)a[r]=e+r*n;return a}function KC(e){return e}var qC=1,JC=2,YC=3,XC=4,ZC=1e-6;function QC(e){return`translate(`+e+`,0)`}function $C(e){return`translate(0,`+e+`)`}function ew(e){return t=>+e(t)}function tw(e,t){return t=Math.max(0,e.bandwidth()-t*2)/2,e.round()&&(t=Math.round(t)),n=>+e(n)+t}function nw(){return!this.__axis}function rw(e,t){var n=[],r=null,i=null,a=6,o=6,s=3,c=typeof window<`u`&&window.devicePixelRatio>1?0:.5,l=e===qC||e===XC?-1:1,u=e===XC||e===JC?`x`:`y`,d=e===qC||e===YC?QC:$C;function f(f){var p=r??(t.ticks?t.ticks.apply(t,n):t.domain()),m=i??(t.tickFormat?t.tickFormat.apply(t,n):KC),h=Math.max(a,0)+s,g=t.range(),_=+g[0]+c,v=+g[g.length-1]+c,y=(t.bandwidth?tw:ew)(t.copy(),c),b=f.selection?f.selection():f,x=b.selectAll(`.domain`).data([null]),S=b.selectAll(`.tick`).data(p,t).order(),C=S.exit(),w=S.enter().append(`g`).attr(`class`,`tick`),T=S.select(`line`),E=S.select(`text`);x=x.merge(x.enter().insert(`path`,`.tick`).attr(`class`,`domain`).attr(`stroke`,`currentColor`)),S=S.merge(w),T=T.merge(w.append(`line`).attr(`stroke`,`currentColor`).attr(u+`2`,l*a)),E=E.merge(w.append(`text`).attr(`fill`,`currentColor`).attr(u,l*h).attr(`dy`,e===qC?`0em`:e===YC?`0.71em`:`0.32em`)),f!==b&&(x=x.transition(f),S=S.transition(f),T=T.transition(f),E=E.transition(f),C=C.transition(f).attr(`opacity`,ZC).attr(`transform`,function(e){return isFinite(e=y(e))?d(e+c):this.getAttribute(`transform`)}),w.attr(`opacity`,ZC).attr(`transform`,function(e){var t=this.parentNode.__axis;return d((t&&isFinite(t=t(e))?t:y(e))+c)})),C.remove(),x.attr(`d`,e===XC||e===JC?o?`M`+l*o+`,`+_+`H`+c+`V`+v+`H`+l*o:`M`+c+`,`+_+`V`+v:o?`M`+_+`,`+l*o+`V`+c+`H`+v+`V`+l*o:`M`+_+`,`+c+`H`+v),S.attr(`opacity`,1).attr(`transform`,function(e){return d(y(e)+c)}),T.attr(u+`2`,l*a),E.attr(u,l*h).text(m),b.filter(nw).attr(`fill`,`none`).attr(`font-size`,10).attr(`font-family`,`sans-serif`).attr(`text-anchor`,e===JC?`start`:e===XC?`end`:`middle`),b.each(function(){this.__axis=y})}return f.scale=function(e){return arguments.length?(t=e,f):t},f.ticks=function(){return n=Array.from(arguments),f},f.tickArguments=function(e){return arguments.length?(n=e==null?[]:Array.from(e),f):n.slice()},f.tickValues=function(e){return arguments.length?(r=e==null?null:Array.from(e),f):r&&r.slice()},f.tickFormat=function(e){return arguments.length?(i=e,f):i},f.tickSize=function(e){return arguments.length?(a=o=+e,f):a},f.tickSizeInner=function(e){return arguments.length?(a=+e,f):a},f.tickSizeOuter=function(e){return arguments.length?(o=+e,f):o},f.tickPadding=function(e){return arguments.length?(s=+e,f):s},f.offset=function(e){return arguments.length?(c=+e,f):c},f}function iw(e){return rw(YC,e)}function aw(e){return rw(XC,e)}var ow={value:()=>{}};function sw(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+``)||r in n||/[\s.]/.test(r))throw Error(`illegal type: `+r);n[r]=[]}return new cw(n)}function cw(e){this._=e}function lw(e,t){return e.trim().split(/^|\s+/).map(function(e){var n=``,r=e.indexOf(`.`);if(r>=0&&(n=e.slice(r+1),e=e.slice(0,r)),e&&!t.hasOwnProperty(e))throw Error(`unknown type: `+e);return{type:e,name:n}})}cw.prototype=sw.prototype={constructor:cw,on:function(e,t){var n=this._,r=lw(e+``,n),i,a=-1,o=r.length;if(arguments.length<2){for(;++a<o;)if((i=(e=r[a]).type)&&(i=uw(n[i],e.name)))return i;return}if(t!=null&&typeof t!=`function`)throw Error(`invalid callback: `+t);for(;++a<o;)if(i=(e=r[a]).type)n[i]=dw(n[i],e.name,t);else if(t==null)for(i in n)n[i]=dw(n[i],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new cw(e)},call:function(e,t){if((i=arguments.length-2)>0)for(var n=Array(i),r=0,i,a;r<i;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(a=this._[e],r=0,i=a.length;r<i;++r)a[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw Error(`unknown type: `+e);for(var r=this._[e],i=0,a=r.length;i<a;++i)r[i].value.apply(t,n)}};function uw(e,t){for(var n=0,r=e.length,i;n<r;++n)if((i=e[n]).name===t)return i.value}function dw(e,t,n){for(var r=0,i=e.length;r<i;++r)if(e[r].name===t){e[r]=ow,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var fw={svg:`http://www.w3.org/2000/svg`,xhtml:`http://www.w3.org/1999/xhtml`,xlink:`http://www.w3.org/1999/xlink`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};function pw(e){var t=e+=``,n=t.indexOf(`:`);return n>=0&&(t=e.slice(0,n))!==`xmlns`&&(e=e.slice(n+1)),fw.hasOwnProperty(t)?{space:fw[t],local:e}:e}function mw(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===`http://www.w3.org/1999/xhtml`&&t.documentElement.namespaceURI===`http://www.w3.org/1999/xhtml`?t.createElement(e):t.createElementNS(n,e)}}function hw(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function gw(e){var t=pw(e);return(t.local?hw:mw)(t)}function _w(){}function vw(e){return e==null?_w:function(){return this.querySelector(e)}}function yw(e){typeof e!=`function`&&(e=vw(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=Array(o),c,l,u=0;u<o;++u)(c=a[u])&&(l=e.call(c,c.__data__,u,a))&&(`__data__`in c&&(l.__data__=c.__data__),s[u]=l);return new sE(r,this._parents)}function bw(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function xw(){return[]}function Sw(e){return e==null?xw:function(){return this.querySelectorAll(e)}}function Cw(e){return function(){return bw(e.apply(this,arguments))}}function ww(e){e=typeof e==`function`?Cw(e):Sw(e);for(var t=this._groups,n=t.length,r=[],i=[],a=0;a<n;++a)for(var o=t[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&(r.push(e.call(c,c.__data__,l,o)),i.push(c));return new sE(r,i)}function Tw(e){return function(){return this.matches(e)}}function Ew(e){return function(t){return t.matches(e)}}var Dw=Array.prototype.find;function Ow(e){return function(){return Dw.call(this.children,e)}}function kw(){return this.firstElementChild}function Aw(e){return this.select(e==null?kw:Ow(typeof e==`function`?e:Ew(e)))}var jw=Array.prototype.filter;function Mw(){return Array.from(this.children)}function Nw(e){return function(){return jw.call(this.children,e)}}function Pw(e){return this.selectAll(e==null?Mw:Nw(typeof e==`function`?e:Ew(e)))}function Fw(e){typeof e!=`function`&&(e=Tw(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new sE(r,this._parents)}function Iw(e){return Array(e.length)}function Lw(){return new sE(this._enter||this._groups.map(Iw),this._parents)}function Rw(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Rw.prototype={constructor:Rw,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function zw(e){return function(){return e}}function Bw(e,t,n,r,i,a){for(var o=0,s,c=t.length,l=a.length;o<l;++o)(s=t[o])?(s.__data__=a[o],r[o]=s):n[o]=new Rw(e,a[o]);for(;o<c;++o)(s=t[o])&&(i[o]=s)}function Vw(e,t,n,r,i,a,o){var s,c,l=new Map,u=t.length,d=a.length,f=Array(u),p;for(s=0;s<u;++s)(c=t[s])&&(f[s]=p=o.call(c,c.__data__,s,t)+``,l.has(p)?i[s]=c:l.set(p,c));for(s=0;s<d;++s)p=o.call(e,a[s],s,a)+``,(c=l.get(p))?(r[s]=c,c.__data__=a[s],l.delete(p)):n[s]=new Rw(e,a[s]);for(s=0;s<u;++s)(c=t[s])&&l.get(f[s])===c&&(i[s]=c)}function Hw(e){return e.__data__}function Uw(e,t){if(!arguments.length)return Array.from(this,Hw);var n=t?Vw:Bw,r=this._parents,i=this._groups;typeof e!=`function`&&(e=zw(e));for(var a=i.length,o=Array(a),s=Array(a),c=Array(a),l=0;l<a;++l){var u=r[l],d=i[l],f=d.length,p=Ww(e.call(u,u&&u.__data__,l,r)),m=p.length,h=s[l]=Array(m),g=o[l]=Array(m);n(u,d,h,g,c[l]=Array(f),p,t);for(var _=0,v=0,y,b;_<m;++_)if(y=h[_]){for(_>=v&&(v=_+1);!(b=g[v])&&++v<m;);y._next=b||null}}return o=new sE(o,r),o._enter=s,o._exit=c,o}function Ww(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function Gw(){return new sE(this._exit||this._groups.map(Iw),this._parents)}function Kw(e,t,n){var r=this.enter(),i=this,a=this.exit();return typeof e==`function`?(r=e(r),r&&=r.selection()):r=r.append(e+``),t!=null&&(i=t(i),i&&=i.selection()),n==null?a.remove():n(a),r&&i?r.merge(i).order():i}function qw(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,i=n.length,a=r.length,o=Math.min(i,a),s=Array(i),c=0;c<o;++c)for(var l=n[c],u=r[c],d=l.length,f=s[c]=Array(d),p,m=0;m<d;++m)(p=l[m]||u[m])&&(f[m]=p);for(;c<i;++c)s[c]=n[c];return new sE(s,this._parents)}function Jw(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],i=r.length-1,a=r[i],o;--i>=0;)(o=r[i])&&(a&&o.compareDocumentPosition(a)^4&&a.parentNode.insertBefore(o,a),a=o);return this}function Yw(e){e||=Xw;function t(t,n){return t&&n?e(t.__data__,n.__data__):!t-!n}for(var n=this._groups,r=n.length,i=Array(r),a=0;a<r;++a){for(var o=n[a],s=o.length,c=i[a]=Array(s),l,u=0;u<s;++u)(l=o[u])&&(c[u]=l);c.sort(t)}return new sE(i,this._parents).order()}function Xw(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Zw(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function Qw(){return Array.from(this)}function $w(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null}function eT(){let e=0;for(let t of this)++e;return e}function tT(){return!this.node()}function nT(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var i=t[n],a=0,o=i.length,s;a<o;++a)(s=i[a])&&e.call(s,s.__data__,a,i);return this}function rT(e){return function(){this.removeAttribute(e)}}function iT(e){return function(){this.removeAttributeNS(e.space,e.local)}}function aT(e,t){return function(){this.setAttribute(e,t)}}function oT(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function sT(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function cT(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function lT(e,t){var n=pw(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?iT:rT:typeof t==`function`?n.local?cT:sT:n.local?oT:aT)(n,t))}function uT(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function dT(e){return function(){this.style.removeProperty(e)}}function fT(e,t,n){return function(){this.style.setProperty(e,t,n)}}function pT(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function mT(e,t,n){return arguments.length>1?this.each((t==null?dT:typeof t==`function`?pT:fT)(e,t,n??``)):hT(this.node(),e)}function hT(e,t){return e.style.getPropertyValue(t)||uT(e).getComputedStyle(e,null).getPropertyValue(t)}function gT(e){return function(){delete this[e]}}function _T(e,t){return function(){this[e]=t}}function vT(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function yT(e,t){return arguments.length>1?this.each((t==null?gT:typeof t==`function`?vT:_T)(e,t)):this.node()[e]}function bT(e){return e.trim().split(/^|\s+/)}function xT(e){return e.classList||new ST(e)}function ST(e){this._node=e,this._names=bT(e.getAttribute(`class`)||``)}ST.prototype={add:function(e){this._names.indexOf(e)<0&&(this._names.push(e),this._node.setAttribute(`class`,this._names.join(` `)))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute(`class`,this._names.join(` `)))},contains:function(e){return this._names.indexOf(e)>=0}};function CT(e,t){for(var n=xT(e),r=-1,i=t.length;++r<i;)n.add(t[r])}function wT(e,t){for(var n=xT(e),r=-1,i=t.length;++r<i;)n.remove(t[r])}function TT(e){return function(){CT(this,e)}}function ET(e){return function(){wT(this,e)}}function DT(e,t){return function(){(t.apply(this,arguments)?CT:wT)(this,e)}}function OT(e,t){var n=bT(e+``);if(arguments.length<2){for(var r=xT(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each((typeof t==`function`?DT:t?TT:ET)(n,t))}function kT(){this.textContent=``}function AT(e){return function(){this.textContent=e}}function jT(e){return function(){var t=e.apply(this,arguments);this.textContent=t??``}}function MT(e){return arguments.length?this.each(e==null?kT:(typeof e==`function`?jT:AT)(e)):this.node().textContent}function NT(){this.innerHTML=``}function PT(e){return function(){this.innerHTML=e}}function FT(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??``}}function IT(e){return arguments.length?this.each(e==null?NT:(typeof e==`function`?FT:PT)(e)):this.node().innerHTML}function LT(){this.nextSibling&&this.parentNode.appendChild(this)}function RT(){return this.each(LT)}function zT(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function BT(){return this.each(zT)}function VT(e){var t=typeof e==`function`?e:gw(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function HT(){return null}function UT(e,t){var n=typeof e==`function`?e:gw(e),r=t==null?HT:typeof t==`function`?t:vw(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function WT(){var e=this.parentNode;e&&e.removeChild(this)}function GT(){return this.each(WT)}function KT(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function qT(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function JT(e){return this.select(e?qT:KT)}function YT(e){return arguments.length?this.property(`__data__`,e):this.node().__data__}function XT(e){return function(t){e.call(this,t,this.__data__)}}function ZT(e){return e.trim().split(/^|\s+/).map(function(e){var t=``,n=e.indexOf(`.`);return n>=0&&(t=e.slice(n+1),e=e.slice(0,n)),{type:e,name:t}})}function QT(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,i=t.length,a;n<i;++n)a=t[n],(!e.type||a.type===e.type)&&a.name===e.name?this.removeEventListener(a.type,a.listener,a.options):t[++r]=a;++r?t.length=r:delete this.__on}}}function $T(e,t,n){return function(){var r=this.__on,i,a=XT(t);if(r){for(var o=0,s=r.length;o<s;++o)if((i=r[o]).type===e.type&&i.name===e.name){this.removeEventListener(i.type,i.listener,i.options),this.addEventListener(i.type,i.listener=a,i.options=n),i.value=t;return}}this.addEventListener(e.type,a,n),i={type:e.type,name:e.name,value:t,listener:a,options:n},r?r.push(i):this.__on=[i]}}function eE(e,t,n){var r=ZT(e+``),i,a=r.length,o;if(arguments.length<2){var s=this.node().__on;if(s){for(var c=0,l=s.length,u;c<l;++c)for(i=0,u=s[c];i<a;++i)if((o=r[i]).type===u.type&&o.name===u.name)return u.value}return}for(s=t?$T:QT,i=0;i<a;++i)this.each(s(r[i],t,n));return this}function tE(e,t,n){var r=uT(e),i=r.CustomEvent;typeof i==`function`?i=new i(t,n):(i=r.document.createEvent(`Event`),n?(i.initEvent(t,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(t,!1,!1)),e.dispatchEvent(i)}function nE(e,t){return function(){return tE(this,e,t)}}function rE(e,t){return function(){return tE(this,e,t.apply(this,arguments))}}function iE(e,t){return this.each((typeof t==`function`?rE:nE)(e,t))}function*aE(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],i=0,a=r.length,o;i<a;++i)(o=r[i])&&(yield o)}var oE=[null];function sE(e,t){this._groups=e,this._parents=t}function cE(){return new sE([[document.documentElement]],oE)}function lE(){return this}sE.prototype=cE.prototype={constructor:sE,select:yw,selectAll:ww,selectChild:Aw,selectChildren:Pw,filter:Fw,data:Uw,enter:Lw,exit:Gw,join:Kw,merge:qw,selection:lE,order:Jw,sort:Yw,call:Zw,nodes:Qw,node:$w,size:eT,empty:tT,each:nT,attr:lT,style:mT,property:yT,classed:OT,text:MT,html:IT,raise:RT,lower:BT,append:VT,insert:UT,remove:GT,clone:JT,datum:YT,on:eE,dispatch:iE,[Symbol.iterator]:aE};function uE(e){return typeof e==`string`?new sE([[document.querySelector(e)]],[document.documentElement]):new sE([[e]],oE)}function dE(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function fE(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function pE(){}var mE=.7,hE=1/mE,gE=`\\s*([+-]?\\d+)\\s*`,_E=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*`,vE=`\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*`,yE=/^#([0-9a-f]{3,8})$/,bE=RegExp(`^rgb\\(${gE},${gE},${gE}\\)$`),xE=RegExp(`^rgb\\(${vE},${vE},${vE}\\)$`),SE=RegExp(`^rgba\\(${gE},${gE},${gE},${_E}\\)$`),CE=RegExp(`^rgba\\(${vE},${vE},${vE},${_E}\\)$`),wE=RegExp(`^hsl\\(${_E},${vE},${vE}\\)$`),TE=RegExp(`^hsla\\(${_E},${vE},${vE},${_E}\\)$`),EE={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};dE(pE,jE,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:DE,formatHex:DE,formatHex8:OE,formatHsl:kE,formatRgb:AE,toString:AE});function DE(){return this.rgb().formatHex()}function OE(){return this.rgb().formatHex8()}function kE(){return WE(this).formatHsl()}function AE(){return this.rgb().formatRgb()}function jE(e){var t,n;return e=(e+``).trim().toLowerCase(),(t=yE.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?ME(t):n===3?new IE(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?NE(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?NE(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=bE.exec(e))?new IE(t[1],t[2],t[3],1):(t=xE.exec(e))?new IE(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=SE.exec(e))?NE(t[1],t[2],t[3],t[4]):(t=CE.exec(e))?NE(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=wE.exec(e))?UE(t[1],t[2]/100,t[3]/100,1):(t=TE.exec(e))?UE(t[1],t[2]/100,t[3]/100,t[4]):EE.hasOwnProperty(e)?ME(EE[e]):e===`transparent`?new IE(NaN,NaN,NaN,0):null}function ME(e){return new IE(e>>16&255,e>>8&255,e&255,1)}function NE(e,t,n,r){return r<=0&&(e=t=n=NaN),new IE(e,t,n,r)}function PE(e){return e instanceof pE||(e=jE(e)),e?(e=e.rgb(),new IE(e.r,e.g,e.b,e.opacity)):new IE}function FE(e,t,n,r){return arguments.length===1?PE(e):new IE(e,t,n,r??1)}function IE(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}dE(IE,FE,fE(pE,{brighter(e){return e=e==null?hE:hE**+e,new IE(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?mE:mE**+e,new IE(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new IE(VE(this.r),VE(this.g),VE(this.b),BE(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:LE,formatHex:LE,formatHex8:RE,formatRgb:zE,toString:zE}));function LE(){return`#${HE(this.r)}${HE(this.g)}${HE(this.b)}`}function RE(){return`#${HE(this.r)}${HE(this.g)}${HE(this.b)}${HE((isNaN(this.opacity)?1:this.opacity)*255)}`}function zE(){let e=BE(this.opacity);return`${e===1?`rgb(`:`rgba(`}${VE(this.r)}, ${VE(this.g)}, ${VE(this.b)}${e===1?`)`:`, ${e})`}`}function BE(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function VE(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function HE(e){return e=VE(e),(e<16?`0`:``)+e.toString(16)}function UE(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new KE(e,t,n,r)}function WE(e){if(e instanceof KE)return new KE(e.h,e.s,e.l,e.opacity);if(e instanceof pE||(e=jE(e)),!e)return new KE;if(e instanceof KE)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),a=Math.max(t,n,r),o=NaN,s=a-i,c=(a+i)/2;return s?(o=t===a?(n-r)/s+(n<r)*6:n===a?(r-t)/s+2:(t-n)/s+4,s/=c<.5?a+i:2-a-i,o*=60):s=c>0&&c<1?0:o,new KE(o,s,c,e.opacity)}function GE(e,t,n,r){return arguments.length===1?WE(e):new KE(e,t,n,r??1)}function KE(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}dE(KE,GE,fE(pE,{brighter(e){return e=e==null?hE:hE**+e,new KE(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?mE:mE**+e,new KE(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new IE(YE(e>=240?e-240:e+120,i,r),YE(e,i,r),YE(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new KE(qE(this.h),JE(this.s),JE(this.l),BE(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){let e=BE(this.opacity);return`${e===1?`hsl(`:`hsla(`}${qE(this.h)}, ${JE(this.s)*100}%, ${JE(this.l)*100}%${e===1?`)`:`, ${e})`}`}}));function qE(e){return e=(e||0)%360,e<0?e+360:e}function JE(e){return Math.max(0,Math.min(1,e||0))}function YE(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}var XE=e=>()=>e;function ZE(e,t){return function(n){return e+n*t}}function QE(e,t,n){return e**=+n,t=t**+n-e,n=1/n,function(r){return(e+r*t)**+n}}function $E(e){return(e=+e)==1?eD:function(t,n){return n-t?QE(t,n,e):XE(isNaN(t)?n:t)}}function eD(e,t){var n=t-e;return n?ZE(e,n):XE(isNaN(e)?t:e)}var tD=(function e(t){var n=$E(t);function r(e,t){var r=n((e=FE(e)).r,(t=FE(t)).r),i=n(e.g,t.g),a=n(e.b,t.b),o=eD(e.opacity,t.opacity);return function(t){return e.r=r(t),e.g=i(t),e.b=a(t),e.opacity=o(t),e+``}}return r.gamma=e,r})(1);function nD(e,t){t||=[];var n=e?Math.min(t.length,e.length):0,r=t.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=e[i]*(1-a)+t[i]*a;return r}}function rD(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function iD(e,t){var n=t?t.length:0,r=e?Math.min(n,e.length):0,i=Array(r),a=Array(n),o;for(o=0;o<r;++o)i[o]=pD(e[o],t[o]);for(;o<n;++o)a[o]=t[o];return function(e){for(o=0;o<r;++o)a[o]=i[o](e);return a}}function aD(e,t){var n=new Date;return e=+e,t=+t,function(r){return n.setTime(e*(1-r)+t*r),n}}function oD(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function sD(e,t){var n={},r={},i;for(i in(typeof e!=`object`||!e)&&(e={}),(typeof t!=`object`||!t)&&(t={}),t)i in e?n[i]=pD(e[i],t[i]):r[i]=t[i];return function(e){for(i in n)r[i]=n[i](e);return r}}var cD=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,lD=new RegExp(cD.source,`g`);function uD(e){return function(){return e}}function dD(e){return function(t){return e(t)+``}}function fD(e,t){var n=cD.lastIndex=lD.lastIndex=0,r,i,a,o=-1,s=[],c=[];for(e+=``,t+=``;(r=cD.exec(e))&&(i=lD.exec(t));)(a=i.index)>n&&(a=t.slice(n,a),s[o]?s[o]+=a:s[++o]=a),(r=r[0])===(i=i[0])?s[o]?s[o]+=i:s[++o]=i:(s[++o]=null,c.push({i:o,x:oD(r,i)})),n=lD.lastIndex;return n<t.length&&(a=t.slice(n),s[o]?s[o]+=a:s[++o]=a),s.length<2?c[0]?dD(c[0].x):uD(t):(t=c.length,function(e){for(var n=0,r;n<t;++n)s[(r=c[n]).i]=r.x(e);return s.join(``)})}function pD(e,t){var n=typeof t,r;return t==null||n===`boolean`?XE(t):(n===`number`?oD:n===`string`?(r=jE(t))?(t=r,tD):fD:t instanceof jE?tD:t instanceof Date?aD:rD(t)?nD:Array.isArray(t)?iD:typeof t.valueOf!=`function`&&typeof t.toString!=`function`||isNaN(t)?sD:oD)(e,t)}function mD(e,t){return e=+e,t=+t,function(n){return Math.round(e*(1-n)+t*n)}}var hD=180/Math.PI,gD={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function _D(e,t,n,r,i,a){var o,s,c;return(o=Math.sqrt(e*e+t*t))&&(e/=o,t/=o),(c=e*n+t*r)&&(n-=e*c,r-=t*c),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,c/=s),e*r<t*n&&(e=-e,t=-t,c=-c,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(t,e)*hD,skewX:Math.atan(c)*hD,scaleX:o,scaleY:s}}var vD;function yD(e){let t=new(typeof DOMMatrix==`function`?DOMMatrix:WebKitCSSMatrix)(e+``);return t.isIdentity?gD:_D(t.a,t.b,t.c,t.d,t.e,t.f)}function bD(e){return e==null||(vD||=document.createElementNS(`http://www.w3.org/2000/svg`,`g`),vD.setAttribute(`transform`,e),!(e=vD.transform.baseVal.consolidate()))?gD:(e=e.matrix,_D(e.a,e.b,e.c,e.d,e.e,e.f))}function xD(e,t,n,r){function i(e){return e.length?e.pop()+` `:``}function a(e,r,i,a,o,s){if(e!==i||r!==a){var c=o.push(`translate(`,null,t,null,n);s.push({i:c-4,x:oD(e,i)},{i:c-2,x:oD(r,a)})}else(i||a)&&o.push(`translate(`+i+t+a+n)}function o(e,t,n,a){e===t?t&&n.push(i(n)+`rotate(`+t+r):(e-t>180?t+=360:t-e>180&&(e+=360),a.push({i:n.push(i(n)+`rotate(`,null,r)-2,x:oD(e,t)}))}function s(e,t,n,a){e===t?t&&n.push(i(n)+`skewX(`+t+r):a.push({i:n.push(i(n)+`skewX(`,null,r)-2,x:oD(e,t)})}function c(e,t,n,r,a,o){if(e!==n||t!==r){var s=a.push(i(a)+`scale(`,null,`,`,null,`)`);o.push({i:s-4,x:oD(e,n)},{i:s-2,x:oD(t,r)})}else(n!==1||r!==1)&&a.push(i(a)+`scale(`+n+`,`+r+`)`)}return function(t,n){var r=[],i=[];return t=e(t),n=e(n),a(t.translateX,t.translateY,n.translateX,n.translateY,r,i),o(t.rotate,n.rotate,r,i),s(t.skewX,n.skewX,r,i),c(t.scaleX,t.scaleY,n.scaleX,n.scaleY,r,i),t=n=null,function(e){for(var t=-1,n=i.length,a;++t<n;)r[(a=i[t]).i]=a.x(e);return r.join(``)}}}var SD=xD(yD,`px, `,`px)`,`deg)`),CD=xD(bD,`, `,`)`,`)`),wD=0,TD=0,ED=0,DD=1e3,OD,kD,AD=0,jD=0,MD=0,ND=typeof performance==`object`&&performance.now?performance:Date,PD=typeof window==`object`&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function FD(){return jD||=(PD(ID),ND.now()+MD)}function ID(){jD=0}function LD(){this._call=this._time=this._next=null}LD.prototype=RD.prototype={constructor:LD,restart:function(e,t,n){if(typeof e!=`function`)throw TypeError(`callback is not a function`);n=(n==null?FD():+n)+(t==null?0:+t),!this._next&&kD!==this&&(kD?kD._next=this:OD=this,kD=this),this._call=e,this._time=n,UD()},stop:function(){this._call&&(this._call=null,this._time=1/0,UD())}};function RD(e,t,n){var r=new LD;return r.restart(e,t,n),r}function zD(){FD(),++wD;for(var e=OD,t;e;)(t=jD-e._time)>=0&&e._call.call(void 0,t),e=e._next;--wD}function BD(){jD=(AD=ND.now())+MD,wD=TD=0;try{zD()}finally{wD=0,HD(),jD=0}}function VD(){var e=ND.now(),t=e-AD;t>DD&&(MD-=t,AD=e)}function HD(){for(var e,t=OD,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:OD=n);kD=e,UD(r)}function UD(e){wD||(TD&&=clearTimeout(TD),e-jD>24?(e<1/0&&(TD=setTimeout(BD,e-ND.now()-MD)),ED&&=clearInterval(ED)):(ED||=(AD=ND.now(),setInterval(VD,DD)),wD=1,PD(BD)))}function WD(e,t,n){var r=new LD;return t=t==null?0:+t,r.restart(n=>{r.stop(),e(n+t)},t,n),r}var GD=sw(`start`,`end`,`cancel`,`interrupt`),KD=[];function qD(e,t,n,r,i,a){var o=e.__transition;if(!o)e.__transition={};else if(n in o)return;ZD(e,n,{name:t,index:r,group:i,on:GD,tween:KD,time:a.time,delay:a.delay,duration:a.duration,ease:a.ease,timer:null,state:0})}function JD(e,t){var n=XD(e,t);if(n.state>0)throw Error(`too late; already scheduled`);return n}function YD(e,t){var n=XD(e,t);if(n.state>3)throw Error(`too late; already running`);return n}function XD(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw Error(`transition not found`);return n}function ZD(e,t,n){var r=e.__transition,i;r[t]=n,n.timer=RD(a,0,n.time);function a(e){n.state=1,n.timer.restart(o,n.delay,n.time),n.delay<=e&&o(e-n.delay)}function o(a){var l,u,d,f;if(n.state!==1)return c();for(l in r)if(f=r[l],f.name===n.name){if(f.state===3)return WD(o);f.state===4?(f.state=6,f.timer.stop(),f.on.call(`interrupt`,e,e.__data__,f.index,f.group),delete r[l]):+l<t&&(f.state=6,f.timer.stop(),f.on.call(`cancel`,e,e.__data__,f.index,f.group),delete r[l])}if(WD(function(){n.state===3&&(n.state=4,n.timer.restart(s,n.delay,n.time),s(a))}),n.state=2,n.on.call(`start`,e,e.__data__,n.index,n.group),n.state===2){for(n.state=3,i=Array(d=n.tween.length),l=0,u=-1;l<d;++l)(f=n.tween[l].value.call(e,e.__data__,n.index,n.group))&&(i[++u]=f);i.length=u+1}}function s(t){for(var r=t<n.duration?n.ease.call(null,t/n.duration):(n.timer.restart(c),n.state=5,1),a=-1,o=i.length;++a<o;)i[a].call(e,r);n.state===5&&(n.on.call(`end`,e,e.__data__,n.index,n.group),c())}function c(){for(var i in n.state=6,n.timer.stop(),delete r[t],r)return;delete e.__transition}}function QD(e,t){var n=e.__transition,r,i,a=!0,o;if(n){for(o in t=t==null?null:t+``,n){if((r=n[o]).name!==t){a=!1;continue}i=r.state>2&&r.state<5,r.state=6,r.timer.stop(),r.on.call(i?`interrupt`:`cancel`,e,e.__data__,r.index,r.group),delete n[o]}a&&delete e.__transition}}function $D(e){return this.each(function(){QD(this,e)})}function eO(e,t){var n,r;return function(){var i=YD(this,e),a=i.tween;if(a!==n){r=n=a;for(var o=0,s=r.length;o<s;++o)if(r[o].name===t){r=r.slice(),r.splice(o,1);break}}i.tween=r}}function tO(e,t,n){var r,i;if(typeof n!=`function`)throw Error();return function(){var a=YD(this,e),o=a.tween;if(o!==r){i=(r=o).slice();for(var s={name:t,value:n},c=0,l=i.length;c<l;++c)if(i[c].name===t){i[c]=s;break}c===l&&i.push(s)}a.tween=i}}function nO(e,t){var n=this._id;if(e+=``,arguments.length<2){for(var r=XD(this.node(),n).tween,i=0,a=r.length,o;i<a;++i)if((o=r[i]).name===e)return o.value;return null}return this.each((t==null?eO:tO)(n,e,t))}function rO(e,t,n){var r=e._id;return e.each(function(){var e=YD(this,r);(e.value||={})[t]=n.apply(this,arguments)}),function(e){return XD(e,r).value[t]}}function iO(e,t){var n;return(typeof t==`number`?oD:t instanceof jE?tD:(n=jE(t))?(t=n,tD):fD)(e,t)}function aO(e){return function(){this.removeAttribute(e)}}function oO(e){return function(){this.removeAttributeNS(e.space,e.local)}}function sO(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttribute(e);return o===i?null:o===r?a:a=t(r=o,n)}}function cO(e,t,n){var r,i=n+``,a;return function(){var o=this.getAttributeNS(e.space,e.local);return o===i?null:o===r?a:a=t(r=o,n)}}function lO(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttribute(e):(o=this.getAttribute(e),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function uO(e,t,n){var r,i,a;return function(){var o,s=n(this),c;return s==null?void this.removeAttributeNS(e.space,e.local):(o=this.getAttributeNS(e.space,e.local),c=s+``,o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s)))}}function dO(e,t){var n=pw(e),r=n===`transform`?CD:iO;return this.attrTween(e,typeof t==`function`?(n.local?uO:lO)(n,r,rO(this,`attr.`+e,t)):t==null?(n.local?oO:aO)(n):(n.local?cO:sO)(n,r,t))}function fO(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function pO(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function mO(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&pO(e,i)),n}return i._value=t,i}function hO(e,t){var n,r;function i(){var i=t.apply(this,arguments);return i!==r&&(n=(r=i)&&fO(e,i)),n}return i._value=t,i}function gO(e,t){var n=`attr.`+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!=`function`)throw Error();var r=pw(e);return this.tween(n,(r.local?mO:hO)(r,t))}function _O(e,t){return function(){JD(this,e).delay=+t.apply(this,arguments)}}function vO(e,t){return t=+t,function(){JD(this,e).delay=t}}function yO(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?_O:vO)(t,e)):XD(this.node(),t).delay}function bO(e,t){return function(){YD(this,e).duration=+t.apply(this,arguments)}}function xO(e,t){return t=+t,function(){YD(this,e).duration=t}}function SO(e){var t=this._id;return arguments.length?this.each((typeof e==`function`?bO:xO)(t,e)):XD(this.node(),t).duration}function CO(e,t){if(typeof t!=`function`)throw Error();return function(){YD(this,e).ease=t}}function wO(e){var t=this._id;return arguments.length?this.each(CO(t,e)):XD(this.node(),t).ease}function TO(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!=`function`)throw Error();YD(this,e).ease=n}}function EO(e){if(typeof e!=`function`)throw Error();return this.each(TO(this._id,e))}function DO(e){typeof e!=`function`&&(e=Tw(e));for(var t=this._groups,n=t.length,r=Array(n),i=0;i<n;++i)for(var a=t[i],o=a.length,s=r[i]=[],c,l=0;l<o;++l)(c=a[l])&&e.call(c,c.__data__,l,a)&&s.push(c);return new nk(r,this._parents,this._name,this._id)}function OO(e){if(e._id!==this._id)throw Error();for(var t=this._groups,n=e._groups,r=t.length,i=n.length,a=Math.min(r,i),o=Array(r),s=0;s<a;++s)for(var c=t[s],l=n[s],u=c.length,d=o[s]=Array(u),f,p=0;p<u;++p)(f=c[p]||l[p])&&(d[p]=f);for(;s<r;++s)o[s]=t[s];return new nk(o,this._parents,this._name,this._id)}function kO(e){return(e+``).trim().split(/^|\s+/).every(function(e){var t=e.indexOf(`.`);return t>=0&&(e=e.slice(0,t)),!e||e===`start`})}function AO(e,t,n){var r,i,a=kO(t)?JD:YD;return function(){var o=a(this,e),s=o.on;s!==r&&(i=(r=s).copy()).on(t,n),o.on=i}}function jO(e,t){var n=this._id;return arguments.length<2?XD(this.node(),n).on.on(e):this.each(AO(n,e,t))}function MO(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function NO(){return this.on(`end.remove`,MO(this._id))}function PO(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=vw(e));for(var r=this._groups,i=r.length,a=Array(i),o=0;o<i;++o)for(var s=r[o],c=s.length,l=a[o]=Array(c),u,d,f=0;f<c;++f)(u=s[f])&&(d=e.call(u,u.__data__,f,s))&&(`__data__`in u&&(d.__data__=u.__data__),l[f]=d,qD(l[f],t,n,f,l,XD(u,n)));return new nk(a,this._parents,t,n)}function FO(e){var t=this._name,n=this._id;typeof e!=`function`&&(e=Sw(e));for(var r=this._groups,i=r.length,a=[],o=[],s=0;s<i;++s)for(var c=r[s],l=c.length,u,d=0;d<l;++d)if(u=c[d]){for(var f=e.call(u,u.__data__,d,c),p,m=XD(u,n),h=0,g=f.length;h<g;++h)(p=f[h])&&qD(p,t,n,h,f,m);a.push(f),o.push(u)}return new nk(a,o,t,n)}var IO=cE.prototype.constructor;function LO(){return new IO(this._groups,this._parents)}function RO(e,t){var n,r,i;return function(){var a=hT(this,e),o=(this.style.removeProperty(e),hT(this,e));return a===o?null:a===n&&o===r?i:i=t(n=a,r=o)}}function zO(e){return function(){this.style.removeProperty(e)}}function BO(e,t,n){var r,i=n+``,a;return function(){var o=hT(this,e);return o===i?null:o===r?a:a=t(r=o,n)}}function VO(e,t,n){var r,i,a;return function(){var o=hT(this,e),s=n(this),c=s+``;return s??(c=s=(this.style.removeProperty(e),hT(this,e))),o===c?null:o===r&&c===i?a:(i=c,a=t(r=o,s))}}function HO(e,t){var n,r,i,a=`style.`+t,o=`end.`+a,s;return function(){var c=YD(this,e),l=c.on,u=c.value[a]==null?s||=zO(t):void 0;(l!==n||i!==u)&&(r=(n=l).copy()).on(o,i=u),c.on=r}}function UO(e,t,n){var r=(e+=``)==`transform`?SD:iO;return t==null?this.styleTween(e,RO(e,r)).on(`end.style.`+e,zO(e)):typeof t==`function`?this.styleTween(e,VO(e,r,rO(this,`style.`+e,t))).each(HO(this._id,e)):this.styleTween(e,BO(e,r,t),n).on(`end.style.`+e,null)}function WO(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function GO(e,t,n){var r,i;function a(){var a=t.apply(this,arguments);return a!==i&&(r=(i=a)&&WO(e,a,n)),r}return a._value=t,a}function KO(e,t,n){var r=`style.`+(e+=``);if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!=`function`)throw Error();return this.tween(r,GO(e,t,n??``))}function qO(e){return function(){this.textContent=e}}function JO(e){return function(){var t=e(this);this.textContent=t??``}}function YO(e){return this.tween(`text`,typeof e==`function`?JO(rO(this,`text`,e)):qO(e==null?``:e+``))}function XO(e){return function(t){this.textContent=e.call(this,t)}}function ZO(e){var t,n;function r(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&XO(r)),t}return r._value=e,r}function QO(e){var t=`text`;if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!=`function`)throw Error();return this.tween(t,ZO(e))}function $O(){for(var e=this._name,t=this._id,n=rk(),r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)if(c=o[l]){var u=XD(c,t);qD(c,e,n,l,o,{time:u.time+u.delay+u.duration,delay:0,duration:u.duration,ease:u.ease})}return new nk(r,this._parents,e,n)}function ek(){var e,t,n=this,r=n._id,i=n.size();return new Promise(function(a,o){var s={value:o},c={value:function(){--i===0&&a()}};n.each(function(){var n=YD(this,r),i=n.on;i!==e&&(t=(e=i).copy(),t._.cancel.push(s),t._.interrupt.push(s),t._.end.push(c)),n.on=t}),i===0&&a()})}var tk=0;function nk(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function rk(){return++tk}var ik=cE.prototype;nk.prototype={constructor:nk,select:PO,selectAll:FO,selectChild:ik.selectChild,selectChildren:ik.selectChildren,filter:DO,merge:OO,selection:LO,transition:$O,call:ik.call,nodes:ik.nodes,node:ik.node,size:ik.size,empty:ik.empty,each:ik.each,on:jO,attr:dO,attrTween:gO,style:UO,styleTween:KO,text:YO,textTween:QO,remove:NO,tween:nO,delay:yO,duration:SO,ease:wO,easeVarying:EO,end:ek,[Symbol.iterator]:ik[Symbol.iterator]};function ak(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var ok={time:null,delay:0,duration:250,ease:ak};function sk(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw Error(`transition ${t} not found`);return n}function ck(e){var t,n;e instanceof nk?(t=e._id,e=e._name):(t=rk(),(n=ok).time=FD(),e=e==null?null:e+``);for(var r=this._groups,i=r.length,a=0;a<i;++a)for(var o=r[a],s=o.length,c,l=0;l<s;++l)(c=o[l])&&qD(c,e,t,l,o,n||sk(c,t));return new nk(r,this._parents,e,t)}cE.prototype.interrupt=$D,cE.prototype.transition=ck;var{abs:lk,max:uk,min:dk}=Math;[`w`,`e`].map(fk),[`n`,`s`].map(fk),[`n`,`w`,`e`,`s`,`nw`,`ne`,`sw`,`se`].map(fk);function fk(e){return{type:e}}var pk=Math.PI,mk=2*pk,hk=1e-6,gk=mk-hk;function _k(e){this._+=e[0];for(let t=1,n=e.length;t<n;++t)this._+=arguments[t]+e[t]}function vk(e){let t=Math.floor(e);if(!(t>=0))throw Error(`invalid digits: ${e}`);if(t>15)return _k;let n=10**t;return function(e){this._+=e[0];for(let t=1,r=e.length;t<r;++t)this._+=Math.round(arguments[t]*n)/n+e[t]}}var yk=class{constructor(e){this._x0=this._y0=this._x1=this._y1=null,this._=``,this._append=e==null?_k:vk(e)}moveTo(e,t){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(e,t){this._append`L${this._x1=+e},${this._y1=+t}`}quadraticCurveTo(e,t,n,r){this._append`Q${+e},${+t},${this._x1=+n},${this._y1=+r}`}bezierCurveTo(e,t,n,r,i,a){this._append`C${+e},${+t},${+n},${+r},${this._x1=+i},${this._y1=+a}`}arcTo(e,t,n,r,i){if(e=+e,t=+t,n=+n,r=+r,i=+i,i<0)throw Error(`negative radius: ${i}`);let a=this._x1,o=this._y1,s=n-e,c=r-t,l=a-e,u=o-t,d=l*l+u*u;if(this._x1===null)this._append`M${this._x1=e},${this._y1=t}`;else if(d>hk){if(!(Math.abs(u*s-c*l)>hk)||!i)this._append`L${this._x1=e},${this._y1=t}`;else{let f=n-a,p=r-o,m=s*s+c*c,h=f*f+p*p,g=Math.sqrt(m),_=Math.sqrt(d),v=i*Math.tan((pk-Math.acos((m+d-h)/(2*g*_)))/2),y=v/_,b=v/g;Math.abs(y-1)>hk&&this._append`L${e+y*l},${t+y*u}`,this._append`A${i},${i},0,0,${+(u*f>l*p)},${this._x1=e+b*s},${this._y1=t+b*c}`}}}arc(e,t,n,r,i,a){if(e=+e,t=+t,n=+n,a=!!a,n<0)throw Error(`negative radius: ${n}`);let o=n*Math.cos(r),s=n*Math.sin(r),c=e+o,l=t+s,u=1^a,d=a?r-i:i-r;this._x1===null?this._append`M${c},${l}`:(Math.abs(this._x1-c)>hk||Math.abs(this._y1-l)>hk)&&this._append`L${c},${l}`,n&&(d<0&&(d=d%mk+mk),d>gk?this._append`A${n},${n},0,1,${u},${e-o},${t-s}A${n},${n},0,1,${u},${this._x1=c},${this._y1=l}`:d>hk&&this._append`A${n},${n},0,${+(d>=pk)},${u},${this._x1=e+n*Math.cos(i)},${this._y1=t+n*Math.sin(i)}`)}rect(e,t,n,r){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+t}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}};yk.prototype;function bk(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString(`en`).replace(/,/g,``):e.toString(10)}function xk(e,t){if(!isFinite(e)||e===0)return null;var n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf(`e`),r=e.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+e.slice(n+1)]}function Sk(e){return e=xk(Math.abs(e)),e?e[1]:NaN}function Ck(e,t){return function(n,r){for(var i=n.length,a=[],o=0,s=e[0],c=0;i>0&&s>0&&(c+s+1>r&&(s=Math.max(1,r-c)),a.push(n.substring(i-=s,i+s)),!((c+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(t)}}function wk(e){return function(t){return t.replace(/[0-9]/g,function(t){return e[+t]})}}var Tk=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Ek(e){if(!(t=Tk.exec(e)))throw Error(`invalid format: `+e);var t;return new Dk({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}Ek.prototype=Dk.prototype;function Dk(e){this.fill=e.fill===void 0?` `:e.fill+``,this.align=e.align===void 0?`>`:e.align+``,this.sign=e.sign===void 0?`-`:e.sign+``,this.symbol=e.symbol===void 0?``:e.symbol+``,this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?``:e.type+``}Dk.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?`0`:``)+(this.width===void 0?``:Math.max(1,this.width|0))+(this.comma?`,`:``)+(this.precision===void 0?``:`.`+Math.max(0,this.precision|0))+(this.trim?`~`:``)+this.type};function Ok(e){out:for(var t=e.length,n=1,r=-1,i;n<t;++n)switch(e[n]){case`.`:r=i=n;break;case`0`:r===0&&(r=n),i=n;break;default:if(!+e[n])break out;r>0&&(r=0)}return r>0?e.slice(0,r)+e.slice(i+1):e}var kk;function Ak(e,t){var n=xk(e,t);if(!n)return kk=void 0,e.toPrecision(t);var r=n[0],i=n[1],a=i-(kk=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,o=r.length;return a===o?r:a>o?r+Array(a-o+1).join(`0`):a>0?r.slice(0,a)+`.`+r.slice(a):`0.`+Array(1-a).join(`0`)+xk(e,Math.max(0,t+a-1))[0]}function jk(e,t){var n=xk(e,t);if(!n)return e+``;var r=n[0],i=n[1];return i<0?`0.`+Array(-i).join(`0`)+r:r.length>i+1?r.slice(0,i+1)+`.`+r.slice(i+1):r+Array(i-r.length+2).join(`0`)}var Mk={"%":(e,t)=>(e*100).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+``,d:bk,e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>jk(e*100,t),r:jk,s:Ak,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Nk(e){return e}var Pk=Array.prototype.map,Fk=[`y`,`z`,`a`,`f`,`p`,`n`,`µ`,`m`,``,`k`,`M`,`G`,`T`,`P`,`E`,`Z`,`Y`];function Ik(e){var t=e.grouping===void 0||e.thousands===void 0?Nk:Ck(Pk.call(e.grouping,Number),e.thousands+``),n=e.currency===void 0?``:e.currency[0]+``,r=e.currency===void 0?``:e.currency[1]+``,i=e.decimal===void 0?`.`:e.decimal+``,a=e.numerals===void 0?Nk:wk(Pk.call(e.numerals,String)),o=e.percent===void 0?`%`:e.percent+``,s=e.minus===void 0?`−`:e.minus+``,c=e.nan===void 0?`NaN`:e.nan+``;function l(e,l){e=Ek(e);var u=e.fill,d=e.align,f=e.sign,p=e.symbol,m=e.zero,h=e.width,g=e.comma,_=e.precision,v=e.trim,y=e.type;y===`n`?(g=!0,y=`g`):Mk[y]||(_===void 0&&(_=12),v=!0,y=`g`),(m||u===`0`&&d===`=`)&&(m=!0,u=`0`,d=`=`);var b=(l&&l.prefix!==void 0?l.prefix:``)+(p===`$`?n:p===`#`&&/[boxX]/.test(y)?`0`+y.toLowerCase():``),x=(p===`$`?r:/[%p]/.test(y)?o:``)+(l&&l.suffix!==void 0?l.suffix:``),S=Mk[y],C=/[defgprs%]/.test(y);_=_===void 0?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,_)):Math.max(0,Math.min(20,_));function w(e){var n=b,r=x,o,l,p;if(y===`c`)r=S(e)+r,e=``;else{e=+e;var w=e<0||1/e<0;if(e=isNaN(e)?c:S(Math.abs(e),_),v&&(e=Ok(e)),w&&+e==0&&f!==`+`&&(w=!1),n=(w?f===`(`?f:s:f===`-`||f===`(`?``:f)+n,r=(y===`s`&&!isNaN(e)&&kk!==void 0?Fk[8+kk/3]:``)+r+(w&&f===`(`?`)`:``),C){for(o=-1,l=e.length;++o<l;)if(p=e.charCodeAt(o),48>p||p>57){r=(p===46?i+e.slice(o+1):e.slice(o))+r,e=e.slice(0,o);break}}}g&&!m&&(e=t(e,1/0));var T=n.length+e.length+r.length,E=T<h?Array(h-T+1).join(u):``;switch(g&&m&&(e=t(E+e,E.length?h-r.length:1/0),E=``),d){case`<`:e=n+e+r+E;break;case`=`:e=n+E+e+r;break;case`^`:e=E.slice(0,T=E.length>>1)+n+e+r+E.slice(T);break;default:e=E+n+e+r}return a(e)}return w.toString=function(){return e+``},w}function u(e,t){var n=Math.max(-8,Math.min(8,Math.floor(Sk(t)/3)))*3,r=10**-n,i=l((e=Ek(e),e.type=`f`,e),{suffix:Fk[8+n/3]});return function(e){return i(r*e)}}return{format:l,formatPrefix:u}}var Lk,Rk,zk;Bk({thousands:`,`,grouping:[3],currency:[`$`,``]});function Bk(e){return Lk=Ik(e),Rk=Lk.format,zk=Lk.formatPrefix,Lk}function Vk(e){return Math.max(0,-Sk(Math.abs(e)))}function Hk(e,t){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Sk(t)/3)))*3-Sk(Math.abs(e)))}function Uk(e,t){return e=Math.abs(e),t=Math.abs(t)-e,Math.max(0,Sk(t)-Sk(e))+1}function Wk(e){var t=0,n=e.children,r=n&&n.length;if(!r)t=1;else for(;--r>=0;)t+=n[r].value;e.value=t}function Gk(){return this.eachAfter(Wk)}function Kk(e,t){let n=-1;for(let r of this)e.call(t,r,++n,this);return this}function qk(e,t){for(var n=this,r=[n],i,a,o=-1;n=r.pop();)if(e.call(t,n,++o,this),i=n.children)for(a=i.length-1;a>=0;--a)r.push(i[a]);return this}function Jk(e,t){for(var n=this,r=[n],i=[],a,o,s,c=-1;n=r.pop();)if(i.push(n),a=n.children)for(o=0,s=a.length;o<s;++o)r.push(a[o]);for(;n=i.pop();)e.call(t,n,++c,this);return this}function Yk(e,t){let n=-1;for(let r of this)if(e.call(t,r,++n,this))return r}function Xk(e){return this.eachAfter(function(t){for(var n=+e(t.data)||0,r=t.children,i=r&&r.length;--i>=0;)n+=r[i].value;t.value=n})}function Zk(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function Qk(e){for(var t=this,n=$k(t,e),r=[t];t!==n;)t=t.parent,r.push(t);for(var i=r.length;e!==n;)r.splice(i,0,e),e=e.parent;return r}function $k(e,t){if(e===t)return e;var n=e.ancestors(),r=t.ancestors(),i=null;for(e=n.pop(),t=r.pop();e===t;)i=e,e=n.pop(),t=r.pop();return i}function eA(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function tA(){return Array.from(this)}function nA(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function rA(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*iA(){var e=this,t,n=[e],r,i,a;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,r=e.children)for(i=0,a=r.length;i<a;++i)n.push(r[i]);while(n.length)}function aA(e,t){e instanceof Map?(e=[void 0,e],t===void 0&&(t=cA)):t===void 0&&(t=sA);for(var n=new dA(e),r,i=[n],a,o,s,c;r=i.pop();)if((o=t(r.data))&&(c=(o=Array.from(o)).length))for(r.children=o,s=c-1;s>=0;--s)i.push(a=o[s]=new dA(o[s])),a.parent=r,a.depth=r.depth+1;return n.eachBefore(uA)}function oA(){return aA(this).eachBefore(lA)}function sA(e){return e.children}function cA(e){return Array.isArray(e)?e[1]:null}function lA(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function uA(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function dA(e){this.data=e,this.depth=this.height=0,this.parent=null}dA.prototype=aA.prototype={constructor:dA,count:Gk,each:Kk,eachAfter:Jk,eachBefore:qk,find:Yk,sum:Xk,sort:Zk,path:Qk,ancestors:eA,descendants:tA,leaves:nA,links:rA,copy:oA,[Symbol.iterator]:iA};function fA(e){e.x0=Math.round(e.x0),e.y0=Math.round(e.y0),e.x1=Math.round(e.x1),e.y1=Math.round(e.y1)}function pA(e,t,n,r,i){for(var a=e.children,o,s=-1,c=a.length,l=e.value&&(r-t)/e.value;++s<c;)o=a[s],o.y0=n,o.y1=i,o.x0=t,o.x1=t+=o.value*l}function mA(){var e=1,t=1,n=0,r=!1;function i(i){var o=i.height+1;return i.x0=i.y0=n,i.x1=e,i.y1=t/o,i.eachBefore(a(t,o)),r&&i.eachBefore(fA),i}function a(e,t){return function(r){r.children&&pA(r,r.x0,e*(r.depth+1)/t,r.x1,e*(r.depth+2)/t);var i=r.x0,a=r.y0,o=r.x1-n,s=r.y1-n;o<i&&(i=o=(i+o)/2),s<a&&(a=s=(a+s)/2),r.x0=i,r.y0=a,r.x1=o,r.y1=s}}return i.round=function(e){return arguments.length?(r=!!e,i):r},i.size=function(n){return arguments.length?(e=+n[0],t=+n[1],i):[e,t]},i.padding=function(e){return arguments.length?(n=+e,i):n},i}function hA(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e)}return this}var gA=Symbol(`implicit`);function _A(){var e=new MC,t=[],n=[],r=gA;function i(i){let a=e.get(i);if(a===void 0){if(r!==gA)return r;e.set(i,a=t.push(i)-1)}return n[a%n.length]}return i.domain=function(n){if(!arguments.length)return t.slice();t=[],e=new MC;for(let r of n)e.has(r)||e.set(r,t.push(r)-1);return i},i.range=function(e){return arguments.length?(n=Array.from(e),i):n.slice()},i.unknown=function(e){return arguments.length?(r=e,i):r},i.copy=function(){return _A(t,n).unknown(r)},hA.apply(i,arguments),i}function vA(){var e=_A().unknown(void 0),t=e.domain,n=e.range,r=0,i=1,a,o,s=!1,c=0,l=0,u=.5;delete e.unknown;function d(){var e=t().length,d=i<r,f=d?i:r,p=d?r:i;a=(p-f)/Math.max(1,e-c+l*2),s&&(a=Math.floor(a)),f+=(p-f-a*(e-c))*u,o=a*(1-c),s&&(f=Math.round(f),o=Math.round(o));var m=GC(e).map(function(e){return f+a*e});return n(d?m.reverse():m)}return e.domain=function(e){return arguments.length?(t(e),d()):t()},e.range=function(e){return arguments.length?([r,i]=e,r=+r,i=+i,d()):[r,i]},e.rangeRound=function(e){return[r,i]=e,r=+r,i=+i,s=!0,d()},e.bandwidth=function(){return o},e.step=function(){return a},e.round=function(e){return arguments.length?(s=!!e,d()):s},e.padding=function(e){return arguments.length?(c=Math.min(1,l=+e),d()):c},e.paddingInner=function(e){return arguments.length?(c=Math.min(1,e),d()):c},e.paddingOuter=function(e){return arguments.length?(l=+e,d()):l},e.align=function(e){return arguments.length?(u=Math.max(0,Math.min(1,e)),d()):u},e.copy=function(){return vA(t(),[r,i]).round(s).paddingInner(c).paddingOuter(l).align(u)},hA.apply(d(),arguments)}function yA(e){var t=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,delete e.paddingOuter,e.copy=function(){return yA(t())},e}function bA(){return yA(vA.apply(null,arguments).paddingInner(1))}function xA(e){return function(){return e}}function SA(e){return+e}var CA=[0,1];function wA(e){return e}function TA(e,t){return(t-=e=+e)?function(n){return(n-e)/t}:xA(isNaN(t)?NaN:.5)}function EA(e,t){var n;return e>t&&(n=e,e=t,t=n),function(n){return Math.max(e,Math.min(t,n))}}function DA(e,t,n){var r=e[0],i=e[1],a=t[0],o=t[1];return i<r?(r=TA(i,r),a=n(o,a)):(r=TA(r,i),a=n(a,o)),function(e){return a(r(e))}}function OA(e,t,n){var r=Math.min(e.length,t.length)-1,i=Array(r),a=Array(r),o=-1;for(e[r]<e[0]&&(e=e.slice().reverse(),t=t.slice().reverse());++o<r;)i[o]=TA(e[o],e[o+1]),a[o]=n(t[o],t[o+1]);return function(t){var n=AC(e,t,1,r)-1;return a[n](i[n](t))}}function kA(e,t){return t.domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown())}function AA(){var e=CA,t=CA,n=pD,r,i,a,o=wA,s,c,l;function u(){var n=Math.min(e.length,t.length);return o!==wA&&(o=EA(e[0],e[n-1])),s=n>2?OA:DA,c=l=null,d}function d(i){return i==null||isNaN(i=+i)?a:(c||=s(e.map(r),t,n))(r(o(i)))}return d.invert=function(n){return o(i((l||=s(t,e.map(r),oD))(n)))},d.domain=function(t){return arguments.length?(e=Array.from(t,SA),u()):e.slice()},d.range=function(e){return arguments.length?(t=Array.from(e),u()):t.slice()},d.rangeRound=function(e){return t=Array.from(e),n=mD,u()},d.clamp=function(e){return arguments.length?(o=e?!0:wA,u()):o!==wA},d.interpolate=function(e){return arguments.length?(n=e,u()):n},d.unknown=function(e){return arguments.length?(a=e,d):a},function(e,t){return r=e,i=t,u()}}function jA(){return AA()(wA,wA)}function MA(e,t,n,r){var i=UC(e,t,n),a;switch(r=Ek(r??`,f`),r.type){case`s`:var o=Math.max(Math.abs(e),Math.abs(t));return r.precision==null&&!isNaN(a=Hk(i,o))&&(r.precision=a),zk(r,o);case``:case`e`:case`g`:case`p`:case`r`:r.precision==null&&!isNaN(a=Uk(i,Math.max(Math.abs(e),Math.abs(t))))&&(r.precision=a-(r.type===`e`));break;case`f`:case`%`:r.precision==null&&!isNaN(a=Vk(i))&&(r.precision=a-(r.type===`%`)*2)}return Rk(r)}function NA(e){var t=e.domain;return e.ticks=function(e){var n=t();return VC(n[0],n[n.length-1],e??10)},e.tickFormat=function(e,n){var r=t();return MA(r[0],r[r.length-1],e??10,n)},e.nice=function(n){n??=10;var r=t(),i=0,a=r.length-1,o=r[i],s=r[a],c,l,u=10;for(s<o&&(l=o,o=s,s=l,l=i,i=a,a=l);u-->0;){if(l=HC(o,s,n),l===c)return r[i]=o,r[a]=s,t(r);if(l>0)o=Math.floor(o/l)*l,s=Math.ceil(s/l)*l;else if(l<0)o=Math.ceil(o*l)/l,s=Math.floor(s*l)/l;else break;c=l}return e},e}function PA(){var e=jA();return e.copy=function(){return kA(e,PA())},hA.apply(e,arguments),NA(e)}function FA(e,t){e=e.slice();var n=0,r=e.length-1,i=e[n],a=e[r],o;return a<i&&(o=n,n=r,r=o,o=i,i=a,a=o),e[n]=t.floor(i),e[r]=t.ceil(a),e}var IA=new Date,LA=new Date;function RA(e,t,n,r){function i(t){return e(t=arguments.length===0?new Date:new Date(+t)),t}return i.floor=t=>(e(t=new Date(+t)),t),i.ceil=n=>(e(n=new Date(n-1)),t(n,1),e(n),n),i.round=e=>{let t=i(e),n=i.ceil(e);return e-t<n-e?t:n},i.offset=(e,n)=>(t(e=new Date(+e),n==null?1:Math.floor(n)),e),i.range=(n,r,a)=>{let o=[];if(n=i.ceil(n),a=a==null?1:Math.floor(a),!(n<r)||!(a>0))return o;let s;do o.push(s=new Date(+n)),t(n,a),e(n);while(s<n&&n<r);return o},i.filter=n=>RA(t=>{if(t>=t)for(;e(t),!n(t);)t.setTime(t-1)},(e,r)=>{if(e>=e){if(r<0)for(;++r<=0;)for(;t(e,-1),!n(e););else for(;--r>=0;)for(;t(e,1),!n(e););}}),n&&(i.count=(t,r)=>(IA.setTime(+t),LA.setTime(+r),e(IA),e(LA),Math.floor(n(IA,LA))),i.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?i.filter(r?t=>r(t)%e===0:t=>i.count(0,t)%e===0):i)),i}var zA=RA(()=>{},(e,t)=>{e.setTime(+e+t)},(e,t)=>t-e);zA.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?RA(t=>{t.setTime(Math.floor(t/e)*e)},(t,n)=>{t.setTime(+t+n*e)},(t,n)=>(n-t)/e):zA),zA.range;var BA=1e3,VA=BA*60,HA=VA*60,UA=HA*24,WA=UA*7,GA=UA*30,KA=UA*365,qA=RA(e=>{e.setTime(e-e.getMilliseconds())},(e,t)=>{e.setTime(+e+t*BA)},(e,t)=>(t-e)/BA,e=>e.getUTCSeconds());qA.range;var JA=RA(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*BA)},(e,t)=>{e.setTime(+e+t*VA)},(e,t)=>(t-e)/VA,e=>e.getMinutes());JA.range;var YA=RA(e=>{e.setUTCSeconds(0,0)},(e,t)=>{e.setTime(+e+t*VA)},(e,t)=>(t-e)/VA,e=>e.getUTCMinutes());YA.range;var XA=RA(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*BA-e.getMinutes()*VA)},(e,t)=>{e.setTime(+e+t*HA)},(e,t)=>(t-e)/HA,e=>e.getHours());XA.range;var ZA=RA(e=>{e.setUTCMinutes(0,0,0)},(e,t)=>{e.setTime(+e+t*HA)},(e,t)=>(t-e)/HA,e=>e.getUTCHours());ZA.range;var QA=RA(e=>e.setHours(0,0,0,0),(e,t)=>e.setDate(e.getDate()+t),(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*VA)/UA,e=>e.getDate()-1);QA.range;var $A=RA(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/UA,e=>e.getUTCDate()-1);$A.range;var ej=RA(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/UA,e=>Math.floor(e/UA));ej.range;function tj(e){return RA(t=>{t.setDate(t.getDate()-(t.getDay()+7-e)%7),t.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*VA)/WA)}var nj=tj(0),rj=tj(1),ij=tj(2),aj=tj(3),oj=tj(4),sj=tj(5),cj=tj(6);nj.range,rj.range,ij.range,aj.range,oj.range,sj.range,cj.range;function lj(e){return RA(t=>{t.setUTCDate(t.getUTCDate()-(t.getUTCDay()+7-e)%7),t.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/WA)}var uj=lj(0),dj=lj(1),fj=lj(2),pj=lj(3),mj=lj(4),hj=lj(5),gj=lj(6);uj.range,dj.range,fj.range,pj.range,mj.range,hj.range,gj.range;var _j=RA(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,t)=>{e.setMonth(e.getMonth()+t)},(e,t)=>t.getMonth()-e.getMonth()+(t.getFullYear()-e.getFullYear())*12,e=>e.getMonth());_j.range;var vj=RA(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCMonth(e.getUTCMonth()+t)},(e,t)=>t.getUTCMonth()-e.getUTCMonth()+(t.getUTCFullYear()-e.getUTCFullYear())*12,e=>e.getUTCMonth());vj.range;var yj=RA(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t)},(e,t)=>t.getFullYear()-e.getFullYear(),e=>e.getFullYear());yj.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:RA(t=>{t.setFullYear(Math.floor(t.getFullYear()/e)*e),t.setMonth(0,1),t.setHours(0,0,0,0)},(t,n)=>{t.setFullYear(t.getFullYear()+n*e)}),yj.range;var bj=RA(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t)},(e,t)=>t.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());bj.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:RA(t=>{t.setUTCFullYear(Math.floor(t.getUTCFullYear()/e)*e),t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCFullYear(t.getUTCFullYear()+n*e)}),bj.range;function xj(e,t,n,r,i,a){let o=[[qA,1,BA],[qA,5,5*BA],[qA,15,15*BA],[qA,30,30*BA],[a,1,VA],[a,5,5*VA],[a,15,15*VA],[a,30,30*VA],[i,1,HA],[i,3,3*HA],[i,6,6*HA],[i,12,12*HA],[r,1,UA],[r,2,2*UA],[n,1,WA],[t,1,GA],[t,3,3*GA],[e,1,KA]];function s(e,t,n){let r=t<e;r&&([e,t]=[t,e]);let i=n&&typeof n.range==`function`?n:c(e,t,n),a=i?i.range(e,+t+1):[];return r?a.reverse():a}function c(t,n,r){let i=Math.abs(n-t)/r,a=EC(([,,e])=>e).right(o,i);if(a===o.length)return e.every(UC(t/KA,n/KA,r));if(a===0)return zA.every(Math.max(UC(t,n,r),1));let[s,c]=o[i/o[a-1][2]<o[a][2]/i?a-1:a];return s.every(c)}return[s,c]}var[Sj,Cj]=xj(bj,vj,uj,ej,ZA,YA),[wj,Tj]=xj(yj,_j,nj,QA,XA,JA);function Ej(e){if(0<=e.y&&e.y<100){var t=new Date(-1,e.m,e.d,e.H,e.M,e.S,e.L);return t.setFullYear(e.y),t}return new Date(e.y,e.m,e.d,e.H,e.M,e.S,e.L)}function Dj(e){if(0<=e.y&&e.y<100){var t=new Date(Date.UTC(-1,e.m,e.d,e.H,e.M,e.S,e.L));return t.setUTCFullYear(e.y),t}return new Date(Date.UTC(e.y,e.m,e.d,e.H,e.M,e.S,e.L))}function Oj(e,t,n){return{y:e,m:t,d:n,H:0,M:0,S:0,L:0}}function kj(e){var t=e.dateTime,n=e.date,r=e.time,i=e.periods,a=e.days,o=e.shortDays,s=e.months,c=e.shortMonths,l=Fj(i),u=Ij(i),d=Fj(a),f=Ij(a),p=Fj(o),m=Ij(o),h=Fj(s),g=Ij(s),_=Fj(c),v=Ij(c),y={a:N,A:P,b:F,B:ee,c:null,d:rM,e:rM,f:cM,g:yM,G:xM,H:iM,I:aM,j:oM,L:sM,m:lM,M:uM,p:te,q:I,Q:WM,s:GM,S:dM,u:fM,U:pM,V:hM,w:gM,W:_M,x:null,X:null,y:vM,Y:bM,Z:SM,"%":UM},b={a:L,A:R,b:ne,B:z,c:null,d:CM,e:CM,f:OM,g:zM,G:VM,H:wM,I:TM,j:EM,L:DM,m:kM,M:AM,p:re,q:B,Q:WM,s:GM,S:jM,u:MM,U:NM,V:FM,w:IM,W:LM,x:null,X:null,y:RM,Y:BM,Z:HM,"%":UM},x={a:E,A:D,b:O,B:k,c:A,d:qj,e:qj,f:$j,g:Uj,G:Hj,H:Yj,I:Yj,j:Jj,L:Qj,m:Kj,M:Xj,p:T,q:Gj,Q:tM,s:nM,S:Zj,u:Rj,U:zj,V:Bj,w:Lj,W:Vj,x:j,X:M,y:Uj,Y:Hj,Z:Wj,"%":eM};y.x=S(n,y),y.X=S(r,y),y.c=S(t,y),b.x=S(n,b),b.X=S(r,b),b.c=S(t,b);function S(e,t){return function(n){var r=[],i=-1,a=0,o=e.length,s,c,l;for(n instanceof Date||(n=new Date(+n));++i<o;)e.charCodeAt(i)===37&&(r.push(e.slice(a,i)),(c=Aj[s=e.charAt(++i)])==null?c=s===`e`?` `:`0`:s=e.charAt(++i),(l=t[s])&&(s=l(n,c)),r.push(s),a=i+1);return r.push(e.slice(a,i)),r.join(``)}}function C(e,t){return function(n){var r=Oj(1900,void 0,1),i=w(r,e,n+=``,0),a,o;if(i!=n.length)return null;if(`Q`in r)return new Date(r.Q);if(`s`in r)return new Date(r.s*1e3+(`L`in r?r.L:0));if(t&&!(`Z`in r)&&(r.Z=0),`p`in r&&(r.H=r.H%12+r.p*12),r.m===void 0&&(r.m=`q`in r?r.q:0),`V`in r){if(r.V<1||r.V>53)return null;`w`in r||(r.w=1),`Z`in r?(a=Dj(Oj(r.y,0,1)),o=a.getUTCDay(),a=o>4||o===0?dj.ceil(a):dj(a),a=$A.offset(a,(r.V-1)*7),r.y=a.getUTCFullYear(),r.m=a.getUTCMonth(),r.d=a.getUTCDate()+(r.w+6)%7):(a=Ej(Oj(r.y,0,1)),o=a.getDay(),a=o>4||o===0?rj.ceil(a):rj(a),a=QA.offset(a,(r.V-1)*7),r.y=a.getFullYear(),r.m=a.getMonth(),r.d=a.getDate()+(r.w+6)%7)}else(`W`in r||`U`in r)&&(`w`in r||(r.w=`u`in r?r.u%7:+(`W`in r)),o=`Z`in r?Dj(Oj(r.y,0,1)).getUTCDay():Ej(Oj(r.y,0,1)).getDay(),r.m=0,r.d=`W`in r?(r.w+6)%7+r.W*7-(o+5)%7:r.w+r.U*7-(o+6)%7);return`Z`in r?(r.H+=r.Z/100|0,r.M+=r.Z%100,Dj(r)):Ej(r)}}function w(e,t,n,r){for(var i=0,a=t.length,o=n.length,s,c;i<a;){if(r>=o)return-1;if(s=t.charCodeAt(i++),s===37){if(s=t.charAt(i++),c=x[s in Aj?t.charAt(i++):s],!c||(r=c(e,n,r))<0)return-1}else if(s!=n.charCodeAt(r++))return-1}return r}function T(e,t,n){var r=l.exec(t.slice(n));return r?(e.p=u.get(r[0].toLowerCase()),n+r[0].length):-1}function E(e,t,n){var r=p.exec(t.slice(n));return r?(e.w=m.get(r[0].toLowerCase()),n+r[0].length):-1}function D(e,t,n){var r=d.exec(t.slice(n));return r?(e.w=f.get(r[0].toLowerCase()),n+r[0].length):-1}function O(e,t,n){var r=_.exec(t.slice(n));return r?(e.m=v.get(r[0].toLowerCase()),n+r[0].length):-1}function k(e,t,n){var r=h.exec(t.slice(n));return r?(e.m=g.get(r[0].toLowerCase()),n+r[0].length):-1}function A(e,n,r){return w(e,t,n,r)}function j(e,t,r){return w(e,n,t,r)}function M(e,t,n){return w(e,r,t,n)}function N(e){return o[e.getDay()]}function P(e){return a[e.getDay()]}function F(e){return c[e.getMonth()]}function ee(e){return s[e.getMonth()]}function te(e){return i[+(e.getHours()>=12)]}function I(e){return 1+~~(e.getMonth()/3)}function L(e){return o[e.getUTCDay()]}function R(e){return a[e.getUTCDay()]}function ne(e){return c[e.getUTCMonth()]}function z(e){return s[e.getUTCMonth()]}function re(e){return i[+(e.getUTCHours()>=12)]}function B(e){return 1+~~(e.getUTCMonth()/3)}return{format:function(e){var t=S(e+=``,y);return t.toString=function(){return e},t},parse:function(e){var t=C(e+=``,!1);return t.toString=function(){return e},t},utcFormat:function(e){var t=S(e+=``,b);return t.toString=function(){return e},t},utcParse:function(e){var t=C(e+=``,!0);return t.toString=function(){return e},t}}}var Aj={"-":``,_:` `,0:`0`},jj=/^\s*\d+/,Mj=/^%/,Nj=/[\\^$*+?|[\]().{}]/g;function Z(e,t,n){var r=e<0?`-`:``,i=(r?-e:e)+``,a=i.length;return r+(a<n?Array(n-a+1).join(t)+i:i)}function Pj(e){return e.replace(Nj,`\\$&`)}function Fj(e){return RegExp(`^(?:`+e.map(Pj).join(`|`)+`)`,`i`)}function Ij(e){return new Map(e.map((e,t)=>[e.toLowerCase(),t]))}function Lj(e,t,n){var r=jj.exec(t.slice(n,n+1));return r?(e.w=+r[0],n+r[0].length):-1}function Rj(e,t,n){var r=jj.exec(t.slice(n,n+1));return r?(e.u=+r[0],n+r[0].length):-1}function zj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.U=+r[0],n+r[0].length):-1}function Bj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.V=+r[0],n+r[0].length):-1}function Vj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.W=+r[0],n+r[0].length):-1}function Hj(e,t,n){var r=jj.exec(t.slice(n,n+4));return r?(e.y=+r[0],n+r[0].length):-1}function Uj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function Wj(e,t,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(t.slice(n,n+6));return r?(e.Z=r[1]?0:-(r[2]+(r[3]||`00`)),n+r[0].length):-1}function Gj(e,t,n){var r=jj.exec(t.slice(n,n+1));return r?(e.q=r[0]*3-3,n+r[0].length):-1}function Kj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.m=r[0]-1,n+r[0].length):-1}function qj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.d=+r[0],n+r[0].length):-1}function Jj(e,t,n){var r=jj.exec(t.slice(n,n+3));return r?(e.m=0,e.d=+r[0],n+r[0].length):-1}function Yj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.H=+r[0],n+r[0].length):-1}function Xj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.M=+r[0],n+r[0].length):-1}function Zj(e,t,n){var r=jj.exec(t.slice(n,n+2));return r?(e.S=+r[0],n+r[0].length):-1}function Qj(e,t,n){var r=jj.exec(t.slice(n,n+3));return r?(e.L=+r[0],n+r[0].length):-1}function $j(e,t,n){var r=jj.exec(t.slice(n,n+6));return r?(e.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function eM(e,t,n){var r=Mj.exec(t.slice(n,n+1));return r?n+r[0].length:-1}function tM(e,t,n){var r=jj.exec(t.slice(n));return r?(e.Q=+r[0],n+r[0].length):-1}function nM(e,t,n){var r=jj.exec(t.slice(n));return r?(e.s=+r[0],n+r[0].length):-1}function rM(e,t){return Z(e.getDate(),t,2)}function iM(e,t){return Z(e.getHours(),t,2)}function aM(e,t){return Z(e.getHours()%12||12,t,2)}function oM(e,t){return Z(1+QA.count(yj(e),e),t,3)}function sM(e,t){return Z(e.getMilliseconds(),t,3)}function cM(e,t){return sM(e,t)+`000`}function lM(e,t){return Z(e.getMonth()+1,t,2)}function uM(e,t){return Z(e.getMinutes(),t,2)}function dM(e,t){return Z(e.getSeconds(),t,2)}function fM(e){var t=e.getDay();return t===0?7:t}function pM(e,t){return Z(nj.count(yj(e)-1,e),t,2)}function mM(e){var t=e.getDay();return t>=4||t===0?oj(e):oj.ceil(e)}function hM(e,t){return e=mM(e),Z(oj.count(yj(e),e)+(yj(e).getDay()===4),t,2)}function gM(e){return e.getDay()}function _M(e,t){return Z(rj.count(yj(e)-1,e),t,2)}function vM(e,t){return Z(e.getFullYear()%100,t,2)}function yM(e,t){return e=mM(e),Z(e.getFullYear()%100,t,2)}function bM(e,t){return Z(e.getFullYear()%1e4,t,4)}function xM(e,t){var n=e.getDay();return e=n>=4||n===0?oj(e):oj.ceil(e),Z(e.getFullYear()%1e4,t,4)}function SM(e){var t=e.getTimezoneOffset();return(t>0?`-`:(t*=-1,`+`))+Z(t/60|0,`0`,2)+Z(t%60,`0`,2)}function CM(e,t){return Z(e.getUTCDate(),t,2)}function wM(e,t){return Z(e.getUTCHours(),t,2)}function TM(e,t){return Z(e.getUTCHours()%12||12,t,2)}function EM(e,t){return Z(1+$A.count(bj(e),e),t,3)}function DM(e,t){return Z(e.getUTCMilliseconds(),t,3)}function OM(e,t){return DM(e,t)+`000`}function kM(e,t){return Z(e.getUTCMonth()+1,t,2)}function AM(e,t){return Z(e.getUTCMinutes(),t,2)}function jM(e,t){return Z(e.getUTCSeconds(),t,2)}function MM(e){var t=e.getUTCDay();return t===0?7:t}function NM(e,t){return Z(uj.count(bj(e)-1,e),t,2)}function PM(e){var t=e.getUTCDay();return t>=4||t===0?mj(e):mj.ceil(e)}function FM(e,t){return e=PM(e),Z(mj.count(bj(e),e)+(bj(e).getUTCDay()===4),t,2)}function IM(e){return e.getUTCDay()}function LM(e,t){return Z(dj.count(bj(e)-1,e),t,2)}function RM(e,t){return Z(e.getUTCFullYear()%100,t,2)}function zM(e,t){return e=PM(e),Z(e.getUTCFullYear()%100,t,2)}function BM(e,t){return Z(e.getUTCFullYear()%1e4,t,4)}function VM(e,t){var n=e.getUTCDay();return e=n>=4||n===0?mj(e):mj.ceil(e),Z(e.getUTCFullYear()%1e4,t,4)}function HM(){return`+0000`}function UM(){return`%`}function WM(e){return+e}function GM(e){return Math.floor(e/1e3)}var KM,qM;JM({dateTime:`%x, %X`,date:`%-m/%-d/%Y`,time:`%-I:%M:%S %p`,periods:[`AM`,`PM`],days:[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],shortDays:[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],months:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],shortMonths:[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`]});function JM(e){return KM=kj(e),qM=KM.format,KM.parse,KM.utcFormat,KM.utcParse,KM}function YM(e){return new Date(e)}function XM(e){return e instanceof Date?+e:+new Date(+e)}function ZM(e,t,n,r,i,a,o,s,c,l){var u=jA(),d=u.invert,f=u.domain,p=l(`.%L`),m=l(`:%S`),h=l(`%I:%M`),g=l(`%I %p`),_=l(`%a %d`),v=l(`%b %d`),y=l(`%B`),b=l(`%Y`);function x(e){return(c(e)<e?p:s(e)<e?m:o(e)<e?h:a(e)<e?g:r(e)<e?i(e)<e?_:v:n(e)<e?y:b)(e)}return u.invert=function(e){return new Date(d(e))},u.domain=function(e){return arguments.length?f(Array.from(e,XM)):f().map(YM)},u.ticks=function(t){var n=f();return e(n[0],n[n.length-1],t??10)},u.tickFormat=function(e,t){return t==null?x:l(t)},u.nice=function(e){var n=f();return(!e||typeof e.range!=`function`)&&(e=t(n[0],n[n.length-1],e??10)),e?f(FA(n,e)):u},u.copy=function(){return kA(u,ZM(e,t,n,r,i,a,o,s,c,l))},u}function QM(){return hA.apply(ZM(wj,Tj,yj,_j,nj,QA,XA,JA,qA,qM).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}function $M(e){return function(){return e}}var eN=Math.abs,tN=Math.atan2,nN=Math.cos,rN=Math.max,iN=Math.min,aN=Math.sin,oN=Math.sqrt,sN=Math.PI,cN=sN/2,lN=2*sN;function uN(e){return e>1?0:e<-1?sN:Math.acos(e)}function dN(e){return e>=1?cN:e<=-1?-cN:Math.asin(e)}function fN(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{let e=Math.floor(n);if(!(e>=0))throw RangeError(`invalid digits: ${n}`);t=e}return e},()=>new yk(t)}function pN(e){return e.innerRadius}function mN(e){return e.outerRadius}function hN(e){return e.startAngle}function gN(e){return e.endAngle}function _N(e){return e&&e.padAngle}function vN(e,t,n,r,i,a,o,s){var c=n-e,l=r-t,u=o-i,d=s-a,f=d*c-u*l;if(!(f*f<1e-12))return f=(u*(t-a)-d*(e-i))/f,[e+f*c,t+f*l]}function yN(e,t,n,r,i,a,o){var s=e-n,c=t-r,l=(o?a:-a)/oN(s*s+c*c),u=l*c,d=-l*s,f=e+u,p=t+d,m=n+u,h=r+d,g=(f+m)/2,_=(p+h)/2,v=m-f,y=h-p,b=v*v+y*y,x=i-a,S=f*h-m*p,C=(y<0?-1:1)*oN(rN(0,x*x*b-S*S)),w=(S*y-v*C)/b,T=(-S*v-y*C)/b,E=(S*y+v*C)/b,D=(-S*v+y*C)/b,O=w-g,k=T-_,A=E-g,j=D-_;return O*O+k*k>A*A+j*j&&(w=E,T=D),{cx:w,cy:T,x01:-u,y01:-d,x11:w*(i/x-1),y11:T*(i/x-1)}}function bN(){var e=pN,t=mN,n=$M(0),r=null,i=hN,a=gN,o=_N,s=null,c=fN(l);function l(){var l,u,d=+e.apply(this,arguments),f=+t.apply(this,arguments),p=i.apply(this,arguments)-cN,m=a.apply(this,arguments)-cN,h=eN(m-p),g=m>p;if(s||=l=c(),f<d&&(u=f,f=d,d=u),!(f>1e-12))s.moveTo(0,0);else if(h>lN-1e-12)s.moveTo(f*nN(p),f*aN(p)),s.arc(0,0,f,p,m,!g),d>1e-12&&(s.moveTo(d*nN(m),d*aN(m)),s.arc(0,0,d,m,p,g));else{var _=p,v=m,y=p,b=m,x=h,S=h,C=o.apply(this,arguments)/2,w=C>1e-12&&(r?+r.apply(this,arguments):oN(d*d+f*f)),T=iN(eN(f-d)/2,+n.apply(this,arguments)),E=T,D=T,O,k;if(w>1e-12){var A=dN(w/d*aN(C)),j=dN(w/f*aN(C));(x-=A*2)>1e-12?(A*=g?1:-1,y+=A,b-=A):(x=0,y=b=(p+m)/2),(S-=j*2)>1e-12?(j*=g?1:-1,_+=j,v-=j):(S=0,_=v=(p+m)/2)}var M=f*nN(_),N=f*aN(_),P=d*nN(b),F=d*aN(b);if(T>1e-12){var ee=f*nN(v),te=f*aN(v),I=d*nN(y),L=d*aN(y),R;if(h<sN){if(R=vN(M,N,I,L,ee,te,P,F)){var ne=M-R[0],z=N-R[1],re=ee-R[0],B=te-R[1],ie=1/aN(uN((ne*re+z*B)/(oN(ne*ne+z*z)*oN(re*re+B*B)))/2),ae=oN(R[0]*R[0]+R[1]*R[1]);E=iN(T,(d-ae)/(ie-1)),D=iN(T,(f-ae)/(ie+1))}else E=D=0}}S>1e-12?D>1e-12?(O=yN(I,L,M,N,f,D,g),k=yN(ee,te,P,F,f,D,g),s.moveTo(O.cx+O.x01,O.cy+O.y01),D<T?s.arc(O.cx,O.cy,D,tN(O.y01,O.x01),tN(k.y01,k.x01),!g):(s.arc(O.cx,O.cy,D,tN(O.y01,O.x01),tN(O.y11,O.x11),!g),s.arc(0,0,f,tN(O.cy+O.y11,O.cx+O.x11),tN(k.cy+k.y11,k.cx+k.x11),!g),s.arc(k.cx,k.cy,D,tN(k.y11,k.x11),tN(k.y01,k.x01),!g))):(s.moveTo(M,N),s.arc(0,0,f,_,v,!g)):s.moveTo(M,N),!(d>1e-12)||!(x>1e-12)?s.lineTo(P,F):E>1e-12?(O=yN(P,F,ee,te,d,-E,g),k=yN(M,N,I,L,d,-E,g),s.lineTo(O.cx+O.x01,O.cy+O.y01),E<T?s.arc(O.cx,O.cy,E,tN(O.y01,O.x01),tN(k.y01,k.x01),!g):(s.arc(O.cx,O.cy,E,tN(O.y01,O.x01),tN(O.y11,O.x11),!g),s.arc(0,0,d,tN(O.cy+O.y11,O.cx+O.x11),tN(k.cy+k.y11,k.cx+k.x11),g),s.arc(k.cx,k.cy,E,tN(k.y11,k.x11),tN(k.y01,k.x01),!g))):s.arc(0,0,d,b,y,g)}if(s.closePath(),l)return s=null,l+``||null}return l.centroid=function(){var n=(+e.apply(this,arguments)+ +t.apply(this,arguments))/2,r=(+i.apply(this,arguments)+ +a.apply(this,arguments))/2-sN/2;return[nN(r)*n,aN(r)*n]},l.innerRadius=function(t){return arguments.length?(e=typeof t==`function`?t:$M(+t),l):e},l.outerRadius=function(e){return arguments.length?(t=typeof e==`function`?e:$M(+e),l):t},l.cornerRadius=function(e){return arguments.length?(n=typeof e==`function`?e:$M(+e),l):n},l.padRadius=function(e){return arguments.length?(r=e==null?null:typeof e==`function`?e:$M(+e),l):r},l.startAngle=function(e){return arguments.length?(i=typeof e==`function`?e:$M(+e),l):i},l.endAngle=function(e){return arguments.length?(a=typeof e==`function`?e:$M(+e),l):a},l.padAngle=function(e){return arguments.length?(o=typeof e==`function`?e:$M(+e),l):o},l.context=function(e){return arguments.length?(s=e??null,l):s},l}Array.prototype.slice;function xN(e){return typeof e==`object`&&`length`in e?e:Array.from(e)}function SN(e){this._context=e}SN.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t)}}};function CN(e){return new SN(e)}function wN(e){return e[0]}function TN(e){return e[1]}function EN(e,t){var n=$M(!0),r=null,i=CN,a=null,o=fN(s);e=typeof e==`function`?e:e===void 0?wN:$M(e),t=typeof t==`function`?t:t===void 0?TN:$M(t);function s(s){var c,l=(s=xN(s)).length,u,d=!1,f;for(r??(a=i(f=o())),c=0;c<=l;++c)!(c<l&&n(u=s[c],c,s))===d&&((d=!d)?a.lineStart():a.lineEnd()),d&&a.point(+e(u,c,s),+t(u,c,s));if(f)return a=null,f+``||null}return s.x=function(t){return arguments.length?(e=typeof t==`function`?t:$M(+t),s):e},s.y=function(e){return arguments.length?(t=typeof e==`function`?e:$M(+e),s):t},s.defined=function(e){return arguments.length?(n=typeof e==`function`?e:$M(!!e),s):n},s.curve=function(e){return arguments.length?(i=e,r!=null&&(a=i(r)),s):i},s.context=function(e){return arguments.length?(e==null?r=a=null:a=i(r=e),s):r},s}function DN(e,t){this._context=e,this._t=t}DN.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&this._point===2&&this._context.lineTo(this._x,this._y),(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}}this._x=e,this._y=t}};function ON(e){return new DN(e,1)}function kN(e,t,n){this.k=e,this.x=t,this.y=n}kN.prototype={constructor:kN,scale:function(e){return e===1?this:new kN(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new kN(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return`translate(`+this.x+`,`+this.y+`) scale(`+this.k+`)`}};var AN=new kN(1,0,0);jN.prototype=kN.prototype;function jN(e){for(;!e.__zoom;)if(!(e=e.parentNode))return AN;return e.__zoom}function MN(e,t=15){let n=e.split(` `),r=[],i=[],a=0;return n.forEach(e=>{a+e.length>t?(i.length&&r.push(i.join(` `)),i=[e],a=e.length):(i.push(e),a+=e.length+ +(i.length>0))}),i.length&&r.push(i.join(` `)),r}var NN={DECISIVE:20,ROUTINE:50},PN=new Set([`WALKOVER`,`DOUBLE_WALKOVER`,`DEFAULTED`,`DOUBLE_DEFAULT`]),FN={COMPETITIVE:`#16a34a`,ROUTINE:`#3b82f6`,DECISIVE:`#8e44ad`,WALKOVER:`#6b7280`},IN=`#cfd8dc`,LN=`COMPETITIVE`,RN=`ROUTINE`,zN=`DECISIVE`,BN=`WALKOVER`;function VN(e,t=NN){if(!e?.length)return;let n=[0,0],r=[0,0];for(let t of e)n[0]+=t.side1Score||0,n[1]+=t.side2Score||0,r[0]+=t.side1TiebreakScore||0,r[1]+=t.side2TiebreakScore||0;r[0]+r[1]&&(n[r[0]>r[1]?0:1]+=1);let i=Math.max(n[0],n[1]);if(i===0)return;let a=Math.round(Math.min(n[0],n[1])/i*100);return Number.isNaN(a)?BN:a<=t.DECISIVE?zN:a<=t.ROUTINE?RN:LN}function HN(e,n=NN){if(e)return VN(t.scoreGovernor.parseScoreString({scoreString:e}),n)}function UN({winningSide:e,matchUpStatus:t,sets:n,scoreString:r,bands:i}){if(t&&PN.has(t))return BN;if(e)return n?.length?VN(n,i):HN(r,i)}function WN(e,t){return e?t?.[e]??FN[e]:IN}var{WILDCARD:GN,QUALIFIER:KN,LUCKY_LOSER:qN}=t.entryStatusConstants,JN=`text-anchor`,YN=`dominant-baseline`,XN=`fill-opacity`,ZN=Object.assign({},...t.fixtures.countries.filter(e=>e.ioc).map(e=>({[e.ioc]:e.iso2})),...t.fixtures.countries.filter(e=>e.iso).map(e=>({[e.iso]:e.iso2})));function QN(e){let t=Math.floor(e.length/2),n=e.slice(0,t),r=e.slice(t).reverse();return[...n,...r]}function $N(e){if(e)switch(e){case GN:return`WC`;case KN:return`Q`;case qN:return`LL`;default:return e}}function eP(e,t){let n=[];for(let r of e)for(let e of r.sides){let i=r.matchUpStatus===`BYE`&&!e.participantName;n.push({name:e.participantName||(i?`BYE`:``),participantName:e.participantName||(i?`BYE`:void 0),drawPosition:e.drawPosition,seedNumber:e.seedNumber,entryStatus:$N(e.entryStatus),nationalityCode:e.nationalityCode,matchUp:r,depth:t,value:1})}return n}function tP(e,t){let n=e.winningSide!==void 0&&e.winningSide!==null?e.sides.find(t=>t.sideNumber===e.winningSide):void 0;!n&&e.matchUpStatus===`BYE`&&(n=e.sides.find(e=>e.participantName));let r=n?.participantName,i=r?t.get(r):void 0;return{winnerName:r,winnerSide:n,winnerLookup:i}}function nP(e,t,n,r){return e.map((e,i)=>{let a=i*2,o=[t[a],t[a+1]].filter(Boolean),{winnerName:s,winnerSide:c,winnerLookup:l}=tP(e,r);return{name:s||``,participantName:s,drawPosition:l?.drawPosition??c?.drawPosition,seedNumber:c?.seedNumber??l?.seedNumber,entryStatus:$N(c?.entryStatus)??l?.entryStatus,nationalityCode:c?.nationalityCode??l?.nationalityCode,scoreString:e.scoreString,matchUpStatus:e.matchUpStatus,competitiveness:e.competitiveness,matchUp:e,depth:n,children:o.length>0?o:void 0}})}function rP(e){let{roundMatchUps:t}=e,n=Object.keys(t).map(Number).sort((e,t)=>e-t);if(n.length===0)throw Error(`No round data found in draw`);let r=t[n[0]],i=QN(eP(r,n.length)),a=new Map;for(let e of i)e.participantName&&e.participantName!==`BYE`&&a.set(e.participantName,e);let o=nP(QN(r),i,n.length-1,a);for(let e=1;e<n.length;e++)o=nP(QN(t[n[e]]),o,n.length-1-e,a);return o.length===1?o[0]:{name:`Tournament`,depth:0,children:o}}function iP(e,t){if(!e)return;let{seedNumber:n,entryStatus:r,drawPosition:i,participantName:a}=e,o;if(a?.trim().toUpperCase()===`BYE`)o=`#B0BEC5`;else if(n){let e=Number(n),t=PA().domain([1,32]).range([`0`,`1`]);o=PA().domain(GC(0,1,1/7)).range([`#81D4FA`,`#42A5F5`,`#1E88E5`,`#1565C0`,`#5C6BC0`,`#673AB7`,`#9C27B0`])(Number(t(e)))}else if(r?.toUpperCase()===`WC`)o=`red`;else if(r&&(r===`Q`||r===`LL`))o=PA().domain(GC(0,1,1/3)).range([`#FFF176`,`#FBC02D`,`#FF9800`])(t(i));else{let e=[`#C8E6C9`,`#81C784`,`#66BB6A`,`#4CAF50`,`#43A047`,`#388E3C`,`#2E7D32`,`#1B5E20`,`#A5D6A7`,`#90CAF9`,`#64B5F6`,`#42A5F5`,`#2196F3`,`#1E88E5`,`#1976D2`,`#1565C0`];o=PA().domain(GC(0,1,1/e.length)).range(e)(t(i))}e.color=o,e.children&&e.children.forEach(n=>{n.participantName===e.participantName&&(n.color=o),iP(n,t)})}function aP(e,t){e&&(e.competitivenessColor=e.children?.length&&e.competitiveness?WN(e.competitiveness,t):IN,e.children?.forEach(e=>aP(e,t)))}function oP(e,t){let n=[];return e.seedNumber?n.push(`Seed ${e.seedNumber}`):e.entryStatus&&n.push(e.entryStatus),t===7&&e.drawPosition&&n.push(`Draw ${e.drawPosition}`),n.length>0?n.join(` • `):void 0}function sP(e,t){let n=e.find(e=>e.data.participantName&&e.data.participantName!==t);return n?.data.participantName?n.data:void 0}function cP(e,t){let n=[e.participantName],r;if(t.children&&t.children.length>0)e.scoreString&&n.push(e.scoreString),r=sP(t.children,e.participantName),r&&n.push(r.participantName);else{let r=oP(e,t.depth);r&&n.push(r)}return{messageLines:n,opponentData:r}}function lP(e,t){return-(e*t/2)+t/2}function uP(e,t,n){let r=uE(e).append(`svg`).attr(`width`,t).attr(`height`,n).style(`display`,`block`),i=r.append(`g`).attr(`transform`,`translate(${t/2}, ${n/2})`);return{svg:r,g:i,flagsGroup:i.append(`g`).attr(`class`,`flags-group`),winningFlagsGroup:i.append(`g`).attr(`class`,`winning-flags-group`),losingFlagsGroup:i.append(`g`).attr(`class`,`losing-flags-group`)}}function dP(e,t,n,r,i){let a=e.append(`text`).attr(`x`,t/2).attr(`y`,n/2).attr(JN,`middle`).attr(YN,`middle`).attr(`font-size`,`${r}px`).attr(`font-weight`,`bold`).style(`fill`,`var(--chc-text-primary, #333)`).attr(`pointer-events`,`none`),o=r+i*.5;return{centerText:a,centerText2:e.append(`text`).attr(`x`,t/2).attr(`y`,n/2+o).attr(JN,`middle`).attr(YN,`middle`).attr(`font-size`,`${i}px`).style(`fill`,`var(--chc-text-secondary, #666)`).attr(`pointer-events`,`none`)}}function fP(e,t,n,r,i,a,o){n&&(i?(t.flagsGroup.selectAll(`text`).remove(),t.winningFlagsGroup.selectAll(`text`).remove(),t.losingFlagsGroup.selectAll(`text`).remove()):e.selectAll(`text`).remove(),e.append(`text`).attr(`font-size`,`${o}px`).attr(JN,`middle`).attr(YN,`middle`).attr(`transform`,`translate(0, ${r*a})`).text(gP(n)))}function pP(e,n,r,i={}){let a=i.width||800,o=i.height||800,s=Math.min(a,o)/800*(i.textScaleFactor??1),c=28*s,l=24*s,u=30*s,d=r||i.title||`Tournament`,f=Object.assign({},...t.fixtures.countries.filter(e=>e.label).map(e=>({[e.ioc]:e.label})));if(!Object.keys(n?.roundMatchUps??{}).length)return{highlightPlayer:()=>0,hide:()=>void 0,setColorMode:()=>void 0};let p=rP(n),m=aA(p,e=>e.children).sum(e=>e.value||0),h=Math.min(a,o)/2,g=h/2,_=e=>e*h/200;mA().size([2*Math.PI,h-g])(m),iP(p,PA().domain([0,n.drawSize||128]).range([0,1])),aP(p,i.competitivenessColors);let v=i.colorMode??`default`,y=e=>v===`competitiveness`?e.competitivenessColor||`#cfd8dc`:e.color||`#ccc`,b=m.descendants(),x=bN().startAngle(e=>e.x0).endAngle(e=>e.x1).innerRadius(e=>e.y0+g).outerRadius(e=>e.y1+g),{svg:S,g:C,flagsGroup:w,winningFlagsGroup:T,losingFlagsGroup:E}=uP(e,a,o),D=new Set,O=e=>{e.nationalityCode&&D.add(e.nationalityCode),e.children&&e.children.forEach(O)};O(p);let k=Array.from(D),{centerText:A,centerText2:j}=dP(S,a,o,c,l);function M(){let e=MN(d,15);A.text(``),A.selectAll(`tspan`).remove(),j.text(``),j.selectAll(`tspan`).remove(),A.selectAll(`tspan`).data(e).join(`tspan`).attr(`x`,a/2).attr(`dy`,(e,t)=>t===0?0:u).text(e=>e);let t=-(e.length*u/2)+u/2;A.attr(`y`,o/2+t),A.style(`display`,`block`),j.style(`display`,`none`)}function N(){if(w.selectAll(`text`).remove(),T.selectAll(`text`).remove(),E.selectAll(`text`).remove(),k.length===0)return;let e=PA().domain([0,k.length]).range([0,Math.PI*2]),t=_(20),n=g-t+10;w.selectAll(`text`).data(k).join(`text`).attr(`font-size`,`${t}px`).attr(JN,`middle`).attr(YN,`middle`).attr(`transform`,(t,r)=>{let i=e(r);return`translate(${Math.cos(i)*n}, ${Math.sin(i)*n})`}).text(e=>gP(e)).style(`cursor`,`pointer`).on(`mouseover`,function(e,t){let n=f[t]||t;A.selectAll(`tspan`).remove(),A.attr(`y`,o/2),A.text(n).style(`display`,`block`),j.selectAll(`tspan`).remove(),j.text(``).style(`display`,`none`),F||C.selectAll(`path`).attr(XN,e=>e.data.nationalityCode===t?.9:.3)}).on(`mouseout`,function(){F||C.selectAll(`path`).attr(XN,.8),M()})}N(),M();let P=i.eventHandlers?.clickCenter;P&&C.insert(`circle`,`:first-child`).attr(`r`,g).attr(`fill`,`transparent`).style(`cursor`,`pointer`).on(`click`,P);let F=!1,ee;function te(e,t){let n=t.data;if(n.participantName){let{messageLines:e,opponentData:r}=cP(n,t);r&&(n.opponent=r),A.selectAll(`tspan`).remove(),A.text(``),A.selectAll(`tspan`).data(e).join(`tspan`).attr(`x`,a/2).attr(`dy`,(e,t)=>t===0?0:u).text(e=>e);let i=lP(e.length,u);A.attr(`y`,o/2+i),A.style(`display`,`block`),j.style(`display`,`none`)}F?n.participantName?.toLowerCase()!==ee?.toLowerCase()&&uE(e.currentTarget).attr(XN,.9):C.selectAll(`path`).attr(XN,e=>e.data.participantName===t.data.participantName?.9:.3);let r=_(30),i=g-r-10,s={flagsGroup:w,winningFlagsGroup:T,losingFlagsGroup:E};fP(T,s,n.nationalityCode,-1,!0,i,r),n.opponent&&fP(E,s,n.opponent.nationalityCode,1,!1,i,r)}function I(e,t){if(F){let n=t.data.participantName?.toLowerCase()===ee?.toLowerCase();uE(e.currentTarget).attr(XN,n?1:.2)}else C.selectAll(`path`).attr(XN,.8);N(),M()}let L=i.eventHandlers?.clickSegment;function R(e,t){if(!L)return;let n=t.data;L({participantName:n.participantName,drawPosition:n.drawPosition,seedNumber:n.seedNumber,entryStatus:n.entryStatus,nationalityCode:n.nationalityCode,scoreString:n.scoreString,matchUpStatus:n.matchUpStatus,competitiveness:n.competitiveness,roundName:n.roundName,depth:n.depth,matchUp:n.matchUp})}let ne=C.selectAll(`path`).data(b).join(`path`).attr(`d`,e=>x(e)).attr(`fill`,e=>y(e.data)).attr(XN,.8).attr(`stroke`,`#fff`).attr(`stroke-width`,1).on(`mouseover`,te).on(`mouseout`,I);L&&ne.style(`cursor`,`pointer`).on(`click`,R),ne.append(`title`).text(e=>{let t=e.data;if(t.participantName){let e=[t.participantName,`Draw: ${t.drawPosition||`N/A`}`];return t.competitiveness&&e.push(`Competitiveness: ${t.competitiveness}`),e.join(`
215
+ `)}return`${t.name}\nDepth: ${e.depth}`});function z(e){let t=0;return F=!!e,ee=e,C.selectAll(`path`).attr(XN,n=>e?n.data.participantName?.toLowerCase()===e.toLowerCase()?(t+=1,1):.2:.8),t}function re(e){S.style(`display`,e?`none`:`block`)}function B(e){v=e,C.selectAll(`path`).attr(`fill`,e=>y(e.data))}return{highlightPlayer:z,hide:re,setColorMode:B}}function mP(e={}){return{render:(t,n,r)=>pP(t,n,r,e)}}function hP(e){return e?.length===2?e&&String.fromCodePoint!==void 0?e.toUpperCase().replaceAll(/./g,e=>String.fromCodePoint((e.codePointAt(0)??0)+127397)):e:``}function gP(e){return hP(ZN[e]||e)}var{LUCKY_LOSER:_P,WILDCARD:vP,QUALIFIER:yP}=t.entryStatusConstants,{WIN_RATIO:bP,ROUND_OUTCOME:xP,MAIN:SP,CONTAINER:CP}=t.drawDefinitionConstants;function wP(e){return e?.finishingPosition===xP&&e?.structureType!==CP}function TP(e){return e?.finishingPosition===bP||e?.structureType===CP}function EP(e){if(!e?.length)return;let t=e.filter(wP);if(t.length)return t.find(e=>e.stage===SP)??t[0]}function DP(e){if(TP(e))return{drawSize:0,roundMatchUps:{}};let t={};for(let[n,r]of Object.entries(e.roundMatchUps))t[Number(n)]=r.map(e=>({...e,winningSide:e.winningSide,drawPositions:e.drawPositions||[],competitiveness:UN({winningSide:e.winningSide,matchUpStatus:e.matchUpStatus,sets:e.score?.sets}),scoreString:e.winningSide===1?e.score?.scoreStringSide1:e.winningSide===2?e.score?.scoreStringSide2:void 0,sides:(e.sides||[]).map(e=>({sideNumber:e.sideNumber,drawPosition:e.drawPosition,participantName:e.participant?.participantName,nationalityCode:e.participant?.person?.nationalityCode,seedNumber:e.seedNumber,entryStatus:e.participant?.entryStatus}))}));return{drawSize:(t[1]?.length||0)*2,roundMatchUps:t,seedAssignments:e.seedAssignments}}var OP={LL:_P,WC:vP,Q:yP},kP=[`R128`,`R64`,`R32`,`R16`,`QF`,`SF`,`F`];function AP(e){let t=jP(e);if(t.length===0)return{drawSize:0,roundMatchUps:{}};let n=t[0].data,r=n.length,i=MP(n),a=NP(t,e),o={};o[1]=FP(n,a,t);for(let e=1;e<t.length;e++)o[e+1]=IP(e,t,a,i);return{drawSize:r,roundMatchUps:o}}function jP(e){let t=[],n=!1;for(let r of kP){let i=e[r];i&&i.length>0&&(n=!0),n&&i&&i.length>0&&t.push({key:r,data:i})}return t}function MP(e){let t=new Map;return e.forEach((e,n)=>{let r=LP(e.player);r&&r!==`BYE`&&t.set(r,{drawPosition:e.Draw??n+1,country:e.country,seed:e.seed,entry:e.entry})}),t}function NP(e,t){let n=new Map;for(let r=0;r<e.length;r++){let i=r+1<e.length?e[r+1].data:t.W||[],a=new Set;for(let e of i){let t=LP(e.player);t&&a.add(t)}n.set(e[r].key,a)}return n}function PP(e,t,n){if(e===`BYE`||t===`BYE`)return e===`BYE`?2:1;if(n.has(e))return 1;if(n.has(t))return 2}function FP(e,t,n){let r=[],i=t.get(n[0].key)||new Set;for(let t=0;t<e.length;t+=2){let a=e[t],o=e[t+1],s=LP(a?.player),c=LP(o?.player),l=s===`BYE`||c===`BYE`,u=PP(s,c,i),d;if(!l&&n.length>1){let e=n[1].data,t=u===1?s:c;d=e.find(e=>LP(e.player)===t)?.score}let f=l?`BYE`:u?`COMPLETED`:`TO_BE_PLAYED`;r.push({roundNumber:1,matchUpStatus:f,winningSide:u,drawPositions:[a?.Draw??t+1,o?.Draw??t+2],competitiveness:UN({winningSide:u,matchUpStatus:f,scoreString:d}),scoreString:d,sides:[zP(1,a,t+1),zP(2,o,t+2)]})}return r}function IP(e,t,n,r){let i=e+1,a=t[e].data,o=n.get(t[e].key)||new Set,s=[];for(let e=0;e<a.length;e+=2){let t=a[e],n=a[e+1],c=LP(t?.player),l=LP(n?.player),u=o.has(c)?1:o.has(l)?2:void 0,d=(u===1?t:u===2?n:void 0)?.score,f=u?`COMPLETED`:`TO_BE_PLAYED`;s.push({roundNumber:i,matchUpStatus:f,winningSide:u,drawPositions:[r.get(c)?.drawPosition??0,r.get(l)?.drawPosition??0],competitiveness:UN({winningSide:u,matchUpStatus:f,scoreString:d}),scoreString:d,sides:[BP(1,t,r),BP(2,n,r)]})}return s}function LP(e){if(!e)return``;let t=e.trim();return t.toUpperCase()===`BYE`?`BYE`:t}function RP(e){if(e)return OP[e.toUpperCase()]||e}function zP(e,t,n){if(!t)return{sideNumber:e,drawPosition:n};let r=LP(t.player);return{sideNumber:e,drawPosition:t.Draw??n,participantName:r||void 0,nationalityCode:t.country||void 0,seedNumber:t.seed?Number(t.seed):void 0,entryStatus:RP(t.entry)}}function BP(e,t,n){if(!t)return{sideNumber:e,drawPosition:0};let r=LP(t.player),i=n.get(r);return{sideNumber:e,drawPosition:i?.drawPosition??0,participantName:r||void 0,nationalityCode:t.country||i?.country||void 0,seedNumber:t.seed?Number(t.seed):i?.seed?Number(i.seed):void 0,entryStatus:RP(t.entry||i?.entry)}}var VP=480,HP=200,UP=280,WP={top:12,right:12,bottom:28,left:32},GP={top:12,right:12,bottom:12,left:12},KP=.6,qP=.9,JP=`http://www.w3.org/2000/svg`,YP=`middle`,XP=`text-anchor`,ZP=`dominant-baseline`,QP=[`var(--chc-rating-low, #5b8ff9)`,`var(--chc-rating-high, #00b894)`];function $P(e,t,n){let r=document.createElementNS(JP,`svg`);return r.setAttribute(`width`,String(e)),r.setAttribute(`height`,String(t)),r.setAttribute(`viewBox`,`0 0 ${e} ${t}`),r.setAttribute(`class`,`chc-rating-distribution-chart`),n&&r.setAttribute(`aria-label`,n),r}function eF(e,t,n){return n<=1||t/(n-1)<.5?QP[0]:QP[1]}function tF(e,t,n,r){return r?r(e,t):eF(e,t,n)}function nF(e){return`${e.binStart.toFixed(1)}–${e.binEnd.toFixed(1)}`}function rF(e){let{stats:t,width:n,height:r,margin:i,showAxis:a,showCounts:o,showMean:s,binColor:c,ariaLabel:l}=e,u=$P(n,r,l),d=uE(u).append(`g`).attr(`class`,`chc-rdc-histogram`).attr(`transform`,`translate(${i.left}, ${i.top})`),f=Math.max(0,n-i.left-i.right),p=Math.max(0,r-i.top-i.bottom);if(t.histogram.length===0||f===0||p===0)return u;let m=vA().domain(t.histogram.map(nF)).range([0,f]).padding(.12),h=PA().domain([0,WC(t.histogram,e=>e.count)??0]).nice().range([p,0]),g=t.histogram.length;if(d.selectAll(`rect.chc-rdc-bar`).data(t.histogram).enter().append(`rect`).attr(`class`,`chc-rdc-bar`).attr(`x`,e=>m(nF(e))??0).attr(`y`,e=>h(e.count)).attr(`width`,m.bandwidth()).attr(`height`,e=>p-h(e.count)).attr(`fill`,(e,t)=>tF(e,t,g,c)).append(`title`).text(e=>`${nF(e)}: ${e.count}`),o&&d.selectAll(`text.chc-rdc-count`).data(t.histogram).enter().append(`text`).attr(`class`,`chc-rdc-count`).attr(`x`,e=>(m(nF(e))??0)+m.bandwidth()/2).attr(`y`,e=>h(e.count)-4).attr(XP,YP).attr(`font-size`,`11`).attr(`fill`,`var(--chc-rdc-count-color, var(--chc-text-primary, #111827))`).text(e=>e.count>0?String(e.count):``),a){let e=t.histogram.map(nF),n=f/g>=55?e:[e[0],e.at(-1)].filter((e,t,n)=>n.indexOf(e)===t);d.append(`g`).attr(`class`,`chc-rdc-axis`).attr(`transform`,`translate(0, ${p})`).call(iw(m).tickValues(n).tickSize(0)).call(e=>e.select(`.domain`).remove()).call(e=>e.selectAll(`text`).attr(`font-size`,`10`).attr(`dy`,`0.9em`))}if(s&&Number.isFinite(t.mean)&&t.histogram.length>0){let e=t.histogram[0],n=t.histogram.at(-1),r=(t.mean-e.binStart)/(n.binEnd-e.binStart);if(r>=0&&r<=1){let e=r*f;d.append(`line`).attr(`class`,`chc-rdc-mean`).attr(`x1`,e).attr(`x2`,e).attr(`y1`,0).attr(`y2`,p).attr(`stroke`,`var(--chc-rating-mean, #d63031)`).attr(`stroke-dasharray`,`4 3`).attr(`stroke-width`,1.5)}}return u}function iF(e,t,n,r){return[e+n*Math.sin(r),t-n*Math.cos(r)]}function aF(e,t,n,r,i,a){let[o,s]=iF(e,t,n,i),[c,l]=iF(e,t,n,a),[u,d]=iF(e,t,r,a),[f,p]=iF(e,t,r,i),m=+(a-i>Math.PI);return[`M ${o} ${s}`,`A ${n} ${n} 0 ${m} 1 ${c} ${l}`,`L ${u} ${d}`,`A ${r} ${r} 0 ${m} 0 ${f} ${p}`,`Z`].join(` `)}function oF(e){let{stats:t,size:n,margin:r,showCounts:i,binColor:a,ariaLabel:o}=e,s=$P(n,n,o);if(t.histogram.length===0||t.count===0)return s;let c=(n-Math.max(r.left+r.right,r.top+r.bottom))/2,l=n/2,u=n/2,d=c*qP,f=c*KP,p=0,m=t.histogram.length;for(let e=0;e<m;e++){let n=t.histogram[e];if(n.count===0)continue;let r=n.count/t.count*2*Math.PI,o=p,c=p+r,h=document.createElementNS(JP,`path`);if(h.setAttribute(`class`,`chc-rdc-slice`),h.setAttribute(`d`,aF(l,u,d,f,o,c)),h.setAttribute(`fill`,tF(n,e,m,a)),s.appendChild(h),i){let e=o+r/2,[t,i]=iF(l,u,(d+f)/2,e),a=document.createElementNS(JP,`text`);a.setAttribute(`class`,`chc-rdc-slice-label`),a.setAttribute(`x`,String(t)),a.setAttribute(`y`,String(i)),a.setAttribute(XP,YP),a.setAttribute(ZP,YP),a.setAttribute(`font-size`,`11`),a.setAttribute(`fill`,`var(--chc-rating-label, #2d3436)`),a.textContent=String(n.count),s.appendChild(a)}p=c}let h=document.createElementNS(JP,`text`);return h.setAttribute(`class`,`chc-rdc-center-count`),h.setAttribute(`x`,String(l)),h.setAttribute(`y`,String(u)),h.setAttribute(XP,YP),h.setAttribute(ZP,YP),h.setAttribute(`font-size`,`20`),h.setAttribute(`font-weight`,`600`),h.textContent=String(t.count),s.appendChild(h),s}function sF(e,t={}){let n=t.mode??`HISTOGRAM`,r=t.ariaLabel??`Participant rating distribution`;return n===`DONUT`?oF({stats:e,size:t.width??t.height??UP,margin:t.margin??GP,showCounts:t.showCounts??!0,binColor:t.binColor,ariaLabel:r}):rF({stats:e,width:t.width??VP,height:t.height??HP,margin:t.margin??WP,showAxis:t.showAxis??!0,showCounts:t.showCounts??!0,showMean:t.showMean??!0,binColor:t.binColor,ariaLabel:r})}var cF=`http://www.w3.org/2000/svg`,lF={top:36,right:16,bottom:28,left:56},uF=600,dF=260,fF=6,pF=8;function mF(e,t){let n=document.createElementNS(cF,`svg`);n.classList.add(`lc-svg`),e.appendChild(n);let r={container:e,svg:n,config:{...t},destroyed:!1};return hF(r),{element:n,update(e){r.destroyed||(r.config={...r.config,...e},hF(r))},destroy(){r.destroyed||(r.destroyed=!0,n.parentNode===e&&e.removeChild(n))}}}function hF(e){let{svg:t,container:n,config:r}=e,i={...lF,...r.margins||{}},a=n.clientWidth||uF,o=r.width??a,s=r.height??dF;for(;t.firstChild;)t.removeChild(t.firstChild);t.setAttribute(`width`,String(o)),t.setAttribute(`height`,String(s)),t.setAttribute(`viewBox`,`0 0 ${o} ${s}`);let c=Math.max(0,o-i.left-i.right),l=Math.max(0,s-i.top-i.bottom),u=(r.data||[]).map(e=>({...e,_dateValue:e.date instanceof Date?e.date:new Date(e.date),_rung:Math.max(0,Math.min(r.rungs.length-1,e.rung))})).filter(e=>!Number.isNaN(e._dateValue.getTime())).sort((e,t)=>e._dateValue.getTime()-t._dateValue.getTime());if(r.title){let e=document.createElementNS(cF,`text`);e.setAttribute(`class`,`lc-title`),e.setAttribute(`x`,String(i.left)),e.setAttribute(`y`,String(Math.max(16,i.top-12))),e.textContent=r.title,t.appendChild(e)}if(!u.length){let e=document.createElementNS(cF,`text`);e.setAttribute(`class`,`lc-empty`),e.setAttribute(`x`,String(o/2)),e.setAttribute(`y`,String(s/2)),e.setAttribute(`text-anchor`,`middle`),e.textContent=`No data`,t.appendChild(e);return}let d=jC(u,e=>e._dateValue),f=Math.max(3,(d[1].getTime()-d[0].getTime())/864e5*.04),p=new Date(d[0].getTime()-f*864e5),m=new Date(d[1].getTime()+f*864e5),h=QM().domain([p,m]).range([0,c]),g=bA().domain([...r.rungs].reverse()).range([0,l]).padding(.5),_=document.createElementNS(cF,`g`);_.setAttribute(`transform`,`translate(${i.left},${i.top})`),t.appendChild(_);let v=document.createElementNS(cF,`g`);v.setAttribute(`class`,`lc-axis lc-axis-y`),_.appendChild(v),uE(v).call(aw(g).tickSize(-c).tickPadding(8));let y=document.createElementNS(cF,`g`);y.setAttribute(`class`,`lc-axis lc-axis-x`),y.setAttribute(`transform`,`translate(0,${l})`),_.appendChild(y);let b=d[1].getFullYear()-d[0].getFullYear()>=1?`%Y`:`%b`,x=r.xTickFormat??b;if(uE(y).call(iw(h).ticks(r.xMaxTicks??pF).tickFormat(qM(x))),r.showConnector!==!1&&u.length>1){let e=EN().x(e=>h(e._dateValue)).y(e=>g(r.rungs[e._rung])??0).curve(ON),t=document.createElementNS(cF,`path`);t.setAttribute(`class`,`lc-connector`),t.setAttribute(`d`,e(u)||``),r.connectorColor&&(t.style.stroke=r.connectorColor),_.appendChild(t)}let S=document.createElementNS(cF,`g`);S.setAttribute(`class`,`lc-marks`),_.appendChild(S);for(let e of u){let t=h(e._dateValue),n=g(r.rungs[e._rung])??0,i=e.radius??r.markRadius??fF,a=document.createElementNS(cF,`circle`);if(a.setAttribute(`class`,`lc-mark`),a.setAttribute(`cx`,String(t)),a.setAttribute(`cy`,String(n)),a.setAttribute(`r`,String(i)),(e.color||r.markColor)&&(a.style.fill=e.color??r.markColor),e.label){let t=[e.label,e.detail].filter(Boolean).join(` — `);a.setAttribute(`aria-label`,t);let n=document.createElementNS(cF,`title`);n.textContent=t,a.appendChild(n)}r.onMarkClick&&(a.style.cursor=`pointer`,a.addEventListener(`click`,t=>r.onMarkClick(e,t))),r.onMarkHover&&(a.addEventListener(`mouseenter`,t=>r.onMarkHover(e,t)),a.addEventListener(`mouseleave`,e=>r.onMarkHover(null,e))),S.appendChild(a)}if(r.source){let e=document.createElementNS(cF,`text`);e.setAttribute(`class`,`lc-source`),e.setAttribute(`x`,String(o-i.right)),e.setAttribute(`y`,String(s-6)),e.setAttribute(`text-anchor`,`end`),e.textContent=`Source: ${r.source}`,t.appendChild(e)}}var gF=`right`,_F=`font-medium`;function vF({target:e,button:t,stateChange:n}){let r=0,i=()=>(r+=1,`Item${r}`),a=document.createElement(`div`);t.class&&a.classList.add(t.class),a.classList.add(`dropdown`),t.id&&(a.id=t.id),t.align===gF&&a.classList.add(`is-right`);let o=e=>e.classList.contains(`is-active`),s=()=>{o(a)&&a.classList.remove(`is-active`)},c=e=>o(e)?(e.classList.remove(`is-active`),!1):(e.classList.add(`is-active`),!0);a.onmouseleave=s,a.onclick=()=>c(a);let l=document.createElement(`div`);l.classList.add(`dropdown-trigger`);let u=document.createElement(`button`);u.className=`button font-medium`,t.intent&&u.classList.add(t.intent),u.setAttribute(`aria-haspopup`,`true`);let d=document.createElement(`span`);V(t.onClick)&&(d.onclick=t.onClick),d.style.cssText=`margin-right: 1em`,d.innerHTML=t.label,u.appendChild(d);let f=document.createElement(`span`);V(t.onClick)&&(f.onclick=t.onClick),f.innerHTML=`
216
216
  <span class="icon is-small font-medium">
217
217
  <i class="fas fa-angle-down font-medium" aria-hidden="true"></i>
218
218
  </span>
219
- `,u.appendChild(f),l.appendChild(u),a.appendChild(l);let p=document.createElement(`div`);p.classList.add(`dropdown-menu`),p.setAttribute(`z-index`,`99998`);let m=document.createElement(`div`);m.classList.add(`dropdown-content`);let h=()=>{let e=p.querySelectorAll(`.dropdown-item`);for(let t of Array.from(e))t.classList.remove(`is-active`)},g=e=>{let r=document.createElement(`a`);r.className=YN;let l=e.disabled?`0.4`:`1`;return r.style.cssText=`text-decoration: none; opacity: ${l};`,e.color&&(r.style.color=e.color),r.classList.add(`dropdown-item`),e.isActive&&r.classList.add(`is-active`),e.value&&(r.value=e.value),e.class&&r.classList.add(e.class),r.onclick=l=>{if(e.disabled)return;e.value&&(u.value=e.value,a.value=e.value),l.stopPropagation(),V(e.onClick)&&(V(n)&&n(),e.onClick(l)),e.close&&s();let f=o(r);h(),f?d.innerHTML=t.label:(t.selection&&c(r),t.modifyLabel&&e.modifyLabel!==!1&&(d.innerHTML=`${t.append?t.label+`: `:``}${e?.label||i()}`))},r.innerHTML=e?.label||i(),r};for(let e of t.options||[])if(e.heading){let t=document.createElement(`div`);t.style.cssText=`font-weight: bold`,t.classList.add(`dropdown-item`,YN),t.innerHTML=e.heading,m.appendChild(t)}else if(e.divider){let e=document.createElement(`hr`);e.classList.add(`dropdown-divider`,YN),m.appendChild(e)}else e.hide||m.appendChild(g(e));return t.options?.length&&(t.options[0].value&&(a.value=t.options[0].value),p.appendChild(m)),a.appendChild(p),e&&e.appendChild(a),a}var ZN=`left`;function QN(e){let{title:t,placeholder:n,options:r,selectionLimit:i,createTable:a,createFilter:o}=e,s=`selectionControl`,c=`selectionTable`,l,u,d=[{label:`Cancel`,intent:`none`,close:!0}],f=()=>{u?u():l?.destroy&&l.destroy(),l=void 0},p=`
219
+ `,u.appendChild(f),l.appendChild(u),a.appendChild(l);let p=document.createElement(`div`);p.classList.add(`dropdown-menu`),p.setAttribute(`z-index`,`99998`);let m=document.createElement(`div`);m.classList.add(`dropdown-content`);let h=()=>{let e=p.querySelectorAll(`.dropdown-item`);for(let t of Array.from(e))t.classList.remove(`is-active`)},g=e=>{let r=document.createElement(`a`);r.className=_F;let l=e.disabled?`0.4`:`1`;return r.style.cssText=`text-decoration: none; opacity: ${l};`,e.color&&(r.style.color=e.color),r.classList.add(`dropdown-item`),e.isActive&&r.classList.add(`is-active`),e.value&&(r.value=e.value),e.class&&r.classList.add(e.class),r.onclick=l=>{if(e.disabled)return;e.value&&(u.value=e.value,a.value=e.value),l.stopPropagation(),V(e.onClick)&&(V(n)&&n(),e.onClick(l)),e.close&&s();let f=o(r);h(),f?d.innerHTML=t.label:(t.selection&&c(r),t.modifyLabel&&e.modifyLabel!==!1&&(d.innerHTML=`${t.append?t.label+`: `:``}${e?.label||i()}`))},r.innerHTML=e?.label||i(),r};for(let e of t.options||[])if(e.heading){let t=document.createElement(`div`);t.style.cssText=`font-weight: bold`,t.classList.add(`dropdown-item`,_F),t.innerHTML=e.heading,m.appendChild(t)}else if(e.divider){let e=document.createElement(`hr`);e.classList.add(`dropdown-divider`,_F),m.appendChild(e)}else e.hide||m.appendChild(g(e));return t.options?.length&&(t.options[0].value&&(a.value=t.options[0].value),p.appendChild(m)),a.appendChild(p),e&&e.appendChild(a),a}var yF=`left`;function bF(e){let{title:t,placeholder:n,options:r,selectionLimit:i,createTable:a,createFilter:o}=e,s=`selectionControl`,c=`selectionTable`,l,u,d=[{label:`Cancel`,intent:`none`,close:!0}],f=()=>{u?u():l?.destroy&&l.destroy(),l=void 0},p=`
220
220
  <div style='min-height: 420px'>
221
221
  <div id='${s}'></div>
222
222
  <div id='${c}'></div>
223
223
  </div>
224
- `;z.open({title:t,content:p,buttons:d,onClose:f});let m=e=>{e?.[0]?.onClick&&(e[0].onClick(),z.close())};if(a){let e=a({anchorId:c,data:r,selectionLimit:i,onSelected:m});l=e.table,u=e.destroy;let t=o?o(l):()=>{},d=[{onKeyDown:e=>e.keyCode===8&&e.target.value.length===1&&t(``),onChange:e=>t(e.target.value),onKeyUp:e=>t(e.target.value),clearSearch:()=>t(``),placeholder:n||`Search`,location:ZN,search:!0}],f=document.getElementById(s)||void 0;yP({table:l,target:f,items:d})}else{let e=document.getElementById(c);if(e){$N({container:e,options:r,onSelected:m});let t=t=>{let n=e.querySelectorAll(`[data-select-item]`),r=t.toLowerCase();n.forEach(e=>{let n=e.textContent?.toLowerCase()||``;e.style.display=!t||n.includes(r)?``:`none`})},i=[{onKeyUp:e=>t(e.target.value),clearSearch:()=>t(``),placeholder:n||`Search`,location:ZN,search:!0}];yP({target:document.getElementById(s)||void 0,items:i})}}}function $N({container:e,options:t,onSelected:n}){let r=document.createElement(`div`);r.style.cssText=`max-height: 380px; overflow-y: auto; padding: 0.5em 0;`;for(let e of t){let t=document.createElement(`a`);t.setAttribute(`data-select-item`,``),t.className=`panel-block font-medium`,t.style.cssText=`cursor: pointer; padding: 0.5em 1em; display: block; text-decoration: none; color: inherit;`,t.innerHTML=e.label,t.onmouseenter=()=>t.style.backgroundColor=`#f5f5f5`,t.onmouseleave=()=>t.style.backgroundColor=``,t.onclick=t=>{t.stopPropagation(),n([e])},r.appendChild(t)}e.appendChild(r)}var eP=`none`;function tP(e){let t=document.createElement(`button`);return t.className=`button font-medium`,e.disabled&&(t.disabled=!0),e.class&&t.classList.add(e.class),e.id&&(t.id=e.id),e.intent&&t.classList.add(e.intent),e.toolTip?.content&&km(t,e.toolTip),t.innerHTML=e.label,e.visible===!1&&(t.style.display=eP),t}var nP=`center`,rP=``,iP=`flex`,aP=`left`,oP=`none`,sP=`overlay`,cP=`right`,lP=({target:e})=>(t=[])=>{e.style.backgroundColor=t?.length?`var(--chc-hover-bg)`:rP;let n=(n,r,i)=>{let a=e.getElementsByClassName(`options_${n}`)[0];a&&(a.style.display=t?.length?r:i)};n(sP,iP,oP),n(aP,oP,iP),n(nP,oP,iP),n(cP,oP,iP)},uP=`center`,dP=`header`,fP=``,pP=`left`,mP=`none`,hP=`overlay`,gP=`right`,_P=`buttonBar`,vP=`top`;function yP(e){let{table:t,targetClassName:n,items:r=[],onSelection:i,selectItemFn:a}=e,{target:o}=e,s=!!o;if(!o&&n&&(o=document.getElementsByClassName(n)?.[0]),!o)return{elements:{},inputs:{}};let c=0,l=0,u={},d={},f;if(s){ne(o);let e=DP();Object.assign(u,e.elements),o.appendChild(e.anchor)}let p=Object.assign({},...[hP,pP,uP,gP,dP].map(e=>{let t=o.getElementsByClassName(`options_${e}`)?.[0];return ne(t),{[e]:t}}).filter(Boolean)),m=lP({table:t,target:o}),h=(e,n)=>{V(n.onClick)&&(e.stopPropagation(),n.disabled||n.onClick(e,t),n.stateChange&&m())},g={onClick:()=>{},location:gP};for(let e of r){let t={...g};oe(e)&&Object.assign(t,e);let n=p[t.location];if(!n){console.log(t.location,p);continue}t.location===hP&&(c+=1),t.location===dP&&(bP(t,o),l+=1);let r=xP(e,t,n,m,h,a,u,d);r?.focus&&(f=r.focus)}let _=o.getElementsByClassName(`panelHeader`)[0];_&&(_.style.display=l?fP:mP),t?._controlBarSelectionHandler&&t.off(`rowSelectionChanged`,t._controlBarSelectionHandler);let v=(e,t)=>{V(i)&&i(t),c&&m(t)};return t&&(t._controlBarSelectionHandler=v),t?.on(`rowSelectionChanged`,v),m(t?.getSelectedRows?.()??[]),f&&setTimeout(()=>f.focus(),200),{elements:u,inputs:d}}function bP(e,t){if(V(e.headerClick)){let n=t.getElementsByClassName(`panelHeader`)[0];n&&(n.onclick=e.headerClick)}}function xP(e,t,n,r,i,a,o,s){if(!t.hide&&(t.input||t.placeholder||t.search)){let r=SP(e,t);return t.id&&(s[t.id]=r.input),t.id&&(o[t.id]=r.elem,r.elem.id=t.id),n?.appendChild(r.elem),t.focus?{focus:r.input}:void 0}if(!t.hide&&t.text){let e=document.createElement(`div`);e.className=`font-medium`,t.id&&(o[t.id]=e,e.id=t.id),e.innerHTML=t.text,e.onclick=e=>i(e,t),n?.appendChild(e);return}!t.id&&(!t?.label||t.hide)||(wP(t,n,r,i,a,o),(!(t?.label||t.tabs)||t.hide)&&o[t.id]&&(o[t.id].style.display=mP))}function SP(e,t){let n=document.createElement(`p`);n.className=`control ${t.search?`has-icons-left has-icons-right`:``}`;let r=document.createElement(`input`);if(r.className=`input font-medium`,r.setAttribute(`type`,`text`),r.setAttribute(`autocomplete`,`off`),r.setAttribute(`placeholder`,e.placeholder||fP),t.id&&r.setAttribute(`id`,t.id),t.onKeyDown&&r.addEventListener(`keydown`,e=>t.onKeyDown(e,t)),t.onChange&&r.addEventListener(`change`,e=>t.onChange(e,t)),t.onKeyUp&&r.addEventListener(`keyup`,e=>{t.clearSearch&&e.key===`Escape`&&(e.stopPropagation(),r.value=``,t.clearSearch()),t.onKeyUp(e,t)}),t.class&&r.classList.add(t.class),t.visible===!1&&(n.style.display=mP),t.value&&(r.value=t.value),n.appendChild(r),t.search&&CP(n,r,t),e.validator){let t=document.createElement(`p`);t.className=`help font-medium`,n.appendChild(t),r.addEventListener(`input`,n=>fn(e,n,r,t,e.validator))}return{elem:n,input:r}}function CP(e,t,n){let r=document.createElement(`span`);if(r.className=`icon is-small is-left font-medium`,r.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16" fill="currentColor"><path d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352a144 144 0 1 0 0-288 144 144 0 1 0 0 288z"/></svg>`,e.appendChild(r),V(n.clearSearch)){let r=document.createElement(`span`);r.className=`icon is-small is-right font-medium`,r.style.pointerEvents=`all`,r.style.cursor=`pointer`,r.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16" fill="#dddada"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"/></svg>`,r.onclick=e=>{e.stopPropagation(),t.value=``,n.clearSearch(),i()};let i=()=>{r.style.display=t.value?``:`none`};t.addEventListener(`input`,i),i(),e.appendChild(r)}}function wP(e,t,n,r,i,a){if(e.options){let r=XN({target:t,button:e,stateChange:n});e.visible===!1&&(r.style.display=mP),e.id&&(a[e.id]=r)}else if(oe(e.selection))TP(e,t,n,i,a);else if(e.tabs)EP(e,t,a);else{let n=tP(e);n.onclick=t=>r(t,e),e.id&&(a[e.id]=n),t?.appendChild(n)}}function TP(e,t,n,r,i){let{selection:{options:a,actions:o},actionPlacement:s,threshold:c=8,...l}=e;if(a?.length<c){a.length&&(s===vP?a.unshift({divider:!0}):a.push({divider:!0})),o.forEach(e=>{let{label:t,...n}=e,r={...n,label:`<p style="font-weight: bold">${t}</p>`};s===vP?a.unshift(r):a.push(r)});let r={...l,options:a},c=XN({target:t,button:r,stateChange:n});r.visible===!1&&(c.style.display=mP),r.id&&(i[e.id]=c)}else{let n=tP(e),o=r||QN;n.onclick=t=>{t.stopPropagation(),o({title:e.selectionTitle||`Select`,options:a})},e.id&&(i[e.id]=n),t?.appendChild(n)}}function EP(e,t,n){let r=document.createElement(`div`);r.className=`tabs is-toggle is-toggle-rounded`;let i=document.createElement(`ul`);r.appendChild(i),e.tabs.forEach(t=>{let n=document.createElement(`li`);t.active&&n.classList.add(`is-active`);let r=document.createElement(`a`);n.appendChild(r),r.onclick=r=>{i.querySelectorAll(`li`).forEach(e=>e.classList.remove(`is-active`)),n.classList.add(`is-active`),V(t.onClick)&&t.onClick(r,e)};let a=document.createElement(`span`);a.innerHTML=t.label,r.appendChild(a),i.appendChild(n)}),e.id&&(n[e.id]=r),t.appendChild(r)}function DP(){let e=document.createElement(`div`);e.className=`panel_container flexcol flexcenter`;let t=document.createElement(`div`);t.className=`panelHeader options_header`,t.style.display=mP,e.appendChild(t);let n=document.createElement(`div`);n.className=_P;let r={optionsOverlay:document.createElement(`div`),optionsLeft:document.createElement(`div`),optionsCenter:document.createElement(`div`),optionsRight:document.createElement(`div`)};r.optionsOverlay.className=`options_overlay`,r.optionsCenter.className=`options_center`,r.optionsRight.className=`options_right`,r.optionsLeft.className=`options_left`;for(let e of Object.values(r))n.appendChild(e);return e.appendChild(n),{elements:r,anchor:e,header:t}}var OP=()=>`sp-layout`,kP=()=>`sp-column`,AP=()=>`sp-panel`,jP=()=>`sp-panel-header`,MP=()=>`sp-panel-title`,NP=()=>`sp-panel-meta`,PP=()=>`sp-panel-actions`,FP=()=>`sp-panel-leading`,IP=()=>`sp-date-strip`,LP=()=>`sp-date-chip`,RP=()=>`sp-badges`,zP=()=>`sp-badge`,BP=()=>`sp-chips`,VP=()=>`sp-chip`,HP=()=>`sp-board`,UP=()=>`sp-venue`,WP=()=>`sp-venue-header`,GP=()=>`sp-venue-title`,KP=()=>`sp-venue-sub`,qP=()=>`sp-dropzone`,JP=()=>`sp-card`,YP=()=>`sp-card-title`,XP=()=>`sp-card-meta`,ZP=()=>`sp-issues`,QP=()=>`sp-issue`,$P=()=>`sp-issue-code`,eF=()=>`sp-issue-msg`,tF=()=>`sp-issue-actions`,nF=()=>`sp-btn sp-btn--sm`,rF=()=>`sp-catalog`,iF=()=>`sp-catalog-toolbar`,aF=()=>`sp-input`,oF=()=>`sp-select`,sF=()=>`sp-group`,cF=()=>`sp-group-header`,lF=()=>`sp-group-body`,uF=()=>`sp-catalog-item`,dF=()=>`sp-small`,fF=()=>`sp-popover-item`,pF=()=>`sp-popover-delete`,mF=()=>`sp-popover-divider`,hF=()=>`sp-insertion-line`,gF=()=>`sp-group-chevron`;function _F(e,t){let n=!!t?.hideLeft,r=t?.catalogSide===`left`,i=document.createElement(`div`);if(i.className=OP(),n)r?i.classList.add(`sp-catalog-left`):i.classList.add(`sp-no-left`);else{let t=document.createElement(`div`);t.className=kP(),t.appendChild(e.dateStrip.element),e.issuesPanel.element.style.flex=`1`,e.issuesPanel.element.style.minHeight=`0`,t.appendChild(e.issuesPanel.element),i.appendChild(t)}let a=document.createElement(`div`);a.className=kP(),e.venueBoard.element.style.flex=`1`,e.venueBoard.element.style.minHeight=`0`,a.appendChild(e.venueBoard.element);let o=document.createElement(`div`);o.className=kP(),e.roundCatalog.element.style.flex=`1 1 0`,e.roundCatalog.element.style.minHeight=`0`,o.appendChild(e.roundCatalog.element),r&&n?(i.appendChild(o),i.appendChild(a)):(i.appendChild(a),i.appendChild(o));function s(t){n||(e.dateStrip.update(t),e.issuesPanel.update(t)),e.venueBoard.update(t),e.roundCatalog.update(t)}return{element:i,update:s}}function vF(e){let t=null,n=null;function r(e){return`${e.date}|${e.venueId}|${e.index}`}function i(){t&&(t.destroy(),t=null,n=null)}function a(t){let n=document.createElement(`div`);n.style.cssText=`font-family:sans-serif; font-size:13px; min-width:150px;`;let r=document.createElement(`div`);r.className=fF(),r.textContent=`Set Not Before Time`,r.addEventListener(`click`,()=>{i(),e.onSetNotBeforeTime(t)}),n.appendChild(r);let a=document.createElement(`div`);a.className=mF(),n.appendChild(a);let o=document.createElement(`div`);return o.className=pF(),o.textContent=`Remove Round`,o.addEventListener(`click`,()=>{i(),e.onDelete(t)}),n.appendChild(o),n}return{show(e,o){let s=r(o);if(n===s){i();return}i();let c=km(e,{content:a(o),allowHTML:!0,interactive:!0,trigger:`manual`,placement:`bottom`,appendTo:document.body,onHidden:()=>{t=null,n=null}});t=c,n=s,c.show()},destroy(){i()},isActiveFor(e){return n===r(e)}}}function yF(e){return structuredClone(e)}function bF(e,t,n){return Math.max(t,Math.min(n,e))}function xF(e){return`${e.tournamentId}|${e.eventId}|${e.drawId}|${e.structureId}|${e.roundNumber}`}function SF(e){return`${e.eventName?`${e.eventName} \u2013 `:``}${e.roundName??`Round ${e.roundNumber}`}${e.roundSegment?` (seg ${e.roundSegment.segmentNumber}/${e.roundSegment.segmentsCount})`:``}`}function CF(e,t){return!e||!t?!1:e.date===t.date&&e.venueId===t.venueId&&e.index===t.index}function wF(e){return{tournamentId:e.tournamentId,eventId:e.eventId,drawId:e.drawId,structureId:e.structureId,roundNumber:e.roundNumber}}function TF(e,t){return`${e}|${t.segmentNumber}/${t.segmentsCount}`}function EF(e){let t=new Map;for(let n of e)for(let e of n.venues)for(let r=0;r<e.rounds.length;r++){let i=e.rounds[r],a=xF(i),o=i.roundSegment,s=o?TF(a,o):a,c={locator:{date:n.scheduleDate,venueId:e.venueId,index:r,roundKey:wF(i),roundSegment:o},date:n.scheduleDate,venueId:e.venueId,roundSegment:o},l=t.get(s);l?l.push(c):t.set(s,[c])}return t}function DF(e){let t=new Map;for(let n of e)for(let e of n.venues)for(let n of e.rounds){if(!n.roundSegment)continue;let e=xF(n),r=t.get(e)??0;n.roundSegment.segmentsCount>r&&t.set(e,n.roundSegment.segmentsCount)}return t}function OF(e,t,n,r=`dim`){let i=t.toLowerCase().trim();return e.filter(e=>r===`hide`&&n.has(xF(e))?!1:!i||`${e.eventName} ${e.drawName??``} ${e.roundName??``} ${e.drawId}`.toLowerCase().includes(i)).map(e=>({...e,isPlanned:n.has(xF(e))}))}function kF(e,t){let n=new Map,r=e=>t===`draw`?`${e.eventName} \u2014 ${e.drawName??e.drawId}`:t===`round`?e.roundName??`Round ${e.roundNumber}`:e.eventName;for(let t of e){let e=r(t),i=n.get(e);i?i.push(t):n.set(e,[t])}return new Map([...n.entries()].sort((e,t)=>e[0].localeCompare(t[0],void 0,{numeric:!0})))}function AF(e){let t=new Set;for(let n of e)for(let e of n.venues)for(let n of e.rounds)n.roundSegment||t.add(xF(n));return t}function jF(e){let t=new Set;for(let n of e)for(let e of n.venues)for(let n of e.rounds)if(n.roundSegment){let e=xF(n);t.add(TF(e,n.roundSegment))}return t}var MF=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function NF(e){return MF.test(e)}function PF(e){let t=document.createElement(`div`);t.className=AP(),t.style.overflowY=`auto`,t.style.scrollbarWidth=`thin`,t.style.scrollbarColor=`var(--sp-scrollbar) transparent`;let n=new Set,r=new Map,i=null,a=document.createElement(`div`);a.className=jP();let o=document.createElement(`div`);o.className=MP(),o.textContent=`Round Catalog`;let s=document.createElement(`div`);s.className=NP(),a.appendChild(o),a.appendChild(s),t.appendChild(a);let c=document.createElement(`div`);c.className=iF();let l=document.createElement(`input`);l.type=`text`,l.placeholder=`Search rounds...`,l.className=aF(),l.addEventListener(`input`,()=>e.onSearchChange(l.value));let u=eS(l,()=>{l.value=``,e.onSearchChange(``),l.focus()}),d=document.createElement(`select`);d.className=oF();for(let[e,t]of[[`event`,`By Event`],[`draw`,`By Draw`],[`round`,`By Round`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,d.appendChild(n)}d.addEventListener(`change`,()=>e.onGroupByChange(d.value)),c.appendChild(u),c.appendChild(d),t.appendChild(c);let f=document.createElement(`div`);f.className=rF(),t.appendChild(f),f.addEventListener(`dragover`,e=>{e.preventDefault(),f.classList.add(`over`),e.dataTransfer.dropEffect=`move`}),f.addEventListener(`dragleave`,e=>{f.contains(e.relatedTarget)||f.classList.remove(`over`)}),f.addEventListener(`drop`,t=>{if(f.classList.remove(`over`),t.preventDefault(),!e.onDropRemove)return;let n;try{n=JSON.parse(t.dataTransfer.getData(`application/json`))}catch{return}n.type===`PLANNED_ROUND`&&e.onDropRemove(n.locator)});function p(t,n,i,a,o,s){let c=document.createElement(`div`);c.className=uF(),i&&c.classList.add(`segment`),t.isPlanned?(c.classList.add(n===`navigate`?`navigate`:`dimmed`),c.draggable=!1,n===`navigate`&&c.addEventListener(`click`,()=>{e.onNavigateToPlanned?.(t)})):(c.draggable=!0,c.addEventListener(`dragstart`,e=>{e.stopPropagation(),e.dataTransfer.setDragImage(c,c.offsetWidth/2,20);let n={type:`CATALOG_ROUND`,roundRef:t};i&&(n.roundSegment=i),e.dataTransfer.setData(`application/json`,JSON.stringify(n)),e.dataTransfer.effectAllowed=`copyMove`}));let l=document.createElement(`div`);l.className=YP();let u=t.roundName&&!t.roundName.startsWith(`rn=`)?t.roundName:`Round `+t.roundNumber,d=i?` \u00b7 Seg ${i.segmentNumber}/${i.segmentsCount}`:``;l.textContent=`${t.eventName} \u2014 ${u}${d}`;let f=document.createElement(`div`);f.className=XP();let p=i&&t.matchCountEstimate?Math.round(t.matchCountEstimate/i.segmentsCount):t.matchCountEstimate,m=p?` · `+p+` matches`:``,h=t.drawName&&!NF(t.drawName)?t.drawName:``;if(f.textContent=h?`${h}${m}`:m.replace(` · `,``)||``,c.appendChild(l),c.appendChild(f),o.length&&n!==`navigate`&&(c.appendChild(FF(o,s)),e.onDropRemove&&c.appendChild(LF(o,e.onDropRemove))),!(t.isPlanned&&n!==`navigate`)&&!t.isPlanned){let e=document.createElement(`div`);e.className=`sp-split-ctl`;let n=xF(t);if(i){let t=document.createElement(`button`);t.type=`button`,t.className=`sp-split-chip sp-split-collapse`,t.title=`Collapse to whole round`,t.textContent=`×`,t.addEventListener(`click`,e=>{e.stopPropagation(),r.delete(n),a()}),e.appendChild(t)}else for(let[t,i,o]of[[`½`,2,`Split into halves`],[`¼`,4,`Split into quarters`]]){let s=document.createElement(`button`);s.type=`button`,s.className=`sp-split-chip`,s.title=o,s.textContent=t,s.addEventListener(`click`,e=>{e.stopPropagation(),r.set(n,i),a()}),e.appendChild(s)}c.appendChild(e)}return c}function m(e){i=e;let t=e.plannedRoundBehavior,a=AF(e.profileDraft),o=jF(e.profileDraft),c=EF(e.profileDraft),h=DF(e.profileDraft),g=new Map(e.venues.map(e=>[e.venueId,e.name])),_=OF(e.roundCatalog,e.catalogSearchQuery,a,t),v=kF(_,e.catalogGroupBy),y=()=>i&&m(i);s.textContent=`${_.length} rounds`,l.value!==e.catalogSearchQuery&&(l.value=e.catalogSearchQuery,tS(u)),d.value!==e.catalogGroupBy&&(d.value=e.catalogGroupBy),f.innerHTML=``;for(let[e,a]of v){let s=document.createElement(`div`);s.className=sF();let l=n.has(e),u=document.createElement(`div`);u.className=cF();let d=document.createElement(`span`);d.className=gF(),d.textContent=l?`▶`:`▼`;let _=document.createElement(`span`);_.textContent=e,u.appendChild(d),u.appendChild(_),u.addEventListener(`click`,()=>{n.has(e)?n.delete(e):n.add(e),i&&m(i)});let v=document.createElement(`div`);v.className=lF(),l&&(v.style.display=`none`);for(let e of a){let n=xF(e),i=r.get(n)??h.get(n);if(!i){let r=c.get(n)??[];v.appendChild(p(e,t,void 0,y,r,g));continue}for(let r=1;r<=i;r++){let a={segmentNumber:r,segmentsCount:i},s=e.isPlanned||o.has(TF(n,a));if(s&&t===`hide`)continue;let l=c.get(TF(n,a))??[];v.appendChild(p({...e,isPlanned:s},t,a,y,l,g))}}s.appendChild(u),s.appendChild(v),f.appendChild(s)}}return{element:t,update:m}}function FF(e,t){let n=document.createElement(`div`);n.className=`sp-catalog-placements`;for(let r of e)n.appendChild(IF(r,t));return n}function IF(e,t){let n=document.createElement(`div`);n.className=`sp-catalog-placement`;let r=document.createElement(`span`);r.className=`sp-catalog-placement-icon`,n.appendChild(r);let i=document.createElement(`span`);i.className=`sp-catalog-placement-label`;let a=t.get(e.venueId)||e.venueId,o=e.roundSegment?` · Seg ${e.roundSegment.segmentNumber}/${e.roundSegment.segmentsCount}`:``;return i.textContent=`${RF(e.date)} · ${a}${o}`,n.appendChild(i),n}function LF(e,t){let n=document.createElement(`div`);n.className=`sp-split-ctl sp-split-ctl-stack`;for(let r of e){let e=document.createElement(`button`);e.type=`button`,e.className=`sp-split-chip sp-split-collapse`,e.title=`Remove this placement`,e.textContent=`×`,e.addEventListener(`click`,e=>{e.stopPropagation(),t(r.locator)}),n.appendChild(e)}return n}function RF(e){try{let t=new Date(`${e}T12:00:00`);return Number.isNaN(t.getTime())?e:`${t.toLocaleDateString(void 0,{weekday:`short`})} ${t.toLocaleDateString(void 0,{month:`short`})} ${t.getDate()}`}catch{return e}}function zF(e){let t=document.createElement(`div`);t.className=AP();let n=document.createElement(`div`);n.className=jP();let r=document.createElement(`div`);r.className=MP(),r.textContent=`Issues`;let i=document.createElement(`div`);i.className=NP(),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=ZP(),t.appendChild(a);function o(t){let n=t.issueIndex.all;if(i.textContent=`${n.length} total (${t.issueIndex.bySeverity.ERROR.length} errors)`,a.innerHTML=``,!n.length){let e=document.createElement(`div`);e.className=dF(),e.textContent=`No issues. Drag rounds into the board to build a profile.`,a.appendChild(e);return}for(let t of n.slice(0,30)){let n=document.createElement(`div`);n.className=QP(),t.severity===`ERROR`?n.classList.add(`error`):t.severity===`WARN`?n.classList.add(`warn`):n.classList.add(`info`);let r=document.createElement(`div`);r.className=$P(),r.textContent=`${t.severity} \u00b7 ${t.code}`;let i=document.createElement(`div`);if(i.className=eF(),i.textContent=t.message,n.appendChild(r),n.appendChild(i),t.fixActions?.length){let r=document.createElement(`div`);r.className=tF();for(let n of t.fixActions){let t=document.createElement(`button`);t.className=nF(),t.textContent=n.label??n.kind,t.addEventListener(`click`,()=>e.onFixAction(n)),r.appendChild(t)}n.appendChild(r)}a.appendChild(n)}}return{element:t,update:o}}var{ROUND_ROBIN:BF,ROUND_ROBIN_WITH_PLAYOFF:VF}=t.drawDefinitionConstants,HF=`Jump to prerequisite`;function UF({profile:e,availability:t,demand:n,dependencies:r,venueOrder:i}){let a=[];if(t?.isDateAvailable)for(let n of e){let e=t.isDateAvailable(n.scheduleDate);e.ok||a.push({code:`DATE_UNAVAILABLE`,severity:`ERROR`,message:`Can't schedule on ${n.scheduleDate} \u2014 day is unavailable${e.reason?`: `+e.reason:``}.`,context:{date:n.scheduleDate},fixActions:[{kind:`OPEN_AVAILABILITY_GRID`,date:n.scheduleDate,label:`Tune availability`}]})}a.push(...WF(e,t,n));let o=QF(e);for(let e of o){let t=e.round.roundSegment;t&&(Number.isInteger(t.segmentNumber)&&Number.isInteger(t.segmentsCount)&&t.segmentsCount>=2&&t.segmentNumber>=1&&t.segmentNumber<=t.segmentsCount||a.push({code:`INVALID_SEGMENT_CONFIG`,severity:`ERROR`,message:`Invalid segment configuration for ${SF(e.round)}.`,context:{locator:e.locator,date:e.locator.date,venueId:e.locator.venueId}}))}let s=new Map,c=new Map;for(let e of o){let t=e.round,n=xF(t);if(!t.roundSegment)s.has(n)?a.push({code:`DUPLICATE_ROUND`,severity:`ERROR`,message:`Round is planned more than once: ${SF(t)}.`,context:{scope:`${t.drawId}|${t.structureId}`,locator:e.locator,date:e.locator.date,venueId:e.locator.venueId},fixActions:[{kind:`JUMP_TO_ITEM`,locator:s.get(n),label:`Jump to existing`}]}):s.set(n,e.locator);else{let r=`${n}|${t.roundSegment.segmentNumber}/${t.roundSegment.segmentsCount}`;c.has(r)?a.push({code:`DUPLICATE_SEGMENT`,severity:`ERROR`,message:`Segment planned more than once: ${SF(t)}.`,context:{scope:`${t.drawId}|${t.structureId}`,locator:e.locator,date:e.locator.date,venueId:e.locator.venueId},fixActions:[{kind:`JUMP_TO_ITEM`,locator:c.get(r),label:`Jump to existing`}]}):c.set(r,e.locator)}}return a.push(...KF({profile:e,venueOrder:i})),r?.getRoundDependencies&&a.push(...XF(o,r)),a}function WF(e,t,n){if(!t?.getDayCapacityMinutes||!n?.estimateDayDemandMinutes)return[];let r=[];for(let i of e){let a=t.getDayCapacityMinutes(i.scheduleDate),o=n.estimateDayDemandMinutes(i.scheduleDate,e);if(a>0&&o>a){let e=Math.round((o-a)/60*10)/10;r.push({code:`DAY_OVERLOAD`,severity:`WARN`,message:`${i.scheduleDate} is overloaded by ~${e}h (${Math.round(o/60)}h planned vs ${Math.round(a/60)}h available).`,context:{date:i.scheduleDate},fixActions:[{kind:`OPEN_AVAILABILITY_GRID`,date:i.scheduleDate,label:`Tune availability`}]})}}return r}var GF=new Set([BF,VF]);function KF({profile:e}){let t=QF(e),n=qF(t),r=JF(t);return eI([...n,...r])}function qF(e){let t=[],n=$F(e,e=>`${e.round.structureId}|${e.locator.date}|${e.locator.venueId}`);for(let[e,r]of n.entries()){let n=r[0]?.round.structureType;if(!(n&&GF.has(n))){r.sort((e,t)=>e.locator.index-t.locator.index);for(let n=0;n<r.length;n++){let i=r[n],a=null;for(let e=n-1;e>=0;e--)if(r[e].round.roundNumber>i.round.roundNumber){a=r[e];break}if(!a)continue;let o=ZF(r,n,a);t.push({code:`ROUND_ORDER_VIOLATION`,severity:`ERROR`,message:`Cannot place ${SF(i.round)} before ${SF(a.round)} in this venue.`,context:{scope:e,drawId:i.round.drawId,structureId:i.round.structureId,date:i.locator.date,venueId:i.locator.venueId,locator:i.locator,prerequisite:a.locator},fixActions:[{kind:`JUMP_TO_ITEM`,locator:a.locator,label:HF},...o.moveOffenderAfter?[{kind:`MOVE_ITEM_AFTER`,locator:i.locator,after:o.moveOffenderAfter,label:`Move offending round after prerequisite set`}]:[],...o.movePrereqBefore?[{kind:`MOVE_ITEM_BEFORE`,locator:a.locator,before:o.movePrereqBefore,label:`Move prerequisite before offending round`}]:[]]})}}}return t}function JF(e){let t=[],n=$F(e,e=>e.round.structureId);for(let[e,r]of n.entries()){let n=r[0]?.round.structureType;if(n&&GF.has(n))continue;let i=new Map;for(let e of r){let t=e.locator.date,n=i.get(t);n?n.push(e):i.set(t,[e])}let a=[...i.keys()].sort();if(a.length<2)continue;let o=-1/0,s=null;for(let n of a){let r=i.get(n);for(let i of r)i.round.roundNumber<o&&s&&t.push({code:`ROUND_ORDER_VIOLATION`,severity:`ERROR`,message:`${SF(s.round)} is scheduled on ${s.locator.date} but its prerequisite ${SF(i.round)} is on the later date ${n}.`,context:{scope:`cross-date|${e}`,drawId:s.round.drawId,structureId:e,date:s.locator.date,venueId:s.locator.venueId,locator:s.locator,prerequisite:i.locator,reason:`cross-date`},fixActions:[{kind:`JUMP_TO_ITEM`,locator:i.locator,label:HF}]});for(let e of r)e.round.roundNumber>o&&(o=e.round.roundNumber,s=e)}}return t}function YF(e,t){if(e.round.structureId!==t.round.structureId||e.locator.date!==t.locator.date||e.locator.venueId!==t.locator.venueId){if(e.locator.date<t.locator.date)return{code:`DEPENDENCY_VIOLATION`,severity:`ERROR`,message:`${SF(e.round)} is scheduled on ${e.locator.date} but depends on ${SF(t.round)} which is on the later date ${t.locator.date}.`,context:{date:e.locator.date,venueId:e.locator.venueId,locator:e.locator,prerequisite:t.locator,reason:`cross-date`},fixActions:[{kind:`JUMP_TO_ITEM`,locator:t.locator,label:HF}]};if(e.locator.date===t.locator.date&&e.locator.venueId===t.locator.venueId&&e.locator.index<t.locator.index)return{code:`DEPENDENCY_VIOLATION`,severity:`ERROR`,message:`${SF(e.round)} is listed before its prerequisite ${SF(t.round)} in the same venue on ${e.locator.date}.`,context:{date:e.locator.date,venueId:e.locator.venueId,locator:e.locator,prerequisite:t.locator,reason:`cross-structure-same-day`},fixActions:[{kind:`JUMP_TO_ITEM`,locator:t.locator,label:HF},{kind:`MOVE_ITEM_AFTER`,locator:e.locator,after:t.locator,label:`Move after prerequisite`},{kind:`MOVE_ITEM_BEFORE`,locator:t.locator,before:e.locator,label:`Move prerequisite before`}]}}}function XF(e,t){let n=[],r=$F(e,e=>xF(e.round));for(let[e,i]of r.entries()){let a=t.getRoundDependencies(e);if(a.length)for(let e of a){let t=r.get(e);if(t)for(let e of i)for(let r of t){let t=YF(e,r);t&&n.push(t)}}}return eI(n)}function ZF(e,t,n){let r=e[t],i=e.indexOf(n);for(let t=i+1;t<e.length;t++)e[t].round.roundNumber>=n.round.roundNumber&&(i=t);return{moveOffenderAfter:e[i].locator,movePrereqBefore:r.locator}}function QF(e){let t=[];for(let n of e)for(let e of n.venues)for(let r=0;r<e.rounds.length;r++){let i=e.rounds[r];t.push({round:i,locator:{date:n.scheduleDate,venueId:e.venueId,index:r,roundKey:wF(i),roundSegment:i.roundSegment}})}return t}function $F(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function eI(e){let t=new Set,n=[];for(let r of e){let e=r.code+`|`+r.message+`|`+(r.context?.scope??``)+`|`+JSON.stringify(r.context?.locator??{});t.has(e)||(t.add(e),n.push(r))}return n}function tI(e){let t={ERROR:[],WARN:[],INFO:[]},n={},r={},i={},a={total:e.length,ERROR:0,WARN:0,INFO:0,byDate:{},byVenue:{},byDraw:{}},o=e=>e===`ERROR`?0:e===`WARN`?1:2,s=(e,t)=>o(e.severity)-o(t.severity)||e.code.localeCompare(t.code)||e.message.localeCompare(t.message);for(let o of e){t[o.severity].push(o),a[o.severity]++;let e=o.context?.date??o.context?.locator?.date,s=o.context?.venueId??o.context?.locator?.venueId,c=o.context?.scope??(o.context?.drawId&&o.context?.structureId?`${o.context.drawId}|${o.context.structureId}`:void 0);e&&(n[e]??=[]).push(o),s&&(r[s]??=[]).push(o),c&&(i[c]??=[]).push(o),nI(a.byDate,e,o.severity),nI(a.byVenue,s,o.severity),nI(a.byDraw,c,o.severity)}for(let e of Object.keys(t))t[e].sort(s);for(let e of[n,r,i])for(let t of Object.keys(e))e[t].sort(s);return{all:e,bySeverity:t,byDate:n,byVenue:r,byDraw:i,counts:a}}function nI(e,t,n){if(!t)return;let r=e[t]??={total:0,ERROR:0,WARN:0,INFO:0};r.total++,r[n]++}function rI(e,t,n){let r=yF(e),{date:i,venueId:a}=n,o=aI(iI(r,i),a);if(t.type===`CATALOG_ROUND`){let e={tournamentId:t.roundRef.tournamentId,eventId:t.roundRef.eventId,eventName:t.roundRef.eventName,drawId:t.roundRef.drawId,drawName:t.roundRef.drawName,structureId:t.roundRef.structureId,structureType:t.roundRef.structureType,roundNumber:t.roundRef.roundNumber,roundName:t.roundRef.roundName};t.roundSegment&&(e.roundSegment=t.roundSegment);let i=bF(n.index,0,o.rounds.length);return o.rounds.splice(i,0,e),oI(o.rounds),{ok:!0,profile:r}}if(t.type===`PLANNED_ROUND`){let{locator:e}=t,s=aI(iI(r,e.date),e.venueId),[c]=s.rounds.splice(e.index,1);oI(s.rounds);let l=n.index;return e.date===i&&e.venueId===a&&e.index<l&&--l,l=bF(l,0,o.rounds.length),o.rounds.splice(l,0,c),oI(o.rounds),{ok:!0,profile:r}}return{ok:!1,profile:e}}function iI(e,t){let n=e.find(e=>e.scheduleDate===t);return n||(n={scheduleDate:t,venues:[]},e.push(n),e.sort((e,t)=>e.scheduleDate.localeCompare(t.scheduleDate))),n}function aI(e,t){let n=e.venues.find(e=>e.venueId===t);return n||(n={venueId:t,rounds:[]},e.venues.push(n)),n}function oI(e){for(let t=0;t<e.length;t++)e[t].sortOrder=t+1}function sI(e,t,n){return e.find(e=>e.scheduleDate===t)?.venues?.find(e=>e.venueId===n)?.rounds??[]}function cI(e,t){return(e.find(e=>e.scheduleDate===t.date)?.venues?.find(e=>e.venueId===t.venueId))?.rounds?.[t.index]??null}function lI(e,t){return e.filter(e=>uI(e.context?.locator,t)||uI(e.context?.prerequisite,t))}function uI(e,t){return!!e&&e.date===t.date&&e.venueId===t.venueId&&e.index===t.index}function dI(e){return e.length?e.some(e=>e.severity===`ERROR`)?`ERROR`:e.some(e=>e.severity===`WARN`)?`WARN`:`INFO`:null}function fI(e,t){let n=xF(t);for(let t of e)for(let e of t.venues)for(let r=0;r<e.rounds.length;r++){let i=e.rounds[r];if(xF(wF(i))===n)return{date:t.scheduleDate,venueId:e.venueId,index:r,roundKey:wF(i),roundSegment:i.roundSegment}}return null}var pI=class{constructor(e){this.listeners=new Set,this.config=e;let t={all:[],bySeverity:{ERROR:[],WARN:[],INFO:[]},byDate:{},byVenue:{},byDraw:{},counts:{total:0,ERROR:0,WARN:0,INFO:0,byDate:{},byVenue:{},byDraw:{}}};this.state={profileDraft:yF(e.initialProfile??[]),venues:e.venues,roundCatalog:e.roundCatalog,schedulableDates:e.schedulableDates,activeDates:e.activeDates,selectedDate:e.selectedDate??e.schedulableDates[0]??null,selectedLocator:null,ruleResults:[],issueIndex:t,catalogSearchQuery:``,catalogGroupBy:`event`,plannedRoundBehavior:e.plannedRoundBehavior??`dim`},this.revalidate()}getState(){return this.state}getSchedulingProfile(){return yF(this.state.profileDraft)}selectDate(e){this.state.selectedDate!==e&&this.setState({selectedDate:e,selectedLocator:null})}selectCard(e){this.setState({selectedLocator:e})}setCatalogSearch(e){this.setState({catalogSearchQuery:e})}setCatalogGroupBy(e){this.setState({catalogGroupBy:e})}navigateToRound(e){let t=fI(this.state.profileDraft,{tournamentId:e.tournamentId,eventId:e.eventId,drawId:e.drawId,structureId:e.structureId,roundNumber:e.roundNumber});t&&this.setState({selectedDate:t.date,selectedLocator:t})}dropRound(e,t){try{let n=rI(this.state.profileDraft,e,t);if(!n.ok)return{ok:!1,errorMessage:`Invalid drop operation`};let r=new Set(this.state.ruleResults.filter(e=>e.severity===`ERROR`).map(mI)),i=UF({profile:n.profile,availability:this.config.availabilityAdapter,demand:this.config.demandAdapter,dependencies:this.config.dependencyAdapter,venueOrder:this.config.venueOrder}).filter(e=>e.severity===`ERROR`).filter(e=>!r.has(mI(e)));return i.length?(this.addRejectionNotice(i[0].message),{ok:!1,errorMessage:i[0].message}):(this.commitProfile(n.profile),{ok:!0})}catch(e){return{ok:!1,errorMessage:String(e)}}}removeRound(e){let t=yF(this.state.profileDraft),n=t.find(t=>t.scheduleDate===e.date);if(!n)return;let r=n.venues.find(t=>t.venueId===e.venueId);if(r&&!(e.index<0||e.index>=r.rounds.length)){r.rounds.splice(e.index,1);for(let e=0;e<r.rounds.length;e++)r.rounds[e].sortOrder=e+1;this.commitProfile(t),this.state.selectedLocator?.date===e.date&&this.state.selectedLocator?.venueId===e.venueId&&this.state.selectedLocator?.index===e.index&&this.setState({selectedLocator:null})}}setNotBeforeTime(e,t){let n=yF(this.state.profileDraft),r=n.find(t=>t.scheduleDate===e.date);if(!r)return;let i=r.venues.find(t=>t.venueId===e.venueId);if(!i)return;let a=i.rounds[e.index];a&&(t?a.notBeforeTime=t:delete a.notBeforeTime,this.commitProfile(n))}applyFixAction(e){if(e.kind===`JUMP_TO_ITEM`&&e.locator){this.setState({selectedDate:e.locator.date,selectedLocator:e.locator});return}if(e.kind===`OPEN_AVAILABILITY_GRID`){this.config.onFixAction?.(e);return}if(e.kind===`MOVE_ITEM_AFTER`&&e.locator&&e.after){let t=hI(this.state.profileDraft,e.locator,e.after);this.commitProfile(t);return}if(e.kind===`MOVE_ITEM_BEFORE`&&e.locator&&e.before){let t=gI(this.state.profileDraft,e.locator,e.before);this.commitProfile(t);return}this.config.onFixAction?.(e)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setState(e){this.state={...this.state,...e},this.emit()}commitProfile(e){this.state={...this.state,profileDraft:e},this.revalidate(),this.config.onProfileChanged?.(yF(e))}addRejectionNotice(e){let t={code:`DROP_REJECTED`,severity:`WARN`,message:`Drop rejected: ${e}`,context:{}},n=[...this.state.ruleResults.filter(e=>e.code!==`DROP_REJECTED`),t],r=tI(n);this.state={...this.state,ruleResults:n,issueIndex:r},this.emit()}revalidate(){let e=UF({profile:this.state.profileDraft,availability:this.config.availabilityAdapter,demand:this.config.demandAdapter,dependencies:this.config.dependencyAdapter,venueOrder:this.config.venueOrder}),t=tI(e);this.state={...this.state,ruleResults:e,issueIndex:t},this.emit()}emit(){for(let e of this.listeners)e(this.state)}};function mI(e){return`${e.code}|${e.context?.scope??``}|${e.context?.structureId??``}|${e.context?.date??``}`}function hI(e,t,n){let r=yF(e),i=_I(r,t);if(!i)return e;let a=vI(r,n.date,n.venueId),o=Math.min(a.length,n.index+1);return a.splice(o,0,i),r}function gI(e,t,n){let r=yF(e),i=_I(r,t);if(!i)return e;let a=vI(r,n.date,n.venueId),o=Math.max(0,Math.min(a.length,n.index));return a.splice(o,0,i),r}function _I(e,t){let n=e.find(e=>e.scheduleDate===t.date);if(!n)return null;let r=n.venues.find(e=>e.venueId===t.venueId);return!r||t.index<0||t.index>=r.rounds.length?null:r.rounds.splice(t.index,1)[0]}function vI(e,t,n){let r=e.find(e=>e.scheduleDate===t);r||(r={scheduleDate:t,venues:[]},e.push(r));let i=r.venues.find(e=>e.venueId===n);return i||(i={venueId:n,rounds:[]},r.venues.push(i)),i.rounds}function yI(e,t){let{round:n,locator:r,isSelected:i,severity:a}=e,o=document.createElement(`div`);o.className=JP(),i&&o.classList.add(`selected`),a===`ERROR`?o.classList.add(`error`):a===`WARN`&&o.classList.add(`warn`),o.draggable=!0,o.addEventListener(`dragstart`,e=>{e.stopPropagation(),e.dataTransfer.setDragImage(o,o.offsetWidth/2,20),e.dataTransfer.setData(`application/json`,JSON.stringify({type:`PLANNED_ROUND`,locator:r})),e.dataTransfer.effectAllowed=`copyMove`}),o.addEventListener(`click`,e=>{e.stopPropagation(),t.onClick(r)}),t.onContextMenu&&o.addEventListener(`contextmenu`,e=>{e.preventDefault(),e.stopPropagation(),t.onContextMenu(r,o)});let s=document.createElement(`div`);s.className=YP();let c=n.roundName&&!n.roundName.startsWith(`rn=`)?n.roundName:`Round `+n.roundNumber;s.textContent=(n.eventName?n.eventName+` — `:``)+c,o.appendChild(s);let l=document.createElement(`div`);l.className=XP(),l.textContent=[n.drawName||``,n.matchCountEstimate?`${n.matchCountEstimate} matches`:``].filter(Boolean).join(` · `),o.appendChild(l);let u=document.createElement(`div`);return u.className=BP(),n.roundSegment&&u.appendChild(bI(`Seg ${n.roundSegment.segmentNumber}/${n.roundSegment.segmentsCount}`,`seg`)),n.notBeforeTime&&u.appendChild(bI(`NB ${n.notBeforeTime}`,`nb`)),a===`ERROR`?u.appendChild(bI(`Error`,`err`)):a===`WARN`&&u.appendChild(bI(`Warn`,`warn`)),u.children.length&&o.appendChild(u),o}function bI(e,t){let n=document.createElement(`div`);return n.className=VP()+` `+t,n.textContent=e,n}function xI(e,t){let n=document.createElement(`div`);n.className=AP();let r=document.createElement(`div`);r.className=jP();let i=t?.titleLeadingActions,a=document.createElement(`div`);if(a.className=MP(),a.textContent=`Day Plan`,i){let e=document.createElement(`div`);e.className=FP();let t=Array.isArray(i)?i:[i];for(let n of t)e.appendChild(n);e.appendChild(a),r.appendChild(e)}else r.appendChild(a);let o=t?.headerActions;if(o){let e=document.createElement(`div`);e.className=PP();let t=Array.isArray(o)?o:[o];for(let n of t)e.appendChild(n);r.appendChild(e)}n.appendChild(r);let s=document.createElement(`div`);s.className=HP(),n.appendChild(s);function c(t){let n=t.selectedDate;s.innerHTML=``;let r=Math.max(1,t.venues.length);r>4?(s.classList.add(`sp-board-scroll`),s.style.gridTemplateColumns=``):(s.classList.remove(`sp-board-scroll`),s.style.gridTemplateColumns=`repeat(${r}, 1fr)`);for(let r of t.venues){let i=document.createElement(`div`);i.className=UP();let a=document.createElement(`div`);a.className=WP();let o=document.createElement(`div`),c=document.createElement(`div`);c.className=GP(),c.textContent=r.name;let l=document.createElement(`div`);l.className=KP(),l.textContent=``,o.appendChild(c),o.appendChild(l);let u=t.issueIndex.counts.byVenue[r.venueId],d=document.createElement(`div`);d.className=zP(),u?.ERROR?(d.classList.add(`err`),d.textContent=`${u.ERROR} err`):u?.WARN?(d.classList.add(`warn`),d.textContent=`${u.WARN} warn`):(d.classList.add(`ok`),d.textContent=`OK`),a.appendChild(o),a.appendChild(d);let f=document.createElement(`div`);if(f.className=qP(),f.dataset.venue=r.venueId,n){let i=sI(t.profileDraft,n,r.venueId);if(!i.length){let e=document.createElement(`div`);e.className=dF(),e.textContent=`Drop rounds here.`,f.appendChild(e)}i.forEach((i,a)=>{let o={date:n,venueId:r.venueId,index:a,roundKey:wF(i),roundSegment:i.roundSegment},s=dI(lI(t.ruleResults,o)),c=yI({round:i,locator:o,isSelected:CF(t.selectedLocator,o),severity:s},{onClick:e.onCardClick,onContextMenu:e.onCardContextMenu});f.appendChild(c)})}else{let e=document.createElement(`div`);e.className=dF(),e.textContent=`Select a date to plan.`,f.appendChild(e)}let p=document.createElement(`div`);p.className=hF(),p.style.display=`none`,f.addEventListener(`dragover`,e=>{if(!n)return;e.preventDefault(),f.classList.add(`over`),e.dataTransfer.dropEffect=`move`;let t=CI(f,e.clientY,p),r=SI(f,p);p.style.display=``,t<r.length?f.insertBefore(p,r[t]):f.appendChild(p)}),f.addEventListener(`dragleave`,e=>{f.contains(e.relatedTarget)||(f.classList.remove(`over`),p.style.display=`none`)}),f.addEventListener(`drop`,t=>{if(f.classList.remove(`over`),p.style.display=`none`,t.preventDefault(),!n)return;let i;try{i=JSON.parse(t.dataTransfer.getData(`application/json`))}catch{return}let a=CI(f,t.clientY,p),o={date:n,venueId:r.venueId,index:a};e.onDrop(i,o)}),i.appendChild(a),i.appendChild(f),s.appendChild(i)}}return{element:n,update:c}}function SI(e,t){return Array.from(e.querySelectorAll(`[draggable="true"]`)).filter(e=>e!==t)}function CI(e,t,n){let r=SI(e,n);for(let e=0;e<r.length;e++){let n=r[e].getBoundingClientRect();if(t<n.top+n.height/2)return e}return r.length}function wI(e){let t=document.createElement(`div`);t.className=AP();let n=document.createElement(`div`);n.className=jP();let r=document.createElement(`div`);r.className=MP(),r.textContent=`Dates`;let i=document.createElement(`div`);i.className=NP(),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=IP(),t.appendChild(a);function o(t){i.textContent=`${t.schedulableDates.length} schedulable`,a.innerHTML=``;let n=t.activeDates?new Set(t.activeDates):null;for(let r of t.schedulableDates){let i=!n||n.has(r),o=t.issueIndex.counts.byDate[r],s=document.createElement(`div`);s.className=LP(),r===t.selectedDate&&s.classList.add(`selected`),i||s.classList.add(`inactive`),s.setAttribute(`data-date`,r);let c=document.createElement(`div`),l=document.createElement(`div`);l.style.cssText=`font-weight:800;font-size:12px`,l.textContent=r;let u=document.createElement(`div`);u.style.cssText=`font-size:11px;color:var(--sp-muted)`,u.textContent=i?`Active`:`Inactive`,c.appendChild(l),c.appendChild(u);let d=document.createElement(`div`);d.className=RP(),o?.ERROR&&d.appendChild(TI(`${o.ERROR} err`,`err`)),o?.WARN&&d.appendChild(TI(`${o.WARN} warn`,`warn`)),!o?.ERROR&&!o?.WARN&&d.appendChild(TI(`OK`,`ok`)),s.appendChild(c),s.appendChild(d),s.addEventListener(`click`,()=>e.onDateSelected(r)),a.appendChild(s)}}return{element:t,update:o}}function TI(e,t){let n=document.createElement(`div`);return n.className=zP()+` `+t,n.textContent=e,n}var EI=class{constructor(e){this.container=null,this.store=new pI(e),this.popover=vF({onDelete:e=>{this.store.removeRound(e)},onSetNotBeforeTime:e=>{let t=prompt(`Enter not-before time (HH:MM):`,`10:00`);t!==null&&this.store.setNotBeforeTime(e,t||void 0)}});let t=wI({onDateSelected:e=>this.store.selectDate(e)}),n=zF({onFixAction:e=>this.store.applyFixAction(e)}),r=xI({onDrop:(e,t)=>{this.store.dropRound(e,t)},onCardClick:e=>this.store.selectCard(e),onCardContextMenu:(e,t)=>{this.popover.show(t,e)}},{headerActions:e.headerActions,titleLeadingActions:e.titleLeadingActions}),i=PF({onSearchChange:e=>this.store.setCatalogSearch(e),onGroupByChange:e=>this.store.setCatalogGroupBy(e),onDropRemove:e=>this.store.removeRound(e),onNavigateToPlanned:e=>this.store.navigateToRound(e)});this.layout=_F({dateStrip:t,issuesPanel:n,venueBoard:r,roundCatalog:i},{hideLeft:e.hideLeft,catalogSide:e.catalogSide}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.layout.element)}destroy(){this.unsubscribe(),this.popover.destroy(),this.container&&this.layout.element.parentNode===this.container&&this.layout.element.remove(),this.container=null}getProfile(){return this.store.getSchedulingProfile()}getStore(){return this.store}};function DI(e,t){let n=new EI(e);return n.render(t),n}var OI=class{constructor(){this.selectedDay=null,this.selectedVenue=null,this.selectedCourt=null,this.layerVisibility=new Map,this.listeners=new Set}setSelectedDay(e){this.selectedDay!==e&&(this.selectedDay=e,this.emit({selectedDay:e}))}getSelectedDay(){return this.selectedDay}setSelectedVenue(e){this.selectedVenue!==e&&(this.selectedVenue=e,this.emit({selectedVenue:e}))}getSelectedVenue(){return this.selectedVenue}setSelectedCourt(e){this.selectedCourt!==e&&(this.selectedCourt=e,this.emit({selectedCourt:e}))}getSelectedCourt(){return this.selectedCourt}setLayerVisibility(e,t){this.layerVisibility.set(e,t),this.emit({layerVisibility:new Map(this.layerVisibility)})}getLayerVisibility(){return new Map(this.layerVisibility)}isLayerVisible(e){return this.layerVisibility.get(e)??!0}getSnapshot(){return{selectedDay:this.selectedDay,selectedVenue:this.selectedVenue,selectedCourt:this.selectedCourt,layerVisibility:new Map(this.layerVisibility)}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}emit(e){let t={type:`VIEW_CHANGED`,payload:e};for(let e of this.listeners)e(t)}},kI={AVAILABLE:`rgba(33, 141, 141, 0.15)`,BLOCKED:`#95a5a6`,PRACTICE:`#9b59b6`,MAINTENANCE:`#f39c12`,RESERVED:`#3498db`,CLOSED:`#2c3e50`,SCHEDULED:`#27ae60`,SOFT_BLOCK:`#5dade2`,HARD_BLOCK:`#e74c3c`,LOCKED:`#34495e`,UNSPECIFIED:`#ecf0f1`};function AI(e,t,n={}){let r=[],i=new Map;for(let e of t){let t=PI(e.ref);i.set(t,e)}let a=new Set;for(let t of e)for(let e of t.rails)a.add(PI(e.court));for(let e of a){let t=i.get(e);if(!t)continue;let n={id:e,content:t.name,courtRef:t.ref,surface:t.surface,indoor:t.indoor,hasLights:t.hasLights,tags:t.tags};r.push(n)}return r}function jI(e,t={}){let{layerVisibility:n=new Map,showSegmentLabels:r=!1,colorScheme:i=kI}=t,a=[];for(let t of e)for(let e of t.rails){let t=PI(e.court);for(let o of e.segments){if(!(n.get(o.status)??!0))continue;let e=`${t}-${o.start}-${o.status}`,s=i[o.status];a.push({id:e,group:t,content:r?MI(o):``,start:o.start,end:o.end,type:`background`,className:`availability-segment segment-${o.status.toLowerCase()}`,style:s===`transparent`?void 0:`background-color: ${s};`,title:`${o.status} segment`,editable:!1,selectable:!1,status:o.status,contributingBlocks:o.contributingBlocks,isSegment:!0})}}return a}function MI(e){let t=Math.round((new Date(e.end).getTime()-new Date(e.start).getTime())/6e4);return`${e.status} (${t}m)`}function NI(e,t={}){let{colorScheme:n=kI}=t,r=[];for(let t of e){let e=PI(t.court),i=n[t.type],a=FI(i,-20);r.push({id:`block-${t.id}`,group:e,content:t.reason||t.type,start:t.start,end:t.end,type:`range`,className:`availability-block block-${t.type.toLowerCase()}`,style:`background-color: ${i}; border-color: ${a};`,title:t.reason||t.type,editable:{updateTime:!0,updateGroup:!0,remove:!1},blockId:t.id,status:t.type,reason:t.reason,isBlock:!0})}return r}function PI(e){return`${e.tournamentId}|${e.venueId}|${e.courtId}`}function FI(e,t){if(!e||!e.startsWith(`#`))return e;let n=parseInt(e.replace(`#`,``),16),r=Math.round(2.55*t),i=(n>>16)+r,a=(n>>8&255)+r,o=(n&255)+r;return`#`+(16777216+(i<255?i<1?0:i:255)*65536+(a<255?a<1?0:a:255)*256+(o<255?o<1?0:o:255)).toString(16).slice(1)}function II(e){let t=e.split(`|`);return t.length===3?{tournamentId:t[0],venueId:t[1],courtId:t[2]}:null}function LI(e){let t=String(e);return t.startsWith(`block-`)?t.slice(6):null}function RI(e){let t=new Date(`${e.day}T${e.dayStartTime}:00`),n=new Date(`${e.day}T${e.dayEndTime}:00`);return{start:t,end:n,min:t,max:n,zoomMin:e.slotMinutes*4*60*1e3,zoomMax:(n.getTime()-t.getTime())*1.5}}var zI=_({EventEmitter:()=>IR,PluginRegistry:()=>CL,TimepickerUI:()=>VR,default:()=>HR});function BI(){PL===0&&(FL=document.body.style.overflowY,IL=document.body.style.paddingRight,document.body.style.paddingRight=`${fL()}px`,document.body.style.overflowY=`hidden`),PL+=1}function VI(){PL!==0&&(--PL,PL===0&&(document.body.style.overflowY=FL,document.body.style.paddingRight=IL,FL=``,IL=``))}function HI(e){let t=e.match(pR);return t?{hour:t[1],minutes:t[2],type:t[3].toUpperCase()}:null}function UI(e){let t=e.match(mR);return t?{hour:t[1],minutes:t[2]}:null}function WI(e,t){let n=parseInt(e.hour,10),r=parseInt(e.minutes,10);if(Number.isNaN(n)||Number.isNaN(r))return 0;if(t===`12h`&&e.type){let t=e.type.toUpperCase();t===`PM`&&n!==12&&(n+=12),t===`AM`&&n===12&&(n=0)}return n*60+r}function GI(e,t){if(t===`12h`){let t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);return t?WI({hour:t[1],minutes:t[2],type:t[3]},`12h`):0}let[n,r]=e.split(`:`);return WI({hour:n??`0`,minutes:r??`0`},`24h`)}function KI(e,t,n,r){e.on(n,r),t.push(()=>e.off(n,r))}function qI(e){let t=e.target,n=t.hasAttribute(`data-md3-ripple`)?t:t.closest(`[data-md3-ripple]`);if(!n||e.button!==0&&e.pointerType===`mouse`)return;let r=n.getBoundingClientRect(),i=Math.max(r.width,r.height)*2,a=e.clientX-r.left,o=e.clientY-r.top;n.style.setProperty(`--ripple-size`,`${i}px`),n.style.setProperty(`--ripple-x`,`${a}px`),n.style.setProperty(`--ripple-y`,`${o}px`),n.classList.remove(kR,AR),n.offsetWidth,n.classList.add(kR,AR),n._rippleHold=!0,jR=n}function JI(e){let t=e.target,n=(t.hasAttribute(`data-md3-ripple`)?t:t.closest(`[data-md3-ripple]`))||jR;n&&(n._rippleHold=!1,n.classList.remove(AR),setTimeout(()=>{n.classList.remove(kR),jR===n&&(jR=null)},1e3))}function YI(e){let t=e.currentTarget;!t||!t._rippleHold||(t._rippleHold=!1,t.classList.remove(AR),setTimeout(()=>{t.classList.remove(kR),jR===t&&(jR=null)},1e3))}function XI(e){if(cL()===!1)return;let t=e||document;t.addEventListener(`pointerdown`,qI),t.addEventListener(`pointerup`,JI),t.addEventListener(`pointercancel`,JI),t.querySelectorAll(`[data-md3-ripple]`).forEach(e=>{e.addEventListener(`mouseleave`,YI)})}function ZI(e){let t=e.ui.mode;return t===`wheel`||t===`compact-wheel`}function QI(e){return e.ui.mode===`compact-wheel`}function $I(e){return QI(e)&&!!e.wheel?.placement}function eL(e,t){let{callbacks:n}=e.options;for(let[e,r]of NR){let i=n[e];i&&t.on(r,i)}}function tL(e,t){for(let n of PR)n.needed(e.options)&&!CL.has(n.name)&&t.emit(`error`,{error:n.message})}function nL(e={}){let t={clock:{...LR.clock,...e.clock},ui:{...LR.ui,...e.ui},labels:{...LR.labels,...e.labels},behavior:{...LR.behavior,...e.behavior},callbacks:{...LR.callbacks,...e.callbacks},timezone:{...LR.timezone,...e.timezone},range:{...LR.range,...e.range},wheel:{...LR.wheel,...e.wheel},clearBehavior:{...LR.clearBehavior,...e.clearBehavior}},n=t.ui.mode;return(n===`wheel`||n===`compact-wheel`)&&(t.wheel={placement:n===`compact-wheel`?`auto`:void 0,hideFooter:void 0,commitOnScroll:void 0,ignoreOutsideClick:void 0,...t.wheel}),t}function rL(e,t){if(e.options.clock.type===`24h`){let e=UI(t);if(!e)throw Error(`Invalid 24h format. Expected HH:MM`);return{hourValue:e.hour.padStart(2,`0`),minutesValue:e.minutes,typeValue:`AM`}}let n=HI(t);if(!n)throw Error(`Invalid 12h format. Expected HH:MM AM/PM`);return{hourValue:n.hour,minutesValue:n.minutes,typeValue:n.type}}function iL(e,t){let n=e.getHour(),r=e.getMinutes();n&&(n.value=t.hourValue,n.setAttribute(`aria-valuenow`,t.hourValue),e.setDegreesHours(Number(t.hourValue)*30)),r&&(r.value=t.minutesValue,r.setAttribute(`aria-valuenow`,t.minutesValue),e.setDegreesMinutes(Number(t.minutesValue)*6))}function aL(e,t){if(e.options.clock.type===`24h`)return;let n=e.getAM(),r=e.getPM();!n||!r||(t===`AM`?(n.classList.add(`active`),r.classList.remove(`active`)):(r.classList.add(`active`),n.classList.remove(`active`)))}function oL(e,t,n){if(ZI(e.options))t.getPlugin(`wheel`)?.scrollToValue?.(n.hourValue,n.minutesValue,n.typeValue);else{let t=e.getClockHand();t&&(t.style.transform=`rotateZ(${e.degreesHours||0}deg)`)}}var sL,cL,lL,uL,dL,fL,pL,mL,hL,gL,_L,vL,yL,bL,xL,SL,CL,wL,TL,EL,DL,OL,kL,AL,jL,ML,NL,PL,FL,IL,LL,RL,zL,BL,VL,HL,UL,WL,GL,KL,qL,JL,YL,XL,ZL,QL,$L,eR,tR,nR,rR,iR,aR,oR,sR,cR,lR,uR,dR,fR,pR,mR,hR,gR,_R,vR,yR,bR,xR,SR,CR,wR,TR,ER,DR,OR,kR,AR,jR,MR,NR,PR,FR,IR,LR,RR,zR,BR,VR,HR,UR=h((()=>{sL=()=>typeof window>`u`,cL=()=>typeof document<`u`,lL=class{_degreesHours=null;_degreesMinutes=null;_options;_isMobileView=!1;_isTouchMouseMove=!1;_disabledTime=null;_cloned=null;_isModalRemove=!0;_isOpen=!1;_isInitialized=!1;_eventHandlersRegistered=!1;_isDestroyed=!1;element;instanceId;customId;constructor(e,t,n,r){this.element=e,this.instanceId=n,this.customId=r,this._options=t}get degreesHours(){return this._degreesHours}get degreesMinutes(){return this._degreesMinutes}get options(){return this._options}get isMobileView(){return this._isMobileView}get isTouchMouseMove(){return this._isTouchMouseMove}get disabledTime(){return this._disabledTime}get cloned(){return this._cloned}get isModalRemove(){return this._isModalRemove}get isOpen(){return this._isOpen}get isInitialized(){return this._isInitialized}get eventHandlersRegistered(){return this._eventHandlersRegistered}get isDestroyed(){return this._isDestroyed}setDegreesHours(e){this._degreesHours=e}setDegreesMinutes(e){this._degreesMinutes=e}setOptions(e){this._options=e}setIsMobileView(e){this._isMobileView=e}setIsTouchMouseMove(e){this._isTouchMouseMove=e}setDisabledTime(e){this._disabledTime=e}setCloned(e){this._cloned=e}setIsModalRemove(e){this._isModalRemove=e}setIsOpen(e){this._isOpen=e}setIsInitialized(e){this._isInitialized=e}setEventHandlersRegistered(e){this._eventHandlersRegistered=e}setIsDestroyed(e){this._isDestroyed=e}updateOptions(e){this._options={...this._options,clock:{...this._options.clock,...e.clock||{}},ui:{...this._options.ui,...e.ui||{}},labels:{...this._options.labels,...e.labels||{}},behavior:{...this._options.behavior,...e.behavior||{}},callbacks:{...this._options.callbacks,...e.callbacks||{}}}}reset(){this._degreesHours=null,this._degreesMinutes=null,this._isTouchMouseMove=!1,this._disabledTime=null,this._cloned=null,this._isModalRemove=!0,this._isOpen=!1,this._isInitialized=!1,this._isDestroyed=!0,this._eventHandlersRegistered=!1}q(e){return this.getModalElement()?.querySelector(e)??null}qMobile(e,t){return this._isMobileView?this.q(e):this.q(t)}getModalElement(){return cL()===!1?null:document.querySelector(`[data-owner-id="${this.instanceId}"]`)}getInput(){return this.element?.querySelector(`input`)}getClockFace(){return this.qMobile(`.tp-ui-clock-face.mobile`,`.tp-ui-clock-face:not(.mobile)`)}getClockHand(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-clock-hand`,`.tp-ui-clock-hand:not(.mobile)`)}getCircle(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-circle-hand`,`.tp-ui-circle-hand:not(.mobile)`)}getTipsWrapper(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper`,`.tp-ui-tips-wrapper:not(.mobile)`)}getTipsWrapperFor24h(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper-24h`,`.tp-ui-tips-wrapper-24h:not(.mobile)`)}getMinutes(){return this.q(`.tp-ui-minutes`)}getHour(){return this.q(`.tp-ui-hour`)}getAM(){return this.q(`.tp-ui-am`)}getPM(){return this.q(`.tp-ui-pm`)}getHourText(){return this.q(`.tp-ui-hour-text`)}getMinutesText(){return this.q(`.tp-ui-minute-text`)}getHeader(){return this.q(`.tp-ui-header`)}getInputWrappers(){return this.getModalElement()?.querySelectorAll(`.tp-ui-input-wrapper`)||null}getDots(){return this.q(`.tp-ui-dots`)}getMinutesTips(){return this.q(`.tp-ui-minutes-time`)}getHourTips(){return this.q(`.tp-ui-hour-time-12`)}getAllValueTips(){let e=this.getModalElement();return e?[...e.querySelectorAll(`.tp-ui-value-tips`),...e.querySelectorAll(`.tp-ui-value-tips-24h`)]:[]}getOpenElementData(){let e=this.element?.querySelectorAll(`[data-open]`);if(e?.length>0){let t=[];return e.forEach(({dataset:e})=>t.push(e.open??``)),[...new Set(t)]}return null}getOpenElement(){let e=this.getInput(),t=this.getOpenElementData();return t===null?(e?.setAttribute(`data-open`,`tp-ui-input`),[e]):t.map(e=>this.element?.querySelectorAll(`[data-open='${e}']`))[0]??``}getCancelButton(){return this.q(`.tp-ui-cancel-btn`)}getOkButton(){return this.q(`.tp-ui-ok-btn`)}getActiveTypeMode(){return this.q(`.tp-ui-type-mode.active`)}getKeyboardClockIcon(){return this.q(`.tp-ui-keyboard-icon-wrapper`)}getFooter(){return this.q(`.tp-ui-footer`)}getWrapper(){return this.q(`.tp-ui-wrapper`)}},uL={DEFAULT_DELAY:300,MODAL_ANIMATION:150,SCROLLBAR_RESTORE:400,MODAL_REMOVE:300,CLOCK_ANIMATION:600,TIPS_ANIMATION:401,MOBILE_TOGGLE:450,CLOCK_SCALE_DELAY:150,WRAPPER_TRANSITION:400,DROPDOWN_CLICK_DELAY:10},dL=class{core;emitter;timeouts=[];constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on(`animation:clock`,()=>{this.handleAnimationSwitchTipsMode()})}runWithAnimation(e,t=uL.MODAL_ANIMATION){if(this.core.options.ui.animation){let n=setTimeout(e,t);this.timeouts.push(n)}else e()}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}setAnimationToOpen(){this.clearAllTimeouts(),this.core.getModalElement()?.classList.add(`opacity`),this.runWithAnimation(()=>{this.core.getModalElement()?.classList.add(`show`)})}removeAnimationToClose(){this.clearAllTimeouts(),this.core.getModalElement()&&this.runWithAnimation(()=>{let e=this.core.getModalElement();e?.classList.remove(`show`),e?.classList.remove(`opacity`)})}handleAnimationClock(){this.core.options.ui.animation&&this.runWithAnimation(()=>{this.core.getClockFace()?.classList.add(`tp-ui-clock-animation`);let e=setTimeout(()=>{this.core.getClockFace()?.classList.remove(`tp-ui-clock-animation`)},uL.CLOCK_ANIMATION);this.timeouts.push(e)})}handleAnimationSwitchTipsMode(){let e=this.core.getClockHand();if(!e)return;this.emitter.emit(`animation:start`,{}),e.classList.add(`tp-ui-tips-animation`);let t=setTimeout(()=>{this.core.getClockHand()?.classList.remove(`tp-ui-tips-animation`),this.emitter.emit(`animation:end`,{})},uL.TIPS_ANIMATION);this.timeouts.push(t)}destroy(){this.clearAllTimeouts()}},fL=()=>{if(cL()===!1)return 0;let e=document.createElement(`div`);e.className=`tp-ui-measure`,document.body.appendChild(e);let t=e.getBoundingClientRect().width-e.clientWidth;return document.body.removeChild(e),t},pL=(e,t)=>e?e.classList.contains(t):!1,mL=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(t,n)=>Number(e)+n),hL=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(e,n)=>Number(t)-n).reverse(),gL=(e=``)=>{let t=e.replace(/(AM|PM|am|pm)/,e=>` ${e}`),n=new Date(`September 20, 2000 ${t}`);return`${n.getHours().toString().padStart(2,`0`)}:${n.getMinutes().toString().padStart(2,`0`)}`},_L=e=>{let[t,n]=e.split(`:`);return`${t.padStart(2,`0`)}:${n.padStart(2,`0`)}`},vL=(e,t)=>{if(e.length<2)return!1;let n=e.map(e=>{let[n,r]=e.trim().split(`-`),i,a;if(t===`12h`){if(!/\s?(AM|PM|am|pm)\s?$/.test(n.trim())||!/\s?(AM|PM|am|pm)\s?$/.test(r.trim()))throw Error(`Invalid 12h format: "${e}"`);i=gL(n.trim()),a=gL(r.trim())}else{if(/\s?(AM|PM|am|pm)\s?/.test(n.trim())||/\s?(AM|PM|am|pm)\s?/.test(r.trim()))throw Error(`Invalid 24h format: "${e}"`);i=_L(n.trim()),a=_L(r.trim())}return{start:i,end:a,original:e}});for(let e=0;e<n.length;e++)for(let t=e+1;t<n.length;t++){let r=n[e],i=n[t];if(r.start<=i.end&&r.end>=i.start||i.start<=r.end&&i.end>=r.start)throw Error(`Overlapping intervals: "${r.original}" and "${i.original}"`)}return!1},yL=()=>typeof window<`u`&&window.crypto&&typeof window.crypto.randomUUID==`function`?window.crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),bL=`<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-200q-33 0-56.5-23.5T80-280v-400q0-33 23.5-56.5T160-760h640q33 0 56.5 23.5T880-680v400q0 33-23.5 56.5T800-200H160Zm0-80h640v-400H160v400Zm160-40h320v-80H320v80ZM200-440h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM200-560h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM160-280v-400 400Z"/></svg>`,xL=`<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z"/></svg>`,SL=class{plugins=new Map;register(e){this.plugins.has(e.name)||this.plugins.set(e.name,e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get(e){return this.plugins.get(e)}getTemplateProvider(e){return this.plugins.get(e)?.templateProvider}getClearHandler(e){return this.plugins.get(e)?.clearHandler}},CL=new SL,wL=[`00`,`13`,`14`,`15`,`16`,`17`,`18`,`19`,`20`,`21`,`22`,`23`],TL=[`12`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`],EL=[`00`,`05`,`10`,`15`,`20`,`25`,`30`,`35`,`40`,`45`,`50`,`55`],DL=(e,t,n)=>{let{timezone:{enabled:r,label:i}}=e;return!r||!CL.has(`timezone`)?``:`<div class="tp-ui-timezone ${t}">
224
+ `;z.open({title:t,content:p,buttons:d,onClose:f});let m=e=>{e?.[0]?.onClick&&(e[0].onClick(),z.close())};if(a){let e=a({anchorId:c,data:r,selectionLimit:i,onSelected:m});l=e.table,u=e.destroy;let t=o?o(l):()=>{},d=[{onKeyDown:e=>e.keyCode===8&&e.target.value.length===1&&t(``),onChange:e=>t(e.target.value),onKeyUp:e=>t(e.target.value),clearSearch:()=>t(``),placeholder:n||`Search`,location:yF,search:!0}],f=document.getElementById(s)||void 0;VF({table:l,target:f,items:d})}else{let e=document.getElementById(c);if(e){xF({container:e,options:r,onSelected:m});let t=t=>{let n=e.querySelectorAll(`[data-select-item]`),r=t.toLowerCase();n.forEach(e=>{let n=e.textContent?.toLowerCase()||``;e.style.display=!t||n.includes(r)?``:`none`})},i=[{onKeyUp:e=>t(e.target.value),clearSearch:()=>t(``),placeholder:n||`Search`,location:yF,search:!0}];VF({target:document.getElementById(s)||void 0,items:i})}}}function xF({container:e,options:t,onSelected:n}){let r=document.createElement(`div`);r.style.cssText=`max-height: 380px; overflow-y: auto; padding: 0.5em 0;`;for(let e of t){let t=document.createElement(`a`);t.setAttribute(`data-select-item`,``),t.className=`panel-block font-medium`,t.style.cssText=`cursor: pointer; padding: 0.5em 1em; display: block; text-decoration: none; color: inherit;`,t.innerHTML=e.label,t.onmouseenter=()=>t.style.backgroundColor=`#f5f5f5`,t.onmouseleave=()=>t.style.backgroundColor=``,t.onclick=t=>{t.stopPropagation(),n([e])},r.appendChild(t)}e.appendChild(r)}var SF=`none`;function CF(e){let t=document.createElement(`button`);return t.className=`button font-medium`,e.disabled&&(t.disabled=!0),e.class&&t.classList.add(e.class),e.id&&(t.id=e.id),e.intent&&t.classList.add(e.intent),e.toolTip?.content&&km(t,e.toolTip),t.innerHTML=e.label,e.visible===!1&&(t.style.display=SF),t}var wF=`center`,TF=``,EF=`flex`,DF=`left`,OF=`none`,kF=`overlay`,AF=`right`,jF=({target:e})=>(t=[])=>{e.style.backgroundColor=t?.length?`var(--chc-hover-bg)`:TF;let n=(n,r,i)=>{let a=e.getElementsByClassName(`options_${n}`)[0];a&&(a.style.display=t?.length?r:i)};n(kF,EF,OF),n(DF,OF,EF),n(wF,OF,EF),n(AF,OF,EF)},MF=`center`,NF=`header`,PF=``,FF=`left`,IF=`none`,LF=`overlay`,RF=`right`,zF=`buttonBar`,BF=`top`;function VF(e){let{table:t,targetClassName:n,items:r=[],onSelection:i,selectItemFn:a}=e,{target:o}=e,s=!!o;if(!o&&n&&(o=document.getElementsByClassName(n)?.[0]),!o)return{elements:{},inputs:{}};let c=0,l=0,u={},d={},f;if(s){ne(o);let e=YF();Object.assign(u,e.elements),o.appendChild(e.anchor)}let p=Object.assign({},...[LF,FF,MF,RF,NF].map(e=>{let t=o.getElementsByClassName(`options_${e}`)?.[0];return ne(t),{[e]:t}}).filter(Boolean)),m=jF({table:t,target:o}),h=(e,n)=>{V(n.onClick)&&(e.stopPropagation(),n.disabled||n.onClick(e,t),n.stateChange&&m())},g={onClick:()=>{},location:RF};for(let e of r){let t={...g};oe(e)&&Object.assign(t,e);let n=p[t.location];if(!n){console.log(t.location,p);continue}t.location===LF&&(c+=1),t.location===NF&&(HF(t,o),l+=1);let r=UF(e,t,n,m,h,a,u,d);r?.focus&&(f=r.focus)}let _=o.getElementsByClassName(`panelHeader`)[0];_&&(_.style.display=l?PF:IF),t?._controlBarSelectionHandler&&t.off(`rowSelectionChanged`,t._controlBarSelectionHandler);let v=(e,t)=>{V(i)&&i(t),c&&m(t)};return t&&(t._controlBarSelectionHandler=v),t?.on(`rowSelectionChanged`,v),m(t?.getSelectedRows?.()??[]),f&&setTimeout(()=>f.focus(),200),{elements:u,inputs:d}}function HF(e,t){if(V(e.headerClick)){let n=t.getElementsByClassName(`panelHeader`)[0];n&&(n.onclick=e.headerClick)}}function UF(e,t,n,r,i,a,o,s){if(!t.hide&&(t.input||t.placeholder||t.search)){let r=WF(e,t);return t.id&&(s[t.id]=r.input),t.id&&(o[t.id]=r.elem,r.elem.id=t.id),n?.appendChild(r.elem),t.focus?{focus:r.input}:void 0}if(!t.hide&&t.text){let e=document.createElement(`div`);e.className=`font-medium`,t.id&&(o[t.id]=e,e.id=t.id),e.innerHTML=t.text,e.onclick=e=>i(e,t),n?.appendChild(e);return}!t.id&&(!t?.label||t.hide)||(KF(t,n,r,i,a,o),(!(t?.label||t.tabs)||t.hide)&&o[t.id]&&(o[t.id].style.display=IF))}function WF(e,t){let n=document.createElement(`p`);n.className=`control ${t.search?`has-icons-left has-icons-right`:``}`;let r=document.createElement(`input`);if(r.className=`input font-medium`,r.setAttribute(`type`,`text`),r.setAttribute(`autocomplete`,`off`),r.setAttribute(`placeholder`,e.placeholder||PF),t.id&&r.setAttribute(`id`,t.id),t.onKeyDown&&r.addEventListener(`keydown`,e=>t.onKeyDown(e,t)),t.onChange&&r.addEventListener(`change`,e=>t.onChange(e,t)),t.onKeyUp&&r.addEventListener(`keyup`,e=>{t.clearSearch&&e.key===`Escape`&&(e.stopPropagation(),r.value=``,t.clearSearch()),t.onKeyUp(e,t)}),t.class&&r.classList.add(t.class),t.visible===!1&&(n.style.display=IF),t.value&&(r.value=t.value),n.appendChild(r),t.search&&GF(n,r,t),e.validator){let t=document.createElement(`p`);t.className=`help font-medium`,n.appendChild(t),r.addEventListener(`input`,n=>fn(e,n,r,t,e.validator))}return{elem:n,input:r}}function GF(e,t,n){let r=document.createElement(`span`);if(r.className=`icon is-small is-left font-medium`,r.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16" fill="currentColor"><path d="M416 208c0 45.9-14.9 88.3-40 122.7L502.6 457.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0L330.7 376c-34.4 25.2-76.8 40-122.7 40C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208zM208 352a144 144 0 1 0 0-288 144 144 0 1 0 0 288z"/></svg>`,e.appendChild(r),V(n.clearSearch)){let r=document.createElement(`span`);r.className=`icon is-small is-right font-medium`,r.style.pointerEvents=`all`,r.style.cursor=`pointer`,r.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="16" height="16" fill="#dddada"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z"/></svg>`,r.onclick=e=>{e.stopPropagation(),t.value=``,n.clearSearch(),i()};let i=()=>{r.style.display=t.value?``:`none`};t.addEventListener(`input`,i),i(),e.appendChild(r)}}function KF(e,t,n,r,i,a){if(e.options){let r=vF({target:t,button:e,stateChange:n});e.visible===!1&&(r.style.display=IF),e.id&&(a[e.id]=r)}else if(oe(e.selection))qF(e,t,n,i,a);else if(e.tabs)JF(e,t,a);else{let n=CF(e);n.onclick=t=>r(t,e),e.id&&(a[e.id]=n),t?.appendChild(n)}}function qF(e,t,n,r,i){let{selection:{options:a,actions:o},actionPlacement:s,threshold:c=8,...l}=e;if(a?.length<c){a.length&&(s===BF?a.unshift({divider:!0}):a.push({divider:!0})),o.forEach(e=>{let{label:t,...n}=e,r={...n,label:`<p style="font-weight: bold">${t}</p>`};s===BF?a.unshift(r):a.push(r)});let r={...l,options:a},c=vF({target:t,button:r,stateChange:n});r.visible===!1&&(c.style.display=IF),r.id&&(i[e.id]=c)}else{let n=CF(e),o=r||bF;n.onclick=t=>{t.stopPropagation(),o({title:e.selectionTitle||`Select`,options:a})},e.id&&(i[e.id]=n),t?.appendChild(n)}}function JF(e,t,n){let r=document.createElement(`div`);r.className=`tabs is-toggle is-toggle-rounded`;let i=document.createElement(`ul`);r.appendChild(i),e.tabs.forEach(t=>{let n=document.createElement(`li`);t.active&&n.classList.add(`is-active`);let r=document.createElement(`a`);n.appendChild(r),r.onclick=r=>{i.querySelectorAll(`li`).forEach(e=>e.classList.remove(`is-active`)),n.classList.add(`is-active`),V(t.onClick)&&t.onClick(r,e)};let a=document.createElement(`span`);a.innerHTML=t.label,r.appendChild(a),i.appendChild(n)}),e.id&&(n[e.id]=r),t.appendChild(r)}function YF(){let e=document.createElement(`div`);e.className=`panel_container flexcol flexcenter`;let t=document.createElement(`div`);t.className=`panelHeader options_header`,t.style.display=IF,e.appendChild(t);let n=document.createElement(`div`);n.className=zF;let r={optionsOverlay:document.createElement(`div`),optionsLeft:document.createElement(`div`),optionsCenter:document.createElement(`div`),optionsRight:document.createElement(`div`)};r.optionsOverlay.className=`options_overlay`,r.optionsCenter.className=`options_center`,r.optionsRight.className=`options_right`,r.optionsLeft.className=`options_left`;for(let e of Object.values(r))n.appendChild(e);return e.appendChild(n),{elements:r,anchor:e,header:t}}var XF=()=>`sp-layout`,ZF=()=>`sp-column`,QF=()=>`sp-panel`,$F=()=>`sp-panel-header`,eI=()=>`sp-panel-title`,tI=()=>`sp-panel-meta`,nI=()=>`sp-panel-actions`,rI=()=>`sp-panel-leading`,iI=()=>`sp-date-strip`,aI=()=>`sp-date-chip`,oI=()=>`sp-badges`,sI=()=>`sp-badge`,cI=()=>`sp-chips`,lI=()=>`sp-chip`,uI=()=>`sp-board`,dI=()=>`sp-venue`,fI=()=>`sp-venue-header`,pI=()=>`sp-venue-title`,mI=()=>`sp-venue-sub`,hI=()=>`sp-dropzone`,gI=()=>`sp-card`,_I=()=>`sp-card-title`,vI=()=>`sp-card-meta`,yI=()=>`sp-issues`,bI=()=>`sp-issue`,xI=()=>`sp-issue-code`,SI=()=>`sp-issue-msg`,CI=()=>`sp-issue-actions`,wI=()=>`sp-btn sp-btn--sm`,TI=()=>`sp-catalog`,EI=()=>`sp-catalog-toolbar`,DI=()=>`sp-input`,OI=()=>`sp-select`,kI=()=>`sp-group`,AI=()=>`sp-group-header`,jI=()=>`sp-group-body`,MI=()=>`sp-catalog-item`,NI=()=>`sp-small`,PI=()=>`sp-popover-item`,FI=()=>`sp-popover-delete`,II=()=>`sp-popover-divider`,LI=()=>`sp-insertion-line`,RI=()=>`sp-group-chevron`;function zI(e,t){let n=!!t?.hideLeft,r=t?.catalogSide===`left`,i=document.createElement(`div`);if(i.className=XF(),n)r?i.classList.add(`sp-catalog-left`):i.classList.add(`sp-no-left`);else{let t=document.createElement(`div`);t.className=ZF(),t.appendChild(e.dateStrip.element),e.issuesPanel.element.style.flex=`1`,e.issuesPanel.element.style.minHeight=`0`,t.appendChild(e.issuesPanel.element),i.appendChild(t)}let a=document.createElement(`div`);a.className=ZF(),e.venueBoard.element.style.flex=`1`,e.venueBoard.element.style.minHeight=`0`,a.appendChild(e.venueBoard.element);let o=document.createElement(`div`);o.className=ZF(),e.roundCatalog.element.style.flex=`1 1 0`,e.roundCatalog.element.style.minHeight=`0`,o.appendChild(e.roundCatalog.element),r&&n?(i.appendChild(o),i.appendChild(a)):(i.appendChild(a),i.appendChild(o));function s(t){n||(e.dateStrip.update(t),e.issuesPanel.update(t)),e.venueBoard.update(t),e.roundCatalog.update(t)}return{element:i,update:s}}function BI(e){let t=null,n=null;function r(e){return`${e.date}|${e.venueId}|${e.index}`}function i(){t&&(t.destroy(),t=null,n=null)}function a(t){let n=document.createElement(`div`);n.style.cssText=`font-family:sans-serif; font-size:13px; min-width:150px;`;let r=document.createElement(`div`);r.className=PI(),r.textContent=`Set Not Before Time`,r.addEventListener(`click`,()=>{i(),e.onSetNotBeforeTime(t)}),n.appendChild(r);let a=document.createElement(`div`);a.className=II(),n.appendChild(a);let o=document.createElement(`div`);return o.className=FI(),o.textContent=`Remove Round`,o.addEventListener(`click`,()=>{i(),e.onDelete(t)}),n.appendChild(o),n}return{show(e,o){let s=r(o);if(n===s){i();return}i();let c=km(e,{content:a(o),allowHTML:!0,interactive:!0,trigger:`manual`,placement:`bottom`,appendTo:document.body,onHidden:()=>{t=null,n=null}});t=c,n=s,c.show()},destroy(){i()},isActiveFor(e){return n===r(e)}}}function VI(e){return structuredClone(e)}function HI(e,t,n){return Math.max(t,Math.min(n,e))}function UI(e){return`${e.tournamentId}|${e.eventId}|${e.drawId}|${e.structureId}|${e.roundNumber}`}function WI(e){return`${e.eventName?`${e.eventName} \u2013 `:``}${e.roundName??`Round ${e.roundNumber}`}${e.roundSegment?` (seg ${e.roundSegment.segmentNumber}/${e.roundSegment.segmentsCount})`:``}`}function GI(e,t){return!e||!t?!1:e.date===t.date&&e.venueId===t.venueId&&e.index===t.index}function KI(e){return{tournamentId:e.tournamentId,eventId:e.eventId,drawId:e.drawId,structureId:e.structureId,roundNumber:e.roundNumber}}function qI(e,t){return`${e}|${t.segmentNumber}/${t.segmentsCount}`}function JI(e){let t=new Map;for(let n of e)for(let e of n.venues)for(let r=0;r<e.rounds.length;r++){let i=e.rounds[r],a=UI(i),o=i.roundSegment,s=o?qI(a,o):a,c={locator:{date:n.scheduleDate,venueId:e.venueId,index:r,roundKey:KI(i),roundSegment:o},date:n.scheduleDate,venueId:e.venueId,roundSegment:o},l=t.get(s);l?l.push(c):t.set(s,[c])}return t}function YI(e){let t=new Map;for(let n of e)for(let e of n.venues)for(let n of e.rounds){if(!n.roundSegment)continue;let e=UI(n),r=t.get(e)??0;n.roundSegment.segmentsCount>r&&t.set(e,n.roundSegment.segmentsCount)}return t}function XI(e,t,n,r=`dim`){let i=t.toLowerCase().trim();return e.filter(e=>r===`hide`&&n.has(UI(e))?!1:!i||`${e.eventName} ${e.drawName??``} ${e.roundName??``} ${e.drawId}`.toLowerCase().includes(i)).map(e=>({...e,isPlanned:n.has(UI(e))}))}function ZI(e,t){let n=new Map,r=e=>t===`draw`?`${e.eventName} \u2014 ${e.drawName??e.drawId}`:t===`round`?e.roundName??`Round ${e.roundNumber}`:e.eventName;for(let t of e){let e=r(t),i=n.get(e);i?i.push(t):n.set(e,[t])}return new Map([...n.entries()].sort((e,t)=>e[0].localeCompare(t[0],void 0,{numeric:!0})))}function QI(e){let t=new Set;for(let n of e)for(let e of n.venues)for(let n of e.rounds)n.roundSegment||t.add(UI(n));return t}function $I(e){let t=new Set;for(let n of e)for(let e of n.venues)for(let n of e.rounds)if(n.roundSegment){let e=UI(n);t.add(qI(e,n.roundSegment))}return t}var eL=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function tL(e){return eL.test(e)}function nL(e){let t=document.createElement(`div`);t.className=QF(),t.style.overflowY=`auto`,t.style.scrollbarWidth=`thin`,t.style.scrollbarColor=`var(--sp-scrollbar) transparent`;let n=new Set,r=new Map,i=null,a=document.createElement(`div`);a.className=$F();let o=document.createElement(`div`);o.className=eI(),o.textContent=`Round Catalog`;let s=document.createElement(`div`);s.className=tI(),a.appendChild(o),a.appendChild(s),t.appendChild(a);let c=document.createElement(`div`);c.className=EI();let l=document.createElement(`input`);l.type=`text`,l.placeholder=`Search rounds...`,l.className=DI(),l.addEventListener(`input`,()=>e.onSearchChange(l.value));let u=SC(l,()=>{l.value=``,e.onSearchChange(``),l.focus()}),d=document.createElement(`select`);d.className=OI();for(let[e,t]of[[`event`,`By Event`],[`draw`,`By Draw`],[`round`,`By Round`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,d.appendChild(n)}d.addEventListener(`change`,()=>e.onGroupByChange(d.value)),c.appendChild(u),c.appendChild(d),t.appendChild(c);let f=document.createElement(`div`);f.className=TI(),t.appendChild(f),f.addEventListener(`dragover`,e=>{e.preventDefault(),f.classList.add(`over`),e.dataTransfer.dropEffect=`move`}),f.addEventListener(`dragleave`,e=>{f.contains(e.relatedTarget)||f.classList.remove(`over`)}),f.addEventListener(`drop`,t=>{if(f.classList.remove(`over`),t.preventDefault(),!e.onDropRemove)return;let n;try{n=JSON.parse(t.dataTransfer.getData(`application/json`))}catch{return}n.type===`PLANNED_ROUND`&&e.onDropRemove(n.locator)});function p(t,n,i,a,o,s){let c=document.createElement(`div`);c.className=MI(),i&&c.classList.add(`segment`),t.isPlanned?(c.classList.add(n===`navigate`?`navigate`:`dimmed`),c.draggable=!1,n===`navigate`&&c.addEventListener(`click`,()=>{e.onNavigateToPlanned?.(t)})):(c.draggable=!0,c.addEventListener(`dragstart`,e=>{e.stopPropagation(),e.dataTransfer.setDragImage(c,c.offsetWidth/2,20);let n={type:`CATALOG_ROUND`,roundRef:t};i&&(n.roundSegment=i),e.dataTransfer.setData(`application/json`,JSON.stringify(n)),e.dataTransfer.effectAllowed=`copyMove`}));let l=document.createElement(`div`);l.className=_I();let u=t.roundName&&!t.roundName.startsWith(`rn=`)?t.roundName:`Round `+t.roundNumber,d=i?` \u00b7 Seg ${i.segmentNumber}/${i.segmentsCount}`:``;l.textContent=`${t.eventName} \u2014 ${u}${d}`;let f=document.createElement(`div`);f.className=vI();let p=i&&t.matchCountEstimate?Math.round(t.matchCountEstimate/i.segmentsCount):t.matchCountEstimate,m=p?` · `+p+` matches`:``,h=t.drawName&&!tL(t.drawName)?t.drawName:``;if(f.textContent=h?`${h}${m}`:m.replace(` · `,``)||``,c.appendChild(l),c.appendChild(f),o.length&&n!==`navigate`&&(c.appendChild(rL(o,s)),e.onDropRemove&&c.appendChild(aL(o,e.onDropRemove))),!(t.isPlanned&&n!==`navigate`)&&!t.isPlanned){let e=document.createElement(`div`);e.className=`sp-split-ctl`;let n=UI(t);if(i){let t=document.createElement(`button`);t.type=`button`,t.className=`sp-split-chip sp-split-collapse`,t.title=`Collapse to whole round`,t.textContent=`×`,t.addEventListener(`click`,e=>{e.stopPropagation(),r.delete(n),a()}),e.appendChild(t)}else for(let[t,i,o]of[[`½`,2,`Split into halves`],[`¼`,4,`Split into quarters`]]){let s=document.createElement(`button`);s.type=`button`,s.className=`sp-split-chip`,s.title=o,s.textContent=t,s.addEventListener(`click`,e=>{e.stopPropagation(),r.set(n,i),a()}),e.appendChild(s)}c.appendChild(e)}return c}function m(e){i=e;let t=e.plannedRoundBehavior,a=QI(e.profileDraft),o=$I(e.profileDraft),c=JI(e.profileDraft),h=YI(e.profileDraft),g=new Map(e.venues.map(e=>[e.venueId,e.name])),_=XI(e.roundCatalog,e.catalogSearchQuery,a,t),v=ZI(_,e.catalogGroupBy),y=()=>i&&m(i);s.textContent=`${_.length} rounds`,l.value!==e.catalogSearchQuery&&(l.value=e.catalogSearchQuery,CC(u)),d.value!==e.catalogGroupBy&&(d.value=e.catalogGroupBy),f.innerHTML=``;for(let[e,a]of v){let s=document.createElement(`div`);s.className=kI();let l=n.has(e),u=document.createElement(`div`);u.className=AI();let d=document.createElement(`span`);d.className=RI(),d.textContent=l?`▶`:`▼`;let _=document.createElement(`span`);_.textContent=e,u.appendChild(d),u.appendChild(_),u.addEventListener(`click`,()=>{n.has(e)?n.delete(e):n.add(e),i&&m(i)});let v=document.createElement(`div`);v.className=jI(),l&&(v.style.display=`none`);for(let e of a){let n=UI(e),i=r.get(n)??h.get(n);if(!i){let r=c.get(n)??[];v.appendChild(p(e,t,void 0,y,r,g));continue}for(let r=1;r<=i;r++){let a={segmentNumber:r,segmentsCount:i},s=e.isPlanned||o.has(qI(n,a));if(s&&t===`hide`)continue;let l=c.get(qI(n,a))??[];v.appendChild(p({...e,isPlanned:s},t,a,y,l,g))}}s.appendChild(u),s.appendChild(v),f.appendChild(s)}}return{element:t,update:m}}function rL(e,t){let n=document.createElement(`div`);n.className=`sp-catalog-placements`;for(let r of e)n.appendChild(iL(r,t));return n}function iL(e,t){let n=document.createElement(`div`);n.className=`sp-catalog-placement`;let r=document.createElement(`span`);r.className=`sp-catalog-placement-icon`,n.appendChild(r);let i=document.createElement(`span`);i.className=`sp-catalog-placement-label`;let a=t.get(e.venueId)||e.venueId,o=e.roundSegment?` · Seg ${e.roundSegment.segmentNumber}/${e.roundSegment.segmentsCount}`:``;return i.textContent=`${oL(e.date)} · ${a}${o}`,n.appendChild(i),n}function aL(e,t){let n=document.createElement(`div`);n.className=`sp-split-ctl sp-split-ctl-stack`;for(let r of e){let e=document.createElement(`button`);e.type=`button`,e.className=`sp-split-chip sp-split-collapse`,e.title=`Remove this placement`,e.textContent=`×`,e.addEventListener(`click`,e=>{e.stopPropagation(),t(r.locator)}),n.appendChild(e)}return n}function oL(e){try{let t=new Date(`${e}T12:00:00`);return Number.isNaN(t.getTime())?e:`${t.toLocaleDateString(void 0,{weekday:`short`})} ${t.toLocaleDateString(void 0,{month:`short`})} ${t.getDate()}`}catch{return e}}function sL(e){let t=document.createElement(`div`);t.className=QF();let n=document.createElement(`div`);n.className=$F();let r=document.createElement(`div`);r.className=eI(),r.textContent=`Issues`;let i=document.createElement(`div`);i.className=tI(),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=yI(),t.appendChild(a);function o(t){let n=t.issueIndex.all;if(i.textContent=`${n.length} total (${t.issueIndex.bySeverity.ERROR.length} errors)`,a.innerHTML=``,!n.length){let e=document.createElement(`div`);e.className=NI(),e.textContent=`No issues. Drag rounds into the board to build a profile.`,a.appendChild(e);return}for(let t of n.slice(0,30)){let n=document.createElement(`div`);n.className=bI(),t.severity===`ERROR`?n.classList.add(`error`):t.severity===`WARN`?n.classList.add(`warn`):n.classList.add(`info`);let r=document.createElement(`div`);r.className=xI(),r.textContent=`${t.severity} \u00b7 ${t.code}`;let i=document.createElement(`div`);if(i.className=SI(),i.textContent=t.message,n.appendChild(r),n.appendChild(i),t.fixActions?.length){let r=document.createElement(`div`);r.className=CI();for(let n of t.fixActions){let t=document.createElement(`button`);t.className=wI(),t.textContent=n.label??n.kind,t.addEventListener(`click`,()=>e.onFixAction(n)),r.appendChild(t)}n.appendChild(r)}a.appendChild(n)}}return{element:t,update:o}}var{ROUND_ROBIN:cL,ROUND_ROBIN_WITH_PLAYOFF:lL}=t.drawDefinitionConstants,uL=`Jump to prerequisite`;function dL({profile:e,availability:t,demand:n,dependencies:r,venueOrder:i}){let a=[];if(t?.isDateAvailable)for(let n of e){let e=t.isDateAvailable(n.scheduleDate);e.ok||a.push({code:`DATE_UNAVAILABLE`,severity:`ERROR`,message:`Can't schedule on ${n.scheduleDate} \u2014 day is unavailable${e.reason?`: `+e.reason:``}.`,context:{date:n.scheduleDate},fixActions:[{kind:`OPEN_AVAILABILITY_GRID`,date:n.scheduleDate,label:`Tune availability`}]})}a.push(...fL(e,t,n));let o=bL(e);for(let e of o){let t=e.round.roundSegment;t&&(Number.isInteger(t.segmentNumber)&&Number.isInteger(t.segmentsCount)&&t.segmentsCount>=2&&t.segmentNumber>=1&&t.segmentNumber<=t.segmentsCount||a.push({code:`INVALID_SEGMENT_CONFIG`,severity:`ERROR`,message:`Invalid segment configuration for ${WI(e.round)}.`,context:{locator:e.locator,date:e.locator.date,venueId:e.locator.venueId}}))}let s=new Map,c=new Map;for(let e of o){let t=e.round,n=UI(t);if(!t.roundSegment)s.has(n)?a.push({code:`DUPLICATE_ROUND`,severity:`ERROR`,message:`Round is planned more than once: ${WI(t)}.`,context:{scope:`${t.drawId}|${t.structureId}`,locator:e.locator,date:e.locator.date,venueId:e.locator.venueId},fixActions:[{kind:`JUMP_TO_ITEM`,locator:s.get(n),label:`Jump to existing`}]}):s.set(n,e.locator);else{let r=`${n}|${t.roundSegment.segmentNumber}/${t.roundSegment.segmentsCount}`;c.has(r)?a.push({code:`DUPLICATE_SEGMENT`,severity:`ERROR`,message:`Segment planned more than once: ${WI(t)}.`,context:{scope:`${t.drawId}|${t.structureId}`,locator:e.locator,date:e.locator.date,venueId:e.locator.venueId},fixActions:[{kind:`JUMP_TO_ITEM`,locator:c.get(r),label:`Jump to existing`}]}):c.set(r,e.locator)}}return a.push(...mL({profile:e,venueOrder:i})),r?.getRoundDependencies&&a.push(...vL(o,r)),a}function fL(e,t,n){if(!t?.getDayCapacityMinutes||!n?.estimateDayDemandMinutes)return[];let r=[];for(let i of e){let a=t.getDayCapacityMinutes(i.scheduleDate),o=n.estimateDayDemandMinutes(i.scheduleDate,e);if(a>0&&o>a){let e=Math.round((o-a)/60*10)/10;r.push({code:`DAY_OVERLOAD`,severity:`WARN`,message:`${i.scheduleDate} is overloaded by ~${e}h (${Math.round(o/60)}h planned vs ${Math.round(a/60)}h available).`,context:{date:i.scheduleDate},fixActions:[{kind:`OPEN_AVAILABILITY_GRID`,date:i.scheduleDate,label:`Tune availability`}]})}}return r}var pL=new Set([cL,lL]);function mL({profile:e}){let t=bL(e),n=hL(t),r=gL(t);return SL([...n,...r])}function hL(e){let t=[],n=xL(e,e=>`${e.round.structureId}|${e.locator.date}|${e.locator.venueId}`);for(let[e,r]of n.entries()){let n=r[0]?.round.structureType;if(!(n&&pL.has(n))){r.sort((e,t)=>e.locator.index-t.locator.index);for(let n=0;n<r.length;n++){let i=r[n],a=null;for(let e=n-1;e>=0;e--)if(r[e].round.roundNumber>i.round.roundNumber){a=r[e];break}if(!a)continue;let o=yL(r,n,a);t.push({code:`ROUND_ORDER_VIOLATION`,severity:`ERROR`,message:`Cannot place ${WI(i.round)} before ${WI(a.round)} in this venue.`,context:{scope:e,drawId:i.round.drawId,structureId:i.round.structureId,date:i.locator.date,venueId:i.locator.venueId,locator:i.locator,prerequisite:a.locator},fixActions:[{kind:`JUMP_TO_ITEM`,locator:a.locator,label:uL},...o.moveOffenderAfter?[{kind:`MOVE_ITEM_AFTER`,locator:i.locator,after:o.moveOffenderAfter,label:`Move offending round after prerequisite set`}]:[],...o.movePrereqBefore?[{kind:`MOVE_ITEM_BEFORE`,locator:a.locator,before:o.movePrereqBefore,label:`Move prerequisite before offending round`}]:[]]})}}}return t}function gL(e){let t=[],n=xL(e,e=>e.round.structureId);for(let[e,r]of n.entries()){let n=r[0]?.round.structureType;if(n&&pL.has(n))continue;let i=new Map;for(let e of r){let t=e.locator.date,n=i.get(t);n?n.push(e):i.set(t,[e])}let a=[...i.keys()].sort();if(a.length<2)continue;let o=-1/0,s=null;for(let n of a){let r=i.get(n);for(let i of r)i.round.roundNumber<o&&s&&t.push({code:`ROUND_ORDER_VIOLATION`,severity:`ERROR`,message:`${WI(s.round)} is scheduled on ${s.locator.date} but its prerequisite ${WI(i.round)} is on the later date ${n}.`,context:{scope:`cross-date|${e}`,drawId:s.round.drawId,structureId:e,date:s.locator.date,venueId:s.locator.venueId,locator:s.locator,prerequisite:i.locator,reason:`cross-date`},fixActions:[{kind:`JUMP_TO_ITEM`,locator:i.locator,label:uL}]});for(let e of r)e.round.roundNumber>o&&(o=e.round.roundNumber,s=e)}}return t}function _L(e,t){if(e.round.structureId!==t.round.structureId||e.locator.date!==t.locator.date||e.locator.venueId!==t.locator.venueId){if(e.locator.date<t.locator.date)return{code:`DEPENDENCY_VIOLATION`,severity:`ERROR`,message:`${WI(e.round)} is scheduled on ${e.locator.date} but depends on ${WI(t.round)} which is on the later date ${t.locator.date}.`,context:{date:e.locator.date,venueId:e.locator.venueId,locator:e.locator,prerequisite:t.locator,reason:`cross-date`},fixActions:[{kind:`JUMP_TO_ITEM`,locator:t.locator,label:uL}]};if(e.locator.date===t.locator.date&&e.locator.venueId===t.locator.venueId&&e.locator.index<t.locator.index)return{code:`DEPENDENCY_VIOLATION`,severity:`ERROR`,message:`${WI(e.round)} is listed before its prerequisite ${WI(t.round)} in the same venue on ${e.locator.date}.`,context:{date:e.locator.date,venueId:e.locator.venueId,locator:e.locator,prerequisite:t.locator,reason:`cross-structure-same-day`},fixActions:[{kind:`JUMP_TO_ITEM`,locator:t.locator,label:uL},{kind:`MOVE_ITEM_AFTER`,locator:e.locator,after:t.locator,label:`Move after prerequisite`},{kind:`MOVE_ITEM_BEFORE`,locator:t.locator,before:e.locator,label:`Move prerequisite before`}]}}}function vL(e,t){let n=[],r=xL(e,e=>UI(e.round));for(let[e,i]of r.entries()){let a=t.getRoundDependencies(e);if(a.length)for(let e of a){let t=r.get(e);if(t)for(let e of i)for(let r of t){let t=_L(e,r);t&&n.push(t)}}}return SL(n)}function yL(e,t,n){let r=e[t],i=e.indexOf(n);for(let t=i+1;t<e.length;t++)e[t].round.roundNumber>=n.round.roundNumber&&(i=t);return{moveOffenderAfter:e[i].locator,movePrereqBefore:r.locator}}function bL(e){let t=[];for(let n of e)for(let e of n.venues)for(let r=0;r<e.rounds.length;r++){let i=e.rounds[r];t.push({round:i,locator:{date:n.scheduleDate,venueId:e.venueId,index:r,roundKey:KI(i),roundSegment:i.roundSegment}})}return t}function xL(e,t){let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i?i.push(r):n.set(e,[r])}return n}function SL(e){let t=new Set,n=[];for(let r of e){let e=r.code+`|`+r.message+`|`+(r.context?.scope??``)+`|`+JSON.stringify(r.context?.locator??{});t.has(e)||(t.add(e),n.push(r))}return n}function CL(e){let t={ERROR:[],WARN:[],INFO:[]},n={},r={},i={},a={total:e.length,ERROR:0,WARN:0,INFO:0,byDate:{},byVenue:{},byDraw:{}},o=e=>e===`ERROR`?0:e===`WARN`?1:2,s=(e,t)=>o(e.severity)-o(t.severity)||e.code.localeCompare(t.code)||e.message.localeCompare(t.message);for(let o of e){t[o.severity].push(o),a[o.severity]++;let e=o.context?.date??o.context?.locator?.date,s=o.context?.venueId??o.context?.locator?.venueId,c=o.context?.scope??(o.context?.drawId&&o.context?.structureId?`${o.context.drawId}|${o.context.structureId}`:void 0);e&&(n[e]??=[]).push(o),s&&(r[s]??=[]).push(o),c&&(i[c]??=[]).push(o),wL(a.byDate,e,o.severity),wL(a.byVenue,s,o.severity),wL(a.byDraw,c,o.severity)}for(let e of Object.keys(t))t[e].sort(s);for(let e of[n,r,i])for(let t of Object.keys(e))e[t].sort(s);return{all:e,bySeverity:t,byDate:n,byVenue:r,byDraw:i,counts:a}}function wL(e,t,n){if(!t)return;let r=e[t]??={total:0,ERROR:0,WARN:0,INFO:0};r.total++,r[n]++}function TL(e,t,n){let r=VI(e),{date:i,venueId:a}=n,o=DL(EL(r,i),a);if(t.type===`CATALOG_ROUND`){let e={tournamentId:t.roundRef.tournamentId,eventId:t.roundRef.eventId,eventName:t.roundRef.eventName,drawId:t.roundRef.drawId,drawName:t.roundRef.drawName,structureId:t.roundRef.structureId,structureType:t.roundRef.structureType,roundNumber:t.roundRef.roundNumber,roundName:t.roundRef.roundName};t.roundSegment&&(e.roundSegment=t.roundSegment);let i=HI(n.index,0,o.rounds.length);return o.rounds.splice(i,0,e),OL(o.rounds),{ok:!0,profile:r}}if(t.type===`PLANNED_ROUND`){let{locator:e}=t,s=DL(EL(r,e.date),e.venueId),[c]=s.rounds.splice(e.index,1);OL(s.rounds);let l=n.index;return e.date===i&&e.venueId===a&&e.index<l&&--l,l=HI(l,0,o.rounds.length),o.rounds.splice(l,0,c),OL(o.rounds),{ok:!0,profile:r}}return{ok:!1,profile:e}}function EL(e,t){let n=e.find(e=>e.scheduleDate===t);return n||(n={scheduleDate:t,venues:[]},e.push(n),e.sort((e,t)=>e.scheduleDate.localeCompare(t.scheduleDate))),n}function DL(e,t){let n=e.venues.find(e=>e.venueId===t);return n||(n={venueId:t,rounds:[]},e.venues.push(n)),n}function OL(e){for(let t=0;t<e.length;t++)e[t].sortOrder=t+1}function kL(e,t,n){return e.find(e=>e.scheduleDate===t)?.venues?.find(e=>e.venueId===n)?.rounds??[]}function AL(e,t){return(e.find(e=>e.scheduleDate===t.date)?.venues?.find(e=>e.venueId===t.venueId))?.rounds?.[t.index]??null}function jL(e,t){return e.filter(e=>ML(e.context?.locator,t)||ML(e.context?.prerequisite,t))}function ML(e,t){return!!e&&e.date===t.date&&e.venueId===t.venueId&&e.index===t.index}function NL(e){return e.length?e.some(e=>e.severity===`ERROR`)?`ERROR`:e.some(e=>e.severity===`WARN`)?`WARN`:`INFO`:null}function PL(e,t){let n=UI(t);for(let t of e)for(let e of t.venues)for(let r=0;r<e.rounds.length;r++){let i=e.rounds[r];if(UI(KI(i))===n)return{date:t.scheduleDate,venueId:e.venueId,index:r,roundKey:KI(i),roundSegment:i.roundSegment}}return null}var FL=class{constructor(e){this.listeners=new Set,this.config=e;let t={all:[],bySeverity:{ERROR:[],WARN:[],INFO:[]},byDate:{},byVenue:{},byDraw:{},counts:{total:0,ERROR:0,WARN:0,INFO:0,byDate:{},byVenue:{},byDraw:{}}};this.state={profileDraft:VI(e.initialProfile??[]),venues:e.venues,roundCatalog:e.roundCatalog,schedulableDates:e.schedulableDates,activeDates:e.activeDates,selectedDate:e.selectedDate??e.schedulableDates[0]??null,selectedLocator:null,ruleResults:[],issueIndex:t,catalogSearchQuery:``,catalogGroupBy:`event`,plannedRoundBehavior:e.plannedRoundBehavior??`dim`},this.revalidate()}getState(){return this.state}getSchedulingProfile(){return VI(this.state.profileDraft)}selectDate(e){this.state.selectedDate!==e&&this.setState({selectedDate:e,selectedLocator:null})}selectCard(e){this.setState({selectedLocator:e})}setCatalogSearch(e){this.setState({catalogSearchQuery:e})}setCatalogGroupBy(e){this.setState({catalogGroupBy:e})}navigateToRound(e){let t=PL(this.state.profileDraft,{tournamentId:e.tournamentId,eventId:e.eventId,drawId:e.drawId,structureId:e.structureId,roundNumber:e.roundNumber});t&&this.setState({selectedDate:t.date,selectedLocator:t})}dropRound(e,t){try{let n=TL(this.state.profileDraft,e,t);if(!n.ok)return{ok:!1,errorMessage:`Invalid drop operation`};let r=new Set(this.state.ruleResults.filter(e=>e.severity===`ERROR`).map(IL)),i=dL({profile:n.profile,availability:this.config.availabilityAdapter,demand:this.config.demandAdapter,dependencies:this.config.dependencyAdapter,venueOrder:this.config.venueOrder}).filter(e=>e.severity===`ERROR`).filter(e=>!r.has(IL(e)));return i.length?(this.addRejectionNotice(i[0].message),{ok:!1,errorMessage:i[0].message}):(this.commitProfile(n.profile),{ok:!0})}catch(e){return{ok:!1,errorMessage:String(e)}}}removeRound(e){let t=VI(this.state.profileDraft),n=t.find(t=>t.scheduleDate===e.date);if(!n)return;let r=n.venues.find(t=>t.venueId===e.venueId);if(r&&!(e.index<0||e.index>=r.rounds.length)){r.rounds.splice(e.index,1);for(let e=0;e<r.rounds.length;e++)r.rounds[e].sortOrder=e+1;this.commitProfile(t),this.state.selectedLocator?.date===e.date&&this.state.selectedLocator?.venueId===e.venueId&&this.state.selectedLocator?.index===e.index&&this.setState({selectedLocator:null})}}setNotBeforeTime(e,t){let n=VI(this.state.profileDraft),r=n.find(t=>t.scheduleDate===e.date);if(!r)return;let i=r.venues.find(t=>t.venueId===e.venueId);if(!i)return;let a=i.rounds[e.index];a&&(t?a.notBeforeTime=t:delete a.notBeforeTime,this.commitProfile(n))}applyFixAction(e){if(e.kind===`JUMP_TO_ITEM`&&e.locator){this.setState({selectedDate:e.locator.date,selectedLocator:e.locator});return}if(e.kind===`OPEN_AVAILABILITY_GRID`){this.config.onFixAction?.(e);return}if(e.kind===`MOVE_ITEM_AFTER`&&e.locator&&e.after){let t=LL(this.state.profileDraft,e.locator,e.after);this.commitProfile(t);return}if(e.kind===`MOVE_ITEM_BEFORE`&&e.locator&&e.before){let t=RL(this.state.profileDraft,e.locator,e.before);this.commitProfile(t);return}this.config.onFixAction?.(e)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setState(e){this.state={...this.state,...e},this.emit()}commitProfile(e){this.state={...this.state,profileDraft:e},this.revalidate(),this.config.onProfileChanged?.(VI(e))}addRejectionNotice(e){let t={code:`DROP_REJECTED`,severity:`WARN`,message:`Drop rejected: ${e}`,context:{}},n=[...this.state.ruleResults.filter(e=>e.code!==`DROP_REJECTED`),t],r=CL(n);this.state={...this.state,ruleResults:n,issueIndex:r},this.emit()}revalidate(){let e=dL({profile:this.state.profileDraft,availability:this.config.availabilityAdapter,demand:this.config.demandAdapter,dependencies:this.config.dependencyAdapter,venueOrder:this.config.venueOrder}),t=CL(e);this.state={...this.state,ruleResults:e,issueIndex:t},this.emit()}emit(){for(let e of this.listeners)e(this.state)}};function IL(e){return`${e.code}|${e.context?.scope??``}|${e.context?.structureId??``}|${e.context?.date??``}`}function LL(e,t,n){let r=VI(e),i=zL(r,t);if(!i)return e;let a=BL(r,n.date,n.venueId),o=Math.min(a.length,n.index+1);return a.splice(o,0,i),r}function RL(e,t,n){let r=VI(e),i=zL(r,t);if(!i)return e;let a=BL(r,n.date,n.venueId),o=Math.max(0,Math.min(a.length,n.index));return a.splice(o,0,i),r}function zL(e,t){let n=e.find(e=>e.scheduleDate===t.date);if(!n)return null;let r=n.venues.find(e=>e.venueId===t.venueId);return!r||t.index<0||t.index>=r.rounds.length?null:r.rounds.splice(t.index,1)[0]}function BL(e,t,n){let r=e.find(e=>e.scheduleDate===t);r||(r={scheduleDate:t,venues:[]},e.push(r));let i=r.venues.find(e=>e.venueId===n);return i||(i={venueId:n,rounds:[]},r.venues.push(i)),i.rounds}function VL(e,t){let{round:n,locator:r,isSelected:i,severity:a}=e,o=document.createElement(`div`);o.className=gI(),i&&o.classList.add(`selected`),a===`ERROR`?o.classList.add(`error`):a===`WARN`&&o.classList.add(`warn`),o.draggable=!0,o.addEventListener(`dragstart`,e=>{e.stopPropagation(),e.dataTransfer.setDragImage(o,o.offsetWidth/2,20),e.dataTransfer.setData(`application/json`,JSON.stringify({type:`PLANNED_ROUND`,locator:r})),e.dataTransfer.effectAllowed=`copyMove`}),o.addEventListener(`click`,e=>{e.stopPropagation(),t.onClick(r)}),t.onContextMenu&&o.addEventListener(`contextmenu`,e=>{e.preventDefault(),e.stopPropagation(),t.onContextMenu(r,o)});let s=document.createElement(`div`);s.className=_I();let c=n.roundName&&!n.roundName.startsWith(`rn=`)?n.roundName:`Round `+n.roundNumber;s.textContent=(n.eventName?n.eventName+` — `:``)+c,o.appendChild(s);let l=document.createElement(`div`);l.className=vI(),l.textContent=[n.drawName||``,n.matchCountEstimate?`${n.matchCountEstimate} matches`:``].filter(Boolean).join(` · `),o.appendChild(l);let u=document.createElement(`div`);return u.className=cI(),n.roundSegment&&u.appendChild(HL(`Seg ${n.roundSegment.segmentNumber}/${n.roundSegment.segmentsCount}`,`seg`)),n.notBeforeTime&&u.appendChild(HL(`NB ${n.notBeforeTime}`,`nb`)),a===`ERROR`?u.appendChild(HL(`Error`,`err`)):a===`WARN`&&u.appendChild(HL(`Warn`,`warn`)),u.children.length&&o.appendChild(u),o}function HL(e,t){let n=document.createElement(`div`);return n.className=lI()+` `+t,n.textContent=e,n}function UL(e,t){let n=document.createElement(`div`);n.className=QF();let r=document.createElement(`div`);r.className=$F();let i=t?.titleLeadingActions,a=document.createElement(`div`);if(a.className=eI(),a.textContent=`Day Plan`,i){let e=document.createElement(`div`);e.className=rI();let t=Array.isArray(i)?i:[i];for(let n of t)e.appendChild(n);e.appendChild(a),r.appendChild(e)}else r.appendChild(a);let o=t?.headerActions;if(o){let e=document.createElement(`div`);e.className=nI();let t=Array.isArray(o)?o:[o];for(let n of t)e.appendChild(n);r.appendChild(e)}n.appendChild(r);let s=document.createElement(`div`);s.className=uI(),n.appendChild(s);function c(t){let n=t.selectedDate;s.innerHTML=``;let r=Math.max(1,t.venues.length);r>4?(s.classList.add(`sp-board-scroll`),s.style.gridTemplateColumns=``):(s.classList.remove(`sp-board-scroll`),s.style.gridTemplateColumns=`repeat(${r}, 1fr)`);for(let r of t.venues){let i=document.createElement(`div`);i.className=dI();let a=document.createElement(`div`);a.className=fI();let o=document.createElement(`div`),c=document.createElement(`div`);c.className=pI(),c.textContent=r.name;let l=document.createElement(`div`);l.className=mI(),l.textContent=``,o.appendChild(c),o.appendChild(l);let u=t.issueIndex.counts.byVenue[r.venueId],d=document.createElement(`div`);d.className=sI(),u?.ERROR?(d.classList.add(`err`),d.textContent=`${u.ERROR} err`):u?.WARN?(d.classList.add(`warn`),d.textContent=`${u.WARN} warn`):(d.classList.add(`ok`),d.textContent=`OK`),a.appendChild(o),a.appendChild(d);let f=document.createElement(`div`);if(f.className=hI(),f.dataset.venue=r.venueId,n){let i=kL(t.profileDraft,n,r.venueId);if(!i.length){let e=document.createElement(`div`);e.className=NI(),e.textContent=`Drop rounds here.`,f.appendChild(e)}i.forEach((i,a)=>{let o={date:n,venueId:r.venueId,index:a,roundKey:KI(i),roundSegment:i.roundSegment},s=NL(jL(t.ruleResults,o)),c=VL({round:i,locator:o,isSelected:GI(t.selectedLocator,o),severity:s},{onClick:e.onCardClick,onContextMenu:e.onCardContextMenu});f.appendChild(c)})}else{let e=document.createElement(`div`);e.className=NI(),e.textContent=`Select a date to plan.`,f.appendChild(e)}let p=document.createElement(`div`);p.className=LI(),p.style.display=`none`,f.addEventListener(`dragover`,e=>{if(!n)return;e.preventDefault(),f.classList.add(`over`),e.dataTransfer.dropEffect=`move`;let t=GL(f,e.clientY,p),r=WL(f,p);p.style.display=``,t<r.length?f.insertBefore(p,r[t]):f.appendChild(p)}),f.addEventListener(`dragleave`,e=>{f.contains(e.relatedTarget)||(f.classList.remove(`over`),p.style.display=`none`)}),f.addEventListener(`drop`,t=>{if(f.classList.remove(`over`),p.style.display=`none`,t.preventDefault(),!n)return;let i;try{i=JSON.parse(t.dataTransfer.getData(`application/json`))}catch{return}let a=GL(f,t.clientY,p),o={date:n,venueId:r.venueId,index:a};e.onDrop(i,o)}),i.appendChild(a),i.appendChild(f),s.appendChild(i)}}return{element:n,update:c}}function WL(e,t){return Array.from(e.querySelectorAll(`[draggable="true"]`)).filter(e=>e!==t)}function GL(e,t,n){let r=WL(e,n);for(let e=0;e<r.length;e++){let n=r[e].getBoundingClientRect();if(t<n.top+n.height/2)return e}return r.length}function KL(e){let t=document.createElement(`div`);t.className=QF();let n=document.createElement(`div`);n.className=$F();let r=document.createElement(`div`);r.className=eI(),r.textContent=`Dates`;let i=document.createElement(`div`);i.className=tI(),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=iI(),t.appendChild(a);function o(t){i.textContent=`${t.schedulableDates.length} schedulable`,a.innerHTML=``;let n=t.activeDates?new Set(t.activeDates):null;for(let r of t.schedulableDates){let i=!n||n.has(r),o=t.issueIndex.counts.byDate[r],s=document.createElement(`div`);s.className=aI(),r===t.selectedDate&&s.classList.add(`selected`),i||s.classList.add(`inactive`),s.setAttribute(`data-date`,r);let c=document.createElement(`div`),l=document.createElement(`div`);l.style.cssText=`font-weight:800;font-size:12px`,l.textContent=r;let u=document.createElement(`div`);u.style.cssText=`font-size:11px;color:var(--sp-muted)`,u.textContent=i?`Active`:`Inactive`,c.appendChild(l),c.appendChild(u);let d=document.createElement(`div`);d.className=oI(),o?.ERROR&&d.appendChild(qL(`${o.ERROR} err`,`err`)),o?.WARN&&d.appendChild(qL(`${o.WARN} warn`,`warn`)),!o?.ERROR&&!o?.WARN&&d.appendChild(qL(`OK`,`ok`)),s.appendChild(c),s.appendChild(d),s.addEventListener(`click`,()=>e.onDateSelected(r)),a.appendChild(s)}}return{element:t,update:o}}function qL(e,t){let n=document.createElement(`div`);return n.className=sI()+` `+t,n.textContent=e,n}var JL=class{constructor(e){this.container=null,this.store=new FL(e),this.popover=BI({onDelete:e=>{this.store.removeRound(e)},onSetNotBeforeTime:e=>{let t=prompt(`Enter not-before time (HH:MM):`,`10:00`);t!==null&&this.store.setNotBeforeTime(e,t||void 0)}});let t=KL({onDateSelected:e=>this.store.selectDate(e)}),n=sL({onFixAction:e=>this.store.applyFixAction(e)}),r=UL({onDrop:(e,t)=>{this.store.dropRound(e,t)},onCardClick:e=>this.store.selectCard(e),onCardContextMenu:(e,t)=>{this.popover.show(t,e)}},{headerActions:e.headerActions,titleLeadingActions:e.titleLeadingActions}),i=nL({onSearchChange:e=>this.store.setCatalogSearch(e),onGroupByChange:e=>this.store.setCatalogGroupBy(e),onDropRemove:e=>this.store.removeRound(e),onNavigateToPlanned:e=>this.store.navigateToRound(e)});this.layout=zI({dateStrip:t,issuesPanel:n,venueBoard:r,roundCatalog:i},{hideLeft:e.hideLeft,catalogSide:e.catalogSide}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.layout.element)}destroy(){this.unsubscribe(),this.popover.destroy(),this.container&&this.layout.element.parentNode===this.container&&this.layout.element.remove(),this.container=null}getProfile(){return this.store.getSchedulingProfile()}getStore(){return this.store}};function YL(e,t){let n=new JL(e);return n.render(t),n}var XL=class{constructor(){this.selectedDay=null,this.selectedVenue=null,this.selectedCourt=null,this.layerVisibility=new Map,this.listeners=new Set}setSelectedDay(e){this.selectedDay!==e&&(this.selectedDay=e,this.emit({selectedDay:e}))}getSelectedDay(){return this.selectedDay}setSelectedVenue(e){this.selectedVenue!==e&&(this.selectedVenue=e,this.emit({selectedVenue:e}))}getSelectedVenue(){return this.selectedVenue}setSelectedCourt(e){this.selectedCourt!==e&&(this.selectedCourt=e,this.emit({selectedCourt:e}))}getSelectedCourt(){return this.selectedCourt}setLayerVisibility(e,t){this.layerVisibility.set(e,t),this.emit({layerVisibility:new Map(this.layerVisibility)})}getLayerVisibility(){return new Map(this.layerVisibility)}isLayerVisible(e){return this.layerVisibility.get(e)??!0}getSnapshot(){return{selectedDay:this.selectedDay,selectedVenue:this.selectedVenue,selectedCourt:this.selectedCourt,layerVisibility:new Map(this.layerVisibility)}}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}emit(e){let t={type:`VIEW_CHANGED`,payload:e};for(let e of this.listeners)e(t)}},ZL={AVAILABLE:`rgba(33, 141, 141, 0.15)`,BLOCKED:`#95a5a6`,PRACTICE:`#9b59b6`,MAINTENANCE:`#f39c12`,RESERVED:`#3498db`,CLOSED:`#2c3e50`,SCHEDULED:`#27ae60`,SOFT_BLOCK:`#5dade2`,HARD_BLOCK:`#e74c3c`,LOCKED:`#34495e`,UNSPECIFIED:`#ecf0f1`};function QL(e,t,n={}){let r=[],i=new Map;for(let e of t){let t=nR(e.ref);i.set(t,e)}let a=new Set;for(let t of e)for(let e of t.rails)a.add(nR(e.court));for(let e of a){let t=i.get(e);if(!t)continue;let n={id:e,content:t.name,courtRef:t.ref,surface:t.surface,indoor:t.indoor,hasLights:t.hasLights,tags:t.tags};r.push(n)}return r}function $L(e,t={}){let{layerVisibility:n=new Map,showSegmentLabels:r=!1,colorScheme:i=ZL}=t,a=[];for(let t of e)for(let e of t.rails){let t=nR(e.court);for(let o of e.segments){if(!(n.get(o.status)??!0))continue;let e=`${t}-${o.start}-${o.status}`,s=i[o.status];a.push({id:e,group:t,content:r?eR(o):``,start:o.start,end:o.end,type:`background`,className:`availability-segment segment-${o.status.toLowerCase()}`,style:s===`transparent`?void 0:`background-color: ${s};`,title:`${o.status} segment`,editable:!1,selectable:!1,status:o.status,contributingBlocks:o.contributingBlocks,isSegment:!0})}}return a}function eR(e){let t=Math.round((new Date(e.end).getTime()-new Date(e.start).getTime())/6e4);return`${e.status} (${t}m)`}function tR(e,t={}){let{colorScheme:n=ZL}=t,r=[];for(let t of e){let e=nR(t.court),i=n[t.type],a=rR(i,-20);r.push({id:`block-${t.id}`,group:e,content:t.reason||t.type,start:t.start,end:t.end,type:`range`,className:`availability-block block-${t.type.toLowerCase()}`,style:`background-color: ${i}; border-color: ${a};`,title:t.reason||t.type,editable:{updateTime:!0,updateGroup:!0,remove:!1},blockId:t.id,status:t.type,reason:t.reason,isBlock:!0})}return r}function nR(e){return`${e.tournamentId}|${e.venueId}|${e.courtId}`}function rR(e,t){if(!e||!e.startsWith(`#`))return e;let n=parseInt(e.replace(`#`,``),16),r=Math.round(2.55*t),i=(n>>16)+r,a=(n>>8&255)+r,o=(n&255)+r;return`#`+(16777216+(i<255?i<1?0:i:255)*65536+(a<255?a<1?0:a:255)*256+(o<255?o<1?0:o:255)).toString(16).slice(1)}function iR(e){let t=e.split(`|`);return t.length===3?{tournamentId:t[0],venueId:t[1],courtId:t[2]}:null}function aR(e){let t=String(e);return t.startsWith(`block-`)?t.slice(6):null}function oR(e){let t=new Date(`${e.day}T${e.dayStartTime}:00`),n=new Date(`${e.day}T${e.dayEndTime}:00`);return{start:t,end:n,min:t,max:n,zoomMin:e.slotMinutes*4*60*1e3,zoomMax:(n.getTime()-t.getTime())*1.5}}var sR=_({EventEmitter:()=>iB,PluginRegistry:()=>GR,TimepickerUI:()=>lB,default:()=>uB});function cR(){nz===0&&(rz=document.body.style.overflowY,iz=document.body.style.paddingRight,document.body.style.paddingRight=`${PR()}px`,document.body.style.overflowY=`hidden`),nz+=1}function lR(){nz!==0&&(--nz,nz===0&&(document.body.style.overflowY=rz,document.body.style.paddingRight=iz,rz=``,iz=``))}function uR(e){let t=e.match(Fz);return t?{hour:t[1],minutes:t[2],type:t[3].toUpperCase()}:null}function dR(e){let t=e.match(Iz);return t?{hour:t[1],minutes:t[2]}:null}function fR(e,t){let n=parseInt(e.hour,10),r=parseInt(e.minutes,10);if(Number.isNaN(n)||Number.isNaN(r))return 0;if(t===`12h`&&e.type){let t=e.type.toUpperCase();t===`PM`&&n!==12&&(n+=12),t===`AM`&&n===12&&(n=0)}return n*60+r}function pR(e,t){if(t===`12h`){let t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);return t?fR({hour:t[1],minutes:t[2],type:t[3]},`12h`):0}let[n,r]=e.split(`:`);return fR({hour:n??`0`,minutes:r??`0`},`24h`)}function mR(e,t,n,r){e.on(n,r),t.push(()=>e.off(n,r))}function hR(e){let t=e.target,n=t.hasAttribute(`data-md3-ripple`)?t:t.closest(`[data-md3-ripple]`);if(!n||e.button!==0&&e.pointerType===`mouse`)return;let r=n.getBoundingClientRect(),i=Math.max(r.width,r.height)*2,a=e.clientX-r.left,o=e.clientY-r.top;n.style.setProperty(`--ripple-size`,`${i}px`),n.style.setProperty(`--ripple-x`,`${a}px`),n.style.setProperty(`--ripple-y`,`${o}px`),n.classList.remove(Zz,Qz),n.offsetWidth,n.classList.add(Zz,Qz),n._rippleHold=!0,$z=n}function gR(e){let t=e.target,n=(t.hasAttribute(`data-md3-ripple`)?t:t.closest(`[data-md3-ripple]`))||$z;n&&(n._rippleHold=!1,n.classList.remove(Qz),setTimeout(()=>{n.classList.remove(Zz),$z===n&&($z=null)},1e3))}function _R(e){let t=e.currentTarget;!t||!t._rippleHold||(t._rippleHold=!1,t.classList.remove(Qz),setTimeout(()=>{t.classList.remove(Zz),$z===t&&($z=null)},1e3))}function vR(e){if(AR()===!1)return;let t=e||document;t.addEventListener(`pointerdown`,hR),t.addEventListener(`pointerup`,gR),t.addEventListener(`pointercancel`,gR),t.querySelectorAll(`[data-md3-ripple]`).forEach(e=>{e.addEventListener(`mouseleave`,_R)})}function yR(e){let t=e.ui.mode;return t===`wheel`||t===`compact-wheel`}function bR(e){return e.ui.mode===`compact-wheel`}function xR(e){return bR(e)&&!!e.wheel?.placement}function SR(e,t){let{callbacks:n}=e.options;for(let[e,r]of tB){let i=n[e];i&&t.on(r,i)}}function CR(e,t){for(let n of nB)n.needed(e.options)&&!GR.has(n.name)&&t.emit(`error`,{error:n.message})}function wR(e={}){let t={clock:{...aB.clock,...e.clock},ui:{...aB.ui,...e.ui},labels:{...aB.labels,...e.labels},behavior:{...aB.behavior,...e.behavior},callbacks:{...aB.callbacks,...e.callbacks},timezone:{...aB.timezone,...e.timezone},range:{...aB.range,...e.range},wheel:{...aB.wheel,...e.wheel},clearBehavior:{...aB.clearBehavior,...e.clearBehavior}},n=t.ui.mode;return(n===`wheel`||n===`compact-wheel`)&&(t.wheel={placement:n===`compact-wheel`?`auto`:void 0,hideFooter:void 0,commitOnScroll:void 0,ignoreOutsideClick:void 0,...t.wheel}),t}function TR(e,t){if(e.options.clock.type===`24h`){let e=dR(t);if(!e)throw Error(`Invalid 24h format. Expected HH:MM`);return{hourValue:e.hour.padStart(2,`0`),minutesValue:e.minutes,typeValue:`AM`}}let n=uR(t);if(!n)throw Error(`Invalid 12h format. Expected HH:MM AM/PM`);return{hourValue:n.hour,minutesValue:n.minutes,typeValue:n.type}}function ER(e,t){let n=e.getHour(),r=e.getMinutes();n&&(n.value=t.hourValue,n.setAttribute(`aria-valuenow`,t.hourValue),e.setDegreesHours(Number(t.hourValue)*30)),r&&(r.value=t.minutesValue,r.setAttribute(`aria-valuenow`,t.minutesValue),e.setDegreesMinutes(Number(t.minutesValue)*6))}function DR(e,t){if(e.options.clock.type===`24h`)return;let n=e.getAM(),r=e.getPM();!n||!r||(t===`AM`?(n.classList.add(`active`),r.classList.remove(`active`)):(r.classList.add(`active`),n.classList.remove(`active`)))}function OR(e,t,n){if(yR(e.options))t.getPlugin(`wheel`)?.scrollToValue?.(n.hourValue,n.minutesValue,n.typeValue);else{let t=e.getClockHand();t&&(t.style.transform=`rotateZ(${e.degreesHours||0}deg)`)}}var kR,AR,jR,MR,NR,PR,FR,IR,LR,RR,zR,BR,VR,HR,UR,WR,GR,KR,qR,JR,YR,XR,ZR,QR,$R,ez,tz,nz,rz,iz,az,oz,sz,cz,lz,uz,dz,fz,pz,mz,hz,gz,_z,vz,yz,bz,xz,Sz,Cz,wz,Tz,Ez,Dz,Oz,kz,Az,jz,Mz,Nz,Pz,Fz,Iz,Lz,Rz,zz,Bz,Vz,Hz,Uz,Wz,Gz,Kz,qz,Jz,Yz,Xz,Zz,Qz,$z,eB,tB,nB,rB,iB,aB,oB,sB,cB,lB,uB,dB=h((()=>{kR=()=>typeof window>`u`,AR=()=>typeof document<`u`,jR=class{_degreesHours=null;_degreesMinutes=null;_options;_isMobileView=!1;_isTouchMouseMove=!1;_disabledTime=null;_cloned=null;_isModalRemove=!0;_isOpen=!1;_isInitialized=!1;_eventHandlersRegistered=!1;_isDestroyed=!1;element;instanceId;customId;constructor(e,t,n,r){this.element=e,this.instanceId=n,this.customId=r,this._options=t}get degreesHours(){return this._degreesHours}get degreesMinutes(){return this._degreesMinutes}get options(){return this._options}get isMobileView(){return this._isMobileView}get isTouchMouseMove(){return this._isTouchMouseMove}get disabledTime(){return this._disabledTime}get cloned(){return this._cloned}get isModalRemove(){return this._isModalRemove}get isOpen(){return this._isOpen}get isInitialized(){return this._isInitialized}get eventHandlersRegistered(){return this._eventHandlersRegistered}get isDestroyed(){return this._isDestroyed}setDegreesHours(e){this._degreesHours=e}setDegreesMinutes(e){this._degreesMinutes=e}setOptions(e){this._options=e}setIsMobileView(e){this._isMobileView=e}setIsTouchMouseMove(e){this._isTouchMouseMove=e}setDisabledTime(e){this._disabledTime=e}setCloned(e){this._cloned=e}setIsModalRemove(e){this._isModalRemove=e}setIsOpen(e){this._isOpen=e}setIsInitialized(e){this._isInitialized=e}setEventHandlersRegistered(e){this._eventHandlersRegistered=e}setIsDestroyed(e){this._isDestroyed=e}updateOptions(e){this._options={...this._options,clock:{...this._options.clock,...e.clock||{}},ui:{...this._options.ui,...e.ui||{}},labels:{...this._options.labels,...e.labels||{}},behavior:{...this._options.behavior,...e.behavior||{}},callbacks:{...this._options.callbacks,...e.callbacks||{}}}}reset(){this._degreesHours=null,this._degreesMinutes=null,this._isTouchMouseMove=!1,this._disabledTime=null,this._cloned=null,this._isModalRemove=!0,this._isOpen=!1,this._isInitialized=!1,this._isDestroyed=!0,this._eventHandlersRegistered=!1}q(e){return this.getModalElement()?.querySelector(e)??null}qMobile(e,t){return this._isMobileView?this.q(e):this.q(t)}getModalElement(){return AR()===!1?null:document.querySelector(`[data-owner-id="${this.instanceId}"]`)}getInput(){return this.element?.querySelector(`input`)}getClockFace(){return this.qMobile(`.tp-ui-clock-face.mobile`,`.tp-ui-clock-face:not(.mobile)`)}getClockHand(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-clock-hand`,`.tp-ui-clock-hand:not(.mobile)`)}getCircle(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-circle-hand`,`.tp-ui-circle-hand:not(.mobile)`)}getTipsWrapper(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper`,`.tp-ui-tips-wrapper:not(.mobile)`)}getTipsWrapperFor24h(){return this.qMobile(`.tp-ui-mobile-clock-wrapper .tp-ui-tips-wrapper-24h`,`.tp-ui-tips-wrapper-24h:not(.mobile)`)}getMinutes(){return this.q(`.tp-ui-minutes`)}getHour(){return this.q(`.tp-ui-hour`)}getAM(){return this.q(`.tp-ui-am`)}getPM(){return this.q(`.tp-ui-pm`)}getHourText(){return this.q(`.tp-ui-hour-text`)}getMinutesText(){return this.q(`.tp-ui-minute-text`)}getHeader(){return this.q(`.tp-ui-header`)}getInputWrappers(){return this.getModalElement()?.querySelectorAll(`.tp-ui-input-wrapper`)||null}getDots(){return this.q(`.tp-ui-dots`)}getMinutesTips(){return this.q(`.tp-ui-minutes-time`)}getHourTips(){return this.q(`.tp-ui-hour-time-12`)}getAllValueTips(){let e=this.getModalElement();return e?[...e.querySelectorAll(`.tp-ui-value-tips`),...e.querySelectorAll(`.tp-ui-value-tips-24h`)]:[]}getOpenElementData(){let e=this.element?.querySelectorAll(`[data-open]`);if(e?.length>0){let t=[];return e.forEach(({dataset:e})=>t.push(e.open??``)),[...new Set(t)]}return null}getOpenElement(){let e=this.getInput(),t=this.getOpenElementData();return t===null?(e?.setAttribute(`data-open`,`tp-ui-input`),[e]):t.map(e=>this.element?.querySelectorAll(`[data-open='${e}']`))[0]??``}getCancelButton(){return this.q(`.tp-ui-cancel-btn`)}getOkButton(){return this.q(`.tp-ui-ok-btn`)}getActiveTypeMode(){return this.q(`.tp-ui-type-mode.active`)}getKeyboardClockIcon(){return this.q(`.tp-ui-keyboard-icon-wrapper`)}getFooter(){return this.q(`.tp-ui-footer`)}getWrapper(){return this.q(`.tp-ui-wrapper`)}},MR={DEFAULT_DELAY:300,MODAL_ANIMATION:150,SCROLLBAR_RESTORE:400,MODAL_REMOVE:300,CLOCK_ANIMATION:600,TIPS_ANIMATION:401,MOBILE_TOGGLE:450,CLOCK_SCALE_DELAY:150,WRAPPER_TRANSITION:400,DROPDOWN_CLICK_DELAY:10},NR=class{core;emitter;timeouts=[];constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on(`animation:clock`,()=>{this.handleAnimationSwitchTipsMode()})}runWithAnimation(e,t=MR.MODAL_ANIMATION){if(this.core.options.ui.animation){let n=setTimeout(e,t);this.timeouts.push(n)}else e()}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}setAnimationToOpen(){this.clearAllTimeouts(),this.core.getModalElement()?.classList.add(`opacity`),this.runWithAnimation(()=>{this.core.getModalElement()?.classList.add(`show`)})}removeAnimationToClose(){this.clearAllTimeouts(),this.core.getModalElement()&&this.runWithAnimation(()=>{let e=this.core.getModalElement();e?.classList.remove(`show`),e?.classList.remove(`opacity`)})}handleAnimationClock(){this.core.options.ui.animation&&this.runWithAnimation(()=>{this.core.getClockFace()?.classList.add(`tp-ui-clock-animation`);let e=setTimeout(()=>{this.core.getClockFace()?.classList.remove(`tp-ui-clock-animation`)},MR.CLOCK_ANIMATION);this.timeouts.push(e)})}handleAnimationSwitchTipsMode(){let e=this.core.getClockHand();if(!e)return;this.emitter.emit(`animation:start`,{}),e.classList.add(`tp-ui-tips-animation`);let t=setTimeout(()=>{this.core.getClockHand()?.classList.remove(`tp-ui-tips-animation`),this.emitter.emit(`animation:end`,{})},MR.TIPS_ANIMATION);this.timeouts.push(t)}destroy(){this.clearAllTimeouts()}},PR=()=>{if(AR()===!1)return 0;let e=document.createElement(`div`);e.className=`tp-ui-measure`,document.body.appendChild(e);let t=e.getBoundingClientRect().width-e.clientWidth;return document.body.removeChild(e),t},FR=(e,t)=>e?e.classList.contains(t):!1,IR=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(t,n)=>Number(e)+n),LR=(e,t)=>Array.from({length:Number(t)-Number(e)+1},(e,n)=>Number(t)-n).reverse(),RR=(e=``)=>{let t=e.replace(/(AM|PM|am|pm)/,e=>` ${e}`),n=new Date(`September 20, 2000 ${t}`);return`${n.getHours().toString().padStart(2,`0`)}:${n.getMinutes().toString().padStart(2,`0`)}`},zR=e=>{let[t,n]=e.split(`:`);return`${t.padStart(2,`0`)}:${n.padStart(2,`0`)}`},BR=(e,t)=>{if(e.length<2)return!1;let n=e.map(e=>{let[n,r]=e.trim().split(`-`),i,a;if(t===`12h`){if(!/\s?(AM|PM|am|pm)\s?$/.test(n.trim())||!/\s?(AM|PM|am|pm)\s?$/.test(r.trim()))throw Error(`Invalid 12h format: "${e}"`);i=RR(n.trim()),a=RR(r.trim())}else{if(/\s?(AM|PM|am|pm)\s?/.test(n.trim())||/\s?(AM|PM|am|pm)\s?/.test(r.trim()))throw Error(`Invalid 24h format: "${e}"`);i=zR(n.trim()),a=zR(r.trim())}return{start:i,end:a,original:e}});for(let e=0;e<n.length;e++)for(let t=e+1;t<n.length;t++){let r=n[e],i=n[t];if(r.start<=i.end&&r.end>=i.start||i.start<=r.end&&i.end>=r.start)throw Error(`Overlapping intervals: "${r.original}" and "${i.original}"`)}return!1},VR=()=>typeof window<`u`&&window.crypto&&typeof window.crypto.randomUUID==`function`?window.crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),HR=`<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-200q-33 0-56.5-23.5T80-280v-400q0-33 23.5-56.5T160-760h640q33 0 56.5 23.5T880-680v400q0 33-23.5 56.5T800-200H160Zm0-80h640v-400H160v400Zm160-40h320v-80H320v80ZM200-440h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM200-560h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80Zm120 0h80v-80h-80v80ZM160-280v-400 400Z"/></svg>`,UR=`<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z"/></svg>`,WR=class{plugins=new Map;register(e){this.plugins.has(e.name)||this.plugins.set(e.name,e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get(e){return this.plugins.get(e)}getTemplateProvider(e){return this.plugins.get(e)?.templateProvider}getClearHandler(e){return this.plugins.get(e)?.clearHandler}},GR=new WR,KR=[`00`,`13`,`14`,`15`,`16`,`17`,`18`,`19`,`20`,`21`,`22`,`23`],qR=[`12`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`],JR=[`00`,`05`,`10`,`15`,`20`,`25`,`30`,`35`,`40`,`45`,`50`,`55`],YR=(e,t,n)=>{let{timezone:{enabled:r,label:i}}=e;return!r||!GR.has(`timezone`)?``:`<div class="tp-ui-timezone ${t}">
225
225
  <span class="tp-ui-timezone-label" id="tp-tz-label-${n}">${i}</span>
226
226
  <div class="tp-ui-timezone-dropdown" role="combobox" aria-expanded="false" aria-haspopup="listbox" aria-labelledby="tp-tz-label-${n}" tabindex="0" data-tz-id="${n}">
227
227
  <div class="tp-ui-timezone-selected" data-placeholder="${i}...">${i}...</div>
228
228
  <svg class="tp-ui-timezone-arrow" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>
229
229
  <div class="tp-ui-timezone-menu" role="listbox" aria-labelledby="tp-tz-label-${n}"></div>
230
230
  </div>
231
- </div>`},OL=e=>{let{range:{enabled:t,fromLabel:n,toLabel:r},labels:{rangeSelectionLabel:i}}=e;return!t||!CL.has(`range`)?``:`<div class="tp-ui-range-header" role="tablist" aria-label="${i}"><button type="button" class="tp-ui-range-tab tp-ui-range-from active" role="tab" tabindex="0" aria-selected="true"><span class="tp-ui-range-tab-label">${n}</span><span class="tp-ui-range-tab-value tp-ui-range-from-time">--:--</span></button><button type="button" class="tp-ui-range-tab tp-ui-range-to" role="tab" tabindex="-1" aria-selected="false"><span class="tp-ui-range-tab-label">${r}</span><span class="tp-ui-range-tab-value tp-ui-range-to-time">--:--</span></button></div>`},kL=(e,t)=>{let{ui:{clearButton:n},labels:{clear:r}}=e;return n?`<div class="tp-ui-clear-btn ${t} disabled" data-md3-ripple tabindex="0" role="button" aria-label="${r}" aria-disabled="true">${r}</div>`:``},AL=(e,t,n)=>{if(e.isWheelMode){let t=CL.getTemplateProvider(`wheel`);return t?`<div class="tp-ui-mobile-clock-wrapper ${e.mobileClass}">${t(n,e.instanceId)}</div>`:`<div class="tp-ui-mobile-clock-wrapper ${e.mobileClass}"></div>`}let{labels:{clockLabel:r}}=n;return`<div class="tp-ui-mobile-clock-wrapper ${e.mobileClass}"><div class="tp-ui-body ${e.mobileClass}"><div class="tp-ui-clock-face ${e.mobileClass}" role="group" aria-label="${r}"><div class="tp-ui-dot ${e.mobileClass}" aria-hidden="true"></div><div class="tp-ui-clock-hand ${e.mobileClass}" aria-hidden="true"><div class="tp-ui-circle-hand ${e.mobileClass}"></div></div><div class="tp-ui-tips-wrapper ${e.mobileClass}" aria-hidden="true"></div>${e.clockType===`24h`?`<div class="tp-ui-tips-wrapper-24h ${e.mobileClass}" aria-hidden="true"></div>`:``}</div></div></div>`},jL=(e,t)=>{let{labels:{time:n,mobileTime:r,timeLabel:i,am:a,pm:o,mobileMinute:s,mobileHour:c,hourLabel:l,minuteLabel:u,periodLabel:d},ui:{editable:f}}=e,{mobileClass:p,clockType:m,instanceId:h}=t,g=p?r:n,_=m===`12h`,v=_?`1`:`0`,y=_?`12`:`23`,b=_?`12`:`0`,x=m===`24h`?``:`<div class="tp-ui-wrapper-type-time ${p}" role="group" aria-label="${d}"><div class="tp-ui-type-mode tp-ui-am ${p?`mobile`:`tp-ui-ripple`}" data-md3-ripple tabindex="0" role="button" aria-label="${a}" aria-pressed="false" data-type="AM">${a}</div><div class="tp-ui-type-mode tp-ui-pm ${p?`mobile`:`tp-ui-ripple`}" data-md3-ripple tabindex="0" role="button" aria-label="${o}" aria-pressed="false" data-type="PM">${o}</div></div>`;return`<div class="tp-ui-select-time ${p}" id="tp-ui-label-${h}">${g}</div><div class="tp-ui-header ${p}"><div class="tp-ui-wrapper-time ${p} ${m===`24h`?`tp-ui-wrapper-time-24h`:``}" role="group" aria-label="${i}"><div class="tp-ui-input-wrapper ${p}"><div class="tp-ui-input-ripple-wrapper ${p}" data-md3-ripple><input name="hour" ${!f&&!p?`readonly`:``} class="tp-ui-hour ${p}" tabindex="0" type="number" min="${v}" max="${y}" aria-label="${p?c:l}" role="spinbutton" aria-valuemin="${v}" aria-valuemax="${y}" aria-valuenow="${b}" aria-valuetext="${b}"></div><div class="tp-ui-hour-text ${p}">${c}</div></div><div class="tp-ui-dots ${p}" aria-hidden="true"><span></span><span></span></div><div class="tp-ui-input-wrapper ${p}"><div class="tp-ui-input-ripple-wrapper ${p}" data-md3-ripple><input name="minutes" ${!f&&!p?`readonly`:``} class="tp-ui-minutes ${p}" tabindex="0" type="number" min="0" max="59" aria-label="${p?s:u}" role="spinbutton" aria-valuemin="0" aria-valuemax="59" aria-valuenow="0" aria-valuetext="00"></div><div class="tp-ui-minute-text ${p}">${s}</div></div></div>${x}</div>`},ML=(e,t)=>{let{ui:{enableSwitchIcon:n,iconTemplate:r,iconTemplateMobile:i},labels:{cancel:a,ok:o,switchToKeyboardLabel:s,switchToClockLabel:c,toggleLabel:l}}=e,u=`<button aria-label="${s}" type="button" class="tp-ui-keyboard-icon">${r||bL}</button>`,d=i||`<button aria-label="${c}" type="button" class="tp-ui-keyboard-icon">${i||xL}</button>`,f=n?`<div class="tp-ui-keyboard-icon-wrapper ${t}" tabindex="0" role="button" aria-pressed="false" aria-label="${l}" data-view="desktop">${t?d:u}</div>`:``,p=kL(e,t);return`<div class="tp-ui-footer ${t}" ${t?`data-view="mobile"`:``}>${f}<div class="tp-ui-wrapper-btn ${t}">${p}<div class="tp-ui-cancel-btn ${t}" data-md3-ripple tabindex="0" role="button" aria-label="${a}">${a}</div><div class="tp-ui-ok-btn ${t}" data-md3-ripple tabindex="0" role="button" aria-label="${o}">${o}</div></div></div>`},NL=(e,t)=>{let{ui:{mode:n,animation:r,theme:i,mobile:a},clock:{incrementMinutes:o}}=e,s=a?`mobile`:``,c=n===`compact-wheel`&&CL.has(`wheel`),l=(n===`wheel`||c)&&CL.has(`wheel`),u=!!e.range?.enabled&&CL.has(`range`),d=!!e.timezone?.enabled&&CL.has(`timezone`),f={mobileClass:s,clockType:e.clock.type||`12h`,instanceId:t,isWheelMode:l,isCompactWheel:c,isRangeMode:u},p=OL(e),m=DL(e,s,t),h=c?``:jL(e,f),g=AL(f,o??1,e),_=c&&e.wheel?.hideFooter===!0?``:ML(e,s),v;return v=c?` tp-ui-compact-wheel-mode`:l?` tp-ui-wheel-mode`:``,`<div class="tp-ui-modal normalize ${s}${u?` tp-ui-range-mode`:``}${d?` tp-ui-tz-mode`:``}${v}" data-theme="${i}" role="dialog" aria-modal="true" aria-labelledby="tp-ui-label-${t}" data-owner-id="${t}" style='transition:${r?`opacity 0.15s linear`:`none`}'><div class="tp-ui-wrapper ${s}" tabindex="0">${p}${h}${m}${g}${_}</div><div class="timepicker-announcer sr-only" role="status" aria-live="polite" aria-atomic="true"></div></div>`},PL=0,FL=``,IL=``,LL=class{core;emitter;timeouts=[];scrollLocked=!1;constructor(e,t){this.core=e,this.emitter=t}runWithTimeout(e,t=uL.DEFAULT_DELAY){let n=setTimeout(e,t);this.timeouts.push(n)}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}isPopoverMode(){return this.core.options.ui.mode===`compact-wheel`&&!!this.core.options.wheel?.placement}clearExistingModal(){if(cL()===!1)return;let e=this.core.getModalElement();e&&e.remove()}setModalTemplate(){if(cL()===!1)return;this.clearExistingModal();let e=NL(this.core.options,this.core.instanceId);if(this.core.options.ui.inline?.enabled){let t=document.getElementById(this.core.options.ui.inline.containerId);if(!t)return;t.innerHTML=``,t.insertAdjacentHTML(`beforeend`,e);let n=t.querySelector(`.tp-ui-modal`);if(n){n.classList.add(`tp-ui--inline`);let{showButtons:e}=this.core.options.ui.inline;(e===!1||e===void 0)&&n.querySelectorAll(`.tp-ui-wrapper-btn, .tp-ui-wrapper-btn.mobile`).forEach(e=>e.style.display=`none`)}return}let{appendModalSelector:t}=this.core.options.ui;t?document.querySelector(t)?.insertAdjacentHTML(`beforeend`,e):document.body.insertAdjacentHTML(`beforeend`,e)}lockScroll(){cL()!==!1&&(this.core.options.ui.inline?.enabled||this.isPopoverMode()||this.core.options.ui.enableScrollbar||this.scrollLocked||(this.scrollLocked=!0,BI()))}unlockScroll(){cL()!==!1&&this.scrollLocked&&(this.scrollLocked=!1,VI())}setScrollbarOrNot(){cL()!==!1&&(this.core.options.ui.inline?.enabled||this.isPopoverMode()||(this.core.options.ui.enableScrollbar?this.runWithTimeout(()=>{sL()||this.runWithTimeout(()=>{this.unlockScroll()},uL.SCROLLBAR_RESTORE)},400):this.lockScroll()))}removeBackdrop(){if(this.core.options.ui.inline?.enabled||this.core.options.ui.backdrop)return;let e=this.core.getModalElement(),t=this.core.getOpenElement();e?.classList.add(`removed`),t.forEach(e=>e?.classList.add(`disabled`))}setNormalizeClass(){let e=this.core.getModalElement();e&&(e.classList.add(`tp-ui-normalize`),e.querySelectorAll(`:scope > div`).forEach(e=>e.classList.add(`tp-ui-normalize`)))}setShowClassToBackdrop(){if(this.core.options.ui.inline?.enabled||this.isPopoverMode()){this.core.getModalElement()?.classList.add(`show`),this.setInitialFocus();return}this.core.options.ui.backdrop&&this.runWithTimeout(()=>{this.core.getModalElement()?.classList.add(`show`),this.setInitialFocus()},uL.MODAL_ANIMATION)}setInitialFocus(){if(!this.core.options.behavior.focusTrap)return;let e=this.core.getWrapper();e&&typeof requestAnimationFrame<`u`&&requestAnimationFrame(()=>{e.focus()})}setFlexEndToFooterIfNoKeyboardIcon(){let e=this.core.getFooter();!this.core.options.ui.enableSwitchIcon&&e&&(e.style.justifyContent=`flex-end`)}destroy(){this.clearAllTimeouts(),this.unlockScroll(),this.clearExistingModal()}},RL=(e,t,n,r)=>{let i={hour:`12`,minutes:`00`,type:t===`24h`?void 0:`PM`};if(!e)return i;let a=e.value.trim();if(!n&&!a)return i;if(typeof n==`boolean`&&n){let[e,n]=new Date().toLocaleTimeString().split(`:`),r=e.padStart(2,`0`);if(/[a-z]/i.test(n)&&t===`12h`){let[e,t]=n.split(` `);return{hour:r,minutes:e,type:t}}return{hour:r,minutes:n,type:void 0}}if(typeof n==`object`){let{time:e,locales:i,preventClockType:a}=n,o=e??new Date;if(a&&r){let[e,t]=new Date(o).toLocaleTimeString().split(`:`);if(/[a-z]/i.test(t)){let[n,r]=t.split(` `);return{hour:e,minutes:n,type:r}}return{hour:e.padStart(2,`0`),minutes:t,type:void 0}}let[s,c]=new Date(o).toLocaleTimeString(i||`en-US`,{hour:`2-digit`,minute:`2-digit`,hour12:t===`12h`}).split(`:`);if(t===`12h`&&/[a-z]/i.test(c)){let e=c.trim().split(` `);return{hour:s,minutes:e[0],type:e[1]||`AM`}}return{hour:s,minutes:c.replace(/\D/g,``),type:void 0}}let[o,s]=a.split(` `),[c=``,l=``]=o.split(`:`),u=c.replace(/\D/g,``),d=l.replace(/\D/g,``),f={hour:u.padStart(2,`0`),minutes:d.padStart(2,`0`),type:t===`12h`?s:void 0};if(u.length>2||d.length>2)return{...f,error:`Invalid input: too many digits.`,currentHour:c,currentMin:l};if(/[a-z]/i.test(o))return{...f,error:`Input contains invalid letters.`};if(a.includes(` `)&&(!s||a.length>8||s!==`AM`&&s!==`PM`))return{...f,error:`Invalid AM/PM format or length.`,currentLength:a.length,currentType:s};let p=Number(u),m=Number(d);if(t===`12h`){if(p<1||p>12||m<0||m>59||s!==`AM`&&s!==`PM`)return{...f,error:`Invalid 12h time.`,currentHour:p,currentMin:m,currentType:s}}else if(p<0||p>23||m<0||m>59)return{...f,error:`Invalid 24h time.`,currentHour:p,currentMin:m};return f},zL=(e,t,n)=>{let r=Number(e);if(Number.isNaN(r))return!1;switch(t){case`hour`:return n===`24h`?r>=0&&r<=23:r>0&&r<=12;case`minutes`:return r>=0&&r<=59;default:return}},BL=`tp-ui`,VL=`mousedown mouseup mousemove mouseleave mouseover touchstart touchmove touchend`,HL=`active`,UL=class{core;emitter;constructor(e,t){this.core=e,this.emitter=t}isCurrentTimeEnabled(e){let t=this.core.options.clock.currentTime;return typeof t==`boolean`?t:!!t?.[e]}preventClockTypeByCurrentTime(){if(!this.isCurrentTimeEnabled(`preventClockType`))return;let e=this.core.getInput();if(!e)return;let{currentTime:t,clockType:n}={currentTime:this.core.options.clock.currentTime,clockType:this.core.options.clock.type},{type:r}=RL(e,n,t,!0);this.core.updateOptions({clock:{type:r?`12h`:`24h`}})}updateInputValueWithCurrentTimeOnStart(){if(!this.isCurrentTimeEnabled(`updateInput`))return;let e=this.core.getInput();if(!e)return;let{hour:t,minutes:n,type:r}=RL(e,this.core.options.clock.type,this.core.options.clock.currentTime);e.value=r?`${t}:${n} ${r}`:`${t}:${n}`}getInputValueOnOpenAndSet(){let e=this.core.getInput();if(!e)return;let t=RL(e,this.core.options.clock.type,this.core.options.clock.currentTime),n=this.core.getHour(),r=this.core.getMinutes(),i=this.core.getActiveTypeMode(),a=this.core.getAM();if(t===void 0){n&&(n.value=`12`),r&&(r.value=`00`);let e={hour:n?.value||`12`,minutes:r?.value||`00`,type:i?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit(`open`,e);let t=this.core.options.range?.enabled===!0;this.core.options.clock.type!==`24h`&&a&&!t&&a.classList.add(HL);return}let[o,s,c]=e.value.split(`:`).join(` `).split(` `);e.value.length===0&&(o=t.hour,s=t.minutes,c=t.type),this.core.options.clock.type!==`24h`&&!c&&(c=t.type||`AM`),n&&(n.value=o.padStart(2,`0`)),r&&(r.value=s.padStart(2,`0`));let l=this.core.getModalElement()?.querySelector(`[data-type='${c}']`);this.core.options.clock.type!==`24h`&&l&&l.classList.add(HL);let u={...t,type:i?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit(`open`,u)}getInputValue(e,t,n){return RL(e,t,n)}destroy(){}},WL=class{core;emitter;isAnimating=!1;constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on(`switch:view`,()=>{this.toggleMobileClockFace()})}checkMobileOption(){this.core.setIsMobileView(!!this.core.options.ui.mobile),this.core.options.ui.mobile&&this.core.updateOptions({ui:{editable:!0}})}toggleMobileClockFace(){if(this.isAnimating)return;let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-wrapper`),n=this.core.getKeyboardClockIcon(),r=e.querySelector(`.tp-ui-mobile-clock-wrapper`),i=e.querySelectorAll(`*`),a=e.querySelector(`.tp-ui-select-time`),o=this.core.getHour(),s=this.core.getMinutes(),c=this.core.getClockFace();if(!t)return;let l=t.classList.contains(`expanded`),u=this.core.isMobileView;l?this.collapseClockFace(t,r,i,n,a,o,s,c,u):this.expandClockFace(t,r,i,n,a,o,s,c)}collapseClockFace(e,t,n,r,i,a,o,s,c){if(this.isAnimating=!0,typeof requestAnimationFrame<`u`){let l=typeof window<`u`&&window.matchMedia(`(orientation: landscape) and (min-width: 320px) and (max-width: 825px)`).matches;requestAnimationFrame(()=>{l&&e instanceof HTMLElement?this.collapseLandscape(e,t,n,r,i,a,o,s,c):this.collapsePortrait(e,t,n,r,i,a,o,s,c)})}else this.switchView(i,r,a,o,!0),this.isAnimating=!1;r?.setAttribute(`aria-label`,`Show clock face`),r?.setAttribute(`aria-pressed`,`false`)}collapseLandscape(e,t,n,r,i,a,o,s,c){s?.classList.remove(`scale-in`);let l=this.core.getModalElement(),u=this.getMobileLandscapeHeight(l);e.style.width=`328px`,e.style.height=u,t instanceof HTMLElement&&(t.style.height=`0`,t.style.opacity=`0`,t.style.transform=`scale(0)`),setTimeout(()=>{this.applyMobileClasses(e,t,n,i,c),e.classList.add(`mobile`),t&&t.classList.add(`mobile`),this.switchView(i,r,a,o,!0),requestAnimationFrame(()=>{e.style.width=``,e.style.height=``,t instanceof HTMLElement&&(t.style.height=``,t.style.opacity=``,t.style.transform=``),this.isAnimating=!1})},uL.WRAPPER_TRANSITION)}collapsePortrait(e,t,n,r,i,a,o,s,c){c?s?.classList.remove(`scale-in`):s?.classList.add(`scale-in`),t?.classList.remove(`expanded`),c&&t?.classList.add(`mobile`),requestAnimationFrame(()=>{this.applyMobileClasses(e,t,n,i,c),this.switchView(i,r,a,o,!0),setTimeout(()=>{this.isAnimating=!1},uL.MOBILE_TOGGLE)})}applyMobileClasses(e,t,n,r,i){e.classList.remove(`expanded`),t?.classList.remove(`expanded`),i&&(e.classList.add(`mobile`),t?.classList.add(`mobile`)),n.forEach(n=>{n!==t&&n!==e&&n!==r&&(n.classList.remove(`expanded`),i&&n.classList.add(`mobile`))}),r&&(r.classList.remove(`expanded`),i&&r.classList.add(`mobile`))}expandClockFace(e,t,n,r,i,a,o,s){this.isAnimating=!0,o?.classList.contains(`active`)&&o?this.emitter.emit(`select:minute`,{minutes:o.value}):a&&this.emitter.emit(`select:hour`,{hour:a.value}),n.forEach(n=>{n!==t&&n!==e&&n!==i&&(n.classList.remove(`mobile`),n.classList.add(`expanded`))}),i&&(i.classList.remove(`mobile`),i.classList.add(`expanded`)),this.switchView(i,r,a,o,!1),typeof requestAnimationFrame<`u`?requestAnimationFrame(()=>{e.classList.remove(`mobile`),e.classList.add(`expanded`),requestAnimationFrame(()=>{t&&(t.classList.remove(`mobile`),t.classList.add(`expanded`)),s&&s.classList.remove(`scale-in`),setTimeout(()=>{s&&s.classList.add(`scale-in`)},uL.CLOCK_SCALE_DELAY),setTimeout(()=>{this.isAnimating=!1},uL.MOBILE_TOGGLE)})}):this.isAnimating=!1,r?.setAttribute(`aria-label`,`Hide clock face`),r?.setAttribute(`aria-pressed`,`true`)}switchView(e,t,n,r,i){let a=this.core.getModalElement(),o=a?.querySelector(`.tp-ui-hour-text`),s=a?.querySelector(`.tp-ui-minute-text`),c=t?.querySelector(`.tp-ui-keyboard-icon`),l=this.core.getInputWrappers(),u=this.core.getHeader(),d=a?.querySelector(`.tp-ui-wrapper-type-time`),f=a?.querySelector(`.tp-ui-am`),p=a?.querySelector(`.tp-ui-pm`),m=a?.querySelectorAll(`.tp-ui-input-ripple-wrapper`),{iconTemplate:h,iconTemplateMobile:g}=this.core.options.ui,{time:_,mobileTime:v}=this.core.options.labels;i?(e?.classList.add(`mobile`),t?.classList.add(`mobile`),n?.classList.add(`mobile`),n?.removeAttribute(`readonly`),r?.classList.add(`mobile`),r?.removeAttribute(`readonly`),o?.classList.add(`mobile`),s?.classList.add(`mobile`),u?.classList.add(`mobile`),d?.classList.add(`mobile`),f?.classList.add(`mobile`),f?.classList.remove(`tp-ui-ripple`),p?.classList.add(`mobile`),p?.classList.remove(`tp-ui-ripple`),l?.forEach(e=>{e.classList.add(`mobile`)}),m?.forEach(e=>{e.classList.add(`mobile`)}),e&&v&&(e.textContent=v),c&&(c.innerHTML=g||xL),this.updateClockFaceAccessibility(!0)):(e?.classList.remove(`mobile`),t?.classList.remove(`mobile`),n?.classList.remove(`mobile`),r?.classList.remove(`mobile`),this.core.options.ui.editable||(n?.setAttribute(`readonly`,``),r?.setAttribute(`readonly`,``)),o?.classList.remove(`mobile`),s?.classList.remove(`mobile`),u?.classList.remove(`mobile`),d?.classList.remove(`mobile`),f?.classList.remove(`mobile`),f?.classList.add(`tp-ui-ripple`),p?.classList.remove(`mobile`),p?.classList.add(`tp-ui-ripple`),l?.forEach(e=>{e.classList.remove(`mobile`)}),m?.forEach(e=>{e.classList.remove(`mobile`)}),e&&_&&(e.textContent=_),c&&(c.innerHTML=h||bL),this.updateClockFaceAccessibility(!1))}updateClockFaceAccessibility(e){let t=this.core.getClockFace();if(!t)return;let n=t.querySelector(`.tp-ui-tips-wrapper`),r=t.querySelector(`.tp-ui-tips-wrapper-24h`),i=t.querySelectorAll(`.tp-ui-tip`);e?(t.setAttribute(`aria-hidden`,`true`),n?.setAttribute(`aria-hidden`,`true`),r?.setAttribute(`aria-hidden`,`true`),i.forEach(e=>{e.setAttribute(`tabindex`,`-1`),e.setAttribute(`aria-hidden`,`true`)})):(t.removeAttribute(`aria-hidden`),n?.removeAttribute(`aria-hidden`),r?.removeAttribute(`aria-hidden`),i.forEach(e=>{e.setAttribute(`tabindex`,`0`),e.removeAttribute(`aria-hidden`)}))}getMobileLandscapeHeight(e){return e?.classList.contains(`tp-ui-tz-mode`)?`326px`:e?.classList.contains(`tp-ui-range-mode`)?`287px`:`258px`}destroy(){}},GL=e=>{if(!e)return;let{disabledTime:t,type:n}=e.clock;if(!t||!Object.keys(t).length)return;let{hours:r,minutes:i,interval:a}=t;if(a){delete t.hours,delete t.minutes;let e=Array.isArray(a)?a:[a];if(!n)throw Error(`clockType required for interval`);return vL(e,n),{value:e.map(e=>{let[t,r]=e.trim().split(`-`),{hour:i,minutes:a,type:o}=RL({value:t.trim()},n),{hour:s,minutes:c,type:l}=RL({value:r.trim()},n),u=mL(i,s).map(e=>Number(e)===0?`00`:String(Number(e))),d=[],f=Number(a),p=Number(c);if(l===o)return f>0&&p<=0?(d.push(u[0],u[u.length-1]),u=u.slice(1,-1)):p<59&&p>0&&f<=0?(d.push(void 0,u[u.length-1]),u=u.slice(0,-1)):p>0&&f>0?(d.push(u[0],u[u.length-1]),u=u.slice(1,-1)):p===0&&f===0&&(d.push(void 0,u[u.length-1]),u.pop()),{removedStartedHour:d[0]!==void 0&&Number(d[0])<=9?`0${d[0]}`:d[0],removedEndHour:d[1]!==void 0&&Number(d[1])<=9?`0${d[1]}`:d[1],rangeArrHour:u,startMinutes:mL(a,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:hL(0,c).map(e=>Number(e)<=9?`0${e}`:`${e}`),startType:o,endType:l};{let e=mL(i,12).map(String),t=hL(1,s).map(String),n=[],r=[];return f>0&&p<=0?(r.push(t[t.length-1]),n.push(e[0]),t.pop(),e.shift()):p<59&&p>0&&f<=0?(n.push(e[0]),r.push(t[t.length-1]),t.pop()):p>0&&f>0?(r.push(t[t.length-1]),n.push(e[0]),t.pop(),e.shift()):p===0&&f===0&&(r.push(t[t.length-1]),n.push(e[0]),t.pop()),{startType:o,endType:l,amHours:e,pmHours:t,removedAmHour:n[0]&&Number(n[0])<=9?`0${n[0]}`:n[0],removedPmHour:r[0]&&Number(r[0])<=9?`0${r[0]}`:r[0],startMinutes:Number(a)===0?[]:mL(a,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:hL(0,c).map(e=>Number(e)<=9?`0${e}`:`${e}`)}}}).reduce((e,t)=>(Object.entries(t).forEach(([t,n])=>{e[t]=Array.isArray(n)?Array.isArray(e[t])?[...e[t],...n]:[...n]:n}),e),{isInterval:!0,clockType:n,intervals:e})}}return r?.forEach(e=>{if(n===`12h`&&Number(e)>12)throw Error(`The disabled hours value has to be less than 13`);if(n===`24h`&&Number(e)>23)throw Error(`The disabled hours value has to be less than 24`)}),i?.forEach(e=>{if(Number(e)>59)throw Error(`The disabled minutes value has to be less than 60`)}),{value:{hours:r?.map(e=>e===`00`||Number(e)===0?`0${Number(e)}`:`${Number(e)}`),minutes:i?.map(e=>Number(e)<=9?`0${e}`:`${e}`)}}},KL=(e,t,n,r)=>{if(e){if(Array.isArray(e)&&e.length>0)return!e.map(e=>zL(e,t,n)).some(e=>e===!1);if(typeof e==`string`||typeof e==`number`){let i=zL(e,t,n),a=r?.map(Number).includes(Number(e));return!!(i&&!a)}}},qL=class{core;constructor(e){this.core=e}getDisableTime(){let e=GL(this.core.options);this.core.setDisabledTime(e||null)}destroy(){}},JL=class{inputValueHandler;mobileViewHandler;disabledTimeHandler;core;constructor(e,t){this.core=e,this.inputValueHandler=new UL(e,t),this.mobileViewHandler=new WL(e,t),this.disabledTimeHandler=new qL(e)}preventClockTypeByCurrentTime(){this.inputValueHandler.preventClockTypeByCurrentTime()}updateInputValueWithCurrentTimeOnStart(){this.inputValueHandler.updateInputValueWithCurrentTimeOnStart()}getInputValueOnOpenAndSet(){this.inputValueHandler.getInputValueOnOpenAndSet()}getInputValue(e,t,n){return this.inputValueHandler.getInputValue(e,t,n)}checkMobileOption(){this.mobileViewHandler.checkMobileOption()}toggleMobileClockFace(){this.mobileViewHandler.toggleMobileClockFace()}updateClockFaceAccessibility(e){this.mobileViewHandler.updateClockFaceAccessibility(e)}getDisableTime(){this.disabledTimeHandler.getDisableTime()}destroy(){this.inputValueHandler.destroy(),this.mobileViewHandler.destroy(),this.disabledTimeHandler.destroy()}},YL=class{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setTheme(){let e=this.core.getModalElement();if(!e)return;let{theme:t}=this.core.options.ui;t&&e.setAttribute(`data-theme`,t)}setInputClassToInputElement(){let e=this.core.getInput();e&&(pL(e,`tp-ui-input`)||e.classList.add(`tp-ui-input`))}setDataOpenToInputIfDoesntExistInWrapper(){let e=this.core.getOpenElementData(),t=this.core.getInput();e===null&&t&&t.setAttribute(`data-open`,`tp-ui-input`)}setClassTopOpenElement(){let e=this.core.getOpenElement();for(let t of e)t&&t.classList.add(`tp-ui-open-element`)}setTimepickerClassToElement(){let e=this.core.element;if(!e)return;e.classList.add(BL);let t=this.core.options.ui.cssClass;t&&t!==BL&&e.classList.add(t)}destroy(){let e=this.core.getModalElement();e&&e.removeAttribute(`data-theme`)}},XL=class e extends Error{constructor(t,n){super(`[TimepickerUI] ${t}`),this.code=n,this.name=`TimepickerError`,Object.setPrototypeOf(this,e.prototype)}},ZL={ELEMENT_NOT_FOUND:`ELEMENT_NOT_FOUND`,INVALID_PARAMETER:`INVALID_PARAMETER`,NO_INPUT_ELEMENT:`NO_INPUT_ELEMENT`,INSTANCE_DESTROYED:`INSTANCE_DESTROYED`,NOT_INITIALIZED:`NOT_INITIALIZED`,INVALID_TIME_FORMAT:`INVALID_TIME_FORMAT`,INLINE_CONFIG_ERROR:`INLINE_CONFIG_ERROR`,CONTAINER_NOT_FOUND:`CONTAINER_NOT_FOUND`,SSR_ENVIRONMENT:`SSR_ENVIRONMENT`},QL=(e,t)=>{if(!e)return;let n=e.querySelector(`.timepicker-announcer`);n&&(n.textContent=``,setTimeout(()=>{n.textContent=t},100))},$L=(e,t)=>{e&&e.setAttribute(`aria-pressed`,String(t))},eR=e=>e.getAttribute(`aria-disabled`)===`true`||e.classList.contains(`disabled`),tR=(e,t)=>{if(!e)return()=>{};let n=n=>{eR(e)||t(n)},r=n=>{n.key!==`Enter`&&n.key!==` `&&n.key!==`Spacebar`||((n.key===` `||n.key===`Spacebar`)&&n.preventDefault(),!eR(e)&&t(n))};return e.addEventListener(`click`,n),e.addEventListener(`keydown`,r),()=>{e.removeEventListener(`click`,n),e.removeEventListener(`keydown`,r)}},nR=()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,rR=class{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setErrorHandler(){let e=this.core.getInput();if(!e)return!0;let{error:t,currentHour:n,currentMin:r,currentType:i,currentLength:a}=RL(e,this.core.options.clock.type);if(this.removeErrorHandler(),t){if(cL()===!1)return!1;let o=this.core.options.labels.invalidTimeFormat??`Invalid time format`,s=document.createElement(`div`);s.classList.add(`tp-ui-invalid-text`),s.setAttribute(`role`,`alert`);let c=document.createElement(`b`);c.textContent=o,s.appendChild(c),e.classList.add(`tp-ui-invalid-format`),e.nextElementSibling?.classList.contains(`tp-ui-invalid-text`)||e.after(s),QL(this.core.getModalElement(),o);let l={error:t,rejectedHour:void 0,rejectedMinute:void 0,inputHour:n,inputMinute:r,inputType:i,inputLength:a};return this.emitter.emit(`error`,l),!1}return!0}removeErrorHandler(){let e=this.core.getInput();if(!e)return;e.classList.remove(`tp-ui-invalid-format`);let t=e.nextElementSibling;t?.classList.contains(`tp-ui-invalid-text`)&&t.remove()}checkDisabledValuesOnStart(){if(!this.core.options.clock.disabledTime)return;let{disabledTime:e,type:t}=this.core.options.clock;if(e.interval){if(!t)throw new XL(`clockType is required when using disabledTime.interval`,ZL.INVALID_PARAMETER);let n=Array.isArray(e.interval)?e.interval:[e.interval];try{vL(n,t)}catch(e){throw new XL(`Invalid disabledTime.interval: ${e.message}`,ZL.INVALID_PARAMETER)}return}let{hours:n,minutes:r}=e,i=!n||KL(n,`hour`,t),a=!r||KL(r,`minutes`,t);if(!i||!a)throw new XL(`Invalid hours or minutes in disabledTime option`,ZL.INVALID_PARAMETER)}destroy(){this.removeErrorHandler()}},iR=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnClick(){let e=this.core.getOpenElement();if(!e)return;let t=()=>{this.core.isDestroyed||this.emitter.emit(`show`,{})};e.forEach(e=>{this.cleanupHandlers.push(tR(e,t))})}handleCancelButton(){let e=this.core.getCancelButton();e&&this.cleanupHandlers.push(tR(e,()=>{this.core.isDestroyed||this.emitter.emit(`cancel`,{})}))}handleOkButton(){let e=this.core.getOkButton();e&&this.cleanupHandlers.push(tR(e,()=>{if(this.core.isDestroyed||e.getAttribute(`aria-disabled`)===`true`)return;let t=this.core.getHour(),n=this.core.getMinutes();if(t&&n){let e=this.core.getActiveTypeMode();this.emitter.emit(`confirm`,{hour:t.value,minutes:n.value,type:e?.textContent||void 0});return}let r=this.core.getModalElement();if(r){let e=r.querySelector(`.tp-ui-wheel-hours .tp-ui-wheel-item.is-center`),t=r.querySelector(`.tp-ui-wheel-minutes .tp-ui-wheel-item.is-center`),n=r.querySelector(`.tp-ui-wheel-ampm .tp-ui-wheel-item.is-center`);this.emitter.emit(`confirm`,{hour:e?.getAttribute(`data-value`)??void 0,minutes:t?.getAttribute(`data-value`)??void 0,type:n?.getAttribute(`data-value`)??void 0})}}))}handleAmClick(){let e=this.core.getAM();e&&this.cleanupHandlers.push(tR(e,()=>{if(this.core.isDestroyed)return;let t=this.core.getPM();e.classList.add(`active`),t?.classList.remove(`active`),$L(e,!0),$L(t,!1),QL(this.core.getModalElement(),this.core.options.labels.announceAmSelected??`AM selected`),this.emitter.emit(`select:am`,{});let n=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit(`update`,{hour:n?.value,minutes:r?.value,type:`AM`})}))}handlePmClick(){let e=this.core.getPM();e&&this.cleanupHandlers.push(tR(e,()=>{if(this.core.isDestroyed)return;let t=this.core.getAM();e.classList.add(`active`),t?.classList.remove(`active`),$L(e,!0),$L(t,!1),QL(this.core.getModalElement(),this.core.options.labels.announcePmSelected??`PM selected`),this.emitter.emit(`select:pm`,{});let n=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit(`update`,{hour:n?.value,minutes:r?.value,type:`PM`})}))}handleSwitchViewButton(){let e=this.core.getKeyboardClockIcon();e&&this.cleanupHandlers.push(tR(e,()=>{this.core.isDestroyed||this.emitter.emit(`switch:view`,{})}))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},aR=(e,t,n)=>Math.max(t,Math.min(n,e)),oR=(e,t)=>{if(e===``)return``;let n=parseInt(e,10);return Number.isNaN(n)?``:aR(n,+!!t,t?12:23).toString().padStart(2,`0`)},sR=e=>{if(e===``)return``;let t=parseInt(e,10);return Number.isNaN(t)?``:aR(t,0,59).toString().padStart(2,`0`)},cR=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleHourEvents(){let e=this.core.getHour();if(!e)return;let t=()=>{if(this.core.isDestroyed)return;e.classList.add(`active`);let t=this.core.getMinutes();t?.classList.remove(`active`),this.emitter.emit(`select:hour`,{hour:e.value});let n=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e.value,minutes:t?.value,type:n?.textContent||void 0})};e.addEventListener(`click`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`click`,t));let n=e.value,r=()=>{if(this.core.isDestroyed||e.hasAttribute(`readonly`))return;let t=this.core.options.clock.type===`12h`,r=oR(e.value,t);if(e.value=r,e.setAttribute(`aria-valuenow`,r),e.value!==n){n=e.value,this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:hour`,{hour:e.value});let t=this.core.getMinutes(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e.value,minutes:t?.value,type:r?.textContent||void 0})}};e.addEventListener(`blur`,r),this.cleanupHandlers.push(()=>e.removeEventListener(`blur`,r))}handleMinutesEvents(){let e=this.core.getMinutes();if(!e)return;let t=()=>{if(this.core.isDestroyed)return;e.classList.add(`active`);let t=this.core.getHour();t?.classList.remove(`active`),this.emitter.emit(`select:minute`,{minutes:e.value});let n=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:t?.value,minutes:e.value,type:n?.textContent||void 0})};e.addEventListener(`click`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`click`,t));let n=e.value,r=()=>{if(this.core.isDestroyed||e.hasAttribute(`readonly`))return;let t=sR(e.value);if(e.value=t,e.setAttribute(`aria-valuenow`,t),e.value!==n){n=e.value,this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:minute`,{minutes:e.value});let t=this.core.getHour(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:t?.value,minutes:e.value,type:r?.textContent||void 0})}};e.addEventListener(`blur`,r),this.cleanupHandlers.push(()=>e.removeEventListener(`blur`,r))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},lR=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnEnterFocus(){let e=this.core.getInput();if(!e)return;let t=e=>{e.key===`Enter`&&!this.core.isDestroyed&&!this.core.isOpen&&this.emitter.emit(`show`,{})};e.addEventListener(`keydown`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,t))}handleEscClick(){if(cL()===!1)return;let e=e=>{this.core.isDestroyed||this.core.isOpen&&e.key===`Escape`&&this.emitter.emit(`cancel`,{})};document.addEventListener(`keydown`,e),this.cleanupHandlers.push(()=>document.removeEventListener(`keydown`,e))}handleKeyboardInput(){let e=this.core.getHour(),t=this.core.getMinutes(),n=[`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`];if(e){let t=t=>{if(this.core.isDestroyed||!n.includes(t.key))return;t.preventDefault();let r=parseInt(e.value)||0,i=parseInt(e.getAttribute(`max`)||`23`),a=+(this.core.options.clock.type===`12h`),o=this.computeSpinValue(t.key,r,a,i,3);e.value=o.toString().padStart(2,`0`),e.setAttribute(`aria-valuenow`,e.value),e.setAttribute(`aria-valuetext`,e.value),QL(this.core.getModalElement(),`${this.core.options.labels.announceHour??`Hour`}: ${e.value}`),this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:hour`,{hour:e.value});let s=this.core.getMinutes(),c=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e.value,minutes:s?.value,type:c?.textContent||void 0})};e.addEventListener(`keydown`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,t))}if(t){let e=e=>{if(this.core.isDestroyed||!n.includes(e.key))return;e.preventDefault();let r=parseInt(t.value)||0,i=this.computeSpinValue(e.key,r,0,59,5);t.value=i.toString().padStart(2,`0`),t.setAttribute(`aria-valuenow`,t.value),t.setAttribute(`aria-valuetext`,t.value),QL(this.core.getModalElement(),`${this.core.options.labels.announceMinute??`Minutes`}: ${t.value}`),this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:minute`,{minutes:t.value});let a=this.core.getHour(),o=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:a?.value,minutes:t.value,type:o?.textContent||void 0})};t.addEventListener(`keydown`,e),this.cleanupHandlers.push(()=>t.removeEventListener(`keydown`,e))}}computeSpinValue(e,t,n,r,i){switch(e){case`ArrowUp`:return t>=r?n:t+1;case`ArrowDown`:return t<=n?r:t-1;case`Home`:return n;case`End`:return r;case`PageUp`:return Math.min(r,t+i);case`PageDown`:return Math.max(n,t-i);default:return t}}focusTrapHandler(){if(cL()===!1)return;let e=this.core.getWrapper();if(!e)return;let t=t=>{if(this.core.isDestroyed||t.key!==`Tab`)return;let n=e.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`),r=[];if(n.forEach(e=>{e.getAttribute(`aria-disabled`)!==`true`&&(e.hasAttribute(`disabled`)||e.hidden||e.getAttribute(`aria-hidden`)!==`true`&&(e.offsetParent===null&&e.getClientRects().length===0||r.push(e)))}),r.length===0)return;let i=r[0],a=r[r.length-1];t.shiftKey&&document.activeElement===i?(a?.focus(),t.preventDefault()):!t.shiftKey&&document.activeElement===a&&(i?.focus(),t.preventDefault())};e.addEventListener(`keydown`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,t))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},uR=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleBackdropClick(){let e=this.core.getModalElement();if(!e)return;let t=t=>{this.core.isDestroyed||t.target===e&&this.emitter.emit(`cancel`,{})};e.addEventListener(`click`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`click`,t))}handleMoveHand(){if(cL()===!1)return;let e=e=>{this.core.isDestroyed||e.preventDefault()};document.addEventListener(`mousedown`,e,!1),document.addEventListener(`touchstart`,e,{passive:!1}),this.cleanupHandlers.push(()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)})}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},dR=class{buttonHandlers;inputHandlers;keyboardHandlers;modalHandlers;constructor(e,t){this.buttonHandlers=new iR(e,t),this.inputHandlers=new cR(e,t),this.keyboardHandlers=new lR(e,t),this.modalHandlers=new uR(e,t)}handleOpenOnClick(){this.buttonHandlers.handleOpenOnClick()}handleOpenOnEnterFocus(){this.keyboardHandlers.handleOpenOnEnterFocus()}handleCancelButton(){this.buttonHandlers.handleCancelButton()}handleOkButton(){this.buttonHandlers.handleOkButton()}handleBackdropClick(){this.modalHandlers.handleBackdropClick()}handleEscClick(){this.keyboardHandlers.handleEscClick()}handleAmClick(){this.buttonHandlers.handleAmClick()}handlePmClick(){this.buttonHandlers.handlePmClick()}handleHourEvents(){this.inputHandlers.handleHourEvents()}handleMinutesEvents(){this.inputHandlers.handleMinutesEvents()}handleKeyboardInput(){this.keyboardHandlers.handleKeyboardInput()}focusTrapHandler(){this.keyboardHandlers.focusTrapHandler()}handleMoveHand(){this.modalHandlers.handleMoveHand()}handleSwitchViewButton(){this.buttonHandlers.handleSwitchViewButton()}destroy(){this.buttonHandlers.destroy(),this.inputHandlers.destroy(),this.keyboardHandlers.destroy(),this.modalHandlers.destroy()}},fR=class{emitter;getClockSystem;setHoursToClock;setMinutesToClock;updateAmPm;convertDisabledTime;constructor(e,t,n,r,i,a){this.emitter=e,this.getClockSystem=t,this.setHoursToClock=n,this.setMinutesToClock=r,this.updateAmPm=i,this.convertDisabledTime=a}setup(){this.emitter.on(`select:hour`,({hour:e})=>{this.emitter.emit(`animation:clock`,{}),this.setHoursToClock(e||null)}),this.emitter.on(`select:minute`,({minutes:e})=>{this.emitter.emit(`animation:clock`,{}),this.setMinutesToClock(e||null)}),this.emitter.on(`select:am`,()=>{this.updateAmPm()}),this.emitter.on(`select:pm`,()=>{this.updateAmPm()}),this.emitter.on(`animation:start`,()=>{this.getClockSystem()?.blockInteractions()}),this.emitter.on(`animation:end`,()=>{this.getClockSystem()?.unblockInteractions()}),this.emitter.on(`range:switch`,e=>{this.refreshDisabledTimeForRange(e.disabledTime)})}refreshDisabledTimeForRange(e){let t=this.getClockSystem();if(!t)return;let n=this.convertDisabledTime(),r=n;if(e){let t=[...n?.hours||[],...e.hours||[]],i=[...n?.minutes||[],...e.minutes||[]];r={...n,hours:t.length>0?t:void 0,minutes:i.length>0?i:void 0,rangeFromType:e.fromType,rangeFromHour:e.fromHour}}t.updateDisabledTime(r)}},pR=/^(1[0-2]|[1-9]):([0-5][0-9])\s*(AM|PM)$/i,mR=/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/,hR=class{static angleToIndex(e,t,n){let r=Math.round(e/30)%12;if(t===`24h`){if(n){let e=r+12;return e===12?0:e}return r===0?12:r}return r===0?12:r}static indexToValue(e,t){if(t===`24h`)return e.toString().padStart(2,`0`);let n=e;return n===0&&(n=12),n>12&&(n-=12),n.toString().padStart(2,`0`)}static indexToAngle(e,t){return t===`24h`?e>=12?(e-12)%12*30:e%12*30:(e===0?12:e)%12*30}static isDisabled(e,t,n){return n?n.isInterval&&n.intervals&&n.clockType?this.isDisabledByInterval(e,t,n):n.rangeFromType!==void 0&&n.rangeFromHour!==void 0?this.isDisabledForRange12h(e,t,n):n.hours?n.hours.some(t=>String(t)===e||Number(t)===Number(e)||t===e):!1:!1}static isDisabledForRange12h(e,t,n){let r=n.rangeFromType,i=n.rangeFromHour,a=parseInt(e,10);return r===null||i===void 0?!1:t===`AM`&&r===`PM`?!0:t===`AM`&&r===`AM`?i===12?!1:a===12||a<i:t===`PM`&&r===`AM`?!1:t===`PM`&&r===`PM`?i===12?!1:a===12||a<i:!1}static isDisabledByInterval(e,t,n){if(!n.intervals)return!1;for(let r=0;r<60;r++){let i=r.toString().padStart(2,`0`);if(!this.isTimeInIntervals(e,i,t,n.intervals,n.clockType))return!1}return!0}static isTimeInIntervals(e,t,n,r,i){let a=GI(i===`12h`?`${e}:${t} ${n}`:`${e}:${t}`,i);for(let e of r){let[t,n]=e.split(`-`).map(e=>e.trim()),r=GI(t,i),o=GI(n,i);if(a>=r&&a<=o)return!0}return!1}static findNearestValid(e,t,n,r){let i=t===`24h`?23:12;for(let a=0;a<=i;a++){let o=a===0?[e]:[e+a,e-a];for(let e of o){let a=e;a<0&&(a+=i+1),a>i&&(a%=i+1);let o=this.indexToValue(a,t);if(!this.isDisabled(o,n,r))return a}}return e}},gR=class{static angleToIndex(e){return Math.round(e/6)%60}static indexToValue(e){return e.toString().padStart(2,`0`)}static indexToAngle(e){return e%60*6}static isDisabled(e,t,n,r,i){return r?r.isInterval&&r.intervals?this.isDisabledByInterval(e,t,n,r,i):r.rangeFromType!==void 0&&r.rangeFromHour!==void 0?this.isDisabledForRange12h(e,t,n,r):r.rangeFromHour!==void 0&&parseInt(t,10)!==r.rangeFromHour?!1:r.minutes?r.minutes.some(t=>String(t)===e||Number(t)===Number(e)||t===e):!1:!1}static isDisabledForRange12h(e,t,n,r){let i=r.rangeFromType,a=r.rangeFromHour,o=parseInt(t,10),s=parseInt(e,10);if(i===null||a===void 0)return!1;let c=r.minutes||[],l=c.length>0?parseInt(c[c.length-1],10)+1:0;return n===`AM`&&i===`PM`?!0:n===`PM`&&i===`AM`?!1:o===a||o===12&&a===12||n===i&&o===a?s<l:!1}static isDisabledByInterval(e,t,n,r,i){if(!r.intervals)return!1;let a=GI(i===`12h`?`${t}:${e} ${n}`:`${t}:${e}`,i);for(let e of r.intervals){let[t,n]=e.split(`-`).map(e=>e.trim()),r=GI(t,i),o=GI(n,i);if(a>=r&&a<=o)return!0}return!1}static findNearestValid(e,t,n,r,i){for(let a=0;a<60;a++){let o=a===0?[e]:[e+a,e-a];for(let e of o){let a=e;a<0&&(a+=60),a>=60&&(a%=60);let o=this.indexToValue(a);if(!this.isDisabled(o,t,n,r,i))return a}}return e}},_R=class{static normalizeAngle(e){let t=e%360;return t<0&&(t+=360),t}static calculateRawAngle(e,t){let n=e.x-t.x,r=e.y-t.y,i=Math.atan2(r,n)*180/Math.PI+90;return this.normalizeAngle(i)}static snapToIncrement(e,t){let n=Math.round(e/t)*t;return this.normalizeAngle(n)}static calculateDistance(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}static isInnerCircle(e,t){return e<t*.75}static calculateShortestPath(e,t){let n=this.normalizeAngle(e),r=this.normalizeAngle(t)-n,i=r>=0?r:r+360,a=r<=0?r:r-360;return e+(Math.abs(i)<Math.abs(a)?i:a)}},vR=class{config;currentAngle=0;tipsCache=new Map;cachedDimensions=new Map;constructor(e){this.config=e}getCachedDimensions(e){let t=this.cachedDimensions.get(e);if(!t){let n=(e.offsetWidth-32)/2;t={width:n,height:(e.offsetHeight-32)/2,radius:n-9},this.cachedDimensions.set(e,t)}return t}setHandAngle(e){let t=_R.calculateShortestPath(this.currentAngle,e);Math.abs(this.currentAngle-t)<.01||(this.currentAngle=t,this.config.clockHand.style.transform=`rotateZ(${t}deg)`)}animateToAngle(e){let t=_R.calculateShortestPath(this.currentAngle,e);if(this.currentAngle=t,nR()){this.config.clockHand.style.transform=`rotateZ(${t}deg)`;return}this.config.tipsWrapper.classList.add(`tp-ui-tips-animation`),this.config.clockHand.style.transform=`rotateZ(${t}deg)`,setTimeout(()=>{this.config.tipsWrapper.classList.remove(`tp-ui-tips-animation`)},401)}setActiveValue(e){let t=[this.config.tipsWrapper];this.config.tipsWrapperFor24h&&t.push(this.config.tipsWrapperFor24h),t.forEach(t=>{t.querySelectorAll(`.tp-ui-value-tips, .tp-ui-value-tips-24h`).forEach(t=>{let n=t;n.textContent===e||Number(n.textContent)===Number(e)?n.classList.add(`active`):n.classList.remove(`active`)})})}renderTips(e,t,n,r,i,a=!0,o,s=``,c=`12`){if(cL()===!1)return;let l=o||this.config.tipsWrapper;a&&(l.innerHTML=``,this.tipsCache.clear());let{width:u,height:d,radius:f}=this.getCachedDimensions(l),p=document.createDocumentFragment(),m=`${t}-${this.config.theme||`default`}`;e.forEach((a,o)=>{let l=`${m}-${a}`,h=this.tipsCache.get(l);h||(h=this.createTip(a,t,i),this.tipsCache.set(l,h));let{wrapper:g,tip:_}=h;this.updateTipState(g,_,a,n,r,i,s,c);let v=o*(360/e.length)*(Math.PI/180);g.style.left=`${u+Math.sin(v)*f}px`,g.style.bottom=`${d+Math.cos(v)*f}px`,p.appendChild(g)}),l.appendChild(p)}createTip(e,t,n){if(cL()===!1){let e={};return{wrapper:e,tip:e}}let r=document.createElement(`span`),i=document.createElement(`span`);i.textContent=e,i.tabIndex=-1;let a=n===`24h`&&t.includes(`24`)?`tp-ui-value-tips-24h`:`tp-ui-value-tips`;return i.classList.add(a),r.classList.add(t),r.appendChild(i),{wrapper:r,tip:i}}updateTipState(e,t,n,r,i,a,o,s){e.classList.remove(`tp-ui-tips-disabled`),t.classList.remove(`tp-ui-tips-disabled`),t.tabIndex=-1,this.checkIfDisabled(n,r,i,a,o,s)&&(e.classList.add(`tp-ui-tips-disabled`),t.classList.add(`tp-ui-tips-disabled`))}checkIfDisabled(e,t,n,r,i,a){return n?t===`hours`?hR.isDisabled(e,i,n):t===`minutes`&&gR.isDisabled(e,a,i,n,r):!1}setCircleSize(e){e?this.config.circle.classList.remove(`small-circle`):this.config.circle.classList.add(`small-circle`)}setCircle24hMode(e){e?(this.config.circle.classList.add(`tp-ui-circle-hand-24h`),this.config.clockHand.classList.add(`tp-ui-clock-hand-24h`)):(this.config.circle.classList.remove(`tp-ui-circle-hand-24h`),this.config.clockHand.classList.remove(`tp-ui-clock-hand-24h`))}destroy(){this.tipsCache.clear(),this.cachedDimensions.clear(),this.config.tipsWrapper.innerHTML=``}},yR=class{static processPointerInput(e){let t=_R.calculateRawAngle(e.pointerPosition,e.clockCenter);return e.mode===`hours`?this.processHours(t,e):this.processMinutes(t,e)}static processHours(e,t){let n=t.smoothHourSnap??!0,r;if(n)r=e;else{let n=t.incrementHours*30;r=_R.snapToIncrement(e,n)}let i=_R.calculateDistance(t.pointerPosition,t.clockCenter),a=t.clockType===`24h`&&_R.isInnerCircle(i,t.clockRadius),o=hR.angleToIndex(r,t.clockType,a),s=hR.indexToValue(o,t.clockType),c=hR.isDisabled(s,t.amPm,t.disabledTime);c&&(o=hR.findNearestValid(o,t.clockType,t.amPm,t.disabledTime));let l=hR.indexToValue(o,t.clockType),u;return u=n?e:hR.indexToAngle(o,t.clockType),{angle:u,value:l,index:o,isValid:!c,isInnerCircle:t.clockType===`24h`?a:void 0}}static processMinutes(e,t){let n=t.incrementMinutes*6,r=_R.snapToIncrement(e,n),i=gR.angleToIndex(r),a=gR.indexToValue(i),o=t.currentHour||`00`,s=gR.isDisabled(a,o,t.amPm,t.disabledTime,t.clockType);s&&(i=gR.findNearestValid(i,o,t.amPm,t.disabledTime,t.clockType));let c=gR.indexToValue(i);return{angle:gR.indexToAngle(i),value:c,index:i,isValid:!s}}static valueToAngle(e,t,n){let r=parseInt(e,10);return t===`hours`?hR.indexToAngle(r,n):gR.indexToAngle(r)}},bR=class{state;renderer;clockType;disabledTime;incrementHours;incrementMinutes;smoothHourSnap;isDragging=!1;callbacks;lastProcessedX=null;lastProcessedY=null;constructor(e,t,n,r,i=1,a=1,o=!0,s={}){this.renderer=e,this.state={...t},this.clockType=n,this.disabledTime=r,this.incrementHours=i,this.incrementMinutes=a,this.smoothHourSnap=o,this.callbacks=s}handlePointerMove(e,t,n){if(this.isDragging=!0,this.lastProcessedX===e.x&&this.lastProcessedY===e.y)return;this.lastProcessedX=e.x,this.lastProcessedY=e.y;let r={pointerPosition:e,clockCenter:t,clockRadius:n,mode:this.state.mode,clockType:this.clockType,amPm:this.state.amPm,disabledTime:this.disabledTime,incrementHours:this.incrementHours,incrementMinutes:this.incrementMinutes,smoothHourSnap:this.smoothHourSnap,currentHour:this.state.hour},i=yR.processPointerInput(r);if(i.isValid){if(this.state.mode===`hours`){let e=this.state.hour;this.state.hour=i.value,this.state.hourAngle=i.angle,this.clockType===`24h`&&i.isInnerCircle!==void 0&&(this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(i.isInnerCircle)),this.callbacks.onHourChange&&e!==i.value&&this.callbacks.onHourChange(i.value)}else{let e=this.state.minute;this.state.minute=i.value,this.state.minuteAngle=i.angle,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1),this.callbacks.onMinuteChange&&e!==i.value&&this.callbacks.onMinuteChange(i.value)}this.renderer.setHandAngle(i.angle),this.renderer.setActiveValue(i.value)}}handlePointerUp(){this.isDragging=!1,this.lastProcessedX=null,this.lastProcessedY=null}snapToNearestHour(){if(this.state.mode!==`hours`)return;let e=yR.valueToAngle(this.state.hour,`hours`,this.clockType);this.state.hourAngle=e,this.renderer.animateToAngle(e)}switchMode(e){this.state.mode=e;let t=e===`hours`?this.state.hourAngle:this.state.minuteAngle,n=e===`hours`?this.state.hour:this.state.minute;if(e===`hours`&&this.clockType===`24h`){let e=parseInt(n,10),t=e===0||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(t)}else this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.renderer.setHandAngle(t),this.renderer.setActiveValue(n)}setValue(e,t){let n=yR.valueToAngle(t,e,this.clockType);if(e===`hours`){if(this.state.hour=t,this.state.hourAngle=n,this.clockType===`24h`){let e=parseInt(t,10),n=e===0||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(n)}else this.renderer.setCircle24hMode(!1)}else this.state.minute=t,this.state.minuteAngle=n,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.state.mode===e&&(this.renderer.setHandAngle(n),this.renderer.setActiveValue(t))}setAmPm(e){this.state.amPm=e}getState(){return{...this.state}}getHour(){return this.state.hour}getMinute(){return this.state.minute}getAmPm(){return this.state.amPm}updateDisabledTime(e){this.disabledTime=e}destroy(){this.renderer.destroy()}},xR=class{controller;clockFace;isActive=!1;isBlocked=!1;config;cachedRect=null;cachedCenter=null;cachedRadius=null;rafId=null;constructor(e,t,n={}){this.controller=e,this.clockFace=t,this.config=n}attach(){this.clockFace.addEventListener(`mousedown`,this.handlePointerDown),this.clockFace.addEventListener(`touchstart`,this.handlePointerDown,{passive:!1})}detach(){this.clockFace.removeEventListener(`mousedown`,this.handlePointerDown),this.clockFace.removeEventListener(`touchstart`,this.handlePointerDown),this.removeGlobalListeners()}block(){this.isBlocked=!0}unblock(){this.isBlocked=!1}handlePointerDown=e=>{if(sL()||this.isBlocked)return;let t=e.target;t&&t.classList&&t.classList.contains(`tp-ui-tips-disabled`)||(e.preventDefault(),this.isActive=!0,this.cachedRect=this.clockFace.getBoundingClientRect(),this.cachedCenter=this.getClockCenter(),this.cachedRadius=this.getClockRadius(),this.processPointerEvent(e),document.addEventListener(`mousemove`,this.handlePointerMove),document.addEventListener(`touchmove`,this.handlePointerMove,{passive:!1}),document.addEventListener(`mouseup`,this.handlePointerUp),document.addEventListener(`touchend`,this.handlePointerUp))};handlePointerMove=e=>{if(!this.isActive||this.isBlocked)return;let t=this.getTargetElement(e);t&&t.classList&&t.classList.contains(`tp-ui-tips-disabled`)||(e.preventDefault(),this.rafId===null&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.processPointerEvent(e)})))};handlePointerUp=()=>{if(!this.isActive)return;this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.isActive=!1,this.cachedRect=null,this.cachedCenter=null,this.cachedRadius=null,this.controller.handlePointerUp();let{autoSwitchToMinutes:e,isMobileView:t,smoothHourSnap:n,hourElement:r,minutesElement:i}=this.config;n&&r?.classList.contains(`active`)&&this.controller.snapToNearestHour(),this.removeGlobalListeners(),e&&r?.classList.contains(`active`)&&!t?(r.classList.remove(`active`),i?.classList.add(`active`),i?.click(),i?.focus(),r.blur()):i?.classList.contains(`active`)&&this.config.onMinuteCommit&&this.config.onMinuteCommit()};processPointerEvent(e){let t=this.getPointerPosition(e),n=this.cachedCenter||this.getClockCenter(),r=this.cachedRadius||this.getClockRadius();this.controller.handlePointerMove(t,n,r)}getPointerPosition(e){let t=this.cachedRect||this.clockFace.getBoundingClientRect();if(`touches`in e){let n=e.touches[0]||e.changedTouches[0];return{x:n.clientX-t.left,y:n.clientY-t.top}}return{x:e.clientX-t.left,y:e.clientY-t.top}}getTargetElement(e){if(`touches`in e){let t=e.touches[0]||e.changedTouches[0];if(t&&!sL())return document.elementFromPoint(t.clientX,t.clientY)}return e.target}getClockCenter(){let e=this.clockFace.offsetWidth,t=this.clockFace.offsetHeight;return{x:e/2,y:t/2}}getClockRadius(){return this.clockFace.offsetWidth/2}removeGlobalListeners(){cL()!==!1&&(document.removeEventListener(`mousemove`,this.handlePointerMove),document.removeEventListener(`touchmove`,this.handlePointerMove),document.removeEventListener(`mouseup`,this.handlePointerUp),document.removeEventListener(`touchend`,this.handlePointerUp))}},SR=class{renderer;controller;dragHandlers;clockType;disabledTime;tipsWrapper;tipsWrapperFor24h;constructor(e){this.clockType=e.clockType,this.disabledTime=e.disabledTime,this.tipsWrapper=e.tipsWrapper,this.tipsWrapperFor24h=e.tipsWrapperFor24h;let t={clockFace:e.clockFace,tipsWrapper:e.tipsWrapper,tipsWrapperFor24h:e.tipsWrapperFor24h,clockHand:e.clockHand,circle:e.circle,theme:e.theme};this.renderer=new vR(t);let n={hour:e.initialHour,minute:e.initialMinute,amPm:e.initialAmPm,hourAngle:this.calculateInitialAngle(`hours`,e.initialHour),minuteAngle:this.calculateInitialAngle(`minutes`,e.initialMinute),mode:`hours`},r={onHourChange:e.onHourChange,onMinuteChange:e.onMinuteChange};this.controller=new bR(this.renderer,n,e.clockType,e.disabledTime,e.incrementHours||1,e.incrementMinutes||1,e.smoothHourSnap??!0,r),this.dragHandlers=new xR(this.controller,e.clockFace,e.dragConfig||{})}initialize(){this.dragHandlers.attach(),this.switchToHours()}switchToHours(){this.controller.switchMode(`hours`),this.clockType===`24h`&&this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.remove(`none`),this.renderHourTips();let e=this.controller.getState();this.renderer.setActiveValue(e.hour)}switchToMinutes(){this.controller.switchMode(`minutes`),this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.add(`none`),this.renderMinuteTips();let e=this.controller.getState();this.renderer.setActiveValue(e.minute)}setHour(e){this.controller.setValue(`hours`,e)}setMinute(e){this.controller.setValue(`minutes`,e)}setAmPm(e){this.controller.setAmPm(e);let t=this.controller.getState();t.mode===`hours`?(this.renderHourTips(),this.renderer.setHandAngle(t.hourAngle),this.renderer.setActiveValue(t.hour)):(this.renderMinuteTips(),this.renderer.setHandAngle(t.minuteAngle),this.renderer.setActiveValue(t.minute))}getHour(){return this.controller.getHour()}getMinute(){return this.controller.getMinute()}getAmPm(){return this.controller.getAmPm()}updateDisabledTime(e){this.disabledTime=e,this.controller.updateDisabledTime(e),this.controller.getState().mode===`hours`?this.renderHourTips():this.renderMinuteTips()}renderHourTips(){let e=this.controller.getState().amPm;this.clockType===`24h`?(this.renderer.renderTips(TL,`tp-ui-hour-time-12`,`hours`,this.disabledTime,this.clockType,!0,this.tipsWrapper,e),this.tipsWrapperFor24h&&this.renderer.renderTips(wL,`tp-ui-hour-time-24`,`hours`,this.disabledTime,this.clockType,!0,this.tipsWrapperFor24h,e)):this.renderer.renderTips(TL,`tp-ui-hour-time-12`,`hours`,this.disabledTime,this.clockType,!0,void 0,e)}renderMinuteTips(){let e=this.controller.getState(),t=e.amPm,n=e.hour;this.renderer.renderTips(EL,`tp-ui-minutes-time`,`minutes`,this.disabledTime,this.clockType,!0,void 0,t,n)}calculateInitialAngle(e,t){let n=parseInt(t,10);return e===`hours`?n%12*30:n*6}destroy(){this.dragHandlers.detach(),this.controller.destroy()}blockInteractions(){this.dragHandlers.block()}unblockInteractions(){this.dragHandlers.unblock()}},CR=class{core;emitter;clockSystem=null;constructor(e,t){this.core=e,this.emitter=t}getClockSystem(){return this.clockSystem}initialize(){let e=this.core.getClockFace(),t=this.core.getClockHand(),n=this.core.getCircle();if(!e||!t||!n)return;let r=this.core.options.clock.type===`24h`,i=this.core.getTipsWrapper();if(!i)return;let a=this.core.getHour(),o=this.core.getMinutes(),s={clockFace:e,tipsWrapper:i,tipsWrapperFor24h:r&&this.core.getTipsWrapperFor24h()||void 0,clockHand:t,circle:n,clockType:this.core.options.clock.type||`12h`,disabledTime:this.convertDisabledTime(),initialHour:a?.value||`12`,initialMinute:o?.value||`00`,initialAmPm:this.getAmPmValue(),theme:this.core.options.ui.theme,incrementHours:this.core.options.clock.incrementHours||1,incrementMinutes:this.core.options.clock.incrementMinutes||1,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,timepicker:null,dragConfig:{autoSwitchToMinutes:this.core.options.clock.autoSwitchToMinutes,isMobileView:this.core.isMobileView,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,hourElement:a,minutesElement:o,onMinuteCommit:()=>{let e=this.core.getMinutes(),t=this.core.getHour(),n=this.core.getActiveTypeMode();this.emitter.emit(`range:minute:commit`,{hour:t?.value??`12`,minutes:e?.value??`00`,type:n?.textContent??void 0})}},onHourChange:e=>{let t=this.core.getHour();t&&(t.value=e,t.setAttribute(`aria-valuenow`,e)),QL(this.core.getModalElement(),`Hour: ${e}`);let n=this.core.getMinutes(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e,minutes:n?.value,type:r?.textContent||void 0})},onMinuteChange:e=>{let t=this.core.getMinutes();t&&(t.value=e,t.setAttribute(`aria-valuenow`,e)),QL(this.core.getModalElement(),`Minutes: ${e}`);let n=this.core.getHour(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:n?.value,minutes:e,type:r?.textContent||void 0})}};this.clockSystem=new SR(s),this.clockSystem.initialize()}convertDisabledTime(){let e=this.core.disabledTime?.value;if(!e)return null;let t;return e.intervals&&(t=Array.isArray(e.intervals)?e.intervals:[e.intervals]),{hours:e.hours,minutes:e.minutes,isInterval:e.isInterval,intervals:t,clockType:e.clockType}}getAmPmValue(){if(this.core.options.clock.type===`24h`)return``;let e=this.core.getActiveTypeMode();if(e){let t=e.textContent?.trim();if(t===`AM`||t===`PM`)return t}let t=this.core.getAM();return this.core.options.range?.enabled===!0?t?.classList.contains(`active`)?`AM`:``:t?.classList.contains(`active`)?`AM`:`PM`}destroy(){this.clockSystem&&=(this.clockSystem.destroy(),null)}},wR=class{core;constructor(e){this.core=e}removeCircleClockClasses24h(){let e=this.core.getCircle(),t=this.core.getClockHand();e?.classList.remove(`tp-ui-circle-hand-24h`),t?.classList.remove(`tp-ui-clock-hand-24h`)}setCircleClockClasses24h(){let e=this.core.getCircle(),t=this.core.getClockHand();e&&e.classList.add(`tp-ui-circle-hand-24h`),t&&t.classList.add(`tp-ui-clock-hand-24h`)}setOnStartCSSClassesIfClockType24h(){if(this.core.options.clock.type===`24h`){let e=this.core.getInput();if(!e)return;let t;e.value.length>0&&(t=e.value.split(`:`)[0]),t&&(Number(t)>12||Number(t)===0)&&this.setCircleClockClasses24h()}}setBgColorToCircleWithMinutesTips(){let e=this.core.getMinutes(),t=this.core.getCircle();if(!(!e||!t)&&e.value&&EL.includes(e.value)){let e=getComputedStyle(t).getPropertyValue(`--timepicker-primary`).trim();e&&(t.style.backgroundColor=e),t.classList.remove(`small-circle`)}}removeBgColorToCirleWithMinutesTips(){let e=this.core.getMinutes(),t=this.core.getCircle();!e||!t||e.value&&EL.includes(e.value)||(t.style.backgroundColor=``,t.classList.add(`small-circle`))}setClassActiveToHourOnOpen(){this.core.options.ui.mobile||this.core.isMobileView||this.core.getHour()?.classList.add(HL)}toggleClassActiveToValueTips(e,t){if(e)return;let n=this.core.getAllValueTips();if(!n)return;let r=n.find(e=>Number(e.innerText)===Number(t));n.forEach(e=>{e.classList.remove(HL),e.setAttribute(`aria-selected`,`false`)}),r!==void 0&&(r.classList.add(HL),r.setAttribute(`aria-selected`,`true`))}},TR=class{getClockSystem;styleHandler;getAmPmValue;clockType;constructor(e,t,n,r){this.getClockSystem=e,this.styleHandler=t,this.getAmPmValue=n,this.clockType=r}setMinutesToClock(e){let t=this.getClockSystem();t&&(this.styleHandler.removeBgColorToCirleWithMinutesTips(),e&&t.setMinute(e),t.switchToMinutes())}setHoursToClock(e){let t=this.getClockSystem();t&&(e&&t.setHour(e),t.switchToHours())}setTransformToCircleWithSwitchesHour(e){let t=this.getClockSystem();!t||!e||t.setHour(e)}setTransformToCircleWithSwitchesMinutes(e){let t=this.getClockSystem();!t||!e||t.setMinute(e)}updateAmPm(){let e=this.getClockSystem();if(!e||this.clockType===`24h`)return;let t=this.getAmPmValue();t!==``&&e.setAmPm(t)}},ER=class{systemInitializer;styleHandler;timeHandler;eventHandler;constructor(e,t){this.systemInitializer=new CR(e,t),this.styleHandler=new wR(e);let n=e.options.clock.type||`12h`;this.timeHandler=new TR(()=>this.systemInitializer.getClockSystem(),this.styleHandler,()=>this.systemInitializer.getAmPmValue(),n),this.eventHandler=new fR(t,()=>this.systemInitializer.getClockSystem(),e=>this.timeHandler.setHoursToClock(e),e=>this.timeHandler.setMinutesToClock(e),()=>this.timeHandler.updateAmPm(),()=>this.systemInitializer.convertDisabledTime()),this.eventHandler.setup()}initializeClockSystem(){this.systemInitializer.initialize()}destroyClockSystem(){this.systemInitializer.destroy()}removeCircleClockClasses24h(){this.styleHandler.removeCircleClockClasses24h()}setCircleClockClasses24h(){this.styleHandler.setCircleClockClasses24h()}setOnStartCSSClassesIfClockType24h(){this.styleHandler.setOnStartCSSClassesIfClockType24h()}setBgColorToCircleWithMinutesTips=()=>{this.styleHandler.setBgColorToCircleWithMinutesTips()};removeBgColorToCirleWithMinutesTips=()=>{this.styleHandler.removeBgColorToCirleWithMinutesTips()};setClassActiveToHourOnOpen=()=>{this.styleHandler.setClassActiveToHourOnOpen()};setMinutesToClock=e=>{this.timeHandler.setMinutesToClock(e)};setHoursToClock=e=>{this.timeHandler.setHoursToClock(e)};setTransformToCircleWithSwitchesHour=e=>{this.timeHandler.setTransformToCircleWithSwitchesHour(e)};setTransformToCircleWithSwitchesMinutes=e=>{this.timeHandler.setTransformToCircleWithSwitchesMinutes(e)};updateAmPm=()=>{this.timeHandler.updateAmPm()};toggleClassActiveToValueTips=e=>{let t=this.systemInitializer.getClockSystem()!==null;this.styleHandler.toggleClassActiveToValueTips(t,e)};destroy(){this.destroyClockSystem()}},DR=class{core;emitter;cleanupHandlers=[];wasCleared=!1;constructor(e,t){this.core=e,this.emitter=t}init(){if(!this.core.options.ui.clearButton)return;let e=this.getClearButton();e&&(this.cleanupHandlers.push(tR(e,()=>{this.core.isDestroyed||this.handleClearClick()})),this.setupInternalEventListeners())}setupInternalEventListeners(){KI(this.emitter,this.cleanupHandlers,`update`,()=>{this.updateClearButtonState()}),KI(this.emitter,this.cleanupHandlers,`open`,()=>{this.updateClearButtonState()}),KI(this.emitter,this.cleanupHandlers,`select:hour`,()=>{this.updateClearButtonState(),this.reenableConfirmIfCleared()}),KI(this.emitter,this.cleanupHandlers,`select:minute`,()=>{this.updateClearButtonState(),this.reenableConfirmIfCleared()})}handleClearClick(){let e=this.core.getInput()?.value||null;this.clearTimeValue(),this.resetClockToNeutral(),this.disableConfirmButton(),this.wasCleared=!0,QL(this.core.getModalElement(),`Time cleared`),this.emitter.emit(`clear`,{previousValue:e}),this.emitter.emit(`update`,{hour:void 0,minutes:void 0,type:void 0});let{callbacks:t}=this.core.options;t.onClear&&t.onClear({previousValue:e})}clearTimeValue(){let e=this.core.options.clearBehavior?.clearInput!==!1,t=this.core.getInput();t&&e&&(t.value=``),this.core.setDegreesHours(null),this.core.setDegreesMinutes(null);let n=CL.getClearHandler(`range`);n&&n(this.core,this.emitter);let r=CL.getClearHandler(`timezone`);r&&r(this.core,this.emitter)}resetClockToNeutral(){let e=this.core.options.clock.type,t=e===`12h`?`PM`:void 0,n=this.core.getHour(),r=this.core.getMinutes();n&&(n.value=`12`,n.removeAttribute(`aria-valuenow`)),r&&(r.value=`00`,r.removeAttribute(`aria-valuenow`));let i=this.core.getClockHand();if(i){let e=i.style.transition;i.style.transition=`none`,i.style.transform=`rotateZ(0deg)`,i.offsetHeight,requestAnimationFrame(()=>{i.style.transition=e})}if(this.removeActiveStates(),n&&n.click(),e===`12h`&&t){let e=this.core.getAM(),t=this.core.getPM();e?.classList.remove(`active`),t?.classList.remove(`active`),e?.setAttribute(`aria-pressed`,`false`),t?.setAttribute(`aria-pressed`,`false`),t?.classList.add(`active`),t?.setAttribute(`aria-pressed`,`true`)}this.emitter.emit(`animation:clock`,{})}removeActiveStates(){this.core.getAllValueTips().forEach(e=>{e.classList.remove(`active`),e.removeAttribute(`aria-selected`)});let e=this.core.getHour(),t=this.core.getMinutes();e?.removeAttribute(`aria-valuenow`),t?.removeAttribute(`aria-valuenow`)}disableConfirmButton(){let e=this.core.getOkButton();e&&(e.classList.add(`disabled`),e.setAttribute(`aria-disabled`,`true`))}updateClearButtonState(){let e=this.getClearButton();if(!e)return;let t=this.core.getInput(),n=t?.value&&t.value.trim()!==``,r=this.core.getHour(),i=this.core.getMinutes(),a=this.core.getActiveTypeMode(),o=this.core.options.clock.type,s=r?.value||``,c=i?.value||``,l=a?.textContent||``,u=n||!(o===`12h`?s===`12`&&c===`00`&&l===`PM`:s===`12`&&c===`00`);e.classList.toggle(`disabled`,!u),e.setAttribute(`aria-disabled`,String(!u))}reenableConfirmIfCleared(){if(!this.wasCleared)return;let e=this.core.getOkButton();e&&(e.classList.remove(`disabled`),e.setAttribute(`aria-disabled`,`false`),this.wasCleared=!1)}getClearButton(){return this.core.getModalElement()?.querySelector(`.tp-ui-clear-btn`)||null}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},OR=class{animation;modal;config;theme;validation;events;clock;clearButton;plugins=new Map;constructor(e,t){this.animation=new dL(e,t),this.modal=new LL(e,t),this.config=new JL(e,t),this.theme=new YL(e,t),this.validation=new rR(e,t),this.events=new dR(e,t),this.clock=new ER(e,t),this.clearButton=new DR(e,t),CL.getAll().forEach(n=>{let r=n.factory(e,t);this.plugins.set(n.name,r)})}getPlugin(e){return this.plugins.get(e)}destroy(){this.animation.destroy(),this.modal.destroy(),this.config.destroy(),this.theme.destroy(),this.validation.destroy(),this.events.destroy(),this.clock.destroy(),this.clearButton.destroy(),this.plugins.forEach(e=>e.destroy()),this.plugins.clear()}},kR=`is-rippling`,AR=`ripple-hold`,jR=null,MR=(e,t)=>{let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>{e(...r)},t)}},NR=[[`onOpen`,`open`],[`onCancel`,`cancel`],[`onConfirm`,`confirm`],[`onUpdate`,`update`],[`onSelectHour`,`select:hour`],[`onSelectMinute`,`select:minute`],[`onSelectAM`,`select:am`],[`onSelectPM`,`select:pm`],[`onError`,`error`],[`onTimezoneChange`,`timezone:change`],[`onRangeConfirm`,`range:confirm`],[`onRangeSwitch`,`range:switch`],[`onRangeValidation`,`range:validation`],[`onClear`,`clear`]],PR=[{needed:e=>e.ui.mode===`wheel`||e.ui.mode===`compact-wheel`,name:`wheel`,message:`WheelPlugin is not registered. Import and register it: PluginRegistry.register(WheelPlugin)`},{needed:e=>!!e.range?.enabled,name:`range`,message:`RangePlugin is not registered. Import and register it: PluginRegistry.register(RangePlugin)`},{needed:e=>!!e.timezone?.enabled,name:`timezone`,message:`TimezonePlugin is not registered. Import and register it: PluginRegistry.register(TimezonePlugin)`}],FR=class e{static EXPANDED_EXCLUDED=[`tp-ui-select-time`,`tp-ui-mobile-clock-wrapper`,`tp-ui-wrapper`];core;managers;emitter;eventsClickMobileHandler=()=>{};mutliEventsMoveHandler=()=>{};unmountTimeouts=[];constructor(e,t,n){this.core=e,this.managers=t,this.emitter=n}init(){if(!this.core.isDestroyed&&!this.core.isInitialized){try{this.managers.config.updateInputValueWithCurrentTimeOnStart(),this.managers.validation.checkDisabledValuesOnStart()}catch{this.core.setIsDestroyed(!0);return}this.managers.theme.setTimepickerClassToElement(),this.managers.theme.setInputClassToInputElement(),this.managers.theme.setDataOpenToInputIfDoesntExistInWrapper(),this.managers.theme.setClassTopOpenElement(),this.managers.config.getDisableTime(),this.core.options.ui.inline?.enabled||this.managers.events.handleOpenOnClick(),this.managers.events.handleOpenOnEnterFocus(),eL(this.core,this.emitter),this.core.setIsInitialized(!0)}}mount(){this.core.isDestroyed||this.core.isOpen||(this.core.isInitialized||this.init(),this.eventsBundle())}unmount(e){let t=MR((...e)=>{if(e.length>2)return;let[t]=e.filter(e=>typeof e==`boolean`),[n]=e.filter(e=>typeof e==`function`);this.core.setIsMobileView(!!this.core.options.ui.mobile);let r=this.core.getModalElement();t&&r&&this.core.getOkButton()?.click(),this.core.setIsTouchMouseMove(!1),this.core.setIsOpen(!1),this.removeEventListeners(),$I(this.core.options)&&this.managers.getPlugin(`wheel`)?.detachPopover?.(),r&&this.managers.animation.removeAnimationToClose(),this.core.getOpenElement().forEach(e=>e?.classList.remove(`disabled`));let i=setTimeout(()=>{this.managers.modal.unlockScroll()},uL.SCROLLBAR_RESTORE);this.unmountTimeouts.push(i);let a=setTimeout(()=>{let e=this.core.getInput();this.core.options.behavior.focusInputAfterClose&&e?.focus();let t=this.core.getModalElement();t&&t.remove(),this.core.setIsModalRemove(!0)},uL.MODAL_REMOVE);this.unmountTimeouts.push(a),n&&n()},this.core.options.behavior.delayHandler||uL.DEFAULT_DELAY);e?t(e):t()}destroy(e){if(this.core.isDestroyed)return;this.clearUnmountTimeouts();let{keepInputValue:t=!1,callback:n}=typeof e==`function`?{callback:e}:e||{},r=this.core.getInput(),i=t?r?.value:null;this.removeEventListeners(),this.core.getModalElement()?.remove(),this.core.getOpenElement()?.forEach(e=>{e&&e.classList.remove(`disabled`,`active`,`tp-ui-open-element`)}),r&&(r.classList.remove(`tp-ui-invalid-format`,`invalid-value`,`error`,`active`,`tp-ui-input`),r.removeAttribute(`data-open`),r.removeAttribute(`data-owner-id`),t&&i&&(r.value=i));let a=this.core.element;a&&(a.classList.remove(`error`,`active`,`disabled`),a.removeAttribute(`data-owner-id`),a.removeAttribute(`data-open`),this.core.options.ui.cssClass&&a.classList.remove(this.core.options.ui.cssClass)),a?.querySelectorAll(`.tp-ui-invalid-text`)?.forEach(e=>e.remove()),this.mutliEventsMoveHandler=()=>{},this.eventsClickMobileHandler=()=>{},this.core.reset(),this.managers.destroy(),this.emitter.clear(),this.managers.modal.unlockScroll(),n&&n()}eventsBundle(){if(this.core.isDestroyed||!this.core.isModalRemove)return;this.clearUnmountTimeouts(),this.core.setIsOpen(!0),this.core.setIsModalRemove(!1),this.setupValidation(),this.disableOpenElements(),this.setupModal(),this.applyExpandedState(),this.managers.modal.setFlexEndToFooterIfNoKeyboardIcon(),this.applyThemeDeferred(),this.managers.animation.setAnimationToOpen(),this.managers.config.getInputValueOnOpenAndSet();let e=ZI(this.core.options)&&CL.has(`wheel`);tL(this.core,this.emitter),this.initClockOrWheel(e),this.initOptionalPlugins(e),this.bindEventHandlers(e),this.finalizeModal(e),$I(this.core.options)&&this.managers.getPlugin(`wheel`)?.attachPopover?.(),this.managers.modal.setShowClassToBackdrop()}setupValidation(){this.managers.validation.setErrorHandler(),this.managers.validation.removeErrorHandler()}disableOpenElements(){this.core.options.ui.inline?.enabled||(this.core.getOpenElement().forEach(e=>e?.classList.add(`disabled`)),$I(this.core.options)||this.core.getInput()?.blur())}setupModal(){this.managers.modal.setScrollbarOrNot(),this.managers.modal.setModalTemplate(),this.managers.modal.setNormalizeClass(),this.managers.modal.removeBackdrop()}applyExpandedState(){if(this.core.isMobileView){this.managers.config.updateClockFaceAccessibility(!0);return}let t=this.core.getModalElement();t&&(t.querySelector(`.tp-ui-mobile-clock-wrapper`)?.classList.add(`expanded`),t.querySelector(`.tp-ui-wrapper`)?.classList.add(`expanded`),t.querySelectorAll(`*`).forEach(t=>{e.EXPANDED_EXCLUDED.some(e=>t.classList.contains(e))||t.classList.add(`expanded`)}))}applyThemeDeferred(){let e=setTimeout(()=>{this.managers.theme.setTheme();let e=this.core.getWrapper();e&&this.core.options.ui.cssClass&&e.classList.add(this.core.options.ui.cssClass)},0);this.unmountTimeouts.push(e)}initClockOrWheel(e){if(e){let e=this.managers.getPlugin(`wheel`);e&&e.init()}else this.managers.clock.initializeClockSystem(),this.managers.clock.setOnStartCSSClassesIfClockType24h(),this.managers.clock.setClassActiveToHourOnOpen()}initOptionalPlugins(e){let t=this.managers.getPlugin(`timezone`);t&&t.init();let n=this.managers.getPlugin(`range`);n&&!e&&n.init()}bindEventHandlers(e){this.managers.events.handleCancelButton(),this.managers.events.handleOkButton(),this.managers.clearButton.init(),e||(this.managers.events.handleHourEvents(),this.managers.events.handleMinutesEvents()),this.managers.events.handleKeyboardInput(),this.core.options.ui.enableSwitchIcon&&!e&&this.managers.events.handleSwitchViewButton(),this.core.options.clock.type!==`24h`&&!QI(this.core.options)&&(this.managers.events.handleAmClick(),this.managers.events.handlePmClick()),this.core.options.behavior.focusTrap&&this.managers.events.focusTrapHandler(),this.core.options.ui.inline?.enabled||(this.managers.events.handleEscClick(),$I(this.core.options)||e&&this.core.options.wheel?.ignoreOutsideClick||this.managers.events.handleBackdropClick())}finalizeModal(e){let t=this.core.getModalElement();if(t&&XI(t),!e){let e=this.core.getClockFace();e&&typeof requestAnimationFrame<`u`&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e?.classList.add(`scale-in`)})})}}clearUnmountTimeouts(){this.unmountTimeouts.forEach(clearTimeout),this.unmountTimeouts=[]}removeEventListeners(){cL()!==!1&&(VL.split(` `).forEach(e=>{document.removeEventListener(e,this.mutliEventsMoveHandler,!1)}),document.removeEventListener(`mousedown`,this.eventsClickMobileHandler))}},IR=class{events=new Map;on(e,t){this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t)}once(e,t){let n=r=>{t(r),this.events.get(e)?.delete(n)};n.__originalHandler=t,this.on(e,n)}off(e,t){if(!t){this.events.delete(e);return}let n=this.events.get(e);n&&n.forEach(e=>{(e===t||e.__originalHandler===t)&&n.delete(e)})}emit(e,t){let n=this.events.get(e);n&&[...n].forEach(e=>{e(t)})}clear(){this.events.clear()}hasListeners(e){return(this.events.get(e)?.size??0)>0}},LR={clock:{type:`12h`,incrementHours:1,incrementMinutes:1,autoSwitchToMinutes:!0,disabledTime:void 0,currentTime:void 0},ui:{mode:`clock`,theme:`basic`,animation:!0,backdrop:!0,mobile:!1,enableSwitchIcon:!1,editable:!1,enableScrollbar:!1,cssClass:void 0,appendModalSelector:``,iconTemplate:``,iconTemplateMobile:``,inline:void 0,clearButton:!1},labels:{am:`AM`,pm:`PM`,ok:`OK`,cancel:`Cancel`,time:`Select time`,mobileTime:`Enter Time`,mobileHour:`Hour`,mobileMinute:`Minute`,clear:`Clear`,hourLabel:`Hour`,minuteLabel:`Minute`,clockLabel:`Clock`,periodLabel:`Period`,timeLabel:`Time`,format24Label:`24-hour`,rangeSelectionLabel:`Range selection`,switchToKeyboardLabel:`Switch to keyboard input`,switchToClockLabel:`Switch to clock`,toggleLabel:`Toggle`,timezoneSelectorLabel:`Timezone`,announceHour:`Hour`,announceMinute:`Minutes`,announceAmSelected:`AM selected`,announcePmSelected:`PM selected`,invalidTimeFormat:`Invalid time format`},behavior:{focusInputAfterClose:!1,focusTrap:!0,delayHandler:300,id:void 0},callbacks:{onOpen:void 0,onCancel:void 0,onConfirm:void 0,onUpdate:void 0,onSelectHour:void 0,onSelectMinute:void 0,onSelectAM:void 0,onSelectPM:void 0,onError:void 0,onTimezoneChange:void 0,onRangeConfirm:void 0,onRangeSwitch:void 0,onRangeValidation:void 0,onClear:void 0},timezone:{enabled:!1,default:void 0,whitelist:void 0,label:`Timezone`},range:{enabled:!1,minDuration:void 0,maxDuration:void 0,fromLabel:`From`,toLabel:`To`},wheel:{placement:void 0,hideFooter:void 0,commitOnScroll:void 0,hideDisabled:void 0,ignoreOutsideClick:void 0},clearBehavior:{clearInput:!0}},RR=e=>e.replace(/[^0-9:APMapm\s]/g,``),zR=new Map,BR=class{core;managers;lifecycle;emitter;constructor(e,t){if(sL())throw Error(`TimepickerUI requires browser environment`);let n=this.resolveInputElement(e);if(!n)throw Error(`Input element not found`);let r=t?.behavior?.id,i=r||`tp-ui-${yL()}`,a=this.createWrapperElement(n),o=nL(t||{});if(o.ui.inline?.enabled&&typeof t?.behavior?.focusTrap>`u`&&(o.behavior.focusTrap=!1),o.ui.inline?.enabled){if(!o.ui.inline.containerId)throw Error(`inline.containerId is required when inline mode is enabled`);if(!sL()&&!document.getElementById(o.ui.inline.containerId))throw Error(`Container element with id "${o.ui.inline.containerId}" not found`)}this.emitter=new IR,this.core=new lL(a,o,i,r);let s=this.core.getInput();if(s){let e=RL(s,o.clock.type),t=Number(e.hour)*30,n=Number(e.minutes)*6;this.core.setDegreesHours(t),this.core.setDegreesMinutes(n)}this.managers=new OR(this.core,this.emitter),this.lifecycle=new FR(this.core,this.managers,this.emitter),this.managers.config.checkMobileOption(),this.managers.config.preventClockTypeByCurrentTime(),this.setupInternalEventListeners(),zR.set(this.core.instanceId,this)}setupInternalEventListeners(){this.emitter.on(`show`,()=>{this.core.isDestroyed||this.lifecycle.mount()}),this.emitter.on(`cancel`,()=>{this.core.isDestroyed||this.lifecycle.unmount()}),this.emitter.on(`confirm`,e=>{if(!this.core.isDestroyed){if(this.core.options.range?.enabled)return;let t=this.core.getInput();if(t&&e.hour&&e.minutes){let n=e.type?` ${e.type}`:``;t.value=`${e.hour}:${e.minutes}${n}`}e.autoCommit||this.lifecycle.unmount()}}),this.emitter.on(`range:confirm`,e=>{if(this.core.isDestroyed)return;let t=this.core.getInput();t&&(t.value=`${e.from} - ${e.to}`),this.lifecycle.unmount()})}create(){this.lifecycle.init(),this.core.options.ui.inline?.enabled&&this.lifecycle.mount()}open(e){this.lifecycle.mount(),e&&e()}close(e,t){this.lifecycle.unmount(e?t:void 0),!e&&t&&t()}destroy(e){zR.delete(this.core.instanceId),this.lifecycle.destroy(e)}update(e,t){this.core.isDestroyed||(this.core.updateOptions(e.options),this.managers.config.checkMobileOption(),this.managers.config.getDisableTime(),e.create&&this.create(),t&&t())}getValue(){if(this.core.isDestroyed)return{hour:``,minutes:``,type:void 0,time:``,degreesHours:null,degreesMinutes:null};let e=this.core.getModalElement(),t=this.core.getInput(),n=`12`,r=`00`,i=this.core.options.clock.type===`24h`?void 0:`AM`,a=null,o=null;if(e){let e=this.core.getHour(),t=this.core.getMinutes(),s=this.core.getActiveTypeMode();n=e?.value||`12`,r=t?.value||`00`,i=this.core.options.clock.type===`24h`?void 0:s?.textContent||`AM`,a=this.core.degreesHours,o=this.core.degreesMinutes}else if(t){let e=RL(t,this.core.options.clock.type);n=e.hour,r=e.minutes,i=e.type,a=Number(n)*30,o=Number(r)*6}let s=``;return s=this.core.options.clock.type===`24h`?`${n.padStart(2,`0`)}:${r.padStart(2,`0`)}`:`${n}:${r.padStart(2,`0`)} ${i}`,{hour:n,minutes:r,type:i,time:s,degreesHours:a,degreesMinutes:o}}setValue(e,t=!0){if(this.core.isDestroyed||!e||typeof e!=`string`)return;this.core.isInitialized||this.create();let n=RR(e.trim());try{let e=rL(this.core,n);if(iL(this.core,e),aL(this.core,e.typeValue),t){let e=this.core.getInput();e&&(e.value=n)}oL(this.core,this.managers,e)}catch{return}}getElement(){return this.core.element}get instanceId(){return this.core.instanceId}get options(){return this.core.options}get isInitialized(){return this.core.isInitialized}get isDestroyed(){return this.core.isDestroyed}get hour(){return this.core.getHour()}get minutes(){return this.core.getMinutes()}get okButton(){return this.core.getOkButton()}get cancelButton(){return this.core.getCancelButton()}get clockHand(){return this.core.getClockHand()}on(e,t){this.core.isDestroyed||this.emitter.on(e,t)}once(e,t){this.core.isDestroyed||this.emitter.once(e,t)}off(e,t){this.core.isDestroyed||this.emitter.off(e,t)}resolveInputElement(e){if(cL()===!1)return null;let t=null;if(typeof e==`string`){if(t=document.querySelector(e),!t)return null}else if(e instanceof HTMLElement)t=e;else return null;return t.tagName===`INPUT`?t:t.querySelector(`input`)}createWrapperElement(e){if(cL()===!1)return e;let t=e.parentElement;if(e.tagName===`INPUT`&&!t?.classList.contains(`tp-ui`)){let t=document.createElement(`div`);return t.className=`tp-ui`,e.parentNode?.insertBefore(t,e),t.appendChild(e),t}return t&&!t.classList.contains(`tp-ui`)&&t.classList.add(`tp-ui`),t||e}static getById(e){return zR.get(e)}static getAllInstances(){return Array.from(zR.values())}static isAvailable(e){return sL()?!1:typeof e==`string`?document.querySelector(e)!==null:e instanceof HTMLElement&&document.contains(e)}static destroyAll(){Array.from(zR.values()).forEach(e=>e.destroy()),zR.clear()}},VR=BR,HR=VR})),WR=_({RangeManager:()=>az,RangePlugin:()=>oz});function GR(e){let t=e.match(tz);return t?{hour:t[1],minutes:t[2],type:t[3].toUpperCase()}:null}function KR(e){let t=e.match(nz);return t?{hour:t[1],minutes:t[2]}:null}function qR(e,t){let n=parseInt(e.hour,10),r=parseInt(e.minutes,10);if(Number.isNaN(n)||Number.isNaN(r))return 0;if(t===`12h`&&e.type){let t=e.type.toUpperCase();t===`PM`&&n!==12&&(n+=12),t===`AM`&&n===12&&(n=0)}return n*60+r}function JR(e){if(!e||e===`--:--`)return null;let t=GR(e);if(t)return{hour:t.hour,minutes:t.minutes,type:t.type};let n=e.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/i);if(n)return{hour:n[1],minutes:n[2],type:n[3].toUpperCase()};let r=KR(e);if(r)return{hour:r.hour,minutes:r.minutes};let i=e.match(/^(\d{1,2}):(\d{2})$/);return i?{hour:i[1],minutes:i[2]}:null}function YR(e){let t=e.minutes===`--`?`--`:e.minutes.padStart(2,`0`),n=`${e.hour}:${t}`;return e.type?`${n} ${e.type}`:n}function XR(e,t){return e?qR(e,t):0}function ZR(e,t,n){if(!e||!t)return 0;let r=XR(e,n);return XR(t,n)-r}function QR(e,t){return e?t===`12h`?!!(e.hour&&e.minutes&&e.type):!!(e.hour&&e.minutes):!1}function $R(e){if(!e||!e.includes(` - `))return{from:null,to:null};let t=e.split(` - `).map(e=>e.trim());return t.length!==2||t[0]===`--:--`||t[1]===`--:--`?{from:null,to:null}:{from:JR(t[0]),to:JR(t[1])}}function ez(e,t,n,r){e.on(n,r),t.push(()=>e.off(n,r))}var tz,nz,rz,iz,az,oz,sz=h((()=>{tz=/^(1[0-2]|[1-9]):([0-5][0-9])\s*(AM|PM)$/i,nz=/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/,rz=class{activePart=`from`;fromValue=null;toValue=null;previewValue=null;clockType;minDuration;maxDuration;emitter;constructor(e,t,n,r){this.clockType=e,this.minDuration=t,this.maxDuration=n,this.emitter=r}getActivePart(){return this.activePart}getFromValue(){return this.fromValue}getToValue(){return this.toValue}getPreviewValue(){return this.previewValue}setFromValue(e){this.fromValue=e}setToValue(e){this.toValue=e}setPreviewValue(e){this.previewValue=e}isFromComplete(){return QR(this.fromValue,this.clockType)}isToComplete(){return QR(this.toValue,this.clockType)}canSwitchToEnd(){return this.isFromComplete()}canConfirm(){return!this.isFromComplete()||!this.isToComplete()?!1:this.getDuration()>0}setActivePart(e){if(e===`to`&&!this.canSwitchToEnd())return!1;let t=this.activePart!==e;return this.activePart=e,t&&(this.previewValue=null),t}resetActivePart(){this.activePart=`from`,this.previewValue=null}getCurrentValue(){return this.previewValue?this.previewValue:this.activePart===`from`?this.fromValue:this.toValue}getSavedValue(){return this.activePart===`from`?this.fromValue:this.toValue}commitPreview(){this.previewValue&&=(this.activePart===`from`?this.fromValue=this.previewValue:this.toValue=this.previewValue,null)}getDuration(){return ZR(this.fromValue,this.toValue,this.clockType)}validate(){if(!this.fromValue||!this.toValue)return{valid:!0,duration:0};let e=this.getDuration(),t=!0;return this.minDuration!==void 0&&e<this.minDuration&&(t=!1),this.maxDuration!==void 0&&e>this.maxDuration&&(t=!1),this.emitter.emit(`range:validation`,{valid:t,duration:e,minDuration:this.minDuration,maxDuration:this.maxDuration}),{valid:t,duration:e}}getDisabledTimeForEndPart(){if(this.activePart===`from`||!this.fromValue||!this.isFromComplete())return null;let e=[],t=[],n=parseInt(this.fromValue.hour,10),r=parseInt(this.fromValue.minutes,10),i=this.fromValue.type;if(this.clockType===`24h`){for(let t=0;t<n;t++)e.push(t.toString().padStart(2,`0`));for(let e=0;e<r;e++)t.push(e.toString().padStart(2,`0`));return{hours:e,minutes:t,fromHour:n}}for(let e=0;e<r;e++)t.push(e.toString().padStart(2,`0`));return{hours:e,minutes:t,fromType:i,fromHour:n}}reset(){this.activePart=`from`,this.fromValue=null,this.toValue=null,this.previewValue=null}},iz=class{core;state;constructor(e,t){this.core=e,this.state=t}updateTabs(){let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-range-tab.tp-ui-range-from`),n=e.querySelector(`.tp-ui-range-tab.tp-ui-range-to`),r=this.state.getActivePart()===`from`,i=this.state.isFromComplete();t?.classList.toggle(`active`,r),n?.classList.toggle(`active`,!r),n?.classList.toggle(`disabled`,!i),t?.setAttribute(`aria-selected`,String(r)),n?.setAttribute(`aria-selected`,String(!r)),n?.setAttribute(`aria-disabled`,String(!i)),t?.setAttribute(`tabindex`,r?`0`:`-1`),n?.setAttribute(`tabindex`,r||!i?`-1`:`0`)}updateTimeDisplay(){let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-range-from-time`),n=e.querySelector(`.tp-ui-range-to-time`),r=this.state.getActivePart(),i=this.state.getPreviewValue(),a=this.state.getFromValue(),o=this.state.getToValue(),s=`--:--`;r===`from`&&i?s=YR(i):a&&(s=YR(a));let c=`--:--`;r===`to`&&i?c=YR(i):o&&(c=YR(o)),t&&(t.textContent=s),n&&(n.textContent=c)}updateOkButton(){let e=this.core.getOkButton();if(!e)return;let t=this.state.canConfirm();e.classList.toggle(`disabled`,!t),e.setAttribute(`aria-disabled`,String(!t))}updateInputValue(){let e=this.core.getInput();if(!e)return;let t=this.state.getFromValue(),n=this.state.getToValue();e.value=`${t?YR(t):`--:--`} - ${n?YR(n):`--:--`}`}syncClockToActivePart(){let e=this.state.getSavedValue(),t=this.core.getHour(),n=this.core.getMinutes();if(t&&(t.value=e?.hour??`12`),n&&(n.value=e?.minutes??`00`),this.core.options.clock.type===`12h`){let t=this.core.getAM(),n=this.core.getPM();e?.type===`AM`?(t?.classList.add(`active`),n?.classList.remove(`active`)):e?.type===`PM`?(n?.classList.add(`active`),t?.classList.remove(`active`)):(t?.classList.remove(`active`),n?.classList.remove(`active`))}n&&(n.blur(),n.classList.remove(`active`)),t&&t.click()}updateAll(){this.updateTabs(),this.updateTimeDisplay(),this.updateOkButton()}},az=class{core;emitter;state;ui;cleanupHandlers=[];isSyncingAmPm=!1;constructor(e,t){this.core=e,this.emitter=t;let{range:n,clock:r}=e.options;this.state=new rz(r.type,n?.minDuration,n?.maxDuration,t),this.ui=new iz(e,this.state)}get isEnabled(){return this.core.options.range?.enabled===!0}init(){if(!this.isEnabled)return;let{from:e,to:t}=$R(this.core.getInput()?.value||``);this.state.setFromValue(e),this.state.setToValue(t),this.state.setActivePart(`from`),this.state.setPreviewValue(null),this.bindEvents(),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent(),this.ui.updateAll()}getActivePart(){return this.state.getActivePart()}setActivePart(e){this.isEnabled&&(this.state.setActivePart(e)&&this.emitter.emit(`range:switch`,{active:e,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent(),this.ui.updateAll())}getFromValue(){return this.state.getFromValue()}getToValue(){return this.state.getToValue()}getDisabledTimeForEndPart(){return this.isEnabled?this.state.getDisabledTimeForEndPart():null}getDuration(){return this.state.getDuration()}validateRange(){return this.isEnabled?this.state.validate():{valid:!0,duration:0}}canConfirm(){return!this.isEnabled||this.state.canConfirm()}getFormattedRange(){let e=this.state.getFromValue(),t=this.state.getToValue();return!e||!t?null:{from:YR(e),to:YR(t)}}bindEvents(){let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-range-tab.tp-ui-range-from`),n=e.querySelector(`.tp-ui-range-tab.tp-ui-range-to`);if(t){let e=()=>this.activatePart(`from`,t);t.addEventListener(`click`,e),this.cleanupHandlers.push(()=>t.removeEventListener(`click`,e))}if(n){let e=()=>this.activatePart(`to`,n);n.addEventListener(`click`,e),this.cleanupHandlers.push(()=>n.removeEventListener(`click`,e))}this.bindTabKeyboard(t,n),ez(this.emitter,this.cleanupHandlers,`update`,()=>this.handleUpdate()),ez(this.emitter,this.cleanupHandlers,`range:minute:commit`,e=>this.handleMinuteCommit(e)),ez(this.emitter,this.cleanupHandlers,`confirm`,()=>this.handleConfirm()),ez(this.emitter,this.cleanupHandlers,`select:am`,()=>this.handleAmPm()),ez(this.emitter,this.cleanupHandlers,`select:pm`,()=>this.handleAmPm()),ez(this.emitter,this.cleanupHandlers,`clear`,()=>this.handleClear())}isTabDisabled(e){return!e||e.getAttribute(`aria-disabled`)===`true`||e.classList.contains(`disabled`)}activatePart(e,t){this.isTabDisabled(t)||this.setActivePart(e)}bindTabKeyboard(e,t){let n=[e,t].filter(e=>e!==null);n.length!==0&&n.forEach((e,t)=>{let r=t===0?`from`:`to`,i=i=>{switch(i.key){case`ArrowRight`:case`ArrowLeft`:{i.preventDefault();let e=((i.key===`ArrowRight`?t+1:t-1)+n.length)%n.length,r=n[e];this.isTabDisabled(r)||r.focus();break}case`Home`:i.preventDefault(),n[0].focus();break;case`End`:i.preventDefault(),n[n.length-1].focus();break;case`Enter`:case` `:case`Spacebar`:i.preventDefault(),this.activatePart(r,e)}};e.addEventListener(`keydown`,i),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,i))})}handleClear(){this.isEnabled&&(this.state.setFromValue(null),this.state.setToValue(null),this.state.setPreviewValue(null),this.state.resetActivePart())}handleUpdate(){if(!this.isEnabled)return;let e=this.core.getHour(),t=this.core.getMinutes(),n=this.core.getActiveTypeMode(),r=e?.value??`12`,i=this.state.getSavedValue(),a=i?.minutes&&i.minutes!==`--`?t?.value??`--`:`--`,o=this.core.options.clock.type===`12h`?n?.textContent??void 0:void 0;this.state.setPreviewValue({hour:r,minutes:a,type:o}),this.ui.updateAll()}handleMinuteCommit(e){if(!this.isEnabled)return;let t={hour:e.hour,minutes:e.minutes,type:e.type??void 0};this.state.getActivePart()===`from`?(this.state.setFromValue(t),this.state.setPreviewValue(null),this.state.isFromComplete()&&(this.state.setActivePart(`to`),this.emitter.emit(`range:switch`,{active:`to`,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent())):(this.state.setToValue(t),this.state.setPreviewValue(null)),this.state.validate(),this.ui.updateAll()}handleAmPm(){if(!this.isEnabled||this.isSyncingAmPm||this.core.options.clock.type!==`12h`)return;let e=this.core.getActiveTypeMode()?.textContent;if(e){if(this.state.getActivePart()===`from`){let t=this.state.getFromValue();t&&(this.state.setFromValue({...t,type:e}),this.state.isFromComplete()&&(this.state.setActivePart(`to`),this.state.setPreviewValue(null),this.emitter.emit(`range:switch`,{active:`to`,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent()))}else{let t=this.state.getToValue();t&&this.state.setToValue({...t,type:e}),this.emitter.emit(`range:switch`,{active:`to`,disabledTime:this.state.getDisabledTimeForEndPart()})}this.state.validate(),this.ui.updateAll()}}emitAmPmSyncEvent(){if(this.core.options.clock.type!==`12h`)return;let e=this.state.getSavedValue();if(e?.type){this.isSyncingAmPm=!0;try{e.type===`AM`?this.emitter.emit(`select:am`,{}):e.type===`PM`&&this.emitter.emit(`select:pm`,{})}finally{this.isSyncingAmPm=!1}}}handleConfirm(){if(!this.isEnabled)return;this.state.commitPreview();let e=this.state.getFromValue(),t=this.state.getToValue(),n=e?YR(e):`--:--`,r=t?YR(t):`--:--`,i=this.state.getDuration();this.ui.updateInputValue(),this.emitter.emit(`range:confirm`,{from:n,to:r,duration:i})}reset(){this.state.reset()}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[],this.reset()}},oz={name:`range`,factory:(e,t)=>new az(e,t),clearHandler:(e,t)=>{if(!e.options.range?.enabled)return;let n=e.getModalElement();if(!n)return;let r=n.querySelector(`.tp-ui-range-from`),i=n.querySelector(`.tp-ui-range-to`),a=n.querySelector(`.tp-ui-range-from-time`),o=n.querySelector(`.tp-ui-range-to-time`);a&&(a.textContent=`--:--`),o&&(o.textContent=`--:--`),r?.classList.add(`active`),i?.classList.remove(`active`),r?.setAttribute(`aria-selected`,`true`),i?.setAttribute(`aria-selected`,`false`),r?.setAttribute(`tabindex`,`0`),i?.setAttribute(`tabindex`,`-1`),i?.classList.add(`disabled`),i?.setAttribute(`aria-disabled`,`true`);let s=e.getHour();s&&s.focus(),t.emit(`range:switch`,{active:`from`,disabledTime:null})}}})),cz,lz,uz,dz=!1;async function fz(){if(!cz){let e=await Promise.resolve().then(()=>(UR(),zI));cz=e.TimepickerUI,lz=e.PluginRegistry,uz=(await Promise.resolve().then(()=>(sz(),WR))).RangePlugin,!dz&&lz&&uz&&(lz.register(uz),dz=!0)}}var pz=class{constructor(e){if(this.config={dayStartTime:`00:00`,dayEndTime:`23:59`,minuteIncrement:5,clockType:`12h`,...e},this.selectedStart=this.extractTimeAsHHMM(e.startTime),e.endTime)this.selectedEnd=this.extractTimeAsHHMM(e.endTime);else{let e=new Date(`2000-01-01T${this.selectedStart}:00Z`),n=new Date(e.getTime()+36e5);this.selectedEnd=t.tools.dateTime.extractTime(n.toISOString())}this.inputElement=document.createElement(`input`),this.container=this.createUI()}extractTimeAsHHMM(e){return e.includes(`T`)?t.tools.dateTime.extractTime(e):e}createUI(){let e=document.createElement(`div`);return e.style.cssText=`
231
+ </div>`},XR=e=>{let{range:{enabled:t,fromLabel:n,toLabel:r},labels:{rangeSelectionLabel:i}}=e;return!t||!GR.has(`range`)?``:`<div class="tp-ui-range-header" role="tablist" aria-label="${i}"><button type="button" class="tp-ui-range-tab tp-ui-range-from active" role="tab" tabindex="0" aria-selected="true"><span class="tp-ui-range-tab-label">${n}</span><span class="tp-ui-range-tab-value tp-ui-range-from-time">--:--</span></button><button type="button" class="tp-ui-range-tab tp-ui-range-to" role="tab" tabindex="-1" aria-selected="false"><span class="tp-ui-range-tab-label">${r}</span><span class="tp-ui-range-tab-value tp-ui-range-to-time">--:--</span></button></div>`},ZR=(e,t)=>{let{ui:{clearButton:n},labels:{clear:r}}=e;return n?`<div class="tp-ui-clear-btn ${t} disabled" data-md3-ripple tabindex="0" role="button" aria-label="${r}" aria-disabled="true">${r}</div>`:``},QR=(e,t,n)=>{if(e.isWheelMode){let t=GR.getTemplateProvider(`wheel`);return t?`<div class="tp-ui-mobile-clock-wrapper ${e.mobileClass}">${t(n,e.instanceId)}</div>`:`<div class="tp-ui-mobile-clock-wrapper ${e.mobileClass}"></div>`}let{labels:{clockLabel:r}}=n;return`<div class="tp-ui-mobile-clock-wrapper ${e.mobileClass}"><div class="tp-ui-body ${e.mobileClass}"><div class="tp-ui-clock-face ${e.mobileClass}" role="group" aria-label="${r}"><div class="tp-ui-dot ${e.mobileClass}" aria-hidden="true"></div><div class="tp-ui-clock-hand ${e.mobileClass}" aria-hidden="true"><div class="tp-ui-circle-hand ${e.mobileClass}"></div></div><div class="tp-ui-tips-wrapper ${e.mobileClass}" aria-hidden="true"></div>${e.clockType===`24h`?`<div class="tp-ui-tips-wrapper-24h ${e.mobileClass}" aria-hidden="true"></div>`:``}</div></div></div>`},$R=(e,t)=>{let{labels:{time:n,mobileTime:r,timeLabel:i,am:a,pm:o,mobileMinute:s,mobileHour:c,hourLabel:l,minuteLabel:u,periodLabel:d},ui:{editable:f}}=e,{mobileClass:p,clockType:m,instanceId:h}=t,g=p?r:n,_=m===`12h`,v=_?`1`:`0`,y=_?`12`:`23`,b=_?`12`:`0`,x=m===`24h`?``:`<div class="tp-ui-wrapper-type-time ${p}" role="group" aria-label="${d}"><div class="tp-ui-type-mode tp-ui-am ${p?`mobile`:`tp-ui-ripple`}" data-md3-ripple tabindex="0" role="button" aria-label="${a}" aria-pressed="false" data-type="AM">${a}</div><div class="tp-ui-type-mode tp-ui-pm ${p?`mobile`:`tp-ui-ripple`}" data-md3-ripple tabindex="0" role="button" aria-label="${o}" aria-pressed="false" data-type="PM">${o}</div></div>`;return`<div class="tp-ui-select-time ${p}" id="tp-ui-label-${h}">${g}</div><div class="tp-ui-header ${p}"><div class="tp-ui-wrapper-time ${p} ${m===`24h`?`tp-ui-wrapper-time-24h`:``}" role="group" aria-label="${i}"><div class="tp-ui-input-wrapper ${p}"><div class="tp-ui-input-ripple-wrapper ${p}" data-md3-ripple><input name="hour" ${!f&&!p?`readonly`:``} class="tp-ui-hour ${p}" tabindex="0" type="number" min="${v}" max="${y}" aria-label="${p?c:l}" role="spinbutton" aria-valuemin="${v}" aria-valuemax="${y}" aria-valuenow="${b}" aria-valuetext="${b}"></div><div class="tp-ui-hour-text ${p}">${c}</div></div><div class="tp-ui-dots ${p}" aria-hidden="true"><span></span><span></span></div><div class="tp-ui-input-wrapper ${p}"><div class="tp-ui-input-ripple-wrapper ${p}" data-md3-ripple><input name="minutes" ${!f&&!p?`readonly`:``} class="tp-ui-minutes ${p}" tabindex="0" type="number" min="0" max="59" aria-label="${p?s:u}" role="spinbutton" aria-valuemin="0" aria-valuemax="59" aria-valuenow="0" aria-valuetext="00"></div><div class="tp-ui-minute-text ${p}">${s}</div></div></div>${x}</div>`},ez=(e,t)=>{let{ui:{enableSwitchIcon:n,iconTemplate:r,iconTemplateMobile:i},labels:{cancel:a,ok:o,switchToKeyboardLabel:s,switchToClockLabel:c,toggleLabel:l}}=e,u=`<button aria-label="${s}" type="button" class="tp-ui-keyboard-icon">${r||HR}</button>`,d=i||`<button aria-label="${c}" type="button" class="tp-ui-keyboard-icon">${i||UR}</button>`,f=n?`<div class="tp-ui-keyboard-icon-wrapper ${t}" tabindex="0" role="button" aria-pressed="false" aria-label="${l}" data-view="desktop">${t?d:u}</div>`:``,p=ZR(e,t);return`<div class="tp-ui-footer ${t}" ${t?`data-view="mobile"`:``}>${f}<div class="tp-ui-wrapper-btn ${t}">${p}<div class="tp-ui-cancel-btn ${t}" data-md3-ripple tabindex="0" role="button" aria-label="${a}">${a}</div><div class="tp-ui-ok-btn ${t}" data-md3-ripple tabindex="0" role="button" aria-label="${o}">${o}</div></div></div>`},tz=(e,t)=>{let{ui:{mode:n,animation:r,theme:i,mobile:a},clock:{incrementMinutes:o}}=e,s=a?`mobile`:``,c=n===`compact-wheel`&&GR.has(`wheel`),l=(n===`wheel`||c)&&GR.has(`wheel`),u=!!e.range?.enabled&&GR.has(`range`),d=!!e.timezone?.enabled&&GR.has(`timezone`),f={mobileClass:s,clockType:e.clock.type||`12h`,instanceId:t,isWheelMode:l,isCompactWheel:c,isRangeMode:u},p=XR(e),m=YR(e,s,t),h=c?``:$R(e,f),g=QR(f,o??1,e),_=c&&e.wheel?.hideFooter===!0?``:ez(e,s),v;return v=c?` tp-ui-compact-wheel-mode`:l?` tp-ui-wheel-mode`:``,`<div class="tp-ui-modal normalize ${s}${u?` tp-ui-range-mode`:``}${d?` tp-ui-tz-mode`:``}${v}" data-theme="${i}" role="dialog" aria-modal="true" aria-labelledby="tp-ui-label-${t}" data-owner-id="${t}" style='transition:${r?`opacity 0.15s linear`:`none`}'><div class="tp-ui-wrapper ${s}" tabindex="0">${p}${h}${m}${g}${_}</div><div class="timepicker-announcer sr-only" role="status" aria-live="polite" aria-atomic="true"></div></div>`},nz=0,rz=``,iz=``,az=class{core;emitter;timeouts=[];scrollLocked=!1;constructor(e,t){this.core=e,this.emitter=t}runWithTimeout(e,t=MR.DEFAULT_DELAY){let n=setTimeout(e,t);this.timeouts.push(n)}clearAllTimeouts(){this.timeouts.forEach(clearTimeout),this.timeouts=[]}isPopoverMode(){return this.core.options.ui.mode===`compact-wheel`&&!!this.core.options.wheel?.placement}clearExistingModal(){if(AR()===!1)return;let e=this.core.getModalElement();e&&e.remove()}setModalTemplate(){if(AR()===!1)return;this.clearExistingModal();let e=tz(this.core.options,this.core.instanceId);if(this.core.options.ui.inline?.enabled){let t=document.getElementById(this.core.options.ui.inline.containerId);if(!t)return;t.innerHTML=``,t.insertAdjacentHTML(`beforeend`,e);let n=t.querySelector(`.tp-ui-modal`);if(n){n.classList.add(`tp-ui--inline`);let{showButtons:e}=this.core.options.ui.inline;(e===!1||e===void 0)&&n.querySelectorAll(`.tp-ui-wrapper-btn, .tp-ui-wrapper-btn.mobile`).forEach(e=>e.style.display=`none`)}return}let{appendModalSelector:t}=this.core.options.ui;t?document.querySelector(t)?.insertAdjacentHTML(`beforeend`,e):document.body.insertAdjacentHTML(`beforeend`,e)}lockScroll(){AR()!==!1&&(this.core.options.ui.inline?.enabled||this.isPopoverMode()||this.core.options.ui.enableScrollbar||this.scrollLocked||(this.scrollLocked=!0,cR()))}unlockScroll(){AR()!==!1&&this.scrollLocked&&(this.scrollLocked=!1,lR())}setScrollbarOrNot(){AR()!==!1&&(this.core.options.ui.inline?.enabled||this.isPopoverMode()||(this.core.options.ui.enableScrollbar?this.runWithTimeout(()=>{kR()||this.runWithTimeout(()=>{this.unlockScroll()},MR.SCROLLBAR_RESTORE)},400):this.lockScroll()))}removeBackdrop(){if(this.core.options.ui.inline?.enabled||this.core.options.ui.backdrop)return;let e=this.core.getModalElement(),t=this.core.getOpenElement();e?.classList.add(`removed`),t.forEach(e=>e?.classList.add(`disabled`))}setNormalizeClass(){let e=this.core.getModalElement();e&&(e.classList.add(`tp-ui-normalize`),e.querySelectorAll(`:scope > div`).forEach(e=>e.classList.add(`tp-ui-normalize`)))}setShowClassToBackdrop(){if(this.core.options.ui.inline?.enabled||this.isPopoverMode()){this.core.getModalElement()?.classList.add(`show`),this.setInitialFocus();return}this.core.options.ui.backdrop&&this.runWithTimeout(()=>{this.core.getModalElement()?.classList.add(`show`),this.setInitialFocus()},MR.MODAL_ANIMATION)}setInitialFocus(){if(!this.core.options.behavior.focusTrap)return;let e=this.core.getWrapper();e&&typeof requestAnimationFrame<`u`&&requestAnimationFrame(()=>{e.focus()})}setFlexEndToFooterIfNoKeyboardIcon(){let e=this.core.getFooter();!this.core.options.ui.enableSwitchIcon&&e&&(e.style.justifyContent=`flex-end`)}destroy(){this.clearAllTimeouts(),this.unlockScroll(),this.clearExistingModal()}},oz=(e,t,n,r)=>{let i={hour:`12`,minutes:`00`,type:t===`24h`?void 0:`PM`};if(!e)return i;let a=e.value.trim();if(!n&&!a)return i;if(typeof n==`boolean`&&n){let[e,n]=new Date().toLocaleTimeString().split(`:`),r=e.padStart(2,`0`);if(/[a-z]/i.test(n)&&t===`12h`){let[e,t]=n.split(` `);return{hour:r,minutes:e,type:t}}return{hour:r,minutes:n,type:void 0}}if(typeof n==`object`){let{time:e,locales:i,preventClockType:a}=n,o=e??new Date;if(a&&r){let[e,t]=new Date(o).toLocaleTimeString().split(`:`);if(/[a-z]/i.test(t)){let[n,r]=t.split(` `);return{hour:e,minutes:n,type:r}}return{hour:e.padStart(2,`0`),minutes:t,type:void 0}}let[s,c]=new Date(o).toLocaleTimeString(i||`en-US`,{hour:`2-digit`,minute:`2-digit`,hour12:t===`12h`}).split(`:`);if(t===`12h`&&/[a-z]/i.test(c)){let e=c.trim().split(` `);return{hour:s,minutes:e[0],type:e[1]||`AM`}}return{hour:s,minutes:c.replace(/\D/g,``),type:void 0}}let[o,s]=a.split(` `),[c=``,l=``]=o.split(`:`),u=c.replace(/\D/g,``),d=l.replace(/\D/g,``),f={hour:u.padStart(2,`0`),minutes:d.padStart(2,`0`),type:t===`12h`?s:void 0};if(u.length>2||d.length>2)return{...f,error:`Invalid input: too many digits.`,currentHour:c,currentMin:l};if(/[a-z]/i.test(o))return{...f,error:`Input contains invalid letters.`};if(a.includes(` `)&&(!s||a.length>8||s!==`AM`&&s!==`PM`))return{...f,error:`Invalid AM/PM format or length.`,currentLength:a.length,currentType:s};let p=Number(u),m=Number(d);if(t===`12h`){if(p<1||p>12||m<0||m>59||s!==`AM`&&s!==`PM`)return{...f,error:`Invalid 12h time.`,currentHour:p,currentMin:m,currentType:s}}else if(p<0||p>23||m<0||m>59)return{...f,error:`Invalid 24h time.`,currentHour:p,currentMin:m};return f},sz=(e,t,n)=>{let r=Number(e);if(Number.isNaN(r))return!1;switch(t){case`hour`:return n===`24h`?r>=0&&r<=23:r>0&&r<=12;case`minutes`:return r>=0&&r<=59;default:return}},cz=`tp-ui`,lz=`mousedown mouseup mousemove mouseleave mouseover touchstart touchmove touchend`,uz=`active`,dz=class{core;emitter;constructor(e,t){this.core=e,this.emitter=t}isCurrentTimeEnabled(e){let t=this.core.options.clock.currentTime;return typeof t==`boolean`?t:!!t?.[e]}preventClockTypeByCurrentTime(){if(!this.isCurrentTimeEnabled(`preventClockType`))return;let e=this.core.getInput();if(!e)return;let{currentTime:t,clockType:n}={currentTime:this.core.options.clock.currentTime,clockType:this.core.options.clock.type},{type:r}=oz(e,n,t,!0);this.core.updateOptions({clock:{type:r?`12h`:`24h`}})}updateInputValueWithCurrentTimeOnStart(){if(!this.isCurrentTimeEnabled(`updateInput`))return;let e=this.core.getInput();if(!e)return;let{hour:t,minutes:n,type:r}=oz(e,this.core.options.clock.type,this.core.options.clock.currentTime);e.value=r?`${t}:${n} ${r}`:`${t}:${n}`}getInputValueOnOpenAndSet(){let e=this.core.getInput();if(!e)return;let t=oz(e,this.core.options.clock.type,this.core.options.clock.currentTime),n=this.core.getHour(),r=this.core.getMinutes(),i=this.core.getActiveTypeMode(),a=this.core.getAM();if(t===void 0){n&&(n.value=`12`),r&&(r.value=`00`);let e={hour:n?.value||`12`,minutes:r?.value||`00`,type:i?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit(`open`,e);let t=this.core.options.range?.enabled===!0;this.core.options.clock.type!==`24h`&&a&&!t&&a.classList.add(uz);return}let[o,s,c]=e.value.split(`:`).join(` `).split(` `);e.value.length===0&&(o=t.hour,s=t.minutes,c=t.type),this.core.options.clock.type!==`24h`&&!c&&(c=t.type||`AM`),n&&(n.value=o.padStart(2,`0`)),r&&(r.value=s.padStart(2,`0`));let l=this.core.getModalElement()?.querySelector(`[data-type='${c}']`);this.core.options.clock.type!==`24h`&&l&&l.classList.add(uz);let u={...t,type:i?.dataset.type,degreesHours:this.core.degreesHours,degreesMinutes:this.core.degreesMinutes};this.emitter.emit(`open`,u)}getInputValue(e,t,n){return oz(e,t,n)}destroy(){}},fz=class{core;emitter;isAnimating=!1;constructor(e,t){this.core=e,this.emitter=t,this.setupEventListeners()}setupEventListeners(){this.emitter.on(`switch:view`,()=>{this.toggleMobileClockFace()})}checkMobileOption(){this.core.setIsMobileView(!!this.core.options.ui.mobile),this.core.options.ui.mobile&&this.core.updateOptions({ui:{editable:!0}})}toggleMobileClockFace(){if(this.isAnimating)return;let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-wrapper`),n=this.core.getKeyboardClockIcon(),r=e.querySelector(`.tp-ui-mobile-clock-wrapper`),i=e.querySelectorAll(`*`),a=e.querySelector(`.tp-ui-select-time`),o=this.core.getHour(),s=this.core.getMinutes(),c=this.core.getClockFace();if(!t)return;let l=t.classList.contains(`expanded`),u=this.core.isMobileView;l?this.collapseClockFace(t,r,i,n,a,o,s,c,u):this.expandClockFace(t,r,i,n,a,o,s,c)}collapseClockFace(e,t,n,r,i,a,o,s,c){if(this.isAnimating=!0,typeof requestAnimationFrame<`u`){let l=typeof window<`u`&&window.matchMedia(`(orientation: landscape) and (min-width: 320px) and (max-width: 825px)`).matches;requestAnimationFrame(()=>{l&&e instanceof HTMLElement?this.collapseLandscape(e,t,n,r,i,a,o,s,c):this.collapsePortrait(e,t,n,r,i,a,o,s,c)})}else this.switchView(i,r,a,o,!0),this.isAnimating=!1;r?.setAttribute(`aria-label`,`Show clock face`),r?.setAttribute(`aria-pressed`,`false`)}collapseLandscape(e,t,n,r,i,a,o,s,c){s?.classList.remove(`scale-in`);let l=this.core.getModalElement(),u=this.getMobileLandscapeHeight(l);e.style.width=`328px`,e.style.height=u,t instanceof HTMLElement&&(t.style.height=`0`,t.style.opacity=`0`,t.style.transform=`scale(0)`),setTimeout(()=>{this.applyMobileClasses(e,t,n,i,c),e.classList.add(`mobile`),t&&t.classList.add(`mobile`),this.switchView(i,r,a,o,!0),requestAnimationFrame(()=>{e.style.width=``,e.style.height=``,t instanceof HTMLElement&&(t.style.height=``,t.style.opacity=``,t.style.transform=``),this.isAnimating=!1})},MR.WRAPPER_TRANSITION)}collapsePortrait(e,t,n,r,i,a,o,s,c){c?s?.classList.remove(`scale-in`):s?.classList.add(`scale-in`),t?.classList.remove(`expanded`),c&&t?.classList.add(`mobile`),requestAnimationFrame(()=>{this.applyMobileClasses(e,t,n,i,c),this.switchView(i,r,a,o,!0),setTimeout(()=>{this.isAnimating=!1},MR.MOBILE_TOGGLE)})}applyMobileClasses(e,t,n,r,i){e.classList.remove(`expanded`),t?.classList.remove(`expanded`),i&&(e.classList.add(`mobile`),t?.classList.add(`mobile`)),n.forEach(n=>{n!==t&&n!==e&&n!==r&&(n.classList.remove(`expanded`),i&&n.classList.add(`mobile`))}),r&&(r.classList.remove(`expanded`),i&&r.classList.add(`mobile`))}expandClockFace(e,t,n,r,i,a,o,s){this.isAnimating=!0,o?.classList.contains(`active`)&&o?this.emitter.emit(`select:minute`,{minutes:o.value}):a&&this.emitter.emit(`select:hour`,{hour:a.value}),n.forEach(n=>{n!==t&&n!==e&&n!==i&&(n.classList.remove(`mobile`),n.classList.add(`expanded`))}),i&&(i.classList.remove(`mobile`),i.classList.add(`expanded`)),this.switchView(i,r,a,o,!1),typeof requestAnimationFrame<`u`?requestAnimationFrame(()=>{e.classList.remove(`mobile`),e.classList.add(`expanded`),requestAnimationFrame(()=>{t&&(t.classList.remove(`mobile`),t.classList.add(`expanded`)),s&&s.classList.remove(`scale-in`),setTimeout(()=>{s&&s.classList.add(`scale-in`)},MR.CLOCK_SCALE_DELAY),setTimeout(()=>{this.isAnimating=!1},MR.MOBILE_TOGGLE)})}):this.isAnimating=!1,r?.setAttribute(`aria-label`,`Hide clock face`),r?.setAttribute(`aria-pressed`,`true`)}switchView(e,t,n,r,i){let a=this.core.getModalElement(),o=a?.querySelector(`.tp-ui-hour-text`),s=a?.querySelector(`.tp-ui-minute-text`),c=t?.querySelector(`.tp-ui-keyboard-icon`),l=this.core.getInputWrappers(),u=this.core.getHeader(),d=a?.querySelector(`.tp-ui-wrapper-type-time`),f=a?.querySelector(`.tp-ui-am`),p=a?.querySelector(`.tp-ui-pm`),m=a?.querySelectorAll(`.tp-ui-input-ripple-wrapper`),{iconTemplate:h,iconTemplateMobile:g}=this.core.options.ui,{time:_,mobileTime:v}=this.core.options.labels;i?(e?.classList.add(`mobile`),t?.classList.add(`mobile`),n?.classList.add(`mobile`),n?.removeAttribute(`readonly`),r?.classList.add(`mobile`),r?.removeAttribute(`readonly`),o?.classList.add(`mobile`),s?.classList.add(`mobile`),u?.classList.add(`mobile`),d?.classList.add(`mobile`),f?.classList.add(`mobile`),f?.classList.remove(`tp-ui-ripple`),p?.classList.add(`mobile`),p?.classList.remove(`tp-ui-ripple`),l?.forEach(e=>{e.classList.add(`mobile`)}),m?.forEach(e=>{e.classList.add(`mobile`)}),e&&v&&(e.textContent=v),c&&(c.innerHTML=g||UR),this.updateClockFaceAccessibility(!0)):(e?.classList.remove(`mobile`),t?.classList.remove(`mobile`),n?.classList.remove(`mobile`),r?.classList.remove(`mobile`),this.core.options.ui.editable||(n?.setAttribute(`readonly`,``),r?.setAttribute(`readonly`,``)),o?.classList.remove(`mobile`),s?.classList.remove(`mobile`),u?.classList.remove(`mobile`),d?.classList.remove(`mobile`),f?.classList.remove(`mobile`),f?.classList.add(`tp-ui-ripple`),p?.classList.remove(`mobile`),p?.classList.add(`tp-ui-ripple`),l?.forEach(e=>{e.classList.remove(`mobile`)}),m?.forEach(e=>{e.classList.remove(`mobile`)}),e&&_&&(e.textContent=_),c&&(c.innerHTML=h||HR),this.updateClockFaceAccessibility(!1))}updateClockFaceAccessibility(e){let t=this.core.getClockFace();if(!t)return;let n=t.querySelector(`.tp-ui-tips-wrapper`),r=t.querySelector(`.tp-ui-tips-wrapper-24h`),i=t.querySelectorAll(`.tp-ui-tip`);e?(t.setAttribute(`aria-hidden`,`true`),n?.setAttribute(`aria-hidden`,`true`),r?.setAttribute(`aria-hidden`,`true`),i.forEach(e=>{e.setAttribute(`tabindex`,`-1`),e.setAttribute(`aria-hidden`,`true`)})):(t.removeAttribute(`aria-hidden`),n?.removeAttribute(`aria-hidden`),r?.removeAttribute(`aria-hidden`),i.forEach(e=>{e.setAttribute(`tabindex`,`0`),e.removeAttribute(`aria-hidden`)}))}getMobileLandscapeHeight(e){return e?.classList.contains(`tp-ui-tz-mode`)?`326px`:e?.classList.contains(`tp-ui-range-mode`)?`287px`:`258px`}destroy(){}},pz=e=>{if(!e)return;let{disabledTime:t,type:n}=e.clock;if(!t||!Object.keys(t).length)return;let{hours:r,minutes:i,interval:a}=t;if(a){delete t.hours,delete t.minutes;let e=Array.isArray(a)?a:[a];if(!n)throw Error(`clockType required for interval`);return BR(e,n),{value:e.map(e=>{let[t,r]=e.trim().split(`-`),{hour:i,minutes:a,type:o}=oz({value:t.trim()},n),{hour:s,minutes:c,type:l}=oz({value:r.trim()},n),u=IR(i,s).map(e=>Number(e)===0?`00`:String(Number(e))),d=[],f=Number(a),p=Number(c);if(l===o)return f>0&&p<=0?(d.push(u[0],u[u.length-1]),u=u.slice(1,-1)):p<59&&p>0&&f<=0?(d.push(void 0,u[u.length-1]),u=u.slice(0,-1)):p>0&&f>0?(d.push(u[0],u[u.length-1]),u=u.slice(1,-1)):p===0&&f===0&&(d.push(void 0,u[u.length-1]),u.pop()),{removedStartedHour:d[0]!==void 0&&Number(d[0])<=9?`0${d[0]}`:d[0],removedEndHour:d[1]!==void 0&&Number(d[1])<=9?`0${d[1]}`:d[1],rangeArrHour:u,startMinutes:IR(a,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:LR(0,c).map(e=>Number(e)<=9?`0${e}`:`${e}`),startType:o,endType:l};{let e=IR(i,12).map(String),t=LR(1,s).map(String),n=[],r=[];return f>0&&p<=0?(r.push(t[t.length-1]),n.push(e[0]),t.pop(),e.shift()):p<59&&p>0&&f<=0?(n.push(e[0]),r.push(t[t.length-1]),t.pop()):p>0&&f>0?(r.push(t[t.length-1]),n.push(e[0]),t.pop(),e.shift()):p===0&&f===0&&(r.push(t[t.length-1]),n.push(e[0]),t.pop()),{startType:o,endType:l,amHours:e,pmHours:t,removedAmHour:n[0]&&Number(n[0])<=9?`0${n[0]}`:n[0],removedPmHour:r[0]&&Number(r[0])<=9?`0${r[0]}`:r[0],startMinutes:Number(a)===0?[]:IR(a,59).map(e=>Number(e)<=9?`0${e}`:`${e}`),endMinutes:LR(0,c).map(e=>Number(e)<=9?`0${e}`:`${e}`)}}}).reduce((e,t)=>(Object.entries(t).forEach(([t,n])=>{e[t]=Array.isArray(n)?Array.isArray(e[t])?[...e[t],...n]:[...n]:n}),e),{isInterval:!0,clockType:n,intervals:e})}}return r?.forEach(e=>{if(n===`12h`&&Number(e)>12)throw Error(`The disabled hours value has to be less than 13`);if(n===`24h`&&Number(e)>23)throw Error(`The disabled hours value has to be less than 24`)}),i?.forEach(e=>{if(Number(e)>59)throw Error(`The disabled minutes value has to be less than 60`)}),{value:{hours:r?.map(e=>e===`00`||Number(e)===0?`0${Number(e)}`:`${Number(e)}`),minutes:i?.map(e=>Number(e)<=9?`0${e}`:`${e}`)}}},mz=(e,t,n,r)=>{if(e){if(Array.isArray(e)&&e.length>0)return!e.map(e=>sz(e,t,n)).some(e=>e===!1);if(typeof e==`string`||typeof e==`number`){let i=sz(e,t,n),a=r?.map(Number).includes(Number(e));return!!(i&&!a)}}},hz=class{core;constructor(e){this.core=e}getDisableTime(){let e=pz(this.core.options);this.core.setDisabledTime(e||null)}destroy(){}},gz=class{inputValueHandler;mobileViewHandler;disabledTimeHandler;core;constructor(e,t){this.core=e,this.inputValueHandler=new dz(e,t),this.mobileViewHandler=new fz(e,t),this.disabledTimeHandler=new hz(e)}preventClockTypeByCurrentTime(){this.inputValueHandler.preventClockTypeByCurrentTime()}updateInputValueWithCurrentTimeOnStart(){this.inputValueHandler.updateInputValueWithCurrentTimeOnStart()}getInputValueOnOpenAndSet(){this.inputValueHandler.getInputValueOnOpenAndSet()}getInputValue(e,t,n){return this.inputValueHandler.getInputValue(e,t,n)}checkMobileOption(){this.mobileViewHandler.checkMobileOption()}toggleMobileClockFace(){this.mobileViewHandler.toggleMobileClockFace()}updateClockFaceAccessibility(e){this.mobileViewHandler.updateClockFaceAccessibility(e)}getDisableTime(){this.disabledTimeHandler.getDisableTime()}destroy(){this.inputValueHandler.destroy(),this.mobileViewHandler.destroy(),this.disabledTimeHandler.destroy()}},_z=class{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setTheme(){let e=this.core.getModalElement();if(!e)return;let{theme:t}=this.core.options.ui;t&&e.setAttribute(`data-theme`,t)}setInputClassToInputElement(){let e=this.core.getInput();e&&(FR(e,`tp-ui-input`)||e.classList.add(`tp-ui-input`))}setDataOpenToInputIfDoesntExistInWrapper(){let e=this.core.getOpenElementData(),t=this.core.getInput();e===null&&t&&t.setAttribute(`data-open`,`tp-ui-input`)}setClassTopOpenElement(){let e=this.core.getOpenElement();for(let t of e)t&&t.classList.add(`tp-ui-open-element`)}setTimepickerClassToElement(){let e=this.core.element;if(!e)return;e.classList.add(cz);let t=this.core.options.ui.cssClass;t&&t!==cz&&e.classList.add(t)}destroy(){let e=this.core.getModalElement();e&&e.removeAttribute(`data-theme`)}},vz=class e extends Error{constructor(t,n){super(`[TimepickerUI] ${t}`),this.code=n,this.name=`TimepickerError`,Object.setPrototypeOf(this,e.prototype)}},yz={ELEMENT_NOT_FOUND:`ELEMENT_NOT_FOUND`,INVALID_PARAMETER:`INVALID_PARAMETER`,NO_INPUT_ELEMENT:`NO_INPUT_ELEMENT`,INSTANCE_DESTROYED:`INSTANCE_DESTROYED`,NOT_INITIALIZED:`NOT_INITIALIZED`,INVALID_TIME_FORMAT:`INVALID_TIME_FORMAT`,INLINE_CONFIG_ERROR:`INLINE_CONFIG_ERROR`,CONTAINER_NOT_FOUND:`CONTAINER_NOT_FOUND`,SSR_ENVIRONMENT:`SSR_ENVIRONMENT`},bz=(e,t)=>{if(!e)return;let n=e.querySelector(`.timepicker-announcer`);n&&(n.textContent=``,setTimeout(()=>{n.textContent=t},100))},xz=(e,t)=>{e&&e.setAttribute(`aria-pressed`,String(t))},Sz=e=>e.getAttribute(`aria-disabled`)===`true`||e.classList.contains(`disabled`),Cz=(e,t)=>{if(!e)return()=>{};let n=n=>{Sz(e)||t(n)},r=n=>{n.key!==`Enter`&&n.key!==` `&&n.key!==`Spacebar`||((n.key===` `||n.key===`Spacebar`)&&n.preventDefault(),!Sz(e)&&t(n))};return e.addEventListener(`click`,n),e.addEventListener(`keydown`,r),()=>{e.removeEventListener(`click`,n),e.removeEventListener(`keydown`,r)}},wz=()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Tz=class{core;emitter;constructor(e,t){this.core=e,this.emitter=t}setErrorHandler(){let e=this.core.getInput();if(!e)return!0;let{error:t,currentHour:n,currentMin:r,currentType:i,currentLength:a}=oz(e,this.core.options.clock.type);if(this.removeErrorHandler(),t){if(AR()===!1)return!1;let o=this.core.options.labels.invalidTimeFormat??`Invalid time format`,s=document.createElement(`div`);s.classList.add(`tp-ui-invalid-text`),s.setAttribute(`role`,`alert`);let c=document.createElement(`b`);c.textContent=o,s.appendChild(c),e.classList.add(`tp-ui-invalid-format`),e.nextElementSibling?.classList.contains(`tp-ui-invalid-text`)||e.after(s),bz(this.core.getModalElement(),o);let l={error:t,rejectedHour:void 0,rejectedMinute:void 0,inputHour:n,inputMinute:r,inputType:i,inputLength:a};return this.emitter.emit(`error`,l),!1}return!0}removeErrorHandler(){let e=this.core.getInput();if(!e)return;e.classList.remove(`tp-ui-invalid-format`);let t=e.nextElementSibling;t?.classList.contains(`tp-ui-invalid-text`)&&t.remove()}checkDisabledValuesOnStart(){if(!this.core.options.clock.disabledTime)return;let{disabledTime:e,type:t}=this.core.options.clock;if(e.interval){if(!t)throw new vz(`clockType is required when using disabledTime.interval`,yz.INVALID_PARAMETER);let n=Array.isArray(e.interval)?e.interval:[e.interval];try{BR(n,t)}catch(e){throw new vz(`Invalid disabledTime.interval: ${e.message}`,yz.INVALID_PARAMETER)}return}let{hours:n,minutes:r}=e,i=!n||mz(n,`hour`,t),a=!r||mz(r,`minutes`,t);if(!i||!a)throw new vz(`Invalid hours or minutes in disabledTime option`,yz.INVALID_PARAMETER)}destroy(){this.removeErrorHandler()}},Ez=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnClick(){let e=this.core.getOpenElement();if(!e)return;let t=()=>{this.core.isDestroyed||this.emitter.emit(`show`,{})};e.forEach(e=>{this.cleanupHandlers.push(Cz(e,t))})}handleCancelButton(){let e=this.core.getCancelButton();e&&this.cleanupHandlers.push(Cz(e,()=>{this.core.isDestroyed||this.emitter.emit(`cancel`,{})}))}handleOkButton(){let e=this.core.getOkButton();e&&this.cleanupHandlers.push(Cz(e,()=>{if(this.core.isDestroyed||e.getAttribute(`aria-disabled`)===`true`)return;let t=this.core.getHour(),n=this.core.getMinutes();if(t&&n){let e=this.core.getActiveTypeMode();this.emitter.emit(`confirm`,{hour:t.value,minutes:n.value,type:e?.textContent||void 0});return}let r=this.core.getModalElement();if(r){let e=r.querySelector(`.tp-ui-wheel-hours .tp-ui-wheel-item.is-center`),t=r.querySelector(`.tp-ui-wheel-minutes .tp-ui-wheel-item.is-center`),n=r.querySelector(`.tp-ui-wheel-ampm .tp-ui-wheel-item.is-center`);this.emitter.emit(`confirm`,{hour:e?.getAttribute(`data-value`)??void 0,minutes:t?.getAttribute(`data-value`)??void 0,type:n?.getAttribute(`data-value`)??void 0})}}))}handleAmClick(){let e=this.core.getAM();e&&this.cleanupHandlers.push(Cz(e,()=>{if(this.core.isDestroyed)return;let t=this.core.getPM();e.classList.add(`active`),t?.classList.remove(`active`),xz(e,!0),xz(t,!1),bz(this.core.getModalElement(),this.core.options.labels.announceAmSelected??`AM selected`),this.emitter.emit(`select:am`,{});let n=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit(`update`,{hour:n?.value,minutes:r?.value,type:`AM`})}))}handlePmClick(){let e=this.core.getPM();e&&this.cleanupHandlers.push(Cz(e,()=>{if(this.core.isDestroyed)return;let t=this.core.getAM();e.classList.add(`active`),t?.classList.remove(`active`),xz(e,!0),xz(t,!1),bz(this.core.getModalElement(),this.core.options.labels.announcePmSelected??`PM selected`),this.emitter.emit(`select:pm`,{});let n=this.core.getHour(),r=this.core.getMinutes();this.emitter.emit(`update`,{hour:n?.value,minutes:r?.value,type:`PM`})}))}handleSwitchViewButton(){let e=this.core.getKeyboardClockIcon();e&&this.cleanupHandlers.push(Cz(e,()=>{this.core.isDestroyed||this.emitter.emit(`switch:view`,{})}))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},Dz=(e,t,n)=>Math.max(t,Math.min(n,e)),Oz=(e,t)=>{if(e===``)return``;let n=parseInt(e,10);return Number.isNaN(n)?``:Dz(n,+!!t,t?12:23).toString().padStart(2,`0`)},kz=e=>{if(e===``)return``;let t=parseInt(e,10);return Number.isNaN(t)?``:Dz(t,0,59).toString().padStart(2,`0`)},Az=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleHourEvents(){let e=this.core.getHour();if(!e)return;let t=()=>{if(this.core.isDestroyed)return;e.classList.add(`active`);let t=this.core.getMinutes();t?.classList.remove(`active`),this.emitter.emit(`select:hour`,{hour:e.value});let n=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e.value,minutes:t?.value,type:n?.textContent||void 0})};e.addEventListener(`click`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`click`,t));let n=e.value,r=()=>{if(this.core.isDestroyed||e.hasAttribute(`readonly`))return;let t=this.core.options.clock.type===`12h`,r=Oz(e.value,t);if(e.value=r,e.setAttribute(`aria-valuenow`,r),e.value!==n){n=e.value,this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:hour`,{hour:e.value});let t=this.core.getMinutes(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e.value,minutes:t?.value,type:r?.textContent||void 0})}};e.addEventListener(`blur`,r),this.cleanupHandlers.push(()=>e.removeEventListener(`blur`,r))}handleMinutesEvents(){let e=this.core.getMinutes();if(!e)return;let t=()=>{if(this.core.isDestroyed)return;e.classList.add(`active`);let t=this.core.getHour();t?.classList.remove(`active`),this.emitter.emit(`select:minute`,{minutes:e.value});let n=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:t?.value,minutes:e.value,type:n?.textContent||void 0})};e.addEventListener(`click`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`click`,t));let n=e.value,r=()=>{if(this.core.isDestroyed||e.hasAttribute(`readonly`))return;let t=kz(e.value);if(e.value=t,e.setAttribute(`aria-valuenow`,t),e.value!==n){n=e.value,this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:minute`,{minutes:e.value});let t=this.core.getHour(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:t?.value,minutes:e.value,type:r?.textContent||void 0})}};e.addEventListener(`blur`,r),this.cleanupHandlers.push(()=>e.removeEventListener(`blur`,r))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},jz=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleOpenOnEnterFocus(){let e=this.core.getInput();if(!e)return;let t=e=>{e.key===`Enter`&&!this.core.isDestroyed&&!this.core.isOpen&&this.emitter.emit(`show`,{})};e.addEventListener(`keydown`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,t))}handleEscClick(){if(AR()===!1)return;let e=e=>{this.core.isDestroyed||this.core.isOpen&&e.key===`Escape`&&this.emitter.emit(`cancel`,{})};document.addEventListener(`keydown`,e),this.cleanupHandlers.push(()=>document.removeEventListener(`keydown`,e))}handleKeyboardInput(){let e=this.core.getHour(),t=this.core.getMinutes(),n=[`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`];if(e){let t=t=>{if(this.core.isDestroyed||!n.includes(t.key))return;t.preventDefault();let r=parseInt(e.value)||0,i=parseInt(e.getAttribute(`max`)||`23`),a=+(this.core.options.clock.type===`12h`),o=this.computeSpinValue(t.key,r,a,i,3);e.value=o.toString().padStart(2,`0`),e.setAttribute(`aria-valuenow`,e.value),e.setAttribute(`aria-valuetext`,e.value),bz(this.core.getModalElement(),`${this.core.options.labels.announceHour??`Hour`}: ${e.value}`),this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:hour`,{hour:e.value});let s=this.core.getMinutes(),c=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e.value,minutes:s?.value,type:c?.textContent||void 0})};e.addEventListener(`keydown`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,t))}if(t){let e=e=>{if(this.core.isDestroyed||!n.includes(e.key))return;e.preventDefault();let r=parseInt(t.value)||0,i=this.computeSpinValue(e.key,r,0,59,5);t.value=i.toString().padStart(2,`0`),t.setAttribute(`aria-valuenow`,t.value),t.setAttribute(`aria-valuetext`,t.value),bz(this.core.getModalElement(),`${this.core.options.labels.announceMinute??`Minutes`}: ${t.value}`),this.emitter.emit(`animation:clock`,{}),this.emitter.emit(`select:minute`,{minutes:t.value});let a=this.core.getHour(),o=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:a?.value,minutes:t.value,type:o?.textContent||void 0})};t.addEventListener(`keydown`,e),this.cleanupHandlers.push(()=>t.removeEventListener(`keydown`,e))}}computeSpinValue(e,t,n,r,i){switch(e){case`ArrowUp`:return t>=r?n:t+1;case`ArrowDown`:return t<=n?r:t-1;case`Home`:return n;case`End`:return r;case`PageUp`:return Math.min(r,t+i);case`PageDown`:return Math.max(n,t-i);default:return t}}focusTrapHandler(){if(AR()===!1)return;let e=this.core.getWrapper();if(!e)return;let t=t=>{if(this.core.isDestroyed||t.key!==`Tab`)return;let n=e.querySelectorAll(`button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])`),r=[];if(n.forEach(e=>{e.getAttribute(`aria-disabled`)!==`true`&&(e.hasAttribute(`disabled`)||e.hidden||e.getAttribute(`aria-hidden`)!==`true`&&(e.offsetParent===null&&e.getClientRects().length===0||r.push(e)))}),r.length===0)return;let i=r[0],a=r[r.length-1];t.shiftKey&&document.activeElement===i?(a?.focus(),t.preventDefault()):!t.shiftKey&&document.activeElement===a&&(i?.focus(),t.preventDefault())};e.addEventListener(`keydown`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,t))}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},Mz=class{core;emitter;cleanupHandlers=[];constructor(e,t){this.core=e,this.emitter=t}handleBackdropClick(){let e=this.core.getModalElement();if(!e)return;let t=t=>{this.core.isDestroyed||t.target===e&&this.emitter.emit(`cancel`,{})};e.addEventListener(`click`,t),this.cleanupHandlers.push(()=>e.removeEventListener(`click`,t))}handleMoveHand(){if(AR()===!1)return;let e=e=>{this.core.isDestroyed||e.preventDefault()};document.addEventListener(`mousedown`,e,!1),document.addEventListener(`touchstart`,e,{passive:!1}),this.cleanupHandlers.push(()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)})}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},Nz=class{buttonHandlers;inputHandlers;keyboardHandlers;modalHandlers;constructor(e,t){this.buttonHandlers=new Ez(e,t),this.inputHandlers=new Az(e,t),this.keyboardHandlers=new jz(e,t),this.modalHandlers=new Mz(e,t)}handleOpenOnClick(){this.buttonHandlers.handleOpenOnClick()}handleOpenOnEnterFocus(){this.keyboardHandlers.handleOpenOnEnterFocus()}handleCancelButton(){this.buttonHandlers.handleCancelButton()}handleOkButton(){this.buttonHandlers.handleOkButton()}handleBackdropClick(){this.modalHandlers.handleBackdropClick()}handleEscClick(){this.keyboardHandlers.handleEscClick()}handleAmClick(){this.buttonHandlers.handleAmClick()}handlePmClick(){this.buttonHandlers.handlePmClick()}handleHourEvents(){this.inputHandlers.handleHourEvents()}handleMinutesEvents(){this.inputHandlers.handleMinutesEvents()}handleKeyboardInput(){this.keyboardHandlers.handleKeyboardInput()}focusTrapHandler(){this.keyboardHandlers.focusTrapHandler()}handleMoveHand(){this.modalHandlers.handleMoveHand()}handleSwitchViewButton(){this.buttonHandlers.handleSwitchViewButton()}destroy(){this.buttonHandlers.destroy(),this.inputHandlers.destroy(),this.keyboardHandlers.destroy(),this.modalHandlers.destroy()}},Pz=class{emitter;getClockSystem;setHoursToClock;setMinutesToClock;updateAmPm;convertDisabledTime;constructor(e,t,n,r,i,a){this.emitter=e,this.getClockSystem=t,this.setHoursToClock=n,this.setMinutesToClock=r,this.updateAmPm=i,this.convertDisabledTime=a}setup(){this.emitter.on(`select:hour`,({hour:e})=>{this.emitter.emit(`animation:clock`,{}),this.setHoursToClock(e||null)}),this.emitter.on(`select:minute`,({minutes:e})=>{this.emitter.emit(`animation:clock`,{}),this.setMinutesToClock(e||null)}),this.emitter.on(`select:am`,()=>{this.updateAmPm()}),this.emitter.on(`select:pm`,()=>{this.updateAmPm()}),this.emitter.on(`animation:start`,()=>{this.getClockSystem()?.blockInteractions()}),this.emitter.on(`animation:end`,()=>{this.getClockSystem()?.unblockInteractions()}),this.emitter.on(`range:switch`,e=>{this.refreshDisabledTimeForRange(e.disabledTime)})}refreshDisabledTimeForRange(e){let t=this.getClockSystem();if(!t)return;let n=this.convertDisabledTime(),r=n;if(e){let t=[...n?.hours||[],...e.hours||[]],i=[...n?.minutes||[],...e.minutes||[]];r={...n,hours:t.length>0?t:void 0,minutes:i.length>0?i:void 0,rangeFromType:e.fromType,rangeFromHour:e.fromHour}}t.updateDisabledTime(r)}},Fz=/^(1[0-2]|[1-9]):([0-5][0-9])\s*(AM|PM)$/i,Iz=/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/,Lz=class{static angleToIndex(e,t,n){let r=Math.round(e/30)%12;if(t===`24h`){if(n){let e=r+12;return e===12?0:e}return r===0?12:r}return r===0?12:r}static indexToValue(e,t){if(t===`24h`)return e.toString().padStart(2,`0`);let n=e;return n===0&&(n=12),n>12&&(n-=12),n.toString().padStart(2,`0`)}static indexToAngle(e,t){return t===`24h`?e>=12?(e-12)%12*30:e%12*30:(e===0?12:e)%12*30}static isDisabled(e,t,n){return n?n.isInterval&&n.intervals&&n.clockType?this.isDisabledByInterval(e,t,n):n.rangeFromType!==void 0&&n.rangeFromHour!==void 0?this.isDisabledForRange12h(e,t,n):n.hours?n.hours.some(t=>String(t)===e||Number(t)===Number(e)||t===e):!1:!1}static isDisabledForRange12h(e,t,n){let r=n.rangeFromType,i=n.rangeFromHour,a=parseInt(e,10);return r===null||i===void 0?!1:t===`AM`&&r===`PM`?!0:t===`AM`&&r===`AM`?i===12?!1:a===12||a<i:t===`PM`&&r===`AM`?!1:t===`PM`&&r===`PM`?i===12?!1:a===12||a<i:!1}static isDisabledByInterval(e,t,n){if(!n.intervals)return!1;for(let r=0;r<60;r++){let i=r.toString().padStart(2,`0`);if(!this.isTimeInIntervals(e,i,t,n.intervals,n.clockType))return!1}return!0}static isTimeInIntervals(e,t,n,r,i){let a=pR(i===`12h`?`${e}:${t} ${n}`:`${e}:${t}`,i);for(let e of r){let[t,n]=e.split(`-`).map(e=>e.trim()),r=pR(t,i),o=pR(n,i);if(a>=r&&a<=o)return!0}return!1}static findNearestValid(e,t,n,r){let i=t===`24h`?23:12;for(let a=0;a<=i;a++){let o=a===0?[e]:[e+a,e-a];for(let e of o){let a=e;a<0&&(a+=i+1),a>i&&(a%=i+1);let o=this.indexToValue(a,t);if(!this.isDisabled(o,n,r))return a}}return e}},Rz=class{static angleToIndex(e){return Math.round(e/6)%60}static indexToValue(e){return e.toString().padStart(2,`0`)}static indexToAngle(e){return e%60*6}static isDisabled(e,t,n,r,i){return r?r.isInterval&&r.intervals?this.isDisabledByInterval(e,t,n,r,i):r.rangeFromType!==void 0&&r.rangeFromHour!==void 0?this.isDisabledForRange12h(e,t,n,r):r.rangeFromHour!==void 0&&parseInt(t,10)!==r.rangeFromHour?!1:r.minutes?r.minutes.some(t=>String(t)===e||Number(t)===Number(e)||t===e):!1:!1}static isDisabledForRange12h(e,t,n,r){let i=r.rangeFromType,a=r.rangeFromHour,o=parseInt(t,10),s=parseInt(e,10);if(i===null||a===void 0)return!1;let c=r.minutes||[],l=c.length>0?parseInt(c[c.length-1],10)+1:0;return n===`AM`&&i===`PM`?!0:n===`PM`&&i===`AM`?!1:o===a||o===12&&a===12||n===i&&o===a?s<l:!1}static isDisabledByInterval(e,t,n,r,i){if(!r.intervals)return!1;let a=pR(i===`12h`?`${t}:${e} ${n}`:`${t}:${e}`,i);for(let e of r.intervals){let[t,n]=e.split(`-`).map(e=>e.trim()),r=pR(t,i),o=pR(n,i);if(a>=r&&a<=o)return!0}return!1}static findNearestValid(e,t,n,r,i){for(let a=0;a<60;a++){let o=a===0?[e]:[e+a,e-a];for(let e of o){let a=e;a<0&&(a+=60),a>=60&&(a%=60);let o=this.indexToValue(a);if(!this.isDisabled(o,t,n,r,i))return a}}return e}},zz=class{static normalizeAngle(e){let t=e%360;return t<0&&(t+=360),t}static calculateRawAngle(e,t){let n=e.x-t.x,r=e.y-t.y,i=Math.atan2(r,n)*180/Math.PI+90;return this.normalizeAngle(i)}static snapToIncrement(e,t){let n=Math.round(e/t)*t;return this.normalizeAngle(n)}static calculateDistance(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}static isInnerCircle(e,t){return e<t*.75}static calculateShortestPath(e,t){let n=this.normalizeAngle(e),r=this.normalizeAngle(t)-n,i=r>=0?r:r+360,a=r<=0?r:r-360;return e+(Math.abs(i)<Math.abs(a)?i:a)}},Bz=class{config;currentAngle=0;tipsCache=new Map;cachedDimensions=new Map;constructor(e){this.config=e}getCachedDimensions(e){let t=this.cachedDimensions.get(e);if(!t){let n=(e.offsetWidth-32)/2;t={width:n,height:(e.offsetHeight-32)/2,radius:n-9},this.cachedDimensions.set(e,t)}return t}setHandAngle(e){let t=zz.calculateShortestPath(this.currentAngle,e);Math.abs(this.currentAngle-t)<.01||(this.currentAngle=t,this.config.clockHand.style.transform=`rotateZ(${t}deg)`)}animateToAngle(e){let t=zz.calculateShortestPath(this.currentAngle,e);if(this.currentAngle=t,wz()){this.config.clockHand.style.transform=`rotateZ(${t}deg)`;return}this.config.tipsWrapper.classList.add(`tp-ui-tips-animation`),this.config.clockHand.style.transform=`rotateZ(${t}deg)`,setTimeout(()=>{this.config.tipsWrapper.classList.remove(`tp-ui-tips-animation`)},401)}setActiveValue(e){let t=[this.config.tipsWrapper];this.config.tipsWrapperFor24h&&t.push(this.config.tipsWrapperFor24h),t.forEach(t=>{t.querySelectorAll(`.tp-ui-value-tips, .tp-ui-value-tips-24h`).forEach(t=>{let n=t;n.textContent===e||Number(n.textContent)===Number(e)?n.classList.add(`active`):n.classList.remove(`active`)})})}renderTips(e,t,n,r,i,a=!0,o,s=``,c=`12`){if(AR()===!1)return;let l=o||this.config.tipsWrapper;a&&(l.innerHTML=``,this.tipsCache.clear());let{width:u,height:d,radius:f}=this.getCachedDimensions(l),p=document.createDocumentFragment(),m=`${t}-${this.config.theme||`default`}`;e.forEach((a,o)=>{let l=`${m}-${a}`,h=this.tipsCache.get(l);h||(h=this.createTip(a,t,i),this.tipsCache.set(l,h));let{wrapper:g,tip:_}=h;this.updateTipState(g,_,a,n,r,i,s,c);let v=o*(360/e.length)*(Math.PI/180);g.style.left=`${u+Math.sin(v)*f}px`,g.style.bottom=`${d+Math.cos(v)*f}px`,p.appendChild(g)}),l.appendChild(p)}createTip(e,t,n){if(AR()===!1){let e={};return{wrapper:e,tip:e}}let r=document.createElement(`span`),i=document.createElement(`span`);i.textContent=e,i.tabIndex=-1;let a=n===`24h`&&t.includes(`24`)?`tp-ui-value-tips-24h`:`tp-ui-value-tips`;return i.classList.add(a),r.classList.add(t),r.appendChild(i),{wrapper:r,tip:i}}updateTipState(e,t,n,r,i,a,o,s){e.classList.remove(`tp-ui-tips-disabled`),t.classList.remove(`tp-ui-tips-disabled`),t.tabIndex=-1,this.checkIfDisabled(n,r,i,a,o,s)&&(e.classList.add(`tp-ui-tips-disabled`),t.classList.add(`tp-ui-tips-disabled`))}checkIfDisabled(e,t,n,r,i,a){return n?t===`hours`?Lz.isDisabled(e,i,n):t===`minutes`&&Rz.isDisabled(e,a,i,n,r):!1}setCircleSize(e){e?this.config.circle.classList.remove(`small-circle`):this.config.circle.classList.add(`small-circle`)}setCircle24hMode(e){e?(this.config.circle.classList.add(`tp-ui-circle-hand-24h`),this.config.clockHand.classList.add(`tp-ui-clock-hand-24h`)):(this.config.circle.classList.remove(`tp-ui-circle-hand-24h`),this.config.clockHand.classList.remove(`tp-ui-clock-hand-24h`))}destroy(){this.tipsCache.clear(),this.cachedDimensions.clear(),this.config.tipsWrapper.innerHTML=``}},Vz=class{static processPointerInput(e){let t=zz.calculateRawAngle(e.pointerPosition,e.clockCenter);return e.mode===`hours`?this.processHours(t,e):this.processMinutes(t,e)}static processHours(e,t){let n=t.smoothHourSnap??!0,r;if(n)r=e;else{let n=t.incrementHours*30;r=zz.snapToIncrement(e,n)}let i=zz.calculateDistance(t.pointerPosition,t.clockCenter),a=t.clockType===`24h`&&zz.isInnerCircle(i,t.clockRadius),o=Lz.angleToIndex(r,t.clockType,a),s=Lz.indexToValue(o,t.clockType),c=Lz.isDisabled(s,t.amPm,t.disabledTime);c&&(o=Lz.findNearestValid(o,t.clockType,t.amPm,t.disabledTime));let l=Lz.indexToValue(o,t.clockType),u;return u=n?e:Lz.indexToAngle(o,t.clockType),{angle:u,value:l,index:o,isValid:!c,isInnerCircle:t.clockType===`24h`?a:void 0}}static processMinutes(e,t){let n=t.incrementMinutes*6,r=zz.snapToIncrement(e,n),i=Rz.angleToIndex(r),a=Rz.indexToValue(i),o=t.currentHour||`00`,s=Rz.isDisabled(a,o,t.amPm,t.disabledTime,t.clockType);s&&(i=Rz.findNearestValid(i,o,t.amPm,t.disabledTime,t.clockType));let c=Rz.indexToValue(i);return{angle:Rz.indexToAngle(i),value:c,index:i,isValid:!s}}static valueToAngle(e,t,n){let r=parseInt(e,10);return t===`hours`?Lz.indexToAngle(r,n):Rz.indexToAngle(r)}},Hz=class{state;renderer;clockType;disabledTime;incrementHours;incrementMinutes;smoothHourSnap;isDragging=!1;callbacks;lastProcessedX=null;lastProcessedY=null;constructor(e,t,n,r,i=1,a=1,o=!0,s={}){this.renderer=e,this.state={...t},this.clockType=n,this.disabledTime=r,this.incrementHours=i,this.incrementMinutes=a,this.smoothHourSnap=o,this.callbacks=s}handlePointerMove(e,t,n){if(this.isDragging=!0,this.lastProcessedX===e.x&&this.lastProcessedY===e.y)return;this.lastProcessedX=e.x,this.lastProcessedY=e.y;let r={pointerPosition:e,clockCenter:t,clockRadius:n,mode:this.state.mode,clockType:this.clockType,amPm:this.state.amPm,disabledTime:this.disabledTime,incrementHours:this.incrementHours,incrementMinutes:this.incrementMinutes,smoothHourSnap:this.smoothHourSnap,currentHour:this.state.hour},i=Vz.processPointerInput(r);if(i.isValid){if(this.state.mode===`hours`){let e=this.state.hour;this.state.hour=i.value,this.state.hourAngle=i.angle,this.clockType===`24h`&&i.isInnerCircle!==void 0&&(this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(i.isInnerCircle)),this.callbacks.onHourChange&&e!==i.value&&this.callbacks.onHourChange(i.value)}else{let e=this.state.minute;this.state.minute=i.value,this.state.minuteAngle=i.angle,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1),this.callbacks.onMinuteChange&&e!==i.value&&this.callbacks.onMinuteChange(i.value)}this.renderer.setHandAngle(i.angle),this.renderer.setActiveValue(i.value)}}handlePointerUp(){this.isDragging=!1,this.lastProcessedX=null,this.lastProcessedY=null}snapToNearestHour(){if(this.state.mode!==`hours`)return;let e=Vz.valueToAngle(this.state.hour,`hours`,this.clockType);this.state.hourAngle=e,this.renderer.animateToAngle(e)}switchMode(e){this.state.mode=e;let t=e===`hours`?this.state.hourAngle:this.state.minuteAngle,n=e===`hours`?this.state.hour:this.state.minute;if(e===`hours`&&this.clockType===`24h`){let e=parseInt(n,10),t=e===0||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(t)}else this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.renderer.setHandAngle(t),this.renderer.setActiveValue(n)}setValue(e,t){let n=Vz.valueToAngle(t,e,this.clockType);if(e===`hours`){if(this.state.hour=t,this.state.hourAngle=n,this.clockType===`24h`){let e=parseInt(t,10),n=e===0||e>=13;this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(n)}else this.renderer.setCircle24hMode(!1)}else this.state.minute=t,this.state.minuteAngle=n,this.renderer.setCircleSize(!0),this.renderer.setCircle24hMode(!1);this.state.mode===e&&(this.renderer.setHandAngle(n),this.renderer.setActiveValue(t))}setAmPm(e){this.state.amPm=e}getState(){return{...this.state}}getHour(){return this.state.hour}getMinute(){return this.state.minute}getAmPm(){return this.state.amPm}updateDisabledTime(e){this.disabledTime=e}destroy(){this.renderer.destroy()}},Uz=class{controller;clockFace;isActive=!1;isBlocked=!1;config;cachedRect=null;cachedCenter=null;cachedRadius=null;rafId=null;constructor(e,t,n={}){this.controller=e,this.clockFace=t,this.config=n}attach(){this.clockFace.addEventListener(`mousedown`,this.handlePointerDown),this.clockFace.addEventListener(`touchstart`,this.handlePointerDown,{passive:!1})}detach(){this.clockFace.removeEventListener(`mousedown`,this.handlePointerDown),this.clockFace.removeEventListener(`touchstart`,this.handlePointerDown),this.removeGlobalListeners()}block(){this.isBlocked=!0}unblock(){this.isBlocked=!1}handlePointerDown=e=>{if(kR()||this.isBlocked)return;let t=e.target;t&&t.classList&&t.classList.contains(`tp-ui-tips-disabled`)||(e.preventDefault(),this.isActive=!0,this.cachedRect=this.clockFace.getBoundingClientRect(),this.cachedCenter=this.getClockCenter(),this.cachedRadius=this.getClockRadius(),this.processPointerEvent(e),document.addEventListener(`mousemove`,this.handlePointerMove),document.addEventListener(`touchmove`,this.handlePointerMove,{passive:!1}),document.addEventListener(`mouseup`,this.handlePointerUp),document.addEventListener(`touchend`,this.handlePointerUp))};handlePointerMove=e=>{if(!this.isActive||this.isBlocked)return;let t=this.getTargetElement(e);t&&t.classList&&t.classList.contains(`tp-ui-tips-disabled`)||(e.preventDefault(),this.rafId===null&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null,this.processPointerEvent(e)})))};handlePointerUp=()=>{if(!this.isActive)return;this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.isActive=!1,this.cachedRect=null,this.cachedCenter=null,this.cachedRadius=null,this.controller.handlePointerUp();let{autoSwitchToMinutes:e,isMobileView:t,smoothHourSnap:n,hourElement:r,minutesElement:i}=this.config;n&&r?.classList.contains(`active`)&&this.controller.snapToNearestHour(),this.removeGlobalListeners(),e&&r?.classList.contains(`active`)&&!t?(r.classList.remove(`active`),i?.classList.add(`active`),i?.click(),i?.focus(),r.blur()):i?.classList.contains(`active`)&&this.config.onMinuteCommit&&this.config.onMinuteCommit()};processPointerEvent(e){let t=this.getPointerPosition(e),n=this.cachedCenter||this.getClockCenter(),r=this.cachedRadius||this.getClockRadius();this.controller.handlePointerMove(t,n,r)}getPointerPosition(e){let t=this.cachedRect||this.clockFace.getBoundingClientRect();if(`touches`in e){let n=e.touches[0]||e.changedTouches[0];return{x:n.clientX-t.left,y:n.clientY-t.top}}return{x:e.clientX-t.left,y:e.clientY-t.top}}getTargetElement(e){if(`touches`in e){let t=e.touches[0]||e.changedTouches[0];if(t&&!kR())return document.elementFromPoint(t.clientX,t.clientY)}return e.target}getClockCenter(){let e=this.clockFace.offsetWidth,t=this.clockFace.offsetHeight;return{x:e/2,y:t/2}}getClockRadius(){return this.clockFace.offsetWidth/2}removeGlobalListeners(){AR()!==!1&&(document.removeEventListener(`mousemove`,this.handlePointerMove),document.removeEventListener(`touchmove`,this.handlePointerMove),document.removeEventListener(`mouseup`,this.handlePointerUp),document.removeEventListener(`touchend`,this.handlePointerUp))}},Wz=class{renderer;controller;dragHandlers;clockType;disabledTime;tipsWrapper;tipsWrapperFor24h;constructor(e){this.clockType=e.clockType,this.disabledTime=e.disabledTime,this.tipsWrapper=e.tipsWrapper,this.tipsWrapperFor24h=e.tipsWrapperFor24h;let t={clockFace:e.clockFace,tipsWrapper:e.tipsWrapper,tipsWrapperFor24h:e.tipsWrapperFor24h,clockHand:e.clockHand,circle:e.circle,theme:e.theme};this.renderer=new Bz(t);let n={hour:e.initialHour,minute:e.initialMinute,amPm:e.initialAmPm,hourAngle:this.calculateInitialAngle(`hours`,e.initialHour),minuteAngle:this.calculateInitialAngle(`minutes`,e.initialMinute),mode:`hours`},r={onHourChange:e.onHourChange,onMinuteChange:e.onMinuteChange};this.controller=new Hz(this.renderer,n,e.clockType,e.disabledTime,e.incrementHours||1,e.incrementMinutes||1,e.smoothHourSnap??!0,r),this.dragHandlers=new Uz(this.controller,e.clockFace,e.dragConfig||{})}initialize(){this.dragHandlers.attach(),this.switchToHours()}switchToHours(){this.controller.switchMode(`hours`),this.clockType===`24h`&&this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.remove(`none`),this.renderHourTips();let e=this.controller.getState();this.renderer.setActiveValue(e.hour)}switchToMinutes(){this.controller.switchMode(`minutes`),this.tipsWrapperFor24h&&this.tipsWrapperFor24h.classList.add(`none`),this.renderMinuteTips();let e=this.controller.getState();this.renderer.setActiveValue(e.minute)}setHour(e){this.controller.setValue(`hours`,e)}setMinute(e){this.controller.setValue(`minutes`,e)}setAmPm(e){this.controller.setAmPm(e);let t=this.controller.getState();t.mode===`hours`?(this.renderHourTips(),this.renderer.setHandAngle(t.hourAngle),this.renderer.setActiveValue(t.hour)):(this.renderMinuteTips(),this.renderer.setHandAngle(t.minuteAngle),this.renderer.setActiveValue(t.minute))}getHour(){return this.controller.getHour()}getMinute(){return this.controller.getMinute()}getAmPm(){return this.controller.getAmPm()}updateDisabledTime(e){this.disabledTime=e,this.controller.updateDisabledTime(e),this.controller.getState().mode===`hours`?this.renderHourTips():this.renderMinuteTips()}renderHourTips(){let e=this.controller.getState().amPm;this.clockType===`24h`?(this.renderer.renderTips(qR,`tp-ui-hour-time-12`,`hours`,this.disabledTime,this.clockType,!0,this.tipsWrapper,e),this.tipsWrapperFor24h&&this.renderer.renderTips(KR,`tp-ui-hour-time-24`,`hours`,this.disabledTime,this.clockType,!0,this.tipsWrapperFor24h,e)):this.renderer.renderTips(qR,`tp-ui-hour-time-12`,`hours`,this.disabledTime,this.clockType,!0,void 0,e)}renderMinuteTips(){let e=this.controller.getState(),t=e.amPm,n=e.hour;this.renderer.renderTips(JR,`tp-ui-minutes-time`,`minutes`,this.disabledTime,this.clockType,!0,void 0,t,n)}calculateInitialAngle(e,t){let n=parseInt(t,10);return e===`hours`?n%12*30:n*6}destroy(){this.dragHandlers.detach(),this.controller.destroy()}blockInteractions(){this.dragHandlers.block()}unblockInteractions(){this.dragHandlers.unblock()}},Gz=class{core;emitter;clockSystem=null;constructor(e,t){this.core=e,this.emitter=t}getClockSystem(){return this.clockSystem}initialize(){let e=this.core.getClockFace(),t=this.core.getClockHand(),n=this.core.getCircle();if(!e||!t||!n)return;let r=this.core.options.clock.type===`24h`,i=this.core.getTipsWrapper();if(!i)return;let a=this.core.getHour(),o=this.core.getMinutes(),s={clockFace:e,tipsWrapper:i,tipsWrapperFor24h:r&&this.core.getTipsWrapperFor24h()||void 0,clockHand:t,circle:n,clockType:this.core.options.clock.type||`12h`,disabledTime:this.convertDisabledTime(),initialHour:a?.value||`12`,initialMinute:o?.value||`00`,initialAmPm:this.getAmPmValue(),theme:this.core.options.ui.theme,incrementHours:this.core.options.clock.incrementHours||1,incrementMinutes:this.core.options.clock.incrementMinutes||1,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,timepicker:null,dragConfig:{autoSwitchToMinutes:this.core.options.clock.autoSwitchToMinutes,isMobileView:this.core.isMobileView,smoothHourSnap:this.core.options.clock.smoothHourSnap??!0,hourElement:a,minutesElement:o,onMinuteCommit:()=>{let e=this.core.getMinutes(),t=this.core.getHour(),n=this.core.getActiveTypeMode();this.emitter.emit(`range:minute:commit`,{hour:t?.value??`12`,minutes:e?.value??`00`,type:n?.textContent??void 0})}},onHourChange:e=>{let t=this.core.getHour();t&&(t.value=e,t.setAttribute(`aria-valuenow`,e)),bz(this.core.getModalElement(),`Hour: ${e}`);let n=this.core.getMinutes(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:e,minutes:n?.value,type:r?.textContent||void 0})},onMinuteChange:e=>{let t=this.core.getMinutes();t&&(t.value=e,t.setAttribute(`aria-valuenow`,e)),bz(this.core.getModalElement(),`Minutes: ${e}`);let n=this.core.getHour(),r=this.core.getActiveTypeMode();this.emitter.emit(`update`,{hour:n?.value,minutes:e,type:r?.textContent||void 0})}};this.clockSystem=new Wz(s),this.clockSystem.initialize()}convertDisabledTime(){let e=this.core.disabledTime?.value;if(!e)return null;let t;return e.intervals&&(t=Array.isArray(e.intervals)?e.intervals:[e.intervals]),{hours:e.hours,minutes:e.minutes,isInterval:e.isInterval,intervals:t,clockType:e.clockType}}getAmPmValue(){if(this.core.options.clock.type===`24h`)return``;let e=this.core.getActiveTypeMode();if(e){let t=e.textContent?.trim();if(t===`AM`||t===`PM`)return t}let t=this.core.getAM();return this.core.options.range?.enabled===!0?t?.classList.contains(`active`)?`AM`:``:t?.classList.contains(`active`)?`AM`:`PM`}destroy(){this.clockSystem&&=(this.clockSystem.destroy(),null)}},Kz=class{core;constructor(e){this.core=e}removeCircleClockClasses24h(){let e=this.core.getCircle(),t=this.core.getClockHand();e?.classList.remove(`tp-ui-circle-hand-24h`),t?.classList.remove(`tp-ui-clock-hand-24h`)}setCircleClockClasses24h(){let e=this.core.getCircle(),t=this.core.getClockHand();e&&e.classList.add(`tp-ui-circle-hand-24h`),t&&t.classList.add(`tp-ui-clock-hand-24h`)}setOnStartCSSClassesIfClockType24h(){if(this.core.options.clock.type===`24h`){let e=this.core.getInput();if(!e)return;let t;e.value.length>0&&(t=e.value.split(`:`)[0]),t&&(Number(t)>12||Number(t)===0)&&this.setCircleClockClasses24h()}}setBgColorToCircleWithMinutesTips(){let e=this.core.getMinutes(),t=this.core.getCircle();if(!(!e||!t)&&e.value&&JR.includes(e.value)){let e=getComputedStyle(t).getPropertyValue(`--timepicker-primary`).trim();e&&(t.style.backgroundColor=e),t.classList.remove(`small-circle`)}}removeBgColorToCirleWithMinutesTips(){let e=this.core.getMinutes(),t=this.core.getCircle();!e||!t||e.value&&JR.includes(e.value)||(t.style.backgroundColor=``,t.classList.add(`small-circle`))}setClassActiveToHourOnOpen(){this.core.options.ui.mobile||this.core.isMobileView||this.core.getHour()?.classList.add(uz)}toggleClassActiveToValueTips(e,t){if(e)return;let n=this.core.getAllValueTips();if(!n)return;let r=n.find(e=>Number(e.innerText)===Number(t));n.forEach(e=>{e.classList.remove(uz),e.setAttribute(`aria-selected`,`false`)}),r!==void 0&&(r.classList.add(uz),r.setAttribute(`aria-selected`,`true`))}},qz=class{getClockSystem;styleHandler;getAmPmValue;clockType;constructor(e,t,n,r){this.getClockSystem=e,this.styleHandler=t,this.getAmPmValue=n,this.clockType=r}setMinutesToClock(e){let t=this.getClockSystem();t&&(this.styleHandler.removeBgColorToCirleWithMinutesTips(),e&&t.setMinute(e),t.switchToMinutes())}setHoursToClock(e){let t=this.getClockSystem();t&&(e&&t.setHour(e),t.switchToHours())}setTransformToCircleWithSwitchesHour(e){let t=this.getClockSystem();!t||!e||t.setHour(e)}setTransformToCircleWithSwitchesMinutes(e){let t=this.getClockSystem();!t||!e||t.setMinute(e)}updateAmPm(){let e=this.getClockSystem();if(!e||this.clockType===`24h`)return;let t=this.getAmPmValue();t!==``&&e.setAmPm(t)}},Jz=class{systemInitializer;styleHandler;timeHandler;eventHandler;constructor(e,t){this.systemInitializer=new Gz(e,t),this.styleHandler=new Kz(e);let n=e.options.clock.type||`12h`;this.timeHandler=new qz(()=>this.systemInitializer.getClockSystem(),this.styleHandler,()=>this.systemInitializer.getAmPmValue(),n),this.eventHandler=new Pz(t,()=>this.systemInitializer.getClockSystem(),e=>this.timeHandler.setHoursToClock(e),e=>this.timeHandler.setMinutesToClock(e),()=>this.timeHandler.updateAmPm(),()=>this.systemInitializer.convertDisabledTime()),this.eventHandler.setup()}initializeClockSystem(){this.systemInitializer.initialize()}destroyClockSystem(){this.systemInitializer.destroy()}removeCircleClockClasses24h(){this.styleHandler.removeCircleClockClasses24h()}setCircleClockClasses24h(){this.styleHandler.setCircleClockClasses24h()}setOnStartCSSClassesIfClockType24h(){this.styleHandler.setOnStartCSSClassesIfClockType24h()}setBgColorToCircleWithMinutesTips=()=>{this.styleHandler.setBgColorToCircleWithMinutesTips()};removeBgColorToCirleWithMinutesTips=()=>{this.styleHandler.removeBgColorToCirleWithMinutesTips()};setClassActiveToHourOnOpen=()=>{this.styleHandler.setClassActiveToHourOnOpen()};setMinutesToClock=e=>{this.timeHandler.setMinutesToClock(e)};setHoursToClock=e=>{this.timeHandler.setHoursToClock(e)};setTransformToCircleWithSwitchesHour=e=>{this.timeHandler.setTransformToCircleWithSwitchesHour(e)};setTransformToCircleWithSwitchesMinutes=e=>{this.timeHandler.setTransformToCircleWithSwitchesMinutes(e)};updateAmPm=()=>{this.timeHandler.updateAmPm()};toggleClassActiveToValueTips=e=>{let t=this.systemInitializer.getClockSystem()!==null;this.styleHandler.toggleClassActiveToValueTips(t,e)};destroy(){this.destroyClockSystem()}},Yz=class{core;emitter;cleanupHandlers=[];wasCleared=!1;constructor(e,t){this.core=e,this.emitter=t}init(){if(!this.core.options.ui.clearButton)return;let e=this.getClearButton();e&&(this.cleanupHandlers.push(Cz(e,()=>{this.core.isDestroyed||this.handleClearClick()})),this.setupInternalEventListeners())}setupInternalEventListeners(){mR(this.emitter,this.cleanupHandlers,`update`,()=>{this.updateClearButtonState()}),mR(this.emitter,this.cleanupHandlers,`open`,()=>{this.updateClearButtonState()}),mR(this.emitter,this.cleanupHandlers,`select:hour`,()=>{this.updateClearButtonState(),this.reenableConfirmIfCleared()}),mR(this.emitter,this.cleanupHandlers,`select:minute`,()=>{this.updateClearButtonState(),this.reenableConfirmIfCleared()})}handleClearClick(){let e=this.core.getInput()?.value||null;this.clearTimeValue(),this.resetClockToNeutral(),this.disableConfirmButton(),this.wasCleared=!0,bz(this.core.getModalElement(),`Time cleared`),this.emitter.emit(`clear`,{previousValue:e}),this.emitter.emit(`update`,{hour:void 0,minutes:void 0,type:void 0});let{callbacks:t}=this.core.options;t.onClear&&t.onClear({previousValue:e})}clearTimeValue(){let e=this.core.options.clearBehavior?.clearInput!==!1,t=this.core.getInput();t&&e&&(t.value=``),this.core.setDegreesHours(null),this.core.setDegreesMinutes(null);let n=GR.getClearHandler(`range`);n&&n(this.core,this.emitter);let r=GR.getClearHandler(`timezone`);r&&r(this.core,this.emitter)}resetClockToNeutral(){let e=this.core.options.clock.type,t=e===`12h`?`PM`:void 0,n=this.core.getHour(),r=this.core.getMinutes();n&&(n.value=`12`,n.removeAttribute(`aria-valuenow`)),r&&(r.value=`00`,r.removeAttribute(`aria-valuenow`));let i=this.core.getClockHand();if(i){let e=i.style.transition;i.style.transition=`none`,i.style.transform=`rotateZ(0deg)`,i.offsetHeight,requestAnimationFrame(()=>{i.style.transition=e})}if(this.removeActiveStates(),n&&n.click(),e===`12h`&&t){let e=this.core.getAM(),t=this.core.getPM();e?.classList.remove(`active`),t?.classList.remove(`active`),e?.setAttribute(`aria-pressed`,`false`),t?.setAttribute(`aria-pressed`,`false`),t?.classList.add(`active`),t?.setAttribute(`aria-pressed`,`true`)}this.emitter.emit(`animation:clock`,{})}removeActiveStates(){this.core.getAllValueTips().forEach(e=>{e.classList.remove(`active`),e.removeAttribute(`aria-selected`)});let e=this.core.getHour(),t=this.core.getMinutes();e?.removeAttribute(`aria-valuenow`),t?.removeAttribute(`aria-valuenow`)}disableConfirmButton(){let e=this.core.getOkButton();e&&(e.classList.add(`disabled`),e.setAttribute(`aria-disabled`,`true`))}updateClearButtonState(){let e=this.getClearButton();if(!e)return;let t=this.core.getInput(),n=t?.value&&t.value.trim()!==``,r=this.core.getHour(),i=this.core.getMinutes(),a=this.core.getActiveTypeMode(),o=this.core.options.clock.type,s=r?.value||``,c=i?.value||``,l=a?.textContent||``,u=n||!(o===`12h`?s===`12`&&c===`00`&&l===`PM`:s===`12`&&c===`00`);e.classList.toggle(`disabled`,!u),e.setAttribute(`aria-disabled`,String(!u))}reenableConfirmIfCleared(){if(!this.wasCleared)return;let e=this.core.getOkButton();e&&(e.classList.remove(`disabled`),e.setAttribute(`aria-disabled`,`false`),this.wasCleared=!1)}getClearButton(){return this.core.getModalElement()?.querySelector(`.tp-ui-clear-btn`)||null}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[]}},Xz=class{animation;modal;config;theme;validation;events;clock;clearButton;plugins=new Map;constructor(e,t){this.animation=new NR(e,t),this.modal=new az(e,t),this.config=new gz(e,t),this.theme=new _z(e,t),this.validation=new Tz(e,t),this.events=new Nz(e,t),this.clock=new Jz(e,t),this.clearButton=new Yz(e,t),GR.getAll().forEach(n=>{let r=n.factory(e,t);this.plugins.set(n.name,r)})}getPlugin(e){return this.plugins.get(e)}destroy(){this.animation.destroy(),this.modal.destroy(),this.config.destroy(),this.theme.destroy(),this.validation.destroy(),this.events.destroy(),this.clock.destroy(),this.clearButton.destroy(),this.plugins.forEach(e=>e.destroy()),this.plugins.clear()}},Zz=`is-rippling`,Qz=`ripple-hold`,$z=null,eB=(e,t)=>{let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>{e(...r)},t)}},tB=[[`onOpen`,`open`],[`onCancel`,`cancel`],[`onConfirm`,`confirm`],[`onUpdate`,`update`],[`onSelectHour`,`select:hour`],[`onSelectMinute`,`select:minute`],[`onSelectAM`,`select:am`],[`onSelectPM`,`select:pm`],[`onError`,`error`],[`onTimezoneChange`,`timezone:change`],[`onRangeConfirm`,`range:confirm`],[`onRangeSwitch`,`range:switch`],[`onRangeValidation`,`range:validation`],[`onClear`,`clear`]],nB=[{needed:e=>e.ui.mode===`wheel`||e.ui.mode===`compact-wheel`,name:`wheel`,message:`WheelPlugin is not registered. Import and register it: PluginRegistry.register(WheelPlugin)`},{needed:e=>!!e.range?.enabled,name:`range`,message:`RangePlugin is not registered. Import and register it: PluginRegistry.register(RangePlugin)`},{needed:e=>!!e.timezone?.enabled,name:`timezone`,message:`TimezonePlugin is not registered. Import and register it: PluginRegistry.register(TimezonePlugin)`}],rB=class e{static EXPANDED_EXCLUDED=[`tp-ui-select-time`,`tp-ui-mobile-clock-wrapper`,`tp-ui-wrapper`];core;managers;emitter;eventsClickMobileHandler=()=>{};mutliEventsMoveHandler=()=>{};unmountTimeouts=[];constructor(e,t,n){this.core=e,this.managers=t,this.emitter=n}init(){if(!this.core.isDestroyed&&!this.core.isInitialized){try{this.managers.config.updateInputValueWithCurrentTimeOnStart(),this.managers.validation.checkDisabledValuesOnStart()}catch{this.core.setIsDestroyed(!0);return}this.managers.theme.setTimepickerClassToElement(),this.managers.theme.setInputClassToInputElement(),this.managers.theme.setDataOpenToInputIfDoesntExistInWrapper(),this.managers.theme.setClassTopOpenElement(),this.managers.config.getDisableTime(),this.core.options.ui.inline?.enabled||this.managers.events.handleOpenOnClick(),this.managers.events.handleOpenOnEnterFocus(),SR(this.core,this.emitter),this.core.setIsInitialized(!0)}}mount(){this.core.isDestroyed||this.core.isOpen||(this.core.isInitialized||this.init(),this.eventsBundle())}unmount(e){let t=eB((...e)=>{if(e.length>2)return;let[t]=e.filter(e=>typeof e==`boolean`),[n]=e.filter(e=>typeof e==`function`);this.core.setIsMobileView(!!this.core.options.ui.mobile);let r=this.core.getModalElement();t&&r&&this.core.getOkButton()?.click(),this.core.setIsTouchMouseMove(!1),this.core.setIsOpen(!1),this.removeEventListeners(),xR(this.core.options)&&this.managers.getPlugin(`wheel`)?.detachPopover?.(),r&&this.managers.animation.removeAnimationToClose(),this.core.getOpenElement().forEach(e=>e?.classList.remove(`disabled`));let i=setTimeout(()=>{this.managers.modal.unlockScroll()},MR.SCROLLBAR_RESTORE);this.unmountTimeouts.push(i);let a=setTimeout(()=>{let e=this.core.getInput();this.core.options.behavior.focusInputAfterClose&&e?.focus();let t=this.core.getModalElement();t&&t.remove(),this.core.setIsModalRemove(!0)},MR.MODAL_REMOVE);this.unmountTimeouts.push(a),n&&n()},this.core.options.behavior.delayHandler||MR.DEFAULT_DELAY);e?t(e):t()}destroy(e){if(this.core.isDestroyed)return;this.clearUnmountTimeouts();let{keepInputValue:t=!1,callback:n}=typeof e==`function`?{callback:e}:e||{},r=this.core.getInput(),i=t?r?.value:null;this.removeEventListeners(),this.core.getModalElement()?.remove(),this.core.getOpenElement()?.forEach(e=>{e&&e.classList.remove(`disabled`,`active`,`tp-ui-open-element`)}),r&&(r.classList.remove(`tp-ui-invalid-format`,`invalid-value`,`error`,`active`,`tp-ui-input`),r.removeAttribute(`data-open`),r.removeAttribute(`data-owner-id`),t&&i&&(r.value=i));let a=this.core.element;a&&(a.classList.remove(`error`,`active`,`disabled`),a.removeAttribute(`data-owner-id`),a.removeAttribute(`data-open`),this.core.options.ui.cssClass&&a.classList.remove(this.core.options.ui.cssClass)),a?.querySelectorAll(`.tp-ui-invalid-text`)?.forEach(e=>e.remove()),this.mutliEventsMoveHandler=()=>{},this.eventsClickMobileHandler=()=>{},this.core.reset(),this.managers.destroy(),this.emitter.clear(),this.managers.modal.unlockScroll(),n&&n()}eventsBundle(){if(this.core.isDestroyed||!this.core.isModalRemove)return;this.clearUnmountTimeouts(),this.core.setIsOpen(!0),this.core.setIsModalRemove(!1),this.setupValidation(),this.disableOpenElements(),this.setupModal(),this.applyExpandedState(),this.managers.modal.setFlexEndToFooterIfNoKeyboardIcon(),this.applyThemeDeferred(),this.managers.animation.setAnimationToOpen(),this.managers.config.getInputValueOnOpenAndSet();let e=yR(this.core.options)&&GR.has(`wheel`);CR(this.core,this.emitter),this.initClockOrWheel(e),this.initOptionalPlugins(e),this.bindEventHandlers(e),this.finalizeModal(e),xR(this.core.options)&&this.managers.getPlugin(`wheel`)?.attachPopover?.(),this.managers.modal.setShowClassToBackdrop()}setupValidation(){this.managers.validation.setErrorHandler(),this.managers.validation.removeErrorHandler()}disableOpenElements(){this.core.options.ui.inline?.enabled||(this.core.getOpenElement().forEach(e=>e?.classList.add(`disabled`)),xR(this.core.options)||this.core.getInput()?.blur())}setupModal(){this.managers.modal.setScrollbarOrNot(),this.managers.modal.setModalTemplate(),this.managers.modal.setNormalizeClass(),this.managers.modal.removeBackdrop()}applyExpandedState(){if(this.core.isMobileView){this.managers.config.updateClockFaceAccessibility(!0);return}let t=this.core.getModalElement();t&&(t.querySelector(`.tp-ui-mobile-clock-wrapper`)?.classList.add(`expanded`),t.querySelector(`.tp-ui-wrapper`)?.classList.add(`expanded`),t.querySelectorAll(`*`).forEach(t=>{e.EXPANDED_EXCLUDED.some(e=>t.classList.contains(e))||t.classList.add(`expanded`)}))}applyThemeDeferred(){let e=setTimeout(()=>{this.managers.theme.setTheme();let e=this.core.getWrapper();e&&this.core.options.ui.cssClass&&e.classList.add(this.core.options.ui.cssClass)},0);this.unmountTimeouts.push(e)}initClockOrWheel(e){if(e){let e=this.managers.getPlugin(`wheel`);e&&e.init()}else this.managers.clock.initializeClockSystem(),this.managers.clock.setOnStartCSSClassesIfClockType24h(),this.managers.clock.setClassActiveToHourOnOpen()}initOptionalPlugins(e){let t=this.managers.getPlugin(`timezone`);t&&t.init();let n=this.managers.getPlugin(`range`);n&&!e&&n.init()}bindEventHandlers(e){this.managers.events.handleCancelButton(),this.managers.events.handleOkButton(),this.managers.clearButton.init(),e||(this.managers.events.handleHourEvents(),this.managers.events.handleMinutesEvents()),this.managers.events.handleKeyboardInput(),this.core.options.ui.enableSwitchIcon&&!e&&this.managers.events.handleSwitchViewButton(),this.core.options.clock.type!==`24h`&&!bR(this.core.options)&&(this.managers.events.handleAmClick(),this.managers.events.handlePmClick()),this.core.options.behavior.focusTrap&&this.managers.events.focusTrapHandler(),this.core.options.ui.inline?.enabled||(this.managers.events.handleEscClick(),xR(this.core.options)||e&&this.core.options.wheel?.ignoreOutsideClick||this.managers.events.handleBackdropClick())}finalizeModal(e){let t=this.core.getModalElement();if(t&&vR(t),!e){let e=this.core.getClockFace();e&&typeof requestAnimationFrame<`u`&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{e?.classList.add(`scale-in`)})})}}clearUnmountTimeouts(){this.unmountTimeouts.forEach(clearTimeout),this.unmountTimeouts=[]}removeEventListeners(){AR()!==!1&&(lz.split(` `).forEach(e=>{document.removeEventListener(e,this.mutliEventsMoveHandler,!1)}),document.removeEventListener(`mousedown`,this.eventsClickMobileHandler))}},iB=class{events=new Map;on(e,t){this.events.has(e)||this.events.set(e,new Set),this.events.get(e).add(t)}once(e,t){let n=r=>{t(r),this.events.get(e)?.delete(n)};n.__originalHandler=t,this.on(e,n)}off(e,t){if(!t){this.events.delete(e);return}let n=this.events.get(e);n&&n.forEach(e=>{(e===t||e.__originalHandler===t)&&n.delete(e)})}emit(e,t){let n=this.events.get(e);n&&[...n].forEach(e=>{e(t)})}clear(){this.events.clear()}hasListeners(e){return(this.events.get(e)?.size??0)>0}},aB={clock:{type:`12h`,incrementHours:1,incrementMinutes:1,autoSwitchToMinutes:!0,disabledTime:void 0,currentTime:void 0},ui:{mode:`clock`,theme:`basic`,animation:!0,backdrop:!0,mobile:!1,enableSwitchIcon:!1,editable:!1,enableScrollbar:!1,cssClass:void 0,appendModalSelector:``,iconTemplate:``,iconTemplateMobile:``,inline:void 0,clearButton:!1},labels:{am:`AM`,pm:`PM`,ok:`OK`,cancel:`Cancel`,time:`Select time`,mobileTime:`Enter Time`,mobileHour:`Hour`,mobileMinute:`Minute`,clear:`Clear`,hourLabel:`Hour`,minuteLabel:`Minute`,clockLabel:`Clock`,periodLabel:`Period`,timeLabel:`Time`,format24Label:`24-hour`,rangeSelectionLabel:`Range selection`,switchToKeyboardLabel:`Switch to keyboard input`,switchToClockLabel:`Switch to clock`,toggleLabel:`Toggle`,timezoneSelectorLabel:`Timezone`,announceHour:`Hour`,announceMinute:`Minutes`,announceAmSelected:`AM selected`,announcePmSelected:`PM selected`,invalidTimeFormat:`Invalid time format`},behavior:{focusInputAfterClose:!1,focusTrap:!0,delayHandler:300,id:void 0},callbacks:{onOpen:void 0,onCancel:void 0,onConfirm:void 0,onUpdate:void 0,onSelectHour:void 0,onSelectMinute:void 0,onSelectAM:void 0,onSelectPM:void 0,onError:void 0,onTimezoneChange:void 0,onRangeConfirm:void 0,onRangeSwitch:void 0,onRangeValidation:void 0,onClear:void 0},timezone:{enabled:!1,default:void 0,whitelist:void 0,label:`Timezone`},range:{enabled:!1,minDuration:void 0,maxDuration:void 0,fromLabel:`From`,toLabel:`To`},wheel:{placement:void 0,hideFooter:void 0,commitOnScroll:void 0,hideDisabled:void 0,ignoreOutsideClick:void 0},clearBehavior:{clearInput:!0}},oB=e=>e.replace(/[^0-9:APMapm\s]/g,``),sB=new Map,cB=class{core;managers;lifecycle;emitter;constructor(e,t){if(kR())throw Error(`TimepickerUI requires browser environment`);let n=this.resolveInputElement(e);if(!n)throw Error(`Input element not found`);let r=t?.behavior?.id,i=r||`tp-ui-${VR()}`,a=this.createWrapperElement(n),o=wR(t||{});if(o.ui.inline?.enabled&&typeof t?.behavior?.focusTrap>`u`&&(o.behavior.focusTrap=!1),o.ui.inline?.enabled){if(!o.ui.inline.containerId)throw Error(`inline.containerId is required when inline mode is enabled`);if(!kR()&&!document.getElementById(o.ui.inline.containerId))throw Error(`Container element with id "${o.ui.inline.containerId}" not found`)}this.emitter=new iB,this.core=new jR(a,o,i,r);let s=this.core.getInput();if(s){let e=oz(s,o.clock.type),t=Number(e.hour)*30,n=Number(e.minutes)*6;this.core.setDegreesHours(t),this.core.setDegreesMinutes(n)}this.managers=new Xz(this.core,this.emitter),this.lifecycle=new rB(this.core,this.managers,this.emitter),this.managers.config.checkMobileOption(),this.managers.config.preventClockTypeByCurrentTime(),this.setupInternalEventListeners(),sB.set(this.core.instanceId,this)}setupInternalEventListeners(){this.emitter.on(`show`,()=>{this.core.isDestroyed||this.lifecycle.mount()}),this.emitter.on(`cancel`,()=>{this.core.isDestroyed||this.lifecycle.unmount()}),this.emitter.on(`confirm`,e=>{if(!this.core.isDestroyed){if(this.core.options.range?.enabled)return;let t=this.core.getInput();if(t&&e.hour&&e.minutes){let n=e.type?` ${e.type}`:``;t.value=`${e.hour}:${e.minutes}${n}`}e.autoCommit||this.lifecycle.unmount()}}),this.emitter.on(`range:confirm`,e=>{if(this.core.isDestroyed)return;let t=this.core.getInput();t&&(t.value=`${e.from} - ${e.to}`),this.lifecycle.unmount()})}create(){this.lifecycle.init(),this.core.options.ui.inline?.enabled&&this.lifecycle.mount()}open(e){this.lifecycle.mount(),e&&e()}close(e,t){this.lifecycle.unmount(e?t:void 0),!e&&t&&t()}destroy(e){sB.delete(this.core.instanceId),this.lifecycle.destroy(e)}update(e,t){this.core.isDestroyed||(this.core.updateOptions(e.options),this.managers.config.checkMobileOption(),this.managers.config.getDisableTime(),e.create&&this.create(),t&&t())}getValue(){if(this.core.isDestroyed)return{hour:``,minutes:``,type:void 0,time:``,degreesHours:null,degreesMinutes:null};let e=this.core.getModalElement(),t=this.core.getInput(),n=`12`,r=`00`,i=this.core.options.clock.type===`24h`?void 0:`AM`,a=null,o=null;if(e){let e=this.core.getHour(),t=this.core.getMinutes(),s=this.core.getActiveTypeMode();n=e?.value||`12`,r=t?.value||`00`,i=this.core.options.clock.type===`24h`?void 0:s?.textContent||`AM`,a=this.core.degreesHours,o=this.core.degreesMinutes}else if(t){let e=oz(t,this.core.options.clock.type);n=e.hour,r=e.minutes,i=e.type,a=Number(n)*30,o=Number(r)*6}let s=``;return s=this.core.options.clock.type===`24h`?`${n.padStart(2,`0`)}:${r.padStart(2,`0`)}`:`${n}:${r.padStart(2,`0`)} ${i}`,{hour:n,minutes:r,type:i,time:s,degreesHours:a,degreesMinutes:o}}setValue(e,t=!0){if(this.core.isDestroyed||!e||typeof e!=`string`)return;this.core.isInitialized||this.create();let n=oB(e.trim());try{let e=TR(this.core,n);if(ER(this.core,e),DR(this.core,e.typeValue),t){let e=this.core.getInput();e&&(e.value=n)}OR(this.core,this.managers,e)}catch{return}}getElement(){return this.core.element}get instanceId(){return this.core.instanceId}get options(){return this.core.options}get isInitialized(){return this.core.isInitialized}get isDestroyed(){return this.core.isDestroyed}get hour(){return this.core.getHour()}get minutes(){return this.core.getMinutes()}get okButton(){return this.core.getOkButton()}get cancelButton(){return this.core.getCancelButton()}get clockHand(){return this.core.getClockHand()}on(e,t){this.core.isDestroyed||this.emitter.on(e,t)}once(e,t){this.core.isDestroyed||this.emitter.once(e,t)}off(e,t){this.core.isDestroyed||this.emitter.off(e,t)}resolveInputElement(e){if(AR()===!1)return null;let t=null;if(typeof e==`string`){if(t=document.querySelector(e),!t)return null}else if(e instanceof HTMLElement)t=e;else return null;return t.tagName===`INPUT`?t:t.querySelector(`input`)}createWrapperElement(e){if(AR()===!1)return e;let t=e.parentElement;if(e.tagName===`INPUT`&&!t?.classList.contains(`tp-ui`)){let t=document.createElement(`div`);return t.className=`tp-ui`,e.parentNode?.insertBefore(t,e),t.appendChild(e),t}return t&&!t.classList.contains(`tp-ui`)&&t.classList.add(`tp-ui`),t||e}static getById(e){return sB.get(e)}static getAllInstances(){return Array.from(sB.values())}static isAvailable(e){return kR()?!1:typeof e==`string`?document.querySelector(e)!==null:e instanceof HTMLElement&&document.contains(e)}static destroyAll(){Array.from(sB.values()).forEach(e=>e.destroy()),sB.clear()}},lB=cB,uB=lB})),fB=_({RangeManager:()=>DB,RangePlugin:()=>OB});function pB(e){let t=e.match(CB);return t?{hour:t[1],minutes:t[2],type:t[3].toUpperCase()}:null}function mB(e){let t=e.match(wB);return t?{hour:t[1],minutes:t[2]}:null}function hB(e,t){let n=parseInt(e.hour,10),r=parseInt(e.minutes,10);if(Number.isNaN(n)||Number.isNaN(r))return 0;if(t===`12h`&&e.type){let t=e.type.toUpperCase();t===`PM`&&n!==12&&(n+=12),t===`AM`&&n===12&&(n=0)}return n*60+r}function gB(e){if(!e||e===`--:--`)return null;let t=pB(e);if(t)return{hour:t.hour,minutes:t.minutes,type:t.type};let n=e.match(/^(\d{1,2}):(\d{2})\s*(AM|PM)$/i);if(n)return{hour:n[1],minutes:n[2],type:n[3].toUpperCase()};let r=mB(e);if(r)return{hour:r.hour,minutes:r.minutes};let i=e.match(/^(\d{1,2}):(\d{2})$/);return i?{hour:i[1],minutes:i[2]}:null}function _B(e){let t=e.minutes===`--`?`--`:e.minutes.padStart(2,`0`),n=`${e.hour}:${t}`;return e.type?`${n} ${e.type}`:n}function vB(e,t){return e?hB(e,t):0}function yB(e,t,n){if(!e||!t)return 0;let r=vB(e,n);return vB(t,n)-r}function bB(e,t){return e?t===`12h`?!!(e.hour&&e.minutes&&e.type):!!(e.hour&&e.minutes):!1}function xB(e){if(!e||!e.includes(` - `))return{from:null,to:null};let t=e.split(` - `).map(e=>e.trim());return t.length!==2||t[0]===`--:--`||t[1]===`--:--`?{from:null,to:null}:{from:gB(t[0]),to:gB(t[1])}}function SB(e,t,n,r){e.on(n,r),t.push(()=>e.off(n,r))}var CB,wB,TB,EB,DB,OB,kB=h((()=>{CB=/^(1[0-2]|[1-9]):([0-5][0-9])\s*(AM|PM)$/i,wB=/^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/,TB=class{activePart=`from`;fromValue=null;toValue=null;previewValue=null;clockType;minDuration;maxDuration;emitter;constructor(e,t,n,r){this.clockType=e,this.minDuration=t,this.maxDuration=n,this.emitter=r}getActivePart(){return this.activePart}getFromValue(){return this.fromValue}getToValue(){return this.toValue}getPreviewValue(){return this.previewValue}setFromValue(e){this.fromValue=e}setToValue(e){this.toValue=e}setPreviewValue(e){this.previewValue=e}isFromComplete(){return bB(this.fromValue,this.clockType)}isToComplete(){return bB(this.toValue,this.clockType)}canSwitchToEnd(){return this.isFromComplete()}canConfirm(){return!this.isFromComplete()||!this.isToComplete()?!1:this.getDuration()>0}setActivePart(e){if(e===`to`&&!this.canSwitchToEnd())return!1;let t=this.activePart!==e;return this.activePart=e,t&&(this.previewValue=null),t}resetActivePart(){this.activePart=`from`,this.previewValue=null}getCurrentValue(){return this.previewValue?this.previewValue:this.activePart===`from`?this.fromValue:this.toValue}getSavedValue(){return this.activePart===`from`?this.fromValue:this.toValue}commitPreview(){this.previewValue&&=(this.activePart===`from`?this.fromValue=this.previewValue:this.toValue=this.previewValue,null)}getDuration(){return yB(this.fromValue,this.toValue,this.clockType)}validate(){if(!this.fromValue||!this.toValue)return{valid:!0,duration:0};let e=this.getDuration(),t=!0;return this.minDuration!==void 0&&e<this.minDuration&&(t=!1),this.maxDuration!==void 0&&e>this.maxDuration&&(t=!1),this.emitter.emit(`range:validation`,{valid:t,duration:e,minDuration:this.minDuration,maxDuration:this.maxDuration}),{valid:t,duration:e}}getDisabledTimeForEndPart(){if(this.activePart===`from`||!this.fromValue||!this.isFromComplete())return null;let e=[],t=[],n=parseInt(this.fromValue.hour,10),r=parseInt(this.fromValue.minutes,10),i=this.fromValue.type;if(this.clockType===`24h`){for(let t=0;t<n;t++)e.push(t.toString().padStart(2,`0`));for(let e=0;e<r;e++)t.push(e.toString().padStart(2,`0`));return{hours:e,minutes:t,fromHour:n}}for(let e=0;e<r;e++)t.push(e.toString().padStart(2,`0`));return{hours:e,minutes:t,fromType:i,fromHour:n}}reset(){this.activePart=`from`,this.fromValue=null,this.toValue=null,this.previewValue=null}},EB=class{core;state;constructor(e,t){this.core=e,this.state=t}updateTabs(){let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-range-tab.tp-ui-range-from`),n=e.querySelector(`.tp-ui-range-tab.tp-ui-range-to`),r=this.state.getActivePart()===`from`,i=this.state.isFromComplete();t?.classList.toggle(`active`,r),n?.classList.toggle(`active`,!r),n?.classList.toggle(`disabled`,!i),t?.setAttribute(`aria-selected`,String(r)),n?.setAttribute(`aria-selected`,String(!r)),n?.setAttribute(`aria-disabled`,String(!i)),t?.setAttribute(`tabindex`,r?`0`:`-1`),n?.setAttribute(`tabindex`,r||!i?`-1`:`0`)}updateTimeDisplay(){let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-range-from-time`),n=e.querySelector(`.tp-ui-range-to-time`),r=this.state.getActivePart(),i=this.state.getPreviewValue(),a=this.state.getFromValue(),o=this.state.getToValue(),s=`--:--`;r===`from`&&i?s=_B(i):a&&(s=_B(a));let c=`--:--`;r===`to`&&i?c=_B(i):o&&(c=_B(o)),t&&(t.textContent=s),n&&(n.textContent=c)}updateOkButton(){let e=this.core.getOkButton();if(!e)return;let t=this.state.canConfirm();e.classList.toggle(`disabled`,!t),e.setAttribute(`aria-disabled`,String(!t))}updateInputValue(){let e=this.core.getInput();if(!e)return;let t=this.state.getFromValue(),n=this.state.getToValue();e.value=`${t?_B(t):`--:--`} - ${n?_B(n):`--:--`}`}syncClockToActivePart(){let e=this.state.getSavedValue(),t=this.core.getHour(),n=this.core.getMinutes();if(t&&(t.value=e?.hour??`12`),n&&(n.value=e?.minutes??`00`),this.core.options.clock.type===`12h`){let t=this.core.getAM(),n=this.core.getPM();e?.type===`AM`?(t?.classList.add(`active`),n?.classList.remove(`active`)):e?.type===`PM`?(n?.classList.add(`active`),t?.classList.remove(`active`)):(t?.classList.remove(`active`),n?.classList.remove(`active`))}n&&(n.blur(),n.classList.remove(`active`)),t&&t.click()}updateAll(){this.updateTabs(),this.updateTimeDisplay(),this.updateOkButton()}},DB=class{core;emitter;state;ui;cleanupHandlers=[];isSyncingAmPm=!1;constructor(e,t){this.core=e,this.emitter=t;let{range:n,clock:r}=e.options;this.state=new TB(r.type,n?.minDuration,n?.maxDuration,t),this.ui=new EB(e,this.state)}get isEnabled(){return this.core.options.range?.enabled===!0}init(){if(!this.isEnabled)return;let{from:e,to:t}=xB(this.core.getInput()?.value||``);this.state.setFromValue(e),this.state.setToValue(t),this.state.setActivePart(`from`),this.state.setPreviewValue(null),this.bindEvents(),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent(),this.ui.updateAll()}getActivePart(){return this.state.getActivePart()}setActivePart(e){this.isEnabled&&(this.state.setActivePart(e)&&this.emitter.emit(`range:switch`,{active:e,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent(),this.ui.updateAll())}getFromValue(){return this.state.getFromValue()}getToValue(){return this.state.getToValue()}getDisabledTimeForEndPart(){return this.isEnabled?this.state.getDisabledTimeForEndPart():null}getDuration(){return this.state.getDuration()}validateRange(){return this.isEnabled?this.state.validate():{valid:!0,duration:0}}canConfirm(){return!this.isEnabled||this.state.canConfirm()}getFormattedRange(){let e=this.state.getFromValue(),t=this.state.getToValue();return!e||!t?null:{from:_B(e),to:_B(t)}}bindEvents(){let e=this.core.getModalElement();if(!e)return;let t=e.querySelector(`.tp-ui-range-tab.tp-ui-range-from`),n=e.querySelector(`.tp-ui-range-tab.tp-ui-range-to`);if(t){let e=()=>this.activatePart(`from`,t);t.addEventListener(`click`,e),this.cleanupHandlers.push(()=>t.removeEventListener(`click`,e))}if(n){let e=()=>this.activatePart(`to`,n);n.addEventListener(`click`,e),this.cleanupHandlers.push(()=>n.removeEventListener(`click`,e))}this.bindTabKeyboard(t,n),SB(this.emitter,this.cleanupHandlers,`update`,()=>this.handleUpdate()),SB(this.emitter,this.cleanupHandlers,`range:minute:commit`,e=>this.handleMinuteCommit(e)),SB(this.emitter,this.cleanupHandlers,`confirm`,()=>this.handleConfirm()),SB(this.emitter,this.cleanupHandlers,`select:am`,()=>this.handleAmPm()),SB(this.emitter,this.cleanupHandlers,`select:pm`,()=>this.handleAmPm()),SB(this.emitter,this.cleanupHandlers,`clear`,()=>this.handleClear())}isTabDisabled(e){return!e||e.getAttribute(`aria-disabled`)===`true`||e.classList.contains(`disabled`)}activatePart(e,t){this.isTabDisabled(t)||this.setActivePart(e)}bindTabKeyboard(e,t){let n=[e,t].filter(e=>e!==null);n.length!==0&&n.forEach((e,t)=>{let r=t===0?`from`:`to`,i=i=>{switch(i.key){case`ArrowRight`:case`ArrowLeft`:{i.preventDefault();let e=((i.key===`ArrowRight`?t+1:t-1)+n.length)%n.length,r=n[e];this.isTabDisabled(r)||r.focus();break}case`Home`:i.preventDefault(),n[0].focus();break;case`End`:i.preventDefault(),n[n.length-1].focus();break;case`Enter`:case` `:case`Spacebar`:i.preventDefault(),this.activatePart(r,e)}};e.addEventListener(`keydown`,i),this.cleanupHandlers.push(()=>e.removeEventListener(`keydown`,i))})}handleClear(){this.isEnabled&&(this.state.setFromValue(null),this.state.setToValue(null),this.state.setPreviewValue(null),this.state.resetActivePart())}handleUpdate(){if(!this.isEnabled)return;let e=this.core.getHour(),t=this.core.getMinutes(),n=this.core.getActiveTypeMode(),r=e?.value??`12`,i=this.state.getSavedValue(),a=i?.minutes&&i.minutes!==`--`?t?.value??`--`:`--`,o=this.core.options.clock.type===`12h`?n?.textContent??void 0:void 0;this.state.setPreviewValue({hour:r,minutes:a,type:o}),this.ui.updateAll()}handleMinuteCommit(e){if(!this.isEnabled)return;let t={hour:e.hour,minutes:e.minutes,type:e.type??void 0};this.state.getActivePart()===`from`?(this.state.setFromValue(t),this.state.setPreviewValue(null),this.state.isFromComplete()&&(this.state.setActivePart(`to`),this.emitter.emit(`range:switch`,{active:`to`,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent())):(this.state.setToValue(t),this.state.setPreviewValue(null)),this.state.validate(),this.ui.updateAll()}handleAmPm(){if(!this.isEnabled||this.isSyncingAmPm||this.core.options.clock.type!==`12h`)return;let e=this.core.getActiveTypeMode()?.textContent;if(e){if(this.state.getActivePart()===`from`){let t=this.state.getFromValue();t&&(this.state.setFromValue({...t,type:e}),this.state.isFromComplete()&&(this.state.setActivePart(`to`),this.state.setPreviewValue(null),this.emitter.emit(`range:switch`,{active:`to`,disabledTime:this.state.getDisabledTimeForEndPart()}),this.ui.syncClockToActivePart(),this.emitAmPmSyncEvent()))}else{let t=this.state.getToValue();t&&this.state.setToValue({...t,type:e}),this.emitter.emit(`range:switch`,{active:`to`,disabledTime:this.state.getDisabledTimeForEndPart()})}this.state.validate(),this.ui.updateAll()}}emitAmPmSyncEvent(){if(this.core.options.clock.type!==`12h`)return;let e=this.state.getSavedValue();if(e?.type){this.isSyncingAmPm=!0;try{e.type===`AM`?this.emitter.emit(`select:am`,{}):e.type===`PM`&&this.emitter.emit(`select:pm`,{})}finally{this.isSyncingAmPm=!1}}}handleConfirm(){if(!this.isEnabled)return;this.state.commitPreview();let e=this.state.getFromValue(),t=this.state.getToValue(),n=e?_B(e):`--:--`,r=t?_B(t):`--:--`,i=this.state.getDuration();this.ui.updateInputValue(),this.emitter.emit(`range:confirm`,{from:n,to:r,duration:i})}reset(){this.state.reset()}destroy(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers=[],this.reset()}},OB={name:`range`,factory:(e,t)=>new DB(e,t),clearHandler:(e,t)=>{if(!e.options.range?.enabled)return;let n=e.getModalElement();if(!n)return;let r=n.querySelector(`.tp-ui-range-from`),i=n.querySelector(`.tp-ui-range-to`),a=n.querySelector(`.tp-ui-range-from-time`),o=n.querySelector(`.tp-ui-range-to-time`);a&&(a.textContent=`--:--`),o&&(o.textContent=`--:--`),r?.classList.add(`active`),i?.classList.remove(`active`),r?.setAttribute(`aria-selected`,`true`),i?.setAttribute(`aria-selected`,`false`),r?.setAttribute(`tabindex`,`0`),i?.setAttribute(`tabindex`,`-1`),i?.classList.add(`disabled`),i?.setAttribute(`aria-disabled`,`true`);let s=e.getHour();s&&s.focus(),t.emit(`range:switch`,{active:`from`,disabledTime:null})}}})),AB,jB,MB,NB=!1;async function PB(){if(!AB){let e=await Promise.resolve().then(()=>(dB(),sR));AB=e.TimepickerUI,jB=e.PluginRegistry,MB=(await Promise.resolve().then(()=>(kB(),fB))).RangePlugin,!NB&&jB&&MB&&(jB.register(MB),NB=!0)}}var FB=class{constructor(e){if(this.config={dayStartTime:`00:00`,dayEndTime:`23:59`,minuteIncrement:5,clockType:`12h`,...e},this.selectedStart=this.extractTimeAsHHMM(e.startTime),e.endTime)this.selectedEnd=this.extractTimeAsHHMM(e.endTime);else{let e=new Date(`2000-01-01T${this.selectedStart}:00Z`),n=new Date(e.getTime()+36e5);this.selectedEnd=t.tools.dateTime.extractTime(n.toISOString())}this.inputElement=document.createElement(`input`),this.container=this.createUI()}extractTimeAsHHMM(e){return e.includes(`T`)?t.tools.dateTime.extractTime(e):e}createUI(){let e=document.createElement(`div`);return e.style.cssText=`
232
232
  position: fixed;
233
233
  left: -9999px;
234
234
  top: -9999px;
@@ -238,14 +238,14 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
238
238
  position: absolute;
239
239
  left: 0;
240
240
  top: 0;
241
- `,e.appendChild(this.inputElement),e}async initTimePicker(){await fz();let e=this.config.clockType??`12h`,[t,n]=this.selectedStart.split(`:`).map(Number),[r,i]=this.selectedEnd.split(`:`).map(Number);if(e===`24h`){let e=`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`,a=`${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`;this.inputElement.value=`${e} - ${a}`,this.inputElement.dataset.timeFrom=e,this.inputElement.dataset.timeTo=a}else{let e=t>=12?`PM`:`AM`,a=t===0?12:t>12?t-12:t,o=`${String(a).padStart(2,`0`)}:${String(n).padStart(2,`0`)} ${e}`,s=r>=12?`PM`:`AM`,c=r===0?12:r>12?r-12:r,l=`${String(c).padStart(2,`0`)}:${String(i).padStart(2,`0`)} ${s}`;this.inputElement.value=`${o} - ${l}`,this.inputElement.dataset.timeFrom=`${String(a).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`,this.inputElement.dataset.timeTo=`${String(c).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`,this.inputElement.dataset.typeFrom=e,this.inputElement.dataset.typeTo=s}let a={enabled:!0,fromLabel:`Start`,toLabel:`End`};this.config.minDuration!==void 0&&(a.minDuration=this.config.minDuration),this.config.maxDuration!==void 0&&(a.maxDuration=this.config.maxDuration),this.picker=new cz(this.inputElement,{range:a,clock:{type:e,incrementMinutes:this.config.minuteIncrement||5},ui:{theme:`crane`},callbacks:{onRangeConfirm:e=>{try{let t=e.from,n=e.to;if(t&&n){let e=e=>{let t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(t){let e=parseInt(t[1],10),n=t[2],r=t[3].toUpperCase();return r===`PM`&&e!==12?e+=12:r===`AM`&&e===12&&(e=0),`${String(e).padStart(2,`0`)}:${n}`}let n=e.match(/(\d{1,2}):(\d{2})/);return n?`${n[1].padStart(2,`0`)}:${n[2]}`:`00:00`};this.selectedStart=e(t),this.selectedEnd=e(n),this.config.onConfirm(this.selectedStart,this.selectedEnd),this.destroy()}}catch(e){console.error(`[ModernTimePicker] Error in onRangeConfirm:`,e)}},onCancel:()=>{try{this.config.onCancel(),this.destroy()}catch(e){console.error(`[ModernTimePicker] Error in onCancel:`,e)}}}}),this.picker.create(),setTimeout(()=>{this.picker&&this.picker.open()},100)}async show(){document.body.appendChild(this.container),await this.initTimePicker()}destroy(){this.picker&&this.picker.destroy&&this.picker.destroy(),this.container.parentNode&&this.container.parentNode.removeChild(this.container)}};async function mz(e){let t=new pz(e);return await t.show(),t}var{BLOCK_TYPES:hz}=t.availability,gz=`padding:6px 12px; cursor:pointer; display:flex; align-items:center; gap:8px;`,_z=`var(--chc-hover-bg)`,vz=`var(--chc-text-primary)`,yz=[[hz.MAINTENANCE,`Maintenance`],[hz.PRACTICE,`Practice`],[hz.RESERVED,`Reserved`],[hz.BLOCKED,`Blocked`]];function bz(){let e=null,t=null;function n(){e&&(e.destroy(),e=null,t=null)}function r(e){let t=document.createElement(`div`);t.style.cssText=`font-family:sans-serif; font-size:13px; min-width:150px;`;for(let r of e.blockTypes){let i=document.createElement(`div`);i.style.cssText=gz,i.innerHTML=`
241
+ `,e.appendChild(this.inputElement),e}async initTimePicker(){await PB();let e=this.config.clockType??`12h`,[t,n]=this.selectedStart.split(`:`).map(Number),[r,i]=this.selectedEnd.split(`:`).map(Number);if(e===`24h`){let e=`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`,a=`${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`;this.inputElement.value=`${e} - ${a}`,this.inputElement.dataset.timeFrom=e,this.inputElement.dataset.timeTo=a}else{let e=t>=12?`PM`:`AM`,a=t===0?12:t>12?t-12:t,o=`${String(a).padStart(2,`0`)}:${String(n).padStart(2,`0`)} ${e}`,s=r>=12?`PM`:`AM`,c=r===0?12:r>12?r-12:r,l=`${String(c).padStart(2,`0`)}:${String(i).padStart(2,`0`)} ${s}`;this.inputElement.value=`${o} - ${l}`,this.inputElement.dataset.timeFrom=`${String(a).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`,this.inputElement.dataset.timeTo=`${String(c).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`,this.inputElement.dataset.typeFrom=e,this.inputElement.dataset.typeTo=s}let a={enabled:!0,fromLabel:`Start`,toLabel:`End`};this.config.minDuration!==void 0&&(a.minDuration=this.config.minDuration),this.config.maxDuration!==void 0&&(a.maxDuration=this.config.maxDuration),this.picker=new AB(this.inputElement,{range:a,clock:{type:e,incrementMinutes:this.config.minuteIncrement||5},ui:{theme:`crane`},callbacks:{onRangeConfirm:e=>{try{let t=e.from,n=e.to;if(t&&n){let e=e=>{let t=e.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(t){let e=parseInt(t[1],10),n=t[2],r=t[3].toUpperCase();return r===`PM`&&e!==12?e+=12:r===`AM`&&e===12&&(e=0),`${String(e).padStart(2,`0`)}:${n}`}let n=e.match(/(\d{1,2}):(\d{2})/);return n?`${n[1].padStart(2,`0`)}:${n[2]}`:`00:00`};this.selectedStart=e(t),this.selectedEnd=e(n),this.config.onConfirm(this.selectedStart,this.selectedEnd),this.destroy()}}catch(e){console.error(`[ModernTimePicker] Error in onRangeConfirm:`,e)}},onCancel:()=>{try{this.config.onCancel(),this.destroy()}catch(e){console.error(`[ModernTimePicker] Error in onCancel:`,e)}}}}),this.picker.create(),setTimeout(()=>{this.picker&&this.picker.open()},100)}async show(){document.body.appendChild(this.container),await this.initTimePicker()}destroy(){this.picker&&this.picker.destroy&&this.picker.destroy(),this.container.parentNode&&this.container.parentNode.removeChild(this.container)}};async function IB(e){let t=new FB(e);return await t.show(),t}var{BLOCK_TYPES:LB}=t.availability,RB=`padding:6px 12px; cursor:pointer; display:flex; align-items:center; gap:8px;`,zB=`var(--chc-hover-bg)`,BB=`var(--chc-text-primary)`,VB=[[LB.MAINTENANCE,`Maintenance`],[LB.PRACTICE,`Practice`],[LB.RESERVED,`Reserved`],[LB.BLOCKED,`Blocked`]];function HB(){let e=null,t=null;function n(){e&&(e.destroy(),e=null,t=null)}function r(e){let t=document.createElement(`div`);t.style.cssText=`font-family:sans-serif; font-size:13px; min-width:150px;`;for(let r of e.blockTypes){let i=document.createElement(`div`);i.style.cssText=RB,i.innerHTML=`
242
242
  <span style="width:10px;height:10px;border-radius:2px;background:${r.color};display:inline-block;"></span>
243
243
  ${r.label}
244
- `,i.addEventListener(`mouseenter`,()=>{i.style.background=_z,i.style.color=vz}),i.addEventListener(`mouseleave`,()=>{i.style.background=`transparent`,i.style.color=``}),i.addEventListener(`click`,()=>{e.onTypeSelected(r.type),n()}),t.appendChild(i)}if(e.onAdjustTime||e.onDelete){let e=document.createElement(`div`);e.style.cssText=`border-top:1px solid var(--chc-border-primary); margin:4px 0;`,t.appendChild(e)}if(e.onAdjustTime){let r=document.createElement(`div`);r.style.cssText=gz,r.innerHTML=`<span style="font-size:14px;">&#128339;</span> Adjust Time`,r.addEventListener(`mouseenter`,()=>{r.style.background=_z,r.style.color=vz}),r.addEventListener(`mouseleave`,()=>{r.style.background=`transparent`,r.style.color=``}),r.addEventListener(`click`,()=>{let t=e.onAdjustTime;n(),e.startTime&&e.endTime&&mz({startTime:e.startTime,endTime:e.endTime,dayStartTime:`06:00`,dayEndTime:`22:00`,minuteIncrement:5,onConfirm:(e,n)=>t(e,n),onCancel:()=>{}})}),t.appendChild(r)}if(e.onDelete){let r=document.createElement(`div`);r.style.cssText=`padding:6px 12px; cursor:pointer; display:flex; align-items:center; gap:8px; color:#e74c3c;`,r.innerHTML=`<span style="font-size:14px;">&#128465;</span> Delete`,r.addEventListener(`mouseenter`,()=>{r.style.background=`#fdecea`}),r.addEventListener(`mouseleave`,()=>{r.style.background=`transparent`}),r.addEventListener(`click`,()=>{let t=e.onDelete;n(),t()}),t.appendChild(r)}return t}function i(e){let{blockId:t,engine:r,day:i,onBlockChanged:o,onManageRegistrations:s}=e,c=document.createElement(`div`);c.style.cssText=`font-family:sans-serif; font-size:13px; min-width:150px;`;for(let[e,a]of yz){let s=kI[e],l=document.createElement(`div`);l.style.cssText=gz,l.innerHTML=`
244
+ `,i.addEventListener(`mouseenter`,()=>{i.style.background=zB,i.style.color=BB}),i.addEventListener(`mouseleave`,()=>{i.style.background=`transparent`,i.style.color=``}),i.addEventListener(`click`,()=>{e.onTypeSelected(r.type),n()}),t.appendChild(i)}if(e.onAdjustTime||e.onDelete){let e=document.createElement(`div`);e.style.cssText=`border-top:1px solid var(--chc-border-primary); margin:4px 0;`,t.appendChild(e)}if(e.onAdjustTime){let r=document.createElement(`div`);r.style.cssText=RB,r.innerHTML=`<span style="font-size:14px;">&#128339;</span> Adjust Time`,r.addEventListener(`mouseenter`,()=>{r.style.background=zB,r.style.color=BB}),r.addEventListener(`mouseleave`,()=>{r.style.background=`transparent`,r.style.color=``}),r.addEventListener(`click`,()=>{let t=e.onAdjustTime;n(),e.startTime&&e.endTime&&IB({startTime:e.startTime,endTime:e.endTime,dayStartTime:`06:00`,dayEndTime:`22:00`,minuteIncrement:5,onConfirm:(e,n)=>t(e,n),onCancel:()=>{}})}),t.appendChild(r)}if(e.onDelete){let r=document.createElement(`div`);r.style.cssText=`padding:6px 12px; cursor:pointer; display:flex; align-items:center; gap:8px; color:#e74c3c;`,r.innerHTML=`<span style="font-size:14px;">&#128465;</span> Delete`,r.addEventListener(`mouseenter`,()=>{r.style.background=`#fdecea`}),r.addEventListener(`mouseleave`,()=>{r.style.background=`transparent`}),r.addEventListener(`click`,()=>{let t=e.onDelete;n(),t()}),t.appendChild(r)}return t}function i(e){let{blockId:t,engine:r,day:i,onBlockChanged:o,onManageRegistrations:s}=e,c=document.createElement(`div`);c.style.cssText=`font-family:sans-serif; font-size:13px; min-width:150px;`;for(let[e,a]of VB){let s=ZL[e],l=document.createElement(`div`);l.style.cssText=RB,l.innerHTML=`
245
245
  <span style="width:10px;height:10px;border-radius:2px;background:${s};display:inline-block;"></span>
246
246
  ${a}
247
- `,l.addEventListener(`mouseenter`,()=>{l.style.background=_z,l.style.color=vz}),l.addEventListener(`mouseleave`,()=>{l.style.background=`transparent`,l.style.color=``}),l.addEventListener(`click`,()=>{let s=r.getDayBlocks(i).find(e=>e.id===t);s&&(r.removeBlock(t),r.applyBlock({courts:[s.court],timeRange:{start:s.start,end:s.end},type:e,reason:a}),o()),n()}),c.appendChild(l)}let l=document.createElement(`div`);l.style.cssText=`border-top:1px solid var(--chc-border-primary); margin:4px 0;`,c.appendChild(l);let u=document.createElement(`div`);u.style.cssText=gz,u.innerHTML=`<span style="font-size:14px;">&#128339;</span> Adjust Time`,u.addEventListener(`mouseenter`,()=>{u.style.background=_z,u.style.color=vz}),u.addEventListener(`mouseleave`,()=>{u.style.background=`transparent`,u.style.color=``}),u.addEventListener(`click`,()=>{n();let e=r.getDayBlocks(i).find(e=>e.id===t);e&&mz({startTime:e.start,endTime:e.end,dayStartTime:`06:00`,dayEndTime:`22:00`,minuteIncrement:5,onConfirm:(n,i)=>{let a=e.start.slice(0,10);r.resizeBlock({blockId:t,newTimeRange:{start:`${a}T${n}:00`,end:`${a}T${i}:00`}}),o()},onCancel:()=>{}})}),c.appendChild(u);let d=r.getDayBlocks(i).find(e=>e.id===t);if(s&&d?.type===hz.PRACTICE){let e=document.createElement(`div`);e.style.cssText=gz,e.innerHTML=`<span style="font-size:14px;">&#128101;</span> Manage Registrations`,e.addEventListener(`mouseenter`,()=>{e.style.background=_z,e.style.color=vz}),e.addEventListener(`mouseleave`,()=>{e.style.background=`transparent`,e.style.color=``}),e.addEventListener(`click`,()=>{n();let e=r.getDayBlocks(i).find(e=>e.id===t);e&&s({blockId:t,courtId:e.court.courtId,venueId:e.court.venueId,date:i,startTime:a(e.start),endTime:a(e.end)})}),c.appendChild(e)}let f=document.createElement(`div`);return f.style.cssText=`padding:6px 12px; cursor:pointer; display:flex; align-items:center; gap:8px; color:#e74c3c;`,f.innerHTML=`<span style="font-size:14px;">&#128465;</span> Delete`,f.addEventListener(`mouseenter`,()=>{f.style.background=`#fdecea`}),f.addEventListener(`mouseleave`,()=>{f.style.background=`transparent`}),f.addEventListener(`click`,()=>{r.removeBlock(t),o(),n()}),c.appendChild(f),c}function a(e){return(e.includes(`T`)?e.split(`T`)[1]:e).slice(0,5)}function o(r,i,a){n();let o=km(r,{content:i,allowHTML:!0,interactive:!0,trigger:`manual`,placement:`bottom`,appendTo:document.body,onHidden:()=>{e=null,t=null}});e=o,t=a,o.show()}return{show(e,i){if(t===i.itemId){n();return}o(e,r(i),i.itemId)},showForEngineBlock(e,r){if(t===r.itemId){n();return}o(e,i(r),r.itemId)},destroy(){n()},isActiveFor(e){return t===e}}}var xz={day:{label:`1 Day`,days:1,timeAxis:{scale:`hour`,step:1}},days3:{label:`3 Days`,days:3,timeAxis:{scale:`hour`,step:3}},week:{label:`Week`,days:7,timeAxis:{scale:`hour`,step:6}},all:{label:`Tournament`,days:0,timeAxis:{scale:`hour`,step:6}}};function Sz(e,t,n,r){let i=r?.labels,a=document.createElement(`div`);a.className=`tg-view-toolbar`;let o=document.createElement(`span`);o.textContent=(i?.view??`View`)+`:`,o.className=`tg-view-toolbar-label`,a.appendChild(o);let s=document.createElement(`input`);s.type=`text`,s.readOnly=!0,s.className=`tg-view-toolbar-date`,n&&s.addEventListener(`changeDate`,()=>{let e=s.value;e&&n(e)}),a.appendChild(s);let c={day:i?.day1??`1 Day`,days3:i?.days3??`3 Days`,week:i?.week??`Week`,all:i?.tournament??`Tournament`},l=[],u=[],d=t||`day`,f=e=>{l.forEach((t,n)=>{t.className=u[n]===e?`sp-btn sp-btn--active`:`sp-btn`})};for(let[t]of Object.entries(xz)){let n=document.createElement(`button`);n.textContent=c[t],n.className=t===d?`sp-btn sp-btn--active`:`sp-btn`,n.addEventListener(`click`,()=>{f(t),e(t)}),l.push(n),u.push(t),a.appendChild(n)}if(r?.onSetDefaultAvailability||r?.onSave){let e=document.createElement(`div`);e.className=`tg-view-toolbar-spacer`,a.appendChild(e)}if(r?.onSetDefaultAvailability){let e=document.createElement(`button`);e.textContent=i?.setDefaultAvailability??`Set Default Availability`,e.className=`sp-btn sp-btn--fill-muted`,e.addEventListener(`click`,r.onSetDefaultAvailability),a.appendChild(e)}let p=null;return r?.onSave&&(p=document.createElement(`button`),p.textContent=i?.saveToTournament??`Save to Tournament`,p.className=`sp-btn sp-btn--fill`,p.disabled=!0,p.addEventListener(`click`,r.onSave),a.appendChild(p)),{element:a,dateInput:s,setActiveView:f,setDate:e=>{s.value=e},setSaveEnabled:e=>{p&&(p.disabled=!e)}}}var Cz=class{constructor(e,t,n){this._dailyStartMin=0,this._dailyEndMin=1440,this._useDailyBounds=!1,this._visibleDays=null,this._visibleDayMs=null,this._start=e.getTime(),this._end=t.getTime(),this._width=Math.max(n,1),this._min=this._start,this._max=this._end,this._zoomMin=9e5,this._zoomMax=(this._end-this._start)*2}get start(){return new Date(this._start)}get end(){return new Date(this._end)}get width(){return this._width}get duration(){return this._end-this._start}get msPerPx(){if(!this._useDailyBounds)return this.duration/this._width;let e=this.toCollapsedMin(new Date(this._start)),t=this.toCollapsedMin(new Date(this._end))-e;return t<=0?1:t*60*1e3/this._width}getDailyBounds(){return this._useDailyBounds?{startMin:this._dailyStartMin,endMin:this._dailyEndMin}:null}getVisibleDays(){return this._visibleDays}timeToX(e){if(!this._useDailyBounds)return(e.getTime()-this._start)/this.duration*this._width;let t=this.toCollapsedMin(e),n=this.toCollapsedMin(new Date(this._start)),r=this.toCollapsedMin(new Date(this._end))-n;return r<=0?0:(t-n)/r*this._width}xToTime(e){if(!this._useDailyBounds){let t=e/this._width*this.duration;return new Date(this._start+t)}let t=this.toCollapsedMin(new Date(this._start)),n=this.toCollapsedMin(new Date(this._end))-t;if(n<=0)return new Date(this._start);let r=t+e/this._width*n;return this.fromCollapsedMin(r)}snap(e,t){let n=e.getTime(),r=t*60*1e3;return new Date(Math.round(n/r)*r)}setWindow(e,t){this._start=e.getTime(),this._end=t.getTime(),this.clampBounds()}setLimits(e){e.min!==void 0&&(this._min=e.min.getTime()),e.max!==void 0&&(this._max=e.max.getTime()),e.zoomMin!==void 0&&(this._zoomMin=e.zoomMin),e.zoomMax!==void 0&&(this._zoomMax=e.zoomMax)}setWidth(e){this._width=Math.max(e,1)}setDailyBounds(e,t){let[n,r]=e.split(`:`).map(Number),[i,a]=t.split(`:`).map(Number);this._dailyStartMin=n*60+r,this._dailyEndMin=i*60+a,this._useDailyBounds=!0}clearDailyBounds(){this._useDailyBounds=!1,this._dailyStartMin=0,this._dailyEndMin=1440,this._visibleDays=null,this._visibleDayMs=null}setVisibleDays(e){this._visibleDays=e,this._visibleDayMs=e.map(e=>new Date(e+`T00:00:00`).getTime())}clearVisibleDays(){this._visibleDays=null,this._visibleDayMs=null}pan(e){if(this._visibleDays)return;if(this._useDailyBounds){let t=this.toCollapsedMin(new Date(this._start)),n=this.toCollapsedMin(new Date(this._end)),r=n-t;if(r<=0)return;let i=e/this._width*r,a=this.fromCollapsedMin(t+i),o=this.fromCollapsedMin(n+i);this._start=a.getTime(),this._end=o.getTime(),this.clampBounds();return}let t=e*this.msPerPx,n=this._start+t,r=this._end+t;if(n<this._min){let e=this._min-n;n+=e,r+=e}if(r>this._max){let e=r-this._max;n-=e,r-=e}this._start=n,this._end=r}zoom(e,t){if(this._visibleDays)return;if(this._useDailyBounds){let n=this.toCollapsedMin(new Date(this._start)),r=this.toCollapsedMin(new Date(this._end))-n,i=n+t/this._width*r,a=r*e,o=this._zoomMin/6e4,s=this._zoomMax/6e4;a=Math.max(o,Math.min(s,a));let c=t/this._width,l=this.fromCollapsedMin(i-a*c),u=this.fromCollapsedMin(i+a*(1-c));this._start=l.getTime(),this._end=u.getTime(),this.clampBounds();return}let n=this._start+t/this._width*this.duration,r=this.duration*e;r=Math.max(this._zoomMin,Math.min(this._zoomMax,r));let i=t/this._width;this._start=n-r*i,this._end=n+r*(1-i),this.clampBounds()}toCollapsedMin(e){let t=this._dailyEndMin-this._dailyStartMin;if(t<=0)return 0;let n=e.getHours()*60+e.getMinutes()+e.getSeconds()/60,r=Math.max(this._dailyStartMin,Math.min(this._dailyEndMin,n))-this._dailyStartMin;if(this._visibleDays&&this._visibleDayMs){let n=new Date(e);n.setHours(0,0,0,0);let i=n.getTime(),a=-1;for(let e=0;e<this._visibleDayMs.length;e++)if(this._visibleDayMs[e]===i){a=e;break}if(a===-1){if(i<this._visibleDayMs[0])return 0;if(i>this._visibleDayMs[this._visibleDayMs.length-1])return this._visibleDayMs.length*t;for(let e=0;e<this._visibleDayMs.length-1;e++)if(i>this._visibleDayMs[e]&&i<this._visibleDayMs[e+1])return(e+1)*t;return 0}return a*t+r}let i=new Date(this._start);i.setHours(0,0,0,0);let a=new Date(e);return a.setHours(0,0,0,0),Math.round((a.getTime()-i.getTime())/864e5)*t+r}fromCollapsedMin(e){let t=this._dailyEndMin-this._dailyStartMin;if(t<=0)return new Date(this._start);let n=Math.floor(e/t),r=e-n*t;if(this._visibleDays&&this._visibleDayMs){let e=Math.max(0,Math.min(n,this._visibleDayMs.length-1)),t=new Date(this._visibleDayMs[e]),i=this._dailyStartMin+r;return t.setHours(Math.floor(i/60),Math.round(i%60),0,0),t}let i=new Date(this._start);i.setHours(0,0,0,0);let a=new Date(i);a.setDate(a.getDate()+n);let o=this._dailyStartMin+r;return a.setHours(Math.floor(o/60),Math.round(o%60),0,0),a}clampBounds(){let e=this._end-this._start;this._start<this._min&&(this._start=this._min,this._end=this._min+e),this._end>this._max&&(this._end=this._max,this._start=this._max-e),this._start<this._min&&(this._start=this._min),this._end>this._max&&(this._end=this._max)}},wz=`tg-tick-day`,Tz=`tg-tick-hour`,Ez=class{constructor(e,t){this.scale=e,this.tickConfig=Dz(t),this.dayEl=document.createElement(`div`),this.dayEl.className=`tg-day-axis`,this.dayEl.setAttribute(`role`,`presentation`),this.hourEl=document.createElement(`div`),this.hourEl.className=`tg-hour-axis`,this.hourEl.setAttribute(`role`,`presentation`),this.dayEl.addEventListener(`click`,e=>{let t=(e.target.closest?.(`.${wz}`))?.dataset.day;t&&this.onDayClick&&this.onDayClick(t)})}getDayElement(){return this.dayEl}getHourElement(){return this.hourEl}setTimeAxisOptions(e){this.tickConfig=Dz(e)}render(){this.renderDayLabels(),this.renderHourTicks()}renderDayLabels(){this.dayEl.innerHTML=``;let{dayFormat:e}=this.tickConfig,t=this.tickConfig.scale,n=this.scale.getDailyBounds();if(n&&t===`hour`){this.renderDayLabelsWithBounds(n,e);return}if(t===`hour`){let t=this.scale.start.getTime(),n=kz(t,this.scale.end.getTime());if(n.length===0){let n=new Date(t);n.setHours(0,0,0,0);let r=document.createElement(`div`);r.className=wz,r.style.left=`0px`,r.style.maxWidth=`${this.scale.width}px`,r.dataset.day=Oz(n),r.textContent=e.format(n),this.dayEl.appendChild(r);return}for(let t of n){let n=this.scale.timeToX(t),r=document.createElement(`div`);r.className=wz,r.style.left=`${n}px`,r.dataset.day=Oz(t),r.textContent=e.format(t),this.dayEl.appendChild(r)}}else if(t===`day`){let e=jz(this.scale.start.getTime(),this.scale.end.getTime());for(let t of e){let e=this.scale.timeToX(t),n=document.createElement(`div`);n.className=wz,n.style.left=`${e}px`,n.dataset.day=Oz(t),n.textContent=this.tickConfig.dayFormat.format(t),this.dayEl.appendChild(n)}}}renderDayLabelsWithBounds(e,t){let n=this.getVisibleDayDates(e),r=this.scale.getVisibleDays(),i=n.length,a=i>0?this.scale.width/i:this.scale.width,o=a<150?new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}):t;if(r&&r.length>0)for(let t of n){let n=new Date(t);n.setHours(0,0,0,0),n.setMinutes(e.startMin);let r=this.scale.timeToX(n),i=document.createElement(`div`);i.className=wz,i.style.left=`${r}px`,i.style.maxWidth=`${Math.floor(a)-4}px`,i.dataset.day=Oz(t),i.textContent=o.format(n),this.dayEl.appendChild(i)}else{let t=this.scale.width;for(let r of n){let n=new Date(r);n.setHours(0,0,0,0),n.setMinutes(e.startMin);let i=new Date(r);i.setHours(0,0,0,0),i.setDate(i.getDate()+1),i.setMinutes(e.startMin);let a=this.scale.timeToX(n),s=this.scale.timeToX(i),c=Math.max(a,0),l=Math.min(s,t)-c;if(l<=0)continue;let u=document.createElement(`div`);u.className=wz,u.style.left=`${c}px`,u.style.maxWidth=`${l}px`,u.dataset.day=Oz(r),u.textContent=o.format(n),this.dayEl.appendChild(u)}}}renderHourTicks(){this.hourEl.innerHTML=``;let{hourFormat:e}=this.tickConfig,t=this.tickConfig.scale,n=this.tickConfig.step,r=this.scale.getDailyBounds();if(r&&t===`hour`){this.renderHourTicksWithBounds(r,n,e);return}let i=this.scale.start.getTime(),a=this.scale.end.getTime();if(t===`hour`){let t=new Set(kz(i,a).map(e=>e.getTime())),r=Az(i,a,n);for(let n of r){if(t.has(n.getTime()))continue;let r=this.scale.timeToX(n),i=document.createElement(`div`);i.className=Tz,i.style.left=`${r}px`,i.textContent=e.format(n),this.hourEl.appendChild(i)}}else if(t===`day`){let e=new Set(jz(i,a).map(e=>e.getTime())),t=kz(i,a);for(let n of t){if(e.has(n.getTime()))continue;let t=this.scale.timeToX(n),r=document.createElement(`div`);r.className=Tz,r.style.left=`${t}px`,r.textContent=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}).format(n),this.hourEl.appendChild(r)}}}renderHourTicksWithBounds(e,t,n){let r=this.getVisibleDayDates(e);for(let i of r){let r=new Date(i);r.setHours(0,0,0,0),r.setMinutes(e.startMin);let a=new Date(i);a.setHours(0,0,0,0),a.setMinutes(e.endMin);let o=Math.ceil(e.startMin/60),s=new Date(i);for(s.setHours(o,0,0,0),s.getHours()%t!==0&&s.setHours(s.getHours()+(t-s.getHours()%t));s.getTime()<=a.getTime();){if(s.getTime()!==r.getTime()){let e=this.scale.timeToX(s),t=document.createElement(`div`);t.className=Tz,t.style.left=`${e}px`,t.textContent=n.format(s),this.hourEl.appendChild(t)}s.setHours(s.getHours()+t)}}}getVisibleDayDates(e){let t=this.scale.getVisibleDays();if(t&&t.length>0)return t.map(e=>new Date(e+`T00:00:00`));let n=this.scale.start.getTime(),r=this.scale.end.getTime(),i=[],a=new Date(n);for(a.setHours(0,0,0,0);;){let t=new Date(a);if(t.setHours(0,0,0,0),t.setMinutes(e.endMin),t.getTime()<n){a.setDate(a.getDate()+1);continue}let o=new Date(a);if(o.setHours(0,0,0,0),o.setMinutes(e.startMin),o.getTime()>r)break;i.push(new Date(a)),a.setDate(a.getDate()+1)}return i}renderGridlines(e,t){e.querySelectorAll(`.tg-gridline`).forEach(e=>e.remove());let n=this.computeTickPositions();for(let{x:r,isMajor:i}of n){let n=document.createElement(`div`);n.className=i?`tg-gridline tg-gridline-major`:`tg-gridline`,n.style.left=`${r}px`,n.style.height=`${t}px`,e.appendChild(n)}}computeTickPositions(){let e=[],t=this.tickConfig.scale,n=this.tickConfig.step,r=this.scale.getDailyBounds(),i=this.scale.start.getTime(),a=this.scale.end.getTime();if(r&&t===`hour`){let t=this.getVisibleDayDates(r);for(let i of t){let t=new Date(i);t.setHours(0,0,0,0),t.setMinutes(r.startMin);let a=new Date(i);a.setHours(0,0,0,0),a.setMinutes(r.endMin),e.push({x:this.scale.timeToX(t),isMajor:!0});let o=Math.ceil(r.startMin/60),s=new Date(i);for(s.setHours(o,0,0,0),s.getHours()%n!==0&&s.setHours(s.getHours()+(n-s.getHours()%n));s.getTime()<=a.getTime();)s.getTime()!==t.getTime()&&e.push({x:this.scale.timeToX(s),isMajor:!1}),s.setHours(s.getHours()+n)}}else if(t===`hour`){let t=kz(i,a),r=new Set(t.map(e=>e.getTime()));for(let n of t)e.push({x:this.scale.timeToX(n),isMajor:!0});for(let t of Az(i,a,n))r.has(t.getTime())||e.push({x:this.scale.timeToX(t),isMajor:!1})}else if(t===`day`){let t=jz(i,a),n=new Set(t.map(e=>e.getTime()));for(let n of t)e.push({x:this.scale.timeToX(n),isMajor:!0});for(let t of kz(i,a))n.has(t.getTime())||e.push({x:this.scale.timeToX(t),isMajor:!1})}return e}destroy(){this.dayEl.remove(),this.hourEl.remove()}};function Dz(e){let t=e?.scale??`hour`,n=e?.step??1;switch(t){case`hour`:return{scale:t,step:n,hourFormat:new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,hour12:!1}),dayFormat:new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`})};case`day`:return{scale:t,step:n,hourFormat:new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),dayFormat:new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`})};default:return{scale:`hour`,step:1,hourFormat:new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,hour12:!1}),dayFormat:new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`})}}}function Oz(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function kz(e,t){let n=[],r=new Date(e);for(r.setHours(0,0,0,0);r.getTime()<=t;)r.getTime()>=e&&n.push(new Date(r)),r.setDate(r.getDate()+1);return n}function Az(e,t,n){let r=[],i=new Date(e);i.setMinutes(0,0,0);let a=i.getHours();for(i.setHours(a-a%n);i.getTime()<=t;)i.getTime()>=e&&r.push(new Date(i)),i.setHours(i.getHours()+n);return r}function jz(e,t){let n=[],r=new Date(e);r.setHours(0,0,0,0);let i=r.getDay(),a=i===0?6:i-1;for(r.setDate(r.getDate()-a);r.getTime()<=t;)r.getTime()>=e&&n.push(new Date(r)),r.setDate(r.getDate()+7);return n}var Mz=class{constructor(e=40){this.groups=[],this.groupIndex=new Map,this.rowHeight=e,this.labelPanel=document.createElement(`div`),this.labelPanel.className=`tg-label-panel`,this.labelPanel.setAttribute(`role`,`rowheader`),this.contentArea=document.createElement(`div`),this.contentArea.className=`tg-content`,this.contentArea.setAttribute(`role`,`grid`)}getLabelPanel(){return this.labelPanel}getContentArea(){return this.contentArea}getRowHeight(){return this.rowHeight}getGroups(){return this.groups}getGroupCount(){return this.groups.length}getGroupAtIndex(e){return this.groups[e]}yToGroupId(e){let t=Math.floor(e/this.rowHeight);return t<0||t>=this.groups.length?null:this.groups[t].id}groupIdToRowIndex(e){return this.groupIndex.get(e)??-1}getRowRange(e,t){let n=Math.max(0,Math.floor(Math.min(e,t)/this.rowHeight)),r=Math.min(this.groups.length-1,Math.floor(Math.max(e,t)/this.rowHeight)),i=[];for(let e=n;e<=r;e++)i.push(this.groups[e].id);return i}getRowTop(e){return e*this.rowHeight}setGroups(e){this.groups=e.slice().sort((e,t)=>e.order!==void 0&&t.order!==void 0?e.order-t.order:e.order===void 0?t.order===void 0?e.content.localeCompare(t.content,void 0,{numeric:!0}):1:-1),this.groupIndex.clear();for(let e=0;e<this.groups.length;e++)this.groupIndex.set(this.groups[e].id,e)}render(){this.renderLabels(),this.renderRows()}renderLabels(){this.labelPanel.innerHTML=``;for(let e of this.groups){let t=document.createElement(`div`);t.className=`tg-label`,t.style.height=`${this.rowHeight}px`,t.textContent=e.content,t.title=e.content,t.dataset.groupId=e.id,this.labelPanel.appendChild(t)}}renderRows(){this.contentArea.querySelectorAll(`.tg-row`).forEach(e=>e.remove());for(let e=0;e<this.groups.length;e++){let t=document.createElement(`div`);t.className=`tg-row`,t.style.height=`${this.rowHeight}px`,t.style.top=`${e*this.rowHeight}px`,t.dataset.groupId=this.groups[e].id,this.contentArea.appendChild(t)}this.contentArea.style.height=`${this.groups.length*this.rowHeight}px`}destroy(){this.labelPanel.remove(),this.contentArea.remove()}},Nz=class{constructor(e,t){this.items=[],this.itemElements=new Map,this.ghostEl=null,this.ghostCountBadge=null,this.scale=e,this.layout=t,this.contentArea=t.getContentArea()}setItems(e){this.items=e}render(){for(let e of this.itemElements.values())e.remove();this.itemElements.clear(),this.contentArea.querySelectorAll(`[data-item-id]`).forEach(e=>{e.dataset.itemId!==`__ghost__`&&e.remove()});for(let e of this.items){let t=this.renderItem(e);t&&(this.contentArea.appendChild(t),this.itemElements.set(e.id,t))}}renderItem(e){let t=this.layout.groupIdToRowIndex(e.group);if(t===-1)return null;let n=e.start instanceof Date?e.start:new Date(e.start),r=e.end?e.end instanceof Date?e.end:new Date(e.end):n,i=this.scale.timeToX(n),a=this.scale.timeToX(r)-i,o=this.layout.getRowTop(t),s=this.layout.getRowHeight();if(a<.5)return null;let c=document.createElement(`div`);if(c.dataset.itemId=e.id,c.title=e.title||e.content,e.type===`background`||e.isSegment)c.className=`tg-item-background ${e.className||``}`.trim(),e.style&&(c.style.cssText=e.style),c.style.position=`absolute`,c.style.left=`${i}px`,c.style.top=`${o}px`,c.style.width=`${a}px`,c.style.height=`${s}px`,c.style.pointerEvents=`none`;else{c.className=`tg-item tg-item-range ${e.className||``}`.trim(),e.style&&(c.style.cssText+=e.style),c.style.position=`absolute`,c.style.left=`${i}px`,c.style.top=`${o+2}px`,c.style.width=`${a}px`,c.style.height=`${s-4}px`,c.style.cursor=`move`;let t=document.createElement(`span`);t.className=`tg-item-content`,t.textContent=e.content,c.appendChild(t);let n=document.createElement(`div`);n.className=`tg-resize-handle tg-resize-left`,n.dataset.handle=`left`,c.appendChild(n);let r=document.createElement(`div`);r.className=`tg-resize-handle tg-resize-right`,r.dataset.handle=`right`,c.appendChild(r)}return c}updateItemPosition(e,t,n,r){let i=this.itemElements.get(e);i&&(i.style.left=`${t}px`,i.style.top=`${n+2}px`,i.style.width=`${r}px`)}showGhost(e){if(!this.ghostEl){this.ghostEl=document.createElement(`div`),this.ghostEl.className=`tg-ghost`,this.ghostEl.dataset.itemId=`__ghost__`;for(let e of[`left`,`right`,`top`,`bottom`]){let t=document.createElement(`div`);t.className=`tg-resize-handle tg-resize-${e}`,t.dataset.handle=e,this.ghostEl.appendChild(t)}this.ghostCountBadge=document.createElement(`div`),this.ghostCountBadge.className=`tg-ghost-count`,this.ghostEl.appendChild(this.ghostCountBadge),this.contentArea.appendChild(this.ghostEl)}let t=this.scale.timeToX(e.startTime),n=this.scale.timeToX(e.endTime)-t,r=this.layout.getRowHeight(),i=e.topRowIndex*r,a=(e.bottomRowIndex-e.topRowIndex+1)*r,o=e.bottomRowIndex-e.topRowIndex+1;this.ghostEl.style.left=`${t}px`,this.ghostEl.style.top=`${i}px`,this.ghostEl.style.width=`${n}px`,this.ghostEl.style.height=`${a}px`,this.ghostEl.style.display=`block`,this.ghostCountBadge&&(this.ghostCountBadge.textContent=`${o} court${o>1?`s`:``}`,this.ghostCountBadge.style.display=o>1?`flex`:`none`)}clearGhost(){this.ghostEl&&(this.ghostEl.remove(),this.ghostEl=null,this.ghostCountBadge=null)}isGhostVisible(){return this.ghostEl!==null&&this.ghostEl.style.display!==`none`}highlightRows(e){this.clearHighlights();for(let t of e){let e=this.contentArea.querySelectorAll(`.tg-row`);e[t]&&e[t].classList.add(`tg-row-highlight`)}}clearHighlights(){this.contentArea.querySelectorAll(`.tg-row-highlight`).forEach(e=>{e.classList.remove(`tg-row-highlight`)})}static hitTest(e){if(!(e instanceof HTMLElement))return{itemId:null,handle:null};let t=e.closest(`.tg-resize-handle`)?.dataset.handle??null;return{itemId:e.closest(`[data-item-id]`)?.dataset.itemId??null,handle:t}}destroy(){this.clearGhost(),this.clearHighlights();for(let e of this.itemElements.values())e.remove();this.itemElements.clear()}},Pz=3,Fz=30,Iz=8,Lz=36e5,Rz=class{constructor(e,t,n,r,i=5,a=!1){this.mode=`IDLE`,this.gesture=null,this.items=[],this.ghostStartTime=null,this.ghostEndTime=null,this.ghostTopRow=0,this.ghostBottomRow=0,this.justDragged=!1,this.autoScrollRaf=null,this.autoScrollDelta=0,this.scrollContainer=null,this.onPointerDown=e=>{if(e.button!==0)return;let{itemId:t,handle:n}=Nz.hitTest(e.target);if(this.mode===`GHOST_EDITING`){if(t===`__ghost__`&&n){this.startGesture(e,`__ghost__`,n===`left`?`RESIZING_LEFT`:n===`right`?`RESIZING_RIGHT`:n===`top`?`RESIZING_TOP`:`RESIZING_BOTTOM`);return}if(t===`__ghost__`&&!n){this.confirmGhost();return}this.cancelGhost();return}if(t){if(n===`left`)this.startGesture(e,t,`RESIZING_LEFT`);else if(n===`right`)this.startGesture(e,t,`RESIZING_RIGHT`);else{let n=this.items.find(e=>e.id===t);if(!n||n.isSegment||n.type===`background`)return;this.startGesture(e,t,`DRAGGING`)}}},this.onPointerMove=e=>{if(this.gesture){if(this.gesture.currentX=e.clientX,this.gesture.currentY=e.clientY,!this.gesture.thresholdExceeded){let t=Math.abs(e.clientX-this.gesture.startX),n=Math.abs(e.clientY-this.gesture.startY);if(t<Pz&&n<Pz)return;this.gesture.thresholdExceeded=!0}switch(this.checkAutoScroll(e),this.mode){case`DRAGGING`:this.handleDragMove(e);break;case`RESIZING_LEFT`:case`RESIZING_RIGHT`:this.gesture.itemId===`__ghost__`?this.handleGhostTimeResize(e):this.handleResizeMove(e);break;case`RESIZING_TOP`:case`RESIZING_BOTTOM`:this.handleGhostRowResize(e)}}},this.onPointerUp=e=>{if(document.removeEventListener(`pointermove`,this.onPointerMove),document.removeEventListener(`pointerup`,this.onPointerUp),this.stopAutoScroll(),!this.gesture){this.mode=`IDLE`;return}let t=this.gesture.itemId===`__ghost__`;if(!this.gesture.thresholdExceeded&&!t){this.gesture.itemId&&this.callbacks.onItemClick?.(this.gesture.itemId,e),this.gesture=null,this.mode=`IDLE`,this.renderer.clearHighlights();return}if(t){this.gesture=null,this.mode=`GHOST_EDITING`;return}if(this.gesture.itemId&&this.gesture.thresholdExceeded){this.justDragged=!0,setTimeout(()=>this.justDragged=!1,300);let t=(e.clientX-this.gesture.startX)*this.scale.msPerPx,n=this.gesture.originalEnd.getTime()-this.gesture.originalStart.getTime(),r,i,a=this.gesture.originalGroup;if(this.mode===`DRAGGING`){r=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),i=new Date(r.getTime()+n);let o=this.contentArea.getBoundingClientRect(),s=e.clientY-o.top+this.contentArea.scrollTop;a=this.layout.yToGroupId(s)||this.gesture.originalGroup}else this.mode===`RESIZING_LEFT`?(r=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),i=this.gesture.originalEnd,r>=i&&(r=new Date(i.getTime()-this.snapMinutes*60*1e3))):(r=this.gesture.originalStart,i=this.scale.snap(new Date(this.gesture.originalEnd.getTime()+t),this.snapMinutes),i<=r&&(i=new Date(r.getTime()+this.snapMinutes*60*1e3)));this.callbacks.onMove?.({id:this.gesture.itemId,group:a,start:r,end:i})}this.gesture=null,this.mode=`IDLE`,this.renderer.clearHighlights()},this.onDblClick=e=>{if(this.justDragged)return;let{itemId:t}=Nz.hitTest(e.target);if(t)return;let n=this.contentArea.getBoundingClientRect(),r=e.clientX-n.left+this.contentArea.scrollLeft,i=e.clientY-n.top+this.contentArea.scrollTop,a=this.scale.xToTime(r),o=this.scale.snap(a,this.snapMinutes),s=new Date(o.getTime()+Lz),c=this.layout.yToGroupId(i);if(!c)return;let l=this.layout.groupIdToRowIndex(c);l<0||(this.ghostStartTime=o,this.ghostEndTime=s,this.ghostTopRow=l,this.ghostBottomRow=l,this.mode=`GHOST_EDITING`,this.renderer.showGhost({startTime:o,endTime:s,topRowIndex:l,bottomRowIndex:l}),this.renderer.highlightRows([l]))},this.onWheel=e=>{if(!((e.ctrlKey||e.metaKey)&&!this.enablePinchZoom)){if(e.preventDefault(),(e.ctrlKey||e.metaKey)&&this.enablePinchZoom){let t=e.deltaY>0?1.15:.87,n=this.contentArea.getBoundingClientRect(),r=e.clientX-n.left;this.scale.zoom(t,r)}else if(e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY)){let t=e.deltaX||e.deltaY;this.scale.pan(t)}else{this.scrollContainer&&(this.scrollContainer.scrollTop+=e.deltaY);return}this.onScaleChanged?.()}},this.onScaleChanged=null,this.onKeyDown=e=>{e.key===`Escape`&&this.mode===`GHOST_EDITING`&&this.cancelGhost()},this.scale=e,this.layout=t,this.renderer=n,this.contentArea=t.getContentArea(),this.wheelTarget=this.contentArea,this.callbacks=r,this.snapMinutes=i,this.enablePinchZoom=a}setItems(e){this.items=e}setScrollContainer(e){this.scrollContainer=e}setWheelTarget(e){this.wheelTarget=e}attach(){this.contentArea.addEventListener(`pointerdown`,this.onPointerDown),this.contentArea.addEventListener(`dblclick`,this.onDblClick),this.wheelTarget.addEventListener(`wheel`,this.onWheel,{passive:!1}),document.addEventListener(`keydown`,this.onKeyDown)}detach(){this.contentArea.removeEventListener(`pointerdown`,this.onPointerDown),this.contentArea.removeEventListener(`dblclick`,this.onDblClick),this.wheelTarget.removeEventListener(`wheel`,this.onWheel),document.removeEventListener(`keydown`,this.onKeyDown),document.removeEventListener(`pointermove`,this.onPointerMove),document.removeEventListener(`pointerup`,this.onPointerUp),this.stopAutoScroll()}getMode(){return this.mode}startGesture(e,t,n){e.preventDefault();let r=this.items.find(e=>e.id===t),i,a,o;if(t===`__ghost__`)i=this.ghostStartTime,a=this.ghostEndTime,o=``;else if(r)i=r.start instanceof Date?r.start:new Date(r.start),a=r.end?r.end instanceof Date?r.end:new Date(r.end):i,o=r.group;else return;this.gesture={mode:n,itemId:t,startX:e.clientX,startY:e.clientY,originalStart:i,originalEnd:a,originalGroup:o,currentX:e.clientX,currentY:e.clientY,thresholdExceeded:!1},this.mode=n,this.contentArea.setPointerCapture(e.pointerId),document.addEventListener(`pointermove`,this.onPointerMove),document.addEventListener(`pointerup`,this.onPointerUp)}handleDragMove(e){if(!this.gesture||!this.gesture.itemId)return;let t=(e.clientX-this.gesture.startX)*this.scale.msPerPx,n=this.gesture.originalEnd.getTime()-this.gesture.originalStart.getTime(),r=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),i=new Date(r.getTime()+n),a=this.contentArea.getBoundingClientRect(),o=e.clientY-a.top+this.contentArea.scrollTop,s=this.layout.yToGroupId(o)||this.gesture.originalGroup;if(this.callbacks.onMoving){let e=this.callbacks.onMoving({id:this.gesture.itemId,group:s,start:r,end:i});if(e===null)return;r=e.start,i=e.end}let c=this.scale.timeToX(r),l=this.scale.timeToX(i)-c,u=this.layout.groupIdToRowIndex(s),d=this.layout.getRowTop(u>=0?u:0);this.renderer.updateItemPosition(this.gesture.itemId,c,d,l),u>=0&&this.renderer.highlightRows([u])}handleResizeMove(e){if(!this.gesture||!this.gesture.itemId)return;let t=(e.clientX-this.gesture.startX)*this.scale.msPerPx,n=this.gesture.originalStart,r=this.gesture.originalEnd;if(this.mode===`RESIZING_LEFT`?(n=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),n>=r&&(n=new Date(r.getTime()-this.snapMinutes*60*1e3))):(r=this.scale.snap(new Date(this.gesture.originalEnd.getTime()+t),this.snapMinutes),r<=n&&(r=new Date(n.getTime()+this.snapMinutes*60*1e3))),this.callbacks.onMoving){let e=this.callbacks.onMoving({id:this.gesture.itemId,group:this.gesture.originalGroup,start:n,end:r});if(e===null)return;n=e.start,r=e.end}let i=this.scale.timeToX(n),a=this.scale.timeToX(r)-i,o=this.layout.groupIdToRowIndex(this.gesture.originalGroup),s=this.layout.getRowTop(o>=0?o:0);this.renderer.updateItemPosition(this.gesture.itemId,i,s,a)}handleGhostTimeResize(e){if(!this.gesture)return;let t=this.contentArea.getBoundingClientRect(),n=e.clientX-t.left+this.contentArea.scrollLeft,r=this.scale.snap(this.scale.xToTime(n),this.snapMinutes);this.mode===`RESIZING_LEFT`?r<this.ghostEndTime&&(this.ghostStartTime=r):r>this.ghostStartTime&&(this.ghostEndTime=r),this.updateGhostDisplay()}handleGhostRowResize(e){if(!this.gesture)return;let t=this.contentArea.getBoundingClientRect(),n=e.clientY-t.top+this.contentArea.scrollTop,r=Math.floor(n/this.layout.getRowHeight()),i=Math.max(0,Math.min(this.layout.getGroupCount()-1,r));this.mode===`RESIZING_TOP`?i<=this.ghostBottomRow&&(this.ghostTopRow=i):i>=this.ghostTopRow&&(this.ghostBottomRow=i),this.updateGhostDisplay()}updateGhostDisplay(){this.renderer.showGhost({startTime:this.ghostStartTime,endTime:this.ghostEndTime,topRowIndex:this.ghostTopRow,bottomRowIndex:this.ghostBottomRow});let e=[];for(let t=this.ghostTopRow;t<=this.ghostBottomRow;t++)e.push(t);this.renderer.highlightRows(e)}confirmGhost(){if(!this.ghostStartTime||!this.ghostEndTime){this.cancelGhost();return}let e=[];for(let t=this.ghostTopRow;t<=this.ghostBottomRow;t++){let n=this.layout.getGroupAtIndex(t);n&&e.push(n.id)}if(e.length===0){this.cancelGhost();return}let t={groupIds:e,topRowIndex:this.ghostTopRow,bottomRowIndex:this.ghostBottomRow,startTime:this.ghostStartTime,endTime:this.ghostEndTime};this.renderer.clearGhost(),this.renderer.clearHighlights(),this.mode=`IDLE`,this.callbacks.onMultiRowCreate?.(t),this.ghostStartTime=null,this.ghostEndTime=null}cancelGhost(){this.renderer.clearGhost(),this.renderer.clearHighlights(),this.mode=`IDLE`,this.ghostStartTime=null,this.ghostEndTime=null}checkAutoScroll(e){if(!this.scrollContainer)return;let t=this.scrollContainer.getBoundingClientRect(),n=t.bottom-e.clientY,r=e.clientY-t.top;n<Fz?(this.autoScrollDelta=Iz*(1-n/Fz),this.startAutoScroll()):r<Fz?(this.autoScrollDelta=-8*(1-r/Fz),this.startAutoScroll()):this.stopAutoScroll()}startAutoScroll(){if(this.autoScrollRaf!==null)return;let e=()=>{this.scrollContainer&&(this.scrollContainer.scrollTop+=this.autoScrollDelta,this.autoScrollRaf=requestAnimationFrame(e))};this.autoScrollRaf=requestAnimationFrame(e)}stopAutoScroll(){this.autoScrollRaf!==null&&(cancelAnimationFrame(this.autoScrollRaf),this.autoScrollRaf=null),this.autoScrollDelta=0}},zz=class{constructor(e,t,n,r={}){this.callbacks={},this.resizeObserver=null,this._batchUpdating=!1,this.eventListeners=new Map,this.options={rowHeight:40,...r};let i=new Date,a=r.start||i,o=r.end||new Date(i.getTime()+432e5),s=e.clientWidth||800;this.scale=new Cz(a,o,s),(r.min||r.max||r.zoomMin||r.zoomMax)&&this.scale.setLimits({min:r.min,max:r.max,zoomMin:r.zoomMin,zoomMax:r.zoomMax}),this.timeAxis=new Ez(this.scale,r.timeAxis),this.layout=new Mz(this.options.rowHeight),this.renderer=new Nz(this.scale,this.layout),this.interaction=new Rz(this.scale,this.layout,this.renderer,this.callbacks,5,r.enablePinchZoom??!1),this.rootEl=document.createElement(`div`),this.rootEl.className=`tg-timeline`,r.height&&(this.rootEl.style.height=r.height);let c=document.createElement(`div`);c.className=`tg-axis-header`;let l=document.createElement(`div`);l.className=`tg-axis-spacer`,c.appendChild(l),c.appendChild(this.timeAxis.getDayElement()),c.appendChild(this.timeAxis.getHourElement()),this.rootEl.appendChild(c),this.bodyEl=document.createElement(`div`),this.bodyEl.className=`tg-body`,this.bodyEl.appendChild(this.layout.getLabelPanel());let u=document.createElement(`div`);u.className=`tg-scroll-wrapper`,u.appendChild(this.layout.getContentArea()),this.bodyEl.appendChild(u),this.rootEl.appendChild(this.bodyEl),e.appendChild(this.rootEl),u.addEventListener(`scroll`,()=>{this.layout.getLabelPanel().scrollTop=u.scrollTop}),this.interaction.setScrollContainer(u),this.interaction.setWheelTarget(this.rootEl),this.interaction.onScaleChanged=()=>this.renderAll(),this.layout.setGroups(n),this.renderer.setItems(t),this.interaction.setItems(t),this.interaction.attach(),this.renderAll(),this.resizeObserver=new ResizeObserver(()=>{let t=u.clientWidth||e.clientWidth;this.scale.setWidth(t),this.renderAll()}),this.resizeObserver.observe(u)}setGroups(e){this.layout.setGroups(e),this.renderAll()}setItems(e){this.renderer.setItems(e),this.interaction.setItems(e),this.renderAll()}setWindow(e,t,n){this.scale.setWindow(e,t),this.renderAll()}setOptions(e){(e.min!==void 0||e.max!==void 0||e.zoomMin!==void 0||e.zoomMax!==void 0)&&this.scale.setLimits({min:e.min,max:e.max,zoomMin:e.zoomMin,zoomMax:e.zoomMax}),e.timeAxis&&this.timeAxis.setTimeAxisOptions(e.timeAxis),e.rowHeight!==void 0&&(this.options.rowHeight=e.rowHeight),Object.assign(this.options,e),this.renderAll()}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,new Set),this.eventListeners.get(e).add(t),e===`click`&&(this.callbacks.onItemClick=(e,t)=>{this.emit(`click`,{item:e,event:t})})}off(e,t){this.eventListeners.get(e)?.delete(t)}emit(e,t){let n=this.eventListeners.get(e);if(n)for(let e of n)e(t)}onMultiRowCreate(e){this.callbacks.onMultiRowCreate=e}onAdd(e){this.callbacks.onAdd=e}onMove(e){this.callbacks.onMove=e}onMoving(e){this.callbacks.onMoving=e}onDayClick(e){this.timeAxis.onDayClick=e}getContentElement(){return this.layout.getContentArea()}setDailyBounds(e,t){this.scale.setDailyBounds(e,t),this.renderAll()}clearDailyBounds(){this.scale.clearDailyBounds(),this.renderAll()}setVisibleDays(e){this.scale.setVisibleDays(e),this.renderAll()}clearVisibleDays(){this.scale.clearVisibleDays(),this.renderAll()}beginBatchUpdate(){this._batchUpdating=!0}endBatchUpdate(){this._batchUpdating=!1,this.renderAll()}renderAll(){if(this._batchUpdating)return;this.timeAxis.render(),this.layout.render(),this.renderer.render();let e=this.layout.getContentArea(),t=this.layout.getGroupCount()*(this.options.rowHeight??40);this.timeAxis.renderGridlines(e,t)}destroy(){this.interaction.detach(),this.resizeObserver?.disconnect(),this.timeAxis.destroy(),this.layout.destroy(),this.renderer.destroy(),this.rootEl.remove(),this.eventListeners.clear()}},{BLOCK_TYPES:Bz}=t.availability,Vz=class{constructor(e,t){this.timeline=null,this.unsubscribe=null,this.currentItems=new Map,this.isRendering=!1,this.popoverManager=bz(),this.viewState=new OI,this.currentDay=null,this.currentView=`day`,this.selectedCourts=new Set,this.visibleCourts=null,this.handleOnMove=e=>{let t=LI(e.id);if(!t)return!1;let n=II(e.group),r=this.toLocalISO(e.start),i=this.toLocalISO(e.end),a=this.engine.moveBlock({blockId:t,newTimeRange:{start:r,end:i},newCourt:n||void 0});return a.conflicts.some(e=>e.severity===`ERROR`)?(this.showConflictDialog(a.conflicts),!1):(this.render(),!0)},this.handleOnMoving=e=>{this.popoverManager.destroy();let t=this.currentItems.get(e.id);if(t&&(t.isSegment||t.type===`background`))return null;let{start:n,end:r}=e,i=II(e.group);if(i){let e=n.toISOString().slice(0,10),t=this.engine.getCourtAvailability(i,e),a=new Date(`${e}T${t.startTime}:00`),o=new Date(`${e}T${t.endTime}:00`);n<a&&(n=a),r>o&&(r=o)}return{start:n,end:r}},this.handleTimelineClick=e=>{let t=e.item;if(!t){this.popoverManager.destroy();return}let n=this.currentItems.get(t);if(!n){this.popoverManager.destroy();return}if(n.isSegment||n.type===`background`){this.popoverManager.destroy();return}if(this.popoverManager.isActiveFor(t)){this.popoverManager.destroy();return}let r=LI(t);if(!r)return;let i=(e.event?.target)?.closest?.(`.tg-item`)??this.config.container.querySelector(`[data-item-id="${t}"]`);if(i){let e=String(n.start).slice(0,10);this.popoverManager.showForEngineBlock(i,{itemId:t,blockId:r,engine:this.engine,day:e,onBlockChanged:()=>this.render(),onManageRegistrations:this.config.onManageRegistrations})}this.config.onBlockSelected&&this.config.onBlockSelected(r)},this.handleMultiRowCreate=e=>{let t=[];for(let n of e.groupIds){let e=II(n);e&&t.push(e)}if(t.length===0)return;let n=this.toLocalISO(e.startTime),r=this.toLocalISO(e.endTime),i=this.engine.applyBlock({courts:t,timeRange:{start:n,end:r},type:Bz.BLOCKED,reason:`New Block`});if(this.render(),i.applied.length>0){let e=i.applied[0].block.id,t=`block-${e}`,r=n.slice(0,10);setTimeout(()=>{let n=this.config.container.querySelector(`[data-item-id="${t}"]`);n&&this.popoverManager.showForEngineBlock(n,{itemId:t,blockId:e,engine:this.engine,day:r,onBlockChanged:()=>this.render(),onManageRegistrations:this.config.onManageRegistrations})},50)}this.config.onTimeRangeSelected&&this.config.onTimeRangeSelected({courts:t,start:n,end:r})},this.handleEngineEvent=e=>{switch(e.type){case`STATE_CHANGED`:case`BLOCKS_CHANGED`:this.render(),e.type===`BLOCKS_CHANGED`&&this.config.onBlocksChanged&&this.config.onBlocksChanged();break;case`CONFLICTS_CHANGED`:this.config.showConflicts&&this.render();break;case`AVAILABILITY_CHANGED`:this.updateTimelineWindow(),this.render()}},this.engine=e,this.config={groupingMode:`BY_VENUE`,showConflicts:!0,showSegmentLabels:!1,colorScheme:kI,...t},this.initialize()}initialize(){if(this.config.initialDay)this.currentDay=this.config.initialDay;else{let e=this.engine.getActiveDays();this.currentDay=e.length>0?e[0]:t.tools.dateTime.extractDate(new Date().toISOString())}this.viewState.setSelectedDay(this.currentDay),this.config.initialView&&(this.currentView=this.config.initialView),this.unsubscribe=this.engine.subscribe(this.handleEngineEvent),this.ensureTimeline()}ensureTimeline(){this.timeline||setTimeout(()=>{this.timeline||this.createTimelineWithData()},0)}getViewDays(){if(!this.currentDay)return[];let e=xz[this.currentView],t=e?e.days:1;if(t<=0)return this.engine.getActiveDays();if(t<=1)return[this.currentDay];let n=this.engine.getActiveDays(),r=n.indexOf(this.currentDay);return r===-1?[this.currentDay]:n.slice(r,r+t)}buildViewData(){if(!this.currentDay)return{groups:[],items:[]};let e=this.getViewDays(),t=this.engine.listCourtMeta(),n=this.viewState.getLayerVisibility(),r={groupingMode:this.config.groupingMode,layerVisibility:n,showSegmentLabels:this.config.showSegmentLabels,colorScheme:this.config.colorScheme},i=AI(this.engine.getDayTimeline(e[0]),t,r);this.visibleCourts!==null&&this.visibleCourts.size>0&&(i=i.filter(e=>this.visibleCourts.has(String(e.id))));let a=this.visibleCourts!==null&&this.visibleCourts.size>0&&i.length>0?new Set(i.map(e=>String(e.id))):null,o=e.length<=1?this.engine.getActiveDays():e,s=[],c=[];for(let e of o){let t=this.engine.getDayTimeline(e);s.push(...jI(t,r)),c.push(...NI(this.engine.getDayBlocks(e),r))}let l=a?s.filter(e=>a.has(String(e.group))):s,u=a?c.filter(e=>a.has(String(e.group))):c,d=[...l,...u];return{groups:i.map((e,t)=>({id:String(e.id),content:typeof e.content==`string`?e.content:``,order:t,courtRef:e.courtRef,surface:e.surface,indoor:e.indoor,hasLights:e.hasLights,tags:e.tags})),items:d.map(e=>({id:String(e.id),group:String(e.group),content:e.content,start:e.start,end:e.end,type:e.type===`background`?`background`:`range`,className:e.className,style:e.style,title:e.title,editable:e.editable,blockId:e.blockId,status:e.status,reason:e.reason,isBlock:e.isBlock,isSegment:e.isSegment,isConflict:e.isConflict}))}}createTimelineWithData(){let e=this.engine.getConfig(),n=this.currentDay||t.tools.dateTime.extractDate(new Date().toISOString()),r=this.getViewDays(),i=r[0]||n,a=r[r.length-1]||n,o=this.engine.getVisibleTimeRange(i),s=this.engine.getVisibleTimeRange(a),c=RI({dayStartTime:o.startTime,dayEndTime:o.endTime,slotMinutes:e.slotMinutes,day:i}),l=xz[this.currentView],u=r.length>1?new Date(`${a}T${s.endTime}:00`):c.end,d=this.engine.getActiveDays(),f=d[0]||i,p=d[d.length-1]||a,m=this.engine.getVisibleTimeRange(f),h=this.engine.getVisibleTimeRange(p),g=new Date(`${f}T${m.startTime}:00`),_=new Date(`${p}T${h.endTime}:00`),{groups:v,items:y}=this.buildViewData();this.currentItems.clear();for(let e of y)this.currentItems.set(e.id,e);this.timeline=new zz(this.config.container,y,v,{start:c.start,end:u,min:g,max:_,zoomMin:c.zoomMin,zoomMax:_.getTime()-g.getTime(),snap:e=>this.snapToMinutes(e,5),rowHeight:40,height:`100%`,timeAxis:l?l.timeAxis:{scale:`hour`,step:1},showTooltips:!0}),this.timeline.setDailyBounds(o.startTime,o.endTime),r.length>1&&this.timeline.setVisibleDays(r),this.timeline.on(`click`,this.handleTimelineClick),this.timeline.onMove(this.handleOnMove),this.timeline.onMoving(this.handleOnMoving),this.timeline.onMultiRowCreate(this.handleMultiRowCreate),this.timeline.onDayClick(e=>{this.setDay(e),this.setViewPreset(`day`),this.config.onDayNavigate?.(e)}),this.config.onBlocksChanged?.()}setDay(e){this.currentDay!==e&&(this.currentDay=e,this.viewState.setSelectedDay(e),this.updateTimelineWindow(),this.render())}getDay(){return this.currentDay}setView(e){this.currentView=e,this.updateTimelineWindow()}setViewPreset(e){let t=xz[e];if(!t||!this.timeline||!this.currentDay)return;this.currentView=e;let n=this.getViewDays(),r=n[0],i=n[n.length-1],a=this.engine.getVisibleTimeRange(r),o=this.engine.getVisibleTimeRange(i);this.timeline.beginBatchUpdate();let s=t.days===0||t.days>1;this.timeline.setDailyBounds(a.startTime,a.endTime),s?this.timeline.setVisibleDays(n):this.timeline.clearVisibleDays();let c=new Date(`${r}T${a.startTime}:00`),l=new Date(`${i}T${o.endTime}:00`);this.timeline.setWindow(c,l,{animation:!1}),this.timeline.setOptions({timeAxis:t.timeAxis});let{groups:u,items:d}=this.buildViewData();this.currentItems.clear();for(let e of d)this.currentItems.set(e.id,e);this.timeline.setGroups(u),this.timeline.setItems(d),this.timeline.endBatchUpdate(),this.config.onBlocksChanged?.()}setSelectedCourts(e){this.selectedCourts=new Set(e)}getSelectedCourts(){return Array.from(this.selectedCourts)}setVisibleCourts(e){this.visibleCourts=e&&e.size===0?null:e,this.render()}setLayerVisibility(e,t){this.viewState.setLayerVisibility(e,t),this.render()}refresh(){this.updateTimelineWindow(),this.render()}destroy(){this.popoverManager.destroy(),this.unsubscribe&&this.unsubscribe(),this.timeline&&=(this.timeline.destroy(),null)}updateTimelineWindow(){if(!this.timeline||!this.currentDay)return;let e=this.engine.getConfig(),t=this.getViewDays(),n=t[0]||this.currentDay,r=t[t.length-1]||this.currentDay,i=this.engine.getVisibleTimeRange(n),a=this.engine.getVisibleTimeRange(r),o=RI({dayStartTime:i.startTime,dayEndTime:i.endTime,slotMinutes:e.slotMinutes,day:n}),s=xz[this.currentView],c=t.length>1?new Date(`${r}T${a.endTime}:00`):o.end,l=this.engine.getActiveDays(),u=l[0]||n,d=l[l.length-1]||r,f=this.engine.getVisibleTimeRange(u),p=this.engine.getVisibleTimeRange(d),m=new Date(`${u}T${f.startTime}:00`),h=new Date(`${d}T${p.endTime}:00`);this.timeline.beginBatchUpdate(),this.timeline.setDailyBounds(i.startTime,i.endTime),t.length>1?this.timeline.setVisibleDays(t):this.timeline.clearVisibleDays(),this.timeline.setOptions({min:m,max:h}),this.timeline.setWindow(o.start,c,{animation:!1}),s&&this.timeline.setOptions({timeAxis:s.timeAxis}),this.timeline.endBatchUpdate()}render(){if(this.currentDay&&!this.isRendering){if(!this.timeline){this.ensureTimeline();return}this.isRendering=!0;try{let{groups:e,items:t}=this.buildViewData();this.currentItems.clear();for(let e of t)this.currentItems.set(e.id,e);this.timeline.setGroups(e),this.timeline.setItems(t)}finally{this.isRendering=!1}}}getPopoverManager(){return this.popoverManager}snapToMinutes(e,t){let n=e.getTime(),r=t*60*1e3,i=Math.round(n/r)*r;return new Date(i)}toLocalISO(e){let t=e=>e.toString().padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`}showConflictDialog(e){let t=e.filter(e=>e.severity===`ERROR`);if(t.length===0)return;if(this.config.onConflict){this.config.onConflict(t);return}let n=t.map(e=>e.message).join(`
248
- `);console.warn(`[availability-grid] cannot complete operation:\n${n}`)}getTimeline(){return this.timeline}getEngine(){return this.engine}getViewState(){return this.viewState}};function Hz(e){let t=e?.totalHours??`Total Hours`,n=e?.blocked??`Blocked`,r=e?.available??`Available`,i=e?.avgPerCourt??`Avg Avail/Court`,a=document.createElement(`div`);a.className=`tg-stats-bar`;let o=e=>{let t=document.createElement(`span`);return t.innerHTML=`${e}: <b>&mdash;</b>`,a.appendChild(t),t},s=o(t),c=o(n),l=o(r),u=o(i);return{element:a,update:e=>{s.innerHTML=`${t}: <b>${e.totalHours.toFixed(1)}h</b>`,c.innerHTML=`${n}: <b>${e.blockedHours.toFixed(1)}h</b>`,l.innerHTML=`${r}: <b>${e.availableHours.toFixed(1)}h</b>`,u.innerHTML=`${i}: <b>${e.avgPerCourt.toFixed(1)}h</b>`}}}var Uz,Wz,Gz,Kz=!1;async function qz(){if(!Uz){let e=await Promise.resolve().then(()=>(UR(),zI));Uz=e.TimepickerUI,Wz=e.PluginRegistry,Gz=(await Promise.resolve().then(()=>(sz(),WR))).RangePlugin,!Kz&&Wz&&Gz&&(Wz.register(Gz),Kz=!0)}}var Jz=0;async function Yz(e){let{title:t,currentDay:n,currentStartTime:r,currentEndTime:i,showScopeToggle:a=!0,venueBounds:o,onConfirm:s,onCancel:c,labels:l={}}=e;await qz();let u=new Date(n+`T12:00:00`).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`}),d=`tp-court-avail-${++Jz}`,f=a?`current-day`:`all-days`,p=document.createElement(`div`);p.className=`tg-modal`,p.style.cssText=`
247
+ `,l.addEventListener(`mouseenter`,()=>{l.style.background=zB,l.style.color=BB}),l.addEventListener(`mouseleave`,()=>{l.style.background=`transparent`,l.style.color=``}),l.addEventListener(`click`,()=>{let s=r.getDayBlocks(i).find(e=>e.id===t);s&&(r.removeBlock(t),r.applyBlock({courts:[s.court],timeRange:{start:s.start,end:s.end},type:e,reason:a}),o()),n()}),c.appendChild(l)}let l=document.createElement(`div`);l.style.cssText=`border-top:1px solid var(--chc-border-primary); margin:4px 0;`,c.appendChild(l);let u=document.createElement(`div`);u.style.cssText=RB,u.innerHTML=`<span style="font-size:14px;">&#128339;</span> Adjust Time`,u.addEventListener(`mouseenter`,()=>{u.style.background=zB,u.style.color=BB}),u.addEventListener(`mouseleave`,()=>{u.style.background=`transparent`,u.style.color=``}),u.addEventListener(`click`,()=>{n();let e=r.getDayBlocks(i).find(e=>e.id===t);e&&IB({startTime:e.start,endTime:e.end,dayStartTime:`06:00`,dayEndTime:`22:00`,minuteIncrement:5,onConfirm:(n,i)=>{let a=e.start.slice(0,10);r.resizeBlock({blockId:t,newTimeRange:{start:`${a}T${n}:00`,end:`${a}T${i}:00`}}),o()},onCancel:()=>{}})}),c.appendChild(u);let d=r.getDayBlocks(i).find(e=>e.id===t);if(s&&d?.type===LB.PRACTICE){let e=document.createElement(`div`);e.style.cssText=RB,e.innerHTML=`<span style="font-size:14px;">&#128101;</span> Manage Registrations`,e.addEventListener(`mouseenter`,()=>{e.style.background=zB,e.style.color=BB}),e.addEventListener(`mouseleave`,()=>{e.style.background=`transparent`,e.style.color=``}),e.addEventListener(`click`,()=>{n();let e=r.getDayBlocks(i).find(e=>e.id===t);e&&s({blockId:t,courtId:e.court.courtId,venueId:e.court.venueId,date:i,startTime:a(e.start),endTime:a(e.end)})}),c.appendChild(e)}let f=document.createElement(`div`);return f.style.cssText=`padding:6px 12px; cursor:pointer; display:flex; align-items:center; gap:8px; color:#e74c3c;`,f.innerHTML=`<span style="font-size:14px;">&#128465;</span> Delete`,f.addEventListener(`mouseenter`,()=>{f.style.background=`#fdecea`}),f.addEventListener(`mouseleave`,()=>{f.style.background=`transparent`}),f.addEventListener(`click`,()=>{r.removeBlock(t),o(),n()}),c.appendChild(f),c}function a(e){return(e.includes(`T`)?e.split(`T`)[1]:e).slice(0,5)}function o(r,i,a){n();let o=km(r,{content:i,allowHTML:!0,interactive:!0,trigger:`manual`,placement:`bottom`,appendTo:document.body,onHidden:()=>{e=null,t=null}});e=o,t=a,o.show()}return{show(e,i){if(t===i.itemId){n();return}o(e,r(i),i.itemId)},showForEngineBlock(e,r){if(t===r.itemId){n();return}o(e,i(r),r.itemId)},destroy(){n()},isActiveFor(e){return t===e}}}var UB={day:{label:`1 Day`,days:1,timeAxis:{scale:`hour`,step:1}},days3:{label:`3 Days`,days:3,timeAxis:{scale:`hour`,step:3}},week:{label:`Week`,days:7,timeAxis:{scale:`hour`,step:6}},all:{label:`Tournament`,days:0,timeAxis:{scale:`hour`,step:6}}};function WB(e,t,n,r){let i=r?.labels,a=document.createElement(`div`);a.className=`tg-view-toolbar`;let o=document.createElement(`span`);o.textContent=(i?.view??`View`)+`:`,o.className=`tg-view-toolbar-label`,a.appendChild(o);let s=document.createElement(`input`);s.type=`text`,s.readOnly=!0,s.className=`tg-view-toolbar-date`,n&&s.addEventListener(`changeDate`,()=>{let e=s.value;e&&n(e)}),a.appendChild(s);let c={day:i?.day1??`1 Day`,days3:i?.days3??`3 Days`,week:i?.week??`Week`,all:i?.tournament??`Tournament`},l=[],u=[],d=t||`day`,f=e=>{l.forEach((t,n)=>{t.className=u[n]===e?`sp-btn sp-btn--active`:`sp-btn`})};for(let[t]of Object.entries(UB)){let n=document.createElement(`button`);n.textContent=c[t],n.className=t===d?`sp-btn sp-btn--active`:`sp-btn`,n.addEventListener(`click`,()=>{f(t),e(t)}),l.push(n),u.push(t),a.appendChild(n)}if(r?.onSetDefaultAvailability||r?.onSave){let e=document.createElement(`div`);e.className=`tg-view-toolbar-spacer`,a.appendChild(e)}if(r?.onSetDefaultAvailability){let e=document.createElement(`button`);e.textContent=i?.setDefaultAvailability??`Set Default Availability`,e.className=`sp-btn sp-btn--fill-muted`,e.addEventListener(`click`,r.onSetDefaultAvailability),a.appendChild(e)}let p=null;return r?.onSave&&(p=document.createElement(`button`),p.textContent=i?.saveToTournament??`Save to Tournament`,p.className=`sp-btn sp-btn--fill`,p.disabled=!0,p.addEventListener(`click`,r.onSave),a.appendChild(p)),{element:a,dateInput:s,setActiveView:f,setDate:e=>{s.value=e},setSaveEnabled:e=>{p&&(p.disabled=!e)}}}var GB=class{constructor(e,t,n){this._dailyStartMin=0,this._dailyEndMin=1440,this._useDailyBounds=!1,this._visibleDays=null,this._visibleDayMs=null,this._start=e.getTime(),this._end=t.getTime(),this._width=Math.max(n,1),this._min=this._start,this._max=this._end,this._zoomMin=9e5,this._zoomMax=(this._end-this._start)*2}get start(){return new Date(this._start)}get end(){return new Date(this._end)}get width(){return this._width}get duration(){return this._end-this._start}get msPerPx(){if(!this._useDailyBounds)return this.duration/this._width;let e=this.toCollapsedMin(new Date(this._start)),t=this.toCollapsedMin(new Date(this._end))-e;return t<=0?1:t*60*1e3/this._width}getDailyBounds(){return this._useDailyBounds?{startMin:this._dailyStartMin,endMin:this._dailyEndMin}:null}getVisibleDays(){return this._visibleDays}timeToX(e){if(!this._useDailyBounds)return(e.getTime()-this._start)/this.duration*this._width;let t=this.toCollapsedMin(e),n=this.toCollapsedMin(new Date(this._start)),r=this.toCollapsedMin(new Date(this._end))-n;return r<=0?0:(t-n)/r*this._width}xToTime(e){if(!this._useDailyBounds){let t=e/this._width*this.duration;return new Date(this._start+t)}let t=this.toCollapsedMin(new Date(this._start)),n=this.toCollapsedMin(new Date(this._end))-t;if(n<=0)return new Date(this._start);let r=t+e/this._width*n;return this.fromCollapsedMin(r)}snap(e,t){let n=e.getTime(),r=t*60*1e3;return new Date(Math.round(n/r)*r)}setWindow(e,t){this._start=e.getTime(),this._end=t.getTime(),this.clampBounds()}setLimits(e){e.min!==void 0&&(this._min=e.min.getTime()),e.max!==void 0&&(this._max=e.max.getTime()),e.zoomMin!==void 0&&(this._zoomMin=e.zoomMin),e.zoomMax!==void 0&&(this._zoomMax=e.zoomMax)}setWidth(e){this._width=Math.max(e,1)}setDailyBounds(e,t){let[n,r]=e.split(`:`).map(Number),[i,a]=t.split(`:`).map(Number);this._dailyStartMin=n*60+r,this._dailyEndMin=i*60+a,this._useDailyBounds=!0}clearDailyBounds(){this._useDailyBounds=!1,this._dailyStartMin=0,this._dailyEndMin=1440,this._visibleDays=null,this._visibleDayMs=null}setVisibleDays(e){this._visibleDays=e,this._visibleDayMs=e.map(e=>new Date(e+`T00:00:00`).getTime())}clearVisibleDays(){this._visibleDays=null,this._visibleDayMs=null}pan(e){if(this._visibleDays)return;if(this._useDailyBounds){let t=this.toCollapsedMin(new Date(this._start)),n=this.toCollapsedMin(new Date(this._end)),r=n-t;if(r<=0)return;let i=e/this._width*r,a=this.fromCollapsedMin(t+i),o=this.fromCollapsedMin(n+i);this._start=a.getTime(),this._end=o.getTime(),this.clampBounds();return}let t=e*this.msPerPx,n=this._start+t,r=this._end+t;if(n<this._min){let e=this._min-n;n+=e,r+=e}if(r>this._max){let e=r-this._max;n-=e,r-=e}this._start=n,this._end=r}zoom(e,t){if(this._visibleDays)return;if(this._useDailyBounds){let n=this.toCollapsedMin(new Date(this._start)),r=this.toCollapsedMin(new Date(this._end))-n,i=n+t/this._width*r,a=r*e,o=this._zoomMin/6e4,s=this._zoomMax/6e4;a=Math.max(o,Math.min(s,a));let c=t/this._width,l=this.fromCollapsedMin(i-a*c),u=this.fromCollapsedMin(i+a*(1-c));this._start=l.getTime(),this._end=u.getTime(),this.clampBounds();return}let n=this._start+t/this._width*this.duration,r=this.duration*e;r=Math.max(this._zoomMin,Math.min(this._zoomMax,r));let i=t/this._width;this._start=n-r*i,this._end=n+r*(1-i),this.clampBounds()}toCollapsedMin(e){let t=this._dailyEndMin-this._dailyStartMin;if(t<=0)return 0;let n=e.getHours()*60+e.getMinutes()+e.getSeconds()/60,r=Math.max(this._dailyStartMin,Math.min(this._dailyEndMin,n))-this._dailyStartMin;if(this._visibleDays&&this._visibleDayMs){let n=new Date(e);n.setHours(0,0,0,0);let i=n.getTime(),a=-1;for(let e=0;e<this._visibleDayMs.length;e++)if(this._visibleDayMs[e]===i){a=e;break}if(a===-1){if(i<this._visibleDayMs[0])return 0;if(i>this._visibleDayMs[this._visibleDayMs.length-1])return this._visibleDayMs.length*t;for(let e=0;e<this._visibleDayMs.length-1;e++)if(i>this._visibleDayMs[e]&&i<this._visibleDayMs[e+1])return(e+1)*t;return 0}return a*t+r}let i=new Date(this._start);i.setHours(0,0,0,0);let a=new Date(e);return a.setHours(0,0,0,0),Math.round((a.getTime()-i.getTime())/864e5)*t+r}fromCollapsedMin(e){let t=this._dailyEndMin-this._dailyStartMin;if(t<=0)return new Date(this._start);let n=Math.floor(e/t),r=e-n*t;if(this._visibleDays&&this._visibleDayMs){let e=Math.max(0,Math.min(n,this._visibleDayMs.length-1)),t=new Date(this._visibleDayMs[e]),i=this._dailyStartMin+r;return t.setHours(Math.floor(i/60),Math.round(i%60),0,0),t}let i=new Date(this._start);i.setHours(0,0,0,0);let a=new Date(i);a.setDate(a.getDate()+n);let o=this._dailyStartMin+r;return a.setHours(Math.floor(o/60),Math.round(o%60),0,0),a}clampBounds(){let e=this._end-this._start;this._start<this._min&&(this._start=this._min,this._end=this._min+e),this._end>this._max&&(this._end=this._max,this._start=this._max-e),this._start<this._min&&(this._start=this._min),this._end>this._max&&(this._end=this._max)}},KB=`tg-tick-day`,qB=`tg-tick-hour`,JB=class{constructor(e,t){this.scale=e,this.tickConfig=YB(t),this.dayEl=document.createElement(`div`),this.dayEl.className=`tg-day-axis`,this.dayEl.setAttribute(`role`,`presentation`),this.hourEl=document.createElement(`div`),this.hourEl.className=`tg-hour-axis`,this.hourEl.setAttribute(`role`,`presentation`),this.dayEl.addEventListener(`click`,e=>{let t=(e.target.closest?.(`.${KB}`))?.dataset.day;t&&this.onDayClick&&this.onDayClick(t)})}getDayElement(){return this.dayEl}getHourElement(){return this.hourEl}setTimeAxisOptions(e){this.tickConfig=YB(e)}render(){this.renderDayLabels(),this.renderHourTicks()}renderDayLabels(){this.dayEl.innerHTML=``;let{dayFormat:e}=this.tickConfig,t=this.tickConfig.scale,n=this.scale.getDailyBounds();if(n&&t===`hour`){this.renderDayLabelsWithBounds(n,e);return}if(t===`hour`){let t=this.scale.start.getTime(),n=ZB(t,this.scale.end.getTime());if(n.length===0){let n=new Date(t);n.setHours(0,0,0,0);let r=document.createElement(`div`);r.className=KB,r.style.left=`0px`,r.style.maxWidth=`${this.scale.width}px`,r.dataset.day=XB(n),r.textContent=e.format(n),this.dayEl.appendChild(r);return}for(let t of n){let n=this.scale.timeToX(t),r=document.createElement(`div`);r.className=KB,r.style.left=`${n}px`,r.dataset.day=XB(t),r.textContent=e.format(t),this.dayEl.appendChild(r)}}else if(t===`day`){let e=$B(this.scale.start.getTime(),this.scale.end.getTime());for(let t of e){let e=this.scale.timeToX(t),n=document.createElement(`div`);n.className=KB,n.style.left=`${e}px`,n.dataset.day=XB(t),n.textContent=this.tickConfig.dayFormat.format(t),this.dayEl.appendChild(n)}}}renderDayLabelsWithBounds(e,t){let n=this.getVisibleDayDates(e),r=this.scale.getVisibleDays(),i=n.length,a=i>0?this.scale.width/i:this.scale.width,o=a<150?new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}):t;if(r&&r.length>0)for(let t of n){let n=new Date(t);n.setHours(0,0,0,0),n.setMinutes(e.startMin);let r=this.scale.timeToX(n),i=document.createElement(`div`);i.className=KB,i.style.left=`${r}px`,i.style.maxWidth=`${Math.floor(a)-4}px`,i.dataset.day=XB(t),i.textContent=o.format(n),this.dayEl.appendChild(i)}else{let t=this.scale.width;for(let r of n){let n=new Date(r);n.setHours(0,0,0,0),n.setMinutes(e.startMin);let i=new Date(r);i.setHours(0,0,0,0),i.setDate(i.getDate()+1),i.setMinutes(e.startMin);let a=this.scale.timeToX(n),s=this.scale.timeToX(i),c=Math.max(a,0),l=Math.min(s,t)-c;if(l<=0)continue;let u=document.createElement(`div`);u.className=KB,u.style.left=`${c}px`,u.style.maxWidth=`${l}px`,u.dataset.day=XB(r),u.textContent=o.format(n),this.dayEl.appendChild(u)}}}renderHourTicks(){this.hourEl.innerHTML=``;let{hourFormat:e}=this.tickConfig,t=this.tickConfig.scale,n=this.tickConfig.step,r=this.scale.getDailyBounds();if(r&&t===`hour`){this.renderHourTicksWithBounds(r,n,e);return}let i=this.scale.start.getTime(),a=this.scale.end.getTime();if(t===`hour`){let t=new Set(ZB(i,a).map(e=>e.getTime())),r=QB(i,a,n);for(let n of r){if(t.has(n.getTime()))continue;let r=this.scale.timeToX(n),i=document.createElement(`div`);i.className=qB,i.style.left=`${r}px`,i.textContent=e.format(n),this.hourEl.appendChild(i)}}else if(t===`day`){let e=new Set($B(i,a).map(e=>e.getTime())),t=ZB(i,a);for(let n of t){if(e.has(n.getTime()))continue;let t=this.scale.timeToX(n),r=document.createElement(`div`);r.className=qB,r.style.left=`${t}px`,r.textContent=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}).format(n),this.hourEl.appendChild(r)}}}renderHourTicksWithBounds(e,t,n){let r=this.getVisibleDayDates(e);for(let i of r){let r=new Date(i);r.setHours(0,0,0,0),r.setMinutes(e.startMin);let a=new Date(i);a.setHours(0,0,0,0),a.setMinutes(e.endMin);let o=Math.ceil(e.startMin/60),s=new Date(i);for(s.setHours(o,0,0,0),s.getHours()%t!==0&&s.setHours(s.getHours()+(t-s.getHours()%t));s.getTime()<=a.getTime();){if(s.getTime()!==r.getTime()){let e=this.scale.timeToX(s),t=document.createElement(`div`);t.className=qB,t.style.left=`${e}px`,t.textContent=n.format(s),this.hourEl.appendChild(t)}s.setHours(s.getHours()+t)}}}getVisibleDayDates(e){let t=this.scale.getVisibleDays();if(t&&t.length>0)return t.map(e=>new Date(e+`T00:00:00`));let n=this.scale.start.getTime(),r=this.scale.end.getTime(),i=[],a=new Date(n);for(a.setHours(0,0,0,0);;){let t=new Date(a);if(t.setHours(0,0,0,0),t.setMinutes(e.endMin),t.getTime()<n){a.setDate(a.getDate()+1);continue}let o=new Date(a);if(o.setHours(0,0,0,0),o.setMinutes(e.startMin),o.getTime()>r)break;i.push(new Date(a)),a.setDate(a.getDate()+1)}return i}renderGridlines(e,t){e.querySelectorAll(`.tg-gridline`).forEach(e=>e.remove());let n=this.computeTickPositions();for(let{x:r,isMajor:i}of n){let n=document.createElement(`div`);n.className=i?`tg-gridline tg-gridline-major`:`tg-gridline`,n.style.left=`${r}px`,n.style.height=`${t}px`,e.appendChild(n)}}computeTickPositions(){let e=[],t=this.tickConfig.scale,n=this.tickConfig.step,r=this.scale.getDailyBounds(),i=this.scale.start.getTime(),a=this.scale.end.getTime();if(r&&t===`hour`){let t=this.getVisibleDayDates(r);for(let i of t){let t=new Date(i);t.setHours(0,0,0,0),t.setMinutes(r.startMin);let a=new Date(i);a.setHours(0,0,0,0),a.setMinutes(r.endMin),e.push({x:this.scale.timeToX(t),isMajor:!0});let o=Math.ceil(r.startMin/60),s=new Date(i);for(s.setHours(o,0,0,0),s.getHours()%n!==0&&s.setHours(s.getHours()+(n-s.getHours()%n));s.getTime()<=a.getTime();)s.getTime()!==t.getTime()&&e.push({x:this.scale.timeToX(s),isMajor:!1}),s.setHours(s.getHours()+n)}}else if(t===`hour`){let t=ZB(i,a),r=new Set(t.map(e=>e.getTime()));for(let n of t)e.push({x:this.scale.timeToX(n),isMajor:!0});for(let t of QB(i,a,n))r.has(t.getTime())||e.push({x:this.scale.timeToX(t),isMajor:!1})}else if(t===`day`){let t=$B(i,a),n=new Set(t.map(e=>e.getTime()));for(let n of t)e.push({x:this.scale.timeToX(n),isMajor:!0});for(let t of ZB(i,a))n.has(t.getTime())||e.push({x:this.scale.timeToX(t),isMajor:!1})}return e}destroy(){this.dayEl.remove(),this.hourEl.remove()}};function YB(e){let t=e?.scale??`hour`,n=e?.step??1;switch(t){case`hour`:return{scale:t,step:n,hourFormat:new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,hour12:!1}),dayFormat:new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`})};case`day`:return{scale:t,step:n,hourFormat:new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`}),dayFormat:new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`})};default:return{scale:`hour`,step:1,hourFormat:new Intl.DateTimeFormat(void 0,{hour:`2-digit`,minute:`2-digit`,hour12:!1}),dayFormat:new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`})}}}function XB(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function ZB(e,t){let n=[],r=new Date(e);for(r.setHours(0,0,0,0);r.getTime()<=t;)r.getTime()>=e&&n.push(new Date(r)),r.setDate(r.getDate()+1);return n}function QB(e,t,n){let r=[],i=new Date(e);i.setMinutes(0,0,0);let a=i.getHours();for(i.setHours(a-a%n);i.getTime()<=t;)i.getTime()>=e&&r.push(new Date(i)),i.setHours(i.getHours()+n);return r}function $B(e,t){let n=[],r=new Date(e);r.setHours(0,0,0,0);let i=r.getDay(),a=i===0?6:i-1;for(r.setDate(r.getDate()-a);r.getTime()<=t;)r.getTime()>=e&&n.push(new Date(r)),r.setDate(r.getDate()+7);return n}var eV=class{constructor(e=40){this.groups=[],this.groupIndex=new Map,this.rowHeight=e,this.labelPanel=document.createElement(`div`),this.labelPanel.className=`tg-label-panel`,this.labelPanel.setAttribute(`role`,`rowheader`),this.contentArea=document.createElement(`div`),this.contentArea.className=`tg-content`,this.contentArea.setAttribute(`role`,`grid`)}getLabelPanel(){return this.labelPanel}getContentArea(){return this.contentArea}getRowHeight(){return this.rowHeight}getGroups(){return this.groups}getGroupCount(){return this.groups.length}getGroupAtIndex(e){return this.groups[e]}yToGroupId(e){let t=Math.floor(e/this.rowHeight);return t<0||t>=this.groups.length?null:this.groups[t].id}groupIdToRowIndex(e){return this.groupIndex.get(e)??-1}getRowRange(e,t){let n=Math.max(0,Math.floor(Math.min(e,t)/this.rowHeight)),r=Math.min(this.groups.length-1,Math.floor(Math.max(e,t)/this.rowHeight)),i=[];for(let e=n;e<=r;e++)i.push(this.groups[e].id);return i}getRowTop(e){return e*this.rowHeight}setGroups(e){this.groups=e.slice().sort((e,t)=>e.order!==void 0&&t.order!==void 0?e.order-t.order:e.order===void 0?t.order===void 0?e.content.localeCompare(t.content,void 0,{numeric:!0}):1:-1),this.groupIndex.clear();for(let e=0;e<this.groups.length;e++)this.groupIndex.set(this.groups[e].id,e)}render(){this.renderLabels(),this.renderRows()}renderLabels(){this.labelPanel.innerHTML=``;for(let e of this.groups){let t=document.createElement(`div`);t.className=`tg-label`,t.style.height=`${this.rowHeight}px`,t.textContent=e.content,t.title=e.content,t.dataset.groupId=e.id,this.labelPanel.appendChild(t)}}renderRows(){this.contentArea.querySelectorAll(`.tg-row`).forEach(e=>e.remove());for(let e=0;e<this.groups.length;e++){let t=document.createElement(`div`);t.className=`tg-row`,t.style.height=`${this.rowHeight}px`,t.style.top=`${e*this.rowHeight}px`,t.dataset.groupId=this.groups[e].id,this.contentArea.appendChild(t)}this.contentArea.style.height=`${this.groups.length*this.rowHeight}px`}destroy(){this.labelPanel.remove(),this.contentArea.remove()}},tV=class{constructor(e,t){this.items=[],this.itemElements=new Map,this.ghostEl=null,this.ghostCountBadge=null,this.scale=e,this.layout=t,this.contentArea=t.getContentArea()}setItems(e){this.items=e}render(){for(let e of this.itemElements.values())e.remove();this.itemElements.clear(),this.contentArea.querySelectorAll(`[data-item-id]`).forEach(e=>{e.dataset.itemId!==`__ghost__`&&e.remove()});for(let e of this.items){let t=this.renderItem(e);t&&(this.contentArea.appendChild(t),this.itemElements.set(e.id,t))}}renderItem(e){let t=this.layout.groupIdToRowIndex(e.group);if(t===-1)return null;let n=e.start instanceof Date?e.start:new Date(e.start),r=e.end?e.end instanceof Date?e.end:new Date(e.end):n,i=this.scale.timeToX(n),a=this.scale.timeToX(r)-i,o=this.layout.getRowTop(t),s=this.layout.getRowHeight();if(a<.5)return null;let c=document.createElement(`div`);if(c.dataset.itemId=e.id,c.title=e.title||e.content,e.type===`background`||e.isSegment)c.className=`tg-item-background ${e.className||``}`.trim(),e.style&&(c.style.cssText=e.style),c.style.position=`absolute`,c.style.left=`${i}px`,c.style.top=`${o}px`,c.style.width=`${a}px`,c.style.height=`${s}px`,c.style.pointerEvents=`none`;else{c.className=`tg-item tg-item-range ${e.className||``}`.trim(),e.style&&(c.style.cssText+=e.style),c.style.position=`absolute`,c.style.left=`${i}px`,c.style.top=`${o+2}px`,c.style.width=`${a}px`,c.style.height=`${s-4}px`,c.style.cursor=`move`;let t=document.createElement(`span`);t.className=`tg-item-content`,t.textContent=e.content,c.appendChild(t);let n=document.createElement(`div`);n.className=`tg-resize-handle tg-resize-left`,n.dataset.handle=`left`,c.appendChild(n);let r=document.createElement(`div`);r.className=`tg-resize-handle tg-resize-right`,r.dataset.handle=`right`,c.appendChild(r)}return c}updateItemPosition(e,t,n,r){let i=this.itemElements.get(e);i&&(i.style.left=`${t}px`,i.style.top=`${n+2}px`,i.style.width=`${r}px`)}showGhost(e){if(!this.ghostEl){this.ghostEl=document.createElement(`div`),this.ghostEl.className=`tg-ghost`,this.ghostEl.dataset.itemId=`__ghost__`;for(let e of[`left`,`right`,`top`,`bottom`]){let t=document.createElement(`div`);t.className=`tg-resize-handle tg-resize-${e}`,t.dataset.handle=e,this.ghostEl.appendChild(t)}this.ghostCountBadge=document.createElement(`div`),this.ghostCountBadge.className=`tg-ghost-count`,this.ghostEl.appendChild(this.ghostCountBadge),this.contentArea.appendChild(this.ghostEl)}let t=this.scale.timeToX(e.startTime),n=this.scale.timeToX(e.endTime)-t,r=this.layout.getRowHeight(),i=e.topRowIndex*r,a=(e.bottomRowIndex-e.topRowIndex+1)*r,o=e.bottomRowIndex-e.topRowIndex+1;this.ghostEl.style.left=`${t}px`,this.ghostEl.style.top=`${i}px`,this.ghostEl.style.width=`${n}px`,this.ghostEl.style.height=`${a}px`,this.ghostEl.style.display=`block`,this.ghostCountBadge&&(this.ghostCountBadge.textContent=`${o} court${o>1?`s`:``}`,this.ghostCountBadge.style.display=o>1?`flex`:`none`)}clearGhost(){this.ghostEl&&(this.ghostEl.remove(),this.ghostEl=null,this.ghostCountBadge=null)}isGhostVisible(){return this.ghostEl!==null&&this.ghostEl.style.display!==`none`}highlightRows(e){this.clearHighlights();for(let t of e){let e=this.contentArea.querySelectorAll(`.tg-row`);e[t]&&e[t].classList.add(`tg-row-highlight`)}}clearHighlights(){this.contentArea.querySelectorAll(`.tg-row-highlight`).forEach(e=>{e.classList.remove(`tg-row-highlight`)})}static hitTest(e){if(!(e instanceof HTMLElement))return{itemId:null,handle:null};let t=e.closest(`.tg-resize-handle`)?.dataset.handle??null;return{itemId:e.closest(`[data-item-id]`)?.dataset.itemId??null,handle:t}}destroy(){this.clearGhost(),this.clearHighlights();for(let e of this.itemElements.values())e.remove();this.itemElements.clear()}},nV=3,rV=30,iV=8,aV=36e5,oV=class{constructor(e,t,n,r,i=5,a=!1){this.mode=`IDLE`,this.gesture=null,this.items=[],this.ghostStartTime=null,this.ghostEndTime=null,this.ghostTopRow=0,this.ghostBottomRow=0,this.justDragged=!1,this.autoScrollRaf=null,this.autoScrollDelta=0,this.scrollContainer=null,this.onPointerDown=e=>{if(e.button!==0)return;let{itemId:t,handle:n}=tV.hitTest(e.target);if(this.mode===`GHOST_EDITING`){if(t===`__ghost__`&&n){this.startGesture(e,`__ghost__`,n===`left`?`RESIZING_LEFT`:n===`right`?`RESIZING_RIGHT`:n===`top`?`RESIZING_TOP`:`RESIZING_BOTTOM`);return}if(t===`__ghost__`&&!n){this.confirmGhost();return}this.cancelGhost();return}if(t){if(n===`left`)this.startGesture(e,t,`RESIZING_LEFT`);else if(n===`right`)this.startGesture(e,t,`RESIZING_RIGHT`);else{let n=this.items.find(e=>e.id===t);if(!n||n.isSegment||n.type===`background`)return;this.startGesture(e,t,`DRAGGING`)}}},this.onPointerMove=e=>{if(this.gesture){if(this.gesture.currentX=e.clientX,this.gesture.currentY=e.clientY,!this.gesture.thresholdExceeded){let t=Math.abs(e.clientX-this.gesture.startX),n=Math.abs(e.clientY-this.gesture.startY);if(t<nV&&n<nV)return;this.gesture.thresholdExceeded=!0}switch(this.checkAutoScroll(e),this.mode){case`DRAGGING`:this.handleDragMove(e);break;case`RESIZING_LEFT`:case`RESIZING_RIGHT`:this.gesture.itemId===`__ghost__`?this.handleGhostTimeResize(e):this.handleResizeMove(e);break;case`RESIZING_TOP`:case`RESIZING_BOTTOM`:this.handleGhostRowResize(e)}}},this.onPointerUp=e=>{if(document.removeEventListener(`pointermove`,this.onPointerMove),document.removeEventListener(`pointerup`,this.onPointerUp),this.stopAutoScroll(),!this.gesture){this.mode=`IDLE`;return}let t=this.gesture.itemId===`__ghost__`;if(!this.gesture.thresholdExceeded&&!t){this.gesture.itemId&&this.callbacks.onItemClick?.(this.gesture.itemId,e),this.gesture=null,this.mode=`IDLE`,this.renderer.clearHighlights();return}if(t){this.gesture=null,this.mode=`GHOST_EDITING`;return}if(this.gesture.itemId&&this.gesture.thresholdExceeded){this.justDragged=!0,setTimeout(()=>this.justDragged=!1,300);let t=(e.clientX-this.gesture.startX)*this.scale.msPerPx,n=this.gesture.originalEnd.getTime()-this.gesture.originalStart.getTime(),r,i,a=this.gesture.originalGroup;if(this.mode===`DRAGGING`){r=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),i=new Date(r.getTime()+n);let o=this.contentArea.getBoundingClientRect(),s=e.clientY-o.top+this.contentArea.scrollTop;a=this.layout.yToGroupId(s)||this.gesture.originalGroup}else this.mode===`RESIZING_LEFT`?(r=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),i=this.gesture.originalEnd,r>=i&&(r=new Date(i.getTime()-this.snapMinutes*60*1e3))):(r=this.gesture.originalStart,i=this.scale.snap(new Date(this.gesture.originalEnd.getTime()+t),this.snapMinutes),i<=r&&(i=new Date(r.getTime()+this.snapMinutes*60*1e3)));this.callbacks.onMove?.({id:this.gesture.itemId,group:a,start:r,end:i})}this.gesture=null,this.mode=`IDLE`,this.renderer.clearHighlights()},this.onDblClick=e=>{if(this.justDragged)return;let{itemId:t}=tV.hitTest(e.target);if(t)return;let n=this.contentArea.getBoundingClientRect(),r=e.clientX-n.left+this.contentArea.scrollLeft,i=e.clientY-n.top+this.contentArea.scrollTop,a=this.scale.xToTime(r),o=this.scale.snap(a,this.snapMinutes),s=new Date(o.getTime()+aV),c=this.layout.yToGroupId(i);if(!c)return;let l=this.layout.groupIdToRowIndex(c);l<0||(this.ghostStartTime=o,this.ghostEndTime=s,this.ghostTopRow=l,this.ghostBottomRow=l,this.mode=`GHOST_EDITING`,this.renderer.showGhost({startTime:o,endTime:s,topRowIndex:l,bottomRowIndex:l}),this.renderer.highlightRows([l]))},this.onWheel=e=>{if(!((e.ctrlKey||e.metaKey)&&!this.enablePinchZoom)){if(e.preventDefault(),(e.ctrlKey||e.metaKey)&&this.enablePinchZoom){let t=e.deltaY>0?1.15:.87,n=this.contentArea.getBoundingClientRect(),r=e.clientX-n.left;this.scale.zoom(t,r)}else if(e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY)){let t=e.deltaX||e.deltaY;this.scale.pan(t)}else{this.scrollContainer&&(this.scrollContainer.scrollTop+=e.deltaY);return}this.onScaleChanged?.()}},this.onScaleChanged=null,this.onKeyDown=e=>{e.key===`Escape`&&this.mode===`GHOST_EDITING`&&this.cancelGhost()},this.scale=e,this.layout=t,this.renderer=n,this.contentArea=t.getContentArea(),this.wheelTarget=this.contentArea,this.callbacks=r,this.snapMinutes=i,this.enablePinchZoom=a}setItems(e){this.items=e}setScrollContainer(e){this.scrollContainer=e}setWheelTarget(e){this.wheelTarget=e}attach(){this.contentArea.addEventListener(`pointerdown`,this.onPointerDown),this.contentArea.addEventListener(`dblclick`,this.onDblClick),this.wheelTarget.addEventListener(`wheel`,this.onWheel,{passive:!1}),document.addEventListener(`keydown`,this.onKeyDown)}detach(){this.contentArea.removeEventListener(`pointerdown`,this.onPointerDown),this.contentArea.removeEventListener(`dblclick`,this.onDblClick),this.wheelTarget.removeEventListener(`wheel`,this.onWheel),document.removeEventListener(`keydown`,this.onKeyDown),document.removeEventListener(`pointermove`,this.onPointerMove),document.removeEventListener(`pointerup`,this.onPointerUp),this.stopAutoScroll()}getMode(){return this.mode}startGesture(e,t,n){e.preventDefault();let r=this.items.find(e=>e.id===t),i,a,o;if(t===`__ghost__`)i=this.ghostStartTime,a=this.ghostEndTime,o=``;else if(r)i=r.start instanceof Date?r.start:new Date(r.start),a=r.end?r.end instanceof Date?r.end:new Date(r.end):i,o=r.group;else return;this.gesture={mode:n,itemId:t,startX:e.clientX,startY:e.clientY,originalStart:i,originalEnd:a,originalGroup:o,currentX:e.clientX,currentY:e.clientY,thresholdExceeded:!1},this.mode=n,this.contentArea.setPointerCapture(e.pointerId),document.addEventListener(`pointermove`,this.onPointerMove),document.addEventListener(`pointerup`,this.onPointerUp)}handleDragMove(e){if(!this.gesture||!this.gesture.itemId)return;let t=(e.clientX-this.gesture.startX)*this.scale.msPerPx,n=this.gesture.originalEnd.getTime()-this.gesture.originalStart.getTime(),r=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),i=new Date(r.getTime()+n),a=this.contentArea.getBoundingClientRect(),o=e.clientY-a.top+this.contentArea.scrollTop,s=this.layout.yToGroupId(o)||this.gesture.originalGroup;if(this.callbacks.onMoving){let e=this.callbacks.onMoving({id:this.gesture.itemId,group:s,start:r,end:i});if(e===null)return;r=e.start,i=e.end}let c=this.scale.timeToX(r),l=this.scale.timeToX(i)-c,u=this.layout.groupIdToRowIndex(s),d=this.layout.getRowTop(u>=0?u:0);this.renderer.updateItemPosition(this.gesture.itemId,c,d,l),u>=0&&this.renderer.highlightRows([u])}handleResizeMove(e){if(!this.gesture||!this.gesture.itemId)return;let t=(e.clientX-this.gesture.startX)*this.scale.msPerPx,n=this.gesture.originalStart,r=this.gesture.originalEnd;if(this.mode===`RESIZING_LEFT`?(n=this.scale.snap(new Date(this.gesture.originalStart.getTime()+t),this.snapMinutes),n>=r&&(n=new Date(r.getTime()-this.snapMinutes*60*1e3))):(r=this.scale.snap(new Date(this.gesture.originalEnd.getTime()+t),this.snapMinutes),r<=n&&(r=new Date(n.getTime()+this.snapMinutes*60*1e3))),this.callbacks.onMoving){let e=this.callbacks.onMoving({id:this.gesture.itemId,group:this.gesture.originalGroup,start:n,end:r});if(e===null)return;n=e.start,r=e.end}let i=this.scale.timeToX(n),a=this.scale.timeToX(r)-i,o=this.layout.groupIdToRowIndex(this.gesture.originalGroup),s=this.layout.getRowTop(o>=0?o:0);this.renderer.updateItemPosition(this.gesture.itemId,i,s,a)}handleGhostTimeResize(e){if(!this.gesture)return;let t=this.contentArea.getBoundingClientRect(),n=e.clientX-t.left+this.contentArea.scrollLeft,r=this.scale.snap(this.scale.xToTime(n),this.snapMinutes);this.mode===`RESIZING_LEFT`?r<this.ghostEndTime&&(this.ghostStartTime=r):r>this.ghostStartTime&&(this.ghostEndTime=r),this.updateGhostDisplay()}handleGhostRowResize(e){if(!this.gesture)return;let t=this.contentArea.getBoundingClientRect(),n=e.clientY-t.top+this.contentArea.scrollTop,r=Math.floor(n/this.layout.getRowHeight()),i=Math.max(0,Math.min(this.layout.getGroupCount()-1,r));this.mode===`RESIZING_TOP`?i<=this.ghostBottomRow&&(this.ghostTopRow=i):i>=this.ghostTopRow&&(this.ghostBottomRow=i),this.updateGhostDisplay()}updateGhostDisplay(){this.renderer.showGhost({startTime:this.ghostStartTime,endTime:this.ghostEndTime,topRowIndex:this.ghostTopRow,bottomRowIndex:this.ghostBottomRow});let e=[];for(let t=this.ghostTopRow;t<=this.ghostBottomRow;t++)e.push(t);this.renderer.highlightRows(e)}confirmGhost(){if(!this.ghostStartTime||!this.ghostEndTime){this.cancelGhost();return}let e=[];for(let t=this.ghostTopRow;t<=this.ghostBottomRow;t++){let n=this.layout.getGroupAtIndex(t);n&&e.push(n.id)}if(e.length===0){this.cancelGhost();return}let t={groupIds:e,topRowIndex:this.ghostTopRow,bottomRowIndex:this.ghostBottomRow,startTime:this.ghostStartTime,endTime:this.ghostEndTime};this.renderer.clearGhost(),this.renderer.clearHighlights(),this.mode=`IDLE`,this.callbacks.onMultiRowCreate?.(t),this.ghostStartTime=null,this.ghostEndTime=null}cancelGhost(){this.renderer.clearGhost(),this.renderer.clearHighlights(),this.mode=`IDLE`,this.ghostStartTime=null,this.ghostEndTime=null}checkAutoScroll(e){if(!this.scrollContainer)return;let t=this.scrollContainer.getBoundingClientRect(),n=t.bottom-e.clientY,r=e.clientY-t.top;n<rV?(this.autoScrollDelta=iV*(1-n/rV),this.startAutoScroll()):r<rV?(this.autoScrollDelta=-8*(1-r/rV),this.startAutoScroll()):this.stopAutoScroll()}startAutoScroll(){if(this.autoScrollRaf!==null)return;let e=()=>{this.scrollContainer&&(this.scrollContainer.scrollTop+=this.autoScrollDelta,this.autoScrollRaf=requestAnimationFrame(e))};this.autoScrollRaf=requestAnimationFrame(e)}stopAutoScroll(){this.autoScrollRaf!==null&&(cancelAnimationFrame(this.autoScrollRaf),this.autoScrollRaf=null),this.autoScrollDelta=0}},sV=class{constructor(e,t,n,r={}){this.callbacks={},this.resizeObserver=null,this._batchUpdating=!1,this.eventListeners=new Map,this.options={rowHeight:40,...r};let i=new Date,a=r.start||i,o=r.end||new Date(i.getTime()+432e5),s=e.clientWidth||800;this.scale=new GB(a,o,s),(r.min||r.max||r.zoomMin||r.zoomMax)&&this.scale.setLimits({min:r.min,max:r.max,zoomMin:r.zoomMin,zoomMax:r.zoomMax}),this.timeAxis=new JB(this.scale,r.timeAxis),this.layout=new eV(this.options.rowHeight),this.renderer=new tV(this.scale,this.layout),this.interaction=new oV(this.scale,this.layout,this.renderer,this.callbacks,5,r.enablePinchZoom??!1),this.rootEl=document.createElement(`div`),this.rootEl.className=`tg-timeline`,r.height&&(this.rootEl.style.height=r.height);let c=document.createElement(`div`);c.className=`tg-axis-header`;let l=document.createElement(`div`);l.className=`tg-axis-spacer`,c.appendChild(l),c.appendChild(this.timeAxis.getDayElement()),c.appendChild(this.timeAxis.getHourElement()),this.rootEl.appendChild(c),this.bodyEl=document.createElement(`div`),this.bodyEl.className=`tg-body`,this.bodyEl.appendChild(this.layout.getLabelPanel());let u=document.createElement(`div`);u.className=`tg-scroll-wrapper`,u.appendChild(this.layout.getContentArea()),this.bodyEl.appendChild(u),this.rootEl.appendChild(this.bodyEl),e.appendChild(this.rootEl),u.addEventListener(`scroll`,()=>{this.layout.getLabelPanel().scrollTop=u.scrollTop}),this.interaction.setScrollContainer(u),this.interaction.setWheelTarget(this.rootEl),this.interaction.onScaleChanged=()=>this.renderAll(),this.layout.setGroups(n),this.renderer.setItems(t),this.interaction.setItems(t),this.interaction.attach(),this.renderAll(),this.resizeObserver=new ResizeObserver(()=>{let t=u.clientWidth||e.clientWidth;this.scale.setWidth(t),this.renderAll()}),this.resizeObserver.observe(u)}setGroups(e){this.layout.setGroups(e),this.renderAll()}setItems(e){this.renderer.setItems(e),this.interaction.setItems(e),this.renderAll()}setWindow(e,t,n){this.scale.setWindow(e,t),this.renderAll()}setOptions(e){(e.min!==void 0||e.max!==void 0||e.zoomMin!==void 0||e.zoomMax!==void 0)&&this.scale.setLimits({min:e.min,max:e.max,zoomMin:e.zoomMin,zoomMax:e.zoomMax}),e.timeAxis&&this.timeAxis.setTimeAxisOptions(e.timeAxis),e.rowHeight!==void 0&&(this.options.rowHeight=e.rowHeight),Object.assign(this.options,e),this.renderAll()}on(e,t){this.eventListeners.has(e)||this.eventListeners.set(e,new Set),this.eventListeners.get(e).add(t),e===`click`&&(this.callbacks.onItemClick=(e,t)=>{this.emit(`click`,{item:e,event:t})})}off(e,t){this.eventListeners.get(e)?.delete(t)}emit(e,t){let n=this.eventListeners.get(e);if(n)for(let e of n)e(t)}onMultiRowCreate(e){this.callbacks.onMultiRowCreate=e}onAdd(e){this.callbacks.onAdd=e}onMove(e){this.callbacks.onMove=e}onMoving(e){this.callbacks.onMoving=e}onDayClick(e){this.timeAxis.onDayClick=e}getContentElement(){return this.layout.getContentArea()}setDailyBounds(e,t){this.scale.setDailyBounds(e,t),this.renderAll()}clearDailyBounds(){this.scale.clearDailyBounds(),this.renderAll()}setVisibleDays(e){this.scale.setVisibleDays(e),this.renderAll()}clearVisibleDays(){this.scale.clearVisibleDays(),this.renderAll()}beginBatchUpdate(){this._batchUpdating=!0}endBatchUpdate(){this._batchUpdating=!1,this.renderAll()}renderAll(){if(this._batchUpdating)return;this.timeAxis.render(),this.layout.render(),this.renderer.render();let e=this.layout.getContentArea(),t=this.layout.getGroupCount()*(this.options.rowHeight??40);this.timeAxis.renderGridlines(e,t)}destroy(){this.interaction.detach(),this.resizeObserver?.disconnect(),this.timeAxis.destroy(),this.layout.destroy(),this.renderer.destroy(),this.rootEl.remove(),this.eventListeners.clear()}},{BLOCK_TYPES:cV}=t.availability,lV=class{constructor(e,t){this.timeline=null,this.unsubscribe=null,this.currentItems=new Map,this.isRendering=!1,this.popoverManager=HB(),this.viewState=new XL,this.currentDay=null,this.currentView=`day`,this.selectedCourts=new Set,this.visibleCourts=null,this.handleOnMove=e=>{let t=aR(e.id);if(!t)return!1;let n=iR(e.group),r=this.toLocalISO(e.start),i=this.toLocalISO(e.end),a=this.engine.moveBlock({blockId:t,newTimeRange:{start:r,end:i},newCourt:n||void 0});return a.conflicts.some(e=>e.severity===`ERROR`)?(this.showConflictDialog(a.conflicts),!1):(this.render(),!0)},this.handleOnMoving=e=>{this.popoverManager.destroy();let t=this.currentItems.get(e.id);if(t&&(t.isSegment||t.type===`background`))return null;let{start:n,end:r}=e,i=iR(e.group);if(i){let e=n.toISOString().slice(0,10),t=this.engine.getCourtAvailability(i,e),a=new Date(`${e}T${t.startTime}:00`),o=new Date(`${e}T${t.endTime}:00`);n<a&&(n=a),r>o&&(r=o)}return{start:n,end:r}},this.handleTimelineClick=e=>{let t=e.item;if(!t){this.popoverManager.destroy();return}let n=this.currentItems.get(t);if(!n){this.popoverManager.destroy();return}if(n.isSegment||n.type===`background`){this.popoverManager.destroy();return}if(this.popoverManager.isActiveFor(t)){this.popoverManager.destroy();return}let r=aR(t);if(!r)return;let i=(e.event?.target)?.closest?.(`.tg-item`)??this.config.container.querySelector(`[data-item-id="${t}"]`);if(i){let e=String(n.start).slice(0,10);this.popoverManager.showForEngineBlock(i,{itemId:t,blockId:r,engine:this.engine,day:e,onBlockChanged:()=>this.render(),onManageRegistrations:this.config.onManageRegistrations})}this.config.onBlockSelected&&this.config.onBlockSelected(r)},this.handleMultiRowCreate=e=>{let t=[];for(let n of e.groupIds){let e=iR(n);e&&t.push(e)}if(t.length===0)return;let n=this.toLocalISO(e.startTime),r=this.toLocalISO(e.endTime),i=this.engine.applyBlock({courts:t,timeRange:{start:n,end:r},type:cV.BLOCKED,reason:`New Block`});if(this.render(),i.applied.length>0){let e=i.applied[0].block.id,t=`block-${e}`,r=n.slice(0,10);setTimeout(()=>{let n=this.config.container.querySelector(`[data-item-id="${t}"]`);n&&this.popoverManager.showForEngineBlock(n,{itemId:t,blockId:e,engine:this.engine,day:r,onBlockChanged:()=>this.render(),onManageRegistrations:this.config.onManageRegistrations})},50)}this.config.onTimeRangeSelected&&this.config.onTimeRangeSelected({courts:t,start:n,end:r})},this.handleEngineEvent=e=>{switch(e.type){case`STATE_CHANGED`:case`BLOCKS_CHANGED`:this.render(),e.type===`BLOCKS_CHANGED`&&this.config.onBlocksChanged&&this.config.onBlocksChanged();break;case`CONFLICTS_CHANGED`:this.config.showConflicts&&this.render();break;case`AVAILABILITY_CHANGED`:this.updateTimelineWindow(),this.render()}},this.engine=e,this.config={groupingMode:`BY_VENUE`,showConflicts:!0,showSegmentLabels:!1,colorScheme:ZL,...t},this.initialize()}initialize(){if(this.config.initialDay)this.currentDay=this.config.initialDay;else{let e=this.engine.getActiveDays();this.currentDay=e.length>0?e[0]:t.tools.dateTime.extractDate(new Date().toISOString())}this.viewState.setSelectedDay(this.currentDay),this.config.initialView&&(this.currentView=this.config.initialView),this.unsubscribe=this.engine.subscribe(this.handleEngineEvent),this.ensureTimeline()}ensureTimeline(){this.timeline||setTimeout(()=>{this.timeline||this.createTimelineWithData()},0)}getViewDays(){if(!this.currentDay)return[];let e=UB[this.currentView],t=e?e.days:1;if(t<=0)return this.engine.getActiveDays();if(t<=1)return[this.currentDay];let n=this.engine.getActiveDays(),r=n.indexOf(this.currentDay);return r===-1?[this.currentDay]:n.slice(r,r+t)}buildViewData(){if(!this.currentDay)return{groups:[],items:[]};let e=this.getViewDays(),t=this.engine.listCourtMeta(),n=this.viewState.getLayerVisibility(),r={groupingMode:this.config.groupingMode,layerVisibility:n,showSegmentLabels:this.config.showSegmentLabels,colorScheme:this.config.colorScheme},i=QL(this.engine.getDayTimeline(e[0]),t,r);this.visibleCourts!==null&&this.visibleCourts.size>0&&(i=i.filter(e=>this.visibleCourts.has(String(e.id))));let a=this.visibleCourts!==null&&this.visibleCourts.size>0&&i.length>0?new Set(i.map(e=>String(e.id))):null,o=e.length<=1?this.engine.getActiveDays():e,s=[],c=[];for(let e of o){let t=this.engine.getDayTimeline(e);s.push(...$L(t,r)),c.push(...tR(this.engine.getDayBlocks(e),r))}let l=a?s.filter(e=>a.has(String(e.group))):s,u=a?c.filter(e=>a.has(String(e.group))):c,d=[...l,...u];return{groups:i.map((e,t)=>({id:String(e.id),content:typeof e.content==`string`?e.content:``,order:t,courtRef:e.courtRef,surface:e.surface,indoor:e.indoor,hasLights:e.hasLights,tags:e.tags})),items:d.map(e=>({id:String(e.id),group:String(e.group),content:e.content,start:e.start,end:e.end,type:e.type===`background`?`background`:`range`,className:e.className,style:e.style,title:e.title,editable:e.editable,blockId:e.blockId,status:e.status,reason:e.reason,isBlock:e.isBlock,isSegment:e.isSegment,isConflict:e.isConflict}))}}createTimelineWithData(){let e=this.engine.getConfig(),n=this.currentDay||t.tools.dateTime.extractDate(new Date().toISOString()),r=this.getViewDays(),i=r[0]||n,a=r[r.length-1]||n,o=this.engine.getVisibleTimeRange(i),s=this.engine.getVisibleTimeRange(a),c=oR({dayStartTime:o.startTime,dayEndTime:o.endTime,slotMinutes:e.slotMinutes,day:i}),l=UB[this.currentView],u=r.length>1?new Date(`${a}T${s.endTime}:00`):c.end,d=this.engine.getActiveDays(),f=d[0]||i,p=d[d.length-1]||a,m=this.engine.getVisibleTimeRange(f),h=this.engine.getVisibleTimeRange(p),g=new Date(`${f}T${m.startTime}:00`),_=new Date(`${p}T${h.endTime}:00`),{groups:v,items:y}=this.buildViewData();this.currentItems.clear();for(let e of y)this.currentItems.set(e.id,e);this.timeline=new sV(this.config.container,y,v,{start:c.start,end:u,min:g,max:_,zoomMin:c.zoomMin,zoomMax:_.getTime()-g.getTime(),snap:e=>this.snapToMinutes(e,5),rowHeight:40,height:`100%`,timeAxis:l?l.timeAxis:{scale:`hour`,step:1},showTooltips:!0}),this.timeline.setDailyBounds(o.startTime,o.endTime),r.length>1&&this.timeline.setVisibleDays(r),this.timeline.on(`click`,this.handleTimelineClick),this.timeline.onMove(this.handleOnMove),this.timeline.onMoving(this.handleOnMoving),this.timeline.onMultiRowCreate(this.handleMultiRowCreate),this.timeline.onDayClick(e=>{this.setDay(e),this.setViewPreset(`day`),this.config.onDayNavigate?.(e)}),this.config.onBlocksChanged?.()}setDay(e){this.currentDay!==e&&(this.currentDay=e,this.viewState.setSelectedDay(e),this.updateTimelineWindow(),this.render())}getDay(){return this.currentDay}setView(e){this.currentView=e,this.updateTimelineWindow()}setViewPreset(e){let t=UB[e];if(!t||!this.timeline||!this.currentDay)return;this.currentView=e;let n=this.getViewDays(),r=n[0],i=n[n.length-1],a=this.engine.getVisibleTimeRange(r),o=this.engine.getVisibleTimeRange(i);this.timeline.beginBatchUpdate();let s=t.days===0||t.days>1;this.timeline.setDailyBounds(a.startTime,a.endTime),s?this.timeline.setVisibleDays(n):this.timeline.clearVisibleDays();let c=new Date(`${r}T${a.startTime}:00`),l=new Date(`${i}T${o.endTime}:00`);this.timeline.setWindow(c,l,{animation:!1}),this.timeline.setOptions({timeAxis:t.timeAxis});let{groups:u,items:d}=this.buildViewData();this.currentItems.clear();for(let e of d)this.currentItems.set(e.id,e);this.timeline.setGroups(u),this.timeline.setItems(d),this.timeline.endBatchUpdate(),this.config.onBlocksChanged?.()}setSelectedCourts(e){this.selectedCourts=new Set(e)}getSelectedCourts(){return Array.from(this.selectedCourts)}setVisibleCourts(e){this.visibleCourts=e&&e.size===0?null:e,this.render()}setLayerVisibility(e,t){this.viewState.setLayerVisibility(e,t),this.render()}refresh(){this.updateTimelineWindow(),this.render()}destroy(){this.popoverManager.destroy(),this.unsubscribe&&this.unsubscribe(),this.timeline&&=(this.timeline.destroy(),null)}updateTimelineWindow(){if(!this.timeline||!this.currentDay)return;let e=this.engine.getConfig(),t=this.getViewDays(),n=t[0]||this.currentDay,r=t[t.length-1]||this.currentDay,i=this.engine.getVisibleTimeRange(n),a=this.engine.getVisibleTimeRange(r),o=oR({dayStartTime:i.startTime,dayEndTime:i.endTime,slotMinutes:e.slotMinutes,day:n}),s=UB[this.currentView],c=t.length>1?new Date(`${r}T${a.endTime}:00`):o.end,l=this.engine.getActiveDays(),u=l[0]||n,d=l[l.length-1]||r,f=this.engine.getVisibleTimeRange(u),p=this.engine.getVisibleTimeRange(d),m=new Date(`${u}T${f.startTime}:00`),h=new Date(`${d}T${p.endTime}:00`);this.timeline.beginBatchUpdate(),this.timeline.setDailyBounds(i.startTime,i.endTime),t.length>1?this.timeline.setVisibleDays(t):this.timeline.clearVisibleDays(),this.timeline.setOptions({min:m,max:h}),this.timeline.setWindow(o.start,c,{animation:!1}),s&&this.timeline.setOptions({timeAxis:s.timeAxis}),this.timeline.endBatchUpdate()}render(){if(this.currentDay&&!this.isRendering){if(!this.timeline){this.ensureTimeline();return}this.isRendering=!0;try{let{groups:e,items:t}=this.buildViewData();this.currentItems.clear();for(let e of t)this.currentItems.set(e.id,e);this.timeline.setGroups(e),this.timeline.setItems(t)}finally{this.isRendering=!1}}}getPopoverManager(){return this.popoverManager}snapToMinutes(e,t){let n=e.getTime(),r=t*60*1e3,i=Math.round(n/r)*r;return new Date(i)}toLocalISO(e){let t=e=>e.toString().padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`}showConflictDialog(e){let t=e.filter(e=>e.severity===`ERROR`);if(t.length===0)return;if(this.config.onConflict){this.config.onConflict(t);return}let n=t.map(e=>e.message).join(`
248
+ `);console.warn(`[availability-grid] cannot complete operation:\n${n}`)}getTimeline(){return this.timeline}getEngine(){return this.engine}getViewState(){return this.viewState}};function uV(e){let t=e?.totalHours??`Total Hours`,n=e?.blocked??`Blocked`,r=e?.available??`Available`,i=e?.avgPerCourt??`Avg Avail/Court`,a=document.createElement(`div`);a.className=`tg-stats-bar`;let o=e=>{let t=document.createElement(`span`);return t.innerHTML=`${e}: <b>&mdash;</b>`,a.appendChild(t),t},s=o(t),c=o(n),l=o(r),u=o(i);return{element:a,update:e=>{s.innerHTML=`${t}: <b>${e.totalHours.toFixed(1)}h</b>`,c.innerHTML=`${n}: <b>${e.blockedHours.toFixed(1)}h</b>`,l.innerHTML=`${r}: <b>${e.availableHours.toFixed(1)}h</b>`,u.innerHTML=`${i}: <b>${e.avgPerCourt.toFixed(1)}h</b>`}}}var dV,fV,pV,mV=!1;async function hV(){if(!dV){let e=await Promise.resolve().then(()=>(dB(),sR));dV=e.TimepickerUI,fV=e.PluginRegistry,pV=(await Promise.resolve().then(()=>(kB(),fB))).RangePlugin,!mV&&fV&&pV&&(fV.register(pV),mV=!0)}}var gV=0;async function _V(e){let{title:t,currentDay:n,currentStartTime:r,currentEndTime:i,showScopeToggle:a=!0,venueBounds:o,onConfirm:s,onCancel:c,labels:l={}}=e;await hV();let u=new Date(n+`T12:00:00`).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`}),d=`tp-court-avail-${++gV}`,f=a?`current-day`:`all-days`,p=document.createElement(`div`);p.className=`tg-modal`,p.style.cssText=`
249
249
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
250
250
  background: var(--chc-bg-overlay); z-index: 10000;
251
251
  display: flex; align-items: center; justify-content: center;
@@ -260,14 +260,14 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
260
260
  display: none; padding: 8px 12px; margin-bottom: 12px; border-radius: 6px;
261
261
  background: #fef3c7; border: 1px solid #f59e0b; color: #92400e;
262
262
  font-size: 12px; line-height: 1.4;
263
- `,v.appendChild(e),v.dataset.venueBoundsStart=o.startTime,v.dataset.venueBoundsEnd=o.endTime}if(a){let e=document.createElement(`div`);e.style.cssText=`margin-bottom: 8px;`;let t=document.createElement(`div`);t.textContent=(l.applyTo||`Apply to`)+`:`,t.style.cssText=`font-size: 12px; color: var(--chc-text-secondary); margin-bottom: 6px; font-weight: 500;`,e.appendChild(t);let n=`availability-scope-${d}`,r=(t,r,i)=>{let a=document.createElement(`label`);a.style.cssText=`display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-size: 13px; color: var(--chc-text-primary);`;let o=document.createElement(`input`);o.type=`radio`,o.name=n,o.value=t,o.checked=i,o.style.cursor=`pointer`,o.addEventListener(`change`,()=>{o.checked&&(f=t)});let s=document.createElement(`span`);s.textContent=r,a.appendChild(o),a.appendChild(s),e.appendChild(a)};r(`current-day`,l.currentDayOnly?l.currentDayOnly.replace("${day}",u):`Current day only (${u})`,!0),r(`all-days`,l.allDays||`All tournament days`,!1),v.appendChild(e)}p.appendChild(m),p.addEventListener(`click`,e=>{e.target===p&&(C(),c?.())}),document.body.appendChild(p);let y=new Uz(g,{range:{enabled:!0,fromLabel:l.startTime||`Start`,toLabel:l.endTime||`End`},clock:{type:`12h`,incrementMinutes:5},ui:{theme:`crane`,inline:{enabled:!0,containerId:d,showButtons:!0}},labels:{ok:l.apply||`Apply`,cancel:l.cancel||`Cancel`},callbacks:{onRangeConfirm:e=>{let t=e.from||r,n=e.to||i;C(),s({startTime:t,endTime:n,scope:f})},onCancel:()=>{C(),c?.()}}});y.create();let b=_.querySelector(`.tp-ui-wrapper`),x=b?.querySelector(`.tp-ui-footer`),S=document.createElement(`div`);if(S.textContent=t,S.style.cssText=`
263
+ `,v.appendChild(e),v.dataset.venueBoundsStart=o.startTime,v.dataset.venueBoundsEnd=o.endTime}if(a){let e=document.createElement(`div`);e.style.cssText=`margin-bottom: 8px;`;let t=document.createElement(`div`);t.textContent=(l.applyTo||`Apply to`)+`:`,t.style.cssText=`font-size: 12px; color: var(--chc-text-secondary); margin-bottom: 6px; font-weight: 500;`,e.appendChild(t);let n=`availability-scope-${d}`,r=(t,r,i)=>{let a=document.createElement(`label`);a.style.cssText=`display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-size: 13px; color: var(--chc-text-primary);`;let o=document.createElement(`input`);o.type=`radio`,o.name=n,o.value=t,o.checked=i,o.style.cursor=`pointer`,o.addEventListener(`change`,()=>{o.checked&&(f=t)});let s=document.createElement(`span`);s.textContent=r,a.appendChild(o),a.appendChild(s),e.appendChild(a)};r(`current-day`,l.currentDayOnly?l.currentDayOnly.replace("${day}",u):`Current day only (${u})`,!0),r(`all-days`,l.allDays||`All tournament days`,!1),v.appendChild(e)}p.appendChild(m),p.addEventListener(`click`,e=>{e.target===p&&(C(),c?.())}),document.body.appendChild(p);let y=new dV(g,{range:{enabled:!0,fromLabel:l.startTime||`Start`,toLabel:l.endTime||`End`},clock:{type:`12h`,incrementMinutes:5},ui:{theme:`crane`,inline:{enabled:!0,containerId:d,showButtons:!0}},labels:{ok:l.apply||`Apply`,cancel:l.cancel||`Cancel`},callbacks:{onRangeConfirm:e=>{let t=e.from||r,n=e.to||i;C(),s({startTime:t,endTime:n,scope:f})},onCancel:()=>{C(),c?.()}}});y.create();let b=_.querySelector(`.tp-ui-wrapper`),x=b?.querySelector(`.tp-ui-footer`),S=document.createElement(`div`);if(S.textContent=t,S.style.cssText=`
264
264
  text-align: center; font-size: 16px; font-weight: 600;
265
265
  padding: 12px 24px 4px;
266
266
  background: var(--tp-bg); color: var(--tp-text);
267
- `,b?b.prepend(S):_.prepend(S),x&&b?x.before(v):m.appendChild(v),o){let e=v.querySelector(`.tp-court-avail-warning`);((t,n)=>{if(!e||!t||!n||t===`--:--`||n===`--:--`)return;let r=t<o.startTime,i=n>o.endTime;if(r||i){let t=l.venueWarning||"Venue hours are ${startTime}–${endTime}. The venue will be widened to accommodate this change.";e.textContent=t.replace("${startTime}",o.startTime).replace("${endTime}",o.endTime),e.style.display=`block`}else e.style.display=`none`})(r,i)}function C(){y?.destroy&&y.destroy(),p.remove()}}var{calculateCapacityStats:Xz}=t.availability,Zz=class{constructor(e){this.control=null,this.rootElement=null,this.venueTreeElement=null,this.calendarElement=null,this.capacityElement=null,this.statsBarInstance=null,this.viewToolbarResult=null,this.datepicker=null,this.visibleCourts=new Set,this.initialSnapshot=``,this.isDirty=!1,this.handleEngineEvent=e=>{e.type===`BLOCKS_CHANGED`&&(this.updateCapacityStats(),this.updateStatsBar(),this.checkDirtyState(),this.config.onMutationsApplied&&this.config.onMutationsApplied(e.payload.mutations)),e.type===`AVAILABILITY_CHANGED`&&this.checkDirtyState()},this.handleBlockSelected=e=>{},this.handleCourtSelected=e=>{},this.handleTimeRangeSelected=e=>{},this.handleCourtCheckboxChange=e=>{let t=e.target,n=t.dataset.courtId,r=t.dataset.venueId,i=t.dataset.tournamentId;if(!n||!r||!i)return;let a=`${i}|${r}|${n}`;t.checked?this.visibleCourts.add(a):this.visibleCourts.delete(a),this.updateVenueCheckboxState(r);let o=new Set(this.visibleCourts);this.control?.setVisibleCourts(o)},this.handleVenueCheckboxChange=e=>{let t=e.target,n=t.dataset.venue,r=t.dataset.tournamentId;if(!n||!r)return;this.engine.listCourtMeta().filter(e=>e.ref.venueId===n).forEach(e=>{let n=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;t.checked?this.visibleCourts.add(n):this.visibleCourts.delete(n)}),(this.venueTreeElement?.querySelectorAll(`.court-checkbox[data-venue-id="${n}"]`))?.forEach(e=>{e.checked=t.checked});let i=new Set(this.visibleCourts);this.control?.setVisibleCourts(i)},this.config={showVenueTree:!0,showCapacity:!0,showToolbar:!0,groupingMode:`BY_VENUE`,showConflicts:!0,showSegmentLabels:!1,...e},this.engine=new t.AvailabilityEngine,this.engine.init(e.tournamentRecord,e.engineConfig),this.initialSnapshot=this.takeSnapshot(),this.engine.subscribe(this.handleEngineEvent)}render(e){e.innerHTML=``,this.rootElement=this.createRootElement(),e.appendChild(this.rootElement),this.config.showToolbar&&this.renderToolbar(),this.config.showCapacity&&this.renderCapacityIndicator();let t=this.rootElement.querySelector(`.availability-grid-main`);if(!t)return;let n=document.createElement(`div`);n.className=`availability-grid-layout`,t.appendChild(n),this.config.showVenueTree&&this.renderVenueTree(n),this.renderCalendar(n),this.calendarElement&&(this.control=new Vz(this.engine,{container:this.calendarElement,initialDay:this.config.initialDay,initialView:this.config.initialView,groupingMode:this.config.groupingMode,showConflicts:this.config.showConflicts,showSegmentLabels:this.config.showSegmentLabels,onBlockSelected:this.handleBlockSelected,onCourtSelected:this.handleCourtSelected,onTimeRangeSelected:this.handleTimeRangeSelected,onManageRegistrations:this.config.onManageRegistrations,onBlocksChanged:()=>{this.updateCapacityStats(),this.updateStatsBar()},onDayNavigate:e=>{this.viewToolbarResult?.setActiveView(`day`),this.viewToolbarResult?.setDate(e),this.datepicker&&this.datepicker.setDate(e,{clear:!0}),this.updateCapacityStats(),this.updateStatsBar()}}),this.config.showToolbar&&this.initDatepicker())}destroy(){this.datepicker&&=(this.datepicker.destroy(),null),this.control&&=(this.control.destroy(),null),this.rootElement&&this.rootElement.parentNode&&this.rootElement.parentNode.removeChild(this.rootElement),this.rootElement=null,this.venueTreeElement=null,this.calendarElement=null,this.capacityElement=null,this.viewToolbarResult=null}createRootElement(){let e=document.createElement(`div`);return e.className=`availability-grid-root`,e.innerHTML=`
267
+ `,b?b.prepend(S):_.prepend(S),x&&b?x.before(v):m.appendChild(v),o){let e=v.querySelector(`.tp-court-avail-warning`);((t,n)=>{if(!e||!t||!n||t===`--:--`||n===`--:--`)return;let r=t<o.startTime,i=n>o.endTime;if(r||i){let t=l.venueWarning||"Venue hours are ${startTime}–${endTime}. The venue will be widened to accommodate this change.";e.textContent=t.replace("${startTime}",o.startTime).replace("${endTime}",o.endTime),e.style.display=`block`}else e.style.display=`none`})(r,i)}function C(){y?.destroy&&y.destroy(),p.remove()}}var{calculateCapacityStats:vV}=t.availability,yV=class{constructor(e){this.control=null,this.rootElement=null,this.venueTreeElement=null,this.calendarElement=null,this.capacityElement=null,this.statsBarInstance=null,this.viewToolbarResult=null,this.datepicker=null,this.visibleCourts=new Set,this.initialSnapshot=``,this.isDirty=!1,this.handleEngineEvent=e=>{e.type===`BLOCKS_CHANGED`&&(this.updateCapacityStats(),this.updateStatsBar(),this.checkDirtyState(),this.config.onMutationsApplied&&this.config.onMutationsApplied(e.payload.mutations)),e.type===`AVAILABILITY_CHANGED`&&this.checkDirtyState()},this.handleBlockSelected=e=>{},this.handleCourtSelected=e=>{},this.handleTimeRangeSelected=e=>{},this.handleCourtCheckboxChange=e=>{let t=e.target,n=t.dataset.courtId,r=t.dataset.venueId,i=t.dataset.tournamentId;if(!n||!r||!i)return;let a=`${i}|${r}|${n}`;t.checked?this.visibleCourts.add(a):this.visibleCourts.delete(a),this.updateVenueCheckboxState(r);let o=new Set(this.visibleCourts);this.control?.setVisibleCourts(o)},this.handleVenueCheckboxChange=e=>{let t=e.target,n=t.dataset.venue,r=t.dataset.tournamentId;if(!n||!r)return;this.engine.listCourtMeta().filter(e=>e.ref.venueId===n).forEach(e=>{let n=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;t.checked?this.visibleCourts.add(n):this.visibleCourts.delete(n)}),(this.venueTreeElement?.querySelectorAll(`.court-checkbox[data-venue-id="${n}"]`))?.forEach(e=>{e.checked=t.checked});let i=new Set(this.visibleCourts);this.control?.setVisibleCourts(i)},this.config={showVenueTree:!0,showCapacity:!0,showToolbar:!0,groupingMode:`BY_VENUE`,showConflicts:!0,showSegmentLabels:!1,...e},this.engine=new t.AvailabilityEngine,this.engine.init(e.tournamentRecord,e.engineConfig),this.initialSnapshot=this.takeSnapshot(),this.engine.subscribe(this.handleEngineEvent)}render(e){e.innerHTML=``,this.rootElement=this.createRootElement(),e.appendChild(this.rootElement),this.config.showToolbar&&this.renderToolbar(),this.config.showCapacity&&this.renderCapacityIndicator();let t=this.rootElement.querySelector(`.availability-grid-main`);if(!t)return;let n=document.createElement(`div`);n.className=`availability-grid-layout`,t.appendChild(n),this.config.showVenueTree&&this.renderVenueTree(n),this.renderCalendar(n),this.calendarElement&&(this.control=new lV(this.engine,{container:this.calendarElement,initialDay:this.config.initialDay,initialView:this.config.initialView,groupingMode:this.config.groupingMode,showConflicts:this.config.showConflicts,showSegmentLabels:this.config.showSegmentLabels,onBlockSelected:this.handleBlockSelected,onCourtSelected:this.handleCourtSelected,onTimeRangeSelected:this.handleTimeRangeSelected,onManageRegistrations:this.config.onManageRegistrations,onBlocksChanged:()=>{this.updateCapacityStats(),this.updateStatsBar()},onDayNavigate:e=>{this.viewToolbarResult?.setActiveView(`day`),this.viewToolbarResult?.setDate(e),this.datepicker&&this.datepicker.setDate(e,{clear:!0}),this.updateCapacityStats(),this.updateStatsBar()}}),this.config.showToolbar&&this.initDatepicker())}destroy(){this.datepicker&&=(this.datepicker.destroy(),null),this.control&&=(this.control.destroy(),null),this.rootElement&&this.rootElement.parentNode&&this.rootElement.parentNode.removeChild(this.rootElement),this.rootElement=null,this.venueTreeElement=null,this.calendarElement=null,this.capacityElement=null,this.viewToolbarResult=null}createRootElement(){let e=document.createElement(`div`);return e.className=`availability-grid-root`,e.innerHTML=`
268
268
  <div class="availability-grid-header"></div>
269
269
  <div class="availability-grid-main"></div>
270
- `,e}renderToolbar(){let e=this.rootElement?.querySelector(`.availability-grid-header`);if(!e)return;let t=this.config.labels;this.viewToolbarResult=Sz(e=>this.control?.setViewPreset(e),this.config.initialView||`day`,e=>this.handleDateChange(e),{labels:t,onSetDefaultAvailability:this.config.onSetDefaultAvailability,onSave:this.config.onSave}),e.appendChild(this.viewToolbarResult.element);let n=this.engine.getActiveDays(),r=this.config.initialDay||(n.length>0?n[0]:``);r&&this.viewToolbarResult.setDate(r),this.statsBarInstance=Hz(t),e.appendChild(this.statsBarInstance.element)}initDatepicker(){if(this.datepicker||!this.viewToolbarResult)return;let e=this.engine.getActiveDays(),t=new Set(e);this.datepicker=new sn(this.viewToolbarResult.dateInput,{format:`yyyy-mm-dd`,language:this.config.language||`en`,autohide:!0,beforeShowDay:e=>{let n=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,`0`),i=String(e.getDate()).padStart(2,`0`);return t.has(`${n}-${r}-${i}`)?{classes:`tg-datepicker-active-day`}:{}}});let n=this.config.initialDay||(e.length>0?e[0]:``);n&&this.datepicker.setDate(n,{clear:!0})}handleDateChange(e){let t=this.engine.getActiveDays();if(t.length===0)return;let n=e;t.includes(e)||(n=t.reduce((t,n)=>Math.abs(new Date(n).getTime()-new Date(e).getTime())<Math.abs(new Date(t).getTime()-new Date(e).getTime())?n:t,t[0])),this.control?.setDay(n),this.updateCapacityStats(),this.updateStatsBar(),this.viewToolbarResult&&this.viewToolbarResult.setDate(n),this.datepicker&&this.datepicker.setDate(n,{clear:!0})}renderCapacityIndicator(){let e=this.rootElement?.querySelector(`.availability-grid-header`);if(!e)return;let t=this.config.labels,n=t?.courtAvailability??`Court Availability`,r=t?.totalHours??`Total Hours`,i=t?.avgPerCourt??`Avg/Court`,a=document.createElement(`div`);a.className=`availability-grid-capacity`,a.innerHTML=`
270
+ `,e}renderToolbar(){let e=this.rootElement?.querySelector(`.availability-grid-header`);if(!e)return;let t=this.config.labels;this.viewToolbarResult=WB(e=>this.control?.setViewPreset(e),this.config.initialView||`day`,e=>this.handleDateChange(e),{labels:t,onSetDefaultAvailability:this.config.onSetDefaultAvailability,onSave:this.config.onSave}),e.appendChild(this.viewToolbarResult.element);let n=this.engine.getActiveDays(),r=this.config.initialDay||(n.length>0?n[0]:``);r&&this.viewToolbarResult.setDate(r),this.statsBarInstance=uV(t),e.appendChild(this.statsBarInstance.element)}initDatepicker(){if(this.datepicker||!this.viewToolbarResult)return;let e=this.engine.getActiveDays(),t=new Set(e);this.datepicker=new sn(this.viewToolbarResult.dateInput,{format:`yyyy-mm-dd`,language:this.config.language||`en`,autohide:!0,beforeShowDay:e=>{let n=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,`0`),i=String(e.getDate()).padStart(2,`0`);return t.has(`${n}-${r}-${i}`)?{classes:`tg-datepicker-active-day`}:{}}});let n=this.config.initialDay||(e.length>0?e[0]:``);n&&this.datepicker.setDate(n,{clear:!0})}handleDateChange(e){let t=this.engine.getActiveDays();if(t.length===0)return;let n=e;t.includes(e)||(n=t.reduce((t,n)=>Math.abs(new Date(n).getTime()-new Date(e).getTime())<Math.abs(new Date(t).getTime()-new Date(e).getTime())?n:t,t[0])),this.control?.setDay(n),this.updateCapacityStats(),this.updateStatsBar(),this.viewToolbarResult&&this.viewToolbarResult.setDate(n),this.datepicker&&this.datepicker.setDate(n,{clear:!0})}renderCapacityIndicator(){let e=this.rootElement?.querySelector(`.availability-grid-header`);if(!e)return;let t=this.config.labels,n=t?.courtAvailability??`Court Availability`,r=t?.totalHours??`Total Hours`,i=t?.avgPerCourt??`Avg/Court`,a=document.createElement(`div`);a.className=`availability-grid-capacity`,a.innerHTML=`
271
271
  <div class="capacity-label">${n}:</div>
272
272
  <div class="capacity-stats">
273
273
  <div class="stat">
@@ -286,7 +286,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
286
286
  <div class="tree-content" id="venue-tree-content">
287
287
  <!-- Tree will be populated dynamically -->
288
288
  </div>
289
- `,e.appendChild(t),this.venueTreeElement=t,this.updateVenueTree()}renderCalendar(e){let t=document.createElement(`div`);t.className=`availability-grid-calendar`,e.appendChild(t),this.calendarElement=t}takeSnapshot(){let e=this.engine.getActiveDays(),t=this.engine.listCourtMeta(),n=[];for(let r of e){let e=this.engine.getDayBlocks(r).map(e=>({id:e.id,type:e.type,start:e.start,end:e.end,court:`${e.court?.venueId}|${e.court?.courtId}`})),i=t.map(e=>{let t=this.engine.getCourtAvailability(e.ref,r);return{ref:`${e.ref.venueId}|${e.ref.courtId}`,s:t.startTime,e:t.endTime}});n.push({day:r,blocks:e,avails:i})}return JSON.stringify(n)}checkDirtyState(){let e=this.takeSnapshot(),t=this.isDirty;this.isDirty=e!==this.initialSnapshot,this.isDirty!==t&&(this.viewToolbarResult?.setSaveEnabled(this.isDirty),this.config.onDirtyChange&&this.config.onDirtyChange(this.isDirty))}resetDirtyState(){this.initialSnapshot=this.takeSnapshot(),this.isDirty=!1,this.viewToolbarResult?.setSaveEnabled(!1),this.config.onDirtyChange&&this.config.onDirtyChange(!1)}updateStatsBar(){if(!this.statsBarInstance||!this.control)return;let e=this.control.getViewDays();if(e.length===0)return;let t=0,n=0,r=0,i=0;for(let a of e){let e=Xz(this.engine.getCapacityCurve(a));t+=e.totalCourtHours,n+=e.totalUnavailableHours??0,r+=e.totalAvailableHours??0,i=e.totalCourts??0}let a=i||1;this.statsBarInstance.update({totalHours:t,blockedHours:n,availableHours:r,avgPerCourt:r/a})}updateCapacityStats(){if(!this.capacityElement||!this.control)return;let e=this.control.getViewDays();if(e.length===0)return;let t=0,n=0;for(let r of e){let e=Xz(this.engine.getCapacityCurve(r));t+=e.totalAvailableHours??0,n=e.totalCourts??0}let r=this.capacityElement.querySelector(`#total-hours`),i=this.capacityElement.querySelector(`#avg-hours`);r&&(r.textContent=`${t.toFixed(1)}h`);let a=n>0?t/n:0;i&&(i.textContent=`${a.toFixed(1)}h`)}updateVenueTree(){if(!this.venueTreeElement)return;let e=this.venueTreeElement.querySelector(`#venue-tree-content`);if(!e)return;let t=this.engine.listCourtMeta(),n=this.engine.getConfig().tournamentId;this.visibleCourts.size===0&&t.forEach(e=>{let t=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;this.visibleCourts.add(t)});let r=new Map;for(let e of this.config.tournamentRecord?.venues||[]){let t=e.venueId;t&&r.set(t,e.venueName||e.venueAbbreviation||t)}let i=new Map;for(let e of t){let t=e.ref.venueId;i.has(t)||i.set(t,[]),i.get(t).push(e)}let a=``;for(let[e,t]of i){let i=t.every(e=>{let t=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;return this.visibleCourts.has(t)}),o=r.get(e)||e;a+=`
289
+ `,e.appendChild(t),this.venueTreeElement=t,this.updateVenueTree()}renderCalendar(e){let t=document.createElement(`div`);t.className=`availability-grid-calendar`,e.appendChild(t),this.calendarElement=t}takeSnapshot(){let e=this.engine.getActiveDays(),t=this.engine.listCourtMeta(),n=[];for(let r of e){let e=this.engine.getDayBlocks(r).map(e=>({id:e.id,type:e.type,start:e.start,end:e.end,court:`${e.court?.venueId}|${e.court?.courtId}`})),i=t.map(e=>{let t=this.engine.getCourtAvailability(e.ref,r);return{ref:`${e.ref.venueId}|${e.ref.courtId}`,s:t.startTime,e:t.endTime}});n.push({day:r,blocks:e,avails:i})}return JSON.stringify(n)}checkDirtyState(){let e=this.takeSnapshot(),t=this.isDirty;this.isDirty=e!==this.initialSnapshot,this.isDirty!==t&&(this.viewToolbarResult?.setSaveEnabled(this.isDirty),this.config.onDirtyChange&&this.config.onDirtyChange(this.isDirty))}resetDirtyState(){this.initialSnapshot=this.takeSnapshot(),this.isDirty=!1,this.viewToolbarResult?.setSaveEnabled(!1),this.config.onDirtyChange&&this.config.onDirtyChange(!1)}updateStatsBar(){if(!this.statsBarInstance||!this.control)return;let e=this.control.getViewDays();if(e.length===0)return;let t=0,n=0,r=0,i=0;for(let a of e){let e=vV(this.engine.getCapacityCurve(a));t+=e.totalCourtHours,n+=e.totalUnavailableHours??0,r+=e.totalAvailableHours??0,i=e.totalCourts??0}let a=i||1;this.statsBarInstance.update({totalHours:t,blockedHours:n,availableHours:r,avgPerCourt:r/a})}updateCapacityStats(){if(!this.capacityElement||!this.control)return;let e=this.control.getViewDays();if(e.length===0)return;let t=0,n=0;for(let r of e){let e=vV(this.engine.getCapacityCurve(r));t+=e.totalAvailableHours??0,n=e.totalCourts??0}let r=this.capacityElement.querySelector(`#total-hours`),i=this.capacityElement.querySelector(`#avg-hours`);r&&(r.textContent=`${t.toFixed(1)}h`);let a=n>0?t/n:0;i&&(i.textContent=`${a.toFixed(1)}h`)}updateVenueTree(){if(!this.venueTreeElement)return;let e=this.venueTreeElement.querySelector(`#venue-tree-content`);if(!e)return;let t=this.engine.listCourtMeta(),n=this.engine.getConfig().tournamentId;this.visibleCourts.size===0&&t.forEach(e=>{let t=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;this.visibleCourts.add(t)});let r=new Map;for(let e of this.config.tournamentRecord?.venues||[]){let t=e.venueId;t&&r.set(t,e.venueName||e.venueAbbreviation||t)}let i=new Map;for(let e of t){let t=e.ref.venueId;i.has(t)||i.set(t,[]),i.get(t).push(e)}let a=``;for(let[e,t]of i){let i=t.every(e=>{let t=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;return this.visibleCourts.has(t)}),o=r.get(e)||e;a+=`
290
290
  <div class="venue-group">
291
291
  <div class="venue-header">
292
292
  <input type="checkbox" class="venue-checkbox"
@@ -318,5 +318,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
318
318
  `}).join(``)}
319
319
  </div>
320
320
  </div>
321
- `}e.innerHTML=a,e.querySelectorAll(`.court-checkbox`).forEach(e=>{e.addEventListener(`change`,this.handleCourtCheckboxChange)}),e.querySelectorAll(`.venue-checkbox`).forEach(e=>{e.addEventListener(`change`,this.handleVenueCheckboxChange)}),e.querySelectorAll(`.venue-edit-icon`).forEach(e=>{e.addEventListener(`click`,e=>{e.stopPropagation();let t=e.currentTarget,n=t.dataset.venue,r=t.dataset.tournamentId,i=t.dataset.venueName||n,a=this.control?.getDay()||this.engine.getActiveDays()[0]||`2026-01-01`,o=this.engine.getVenueAvailability(r,n),s=this.engine.getConfig();Yz({title:`Venue Defaults \u2014 ${i}`,currentDay:a,currentStartTime:o?.startTime||s.dayStartTime,currentEndTime:o?.endTime||s.dayEndTime,showScopeToggle:!1,onConfirm:({startTime:e,endTime:t})=>{this.engine.setVenueDefaultAvailability(r,n,{startTime:e,endTime:t}),this.engine.clearCourtAvailabilityForVenue(r,n),this.control?.refresh()}})})}),e.querySelectorAll(`.court-edit-icon`).forEach(e=>{e.addEventListener(`click`,e=>{e.stopPropagation();let t=e.currentTarget,n=t.dataset.courtId,r=t.dataset.venueId,i=t.dataset.tournamentId,a=t.dataset.courtName||n,o={tournamentId:i,venueId:r,courtId:n},s=this.control?.getDay()||this.engine.getActiveDays()[0]||`2026-01-01`,c=this.engine.getCourtAvailability(o,s);Yz({title:`Court \u2014 ${a}`,currentDay:s,currentStartTime:c.startTime,currentEndTime:c.endTime,showScopeToggle:!0,onConfirm:({startTime:e,endTime:t,scope:n})=>{n===`all-days`?this.engine.setCourtAvailabilityAllDays(o,{startTime:e,endTime:t}):this.engine.setCourtAvailability(o,s,{startTime:e,endTime:t}),this.control?.refresh()}})})})}updateVenueCheckboxState(e){let t=this.engine.listCourtMeta().filter(t=>t.ref.venueId===e),n=t.filter(e=>{let t=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;return this.visibleCourts.has(t)}).length,r=this.venueTreeElement?.querySelector(`.venue-checkbox[data-venue="${e}"]`);r&&(n===0?(r.checked=!1,r.indeterminate=!1):n===t.length?(r.checked=!0,r.indeterminate=!1):(r.checked=!1,r.indeterminate=!0))}getEngine(){return this.engine}getControl(){return this.control}setDay(e){this.control?.setDay(e),this.updateCapacityStats()}refresh(){this.control?.refresh(),this.updateCapacityStats(),this.updateVenueTree()}};function Qz(e,t){let n=new Zz(e);return n.render(t),n}var{LUCKY_DRAW:$z,ROUND_ROBIN:eB,AD_HOC:tB}=t.drawDefinitionConstants;function nB(e){let t=Math.max(2,e),n=2**Math.floor(Math.log2(t)),r=t-n;if(r<=0)return new Map;let i=new Map,a=0,o=n/2;for(;o>=1;)a++,r&o&&(a++,i.set(a,o)),o=Math.floor(o/2);return i}function rB(e){let t=Math.max(2,e),n=2**Math.floor(Math.log2(t)),r=t-n,i=0,a=n/2;for(;a>=1;)i++,r&a&&i++,a=Math.floor(a/2);return i}function iB(e){let t=Math.max(2,e),n=t%2?t+1:t,r=!!(Math.ceil(n/2)%2),i=[{participantsCount:n,preFeedRound:r}];for(;n>2;){let e=Math.ceil(n/2),t=e===1,r=!!(!t&&e%2);n=!t&&r?e+1:e;let a=!!(n!==2&&Math.ceil(n/2)%2);i.push({participantsCount:n,preFeedRound:a,feedRound:r})}return i}function aB(e){let t=Math.max(2,e);return t&t-1?iB(e).length:Math.ceil(Math.log2(t))}function oB(e,t){let n=Math.max(2,e);if(!(n&n-1))return Math.floor(n/2**t);let r=iB(e),i=t-1;if(i<0||i>=r.length)return 0;let{participantsCount:a,preFeedRound:o}=r[i],s=a/2,c=o?s-1:s;if(t===1&&n%2!=0){let e=a-n;c-=e}return c}function sB(e,t,n){return e===eB?(n?.groupSize||Math.min(t,4))-1:e===tB?n?.roundsCount||1:e===$z?aB(t):rB(t)}function cB(e,t,n){return e===$z?oB(t,n):Math.floor(t/2**n)}var{ROUND_ROBIN:lB,AD_HOC:uB,LUCKY_DRAW:dB}=t.drawDefinitionConstants,fB=0;function pB({structureType:e,drawSize:t,stage:n,structureId:r,qualifyingPositions:i,structureOptions:a}){return e===lB?hB({drawSize:t,stage:n,structureId:r,structureOptions:a}):e===uB?_B({drawSize:t,stage:n,structureId:r,roundsCount:a?.roundsCount||1}):e===dB?gB({drawSize:t,stage:n,structureId:r}):mB({drawSize:t,stage:n,structureId:r,qualifyingPositions:i})}function mB({drawSize:e,stage:t,structureId:n,qualifyingPositions:r}){let i=Math.max(2,e),a=2**Math.floor(Math.log2(i)),o=i-a,s=[],c=a/2;for(;c>=1;)s.push({count:c,isFeed:!1}),o&c&&s.push({count:c,isFeed:!0}),c=Math.floor(c/2);if(r&&r>0&&e>r){let t=Math.round(Math.log2(e/r));t>0&&s.length>t&&(s.length=t)}let l=s.length,u=[],d=1,f=0,p=new Set;for(let e=0;e<l-1;e++)!s[e].isFeed&&s[e+1].isFeed&&p.add(e);for(let e=0;e<l;e++){let{count:r,isFeed:i}=s[e],a=e+1,o=i?2**Math.max(0,f-1):2**f,c=i||p.has(e);for(let s=1;s<=r;s++){let r=a===1&&!i;u.push({matchUpId:`preview-${++fB}`,roundNumber:a,roundPosition:s,drawPositions:r?[(s-1)*2+1,(s-1)*2+2]:i?[d++]:[],finishingRound:l-e,roundFactor:o,preFeedRound:c,stage:t,structureId:n})}i||f++}return u}function hB({drawSize:e,stage:t,structureId:n,structureOptions:r}){let i=[],a=r?.groupSize||Math.min(e,4),o=Math.ceil(e/a),s=a-1;for(let e=0;e<o;e++)for(let r=1;r<=s;r++){let o=Math.floor(a/2);for(let a=1;a<=o;a++)i.push({matchUpId:`preview-${++fB}`,roundNumber:r,roundPosition:e*o+a,isRoundRobin:!0,stage:t,structureId:`${n}-g${e}`})}return i}function gB({drawSize:e,stage:t,structureId:n}){let r=Math.max(2,e);if(!(r&r-1))return mB({drawSize:e,stage:t,structureId:n});let i=iB(r),a=i.length,o=[],s=1;for(let e=0;e<a;e++){let{participantsCount:r,preFeedRound:c}=i[e],l=r/2,u=e+1;for(let r=1;r<=l;r++){let i=u===1;o.push({matchUpId:`preview-${++fB}`,roundNumber:u,roundPosition:r,drawPositions:i?[s++,s++]:[],finishingRound:a-e,roundFactor:1,preFeedRound:!!c,stage:t,structureId:n})}}return o}function _B({drawSize:e,stage:t,structureId:n,roundsCount:r=1}){let i=[];if(e<2)return i;let a=Math.floor(e/2);for(let e=1;e<=r;e++)for(let r=1;r<=a;r++)i.push({matchUpId:`preview-${++fB}`,roundNumber:e,roundPosition:r,finishingRound:1,stage:t,structureId:n});return i}var{ROUND_ROBIN:vB}=t.drawDefinitionConstants,yB=new Map;function bB(e,n,r){let i=`${e}:${n}:${r||``}`,a=yB.get(i);if(a)return a;try{let a={drawSize:n,drawType:e};r&&(a.structureOptions={groupSize:r});let{tournamentRecord:o}=t.mocksEngine.generateTournamentRecord({drawProfiles:[a]}),s=o?.events?.[0]?.drawDefinitions?.[0];if(!s)return xB(i,{});let c=(s.structures||[])[0];if(!c)return xB(i,{});let l=c.structureType===`CONTAINER`,u={};if(l||e===vB){let{availablePlayoffProfiles:e}=t.drawsGovernor.getAvailablePlayoffProfiles({drawDefinition:s}),n=e?.[0];n&&(u={playoffFinishingPositionRanges:n.playoffFinishingPositionRanges,finishingPositionsAvailable:n.finishingPositionsAvailable})}else{let e=c.structureId,{playoffRounds:n,playoffRoundsRanges:r}=t.drawsGovernor.getAvailablePlayoffProfiles({drawDefinition:s,structureId:e});u={playoffRounds:n,playoffRoundsRanges:r}}return xB(i,u)}catch{return xB(i,{})}}function xB(e,t){return yB.set(e,t),t}var{MAIN:SB,QUALIFYING:CB,CONSOLATION:wB,PLAY_OFF:TB,ROUND_ROBIN:EB,AD_HOC:DB,LUCKY_DRAW:OB,WINNER:kB,LOSER:AB}=t.drawDefinitionConstants,jB=240,MB=48,NB=16;function PB(e){if(e.structureType===EB)return(e.structureOptions?.groupSize||Math.min(e.drawSize,4))-1;if(e.structureType===DB)return e.structureOptions?.roundsCount||1;if(e.structureType===OB)return aB(e.drawSize);let t=Math.max(2,e.drawSize),n=2**Math.floor(Math.log2(t)),r=t-n,i=0,a=n/2;for(;a>=1;)i++,r&a&&i++,a=Math.floor(a/2);if(e.qualifyingPositions&&e.qualifyingPositions>0&&e.drawSize>e.qualifyingPositions){let t=Math.round(Math.log2(e.drawSize/e.qualifyingPositions));t>0&&t<i&&(i=t)}return i}function FB(e){let t=PB(e);return Math.max(jB,t*MB+NB)}var IB={[SB]:`tb-card-badge--main`,[CB]:`tb-card-badge--qualifying`,[wB]:`tb-card-badge--consolation`,[TB]:`tb-card-badge--playoff`};function LB(e,t,n,r,i,a,o,s){let c=a&&a.length>0,l=document.createElement(`div`);l.className=`tb-card${n?` tb-card--selected`:``}${c?` tb-card--warning`:``}`,l.style.left=`${e.position.x}px`,l.style.top=`${e.position.y}px`,l.style.minWidth=`${FB(e)}px`,l.setAttribute(`data-node-id`,e.id);let u=document.createElement(`div`);u.className=`tb-card-header`;let d=document.createElement(`span`);d.className=`tb-card-badge ${IB[e.stage]||`tb-card-badge--main`}`,d.textContent=e.stage.substring(0,4);let f=document.createElement(`span`);f.className=`tb-card-name`,f.textContent=e.structureName;let p=document.createElement(`span`);if(p.className=`tb-card-size`,p.textContent=`\u00d7${e.drawSize}`,u.appendChild(d),u.appendChild(f),u.appendChild(p),o){let e=document.createElement(`div`);e.className=`tb-card-advance`,e.textContent=o,u.appendChild(e)}let m=document.createElement(`div`);m.className=`tb-card-preview`;let h=e.matchUps||pB({structureType:e.structureType,drawSize:e.drawSize,stage:e.stage,structureId:e.id,qualifyingPositions:e.qualifyingPositions,structureOptions:e.structureOptions});if(h.length>0)try{let t=Di({matchUps:h,structureId:e.id,showHeaders:!1});t.style.transform=`scale(0.8)`,t.style.transformOrigin=`top left`,m.appendChild(t)}catch{m.textContent=`${e.structureType} \u00d7${e.drawSize}`,m.style.cssText+=`font-size:11px;color:var(--chc-text-muted);display:flex;align-items:center;justify-content:center;`}if(i?.length&&m.querySelector(`.chc-schematic-structure`)){let e=m.querySelectorAll(`.chc-schematic-round-container[data-round-number]`);for(let n of e){let e=parseInt(n.getAttribute(`data-round-number`)||`0`),r=i.filter(t=>t.roundNumber===e);if(!r.length)continue;let a=r.find(e=>e.isSelected)||r.find(e=>e.linkType===AB)||r.find(e=>e.linkType===kB)||r[0];n.classList.add(`tb-round-linked`),n.classList.add(`tb-round-linked--${a.linkType.toLowerCase()}`),n.classList.add(`tb-round-linked--${a.direction}`),a.isSelected&&n.classList.add(`tb-round-linked--active`),n.style.cursor=`pointer`,n.addEventListener(`click`,e=>{e.stopPropagation(),t.onSelectEdge(a.edgeId)}),n.title=r.map(t=>`R${e} ${t.linkType} ${t.direction===`source`?`out`:`in`}`).join(`, `)}}let g=bB(e.structureType,e.drawSize,e.structureOptions?.groupSize),_=null;g.playoffRoundsRanges?.length?(_=document.createElement(`div`),_.className=`tb-card-rounds`,_.textContent=g.playoffRoundsRanges.map(e=>`R${e.roundNumber}:${e.finishingPositionRange}`).join(` `)):g.playoffFinishingPositionRanges?.length&&(_=document.createElement(`div`),_.className=`tb-card-rounds`,_.textContent=g.playoffFinishingPositionRanges.map(e=>`P${e.finishingPosition}:${e.finishingPositionRange}`).join(` `));let v=document.createElement(`div`);v.className=`tb-card-ports`;let y=document.createElement(`div`);y.className=`tb-port tb-port--input`,y.title=`Input`,y.addEventListener(`mouseup`,()=>{t.onPortMouseUp(e.id)});let b=document.createElement(`div`);b.className=`tb-port-group`;let x=document.createElement(`div`);x.className=`tb-port tb-port--winner${r?` tb-port--connected`:``}`,x.title=r?`Winner linked`:`Winner output`,r||x.addEventListener(`mousedown`,n=>{n.stopPropagation(),t.onPortMouseDown(e.id,`winner`)});let S=document.createElement(`div`);if(S.className=`tb-port tb-port--loser`,S.title=`Loser output`,S.addEventListener(`mousedown`,n=>{n.stopPropagation(),t.onPortMouseDown(e.id,`loser`)}),b.appendChild(x),b.appendChild(S),v.appendChild(y),v.appendChild(b),l.appendChild(u),l.appendChild(m),s?.length){let e=document.createElement(`div`);e.className=`tb-card-chips`;for(let n of s){let r=document.createElement(`span`);r.className=`tb-card-chip`,r.textContent=`P${n.position}`,r.title=`Position ${n.position} → ${n.targetName}`,r.addEventListener(`click`,e=>{e.stopPropagation(),t.onSelectEdge(n.edgeId)}),e.appendChild(r)}l.appendChild(e)}if(_&&l.appendChild(_),c){let e=document.createElement(`div`);e.className=`tb-card-warning`,e.textContent=`⚠ Issue`;let t=document.createElement(`div`);t.className=`tb-card-warning-detail`,t.textContent=a.join(`; `),e.appendChild(t),e.addEventListener(`click`,t=>{t.stopPropagation(),e.classList.toggle(`tb-card-warning--open`)}),l.appendChild(e)}return l.appendChild(v),l.addEventListener(`mouseup`,()=>{t.onPortMouseUp(e.id)}),l.addEventListener(`click`,n=>{n.stopPropagation(),t.onSelect(e.id)}),t.onDoubleClick&&l.addEventListener(`dblclick`,n=>{n.stopPropagation(),t.onDoubleClick(e.id)}),l.addEventListener(`mousedown`,n=>{n.target.classList.contains(`tb-port`)||t.onDragStart(e.id,n.clientX,n.clientY)}),l}function RB(e,t){let n=FB(e);switch(t){case`input`:return{x:e.position.x,y:e.position.y+80};case`winner`:return{x:e.position.x+n,y:e.position.y+80-8};case`loser`:return{x:e.position.x+n,y:e.position.y+80+8}}}var{MAIN:zB,QUALIFYING:BB,CONSOLATION:VB,WINNER:HB,LOSER:UB,ROUND_ROBIN:WB}=t.drawDefinitionConstants,GB=`POSITION`,KB=0;function qB(e){return`${e}-${++KB}-${Date.now().toString(36)}`}function JB(e){let t=2;for(;t*2<=e;)t*=2;return t}var YB=60,XB=class{constructor(e){this.listeners=new Set,this.state={nodes:[],edges:[],selectedNodeId:null,selectedEdgeId:null,drawName:`New Draw`,...e}}getState(){return{...this.state}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){let e=this.getState();for(let t of this.listeners)t(e)}setDrawName(e){this.state.drawName=e,this.notify()}addNode(e){let t={...e,id:qB(`node`),position:this.nextNodePosition()};return this.state.nodes.push(t),this.state.templateName=void 0,this.notify(),t}updateNode(e,t){let n=this.state.nodes.find(t=>t.id===e);n&&(Object.keys(t).some(e=>e!==`position`)&&(this.state.templateName=void 0),Object.assign(n,t),this.notify())}removeNode(e){let t=this.state.edges.filter(t=>t.sourceNodeId===e).map(e=>e.targetNodeId);this.state.nodes=this.state.nodes.filter(t=>t.id!==e),this.state.edges=this.state.edges.filter(t=>t.sourceNodeId!==e&&t.targetNodeId!==e),this.state.selectedNodeId===e&&(this.state.selectedNodeId=null),this.state.templateName=void 0;for(let e of t)this.clampConsolationDrawSize(e);this.notify()}addEdge(e){if(e.linkType===HB&&this.state.edges.find(t=>t.sourceNodeId===e.sourceNodeId&&t.linkType===HB))return null;let t=this.state.nodes.find(t=>t.id===e.sourceNodeId),n=this.state.nodes.find(t=>t.id===e.targetNodeId);if(t?.structureType===WB&&e.linkType!==GB||t?.stage===BB&&n&&n.stage!==BB&&n.stage!==zB||n?.stage===BB&&t&&t.stage!==BB)return null;let r={...e,id:qB(`edge`),targetRoundNumber:e.targetRoundNumber||1,label:this.computeEdgeLabel(e)};return this.state.edges.push(r),this.state.templateName=void 0,this.clampConsolationDrawSize(r.targetNodeId),this.notify(),r}updateEdge(e,t){let n=this.state.edges.find(t=>t.id===e);n&&(Object.assign(n,t),n.label=this.computeEdgeLabel(n),this.state.templateName=void 0,this.notify())}removeEdge(e){let t=this.state.edges.find(t=>t.id===e);this.state.edges=this.state.edges.filter(t=>t.id!==e),this.state.selectedEdgeId===e&&(this.state.selectedEdgeId=null),this.state.templateName=void 0,t&&this.clampConsolationDrawSize(t.targetNodeId),this.notify()}selectNode(e){this.state.selectedNodeId=e,this.state.selectedEdgeId=null,this.notify()}selectEdge(e){this.state.selectedEdgeId=e,this.state.selectedNodeId=null,this.notify()}clampConsolationDrawSize(e){let t=this.state.nodes.find(t=>t.id===e);if(!t||t.stage!==VB)return;let n=this.inboundCapacity(e);n>0&&t.drawSize>n&&(t.drawSize=JB(n))}inboundCapacity(e){let t=this.state.edges.filter(t=>t.targetNodeId===e),n=0;for(let e of t){let t=this.state.nodes.find(t=>t.id===e.sourceNodeId);if(t){if(e.linkType===UB){let r=e.sourceRoundNumber||1;n+=cB(t.structureType,t.drawSize,r)}else n+=t.qualifyingPositions||Math.floor(t.drawSize/2)}}return n}nextNodePosition(){if(this.state.nodes.length===0)return{x:40,y:40};let e=0;for(let t of this.state.nodes)e=Math.max(e,t.position.x+FB(t));return{x:e+YB,y:40}}autoLayout(){let e=this.state.nodes,t=this.state.edges;if(!e.length)return;let n=new Map,r=new Map;for(let e of t)r.has(e.sourceNodeId)||r.set(e.sourceNodeId,[]),r.get(e.sourceNodeId).push(e.targetNodeId),n.has(e.targetNodeId)||n.set(e.targetNodeId,[]),n.get(e.targetNodeId).push(e.sourceNodeId);let i=e.filter(e=>!n.has(e.id)||n.get(e.id).length===0);if(!i.length){let t=e.filter(e=>e.stage===zB);i.push(...t.length?t:[e[0]])}let a=new Map,o=new Set(e.filter(e=>e.stage===BB).map(e=>e.id)),s=[];for(let e of i)o.has(e.id)?a.set(e.id,-1):a.set(e.id,0),s.push(e.id);let c=e.length*(e.length-1)+e.length,l=0;for(;s.length&&l<c;){l++;let e=s.shift(),t=a.get(e),n=r.get(e)||[];for(let e of n){let n=t+1,r=a.get(e);(r===void 0||n>r)&&(a.set(e,n),s.push(e))}}for(let t of e)a.has(t.id)||a.set(t.id,0);let u=Math.min(...a.values());if(u<0)for(let[e,t]of a)a.set(e,t-u);let d=new Map;for(let t of e){let e=a.get(t.id);d.has(e)||d.set(e,[]),d.get(e).push(t)}let f=[...d.keys()].sort((e,t)=>e-t),p=40;for(let e of f){let t=d.get(e),n=Math.max(...t.map(e=>FB(e)));t.forEach((e,t)=>{e.position={x:p,y:t*190+40}}),p+=n+YB}}loadState(e){this.state={...e},this.notify()}computeEdgeLabel(e){let t=e.linkType||`LINK`,n=``;return e.sourceRoundNumber&&(n+=`R${e.sourceRoundNumber} `),n+=t.toLowerCase(),e.targetRoundNumber&&(n+=` \u2192 R${e.targetRoundNumber}`),e.qualifyingPositions&&(n+=` (${e.qualifyingPositions}Q)`),e.finishingPositions?.length&&(n+=` [${e.finishingPositions.join(`,`)}]`),n}},{WINNER:ZB,LOSER:QB,QUALIFYING:$B,CONSOLATION:eV,ROUND_ROBIN:tV}=t.drawDefinitionConstants,nV=`POSITION`,rV=e=>e===tV;function iV(e,t){if(!rV(e.structureType))return;let n=t.edges.filter(t=>t.sourceNodeId===e.id&&t.linkType===nV);if(!n.length)return;let r=new Set(n.flatMap(e=>e.finishingPositions||[])),i=e.structureOptions?.groupSize||4;return`${r.size} of ${i} advance`}var aV=`http://www.w3.org/2000/svg`,oV={[ZB]:`tb-edge--winner`,[QB]:`tb-edge--loser`,[nV]:`tb-edge--position`};function sV(e){let t=document.createElement(`div`);t.className=`tb-canvas`;let n=document.createElementNS(aV,`svg`);n.classList.add(`tb-canvas-svg`);let r=document.createElementNS(aV,`defs`);for(let[e,t]of Object.entries(oV)){let n=document.createElementNS(aV,`marker`);n.setAttribute(`id`,`arrowhead-${e}`),n.setAttribute(`markerWidth`,`8`),n.setAttribute(`markerHeight`,`6`),n.setAttribute(`refX`,`8`),n.setAttribute(`refY`,`3`),n.setAttribute(`orient`,`auto`);let i=document.createElementNS(aV,`polygon`);i.setAttribute(`points`,`0 0, 8 3, 0 6`),i.setAttribute(`class`,t),i.style.fill=`currentColor`,n.appendChild(i),r.appendChild(n)}n.appendChild(r);let i=document.createElement(`div`);i.className=`tb-canvas-nodes`;let a=document.createElement(`div`);a.className=`tb-canvas-spacer`,t.appendChild(n),t.appendChild(i),t.appendChild(a);let o=null,s=null,c=null,l=!1,u=null;t.addEventListener(`click`,()=>{l||(e.onSelectNode(null),e.onSelectEdge(null))}),t.addEventListener(`mousemove`,n=>{if(s&&!c){let e=n.clientX-s.startX,t=n.clientY-s.startY;Math.abs(e)+Math.abs(t)>=4&&(c=s,s=null)}if(c&&u){let t=n.clientX-c.startX,r=n.clientY-c.startY;e.onMoveNode(c.nodeId,Math.max(0,c.origX+t),Math.max(0,c.origY+r))}if(o?.tempLine){let e=t.getBoundingClientRect();o.tempLine.setAttribute(`x2`,String(n.clientX-e.left+t.scrollLeft)),o.tempLine.setAttribute(`y2`,String(n.clientY-e.top+t.scrollTop))}}),t.addEventListener(`mouseup`,()=>{c&&(l=!0,c=null,setTimeout(()=>{l=!1},0)),s=null,o?.tempLine&&(n.removeChild(o.tempLine),o=null)});function d(e){return new Set(e.edges.filter(e=>e.linkType===ZB).map(e=>e.sourceNodeId).filter(t=>{let n=e.nodes.find(e=>e.id===t);return n&&n.stage===$B&&!rV(n.structureType)}))}function f(e){let t=new Map;for(let n of e.edges){let r=n.sourceRoundNumber,i=n.targetRoundNumber,a=n.id===e.selectedEdgeId;if(!r&&n.linkType===ZB){let t=e.nodes.find(e=>e.id===n.sourceNodeId);t&&(r=PB(t))}r&&(t.has(n.sourceNodeId)||t.set(n.sourceNodeId,[]),t.get(n.sourceNodeId).push({roundNumber:r,linkType:n.linkType,direction:`source`,edgeId:n.id,isSelected:a})),i&&(t.has(n.targetNodeId)||t.set(n.targetNodeId,[]),t.get(n.targetNodeId).push({roundNumber:i,linkType:n.linkType,direction:`target`,edgeId:n.id,isSelected:a}))}return t}function p(e){let t=new Map;for(let n of e.edges){if(n.linkType!==ZB)continue;let r=n.targetRoundNumber||1;if(r<=1)continue;let i=e.nodes.find(e=>e.id===n.sourceNodeId);if(!i||i.stage!==$B)continue;t.has(n.targetNodeId)||t.set(n.targetNodeId,[]);let a=i.qualifyingPositions||Math.floor(i.drawSize/4);t.get(n.targetNodeId).push({targetRound:r,qp:a,warning:`Round ${r} needs fed drawPositions to accommodate ${i.structureName} link`})}let n=new Map;for(let[r,i]of t){let t=e.nodes.find(e=>e.id===r);if(!t)continue;let a=nB(t.drawSize),o=new Map;for(let e of i)o.set(e.targetRound,(o.get(e.targetRound)||0)+e.qp);let s=[];for(let e of i)(a.get(e.targetRound)||0)<(o.get(e.targetRound)||0)&&s.push(e.warning);s.length>0&&n.set(r,s)}return n}function m(e){let t=new Map;for(let n of e.nodes){if(!rV(n.structureType))continue;let r=e.edges.filter(e=>e.sourceNodeId===n.id&&e.linkType===nV);if(!r.length)continue;let i=[];for(let t of r){let n=e.nodes.find(e=>e.id===t.targetNodeId);for(let e of t.finishingPositions||[])i.push({position:e,edgeId:t.id,targetName:n?.structureName||`?`})}i.sort((e,t)=>e.position-t.position),t.set(n.id,i)}return t}function h(e,t,n){return e&&rV(e.structureType)?nV:n===`loser`||t?.stage===eV?QB:ZB}function g(t){return{onSelect:t=>{e.onSelectNode(t)},onSelectEdge:t=>{e.onSelectEdge(t)},onDoubleClick:e.onDoubleClickNode?t=>e.onDoubleClickNode(t):void 0,onPortMouseDown:(e,r)=>{let i=t.nodes.find(t=>t.id===e);if(!i)return;let a=RB(i,r),s=document.createElementNS(aV,`line`);s.setAttribute(`x1`,String(a.x)),s.setAttribute(`y1`,String(a.y)),s.setAttribute(`x2`,String(a.x)),s.setAttribute(`y2`,String(a.y)),s.setAttribute(`stroke`,r===`winner`?`green`:`red`),s.setAttribute(`stroke-width`,`2`),s.setAttribute(`stroke-dasharray`,`4 2`),n.appendChild(s),o={sourceNodeId:e,portType:r,tempLine:s}},onPortMouseUp:r=>{if(o&&o.sourceNodeId!==r){let n=h(t.nodes.find(e=>e.id===o.sourceNodeId),t.nodes.find(e=>e.id===r),o.portType);e.onCreateEdge(o.sourceNodeId,r,n)}o?.tempLine&&n.removeChild(o.tempLine),o=null},onDragStart:(e,n,r)=>{let i=t.nodes.find(t=>t.id===e);i&&(s={nodeId:e,startX:n,startY:r,origX:i.position.x,origY:i.position.y})}}}function _(e){u=e,i.innerHTML=``;let t=d(e),r=f(e),o=p(e),s=m(e),c=g(e);for(let n of e.nodes){let a=LB(n,c,e.selectedNodeId===n.id,t.has(n.id),r.get(n.id),o.get(n.id),iV(n,e),s.get(n.id));i.appendChild(a)}n.querySelectorAll(`path, text.tb-edge-label, path.tb-edge-hit`).forEach(e=>n.removeChild(e));let l=new Map;for(let t of e.edges){let e=`${t.sourceNodeId}:${t.targetNodeId}`;l.has(e)||l.set(e,[]),l.get(e).push(t)}for(let t of l.values()){let r=t.length;t.forEach((t,i)=>{let a=r>1?(i-(r-1)/2)*14:0;v(n,t,e,a)})}let h=600,_=400;for(let t of e.nodes)h=Math.max(h,t.position.x+FB(t)+40),_=Math.max(_,t.position.y+180);n.setAttribute(`width`,String(h)),n.setAttribute(`height`,String(_)),i.style.width=`${h}px`,i.style.height=`${_}px`,a.style.width=`${h}px`,a.style.height=`${_}px`}function v(t,n,r,i=0){let a=r.nodes.find(e=>e.id===n.sourceNodeId),o=r.nodes.find(e=>e.id===n.targetNodeId);if(!a||!o)return;let s=RB(a,n.linkType===QB?`loser`:`winner`),c=RB(o,`input`),l=s.y+i,u=c.y+i,d=c.x-s.x,f=`M ${s.x},${l} C ${s.x+d/2},${l} ${s.x+d/2},${u} ${c.x},${u}`,p=document.createElementNS(aV,`path`);p.setAttribute(`d`,f),p.classList.add(`tb-edge-hit`),p.addEventListener(`click`,t=>{t.stopPropagation(),e.onSelectEdge(n.id)}),t.appendChild(p);let m=document.createElementNS(aV,`path`);if(m.setAttribute(`d`,f),m.classList.add(oV[n.linkType]||`tb-edge--winner`),r.selectedEdgeId===n.id&&m.classList.add(`tb-edge--selected`),m.setAttribute(`marker-end`,`url(#arrowhead-${n.linkType})`),m.addEventListener(`click`,t=>{t.stopPropagation(),e.onSelectEdge(n.id)}),t.appendChild(m),n.label){let e=(s.x+c.x)/2,r=(l+u)/2-8,i=document.createElementNS(aV,`text`);i.classList.add(`tb-edge-label`),i.setAttribute(`x`,String(e)),i.setAttribute(`y`,String(r)),i.setAttribute(`text-anchor`,`middle`),i.textContent=n.label,t.appendChild(i)}}return{element:t,update:_}}var{SINGLE_ELIMINATION:cV,ROUND_ROBIN:lV,FEED_IN:uV,FEED_IN_CHAMPIONSHIP:dV,FIRST_MATCH_LOSER_CONSOLATION:fV,COMPASS:pV,OLYMPIC:mV,AD_HOC:hV,LUCKY_DRAW:gV,MAIN:_V,QUALIFYING:vV,CONSOLATION:yV,PLAY_OFF:bV,WINNER:xV}=t.drawDefinitionConstants,SV=`POSITION`,CV=[{label:`Single Elimination`,value:cV},{label:`Round Robin`,value:lV},{label:`Feed-In Championship`,value:dV},{label:`FMLC`,value:fV},{label:`Compass`,value:pV},{label:`Olympic`,value:mV},{label:`Ad-hoc`,value:hV}],wV=[{label:`Single Elimination`,value:cV},{label:`Round Robin`,value:lV},{label:`Lucky Draw`,value:gV},{label:`Staggered Entry`,value:uV},{label:`Ad-hoc`,value:hV}],TV=[{label:`Main`,value:_V},{label:`Qualifying`,value:vV},{label:`Consolation`,value:yV},{label:`Playoff`,value:bV}];function EV(e){let t=[],n=Math.floor(e/2);for(;n>=1;)t.push(n),n=Math.floor(n/2);return t}function DV(e,t=8){let n=[];for(let r=3;r<=t;r++){let t=Math.ceil(e/r),i=t*r-e,a=Math.ceil(e/t),o=Math.ceil(i/t);(!i||i<r)&&a===r&&a>=3&&o<2&&n.push(r)}return n}function OV(e,t,n,r,i,a){let o=DV(e.drawSize),s=e.structureOptions?.groupSize||4,c=o.includes(s)?o:[s,...o].sort((e,t)=>e-t),l=Math.ceil(e.drawSize/s);i.push({label:`Group Size`,field:`groupSize`,value:String(s),disabled:n,options:c.map(e=>({label:String(e),value:String(e),selected:e===s}))}),i.push({label:`Groups`,field:`groupCount`,value:String(l),disabled:!0}),n||a.push({control:`groupSize`,onChange:({e:t})=>{let n=parseInt(t.target.value);r.onUpdateNode(e.id,{structureOptions:{...e.structureOptions,groupSize:n}})}});let u=t.edges.filter(t=>t.sourceNodeId===e.id&&t.linkType===SV),d=new Set(u.flatMap(e=>e.finishingPositions||[])),f=d.size||0,p=Array.from({length:s},(e,t)=>t+1);i.push({label:`Advance Per Group`,field:`advancePerGroup`,value:String(f),disabled:n||u.length===0,options:p.map(e=>({label:String(e),value:String(e),selected:e===f}))}),!n&&u.length>0&&a.push({control:`advancePerGroup`,onChange:({e})=>{let t=parseInt(e.target.value),n=d.size;if(t!==n){if(t>n){let e=u.at(-1),n=[];for(let e=1;e<=s&&d.size+n.length<t;e++)d.has(e)||n.push(e);n.length>0&&r.onUpdateEdge(e.id,{finishingPositions:[...e.finishingPositions||[],...n].sort((e,t)=>e-t)})}else{let e=[...d].sort((e,t)=>t-e),i=new Set(e.slice(0,n-t));for(let e of u){let t=(e.finishingPositions||[]).filter(e=>!i.has(e));t.length!==(e.finishingPositions||[]).length&&r.onUpdateEdge(e.id,{finishingPositions:t})}}}}}),u.length>0&&f>0&&kV(u,t,l,i)}function kV(e,t,n,r){let i=new Map;for(let t of e)i.has(t.targetNodeId)||i.set(t.targetNodeId,[]),i.get(t.targetNodeId).push(...t.finishingPositions||[]);let a=[];for(let[e,r]of i){let i=t.nodes.find(t=>t.id===e),o=[...new Set(r)].sort((e,t)=>e-t),s=o.length===1?`P${o[0]}`:`P${o.join(`,`)}`;a.push(`${s} → ${i?.structureName||`?`} (${o.length*n})`)}a.length>0&&r.push({label:`Playoff Groups`,field:`playoffSummary`,value:a.join(`
322
- `),disabled:!0})}function AV(e,t,n,r,i,a){let o=t.edges.find(t=>t.targetNodeId===e.id&&t.linkType===SV);if(!o||t.nodes.find(e=>e.id===o.sourceNodeId)?.structureType!==lV)return;let s=e.structureOptions?.playoffDrawType||cV;if(i.push({label:`Playoff Draw Type`,field:`playoffDrawType`,value:s,disabled:n,options:CV.map(e=>({...e,selected:e.value===s}))}),n||a.push({control:`playoffDrawType`,onChange:({e:t})=>r.onUpdateNode(e.id,{structureOptions:{...e.structureOptions,playoffDrawType:t.target.value}})}),s===lV){let t=e.structureOptions?.groupSize||4;i.push({label:`Playoff Group Size`,field:`playoffGroupSize`,value:String(t),disabled:n,options:[3,4,5,6,8].map(e=>({label:String(e),value:String(e),selected:e===t}))}),n||a.push({control:`playoffGroupSize`,onChange:({e:t})=>r.onUpdateNode(e.id,{structureOptions:{...e.structureOptions,groupSize:parseInt(t.target.value)}})})}}function jV(e,t,n,r,i){let a=EV(e.drawSize),o=e.qualifyingPositions??a[0];r.push({label:`Qualifying Positions`,field:`qualifyingPositions`,value:String(o),disabled:t,options:a.map(e=>({label:String(e),value:String(e),selected:e===o}))}),t||i.push({control:`qualifyingPositions`,onChange:({e:t})=>n.onUpdateNode(e.id,{qualifyingPositions:parseInt(t.target.value)})})}function MV(e,t,n){let r=nB(e.drawSize),i=new Map,a=[];for(let n of t.edges){if(n.linkType!==xV||n.targetNodeId!==e.id)continue;let r=n.targetRoundNumber||1;if(r<=1)continue;let o=t.nodes.find(e=>e.id===n.sourceNodeId);if(!o||o.stage!==vV)continue;let s=o.qualifyingPositions||Math.floor(o.drawSize/4);i.set(r,(i.get(r)||0)+s),a.push({targetRound:r,qp:s,sourceName:o.structureName})}let o=[];for(let e of a){let t=r.get(e.targetRound)||0;t>=(i.get(e.targetRound)||0)||(t===0?o.push(`Round ${e.targetRound} is not a feed round — ${e.sourceName} sends ${e.qp} qualifiers`):o.push(`Round ${e.targetRound} has ${t} feed positions but ${e.sourceName} sends ${e.qp} qualifiers`))}if(o.length>0){let e=document.createElement(`div`);e.className=`tb-editor-warning`;for(let t of o){let n=document.createElement(`div`);n.textContent=`\u26a0 ${t}`,e.appendChild(n)}let t=document.createElement(`div`);t.style.marginTop=`6px`,t.textContent=`Change the target round to a feed round, or increase the draw size to create feed positions at that round.`,e.appendChild(t),n.appendChild(e)}}function NV(e){let t=document.createElement(`div`),n=!!e.readOnly;function r(r){t.innerHTML=``;let i=r.selectedNodeId?r.nodes.find(e=>e.id===r.selectedNodeId):null;if(!i)return;let a=document.createElement(`div`);a.className=`tb-editor-header`,a.textContent=`Structure Properties`,t.appendChild(a);let o=document.createElement(`div`);o.className=`tb-editor-body`;let s=[{label:`Name`,field:`structureName`,value:i.structureName,...n?{disabled:!0}:{validator:Hx(1),error:`Name required`}},{label:`Stage`,field:`stage`,value:i.stage,disabled:n,options:TV.map(e=>({...e,selected:e.value===i.stage}))},{label:`Structure Type`,field:`structureType`,value:i.structureType,disabled:n,options:wV.map(e=>({...e,selected:e.value===i.structureType}))},{label:i.stage===_V?`Draw Size`:`Structure Size`,field:`drawSize`,type:`number`,value:String(i.drawSize),...n?{disabled:!0}:i.structureType===hV?{validator:Wx(0,256),error:`Must be 0-256`}:{validator:Wx(2,256),error:`Must be 2-256`}}],c=n?[]:[{control:`structureName`,onChange:({inputs:t})=>e.onUpdateNode(i.id,{structureName:t.structureName.value})},{control:`stage`,onChange:({e:t})=>e.onUpdateNode(i.id,{stage:t.target.value})},{control:`structureType`,onChange:({e:t})=>e.onUpdateNode(i.id,{structureType:t.target.value})},{control:`drawSize`,onChange:({inputs:t})=>{let n=parseInt(t.drawSize.value);if(n<(i.structureType===hV?0:2))return;let r={drawSize:n};if(i.structureType===lV){let e=i.structureOptions?.groupSize||4,t=DV(n);!t.includes(e)&&t.length>0&&(r.structureOptions={...i.structureOptions,groupSize:t[0]})}e.onUpdateNode(i.id,r)}}];i.structureType===lV&&OV(i,r,n,e,s,c),i.stage===bV&&AV(i,r,n,e,s,c),i.stage===vV&&jV(i,n,e,s,c),Oi(o,s,c);let l=document.createElement(`div`);l.className=`field font-medium`,l.style.cssText=`flex-grow: 1`;let u=document.createElement(`label`);u.style.cssText=`font-weight: bold; font-size: larger;`,u.textContent=`MatchUp Format`,l.appendChild(u);let d=document.createElement(`div`);if(d.className=`tb-format-trigger`,d.textContent=i.matchUpFormat||`Not set`,n?(d.style.cursor=`default`,d.style.opacity=`0.7`):d.onclick=()=>{Ha({existingMatchUpFormat:i.matchUpFormat,callback:t=>{e.onUpdateNode(i.id,{matchUpFormat:t||void 0}),d.textContent=t||`Not set`}})},l.appendChild(d),o.appendChild(l),MV(i,r,o),!n&&!e.hideDelete){let t=document.createElement(`button`);t.className=`sp-btn sp-btn--danger sp-btn--full`,t.style.marginTop=`12px`,t.textContent=`Delete Structure`,t.onclick=()=>e.onDeleteNode(i.id),o.appendChild(t)}t.appendChild(o)}return{element:t,update:r}}var{WINNER:PV,LOSER:FV,TOP_DOWN:IV,BOTTOM_UP:LV,QUALIFYING:RV,ROUND_ROBIN:zV}=t.drawDefinitionConstants,BV=`POSITION`,VV=`ALTERNATING`,HV=e=>e===zV,UV=[{label:`Winner`,value:PV},{label:`Loser`,value:FV},{label:`Position`,value:BV}],WV=[{label:`Top-Down`,value:IV},{label:`Bottom-Up`,value:LV},{label:`Alternating`,value:VV}];function GV(e){let t=document.createElement(`div`),n=!!e.readOnly;function r(t,r,i,a,o,s){let c=[],l=[],u=r?bB(r.structureType,r.drawSize,r.structureOptions?.groupSize):{},d=u.playoffRoundsRanges&&u.playoffRoundsRanges.length>0;if(d){let e=u.playoffRoundsRanges.map(e=>({label:`R${e.roundNumber} (${e.finishingPositionRange})`,value:String(e.roundNumber),selected:e.roundNumber===(t.sourceRoundNumber||a)}));c.push({label:`Source Round`,field:`sourceRoundNumber`,value:String(t.sourceRoundNumber||a),disabled:n,options:e})}else c.push({label:`Source Round`,field:`sourceRoundNumber`,type:`number`,value:String(t.sourceRoundNumber||a),disabled:n});return c.push({label:s?`Enter at Round`:`Target Round`,field:`targetRoundNumber`,type:`number`,value:String(t.targetRoundNumber||0),disabled:n}),n||(d?l.push({control:`sourceRoundNumber`,onChange:({e:n})=>{let r=Number.parseInt(n.target.value)||0;e.onUpdateEdge(t.id,{sourceRoundNumber:r||void 0})}}):l.push({control:`sourceRoundNumber`,onChange:({inputs:n})=>{let r=Number.parseInt(n.sourceRoundNumber.value)||0,i=Math.max(0,Math.min(r,a));e.onUpdateEdge(t.id,{sourceRoundNumber:i||void 0})}}),l.push({control:`targetRoundNumber`,onChange:({inputs:n})=>{let r=Number.parseInt(n.targetRoundNumber.value)||0,i=Math.max(0,Math.min(r,o));e.onUpdateEdge(t.id,{targetRoundNumber:i||void 0})}})),{items:c,relationships:l}}function i(t,r,i){let a=r.structureOptions?.groupSize||4,o=new Set(t.finishingPositions||[]),s=i.edges.filter(e=>e.id!==t.id&&e.sourceNodeId===t.sourceNodeId&&e.linkType===BV),c=new Set;for(let e of s)for(let t of e.finishingPositions||[])c.add(t);let l=document.createElement(`div`);l.className=`field`,l.style.marginBottom=`10px`;let u=document.createElement(`label`);u.style.cssText=`font-size:11px;font-weight:600;color:var(--chc-text-secondary);margin-bottom:3px;display:block;`,u.textContent=`Finishing Positions`,l.appendChild(u);for(let r=1;r<=a;r++){let i=document.createElement(`label`);i.style.cssText=`display:flex;align-items:center;gap:4px;font-size:12px;padding:2px 0;cursor:pointer;`;let a=document.createElement(`input`);a.type=`checkbox`,a.checked=o.has(r);let s=c.has(r);n||s?a.disabled=!0:a.addEventListener(`change`,()=>{let n=new Set(o);a.checked?n.add(r):n.delete(r),e.onUpdateEdge(t.id,{finishingPositions:Array.from(n).sort((e,t)=>e-t)})});let u=document.createElement(`span`);u.textContent=`Position ${r}`,s&&(u.style.color=`var(--chc-text-muted, #999)`,u.title=`Used by another link`,i.style.opacity=`0.5`,i.style.cursor=`not-allowed`),i.appendChild(a),i.appendChild(u),l.appendChild(i)}return l}function a(a){t.innerHTML=``;let o=a.selectedEdgeId?a.edges.find(e=>e.id===a.selectedEdgeId):null;if(!o)return;let s=a.nodes.find(e=>e.id===o.sourceNodeId),c=a.nodes.find(e=>e.id===o.targetNodeId),l=document.createElement(`div`);l.className=`tb-editor-header`,l.textContent=`Link Properties`,t.appendChild(l);let u=document.createElement(`div`);u.className=`tb-editor-body`;let d=document.createElement(`div`);d.style.cssText=`font-size:11px;color:var(--chc-text-muted);margin-bottom:8px;`,d.textContent=`${s?.structureName||`Source`} → ${c?.structureName||`Target`}`,u.appendChild(d);let f=o.linkType===PV&&s?.stage===RV,p=s?sB(s.structureType,s.drawSize,s.structureOptions):8,m=c?sB(c.structureType,c.drawSize,c.structureOptions):8,h=o.linkType===BV&&s&&HV(s.structureType),g=[{label:`Link Type`,field:`linkType`,value:o.linkType,disabled:n,options:UV.map(e=>({...e,selected:e.value===o.linkType}))}],_=n?[]:[{control:`linkType`,onChange:({e:t})=>e.onUpdateEdge(o.id,{linkType:t.target.value})}];if(!h){let e=r(o,s,c,p,m,f);g.push(...e.items),_.push(...e.relationships)}if(f&&s){let t=Math.floor(s.drawSize/2),r=Math.floor(s.drawSize/4),i=o.qualifyingPositions||r;g.push({label:`Qualifying Positions`,field:`qualifyingPositions`,type:`number`,value:String(i),disabled:n}),n||_.push({control:`qualifyingPositions`,onChange:({inputs:n})=>{let r=Number.parseInt(n.qualifyingPositions.value)||1,i=Math.max(1,Math.min(r,t));e.onUpdateEdge(o.id,{qualifyingPositions:i})}})}if(o.linkType===FV&&(g.push({label:`Feed Profile`,field:`feedProfile`,value:o.feedProfile||IV,disabled:n,options:WV.map(e=>({...e,selected:e.value===(o.feedProfile||IV)}))}),n||_.push({control:`feedProfile`,onChange:({e:t})=>e.onUpdateEdge(o.id,{feedProfile:t.target.value})})),o.linkType===BV&&!h&&(g.push({label:`Finishing Positions`,field:`finishingPositions`,value:(o.finishingPositions||[]).join(`, `),placeholder:`e.g., 1, 2`,disabled:n}),n||_.push({control:`finishingPositions`,onChange:({inputs:t})=>{let n=t.finishingPositions.value.split(`,`).map(e=>Number.parseInt(e.trim())).filter(e=>!Number.isNaN(e));e.onUpdateEdge(o.id,{finishingPositions:n})}})),Oi(u,g,_),h&&s&&u.appendChild(i(o,s,a)),!n){let t=document.createElement(`button`);t.className=`sp-btn sp-btn--danger sp-btn--full`,t.style.marginTop=`12px`,t.textContent=`Delete Link`,t.onclick=()=>e.onDeleteEdge(o.id),u.appendChild(t)}t.appendChild(u)}return{element:t,update:a}}var{MAIN:KV,QUALIFYING:qV,CONSOLATION:JV,WINNER:YV,LOSER:XV,SINGLE_ELIMINATION:ZV,ROUND_ROBIN:QV,AD_HOC:$V}=t.drawDefinitionConstants,eH=`POSITION`;function tH(e){let t=[],n=nH(e,t);return iH(e,rH(e),t),aH(e,t),oH(e,t),sH(e,t),cH(e,n,t),lH(e,t),uH(e,t),fH(e,t),pH(e,t),mH(e)&&t.push({severity:`error`,message:`Circular dependency detected between structures`}),t}function nH(e,t){let n=e.nodes.filter(e=>e.stage===KV);return n.length===0?t.push({severity:`error`,message:`A main draw structure is required`}):n.length>1&&t.push({severity:`error`,message:`Only one main draw structure is allowed`}),n}function rH(e){let t=new Set;for(let n of e.edges)n.linkType===YV&&(n.targetRoundNumber||1)>1&&e.nodes.find(e=>e.id===n.sourceNodeId)?.stage===qV&&t.add(n.targetNodeId);let n=new Map;for(let t of e.edges)t.linkType===XV&&n.set(t.targetNodeId,(n.get(t.targetNodeId)||0)+1);for(let[e,r]of n)r>1&&t.add(e);return t}function iH(e,t,n){for(let r of e.nodes){if(r.structureType===ZV&&!t.has(r.id)){let t=e.edges.some(e=>e.targetNodeId===r.id);(r.stage===KV||r.stage===qV)&&!t&&(r.drawSize>0&&!(r.drawSize&r.drawSize-1)||n.push({severity:`error`,message:`"${r.structureName}" draw size must be a power of 2`,nodeId:r.id}))}let i=r.structureType===$V?0:2;r.drawSize<i&&n.push({message:`"${r.structureName}" draw size must be at least ${i}`,severity:`error`,nodeId:r.id})}}function aH(e,t){for(let n of e.edges){let r=e.nodes.find(e=>e.id===n.sourceNodeId),i=e.nodes.find(e=>e.id===n.targetNodeId);if(r||t.push({severity:`error`,message:`Edge references missing source node`,edgeId:n.id}),i||t.push({severity:`error`,message:`Edge references missing target node`,edgeId:n.id}),r&&n.sourceRoundNumber){let e=sB(r.structureType,r.drawSize,r.structureOptions);(n.sourceRoundNumber>e||n.sourceRoundNumber<1)&&t.push({severity:`warning`,message:`Edge source round ${n.sourceRoundNumber} is outside "${r.structureName}" range (1-${e})`,edgeId:n.id})}if(i&&n.targetRoundNumber){let e=sB(i.structureType,i.drawSize,i.structureOptions);(n.targetRoundNumber>e||n.targetRoundNumber<1)&&t.push({severity:`warning`,message:`Edge target round ${n.targetRoundNumber} is outside "${i.structureName}" range (1-${e})`,edgeId:n.id})}}}function oH(e,t){let n=new Map;for(let t of e.edges)t.linkType===YV&&(n.has(t.sourceNodeId)||n.set(t.sourceNodeId,[]),n.get(t.sourceNodeId).push(t.id));for(let[r,i]of n)if(i.length>1){let n=e.nodes.find(e=>e.id===r)?.structureName||`Unknown`;for(let e of i)t.push({severity:`error`,message:`"${n}" has multiple winner links (only one allowed)`,edgeId:e})}}function sH(e,t){let n=new Map;for(let t of e.edges)t.sourceRoundNumber&&(n.has(t.sourceNodeId)||n.set(t.sourceNodeId,[]),n.get(t.sourceNodeId).push({round:t.sourceRoundNumber,edgeId:t.id}));for(let[r,i]of n){let n=new Map,a=e.nodes.find(e=>e.id===r)?.structureName||`Unknown`;for(let{round:e,edgeId:r}of i)n.has(e)?t.push({severity:`error`,message:`"${a}" has multiple links from round ${e}`,edgeId:r}):n.set(e,r)}}function cH(e,t,n){let r=e.nodes.filter(e=>e.stage===qV);for(let i of r){let r=e.edges.find(e=>e.sourceNodeId===i.id&&e.linkType===YV&&t.some(t=>t.id===e.targetNodeId));if(r||n.push({severity:`warning`,message:`Qualifying structure "${i.structureName}" has no winner link to a main structure`,nodeId:i.id}),r?.qualifyingPositions){let e=Math.floor(i.drawSize/2);r.qualifyingPositions>e&&n.push({severity:`warning`,message:`Qualifying positions (${r.qualifyingPositions}) exceeds half of "${i.structureName}" draw size (${e})`,edgeId:r.id})}}}function lH(e,t){let n=new Map;for(let t of e.edges){if(t.linkType!==YV)continue;let r=t.targetRoundNumber||1;if(r<=1)continue;let i=e.nodes.find(e=>e.id===t.sourceNodeId);if(!i||i.stage!==qV)continue;n.has(t.targetNodeId)||n.set(t.targetNodeId,[]);let a=i.qualifyingPositions||Math.floor(i.drawSize/4);n.get(t.targetNodeId).push({edgeId:t.id,targetRound:r,qp:a,sourceName:i.structureName})}for(let[r,i]of n){let n=e.nodes.find(e=>e.id===r);if(!n)continue;let a=nB(n.drawSize),o=new Map;for(let e of i)o.set(e.targetRound,(o.get(e.targetRound)||0)+e.qp);for(let{edgeId:e,targetRound:s,sourceName:c}of i)(a.get(s)||0)<(o.get(s)||0)&&t.push({severity:`warning`,message:`"${n.structureName}" round ${s} is not a feed round or has insufficient capacity for ${c} link`,nodeId:r,edgeId:e})}}function uH(e,t){for(let n of e.edges){if(n.linkType!==XV)continue;let r=e.nodes.find(e=>e.id===n.sourceNodeId),i=e.nodes.find(e=>e.id===n.targetNodeId);if(!r||!i)continue;let a=n.sourceRoundNumber||1,o=n.targetRoundNumber||1,s=cB(r.structureType,r.drawSize,a),c=nB(i.drawSize);o!==1&&dH(c,o,s,r,i,a,n.id,t)}}function dH(e,t,n,r,i,a,o,s){let c=e.get(t);c===void 0?s.push({severity:`error`,message:`"${i.structureName}" R${t} is not a feed round — cannot receive ${n} losers from "${r.structureName}" R${a}`,edgeId:o}):n>c?s.push({severity:`error`,message:`"${r.structureName}" R${a} produces ${n} losers but "${i.structureName}" R${t} only has ${c} feed positions`,edgeId:o}):n<c&&s.push({severity:`warning`,message:`"${r.structureName}" R${a} produces ${n} losers but "${i.structureName}" R${t} has ${c} feed positions — ${c-n} will be empty`,edgeId:o})}function fH(e,t){let n=e.nodes.filter(e=>e.stage===JV);for(let r of n){let n=e.edges.filter(e=>e.targetNodeId===r.id);if(n.length===0)continue;let i=0;for(let t of n){let n=e.nodes.find(e=>e.id===t.sourceNodeId);if(n){if(t.linkType===XV){let e=t.sourceRoundNumber||1;i+=cB(n.structureType,n.drawSize,e)}else i+=n.qualifyingPositions||Math.floor(n.drawSize/2)}}i>0&&r.drawSize>i&&t.push({severity:`warning`,message:`"${r.structureName}" draw size (${r.drawSize}) exceeds inbound capacity (${i})`,nodeId:r.id}),i>0&&i>r.drawSize&&t.push({severity:`error`,message:`"${r.structureName}" receives ${i} participants but only has ${r.drawSize} positions`,nodeId:r.id})}}function pH(e,t){let n=new Map;for(let r of e.edges){if(r.linkType!==eH)continue;n.has(r.sourceNodeId)||n.set(r.sourceNodeId,[]),n.get(r.sourceNodeId).push({edgeId:r.id,positions:r.finishingPositions||[]});let i=e.nodes.find(e=>e.id===r.sourceNodeId);if(i&&i.structureType===QV){let e=i.structureOptions?.groupSize||4;for(let n of r.finishingPositions||[])(n<1||n>e)&&t.push({severity:`error`,message:`Position ${n} is outside valid range (1-${e}) for "${i.structureName}"`,edgeId:r.id})}}for(let[r,i]of n){if(i.length<2)continue;let n=e.nodes.find(e=>e.id===r)?.structureName||`Unknown`,a=new Map;for(let{edgeId:e,positions:r}of i)for(let i of r)a.has(i)?t.push({severity:`warning`,message:`Position ${i} from "${n}" is used by multiple POSITION links`,edgeId:e}):a.set(i,e)}}function mH(e){let t=new Map;for(let n of e.nodes)t.set(n.id,[]);for(let n of e.edges){let e=t.get(n.sourceNodeId);e&&e.push(n.targetNodeId)}let n=new Set,r=new Set;function i(e){if(r.has(e))return!0;if(n.has(e))return!1;n.add(e),r.add(e);for(let n of t.get(e)||[])if(i(n))return!0;return r.delete(e),!1}for(let t of e.nodes)if(i(t.id))return!0;return!1}var{MAIN:hH,QUALIFYING:gH,CONSOLATION:_H,PLAY_OFF:vH,LUCKY_DRAW:yH}=t.drawDefinitionConstants;function bH(e,t,n={}){let r=document.createElement(`div`);r.className=`tb-toolbar-wrapper`;let i=document.createElement(`div`);i.className=`tb-toolbar-row`;let a=document.createElement(`div`);a.style.flex=`1`,a.style.minWidth=`0`,i.appendChild(a),r.appendChild(i);let o=document.createElement(`div`);o.className=`tb-validation`,o.style.display=`none`,r.appendChild(o);let s=null,c=()=>{if(!s)return;let e=tH(s);if(o.innerHTML=``,e.length===0){o.style.display=`block`;let e=document.createElement(`div`);e.className=`tb-validation-item`,e.innerHTML=`<span style="color:var(--chc-status-success)">&#10003; Valid topology</span>`,o.appendChild(e)}else{o.style.display=`block`;for(let t of e){let e=document.createElement(`div`);e.className=`tb-validation-item`;let n=document.createElement(`span`);n.className=`tb-validation-icon tb-validation-icon--${t.severity}`,n.textContent=t.severity===`error`?`!`:`?`;let r=document.createElement(`span`);r.textContent=t.message,e.appendChild(n),e.appendChild(r),o.appendChild(e)}}setTimeout(()=>{o.style.display=`none`},5e3)},l=[];if(!n.readOnly){let t=[{label:`Main`,value:hH,onClick:()=>e.onAddStructure(hH),close:!0},{label:`Lucky Draw`,value:yH,onClick:()=>e.onAddStructure(hH,yH),close:!0},{label:`Qualifying`,value:gH,onClick:()=>e.onAddStructure(gH),close:!0},{label:`Consolation`,value:_H,onClick:()=>e.onAddStructure(_H),close:!0},{label:`Playoff`,value:vH,onClick:()=>e.onAddStructure(vH),close:!0}];l.push({label:`Add Structure`,location:`right`,options:t})}if(!n.hideTemplates&&t.length>0){let n=t.map(n=>({label:n.name,value:n.name,onClick:()=>{let r=t.find(e=>e.name===n.name);r&&e.onLoadTemplate(r)},close:!0}));l.push({label:`Templates`,location:`right`,options:n})}!n.readOnly&&e.onClear&&l.push({label:`Clear`,location:`right`,onClick:()=>e.onClear()}),n.readOnly||l.push({label:`Auto Layout`,location:`right`,onClick:()=>e.onAutoLayout()},{label:`Validate`,location:`right`,onClick:()=>c()}),!n.readOnly&&e.onSaveTemplate&&l.push({label:`Save Template`,location:`right`,intent:`is-success`,onClick:()=>e.onSaveTemplate()}),!n.readOnly&&!n.hideGenerate&&l.push({label:`Generate Draw`,location:`right`,intent:`is-success`,onClick:()=>e.onGenerate()}),yP({target:a,items:l});function u(e){s=e}return{element:r,update:u}}function xH({toolbar:e,canvas:t,nodeEditor:n,edgeEditor:r}){let i=document.createElement(`div`);i.className=`tb-layout`,i.appendChild(e.element);let a=document.createElement(`div`);a.className=`tb-body`,a.appendChild(t.element);let o=document.createElement(`div`);o.className=`tb-editor`,o.appendChild(n.element),o.appendChild(r.element),a.appendChild(o),i.appendChild(a);function s(i){if(e.update(i),t.update(i),n.element.style.display=i.selectedNodeId?``:`none`,r.element.style.display=i.selectedEdgeId?``:`none`,!i.selectedNodeId&&!i.selectedEdgeId){if(!o.querySelector(`.tb-editor-empty`)){let e=document.createElement(`div`);e.className=`tb-editor-empty`,e.textContent=`Select a structure or link to view properties`,o.appendChild(e)}}else{let e=o.querySelector(`.tb-editor-empty`);e&&e.remove()}n.update(i),r.update(i)}function c(){e.destroy?.(),t.destroy?.(),n.destroy?.(),r.destroy?.()}return{element:i,update:s,destroy:c}}var{SINGLE_ELIMINATION:SH,FEED_IN:CH,ROUND_ROBIN:wH,LUCKY_DRAW:TH,MAIN:EH,QUALIFYING:DH,CONSOLATION:OH,PLAY_OFF:kH}=t.drawDefinitionConstants,AH=`WINNER`,jH=`LOSER`,MH=`POSITION`,NH=`tpl-edge-1`,PH=`tpl-edge-2`,FH=`tpl-edge-3`,IH=`tpl-edge-4`,LH=`tpl-edge-5`,RH=`tpl-edge-6`,zH=`tpl-edge-7`,BH=`R1 losers → R1`,VH=[{name:`Single Elimination + Qualifying`,description:`Standard SE main draw with one qualifying structure`,state:{drawName:`SE + Qualifying`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:EH,structureType:SH,drawSize:32,position:{x:320,y:40}},{id:`tpl-qual`,structureName:`Qualifying`,stage:DH,structureType:SH,drawSize:16,qualifyingPositions:4,position:{x:40,y:40}}],edges:[{id:NH,sourceNodeId:`tpl-qual`,targetNodeId:`tpl-main`,linkType:AH,targetRoundNumber:1,qualifyingPositions:4,label:`winners → R1 (4Q)`}]}},{name:`FMLC (First Match Loser Consolation)`,description:`Main draw with first match loser consolation`,state:{drawName:`FMLC`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:EH,structureType:SH,drawSize:32,position:{x:40,y:40}},{id:`tpl-cons`,structureName:`Consolation`,stage:OH,structureType:SH,drawSize:16,position:{x:320,y:40}}],edges:[{id:NH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH}]}},{name:`Feed-In Championship (FIC)`,description:`Main draw with multi-round fed consolation`,state:{drawName:`FIC`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:EH,structureType:SH,drawSize:32,position:{x:40,y:40}},{id:`tpl-cons`,structureName:`Consolation`,stage:OH,structureType:CH,drawSize:31,position:{x:460,y:40}}],edges:[{id:NH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH},{id:PH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:jH,sourceRoundNumber:2,targetRoundNumber:2,label:`R2 losers → R2`},{id:FH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:jH,sourceRoundNumber:3,targetRoundNumber:4,label:`R3 losers → R4`},{id:IH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:jH,sourceRoundNumber:4,targetRoundNumber:6,label:`R4 losers → R6`},{id:LH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:jH,sourceRoundNumber:5,targetRoundNumber:8,label:`R5 losers → R8`}]}},{name:`Compass`,description:`8-draw compass structure`,state:{drawName:`Compass`,nodes:[{id:`tpl-east`,structureName:`East`,stage:EH,structureType:SH,drawSize:32,position:{x:40,y:40}},{id:`tpl-west`,structureName:`West`,stage:OH,structureType:SH,drawSize:16,position:{x:400,y:40}},{id:`tpl-north`,structureName:`North`,stage:OH,structureType:SH,drawSize:8,position:{x:400,y:210}},{id:`tpl-ne`,structureName:`Northeast`,stage:OH,structureType:SH,drawSize:4,position:{x:400,y:380}},{id:`tpl-south`,structureName:`South`,stage:OH,structureType:SH,drawSize:8,position:{x:680,y:40}},{id:`tpl-sw`,structureName:`Southwest`,stage:OH,structureType:SH,drawSize:4,position:{x:680,y:210}},{id:`tpl-nw`,structureName:`Northwest`,stage:OH,structureType:SH,drawSize:4,position:{x:680,y:380}},{id:`tpl-se`,structureName:`Southeast`,stage:OH,structureType:SH,drawSize:4,position:{x:960,y:40}}],edges:[{id:NH,sourceNodeId:`tpl-east`,targetNodeId:`tpl-west`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH},{id:PH,sourceNodeId:`tpl-east`,targetNodeId:`tpl-north`,linkType:jH,sourceRoundNumber:2,targetRoundNumber:1,label:`R2 losers → R1`},{id:FH,sourceNodeId:`tpl-east`,targetNodeId:`tpl-ne`,linkType:jH,sourceRoundNumber:3,targetRoundNumber:1,label:`R3 losers → R1`},{id:IH,sourceNodeId:`tpl-west`,targetNodeId:`tpl-south`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH},{id:LH,sourceNodeId:`tpl-west`,targetNodeId:`tpl-sw`,linkType:jH,sourceRoundNumber:2,targetRoundNumber:1,label:`R2 losers → R1`},{id:RH,sourceNodeId:`tpl-north`,targetNodeId:`tpl-nw`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH},{id:zH,sourceNodeId:`tpl-south`,targetNodeId:`tpl-se`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH}]}},{name:`Round Robin + Playoff`,description:`Round robin groups with winners and consolation playoffs`,state:{drawName:`RR + Playoff`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:EH,structureType:wH,drawSize:16,structureOptions:{groupSize:4},position:{x:40,y:40}},{id:`tpl-playoff-gold`,structureName:`Gold Flight`,stage:kH,structureType:SH,drawSize:8,position:{x:320,y:40}},{id:`tpl-playoff-silver`,structureName:`Silver Flight`,stage:kH,structureType:SH,drawSize:8,position:{x:320,y:220}}],edges:[{id:NH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-playoff-gold`,linkType:MH,finishingPositions:[1,2],label:`positions 1,2`},{id:PH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-playoff-silver`,linkType:MH,finishingPositions:[3,4],label:`positions 3,4`}]}},{name:`Lucky Draw + Consolation`,description:`Lucky draw main with consolation receiving R1 losers`,state:{drawName:`Lucky + Consolation`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:EH,structureType:TH,drawSize:11,position:{x:40,y:40}},{id:`tpl-cons`,structureName:`Consolation`,stage:OH,structureType:SH,drawSize:4,position:{x:340,y:40}}],edges:[{id:NH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH}]}},{name:`Lucky Draw → Round Robin`,description:`Lucky draw main with R1 losers feeding into round robin consolation`,state:{drawName:`Lucky → RR`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:EH,structureType:TH,drawSize:25,position:{x:40,y:40}},{id:`tpl-cons-rr`,structureName:`Consolation RR`,stage:OH,structureType:wH,drawSize:12,structureOptions:{groupSize:4},position:{x:500,y:40}}],edges:[{id:NH,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons-rr`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:BH}]}},{name:`Adaptive (drawSize 11)`,description:`Compass-like multi-structure topology with lucky draw structures`,state:{drawName:`Adaptive`,nodes:[{id:`tpl-east`,structureName:`East`,stage:EH,structureType:TH,drawSize:11,position:{x:40,y:40}},{id:`tpl-west`,structureName:`West`,stage:OH,structureType:TH,drawSize:6,position:{x:340,y:40}},{id:`tpl-north`,structureName:`North`,stage:OH,structureType:SH,drawSize:2,position:{x:340,y:250}},{id:`tpl-south`,structureName:`South`,stage:OH,structureType:SH,drawSize:2,position:{x:600,y:40}}],edges:[{id:NH,sourceNodeId:`tpl-east`,targetNodeId:`tpl-west`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:`R1 losers → R1 (6 losers)`},{id:PH,sourceNodeId:`tpl-east`,targetNodeId:`tpl-north`,linkType:jH,sourceRoundNumber:2,targetRoundNumber:1,label:`R2 losers → R1 (2 losers)`},{id:FH,sourceNodeId:`tpl-west`,targetNodeId:`tpl-south`,linkType:jH,sourceRoundNumber:1,targetRoundNumber:1,label:`R1 losers → R1 (2 losers)`}]}}],{MAIN:HH,QUALIFYING:UH,CONSOLATION:WH,PLAY_OFF:GH,SINGLE_ELIMINATION:KH,LUCKY_DRAW:qH,WINNER:JH,LOSER:YH}=t.drawDefinitionConstants,XH=`POSITION`,ZH=class{constructor(e={}){this.config=e,this.store=new XB(e.initialState);let t=[...VH,...e.templates||[]],n=!!e.readOnly,r=this.buildToolbarPanel(t,n),i=this.buildCanvasPanel(n),a=NV({onUpdateNode:n?()=>{}:(e,t)=>this.store.updateNode(e,t),onUpdateEdge:n?()=>{}:(e,t)=>this.store.updateEdge(e,t),onDeleteNode:n?()=>{}:e=>this.store.removeNode(e),readOnly:n,hideDelete:e.hideDelete}),o=GV({onUpdateEdge:n?()=>{}:(e,t)=>this.store.updateEdge(e,t),onDeleteEdge:n?()=>{}:e=>this.store.removeEdge(e),readOnly:n});this.layout=xH({toolbar:r,canvas:i,nodeEditor:a,edgeEditor:o}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}buildToolbarPanel(e,t){return bH({onAddStructure:(e,t)=>this.addDefaultStructure(e,t),onLoadTemplate:e=>{this.store.loadState({...e.state,selectedNodeId:null,selectedEdgeId:null,templateName:e.name})},onAutoLayout:()=>{this.store.autoLayout();let e=this.store.getState();this.store.loadState(e)},onGenerate:()=>this.handleGenerate(),onSaveTemplate:this.config.onSaveTemplate?()=>this.config.onSaveTemplate(this.store.getState()):void 0,onClear:this.config.onClear},e,{hideTemplates:this.config.hideTemplates,hideGenerate:this.config.hideGenerate,readOnly:t})}buildCanvasPanel(e){return sV({onSelectNode:e=>this.store.selectNode(e),onSelectEdge:e=>this.store.selectEdge(e),onDoubleClickNode:this.config.onDoubleClickNode?e=>{let t=this.store.getState(),n=t.nodes.find(t=>t.id===e);n&&this.config.onDoubleClickNode(n,t)}:void 0,onMoveNode:(e,t,n)=>this.store.updateNode(e,{position:{x:t,y:n}}),onCreateEdge:e?()=>{}:(e,t,n)=>{this.handleCreateEdge(e,t,n)},onPortMouseDown:()=>{}})}handleCreateEdge(e,t,n){let r=this.store.getState().nodes.find(t=>t.id===e);if(n===XH){let i=this.store.getState().edges.filter(t=>t.sourceNodeId===e&&t.linkType===XH),a=new Set(i.flatMap(e=>e.finishingPositions||[])),o=r?.structureOptions?.groupSize||4,s=1;for(let e=1;e<=o;e++)if(!a.has(e)){s=e;break}this.store.addEdge({sourceNodeId:e,targetNodeId:t,linkType:n,finishingPositions:[s]})}else if(n===YH){let i=this.store.getState().edges.filter(t=>t.sourceNodeId===e&&t.linkType===YH),a=new Set(i.map(e=>e.sourceRoundNumber)),o=r?sB(r.structureType,r.drawSize,r.structureOptions):1,s=1;for(let e=1;e<=o;e++)if(!a.has(e)){s=e;break}this.store.addEdge({sourceNodeId:e,targetNodeId:t,linkType:n,sourceRoundNumber:s})}else{let i=n===JH&&r?.stage===UH;this.store.addEdge({sourceNodeId:e,targetNodeId:t,linkType:n,...i&&{targetRoundNumber:1}})}}render(e){e.appendChild(this.layout.element)}destroy(){this.unsubscribe(),this.layout.destroy?.(),this.layout.element.remove()}autoLayout(){this.store.autoLayout();let e=this.store.getState();this.store.loadState(e)}getState(){return this.store.getState()}loadState(e){this.store.loadState(e)}addDefaultStructure(e,t){let n=t===qH,r=this.store.getState().nodes.filter(t=>t.stage===e).length,i={[HH]:n?`Lucky Draw`:`Main Draw`,[UH]:`Qualifying ${r+1}`,[WH]:`Consolation`,[GH]:`Playoff ${r+1}`},a={[HH]:n?11:32,[UH]:16,[WH]:16,[GH]:4}[e]||16,o=this.store.addNode({structureName:i[e]||e,stage:e,structureType:t||KH,drawSize:a,...e===UH&&{qualifyingPositions:Math.floor(a/4)}});this.scrollCanvasToNode(o)}scrollCanvasToNode(e){let t=this.layout.element.querySelector(`.tb-canvas`);t&&requestAnimationFrame(()=>{let n=e.position.x+FB(e)+40;n>t.scrollLeft+t.clientWidth&&t.scrollTo({left:n-t.clientWidth,behavior:`smooth`})})}handleGenerate(){let e=this.store.getState(),t=tH(e);t.some(e=>e.severity===`error`)&&console.warn(`Topology validation errors:`,t),this.config.onGenerate&&this.config.onGenerate(e)}},{MAIN:QH,CONSOLATION:$H,QUALIFYING:eU,PLAY_OFF:tU,SINGLE_ELIMINATION:nU,FEED_IN:rU,FIRST_MATCH_LOSER_CONSOLATION:iU,FEED_IN_CHAMPIONSHIP:aU,COMPASS:oU,WINNER:sU,LOSER:cU,ROUND_ROBIN:lU,AD_HOC:uU,LUCKY_DRAW:dU}=t.drawDefinitionConstants,fU=`POSITION`;function pU(e,t){let n=e.nodes.filter(e=>e.stage===$H),r=e.nodes.filter(e=>e.stage===eU),i=e.nodes.filter(e=>e.stage===tU);if(t.structureType===lU)return e.edges.some(n=>n.sourceNodeId===t.id&&n.linkType===fU&&e.nodes.some(e=>e.id===n.targetNodeId&&e.stage===tU))?`ROUND_ROBIN_WITH_PLAYOFF`:lU;if(t.structureType===uU)return uU;if(t.structureType===rU)return rU;if(t.structureType===dU)return dU;if(n.length===7&&r.length===0&&i.length===0){let n=e.edges.filter(e=>e.linkType===cU&&e.sourceNodeId===t.id),r=new Set(n.map(e=>e.sourceRoundNumber));if(r.has(1)&&r.has(2)&&r.has(3))return oU}if(n.length===1&&r.length===0&&i.length===0){let r=n[0],i=e.edges.filter(e=>e.linkType===cU&&e.sourceNodeId===t.id&&e.targetNodeId===r.id);if(r.structureType===rU||i.length>1)return aU;if(i.length===1&&i[0].sourceRoundNumber===1)return iU}return nU}function mU(e){let t=e.nodes.find(e=>e.stage===QH);if(!t)throw Error(`No main structure node found`);let n=e.nodes.filter(e=>e.stage===eU),r=e.nodes.filter(e=>e.stage===tU),i=pU(e,t);i===nU&&!yU(t.drawSize)&&(i=rU);let a={drawName:e.drawName,drawType:i,drawSize:t.drawSize,matchUpFormat:t.matchUpFormat||void 0,structureOptions:t.structureOptions||void 0,automated:!0};n.length>0&&_U(a,n,e.edges);let o=[];return hU(e,t,i,o),gU(e,t,r,a),{drawOptions:a,postGenerationMethods:o}}function hU(e,t,n,r){let i=e.nodes.filter(e=>e.stage===$H),a=e.edges.filter(e=>e.linkType===cU&&e.sourceNodeId===t.id&&i.some(t=>t.id===e.targetNodeId)),o=[iU,aU,oU];if(a.length===0||o.includes(n))return;let s=new Map;for(let e of a)s.has(e.targetNodeId)||s.set(e.targetNodeId,[]),s.get(e.targetNodeId).push(e);for(let[e,t]of s){let n=i.find(t=>t.id===e);if(!n)continue;let a=t.map(e=>({sourceRoundNumber:e.sourceRoundNumber||1,targetRoundNumber:e.targetRoundNumber||1}));r.push({method:`attachConsolationStructures`,params:{structureName:n.structureName,structureType:n.structureType,drawSize:n.drawSize,matchUpFormat:n.matchUpFormat||void 0,structureOptions:n.structureOptions||void 0,links:a}})}}function gU(e,t,n,r){let i=t.structureType===lU,a=i?e.edges.filter(e=>e.sourceNodeId===t.id&&e.linkType===fU&&n.some(t=>t.id===e.targetNodeId)):[];if(i&&a.length>0){let e=new Map;for(let t of a)e.has(t.targetNodeId)||e.set(t.targetNodeId,[]),e.get(t.targetNodeId).push(t);let t=[];for(let[r,i]of e){let e=n.find(e=>e.id===r);if(!e)continue;let a=Array.from(new Set(i.flatMap(e=>e.finishingPositions||[]))).sort((e,t)=>e-t),o=e.structureOptions?.playoffDrawType||nU,s={finishingPositions:a,structureName:e.structureName,drawType:o};o===lU&&e.structureOptions?.groupSize&&(s.structureOptions={groupSize:e.structureOptions.groupSize}),t.push(s)}t.length>0&&(r.structureOptions={...r.structureOptions,playoffGroups:t})}else if(n.length>0){let i=vU(t.id,n,e.edges);i&&(r.withPlayoffs=i)}}function _U(e,t,n){let r=n.filter(e=>e.linkType===sU&&t.some(t=>t.id===e.sourceNodeId)),i={};for(let e of t){let t=r.find(t=>t.sourceNodeId===e.id),n=t?.targetRoundNumber||1;i[n]||(i[n]=[]),i[n].push({node:e,edge:t})}let a=0;e.qualifyingProfiles=Object.entries(i).map(([e,t])=>{let n=t.map(({node:e,edge:t})=>{let n=e.qualifyingPositions||t?.qualifyingPositions||Math.floor(e.drawSize/4);return a+=n,{structureName:e.structureName,drawType:e.structureType,drawSize:e.drawSize,qualifyingPositions:n,seedsCount:0}});return{roundTarget:Number(e),structureProfiles:n}}),e.qualifiersCount=a,e.qualifyingPlaceholder=!0}function vU(e,t,n){let r=n.filter(n=>n.sourceNodeId===e&&n.linkType===cU&&t.some(e=>e.id===n.targetNodeId));if(!r.length)return;let i=[],a={},o={};for(let e of r){if(!e.sourceRoundNumber)continue;let r=t.find(t=>t.id===e.targetNodeId);if(!r)continue;i.push({[e.sourceRoundNumber]:1});let s=`0-${i.length}`;a[s]={name:r.structureName,abbreviation:r.structureName.substring(0,3)};let c=vU(r.id,t,n);c&&(o[e.sourceRoundNumber]=c)}if(i.length)return{roundProfiles:i,...Object.keys(a).length>0&&{playoffAttributes:a},...Object.keys(o).length>0&&{roundPlayoffs:o}}}function yU(e){return e>0&&!(e&e-1)}var{MAIN:bU}=t.drawDefinitionConstants,xU=()=>`spl-layout`,SU=()=>`spl-left`,CU=()=>`spl-toggle`,wU=()=>`spl-center`,TU=()=>`spl-center-header`,EU=()=>`spl-center-title`,DU=()=>`spl-center-actions`,OU=()=>`spl-center-leading`,kU=()=>`spl-grid-slot`,AU=()=>`spl-right`,jU=()=>`spl-matchup-card`,MU=()=>`spl-card-title`,NU=()=>`spl-card-sides`,PU=()=>`spl-card-meta`,FU=()=>`spl-card-chips`,IU=()=>`spl-card-chip`,LU=()=>`sp-panel`,RU=()=>`sp-panel-header`,zU=()=>`sp-panel-title`,BU=()=>`sp-panel-meta`,VU=()=>`sp-date-strip`,HU=()=>`sp-date-chip`,UU=()=>`sp-badges`,WU=()=>`sp-catalog`,GU=()=>`sp-catalog-toolbar`,KU=()=>`sp-input`,qU=()=>`sp-select`,JU=()=>`sp-group`,YU=()=>`sp-group-header`,XU=()=>`sp-group-body`,ZU=()=>`sp-group-chevron`,QU=()=>`sp-issues`,$U=()=>`sp-issue`,eW=()=>`sp-issue-code`,tW=()=>`sp-issue-msg`,nW=()=>`sp-inspector`,rW=()=>`sp-kv`,iW=()=>`sp-kv-key`,aW=()=>`sp-kv-value`,oW=()=>`sp-small`;function sW(e,t,n){let r=!!n?.hideLeft,i=n?.catalogSide===`left`,a=document.createElement(`div`);a.className=xU();let o=null,s=null;if(r)i?a.classList.add(`spl-catalog-left`):a.classList.add(`spl-no-left`);else{o=document.createElement(`div`),o.className=SU(),s=document.createElement(`button`),s.className=CU(),s.textContent=`◀`,s.title=`Toggle sidebar`,s.addEventListener(`click`,()=>t.onToggleLeft()),o.appendChild(s);let n=document.createElement(`div`);n.className=`spl-left-content`,n.style.cssText=`display:flex;flex-direction:column;gap:12px;flex:1;min-height:0`,e.dateStrip.element.style.flex=`1`,e.dateStrip.element.style.minHeight=`0`,e.dateStrip.element.style.overflow=`auto`,n.appendChild(e.dateStrip.element),e.issuesPanel.element.style.flex=`1`,e.issuesPanel.element.style.minHeight=`0`,e.issuesPanel.element.style.overflow=`auto`,n.appendChild(e.issuesPanel.element),o.appendChild(n)}let c=e.courtGridSlot.element,l=document.createElement(`div`);l.className=AU(),e.matchUpCatalog.element.style.flex=`3`,e.matchUpCatalog.element.style.minHeight=`0`,e.matchUpCatalog.element.style.overflow=`auto`,l.appendChild(e.matchUpCatalog.element),e.inspectorPanel.element.style.flex=`1`,e.inspectorPanel.element.style.minHeight=`120px`,e.inspectorPanel.element.style.overflow=`auto`,l.appendChild(e.inspectorPanel.element),o&&a.appendChild(o),i&&r?(a.appendChild(l),a.appendChild(c)):(a.appendChild(c),a.appendChild(l));function u(t){r||(t.leftCollapsed?(a.classList.add(`spl-left-collapsed`),s&&(s.textContent=`▶`)):(a.classList.remove(`spl-left-collapsed`),s&&(s.textContent=`◀`)),e.dateStrip.update(t),e.issuesPanel.update(t)),e.courtGridSlot.update(t),e.matchUpCatalog.update(t),e.inspectorPanel.update(t)}return{element:a,update:u}}function cW(e){let t=e.sides;if(t?.length===2){let e=lW(t[0]),n=lW(t[1]);if(e&&n)return`${e} vs ${n}`;if(e)return`${e} vs TBD`;if(n)return`TBD vs ${n}`}return`TBD vs TBD`}function lW(e){return e?`${e.participantName??``}${e.seedNumber?` [${e.seedNumber}]`:``}`:``}function uW(e){let t=[e.eventName,e.drawName??``,e.roundName??``];if(e.sides)for(let n of e.sides)n.participantName&&t.push(n.participantName);return t.join(` `).toLowerCase()}function dW(){let e=document.createElement(`div`);e.className=LU();let t=document.createElement(`div`);t.className=RU();let n=document.createElement(`div`);n.className=zU(),n.textContent=`Inspector`,t.appendChild(n),e.appendChild(t);let r=document.createElement(`div`);r.className=nW(),e.appendChild(r);function i(e){r.innerHTML=``;let t=e.selectedMatchUp;if(!t){let e=document.createElement(`div`);e.className=oW(),e.textContent=`Select a matchUp in the catalog to see details.`,r.appendChild(e);return}if(fW(r,`Event`,t.eventName),fW(r,`Draw`,t.drawName??t.drawId),fW(r,`Round`,t.roundName??`Round ${t.roundNumber}`),fW(r,`Type`,t.matchUpType??`—`),fW(r,`Format`,t.matchUpFormat??`—`),fW(r,`Scheduled`,t.isScheduled?`Yes`:`No`),t.scheduledTime&&fW(r,`Time`,t.scheduledTime),t.scheduledCourtName&&fW(r,`Court`,t.scheduledCourtName),t.sides?.length){let e=document.createElement(`div`);e.className=oW(),e.style.marginTop=`8px`,e.textContent=`Participants:`,r.appendChild(e);let n=document.createElement(`div`);n.className=`spl-inspector-sides`;for(let e of t.sides){let t=document.createElement(`div`);t.className=`spl-inspector-side`;let r=document.createElement(`span`);if(r.textContent=lW(e)||`TBD`,t.appendChild(r),e.ranking){let n=document.createElement(`span`);n.className=`spl-inspector-seed`,n.textContent=`#${e.ranking}`,t.appendChild(n)}n.appendChild(t)}r.appendChild(n)}}return{element:e,update:i}}function fW(e,t,n){let r=document.createElement(`div`);r.className=rW();let i=document.createElement(`div`);i.className=iW(),i.textContent=t;let a=document.createElement(`div`);a.className=aW(),a.textContent=n,r.appendChild(i),r.appendChild(a),e.appendChild(r)}var pW=new Set([`COMPLETED`,`RETIRED`,`WALKOVER`,`DEFAULTED`,`DOUBLE_WALKOVER`,`DOUBLE_DEFAULT`,`CANCELLED`,`ABANDONED`,`DEAD_RUBBER`]);function mW(e){return!!e&&pW.has(e)}function hW(e,t,n=`dim`,r,i=!1){let a=t.toLowerCase().trim();return e.filter(e=>n===`hide`&&e.isScheduled||!i&&mW(e.matchUpStatus)||r&&(r.eventType&&e.matchUpType!==r.eventType||r.eventName&&e.eventName!==r.eventName||r.drawName&&(e.drawName??e.drawId)!==r.drawName||r.gender&&e.gender!==r.gender||r.roundName&&e.roundName!==r.roundName)?!1:!a||uW(e).includes(a))}function gW(e){let t=new Map;for(let n of e){if(n.isScheduled||mW(n.matchUpStatus))continue;let e=t.get(n.eventId);(e===void 0||n.roundNumber<e)&&t.set(n.eventId,n.roundNumber)}return t}var _W={CONSOLATION:`Consolation`,PLAYOFF:`Playoff`,QUALIFYING:`Qualifying`,ROUND_ROBIN:`Round Robin`,PLAY_OFF:`Playoff`,Q_PLAYOFF:`Qualifying Playoff`,COMPASS:`Compass`,VOLUNTARY_CONSOLATION:`Voluntary Consolation`},vW=`Unscheduled`;function yW(e){if(e.structureName&&e.structureName.trim())return e.structureName.trim();let t=e.stage;return!t||t===`MAIN`?``:_W[t]??t.charAt(0)+t.slice(1).toLowerCase().replace(/_/g,` `)}function bW(e){let t;for(let n of e){let e=n.scheduledTime;e&&(t===void 0||e.localeCompare(t)<0)&&(t=e)}return t}function xW(e){let t=(e.sides??[]).filter(e=>!!e.participantId).length;return t>2?2:t}function SW(e){let t=0;for(let n of e){let e=xW(n);if(e>t&&(t=e),t===2)break}return t}function CW(e){return e.map((e,t)=>({item:e,index:t,readiness:xW(e)})).sort((e,t)=>t.readiness-e.readiness||e.index-t.index).map(e=>e.item)}function wW(e,t){let n=new Map,r=e=>{if(t===`draw`)return`${e.eventName} \u2014 ${e.drawName??e.drawId}`;if(t===`round`)return e.roundName??`Round ${e.roundNumber}`;if(t===`structure`){let t=yW(e);return t?`${e.eventName} \u2014 ${t}`:e.eventName}return t===`time`?e.scheduledTime??vW:e.eventName};for(let t of e){let e=r(t),i=n.get(e);i?i.push(t):n.set(e,[t])}return new Map([...n.entries()].map(([e,t])=>[e,CW(t)]).sort((e,t)=>{let n=SW(e[1]),r=SW(t[1]);if(n!==r)return r-n;let i=bW(e[1]),a=bW(t[1]);return i!==void 0&&a!==void 0&&i!==a?i.localeCompare(a):i!==void 0&&a===void 0?-1:i===void 0&&a!==void 0?1:e[0].localeCompare(t[0],void 0,{numeric:!0})}))}function TW(e,t,n={}){let r=document.createElement(`div`);r.className=jU(),r.setAttribute(`data-matchup-id`,e.matchUpId);let i=mW(e.matchUpStatus);e.isScheduled?(r.classList.add(`scheduled`),r.draggable=!1):i?(r.classList.add(`completed`),r.draggable=!1):(r.draggable=!0,r.addEventListener(`dragstart`,t=>{t.stopPropagation(),t.dataTransfer.setDragImage(r,r.offsetWidth/2,20),t.dataTransfer.setData(`application/json`,JSON.stringify({type:`CATALOG_MATCHUP`,matchUp:e})),t.dataTransfer.effectAllowed=`copyMove`})),t.onClick&&r.addEventListener(`click`,n=>{n.stopPropagation(),t.onClick(e)});let a=document.createElement(`div`);if(a.className=MU(),typeof n.roundOffset==`number`){let e=n.roundOffset===0?`spl-card-title--round-current`:n.roundOffset===1?`spl-card-title--round-next`:`spl-card-title--round-later`;a.classList.add(e)}let o=`${e.eventName} \u2014 ${e.roundName??`Round `+e.roundNumber}`,s=n.prominentTime&&!!e.scheduledTime;if(s){a.classList.add(`with-time`);let t=document.createElement(`span`);t.className=`spl-card-title-text`,t.textContent=o;let n=document.createElement(`span`);n.className=`spl-card-time-header`,n.textContent=e.scheduledTime,a.appendChild(t),a.appendChild(n)}else a.textContent=o;r.appendChild(a);let c=document.createElement(`div`);c.className=NU(),c.textContent=cW(e),r.appendChild(c);let l=document.createElement(`div`);l.className=PU();let u=[];e.drawName&&u.push(e.drawName),e.matchUpType&&u.push(e.matchUpType.toLowerCase()),l.textContent=u.join(` · `),r.appendChild(l);let d=document.createElement(`div`);if(d.className=FU(),e.scheduledTime&&!s&&d.appendChild(EW(e.scheduledTime,`time`)),e.scheduledCourtName&&d.appendChild(EW(e.scheduledCourtName,`court`)),e.matchUpFormat&&d.appendChild(EW(e.matchUpFormat,`type`)),i&&e.matchUpStatus){let t=e.matchUpStatus.replace(/_/g,` `);d.appendChild(EW(t,`status`))}if(e.stage&&e.stage!==`MAIN`){let t=e.stage.replace(/_/g,` `);d.appendChild(EW(t,`stage`))}if(d.children.length&&r.appendChild(d),e.isScheduled){let e=document.createElement(`span`);e.className=`spl-matchup-check`,e.textContent=`✓`,r.appendChild(e)}return r}function EW(e,t){let n=document.createElement(`div`);return n.className=IU()+` `+t,n.textContent=e,n}function DW(e,t){let n=new Set;for(let r of e){let e=t(r);e&&n.add(e)}return[...n].sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))}function OW(e){let t=document.createElement(`div`);t.className=LU();let n=`spl-catalog-drop-over`,r=`is-filtering`,i=new Set,a=null,o,s={};t.addEventListener(`dragover`,e=>{e.preventDefault(),t.classList.add(n),e.dataTransfer.dropEffect=`move`}),t.addEventListener(`dragleave`,e=>{t.contains(e.relatedTarget)||t.classList.remove(n)}),t.addEventListener(`drop`,r=>{if(t.classList.remove(n),r.preventDefault(),!e.onDropRemove)return;let i;try{i=JSON.parse(r.dataTransfer.getData(`application/json`))}catch{return}(i.type===`CATALOG_MATCHUP`||i.type===`GRID_MATCHUP`)&&e.onDropRemove(i.matchUp.matchUpId)});let c=document.createElement(`div`);c.className=RU();let l=document.createElement(`div`);l.className=`spl-catalog-title-row`;let u=document.createElement(`div`);u.className=zU(),u.textContent=`MatchUp Catalog`;let d=document.createElement(`button`);d.className=`spl-catalog-filter-btn`,d.title=`Filter matchUps`,d.innerHTML=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/></svg>`,l.appendChild(u),l.appendChild(d);let f=document.createElement(`div`);f.className=BU(),c.appendChild(l),c.appendChild(f),t.appendChild(c);let p=document.createElement(`div`);p.className=GU();let m=document.createElement(`input`);m.type=`text`,m.placeholder=`Search matchUps...`,m.className=KU(),m.addEventListener(`input`,()=>e.onSearchChange(m.value));let h=eS(m,()=>{m.value=``,e.onSearchChange(``),m.focus()}),g=document.createElement(`select`);g.className=qU();for(let[e,t]of[[`event`,`By Event`],[`draw`,`By Draw`],[`round`,`By Round`],[`structure`,`By Structure`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,g.appendChild(n)}g.addEventListener(`change`,()=>e.onGroupByChange(g.value)),p.appendChild(h),p.appendChild(g),t.appendChild(p);function _(){o&&=(o.destroy(),void 0)}function v(){return!!(s.eventType||s.eventName||s.drawName||s.gender||s.roundName)}function y(){d.classList.toggle(`active`,v())}function b(){let t=a?.matchUpCatalog??[],n=document.createElement(`div`);n.className=`spl-filter-popover`;let i=document.createElement(`div`);i.className=`spl-filter-header`;let o=document.createElement(`button`);o.className=`spl-filter-clear-btn`,o.textContent=`Clear All`,o.addEventListener(`click`,t=>{t.stopPropagation(),s={},e.onFilterChange(s),y();for(let e of n.querySelectorAll(`select`)){e.value=``,e.classList.remove(r);let t=e.previousElementSibling;t?.classList.contains(`spl-filter-label`)&&t.classList.remove(r)}}),i.appendChild(o);let c=document.createElement(`button`);c.className=`spl-filter-close-btn`,c.textContent=`×`,c.addEventListener(`click`,e=>{e.stopPropagation(),_()}),i.appendChild(c),n.appendChild(i);let l=[{label:`All Event Types`,key:`eventType`,values:DW(t,e=>e.matchUpType)},{label:`All Events`,key:`eventName`,values:DW(t,e=>e.eventName)},{label:`All Flights`,key:`drawName`,values:DW(t,e=>e.drawName)},{label:`All Genders`,key:`gender`,values:DW(t,e=>e.gender)},{label:`All Rounds`,key:`roundName`,values:DW(t,e=>e.roundName)}];for(let t of l){if(t.values.length<2)continue;let i=document.createElement(`label`);i.className=`spl-filter-label`,i.textContent=t.label,n.appendChild(i);let a=document.createElement(`select`);a.className=`spl-filter-select`;let o=document.createElement(`option`);o.value=``,o.textContent=t.label,a.appendChild(o);for(let e of t.values){let t=document.createElement(`option`);t.value=e,t.textContent=e,a.appendChild(t)}a.value=s[t.key]??``;let c=()=>{let e=a.value!==``;a.classList.toggle(r,e),i.classList.toggle(r,e)};c(),a.addEventListener(`change`,()=>{s={...s,[t.key]:a.value||void 0},e.onFilterChange(s),y(),c()}),n.appendChild(a)}let u=document.createElement(`label`);u.className=`spl-filter-toggle`;let d=document.createElement(`input`);d.type=`checkbox`,d.checked=a?.showScheduled??!1,d.addEventListener(`change`,()=>{e.onShowScheduledChange?.(d.checked)}),u.appendChild(d),u.appendChild(document.createTextNode(` Show assigned`)),n.appendChild(u);let f=document.createElement(`label`);f.className=`spl-filter-toggle`;let p=document.createElement(`input`);return p.type=`checkbox`,p.checked=a?.showCompleted??!1,p.addEventListener(`change`,()=>{e.onShowCompletedChange(p.checked)}),f.appendChild(p),f.appendChild(document.createTextNode(` Show completed`)),n.appendChild(f),n}d.addEventListener(`click`,()=>{_(),o=km(d,{content:b(),placement:`bottom-start`,interactive:!0,trigger:`manual`,appendTo:()=>t,onClickOutside:()=>_(),theme:``}),o.show()});let x=document.createElement(`div`);x.className=WU(),t.appendChild(x);function S(t){a=t,s=t.catalogFilters??{},y();let n=gW(t.matchUpCatalog),r=t.showScheduled?t.scheduledBehavior:`hide`,o=hW(t.matchUpCatalog,t.catalogSearchQuery,r,t.catalogFilters,t.showCompleted),c=wW(o,t.catalogGroupBy),l=o.filter(e=>!e.isScheduled).length;f.textContent=`${l} unscheduled`,m.value!==t.catalogSearchQuery&&(m.value=t.catalogSearchQuery,tS(h)),g.value!==t.catalogGroupBy&&(g.value=t.catalogGroupBy),x.innerHTML=``;for(let[r,o]of c){let s=document.createElement(`div`);s.className=JU();let c=i.has(r),l=document.createElement(`div`);l.className=YU();let u=document.createElement(`span`);u.className=ZU(),u.textContent=c?`▶`:`▼`;let d=document.createElement(`span`);d.textContent=`${r} (${o.length})`,l.appendChild(u),l.appendChild(d),l.addEventListener(`click`,()=>{i.has(r)?i.delete(r):i.add(r),a&&S(a)});let f=document.createElement(`div`);f.className=XU(),c&&(f.style.display=`none`);for(let r of o){let i=n.get(r.eventId),a=TW(r,{onClick:t=>e.onMatchUpSelected?.(t)},{roundOffset:i!==void 0&&!r.isScheduled&&!mW(r.matchUpStatus)?Math.max(0,r.roundNumber-i):void 0});t.selectedMatchUp?.matchUpId===r.matchUpId&&a.classList.add(`selected`),f.appendChild(a)}s.appendChild(l),s.appendChild(f),x.appendChild(s)}}return{element:t,update:S}}function kW(e){let t={ERROR:[],WARN:[],INFO:[]},n={},r={total:e.length,ERROR:0,WARN:0,INFO:0},i={},a=e=>e===`ERROR`?0:e===`WARN`?1:2;for(let a of e)if(t[a.severity].push(a),r[a.severity]++,a.date){(n[a.date]??=[]).push(a);let e=i[a.date]??={total:0,ERROR:0,WARN:0,INFO:0};e.total++,e[a.severity]++}let o=(e,t)=>a(e.severity)-a(t.severity)||e.message.localeCompare(t.message),s=[...e].sort(o);for(let e of Object.keys(t))t[e].sort(o);for(let e of Object.keys(n))n[e].sort(o);return{all:s,bySeverity:t,byDate:n,counts:r,countsByDate:i}}var AW=`spl-cell--issue-pulse`;function jW(){let e=document.createElement(`div`);e.className=LU();let t=document.createElement(`div`);t.className=RU();let n=document.createElement(`div`);n.className=zU(),n.textContent=`Issues`;let r=document.createElement(`div`);r.className=BU(),t.appendChild(n),t.appendChild(r),e.appendChild(t);let i=document.createElement(`div`);i.className=QU(),e.appendChild(i);function a(e){let t=kW(e.issues);if(r.textContent=`${t.counts.total} total (${t.counts.ERROR} errors)`,i.innerHTML=``,!t.all.length){let e=document.createElement(`div`);e.className=oW(),e.textContent=`No scheduling conflicts.`,i.appendChild(e);return}for(let e of t.all.slice(0,30)){let t=document.createElement(`div`);t.className=$U(),e.severity===`ERROR`?t.classList.add(`error`):e.severity===`WARN`?t.classList.add(`warn`):t.classList.add(`info`);let n=document.createElement(`div`);n.className=eW(),n.textContent=e.severity;let r=document.createElement(`div`);if(r.className=tW(),e.participants){if(e.prefix){let t=document.createElement(`span`);t.textContent=e.prefix,t.style.opacity=`0.7`,r.appendChild(t)}let t=document.createElement(`span`);t.textContent=(e.issueType||``)+`: `,t.style.opacity=`0.7`,r.appendChild(t);let n=document.createElement(`span`);if(n.textContent=e.participants,n.style.color=`var(--spl-issue-participant1, #4fc3f7)`,n.style.fontWeight=`600`,r.appendChild(n),e.conflictParticipants?.length){let t=document.createElement(`span`);t.textContent=` conflicts with `,t.style.opacity=`0.7`,r.appendChild(t),e.conflictParticipants.forEach((e,t)=>{if(t>0){let e=document.createElement(`span`);e.textContent=`, `,e.style.opacity=`0.7`,r.appendChild(e)}let n=document.createElement(`span`);n.textContent=e,n.style.color=`var(--spl-issue-participant2, #ffb74d)`,n.style.fontWeight=`600`,r.appendChild(n)})}}else r.textContent=e.message;if(e.matchUpId){t.style.cursor=`pointer`;let n=e.matchUpId;t.addEventListener(`click`,()=>{console.log(`[issuesPanel] clicked issue row, matchUpId:`,n),o(n)})}else console.log(`[issuesPanel] issue has no matchUpId:`,e.message);t.appendChild(n),t.appendChild(r),i.appendChild(t)}}function o(e){let t=`.spl-grid-cell[data-matchup-id="${e}"]`,n=document.querySelector(t);console.log(`[issuesPanel] scrollToMatchUp selector:`,t,`found:`,!!n),n&&(n.scrollIntoView({behavior:`smooth`,block:`center`,inline:`center`}),n.classList.remove(AW),n.offsetWidth,n.classList.add(AW),n.addEventListener(`animationend`,()=>n.classList.remove(AW),{once:!0}))}return{element:e,update:a}}function MW(e){let t=document.createElement(`div`);t.className=LU();let n=document.createElement(`div`);n.className=RU();let r=document.createElement(`div`);r.className=zU(),r.textContent=`Dates`;let i=document.createElement(`div`);i.className=BU(),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=VU(),t.appendChild(a);function o(t){let n=t.scheduleDates;i.textContent=`${n.length} dates`,a.innerHTML=``;for(let r of n){let n=document.createElement(`div`);n.className=HU(),r.date===t.selectedDate&&n.classList.add(`selected`),r.isActive||n.classList.add(`inactive`),n.setAttribute(`data-date`,r.date);let i=document.createElement(`div`),o=document.createElement(`div`);o.style.cssText=`font-weight:800;font-size:0.75rem`,o.textContent=r.date;let s=document.createElement(`div`);s.style.cssText=`font-size:0.6875rem;color:var(--sp-muted)`,s.textContent=r.isActive?`Active`:`Inactive`,i.appendChild(o),i.appendChild(s);let c=document.createElement(`div`);if(c.className=UU(),r.matchUpCount!=null){let e=document.createElement(`div`);e.className=`spl-date-badge matchups`,e.textContent=`${r.matchUpCount} matchUps`,c.appendChild(e)}if(r.issueCount&&r.issueCount>0){let e=document.createElement(`div`);e.className=`spl-date-badge issues`,e.textContent=`${r.issueCount} issues`,c.appendChild(e)}n.appendChild(i),n.appendChild(c),n.addEventListener(`click`,()=>e.onDateSelected(r.date)),a.appendChild(n)}}return{element:t,update:o}}function NW(e,t,n){let r=document.createElement(`div`);r.className=wU();let i=document.createElement(`div`);i.className=TU();let a=n?.titleLeadingActions,o;if(n?.titleSlot?o=n.titleSlot:(o=document.createElement(`div`),o.className=EU(),o.textContent=`Court Grid`),a){let e=document.createElement(`div`);e.className=OU();let t=Array.isArray(a)?a:[a];for(let n of t)e.appendChild(n);e.appendChild(o),i.appendChild(e)}else i.appendChild(o);let s=n?.headerActions;if(s){let e=document.createElement(`div`);e.className=DU();let t=Array.isArray(s)?s:[s];for(let n of t)e.appendChild(n);i.appendChild(e)}r.appendChild(i);let c=document.createElement(`div`);c.className=kU(),n?.gridMaxHeight&&(c.style.maxHeight=n.gridMaxHeight),e&&c.appendChild(e),c.addEventListener(`dragover`,e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`}),c.addEventListener(`drop`,e=>{if(e.preventDefault(),!t.onMatchUpDrop)return;let n;try{n=JSON.parse(e.dataTransfer.getData(`application/json`))}catch{return}(n.type===`CATALOG_MATCHUP`||n.type===`GRID_MATCHUP`)&&t.onMatchUpDrop(n,e)}),r.appendChild(c);function l(e){}return{element:r,update:l}}var PW=class{constructor(e){this.listeners=new Set,this.config=e;let t=e.initialCatalogState??{};this.state={matchUpCatalog:e.matchUpCatalog,scheduleDates:e.scheduleDates,issues:e.issues??[],selectedDate:e.scheduleDates[0]?.date??null,selectedMatchUp:null,catalogSearchQuery:t.catalogSearchQuery??``,catalogGroupBy:t.catalogGroupBy??`event`,catalogFilters:t.catalogFilters??{},showCompleted:t.showCompleted??!1,showScheduled:t.showScheduled??!1,scheduledBehavior:e.scheduledBehavior??`dim`,schedulingMode:e.schedulingMode??`immediate`,pendingActions:[],hasUnsavedChanges:!1,leftCollapsed:!!e.hideLeft,hideLeft:!!e.hideLeft,activeStripVisible:e.activeStripVisible??!0}}getState(){return this.state}setMatchUpCatalog(e){this.setState({matchUpCatalog:e}),this.state.selectedMatchUp&&(e.some(e=>e.matchUpId===this.state.selectedMatchUp?.matchUpId)||this.setState({selectedMatchUp:null}))}setScheduleDates(e){this.setState({scheduleDates:e})}setIssues(e){this.setState({issues:e})}handleMatchUpDrop(e,t){if(this.state.schedulingMode===`immediate`)this.config.onMatchUpDrop?.(e,t);else{let n={kind:`schedule`,matchUpId:e.matchUp.matchUpId,matchUp:e.matchUp,event:t};this.setState({pendingActions:[...this.state.pendingActions,n],hasUnsavedChanges:!0})}}handleMatchUpRemove(e){if(this.state.schedulingMode===`immediate`)this.config.onMatchUpRemove?.(e);else{let t=this.state.pendingActions.findIndex(t=>t.kind===`schedule`&&t.matchUpId===e);if(t>=0){let e=[...this.state.pendingActions];e.splice(t,1),this.setState({pendingActions:e,hasUnsavedChanges:e.length>0})}else{let t={kind:`unschedule`,matchUpId:e};this.setState({pendingActions:[...this.state.pendingActions,t],hasUnsavedChanges:!0})}}}save(){let e=this.state.pendingActions;return e.length?(this.config.onBulkSave?.(e),this.setState({pendingActions:[],hasUnsavedChanges:!1}),e):[]}discardPending(){this.setState({pendingActions:[],hasUnsavedChanges:!1})}getPendingActions(){return this.state.pendingActions}selectDate(e){this.state.selectedDate!==e&&(this.setState({selectedDate:e}),this.config.onDateSelected?.(e))}selectMatchUp(e){this.setState({selectedMatchUp:e}),this.config.onMatchUpSelected?.(e)}setCatalogSearch(e){this.setState({catalogSearchQuery:e})}setCatalogGroupBy(e){this.setState({catalogGroupBy:e})}setCatalogFilters(e){this.setState({catalogFilters:e})}setShowCompleted(e){this.setState({showCompleted:e})}setShowScheduled(e){this.setState({showScheduled:e})}toggleLeftPanel(){this.setState({leftCollapsed:!this.state.leftCollapsed})}setActiveStripVisible(e){this.state.activeStripVisible!==e&&this.setState({activeStripVisible:e})}toggleActiveStrip(){this.setState({activeStripVisible:!this.state.activeStripVisible})}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setState(e){this.state={...this.state,...e},this.emit()}emit(){for(let e of this.listeners)e(this.state)}},FW=class{constructor(e){this.container=null,this.store=new PW(e);let t=MW({onDateSelected:e=>this.store.selectDate(e)}),n=jW(),r=NW(e.courtGridElement,{onMatchUpDrop:(e,t)=>{this.store.handleMatchUpDrop(e,t)}},{gridMaxHeight:e.gridMaxHeight,headerActions:e.headerActions,titleLeadingActions:e.titleLeadingActions,titleSlot:e.titleSlot}),i=OW({onSearchChange:e=>this.store.setCatalogSearch(e),onGroupByChange:e=>this.store.setCatalogGroupBy(e),onFilterChange:e=>this.store.setCatalogFilters(e),onShowCompletedChange:e=>this.store.setShowCompleted(e),onShowScheduledChange:e=>this.store.setShowScheduled(e),onMatchUpSelected:e=>this.store.selectMatchUp(e),onDropRemove:e=>{this.store.handleMatchUpRemove(e)}}),a=dW();this.layout=sW({dateStrip:t,issuesPanel:n,courtGridSlot:r,matchUpCatalog:i,inspectorPanel:a},{onToggleLeft:()=>this.store.toggleLeftPanel()},{hideLeft:e.hideLeft,catalogSide:e.catalogSide}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.layout.element)}destroy(){this.unsubscribe(),this.container&&this.layout.element.parentNode===this.container&&this.layout.element.remove(),this.container=null}setMatchUpCatalog(e){this.store.setMatchUpCatalog(e)}setScheduleDates(e){this.store.setScheduleDates(e)}setIssues(e){this.store.setIssues(e)}setActiveStripVisible(e){this.store.setActiveStripVisible(e)}toggleActiveStrip(){this.store.toggleActiveStrip()}get activeStripVisible(){return this.store.getState().activeStripVisible}save(){return this.store.save()}discardPending(){this.store.discardPending()}get hasUnsavedChanges(){return this.store.getState().hasUnsavedChanges}getStore(){return this.store}},IW=new Set([`IN_PROGRESS`]),LW=new Set([`SUSPENDED`]),RW=new Set([`CANCELLED`,`ABANDONED`,`COMPLETED`,`DEAD_RUBBER`,`DEFAULTED`,`DOUBLE_WALKOVER`,`DOUBLE_DEFAULT`,`RETIRED`,`WALKOVER`]),zW=`in-progress`,BW=`suspended`,VW=`pending`,HW=`completed`;function UW(e,t,n,r){let i=e.matchUpStatus;return i&&n.has(i)?BW:i&&t.has(i)||e.hasScore&&e.winningSide===void 0&&(!i||!r.has(i))?zW:i&&r.has(i)||e.winningSide!==void 0?HW:VW}function WW(e,t){let n=t?.inProgressStatuses??IW,r=t?.suspendedStatuses??LW,i=t?.completedStatuses??RW,a=e.cells,o=-1;for(let t=0;t<a.length;t++){let s=a[t];if(!s)continue;let c=UW(s,n,r,i);if(c===zW||c===BW)return{courtId:e.courtId,state:c,matchUp:s,rowIndex:t};c===VW&&s.calledAt&&o===-1&&(o=t)}return o===-1?{courtId:e.courtId,state:`free`}:{courtId:e.courtId,state:`next`,matchUp:a[o],rowIndex:o}}function GW(e,t){return e.columns.map(e=>WW(e,t))}function KW(e,t){if(t.size===0)return!1;for(let n of e.participantIds)if(t.has(n))return!0;return!1}function qW(e,t){return t.roundNumber!==void 0&&t.drawId!==void 0&&e.drawId===t.drawId&&e.roundNumber!==void 0&&e.roundNumber<t.roundNumber}function JW(e,t){let n=new Set(t.participantIds??[]),r=-1,i=-1;for(let a of e.columns)for(let e=0;e<a.cells.length;e++){let o=a.cells[e];!o||o.matchUpId===t.matchUpId||(e>r&&KW(o,n)&&(r=e),e>i&&qW(o,t)&&(i=e))}return{participantFloor:r,earlierRoundFloor:i}}function YW(e,t,n){let r=t;for(;r<e.cells.length;){let t=e.cells[r];if(!t||t.matchUpId===n)return r;r++}return r}function XW(e,t,n,r){let i=e.columns.find(e=>e.courtId===t);if(!i)throw Error(`computeActiveStripDropTarget: court "${t}" not present in grid`);let{participantFloor:a,earlierRoundFloor:o}=JW(e,n),s=WW(i,r),c=s.state!==`free`&&s.rowIndex!==void 0?s.rowIndex:-1;return{courtId:t,rowIndex:YW(i,Math.max(0,a+1,o+1,c),n.matchUpId)}}function ZW(e,t){if(t.roundNumber===void 0||t.drawId===void 0)return 1/0;for(let n=0;n<e.cells.length;n++){let r=e.cells[n];if(!(!r||r.matchUpId===t.matchUpId)&&r.drawId===t.drawId&&r.roundNumber!==void 0&&r.roundNumber>t.roundNumber)return n}return 1/0}function QW(e,t){let n=e.columns.map(e=>({courtId:e.courtId,cells:e.cells.slice()})),r={columns:n},i=new Map(n.map(e=>[e.courtId,e]));return t.toSorted((e,t)=>(e.roundNumber??0)-(t.roundNumber??0)||e.matchUpId.localeCompare(t.matchUpId)).map(e=>{let t=e.courtId?i.get(e.courtId):void 0;if(!t)return{matchUpId:e.matchUpId,placed:!1};let n={matchUpId:e.matchUpId,drawId:e.drawId,roundNumber:e.roundNumber,participantIds:e.participantIds},{participantFloor:a,earlierRoundFloor:o}=JW(r,n),s=Math.max(0,a+1,o+1),c=ZW(t,e),l=-1;for(let n=s;n<=t.cells.length&&n<c;n++){let r=t.cells[n];if(!r||r.matchUpId===e.matchUpId){l=n;break}}return l===-1?{matchUpId:e.matchUpId,placed:!1}:(t.cells[l]={matchUpId:e.matchUpId,drawId:e.drawId,roundNumber:e.roundNumber,participantIds:e.participantIds},{matchUpId:e.matchUpId,courtId:e.courtId,rowIndex:l,placed:!0})})}var $W=`drop-over`;function eG(e,t,n,r,i){e.addEventListener(`dragover`,t=>{t.preventDefault(),e.classList.add($W),t.dataTransfer&&(t.dataTransfer.dropEffect=`move`)}),e.addEventListener(`dragleave`,()=>{e.classList.remove($W)}),e.addEventListener(`drop`,a=>{if(e.classList.remove($W),a.preventDefault(),!n.onMatchUpDrop)return;let o;try{o=JSON.parse(a.dataTransfer?.getData(`application/json`)??``)}catch{return}if(o.type!==`CATALOG_MATCHUP`&&o.type!==`GRID_MATCHUP`)return;let s={matchUpId:o.matchUp.matchUpId,drawId:o.matchUp.drawId,roundNumber:o.matchUp.roundNumber,participantIds:(o.matchUp.sides??[]).map(e=>e.participantId).filter(e=>!!e)},c=XW(r(),t.courtId,s,i);n.onMatchUpDrop(o,c,a)})}function tG(e){return e===`in-progress`?`LIVE`:e===`suspended`?`SUSP`:e===`next`?`NEXT`:null}function nG(e,t,n,r,i){let a=document.createElement(`div`);if(a.className=`spl-active-strip-cell state-${e.state}`,i&&(a.classList.add(`has-availability-block`),e.state!==`free`&&e.matchUp&&a.classList.add(`has-block-conflict`)),a.dataset.courtId=e.courtId,e.rowIndex!==void 0&&(a.dataset.rowIndex=String(e.rowIndex)),r.cellHeight&&(a.style.minHeight=r.cellHeight),i){let e=document.createElement(`div`);e.className=`spl-active-strip-block-banner block-${i.type.toLowerCase()}`;let t=document.createElement(`span`);if(t.className=`spl-active-strip-block-label`,t.textContent=i.label,e.appendChild(t),i.detail){let t=document.createElement(`span`);t.className=`spl-active-strip-block-detail`,t.textContent=i.detail,e.appendChild(t)}a.appendChild(e)}if(e.state!==`free`&&e.matchUp){let t=r.renderCell?.(e.matchUp);if(t)a.appendChild(t);else{let t=document.createElement(`div`);t.className=`spl-active-strip-body`,t.textContent=e.matchUp.participantIds.join(` – `)||e.matchUp.matchUpId,a.appendChild(t)}}let o=tG(e.state);if(o){let t=document.createElement(`span`);t.className=`spl-active-strip-state-pill`,t.textContent=o,e.state===`suspended`&&(t.title=`Suspended`),a.appendChild(t)}return eG(a,e,t,n,r.statusOptions),a}function rG(e){let t=document.createElement(`div`);if(t.className=`spl-active-strip-spacer`,e.cellHeight&&(t.style.minHeight=e.cellHeight),e.spacerLabel){let n=document.createElement(`span`);n.className=`spl-active-strip-spacer-label`,n.textContent=e.spacerLabel,t.appendChild(n)}return t}function iG(e={},t={}){let n=document.createElement(`div`);n.className=`spl-active-strip`;let r={grid:{columns:[]},courts:[]};function i(){return r.grid}function a(){n.innerHTML=``,r.gridTemplateColumns?(n.style.display=`grid`,n.style.gridTemplateColumns=r.gridTemplateColumns):(n.style.display=``,n.style.gridTemplateColumns=``),n.style.minWidth=r.minWidth??``,n.appendChild(rG(t));let a=GW(r.grid,t.statusOptions);for(let o of a){let a=r.courtBlocks?.[o.courtId];n.appendChild(nG(o,e,i,t,a))}}function o(e){r=e,a()}function s(e){n.hidden=!e.activeStripVisible}return{element:n,setData:o,update:s}}var aG=`spl-cell--conflict-highlight`,oG=`spl-cell--complete`,sG={header:[`time`],body:[`eventRound`,`participants`],footer:[`score`],participantDisplay:{nameFormat:`full`,showSeed:!1,showRanking:!1,showNationality:!1,boldWinner:!0,showPotentials:!0}};function cG(e,t){let n=t??sG;return e.isBlocked?uG(e):e.isReserved?lG(e):e.matchUpId?fG(e,n):dG()}function lG(e){let t=document.createElement(`div`);t.className=`spl-grid-cell spl-cell--reserved`,t.dataset.reserved=`true`;let n=document.createElement(`div`);n.className=`spl-grid-cell__reserved-label`;let r=document.createElement(`div`);r.className=`spl-grid-cell__reserved-type`,r.textContent=`Reserved`,n.appendChild(r);let i=e.reservation?.tournamentName;if(i){let e=document.createElement(`div`);e.className=`spl-grid-cell__reserved-name`,e.textContent=i,n.appendChild(e)}let a=e.reservation?.scheduledTime??e.schedule?.scheduledTime;if(a){let e=document.createElement(`div`);e.className=`spl-grid-cell__reserved-time`,e.textContent=a,n.appendChild(e)}return t.appendChild(n),t}function uG(e){let t=document.createElement(`div`);t.className=`spl-grid-cell spl-cell--blocked`;let n=e.booking?.bookingType||`BLOCKED`;t.dataset.bookingType=n;let r=document.createElement(`div`);r.className=`spl-grid-cell__block-label`;let i=document.createElement(`div`);if(i.className=`spl-grid-cell__block-type`,i.textContent=n,r.appendChild(i),e.booking?.rowCount){let t=document.createElement(`div`);t.className=`spl-grid-cell__block-rows`,t.textContent=`${e.booking.rowCount} rows`,r.appendChild(t)}if(e.booking?.notes){let t=document.createElement(`div`);t.className=`spl-grid-cell__block-notes`,t.textContent=e.booking.notes,r.appendChild(t)}let a=e.booking?.registrations??[];if(a.length){let e=document.createElement(`ul`);e.className=`spl-grid-cell__block-registrations`;for(let t of a){let n=document.createElement(`li`);n.className=`spl-grid-cell__block-registration`,n.textContent=t,e.appendChild(n)}r.appendChild(e)}return t.appendChild(r),t}function dG(){let e=document.createElement(`div`);return e.className=`spl-grid-cell spl-cell--empty`,e}function fG(e,t){let n=document.createElement(`div`);if(n.className=`spl-grid-cell`,n.dataset.matchupId=e.matchUpId,e.drawId&&(n.dataset.drawId=e.drawId),e.gender&&(n.dataset.gender=e.gender),pG(n,e),t.header.length){let r=document.createElement(`div`);r.className=`spl-grid-cell__header`,mG(r,t.header,e,t),n.appendChild(r)}if(t.body.length){let r=document.createElement(`div`);r.className=`spl-grid-cell__body`,mG(r,t.body,e,t),n.appendChild(r)}if(t.footer.length){let r=document.createElement(`div`);r.className=`spl-grid-cell__footer`,mG(r,t.footer,e,t),n.appendChild(r)}return e.issueIds?.length&&(n.addEventListener(`mouseenter`,()=>{n.classList.add(aG);for(let t of e.issueIds)document.querySelectorAll(`[data-matchup-id="${t}"]`).forEach(e=>e.classList.add(aG))}),n.addEventListener(`mouseleave`,()=>{n.classList.remove(aG);for(let t of e.issueIds)document.querySelectorAll(`[data-matchup-id="${t}"]`).forEach(e=>e.classList.remove(aG))})),n}function pG(e,t){let n=t.matchUpStatus?.toUpperCase();n===`COMPLETED`||n===`RETIRED`||n===`DEFAULTED`||n===`WALKOVER`?e.classList.add(oG):n===`IN_PROGRESS`?e.classList.add(`spl-cell--inprogress`):n===`ABANDONED`?e.classList.add(`spl-cell--abandoned`):n===`CANCELLED`?e.classList.add(`spl-cell--cancelled`):n===`DOUBLE_WALKOVER`&&e.classList.add(`spl-cell--double-walkover`);let r=t.scheduleState?.toUpperCase();r===`SCHEDULE_ERROR`||r===`ERROR`?e.classList.add(`spl-cell--error`):r===`SCHEDULE_CONFLICT`||r===`CONFLICT`?e.classList.add(`spl-cell--conflict`):r===`SCHEDULE_WARNING`||r===`WARNING`?e.classList.add(`spl-cell--warning`):(r===`SCHEDULE_ISSUE`||r===`ISSUE`)&&e.classList.add(`spl-cell--issue`),(t.issueType===`DOUBLE_BOOKING`||t.issueType===`courtDoubleBooking`)&&e.classList.add(`spl-cell--double-booking`)}function mG(e,t,n,r){for(let i of t){let t=hG(i,n,r);t&&e.appendChild(t)}}function hG(e,t,n){switch(e){case`time`:return gG(t);case`eventRound`:return _G(t);case`participants`:return vG(t,n.participantDisplay);case`score`:return CG(t);case`matchUpStatus`:return wG(t);case`matchUpFormat`:return TG(t);case`umpire`:return EG(t);default:return null}}function gG(e){let t=e.schedule?.scheduledTime||e.schedule?.startTime,n=e.schedule?.timeModifiers,r=e.schedule?.courtAnnotation;if(!t&&!n?.length&&!r)return null;let i=document.createElement(`div`);i.className=`spl-grid-cell__time`;let a=[];if(n?.length&&a.push(n.join(` `)),t&&a.push(t),i.textContent=a.join(` `)||``,r){let e=document.createElement(`span`);e.className=`spl-grid-cell__court-annotation`,e.textContent=` ${r}`,i.appendChild(e)}return i}function _G(e){let t=[e.eventName,e.roundName].filter(Boolean);if(!t.length)return null;let n=document.createElement(`div`);return n.className=`spl-grid-cell__event-round`,n.textContent=t.join(` `),n}function vG(e,t){let n=t??sG.participantDisplay,r=document.createElement(`div`);r.className=`spl-grid-cell__participants`;let i=e.sides||[],a=e.matchUpStatus?.toUpperCase()===`BYE`,o=i.some(e=>e.bye);if(i.length===0&&n.showPotentials!==!1&&e.potentialParticipants?.length){for(let t=0;t<e.potentialParticipants.length;t++){t>0&&r.appendChild(xG());let n=e.potentialParticipants[t].map(e=>e?.participantName||`TBD`).join(` / `),i=document.createElement(`div`);i.className=`spl-grid-cell__side spl-grid-cell__potential`,i.textContent=n||`TBD`,r.appendChild(i)}return r}if(i.length===0)return null;for(let t=0;t<i.length;t++){let a=i[t];a.bye?r.appendChild(bG()):(t>0&&!i[t-1]?.bye&&r.appendChild(xG()),r.appendChild(yG(a,e,n,a.sideNumber??t+1)))}return(a||o)&&i.length===1&&!i[0].bye&&r.appendChild(bG()),r}function yG(e,t,n,r){let i=document.createElement(`div`);i.className=`spl-grid-cell__side`;let a=document.createElement(`span`);a.className=`spl-grid-cell__name`;let o=SG(e.participantName,n.nameFormat)||`TBD`;if(n.showSeed&&e.seedNumber&&(o+=` [${e.seedNumber}]`),n.showRanking&&e.ranking&&(o+=` (#${e.ranking})`),n.showNationality&&e.nationality&&(o+=` ${e.nationality}`),a.textContent=o,n.boldWinner!==!1&&t.winningSide===r&&(a.style.fontWeight=`bold`),i.appendChild(a),e.teamName){let t=document.createElement(`div`);t.className=`spl-grid-cell__team-name`,t.textContent=e.teamName,i.appendChild(t)}return i}function bG(){let e=document.createElement(`div`);return e.className=`spl-grid-cell__bye`,e.textContent=`BYE`,e}function xG(){let e=document.createElement(`div`);return e.className=`spl-grid-cell__vs`,e.textContent=`vs.`,e}function SG(e,t){if(!e)return``;switch(t){case`last`:return e.includes(`,`)?e.split(`,`)[0].trim():e.trim().split(/\s+/).at(-1);case`lastFirst`:{if(e.includes(`,`))return e.trim();let t=e.trim().split(/\s+/);return t.length<2?e:`${t.at(-1)}, ${t.slice(0,-1).join(` `)}`}case`firstLast`:{if(!e.includes(`,`))return e.trim();let[t,...n]=e.split(`,`);return`${n.join(`,`).trim()} ${t.trim()}`}default:return e}}function CG(e){let t=e.score?.scoreStringSide1,n=e.matchUpStatus?.toUpperCase(),r=n===`WALKOVER`?`WALKOVER`:n===`DEFAULTED`?`DEFAULT`:n===`RETIRED`?`RET.`:n===`DOUBLE_WALKOVER`?`D.W/O`:n===`ABANDONED`?`ABN.`:null;if(!t&&!r)return null;let i=document.createElement(`div`);return i.className=`spl-grid-cell__score`,i.textContent=t||r||``,i}function wG(e){if(!e.matchUpStatus)return null;let t=document.createElement(`div`);t.className=`spl-grid-cell__status-badge`;let n=e.matchUpStatus.toUpperCase();return n===`IN_PROGRESS`?(t.textContent=`LIVE`,t.classList.add(`spl-grid-cell__status-badge--live`)):n===`COMPLETED`||n===`RETIRED`||n===`DEFAULTED`||n===`WALKOVER`?(t.textContent=`DONE`,t.classList.add(`spl-grid-cell__status-badge--done`)):t.textContent=e.matchUpStatus.replaceAll(`_`,` `),t}function TG(e){if(!e.matchUpFormat)return null;let t=document.createElement(`div`);return t.className=`spl-grid-cell__format`,t.textContent=e.matchUpFormat,t}function EG(e){if(!e.umpire)return null;let t=document.createElement(`div`);return t.className=`spl-grid-cell__umpire`,t.textContent=e.umpire,t}function DG(e){if(!e)return{matchUpId:``};if(e.isBlocked)return{matchUpId:``,isBlocked:!0,booking:e.booking};let t=(e.sides||[]).map((e,t)=>({sideNumber:e.sideNumber??t+1,participantName:e.participant?.participantName??e.participantName,participantId:e.participantId??e.participant?.participantId,seedNumber:e.seedValue??e.seedNumber,ranking:e.ranking,nationality:e.participant?.nationalityCode??e.participant?.person?.nationalityCode??e.nationalityCode,teamName:e.teamParticipant?.participantName??e.teamName,bye:e.bye||void 0}));return{matchUpId:e.matchUpId,drawId:e.drawId,eventName:e.eventName,roundName:e.roundName,matchUpFormat:e.matchUpFormat,matchUpType:e.matchUpType,matchUpStatus:e.matchUpStatus,winningSide:e.winningSide,gender:e.gender??e.eventGender,sides:t,potentialParticipants:e.potentialParticipants,schedule:e.schedule?{scheduledTime:e.schedule.scheduledTime,startTime:e.schedule.startTime,timeModifiers:e.schedule.timeModifiers,courtAnnotation:e.schedule.courtAnnotation,courtId:e.schedule.courtId,courtOrder:e.schedule.courtOrder,venueId:e.schedule.venueId}:void 0,score:e.score?{scoreStringSide1:e.score.scoreStringSide1,scoreStringSide2:e.score.scoreStringSide2}:void 0,umpire:e.umpire?.participantName??e.umpireName,scheduleState:e.scheduleState,issueType:e.issueType,issueIds:e.issueIds}}function OG({cell:e,listProvider:t,onSelect:n,onCancel:r}){let i=e.innerHTML,a=[],o=!1,s=!1;e.classList.add(`spl-cell--typeahead`),e.innerHTML=``;let c=document.createElement(`div`);c.className=`spl-cell--typeahead-wrapper`,e.appendChild(c);let l=document.createElement(`input`);l.type=`text`,l.placeholder=`Search matchUps...`,l.setAttribute(`inputmode`,`search`),l.setAttribute(`autocapitalize`,`off`),l.setAttribute(`enterkeyhint`,`search`),l.setAttribute(`autocomplete`,`off`),c.appendChild(l);let u=e,d=0;for(;u&&d<10;){let e=window.getComputedStyle(u);(e.overflow!==`visible`||e.overflowX!==`visible`||e.overflowY!==`visible`)&&(a.push({el:u,overflow:u.style.overflow,overflowX:u.style.overflowX,overflowY:u.style.overflowY}),u.style.setProperty(`overflow`,`visible`,`important`),u.style.setProperty(`overflow-x`,`visible`,`important`),u.style.setProperty(`overflow-y`,`visible`,`important`)),u=u.parentElement,d++}ce({list:t(),element:l,listProvider:t,callback:e=>{e&&!s&&(o=!0,p(),n(e))}}),l.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),p(),r?.())}),l.addEventListener(`blur`,()=>{setTimeout(()=>{!o&&!s&&(p(),r?.())},200)});let f=e=>{e.target!==l&&!c.contains(e.target)&&(e.preventDefault(),l.blur())};e.addEventListener(`mousedown`,f),c.addEventListener(`click`,e=>{e.stopPropagation()}),setTimeout(()=>l.focus(),0);function p(){if(!s){s=!0,e.removeEventListener(`mousedown`,f),e.classList.remove(`spl-cell--typeahead`),e.innerHTML=i;for(let{el:e,overflow:t,overflowX:n,overflowY:r}of a)t?e.style.overflow=t:e.style.removeProperty(`overflow`),n?e.style.overflowX=n:e.style.removeProperty(`overflow-x`),r?e.style.overflowY=r:e.style.removeProperty(`overflow-y`)}}return{destroy:p}}function kG(e,t){let n=new FW(e);return n.render(t),n}var AG=class{constructor(e){this.listeners=new Set,this.config=e,this.state={compositionName:e.compositionName||`Custom`,theme:e.composition?.theme||``,configuration:{...e.composition?.configuration||{}},colors:e.composition?.colors?{...e.composition.colors}:void 0,expandedSections:new Set([`theme`,`display`]),isDirty:!1,readOnly:e.readOnly||!1}}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.setState({expandedSections:t})}setTheme(e){this.setState({theme:e,isDirty:!0}),this.notifyChange()}setColorField(e,t){let n={...this.state.colors||{}};t===void 0||t===``?delete n[e]:n[e]=t;let r=Object.keys(n).length>0;this.setState({colors:r?n:void 0,isDirty:!0}),this.notifyChange()}clearColors(){this.setState({colors:void 0,isDirty:!0}),this.notifyChange()}setCompositionName(e){this.setState({compositionName:e,isDirty:!0})}setConfigField(e,t){let n={...this.state.configuration,[e]:t};this.setState({configuration:n,isDirty:!0}),this.notifyChange()}setConfigNestedField(e,t,n){let r={...this.state.configuration[e]||{},[t]:n};this.setConfigField(e,r)}setConfiguration(e){this.setState({configuration:{...e},isDirty:!0}),this.notifyChange()}loadComposition(e,t,n,r){this.setState({compositionName:e,theme:t,configuration:{...n},colors:r?{...r}:void 0,isDirty:!1}),this.notifyChange()}resetToInitial(){this.setState({compositionName:this.config.compositionName||`Custom`,theme:this.config.composition?.theme||``,configuration:{...this.config.composition?.configuration||{}},colors:this.config.composition?.colors?{...this.config.composition.colors}:void 0,isDirty:!1}),this.notifyChange()}setState(e){this.state={...this.state,...e},this.emit()}emit(){for(let e of this.listeners)e(this.state)}notifyChange(){this.config.onChange?.({theme:this.state.theme,configuration:this.state.configuration,...this.state.colors?{colors:{...this.state.colors}}:{}})}},jG=()=>`ce-layout`,MG=()=>`ce-left`,NG=()=>`ce-right`,PG=()=>`ce-name-row`,FG=()=>`ce-name-label`,IG=()=>`ce-name-input`,LG=()=>`ce-section`,RG=()=>`ce-section-header`,zG=()=>`ce-section-chevron`,BG=()=>`ce-section-body`,VG=()=>`ce-field`,HG=()=>`ce-field-label`,UG=()=>`ce-field-control`,WG=()=>`ce-select`,GG=()=>`ce-text-input`,KG=()=>`ce-color-input`,qG=()=>`ce-toggle`,JG=()=>`ce-toggle-track`,YG=()=>`ce-preview`,XG=()=>`ce-preview-header`,ZG=()=>`ce-preview-body`,QG=()=>`ce-preview-matchup`,$G=()=>`ce-subgroup`,eK=()=>`ce-subgroup-title`;function tK(e,t){let n=document.createElement(`div`);n.className=LG();let r=document.createElement(`div`);r.className=RG();let i=document.createElement(`span`);i.className=zG();let a=document.createElement(`span`);a.textContent=e.label,r.appendChild(i),r.appendChild(a),r.addEventListener(`click`,()=>t.toggleSection(e.id));let o=document.createElement(`div`);o.className=BG();let s=e.factory(t);o.appendChild(s.element),n.appendChild(r),n.appendChild(o);function c(t){let n=t.expandedSections.has(e.id);i.textContent=n?`▼`:`▶`,o.style.display=n?`block`:`none`,n&&s.update(t)}return{element:n,update:c}}function nK(e,t,n,r=!1){let i=document.createElement(`div`);i.className=VG();let a=document.createElement(`span`);a.className=HG(),a.textContent=e,i.appendChild(a);let o=document.createElement(`label`);o.className=qG();let s=document.createElement(`input`);s.type=`checkbox`,s.checked=t,s.disabled=r,s.addEventListener(`change`,()=>n(s.checked));let c=document.createElement(`span`);c.className=JG(),o.appendChild(s),o.appendChild(c);let l=document.createElement(`div`);return l.className=UG(),l.appendChild(o),i.appendChild(l),{element:i,setChecked:e=>{s.checked=e},setDisabled:e=>{s.disabled=e}}}function rK(e,t,n,r,i=!1){let a=document.createElement(`div`);a.className=VG();let o=document.createElement(`span`);o.className=HG(),o.textContent=e,a.appendChild(o);let s=document.createElement(`select`);s.className=WG(),s.disabled=i;for(let e of t){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,e.value===n&&(t.selected=!0),s.appendChild(t)}s.addEventListener(`change`,()=>r(s.value));let c=document.createElement(`div`);return c.className=UG(),c.appendChild(s),a.appendChild(c),{element:a,setValue:e=>{s.value=e}}}function iK(e,t,n,r=``,i=!1){let a=document.createElement(`div`);a.className=VG();let o=document.createElement(`span`);o.className=HG(),o.textContent=e,a.appendChild(o);let s=document.createElement(`input`);s.type=`text`,s.className=GG(),s.value=t,s.placeholder=r,s.disabled=i,s.addEventListener(`input`,()=>n(s.value));let c=document.createElement(`div`);return c.className=UG(),c.appendChild(s),a.appendChild(c),{element:a,setValue:e=>{s.value=e}}}function aK(e,t,n,r=!1){let i=document.createElement(`div`);i.className=VG();let a=document.createElement(`span`);a.className=HG(),a.textContent=e,i.appendChild(a);let o=document.createElement(`input`);o.type=`color`,o.className=KG(),o.value=t||`#000000`,o.disabled=r,o.addEventListener(`input`,()=>n(o.value));let s=document.createElement(`div`);return s.className=UG(),s.appendChild(o),i.appendChild(s),{element:i,setValue:e=>{o.value=e||`#000000`}}}var oK=[],sK=new Set;for(let[,e]of Object.entries(mi))if(!sK.has(e.theme)){sK.add(e.theme);let t=e.theme.replace(`chc-theme-`,``).replace(/-/g,` `).replace(/\b\w/g,e=>e.toUpperCase());oK.push({value:e.theme,label:t})}function cK(e){let t=document.createElement(`div`),n=rK(`Load preset`,[{value:``,label:`— Load preset —`},...Object.keys(mi).map(e=>({value:e,label:e}))],``,t=>{if(!t)return;let r=mi[t];r&&e.loadComposition(t,r.theme,r.configuration||{},r.colors),n.setValue(``)},e.getState().readOnly);t.appendChild(n.element);let r=document.createElement(`div`);r.style.cssText=`font-size:0.7rem; color:var(--chc-text-secondary, #999); padding:0 0 0.3rem; line-height:1.3;`,r.textContent=`Replaces all settings with a built-in composition.`,t.appendChild(r);let i=rK(`Color theme`,oK,e.getState().theme,t=>e.setTheme(t),e.getState().readOnly);t.appendChild(i.element);let a=document.createElement(`div`);a.style.cssText=`font-size:0.7rem; color:var(--chc-text-secondary, #999); padding:0 0 0.3rem; line-height:1.3;`,a.textContent=`Changes only the color scheme, not the display settings.`,t.appendChild(a);function o(e){i.setValue(e.theme)}return{element:t,update:o}}var lK=[{key:`border`,label:`MatchUp border`},{key:`borderHover`,label:`MatchUp border (hover)`},{key:`borderInlineStart`,label:`Left-edge accent`},{key:`connector`,label:`Connector lines`,hint:`Use "transparent" to hide`},{key:`matchUpBackground`,label:`MatchUp background`},{key:`internalDividers`,label:`Participant dividers`},{key:`score`,label:`[Score] placeholder text`},{key:`roundHeader`,label:`Round header text`},{key:`roundHeaderBackground`,label:`Round header background`,hint:`Leave blank for transparent`},{key:`roundHeaderUnderline`,label:`Round header underline`,hint:`Divider below header`},{key:`matchUpFooterText`,label:`MatchUp footer text`},{key:`matchUpFooterBackground`,label:`MatchUp footer background`},{key:`matchUpFooterDivider`,label:`MatchUp footer divider`,hint:`Border above footer`}],uK=/^#[0-9a-f]{6}$/i;function dK(e,t,n,r){let i=document.createElement(`div`);i.className=VG();let a=document.createElement(`span`);a.className=HG(),a.textContent=e.label,i.appendChild(a);let o=document.createElement(`div`);o.className=UG(),o.style.display=`flex`,o.style.gap=`0.4rem`,o.style.alignItems=`center`;let s=document.createElement(`input`);s.type=`color`,s.className=KG(),s.disabled=r;let c=document.createElement(`input`);c.type=`text`,c.className=GG(),c.placeholder=e.hint||`#rrggbb or color name`,c.disabled=r,c.style.flex=`1`;function l(e){c.value=e||``,e&&uK.test(e)?(s.value=e,s.style.opacity=`1`):(s.value=`#000000`,s.style.opacity=e?`0.4`:`1`)}return l(t),s.addEventListener(`input`,()=>{c.value=s.value,s.style.opacity=`1`,n(s.value)}),c.addEventListener(`input`,()=>{let e=c.value.trim();e&&uK.test(e)?(s.value=e,s.style.opacity=`1`):s.style.opacity=e?`0.4`:`1`,n(e||void 0)}),o.appendChild(s),o.appendChild(c),i.appendChild(o),{element:i,setValue:l}}function fK(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=document.createElement(`div`);r.style.cssText=`font-size:0.7rem; color:var(--chc-text-secondary, #999); padding:0 0 0.4rem; line-height:1.3;`,r.textContent=`Per-composition overrides. Leave blank to inherit from the selected theme.`,t.appendChild(r);let i=lK.map(r=>{let i=dK(r,e.getState().colors?.[r.key],t=>e.setColorField(r.key,t),n);return t.appendChild(i.element),{def:r,ctrl:i}}),a=document.createElement(`div`);a.className=VG();let o=document.createElement(`span`);o.className=HG(),o.textContent=`Left-edge width`,a.appendChild(o);let s=document.createElement(`div`);s.className=UG();let c=document.createElement(`input`);c.type=`text`,c.className=GG(),c.placeholder=`e.g. 10px`,c.disabled=n,c.value=e.getState().colors?.borderInlineStartWidth||``,c.addEventListener(`input`,()=>{let t=c.value.trim();e.setColorField(`borderInlineStartWidth`,t||void 0)}),s.appendChild(c),a.appendChild(s),t.appendChild(a);let l=document.createElement(`button`);l.type=`button`,l.textContent=`Clear color overrides`,l.disabled=n,l.style.cssText=`margin-top:0.6rem; padding:0.25rem 0.5rem; font-size:0.75rem; cursor:pointer; background:transparent; border:1px solid var(--chc-border-secondary, #ccc); border-radius:4px;`,l.addEventListener(`click`,()=>e.clearColors()),t.appendChild(l);function u(e){for(let{def:t,ctrl:n}of i)n.setValue(e.colors?.[t.key]);c.value=e.colors?.borderInlineStartWidth||``}return{element:t,update:u}}function pK(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=nK(`Nationality flags`,!!r.flags,t=>e.setConfigField(`flags`,t),n),a=rK(`Seeding style`,[{value:``,label:`None`},{value:`true`,label:`Parentheses`},{value:`square`,label:`Square brackets`}],r.bracketedSeeds===`square`?`square`:r.bracketedSeeds?`true`:``,t=>{t===`square`?e.setConfigField(`bracketedSeeds`,`square`):t===`true`?e.setConfigField(`bracketedSeeds`,!0):e.setConfigField(`bracketedSeeds`,void 0)},n),o=rK(`Seed element`,[{value:``,label:`Default`},{value:`sup`,label:`Superscript`},{value:`span`,label:`Inline`}],r.seedingElement||``,t=>e.setConfigField(`seedingElement`,t||void 0),n),s=nK(`Draw positions (1st round)`,!!r.drawPositions,t=>e.setConfigField(`drawPositions`,t),n),c=nK(`Draw positions (all rounds)`,!!r.allDrawPositions,t=>e.setConfigField(`allDrawPositions`,t),n),l=nK(`Team logo`,r.teamLogo!==!1,t=>e.setConfigField(`teamLogo`,t),n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element),t.appendChild(c.element),t.appendChild(l.element);function u(e){let t=e.configuration;i.setChecked(!!t.flags),a.setValue(t.bracketedSeeds===`square`?`square`:t.bracketedSeeds?`true`:``),o.setValue(t.seedingElement||``),s.setChecked(!!t.drawPositions),c.setChecked(!!t.allDrawPositions),l.setChecked(t.teamLogo!==!1)}return{element:t,update:u}}function mK(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=nK(`Score box`,!!r.scoreBox,t=>e.setConfigField(`scoreBox`,t),n),a=nK(`Game score only`,!!r.gameScoreOnly,t=>e.setConfigField(`gameScoreOnly`,t),n);t.appendChild(i.element),t.appendChild(a.element);let o=document.createElement(`div`);o.className=$G();let s=document.createElement(`div`);s.className=eK(),s.textContent=`Game Score Display`,o.appendChild(s);let c=rK(`Position`,[{value:``,label:`Default`},{value:`leading`,label:`Leading`},{value:`trailing`,label:`Trailing`}],r.gameScore?.position||``,t=>e.setConfigNestedField(`gameScore`,`position`,t||void 0),n),l=nK(`Inverted`,!!r.gameScore?.inverted,t=>e.setConfigNestedField(`gameScore`,`inverted`,t),n);o.appendChild(c.element),o.appendChild(l.element),t.appendChild(o);function u(e){let t=e.configuration;i.setChecked(!!t.scoreBox),a.setChecked(!!t.gameScoreOnly),c.setValue(t.gameScore?.position||``),l.setChecked(!!t.gameScore?.inverted)}return{element:t,update:u}}function hK(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=nK(`Gender color`,!!r.genderColor,t=>e.setConfigField(`genderColor`,t),n),a=nK(`Winner color`,!!r.winnerColor,t=>e.setConfigField(`winnerColor`,t),n),o=rK(`Detail`,[{value:``,label:`Default`},{value:`TEAM`,label:`Team`},{value:`ADDRESS`,label:`Address`}],r.participantDetail||``,t=>{e.setConfigField(`participantDetail`,t||void 0),e.setConfigField(`showAddress`,t===`ADDRESS`)},n),s=iK(`Position color`,r.drawPositionColor||``,t=>e.setConfigField(`drawPositionColor`,t||void 0),`#999`,n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element);function c(e){let t=e.configuration;i.setChecked(!!t.genderColor),a.setChecked(!!t.winnerColor),o.setValue(t.participantDetail||``),s.setValue(t.drawPositionColor||``)}return{element:t,update:c}}function gK(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=iK(`TBD text`,r.placeHolders?.tbd||``,t=>e.setConfigNestedField(`placeHolders`,`tbd`,t||void 0),`TBD`,n),a=iK(`Bye text`,r.placeHolders?.bye||``,t=>e.setConfigNestedField(`placeHolders`,`bye`,t||void 0),`Bye`,n),o=iK(`Qualifier text`,r.placeHolders?.qualifier||``,t=>e.setConfigNestedField(`placeHolders`,`qualifier`,t||void 0),`Qualifier`,n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element);function s(e){let t=e.configuration;i.setValue(t.placeHolders?.tbd||``),a.setValue(t.placeHolders?.bye||``),o.setValue(t.placeHolders?.qualifier||``)}return{element:t,update:s}}var _K=[{scaleName:`WTN`,accessor:`wtnRating`,label:`WTN`},{scaleName:`UTR`,accessor:`utrRating`,label:`UTR`},{scaleName:`NTRP`,accessor:`ntrpRating`,label:`NTRP`},{scaleName:`ELO`,accessor:`eloRating`,label:`ELO`}];function vK(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration.scaleAttributes||{},i=rK(`Scale type`,[{value:``,label:`None`},{value:`RATING`,label:`Rating`},{value:`RANKING`,label:`Ranking`},{value:`SEEDING`,label:`Seeding`}],r.scaleType||``,t=>e.setConfigNestedField(`scaleAttributes`,`scaleType`,t||void 0),n),a=rK(`Scale name`,[{value:``,label:`None`},..._K.map(e=>({value:e.scaleName,label:e.label}))],r.scaleName||``,t=>{e.setConfigNestedField(`scaleAttributes`,`scaleName`,t||void 0);let n=_K.find(e=>e.scaleName===t);e.setConfigNestedField(`scaleAttributes`,`accessor`,n?.accessor||void 0)},n),o=aK(`Color`,r.scaleColor||`#ff0000`,t=>e.setConfigNestedField(`scaleAttributes`,`scaleColor`,t),n),s=rK(`Event type`,[{value:``,label:`Any`},{value:`SINGLES`,label:`Singles`},{value:`DOUBLES`,label:`Doubles`}],r.eventType||``,t=>e.setConfigNestedField(`scaleAttributes`,`eventType`,t||void 0),n),c=nK(`Fallback`,!!r.fallback,t=>e.setConfigNestedField(`scaleAttributes`,`fallback`,t),n),l=nK(`Right of name`,r.scalePosition===`right`,t=>e.setConfigNestedField(`scaleAttributes`,`scalePosition`,t?`right`:`left`),n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element),t.appendChild(c.element),t.appendChild(l.element);function u(e){let t=e.configuration.scaleAttributes||{},n=!!e.configuration.flags;i.setValue(t.scaleType||``),a.setValue(t.scaleName||``),o.setValue(t.scaleColor||`#ff0000`),s.setValue(t.eventType||``),c.setChecked(!!t.fallback),n?(l.setChecked(!0),l.setDisabled(!0)):(l.setChecked(t.scalePosition===`right`),l.setDisabled(!1))}return{element:t,update:u}}function yK(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=nK(`Schedule info`,!!r.scheduleInfo,t=>e.setConfigField(`scheduleInfo`,t),n),a=nK(`Round header`,!!r.roundHeader,t=>e.setConfigField(`roundHeader`,t),n),o=nK(`MatchUp footer`,!!r.matchUpFooter,t=>e.setConfigField(`matchUpFooter`,t),n),s=nK(`Center info`,!!r.centerInfo,t=>e.setConfigField(`centerInfo`,t),n),c=nK(`Set number`,!!r.resultsInfo,t=>e.setConfigField(`resultsInfo`,t),n),l=nK(`Winner chevron`,!!r.winnerChevron,t=>e.setConfigField(`winnerChevron`,t),n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element),t.appendChild(c.element),t.appendChild(l.element);function u(e){let t=e.configuration;i.setChecked(!!t.scheduleInfo),a.setChecked(!!t.roundHeader),o.setChecked(!!t.matchUpFooter),s.setChecked(!!t.centerInfo),c.setChecked(!!t.resultsInfo),l.setChecked(!!t.winnerChevron)}return{element:t,update:u}}var{DOUBLES:bK,SINGLES:xK}=t.eventConstants,{AD_HOC:SK}=t.drawDefinitionConstants,{INDIVIDUAL:CK}=t.participantConstants;function wK({matchUpFormat:e=`SET5-S:6/TB7`,randomWinningSide:n=!0,qualifyingProfiles:r,participantsCount:i,completionGoal:a,drawSize:o=4,eventType:s,outcomes:c,drawType:l,withRatings:u,withAllRatings:d}={}){let f=a<100?Math.floor(o*.01*a):void 0,p=`venueId`,m=[{venueName:`Challenge Courts`,venueAbbreviation:`CC`,startTime:`08:00`,endTime:`20:00`,venueId:p,courtNames:[1,2,3,4,5,6,7,8],courtIds:[`c1`,`c2`,`c3`,`c4`],courtsCount:8}],h={eventType:s===bK?bK:xK,completionGoal:f,qualifyingProfiles:r,participantsCount:i,seedsCount:8,matchUpFormat:e,drawSize:o,drawType:l,outcomes:c};l===SK&&Object.assign(h,{drawMatic:!0,roundsCount:3});let{tournamentRecord:g}=t.mocksEngine.generateTournamentRecord({drawProfiles:[h],completeAllMatchUps:!0,randomWinningSide:n,venueProfiles:m});t.tournamentEngine.setState(g),t.tournamentEngine.createTeamsFromParticipantAttributes({personAttribute:`nationalityCode`,addParticipants:!0});let _=d||(u?[{...u,accessor:u.scaleName}]:[]);if(_.length>0){let{participants:e}=t.tournamentEngine.getParticipants({participantFilters:{participantTypes:[CK]}});for(let n of _)e.forEach(e=>{let r=+(10+Math.random()*6).toFixed(2);t.tournamentEngine.setParticipantScaleItem({participantId:e.participantId,scaleItem:{scaleValue:{[n.accessor]:r},scaleName:n.scaleName,scaleType:n.scaleType||`RATING`,eventType:n.eventType||xK}})})}let{matchUps:v}=t.tournamentEngine.allTournamentMatchUps({participantsProfile:{withGroupings:!0}}),y=v.map(({matchUpId:e})=>e),b={startTime:`08:00`,endTime:`10:00`,scheduledTime:`07:00`,scheduledDate:`2021-01-01`,courtId:`c1`,venueId:p};t.tournamentEngine.bulkScheduleMatchUps({matchUpIds:y,schedule:b});let{matchUps:x}=t.tournamentEngine.allTournamentMatchUps({participantsProfile:{withISO2:!0,withIOC:!0,withScaleValues:!!(u||d)}});return{matchUps:x}}var TK=null;function EK(){if(!TK){let{matchUps:e}=wK({drawSize:8,eventType:`SINGLES`,randomWinningSide:!0,matchUpFormat:`SET3-S:6/TB7`,withAllRatings:_K.map(e=>({scaleName:e.scaleName,accessor:e.accessor}))}),t=e.filter(e=>e.roundNumber===1).slice(0,2),n=t[0]?.sides?.[0]?.participant,r=t[0]?.sides?.[1]?.participant,i={matchUpId:`preview-in-progress`,matchUpType:`SINGLES`,matchUpStatus:`IN_PROGRESS`,roundNumber:1,sides:[{sideNumber:1,drawPosition:5,seedNumber:3,seedValue:`3`,participant:n},{sideNumber:2,drawPosition:6,seedNumber:6,seedValue:`6`,participant:r}],score:{scoreStringSide1:`6-4 3-2`,scoreStringSide2:`4-6 2-3`,sets:[{setNumber:1,side1Score:6,side2Score:4,winningSide:1},{setNumber:2,side1Score:3,side2Score:2,side1PointScore:`30`,side2PointScore:`15`}]}},a={matchUpId:`preview-bye`,matchUpType:`SINGLES`,matchUpStatus:`BYE`,roundNumber:1,sides:[{sideNumber:1,drawPosition:7,seedNumber:2,seedValue:`2`,participant:n},{sideNumber:2,drawPosition:8,bye:!0}]},o={matchUpId:`preview-tbd`,matchUpType:`SINGLES`,matchUpStatus:`TO_BE_PLAYED`,roundNumber:1,sides:[{sideNumber:1,drawPosition:9,seedNumber:3,seedValue:`3`,participant:n},{sideNumber:2,drawPosition:10}]},s={matchUpId:`preview-qualifier`,matchUpType:`SINGLES`,matchUpStatus:`TO_BE_PLAYED`,roundNumber:1,sides:[{sideNumber:1,drawPosition:11,qualifier:!0},{sideNumber:2,drawPosition:12,seedNumber:4,seedValue:`4`,participant:n}]};TK=[...t,i,a,o,s]}return TK}var DK=null;function OK(){if(!DK){let{matchUps:e}=wK({drawSize:4,eventType:`SINGLES`,matchUpFormat:`SET3-S:6/TB7`,completionGoal:50,randomWinningSide:!0});DK=e}return DK}function kK(){let e=document.createElement(`div`);e.className=YG();let t=document.createElement(`div`);t.className=XG(),t.textContent=`Preview`,e.appendChild(t);let n=document.createElement(`div`);n.className=ZG(),e.appendChild(n);let r=``,i=``,a=``;function o(e){let t=JSON.stringify(e.configuration),o=JSON.stringify(e.colors||{});if(e.theme===r&&t===i&&o===a)return;r=e.theme,i=t,a=o,n.innerHTML=``,br(n),yr(n,e.colors);let s={theme:e.theme,configuration:{...e.configuration,matchUpFooter:!0},colors:e.colors?{...e.colors}:void 0},c=_r({roundNumber:1,roundProfile:{1:{roundName:`Round 1`}}});n.appendChild(c);let l=EK();for(let e of l){let t=document.createElement(`div`);t.className=QG();let r=ei({matchUp:e,composition:s,isLucky:!0});t.appendChild(r),n.appendChild(t)}let u=document.createElement(`div`);u.style.cssText=`margin-top:1.5rem; padding:0 0.25rem; font-size:0.7rem; color:var(--chc-text-secondary, #999); text-transform:uppercase; letter-spacing:0.05em;`,u.textContent=`Connector preview`,n.appendChild(u);let d=ni({matchUps:OK(),composition:s});n.appendChild(d)}return{element:e,update:o}}var AK=[{id:`theme`,label:`Theme & Preset`,factory:cK},{id:`colors`,label:`Colors`,factory:fK},{id:`display`,label:`Display`,factory:pK},{id:`score`,label:`Score`,factory:mK},{id:`participant`,label:`Participant`,factory:hK},{id:`placeholder`,label:`Placeholders`,factory:gK},{id:`scale`,label:`Scale Attributes`,factory:vK},{id:`layout`,label:`Layout & Info`,factory:yK}];function jK(e,t){let n=new AG(t),r=document.createElement(`div`);r.className=jG();let i=document.createElement(`div`);i.className=MG();let a=document.createElement(`div`);a.className=PG();let o=document.createElement(`span`);o.className=FG(),o.textContent=`Name`;let s=document.createElement(`input`);s.type=`text`,s.className=IG(),s.value=n.getState().compositionName,s.disabled=n.getState().readOnly,s.addEventListener(`input`,()=>n.setCompositionName(s.value)),a.appendChild(o),a.appendChild(s),i.appendChild(a);let c=AK.map(e=>{let t=tK(e,n);return i.appendChild(t.element),t}),l=document.createElement(`div`);l.className=NG();let u=kK();l.appendChild(u.element),r.appendChild(i),r.appendChild(l),e.appendChild(r);let d=n.subscribe(e=>{s.value=e.compositionName;for(let t of c)t.update(e);u.update(e)}),f=n.getState();for(let e of c)e.update(f);return u.update(f),{destroy:()=>{d(),e.contains(r)&&e.removeChild(r)},getComposition:()=>{let e=n.getState(),{participantProvider:t,persistInputFields:r,inlineAssignment:i,...a}=e.configuration;return{compositionName:e.compositionName,theme:e.theme,configuration:a,...e.colors?{colors:{...e.colors}}:{},version:1}}}}var MK=[`grand-slam`,`itf`,`minimal`,`none`],NK=[`standard`,`seedings`,`officials`,`none`],PK=[`a4`,`letter`],FK=[`auto`,`portrait`,`landscape`],IK={page:{pageSize:`a4`,orientation:`auto`,margins:{top:15,right:10,bottom:15,left:10}},header:{layout:`itf`,tournamentName:``},footer:{layout:`standard`,showTimestamp:!0,showPageNumbers:!0},content:{}};function LK(e,t){let n=XK(IK,t.config??{}),r=!!t.readOnly,i=Q(`div`,`pce-root`),a=Q(`div`,`pce-form`),o=Q(`div`,`pce-aside`);i.appendChild(a),i.appendChild(o);let s=null;function c(){a.innerHTML=``,a.appendChild(RK(n,r,l)),a.appendChild(zK(n,r,l)),a.appendChild(BK(n,r,l)),a.appendChild(VK(n,r,t.printType,l)),!r&&t.onSave&&a.appendChild(HK(()=>t.onSave?.(ZK(n)))),o.innerHTML=``;let e=Q(`div`,`pce-aside-title`);e.textContent=`Print Type`,o.appendChild(e);let i=Q(`span`,`pce-print-type-pill`);i.textContent=t.printType,o.appendChild(i);let c=Q(`div`,`pce-aside-title`);c.textContent=`Resolved Config`,c.style.marginTop=`8px`,o.appendChild(c),s=Q(`div`,`pce-preview-stub`),s.textContent=JSON.stringify(n,null,2),o.appendChild(s);let u=Q(`div`,`pce-preview-note`);u.textContent=`Live PDF preview not yet wired — see admin-client integration.`,o.appendChild(u)}function l(){s&&(s.textContent=JSON.stringify(n,null,2)),t.onChange?.(ZK(n))}return c(),e.appendChild(i),{destroy:()=>{i.parentNode&&i.parentNode.removeChild(i)},getConfig:()=>ZK(n),setConfig:e=>{Object.assign(n,XK(IK,e)),c()}}}function RK(e,t,n){let{section:r,body:i}=qK(`Page`);i.appendChild(UK(`Size`,PK,e.page?.pageSize??`a4`,t,t=>{YK(e,`page`).pageSize=t,n()})),i.appendChild(UK(`Orientation`,FK,e.page?.orientation??`auto`,t,t=>{YK(e,`page`).orientation=t,n()}));let a=Q(`div`,`pce-field pce-field-full`);a.appendChild(JK(`Margins (mm)`));let o=Q(`div`);return o.style.display=`grid`,o.style.gridTemplateColumns=`repeat(4, 1fr)`,o.style.gap=`6px`,[`top`,`right`,`bottom`,`left`].forEach(r=>{o.appendChild(GK(r,e.page?.margins?.[r]??10,t,t=>{let i=YK(YK(e,`page`),`margins`);i[r]=t,n()}))}),a.appendChild(o),i.appendChild(a),r}function zK(e,t,n){let{section:r,body:i}=qK(`Header`);return i.appendChild(UK(`Layout`,MK,e.header?.layout??`itf`,t,t=>{YK(e,`header`).layout=t,n()})),i.appendChild(WK(`Tournament name`,e.header?.tournamentName??``,t,t=>{YK(e,`header`).tournamentName=t,n()})),i.appendChild(WK(`Subtitle`,e.header?.subtitle??``,t,t=>{YK(e,`header`).subtitle=t||void 0,n()})),r}function BK(e,t,n){let{section:r,body:i}=qK(`Footer`);return i.appendChild(UK(`Layout`,NK,e.footer?.layout??`standard`,t,t=>{YK(e,`footer`).layout=t,n()})),i.appendChild(KK(`Show timestamp`,e.footer?.showTimestamp??!0,t,t=>{YK(e,`footer`).showTimestamp=t,n()})),i.appendChild(KK(`Show page numbers`,e.footer?.showPageNumbers??!0,t,t=>{YK(e,`footer`).showPageNumbers=t,n()})),r}function VK(e,t,n,r){let{section:i,body:a}=qK(`Content — ${n}`);if(n===`draw`){let n=YK(YK(e,`content`),`draw`);a.appendChild(KK(`Include seedings`,!!n.includeSeedings,t,e=>{n.includeSeedings=e,r()})),a.appendChild(KK(`Include scores`,!!n.includeScores,t,e=>{n.includeScores=e,r()})),a.appendChild(KK(`Show byes`,!!n.showByes,t,e=>{n.showByes=e,r()})),a.appendChild(KK(`Show draw positions`,!!n.showDrawPositions,t,e=>{n.showDrawPositions=e,r()}))}else if(n===`schedule`){let n=YK(YK(e,`content`),`schedule`);a.appendChild(UK(`Cell style`,[`detailed`,`compact`],n.cellStyle??`detailed`,t,e=>{n.cellStyle=e,r()})),a.appendChild(KK(`Show match numbers`,!!n.showMatchNumbers,t,e=>{n.showMatchNumbers=e,r()})),a.appendChild(WK(`Alert banner`,n.alertBanner??``,t,e=>{n.alertBanner=e||void 0,r()}))}else{let e=Q(`div`,`pce-field pce-field-full`),t=Q(`div`,`pce-preview-note`);t.textContent=`Content options for "${n}" not yet implemented.`,e.appendChild(t),a.appendChild(e)}return i}function HK(e){let t=Q(`div`,`pce-actions`),n=Q(`button`,`pce-button pce-button-primary`);return n.type=`button`,n.textContent=`Save`,n.addEventListener(`click`,e),t.appendChild(n),t}function UK(e,t,n,r,i){let a=Q(`div`,`pce-field`);a.appendChild(JK(e));let o=Q(`select`,`pce-select`);return o.disabled=r,t.forEach(e=>{let t=document.createElement(`option`);t.value=e,t.textContent=e,e===n&&(t.selected=!0),o.appendChild(t)}),o.addEventListener(`change`,()=>i(o.value)),a.appendChild(o),a}function WK(e,t,n,r){let i=Q(`div`,`pce-field`);i.appendChild(JK(e));let a=Q(`input`,`pce-input`);return a.type=`text`,a.value=t,a.disabled=n,a.addEventListener(`input`,()=>r(a.value)),i.appendChild(a),i}function GK(e,t,n,r){let i=Q(`div`,`pce-field`);i.appendChild(JK(e));let a=Q(`input`,`pce-input`);return a.type=`number`,a.value=String(t),a.disabled=n,a.addEventListener(`input`,()=>{let e=parseFloat(a.value);Number.isNaN(e)||r(e)}),i.appendChild(a),i}function KK(e,t,n,r){let i=Q(`div`,`pce-field pce-checkbox-row pce-field-full`),a=Q(`input`);a.type=`checkbox`,a.checked=t,a.disabled=n,a.addEventListener(`change`,()=>r(a.checked)),i.appendChild(a);let o=JK(e);return o.style.fontSize=`13px`,o.style.color=`var(--chc-text-primary, #222)`,i.appendChild(o),i}function qK(e){let t=Q(`div`,`pce-section`),n=Q(`div`,`pce-section-header`);n.textContent=e;let r=Q(`div`,`pce-section-body`);return t.appendChild(n),t.appendChild(r),{section:t,body:r}}function Q(e,t){let n=document.createElement(e);return t&&(n.className=t),n}function JK(e){let t=Q(`label`,`pce-field-label`);return t.textContent=e,t}function YK(e,t){return(e[t]===void 0||e[t]===null)&&(e[t]={}),e[t]}function XK(e,t){return{name:t.name??e.name,page:{...e.page,...t.page,margins:{...e.page?.margins,...t.page?.margins}},header:{...e.header,...t.header},footer:{...e.footer,...t.footer},content:{...e.content,...t.content}}}function ZK(e){return JSON.parse(JSON.stringify(e))}var QK=`chc-scorecard-side-score--winner`;function $K({matchUp:e,composition:t,eventHandlers:n,swapSides:r}){let i=document.createElement(`div`);i.className=`chc-scorecard`;let a=r?2:1,o=r?1:2,s=cq(e,a)||``,c=cq(e,o)||``,l=r?aq(e.winningSide):e.winningSide,u=eq({side1Name:s,side2Name:c,sets:r?oq(e.score?.sets):e.score?.sets,winningSide:l,side1Id:`chc-sc-side1`,side2Id:`chc-sc-side2`});i.appendChild(u);let d=e.tieFormat?.collectionDefinitions?.slice().sort((e,t)=>(e.collectionOrder||0)-(t.collectionOrder||0))||[];for(let a of d){let o=iq({collectionDefinition:a,collectionMatchUps:(e.tieMatchUps||[]).filter(e=>e.collectionId===a.collectionId).sort((e,t)=>(e.collectionPosition||0)-(t.collectionPosition||0)),composition:t,eventHandlers:n,swapSides:r});i.appendChild(o)}return i}function eq({side1Name:e,side2Name:t,sets:n,winningSide:r,side1Id:i,side2Id:a}){let o=document.createElement(`div`);o.className=`chc-scorecard-header`;let s=document.createElement(`div`);s.className=`chc-scorecard-header-body`;let c=nq(e,`end`),l=nq(t,`start`),u=rq(n,1,r,i),d=rq(n,2,r,a),f=document.createElement(`div`);f.className=`chc-scorecard-score-box`;let p=document.createElement(`div`);p.className=`chc-scorecard-score-flex`;let m=document.createElement(`div`);return m.className=`chc-scorecard-vs`,m.textContent=`vs`,p.appendChild(u),p.appendChild(m),p.appendChild(d),f.appendChild(p),s.appendChild(c),s.appendChild(f),s.appendChild(l),o.appendChild(s),o}function tq(e,t=`chc-sc-side1`,n=`chc-sc-side2`,r){let i=e?.score?.sets?.[0];if(!i)return;let a=document.getElementById(t),o=document.getElementById(n);if(!a||!o)return;a.classList.remove(QK),o.classList.remove(QK);let s=r?`side2Score`:`side1Score`,c=r?`side1Score`:`side2Score`;a.textContent=String(i[s]??0),o.textContent=String(i[c]??0);let l=r?aq(e.winningSide):e.winningSide;l===1&&a.classList.add(QK),l===2&&o.classList.add(QK)}function nq(e,t){let n=document.createElement(`div`);n.className=`chc-scorecard-side chc-scorecard-side--${t}`;let r=document.createElement(`div`);return r.className=`chc-scorecard-side-name`,r.textContent=e,n.appendChild(r),n}function rq(e,t,n,r){let i=e?.[0]?.[`side${t}Score`]??0,a=document.createElement(`span`);return a.className=`chc-scorecard-side-score`,r&&(a.id=r),t===1?a.style.paddingLeft=`1rem`:a.style.paddingRight=`1rem`,t===n&&a.classList.add(QK),a.textContent=String(i),a}function iq({collectionDefinition:e,collectionMatchUps:t,composition:n,eventHandlers:r,swapSides:i}){let a=document.createElement(`div`);a.className=`chc-scorecard-panel`;let o=document.createElement(`div`);o.className=`chc-scorecard-panel-header`;let s=document.createElement(`div`);s.className=`chc-scorecard-panel-name`,s.textContent=e.collectionName||`Collection`;let c=document.createElement(`div`);c.className=`chc-scorecard-panel-meta`;let l=(e.matchUpType||``).toUpperCase(),u=document.createElement(`span`);u.className=`chc-scorecard-type-badge chc-scorecard-type-badge--${l===`DOUBLES`?`doubles`:`singles`}`,u.textContent=l===`DOUBLES`?`D`:`S`;let d=document.createElement(`span`);d.className=`chc-scorecard-count-badge`,d.textContent=String(t.length),c.appendChild(u),c.appendChild(d),o.appendChild(s),o.appendChild(c),a.appendChild(o);let f=document.createElement(`div`);f.className=`chc-scorecard-grid`;for(let e of t){let t=ei({matchUp:i?sq(e):e,isLucky:!0,eventHandlers:r,composition:n});t.classList.add(`chc-scorecard-card`),f.appendChild(t)}return a.appendChild(f),a}function aq(e){if(e===1)return 2;if(e===2)return 1}function oq(e){if(e)return e.map(e=>({...e,side1Score:e.side2Score,side2Score:e.side1Score,side1TiebreakScore:e.side2TiebreakScore,side2TiebreakScore:e.side1TiebreakScore}))}function sq(e){let t=e.sides?.map(e=>({...e,sideNumber:e.sideNumber===1?2:1}));return{...e,sides:t,score:e.score?{...e.score,sets:oq(e.score.sets)}:e.score,winningSide:aq(e.winningSide)}}function cq(e,t){return e.sides?.find(e=>e.sideNumber===t)?.participant?.participantName}function lq(e){let{matchUpId:t,manager:n,baseMatchUp:r,onUpdate:i,showSituation:a}=e,o=document.createElement(`div`);o.className=`chc-inline-scoring-footer`;let s=document.createElement(`div`);s.className=`chc-inline-scoring-buttons`;let c=(e,t)=>{let n=document.createElement(`button`);return n.textContent=e,n.className=`chc-inline-scoring-btn ${t}`,n},l=c(`Undo`,`chc-is-undo`),u=c(`Redo`,`chc-is-redo`),d=c(`Clear`,`chc-is-clear`),f=c(`Submit`,`chc-is-submit`),p;a&&(p=document.createElement(`span`),p.className=`chc-inline-scoring-situation`),l.onclick=e=>{e.stopPropagation();let a=n.undo(t,r);a&&(i(a),m())},u.onclick=e=>{e.stopPropagation();let a=n.redo(t,r);a&&(i(a),m())},d.onclick=e=>{e.stopPropagation();let a=n.reset(t,r);a&&(i(a),m())},f.onclick=e=>{e.stopPropagation();let i=n.get(t);if(i){let e=n.getMatchUp(t,r);n.callbacks?.onSubmit?.({matchUpId:t,matchUp:e,engine:i.engine})}},s.append(l,u,d,f),o.appendChild(s),p&&o.appendChild(p);function m(){let e=n.canUndo(t),r=n.canRedo(t),i=n.isComplete(t);if(l.disabled=!e,u.disabled=!r,d.disabled=!e&&!r,p){let e=n.getSituation(t);if(e&&!i){let t=[e.isTiebreak&&`TB`,e.isBreakPoint&&`Break`,e.isGamePoint&&`Game`,e.isSetPoint&&`Set`,e.isMatchPoint&&`Match`].filter(Boolean);p.textContent=t.length?t.join(` • `):``}else p.textContent=i?`Complete`:``}}return m(),{element:o,update:m}}var uq=`chc-iss-score-cell`;function dq(e){if(!e?.matchUpId)throw Error(`buildInteractiveScoringShell: matchUpId is required`);if(!e?.matchUpFormat)throw Error(`buildInteractiveScoringShell: matchUpFormat is required`);let t=e.initialMatchUp??fq(e),n=new Set,r=new gs({onScoreChange:({matchUp:e})=>{a(e,!1)},onMatchComplete:({winningSide:n})=>{a(r.getMatchUp(e.matchUpId,t),!0,n)}});r.getOrCreate(e.matchUpId,e.matchUpFormat,t);let i=document.createElement(`div`);i.className=`chc-interactive-scoring-shell`,i.dataset.matchupId=e.matchUpId,i.dataset.tournamentId=e.tournamentId,l();function a(t,r,i){let a={matchUpId:e.matchUpId,matchUp:t,isComplete:r,winningSide:i??t.winningSide},o=new CustomEvent(`stateChanged`,{detail:a});n.forEach(e=>{try{e(o)}catch(e){console.warn(`[interactive-scoring] listener threw`,e)}})}function o(n){r.isComplete(e.matchUpId)||(r.addPoint(e.matchUpId,n,t),l())}function s(){r.canUndo(e.matchUpId)&&(r.undo(e.matchUpId,t),l(),a(r.getMatchUp(e.matchUpId,t),r.isComplete(e.matchUpId)))}async function c(){e.confirmReset&&!await e.confirmReset()||(r.reset(e.matchUpId,t),l(),a(r.getMatchUp(e.matchUpId,t),!1))}function l(){i.innerHTML=``,i.append(pq(e),mq(r,e,t),hq(r,e,o),gq(r,e,s,c))}return{element:i,getState:()=>r.getMatchUp(e.matchUpId,t),reset:()=>{r.reset(e.matchUpId,t),l(),a(r.getMatchUp(e.matchUpId,t),!1)},destroy:()=>{n.clear(),r.remove(e.matchUpId),i.innerHTML=``},addEventListener:(e,t)=>{e===`stateChanged`&&n.add(t)},removeEventListener:(e,t)=>{e===`stateChanged`&&n.delete(t)}}}function fq(e){return{matchUpId:e.matchUpId,tournamentId:e.tournamentId,matchUpFormat:e.matchUpFormat,matchUpStatus:`TO_BE_PLAYED`,score:{sets:[]},sides:[{sideNumber:1,participant:{participantName:e.side1Name}},{sideNumber:2,participant:{participantName:e.side2Name}}]}}function pq(e){let t=document.createElement(`div`);t.className=`chc-iss-header`;let n=document.createElement(`div`);n.className=`chc-iss-header-side chc-iss-header-side1`,n.textContent=e.side1Name||`Side 1`;let r=document.createElement(`div`);r.className=`chc-iss-header-vs`,r.textContent=`vs`;let i=document.createElement(`div`);return i.className=`chc-iss-header-side chc-iss-header-side2`,i.textContent=e.side2Name||`Side 2`,t.append(n,r,i),t}function mq(e,t,n){let r=document.createElement(`div`);r.className=`chc-iss-score-display`;let i=e.getMatchUp(t.matchUpId,n),a=i.score?.sets??[],o=document.createElement(`div`);o.className=`chc-iss-score-grid`,o.style.setProperty(`--sets`,String(Math.max(a.length,1)));let s=document.createElement(`div`);s.className=`chc-iss-score-row chc-iss-score-row-side1`;let c=document.createElement(`div`);c.className=`chc-iss-score-row chc-iss-score-row-side2`;for(let e of a){let t=document.createElement(`div`);t.className=uq,t.textContent=String(e.side1Score??0),e.winningSide===1&&t.classList.add(`chc-iss-score-cell-won`),s.append(t);let n=document.createElement(`div`);n.className=uq,n.textContent=String(e.side2Score??0),e.winningSide===2&&n.classList.add(`chc-iss-score-cell-won`),c.append(n)}if(a.length===0){let e=document.createElement(`div`);e.className=uq,e.textContent=`0`,s.append(e);let t=document.createElement(`div`);t.className=uq,t.textContent=`0`,c.append(t)}o.append(s,c),r.append(o);let l=a.at(-1);if(l&&!l.winningSide&&l.side1PointScore!=null){let e=document.createElement(`div`);e.className=`chc-iss-game-score`;let t=document.createElement(`span`);t.className=`chc-iss-game-score-side1`,t.textContent=String(l.side1PointScore);let n=document.createElement(`span`);n.className=`chc-iss-game-score-sep`,n.textContent=` — `;let i=document.createElement(`span`);i.className=`chc-iss-game-score-side2`,i.textContent=String(l.side2PointScore),e.append(t,n,i),r.append(e)}if(e.isComplete(t.matchUpId)){let e=document.createElement(`div`);e.className=`chc-iss-match-complete`,e.textContent=`${(i.winningSide===1?t.side1Name:t.side2Name)||`Match`} wins`,r.append(e)}return r}function hq(e,t,n){let r=document.createElement(`div`);r.className=`chc-iss-point-buttons`;let i=e.isComplete(t.matchUpId),a=document.createElement(`button`);a.type=`button`,a.className=`chc-iss-point-button chc-iss-point-button-side1`,a.disabled=i,a.setAttribute(`aria-label`,`${t.side1Name} won the point`);let o=document.createElement(`span`);o.className=`chc-iss-point-button-label`,o.textContent=t.side1Name||`Side 1`;let s=document.createElement(`span`);s.className=`chc-iss-point-button-hint`,s.textContent=`won the point`,a.append(o,s),a.addEventListener(`click`,()=>n(0));let c=document.createElement(`button`);c.type=`button`,c.className=`chc-iss-point-button chc-iss-point-button-side2`,c.disabled=i,c.setAttribute(`aria-label`,`${t.side2Name} won the point`);let l=document.createElement(`span`);l.className=`chc-iss-point-button-label`,l.textContent=t.side2Name||`Side 2`;let u=document.createElement(`span`);return u.className=`chc-iss-point-button-hint`,u.textContent=`won the point`,c.append(l,u),c.addEventListener(`click`,()=>n(1)),r.append(a,c),r}function gq(e,t,n,r){let i=document.createElement(`div`);i.className=`chc-iss-control-bar`;let a=document.createElement(`button`);a.type=`button`,a.className=`chc-iss-control-button chc-iss-control-undo`,a.textContent=`Undo`,a.disabled=!e.canUndo(t.matchUpId),a.addEventListener(`click`,n);let o=document.createElement(`button`);return o.type=`button`,o.className=`chc-iss-control-button chc-iss-control-reset`,o.textContent=`Reset`,o.addEventListener(`click`,()=>{r()}),i.append(a,o),i}function _q(){return{policyName:`New Ranking Policy`,policyVersion:`1.0`,awardProfiles:[{profileName:`Default`,finishingPositionRanges:{1:100,2:70,4:50,8:30,16:15,32:8}}],requireWinForPoints:!0,doublesAttribution:`fullToEach`}}function $(e){return structuredClone(e)}var vq=class{constructor(e){this.listeners=new Set,this.config=e;let t=$(e.initialPolicy??_q()),n=t.awardProfiles?.length??0;this.state={draft:t,expandedSections:new Set(n>5?[`awardProfiles`]:[`metadata`,`awardProfiles`,`qualityWinProfiles`,`aggregationRules`]),expandedProfiles:new Set(n<=5?Array.from({length:n},(e,t)=>t):[]),profileFilter:``,dirty:!1,readonly:e.readonly??!1}}getState(){return this.state}getData(){return $(this.state.draft)}setData(e){let t=e.awardProfiles?.length??0;this.state={...this.state,draft:$(e),expandedProfiles:new Set(t<=5?Array.from({length:t},(e,t)=>t):[]),profileFilter:``,dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}toggleProfile(e){let t=new Set(this.state.expandedProfiles);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedProfiles:t},this.emit()}setProfileFilter(e){this.state={...this.state,profileFilter:e},this.emit()}setPolicyName(e){let t=$(this.state.draft);t.policyName=e,this.commitDraft(t)}setPolicyVersion(e){let t=$(this.state.draft);t.policyVersion=e,this.commitDraft(t)}setValidDateRange(e,t){let n=$(this.state.draft);n.validDateRange||={},n.validDateRange[e]=t||void 0,this.commitDraft(n)}setGlobalFlag(e,t){let n=$(this.state.draft);n[e]=t,this.commitDraft(n)}setDoublesAttribution(e){let t=$(this.state.draft);t.doublesAttribution=e||void 0,this.commitDraft(t)}setCategoryResolution(e){let t=$(this.state.draft);t.categoryResolution=e||void 0,this.commitDraft(t)}addProfile(){let e=$(this.state.draft);e.awardProfiles||=[],e.awardProfiles.push({profileName:`Profile ${e.awardProfiles.length+1}`,finishingPositionRanges:{1:100,2:70,4:50,8:30}});let t=new Set(this.state.expandedProfiles);t.add(e.awardProfiles.length-1),this.state={...this.state,expandedProfiles:t},this.commitDraft(e)}removeProfile(e){let t=$(this.state.draft);if(!t.awardProfiles||e<0||e>=t.awardProfiles.length)return;t.awardProfiles.splice(e,1);let n=new Set;for(let t of this.state.expandedProfiles)t<e?n.add(t):t>e&&n.add(t-1);this.state={...this.state,expandedProfiles:n},this.commitDraft(t)}duplicateProfile(e){let t=$(this.state.draft);if(!t.awardProfiles||e<0||e>=t.awardProfiles.length)return;let n=$(t.awardProfiles[e]);n.profileName=`${n.profileName??`Profile`} (Copy)`,t.awardProfiles.splice(e+1,0,n);let r=new Set;for(let t of this.state.expandedProfiles)t<=e?r.add(t):r.add(t+1);r.add(e+1),this.state={...this.state,expandedProfiles:r},this.commitDraft(t)}moveProfile(e,t){let n=$(this.state.draft);if(!n.awardProfiles||e<0||e>=n.awardProfiles.length||t<0||t>=n.awardProfiles.length)return;let[r]=n.awardProfiles.splice(e,1);n.awardProfiles.splice(t,0,r),this.commitDraft(n)}setProfileName(e,t){let n=$(this.state.draft);n.awardProfiles?.[e]&&(n.awardProfiles[e].profileName=t,this.commitDraft(n))}setProfileFlag(e,t,n){let r=$(this.state.draft);r.awardProfiles?.[e]&&(n===void 0?delete r.awardProfiles[e][t]:r.awardProfiles[e][t]=n,this.commitDraft(r))}setFlatPositionPoints(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e];i&&(i.finishingPositionRanges||={},i.finishingPositionRanges[t]=n,this.commitDraft(r))}addPositionRow(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r&&(r.finishingPositionRanges||={},r.finishingPositionRanges[t]===void 0&&(r.finishingPositionRanges[t]=0,this.commitDraft(n)))}removePositionRow(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r?.finishingPositionRanges&&(delete r.finishingPositionRanges[t],this.commitDraft(n))}setPointsPerWin(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r&&(t===void 0?delete r.pointsPerWin:r.pointsPerWin=t,this.commitDraft(n))}addBonusPoint(e){let t=$(this.state.draft),n=t.awardProfiles?.[e];n&&(n.bonusPoints||=[],n.bonusPoints.push({finishingPositions:[1],value:0}),this.commitDraft(t))}removeBonusPoint(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r?.bonusPoints&&(r.bonusPoints.splice(t,1),r.bonusPoints.length||delete r.bonusPoints,this.commitDraft(n))}setBonusPointPositions(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e]?.bonusPoints?.[t];i&&(i.finishingPositions=n,this.commitDraft(r))}setBonusPointValue(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e]?.bonusPoints?.[t];i&&(i.value=n,this.commitDraft(r))}setLevelPositionPoints(e,t,n,r){let i=$(this.state.draft),a=i.awardProfiles?.[e];if(!a)return;a.finishingPositionRanges||={};let o=a.finishingPositionRanges[t];o&&typeof o==`object`&&o.level&&(o.level[n]=r),this.commitDraft(i)}addLevel(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];if(r?.finishingPositionRanges){for(let e of Object.keys(r.finishingPositionRanges)){let n=r.finishingPositionRanges[e];n&&typeof n==`object`&&n.level&&n.level[t]===void 0&&(n.level[t]=0)}r.levels&&!r.levels.includes(t)&&(r.levels.push(t),r.levels.sort((e,t)=>e-t)),this.commitDraft(n)}}removeLevel(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];if(r?.finishingPositionRanges){for(let e of Object.keys(r.finishingPositionRanges)){let n=r.finishingPositionRanges[e];n&&typeof n==`object`&&n.level&&delete n.level[t]}r.levels&&=r.levels.filter(e=>e!==t),this.commitDraft(n)}}setProfileScope(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e];i&&(n.length?i[t]=n:delete i[t],this.commitDraft(r))}setProfileField(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e];i&&(n===void 0||n===``?delete i[t]:i[t]=n,this.commitDraft(r))}addQualityWinProfile(){let e=$(this.state.draft);e.qualityWinProfiles||=[],e.qualityWinProfiles.push({rankingScaleName:`New Profile`,rankingRanges:[{rankRange:[1,10],value:10}]}),this.commitDraft(e)}removeQualityWinProfile(e){let t=$(this.state.draft);t.qualityWinProfiles&&(t.qualityWinProfiles.splice(e,1),t.qualityWinProfiles.length||delete t.qualityWinProfiles,this.commitDraft(t))}setQualityWinField(e,t,n){let r=$(this.state.draft),i=r.qualityWinProfiles?.[e];i&&(n===void 0||n===``?delete i[t]:i[t]=n,this.commitDraft(r))}addQualityWinRange(e){let t=$(this.state.draft),n=t.qualityWinProfiles?.[e];if(!n)return;let r=n.rankingRanges.at(-1),i=r?r.rankRange[1]+1:1;n.rankingRanges.push({rankRange:[i,i+9],value:0}),this.commitDraft(t)}removeQualityWinRange(e,t){let n=$(this.state.draft),r=n.qualityWinProfiles?.[e];r&&(r.rankingRanges.splice(t,1),this.commitDraft(n))}setQualityWinRange(e,t,n,r){let i=$(this.state.draft),a=i.qualityWinProfiles?.[e]?.rankingRanges?.[t];a&&(n===`rankRange`?a.rankRange=r:a.value=r,this.commitDraft(i))}setAggregationField(e,t){let n=$(this.state.draft);n.aggregationRules||={},t===void 0||t===``?delete n.aggregationRules[e]:n.aggregationRules[e]=t,this.commitDraft(n)}addTiebreakCriterion(e){let t=$(this.state.draft);t.aggregationRules||={},t.aggregationRules.tiebreakCriteria||(t.aggregationRules.tiebreakCriteria=[]),t.aggregationRules.tiebreakCriteria.push(e),this.commitDraft(t)}removeTiebreakCriterion(e){let t=$(this.state.draft);t.aggregationRules?.tiebreakCriteria&&(t.aggregationRules.tiebreakCriteria.splice(e,1),t.aggregationRules.tiebreakCriteria.length||delete t.aggregationRules.tiebreakCriteria,this.commitDraft(t))}addCountingBucket(){let e=$(this.state.draft);e.aggregationRules||={},e.aggregationRules.countingBuckets||(e.aggregationRules.countingBuckets=[]),e.aggregationRules.countingBuckets.push({bucketName:`New Bucket`}),this.commitDraft(e)}removeCountingBucket(e){let t=$(this.state.draft);t.aggregationRules?.countingBuckets&&(t.aggregationRules.countingBuckets.splice(e,1),t.aggregationRules.countingBuckets.length||delete t.aggregationRules.countingBuckets,this.commitDraft(t))}setCountingBucketField(e,t,n){let r=$(this.state.draft),i=r.aggregationRules?.countingBuckets?.[e];i&&(n===void 0||n===``?delete i[t]:i[t]=n,this.commitDraft(r))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.($(e))}emit(){for(let e of this.listeners)e(this.state)}},yq=()=>`re-section`,bq=()=>`re-section-header`,xq=()=>`re-section-chevron`,Sq=()=>`re-section-count`,Cq=()=>`re-section-body`,wq=()=>`re-field-row`,Tq=()=>`re-field-label`,Eq=()=>`re-field-input re-field-input--text`,Dq=()=>`re-field-input re-field-input--number`,Oq=()=>`re-field-input re-field-input--date`,kq=()=>`re-field-select`,Aq=()=>`re-checkbox-row`,jq=()=>`re-points-input`,Mq=()=>`re-profile-card`,Nq=()=>`re-profile-header`,Pq=()=>`re-profile-name-input`,Fq=()=>`re-profile-body`,Iq=()=>`re-profile-actions`,Lq=()=>`re-icon-btn`,Rq=()=>`re-icon-btn re-icon-btn--danger`,zq=()=>`re-empty`,Bq=()=>`re-editor`,Vq=[`totalPoints`,`bestResult`,`headToHead`,`numberOfWins`,`recentResults`,`drawSize`,`numberOfResults`];function Hq(e){let t=document.createElement(`div`),n=``;function r(t,n,r,i,a,o){let s=document.createElement(`div`);s.className=wq();let c=document.createElement(`div`);if(c.className=Tq(),c.textContent=n,s.appendChild(c),o){let e=document.createElement(`span`);e.style.cssText=`font-size:0.85rem;color:var(--sp-text)`,e.textContent=String(i),s.appendChild(e)}else if(r===`select`){let n=document.createElement(`select`);n.className=kq();let r=document.createElement(`option`);r.value=``,r.textContent=`(none)`,n.appendChild(r);for(let e of a??[]){let t=document.createElement(`option`);t.value=e,t.textContent=e,n.appendChild(t)}n.value=i??``,n.addEventListener(`change`,()=>e.setAggregationField(t,n.value||void 0)),s.appendChild(n)}else{let n=document.createElement(`input`);n.type=`number`,n.className=Dq(),n.value=i===void 0?``:String(i),n.placeholder=`—`,n.addEventListener(`change`,()=>{let r=n.value.trim();e.setAggregationField(t,r?Number.parseInt(r,10):void 0)}),s.appendChild(n)}return s}function i(n,r){let i=document.createElement(`div`);if(i.style.cssText=`font-weight:600;font-size:0.8rem;margin:0.5rem 0 0.3rem;color:var(--sp-text)`,i.textContent=`Tiebreak Order`,t.appendChild(i),n.length){let i=document.createElement(`ol`);i.style.cssText=`font-size:0.8rem;margin:0;padding-left:1.5rem;color:var(--sp-text)`;for(let t=0;t<n.length;t++){let a=document.createElement(`li`);a.style.cssText=`display:flex;align-items:center;gap:6px;margin-bottom:2px`;let o=document.createElement(`span`);if(o.textContent=n[t],a.appendChild(o),!r){let n=document.createElement(`span`);n.className=Rq(),n.textContent=`×`,n.style.cursor=`pointer`,n.addEventListener(`click`,()=>e.removeTiebreakCriterion(t)),a.appendChild(n)}i.appendChild(a)}t.appendChild(i)}else if(r){let e=document.createElement(`div`);e.className=zq(),e.textContent=`No tiebreak criteria`,t.appendChild(e)}if(!r){let r=document.createElement(`div`);r.style.cssText=`display:flex;align-items:center;gap:4px;margin-top:4px`;let i=document.createElement(`select`);i.className=kq(),i.style.fontSize=`0.75rem`;let a=new Set(n),o=Vq.filter(e=>!a.has(e));for(let e of o){let t=document.createElement(`option`);t.value=e,t.textContent=e,i.appendChild(t)}let s=document.createElement(`button`);s.className=`sp-btn sp-btn--sm sp-btn--outline`,s.textContent=`+ Add`,s.addEventListener(`click`,()=>{i.value&&e.addTiebreakCriterion(i.value)}),o.length&&(r.appendChild(i),r.appendChild(s),t.appendChild(r))}}function a(t,n,r){let i=document.createElement(`div`);i.style.cssText=`border:1px solid var(--sp-border);border-radius:8px;padding:0.4rem;margin-bottom:0.4rem;font-size:0.8rem`;let a=document.createElement(`div`);if(a.style.cssText=`display:flex;align-items:center;gap:6px;margin-bottom:0.2rem`,r){let e=document.createElement(`span`);e.style.cssText=`font-weight:600;color:var(--sp-text)`,e.textContent=t.bucketName||`Bucket`,a.appendChild(e)}else{let r=document.createElement(`input`);r.type=`text`,r.className=`re-field-input re-field-input--text`,r.style.cssText=`width:120px;font-size:0.75rem;font-weight:600`,r.value=t.bucketName||``,r.placeholder=`Bucket name`,r.addEventListener(`change`,()=>e.setCountingBucketField(n,`bucketName`,r.value)),a.appendChild(r);let i=document.createElement(`div`);i.style.flexGrow=`1`,a.appendChild(i);let o=document.createElement(`span`);o.className=Rq(),o.textContent=`✕`,o.style.cursor=`pointer`,o.addEventListener(`click`,()=>e.removeCountingBucket(n)),a.appendChild(o)}i.appendChild(a);let o=[];if(t.eventTypes?.length&&o.push(`Events: ${t.eventTypes.join(`, `)}`),t.bestOfCount!==void 0&&o.push(`Best of: ${t.bestOfCount}`),t.levels?.length&&o.push(`Levels: ${t.levels.join(`, `)}`),t.minResults!==void 0&&o.push(`Min: ${t.minResults}`),r&&o.length){let e=document.createElement(`div`);e.style.cssText=`color:var(--sp-muted);font-size:0.75rem`,e.textContent=o.join(` | `),i.appendChild(e)}else if(!r){let r=document.createElement(`div`);r.className=wq();let a=document.createElement(`div`);a.className=Tq(),a.style.cssText=`min-width:70px;font-size:0.75rem`,a.textContent=`Best of`,r.appendChild(a);let o=document.createElement(`input`);o.type=`number`,o.className=Dq(),o.style.fontSize=`0.75rem`,o.value=t.bestOfCount===void 0?``:String(t.bestOfCount),o.addEventListener(`change`,()=>{let t=o.value.trim();e.setCountingBucketField(n,`bestOfCount`,t?Number.parseInt(t,10):void 0)}),r.appendChild(o),i.appendChild(r)}return i}function o(n){let o=n.draft.aggregationRules;if(t.innerHTML=``,!o&&n.readonly){let e=document.createElement(`div`);e.className=zq(),e.textContent=`No aggregation rules defined (all results summed)`,t.appendChild(e);return}let s=[[`rollingPeriodDays`,`Rolling period (days)`,`number`,o?.rollingPeriodDays],[`bestOfCount`,`Best of count`,`number`,o?.bestOfCount],[`minCountableResults`,`Min countable results`,`number`,o?.minCountableResults],[`decayFunction`,`Decay function`,`select`,o?.decayFunction,[`none`,`linear`,`exponential`,`step`]]];for(let[e,i,a,o,c]of s)o===void 0&&n.readonly||t.appendChild(r(e,i,a,o,c,n.readonly));let c=[[`separateByGender`,`Separate by gender`,o?.separateByGender],[`perCategory`,`Per category`,o?.perCategory]];for(let[r,i,a]of c){if(a===void 0&&n.readonly)continue;let o=document.createElement(`div`);o.className=Aq();let s=document.createElement(`input`);s.type=`checkbox`,s.checked=a??!1,s.disabled=n.readonly,s.addEventListener(`change`,()=>e.setAggregationField(r,s.checked));let c=document.createElement(`label`);c.textContent=i,o.appendChild(s),o.appendChild(c),t.appendChild(o)}i(o?.tiebreakCriteria??[],n.readonly);let l=o?.countingBuckets??[];if(l.length||!n.readonly){let r=document.createElement(`div`);r.style.cssText=`font-weight:600;font-size:0.8rem;margin:0.5rem 0 0.3rem;color:var(--sp-text)`,r.textContent=`Counting Buckets`,t.appendChild(r);for(let e=0;e<l.length;e++)t.appendChild(a(l[e],e,n.readonly));if(!n.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add Bucket`,n.addEventListener(`click`,()=>e.addCountingBucket()),t.appendChild(n)}}}function s(e){let t=JSON.stringify(e.draft.aggregationRules??{});t!==n&&(n=t,o(e))}return{element:t,update:s}}function Uq(e){let t=document.createElement(`div`),n=``;function r(t,n,r){let i=document.createElement(`div`);if(i.style.cssText=`display:flex;align-items:center;gap:0.5rem;margin-bottom:0.4rem`,r){let e=document.createElement(`span`);e.style.cssText=`font-weight:600;font-size:0.85rem;color:var(--sp-text)`,e.textContent=n.rankingScaleName,i.appendChild(e)}else{let r=document.createElement(`input`);r.type=`text`,r.className=Eq(),r.style.cssText=`width:150px;font-weight:600`,r.value=n.rankingScaleName,r.addEventListener(`change`,()=>e.setQualityWinField(t,`rankingScaleName`,r.value)),i.appendChild(r);let a=document.createElement(`div`);a.style.flexGrow=`1`,i.appendChild(a);let o=document.createElement(`span`);o.className=Rq(),o.textContent=`✕`,o.title=`Delete profile`,o.style.cursor=`pointer`,o.addEventListener(`click`,()=>e.removeQualityWinProfile(t)),i.appendChild(o)}return i}let i=`text-align:right;padding:2px 4px`,a=`text-align:right;width:4rem`;function o(t,n,r,a){let o=document.createElement(`tr`);if(a)for(let e of[r.rankRange[0],r.rankRange[1],r.value]){let t=document.createElement(`td`);t.style.cssText=`text-align:right;font-variant-numeric:tabular-nums;padding:2px 4px`,t.textContent=e.toLocaleString(),o.appendChild(t)}else{let a=document.createElement(`td`);a.style.cssText=i,a.appendChild(Wq(r.rankRange[0],i=>{e.setQualityWinRange(t,n,`rankRange`,[i,r.rankRange[1]])})),o.appendChild(a);let s=document.createElement(`td`);s.style.cssText=i,s.appendChild(Wq(r.rankRange[1],i=>{e.setQualityWinRange(t,n,`rankRange`,[r.rankRange[0],i])})),o.appendChild(s);let c=document.createElement(`td`);c.style.cssText=i,c.appendChild(Wq(r.value,r=>{e.setQualityWinRange(t,n,`value`,r)})),o.appendChild(c);let l=document.createElement(`td`);l.style.cssText=`text-align:center;padding:2px`;let u=document.createElement(`span`);u.className=Rq(),u.textContent=`×`,u.style.cursor=`pointer`,u.addEventListener(`click`,()=>e.removeQualityWinRange(t,n)),l.appendChild(u),o.appendChild(l)}return o}function s(e,t,n){let r=document.createElement(`table`);r.style.cssText=`font-size:0.8rem;margin-bottom:0.3rem;border-collapse:collapse`;let i=document.createElement(`thead`),s=document.createElement(`tr`);for(let[e,t]of[[`From`,a],[`To`,a],[`Bonus`,a]]){let n=document.createElement(`th`);n.textContent=e,n.style.cssText=t+`;padding:2px 4px`,s.appendChild(n)}if(!n){let e=document.createElement(`th`);e.style.cssText=`width:2rem;padding:2px`,s.appendChild(e)}i.appendChild(s),r.appendChild(i);let c=document.createElement(`tbody`);for(let r=0;r<t.rankingRanges.length;r++)c.appendChild(o(e,r,t.rankingRanges[r],n));return r.appendChild(c),r}function c(t,n,r,i,a){let o=document.createElement(`div`);o.className=wq();let s=document.createElement(`div`);if(s.className=Tq(),s.style.minWidth=`100px`,s.style.fontSize=`0.75rem`,s.textContent=r,o.appendChild(s),a){let e=document.createElement(`span`);e.style.cssText=`font-size:0.75rem;color:var(--sp-muted)`,e.textContent=String(i),o.appendChild(e)}else{let r=document.createElement(`input`);r.type=typeof i==`number`?`number`:`text`,r.className=typeof i==`number`?Dq():Eq(),r.style.fontSize=`0.75rem`,r.value=i===void 0?``:String(i),r.addEventListener(`change`,()=>{let a=r.value.trim();typeof i==`number`||n===`maxBonusPerTournament`?e.setQualityWinField(t,n,a?Number.parseFloat(a):void 0):e.setQualityWinField(t,n,a||void 0)}),o.appendChild(r)}return o}function l(n){let i=n.draft.qualityWinProfiles;if(t.innerHTML=``,!i?.length){let r=document.createElement(`div`);if(r.className=zq(),r.textContent=`No quality win profiles defined`,t.appendChild(r),!n.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add Quality Win Profile`,n.addEventListener(`click`,()=>e.addQualityWinProfile()),t.appendChild(n)}return}for(let a=0;a<i.length;a++){let o=i[a],l=document.createElement(`div`);if(l.style.cssText=`border:1px solid var(--sp-border);border-radius:10px;padding:0.5rem;margin-bottom:0.5rem`,l.appendChild(r(a,o,n.readonly)),o.rankingRanges?.length&&(l.appendChild(s(a,o,n.readonly)),!n.readonly)){let t=document.createElement(`button`);t.className=`sp-btn sp-btn--sm sp-btn--outline`,t.textContent=`+ Range`,t.style.marginBottom=`0.3rem`,t.addEventListener(`click`,()=>e.addQualityWinRange(a)),l.appendChild(t)}let u=[[`maxBonusPerTournament`,`Max bonus/tournament`,o.maxBonusPerTournament],[`rankingSnapshot`,`Ranking snapshot`,o.rankingSnapshot]];for(let[e,t,r]of u)r===void 0&&n.readonly||l.appendChild(c(a,e,t,r,n.readonly));if(o.includeWalkovers!==void 0||!n.readonly){let t=document.createElement(`div`);t.className=Aq();let r=document.createElement(`input`);r.type=`checkbox`,r.checked=o.includeWalkovers??!1,r.disabled=n.readonly,r.addEventListener(`change`,()=>e.setQualityWinField(a,`includeWalkovers`,r.checked));let i=document.createElement(`label`);i.textContent=`Include walkovers`,i.style.fontSize=`0.75rem`,t.appendChild(r),t.appendChild(i),l.appendChild(t)}t.appendChild(l)}if(!n.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add Quality Win Profile`,n.addEventListener(`click`,()=>e.addQualityWinProfile()),t.appendChild(n)}}function u(e){let t=JSON.stringify(e.draft.qualityWinProfiles??[]);t!==n&&(n=t,l(e))}return{element:t,update:u}}function Wq(e,t){let n=document.createElement(`input`);return n.type=`number`,n.className=jq(),n.value=String(e),n.addEventListener(`change`,()=>{let e=Number.parseFloat(n.value);Number.isNaN(e)||t(e)}),n}function Gq(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=wq();let r=document.createElement(`div`);r.className=Tq(),r.textContent=`Name`;let i=document.createElement(`input`);i.type=`text`,i.className=Eq(),i.placeholder=`Policy name`,i.addEventListener(`change`,()=>e.setPolicyName(i.value)),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=wq();let o=document.createElement(`div`);o.className=Tq(),o.textContent=`Version`;let s=document.createElement(`input`);s.type=`text`,s.className=Eq(),s.placeholder=`1.0`,s.style.width=`80px`,s.addEventListener(`change`,()=>e.setPolicyVersion(s.value)),a.appendChild(o),a.appendChild(s),t.appendChild(a);let c=document.createElement(`div`);c.className=wq();let l=document.createElement(`div`);l.className=Tq(),l.textContent=`Valid from`;let u=document.createElement(`input`);u.type=`date`,u.className=Oq(),u.addEventListener(`change`,()=>e.setValidDateRange(`startDate`,u.value)),c.appendChild(l),c.appendChild(u),t.appendChild(c);let d=document.createElement(`div`);d.className=wq();let f=document.createElement(`div`);f.className=Tq(),f.textContent=`Valid until`;let p=document.createElement(`input`);p.type=`date`,p.className=Oq(),p.addEventListener(`change`,()=>e.setValidDateRange(`endDate`,p.value)),d.appendChild(f),d.appendChild(p),t.appendChild(d);let m=document.createElement(`div`);m.className=wq();let h=document.createElement(`div`);h.className=Tq(),h.textContent=`Doubles attribution`;let g=document.createElement(`select`);g.className=kq();for(let[e,t]of[[``,`(none)`],[`fullToEach`,`Full to each`],[`halfToEach`,`Half to each`],[`split`,`Split`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,g.appendChild(n)}g.addEventListener(`change`,()=>e.setDoublesAttribution(g.value)),m.appendChild(h),m.appendChild(g),t.appendChild(m);let _=document.createElement(`div`);_.className=wq();let v=document.createElement(`div`);v.className=Tq(),v.textContent=`Category resolution`;let y=document.createElement(`select`);y.className=kq();for(let[e,t]of[[``,`(none)`],[`matchCategory`,`Match category`],[`eventCategory`,`Event category`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,y.appendChild(n)}y.addEventListener(`change`,()=>e.setCategoryResolution(y.value)),_.appendChild(v),_.appendChild(y),t.appendChild(_);let b=document.createElement(`div`);b.className=Aq();let x=document.createElement(`input`);x.type=`checkbox`,x.id=`re-require-win`;let S=document.createElement(`label`);S.htmlFor=`re-require-win`,S.textContent=`Require win for points`,x.addEventListener(`change`,()=>e.setGlobalFlag(`requireWinForPoints`,x.checked)),b.appendChild(x),b.appendChild(S),t.appendChild(b);let C=document.createElement(`div`);C.className=Aq();let w=document.createElement(`input`);w.type=`checkbox`,w.id=`re-require-win-r1`;let T=document.createElement(`label`);T.htmlFor=`re-require-win-r1`,T.textContent=`Require win in first round`,w.addEventListener(`change`,()=>e.setGlobalFlag(`requireWinFirstRound`,w.checked)),C.appendChild(w),C.appendChild(T),t.appendChild(C);let E=[i,s,u,p],D=[g,y],O=[x,w];function k(e){let{draft:t}=e;document.activeElement!==i&&(i.value=t.policyName??``),document.activeElement!==s&&(s.value=t.policyVersion??``),document.activeElement!==u&&(u.value=t.validDateRange?.startDate??``),document.activeElement!==p&&(p.value=t.validDateRange?.endDate??``),document.activeElement!==g&&(g.value=t.doublesAttribution??``),document.activeElement!==y&&(y.value=t.categoryResolution??``),x.checked=t.requireWinForPoints??!1,w.checked=t.requireWinFirstRound??!1;let n=e.readonly;for(let e of E)e.disabled=n;for(let e of D)e.disabled=n;for(let e of O)e.disabled=n}return{element:t,update:k}}var Kq={1:`W`,2:`F`,4:`SF`,8:`QF`,16:`R16`,32:`R32`,64:`R64`,128:`R128`,256:`R256`},qq=`level-keyed`;function Jq(e){return Kq[e]??`R${e}`}function Yq(e){if(!e)return{type:`flat`};let t=Object.values(e);if(!t.length||t.every(e=>typeof e==`number`))return{type:`flat`};let n=Xq(t);return n.hasConditionalArray?{type:`conditional`}:n.hasLevelFlightNesting?Zq(t,n.allLevels):n.allLevels.size>0?{type:`level-columns`,levels:[...n.allLevels].sort((e,t)=>e-t)}:n.allFlights.size>0?{type:`flight-columns`,flights:[...n.allFlights].sort((e,t)=>e-t)}:{type:`flat`}}function Xq(e){let t=new Set,n=new Set,r=!1,i=!1;for(let a of e){let e=Qq(a);if(e.type===qq){for(let n of e.levels)t.add(n);e.hasFlightNesting&&(i=!0)}else if(e.type===`flight-keyed`)for(let t=0;t<e.flightCount;t++)n.add(t+1);else e.type===`conditional-array`&&(r=!0)}return{allLevels:t,allFlights:n,hasConditionalArray:r,hasLevelFlightNesting:i}}function Zq(e,t){let n={},r=[...t].sort((e,t)=>e-t);for(let t of e){let e=Qq(t);if(e.type===qq&&e.flightDetails)for(let[t,r]of Object.entries(e.flightDetails)){let e=Number(t);n[e]||(n[e]=[]);for(let t of r)n[e].includes(t)||n[e].push(t)}}return{type:`level-flight-tabs`,levels:r,flightsPerLevel:n}}function Qq(e){if(typeof e==`number`)return{type:`flat`,levels:[],flightCount:0,hasFlightNesting:!1};if(Array.isArray(e))return{type:`conditional-array`,levels:[],flightCount:0,hasFlightNesting:!1};if(typeof e!=`object`||!e)return{type:`flat`,levels:[],flightCount:0,hasFlightNesting:!1};if(e.level!==void 0){if(Array.isArray(e.level))return{type:qq,levels:e.level.map((e,t)=>t+1),flightCount:0,hasFlightNesting:!1};if(typeof e.level==`object`){let t=Object.keys(e.level).map(Number).filter(e=>!Number.isNaN(e)),n=!1,r={};for(let[t,i]of Object.entries(e.level))typeof i==`object`&&i&&i.flights&&(n=!0,r[Number(t)]=i.flights.map((e,t)=>t+1));return{type:qq,levels:t,flightCount:0,hasFlightNesting:n,flightDetails:r}}}return e.flights!==void 0||e.f!==void 0?{type:`flight-keyed`,levels:[],flightCount:(e.flights??e.f??[]).length,hasFlightNesting:!1}:e.value===void 0?{type:`flat`,levels:[],flightCount:0,hasFlightNesting:!1}:{type:`explicit-flat`,levels:[],flightCount:0,hasFlightNesting:!1}}function $q(e,t={}){if(typeof e==`number`)return e;if(e!=null){if(Array.isArray(e))return eJ(e,t);if(typeof e==`object`){if(e.level!==void 0&&t.level!==void 0)return tJ(e,t);if(t.flight!==void 0){let n=e.flights??e.f;if(Array.isArray(n))return n[t.flight-1]}if(e.value!==void 0)return e.value}}}function eJ(e,t){for(let n of e){if(n.drawSizes&&t.drawSize&&n.drawSizes.includes(t.drawSize))return $q(n,t);if(n.drawSize!==void 0&&t.drawSize!==void 0&&(n.threshold?t.drawSize>=n.drawSize:t.drawSize===n.drawSize))return $q({...n,drawSize:void 0,drawSizes:void 0,threshold:void 0},t);if(n.drawSize===void 0&&n.drawSizes===void 0)return $q(n,t)}}function tJ(e,t){let n=Array.isArray(e.level)?e.level[t.level-1]:e.level[t.level];if(n!==void 0)return typeof n==`object`&&n?$q(n,t):typeof n==`number`?n:void 0}function nJ(e){let t=[],n=Object.keys(e.finishingPositionRanges??{}).length;return n&&t.push(`${n} positions`),(e.perWinPoints||e.pointsPerWin)&&t.push(`per-win`),e.bonusPoints?.length&&t.push(`${e.bonusPoints.length} bonus`),t.join(`, `)||`empty`}function rJ(e){let t=[];for(let n of e.eventTypes??[])t.push({label:n,intent:`re-badge--accent`});for(let n of e.stages??[])t.push({label:n,intent:`re-badge--success`});for(let n of e.levels??[])t.push({label:`L${n}`,intent:`re-badge--warn`});for(let n of e.drawTypes??[])t.push({label:n.replaceAll(`_`,` `),intent:`re-badge--primary`});return e.participationOrder!==void 0&&t.push({label:`PO:${e.participationOrder}`,intent:`re-badge--info`}),t}function iJ(e){return e==null?`--`:e.toLocaleString()}var aJ=[1,2,4,8,16,32,64,128],oJ=`font-size:0.8rem;margin-bottom:0;border-collapse:collapse`,sJ=`width:3.5rem;text-align:center`;function cJ(e,t){let n=document.createElement(`div`);n.style.cssText=`overflow-x:auto`;let r=``;function i(r){let i=r.draft.awardProfiles?.[t]?.finishingPositionRanges;if(n.innerHTML=``,!i||!Object.keys(i).length){let i=document.createElement(`div`);if(i.className=zq(),i.textContent=`No finishing position points defined`,!r.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add position`,n.style.marginLeft=`8px`,n.addEventListener(`click`,()=>e.addPositionRow(t,1)),i.appendChild(n)}n.appendChild(i);return}let a=Yq(i),o=Object.keys(i).map(Number).sort((e,t)=>e-t);a.type===`flat`?lJ(n,o,i,r.readonly,e,t):a.type===`level-columns`?uJ(n,o,i,a.levels,r.readonly,e,t):dJ(n,o,i,a)}function a(e){let n=e.draft.awardProfiles?.[t],a=JSON.stringify(n?.finishingPositionRanges??{});a!==r&&(r=a,i(e))}return{element:n,update:a}}function lJ(e,t,n,r,i,a){let o=document.createElement(`table`);o.style.cssText=oJ;let s=document.createElement(`thead`),c=document.createElement(`tr`);fJ(c,`Pos`,sJ),fJ(c,`Points`,`text-align:right`),r||fJ(c,``,`width:2rem`),s.appendChild(c),o.appendChild(s);let l=document.createElement(`tbody`);for(let e of t){let t=document.createElement(`tr`);pJ(t,e);let o=document.createElement(`td`);o.style.cssText=`text-align:right;padding:2px 4px`,r?(o.style.fontVariantNumeric=`tabular-nums`,o.textContent=iJ(typeof n[e]==`number`?n[e]:$q(n[e]))):o.appendChild(hJ(typeof n[e]==`number`?n[e]:$q(n[e])??0,t=>i.setFlatPositionPoints(a,e,t))),t.appendChild(o),r||mJ(t,()=>i.removePositionRow(a,e)),l.appendChild(t)}o.appendChild(l),e.appendChild(o),r||gJ(e,t,i,a)}function uJ(e,t,n,r,i,a,o){let s=document.createElement(`table`);s.style.cssText=oJ;let c=document.createElement(`thead`),l=document.createElement(`tr`);fJ(l,`Pos`,sJ);for(let e of r){let t=document.createElement(`th`);if(t.style.cssText=`text-align:right;min-width:3.5rem;padding:2px 4px`,i)t.textContent=`L${e}`;else{let n=document.createElement(`div`);n.style.cssText=`display:flex;align-items:center;justify-content:flex-end;gap:4px`;let r=document.createElement(`span`);r.textContent=`L${e}`,n.appendChild(r);let i=document.createElement(`span`);i.className=Rq(),i.textContent=`×`,i.title=`Remove level ${e}`,i.style.cssText=`cursor:pointer;font-size:0.65rem`,i.addEventListener(`click`,()=>a.removeLevel(o,e)),n.appendChild(i),t.appendChild(n)}l.appendChild(t)}i||fJ(l,``,`width:2rem`),c.appendChild(l),s.appendChild(c);let u=document.createElement(`tbody`);for(let e of t){let t=document.createElement(`tr`);pJ(t,e);for(let s of r){let r=document.createElement(`td`);r.style.cssText=`text-align:right;padding:2px 4px`;let c=$q(n[e],{level:s});i?(r.style.fontVariantNumeric=`tabular-nums`,r.textContent=iJ(c),c===void 0&&(r.style.color=`var(--sp-muted)`)):r.appendChild(hJ(c??0,t=>a.setLevelPositionPoints(o,e,s,t))),t.appendChild(r)}i||mJ(t,()=>a.removePositionRow(o,e)),u.appendChild(t)}if(s.appendChild(u),e.appendChild(s),!i){let n=document.createElement(`div`);n.style.cssText=`display:flex;gap:8px;margin-top:6px;flex-wrap:wrap`;let i=document.createElement(`div`);i.style.cssText=`display:flex;align-items:center;gap:4px`;let s=document.createElement(`input`);s.type=`number`,s.className=jq(),s.style.width=`50px`,s.placeholder=`L#`,s.min=`1`;let c=document.createElement(`button`);c.className=`sp-btn sp-btn--sm sp-btn--outline`,c.textContent=`+ Level`,c.addEventListener(`click`,()=>{let e=Number.parseInt(s.value,10);!Number.isNaN(e)&&e>0&&!r.includes(e)&&(a.addLevel(o,e),s.value=``)}),i.appendChild(s),i.appendChild(c),n.appendChild(i),_J(n,t,a,o),e.appendChild(n)}}function dJ(e,t,n,r){let i=document.createElement(`div`);i.style.cssText=`font-size:0.7rem;color:var(--sp-muted);margin-bottom:4px;font-style:italic`,i.textContent=`(${r.type} layout — view only)`,e.appendChild(i);let a=document.createElement(`table`);a.style.cssText=oJ;let o=document.createElement(`thead`),s=document.createElement(`tr`);if(fJ(s,`Pos`,sJ),r.type===`flight-columns`)for(let e of r.flights)fJ(s,`F${e}`,`text-align:right;min-width:3.5rem`);else fJ(s,`Points`,`text-align:right`);o.appendChild(s),a.appendChild(o);let c=document.createElement(`tbody`);for(let e of t){let t=document.createElement(`tr`);pJ(t,e);let i=n[e];if(r.type===`flight-columns`)for(let e of r.flights){let n=document.createElement(`td`);n.style.cssText=`text-align:right;font-variant-numeric:tabular-nums;padding:2px 4px`;let r=$q(i,{flight:e});n.textContent=iJ(r),r===void 0&&(n.style.color=`var(--sp-muted)`),t.appendChild(n)}else{let e=document.createElement(`td`);if(e.style.cssText=`text-align:right;font-variant-numeric:tabular-nums;padding:2px 4px`,e.textContent=iJ($q(i)),Array.isArray(i)){let t=document.createElement(`span`);t.style.cssText=`margin-left:0.3rem;font-size:0.65rem;color:var(--sp-muted)`,t.textContent=`${i.length} variants`,t.title=JSON.stringify(i,null,2),e.appendChild(t)}t.appendChild(e)}c.appendChild(t)}a.appendChild(c),e.appendChild(a)}function fJ(e,t,n){let r=document.createElement(`th`);r.textContent=t,r.style.cssText=n+`;padding:2px 4px`,e.appendChild(r)}function pJ(e,t){let n=document.createElement(`td`);n.style.cssText=`text-align:center;font-weight:600;color:var(--sp-text);padding:2px 4px`,n.textContent=Jq(t),e.appendChild(n)}function mJ(e,t){let n=document.createElement(`td`);n.style.cssText=`text-align:center;vertical-align:middle;padding:2px`;let r=document.createElement(`span`);r.className=Rq(),r.textContent=`×`,r.title=`Remove position`,r.style.cursor=`pointer`,r.addEventListener(`click`,t),n.appendChild(r),e.appendChild(n)}function hJ(e,t){let n=document.createElement(`input`);return n.type=`number`,n.className=jq(),n.value=String(e),n.addEventListener(`change`,()=>{let e=Number.parseFloat(n.value);Number.isNaN(e)||t(e)}),n}function gJ(e,t,n,r){let i=document.createElement(`div`);i.style.cssText=`display:flex;gap:8px;margin-top:6px;flex-wrap:wrap`,_J(i,t,n,r),e.appendChild(i)}function _J(e,t,n,r){let i=new Set(t),a=aJ.filter(e=>!i.has(e));if(!a.length)return;let o=document.createElement(`div`);o.style.cssText=`display:flex;align-items:center;gap:4px`;let s=document.createElement(`select`);s.className=`re-field-select`,s.style.cssText=`min-width:80px;font-size:11px;padding:4px 6px`;for(let e of a){let t=document.createElement(`option`);t.value=String(e),t.textContent=Jq(e),s.appendChild(t)}let c=document.createElement(`button`);c.className=`sp-btn sp-btn--sm sp-btn--outline`,c.textContent=`+ Position`,c.addEventListener(`click`,()=>{let e=Number.parseInt(s.value,10);Number.isNaN(e)||n.addPositionRow(r,e)}),o.appendChild(s),o.appendChild(c),e.appendChild(o)}function vJ(e,t){let n=document.createElement(`div`);n.style.cssText=`padding:0.25rem 0;font-size:0.8rem`;let r=document.createElement(`div`);r.className=wq();let i=document.createElement(`div`);i.className=Tq(),i.textContent=`Per-Win`,i.style.minWidth=`80px`;let a=document.createElement(`input`);a.type=`number`,a.className=jq(),a.placeholder=`—`,a.addEventListener(`change`,()=>{let n=a.value.trim();e.setPointsPerWin(t,n===``?void 0:parseFloat(n))});let o=document.createElement(`div`);o.style.cssText=`font-size:0.75rem;color:var(--sp-muted)`,r.appendChild(i),r.appendChild(a),n.appendChild(r),n.appendChild(o);function s(e){let r=e.draft.awardProfiles?.[t];if(!r){n.style.display=`none`;return}let i=r.perWinPoints,s=r.pointsPerWin;if(!i&&s===void 0){n.style.display=`none`;return}if(n.style.display=``,a.disabled=e.readonly,s!==void 0&&typeof s==`number`)a.style.display=``,o.style.display=`none`,document.activeElement!==a&&(a.value=String(s));else if(s!==void 0){a.style.display=`none`,o.style.display=``;let e=$q(s);o.textContent=`${iJ(e)} pts/win (complex)`}else if(i){a.style.display=`none`,o.style.display=``;let e=(Array.isArray(i)?i:[i]).map(e=>{let t=[];return e.participationOrders?.length&&t.push(`PO:${e.participationOrders.join(`,`)}`),e.value!==void 0&&t.push(`${e.value} pts/win`),e.limit!==void 0&&t.push(`limit: ${e.limit}`),t.join(` | `)});o.textContent=e.join(`; `)}if(r.maxCountableMatches!==void 0){let e=typeof r.maxCountableMatches==`number`?r.maxCountableMatches:`level-keyed`;o.style.display=``;let t=o.textContent;o.textContent=t?`${t} — max countable: ${e}`:`Max countable: ${e}`}}return{element:n,update:s}}function yJ(e,t){let n=document.createElement(`div`);n.style.cssText=`padding:0.25rem 0;font-size:0.8rem`;let r=``;function i(r){let i=r.draft.awardProfiles?.[t]?.bonusPoints;if(n.innerHTML=``,!i?.length&&r.readonly){n.style.display=`none`;return}n.style.display=``;let a=document.createElement(`div`);if(a.style.cssText=`font-weight:600;color:var(--sp-text);margin-bottom:4px`,a.textContent=`Bonus Points`,n.appendChild(a),i?.length)for(let a=0;a<i.length;a++){let o=i[a],s=document.createElement(`div`);if(s.style.cssText=`display:flex;align-items:center;gap:6px;margin-bottom:4px;padding-left:0.5rem`,r.readonly){let e=o.finishingPositions.map(Jq).join(`, `),t=document.createElement(`span`);t.textContent=`${e}: `,s.appendChild(t);let n=document.createElement(`span`);n.style.fontVariantNumeric=`tabular-nums`,n.textContent=typeof o.value==`number`?o.value.toLocaleString():String(o.value??`—`),s.appendChild(n)}else{let n=document.createElement(`span`);n.style.cssText=`font-size:0.75rem;color:var(--sp-muted);min-width:30px`,n.textContent=`Pos:`,s.appendChild(n);let r=document.createElement(`input`);r.type=`text`,r.className=jq(),r.style.width=`80px`,r.value=o.finishingPositions.join(`, `),r.title=`Comma-separated positions (e.g. 1, 2)`,r.addEventListener(`change`,()=>{let n=r.value.split(`,`).map(e=>Number.parseInt(e.trim(),10)).filter(e=>!Number.isNaN(e)&&e>0);n.length&&e.setBonusPointPositions(t,a,n)}),s.appendChild(r);let i=document.createElement(`span`);i.style.cssText=`font-size:0.75rem;color:var(--sp-muted)`,i.textContent=`Pts:`,s.appendChild(i);let c=document.createElement(`input`);c.type=`number`,c.className=jq(),c.value=typeof o.value==`number`?String(o.value):``,c.addEventListener(`change`,()=>{let n=Number.parseFloat(c.value);Number.isNaN(n)||e.setBonusPointValue(t,a,n)}),s.appendChild(c);let l=document.createElement(`span`);l.className=Rq(),l.textContent=`×`,l.title=`Remove bonus`,l.style.cursor=`pointer`,l.addEventListener(`click`,()=>e.removeBonusPoint(t,a)),s.appendChild(l)}n.appendChild(s)}if(!r.readonly){let r=document.createElement(`button`);r.className=`sp-btn sp-btn--sm sp-btn--outline`,r.textContent=`+ Add bonus`,r.style.cssText=`margin-top:4px;margin-left:0.5rem`,r.addEventListener(`click`,()=>e.addBonusPoint(t)),n.appendChild(r)}}function a(e){let n=e.draft.awardProfiles?.[t],a=JSON.stringify(n?.bonusPoints??[]);a!==r&&(r=a,i(e))}return{element:n,update:a}}function bJ(e){let t=document.createElement(`div`);t.style.cssText=`display:inline-flex;gap:0.25rem;flex-wrap:wrap;margin-bottom:0`;let n=rJ(e);if(!n.length){let e=document.createElement(`span`);return e.className=`re-badge re-badge--neutral`,e.textContent=`All`,t.appendChild(e),t}for(let e of n){let n=document.createElement(`span`);n.className=`re-badge ${e.intent}`,n.textContent=e.label,t.appendChild(n)}return t}var xJ=[{field:`eventTypes`,label:`Event types`,options:[`SINGLES`,`DOUBLES`,`TEAM`]},{field:`drawTypes`,label:`Draw types`,options:[`SINGLE_ELIMINATION`,`DOUBLE_ELIMINATION`,`ROUND_ROBIN`,`COMPASS`,`FEED_IN`,`AD_HOC`,`LUCKY_DRAW`]},{field:`stages`,label:`Stages`,options:[`MAIN`,`QUALIFYING`,`CONSOLATION`,`PLAY_OFF`]},{field:`levels`,label:`Levels`,options:[],isNumeric:!0}],SJ=[[`maxDrawSize`,`Max draw size`],[`maxLevel`,`Max level`],[`priority`,`Priority`],[`participationOrder`,`Participation order`]];function CJ(e,t){let n=document.createElement(`div`);n.style.cssText=`padding:0.25rem 0`;let r=document.createElement(`div`);r.style.cssText=`font-weight:600;font-size:0.8rem;color:var(--sp-text);margin-bottom:4px`,r.textContent=`Scope`,n.appendChild(r);let i=document.createElement(`div`);n.appendChild(i);let a=``;function o(n,r){if(n.isNumeric){let i=document.createElement(`input`);return i.type=`number`,i.min=`1`,i.placeholder=`+`,i.style.cssText=`width:36px;font-size:0.7rem;padding:2px 4px;border:1px dashed var(--sp-border);border-radius:4px;background:transparent;color:var(--sp-text);outline:none;text-align:center`,i.addEventListener(`keydown`,a=>{if(a.key===`Enter`){let a=Number.parseInt(i.value,10);!Number.isNaN(a)&&a>0&&!r.includes(a)&&(e.setProfileScope(t,n.field,[...r,a].sort((e,t)=>e-t)),i.value=``)}}),i}let i=n.options.filter(e=>!r.includes(e));if(!i.length)return;let a=document.createElement(`select`);a.style.cssText=`font-size:0.65rem;padding:2px 4px;border:1px dashed var(--sp-border);border-radius:4px;background:transparent;color:var(--sp-muted);outline:none;cursor:pointer`;let o=document.createElement(`option`);o.value=``,o.textContent=`+`,a.appendChild(o);for(let e of i){let t=document.createElement(`option`);t.value=e,t.textContent=e,a.appendChild(t)}return a.addEventListener(`change`,()=>{a.value&&e.setProfileScope(t,n.field,[...r,a.value])}),a}function s(n,r,i){let a=document.createElement(`div`);a.style.cssText=`margin-bottom:6px`;let s=document.createElement(`div`);s.style.cssText=`font-size:0.7rem;color:var(--sp-muted);margin-bottom:2px`,s.textContent=n.label,a.appendChild(s);let c=document.createElement(`div`);c.style.cssText=`display:flex;flex-wrap:wrap;gap:4px;align-items:center`;for(let a of r){let o=document.createElement(`span`);if(o.className=`re-badge re-badge--accent`,o.style.cssText=`display:inline-flex;align-items:center;gap:3px`,o.textContent=n.isNumeric?`L${a}`:String(a),!i){let i=document.createElement(`span`);i.style.cssText=`cursor:pointer;font-size:0.6rem;opacity:0.7`,i.textContent=`×`,i.addEventListener(`click`,()=>{e.setProfileScope(t,n.field,r.filter(e=>e!==a))}),o.appendChild(i)}c.appendChild(o)}if(!i){let e=o(n,r);e&&c.appendChild(e)}return a.appendChild(c),a}function c(r){i.innerHTML=``;let a=r.draft.awardProfiles?.[t];if(!a)return;let o=r.readonly;for(let e of xJ){let t=a[e.field]??[];o&&!t.length||i.appendChild(s(e,t,o))}for(let[n,r]of SJ){let s=a[n];if(o&&s===void 0)continue;let c=document.createElement(`div`);c.className=wq();let l=document.createElement(`div`);if(l.className=Tq(),l.style.cssText=`min-width:110px;font-size:0.75rem`,l.textContent=r,c.appendChild(l),o){let e=document.createElement(`span`);e.style.cssText=`font-size:0.75rem;color:var(--sp-text)`,e.textContent=String(s),c.appendChild(e)}else{let r=document.createElement(`input`);r.type=`number`,r.className=Dq(),r.style.fontSize=`0.75rem`,r.value=s===void 0?``:String(s),r.placeholder=`—`,r.addEventListener(`change`,()=>{let i=r.value.trim();e.setProfileField(t,n,i?Number.parseInt(i,10):void 0)}),c.appendChild(r)}i.appendChild(c)}let c=i.children.length>0;n.style.display=c?``:`none`}function l(e){let n=e.draft.awardProfiles?.[t],r=xJ.map(e=>n?.[e.field]??[]),i=SJ.map(([e])=>n?.[e]),o=JSON.stringify([r,i,e.readonly]);o!==a&&(a=o,c(e))}return{element:n,update:l}}function wJ(e,t){let n=document.createElement(`div`);n.className=Mq();let r=document.createElement(`div`);r.className=Nq();let i=document.createElement(`span`);i.className=xq(),i.style.flexShrink=`0`,r.appendChild(i);let a=document.createElement(`input`);a.type=`text`,a.className=Pq(),a.addEventListener(`click`,e=>e.stopPropagation()),a.addEventListener(`change`,()=>e.setProfileName(t,a.value)),r.appendChild(a);let o=document.createElement(`div`);o.style.cssText=`flex-grow:1;display:inline-flex;gap:0.25rem;flex-wrap:wrap`,r.appendChild(o);let s=document.createElement(`span`);s.style.cssText=`font-size:0.75rem;color:var(--sp-muted);white-space:nowrap;flex-shrink:0`,r.appendChild(s);let c=document.createElement(`div`);c.className=Iq();let l=document.createElement(`button`);l.className=Lq(),l.textContent=`⎘`,l.title=`Duplicate profile`,l.addEventListener(`click`,n=>{n.stopPropagation(),e.duplicateProfile(t)});let u=document.createElement(`button`);u.className=Rq(),u.textContent=`✕`,u.title=`Delete profile`,u.addEventListener(`click`,n=>{n.stopPropagation(),e.removeProfile(t)}),c.appendChild(l),c.appendChild(u),r.appendChild(c),r.addEventListener(`click`,()=>e.toggleProfile(t)),n.appendChild(r);let d=document.createElement(`div`);d.className=Fq();let f=document.createElement(`div`);f.style.cssText=`font-weight:600;font-size:0.85rem;color:var(--sp-text);margin-bottom:6px`,d.appendChild(f);let p=cJ(e,t);d.appendChild(p.element);let m=vJ(e,t);d.appendChild(m.element);let h=yJ(e,t);d.appendChild(h.element);let g=CJ(e,t);d.appendChild(g.element);let _=document.createElement(`div`);_.style.cssText=`padding:0.25rem 0;font-size:0.75rem;color:var(--sp-muted)`,d.appendChild(_),n.appendChild(d);function v(e){let r=e.draft.awardProfiles?.[t];if(!r){n.style.display=`none`;return}n.style.display=``;let l=e.expandedProfiles.has(t),u=e.readonly;i.textContent=l?`▼`:`▶`;let v=r.profileName||`Profile ${t+1}`;document.activeElement!==a&&(a.value=v),a.title=v,a.disabled=u,o.innerHTML=``;let y=bJ(r);if(y.style.flexGrow=`1`,o.appendChild(y),s.textContent=l?``:nJ(r),c.style.display=u?`none`:`flex`,d.style.display=l?``:`none`,l){f.textContent=v,p.update(e),m.update(e),h.update(e),g.update(e);let t=[];r.requireWinForPoints!==void 0&&t.push(`requireWin: ${r.requireWinForPoints}`),r.requireWinFirstRound!==void 0&&t.push(`requireWinR1: ${r.requireWinFirstRound}`),_.textContent=t.join(` | `),_.style.display=t.length?``:`none`}}return{element:n,update:v}}function TJ(e,t){let n=document.createElement(`div`);n.className=Bq();let r=Gq(e),i=Uq(e),a=Hq(e),o=[{id:`metadata`,label:`Metadata`},{id:`awardProfiles`,label:`Award Profiles`,countFn:e=>e.draft.awardProfiles?.length??0},{id:`qualityWinProfiles`,label:`Quality Win Profiles`,countFn:e=>e.draft.qualityWinProfiles?.length??0},{id:`aggregationRules`,label:`Aggregation Rules`}],s=[];for(let t of o){let o=document.createElement(`div`);o.className=yq();let c=document.createElement(`div`);c.className=bq();let l=document.createElement(`span`);l.className=xq();let u=document.createElement(`span`);u.textContent=t.label;let d=document.createElement(`span`);d.className=Sq(),c.appendChild(l),c.appendChild(u),c.appendChild(d),c.addEventListener(`click`,()=>e.toggleSection(t.id));let f=document.createElement(`div`);f.className=Cq(),t.id===`metadata`&&f.appendChild(r.element),t.id===`qualityWinProfiles`&&f.appendChild(i.element),t.id===`aggregationRules`&&f.appendChild(a.element),o.appendChild(c),o.appendChild(f),n.appendChild(o),s.push({id:t.id,chevron:l,countEl:d,bodyEl:f})}let c=[],l=-1,u=``,d=null;function f(e,t){for(let n=0;n<o.length;n++){let r=o[n],i=s[n],a=e.has(r.id);if(i.chevron.textContent=a?`▼`:`▶`,i.bodyEl.style.display=a?`block`:`none`,r.countFn){let e=r.countFn(t);i.countEl.textContent=e?`(${e})`:``}}}function p(t,n){let r=s[1].bodyEl;r.innerHTML=``,c=[];let i=t.draft.awardProfiles??[],a=0;for(let t=0;t<i.length;t++){let o=i[t];if(n&&![o.profileName??``,...o.eventTypes??[],...o.stages??[],...(o.levels??[]).map(e=>`L${e}`),...o.drawTypes??[]].join(` `).toLowerCase().includes(n))continue;let s=wJ(e,t);c.push(s),r.appendChild(s.element),a++}if(!a){let e=document.createElement(`div`);e.className=zq(),e.textContent=n?`No profiles match filter`:`No award profiles defined`,r.appendChild(e)}t.readonly||(d=document.createElement(`button`),d.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,d.textContent=`+ Add Profile`,d.addEventListener(`click`,()=>e.addProfile()),r.appendChild(d))}return{element:n,update:e=>{let{draft:t,expandedSections:n,profileFilter:o}=e;if(f(n,e),n.has(`metadata`)&&r.update(e),n.has(`awardProfiles`)){let n=t.awardProfiles?.length??0,r=o.toLowerCase();(n!==l||r!==u)&&(l=n,u=r,p(e,r));for(let t of c)t.update(e);d&&(d.style.display=e.readonly?`none`:``)}n.has(`qualityWinProfiles`)&&i.update(e),n.has(`aggregationRules`)&&a.update(e)}}}var EJ=class e{constructor(e){this.container=null,this.store=new vq(e),this.panel=TJ(this.store,e),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.panel.element.remove(),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e),readonly:t.readonly},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}};function DJ(e){return OJ[e]??e}var OJ={"SET3-S:6/TB7":`Best of 3 TB sets`,"SET3-S:6/TB7-F:TB10":`2 TB sets, MTB10`,"SET3-S:6/TB7-F:TB7":`2 TB sets, MTB7`,"SET3-S:4NOAD-F:TB7":`2 short sets (4, NOAD), MTB7`,"SET3-S:4/TB7":`Best of 3 short sets (4)`,"SET3-S:4/TB7-F:TB7":`2 short sets (4), MTB7`,"SET3-S:4/TB7-F:TB10":`2 short sets (4), MTB10`,"SET3-S:4/TB5@3":`3 short sets (4), TB5@3`,"SET1-S:8/TB7":`8-game pro-set, TB7`,"SET1-S:8/TB7@7":`8-game pro-set, TB7@7`,"SET1-S:5/TB9@4":`1 set to 5, TB9@4`,"SET1-S:6/TB7":`1 TB set`,"SET1-S:6NOAD":`1 set to 6, NOAD`,"SET1-S:4/TB7":`1 short set (4), TB7`,"SET1-S:4/TB5@3":`1 short set (4), TB5@3`,"SET1-S:4NOAD":`1 short set (4), NOAD`,"SET3-S:TB10":`Best of 3 TB10 games`,"SET1-S:T20":`Timed 20 min`,"SET1-S:TB10":`1 TB10 game`,"SET5-S:6/TB7":`Best of 5 TB sets`,"SET5-S:6/TB7-F:TB10":`5 sets, MTB10`,"SET1-S:6/TB10":`1 set, TB10`,"SET1-S:8":`Pro-set to 8`,"SET1-S:10":`Pro-set to 10`,"SET1-S:T7":`TB7 only`,"SET1-S:T21":`TB21 only`};function kJ(){return{allowModificationWhenMatchUpsScheduled:{courts:!1,venues:!1},defaultTimes:{averageTimes:[{categoryNames:[],minutes:{default:90}}],recoveryTimes:[{minutes:{default:60}}]},defaultDailyLimits:{SINGLES:2,DOUBLES:2,total:3},matchUpAverageTimes:[],matchUpRecoveryTimes:[],matchUpDailyLimits:[]}}function AJ(e){return structuredClone(e)}var jJ=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:AJ(e.initialPolicy??kJ()),expandedSections:new Set([`modificationFlags`,`dailyLimits`,`defaultTimes`,`averageTimes`,`recoveryTimes`]),dirty:!1}}getState(){return this.state}getData(){return AJ(this.state.draft)}setData(e){this.state={...this.state,draft:AJ(e),dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}setModificationFlag(e,t){let n=AJ(this.state.draft);n.allowModificationWhenMatchUpsScheduled||={courts:!1,venues:!1},n.allowModificationWhenMatchUpsScheduled[e]=t,this.commitDraft(n)}setDailyLimit(e,t){let n=AJ(this.state.draft);n.defaultDailyLimits||={},n.defaultDailyLimits[e]=t,this.commitDraft(n)}setDefaultAverageTime(e,t,n){let r=AJ(this.state.draft);r.defaultTimes||={},r.defaultTimes.averageTimes||(r.defaultTimes.averageTimes=[{categoryNames:[],minutes:{default:90}}]);let i=r.defaultTimes.averageTimes[e];i&&(t===`DOUBLES`?n===void 0?delete i.minutes.DOUBLES:i.minutes.DOUBLES=n:i.minutes.default=n??0,this.commitDraft(r))}setDefaultRecoveryTime(e,t,n){let r=AJ(this.state.draft);r.defaultTimes||={},r.defaultTimes.recoveryTimes||(r.defaultTimes.recoveryTimes=[{minutes:{default:60}}]);let i=r.defaultTimes.recoveryTimes[e];i&&(t===`DOUBLES`?n===void 0?delete i.minutes.DOUBLES:i.minutes.DOUBLES=n:i.minutes.default=n??0,this.commitDraft(r))}addAverageFormatGroup(){let e=AJ(this.state.draft);e.matchUpAverageTimes||=[],e.matchUpAverageTimes.push({matchUpFormatCodes:[],averageTimes:[{categoryNames:[],minutes:{default:60}}]}),this.commitDraft(e)}removeAverageFormatGroup(e){let t=AJ(this.state.draft);t.matchUpAverageTimes&&(t.matchUpAverageTimes.splice(e,1),this.commitDraft(t))}setAverageFormatCodes(e,t){let n=AJ(this.state.draft),r=n.matchUpAverageTimes?.[e];r&&(r.matchUpFormatCodes=t,this.commitDraft(n))}setAverageTime(e,t,n,r){let i=AJ(this.state.draft),a=i.matchUpAverageTimes?.[e]?.averageTimes?.[t];a&&(n===`DOUBLES`?r===void 0?delete a.minutes.DOUBLES:a.minutes.DOUBLES=r:a.minutes.default=r??0,this.commitDraft(i))}addAverageCategoryOverride(e){let t=AJ(this.state.draft),n=t.matchUpAverageTimes?.[e];n&&(n.averageTimes.push({categoryTypes:[],minutes:{default:60}}),this.commitDraft(t))}removeAverageCategoryOverride(e,t){let n=AJ(this.state.draft),r=n.matchUpAverageTimes?.[e];r&&(r.averageTimes.splice(t,1),this.commitDraft(n))}setAverageOverrideCategories(e,t,n,r){let i=AJ(this.state.draft),a=i.matchUpAverageTimes?.[e]?.averageTimes?.[t];a&&(n===`categoryNames`?(delete a.categoryTypes,a.categoryNames=r):(delete a.categoryNames,a.categoryTypes=r),this.commitDraft(i))}addRecoveryFormatGroup(){let e=AJ(this.state.draft);e.matchUpRecoveryTimes||=[],e.matchUpRecoveryTimes.push({matchUpFormatCodes:[],recoveryTimes:[{categoryNames:[],minutes:{default:30}}]}),this.commitDraft(e)}removeRecoveryFormatGroup(e){let t=AJ(this.state.draft);t.matchUpRecoveryTimes&&(t.matchUpRecoveryTimes.splice(e,1),this.commitDraft(t))}setRecoveryFormatCodes(e,t){let n=AJ(this.state.draft),r=n.matchUpRecoveryTimes?.[e];r&&(r.matchUpFormatCodes=t,this.commitDraft(n))}setRecoveryTime(e,t,n,r){let i=AJ(this.state.draft),a=i.matchUpRecoveryTimes?.[e]?.recoveryTimes?.[t];a&&(n===`DOUBLES`?r===void 0?delete a.minutes.DOUBLES:a.minutes.DOUBLES=r:a.minutes.default=r??0,this.commitDraft(i))}addRecoveryCategoryOverride(e){let t=AJ(this.state.draft),n=t.matchUpRecoveryTimes?.[e];n&&(n.recoveryTimes.push({categoryTypes:[],minutes:{default:30}}),this.commitDraft(t))}removeRecoveryCategoryOverride(e,t){let n=AJ(this.state.draft),r=n.matchUpRecoveryTimes?.[e];r&&(r.recoveryTimes.splice(t,1),this.commitDraft(n))}setRecoveryOverrideCategories(e,t,n,r){let i=AJ(this.state.draft),a=i.matchUpRecoveryTimes?.[e]?.recoveryTimes?.[t];a&&(n===`categoryNames`?(delete a.categoryTypes,a.categoryNames=r):(delete a.categoryNames,a.categoryTypes=r),this.commitDraft(i))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(AJ(e))}emit(){for(let e of this.listeners)e(this.state)}},MJ=()=>`se-section`,NJ=()=>`se-section-header`,PJ=()=>`se-section-chevron`,FJ=()=>`se-section-body`,IJ=()=>`se-field-row`,LJ=()=>`se-field-label`,RJ=()=>`se-field-input`,zJ=()=>`se-field-unit`,BJ=()=>`se-checkbox-row`,VJ=()=>`se-format-group`,HJ=()=>`se-format-group-header`,UJ=()=>`se-format-group-label`,WJ=()=>`se-tag-picker`,GJ=()=>`sp-chip`,KJ=()=>`sp-chip__remove`,qJ=()=>`se-tag-add-wrap`,JJ=()=>`sp-btn-icon`,YJ=()=>`se-override-row`,XJ=()=>`se-override-categories`,ZJ=()=>`se-override-remove`,QJ=()=>`sp-btn sp-btn--sm sp-btn--outline se-add-btn`,$J=()=>`sp-btn-icon sp-btn-icon--danger`,eY=()=>`se-editor`;function tY(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=BJ();let r=document.createElement(`input`);r.type=`checkbox`,r.id=`se-mod-courts`;let i=document.createElement(`label`);i.htmlFor=`se-mod-courts`,i.textContent=`Allow court modifications when matchUps scheduled`,r.addEventListener(`change`,()=>{e.setModificationFlag(`courts`,r.checked)}),n.appendChild(r),n.appendChild(i);let a=document.createElement(`div`);a.className=BJ();let o=document.createElement(`input`);o.type=`checkbox`,o.id=`se-mod-venues`;let s=document.createElement(`label`);s.htmlFor=`se-mod-venues`,s.textContent=`Allow venue modifications when matchUps scheduled`,o.addEventListener(`change`,()=>{e.setModificationFlag(`venues`,o.checked)}),a.appendChild(o),a.appendChild(s),t.appendChild(n),t.appendChild(a);function c(e){let t=e.draft.allowModificationWhenMatchUpsScheduled;r.checked=t?.courts??!1,o.checked=t?.venues??!1}return{element:t,update:c}}var nY=`is-success`,rY=`is-danger`;function iY(e){if(e===``)return!0;let t=parseInt(e,10);return!isNaN(t)&&t>=0&&String(t)===e.trim()}function aY(e,t){if(t===``){e.classList.remove(nY,rY);return}iY(t)?(e.classList.remove(rY),e.classList.add(nY)):(e.classList.remove(nY),e.classList.add(rY))}function oY(e){let t=document.createElement(`div`),n=[];for(let[r,i]of[[`SINGLES`,`Singles limit`],[`DOUBLES`,`Doubles limit`],[`total`,`Total limit`]]){let a=document.createElement(`div`);a.className=IJ();let o=document.createElement(`div`);o.className=LJ(),o.textContent=i;let s=document.createElement(`input`);s.type=`text`,s.className=RJ(),s.placeholder=`0`,s.addEventListener(`input`,()=>{aY(s,s.value)}),s.addEventListener(`change`,()=>{let t=parseInt(s.value,10);!isNaN(t)&&t>=0&&e.setDailyLimit(r,t)}),a.appendChild(o),a.appendChild(s),t.appendChild(a),n.push({key:r,label:i,input:s})}function r(e){let t=e.draft.defaultDailyLimits;for(let e of n){let n=t?.[e.key];document.activeElement!==e.input&&(e.input.value=n===void 0?``:String(n))}}return{element:t,update:r}}var sY=`is-success`,cY=`is-danger`;function lY(e){if(e===``)return!0;let t=parseInt(e,10);return!isNaN(t)&&t>=0&&String(t)===e.trim()}function uY(e,t,n){if(t===``&&n){e.classList.remove(sY,cY);return}lY(t)&&(t!==``||n)?(e.classList.remove(cY),e.classList.add(sY)):(e.classList.remove(sY),e.classList.add(cY))}function dY(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.style.cssText=`font-size:11px;font-weight:700;color:var(--sp-muted);margin-bottom:6px;`,n.textContent=`Default Average Times`,t.appendChild(n);let r=fY(`Default`,`min`,!1),i=fY(`Doubles override`,`min`,!0);t.appendChild(r.row),t.appendChild(i.row),r.input.addEventListener(`input`,()=>{uY(r.input,r.input.value,!1)}),r.input.addEventListener(`change`,()=>{let t=parseInt(r.input.value,10);!isNaN(t)&&t>=0&&e.setDefaultAverageTime(0,`default`,t)}),i.input.addEventListener(`input`,()=>{uY(i.input,i.input.value,!0)}),i.input.addEventListener(`change`,()=>{let t=i.input.value.trim();if(t===``||t===`-`)e.setDefaultAverageTime(0,`DOUBLES`,void 0);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&e.setDefaultAverageTime(0,`DOUBLES`,n)}});let a=document.createElement(`div`);a.style.height=`12px`,t.appendChild(a);let o=document.createElement(`div`);o.style.cssText=`font-size:11px;font-weight:700;color:var(--sp-muted);margin-bottom:6px;`,o.textContent=`Default Recovery Times`,t.appendChild(o);let s=fY(`Default`,`min`,!1),c=fY(`Doubles override`,`min`,!0);t.appendChild(s.row),t.appendChild(c.row),s.input.addEventListener(`input`,()=>{uY(s.input,s.input.value,!1)}),s.input.addEventListener(`change`,()=>{let t=parseInt(s.input.value,10);!isNaN(t)&&t>=0&&e.setDefaultRecoveryTime(0,`default`,t)}),c.input.addEventListener(`input`,()=>{uY(c.input,c.input.value,!0)}),c.input.addEventListener(`change`,()=>{let t=c.input.value.trim();if(t===``||t===`-`)e.setDefaultRecoveryTime(0,`DOUBLES`,void 0);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&e.setDefaultRecoveryTime(0,`DOUBLES`,n)}});function l(e){let t=e.draft.defaultTimes?.averageTimes?.[0];document.activeElement!==r.input&&(r.input.value=t?String(t.minutes.default):``),document.activeElement!==i.input&&(i.input.value=t?.minutes.DOUBLES===void 0?``:String(t.minutes.DOUBLES)),i.input.placeholder=`—`;let n=e.draft.defaultTimes?.recoveryTimes?.[0];document.activeElement!==s.input&&(s.input.value=n?String(n.minutes.default):``),document.activeElement!==c.input&&(c.input.value=n?.minutes.DOUBLES===void 0?``:String(n.minutes.DOUBLES)),c.input.placeholder=`—`}return{element:t,update:l}}function fY(e,t,n){let r=document.createElement(`div`);r.className=IJ();let i=document.createElement(`div`);i.className=LJ(),i.textContent=e;let a=document.createElement(`input`);a.type=`text`,a.className=RJ(),a.placeholder=n?`—`:`0`;let o=document.createElement(`div`);return o.className=zJ(),o.textContent=t,r.appendChild(i),r.appendChild(a),r.appendChild(o),{row:r,input:a}}var pY=`is-success`,mY=`is-danger`;function hY(e){if(e===``)return!0;let t=parseInt(e,10);return!isNaN(t)&&t>=0&&String(t)===e.trim()}function gY(e,t,n){if(t===``&&n){e.classList.remove(pY,mY);return}hY(t)&&(t!==``||n)?(e.classList.remove(mY),e.classList.add(pY)):(e.classList.remove(pY),e.classList.add(mY))}function _Y(e){let t=document.createElement(`div`);t.className=VJ();let n=document.createElement(`div`);n.className=HJ();let r=document.createElement(`div`);r.style.flex=`1`;let i=document.createElement(`div`);i.className=UJ(),i.textContent=`Formats`,r.appendChild(i);let a=document.createElement(`div`);a.className=WJ();for(let t of e.formatCodes){let n=document.createElement(`span`);n.className=GJ(),n.title=`${t} — click to edit`;let r=document.createElement(`span`);r.textContent=DJ(t),n.addEventListener(`click`,()=>{Ha({existingMatchUpFormat:t,callback:n=>{if(!n||n===t)return;let r=e.formatCodes.map(e=>e===t?n:e);e.onFormatCodesChange(r)}})});let i=document.createElement(`span`);i.className=KJ(),i.textContent=`×`,i.addEventListener(`click`,n=>{n.stopPropagation(),e.onFormatCodesChange(e.formatCodes.filter(e=>e!==t))}),n.appendChild(r),n.appendChild(i),a.appendChild(n)}let o=document.createElement(`div`);o.className=qJ();let s=document.createElement(`button`);s.className=JJ(),s.textContent=`+`,s.type=`button`,s.title=`Add format code`,s.addEventListener(`click`,t=>{t.stopPropagation(),Ha({existingMatchUpFormat:`SET3-S:6/TB7`,callback:t=>{t&&!e.formatCodes.includes(t)&&e.onFormatCodesChange([...e.formatCodes,t])}})}),o.appendChild(s),a.appendChild(o),r.appendChild(a);let c=document.createElement(`button`);c.className=$J(),c.textContent=`×`,c.type=`button`,c.title=`Remove format group`,c.addEventListener(`click`,()=>e.onRemoveGroup()),n.appendChild(r),n.appendChild(c),t.appendChild(n);for(let n=0;n<e.overrides.length;n++){let r=e.overrides[n],i=document.createElement(`div`);i.className=YJ();let a=document.createElement(`div`);a.className=`${XJ()}${r.isDefault?` all`:``}`,a.textContent=r.categoryLabel;let o=document.createElement(`input`);o.type=`text`,o.className=RJ(),o.value=String(r.defaultMinutes),o.placeholder=`0`;let s=n;o.addEventListener(`input`,()=>{gY(o,o.value,!1)}),o.addEventListener(`change`,()=>{let t=parseInt(o.value,10);!isNaN(t)&&t>=0&&e.onTimeChange(s,`default`,t)});let c=document.createElement(`span`);c.className=zJ(),c.textContent=`min`;let l=document.createElement(`span`);l.style.cssText=`font-size:11px;color:var(--sp-muted);margin-left:8px;`,l.textContent=`Doubles:`;let u=document.createElement(`input`);if(u.type=`text`,u.className=RJ(),u.value=r.doublesMinutes===void 0?``:String(r.doublesMinutes),u.placeholder=`—`,u.addEventListener(`input`,()=>{gY(u,u.value,!0)}),u.addEventListener(`change`,()=>{let t=u.value.trim();if(t===``||t===`-`)e.onTimeChange(s,`DOUBLES`,void 0);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&e.onTimeChange(s,`DOUBLES`,n)}}),i.appendChild(a),i.appendChild(o),i.appendChild(c),i.appendChild(l),i.appendChild(u),!r.isDefault){let t=document.createElement(`span`);t.className=ZJ(),t.textContent=`×`,t.addEventListener(`click`,()=>e.onRemoveOverride(s)),i.appendChild(t)}t.appendChild(i)}let l=document.createElement(`button`);return l.className=QJ(),l.textContent=`+ Add Override`,l.type=`button`,l.addEventListener(`click`,()=>e.onAddOverride()),t.appendChild(l),t}function vY(e,t){let n=document.createElement(`div`),r=document.createElement(`div`);n.appendChild(r);let i=document.createElement(`button`);i.className=QJ(),i.textContent=`+ Add Format Group`,i.type=`button`,i.addEventListener(`click`,()=>e.addAverageFormatGroup()),n.appendChild(i);function a(n){r.innerHTML=``;let i=n.draft.matchUpAverageTimes??[];for(let n=0;n<i.length;n++){let a=i[n],o=a.averageTimes.map((e,t)=>{let n=e.categoryTypes??e.categoryNames??[];return{categoryLabel:n.length===0&&t===0?`All categories`:n.join(`, `)||`All categories`,isDefault:n.length===0&&t===0,defaultMinutes:e.minutes.default,doublesMinutes:e.minutes.DOUBLES}}),s=n,c=_Y({formatCodes:a.matchUpFormatCodes,overrides:o,availableFormats:t.matchUpFormatCodes??yY(),onFormatCodesChange:t=>e.setAverageFormatCodes(s,t),onTimeChange:(t,n,r)=>e.setAverageTime(s,t,n,r),onAddOverride:()=>e.addAverageCategoryOverride(s),onRemoveOverride:t=>e.removeAverageCategoryOverride(s,t),onRemoveGroup:()=>e.removeAverageFormatGroup(s)});r.appendChild(c)}if(i.length===0){let e=document.createElement(`div`);e.style.cssText=`font-size:12px;color:var(--sp-muted);padding:8px 0;`,e.textContent=`No format-specific average times configured. Add a format group to set per-format times.`,r.appendChild(e)}}return{element:n,update:a}}function yY(){return[`SET3-S:6/TB7`,`SET3-S:6/TB7-F:TB10`,`SET3-S:6/TB7-F:TB7`,`SET3-S:4NOAD-F:TB7`,`SET3-S:4/TB7`,`SET3-S:4/TB7-F:TB7`,`SET3-S:4/TB7-F:TB10`,`SET3-S:4/TB5@3`,`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:4/TB5@3`,`SET1-S:4NOAD`,`SET3-S:TB10`,`SET1-S:T20`,`SET1-S:TB10`]}function bY(e,t){let n=document.createElement(`div`),r=document.createElement(`div`);n.appendChild(r);let i=document.createElement(`button`);i.className=QJ(),i.textContent=`+ Add Format Group`,i.type=`button`,i.addEventListener(`click`,()=>e.addRecoveryFormatGroup()),n.appendChild(i);function a(n){r.innerHTML=``;let i=n.draft.matchUpRecoveryTimes??[];for(let n=0;n<i.length;n++){let a=i[n],o=a.recoveryTimes.map((e,t)=>{let n=e.categoryTypes??e.categoryNames??[];return{categoryLabel:n.length===0&&t===0?`All categories`:n.join(`, `)||`All categories`,isDefault:n.length===0&&t===0,defaultMinutes:e.minutes.default,doublesMinutes:e.minutes.DOUBLES}}),s=n,c=_Y({formatCodes:a.matchUpFormatCodes,overrides:o,availableFormats:t.matchUpFormatCodes??xY(),onFormatCodesChange:t=>e.setRecoveryFormatCodes(s,t),onTimeChange:(t,n,r)=>e.setRecoveryTime(s,t,n,r),onAddOverride:()=>e.addRecoveryCategoryOverride(s),onRemoveOverride:t=>e.removeRecoveryCategoryOverride(s,t),onRemoveGroup:()=>e.removeRecoveryFormatGroup(s)});r.appendChild(c)}if(i.length===0){let e=document.createElement(`div`);e.style.cssText=`font-size:12px;color:var(--sp-muted);padding:8px 0;`,e.textContent=`No format-specific recovery times configured. Add a format group to set per-format recovery.`,r.appendChild(e)}}return{element:n,update:a}}function xY(){return[`SET3-S:6/TB7`,`SET3-S:6/TB7-F:TB10`,`SET3-S:6/TB7-F:TB7`,`SET3-S:4NOAD-F:TB7`,`SET3-S:4/TB7`,`SET3-S:4/TB7-F:TB7`,`SET3-S:4/TB7-F:TB10`,`SET3-S:4/TB5@3`,`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:4/TB5@3`,`SET1-S:4NOAD`,`SET3-S:TB10`,`SET1-S:T20`,`SET1-S:TB10`]}function SY(e,t){let n=document.createElement(`div`);n.className=eY();let r=[{id:`modificationFlags`,label:`Modification Flags`,factory:()=>tY(e)},{id:`dailyLimits`,label:`Daily Limits`,factory:()=>oY(e)},{id:`defaultTimes`,label:`Default Times`,factory:()=>dY(e)},{id:`averageTimes`,label:`Match Average Times`,factory:()=>vY(e,t)},{id:`recoveryTimes`,label:`Match Recovery Times`,factory:()=>bY(e,t)}],i=[];for(let t of r){let r=document.createElement(`div`);r.className=MJ();let a=document.createElement(`div`);a.className=NJ();let o=document.createElement(`span`);o.className=PJ();let s=document.createElement(`span`);s.textContent=t.label,a.appendChild(o),a.appendChild(s),a.addEventListener(`click`,()=>e.toggleSection(t.id));let c=document.createElement(`div`);c.className=FJ();let l=t.factory();c.appendChild(l.element),r.appendChild(a),r.appendChild(c),n.appendChild(r),i.push({id:t.id,chevron:o,bodyEl:c,inner:l})}function a(e){for(let t of i){let n=e.expandedSections.has(t.id);t.chevron.textContent=n?`▼`:`▶`,t.bodyEl.style.display=n?`block`:`none`,n&&t.inner.update(e)}}return{element:n,update:a}}var CY=class e{constructor(e){this.container=null,this.store=new jJ(e),this.panel=SY(this.store,e),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}};function wY(e,t){let n=new CY(e);return n.render(t),n}var TY=ma,EY=(()=>{let e=new Map;for(let t of TY)t.format&&e.set(t.format,t);return e})();function DY(e){if(e)return EY.get(e)}var OY=TY.filter(e=>e.format&&e.name).sort((e,t)=>(e.name??``).localeCompare(t.name??``));function kY(e){return typeof e==`string`?e:e.matchUpFormat}function AY(e){return(typeof e==`string`?``:e.name??``)||(DY(kY(e))?.name??``)}function jY(e){return(typeof e==`string`?``:e.description??``)||(DY(kY(e))?.desc??``)}function MY(e){return typeof e==`string`?{matchUpFormat:e}:{...e}}var NY=`SET3-S:6/TB7`;function PY(){return{defaultMatchUpFormat:NY,matchUpFormats:[],requireParticipantsForScoring:!1,allowChangePropagation:!1,allowDeletionWithScoresPresent:{drawDefinitions:!1,structures:!1},matchUpStatusCodes:{ABANDONED:[],CANCELLED:[],DEFAULTED:[],INCOMPLETE:[],RETIRED:[],WALKOVER:[]}}}function FY(e){return structuredClone(e)}var IY=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:FY(e.initialPolicy??PY()),expandedSections:new Set([`defaults`,`allowedFormats`]),expandedStatuses:new Set,advancedOpen:!1,dirty:!1}}isReadonly(){return this.config.readonly===!0}getState(){return this.state}getData(){return FY(this.state.draft)}setData(e){this.state={...this.state,draft:FY(e),dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}toggleStatus(e){let t=new Set(this.state.expandedStatuses);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedStatuses:t},this.emit()}setAdvancedOpen(e){this.state.advancedOpen!==e&&(this.state={...this.state,advancedOpen:e},this.emit())}setDefaultMatchUpFormat(e){if(this.isReadonly())return;let t=FY(this.state.draft);t.defaultMatchUpFormat=e,this.commitDraft(t)}setRequireParticipants(e){if(this.isReadonly())return;let t=FY(this.state.draft);t.requireParticipantsForScoring=e,this.commitDraft(t)}setRequireAllPositions(e){if(this.isReadonly())return;let t=FY(this.state.draft);e==="default"?delete t.requireAllPositionsAssigned:t.requireAllPositionsAssigned=e===`true`,this.commitDraft(t)}setAllowChangePropagation(e){if(this.isReadonly())return;let t=FY(this.state.draft);t.allowChangePropagation=e,this.commitDraft(t)}setAllowDeletionDraws(e){if(this.isReadonly())return;let t=FY(this.state.draft);t.allowDeletionWithScoresPresent??={},t.allowDeletionWithScoresPresent.drawDefinitions=e,this.commitDraft(t)}setAllowDeletionStructures(e){if(this.isReadonly())return;let t=FY(this.state.draft);t.allowDeletionWithScoresPresent??={},t.allowDeletionWithScoresPresent.structures=e,this.commitDraft(t)}addAllowedFormat(e){if(this.isReadonly())return;let t=FY(this.state.draft);t.matchUpFormats??=[];let n={matchUpFormat:``,...e};t.matchUpFormats.push(n),this.commitDraft(t)}removeAllowedFormat(e){if(this.isReadonly())return;let t=FY(this.state.draft);t.matchUpFormats&&(t.matchUpFormats.splice(e,1),this.commitDraft(t))}setAllowedFormatField(e,t,n){if(this.isReadonly())return;let r=FY(this.state.draft);if(!r.matchUpFormats?.[e])return;let i=MY(r.matchUpFormats[e]);t===`name`?i.name=n:t===`description`?i.description=n:i.matchUpFormat=n,i.name===``&&delete i.name,i.description===``&&delete i.description,r.matchUpFormats[e]=i,this.commitDraft(r)}isAllowedFormatDuplicate(e,t){let n=e.trim();return n?(this.state.draft.matchUpFormats??[]).some((e,r)=>r!==t&&kY(e)===n):!1}addAllowedFormatCategory(e,t,n){if(this.isReadonly())return;let r=n.trim();if(!r)return;let i=FY(this.state.draft);if(!i.matchUpFormats?.[e])return;let a=MY(i.matchUpFormats[e]);a[t]??=[],!a[t].includes(r)&&(a[t].push(r),i.matchUpFormats[e]=a,this.commitDraft(i))}removeAllowedFormatCategory(e,t,n){if(this.isReadonly())return;let r=FY(this.state.draft),i=r.matchUpFormats?.[e];if(!i)return;let a=MY(i),o=a[t];o&&(o.splice(n,1),o.length===0&&delete a[t],r.matchUpFormats[e]=a,this.commitDraft(r))}addStatusCode(e,t){if(this.isReadonly())return;let n=t.trim();if(!n)return;let r=FY(this.state.draft);r.matchUpStatusCodes??={},r.matchUpStatusCodes[e]??=[],!r.matchUpStatusCodes[e].includes(n)&&(r.matchUpStatusCodes[e].push(n),this.commitDraft(r))}removeStatusCode(e,t){if(this.isReadonly())return;let n=FY(this.state.draft),r=n.matchUpStatusCodes?.[e];r&&(r.splice(t,1),this.commitDraft(n))}addProcessCode(e){if(this.isReadonly())return;let t=e.trim();if(!t)return;let n=FY(this.state.draft);n.processCodes??={},n.processCodes.incompleteAssignmentsOnDefault??=[],!n.processCodes.incompleteAssignmentsOnDefault.includes(t)&&(n.processCodes.incompleteAssignmentsOnDefault.push(t),this.commitDraft(n))}removeProcessCode(e){if(this.isReadonly())return;let t=FY(this.state.draft),n=t.processCodes?.incompleteAssignmentsOnDefault;n&&(n.splice(e,1),this.commitDraft(t))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(FY(e))}emit(){for(let e of this.listeners)e(this.state)}},LY=`__custom__`,RY=`standard`,zY=`tiebreak`,BY=`timed`,VY=`sc-format-row`,HY=`sc-format-label`,UY=`sc-format-select`;function WY(){return{bestOf:3,setType:RY,setTo:6,hasTiebreak:!0,tiebreakTo:7,tiebreakAt:`same`,noAd:!1,tbOnlyTo:11,tbOnlyModifier:``,tbOnlyNoAd:!1,minutes:20,timedBasis:`G`,differentFinal:!1,finalKind:`matchTiebreak`,finalSetTo:6,finalTbTo:7,finalMatchTbTo:10}}function GY(e){let n=WY(),r=t.matchUpFormatCode.parse?.(e);return r?(typeof r.bestOf==`number`&&(n.bestOf=r.bestOf),r.setFormat&&KY(n,r.setFormat),r.finalSetFormat&&qY(n,r.finalSetFormat),n):n}function KY(e,t){if(t.timed){e.setType=BY,typeof t.minutes==`number`&&(e.minutes=t.minutes),e.timedBasis=t.based===`P`?`P`:`G`;return}if(t.tiebreakSet){e.setType=zY,typeof t.tiebreakSet.tiebreakTo==`number`&&(e.tbOnlyTo=t.tiebreakSet.tiebreakTo),e.tbOnlyModifier=t.tiebreakSet.modifier===`RALLY`?`RALLY`:``,e.tbOnlyNoAd=!!t.tiebreakSet.NoAD;return}e.setType=RY,typeof t.setTo==`number`&&(e.setTo=t.setTo),e.noAd=!!t.NoAD,e.hasTiebreak=!t.noTiebreak&&!!t.tiebreakFormat,t.tiebreakFormat?.tiebreakTo&&(e.tiebreakTo=t.tiebreakFormat.tiebreakTo),typeof t.tiebreakAt==`number`&&t.tiebreakAt!==t.setTo&&(e.tiebreakAt=t.tiebreakAt)}function qY(e,t){if(e.differentFinal=!0,t.tiebreakSet){e.finalKind=`matchTiebreak`,typeof t.tiebreakSet.tiebreakTo==`number`&&(e.finalMatchTbTo=t.tiebreakSet.tiebreakTo);return}e.finalKind=`standard`,typeof t.setTo==`number`&&(e.finalSetTo=t.setTo),t.tiebreakFormat?.tiebreakTo&&(e.finalTbTo=t.tiebreakFormat.tiebreakTo)}function JY(e){let t={bestOf:e.bestOf};if(e.setType===BY)t.setFormat={timed:!0,minutes:e.minutes},e.timedBasis===`P`&&(t.setFormat.based=`P`);else if(e.setType===zY)t.setFormat={tiebreakSet:{tiebreakTo:e.tbOnlyTo,...e.tbOnlyModifier?{modifier:e.tbOnlyModifier}:{},...e.tbOnlyNoAd?{NoAD:!0}:{}}};else{let n={setTo:e.setTo};e.noAd&&(n.NoAD=!0),e.hasTiebreak?(n.tiebreakFormat={tiebreakTo:e.tiebreakTo},n.tiebreakAt=e.tiebreakAt===`same`?e.setTo:e.tiebreakAt):n.noTiebreak=!0,t.setFormat=n}return e.differentFinal&&(t.finalSetFormat=e.finalKind===`matchTiebreak`?{tiebreakSet:{tiebreakTo:e.finalMatchTbTo}}:{setTo:e.finalSetTo,tiebreakAt:e.finalSetTo,tiebreakFormat:{tiebreakTo:e.finalTbTo}}),t}function YY(e){try{return t.matchUpFormatCode.stringify?.(e)}catch{return}}function XY(e){return e?!!t.matchUpFormatCode.parse?.(e):!1}function ZY(e){let t=e.initialValue||`SET3-S:6/TB7`,n=GY(t),r=document.createElement(`div`);r.className=`sc-format-picker`;let i=document.createElement(`div`);i.className=VY;let a=document.createElement(`label`);a.textContent=`Preset`,a.className=HY;let o=document.createElement(`select`);o.className=UY;for(let e of OY){let t=document.createElement(`option`);t.value=e.format??``,t.textContent=e.desc?`${e.name} — ${e.desc}`:e.name??``,o.appendChild(t)}let s=document.createElement(`option`);s.value=LY,s.textContent=`Custom…`,o.appendChild(s),i.appendChild(a),i.appendChild(o),r.appendChild(i);let c=document.createElement(`div`);c.className=`sc-format-row sc-format-custom-row`,c.style.display=`none`;let l=document.createElement(`label`);l.textContent=`Format string`,l.className=HY;let u=document.createElement(`input`);u.type=`text`,u.className=`sc-format-input`,u.placeholder=`e.g. SET3-S:6/TB7-F:TB10`,c.appendChild(l),c.appendChild(u),r.appendChild(c);let d=document.createElement(`button`);d.type=`button`,d.className=`sc-format-builder-toggle`,d.textContent=`▸ Build a custom format`,r.appendChild(d);let f=document.createElement(`div`);f.className=`sc-format-builder-body`,f.style.display=`none`,r.appendChild(f);let p=!1;d.addEventListener(`click`,()=>{p=!p,f.style.display=p?`block`:`none`,d.textContent=p?`▾ Build a custom format`:`▸ Build a custom format`,p&&y()});let m=document.createElement(`div`);m.className=`sc-format-result`;let h=document.createElement(`code`);h.className=`sc-format-chip`;let g=document.createElement(`span`);g.className=`sc-format-validity`,m.appendChild(document.createTextNode(`Result:`)),m.appendChild(h),m.appendChild(g),r.appendChild(m);function _(r,i={}){t=r,i.skipBuilderResync||(n=GY(r)),v(),p&&y(),e.onChange(r)}function v(){let e=DY(t);e?.format?(o.value=e.format,c.style.display=`none`):(o.value=LY,c.style.display=``,u.value=t),h.textContent=t;let n=XY(t);g.textContent=n?`✓ valid`:`✗ invalid`,g.dataset.valid=n?`true`:`false`}o.addEventListener(`change`,()=>{let e=o.value;if(e===LY){c.style.display=``,u.value=t,u.focus();return}_(e)}),u.addEventListener(`input`,()=>{_(u.value,{skipBuilderResync:!0})});function y(){f.innerHTML=``,f.appendChild(QY(`Best of`,[1,3,5],n.bestOf,e=>{n.bestOf=e,b()})),f.appendChild($Y(`Set type`,[{value:RY,label:`Standard`},{value:zY,label:`Tiebreak set`},{value:BY,label:`Timed`}],n.setType,e=>{n.setType=e,b()})),n.setType===RY?(f.appendChild(QY(`Games to`,[4,6,8,10],n.setTo,e=>{n.setTo=e,(n.tiebreakAt===`same`||n.tiebreakAt===n.setTo)&&(n.tiebreakAt=`same`),b()})),f.appendChild(eX(`Tiebreak at set end`,n.hasTiebreak,e=>{n.hasTiebreak=e,b()})),n.hasTiebreak&&f.appendChild(QY(`Tiebreak first to`,[5,7,10,12,15,21],n.tiebreakTo,e=>{n.tiebreakTo=e,b()})),f.appendChild(eX(`No-advantage games`,n.noAd,e=>{n.noAd=e,b()}))):n.setType===zY?(f.appendChild(QY(`First to`,[7,10,11,15,21],n.tbOnlyTo,e=>{n.tbOnlyTo=e,b()})),f.appendChild($Y(`Scoring`,[{value:``,label:`Sideout`},{value:`RALLY`,label:`Rally`}],n.tbOnlyModifier,e=>{n.tbOnlyModifier=e,b()})),f.appendChild(eX(`No-advantage`,n.tbOnlyNoAd,e=>{n.tbOnlyNoAd=e,b()}))):(f.appendChild(QY(`Minutes`,[10,15,20,25,30,45],n.minutes,e=>{n.minutes=e,b()})),f.appendChild($Y(`Basis`,[{value:`G`,label:`Games`},{value:`P`,label:`Points`}],n.timedBasis,e=>{n.timedBasis=e,b()}))),f.appendChild(eX(`Different final-set rules`,n.differentFinal,e=>{n.differentFinal=e,b()})),n.differentFinal&&(f.appendChild($Y(`Final set`,[{value:`standard`,label:`Standard set`},{value:`matchTiebreak`,label:`Match tiebreak`}],n.finalKind,e=>{n.finalKind=e,b()})),n.finalKind===`standard`?(f.appendChild(QY(`Final games to`,[4,6,8],n.finalSetTo,e=>{n.finalSetTo=e,b()})),f.appendChild(QY(`Final tiebreak to`,[7,10,12,15],n.finalTbTo,e=>{n.finalTbTo=e,b()}))):f.appendChild(QY(`Match tiebreak to`,[7,10,15,21],n.finalMatchTbTo,e=>{n.finalMatchTbTo=e,b()})))}function b(){let e=YY(JY(n));typeof e==`string`?_(e,{skipBuilderResync:!0}):y()}return e.readonly&&(o.disabled=!0,u.disabled=!0,d.disabled=!0),v(),{element:r,setValue(e){let r=e||`SET3-S:6/TB7`;r!==t&&(t=r,n=GY(r),v(),p&&y())},destroy(){r.remove()}}}function QY(e,t,n,r){let i=document.createElement(`div`);i.className=VY;let a=document.createElement(`label`);a.textContent=e,a.className=HY;let o=document.createElement(`select`);o.className=UY;for(let e of t){let t=document.createElement(`option`);t.value=String(e),t.textContent=String(e),o.appendChild(t)}return o.value=String(n),o.addEventListener(`change`,()=>r(Number(o.value))),i.appendChild(a),i.appendChild(o),i}function $Y(e,t,n,r){let i=document.createElement(`div`);i.className=VY;let a=document.createElement(`span`);a.textContent=e,a.className=HY;let o=document.createElement(`div`);o.className=`sc-format-radio-group`;let s=`sc-fmt-radio-${Math.floor(Math.random()*1e9).toString(36)}`;for(let e of t){let t=document.createElement(`label`);t.className=`sc-format-radio-option`;let i=document.createElement(`input`);i.type=`radio`,i.name=s,i.value=e.value,i.checked=e.value===n,i.addEventListener(`change`,()=>{i.checked&&r(i.value)}),t.appendChild(i),t.appendChild(document.createTextNode(e.label)),o.appendChild(t)}return i.appendChild(a),i.appendChild(o),i}function eX(e,t,n){let r=document.createElement(`div`);r.className=`sc-format-row sc-format-checkbox-row`;let i=document.createElement(`label`);i.className=`sc-format-checkbox-label`;let a=document.createElement(`input`);return a.type=`checkbox`,a.checked=t,a.addEventListener(`change`,()=>n(a.checked)),i.appendChild(a),i.appendChild(document.createTextNode(e)),r.appendChild(i),r}function tX(e){let t=document.createElement(`div`);t.className=`sc-section-body-inner`;let n=document.createElement(`div`);n.className=`sc-field-block`;let r=document.createElement(`div`);r.className=`sc-field-block-label`,r.textContent=`Default match-up format`;let i=document.createElement(`div`);i.className=`sc-field-help`,i.textContent=`Used when an event or draw does not specify its own format.`,n.appendChild(r),n.appendChild(i);let a=ZY({initialValue:e.getData().defaultMatchUpFormat,readonly:e.isReadonly(),onChange:t=>e.setDefaultMatchUpFormat(t)});n.appendChild(a.element),t.appendChild(n);let o=nX({label:`Require both participants before scoring`,help:`Block score entry until both sides have a participant assigned.`,initial:!!e.getData().requireParticipantsForScoring,readonly:e.isReadonly(),onChange:t=>e.setRequireParticipants(t)});t.appendChild(o.element);let s=document.createElement(`div`);s.className=`sc-field-row`;let c=document.createElement(`label`);c.className=`sc-field-label`,c.textContent=`Require all positions assigned`;let l=document.createElement(`select`);l.className=`sc-field-input`;for(let e of[{value:`default`,label:`Default (required in MAIN stage)`},{value:`true`,label:`Always required`},{value:`false`,label:`Never required`}]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,l.appendChild(t)}l.addEventListener(`change`,()=>{e.setRequireAllPositions(l.value)}),e.isReadonly()&&(l.disabled=!0),s.appendChild(c),s.appendChild(l),t.appendChild(s);let u=nX({label:`Allow change propagation`,help:`Editing a completed matchUp's winningSide updates all downstream matchUps in the structure.`,initial:!!e.getData().allowChangePropagation,readonly:e.isReadonly(),onChange:t=>e.setAllowChangePropagation(t)});t.appendChild(u.element);let d=document.createElement(`div`);d.className=`sc-field-block`;let f=document.createElement(`div`);f.className=`sc-field-block-label`,f.textContent=`Allow deletion with scores present`;let p=document.createElement(`div`);p.className=`sc-field-help`,p.textContent=`When off, the corresponding entity cannot be deleted while it has scored matchUps.`,d.appendChild(f),d.appendChild(p);let m=nX({label:`Draw definitions`,help:``,initial:!!e.getData().allowDeletionWithScoresPresent?.drawDefinitions,readonly:e.isReadonly(),onChange:t=>e.setAllowDeletionDraws(t)}),h=nX({label:`Structures`,help:``,initial:!!e.getData().allowDeletionWithScoresPresent?.structures,readonly:e.isReadonly(),onChange:t=>e.setAllowDeletionStructures(t)});d.appendChild(m.element),d.appendChild(h.element),t.appendChild(d);function g(e){let t=e.draft;a.setValue(t.defaultMatchUpFormat||``),o.setChecked(!!t.requireParticipantsForScoring),t.requireAllPositionsAssigned===void 0?l.value=`default`:l.value=t.requireAllPositionsAssigned?`true`:`false`,u.setChecked(!!t.allowChangePropagation),m.setChecked(!!t.allowDeletionWithScoresPresent?.drawDefinitions),h.setChecked(!!t.allowDeletionWithScoresPresent?.structures)}return{element:t,update:g}}function nX(e){let t=document.createElement(`div`);t.className=`sc-checkbox-row`;let n=document.createElement(`input`);n.type=`checkbox`,n.checked=e.initial,e.readonly&&(n.disabled=!0),n.addEventListener(`change`,()=>e.onChange(n.checked));let r=document.createElement(`div`);r.className=`sc-checkbox-text`;let i=document.createElement(`label`);if(i.textContent=e.label,r.appendChild(i),e.help){let t=document.createElement(`div`);t.className=`sc-checkbox-help`,t.textContent=e.help,r.appendChild(t)}return t.appendChild(n),t.appendChild(r),{element:t,setChecked(e){n.checked=e}}}function rX(e){let t=document.createElement(`div`);t.className=`sc-taglist`;let n=document.createElement(`div`);n.className=`sc-taglist-chips`,t.appendChild(n);let r=document.createElement(`div`);r.className=`sc-taglist-input-row`;let i=document.createElement(`input`);i.type=`text`,i.className=`sc-taglist-input`,e.placeholder&&(i.placeholder=e.placeholder);let a=document.createElement(`button`);a.type=`button`,a.className=`sp-btn sp-btn--sm sp-btn--outline`,a.textContent=`Add`;let o=document.createElement(`div`);o.className=`sc-taglist-error`,o.style.display=`none`,r.appendChild(i),r.appendChild(a),t.appendChild(r),t.appendChild(o);let s=[...e.values];function c(){if(n.innerHTML=``,s.length===0){let e=document.createElement(`span`);e.className=`sc-taglist-empty`,e.textContent=`none`,n.appendChild(e);return}s.forEach((t,r)=>{let i=document.createElement(`span`);i.className=`sc-taglist-chip`;let a=document.createElement(`code`);if(a.textContent=t,i.appendChild(a),!e.readonly){let n=document.createElement(`button`);n.type=`button`,n.className=`sc-taglist-chip-remove`,n.setAttribute(`aria-label`,`Remove ${t}`),n.textContent=`×`,n.addEventListener(`click`,()=>e.onRemove(r)),i.appendChild(n)}n.appendChild(i)})}function l(){let t=i.value.trim();if(t){if(e.validate&&!e.validate(t)){o.textContent=e.invalidMessage??`Invalid value`,o.style.display=``;return}o.style.display=`none`,i.value=``,e.onAdd(t)}}return a.addEventListener(`click`,l),i.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),l())}),e.readonly&&(i.disabled=!0,a.disabled=!0,r.style.display=`none`),c(),{element:t,setValues(e){s=[...e],c()},destroy(){t.remove()}}}function iX(e){let t=document.createElement(`div`);t.className=`sc-section-body-inner`;let n=document.createElement(`div`);n.className=`sc-field-help`,n.textContent=`Restrict which formats events under this policy can use. Each entry surfaces in the MatchUp Format Dialog using Name as the dropdown label and Description as the sub-text. Empty list = no restriction.`,t.appendChild(n);let r=document.createElement(`div`);r.className=`sc-format-list-header`,r.appendChild(aX(``)),r.appendChild(aX(`Name`)),r.appendChild(aX(`Format`)),r.appendChild(aX(`Description`)),r.appendChild(aX(``)),t.appendChild(r);let i=document.createElement(`div`);i.className=`sc-format-list-rows`,t.appendChild(i);let a=document.createElement(`div`);a.className=`sc-format-list-empty`,a.textContent=`No allowed formats — any format will be accepted.`,t.appendChild(a);let o=document.createElement(`div`);o.className=`sc-format-list-actions`;let s=document.createElement(`button`);s.type=`button`,s.className=`sp-btn sp-btn--sm sp-btn--outline`,s.textContent=`+ Add format`,s.addEventListener(`click`,()=>e.addAllowedFormat());let c=document.createElement(`select`);c.className=`sc-format-list-preset-picker`;let l=document.createElement(`option`);l.value=``,l.textContent=`Add from preset…`,c.appendChild(l);for(let e of OY){let t=document.createElement(`option`);t.value=e.format??``,t.textContent=e.desc?`${e.name} — ${e.desc}`:e.name??``,c.appendChild(t)}c.addEventListener(`change`,()=>{let t=c.value;if(!t)return;let n=OY.find(e=>e.format===t);n?.format&&e.addAllowedFormat({matchUpFormat:n.format,name:n.name,description:n.desc}),c.value=``}),o.appendChild(s),o.appendChild(c),t.appendChild(o),e.isReadonly()&&(s.disabled=!0,c.disabled=!0);let u=[];function d(t){for(a.style.display=t.length===0?``:`none`,r.style.display=t.length===0?`none`:``;u.length>t.length;)u.pop()?.destroy();for(;u.length<t.length;){let t=u.length,n=oX(e,t);i.appendChild(n.element),u.push(n)}for(let e=0;e<t.length;e+=1)u[e].setIndex(e),u[e].setEntry(t[e])}d(e.getData().matchUpFormats??[]);function f(e){d(e.draft.matchUpFormats??[])}return{element:t,update:f}}function aX(e){let t=document.createElement(`div`);return t.className=`sc-format-list-header-label`,t.textContent=e,t}function oX(e,n){let r=n,i=!1,a=e.isReadonly(),o=document.createElement(`div`);o.className=`sc-format-list-row-wrap`;let s=document.createElement(`div`);s.className=`sc-format-list-row`;let c=document.createElement(`button`);c.type=`button`,c.className=`sc-format-list-row-expand`,c.setAttribute(`aria-label`,`Expand advanced fields`),c.textContent=`▸`;let l=cX(`Display name`,a),u=cX(`SET3-S:6/TB7`,a);u.classList.add(`sc-format-list-format-input`);let d=cX(`Description shown beneath the name`,a),f=document.createElement(`span`);f.className=`sc-format-list-validity`;let p=document.createElement(`button`);p.type=`button`,p.className=`sc-format-list-row-remove`,p.setAttribute(`aria-label`,`Remove format`),p.textContent=`×`,a&&(p.disabled=!0),p.addEventListener(`click`,()=>e.removeAllowedFormat(r));let m=document.createElement(`div`);m.className=`sc-format-list-format-cell`,m.appendChild(u),m.appendChild(f),s.appendChild(c),s.appendChild(l),s.appendChild(m),s.appendChild(d),s.appendChild(p);let h=document.createElement(`div`);h.className=`sc-format-list-row-advanced`,h.style.display=`none`;let g=document.createElement(`div`);g.className=`sc-field-help`,g.textContent=`Category filters scope this format to events with matching categoryNames / categoryTypes. Empty = applies to all categories.`,h.appendChild(g);let _=sX({label:`Category names`,placeholder:`e.g. U18`,initial:[],readonly:a,onAdd:t=>e.addAllowedFormatCategory(r,`categoryNames`,t),onRemove:t=>e.removeAllowedFormatCategory(r,`categoryNames`,t)});h.appendChild(_.element);let v=sX({label:`Category types`,placeholder:`e.g. AGE`,initial:[],readonly:a,onAdd:t=>e.addAllowedFormatCategory(r,`categoryTypes`,t),onRemove:t=>e.removeAllowedFormatCategory(r,`categoryTypes`,t)});h.appendChild(v.element),o.appendChild(s),o.appendChild(h),c.addEventListener(`click`,()=>{i=!i,c.textContent=i?`▾`:`▸`,h.style.display=i?``:`none`}),l.addEventListener(`input`,()=>e.setAllowedFormatField(r,`name`,l.value)),u.addEventListener(`input`,()=>{e.setAllowedFormatField(r,`matchUpFormat`,u.value),y()}),d.addEventListener(`input`,()=>e.setAllowedFormatField(r,`description`,d.value));function y(){let e=u.value.trim();if(!e){f.textContent=``,f.dataset.state=`empty`;return}t.matchUpFormatCode.parse?.(e)?(f.textContent=`✓`,f.dataset.state=`valid`):(f.textContent=`✗`,f.dataset.state=`invalid`)}return{element:o,setEntry(e){let t=MY(e),n=AY(e),r=kY(e),i=jY(e);l.value!==n&&(l.value=n),u.value!==r&&(u.value=r),d.value!==i&&(d.value=i),_.tagList.setValues(t.categoryNames??[]),v.tagList.setValues(t.categoryTypes??[]);let a=(t.categoryNames?.length??0)+(t.categoryTypes?.length??0)>0;c.dataset.hasContent=a?`true`:`false`,y()},setIndex(e){r=e},destroy(){o.remove()}}}function sX(e){let t=document.createElement(`div`);t.className=`sc-format-list-category-field`;let n=document.createElement(`div`);n.className=`sc-format-list-category-label`,n.textContent=e.label,t.appendChild(n);let r=rX({values:e.initial,placeholder:e.placeholder,readonly:e.readonly,onAdd:e.onAdd,onRemove:e.onRemove});return t.appendChild(r.element),{element:t,tagList:r}}function cX(e,t){let n=document.createElement(`input`);return n.type=`text`,n.className=`sc-format-list-input`,n.placeholder=e,t&&(n.disabled=!0),n}var lX=[`ABANDONED`,`CANCELLED`,`DEFAULTED`,`INCOMPLETE`,`RETIRED`,`WALKOVER`];function uX(e){let t=document.createElement(`div`);t.className=`sc-section-body-inner`;let n=lX.map(t=>dX(e,t));for(let r of n)t.appendChild(fX(r,()=>e.toggleStatus(r.key)));let r=document.createElement(`div`);r.className=`sc-advanced`;let i=document.createElement(`div`);i.className=`sc-advanced-header`;let a=document.createElement(`span`);a.className=`sc-advanced-chevron`;let o=document.createElement(`span`);o.textContent=`Advanced — process codes`,i.appendChild(a),i.appendChild(o),i.addEventListener(`click`,()=>e.setAdvancedOpen(!e.getState().advancedOpen));let s=document.createElement(`div`);s.className=`sc-advanced-body`,s.style.display=`none`;let c=document.createElement(`div`);c.className=`sc-field-help`,c.textContent=`Tokens passed to downstream governors when assignments are incomplete on default. The factory default ships ["RANKING.IGNORE"].`,s.appendChild(c);let l=rX({values:e.getData().processCodes?.incompleteAssignmentsOnDefault??[],placeholder:`e.g. RANKING.IGNORE`,readonly:e.isReadonly(),onAdd:t=>e.addProcessCode(t),onRemove:t=>e.removeProcessCode(t)});s.appendChild(l.element),r.appendChild(i),r.appendChild(s),t.appendChild(r);function u(e){for(let t of n){let n=e.draft.matchUpStatusCodes?.[t.key]??[];t.countEl.textContent=String(n.length);let r=e.expandedStatuses.has(t.key);t.chevron.textContent=r?`▾`:`▸`,t.body.style.display=r?`block`:`none`,t.tagList.setValues(n)}a.textContent=e.advancedOpen?`▾`:`▸`,s.style.display=e.advancedOpen?`block`:`none`,l.setValues(e.draft.processCodes?.incompleteAssignmentsOnDefault??[])}return{element:t,update:u}}function dX(e,t){let n=document.createElement(`span`);n.className=`sc-status-chevron`;let r=document.createElement(`span`);r.className=`sc-status-count`;let i=document.createElement(`div`);i.className=`sc-status-body`;let a=rX({values:e.getData().matchUpStatusCodes?.[t]??[],placeholder:`e.g. INJURY`,readonly:e.isReadonly(),onAdd:n=>e.addStatusCode(t,n),onRemove:n=>e.removeStatusCode(t,n)});return i.appendChild(a.element),{key:t,chevron:n,countEl:r,body:i,tagList:a}}function fX(e,t){let n=document.createElement(`div`);n.className=`sc-status-group`;let r=document.createElement(`div`);r.className=`sc-status-header`;let i=document.createElement(`span`);i.className=`sc-status-label`,i.textContent=pX(e.key),r.appendChild(e.chevron),r.appendChild(i);let a=document.createElement(`span`);return a.className=`sc-status-count-wrap`,a.appendChild(document.createTextNode(`(`)),a.appendChild(e.countEl),a.appendChild(document.createTextNode(`)`)),r.appendChild(a),r.addEventListener(`click`,t),n.appendChild(r),n.appendChild(e.body),n}function pX(e){return e.charAt(0)+e.slice(1).toLowerCase()}function mX(e){let t=document.createElement(`div`);t.className=`sc-editor`;let n=[{id:`defaults`,label:`Defaults`,factory:()=>tX(e)},{id:`allowedFormats`,label:`Allowed match-up formats`,factory:()=>iX(e)},{id:`statusCodes`,label:`Status code refinements`,factory:()=>uX(e)}],r=[];for(let i of n){let n=document.createElement(`div`);n.className=`sc-section`;let a=document.createElement(`div`);a.className=`sc-section-header`;let o=document.createElement(`span`);o.className=`sc-section-chevron`;let s=document.createElement(`span`);s.textContent=i.label,a.appendChild(o),a.appendChild(s),a.addEventListener(`click`,()=>e.toggleSection(i.id));let c=document.createElement(`div`);c.className=`sc-section-body`;let l=i.factory();c.appendChild(l.element),n.appendChild(a),n.appendChild(c),t.appendChild(n),r.push({id:i.id,chevron:o,bodyEl:c,inner:l})}function i(e){for(let t of r){let n=e.expandedSections.has(t.id);t.chevron.textContent=n?`▾`:`▸`,t.bodyEl.style.display=n?`block`:`none`,n&&t.inner.update(e)}}return{element:t,update:i}}var hX=class e{constructor(e){this.container=null,this.store=new IY(e),this.panel=mX(this.store),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,readonly:t.readonly,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}},gX=[{value:`SEPARATE`,label:`Separate`,description:`Each seed placed in its own section of the draw`},{value:`WATERFALL`,label:`Waterfall`,description:`Seeds cascade down section by section`},{value:`CLUSTER`,label:`Cluster`,description:`Seeds grouped in clusters (e.g. 5-8 together)`}],_X=[`SINGLE_ELIMINATION`,`DOUBLE_ELIMINATION`,`ROUND_ROBIN`,`ROUND_ROBIN_WITH_PLAYOFF`,`FEED_IN`,`FEED_IN_CHAMPIONSHIP`,`FEED_IN_CHAMPIONSHIP_TO_SF`,`FEED_IN_CHAMPIONSHIP_TO_QF`,`FEED_IN_CHAMPIONSHIP_TO_R16`,`FIRST_MATCH_LOSER_CONSOLATION`,`CURTIS_CONSOLATION`,`COMPASS`,`OLYMPIC`];function vX(){return{policyName:``,seedingProfile:{positioning:`SEPARATE`},validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,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}]}}function yX(e){return structuredClone(e)}var bX=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:yX(e.initialPolicy??vX()),expandedSections:new Set([`profile`,`flags`,`thresholds`,`drawTypeOverrides`]),dirty:!1}}getState(){return this.state}getData(){return yX(this.state.draft)}setData(e){this.state={...this.state,draft:yX(e),dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}setPolicyName(e){let t=yX(this.state.draft);t.policyName=e,this.commitDraft(t)}setPositioning(e){let t=yX(this.state.draft);t.seedingProfile??={},t.seedingProfile.positioning=e,this.commitDraft(t)}setValidSeedPositionsIgnore(e){let t=yX(this.state.draft);t.validSeedPositions={ignore:e},this.commitDraft(t)}setDuplicateSeedNumbers(e){let t=yX(this.state.draft);t.duplicateSeedNumbers=e,this.commitDraft(t)}setDrawSizeProgression(e){let t=yX(this.state.draft);t.drawSizeProgression=e,this.commitDraft(t)}addThreshold(){let e=yX(this.state.draft);e.seedsCountThresholds??=[];let t=e.seedsCountThresholds.at(-1),n=t?t.drawSize*2:4;e.seedsCountThresholds.push({drawSize:n,minimumParticipantCount:Math.max(1,Math.floor(n*.75)),seedsCount:Math.max(2,Math.floor(n/4))}),this.commitDraft(e)}removeThreshold(e){let t=yX(this.state.draft);t.seedsCountThresholds&&(t.seedsCountThresholds.splice(e,1),this.commitDraft(t))}setThresholdField(e,t,n){let r=yX(this.state.draft),i=r.seedsCountThresholds?.[e];i&&(i[t]=n,this.commitDraft(r))}sortThresholds(){let e=yX(this.state.draft);e.seedsCountThresholds&&(e.seedsCountThresholds.sort((e,t)=>e.drawSize-t.drawSize),this.commitDraft(e))}addDrawTypeOverride(e,t){if(!e)return;let n=yX(this.state.draft);n.seedingProfile??={},n.seedingProfile.drawTypes??={},n.seedingProfile.drawTypes[e]={positioning:t},this.commitDraft(n)}removeDrawTypeOverride(e){let t=yX(this.state.draft);t.seedingProfile?.drawTypes&&(delete t.seedingProfile.drawTypes[e],Object.keys(t.seedingProfile.drawTypes).length===0&&delete t.seedingProfile.drawTypes,this.commitDraft(t))}setDrawTypeOverridePositioning(e,t){let n=yX(this.state.draft),r=n.seedingProfile?.drawTypes;r?.[e]&&(r[e]={positioning:t},this.commitDraft(n))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(yX(e))}emit(){for(let e of this.listeners)e(this.state)}},xX=()=>`sd-editor`,SX=()=>`sd-section`,CX=()=>`sd-section-header`,wX=()=>`sd-section-chevron`,TX=()=>`sd-section-body`,EX=()=>`sd-field-row`,DX=()=>`sd-field-label`,OX=()=>`sd-field-input`,kX=()=>`sd-checkbox-row`,AX=()=>`sd-checkbox-desc`,jX=()=>`sd-radio-group`,MX=()=>`sd-radio-option`,NX=()=>`sp-btn sp-btn--sm sp-btn--outline sd-add-btn`,PX=()=>`sp-btn sp-btn--sm sp-btn--ghost sd-sort-btn`,FX=()=>`sp-btn-icon sp-btn-icon--danger sd-remove-btn`,IX=()=>`sd-table-wrap`,LX=()=>`sd-table`,RX=()=>`sd-number-cell-input`,zX=()=>`sd-empty`,BX=()=>`sd-actions-row`,VX=()=>`sd-override-row`,HX=()=>`sd-override-add-row`,UX=()=>`sd-override-drawtype`,WX=()=>`sd-select`;function GX(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=EX();let r=document.createElement(`div`);r.className=DX(),r.textContent=`Policy name`;let i=document.createElement(`input`);i.type=`text`,i.className=OX()+` sd-field-input--wide`,i.placeholder=`e.g. USTA SEEDING`,i.addEventListener(`input`,()=>e.setPolicyName(i.value)),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=EX()+` sd-field-row--top`;let o=document.createElement(`div`);o.className=DX(),o.textContent=`Default positioning`,a.appendChild(o);let s=document.createElement(`div`);s.className=jX();let c=[];for(let t of gX){let n=document.createElement(`label`);n.className=MX();let r=document.createElement(`input`);r.type=`radio`,r.name=`sd-positioning`,r.value=t.value,r.addEventListener(`change`,()=>{r.checked&&e.setPositioning(t.value)});let i=document.createElement(`span`);i.innerHTML=`<strong>${t.label}</strong><div class="sd-radio-desc">${t.description}</div>`,n.appendChild(r),n.appendChild(i),s.appendChild(n),c.push({value:t.value,input:r})}a.appendChild(s),t.appendChild(a);function l(e){document.activeElement!==i&&(i.value=e.draft.policyName??``);let t=e.draft.seedingProfile?.positioning;for(let e of c)e.input.checked=e.value===t}return{element:t,update:l}}function KX(e){let t=document.createElement(`div`),n=[{id:`sd-valid-seed-positions-ignore`,label:`Ignore valid seed positions`,description:`Allow seeds to be placed at any drawPosition (rather than only canonical seeded positions).`,read:e=>e.draft.validSeedPositions?.ignore??!1,write:t=>e.setValidSeedPositionsIgnore(t)},{id:`sd-duplicate-seed-numbers`,label:`Allow duplicate seed numbers`,description:`Permit shared seed numbers (e.g. multiple #5 seeds in CLUSTER positioning).`,read:e=>e.draft.duplicateSeedNumbers??!1,write:t=>e.setDuplicateSeedNumbers(t)},{id:`sd-draw-size-progression`,label:`Draw size progression`,description:`Apply thresholds at or below the matched draw size, instead of requiring an exact match.`,read:e=>e.draft.drawSizeProgression??!1,write:t=>e.setDrawSizeProgression(t)}],r=[];for(let e of n){let n=document.createElement(`div`);n.className=kX();let i=document.createElement(`input`);i.type=`checkbox`,i.id=e.id,i.addEventListener(`change`,()=>e.write(i.checked));let a=document.createElement(`label`);a.htmlFor=e.id,a.textContent=e.label;let o=document.createElement(`div`);o.className=AX(),o.textContent=e.description;let s=document.createElement(`div`);s.appendChild(a),s.appendChild(o),n.appendChild(i),n.appendChild(s),t.appendChild(n),r.push({def:e,input:i})}function i(e){for(let t of r)t.input.checked=t.def.read(e)}return{element:t,update:i}}var qX=[{field:`drawSize`,label:`Draw size`,min:2,placeholder:`32`},{field:`minimumParticipantCount`,label:`Min participants`,min:0,placeholder:`24`},{field:`seedsCount`,label:`Seeds`,min:0,placeholder:`8`}];function JX(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=IX();let r=document.createElement(`table`);r.className=LX();let i=document.createElement(`thead`),a=document.createElement(`tr`);for(let e of qX){let t=document.createElement(`th`);t.textContent=e.label,a.appendChild(t)}let o=document.createElement(`th`);o.setAttribute(`aria-label`,`Actions`),a.appendChild(o),i.appendChild(a),r.appendChild(i);let s=document.createElement(`tbody`);r.appendChild(s),n.appendChild(r),t.appendChild(n);let c=document.createElement(`div`);c.className=zX(),c.textContent=`No seed-count thresholds defined. Add a row to configure seeds per draw size.`,t.appendChild(c);let l=document.createElement(`div`);l.className=BX();let u=document.createElement(`button`);u.type=`button`,u.className=NX(),u.textContent=`+ Add threshold`,u.addEventListener(`click`,()=>e.addThreshold());let d=document.createElement(`button`);d.type=`button`,d.className=PX(),d.textContent=`Sort by draw size`,d.addEventListener(`click`,()=>e.sortThresholds()),l.appendChild(u),l.appendChild(d),t.appendChild(l);function f(t){let n=t.draft.seedsCountThresholds??[];if(s.innerHTML=``,n.length===0){r.style.display=`none`,c.style.display=`block`,d.disabled=!0;return}r.style.display=``,c.style.display=`none`,d.disabled=n.length<2;for(let t=0;t<n.length;t++){let r=n[t],i=document.createElement(`tr`);for(let n of qX){let a=document.createElement(`td`),o=document.createElement(`input`);o.type=`number`,o.min=String(n.min),o.className=RX(),o.value=String(r[n.field]),n.placeholder&&(o.placeholder=n.placeholder);let s=t,c=n.field;o.addEventListener(`change`,()=>{let t=parseInt(o.value,10);!isNaN(t)&&t>=n.min?e.setThresholdField(s,c,t):o.value=String(r[n.field])}),a.appendChild(o),i.appendChild(a)}let a=document.createElement(`td`),o=document.createElement(`button`);o.type=`button`,o.className=FX(),o.setAttribute(`aria-label`,`Remove threshold row ${t+1}`),o.textContent=`×`;let c=t;o.addEventListener(`click`,()=>e.removeThreshold(c)),a.appendChild(o),i.appendChild(a),s.appendChild(i)}}return{element:t,update:f}}function YX(e,t){let n=document.createElement(`select`);n.className=WX();for(let e of gX){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,n.appendChild(t)}return n.value=e,n.addEventListener(`change`,()=>t(n.value)),n}function XX(e,t){let n=document.createElement(`div`),r=t.drawTypes??_X,i=document.createElement(`div`);n.appendChild(i);let a=document.createElement(`div`);a.className=zX(),a.textContent=`No draw-type overrides. The default positioning is used for every drawType.`,n.appendChild(a);let o=document.createElement(`div`);o.className=HX();let s=document.createElement(`select`);s.className=WX();function c(e){s.innerHTML=``;let t=document.createElement(`option`);t.value=``,t.textContent=`Select drawType…`,s.appendChild(t);for(let t of r){if(e.has(t))continue;let n=document.createElement(`option`);n.value=t,n.textContent=t,s.appendChild(n)}}let l=YX(`WATERFALL`,()=>{}),u=document.createElement(`button`);u.type=`button`,u.className=NX(),u.textContent=`+ Add override`,u.addEventListener(`click`,()=>{let t=s.value;t&&e.addDrawTypeOverride(t,l.value)});let d=document.createElement(`div`);d.className=BX(),d.appendChild(s),d.appendChild(l),d.appendChild(u),o.appendChild(d),n.appendChild(o);function f(t){let n=t.draft.seedingProfile?.drawTypes??{},r=Object.entries(n);if(i.innerHTML=``,r.length===0)a.style.display=`block`;else{a.style.display=`none`;for(let[t,{positioning:n}]of r){let r=document.createElement(`div`);r.className=VX();let a=document.createElement(`div`);a.className=UX(),a.textContent=t;let o=YX(n,n=>e.setDrawTypeOverridePositioning(t,n)),s=document.createElement(`button`);s.type=`button`,s.className=FX(),s.setAttribute(`aria-label`,`Remove override for ${t}`),s.textContent=`×`,s.addEventListener(`click`,()=>e.removeDrawTypeOverride(t)),r.appendChild(a),r.appendChild(o),r.appendChild(s),i.appendChild(r)}}c(new Set(Object.keys(n))),u.disabled=s.options.length<=1}return{element:n,update:f}}function ZX(e,t){let n=document.createElement(`div`);n.className=xX();let r=[{id:`profile`,label:`Profile`,factory:()=>GX(e)},{id:`flags`,label:`Flags`,factory:()=>KX(e)},{id:`thresholds`,label:`Seed Count Thresholds`,factory:()=>JX(e)},{id:`drawTypeOverrides`,label:`Draw Type Overrides`,factory:()=>XX(e,t)}],i=[];for(let t of r){let r=document.createElement(`div`);r.className=SX();let a=document.createElement(`div`);a.className=CX();let o=document.createElement(`span`);o.className=wX();let s=document.createElement(`span`);s.textContent=t.label,a.appendChild(o),a.appendChild(s),a.addEventListener(`click`,()=>e.toggleSection(t.id));let c=document.createElement(`div`);c.className=TX();let l=t.factory();c.appendChild(l.element),r.appendChild(a),r.appendChild(c),n.appendChild(r),i.push({id:t.id,chevron:o,bodyEl:c,inner:l})}function a(e){for(let t of i){let n=e.expandedSections.has(t.id);t.chevron.textContent=n?`▼`:`▶`,t.bodyEl.style.display=n?`block`:`none`,n&&t.inner.update(e)}}return{element:n,update:a}}var QX=class e{constructor(e){this.container=null,this.store=new bX(e),this.panel=ZX(this.store,e),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}},$X=t.factoryConstants.policyConstants.POLICY_TYPE_PARTICIPANT;function eZ(e){return structuredClone(e)}function tZ(){return eZ(t.fixtures.policies.POLICY_PRIVACY_DEFAULT[$X])}function nZ(e){return e?.participant??{}}function rZ(e){let t=e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1)}function iZ(){let e=nZ(tZ()),t=Object.keys(e).filter(t=>typeof e[t]==`boolean`).map(e=>({field:e,group:`participant`,label:rZ(e)})),n=Object.keys(e.person??{}).filter(t=>typeof e.person[t]==`boolean`).map(e=>({field:e,group:`person`,label:rZ(e)}));return[...t,...n]}function aZ(e,t,n){let r=nZ(e);return t===`person`?!!r.person?.[n]:!!r[n]}function oZ(e,t,n,r){let i=nZ(e),a=(e,t)=>{e&&n in e&&(e[n]=r),t&&n in t&&(t[n]=r)};t===`person`?a(i.person,i.individualParticipants?.person):a(i,i.individualParticipants)}function sZ(e){return e?.policyName??``}function cZ(e,t){e&&(e.policyName=t)}function lZ(e){return structuredClone(e)}var uZ=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:lZ(e.initialPolicy??tZ()),dirty:!1}}getState(){return this.state}getData(){return lZ(this.state.draft)}setData(e){this.state={...this.state,draft:lZ(e),dirty:!1},this.emit()}setPolicyName(e){let t=lZ(this.state.draft);cZ(t,e),this.commitDraft(t)}setField(e,t,n){let r=lZ(this.state.draft);oZ(r,e,t,n),this.commitDraft(r)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(lZ(e))}emit(){for(let e of this.listeners)e(this.state)}};function dZ(e,t){let n=document.createElement(`div`);n.className=`privacy-editor`;let r=document.createElement(`p`);r.className=`privacy-editor__intro`,r.textContent=`Choose which participant details are published publicly. Unchecked = kept private.`,n.appendChild(r);let i=document.createElement(`label`);i.className=`privacy-editor__name`;let a=document.createElement(`span`);a.textContent=`Policy name`;let o=document.createElement(`input`);o.type=`text`,o.placeholder=`e.g. Public roster privacy`,o.addEventListener(`input`,()=>e.setPolicyName(o.value)),i.append(a,o),n.appendChild(i);let s=iZ(),c=new Map,l=(t,r)=>{let i=document.createElement(`section`);i.className=`privacy-editor__group`;let a=document.createElement(`h4`);a.textContent=r,i.appendChild(a);let o=document.createElement(`div`);o.className=`privacy-editor__grid`;for(let n of s.filter(e=>e.group===t)){let r=document.createElement(`label`);r.className=`privacy-editor__toggle`;let i=document.createElement(`input`);i.type=`checkbox`,i.addEventListener(`change`,()=>e.setField(t,n.field,i.checked));let a=document.createElement(`span`);a.textContent=n.label,r.append(i,a),o.appendChild(r),c.set(`${t}.${n.field}`,i)}i.appendChild(o),n.appendChild(i)};return l(`person`,`Person details`),l(`participant`,`Participant details`),{element:n,update:e=>{o.value=sZ(e.draft);for(let t of s){let n=c.get(`${t.group}.${t.field}`);n&&(n.checked=aZ(e.draft,t.group,t.field))}}}}var fZ=class e{constructor(e){this.container=null,this.store=new uZ(e),this.panel=dZ(this.store,e),this.unsubscribe=this.store.subscribe(e=>this.panel.update(e)),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}},pZ=()=>`pc-layout`,mZ=()=>`pc-panel`,hZ=()=>`pc-panel-header`,gZ=()=>`pc-panel-title`,_Z=()=>`pc-panel-meta`,vZ=()=>`pc-toolbar`,yZ=()=>`pc-input`,bZ=()=>`pc-select`,xZ=()=>`pc-catalog`,SZ=()=>`pc-group`,CZ=()=>`pc-group-header`,wZ=()=>`pc-group-chevron`,TZ=()=>`pc-group-body`,EZ=()=>`pc-card`,DZ=()=>`pc-card-title`,OZ=()=>`pc-card-meta`,kZ=()=>`pc-type-badge`,AZ=()=>`pc-editor`,jZ=()=>`pc-editor-header`,MZ=()=>`pc-editor-header-left`,NZ=()=>`pc-editor-actions`,PZ=()=>`sp-btn sp-btn--sm`,FZ=()=>`sp-btn sp-btn--sm sp-btn--accent`,IZ=()=>`pc-dirty-dot`,LZ=()=>`pc-editor-body`,RZ=()=>`pc-empty`,zZ=()=>`pc-json-editor`,BZ=()=>`pc-json-error`;function VZ(e){let t=document.createElement(`div`);t.className=pZ(),t.appendChild(e.catalogPanel.element),t.appendChild(e.editorShell.element);function n(t){e.catalogPanel.update(t),e.editorShell.update(t)}return{element:t,update:n}}var HZ=`scheduling`,UZ=`scoring`,WZ=`seeding`,GZ=`draws`,KZ=`avoidance`,qZ=`feedIn`,JZ=`progression`,YZ=`roundNaming`,XZ=`positionActions`,ZZ=`matchUpActions`,QZ=`roundRobinTally`,$Z=`rankingPoints`,eQ=`competitiveBands`,tQ=`voluntaryConsolation`,nQ=`participant`,rQ=`display`,iQ=`audit`,aQ=`Tournament Operations`,oQ=`Scoring & Results`,sQ=`Ranking Points`,cQ=`Draw Configuration`,lQ=`Participants`,uQ=`Display & Audit`,dQ=(e,t,n,r,i)=>({policyType:e,label:t,description:n,group:r,hasEditor:i}),fQ=[dQ(HZ,`Scheduling`,`Match scheduling, average times, recovery times, daily limits`,aQ,!0),dQ(XZ,`Position Actions`,`Allowed position actions (alternates, walkovers, withdrawals)`,aQ,!1),dQ(ZZ,`MatchUp Actions`,`Allowed matchUp status transitions and actions`,aQ,!1),dQ(KZ,`Avoidance`,`Draw placement avoidance rules (club, nationality, region)`,aQ,!1),dQ(UZ,`Scoring`,`Score entry validation and completion rules`,oQ,!0),dQ(QZ,`Round Robin Tally`,`Round-robin group standing calculation method`,oQ,!1),dQ($Z,`Ranking Points`,`Point allocation by draw size, round, and result`,sQ,!0),dQ(eQ,`Competitive Bands`,`Rating/ranking band definitions for competitive grouping`,oQ,!1),dQ(GZ,`Draws`,`Draw generation rules and structure options`,cQ,!1),dQ(WZ,`Seeding`,`Seeding thresholds and placement rules by draw size`,cQ,!0),dQ(qZ,`Feed-In`,`Feed-in consolation structure rules`,cQ,!1),dQ(JZ,`Progression`,`Player progression between draw structures`,cQ,!1),dQ(tQ,`Voluntary Consolation`,`Voluntary consolation entry rules`,cQ,!1),dQ(YZ,`Round Naming`,`Custom round name labels (QF, SF, F, etc.)`,cQ,!1),dQ(nQ,`Participant Privacy`,`Which participant details are published publicly`,lQ,!0),dQ(rQ,`Display`,`Client display configuration (public vs admin views)`,uQ,!1),dQ(iQ,`Audit`,`Audit trail and change logging configuration`,uQ,!1)];function pQ(e){return fQ.find(t=>t.policyType===e)}function mQ(e){return e===`rankingPoints`?_q():e===`scheduling`?kJ():e===`scoring`?PY():e===`seeding`?vX():e===`participant`?tZ():{}}var hQ=[aQ,oQ,sQ,cQ,lQ,uQ];function gQ(e,t){let n=t.toLowerCase().trim();return n?e.filter(e=>{let t=pQ(e.policyType);return[e.name,e.description,e.policyType,t?.label??``,e.source].join(` `).toLowerCase().includes(n)}):e}function _Q(e,t){let n=new Map;if(t===`type`){for(let e of hQ)n.set(e,[]);for(let t of e){let e=pQ(t.policyType)?.group??`Display & Audit`,r=n.get(e);r?r.push(t):n.set(e,[t])}for(let[e,t]of n)t.length===0&&n.delete(e)}else for(let t of e){let e=t.source===`builtin`?`Built-in Policies`:`User Policies`,r=n.get(e);r?r.push(t):n.set(e,[t])}return n}function vQ(e){let t=document.createElement(`div`);t.className=mZ(),t.style.overflowY=`auto`,t.style.scrollbarWidth=`thin`,t.style.scrollbarColor=`var(--sp-scrollbar) transparent`;let n=new Set,r=null,i=document.createElement(`div`);i.className=hZ();let a=document.createElement(`div`);a.className=gZ(),a.textContent=`Policy Catalog`;let o=document.createElement(`div`);o.className=_Z(),i.appendChild(a),i.appendChild(o),t.appendChild(i);let s=document.createElement(`div`);s.className=vZ();let c=document.createElement(`input`);c.type=`text`,c.placeholder=`Search policies...`,c.className=yZ(),c.addEventListener(`input`,()=>e.onSearchChange(c.value));let l=document.createElement(`select`);l.className=bZ();for(let[e,t]of[[`type`,`By Type`],[`source`,`By Source`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,l.appendChild(n)}l.addEventListener(`change`,()=>e.onGroupByChange(l.value));let u=document.createElement(`div`);u.style.cssText=`position:relative;flex-shrink:0`;let d=document.createElement(`button`);d.className=`sp-btn-icon`,d.textContent=`+`,d.title=`New policy`,d.style.cssText=`font-size:1rem;font-weight:700`;let f=document.createElement(`div`);f.style.cssText=`display:none;position:absolute;top:100%;right:0;z-index:100;min-width:180px;background:var(--sp-panel-bg);border:1px solid var(--sp-border);border-radius:12px;box-shadow:var(--sp-panel-shadow);padding:4px;margin-top:4px`;let p=fQ.filter(e=>e.hasEditor);for(let t of p){let n=document.createElement(`div`);n.style.cssText=`padding:6px 10px;font-size:12px;border-radius:8px;cursor:pointer;color:var(--sp-text)`,n.textContent=t.label,n.addEventListener(`mouseenter`,()=>{n.style.background=`var(--sp-hover-bg)`}),n.addEventListener(`mouseleave`,()=>{n.style.background=``}),n.addEventListener(`click`,n=>{n.stopPropagation(),f.style.display=`none`,e.onNewPolicy?.(t.policyType)}),f.appendChild(n)}d.addEventListener(`click`,e=>{e.stopPropagation(),f.style.display=f.style.display===`none`?`block`:`none`}),document.addEventListener(`click`,()=>{f.style.display=`none`}),u.appendChild(d),u.appendChild(f),s.appendChild(c),s.appendChild(l),s.appendChild(u),t.appendChild(s);let m=document.createElement(`div`);m.className=xZ(),t.appendChild(m);function h(t){r=t;let i=gQ(t.catalog,t.searchQuery),a=_Q(i,t.groupBy);o.textContent=`${i.length} policies`,c.value!==t.searchQuery&&(c.value=t.searchQuery),l.value!==t.groupBy&&(l.value=t.groupBy),m.innerHTML=``;for(let[i,o]of a){let a=document.createElement(`div`);a.className=SZ();let s=n.has(i),c=document.createElement(`div`);c.className=CZ();let l=document.createElement(`span`);l.className=wZ(),l.textContent=s?`▶`:`▼`;let u=document.createElement(`span`);u.textContent=`${i} (${o.length})`,c.appendChild(l),c.appendChild(u),c.addEventListener(`click`,()=>{n.has(i)?n.delete(i):n.add(i),r&&h(r)});let d=document.createElement(`div`);d.className=TZ(),s&&(d.style.display=`none`);for(let n of o){let r=document.createElement(`div`);r.className=EZ(),n.id===t.selectedId&&r.classList.add(`active`),r.addEventListener(`click`,()=>e.onSelectPolicy(n.id));let i=document.createElement(`div`);i.style.cssText=`display:flex;align-items:center;gap:4px`;let a=document.createElement(`div`);if(a.className=DZ(),a.style.flex=`1`,a.textContent=n.name,i.appendChild(a),e.onDuplicatePolicy){let t=document.createElement(`span`);t.style.cssText=`font-size:10px;cursor:pointer;color:var(--sp-muted);padding:2px`,t.textContent=`⎘`,t.title=`Duplicate`,t.addEventListener(`click`,t=>{t.stopPropagation(),e.onDuplicatePolicy?.(n.id)}),i.appendChild(t)}if(n.source===`user`&&e.onDeletePolicy){let t=document.createElement(`span`);t.style.cssText=`font-size:10px;cursor:pointer;color:var(--sp-muted);padding:2px`,t.textContent=`✕`,t.title=`Delete`,t.addEventListener(`click`,t=>{t.stopPropagation(),e.onDeletePolicy?.(n.id)}),i.appendChild(t)}r.appendChild(i);let o=document.createElement(`div`);o.className=OZ();let s=pQ(n.policyType),c=document.createElement(`span`);c.className=kZ(),c.textContent=s?.label??n.policyType;let l=document.createElement(`span`);l.className=`${kZ()} ${n.source}`,l.textContent=n.source,o.appendChild(c),o.appendChild(l),r.appendChild(o),d.appendChild(r)}a.appendChild(c),a.appendChild(d),m.appendChild(a)}}return{element:t,update:h}}function yQ(e){return structuredClone(e)}var bQ=class{constructor(e){this.listeners=new Set,this.localIdCounter=0,this.config=e;let t=new Set((e.builtinPolicies??[]).map(e=>e.id)),n=[...e.builtinPolicies??[],...(e.userPolicies??[]).filter(e=>!t.has(e.id))];this.state={catalog:n,searchQuery:``,groupBy:`type`,selectedId:null,editorDraft:null,editedName:null,dirty:!1}}getState(){return this.state}getSelectedItem(){return this.state.selectedId?this.state.catalog.find(e=>e.id===this.state.selectedId)??null:null}setCatalogSearch(e){this.setState({searchQuery:e})}setCatalogGroupBy(e){this.setState({groupBy:e})}selectPolicy(e){if(this.state.selectedId===e)return;let t=this.state.catalog.find(t=>t.id===e);t&&(this.setState({selectedId:e,editorDraft:yQ(t.policyData),editedName:t.name,dirty:!1}),this.config.onSelectionChanged?.(t))}clearSelection(){this.state.selectedId&&(this.setState({selectedId:null,editorDraft:null,editedName:null,dirty:!1}),this.config.onSelectionChanged?.(null))}renamePolicy(e){if(!this.state.selectedId)return;let t=this.getSelectedItem();!t||t.source===`builtin`||this.state.editedName!==e&&this.setState({editedName:e,dirty:!0})}updateEditorDraft(e){this.setState({editorDraft:e,dirty:!0})}markDirty(){this.state.dirty||this.setState({dirty:!0})}markClean(){this.state.dirty&&this.setState({dirty:!1})}savePolicy(){let e=this.getSelectedItem();if(!e||!this.state.editorDraft)return;let t={...e,name:this.state.editedName??e.name,policyData:yQ(this.state.editorDraft)},n=this.state.catalog.map(e=>e.id===t.id?t:e);this.state={...this.state,catalog:n,dirty:!1},this.emit(),this.config.onPolicySaved?.(t)}resetDraft(){let e=this.getSelectedItem();e&&this.setState({editorDraft:yQ(e.policyData),editedName:e.name,dirty:!1})}applyPolicy(){let e=this.getSelectedItem();if(!e)return;let t={...e,policyData:this.state.editorDraft?yQ(this.state.editorDraft):yQ(e.policyData)};this.config.onPolicyApplied?.(t)}addNewPolicy(e){let t=this.nextLocalId(e),n={id:t,name:`New ${e} policy`,policyType:e,source:`user`,description:``,policyData:mQ(e)};return this.appendAndSelect(n),this.runCreateAndReconcile(n),t}duplicatePolicy(e){let t=this.state.catalog.find(t=>t.id===e);if(!t)return null;let n=this.nextLocalId(t.policyType),r={id:n,name:`${t.name} (Copy)`,policyType:t.policyType,source:`user`,description:t.description,policyData:yQ(t.policyData)};return this.appendAndSelect(r),this.runCreateAndReconcile(r),n}reconcilePolicyId(e,t){if(e===t||this.state.catalog.findIndex(t=>t.id===e)===-1)return;let n=this.state.catalog.map(n=>n.id===e?{...n,id:t}:n),r=this.state.selectedId===e;this.state={...this.state,catalog:n,...r?{selectedId:t}:{}},this.emit()}deletePolicy(e){let t=this.state.catalog.find(t=>t.id===e);if(!t||t.source===`builtin`)return;let n=this.state.catalog.filter(t=>t.id!==e),r=this.state.selectedId===e;this.state={...this.state,catalog:n,...r?{selectedId:null,editorDraft:null,dirty:!1}:{}},this.emit(),this.config.onPolicyDeleted?.(e),r&&this.config.onSelectionChanged?.(null)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setState(e){this.state={...this.state,...e},this.emit()}emit(){for(let e of this.listeners)e(this.state)}nextLocalId(e){return this.localIdCounter+=1,`user-${e}-${Date.now()}-${this.localIdCounter}`}appendAndSelect(e){let t=[...this.state.catalog,e];this.state={...this.state,catalog:t,selectedId:e.id,editorDraft:yQ(e.policyData),editedName:e.name,dirty:!1},this.emit(),this.config.onSelectionChanged?.(e)}runCreateAndReconcile(e){let t=this.config.onPolicyCreated?.(e);if(t!==void 0){if(typeof t==`string`){this.reconcilePolicyId(e.id,t);return}Promise.resolve(t).then(t=>{typeof t==`string`&&this.reconcilePolicyId(e.id,t)}).catch(()=>{})}}};function xQ(e){let t=document.createElement(`div`);t.className=mZ();let n=document.createElement(`div`);n.className=AZ();let r=document.createElement(`div`);r.className=jZ();let i=document.createElement(`div`);i.className=MZ();let a=document.createElement(`div`);a.className=gZ();let o=document.createElement(`input`);o.type=`text`,o.className=`${gZ()} pc-name-input`,o.setAttribute(`aria-label`,`Policy name`),o.setAttribute(`data-testid`,`pc-name-input`),o.placeholder=`Policy name`,o.addEventListener(`input`,()=>e.onRename(o.value));let s=document.createElement(`span`);s.className=kZ();let c=document.createElement(`span`);c.className=kZ(),c.textContent=`read-only`,c.style.display=`none`;let l=document.createElement(`div`);l.className=IZ(),l.style.display=`none`,l.title=`Unsaved changes`,i.appendChild(l),i.appendChild(a),i.appendChild(o),i.appendChild(s),i.appendChild(c);let u=document.createElement(`div`);u.className=NZ();let d=document.createElement(`button`);d.className=PZ(),d.textContent=`Reset`,d.addEventListener(`click`,()=>e.onReset());let f=document.createElement(`button`);f.className=FZ(),f.textContent=`Save`,f.addEventListener(`click`,()=>e.onSave());let p=document.createElement(`button`);p.className=PZ(),p.textContent=`Apply`,p.addEventListener(`click`,()=>e.onApply());let m=document.createElement(`button`);m.className=PZ(),m.textContent=`Duplicate`,m.addEventListener(`click`,()=>e.onDuplicate()),u.appendChild(d),u.appendChild(f),u.appendChild(p),u.appendChild(m);let h=document.createElement(`div`);h.className=NZ();let g=document.createElement(`button`);g.className=FZ(),g.textContent=`Use as Template`,g.addEventListener(`click`,()=>e.onDuplicate()),h.appendChild(g),r.appendChild(i),r.appendChild(u),r.appendChild(h);let _=document.createElement(`div`);_.className=LZ(),n.appendChild(r),n.appendChild(_);let v=document.createElement(`div`);v.className=RZ(),v.textContent=`Select a policy to edit`,t.appendChild(n),t.appendChild(v);function y(e){let t=e.selectedId!==null;if(n.style.display=t?`flex`:`none`,v.style.display=t?`none`:`flex`,!t)return;let r=e.catalog.find(t=>t.id===e.selectedId);if(!r)return;let i=r.source===`builtin`,d=e.editedName??r.name;a.textContent=d,document.activeElement!==o&&o.value!==d&&(o.value=d);let f=pQ(r.policyType);s.textContent=f?.label??r.policyType,a.style.display=i?``:`none`,o.style.display=i?`none`:``,c.style.display=i?``:`none`,u.style.display=i?`none`:`flex`,h.style.display=i?`flex`:`none`,l.style.display=!i&&e.dirty?`block`:`none`}return{element:t,update:y,bodyElement:_}}function SQ(e){let t=document.createElement(`div`);t.className=zZ();let n=document.createElement(`textarea`);n.value=JSON.stringify(e.initialData,null,2);let r=document.createElement(`div`);r.className=BZ(),r.style.display=`none`;let i={...e.initialData};return n.addEventListener(`input`,()=>{try{let t=JSON.parse(n.value);i=t,r.style.display=`none`,e.onChange(t)}catch(e){r.style.display=`block`,r.textContent=`Invalid JSON: ${e.message}`}}),t.appendChild(n),t.appendChild(r),{element:t,setData(e){i={...e},n.value=JSON.stringify(e,null,2),r.style.display=`none`},getData(){return{...i}},destroy(){t.remove()}}}var CQ=class{constructor(e){this.currentEditor=null,this.container=null,this.store=new bQ(e);let t=vQ({onSearchChange:e=>this.store.setCatalogSearch(e),onGroupByChange:e=>this.store.setCatalogGroupBy(e),onSelectPolicy:e=>this.handleSelectPolicy(e),onNewPolicy:e=>{this.store.addNewPolicy(e),this.mountEditorForSelection()},onDuplicatePolicy:e=>{this.store.duplicatePolicy(e),this.mountEditorForSelection()},onDeletePolicy:e=>{this.store.deletePolicy(e),this.store.getSelectedItem()||this.destroyCurrentEditor()}});this.editorShell=xQ({onSave:()=>this.store.savePolicy(),onReset:()=>{this.store.resetDraft(),this.syncEditorFromStore()},onApply:()=>this.store.applyPolicy(),onDuplicate:()=>{let e=this.store.getSelectedItem();e&&(this.store.duplicatePolicy(e.id),this.mountEditorForSelection())},onRename:e=>this.store.renamePolicy(e)}),this.layout=VZ({catalogPanel:t,editorShell:this.editorShell}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.layout.element)}destroy(){this.destroyCurrentEditor(),this.unsubscribe(),this.container&&this.layout.element.parentNode===this.container&&this.layout.element.remove(),this.container=null}getStore(){return this.store}handleSelectPolicy(e){this.store.selectPolicy(e),this.mountEditorForSelection()}mountEditorForSelection(){this.destroyCurrentEditor();let e=this.store.getSelectedItem();if(!e)return;let t=e.source===`builtin`,n={initialData:{...e.policyData},onChange:e=>{this.store.updateEditorDraft(e)},readonly:t};this.currentEditor=e.policyType===`scheduling`?CY.createEditorInstance(n):e.policyType===`rankingPoints`?EJ.createEditorInstance(n):e.policyType===`seeding`?QX.createEditorInstance(n):e.policyType===`scoring`?hX.createEditorInstance(n):e.policyType===`participant`?fZ.createEditorInstance(n):SQ(n),this.editorShell.bodyElement.innerHTML=``,this.editorShell.bodyElement.appendChild(this.currentEditor.element)}syncEditorFromStore(){let e=this.store.getState();this.currentEditor&&e.editorDraft&&this.currentEditor.setData(e.editorDraft)}destroyCurrentEditor(){this.currentEditor&&=(this.currentEditor.destroy(),null),this.editorShell.bodyElement.innerHTML=``}};function wQ(e,t,n,r){e!==void 0&&e<0&&r.push({severity:`error`,path:t,message:n})}function TQ(e,t){if(!e.defaultTimes)return;let n=e.defaultTimes.averageTimes;if(n)for(let e=0;e<n.length;e++)wQ(n[e].minutes.default,`defaultTimes.averageTimes[${e}].minutes.default`,`Default average time must be non-negative`,t),wQ(n[e].minutes.DOUBLES,`defaultTimes.averageTimes[${e}].minutes.DOUBLES`,`Doubles average time must be non-negative`,t);let r=e.defaultTimes.recoveryTimes;if(r)for(let e=0;e<r.length;e++)wQ(r[e].minutes.default,`defaultTimes.recoveryTimes[${e}].minutes.default`,`Default recovery time must be non-negative`,t)}function EQ(e,t){if(!e.defaultDailyLimits)return;let n=e.defaultDailyLimits;wQ(n.SINGLES,`defaultDailyLimits.SINGLES`,`Singles daily limit must be non-negative`,t),wQ(n.DOUBLES,`defaultDailyLimits.DOUBLES`,`Doubles daily limit must be non-negative`,t),wQ(n.total,`defaultDailyLimits.total`,`Total daily limit must be non-negative`,t)}function DQ(e){let t=[];return TQ(e,t),EQ(e,t),e.matchUpAverageTimes&&OQ(e.matchUpAverageTimes,`matchUpAverageTimes`,`averageTimes`,t),e.matchUpRecoveryTimes&&kQ(e.matchUpRecoveryTimes,`matchUpRecoveryTimes`,t),AQ(e,t),t}function OQ(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];a.matchUpFormatCodes.length||r.push({severity:`error`,path:`${t}[${i}].matchUpFormatCodes`,message:`At least one format code is required per format group`});let o=a[n];if(o)for(let e=0;e<o.length;e++)wQ(o[e].minutes.default,`${t}[${i}].${n}[${e}].minutes.default`,`Time must be non-negative`,r),wQ(o[e].minutes.DOUBLES,`${t}[${i}].${n}[${e}].minutes.DOUBLES`,`Doubles time must be non-negative`,r)}}function kQ(e,t,n){for(let r=0;r<e.length;r++){let i=e[r];i.matchUpFormatCodes.length||n.push({severity:`error`,path:`${t}[${r}].matchUpFormatCodes`,message:`At least one format code is required per format group`});for(let e=0;e<i.recoveryTimes.length;e++)wQ(i.recoveryTimes[e].minutes.default,`${t}[${r}].recoveryTimes[${e}].minutes.default`,`Recovery time must be non-negative`,n),wQ(i.recoveryTimes[e].minutes.DOUBLES,`${t}[${r}].recoveryTimes[${e}].minutes.DOUBLES`,`Doubles recovery time must be non-negative`,n)}}function AQ(e,t){let n=(e,n)=>{if(!e)return;let r=new Map;for(let i=0;i<e.length;i++)for(let a of e[i].matchUpFormatCodes)r.has(a)?t.push({severity:`warning`,path:`${n}[${i}].matchUpFormatCodes`,message:`Format code "${a}" also appears in group ${r.get(a)}`}):r.set(a,i)};n(e.matchUpAverageTimes,`matchUpAverageTimes`),n(e.matchUpRecoveryTimes,`matchUpRecoveryTimes`)}function jQ(e,t){let n=new CQ(e);return n.render(t),n}e.AvailabilityGrid=Zz,e.COMPETITIVENESS_BUCKETS=Fv,e.COMPETITIVENESS_COLORS=pM,e.COURT_SVG_RESOURCE_SUB_TYPE=ph,e.CompositionEditorStore=AG,e.DEFAULT_COMPETITIVE_BANDS=dM,e.DEFAULT_COURT_CARD_CONFIG=F_,e.DEFAULT_DRAW_CARD_CONFIG=$v,e.DEFAULT_EVENT_CARD_CONFIG=Gy,e.DEFAULT_SCHEDULE_CELL_CONFIG=sG,e.DEFAULT_TOURNAMENT_CARD_CONFIG=Lh,e.DEFAULT_VENUE_CARD_CONFIG=Gg,e.DrawStateManager=Zx,e.EVENT_CARD_LIGHT_MODE_THRESHOLD=Ky,e.InlineScoringManager=gs,e.MATCH_FORMATS=Bx,e.NEUTRAL_SEGMENT_COLOR=mM,e.POLICY_TYPE_GROUPS=hQ,e.POLICY_TYPE_METADATA=fQ,e.PolicyCatalogControl=CQ,e.PolicyCatalogStore=bQ,e.ProfileStore=pI,e.SchedulePageControl=FW,e.SchedulePageStore=PW,e.SchedulingEditorControl=CY,e.SchedulingEditorStore=jJ,e.SchedulingProfileControl=EI,e.TopologyBuilderControl=ZH,e.TopologyStore=XB,e.activateScheduleCellTypeAhead=OG,e.aggregateCompetitiveness=Rv,e.applyDropCommit=rI,e.badmintonCourt=dh,e.barButton=tP,e.baseballDiamond=ch,e.basketballCourt=sh,e.buildActiveStripPanel=iG,e.buildCardSkeleton=Ih,e.buildCompetitivenessBar=Vv,e.buildCompetitivenessDonut=Zv,e.buildCourtCard=tv,e.buildCourtGridSlot=NW,e.buildCourtSkeletonCard=_v,e.buildDateStrip=wI,e.buildDrawCard=yy,e.buildDrawSkeletonCard=Ry,e.buildEdgeEditor=GV,e.buildEditorShell=xQ,e.buildEventCard=yb,e.buildEventSkeletonCard=Lb,e.buildHiveIDLogin=Mx,e.buildInteractiveScoringShell=dq,e.buildIssueIndex=tI,e.buildIssuesPanel=zF,e.buildJsonEditor=SQ,e.buildLadderChart=KN,e.buildMatchUpCard=TW,e.buildMatchUpCatalog=OW,e.buildNodeEditor=NV,e.buildPolicyCatalogLayout=VZ,e.buildPolicyCatalogPanel=vQ,e.buildRatingDistributionChart=zN,e.buildRoundCard=yI,e.buildRoundCatalog=PF,e.buildScheduleDateStrip=MW,e.buildScheduleGridCell=cG,e.buildScheduleInspectorPanel=dW,e.buildScheduleIssueIndex=kW,e.buildScheduleIssuesPanel=jW,e.buildSchedulePageLayout=sW,e.buildSchedulingEditorPanel=SY,e.buildSchedulingProfileLayout=_F,e.buildSegmentedBar=Qv,e.buildSetScore=Gs,e.buildSkeletonCard=Og,e.buildStructureCard=LB,e.buildStructureMinimap=Ci,e.buildTeamCard=Mv,e.buildToolbar=bH,e.buildTopologyBuilderLayout=xH,e.buildTopologyCanvas=sV,e.buildTournamentCard=lg,e.buildVenueBoard=xI,e.buildVenueCard=f_,e.buildVenueSkeletonCard=k_,e.burstChart=KM,e.cModal=z,e.calculateComplement=Vs,e.competitivenessColor=SM,e.completeMagicLink=Nx,e.compositions=mi,e.computeActiveStrip=GW,e.computeActiveStripCell=WW,e.computeBaseRoundByEvent=gW,e.computeReschedulePlacements=QW,e.consumeMagicLink=Sx,e.controlBar=yP,e.courthiveComponentsVersion=zx,e.createAvailabilityGrid=Qz,e.createCardPopoverManager=vF,e.createCompositionEditor=jK,e.createCourtSvg=bh,e.createInlineScoringFooter=lq,e.createNotesEditor=$m,e.createPolicyCatalog=jQ,e.createPrintCompositionEditor=LK,e.createSchedulePage=kG,e.createSchedulingEditor=wY,e.createSchedulingProfile=DI,e.destroyTipster=rh,e.drawer=bd,e.dropDownButton=XN,e.emptySchedulingPolicy=kJ,e.engineToMatchUp=ms,e.extractCourtSvgSport=Fh,e.extractImageURL=Ph,e.filterCatalog=OF,e.filterMatchUpCatalog=hW,e.filterPolicyCatalog=gQ,e.findIssuesForLocator=lI,e.formatAddress=Sh,e.formatCodeLabel=DJ,e.formatDateRange=Mh,e.formatFeeRange=zg,e.formatVenueLocation=Ch,e.fromFactoryDrawData=aN,e.fromLegacyDraw=cN,e.generatePreviewMatchUps=pB,e.getAgeCategoryModal=Ao,e.getCategoryModal=No,e.getCompetitivenessBand=yM,e.getCompetitivenessFromScoreString=bM,e.getFlightProfileModal=us,e.getGenerateTeamsModal=Ki,e.getMatchUpFormatModal=Ha,e.getMatchWinner=Bs,e.getMaxAllowedScore=Is,e.getMockParticipantsModal=Bi,e.getPlannedRoundKeys=AF,e.getPolicyTypeMeta=pQ,e.getPortPosition=RB,e.getRoundAt=cI,e.getScoringConfig=ys,e.getSetFormatForIndex=Ns,e.getSetWinner=Rs,e.getVenueRounds=sI,e.groupCatalog=kF,e.groupMatchUpCatalog=wW,e.groupPolicyCatalog=_Q,e.hockeyRink=lh,e.initDrawer=xd,e.isCompletedStatus=mW,e.isExistingUserConflict=Cx,e.isMatchComplete=zs,e.isSetComplete=Ls,e.isSetTiebreakOnly=Ps,e.isSetTimed=Fs,e.mapCourtToCardData=wv,e.mapDrawDefinitionToCardData=Wy,e.mapEventToCardData=ex,e.mapMatchUpToCellData=DG,e.mapTournamentToCardData=Ug,e.mapVenueToCardData=P_,e.matchUpLabel=cW,e.matchUpSearchKey=uW,e.maxSeverity=dI,e.mergeCourtCardConfig=I_,e.mergeDrawCardConfig=ey,e.mergeEventCardConfig=qy,e.mergeTournamentCardConfig=Rh,e.mergeVenueCardConfig=Kg,e.notesToolbar=Fm,e.openCompositionEditorModal=Qi,e.openScheduleCellConfigModal=ea,e.padelCourt=fh,e.participantLabel=lW,e.pickProgressionStructure=iN,e.pickleballCourt=uh,e.renderButtons=Vx,e.renderContainer=ii,e.renderField=gn,e.renderForm=Oi,e.renderInlineMatchUp=fs,e.renderMatchUp=ei,e.renderMenu=eh,e.renderOptions=hn,e.renderParticipant=hr,e.renderParticipantInput=Cn,e.renderRound=ti,e.renderRoundHeader=_r,e.renderSchematicMatchUp=Ti,e.renderSchematicRound=Ei,e.renderSchematicStructure=Di,e.renderScorecard=$K,e.renderStructure=ni,e.renderTeamVsHeader=eq,e.requestMagicLink=xx,e.resetScoringConfig=xs,e.resolveCourtSport=vh,e.resolveEventStatus=Bb,e.resolvePublishedComposition=gi,e.resolveTournamentStatus=Ng,e.scoringModal=lu,e.selectItem=QN,e.setScoringConfig=bs,e.shouldApplySmartComplement=Hs,e.shouldCreateNextSet=Ws,e.shouldShowTiebreak=Us,e.showCourtAvailabilityModal=Yz,e.signup=yx,e.sportFromMatchUpFormat=_h,e.standardTemplates=VH,e.syncClearVisibility=tS,e.tennisCourt=oh,e.tipster=ih,e.toggleOverlay=lP,e.topologyToDrawOptions=mU,e.totalBuckets=zv,e.updateHeadingSelect=Lm,e.updateTieScore=tq,e.updateToolbarState=Im,e.validateProfile=UF,e.validateSchedulingPolicy=DQ,e.validateTopology=tH,e.validator=fn,Object.defineProperty(e,"validators",{enumerable:!0,get:function(){return Xx}}),e.verifyExisting=bx,e.wrapSearchWithClear=eS});
321
+ `}e.innerHTML=a,e.querySelectorAll(`.court-checkbox`).forEach(e=>{e.addEventListener(`change`,this.handleCourtCheckboxChange)}),e.querySelectorAll(`.venue-checkbox`).forEach(e=>{e.addEventListener(`change`,this.handleVenueCheckboxChange)}),e.querySelectorAll(`.venue-edit-icon`).forEach(e=>{e.addEventListener(`click`,e=>{e.stopPropagation();let t=e.currentTarget,n=t.dataset.venue,r=t.dataset.tournamentId,i=t.dataset.venueName||n,a=this.control?.getDay()||this.engine.getActiveDays()[0]||`2026-01-01`,o=this.engine.getVenueAvailability(r,n),s=this.engine.getConfig();_V({title:`Venue Defaults \u2014 ${i}`,currentDay:a,currentStartTime:o?.startTime||s.dayStartTime,currentEndTime:o?.endTime||s.dayEndTime,showScopeToggle:!1,onConfirm:({startTime:e,endTime:t})=>{this.engine.setVenueDefaultAvailability(r,n,{startTime:e,endTime:t}),this.engine.clearCourtAvailabilityForVenue(r,n),this.control?.refresh()}})})}),e.querySelectorAll(`.court-edit-icon`).forEach(e=>{e.addEventListener(`click`,e=>{e.stopPropagation();let t=e.currentTarget,n=t.dataset.courtId,r=t.dataset.venueId,i=t.dataset.tournamentId,a=t.dataset.courtName||n,o={tournamentId:i,venueId:r,courtId:n},s=this.control?.getDay()||this.engine.getActiveDays()[0]||`2026-01-01`,c=this.engine.getCourtAvailability(o,s);_V({title:`Court \u2014 ${a}`,currentDay:s,currentStartTime:c.startTime,currentEndTime:c.endTime,showScopeToggle:!0,onConfirm:({startTime:e,endTime:t,scope:n})=>{n===`all-days`?this.engine.setCourtAvailabilityAllDays(o,{startTime:e,endTime:t}):this.engine.setCourtAvailability(o,s,{startTime:e,endTime:t}),this.control?.refresh()}})})})}updateVenueCheckboxState(e){let t=this.engine.listCourtMeta().filter(t=>t.ref.venueId===e),n=t.filter(e=>{let t=`${e.ref.tournamentId}|${e.ref.venueId}|${e.ref.courtId}`;return this.visibleCourts.has(t)}).length,r=this.venueTreeElement?.querySelector(`.venue-checkbox[data-venue="${e}"]`);r&&(n===0?(r.checked=!1,r.indeterminate=!1):n===t.length?(r.checked=!0,r.indeterminate=!1):(r.checked=!1,r.indeterminate=!0))}getEngine(){return this.engine}getControl(){return this.control}setDay(e){this.control?.setDay(e),this.updateCapacityStats()}refresh(){this.control?.refresh(),this.updateCapacityStats(),this.updateVenueTree()}};function bV(e,t){let n=new yV(e);return n.render(t),n}var{LUCKY_DRAW:xV,ROUND_ROBIN:SV,AD_HOC:CV}=t.drawDefinitionConstants;function wV(e){let t=Math.max(2,e),n=2**Math.floor(Math.log2(t)),r=t-n;if(r<=0)return new Map;let i=new Map,a=0,o=n/2;for(;o>=1;)a++,r&o&&(a++,i.set(a,o)),o=Math.floor(o/2);return i}function TV(e){let t=Math.max(2,e),n=2**Math.floor(Math.log2(t)),r=t-n,i=0,a=n/2;for(;a>=1;)i++,r&a&&i++,a=Math.floor(a/2);return i}function EV(e){let t=Math.max(2,e),n=t%2?t+1:t,r=!!(Math.ceil(n/2)%2),i=[{participantsCount:n,preFeedRound:r}];for(;n>2;){let e=Math.ceil(n/2),t=e===1,r=!!(!t&&e%2);n=!t&&r?e+1:e;let a=!!(n!==2&&Math.ceil(n/2)%2);i.push({participantsCount:n,preFeedRound:a,feedRound:r})}return i}function DV(e){let t=Math.max(2,e);return t&t-1?EV(e).length:Math.ceil(Math.log2(t))}function OV(e,t){let n=Math.max(2,e);if(!(n&n-1))return Math.floor(n/2**t);let r=EV(e),i=t-1;if(i<0||i>=r.length)return 0;let{participantsCount:a,preFeedRound:o}=r[i],s=a/2,c=o?s-1:s;if(t===1&&n%2!=0){let e=a-n;c-=e}return c}function kV(e,t,n){return e===SV?(n?.groupSize||Math.min(t,4))-1:e===CV?n?.roundsCount||1:e===xV?DV(t):TV(t)}function AV(e,t,n){return e===xV?OV(t,n):Math.floor(t/2**n)}var{ROUND_ROBIN:jV,AD_HOC:MV,LUCKY_DRAW:NV}=t.drawDefinitionConstants,PV=0;function FV({structureType:e,drawSize:t,stage:n,structureId:r,qualifyingPositions:i,structureOptions:a}){return e===jV?LV({drawSize:t,stage:n,structureId:r,structureOptions:a}):e===MV?zV({drawSize:t,stage:n,structureId:r,roundsCount:a?.roundsCount||1}):e===NV?RV({drawSize:t,stage:n,structureId:r}):IV({drawSize:t,stage:n,structureId:r,qualifyingPositions:i})}function IV({drawSize:e,stage:t,structureId:n,qualifyingPositions:r}){let i=Math.max(2,e),a=2**Math.floor(Math.log2(i)),o=i-a,s=[],c=a/2;for(;c>=1;)s.push({count:c,isFeed:!1}),o&c&&s.push({count:c,isFeed:!0}),c=Math.floor(c/2);if(r&&r>0&&e>r){let t=Math.round(Math.log2(e/r));t>0&&s.length>t&&(s.length=t)}let l=s.length,u=[],d=1,f=0,p=new Set;for(let e=0;e<l-1;e++)!s[e].isFeed&&s[e+1].isFeed&&p.add(e);for(let e=0;e<l;e++){let{count:r,isFeed:i}=s[e],a=e+1,o=i?2**Math.max(0,f-1):2**f,c=i||p.has(e);for(let s=1;s<=r;s++){let r=a===1&&!i;u.push({matchUpId:`preview-${++PV}`,roundNumber:a,roundPosition:s,drawPositions:r?[(s-1)*2+1,(s-1)*2+2]:i?[d++]:[],finishingRound:l-e,roundFactor:o,preFeedRound:c,stage:t,structureId:n})}i||f++}return u}function LV({drawSize:e,stage:t,structureId:n,structureOptions:r}){let i=[],a=r?.groupSize||Math.min(e,4),o=Math.ceil(e/a),s=a-1;for(let e=0;e<o;e++)for(let r=1;r<=s;r++){let o=Math.floor(a/2);for(let a=1;a<=o;a++)i.push({matchUpId:`preview-${++PV}`,roundNumber:r,roundPosition:e*o+a,isRoundRobin:!0,stage:t,structureId:`${n}-g${e}`})}return i}function RV({drawSize:e,stage:t,structureId:n}){let r=Math.max(2,e);if(!(r&r-1))return IV({drawSize:e,stage:t,structureId:n});let i=EV(r),a=i.length,o=[],s=1;for(let e=0;e<a;e++){let{participantsCount:r,preFeedRound:c}=i[e],l=r/2,u=e+1;for(let r=1;r<=l;r++){let i=u===1;o.push({matchUpId:`preview-${++PV}`,roundNumber:u,roundPosition:r,drawPositions:i?[s++,s++]:[],finishingRound:a-e,roundFactor:1,preFeedRound:!!c,stage:t,structureId:n})}}return o}function zV({drawSize:e,stage:t,structureId:n,roundsCount:r=1}){let i=[];if(e<2)return i;let a=Math.floor(e/2);for(let e=1;e<=r;e++)for(let r=1;r<=a;r++)i.push({matchUpId:`preview-${++PV}`,roundNumber:e,roundPosition:r,finishingRound:1,stage:t,structureId:n});return i}var{ROUND_ROBIN:BV}=t.drawDefinitionConstants,VV=new Map;function HV(e,n,r){let i=`${e}:${n}:${r||``}`,a=VV.get(i);if(a)return a;try{let a={drawSize:n,drawType:e};r&&(a.structureOptions={groupSize:r});let{tournamentRecord:o}=t.mocksEngine.generateTournamentRecord({drawProfiles:[a]}),s=o?.events?.[0]?.drawDefinitions?.[0];if(!s)return UV(i,{});let c=(s.structures||[])[0];if(!c)return UV(i,{});let l=c.structureType===`CONTAINER`,u={};if(l||e===BV){let{availablePlayoffProfiles:e}=t.drawsGovernor.getAvailablePlayoffProfiles({drawDefinition:s}),n=e?.[0];n&&(u={playoffFinishingPositionRanges:n.playoffFinishingPositionRanges,finishingPositionsAvailable:n.finishingPositionsAvailable})}else{let e=c.structureId,{playoffRounds:n,playoffRoundsRanges:r}=t.drawsGovernor.getAvailablePlayoffProfiles({drawDefinition:s,structureId:e});u={playoffRounds:n,playoffRoundsRanges:r}}return UV(i,u)}catch{return UV(i,{})}}function UV(e,t){return VV.set(e,t),t}var{MAIN:WV,QUALIFYING:GV,CONSOLATION:KV,PLAY_OFF:qV,ROUND_ROBIN:JV,AD_HOC:YV,LUCKY_DRAW:XV,WINNER:ZV,LOSER:QV}=t.drawDefinitionConstants,$V=240,eH=48,tH=16;function nH(e){if(e.structureType===JV)return(e.structureOptions?.groupSize||Math.min(e.drawSize,4))-1;if(e.structureType===YV)return e.structureOptions?.roundsCount||1;if(e.structureType===XV)return DV(e.drawSize);let t=Math.max(2,e.drawSize),n=2**Math.floor(Math.log2(t)),r=t-n,i=0,a=n/2;for(;a>=1;)i++,r&a&&i++,a=Math.floor(a/2);if(e.qualifyingPositions&&e.qualifyingPositions>0&&e.drawSize>e.qualifyingPositions){let t=Math.round(Math.log2(e.drawSize/e.qualifyingPositions));t>0&&t<i&&(i=t)}return i}function rH(e){let t=nH(e);return Math.max($V,t*eH+tH)}var iH={[WV]:`tb-card-badge--main`,[GV]:`tb-card-badge--qualifying`,[KV]:`tb-card-badge--consolation`,[qV]:`tb-card-badge--playoff`};function aH(e,t,n,r,i,a,o,s){let c=a&&a.length>0,l=document.createElement(`div`);l.className=`tb-card${n?` tb-card--selected`:``}${c?` tb-card--warning`:``}`,l.style.left=`${e.position.x}px`,l.style.top=`${e.position.y}px`,l.style.minWidth=`${rH(e)}px`,l.setAttribute(`data-node-id`,e.id);let u=document.createElement(`div`);u.className=`tb-card-header`;let d=document.createElement(`span`);d.className=`tb-card-badge ${iH[e.stage]||`tb-card-badge--main`}`,d.textContent=e.stage.substring(0,4);let f=document.createElement(`span`);f.className=`tb-card-name`,f.textContent=e.structureName;let p=document.createElement(`span`);if(p.className=`tb-card-size`,p.textContent=`\u00d7${e.drawSize}`,u.appendChild(d),u.appendChild(f),u.appendChild(p),o){let e=document.createElement(`div`);e.className=`tb-card-advance`,e.textContent=o,u.appendChild(e)}let m=document.createElement(`div`);m.className=`tb-card-preview`;let h=e.matchUps||FV({structureType:e.structureType,drawSize:e.drawSize,stage:e.stage,structureId:e.id,qualifyingPositions:e.qualifyingPositions,structureOptions:e.structureOptions});if(h.length>0)try{let t=Di({matchUps:h,structureId:e.id,showHeaders:!1});t.style.transform=`scale(0.8)`,t.style.transformOrigin=`top left`,m.appendChild(t)}catch{m.textContent=`${e.structureType} \u00d7${e.drawSize}`,m.style.cssText+=`font-size:11px;color:var(--chc-text-muted);display:flex;align-items:center;justify-content:center;`}if(i?.length&&m.querySelector(`.chc-schematic-structure`)){let e=m.querySelectorAll(`.chc-schematic-round-container[data-round-number]`);for(let n of e){let e=parseInt(n.getAttribute(`data-round-number`)||`0`),r=i.filter(t=>t.roundNumber===e);if(!r.length)continue;let a=r.find(e=>e.isSelected)||r.find(e=>e.linkType===QV)||r.find(e=>e.linkType===ZV)||r[0];n.classList.add(`tb-round-linked`),n.classList.add(`tb-round-linked--${a.linkType.toLowerCase()}`),n.classList.add(`tb-round-linked--${a.direction}`),a.isSelected&&n.classList.add(`tb-round-linked--active`),n.style.cursor=`pointer`,n.addEventListener(`click`,e=>{e.stopPropagation(),t.onSelectEdge(a.edgeId)}),n.title=r.map(t=>`R${e} ${t.linkType} ${t.direction===`source`?`out`:`in`}`).join(`, `)}}let g=HV(e.structureType,e.drawSize,e.structureOptions?.groupSize),_=null;g.playoffRoundsRanges?.length?(_=document.createElement(`div`),_.className=`tb-card-rounds`,_.textContent=g.playoffRoundsRanges.map(e=>`R${e.roundNumber}:${e.finishingPositionRange}`).join(` `)):g.playoffFinishingPositionRanges?.length&&(_=document.createElement(`div`),_.className=`tb-card-rounds`,_.textContent=g.playoffFinishingPositionRanges.map(e=>`P${e.finishingPosition}:${e.finishingPositionRange}`).join(` `));let v=document.createElement(`div`);v.className=`tb-card-ports`;let y=document.createElement(`div`);y.className=`tb-port tb-port--input`,y.title=`Input`,y.addEventListener(`mouseup`,()=>{t.onPortMouseUp(e.id)});let b=document.createElement(`div`);b.className=`tb-port-group`;let x=document.createElement(`div`);x.className=`tb-port tb-port--winner${r?` tb-port--connected`:``}`,x.title=r?`Winner linked`:`Winner output`,r||x.addEventListener(`mousedown`,n=>{n.stopPropagation(),t.onPortMouseDown(e.id,`winner`)});let S=document.createElement(`div`);if(S.className=`tb-port tb-port--loser`,S.title=`Loser output`,S.addEventListener(`mousedown`,n=>{n.stopPropagation(),t.onPortMouseDown(e.id,`loser`)}),b.appendChild(x),b.appendChild(S),v.appendChild(y),v.appendChild(b),l.appendChild(u),l.appendChild(m),s?.length){let e=document.createElement(`div`);e.className=`tb-card-chips`;for(let n of s){let r=document.createElement(`span`);r.className=`tb-card-chip`,r.textContent=`P${n.position}`,r.title=`Position ${n.position} → ${n.targetName}`,r.addEventListener(`click`,e=>{e.stopPropagation(),t.onSelectEdge(n.edgeId)}),e.appendChild(r)}l.appendChild(e)}if(_&&l.appendChild(_),c){let e=document.createElement(`div`);e.className=`tb-card-warning`,e.textContent=`⚠ Issue`;let t=document.createElement(`div`);t.className=`tb-card-warning-detail`,t.textContent=a.join(`; `),e.appendChild(t),e.addEventListener(`click`,t=>{t.stopPropagation(),e.classList.toggle(`tb-card-warning--open`)}),l.appendChild(e)}return l.appendChild(v),l.addEventListener(`mouseup`,()=>{t.onPortMouseUp(e.id)}),l.addEventListener(`click`,n=>{n.stopPropagation(),t.onSelect(e.id)}),t.onDoubleClick&&l.addEventListener(`dblclick`,n=>{n.stopPropagation(),t.onDoubleClick(e.id)}),l.addEventListener(`mousedown`,n=>{n.target.classList.contains(`tb-port`)||t.onDragStart(e.id,n.clientX,n.clientY)}),l}function oH(e,t){let n=rH(e);switch(t){case`input`:return{x:e.position.x,y:e.position.y+80};case`winner`:return{x:e.position.x+n,y:e.position.y+80-8};case`loser`:return{x:e.position.x+n,y:e.position.y+80+8}}}var{MAIN:sH,QUALIFYING:cH,CONSOLATION:lH,WINNER:uH,LOSER:dH,ROUND_ROBIN:fH}=t.drawDefinitionConstants,pH=`POSITION`,mH=0;function hH(e){return`${e}-${++mH}-${Date.now().toString(36)}`}function gH(e){let t=2;for(;t*2<=e;)t*=2;return t}var _H=60,vH=class{constructor(e){this.listeners=new Set,this.state={nodes:[],edges:[],selectedNodeId:null,selectedEdgeId:null,drawName:`New Draw`,...e}}getState(){return{...this.state}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notify(){let e=this.getState();for(let t of this.listeners)t(e)}setDrawName(e){this.state.drawName=e,this.notify()}addNode(e){let t={...e,id:hH(`node`),position:this.nextNodePosition()};return this.state.nodes.push(t),this.state.templateName=void 0,this.notify(),t}updateNode(e,t){let n=this.state.nodes.find(t=>t.id===e);n&&(Object.keys(t).some(e=>e!==`position`)&&(this.state.templateName=void 0),Object.assign(n,t),this.notify())}removeNode(e){let t=this.state.edges.filter(t=>t.sourceNodeId===e).map(e=>e.targetNodeId);this.state.nodes=this.state.nodes.filter(t=>t.id!==e),this.state.edges=this.state.edges.filter(t=>t.sourceNodeId!==e&&t.targetNodeId!==e),this.state.selectedNodeId===e&&(this.state.selectedNodeId=null),this.state.templateName=void 0;for(let e of t)this.clampConsolationDrawSize(e);this.notify()}addEdge(e){if(e.linkType===uH&&this.state.edges.find(t=>t.sourceNodeId===e.sourceNodeId&&t.linkType===uH))return null;let t=this.state.nodes.find(t=>t.id===e.sourceNodeId),n=this.state.nodes.find(t=>t.id===e.targetNodeId);if(t?.structureType===fH&&e.linkType!==pH||t?.stage===cH&&n&&n.stage!==cH&&n.stage!==sH||n?.stage===cH&&t&&t.stage!==cH)return null;let r={...e,id:hH(`edge`),targetRoundNumber:e.targetRoundNumber||1,label:this.computeEdgeLabel(e)};return this.state.edges.push(r),this.state.templateName=void 0,this.clampConsolationDrawSize(r.targetNodeId),this.notify(),r}updateEdge(e,t){let n=this.state.edges.find(t=>t.id===e);n&&(Object.assign(n,t),n.label=this.computeEdgeLabel(n),this.state.templateName=void 0,this.notify())}removeEdge(e){let t=this.state.edges.find(t=>t.id===e);this.state.edges=this.state.edges.filter(t=>t.id!==e),this.state.selectedEdgeId===e&&(this.state.selectedEdgeId=null),this.state.templateName=void 0,t&&this.clampConsolationDrawSize(t.targetNodeId),this.notify()}selectNode(e){this.state.selectedNodeId=e,this.state.selectedEdgeId=null,this.notify()}selectEdge(e){this.state.selectedEdgeId=e,this.state.selectedNodeId=null,this.notify()}clampConsolationDrawSize(e){let t=this.state.nodes.find(t=>t.id===e);if(!t||t.stage!==lH)return;let n=this.inboundCapacity(e);n>0&&t.drawSize>n&&(t.drawSize=gH(n))}inboundCapacity(e){let t=this.state.edges.filter(t=>t.targetNodeId===e),n=0;for(let e of t){let t=this.state.nodes.find(t=>t.id===e.sourceNodeId);if(t){if(e.linkType===dH){let r=e.sourceRoundNumber||1;n+=AV(t.structureType,t.drawSize,r)}else n+=t.qualifyingPositions||Math.floor(t.drawSize/2)}}return n}nextNodePosition(){if(this.state.nodes.length===0)return{x:40,y:40};let e=0;for(let t of this.state.nodes)e=Math.max(e,t.position.x+rH(t));return{x:e+_H,y:40}}autoLayout(){let e=this.state.nodes,t=this.state.edges;if(!e.length)return;let n=new Map,r=new Map;for(let e of t)r.has(e.sourceNodeId)||r.set(e.sourceNodeId,[]),r.get(e.sourceNodeId).push(e.targetNodeId),n.has(e.targetNodeId)||n.set(e.targetNodeId,[]),n.get(e.targetNodeId).push(e.sourceNodeId);let i=e.filter(e=>!n.has(e.id)||n.get(e.id).length===0);if(!i.length){let t=e.filter(e=>e.stage===sH);i.push(...t.length?t:[e[0]])}let a=new Map,o=new Set(e.filter(e=>e.stage===cH).map(e=>e.id)),s=[];for(let e of i)o.has(e.id)?a.set(e.id,-1):a.set(e.id,0),s.push(e.id);let c=e.length*(e.length-1)+e.length,l=0;for(;s.length&&l<c;){l++;let e=s.shift(),t=a.get(e),n=r.get(e)||[];for(let e of n){let n=t+1,r=a.get(e);(r===void 0||n>r)&&(a.set(e,n),s.push(e))}}for(let t of e)a.has(t.id)||a.set(t.id,0);let u=Math.min(...a.values());if(u<0)for(let[e,t]of a)a.set(e,t-u);let d=new Map;for(let t of e){let e=a.get(t.id);d.has(e)||d.set(e,[]),d.get(e).push(t)}let f=[...d.keys()].sort((e,t)=>e-t),p=40;for(let e of f){let t=d.get(e),n=Math.max(...t.map(e=>rH(e)));t.forEach((e,t)=>{e.position={x:p,y:t*190+40}}),p+=n+_H}}loadState(e){this.state={...e},this.notify()}computeEdgeLabel(e){let t=e.linkType||`LINK`,n=``;return e.sourceRoundNumber&&(n+=`R${e.sourceRoundNumber} `),n+=t.toLowerCase(),e.targetRoundNumber&&(n+=` \u2192 R${e.targetRoundNumber}`),e.qualifyingPositions&&(n+=` (${e.qualifyingPositions}Q)`),e.finishingPositions?.length&&(n+=` [${e.finishingPositions.join(`,`)}]`),n}},{WINNER:yH,LOSER:bH,QUALIFYING:xH,CONSOLATION:SH,ROUND_ROBIN:CH}=t.drawDefinitionConstants,wH=`POSITION`,TH=e=>e===CH;function EH(e,t){if(!TH(e.structureType))return;let n=t.edges.filter(t=>t.sourceNodeId===e.id&&t.linkType===wH);if(!n.length)return;let r=new Set(n.flatMap(e=>e.finishingPositions||[])),i=e.structureOptions?.groupSize||4;return`${r.size} of ${i} advance`}var DH=`http://www.w3.org/2000/svg`,OH={[yH]:`tb-edge--winner`,[bH]:`tb-edge--loser`,[wH]:`tb-edge--position`};function kH(e){let t=document.createElement(`div`);t.className=`tb-canvas`;let n=document.createElementNS(DH,`svg`);n.classList.add(`tb-canvas-svg`);let r=document.createElementNS(DH,`defs`);for(let[e,t]of Object.entries(OH)){let n=document.createElementNS(DH,`marker`);n.setAttribute(`id`,`arrowhead-${e}`),n.setAttribute(`markerWidth`,`8`),n.setAttribute(`markerHeight`,`6`),n.setAttribute(`refX`,`8`),n.setAttribute(`refY`,`3`),n.setAttribute(`orient`,`auto`);let i=document.createElementNS(DH,`polygon`);i.setAttribute(`points`,`0 0, 8 3, 0 6`),i.setAttribute(`class`,t),i.style.fill=`currentColor`,n.appendChild(i),r.appendChild(n)}n.appendChild(r);let i=document.createElement(`div`);i.className=`tb-canvas-nodes`;let a=document.createElement(`div`);a.className=`tb-canvas-spacer`,t.appendChild(n),t.appendChild(i),t.appendChild(a);let o=null,s=null,c=null,l=!1,u=null;t.addEventListener(`click`,()=>{l||(e.onSelectNode(null),e.onSelectEdge(null))}),t.addEventListener(`mousemove`,n=>{if(s&&!c){let e=n.clientX-s.startX,t=n.clientY-s.startY;Math.abs(e)+Math.abs(t)>=4&&(c=s,s=null)}if(c&&u){let t=n.clientX-c.startX,r=n.clientY-c.startY;e.onMoveNode(c.nodeId,Math.max(0,c.origX+t),Math.max(0,c.origY+r))}if(o?.tempLine){let e=t.getBoundingClientRect();o.tempLine.setAttribute(`x2`,String(n.clientX-e.left+t.scrollLeft)),o.tempLine.setAttribute(`y2`,String(n.clientY-e.top+t.scrollTop))}}),t.addEventListener(`mouseup`,()=>{c&&(l=!0,c=null,setTimeout(()=>{l=!1},0)),s=null,o?.tempLine&&(n.removeChild(o.tempLine),o=null)});function d(e){return new Set(e.edges.filter(e=>e.linkType===yH).map(e=>e.sourceNodeId).filter(t=>{let n=e.nodes.find(e=>e.id===t);return n&&n.stage===xH&&!TH(n.structureType)}))}function f(e){let t=new Map;for(let n of e.edges){let r=n.sourceRoundNumber,i=n.targetRoundNumber,a=n.id===e.selectedEdgeId;if(!r&&n.linkType===yH){let t=e.nodes.find(e=>e.id===n.sourceNodeId);t&&(r=nH(t))}r&&(t.has(n.sourceNodeId)||t.set(n.sourceNodeId,[]),t.get(n.sourceNodeId).push({roundNumber:r,linkType:n.linkType,direction:`source`,edgeId:n.id,isSelected:a})),i&&(t.has(n.targetNodeId)||t.set(n.targetNodeId,[]),t.get(n.targetNodeId).push({roundNumber:i,linkType:n.linkType,direction:`target`,edgeId:n.id,isSelected:a}))}return t}function p(e){let t=new Map;for(let n of e.edges){if(n.linkType!==yH)continue;let r=n.targetRoundNumber||1;if(r<=1)continue;let i=e.nodes.find(e=>e.id===n.sourceNodeId);if(!i||i.stage!==xH)continue;t.has(n.targetNodeId)||t.set(n.targetNodeId,[]);let a=i.qualifyingPositions||Math.floor(i.drawSize/4);t.get(n.targetNodeId).push({targetRound:r,qp:a,warning:`Round ${r} needs fed drawPositions to accommodate ${i.structureName} link`})}let n=new Map;for(let[r,i]of t){let t=e.nodes.find(e=>e.id===r);if(!t)continue;let a=wV(t.drawSize),o=new Map;for(let e of i)o.set(e.targetRound,(o.get(e.targetRound)||0)+e.qp);let s=[];for(let e of i)(a.get(e.targetRound)||0)<(o.get(e.targetRound)||0)&&s.push(e.warning);s.length>0&&n.set(r,s)}return n}function m(e){let t=new Map;for(let n of e.nodes){if(!TH(n.structureType))continue;let r=e.edges.filter(e=>e.sourceNodeId===n.id&&e.linkType===wH);if(!r.length)continue;let i=[];for(let t of r){let n=e.nodes.find(e=>e.id===t.targetNodeId);for(let e of t.finishingPositions||[])i.push({position:e,edgeId:t.id,targetName:n?.structureName||`?`})}i.sort((e,t)=>e.position-t.position),t.set(n.id,i)}return t}function h(e,t,n){return e&&TH(e.structureType)?wH:n===`loser`||t?.stage===SH?bH:yH}function g(t){return{onSelect:t=>{e.onSelectNode(t)},onSelectEdge:t=>{e.onSelectEdge(t)},onDoubleClick:e.onDoubleClickNode?t=>e.onDoubleClickNode(t):void 0,onPortMouseDown:(e,r)=>{let i=t.nodes.find(t=>t.id===e);if(!i)return;let a=oH(i,r),s=document.createElementNS(DH,`line`);s.setAttribute(`x1`,String(a.x)),s.setAttribute(`y1`,String(a.y)),s.setAttribute(`x2`,String(a.x)),s.setAttribute(`y2`,String(a.y)),s.setAttribute(`stroke`,r===`winner`?`green`:`red`),s.setAttribute(`stroke-width`,`2`),s.setAttribute(`stroke-dasharray`,`4 2`),n.appendChild(s),o={sourceNodeId:e,portType:r,tempLine:s}},onPortMouseUp:r=>{if(o&&o.sourceNodeId!==r){let n=h(t.nodes.find(e=>e.id===o.sourceNodeId),t.nodes.find(e=>e.id===r),o.portType);e.onCreateEdge(o.sourceNodeId,r,n)}o?.tempLine&&n.removeChild(o.tempLine),o=null},onDragStart:(e,n,r)=>{let i=t.nodes.find(t=>t.id===e);i&&(s={nodeId:e,startX:n,startY:r,origX:i.position.x,origY:i.position.y})}}}function _(e){u=e,i.innerHTML=``;let t=d(e),r=f(e),o=p(e),s=m(e),c=g(e);for(let n of e.nodes){let a=aH(n,c,e.selectedNodeId===n.id,t.has(n.id),r.get(n.id),o.get(n.id),EH(n,e),s.get(n.id));i.appendChild(a)}n.querySelectorAll(`path, text.tb-edge-label, path.tb-edge-hit`).forEach(e=>n.removeChild(e));let l=new Map;for(let t of e.edges){let e=`${t.sourceNodeId}:${t.targetNodeId}`;l.has(e)||l.set(e,[]),l.get(e).push(t)}for(let t of l.values()){let r=t.length;t.forEach((t,i)=>{let a=r>1?(i-(r-1)/2)*14:0;v(n,t,e,a)})}let h=600,_=400;for(let t of e.nodes)h=Math.max(h,t.position.x+rH(t)+40),_=Math.max(_,t.position.y+180);n.setAttribute(`width`,String(h)),n.setAttribute(`height`,String(_)),i.style.width=`${h}px`,i.style.height=`${_}px`,a.style.width=`${h}px`,a.style.height=`${_}px`}function v(t,n,r,i=0){let a=r.nodes.find(e=>e.id===n.sourceNodeId),o=r.nodes.find(e=>e.id===n.targetNodeId);if(!a||!o)return;let s=oH(a,n.linkType===bH?`loser`:`winner`),c=oH(o,`input`),l=s.y+i,u=c.y+i,d=c.x-s.x,f=`M ${s.x},${l} C ${s.x+d/2},${l} ${s.x+d/2},${u} ${c.x},${u}`,p=document.createElementNS(DH,`path`);p.setAttribute(`d`,f),p.classList.add(`tb-edge-hit`),p.addEventListener(`click`,t=>{t.stopPropagation(),e.onSelectEdge(n.id)}),t.appendChild(p);let m=document.createElementNS(DH,`path`);if(m.setAttribute(`d`,f),m.classList.add(OH[n.linkType]||`tb-edge--winner`),r.selectedEdgeId===n.id&&m.classList.add(`tb-edge--selected`),m.setAttribute(`marker-end`,`url(#arrowhead-${n.linkType})`),m.addEventListener(`click`,t=>{t.stopPropagation(),e.onSelectEdge(n.id)}),t.appendChild(m),n.label){let e=(s.x+c.x)/2,r=(l+u)/2-8,i=document.createElementNS(DH,`text`);i.classList.add(`tb-edge-label`),i.setAttribute(`x`,String(e)),i.setAttribute(`y`,String(r)),i.setAttribute(`text-anchor`,`middle`),i.textContent=n.label,t.appendChild(i)}}return{element:t,update:_}}var{SINGLE_ELIMINATION:AH,ROUND_ROBIN:jH,FEED_IN:MH,FEED_IN_CHAMPIONSHIP:NH,FIRST_MATCH_LOSER_CONSOLATION:PH,COMPASS:FH,OLYMPIC:IH,AD_HOC:LH,LUCKY_DRAW:RH,MAIN:zH,QUALIFYING:BH,CONSOLATION:VH,PLAY_OFF:HH,WINNER:UH}=t.drawDefinitionConstants,WH=`POSITION`,GH=[{label:`Single Elimination`,value:AH},{label:`Round Robin`,value:jH},{label:`Feed-In Championship`,value:NH},{label:`FMLC`,value:PH},{label:`Compass`,value:FH},{label:`Olympic`,value:IH},{label:`Ad-hoc`,value:LH}],KH=[{label:`Single Elimination`,value:AH},{label:`Round Robin`,value:jH},{label:`Lucky Draw`,value:RH},{label:`Staggered Entry`,value:MH},{label:`Ad-hoc`,value:LH}],qH=[{label:`Main`,value:zH},{label:`Qualifying`,value:BH},{label:`Consolation`,value:VH},{label:`Playoff`,value:HH}];function JH(e){let t=[],n=Math.floor(e/2);for(;n>=1;)t.push(n),n=Math.floor(n/2);return t}function YH(e,t=8){let n=[];for(let r=3;r<=t;r++){let t=Math.ceil(e/r),i=t*r-e,a=Math.ceil(e/t),o=Math.ceil(i/t);(!i||i<r)&&a===r&&a>=3&&o<2&&n.push(r)}return n}function XH(e,t,n,r,i,a){let o=YH(e.drawSize),s=e.structureOptions?.groupSize||4,c=o.includes(s)?o:[s,...o].sort((e,t)=>e-t),l=Math.ceil(e.drawSize/s);i.push({label:`Group Size`,field:`groupSize`,value:String(s),disabled:n,options:c.map(e=>({label:String(e),value:String(e),selected:e===s}))}),i.push({label:`Groups`,field:`groupCount`,value:String(l),disabled:!0}),n||a.push({control:`groupSize`,onChange:({e:t})=>{let n=parseInt(t.target.value);r.onUpdateNode(e.id,{structureOptions:{...e.structureOptions,groupSize:n}})}});let u=t.edges.filter(t=>t.sourceNodeId===e.id&&t.linkType===WH),d=new Set(u.flatMap(e=>e.finishingPositions||[])),f=d.size||0,p=Array.from({length:s},(e,t)=>t+1);i.push({label:`Advance Per Group`,field:`advancePerGroup`,value:String(f),disabled:n||u.length===0,options:p.map(e=>({label:String(e),value:String(e),selected:e===f}))}),!n&&u.length>0&&a.push({control:`advancePerGroup`,onChange:({e})=>{let t=parseInt(e.target.value),n=d.size;if(t!==n){if(t>n){let e=u.at(-1),n=[];for(let e=1;e<=s&&d.size+n.length<t;e++)d.has(e)||n.push(e);n.length>0&&r.onUpdateEdge(e.id,{finishingPositions:[...e.finishingPositions||[],...n].sort((e,t)=>e-t)})}else{let e=[...d].sort((e,t)=>t-e),i=new Set(e.slice(0,n-t));for(let e of u){let t=(e.finishingPositions||[]).filter(e=>!i.has(e));t.length!==(e.finishingPositions||[]).length&&r.onUpdateEdge(e.id,{finishingPositions:t})}}}}}),u.length>0&&f>0&&ZH(u,t,l,i)}function ZH(e,t,n,r){let i=new Map;for(let t of e)i.has(t.targetNodeId)||i.set(t.targetNodeId,[]),i.get(t.targetNodeId).push(...t.finishingPositions||[]);let a=[];for(let[e,r]of i){let i=t.nodes.find(t=>t.id===e),o=[...new Set(r)].sort((e,t)=>e-t),s=o.length===1?`P${o[0]}`:`P${o.join(`,`)}`;a.push(`${s} → ${i?.structureName||`?`} (${o.length*n})`)}a.length>0&&r.push({label:`Playoff Groups`,field:`playoffSummary`,value:a.join(`
322
+ `),disabled:!0})}function QH(e,t,n,r,i,a){let o=t.edges.find(t=>t.targetNodeId===e.id&&t.linkType===WH);if(!o||t.nodes.find(e=>e.id===o.sourceNodeId)?.structureType!==jH)return;let s=e.structureOptions?.playoffDrawType||AH;if(i.push({label:`Playoff Draw Type`,field:`playoffDrawType`,value:s,disabled:n,options:GH.map(e=>({...e,selected:e.value===s}))}),n||a.push({control:`playoffDrawType`,onChange:({e:t})=>r.onUpdateNode(e.id,{structureOptions:{...e.structureOptions,playoffDrawType:t.target.value}})}),s===jH){let t=e.structureOptions?.groupSize||4;i.push({label:`Playoff Group Size`,field:`playoffGroupSize`,value:String(t),disabled:n,options:[3,4,5,6,8].map(e=>({label:String(e),value:String(e),selected:e===t}))}),n||a.push({control:`playoffGroupSize`,onChange:({e:t})=>r.onUpdateNode(e.id,{structureOptions:{...e.structureOptions,groupSize:parseInt(t.target.value)}})})}}function $H(e,t,n,r,i){let a=JH(e.drawSize),o=e.qualifyingPositions??a[0];r.push({label:`Qualifying Positions`,field:`qualifyingPositions`,value:String(o),disabled:t,options:a.map(e=>({label:String(e),value:String(e),selected:e===o}))}),t||i.push({control:`qualifyingPositions`,onChange:({e:t})=>n.onUpdateNode(e.id,{qualifyingPositions:parseInt(t.target.value)})})}function eU(e,t,n){let r=wV(e.drawSize),i=new Map,a=[];for(let n of t.edges){if(n.linkType!==UH||n.targetNodeId!==e.id)continue;let r=n.targetRoundNumber||1;if(r<=1)continue;let o=t.nodes.find(e=>e.id===n.sourceNodeId);if(!o||o.stage!==BH)continue;let s=o.qualifyingPositions||Math.floor(o.drawSize/4);i.set(r,(i.get(r)||0)+s),a.push({targetRound:r,qp:s,sourceName:o.structureName})}let o=[];for(let e of a){let t=r.get(e.targetRound)||0;t>=(i.get(e.targetRound)||0)||(t===0?o.push(`Round ${e.targetRound} is not a feed round — ${e.sourceName} sends ${e.qp} qualifiers`):o.push(`Round ${e.targetRound} has ${t} feed positions but ${e.sourceName} sends ${e.qp} qualifiers`))}if(o.length>0){let e=document.createElement(`div`);e.className=`tb-editor-warning`;for(let t of o){let n=document.createElement(`div`);n.textContent=`\u26a0 ${t}`,e.appendChild(n)}let t=document.createElement(`div`);t.style.marginTop=`6px`,t.textContent=`Change the target round to a feed round, or increase the draw size to create feed positions at that round.`,e.appendChild(t),n.appendChild(e)}}function tU(e){let t=document.createElement(`div`),n=!!e.readOnly;function r(r){t.innerHTML=``;let i=r.selectedNodeId?r.nodes.find(e=>e.id===r.selectedNodeId):null;if(!i)return;let a=document.createElement(`div`);a.className=`tb-editor-header`,a.textContent=`Structure Properties`,t.appendChild(a);let o=document.createElement(`div`);o.className=`tb-editor-body`;let s=[{label:`Name`,field:`structureName`,value:i.structureName,...n?{disabled:!0}:{validator:uC(1),error:`Name required`}},{label:`Stage`,field:`stage`,value:i.stage,disabled:n,options:qH.map(e=>({...e,selected:e.value===i.stage}))},{label:`Structure Type`,field:`structureType`,value:i.structureType,disabled:n,options:KH.map(e=>({...e,selected:e.value===i.structureType}))},{label:i.stage===zH?`Draw Size`:`Structure Size`,field:`drawSize`,type:`number`,value:String(i.drawSize),...n?{disabled:!0}:i.structureType===LH?{validator:fC(0,256),error:`Must be 0-256`}:{validator:fC(2,256),error:`Must be 2-256`}}],c=n?[]:[{control:`structureName`,onChange:({inputs:t})=>e.onUpdateNode(i.id,{structureName:t.structureName.value})},{control:`stage`,onChange:({e:t})=>e.onUpdateNode(i.id,{stage:t.target.value})},{control:`structureType`,onChange:({e:t})=>e.onUpdateNode(i.id,{structureType:t.target.value})},{control:`drawSize`,onChange:({inputs:t})=>{let n=parseInt(t.drawSize.value);if(n<(i.structureType===LH?0:2))return;let r={drawSize:n};if(i.structureType===jH){let e=i.structureOptions?.groupSize||4,t=YH(n);!t.includes(e)&&t.length>0&&(r.structureOptions={...i.structureOptions,groupSize:t[0]})}e.onUpdateNode(i.id,r)}}];i.structureType===jH&&XH(i,r,n,e,s,c),i.stage===HH&&QH(i,r,n,e,s,c),i.stage===BH&&$H(i,n,e,s,c),Oi(o,s,c);let l=document.createElement(`div`);l.className=`field font-medium`,l.style.cssText=`flex-grow: 1`;let u=document.createElement(`label`);u.style.cssText=`font-weight: bold; font-size: larger;`,u.textContent=`MatchUp Format`,l.appendChild(u);let d=document.createElement(`div`);if(d.className=`tb-format-trigger`,d.textContent=i.matchUpFormat||`Not set`,n?(d.style.cursor=`default`,d.style.opacity=`0.7`):d.onclick=()=>{Ha({existingMatchUpFormat:i.matchUpFormat,callback:t=>{e.onUpdateNode(i.id,{matchUpFormat:t||void 0}),d.textContent=t||`Not set`}})},l.appendChild(d),o.appendChild(l),eU(i,r,o),!n&&!e.hideDelete){let t=document.createElement(`button`);t.className=`sp-btn sp-btn--danger sp-btn--full`,t.style.marginTop=`12px`,t.textContent=`Delete Structure`,t.onclick=()=>e.onDeleteNode(i.id),o.appendChild(t)}t.appendChild(o)}return{element:t,update:r}}var{WINNER:nU,LOSER:rU,TOP_DOWN:iU,BOTTOM_UP:aU,QUALIFYING:oU,ROUND_ROBIN:sU}=t.drawDefinitionConstants,cU=`POSITION`,lU=`ALTERNATING`,uU=e=>e===sU,dU=[{label:`Winner`,value:nU},{label:`Loser`,value:rU},{label:`Position`,value:cU}],fU=[{label:`Top-Down`,value:iU},{label:`Bottom-Up`,value:aU},{label:`Alternating`,value:lU}];function pU(e){let t=document.createElement(`div`),n=!!e.readOnly;function r(t,r,i,a,o,s){let c=[],l=[],u=r?HV(r.structureType,r.drawSize,r.structureOptions?.groupSize):{},d=u.playoffRoundsRanges&&u.playoffRoundsRanges.length>0;if(d){let e=u.playoffRoundsRanges.map(e=>({label:`R${e.roundNumber} (${e.finishingPositionRange})`,value:String(e.roundNumber),selected:e.roundNumber===(t.sourceRoundNumber||a)}));c.push({label:`Source Round`,field:`sourceRoundNumber`,value:String(t.sourceRoundNumber||a),disabled:n,options:e})}else c.push({label:`Source Round`,field:`sourceRoundNumber`,type:`number`,value:String(t.sourceRoundNumber||a),disabled:n});return c.push({label:s?`Enter at Round`:`Target Round`,field:`targetRoundNumber`,type:`number`,value:String(t.targetRoundNumber||0),disabled:n}),n||(d?l.push({control:`sourceRoundNumber`,onChange:({e:n})=>{let r=Number.parseInt(n.target.value)||0;e.onUpdateEdge(t.id,{sourceRoundNumber:r||void 0})}}):l.push({control:`sourceRoundNumber`,onChange:({inputs:n})=>{let r=Number.parseInt(n.sourceRoundNumber.value)||0,i=Math.max(0,Math.min(r,a));e.onUpdateEdge(t.id,{sourceRoundNumber:i||void 0})}}),l.push({control:`targetRoundNumber`,onChange:({inputs:n})=>{let r=Number.parseInt(n.targetRoundNumber.value)||0,i=Math.max(0,Math.min(r,o));e.onUpdateEdge(t.id,{targetRoundNumber:i||void 0})}})),{items:c,relationships:l}}function i(t,r,i){let a=r.structureOptions?.groupSize||4,o=new Set(t.finishingPositions||[]),s=i.edges.filter(e=>e.id!==t.id&&e.sourceNodeId===t.sourceNodeId&&e.linkType===cU),c=new Set;for(let e of s)for(let t of e.finishingPositions||[])c.add(t);let l=document.createElement(`div`);l.className=`field`,l.style.marginBottom=`10px`;let u=document.createElement(`label`);u.style.cssText=`font-size:11px;font-weight:600;color:var(--chc-text-secondary);margin-bottom:3px;display:block;`,u.textContent=`Finishing Positions`,l.appendChild(u);for(let r=1;r<=a;r++){let i=document.createElement(`label`);i.style.cssText=`display:flex;align-items:center;gap:4px;font-size:12px;padding:2px 0;cursor:pointer;`;let a=document.createElement(`input`);a.type=`checkbox`,a.checked=o.has(r);let s=c.has(r);n||s?a.disabled=!0:a.addEventListener(`change`,()=>{let n=new Set(o);a.checked?n.add(r):n.delete(r),e.onUpdateEdge(t.id,{finishingPositions:Array.from(n).sort((e,t)=>e-t)})});let u=document.createElement(`span`);u.textContent=`Position ${r}`,s&&(u.style.color=`var(--chc-text-muted, #999)`,u.title=`Used by another link`,i.style.opacity=`0.5`,i.style.cursor=`not-allowed`),i.appendChild(a),i.appendChild(u),l.appendChild(i)}return l}function a(a){t.innerHTML=``;let o=a.selectedEdgeId?a.edges.find(e=>e.id===a.selectedEdgeId):null;if(!o)return;let s=a.nodes.find(e=>e.id===o.sourceNodeId),c=a.nodes.find(e=>e.id===o.targetNodeId),l=document.createElement(`div`);l.className=`tb-editor-header`,l.textContent=`Link Properties`,t.appendChild(l);let u=document.createElement(`div`);u.className=`tb-editor-body`;let d=document.createElement(`div`);d.style.cssText=`font-size:11px;color:var(--chc-text-muted);margin-bottom:8px;`,d.textContent=`${s?.structureName||`Source`} → ${c?.structureName||`Target`}`,u.appendChild(d);let f=o.linkType===nU&&s?.stage===oU,p=s?kV(s.structureType,s.drawSize,s.structureOptions):8,m=c?kV(c.structureType,c.drawSize,c.structureOptions):8,h=o.linkType===cU&&s&&uU(s.structureType),g=[{label:`Link Type`,field:`linkType`,value:o.linkType,disabled:n,options:dU.map(e=>({...e,selected:e.value===o.linkType}))}],_=n?[]:[{control:`linkType`,onChange:({e:t})=>e.onUpdateEdge(o.id,{linkType:t.target.value})}];if(!h){let e=r(o,s,c,p,m,f);g.push(...e.items),_.push(...e.relationships)}if(f&&s){let t=Math.floor(s.drawSize/2),r=Math.floor(s.drawSize/4),i=o.qualifyingPositions||r;g.push({label:`Qualifying Positions`,field:`qualifyingPositions`,type:`number`,value:String(i),disabled:n}),n||_.push({control:`qualifyingPositions`,onChange:({inputs:n})=>{let r=Number.parseInt(n.qualifyingPositions.value)||1,i=Math.max(1,Math.min(r,t));e.onUpdateEdge(o.id,{qualifyingPositions:i})}})}if(o.linkType===rU&&(g.push({label:`Feed Profile`,field:`feedProfile`,value:o.feedProfile||iU,disabled:n,options:fU.map(e=>({...e,selected:e.value===(o.feedProfile||iU)}))}),n||_.push({control:`feedProfile`,onChange:({e:t})=>e.onUpdateEdge(o.id,{feedProfile:t.target.value})})),o.linkType===cU&&!h&&(g.push({label:`Finishing Positions`,field:`finishingPositions`,value:(o.finishingPositions||[]).join(`, `),placeholder:`e.g., 1, 2`,disabled:n}),n||_.push({control:`finishingPositions`,onChange:({inputs:t})=>{let n=t.finishingPositions.value.split(`,`).map(e=>Number.parseInt(e.trim())).filter(e=>!Number.isNaN(e));e.onUpdateEdge(o.id,{finishingPositions:n})}})),Oi(u,g,_),h&&s&&u.appendChild(i(o,s,a)),!n){let t=document.createElement(`button`);t.className=`sp-btn sp-btn--danger sp-btn--full`,t.style.marginTop=`12px`,t.textContent=`Delete Link`,t.onclick=()=>e.onDeleteEdge(o.id),u.appendChild(t)}t.appendChild(u)}return{element:t,update:a}}var{MAIN:mU,QUALIFYING:hU,CONSOLATION:gU,WINNER:_U,LOSER:vU,SINGLE_ELIMINATION:yU,ROUND_ROBIN:bU,AD_HOC:xU}=t.drawDefinitionConstants,SU=`POSITION`;function CU(e){let t=[],n=wU(e,t);return EU(e,TU(e),t),DU(e,t),OU(e,t),kU(e,t),AU(e,n,t),jU(e,t),MU(e,t),PU(e,t),FU(e,t),IU(e)&&t.push({severity:`error`,message:`Circular dependency detected between structures`}),t}function wU(e,t){let n=e.nodes.filter(e=>e.stage===mU);return n.length===0?t.push({severity:`error`,message:`A main draw structure is required`}):n.length>1&&t.push({severity:`error`,message:`Only one main draw structure is allowed`}),n}function TU(e){let t=new Set;for(let n of e.edges)n.linkType===_U&&(n.targetRoundNumber||1)>1&&e.nodes.find(e=>e.id===n.sourceNodeId)?.stage===hU&&t.add(n.targetNodeId);let n=new Map;for(let t of e.edges)t.linkType===vU&&n.set(t.targetNodeId,(n.get(t.targetNodeId)||0)+1);for(let[e,r]of n)r>1&&t.add(e);return t}function EU(e,t,n){for(let r of e.nodes){if(r.structureType===yU&&!t.has(r.id)){let t=e.edges.some(e=>e.targetNodeId===r.id);(r.stage===mU||r.stage===hU)&&!t&&(r.drawSize>0&&!(r.drawSize&r.drawSize-1)||n.push({severity:`error`,message:`"${r.structureName}" draw size must be a power of 2`,nodeId:r.id}))}let i=r.structureType===xU?0:2;r.drawSize<i&&n.push({message:`"${r.structureName}" draw size must be at least ${i}`,severity:`error`,nodeId:r.id})}}function DU(e,t){for(let n of e.edges){let r=e.nodes.find(e=>e.id===n.sourceNodeId),i=e.nodes.find(e=>e.id===n.targetNodeId);if(r||t.push({severity:`error`,message:`Edge references missing source node`,edgeId:n.id}),i||t.push({severity:`error`,message:`Edge references missing target node`,edgeId:n.id}),r&&n.sourceRoundNumber){let e=kV(r.structureType,r.drawSize,r.structureOptions);(n.sourceRoundNumber>e||n.sourceRoundNumber<1)&&t.push({severity:`warning`,message:`Edge source round ${n.sourceRoundNumber} is outside "${r.structureName}" range (1-${e})`,edgeId:n.id})}if(i&&n.targetRoundNumber){let e=kV(i.structureType,i.drawSize,i.structureOptions);(n.targetRoundNumber>e||n.targetRoundNumber<1)&&t.push({severity:`warning`,message:`Edge target round ${n.targetRoundNumber} is outside "${i.structureName}" range (1-${e})`,edgeId:n.id})}}}function OU(e,t){let n=new Map;for(let t of e.edges)t.linkType===_U&&(n.has(t.sourceNodeId)||n.set(t.sourceNodeId,[]),n.get(t.sourceNodeId).push(t.id));for(let[r,i]of n)if(i.length>1){let n=e.nodes.find(e=>e.id===r)?.structureName||`Unknown`;for(let e of i)t.push({severity:`error`,message:`"${n}" has multiple winner links (only one allowed)`,edgeId:e})}}function kU(e,t){let n=new Map;for(let t of e.edges)t.sourceRoundNumber&&(n.has(t.sourceNodeId)||n.set(t.sourceNodeId,[]),n.get(t.sourceNodeId).push({round:t.sourceRoundNumber,edgeId:t.id}));for(let[r,i]of n){let n=new Map,a=e.nodes.find(e=>e.id===r)?.structureName||`Unknown`;for(let{round:e,edgeId:r}of i)n.has(e)?t.push({severity:`error`,message:`"${a}" has multiple links from round ${e}`,edgeId:r}):n.set(e,r)}}function AU(e,t,n){let r=e.nodes.filter(e=>e.stage===hU);for(let i of r){let r=e.edges.find(e=>e.sourceNodeId===i.id&&e.linkType===_U&&t.some(t=>t.id===e.targetNodeId));if(r||n.push({severity:`warning`,message:`Qualifying structure "${i.structureName}" has no winner link to a main structure`,nodeId:i.id}),r?.qualifyingPositions){let e=Math.floor(i.drawSize/2);r.qualifyingPositions>e&&n.push({severity:`warning`,message:`Qualifying positions (${r.qualifyingPositions}) exceeds half of "${i.structureName}" draw size (${e})`,edgeId:r.id})}}}function jU(e,t){let n=new Map;for(let t of e.edges){if(t.linkType!==_U)continue;let r=t.targetRoundNumber||1;if(r<=1)continue;let i=e.nodes.find(e=>e.id===t.sourceNodeId);if(!i||i.stage!==hU)continue;n.has(t.targetNodeId)||n.set(t.targetNodeId,[]);let a=i.qualifyingPositions||Math.floor(i.drawSize/4);n.get(t.targetNodeId).push({edgeId:t.id,targetRound:r,qp:a,sourceName:i.structureName})}for(let[r,i]of n){let n=e.nodes.find(e=>e.id===r);if(!n)continue;let a=wV(n.drawSize),o=new Map;for(let e of i)o.set(e.targetRound,(o.get(e.targetRound)||0)+e.qp);for(let{edgeId:e,targetRound:s,sourceName:c}of i)(a.get(s)||0)<(o.get(s)||0)&&t.push({severity:`warning`,message:`"${n.structureName}" round ${s} is not a feed round or has insufficient capacity for ${c} link`,nodeId:r,edgeId:e})}}function MU(e,t){for(let n of e.edges){if(n.linkType!==vU)continue;let r=e.nodes.find(e=>e.id===n.sourceNodeId),i=e.nodes.find(e=>e.id===n.targetNodeId);if(!r||!i)continue;let a=n.sourceRoundNumber||1,o=n.targetRoundNumber||1,s=AV(r.structureType,r.drawSize,a),c=wV(i.drawSize);o!==1&&NU(c,o,s,r,i,a,n.id,t)}}function NU(e,t,n,r,i,a,o,s){let c=e.get(t);c===void 0?s.push({severity:`error`,message:`"${i.structureName}" R${t} is not a feed round — cannot receive ${n} losers from "${r.structureName}" R${a}`,edgeId:o}):n>c?s.push({severity:`error`,message:`"${r.structureName}" R${a} produces ${n} losers but "${i.structureName}" R${t} only has ${c} feed positions`,edgeId:o}):n<c&&s.push({severity:`warning`,message:`"${r.structureName}" R${a} produces ${n} losers but "${i.structureName}" R${t} has ${c} feed positions — ${c-n} will be empty`,edgeId:o})}function PU(e,t){let n=e.nodes.filter(e=>e.stage===gU);for(let r of n){let n=e.edges.filter(e=>e.targetNodeId===r.id);if(n.length===0)continue;let i=0;for(let t of n){let n=e.nodes.find(e=>e.id===t.sourceNodeId);if(n){if(t.linkType===vU){let e=t.sourceRoundNumber||1;i+=AV(n.structureType,n.drawSize,e)}else i+=n.qualifyingPositions||Math.floor(n.drawSize/2)}}i>0&&r.drawSize>i&&t.push({severity:`warning`,message:`"${r.structureName}" draw size (${r.drawSize}) exceeds inbound capacity (${i})`,nodeId:r.id}),i>0&&i>r.drawSize&&t.push({severity:`error`,message:`"${r.structureName}" receives ${i} participants but only has ${r.drawSize} positions`,nodeId:r.id})}}function FU(e,t){let n=new Map;for(let r of e.edges){if(r.linkType!==SU)continue;n.has(r.sourceNodeId)||n.set(r.sourceNodeId,[]),n.get(r.sourceNodeId).push({edgeId:r.id,positions:r.finishingPositions||[]});let i=e.nodes.find(e=>e.id===r.sourceNodeId);if(i&&i.structureType===bU){let e=i.structureOptions?.groupSize||4;for(let n of r.finishingPositions||[])(n<1||n>e)&&t.push({severity:`error`,message:`Position ${n} is outside valid range (1-${e}) for "${i.structureName}"`,edgeId:r.id})}}for(let[r,i]of n){if(i.length<2)continue;let n=e.nodes.find(e=>e.id===r)?.structureName||`Unknown`,a=new Map;for(let{edgeId:e,positions:r}of i)for(let i of r)a.has(i)?t.push({severity:`warning`,message:`Position ${i} from "${n}" is used by multiple POSITION links`,edgeId:e}):a.set(i,e)}}function IU(e){let t=new Map;for(let n of e.nodes)t.set(n.id,[]);for(let n of e.edges){let e=t.get(n.sourceNodeId);e&&e.push(n.targetNodeId)}let n=new Set,r=new Set;function i(e){if(r.has(e))return!0;if(n.has(e))return!1;n.add(e),r.add(e);for(let n of t.get(e)||[])if(i(n))return!0;return r.delete(e),!1}for(let t of e.nodes)if(i(t.id))return!0;return!1}var{MAIN:LU,QUALIFYING:RU,CONSOLATION:zU,PLAY_OFF:BU,LUCKY_DRAW:VU}=t.drawDefinitionConstants;function HU(e,t,n={}){let r=document.createElement(`div`);r.className=`tb-toolbar-wrapper`;let i=document.createElement(`div`);i.className=`tb-toolbar-row`;let a=document.createElement(`div`);a.style.flex=`1`,a.style.minWidth=`0`,i.appendChild(a),r.appendChild(i);let o=document.createElement(`div`);o.className=`tb-validation`,o.style.display=`none`,r.appendChild(o);let s=null,c=()=>{if(!s)return;let e=CU(s);if(o.innerHTML=``,e.length===0){o.style.display=`block`;let e=document.createElement(`div`);e.className=`tb-validation-item`,e.innerHTML=`<span style="color:var(--chc-status-success)">&#10003; Valid topology</span>`,o.appendChild(e)}else{o.style.display=`block`;for(let t of e){let e=document.createElement(`div`);e.className=`tb-validation-item`;let n=document.createElement(`span`);n.className=`tb-validation-icon tb-validation-icon--${t.severity}`,n.textContent=t.severity===`error`?`!`:`?`;let r=document.createElement(`span`);r.textContent=t.message,e.appendChild(n),e.appendChild(r),o.appendChild(e)}}setTimeout(()=>{o.style.display=`none`},5e3)},l=[];if(!n.readOnly){let t=[{label:`Main`,value:LU,onClick:()=>e.onAddStructure(LU),close:!0},{label:`Lucky Draw`,value:VU,onClick:()=>e.onAddStructure(LU,VU),close:!0},{label:`Qualifying`,value:RU,onClick:()=>e.onAddStructure(RU),close:!0},{label:`Consolation`,value:zU,onClick:()=>e.onAddStructure(zU),close:!0},{label:`Playoff`,value:BU,onClick:()=>e.onAddStructure(BU),close:!0}];l.push({label:`Add Structure`,location:`right`,options:t})}if(!n.hideTemplates&&t.length>0){let n=t.map(n=>({label:n.name,value:n.name,onClick:()=>{let r=t.find(e=>e.name===n.name);r&&e.onLoadTemplate(r)},close:!0}));l.push({label:`Templates`,location:`right`,options:n})}!n.readOnly&&e.onClear&&l.push({label:`Clear`,location:`right`,onClick:()=>e.onClear()}),n.readOnly||l.push({label:`Auto Layout`,location:`right`,onClick:()=>e.onAutoLayout()},{label:`Validate`,location:`right`,onClick:()=>c()}),!n.readOnly&&e.onSaveTemplate&&l.push({label:`Save Template`,location:`right`,intent:`is-success`,onClick:()=>e.onSaveTemplate()}),!n.readOnly&&!n.hideGenerate&&l.push({label:`Generate Draw`,location:`right`,intent:`is-success`,onClick:()=>e.onGenerate()}),VF({target:a,items:l});function u(e){s=e}return{element:r,update:u}}function UU({toolbar:e,canvas:t,nodeEditor:n,edgeEditor:r}){let i=document.createElement(`div`);i.className=`tb-layout`,i.appendChild(e.element);let a=document.createElement(`div`);a.className=`tb-body`,a.appendChild(t.element);let o=document.createElement(`div`);o.className=`tb-editor`,o.appendChild(n.element),o.appendChild(r.element),a.appendChild(o),i.appendChild(a);function s(i){if(e.update(i),t.update(i),n.element.style.display=i.selectedNodeId?``:`none`,r.element.style.display=i.selectedEdgeId?``:`none`,!i.selectedNodeId&&!i.selectedEdgeId){if(!o.querySelector(`.tb-editor-empty`)){let e=document.createElement(`div`);e.className=`tb-editor-empty`,e.textContent=`Select a structure or link to view properties`,o.appendChild(e)}}else{let e=o.querySelector(`.tb-editor-empty`);e&&e.remove()}n.update(i),r.update(i)}function c(){e.destroy?.(),t.destroy?.(),n.destroy?.(),r.destroy?.()}return{element:i,update:s,destroy:c}}var{SINGLE_ELIMINATION:WU,FEED_IN:GU,ROUND_ROBIN:KU,LUCKY_DRAW:qU,MAIN:JU,QUALIFYING:YU,CONSOLATION:XU,PLAY_OFF:ZU}=t.drawDefinitionConstants,QU=`WINNER`,$U=`LOSER`,eW=`POSITION`,tW=`tpl-edge-1`,nW=`tpl-edge-2`,rW=`tpl-edge-3`,iW=`tpl-edge-4`,aW=`tpl-edge-5`,oW=`tpl-edge-6`,sW=`tpl-edge-7`,cW=`R1 losers → R1`,lW=[{name:`Single Elimination + Qualifying`,description:`Standard SE main draw with one qualifying structure`,state:{drawName:`SE + Qualifying`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:JU,structureType:WU,drawSize:32,position:{x:320,y:40}},{id:`tpl-qual`,structureName:`Qualifying`,stage:YU,structureType:WU,drawSize:16,qualifyingPositions:4,position:{x:40,y:40}}],edges:[{id:tW,sourceNodeId:`tpl-qual`,targetNodeId:`tpl-main`,linkType:QU,targetRoundNumber:1,qualifyingPositions:4,label:`winners → R1 (4Q)`}]}},{name:`FMLC (First Match Loser Consolation)`,description:`Main draw with first match loser consolation`,state:{drawName:`FMLC`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:JU,structureType:WU,drawSize:32,position:{x:40,y:40}},{id:`tpl-cons`,structureName:`Consolation`,stage:XU,structureType:WU,drawSize:16,position:{x:320,y:40}}],edges:[{id:tW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW}]}},{name:`Feed-In Championship (FIC)`,description:`Main draw with multi-round fed consolation`,state:{drawName:`FIC`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:JU,structureType:WU,drawSize:32,position:{x:40,y:40}},{id:`tpl-cons`,structureName:`Consolation`,stage:XU,structureType:GU,drawSize:31,position:{x:460,y:40}}],edges:[{id:tW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW},{id:nW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:$U,sourceRoundNumber:2,targetRoundNumber:2,label:`R2 losers → R2`},{id:rW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:$U,sourceRoundNumber:3,targetRoundNumber:4,label:`R3 losers → R4`},{id:iW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:$U,sourceRoundNumber:4,targetRoundNumber:6,label:`R4 losers → R6`},{id:aW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:$U,sourceRoundNumber:5,targetRoundNumber:8,label:`R5 losers → R8`}]}},{name:`Compass`,description:`8-draw compass structure`,state:{drawName:`Compass`,nodes:[{id:`tpl-east`,structureName:`East`,stage:JU,structureType:WU,drawSize:32,position:{x:40,y:40}},{id:`tpl-west`,structureName:`West`,stage:XU,structureType:WU,drawSize:16,position:{x:400,y:40}},{id:`tpl-north`,structureName:`North`,stage:XU,structureType:WU,drawSize:8,position:{x:400,y:210}},{id:`tpl-ne`,structureName:`Northeast`,stage:XU,structureType:WU,drawSize:4,position:{x:400,y:380}},{id:`tpl-south`,structureName:`South`,stage:XU,structureType:WU,drawSize:8,position:{x:680,y:40}},{id:`tpl-sw`,structureName:`Southwest`,stage:XU,structureType:WU,drawSize:4,position:{x:680,y:210}},{id:`tpl-nw`,structureName:`Northwest`,stage:XU,structureType:WU,drawSize:4,position:{x:680,y:380}},{id:`tpl-se`,structureName:`Southeast`,stage:XU,structureType:WU,drawSize:4,position:{x:960,y:40}}],edges:[{id:tW,sourceNodeId:`tpl-east`,targetNodeId:`tpl-west`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW},{id:nW,sourceNodeId:`tpl-east`,targetNodeId:`tpl-north`,linkType:$U,sourceRoundNumber:2,targetRoundNumber:1,label:`R2 losers → R1`},{id:rW,sourceNodeId:`tpl-east`,targetNodeId:`tpl-ne`,linkType:$U,sourceRoundNumber:3,targetRoundNumber:1,label:`R3 losers → R1`},{id:iW,sourceNodeId:`tpl-west`,targetNodeId:`tpl-south`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW},{id:aW,sourceNodeId:`tpl-west`,targetNodeId:`tpl-sw`,linkType:$U,sourceRoundNumber:2,targetRoundNumber:1,label:`R2 losers → R1`},{id:oW,sourceNodeId:`tpl-north`,targetNodeId:`tpl-nw`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW},{id:sW,sourceNodeId:`tpl-south`,targetNodeId:`tpl-se`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW}]}},{name:`Round Robin + Playoff`,description:`Round robin groups with winners and consolation playoffs`,state:{drawName:`RR + Playoff`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:JU,structureType:KU,drawSize:16,structureOptions:{groupSize:4},position:{x:40,y:40}},{id:`tpl-playoff-gold`,structureName:`Gold Flight`,stage:ZU,structureType:WU,drawSize:8,position:{x:320,y:40}},{id:`tpl-playoff-silver`,structureName:`Silver Flight`,stage:ZU,structureType:WU,drawSize:8,position:{x:320,y:220}}],edges:[{id:tW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-playoff-gold`,linkType:eW,finishingPositions:[1,2],label:`positions 1,2`},{id:nW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-playoff-silver`,linkType:eW,finishingPositions:[3,4],label:`positions 3,4`}]}},{name:`Lucky Draw + Consolation`,description:`Lucky draw main with consolation receiving R1 losers`,state:{drawName:`Lucky + Consolation`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:JU,structureType:qU,drawSize:11,position:{x:40,y:40}},{id:`tpl-cons`,structureName:`Consolation`,stage:XU,structureType:WU,drawSize:4,position:{x:340,y:40}}],edges:[{id:tW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW}]}},{name:`Lucky Draw → Round Robin`,description:`Lucky draw main with R1 losers feeding into round robin consolation`,state:{drawName:`Lucky → RR`,nodes:[{id:`tpl-main`,structureName:`Main Draw`,stage:JU,structureType:qU,drawSize:25,position:{x:40,y:40}},{id:`tpl-cons-rr`,structureName:`Consolation RR`,stage:XU,structureType:KU,drawSize:12,structureOptions:{groupSize:4},position:{x:500,y:40}}],edges:[{id:tW,sourceNodeId:`tpl-main`,targetNodeId:`tpl-cons-rr`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:cW}]}},{name:`Adaptive (drawSize 11)`,description:`Compass-like multi-structure topology with lucky draw structures`,state:{drawName:`Adaptive`,nodes:[{id:`tpl-east`,structureName:`East`,stage:JU,structureType:qU,drawSize:11,position:{x:40,y:40}},{id:`tpl-west`,structureName:`West`,stage:XU,structureType:qU,drawSize:6,position:{x:340,y:40}},{id:`tpl-north`,structureName:`North`,stage:XU,structureType:WU,drawSize:2,position:{x:340,y:250}},{id:`tpl-south`,structureName:`South`,stage:XU,structureType:WU,drawSize:2,position:{x:600,y:40}}],edges:[{id:tW,sourceNodeId:`tpl-east`,targetNodeId:`tpl-west`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:`R1 losers → R1 (6 losers)`},{id:nW,sourceNodeId:`tpl-east`,targetNodeId:`tpl-north`,linkType:$U,sourceRoundNumber:2,targetRoundNumber:1,label:`R2 losers → R1 (2 losers)`},{id:rW,sourceNodeId:`tpl-west`,targetNodeId:`tpl-south`,linkType:$U,sourceRoundNumber:1,targetRoundNumber:1,label:`R1 losers → R1 (2 losers)`}]}}],{MAIN:uW,QUALIFYING:dW,CONSOLATION:fW,PLAY_OFF:pW,SINGLE_ELIMINATION:mW,LUCKY_DRAW:hW,WINNER:gW,LOSER:_W}=t.drawDefinitionConstants,vW=`POSITION`,yW=class{constructor(e={}){this.config=e,this.store=new vH(e.initialState);let t=[...lW,...e.templates||[]],n=!!e.readOnly,r=this.buildToolbarPanel(t,n),i=this.buildCanvasPanel(n),a=tU({onUpdateNode:n?()=>{}:(e,t)=>this.store.updateNode(e,t),onUpdateEdge:n?()=>{}:(e,t)=>this.store.updateEdge(e,t),onDeleteNode:n?()=>{}:e=>this.store.removeNode(e),readOnly:n,hideDelete:e.hideDelete}),o=pU({onUpdateEdge:n?()=>{}:(e,t)=>this.store.updateEdge(e,t),onDeleteEdge:n?()=>{}:e=>this.store.removeEdge(e),readOnly:n});this.layout=UU({toolbar:r,canvas:i,nodeEditor:a,edgeEditor:o}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}buildToolbarPanel(e,t){return HU({onAddStructure:(e,t)=>this.addDefaultStructure(e,t),onLoadTemplate:e=>{this.store.loadState({...e.state,selectedNodeId:null,selectedEdgeId:null,templateName:e.name})},onAutoLayout:()=>{this.store.autoLayout();let e=this.store.getState();this.store.loadState(e)},onGenerate:()=>this.handleGenerate(),onSaveTemplate:this.config.onSaveTemplate?()=>this.config.onSaveTemplate(this.store.getState()):void 0,onClear:this.config.onClear},e,{hideTemplates:this.config.hideTemplates,hideGenerate:this.config.hideGenerate,readOnly:t})}buildCanvasPanel(e){return kH({onSelectNode:e=>this.store.selectNode(e),onSelectEdge:e=>this.store.selectEdge(e),onDoubleClickNode:this.config.onDoubleClickNode?e=>{let t=this.store.getState(),n=t.nodes.find(t=>t.id===e);n&&this.config.onDoubleClickNode(n,t)}:void 0,onMoveNode:(e,t,n)=>this.store.updateNode(e,{position:{x:t,y:n}}),onCreateEdge:e?()=>{}:(e,t,n)=>{this.handleCreateEdge(e,t,n)},onPortMouseDown:()=>{}})}handleCreateEdge(e,t,n){let r=this.store.getState().nodes.find(t=>t.id===e);if(n===vW){let i=this.store.getState().edges.filter(t=>t.sourceNodeId===e&&t.linkType===vW),a=new Set(i.flatMap(e=>e.finishingPositions||[])),o=r?.structureOptions?.groupSize||4,s=1;for(let e=1;e<=o;e++)if(!a.has(e)){s=e;break}this.store.addEdge({sourceNodeId:e,targetNodeId:t,linkType:n,finishingPositions:[s]})}else if(n===_W){let i=this.store.getState().edges.filter(t=>t.sourceNodeId===e&&t.linkType===_W),a=new Set(i.map(e=>e.sourceRoundNumber)),o=r?kV(r.structureType,r.drawSize,r.structureOptions):1,s=1;for(let e=1;e<=o;e++)if(!a.has(e)){s=e;break}this.store.addEdge({sourceNodeId:e,targetNodeId:t,linkType:n,sourceRoundNumber:s})}else{let i=n===gW&&r?.stage===dW;this.store.addEdge({sourceNodeId:e,targetNodeId:t,linkType:n,...i&&{targetRoundNumber:1}})}}render(e){e.appendChild(this.layout.element)}destroy(){this.unsubscribe(),this.layout.destroy?.(),this.layout.element.remove()}autoLayout(){this.store.autoLayout();let e=this.store.getState();this.store.loadState(e)}getState(){return this.store.getState()}loadState(e){this.store.loadState(e)}addDefaultStructure(e,t){let n=t===hW,r=this.store.getState().nodes.filter(t=>t.stage===e).length,i={[uW]:n?`Lucky Draw`:`Main Draw`,[dW]:`Qualifying ${r+1}`,[fW]:`Consolation`,[pW]:`Playoff ${r+1}`},a={[uW]:n?11:32,[dW]:16,[fW]:16,[pW]:4}[e]||16,o=this.store.addNode({structureName:i[e]||e,stage:e,structureType:t||mW,drawSize:a,...e===dW&&{qualifyingPositions:Math.floor(a/4)}});this.scrollCanvasToNode(o)}scrollCanvasToNode(e){let t=this.layout.element.querySelector(`.tb-canvas`);t&&requestAnimationFrame(()=>{let n=e.position.x+rH(e)+40;n>t.scrollLeft+t.clientWidth&&t.scrollTo({left:n-t.clientWidth,behavior:`smooth`})})}handleGenerate(){let e=this.store.getState(),t=CU(e);t.some(e=>e.severity===`error`)&&console.warn(`Topology validation errors:`,t),this.config.onGenerate&&this.config.onGenerate(e)}},{MAIN:bW,CONSOLATION:xW,QUALIFYING:SW,PLAY_OFF:CW,SINGLE_ELIMINATION:wW,FEED_IN:TW,FIRST_MATCH_LOSER_CONSOLATION:EW,FEED_IN_CHAMPIONSHIP:DW,COMPASS:OW,WINNER:kW,LOSER:AW,ROUND_ROBIN:jW,AD_HOC:MW,LUCKY_DRAW:NW}=t.drawDefinitionConstants,PW=`POSITION`;function FW(e,t){let n=e.nodes.filter(e=>e.stage===xW),r=e.nodes.filter(e=>e.stage===SW),i=e.nodes.filter(e=>e.stage===CW);if(t.structureType===jW)return e.edges.some(n=>n.sourceNodeId===t.id&&n.linkType===PW&&e.nodes.some(e=>e.id===n.targetNodeId&&e.stage===CW))?`ROUND_ROBIN_WITH_PLAYOFF`:jW;if(t.structureType===MW)return MW;if(t.structureType===TW)return TW;if(t.structureType===NW)return NW;if(n.length===7&&r.length===0&&i.length===0){let n=e.edges.filter(e=>e.linkType===AW&&e.sourceNodeId===t.id),r=new Set(n.map(e=>e.sourceRoundNumber));if(r.has(1)&&r.has(2)&&r.has(3))return OW}if(n.length===1&&r.length===0&&i.length===0){let r=n[0],i=e.edges.filter(e=>e.linkType===AW&&e.sourceNodeId===t.id&&e.targetNodeId===r.id);if(r.structureType===TW||i.length>1)return DW;if(i.length===1&&i[0].sourceRoundNumber===1)return EW}return wW}function IW(e){let t=e.nodes.find(e=>e.stage===bW);if(!t)throw Error(`No main structure node found`);let n=e.nodes.filter(e=>e.stage===SW),r=e.nodes.filter(e=>e.stage===CW),i=FW(e,t);i===wW&&!VW(t.drawSize)&&(i=TW);let a={drawName:e.drawName,drawType:i,drawSize:t.drawSize,matchUpFormat:t.matchUpFormat||void 0,structureOptions:t.structureOptions||void 0,automated:!0};n.length>0&&zW(a,n,e.edges);let o=[];return LW(e,t,i,o),RW(e,t,r,a),{drawOptions:a,postGenerationMethods:o}}function LW(e,t,n,r){let i=e.nodes.filter(e=>e.stage===xW),a=e.edges.filter(e=>e.linkType===AW&&e.sourceNodeId===t.id&&i.some(t=>t.id===e.targetNodeId)),o=[EW,DW,OW];if(a.length===0||o.includes(n))return;let s=new Map;for(let e of a)s.has(e.targetNodeId)||s.set(e.targetNodeId,[]),s.get(e.targetNodeId).push(e);for(let[e,t]of s){let n=i.find(t=>t.id===e);if(!n)continue;let a=t.map(e=>({sourceRoundNumber:e.sourceRoundNumber||1,targetRoundNumber:e.targetRoundNumber||1}));r.push({method:`attachConsolationStructures`,params:{structureName:n.structureName,structureType:n.structureType,drawSize:n.drawSize,matchUpFormat:n.matchUpFormat||void 0,structureOptions:n.structureOptions||void 0,links:a}})}}function RW(e,t,n,r){let i=t.structureType===jW,a=i?e.edges.filter(e=>e.sourceNodeId===t.id&&e.linkType===PW&&n.some(t=>t.id===e.targetNodeId)):[];if(i&&a.length>0){let e=new Map;for(let t of a)e.has(t.targetNodeId)||e.set(t.targetNodeId,[]),e.get(t.targetNodeId).push(t);let t=[];for(let[r,i]of e){let e=n.find(e=>e.id===r);if(!e)continue;let a=Array.from(new Set(i.flatMap(e=>e.finishingPositions||[]))).sort((e,t)=>e-t),o=e.structureOptions?.playoffDrawType||wW,s={finishingPositions:a,structureName:e.structureName,drawType:o};o===jW&&e.structureOptions?.groupSize&&(s.structureOptions={groupSize:e.structureOptions.groupSize}),t.push(s)}t.length>0&&(r.structureOptions={...r.structureOptions,playoffGroups:t})}else if(n.length>0){let i=BW(t.id,n,e.edges);i&&(r.withPlayoffs=i)}}function zW(e,t,n){let r=n.filter(e=>e.linkType===kW&&t.some(t=>t.id===e.sourceNodeId)),i={};for(let e of t){let t=r.find(t=>t.sourceNodeId===e.id),n=t?.targetRoundNumber||1;i[n]||(i[n]=[]),i[n].push({node:e,edge:t})}let a=0;e.qualifyingProfiles=Object.entries(i).map(([e,t])=>{let n=t.map(({node:e,edge:t})=>{let n=e.qualifyingPositions||t?.qualifyingPositions||Math.floor(e.drawSize/4);return a+=n,{structureName:e.structureName,drawType:e.structureType,drawSize:e.drawSize,qualifyingPositions:n,seedsCount:0}});return{roundTarget:Number(e),structureProfiles:n}}),e.qualifiersCount=a,e.qualifyingPlaceholder=!0}function BW(e,t,n){let r=n.filter(n=>n.sourceNodeId===e&&n.linkType===AW&&t.some(e=>e.id===n.targetNodeId));if(!r.length)return;let i=[],a={},o={};for(let e of r){if(!e.sourceRoundNumber)continue;let r=t.find(t=>t.id===e.targetNodeId);if(!r)continue;i.push({[e.sourceRoundNumber]:1});let s=`0-${i.length}`;a[s]={name:r.structureName,abbreviation:r.structureName.substring(0,3)};let c=BW(r.id,t,n);c&&(o[e.sourceRoundNumber]=c)}if(i.length)return{roundProfiles:i,...Object.keys(a).length>0&&{playoffAttributes:a},...Object.keys(o).length>0&&{roundPlayoffs:o}}}function VW(e){return e>0&&!(e&e-1)}var{MAIN:HW}=t.drawDefinitionConstants,UW=()=>`spl-layout`,WW=()=>`spl-left`,GW=()=>`spl-toggle`,KW=()=>`spl-center`,qW=()=>`spl-center-header`,JW=()=>`spl-center-title`,YW=()=>`spl-center-actions`,XW=()=>`spl-center-leading`,ZW=()=>`spl-grid-slot`,QW=()=>`spl-right`,$W=()=>`spl-matchup-card`,eG=()=>`spl-card-title`,tG=()=>`spl-card-sides`,nG=()=>`spl-card-meta`,rG=()=>`spl-card-chips`,iG=()=>`spl-card-chip`,aG=()=>`sp-panel`,oG=()=>`sp-panel-header`,sG=()=>`sp-panel-title`,cG=()=>`sp-panel-meta`,lG=()=>`sp-date-strip`,uG=()=>`sp-date-chip`,dG=()=>`sp-badges`,fG=()=>`sp-catalog`,pG=()=>`sp-catalog-toolbar`,mG=()=>`sp-input`,hG=()=>`sp-select`,gG=()=>`sp-group`,_G=()=>`sp-group-header`,vG=()=>`sp-group-body`,yG=()=>`sp-group-chevron`,bG=()=>`sp-issues`,xG=()=>`sp-issue`,SG=()=>`sp-issue-code`,CG=()=>`sp-issue-msg`,wG=()=>`sp-inspector`,TG=()=>`sp-kv`,EG=()=>`sp-kv-key`,DG=()=>`sp-kv-value`,OG=()=>`sp-small`;function kG(e,t,n){let r=!!n?.hideLeft,i=n?.catalogSide===`left`,a=document.createElement(`div`);a.className=UW();let o=null,s=null;if(r)i?a.classList.add(`spl-catalog-left`):a.classList.add(`spl-no-left`);else{o=document.createElement(`div`),o.className=WW(),s=document.createElement(`button`),s.className=GW(),s.textContent=`◀`,s.title=`Toggle sidebar`,s.addEventListener(`click`,()=>t.onToggleLeft()),o.appendChild(s);let n=document.createElement(`div`);n.className=`spl-left-content`,n.style.cssText=`display:flex;flex-direction:column;gap:12px;flex:1;min-height:0`,e.dateStrip.element.style.flex=`1`,e.dateStrip.element.style.minHeight=`0`,e.dateStrip.element.style.overflow=`auto`,n.appendChild(e.dateStrip.element),e.issuesPanel.element.style.flex=`1`,e.issuesPanel.element.style.minHeight=`0`,e.issuesPanel.element.style.overflow=`auto`,n.appendChild(e.issuesPanel.element),o.appendChild(n)}let c=e.courtGridSlot.element,l=document.createElement(`div`);l.className=QW(),e.matchUpCatalog.element.style.flex=`3`,e.matchUpCatalog.element.style.minHeight=`0`,e.matchUpCatalog.element.style.overflow=`auto`,l.appendChild(e.matchUpCatalog.element),e.inspectorPanel.element.style.flex=`1`,e.inspectorPanel.element.style.minHeight=`120px`,e.inspectorPanel.element.style.overflow=`auto`,l.appendChild(e.inspectorPanel.element),o&&a.appendChild(o),i&&r?(a.appendChild(l),a.appendChild(c)):(a.appendChild(c),a.appendChild(l));function u(t){r||(t.leftCollapsed?(a.classList.add(`spl-left-collapsed`),s&&(s.textContent=`▶`)):(a.classList.remove(`spl-left-collapsed`),s&&(s.textContent=`◀`)),e.dateStrip.update(t),e.issuesPanel.update(t)),e.courtGridSlot.update(t),e.matchUpCatalog.update(t),e.inspectorPanel.update(t)}return{element:a,update:u}}function AG(e){let t=e.sides;if(t?.length===2){let e=jG(t[0]),n=jG(t[1]);if(e&&n)return`${e} vs ${n}`;if(e)return`${e} vs TBD`;if(n)return`TBD vs ${n}`}return`TBD vs TBD`}function jG(e){return e?`${e.participantName??``}${e.seedNumber?` [${e.seedNumber}]`:``}`:``}function MG(e){let t=[e.eventName,e.drawName??``,e.roundName??``];if(e.sides)for(let n of e.sides)n.participantName&&t.push(n.participantName);return t.join(` `).toLowerCase()}function NG(){let e=document.createElement(`div`);e.className=aG();let t=document.createElement(`div`);t.className=oG();let n=document.createElement(`div`);n.className=sG(),n.textContent=`Inspector`,t.appendChild(n),e.appendChild(t);let r=document.createElement(`div`);r.className=wG(),e.appendChild(r);function i(e){r.innerHTML=``;let t=e.selectedMatchUp;if(!t){let e=document.createElement(`div`);e.className=OG(),e.textContent=`Select a matchUp in the catalog to see details.`,r.appendChild(e);return}if(PG(r,`Event`,t.eventName),PG(r,`Draw`,t.drawName??t.drawId),PG(r,`Round`,t.roundName??`Round ${t.roundNumber}`),PG(r,`Type`,t.matchUpType??`—`),PG(r,`Format`,t.matchUpFormat??`—`),PG(r,`Scheduled`,t.isScheduled?`Yes`:`No`),t.scheduledTime&&PG(r,`Time`,t.scheduledTime),t.scheduledCourtName&&PG(r,`Court`,t.scheduledCourtName),t.sides?.length){let e=document.createElement(`div`);e.className=OG(),e.style.marginTop=`8px`,e.textContent=`Participants:`,r.appendChild(e);let n=document.createElement(`div`);n.className=`spl-inspector-sides`;for(let e of t.sides){let t=document.createElement(`div`);t.className=`spl-inspector-side`;let r=document.createElement(`span`);if(r.textContent=jG(e)||`TBD`,t.appendChild(r),e.ranking){let n=document.createElement(`span`);n.className=`spl-inspector-seed`,n.textContent=`#${e.ranking}`,t.appendChild(n)}n.appendChild(t)}r.appendChild(n)}}return{element:e,update:i}}function PG(e,t,n){let r=document.createElement(`div`);r.className=TG();let i=document.createElement(`div`);i.className=EG(),i.textContent=t;let a=document.createElement(`div`);a.className=DG(),a.textContent=n,r.appendChild(i),r.appendChild(a),e.appendChild(r)}var FG=new Set([`COMPLETED`,`RETIRED`,`WALKOVER`,`DEFAULTED`,`DOUBLE_WALKOVER`,`DOUBLE_DEFAULT`,`CANCELLED`,`ABANDONED`,`DEAD_RUBBER`]);function IG(e){return!!e&&FG.has(e)}function LG(e,t,n=`dim`,r,i=!1){let a=t.toLowerCase().trim();return e.filter(e=>n===`hide`&&e.isScheduled||!i&&IG(e.matchUpStatus)||r&&(r.eventType&&e.matchUpType!==r.eventType||r.eventName&&e.eventName!==r.eventName||r.drawName&&(e.drawName??e.drawId)!==r.drawName||r.gender&&e.gender!==r.gender||r.roundName&&e.roundName!==r.roundName)?!1:!a||MG(e).includes(a))}function RG(e){let t=new Map;for(let n of e){if(n.isScheduled||IG(n.matchUpStatus))continue;let e=t.get(n.eventId);(e===void 0||n.roundNumber<e)&&t.set(n.eventId,n.roundNumber)}return t}var zG={CONSOLATION:`Consolation`,PLAYOFF:`Playoff`,QUALIFYING:`Qualifying`,ROUND_ROBIN:`Round Robin`,PLAY_OFF:`Playoff`,Q_PLAYOFF:`Qualifying Playoff`,COMPASS:`Compass`,VOLUNTARY_CONSOLATION:`Voluntary Consolation`},BG=`Unscheduled`;function VG(e){if(e.structureName&&e.structureName.trim())return e.structureName.trim();let t=e.stage;return!t||t===`MAIN`?``:zG[t]??t.charAt(0)+t.slice(1).toLowerCase().replace(/_/g,` `)}function HG(e){let t;for(let n of e){let e=n.scheduledTime;e&&(t===void 0||e.localeCompare(t)<0)&&(t=e)}return t}function UG(e){let t=(e.sides??[]).filter(e=>!!e.participantId).length;return t>2?2:t}function WG(e){let t=0;for(let n of e){let e=UG(n);if(e>t&&(t=e),t===2)break}return t}function GG(e){return e.map((e,t)=>({item:e,index:t,readiness:UG(e)})).sort((e,t)=>t.readiness-e.readiness||e.index-t.index).map(e=>e.item)}function KG(e,t){let n=new Map,r=e=>{if(t===`draw`)return`${e.eventName} \u2014 ${e.drawName??e.drawId}`;if(t===`round`)return e.roundName??`Round ${e.roundNumber}`;if(t===`structure`){let t=VG(e);return t?`${e.eventName} \u2014 ${t}`:e.eventName}return t===`time`?e.scheduledTime??BG:e.eventName};for(let t of e){let e=r(t),i=n.get(e);i?i.push(t):n.set(e,[t])}return new Map([...n.entries()].map(([e,t])=>[e,GG(t)]).sort((e,t)=>{let n=WG(e[1]),r=WG(t[1]);if(n!==r)return r-n;let i=HG(e[1]),a=HG(t[1]);return i!==void 0&&a!==void 0&&i!==a?i.localeCompare(a):i!==void 0&&a===void 0?-1:i===void 0&&a!==void 0?1:e[0].localeCompare(t[0],void 0,{numeric:!0})}))}function qG(e,t,n={}){let r=document.createElement(`div`);r.className=$W(),r.setAttribute(`data-matchup-id`,e.matchUpId);let i=IG(e.matchUpStatus);e.isScheduled?(r.classList.add(`scheduled`),r.draggable=!1):i?(r.classList.add(`completed`),r.draggable=!1):(r.draggable=!0,r.addEventListener(`dragstart`,t=>{t.stopPropagation(),t.dataTransfer.setDragImage(r,r.offsetWidth/2,20),t.dataTransfer.setData(`application/json`,JSON.stringify({type:`CATALOG_MATCHUP`,matchUp:e})),t.dataTransfer.effectAllowed=`copyMove`})),t.onClick&&r.addEventListener(`click`,n=>{n.stopPropagation(),t.onClick(e)});let a=document.createElement(`div`);if(a.className=eG(),typeof n.roundOffset==`number`){let e=n.roundOffset===0?`spl-card-title--round-current`:n.roundOffset===1?`spl-card-title--round-next`:`spl-card-title--round-later`;a.classList.add(e)}let o=`${e.eventName} \u2014 ${e.roundName??`Round `+e.roundNumber}`,s=n.prominentTime&&!!e.scheduledTime;if(s){a.classList.add(`with-time`);let t=document.createElement(`span`);t.className=`spl-card-title-text`,t.textContent=o;let n=document.createElement(`span`);n.className=`spl-card-time-header`,n.textContent=e.scheduledTime,a.appendChild(t),a.appendChild(n)}else a.textContent=o;r.appendChild(a);let c=document.createElement(`div`);c.className=tG(),c.textContent=AG(e),r.appendChild(c);let l=document.createElement(`div`);l.className=nG();let u=[];e.drawName&&u.push(e.drawName),e.matchUpType&&u.push(e.matchUpType.toLowerCase()),l.textContent=u.join(` · `),r.appendChild(l);let d=document.createElement(`div`);if(d.className=rG(),e.scheduledTime&&!s&&d.appendChild(JG(e.scheduledTime,`time`)),e.scheduledCourtName&&d.appendChild(JG(e.scheduledCourtName,`court`)),e.matchUpFormat&&d.appendChild(JG(e.matchUpFormat,`type`)),i&&e.matchUpStatus){let t=e.matchUpStatus.replace(/_/g,` `);d.appendChild(JG(t,`status`))}if(e.stage&&e.stage!==`MAIN`){let t=e.stage.replace(/_/g,` `);d.appendChild(JG(t,`stage`))}if(d.children.length&&r.appendChild(d),e.isScheduled){let e=document.createElement(`span`);e.className=`spl-matchup-check`,e.textContent=`✓`,r.appendChild(e)}return r}function JG(e,t){let n=document.createElement(`div`);return n.className=iG()+` `+t,n.textContent=e,n}function YG(e,t){let n=new Set;for(let r of e){let e=t(r);e&&n.add(e)}return[...n].sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}))}function XG(e){let t=document.createElement(`div`);t.className=aG();let n=`spl-catalog-drop-over`,r=`is-filtering`,i=new Set,a=null,o,s={};t.addEventListener(`dragover`,e=>{e.preventDefault(),t.classList.add(n),e.dataTransfer.dropEffect=`move`}),t.addEventListener(`dragleave`,e=>{t.contains(e.relatedTarget)||t.classList.remove(n)}),t.addEventListener(`drop`,r=>{if(t.classList.remove(n),r.preventDefault(),!e.onDropRemove)return;let i;try{i=JSON.parse(r.dataTransfer.getData(`application/json`))}catch{return}(i.type===`CATALOG_MATCHUP`||i.type===`GRID_MATCHUP`)&&e.onDropRemove(i.matchUp.matchUpId)});let c=document.createElement(`div`);c.className=oG();let l=document.createElement(`div`);l.className=`spl-catalog-title-row`;let u=document.createElement(`div`);u.className=sG(),u.textContent=`MatchUp Catalog`;let d=document.createElement(`button`);d.className=`spl-catalog-filter-btn`,d.title=`Filter matchUps`,d.innerHTML=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/></svg>`,l.appendChild(u),l.appendChild(d);let f=document.createElement(`div`);f.className=cG(),c.appendChild(l),c.appendChild(f),t.appendChild(c);let p=document.createElement(`div`);p.className=pG();let m=document.createElement(`input`);m.type=`text`,m.placeholder=`Search matchUps...`,m.className=mG(),m.addEventListener(`input`,()=>e.onSearchChange(m.value));let h=SC(m,()=>{m.value=``,e.onSearchChange(``),m.focus()}),g=document.createElement(`select`);g.className=hG();for(let[e,t]of[[`event`,`By Event`],[`draw`,`By Draw`],[`round`,`By Round`],[`structure`,`By Structure`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,g.appendChild(n)}g.addEventListener(`change`,()=>e.onGroupByChange(g.value)),p.appendChild(h),p.appendChild(g),t.appendChild(p);function _(){o&&=(o.destroy(),void 0)}function v(){return!!(s.eventType||s.eventName||s.drawName||s.gender||s.roundName)}function y(){d.classList.toggle(`active`,v())}function b(){let t=a?.matchUpCatalog??[],n=document.createElement(`div`);n.className=`spl-filter-popover`;let i=document.createElement(`div`);i.className=`spl-filter-header`;let o=document.createElement(`button`);o.className=`spl-filter-clear-btn`,o.textContent=`Clear All`,o.addEventListener(`click`,t=>{t.stopPropagation(),s={},e.onFilterChange(s),y();for(let e of n.querySelectorAll(`select`)){e.value=``,e.classList.remove(r);let t=e.previousElementSibling;t?.classList.contains(`spl-filter-label`)&&t.classList.remove(r)}}),i.appendChild(o);let c=document.createElement(`button`);c.className=`spl-filter-close-btn`,c.textContent=`×`,c.addEventListener(`click`,e=>{e.stopPropagation(),_()}),i.appendChild(c),n.appendChild(i);let l=[{label:`All Event Types`,key:`eventType`,values:YG(t,e=>e.matchUpType)},{label:`All Events`,key:`eventName`,values:YG(t,e=>e.eventName)},{label:`All Flights`,key:`drawName`,values:YG(t,e=>e.drawName)},{label:`All Genders`,key:`gender`,values:YG(t,e=>e.gender)},{label:`All Rounds`,key:`roundName`,values:YG(t,e=>e.roundName)}];for(let t of l){if(t.values.length<2)continue;let i=document.createElement(`label`);i.className=`spl-filter-label`,i.textContent=t.label,n.appendChild(i);let a=document.createElement(`select`);a.className=`spl-filter-select`;let o=document.createElement(`option`);o.value=``,o.textContent=t.label,a.appendChild(o);for(let e of t.values){let t=document.createElement(`option`);t.value=e,t.textContent=e,a.appendChild(t)}a.value=s[t.key]??``;let c=()=>{let e=a.value!==``;a.classList.toggle(r,e),i.classList.toggle(r,e)};c(),a.addEventListener(`change`,()=>{s={...s,[t.key]:a.value||void 0},e.onFilterChange(s),y(),c()}),n.appendChild(a)}let u=document.createElement(`label`);u.className=`spl-filter-toggle`;let d=document.createElement(`input`);d.type=`checkbox`,d.checked=a?.showScheduled??!1,d.addEventListener(`change`,()=>{e.onShowScheduledChange?.(d.checked)}),u.appendChild(d),u.appendChild(document.createTextNode(` Show assigned`)),n.appendChild(u);let f=document.createElement(`label`);f.className=`spl-filter-toggle`;let p=document.createElement(`input`);return p.type=`checkbox`,p.checked=a?.showCompleted??!1,p.addEventListener(`change`,()=>{e.onShowCompletedChange(p.checked)}),f.appendChild(p),f.appendChild(document.createTextNode(` Show completed`)),n.appendChild(f),n}d.addEventListener(`click`,()=>{_(),o=km(d,{content:b(),placement:`bottom-start`,interactive:!0,trigger:`manual`,appendTo:()=>t,onClickOutside:()=>_(),theme:``}),o.show()});let x=document.createElement(`div`);x.className=fG(),t.appendChild(x);function S(t){a=t,s=t.catalogFilters??{},y();let n=RG(t.matchUpCatalog),r=t.showScheduled?t.scheduledBehavior:`hide`,o=LG(t.matchUpCatalog,t.catalogSearchQuery,r,t.catalogFilters,t.showCompleted),c=KG(o,t.catalogGroupBy),l=o.filter(e=>!e.isScheduled).length;f.textContent=`${l} unscheduled`,m.value!==t.catalogSearchQuery&&(m.value=t.catalogSearchQuery,CC(h)),g.value!==t.catalogGroupBy&&(g.value=t.catalogGroupBy),x.innerHTML=``;for(let[r,o]of c){let s=document.createElement(`div`);s.className=gG();let c=i.has(r),l=document.createElement(`div`);l.className=_G();let u=document.createElement(`span`);u.className=yG(),u.textContent=c?`▶`:`▼`;let d=document.createElement(`span`);d.textContent=`${r} (${o.length})`,l.appendChild(u),l.appendChild(d),l.addEventListener(`click`,()=>{i.has(r)?i.delete(r):i.add(r),a&&S(a)});let f=document.createElement(`div`);f.className=vG(),c&&(f.style.display=`none`);for(let r of o){let i=n.get(r.eventId),a=qG(r,{onClick:t=>e.onMatchUpSelected?.(t)},{roundOffset:i!==void 0&&!r.isScheduled&&!IG(r.matchUpStatus)?Math.max(0,r.roundNumber-i):void 0});t.selectedMatchUp?.matchUpId===r.matchUpId&&a.classList.add(`selected`),f.appendChild(a)}s.appendChild(l),s.appendChild(f),x.appendChild(s)}}return{element:t,update:S}}function ZG(e){let t={ERROR:[],WARN:[],INFO:[]},n={},r={total:e.length,ERROR:0,WARN:0,INFO:0},i={},a=e=>e===`ERROR`?0:e===`WARN`?1:2;for(let a of e)if(t[a.severity].push(a),r[a.severity]++,a.date){(n[a.date]??=[]).push(a);let e=i[a.date]??={total:0,ERROR:0,WARN:0,INFO:0};e.total++,e[a.severity]++}let o=(e,t)=>a(e.severity)-a(t.severity)||e.message.localeCompare(t.message),s=[...e].sort(o);for(let e of Object.keys(t))t[e].sort(o);for(let e of Object.keys(n))n[e].sort(o);return{all:s,bySeverity:t,byDate:n,counts:r,countsByDate:i}}var QG=`spl-cell--issue-pulse`;function $G(){let e=document.createElement(`div`);e.className=aG();let t=document.createElement(`div`);t.className=oG();let n=document.createElement(`div`);n.className=sG(),n.textContent=`Issues`;let r=document.createElement(`div`);r.className=cG(),t.appendChild(n),t.appendChild(r),e.appendChild(t);let i=document.createElement(`div`);i.className=bG(),e.appendChild(i);function a(e){let t=ZG(e.issues);if(r.textContent=`${t.counts.total} total (${t.counts.ERROR} errors)`,i.innerHTML=``,!t.all.length){let e=document.createElement(`div`);e.className=OG(),e.textContent=`No scheduling conflicts.`,i.appendChild(e);return}for(let e of t.all.slice(0,30)){let t=document.createElement(`div`);t.className=xG(),e.severity===`ERROR`?t.classList.add(`error`):e.severity===`WARN`?t.classList.add(`warn`):t.classList.add(`info`);let n=document.createElement(`div`);n.className=SG(),n.textContent=e.severity;let r=document.createElement(`div`);if(r.className=CG(),e.participants){if(e.prefix){let t=document.createElement(`span`);t.textContent=e.prefix,t.style.opacity=`0.7`,r.appendChild(t)}let t=document.createElement(`span`);t.textContent=(e.issueType||``)+`: `,t.style.opacity=`0.7`,r.appendChild(t);let n=document.createElement(`span`);if(n.textContent=e.participants,n.style.color=`var(--spl-issue-participant1, #4fc3f7)`,n.style.fontWeight=`600`,r.appendChild(n),e.conflictParticipants?.length){let t=document.createElement(`span`);t.textContent=` conflicts with `,t.style.opacity=`0.7`,r.appendChild(t),e.conflictParticipants.forEach((e,t)=>{if(t>0){let e=document.createElement(`span`);e.textContent=`, `,e.style.opacity=`0.7`,r.appendChild(e)}let n=document.createElement(`span`);n.textContent=e,n.style.color=`var(--spl-issue-participant2, #ffb74d)`,n.style.fontWeight=`600`,r.appendChild(n)})}}else r.textContent=e.message;if(e.matchUpId){t.style.cursor=`pointer`;let n=e.matchUpId;t.addEventListener(`click`,()=>{console.log(`[issuesPanel] clicked issue row, matchUpId:`,n),o(n)})}else console.log(`[issuesPanel] issue has no matchUpId:`,e.message);t.appendChild(n),t.appendChild(r),i.appendChild(t)}}function o(e){let t=`.spl-grid-cell[data-matchup-id="${e}"]`,n=document.querySelector(t);console.log(`[issuesPanel] scrollToMatchUp selector:`,t,`found:`,!!n),n&&(n.scrollIntoView({behavior:`smooth`,block:`center`,inline:`center`}),n.classList.remove(QG),n.offsetWidth,n.classList.add(QG),n.addEventListener(`animationend`,()=>n.classList.remove(QG),{once:!0}))}return{element:e,update:a}}function eK(e){let t=document.createElement(`div`);t.className=aG();let n=document.createElement(`div`);n.className=oG();let r=document.createElement(`div`);r.className=sG(),r.textContent=`Dates`;let i=document.createElement(`div`);i.className=cG(),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=lG(),t.appendChild(a);function o(t){let n=t.scheduleDates;i.textContent=`${n.length} dates`,a.innerHTML=``;for(let r of n){let n=document.createElement(`div`);n.className=uG(),r.date===t.selectedDate&&n.classList.add(`selected`),r.isActive||n.classList.add(`inactive`),n.setAttribute(`data-date`,r.date);let i=document.createElement(`div`),o=document.createElement(`div`);o.style.cssText=`font-weight:800;font-size:0.75rem`,o.textContent=r.date;let s=document.createElement(`div`);s.style.cssText=`font-size:0.6875rem;color:var(--sp-muted)`,s.textContent=r.isActive?`Active`:`Inactive`,i.appendChild(o),i.appendChild(s);let c=document.createElement(`div`);if(c.className=dG(),r.matchUpCount!=null){let e=document.createElement(`div`);e.className=`spl-date-badge matchups`,e.textContent=`${r.matchUpCount} matchUps`,c.appendChild(e)}if(r.issueCount&&r.issueCount>0){let e=document.createElement(`div`);e.className=`spl-date-badge issues`,e.textContent=`${r.issueCount} issues`,c.appendChild(e)}n.appendChild(i),n.appendChild(c),n.addEventListener(`click`,()=>e.onDateSelected(r.date)),a.appendChild(n)}}return{element:t,update:o}}function tK(e,t,n){let r=document.createElement(`div`);r.className=KW();let i=document.createElement(`div`);i.className=qW();let a=n?.titleLeadingActions,o;if(n?.titleSlot?o=n.titleSlot:(o=document.createElement(`div`),o.className=JW(),o.textContent=`Court Grid`),a){let e=document.createElement(`div`);e.className=XW();let t=Array.isArray(a)?a:[a];for(let n of t)e.appendChild(n);e.appendChild(o),i.appendChild(e)}else i.appendChild(o);let s=n?.headerActions;if(s){let e=document.createElement(`div`);e.className=YW();let t=Array.isArray(s)?s:[s];for(let n of t)e.appendChild(n);i.appendChild(e)}r.appendChild(i);let c=document.createElement(`div`);c.className=ZW(),n?.gridMaxHeight&&(c.style.maxHeight=n.gridMaxHeight),e&&c.appendChild(e),c.addEventListener(`dragover`,e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`}),c.addEventListener(`drop`,e=>{if(e.preventDefault(),!t.onMatchUpDrop)return;let n;try{n=JSON.parse(e.dataTransfer.getData(`application/json`))}catch{return}(n.type===`CATALOG_MATCHUP`||n.type===`GRID_MATCHUP`)&&t.onMatchUpDrop(n,e)}),r.appendChild(c);function l(e){}return{element:r,update:l}}var nK=class{constructor(e){this.listeners=new Set,this.config=e;let t=e.initialCatalogState??{};this.state={matchUpCatalog:e.matchUpCatalog,scheduleDates:e.scheduleDates,issues:e.issues??[],selectedDate:e.scheduleDates[0]?.date??null,selectedMatchUp:null,catalogSearchQuery:t.catalogSearchQuery??``,catalogGroupBy:t.catalogGroupBy??`event`,catalogFilters:t.catalogFilters??{},showCompleted:t.showCompleted??!1,showScheduled:t.showScheduled??!1,scheduledBehavior:e.scheduledBehavior??`dim`,schedulingMode:e.schedulingMode??`immediate`,pendingActions:[],hasUnsavedChanges:!1,leftCollapsed:!!e.hideLeft,hideLeft:!!e.hideLeft,activeStripVisible:e.activeStripVisible??!0}}getState(){return this.state}setMatchUpCatalog(e){this.setState({matchUpCatalog:e}),this.state.selectedMatchUp&&(e.some(e=>e.matchUpId===this.state.selectedMatchUp?.matchUpId)||this.setState({selectedMatchUp:null}))}setScheduleDates(e){this.setState({scheduleDates:e})}setIssues(e){this.setState({issues:e})}handleMatchUpDrop(e,t){if(this.state.schedulingMode===`immediate`)this.config.onMatchUpDrop?.(e,t);else{let n={kind:`schedule`,matchUpId:e.matchUp.matchUpId,matchUp:e.matchUp,event:t};this.setState({pendingActions:[...this.state.pendingActions,n],hasUnsavedChanges:!0})}}handleMatchUpRemove(e){if(this.state.schedulingMode===`immediate`)this.config.onMatchUpRemove?.(e);else{let t=this.state.pendingActions.findIndex(t=>t.kind===`schedule`&&t.matchUpId===e);if(t>=0){let e=[...this.state.pendingActions];e.splice(t,1),this.setState({pendingActions:e,hasUnsavedChanges:e.length>0})}else{let t={kind:`unschedule`,matchUpId:e};this.setState({pendingActions:[...this.state.pendingActions,t],hasUnsavedChanges:!0})}}}save(){let e=this.state.pendingActions;return e.length?(this.config.onBulkSave?.(e),this.setState({pendingActions:[],hasUnsavedChanges:!1}),e):[]}discardPending(){this.setState({pendingActions:[],hasUnsavedChanges:!1})}getPendingActions(){return this.state.pendingActions}selectDate(e){this.state.selectedDate!==e&&(this.setState({selectedDate:e}),this.config.onDateSelected?.(e))}selectMatchUp(e){this.setState({selectedMatchUp:e}),this.config.onMatchUpSelected?.(e)}setCatalogSearch(e){this.setState({catalogSearchQuery:e})}setCatalogGroupBy(e){this.setState({catalogGroupBy:e})}setCatalogFilters(e){this.setState({catalogFilters:e})}setShowCompleted(e){this.setState({showCompleted:e})}setShowScheduled(e){this.setState({showScheduled:e})}toggleLeftPanel(){this.setState({leftCollapsed:!this.state.leftCollapsed})}setActiveStripVisible(e){this.state.activeStripVisible!==e&&this.setState({activeStripVisible:e})}toggleActiveStrip(){this.setState({activeStripVisible:!this.state.activeStripVisible})}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setState(e){this.state={...this.state,...e},this.emit()}emit(){for(let e of this.listeners)e(this.state)}},rK=class{constructor(e){this.container=null,this.store=new nK(e);let t=eK({onDateSelected:e=>this.store.selectDate(e)}),n=$G(),r=tK(e.courtGridElement,{onMatchUpDrop:(e,t)=>{this.store.handleMatchUpDrop(e,t)}},{gridMaxHeight:e.gridMaxHeight,headerActions:e.headerActions,titleLeadingActions:e.titleLeadingActions,titleSlot:e.titleSlot}),i=XG({onSearchChange:e=>this.store.setCatalogSearch(e),onGroupByChange:e=>this.store.setCatalogGroupBy(e),onFilterChange:e=>this.store.setCatalogFilters(e),onShowCompletedChange:e=>this.store.setShowCompleted(e),onShowScheduledChange:e=>this.store.setShowScheduled(e),onMatchUpSelected:e=>this.store.selectMatchUp(e),onDropRemove:e=>{this.store.handleMatchUpRemove(e)}}),a=NG();this.layout=kG({dateStrip:t,issuesPanel:n,courtGridSlot:r,matchUpCatalog:i,inspectorPanel:a},{onToggleLeft:()=>this.store.toggleLeftPanel()},{hideLeft:e.hideLeft,catalogSide:e.catalogSide}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.layout.element)}destroy(){this.unsubscribe(),this.container&&this.layout.element.parentNode===this.container&&this.layout.element.remove(),this.container=null}setMatchUpCatalog(e){this.store.setMatchUpCatalog(e)}setScheduleDates(e){this.store.setScheduleDates(e)}setIssues(e){this.store.setIssues(e)}setActiveStripVisible(e){this.store.setActiveStripVisible(e)}toggleActiveStrip(){this.store.toggleActiveStrip()}get activeStripVisible(){return this.store.getState().activeStripVisible}save(){return this.store.save()}discardPending(){this.store.discardPending()}get hasUnsavedChanges(){return this.store.getState().hasUnsavedChanges}getStore(){return this.store}},iK=new Set([`IN_PROGRESS`]),aK=new Set([`SUSPENDED`]),oK=new Set([`CANCELLED`,`ABANDONED`,`COMPLETED`,`DEAD_RUBBER`,`DEFAULTED`,`DOUBLE_WALKOVER`,`DOUBLE_DEFAULT`,`RETIRED`,`WALKOVER`]),sK=`in-progress`,cK=`suspended`,lK=`pending`,uK=`completed`;function dK(e,t,n,r){let i=e.matchUpStatus;return i&&n.has(i)?cK:i&&t.has(i)||e.hasScore&&e.winningSide===void 0&&(!i||!r.has(i))?sK:i&&r.has(i)||e.winningSide!==void 0?uK:lK}function fK(e,t){let n=t?.inProgressStatuses??iK,r=t?.suspendedStatuses??aK,i=t?.completedStatuses??oK,a=e.cells,o=-1;for(let t=0;t<a.length;t++){let s=a[t];if(!s)continue;let c=dK(s,n,r,i);if(c===sK||c===cK)return{courtId:e.courtId,state:c,matchUp:s,rowIndex:t};c===lK&&s.calledAt&&o===-1&&(o=t)}return o===-1?{courtId:e.courtId,state:`free`}:{courtId:e.courtId,state:`next`,matchUp:a[o],rowIndex:o}}function pK(e,t){return e.columns.map(e=>fK(e,t))}function mK(e,t){if(t.size===0)return!1;for(let n of e.participantIds)if(t.has(n))return!0;return!1}function hK(e,t){return t.roundNumber!==void 0&&t.drawId!==void 0&&e.drawId===t.drawId&&e.roundNumber!==void 0&&e.roundNumber<t.roundNumber}function gK(e,t){let n=new Set(t.participantIds??[]),r=-1,i=-1;for(let a of e.columns)for(let e=0;e<a.cells.length;e++){let o=a.cells[e];!o||o.matchUpId===t.matchUpId||(e>r&&mK(o,n)&&(r=e),e>i&&hK(o,t)&&(i=e))}return{participantFloor:r,earlierRoundFloor:i}}function _K(e,t,n){let r=t;for(;r<e.cells.length;){let t=e.cells[r];if(!t||t.matchUpId===n)return r;r++}return r}function vK(e,t,n,r){let i=e.columns.find(e=>e.courtId===t);if(!i)throw Error(`computeActiveStripDropTarget: court "${t}" not present in grid`);let{participantFloor:a,earlierRoundFloor:o}=gK(e,n),s=fK(i,r),c=s.state!==`free`&&s.rowIndex!==void 0?s.rowIndex:-1;return{courtId:t,rowIndex:_K(i,Math.max(0,a+1,o+1,c),n.matchUpId)}}function yK(e,t){if(t.roundNumber===void 0||t.drawId===void 0)return 1/0;for(let n=0;n<e.cells.length;n++){let r=e.cells[n];if(!(!r||r.matchUpId===t.matchUpId)&&r.drawId===t.drawId&&r.roundNumber!==void 0&&r.roundNumber>t.roundNumber)return n}return 1/0}function bK(e,t){let n=e.columns.map(e=>({courtId:e.courtId,cells:e.cells.slice()})),r={columns:n},i=new Map(n.map(e=>[e.courtId,e]));return t.toSorted((e,t)=>(e.roundNumber??0)-(t.roundNumber??0)||e.matchUpId.localeCompare(t.matchUpId)).map(e=>{let t=e.courtId?i.get(e.courtId):void 0;if(!t)return{matchUpId:e.matchUpId,placed:!1};let n={matchUpId:e.matchUpId,drawId:e.drawId,roundNumber:e.roundNumber,participantIds:e.participantIds},{participantFloor:a,earlierRoundFloor:o}=gK(r,n),s=Math.max(0,a+1,o+1),c=yK(t,e),l=-1;for(let n=s;n<=t.cells.length&&n<c;n++){let r=t.cells[n];if(!r||r.matchUpId===e.matchUpId){l=n;break}}return l===-1?{matchUpId:e.matchUpId,placed:!1}:(t.cells[l]={matchUpId:e.matchUpId,drawId:e.drawId,roundNumber:e.roundNumber,participantIds:e.participantIds},{matchUpId:e.matchUpId,courtId:e.courtId,rowIndex:l,placed:!0})})}var xK=`drop-over`;function SK(e,t,n,r,i){e.addEventListener(`dragover`,t=>{t.preventDefault(),e.classList.add(xK),t.dataTransfer&&(t.dataTransfer.dropEffect=`move`)}),e.addEventListener(`dragleave`,()=>{e.classList.remove(xK)}),e.addEventListener(`drop`,a=>{if(e.classList.remove(xK),a.preventDefault(),!n.onMatchUpDrop)return;let o;try{o=JSON.parse(a.dataTransfer?.getData(`application/json`)??``)}catch{return}if(o.type!==`CATALOG_MATCHUP`&&o.type!==`GRID_MATCHUP`)return;let s={matchUpId:o.matchUp.matchUpId,drawId:o.matchUp.drawId,roundNumber:o.matchUp.roundNumber,participantIds:(o.matchUp.sides??[]).map(e=>e.participantId).filter(e=>!!e)},c=vK(r(),t.courtId,s,i);n.onMatchUpDrop(o,c,a)})}function CK(e){return e===`in-progress`?`LIVE`:e===`suspended`?`SUSP`:e===`next`?`NEXT`:null}function wK(e,t,n,r,i){let a=document.createElement(`div`);if(a.className=`spl-active-strip-cell state-${e.state}`,i&&(a.classList.add(`has-availability-block`),e.state!==`free`&&e.matchUp&&a.classList.add(`has-block-conflict`)),a.dataset.courtId=e.courtId,e.rowIndex!==void 0&&(a.dataset.rowIndex=String(e.rowIndex)),r.cellHeight&&(a.style.minHeight=r.cellHeight),i){let e=document.createElement(`div`);e.className=`spl-active-strip-block-banner block-${i.type.toLowerCase()}`;let t=document.createElement(`span`);if(t.className=`spl-active-strip-block-label`,t.textContent=i.label,e.appendChild(t),i.detail){let t=document.createElement(`span`);t.className=`spl-active-strip-block-detail`,t.textContent=i.detail,e.appendChild(t)}a.appendChild(e)}if(e.state!==`free`&&e.matchUp){let t=r.renderCell?.(e.matchUp);if(t)a.appendChild(t);else{let t=document.createElement(`div`);t.className=`spl-active-strip-body`,t.textContent=e.matchUp.participantIds.join(` – `)||e.matchUp.matchUpId,a.appendChild(t)}}let o=CK(e.state);if(o){let t=document.createElement(`span`);t.className=`spl-active-strip-state-pill`,t.textContent=o,e.state===`suspended`&&(t.title=`Suspended`),a.appendChild(t)}return SK(a,e,t,n,r.statusOptions),a}function TK(e){let t=document.createElement(`div`);if(t.className=`spl-active-strip-spacer`,e.cellHeight&&(t.style.minHeight=e.cellHeight),e.spacerLabel){let n=document.createElement(`span`);n.className=`spl-active-strip-spacer-label`,n.textContent=e.spacerLabel,t.appendChild(n)}return t}function EK(e={},t={}){let n=document.createElement(`div`);n.className=`spl-active-strip`;let r={grid:{columns:[]},courts:[]};function i(){return r.grid}function a(){n.innerHTML=``,r.gridTemplateColumns?(n.style.display=`grid`,n.style.gridTemplateColumns=r.gridTemplateColumns):(n.style.display=``,n.style.gridTemplateColumns=``),n.style.minWidth=r.minWidth??``,n.appendChild(TK(t));let a=pK(r.grid,t.statusOptions);for(let o of a){let a=r.courtBlocks?.[o.courtId];n.appendChild(wK(o,e,i,t,a))}}function o(e){r=e,a()}function s(e){n.hidden=!e.activeStripVisible}return{element:n,setData:o,update:s}}var DK=`spl-cell--conflict-highlight`,OK=`spl-cell--complete`,kK={header:[`time`],body:[`eventRound`,`participants`],footer:[`score`],participantDisplay:{nameFormat:`full`,showSeed:!1,showRanking:!1,showNationality:!1,boldWinner:!0,showPotentials:!0}};function AK(e,t){let n=t??kK;return e.isBlocked?MK(e):e.isReserved?jK(e):e.matchUpId?PK(e,n):NK()}function jK(e){let t=document.createElement(`div`);t.className=`spl-grid-cell spl-cell--reserved`,t.dataset.reserved=`true`;let n=document.createElement(`div`);n.className=`spl-grid-cell__reserved-label`;let r=document.createElement(`div`);r.className=`spl-grid-cell__reserved-type`,r.textContent=`Reserved`,n.appendChild(r);let i=e.reservation?.tournamentName;if(i){let e=document.createElement(`div`);e.className=`spl-grid-cell__reserved-name`,e.textContent=i,n.appendChild(e)}let a=e.reservation?.scheduledTime??e.schedule?.scheduledTime;if(a){let e=document.createElement(`div`);e.className=`spl-grid-cell__reserved-time`,e.textContent=a,n.appendChild(e)}return t.appendChild(n),t}function MK(e){let t=document.createElement(`div`);t.className=`spl-grid-cell spl-cell--blocked`;let n=e.booking?.bookingType||`BLOCKED`;t.dataset.bookingType=n;let r=document.createElement(`div`);r.className=`spl-grid-cell__block-label`;let i=document.createElement(`div`);if(i.className=`spl-grid-cell__block-type`,i.textContent=n,r.appendChild(i),e.booking?.rowCount){let t=document.createElement(`div`);t.className=`spl-grid-cell__block-rows`,t.textContent=`${e.booking.rowCount} rows`,r.appendChild(t)}if(e.booking?.notes){let t=document.createElement(`div`);t.className=`spl-grid-cell__block-notes`,t.textContent=e.booking.notes,r.appendChild(t)}let a=e.booking?.registrations??[];if(a.length){let e=document.createElement(`ul`);e.className=`spl-grid-cell__block-registrations`;for(let t of a){let n=document.createElement(`li`);n.className=`spl-grid-cell__block-registration`,n.textContent=t,e.appendChild(n)}r.appendChild(e)}return t.appendChild(r),t}function NK(){let e=document.createElement(`div`);return e.className=`spl-grid-cell spl-cell--empty`,e}function PK(e,t){let n=document.createElement(`div`);if(n.className=`spl-grid-cell`,n.dataset.matchupId=e.matchUpId,e.drawId&&(n.dataset.drawId=e.drawId),e.gender&&(n.dataset.gender=e.gender),FK(n,e),t.header.length){let r=document.createElement(`div`);r.className=`spl-grid-cell__header`,IK(r,t.header,e,t),n.appendChild(r)}if(t.body.length){let r=document.createElement(`div`);r.className=`spl-grid-cell__body`,IK(r,t.body,e,t),n.appendChild(r)}if(t.footer.length){let r=document.createElement(`div`);r.className=`spl-grid-cell__footer`,IK(r,t.footer,e,t),n.appendChild(r)}return e.issueIds?.length&&(n.addEventListener(`mouseenter`,()=>{n.classList.add(DK);for(let t of e.issueIds)document.querySelectorAll(`[data-matchup-id="${t}"]`).forEach(e=>e.classList.add(DK))}),n.addEventListener(`mouseleave`,()=>{n.classList.remove(DK);for(let t of e.issueIds)document.querySelectorAll(`[data-matchup-id="${t}"]`).forEach(e=>e.classList.remove(DK))})),n}function FK(e,t){let n=t.matchUpStatus?.toUpperCase();n===`COMPLETED`||n===`RETIRED`||n===`DEFAULTED`||n===`WALKOVER`?e.classList.add(OK):n===`IN_PROGRESS`?e.classList.add(`spl-cell--inprogress`):n===`ABANDONED`?e.classList.add(`spl-cell--abandoned`):n===`CANCELLED`?e.classList.add(`spl-cell--cancelled`):n===`DOUBLE_WALKOVER`&&e.classList.add(`spl-cell--double-walkover`);let r=t.scheduleState?.toUpperCase();r===`SCHEDULE_ERROR`||r===`ERROR`?e.classList.add(`spl-cell--error`):r===`SCHEDULE_CONFLICT`||r===`CONFLICT`?e.classList.add(`spl-cell--conflict`):r===`SCHEDULE_WARNING`||r===`WARNING`?e.classList.add(`spl-cell--warning`):(r===`SCHEDULE_ISSUE`||r===`ISSUE`)&&e.classList.add(`spl-cell--issue`),(t.issueType===`DOUBLE_BOOKING`||t.issueType===`courtDoubleBooking`)&&e.classList.add(`spl-cell--double-booking`)}function IK(e,t,n,r){for(let i of t){let t=LK(i,n,r);t&&e.appendChild(t)}}function LK(e,t,n){switch(e){case`time`:return RK(t);case`eventRound`:return zK(t);case`participants`:return BK(t,n.participantDisplay);case`score`:return GK(t);case`matchUpStatus`:return KK(t);case`matchUpFormat`:return qK(t);case`umpire`:return JK(t);default:return null}}function RK(e){let t=e.schedule?.scheduledTime||e.schedule?.startTime,n=e.schedule?.timeModifiers,r=e.schedule?.courtAnnotation;if(!t&&!n?.length&&!r)return null;let i=document.createElement(`div`);i.className=`spl-grid-cell__time`;let a=[];if(n?.length&&a.push(n.join(` `)),t&&a.push(t),i.textContent=a.join(` `)||``,r){let e=document.createElement(`span`);e.className=`spl-grid-cell__court-annotation`,e.textContent=` ${r}`,i.appendChild(e)}return i}function zK(e){let t=[e.eventName,e.roundName].filter(Boolean);if(!t.length)return null;let n=document.createElement(`div`);return n.className=`spl-grid-cell__event-round`,n.textContent=t.join(` `),n}function BK(e,t){let n=t??kK.participantDisplay,r=document.createElement(`div`);r.className=`spl-grid-cell__participants`;let i=e.sides||[],a=e.matchUpStatus?.toUpperCase()===`BYE`,o=i.some(e=>e.bye);if(i.length===0&&n.showPotentials!==!1&&e.potentialParticipants?.length){for(let t=0;t<e.potentialParticipants.length;t++){t>0&&r.appendChild(UK());let n=e.potentialParticipants[t].map(e=>e?.participantName||`TBD`).join(` / `),i=document.createElement(`div`);i.className=`spl-grid-cell__side spl-grid-cell__potential`,i.textContent=n||`TBD`,r.appendChild(i)}return r}if(i.length===0)return null;for(let t=0;t<i.length;t++){let a=i[t];a.bye?r.appendChild(HK()):(t>0&&!i[t-1]?.bye&&r.appendChild(UK()),r.appendChild(VK(a,e,n,a.sideNumber??t+1)))}return(a||o)&&i.length===1&&!i[0].bye&&r.appendChild(HK()),r}function VK(e,t,n,r){let i=document.createElement(`div`);i.className=`spl-grid-cell__side`;let a=document.createElement(`span`);a.className=`spl-grid-cell__name`;let o=WK(e.participantName,n.nameFormat)||`TBD`;if(n.showSeed&&e.seedNumber&&(o+=` [${e.seedNumber}]`),n.showRanking&&e.ranking&&(o+=` (#${e.ranking})`),n.showNationality&&e.nationality&&(o+=` ${e.nationality}`),a.textContent=o,n.boldWinner!==!1&&t.winningSide===r&&(a.style.fontWeight=`bold`),i.appendChild(a),e.teamName){let t=document.createElement(`div`);t.className=`spl-grid-cell__team-name`,t.textContent=e.teamName,i.appendChild(t)}return i}function HK(){let e=document.createElement(`div`);return e.className=`spl-grid-cell__bye`,e.textContent=`BYE`,e}function UK(){let e=document.createElement(`div`);return e.className=`spl-grid-cell__vs`,e.textContent=`vs.`,e}function WK(e,t){if(!e)return``;switch(t){case`last`:return e.includes(`,`)?e.split(`,`)[0].trim():e.trim().split(/\s+/).at(-1);case`lastFirst`:{if(e.includes(`,`))return e.trim();let t=e.trim().split(/\s+/);return t.length<2?e:`${t.at(-1)}, ${t.slice(0,-1).join(` `)}`}case`firstLast`:{if(!e.includes(`,`))return e.trim();let[t,...n]=e.split(`,`);return`${n.join(`,`).trim()} ${t.trim()}`}default:return e}}function GK(e){let t=e.score?.scoreStringSide1,n=e.matchUpStatus?.toUpperCase(),r=n===`WALKOVER`?`WALKOVER`:n===`DEFAULTED`?`DEFAULT`:n===`RETIRED`?`RET.`:n===`DOUBLE_WALKOVER`?`D.W/O`:n===`ABANDONED`?`ABN.`:null;if(!t&&!r)return null;let i=document.createElement(`div`);return i.className=`spl-grid-cell__score`,i.textContent=t||r||``,i}function KK(e){if(!e.matchUpStatus)return null;let t=document.createElement(`div`);t.className=`spl-grid-cell__status-badge`;let n=e.matchUpStatus.toUpperCase();return n===`IN_PROGRESS`?(t.textContent=`LIVE`,t.classList.add(`spl-grid-cell__status-badge--live`)):n===`COMPLETED`||n===`RETIRED`||n===`DEFAULTED`||n===`WALKOVER`?(t.textContent=`DONE`,t.classList.add(`spl-grid-cell__status-badge--done`)):t.textContent=e.matchUpStatus.replaceAll(`_`,` `),t}function qK(e){if(!e.matchUpFormat)return null;let t=document.createElement(`div`);return t.className=`spl-grid-cell__format`,t.textContent=e.matchUpFormat,t}function JK(e){if(!e.umpire)return null;let t=document.createElement(`div`);return t.className=`spl-grid-cell__umpire`,t.textContent=e.umpire,t}function YK(e){if(!e)return{matchUpId:``};if(e.isBlocked)return{matchUpId:``,isBlocked:!0,booking:e.booking};let t=(e.sides||[]).map((e,t)=>({sideNumber:e.sideNumber??t+1,participantName:e.participant?.participantName??e.participantName,participantId:e.participantId??e.participant?.participantId,seedNumber:e.seedValue??e.seedNumber,ranking:e.ranking,nationality:e.participant?.nationalityCode??e.participant?.person?.nationalityCode??e.nationalityCode,teamName:e.teamParticipant?.participantName??e.teamName,bye:e.bye||void 0}));return{matchUpId:e.matchUpId,drawId:e.drawId,eventName:e.eventName,roundName:e.roundName,matchUpFormat:e.matchUpFormat,matchUpType:e.matchUpType,matchUpStatus:e.matchUpStatus,winningSide:e.winningSide,gender:e.gender??e.eventGender,sides:t,potentialParticipants:e.potentialParticipants,schedule:e.schedule?{scheduledTime:e.schedule.scheduledTime,startTime:e.schedule.startTime,timeModifiers:e.schedule.timeModifiers,courtAnnotation:e.schedule.courtAnnotation,courtId:e.schedule.courtId,courtOrder:e.schedule.courtOrder,venueId:e.schedule.venueId}:void 0,score:e.score?{scoreStringSide1:e.score.scoreStringSide1,scoreStringSide2:e.score.scoreStringSide2}:void 0,umpire:e.umpire?.participantName??e.umpireName,scheduleState:e.scheduleState,issueType:e.issueType,issueIds:e.issueIds}}function XK({cell:e,listProvider:t,onSelect:n,onCancel:r}){let i=e.innerHTML,a=[],o=!1,s=!1;e.classList.add(`spl-cell--typeahead`),e.innerHTML=``;let c=document.createElement(`div`);c.className=`spl-cell--typeahead-wrapper`,e.appendChild(c);let l=document.createElement(`input`);l.type=`text`,l.placeholder=`Search matchUps...`,l.setAttribute(`inputmode`,`search`),l.setAttribute(`autocapitalize`,`off`),l.setAttribute(`enterkeyhint`,`search`),l.setAttribute(`autocomplete`,`off`),c.appendChild(l);let u=e,d=0;for(;u&&d<10;){let e=window.getComputedStyle(u);(e.overflow!==`visible`||e.overflowX!==`visible`||e.overflowY!==`visible`)&&(a.push({el:u,overflow:u.style.overflow,overflowX:u.style.overflowX,overflowY:u.style.overflowY}),u.style.setProperty(`overflow`,`visible`,`important`),u.style.setProperty(`overflow-x`,`visible`,`important`),u.style.setProperty(`overflow-y`,`visible`,`important`)),u=u.parentElement,d++}ce({list:t(),element:l,listProvider:t,callback:e=>{e&&!s&&(o=!0,p(),n(e))}}),l.addEventListener(`keydown`,e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),p(),r?.())}),l.addEventListener(`blur`,()=>{setTimeout(()=>{!o&&!s&&(p(),r?.())},200)});let f=e=>{e.target!==l&&!c.contains(e.target)&&(e.preventDefault(),l.blur())};e.addEventListener(`mousedown`,f),c.addEventListener(`click`,e=>{e.stopPropagation()}),setTimeout(()=>l.focus(),0);function p(){if(!s){s=!0,e.removeEventListener(`mousedown`,f),e.classList.remove(`spl-cell--typeahead`),e.innerHTML=i;for(let{el:e,overflow:t,overflowX:n,overflowY:r}of a)t?e.style.overflow=t:e.style.removeProperty(`overflow`),n?e.style.overflowX=n:e.style.removeProperty(`overflow-x`),r?e.style.overflowY=r:e.style.removeProperty(`overflow-y`)}}return{destroy:p}}function ZK(e,t){let n=new rK(e);return n.render(t),n}var QK=class{constructor(e){this.listeners=new Set,this.config=e,this.state={compositionName:e.compositionName||`Custom`,theme:e.composition?.theme||``,configuration:{...e.composition?.configuration||{}},colors:e.composition?.colors?{...e.composition.colors}:void 0,expandedSections:new Set([`theme`,`display`]),isDirty:!1,readOnly:e.readOnly||!1}}getState(){return this.state}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.setState({expandedSections:t})}setTheme(e){this.setState({theme:e,isDirty:!0}),this.notifyChange()}setColorField(e,t){let n={...this.state.colors||{}};t===void 0||t===``?delete n[e]:n[e]=t;let r=Object.keys(n).length>0;this.setState({colors:r?n:void 0,isDirty:!0}),this.notifyChange()}clearColors(){this.setState({colors:void 0,isDirty:!0}),this.notifyChange()}setCompositionName(e){this.setState({compositionName:e,isDirty:!0})}setConfigField(e,t){let n={...this.state.configuration,[e]:t};this.setState({configuration:n,isDirty:!0}),this.notifyChange()}setConfigNestedField(e,t,n){let r={...this.state.configuration[e]||{},[t]:n};this.setConfigField(e,r)}setConfiguration(e){this.setState({configuration:{...e},isDirty:!0}),this.notifyChange()}loadComposition(e,t,n,r){this.setState({compositionName:e,theme:t,configuration:{...n},colors:r?{...r}:void 0,isDirty:!1}),this.notifyChange()}resetToInitial(){this.setState({compositionName:this.config.compositionName||`Custom`,theme:this.config.composition?.theme||``,configuration:{...this.config.composition?.configuration||{}},colors:this.config.composition?.colors?{...this.config.composition.colors}:void 0,isDirty:!1}),this.notifyChange()}setState(e){this.state={...this.state,...e},this.emit()}emit(){for(let e of this.listeners)e(this.state)}notifyChange(){this.config.onChange?.({theme:this.state.theme,configuration:this.state.configuration,...this.state.colors?{colors:{...this.state.colors}}:{}})}},$K=()=>`ce-layout`,eq=()=>`ce-left`,tq=()=>`ce-right`,nq=()=>`ce-name-row`,rq=()=>`ce-name-label`,iq=()=>`ce-name-input`,aq=()=>`ce-section`,oq=()=>`ce-section-header`,sq=()=>`ce-section-chevron`,cq=()=>`ce-section-body`,lq=()=>`ce-field`,uq=()=>`ce-field-label`,dq=()=>`ce-field-control`,fq=()=>`ce-select`,pq=()=>`ce-text-input`,mq=()=>`ce-color-input`,hq=()=>`ce-toggle`,gq=()=>`ce-toggle-track`,_q=()=>`ce-preview`,vq=()=>`ce-preview-header`,yq=()=>`ce-preview-body`,bq=()=>`ce-preview-matchup`,xq=()=>`ce-subgroup`,Sq=()=>`ce-subgroup-title`;function Cq(e,t){let n=document.createElement(`div`);n.className=aq();let r=document.createElement(`div`);r.className=oq();let i=document.createElement(`span`);i.className=sq();let a=document.createElement(`span`);a.textContent=e.label,r.appendChild(i),r.appendChild(a),r.addEventListener(`click`,()=>t.toggleSection(e.id));let o=document.createElement(`div`);o.className=cq();let s=e.factory(t);o.appendChild(s.element),n.appendChild(r),n.appendChild(o);function c(t){let n=t.expandedSections.has(e.id);i.textContent=n?`▼`:`▶`,o.style.display=n?`block`:`none`,n&&s.update(t)}return{element:n,update:c}}function wq(e,t,n,r=!1){let i=document.createElement(`div`);i.className=lq();let a=document.createElement(`span`);a.className=uq(),a.textContent=e,i.appendChild(a);let o=document.createElement(`label`);o.className=hq();let s=document.createElement(`input`);s.type=`checkbox`,s.checked=t,s.disabled=r,s.addEventListener(`change`,()=>n(s.checked));let c=document.createElement(`span`);c.className=gq(),o.appendChild(s),o.appendChild(c);let l=document.createElement(`div`);return l.className=dq(),l.appendChild(o),i.appendChild(l),{element:i,setChecked:e=>{s.checked=e},setDisabled:e=>{s.disabled=e}}}function Tq(e,t,n,r,i=!1){let a=document.createElement(`div`);a.className=lq();let o=document.createElement(`span`);o.className=uq(),o.textContent=e,a.appendChild(o);let s=document.createElement(`select`);s.className=fq(),s.disabled=i;for(let e of t){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,e.value===n&&(t.selected=!0),s.appendChild(t)}s.addEventListener(`change`,()=>r(s.value));let c=document.createElement(`div`);return c.className=dq(),c.appendChild(s),a.appendChild(c),{element:a,setValue:e=>{s.value=e}}}function Eq(e,t,n,r=``,i=!1){let a=document.createElement(`div`);a.className=lq();let o=document.createElement(`span`);o.className=uq(),o.textContent=e,a.appendChild(o);let s=document.createElement(`input`);s.type=`text`,s.className=pq(),s.value=t,s.placeholder=r,s.disabled=i,s.addEventListener(`input`,()=>n(s.value));let c=document.createElement(`div`);return c.className=dq(),c.appendChild(s),a.appendChild(c),{element:a,setValue:e=>{s.value=e}}}function Dq(e,t,n,r=!1){let i=document.createElement(`div`);i.className=lq();let a=document.createElement(`span`);a.className=uq(),a.textContent=e,i.appendChild(a);let o=document.createElement(`input`);o.type=`color`,o.className=mq(),o.value=t||`#000000`,o.disabled=r,o.addEventListener(`input`,()=>n(o.value));let s=document.createElement(`div`);return s.className=dq(),s.appendChild(o),i.appendChild(s),{element:i,setValue:e=>{o.value=e||`#000000`}}}var Oq=[],kq=new Set;for(let[,e]of Object.entries(mi))if(!kq.has(e.theme)){kq.add(e.theme);let t=e.theme.replace(`chc-theme-`,``).replace(/-/g,` `).replace(/\b\w/g,e=>e.toUpperCase());Oq.push({value:e.theme,label:t})}function Aq(e){let t=document.createElement(`div`),n=Tq(`Load preset`,[{value:``,label:`— Load preset —`},...Object.keys(mi).map(e=>({value:e,label:e}))],``,t=>{if(!t)return;let r=mi[t];r&&e.loadComposition(t,r.theme,r.configuration||{},r.colors),n.setValue(``)},e.getState().readOnly);t.appendChild(n.element);let r=document.createElement(`div`);r.style.cssText=`font-size:0.7rem; color:var(--chc-text-secondary, #999); padding:0 0 0.3rem; line-height:1.3;`,r.textContent=`Replaces all settings with a built-in composition.`,t.appendChild(r);let i=Tq(`Color theme`,Oq,e.getState().theme,t=>e.setTheme(t),e.getState().readOnly);t.appendChild(i.element);let a=document.createElement(`div`);a.style.cssText=`font-size:0.7rem; color:var(--chc-text-secondary, #999); padding:0 0 0.3rem; line-height:1.3;`,a.textContent=`Changes only the color scheme, not the display settings.`,t.appendChild(a);function o(e){i.setValue(e.theme)}return{element:t,update:o}}var jq=[{key:`border`,label:`MatchUp border`},{key:`borderHover`,label:`MatchUp border (hover)`},{key:`borderInlineStart`,label:`Left-edge accent`},{key:`connector`,label:`Connector lines`,hint:`Use "transparent" to hide`},{key:`matchUpBackground`,label:`MatchUp background`},{key:`internalDividers`,label:`Participant dividers`},{key:`score`,label:`[Score] placeholder text`},{key:`roundHeader`,label:`Round header text`},{key:`roundHeaderBackground`,label:`Round header background`,hint:`Leave blank for transparent`},{key:`roundHeaderUnderline`,label:`Round header underline`,hint:`Divider below header`},{key:`matchUpFooterText`,label:`MatchUp footer text`},{key:`matchUpFooterBackground`,label:`MatchUp footer background`},{key:`matchUpFooterDivider`,label:`MatchUp footer divider`,hint:`Border above footer`}],Mq=/^#[0-9a-f]{6}$/i;function Nq(e,t,n,r){let i=document.createElement(`div`);i.className=lq();let a=document.createElement(`span`);a.className=uq(),a.textContent=e.label,i.appendChild(a);let o=document.createElement(`div`);o.className=dq(),o.style.display=`flex`,o.style.gap=`0.4rem`,o.style.alignItems=`center`;let s=document.createElement(`input`);s.type=`color`,s.className=mq(),s.disabled=r;let c=document.createElement(`input`);c.type=`text`,c.className=pq(),c.placeholder=e.hint||`#rrggbb or color name`,c.disabled=r,c.style.flex=`1`;function l(e){c.value=e||``,e&&Mq.test(e)?(s.value=e,s.style.opacity=`1`):(s.value=`#000000`,s.style.opacity=e?`0.4`:`1`)}return l(t),s.addEventListener(`input`,()=>{c.value=s.value,s.style.opacity=`1`,n(s.value)}),c.addEventListener(`input`,()=>{let e=c.value.trim();e&&Mq.test(e)?(s.value=e,s.style.opacity=`1`):s.style.opacity=e?`0.4`:`1`,n(e||void 0)}),o.appendChild(s),o.appendChild(c),i.appendChild(o),{element:i,setValue:l}}function Pq(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=document.createElement(`div`);r.style.cssText=`font-size:0.7rem; color:var(--chc-text-secondary, #999); padding:0 0 0.4rem; line-height:1.3;`,r.textContent=`Per-composition overrides. Leave blank to inherit from the selected theme.`,t.appendChild(r);let i=jq.map(r=>{let i=Nq(r,e.getState().colors?.[r.key],t=>e.setColorField(r.key,t),n);return t.appendChild(i.element),{def:r,ctrl:i}}),a=document.createElement(`div`);a.className=lq();let o=document.createElement(`span`);o.className=uq(),o.textContent=`Left-edge width`,a.appendChild(o);let s=document.createElement(`div`);s.className=dq();let c=document.createElement(`input`);c.type=`text`,c.className=pq(),c.placeholder=`e.g. 10px`,c.disabled=n,c.value=e.getState().colors?.borderInlineStartWidth||``,c.addEventListener(`input`,()=>{let t=c.value.trim();e.setColorField(`borderInlineStartWidth`,t||void 0)}),s.appendChild(c),a.appendChild(s),t.appendChild(a);let l=document.createElement(`button`);l.type=`button`,l.textContent=`Clear color overrides`,l.disabled=n,l.style.cssText=`margin-top:0.6rem; padding:0.25rem 0.5rem; font-size:0.75rem; cursor:pointer; background:transparent; border:1px solid var(--chc-border-secondary, #ccc); border-radius:4px;`,l.addEventListener(`click`,()=>e.clearColors()),t.appendChild(l);function u(e){for(let{def:t,ctrl:n}of i)n.setValue(e.colors?.[t.key]);c.value=e.colors?.borderInlineStartWidth||``}return{element:t,update:u}}function Fq(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=wq(`Nationality flags`,!!r.flags,t=>e.setConfigField(`flags`,t),n),a=Tq(`Seeding style`,[{value:``,label:`None`},{value:`true`,label:`Parentheses`},{value:`square`,label:`Square brackets`}],r.bracketedSeeds===`square`?`square`:r.bracketedSeeds?`true`:``,t=>{t===`square`?e.setConfigField(`bracketedSeeds`,`square`):t===`true`?e.setConfigField(`bracketedSeeds`,!0):e.setConfigField(`bracketedSeeds`,void 0)},n),o=Tq(`Seed element`,[{value:``,label:`Default`},{value:`sup`,label:`Superscript`},{value:`span`,label:`Inline`}],r.seedingElement||``,t=>e.setConfigField(`seedingElement`,t||void 0),n),s=wq(`Draw positions (1st round)`,!!r.drawPositions,t=>e.setConfigField(`drawPositions`,t),n),c=wq(`Draw positions (all rounds)`,!!r.allDrawPositions,t=>e.setConfigField(`allDrawPositions`,t),n),l=wq(`Team logo`,r.teamLogo!==!1,t=>e.setConfigField(`teamLogo`,t),n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element),t.appendChild(c.element),t.appendChild(l.element);function u(e){let t=e.configuration;i.setChecked(!!t.flags),a.setValue(t.bracketedSeeds===`square`?`square`:t.bracketedSeeds?`true`:``),o.setValue(t.seedingElement||``),s.setChecked(!!t.drawPositions),c.setChecked(!!t.allDrawPositions),l.setChecked(t.teamLogo!==!1)}return{element:t,update:u}}function Iq(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=wq(`Score box`,!!r.scoreBox,t=>e.setConfigField(`scoreBox`,t),n),a=wq(`Game score only`,!!r.gameScoreOnly,t=>e.setConfigField(`gameScoreOnly`,t),n);t.appendChild(i.element),t.appendChild(a.element);let o=document.createElement(`div`);o.className=xq();let s=document.createElement(`div`);s.className=Sq(),s.textContent=`Game Score Display`,o.appendChild(s);let c=Tq(`Position`,[{value:``,label:`Default`},{value:`leading`,label:`Leading`},{value:`trailing`,label:`Trailing`}],r.gameScore?.position||``,t=>e.setConfigNestedField(`gameScore`,`position`,t||void 0),n),l=wq(`Inverted`,!!r.gameScore?.inverted,t=>e.setConfigNestedField(`gameScore`,`inverted`,t),n);o.appendChild(c.element),o.appendChild(l.element),t.appendChild(o);function u(e){let t=e.configuration;i.setChecked(!!t.scoreBox),a.setChecked(!!t.gameScoreOnly),c.setValue(t.gameScore?.position||``),l.setChecked(!!t.gameScore?.inverted)}return{element:t,update:u}}function Lq(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=wq(`Gender color`,!!r.genderColor,t=>e.setConfigField(`genderColor`,t),n),a=wq(`Winner color`,!!r.winnerColor,t=>e.setConfigField(`winnerColor`,t),n),o=Tq(`Detail`,[{value:``,label:`Default`},{value:`TEAM`,label:`Team`},{value:`ADDRESS`,label:`Address`}],r.participantDetail||``,t=>{e.setConfigField(`participantDetail`,t||void 0),e.setConfigField(`showAddress`,t===`ADDRESS`)},n),s=Eq(`Position color`,r.drawPositionColor||``,t=>e.setConfigField(`drawPositionColor`,t||void 0),`#999`,n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element);function c(e){let t=e.configuration;i.setChecked(!!t.genderColor),a.setChecked(!!t.winnerColor),o.setValue(t.participantDetail||``),s.setValue(t.drawPositionColor||``)}return{element:t,update:c}}function Rq(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=Eq(`TBD text`,r.placeHolders?.tbd||``,t=>e.setConfigNestedField(`placeHolders`,`tbd`,t||void 0),`TBD`,n),a=Eq(`Bye text`,r.placeHolders?.bye||``,t=>e.setConfigNestedField(`placeHolders`,`bye`,t||void 0),`Bye`,n),o=Eq(`Qualifier text`,r.placeHolders?.qualifier||``,t=>e.setConfigNestedField(`placeHolders`,`qualifier`,t||void 0),`Qualifier`,n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element);function s(e){let t=e.configuration;i.setValue(t.placeHolders?.tbd||``),a.setValue(t.placeHolders?.bye||``),o.setValue(t.placeHolders?.qualifier||``)}return{element:t,update:s}}var zq=[{scaleName:`WTN`,accessor:`wtnRating`,label:`WTN`},{scaleName:`UTR`,accessor:`utrRating`,label:`UTR`},{scaleName:`NTRP`,accessor:`ntrpRating`,label:`NTRP`},{scaleName:`ELO`,accessor:`eloRating`,label:`ELO`}];function Bq(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration.scaleAttributes||{},i=Tq(`Scale type`,[{value:``,label:`None`},{value:`RATING`,label:`Rating`},{value:`RANKING`,label:`Ranking`},{value:`SEEDING`,label:`Seeding`}],r.scaleType||``,t=>e.setConfigNestedField(`scaleAttributes`,`scaleType`,t||void 0),n),a=Tq(`Scale name`,[{value:``,label:`None`},...zq.map(e=>({value:e.scaleName,label:e.label}))],r.scaleName||``,t=>{e.setConfigNestedField(`scaleAttributes`,`scaleName`,t||void 0);let n=zq.find(e=>e.scaleName===t);e.setConfigNestedField(`scaleAttributes`,`accessor`,n?.accessor||void 0)},n),o=Dq(`Color`,r.scaleColor||`#ff0000`,t=>e.setConfigNestedField(`scaleAttributes`,`scaleColor`,t),n),s=Tq(`Event type`,[{value:``,label:`Any`},{value:`SINGLES`,label:`Singles`},{value:`DOUBLES`,label:`Doubles`}],r.eventType||``,t=>e.setConfigNestedField(`scaleAttributes`,`eventType`,t||void 0),n),c=wq(`Fallback`,!!r.fallback,t=>e.setConfigNestedField(`scaleAttributes`,`fallback`,t),n),l=wq(`Right of name`,r.scalePosition===`right`,t=>e.setConfigNestedField(`scaleAttributes`,`scalePosition`,t?`right`:`left`),n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element),t.appendChild(c.element),t.appendChild(l.element);function u(e){let t=e.configuration.scaleAttributes||{},n=!!e.configuration.flags;i.setValue(t.scaleType||``),a.setValue(t.scaleName||``),o.setValue(t.scaleColor||`#ff0000`),s.setValue(t.eventType||``),c.setChecked(!!t.fallback),n?(l.setChecked(!0),l.setDisabled(!0)):(l.setChecked(t.scalePosition===`right`),l.setDisabled(!1))}return{element:t,update:u}}function Vq(e){let t=document.createElement(`div`),n=e.getState().readOnly,r=e.getState().configuration,i=wq(`Schedule info`,!!r.scheduleInfo,t=>e.setConfigField(`scheduleInfo`,t),n),a=wq(`Round header`,!!r.roundHeader,t=>e.setConfigField(`roundHeader`,t),n),o=wq(`MatchUp footer`,!!r.matchUpFooter,t=>e.setConfigField(`matchUpFooter`,t),n),s=wq(`Center info`,!!r.centerInfo,t=>e.setConfigField(`centerInfo`,t),n),c=wq(`Set number`,!!r.resultsInfo,t=>e.setConfigField(`resultsInfo`,t),n),l=wq(`Winner chevron`,!!r.winnerChevron,t=>e.setConfigField(`winnerChevron`,t),n);t.appendChild(i.element),t.appendChild(a.element),t.appendChild(o.element),t.appendChild(s.element),t.appendChild(c.element),t.appendChild(l.element);function u(e){let t=e.configuration;i.setChecked(!!t.scheduleInfo),a.setChecked(!!t.roundHeader),o.setChecked(!!t.matchUpFooter),s.setChecked(!!t.centerInfo),c.setChecked(!!t.resultsInfo),l.setChecked(!!t.winnerChevron)}return{element:t,update:u}}var{DOUBLES:Hq,SINGLES:Uq}=t.eventConstants,{AD_HOC:Wq}=t.drawDefinitionConstants,{INDIVIDUAL:Gq}=t.participantConstants;function Kq({matchUpFormat:e=`SET5-S:6/TB7`,randomWinningSide:n=!0,qualifyingProfiles:r,participantsCount:i,completionGoal:a,drawSize:o=4,eventType:s,outcomes:c,drawType:l,withRatings:u,withAllRatings:d}={}){let f=a<100?Math.floor(o*.01*a):void 0,p=`venueId`,m=[{venueName:`Challenge Courts`,venueAbbreviation:`CC`,startTime:`08:00`,endTime:`20:00`,venueId:p,courtNames:[1,2,3,4,5,6,7,8],courtIds:[`c1`,`c2`,`c3`,`c4`],courtsCount:8}],h={eventType:s===Hq?Hq:Uq,completionGoal:f,qualifyingProfiles:r,participantsCount:i,seedsCount:8,matchUpFormat:e,drawSize:o,drawType:l,outcomes:c};l===Wq&&Object.assign(h,{drawMatic:!0,roundsCount:3});let{tournamentRecord:g}=t.mocksEngine.generateTournamentRecord({drawProfiles:[h],completeAllMatchUps:!0,randomWinningSide:n,venueProfiles:m});t.tournamentEngine.setState(g),t.tournamentEngine.createTeamsFromParticipantAttributes({personAttribute:`nationalityCode`,addParticipants:!0});let _=d||(u?[{...u,accessor:u.scaleName}]:[]);if(_.length>0){let{participants:e}=t.tournamentEngine.getParticipants({participantFilters:{participantTypes:[Gq]}});for(let n of _)e.forEach(e=>{let r=+(10+Math.random()*6).toFixed(2);t.tournamentEngine.setParticipantScaleItem({participantId:e.participantId,scaleItem:{scaleValue:{[n.accessor]:r},scaleName:n.scaleName,scaleType:n.scaleType||`RATING`,eventType:n.eventType||Uq}})})}let{matchUps:v}=t.tournamentEngine.allTournamentMatchUps({participantsProfile:{withGroupings:!0}}),y=v.map(({matchUpId:e})=>e),b={startTime:`08:00`,endTime:`10:00`,scheduledTime:`07:00`,scheduledDate:`2021-01-01`,courtId:`c1`,venueId:p};t.tournamentEngine.bulkScheduleMatchUps({matchUpIds:y,schedule:b});let{matchUps:x}=t.tournamentEngine.allTournamentMatchUps({participantsProfile:{withISO2:!0,withIOC:!0,withScaleValues:!!(u||d)}});return{matchUps:x}}var qq=null;function Jq(){if(!qq){let{matchUps:e}=Kq({drawSize:8,eventType:`SINGLES`,randomWinningSide:!0,matchUpFormat:`SET3-S:6/TB7`,withAllRatings:zq.map(e=>({scaleName:e.scaleName,accessor:e.accessor}))}),t=e.filter(e=>e.roundNumber===1).slice(0,2),n=t[0]?.sides?.[0]?.participant,r=t[0]?.sides?.[1]?.participant,i={matchUpId:`preview-in-progress`,matchUpType:`SINGLES`,matchUpStatus:`IN_PROGRESS`,roundNumber:1,sides:[{sideNumber:1,drawPosition:5,seedNumber:3,seedValue:`3`,participant:n},{sideNumber:2,drawPosition:6,seedNumber:6,seedValue:`6`,participant:r}],score:{scoreStringSide1:`6-4 3-2`,scoreStringSide2:`4-6 2-3`,sets:[{setNumber:1,side1Score:6,side2Score:4,winningSide:1},{setNumber:2,side1Score:3,side2Score:2,side1PointScore:`30`,side2PointScore:`15`}]}},a={matchUpId:`preview-bye`,matchUpType:`SINGLES`,matchUpStatus:`BYE`,roundNumber:1,sides:[{sideNumber:1,drawPosition:7,seedNumber:2,seedValue:`2`,participant:n},{sideNumber:2,drawPosition:8,bye:!0}]},o={matchUpId:`preview-tbd`,matchUpType:`SINGLES`,matchUpStatus:`TO_BE_PLAYED`,roundNumber:1,sides:[{sideNumber:1,drawPosition:9,seedNumber:3,seedValue:`3`,participant:n},{sideNumber:2,drawPosition:10}]},s={matchUpId:`preview-qualifier`,matchUpType:`SINGLES`,matchUpStatus:`TO_BE_PLAYED`,roundNumber:1,sides:[{sideNumber:1,drawPosition:11,qualifier:!0},{sideNumber:2,drawPosition:12,seedNumber:4,seedValue:`4`,participant:n}]};qq=[...t,i,a,o,s]}return qq}var Yq=null;function Xq(){if(!Yq){let{matchUps:e}=Kq({drawSize:4,eventType:`SINGLES`,matchUpFormat:`SET3-S:6/TB7`,completionGoal:50,randomWinningSide:!0});Yq=e}return Yq}function Zq(){let e=document.createElement(`div`);e.className=_q();let t=document.createElement(`div`);t.className=vq(),t.textContent=`Preview`,e.appendChild(t);let n=document.createElement(`div`);n.className=yq(),e.appendChild(n);let r=``,i=``,a=``;function o(e){let t=JSON.stringify(e.configuration),o=JSON.stringify(e.colors||{});if(e.theme===r&&t===i&&o===a)return;r=e.theme,i=t,a=o,n.innerHTML=``,br(n),yr(n,e.colors);let s={theme:e.theme,configuration:{...e.configuration,matchUpFooter:!0},colors:e.colors?{...e.colors}:void 0},c=_r({roundNumber:1,roundProfile:{1:{roundName:`Round 1`}}});n.appendChild(c);let l=Jq();for(let e of l){let t=document.createElement(`div`);t.className=bq();let r=ei({matchUp:e,composition:s,isLucky:!0});t.appendChild(r),n.appendChild(t)}let u=document.createElement(`div`);u.style.cssText=`margin-top:1.5rem; padding:0 0.25rem; font-size:0.7rem; color:var(--chc-text-secondary, #999); text-transform:uppercase; letter-spacing:0.05em;`,u.textContent=`Connector preview`,n.appendChild(u);let d=ni({matchUps:Xq(),composition:s});n.appendChild(d)}return{element:e,update:o}}var Qq=[{id:`theme`,label:`Theme & Preset`,factory:Aq},{id:`colors`,label:`Colors`,factory:Pq},{id:`display`,label:`Display`,factory:Fq},{id:`score`,label:`Score`,factory:Iq},{id:`participant`,label:`Participant`,factory:Lq},{id:`placeholder`,label:`Placeholders`,factory:Rq},{id:`scale`,label:`Scale Attributes`,factory:Bq},{id:`layout`,label:`Layout & Info`,factory:Vq}];function $q(e,t){let n=new QK(t),r=document.createElement(`div`);r.className=$K();let i=document.createElement(`div`);i.className=eq();let a=document.createElement(`div`);a.className=nq();let o=document.createElement(`span`);o.className=rq(),o.textContent=`Name`;let s=document.createElement(`input`);s.type=`text`,s.className=iq(),s.value=n.getState().compositionName,s.disabled=n.getState().readOnly,s.addEventListener(`input`,()=>n.setCompositionName(s.value)),a.appendChild(o),a.appendChild(s),i.appendChild(a);let c=Qq.map(e=>{let t=Cq(e,n);return i.appendChild(t.element),t}),l=document.createElement(`div`);l.className=tq();let u=Zq();l.appendChild(u.element),r.appendChild(i),r.appendChild(l),e.appendChild(r);let d=n.subscribe(e=>{s.value=e.compositionName;for(let t of c)t.update(e);u.update(e)}),f=n.getState();for(let e of c)e.update(f);return u.update(f),{destroy:()=>{d(),e.contains(r)&&e.removeChild(r)},getComposition:()=>{let e=n.getState(),{participantProvider:t,persistInputFields:r,inlineAssignment:i,...a}=e.configuration;return{compositionName:e.compositionName,theme:e.theme,configuration:a,...e.colors?{colors:{...e.colors}}:{},version:1}}}}var eJ=[`grand-slam`,`itf`,`minimal`,`none`],tJ=[`standard`,`seedings`,`officials`,`none`],nJ=[`a4`,`letter`],rJ=[`auto`,`portrait`,`landscape`],iJ={page:{pageSize:`a4`,orientation:`auto`,margins:{top:15,right:10,bottom:15,left:10}},header:{layout:`itf`,tournamentName:``},footer:{layout:`standard`,showTimestamp:!0,showPageNumbers:!0},content:{}};function aJ(e,t){let n=vJ(iJ,t.config??{}),r=!!t.readOnly,i=Q(`div`,`pce-root`),a=Q(`div`,`pce-form`),o=Q(`div`,`pce-aside`);i.appendChild(a),i.appendChild(o);let s=null;function c(){a.innerHTML=``,a.appendChild(oJ(n,r,l)),a.appendChild(sJ(n,r,l)),a.appendChild(cJ(n,r,l)),a.appendChild(lJ(n,r,t.printType,l)),!r&&t.onSave&&a.appendChild(uJ(()=>t.onSave?.(yJ(n)))),o.innerHTML=``;let e=Q(`div`,`pce-aside-title`);e.textContent=`Print Type`,o.appendChild(e);let i=Q(`span`,`pce-print-type-pill`);i.textContent=t.printType,o.appendChild(i);let c=Q(`div`,`pce-aside-title`);c.textContent=`Resolved Config`,c.style.marginTop=`8px`,o.appendChild(c),s=Q(`div`,`pce-preview-stub`),s.textContent=JSON.stringify(n,null,2),o.appendChild(s);let u=Q(`div`,`pce-preview-note`);u.textContent=`Live PDF preview not yet wired — see admin-client integration.`,o.appendChild(u)}function l(){s&&(s.textContent=JSON.stringify(n,null,2)),t.onChange?.(yJ(n))}return c(),e.appendChild(i),{destroy:()=>{i.parentNode&&i.parentNode.removeChild(i)},getConfig:()=>yJ(n),setConfig:e=>{Object.assign(n,vJ(iJ,e)),c()}}}function oJ(e,t,n){let{section:r,body:i}=hJ(`Page`);i.appendChild(dJ(`Size`,nJ,e.page?.pageSize??`a4`,t,t=>{_J(e,`page`).pageSize=t,n()})),i.appendChild(dJ(`Orientation`,rJ,e.page?.orientation??`auto`,t,t=>{_J(e,`page`).orientation=t,n()}));let a=Q(`div`,`pce-field pce-field-full`);a.appendChild(gJ(`Margins (mm)`));let o=Q(`div`);return o.style.display=`grid`,o.style.gridTemplateColumns=`repeat(4, 1fr)`,o.style.gap=`6px`,[`top`,`right`,`bottom`,`left`].forEach(r=>{o.appendChild(pJ(r,e.page?.margins?.[r]??10,t,t=>{let i=_J(_J(e,`page`),`margins`);i[r]=t,n()}))}),a.appendChild(o),i.appendChild(a),r}function sJ(e,t,n){let{section:r,body:i}=hJ(`Header`);return i.appendChild(dJ(`Layout`,eJ,e.header?.layout??`itf`,t,t=>{_J(e,`header`).layout=t,n()})),i.appendChild(fJ(`Tournament name`,e.header?.tournamentName??``,t,t=>{_J(e,`header`).tournamentName=t,n()})),i.appendChild(fJ(`Subtitle`,e.header?.subtitle??``,t,t=>{_J(e,`header`).subtitle=t||void 0,n()})),r}function cJ(e,t,n){let{section:r,body:i}=hJ(`Footer`);return i.appendChild(dJ(`Layout`,tJ,e.footer?.layout??`standard`,t,t=>{_J(e,`footer`).layout=t,n()})),i.appendChild(mJ(`Show timestamp`,e.footer?.showTimestamp??!0,t,t=>{_J(e,`footer`).showTimestamp=t,n()})),i.appendChild(mJ(`Show page numbers`,e.footer?.showPageNumbers??!0,t,t=>{_J(e,`footer`).showPageNumbers=t,n()})),r}function lJ(e,t,n,r){let{section:i,body:a}=hJ(`Content — ${n}`);if(n===`draw`){let n=_J(_J(e,`content`),`draw`);a.appendChild(mJ(`Include seedings`,!!n.includeSeedings,t,e=>{n.includeSeedings=e,r()})),a.appendChild(mJ(`Include scores`,!!n.includeScores,t,e=>{n.includeScores=e,r()})),a.appendChild(mJ(`Show byes`,!!n.showByes,t,e=>{n.showByes=e,r()})),a.appendChild(mJ(`Show draw positions`,!!n.showDrawPositions,t,e=>{n.showDrawPositions=e,r()}))}else if(n===`schedule`){let n=_J(_J(e,`content`),`schedule`);a.appendChild(dJ(`Cell style`,[`detailed`,`compact`],n.cellStyle??`detailed`,t,e=>{n.cellStyle=e,r()})),a.appendChild(mJ(`Show match numbers`,!!n.showMatchNumbers,t,e=>{n.showMatchNumbers=e,r()})),a.appendChild(fJ(`Alert banner`,n.alertBanner??``,t,e=>{n.alertBanner=e||void 0,r()}))}else{let e=Q(`div`,`pce-field pce-field-full`),t=Q(`div`,`pce-preview-note`);t.textContent=`Content options for "${n}" not yet implemented.`,e.appendChild(t),a.appendChild(e)}return i}function uJ(e){let t=Q(`div`,`pce-actions`),n=Q(`button`,`pce-button pce-button-primary`);return n.type=`button`,n.textContent=`Save`,n.addEventListener(`click`,e),t.appendChild(n),t}function dJ(e,t,n,r,i){let a=Q(`div`,`pce-field`);a.appendChild(gJ(e));let o=Q(`select`,`pce-select`);return o.disabled=r,t.forEach(e=>{let t=document.createElement(`option`);t.value=e,t.textContent=e,e===n&&(t.selected=!0),o.appendChild(t)}),o.addEventListener(`change`,()=>i(o.value)),a.appendChild(o),a}function fJ(e,t,n,r){let i=Q(`div`,`pce-field`);i.appendChild(gJ(e));let a=Q(`input`,`pce-input`);return a.type=`text`,a.value=t,a.disabled=n,a.addEventListener(`input`,()=>r(a.value)),i.appendChild(a),i}function pJ(e,t,n,r){let i=Q(`div`,`pce-field`);i.appendChild(gJ(e));let a=Q(`input`,`pce-input`);return a.type=`number`,a.value=String(t),a.disabled=n,a.addEventListener(`input`,()=>{let e=parseFloat(a.value);Number.isNaN(e)||r(e)}),i.appendChild(a),i}function mJ(e,t,n,r){let i=Q(`div`,`pce-field pce-checkbox-row pce-field-full`),a=Q(`input`);a.type=`checkbox`,a.checked=t,a.disabled=n,a.addEventListener(`change`,()=>r(a.checked)),i.appendChild(a);let o=gJ(e);return o.style.fontSize=`13px`,o.style.color=`var(--chc-text-primary, #222)`,i.appendChild(o),i}function hJ(e){let t=Q(`div`,`pce-section`),n=Q(`div`,`pce-section-header`);n.textContent=e;let r=Q(`div`,`pce-section-body`);return t.appendChild(n),t.appendChild(r),{section:t,body:r}}function Q(e,t){let n=document.createElement(e);return t&&(n.className=t),n}function gJ(e){let t=Q(`label`,`pce-field-label`);return t.textContent=e,t}function _J(e,t){return(e[t]===void 0||e[t]===null)&&(e[t]={}),e[t]}function vJ(e,t){return{name:t.name??e.name,page:{...e.page,...t.page,margins:{...e.page?.margins,...t.page?.margins}},header:{...e.header,...t.header},footer:{...e.footer,...t.footer},content:{...e.content,...t.content}}}function yJ(e){return JSON.parse(JSON.stringify(e))}var bJ=`chc-scorecard-side-score--winner`;function xJ({matchUp:e,composition:t,eventHandlers:n,swapSides:r}){let i=document.createElement(`div`);i.className=`chc-scorecard`;let a=r?2:1,o=r?1:2,s=AJ(e,a)||``,c=AJ(e,o)||``,l=r?DJ(e.winningSide):e.winningSide,u=SJ({side1Name:s,side2Name:c,sets:r?OJ(e.score?.sets):e.score?.sets,winningSide:l,side1Id:`chc-sc-side1`,side2Id:`chc-sc-side2`});i.appendChild(u);let d=e.tieFormat?.collectionDefinitions?.slice().sort((e,t)=>(e.collectionOrder||0)-(t.collectionOrder||0))||[];for(let a of d){let o=EJ({collectionDefinition:a,collectionMatchUps:(e.tieMatchUps||[]).filter(e=>e.collectionId===a.collectionId).sort((e,t)=>(e.collectionPosition||0)-(t.collectionPosition||0)),composition:t,eventHandlers:n,swapSides:r});i.appendChild(o)}return i}function SJ({side1Name:e,side2Name:t,sets:n,winningSide:r,side1Id:i,side2Id:a}){let o=document.createElement(`div`);o.className=`chc-scorecard-header`;let s=document.createElement(`div`);s.className=`chc-scorecard-header-body`;let c=wJ(e,`end`),l=wJ(t,`start`),u=TJ(n,1,r,i),d=TJ(n,2,r,a),f=document.createElement(`div`);f.className=`chc-scorecard-score-box`;let p=document.createElement(`div`);p.className=`chc-scorecard-score-flex`;let m=document.createElement(`div`);return m.className=`chc-scorecard-vs`,m.textContent=`vs`,p.appendChild(u),p.appendChild(m),p.appendChild(d),f.appendChild(p),s.appendChild(c),s.appendChild(f),s.appendChild(l),o.appendChild(s),o}function CJ(e,t=`chc-sc-side1`,n=`chc-sc-side2`,r){let i=e?.score?.sets?.[0];if(!i)return;let a=document.getElementById(t),o=document.getElementById(n);if(!a||!o)return;a.classList.remove(bJ),o.classList.remove(bJ);let s=r?`side2Score`:`side1Score`,c=r?`side1Score`:`side2Score`;a.textContent=String(i[s]??0),o.textContent=String(i[c]??0);let l=r?DJ(e.winningSide):e.winningSide;l===1&&a.classList.add(bJ),l===2&&o.classList.add(bJ)}function wJ(e,t){let n=document.createElement(`div`);n.className=`chc-scorecard-side chc-scorecard-side--${t}`;let r=document.createElement(`div`);return r.className=`chc-scorecard-side-name`,r.textContent=e,n.appendChild(r),n}function TJ(e,t,n,r){let i=e?.[0]?.[`side${t}Score`]??0,a=document.createElement(`span`);return a.className=`chc-scorecard-side-score`,r&&(a.id=r),t===1?a.style.paddingLeft=`1rem`:a.style.paddingRight=`1rem`,t===n&&a.classList.add(bJ),a.textContent=String(i),a}function EJ({collectionDefinition:e,collectionMatchUps:t,composition:n,eventHandlers:r,swapSides:i}){let a=document.createElement(`div`);a.className=`chc-scorecard-panel`;let o=document.createElement(`div`);o.className=`chc-scorecard-panel-header`;let s=document.createElement(`div`);s.className=`chc-scorecard-panel-name`,s.textContent=e.collectionName||`Collection`;let c=document.createElement(`div`);c.className=`chc-scorecard-panel-meta`;let l=(e.matchUpType||``).toUpperCase(),u=document.createElement(`span`);u.className=`chc-scorecard-type-badge chc-scorecard-type-badge--${l===`DOUBLES`?`doubles`:`singles`}`,u.textContent=l===`DOUBLES`?`D`:`S`;let d=document.createElement(`span`);d.className=`chc-scorecard-count-badge`,d.textContent=String(t.length),c.appendChild(u),c.appendChild(d),o.appendChild(s),o.appendChild(c),a.appendChild(o);let f=document.createElement(`div`);f.className=`chc-scorecard-grid`;for(let e of t){let t=ei({matchUp:i?kJ(e):e,isLucky:!0,eventHandlers:r,composition:n});t.classList.add(`chc-scorecard-card`),f.appendChild(t)}return a.appendChild(f),a}function DJ(e){if(e===1)return 2;if(e===2)return 1}function OJ(e){if(e)return e.map(e=>({...e,side1Score:e.side2Score,side2Score:e.side1Score,side1TiebreakScore:e.side2TiebreakScore,side2TiebreakScore:e.side1TiebreakScore}))}function kJ(e){let t=e.sides?.map(e=>({...e,sideNumber:e.sideNumber===1?2:1}));return{...e,sides:t,score:e.score?{...e.score,sets:OJ(e.score.sets)}:e.score,winningSide:DJ(e.winningSide)}}function AJ(e,t){return e.sides?.find(e=>e.sideNumber===t)?.participant?.participantName}function jJ(e){let{matchUpId:t,manager:n,baseMatchUp:r,onUpdate:i,showSituation:a}=e,o=document.createElement(`div`);o.className=`chc-inline-scoring-footer`;let s=document.createElement(`div`);s.className=`chc-inline-scoring-buttons`;let c=(e,t)=>{let n=document.createElement(`button`);return n.textContent=e,n.className=`chc-inline-scoring-btn ${t}`,n},l=c(`Undo`,`chc-is-undo`),u=c(`Redo`,`chc-is-redo`),d=c(`Clear`,`chc-is-clear`),f=c(`Submit`,`chc-is-submit`),p;a&&(p=document.createElement(`span`),p.className=`chc-inline-scoring-situation`),l.onclick=e=>{e.stopPropagation();let a=n.undo(t,r);a&&(i(a),m())},u.onclick=e=>{e.stopPropagation();let a=n.redo(t,r);a&&(i(a),m())},d.onclick=e=>{e.stopPropagation();let a=n.reset(t,r);a&&(i(a),m())},f.onclick=e=>{e.stopPropagation();let i=n.get(t);if(i){let e=n.getMatchUp(t,r);n.callbacks?.onSubmit?.({matchUpId:t,matchUp:e,engine:i.engine})}},s.append(l,u,d,f),o.appendChild(s),p&&o.appendChild(p);function m(){let e=n.canUndo(t),r=n.canRedo(t),i=n.isComplete(t);if(l.disabled=!e,u.disabled=!r,d.disabled=!e&&!r,p){let e=n.getSituation(t);if(e&&!i){let t=[e.isTiebreak&&`TB`,e.isBreakPoint&&`Break`,e.isGamePoint&&`Game`,e.isSetPoint&&`Set`,e.isMatchPoint&&`Match`].filter(Boolean);p.textContent=t.length?t.join(` • `):``}else p.textContent=i?`Complete`:``}}return m(),{element:o,update:m}}var MJ=`chc-iss-score-cell`;function NJ(e){if(!e?.matchUpId)throw Error(`buildInteractiveScoringShell: matchUpId is required`);if(!e?.matchUpFormat)throw Error(`buildInteractiveScoringShell: matchUpFormat is required`);let t=e.initialMatchUp??PJ(e),n=new Set,r=new gs({onScoreChange:({matchUp:e})=>{a(e,!1)},onMatchComplete:({winningSide:n})=>{a(r.getMatchUp(e.matchUpId,t),!0,n)}});r.getOrCreate(e.matchUpId,e.matchUpFormat,t);let i=document.createElement(`div`);i.className=`chc-interactive-scoring-shell`,i.dataset.matchupId=e.matchUpId,i.dataset.tournamentId=e.tournamentId,l();function a(t,r,i){let a={matchUpId:e.matchUpId,matchUp:t,isComplete:r,winningSide:i??t.winningSide},o=new CustomEvent(`stateChanged`,{detail:a});n.forEach(e=>{try{e(o)}catch(e){console.warn(`[interactive-scoring] listener threw`,e)}})}function o(n){r.isComplete(e.matchUpId)||(r.addPoint(e.matchUpId,n,t),l())}function s(){r.canUndo(e.matchUpId)&&(r.undo(e.matchUpId,t),l(),a(r.getMatchUp(e.matchUpId,t),r.isComplete(e.matchUpId)))}async function c(){e.confirmReset&&!await e.confirmReset()||(r.reset(e.matchUpId,t),l(),a(r.getMatchUp(e.matchUpId,t),!1))}function l(){i.innerHTML=``,i.append(FJ(e),IJ(r,e,t),LJ(r,e,o),RJ(r,e,s,c))}return{element:i,getState:()=>r.getMatchUp(e.matchUpId,t),reset:()=>{r.reset(e.matchUpId,t),l(),a(r.getMatchUp(e.matchUpId,t),!1)},destroy:()=>{n.clear(),r.remove(e.matchUpId),i.innerHTML=``},addEventListener:(e,t)=>{e===`stateChanged`&&n.add(t)},removeEventListener:(e,t)=>{e===`stateChanged`&&n.delete(t)}}}function PJ(e){return{matchUpId:e.matchUpId,tournamentId:e.tournamentId,matchUpFormat:e.matchUpFormat,matchUpStatus:`TO_BE_PLAYED`,score:{sets:[]},sides:[{sideNumber:1,participant:{participantName:e.side1Name}},{sideNumber:2,participant:{participantName:e.side2Name}}]}}function FJ(e){let t=document.createElement(`div`);t.className=`chc-iss-header`;let n=document.createElement(`div`);n.className=`chc-iss-header-side chc-iss-header-side1`,n.textContent=e.side1Name||`Side 1`;let r=document.createElement(`div`);r.className=`chc-iss-header-vs`,r.textContent=`vs`;let i=document.createElement(`div`);return i.className=`chc-iss-header-side chc-iss-header-side2`,i.textContent=e.side2Name||`Side 2`,t.append(n,r,i),t}function IJ(e,t,n){let r=document.createElement(`div`);r.className=`chc-iss-score-display`;let i=e.getMatchUp(t.matchUpId,n),a=i.score?.sets??[],o=document.createElement(`div`);o.className=`chc-iss-score-grid`,o.style.setProperty(`--sets`,String(Math.max(a.length,1)));let s=document.createElement(`div`);s.className=`chc-iss-score-row chc-iss-score-row-side1`;let c=document.createElement(`div`);c.className=`chc-iss-score-row chc-iss-score-row-side2`;for(let e of a){let t=document.createElement(`div`);t.className=MJ,t.textContent=String(e.side1Score??0),e.winningSide===1&&t.classList.add(`chc-iss-score-cell-won`),s.append(t);let n=document.createElement(`div`);n.className=MJ,n.textContent=String(e.side2Score??0),e.winningSide===2&&n.classList.add(`chc-iss-score-cell-won`),c.append(n)}if(a.length===0){let e=document.createElement(`div`);e.className=MJ,e.textContent=`0`,s.append(e);let t=document.createElement(`div`);t.className=MJ,t.textContent=`0`,c.append(t)}o.append(s,c),r.append(o);let l=a.at(-1);if(l&&!l.winningSide&&l.side1PointScore!=null){let e=document.createElement(`div`);e.className=`chc-iss-game-score`;let t=document.createElement(`span`);t.className=`chc-iss-game-score-side1`,t.textContent=String(l.side1PointScore);let n=document.createElement(`span`);n.className=`chc-iss-game-score-sep`,n.textContent=` — `;let i=document.createElement(`span`);i.className=`chc-iss-game-score-side2`,i.textContent=String(l.side2PointScore),e.append(t,n,i),r.append(e)}if(e.isComplete(t.matchUpId)){let e=document.createElement(`div`);e.className=`chc-iss-match-complete`,e.textContent=`${(i.winningSide===1?t.side1Name:t.side2Name)||`Match`} wins`,r.append(e)}return r}function LJ(e,t,n){let r=document.createElement(`div`);r.className=`chc-iss-point-buttons`;let i=e.isComplete(t.matchUpId),a=document.createElement(`button`);a.type=`button`,a.className=`chc-iss-point-button chc-iss-point-button-side1`,a.disabled=i,a.setAttribute(`aria-label`,`${t.side1Name} won the point`);let o=document.createElement(`span`);o.className=`chc-iss-point-button-label`,o.textContent=t.side1Name||`Side 1`;let s=document.createElement(`span`);s.className=`chc-iss-point-button-hint`,s.textContent=`won the point`,a.append(o,s),a.addEventListener(`click`,()=>n(0));let c=document.createElement(`button`);c.type=`button`,c.className=`chc-iss-point-button chc-iss-point-button-side2`,c.disabled=i,c.setAttribute(`aria-label`,`${t.side2Name} won the point`);let l=document.createElement(`span`);l.className=`chc-iss-point-button-label`,l.textContent=t.side2Name||`Side 2`;let u=document.createElement(`span`);return u.className=`chc-iss-point-button-hint`,u.textContent=`won the point`,c.append(l,u),c.addEventListener(`click`,()=>n(1)),r.append(a,c),r}function RJ(e,t,n,r){let i=document.createElement(`div`);i.className=`chc-iss-control-bar`;let a=document.createElement(`button`);a.type=`button`,a.className=`chc-iss-control-button chc-iss-control-undo`,a.textContent=`Undo`,a.disabled=!e.canUndo(t.matchUpId),a.addEventListener(`click`,n);let o=document.createElement(`button`);return o.type=`button`,o.className=`chc-iss-control-button chc-iss-control-reset`,o.textContent=`Reset`,o.addEventListener(`click`,()=>{r()}),i.append(a,o),i}function zJ(){return{policyName:`New Ranking Policy`,policyVersion:`1.0`,awardProfiles:[{profileName:`Default`,finishingPositionRanges:{1:100,2:70,4:50,8:30,16:15,32:8}}],requireWinForPoints:!0,doublesAttribution:`fullToEach`}}function $(e){return structuredClone(e)}var BJ=class{constructor(e){this.listeners=new Set,this.config=e;let t=$(e.initialPolicy??zJ()),n=t.awardProfiles?.length??0;this.state={draft:t,expandedSections:new Set(n>5?[`awardProfiles`]:[`metadata`,`awardProfiles`,`qualityWinProfiles`,`aggregationRules`]),expandedProfiles:new Set(n<=5?Array.from({length:n},(e,t)=>t):[]),profileFilter:``,dirty:!1,readonly:e.readonly??!1}}getState(){return this.state}getData(){return $(this.state.draft)}setData(e){let t=e.awardProfiles?.length??0;this.state={...this.state,draft:$(e),expandedProfiles:new Set(t<=5?Array.from({length:t},(e,t)=>t):[]),profileFilter:``,dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}toggleProfile(e){let t=new Set(this.state.expandedProfiles);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedProfiles:t},this.emit()}setProfileFilter(e){this.state={...this.state,profileFilter:e},this.emit()}setPolicyName(e){let t=$(this.state.draft);t.policyName=e,this.commitDraft(t)}setPolicyVersion(e){let t=$(this.state.draft);t.policyVersion=e,this.commitDraft(t)}setValidDateRange(e,t){let n=$(this.state.draft);n.validDateRange||={},n.validDateRange[e]=t||void 0,this.commitDraft(n)}setGlobalFlag(e,t){let n=$(this.state.draft);n[e]=t,this.commitDraft(n)}setDoublesAttribution(e){let t=$(this.state.draft);t.doublesAttribution=e||void 0,this.commitDraft(t)}setCategoryResolution(e){let t=$(this.state.draft);t.categoryResolution=e||void 0,this.commitDraft(t)}addProfile(){let e=$(this.state.draft);e.awardProfiles||=[],e.awardProfiles.push({profileName:`Profile ${e.awardProfiles.length+1}`,finishingPositionRanges:{1:100,2:70,4:50,8:30}});let t=new Set(this.state.expandedProfiles);t.add(e.awardProfiles.length-1),this.state={...this.state,expandedProfiles:t},this.commitDraft(e)}removeProfile(e){let t=$(this.state.draft);if(!t.awardProfiles||e<0||e>=t.awardProfiles.length)return;t.awardProfiles.splice(e,1);let n=new Set;for(let t of this.state.expandedProfiles)t<e?n.add(t):t>e&&n.add(t-1);this.state={...this.state,expandedProfiles:n},this.commitDraft(t)}duplicateProfile(e){let t=$(this.state.draft);if(!t.awardProfiles||e<0||e>=t.awardProfiles.length)return;let n=$(t.awardProfiles[e]);n.profileName=`${n.profileName??`Profile`} (Copy)`,t.awardProfiles.splice(e+1,0,n);let r=new Set;for(let t of this.state.expandedProfiles)t<=e?r.add(t):r.add(t+1);r.add(e+1),this.state={...this.state,expandedProfiles:r},this.commitDraft(t)}moveProfile(e,t){let n=$(this.state.draft);if(!n.awardProfiles||e<0||e>=n.awardProfiles.length||t<0||t>=n.awardProfiles.length)return;let[r]=n.awardProfiles.splice(e,1);n.awardProfiles.splice(t,0,r),this.commitDraft(n)}setProfileName(e,t){let n=$(this.state.draft);n.awardProfiles?.[e]&&(n.awardProfiles[e].profileName=t,this.commitDraft(n))}setProfileFlag(e,t,n){let r=$(this.state.draft);r.awardProfiles?.[e]&&(n===void 0?delete r.awardProfiles[e][t]:r.awardProfiles[e][t]=n,this.commitDraft(r))}setFlatPositionPoints(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e];i&&(i.finishingPositionRanges||={},i.finishingPositionRanges[t]=n,this.commitDraft(r))}addPositionRow(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r&&(r.finishingPositionRanges||={},r.finishingPositionRanges[t]===void 0&&(r.finishingPositionRanges[t]=0,this.commitDraft(n)))}removePositionRow(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r?.finishingPositionRanges&&(delete r.finishingPositionRanges[t],this.commitDraft(n))}setPointsPerWin(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r&&(t===void 0?delete r.pointsPerWin:r.pointsPerWin=t,this.commitDraft(n))}addBonusPoint(e){let t=$(this.state.draft),n=t.awardProfiles?.[e];n&&(n.bonusPoints||=[],n.bonusPoints.push({finishingPositions:[1],value:0}),this.commitDraft(t))}removeBonusPoint(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];r?.bonusPoints&&(r.bonusPoints.splice(t,1),r.bonusPoints.length||delete r.bonusPoints,this.commitDraft(n))}setBonusPointPositions(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e]?.bonusPoints?.[t];i&&(i.finishingPositions=n,this.commitDraft(r))}setBonusPointValue(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e]?.bonusPoints?.[t];i&&(i.value=n,this.commitDraft(r))}setLevelPositionPoints(e,t,n,r){let i=$(this.state.draft),a=i.awardProfiles?.[e];if(!a)return;a.finishingPositionRanges||={};let o=a.finishingPositionRanges[t];o&&typeof o==`object`&&o.level&&(o.level[n]=r),this.commitDraft(i)}addLevel(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];if(r?.finishingPositionRanges){for(let e of Object.keys(r.finishingPositionRanges)){let n=r.finishingPositionRanges[e];n&&typeof n==`object`&&n.level&&n.level[t]===void 0&&(n.level[t]=0)}r.levels&&!r.levels.includes(t)&&(r.levels.push(t),r.levels.sort((e,t)=>e-t)),this.commitDraft(n)}}removeLevel(e,t){let n=$(this.state.draft),r=n.awardProfiles?.[e];if(r?.finishingPositionRanges){for(let e of Object.keys(r.finishingPositionRanges)){let n=r.finishingPositionRanges[e];n&&typeof n==`object`&&n.level&&delete n.level[t]}r.levels&&=r.levels.filter(e=>e!==t),this.commitDraft(n)}}setProfileScope(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e];i&&(n.length?i[t]=n:delete i[t],this.commitDraft(r))}setProfileField(e,t,n){let r=$(this.state.draft),i=r.awardProfiles?.[e];i&&(n===void 0||n===``?delete i[t]:i[t]=n,this.commitDraft(r))}addQualityWinProfile(){let e=$(this.state.draft);e.qualityWinProfiles||=[],e.qualityWinProfiles.push({rankingScaleName:`New Profile`,rankingRanges:[{rankRange:[1,10],value:10}]}),this.commitDraft(e)}removeQualityWinProfile(e){let t=$(this.state.draft);t.qualityWinProfiles&&(t.qualityWinProfiles.splice(e,1),t.qualityWinProfiles.length||delete t.qualityWinProfiles,this.commitDraft(t))}setQualityWinField(e,t,n){let r=$(this.state.draft),i=r.qualityWinProfiles?.[e];i&&(n===void 0||n===``?delete i[t]:i[t]=n,this.commitDraft(r))}addQualityWinRange(e){let t=$(this.state.draft),n=t.qualityWinProfiles?.[e];if(!n)return;let r=n.rankingRanges.at(-1),i=r?r.rankRange[1]+1:1;n.rankingRanges.push({rankRange:[i,i+9],value:0}),this.commitDraft(t)}removeQualityWinRange(e,t){let n=$(this.state.draft),r=n.qualityWinProfiles?.[e];r&&(r.rankingRanges.splice(t,1),this.commitDraft(n))}setQualityWinRange(e,t,n,r){let i=$(this.state.draft),a=i.qualityWinProfiles?.[e]?.rankingRanges?.[t];a&&(n===`rankRange`?a.rankRange=r:a.value=r,this.commitDraft(i))}setAggregationField(e,t){let n=$(this.state.draft);n.aggregationRules||={},t===void 0||t===``?delete n.aggregationRules[e]:n.aggregationRules[e]=t,this.commitDraft(n)}addTiebreakCriterion(e){let t=$(this.state.draft);t.aggregationRules||={},t.aggregationRules.tiebreakCriteria||(t.aggregationRules.tiebreakCriteria=[]),t.aggregationRules.tiebreakCriteria.push(e),this.commitDraft(t)}removeTiebreakCriterion(e){let t=$(this.state.draft);t.aggregationRules?.tiebreakCriteria&&(t.aggregationRules.tiebreakCriteria.splice(e,1),t.aggregationRules.tiebreakCriteria.length||delete t.aggregationRules.tiebreakCriteria,this.commitDraft(t))}addCountingBucket(){let e=$(this.state.draft);e.aggregationRules||={},e.aggregationRules.countingBuckets||(e.aggregationRules.countingBuckets=[]),e.aggregationRules.countingBuckets.push({bucketName:`New Bucket`}),this.commitDraft(e)}removeCountingBucket(e){let t=$(this.state.draft);t.aggregationRules?.countingBuckets&&(t.aggregationRules.countingBuckets.splice(e,1),t.aggregationRules.countingBuckets.length||delete t.aggregationRules.countingBuckets,this.commitDraft(t))}setCountingBucketField(e,t,n){let r=$(this.state.draft),i=r.aggregationRules?.countingBuckets?.[e];i&&(n===void 0||n===``?delete i[t]:i[t]=n,this.commitDraft(r))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.($(e))}emit(){for(let e of this.listeners)e(this.state)}},VJ=()=>`re-section`,HJ=()=>`re-section-header`,UJ=()=>`re-section-chevron`,WJ=()=>`re-section-count`,GJ=()=>`re-section-body`,KJ=()=>`re-field-row`,qJ=()=>`re-field-label`,JJ=()=>`re-field-input re-field-input--text`,YJ=()=>`re-field-input re-field-input--number`,XJ=()=>`re-field-input re-field-input--date`,ZJ=()=>`re-field-select`,QJ=()=>`re-checkbox-row`,$J=()=>`re-points-input`,eY=()=>`re-profile-card`,tY=()=>`re-profile-header`,nY=()=>`re-profile-name-input`,rY=()=>`re-profile-body`,iY=()=>`re-profile-actions`,aY=()=>`re-icon-btn`,oY=()=>`re-icon-btn re-icon-btn--danger`,sY=()=>`re-empty`,cY=()=>`re-editor`,lY=[`totalPoints`,`bestResult`,`headToHead`,`numberOfWins`,`recentResults`,`drawSize`,`numberOfResults`];function uY(e){let t=document.createElement(`div`),n=``;function r(t,n,r,i,a,o){let s=document.createElement(`div`);s.className=KJ();let c=document.createElement(`div`);if(c.className=qJ(),c.textContent=n,s.appendChild(c),o){let e=document.createElement(`span`);e.style.cssText=`font-size:0.85rem;color:var(--sp-text)`,e.textContent=String(i),s.appendChild(e)}else if(r===`select`){let n=document.createElement(`select`);n.className=ZJ();let r=document.createElement(`option`);r.value=``,r.textContent=`(none)`,n.appendChild(r);for(let e of a??[]){let t=document.createElement(`option`);t.value=e,t.textContent=e,n.appendChild(t)}n.value=i??``,n.addEventListener(`change`,()=>e.setAggregationField(t,n.value||void 0)),s.appendChild(n)}else{let n=document.createElement(`input`);n.type=`number`,n.className=YJ(),n.value=i===void 0?``:String(i),n.placeholder=`—`,n.addEventListener(`change`,()=>{let r=n.value.trim();e.setAggregationField(t,r?Number.parseInt(r,10):void 0)}),s.appendChild(n)}return s}function i(n,r){let i=document.createElement(`div`);if(i.style.cssText=`font-weight:600;font-size:0.8rem;margin:0.5rem 0 0.3rem;color:var(--sp-text)`,i.textContent=`Tiebreak Order`,t.appendChild(i),n.length){let i=document.createElement(`ol`);i.style.cssText=`font-size:0.8rem;margin:0;padding-left:1.5rem;color:var(--sp-text)`;for(let t=0;t<n.length;t++){let a=document.createElement(`li`);a.style.cssText=`display:flex;align-items:center;gap:6px;margin-bottom:2px`;let o=document.createElement(`span`);if(o.textContent=n[t],a.appendChild(o),!r){let n=document.createElement(`span`);n.className=oY(),n.textContent=`×`,n.style.cursor=`pointer`,n.addEventListener(`click`,()=>e.removeTiebreakCriterion(t)),a.appendChild(n)}i.appendChild(a)}t.appendChild(i)}else if(r){let e=document.createElement(`div`);e.className=sY(),e.textContent=`No tiebreak criteria`,t.appendChild(e)}if(!r){let r=document.createElement(`div`);r.style.cssText=`display:flex;align-items:center;gap:4px;margin-top:4px`;let i=document.createElement(`select`);i.className=ZJ(),i.style.fontSize=`0.75rem`;let a=new Set(n),o=lY.filter(e=>!a.has(e));for(let e of o){let t=document.createElement(`option`);t.value=e,t.textContent=e,i.appendChild(t)}let s=document.createElement(`button`);s.className=`sp-btn sp-btn--sm sp-btn--outline`,s.textContent=`+ Add`,s.addEventListener(`click`,()=>{i.value&&e.addTiebreakCriterion(i.value)}),o.length&&(r.appendChild(i),r.appendChild(s),t.appendChild(r))}}function a(t,n,r){let i=document.createElement(`div`);i.style.cssText=`border:1px solid var(--sp-border);border-radius:8px;padding:0.4rem;margin-bottom:0.4rem;font-size:0.8rem`;let a=document.createElement(`div`);if(a.style.cssText=`display:flex;align-items:center;gap:6px;margin-bottom:0.2rem`,r){let e=document.createElement(`span`);e.style.cssText=`font-weight:600;color:var(--sp-text)`,e.textContent=t.bucketName||`Bucket`,a.appendChild(e)}else{let r=document.createElement(`input`);r.type=`text`,r.className=`re-field-input re-field-input--text`,r.style.cssText=`width:120px;font-size:0.75rem;font-weight:600`,r.value=t.bucketName||``,r.placeholder=`Bucket name`,r.addEventListener(`change`,()=>e.setCountingBucketField(n,`bucketName`,r.value)),a.appendChild(r);let i=document.createElement(`div`);i.style.flexGrow=`1`,a.appendChild(i);let o=document.createElement(`span`);o.className=oY(),o.textContent=`✕`,o.style.cursor=`pointer`,o.addEventListener(`click`,()=>e.removeCountingBucket(n)),a.appendChild(o)}i.appendChild(a);let o=[];if(t.eventTypes?.length&&o.push(`Events: ${t.eventTypes.join(`, `)}`),t.bestOfCount!==void 0&&o.push(`Best of: ${t.bestOfCount}`),t.levels?.length&&o.push(`Levels: ${t.levels.join(`, `)}`),t.minResults!==void 0&&o.push(`Min: ${t.minResults}`),r&&o.length){let e=document.createElement(`div`);e.style.cssText=`color:var(--sp-muted);font-size:0.75rem`,e.textContent=o.join(` | `),i.appendChild(e)}else if(!r){let r=document.createElement(`div`);r.className=KJ();let a=document.createElement(`div`);a.className=qJ(),a.style.cssText=`min-width:70px;font-size:0.75rem`,a.textContent=`Best of`,r.appendChild(a);let o=document.createElement(`input`);o.type=`number`,o.className=YJ(),o.style.fontSize=`0.75rem`,o.value=t.bestOfCount===void 0?``:String(t.bestOfCount),o.addEventListener(`change`,()=>{let t=o.value.trim();e.setCountingBucketField(n,`bestOfCount`,t?Number.parseInt(t,10):void 0)}),r.appendChild(o),i.appendChild(r)}return i}function o(n){let o=n.draft.aggregationRules;if(t.innerHTML=``,!o&&n.readonly){let e=document.createElement(`div`);e.className=sY(),e.textContent=`No aggregation rules defined (all results summed)`,t.appendChild(e);return}let s=[[`rollingPeriodDays`,`Rolling period (days)`,`number`,o?.rollingPeriodDays],[`bestOfCount`,`Best of count`,`number`,o?.bestOfCount],[`minCountableResults`,`Min countable results`,`number`,o?.minCountableResults],[`decayFunction`,`Decay function`,`select`,o?.decayFunction,[`none`,`linear`,`exponential`,`step`]]];for(let[e,i,a,o,c]of s)o===void 0&&n.readonly||t.appendChild(r(e,i,a,o,c,n.readonly));let c=[[`separateByGender`,`Separate by gender`,o?.separateByGender],[`perCategory`,`Per category`,o?.perCategory]];for(let[r,i,a]of c){if(a===void 0&&n.readonly)continue;let o=document.createElement(`div`);o.className=QJ();let s=document.createElement(`input`);s.type=`checkbox`,s.checked=a??!1,s.disabled=n.readonly,s.addEventListener(`change`,()=>e.setAggregationField(r,s.checked));let c=document.createElement(`label`);c.textContent=i,o.appendChild(s),o.appendChild(c),t.appendChild(o)}i(o?.tiebreakCriteria??[],n.readonly);let l=o?.countingBuckets??[];if(l.length||!n.readonly){let r=document.createElement(`div`);r.style.cssText=`font-weight:600;font-size:0.8rem;margin:0.5rem 0 0.3rem;color:var(--sp-text)`,r.textContent=`Counting Buckets`,t.appendChild(r);for(let e=0;e<l.length;e++)t.appendChild(a(l[e],e,n.readonly));if(!n.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add Bucket`,n.addEventListener(`click`,()=>e.addCountingBucket()),t.appendChild(n)}}}function s(e){let t=JSON.stringify(e.draft.aggregationRules??{});t!==n&&(n=t,o(e))}return{element:t,update:s}}function dY(e){let t=document.createElement(`div`),n=``;function r(t,n,r){let i=document.createElement(`div`);if(i.style.cssText=`display:flex;align-items:center;gap:0.5rem;margin-bottom:0.4rem`,r){let e=document.createElement(`span`);e.style.cssText=`font-weight:600;font-size:0.85rem;color:var(--sp-text)`,e.textContent=n.rankingScaleName,i.appendChild(e)}else{let r=document.createElement(`input`);r.type=`text`,r.className=JJ(),r.style.cssText=`width:150px;font-weight:600`,r.value=n.rankingScaleName,r.addEventListener(`change`,()=>e.setQualityWinField(t,`rankingScaleName`,r.value)),i.appendChild(r);let a=document.createElement(`div`);a.style.flexGrow=`1`,i.appendChild(a);let o=document.createElement(`span`);o.className=oY(),o.textContent=`✕`,o.title=`Delete profile`,o.style.cursor=`pointer`,o.addEventListener(`click`,()=>e.removeQualityWinProfile(t)),i.appendChild(o)}return i}let i=`text-align:right;padding:2px 4px`,a=`text-align:right;width:4rem`;function o(t,n,r,a){let o=document.createElement(`tr`);if(a)for(let e of[r.rankRange[0],r.rankRange[1],r.value]){let t=document.createElement(`td`);t.style.cssText=`text-align:right;font-variant-numeric:tabular-nums;padding:2px 4px`,t.textContent=e.toLocaleString(),o.appendChild(t)}else{let a=document.createElement(`td`);a.style.cssText=i,a.appendChild(fY(r.rankRange[0],i=>{e.setQualityWinRange(t,n,`rankRange`,[i,r.rankRange[1]])})),o.appendChild(a);let s=document.createElement(`td`);s.style.cssText=i,s.appendChild(fY(r.rankRange[1],i=>{e.setQualityWinRange(t,n,`rankRange`,[r.rankRange[0],i])})),o.appendChild(s);let c=document.createElement(`td`);c.style.cssText=i,c.appendChild(fY(r.value,r=>{e.setQualityWinRange(t,n,`value`,r)})),o.appendChild(c);let l=document.createElement(`td`);l.style.cssText=`text-align:center;padding:2px`;let u=document.createElement(`span`);u.className=oY(),u.textContent=`×`,u.style.cursor=`pointer`,u.addEventListener(`click`,()=>e.removeQualityWinRange(t,n)),l.appendChild(u),o.appendChild(l)}return o}function s(e,t,n){let r=document.createElement(`table`);r.style.cssText=`font-size:0.8rem;margin-bottom:0.3rem;border-collapse:collapse`;let i=document.createElement(`thead`),s=document.createElement(`tr`);for(let[e,t]of[[`From`,a],[`To`,a],[`Bonus`,a]]){let n=document.createElement(`th`);n.textContent=e,n.style.cssText=t+`;padding:2px 4px`,s.appendChild(n)}if(!n){let e=document.createElement(`th`);e.style.cssText=`width:2rem;padding:2px`,s.appendChild(e)}i.appendChild(s),r.appendChild(i);let c=document.createElement(`tbody`);for(let r=0;r<t.rankingRanges.length;r++)c.appendChild(o(e,r,t.rankingRanges[r],n));return r.appendChild(c),r}function c(t,n,r,i,a){let o=document.createElement(`div`);o.className=KJ();let s=document.createElement(`div`);if(s.className=qJ(),s.style.minWidth=`100px`,s.style.fontSize=`0.75rem`,s.textContent=r,o.appendChild(s),a){let e=document.createElement(`span`);e.style.cssText=`font-size:0.75rem;color:var(--sp-muted)`,e.textContent=String(i),o.appendChild(e)}else{let r=document.createElement(`input`);r.type=typeof i==`number`?`number`:`text`,r.className=typeof i==`number`?YJ():JJ(),r.style.fontSize=`0.75rem`,r.value=i===void 0?``:String(i),r.addEventListener(`change`,()=>{let a=r.value.trim();typeof i==`number`||n===`maxBonusPerTournament`?e.setQualityWinField(t,n,a?Number.parseFloat(a):void 0):e.setQualityWinField(t,n,a||void 0)}),o.appendChild(r)}return o}function l(n){let i=n.draft.qualityWinProfiles;if(t.innerHTML=``,!i?.length){let r=document.createElement(`div`);if(r.className=sY(),r.textContent=`No quality win profiles defined`,t.appendChild(r),!n.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add Quality Win Profile`,n.addEventListener(`click`,()=>e.addQualityWinProfile()),t.appendChild(n)}return}for(let a=0;a<i.length;a++){let o=i[a],l=document.createElement(`div`);if(l.style.cssText=`border:1px solid var(--sp-border);border-radius:10px;padding:0.5rem;margin-bottom:0.5rem`,l.appendChild(r(a,o,n.readonly)),o.rankingRanges?.length&&(l.appendChild(s(a,o,n.readonly)),!n.readonly)){let t=document.createElement(`button`);t.className=`sp-btn sp-btn--sm sp-btn--outline`,t.textContent=`+ Range`,t.style.marginBottom=`0.3rem`,t.addEventListener(`click`,()=>e.addQualityWinRange(a)),l.appendChild(t)}let u=[[`maxBonusPerTournament`,`Max bonus/tournament`,o.maxBonusPerTournament],[`rankingSnapshot`,`Ranking snapshot`,o.rankingSnapshot]];for(let[e,t,r]of u)r===void 0&&n.readonly||l.appendChild(c(a,e,t,r,n.readonly));if(o.includeWalkovers!==void 0||!n.readonly){let t=document.createElement(`div`);t.className=QJ();let r=document.createElement(`input`);r.type=`checkbox`,r.checked=o.includeWalkovers??!1,r.disabled=n.readonly,r.addEventListener(`change`,()=>e.setQualityWinField(a,`includeWalkovers`,r.checked));let i=document.createElement(`label`);i.textContent=`Include walkovers`,i.style.fontSize=`0.75rem`,t.appendChild(r),t.appendChild(i),l.appendChild(t)}t.appendChild(l)}if(!n.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add Quality Win Profile`,n.addEventListener(`click`,()=>e.addQualityWinProfile()),t.appendChild(n)}}function u(e){let t=JSON.stringify(e.draft.qualityWinProfiles??[]);t!==n&&(n=t,l(e))}return{element:t,update:u}}function fY(e,t){let n=document.createElement(`input`);return n.type=`number`,n.className=$J(),n.value=String(e),n.addEventListener(`change`,()=>{let e=Number.parseFloat(n.value);Number.isNaN(e)||t(e)}),n}function pY(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=KJ();let r=document.createElement(`div`);r.className=qJ(),r.textContent=`Name`;let i=document.createElement(`input`);i.type=`text`,i.className=JJ(),i.placeholder=`Policy name`,i.addEventListener(`change`,()=>e.setPolicyName(i.value)),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=KJ();let o=document.createElement(`div`);o.className=qJ(),o.textContent=`Version`;let s=document.createElement(`input`);s.type=`text`,s.className=JJ(),s.placeholder=`1.0`,s.style.width=`80px`,s.addEventListener(`change`,()=>e.setPolicyVersion(s.value)),a.appendChild(o),a.appendChild(s),t.appendChild(a);let c=document.createElement(`div`);c.className=KJ();let l=document.createElement(`div`);l.className=qJ(),l.textContent=`Valid from`;let u=document.createElement(`input`);u.type=`date`,u.className=XJ(),u.addEventListener(`change`,()=>e.setValidDateRange(`startDate`,u.value)),c.appendChild(l),c.appendChild(u),t.appendChild(c);let d=document.createElement(`div`);d.className=KJ();let f=document.createElement(`div`);f.className=qJ(),f.textContent=`Valid until`;let p=document.createElement(`input`);p.type=`date`,p.className=XJ(),p.addEventListener(`change`,()=>e.setValidDateRange(`endDate`,p.value)),d.appendChild(f),d.appendChild(p),t.appendChild(d);let m=document.createElement(`div`);m.className=KJ();let h=document.createElement(`div`);h.className=qJ(),h.textContent=`Doubles attribution`;let g=document.createElement(`select`);g.className=ZJ();for(let[e,t]of[[``,`(none)`],[`fullToEach`,`Full to each`],[`halfToEach`,`Half to each`],[`split`,`Split`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,g.appendChild(n)}g.addEventListener(`change`,()=>e.setDoublesAttribution(g.value)),m.appendChild(h),m.appendChild(g),t.appendChild(m);let _=document.createElement(`div`);_.className=KJ();let v=document.createElement(`div`);v.className=qJ(),v.textContent=`Category resolution`;let y=document.createElement(`select`);y.className=ZJ();for(let[e,t]of[[``,`(none)`],[`matchCategory`,`Match category`],[`eventCategory`,`Event category`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,y.appendChild(n)}y.addEventListener(`change`,()=>e.setCategoryResolution(y.value)),_.appendChild(v),_.appendChild(y),t.appendChild(_);let b=document.createElement(`div`);b.className=QJ();let x=document.createElement(`input`);x.type=`checkbox`,x.id=`re-require-win`;let S=document.createElement(`label`);S.htmlFor=`re-require-win`,S.textContent=`Require win for points`,x.addEventListener(`change`,()=>e.setGlobalFlag(`requireWinForPoints`,x.checked)),b.appendChild(x),b.appendChild(S),t.appendChild(b);let C=document.createElement(`div`);C.className=QJ();let w=document.createElement(`input`);w.type=`checkbox`,w.id=`re-require-win-r1`;let T=document.createElement(`label`);T.htmlFor=`re-require-win-r1`,T.textContent=`Require win in first round`,w.addEventListener(`change`,()=>e.setGlobalFlag(`requireWinFirstRound`,w.checked)),C.appendChild(w),C.appendChild(T),t.appendChild(C);let E=[i,s,u,p],D=[g,y],O=[x,w];function k(e){let{draft:t}=e;document.activeElement!==i&&(i.value=t.policyName??``),document.activeElement!==s&&(s.value=t.policyVersion??``),document.activeElement!==u&&(u.value=t.validDateRange?.startDate??``),document.activeElement!==p&&(p.value=t.validDateRange?.endDate??``),document.activeElement!==g&&(g.value=t.doublesAttribution??``),document.activeElement!==y&&(y.value=t.categoryResolution??``),x.checked=t.requireWinForPoints??!1,w.checked=t.requireWinFirstRound??!1;let n=e.readonly;for(let e of E)e.disabled=n;for(let e of D)e.disabled=n;for(let e of O)e.disabled=n}return{element:t,update:k}}var mY={1:`W`,2:`F`,4:`SF`,8:`QF`,16:`R16`,32:`R32`,64:`R64`,128:`R128`,256:`R256`},hY=`level-keyed`;function gY(e){return mY[e]??`R${e}`}function _Y(e){if(!e)return{type:`flat`};let t=Object.values(e);if(!t.length||t.every(e=>typeof e==`number`))return{type:`flat`};let n=vY(t);return n.hasConditionalArray?{type:`conditional`}:n.hasLevelFlightNesting?yY(t,n.allLevels):n.allLevels.size>0?{type:`level-columns`,levels:[...n.allLevels].sort((e,t)=>e-t)}:n.allFlights.size>0?{type:`flight-columns`,flights:[...n.allFlights].sort((e,t)=>e-t)}:{type:`flat`}}function vY(e){let t=new Set,n=new Set,r=!1,i=!1;for(let a of e){let e=bY(a);if(e.type===hY){for(let n of e.levels)t.add(n);e.hasFlightNesting&&(i=!0)}else if(e.type===`flight-keyed`)for(let t=0;t<e.flightCount;t++)n.add(t+1);else e.type===`conditional-array`&&(r=!0)}return{allLevels:t,allFlights:n,hasConditionalArray:r,hasLevelFlightNesting:i}}function yY(e,t){let n={},r=[...t].sort((e,t)=>e-t);for(let t of e){let e=bY(t);if(e.type===hY&&e.flightDetails)for(let[t,r]of Object.entries(e.flightDetails)){let e=Number(t);n[e]||(n[e]=[]);for(let t of r)n[e].includes(t)||n[e].push(t)}}return{type:`level-flight-tabs`,levels:r,flightsPerLevel:n}}function bY(e){if(typeof e==`number`)return{type:`flat`,levels:[],flightCount:0,hasFlightNesting:!1};if(Array.isArray(e))return{type:`conditional-array`,levels:[],flightCount:0,hasFlightNesting:!1};if(typeof e!=`object`||!e)return{type:`flat`,levels:[],flightCount:0,hasFlightNesting:!1};if(e.level!==void 0){if(Array.isArray(e.level))return{type:hY,levels:e.level.map((e,t)=>t+1),flightCount:0,hasFlightNesting:!1};if(typeof e.level==`object`){let t=Object.keys(e.level).map(Number).filter(e=>!Number.isNaN(e)),n=!1,r={};for(let[t,i]of Object.entries(e.level))typeof i==`object`&&i&&i.flights&&(n=!0,r[Number(t)]=i.flights.map((e,t)=>t+1));return{type:hY,levels:t,flightCount:0,hasFlightNesting:n,flightDetails:r}}}return e.flights!==void 0||e.f!==void 0?{type:`flight-keyed`,levels:[],flightCount:(e.flights??e.f??[]).length,hasFlightNesting:!1}:e.value===void 0?{type:`flat`,levels:[],flightCount:0,hasFlightNesting:!1}:{type:`explicit-flat`,levels:[],flightCount:0,hasFlightNesting:!1}}function xY(e,t={}){if(typeof e==`number`)return e;if(e!=null){if(Array.isArray(e))return SY(e,t);if(typeof e==`object`){if(e.level!==void 0&&t.level!==void 0)return CY(e,t);if(t.flight!==void 0){let n=e.flights??e.f;if(Array.isArray(n))return n[t.flight-1]}if(e.value!==void 0)return e.value}}}function SY(e,t){for(let n of e){if(n.drawSizes&&t.drawSize&&n.drawSizes.includes(t.drawSize))return xY(n,t);if(n.drawSize!==void 0&&t.drawSize!==void 0&&(n.threshold?t.drawSize>=n.drawSize:t.drawSize===n.drawSize))return xY({...n,drawSize:void 0,drawSizes:void 0,threshold:void 0},t);if(n.drawSize===void 0&&n.drawSizes===void 0)return xY(n,t)}}function CY(e,t){let n=Array.isArray(e.level)?e.level[t.level-1]:e.level[t.level];if(n!==void 0)return typeof n==`object`&&n?xY(n,t):typeof n==`number`?n:void 0}function wY(e){let t=[],n=Object.keys(e.finishingPositionRanges??{}).length;return n&&t.push(`${n} positions`),(e.perWinPoints||e.pointsPerWin)&&t.push(`per-win`),e.bonusPoints?.length&&t.push(`${e.bonusPoints.length} bonus`),t.join(`, `)||`empty`}function TY(e){let t=[];for(let n of e.eventTypes??[])t.push({label:n,intent:`re-badge--accent`});for(let n of e.stages??[])t.push({label:n,intent:`re-badge--success`});for(let n of e.levels??[])t.push({label:`L${n}`,intent:`re-badge--warn`});for(let n of e.drawTypes??[])t.push({label:n.replaceAll(`_`,` `),intent:`re-badge--primary`});return e.participationOrder!==void 0&&t.push({label:`PO:${e.participationOrder}`,intent:`re-badge--info`}),t}function EY(e){return e==null?`--`:e.toLocaleString()}var DY=[1,2,4,8,16,32,64,128],OY=`font-size:0.8rem;margin-bottom:0;border-collapse:collapse`,kY=`width:3.5rem;text-align:center`;function AY(e,t){let n=document.createElement(`div`);n.style.cssText=`overflow-x:auto`;let r=``;function i(r){let i=r.draft.awardProfiles?.[t]?.finishingPositionRanges;if(n.innerHTML=``,!i||!Object.keys(i).length){let i=document.createElement(`div`);if(i.className=sY(),i.textContent=`No finishing position points defined`,!r.readonly){let n=document.createElement(`button`);n.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,n.textContent=`+ Add position`,n.style.marginLeft=`8px`,n.addEventListener(`click`,()=>e.addPositionRow(t,1)),i.appendChild(n)}n.appendChild(i);return}let a=_Y(i),o=Object.keys(i).map(Number).sort((e,t)=>e-t);a.type===`flat`?jY(n,o,i,r.readonly,e,t):a.type===`level-columns`?MY(n,o,i,a.levels,r.readonly,e,t):NY(n,o,i,a)}function a(e){let n=e.draft.awardProfiles?.[t],a=JSON.stringify(n?.finishingPositionRanges??{});a!==r&&(r=a,i(e))}return{element:n,update:a}}function jY(e,t,n,r,i,a){let o=document.createElement(`table`);o.style.cssText=OY;let s=document.createElement(`thead`),c=document.createElement(`tr`);PY(c,`Pos`,kY),PY(c,`Points`,`text-align:right`),r||PY(c,``,`width:2rem`),s.appendChild(c),o.appendChild(s);let l=document.createElement(`tbody`);for(let e of t){let t=document.createElement(`tr`);FY(t,e);let o=document.createElement(`td`);o.style.cssText=`text-align:right;padding:2px 4px`,r?(o.style.fontVariantNumeric=`tabular-nums`,o.textContent=EY(typeof n[e]==`number`?n[e]:xY(n[e]))):o.appendChild(LY(typeof n[e]==`number`?n[e]:xY(n[e])??0,t=>i.setFlatPositionPoints(a,e,t))),t.appendChild(o),r||IY(t,()=>i.removePositionRow(a,e)),l.appendChild(t)}o.appendChild(l),e.appendChild(o),r||RY(e,t,i,a)}function MY(e,t,n,r,i,a,o){let s=document.createElement(`table`);s.style.cssText=OY;let c=document.createElement(`thead`),l=document.createElement(`tr`);PY(l,`Pos`,kY);for(let e of r){let t=document.createElement(`th`);if(t.style.cssText=`text-align:right;min-width:3.5rem;padding:2px 4px`,i)t.textContent=`L${e}`;else{let n=document.createElement(`div`);n.style.cssText=`display:flex;align-items:center;justify-content:flex-end;gap:4px`;let r=document.createElement(`span`);r.textContent=`L${e}`,n.appendChild(r);let i=document.createElement(`span`);i.className=oY(),i.textContent=`×`,i.title=`Remove level ${e}`,i.style.cssText=`cursor:pointer;font-size:0.65rem`,i.addEventListener(`click`,()=>a.removeLevel(o,e)),n.appendChild(i),t.appendChild(n)}l.appendChild(t)}i||PY(l,``,`width:2rem`),c.appendChild(l),s.appendChild(c);let u=document.createElement(`tbody`);for(let e of t){let t=document.createElement(`tr`);FY(t,e);for(let s of r){let r=document.createElement(`td`);r.style.cssText=`text-align:right;padding:2px 4px`;let c=xY(n[e],{level:s});i?(r.style.fontVariantNumeric=`tabular-nums`,r.textContent=EY(c),c===void 0&&(r.style.color=`var(--sp-muted)`)):r.appendChild(LY(c??0,t=>a.setLevelPositionPoints(o,e,s,t))),t.appendChild(r)}i||IY(t,()=>a.removePositionRow(o,e)),u.appendChild(t)}if(s.appendChild(u),e.appendChild(s),!i){let n=document.createElement(`div`);n.style.cssText=`display:flex;gap:8px;margin-top:6px;flex-wrap:wrap`;let i=document.createElement(`div`);i.style.cssText=`display:flex;align-items:center;gap:4px`;let s=document.createElement(`input`);s.type=`number`,s.className=$J(),s.style.width=`50px`,s.placeholder=`L#`,s.min=`1`;let c=document.createElement(`button`);c.className=`sp-btn sp-btn--sm sp-btn--outline`,c.textContent=`+ Level`,c.addEventListener(`click`,()=>{let e=Number.parseInt(s.value,10);!Number.isNaN(e)&&e>0&&!r.includes(e)&&(a.addLevel(o,e),s.value=``)}),i.appendChild(s),i.appendChild(c),n.appendChild(i),zY(n,t,a,o),e.appendChild(n)}}function NY(e,t,n,r){let i=document.createElement(`div`);i.style.cssText=`font-size:0.7rem;color:var(--sp-muted);margin-bottom:4px;font-style:italic`,i.textContent=`(${r.type} layout — view only)`,e.appendChild(i);let a=document.createElement(`table`);a.style.cssText=OY;let o=document.createElement(`thead`),s=document.createElement(`tr`);if(PY(s,`Pos`,kY),r.type===`flight-columns`)for(let e of r.flights)PY(s,`F${e}`,`text-align:right;min-width:3.5rem`);else PY(s,`Points`,`text-align:right`);o.appendChild(s),a.appendChild(o);let c=document.createElement(`tbody`);for(let e of t){let t=document.createElement(`tr`);FY(t,e);let i=n[e];if(r.type===`flight-columns`)for(let e of r.flights){let n=document.createElement(`td`);n.style.cssText=`text-align:right;font-variant-numeric:tabular-nums;padding:2px 4px`;let r=xY(i,{flight:e});n.textContent=EY(r),r===void 0&&(n.style.color=`var(--sp-muted)`),t.appendChild(n)}else{let e=document.createElement(`td`);if(e.style.cssText=`text-align:right;font-variant-numeric:tabular-nums;padding:2px 4px`,e.textContent=EY(xY(i)),Array.isArray(i)){let t=document.createElement(`span`);t.style.cssText=`margin-left:0.3rem;font-size:0.65rem;color:var(--sp-muted)`,t.textContent=`${i.length} variants`,t.title=JSON.stringify(i,null,2),e.appendChild(t)}t.appendChild(e)}c.appendChild(t)}a.appendChild(c),e.appendChild(a)}function PY(e,t,n){let r=document.createElement(`th`);r.textContent=t,r.style.cssText=n+`;padding:2px 4px`,e.appendChild(r)}function FY(e,t){let n=document.createElement(`td`);n.style.cssText=`text-align:center;font-weight:600;color:var(--sp-text);padding:2px 4px`,n.textContent=gY(t),e.appendChild(n)}function IY(e,t){let n=document.createElement(`td`);n.style.cssText=`text-align:center;vertical-align:middle;padding:2px`;let r=document.createElement(`span`);r.className=oY(),r.textContent=`×`,r.title=`Remove position`,r.style.cursor=`pointer`,r.addEventListener(`click`,t),n.appendChild(r),e.appendChild(n)}function LY(e,t){let n=document.createElement(`input`);return n.type=`number`,n.className=$J(),n.value=String(e),n.addEventListener(`change`,()=>{let e=Number.parseFloat(n.value);Number.isNaN(e)||t(e)}),n}function RY(e,t,n,r){let i=document.createElement(`div`);i.style.cssText=`display:flex;gap:8px;margin-top:6px;flex-wrap:wrap`,zY(i,t,n,r),e.appendChild(i)}function zY(e,t,n,r){let i=new Set(t),a=DY.filter(e=>!i.has(e));if(!a.length)return;let o=document.createElement(`div`);o.style.cssText=`display:flex;align-items:center;gap:4px`;let s=document.createElement(`select`);s.className=`re-field-select`,s.style.cssText=`min-width:80px;font-size:11px;padding:4px 6px`;for(let e of a){let t=document.createElement(`option`);t.value=String(e),t.textContent=gY(e),s.appendChild(t)}let c=document.createElement(`button`);c.className=`sp-btn sp-btn--sm sp-btn--outline`,c.textContent=`+ Position`,c.addEventListener(`click`,()=>{let e=Number.parseInt(s.value,10);Number.isNaN(e)||n.addPositionRow(r,e)}),o.appendChild(s),o.appendChild(c),e.appendChild(o)}function BY(e,t){let n=document.createElement(`div`);n.style.cssText=`padding:0.25rem 0;font-size:0.8rem`;let r=document.createElement(`div`);r.className=KJ();let i=document.createElement(`div`);i.className=qJ(),i.textContent=`Per-Win`,i.style.minWidth=`80px`;let a=document.createElement(`input`);a.type=`number`,a.className=$J(),a.placeholder=`—`,a.addEventListener(`change`,()=>{let n=a.value.trim();e.setPointsPerWin(t,n===``?void 0:parseFloat(n))});let o=document.createElement(`div`);o.style.cssText=`font-size:0.75rem;color:var(--sp-muted)`,r.appendChild(i),r.appendChild(a),n.appendChild(r),n.appendChild(o);function s(e){let r=e.draft.awardProfiles?.[t];if(!r){n.style.display=`none`;return}let i=r.perWinPoints,s=r.pointsPerWin;if(!i&&s===void 0){n.style.display=`none`;return}if(n.style.display=``,a.disabled=e.readonly,s!==void 0&&typeof s==`number`)a.style.display=``,o.style.display=`none`,document.activeElement!==a&&(a.value=String(s));else if(s!==void 0){a.style.display=`none`,o.style.display=``;let e=xY(s);o.textContent=`${EY(e)} pts/win (complex)`}else if(i){a.style.display=`none`,o.style.display=``;let e=(Array.isArray(i)?i:[i]).map(e=>{let t=[];return e.participationOrders?.length&&t.push(`PO:${e.participationOrders.join(`,`)}`),e.value!==void 0&&t.push(`${e.value} pts/win`),e.limit!==void 0&&t.push(`limit: ${e.limit}`),t.join(` | `)});o.textContent=e.join(`; `)}if(r.maxCountableMatches!==void 0){let e=typeof r.maxCountableMatches==`number`?r.maxCountableMatches:`level-keyed`;o.style.display=``;let t=o.textContent;o.textContent=t?`${t} — max countable: ${e}`:`Max countable: ${e}`}}return{element:n,update:s}}function VY(e,t){let n=document.createElement(`div`);n.style.cssText=`padding:0.25rem 0;font-size:0.8rem`;let r=``;function i(r){let i=r.draft.awardProfiles?.[t]?.bonusPoints;if(n.innerHTML=``,!i?.length&&r.readonly){n.style.display=`none`;return}n.style.display=``;let a=document.createElement(`div`);if(a.style.cssText=`font-weight:600;color:var(--sp-text);margin-bottom:4px`,a.textContent=`Bonus Points`,n.appendChild(a),i?.length)for(let a=0;a<i.length;a++){let o=i[a],s=document.createElement(`div`);if(s.style.cssText=`display:flex;align-items:center;gap:6px;margin-bottom:4px;padding-left:0.5rem`,r.readonly){let e=o.finishingPositions.map(gY).join(`, `),t=document.createElement(`span`);t.textContent=`${e}: `,s.appendChild(t);let n=document.createElement(`span`);n.style.fontVariantNumeric=`tabular-nums`,n.textContent=typeof o.value==`number`?o.value.toLocaleString():String(o.value??`—`),s.appendChild(n)}else{let n=document.createElement(`span`);n.style.cssText=`font-size:0.75rem;color:var(--sp-muted);min-width:30px`,n.textContent=`Pos:`,s.appendChild(n);let r=document.createElement(`input`);r.type=`text`,r.className=$J(),r.style.width=`80px`,r.value=o.finishingPositions.join(`, `),r.title=`Comma-separated positions (e.g. 1, 2)`,r.addEventListener(`change`,()=>{let n=r.value.split(`,`).map(e=>Number.parseInt(e.trim(),10)).filter(e=>!Number.isNaN(e)&&e>0);n.length&&e.setBonusPointPositions(t,a,n)}),s.appendChild(r);let i=document.createElement(`span`);i.style.cssText=`font-size:0.75rem;color:var(--sp-muted)`,i.textContent=`Pts:`,s.appendChild(i);let c=document.createElement(`input`);c.type=`number`,c.className=$J(),c.value=typeof o.value==`number`?String(o.value):``,c.addEventListener(`change`,()=>{let n=Number.parseFloat(c.value);Number.isNaN(n)||e.setBonusPointValue(t,a,n)}),s.appendChild(c);let l=document.createElement(`span`);l.className=oY(),l.textContent=`×`,l.title=`Remove bonus`,l.style.cursor=`pointer`,l.addEventListener(`click`,()=>e.removeBonusPoint(t,a)),s.appendChild(l)}n.appendChild(s)}if(!r.readonly){let r=document.createElement(`button`);r.className=`sp-btn sp-btn--sm sp-btn--outline`,r.textContent=`+ Add bonus`,r.style.cssText=`margin-top:4px;margin-left:0.5rem`,r.addEventListener(`click`,()=>e.addBonusPoint(t)),n.appendChild(r)}}function a(e){let n=e.draft.awardProfiles?.[t],a=JSON.stringify(n?.bonusPoints??[]);a!==r&&(r=a,i(e))}return{element:n,update:a}}function HY(e){let t=document.createElement(`div`);t.style.cssText=`display:inline-flex;gap:0.25rem;flex-wrap:wrap;margin-bottom:0`;let n=TY(e);if(!n.length){let e=document.createElement(`span`);return e.className=`re-badge re-badge--neutral`,e.textContent=`All`,t.appendChild(e),t}for(let e of n){let n=document.createElement(`span`);n.className=`re-badge ${e.intent}`,n.textContent=e.label,t.appendChild(n)}return t}var UY=[{field:`eventTypes`,label:`Event types`,options:[`SINGLES`,`DOUBLES`,`TEAM`]},{field:`drawTypes`,label:`Draw types`,options:[`SINGLE_ELIMINATION`,`DOUBLE_ELIMINATION`,`ROUND_ROBIN`,`COMPASS`,`FEED_IN`,`AD_HOC`,`LUCKY_DRAW`]},{field:`stages`,label:`Stages`,options:[`MAIN`,`QUALIFYING`,`CONSOLATION`,`PLAY_OFF`]},{field:`levels`,label:`Levels`,options:[],isNumeric:!0}],WY=[[`maxDrawSize`,`Max draw size`],[`maxLevel`,`Max level`],[`priority`,`Priority`],[`participationOrder`,`Participation order`]];function GY(e,t){let n=document.createElement(`div`);n.style.cssText=`padding:0.25rem 0`;let r=document.createElement(`div`);r.style.cssText=`font-weight:600;font-size:0.8rem;color:var(--sp-text);margin-bottom:4px`,r.textContent=`Scope`,n.appendChild(r);let i=document.createElement(`div`);n.appendChild(i);let a=``;function o(n,r){if(n.isNumeric){let i=document.createElement(`input`);return i.type=`number`,i.min=`1`,i.placeholder=`+`,i.style.cssText=`width:36px;font-size:0.7rem;padding:2px 4px;border:1px dashed var(--sp-border);border-radius:4px;background:transparent;color:var(--sp-text);outline:none;text-align:center`,i.addEventListener(`keydown`,a=>{if(a.key===`Enter`){let a=Number.parseInt(i.value,10);!Number.isNaN(a)&&a>0&&!r.includes(a)&&(e.setProfileScope(t,n.field,[...r,a].sort((e,t)=>e-t)),i.value=``)}}),i}let i=n.options.filter(e=>!r.includes(e));if(!i.length)return;let a=document.createElement(`select`);a.style.cssText=`font-size:0.65rem;padding:2px 4px;border:1px dashed var(--sp-border);border-radius:4px;background:transparent;color:var(--sp-muted);outline:none;cursor:pointer`;let o=document.createElement(`option`);o.value=``,o.textContent=`+`,a.appendChild(o);for(let e of i){let t=document.createElement(`option`);t.value=e,t.textContent=e,a.appendChild(t)}return a.addEventListener(`change`,()=>{a.value&&e.setProfileScope(t,n.field,[...r,a.value])}),a}function s(n,r,i){let a=document.createElement(`div`);a.style.cssText=`margin-bottom:6px`;let s=document.createElement(`div`);s.style.cssText=`font-size:0.7rem;color:var(--sp-muted);margin-bottom:2px`,s.textContent=n.label,a.appendChild(s);let c=document.createElement(`div`);c.style.cssText=`display:flex;flex-wrap:wrap;gap:4px;align-items:center`;for(let a of r){let o=document.createElement(`span`);if(o.className=`re-badge re-badge--accent`,o.style.cssText=`display:inline-flex;align-items:center;gap:3px`,o.textContent=n.isNumeric?`L${a}`:String(a),!i){let i=document.createElement(`span`);i.style.cssText=`cursor:pointer;font-size:0.6rem;opacity:0.7`,i.textContent=`×`,i.addEventListener(`click`,()=>{e.setProfileScope(t,n.field,r.filter(e=>e!==a))}),o.appendChild(i)}c.appendChild(o)}if(!i){let e=o(n,r);e&&c.appendChild(e)}return a.appendChild(c),a}function c(r){i.innerHTML=``;let a=r.draft.awardProfiles?.[t];if(!a)return;let o=r.readonly;for(let e of UY){let t=a[e.field]??[];o&&!t.length||i.appendChild(s(e,t,o))}for(let[n,r]of WY){let s=a[n];if(o&&s===void 0)continue;let c=document.createElement(`div`);c.className=KJ();let l=document.createElement(`div`);if(l.className=qJ(),l.style.cssText=`min-width:110px;font-size:0.75rem`,l.textContent=r,c.appendChild(l),o){let e=document.createElement(`span`);e.style.cssText=`font-size:0.75rem;color:var(--sp-text)`,e.textContent=String(s),c.appendChild(e)}else{let r=document.createElement(`input`);r.type=`number`,r.className=YJ(),r.style.fontSize=`0.75rem`,r.value=s===void 0?``:String(s),r.placeholder=`—`,r.addEventListener(`change`,()=>{let i=r.value.trim();e.setProfileField(t,n,i?Number.parseInt(i,10):void 0)}),c.appendChild(r)}i.appendChild(c)}let c=i.children.length>0;n.style.display=c?``:`none`}function l(e){let n=e.draft.awardProfiles?.[t],r=UY.map(e=>n?.[e.field]??[]),i=WY.map(([e])=>n?.[e]),o=JSON.stringify([r,i,e.readonly]);o!==a&&(a=o,c(e))}return{element:n,update:l}}function KY(e,t){let n=document.createElement(`div`);n.className=eY();let r=document.createElement(`div`);r.className=tY();let i=document.createElement(`span`);i.className=UJ(),i.style.flexShrink=`0`,r.appendChild(i);let a=document.createElement(`input`);a.type=`text`,a.className=nY(),a.addEventListener(`click`,e=>e.stopPropagation()),a.addEventListener(`change`,()=>e.setProfileName(t,a.value)),r.appendChild(a);let o=document.createElement(`div`);o.style.cssText=`flex-grow:1;display:inline-flex;gap:0.25rem;flex-wrap:wrap`,r.appendChild(o);let s=document.createElement(`span`);s.style.cssText=`font-size:0.75rem;color:var(--sp-muted);white-space:nowrap;flex-shrink:0`,r.appendChild(s);let c=document.createElement(`div`);c.className=iY();let l=document.createElement(`button`);l.className=aY(),l.textContent=`⎘`,l.title=`Duplicate profile`,l.addEventListener(`click`,n=>{n.stopPropagation(),e.duplicateProfile(t)});let u=document.createElement(`button`);u.className=oY(),u.textContent=`✕`,u.title=`Delete profile`,u.addEventListener(`click`,n=>{n.stopPropagation(),e.removeProfile(t)}),c.appendChild(l),c.appendChild(u),r.appendChild(c),r.addEventListener(`click`,()=>e.toggleProfile(t)),n.appendChild(r);let d=document.createElement(`div`);d.className=rY();let f=document.createElement(`div`);f.style.cssText=`font-weight:600;font-size:0.85rem;color:var(--sp-text);margin-bottom:6px`,d.appendChild(f);let p=AY(e,t);d.appendChild(p.element);let m=BY(e,t);d.appendChild(m.element);let h=VY(e,t);d.appendChild(h.element);let g=GY(e,t);d.appendChild(g.element);let _=document.createElement(`div`);_.style.cssText=`padding:0.25rem 0;font-size:0.75rem;color:var(--sp-muted)`,d.appendChild(_),n.appendChild(d);function v(e){let r=e.draft.awardProfiles?.[t];if(!r){n.style.display=`none`;return}n.style.display=``;let l=e.expandedProfiles.has(t),u=e.readonly;i.textContent=l?`▼`:`▶`;let v=r.profileName||`Profile ${t+1}`;document.activeElement!==a&&(a.value=v),a.title=v,a.disabled=u,o.innerHTML=``;let y=HY(r);if(y.style.flexGrow=`1`,o.appendChild(y),s.textContent=l?``:wY(r),c.style.display=u?`none`:`flex`,d.style.display=l?``:`none`,l){f.textContent=v,p.update(e),m.update(e),h.update(e),g.update(e);let t=[];r.requireWinForPoints!==void 0&&t.push(`requireWin: ${r.requireWinForPoints}`),r.requireWinFirstRound!==void 0&&t.push(`requireWinR1: ${r.requireWinFirstRound}`),_.textContent=t.join(` | `),_.style.display=t.length?``:`none`}}return{element:n,update:v}}function qY(e,t){let n=document.createElement(`div`);n.className=cY();let r=pY(e),i=dY(e),a=uY(e),o=[{id:`metadata`,label:`Metadata`},{id:`awardProfiles`,label:`Award Profiles`,countFn:e=>e.draft.awardProfiles?.length??0},{id:`qualityWinProfiles`,label:`Quality Win Profiles`,countFn:e=>e.draft.qualityWinProfiles?.length??0},{id:`aggregationRules`,label:`Aggregation Rules`}],s=[];for(let t of o){let o=document.createElement(`div`);o.className=VJ();let c=document.createElement(`div`);c.className=HJ();let l=document.createElement(`span`);l.className=UJ();let u=document.createElement(`span`);u.textContent=t.label;let d=document.createElement(`span`);d.className=WJ(),c.appendChild(l),c.appendChild(u),c.appendChild(d),c.addEventListener(`click`,()=>e.toggleSection(t.id));let f=document.createElement(`div`);f.className=GJ(),t.id===`metadata`&&f.appendChild(r.element),t.id===`qualityWinProfiles`&&f.appendChild(i.element),t.id===`aggregationRules`&&f.appendChild(a.element),o.appendChild(c),o.appendChild(f),n.appendChild(o),s.push({id:t.id,chevron:l,countEl:d,bodyEl:f})}let c=[],l=-1,u=``,d=null;function f(e,t){for(let n=0;n<o.length;n++){let r=o[n],i=s[n],a=e.has(r.id);if(i.chevron.textContent=a?`▼`:`▶`,i.bodyEl.style.display=a?`block`:`none`,r.countFn){let e=r.countFn(t);i.countEl.textContent=e?`(${e})`:``}}}function p(t,n){let r=s[1].bodyEl;r.innerHTML=``,c=[];let i=t.draft.awardProfiles??[],a=0;for(let t=0;t<i.length;t++){let o=i[t];if(n&&![o.profileName??``,...o.eventTypes??[],...o.stages??[],...(o.levels??[]).map(e=>`L${e}`),...o.drawTypes??[]].join(` `).toLowerCase().includes(n))continue;let s=KY(e,t);c.push(s),r.appendChild(s.element),a++}if(!a){let e=document.createElement(`div`);e.className=sY(),e.textContent=n?`No profiles match filter`:`No award profiles defined`,r.appendChild(e)}t.readonly||(d=document.createElement(`button`),d.className=`sp-btn sp-btn--sm sp-btn--outline re-add-btn`,d.textContent=`+ Add Profile`,d.addEventListener(`click`,()=>e.addProfile()),r.appendChild(d))}return{element:n,update:e=>{let{draft:t,expandedSections:n,profileFilter:o}=e;if(f(n,e),n.has(`metadata`)&&r.update(e),n.has(`awardProfiles`)){let n=t.awardProfiles?.length??0,r=o.toLowerCase();(n!==l||r!==u)&&(l=n,u=r,p(e,r));for(let t of c)t.update(e);d&&(d.style.display=e.readonly?`none`:``)}n.has(`qualityWinProfiles`)&&i.update(e),n.has(`aggregationRules`)&&a.update(e)}}}var JY=class e{constructor(e){this.container=null,this.store=new BJ(e),this.panel=qY(this.store,e),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.panel.element.remove(),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e),readonly:t.readonly},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}};function YY(e){return XY[e]??e}var XY={"SET3-S:6/TB7":`Best of 3 TB sets`,"SET3-S:6/TB7-F:TB10":`2 TB sets, MTB10`,"SET3-S:6/TB7-F:TB7":`2 TB sets, MTB7`,"SET3-S:4NOAD-F:TB7":`2 short sets (4, NOAD), MTB7`,"SET3-S:4/TB7":`Best of 3 short sets (4)`,"SET3-S:4/TB7-F:TB7":`2 short sets (4), MTB7`,"SET3-S:4/TB7-F:TB10":`2 short sets (4), MTB10`,"SET3-S:4/TB5@3":`3 short sets (4), TB5@3`,"SET1-S:8/TB7":`8-game pro-set, TB7`,"SET1-S:8/TB7@7":`8-game pro-set, TB7@7`,"SET1-S:5/TB9@4":`1 set to 5, TB9@4`,"SET1-S:6/TB7":`1 TB set`,"SET1-S:6NOAD":`1 set to 6, NOAD`,"SET1-S:4/TB7":`1 short set (4), TB7`,"SET1-S:4/TB5@3":`1 short set (4), TB5@3`,"SET1-S:4NOAD":`1 short set (4), NOAD`,"SET3-S:TB10":`Best of 3 TB10 games`,"SET1-S:T20":`Timed 20 min`,"SET1-S:TB10":`1 TB10 game`,"SET5-S:6/TB7":`Best of 5 TB sets`,"SET5-S:6/TB7-F:TB10":`5 sets, MTB10`,"SET1-S:6/TB10":`1 set, TB10`,"SET1-S:8":`Pro-set to 8`,"SET1-S:10":`Pro-set to 10`,"SET1-S:T7":`TB7 only`,"SET1-S:T21":`TB21 only`};function ZY(){return{allowModificationWhenMatchUpsScheduled:{courts:!1,venues:!1},defaultTimes:{averageTimes:[{categoryNames:[],minutes:{default:90}}],recoveryTimes:[{minutes:{default:60}}]},defaultDailyLimits:{SINGLES:2,DOUBLES:2,total:3},matchUpAverageTimes:[],matchUpRecoveryTimes:[],matchUpDailyLimits:[]}}function QY(e){return structuredClone(e)}var $Y=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:QY(e.initialPolicy??ZY()),expandedSections:new Set([`modificationFlags`,`dailyLimits`,`defaultTimes`,`averageTimes`,`recoveryTimes`]),dirty:!1}}getState(){return this.state}getData(){return QY(this.state.draft)}setData(e){this.state={...this.state,draft:QY(e),dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}setModificationFlag(e,t){let n=QY(this.state.draft);n.allowModificationWhenMatchUpsScheduled||={courts:!1,venues:!1},n.allowModificationWhenMatchUpsScheduled[e]=t,this.commitDraft(n)}setDailyLimit(e,t){let n=QY(this.state.draft);n.defaultDailyLimits||={},n.defaultDailyLimits[e]=t,this.commitDraft(n)}setDefaultAverageTime(e,t,n){let r=QY(this.state.draft);r.defaultTimes||={},r.defaultTimes.averageTimes||(r.defaultTimes.averageTimes=[{categoryNames:[],minutes:{default:90}}]);let i=r.defaultTimes.averageTimes[e];i&&(t===`DOUBLES`?n===void 0?delete i.minutes.DOUBLES:i.minutes.DOUBLES=n:i.minutes.default=n??0,this.commitDraft(r))}setDefaultRecoveryTime(e,t,n){let r=QY(this.state.draft);r.defaultTimes||={},r.defaultTimes.recoveryTimes||(r.defaultTimes.recoveryTimes=[{minutes:{default:60}}]);let i=r.defaultTimes.recoveryTimes[e];i&&(t===`DOUBLES`?n===void 0?delete i.minutes.DOUBLES:i.minutes.DOUBLES=n:i.minutes.default=n??0,this.commitDraft(r))}addAverageFormatGroup(){let e=QY(this.state.draft);e.matchUpAverageTimes||=[],e.matchUpAverageTimes.push({matchUpFormatCodes:[],averageTimes:[{categoryNames:[],minutes:{default:60}}]}),this.commitDraft(e)}removeAverageFormatGroup(e){let t=QY(this.state.draft);t.matchUpAverageTimes&&(t.matchUpAverageTimes.splice(e,1),this.commitDraft(t))}setAverageFormatCodes(e,t){let n=QY(this.state.draft),r=n.matchUpAverageTimes?.[e];r&&(r.matchUpFormatCodes=t,this.commitDraft(n))}setAverageTime(e,t,n,r){let i=QY(this.state.draft),a=i.matchUpAverageTimes?.[e]?.averageTimes?.[t];a&&(n===`DOUBLES`?r===void 0?delete a.minutes.DOUBLES:a.minutes.DOUBLES=r:a.minutes.default=r??0,this.commitDraft(i))}addAverageCategoryOverride(e){let t=QY(this.state.draft),n=t.matchUpAverageTimes?.[e];n&&(n.averageTimes.push({categoryTypes:[],minutes:{default:60}}),this.commitDraft(t))}removeAverageCategoryOverride(e,t){let n=QY(this.state.draft),r=n.matchUpAverageTimes?.[e];r&&(r.averageTimes.splice(t,1),this.commitDraft(n))}setAverageOverrideCategories(e,t,n,r){let i=QY(this.state.draft),a=i.matchUpAverageTimes?.[e]?.averageTimes?.[t];a&&(n===`categoryNames`?(delete a.categoryTypes,a.categoryNames=r):(delete a.categoryNames,a.categoryTypes=r),this.commitDraft(i))}addRecoveryFormatGroup(){let e=QY(this.state.draft);e.matchUpRecoveryTimes||=[],e.matchUpRecoveryTimes.push({matchUpFormatCodes:[],recoveryTimes:[{categoryNames:[],minutes:{default:30}}]}),this.commitDraft(e)}removeRecoveryFormatGroup(e){let t=QY(this.state.draft);t.matchUpRecoveryTimes&&(t.matchUpRecoveryTimes.splice(e,1),this.commitDraft(t))}setRecoveryFormatCodes(e,t){let n=QY(this.state.draft),r=n.matchUpRecoveryTimes?.[e];r&&(r.matchUpFormatCodes=t,this.commitDraft(n))}setRecoveryTime(e,t,n,r){let i=QY(this.state.draft),a=i.matchUpRecoveryTimes?.[e]?.recoveryTimes?.[t];a&&(n===`DOUBLES`?r===void 0?delete a.minutes.DOUBLES:a.minutes.DOUBLES=r:a.minutes.default=r??0,this.commitDraft(i))}addRecoveryCategoryOverride(e){let t=QY(this.state.draft),n=t.matchUpRecoveryTimes?.[e];n&&(n.recoveryTimes.push({categoryTypes:[],minutes:{default:30}}),this.commitDraft(t))}removeRecoveryCategoryOverride(e,t){let n=QY(this.state.draft),r=n.matchUpRecoveryTimes?.[e];r&&(r.recoveryTimes.splice(t,1),this.commitDraft(n))}setRecoveryOverrideCategories(e,t,n,r){let i=QY(this.state.draft),a=i.matchUpRecoveryTimes?.[e]?.recoveryTimes?.[t];a&&(n===`categoryNames`?(delete a.categoryTypes,a.categoryNames=r):(delete a.categoryNames,a.categoryTypes=r),this.commitDraft(i))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(QY(e))}emit(){for(let e of this.listeners)e(this.state)}},eX=()=>`se-section`,tX=()=>`se-section-header`,nX=()=>`se-section-chevron`,rX=()=>`se-section-body`,iX=()=>`se-field-row`,aX=()=>`se-field-label`,oX=()=>`se-field-input`,sX=()=>`se-field-unit`,cX=()=>`se-checkbox-row`,lX=()=>`se-format-group`,uX=()=>`se-format-group-header`,dX=()=>`se-format-group-label`,fX=()=>`se-tag-picker`,pX=()=>`sp-chip`,mX=()=>`sp-chip__remove`,hX=()=>`se-tag-add-wrap`,gX=()=>`sp-btn-icon`,_X=()=>`se-override-row`,vX=()=>`se-override-categories`,yX=()=>`se-override-remove`,bX=()=>`sp-btn sp-btn--sm sp-btn--outline se-add-btn`,xX=()=>`sp-btn-icon sp-btn-icon--danger`,SX=()=>`se-editor`;function CX(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=cX();let r=document.createElement(`input`);r.type=`checkbox`,r.id=`se-mod-courts`;let i=document.createElement(`label`);i.htmlFor=`se-mod-courts`,i.textContent=`Allow court modifications when matchUps scheduled`,r.addEventListener(`change`,()=>{e.setModificationFlag(`courts`,r.checked)}),n.appendChild(r),n.appendChild(i);let a=document.createElement(`div`);a.className=cX();let o=document.createElement(`input`);o.type=`checkbox`,o.id=`se-mod-venues`;let s=document.createElement(`label`);s.htmlFor=`se-mod-venues`,s.textContent=`Allow venue modifications when matchUps scheduled`,o.addEventListener(`change`,()=>{e.setModificationFlag(`venues`,o.checked)}),a.appendChild(o),a.appendChild(s),t.appendChild(n),t.appendChild(a);function c(e){let t=e.draft.allowModificationWhenMatchUpsScheduled;r.checked=t?.courts??!1,o.checked=t?.venues??!1}return{element:t,update:c}}var wX=`is-success`,TX=`is-danger`;function EX(e){if(e===``)return!0;let t=parseInt(e,10);return!isNaN(t)&&t>=0&&String(t)===e.trim()}function DX(e,t){if(t===``){e.classList.remove(wX,TX);return}EX(t)?(e.classList.remove(TX),e.classList.add(wX)):(e.classList.remove(wX),e.classList.add(TX))}function OX(e){let t=document.createElement(`div`),n=[];for(let[r,i]of[[`SINGLES`,`Singles limit`],[`DOUBLES`,`Doubles limit`],[`total`,`Total limit`]]){let a=document.createElement(`div`);a.className=iX();let o=document.createElement(`div`);o.className=aX(),o.textContent=i;let s=document.createElement(`input`);s.type=`text`,s.className=oX(),s.placeholder=`0`,s.addEventListener(`input`,()=>{DX(s,s.value)}),s.addEventListener(`change`,()=>{let t=parseInt(s.value,10);!isNaN(t)&&t>=0&&e.setDailyLimit(r,t)}),a.appendChild(o),a.appendChild(s),t.appendChild(a),n.push({key:r,label:i,input:s})}function r(e){let t=e.draft.defaultDailyLimits;for(let e of n){let n=t?.[e.key];document.activeElement!==e.input&&(e.input.value=n===void 0?``:String(n))}}return{element:t,update:r}}var kX=`is-success`,AX=`is-danger`;function jX(e){if(e===``)return!0;let t=parseInt(e,10);return!isNaN(t)&&t>=0&&String(t)===e.trim()}function MX(e,t,n){if(t===``&&n){e.classList.remove(kX,AX);return}jX(t)&&(t!==``||n)?(e.classList.remove(AX),e.classList.add(kX)):(e.classList.remove(kX),e.classList.add(AX))}function NX(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.style.cssText=`font-size:11px;font-weight:700;color:var(--sp-muted);margin-bottom:6px;`,n.textContent=`Default Average Times`,t.appendChild(n);let r=PX(`Default`,`min`,!1),i=PX(`Doubles override`,`min`,!0);t.appendChild(r.row),t.appendChild(i.row),r.input.addEventListener(`input`,()=>{MX(r.input,r.input.value,!1)}),r.input.addEventListener(`change`,()=>{let t=parseInt(r.input.value,10);!isNaN(t)&&t>=0&&e.setDefaultAverageTime(0,`default`,t)}),i.input.addEventListener(`input`,()=>{MX(i.input,i.input.value,!0)}),i.input.addEventListener(`change`,()=>{let t=i.input.value.trim();if(t===``||t===`-`)e.setDefaultAverageTime(0,`DOUBLES`,void 0);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&e.setDefaultAverageTime(0,`DOUBLES`,n)}});let a=document.createElement(`div`);a.style.height=`12px`,t.appendChild(a);let o=document.createElement(`div`);o.style.cssText=`font-size:11px;font-weight:700;color:var(--sp-muted);margin-bottom:6px;`,o.textContent=`Default Recovery Times`,t.appendChild(o);let s=PX(`Default`,`min`,!1),c=PX(`Doubles override`,`min`,!0);t.appendChild(s.row),t.appendChild(c.row),s.input.addEventListener(`input`,()=>{MX(s.input,s.input.value,!1)}),s.input.addEventListener(`change`,()=>{let t=parseInt(s.input.value,10);!isNaN(t)&&t>=0&&e.setDefaultRecoveryTime(0,`default`,t)}),c.input.addEventListener(`input`,()=>{MX(c.input,c.input.value,!0)}),c.input.addEventListener(`change`,()=>{let t=c.input.value.trim();if(t===``||t===`-`)e.setDefaultRecoveryTime(0,`DOUBLES`,void 0);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&e.setDefaultRecoveryTime(0,`DOUBLES`,n)}});function l(e){let t=e.draft.defaultTimes?.averageTimes?.[0];document.activeElement!==r.input&&(r.input.value=t?String(t.minutes.default):``),document.activeElement!==i.input&&(i.input.value=t?.minutes.DOUBLES===void 0?``:String(t.minutes.DOUBLES)),i.input.placeholder=`—`;let n=e.draft.defaultTimes?.recoveryTimes?.[0];document.activeElement!==s.input&&(s.input.value=n?String(n.minutes.default):``),document.activeElement!==c.input&&(c.input.value=n?.minutes.DOUBLES===void 0?``:String(n.minutes.DOUBLES)),c.input.placeholder=`—`}return{element:t,update:l}}function PX(e,t,n){let r=document.createElement(`div`);r.className=iX();let i=document.createElement(`div`);i.className=aX(),i.textContent=e;let a=document.createElement(`input`);a.type=`text`,a.className=oX(),a.placeholder=n?`—`:`0`;let o=document.createElement(`div`);return o.className=sX(),o.textContent=t,r.appendChild(i),r.appendChild(a),r.appendChild(o),{row:r,input:a}}var FX=`is-success`,IX=`is-danger`;function LX(e){if(e===``)return!0;let t=parseInt(e,10);return!isNaN(t)&&t>=0&&String(t)===e.trim()}function RX(e,t,n){if(t===``&&n){e.classList.remove(FX,IX);return}LX(t)&&(t!==``||n)?(e.classList.remove(IX),e.classList.add(FX)):(e.classList.remove(FX),e.classList.add(IX))}function zX(e){let t=document.createElement(`div`);t.className=lX();let n=document.createElement(`div`);n.className=uX();let r=document.createElement(`div`);r.style.flex=`1`;let i=document.createElement(`div`);i.className=dX(),i.textContent=`Formats`,r.appendChild(i);let a=document.createElement(`div`);a.className=fX();for(let t of e.formatCodes){let n=document.createElement(`span`);n.className=pX(),n.title=`${t} — click to edit`;let r=document.createElement(`span`);r.textContent=YY(t),n.addEventListener(`click`,()=>{Ha({existingMatchUpFormat:t,callback:n=>{if(!n||n===t)return;let r=e.formatCodes.map(e=>e===t?n:e);e.onFormatCodesChange(r)}})});let i=document.createElement(`span`);i.className=mX(),i.textContent=`×`,i.addEventListener(`click`,n=>{n.stopPropagation(),e.onFormatCodesChange(e.formatCodes.filter(e=>e!==t))}),n.appendChild(r),n.appendChild(i),a.appendChild(n)}let o=document.createElement(`div`);o.className=hX();let s=document.createElement(`button`);s.className=gX(),s.textContent=`+`,s.type=`button`,s.title=`Add format code`,s.addEventListener(`click`,t=>{t.stopPropagation(),Ha({existingMatchUpFormat:`SET3-S:6/TB7`,callback:t=>{t&&!e.formatCodes.includes(t)&&e.onFormatCodesChange([...e.formatCodes,t])}})}),o.appendChild(s),a.appendChild(o),r.appendChild(a);let c=document.createElement(`button`);c.className=xX(),c.textContent=`×`,c.type=`button`,c.title=`Remove format group`,c.addEventListener(`click`,()=>e.onRemoveGroup()),n.appendChild(r),n.appendChild(c),t.appendChild(n);for(let n=0;n<e.overrides.length;n++){let r=e.overrides[n],i=document.createElement(`div`);i.className=_X();let a=document.createElement(`div`);a.className=`${vX()}${r.isDefault?` all`:``}`,a.textContent=r.categoryLabel;let o=document.createElement(`input`);o.type=`text`,o.className=oX(),o.value=String(r.defaultMinutes),o.placeholder=`0`;let s=n;o.addEventListener(`input`,()=>{RX(o,o.value,!1)}),o.addEventListener(`change`,()=>{let t=parseInt(o.value,10);!isNaN(t)&&t>=0&&e.onTimeChange(s,`default`,t)});let c=document.createElement(`span`);c.className=sX(),c.textContent=`min`;let l=document.createElement(`span`);l.style.cssText=`font-size:11px;color:var(--sp-muted);margin-left:8px;`,l.textContent=`Doubles:`;let u=document.createElement(`input`);if(u.type=`text`,u.className=oX(),u.value=r.doublesMinutes===void 0?``:String(r.doublesMinutes),u.placeholder=`—`,u.addEventListener(`input`,()=>{RX(u,u.value,!0)}),u.addEventListener(`change`,()=>{let t=u.value.trim();if(t===``||t===`-`)e.onTimeChange(s,`DOUBLES`,void 0);else{let n=parseInt(t,10);!isNaN(n)&&n>=0&&e.onTimeChange(s,`DOUBLES`,n)}}),i.appendChild(a),i.appendChild(o),i.appendChild(c),i.appendChild(l),i.appendChild(u),!r.isDefault){let t=document.createElement(`span`);t.className=yX(),t.textContent=`×`,t.addEventListener(`click`,()=>e.onRemoveOverride(s)),i.appendChild(t)}t.appendChild(i)}let l=document.createElement(`button`);return l.className=bX(),l.textContent=`+ Add Override`,l.type=`button`,l.addEventListener(`click`,()=>e.onAddOverride()),t.appendChild(l),t}function BX(e,t){let n=document.createElement(`div`),r=document.createElement(`div`);n.appendChild(r);let i=document.createElement(`button`);i.className=bX(),i.textContent=`+ Add Format Group`,i.type=`button`,i.addEventListener(`click`,()=>e.addAverageFormatGroup()),n.appendChild(i);function a(n){r.innerHTML=``;let i=n.draft.matchUpAverageTimes??[];for(let n=0;n<i.length;n++){let a=i[n],o=a.averageTimes.map((e,t)=>{let n=e.categoryTypes??e.categoryNames??[];return{categoryLabel:n.length===0&&t===0?`All categories`:n.join(`, `)||`All categories`,isDefault:n.length===0&&t===0,defaultMinutes:e.minutes.default,doublesMinutes:e.minutes.DOUBLES}}),s=n,c=zX({formatCodes:a.matchUpFormatCodes,overrides:o,availableFormats:t.matchUpFormatCodes??VX(),onFormatCodesChange:t=>e.setAverageFormatCodes(s,t),onTimeChange:(t,n,r)=>e.setAverageTime(s,t,n,r),onAddOverride:()=>e.addAverageCategoryOverride(s),onRemoveOverride:t=>e.removeAverageCategoryOverride(s,t),onRemoveGroup:()=>e.removeAverageFormatGroup(s)});r.appendChild(c)}if(i.length===0){let e=document.createElement(`div`);e.style.cssText=`font-size:12px;color:var(--sp-muted);padding:8px 0;`,e.textContent=`No format-specific average times configured. Add a format group to set per-format times.`,r.appendChild(e)}}return{element:n,update:a}}function VX(){return[`SET3-S:6/TB7`,`SET3-S:6/TB7-F:TB10`,`SET3-S:6/TB7-F:TB7`,`SET3-S:4NOAD-F:TB7`,`SET3-S:4/TB7`,`SET3-S:4/TB7-F:TB7`,`SET3-S:4/TB7-F:TB10`,`SET3-S:4/TB5@3`,`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:4/TB5@3`,`SET1-S:4NOAD`,`SET3-S:TB10`,`SET1-S:T20`,`SET1-S:TB10`]}function HX(e,t){let n=document.createElement(`div`),r=document.createElement(`div`);n.appendChild(r);let i=document.createElement(`button`);i.className=bX(),i.textContent=`+ Add Format Group`,i.type=`button`,i.addEventListener(`click`,()=>e.addRecoveryFormatGroup()),n.appendChild(i);function a(n){r.innerHTML=``;let i=n.draft.matchUpRecoveryTimes??[];for(let n=0;n<i.length;n++){let a=i[n],o=a.recoveryTimes.map((e,t)=>{let n=e.categoryTypes??e.categoryNames??[];return{categoryLabel:n.length===0&&t===0?`All categories`:n.join(`, `)||`All categories`,isDefault:n.length===0&&t===0,defaultMinutes:e.minutes.default,doublesMinutes:e.minutes.DOUBLES}}),s=n,c=zX({formatCodes:a.matchUpFormatCodes,overrides:o,availableFormats:t.matchUpFormatCodes??UX(),onFormatCodesChange:t=>e.setRecoveryFormatCodes(s,t),onTimeChange:(t,n,r)=>e.setRecoveryTime(s,t,n,r),onAddOverride:()=>e.addRecoveryCategoryOverride(s),onRemoveOverride:t=>e.removeRecoveryCategoryOverride(s,t),onRemoveGroup:()=>e.removeRecoveryFormatGroup(s)});r.appendChild(c)}if(i.length===0){let e=document.createElement(`div`);e.style.cssText=`font-size:12px;color:var(--sp-muted);padding:8px 0;`,e.textContent=`No format-specific recovery times configured. Add a format group to set per-format recovery.`,r.appendChild(e)}}return{element:n,update:a}}function UX(){return[`SET3-S:6/TB7`,`SET3-S:6/TB7-F:TB10`,`SET3-S:6/TB7-F:TB7`,`SET3-S:4NOAD-F:TB7`,`SET3-S:4/TB7`,`SET3-S:4/TB7-F:TB7`,`SET3-S:4/TB7-F:TB10`,`SET3-S:4/TB5@3`,`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:4/TB5@3`,`SET1-S:4NOAD`,`SET3-S:TB10`,`SET1-S:T20`,`SET1-S:TB10`]}function WX(e,t){let n=document.createElement(`div`);n.className=SX();let r=[{id:`modificationFlags`,label:`Modification Flags`,factory:()=>CX(e)},{id:`dailyLimits`,label:`Daily Limits`,factory:()=>OX(e)},{id:`defaultTimes`,label:`Default Times`,factory:()=>NX(e)},{id:`averageTimes`,label:`Match Average Times`,factory:()=>BX(e,t)},{id:`recoveryTimes`,label:`Match Recovery Times`,factory:()=>HX(e,t)}],i=[];for(let t of r){let r=document.createElement(`div`);r.className=eX();let a=document.createElement(`div`);a.className=tX();let o=document.createElement(`span`);o.className=nX();let s=document.createElement(`span`);s.textContent=t.label,a.appendChild(o),a.appendChild(s),a.addEventListener(`click`,()=>e.toggleSection(t.id));let c=document.createElement(`div`);c.className=rX();let l=t.factory();c.appendChild(l.element),r.appendChild(a),r.appendChild(c),n.appendChild(r),i.push({id:t.id,chevron:o,bodyEl:c,inner:l})}function a(e){for(let t of i){let n=e.expandedSections.has(t.id);t.chevron.textContent=n?`▼`:`▶`,t.bodyEl.style.display=n?`block`:`none`,n&&t.inner.update(e)}}return{element:n,update:a}}var GX=class e{constructor(e){this.container=null,this.store=new $Y(e),this.panel=WX(this.store,e),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}};function KX(e,t){let n=new GX(e);return n.render(t),n}var qX=ma,JX=(()=>{let e=new Map;for(let t of qX)t.format&&e.set(t.format,t);return e})();function YX(e){if(e)return JX.get(e)}var XX=qX.filter(e=>e.format&&e.name).sort((e,t)=>(e.name??``).localeCompare(t.name??``));function ZX(e){return typeof e==`string`?e:e.matchUpFormat}function QX(e){return(typeof e==`string`?``:e.name??``)||(YX(ZX(e))?.name??``)}function $X(e){return(typeof e==`string`?``:e.description??``)||(YX(ZX(e))?.desc??``)}function eZ(e){return typeof e==`string`?{matchUpFormat:e}:{...e}}var tZ=`SET3-S:6/TB7`;function nZ(){return{defaultMatchUpFormat:tZ,matchUpFormats:[],requireParticipantsForScoring:!1,allowChangePropagation:!1,allowDeletionWithScoresPresent:{drawDefinitions:!1,structures:!1},matchUpStatusCodes:{ABANDONED:[],CANCELLED:[],DEFAULTED:[],INCOMPLETE:[],RETIRED:[],WALKOVER:[]}}}function rZ(e){return structuredClone(e)}var iZ=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:rZ(e.initialPolicy??nZ()),expandedSections:new Set([`defaults`,`allowedFormats`]),expandedStatuses:new Set,advancedOpen:!1,dirty:!1}}isReadonly(){return this.config.readonly===!0}getState(){return this.state}getData(){return rZ(this.state.draft)}setData(e){this.state={...this.state,draft:rZ(e),dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}toggleStatus(e){let t=new Set(this.state.expandedStatuses);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedStatuses:t},this.emit()}setAdvancedOpen(e){this.state.advancedOpen!==e&&(this.state={...this.state,advancedOpen:e},this.emit())}setDefaultMatchUpFormat(e){if(this.isReadonly())return;let t=rZ(this.state.draft);t.defaultMatchUpFormat=e,this.commitDraft(t)}setRequireParticipants(e){if(this.isReadonly())return;let t=rZ(this.state.draft);t.requireParticipantsForScoring=e,this.commitDraft(t)}setRequireAllPositions(e){if(this.isReadonly())return;let t=rZ(this.state.draft);e==="default"?delete t.requireAllPositionsAssigned:t.requireAllPositionsAssigned=e===`true`,this.commitDraft(t)}setAllowChangePropagation(e){if(this.isReadonly())return;let t=rZ(this.state.draft);t.allowChangePropagation=e,this.commitDraft(t)}setAllowDeletionDraws(e){if(this.isReadonly())return;let t=rZ(this.state.draft);t.allowDeletionWithScoresPresent??={},t.allowDeletionWithScoresPresent.drawDefinitions=e,this.commitDraft(t)}setAllowDeletionStructures(e){if(this.isReadonly())return;let t=rZ(this.state.draft);t.allowDeletionWithScoresPresent??={},t.allowDeletionWithScoresPresent.structures=e,this.commitDraft(t)}addAllowedFormat(e){if(this.isReadonly())return;let t=rZ(this.state.draft);t.matchUpFormats??=[];let n={matchUpFormat:``,...e};t.matchUpFormats.push(n),this.commitDraft(t)}removeAllowedFormat(e){if(this.isReadonly())return;let t=rZ(this.state.draft);t.matchUpFormats&&(t.matchUpFormats.splice(e,1),this.commitDraft(t))}setAllowedFormatField(e,t,n){if(this.isReadonly())return;let r=rZ(this.state.draft);if(!r.matchUpFormats?.[e])return;let i=eZ(r.matchUpFormats[e]);t===`name`?i.name=n:t===`description`?i.description=n:i.matchUpFormat=n,i.name===``&&delete i.name,i.description===``&&delete i.description,r.matchUpFormats[e]=i,this.commitDraft(r)}isAllowedFormatDuplicate(e,t){let n=e.trim();return n?(this.state.draft.matchUpFormats??[]).some((e,r)=>r!==t&&ZX(e)===n):!1}addAllowedFormatCategory(e,t,n){if(this.isReadonly())return;let r=n.trim();if(!r)return;let i=rZ(this.state.draft);if(!i.matchUpFormats?.[e])return;let a=eZ(i.matchUpFormats[e]);a[t]??=[],!a[t].includes(r)&&(a[t].push(r),i.matchUpFormats[e]=a,this.commitDraft(i))}removeAllowedFormatCategory(e,t,n){if(this.isReadonly())return;let r=rZ(this.state.draft),i=r.matchUpFormats?.[e];if(!i)return;let a=eZ(i),o=a[t];o&&(o.splice(n,1),o.length===0&&delete a[t],r.matchUpFormats[e]=a,this.commitDraft(r))}addStatusCode(e,t){if(this.isReadonly())return;let n=t.trim();if(!n)return;let r=rZ(this.state.draft);r.matchUpStatusCodes??={},r.matchUpStatusCodes[e]??=[],!r.matchUpStatusCodes[e].includes(n)&&(r.matchUpStatusCodes[e].push(n),this.commitDraft(r))}removeStatusCode(e,t){if(this.isReadonly())return;let n=rZ(this.state.draft),r=n.matchUpStatusCodes?.[e];r&&(r.splice(t,1),this.commitDraft(n))}addProcessCode(e){if(this.isReadonly())return;let t=e.trim();if(!t)return;let n=rZ(this.state.draft);n.processCodes??={},n.processCodes.incompleteAssignmentsOnDefault??=[],!n.processCodes.incompleteAssignmentsOnDefault.includes(t)&&(n.processCodes.incompleteAssignmentsOnDefault.push(t),this.commitDraft(n))}removeProcessCode(e){if(this.isReadonly())return;let t=rZ(this.state.draft),n=t.processCodes?.incompleteAssignmentsOnDefault;n&&(n.splice(e,1),this.commitDraft(t))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(rZ(e))}emit(){for(let e of this.listeners)e(this.state)}},aZ=`__custom__`,oZ=`standard`,sZ=`tiebreak`,cZ=`timed`,lZ=`sc-format-row`,uZ=`sc-format-label`,dZ=`sc-format-select`;function fZ(){return{bestOf:3,setType:oZ,setTo:6,hasTiebreak:!0,tiebreakTo:7,tiebreakAt:`same`,noAd:!1,tbOnlyTo:11,tbOnlyModifier:``,tbOnlyNoAd:!1,minutes:20,timedBasis:`G`,differentFinal:!1,finalKind:`matchTiebreak`,finalSetTo:6,finalTbTo:7,finalMatchTbTo:10}}function pZ(e){let n=fZ(),r=t.matchUpFormatCode.parse?.(e);return r?(typeof r.bestOf==`number`&&(n.bestOf=r.bestOf),r.setFormat&&mZ(n,r.setFormat),r.finalSetFormat&&hZ(n,r.finalSetFormat),n):n}function mZ(e,t){if(t.timed){e.setType=cZ,typeof t.minutes==`number`&&(e.minutes=t.minutes),e.timedBasis=t.based===`P`?`P`:`G`;return}if(t.tiebreakSet){e.setType=sZ,typeof t.tiebreakSet.tiebreakTo==`number`&&(e.tbOnlyTo=t.tiebreakSet.tiebreakTo),e.tbOnlyModifier=t.tiebreakSet.modifier===`RALLY`?`RALLY`:``,e.tbOnlyNoAd=!!t.tiebreakSet.NoAD;return}e.setType=oZ,typeof t.setTo==`number`&&(e.setTo=t.setTo),e.noAd=!!t.NoAD,e.hasTiebreak=!t.noTiebreak&&!!t.tiebreakFormat,t.tiebreakFormat?.tiebreakTo&&(e.tiebreakTo=t.tiebreakFormat.tiebreakTo),typeof t.tiebreakAt==`number`&&t.tiebreakAt!==t.setTo&&(e.tiebreakAt=t.tiebreakAt)}function hZ(e,t){if(e.differentFinal=!0,t.tiebreakSet){e.finalKind=`matchTiebreak`,typeof t.tiebreakSet.tiebreakTo==`number`&&(e.finalMatchTbTo=t.tiebreakSet.tiebreakTo);return}e.finalKind=`standard`,typeof t.setTo==`number`&&(e.finalSetTo=t.setTo),t.tiebreakFormat?.tiebreakTo&&(e.finalTbTo=t.tiebreakFormat.tiebreakTo)}function gZ(e){let t={bestOf:e.bestOf};if(e.setType===cZ)t.setFormat={timed:!0,minutes:e.minutes},e.timedBasis===`P`&&(t.setFormat.based=`P`);else if(e.setType===sZ)t.setFormat={tiebreakSet:{tiebreakTo:e.tbOnlyTo,...e.tbOnlyModifier?{modifier:e.tbOnlyModifier}:{},...e.tbOnlyNoAd?{NoAD:!0}:{}}};else{let n={setTo:e.setTo};e.noAd&&(n.NoAD=!0),e.hasTiebreak?(n.tiebreakFormat={tiebreakTo:e.tiebreakTo},n.tiebreakAt=e.tiebreakAt===`same`?e.setTo:e.tiebreakAt):n.noTiebreak=!0,t.setFormat=n}return e.differentFinal&&(t.finalSetFormat=e.finalKind===`matchTiebreak`?{tiebreakSet:{tiebreakTo:e.finalMatchTbTo}}:{setTo:e.finalSetTo,tiebreakAt:e.finalSetTo,tiebreakFormat:{tiebreakTo:e.finalTbTo}}),t}function _Z(e){try{return t.matchUpFormatCode.stringify?.(e)}catch{return}}function vZ(e){return e?!!t.matchUpFormatCode.parse?.(e):!1}function yZ(e){let t=e.initialValue||`SET3-S:6/TB7`,n=pZ(t),r=document.createElement(`div`);r.className=`sc-format-picker`;let i=document.createElement(`div`);i.className=lZ;let a=document.createElement(`label`);a.textContent=`Preset`,a.className=uZ;let o=document.createElement(`select`);o.className=dZ;for(let e of XX){let t=document.createElement(`option`);t.value=e.format??``,t.textContent=e.desc?`${e.name} — ${e.desc}`:e.name??``,o.appendChild(t)}let s=document.createElement(`option`);s.value=aZ,s.textContent=`Custom…`,o.appendChild(s),i.appendChild(a),i.appendChild(o),r.appendChild(i);let c=document.createElement(`div`);c.className=`sc-format-row sc-format-custom-row`,c.style.display=`none`;let l=document.createElement(`label`);l.textContent=`Format string`,l.className=uZ;let u=document.createElement(`input`);u.type=`text`,u.className=`sc-format-input`,u.placeholder=`e.g. SET3-S:6/TB7-F:TB10`,c.appendChild(l),c.appendChild(u),r.appendChild(c);let d=document.createElement(`button`);d.type=`button`,d.className=`sc-format-builder-toggle`,d.textContent=`▸ Build a custom format`,r.appendChild(d);let f=document.createElement(`div`);f.className=`sc-format-builder-body`,f.style.display=`none`,r.appendChild(f);let p=!1;d.addEventListener(`click`,()=>{p=!p,f.style.display=p?`block`:`none`,d.textContent=p?`▾ Build a custom format`:`▸ Build a custom format`,p&&y()});let m=document.createElement(`div`);m.className=`sc-format-result`;let h=document.createElement(`code`);h.className=`sc-format-chip`;let g=document.createElement(`span`);g.className=`sc-format-validity`,m.appendChild(document.createTextNode(`Result:`)),m.appendChild(h),m.appendChild(g),r.appendChild(m);function _(r,i={}){t=r,i.skipBuilderResync||(n=pZ(r)),v(),p&&y(),e.onChange(r)}function v(){let e=YX(t);e?.format?(o.value=e.format,c.style.display=`none`):(o.value=aZ,c.style.display=``,u.value=t),h.textContent=t;let n=vZ(t);g.textContent=n?`✓ valid`:`✗ invalid`,g.dataset.valid=n?`true`:`false`}o.addEventListener(`change`,()=>{let e=o.value;if(e===aZ){c.style.display=``,u.value=t,u.focus();return}_(e)}),u.addEventListener(`input`,()=>{_(u.value,{skipBuilderResync:!0})});function y(){f.innerHTML=``,f.appendChild(bZ(`Best of`,[1,3,5],n.bestOf,e=>{n.bestOf=e,b()})),f.appendChild(xZ(`Set type`,[{value:oZ,label:`Standard`},{value:sZ,label:`Tiebreak set`},{value:cZ,label:`Timed`}],n.setType,e=>{n.setType=e,b()})),n.setType===oZ?(f.appendChild(bZ(`Games to`,[4,6,8,10],n.setTo,e=>{n.setTo=e,(n.tiebreakAt===`same`||n.tiebreakAt===n.setTo)&&(n.tiebreakAt=`same`),b()})),f.appendChild(SZ(`Tiebreak at set end`,n.hasTiebreak,e=>{n.hasTiebreak=e,b()})),n.hasTiebreak&&f.appendChild(bZ(`Tiebreak first to`,[5,7,10,12,15,21],n.tiebreakTo,e=>{n.tiebreakTo=e,b()})),f.appendChild(SZ(`No-advantage games`,n.noAd,e=>{n.noAd=e,b()}))):n.setType===sZ?(f.appendChild(bZ(`First to`,[7,10,11,15,21],n.tbOnlyTo,e=>{n.tbOnlyTo=e,b()})),f.appendChild(xZ(`Scoring`,[{value:``,label:`Sideout`},{value:`RALLY`,label:`Rally`}],n.tbOnlyModifier,e=>{n.tbOnlyModifier=e,b()})),f.appendChild(SZ(`No-advantage`,n.tbOnlyNoAd,e=>{n.tbOnlyNoAd=e,b()}))):(f.appendChild(bZ(`Minutes`,[10,15,20,25,30,45],n.minutes,e=>{n.minutes=e,b()})),f.appendChild(xZ(`Basis`,[{value:`G`,label:`Games`},{value:`P`,label:`Points`}],n.timedBasis,e=>{n.timedBasis=e,b()}))),f.appendChild(SZ(`Different final-set rules`,n.differentFinal,e=>{n.differentFinal=e,b()})),n.differentFinal&&(f.appendChild(xZ(`Final set`,[{value:`standard`,label:`Standard set`},{value:`matchTiebreak`,label:`Match tiebreak`}],n.finalKind,e=>{n.finalKind=e,b()})),n.finalKind===`standard`?(f.appendChild(bZ(`Final games to`,[4,6,8],n.finalSetTo,e=>{n.finalSetTo=e,b()})),f.appendChild(bZ(`Final tiebreak to`,[7,10,12,15],n.finalTbTo,e=>{n.finalTbTo=e,b()}))):f.appendChild(bZ(`Match tiebreak to`,[7,10,15,21],n.finalMatchTbTo,e=>{n.finalMatchTbTo=e,b()})))}function b(){let e=_Z(gZ(n));typeof e==`string`?_(e,{skipBuilderResync:!0}):y()}return e.readonly&&(o.disabled=!0,u.disabled=!0,d.disabled=!0),v(),{element:r,setValue(e){let r=e||`SET3-S:6/TB7`;r!==t&&(t=r,n=pZ(r),v(),p&&y())},destroy(){r.remove()}}}function bZ(e,t,n,r){let i=document.createElement(`div`);i.className=lZ;let a=document.createElement(`label`);a.textContent=e,a.className=uZ;let o=document.createElement(`select`);o.className=dZ;for(let e of t){let t=document.createElement(`option`);t.value=String(e),t.textContent=String(e),o.appendChild(t)}return o.value=String(n),o.addEventListener(`change`,()=>r(Number(o.value))),i.appendChild(a),i.appendChild(o),i}function xZ(e,t,n,r){let i=document.createElement(`div`);i.className=lZ;let a=document.createElement(`span`);a.textContent=e,a.className=uZ;let o=document.createElement(`div`);o.className=`sc-format-radio-group`;let s=`sc-fmt-radio-${Math.floor(Math.random()*1e9).toString(36)}`;for(let e of t){let t=document.createElement(`label`);t.className=`sc-format-radio-option`;let i=document.createElement(`input`);i.type=`radio`,i.name=s,i.value=e.value,i.checked=e.value===n,i.addEventListener(`change`,()=>{i.checked&&r(i.value)}),t.appendChild(i),t.appendChild(document.createTextNode(e.label)),o.appendChild(t)}return i.appendChild(a),i.appendChild(o),i}function SZ(e,t,n){let r=document.createElement(`div`);r.className=`sc-format-row sc-format-checkbox-row`;let i=document.createElement(`label`);i.className=`sc-format-checkbox-label`;let a=document.createElement(`input`);return a.type=`checkbox`,a.checked=t,a.addEventListener(`change`,()=>n(a.checked)),i.appendChild(a),i.appendChild(document.createTextNode(e)),r.appendChild(i),r}function CZ(e){let t=document.createElement(`div`);t.className=`sc-section-body-inner`;let n=document.createElement(`div`);n.className=`sc-field-block`;let r=document.createElement(`div`);r.className=`sc-field-block-label`,r.textContent=`Default match-up format`;let i=document.createElement(`div`);i.className=`sc-field-help`,i.textContent=`Used when an event or draw does not specify its own format.`,n.appendChild(r),n.appendChild(i);let a=yZ({initialValue:e.getData().defaultMatchUpFormat,readonly:e.isReadonly(),onChange:t=>e.setDefaultMatchUpFormat(t)});n.appendChild(a.element),t.appendChild(n);let o=wZ({label:`Require both participants before scoring`,help:`Block score entry until both sides have a participant assigned.`,initial:!!e.getData().requireParticipantsForScoring,readonly:e.isReadonly(),onChange:t=>e.setRequireParticipants(t)});t.appendChild(o.element);let s=document.createElement(`div`);s.className=`sc-field-row`;let c=document.createElement(`label`);c.className=`sc-field-label`,c.textContent=`Require all positions assigned`;let l=document.createElement(`select`);l.className=`sc-field-input`;for(let e of[{value:`default`,label:`Default (required in MAIN stage)`},{value:`true`,label:`Always required`},{value:`false`,label:`Never required`}]){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,l.appendChild(t)}l.addEventListener(`change`,()=>{e.setRequireAllPositions(l.value)}),e.isReadonly()&&(l.disabled=!0),s.appendChild(c),s.appendChild(l),t.appendChild(s);let u=wZ({label:`Allow change propagation`,help:`Editing a completed matchUp's winningSide updates all downstream matchUps in the structure.`,initial:!!e.getData().allowChangePropagation,readonly:e.isReadonly(),onChange:t=>e.setAllowChangePropagation(t)});t.appendChild(u.element);let d=document.createElement(`div`);d.className=`sc-field-block`;let f=document.createElement(`div`);f.className=`sc-field-block-label`,f.textContent=`Allow deletion with scores present`;let p=document.createElement(`div`);p.className=`sc-field-help`,p.textContent=`When off, the corresponding entity cannot be deleted while it has scored matchUps.`,d.appendChild(f),d.appendChild(p);let m=wZ({label:`Draw definitions`,help:``,initial:!!e.getData().allowDeletionWithScoresPresent?.drawDefinitions,readonly:e.isReadonly(),onChange:t=>e.setAllowDeletionDraws(t)}),h=wZ({label:`Structures`,help:``,initial:!!e.getData().allowDeletionWithScoresPresent?.structures,readonly:e.isReadonly(),onChange:t=>e.setAllowDeletionStructures(t)});d.appendChild(m.element),d.appendChild(h.element),t.appendChild(d);function g(e){let t=e.draft;a.setValue(t.defaultMatchUpFormat||``),o.setChecked(!!t.requireParticipantsForScoring),t.requireAllPositionsAssigned===void 0?l.value=`default`:l.value=t.requireAllPositionsAssigned?`true`:`false`,u.setChecked(!!t.allowChangePropagation),m.setChecked(!!t.allowDeletionWithScoresPresent?.drawDefinitions),h.setChecked(!!t.allowDeletionWithScoresPresent?.structures)}return{element:t,update:g}}function wZ(e){let t=document.createElement(`div`);t.className=`sc-checkbox-row`;let n=document.createElement(`input`);n.type=`checkbox`,n.checked=e.initial,e.readonly&&(n.disabled=!0),n.addEventListener(`change`,()=>e.onChange(n.checked));let r=document.createElement(`div`);r.className=`sc-checkbox-text`;let i=document.createElement(`label`);if(i.textContent=e.label,r.appendChild(i),e.help){let t=document.createElement(`div`);t.className=`sc-checkbox-help`,t.textContent=e.help,r.appendChild(t)}return t.appendChild(n),t.appendChild(r),{element:t,setChecked(e){n.checked=e}}}function TZ(e){let t=document.createElement(`div`);t.className=`sc-taglist`;let n=document.createElement(`div`);n.className=`sc-taglist-chips`,t.appendChild(n);let r=document.createElement(`div`);r.className=`sc-taglist-input-row`;let i=document.createElement(`input`);i.type=`text`,i.className=`sc-taglist-input`,e.placeholder&&(i.placeholder=e.placeholder);let a=document.createElement(`button`);a.type=`button`,a.className=`sp-btn sp-btn--sm sp-btn--outline`,a.textContent=`Add`;let o=document.createElement(`div`);o.className=`sc-taglist-error`,o.style.display=`none`,r.appendChild(i),r.appendChild(a),t.appendChild(r),t.appendChild(o);let s=[...e.values];function c(){if(n.innerHTML=``,s.length===0){let e=document.createElement(`span`);e.className=`sc-taglist-empty`,e.textContent=`none`,n.appendChild(e);return}s.forEach((t,r)=>{let i=document.createElement(`span`);i.className=`sc-taglist-chip`;let a=document.createElement(`code`);if(a.textContent=t,i.appendChild(a),!e.readonly){let n=document.createElement(`button`);n.type=`button`,n.className=`sc-taglist-chip-remove`,n.setAttribute(`aria-label`,`Remove ${t}`),n.textContent=`×`,n.addEventListener(`click`,()=>e.onRemove(r)),i.appendChild(n)}n.appendChild(i)})}function l(){let t=i.value.trim();if(t){if(e.validate&&!e.validate(t)){o.textContent=e.invalidMessage??`Invalid value`,o.style.display=``;return}o.style.display=`none`,i.value=``,e.onAdd(t)}}return a.addEventListener(`click`,l),i.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),l())}),e.readonly&&(i.disabled=!0,a.disabled=!0,r.style.display=`none`),c(),{element:t,setValues(e){s=[...e],c()},destroy(){t.remove()}}}function EZ(e){let t=document.createElement(`div`);t.className=`sc-section-body-inner`;let n=document.createElement(`div`);n.className=`sc-field-help`,n.textContent=`Restrict which formats events under this policy can use. Each entry surfaces in the MatchUp Format Dialog using Name as the dropdown label and Description as the sub-text. Empty list = no restriction.`,t.appendChild(n);let r=document.createElement(`div`);r.className=`sc-format-list-header`,r.appendChild(DZ(``)),r.appendChild(DZ(`Name`)),r.appendChild(DZ(`Format`)),r.appendChild(DZ(`Description`)),r.appendChild(DZ(``)),t.appendChild(r);let i=document.createElement(`div`);i.className=`sc-format-list-rows`,t.appendChild(i);let a=document.createElement(`div`);a.className=`sc-format-list-empty`,a.textContent=`No allowed formats — any format will be accepted.`,t.appendChild(a);let o=document.createElement(`div`);o.className=`sc-format-list-actions`;let s=document.createElement(`button`);s.type=`button`,s.className=`sp-btn sp-btn--sm sp-btn--outline`,s.textContent=`+ Add format`,s.addEventListener(`click`,()=>e.addAllowedFormat());let c=document.createElement(`select`);c.className=`sc-format-list-preset-picker`;let l=document.createElement(`option`);l.value=``,l.textContent=`Add from preset…`,c.appendChild(l);for(let e of XX){let t=document.createElement(`option`);t.value=e.format??``,t.textContent=e.desc?`${e.name} — ${e.desc}`:e.name??``,c.appendChild(t)}c.addEventListener(`change`,()=>{let t=c.value;if(!t)return;let n=XX.find(e=>e.format===t);n?.format&&e.addAllowedFormat({matchUpFormat:n.format,name:n.name,description:n.desc}),c.value=``}),o.appendChild(s),o.appendChild(c),t.appendChild(o),e.isReadonly()&&(s.disabled=!0,c.disabled=!0);let u=[];function d(t){for(a.style.display=t.length===0?``:`none`,r.style.display=t.length===0?`none`:``;u.length>t.length;)u.pop()?.destroy();for(;u.length<t.length;){let t=u.length,n=OZ(e,t);i.appendChild(n.element),u.push(n)}for(let e=0;e<t.length;e+=1)u[e].setIndex(e),u[e].setEntry(t[e])}d(e.getData().matchUpFormats??[]);function f(e){d(e.draft.matchUpFormats??[])}return{element:t,update:f}}function DZ(e){let t=document.createElement(`div`);return t.className=`sc-format-list-header-label`,t.textContent=e,t}function OZ(e,n){let r=n,i=!1,a=e.isReadonly(),o=document.createElement(`div`);o.className=`sc-format-list-row-wrap`;let s=document.createElement(`div`);s.className=`sc-format-list-row`;let c=document.createElement(`button`);c.type=`button`,c.className=`sc-format-list-row-expand`,c.setAttribute(`aria-label`,`Expand advanced fields`),c.textContent=`▸`;let l=AZ(`Display name`,a),u=AZ(`SET3-S:6/TB7`,a);u.classList.add(`sc-format-list-format-input`);let d=AZ(`Description shown beneath the name`,a),f=document.createElement(`span`);f.className=`sc-format-list-validity`;let p=document.createElement(`button`);p.type=`button`,p.className=`sc-format-list-row-remove`,p.setAttribute(`aria-label`,`Remove format`),p.textContent=`×`,a&&(p.disabled=!0),p.addEventListener(`click`,()=>e.removeAllowedFormat(r));let m=document.createElement(`div`);m.className=`sc-format-list-format-cell`,m.appendChild(u),m.appendChild(f),s.appendChild(c),s.appendChild(l),s.appendChild(m),s.appendChild(d),s.appendChild(p);let h=document.createElement(`div`);h.className=`sc-format-list-row-advanced`,h.style.display=`none`;let g=document.createElement(`div`);g.className=`sc-field-help`,g.textContent=`Category filters scope this format to events with matching categoryNames / categoryTypes. Empty = applies to all categories.`,h.appendChild(g);let _=kZ({label:`Category names`,placeholder:`e.g. U18`,initial:[],readonly:a,onAdd:t=>e.addAllowedFormatCategory(r,`categoryNames`,t),onRemove:t=>e.removeAllowedFormatCategory(r,`categoryNames`,t)});h.appendChild(_.element);let v=kZ({label:`Category types`,placeholder:`e.g. AGE`,initial:[],readonly:a,onAdd:t=>e.addAllowedFormatCategory(r,`categoryTypes`,t),onRemove:t=>e.removeAllowedFormatCategory(r,`categoryTypes`,t)});h.appendChild(v.element),o.appendChild(s),o.appendChild(h),c.addEventListener(`click`,()=>{i=!i,c.textContent=i?`▾`:`▸`,h.style.display=i?``:`none`}),l.addEventListener(`input`,()=>e.setAllowedFormatField(r,`name`,l.value)),u.addEventListener(`input`,()=>{e.setAllowedFormatField(r,`matchUpFormat`,u.value),y()}),d.addEventListener(`input`,()=>e.setAllowedFormatField(r,`description`,d.value));function y(){let e=u.value.trim();if(!e){f.textContent=``,f.dataset.state=`empty`;return}t.matchUpFormatCode.parse?.(e)?(f.textContent=`✓`,f.dataset.state=`valid`):(f.textContent=`✗`,f.dataset.state=`invalid`)}return{element:o,setEntry(e){let t=eZ(e),n=QX(e),r=ZX(e),i=$X(e);l.value!==n&&(l.value=n),u.value!==r&&(u.value=r),d.value!==i&&(d.value=i),_.tagList.setValues(t.categoryNames??[]),v.tagList.setValues(t.categoryTypes??[]);let a=(t.categoryNames?.length??0)+(t.categoryTypes?.length??0)>0;c.dataset.hasContent=a?`true`:`false`,y()},setIndex(e){r=e},destroy(){o.remove()}}}function kZ(e){let t=document.createElement(`div`);t.className=`sc-format-list-category-field`;let n=document.createElement(`div`);n.className=`sc-format-list-category-label`,n.textContent=e.label,t.appendChild(n);let r=TZ({values:e.initial,placeholder:e.placeholder,readonly:e.readonly,onAdd:e.onAdd,onRemove:e.onRemove});return t.appendChild(r.element),{element:t,tagList:r}}function AZ(e,t){let n=document.createElement(`input`);return n.type=`text`,n.className=`sc-format-list-input`,n.placeholder=e,t&&(n.disabled=!0),n}var jZ=[`ABANDONED`,`CANCELLED`,`DEFAULTED`,`INCOMPLETE`,`RETIRED`,`WALKOVER`];function MZ(e){let t=document.createElement(`div`);t.className=`sc-section-body-inner`;let n=jZ.map(t=>NZ(e,t));for(let r of n)t.appendChild(PZ(r,()=>e.toggleStatus(r.key)));let r=document.createElement(`div`);r.className=`sc-advanced`;let i=document.createElement(`div`);i.className=`sc-advanced-header`;let a=document.createElement(`span`);a.className=`sc-advanced-chevron`;let o=document.createElement(`span`);o.textContent=`Advanced — process codes`,i.appendChild(a),i.appendChild(o),i.addEventListener(`click`,()=>e.setAdvancedOpen(!e.getState().advancedOpen));let s=document.createElement(`div`);s.className=`sc-advanced-body`,s.style.display=`none`;let c=document.createElement(`div`);c.className=`sc-field-help`,c.textContent=`Tokens passed to downstream governors when assignments are incomplete on default. The factory default ships ["RANKING.IGNORE"].`,s.appendChild(c);let l=TZ({values:e.getData().processCodes?.incompleteAssignmentsOnDefault??[],placeholder:`e.g. RANKING.IGNORE`,readonly:e.isReadonly(),onAdd:t=>e.addProcessCode(t),onRemove:t=>e.removeProcessCode(t)});s.appendChild(l.element),r.appendChild(i),r.appendChild(s),t.appendChild(r);function u(e){for(let t of n){let n=e.draft.matchUpStatusCodes?.[t.key]??[];t.countEl.textContent=String(n.length);let r=e.expandedStatuses.has(t.key);t.chevron.textContent=r?`▾`:`▸`,t.body.style.display=r?`block`:`none`,t.tagList.setValues(n)}a.textContent=e.advancedOpen?`▾`:`▸`,s.style.display=e.advancedOpen?`block`:`none`,l.setValues(e.draft.processCodes?.incompleteAssignmentsOnDefault??[])}return{element:t,update:u}}function NZ(e,t){let n=document.createElement(`span`);n.className=`sc-status-chevron`;let r=document.createElement(`span`);r.className=`sc-status-count`;let i=document.createElement(`div`);i.className=`sc-status-body`;let a=TZ({values:e.getData().matchUpStatusCodes?.[t]??[],placeholder:`e.g. INJURY`,readonly:e.isReadonly(),onAdd:n=>e.addStatusCode(t,n),onRemove:n=>e.removeStatusCode(t,n)});return i.appendChild(a.element),{key:t,chevron:n,countEl:r,body:i,tagList:a}}function PZ(e,t){let n=document.createElement(`div`);n.className=`sc-status-group`;let r=document.createElement(`div`);r.className=`sc-status-header`;let i=document.createElement(`span`);i.className=`sc-status-label`,i.textContent=FZ(e.key),r.appendChild(e.chevron),r.appendChild(i);let a=document.createElement(`span`);return a.className=`sc-status-count-wrap`,a.appendChild(document.createTextNode(`(`)),a.appendChild(e.countEl),a.appendChild(document.createTextNode(`)`)),r.appendChild(a),r.addEventListener(`click`,t),n.appendChild(r),n.appendChild(e.body),n}function FZ(e){return e.charAt(0)+e.slice(1).toLowerCase()}function IZ(e){let t=document.createElement(`div`);t.className=`sc-editor`;let n=[{id:`defaults`,label:`Defaults`,factory:()=>CZ(e)},{id:`allowedFormats`,label:`Allowed match-up formats`,factory:()=>EZ(e)},{id:`statusCodes`,label:`Status code refinements`,factory:()=>MZ(e)}],r=[];for(let i of n){let n=document.createElement(`div`);n.className=`sc-section`;let a=document.createElement(`div`);a.className=`sc-section-header`;let o=document.createElement(`span`);o.className=`sc-section-chevron`;let s=document.createElement(`span`);s.textContent=i.label,a.appendChild(o),a.appendChild(s),a.addEventListener(`click`,()=>e.toggleSection(i.id));let c=document.createElement(`div`);c.className=`sc-section-body`;let l=i.factory();c.appendChild(l.element),n.appendChild(a),n.appendChild(c),t.appendChild(n),r.push({id:i.id,chevron:o,bodyEl:c,inner:l})}function i(e){for(let t of r){let n=e.expandedSections.has(t.id);t.chevron.textContent=n?`▾`:`▸`,t.bodyEl.style.display=n?`block`:`none`,n&&t.inner.update(e)}}return{element:t,update:i}}var LZ=class e{constructor(e){this.container=null,this.store=new iZ(e),this.panel=IZ(this.store),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,readonly:t.readonly,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}},RZ=[{value:`SEPARATE`,label:`Separate`,description:`Each seed placed in its own section of the draw`},{value:`WATERFALL`,label:`Waterfall`,description:`Seeds cascade down section by section`},{value:`CLUSTER`,label:`Cluster`,description:`Seeds grouped in clusters (e.g. 5-8 together)`}],zZ=[`SINGLE_ELIMINATION`,`DOUBLE_ELIMINATION`,`ROUND_ROBIN`,`ROUND_ROBIN_WITH_PLAYOFF`,`FEED_IN`,`FEED_IN_CHAMPIONSHIP`,`FEED_IN_CHAMPIONSHIP_TO_SF`,`FEED_IN_CHAMPIONSHIP_TO_QF`,`FEED_IN_CHAMPIONSHIP_TO_R16`,`FIRST_MATCH_LOSER_CONSOLATION`,`CURTIS_CONSOLATION`,`COMPASS`,`OLYMPIC`];function BZ(){return{policyName:``,seedingProfile:{positioning:`SEPARATE`},validSeedPositions:{ignore:!0},duplicateSeedNumbers:!0,drawSizeProgression:!0,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}]}}function VZ(e){return structuredClone(e)}var HZ=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:VZ(e.initialPolicy??BZ()),expandedSections:new Set([`profile`,`flags`,`thresholds`,`drawTypeOverrides`]),dirty:!1}}getState(){return this.state}getData(){return VZ(this.state.draft)}setData(e){this.state={...this.state,draft:VZ(e),dirty:!1},this.emit()}toggleSection(e){let t=new Set(this.state.expandedSections);t.has(e)?t.delete(e):t.add(e),this.state={...this.state,expandedSections:t},this.emit()}setPolicyName(e){let t=VZ(this.state.draft);t.policyName=e,this.commitDraft(t)}setPositioning(e){let t=VZ(this.state.draft);t.seedingProfile??={},t.seedingProfile.positioning=e,this.commitDraft(t)}setValidSeedPositionsIgnore(e){let t=VZ(this.state.draft);t.validSeedPositions={ignore:e},this.commitDraft(t)}setDuplicateSeedNumbers(e){let t=VZ(this.state.draft);t.duplicateSeedNumbers=e,this.commitDraft(t)}setDrawSizeProgression(e){let t=VZ(this.state.draft);t.drawSizeProgression=e,this.commitDraft(t)}addThreshold(){let e=VZ(this.state.draft);e.seedsCountThresholds??=[];let t=e.seedsCountThresholds.at(-1),n=t?t.drawSize*2:4;e.seedsCountThresholds.push({drawSize:n,minimumParticipantCount:Math.max(1,Math.floor(n*.75)),seedsCount:Math.max(2,Math.floor(n/4))}),this.commitDraft(e)}removeThreshold(e){let t=VZ(this.state.draft);t.seedsCountThresholds&&(t.seedsCountThresholds.splice(e,1),this.commitDraft(t))}setThresholdField(e,t,n){let r=VZ(this.state.draft),i=r.seedsCountThresholds?.[e];i&&(i[t]=n,this.commitDraft(r))}sortThresholds(){let e=VZ(this.state.draft);e.seedsCountThresholds&&(e.seedsCountThresholds.sort((e,t)=>e.drawSize-t.drawSize),this.commitDraft(e))}addDrawTypeOverride(e,t){if(!e)return;let n=VZ(this.state.draft);n.seedingProfile??={},n.seedingProfile.drawTypes??={},n.seedingProfile.drawTypes[e]={positioning:t},this.commitDraft(n)}removeDrawTypeOverride(e){let t=VZ(this.state.draft);t.seedingProfile?.drawTypes&&(delete t.seedingProfile.drawTypes[e],Object.keys(t.seedingProfile.drawTypes).length===0&&delete t.seedingProfile.drawTypes,this.commitDraft(t))}setDrawTypeOverridePositioning(e,t){let n=VZ(this.state.draft),r=n.seedingProfile?.drawTypes;r?.[e]&&(r[e]={positioning:t},this.commitDraft(n))}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(VZ(e))}emit(){for(let e of this.listeners)e(this.state)}},UZ=()=>`sd-editor`,WZ=()=>`sd-section`,GZ=()=>`sd-section-header`,KZ=()=>`sd-section-chevron`,qZ=()=>`sd-section-body`,JZ=()=>`sd-field-row`,YZ=()=>`sd-field-label`,XZ=()=>`sd-field-input`,ZZ=()=>`sd-checkbox-row`,QZ=()=>`sd-checkbox-desc`,$Z=()=>`sd-radio-group`,eQ=()=>`sd-radio-option`,tQ=()=>`sp-btn sp-btn--sm sp-btn--outline sd-add-btn`,nQ=()=>`sp-btn sp-btn--sm sp-btn--ghost sd-sort-btn`,rQ=()=>`sp-btn-icon sp-btn-icon--danger sd-remove-btn`,iQ=()=>`sd-table-wrap`,aQ=()=>`sd-table`,oQ=()=>`sd-number-cell-input`,sQ=()=>`sd-empty`,cQ=()=>`sd-actions-row`,lQ=()=>`sd-override-row`,uQ=()=>`sd-override-add-row`,dQ=()=>`sd-override-drawtype`,fQ=()=>`sd-select`;function pQ(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=JZ();let r=document.createElement(`div`);r.className=YZ(),r.textContent=`Policy name`;let i=document.createElement(`input`);i.type=`text`,i.className=XZ()+` sd-field-input--wide`,i.placeholder=`e.g. USTA SEEDING`,i.addEventListener(`input`,()=>e.setPolicyName(i.value)),n.appendChild(r),n.appendChild(i),t.appendChild(n);let a=document.createElement(`div`);a.className=JZ()+` sd-field-row--top`;let o=document.createElement(`div`);o.className=YZ(),o.textContent=`Default positioning`,a.appendChild(o);let s=document.createElement(`div`);s.className=$Z();let c=[];for(let t of RZ){let n=document.createElement(`label`);n.className=eQ();let r=document.createElement(`input`);r.type=`radio`,r.name=`sd-positioning`,r.value=t.value,r.addEventListener(`change`,()=>{r.checked&&e.setPositioning(t.value)});let i=document.createElement(`span`);i.innerHTML=`<strong>${t.label}</strong><div class="sd-radio-desc">${t.description}</div>`,n.appendChild(r),n.appendChild(i),s.appendChild(n),c.push({value:t.value,input:r})}a.appendChild(s),t.appendChild(a);function l(e){document.activeElement!==i&&(i.value=e.draft.policyName??``);let t=e.draft.seedingProfile?.positioning;for(let e of c)e.input.checked=e.value===t}return{element:t,update:l}}function mQ(e){let t=document.createElement(`div`),n=[{id:`sd-valid-seed-positions-ignore`,label:`Ignore valid seed positions`,description:`Allow seeds to be placed at any drawPosition (rather than only canonical seeded positions).`,read:e=>e.draft.validSeedPositions?.ignore??!1,write:t=>e.setValidSeedPositionsIgnore(t)},{id:`sd-duplicate-seed-numbers`,label:`Allow duplicate seed numbers`,description:`Permit shared seed numbers (e.g. multiple #5 seeds in CLUSTER positioning).`,read:e=>e.draft.duplicateSeedNumbers??!1,write:t=>e.setDuplicateSeedNumbers(t)},{id:`sd-draw-size-progression`,label:`Draw size progression`,description:`Apply thresholds at or below the matched draw size, instead of requiring an exact match.`,read:e=>e.draft.drawSizeProgression??!1,write:t=>e.setDrawSizeProgression(t)}],r=[];for(let e of n){let n=document.createElement(`div`);n.className=ZZ();let i=document.createElement(`input`);i.type=`checkbox`,i.id=e.id,i.addEventListener(`change`,()=>e.write(i.checked));let a=document.createElement(`label`);a.htmlFor=e.id,a.textContent=e.label;let o=document.createElement(`div`);o.className=QZ(),o.textContent=e.description;let s=document.createElement(`div`);s.appendChild(a),s.appendChild(o),n.appendChild(i),n.appendChild(s),t.appendChild(n),r.push({def:e,input:i})}function i(e){for(let t of r)t.input.checked=t.def.read(e)}return{element:t,update:i}}var hQ=[{field:`drawSize`,label:`Draw size`,min:2,placeholder:`32`},{field:`minimumParticipantCount`,label:`Min participants`,min:0,placeholder:`24`},{field:`seedsCount`,label:`Seeds`,min:0,placeholder:`8`}];function gQ(e){let t=document.createElement(`div`),n=document.createElement(`div`);n.className=iQ();let r=document.createElement(`table`);r.className=aQ();let i=document.createElement(`thead`),a=document.createElement(`tr`);for(let e of hQ){let t=document.createElement(`th`);t.textContent=e.label,a.appendChild(t)}let o=document.createElement(`th`);o.setAttribute(`aria-label`,`Actions`),a.appendChild(o),i.appendChild(a),r.appendChild(i);let s=document.createElement(`tbody`);r.appendChild(s),n.appendChild(r),t.appendChild(n);let c=document.createElement(`div`);c.className=sQ(),c.textContent=`No seed-count thresholds defined. Add a row to configure seeds per draw size.`,t.appendChild(c);let l=document.createElement(`div`);l.className=cQ();let u=document.createElement(`button`);u.type=`button`,u.className=tQ(),u.textContent=`+ Add threshold`,u.addEventListener(`click`,()=>e.addThreshold());let d=document.createElement(`button`);d.type=`button`,d.className=nQ(),d.textContent=`Sort by draw size`,d.addEventListener(`click`,()=>e.sortThresholds()),l.appendChild(u),l.appendChild(d),t.appendChild(l);function f(t){let n=t.draft.seedsCountThresholds??[];if(s.innerHTML=``,n.length===0){r.style.display=`none`,c.style.display=`block`,d.disabled=!0;return}r.style.display=``,c.style.display=`none`,d.disabled=n.length<2;for(let t=0;t<n.length;t++){let r=n[t],i=document.createElement(`tr`);for(let n of hQ){let a=document.createElement(`td`),o=document.createElement(`input`);o.type=`number`,o.min=String(n.min),o.className=oQ(),o.value=String(r[n.field]),n.placeholder&&(o.placeholder=n.placeholder);let s=t,c=n.field;o.addEventListener(`change`,()=>{let t=parseInt(o.value,10);!isNaN(t)&&t>=n.min?e.setThresholdField(s,c,t):o.value=String(r[n.field])}),a.appendChild(o),i.appendChild(a)}let a=document.createElement(`td`),o=document.createElement(`button`);o.type=`button`,o.className=rQ(),o.setAttribute(`aria-label`,`Remove threshold row ${t+1}`),o.textContent=`×`;let c=t;o.addEventListener(`click`,()=>e.removeThreshold(c)),a.appendChild(o),i.appendChild(a),s.appendChild(i)}}return{element:t,update:f}}function _Q(e,t){let n=document.createElement(`select`);n.className=fQ();for(let e of RZ){let t=document.createElement(`option`);t.value=e.value,t.textContent=e.label,n.appendChild(t)}return n.value=e,n.addEventListener(`change`,()=>t(n.value)),n}function vQ(e,t){let n=document.createElement(`div`),r=t.drawTypes??zZ,i=document.createElement(`div`);n.appendChild(i);let a=document.createElement(`div`);a.className=sQ(),a.textContent=`No draw-type overrides. The default positioning is used for every drawType.`,n.appendChild(a);let o=document.createElement(`div`);o.className=uQ();let s=document.createElement(`select`);s.className=fQ();function c(e){s.innerHTML=``;let t=document.createElement(`option`);t.value=``,t.textContent=`Select drawType…`,s.appendChild(t);for(let t of r){if(e.has(t))continue;let n=document.createElement(`option`);n.value=t,n.textContent=t,s.appendChild(n)}}let l=_Q(`WATERFALL`,()=>{}),u=document.createElement(`button`);u.type=`button`,u.className=tQ(),u.textContent=`+ Add override`,u.addEventListener(`click`,()=>{let t=s.value;t&&e.addDrawTypeOverride(t,l.value)});let d=document.createElement(`div`);d.className=cQ(),d.appendChild(s),d.appendChild(l),d.appendChild(u),o.appendChild(d),n.appendChild(o);function f(t){let n=t.draft.seedingProfile?.drawTypes??{},r=Object.entries(n);if(i.innerHTML=``,r.length===0)a.style.display=`block`;else{a.style.display=`none`;for(let[t,{positioning:n}]of r){let r=document.createElement(`div`);r.className=lQ();let a=document.createElement(`div`);a.className=dQ(),a.textContent=t;let o=_Q(n,n=>e.setDrawTypeOverridePositioning(t,n)),s=document.createElement(`button`);s.type=`button`,s.className=rQ(),s.setAttribute(`aria-label`,`Remove override for ${t}`),s.textContent=`×`,s.addEventListener(`click`,()=>e.removeDrawTypeOverride(t)),r.appendChild(a),r.appendChild(o),r.appendChild(s),i.appendChild(r)}}c(new Set(Object.keys(n))),u.disabled=s.options.length<=1}return{element:n,update:f}}function yQ(e,t){let n=document.createElement(`div`);n.className=UZ();let r=[{id:`profile`,label:`Profile`,factory:()=>pQ(e)},{id:`flags`,label:`Flags`,factory:()=>mQ(e)},{id:`thresholds`,label:`Seed Count Thresholds`,factory:()=>gQ(e)},{id:`drawTypeOverrides`,label:`Draw Type Overrides`,factory:()=>vQ(e,t)}],i=[];for(let t of r){let r=document.createElement(`div`);r.className=WZ();let a=document.createElement(`div`);a.className=GZ();let o=document.createElement(`span`);o.className=KZ();let s=document.createElement(`span`);s.textContent=t.label,a.appendChild(o),a.appendChild(s),a.addEventListener(`click`,()=>e.toggleSection(t.id));let c=document.createElement(`div`);c.className=qZ();let l=t.factory();c.appendChild(l.element),r.appendChild(a),r.appendChild(c),n.appendChild(r),i.push({id:t.id,chevron:o,bodyEl:c,inner:l})}function a(e){for(let t of i){let n=e.expandedSections.has(t.id);t.chevron.textContent=n?`▼`:`▶`,t.bodyEl.style.display=n?`block`:`none`,n&&t.inner.update(e)}}return{element:n,update:a}}var bQ=class e{constructor(e){this.container=null,this.store=new HZ(e),this.panel=yQ(this.store,e),this.unsubscribe=this.store.subscribe(e=>{this.panel.update(e)}),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}},xQ=t.factoryConstants.policyConstants.POLICY_TYPE_PARTICIPANT;function SQ(e){return structuredClone(e)}function CQ(){return SQ(t.fixtures.policies.POLICY_PRIVACY_DEFAULT[xQ])}function wQ(e){return e?.participant??{}}function TQ(e){let t=e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1)}function EQ(){let e=wQ(CQ()),t=Object.keys(e).filter(t=>typeof e[t]==`boolean`).map(e=>({field:e,group:`participant`,label:TQ(e)})),n=Object.keys(e.person??{}).filter(t=>typeof e.person[t]==`boolean`).map(e=>({field:e,group:`person`,label:TQ(e)}));return[...t,...n]}function DQ(e,t,n){let r=wQ(e);return t===`person`?!!r.person?.[n]:!!r[n]}function OQ(e,t,n,r){let i=wQ(e),a=(e,t)=>{e&&n in e&&(e[n]=r),t&&n in t&&(t[n]=r)};t===`person`?a(i.person,i.individualParticipants?.person):a(i,i.individualParticipants)}function kQ(e){return e?.policyName??``}function AQ(e,t){e&&(e.policyName=t)}function jQ(e){return structuredClone(e)}var MQ=class{constructor(e){this.listeners=new Set,this.config=e,this.state={draft:jQ(e.initialPolicy??CQ()),dirty:!1}}getState(){return this.state}getData(){return jQ(this.state.draft)}setData(e){this.state={...this.state,draft:jQ(e),dirty:!1},this.emit()}setPolicyName(e){let t=jQ(this.state.draft);AQ(t,e),this.commitDraft(t)}setField(e,t,n){let r=jQ(this.state.draft);OQ(r,e,t,n),this.commitDraft(r)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}commitDraft(e){this.state={...this.state,draft:e,dirty:!0},this.emit(),this.config.onChange?.(jQ(e))}emit(){for(let e of this.listeners)e(this.state)}};function NQ(e,t){let n=document.createElement(`div`);n.className=`privacy-editor`;let r=document.createElement(`p`);r.className=`privacy-editor__intro`,r.textContent=`Choose which participant details are published publicly. Unchecked = kept private.`,n.appendChild(r);let i=document.createElement(`label`);i.className=`privacy-editor__name`;let a=document.createElement(`span`);a.textContent=`Policy name`;let o=document.createElement(`input`);o.type=`text`,o.placeholder=`e.g. Public roster privacy`,o.addEventListener(`input`,()=>e.setPolicyName(o.value)),i.append(a,o),n.appendChild(i);let s=EQ(),c=new Map,l=(t,r)=>{let i=document.createElement(`section`);i.className=`privacy-editor__group`;let a=document.createElement(`h4`);a.textContent=r,i.appendChild(a);let o=document.createElement(`div`);o.className=`privacy-editor__grid`;for(let n of s.filter(e=>e.group===t)){let r=document.createElement(`label`);r.className=`privacy-editor__toggle`;let i=document.createElement(`input`);i.type=`checkbox`,i.addEventListener(`change`,()=>e.setField(t,n.field,i.checked));let a=document.createElement(`span`);a.textContent=n.label,r.append(i,a),o.appendChild(r),c.set(`${t}.${n.field}`,i)}i.appendChild(o),n.appendChild(i)};return l(`person`,`Person details`),l(`participant`,`Participant details`),{element:n,update:e=>{o.value=kQ(e.draft);for(let t of s){let n=c.get(`${t.group}.${t.field}`);n&&(n.checked=DQ(e.draft,t.group,t.field))}}}}var PQ=class e{constructor(e){this.container=null,this.store=new MQ(e),this.panel=NQ(this.store,e),this.unsubscribe=this.store.subscribe(e=>this.panel.update(e)),this.panel.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.panel.element)}destroy(){this.unsubscribe(),this.container&&this.panel.element.parentNode===this.container&&this.container.removeChild(this.panel.element),this.container=null}getData(){return this.store.getData()}setData(e){this.store.setData(e)}getStore(){return this.store}static createEditorInstance(t){let n={initialPolicy:t.initialData,onChange:e=>t.onChange(e)},r=new e(n);return{element:r.panel.element,setData(e){r.setData(e)},getData(){return r.getData()},destroy(){r.destroy()}}}},FQ=()=>`pc-layout`,IQ=()=>`pc-panel`,LQ=()=>`pc-panel-header`,RQ=()=>`pc-panel-title`,zQ=()=>`pc-panel-meta`,BQ=()=>`pc-toolbar`,VQ=()=>`pc-input`,HQ=()=>`pc-select`,UQ=()=>`pc-catalog`,WQ=()=>`pc-group`,GQ=()=>`pc-group-header`,KQ=()=>`pc-group-chevron`,qQ=()=>`pc-group-body`,JQ=()=>`pc-card`,YQ=()=>`pc-card-title`,XQ=()=>`pc-card-meta`,ZQ=()=>`pc-type-badge`,QQ=()=>`pc-editor`,$Q=()=>`pc-editor-header`,e$=()=>`pc-editor-header-left`,t$=()=>`pc-editor-actions`,n$=()=>`sp-btn sp-btn--sm`,r$=()=>`sp-btn sp-btn--sm sp-btn--accent`,i$=()=>`pc-dirty-dot`,a$=()=>`pc-editor-body`,o$=()=>`pc-empty`,s$=()=>`pc-json-editor`,c$=()=>`pc-json-error`;function l$(e){let t=document.createElement(`div`);t.className=FQ(),t.appendChild(e.catalogPanel.element),t.appendChild(e.editorShell.element);function n(t){e.catalogPanel.update(t),e.editorShell.update(t)}return{element:t,update:n}}var u$=`scheduling`,d$=`scoring`,f$=`seeding`,p$=`draws`,m$=`avoidance`,h$=`feedIn`,g$=`progression`,_$=`roundNaming`,v$=`positionActions`,y$=`matchUpActions`,b$=`roundRobinTally`,x$=`rankingPoints`,S$=`competitiveBands`,C$=`voluntaryConsolation`,w$=`participant`,T$=`display`,E$=`audit`,D$=`Tournament Operations`,O$=`Scoring & Results`,k$=`Ranking Points`,A$=`Draw Configuration`,j$=`Participants`,M$=`Display & Audit`,N$=(e,t,n,r,i)=>({policyType:e,label:t,description:n,group:r,hasEditor:i}),P$=[N$(u$,`Scheduling`,`Match scheduling, average times, recovery times, daily limits`,D$,!0),N$(v$,`Position Actions`,`Allowed position actions (alternates, walkovers, withdrawals)`,D$,!1),N$(y$,`MatchUp Actions`,`Allowed matchUp status transitions and actions`,D$,!1),N$(m$,`Avoidance`,`Draw placement avoidance rules (club, nationality, region)`,D$,!1),N$(d$,`Scoring`,`Score entry validation and completion rules`,O$,!0),N$(b$,`Round Robin Tally`,`Round-robin group standing calculation method`,O$,!1),N$(x$,`Ranking Points`,`Point allocation by draw size, round, and result`,k$,!0),N$(S$,`Competitive Bands`,`Rating/ranking band definitions for competitive grouping`,O$,!1),N$(p$,`Draws`,`Draw generation rules and structure options`,A$,!1),N$(f$,`Seeding`,`Seeding thresholds and placement rules by draw size`,A$,!0),N$(h$,`Feed-In`,`Feed-in consolation structure rules`,A$,!1),N$(g$,`Progression`,`Player progression between draw structures`,A$,!1),N$(C$,`Voluntary Consolation`,`Voluntary consolation entry rules`,A$,!1),N$(_$,`Round Naming`,`Custom round name labels (QF, SF, F, etc.)`,A$,!1),N$(w$,`Participant Privacy`,`Which participant details are published publicly`,j$,!0),N$(T$,`Display`,`Client display configuration (public vs admin views)`,M$,!1),N$(E$,`Audit`,`Audit trail and change logging configuration`,M$,!1)];function F$(e){return P$.find(t=>t.policyType===e)}function I$(e){return e===`rankingPoints`?zJ():e===`scheduling`?ZY():e===`scoring`?nZ():e===`seeding`?BZ():e===`participant`?CQ():{}}var L$=[D$,O$,k$,A$,j$,M$];function R$(e,t){let n=t.toLowerCase().trim();return n?e.filter(e=>{let t=F$(e.policyType);return[e.name,e.description,e.policyType,t?.label??``,e.source].join(` `).toLowerCase().includes(n)}):e}function z$(e,t){let n=new Map;if(t===`type`){for(let e of L$)n.set(e,[]);for(let t of e){let e=F$(t.policyType)?.group??`Display & Audit`,r=n.get(e);r?r.push(t):n.set(e,[t])}for(let[e,t]of n)t.length===0&&n.delete(e)}else for(let t of e){let e=t.source===`builtin`?`Built-in Policies`:`User Policies`,r=n.get(e);r?r.push(t):n.set(e,[t])}return n}function B$(e){let t=document.createElement(`div`);t.className=IQ(),t.style.overflowY=`auto`,t.style.scrollbarWidth=`thin`,t.style.scrollbarColor=`var(--sp-scrollbar) transparent`;let n=new Set,r=null,i=document.createElement(`div`);i.className=LQ();let a=document.createElement(`div`);a.className=RQ(),a.textContent=`Policy Catalog`;let o=document.createElement(`div`);o.className=zQ(),i.appendChild(a),i.appendChild(o),t.appendChild(i);let s=document.createElement(`div`);s.className=BQ();let c=document.createElement(`input`);c.type=`text`,c.placeholder=`Search policies...`,c.className=VQ(),c.addEventListener(`input`,()=>e.onSearchChange(c.value));let l=document.createElement(`select`);l.className=HQ();for(let[e,t]of[[`type`,`By Type`],[`source`,`By Source`]]){let n=document.createElement(`option`);n.value=e,n.textContent=t,l.appendChild(n)}l.addEventListener(`change`,()=>e.onGroupByChange(l.value));let u=document.createElement(`div`);u.style.cssText=`position:relative;flex-shrink:0`;let d=document.createElement(`button`);d.className=`sp-btn-icon`,d.textContent=`+`,d.title=`New policy`,d.style.cssText=`font-size:1rem;font-weight:700`;let f=document.createElement(`div`);f.style.cssText=`display:none;position:absolute;top:100%;right:0;z-index:100;min-width:180px;background:var(--sp-panel-bg);border:1px solid var(--sp-border);border-radius:12px;box-shadow:var(--sp-panel-shadow);padding:4px;margin-top:4px`;let p=P$.filter(e=>e.hasEditor);for(let t of p){let n=document.createElement(`div`);n.style.cssText=`padding:6px 10px;font-size:12px;border-radius:8px;cursor:pointer;color:var(--sp-text)`,n.textContent=t.label,n.addEventListener(`mouseenter`,()=>{n.style.background=`var(--sp-hover-bg)`}),n.addEventListener(`mouseleave`,()=>{n.style.background=``}),n.addEventListener(`click`,n=>{n.stopPropagation(),f.style.display=`none`,e.onNewPolicy?.(t.policyType)}),f.appendChild(n)}d.addEventListener(`click`,e=>{e.stopPropagation(),f.style.display=f.style.display===`none`?`block`:`none`}),document.addEventListener(`click`,()=>{f.style.display=`none`}),u.appendChild(d),u.appendChild(f),s.appendChild(c),s.appendChild(l),s.appendChild(u),t.appendChild(s);let m=document.createElement(`div`);m.className=UQ(),t.appendChild(m);function h(t){r=t;let i=R$(t.catalog,t.searchQuery),a=z$(i,t.groupBy);o.textContent=`${i.length} policies`,c.value!==t.searchQuery&&(c.value=t.searchQuery),l.value!==t.groupBy&&(l.value=t.groupBy),m.innerHTML=``;for(let[i,o]of a){let a=document.createElement(`div`);a.className=WQ();let s=n.has(i),c=document.createElement(`div`);c.className=GQ();let l=document.createElement(`span`);l.className=KQ(),l.textContent=s?`▶`:`▼`;let u=document.createElement(`span`);u.textContent=`${i} (${o.length})`,c.appendChild(l),c.appendChild(u),c.addEventListener(`click`,()=>{n.has(i)?n.delete(i):n.add(i),r&&h(r)});let d=document.createElement(`div`);d.className=qQ(),s&&(d.style.display=`none`);for(let n of o){let r=document.createElement(`div`);r.className=JQ(),n.id===t.selectedId&&r.classList.add(`active`),r.addEventListener(`click`,()=>e.onSelectPolicy(n.id));let i=document.createElement(`div`);i.style.cssText=`display:flex;align-items:center;gap:4px`;let a=document.createElement(`div`);if(a.className=YQ(),a.style.flex=`1`,a.textContent=n.name,i.appendChild(a),e.onDuplicatePolicy){let t=document.createElement(`span`);t.style.cssText=`font-size:10px;cursor:pointer;color:var(--sp-muted);padding:2px`,t.textContent=`⎘`,t.title=`Duplicate`,t.addEventListener(`click`,t=>{t.stopPropagation(),e.onDuplicatePolicy?.(n.id)}),i.appendChild(t)}if(n.source===`user`&&e.onDeletePolicy){let t=document.createElement(`span`);t.style.cssText=`font-size:10px;cursor:pointer;color:var(--sp-muted);padding:2px`,t.textContent=`✕`,t.title=`Delete`,t.addEventListener(`click`,t=>{t.stopPropagation(),e.onDeletePolicy?.(n.id)}),i.appendChild(t)}r.appendChild(i);let o=document.createElement(`div`);o.className=XQ();let s=F$(n.policyType),c=document.createElement(`span`);c.className=ZQ(),c.textContent=s?.label??n.policyType;let l=document.createElement(`span`);l.className=`${ZQ()} ${n.source}`,l.textContent=n.source,o.appendChild(c),o.appendChild(l),r.appendChild(o),d.appendChild(r)}a.appendChild(c),a.appendChild(d),m.appendChild(a)}}return{element:t,update:h}}function V$(e){return structuredClone(e)}var H$=class{constructor(e){this.listeners=new Set,this.localIdCounter=0,this.config=e;let t=new Set((e.builtinPolicies??[]).map(e=>e.id)),n=[...e.builtinPolicies??[],...(e.userPolicies??[]).filter(e=>!t.has(e.id))];this.state={catalog:n,searchQuery:``,groupBy:`type`,selectedId:null,editorDraft:null,editedName:null,dirty:!1}}getState(){return this.state}getSelectedItem(){return this.state.selectedId?this.state.catalog.find(e=>e.id===this.state.selectedId)??null:null}setCatalogSearch(e){this.setState({searchQuery:e})}setCatalogGroupBy(e){this.setState({groupBy:e})}selectPolicy(e){if(this.state.selectedId===e)return;let t=this.state.catalog.find(t=>t.id===e);t&&(this.setState({selectedId:e,editorDraft:V$(t.policyData),editedName:t.name,dirty:!1}),this.config.onSelectionChanged?.(t))}clearSelection(){this.state.selectedId&&(this.setState({selectedId:null,editorDraft:null,editedName:null,dirty:!1}),this.config.onSelectionChanged?.(null))}renamePolicy(e){if(!this.state.selectedId)return;let t=this.getSelectedItem();!t||t.source===`builtin`||this.state.editedName!==e&&this.setState({editedName:e,dirty:!0})}updateEditorDraft(e){this.setState({editorDraft:e,dirty:!0})}markDirty(){this.state.dirty||this.setState({dirty:!0})}markClean(){this.state.dirty&&this.setState({dirty:!1})}savePolicy(){let e=this.getSelectedItem();if(!e||!this.state.editorDraft)return;let t={...e,name:this.state.editedName??e.name,policyData:V$(this.state.editorDraft)},n=this.state.catalog.map(e=>e.id===t.id?t:e);this.state={...this.state,catalog:n,dirty:!1},this.emit(),this.config.onPolicySaved?.(t)}resetDraft(){let e=this.getSelectedItem();e&&this.setState({editorDraft:V$(e.policyData),editedName:e.name,dirty:!1})}applyPolicy(){let e=this.getSelectedItem();if(!e)return;let t={...e,policyData:this.state.editorDraft?V$(this.state.editorDraft):V$(e.policyData)};this.config.onPolicyApplied?.(t)}addNewPolicy(e){let t=this.nextLocalId(e),n={id:t,name:`New ${e} policy`,policyType:e,source:`user`,description:``,policyData:I$(e)};return this.appendAndSelect(n),this.runCreateAndReconcile(n),t}duplicatePolicy(e){let t=this.state.catalog.find(t=>t.id===e);if(!t)return null;let n=this.nextLocalId(t.policyType),r={id:n,name:`${t.name} (Copy)`,policyType:t.policyType,source:`user`,description:t.description,policyData:V$(t.policyData)};return this.appendAndSelect(r),this.runCreateAndReconcile(r),n}reconcilePolicyId(e,t){if(e===t||this.state.catalog.findIndex(t=>t.id===e)===-1)return;let n=this.state.catalog.map(n=>n.id===e?{...n,id:t}:n),r=this.state.selectedId===e;this.state={...this.state,catalog:n,...r?{selectedId:t}:{}},this.emit()}deletePolicy(e){let t=this.state.catalog.find(t=>t.id===e);if(!t||t.source===`builtin`)return;let n=this.state.catalog.filter(t=>t.id!==e),r=this.state.selectedId===e;this.state={...this.state,catalog:n,...r?{selectedId:null,editorDraft:null,dirty:!1}:{}},this.emit(),this.config.onPolicyDeleted?.(e),r&&this.config.onSelectionChanged?.(null)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setState(e){this.state={...this.state,...e},this.emit()}emit(){for(let e of this.listeners)e(this.state)}nextLocalId(e){return this.localIdCounter+=1,`user-${e}-${Date.now()}-${this.localIdCounter}`}appendAndSelect(e){let t=[...this.state.catalog,e];this.state={...this.state,catalog:t,selectedId:e.id,editorDraft:V$(e.policyData),editedName:e.name,dirty:!1},this.emit(),this.config.onSelectionChanged?.(e)}runCreateAndReconcile(e){let t=this.config.onPolicyCreated?.(e);if(t!==void 0){if(typeof t==`string`){this.reconcilePolicyId(e.id,t);return}Promise.resolve(t).then(t=>{typeof t==`string`&&this.reconcilePolicyId(e.id,t)}).catch(()=>{})}}};function U$(e){let t=document.createElement(`div`);t.className=IQ();let n=document.createElement(`div`);n.className=QQ();let r=document.createElement(`div`);r.className=$Q();let i=document.createElement(`div`);i.className=e$();let a=document.createElement(`div`);a.className=RQ();let o=document.createElement(`input`);o.type=`text`,o.className=`${RQ()} pc-name-input`,o.setAttribute(`aria-label`,`Policy name`),o.setAttribute(`data-testid`,`pc-name-input`),o.placeholder=`Policy name`,o.addEventListener(`input`,()=>e.onRename(o.value));let s=document.createElement(`span`);s.className=ZQ();let c=document.createElement(`span`);c.className=ZQ(),c.textContent=`read-only`,c.style.display=`none`;let l=document.createElement(`div`);l.className=i$(),l.style.display=`none`,l.title=`Unsaved changes`,i.appendChild(l),i.appendChild(a),i.appendChild(o),i.appendChild(s),i.appendChild(c);let u=document.createElement(`div`);u.className=t$();let d=document.createElement(`button`);d.className=n$(),d.textContent=`Reset`,d.addEventListener(`click`,()=>e.onReset());let f=document.createElement(`button`);f.className=r$(),f.textContent=`Save`,f.addEventListener(`click`,()=>e.onSave());let p=document.createElement(`button`);p.className=n$(),p.textContent=`Apply`,p.addEventListener(`click`,()=>e.onApply());let m=document.createElement(`button`);m.className=n$(),m.textContent=`Duplicate`,m.addEventListener(`click`,()=>e.onDuplicate()),u.appendChild(d),u.appendChild(f),u.appendChild(p),u.appendChild(m);let h=document.createElement(`div`);h.className=t$();let g=document.createElement(`button`);g.className=r$(),g.textContent=`Use as Template`,g.addEventListener(`click`,()=>e.onDuplicate()),h.appendChild(g),r.appendChild(i),r.appendChild(u),r.appendChild(h);let _=document.createElement(`div`);_.className=a$(),n.appendChild(r),n.appendChild(_);let v=document.createElement(`div`);v.className=o$(),v.textContent=`Select a policy to edit`,t.appendChild(n),t.appendChild(v);function y(e){let t=e.selectedId!==null;if(n.style.display=t?`flex`:`none`,v.style.display=t?`none`:`flex`,!t)return;let r=e.catalog.find(t=>t.id===e.selectedId);if(!r)return;let i=r.source===`builtin`,d=e.editedName??r.name;a.textContent=d,document.activeElement!==o&&o.value!==d&&(o.value=d);let f=F$(r.policyType);s.textContent=f?.label??r.policyType,a.style.display=i?``:`none`,o.style.display=i?`none`:``,c.style.display=i?``:`none`,u.style.display=i?`none`:`flex`,h.style.display=i?`flex`:`none`,l.style.display=!i&&e.dirty?`block`:`none`}return{element:t,update:y,bodyElement:_}}function W$(e){let t=document.createElement(`div`);t.className=s$();let n=document.createElement(`textarea`);n.value=JSON.stringify(e.initialData,null,2);let r=document.createElement(`div`);r.className=c$(),r.style.display=`none`;let i={...e.initialData};return n.addEventListener(`input`,()=>{try{let t=JSON.parse(n.value);i=t,r.style.display=`none`,e.onChange(t)}catch(e){r.style.display=`block`,r.textContent=`Invalid JSON: ${e.message}`}}),t.appendChild(n),t.appendChild(r),{element:t,setData(e){i={...e},n.value=JSON.stringify(e,null,2),r.style.display=`none`},getData(){return{...i}},destroy(){t.remove()}}}var G$=class{constructor(e){this.currentEditor=null,this.container=null,this.store=new H$(e);let t=B$({onSearchChange:e=>this.store.setCatalogSearch(e),onGroupByChange:e=>this.store.setCatalogGroupBy(e),onSelectPolicy:e=>this.handleSelectPolicy(e),onNewPolicy:e=>{this.store.addNewPolicy(e),this.mountEditorForSelection()},onDuplicatePolicy:e=>{this.store.duplicatePolicy(e),this.mountEditorForSelection()},onDeletePolicy:e=>{this.store.deletePolicy(e),this.store.getSelectedItem()||this.destroyCurrentEditor()}});this.editorShell=U$({onSave:()=>this.store.savePolicy(),onReset:()=>{this.store.resetDraft(),this.syncEditorFromStore()},onApply:()=>this.store.applyPolicy(),onDuplicate:()=>{let e=this.store.getSelectedItem();e&&(this.store.duplicatePolicy(e.id),this.mountEditorForSelection())},onRename:e=>this.store.renamePolicy(e)}),this.layout=l$({catalogPanel:t,editorShell:this.editorShell}),this.unsubscribe=this.store.subscribe(e=>{this.layout.update(e)}),this.layout.update(this.store.getState())}render(e){this.container=e,e.appendChild(this.layout.element)}destroy(){this.destroyCurrentEditor(),this.unsubscribe(),this.container&&this.layout.element.parentNode===this.container&&this.layout.element.remove(),this.container=null}getStore(){return this.store}handleSelectPolicy(e){this.store.selectPolicy(e),this.mountEditorForSelection()}mountEditorForSelection(){this.destroyCurrentEditor();let e=this.store.getSelectedItem();if(!e)return;let t=e.source===`builtin`,n={initialData:{...e.policyData},onChange:e=>{this.store.updateEditorDraft(e)},readonly:t};this.currentEditor=e.policyType===`scheduling`?GX.createEditorInstance(n):e.policyType===`rankingPoints`?JY.createEditorInstance(n):e.policyType===`seeding`?bQ.createEditorInstance(n):e.policyType===`scoring`?LZ.createEditorInstance(n):e.policyType===`participant`?PQ.createEditorInstance(n):W$(n),this.editorShell.bodyElement.innerHTML=``,this.editorShell.bodyElement.appendChild(this.currentEditor.element)}syncEditorFromStore(){let e=this.store.getState();this.currentEditor&&e.editorDraft&&this.currentEditor.setData(e.editorDraft)}destroyCurrentEditor(){this.currentEditor&&=(this.currentEditor.destroy(),null),this.editorShell.bodyElement.innerHTML=``}};function K$(e,t,n,r){e!==void 0&&e<0&&r.push({severity:`error`,path:t,message:n})}function q$(e,t){if(!e.defaultTimes)return;let n=e.defaultTimes.averageTimes;if(n)for(let e=0;e<n.length;e++)K$(n[e].minutes.default,`defaultTimes.averageTimes[${e}].minutes.default`,`Default average time must be non-negative`,t),K$(n[e].minutes.DOUBLES,`defaultTimes.averageTimes[${e}].minutes.DOUBLES`,`Doubles average time must be non-negative`,t);let r=e.defaultTimes.recoveryTimes;if(r)for(let e=0;e<r.length;e++)K$(r[e].minutes.default,`defaultTimes.recoveryTimes[${e}].minutes.default`,`Default recovery time must be non-negative`,t)}function J$(e,t){if(!e.defaultDailyLimits)return;let n=e.defaultDailyLimits;K$(n.SINGLES,`defaultDailyLimits.SINGLES`,`Singles daily limit must be non-negative`,t),K$(n.DOUBLES,`defaultDailyLimits.DOUBLES`,`Doubles daily limit must be non-negative`,t),K$(n.total,`defaultDailyLimits.total`,`Total daily limit must be non-negative`,t)}function Y$(e){let t=[];return q$(e,t),J$(e,t),e.matchUpAverageTimes&&X$(e.matchUpAverageTimes,`matchUpAverageTimes`,`averageTimes`,t),e.matchUpRecoveryTimes&&Z$(e.matchUpRecoveryTimes,`matchUpRecoveryTimes`,t),Q$(e,t),t}function X$(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i];a.matchUpFormatCodes.length||r.push({severity:`error`,path:`${t}[${i}].matchUpFormatCodes`,message:`At least one format code is required per format group`});let o=a[n];if(o)for(let e=0;e<o.length;e++)K$(o[e].minutes.default,`${t}[${i}].${n}[${e}].minutes.default`,`Time must be non-negative`,r),K$(o[e].minutes.DOUBLES,`${t}[${i}].${n}[${e}].minutes.DOUBLES`,`Doubles time must be non-negative`,r)}}function Z$(e,t,n){for(let r=0;r<e.length;r++){let i=e[r];i.matchUpFormatCodes.length||n.push({severity:`error`,path:`${t}[${r}].matchUpFormatCodes`,message:`At least one format code is required per format group`});for(let e=0;e<i.recoveryTimes.length;e++)K$(i.recoveryTimes[e].minutes.default,`${t}[${r}].recoveryTimes[${e}].minutes.default`,`Recovery time must be non-negative`,n),K$(i.recoveryTimes[e].minutes.DOUBLES,`${t}[${r}].recoveryTimes[${e}].minutes.DOUBLES`,`Doubles recovery time must be non-negative`,n)}}function Q$(e,t){let n=(e,n)=>{if(!e)return;let r=new Map;for(let i=0;i<e.length;i++)for(let a of e[i].matchUpFormatCodes)r.has(a)?t.push({severity:`warning`,path:`${n}[${i}].matchUpFormatCodes`,message:`Format code "${a}" also appears in group ${r.get(a)}`}):r.set(a,i)};n(e.matchUpAverageTimes,`matchUpAverageTimes`),n(e.matchUpRecoveryTimes,`matchUpRecoveryTimes`)}function $$(e,t){let n=new G$(e);return n.render(t),n}e.AvailabilityGrid=yV,e.COMPETITIVENESS_BUCKETS=rb,e.COMPETITIVENESS_COLORS=FN,e.COURT_SVG_RESOURCE_SUB_TYPE=ph,e.CompositionEditorStore=QK,e.DEFAULT_COMPETITIVE_BANDS=NN,e.DEFAULT_COURT_CARD_CONFIG=I_,e.DEFAULT_COURT_LAYOUT_CONFIG=Ev,e.DEFAULT_DRAW_CARD_CONFIG=xb,e.DEFAULT_EVENT_CARD_CONFIG=px,e.DEFAULT_SCHEDULE_CELL_CONFIG=kK,e.DEFAULT_TOURNAMENT_CARD_CONFIG=Rh,e.DEFAULT_VENUE_CARD_CONFIG=Kg,e.DEFAULT_VENUE_LOCATOR_CONFIG=Jv,e.DrawStateManager=yC,e.EVENT_CARD_LIGHT_MODE_THRESHOLD=mx,e.InlineScoringManager=gs,e.MATCH_FORMATS=cC,e.NEUTRAL_SEGMENT_COLOR=IN,e.POLICY_TYPE_GROUPS=L$,e.POLICY_TYPE_METADATA=P$,e.PolicyCatalogControl=G$,e.PolicyCatalogStore=H$,e.ProfileStore=FL,e.SchedulePageControl=rK,e.SchedulePageStore=nK,e.SchedulingEditorControl=GX,e.SchedulingEditorStore=$Y,e.SchedulingProfileControl=JL,e.TopologyBuilderControl=yW,e.TopologyStore=vH,e.activateScheduleCellTypeAhead=XK,e.aggregateCompetitiveness=ob,e.applyDropCommit=TL,e.badmintonCourt=dh,e.barButton=CF,e.baseballDiamond=ch,e.basketballCourt=sh,e.buildActiveStripPanel=EK,e.buildCardSkeleton=Lh,e.buildCompetitivenessBar=lb,e.buildCompetitivenessDonut=yb,e.buildCourtCard=nv,e.buildCourtGridSlot=tK,e.buildCourtLayout=Uv,e.buildCourtSkeletonCard=vv,e.buildDateStrip=KL,e.buildDrawCard=Vb,e.buildDrawSkeletonCard=ox,e.buildEdgeEditor=pU,e.buildEditorShell=U$,e.buildEventCard=Vx,e.buildEventSkeletonCard=aS,e.buildHiveIDLogin=eC,e.buildInteractiveScoringShell=NJ,e.buildIssueIndex=CL,e.buildIssuesPanel=sL,e.buildJsonEditor=W$,e.buildLadderChart=mF,e.buildMatchUpCard=qG,e.buildMatchUpCatalog=XG,e.buildNodeEditor=tU,e.buildPolicyCatalogLayout=l$,e.buildPolicyCatalogPanel=B$,e.buildRatingDistributionChart=sF,e.buildRoundCard=VL,e.buildRoundCatalog=nL,e.buildScheduleDateStrip=eK,e.buildScheduleGridCell=AK,e.buildScheduleInspectorPanel=NG,e.buildScheduleIssueIndex=ZG,e.buildScheduleIssuesPanel=$G,e.buildSchedulePageLayout=kG,e.buildSchedulingEditorPanel=WX,e.buildSchedulingProfileLayout=zI,e.buildSegmentedBar=bb,e.buildSetScore=Gs,e.buildSkeletonCard=kg,e.buildStructureCard=aH,e.buildStructureMinimap=Ci,e.buildTeamCard=eb,e.buildToolbar=HU,e.buildTopologyBuilderLayout=UU,e.buildTopologyCanvas=kH,e.buildTournamentCard=ug,e.buildVenueBoard=UL,e.buildVenueCard=p_,e.buildVenueLocator=Dy,e.buildVenueSkeletonCard=A_,e.burstChart=mP,e.cModal=z,e.calculateComplement=Vs,e.cellCardConfig=Kv,e.competitivenessColor=WN,e.completeMagicLink=tC,e.compositions=mi,e.computeActiveStrip=pK,e.computeActiveStripCell=fK,e.computeBaseRoundByEvent=RG,e.computeReschedulePlacements=bK,e.consumeMagicLink=WS,e.controlBar=VF,e.courthiveComponentsVersion=sC,e.createAvailabilityGrid=bV,e.createCardPopoverManager=BI,e.createCompositionEditor=$q,e.createCourtSvg=bh,e.createInlineScoringFooter=jJ,e.createNotesEditor=$m,e.createPolicyCatalog=$$,e.createPrintCompositionEditor=aJ,e.createSchedulePage=ZK,e.createSchedulingEditor=KX,e.createSchedulingProfile=YL,e.describeCourt=Ey,e.destroyTipster=rh,e.destroyVenueLocator=Oy,e.drawer=bd,e.dropDownButton=vF,e.emptySchedulingPolicy=ZY,e.engineToMatchUp=ms,e.extractCourtSvgSport=Ih,e.extractImageURL=Fh,e.filterCatalog=XI,e.filterMatchUpCatalog=LG,e.filterPolicyCatalog=R$,e.findIssuesForLocator=jL,e.formatAddress=Sh,e.formatCodeLabel=YY,e.formatDateRange=Mh,e.formatFeeRange=Bg,e.formatVenueLocation=Ch,e.fromFactoryDrawData=DP,e.fromLegacyDraw=AP,e.generatePreviewMatchUps=FV,e.getAgeCategoryModal=Ao,e.getCategoryModal=No,e.getCompetitivenessBand=VN,e.getCompetitivenessFromScoreString=HN,e.getFlightProfileModal=us,e.getGenerateTeamsModal=Ki,e.getMatchUpFormatModal=Ha,e.getMatchWinner=Bs,e.getMaxAllowedScore=Is,e.getMockParticipantsModal=Bi,e.getPlannedRoundKeys=QI,e.getPolicyTypeMeta=F$,e.getPortPosition=oH,e.getRoundAt=AL,e.getScoringConfig=ys,e.getSetFormatForIndex=Ns,e.getSetWinner=Rs,e.getVenueRounds=kL,e.groupCatalog=ZI,e.groupCourts=Vv,e.groupMatchUpCatalog=KG,e.groupPolicyCatalog=z$,e.hasVenueGeo=wy,e.hockeyRink=lh,e.initDrawer=xd,e.isCompletedStatus=IG,e.isExistingUserConflict=GS,e.isMatchComplete=zs,e.isSetComplete=Ls,e.isSetTiebreakOnly=Ps,e.isSetTimed=Fs,e.mapCourtToCardData=Tv,e.mapDrawDefinitionToCardData=fx,e.mapEventToCardData=SS,e.mapMatchUpToCellData=YK,e.mapTournamentToCardData=Wg,e.mapVenueToCardData=F_,e.mapVenueToLocatorData=Ky,e.matchUpLabel=AG,e.matchUpSearchKey=MG,e.maxSeverity=NL,e.mergeCourtCardConfig=L_,e.mergeCourtLayoutConfig=Dv,e.mergeDrawCardConfig=Sb,e.mergeEventCardConfig=hx,e.mergeTournamentCardConfig=zh,e.mergeVenueCardConfig=qg,e.mergeVenueLocatorConfig=Yv,e.notesToolbar=Fm,e.openCompositionEditorModal=Qi,e.openScheduleCellConfigModal=ea,e.padelCourt=fh,e.participantLabel=jG,e.pickProgressionStructure=EP,e.pickleballCourt=uh,e.renderButtons=lC,e.renderContainer=ii,e.renderField=gn,e.renderForm=Oi,e.renderInlineMatchUp=fs,e.renderMatchUp=ei,e.renderMenu=eh,e.renderOptions=hn,e.renderParticipant=hr,e.renderParticipantInput=Cn,e.renderRound=ti,e.renderRoundHeader=_r,e.renderSchematicMatchUp=Ti,e.renderSchematicRound=Ei,e.renderSchematicStructure=Di,e.renderScorecard=xJ,e.renderStructure=ni,e.renderTeamVsHeader=SJ,e.requestMagicLink=US,e.resetScoringConfig=xs,e.resolveCourtSport=vh,e.resolveEventStatus=cS,e.resolvePublishedComposition=gi,e.resolveTournamentStatus=Pg,e.scoringModal=lu,e.selectItem=bF,e.setScoringConfig=bs,e.settingOf=zv,e.shouldApplySmartComplement=Hs,e.shouldCreateNextSet=Ws,e.shouldShowTiebreak=Us,e.showCourtAvailabilityModal=_V,e.signup=VS,e.sortVenueCourts=Ty,e.sportFromMatchUpFormat=_h,e.standardTemplates=lW,e.summarizeCourts=Hv,e.surfaceOf=Bv,e.syncClearVisibility=CC,e.tennisCourt=oh,e.tipster=ih,e.toggleOverlay=jF,e.topologyToDrawOptions=IW,e.totalBuckets=sb,e.updateHeadingSelect=Lm,e.updateTieScore=CJ,e.updateToolbarState=Im,e.validateProfile=dL,e.validateSchedulingPolicy=Y$,e.validateTopology=CU,e.validator=fn,Object.defineProperty(e,"validators",{enumerable:!0,get:function(){return vC}}),e.verifyExisting=HS,e.wrapSearchWithClear=SC});