import{a as d,b as s}from"./chunk-NOGHTXP6.js";import{a as c}from"./chunk-65OJRBX6.js";var p="django-sortable-select{background-color:rgba(0,0,0,0) !important}django-sortable-select.focus{opacity:1}django-sortable-select option.sortable-selected,django-sortable-select optgroup.sortable-selected{opacity:1;cursor:grab}django-sortable-select option.sortable-chosen,django-sortable-select option.sortable-ghost,django-sortable-select optgroup.sortable-chosen,django-sortable-select optgroup.sortable-ghost{opacity:1;cursor:grabbing !important}django-sortable-select option{display:block;line-height:normal;cursor:default}django-sortable-select option.sortable-chosen,django-sortable-select option.sortable-selected{opacity:1}django-sortable-select optgroup option::before{opacity:1}";s.mount(new d);var u=class extends HTMLElement{constructor(){super();this.baseSelector="django-sortable-select";this.lastSelected=null}initialize(e){c.stylesAreInstalled(this.baseSelector)||this.transferStyles(e),s.create(this,{animation:150,fallbackOnBody:!0,multiDrag:!0,onEnd:t=>this.onEnd(t)}),this.querySelectorAll("optgroup").forEach(t=>{s.create(this,{animation:150,fallbackOnBody:!0,multiDrag:!0,onEnd:o=>this.onEnd(o),handle:">option",group:t.label})}),this.addEventListener("click",t=>this.optionSelected(t)),window.addEventListener("click",t=>this.elementFocus(t))}onEnd(e){this.deselectAllOptions();let t=new Event("options-sorted",{bubbles:!0,cancelable:!0,composed:!1});this.dispatchEvent(t)}elementFocus(e){e.target instanceof HTMLElement&&this.contains(e.target)?this.classList.add("focus"):this.classList.remove("focus")}optionSelected(e){if(!(e.target instanceof HTMLOptionElement))return;let t=e.target;if(e instanceof PointerEvent&&e.metaKey)(t.selected=!t.selected)?s.utils.select(t):s.utils.deselect(t);else if(e instanceof PointerEvent&&e.shiftKey&&this.lastSelected){this.deselectAllOptions();let o=!1;for(let l of this.getElementsByTagName("option"))l===t||l===this.lastSelected?(l.selected=!0,o=!o):l.selected=o,l.selected&&s.utils.select(l)}else this.deselectAllOptions(),t.selected=!0,s.utils.select(t);this.lastSelected=t,e.preventDefault()}deselectAllOptions(){for(let e of this.getElementsByTagName("option"))e.selected=!1,s.utils.deselect(e)}transferStyles(e){let t=document.createElement("style");if(t.innerText=p,document.head.appendChild(t),!t.sheet)throw new Error("Could not create <style> element");let o=t.sheet,l=!1,r=e.querySelector("option");for(let a=0;a<o.cssRules.length;a++){let i=o.cssRules.item(a),n;switch(i.selectorText){case this.baseSelector:n=c.extractStyles(e,["display","width","height","border","box-shadow","outline","overflow","font-family","font-size","font-stretch","font-style","font-weight","letter-spacing","white-space","line-height"]),o.insertRule(`${i.selectorText}{${n}}`,++a),l=!0;break;case`${this.baseSelector}.focus`:e.style.transition="none",e.focus(),n=c.extractStyles(e,["border","box-shadow","outline"]),e.blur(),o.insertRule(`${i.selectorText}{${n}}`,++a),e.style.transition="";break;case`${this.baseSelector} option.sortable-chosen, ${this.baseSelector} option.sortable-selected`:r&&(r.selected=!0,n=c.extractStyles(r,["color","background-color"]),o.insertRule(`${i.selectorText}{${n}}`,++a),r.selected=!1);break;case`${this.baseSelector}.focus option.sortable-chosen, ${this.baseSelector}.focus option.sortable-selected`:e.focus(),r&&(r.selected=!0,n=c.extractStyles(r,["color","background-color"]),o.insertRule(`${i.selectorText}{${n}}`,++a),r.selected=!1),e.blur();break;case`${this.baseSelector} optgroup option::before`:o.insertRule(`${i.selectorText}{content:"\\0000a0\\0000a0\\0000a0\\0000a0";}`,++a);break;default:break}}if(!l)throw new Error(`Could not load styles for ${this.baseSelector}`)}add(e){e instanceof HTMLOptionElement?(this.appendChild(e),s.utils.select(e)):e instanceof HTMLOptGroupElement&&(this.appendChild(e),s.create(e,{animation:150,fallbackOnBody:!0,multiDrag:!0,onEnd:t=>this.onEnd(t),handle:">option"}))}},b=class extends HTMLOptGroupElement{constructor(){super();this.lastSelected=null}};export{u as a,b};
