var Me=Object.defineProperty;var Ve=(i,e,t)=>e in i?Me(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var H=(i,e,t)=>Ve(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})}}),Be="modulepreload",ze=function(i){return"/"+i},ce={},je=function(e,t,n){let s=Promise.resolve();if(t&&t.length>0){document.getElementsByTagName("link");const r=document.querySelector("meta[property=csp-nonce]"),l=(r==null?void 0:r.nonce)||(r==null?void 0:r.getAttribute("nonce"));s=Promise.allSettled(t.map(a=>{if(a=ze(a),a in ce)return;ce[a]=!0;const c=a.endsWith(".css"),d=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${a}"]${d}`))return;const u=document.createElement("link");if(u.rel=c?"stylesheet":Be,c||(u.as="script"),u.crossOrigin="",u.href=a,l&&u.setAttribute("nonce",l),document.head.appendChild(u),c)return new Promise((f,w)=>{u.addEventListener("load",f),u.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${a}`)))})}))}function o(r){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=r,window.dispatchEvent(l),!l.defaultPrevented)throw r}return s.then(r=>{for(const l of r||[])l.status==="rejected"&&o(l.reason);return e().catch(o)})},Ke=i=>({dataField:i.dataField,tableName:i.tableName,label:i.label??null,locale:i.locale??"en",onlyFuture:i.onlyFuture??!1,noWeekEnds:i.noWeekEnds??!1,customConfig:i.customConfig??null,type:i.type,element:null,selectedDates:null,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()});const e=this.locale.locale;typeof e<"u"&&typeof flatpickr<"u"&&je(()=>import(`flatpickr/dist/l10n/${e}.js`),[]).then(n=>{this.locale.locale=n.default[e]}).catch(n=>{console.error("flatpickr l10n error",n)});const t=this.getOptions();this.$refs.rangeInput&&typeof flatpickr<"u"&&(this.element=flatpickr(this.$refs.rangeInput,t),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,n,s)=>{t=t.map(o=>this.element.formatDate(o,"Y-m-d")),t.length>0&&this.selectedDates!==n&&Livewire.dispatch("pg:datePicker-"+this.tableName,{selectedDates:t,dateStr:n,timezone:this.customConfig.timezone??new Date().toString().match(/([-\+][0-9]+)\s/)[1],type:this.type,field:this.dataField,label:this.label})},e}}),qe=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),n=>{setTimeout(()=>{this.setFocusToEnd(n),this.store().getTextContent(this.hash)&&(n.textContent=this.store().getTextContent(this.hash))},30)}),this.hashError){const n=this.store().get(this.hash),s=document.getElementById("clickable-"+n);s&&s.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((s,o)=>{for(let r of s)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(),n=document.createRange();n.selectNodeContents(e),n.collapse(!1),t.removeAllRanges(),t.addRange(n),e.focus()}});function Ue(i){i.querySelectorAll("tbody tr td").forEach(e=>{e.classList.remove("hidden")}),i.querySelectorAll("thead tr th").forEach(e=>{e.classList.remove("hidden")})}function Ye(i){let e=0;const t=i.querySelectorAll("table thead tr:nth-child(1) th[fixed]"),n=oe(i);return t.forEach(s=>{e+=oe(s)}),n-e}function Ge(i,e){const t=[].slice.call(i.querySelectorAll("table thead tr:nth-child(1) th")),n=[].slice.call(t).sort(function(l,a){const c=l.getAttribute("sort_order")??999,d=a.getAttribute("sort_order")??999;return c-d});let s=0,o=!0;const r=[];return n.forEach(l=>{const a=oe(l);l.getAttribute("fixed")===null&&(o&&s<=e&&s+a<=e?s+=a:(r.push(t.indexOf(l)+1),o=!1))}),r}function We(i,e){for(const t of e)i.querySelectorAll(`tbody:not(tbody[expand]) tr td:nth-child(${t})`).forEach(n=>{n.classList.add("hidden")}),i.querySelectorAll(`thead tr th:nth-child(${t})`).forEach(n=>{n.classList.add("hidden")})}function Qe(i,e){var t,n;if(i.querySelectorAll("table tbody[expand] tr td div").length){for(const s of i.querySelectorAll("table tbody[expand] tr td div"))s.innerHTML="";if(e.length)for(const s 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(${s}) span[data-value]`).textContent;const c=(n=r.querySelector(`tr:last-child td:nth-child(${s})`))==null?void 0:n.innerHTML;a.length&&(a+=":"),l.querySelector(`div[data-expand-item-${s}]`)||(l.innerHTML+=`<div class="responsive-row-expand-item-container" data-expand-item-${s}>
                    <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 Je(i){Ue(i);const e=Ye(i),t=Ge(i,e);Qe(i,t),We(i,t)}const Xe=()=>({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;Je(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)}}),Ze=(i,e,t)=>{Livewire.dispatch(`${i}-${e.tableName}`,{label:e.label,field:e.dataField,values:t})},xe=(i,e)=>{Ze("pg:multiSelect",i,e)};function Z(i,e){i.split(/\s+/).forEach(t=>{e(t)})}class et{constructor(){this._events={}}on(e,t){Z(e,n=>{const s=this._events[n]||[];s.push(t),this._events[n]=s})}off(e,t){var n=arguments.length;if(n===0){this._events={};return}Z(e,s=>{if(n===1){delete this._events[s];return}const o=this._events[s];o!==void 0&&(o.splice(o.indexOf(t),1),this._events[s]=o)})}trigger(e,...t){var n=this;Z(e,s=>{const o=n._events[s];o!==void 0&&o.forEach(r=>{r.apply(n,t)})})}}function tt(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,n;const s=this,o=[];if(Array.isArray(e))e.forEach(r=>{typeof r=="string"?o.push(r):(s.plugins.settings[r.name]=r.options,o.push(r.name))});else if(e)for(t in e)e.hasOwnProperty(t)&&(s.plugins.settings[t]=e[t],o.push(t));for(;n=o.shift();)s.require(n)}loadPlugin(e){var t=this,n=t.plugins,s=i.plugins[e];if(!i.plugins.hasOwnProperty(e))throw new Error('Unable to find "'+e+'" plugin');n.requested[e]=!0,n.loaded[e]=s.fn.apply(t,[t.plugins.settings[e]||{}]),n.names.push(e)}require(e){var t=this,n=t.plugins;if(!t.plugins.loaded.hasOwnProperty(e)){if(n.requested[e])throw new Error('Plugin has circular dependency ("'+e+'")');t.loadPlugin(e)}return n.loaded[e]}}}const X=i=>(i=i.filter(Boolean),i.length<2?i[0]||"":nt(i)==1?"["+i.join("")+"]":"(?:"+i.join("|")+")"),Ie=i=>{if(!it(i))return i.join("");let e="",t=0;const n=()=>{t>1&&(e+="{"+t+"}")};return i.forEach((s,o)=>{if(s===i[o-1]){t++;return}n(),e+=s,t=1}),n(),e},Le=i=>{let e=Array.from(i);return X(e)},it=i=>new Set(i).size!==i.length,N=i=>(i+"").replace(/([\$\(\)\*\+\.\?\[\]\^\{\|\}\\])/gu,"\\$1"),nt=i=>i.reduce((e,t)=>Math.max(e,st(t)),0),st=i=>Array.from(i).length,ke=i=>{if(i.length===1)return[[i]];let e=[];const t=i.substring(1);return ke(t).forEach(function(s){let o=s.slice(0);o[0]=i.charAt(0)+o[0],e.push(o),o=s.slice(0),o.unshift(i.charAt(0)),e.push(o)}),e},rt=[[0,65535]],ot="[̀-ͯ·ʾʼ]";let W,Fe;const lt=3,ae={},de={"/":"⁄∕",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 de){let e=de[i]||"";for(let t=0;t<e.length;t++){let n=e.substring(t,t+1);ae[n]=i}}const at=new RegExp(Object.keys(ae).join("|")+"|"+ot,"gu"),ct=i=>{W===void 0&&(W=ht(rt))},ue=(i,e="NFKD")=>i.normalize(e),Q=i=>Array.from(i).reduce((e,t)=>e+dt(t),""),dt=i=>(i=ue(i).toLowerCase().replace(at,e=>ae[e]||""),ue(i,"NFC"));function*ut(i){for(const[e,t]of i)for(let n=e;n<=t;n++){let s=String.fromCharCode(n),o=Q(s);o!=s.toLowerCase()&&(o.length>lt||o.length!=0&&(yield{folded:o,composed:s,code_point:n}))}}const ft=i=>{const e={},t=(n,s)=>{const o=e[n]||new Set,r=new RegExp("^"+Le(o)+"$","iu");s.match(r)||(o.add(N(s)),e[n]=o)};for(let n of ut(i))t(n.folded,n.folded),t(n.folded,n.composed);return e},ht=i=>{const e=ft(i),t={};let n=[];for(let o in e){let r=e[o];r&&(t[o]=Le(r)),o.length>1&&n.push(N(o))}n.sort((o,r)=>r.length-o.length);const s=X(n);return Fe=new RegExp("^"+s,"u"),t},pt=(i,e=1)=>{let t=0;return i=i.map(n=>(W[n]&&(t+=n.length),W[n]||n)),t>=e?Ie(i):""},gt=(i,e=1)=>(e=Math.max(e,i.length-1),X(ke(i).map(t=>pt(t,e)))),fe=(i,e=!0)=>{let t=i.length>1?1:0;return X(i.map(n=>{let s=[];const o=e?n.length():n.length()-1;for(let r=0;r<o;r++)s.push(gt(n.substrs[r]||"",t));return Ie(s)}))},mt=(i,e)=>{for(const t of e){if(t.start!=i.start||t.end!=i.end||t.substrs.join("")!==i.substrs.join(""))continue;let n=i.parts;const s=r=>{for(const l of n){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(s).length>0))return!0}return!1};class J{constructor(){H(this,"parts");H(this,"substrs");H(this,"start");H(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 n=new J,s=JSON.parse(JSON.stringify(this.parts)),o=s.pop();for(const a of s)n.add(a);let r=t.substr.substring(0,e-o.start),l=r.length;return n.add({start:o.start,end:o.start+l,length:l,substr:r}),n}}const vt=i=>{ct(),i=Q(i);let e="",t=[new J];for(let n=0;n<i.length;n++){let o=i.substring(n).match(Fe);const r=i.substring(n,n+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<=n)if(l){const f=l.length;d.add({start:n,end:n+f,length:f,substr:l}),c.add("1")}else d.add({start:n,end:n+1,length:1,substr:r}),c.add("2");else if(l){let f=d.clone(n,u);const w=l.length;f.add({start:n,end:n+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)mt(d,t)||t.push(d);continue}if(n>0&&c.size==1&&!c.has("3")){e+=fe(t,!1);let d=new J;const u=t[0];u&&d.add(u.last()),t=[d]}}return e+=fe(t,!0),e},wt=(i,e)=>{if(i)return i[e]},bt=(i,e)=>{if(i){for(var t,n=e.split(".");(t=n.shift())&&(i=i[t]););return i}},ee=(i,e,t)=>{var n,s;return!i||(i=i+"",e.regex==null)||(s=i.search(e.regex),s===-1)?0:(n=e.string.length/i.length,s===0&&(n+=.5),n*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)},_t=(i,e)=>typeof i=="number"&&typeof e=="number"?i>e?1:i<e?-1:0:(i=Q(i+"").toLowerCase(),e=Q(e+"").toLowerCase(),i>e?1:e>i?-1:0);class yt{constructor(e,t){H(this,"items");H(this,"settings");this.items=e,this.settings=t||{diacritics:!0}}tokenize(e,t,n){if(!e||!e.length)return[];const s=[],o=e.split(/\s+/);var r;return n&&(r=new RegExp("^("+Object.keys(n).map(N).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=vt(l)||null:d=N(l),d&&t&&(d="\\b"+d)),s.push({string:l,regex:d?new RegExp(d,"iu"):null,field:c})}),s}getScoreFunction(e,t){var n=this.prepareSearch(e,t);return this._getScoreFunction(n)}_getScoreFunction(e){const t=e.tokens,n=t.length;if(!n)return function(){return 0};const s=e.options.fields,o=e.weights,r=s.length,l=e.getAttrFn;if(!r)return function(){return 1};const a=function(){return r===1?function(c,d){const u=s[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 n===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/n}:function(c){var d=0;return K(t,u=>{d+=a(u,c)}),d/n}}getSortFunction(e,t){var n=this.prepareSearch(e,t);return this._getSortFunction(n)}_getSortFunction(e){var t,n=[];const s=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(s.items[d.id],c)};if(r)for(let c of r)(e.query||c.field!=="$score")&&n.push(c);if(e.query){t=!0;for(let c of n)if(c.field==="$score"){t=!1;break}t&&n.unshift({field:"$score",direction:"desc"})}else n=n.filter(c=>c.field!=="$score");return n.length?function(c,d){var u,f;for(let w of n)if(f=w.field,u=(w.direction==="desc"?-1:1)*_t(l(f,c),l(f,d)),u)return u;return 0}:null}prepareSearch(e,t){const n={};var s=Object.assign({},t);if(te(s,"sort"),te(s,"sort_empty"),s.fields){te(s,"fields");const o=[];s.fields.forEach(r=>{typeof r=="string"&&(r={field:r,weight:1}),o.push(r),n[r.field]="weight"in r?r.weight:1}),s.fields=o}return{options:s,query:e.toLowerCase().trim(),tokens:this.tokenize(e,s.respect_word_boundaries,n),total:0,items:[],weights:n,getAttrFn:s.nesting?bt:wt}}search(e,t){var n=this,s,o;o=this.prepareSearch(e,t),t=o.options,e=o.query;const r=t.score||n._getScoreFunction(o);e.length?K(n.items,(a,c)=>{s=r(a),(t.filter===!1||s>0)&&o.items.push({score:s,id:c})}):K(n.items,(a,c)=>{o.items.push({score:1,id:c})});const l=n._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;"),Ot=(i,e)=>e>0?window.setTimeout(i,e):(i.call(null),null),At=(i,e)=>{var t;return function(n,s){var o=this;t&&(o.loading=Math.max(o.loading-1,0),clearTimeout(t)),t=setTimeout(function(){t=null,o.loadedSearches[n]=!0,i.call(o,n,s)},e)}},he=(i,e,t)=>{var n,s=i.trigger,o={};i.trigger=function(){var r=arguments[0];if(e.indexOf(r)!==-1)o[r]=arguments;else return s.apply(i,arguments)},t.apply(i,[]),i.trigger=s;for(n of e)n in o&&s.apply(i,o[n])},Ct=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,n)=>{i.addEventListener(e,t,n)},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},ne=(i,e)=>{const t=i.getAttribute("id");return t||(i.setAttribute("id",e),e)},pe=i=>i.replace(/[\\"']/g,"\\$&"),R=(i,e)=>{e&&i.append(e)},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(Te(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},Te=i=>typeof i=="string"&&i.indexOf("<")>-1,St=i=>i.replace(/['"\\]/g,"\\$&"),se=(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=Pe(e);i=He(i),i.map(n=>{t.map(s=>{n.classList.add(s)})})},P=(i,...e)=>{var t=Pe(e);i=He(i),i.map(n=>{t.map(s=>{n.classList.remove(s)})})},Pe=i=>{var e=[];return E(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}},ge=(i,e=0)=>e>0?i[i.length-1]:i[0],Et=i=>Object.keys(i).length===0,me=(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(e,(t,n)=>{t==null?i.removeAttribute(n):i.setAttribute(n,""+t)})},le=(i,e)=>{i.parentNode&&i.parentNode.replaceChild(e,i)},$t=(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},n=o=>{o.nodeType===1&&o.childNodes&&!/(script|style)/i.test(o.tagName)&&(o.className!=="highlight"||o.tagName!=="SPAN")&&Array.from(o.childNodes).forEach(r=>{s(r)})},s=o=>o.nodeType===3?t(o):(n(o),0);s(i)},xt=i=>{var e=i.querySelectorAll("span.highlight");Array.prototype.forEach.call(e,function(t){var n=t.parentNode;n.replaceChild(t.firstChild,t),n.normalize()})},It=65,Lt=13,kt=27,Ft=37,Tt=38,Pt=39,Ht=40,ve=8,Dt=46,we=9,Rt=typeof navigator>"u"?!1:/Mac/.test(navigator.userAgent),U=Rt?"metaKey":"ctrlKey",be={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 _e(i,e){var t=Object.assign({},be,e),n=t.dataAttr,s=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,_={},p=1;let C=0;var F=m=>{var b=Object.assign({},m.dataset),g=n&&b[n];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 $=_[g][l];$?Array.isArray($)?$.push(b):_[g][l]=[$,b]:_[g][l]=b}}else{var y=F(m);y[s]=y[s]||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)}},M=m=>{var b,g;g=F(m),g[a]=g[a]||m.getAttribute("label")||"",g[c]=g[c]||p++,g[r]=g[r]||m.disabled,g.$order=g.$order||++C,f.optgroups.push(g),b=g[c],E(m.children,$=>{B($,b)})};f.maxItems=i.hasAttribute("multiple")?null:1,E(i.children,m=>{v=m.tagName.toLowerCase(),v==="optgroup"?M(m):v==="option"&&B(m)})},h=()=>{const v=i.getAttribute(n);if(v)f.options=JSON.parse(v),E(f.options,_=>{f.items.push(_[o])});else{var O=i.value.trim()||"";if(!t.allowEmptyOption&&!O.length)return;const _=O.split(t.delimiter);E(_,p=>{const C={};C[s]=p,C[o]=p,f.options.push(C)}),f.items=_}};return d==="select"?w():h(),Object.assign({},be,f,e)}var ye=0;class I extends tt(et){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,ye++;var n,s=T(e);if(s.tomselect)throw new Error("Tom Select already initialized on this element");s.tomselect=this;var o=window.getComputedStyle&&window.getComputedStyle(s,null);n=o.getPropertyValue("direction");const r=_e(s,t);this.settings=r,this.input=s,this.tabIndex=s.tabIndex||0,this.is_select_tag=s.tagName.toLowerCase()==="select",this.rtl=/rtl/i.test(n),this.inputId=ne(s,"tomselect-"+ye),this.isRequired=s.required,this.sifter=new yt(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 h;if(L(a,r.wrapperClass,f,w),L(c,r.controlClass),R(a,c),L(d,r.dropdownClass,w),r.copyClassesToDropdown&&L(d,f),L(u,r.dropdownContentClass),R(d,u),T(r.dropdownParent||a).appendChild(d),Te(r.controlInput)){h=T(r.controlInput);var v=["autocorrect","autocapitalize","autocomplete","spellcheck"];E(v,O=>{s.getAttribute(O)&&A(h,{[O]:s.getAttribute(O)})}),h.tabIndex=-1,c.appendChild(h),this.focus_node=h}else r.controlInput?(h=T(r.controlInput),this.focus_node=h):(h=T("<input/>"),this.focus_node=c);this.wrapper=a,this.dropdown=d,this.dropdown_content=u,this.control=c,this.control_input=h,this.setup()}setup(){const e=this,t=e.settings,n=e.control_input,s=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=ne(c,e.inputId+"-ts-control"),w="label[for='"+St(e.inputId)+"']",h=document.querySelector(w),v=e.focus.bind(e);if(h){x(h,"click",v),A(h,{for:f});const p=ne(h,e.inputId+"-ts-label");A(c,{"aria-labelledby":p}),A(o,{"aria-labelledby":p})}if(r.style.width=a.style.width,e.plugins.names.length){const p="plugin-"+e.plugins.names.join(" plugin-");L([r,s],p)}(t.maxItems===null||t.maxItems>1)&&e.is_select_tag&&A(a,{multiple:"multiple"}),t.placeholder&&A(n,{placeholder:t.placeholder}),!t.splitOn&&t.delimiter&&(t.splitOn=new RegExp("\\s*"+N(t.delimiter)+"+\\s*")),t.load&&t.loadThrottle&&(t.load=At(t.load,t.loadThrottle)),x(s,"mousemove",()=>{e.ignoreHover=!1}),x(s,"mouseenter",p=>{var C=re(p.target,"[data-selectable]",s);C&&e.onOptionHover(p,C)},{capture:!0}),x(s,"click",p=>{const C=re(p.target,"[data-selectable]");C&&(e.onOptionSelect(p,C),S(p,!0))}),x(l,"click",p=>{var C=re(p.target,"[data-ts-item]",l);if(C&&e.onItemSelect(p,C)){S(p,!0);return}n.value==""&&(e.onClick(),S(p,!0))}),x(c,"keydown",p=>e.onKeyDown(p)),x(n,"keypress",p=>e.onKeyPress(p)),x(n,"input",p=>e.onInput(p)),x(c,"blur",p=>e.onBlur(p)),x(c,"focus",p=>e.onFocus(p)),x(n,"paste",p=>e.onPaste(p));const O=p=>{const C=p.composedPath()[0];if(!r.contains(C)&&!s.contains(C)){e.isFocused&&e.blur(),e.inputState();return}C==n&&e.isOpen?p.stopPropagation():S(p,!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",_),h&&h.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),E(t,n=>{this.registerOptionGroup(n)})}setupTemplates(){var e=this,t=e.settings.labelField,n=e.settings.optgroupLabelField,s={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[n])+"</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({},s,e.settings.render)}setupCallbacks(){var e,t,n={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 n)t=this.settings[n[e]],t&&this.on(e,t)}sync(e=!0){const t=this,n=e?_e(t.input,{delimiter:t.settings.delimiter}):t.settings;t.setupOptions(n.options,n.optgroups),t.setValue(n.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(){se(this.input,"input"),se(this.input,"change")}onPaste(e){var t=this;if(t.isInputHidden||t.isLocked){S(e);return}t.settings.splitOn&&setTimeout(()=>{var n=t.inputValue();if(n.match(t.settings.splitOn)){var s=n.trim().split(t.settings.splitOn);E(s,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 n=String.fromCharCode(e.keyCode||e.which);if(t.settings.create&&t.settings.mode==="multi"&&n===t.settings.delimiter){t.createItem(),S(e);return}}onKeyDown(e){var t=this;if(t.ignoreHover=!0,t.isLocked){e.keyCode!==we&&S(e);return}switch(e.keyCode){case It:if(D(U,e)&&t.control_input.value==""){S(e),t.selectAll();return}break;case kt:t.isOpen&&(S(e,!0),t.close()),t.clearActiveItems();return;case Ht:if(!t.isOpen&&t.hasOptions)t.open();else if(t.activeOption){let n=t.getAdjacent(t.activeOption,1);n&&t.setActiveOption(n)}S(e);return;case Tt:if(t.activeOption){let n=t.getAdjacent(t.activeOption,-1);n&&t.setActiveOption(n)}S(e);return;case Lt: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 Ft:t.advanceSelection(-1,e);return;case Pt:t.advanceSelection(1,e);return;case we:t.settings.selectOnTab&&(t.canSelect(t.activeOption)&&(t.onOptionSelect(e,t.activeOption),S(e)),t.settings.create&&t.createItem()&&S(e));return;case ve:case Dt: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=Ot(()=>{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,n=t.isFocused;if(t.isDisabled||t.isReadOnly){t.blur(),S(e);return}t.ignoreFocus||(t.isFocused=!0,t.settings.preload==="focus"&&t.preload(),n||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 n=()=>{t.close(),t.setActiveItem(),t.setCaret(t.items.length),t.trigger("blur")};t.settings.create&&t.settings.createOnBlur?t.createItem(null,n):n()}}}onOptionSelect(e,t){var n,s=this;t.parentElement&&t.parentElement.matches("[data-disabled]")||(t.classList.contains("create")?s.createItem(null,()=>{s.settings.closeAfterSelect&&s.close()}):(n=t.dataset.value,typeof n<"u"&&(s.lastQuery=null,s.addItem(n),s.settings.closeAfterSelect&&s.close(),!s.settings.hideSelected&&e.type&&/click/.test(e.type)&&s.setActiveOption(t))))}canSelect(e){return!!(this.isOpen&&e&&this.dropdown_content.contains(e))}onItemSelect(e,t){var n=this;return!n.isLocked&&n.settings.mode==="multi"?(S(e),n.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 n=t.loadCallback.bind(t);t.settings.load.call(t,e,n)}loadCallback(e,t){const n=this;n.loading=Math.max(n.loading-1,0),n.lastQuery=null,n.clearActiveOption(),n.setupOptions(e,t),n.refreshOptions(n.isFocused&&!n.isInputHidden),n.loading||P(n.wrapper,n.settings.loadingClass),n.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,n=t.value!==e;n&&(t.value=e,se(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 n=t?[]:["change"];he(this,n,()=>{this.clear(t),this.addItems(e,t)})}setMaxItems(e){e===0&&(e=null),this.settings.maxItems=e,this.refreshState()}setActiveItem(e,t){var n=this,s,o,r,l,a,c;if(n.settings.mode!=="single"){if(!e){n.clearActiveItems(),n.isFocused&&n.inputState();return}if(s=t&&t.type.toLowerCase(),s==="click"&&D("shiftKey",t)&&n.activeItems.length){for(c=n.getLastActive(),r=Array.prototype.indexOf.call(n.control.children,c),l=Array.prototype.indexOf.call(n.control.children,e),r>l&&(a=r,r=l,l=a),o=r;o<=l;o++)e=n.control.children[o],n.activeItems.indexOf(e)===-1&&n.setActiveItemClass(e);S(t)}else s==="click"&&D(U,t)||s==="keydown"&&D("shiftKey",t)?e.classList.contains("active")?n.removeActiveItem(e):n.setActiveItemClass(e):(n.clearActiveItems(),n.setActiveItemClass(e));n.inputState(),n.isFocused||n.focus()}}setActiveItemClass(e){const t=this,n=t.control.querySelector(".last-active");n&&P(n,"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),P(e,"active")}clearActiveItems(){P(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 n=this.dropdown_content,s=n.clientHeight,o=n.scrollTop||0,r=e.offsetHeight,l=e.getBoundingClientRect().top-n.getBoundingClientRect().top+o;l+r>s+o?this.scroll(l-s+r,t):l<o&&this.scroll(l,t)}scroll(e,t){const n=this.dropdown_content;t&&(n.style.scrollBehavior=t),n.scrollTop=e,n.style.scrollBehavior=""}clearActiveOption(){this.activeOption&&(P(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,E(t,n=>{e.setActiveItemClass(n)}))}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,n,s=this,o=this.getSearchOptions();if(s.settings.score&&(n=s.settings.score.call(s,e),typeof n!="function"))throw new Error('Tom Select "score" setting must be a function that returns a function');return e!==s.lastQuery?(s.lastQuery=e,t=s.sifter.search(e,Object.assign(o,{score:n})),s.currentResults=t):t=Object.assign({},s.currentResults),s.settings.hideSelected&&(t.items=t.items.filter(r=>{let l=k(r.id);return!(l&&s.items.indexOf(l)!==-1)})),t}refreshOptions(e=!0){var t,n,s,o,r,l,a,c,d,u;const f={},w=[];var h=this,v=h.inputValue();const O=v===h.lastQuery||v==""&&h.lastQuery==null;var _=h.search(v),p=null,C=h.settings.shouldOpen||!1,F=h.dropdown_content;O&&(p=h.activeOption,p&&(d=p.closest("[data-group]"))),o=_.items.length,typeof h.settings.maxOptions=="number"&&(o=Math.min(o,h.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 $=document.createDocumentFragment();return g=w.length,w.push({fragment:$,order:b,optgroup:m}),[g,$]};for(t=0;t<o;t++){let m=_.items[t];if(!m)continue;let b=m.id,g=h.options[b];if(g===void 0)continue;let $=G(b),y=h.getOption($,!0);for(h.settings.hideSelected||y.classList.toggle("selected",h.items.includes($)),r=g[h.settings.optgroupField]||"",l=Array.isArray(r)?r:[r],n=0,s=l&&l.length;n<s;n++){r=l[n];let z=g.$order,j=h.optgroups[r];j===void 0?r="":z=j.$order;const[De,Re]=B(r,z);n>0&&(y=y.cloneNode(!0),A(y,{id:g.$id+"-clone-"+n,"aria-selected":null}),y.classList.add("ts-cloned"),P(y,"active"),h.activeOption&&h.activeOption.dataset.value==b&&d&&d.dataset.group===r.toString()&&(p=y)),Re.appendChild(y),r!=""&&(f[r]=De)}}h.settings.lockOptgroupOrder&&w.sort((m,b)=>m.order-b.order),a=document.createDocumentFragment(),E(w,m=>{let b=m.fragment,g=m.optgroup;if(!b||!b.children.length)return;let $=h.optgroups[g];if($!==void 0){let y=document.createDocumentFragment(),z=h.render("optgroup_header",$);R(y,z),R(y,b);let j=h.render("optgroup",{group:$,options:y});R(a,j)}else R(a,b)}),F.innerHTML="",R(F,a),h.settings.highlight&&(xt(F),_.query.length&&_.tokens.length&&E(_.tokens,m=>{$t(F,m.regex)}));var M=m=>{let b=h.render(m,{input:v});return b&&(C=!0,F.insertBefore(b,F.firstChild)),b};if(h.loading?M("loading"):h.settings.shouldLoad.call(h,v)?_.items.length===0&&M("no_results"):M("not_loading"),c=h.canCreate(v),c&&(u=M("option_create")),h.hasOptions=_.items.length>0||c,C){if(_.items.length>0){if(!p&&h.settings.mode==="single"&&h.items[0]!=null&&(p=h.getOption(h.items[0])),!F.contains(p)){let m=0;u&&!h.settings.addPrecedence&&(m=1),p=h.selectable()[m]}}else u&&(p=u);e&&!h.isOpen&&(h.open(),h.scrollToOption(p,"auto")),h.setActiveOption(p)}else h.clearActiveOption(),e&&h.isOpen&&h.close(!1)}selectable(){return this.dropdown_content.querySelectorAll("[data-selectable]")}addOption(e,t=!1){const n=this;if(Array.isArray(e))return n.addOptions(e,t),!1;const s=k(e[n.settings.valueField]);return s===null||n.options.hasOwnProperty(s)?!1:(e.$order=e.$order||++n.order,e.$id=n.inputId+"-opt-"+e.$order,n.options[s]=e,n.lastQuery=null,t&&(n.userOptions[s]=t,n.trigger("option_add",s,e)),s)}addOptions(e,t=!1){E(e,n=>{this.addOption(n,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 n;t[this.settings.optgroupValueField]=e,(n=this.registerOptionGroup(t))&&this.trigger("optgroup_add",n,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 n=this;var s,o;const r=k(e),l=k(t[n.settings.valueField]);if(r===null)return;const a=n.options[r];if(a==null)return;if(typeof l!="string")throw new Error("Value must be set in option data");const c=n.getOption(r),d=n.getItem(r);if(t.$order=t.$order||a.$order,delete n.options[r],n.uncacheValue(l),n.options[l]=t,c){if(n.dropdown_content.contains(c)){const u=n._render("option",t);le(c,u),n.activeOption===c&&n.setActiveOption(u)}c.remove()}d&&(o=n.items.indexOf(r),o!==-1&&n.items.splice(o,1,l),s=n._render("item",t),d.classList.contains("active")&&L(s,"active"),le(d,s)),n.lastQuery=null}removeOption(e,t){const n=this;e=G(e),n.uncacheValue(e),delete n.userOptions[e],delete n.options[e],n.lastQuery=null,n.trigger("option_remove",e),n.removeItem(e,t)}clearOptions(e){const t=(e||this.clearFilter).bind(this);this.loadedSearches={},this.userOptions={},this.clearCache();const n={};E(this.options,(s,o)=>{t(s,o)&&(n[o]=s)}),this.options=this.sifter.items=n,this.lastQuery=null,this.trigger("option_clear")}clearFilter(e,t){return this.items.indexOf(t)>=0}getOption(e,t=!1){const n=k(e);if(n===null)return null;const s=this.options[n];if(s!=null){if(s.$div)return s.$div;if(t)return this._render("option",s)}return null}getAdjacent(e,t,n="option"){var s=this,o;if(!e)return null;n=="item"?o=s.controlChildren():o=s.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 n=this,s=Array.isArray(e)?e:[e];s=s.filter(r=>n.items.indexOf(r)===-1);const o=s[s.length-1];s.forEach(r=>{n.isPending=r!==o,n.addItem(r,t)})}addItem(e,t){var n=t?[]:["change","dropdown_close"];he(this,n,()=>{var s,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(s=r._render("item",r.options[a]),r.control.contains(s)&&(s=s.cloneNode(!0)),o=r.isFull(),r.items.splice(r.caretPos,0,a),r.insertAtCaret(s),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,s),r.isPending||r.updateOriginalInput({silent:t})}(!r.isPending||!o&&r.isFull())&&(r.inputState(),r.refreshState())}})}removeItem(e=null,t){const n=this;if(e=n.getItem(e),!e)return;var s,o;const r=e.dataset.value;s=me(e),e.remove(),e.classList.contains("active")&&(o=n.activeItems.indexOf(e),n.activeItems.splice(o,1),P(e,"active")),n.items.splice(s,1),n.lastQuery=null,!n.settings.persist&&n.userOptions.hasOwnProperty(r)&&n.removeOption(r,t),s<n.caretPos&&n.setCaret(n.caretPos-1),n.updateOriginalInput({silent:t}),n.refreshState(),n.positionDropdown(),n.trigger("item_remove",r,e)}createItem(e=null,t=()=>{}){arguments.length===3&&(t=arguments[2]),typeof t!="function"&&(t=()=>{});var n=this,s=n.caretPos,o;if(e=e||n.inputValue(),!n.canCreate(e))return t(),!1;n.lock();var r=!1,l=a=>{if(n.unlock(),!a||typeof a!="object")return t();var c=k(a[n.settings.valueField]);if(typeof c!="string")return t();n.setTextboxValue(),n.addOption(a,!0),n.setCaret(s),n.addItem(c),t(a),r=!0};return typeof n.settings.create=="function"?o=n.settings.create.call(this,e,l):o={[n.settings.labelField]:e,[n.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(),n=e.isLocked;e.wrapper.classList.toggle("rtl",e.rtl);const s=e.wrapper.classList;s.toggle("focus",e.isFocused),s.toggle("disabled",e.isDisabled),s.toggle("readonly",e.isReadOnly),s.toggle("required",e.isRequired),s.toggle("invalid",!e.isValid),s.toggle("locked",n),s.toggle("full",t),s.toggle("input-active",e.isFocused&&!e.isInputHidden),s.toggle("dropdown-active",e.isOpen),s.toggle("has-options",Et(e.options)),s.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 n,s;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(n=t.options[d],s=n[t.settings.labelField]||"",l.includes(n.$option)){const u=t.input.querySelector(`option[value="${pe(d)}"]:not(:checked)`);c(u,d,s)}else n.$option=c(n.$option,d,s)})}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,n=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(),n&&t.trigger("dropdown_close",t.dropdown)}positionDropdown(){if(this.settings.dropdownParent==="body"){var e=this.control,t=e.getBoundingClientRect(),n=e.offsetHeight+t.top+window.scrollY,s=t.left+window.scrollX;q(this.dropdown,{width:t.width+"px",top:n+"px",left:s+"px"})}}clear(e){var t=this;if(t.items.length){var n=t.controlChildren();E(n,s=>{t.removeItem(s,!0)}),t.inputState(),e||t.updateOriginalInput(),t.trigger("clear")}}insertAtCaret(e){const t=this,n=t.caretPos,s=t.control;s.insertBefore(e,s.children[n]||null),t.setCaret(n+1)}deleteSelection(e){var t,n,s,o,r=this;t=e&&e.keyCode===ve?-1:1,n=Ct(r.control_input);const l=[];if(r.activeItems.length)o=ge(r.activeItems,t),s=me(o),t>0&&s++,E(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&&n.start===0&&n.length===0?c=a[r.caretPos-1]:t>0&&n.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 s<"u"&&r.setCaret(s);l.length;)r.removeItem(l.pop());return r.inputState(),r.positionDropdown(),r.refreshOptions(!1),!0}shouldDelete(e,t){const n=e.map(s=>s.dataset.value);return!(!n.length||typeof this.settings.onDelete=="function"&&this.settings.onDelete(n,t)===!1)}advanceSelection(e,t){var n,s,o=this;o.rtl&&(e*=-1),!o.inputValue().length&&(D(U,t)||D("shiftKey",t)?(n=o.getLastActive(e),n?n.classList.contains("active")?s=o.getAdjacent(n,e,"item"):s=n:e>0?s=o.control_input.nextElementSibling:s=o.control_input.previousElementSibling,s&&(s.classList.contains("active")&&o.removeActiveItem(n),o.setActiveItemClass(s))):o.moveCaret(e))}moveCaret(e){}getLastActive(e){let t=this.control.querySelector(".last-active");if(t)return t;var n=this.control.querySelectorAll(".active");if(n)return ge(n,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,P(e.input,"tomselected","ts-hidden-accessible"),e._destroy(),delete e.input.tomselect}render(e,t){var n,s;const o=this;if(typeof this.settings.render[e]!="function"||(s=o.settings.render[e].call(this,t,ie),!s))return null;if(s=T(s),e==="option"||e==="option_create"?t[o.settings.disabledField]?A(s,{"aria-disabled":"true"}):A(s,{"data-selectable":""}):e==="optgroup"&&(n=t.group[o.settings.optgroupValueField],A(s,{"data-group":n}),t.group[o.settings.disabledField]&&A(s,{"data-disabled":""})),e==="option"||e==="item"){const r=G(t[o.settings.valueField]);A(s,{"data-value":r}),e==="item"?(L(s,o.settings.itemClass),A(s,{"data-ts-item":""})):(L(s,o.settings.optionClass),A(s,{role:"option",id:t.$id}),t.$div=s,o.options[r]=t)}return s}_render(e,t){const n=this.render(e,t);if(n==null)throw"HTMLElement expected";return n}clearCache(){E(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,n){var s=this,o=s[t];s[t]=function(){var r,l;return e==="after"&&(r=o.apply(s,arguments)),l=n.apply(s,arguments),e==="instead"?l:(e==="before"&&(r=o.apply(s,arguments)),r)}}}const Mt=(i,e,t,n)=>{i.addEventListener(e,t,n)};function Vt(){Mt(this.input,"change",()=>{this.sync()})}const Nt=i=>typeof i>"u"||i===null?null:Bt(i),Bt=i=>typeof i=="boolean"?i?"1":"0":i+"",Oe=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},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){var e=this,t=e.onOptionSelect;e.settings.hideSelected=!1;const n=Object.assign({className:"tomselect-checkbox",checkedClassNames:void 0,uncheckedClassNames:void 0},i);var s=function(l,a){a?(l.checked=!0,n.uncheckedClassNames&&l.classList.remove(...n.uncheckedClassNames),n.checkedClassNames&&l.classList.add(...n.checkedClassNames)):(l.checked=!1,n.checkedClassNames&&l.classList.remove(...n.checkedClassNames),n.uncheckedClassNames&&l.classList.add(...n.uncheckedClassNames))},o=function(l){setTimeout(()=>{var a=l.querySelector("input."+n.className);a instanceof HTMLInputElement&&s(a,l.classList.contains("selected"))},1)};e.hook("after","setupTemplates",()=>{var r=e.settings.render.option;e.settings.render.option=(l,a)=>{var c=zt(r.call(e,l,a)),d=document.createElement("input");n.className&&d.classList.add(n.className),d.addEventListener("click",function(f){Oe(f)}),d.type="checkbox";const u=Nt(l[e.settings.valueField]);return s(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(),Oe(r,!0);return}t.call(e,r,l),o(l)})}const qt=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(Ut(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},Ut=i=>typeof i=="string"&&i.indexOf("<")>-1;function Yt(i){const e=this,t=Object.assign({className:"clear-button",title:"Clear All",html:n=>`<div class="${n.className}" title="${n.title}">&#10799;</div>`},i);e.on("initialize",()=>{var n=qt(t.html(t));n.addEventListener("click",s=>{e.isLocked||(e.clear(),e.settings.mode==="single"&&e.settings.allowEmptyOption&&e.addItem(""),s.preventDefault(),s.stopPropagation())}),e.control.appendChild(n)})}const Gt=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},V=(i,e,t,n)=>{i.addEventListener(e,t,n)},Wt=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},Qt=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,Xt=(i,e)=>{Wt(e,(t,n)=>{t==null?i.removeAttribute(n):i.setAttribute(n,""+t)})},Zt=(i,e)=>{var t;(t=i.parentNode)==null||t.insertBefore(e,i.nextSibling)},ei=(i,e)=>{var t;(t=i.parentNode)==null||t.insertBefore(e,i)},ti=(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 ii(){var i=this;if(i.settings.mode!=="multi")return;var e=i.lock,t=i.unlock;let n=!0,s;i.hook("after","setupTemplates",()=>{var o=i.settings.render.item;i.settings.render.item=(r,l)=>{const a=Qt(o.call(i,r,l));Xt(a,{draggable:"true"});const c=v=>{n||Gt(v),v.stopPropagation()},d=v=>{s=a,setTimeout(()=>{a.classList.add("ts-dragging")},0)},u=v=>{v.preventDefault(),a.classList.add("ts-drag-over"),w(a,s)},f=()=>{a.classList.remove("ts-drag-over")},w=(v,O)=>{O!==void 0&&(ti(O,a)?Zt(v,O):ei(v,O))},h=()=>{var v;document.querySelectorAll(".ts-drag-over").forEach(_=>_.classList.remove("ts-drag-over")),(v=s)==null||v.classList.remove("ts-dragging"),s=void 0;var O=[];i.control.querySelectorAll("[data-value]").forEach(_=>{if(_.dataset.value){let p=_.dataset.value;p&&O.push(p)}}),i.setValue(O)};return V(a,"mousedown",c),V(a,"dragstart",d),V(a,"dragenter",u),V(a,"dragover",u),V(a,"dragleave",f),V(a,"dragend",h),a}}),i.hook("instead","lock",()=>(n=!1,e.call(i))),i.hook("instead","unlock",()=>(n=!0,t.call(i)))}const ni=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},si=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(ri(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},ri=i=>typeof i=="string"&&i.indexOf("<")>-1;function oi(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:n=>'<div class="'+n.headerClass+'"><div class="'+n.titleRowClass+'"><span class="'+n.labelClass+'">'+n.title+'</span><a class="'+n.closeClass+'">&times;</a></div></div>'},i);e.on("initialize",()=>{var n=si(t.html(t)),s=n.querySelector("."+t.closeClass);s&&s.addEventListener("click",o=>{ni(o,!0),e.close()}),e.dropdown.insertBefore(n,e.dropdown.firstChild)})}const li=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},ai=(i,...e)=>{var t=ci(e);i=di(i),i.map(n=>{t.map(s=>{n.classList.remove(s)})})},ci=i=>{var e=[];return li(i,t=>{typeof t=="string"&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},di=i=>(Array.isArray(i)||(i=[i]),i),ui=(i,e)=>{if(!i)return-1;e=e||i.nodeName;for(var t=0;i=i.previousElementSibling;)i.matches(e)&&t++;return t};function fi(){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,n)=>{n<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 n=ui(t);i.setCaret(e>0?n+1:n),i.setActiveItem(),ai(t,"last-active")}else i.setCaret(i.caretPos+e)})}const hi=27,pi=9,gi=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},mi=(i,e,t,n)=>{i.addEventListener(e,t,n)},vi=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},Ae=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(wi(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},wi=i=>typeof i=="string"&&i.indexOf("<")>-1,bi=(i,...e)=>{var t=_i(e);i=yi(i),i.map(n=>{t.map(s=>{n.classList.add(s)})})},_i=i=>{var e=[];return vi(i,t=>{typeof t=="string"&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},yi=i=>(Array.isArray(i)||(i=[i]),i);function Oi(){const i=this;i.settings.shouldOpen=!0,i.hook("before","setup",()=>{i.focus_node=i.control,bi(i.control_input,"dropdown-input");const e=Ae('<div class="dropdown-input-wrap">');e.append(i.control_input),i.dropdown.insertBefore(e,i.dropdown.firstChild);const t=Ae('<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 hi:i.isOpen&&(gi(t,!0),i.close()),i.clearActiveItems();return;case pi: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)}),mi(i.control_input,"blur",()=>i.onBlur()),i.hook("before","close",()=>{i.isOpen&&i.focus_node.focus({preventScroll:!0})})})}const Y=(i,e,t,n)=>{i.addEventListener(e,t,n)};function Ai(){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 n=["letterSpacing","fontSize","fontFamily","fontWeight","textTransform"];for(const o of n)e.style[o]=t.style[o];var s=()=>{e.textContent=t.value,t.style.width=e.clientWidth+"px"};s(),i.on("update item_add item_remove",s),Y(t,"input",s),Y(t,"keyup",s),Y(t,"blur",s),Y(t,"update",s)})}function Ci(){var i=this,e=i.deleteSelection;this.hook("instead","deleteSelection",t=>i.activeItems.length?e.call(i,t):!1)}function Si(){this.hook("instead","setActiveItem",()=>{}),this.hook("instead","selectAll",()=>{})}const Ce=37,Ei=39,$i=(i,e,t)=>{for(;i&&i.matches;){if(i.matches(e))return i;i=i.parentNode}},xi=(i,e)=>{if(!i)return-1;e=e||i.nodeName;for(var t=0;i=i.previousElementSibling;)i.matches(e)&&t++;return t};function Ii(){var i=this,e=i.onKeyDown;i.hook("instead","onKeyDown",t=>{var n,s,o,r;if(!i.isOpen||!(t.keyCode===Ce||t.keyCode===Ei))return e.call(i,t);i.ignoreHover=!0,r=$i(i.activeOption,"[data-group]"),n=xi(i.activeOption,"[data-selectable]"),r&&(t.keyCode===Ce?r=r.previousSibling:r=r.nextSibling,r&&(o=r.querySelectorAll("[data-selectable]"),s=o[Math.min(o.length-1,n)],s&&i.setActiveOption(s)))})}const Li=i=>(i+"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Se=(i,e=!1)=>{i&&(i.preventDefault(),e&&i.stopPropagation())},Ee=(i,e,t,n)=>{i.addEventListener(e,t,n)},$e=i=>{if(i.jquery)return i[0];if(i instanceof HTMLElement)return i;if(ki(i)){var e=document.createElement("template");return e.innerHTML=i.trim(),e.content.firstChild}return document.querySelector(i)},ki=i=>typeof i=="string"&&i.indexOf("<")>-1;function Fi(i){const e=Object.assign({label:"&times;",title:"Remove",className:"remove",append:!0},i);var t=this;if(e.append){var n='<a href="javascript:void(0)" class="'+e.className+'" tabindex="-1" title="'+Li(e.title)+'">'+e.label+"</a>";t.hook("after","setupTemplates",()=>{var s=t.settings.render.item;t.settings.render.item=(o,r)=>{var l=$e(s.call(t,o,r)),a=$e(n);return l.appendChild(a),Ee(a,"mousedown",c=>{Se(c,!0)}),Ee(a,"click",c=>{t.isLocked||(Se(c,!0),!t.isLocked&&t.shouldDelete([l],c)&&(t.removeItem(l),t.refreshOptions(!1),t.inputState()))}),l}})}}function Ti(i){const e=this,t=Object.assign({text:n=>n[e.settings.labelField]},i);e.on("item_remove",function(n){if(e.isFocused&&e.control_input.value.trim()===""){var s=e.options[n];s&&e.setTextboxValue(t.text.call(e,s))}})}const Pi=(i,e)=>{if(Array.isArray(i))i.forEach(e);else for(var t in i)i.hasOwnProperty(t)&&e(i[t],t)},Hi=(i,...e)=>{var t=Di(e);i=Ri(i),i.map(n=>{t.map(s=>{n.classList.add(s)})})},Di=i=>{var e=[];return Pi(i,t=>{typeof t=="string"&&(t=t.trim().split(/[\t\n\f\r\s]/)),Array.isArray(t)&&(e=e.concat(t))}),e.filter(Boolean)},Ri=i=>(Array.isArray(i)||(i=[i]),i);function Mi(){const i=this,e=i.canLoad,t=i.clearActiveOption,n=i.loadCallback;var s={},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 s&&s[u]),d=(u,f)=>i.items.indexOf(f)>=0||a.indexOf(f)>=0;i.setNextUrl=(u,f)=>{s[u]=f},i.getUrl=u=>{if(u in s){const f=s[u];return s[u]=!1,f}return i.clearPagination(),i.settings.firstUrl.call(i,u)},i.clearPagination=()=>{s={}},i.hook("instead","clearActiveOption",()=>{if(!r)return t.call(i)}),i.hook("instead","canLoad",u=>u in s?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])}n.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 s&&!o.querySelector(".no-results")&&(f=i.render("no_more_results",{query:u})),f&&(Hi(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",Vt);I.define("checkbox_options",Kt);I.define("clear_button",Yt);I.define("drag_drop",ii);I.define("dropdown_header",oi);I.define("caret_position",fi);I.define("dropdown_input",Oi);I.define("input_autogrow",Ai);I.define("no_backspace_delete",Ci);I.define("no_active_items",Si);I.define("optgroup_columns",Ii);I.define("remove_button",Fi);I.define("restore_on_backspace",Ti);I.define("virtual_scroll",Mi);const Vi=i=>({init(){const e=this.$refs[`select_picker_${i.dataField}_${i.tableName}`],t={items:i.initialValues,...i.framework,onChange:o=>{xe(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)})}},n={valueField:i.optionValue,labelField:i.optionLabel,searchField:i.optionLabel,load:async function(o,r){function l(a,c){var h;const{method:d,url:u}=a,f=new Request(u,{method:d,body:d.toLowerCase()==="post"?JSON.stringify({search:c,...s}):void 0});f.headers.set("Content-Type","application/json"),f.headers.set("Accept","application/json"),f.headers.set("X-Requested-With","XMLHttpRequest");const w=(h=document.head.querySelector('[name="csrf-token"]'))==null?void 0:h.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 s=t;i.hasOwnProperty("asyncData")&&(s=Object.assign(t,n)),new I(e,s)}}),Ni=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:n=>{let s=n.map(o=>o.value);xe(i,s)}}})},deepCopy(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(this.deepCopy);const t={};for(const n in e)e.hasOwnProperty(n)&&(t[n]=this.deepCopy(e[n]));return t}}),Bi=()=>({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)}}),zi=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 s=window[`pgActions_${t}`];s&&s[this.rowId]!==void 0&&(e=s[this.rowId])}else e=window[`pgActionsHeader_${t}`];if(typeof e!="object"||e===null)return"";let n="";return e.forEach(s=>{let o=this.shouldHideAction(s),r=this.getReplaceHtml(s);if(!o)if(r)n+=r;else{let l=this.buildAttributesString(s);if(s.icon){let a=this.processIcon(s);if(!a)return;n+=this.buildActionHtmlWithIcon(s,l,a)}else n+=this.buildActionHtml(s,l)}}),n},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(n=>{n.action.includes(e.action)&&n.apply&&n.rule.hide&&(t=!0)}),t},getReplaceHtml(e){let t=null;return e.rules&&Object.values(e.rules).length>0&&Object.values(e.rules).forEach(n=>{n.apply&&n.action.includes(e.action)&&n.replaceHtml&&(t=n.replaceHtml)}),t},buildAttributesString(e){let t=e.attributes??[];return e.rules&&Object.values(e.rules).length>0&&Object.values(e.rules).forEach(n=>{n.apply&&n.action.includes(e.action)&&n.rule.setAttribute&&n.rule.setAttribute.length>0&&Object.values(n.rule.setAttribute).forEach(s=>{t[s.attribute]=s.value})}),Object.entries(t).map(([n,s])=>` ${n}="${s}"`).join("")},processIcon(e){const t=Object.entries(e.iconAttributes??[]).map(([s,o])=>` ${s}="${o}"`).join("");let n=window.pgResourceIcons[e.icon];return typeof n>"u"?(console.warn(`PowerGrid: Unable to load icons in javascript window in row: [${this.rowId}]`),null):this.replaceIconAttributes(n,t)},replaceIconAttributes(e,t){return e.replace(/<([^\s>]+)([^>]*)>/,(n,s,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`<${s} ${r} ${l}>`})},buildActionHtmlWithIcon(e,t,n){return e.slot?`<${e.tag??"button"} ${t}>${n} ${e.slot}</${e.tag??"button"}>`:`<${e.tag??"button"} ${t}>${n}</${e.tag??"button"}>`},buildActionHtml(e,t){return`<${e.tag??"button"} ${t}>${e.slot}</${e.tag??"button"}>`}}),ji=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],n=this.templateContent[e];if(n){let s=t;for(const[o,r]of Object.entries(n)){const l=`{{ ${o} }}`,a=String(r).replace(/'/g,"\\'");s=s.replaceAll(l,a)}this.rendered=s}}}),Ki=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(n=>{e[n]+=e[n]?` ${t[n]}`:t[n]})}),e}});window.pgToggleable=Ne;window.pgFlatpickr=Ke;window.pgEditable=qe;window.pgResponsive=Xe;window.pgTomSelect=Vi;window.pgSlimSelect=Ni;window.pgLoadMore=Bi;window.pgRenderActions=zi;window.pgRowAttributes=Ki;window.pgRenderRowTemplate=ji;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)})})});
