import{r as a,c as t,h as e,H as c,g as i}from"./p-cdf3f581.js";import{S as r}from"./p-14b00fa9.js";const s=class{constructor(e){a(this,e),this.calciteListOrderChange=t(this,"calciteListOrderChange",7),this.handleSelector="calcite-handle",this.disabled=!1,this.loading=!1,this.handleActivated=!1,this.items=[],this.observer=new MutationObserver(()=>{this.cleanUpDragAndDrop(),this.items=Array.from(this.el.children),this.setUpDragAndDrop()})}connectedCallback(){this.items=Array.from(this.el.children),this.setUpDragAndDrop(),this.beginObserving()}disconnectedCallback(){this.observer.disconnect(),this.cleanUpDragAndDrop()}calciteHandleNudgeHandler(a){const t=this.items.find(t=>t.contains(a.detail.handle)||a.composedPath().includes(t)),e=this.items.length-1,c=this.items.indexOf(t);let i,r=!1;switch(a.detail.direction){case"up":a.preventDefault(),0===c?r=!0:i=c-1;break;case"down":a.preventDefault(),c===e?i=0:c===e-1?r=!0:i=c+2;break;default:return}this.observer.disconnect(),r?t.parentElement.appendChild(t):t.parentElement.insertBefore(t,this.items[i]),this.items=Array.from(this.el.children),a.detail.handle.activated=!0,a.detail.handle.setFocus(),this.beginObserving()}setUpDragAndDrop(){this.sortable=r.create(this.el,{handle:this.handleSelector,onUpdate:()=>{this.items=Array.from(this.el.children),this.calciteListOrderChange.emit()},onStart:()=>{this.observer.disconnect()},onEnd:()=>{this.beginObserving()}})}cleanUpDragAndDrop(){this.sortable.destroy(),this.sortable=null}beginObserving(){this.observer.observe(this.el,{childList:!0,subtree:!0})}render(){return e(c,null,e("slot",null))}get el(){return i(this)}};s.style=":host([hidden]){display:none}:host([theme=dark]){--calcite-app-background:#404040;--calcite-app-foreground:#dfdfdf;--calcite-app-background-hover:#2b2b2b;--calcite-app-foreground-hover:#f3f3f3;--calcite-app-background-active:#151515;--calcite-app-foreground-active:#59d6ff;--calcite-app-foreground-subtle:#eaeaea;--calcite-app-background-content:#2b2b2b;--calcite-app-border:#2b2b2b;--calcite-app-border-hover:#2b2b2b;--calcite-app-border-subtle:#2b2b2b;--calcite-app-scrim:rgba(64, 64, 64, 0.8)}:host([theme=light]){--calcite-app-background:#ffffff;--calcite-app-foreground:#404040;--calcite-app-background-hover:#eaeaea;--calcite-app-foreground-hover:#2b2b2b;--calcite-app-background-active:#c7eaff;--calcite-app-foreground-active:#00619b;--calcite-app-foreground-subtle:#757575;--calcite-app-foreground-link:#007ac2;--calcite-app-background-content:#f3f3f3;--calcite-app-background-clear:transparent;--calcite-app-border:#eaeaea;--calcite-app-border-hover:#dfdfdf;--calcite-app-border-subtle:#f3f3f3;--calcite-app-border-active:#00619b;--calcite-app-disabled-opacity:0.25;--calcite-app-scrim:rgba(255, 255, 255, 0.8)}";export{s as calcite_sortable_list}