var Me=Object.defineProperty;var Re=(i,e,t)=>e in i?Me(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var P=(i,e,t)=>Re(i,typeof e!="symbol"?e+"":e,t);document.addEventListener("alpine:init",()=>{window.Alpine.store("editOnClickValidation",{pending:[],set(i,e){this.pending=this.pending.filter(t=>t.value!==i),this.pending.push({value:i,textContent:e})},has(i){return this.pending.some(e=>e.value===i)},get(i){return this.pending.find(e=>e.value===i)},notContains(i){return this.pending.length>0&&!this.has(i)},clear(){this.pending=[]},getTextContent(i){const e=this.pending.find(t=>t.value===i);return e?e.textContent:null}}),window.editOnClickValidation=window.Alpine.store("editOnClickValidation")});document.addEventListener("alpine:init",()=>{window.Alpine.store("pgBulkActions",{selected:[],init(){window.addEventListener("pgBulkActions::addMore",i=>{const e=i.__livewire.params[0];typeof this.selected[e.tableName]>"u"&&(this.selected[e.tableName]=[]),this.selected[e.tableName].push(e.value)}),window.addEventListener("pgBulkActions::clear",i=>{this.clear(i.detail)}),window.addEventListener("pgBulkActions::clearAll",()=>{this.clearAll()})},add(i,e){if(typeof this.selected[e]>"u"&&(this.selected[e]=[]),!this.selected[e].includes(i)){this.selected[e].push(i);return}this.remove(i,e)},remove(i,e){const t=this.selected[e].indexOf(i);t>-1&&this.selected[e].splice(t,1)},get(i){return this.selected[i]??""},count(i){return typeof this.selected[i]>"u"?0:this.selected[i].length},clear(i){this.selected[i]=[]},clearAll(){this.selected=[]}}),window.pgBulkActions=window.Alpine.store("pgBulkActions")});const Ne=i=>({field:i.field??null,tableName:i.tableName??null,enabled:i.enabled??!1,id:i.id,trueValue:i.trueValue,falseValue:i.falseValue,toggle:i.toggle,save(){this.toggle=this.toggle===0?1:0,this.$wire.dispatch("pg:toggleable-"+this.tableName,{id:this.id,field:this.field,value:this.toggle})}}),Ve=(i,e,t)=>{const s=i[e];return s?typeof s=="function"?s():Promise.resolve(s):new Promise((n,o)=>{(typeof queueMicrotask=="function"?queueMicrotask:setTimeout)(o.bind(null,new Error("Unknown variable dynamic import: "+e+(e.split("/").length!==t?". Note that variables only represent file names one level deep.":""))))})},Be=i=>({dataField:i.dataField,tableName:i.tableName,label:i.label??null,locale:i.locale??{locale:"default",dateFormat:"Y-m-d H:i",time_24hr:!1,enableTime:!0},onlyFuture:i.onlyFuture??!1,noWeekEnds:i.noWeekEnds??!1,customConfig:i.customConfig??null,type:i.type,element:null,selectedDates:null,async init(){typeof flatpickr>"u"&&(console.log("%c%s","color: #f59e0c; font-size: 1.2em; font-weight: bold; line-height: 1.5"," PowerGrid"),console.error("%c%s","font-size: 1em; line-height: 1.5",`
Failed to mount filter: Filter::datetime('${this.dataField}') on table ['${this.tableName}']

• Install flatpickr: npm install flatpickr

• Add 'import flatpickr from "flatpickr"' in resources/js/app.js file
  `)),window.addEventListener(`pg:clear_flatpickr::${this.tableName}:${this.dataField}`,()=>{this.$refs.rangeInput&&this.element&&this.element.clear()}),window.addEventListener(`pg:clear_all_flatpickr::${this.tableName}`,()=>{this.$refs.rangeInput&&this.element&&this.element.clear()});try{const t=await Ve(Object.assign({}),`./flatpickr/dist/l10n/${this.locale.locale}.js`,5);flatpickr.localize(t.default||t)}catch{}const e=this.getOptions();this.$refs.rangeInput&&typeof flatpickr<"u"&&(this.element=flatpickr(this.$refs.rangeInput,e),this.selectedDates=this.$wire.get(`filters.${this.type}.${this.dataField}.formatted`),this.element.setDate(this.selectedDates))},getOptions(){const e={mode:"range",defaultHour:0,...this.locale,...this.customConfig};return this.onlyFuture&&(e.minDate="today"),this.noWeekEnds&&(e.disable=[function(t){return t.getDay()===0||t.getDay()===6}]),e.onClose=(t,s,n)=>{t=t.map(o=>this.element.formatDate(o,"Y-m-d")),t.length>0&&this.selectedDates!==s&&Livewire.dispatch("pg:datePicker-"+this.tableName,{selectedDates:t,dateStr:s,timezone:this.customConfig.timezone??new Date().toString().match(/([-\+][0-9]+)\s/)[1],type:this.type,field:this.dataField,label:this.label})},e}}),ze=i=>({theme:i.theme,id:i.id??null,dataField:i.dataField??null,content:i.content,fallback:i.fallback,inputClass:i.inputClass,saveOnMouseOut:i.saveOnMouseOut,oldContent:null,editable:!1,hash:null,hashError:!0,showEditable:!1,editableInput:"",init(){this.content.length===0&&this.fallback&&(this.content=this.htmlSpecialChars(this.fallback)),this.hash=this.dataField+"-"+this.id,window.addEventListener("toggle-"+this.hash,()=>{this.observe(()=>document.getElementById("clickable-"+this.hash),e=>{e.click(),this.observe(()=>document.getElementById("editable-"+this.hash),t=>{setTimeout(()=>this.setFocusToEnd(t),100)})})}),this.$watch("editable",e=>{if(e){let t=!1;if(this.showEditable=!1,this.content=this.htmlSpecialChars(this.content),this.oldContent=this.content,this.hashError=this.store().notContains(this.hash),this.observe(()=>document.getElementById("editable-"+this.hash),s=>{setTimeout(()=>{this.setFocusToEnd(s),this.store().getTextContent(this.hash)&&(s.textContent=this.store().getTextContent(this.hash))},30)}),this.hashError){const s=this.store().get(this.hash),n=document.getElementById("clickable-"+s);n&&n.click()}t=!0,this.editableInput=`
                <div
                    x-ref="editable"
                    x-text="content"
                    value="${this.content}"
                    placeholder="${this.content}"
                    contenteditable
                    class="pg-single-line ${this.inputClass}"
                    ${this.saveOnMouseOut?'x-on:mousedown.outside="save()"':""}
                    x-on:keydown.enter="save()"
                    id="${"editable-"+this.dataField+"-"+this.id}"
                    x-on:keydown.esc="cancel"
                >
                </div>`,this.$nextTick(()=>setTimeout(()=>{this.showEditable=t,this.focus()},150))}}),this.content=this.htmlSpecialChars(this.content)},store(){return window.editOnClickValidation},save(){this.store().clear(),this.store().set(this.hash,this.$el.textContent),this.observe(()=>document.getElementById("clickable-"+this.hash),e=>{e.textContent=this.$el.textContent}),window.addEventListener("pg:editable-close-"+this.id,()=>{this.store().clear(),this.editable=!1,this.showEditable=!1}),this.store().has(this.hash)||this.store().set(this.hash,this.$el.textContent),this.$wire.dispatch("pg:editable-"+this.$wire.tableName,{id:this.id,value:this.$el.textContent,field:this.dataField}),this.oldContent=this.store().getTextContent(this.hash),this.$nextTick(()=>{this.focus(),this.$el.setAttribute("value","")}),this.content=this.htmlSpecialChars(this.$el.textContent)},focus(){this.setFocusToEnd(this.$el)},cancel(){this.store().clear(),this.$refs.editable.textContent=this.oldContent,this.content=this.oldContent,this.editable=!1,this.showEditable=!1,this.$refs.error&&(this.$refs.error.innerHTML="")},htmlSpecialChars(e){const t=document.createElement("div");return t.innerHTML=e,t.textContent},observe(e,t){new MutationObserver((n,o)=>{for(let r of n)if(r.type==="childList"){const l=e();if(l){t(l),o.disconnect();break}}}).observe(document.body,{childList:!0,subtree:!0})},setFocusToEnd(e){if(!e)return;const t=window.getSelection(),s=document.createRange();s.selectNodeContents(e),s.collapse(!1),t.removeAllRanges(),t.addRange(s),e.focus()}});function je(i){i.querySelectorAll("tbody tr td").forEach(e=>{e.classList.remove("hidden")}),i.querySelectorAll("thead tr th").forEach(e=>{e.classList.remove("hidden")})}function Ke(i){let e=0;const t=i.querySelectorAll("table thead tr:nth-child(1) th[fixed]"),s=oe(i);return t.forEach(n=>{e+=oe(n)}),s-e}function qe(i,e){const t=[].slice.call(i.querySelectorAll("table thead tr:nth-child(1) th")),s=[].slice.call(t).sort(function(l,a){const c=l.getAttribute("sort_order")??999,d=a.getAttribute("sort_order")??999;return c-d});let n=0,o=!0;const r=[];return s.forEach(l=>{const a=oe(l);l.getAttribute("fixed")===null&&(o&&n<=e&&n+a<=e?n+=a:(r.push(t.indexOf(l)+1),o=!1))}),r}function Ue(i,e){for(const t of e)i.querySelectorAll(`tbody:not(tbody[expand]) tr td:nth-child(${t})`).forEach(s=>{s.classList.add("hidden")}),i.querySelectorAll(`thead tr th:nth-child(${t})`).forEach(s=>{s.classList.add("hidden")})}function Ye(i,e){var t,s;if(i.querySelectorAll("table tbody[expand] tr td div").length){for(const n of i.querySelectorAll("table tbody[expand] tr td div"))n.innerHTML="";if(e.length)for(const n of e){const o=i.querySelectorAll("table tbody:not(tbody[expand])");for(const r of o){const l=(t=r.nextElementSibling)==null?void 0:t.querySelector("tr td div");if(!l)continue;let a=i.querySelector(`table thead tr th:nth-child(${n}) span[data-value]`).textContent;const c=(s=r.querySelector(`tr:last-child td:nth-child(${n})`))==null?void 0:s.innerHTML;a.length&&(a+=":"),l.querySelector(`div[data-expand-item-${n}]`)||(l.innerHTML+=`<div class="responsive-row-expand-item-container" data-expand-item-${n}>
                    <span class="font-bold responsive-row-expand-item-name">${a}</span>
                    <span class="responsive-row-expand-item-value">${c}</span>
                </div>`)}}}}function oe(i){return parseFloat(i.getBoundingClientRect().width.toFixed(2))}function Ge(i){je(i);const e=Ke(i),t=qe(i,e);Ye(i,t),Ue(i,t)}const Qe=()=>({running:!1,expanded:null,element:null,hasHiddenElements:!1,size:0,toggleExpanded(i){this.expanded=this.expanded==i?null:i},init(){this.$nextTick(()=>{this.handleResize(),this.observeElement(),window.addEventListener("pg-livewire-request-finished",()=>{setTimeout(()=>this.handleResize(),5)})})},handleResize(){var e;const i=this.$el;Ge(i),this.hasHiddenElements=(e=i.querySelector("table tbody[expand] tr td div"))==null?void 0:e.innerHTML,this.hasHiddenElements||(this.expanded=null)},observeElement(){new ResizeObserver(e=>{e.forEach(t=>{if(t.contentRect.width>0){if(this.size===this.$el.getBoundingClientRect().width)return;this.size=this.$el.getBoundingClientRect().width,this.handleResize()}})}).observe(this.$el)}}),We=(i,e,t)=>{Livewire.dispatch(`${i}-${e.tableName}`,{label:e.label,field:e.dataField,values:t})},Ee=(i,e)=>{We("pg:multiSelect",i,e)};function Z(i,e){i.split(/\s+/).forEach(t=>{e(t)})}class Je{constructor(){this._events={}}on(e,t){Z(e,s=>{const n=this._events[s]||[];n.push(t),this._events[s]=n})}off(e,t){var s=arguments.length;if(s===0){this._events={};return}Z(e,n=>{if(s===1){delete this._events[n];return}const o=this._events[n];o!==void 0&&(o.splice(o.indexOf(t),1),this._events[n]=o)})}trigger(e,...t){var s=this;Z(e,n=>{const o=s._events[n];o!==void 0&&o.forEach(r=>{r.apply(s,t)})})}}function Xe(i){return i.plugins={},class extends i{constructor(){super(...arguments),this.plugins={names:[],settings:{},requested:{},loaded:{}}}static define(e,t){i.plugins[e]={name:e,fn:t}}initializePlugins(e){var t,s;const n=this,o=[];if(Array.isArray(e))e.forEach(r=>{typeof r=="string"?o.push(r):(n.plugins.settings[r.name]=r.options,o.push(r.name))});else if(e)for(t in e)e.hasOwnProperty(t)&&(n.plugins.settings[t]=e[t],o.push(t));for(;s=o.shift();)n.require(s)}loadPlugin(e){var t=this,s=t.plugins,n=i.plugins[e];if(!i.plugins.hasOwnProperty(e))throw new Error('Unable to find "'+e+'" plugin');s.requested[e]=!0,s.loaded[e]=n.fn.apply(t,[t.plugins.settings[e]||{}]),s.names.push(e)}require(e){var t=this,s=t.plugins;if(!t.plugins.loaded.hasOwnProperty(e)){if(s.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")');t.loadPlugin(e)}return s.loaded[e]}}}const X=i=>(i=i.filter(Boolean),i.length<2?i[0]||"":et(i)==1?"["+i.join("")+"]":"(?:"+i.join("|")+")"),xe=i=>{if(!Ze(i))return i.join("");let e="",t=0;const s=()=>{t>1&&(e+="{"+t+"}")};return i.forEach((n,o)=>{if(n===i[o-1]){t++;return}s(),e+=n,t=1}),s(),e},Ie=i=>{let e=Array.from(i);return X(e)},Ze=i=>new Set(i).size!==i.length,V=i=>(i+"").replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu,"\\$1"),et=i=>i.reduce((e,t)=>Math.max(e,tt(t)),0),tt=i=>Array.from(i).length,Le=i=>{if(i.length===1)return[[i]];let e=[];const t=i.substring(1);return Le(t).forEach(function(n){let o=n.slice(0);o[0]=i.charAt(0)+o[0],e.push(o),o=n.slice(0),o.unshift(i.charAt(0)),e.push(o)}),e},it=[[0,65535]],st="[̀-ͯ·ʾʼ]";let Q,ke;const nt=3,ae={},ce={"/":"⁄∕",0:"߀",a:"ⱥɐɑ",aa:"ꜳ",ae:"æǽǣ",ao:"ꜵ",au:"ꜷ",av:"ꜹꜻ",ay:"ꜽ",b:"ƀɓƃ",c:"ꜿƈȼↄ",d:"đɗɖᴅƌꮷԁɦ",e:"ɛǝᴇɇ",f:"ꝼƒ",g:"ǥɠꞡᵹꝿɢ",h:"ħⱨⱶɥ",i:"ɨı",j:"ɉȷ",k:"ƙⱪꝁꝃꝅꞣ",l:"łƚɫⱡꝉꝇꞁɭ",m:"ɱɯϻ",n:"ꞥƞɲꞑᴎлԉ",o:"øǿɔɵꝋꝍᴑ",oe:"œ",oi:"ƣ",oo:"ꝏ",ou:"ȣ",p:"ƥᵽꝑꝓꝕρ",q:"ꝗꝙɋ",r:"ɍɽꝛꞧꞃ",s:"ßȿꞩꞅʂ",t:"ŧƭʈⱦꞇ",th:"þ",tz:"ꜩ",u:"ʉ",v:"ʋꝟʌ",vy:"ꝡ",w:"ⱳ",y:"ƴɏỿ",z:"ƶȥɀⱬꝣ",hv:"ƕ"};for(let i in ce){let e=ce[i]||"";for(let t=0;t<e.length;t++){let s=e.substring(t,t+1);ae[s]=i}}const rt=new RegExp(Object.keys(ae).join("|")+"|"+st,"gu"),ot=i=>{Q===void 0&&(Q=dt(it))},de=(i,e="NFKD")=>i.normalize(e),W=i=>Array.from(i).reduce((e,t)=>e+lt(t),""),lt=i=>(i=de(i).toLowerCase().replace(rt,e=>ae[e]||""),de(i,"NFC"));function*at(i){for(const[e,t]of i)for(let s=e;s<=t;s++){let n=String.fromCharCode(s),o=W(n);o!=n.toLowerCase()&&(o.length>nt||o.length!=0&&(yield{folded:o,composed:n,code_point:s}))}}const ct=i=>{const e={},t=(s,n)=>{const o=e[s]||new Set,r=new RegExp("^"+Ie(o)+"$","iu");n.match(r)||(o.add(V(n)),e[s]=o)};for(let s of at(i))t(s.folded,s.folded),t(s.folded,s.composed);return e},dt=i=>{const e=ct(i),t={};let s=[];for(let o in e){let r=e[o];r&&(t[o]=Ie(r)),o.length>1&&s.push(V(o))}s.sort((o,r)=>r.length-o.length);const n=X(s);return ke=new RegExp("^"+n,"u"),t},ut=(i,e=1)=>{let t=0;return i=i.map(s=>(Q[s]&&(t+=s.length),Q[s]||s)),t>=e?xe(i):""},ft=(i,e=1)=>(e=Math.max(e,i.length-1),X(Le(i).map(t=>ut(t,e)))),ue=(i,e=!0)=>{let t=i.length>1?1:0;return X(i.map(s=>{let n=[];const o=e?s.length():s.length()-1;for(let r=0;r<o;r++)n.push(ft(s.substrs[r]||"",t));return xe(n)}))},pt=(i,e)=>{for(const t of e){if(t.start!=i.start||t.end!=i.end||t.substrs.join("")!==i.substrs.join(""))continue;let s=i.parts;const n=r=>{for(const l of s){if(l.start===r.start&&l.substr===r.substr)return!1;if(!(r.length==1||l.length==1)&&(r.start<l.start&&r.end>l.start||l.start<r.start&&l.end>r.start))return!0}return!1};if(!(t.parts.filter(n).length>0))return!0}return!1};class J{constructor(){P(this,"parts");P(this,"substrs");P(this,"start");P(this,"end");this.parts=[],this.substrs=[],this.start=0,this.end=0}add(e){e&&(this.parts.push(e),this.substrs.push(e.substr),this.start=Math.min(e.start,this.start),this.end=Math.max(e.end,this.end))}last(){return this.parts[this.parts.length-1]}length(){return this.parts.length}clone(e,t){let s=new J,n=JSON.parse(JSON.stringify(this.parts)),o=n.pop();for(const a of n)s.add(a);let r=t.substr.substring(0,e-o.start),l=r.length;return s.add({start:o.start,end:o.start+l,length:l,substr:r}),s}}const ht=i=>{ot(),i=W(i);let e="",t=[new J];for(let s=0;s<i.length;s++){let o=i.substring(s).match(ke);const r=i.substring(s,s+1),l=o?o[0]:null;let a=[],c=new Set;for(const d of t){const u=d.last();if(!u||u.length==1||u.end<=s)if(l){const f=l.length;d.add({start:s,end:s+f,length:f,substr:l}),c.add("1")}else d.add({start:s,end:s+1,length:1,substr:r}),c.add("2");else if(l){let f=d.clone(s,u);const w=l.length;f.add({start:s,end:s+w,length:w,substr:l}),a.push(f)}else c.add("3")}if(a.length>0){a=a.sort((d,u)=>d.length()-u.length());for(let d of a)pt(d,t)||t.push(d);continue}if(s>0&&c.size==1&&!c.has("3")){e+=ue(t,!1);let d=new J;const u=t[0];u&&d.add(u.last()),t=[d]}}return e+=ue(t,!0),e},gt=(i,e)=>{if(i)return i[e]},mt=(i,e)=>{if(i){for(var t,s=e.split(".");(t=s.shift())&&(i=i[t]););return i}},ee=(i,e,t)=>{var s,n;return!i||(i=i+"",e.regex==null)||(n=i.search(e.regex),n===-1)?0:(s=e.string.length/i.length,n===0&&(s+=.5),s*t)},te=(i,e)=>{var t=i[e];if(typeof t=="function")return t;t&&!Array.isArray(t)&&(i[e]=[t])},K=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},vt=(i,e)=>typeof i=="number"&&typeof e=="number"?i>e?1:i<e?-1:0:(i=W(i+"").toLowerCase(),e=W(e+"").toLowerCase(),i>e?1:e>i?-1:0);class wt{constructor(e,t){P(this,"items");P(this,"settings");this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t,s){if(!e||!e.length)return[];const n=[],o=e.split(/\s+/);var r;return s&&(r=new RegExp("^("+Object.keys(s).map(V).join("|")+"):(.*)$")),o.forEach(l=>{let a,c=null,d=null;r&&(a=l.match(r))&&(c=a[1],l=a[2]),l.length>0&&(this.settings.diacritics?d=ht(l)||null:d=V(l),d&&t&&(d="\\b"+d)),n.push({string:l,regex:d?new RegExp(d,"iu"):null,field:c})}),n}getScoreFunction(e,t){var s=this.prepareSearch(e,t);return this._getScoreFunction(s)}_getScoreFunction(e){const t=e.tokens,s=t.length;if(!s)return function(){return 0};const n=e.options.fields,o=e.weights,r=n.length,l=e.getAttrFn;if(!r)return function(){return 1};const a=function(){return r===1?function(c,d){const u=n[0].field;return ee(l(d,u),c,o[u]||1)}:function(c,d){var u=0;if(c.field){const f=l(d,c.field);!c.regex&&f?u+=1/r:u+=ee(f,c,1)}else K(o,(f,w)=>{u+=ee(l(d,w),c,f)});return u/r}}();return s===1?function(c){return a(t[0],c)}:e.options.conjunction==="and"?function(c){var d,u=0;for(let f of t){if(d=a(f,c),d<=0)return 0;u+=d}return u/s}:function(c){var d=0;return K(t,u=>{d+=a(u,c)}),d/s}}getSortFunction(e,t){var s=this.prepareSearch(e,t);return this._getSortFunction(s)}_getSortFunction(e){var t,s=[];const n=this,o=e.options,r=!e.query&&o.sort_empty?o.sort_empty:o.sort;if(typeof r=="function")return r.bind(this);const l=function(c,d){return c==="$score"?d.score:e.getAttrFn(n.items[d.id],c)};if(r)for(let c of r)(e.query||c.field!=="$score")&&s.push(c);if(e.query){t=!0;for(let c of s)if(c.field==="$score"){t=!1;break}t&&s.unshift({field:"$score",direction:"desc"})}else s=s.filter(c=>c.field!=="$score");return s.length?function(c,d){var u,f;for(let w of s)if(f=w.field,u=(w.direction==="desc"?-1:1)*vt(l(f,c),l(f,d)),u)return u;return 0}:null}prepareSearch(e,t){const s={};var n=Object.assign({},t);if(te(n,"sort"),te(n,"sort_empty"),n.fields){te(n,"fields");const o=[];n.fields.forEach(r=>{typeof r=="string"&&(r={field:r,weight:1}),o.push(r),s[r.field]="weight"in r?r.weight:1}),n.fields=o}return{options:n,query:e.toLowerCase().trim(),tokens:this.tokenize(e,n.respect_word_boundaries,s),total:0,items:[],weights:s,getAttrFn:n.nesting?mt:gt}}search(e,t){var s=this,n,o;o=this.prepareSearch(e,t),t=o.options,e=o.query;const r=t.score||s._getScoreFunction(o);e.length?K(s.items,(a,c)=>{n=r(a),(t.filter===!1||n>0)&&o.items.push({score:n,id:c})}):K(s.items,(a,c)=>{o.items.push({score:1,id:c})});const l=s._getSortFunction(o);return l&&o.items.sort(l),o.total=o.items.length,typeof t.limit=="number"&&(o.items=o.items.slice(0,t.limit)),o}}const k=i=>typeof i>"u"||i===null?null:G(i),G=i=>typeof i=="boolean"?i?"1":"0":i+"",ie=i=>(i+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),bt=(i,e)=>e>0?window.setTimeout(i,e):(i.call(null),null),_t=(i,e)=>{var t;return function(s,n){var o=this;t&&(o.loading=Math.max(o.loading-1,0),clearTimeout(t)),t=setTimeout(function(){t=null,o.loadedSearches[s]=!0,i.call(o,s,n)},e)}},fe=(i,e,t)=>{var s,n=i.trigger,o={};i.trigger=function(){var r=arguments[0];if(e.indexOf(r)!==-1)o[r]=arguments;else return n.apply(i,arguments)},t.apply(i,[]),i.trigger=n;for(s of e)s in o&&n.apply(i,o[s])},yt=i=>({start:i.selectionStart||0,length:(i.selectionEnd||0)-(i.selectionStart||0)}),S=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},x=(i,e,t,s)=>{i.addEventListener(e,t,s)},D=(i,e)=>{if(!e||!e[i])return!1;var t=(e.altKey?1:0)+(e.ctrlKey?1:0)+(e.shiftKey?1:0)+(e.metaKey?1:0);return t===1},se=(i,e)=>{const t=i.getAttribute("id");return t||(i.setAttribute("id",e),e)},pe=i=>i.replace(/[\\"']/g,"\\$&"),M=(i,e)=>{e&&i.append(e)},$=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},T=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(Fe(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},Fe=i=>typeof i=="string"&&i.indexOf("<")>-1,Ot=i=>i.replace(/['"\\]/g,"\\$&"),ne=(i,e)=>{var t=document.createEvent("HTMLEvents");t.initEvent(e,!0,!1),i.dispatchEvent(t)},q=(i,e)=>{Object.assign(i.style,e)},L=(i,...e)=>{var t=Te(e);i=He(i),i.map(s=>{t.map(n=>{s.classList.add(n)})})},H=(i,...e)=>{var t=Te(e);i=He(i),i.map(s=>{t.map(n=>{s.classList.remove(n)})})},Te=i=>{var e=[];return $(i,t=>{typeof t=="string"&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},He=i=>(Array.isArray(i)||(i=[i]),i),re=(i,e,t)=>{if(!(t&&!t.contains(i)))for(;i&&i.matches;){if(i.matches(e))return i;i=i.parentNode}},he=(i,e=0)=>e>0?i[i.length-1]:i[0],At=i=>Object.keys(i).length===0,ge=(i,e)=>{if(!i)return-1;e=e||i.nodeName;for(var t=0;i=i.previousElementSibling;)i.matches(e)&&t++;return t},A=(i,e)=>{$(e,(t,s)=>{t==null?i.removeAttribute(s):i.setAttribute(s,""+t)})},le=(i,e)=>{i.parentNode&&i.parentNode.replaceChild(e,i)},Ct=(i,e)=>{if(e===null)return;if(typeof e=="string"){if(!e.length)return;e=new RegExp(e,"i")}const t=o=>{var r=o.data.match(e);if(r&&o.data.length>0){var l=document.createElement("span");l.className="highlight";var a=o.splitText(r.index);a.splitText(r[0].length);var c=a.cloneNode(!0);return l.appendChild(c),le(a,l),1}return 0},s=o=>{o.nodeType===1&&o.childNodes&&!/(script|style)/i.test(o.tagName)&&(o.className!=="highlight"||o.tagName!=="SPAN")&&Array.from(o.childNodes).forEach(r=>{n(r)})},n=o=>o.nodeType===3?t(o):(s(o),0);n(i)},St=i=>{var e=i.querySelectorAll("span.highlight");Array.prototype.forEach.call(e,function(t){var s=t.parentNode;s.replaceChild(t.firstChild,t),s.normalize()})},$t=65,Et=13,xt=27,It=37,Lt=38,kt=39,Ft=40,me=8,Tt=46,ve=9,Ht=typeof navigator>"u"?!1:/Mac/.test(navigator.userAgent),U=Ht?"metaKey":"ctrlKey",we={options:[],optgroups:[],plugins:[],delimiter:",",splitOn:null,persist:!0,diacritics:!0,create:null,createOnBlur:!1,createFilter:null,highlight:!0,openOnFocus:!0,shouldOpen:null,maxOptions:50,maxItems:null,hideSelected:null,duplicates:!1,addPrecedence:!1,selectOnTab:!1,preload:null,allowEmptyOption:!1,refreshThrottle:300,loadThrottle:300,loadingClass:"loading",dataAttr:null,optgroupField:"optgroup",valueField:"value",labelField:"text",disabledField:"disabled",optgroupLabelField:"label",optgroupValueField:"value",lockOptgroupOrder:!1,sortField:"$order",searchField:["text"],searchConjunction:"and",mode:null,wrapperClass:"ts-wrapper",controlClass:"ts-control",dropdownClass:"ts-dropdown",dropdownContentClass:"ts-dropdown-content",itemClass:"item",optionClass:"option",dropdownParent:null,controlInput:'<input type="text" autocomplete="off" size="1" />',copyClassesToDropdown:!1,placeholder:null,hidePlaceholder:null,shouldLoad:function(i){return i.length>0},render:{}};function be(i,e){var t=Object.assign({},we,e),s=t.dataAttr,n=t.labelField,o=t.valueField,r=t.disabledField,l=t.optgroupField,a=t.optgroupLabelField,c=t.optgroupValueField,d=i.tagName.toLowerCase(),u=i.getAttribute("placeholder")||i.getAttribute("data-placeholder");if(!u&&!t.allowEmptyOption){let v=i.querySelector('option[value=""]');v&&(u=v.textContent)}var f={placeholder:u,options:[],optgroups:[],items:[],maxItems:null},w=()=>{var v,O=f.options,_={},h=1;let C=0;var F=m=>{var b=Object.assign({},m.dataset),g=s&&b[s];return typeof g=="string"&&g.length&&(b=Object.assign(b,JSON.parse(g))),b},B=(m,b)=>{var g=k(m.value);if(g!=null&&!(!g&&!t.allowEmptyOption)){if(_.hasOwnProperty(g)){if(b){var E=_[g][l];E?Array.isArray(E)?E.push(b):_[g][l]=[E,b]:_[g][l]=b}}else{var y=F(m);y[n]=y[n]||m.textContent,y[o]=y[o]||g,y[r]=y[r]||m.disabled,y[l]=y[l]||b,y.$option=m,y.$order=y.$order||++C,_[g]=y,O.push(y)}m.selected&&f.items.push(g)}},R=m=>{var b,g;g=F(m),g[a]=g[a]||m.getAttribute("label")||"",g[c]=g[c]||h++,g[r]=g[r]||m.disabled,g.$order=g.$order||++C,f.optgroups.push(g),b=g[c],$(m.children,E=>{B(E,b)})};f.maxItems=i.hasAttribute("multiple")?null:1,$(i.children,m=>{v=m.tagName.toLowerCase(),v==="optgroup"?R(m):v==="option"&&B(m)})},p=()=>{const v=i.getAttribute(s);if(v)f.options=JSON.parse(v),$(f.options,_=>{f.items.push(_[o])});else{var O=i.value.trim()||"";if(!t.allowEmptyOption&&!O.length)return;const _=O.split(t.delimiter);$(_,h=>{const C={};C[n]=h,C[o]=h,f.options.push(C)}),f.items=_}};return d==="select"?w():p(),Object.assign({},we,f,e)}var _e=0;class I extends Xe(Je){constructor(e,t){super(),this.order=0,this.isOpen=!1,this.isDisabled=!1,this.isReadOnly=!1,this.isInvalid=!1,this.isValid=!0,this.isLocked=!1,this.isFocused=!1,this.isInputHidden=!1,this.isSetup=!1,this.ignoreFocus=!1,this.ignoreHover=!1,this.hasOptions=!1,this.lastValue="",this.caretPos=0,this.loading=0,this.loadedSearches={},this.activeOption=null,this.activeItems=[],this.optgroups={},this.options={},this.userOptions={},this.items=[],this.refreshTimeout=null,_e++;var s,n=T(e);if(n.tomselect)throw new Error("Tom Select already initialized on this element");n.tomselect=this;var o=window.getComputedStyle&&window.getComputedStyle(n,null);s=o.getPropertyValue("direction");const r=be(n,t);this.settings=r,this.input=n,this.tabIndex=n.tabIndex||0,this.is_select_tag=n.tagName.toLowerCase()==="select",this.rtl=/rtl/i.test(s),this.inputId=se(n,"tomselect-"+_e),this.isRequired=n.required,this.sifter=new wt(this.options,{diacritics:r.diacritics}),r.mode=r.mode||(r.maxItems===1?"single":"multi"),typeof r.hideSelected!="boolean"&&(r.hideSelected=r.mode==="multi"),typeof r.hidePlaceholder!="boolean"&&(r.hidePlaceholder=r.mode!=="multi");var l=r.createFilter;typeof l!="function"&&(typeof l=="string"&&(l=new RegExp(l)),l instanceof RegExp?r.createFilter=O=>l.test(O):r.createFilter=O=>this.settings.duplicates||!this.options[O]),this.initializePlugins(r.plugins),this.setupCallbacks(),this.setupTemplates();const a=T("<div>"),c=T("<div>"),d=this._render("dropdown"),u=T('<div role="listbox" tabindex="-1">'),f=this.input.getAttribute("class")||"",w=r.mode;var p;if(L(a,r.wrapperClass,f,w),L(c,r.controlClass),M(a,c),L(d,r.dropdownClass,w),r.copyClassesToDropdown&&L(d,f),L(u,r.dropdownContentClass),M(d,u),T(r.dropdownParent||a).appendChild(d),Fe(r.controlInput)){p=T(r.controlInput);var v=["autocorrect","autocapitalize","autocomplete","spellcheck"];$(v,O=>{n.getAttribute(O)&&A(p,{[O]:n.getAttribute(O)})}),p.tabIndex=-1,c.appendChild(p),this.focus_node=p}else r.controlInput?(p=T(r.controlInput),this.focus_node=p):(p=T("<input/>"),this.focus_node=c);this.wrapper=a,this.dropdown=d,this.dropdown_content=u,this.control=c,this.control_input=p,this.setup()}setup(){const e=this,t=e.settings,s=e.control_input,n=e.dropdown,o=e.dropdown_content,r=e.wrapper,l=e.control,a=e.input,c=e.focus_node,d={passive:!0},u=e.inputId+"-ts-dropdown";A(o,{id:u}),A(c,{role:"combobox","aria-haspopup":"listbox","aria-expanded":"false","aria-controls":u});const f=se(c,e.inputId+"-ts-control"),w="label[for='"+Ot(e.inputId)+"']",p=document.querySelector(w),v=e.focus.bind(e);if(p){x(p,"click",v),A(p,{for:f});const h=se(p,e.inputId+"-ts-label");A(c,{"aria-labelledby":h}),A(o,{"aria-labelledby":h})}if(r.style.width=a.style.width,e.plugins.names.length){const h="plugin-"+e.plugins.names.join(" plugin-");L([r,n],h)}(t.maxItems===null||t.maxItems>1)&&e.is_select_tag&&A(a,{multiple:"multiple"}),t.placeholder&&A(s,{placeholder:t.placeholder}),!t.splitOn&&t.delimiter&&(t.splitOn=new RegExp("\\s*"+V(t.delimiter)+"+\\s*")),t.load&&t.loadThrottle&&(t.load=_t(t.load,t.loadThrottle)),x(n,"mousemove",()=>{e.ignoreHover=!1}),x(n,"mouseenter",h=>{var C=re(h.target,"[data-selectable]",n);C&&e.onOptionHover(h,C)},{capture:!0}),x(n,"click",h=>{const C=re(h.target,"[data-selectable]");C&&(e.onOptionSelect(h,C),S(h,!0))}),x(l,"click",h=>{var C=re(h.target,"[data-ts-item]",l);if(C&&e.onItemSelect(h,C)){S(h,!0);return}s.value==""&&(e.onClick(),S(h,!0))}),x(c,"keydown",h=>e.onKeyDown(h)),x(s,"keypress",h=>e.onKeyPress(h)),x(s,"input",h=>e.onInput(h)),x(c,"blur",h=>e.onBlur(h)),x(c,"focus",h=>e.onFocus(h)),x(s,"paste",h=>e.onPaste(h));const O=h=>{const C=h.composedPath()[0];if(!r.contains(C)&&!n.contains(C)){e.isFocused&&e.blur(),e.inputState();return}C==s&&e.isOpen?h.stopPropagation():S(h,!0)},_=()=>{e.isOpen&&e.positionDropdown()};x(document,"mousedown",O),x(window,"scroll",_,d),x(window,"resize",_,d),this._destroy=()=>{document.removeEventListener("mousedown",O),window.removeEventListener("scroll",_),window.removeEventListener("resize",_),p&&p.removeEventListener("click",v)},this.revertSettings={innerHTML:a.innerHTML,tabIndex:a.tabIndex},a.tabIndex=-1,a.insertAdjacentElement("afterend",e.wrapper),e.sync(!1),t.items=[],delete t.optgroups,delete t.options,x(a,"invalid",()=>{e.isValid&&(e.isValid=!1,e.isInvalid=!0,e.refreshState())}),e.updateOriginalInput(),e.refreshItems(),e.close(!1),e.inputState(),e.isSetup=!0,a.disabled?e.disable():a.readOnly?e.setReadOnly(!0):e.enable(),e.on("change",this.onChange),L(a,"tomselected","ts-hidden-accessible"),e.trigger("initialize"),t.preload===!0&&e.preload()}setupOptions(e=[],t=[]){this.addOptions(e),$(t,s=>{this.registerOptionGroup(s)})}setupTemplates(){var e=this,t=e.settings.labelField,s=e.settings.optgroupLabelField,n={optgroup:o=>{let r=document.createElement("div");return r.className="optgroup",r.appendChild(o.options),r},optgroup_header:(o,r)=>'<div class="optgroup-header">'+r(o[s])+"</div>",option:(o,r)=>"<div>"+r(o[t])+"</div>",item:(o,r)=>"<div>"+r(o[t])+"</div>",option_create:(o,r)=>'<div class="create">Add <strong>'+r(o.input)+"</strong>&hellip;</div>",no_results:()=>'<div class="no-results">No results found</div>',loading:()=>'<div class="spinner"></div>',not_loading:()=>{},dropdown:()=>"<div></div>"};e.settings.render=Object.assign({},n,e.settings.render)}setupCallbacks(){var e,t,s={initialize:"onInitialize",change:"onChange",item_add:"onItemAdd",item_remove:"onItemRemove",item_select:"onItemSelect",clear:"onClear",option_add:"onOptionAdd",option_remove:"onOptionRemove",option_clear:"onOptionClear",optgroup_add:"onOptionGroupAdd",optgroup_remove:"onOptionGroupRemove",optgroup_clear:"onOptionGroupClear",dropdown_open:"onDropdownOpen",dropdown_close:"onDropdownClose",type:"onType",load:"onLoad",focus:"onFocus",blur:"onBlur"};for(e in s)t=this.settings[s[e]],t&&this.on(e,t)}sync(e=!0){const t=this,s=e?be(t.input,{delimiter:t.settings.delimiter}):t.settings;t.setupOptions(s.options,s.optgroups),t.setValue(s.items||[],!0),t.lastQuery=null}onClick(){var e=this;if(e.activeItems.length>0){e.clearActiveItems(),e.focus();return}e.isFocused&&e.isOpen?e.blur():e.focus()}onMouseDown(){}onChange(){ne(this.input,"input"),ne(this.input,"change")}onPaste(e){var t=this;if(t.isInputHidden||t.isLocked){S(e);return}t.settings.splitOn&&setTimeout(()=>{var s=t.inputValue();if(s.match(t.settings.splitOn)){var n=s.trim().split(t.settings.splitOn);$(n,o=>{k(o)&&(this.options[o]?t.addItem(o):t.createItem(o))})}},0)}onKeyPress(e){var t=this;if(t.isLocked){S(e);return}var s=String.fromCharCode(e.keyCode||e.which);if(t.settings.create&&t.settings.mode==="multi"&&s===t.settings.delimiter){t.createItem(),S(e);return}}onKeyDown(e){var t=this;if(t.ignoreHover=!0,t.isLocked){e.keyCode!==ve&&S(e);return}switch(e.keyCode){case $t:if(D(U,e)&&t.control_input.value==""){S(e),t.selectAll();return}break;case xt:t.isOpen&&(S(e,!0),t.close()),t.clearActiveItems();return;case Ft:if(!t.isOpen&&t.hasOptions)t.open();else if(t.activeOption){let s=t.getAdjacent(t.activeOption,1);s&&t.setActiveOption(s)}S(e);return;case Lt:if(t.activeOption){let s=t.getAdjacent(t.activeOption,-1);s&&t.setActiveOption(s)}S(e);return;case Et:t.canSelect(t.activeOption)?(t.onOptionSelect(e,t.activeOption),S(e)):(t.settings.create&&t.createItem()||document.activeElement==t.control_input&&t.isOpen)&&S(e);return;case It:t.advanceSelection(-1,e);return;case kt:t.advanceSelection(1,e);return;case ve:t.settings.selectOnTab&&(t.canSelect(t.activeOption)&&(t.onOptionSelect(e,t.activeOption),S(e)),t.settings.create&&t.createItem()&&S(e));return;case me:case Tt:t.deleteSelection(e);return}t.isInputHidden&&!D(U,e)&&S(e)}onInput(e){if(this.isLocked)return;const t=this.inputValue();if(this.lastValue!==t){if(this.lastValue=t,t==""){this._onInput();return}this.refreshTimeout&&window.clearTimeout(this.refreshTimeout),this.refreshTimeout=bt(()=>{this.refreshTimeout=null,this._onInput()},this.settings.refreshThrottle)}}_onInput(){const e=this.lastValue;this.settings.shouldLoad.call(this,e)&&this.load(e),this.refreshOptions(),this.trigger("type",e)}onOptionHover(e,t){this.ignoreHover||this.setActiveOption(t,!1)}onFocus(e){var t=this,s=t.isFocused;if(t.isDisabled||t.isReadOnly){t.blur(),S(e);return}t.ignoreFocus||(t.isFocused=!0,t.settings.preload==="focus"&&t.preload(),s||t.trigger("focus"),t.activeItems.length||(t.inputState(),t.refreshOptions(!!t.settings.openOnFocus)),t.refreshState())}onBlur(e){if(document.hasFocus()!==!1){var t=this;if(t.isFocused){t.isFocused=!1,t.ignoreFocus=!1;var s=()=>{t.close(),t.setActiveItem(),t.setCaret(t.items.length),t.trigger("blur")};t.settings.create&&t.settings.createOnBlur?t.createItem(null,s):s()}}}onOptionSelect(e,t){var s,n=this;t.parentElement&&t.parentElement.matches("[data-disabled]")||(t.classList.contains("create")?n.createItem(null,()=>{n.settings.closeAfterSelect&&n.close()}):(s=t.dataset.value,typeof s<"u"&&(n.lastQuery=null,n.addItem(s),n.settings.closeAfterSelect&&n.close(),!n.settings.hideSelected&&e.type&&/click/.test(e.type)&&n.setActiveOption(t))))}canSelect(e){return!!(this.isOpen&&e&&this.dropdown_content.contains(e))}onItemSelect(e,t){var s=this;return!s.isLocked&&s.settings.mode==="multi"?(S(e),s.setActiveItem(t,e),!0):!1}canLoad(e){return!(!this.settings.load||this.loadedSearches.hasOwnProperty(e))}load(e){const t=this;if(!t.canLoad(e))return;L(t.wrapper,t.settings.loadingClass),t.loading++;const s=t.loadCallback.bind(t);t.settings.load.call(t,e,s)}loadCallback(e,t){const s=this;s.loading=Math.max(s.loading-1,0),s.lastQuery=null,s.clearActiveOption(),s.setupOptions(e,t),s.refreshOptions(s.isFocused&&!s.isInputHidden),s.loading||H(s.wrapper,s.settings.loadingClass),s.trigger("load",e,t)}preload(){var e=this.wrapper.classList;e.contains("preloaded")||(e.add("preloaded"),this.load(""))}setTextboxValue(e=""){var t=this.control_input,s=t.value!==e;s&&(t.value=e,ne(t,"update"),this.lastValue=e)}getValue(){return this.is_select_tag&&this.input.hasAttribute("multiple")?this.items:this.items.join(this.settings.delimiter)}setValue(e,t){var s=t?[]:["change"];fe(this,s,()=>{this.clear(t),this.addItems(e,t)})}setMaxItems(e){e===0&&(e=null),this.settings.maxItems=e,this.refreshState()}setActiveItem(e,t){var s=this,n,o,r,l,a,c;if(s.settings.mode!=="single"){if(!e){s.clearActiveItems(),s.isFocused&&s.inputState();return}if(n=t&&t.type.toLowerCase(),n==="click"&&D("shiftKey",t)&&s.activeItems.length){for(c=s.getLastActive(),r=Array.prototype.indexOf.call(s.control.children,c),l=Array.prototype.indexOf.call(s.control.children,e),r>l&&(a=r,r=l,l=a),o=r;o<=l;o++)e=s.control.children[o],s.activeItems.indexOf(e)===-1&&s.setActiveItemClass(e);S(t)}else n==="click"&&D(U,t)||n==="keydown"&&D("shiftKey",t)?e.classList.contains("active")?s.removeActiveItem(e):s.setActiveItemClass(e):(s.clearActiveItems(),s.setActiveItemClass(e));s.inputState(),s.isFocused||s.focus()}}setActiveItemClass(e){const t=this,s=t.control.querySelector(".last-active");s&&H(s,"last-active"),L(e,"active last-active"),t.trigger("item_select",e),t.activeItems.indexOf(e)==-1&&t.activeItems.push(e)}removeActiveItem(e){var t=this.activeItems.indexOf(e);this.activeItems.splice(t,1),H(e,"active")}clearActiveItems(){H(this.activeItems,"active"),this.activeItems=[]}setActiveOption(e,t=!0){e!==this.activeOption&&(this.clearActiveOption(),e&&(this.activeOption=e,A(this.focus_node,{"aria-activedescendant":e.getAttribute("id")}),A(e,{"aria-selected":"true"}),L(e,"active"),t&&this.scrollToOption(e)))}scrollToOption(e,t){if(!e)return;const s=this.dropdown_content,n=s.clientHeight,o=s.scrollTop||0,r=e.offsetHeight,l=e.getBoundingClientRect().top-s.getBoundingClientRect().top+o;l+r>n+o?this.scroll(l-n+r,t):l<o&&this.scroll(l,t)}scroll(e,t){const s=this.dropdown_content;t&&(s.style.scrollBehavior=t),s.scrollTop=e,s.style.scrollBehavior=""}clearActiveOption(){this.activeOption&&(H(this.activeOption,"active"),A(this.activeOption,{"aria-selected":null})),this.activeOption=null,A(this.focus_node,{"aria-activedescendant":null})}selectAll(){const e=this;if(e.settings.mode==="single")return;const t=e.controlChildren();t.length&&(e.inputState(),e.close(),e.activeItems=t,$(t,s=>{e.setActiveItemClass(s)}))}inputState(){var e=this;e.control.contains(e.control_input)&&(A(e.control_input,{placeholder:e.settings.placeholder}),e.activeItems.length>0||!e.isFocused&&e.settings.hidePlaceholder&&e.items.length>0?(e.setTextboxValue(),e.isInputHidden=!0):(e.settings.hidePlaceholder&&e.items.length>0&&A(e.control_input,{placeholder:""}),e.isInputHidden=!1),e.wrapper.classList.toggle("input-hidden",e.isInputHidden))}inputValue(){return this.control_input.value.trim()}focus(){var e=this;e.isDisabled||e.isReadOnly||(e.ignoreFocus=!0,e.control_input.offsetWidth?e.control_input.focus():e.focus_node.focus(),setTimeout(()=>{e.ignoreFocus=!1,e.onFocus()},0))}blur(){this.focus_node.blur(),this.onBlur()}getScoreFunction(e){return this.sifter.getScoreFunction(e,this.getSearchOptions())}getSearchOptions(){var e=this.settings,t=e.sortField;return typeof e.sortField=="string"&&(t=[{field:e.sortField}]),{fields:e.searchField,conjunction:e.searchConjunction,sort:t,nesting:e.nesting}}search(e){var t,s,n=this,o=this.getSearchOptions();if(n.settings.score&&(s=n.settings.score.call(n,e),typeof s!="function"))throw new Error('Tom Select "score" setting must be a function that returns a function');return e!==n.lastQuery?(n.lastQuery=e,t=n.sifter.search(e,Object.assign(o,{score:s})),n.currentResults=t):t=Object.assign({},n.currentResults),n.settings.hideSelected&&(t.items=t.items.filter(r=>{let l=k(r.id);return!(l&&n.items.indexOf(l)!==-1)})),t}refreshOptions(e=!0){var t,s,n,o,r,l,a,c,d,u;const f={},w=[];var p=this,v=p.inputValue();const O=v===p.lastQuery||v==""&&p.lastQuery==null;var _=p.search(v),h=null,C=p.settings.shouldOpen||!1,F=p.dropdown_content;O&&(h=p.activeOption,h&&(d=h.closest("[data-group]"))),o=_.items.length,typeof p.settings.maxOptions=="number"&&(o=Math.min(o,p.settings.maxOptions)),o>0&&(C=!0);const B=(m,b)=>{let g=f[m];if(g!==void 0){let y=w[g];if(y!==void 0)return[g,y.fragment]}let E=document.createDocumentFragment();return g=w.length,w.push({fragment:E,order:b,optgroup:m}),[g,E]};for(t=0;t<o;t++){let m=_.items[t];if(!m)continue;let b=m.id,g=p.options[b];if(g===void 0)continue;let E=G(b),y=p.getOption(E,!0);for(p.settings.hideSelected||y.classList.toggle("selected",p.items.includes(E)),r=g[p.settings.optgroupField]||"",l=Array.isArray(r)?r:[r],s=0,n=l&&l.length;s<n;s++){r=l[s];let z=g.$order,j=p.optgroups[r];j===void 0?r="":z=j.$order;const[Pe,De]=B(r,z);s>0&&(y=y.cloneNode(!0),A(y,{id:g.$id+"-clone-"+s,"aria-selected":null}),y.classList.add("ts-cloned"),H(y,"active"),p.activeOption&&p.activeOption.dataset.value==b&&d&&d.dataset.group===r.toString()&&(h=y)),De.appendChild(y),r!=""&&(f[r]=Pe)}}p.settings.lockOptgroupOrder&&w.sort((m,b)=>m.order-b.order),a=document.createDocumentFragment(),$(w,m=>{let b=m.fragment,g=m.optgroup;if(!b||!b.children.length)return;let E=p.optgroups[g];if(E!==void 0){let y=document.createDocumentFragment(),z=p.render("optgroup_header",E);M(y,z),M(y,b);let j=p.render("optgroup",{group:E,options:y});M(a,j)}else M(a,b)}),F.innerHTML="",M(F,a),p.settings.highlight&&(St(F),_.query.length&&_.tokens.length&&$(_.tokens,m=>{Ct(F,m.regex)}));var R=m=>{let b=p.render(m,{input:v});return b&&(C=!0,F.insertBefore(b,F.firstChild)),b};if(p.loading?R("loading"):p.settings.shouldLoad.call(p,v)?_.items.length===0&&R("no_results"):R("not_loading"),c=p.canCreate(v),c&&(u=R("option_create")),p.hasOptions=_.items.length>0||c,C){if(_.items.length>0){if(!h&&p.settings.mode==="single"&&p.items[0]!=null&&(h=p.getOption(p.items[0])),!F.contains(h)){let m=0;u&&!p.settings.addPrecedence&&(m=1),h=p.selectable()[m]}}else u&&(h=u);e&&!p.isOpen&&(p.open(),p.scrollToOption(h,"auto")),p.setActiveOption(h)}else p.clearActiveOption(),e&&p.isOpen&&p.close(!1)}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e,t=!1){const s=this;if(Array.isArray(e))return s.addOptions(e,t),!1;const n=k(e[s.settings.valueField]);return n===null||s.options.hasOwnProperty(n)?!1:(e.$order=e.$order||++s.order,e.$id=s.inputId+"-opt-"+e.$order,s.options[n]=e,s.lastQuery=null,t&&(s.userOptions[n]=t,s.trigger("option_add",n,e)),n)}addOptions(e,t=!1){$(e,s=>{this.addOption(s,t)})}registerOption(e){return this.addOption(e)}registerOptionGroup(e){var t=k(e[this.settings.optgroupValueField]);return t===null?!1:(e.$order=e.$order||++this.order,this.optgroups[t]=e,t)}addOptionGroup(e,t){var s;t[this.settings.optgroupValueField]=e,(s=this.registerOptionGroup(t))&&this.trigger("optgroup_add",s,t)}removeOptionGroup(e){this.optgroups.hasOwnProperty(e)&&(delete this.optgroups[e],this.clearCache(),this.trigger("optgroup_remove",e))}clearOptionGroups(){this.optgroups={},this.clearCache(),this.trigger("optgroup_clear")}updateOption(e,t){const s=this;var n,o;const r=k(e),l=k(t[s.settings.valueField]);if(r===null)return;const a=s.options[r];if(a==null)return;if(typeof l!="string")throw new Error("Value must be set in option data");const c=s.getOption(r),d=s.getItem(r);if(t.$order=t.$order||a.$order,delete s.options[r],s.uncacheValue(l),s.options[l]=t,c){if(s.dropdown_content.contains(c)){const u=s._render("option",t);le(c,u),s.activeOption===c&&s.setActiveOption(u)}c.remove()}d&&(o=s.items.indexOf(r),o!==-1&&s.items.splice(o,1,l),n=s._render("item",t),d.classList.contains("active")&&L(n,"active"),le(d,n)),s.lastQuery=null}removeOption(e,t){const s=this;e=G(e),s.uncacheValue(e),delete s.userOptions[e],delete s.options[e],s.lastQuery=null,s.trigger("option_remove",e),s.removeItem(e,t)}clearOptions(e){const t=(e||this.clearFilter).bind(this);this.loadedSearches={},this.userOptions={},this.clearCache();const s={};$(this.options,(n,o)=>{t(n,o)&&(s[o]=n)}),this.options=this.sifter.items=s,this.lastQuery=null,this.trigger("option_clear")}clearFilter(e,t){return this.items.indexOf(t)>=0}getOption(e,t=!1){const s=k(e);if(s===null)return null;const n=this.options[s];if(n!=null){if(n.$div)return n.$div;if(t)return this._render("option",n)}return null}getAdjacent(e,t,s="option"){var n=this,o;if(!e)return null;s=="item"?o=n.controlChildren():o=n.dropdown_content.querySelectorAll("[data-selectable]");for(let r=0;r<o.length;r++)if(o[r]==e)return t>0?o[r+1]:o[r-1];return null}getItem(e){if(typeof e=="object")return e;var t=k(e);return t!==null?this.control.querySelector(`[data-value="${pe(t)}"]`):null}addItems(e,t){var s=this,n=Array.isArray(e)?e:[e];n=n.filter(r=>s.items.indexOf(r)===-1);const o=n[n.length-1];n.forEach(r=>{s.isPending=r!==o,s.addItem(r,t)})}addItem(e,t){var s=t?[]:["change","dropdown_close"];fe(this,s,()=>{var n,o;const r=this,l=r.settings.mode,a=k(e);if(!(a&&r.items.indexOf(a)!==-1&&(l==="single"&&r.close(),l==="single"||!r.settings.duplicates))&&!(a===null||!r.options.hasOwnProperty(a))&&(l==="single"&&r.clear(t),!(l==="multi"&&r.isFull()))){if(n=r._render("item",r.options[a]),r.control.contains(n)&&(n=n.cloneNode(!0)),o=r.isFull(),r.items.splice(r.caretPos,0,a),r.insertAtCaret(n),r.isSetup){if(!r.isPending&&r.settings.hideSelected){let c=r.getOption(a),d=r.getAdjacent(c,1);d&&r.setActiveOption(d)}!r.isPending&&!r.settings.closeAfterSelect&&r.refreshOptions(r.isFocused&&l!=="single"),r.settings.closeAfterSelect!=!1&&r.isFull()?r.close():r.isPending||r.positionDropdown(),r.trigger("item_add",a,n),r.isPending||r.updateOriginalInput({silent:t})}(!r.isPending||!o&&r.isFull())&&(r.inputState(),r.refreshState())}})}removeItem(e=null,t){const s=this;if(e=s.getItem(e),!e)return;var n,o;const r=e.dataset.value;n=ge(e),e.remove(),e.classList.contains("active")&&(o=s.activeItems.indexOf(e),s.activeItems.splice(o,1),H(e,"active")),s.items.splice(n,1),s.lastQuery=null,!s.settings.persist&&s.userOptions.hasOwnProperty(r)&&s.removeOption(r,t),n<s.caretPos&&s.setCaret(s.caretPos-1),s.updateOriginalInput({silent:t}),s.refreshState(),s.positionDropdown(),s.trigger("item_remove",r,e)}createItem(e=null,t=()=>{}){arguments.length===3&&(t=arguments[2]),typeof t!="function"&&(t=()=>{});var s=this,n=s.caretPos,o;if(e=e||s.inputValue(),!s.canCreate(e))return t(),!1;s.lock();var r=!1,l=a=>{if(s.unlock(),!a||typeof a!="object")return t();var c=k(a[s.settings.valueField]);if(typeof c!="string")return t();s.setTextboxValue(),s.addOption(a,!0),s.setCaret(n),s.addItem(c),t(a),r=!0};return typeof s.settings.create=="function"?o=s.settings.create.call(this,e,l):o={[s.settings.labelField]:e,[s.settings.valueField]:e},r||l(o),!0}refreshItems(){var e=this;e.lastQuery=null,e.isSetup&&e.addItems(e.items),e.updateOriginalInput(),e.refreshState()}refreshState(){const e=this;e.refreshValidityState();const t=e.isFull(),s=e.isLocked;e.wrapper.classList.toggle("rtl",e.rtl);const n=e.wrapper.classList;n.toggle("focus",e.isFocused),n.toggle("disabled",e.isDisabled),n.toggle("readonly",e.isReadOnly),n.toggle("required",e.isRequired),n.toggle("invalid",!e.isValid),n.toggle("locked",s),n.toggle("full",t),n.toggle("input-active",e.isFocused&&!e.isInputHidden),n.toggle("dropdown-active",e.isOpen),n.toggle("has-options",At(e.options)),n.toggle("has-items",e.items.length>0)}refreshValidityState(){var e=this;e.input.validity&&(e.isValid=e.input.validity.valid,e.isInvalid=!e.isValid)}isFull(){return this.settings.maxItems!==null&&this.items.length>=this.settings.maxItems}updateOriginalInput(e={}){const t=this;var s,n;const o=t.input.querySelector('option[value=""]');if(t.is_select_tag){let c=function(d,u,f){return d||(d=T('<option value="'+ie(u)+'">'+ie(f)+"</option>")),d!=o&&t.input.append(d),l.push(d),(d!=o||a>0)&&(d.selected=!0),d};var r=c;const l=[],a=t.input.querySelectorAll("option:checked").length;t.input.querySelectorAll("option:checked").forEach(d=>{d.selected=!1}),t.items.length==0&&t.settings.mode=="single"?c(o,"",""):t.items.forEach(d=>{if(s=t.options[d],n=s[t.settings.labelField]||"",l.includes(s.$option)){const u=t.input.querySelector(`option[value="${pe(d)}"]:not(:checked)`);c(u,d,n)}else s.$option=c(s.$option,d,n)})}else t.input.value=t.getValue();t.isSetup&&(e.silent||t.trigger("change",t.getValue()))}open(){var e=this;e.isLocked||e.isOpen||e.settings.mode==="multi"&&e.isFull()||(e.isOpen=!0,A(e.focus_node,{"aria-expanded":"true"}),e.refreshState(),q(e.dropdown,{visibility:"hidden",display:"block"}),e.positionDropdown(),q(e.dropdown,{visibility:"visible",display:"block"}),e.focus(),e.trigger("dropdown_open",e.dropdown))}close(e=!0){var t=this,s=t.isOpen;e&&(t.setTextboxValue(),t.settings.mode==="single"&&t.items.length&&t.inputState()),t.isOpen=!1,A(t.focus_node,{"aria-expanded":"false"}),q(t.dropdown,{display:"none"}),t.settings.hideSelected&&t.clearActiveOption(),t.refreshState(),s&&t.trigger("dropdown_close",t.dropdown)}positionDropdown(){if(this.settings.dropdownParent==="body"){var e=this.control,t=e.getBoundingClientRect(),s=e.offsetHeight+t.top+window.scrollY,n=t.left+window.scrollX;q(this.dropdown,{width:t.width+"px",top:s+"px",left:n+"px"})}}clear(e){var t=this;if(t.items.length){var s=t.controlChildren();$(s,n=>{t.removeItem(n,!0)}),t.inputState(),e||t.updateOriginalInput(),t.trigger("clear")}}insertAtCaret(e){const t=this,s=t.caretPos,n=t.control;n.insertBefore(e,n.children[s]||null),t.setCaret(s+1)}deleteSelection(e){var t,s,n,o,r=this;t=e&&e.keyCode===me?-1:1,s=yt(r.control_input);const l=[];if(r.activeItems.length)o=he(r.activeItems,t),n=ge(o),t>0&&n++,$(r.activeItems,a=>l.push(a));else if((r.isFocused||r.settings.mode==="single")&&r.items.length){const a=r.controlChildren();let c;t<0&&s.start===0&&s.length===0?c=a[r.caretPos-1]:t>0&&s.start===r.inputValue().length&&(c=a[r.caretPos]),c!==void 0&&l.push(c)}if(!r.shouldDelete(l,e))return!1;for(S(e,!0),typeof n<"u"&&r.setCaret(n);l.length;)r.removeItem(l.pop());return r.inputState(),r.positionDropdown(),r.refreshOptions(!1),!0}shouldDelete(e,t){const s=e.map(n=>n.dataset.value);return!(!s.length||typeof this.settings.onDelete=="function"&&this.settings.onDelete(s,t)===!1)}advanceSelection(e,t){var s,n,o=this;o.rtl&&(e*=-1),!o.inputValue().length&&(D(U,t)||D("shiftKey",t)?(s=o.getLastActive(e),s?s.classList.contains("active")?n=o.getAdjacent(s,e,"item"):n=s:e>0?n=o.control_input.nextElementSibling:n=o.control_input.previousElementSibling,n&&(n.classList.contains("active")&&o.removeActiveItem(s),o.setActiveItemClass(n))):o.moveCaret(e))}moveCaret(e){}getLastActive(e){let t=this.control.querySelector(".last-active");if(t)return t;var s=this.control.querySelectorAll(".active");if(s)return he(s,e)}setCaret(e){this.caretPos=this.items.length}controlChildren(){return Array.from(this.control.querySelectorAll("[data-ts-item]"))}lock(){this.setLocked(!0)}unlock(){this.setLocked(!1)}setLocked(e=this.isReadOnly||this.isDisabled){this.isLocked=e,this.refreshState()}disable(){this.setDisabled(!0),this.close()}enable(){this.setDisabled(!1)}setDisabled(e){this.focus_node.tabIndex=e?-1:this.tabIndex,this.isDisabled=e,this.input.disabled=e,this.control_input.disabled=e,this.setLocked()}setReadOnly(e){this.isReadOnly=e,this.input.readOnly=e,this.control_input.readOnly=e,this.setLocked()}destroy(){var e=this,t=e.revertSettings;e.trigger("destroy"),e.off(),e.wrapper.remove(),e.dropdown.remove(),e.input.innerHTML=t.innerHTML,e.input.tabIndex=t.tabIndex,H(e.input,"tomselected","ts-hidden-accessible"),e._destroy(),delete e.input.tomselect}render(e,t){var s,n;const o=this;if(typeof this.settings.render[e]!="function"||(n=o.settings.render[e].call(this,t,ie),!n))return null;if(n=T(n),e==="option"||e==="option_create"?t[o.settings.disabledField]?A(n,{"aria-disabled":"true"}):A(n,{"data-selectable":""}):e==="optgroup"&&(s=t.group[o.settings.optgroupValueField],A(n,{"data-group":s}),t.group[o.settings.disabledField]&&A(n,{"data-disabled":""})),e==="option"||e==="item"){const r=G(t[o.settings.valueField]);A(n,{"data-value":r}),e==="item"?(L(n,o.settings.itemClass),A(n,{"data-ts-item":""})):(L(n,o.settings.optionClass),A(n,{role:"option",id:t.$id}),t.$div=n,o.options[r]=t)}return n}_render(e,t){const s=this.render(e,t);if(s==null)throw"HTMLElement expected";return s}clearCache(){$(this.options,e=>{e.$div&&(e.$div.remove(),delete e.$div)})}uncacheValue(e){const t=this.getOption(e);t&&t.remove()}canCreate(e){return this.settings.create&&e.length>0&&this.settings.createFilter.call(this,e)}hook(e,t,s){var n=this,o=n[t];n[t]=function(){var r,l;return e==="after"&&(r=o.apply(n,arguments)),l=s.apply(n,arguments),e==="instead"?l:(e==="before"&&(r=o.apply(n,arguments)),r)}}}const Pt=(i,e,t,s)=>{i.addEventListener(e,t,s)};function Dt(){Pt(this.input,"change",()=>{this.sync()})}const Mt=i=>typeof i>"u"||i===null?null:Rt(i),Rt=i=>typeof i=="boolean"?i?"1":"0":i+"",ye=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},Nt=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(Vt(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},Vt=i=>typeof i=="string"&&i.indexOf("<")>-1;function Bt(i){var e=this,t=e.onOptionSelect;e.settings.hideSelected=!1;const s=Object.assign({className:"tomselect-checkbox",checkedClassNames:void 0,uncheckedClassNames:void 0},i);var n=function(l,a){a?(l.checked=!0,s.uncheckedClassNames&&l.classList.remove(...s.uncheckedClassNames),s.checkedClassNames&&l.classList.add(...s.checkedClassNames)):(l.checked=!1,s.checkedClassNames&&l.classList.remove(...s.checkedClassNames),s.uncheckedClassNames&&l.classList.add(...s.uncheckedClassNames))},o=function(l){setTimeout(()=>{var a=l.querySelector("input."+s.className);a instanceof HTMLInputElement&&n(a,l.classList.contains("selected"))},1)};e.hook("after","setupTemplates",()=>{var r=e.settings.render.option;e.settings.render.option=(l,a)=>{var c=Nt(r.call(e,l,a)),d=document.createElement("input");s.className&&d.classList.add(s.className),d.addEventListener("click",function(f){ye(f)}),d.type="checkbox";const u=Mt(l[e.settings.valueField]);return n(d,!!(u&&e.items.indexOf(u)>-1)),c.prepend(d),c}}),e.on("item_remove",r=>{var l=e.getOption(r);l&&(l.classList.remove("selected"),o(l))}),e.on("item_add",r=>{var l=e.getOption(r);l&&o(l)}),e.hook("instead","onOptionSelect",(r,l)=>{if(l.classList.contains("selected")){l.classList.remove("selected"),e.removeItem(l.dataset.value),e.refreshOptions(),ye(r,!0);return}t.call(e,r,l),o(l)})}const zt=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(jt(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},jt=i=>typeof i=="string"&&i.indexOf("<")>-1;function Kt(i){const e=this,t=Object.assign({className:"clear-button",title:"Clear All",html:s=>`<div class="${s.className}" title="${s.title}">&#10799;</div>`},i);e.on("initialize",()=>{var s=zt(t.html(t));s.addEventListener("click",n=>{e.isLocked||(e.clear(),e.settings.mode==="single"&&e.settings.allowEmptyOption&&e.addItem(""),n.preventDefault(),n.stopPropagation())}),e.control.appendChild(s)})}const qt=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},N=(i,e,t,s)=>{i.addEventListener(e,t,s)},Ut=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},Yt=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(Gt(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},Gt=i=>typeof i=="string"&&i.indexOf("<")>-1,Qt=(i,e)=>{Ut(e,(t,s)=>{t==null?i.removeAttribute(s):i.setAttribute(s,""+t)})},Wt=(i,e)=>{var t;(t=i.parentNode)==null||t.insertBefore(e,i.nextSibling)},Jt=(i,e)=>{var t;(t=i.parentNode)==null||t.insertBefore(e,i)},Xt=(i,e)=>{do{var t;if(e=(t=e)==null?void 0:t.previousElementSibling,i==e)return!0}while(e&&e.previousElementSibling);return!1};function Zt(){var i=this;if(i.settings.mode!=="multi")return;var e=i.lock,t=i.unlock;let s=!0,n;i.hook("after","setupTemplates",()=>{var o=i.settings.render.item;i.settings.render.item=(r,l)=>{const a=Yt(o.call(i,r,l));Qt(a,{draggable:"true"});const c=v=>{s||qt(v),v.stopPropagation()},d=v=>{n=a,setTimeout(()=>{a.classList.add("ts-dragging")},0)},u=v=>{v.preventDefault(),a.classList.add("ts-drag-over"),w(a,n)},f=()=>{a.classList.remove("ts-drag-over")},w=(v,O)=>{O!==void 0&&(Xt(O,a)?Wt(v,O):Jt(v,O))},p=()=>{var v;document.querySelectorAll(".ts-drag-over").forEach(_=>_.classList.remove("ts-drag-over")),(v=n)==null||v.classList.remove("ts-dragging"),n=void 0;var O=[];i.control.querySelectorAll("[data-value]").forEach(_=>{if(_.dataset.value){let h=_.dataset.value;h&&O.push(h)}}),i.setValue(O)};return N(a,"mousedown",c),N(a,"dragstart",d),N(a,"dragenter",u),N(a,"dragover",u),N(a,"dragleave",f),N(a,"dragend",p),a}}),i.hook("instead","lock",()=>(s=!1,e.call(i))),i.hook("instead","unlock",()=>(s=!0,t.call(i)))}const ei=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},ti=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(ii(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},ii=i=>typeof i=="string"&&i.indexOf("<")>-1;function si(i){const e=this,t=Object.assign({title:"Untitled",headerClass:"dropdown-header",titleRowClass:"dropdown-header-title",labelClass:"dropdown-header-label",closeClass:"dropdown-header-close",html:s=>'<div class="'+s.headerClass+'"><div class="'+s.titleRowClass+'"><span class="'+s.labelClass+'">'+s.title+'</span><a class="'+s.closeClass+'">&times;</a></div></div>'},i);e.on("initialize",()=>{var s=ti(t.html(t)),n=s.querySelector("."+t.closeClass);n&&n.addEventListener("click",o=>{ei(o,!0),e.close()}),e.dropdown.insertBefore(s,e.dropdown.firstChild)})}const ni=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},ri=(i,...e)=>{var t=oi(e);i=li(i),i.map(s=>{t.map(n=>{s.classList.remove(n)})})},oi=i=>{var e=[];return ni(i,t=>{typeof t=="string"&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},li=i=>(Array.isArray(i)||(i=[i]),i),ai=(i,e)=>{if(!i)return-1;e=e||i.nodeName;for(var t=0;i=i.previousElementSibling;)i.matches(e)&&t++;return t};function ci(){var i=this;i.hook("instead","setCaret",e=>{i.settings.mode==="single"||!i.control.contains(i.control_input)?e=i.items.length:(e=Math.max(0,Math.min(i.items.length,e)),e!=i.caretPos&&!i.isPending&&i.controlChildren().forEach((t,s)=>{s<e?i.control_input.insertAdjacentElement("beforebegin",t):i.control.appendChild(t)})),i.caretPos=e}),i.hook("instead","moveCaret",e=>{if(!i.isFocused)return;const t=i.getLastActive(e);if(t){const s=ai(t);i.setCaret(e>0?s+1:s),i.setActiveItem(),ri(t,"last-active")}else i.setCaret(i.caretPos+e)})}const di=27,ui=9,fi=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},pi=(i,e,t,s)=>{i.addEventListener(e,t,s)},hi=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},Oe=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(gi(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},gi=i=>typeof i=="string"&&i.indexOf("<")>-1,mi=(i,...e)=>{var t=vi(e);i=wi(i),i.map(s=>{t.map(n=>{s.classList.add(n)})})},vi=i=>{var e=[];return hi(i,t=>{typeof t=="string"&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},wi=i=>(Array.isArray(i)||(i=[i]),i);function bi(){const i=this;i.settings.shouldOpen=!0,i.hook("before","setup",()=>{i.focus_node=i.control,mi(i.control_input,"dropdown-input");const e=Oe('<div class="dropdown-input-wrap">');e.append(i.control_input),i.dropdown.insertBefore(e,i.dropdown.firstChild);const t=Oe('<input class="items-placeholder" tabindex="-1" />');t.placeholder=i.settings.placeholder||"",i.control.append(t)}),i.on("initialize",()=>{i.control_input.addEventListener("keydown",t=>{switch(t.keyCode){case di:i.isOpen&&(fi(t,!0),i.close()),i.clearActiveItems();return;case ui:i.focus_node.tabIndex=-1;break}return i.onKeyDown.call(i,t)}),i.on("blur",()=>{i.focus_node.tabIndex=i.isDisabled?-1:i.tabIndex}),i.on("dropdown_open",()=>{i.control_input.focus()});const e=i.onBlur;i.hook("instead","onBlur",t=>{if(!(t&&t.relatedTarget==i.control_input))return e.call(i)}),pi(i.control_input,"blur",()=>i.onBlur()),i.hook("before","close",()=>{i.isOpen&&i.focus_node.focus({preventScroll:!0})})})}const Y=(i,e,t,s)=>{i.addEventListener(e,t,s)};function _i(){var i=this;i.on("initialize",()=>{var e=document.createElement("span"),t=i.control_input;e.style.cssText="position:absolute; top:-99999px; left:-99999px; width:auto; padding:0; white-space:pre; ",i.wrapper.appendChild(e);var s=["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"];for(const o of s)e.style[o]=t.style[o];var n=()=>{e.textContent=t.value,t.style.width=e.clientWidth+"px"};n(),i.on("update item_add item_remove",n),Y(t,"input",n),Y(t,"keyup",n),Y(t,"blur",n),Y(t,"update",n)})}function yi(){var i=this,e=i.deleteSelection;this.hook("instead","deleteSelection",t=>i.activeItems.length?e.call(i,t):!1)}function Oi(){this.hook("instead","setActiveItem",()=>{}),this.hook("instead","selectAll",()=>{})}const Ae=37,Ai=39,Ci=(i,e,t)=>{for(;i&&i.matches;){if(i.matches(e))return i;i=i.parentNode}},Si=(i,e)=>{if(!i)return-1;e=e||i.nodeName;for(var t=0;i=i.previousElementSibling;)i.matches(e)&&t++;return t};function $i(){var i=this,e=i.onKeyDown;i.hook("instead","onKeyDown",t=>{var s,n,o,r;if(!i.isOpen||!(t.keyCode===Ae||t.keyCode===Ai))return e.call(i,t);i.ignoreHover=!0,r=Ci(i.activeOption,"[data-group]"),s=Si(i.activeOption,"[data-selectable]"),r&&(t.keyCode===Ae?r=r.previousSibling:r=r.nextSibling,r&&(o=r.querySelectorAll("[data-selectable]"),n=o[Math.min(o.length-1,s)],n&&i.setActiveOption(n)))})}const Ei=i=>(i+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Ce=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},Se=(i,e,t,s)=>{i.addEventListener(e,t,s)},$e=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(xi(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},xi=i=>typeof i=="string"&&i.indexOf("<")>-1;function Ii(i){const e=Object.assign({label:"&times;",title:"Remove",className:"remove",append:!0},i);var t=this;if(e.append){var s='<a href="javascript:void(0)" class="'+e.className+'" tabindex="-1" title="'+Ei(e.title)+'">'+e.label+"</a>";t.hook("after","setupTemplates",()=>{var n=t.settings.render.item;t.settings.render.item=(o,r)=>{var l=$e(n.call(t,o,r)),a=$e(s);return l.appendChild(a),Se(a,"mousedown",c=>{Ce(c,!0)}),Se(a,"click",c=>{t.isLocked||(Ce(c,!0),!t.isLocked&&t.shouldDelete([l],c)&&(t.removeItem(l),t.refreshOptions(!1),t.inputState()))}),l}})}}function Li(i){const e=this,t=Object.assign({text:s=>s[e.settings.labelField]},i);e.on("item_remove",function(s){if(e.isFocused&&e.control_input.value.trim()===""){var n=e.options[s];n&&e.setTextboxValue(t.text.call(e,n))}})}const ki=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},Fi=(i,...e)=>{var t=Ti(e);i=Hi(i),i.map(s=>{t.map(n=>{s.classList.add(n)})})},Ti=i=>{var e=[];return ki(i,t=>{typeof t=="string"&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},Hi=i=>(Array.isArray(i)||(i=[i]),i);function Pi(){const i=this,e=i.canLoad,t=i.clearActiveOption,s=i.loadCallback;var n={},o,r=!1,l,a=[];if(i.settings.shouldLoadMore||(i.settings.shouldLoadMore=()=>{if(o.clientHeight/(o.scrollHeight-o.scrollTop)>.9)return!0;if(i.activeOption){var f=i.selectable(),w=Array.from(f).indexOf(i.activeOption);if(w>=f.length-2)return!0}return!1}),!i.settings.firstUrl)throw"virtual_scroll plugin requires a firstUrl() method";i.settings.sortField=[{field:"$order"},{field:"$score"}];const c=u=>typeof i.settings.maxOptions=="number"&&o.children.length>=i.settings.maxOptions?!1:!!(u in n&&n[u]),d=(u,f)=>i.items.indexOf(f)>=0||a.indexOf(f)>=0;i.setNextUrl=(u,f)=>{n[u]=f},i.getUrl=u=>{if(u in n){const f=n[u];return n[u]=!1,f}return i.clearPagination(),i.settings.firstUrl.call(i,u)},i.clearPagination=()=>{n={}},i.hook("instead","clearActiveOption",()=>{if(!r)return t.call(i)}),i.hook("instead","canLoad",u=>u in n?c(u):e.call(i,u)),i.hook("instead","loadCallback",(u,f)=>{if(!r)i.clearOptions(d);else if(l){const w=u[0];w!==void 0&&(l.dataset.value=w[i.settings.valueField])}s.call(i,u,f),r=!1}),i.hook("after","refreshOptions",()=>{const u=i.lastValue;var f;c(u)?(f=i.render("loading_more",{query:u}),f&&(f.setAttribute("data-selectable",""),l=f)):u in n&&!o.querySelector(".no-results")&&(f=i.render("no_more_results",{query:u})),f&&(Fi(f,i.settings.optionClass),o.append(f))}),i.on("initialize",()=>{a=Object.keys(i.options),o=i.dropdown_content,i.settings.render=Object.assign({},{loading_more:()=>'<div class="loading-more-results">Loading more results ... </div>',no_more_results:()=>'<div class="no-more-results">No more results</div>'},i.settings.render),o.addEventListener("scroll",()=>{i.settings.shouldLoadMore.call(i)&&c(i.lastValue)&&(r||(r=!0,i.load.call(i,i.lastValue)))})})}I.define("change_listener",Dt);I.define("checkbox_options",Bt);I.define("clear_button",Kt);I.define("drag_drop",Zt);I.define("dropdown_header",si);I.define("caret_position",ci);I.define("dropdown_input",bi);I.define("input_autogrow",_i);I.define("no_backspace_delete",yi);I.define("no_active_items",Oi);I.define("optgroup_columns",$i);I.define("remove_button",Ii);I.define("restore_on_backspace",Li);I.define("virtual_scroll",Pi);const Di=i=>({init(){const e=this.$refs[`select_picker_${i.dataField}_${i.tableName}`],t={items:i.initialValues,...i.framework,onChange:o=>{Ee(i,o)},onInitialize:()=>{window.addEventListener(`pg:clear_multi_select::${i.tableName}:${i.dataField}`,()=>{e&&e.tomselect.clear(!0)}),window.addEventListener(`pg:clear_all_multi_select::${i.tableName}`,()=>{e&&e.tomselect.clear(!0)})}},s={valueField:i.optionValue,labelField:i.optionLabel,searchField:i.optionLabel,load:async function(o,r){function l(a,c){var p;const{method:d,url:u}=a,f=new Request(u,{method:d,body:d.toLowerCase()==="post"?JSON.stringify({search:c,...n}):void 0});f.headers.set("Content-Type","application/json"),f.headers.set("Accept","application/json"),f.headers.set("X-Requested-With","XMLHttpRequest");const w=(p=document.head.querySelector('[name="csrf-token"]'))==null?void 0:p.getAttribute("content");return w&&f.headers.set("X-CSRF-TOKEN",w),f}fetch(l(i.asyncData,o)).then(a=>a.json()).then(a=>{r(a)}).catch(()=>{r()})},render:{option:function(o,r){return`<div class="py-2 mb-1"><span>${r(o[i.optionLabel])}</span></div>`},item:function(o,r){return`<div class="py-2 mb-1"><span>${r(o[i.optionLabel])}</span></div>`}}};let n=t;i.hasOwnProperty("asyncData")&&(n=Object.assign(t,s)),new I(e,n)}}),Mi=i=>({initialValues:i.initialValues,framework:i.framework,init(){const e=this.$refs["select_picker_"+i.dataField+"_"+i.tableName],t=this.deepCopy(this.framework);new window.SlimSelect({select:e,...t,events:{afterChange:s=>{let n=s.map(o=>o.value);Ee(i,n)}}})},deepCopy(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(this.deepCopy);const t={};for(const s in e)e.hasOwnProperty(s)&&(t[s]=this.deepCopy(e[s]));return t}}),Ri=()=>({init(){Livewire.on("pg:scrollTop",e=>{setTimeout(()=>{document.querySelector("body").scrollIntoView({behavior:"auto"})},0)}),new IntersectionObserver(e=>{e[0].isIntersecting&&this.$wire.call("loadMore")},{rootMargin:"300px"}).observe(this.$el)}}),Ni=i=>({rowId:(i==null?void 0:i.rowId)??null,parentId:(i==null?void 0:i.parentId)??null,toHtml(){let e=null;const t=this.parentId??this.$wire.id;if(this.rowId){const n=window[`pgActions_${t}`];n&&n[this.rowId]!==void 0&&(e=n[this.rowId])}else e=window[`pgActionsHeader_${t}`];if(typeof e!="object"||e===null)return"";let s="";return e.forEach(n=>{let o=this.shouldHideAction(n),r=this.getReplaceHtml(n);if(!o)if(r)s+=r;else{let l=this.buildAttributesString(n);if(n.icon){let a=this.processIcon(n);if(!a)return;s+=this.buildActionHtmlWithIcon(n,l,a)}else s+=this.buildActionHtml(n,l)}}),s},shouldHideAction(e){if(e.can===!1)return!0;let t=!1;return e.rules&&Object.values(e.rules).length>0&&Object.values(e.rules).forEach(s=>{s.action.includes(e.action)&&s.apply&&s.rule.hide&&(t=!0)}),t},getReplaceHtml(e){let t=null;return e.rules&&Object.values(e.rules).length>0&&Object.values(e.rules).forEach(s=>{s.apply&&s.action.includes(e.action)&&s.replaceHtml&&(t=s.replaceHtml)}),t},buildAttributesString(e){let t=e.attributes??[];return e.rules&&Object.values(e.rules).length>0&&Object.values(e.rules).forEach(s=>{s.apply&&s.action.includes(e.action)&&s.rule.setAttribute&&s.rule.setAttribute.length>0&&Object.values(s.rule.setAttribute).forEach(n=>{t[n.attribute]=n.value})}),Object.entries(t).map(([s,n])=>` ${s}="${n}"`).join("")},processIcon(e){const t=Object.entries(e.iconAttributes??[]).map(([n,o])=>` ${n}="${o}"`).join("");let s=window.pgResourceIcons[e.icon];return typeof s>"u"?(console.warn(`PowerGrid: Unable to load icons in javascript window in row: [${this.rowId}]`),null):this.replaceIconAttributes(s,t)},replaceIconAttributes(e,t){return e.replace(/<([^\s>]+)([^>]*)>/,(s,n,o)=>{let r=o.trim();const l=t.replace(/class="([^"]*)"/,(a,c)=>(r.includes("class=")?r=r.replace(/class="([^"]*)"/,(d,u)=>`class="${u} ${c.trim()}"`):r+=` ${a}`,""));return`<${n} ${r} ${l}>`})},buildActionHtmlWithIcon(e,t,s){return e.slot?`<${e.tag??"button"} ${t}>${s} ${e.slot}</${e.tag??"button"}>`:`<${e.tag??"button"} ${t}>${s}</${e.tag??"button"}>`},buildActionHtml(e,t){return`<${e.tag??"button"} ${t}>${e.slot}</${e.tag??"button"}>`}}),Vi=i=>({templateContent:(i==null?void 0:i.templateContent)??null,rendered:null,parentId:(i==null?void 0:i.parentId)??null,init(){const e=Object.keys(this.templateContent)[0],t=window[`pgRowTemplates_${this.parentId??this.$wire.id}`][e],s=this.templateContent[e];if(s){let n=t;for(const[o,r]of Object.entries(s)){const l=`{{ ${o} }}`,a=String(r).replace(/'/g,"\\'");n=n.replaceAll(l,a)}this.rendered=n}}}),Bi=i=>({rowId:i.rowId,rules:i.rules,defaultClasses:i.defaultClasses,attributes:[],theme:[],init(){this.rules&&Object.values(this.rules).forEach(e=>{(e.applyLoop||e.apply)&&(e!=null&&e.attributes)&&this.attributes.push(e.attributes)})},getAttributes(){let e={class:this.defaultClasses};return this.attributes.forEach(t=>{Object.keys(t).forEach(s=>{e[s]+=e[s]?` ${t[s]}`:t[s]})}),e}});window.pgToggleable=Ne;window.pgFlatpickr=Be;window.pgEditable=ze;window.pgResponsive=Qe;window.pgTomSelect=Di;window.pgSlimSelect=Mi;window.pgLoadMore=Ri;window.pgRenderActions=Ni;window.pgRowAttributes=Bi;window.pgRenderRowTemplate=Vi;document.addEventListener("DOMContentLoaded",()=>{Livewire.hook("commit",({component:i,succeed:e,fail:t})=>{i.ephemeral.setUp&&i.ephemeral.setUp.hasOwnProperty("responsive")&&(e(()=>{queueMicrotask(()=>{window.dispatchEvent(new CustomEvent("pg-livewire-request-finished"))})}),t(()=>{window.dispatchEvent(new CustomEvent("pg-livewire-request-finished"))}))})});document.addEventListener("DOMContentLoaded",()=>{window.Alpine.directive("multisort-shift-click",(i,{expression:e})=>{i.addEventListener("click",t=>{window.Livewire.find(e).set("multiSort",t.shiftKey)})})});
