import{a as e,i as t,n,r}from"./payload-DyKkZIOX.mjs";function i(e,t){let n=[];for(let r of Array.from(e.querySelectorAll(`[data-action-id]`))){let e=r.getAttribute(`data-action-id`);if(!e)continue;if(r.tagName===`SELECT`){let i=r,a=()=>{t(e,i.value)};i.addEventListener(`change`,a),n.push(()=>{i.removeEventListener(`change`,a)});continue}let i=()=>{t(e)};r.addEventListener(`click`,i),n.push(()=>{r.removeEventListener(`click`,i)})}return()=>{for(let e of n)e()}}function a(e){let t=e.createElement(`style`);return t.textContent=`
.bk-checklist-progress {
  margin-bottom: var(--dt-space-3);
  color: var(--dt-text-secondary);
  font-size: var(--dt-font-size-sm);
  font-weight: 600;
}

.bk-checklist-box {
  width: var(--dt-space-6);
  height: var(--dt-space-6);
  margin: 0;
  accent-color: var(--dt-accent-fg);
}
`,t}function o(e,t){let n=t.filter(e=>e.getAttribute(`data-checked`)===`true`).length,r=t.length;return e.textContent=`${n}/${r} complete`,{complete:n,total:r}}function s(e,t={}){let n=Array.from(e.querySelectorAll(`.bk-checklist-item`));if(n.length===0)return()=>{};let r=e.ownerDocument,i=a(r),s=r.createElement(`div`);s.className=`bk-checklist-progress`,e.parentElement?.insertBefore(s,e),r.head?.appendChild(i);let c=[];for(let[e,i]of n.entries()){let a=i.querySelector(`.bk-checklist-icon`),l=i.querySelector(`.bk-checklist-label`)?.textContent?.trim()??``,u=r.createElement(`input`);u.type=`checkbox`,u.className=`bk-checklist-box`,u.checked=i.getAttribute(`data-checked`)===`true`;let d=()=>{i.setAttribute(`data-checked`,String(u.checked));let r=o(s,n);t.onAction?.(`checklist`,JSON.stringify({index:e,label:l,checked:u.checked,complete:r.complete,total:r.total}))};u.addEventListener(`change`,d),c.push(()=>{u.removeEventListener(`change`,d)}),a?a.replaceWith(u):i.insertBefore(u,i.firstChild)}return o(s,n),()=>{for(let e of c)e();s.remove(),i.remove();for(let e of n){let t=e.querySelector(`.bk-checklist-box`);if(!t)continue;let n=r.createElement(`span`);n.className=`bk-checklist-icon`,n.textContent=e.getAttribute(`data-checked`)===`true`?`✓`:`×`,t.replaceWith(n)}}}const c=`data-sort-label`,l=`data-sort-dir`,u=new Intl.Collator(void 0,{numeric:!0,sensitivity:`base`});function d(e){let t=e.getAttribute(c);if(t!==null)return t;let n=e.textContent?.trim()??``;return e.setAttribute(c,n),n}function f(e,t,n){for(let[r,i]of e.entries())i.textContent=d(i),r===t?(i.setAttribute(l,n),i.append(` ${n===`asc`?`▲`:`▼`}`)):i.removeAttribute(l)}function p(e,t){return e.querySelectorAll(`td`)[t]?.textContent?.trim()??``}function m(e){let t=Array.from(e.querySelectorAll(`thead th`)),n=e.querySelector(`tbody`);if(!n||t.length===0)return()=>{};let r=Array.from(n.querySelectorAll(`tr`)),i=e.parentElement,a=null,o=`asc`,s=``,m=null,h=[],g=()=>{let e=[...r];if(a!==null){let t=a;e.sort((e,n)=>{let r=u.compare(p(e,t),p(n,t));return o===`asc`?r:-r})}for(let t of e){n.appendChild(t);let e=t.textContent?.toLowerCase()??``;t.hidden=s.length>0&&!e.includes(s)}f(t,a,o)};for(let[e,n]of t.entries()){d(n);let t=()=>{a===e?o=o===`asc`?`desc`:`asc`:(a=e,o=`asc`),g()};n.style.cursor=`pointer`,n.addEventListener(`click`,t),h.push(()=>{n.removeEventListener(`click`,t)})}if(r.length>5&&i){m=i.ownerDocument.createElement(`input`),m.className=`bk-table-filter`,m.placeholder=`Filter...`;let t=()=>{s=m?.value.toLowerCase().trim()??``,g()};i.insertBefore(m,e),m.addEventListener(`input`,t),h.push(()=>{m?.removeEventListener(`input`,t),m?.remove(),m=null})}return g(),()=>{for(let e of h)e();for(let e of t)e.textContent=d(e),e.removeAttribute(l),e.removeAttribute(c),e.style.removeProperty(`cursor`);for(let e of r)e.hidden=!1}}function h(e){for(let t of Array.from(e.children))if(t.tagName===`SUMMARY`)return t;return null}function g(e){let t=e.closest(`details`);if(!t)return null;let n=t.parentElement;for(;n;){if(n.tagName===`DETAILS`)return h(n);n=n.parentElement}return null}function _(e){return Array.from(e.querySelectorAll(`summary`))}function v(e){return e.open||e.hasAttribute(`open`)}function y(e,t){e.open=t,t?e.setAttribute(`open`,``):e.removeAttribute(`open`)}function b(e,t){e.textContent=t.every(e=>v(e))?`Collapse all`:`Expand all`}function x(e){let t=Array.from(e.querySelectorAll(`details`));if(t.length===0)return()=>{};let n=e.ownerDocument.createElement(`button`);n.type=`button`,n.className=`bk-tree-toggle-all`,e.insertBefore(n,e.firstChild);let r=()=>{let e=t.some(e=>!v(e));for(let n of t)y(n,e);b(n,t)},i=()=>{r()};n.addEventListener(`click`,i);let a=t.map(e=>{let r=()=>{b(n,t)};return e.addEventListener(`toggle`,r),()=>{e.removeEventListener(`toggle`,r)}}),o=_(e).map(t=>{t.tabIndex=0;let n=n=>{let r=_(e),i=r.indexOf(t);if(i===-1)return;let a=t.closest(`details`);if(n.key===`ArrowDown`){r[i+1]?.focus(),n.preventDefault();return}if(n.key===`ArrowUp`){r[i-1]?.focus(),n.preventDefault();return}if(n.key===`ArrowRight`){if(a&&!v(a))y(a,!0);else{let e=r[i+1];e&&a?.contains(e)&&e.focus()}n.preventDefault();return}n.key===`ArrowLeft`&&(a&&v(a)?y(a,!1):g(t)?.focus(),n.preventDefault())};return t.addEventListener(`keydown`,n),()=>{t.removeEventListener(`keydown`,n)}});return b(n,t),()=>{n.removeEventListener(`click`,i);for(let e of a)e();for(let e of o)e();n.remove()}}const S=[{selector:`.bk-table`,matches:e=>!r(e.ownerDocument),load:async()=>({hydrate:e=>m(e)})},{selector:`.bk-table`,matches:(t,n)=>r(t.ownerDocument)&&e(t,`.bk-table`,n),load:()=>import(`./form-SyIoFeT1.mjs`).then(e=>({hydrate:(t,n)=>e.hydrateForm(t,n)}))},{selector:`.bk-tree`,matches:e=>!n(e.ownerDocument),load:async()=>({hydrate:e=>x(e)})},{selector:`.bk-tree`,matches:e=>n(e.ownerDocument),load:()=>import(`./flame-graph-CV8KCLKu.mjs`).then(e=>({hydrate:(t,n)=>e.hydrateFlameGraph(t,n)}))},{selector:`.bk-actions`,load:async()=>({hydrate:(e,t)=>t?.onAction?i(e,t.onAction):()=>{}})},{selector:`.bk-checklist`,load:async()=>({hydrate:(e,t)=>s(e,t)})},{selector:`.bk-cards`,matches:(n,r)=>t(n.ownerDocument)&&e(n,`.bk-cards`,r),load:()=>import(`./picker-CZJricO9.mjs`).then(e=>({hydrate:(t,n)=>e.hydratePicker(t,n)}))}],C=`data-hydrated`;function w(e,t){let n=[];return e.matches(t)&&n.push(e),n.push(...Array.from(e.querySelectorAll(t))),n}function T(e,t,n){e.push(()=>{n(),t.removeAttribute(C)})}function E(e={}){let t=e.container??document.body,n=[];for(let e of w(t,`.bk-table`))e.hasAttribute(C)||(e.setAttribute(C,``),T(n,e,m(e)));for(let e of w(t,`.bk-tree`))e.hasAttribute(C)||(e.setAttribute(C,``),T(n,e,x(e)));for(let r of w(t,`.bk-checklist`))r.hasAttribute(C)||(r.setAttribute(C,``),T(n,r,s(r,e)));for(let r of w(t,`.bk-actions`))if(!r.hasAttribute(C)){if(r.setAttribute(C,``),e.onAction){T(n,r,i(r,e.onAction));continue}n.push(()=>{r.removeAttribute(C)})}return()=>{for(let e of n)e();n.length=0}}async function D(e={}){let t=e.container??document.body,n={...e,container:t},r=[],i=S.map(e=>({definition:e,elements:w(t,e.selector).filter(t=>!t.hasAttribute(C)&&(e.matches?.(t,n)??!0))})).filter(({elements:e})=>e.length>0);if(i.length===0)return()=>{};let a=await Promise.all(i.map(async({definition:e,elements:t})=>({island:await e.load(),elements:t})));for(let{island:e,elements:t}of a)for(let i of t)i.hasAttribute(C)||(i.setAttribute(C,``),T(r,i,e.hydrate(i,n)));return()=>{for(let e of r)e();r.length=0}}export{S as ISLAND_REGISTRY,E as hydrate,i as hydrateActions,D as hydrateAsync,m as hydrateTable,x as hydrateTree};