monobill-mintui 0.6.607 → 0.6.609
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/form/Form.d.ts +7 -0
- package/dist/components/form/Form.d.ts.map +1 -1
- package/dist/components/select/Select.d.ts +3 -0
- package/dist/components/select/Select.d.ts.map +1 -1
- package/dist/index.cjs +9 -5
- package/dist/index.js +169 -125
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -79,8 +79,12 @@ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{val
|
|
|
79
79
|
background: rgba(255, 255, 255, 0.2);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
`,n.classList.add(`mint-date-shortcuts-row`),document.head.querySelector(`style[data-mint-date-shortcuts]`)||(r.setAttribute(`data-mint-date-shortcuts`,`true`),document.head.appendChild(r));let i=document.createElement(`div`);i.className=`absolute left-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-r from-white dark:from-mint-elevated to-transparent opacity-0 md:hidden`,t.appendChild(i);let a=document.createElement(`div`);a.className=`absolute right-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-l from-white dark:from-mint-elevated to-transparent opacity-100 md:hidden`,t.appendChild(a);let s=document.createElement(`div`);s.className=`hidden md:block absolute top-0 left-0 right-0 h-8 pointer-events-none z-10 bg-gradient-to-b from-white dark:from-mint-elevated to-transparent opacity-0`,t.appendChild(s);let l=document.createElement(`div`);l.className=`hidden md:block absolute bottom-0 left-0 right-0 h-8 pointer-events-none z-10 bg-gradient-to-t from-white dark:from-mint-elevated to-transparent opacity-100`,t.appendChild(l);let u=()=>{if(window.innerWidth>=768){let e=n.scrollTop,t=n.scrollHeight,r=n.clientHeight;e>0?s.style.opacity=`1`:s.style.opacity=`0`,e+r<t-1?l.style.opacity=`1`:l.style.opacity=`0`,i.style.opacity=`0`,a.style.opacity=`0`}else{let e=n.scrollLeft,t=n.scrollWidth,r=n.clientWidth;e>0?i.style.opacity=`1`:i.style.opacity=`0`,e+r<t-1?a.style.opacity=`1`:a.style.opacity=`0`,s.style.opacity=`0`,l.style.opacity=`0`}};n.addEventListener(`scroll`,u),window.addEventListener(`resize`,u),setTimeout(u,0),o.forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.tabIndex=0,t.className=`px-3 py-1.5 text-xs font-medium rounded-md bg-gray-100 dark:bg-mint-hover text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-mint-elevated whitespace-nowrap flex-shrink-0 md:w-full md:text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,t.textContent=e.label,t.setAttribute(`data-keep-popover-open`,`true`);let r=()=>{let t=e.action();if(t){if(this._isRange&&`start`in t&&`end`in t){this._selectedStartDate=t.start,this._selectedEndDate=t.end;let e=this.getFormat(),n=`${this._formatDate(t.start,e)} - ${this._formatDate(t.end,e)}`;this.setValue(n),this._currentMonth=t.start.getMonth(),this._currentYear=t.start.getFullYear()}else if(t instanceof Date){this._selectedStartDate=t,this._selectedEndDate=null;let e=this.getFormat(),n=this._formatDate(t,e);this.setValue(n),this._currentMonth=t.getMonth(),this._currentYear=t.getFullYear()}this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close(),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0}))}};t.addEventListener(`click`,r),t.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),n.appendChild(t)}),t.appendChild(n),e.appendChild(t),c.appendChild(e)}l.appendChild(u),l.appendChild(b),l.appendChild(x),c.appendChild(l),this._calendarContainer.appendChild(c)}_buildMonthView(){if(!this._calendarContainer)return;let e=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],t=document.createElement(`div`);t.className=`flex items-center justify-between mb-4`;let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,n.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,n.setAttribute(`data-keep-popover-open`,`true`);let r=document.createElement(`mint-icon`);r.setAttribute(`name`,`caret-left`),r.className=`w-4 h-4`,n.appendChild(r);let i=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear--,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};n.addEventListener(`click`,i),n.addEventListener(`touchend`,e=>{e.preventDefault(),i()},{passive:!1}),t.appendChild(n);let a=document.createElement(`button`);a.type=`button`,a.tabIndex=0,a.className=`text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 rounded px-1`,a.setAttribute(`data-keep-popover-open`,`true`),a.textContent=String(this._currentYear);let o=()=>{this.getMode()!==`year`&&(this._viewMode=`year`,this._buildCalendar())};a.addEventListener(`click`,o),a.addEventListener(`touchend`,e=>{e.preventDefault(),o()},{passive:!1}),t.appendChild(a);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`w-4 h-4`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear++,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),t.appendChild(s);let u=document.createElement(`div`);u.className=`grid grid-cols-3 gap-2`,e.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,n.setAttribute(`data-keep-popover-open`,`true`),n.className=`p-2 rounded text-sm font-medium focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${this._currentMonth===t?`bg-slate-800 dark:bg-slate-600 text-white`:`text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-mint-hover`}`,n.textContent=e;let r=()=>{if(this.getMode()===`month`){let e=new Date(this._currentYear,t,1),n=this.getFormat(),r=this._formatDate(e,n);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentMonth=t,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else{let e=this._currentMonth,n=this._currentYear;this._currentMonth=t,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,n,this._currentMonth,this._currentYear)}};n.addEventListener(`click`,r),n.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),u.appendChild(n)}),this._calendarContainer.appendChild(t),this._calendarContainer.appendChild(u)}_buildYearView(){if(!this._calendarContainer)return;let e=this._currentYear-6,t=this._currentYear+6,n=document.createElement(`div`);n.className=`flex items-center justify-between mb-4`;let r=document.createElement(`button`);r.type=`button`,r.tabIndex=0,r.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,r.setAttribute(`data-keep-popover-open`,`true`);let i=document.createElement(`mint-icon`);i.setAttribute(`name`,`caret-left`),i.className=`w-4 h-4`,r.appendChild(i);let a=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear-=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};r.addEventListener(`click`,a),r.addEventListener(`touchend`,e=>{e.preventDefault(),a()},{passive:!1}),n.appendChild(r);let o=document.createElement(`div`);o.className=`text-sm font-medium text-gray-900 dark:text-gray-100`,o.textContent=`${e} - ${t}`,n.appendChild(o);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`w-4 h-4`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear+=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),n.appendChild(s);let u=document.createElement(`div`);u.className=`grid grid-cols-3 gap-2`;for(let n=e;n<=t;n++){let e=document.createElement(`button`);e.type=`button`,e.tabIndex=0,e.setAttribute(`data-keep-popover-open`,`true`),e.className=`p-2 rounded text-sm font-medium focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${this._currentYear===n?`bg-slate-800 dark:bg-slate-600 text-white`:`text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-mint-hover`}`,e.textContent=String(n),e.addEventListener(`click`,()=>{let e=this.getMode();if(e===`year`){let e=new Date(n,0,1),t=this.getFormat(),r=this._formatDate(e,t);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentYear=n,this._currentMonth=0,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(e===`month`){let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`month`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}else{let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}}),u.appendChild(e)}this._calendarContainer.appendChild(n),this._calendarContainer.appendChild(u)}_getDaysInMonth(e,t){return new Date(t,e+1,0).getDate()}_getFirstDayOfMonth(e,t){let n=this.getWeekStartDay(),r=new Date(t,e,1).getDay();return r>=n?r-n:7-(n-r)}_isToday(e){let t=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateSelected(e){let t=this.getSelectionMode();return this._isRange||t===`week`||t===`month`?this._selectedStartDate&&this._selectedEndDate?this._isSameDate(e,this._selectedStartDate)||this._isSameDate(e,this._selectedEndDate):this._isRange&&this._selectedStartDate&&!this._selectedEndDate?this._isSameDate(e,this._selectedStartDate):!1:this._selectedStartDate!==null&&this._isSameDate(e,this._selectedStartDate)}_isDateInRange(e){let t=this.getSelectionMode();if((this._isRange||t===`week`||t===`month`)&&this._selectedStartDate&&this._selectedEndDate)return this._rangeIncludesDisabledDates(this._selectedStartDate,this._selectedEndDate)?!1:e>=this._selectedStartDate&&e<=this._selectedEndDate;if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate){let t=this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,n=this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate;if(this._rangeIncludesDisabledDates(t,n)){let r=this._findFirstDisabledDateInRange(t,n);return r?this._selectedStartDate<this._hoveredDate?e>=t&&e<r&&!this._isSameDate(e,t):e>r&&e<=n&&!this._isSameDate(e,n):!1}return e>=t&&e<=n&&!this._isSameDate(e,t)&&!this._isSameDate(e,n)}return!1}_rangeIncludesDisabledDates(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate());return n.some(e=>{let t=new Date(e.getFullYear(),e.getMonth(),e.getDate());return t>=r&&t<=i})}_findFirstDisabledDateInRange(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()),a=n.map(e=>new Date(e.getFullYear(),e.getMonth(),e.getDate())).filter(e=>e>=r&&e<=i).sort((e,t)=>e.getTime()-t.getTime());return a.length>0?a[0]:null}_hasIncompleteRange(){return this._isRange&&this._selectedStartDate!==null&&this._selectedEndDate===null}_isSameDate(e,t){return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateDisabled(e){return this.getDisabledDates().some(t=>this._isSameDate(e,t))}_dispatchMonthChangeEvent(e,t,n,r){(e!==n||t!==r)&&this.dispatchEvent(new CustomEvent(`month-change`,{detail:{month:n,year:r,oldMonth:e,oldYear:t},bubbles:!0,cancelable:!0,composed:!0}))}_dispatchDateChangeEvent(){let e=this.getFormat(),t={value:this.getValue()};this._selectedStartDate&&(t.startDate=this._selectedStartDate,t.startDateFormatted=this._formatDate(this._selectedStartDate,e)),this._selectedEndDate&&(t.endDate=this._selectedEndDate,t.endDateFormatted=this._formatDate(this._selectedEndDate,e)),this.dispatchEvent(new CustomEvent(`date-change`,{detail:t,bubbles:!0,cancelable:!0,composed:!0}))}_setupContainerObserver(){if(this._resizeObserver&&=(this._resizeObserver.disconnect(),null),!this._inputsWrapperEl)return;let e=e=>{this._inputsWrapperEl&&(e<400?(this._inputsWrapperEl.classList.add(`flex-wrap`),this._inputsWrapperEl.classList.remove(`flex-nowrap`)):(this._inputsWrapperEl.classList.remove(`flex-wrap`),this._inputsWrapperEl.classList.add(`flex-nowrap`)))};e(this._inputsWrapperEl.offsetWidth||this.offsetWidth),this._resizeObserver=new ResizeObserver(t=>{for(let n of t){let t=n.contentRect.width;e(t)}}),this._resizeObserver.observe(this)}_getWeekStart(e){let t=this.getWeekStartDay(),n=e.getDay(),r;r=n>=t?n-t:7-(t-n);let i=new Date(e);return i.setDate(e.getDate()-r),i.setHours(0,0,0,0),i}_getWeekEnd(e){let t=this._getWeekStart(e),n=new Date(t);return n.setDate(t.getDate()+6),n.setHours(23,59,59,999),n}_getMonthStart(e){let t=new Date(e.getFullYear(),e.getMonth(),1);return t.setHours(0,0,0,0),t}_getMonthEnd(e){let t=new Date(e.getFullYear(),e.getMonth()+1,0);return t.setHours(23,59,59,999),t}_handleDateClick(e){this._isHandlingClick=!0;try{let t=this.getFormat(),n=this.getSelectionMode(),r,i;if(n===`week`?(r=this._getWeekStart(e),i=this._getWeekEnd(e)):n===`month`?(r=this._getMonthStart(e),i=this._getMonthEnd(e)):(r=e,i=e),this.isRange()||n===`week`||n===`month`)if(n===`week`||n===`month`){if(this._rangeIncludesDisabledDates(r,i)){this._buildCalendar();return}this._selectedStartDate=r,this._selectedEndDate=i;let e=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(this._hoveredDate=null,this._selectedStartDate===null){if(this._isDateDisabled(r)){this._buildCalendar();return}this._selectedStartDate=new Date(r.getFullYear(),r.getMonth(),r.getDate()),this._selectedEndDate=null,this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear(),this._hoveredDate=null,this._buildCalendar()}else if(this._selectedEndDate===null){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=this._selectedStartDate?new Date(this._selectedStartDate.getFullYear(),this._selectedStartDate.getMonth(),this._selectedStartDate.getDate()):null,i,a;if(r&&n<r?(i=n,a=r):(i=r,a=n),this._rangeIncludesDisabledDates(i,a)){this._buildCalendar();return}r&&n<r?(this._selectedEndDate=r,this._selectedStartDate=n):(this._selectedEndDate=n,r&&(this._selectedStartDate=r)),this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();let o=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setAttribute(`value`,o),this._textInput&&(this._textInput.value=o),this._hiddenInput&&(this._hiddenInput.value=o),this._updateDisplayText(),this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else this._selectedStartDate=r,this._selectedEndDate=null;else{this._selectedStartDate=r,this._selectedEndDate=null;let e=this._formatDate(r,t);this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}this._buildCalendar(),this._updateDisplayText(),this._exitInputMode();let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this._dispatchDateChangeEvent()}finally{this._isHandlingClick=!1}}_updateDisplayText(){if(!this._displayEl)return;let e=this.getDisplayFormat(),t=this.getSelectionMode(),n=this._isRange||t===`week`||t===`month`,r=``;n&&this._selectedStartDate&&this._selectedEndDate?r=`${this._formatDatePhp(this._selectedStartDate,e)} - ${this._formatDatePhp(this._selectedEndDate,e)}`:this._selectedStartDate&&(r=this._formatDatePhp(this._selectedStartDate,e)),r?(this._displayEl.textContent=r,this._displayEl.classList.remove(`text-gray-400`,`dark:text-gray-500`),this._displayEl.classList.add(`text-gray-900`,`dark:text-white`)):(this._displayEl.textContent=`Select date`,this._displayEl.classList.add(`text-gray-400`,`dark:text-gray-500`),this._displayEl.classList.remove(`text-gray-900`,`dark:text-white`)),this._displayEl&&this._inputsWrapperEl&&(this._displayEl.style.display=this._isInputMode?`none`:`flex`,this._inputsWrapperEl.style.display=this._isInputMode?`flex`:`none`)}_enterInputMode(){if(!this._isInputMode&&!(this.isReadonly()||this.isDisabled())&&(this._isInputMode=!0,this._displayEl&&this._inputsWrapperEl&&(this._displayEl.style.display=`none`,this._inputsWrapperEl.style.display=`flex`),this._startPartInputs.length>0)){let e=this._startPartInputs[0];requestAnimationFrame(()=>{e.focus();try{e.setSelectionRange(0,e.value.length)}catch{}})}}_exitInputMode(){this._isInputMode&&(this._isInputMode=!1,this._displayEl&&this._inputsWrapperEl&&(this._displayEl.style.display=`flex`,this._inputsWrapperEl.style.display=`none`),this._updateDisplayText())}_renderSkeleton(e){let t=this.querySelector(`.mint-date-picker-skeleton-container`),n=this._fieldsContainer,r=this._input;if(e){t||(t=document.createElement(`div`),t.className=`mint-date-picker-skeleton-container absolute inset-0 z-10 pointer-events-none`,r?(r.classList.contains(`relative`)||r.classList.add(`relative`),r.appendChild(t)):(this.style.position=`relative`,this.appendChild(t)));let e=t.querySelector(`.mint-date-picker-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-date-picker-skeleton w-full rounded-lg bg-gray-200 dark:bg-mint-hover animate-pulse`,e.style.height=`2.25rem`,t.appendChild(e)),t.style.display=`block`,n&&(n.style.visibility=`hidden`,n.style.pointerEvents=`none`),this._displayEl&&(this._displayEl.style.visibility=`hidden`,this._displayEl.style.pointerEvents=`none`)}else t&&(t.style.display=`none`),n&&(n.style.visibility=`visible`,n.style.pointerEvents=`auto`),this._displayEl&&(this._displayEl.style.visibility=`visible`,this._displayEl.style.pointerEvents=`auto`)}_getFocusableElements(){if(!this._calendarContainer)return[];let e=[`button:not([disabled])`,`a[href]`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`, `);return Array.from(this._calendarContainer.querySelectorAll(e)).filter(e=>{let t=window.getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}_setupFocusTrap(){if(!this._popover||!this._popover.hasAttribute(`open`))return;this._removeFocusTrap();let e=this;this._focusTrapHandler=function(t){if(t.key!==`Tab`)return;if(!e._popover||!e._popover.hasAttribute(`open`)){e._removeFocusTrap();return}let n=e._getFocusableElements();if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;if(!e._calendarContainer?.contains(a)){t.preventDefault(),r.focus();return}if(t.shiftKey&&a===r){t.preventDefault(),i.focus();return}if(!t.shiftKey&&a===i){t.preventDefault(),r.focus();return}},this._escapeHandler=function(t){(t.key===`Escape`||t.key===`Esc`)&&e._popover&&e._popover.hasAttribute(`open`)&&(t.preventDefault(),t.stopPropagation(),typeof e._popover.close==`function`&&e._popover.close())},document.addEventListener(`keydown`,this._focusTrapHandler,!0),document.addEventListener(`keydown`,this._escapeHandler,!0),requestAnimationFrame(()=>{let e=this._getFocusableElements();e.length>0&&e[0].focus()})}_removeFocusTrap(){this._focusTrapHandler&&=(document.removeEventListener(`keydown`,this._focusTrapHandler,!0),null),this._escapeHandler&&=(document.removeEventListener(`keydown`,this._escapeHandler,!0),null)}};customElements.get(`mint-date-picker`)||customElements.define(`mint-date-picker`,C);var w=class extends HTMLElement{constructor(...e){super(...e),this._triggerId=`mint-time-picker-trigger-${Math.random().toString(36).slice(2,10)}`,this._popover=null,this._popoverObserver=null,this._inputEl=null,this._hiddenInput=null,this._single={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeStart={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeEnd={hour:5,minute:0,second:0,meridiem:`PM`},this._invalidFromInput=!1}static get observedAttributes(){return[`value`,`label`,`info`,`disabled`,`id`,`name`,`required`,`readonly`,`range`,`hours`,`minutes`,`seconds`,`error`,`error-message`]}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`),this._parseAndApplyValue(this.getAttribute(`value`)||``),this.render()}disconnectedCallback(){this._popoverObserver&&=(this._popoverObserver.disconnect(),null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`value`){if(this._parseAndApplyValue(n||``),this._syncHiddenInput(),this._syncInputValue(),this._popover){let e=this._popover.querySelector(`[data-mint-time-picker-body="true"]`);e&&this._buildPopoverContent(e)}return}e!==`error`&&e!==`error-message`&&(this._invalidFromInput=!1),this.render()}}get value(){return this.getValue()}set value(e){this.setValue(e||``)}getValue(){return this.getAttribute(`value`)||``}setValue(e){e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this._parseAndApplyValue(e||``),this._syncHiddenInput(),this._syncInputValue()}isRange(){return this.getAttribute(`range`)===`true`}isHoursEnabled(){let e=this.getAttribute(`hours`);return e===null?!0:e!==`false`}isMinutesEnabled(){let e=this.getAttribute(`minutes`);return e===null?!0:e!==`false`}isSecondsEnabled(){let e=this.getAttribute(`seconds`);return e===null?!1:e!==`false`}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasExternalError(){return this.getAttribute(`error`)===`true`}getExternalErrorMessage(){return this.getAttribute(`error-message`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getName(){return this.getAttribute(`name`)||``}_getEffectiveError(){return{hasError:this.hasExternalError(),message:this.getExternalErrorMessage()}}_formatParts(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=[];return t&&i.push(e.hour.toString()),n&&i.push(e.minute.toString().padStart(2,`0`)),r&&i.push(e.second.toString().padStart(2,`0`)),t?`${i.join(`:`)} ${e.meridiem.toLowerCase()}`:i.join(`:`)}_to24Hour(e){let t=e.hour%12;return e.meridiem===`PM`&&(t+=12),{hour:t,minute:e.minute,second:e.second}}_formatParts24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=this._to24Hour(e),a=[];return t&&a.push(i.hour.toString().padStart(2,`0`)),n&&a.push(i.minute.toString().padStart(2,`0`)),r&&a.push(i.second.toString().padStart(2,`0`)),a.join(`:`)}_getDisplayValue(){return this.isRange()?`${this._formatParts(this._rangeStart)} - ${this._formatParts(this._rangeEnd)}`:this._formatParts(this._single)}_getOutputValue(){return this.isRange()?`${this._formatParts24(this._rangeStart)} - ${this._formatParts24(this._rangeEnd)}`:this._formatParts24(this._single)}_getExpectedFormat(){let e=this.isHoursEnabled(),t=this.isMinutesEnabled(),n=this.isSecondsEnabled(),r=[];e&&r.push(`h`),t&&r.push(`mm`),n&&r.push(`ss`);let i=e?`${r.join(`:`)} am/pm`:r.join(`:`);return this.isRange()?`${i} - ${i}`:i}_syncHiddenInput(){this._hiddenInput&&(this._hiddenInput.value=this.getValue()||this._getOutputValue())}_syncInputValue(){this._inputEl&&(this._inputEl.value=this._getDisplayValue(),typeof this._inputEl.render==`function`&&this._inputEl.render())}_emitChangeFromPicker(){let e=this._getOutputValue();this._invalidFromInput=!1,this.setAttribute(`value`,e),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_parseSingle(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?\s*(am|pm)$/i);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0),s=e[4].toUpperCase();return t<1||t>12||n&&(a<0||a>59)||r&&(o<0||o>59)?null:{hour:t,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseSingleOutput24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0);if(t<0||t>23||n&&(a<0||a>59)||r&&(o<0||o>59))return null;let s=t>=12?`PM`:`AM`;return{hour:t%12==0?12:t%12,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseAndApplyValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingleOutput24(t||``),i=this._parseSingleOutput24(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingleOutput24(e);return t?(this._single=t,!0):!1}_parseAndApplyDisplayValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingle(t||``),i=this._parseSingle(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingle(e);return t?(this._single=t,!0):!1}_handleTypedValue(e){let t=e.trim();if(!t){this._invalidFromInput=!1,this.removeAttribute(`value`),this._syncHiddenInput(),this._syncInputValue();return}if(!this._parseAndApplyDisplayValue(t)){this._invalidFromInput=!0,this.removeAttribute(`value`),this._inputEl&&(this._inputEl.value=``),this._syncHiddenInput(),this.render(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}));return}this._invalidFromInput=!1;let n=this._getOutputValue();this.setAttribute(`value`,n),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_buildColumn(e,t,n,r=!0,i=`py-28`){let a=document.createElement(`div`);return a.className=`h-[15rem] overflow-y-auto ${i} ${r?`border-r border-gray-300 dark:border-mint-divider`:``}`,e.forEach(e=>{let r=document.createElement(`button`);r.type=`button`;let i=e===t;r.className=`block w-full py-2 text-center text-base leading-none ${i?`font-semibold text-brand-500 dark:text-white`:`font-normal text-gray-500 dark:text-gray-400`}`,r.dataset.selected=i?`true`:`false`,r.textContent=e,r.addEventListener(`click`,()=>n(e)),a.appendChild(r)}),a}_centerSelectedInColumn(e,t=0){let n=e.querySelector(`button[data-selected="true"]`);if(!n)return;let r=n.offsetTop-(e.clientHeight/2-n.clientHeight/2)-t;e.scrollTop=Math.max(0,r)}_centerAllColumnsInPopoverBody(){if(!this._popover)return;let e=this._popover.querySelector(`[data-mint-time-picker-body="true"]`);if(!e)return;let t=Array.from(e.querySelectorAll(`.h-\\[15rem\\]`)),n=this.isRange()?20:0;t.forEach(e=>this._centerSelectedInColumn(e,n))}_setupPopoverOpenObserver(){this._popover&&(this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._popoverObserver=new MutationObserver(()=>{this._popover?.getAttribute(`open`)===`true`&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:[`open`]}))}_buildPickerSet(e,t,n){let r=this.isHoursEnabled(),i=this.isMinutesEnabled(),a=this.isSecondsEnabled(),o=document.createElement(`div`),s=(r?1:0)+(i?1:0)+(a?1:0)+(r?1:0);o.className=`grid bg-white dark:bg-mint-elevated overflow-hidden`,o.style.gridTemplateColumns=`repeat(${Math.max(s,1)}, minmax(0, 1fr))`;let c=Array.from({length:12},(e,t)=>(t+1).toString().padStart(2,`0`)),l=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),u=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),d=[`AM`,`PM`],f=[];r&&f.push(this._buildColumn(c,t.hour.toString().padStart(2,`0`),e=>{n({...t,hour:Number(e)})},!0,`py-32`)),i&&f.push(this._buildColumn(l,t.minute.toString().padStart(2,`0`),e=>{n({...t,minute:Number(e)})},!0,`py-32`)),a&&f.push(this._buildColumn(u,t.second.toString().padStart(2,`0`),e=>{n({...t,second:Number(e)})},!0,`py-32`)),r&&f.push(this._buildColumn(d,t.meridiem,e=>{n({...t,meridiem:e})},!0,`py-20`)),f.forEach((e,t)=>{t===f.length-1&&e.classList.remove(`border-r`),o.appendChild(e)}),e.appendChild(o)}_buildPopoverContent(e){if(e.innerHTML=``,!this.isRange()){this._buildPickerSet(e,this._single,t=>{this._single=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)});return}let t=document.createElement(`div`);t.className=`flex flex-col gap-3 min-[640px]:grid min-[640px]:grid-cols-2`;let n=document.createElement(`div`),r=document.createElement(`mint-text`);r.setAttribute(`variant`,`muted`),r.className=`mb-2 text-xs uppercase`,r.textContent=`Start`,n.appendChild(r),this._buildPickerSet(n,this._rangeStart,t=>{this._rangeStart=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)});let i=document.createElement(`div`),a=document.createElement(`mint-text`);a.setAttribute(`variant`,`muted`),a.className=`mb-2 text-xs uppercase`,a.textContent=`End`,i.appendChild(a),this._buildPickerSet(i,this._rangeEnd,t=>{this._rangeEnd=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)}),t.appendChild(n),t.appendChild(i),e.appendChild(t),requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})}_syncInputIconDarkModeTone(){if(!this._inputEl)return;let e=this._inputEl.querySelector(`mint-icon`);e&&(e.classList.remove(`dark:text-gray-500`),e.classList.add(`dark:text-white`))}render(){let e=this.isDisabled(),t=this.isReadonly(),n=this._getEffectiveError();this.innerHTML=``;let r=document.createElement(`div`);r.className=`w-full`,this._inputEl=document.createElement(`mint-input`),this._inputEl.id=this._triggerId,this._inputEl.classList.add(`w-full`),this._inputEl.setAttribute(`type`,`text`),this._inputEl.setAttribute(`icon`,`clock`),this._inputEl.setAttribute(`placeholder`,this._getExpectedFormat()),this._inputEl.setAttribute(`label`,this.getLabel()),this._inputEl.setAttribute(`info`,this.getInfo()),this._inputEl.setAttribute(`value`,this._getDisplayValue()),this._inputEl.setAttribute(`error`,n.hasError?`true`:`false`),this._inputEl.setAttribute(`error-message`,n.message||``),e&&this._inputEl.setAttribute(`disabled`,`true`),t&&this._inputEl.setAttribute(`readonly`,`true`),this._inputEl.addEventListener(`change`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())}),this._inputEl.addEventListener(`blur`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())},!0),r.appendChild(this._inputEl),this._syncInputIconDarkModeTone(),this._hiddenInput=document.createElement(`input`),this._hiddenInput.type=`hidden`,this._hiddenInput.name=this.getName(),this._hiddenInput.required=this.isRequired(),r.appendChild(this._hiddenInput),this._syncHiddenInput(),this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`trigger-id`,this._triggerId),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`),this._popover.setAttribute(`distance`,`6px`),(e||t)&&this._popover.setAttribute(`open`,`false`);let i=document.createElement(`div`);i.setAttribute(`data-mint-time-picker-body`,`true`),i.className=`min-w-[18rem] max-w-[56rem] p-3 bg-white dark:bg-mint-elevated`,this._buildPopoverContent(i),this._popover.appendChild(i),r.appendChild(this._popover),this._setupPopoverOpenObserver(),this.appendChild(r)}};customElements.get(`mint-time-picker`)||customElements.define(`mint-time-picker`,w);var T=class extends HTMLElement{static get observedAttributes(){return[`name`,`value`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`multiple`,`loading`]}constructor(){super(),this._select=null,this._wrapper=null,this._caretUpIcon=null,this._caretDownIcon=null,this._changeHandler=null,this._optionObserver=null,this._childrenObserver=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`inline-block`,`w-full`),this.getLabel()||console.error(`mint-select: The "label" attribute is required. Please provide a label for the select.`),this.render(),this._childrenObserver&&this._childrenObserver.disconnect(),this._childrenObserver=new MutationObserver(e=>{e.some(e=>{let t=Array.from(e.addedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`))||Array.from(e.removedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)),n=e.type===`attributes`&&e.target.nodeType===Node.ELEMENT_NODE&&(e.target.tagName===`OPTION`||e.target.tagName===`OPTGROUP`);return t||n})&&requestAnimationFrame(()=>{this.render()})}),this._childrenObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`selected`,`disabled`]})}disconnectedCallback(){this._select&&this._changeHandler&&(this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=null),this._optionObserver&&=(this._optionObserver.disconnect(),null),this._childrenObserver&&=(this._childrenObserver.disconnect(),null)}isLoading(){return this.getAttribute(`loading`)===`true`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`));return}if(e===`loading`){this.render();return}if(e===`value`){if(this._select)if(this.isMultiple()){let e=[];try{let t=n?JSON.parse(n):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=n?[String(n)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=n||``;return}this.render()}}getName(){return this.getAttribute(`name`)||``}getValue(){if(this.isMultiple()&&this._select){let e=Array.from(this._select.selectedOptions).map(e=>e.value);return JSON.stringify(e)}return this.hasAttribute(`value`)?this.getAttribute(`value`)||``:this._select?this._select.value:``}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(e=>String(e)):e==null||e===``?[]:[String(e)];this.setAttribute(`value`,JSON.stringify(t)),this._select&&Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)});return}let t=e==null?``:String(e);this.setAttribute(`value`,t),this._select&&(this._select.value=t)}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{if(this.isMultiple()){this.setValue(e);return}let t=e||``;(this.getAttribute(`value`)||``)!==t&&this.setAttribute(`value`,t),this._select&&requestAnimationFrame(()=>{this._select&&(t===``||Array.from(this._select.options).some(e=>e.value===t))&&this._select.value!==t&&(this._select.value=t)})}catch{}}isDisabled(){return this.getAttribute(`disabled`)===`true`}isMultiple(){return this.getAttribute(`multiple`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getSelectClasses(){let e=this.hasError(),t=this.isMultiple(),n=[`w-full`,`px-3.5`,t?`pr-3.5`:`pr-10`,t?`py-2`:`py-1.5`,t?`min-h-[6rem]`:`min-h-[2rem]`,`text-sm`,`font-medium`,`rounded-lg`,`box-border`,`bg-white`,`dark:bg-mint-elevated`,`text-gray-900`,`dark:text-white`,`outline-none`,`focus:outline-none`,`disabled:opacity-40`,`disabled:cursor-not-allowed`,`appearance-none`,`bg-no-repeat`,`bg-right`,`cursor-pointer`],r=[`border-2`,e?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`],i=[`focus-visible:ring-2`,`focus-visible:ring-offset-1`,e?`focus-visible:ring-red-400 dark:focus-visible:ring-red-500`:`focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`];return[...n,...r,...i].filter(Boolean).join(` `)}render(){let e=this.isLoading(),t=[];this._select&&Array.from(this._select.children).forEach(e=>{(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)&&t.push(e.cloneNode(!0))});let n=Array.from(this.children).filter(e=>e.tagName===`OPTION`||e.tagName===`OPTGROUP`).map(e=>e.cloneNode(!0));for(;this.firstChild;)this.removeChild(this.firstChild);this._wrapper=null,this._select=null;let r=this.getLabel(),i=this.getInfo(),a=this.getId(),o=this.getName(),s=this.getValue(),c=this.isDisabled(),l=this.isMultiple(),u=this.hasError();if(r){let e=document.createElement(`label`);e.className=`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,a&&e.setAttribute(`for`,a);let t=document.createTextNode(r);e.appendChild(t),this.appendChild(e)}this._wrapper=document.createElement(`div`),this._wrapper.className=`relative w-full`,this.appendChild(this._wrapper),this._select=document.createElement(`select`),this._select.className=this.getSelectClasses(),a&&(this._select.id=a),o&&(this._select.name=o),c&&(this._select.disabled=!0),l&&(this._select.multiple=!0),this._select.setAttribute(`aria-invalid`,u?`true`:`false`);let d=n.length>0?n:t;if(d.length>0&&d.forEach(e=>{this._select.appendChild(e)}),this._select.options.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`Select an option`,e.disabled=!0,e.selected=!0,this._select.appendChild(e)}if(l){let e=[];try{let t=s?JSON.parse(s):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=s?[String(s)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=s||``;if(this._changeHandler&&this._select&&this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=e=>{let t=e.target,n=l?Array.from(t.selectedOptions).map(e=>e.value):t.value,r=l?JSON.stringify(n):String(n||``);(this.getAttribute(`value`)||``)!==r&&(r?this.setAttribute(`value`,r):this.removeAttribute(`value`));let i=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(i),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:n},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:n},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener(`change`,this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{let e=this.getAttribute(`value`)||this.value||``;this._select&&e&&requestAnimationFrame(()=>{if(this._select)if(l){let t=[];try{let n=JSON.parse(e);t=Array.isArray(n)?n.map(e=>String(e)):[]}catch{t=[String(e)]}Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)})}else Array.from(this._select.options).some(t=>t.value===e)&&this._select.value!==e&&(this._select.value=e)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),l)this._caretUpIcon=null,this._caretDownIcon=null;else{let e=document.createElement(`div`);e.className=`absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none z-10 flex flex-col`,this._caretUpIcon=document.createElement(`mint-icon`),this._caretUpIcon.setAttribute(`name`,`caret-up`),this._caretUpIcon.className=`w-[.9em] h-[.9em] text-gray-400 dark:text-gray-500 mb-[-.2rem]`,e.appendChild(this._caretUpIcon),this._caretDownIcon=document.createElement(`mint-icon`),this._caretDownIcon.setAttribute(`name`,`caret-down`),this._caretDownIcon.className=`w-[.9em] h-[.9em] text-gray-400 dark:text-gray-500 mt-[-.2rem]`,e.appendChild(this._caretDownIcon),this._wrapper.appendChild(e)}if(i){let e=document.createElement(`div`);e.className=`mt-1 text-xs text-gray-500 dark:text-gray-400`,e.textContent=i,this.appendChild(e)}this._renderErrorState(),this._renderSkeleton(e)}_renderSkeleton(e){let t=this.querySelector(`.mint-select-skeleton-container`),n=this._wrapper;if(e){t||(t=document.createElement(`div`),t.className=`mint-select-skeleton-container absolute inset-0 z-10 pointer-events-none`,n?(n.classList.contains(`relative`)||n.classList.add(`relative`),n.appendChild(t)):(this.style.position=`relative`,this.appendChild(t)));let e=t.querySelector(`.mint-select-skeleton`);if(!e){e=document.createElement(`div`),e.className=`mint-select-skeleton w-full rounded-lg bg-gray-200 dark:bg-mint-hover animate-pulse`;let n=this.isMultiple();e.style.height=n?`6rem`:`2.25rem`,t.appendChild(e)}t.style.display=`block`,this._select&&(this._select.style.opacity=`0`,this._select.style.pointerEvents=`none`)}else t&&(t.style.display=`none`),this._select&&(this._select.style.opacity=`1`,this._select.style.pointerEvents=`auto`)}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-select-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-select-error mt-1 text-xs text-red-600 dark:text-red-400`,this.appendChild(n)),n.textContent=t):n&&n.remove()}};customElements.get(`mint-select`)||customElements.define(`mint-select`,T);var E=class extends HTMLElement{static get observedAttributes(){return[`label`,`accept`,`multiple`,`width`,`height`,`disabled`,`name`,`error`,`error-message`,`loading`]}constructor(){super(),this._dropzone=null,this._fileInput=null,this._previewContainer=null,this._isDragging=!1,this._wasDragging=!1,this._isUpdatingFiles=!1,this._listenersInitialized=!1,this._selectedFiles=[],this._previewUrls=[],this._resetHandler=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`inline-block`),this.render(),this._attachFormResetListener()}disconnectedCallback(){if(this.removeEventListeners(),this._cleanupPreviewUrls(),this._resetHandler){let e=this.closest(`form`);e&&e.removeEventListener(`reset`,this._resetHandler),this._resetHandler=null}}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._updateDragStateClass(),this._renderErrorState(this.hasError(),this.getErrorMessage());return}if(e===`loading`){this.render();return}this.render()}}getLabel(){return this.getAttribute(`label`)||``}getAccept(){return this.getAttribute(`accept`)||``}isMultiple(){return this.getAttribute(`multiple`)===`true`}getWidth(){return this.getAttribute(`width`)||`200px`}getHeight(){return this.getAttribute(`height`)||`200px`}_renderSkeleton(e){let t=this.querySelector(`.mint-dropzone-skeleton-container`),n=this._dropzone;if(e){t||(t=document.createElement(`div`),t.className=`mint-dropzone-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center justify-center`,n?(n.classList.contains(`relative`)||n.classList.add(`relative`),n.appendChild(t)):(this.style.position=`relative`,this.appendChild(t)));let e=t.querySelector(`.mint-dropzone-skeleton`);if(e||(e=document.createElement(`div`),e.className=`mint-dropzone-skeleton rounded-lg border-2 border-dashed border-gray-300 dark:border-mint-divider bg-gray-200 dark:bg-mint-hover animate-pulse`,e.style.width=`100%`,e.style.height=`100%`,t.appendChild(e)),t.style.display=`flex`,n){let e=n.querySelector(`.mint-dropzone-icon`),t=n.querySelector(`.mint-dropzone-label`),r=n.querySelector(`.mint-dropzone-previews-wrapper`),i=this._fileInput;if(e){let t=e;t.style.visibility=`hidden`,t.style.pointerEvents=`none`}if(t){let e=t;e.style.visibility=`hidden`,e.style.pointerEvents=`none`}if(r){let e=r;e.style.visibility=`hidden`,e.style.pointerEvents=`none`}i&&(i.style.visibility=`hidden`,i.style.pointerEvents=`none`),n.style.pointerEvents=`none`}}else if(t&&(t.style.display=`none`),n){let e=n.querySelector(`.mint-dropzone-icon`),t=n.querySelector(`.mint-dropzone-label`),r=n.querySelector(`.mint-dropzone-previews-wrapper`),i=this._fileInput;if(e){let t=e;t.style.visibility=`visible`,t.style.pointerEvents=`auto`}if(t){let e=t;e.style.visibility=`visible`,e.style.pointerEvents=`auto`}if(r){let e=r;e.style.visibility=`visible`,e.style.pointerEvents=`auto`}i&&(i.style.visibility=`visible`,i.style.pointerEvents=`auto`),n.style.pointerEvents=`auto`}}getName(){return this.getAttribute(`name`)||``}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}isDisabled(){return this.getAttribute(`disabled`)===`true`}isLoading(){return this.getAttribute(`loading`)===`true`}render(){let e=this.isLoading(),t=this.getLabel(),n=this.getAccept(),r=this.isMultiple(),i=this.isDisabled(),a=this.getWidth(),o=this.getHeight(),s=this.getName(),c=this.hasError(),l=this.getErrorMessage();this._dropzone||(this._dropzone=document.createElement(`div`),this.appendChild(this._dropzone)),this._updateDragStateClass(),this._dropzone.setAttribute(`aria-invalid`,c?`true`:`false`),i?(this._dropzone.setAttribute(`tabindex`,`-1`),this._dropzone.removeAttribute(`role`)):(this._dropzone.setAttribute(`tabindex`,`0`),this._dropzone.setAttribute(`role`,`button`),this._dropzone.setAttribute(`aria-label`,t||`File upload dropzone`)),this._dropzone.style.width=a,this._dropzone.style.height=o,this._dropzone.style.minWidth=a,this._dropzone.style.minHeight=o,this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.style.display=`none`,this._fileInput.setAttribute(`tabindex`,`-1`),this._fileInput.setAttribute(`aria-hidden`,`true`),this._dropzone.appendChild(this._fileInput)),this._fileInput.accept=n,this._fileInput.multiple=r,this._fileInput.disabled=i,s?this._fileInput.name=s:this._fileInput.removeAttribute(`name`),this._fileInput.setAttribute(`aria-invalid`,c?`true`:`false`);let u=this._dropzone.querySelector(`.mint-dropzone-icon`),d=this._dropzone.querySelector(`.mint-dropzone-label`);u&&u.remove(),d&&d.remove();let f=document.createElement(`div`);f.className=`mint-dropzone-icon flex items-center justify-center mt-2 mb-2 flex-shrink-0`;let p=document.createElement(`mint-icon`);if(p.setAttribute(`name`,`upload`),p.className=`w-12 h-12 text-gray-400 dark:text-gray-500`,f.appendChild(p),this._dropzone.appendChild(f),t){let e=document.createElement(`div`);e.className=`mint-dropzone-label text-sm font-medium text-gray-600 dark:text-gray-400 text-center px-4 flex-shrink-0`,e.textContent=t,this._dropzone.appendChild(e)}this.setupEventListeners(),this._renderErrorState(c,l),this._renderPreviews(),this._renderSkeleton(e)}_updateDragState(){this._dropzone&&this._updateDragStateClass()}_renderErrorState(e,t){let n=this.querySelector(`.mint-dropzone-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-dropzone-error mt-1 text-xs text-red-600 dark:text-red-400`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_updateDragStateClass(){if(!this._dropzone)return;let e=this.isDisabled(),t=this.hasError(),n=`relative border-2 border-dashed rounded-lg flex flex-col items-center ${this._selectedFiles.length>0?`justify-start`:`justify-center`} cursor-pointer overflow-hidden`,r=this._isDragging?`border-gray-400 dark:border-gray-500 bg-gray-50 dark:bg-mint-elevated dark:border-mint-divider`:`border-gray-300 dark:border-mint-divider bg-white dark:bg-mint-elevated dark:border-mint-divider hover:border-gray-400 dark:hover:border-mint-divider`,i=t?`border-red-300 dark:border-red-300 bg-red-50/50 dark:bg-red-900/30`:``,a=e?`opacity-40 cursor-not-allowed`:``;this._dropzone.className=`${n} ${t?i:r} ${a} focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`.trim()}setupEventListeners(){this._listenersInitialized||(this._listenersInitialized=!0,this.removeEventListeners(),!(!this._dropzone||!this._fileInput||this.isDisabled())&&(this._onDropzoneClick||=e=>{if(!(this.isDisabled()||!this._fileInput)&&e.target!==this._fileInput&&(e.stopPropagation(),e.preventDefault(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onDragOver||=e=>{e.preventDefault(),e.stopPropagation(),this.isDisabled()||this._isDragging||(this._isDragging=!0,this._wasDragging=!0,this._updateDragState())},this._onDragLeave||=e=>{e.preventDefault(),e.stopPropagation();let t=this._dropzone?.getBoundingClientRect();t&&(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState())},this._onDrop||=e=>{if(e.preventDefault(),e.stopPropagation(),this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState()),this.isDisabled())return;let t=e.dataTransfer?.files;t&&t.length>0&&this._handleFiles(t)},this._onFileInputInput||=e=>{e.stopImmediatePropagation(),e.stopPropagation()},this._onKeyDown||=e=>{if(!(this.isDisabled()||!this._fileInput)&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onFocus||=e=>{this._dropzone&&!this.isDisabled()&&this._dropzone.classList.add(`focus-visible:ring-2`)},this._onBlur||=e=>{this._dropzone},this._onFileInputChange||=e=>{if(e.stopImmediatePropagation(),e.stopPropagation(),this._isUpdatingFiles)return;let t=e.target.files;if(t&&t.length>0){let e=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<t.length;n++){let a=t[n];this._isFileAccepted(a,e)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}},this._dropzone.addEventListener(`click`,this._onDropzoneClick),this._dropzone.addEventListener(`dragover`,this._onDragOver),this._dropzone.addEventListener(`dragleave`,this._onDragLeave),this._dropzone.addEventListener(`drop`,this._onDrop),this._dropzone.addEventListener(`keydown`,this._onKeyDown),this._dropzone.addEventListener(`focus`,this._onFocus),this._dropzone.addEventListener(`blur`,this._onBlur),this._fileInput.addEventListener(`change`,this._onFileInputChange),this._fileInput.addEventListener(`input`,this._onFileInputInput,!0)))}removeEventListeners(){this._dropzone&&(this._onDropzoneClick&&this._dropzone.removeEventListener(`click`,this._onDropzoneClick),this._onDragOver&&this._dropzone.removeEventListener(`dragover`,this._onDragOver),this._onDragLeave&&this._dropzone.removeEventListener(`dragleave`,this._onDragLeave),this._onDrop&&this._dropzone.removeEventListener(`drop`,this._onDrop),this._onKeyDown&&this._dropzone.removeEventListener(`keydown`,this._onKeyDown),this._onFocus&&this._dropzone.removeEventListener(`focus`,this._onFocus),this._onBlur&&this._dropzone.removeEventListener(`blur`,this._onBlur)),this._fileInput&&(this._onFileInputChange&&this._fileInput.removeEventListener(`change`,this._onFileInputChange),this._onFileInputInput&&this._fileInput.removeEventListener(`input`,this._onFileInputInput,!0)),this._isDragging=!1,this._listenersInitialized=!1}_handleFiles(e){let t=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<e.length;n++){let a=e[n];this._isFileAccepted(a,t)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}_isFileAccepted(e,t){if(!t)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase());for(let t of n)if(t.startsWith(`.`)){if(`.`+e.name.split(`.`).pop()?.toLowerCase()===t)return!0}else if(t.includes(`/*`)){if(t.split(`/`)[0]===e.type.split(`/`)[0])return!0}else if(e.type===t)return!0;return!1}_dispatchEvent(e,t){let n=t.target,r=new CustomEvent(e,{detail:{files:n.files?Array.from(n.files):[],value:n.value||``},bubbles:!0,cancelable:!0});this.dispatchEvent(r)}_dispatchSelectionEvents(){let e={files:[...this._selectedFiles],value:``};this.dispatchEvent(new CustomEvent(`input`,{detail:e,bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:e,bubbles:!0,cancelable:!0,composed:!0}))}_syncFileInputFromSelected(){if(!this._fileInput)return;let e=new DataTransfer;this._selectedFiles.forEach(t=>{try{e.items.add(t)}catch(e){console.warn(`Failed to add file to DataTransfer:`,e)}}),this._isUpdatingFiles=!0;try{this._fileInput.files=e.files}catch(e){console.warn(`Failed to set files on input:`,e)}setTimeout(()=>{this._isUpdatingFiles=!1},0)}get files(){return this._syncFileInputFromSelected(),this._fileInput?.files||null}syncFiles(){this._syncFileInputFromSelected()}_renderPreviews(){if(!this._dropzone)return;if(this._previewContainer&&(this._cleanupPreviewUrls(),this._previewContainer.remove()),this._selectedFiles.length===0){this._previewContainer=null,this._updateDragStateClass();return}let e=document.createElement(`div`);e.className=`mint-dropzone-previews-wrapper mt-3 w-full relative max-h-48`;let t=document.createElement(`div`);t.className=`mint-dropzone-previews w-full flex flex-col gap-2 max-h-48 overflow-y-auto overflow-x-hidden px-2 pb-2`,this._selectedFiles.forEach((e,n)=>{let r=document.createElement(`div`);if(r.className=`flex items-center gap-3 p-2 rounded border border-gray-200 dark:border-mint-divider bg-gray-50 dark:bg-mint-elevated`,e.type.startsWith(`image/`)){let t=document.createElement(`img`);t.className=`w-12 h-12 object-cover rounded border border-gray-200 dark:border-mint-divider`;let n=URL.createObjectURL(e);this._previewUrls.push(n),t.src=n,r.appendChild(t)}else{let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`attach`),e.className=`w-5 h-5 text-gray-500 dark:text-gray-300`,r.appendChild(e)}let i=document.createElement(`div`);i.className=`flex-1 text-sm text-gray-800 dark:text-gray-100 truncate`,i.textContent=e.name,r.appendChild(i);let a=document.createElement(`button`);a.type=`button`,a.className=`text-gray-500 hover:bg-red-100 dark:hover:bg-red-900/30 flex items-center justify-center w-6 h-6 rounded-full`;let o=document.createElement(`mint-icon`);o.setAttribute(`name`,`close`),o.className=`w-4 h-4`,a.appendChild(o),a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this._removeFileAt(n)}),r.appendChild(a),t.appendChild(r)});let n=this.hasError(),r=this._isDragging,i=`from-white dark:from-mint-elevated`;n?i=`from-red-50 dark:from-red-900/30`:r&&(i=`from-gray-50 dark:from-mint-elevated`);let a=document.createElement(`div`);a.className=`absolute top-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-b ${i} to-transparent opacity-0`,e.appendChild(a);let o=document.createElement(`div`);o.className=`absolute bottom-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-t ${i} to-transparent opacity-100`,e.appendChild(o);let s=()=>{let e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;e>0?a.style.opacity=`1`:a.style.opacity=`0`,e+r<n-1?o.style.opacity=`1`:o.style.opacity=`0`};s(),t.addEventListener(`scroll`,s),e.appendChild(t),this._previewContainer=e,this._dropzone.appendChild(e),this._updateDragStateClass()}_removeFileAt(e){if(e<0||e>=this._selectedFiles.length)return;let[t]=this._selectedFiles.splice(e,1);t&&this._cleanupPreviewUrls(),this._syncFileInputFromSelected(),this._renderPreviews(),this._dispatchSelectionEvents()}_cleanupPreviewUrls(){this._previewUrls.forEach(e=>URL.revokeObjectURL(e)),this._previewUrls=[]}_attachFormResetListener(){let e=this.closest(`form`);!e||this._resetHandler||(this._resetHandler=()=>{this._selectedFiles=[],this._syncFileInputFromSelected(),this._renderPreviews(),this._cleanupPreviewUrls()},e.addEventListener(`reset`,this._resetHandler))}_applyValidFiles(e){if(this.isMultiple()){let t=e.filter(e=>!this._isDuplicateFile(e));this._selectedFiles.push(...t)}else this._selectedFiles=[e[0]];this._syncFileInputFromSelected(),this._selectedFiles.length>0&&(this.removeAttribute(`error`),this.removeAttribute(`error-message`),this._fileInput&&this._fileInput.removeAttribute(`aria-invalid`)),this._renderPreviews(),this._dispatchSelectionEvents()}_isDuplicateFile(e){return this._selectedFiles.some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)}};customElements.get(`mint-dropzone`)||customElements.define(`mint-dropzone`,E);var D=class extends HTMLElement{static get observedAttributes(){return[`action`,`method`,`enctype`,`data-form-data`,`loading`,`headers`,`submitting`]}constructor(){super(),this._form=null,this._submitHandler=null,this._hostSubmitHandler=null,this._errors={},this._fieldBlurHandlers=new Map,this._fieldChangeHandlers=new Map,this._observer=null,this._formData=null,this._headers=null,this._buttonStates=new Map,this._attrSubmittingMintFields=new Map,this._attrSubmittingNativeFields=new Map,this._attrSubmittingMintButtons=new Map,this._attrSubmittingNativeButtons=new Map,this._reactiveDataProxy=null,this._reactiveDataObserver=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}connectedCallback(){this._render(),this._ensureSubmitHandler(),this._setupBlurValidation();let e=this.getAttribute(`headers`);e&&this._parseHeaders(e),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(this._formData)this._isReactiveObject(this._formData)?this._setupReactiveDataObserver(this._formData):this._lastDataSnapshot||=this._createDataSnapshot(this._formData),this._applyFormData();else{let e=this.getAttribute(`data-form-data`);e&&(this._parseFormData(e),this._applyFormData())}this._propagateLoadingState(),this._applySubmittingAttributeState()})})}disconnectedCallback(){this._form&&this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._hostSubmitHandler&&this.removeEventListener(`submit`,this._hostSubmitHandler),this._restoreSubmittingAttributeState(),this._cleanupBlurValidation(),this._stopReactiveDataObserver()}reset(){this._clearErrors(),this._formData?this._applyFormData():this.clear()}clear(){this._clearErrors(),this._form&&this._form.reset(),this._resetCustomFields()}submit(){if(this._form){if(typeof this._form.requestSubmit==`function`){this._form.requestSubmit();return}this._handleSubmit(new Event(`submit`,{bubbles:!0,cancelable:!0}))}}attributeChangedCallback(e,t,n){e===`form-data`?(this._parseFormData(n),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})):e===`headers`?this._parseHeaders(n):e===`loading`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._propagateLoadingState()}):this._propagateLoadingState():e===`submitting`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._applySubmittingAttributeState()}):this._applySubmittingAttributeState():this._applyFormAttributes()}get data(){return this._formData}set data(e){this._stopReactiveDataObserver(),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null,e&&typeof e==`object`&&!Array.isArray(e)?(this._formData=e,this._isReactiveObject(e)?this._setupReactiveDataObserver(e):this._lastDataSnapshot=this._createDataSnapshot(e)):e==null?this._formData=null:this._parseFormData(e),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})})}get headers(){return this._headers}set headers(e){if(e&&typeof e==`object`&&!Array.isArray(e))this._headers=e;else if(e==null)this._headers=null;else if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_render(){if(this.classList.add(`block`,`w-full`),!this._form){for(this._form=document.createElement(`form`),this._form.noValidate=!0;this.firstChild;)this._form.appendChild(this.firstChild);this.appendChild(this._form)}this._ensureSubmitHandler(),this._applyFormAttributes()}_ensureSubmitHandler(){this._form&&(this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._submitHandler=e=>{e.preventDefault(),e.stopImmediatePropagation(),this._handleSubmit(e)},this._form.addEventListener(`submit`,this._submitHandler,!0))}_applyFormAttributes(){if(!this._form)return;let e=this.getAttribute(`action`)||``,t=this.getAttribute(`method`)||``,n=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;e&&(this._form.action=e),t&&(this._form.method=t),this._form.enctype=n}async _handleSubmit(e){if(e.preventDefault(),!this._form)return;this._clearErrors(),this._syncDropzoneFiles();let t=this._collectValidationRules(),n=new FormData(this._form),r=this._formDataToValues(n);if(this._formData){let e=this._getReactiveValue(this._formData);e&&typeof e==`object`&&!Array.isArray(e)&&(r={...this._extractReactiveData(e),...r})}if(!this._validate(r,t)){this.dispatchEvent(new CustomEvent(`invalid`,{detail:{errors:this._errors},bubbles:!0,cancelable:!0,composed:!0}));return}let i=new CustomEvent(`submit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(i),i.form=this;let a=new CustomEvent(`mintFormSubmit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});if(a.form=this,this.dispatchEvent(a),i.defaultPrevented||a.defaultPrevented)return;let o=this.getAttribute(`action`),s=this.getAttribute(`method`);if(!(!o||!s)){this._setButtonsSubmitting();try{let e=await this._submitData(n,r);this.dispatchEvent(new CustomEvent(`submitsuccess`,{detail:e,bubbles:!0,cancelable:!0}))}catch(e){e?.status===422&&e?.data?.errors&&this._applyServerErrors(e.data.errors),this.dispatchEvent(new CustomEvent(`submiterror`,{detail:{error:e},bubbles:!0,cancelable:!0}))}finally{this._restoreButtonsState()}}}async _submitData(e,t){let n=this.getAttribute(`action`),r=this.getAttribute(`method`),i=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;if(!n)return{status:0,ok:!0,data:{values:t}};let a=Array.from(e.values()).some(e=>e instanceof File),o=null,s={},c=n;if(typeof window<`u`&&window.mintForm?.defaults?.headers?.common&&Object.assign(s,window.mintForm.defaults.headers.common),this._headers&&Object.assign(s,this._headers),r===`GET`){let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),c+=(n.includes(`?`)?`&`:`?`)+t.toString()}else if(i===`multipart/form-data`||a)o=e;else if(i===`application/json`)o=JSON.stringify(t),s[`Content-Type`]=`application/json`;else{let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),o=t,s[`Content-Type`]=`application/x-www-form-urlencoded`}if(typeof fetch==`function`)try{let e=await fetch(c,{method:r||`POST`,body:r===`GET`?null:o,headers:s}),t=await e.text().catch(()=>``),n=t;try{n=JSON.parse(t)}catch{}if(!e.ok){let t={status:e.status,data:n,response:{status:e.status,data:n}};throw await this._applyErrorInterceptors(t)}let i={status:e.status,ok:e.ok,data:n};return await this._applySuccessInterceptors(i)}catch(e){if(e.response)throw e;let t={status:e.status||0,data:e.data||e.message||`Network error`,response:{status:e.status||0,data:e.data||e.message||`Network error`}};throw await this._applyErrorInterceptors(t)}let l=this;return await new Promise(async(e,t)=>{let n=new XMLHttpRequest;n.open(r||`POST`,c,!0),Object.entries(s).forEach(([e,t])=>n.setRequestHeader(e,t)),n.onload=async function(){let{status:r,responseText:i}=n;if(r>=200&&r<300){let n=i;try{n=JSON.parse(i)}catch{}try{let t={status:r,ok:!0,data:n};e(await l._applySuccessInterceptors(t))}catch(e){t(e)}}else{let e=i;try{e=JSON.parse(i)}catch{}try{let n={status:r,data:e,response:{status:r,data:e}};t(await l._applyErrorInterceptors(n))}catch(e){t(e)}}},n.onerror=async function(){try{let e={status:n.status||0,data:n.responseText||`Network error`,response:{status:n.status||0,data:n.responseText||`Network error`}};t(await l._applyErrorInterceptors(e))}catch(e){t(e)}},n.send(r===`GET`?null:o)})}async _applySuccessInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return e;let t=e,n=window.mintForm.interceptors.response.handlers;for(let e of n)e.fulfilled&&(t=await e.fulfilled(t));return t}async _applyErrorInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return Promise.reject(e);let t=e,n=window.mintForm.interceptors.response.handlers;for(let e=n.length-1;e>=0;e--){let r=n[e];if(r.rejected)try{if(t=await r.rejected(t),t!==void 0)return t}catch(e){t=e}}return Promise.reject(t)}_formDataToValues(e){let t={};return e.forEach((e,n)=>{e instanceof File?(t[n]||(t[n]=[]),t[n].push(e)):n in t?Array.isArray(t[n])?(t[n].length>0&&t[n][0]instanceof File,t[n].push(e)):t[n]=[t[n],e]:t[n]=e}),this._form&&(Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n&&e.files!==void 0&&e.files){let r=e.files;if(r.length>0){let e=Array.from(r);t[n]&&Array.isArray(t[n])?e.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=e}}}),Array.from(this._form.querySelectorAll(`input[type="file"][name]`)).forEach(e=>{let n=e.name;if(n&&e.files&&e.files.length>0){let r=Array.from(e.files);t[n]&&Array.isArray(t[n])?r.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=r}}),Array.from(this._form.querySelectorAll(`mint-tags[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n){let r=[];e.tags===void 0?typeof e.getTags==`function`&&(r=e.getTags()):r=e.tags,Array.isArray(r)&&r.length>0?t[n]=r.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):t[n]=[]}})),t}_collectValidationRules(){let e={};return this._form&&Array.from(this._form.querySelectorAll(`[name][validation]`)).forEach(t=>{let n=t.getAttribute(`name`)||``,r=t.getAttribute(`validation`);if(!n||!r)return;let i=this._parseRules(r);i.length&&(e[n]=i)}),e}_parseRules(e){if(!e)return[];try{let t=e.replace(/'/g,`"`),n=JSON.parse(t);if(Array.isArray(n))return n.map(e=>String(e))}catch{}return e.split(`,`).map(e=>e.trim()).filter(Boolean)}_validate(e,t){let n=!0;return this._errors={},Object.entries(t||{}).forEach(([e,t])=>{let r=Array.isArray(t)?t:[t],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(n=!1,this._errors[e]=o,this._flagFieldError(i,o)):this._clearFieldError(i)}),n}_validateField(e){let t=this._collectValidationRules();if(!t[e])return;let n=t[e],r=Array.isArray(n)?n:[n],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(this._errors[e]=o,this._flagFieldError(i,o)):(this._clearFieldError(i),delete this._errors[e])}_validateRules(e,t){for(let n of t){let[t,r]=n.split(`:`);switch(t){case`required`:if(e==null||typeof e==`string`&&e.trim()===``||e instanceof FileList&&e.length===0||Array.isArray(e)&&e.length===0)return`This field is required.`;break;case`string`:if(typeof e!=`string`)return`Must be a string.`;break;case`email`:if(typeof e==`string`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()))return`Enter a valid email.`;break;case`number`:{let t=Number(e);if(Number.isNaN(t))return`Must be a number.`;break}case`min`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length<t)return`Must be at least ${t} characters.`;if(Array.isArray(e)&&e.length<t)return`Select at least ${t}.`;if(e instanceof FileList&&e.length<t)return`Upload at least ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)<t)return`Must be at least ${t}.`;break}case`max`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length>t)return`Must be at most ${t} characters.`;if(Array.isArray(e)&&e.length>t)return`Select no more than ${t}.`;if(e instanceof FileList&&e.length>t)return`Upload no more than ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)>t)return`Must be at most ${t}.`;break}default:break}}return null}_getFieldElements(e){if(!this._form)return[];let t=Array.from(this._form.querySelectorAll(`[name="${e}"]`)),n=t.filter(e=>e.tagName===`MINT-SELECT`);if(n.length>0){let r=[];return n.forEach(t=>{let n=t.querySelector(`select[name="`+e+`"]`);n&&r.push(n)}),t.filter(e=>e.tagName!==`MINT-SELECT`).concat(r)}if(t.filter(e=>e.tagName===`MINT-TAGS`).length>0)return t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`));let r=t.filter(e=>e.tagName===`INPUT`&&e.closest(`mint-tags`));if(r.length>0){let e=[];return r.forEach(t=>{let n=t.closest(`mint-tags`);n&&!e.includes(n)&&e.push(n)}),t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`)).concat(e)}return t}_extractFieldValue(e){if(e.length===0)return``;let t=e.find(e=>e instanceof HTMLSelectElement);if(t)return t.multiple?Array.from(t.selectedOptions).map(e=>e.value):t.value;if(e.length>1){let t=e.filter(e=>e instanceof HTMLInputElement);if(t.length>0&&t.length===e.length){let e=t.filter(e=>e.checked);if(t.every(e=>e.type===`radio`))return e.length>0?e[0].value||`on`:``;if(t.every(e=>e.type===`checkbox`))return e.map(e=>e.value||`on`)}let n=e.filter(e=>e.tagName===`MINT-CHOICE`);if(n.length>0&&n.length===e.length){let e=n.find(e=>typeof e.getValue==`function`?e.getValue()!==``:e.querySelector(`mint-choice-option[checked]`)!==null);if(e){if(typeof e.getValue==`function`)return e.getValue();let t=e.querySelector(`mint-choice-option[checked]`);if(t)return t.getAttribute(`value`)||``}return``}let r=e.filter(e=>e.tagName===`MINT-CHECKBOX`);if(r.length>0&&r.length===e.length)return r.filter(e=>e.checked===void 0?e.hasAttribute(`checked`):e.checked).map(e=>e.getAttribute(`value`)||`on`)}let n=e[0];if(n instanceof HTMLInputElement)return n.type===`file`?n.files:n.type===`checkbox`||n.type===`radio`?n.checked?n.value||`on`:``:n.value;if(n instanceof HTMLTextAreaElement)return n.value;if(n.tagName===`MINT-SELECT`){let e=n.querySelector(`select`);if(e)return e.multiple?Array.from(e.selectedOptions).map(e=>e.value):e.value;if(typeof n.getValue==`function`){let e=n.getValue();if(e!=null&&e!==``)return e}return n.getAttribute(`value`)||``}if(n.tagName===`MINT-DROPZONE`&&n.files!==void 0)return n.files;if(n.tagName===`MINT-TAGS`){let e=null;return n.tags===void 0?typeof n.getTags==`function`&&(e=n.getTags()):e=n.tags,Array.isArray(e)?e.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):[]}return n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`?(n.checked===void 0?n.hasAttribute(`checked`):n.checked)?n.getAttribute(`value`)||`on`:``:n.tagName===`MINT-CHOICE`?(typeof n.getValue==`function`?n.getValue():``)||``:n.value===void 0?n.getAttribute(`value`)||``:n.value}_flagFieldError(e,t){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.setAttribute(`aria-invalid`,`true`);let n=this._resolveHost(e);n&&(n.setAttribute(`error`,`true`),n.setAttribute(`error-message`,t),n.setAttribute(`data-mint-form-error`,`true`))})}_clearFieldError(e){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.removeAttribute(`aria-invalid`);let t=this._resolveHost(e);t&&(t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`))})}_clearErrors(){this.querySelectorAll(`[data-mint-form-error]`).forEach(e=>{let t=e;t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`)}),this._form&&this._form.querySelectorAll(`[aria-invalid="true"]`).forEach(e=>{e.removeAttribute(`aria-invalid`)}),this._errors={}}setFormErrors(e){this._applyServerErrors(e)}_applyServerErrors(e){this._clearErrors(),Object.entries(e).forEach(([e,t])=>{let n=Array.isArray(t)?t[0]||`Validation error`:t||`Validation error`,r=this._getFieldElements(e);r.length>0&&(this._errors[e]=n,this._flagFieldError(r,n))})}_parseFormData(e){if(!e){this._formData=null;return}if(typeof e==`object`&&!Array.isArray(e)){this._formData=e;return}if(typeof e==`string`)try{this._formData=JSON.parse(e)}catch{this._formData=null}else this._formData=null}_parseHeaders(e){if(!e){this._headers=null;return}if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_applyFormData(){if(!this._formData||!this._form)return;let e=this._getReactiveValue(this._formData);if(!e||typeof e!=`object`||Array.isArray(e))return;let t=this._extractReactiveData(e),n=this._createDataSnapshot(t),r=this._lastAppliedDataSnapshot,i=new Set;if(r?(Object.keys(n).forEach(e=>{let t=r[e],a=n[e];JSON.stringify(t)!==JSON.stringify(a)&&i.add(e)}),Object.keys(r).forEach(e=>{e in n||i.add(e)})):Object.keys(n).forEach(e=>i.add(e)),i.size===0)return;let a=()=>{i.forEach(e=>{let t=n[e],r=this._getFieldElements(e);if(r.length===0){setTimeout(()=>{let t=this._getFieldElements(e);if(t.length===0)return;let n=this._formData?this._getReactiveValue(this._formData):null;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[e];this._applyValueToField(t,e,r)},300);return}this._applyValueToField(r,e,t)}),this._lastAppliedDataSnapshot=n};requestAnimationFrame(()=>{requestAnimationFrame(()=>{a()})})}_applyValueToField(e,t,n){e.forEach(e=>{let r=e.tagName;try{if(r===`MINT-INPUT`)e.value!==void 0&&(e.value=n||``);else if(r===`MINT-DATE-PICKER`)typeof e.setValue==`function`&&e.setValue(n||``);else if(r===`MINT-SELECT`||r===`SELECT`)if(r===`SELECT`){let t=e,r=t.closest(`mint-select`);if(r&&typeof r.setValue==`function`)r.setValue(n);else if(t.multiple){let e=Array.isArray(n)?n.map(e=>String(e)):n==null||n===``?[]:[String(n)];Array.from(t.options).forEach(t=>{t.selected=e.includes(t.value)})}else t.value=n==null?``:String(n)}else typeof e.setValue==`function`&&e.setValue(n);else if(r===`MINT-CHOICE`)typeof e.setValue==`function`?e.setValue(n==null?``:String(n)):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=e.getAttribute(`value`)===n});else if(r===`MINT-CHECKBOX`||r===`MINT-SWITCH`){let t=n===!0||n===`true`||n===`on`||n===1||n===`1`;e.checked===void 0?t?e.setAttribute(`checked`,`true`):e.removeAttribute(`checked`):e.checked=t}else if(r===`MINT-TAGS`)if(Array.isArray(n)){let t=new Map;try{let n=e.getAttribute(`predefined-tags`);if(n){let e=JSON.parse(n);Array.isArray(e)&&(t=new Map(e.map(e=>{if(typeof e==`string`){let t=e.trim();return t?[t.toLowerCase(),t]:null}if(!e||typeof e!=`object`)return null;let t=String(e.value??``).trim();if(!t)return null;let n=String(e.label??t);return[t.toLowerCase(),n]}).filter(e=>e!==null)))}}catch{}e.tags!==void 0&&(e.tags=n.map(e=>{if(typeof e==`string`){let n=e.trim();return{value:n,label:t.get(n.toLowerCase())||n,dismissable:!0}}if(e&&typeof e==`object`){let n=String(e.value??``).trim(),r=t.get(n.toLowerCase())||String(e.label??n);return{...e,value:n,label:r,dismissable:e.dismissable!==!1}}return e}))}else e.tags!==void 0&&(e.tags=[]);else if(e instanceof HTMLInputElement){if(e.type===`file`)return;e.type===`checkbox`||e.type===`radio`?e.checked=n===!0||n===`true`||n===`on`||n===1||n===`1`:e.value=n||``}else (e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(e.value=n||``)}catch(e){console.warn(`Failed to set value for field ${t}:`,e)}})}_resetCustomFields(){this.querySelectorAll(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{e.removeAttribute(`error`),e.removeAttribute(`error-message`);let t=e.tagName;if(t===`MINT-INPUT`)try{e.value=``}catch{}else if(t===`MINT-DATE-PICKER`)try{e.setValue?.(``)}catch{}else if(t===`MINT-SELECT`)try{e.setValue?.(``)}catch{}else if(t===`MINT-DROPZONE`){let t=e.querySelector(`input[type="file"]`);t&&(t.value=``)}else if(t===`MINT-CHECKBOX`||t===`MINT-SWITCH`)try{if(e.checked!==void 0)e.checked=!1;else{e.removeAttribute(`checked`);let t=e.querySelector(`input[type="checkbox"], input[type="radio"]`);t&&(t.checked=!1)}}catch{}else if(t===`MINT-CHOICE`)try{typeof e.setValue==`function`?e.setValue(``):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=!1})}catch{}else if(t===`MINT-TAGS`)try{e.tags=[]}catch{}})}_resolveHost(e){if(e.tagName===`MINT-CHOICE-OPTION`){let t=e.closest(`mint-choice`);if(t)return t}return e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)||e}_setupBlurValidation(){if(!this._form)return;let e=e=>{let t=e.target;if(!t)return;let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);if(!r||!this._collectValidationRules()[r])return;let i=this._extractFieldValue([n]),a=i!=null&&(typeof i==`string`?i.trim()!==``:i instanceof FileList||Array.isArray(i)?i.length>0:!0),o=n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&(t.hasAttribute(`aria-invalid`)||t.closest(`[data-mint-form-error]`)),s=!!n.closest(`mint-tags`),c=n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`||n.tagName===`MINT-CHOICE`||t instanceof HTMLElement&&(t.closest(`mint-checkbox, mint-switch, mint-choice`)||t.closest(`mint-choice-option`)),l=n.tagName===`MINT-DATE-PICKER`||t instanceof HTMLElement&&t.closest(`mint-date-picker`);(a||o||s||c||l)&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`blur`,e,!0),this._fieldBlurHandlers.set(this._form,e);let t=e=>{let t=e.target;if(!t)return;if(!(t instanceof HTMLInputElement&&t.type===`file`)){let e=this._findFieldElement(t),n=e?this._getFieldName(e):null;e&&n&&this._syncFieldToReactiveData(e,n)}if(e.type===`tags-change`&&t.tagName===`MINT-TAGS`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLSelectElement||t.tagName===`MINT-SELECT`||t.closest(`mint-select`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(e.type===`choice-change`&&t.tagName===`MINT-CHOICE`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLInputElement&&t.type===`checkbox`||t.tagName===`MINT-CHECKBOX`||t.tagName===`MINT-SWITCH`||t.closest(`mint-checkbox, mint-switch`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);r&&this._collectValidationRules()[r]&&(n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&t.hasAttribute(`aria-invalid`))&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`change`,t,!0),this._form.addEventListener(`input`,t,!0),this._form.addEventListener(`tags-change`,t,!0),this._form.addEventListener(`choice-change`,t,!0),this._fieldChangeHandlers.set(this._form,t)}_findFieldElement(e){let t=e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`);if(t&&t.hasAttribute(`name`))return t;if(e.hasAttribute(`name`)&&(e.tagName.startsWith(`MINT-`)||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)||(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.hasAttribute(`name`))return e;let n=e;for(;n&&n!==this._form;){if(n.hasAttribute(`name`))return n;n=n.parentElement}return null}_getFieldName(e){return e.hasAttribute(`name`)||e.tagName.startsWith(`MINT-`)?e.getAttribute(`name`):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.name||null}_syncFieldToReactiveData(e,t){if(!this._formData||!t)return;let n=this._getReactiveValue(this._formData);if(!n||typeof n!=`object`||Array.isArray(n))return;let r=this._getFieldElements(t),i=this._extractFieldValue(r.length?r:[e]);n[t]=this._normalizeReactiveValue(r,i),this._lastDataSnapshot=this._createDataSnapshot(n)}_normalizeReactiveValue(e,t){if(t instanceof FileList)return Array.from(t);if(Array.isArray(t))return t;let n=e[0];return e.length===1&&(n instanceof HTMLInputElement&&n.type===`checkbox`||n?.tagName===`MINT-CHECKBOX`||n?.tagName===`MINT-SWITCH`)?!!t:t??``}_cleanupBlurValidation(){if(this._form&&this._fieldBlurHandlers.has(this._form)){let e=this._fieldBlurHandlers.get(this._form);e&&this._form.removeEventListener(`blur`,e,!0),this._fieldBlurHandlers.delete(this._form)}if(this._form&&this._fieldChangeHandlers.has(this._form)){let e=this._fieldChangeHandlers.get(this._form);e&&(this._form.removeEventListener(`change`,e,!0),this._form.removeEventListener(`input`,e,!0),this._form.removeEventListener(`tags-change`,e,!0),this._form.removeEventListener(`choice-change`,e,!0)),this._fieldChangeHandlers.delete(this._form)}this._observer&&=(this._observer.disconnect(),null)}_syncDropzoneFiles(){this._form&&Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{typeof e.syncFiles==`function`&&e.syncFiles()})}_isSubmittingAttrActive(){let e=this.getAttribute(`submitting`);return e!==null&&e!==`false`}_applySubmittingAttributeState(){if(this._form){if(!this._isSubmittingAttrActive()){this._restoreSubmittingAttributeState();return}this._attrSubmittingMintFields.size>0||this._attrSubmittingNativeFields.size>0||this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0||(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`;this._attrSubmittingMintFields.set(e,t),t||e.setAttribute(`disabled`,`true`),typeof e.render==`function`&&e.render()}),this._form.querySelectorAll(`input, textarea, select`).forEach(e=>{if(e.closest(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags, mint-button`)||e instanceof HTMLInputElement&&e.type===`hidden`)return;let t=e.disabled;this._attrSubmittingNativeFields.set(e,t),t||(e.disabled=!0)}),Array.from(this.querySelectorAll(`mint-button`)).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._attrSubmittingMintButtons.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&!n&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),Array.from(this.querySelectorAll(`button`)).forEach(e=>{if(e.closest(`mint-button, mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`))return;let t=e.disabled;this._attrSubmittingNativeButtons.set(e,t),t||(e.disabled=!0)}))}}_restoreSubmittingAttributeState(){this._attrSubmittingMintFields.forEach((e,t)=>{e?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintFields.clear(),this._attrSubmittingNativeFields.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeFields.clear(),this._attrSubmittingMintButtons.forEach((e,t)=>{e.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),e.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintButtons.clear(),this._attrSubmittingNativeButtons.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeButtons.clear()}_propagateLoadingState(){if(!this._form)return;let e=this.getAttribute(`loading`),t=e!==null&&e!==`false`;Array.from(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)).forEach(e=>{t?e.setAttribute(`loading`,`true`):e.removeAttribute(`loading`),typeof e.render==`function`&&e.render()})}_setButtonsSubmitting(){if(!this._form)return;this._buttonStates.clear();let e=Array.from(this.querySelectorAll(`mint-button`)),t=Array.from(this.querySelectorAll(`button`));e.forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._buttonStates.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),t.forEach(e=>{if(e.closest(`mint-button`))return;let t=e.disabled;this._buttonStates.set(e,{disabled:t,loading:!1}),t||(e.disabled=!0)})}_restoreButtonsState(){if(!this._form)return;let e=this._isSubmittingAttrActive()&&(this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0),t=Array.from(this.querySelectorAll(`mint-button`)),n=Array.from(this.querySelectorAll(`button`));t.forEach(t=>{if(e&&this._attrSubmittingMintButtons.has(t))return;let n=this._buttonStates.get(t);n&&(n.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),n.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render())}),n.forEach(t=>{if(t.closest(`mint-button`)||e&&this._attrSubmittingNativeButtons.has(t))return;let n=this._buttonStates.get(t);n&&(t.disabled=n.disabled)}),this._buttonStates.clear()}_isReactiveObject(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;if(`__v_isRef`in e||`_value`in e||`__v_raw`in e||`__v_isReactive`in e||`__ob__`in e)return!0;try{let t=e.toString();if(t===`[object Object]`||t.includes(`Proxy`)){let t=Object.keys(e)[0];if(t){let n=Object.getOwnPropertyDescriptor(e,t);if(n&&(n.get||n.set))return!0}}}catch{return!0}return!0}_createDataSnapshot(e){try{let t=this._extractReactiveData(e);return JSON.parse(JSON.stringify(t))}catch{return{...this._extractReactiveData(e)}}}_extractReactiveData(e){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>this._extractReactiveData(e));let t=this._getReactiveValue(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=this._extractReactiveData(t[n]));return e}return t}_hasDataChanged(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch{return!0}}_getReactiveValue(e){if(!e||typeof e!=`object`)return e;if(`_value`in e||`__v_isRef`in e){if(e.value!==void 0)return e.value;if(`_value`in e)return e._value}return`__v_raw`in e||`__v_isReactive`in e||`__ob__`in e,e}_setupReactiveDataObserver(e){if(this._stopReactiveDataObserver(),!this.isConnected)return;let t=this._getReactiveValue(e);if(t&&typeof t==`object`&&!Array.isArray(t))this._lastDataSnapshot=this._createDataSnapshot(t);else{this._lastDataSnapshot=null;return}let n=()=>{if(!this._formData||!this._lastDataSnapshot){this._stopReactiveDataObserver();return}let e=this._getReactiveValue(this._formData);if(e&&typeof e==`object`&&!Array.isArray(e)){let t=this._createDataSnapshot(e);this._hasDataChanged(t,this._lastDataSnapshot)&&(this._lastDataSnapshot=t,requestAnimationFrame(()=>{this._applyFormData()}))}this.isConnected&&this._formData?this._reactiveDataObserver=requestAnimationFrame(n):this._stopReactiveDataObserver()};this._reactiveDataObserver=requestAnimationFrame(n)}_stopReactiveDataObserver(){this._reactiveDataObserver!==null&&(cancelAnimationFrame(this._reactiveDataObserver),this._reactiveDataObserver=null),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}};customElements.get(`mint-form`)||customElements.define(`mint-form`,D),typeof window<`u`&&(window.mintForm=window.mintForm||{defaults:{headers:{common:{}}},interceptors:{response:{handlers:[]}}},window.mintForm.interceptors.response.use||(window.mintForm.interceptors.response.use=function(e,t){return window.mintForm.interceptors.response.handlers.push({fulfilled:e,rejected:t}),window.mintForm.interceptors.response.handlers.length-1}));var O=class extends HTMLElement{constructor(...e){super(...e),this._observer=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`align-baseline`,`block`,`w-full`,`rounded-lg`,`border`,`border-gray-200`,`dark:border-mint-divider`),this.hasAttribute(`data-mint-rt-scroll-inner`)?this.classList.add(`min-w-0`,`overflow-x-visible`,`overflow-y-visible`):this.classList.add(`min-w-0`,`overflow-x-auto`),this._observeChanges(),this._applyStyles(),requestAnimationFrame(()=>{this._applyStyles(),setTimeout(()=>this._applyStyles(),0)})}disconnectedCallback(){this._observer&&=(this._observer.disconnect(),null)}_observeChanges(){this._observer=new MutationObserver(()=>this._applyStyles()),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!1})}_applyStyles(){this._observer&&this._observer.disconnect();let e=Array.from(this.querySelectorAll(`table`));if(e.length===0){this._observer&&this._observeChanges();return}let t=e.find(e=>e.querySelector(`thead`))??e[0],n=e.find(e=>e.querySelector(`tbody`))??e[0];e.forEach(e=>{let t=!!e.closest(`[id^="mint-rt-vscroll-"]`),n=!!e.closest(`mint-resource-table[data-mint-rt-fixed-header]`),r=t||n,i=[`w-full`,r?`border-separate border-spacing-0`:`border-collapse`,`text-sm`,`font-medium`,...r?[]:[`overflow-hidden`]];this._setClasses(e,i)});let r=t.querySelector(`thead`);if(r){r.classList.add(`bg-[#F7F7F7]`,`dark:bg-mint-nav`);let e=r.querySelectorAll(`th`);e.forEach((t,n)=>{let r=t.querySelector(`mint-icon`),i=r?.getAttribute(`name`)||``,a=t.hasAttribute(`data-mint-rt-sortable`)||r!==null&&i!==`ellipsis`;this._setClasses(t,[`text-left`,`font-semibold`,`text-gray-900`,`dark:text-white`,`px-3`,`py-2`,`border-b`,`border-gray-200`,`dark:border-mint-divider`,`bg-[#F7F7F7]`,`dark:bg-mint-nav`]),a&&t.classList.add(`cursor-pointer`,`hover:bg-gray-100`,`dark:hover:bg-mint-hover`),n===0&&t.classList.add(`pl-3`),n===e.length-1&&t.classList.add(`pr-3`);let o=t.closest(`table`),s=o?.closest(`mint-resource-table`),c=!!s?.hasAttribute(`data-mint-rt-fixed-header`),l=!!s?.hasAttribute(`data-mint-rt-fixed-controls`);if(o?.closest(`[id^="mint-rt-vscroll-"]`)||c){let e=c&&l?`top-[var(--mint-rt-fixed-controls-h,0px)]`:`top-0`;t.classList.add(`sticky`,e,`z-30`,`bg-[#F7F7F7]`,`dark:bg-mint-nav`,`shadow-sm`)}})}let i=n.querySelector(`tbody`);if(i){let e=Array.from(i.querySelectorAll(`tr`)),t=!!n.closest(`[id^="mint-rt-vscroll-"]`)||!!n.closest(`mint-resource-table`)?.hasAttribute(`data-mint-rt-fixed-header`),r=e.findIndex(e=>e.getAttribute(`data-mint-rt-spacer`)===`bottom`);e.forEach((n,i)=>{let a=n.hasAttribute(`data-mint-rt-spacer`),o=n.hasAttribute(`data-row-clickable`);a||t?this._setClasses(n,[`bg-white`,`dark:bg-mint-canvas`]):this._setClasses(n,[`bg-white`,`dark:bg-mint-canvas`,`border-b`,`border-gray-200`,`dark:border-mint-divider`]),o&&!a&&n.classList.add(`cursor-pointer`,`hover:bg-gray-50`,`dark:hover:bg-mint-elevated`),!t&&i===e.length-1&&n.classList.remove(`border-b`);let s=n.querySelectorAll(`td`);s.forEach((o,c)=>{let l=[`text-gray-900`,`dark:text-gray-100`,`px-3`,`py-2`];if(t&&!a){let t=n.hasAttribute(`data-mint-rt-last-row`),a=r===-1&&i===e.length-1;!t&&!a&&l.push(`border-b`,`border-gray-200`,`dark:border-mint-divider`)}this._setClasses(o,l),c===0&&o.classList.add(`pl-3`),c===s.length-1&&o.classList.add(`pr-3`),this._restoreCell(o)})})}let a=n.querySelector(`tfoot`);a&&(this._setClasses(a,[`bg-[#F7F7F7]`,`dark:bg-mint-nav`,`font-semibold`]),a.querySelectorAll(`td`).forEach(e=>{this._setClasses(e,[`text-gray-900`,`dark:text-gray-100`,`px-3`,`py-2`,`border-t`,`border-gray-200`,`dark:border-mint-divider`]),this._restoreCell(e)})),this._observer&&this._observeChanges()}_restoreCell(e){if(e.dataset.mtProcessed!==`true`)return;let t={};Array.from(e.attributes).forEach(e=>{e.name.startsWith(`data-`)&&e.name!==`data-original`&&e.name!==`data-mt-processed`&&(t[e.name]=e.value)});let n=e.getAttribute(`data-original`)||``;e.dataset.mtProcessed=``,e.innerHTML=n,Object.entries(t).forEach(([t,n])=>{e.setAttribute(t,n)})}_setClasses(e,t){e.className=``,t.filter(Boolean).forEach(t=>e.classList.add(...t.split(` `)))}};customElements.get(`mint-table`)||customElements.define(`mint-table`,O);var k=class extends HTMLElement{constructor(...e){super(...e),this._root=null,this._textWrap=null,this._dismissBtn=null,this._clickHandler=null}static get observedAttributes(){return[`dismissable`]}connectedCallback(){this._render()}disconnectedCallback(){this._dismissBtn&&this._clickHandler&&this._dismissBtn.removeEventListener(`click`,this._clickHandler)}attributeChangedCallback(){this._render()}_render(){if(this.classList.add(`inline-flex`,`items-center`,`gap-2`,`px-3`,`py-1`,`rounded-full`,`border`,`border-gray-200`,`dark:border-mint-divider`,`bg-gray-100`,`dark:bg-mint-elevated`,`text-gray-900`,`dark:text-gray-100`,`text-sm`,`font-medium`),!this._root){for(this._root=document.createElement(`div`),this._root.className=`flex items-center gap-2 w-full`,this._textWrap=document.createElement(`span`),this._textWrap.className=`inline-flex items-center min-w-[0.5rem]`,this._textWrap.setAttribute(`data-mt-chip-text`,``);this.firstChild;){let e=this.firstChild;if(e===this._root)break;this._textWrap.appendChild(e)}this._root.appendChild(this._textWrap),this.appendChild(this._root)}let e=this.getAttribute(`dismissable`);e===``||e===`true`||this.hasAttribute(`dismissable`)?(this._dismissBtn||this._createDismissBtn(),this._dismissBtn&&!this._dismissBtn.isConnected&&this._root?.appendChild(this._dismissBtn)):this._dismissBtn&&this._dismissBtn.parentElement===this._root&&this._dismissBtn.remove()}_createDismissBtn(){let e=document.createElement(`button`);e.type=`button`,e.setAttribute(`aria-label`,`Dismiss`),e.className=[`shrink-0`,`inline-flex`,`items-center`,`justify-center`,`w-5`,`h-5`,`rounded-full`,`text-gray-500`,`dark:text-gray-300`,`hover:text-gray-700`,`dark:hover:text-gray-100`,`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-offset-1`,`focus-visible:ring-gray-400`,`dark:focus-visible:ring-gray-500`,`border-none`,`bg-transparent`,`cursor-pointer`].join(` `);let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`close`),t.className=`w-3 h-3`,e.appendChild(t),this._clickHandler=e=>{e.stopPropagation(),this.dispatchEvent(new CustomEvent(`dismiss`,{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`dismissed`,{bubbles:!0,composed:!0})),this.remove()},e.addEventListener(`click`,this._clickHandler),this._dismissBtn=e}};customElements.get(`mint-chip`)||customElements.define(`mint-chip`,k);var A=class extends HTMLElement{constructor(...e){super(...e),this._container=null,this._chipsWrap=null,this._input=null,this._tags=[],this._predefinedTags=[],this._placeholder=`Add tag`,this._predefinedPopoverOpenListenersAttached=!1,this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose=!1,this._dragIndex=null,this._dragChip=null,this._isPointerDragging=!1,this._pointerMoveHandler=null,this._pointerUpHandler=null,this._containerFocusRingListeners=!1,this._predefinedFieldResizeObserver=null,this._predefinedPopoverBodyEl=null}static get observedAttributes(){return[`tags`,`placeholder`,`predefined-tags`,`predefined-only`,`sortable`,`label`,`info`,`error`,`error-message`,`name`,`id`,`required`,`loading`]}connectedCallback(){this._parseAttrs(),this._render(),this._pointerMoveHandler||(this._pointerMoveHandler=e=>this._onPointerMove(e),window.addEventListener(`pointermove`,this._pointerMoveHandler)),this._pointerUpHandler||(this._pointerUpHandler=e=>this._onPointerUp(e),window.addEventListener(`pointerup`,this._pointerUpHandler),window.addEventListener(`pointercancel`,this._pointerUpHandler))}disconnectedCallback(){this._disconnectPredefinedFieldResizeObserver()}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){if(this._renderErrorState(),this._container){let e=this.hasError(),t=[`flex`,`flex-wrap`,`items-center`,`gap-2`,`w-full`,`px-2`,`py-1.5`,`min-h-[2rem]`,`rounded-lg`,`border-2`,e?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`,`bg-white`,`dark:bg-mint-elevated`,...this._containerRingClasses(e)];this._container.className=t.join(` `)}return}if(e===`loading`){this._parseAttrs(),this._render();return}this._parseAttrs(),this._render()}}set tags(e){this._tags=Array.isArray(e)?[...e]:[],this._syncAttr(),this._render()}get tags(){return[...this._tags]}_parseAttrs(){let e=this.getAttribute(`tags`);e&&(this._tags=this._parseTagItems(e,`tags`));let t=this.getAttribute(`placeholder`);t!==null&&(this._placeholder=t);let n=this.getAttribute(`predefined-tags`);this._predefinedTags=this._parseTagItems(n,`predefined-tags`)}_parseTagItems(e,t){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{if(typeof e==`string`){let t=e.trim();return t?{value:t,label:t,dismissable:!0}:null}if(!e||typeof e!=`object`)return null;let t=e,n=String(t.value??``).trim();return n?{value:n,label:String(t.label??n),dismissable:t.dismissable!==!1}:null}).filter(e=>e!==null):[]}catch(e){return console.warn(`mint-tags: failed to parse ${t} attribute`,e),[]}}_syncAttr(){this.setAttribute(`tags`,JSON.stringify(this._tags))}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}hasError(){return this.getAttribute(`error`)===`true`}_containerRingClasses(e){return e?[`focus-within:ring-2`,`focus-within:ring-offset-1`,`focus-within:ring-red-400`,`dark:focus-within:ring-red-500`,`data-[mint-tags-active=true]:ring-2`,`data-[mint-tags-active=true]:ring-offset-1`,`data-[mint-tags-active=true]:ring-red-400`,`dark:data-[mint-tags-active=true]:ring-red-500`]:[`focus-within:ring-2`,`focus-within:ring-offset-1`,`focus-within:ring-gray-400`,`dark:focus-within:ring-gray-500`,`data-[mint-tags-active=true]:ring-2`,`data-[mint-tags-active=true]:ring-offset-1`,`data-[mint-tags-active=true]:ring-gray-400`,`dark:data-[mint-tags-active=true]:ring-gray-500`]}_attachContainerFocusRingListeners(){!this._container||this._containerFocusRingListeners||(this._containerFocusRingListeners=!0,this._container.addEventListener(`focusin`,()=>{this._container?.setAttribute(`data-mint-tags-active`,`true`)}),this._container.addEventListener(`focusout`,()=>{requestAnimationFrame(()=>{this._container&&(this._container.contains(document.activeElement)||this._container.removeAttribute(`data-mint-tags-active`))})}))}getErrorMessage(){return this.getAttribute(`error-message`)||``}getName(){return this.getAttribute(`name`)||``}getId(){return this.getAttribute(`id`)||``}isRequired(){return this.getAttribute(`required`)===`true`}isLoading(){return this.hasAttribute(`loading`)}isPredefinedOnly(){return this.getAttribute(`predefined-only`)===`true`}_render(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`);let e=this.isLoading(),t=this.getLabel(),n=this.getInfo(),r=this.hasError(),i=this.getId()||`mint-tags-${Math.random().toString(36).substr(2,9)}`;if(this.getId()||this.setAttribute(`id`,i),this._container)this._input&&(this._input.placeholder=this._placeholder);else{this._container=document.createElement(`div`);let e=[`flex`,`flex-wrap`,`items-center`,`gap-2`,`w-full`,`px-2`,`py-1`,`min-h-[2rem]`,`rounded-lg`,`border-2`,r?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`,`bg-white`,`dark:bg-mint-elevated`,...this._containerRingClasses(r)];this._container.className=e.join(` `),this._container.addEventListener(`pointerdown`,e=>this._onContainerPointerDown(e)),this._attachContainerFocusRingListeners(),this._chipsWrap=document.createElement(`div`),this._chipsWrap.className=`flex flex-wrap items-center gap-2`,this._chipsWrap.addEventListener(`dragover`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._chipsWrap.addEventListener(`drop`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._input=document.createElement(`input`),this._input.type=`text`,this._input.placeholder=this._placeholder,this._input.className=[`min-w-[6rem]`,`flex-1`,`bg-transparent`,`border-none`,`outline-none`,`text-sm`,`text-gray-900`,`dark:text-gray-100`,`placeholder:text-gray-400`,`dark:placeholder:text-gray-500`,`p-1.5`].join(` `),this._input.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this._addFromInput())}),this._container.appendChild(this._chipsWrap),this.appendChild(this._container)}if(this._input&&(this.isPredefinedOnly()&&this._predefinedTags.length>0?this._input.setAttribute(`readonly`,`true`):this._input.removeAttribute(`readonly`)),this._container){let e=[`flex`,`flex-wrap`,`items-center`,`gap-2`,`w-full`,`px-2`,`py-1`,`min-h-[2rem]`,`rounded-lg`,`border-2`,r?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`,`bg-white`,`dark:bg-mint-elevated`,...this._containerRingClasses(r)];this._container.className=e.join(` `)}let a=this.querySelector(`.mint-tags-label-container`);if(t){a||(a=document.createElement(`div`),a.className=`mint-tags-label-container mb-[.25rem]`,this._container&&this._container.parentElement===this?this.insertBefore(a,this._container):this.insertBefore(a,this.firstChild));let e=a.querySelector(`.mint-tags-label`);t?(e||(e=document.createElement(`label`),e.className=`mint-tags-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none`,a.appendChild(e)),e.textContent=t,e.setAttribute(`for`,i)):e&&e.remove()}else a&&a.remove();let o=this.querySelector(`.mint-tags-info`);n?(o||(o=document.createElement(`span`),o.className=`mint-tags-info text-xs text-gray-500 dark:text-gray-400 select-none mt-1 block`,this._container&&this._container.parentElement===this?this.insertBefore(o,this._container.nextSibling):this.appendChild(o)),o.textContent=n):o&&o.remove();let s=this.getName();s?(this.setAttribute(`name`,s),this._input&&(this._input.name=s,this._input.id=i)):(this.removeAttribute(`name`),this._input&&(this._input.removeAttribute(`name`),this._input.id=i)),this._wireInputBackspace(),this._renderChips(),this._renderPredefinedPopover(),this._renderErrorState(),this._renderSkeleton(e)}_getAvailablePredefinedTags(){let e=new Set(this._tags.map(e=>e.value.toLowerCase()));return this._predefinedTags.filter(t=>!e.has(t.value.toLowerCase()))}_shouldShowInput(){return this._input?!this.isPredefinedOnly()||!this._predefinedTags.length?!0:this._getAvailablePredefinedTags().length>0:!1}_disconnectPredefinedFieldResizeObserver(){this._predefinedFieldResizeObserver&&=(this._predefinedFieldResizeObserver.disconnect(),null),this._predefinedPopoverBodyEl=null}_syncPredefinedPopoverBodyMinWidth(e){if(!this._container)return;let t=this._container.offsetWidth;t>0?e.style.minWidth=`${Math.max(t,200)}px`:e.style.minWidth=`12rem`}_attachPredefinedFieldResizeObserver(e){if(this._disconnectPredefinedFieldResizeObserver(),!this._container||typeof ResizeObserver>`u`){this._syncPredefinedPopoverBodyMinWidth(e);return}this._predefinedPopoverBodyEl=e,this._predefinedFieldResizeObserver=new ResizeObserver(()=>{!this._predefinedPopoverBodyEl||!this._container||this._syncPredefinedPopoverBodyMinWidth(this._predefinedPopoverBodyEl)}),this._predefinedFieldResizeObserver.observe(this._container),this._syncPredefinedPopoverBodyMinWidth(e)}_renderPredefinedPopover(){if(!this._container||!this._chipsWrap||(this._disconnectPredefinedFieldResizeObserver(),this.querySelectorAll(`[data-mint-tags-predefined="true"]`).forEach(e=>e.remove()),!this._predefinedTags.length)||!this._input||!this._input.id)return;let e=this._getAvailablePredefinedTags();if(this.isPredefinedOnly()&&e.length===0)return;let t=`${this.getAttribute(`id`)||this._input.id}-tags-field`;this._container.id=t;let n=document.createElement(`mint-popover`);n.setAttribute(`trigger-id`,t),n.setAttribute(`trigger-toggle`,`false`),n.setAttribute(`trigger-align`,`start`),n.setAttribute(`direction`,`down`),n.setAttribute(`padding`,`0`),n.setAttribute(`distance`,`6px`),n.dataset.mintTagsPredefined=`true`;let r=document.createElement(`div`);if(r.dataset.mintTagsPredefinedBody=`true`,r.className=`box-border flex w-full min-w-0 flex-col gap-0.5 bg-white p-1 dark:bg-mint-elevated`,r.addEventListener(`mousedown`,e=>{e.preventDefault()}),e.length)e.forEach(e=>{let t=document.createElement(`mint-button`);t.setAttribute(`type`,`button`),t.setAttribute(`variant`,`ghost`),t.setAttribute(`full-width`,`true`),t.setAttribute(`align`,`left`),t.className=`w-full justify-start`,t.textContent=e.label||e.value,t.addEventListener(`mousedown`,e=>{e.preventDefault()},!0),t.addEventListener(`click`,()=>{this._addTag(e),n.removeAttribute(`open`),requestAnimationFrame(()=>{this._input?.focus({preventScroll:!0}),this._container?.setAttribute(`data-mint-tags-active`,`true`)})}),r.appendChild(t)});else{let e=document.createElement(`div`);e.className=`px-2 py-1 text-xs text-gray-500 dark:text-gray-400`,e.textContent=`No tags available`,r.appendChild(e)}n.appendChild(r),this._container.appendChild(n),this._attachPredefinedPopoverOpenOnInputFocus(),this._attachPredefinedFieldResizeObserver(r)}_getPredefinedPopoverEl(){return this.querySelector(`mint-popover[data-mint-tags-predefined="true"]`)}_attachPredefinedPopoverOpenOnInputFocus(){!this._input||!this._predefinedTags.length||this._predefinedPopoverOpenListenersAttached||(this._predefinedPopoverOpenListenersAttached=!0,this._input.addEventListener(`focus`,()=>{if(this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this.isLoading())return;let e=this._getPredefinedPopoverEl();e&&e.setAttribute(`open`,`true`)}),this._input.addEventListener(`blur`,()=>{this._predefinedBlurCloseTimer!==null&&window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=window.setTimeout(()=>{if(this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose){this._suppressNextPredefinedBlurClose=!1;return}this._getPredefinedPopoverEl()?.removeAttribute(`open`)},150)}))}_renderSkeleton(e){let t=this._container;if(!t)return;t.classList.contains(`relative`)||t.classList.add(`relative`);let n=t.querySelector(`.mint-tags-skeleton`);e?(n||(n=document.createElement(`div`),n.className=`mint-tags-skeleton absolute inset-0 z-10 pointer-events-none rounded-lg bg-gray-200 dark:bg-mint-hover animate-pulse`,t.appendChild(n)),n.style.display=`block`,this._chipsWrap&&(this._chipsWrap.style.visibility=`hidden`,this._chipsWrap.style.pointerEvents=`none`),this._input&&(this._input.style.visibility=`hidden`,this._input.style.pointerEvents=`none`)):(n&&(n.style.display=`none`),this._chipsWrap&&(this._chipsWrap.style.visibility=`visible`,this._chipsWrap.style.pointerEvents=`auto`),this._input&&(this._input.style.visibility=`visible`,this._input.style.pointerEvents=`auto`))}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-tags-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-tags-error mt-1 text-xs text-red-600 dark:text-red-400`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_renderChips(){if(!this._chipsWrap)return;this._chipsWrap.innerHTML=``;let e=0;this._tags.forEach(t=>{let n=document.createElement(`mint-chip`);n.dataset.index=String(e++),n.dataset.value=t.value,n.draggable=this.hasAttribute(`sortable`),n.draggable&&n.classList.add(`cursor-move`),t.dismissable&&(n.setAttribute(`dismissable`,`true`),n.addEventListener(`dismissed`,()=>this._removeTag(t.value))),this._chipsWrap.appendChild(n);let r=n.querySelector(`[data-mt-chip-text]`);r&&(r.textContent=t.label||t.value),this._setupChipEvents(n,t),n.draggable&&(n.addEventListener(`dragstart`,e=>this._onDragStart(e,n)),n.addEventListener(`dragover`,e=>this._onDragOverChip(e,n)),n.addEventListener(`drop`,e=>this._onDrop(e)),n.addEventListener(`dragend`,()=>this._onDragEnd())),this.hasAttribute(`sortable`)&&n.addEventListener(`pointerdown`,e=>this._onPointerDown(e,n))}),this._input&&this._shouldShowInput()&&(this.hasAttribute(`sortable`)&&(this._input.addEventListener(`dragover`,e=>this._onDragOverInput(e)),this._input.addEventListener(`drop`,e=>this._onDrop(e)),this._input.addEventListener(`dragend`,()=>this._onDragEnd())),this._chipsWrap.appendChild(this._input))}_addFromInput(){if(!this._input)return;let e=this._input.value.trim();if(!e)return;if(this._tags.some(t=>t.value.toLowerCase()===e.toLowerCase())){this._input.value=``;return}let t=this._predefinedTags.find(t=>t.value.toLowerCase()===e.toLowerCase());if(this.isPredefinedOnly()){if(!t){this._input.value=``;return}this._addTag(t)}else this._addTag(t||{value:e,label:e,dismissable:!0});this._input.value=``,setTimeout(()=>{this._input?.focus()},10)}_addTag(e){this._tags.some(t=>t.value.toLowerCase()===e.value.toLowerCase())||(this._tags.push({value:e.value,label:e.label||e.value,dismissable:e.dismissable!==!1}),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange())}_removeTag(e){this._tags=this._tags.filter(t=>t.value!==e),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange()}_emitChange(){this.dispatchEvent(new CustomEvent(`tags-change`,{bubbles:!0,composed:!0,detail:{tags:this.tags}}))}_focusLastChip(){let e=this._chipsWrap?.querySelectorAll(`mint-chip`);e&&e.length>0&&e[e.length-1].focus({preventScroll:!0})}_focusInput(){setTimeout(()=>{this._input?.focus({preventScroll:!0})},10)}_wireInputBackspace(){this._input&&this._input.addEventListener(`keydown`,e=>{e.key===`Backspace`&&this._input?.value===``&&(e.preventDefault(),this._focusLastChip())})}_setupChipEvents(e,t){e.tabIndex=0,e.addEventListener(`keydown`,e=>{(e.key===`Backspace`||e.key===`Delete`)&&t.dismissable&&(e.preventDefault(),this._removeTag(t.value),this._focusInput())})}_onContainerPointerDown(e){if(!this._input||!this._input.isConnected||this._input.parentElement!==this._chipsWrap||e.button!==0||e.defaultPrevented)return;let t=e.composedPath();if(!t.some(e=>e===this._input)&&!t.some(e=>e instanceof Element&&e.closest(`mint-chip`)!=null)){this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this._suppressNextPredefinedBlurClose=!0,e.preventDefault();try{this._input.focus({preventScroll:!0})}catch{}this._predefinedTags.length>0&&this._getPredefinedPopoverEl()?.setAttribute(`open`,`true`)}}_onDragStart(e,t){this.hasAttribute(`sortable`)&&(this._dragChip=t,this._dragIndex=Number(t.dataset.index),e.dataTransfer?.setData(`text/plain`,t.dataset.index||``),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.dropEffect=`move`),t.classList.add(`opacity-60`))}_reorderTags(e,t){if(e<0||t<0||e>=this._tags.length||t>=this._tags.length)return;let n=[...this._tags],[r]=n.splice(e,1);n.splice(t,0,r),this._tags=n,this._syncAttr(),this._renderChips(),this._emitChange()}_onDragOverInput(e){this.hasAttribute(`sortable`)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),this._dragChip&&this._chipsWrap&&this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input))}_onDragOverChip(e,t){if(!this.hasAttribute(`sortable`)||(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),!this._dragChip||!this._chipsWrap)||t===this._dragChip)return;let n=t.getBoundingClientRect();if(e.clientX<n.left+n.width*.5){if(this._dragChip.nextSibling===t)return;this._chipsWrap.insertBefore(this._dragChip,t)}else{if(t.nextSibling===this._dragChip)return;let e=t.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}}_onDrop(e){this.hasAttribute(`sortable`)&&e.preventDefault()}_onDragEnd(){this._dragChip&&this._dragChip.classList.remove(`opacity-60`),this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}_syncOrderFromDom(){if(!this._chipsWrap)return;let e=Array.from(this._chipsWrap.querySelectorAll(`mint-chip`));if(e.length===0)return;let t=[];e.forEach(e=>{let n=e.dataset.value;if(!n)return;let r=this._tags.find(e=>e.value===n);r&&t.push(r)}),t.length===this._tags.length&&(this._tags=t,this._syncAttr(),this._renderChips(),this._emitChange())}_onPointerDown(e,t){if(this.hasAttribute(`sortable`)&&e.pointerType!==`mouse`){this._isPointerDragging=!0,this._dragChip=t,this._dragIndex=Number(t.dataset.index);try{t.setPointerCapture(e.pointerId)}catch{}t.classList.add(`opacity-60`,`select-none`),e.preventDefault()}}_onPointerMove(e){if(!this._isPointerDragging||!this._dragChip||!this._chipsWrap||e.pointerType===`mouse`)return;let t=document.elementFromPoint(e.clientX,e.clientY);if(!t)return;let n=t.closest(`mint-chip`);if(n&&n!==this._dragChip){let t=n.getBoundingClientRect();if(e.clientX<t.left+t.width*.5)this._dragChip.nextSibling!==n&&this._chipsWrap.insertBefore(this._dragChip,n);else if(n.nextSibling!==this._dragChip){let e=n.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}return}this._input&&t.closest(`input`)===this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input)}_onPointerUp(e){if(this._isPointerDragging){if(this._isPointerDragging=!1,this._dragChip){try{this._dragChip.releasePointerCapture(e.pointerId)}catch{}this._dragChip.classList.remove(`opacity-60`,`select-none`)}this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}}};customElements.get(`mint-tags`)||customElements.define(`mint-tags`,A);var j=class extends HTMLElement{constructor(...e){super(...e),this._clickHandler=null,this._keydownHandler=null}connectedCallback(){this._render(),this._setupEventListeners()}disconnectedCallback(){this._cleanupEventListeners()}_render(){this.classList.add(`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-offset-1`,`focus-visible:ring-gray-400`,`dark:focus-visible:ring-gray-500`,`rounded`),this.getAttribute(`disabled`)===`true`?this.classList.add(`cursor-not-allowed`,`opacity-50`):this.classList.add(`cursor-pointer`),this.getAttribute(`role`)||this.setAttribute(`role`,`button`),this.getAttribute(`tabindex`)||this.setAttribute(`tabindex`,`0`)}_setupEventListeners(){this._clickHandler=e=>{if(this.getAttribute(`disabled`)===`true`){e.preventDefault(),e.stopPropagation();return}this._handleClick(e)},this._keydownHandler=e=>{if(e.key===`Enter`||e.key===` `){if(this.getAttribute(`disabled`)===`true`){e.preventDefault(),e.stopPropagation();return}e.preventDefault(),this._handleClick(e)}},this.addEventListener(`click`,this._clickHandler),this.addEventListener(`keydown`,this._keydownHandler)}_cleanupEventListeners(){this._clickHandler&&=(this.removeEventListener(`click`,this._clickHandler),null),this._keydownHandler&&=(this.removeEventListener(`keydown`,this._keydownHandler),null)}_handleClick(e){this.dispatchEvent(new CustomEvent(`clickable-click`,{bubbles:!0,composed:!0,detail:{originalEvent:e}}))}static get observedAttributes(){return[`disabled`]}attributeChangedCallback(e,t,n){e===`disabled`&&(n===`true`?(this.classList.remove(`cursor-pointer`),this.classList.add(`opacity-50`,`cursor-not-allowed`),this.setAttribute(`aria-disabled`,`true`)):(this.classList.remove(`opacity-50`,`cursor-not-allowed`),this.classList.add(`cursor-pointer`),this.removeAttribute(`aria-disabled`)))}};customElements.get(`mint-clickable`)||customElements.define(`mint-clickable`,j);var ee=class extends HTMLElement{static get observedAttributes(){return[`heading`,`dismissable`,`tone`]}constructor(){super(),this._headingElement=null,this._iconElement=null,this._dismissButton=null,this._headerWrapper=null,this._bodyWrapper=null,this._dismissHandler=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`),this.render()}disconnectedCallback(){this._dismissButton&&this._dismissHandler&&this._dismissButton.removeEventListener(`click`,this._dismissHandler)}attributeChangedCallback(e,t,n){t!==n&&this.render()}getHeading(){return this.getAttribute(`heading`)||``}getTone(){let e=this.getAttribute(`tone`);return e===`info`||e===`success`||e===`warning`||e===`danger`?e:`info`}isDismissable(){return this.getAttribute(`dismissable`)===`true`}getIconName(){switch(this.getTone()){case`info`:return`info`;case`success`:return`success`;case`warning`:return`warning`;case`danger`:return`error`;default:return`info`}}getIconColorClasses(){switch(this.getTone()){case`info`:return`text-gray-700 dark:text-gray-300`;case`success`:return`text-green-600 dark:text-green-400`;case`warning`:return`text-yellow-600 dark:text-yellow-400`;case`danger`:return`text-red-600 dark:text-red-400`;default:return`text-gray-700 dark:text-gray-300`}}getHeadingColorClasses(){return`text-gray-900 dark:text-gray-100`}getHeaderBackgroundClasses(){switch(this.getTone()){case`info`:return`bg-gray-100 dark:bg-white/5`;case`success`:return`bg-green-100 dark:bg-green-900/30`;case`warning`:return`bg-yellow-100 dark:bg-yellow-900/30`;case`danger`:return`bg-red-100 dark:bg-red-900/30`;default:return`bg-gray-100 dark:bg-white/5`}}getBorderClasses(){switch(this.getTone()){case`info`:return`border-gray-200 dark:border-mint-divider`;case`success`:return`border-green-200 dark:border-green-800`;case`warning`:return`border-yellow-200 dark:border-yellow-800`;case`danger`:return`border-red-200 dark:border-red-800`;default:return`border-gray-200 dark:border-mint-divider`}}getAriaLive(){return this.getTone()===`danger`?`assertive`:`polite`}render(){let e=this.getTone(),t=this.getHeading(),n=this.isDismissable();this.className=`box-border m-0 p-0 border-0 align-baseline block rounded-lg border shadow-sm overflow-hidden ${this.getBorderClasses()}`;let r=this.getAriaLive();this.setAttribute(`role`,`alert`),this.setAttribute(`aria-live`,r),e===`danger`?this.setAttribute(`aria-atomic`,`true`):this.removeAttribute(`aria-atomic`);let i=[];for(this._bodyWrapper?Array.from(this._bodyWrapper.childNodes).forEach(e=>{i.push(e)}):Array.from(this.childNodes).forEach(e=>{e!==this._headerWrapper&&e!==this._bodyWrapper&&e!==this._iconElement&&e!==this._headingElement&&e!==this._dismissButton&&i.push(e)}),this._dismissButton&&this._dismissHandler&&this._dismissButton.removeEventListener(`click`,this._dismissHandler);this.firstChild;)this.removeChild(this.firstChild);if(this._headerWrapper=null,this._bodyWrapper=null,this._iconElement=null,this._headingElement=null,this._dismissButton=null,this._headerWrapper=document.createElement(`div`),this._headerWrapper.className=`px-4 py-3 flex items-center gap-3 ${this.getHeaderBackgroundClasses()}`,this._iconElement=document.createElement(`mint-icon`),this._iconElement.setAttribute(`name`,this.getIconName()),this._iconElement.className=`flex-shrink-0 w-5 h-5 ${this.getIconColorClasses()}`,this._headerWrapper.appendChild(this._iconElement),this._headingElement=document.createElement(`mint-text`),this._headingElement.className=`font-semibold flex-1 ${this.getHeadingColorClasses()}`,this._headingElement.textContent=t||``,this._headerWrapper.appendChild(this._headingElement),n){this._dismissButton=document.createElement(`button`),this._dismissButton.className=`flex-shrink-0 p-1 rounded hover:bg-black/10 dark:hover:bg-white/10`,this._dismissButton.setAttribute(`aria-label`,`Dismiss alert`),this._dismissButton.setAttribute(`type`,`button`);let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`close`),e.className=`w-4 h-4 text-gray-700 dark:text-gray-300`,this._dismissButton.appendChild(e),this._dismissHandler=e=>{e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent(`dismissed`,{bubbles:!0,composed:!0})),this.remove()},this._dismissButton.addEventListener(`click`,this._dismissHandler),this._headerWrapper.appendChild(this._dismissButton)}this._bodyWrapper=document.createElement(`div`),this._bodyWrapper.className=`px-4 py-3 bg-white dark:bg-mint-elevated`,i.forEach(e=>{this._bodyWrapper.appendChild(e)}),this.appendChild(this._headerWrapper),this.appendChild(this._bodyWrapper)}};customElements.get(`mint-alert`)||customElements.define(`mint-alert`,ee);var M=class extends HTMLElement{static get observedAttributes(){return[`configuration`,`loading`,`virtual-scroll`,`virtual-scroll-root`,`virtual-row-height`,`virtual-max-height`,`fixed-header`,`fixed-controls`]}_isExternalLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}constructor(){super(),this._configuration=null,this._rows=[],this._search=``,this._currentPage=1,this._perPage=15,this._totalRows=0,this._lastPage=0,this._offset=0,this._loaded=!1,this._fetching=!1,this._loading=!1,this._loadingPage=null,this._fetchError=null,this._searching=!1,this._sorting=!1,this._sortingColumn=null,this._type=`provided`,this._searchTimeoutId=null,this._sortTimeoutId=null,this._searchColumns=[],this._exportColumns={},this._columns=[],this._tableId=``,this._searchInput=null,this._tableContainer=null,this._paginationContainer=null,this._skeletonContainer=null,this._inMintCard=!1,this._virtualBodyScrollEl=null,this._virtualScrollHandler=null,this._virtualWindowRaf=null,this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``,this._virtualResizeObserver=null,this._virtualWindowResizeHandler=null,this._virtualRowCache=new Map,this._virtualRangeFetching=!1,this._mobileListMql=null,this._boundMobileListMqlListener=null,this._virtualFetchGeneration=0,this._virtualAjaxPrefetchTimer=null,this._fixedChromeResizeObserver=null}get inMintCard(){return this._inMintCard}get configuration(){return this._configuration}set configuration(e){e&&typeof e==`object`&&!Array.isArray(e)?(this._configuration=e,this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._type=typeof this._configuration.data==`string`?`ajax`:`provided`,this._loaded=!1,this._currentPage=1,this._offset=0,this._type===`provided`&&Array.isArray(this._configuration.data)&&(this._rows=[...this._configuration.data],this._totalRows=this._configuration.data.length),this._initializeColumns(),this.isConnected&&this.render()):e==null?this._configuration=null:this._parseConfiguration()}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`),this._inMintCard=this.parentElement?.tagName?.toLowerCase()===`mint-card`,this._configuration||this._parseConfiguration(),this._initializeColumns(),this._loadPageFromUrl(),this._attachRowClickHandler(),this.render()}disconnectedCallback(){this._searchTimeoutId&&clearTimeout(this._searchTimeoutId),this._detachVirtualScroll(),this._detachFixedChromeResize(),this._detachMobileListMql(),this._rowClickHandler&&=(this.removeEventListener(`click`,this._rowClickHandler,!0),null),this._scrollHandler&&=(window.removeEventListener(`scroll`,this._scrollHandler),null)}attributeChangedCallback(e,t,n){e===`configuration`&&t!==n?(!this._configuration||typeof n==`string`)&&(this._parseConfiguration(),this.render()):t!==n&&(e===`loading`||e===`virtual-scroll`||e===`virtual-scroll-root`||e===`virtual-row-height`||e===`virtual-max-height`||e===`fixed-header`||e===`fixed-controls`)&&this._configuration&&this.isConnected&&this.render()}refresh(){this._configuration&&(this._type===`ajax`?this._fetchData(void 0,!0,this._perPage,this._offset):(Array.isArray(this._configuration.data)&&(this._rows=[...this._configuration.data],this._totalRows=this._rows.length),this.render()))}setData(e){if(this._configuration){if(this._configuration.data=e,this._type=typeof e==`string`?`ajax`:`provided`,this._currentPage=1,this._offset=0,this._fetchError=null,this._searching=!1,this._loadingPage=null,this._sortTimeoutId&&=(clearTimeout(this._sortTimeoutId),null),this._searchTimeoutId&&=(clearTimeout(this._searchTimeoutId),null),this._virtualScrollActive()&&(this._virtualRowCache.clear(),this._virtualInvalidate()),this._type===`ajax`){this._rows=[],this._totalRows=0,this._lastPage=0,this._loaded=!1,this._fetching=!1,this._loading=!1,this._fetchData(void 0,!0,this._perPage,0);return}this._rows=Array.isArray(e)?[...e]:[],this._totalRows=this._rows.length,this._lastPage=Math.max(1,Math.ceil(this._totalRows/this._perPage)),this._loaded=!0,this._fetching=!1,this._loading=!1,this.render()}}_parseConfiguration(){let e=this.getAttribute(`configuration`);if(!e){console.error(`mint-resource-table: configuration attribute is required`);return}try{this._configuration=JSON.parse(e),this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._type=typeof this._configuration.data==`string`?`ajax`:`provided`,this._loaded=!1,this._currentPage=this._getPageFromUrl()||1,this._offset=(this._currentPage-1)*this._perPage,this._type===`provided`&&Array.isArray(this._configuration.data)&&(this._rows=[...this._configuration.data],this._totalRows=this._configuration.data.length),this._initializeColumns()}catch(e){console.error(`mint-resource-table: Invalid configuration JSON`,e)}}_initializeColumns(){this._configuration&&(this._searchColumns=[],this._exportColumns={},this._columns=[],this._configuration.columns.forEach(e=>{e.searchable&&e.data&&this._searchColumns.push(e.data),e.export&&e.data&&(this._exportColumns[e.data]=e.label),e.data&&this._columns.push(e.data)}),this._configuration.sortBy||(this._configuration.sortBy=`id`),this._configuration.sort||(this._configuration.sort=`asc`))}async _fetchData(e,t=!0,n,r){if(!this._configuration)return;let i=e||(typeof this._configuration.data==`string`?this._configuration.data:null);if(!i||this._fetching||this._loading)return;t&&(this._fetching=!0,this._loaded?this._updatePagination():this.render()),this._loading=!0;let a=n||this._perPage,o=r===void 0?this._offset:r;this._virtualScrollActive()&&this._type===`ajax`&&o===0&&(this._virtualFetchGeneration++,this._virtualRowCache.clear(),this._virtualInvalidate());try{let e=new URLSearchParams({perPage:a.toString(),offset:o.toString(),search:this._search,sortBy:this._configuration.sortBy||`id`,sort:this._configuration.sort||`asc`,searchColumns:this._searchColumns.join(`,`),columns:this._columns.join(`,`)}),t={};this._configuration.headers&&(t.headers=this._configuration.headers);let n=await fetch(`${i}?${e.toString()}`,t);if(!n.ok)throw Error(`HTTP error! status: ${n.status}`);let r=await n.json(),s=r.content?.rows||[],c=r.content?.total||0,l=s;this._configuration.predefinedData?(l=[...this._configuration.predefinedData,...s],this._totalRows=c+this._configuration.predefinedData.length):this._totalRows=c,this._rows=l;let u=Math.floor(o/a)+1;r.content?.current_page!==void 0&&r.content.current_page===u?this._currentPage=r.content.current_page:this._currentPage=u,this._offset=(this._currentPage-1)*a,this._lastPage=r.content?.last_page||1,this._fetching=!1,this._loaded=!0,this._loading=!1,this._fetchError=null,this._searching=!1;let d=this._sorting;d&&this._updateSortIcons(),this._sorting=!1,this._sortingColumn=null,d&&this._updateSortIcons(),this.dispatchEvent(new CustomEvent(`loaded`,{detail:{rows:this._rows}})),this._updateSearchIcon();let f=`tbody[data-mint-rt-tbody="${this._tableId}"]`,p=!!this.querySelector(f);if(this._virtualScrollActive()&&this._type===`ajax`)p||this.render(),s.forEach((e,t)=>{this._virtualRowCache.set(o+t,e)}),this._virtualInvalidate(),o===0?queueMicrotask(()=>this._scrollVirtualTableTopIntoView()):this._scheduleVirtualWindowSync(),this._loadingPage,this._loadingPage=null,this._updatePagination(),setTimeout(()=>{let e=this._paginationMountedRoot();e&&e.querySelectorAll(`mint-button[data-action="page"]`).forEach(e=>{`render`in e&&typeof e.render==`function`&&e.render()})},0);else if(this.querySelector(`#${this._tableId}`)?.closest(`table`)?.querySelector(`tbody`)){if(d){let e=this._loading,t=this._fetching;this._loading=!1,this._fetching=!1,this._updateTableBody(),this._loading=e,this._fetching=t}else this._updateTableBody();this._loadingPage,this._loadingPage=null,this._updatePagination(),setTimeout(()=>{let e=this._paginationMountedRoot();e&&e.querySelectorAll(`mint-button[data-action="page"]`).forEach(e=>{`render`in e&&typeof e.render==`function`&&e.render()})},0)}else this.render()}catch(e){this._fetching=!1,this._loading=!1,this._loadingPage=null,this._loaded=!0,this._searching=!1,this._fetchError=e instanceof Error?e.message:`Failed to fetch data`,console.error(`mint-resource-table: Error fetching data`,e),this._updateSearchIcon(),this.querySelector(`#${this._tableId}`)?.closest(`table`)?.querySelector(`tbody`)?(this._updateTableBody(),this._loadingPage=null,this._updatePagination()):this.render()}}_getRows(){if(!this._configuration)return[];if(this._type===`ajax`)return this._rows;let e=[...this._rows],t=this._configuration.sortBy||`id`,n=this._configuration.sort||`asc`;if(this._search){let t=this._search.toLowerCase().trim().split(/\s+/);e=e.filter(e=>{let n=Object.values(e).map(e=>String(e).toLowerCase()).join(` `);return t.every(e=>n.includes(e))})}if(e.sort((e,r)=>{let i=e[t],a=r[t];if(i==null&&a==null)return 0;if(i==null)return 1;if(a==null)return-1;let o=typeof i==`number`?i:typeof i==`string`&&!isNaN(Number(i))&&i.trim()!==``?Number(i):null,s=typeof a==`number`?a:typeof a==`string`&&!isNaN(Number(a))&&a.trim()!==``?Number(a):null;if(o!==null&&s!==null){let e=o-s;return n===`asc`?e:-e}let c=i instanceof Date?i:typeof i==`string`?new Date(i):null,l=a instanceof Date?a:typeof a==`string`?new Date(a):null;if(c&&l&&!isNaN(c.getTime())&&!isNaN(l.getTime())){let e=c.getTime()-l.getTime();return n===`asc`?e:-e}let u=String(i).localeCompare(String(a),void 0,{numeric:!0,sensitivity:`base`});return n===`asc`?u:-u}),this._perPage){let t=Math.ceil(e.length/this._perPage);this._lastPage=t,e.forEach((e,t)=>{e.page=Math.ceil((t+1)/this._perPage)}),this._currentPage>t&&t>0&&(this._currentPage=t)}return e.filter(e=>!this._perPage||e.page===this._currentPage)}_getAllFilteredRowsSorted(){if(!this._configuration||this._type!==`provided`)return[];let e=[...this._rows],t=this._configuration.sortBy||`id`,n=this._configuration.sort||`asc`;if(this._search){let t=this._search.toLowerCase().trim().split(/\s+/);e=e.filter(e=>{let n=Object.values(e).map(e=>String(e).toLowerCase()).join(` `);return t.every(e=>n.includes(e))})}if(e.sort((e,r)=>{let i=e[t],a=r[t];if(i==null&&a==null)return 0;if(i==null)return 1;if(a==null)return-1;let o=typeof i==`number`?i:typeof i==`string`&&!isNaN(Number(i))&&i.trim()!==``?Number(i):null,s=typeof a==`number`?a:typeof a==`string`&&!isNaN(Number(a))&&a.trim()!==``?Number(a):null;if(o!==null&&s!==null){let e=o-s;return n===`asc`?e:-e}let c=i instanceof Date?i:typeof i==`string`?new Date(i):null,l=a instanceof Date?a:typeof a==`string`?new Date(a):null;if(c&&l&&!isNaN(c.getTime())&&!isNaN(l.getTime())){let e=c.getTime()-l.getTime();return n===`asc`?e:-e}let u=String(i).localeCompare(String(a),void 0,{numeric:!0,sensitivity:`base`});return n===`asc`?u:-u}),this._perPage){let t=Math.ceil(e.length/this._perPage);this._lastPage=t,e.forEach((e,t)=>{e.page=Math.ceil((t+1)/this._perPage)}),this._currentPage>t&&t>0&&(this._currentPage=t)}return e.filter(e=>!this._perPage||e.page===this._currentPage)}_virtualInvalidate(){this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``}_getRowDataForEventIndex(e){if(this._configuration){if(!this._virtualScrollActive())return this._getRows()[e];if(this._type===`provided`)return this._getAllFilteredRowsSorted()[e];if(this._type===`ajax`)return this._virtualRowCache.get(e)}}getRowByIndex(e){return this._getRowDataForEventIndex(e)}_virtualScrollActive(){return this._configuration?(this.getAttribute(`virtual-scroll`)||``).toLowerCase().trim()===`true`:!1}_virtualScrollRoot(){let e=(this.getAttribute(`virtual-scroll-root`)||``).toLowerCase().trim();return e===`table-body`||e===`body`||this._configuration?.virtualScrollRoot===`table-body`?`table-body`:`document`}_virtualBodyScrollDisablesDocumentFixedChrome(){return this._virtualScrollActive()&&this._virtualScrollRoot()===`table-body`}_fixedHeader(){if(this._virtualBodyScrollDisablesDocumentFixedChrome()||!this.hasAttribute(`fixed-header`))return!1;let e=(this.getAttribute(`fixed-header`)||``).toLowerCase().trim();return e!==`false`&&e!==`0`}_fixedControls(){if(this._virtualBodyScrollDisablesDocumentFixedChrome()||!this.hasAttribute(`fixed-controls`))return!1;let e=(this.getAttribute(`fixed-controls`)||``).toLowerCase().trim();return e!==`false`&&e!==`0`}_virtualRowHeightPx(){let e=parseInt(this.getAttribute(`virtual-row-height`)||``,10);if(!isNaN(e)&&e>0)return e;let t=this._configuration?.virtualRowHeight;return typeof t==`number`&&t>0?t:48}_virtualRowHeightPxForSync(e){let t=this._virtualRowHeightPx();if(!this._configuration)return t;if(e){let e=this._mobileThumbnailColumn();if(e){let n=this._thumbnailMobilePx(e);return Math.max(t,n+36)}return Math.max(t,80)}let n=this._mobileThumbnailColumn();if(n){let e=this._thumbnailDesktopPx(n);return Math.max(t,e+28)}return t}_virtualMaxHeightCss(){let e=this.getAttribute(`virtual-max-height`);if(e&&e.trim())return e.trim();let t=this._configuration?.virtualMaxHeight;return t&&String(t).trim()?String(t).trim():`min(70dvh, 28rem)`}_virtualColspan(){return this._configuration?Math.max(1,this._configuration.columns.filter(e=>!e.hidden).length):1}_ensureMobileListMql(){typeof window>`u`||!window.matchMedia||this._mobileListMql||(this._mobileListMql=window.matchMedia(`(max-width: 767px)`),this._boundMobileListMqlListener=()=>{this._configuration&&this.isConnected&&this.render()},this._mobileListMql.addEventListener(`change`,this._boundMobileListMqlListener))}_detachMobileListMql(){this._mobileListMql&&this._boundMobileListMqlListener&&this._mobileListMql.removeEventListener(`change`,this._boundMobileListMqlListener),this._mobileListMql=null,this._boundMobileListMqlListener=null}_useMobileListLayout(){return!!this._mobileListMql?.matches}_paginationHostPlaceholderHtml(){if(!this._configuration?.perPage||this._virtualScrollActive())return``;let e=this._lastPage||Math.ceil(this._rows.length/this._perPage);if((this._lastPage>0?this._lastPage:e)<=1)return``;let t=[`mint-rt-pagination-host`,`w-full min-w-0 overflow-x-auto overflow-y-hidden overscroll-x-contain`,`flex justify-center [-webkit-overflow-scrolling:touch] md:justify-end`,this._inMintCard?`border-t border-gray-200 px-3.5 pb-3.5 pt-3 dark:border-mint-divider md:border-t-0 md:pt-0`:`border-t border-gray-200 px-2 py-3 dark:border-mint-divider md:border-t-0 md:py-0 md:mt-4`].join(` `);return`<div id="mint-rt-pagination-host-${this._tableId}" data-mint-rt-pagination-wrap="" class="${t}"></div>`}_getPaginationHostEl(){return this.querySelector(`#mint-rt-pagination-host-${this._tableId}`)}_paginationMountedRoot(){return this._getPaginationHostEl()||this.querySelector(`nav[data-mint-rt-pagination-nav]`)?.parentElement||this.querySelector(`nav`)?.closest(`.flex.justify-end`)}_paginationPageButtonLi(e){let t=this._currentPage===e,n=this._loadingPage===e;return`<li class="shrink-0"><mint-button variant="solid" size="sm"${t?` active="true"`:``}${this._loading||this._fetching?` disabled="true"`:``}${n?` loading="true"`:``} data-action="page" data-page="${e}">${n?``:`${e}`}</mint-button></li>`}_paginationHtmlCompactMiddle(e){let t=``,n=this._currentPage;if(e<=5){for(let n=1;n<=e;n++)t+=this._paginationPageButtonLi(n);return t}let r=[...new Set([1,e,n-1,n,n+1].map(t=>Math.min(e,Math.max(1,t))))].sort((e,t)=>e-t),i=0;for(let e of r)i>0&&e-i>1&&(t+=`<li class="shrink-0"><span class="px-1 text-gray-500 dark:text-gray-400" aria-hidden="true">…</span></li>`),t+=this._paginationPageButtonLi(e),i=e;return t}_paginationHtmlDesktopMiddle(e){let t=``,n=e>=10,r=Math.max(1,this._currentPage-1),i=Math.min(e,this._currentPage+1);if(n){for(let e=1;e<=3;e++)t+=this._paginationPageButtonLi(e);let n=i<=3,a=r>=e-2;if(!n&&!a){r>4&&(t+=`<li class="shrink-0"><span class="px-2">...</span></li>`);for(let e=r;e<=i;e++)e<=3||(t+=this._paginationPageButtonLi(e));i<e-3&&(t+=`<li class="shrink-0"><span class="px-2">...</span></li>`)}else (n&&!a||!n&&a&&e-2>4)&&(t+=`<li class="shrink-0"><span class="px-2">...</span></li>`);for(let o=e-2;o<=e;o++)o<=3||!n&&!a&&o>=r&&o<=i||(t+=this._paginationPageButtonLi(o))}else for(let n=1;n<=e;n++)t+=this._paginationPageButtonLi(n);return t}_buildPaginationNavMarkup(e){let t=this._currentPage===1||this._loading||this._fetching,n=`<nav data-mint-rt-pagination-nav="" class="w-max max-w-none shrink-0" aria-label="Pagination">`;n+=`<ul class="flex flex-nowrap items-center gap-1">`,n+=`<li class="shrink-0"><mint-button variant="solid" size="sm" icon="caret-left" ${t?`disabled="true"`:``} data-action="page-prev"></mint-button></li>`,n+=this._useMobileListLayout()?this._paginationHtmlCompactMiddle(e):this._paginationHtmlDesktopMiddle(e);let r=this._currentPage>=e||this._loading||this._fetching;return n+=`<li class="shrink-0"><mint-button variant="solid" size="sm" icon="caret-right" ${r?`disabled="true"`:``} data-action="page-next"></mint-button></li>`,n+=`</ul></nav>`,n}_hasSortableColumns(){return!!this._configuration?.columns.some(e=>!e.hidden&&e.sortable&&e.data)}_getMobileSortTriggerIconName(){return`sort-arrows`}_mobileSortPopoverAffordanceInnerHtml(e){return e===`spinner`?`<span class="inline-block h-4 w-4 shrink-0 animate-spin rounded-full border-2 border-gray-300 border-t-gray-700 dark:border-gray-600 dark:border-t-gray-200" aria-hidden="true"></span>`:e===`caret-up`||e===`caret-down`?`<mint-icon name="${e}" class="h-4 w-4 shrink-0 text-gray-500 dark:text-gray-400"></mint-icon>`:``}_buildMobileSortPopoverInnerHtml(){if(!this._configuration)return``;let e=`<div class="flex w-full min-w-[11rem] flex-col gap-0.5 p-1">`;return this._configuration.columns.forEach((t,n)=>{if(t.hidden||!t.sortable||!t.data)return;let r=t.raw?t.label:this._escapeHtml(t.label),i=this._getSortClass(t),a=this._mobileSortPopoverAffordanceInnerHtml(i),o=` type="button" variant="ghost" tone="neutral" size="sm" full-width="true" align="left" data-action="mobile-sort" data-column-key="${n}"`;e+=`<mint-button${o}>`,e+=`<span class="flex w-full min-w-0 flex-1 items-center justify-between gap-2">`,e+=`<span class="min-w-0 flex-1 truncate text-left">${r}</span>`,e+=`<span class="inline-flex shrink-0 items-center justify-end" data-mint-rt-mobile-sort-affordance="">${a}</span>`,e+=`</span></mint-button>`}),e+=`</div>`,e}_syncMobileSortPopoverIcons(){if(!this._configuration)return;let e=this.querySelector(`#mint-rt-mobile-sort-popover-${this._tableId}`);e&&this._configuration.columns.forEach((t,n)=>{if(t.hidden||!t.sortable||!t.data)return;let r=e.querySelector(`[data-action="mobile-sort"][data-column-key="${n}"]`);if(!r||r.tagName!==`MINT-BUTTON`)return;let i=r.querySelector(`[data-mint-rt-mobile-sort-affordance]`);if(!i)return;let a=this._getSortClass(t);i.innerHTML=this._mobileSortPopoverAffordanceInnerHtml(a),i.querySelectorAll(`mint-icon`).forEach(e=>{let t=e;typeof t.render==`function`&&t.render()})})}_closeMobileSortPopover(){let e=this.querySelector(`#mint-rt-mobile-sort-popover-${this._tableId}`);e&&typeof e.close==`function`?e.close():e&&e.removeAttribute(`open`)}_buildMobileSortToolbarHtml(){if(!this._hasSortableColumns())return``;let e=`mint-rt-mobile-sort-btn-${this._tableId}`,t=`mint-rt-mobile-sort-popover-${this._tableId}`,n=this._sorting?` loading="true"`:``,r=` icon="${this._escapeHtml(this._getMobileSortTriggerIconName())}"`,i=`<div class="flex shrink-0 items-center md:hidden">`;return i+=`<mint-button id="${e}" data-mint-rt-toolbar="mobile-sort" variant="solid" tone="neutral" size="sm"${n}${r}></mint-button>`,i+=`<mint-popover id="${t}" trigger-id="${e}" direction="down" padding="0">`,i+=this._buildMobileSortPopoverInnerHtml(),i+=`</mint-popover></div>`,i}_stripHtml(e){if(!e)return``;let t=document.createElement(`div`);return t.innerHTML=e,(t.textContent||t.innerText||``).replace(/\s+/g,` `).trim()}_visibleDataColumns(){return this._configuration?this._configuration.columns.filter(e=>!e.hidden):[]}_mobileThumbnailColumn(){return this._visibleDataColumns().find(e=>e.thumbnail)||null}_thumbnailDesktopPx(e){let t=typeof e.thumbnailDesktopPx==`number`&&e.thumbnailDesktopPx>0?e.thumbnailDesktopPx:void 0,n=this._configuration,r=n&&typeof n.thumbnailDesktopPx==`number`&&n.thumbnailDesktopPx>0?n.thumbnailDesktopPx:void 0;return Math.round(t??r??40)}_thumbnailMobilePx(e){let t=typeof e.thumbnailMobilePx==`number`&&e.thumbnailMobilePx>0?e.thumbnailMobilePx:void 0,n=this._configuration,r=n&&typeof n.thumbnailMobilePx==`number`&&n.thumbnailMobilePx>0?n.thumbnailMobilePx:void 0;return Math.round(t??r??56)}_wrapThumbnailDesktopBox(e,t){let n=this._thumbnailDesktopPx(t);return`<div class="flex shrink-0 items-stretch overflow-hidden rounded-md border border-gray-200 bg-gray-100 p-0 dark:border-mint-divider dark:bg-mint-hover [&>*]:m-0 [&>*]:min-h-0 [&>*]:min-w-0 [&>*]:w-full [&>*]:max-w-full [&>*]:p-0 [&>span]:flex [&>span]:h-full [&>span]:w-full [&>span]:min-h-0 [&>span]:min-w-0 [&>span]:items-stretch [&>span]:justify-stretch [&_img]:!m-0 [&_img]:!box-border [&_img]:!block [&_img]:!h-full [&_img]:!w-full [&_img]:!min-h-0 [&_img]:!min-w-0 [&_img]:!max-h-full [&_img]:!max-w-full [&_img]:!border-0 [&_img]:!p-0 [&_img]:!rounded-none [&_img]:!object-cover [&_img]:!object-center" style="${`width:${n}px;height:${n}px;min-width:${n}px;min-height:${n}px`}">${e}</div>`}_mobilePrimaryColumn(){let e=this._visibleDataColumns();return e.find(e=>e.primary)||e.find(e=>(e.data||typeof e.format==`function`)&&!e.thumbnail&&!e.actions)||e[0]||null}_mobileActionsDropdownColumn(){return this._visibleDataColumns().find(e=>e.actions&&e.actionStyle!==`buttons`)||null}_columnPlainSummaryText(e,t){if(!(!e.show||e.show(this,t))||e.actions||e.action)return``;try{if(e.raw){if(typeof e.format==`function`)return this._stripHtml(e.format(this,t));if(e.data)return String(t[e.data]??``)}else{if(typeof e.format==`function`)return this._stripHtml(e.format(this,t));if(e.data)return String(t[e.data]??``)}}catch{return``}return``}_buildTableCellInnerHtml(e,t,n,r=`table`){if(!this._configuration)return``;let i=n,a=``;if(!(!e.show||e.show(this,t)))return``;if(e.raw)if(e.action){if(!e.action.show||e.action.show(this,t)){let n=typeof e.action.label==`function`?e.action.label(this,t):e.action.label;a+=`<mint-button variant="solid" data-action="column-action" data-row-index="${i}" data-column-key="${this._configuration.columns.indexOf(e)}">${this._escapeHtml(String(n))}</mint-button>`}}else if(e.actions)if(e.actionStyle!==`buttons`){let n=`actions-popover-${this._tableId}-${i}`,r=`actions-button-${this._tableId}-${i}`;a+=`<mint-button id="${r}" variant="link" icon="ellipsis">`,a+=`</mint-button>`,a+=`<mint-popover id="${n}" trigger-id="${r}" direction="down">`,e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=typeof n.label==`function`?n.label(this,t):n.label;a+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-mint-hover" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}">${this._escapeHtml(String(o))}</div>`}}),a+=`</mint-popover>`}else e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=n.label?typeof n.label==`function`?n.label(this,t):n.label:``,s=n.icon?` icon="${this._escapeHtml(n.icon)}"`:``,c=n.variant?` variant="${this._escapeHtml(n.variant)}"`:` variant="link"`,l=n.tone?` tone="${this._escapeHtml(n.tone)}"`:``;a+=`<mint-button${c} class="${n.classes||``}" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}"${s}${l}>`,o&&(a+=this._escapeHtml(String(o))),a+=`</mint-button>`}});else typeof e.format==`function`?a+=e.format(this,t):e.data&&(a+=this._escapeHtml(String(t[e.data]||``)));else if(e.action)(!e.action.show||e.action.show(this,t))&&(a+=`<mint-button variant="solid" data-action="column-action" data-row-index="${i}" data-column-key="${this._configuration.columns.indexOf(e)}">${e.action.label}</mint-button>`);else if(e.actions)if(e.actionStyle!==`buttons`){let n=`actions-popover-${this._tableId}-${i}`,r=`actions-button-${this._tableId}-${i}`;a+=`<mint-button id="${r}" variant="link" icon="ellipsis">`,a+=`</mint-button>`,a+=`<mint-popover id="${n}" trigger-id="${r}" direction="down">`,e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=typeof n.label==`function`?n.label(this,t):n.label;a+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-mint-hover" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}">${this._escapeHtml(String(o))}</div>`}}),a+=`</mint-popover>`}else e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=n.label?typeof n.label==`function`?n.label(this,t):n.label:``,s=n.icon?` icon="${this._escapeHtml(n.icon)}"`:``,c=n.variant?` variant="${this._escapeHtml(n.variant)}"`:` variant="link"`,l=n.tone?` tone="${this._escapeHtml(n.tone)}"`:``;a+=`<mint-button${c} class="${n.classes||``}" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}"${s}${l}>`,o&&(a+=this._escapeHtml(String(o))),a+=`</mint-button>`}});else typeof e.format==`function`?a+=this._escapeHtml(e.format(this,t)):e.data&&(a+=this._escapeHtml(String(t[e.data]||``)));return r===`table`&&e.thumbnail&&a&&!e.actions&&!e.action?this._wrapThumbnailDesktopBox(a,e):a}_buildMobileListItemHtml(e,t,n,r=!1){if(!this._configuration)return``;let i=t,a=typeof this._configuration.onRowClick==`function`,o=this._mobileThumbnailColumn(),s=this._mobilePrimaryColumn(),c=this._mobileActionsDropdownColumn(),l=o?this._buildTableCellInnerHtml(o,e,i,`mobile`):``,u=s?this._buildTableCellInnerHtml(s,e,i,`mobile`):``,d=c?this._buildTableCellInnerHtml(c,e,i,`mobile`):``,f=[],p=this._configuration.mobileShowLabels===!0;for(let t of this._configuration.columns){if(t.hidden||o&&t===o||s&&t===s||c&&t===c)continue;let n=this._columnPlainSummaryText(t,e);if(n)if(p){let e=this._stripHtml(String(t.label||``)).trim();e?f.push(`${this._escapeHtml(e)}: ${this._escapeHtml(n)}`):f.push(this._escapeHtml(n))}else f.push(this._escapeHtml(n))}let m=f.join(`<span class="text-gray-300 dark:text-gray-600" aria-hidden="true"> · </span>`),h=[`list-none`,...r?[]:[`border-b`,`border-gray-200`,`dark:border-mint-divider`],`bg-white`,`dark:bg-mint-canvas`,a?`cursor-pointer hover:bg-gray-50 dark:hover:bg-mint-elevated`:``].filter(Boolean).join(` `),g=`<div class="flex items-center gap-3 py-3 pr-4${o?` pl-0`:` pl-4`}">`;if(o){let e=this._thumbnailMobilePx(o),t=`width:${e}px;height:${e}px;min-width:${e}px;min-height:${e}px`;g+=`<div class="flex shrink-0 items-stretch overflow-hidden rounded-md border border-gray-200 bg-gray-100 p-0 dark:border-mint-divider dark:bg-mint-hover [&>*]:m-0 [&>*]:min-h-0 [&>*]:min-w-0 [&>*]:w-full [&>*]:max-w-full [&>*]:p-0 [&>span]:flex [&>span]:h-full [&>span]:w-full [&>span]:min-h-0 [&>span]:min-w-0 [&>span]:items-stretch [&>span]:justify-stretch [&_img]:!m-0 [&_img]:!box-border [&_img]:!block [&_img]:!h-full [&_img]:!w-full [&_img]:!min-h-0 [&_img]:!min-w-0 [&_img]:!max-h-full [&_img]:!max-w-full [&_img]:!border-0 [&_img]:!p-0 [&_img]:!rounded-none [&_img]:!object-cover [&_img]:!object-center" style="${t}">${l}</div>`}g+=`<div class="flex min-w-0 flex-1 flex-col justify-center gap-1">`,g+=`<div class="flex items-start justify-between gap-2">`,g+=`<div class="min-w-0 text-sm font-semibold leading-snug text-gray-900 dark:text-white">${u}</div>`,d&&(g+=`<div class="shrink-0 -mr-1">${d}</div>`),g+=`</div>`,m&&(g+=`<div class="text-xs font-normal leading-snug text-gray-500 dark:text-gray-400">${m}</div>`),g+=`</div></div>`;let _=typeof n==`number`&&n>0?` style="box-sizing:border-box;min-height:${n}px;max-height:${n}px;height:${n}px;overflow:hidden"`:``;return`<li data-row-index="${i}" ${a?`data-row-clickable="true" `:``}class="${h}"${_}>${g}</li>`}_buildMobileListPlaceholderLi(e,t,n=!1){let r=this._mobileThumbnailColumn(),i=r?this._thumbnailMobilePx(r):56,a=`width:${i}px;height:${i}px;min-width:${i}px;min-height:${i}px`;return`<li data-row-index="${e}" data-mint-rt-placeholder="true" class="list-none${n?``:` border-b border-gray-200 dark:border-mint-divider`} bg-white dark:bg-mint-canvas" style="box-sizing:border-box;min-height:${t}px;max-height:${t}px;height:${t}px;overflow:hidden"><div class="flex h-full min-h-0 items-center gap-3 py-3 pl-0 pr-4"><div class="shrink-0 overflow-hidden rounded-md bg-gray-200 dark:bg-white/15" style="${a}"></div><div class="flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 py-0.5"><div class="h-4 w-40 rounded bg-gray-200 dark:bg-white/15"></div><div class="h-3 w-full max-w-xs rounded bg-gray-200 dark:bg-white/15"></div></div></div></li>`}_renderColgroupHtml(){if(!this._configuration)return``;let e=this._configuration.columns.filter(e=>!e.hidden),t=[],n=0;for(let r of e){let e=r.width==null?``:String(r.width).trim();e?/^\d+(\.\d+)?$/.test(e)?(n+=parseFloat(e),t.push(`px`)):t.push(`lit`):t.push(`flex`)}let r=t.filter(e=>e===`flex`).length,i=t.includes(`lit`),a=``;r>0&&!i&&(a=n>0?`width:calc((100% - ${n}px) / ${r});min-width:0`:`width:${100/r}%;min-width:0`);let o=`<colgroup>`;return e.forEach((e,n)=>{let r=e.width==null?``:String(e.width).trim(),i=t[n],s=``;i===`px`?s=` style="width:${r}px;min-width:0"`:i===`lit`?s=` style="width:${this._escapeHtml(r)};min-width:0"`:a&&(s=` style="${a}"`),o+=`<col${s} />`}),o+=`</colgroup>`,o}_buildDataRowHtml(e,t,n,r=!1){if(!this._configuration)return``;let i=t,a=n,o=`box-sizing:border-box;min-height:${a}px;max-height:${a}px;height:${a}px;overflow:hidden`,s=``,c=typeof this._configuration.onRowClick==`function`,l=c?`cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800`:``,u=c?` data-row-clickable="true"`:``,d=l?` class="${l}"`:``;return s+=`<tr data-row-index="${i}"${r?` data-mint-rt-last-row=""`:``}${u}${d} style="${o}">`,this._configuration.columns.forEach(t=>{if(t.hidden)return;let n=!t.show||t.show(this,e),r=`${this._getStyle(t)}box-sizing:border-box;max-height:${a}px;overflow:hidden;vertical-align:middle;`;s+=`<td style="${r}" class="${this._getClasses(t,!0)}">`,s+=n?this._buildTableCellInnerHtml(t,e,i):``,s+=`</td>`}),s+=`</tr>`,s}_getVirtualRowCount(){return!this._virtualScrollActive()||!this._configuration?0:this._type===`provided`?this._getAllFilteredRowsSorted().length:this._type===`ajax`?this._totalRows:0}_getVirtualRowAt(e){return this._type===`provided`?this._getAllFilteredRowsSorted()[e]??null:this._type===`ajax`&&this._virtualRowCache.has(e)?this._virtualRowCache.get(e):null}_buildVirtualPlaceholderRowHtml(e,t,n=!1){if(!this._configuration)return``;let r=t,i=`box-sizing:border-box;min-height:${r}px;max-height:${r}px;height:${r}px;overflow:hidden`,a=`<tr data-row-index="${e}" data-mint-rt-placeholder="true"${n?` data-mint-rt-last-row=""`:``} class="bg-white dark:bg-mint-canvas" style="${i}">`;return this._configuration.columns.forEach(e=>{if(e.hidden)return;let t=`${this._getStyle(e)}box-sizing:border-box;max-height:${r}px;height:${r}px;overflow:hidden;vertical-align:middle;line-height:0;`;if(a+=`<td style="${t}" class="${this._getClasses(e,!0)}">`,e.thumbnail){let t=this._thumbnailDesktopPx(e);a+=`<div class="rounded-md bg-gray-200 dark:bg-white/15" style="width:${t}px;height:${t}px;max-width:100%;box-sizing:border-box"></div>`}else a+=`<div class="h-4 max-w-[95%] rounded bg-gray-200 dark:bg-white/15"></div>`;a+=`</td>`}),a+=`</tr>`,a}_virtualScrollStickyOverlapPx(e){let t=0;if(this._fixedControls()){let e=this.querySelector(`#mint-rt-fixed-controls-${this._tableId}`);if(e)t+=Math.ceil(e.getBoundingClientRect().height);else{let e=getComputedStyle(this).getPropertyValue(`--mint-rt-fixed-controls-h`).trim(),n=parseFloat(e);isNaN(n)||(t+=Math.ceil(n))}}if(this._fixedHeader()&&e){let n=e.querySelector(`thead`);n&&(t+=Math.ceil(n.getBoundingClientRect().height))}return t}_scrollVirtualTableTopIntoView(){if(!(!this._virtualScrollActive()||!this.isConnected)){if(this._virtualScrollRoot()===`table-body`){let e=this._virtualBodyScrollEl?.isConnected?this._virtualBodyScrollEl:this.querySelector(`#mint-rt-vscroll-${this._tableId}`);this._useMobileListLayout()&&e&&e.querySelector(`ul[data-mint-rt-mobile-list="${this._tableId}"]`);let t=e?.querySelector(`mint-table.table-section`)||e?.querySelector(`mint-table`),n=t?.querySelector(`#${this._tableId}`)?.closest(`table`)||t?.querySelector(`table`);this._virtualScrollStickyOverlapPx(n),e&&(e.scrollTop=0,this._virtualBodyScrollEl=e,this._virtualInvalidate(),this._scheduleVirtualWindowSync());return}this._virtualInvalidate(),this._scheduleVirtualWindowSync()}}_scheduleVirtualWindowSync(){this._virtualScrollActive()&&this._virtualWindowRaf===null&&(this._virtualWindowRaf=window.requestAnimationFrame(()=>{this._virtualWindowRaf=null,this._syncVirtualWindow()}))}_syncVirtualWindow(){if(!this._virtualScrollActive()||!this._configuration)return;let e=this._useMobileListLayout(),t=this.querySelector(`tbody[data-mint-rt-tbody="${this._tableId}"]`),n=this.querySelector(`ul[data-mint-rt-mobile-list="${this._tableId}"]`),r=e?n:t;if(!r)return;let i=this._getVirtualRowCount(),a=this._virtualRowHeightPxForSync(e),o=this._virtualColspan();if(i===0){e?this._fetchError?r.innerHTML=`<li class="list-none px-4 py-8 text-center text-sm text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</li>`:r.innerHTML=`<li class="list-none px-4 py-8 text-center text-sm">No records found.</li>`:this._fetchError?r.innerHTML=`<tr><td colspan="${o}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`:r.innerHTML=`<tr><td colspan="${o}" class="text-center py-8">No records found.</td></tr>`,this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``;return}let s=0,c=window.innerHeight;if(this._virtualScrollRoot()===`table-body`){let e=this._virtualBodyScrollEl;if((!e||!e.isConnected)&&(e=this.querySelector(`#mint-rt-vscroll-${this._tableId}`),this._virtualBodyScrollEl=e),!e)return;s=e.scrollTop,c=e.clientHeight||400}else{let e=r.getBoundingClientRect();s=Math.max(0,-e.top)}let l=Math.min(Math.max(0,Math.floor(s/a)),Math.max(0,i-1)),u=Math.ceil(c/a)+16,d=Math.max(0,l-8),f=Math.min(i,l+u),p=``;if(this._type===`ajax`)for(let e=d;e<f;e++)p+=this._virtualRowCache.has(e)?`1`:`0`;if(d===this._virtualLastRangeStart&&f===this._virtualLastRangeEnd&&(this._type!==`ajax`||p===this._virtualLastRangeCacheSig))return;this._virtualLastRangeStart=d,this._virtualLastRangeEnd=f,this._virtualLastRangeCacheSig=p;let m=d*a,h=Math.max(0,(i-f)*a),g=``;if(e){g+=`<li aria-hidden="true" class="pointer-events-none m-0 block list-none border-0 p-0" style="height:${m}px"></li>`;for(let e=d;e<f;e++){let t=this._getVirtualRowAt(e),n=i>0&&e===i-1;t?g+=this._buildMobileListItemHtml(t,e,a,n):g+=this._buildMobileListPlaceholderLi(e,a,n)}g+=`<li aria-hidden="true" class="pointer-events-none m-0 block list-none border-0 p-0" style="height:${h}px"></li>`}else{g+=`<tr data-mint-rt-spacer="top" aria-hidden="true"><td colspan="${o}" style="height:${m}px;padding:0;border:0;line-height:0;font-size:0"></td></tr>`;for(let e=d;e<f;e++){let t=this._getVirtualRowAt(e),n=i>0&&e===i-1;t?g+=this._buildDataRowHtml(t,e,a,n):g+=this._buildVirtualPlaceholderRowHtml(e,a,n)}g+=`<tr data-mint-rt-spacer="bottom" aria-hidden="true"><td colspan="${o}" style="height:${h}px;padding:0;border:0;line-height:0;font-size:0"></td></tr>`}if(r.innerHTML=g,this.querySelectorAll(`tbody[data-mint-rt-tbody="${this._tableId}"] mint-button[data-action], ul[data-mint-rt-mobile-list="${this._tableId}"] mint-button[data-action]`).forEach(e=>{e.render&&e.render()}),this._attachTableEventListeners(),this._attachRowClickHandler(),this._type===`ajax`&&this._virtualScrollActive()&&this._scheduleVirtualAjaxPrefetch(d,f),this._virtualScrollRoot()===`table-body`&&!e){let e=this._virtualBodyScrollEl;e?.isConnected&&requestAnimationFrame(()=>{if(!e.isConnected)return;let t=Math.max(0,e.scrollHeight-e.clientHeight);e.scrollTop>t&&(e.scrollTop=t)})}}_detachVirtualScroll(){this._virtualScrollHandler&&=(window.removeEventListener(`scroll`,this._virtualScrollHandler),this._virtualBodyScrollEl?.removeEventListener(`scroll`,this._virtualScrollHandler),null),this._virtualWindowResizeHandler&&=(window.removeEventListener(`resize`,this._virtualWindowResizeHandler),null),this._virtualResizeObserver&&=(this._virtualResizeObserver.disconnect(),null),this._virtualBodyScrollEl=null,this._virtualWindowRaf!==null&&(window.cancelAnimationFrame(this._virtualWindowRaf),this._virtualWindowRaf=null),this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``,this._virtualAjaxPrefetchTimer!==null&&(window.clearTimeout(this._virtualAjaxPrefetchTimer),this._virtualAjaxPrefetchTimer=null),this._virtualRangeFetching=!1}_scheduleVirtualAjaxPrefetch(e,t){if(this._type!==`ajax`||!this._virtualScrollActive()||!this._configuration)return;let n=!1;for(let r=e;r<t;r++)if(!this._virtualRowCache.has(r)){n=!0;break}if(!n)return;this._virtualAjaxPrefetchTimer!==null&&window.clearTimeout(this._virtualAjaxPrefetchTimer);let r=e,i=t;this._virtualAjaxPrefetchTimer=window.setTimeout(()=>{this._virtualAjaxPrefetchTimer=null,this._fetchVirtualAjaxRange(r,i-r)},60)}async _fetchVirtualAjaxRange(e,t){if(!this._configuration||this._type!==`ajax`||!this._virtualScrollActive())return;let n=typeof this._configuration.data==`string`?this._configuration.data:null;if(!n||t<=0||this._virtualRangeFetching||e<0||e>=this._totalRows)return;this._virtualRangeFetching=!0;let r=this._virtualFetchGeneration,i=Math.min(e,Math.max(0,this._totalRows-1)),a=Math.min(150,Math.max(this._perPage,t,15),Math.max(1,this._totalRows-i));try{let e=new URLSearchParams({perPage:a.toString(),offset:i.toString(),search:this._search,sortBy:this._configuration.sortBy||`id`,sort:this._configuration.sort||`asc`,searchColumns:this._searchColumns.join(`,`),columns:this._columns.join(`,`)}),t={};this._configuration.headers&&(t.headers=this._configuration.headers);let o=await fetch(`${n}?${e.toString()}`,t);if(!o.ok)throw Error(`HTTP error! status: ${o.status}`);let s=await o.json();if(r!==this._virtualFetchGeneration)return;(s.content?.rows||[]).forEach((e,t)=>{let n=i+t;n<this._totalRows&&this._virtualRowCache.set(n,e)})}catch(e){console.error(`mint-resource-table: virtual range fetch failed`,e)}finally{this._virtualRangeFetching=!1,r===this._virtualFetchGeneration&&(this._virtualInvalidate(),this._scheduleVirtualWindowSync())}}_detachFixedChromeResize(){this._fixedChromeResizeObserver?.disconnect(),this._fixedChromeResizeObserver=null,this.style.removeProperty(`--mint-rt-fixed-controls-h`)}_syncFixedControlsChromeHeight(){if(!this._fixedHeader()||!this._fixedControls())return;this._fixedChromeResizeObserver?.disconnect(),this._fixedChromeResizeObserver=null;let e=this.querySelector(`#mint-rt-fixed-controls-${this._tableId}`);if(!e)return;let t=()=>{let t=Math.ceil(e.getBoundingClientRect().height);this.style.setProperty(`--mint-rt-fixed-controls-h`,`${t}px`)};t(),this._fixedChromeResizeObserver=new ResizeObserver(t),this._fixedChromeResizeObserver.observe(e)}_attachVirtualScrollListeners(){if(this._detachVirtualScroll(),!this._virtualScrollActive())return;let e=()=>{this._scheduleVirtualWindowSync()};this._virtualScrollHandler=e,this._virtualScrollRoot()===`table-body`?(this._virtualBodyScrollEl=this.querySelector(`#mint-rt-vscroll-${this._tableId}`),this._virtualBodyScrollEl?.addEventListener(`scroll`,e,{passive:!0}),this._virtualBodyScrollEl&&typeof ResizeObserver<`u`&&(this._virtualResizeObserver=new ResizeObserver(()=>this._scheduleVirtualWindowSync()),this._virtualResizeObserver.observe(this._virtualBodyScrollEl))):window.addEventListener(`scroll`,e,{passive:!0}),this._virtualWindowResizeHandler=()=>this._scheduleVirtualWindowSync(),window.addEventListener(`resize`,this._virtualWindowResizeHandler,{passive:!0}),this._scheduleVirtualWindowSync()}_toggleSort(e){if(!this._configuration||!e.data||!e.sortable)return;let t=e.data;if(this._sortTimeoutId!==null&&(clearTimeout(this._sortTimeoutId),this._sortTimeoutId=null),this._sorting=!0,this._sortingColumn=e,this._updateSortIcons(),this._type===`ajax`)this._sortTimeoutId=window.setTimeout(()=>{if(this._sortTimeoutId=null,!this._configuration||!t||!e.sortable)return;let n=this._configuration.sort||`asc`;this._configuration.sortBy?.toLowerCase()===t.toLowerCase()&&(n=n===`desc`?`asc`:`desc`),this._configuration.sort=n,this._configuration.sortBy=t,this._updateSortIcons(),this._offset=0,this._currentPage=1,this._fetching=!1,this._loading=!1,this._fetchData(void 0,!1,this._perPage,0)},10);else{let e=this._configuration.sort||`asc`;this._configuration.sortBy?.toLowerCase()===t.toLowerCase()&&(e=e===`desc`?`asc`:`desc`),this._configuration.sort=e,this._configuration.sortBy=t,this._currentPage=1,this._sorting=!1,this._sortingColumn=null,this._updateSortIcons(),this.render(),this._virtualScrollActive()&&queueMicrotask(()=>this._scrollVirtualTableTopIntoView())}}_getSortClass(e){return this._sorting&&this._sortingColumn===e?`spinner`:this._configuration?.sortBy?.toLowerCase()===e.data?.toLowerCase()?this._configuration?.sort?.toLowerCase()===`desc`?`caret-down`:`caret-up`:``}_updateSortIcons(){if(!this._configuration)return;this._configuration.columns.forEach((e,t)=>{if(!e.sortable||e.hidden)return;let n=this.querySelector(`th[data-column-key="${t}"]`);if(!n)return;let r=n.querySelector(`:scope > div.flex.items-center`);if(!r)return;let i=r.querySelector(`:scope > div.ml-2.flex.items-center`),a=this._getSortClass(e),o=()=>{if(!i){let e=document.createElement(`div`);e.className=`ml-2 flex items-center`,r.appendChild(e),i=e}return i},s=()=>{i&&=(i.remove(),null)};if(a===`spinner`){let e=o();if(e.querySelector(`mint-icon`)?.remove(),!e.querySelector(`mint-spinner`)){let t=document.createElement(`mint-spinner`);t.className=`w-4 h-4`,e.appendChild(t)}}else if(a===`caret-up`||a===`caret-down`){let e=o();e.querySelector(`mint-spinner`)?.remove();let t=e.querySelector(`mint-icon`);t||(t=document.createElement(`mint-icon`),e.appendChild(t)),t.setAttribute(`name`,a),t.className=`w-4 h-4`}else s()}),this._syncMobileSortPopoverIcons();let e=this.querySelector(`#mint-rt-mobile-sort-btn-${this._tableId}`);e&&(e.setAttribute(`icon`,this._getMobileSortTriggerIconName()),this._sorting?e.setAttribute(`loading`,`true`):e.removeAttribute(`loading`),typeof e.render==`function`&&e.render())}_showFetchingState(){}_triggerSearch(){this._searchTimeoutId&&clearTimeout(this._searchTimeoutId),this._searching=!0,this._type===`ajax`&&this._updateSearchIcon(),this._type!==`ajax`&&(this._currentPage=1),this._updateTableBody(),this._type!==`ajax`&&this._updatePagination(),this._searchTimeoutId=window.setTimeout(()=>{this._type===`ajax`?(this._offset=0,this._fetchData(void 0,!1,this._perPage,0)):(this._searching=!1,this._virtualScrollActive()&&queueMicrotask(()=>this._scrollVirtualTableTopIntoView()))},400)}_updateSearchIcon(){let e=this.querySelector(`#search-${this._tableId}`);if(!e)return;let t=this._type===`ajax`&&(this._searching||this._fetching);setTimeout(()=>{let n=e.querySelector(`.relative`)||e.querySelector(`div`);if(!n)return;let r=n.querySelector(`mint-icon`),i=n.querySelector(`mint-spinner`);if(t){if(r&&!i){let e=document.createElement(`mint-spinner`);e.className=`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none`,r.replaceWith(e)}else if(!r&&!i){let e=document.createElement(`mint-spinner`);e.className=`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none`,n.appendChild(e)}}else if(i){e.getAttribute(`icon`)||e.setAttribute(`icon`,`search`);let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`search`),t.className=`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400 dark:text-gray-500 pointer-events-none`,i.replaceWith(t)}},0)}_updateTableBody(){if(!this._configuration)return;let e=this.querySelector(`tbody[data-mint-rt-tbody="${this._tableId}"]`),t=this.querySelector(`#${this._tableId}`)?.closest(`table`)?.querySelector(`tbody`);if(this._virtualScrollActive()&&(this._type===`provided`||this._type===`ajax`)){if(!(e||t)){this.render();return}let n=this.querySelector(`#search-${this._tableId}`),r=document.activeElement===n||n?.querySelector(`input`)===document.activeElement,i=this._search;if((this._fetching||this._loading)&&!this._loaded&&!this._sorting)return;if(this._virtualInvalidate(),this._syncVirtualWindow(),r&&n){let e=n.querySelector(`input`)||n._element;e?(e.value=i,setTimeout(()=>{e.focus(),e.setSelectionRange(i.length,i.length)},0)):n.value!==void 0&&(n.value=i,setTimeout(()=>{n.focus()},0))}return}let n=this._getRows(),r=t;if(!r){this.render();return}let i=this.querySelector(`#search-${this._tableId}`),a=document.activeElement===i||i?.querySelector(`input`)===document.activeElement,o=this._search,s=``,c=``;if((this._fetching||this._loading)&&!this._loaded&&!this._sorting)return;n.forEach((e,t)=>{c+=this._buildMobileListItemHtml(e,t,void 0,t===n.length-1);let r=typeof this._configuration.onRowClick==`function`,i=r?`cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800`:``;s+=`<tr data-row-index="${t}" ${r?`data-row-clickable="true"`:``}${i?` class="${i}"`:``}>`,this._configuration.columns.forEach(n=>{if(n.hidden)return;let r=!n.show||n.show(this,e);s+=`<td style="${this._getStyle(n)}" class="${this._getClasses(n,!0)}">`,r&&(s+=this._buildTableCellInnerHtml(n,e,t,`table`)),s+=`</td>`}),s+=`</tr>`}),n.length===0&&(this._fetchError?(s+=`<tr><td colspan="${this._configuration.columns.filter(e=>!e.hidden).length}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`,c+=`<li class="list-none px-4 py-8 text-center text-sm text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</li>`):(s+=`<tr><td colspan="${this._configuration.columns.filter(e=>!e.hidden).length}" class="text-center py-8">No records found.</td></tr>`,c+=`<li class="list-none px-4 py-8 text-center text-sm">No records found.</li>`)),r.innerHTML=s;let l=this.querySelector(`ul[data-mint-rt-mobile-list="${this._tableId}"]`);if(l&&(l.innerHTML=c),this._attachTableEventListeners(),this._attachRowClickHandler(),a&&i){let e=i.querySelector(`input`)||i._element;e?(e.value=o,setTimeout(()=>{e.focus(),e.setSelectionRange(o.length,o.length)},0)):i.value!==void 0&&(i.value=o,setTimeout(()=>{i.focus()},0))}}_updatePagination(){if(!this._configuration)return;let e=this._lastPage||Math.ceil(this._rows.length/this._perPage),t=()=>{let e=this.querySelector(`mint-table`),t=e?.nextElementSibling;e&&t&&t.id!==`mint-rt-pagination-host-${this._tableId}`&&!t.classList.contains(`mint-rt-pagination-host`)&&t.querySelector?.(`[data-action="page"]`)&&t.remove()};if(!this._configuration.perPage||e<=1||this._virtualScrollActive()){this._getPaginationHostEl()?.replaceChildren(),t();return}let n=this._getPaginationHostEl();if(!n){let e=this.querySelector(`[data-mint-rt-mobile-list="${this._tableId}"]`)||this.querySelector(`mint-table`);if(!e){this.render();return}n=document.createElement(`div`),n.id=`mint-rt-pagination-host-${this._tableId}`,n.setAttribute(`data-mint-rt-pagination-wrap`,``),n.className=`mint-rt-pagination-host w-full min-w-0 overflow-x-auto overflow-y-hidden overscroll-x-contain flex justify-center [-webkit-overflow-scrolling:touch] md:justify-end `+(this._inMintCard?`border-t border-gray-200 px-3.5 pb-3.5 pt-3 dark:border-mint-divider md:border-t-0 md:pt-0`:`border-t border-gray-200 px-2 py-3 dark:border-mint-divider md:border-t-0 md:py-0 md:mt-4`),e.insertAdjacentElement(`afterend`,n)}let r=this._buildPaginationNavMarkup(e);n.innerHTML=r,setTimeout(()=>{this._attachPaginationListeners(),n.querySelectorAll(`mint-button[data-action="page"]`).forEach(e=>{let t=e.getAttribute(`data-page`),n=t&&this._loadingPage===parseInt(t),r=e._button||e.querySelector(`button`);if(r)if(n){let e=[],t=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,null),n;for(;n=t.nextNode();)e.push(n);e.forEach(e=>e.parentNode?.removeChild(e));let i=r.querySelector(`.mint-button-content`);if(i){let e=i.textContent?.trim();e&&/^\d+$/.test(e)&&i.remove()}let a=r.querySelector(`span.mr-2`);a&&a.querySelector(`mint-spinner`)&&(a.classList.remove(`mr-2`),a.classList.add(`mr-0`))}else{let e=r.textContent?.trim();if(!e||!/^\d+$/.test(e)){let e=t||``,n=r.querySelector(`mint-spinner`);r.innerHTML=``,n&&r.appendChild(n),r.appendChild(document.createTextNode(e))}}if(`render`in e&&typeof e.render==`function`&&(e.render(),n&&r)){let e=r.querySelector(`span.mr-2`);e&&e.querySelector(`mint-spinner`)&&(e.classList.remove(`mr-2`),e.classList.add(`mr-0`))}}),n.querySelectorAll(`mint-button[data-action="page-prev"], mint-button[data-action="page-next"]`).forEach(e=>{`render`in e&&typeof e.render==`function`&&e.render()}),this._loadingPage!==null&&!this._loading&&!this._fetching&&this._updatePagination()},0)}_goToPage(e){let t=this._lastPage||Math.ceil(this._rows.length/this._perPage);e>t&&(e=t),e<1&&(e=1),e!==this._currentPage&&(this._currentPage=e,this._offset=(e-1)*this._perPage,this._updatePageInUrl(e),this._type===`ajax`?(this._loadingPage=e,this._updatePagination(),this._fetchData()):this.render())}_handleButtonClick(e){if(this._configuration)switch(e.type){case`export`:break;case`print`:window.print();break;case`csv`:this._downloadCSV();break;default:e.onClick&&e.onClick(this);break}}_downloadCSV(){if(!this._configuration)return;let e=this.querySelector(`#${this._tableId}`)||this.querySelector(`table`);if(!e)return;let t=`data:text/csv;charset=utf-8,`,n=e=>{let n=[];e.querySelectorAll(`th, td`).forEach(e=>{let t=e.getAttribute(`colspan`);if(t)for(let e=0;e<parseInt(t,10)-1;e++)n.push(``);n.push(`"`+e.textContent?.trim().replace(/"/g,`""`)+`"`)}),t+=n.join(`,`)+`
|
|
83
|
-
`};e.querySelectorAll(`tr`).forEach(e=>n(e));let r=encodeURI(t),i=document.createElement(`a`);i.setAttribute(`href`,r),i.setAttribute(`download`,`${this._configuration.export_name||this._tableId}.csv`),document.body.appendChild(i),i.click(),document.body.removeChild(i)}_getStyle(e){let t=``;return(e.nowrap||e.actions)&&(t+=`white-space: nowrap;`),e.offsetLeft&&(t+=`left: ${e.offsetLeft} !important;`),e.offsetRight&&(t+=`right: ${e.offsetRight} !important;`),e.width&&(t+=`min-width: ${e.width}px; max-width: ${e.width}px;`),t}_getClasses(e,t=!1){let n=[];return e.class&&n.push(e.class.trim()),e.sortable&&!t&&n.push(`cursor-pointer`),e.stickLeft&&n.push(`sticky-left`),e.stickRight&&n.push(`sticky-right`),n.join(` `)}_renderTheadHtml(e,t,n=!1,r=!1){if(!this._configuration)return``;let i=[`bg-white`,`dark:bg-mint-nav`];e&&(i.push(`sticky`,`z-30`),r?i.push(`top-[var(--mint-rt-fixed-controls-h,0px)]`):i.push(`top-0`)),t&&i.push(`border-b`,`border-gray-200`,`dark:border-mint-divider`);let a=`<thead class="${i.join(` `)}"><tr>`;return this._configuration.columns.forEach((e,t)=>{if(e.hidden)return;let r=n?``:` width="${e.width||``}"`,i=e.sortable?` data-mint-rt-sortable=""`:``;if(a+=`<th${r} style="${this._getStyle(e)}" class="${this._getClasses(e)}" data-column-key="${t}"${i}>`,e.showLabel!==!1){if(a+=`<div class="flex items-center">`,a+=`<div class="flex-1">${e.raw?e.label:this._escapeHtml(e.label)}</div>`,e.sortable){let t=this._getSortClass(e);t===`spinner`?a+=`<div class="ml-2 flex items-center"><mint-spinner class="w-4 h-4"></mint-spinner></div>`:(t===`caret-up`||t===`caret-down`)&&(a+=`<div class="ml-2 flex items-center"><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`)}a+=`</div>`}a+=`</th>`}),a+=`</tr></thead>`,a}render(){if(!this._configuration){this.innerHTML=`<div class="p-4 text-red-500">Error: Invalid configuration</div>`;return}this._ensureMobileListMql();let e=String(this._configuration.id||``).trim();e&&(this.id=e),this._detachVirtualScroll(),this._detachFixedChromeResize(),this._virtualScrollActive()||this._virtualRowCache.clear();let t=!this._loaded||this._rows.length>0||this._search.length>0||this._searching,n=this._getRows();this._lastPage||Math.ceil(this._rows.length/this._perPage);let r=this._isExternalLoading(),i=``;if(t){let e=this._fixedControls(),t=[`flex`,`items-center`,`min-w-0`,this._inMintCard?`p-3.5`:`mb-3`,e?`sticky top-0 z-20 bg-white dark:bg-mint-nav border-b border-gray-200 dark:border-mint-divider`:``].filter(Boolean).join(` `);if(i+=`<div id="mint-rt-fixed-controls-${this._tableId}" class="${t}">`,i+=`<div class="flex min-w-0 flex-1 items-center gap-2">`,i+=this._buildMobileSortToolbarHtml(),this._configuration.showSearch!==!1){let e=`search-${this._tableId}`,t=this._escapeHtml(this._configuration.searchPlaceholder||`Search...`);i+=`<mint-input id="${e}" type="search" label="" placeholder="${t}" class="min-w-0 flex-1" icon="search" value="${this._escapeHtml(this._search)}"></mint-input>`}i+=`<div class="hidden shrink-0 items-center gap-2 md:flex">`,this._configuration.buttons&&this._configuration.buttons.forEach(e=>{let t=e.icon?` icon="${this._escapeHtml(e.icon)}"`:``,n=e.tone?` tone="${this._escapeHtml(e.tone)}"`:``;i+=`<mint-button variant="solid" class="${e.class||``}" data-button-type="${e.type||`custom`}"${t}${n}>`,e.label&&(i+=this._escapeHtml(e.label)),i+=`</mint-button>`}),i+=`</div>`,i+=`</div>`,i+=`</div>`}if((this._type===`ajax`&&!this._loaded||this._type===`provided`&&r)&&!this._fetchError&&!this._sorting){let e=this._fixedHeader()?` data-mint-rt-scroll-inner=""`:``,t=this._fixedHeader()&&this._fixedControls(),n=this._fixedHeader()?t?`sticky top-[var(--mint-rt-fixed-controls-h,0px)] z-30 `:`sticky top-0 z-30 `:`sticky top-0 z-10 `;i+=`<div class="min-w-0">`,i+=`<mint-table class="table-section`+(this._inMintCard?` rounded-t-none`:``)+`"`+e+`>`,i+=`<table id="${this._tableId}">`,i+=`<thead class="`+n+`bg-white dark:bg-mint-nav border-b border-gray-200 dark:border-mint-divider"><tr>`,this._configuration.columns.forEach((e,t)=>{if(e.hidden)return;let n=e.sortable?` data-mint-rt-sortable=""`:``;if(i+=`<th width="${e.width||``}" style="${this._getStyle(e)}" class="${this._getClasses(e)}" data-column-key="${t}"${n}>`,e.showLabel!==!1){if(i+=`<div class="flex items-center">`,i+=`<div class="flex-1">${e.raw?e.label:this._escapeHtml(e.label)}</div>`,e.sortable){let t=this._getSortClass(e);t===`spinner`?i+=`<div class="ml-2 flex items-center"><mint-spinner class="w-4 h-4"></mint-spinner></div>`:(t===`caret-up`||t===`caret-down`)&&(i+=`<div class="ml-2 flex items-center"><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`)}i+=`</div>`}i+=`</th>`}),i+=`</tr></thead>`,i+=`<tbody>`;for(let e=0;e<4;e++)i+=`<tr>`,this._configuration.columns.forEach(e=>{if(!e.hidden){if(i+=`<td style="${this._getStyle(e)}" class="${this._getClasses(e,!0)}">`,e.thumbnail){let t=this._thumbnailDesktopPx(e);i+=`<div class="rounded-md bg-gray-200 dark:bg-white/15 animate-pulse" style="width:${t}px;height:${t}px;box-sizing:border-box"></div>`}else i+=`<div class="h-4 max-w-[95%] rounded bg-gray-200 dark:bg-white/15 animate-pulse"></div>`;i+=`</td>`}}),i+=`</tr>`;i+=`</tbody>`,i+=`</table>`,i+=`</mint-table>`,i+=`</div>`,i+=this._paginationHostPlaceholderHtml()}else if(n.length>0||this._search.length>0||this._searching||this._fetchError){let e=this._virtualScrollActive()&&(this._type===`provided`||this._type===`ajax`&&this._loaded&&!this._fetchError),t=e&&this._virtualScrollRoot()===`table-body`,a=this._escapeHtml(this._virtualMaxHeightCss()),o=t||this._fixedHeader(),s=this._fixedHeader()&&this._fixedControls(),c=o?` data-mint-rt-scroll-inner=""`:``,l=`table-section`+(this._inMintCard?` rounded-t-none`:``),u=`m-0 min-h-0 w-full list-none border-collapse overflow-x-hidden bg-white ${this._inMintCard?`px-3.5 py-3.5`:`py-3`} dark:bg-mint-canvas md:hidden`,d=``;if(t){let e=this._renderColgroupHtml();i+=`<div id="mint-rt-vscroll-${this._tableId}" class="overflow-y-auto overflow-x-auto min-h-0 w-full" style="max-height: ${a}; scrollbar-gutter: stable; overscroll-behavior-x: contain; overscroll-behavior-y: none; overflow-anchor: none;">`,i+=`<div class="hidden min-h-0 min-w-0 md:block">`,i+=`<mint-table class="${l}"${c}>`,i+=`<table id="${this._tableId}" class="w-full min-w-0 table-fixed">`,i+=e,i+=this._renderTheadHtml(!0,!0,!0,s)}else i+=`<div class="hidden min-h-0 min-w-0 md:block">`,i+=`<mint-table class="${l}"${c}>`,i+=`<table id="${this._tableId}">`,e&&(i+=this._renderColgroupHtml()),i+=this._renderTheadHtml(!0,!0,!!e,s);if(i+=`<tbody`+(e?` data-mint-rt-tbody="${this._tableId}"`:``)+`>`,!this._fetching&&!this._loading&&!r&&!e&&n.forEach((e,t)=>{d+=this._buildMobileListItemHtml(e,t,void 0,t===n.length-1);let r=typeof this._configuration.onRowClick==`function`,a=r?`cursor-pointer hover:bg-gray-50 dark:hover:bg-mint-elevated`:``;i+=`<tr data-row-index="${t}" ${r?`data-row-clickable="true"`:``}${a?` class="${a}"`:``}>`,this._configuration.columns.forEach(n=>{if(n.hidden)return;let r=!n.show||n.show(this,e);i+=`<td style="${this._getStyle(n)}" class="${this._getClasses(n,!0)}">`,r&&(i+=this._buildTableCellInnerHtml(n,e,t,`table`)),i+=`</td>`}),i+=`</tr>`}),!this._fetching&&!this._loading&&!r&&n.length===0&&!e)if(this._fetchError){let e=this._configuration.columns.filter(e=>!e.hidden).length;i+=`<tr><td colspan="${e}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`,d+=`<li class="list-none px-4 py-8 text-center text-sm text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</li>`}else{let e=this._configuration.columns.filter(e=>!e.hidden).length;i+=`<tr><td colspan="${e}" class="text-center py-8">No records found.</td></tr>`,d+=`<li class="list-none px-4 py-8 text-center text-sm">No records found.</li>`}i+=`</tbody>`,i+=`</table>`,i+=`</mint-table>`,i+=`</div>`,i+=`<ul class="${u}" data-mint-rt-mobile-list="${this._tableId}">${e?``:d}</ul>`,e||(i+=this._paginationHostPlaceholderHtml()),t&&(i+=`</div>`)}else i+=`<slot name="empty"></slot>`;this._fixedHeader()?this.setAttribute(`data-mint-rt-fixed-header`,``):this.removeAttribute(`data-mint-rt-fixed-header`),this._fixedControls()?this.setAttribute(`data-mint-rt-fixed-controls`,``):this.removeAttribute(`data-mint-rt-fixed-controls`),this.innerHTML=i,this._updatePagination(),this.querySelectorAll(`mint-button[data-action]`).forEach(e=>{e.render&&e.render()}),this.querySelectorAll(`mint-button[data-mint-rt-toolbar]`).forEach(e=>{e.render&&e.render()}),this.querySelectorAll(`mint-button[data-button-type]`).forEach(e=>{e.render&&e.render()}),this._attachEventListeners(),this._type===`ajax`&&!this._loaded&&!this._fetching&&!this._loading&&this._fetchData()}_attachRowClickHandler(){this._rowClickHandler&&this.removeEventListener(`click`,this._rowClickHandler,!0);let e=e=>{let t=e.target;if(t.tagName===`MINT-BUTTON`||t.tagName===`BUTTON`||t.closest(`mint-button`)||t.closest(`button`)||t.closest(`mint-popover`)||t.closest(`[data-action]`))return;let n=t.closest(`tr[data-row-clickable="true"]`)||t.closest(`li[data-row-clickable="true"]`);if(!n)return;let r=n.getAttribute(`data-row-index`);if(!r)return;let i=parseInt(r),a=this._getRowDataForEventIndex(i);!a||!this._configuration?.onRowClick||(this._configuration.onRowClick.length===1?this._configuration.onRowClick(a):this._configuration.onRowClick(this,a))};this.addEventListener(`click`,e,!0),this._rowClickHandler=e}_attachPaginationListeners(){this.querySelectorAll(`[data-action="page"]`).forEach(e=>{e.addEventListener(`click`,()=>{if(e.getAttribute(`active`)===`true`)return;let t=parseInt(e.getAttribute(`data-page`)||`1`);t!==this._currentPage&&this._goToPage(t)})}),this.querySelectorAll(`[data-action="page-prev"]`).forEach(e=>{e.addEventListener(`click`,()=>{this._goToPage(this._currentPage-1)})}),this.querySelectorAll(`[data-action="page-next"]`).forEach(e=>{e.addEventListener(`click`,()=>{this._goToPage(this._currentPage+1)})})}_attachTableEventListeners(){this.querySelectorAll(`[data-action="row-action"]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=parseInt(e.getAttribute(`data-row-index`)||`0`),n=parseInt(e.getAttribute(`data-action-index`)||`0`),r=parseInt(e.getAttribute(`data-column-key`)||`0`),i=this._getRowDataForEventIndex(t),a=this._configuration?.columns[r];a&&a.actions&&a.actions[n]&&i!==void 0&&a.actions[n].onClick(this,i)})}),this.querySelectorAll(`[data-action="column-action"]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=parseInt(e.getAttribute(`data-row-index`)||`0`),n=parseInt(e.getAttribute(`data-column-key`)||`0`),r=this._getRowDataForEventIndex(t),i=this._configuration?.columns[n];i&&i.action&&r!==void 0&&i.action.onClick(this,r)})})}_attachEventListeners(){let e=this.querySelector(`#search-${this._tableId}`);if(e){let t=e.querySelector(`input`)||e._element;t?t.addEventListener(`input`,e=>{this._search=e.target.value,this._triggerSearch()}):e.addEventListener(`input`,t=>{this._search=e.value||t.target.value||``,this._triggerSearch()})}this._attachTableEventListeners(),this._attachRowClickHandler(),this.querySelectorAll(`th[data-column-key]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=parseInt(e.getAttribute(`data-column-key`)||`0`),n=this._configuration?.columns[t];n&&this._toggleSort(n)})}),this.querySelectorAll(`[data-action="mobile-sort"]`).forEach(e=>{e.addEventListener(`click`,t=>{t.stopPropagation();let n=parseInt(e.getAttribute(`data-column-key`)||`0`,10),r=this._configuration?.columns[n];r&&(this._closeMobileSortPopover(),this._toggleSort(r))})}),this.querySelectorAll(`[data-button-type]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=e.getAttribute(`data-button-type`),n=this._configuration?.buttons?.find(e=>(e.type||`custom`)===t);n&&this._handleButtonClick(n)})}),this._attachPaginationListeners(),this._virtualScrollActive()&&(this._type===`provided`||this._type===`ajax`)&&this._attachVirtualScrollListeners(),this._fixedHeader()&&this._fixedControls()&&queueMicrotask(()=>{this._syncFixedControlsChromeHeight(),requestAnimationFrame(()=>this._syncFixedControlsChromeHeight())})}_escapeHtml(e){let t=document.createElement(`div`);return t.textContent=e,t.innerHTML}_getPageFromUrl(){if(!this._tableId)return null;let e=new URLSearchParams(window.location.search).get(`mui.${this._tableId}`);if(!e)return null;let t=parseInt(e,10);return isNaN(t)||t<1?null:t}_updatePageInUrl(e){if(!this._tableId)return;let t=new URL(window.location.href),n=t.searchParams;n.set(`mui.${this._tableId}`,e.toString()),e===1&&n.set(`mui.${this._tableId}`,`1`),window.history.replaceState({},``,t.toString())}_loadPageFromUrl(){if(!this._configuration||!this._tableId)return;let e=this._getPageFromUrl();e!==null&&(this._currentPage=e,this._offset=(this._currentPage-1)*this._perPage)}};customElements.get(`mint-resource-table`)||customElements.define(`mint-resource-table`,M);var te=550,ne=12,re={passive:!0},ie=class extends HTMLElement{constructor(...e){super(...e),this._table=null,this._anchor=null,this._popover=null,this._menuRoot=null,this._baseId=``,this._touchTimer=null,this._touchStart=null,this._slotObserver=null,this._scrollCloseTargets=[],this._onScrollClose=()=>{this._closePopover()},this._onContextMenu=e=>{let t=e,n=this._rowTargetFromEventTarget(t.target);n&&(t.preventDefault(),this._openAtRowIndex(n.index,t.clientX,t.clientY))},this._onTouchStart=e=>{let t=e;if(!t.touches.length)return;let n=this._rowTargetFromEventTarget(t.target);if(!n)return;let r=t.touches[0];this._touchStart={x:r.clientX,y:r.clientY,rowIndex:n.index},this._touchTimer!==null&&(window.clearTimeout(this._touchTimer),this._touchTimer=null);let i=this._longPressMs();this._touchTimer=window.setTimeout(()=>{this._touchTimer=null,this._touchStart&&=(this._openAtRowIndex(this._touchStart.rowIndex,this._touchStart.x,this._touchStart.y),null)},i)},this._onTouchMove=e=>{if(!this._touchStart||this._touchTimer===null)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this._touchStart.x,r=t.clientY-this._touchStart.y;n*n+r*r>ne*ne&&(this._clearTouchTimer(),this._touchStart=null)},this._onTouchEnd=()=>{this._clearTouchTimer(),this._touchStart=null}}static get observedAttributes(){return[`for`,`long-press-ms`]}connectedCallback(){this.classList.add(`contents`),this._baseId=this.id?.trim()||`mint-rt-ctx-${Math.random().toString(36).slice(2,10)}`,this._anchor=document.createElement(`div`),this._anchor.id=`${this._baseId}-anchor`,this._anchor.setAttribute(`aria-hidden`,`true`),this._anchor.className=`pointer-events-none fixed z-0 h-px w-px overflow-hidden p-0 m-0 border-0 opacity-0`,document.body.appendChild(this._anchor),this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`data-mint-rt-ctx-internal`,``),this._popover.id=`${this._baseId}-popover`,this._popover.setAttribute(`trigger-id`,this._anchor.id),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`),this._popover.setAttribute(`distance`,`6px`),this._menuRoot=document.createElement(`div`),this._menuRoot.className=`flex min-w-[11rem] flex-col gap-0.5 py-1`,this._popover.appendChild(this._menuRoot),this.appendChild(this._popover),this._slotObserver=new MutationObserver(()=>{this._hideMenuSlotSources()}),this._slotObserver.observe(this,{childList:!0}),queueMicrotask(()=>{this._hideMenuSlotSources(),this._bindTable()})}disconnectedCallback(){this._slotObserver?.disconnect(),this._slotObserver=null,this._unbindTable(),this._anchor?.remove(),this._anchor=null,this._popover?.remove(),this._popover=null,this._menuRoot=null}attributeChangedCallback(){this.isConnected&&this._bindTable()}_longPressMs(){let e=parseInt(this.getAttribute(`long-press-ms`)||``,10);return!Number.isNaN(e)&&e>100?e:te}_resolveTable(){let e=this.getAttribute(`for`)?.trim();if(e){let t=document.getElementById(e);return t&&t.tagName===`MINT-RESOURCE-TABLE`?t:null}let t=this.previousElementSibling;return t&&t.tagName===`MINT-RESOURCE-TABLE`?t:this.parentElement?.querySelector?.(`mint-resource-table`)??null}_hideMenuSlotSources(){for(let e of Array.from(this.children))e===this._popover||e.hasAttribute(`data-mint-rt-ctx-internal`)||e.setAttribute(`hidden`,``)}_bindTable(){this._unbindTable(),this._table=this._resolveTable(),this._table&&(this._table.addEventListener(`contextmenu`,this._onContextMenu,!0),this._table.addEventListener(`touchstart`,this._onTouchStart,{passive:!0}),this._table.addEventListener(`touchmove`,this._onTouchMove,{passive:!0}),this._table.addEventListener(`touchend`,this._onTouchEnd,{passive:!0}),this._table.addEventListener(`touchcancel`,this._onTouchEnd,{passive:!0}))}_unbindTable(){this._closePopover(),this._table&&=(this._table.removeEventListener(`contextmenu`,this._onContextMenu,!0),this._table.removeEventListener(`touchstart`,this._onTouchStart),this._table.removeEventListener(`touchmove`,this._onTouchMove),this._table.removeEventListener(`touchend`,this._onTouchEnd),this._table.removeEventListener(`touchcancel`,this._onTouchEnd),null)}_rowTargetFromEventTarget(e){if(!e||!this._table)return null;let t=e.closest?.(`tr[data-row-index], li[data-row-index]`);if(!t||!this._table.contains(t)||t.hasAttribute(`data-mint-rt-spacer`)||t.getAttribute(`data-mint-rt-placeholder`)===`true`)return null;let n=t.getAttribute(`data-row-index`);if(n==null)return null;let r=parseInt(n,10);return Number.isNaN(r)?null:{index:r}}_clearTouchTimer(){this._touchTimer!==null&&(window.clearTimeout(this._touchTimer),this._touchTimer=null)}_positionAnchor(e,t){this._anchor&&(this._anchor.style.left=`${Math.round(e)}px`,this._anchor.style.top=`${Math.round(t)}px`)}_slotTemplateElements(){return Array.from(this.children).filter(e=>e!==this._popover&&e instanceof HTMLElement&&!e.hasAttribute(`data-mint-rt-ctx-internal`))}_elementIsScrollContainer(e){let t=getComputedStyle(e);return t.overflowX===`auto`||t.overflowX===`scroll`||t.overflowY===`auto`||t.overflowY===`scroll`}_collectScrollCloseTargets(e){let t=[],n=new Set,r=e=>{!e||n.has(e)||(n.add(e),t.push(e))};r(window),e.querySelectorAll(`[id^="mint-rt-vscroll-"]`).forEach(e=>{this._elementIsScrollContainer(e)&&r(e)});let i=e.querySelector(`mint-table`);for(;i&&i!==e;)this._elementIsScrollContainer(i)&&r(i),i=i.parentElement;return this._elementIsScrollContainer(e)&&r(e),t}_detachScrollCloseListeners(){for(let e of this._scrollCloseTargets)e.removeEventListener(`scroll`,this._onScrollClose,re);this._scrollCloseTargets=[]}_attachScrollCloseListeners(e){this._detachScrollCloseListeners(),this._scrollCloseTargets=this._collectScrollCloseTargets(e);for(let e of this._scrollCloseTargets)e.addEventListener(`scroll`,this._onScrollClose,re)}_closePopover(){if(this._detachScrollCloseListeners(),!this._popover?.hasAttribute(`open`))return;let e=this._popover;typeof e.close==`function`?e.close():this._popover.removeAttribute(`open`)}_openAtRowIndex(e,t,n){this._closePopover();let r=this._resolveTable();if(!r||typeof r.getRowByIndex!=`function`||!this._popover||!this._menuRoot)return;let i=this._popover,a=this._menuRoot,o=r.getRowByIndex(e);if(o===void 0)return;let s=this._slotTemplateElements();if(!s.length)return;this._positionAnchor(t,n),a.innerHTML=``,s.forEach(t=>{if(t.hasAttribute(`data-mint-rt-ctx-if-selection`)&&!(window.getSelection?.()?.toString?.()?.trim()??``))return;let n=t.cloneNode(!0);n.removeAttribute(`hidden`),n.addEventListener(`click`,t=>{t.stopPropagation();let r=n.getAttribute(`data-context-action`)||n.querySelector?.(`[data-context-action]`)?.getAttribute(`data-context-action`)||``,i=window.getSelection?.()?.toString?.()?.trim()??``;this.dispatchEvent(new CustomEvent(`context-action`,{bubbles:!0,composed:!0,detail:{action:r,row:o,rowIndex:e,selectedText:i}})),this._closePopover()}),a.appendChild(n);let r=n;typeof r.render==`function`&&queueMicrotask(()=>r.render())}),i.removeAttribute(`open`),i.offsetHeight,i.setAttribute(`open`,`true`);let c=i;typeof c.render==`function`&&queueMicrotask(()=>c.render());let l=this._resolveTable();l&&this._attachScrollCloseListeners(l)}};customElements.get(`mint-resource-table-context-menu`)||customElements.define(`mint-resource-table-context-menu`,ie);var ae=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`,`position`,`full-page`,`width`,`height`]}constructor(){super(),this._overlay=null,this._offCanvas=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._darkModeObserver=null,this._contentObserver=null,this._renderFrame=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`fixed`,`inset-0`,`z-50`),this.isOpen()||this.classList.add(`hidden`),this.render(),this._observeDarkMode(),this._observeContentMutations()}disconnectedCallback(){this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}getId(){return this.getAttribute(`id`)||``}getHeading(){return this.getAttribute(`heading`)||``}getPosition(){let e=this.getAttribute(`position`)?.toLowerCase();return e===`top`||e===`bottom`||e===`left`||e===`right`?e:`right`}isFullPage(){return this.getAttribute(`full-page`)===`true`}getWidth(){return this.getAttribute(`width`)||`320px`}getHeight(){return this.getAttribute(`height`)||``}_normalizeCssValue(e){return/^\d+(\.\d+)?$/.test(e.trim())?`${e.trim()}px`:e.trim()}isOpen(){return this.getAttribute(`open`)===`true`}open(){this.setAttribute(`open`,`true`)}close(){this.removeAttribute(`open`)}render(){let e=this.getId(),t=this.getHeading(),n=this.isOpen(),r=this.getPosition(),i=this.isFullPage(),a=this.getHeight();e&&(this.id=e),this._overlay||(this._overlay=document.createElement(`div`),this._overlay.className=`fixed inset-0 bg-black/50 transition-opacity duration-200 z-40`,this._overlay.addEventListener(`click`,()=>this.close()),this.appendChild(this._overlay)),this._offCanvas||(this._offCanvas=document.createElement(`div`),this.appendChild(this._offCanvas));let o=this._getPositionClasses(r,i);this._offCanvas.className=o;let s=this._offCanvas.querySelector(`.off-canvas-content`);if(s||(s=document.createElement(`div`),s.className=`off-canvas-content bg-white dark:bg-mint-elevated dark:border dark:border-mint-divider shadow-xl flex flex-col pointer-events-auto`,s.style.transform=this._getTransformValue(r,!1),this._offCanvas.appendChild(s)),n?this._animateEnter():this._animateExit(),Array.from(s.classList).forEach(e=>{(e.startsWith(`w-`)||e.startsWith(`max-w-`)||e.startsWith(`md:w-`)||e.startsWith(`md:max-w-`)||e.startsWith(`sm:w-`)||e.startsWith(`sm:max-w-`))&&s.classList.remove(e)}),s.classList.remove(`h-full`,`max-h-[90vh]`,`max-h-screen`,`md:h-full`,`md:max-h-[90vh]`,`md:max-h-screen`,`sm:h-full`,`sm:max-h-[90vh]`),s.classList.remove(`has-custom-width`,`has-custom-height`),s.style.removeProperty(`--off-canvas-width`),s.style.removeProperty(`--off-canvas-height`),i)s.classList.add(`w-full`,`h-full`,`max-w-none`);else if(r===`top`||r===`bottom`)if(s.classList.add(`w-full`,`h-full`,`max-w-none`),a){let e=this._normalizeCssValue(a);s.style.setProperty(`--off-canvas-height`,e),s.classList.add(`has-custom-height`),this._ensureHeightStyle()}else s.classList.add(`md:max-h-[90vh]`,`md:h-auto`);else{s.classList.add(`w-full`,`h-full`,`max-w-none`);let e=this.getWidth(),t=this._normalizeCssValue(e);s.style.setProperty(`--off-canvas-width`,t),s.classList.add(`has-custom-width`),this._ensureWidthStyle()}this._header||(this._header=document.createElement(`div`),this._header.className=`flex items-center justify-between p-4 border-b border-gray-200 dark:border-mint-divider flex-shrink-0`,s.appendChild(this._header)),this._headingSlot||(this._headingSlot=document.createElement(`div`),this._headingSlot.className=`flex-1`,this._headingSlot.setAttribute(`slot`,`heading`),this._header.appendChild(this._headingSlot));let c=this._headingSlot.querySelector(`mint-text`);t?(c||(c=document.createElement(`mint-text`),c.setAttribute(`size`,`sub-heading`),c.setAttribute(`bold`,`true`),this._headingSlot.appendChild(c)),c.textContent=t):c&&c.remove(),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._offCanvas&&e!==this._headingSlot&&e.getAttribute(`slot`)===`heading`).forEach(e=>{this._headingSlot&&e.parentElement!==this._headingSlot&&this._headingSlot.appendChild(e)}),this._closeButton||(this._closeButton=document.createElement(`mint-button`),this._closeButton.setAttribute(`variant`,`ghost`),this._closeButton.setAttribute(`icon`,`close`),this._closeButton.addEventListener(`click`,()=>this.close()),this._header.appendChild(this._closeButton)),this._bodySlot||(this._bodySlot=document.createElement(`div`),this._bodySlot.className=`flex-1 overflow-y-auto p-4`,this._bodySlot.setAttribute(`slot`,`body`),s.appendChild(this._bodySlot)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._offCanvas&&e!==this._bodySlot&&e.getAttribute(`slot`)===`body`).forEach(e=>{this._bodySlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`p-4 border-t border-gray-200 dark:border-mint-divider flex-shrink-0`,this._actionsSlot.setAttribute(`slot`,`actions`),s.appendChild(this._actionsSlot));let l=this._actionsSlot.querySelector(`mint-stack`);l||(l=document.createElement(`mint-stack`),l.setAttribute(`direction`,`horizontal`),l.className=`justify-end`,this._actionsSlot.appendChild(l)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._offCanvas&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`).forEach(e=>{Array.from(e.children).forEach(e=>{e.parentElement!==l&&l.appendChild(e)}),e.parentElement&&e.remove()}),Array.from(this.children).forEach(e=>{e!==this._overlay&&e!==this._offCanvas&&e.getAttribute(`slot`)!==`heading`&&e.getAttribute(`slot`)!==`body`&&e.getAttribute(`slot`)!==`actions`&&e!==this._headingSlot&&e!==this._bodySlot&&e!==this._actionsSlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._updateBackgroundColor()}_getPositionClasses(e,t){let n=`fixed z-50 pointer-events-none`;switch(e){case`top`:return`${n} inset-0 md:inset-x-0 md:top-0 md:bottom-auto ${t?`md:h-full`:`md:h-auto`}`;case`bottom`:return`${n} inset-0 md:inset-x-0 md:bottom-0 md:top-auto ${t?`md:h-full`:`md:h-auto`}`;case`left`:return`${n} inset-0 md:inset-y-0 md:left-0 md:right-auto ${t?`md:w-full`:`md:w-auto`}`;case`right`:return`${n} inset-0 md:inset-y-0 md:right-0 md:left-auto ${t?`md:w-full`:`md:w-auto`}`;default:return`${n} inset-0 md:inset-y-0 md:right-0 md:left-auto ${t?`md:w-full`:`md:w-auto`}`}}_getTransformValue(e,t){if(t)switch(e){case`top`:return`translateY(0)`;case`bottom`:return`translateY(0)`;case`left`:return`translateX(0)`;case`right`:return`translateX(0)`;default:return`translateX(0)`}else switch(e){case`top`:return`translateY(-100%)`;case`bottom`:return`translateY(100%)`;case`left`:return`translateX(-100%)`;case`right`:return`translateX(100%)`;default:return`translateX(100%)`}}_updateBackgroundColor(){if(!this._offCanvas)return;let e=document.documentElement.classList.contains(`dark`),t=this._offCanvas.querySelector(`.off-canvas-content`);t&&(e?(t.classList.remove(`bg-white`),t.classList.add(`bg-mint-elevated`,`border`,`border-mint-divider`)):(t.classList.remove(`bg-mint-elevated`,`border`,`border-mint-divider`),t.classList.add(`bg-white`)))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_animateEnter(){let e=this._offCanvas?.querySelector(`.off-canvas-content`);if(!e)return;let t=this.getPosition();e.style.transform=this._getTransformValue(t,!1),e.style.transition=`transform 300ms ease-out`,this.classList.remove(`hidden`),requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.style.transform=this._getTransformValue(t,!0)})})}_animateExit(){let e=this._offCanvas?.querySelector(`.off-canvas-content`);if(!e){this.classList.add(`hidden`);return}let t=this.getPosition();e.style.transition=`transform 300ms ease-in`,e.style.transform=this._getTransformValue(t,!1),setTimeout(()=>{this.classList.add(`hidden`),e.style.transform=``,e.style.transition=``},300)}_ensureWidthStyle(){if(!document.getElementById(`off-canvas-width-style`)){let e=document.createElement(`style`);e.id=`off-canvas-width-style`,e.textContent=`
|
|
82
|
+
`,n.classList.add(`mint-date-shortcuts-row`),document.head.querySelector(`style[data-mint-date-shortcuts]`)||(r.setAttribute(`data-mint-date-shortcuts`,`true`),document.head.appendChild(r));let i=document.createElement(`div`);i.className=`absolute left-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-r from-white dark:from-mint-elevated to-transparent opacity-0 md:hidden`,t.appendChild(i);let a=document.createElement(`div`);a.className=`absolute right-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-l from-white dark:from-mint-elevated to-transparent opacity-100 md:hidden`,t.appendChild(a);let s=document.createElement(`div`);s.className=`hidden md:block absolute top-0 left-0 right-0 h-8 pointer-events-none z-10 bg-gradient-to-b from-white dark:from-mint-elevated to-transparent opacity-0`,t.appendChild(s);let l=document.createElement(`div`);l.className=`hidden md:block absolute bottom-0 left-0 right-0 h-8 pointer-events-none z-10 bg-gradient-to-t from-white dark:from-mint-elevated to-transparent opacity-100`,t.appendChild(l);let u=()=>{if(window.innerWidth>=768){let e=n.scrollTop,t=n.scrollHeight,r=n.clientHeight;e>0?s.style.opacity=`1`:s.style.opacity=`0`,e+r<t-1?l.style.opacity=`1`:l.style.opacity=`0`,i.style.opacity=`0`,a.style.opacity=`0`}else{let e=n.scrollLeft,t=n.scrollWidth,r=n.clientWidth;e>0?i.style.opacity=`1`:i.style.opacity=`0`,e+r<t-1?a.style.opacity=`1`:a.style.opacity=`0`,s.style.opacity=`0`,l.style.opacity=`0`}};n.addEventListener(`scroll`,u),window.addEventListener(`resize`,u),setTimeout(u,0),o.forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.tabIndex=0,t.className=`px-3 py-1.5 text-xs font-medium rounded-md bg-gray-100 dark:bg-mint-hover text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-mint-elevated whitespace-nowrap flex-shrink-0 md:w-full md:text-left focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,t.textContent=e.label,t.setAttribute(`data-keep-popover-open`,`true`);let r=()=>{let t=e.action();if(t){if(this._isRange&&`start`in t&&`end`in t){this._selectedStartDate=t.start,this._selectedEndDate=t.end;let e=this.getFormat(),n=`${this._formatDate(t.start,e)} - ${this._formatDate(t.end,e)}`;this.setValue(n),this._currentMonth=t.start.getMonth(),this._currentYear=t.start.getFullYear()}else if(t instanceof Date){this._selectedStartDate=t,this._selectedEndDate=null;let e=this.getFormat(),n=this._formatDate(t,e);this.setValue(n),this._currentMonth=t.getMonth(),this._currentYear=t.getFullYear()}this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close(),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0}))}};t.addEventListener(`click`,r),t.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),n.appendChild(t)}),t.appendChild(n),e.appendChild(t),c.appendChild(e)}l.appendChild(u),l.appendChild(b),l.appendChild(x),c.appendChild(l),this._calendarContainer.appendChild(c)}_buildMonthView(){if(!this._calendarContainer)return;let e=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],t=document.createElement(`div`);t.className=`flex items-center justify-between mb-4`;let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,n.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,n.setAttribute(`data-keep-popover-open`,`true`);let r=document.createElement(`mint-icon`);r.setAttribute(`name`,`caret-left`),r.className=`w-4 h-4`,n.appendChild(r);let i=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear--,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};n.addEventListener(`click`,i),n.addEventListener(`touchend`,e=>{e.preventDefault(),i()},{passive:!1}),t.appendChild(n);let a=document.createElement(`button`);a.type=`button`,a.tabIndex=0,a.className=`text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 rounded px-1`,a.setAttribute(`data-keep-popover-open`,`true`),a.textContent=String(this._currentYear);let o=()=>{this.getMode()!==`year`&&(this._viewMode=`year`,this._buildCalendar())};a.addEventListener(`click`,o),a.addEventListener(`touchend`,e=>{e.preventDefault(),o()},{passive:!1}),t.appendChild(a);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`w-4 h-4`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear++,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),t.appendChild(s);let u=document.createElement(`div`);u.className=`grid grid-cols-3 gap-2`,e.forEach((e,t)=>{let n=document.createElement(`button`);n.type=`button`,n.tabIndex=0,n.setAttribute(`data-keep-popover-open`,`true`),n.className=`p-2 rounded text-sm font-medium focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${this._currentMonth===t?`bg-slate-800 dark:bg-slate-600 text-white`:`text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-mint-hover`}`,n.textContent=e;let r=()=>{if(this.getMode()===`month`){let e=new Date(this._currentYear,t,1),n=this.getFormat(),r=this._formatDate(e,n);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentMonth=t,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else{let e=this._currentMonth,n=this._currentYear;this._currentMonth=t,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,n,this._currentMonth,this._currentYear)}};n.addEventListener(`click`,r),n.addEventListener(`touchend`,e=>{e.preventDefault(),r()},{passive:!1}),u.appendChild(n)}),this._calendarContainer.appendChild(t),this._calendarContainer.appendChild(u)}_buildYearView(){if(!this._calendarContainer)return;let e=this._currentYear-6,t=this._currentYear+6,n=document.createElement(`div`);n.className=`flex items-center justify-between mb-4`;let r=document.createElement(`button`);r.type=`button`,r.tabIndex=0,r.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,r.setAttribute(`data-keep-popover-open`,`true`);let i=document.createElement(`mint-icon`);i.setAttribute(`name`,`caret-left`),i.className=`w-4 h-4`,r.appendChild(i);let a=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear-=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};r.addEventListener(`click`,a),r.addEventListener(`touchend`,e=>{e.preventDefault(),a()},{passive:!1}),n.appendChild(r);let o=document.createElement(`div`);o.className=`text-sm font-medium text-gray-900 dark:text-gray-100`,o.textContent=`${e} - ${t}`,n.appendChild(o);let s=document.createElement(`button`);s.type=`button`,s.tabIndex=0,s.className=`p-1 rounded hover:bg-gray-100 dark:hover:bg-mint-hover text-gray-600 dark:text-gray-300 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`,s.setAttribute(`data-keep-popover-open`,`true`);let c=document.createElement(`mint-icon`);c.setAttribute(`name`,`caret-right`),c.className=`w-4 h-4`,s.appendChild(c);let l=()=>{let e=this._currentMonth,t=this._currentYear;this._currentYear+=12,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)};s.addEventListener(`click`,l),s.addEventListener(`touchend`,e=>{e.preventDefault(),l()},{passive:!1}),n.appendChild(s);let u=document.createElement(`div`);u.className=`grid grid-cols-3 gap-2`;for(let n=e;n<=t;n++){let e=document.createElement(`button`);e.type=`button`,e.tabIndex=0,e.setAttribute(`data-keep-popover-open`,`true`),e.className=`p-2 rounded text-sm font-medium focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${this._currentYear===n?`bg-slate-800 dark:bg-slate-600 text-white`:`text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-mint-hover`}`,e.textContent=String(n),e.addEventListener(`click`,()=>{let e=this.getMode();if(e===`year`){let e=new Date(n,0,1),t=this.getFormat(),r=this._formatDate(e,t);this.setValue(r),this._selectedStartDate=e,this._selectedEndDate=null;let i=this._currentMonth,a=this._currentYear;this._currentYear=n,this._currentMonth=0,this._dispatchMonthChangeEvent(i,a,this._currentMonth,this._currentYear),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0})),this._dispatchDateChangeEvent(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(e===`month`){let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`month`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}else{let e=this._currentMonth,t=this._currentYear;this._currentYear=n,this._viewMode=`calendar`,this._buildCalendar(),this._dispatchMonthChangeEvent(e,t,this._currentMonth,this._currentYear)}}),u.appendChild(e)}this._calendarContainer.appendChild(n),this._calendarContainer.appendChild(u)}_getDaysInMonth(e,t){return new Date(t,e+1,0).getDate()}_getFirstDayOfMonth(e,t){let n=this.getWeekStartDay(),r=new Date(t,e,1).getDay();return r>=n?r-n:7-(n-r)}_isToday(e){let t=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateSelected(e){let t=this.getSelectionMode();return this._isRange||t===`week`||t===`month`?this._selectedStartDate&&this._selectedEndDate?this._isSameDate(e,this._selectedStartDate)||this._isSameDate(e,this._selectedEndDate):this._isRange&&this._selectedStartDate&&!this._selectedEndDate?this._isSameDate(e,this._selectedStartDate):!1:this._selectedStartDate!==null&&this._isSameDate(e,this._selectedStartDate)}_isDateInRange(e){let t=this.getSelectionMode();if((this._isRange||t===`week`||t===`month`)&&this._selectedStartDate&&this._selectedEndDate)return this._rangeIncludesDisabledDates(this._selectedStartDate,this._selectedEndDate)?!1:e>=this._selectedStartDate&&e<=this._selectedEndDate;if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate){let t=this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,n=this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate;if(this._rangeIncludesDisabledDates(t,n)){let r=this._findFirstDisabledDateInRange(t,n);return r?this._selectedStartDate<this._hoveredDate?e>=t&&e<r&&!this._isSameDate(e,t):e>r&&e<=n&&!this._isSameDate(e,n):!1}return e>=t&&e<=n&&!this._isSameDate(e,t)&&!this._isSameDate(e,n)}return!1}_rangeIncludesDisabledDates(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate());return n.some(e=>{let t=new Date(e.getFullYear(),e.getMonth(),e.getDate());return t>=r&&t<=i})}_findFirstDisabledDateInRange(e,t){let n=this.getDisabledDates(),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()),i=new Date(t.getFullYear(),t.getMonth(),t.getDate()),a=n.map(e=>new Date(e.getFullYear(),e.getMonth(),e.getDate())).filter(e=>e>=r&&e<=i).sort((e,t)=>e.getTime()-t.getTime());return a.length>0?a[0]:null}_hasIncompleteRange(){return this._isRange&&this._selectedStartDate!==null&&this._selectedEndDate===null}_isSameDate(e,t){return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}_isDateDisabled(e){return this.getDisabledDates().some(t=>this._isSameDate(e,t))}_dispatchMonthChangeEvent(e,t,n,r){(e!==n||t!==r)&&this.dispatchEvent(new CustomEvent(`month-change`,{detail:{month:n,year:r,oldMonth:e,oldYear:t},bubbles:!0,cancelable:!0,composed:!0}))}_dispatchDateChangeEvent(){let e=this.getFormat(),t={value:this.getValue()};this._selectedStartDate&&(t.startDate=this._selectedStartDate,t.startDateFormatted=this._formatDate(this._selectedStartDate,e)),this._selectedEndDate&&(t.endDate=this._selectedEndDate,t.endDateFormatted=this._formatDate(this._selectedEndDate,e)),this.dispatchEvent(new CustomEvent(`date-change`,{detail:t,bubbles:!0,cancelable:!0,composed:!0}))}_setupContainerObserver(){if(this._resizeObserver&&=(this._resizeObserver.disconnect(),null),!this._inputsWrapperEl)return;let e=e=>{this._inputsWrapperEl&&(e<400?(this._inputsWrapperEl.classList.add(`flex-wrap`),this._inputsWrapperEl.classList.remove(`flex-nowrap`)):(this._inputsWrapperEl.classList.remove(`flex-wrap`),this._inputsWrapperEl.classList.add(`flex-nowrap`)))};e(this._inputsWrapperEl.offsetWidth||this.offsetWidth),this._resizeObserver=new ResizeObserver(t=>{for(let n of t){let t=n.contentRect.width;e(t)}}),this._resizeObserver.observe(this)}_getWeekStart(e){let t=this.getWeekStartDay(),n=e.getDay(),r;r=n>=t?n-t:7-(t-n);let i=new Date(e);return i.setDate(e.getDate()-r),i.setHours(0,0,0,0),i}_getWeekEnd(e){let t=this._getWeekStart(e),n=new Date(t);return n.setDate(t.getDate()+6),n.setHours(23,59,59,999),n}_getMonthStart(e){let t=new Date(e.getFullYear(),e.getMonth(),1);return t.setHours(0,0,0,0),t}_getMonthEnd(e){let t=new Date(e.getFullYear(),e.getMonth()+1,0);return t.setHours(23,59,59,999),t}_handleDateClick(e){this._isHandlingClick=!0;try{let t=this.getFormat(),n=this.getSelectionMode(),r,i;if(n===`week`?(r=this._getWeekStart(e),i=this._getWeekEnd(e)):n===`month`?(r=this._getMonthStart(e),i=this._getMonthEnd(e)):(r=e,i=e),this.isRange()||n===`week`||n===`month`)if(n===`week`||n===`month`){if(this._rangeIncludesDisabledDates(r,i)){this._buildCalendar();return}this._selectedStartDate=r,this._selectedEndDate=i;let e=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else if(this._hoveredDate=null,this._selectedStartDate===null){if(this._isDateDisabled(r)){this._buildCalendar();return}this._selectedStartDate=new Date(r.getFullYear(),r.getMonth(),r.getDate()),this._selectedEndDate=null,this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear(),this._hoveredDate=null,this._buildCalendar()}else if(this._selectedEndDate===null){let n=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=this._selectedStartDate?new Date(this._selectedStartDate.getFullYear(),this._selectedStartDate.getMonth(),this._selectedStartDate.getDate()):null,i,a;if(r&&n<r?(i=n,a=r):(i=r,a=n),this._rangeIncludesDisabledDates(i,a)){this._buildCalendar();return}r&&n<r?(this._selectedEndDate=r,this._selectedStartDate=n):(this._selectedEndDate=n,r&&(this._selectedStartDate=r)),this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();let o=`${this._formatDate(this._selectedStartDate,t)} - ${this._formatDate(this._selectedEndDate,t)}`;this.setAttribute(`value`,o),this._textInput&&(this._textInput.value=o),this._hiddenInput&&(this._hiddenInput.value=o),this._updateDisplayText(),this._buildCalendar(),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}else this._selectedStartDate=r,this._selectedEndDate=null;else{this._selectedStartDate=r,this._selectedEndDate=null;let e=this._formatDate(r,t);this.setValue(e),this._textInput&&(this._textInput.value=e),this._popover&&typeof this._popover.close==`function`&&this._popover.close()}this._buildCalendar(),this._updateDisplayText(),this._exitInputMode();let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0})),this._dispatchDateChangeEvent()}finally{this._isHandlingClick=!1}}_updateDisplayText(){if(!this._displayEl)return;let e=this.getDisplayFormat(),t=this.getSelectionMode(),n=this._isRange||t===`week`||t===`month`,r=``;n&&this._selectedStartDate&&this._selectedEndDate?r=`${this._formatDatePhp(this._selectedStartDate,e)} - ${this._formatDatePhp(this._selectedEndDate,e)}`:this._selectedStartDate&&(r=this._formatDatePhp(this._selectedStartDate,e)),r?(this._displayEl.textContent=r,this._displayEl.classList.remove(`text-gray-400`,`dark:text-gray-500`),this._displayEl.classList.add(`text-gray-900`,`dark:text-white`)):(this._displayEl.textContent=`Select date`,this._displayEl.classList.add(`text-gray-400`,`dark:text-gray-500`),this._displayEl.classList.remove(`text-gray-900`,`dark:text-white`)),this._displayEl&&this._inputsWrapperEl&&(this._displayEl.style.display=this._isInputMode?`none`:`flex`,this._inputsWrapperEl.style.display=this._isInputMode?`flex`:`none`)}_enterInputMode(){if(!this._isInputMode&&!(this.isReadonly()||this.isDisabled())&&(this._isInputMode=!0,this._displayEl&&this._inputsWrapperEl&&(this._displayEl.style.display=`none`,this._inputsWrapperEl.style.display=`flex`),this._startPartInputs.length>0)){let e=this._startPartInputs[0];requestAnimationFrame(()=>{e.focus();try{e.setSelectionRange(0,e.value.length)}catch{}})}}_exitInputMode(){this._isInputMode&&(this._isInputMode=!1,this._displayEl&&this._inputsWrapperEl&&(this._displayEl.style.display=`flex`,this._inputsWrapperEl.style.display=`none`),this._updateDisplayText())}_renderSkeleton(e){let t=this.querySelector(`.mint-date-picker-skeleton-container`),n=this._fieldsContainer,r=this._input;if(e){t||(t=document.createElement(`div`),t.className=`mint-date-picker-skeleton-container absolute inset-0 z-10 pointer-events-none`,r?(r.classList.contains(`relative`)||r.classList.add(`relative`),r.appendChild(t)):(this.style.position=`relative`,this.appendChild(t)));let e=t.querySelector(`.mint-date-picker-skeleton`);e||(e=document.createElement(`div`),e.className=`mint-date-picker-skeleton w-full rounded-lg bg-gray-200 dark:bg-mint-hover animate-pulse`,e.style.height=`2.25rem`,t.appendChild(e)),t.style.display=`block`,n&&(n.style.visibility=`hidden`,n.style.pointerEvents=`none`),this._displayEl&&(this._displayEl.style.visibility=`hidden`,this._displayEl.style.pointerEvents=`none`)}else t&&(t.style.display=`none`),n&&(n.style.visibility=`visible`,n.style.pointerEvents=`auto`),this._displayEl&&(this._displayEl.style.visibility=`visible`,this._displayEl.style.pointerEvents=`auto`)}_getFocusableElements(){if(!this._calendarContainer)return[];let e=[`button:not([disabled])`,`a[href]`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`, `);return Array.from(this._calendarContainer.querySelectorAll(e)).filter(e=>{let t=window.getComputedStyle(e);return t.display!==`none`&&t.visibility!==`hidden`})}_setupFocusTrap(){if(!this._popover||!this._popover.hasAttribute(`open`))return;this._removeFocusTrap();let e=this;this._focusTrapHandler=function(t){if(t.key!==`Tab`)return;if(!e._popover||!e._popover.hasAttribute(`open`)){e._removeFocusTrap();return}let n=e._getFocusableElements();if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;if(!e._calendarContainer?.contains(a)){t.preventDefault(),r.focus();return}if(t.shiftKey&&a===r){t.preventDefault(),i.focus();return}if(!t.shiftKey&&a===i){t.preventDefault(),r.focus();return}},this._escapeHandler=function(t){(t.key===`Escape`||t.key===`Esc`)&&e._popover&&e._popover.hasAttribute(`open`)&&(t.preventDefault(),t.stopPropagation(),typeof e._popover.close==`function`&&e._popover.close())},document.addEventListener(`keydown`,this._focusTrapHandler,!0),document.addEventListener(`keydown`,this._escapeHandler,!0),requestAnimationFrame(()=>{let e=this._getFocusableElements();e.length>0&&e[0].focus()})}_removeFocusTrap(){this._focusTrapHandler&&=(document.removeEventListener(`keydown`,this._focusTrapHandler,!0),null),this._escapeHandler&&=(document.removeEventListener(`keydown`,this._escapeHandler,!0),null)}};customElements.get(`mint-date-picker`)||customElements.define(`mint-date-picker`,C);var w=class extends HTMLElement{constructor(...e){super(...e),this._triggerId=`mint-time-picker-trigger-${Math.random().toString(36).slice(2,10)}`,this._popover=null,this._popoverObserver=null,this._inputEl=null,this._hiddenInput=null,this._single={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeStart={hour:9,minute:0,second:0,meridiem:`AM`},this._rangeEnd={hour:5,minute:0,second:0,meridiem:`PM`},this._invalidFromInput=!1}static get observedAttributes(){return[`value`,`label`,`info`,`disabled`,`id`,`name`,`required`,`readonly`,`range`,`hours`,`minutes`,`seconds`,`error`,`error-message`]}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`),this._parseAndApplyValue(this.getAttribute(`value`)||``),this.render()}disconnectedCallback(){this._popoverObserver&&=(this._popoverObserver.disconnect(),null)}attributeChangedCallback(e,t,n){if(t!==n){if(e===`value`){if(this._parseAndApplyValue(n||``),this._syncHiddenInput(),this._syncInputValue(),this._popover){let e=this._popover.querySelector(`[data-mint-time-picker-body="true"]`);e&&this._buildPopoverContent(e)}return}e!==`error`&&e!==`error-message`&&(this._invalidFromInput=!1),this.render()}}get value(){return this.getValue()}set value(e){this.setValue(e||``)}getValue(){return this.getAttribute(`value`)||``}setValue(e){e?this.setAttribute(`value`,e):this.removeAttribute(`value`),this._parseAndApplyValue(e||``),this._syncHiddenInput(),this._syncInputValue()}isRange(){return this.getAttribute(`range`)===`true`}isHoursEnabled(){let e=this.getAttribute(`hours`);return e===null?!0:e!==`false`}isMinutesEnabled(){let e=this.getAttribute(`minutes`);return e===null?!0:e!==`false`}isSecondsEnabled(){let e=this.getAttribute(`seconds`);return e===null?!1:e!==`false`}isDisabled(){return this.getAttribute(`disabled`)===`true`}isReadonly(){return this.getAttribute(`readonly`)===`true`}isRequired(){return this.getAttribute(`required`)===`true`}hasExternalError(){return this.getAttribute(`error`)===`true`}getExternalErrorMessage(){return this.getAttribute(`error-message`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getName(){return this.getAttribute(`name`)||``}_getEffectiveError(){return{hasError:this.hasExternalError(),message:this.getExternalErrorMessage()}}_formatParts(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=[];return t&&i.push(e.hour.toString()),n&&i.push(e.minute.toString().padStart(2,`0`)),r&&i.push(e.second.toString().padStart(2,`0`)),t?`${i.join(`:`)} ${e.meridiem.toLowerCase()}`:i.join(`:`)}_to24Hour(e){let t=e.hour%12;return e.meridiem===`PM`&&(t+=12),{hour:t,minute:e.minute,second:e.second}}_formatParts24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=this._to24Hour(e),a=[];return t&&a.push(i.hour.toString().padStart(2,`0`)),n&&a.push(i.minute.toString().padStart(2,`0`)),r&&a.push(i.second.toString().padStart(2,`0`)),a.join(`:`)}_getDisplayValue(){return this.isRange()?`${this._formatParts(this._rangeStart)} - ${this._formatParts(this._rangeEnd)}`:this._formatParts(this._single)}_getOutputValue(){return this.isRange()?`${this._formatParts24(this._rangeStart)} - ${this._formatParts24(this._rangeEnd)}`:this._formatParts24(this._single)}_getExpectedFormat(){let e=this.isHoursEnabled(),t=this.isMinutesEnabled(),n=this.isSecondsEnabled(),r=[];e&&r.push(`h`),t&&r.push(`mm`),n&&r.push(`ss`);let i=e?`${r.join(`:`)} am/pm`:r.join(`:`);return this.isRange()?`${i} - ${i}`:i}_syncHiddenInput(){this._hiddenInput&&(this._hiddenInput.value=this.getValue()||this._getOutputValue())}_syncInputValue(){this._inputEl&&(this._inputEl.value=this._getDisplayValue(),typeof this._inputEl.render==`function`&&this._inputEl.render())}_emitChangeFromPicker(){let e=this._getOutputValue();this._invalidFromInput=!1,this.setAttribute(`value`,e),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_parseSingle(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{1,2})(?::(\d{2}))?(?::(\d{2}))?\s*(am|pm)$/i);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0),s=e[4].toUpperCase();return t<1||t>12||n&&(a<0||a>59)||r&&(o<0||o>59)?null:{hour:t,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseSingleOutput24(e){let t=this.isHoursEnabled(),n=this.isMinutesEnabled(),r=this.isSecondsEnabled(),i=e.trim();if(t){let e=i.match(/^(\d{2})(?::(\d{2}))?(?::(\d{2}))?$/);if(!e)return null;let t=Number(e[1]),a=Number(e[2]??0),o=Number(e[3]??0);if(t<0||t>23||n&&(a<0||a>59)||r&&(o<0||o>59))return null;let s=t>=12?`PM`:`AM`;return{hour:t%12==0?12:t%12,minute:a,second:o,meridiem:s}}let a=i.match(/^(\d{2})(?::(\d{2}))?$/);if(!a)return null;let o=Number(a[1]),s=Number(a[2]??0);return n&&(o<0||o>59)||r&&(s<0||s>59)?null:{hour:12,minute:o,second:s,meridiem:`AM`}}_parseAndApplyValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingleOutput24(t||``),i=this._parseSingleOutput24(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingleOutput24(e);return t?(this._single=t,!0):!1}_parseAndApplyDisplayValue(e){if(!e)return!1;if(this.isRange()){let[t,n]=e.split(`-`).map(e=>e.trim()),r=this._parseSingle(t||``),i=this._parseSingle(n||``);return!r||!i?!1:(this._rangeStart=r,this._rangeEnd=i,!0)}let t=this._parseSingle(e);return t?(this._single=t,!0):!1}_handleTypedValue(e){let t=e.trim();if(!t){this._invalidFromInput=!1,this.removeAttribute(`value`),this._syncHiddenInput(),this._syncInputValue();return}if(!this._parseAndApplyDisplayValue(t)){this._invalidFromInput=!0,this.removeAttribute(`value`),this._inputEl&&(this._inputEl.value=``),this._syncHiddenInput(),this.render(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}));return}this._invalidFromInput=!1;let n=this._getOutputValue();this.setAttribute(`value`,n),this._syncHiddenInput(),this._syncInputValue(),this.dispatchEvent(new Event(`input`,{bubbles:!0,composed:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0}))}_buildColumn(e,t,n,r=!0,i=`py-28`){let a=document.createElement(`div`);return a.className=`h-[15rem] overflow-y-auto ${i} ${r?`border-r border-gray-300 dark:border-mint-divider`:``}`,e.forEach(e=>{let r=document.createElement(`button`);r.type=`button`;let i=e===t;r.className=`block w-full py-2 text-center text-base leading-none ${i?`font-semibold text-brand-500 dark:text-white`:`font-normal text-gray-500 dark:text-gray-400`}`,r.dataset.selected=i?`true`:`false`,r.textContent=e,r.addEventListener(`click`,()=>n(e)),a.appendChild(r)}),a}_centerSelectedInColumn(e,t=0){let n=e.querySelector(`button[data-selected="true"]`);if(!n)return;let r=n.offsetTop-(e.clientHeight/2-n.clientHeight/2)-t;e.scrollTop=Math.max(0,r)}_centerAllColumnsInPopoverBody(){if(!this._popover)return;let e=this._popover.querySelector(`[data-mint-time-picker-body="true"]`);if(!e)return;let t=Array.from(e.querySelectorAll(`.h-\\[15rem\\]`)),n=this.isRange()?20:0;t.forEach(e=>this._centerSelectedInColumn(e,n))}_setupPopoverOpenObserver(){this._popover&&(this._popoverObserver&&=(this._popoverObserver.disconnect(),null),this._popoverObserver=new MutationObserver(()=>{this._popover?.getAttribute(`open`)===`true`&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:[`open`]}))}_buildPickerSet(e,t,n){let r=this.isHoursEnabled(),i=this.isMinutesEnabled(),a=this.isSecondsEnabled(),o=document.createElement(`div`),s=(r?1:0)+(i?1:0)+(a?1:0)+(r?1:0);o.className=`grid bg-white dark:bg-mint-elevated overflow-hidden`,o.style.gridTemplateColumns=`repeat(${Math.max(s,1)}, minmax(0, 1fr))`;let c=Array.from({length:12},(e,t)=>(t+1).toString().padStart(2,`0`)),l=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),u=Array.from({length:60},(e,t)=>t.toString().padStart(2,`0`)),d=[`AM`,`PM`],f=[];r&&f.push(this._buildColumn(c,t.hour.toString().padStart(2,`0`),e=>{n({...t,hour:Number(e)})},!0,`py-32`)),i&&f.push(this._buildColumn(l,t.minute.toString().padStart(2,`0`),e=>{n({...t,minute:Number(e)})},!0,`py-32`)),a&&f.push(this._buildColumn(u,t.second.toString().padStart(2,`0`),e=>{n({...t,second:Number(e)})},!0,`py-32`)),r&&f.push(this._buildColumn(d,t.meridiem,e=>{n({...t,meridiem:e})},!0,`py-20`)),f.forEach((e,t)=>{t===f.length-1&&e.classList.remove(`border-r`),o.appendChild(e)}),e.appendChild(o)}_buildPopoverContent(e){if(e.innerHTML=``,!this.isRange()){this._buildPickerSet(e,this._single,t=>{this._single=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)});return}let t=document.createElement(`div`);t.className=`flex flex-col gap-3 min-[640px]:grid min-[640px]:grid-cols-2`;let n=document.createElement(`div`),r=document.createElement(`mint-text`);r.setAttribute(`variant`,`muted`),r.className=`mb-2 text-xs uppercase`,r.textContent=`Start`,n.appendChild(r),this._buildPickerSet(n,this._rangeStart,t=>{this._rangeStart=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)});let i=document.createElement(`div`),a=document.createElement(`mint-text`);a.setAttribute(`variant`,`muted`),a.className=`mb-2 text-xs uppercase`,a.textContent=`End`,i.appendChild(a),this._buildPickerSet(i,this._rangeEnd,t=>{this._rangeEnd=t,this._emitChangeFromPicker(),this._buildPopoverContent(e)}),t.appendChild(n),t.appendChild(i),e.appendChild(t),requestAnimationFrame(()=>{this._centerAllColumnsInPopoverBody()})}_syncInputIconDarkModeTone(){if(!this._inputEl)return;let e=this._inputEl.querySelector(`mint-icon`);e&&(e.classList.remove(`dark:text-gray-500`),e.classList.add(`dark:text-white`))}render(){let e=this.isDisabled(),t=this.isReadonly(),n=this._getEffectiveError();this.innerHTML=``;let r=document.createElement(`div`);r.className=`w-full`,this._inputEl=document.createElement(`mint-input`),this._inputEl.id=this._triggerId,this._inputEl.classList.add(`w-full`),this._inputEl.setAttribute(`type`,`text`),this._inputEl.setAttribute(`icon`,`clock`),this._inputEl.setAttribute(`placeholder`,this._getExpectedFormat()),this._inputEl.setAttribute(`label`,this.getLabel()),this._inputEl.setAttribute(`info`,this.getInfo()),this._inputEl.setAttribute(`value`,this._getDisplayValue()),this._inputEl.setAttribute(`error`,n.hasError?`true`:`false`),this._inputEl.setAttribute(`error-message`,n.message||``),e&&this._inputEl.setAttribute(`disabled`,`true`),t&&this._inputEl.setAttribute(`readonly`,`true`),this._inputEl.addEventListener(`change`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())}),this._inputEl.addEventListener(`blur`,n=>{if(e||t)return;let r=n.target;this._handleTypedValue((r?.value||``).toString())},!0),r.appendChild(this._inputEl),this._syncInputIconDarkModeTone(),this._hiddenInput=document.createElement(`input`),this._hiddenInput.type=`hidden`,this._hiddenInput.name=this.getName(),this._hiddenInput.required=this.isRequired(),r.appendChild(this._hiddenInput),this._syncHiddenInput(),this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`trigger-id`,this._triggerId),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`),this._popover.setAttribute(`distance`,`6px`),(e||t)&&this._popover.setAttribute(`open`,`false`);let i=document.createElement(`div`);i.setAttribute(`data-mint-time-picker-body`,`true`),i.className=`min-w-[18rem] max-w-[56rem] p-3 bg-white dark:bg-mint-elevated`,this._buildPopoverContent(i),this._popover.appendChild(i),r.appendChild(this._popover),this._setupPopoverOpenObserver(),this.appendChild(r)}};customElements.get(`mint-time-picker`)||customElements.define(`mint-time-picker`,w);var T=`data-mint-select-part`,E=class e extends HTMLElement{static get observedAttributes(){return[`name`,`value`,`disabled`,`id`,`required`,`label`,`info`,`error`,`error-message`,`multiple`,`loading`]}static{this._lightDomOptionHideStylesInjected=!1}static _ensureLightDomOptionHideStyles(){if(e._lightDomOptionHideStylesInjected||typeof document>`u`)return;e._lightDomOptionHideStylesInjected=!0;let t=document.createElement(`style`);t.setAttribute(`data-mint-select-light-dom`,``),t.textContent=`/* Framework-driven <option>/<optgroup> stay on the host for DOM reconciliation; the visible control is the inner <select>. */
|
|
83
|
+
mint-select > option,
|
|
84
|
+
mint-select > optgroup {
|
|
85
|
+
display: none !important;
|
|
86
|
+
}`,document.head.appendChild(t)}constructor(){super(),this._select=null,this._wrapper=null,this._caretUpIcon=null,this._caretDownIcon=null,this._changeHandler=null,this._optionObserver=null,this._childrenObserver=null,this._hostOptionsObserverRaf=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`inline-block`,`w-full`),this.getLabel()||console.error(`mint-select: The "label" attribute is required. Please provide a label for the select.`),e._ensureLightDomOptionHideStyles(),this.render(),this._childrenObserver&&this._childrenObserver.disconnect(),this._childrenObserver=new MutationObserver(e=>{if(e.some(e=>{let t=e.target;if(this._select&&(t===this._select||this._select.contains(t)))return!1;let n=Array.from(e.addedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`))||Array.from(e.removedNodes).some(e=>e.nodeType===Node.ELEMENT_NODE&&(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)),r=e.type===`attributes`&&e.target.nodeType===Node.ELEMENT_NODE&&(e.target.tagName===`OPTION`||e.target.tagName===`OPTGROUP`);return n||r})){if(this._hostOptionsObserverRaf!==null)return;this._hostOptionsObserverRaf=requestAnimationFrame(()=>{this._hostOptionsObserverRaf=null,this.isConnected&&this.render()})}}),this._childrenObserver.observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`value`,`selected`,`disabled`]})}disconnectedCallback(){this._select&&this._changeHandler&&(this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=null),this._optionObserver&&=(this._optionObserver.disconnect(),null),this._childrenObserver&&=(this._childrenObserver.disconnect(),null),this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null)}isLoading(){return this.getAttribute(`loading`)===`true`}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute(`aria-invalid`,this.hasError()?`true`:`false`));return}if(e===`loading`){this.render();return}if(e===`value`){if(this._select)if(this.isMultiple()){let e=[];try{let t=n?JSON.parse(n):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=n?[String(n)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=n||``;return}this.render()}}getName(){return this.getAttribute(`name`)||``}getValue(){if(this.isMultiple()&&this._select){let e=Array.from(this._select.selectedOptions).map(e=>e.value);return JSON.stringify(e)}return this.hasAttribute(`value`)?this.getAttribute(`value`)||``:this._select?this._select.value:``}setValue(e){if(this.isMultiple()){let t=Array.isArray(e)?e.map(e=>String(e)):e==null||e===``?[]:[String(e)];this.setAttribute(`value`,JSON.stringify(t)),this._select&&Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)});return}let t=e==null?``:String(e);this.setAttribute(`value`,t),this._select&&(this._select.value=t)}get value(){try{return this.getValue()||``}catch{return``}}set value(e){try{if(this.isMultiple()){this.setValue(e);return}let t=e||``;(this.getAttribute(`value`)||``)!==t&&this.setAttribute(`value`,t),this._select&&requestAnimationFrame(()=>{this._select&&(t===``||Array.from(this._select.options).some(e=>e.value===t))&&this._select.value!==t&&(this._select.value=t)})}catch{}}isDisabled(){return this.getAttribute(`disabled`)===`true`}isMultiple(){return this.getAttribute(`multiple`)===`true`}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}getId(){return this.getAttribute(`id`)||``}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}getSelectClasses(){let e=this.hasError(),t=this.isMultiple(),n=[`w-full`,`px-3.5`,t?`pr-3.5`:`pr-10`,t?`py-2`:`py-1.5`,t?`min-h-[6rem]`:`min-h-[2rem]`,`text-sm`,`font-medium`,`rounded-lg`,`box-border`,`bg-white`,`dark:bg-mint-elevated`,`text-gray-900`,`dark:text-white`,`outline-none`,`focus:outline-none`,`disabled:opacity-40`,`disabled:cursor-not-allowed`,`appearance-none`,`bg-no-repeat`,`bg-right`,`cursor-pointer`],r=[`border-2`,e?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`],i=[`focus-visible:ring-2`,`focus-visible:ring-offset-1`,e?`focus-visible:ring-red-400 dark:focus-visible:ring-red-500`:`focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`];return[...n,...r,...i].filter(Boolean).join(` `)}render(){this._hostOptionsObserverRaf!==null&&(cancelAnimationFrame(this._hostOptionsObserverRaf),this._hostOptionsObserverRaf=null);let e=this.isLoading(),t=this.isMultiple(),n=this.getValue(),r=[];this._select&&Array.from(this._select.children).forEach(e=>{(e.tagName===`OPTION`||e.tagName===`OPTGROUP`)&&r.push(e.cloneNode(!0))}),Array.from(this.children).forEach(e=>{e instanceof HTMLElement&&e.hasAttribute(T)&&e.remove()}),this._wrapper=null,this._select=null;let i=Array.from(this.children).filter(e=>e.tagName===`OPTION`||e.tagName===`OPTGROUP`).map(e=>e.cloneNode(!0)),a=this.getLabel(),o=this.getInfo(),s=this.getId(),c=this.getName(),l=this.isDisabled(),u=this.hasError();if(a){let e=document.createElement(`label`);e.setAttribute(T,`label`),e.className=`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,s&&e.setAttribute(`for`,s);let t=document.createTextNode(a);e.appendChild(t),this.appendChild(e)}this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(T,`wrapper`),this._wrapper.className=`relative w-full`,this.appendChild(this._wrapper),this._select=document.createElement(`select`),this._select.className=this.getSelectClasses(),s&&(this._select.id=s),c&&(this._select.name=c),l&&(this._select.disabled=!0),t&&(this._select.multiple=!0),this._select.setAttribute(`aria-invalid`,u?`true`:`false`);let d=i.length>0?i:r;if(d.length>0&&d.forEach(e=>{this._select.appendChild(e)}),this._select.options.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`Select an option`,e.disabled=!0,e.selected=!0,this._select.appendChild(e)}if(t){let e=[];try{let t=n?JSON.parse(n):[];e=Array.isArray(t)?t.map(e=>String(e)):[]}catch{e=n?[String(n)]:[]}Array.from(this._select.options).forEach(t=>{t.selected=e.includes(t.value)})}else this._select.value=n||``;if(this._changeHandler&&this._select&&this._select.removeEventListener(`change`,this._changeHandler),this._changeHandler=e=>{let n=e.target,r=t?Array.from(n.selectedOptions).map(e=>e.value):n.value,i=t?JSON.stringify(r):String(r||``);(this.getAttribute(`value`)||``)!==i&&(i?this.setAttribute(`value`,i):this.removeAttribute(`value`));let a=new Event(`input`,{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),this.dispatchEvent(new CustomEvent(`input`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:{value:r},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener(`change`,this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{let e=this.getAttribute(`value`)||this.value||``;this._select&&e&&requestAnimationFrame(()=>{if(this._select)if(t){let t=[];try{let n=JSON.parse(e);t=Array.isArray(n)?n.map(e=>String(e)):[]}catch{t=[String(e)]}Array.from(this._select.options).forEach(e=>{e.selected=t.includes(e.value)})}else Array.from(this._select.options).some(t=>t.value===e)&&this._select.value!==e&&(this._select.value=e)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),t)this._caretUpIcon=null,this._caretDownIcon=null;else{let e=document.createElement(`div`);e.className=`absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none z-10 flex flex-col`,this._caretUpIcon=document.createElement(`mint-icon`),this._caretUpIcon.setAttribute(`name`,`caret-up`),this._caretUpIcon.className=`w-[.9em] h-[.9em] text-gray-400 dark:text-gray-500 mb-[-.2rem]`,e.appendChild(this._caretUpIcon),this._caretDownIcon=document.createElement(`mint-icon`),this._caretDownIcon.setAttribute(`name`,`caret-down`),this._caretDownIcon.className=`w-[.9em] h-[.9em] text-gray-400 dark:text-gray-500 mt-[-.2rem]`,e.appendChild(this._caretDownIcon),this._wrapper.appendChild(e)}if(o){let e=document.createElement(`div`);e.setAttribute(T,`info`),e.className=`mt-1 text-xs text-gray-500 dark:text-gray-400`,e.textContent=o,this.appendChild(e)}this._renderErrorState(),this._renderSkeleton(e)}_renderSkeleton(e){let t=this.querySelector(`.mint-select-skeleton-container`),n=this._wrapper;if(e){t||(t=document.createElement(`div`),t.className=`mint-select-skeleton-container absolute inset-0 z-10 pointer-events-none`,n?(n.classList.contains(`relative`)||n.classList.add(`relative`),n.appendChild(t)):(this.style.position=`relative`,this.appendChild(t)));let e=t.querySelector(`.mint-select-skeleton`);if(!e){e=document.createElement(`div`),e.className=`mint-select-skeleton w-full rounded-lg bg-gray-200 dark:bg-mint-hover animate-pulse`;let n=this.isMultiple();e.style.height=n?`6rem`:`2.25rem`,t.appendChild(e)}t.style.display=`block`,this._select&&(this._select.style.opacity=`0`,this._select.style.pointerEvents=`none`)}else t&&(t.style.display=`none`),this._select&&(this._select.style.opacity=`1`,this._select.style.pointerEvents=`auto`)}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-select-error`);e&&t?(n?n.hasAttribute(T)||n.setAttribute(T,`error`):(n=document.createElement(`div`),n.setAttribute(T,`error`),n.className=`mint-select-error mt-1 text-xs text-red-600 dark:text-red-400`,this.appendChild(n)),n.textContent=t):n&&n.remove()}};customElements.get(`mint-select`)||customElements.define(`mint-select`,E);var D=class extends HTMLElement{static get observedAttributes(){return[`label`,`accept`,`multiple`,`width`,`height`,`disabled`,`name`,`error`,`error-message`,`loading`]}constructor(){super(),this._dropzone=null,this._fileInput=null,this._previewContainer=null,this._isDragging=!1,this._wasDragging=!1,this._isUpdatingFiles=!1,this._listenersInitialized=!1,this._selectedFiles=[],this._previewUrls=[],this._resetHandler=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`inline-block`),this.render(),this._attachFormResetListener()}disconnectedCallback(){if(this.removeEventListeners(),this._cleanupPreviewUrls(),this._resetHandler){let e=this.closest(`form`);e&&e.removeEventListener(`reset`,this._resetHandler),this._resetHandler=null}}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){this._updateDragStateClass(),this._renderErrorState(this.hasError(),this.getErrorMessage());return}if(e===`loading`){this.render();return}this.render()}}getLabel(){return this.getAttribute(`label`)||``}getAccept(){return this.getAttribute(`accept`)||``}isMultiple(){return this.getAttribute(`multiple`)===`true`}getWidth(){return this.getAttribute(`width`)||`200px`}getHeight(){return this.getAttribute(`height`)||`200px`}_renderSkeleton(e){let t=this.querySelector(`.mint-dropzone-skeleton-container`),n=this._dropzone;if(e){t||(t=document.createElement(`div`),t.className=`mint-dropzone-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center justify-center`,n?(n.classList.contains(`relative`)||n.classList.add(`relative`),n.appendChild(t)):(this.style.position=`relative`,this.appendChild(t)));let e=t.querySelector(`.mint-dropzone-skeleton`);if(e||(e=document.createElement(`div`),e.className=`mint-dropzone-skeleton rounded-lg border-2 border-dashed border-gray-300 dark:border-mint-divider bg-gray-200 dark:bg-mint-hover animate-pulse`,e.style.width=`100%`,e.style.height=`100%`,t.appendChild(e)),t.style.display=`flex`,n){let e=n.querySelector(`.mint-dropzone-icon`),t=n.querySelector(`.mint-dropzone-label`),r=n.querySelector(`.mint-dropzone-previews-wrapper`),i=this._fileInput;if(e){let t=e;t.style.visibility=`hidden`,t.style.pointerEvents=`none`}if(t){let e=t;e.style.visibility=`hidden`,e.style.pointerEvents=`none`}if(r){let e=r;e.style.visibility=`hidden`,e.style.pointerEvents=`none`}i&&(i.style.visibility=`hidden`,i.style.pointerEvents=`none`),n.style.pointerEvents=`none`}}else if(t&&(t.style.display=`none`),n){let e=n.querySelector(`.mint-dropzone-icon`),t=n.querySelector(`.mint-dropzone-label`),r=n.querySelector(`.mint-dropzone-previews-wrapper`),i=this._fileInput;if(e){let t=e;t.style.visibility=`visible`,t.style.pointerEvents=`auto`}if(t){let e=t;e.style.visibility=`visible`,e.style.pointerEvents=`auto`}if(r){let e=r;e.style.visibility=`visible`,e.style.pointerEvents=`auto`}i&&(i.style.visibility=`visible`,i.style.pointerEvents=`auto`),n.style.pointerEvents=`auto`}}getName(){return this.getAttribute(`name`)||``}hasError(){return this.getAttribute(`error`)===`true`}getErrorMessage(){return this.getAttribute(`error-message`)||``}isDisabled(){return this.getAttribute(`disabled`)===`true`}isLoading(){return this.getAttribute(`loading`)===`true`}render(){let e=this.isLoading(),t=this.getLabel(),n=this.getAccept(),r=this.isMultiple(),i=this.isDisabled(),a=this.getWidth(),o=this.getHeight(),s=this.getName(),c=this.hasError(),l=this.getErrorMessage();this._dropzone||(this._dropzone=document.createElement(`div`),this.appendChild(this._dropzone)),this._updateDragStateClass(),this._dropzone.setAttribute(`aria-invalid`,c?`true`:`false`),i?(this._dropzone.setAttribute(`tabindex`,`-1`),this._dropzone.removeAttribute(`role`)):(this._dropzone.setAttribute(`tabindex`,`0`),this._dropzone.setAttribute(`role`,`button`),this._dropzone.setAttribute(`aria-label`,t||`File upload dropzone`)),this._dropzone.style.width=a,this._dropzone.style.height=o,this._dropzone.style.minWidth=a,this._dropzone.style.minHeight=o,this._fileInput||(this._fileInput=document.createElement(`input`),this._fileInput.type=`file`,this._fileInput.style.display=`none`,this._fileInput.setAttribute(`tabindex`,`-1`),this._fileInput.setAttribute(`aria-hidden`,`true`),this._dropzone.appendChild(this._fileInput)),this._fileInput.accept=n,this._fileInput.multiple=r,this._fileInput.disabled=i,s?this._fileInput.name=s:this._fileInput.removeAttribute(`name`),this._fileInput.setAttribute(`aria-invalid`,c?`true`:`false`);let u=this._dropzone.querySelector(`.mint-dropzone-icon`),d=this._dropzone.querySelector(`.mint-dropzone-label`);u&&u.remove(),d&&d.remove();let f=document.createElement(`div`);f.className=`mint-dropzone-icon flex items-center justify-center mt-2 mb-2 flex-shrink-0`;let p=document.createElement(`mint-icon`);if(p.setAttribute(`name`,`upload`),p.className=`w-12 h-12 text-gray-400 dark:text-gray-500`,f.appendChild(p),this._dropzone.appendChild(f),t){let e=document.createElement(`div`);e.className=`mint-dropzone-label text-sm font-medium text-gray-600 dark:text-gray-400 text-center px-4 flex-shrink-0`,e.textContent=t,this._dropzone.appendChild(e)}this.setupEventListeners(),this._renderErrorState(c,l),this._renderPreviews(),this._renderSkeleton(e)}_updateDragState(){this._dropzone&&this._updateDragStateClass()}_renderErrorState(e,t){let n=this.querySelector(`.mint-dropzone-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-dropzone-error mt-1 text-xs text-red-600 dark:text-red-400`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_updateDragStateClass(){if(!this._dropzone)return;let e=this.isDisabled(),t=this.hasError(),n=`relative border-2 border-dashed rounded-lg flex flex-col items-center ${this._selectedFiles.length>0?`justify-start`:`justify-center`} cursor-pointer overflow-hidden`,r=this._isDragging?`border-gray-400 dark:border-gray-500 bg-gray-50 dark:bg-mint-elevated dark:border-mint-divider`:`border-gray-300 dark:border-mint-divider bg-white dark:bg-mint-elevated dark:border-mint-divider hover:border-gray-400 dark:hover:border-mint-divider`,i=t?`border-red-300 dark:border-red-300 bg-red-50/50 dark:bg-red-900/30`:``,a=e?`opacity-40 cursor-not-allowed`:``;this._dropzone.className=`${n} ${t?i:r} ${a} focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`.trim()}setupEventListeners(){this._listenersInitialized||(this._listenersInitialized=!0,this.removeEventListeners(),!(!this._dropzone||!this._fileInput||this.isDisabled())&&(this._onDropzoneClick||=e=>{if(!(this.isDisabled()||!this._fileInput)&&e.target!==this._fileInput&&(e.stopPropagation(),e.preventDefault(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onDragOver||=e=>{e.preventDefault(),e.stopPropagation(),this.isDisabled()||this._isDragging||(this._isDragging=!0,this._wasDragging=!0,this._updateDragState())},this._onDragLeave||=e=>{e.preventDefault(),e.stopPropagation();let t=this._dropzone?.getBoundingClientRect();t&&(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState())},this._onDrop||=e=>{if(e.preventDefault(),e.stopPropagation(),this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState()),this.isDisabled())return;let t=e.dataTransfer?.files;t&&t.length>0&&this._handleFiles(t)},this._onFileInputInput||=e=>{e.stopImmediatePropagation(),e.stopPropagation()},this._onKeyDown||=e=>{if(!(this.isDisabled()||!this._fileInput)&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),e.isTrusted))try{this._fileInput.click()}catch(e){console.debug(`File chooser blocked:`,e)}},this._onFocus||=e=>{this._dropzone&&!this.isDisabled()&&this._dropzone.classList.add(`focus-visible:ring-2`)},this._onBlur||=e=>{this._dropzone},this._onFileInputChange||=e=>{if(e.stopImmediatePropagation(),e.stopPropagation(),this._isUpdatingFiles)return;let t=e.target.files;if(t&&t.length>0){let e=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<t.length;n++){let a=t[n];this._isFileAccepted(a,e)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}},this._dropzone.addEventListener(`click`,this._onDropzoneClick),this._dropzone.addEventListener(`dragover`,this._onDragOver),this._dropzone.addEventListener(`dragleave`,this._onDragLeave),this._dropzone.addEventListener(`drop`,this._onDrop),this._dropzone.addEventListener(`keydown`,this._onKeyDown),this._dropzone.addEventListener(`focus`,this._onFocus),this._dropzone.addEventListener(`blur`,this._onBlur),this._fileInput.addEventListener(`change`,this._onFileInputChange),this._fileInput.addEventListener(`input`,this._onFileInputInput,!0)))}removeEventListeners(){this._dropzone&&(this._onDropzoneClick&&this._dropzone.removeEventListener(`click`,this._onDropzoneClick),this._onDragOver&&this._dropzone.removeEventListener(`dragover`,this._onDragOver),this._onDragLeave&&this._dropzone.removeEventListener(`dragleave`,this._onDragLeave),this._onDrop&&this._dropzone.removeEventListener(`drop`,this._onDrop),this._onKeyDown&&this._dropzone.removeEventListener(`keydown`,this._onKeyDown),this._onFocus&&this._dropzone.removeEventListener(`focus`,this._onFocus),this._onBlur&&this._dropzone.removeEventListener(`blur`,this._onBlur)),this._fileInput&&(this._onFileInputChange&&this._fileInput.removeEventListener(`change`,this._onFileInputChange),this._onFileInputInput&&this._fileInput.removeEventListener(`input`,this._onFileInputInput,!0)),this._isDragging=!1,this._listenersInitialized=!1}_handleFiles(e){let t=this.getAccept(),n=this.isMultiple(),r=[],i=[];for(let n=0;n<e.length;n++){let a=e[n];this._isFileAccepted(a,t)?r.push(a):i.push(a)}if(!n&&r.length>1&&(i.push(...r.slice(1)),r.splice(1)),i.length>0){let e=new CustomEvent(`dropRejected`,{detail:{files:i,reason:`File type not accepted or multiple files not allowed`},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}r.length>0&&this._applyValidFiles(r)}_isFileAccepted(e,t){if(!t)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase());for(let t of n)if(t.startsWith(`.`)){if(`.`+e.name.split(`.`).pop()?.toLowerCase()===t)return!0}else if(t.includes(`/*`)){if(t.split(`/`)[0]===e.type.split(`/`)[0])return!0}else if(e.type===t)return!0;return!1}_dispatchEvent(e,t){let n=t.target,r=new CustomEvent(e,{detail:{files:n.files?Array.from(n.files):[],value:n.value||``},bubbles:!0,cancelable:!0});this.dispatchEvent(r)}_dispatchSelectionEvents(){let e={files:[...this._selectedFiles],value:``};this.dispatchEvent(new CustomEvent(`input`,{detail:e,bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`change`,{detail:e,bubbles:!0,cancelable:!0,composed:!0}))}_syncFileInputFromSelected(){if(!this._fileInput)return;let e=new DataTransfer;this._selectedFiles.forEach(t=>{try{e.items.add(t)}catch(e){console.warn(`Failed to add file to DataTransfer:`,e)}}),this._isUpdatingFiles=!0;try{this._fileInput.files=e.files}catch(e){console.warn(`Failed to set files on input:`,e)}setTimeout(()=>{this._isUpdatingFiles=!1},0)}get files(){return this._syncFileInputFromSelected(),this._fileInput?.files||null}syncFiles(){this._syncFileInputFromSelected()}_renderPreviews(){if(!this._dropzone)return;if(this._previewContainer&&(this._cleanupPreviewUrls(),this._previewContainer.remove()),this._selectedFiles.length===0){this._previewContainer=null,this._updateDragStateClass();return}let e=document.createElement(`div`);e.className=`mint-dropzone-previews-wrapper mt-3 w-full relative max-h-48`;let t=document.createElement(`div`);t.className=`mint-dropzone-previews w-full flex flex-col gap-2 max-h-48 overflow-y-auto overflow-x-hidden px-2 pb-2`,this._selectedFiles.forEach((e,n)=>{let r=document.createElement(`div`);if(r.className=`flex items-center gap-3 p-2 rounded border border-gray-200 dark:border-mint-divider bg-gray-50 dark:bg-mint-elevated`,e.type.startsWith(`image/`)){let t=document.createElement(`img`);t.className=`w-12 h-12 object-cover rounded border border-gray-200 dark:border-mint-divider`;let n=URL.createObjectURL(e);this._previewUrls.push(n),t.src=n,r.appendChild(t)}else{let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`attach`),e.className=`w-5 h-5 text-gray-500 dark:text-gray-300`,r.appendChild(e)}let i=document.createElement(`div`);i.className=`flex-1 text-sm text-gray-800 dark:text-gray-100 truncate`,i.textContent=e.name,r.appendChild(i);let a=document.createElement(`button`);a.type=`button`,a.className=`text-gray-500 hover:bg-red-100 dark:hover:bg-red-900/30 flex items-center justify-center w-6 h-6 rounded-full`;let o=document.createElement(`mint-icon`);o.setAttribute(`name`,`close`),o.className=`w-4 h-4`,a.appendChild(o),a.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),this._removeFileAt(n)}),r.appendChild(a),t.appendChild(r)});let n=this.hasError(),r=this._isDragging,i=`from-white dark:from-mint-elevated`;n?i=`from-red-50 dark:from-red-900/30`:r&&(i=`from-gray-50 dark:from-mint-elevated`);let a=document.createElement(`div`);a.className=`absolute top-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-b ${i} to-transparent opacity-0`,e.appendChild(a);let o=document.createElement(`div`);o.className=`absolute bottom-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-t ${i} to-transparent opacity-100`,e.appendChild(o);let s=()=>{let e=t.scrollTop,n=t.scrollHeight,r=t.clientHeight;e>0?a.style.opacity=`1`:a.style.opacity=`0`,e+r<n-1?o.style.opacity=`1`:o.style.opacity=`0`};s(),t.addEventListener(`scroll`,s),e.appendChild(t),this._previewContainer=e,this._dropzone.appendChild(e),this._updateDragStateClass()}_removeFileAt(e){if(e<0||e>=this._selectedFiles.length)return;let[t]=this._selectedFiles.splice(e,1);t&&this._cleanupPreviewUrls(),this._syncFileInputFromSelected(),this._renderPreviews(),this._dispatchSelectionEvents()}_cleanupPreviewUrls(){this._previewUrls.forEach(e=>URL.revokeObjectURL(e)),this._previewUrls=[]}_attachFormResetListener(){let e=this.closest(`form`);!e||this._resetHandler||(this._resetHandler=()=>{this._selectedFiles=[],this._syncFileInputFromSelected(),this._renderPreviews(),this._cleanupPreviewUrls()},e.addEventListener(`reset`,this._resetHandler))}_applyValidFiles(e){if(this.isMultiple()){let t=e.filter(e=>!this._isDuplicateFile(e));this._selectedFiles.push(...t)}else this._selectedFiles=[e[0]];this._syncFileInputFromSelected(),this._selectedFiles.length>0&&(this.removeAttribute(`error`),this.removeAttribute(`error-message`),this._fileInput&&this._fileInput.removeAttribute(`aria-invalid`)),this._renderPreviews(),this._dispatchSelectionEvents()}_isDuplicateFile(e){return this._selectedFiles.some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)}};customElements.get(`mint-dropzone`)||customElements.define(`mint-dropzone`,D);var O=class extends HTMLElement{static get observedAttributes(){return[`action`,`method`,`enctype`,`data-form-data`,`loading`,`headers`,`submitting`]}constructor(){super(),this._form=null,this._submitHandler=null,this._hostSubmitHandler=null,this._errors={},this._fieldBlurHandlers=new Map,this._fieldChangeHandlers=new Map,this._observer=null,this._formData=null,this._headers=null,this._buttonStates=new Map,this._attrSubmittingMintFields=new Map,this._attrSubmittingNativeFields=new Map,this._attrSubmittingMintButtons=new Map,this._attrSubmittingNativeButtons=new Map,this._reactiveDataProxy=null,this._reactiveDataObserver=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}connectedCallback(){this._render(),this._ensureSubmitHandler(),this._setupBlurValidation();let e=this.getAttribute(`headers`);e&&this._parseHeaders(e),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(this._formData)this._isReactiveObject(this._formData)?this._setupReactiveDataObserver(this._formData):this._lastDataSnapshot||=this._createDataSnapshot(this._formData),this._applyFormData();else{let e=this.getAttribute(`data-form-data`);e&&(this._parseFormData(e),this._applyFormData())}this._propagateLoadingState(),this._applySubmittingAttributeState()})})}disconnectedCallback(){this._form&&this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._hostSubmitHandler&&this.removeEventListener(`submit`,this._hostSubmitHandler),this._restoreSubmittingAttributeState(),this._cleanupBlurValidation(),this._stopReactiveDataObserver()}reset(){this._clearErrors(),this._formData?this._applyFormData():this.clear()}clear(){this._clearErrors(),this._form&&this._form.reset(),this._resetCustomFields()}submit(){if(this._form){if(typeof this._form.requestSubmit==`function`){this._form.requestSubmit();return}this._handleSubmit(new Event(`submit`,{bubbles:!0,cancelable:!0}))}}attributeChangedCallback(e,t,n){e===`form-data`?(this._parseFormData(n),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})):e===`headers`?this._parseHeaders(n):e===`loading`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._propagateLoadingState()}):this._propagateLoadingState():e===`submitting`?this.isConnected&&this._form?requestAnimationFrame(()=>{this._applySubmittingAttributeState()}):this._applySubmittingAttributeState():this._applyFormAttributes()}get data(){return this._formData}set data(e){this._stopReactiveDataObserver(),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null,e&&typeof e==`object`&&!Array.isArray(e)?(this._formData=e,this._isReactiveObject(e)?this._setupReactiveDataObserver(e):this._lastDataSnapshot=this._createDataSnapshot(e)):e==null?this._formData=null:this._parseFormData(e),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})})}get headers(){return this._headers}set headers(e){if(e&&typeof e==`object`&&!Array.isArray(e))this._headers=e;else if(e==null)this._headers=null;else if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_render(){if(this.classList.add(`block`,`w-full`),!this._form){for(this._form=document.createElement(`form`),this._form.noValidate=!0;this.firstChild;)this._form.appendChild(this.firstChild);this.appendChild(this._form)}this._ensureSubmitHandler(),this._applyFormAttributes()}_ensureSubmitHandler(){this._form&&(this._submitHandler&&this._form.removeEventListener(`submit`,this._submitHandler,!0),this._submitHandler=e=>{e.preventDefault(),e.stopImmediatePropagation(),this._handleSubmit(e)},this._form.addEventListener(`submit`,this._submitHandler,!0))}_applyFormAttributes(){if(!this._form)return;let e=this.getAttribute(`action`)||``,t=this.getAttribute(`method`)||``,n=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;e&&(this._form.action=e),t&&(this._form.method=t),this._form.enctype=n}async _handleSubmit(e){if(e.preventDefault(),!this._form)return;this._clearErrors(),this._syncDropzoneFiles();let t=this._collectValidationRules(),n=new FormData(this._form),r=this._formDataToValues(n);if(this._formData){let e=this._getReactiveValue(this._formData);e&&typeof e==`object`&&!Array.isArray(e)&&(r={...this._extractReactiveData(e),...r})}let i=this._collectLiveControlValues();if(r={...r,...i},!this._validate(r,t)){this.dispatchEvent(new CustomEvent(`invalid`,{detail:{errors:this._errors},bubbles:!0,cancelable:!0,composed:!0}));return}let a=new CustomEvent(`submit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(a),a.form=this;let o=new CustomEvent(`mintFormSubmit`,{detail:{formData:n,values:r,form:this},bubbles:!0,cancelable:!0,composed:!0});if(o.form=this,this.dispatchEvent(o),a.defaultPrevented||o.defaultPrevented)return;let s=this.getAttribute(`action`),c=this.getAttribute(`method`);if(!(!s||!c)){this._setButtonsSubmitting();try{let e=await this._submitData(n,r);this.dispatchEvent(new CustomEvent(`submitsuccess`,{detail:e,bubbles:!0,cancelable:!0}))}catch(e){e?.status===422&&e?.data?.errors&&this._applyServerErrors(e.data.errors),this.dispatchEvent(new CustomEvent(`submiterror`,{detail:{error:e},bubbles:!0,cancelable:!0}))}finally{this._restoreButtonsState()}}}async _submitData(e,t){let n=this.getAttribute(`action`),r=this.getAttribute(`method`),i=this.getAttribute(`enctype`)||`application/x-www-form-urlencoded`;if(!n)return{status:0,ok:!0,data:{values:t}};let a=Array.from(e.values()).some(e=>e instanceof File),o=null,s={},c=n;if(typeof window<`u`&&window.mintForm?.defaults?.headers?.common&&Object.assign(s,window.mintForm.defaults.headers.common),this._headers&&Object.assign(s,this._headers),r===`GET`){let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),c+=(n.includes(`?`)?`&`:`?`)+t.toString()}else if(i===`multipart/form-data`||a)o=e;else if(i===`application/json`)o=JSON.stringify(t),s[`Content-Type`]=`application/json`;else{let t=new URLSearchParams;e.forEach((e,n)=>{e instanceof File||t.append(n,String(e))}),o=t,s[`Content-Type`]=`application/x-www-form-urlencoded`}if(typeof fetch==`function`)try{let e=await fetch(c,{method:r||`POST`,body:r===`GET`?null:o,headers:s}),t=await e.text().catch(()=>``),n=t;try{n=JSON.parse(t)}catch{}if(!e.ok){let t={status:e.status,data:n,response:{status:e.status,data:n}};throw await this._applyErrorInterceptors(t)}let i={status:e.status,ok:e.ok,data:n};return await this._applySuccessInterceptors(i)}catch(e){if(e.response)throw e;let t={status:e.status||0,data:e.data||e.message||`Network error`,response:{status:e.status||0,data:e.data||e.message||`Network error`}};throw await this._applyErrorInterceptors(t)}let l=this;return await new Promise(async(e,t)=>{let n=new XMLHttpRequest;n.open(r||`POST`,c,!0),Object.entries(s).forEach(([e,t])=>n.setRequestHeader(e,t)),n.onload=async function(){let{status:r,responseText:i}=n;if(r>=200&&r<300){let n=i;try{n=JSON.parse(i)}catch{}try{let t={status:r,ok:!0,data:n};e(await l._applySuccessInterceptors(t))}catch(e){t(e)}}else{let e=i;try{e=JSON.parse(i)}catch{}try{let n={status:r,data:e,response:{status:r,data:e}};t(await l._applyErrorInterceptors(n))}catch(e){t(e)}}},n.onerror=async function(){try{let e={status:n.status||0,data:n.responseText||`Network error`,response:{status:n.status||0,data:n.responseText||`Network error`}};t(await l._applyErrorInterceptors(e))}catch(e){t(e)}},n.send(r===`GET`?null:o)})}async _applySuccessInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return e;let t=e,n=window.mintForm.interceptors.response.handlers;for(let e of n)e.fulfilled&&(t=await e.fulfilled(t));return t}async _applyErrorInterceptors(e){if(typeof window>`u`||!window.mintForm?.interceptors?.response?.handlers)return Promise.reject(e);let t=e,n=window.mintForm.interceptors.response.handlers;for(let e=n.length-1;e>=0;e--){let r=n[e];if(r.rejected)try{if(t=await r.rejected(t),t!==void 0)return t}catch(e){t=e}}return Promise.reject(t)}_formDataToValues(e){let t={};return e.forEach((e,n)=>{e instanceof File?(t[n]||(t[n]=[]),t[n].push(e)):n in t?Array.isArray(t[n])?(t[n].length>0&&t[n][0]instanceof File,t[n].push(e)):t[n]=[t[n],e]:t[n]=e}),this._form&&(Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n&&e.files!==void 0&&e.files){let r=e.files;if(r.length>0){let e=Array.from(r);t[n]&&Array.isArray(t[n])?e.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=e}}}),Array.from(this._form.querySelectorAll(`input[type="file"][name]`)).forEach(e=>{let n=e.name;if(n&&e.files&&e.files.length>0){let r=Array.from(e.files);t[n]&&Array.isArray(t[n])?r.forEach(e=>{t[n].some(t=>t.name===e.name&&t.size===e.size&&t.lastModified===e.lastModified)||t[n].push(e)}):t[n]=r}}),Array.from(this._form.querySelectorAll(`mint-tags[name]`)).forEach(e=>{let n=e.getAttribute(`name`);if(n){let r=[];e.tags===void 0?typeof e.getTags==`function`&&(r=e.getTags()):r=e.tags,Array.isArray(r)&&r.length>0?t[n]=r.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):t[n]=[]}})),t}_isControlDisabledForSubmit(e){let t=e;for(;t&&t!==this._form;){if((t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLButtonElement)&&t.disabled)return!0;let e=t.getAttribute(`disabled`);if(e!==null&&e!==`false`)return!0;t=t.parentElement}return!1}_collectLiveControlValues(){let e={};if(!this._form)return e;let t=new Set;for(let e of Array.from(this._form.querySelectorAll(`[name]`))){let n=e.getAttribute(`name`);!n||this._isControlDisabledForSubmit(e)||t.add(n)}for(let n of t){let t=this._getFieldElements(n).filter(e=>!this._isControlDisabledForSubmit(e));if(t.length!==0)try{e[n]=this._extractFieldValue(t)}catch{}}return e}_collectValidationRules(){let e={};return this._form&&Array.from(this._form.querySelectorAll(`[name][validation]`)).forEach(t=>{let n=t.getAttribute(`name`)||``,r=t.getAttribute(`validation`);if(!n||!r)return;let i=this._parseRules(r);i.length&&(e[n]=i)}),e}_parseRules(e){if(!e)return[];try{let t=e.replace(/'/g,`"`),n=JSON.parse(t);if(Array.isArray(n))return n.map(e=>String(e))}catch{}return e.split(`,`).map(e=>e.trim()).filter(Boolean)}_validate(e,t){let n=!0;return this._errors={},Object.entries(t||{}).forEach(([e,t])=>{let r=Array.isArray(t)?t:[t],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(n=!1,this._errors[e]=o,this._flagFieldError(i,o)):this._clearFieldError(i)}),n}_validateField(e){let t=this._collectValidationRules();if(!t[e])return;let n=t[e],r=Array.isArray(n)?n:[n],i=this._getFieldElements(e),a=this._extractFieldValue(i),o=this._validateRules(a,r);o?(this._errors[e]=o,this._flagFieldError(i,o)):(this._clearFieldError(i),delete this._errors[e])}_validateRules(e,t){for(let n of t){let[t,r]=n.split(`:`);switch(t){case`required`:if(e==null||typeof e==`string`&&e.trim()===``||e instanceof FileList&&e.length===0||Array.isArray(e)&&e.length===0)return`This field is required.`;break;case`string`:if(typeof e!=`string`)return`Must be a string.`;break;case`email`:if(typeof e==`string`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.trim()))return`Enter a valid email.`;break;case`number`:{let t=Number(e);if(Number.isNaN(t))return`Must be a number.`;break}case`min`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length<t)return`Must be at least ${t} characters.`;if(Array.isArray(e)&&e.length<t)return`Select at least ${t}.`;if(e instanceof FileList&&e.length<t)return`Upload at least ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)<t)return`Must be at least ${t}.`;break}case`max`:{let t=Number(r);if(Number.isNaN(t))break;if(typeof e==`string`&&e.trim().length>t)return`Must be at most ${t} characters.`;if(Array.isArray(e)&&e.length>t)return`Select no more than ${t}.`;if(e instanceof FileList&&e.length>t)return`Upload no more than ${t} files.`;if(e!=null&&!Number.isNaN(Number(e))&&Number(e)>t)return`Must be at most ${t}.`;break}default:break}}return null}_getFieldElements(e){if(!this._form)return[];let t=Array.from(this._form.querySelectorAll(`[name="${e}"]`)),n=t.filter(e=>e.tagName===`MINT-SELECT`);if(n.length>0){let r=[];return n.forEach(t=>{let n=t.querySelector(`select[name="`+e+`"]`);n&&r.push(n)}),t.filter(e=>e.tagName!==`MINT-SELECT`).concat(r)}if(t.filter(e=>e.tagName===`MINT-TAGS`).length>0)return t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`));let r=t.filter(e=>e.tagName===`INPUT`&&e.closest(`mint-tags`));if(r.length>0){let e=[];return r.forEach(t=>{let n=t.closest(`mint-tags`);n&&!e.includes(n)&&e.push(n)}),t.filter(e=>e.tagName!==`INPUT`||!e.closest(`mint-tags`)).concat(e)}return t}_extractFieldValue(e){if(e.length===0)return``;let t=e.find(e=>e instanceof HTMLSelectElement);if(t)return t.multiple?Array.from(t.selectedOptions).map(e=>e.value):t.value;if(e.length>1){let t=e.filter(e=>e instanceof HTMLInputElement);if(t.length>0&&t.length===e.length){let e=t.filter(e=>e.checked);if(t.every(e=>e.type===`radio`))return e.length>0?e[0].value||`on`:``;if(t.every(e=>e.type===`checkbox`))return e.map(e=>e.value||`on`)}let n=e.filter(e=>e.tagName===`MINT-CHOICE`);if(n.length>0&&n.length===e.length){let e=n.find(e=>typeof e.getValue==`function`?e.getValue()!==``:e.querySelector(`mint-choice-option[checked]`)!==null);if(e){if(typeof e.getValue==`function`)return e.getValue();let t=e.querySelector(`mint-choice-option[checked]`);if(t)return t.getAttribute(`value`)||``}return``}let r=e.filter(e=>e.tagName===`MINT-CHECKBOX`);if(r.length>0&&r.length===e.length)return r.filter(e=>e.checked===void 0?e.hasAttribute(`checked`):e.checked).map(e=>e.getAttribute(`value`)||`on`)}let n=e[0];if(n instanceof HTMLInputElement)return n.type===`file`?n.files:n.type===`checkbox`||n.type===`radio`?n.checked?n.value||`on`:``:n.value;if(n instanceof HTMLTextAreaElement)return n.value;if(n.tagName===`MINT-SELECT`){let e=n.querySelector(`select`);if(e)return e.multiple?Array.from(e.selectedOptions).map(e=>e.value):e.value;if(typeof n.getValue==`function`){let e=n.getValue();if(e!=null&&e!==``)return e}return n.getAttribute(`value`)||``}if(n.tagName===`MINT-DROPZONE`&&n.files!==void 0)return n.files;if(n.tagName===`MINT-TAGS`){let e=null;return n.tags===void 0?typeof n.getTags==`function`&&(e=n.getTags()):e=n.tags,Array.isArray(e)?e.map(e=>typeof e==`string`?e:e?.value||e?.label||``).filter(e=>e.trim()!==``):[]}return n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`?(n.checked===void 0?n.hasAttribute(`checked`):n.checked)?n.getAttribute(`value`)||`on`:``:n.tagName===`MINT-CHOICE`?(typeof n.getValue==`function`?n.getValue():``)||``:n.value===void 0?n.getAttribute(`value`)||``:n.value}_flagFieldError(e,t){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.setAttribute(`aria-invalid`,`true`);let n=this._resolveHost(e);n&&(n.setAttribute(`error`,`true`),n.setAttribute(`error-message`,t),n.setAttribute(`data-mint-form-error`,`true`))})}_clearFieldError(e){e.length!==0&&e.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.removeAttribute(`aria-invalid`);let t=this._resolveHost(e);t&&(t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`))})}_clearErrors(){this.querySelectorAll(`[data-mint-form-error]`).forEach(e=>{let t=e;t.removeAttribute(`error`),t.removeAttribute(`error-message`),t.removeAttribute(`data-mint-form-error`)}),this._form&&this._form.querySelectorAll(`[aria-invalid="true"]`).forEach(e=>{e.removeAttribute(`aria-invalid`)}),this._errors={}}setFormErrors(e){this._applyServerErrors(e)}_applyServerErrors(e){this._clearErrors(),Object.entries(e).forEach(([e,t])=>{let n=Array.isArray(t)?t[0]||`Validation error`:t||`Validation error`,r=this._getFieldElements(e);r.length>0&&(this._errors[e]=n,this._flagFieldError(r,n))})}_parseFormData(e){if(!e){this._formData=null;return}if(typeof e==`object`&&!Array.isArray(e)){this._formData=e;return}if(typeof e==`string`)try{this._formData=JSON.parse(e)}catch{this._formData=null}else this._formData=null}_parseHeaders(e){if(!e){this._headers=null;return}if(typeof e==`string`)try{this._headers=JSON.parse(e)}catch{this._headers=null}else this._headers=null}_applyFormData(){if(!this._formData||!this._form)return;let e=this._getReactiveValue(this._formData);if(!e||typeof e!=`object`||Array.isArray(e))return;let t=this._extractReactiveData(e),n=this._createDataSnapshot(t),r=this._lastAppliedDataSnapshot,i=new Set;if(r?(Object.keys(n).forEach(e=>{let t=r[e],a=n[e];JSON.stringify(t)!==JSON.stringify(a)&&i.add(e)}),Object.keys(r).forEach(e=>{e in n||i.add(e)})):Object.keys(n).forEach(e=>i.add(e)),i.size===0)return;let a=()=>{i.forEach(e=>{let t=n[e],r=this._getFieldElements(e);if(r.length===0){setTimeout(()=>{let t=this._getFieldElements(e);if(t.length===0)return;let n=this._formData?this._getReactiveValue(this._formData):null;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[e];this._applyValueToField(t,e,r)},300);return}this._applyValueToField(r,e,t)}),this._lastAppliedDataSnapshot=n};requestAnimationFrame(()=>{requestAnimationFrame(()=>{a()})})}_applyValueToField(e,t,n){e.forEach(e=>{let r=e.tagName;try{if(r===`MINT-INPUT`)e.value!==void 0&&(e.value=n||``);else if(r===`MINT-DATE-PICKER`)typeof e.setValue==`function`&&e.setValue(n||``);else if(r===`MINT-SELECT`||r===`SELECT`)if(r===`SELECT`){let t=e,r=t.closest(`mint-select`);if(r&&typeof r.setValue==`function`)r.setValue(n);else if(t.multiple){let e=Array.isArray(n)?n.map(e=>String(e)):n==null||n===``?[]:[String(n)];Array.from(t.options).forEach(t=>{t.selected=e.includes(t.value)})}else t.value=n==null?``:String(n)}else typeof e.setValue==`function`&&e.setValue(n);else if(r===`MINT-CHOICE`)typeof e.setValue==`function`?e.setValue(n==null?``:String(n)):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=e.getAttribute(`value`)===n});else if(r===`MINT-CHECKBOX`||r===`MINT-SWITCH`){let t=n===!0||n===`true`||n===`on`||n===1||n===`1`;e.checked===void 0?t?e.setAttribute(`checked`,`true`):e.removeAttribute(`checked`):e.checked=t}else if(r===`MINT-TAGS`)if(Array.isArray(n)){let t=new Map;try{let n=e.getAttribute(`predefined-tags`);if(n){let e=JSON.parse(n);Array.isArray(e)&&(t=new Map(e.map(e=>{if(typeof e==`string`){let t=e.trim();return t?[t.toLowerCase(),t]:null}if(!e||typeof e!=`object`)return null;let t=String(e.value??``).trim();if(!t)return null;let n=String(e.label??t);return[t.toLowerCase(),n]}).filter(e=>e!==null)))}}catch{}e.tags!==void 0&&(e.tags=n.map(e=>{if(typeof e==`string`){let n=e.trim();return{value:n,label:t.get(n.toLowerCase())||n,dismissable:!0}}if(e&&typeof e==`object`){let n=String(e.value??``).trim(),r=t.get(n.toLowerCase())||String(e.label??n);return{...e,value:n,label:r,dismissable:e.dismissable!==!1}}return e}))}else e.tags!==void 0&&(e.tags=[]);else if(e instanceof HTMLInputElement){if(e.type===`file`)return;e.type===`checkbox`||e.type===`radio`?e.checked=n===!0||n===`true`||n===`on`||n===1||n===`1`:e.value=n||``}else (e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(e.value=n||``)}catch(e){console.warn(`Failed to set value for field ${t}:`,e)}})}_resetCustomFields(){this.querySelectorAll(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{e.removeAttribute(`error`),e.removeAttribute(`error-message`);let t=e.tagName;if(t===`MINT-INPUT`)try{e.value=``}catch{}else if(t===`MINT-DATE-PICKER`)try{e.setValue?.(``)}catch{}else if(t===`MINT-SELECT`)try{e.setValue?.(``)}catch{}else if(t===`MINT-DROPZONE`){let t=e.querySelector(`input[type="file"]`);t&&(t.value=``)}else if(t===`MINT-CHECKBOX`||t===`MINT-SWITCH`)try{if(e.checked!==void 0)e.checked=!1;else{e.removeAttribute(`checked`);let t=e.querySelector(`input[type="checkbox"], input[type="radio"]`);t&&(t.checked=!1)}}catch{}else if(t===`MINT-CHOICE`)try{typeof e.setValue==`function`?e.setValue(``):e.querySelectorAll(`mint-choice-option`).forEach(e=>{e.checked=!1})}catch{}else if(t===`MINT-TAGS`)try{e.tags=[]}catch{}})}_resolveHost(e){if(e.tagName===`MINT-CHOICE-OPTION`){let t=e.closest(`mint-choice`);if(t)return t}return e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)||e}_setupBlurValidation(){if(!this._form)return;let e=e=>{let t=e.target;if(!t)return;let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);if(!r||!this._collectValidationRules()[r])return;let i=this._extractFieldValue([n]),a=i!=null&&(typeof i==`string`?i.trim()!==``:i instanceof FileList||Array.isArray(i)?i.length>0:!0),o=n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&(t.hasAttribute(`aria-invalid`)||t.closest(`[data-mint-form-error]`)),s=!!n.closest(`mint-tags`),c=n.tagName===`MINT-CHECKBOX`||n.tagName===`MINT-SWITCH`||n.tagName===`MINT-CHOICE`||t instanceof HTMLElement&&(t.closest(`mint-checkbox, mint-switch, mint-choice`)||t.closest(`mint-choice-option`)),l=n.tagName===`MINT-DATE-PICKER`||t instanceof HTMLElement&&t.closest(`mint-date-picker`);(a||o||s||c||l)&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`blur`,e,!0),this._fieldBlurHandlers.set(this._form,e);let t=e=>{let t=e.target;if(!t)return;if(!(t instanceof HTMLInputElement&&t.type===`file`)){let e=this._findFieldElement(t),n=e?this._getFieldName(e):null;e&&n&&this._syncFieldToReactiveData(e,n)}if(e.type===`tags-change`&&t.tagName===`MINT-TAGS`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLSelectElement||t.tagName===`MINT-SELECT`||t.closest(`mint-select`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(e.type===`choice-change`&&t.tagName===`MINT-CHOICE`){let e=t,n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}if(t instanceof HTMLInputElement&&t.type===`checkbox`||t.tagName===`MINT-CHECKBOX`||t.tagName===`MINT-SWITCH`||t.closest(`mint-checkbox, mint-switch`)){let e=this._findFieldElement(t);if(!e)return;let n=this._getFieldName(e);if(!n||!this._collectValidationRules()[n])return;setTimeout(()=>{this._validateField(n)},0);return}let n=this._findFieldElement(t);if(!n)return;let r=this._getFieldName(n);r&&this._collectValidationRules()[r]&&(n.hasAttribute(`data-mint-form-error`)||t instanceof HTMLElement&&t.hasAttribute(`aria-invalid`))&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener(`change`,t,!0),this._form.addEventListener(`input`,t,!0),this._form.addEventListener(`tags-change`,t,!0),this._form.addEventListener(`choice-change`,t,!0),this._fieldChangeHandlers.set(this._form,t)}_findFieldElement(e){let t=e.closest(`mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`);if(t&&t.hasAttribute(`name`))return t;if(e.hasAttribute(`name`)&&(e.tagName.startsWith(`MINT-`)||e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)||(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.hasAttribute(`name`))return e;let n=e;for(;n&&n!==this._form;){if(n.hasAttribute(`name`))return n;n=n.parentElement}return null}_getFieldName(e){return e.hasAttribute(`name`)||e.tagName.startsWith(`MINT-`)?e.getAttribute(`name`):(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.name||null}_syncFieldToReactiveData(e,t){if(!this._formData||!t)return;let n=this._getReactiveValue(this._formData);if(!n||typeof n!=`object`||Array.isArray(n))return;let r=this._getFieldElements(t),i=this._extractFieldValue(r.length?r:[e]);n[t]=this._normalizeReactiveValue(r,i),this._lastDataSnapshot=this._createDataSnapshot(n)}_normalizeReactiveValue(e,t){if(t instanceof FileList)return Array.from(t);if(Array.isArray(t))return t;let n=e[0];return e.length===1&&(n instanceof HTMLInputElement&&n.type===`checkbox`||n?.tagName===`MINT-CHECKBOX`||n?.tagName===`MINT-SWITCH`)?!!t:t??``}_cleanupBlurValidation(){if(this._form&&this._fieldBlurHandlers.has(this._form)){let e=this._fieldBlurHandlers.get(this._form);e&&this._form.removeEventListener(`blur`,e,!0),this._fieldBlurHandlers.delete(this._form)}if(this._form&&this._fieldChangeHandlers.has(this._form)){let e=this._fieldChangeHandlers.get(this._form);e&&(this._form.removeEventListener(`change`,e,!0),this._form.removeEventListener(`input`,e,!0),this._form.removeEventListener(`tags-change`,e,!0),this._form.removeEventListener(`choice-change`,e,!0)),this._fieldChangeHandlers.delete(this._form)}this._observer&&=(this._observer.disconnect(),null)}_syncDropzoneFiles(){this._form&&Array.from(this._form.querySelectorAll(`mint-dropzone[name]`)).forEach(e=>{typeof e.syncFiles==`function`&&e.syncFiles()})}_isSubmittingAttrActive(){let e=this.getAttribute(`submitting`);return e!==null&&e!==`false`}_applySubmittingAttributeState(){if(this._form){if(!this._isSubmittingAttrActive()){this._restoreSubmittingAttributeState();return}this._attrSubmittingMintFields.size>0||this._attrSubmittingNativeFields.size>0||this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0||(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`;this._attrSubmittingMintFields.set(e,t),t||e.setAttribute(`disabled`,`true`),typeof e.render==`function`&&e.render()}),this._form.querySelectorAll(`input, textarea, select`).forEach(e=>{if(e.closest(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags, mint-button`)||e instanceof HTMLInputElement&&e.type===`hidden`)return;let t=e.disabled;this._attrSubmittingNativeFields.set(e,t),t||(e.disabled=!0)}),Array.from(this.querySelectorAll(`mint-button`)).forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._attrSubmittingMintButtons.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&!n&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),Array.from(this.querySelectorAll(`button`)).forEach(e=>{if(e.closest(`mint-button, mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`))return;let t=e.disabled;this._attrSubmittingNativeButtons.set(e,t),t||(e.disabled=!0)}))}}_restoreSubmittingAttributeState(){this._attrSubmittingMintFields.forEach((e,t)=>{e?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintFields.clear(),this._attrSubmittingNativeFields.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeFields.clear(),this._attrSubmittingMintButtons.forEach((e,t)=>{e.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),e.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render()}),this._attrSubmittingMintButtons.clear(),this._attrSubmittingNativeButtons.forEach((e,t)=>{t.disabled=e}),this._attrSubmittingNativeButtons.clear()}_propagateLoadingState(){if(!this._form)return;let e=this.getAttribute(`loading`),t=e!==null&&e!==`false`;Array.from(this._form.querySelectorAll(`mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags`)).forEach(e=>{t?e.setAttribute(`loading`,`true`):e.removeAttribute(`loading`),typeof e.render==`function`&&e.render()})}_setButtonsSubmitting(){if(!this._form)return;this._buttonStates.clear();let e=Array.from(this.querySelectorAll(`mint-button`)),t=Array.from(this.querySelectorAll(`button`));e.forEach(e=>{let t=e.getAttribute(`disabled`)===`true`,n=e.getAttribute(`loading`)===`true`;this._buttonStates.set(e,{disabled:t,loading:n});let r=(e.getAttribute(`type`)||e.getAttribute(`button-type`)||`default`)===`submit`;t||e.setAttribute(`disabled`,`true`),r&&e.setAttribute(`loading`,`true`),typeof e.render==`function`&&e.render()}),t.forEach(e=>{if(e.closest(`mint-button`))return;let t=e.disabled;this._buttonStates.set(e,{disabled:t,loading:!1}),t||(e.disabled=!0)})}_restoreButtonsState(){if(!this._form)return;let e=this._isSubmittingAttrActive()&&(this._attrSubmittingMintButtons.size>0||this._attrSubmittingNativeButtons.size>0),t=Array.from(this.querySelectorAll(`mint-button`)),n=Array.from(this.querySelectorAll(`button`));t.forEach(t=>{if(e&&this._attrSubmittingMintButtons.has(t))return;let n=this._buttonStates.get(t);n&&(n.disabled?t.setAttribute(`disabled`,`true`):t.removeAttribute(`disabled`),n.loading?t.setAttribute(`loading`,`true`):t.removeAttribute(`loading`),typeof t.render==`function`&&t.render())}),n.forEach(t=>{if(t.closest(`mint-button`)||e&&this._attrSubmittingNativeButtons.has(t))return;let n=this._buttonStates.get(t);n&&(t.disabled=n.disabled)}),this._buttonStates.clear()}_isReactiveObject(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;if(`__v_isRef`in e||`_value`in e||`__v_raw`in e||`__v_isReactive`in e||`__ob__`in e)return!0;try{let t=e.toString();if(t===`[object Object]`||t.includes(`Proxy`)){let t=Object.keys(e)[0];if(t){let n=Object.getOwnPropertyDescriptor(e,t);if(n&&(n.get||n.set))return!0}}}catch{return!0}return!0}_createDataSnapshot(e){try{let t=this._extractReactiveData(e);return JSON.parse(JSON.stringify(t))}catch{return{...this._extractReactiveData(e)}}}_extractReactiveData(e){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>this._extractReactiveData(e));let t=this._getReactiveValue(e);if(t&&typeof t==`object`&&!Array.isArray(t)){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=this._extractReactiveData(t[n]));return e}return t}_hasDataChanged(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch{return!0}}_getReactiveValue(e){if(!e||typeof e!=`object`)return e;if(`_value`in e||`__v_isRef`in e){if(e.value!==void 0)return e.value;if(`_value`in e)return e._value}return`__v_raw`in e||`__v_isReactive`in e||`__ob__`in e,e}_setupReactiveDataObserver(e){if(this._stopReactiveDataObserver(),!this.isConnected)return;let t=this._getReactiveValue(e);if(t&&typeof t==`object`&&!Array.isArray(t))this._lastDataSnapshot=this._createDataSnapshot(t);else{this._lastDataSnapshot=null;return}let n=()=>{if(!this._formData||!this._lastDataSnapshot){this._stopReactiveDataObserver();return}let e=this._getReactiveValue(this._formData);if(e&&typeof e==`object`&&!Array.isArray(e)){let t=this._createDataSnapshot(e);this._hasDataChanged(t,this._lastDataSnapshot)&&(this._lastDataSnapshot=t,requestAnimationFrame(()=>{this._applyFormData()}))}this.isConnected&&this._formData?this._reactiveDataObserver=requestAnimationFrame(n):this._stopReactiveDataObserver()};this._reactiveDataObserver=requestAnimationFrame(n)}_stopReactiveDataObserver(){this._reactiveDataObserver!==null&&(cancelAnimationFrame(this._reactiveDataObserver),this._reactiveDataObserver=null),this._reactiveDataProxy=null,this._lastDataSnapshot=null,this._lastAppliedDataSnapshot=null}};customElements.get(`mint-form`)||customElements.define(`mint-form`,O),typeof window<`u`&&(window.mintForm=window.mintForm||{defaults:{headers:{common:{}}},interceptors:{response:{handlers:[]}}},window.mintForm.interceptors.response.use||(window.mintForm.interceptors.response.use=function(e,t){return window.mintForm.interceptors.response.handlers.push({fulfilled:e,rejected:t}),window.mintForm.interceptors.response.handlers.length-1}));var k=class extends HTMLElement{constructor(...e){super(...e),this._observer=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`align-baseline`,`block`,`w-full`,`rounded-lg`,`border`,`border-gray-200`,`dark:border-mint-divider`),this.hasAttribute(`data-mint-rt-scroll-inner`)?this.classList.add(`min-w-0`,`overflow-x-visible`,`overflow-y-visible`):this.classList.add(`min-w-0`,`overflow-x-auto`),this._observeChanges(),this._applyStyles(),requestAnimationFrame(()=>{this._applyStyles(),setTimeout(()=>this._applyStyles(),0)})}disconnectedCallback(){this._observer&&=(this._observer.disconnect(),null)}_observeChanges(){this._observer=new MutationObserver(()=>this._applyStyles()),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!1})}_applyStyles(){this._observer&&this._observer.disconnect();let e=Array.from(this.querySelectorAll(`table`));if(e.length===0){this._observer&&this._observeChanges();return}let t=e.find(e=>e.querySelector(`thead`))??e[0],n=e.find(e=>e.querySelector(`tbody`))??e[0];e.forEach(e=>{let t=!!e.closest(`[id^="mint-rt-vscroll-"]`),n=!!e.closest(`mint-resource-table[data-mint-rt-fixed-header]`),r=t||n,i=[`w-full`,r?`border-separate border-spacing-0`:`border-collapse`,`text-sm`,`font-medium`,...r?[]:[`overflow-hidden`]];this._setClasses(e,i)});let r=t.querySelector(`thead`);if(r){r.classList.add(`bg-[#F7F7F7]`,`dark:bg-mint-nav`);let e=r.querySelectorAll(`th`);e.forEach((t,n)=>{let r=t.querySelector(`mint-icon`),i=r?.getAttribute(`name`)||``,a=t.hasAttribute(`data-mint-rt-sortable`)||r!==null&&i!==`ellipsis`;this._setClasses(t,[`text-left`,`font-semibold`,`text-gray-900`,`dark:text-white`,`px-3`,`py-2`,`border-b`,`border-gray-200`,`dark:border-mint-divider`,`bg-[#F7F7F7]`,`dark:bg-mint-nav`]),a&&t.classList.add(`cursor-pointer`,`hover:bg-gray-100`,`dark:hover:bg-mint-hover`),n===0&&t.classList.add(`pl-3`),n===e.length-1&&t.classList.add(`pr-3`);let o=t.closest(`table`),s=o?.closest(`mint-resource-table`),c=!!s?.hasAttribute(`data-mint-rt-fixed-header`),l=!!s?.hasAttribute(`data-mint-rt-fixed-controls`);if(o?.closest(`[id^="mint-rt-vscroll-"]`)||c){let e=c&&l?`top-[var(--mint-rt-fixed-controls-h,0px)]`:`top-0`;t.classList.add(`sticky`,e,`z-30`,`bg-[#F7F7F7]`,`dark:bg-mint-nav`,`shadow-sm`)}})}let i=n.querySelector(`tbody`);if(i){let e=Array.from(i.querySelectorAll(`tr`)),t=!!n.closest(`[id^="mint-rt-vscroll-"]`)||!!n.closest(`mint-resource-table`)?.hasAttribute(`data-mint-rt-fixed-header`),r=e.findIndex(e=>e.getAttribute(`data-mint-rt-spacer`)===`bottom`);e.forEach((n,i)=>{let a=n.hasAttribute(`data-mint-rt-spacer`),o=n.hasAttribute(`data-row-clickable`);a||t?this._setClasses(n,[`bg-white`,`dark:bg-mint-canvas`]):this._setClasses(n,[`bg-white`,`dark:bg-mint-canvas`,`border-b`,`border-gray-200`,`dark:border-mint-divider`]),o&&!a&&n.classList.add(`cursor-pointer`,`hover:bg-gray-50`,`dark:hover:bg-mint-elevated`),!t&&i===e.length-1&&n.classList.remove(`border-b`);let s=n.querySelectorAll(`td`);s.forEach((o,c)=>{let l=[`text-gray-900`,`dark:text-gray-100`,`px-3`,`py-2`];if(t&&!a){let t=n.hasAttribute(`data-mint-rt-last-row`),a=r===-1&&i===e.length-1;!t&&!a&&l.push(`border-b`,`border-gray-200`,`dark:border-mint-divider`)}this._setClasses(o,l),c===0&&o.classList.add(`pl-3`),c===s.length-1&&o.classList.add(`pr-3`),this._restoreCell(o)})})}let a=n.querySelector(`tfoot`);a&&(this._setClasses(a,[`bg-[#F7F7F7]`,`dark:bg-mint-nav`,`font-semibold`]),a.querySelectorAll(`td`).forEach(e=>{this._setClasses(e,[`text-gray-900`,`dark:text-gray-100`,`px-3`,`py-2`,`border-t`,`border-gray-200`,`dark:border-mint-divider`]),this._restoreCell(e)})),this._observer&&this._observeChanges()}_restoreCell(e){if(e.dataset.mtProcessed!==`true`)return;let t={};Array.from(e.attributes).forEach(e=>{e.name.startsWith(`data-`)&&e.name!==`data-original`&&e.name!==`data-mt-processed`&&(t[e.name]=e.value)});let n=e.getAttribute(`data-original`)||``;e.dataset.mtProcessed=``,e.innerHTML=n,Object.entries(t).forEach(([t,n])=>{e.setAttribute(t,n)})}_setClasses(e,t){e.className=``,t.filter(Boolean).forEach(t=>e.classList.add(...t.split(` `)))}};customElements.get(`mint-table`)||customElements.define(`mint-table`,k);var A=class extends HTMLElement{constructor(...e){super(...e),this._root=null,this._textWrap=null,this._dismissBtn=null,this._clickHandler=null}static get observedAttributes(){return[`dismissable`]}connectedCallback(){this._render()}disconnectedCallback(){this._dismissBtn&&this._clickHandler&&this._dismissBtn.removeEventListener(`click`,this._clickHandler)}attributeChangedCallback(){this._render()}_render(){if(this.classList.add(`inline-flex`,`items-center`,`gap-2`,`px-3`,`py-1`,`rounded-full`,`border`,`border-gray-200`,`dark:border-mint-divider`,`bg-gray-100`,`dark:bg-mint-elevated`,`text-gray-900`,`dark:text-gray-100`,`text-sm`,`font-medium`),!this._root){for(this._root=document.createElement(`div`),this._root.className=`flex items-center gap-2 w-full`,this._textWrap=document.createElement(`span`),this._textWrap.className=`inline-flex items-center min-w-[0.5rem]`,this._textWrap.setAttribute(`data-mt-chip-text`,``);this.firstChild;){let e=this.firstChild;if(e===this._root)break;this._textWrap.appendChild(e)}this._root.appendChild(this._textWrap),this.appendChild(this._root)}let e=this.getAttribute(`dismissable`);e===``||e===`true`||this.hasAttribute(`dismissable`)?(this._dismissBtn||this._createDismissBtn(),this._dismissBtn&&!this._dismissBtn.isConnected&&this._root?.appendChild(this._dismissBtn)):this._dismissBtn&&this._dismissBtn.parentElement===this._root&&this._dismissBtn.remove()}_createDismissBtn(){let e=document.createElement(`button`);e.type=`button`,e.setAttribute(`aria-label`,`Dismiss`),e.className=[`shrink-0`,`inline-flex`,`items-center`,`justify-center`,`w-5`,`h-5`,`rounded-full`,`text-gray-500`,`dark:text-gray-300`,`hover:text-gray-700`,`dark:hover:text-gray-100`,`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-offset-1`,`focus-visible:ring-gray-400`,`dark:focus-visible:ring-gray-500`,`border-none`,`bg-transparent`,`cursor-pointer`].join(` `);let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`close`),t.className=`w-3 h-3`,e.appendChild(t),this._clickHandler=e=>{e.stopPropagation(),this.dispatchEvent(new CustomEvent(`dismiss`,{bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`dismissed`,{bubbles:!0,composed:!0})),this.remove()},e.addEventListener(`click`,this._clickHandler),this._dismissBtn=e}};customElements.get(`mint-chip`)||customElements.define(`mint-chip`,A);var j=class extends HTMLElement{constructor(...e){super(...e),this._container=null,this._chipsWrap=null,this._input=null,this._tags=[],this._predefinedTags=[],this._placeholder=`Add tag`,this._predefinedPopoverOpenListenersAttached=!1,this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose=!1,this._dragIndex=null,this._dragChip=null,this._isPointerDragging=!1,this._pointerMoveHandler=null,this._pointerUpHandler=null,this._containerFocusRingListeners=!1,this._predefinedFieldResizeObserver=null,this._predefinedPopoverBodyEl=null}static get observedAttributes(){return[`tags`,`placeholder`,`predefined-tags`,`predefined-only`,`sortable`,`label`,`info`,`error`,`error-message`,`name`,`id`,`required`,`loading`]}connectedCallback(){this._parseAttrs(),this._render(),this._pointerMoveHandler||(this._pointerMoveHandler=e=>this._onPointerMove(e),window.addEventListener(`pointermove`,this._pointerMoveHandler)),this._pointerUpHandler||(this._pointerUpHandler=e=>this._onPointerUp(e),window.addEventListener(`pointerup`,this._pointerUpHandler),window.addEventListener(`pointercancel`,this._pointerUpHandler))}disconnectedCallback(){this._disconnectPredefinedFieldResizeObserver()}attributeChangedCallback(e,t,n){if(t!==n){if(e===`error`||e===`error-message`){if(this._renderErrorState(),this._container){let e=this.hasError(),t=[`flex`,`flex-wrap`,`items-center`,`gap-2`,`w-full`,`px-2`,`py-1.5`,`min-h-[2rem]`,`rounded-lg`,`border-2`,e?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`,`bg-white`,`dark:bg-mint-elevated`,...this._containerRingClasses(e)];this._container.className=t.join(` `)}return}if(e===`loading`){this._parseAttrs(),this._render();return}this._parseAttrs(),this._render()}}set tags(e){this._tags=Array.isArray(e)?[...e]:[],this._syncAttr(),this._render()}get tags(){return[...this._tags]}_parseAttrs(){let e=this.getAttribute(`tags`);e&&(this._tags=this._parseTagItems(e,`tags`));let t=this.getAttribute(`placeholder`);t!==null&&(this._placeholder=t);let n=this.getAttribute(`predefined-tags`);this._predefinedTags=this._parseTagItems(n,`predefined-tags`)}_parseTagItems(e,t){if(!e)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t.map(e=>{if(typeof e==`string`){let t=e.trim();return t?{value:t,label:t,dismissable:!0}:null}if(!e||typeof e!=`object`)return null;let t=e,n=String(t.value??``).trim();return n?{value:n,label:String(t.label??n),dismissable:t.dismissable!==!1}:null}).filter(e=>e!==null):[]}catch(e){return console.warn(`mint-tags: failed to parse ${t} attribute`,e),[]}}_syncAttr(){this.setAttribute(`tags`,JSON.stringify(this._tags))}getLabel(){return this.getAttribute(`label`)||``}getInfo(){return this.getAttribute(`info`)||``}hasError(){return this.getAttribute(`error`)===`true`}_containerRingClasses(e){return e?[`focus-within:ring-2`,`focus-within:ring-offset-1`,`focus-within:ring-red-400`,`dark:focus-within:ring-red-500`,`data-[mint-tags-active=true]:ring-2`,`data-[mint-tags-active=true]:ring-offset-1`,`data-[mint-tags-active=true]:ring-red-400`,`dark:data-[mint-tags-active=true]:ring-red-500`]:[`focus-within:ring-2`,`focus-within:ring-offset-1`,`focus-within:ring-gray-400`,`dark:focus-within:ring-gray-500`,`data-[mint-tags-active=true]:ring-2`,`data-[mint-tags-active=true]:ring-offset-1`,`data-[mint-tags-active=true]:ring-gray-400`,`dark:data-[mint-tags-active=true]:ring-gray-500`]}_attachContainerFocusRingListeners(){!this._container||this._containerFocusRingListeners||(this._containerFocusRingListeners=!0,this._container.addEventListener(`focusin`,()=>{this._container?.setAttribute(`data-mint-tags-active`,`true`)}),this._container.addEventListener(`focusout`,()=>{requestAnimationFrame(()=>{this._container&&(this._container.contains(document.activeElement)||this._container.removeAttribute(`data-mint-tags-active`))})}))}getErrorMessage(){return this.getAttribute(`error-message`)||``}getName(){return this.getAttribute(`name`)||``}getId(){return this.getAttribute(`id`)||``}isRequired(){return this.getAttribute(`required`)===`true`}isLoading(){return this.hasAttribute(`loading`)}isPredefinedOnly(){return this.getAttribute(`predefined-only`)===`true`}_render(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`);let e=this.isLoading(),t=this.getLabel(),n=this.getInfo(),r=this.hasError(),i=this.getId()||`mint-tags-${Math.random().toString(36).substr(2,9)}`;if(this.getId()||this.setAttribute(`id`,i),this._container)this._input&&(this._input.placeholder=this._placeholder);else{this._container=document.createElement(`div`);let e=[`flex`,`flex-wrap`,`items-center`,`gap-2`,`w-full`,`px-2`,`py-1`,`min-h-[2rem]`,`rounded-lg`,`border-2`,r?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`,`bg-white`,`dark:bg-mint-elevated`,...this._containerRingClasses(r)];this._container.className=e.join(` `),this._container.addEventListener(`pointerdown`,e=>this._onContainerPointerDown(e)),this._attachContainerFocusRingListeners(),this._chipsWrap=document.createElement(`div`),this._chipsWrap.className=`flex flex-wrap items-center gap-2`,this._chipsWrap.addEventListener(`dragover`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._chipsWrap.addEventListener(`drop`,e=>{this.hasAttribute(`sortable`)&&e.preventDefault()}),this._input=document.createElement(`input`),this._input.type=`text`,this._input.placeholder=this._placeholder,this._input.className=[`min-w-[6rem]`,`flex-1`,`bg-transparent`,`border-none`,`outline-none`,`text-sm`,`text-gray-900`,`dark:text-gray-100`,`placeholder:text-gray-400`,`dark:placeholder:text-gray-500`,`p-1.5`].join(` `),this._input.addEventListener(`keydown`,e=>{e.key===`Enter`&&(e.preventDefault(),this._addFromInput())}),this._container.appendChild(this._chipsWrap),this.appendChild(this._container)}if(this._input&&(this.isPredefinedOnly()&&this._predefinedTags.length>0?this._input.setAttribute(`readonly`,`true`):this._input.removeAttribute(`readonly`)),this._container){let e=[`flex`,`flex-wrap`,`items-center`,`gap-2`,`w-full`,`px-2`,`py-1`,`min-h-[2rem]`,`rounded-lg`,`border-2`,r?`border-red-300 dark:border-red-300`:`border-gray-200 dark:border-mint-divider`,`bg-white`,`dark:bg-mint-elevated`,...this._containerRingClasses(r)];this._container.className=e.join(` `)}let a=this.querySelector(`.mint-tags-label-container`);if(t){a||(a=document.createElement(`div`),a.className=`mint-tags-label-container mb-[.25rem]`,this._container&&this._container.parentElement===this?this.insertBefore(a,this._container):this.insertBefore(a,this.firstChild));let e=a.querySelector(`.mint-tags-label`);t?(e||(e=document.createElement(`label`),e.className=`mint-tags-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none`,a.appendChild(e)),e.textContent=t,e.setAttribute(`for`,i)):e&&e.remove()}else a&&a.remove();let o=this.querySelector(`.mint-tags-info`);n?(o||(o=document.createElement(`span`),o.className=`mint-tags-info text-xs text-gray-500 dark:text-gray-400 select-none mt-1 block`,this._container&&this._container.parentElement===this?this.insertBefore(o,this._container.nextSibling):this.appendChild(o)),o.textContent=n):o&&o.remove();let s=this.getName();s?(this.setAttribute(`name`,s),this._input&&(this._input.name=s,this._input.id=i)):(this.removeAttribute(`name`),this._input&&(this._input.removeAttribute(`name`),this._input.id=i)),this._wireInputBackspace(),this._renderChips(),this._renderPredefinedPopover(),this._renderErrorState(),this._renderSkeleton(e)}_getAvailablePredefinedTags(){let e=new Set(this._tags.map(e=>e.value.toLowerCase()));return this._predefinedTags.filter(t=>!e.has(t.value.toLowerCase()))}_shouldShowInput(){return this._input?!this.isPredefinedOnly()||!this._predefinedTags.length?!0:this._getAvailablePredefinedTags().length>0:!1}_disconnectPredefinedFieldResizeObserver(){this._predefinedFieldResizeObserver&&=(this._predefinedFieldResizeObserver.disconnect(),null),this._predefinedPopoverBodyEl=null}_syncPredefinedPopoverBodyMinWidth(e){if(!this._container)return;let t=this._container.offsetWidth;t>0?e.style.minWidth=`${Math.max(t,200)}px`:e.style.minWidth=`12rem`}_attachPredefinedFieldResizeObserver(e){if(this._disconnectPredefinedFieldResizeObserver(),!this._container||typeof ResizeObserver>`u`){this._syncPredefinedPopoverBodyMinWidth(e);return}this._predefinedPopoverBodyEl=e,this._predefinedFieldResizeObserver=new ResizeObserver(()=>{!this._predefinedPopoverBodyEl||!this._container||this._syncPredefinedPopoverBodyMinWidth(this._predefinedPopoverBodyEl)}),this._predefinedFieldResizeObserver.observe(this._container),this._syncPredefinedPopoverBodyMinWidth(e)}_renderPredefinedPopover(){if(!this._container||!this._chipsWrap||(this._disconnectPredefinedFieldResizeObserver(),this.querySelectorAll(`[data-mint-tags-predefined="true"]`).forEach(e=>e.remove()),!this._predefinedTags.length)||!this._input||!this._input.id)return;let e=this._getAvailablePredefinedTags();if(this.isPredefinedOnly()&&e.length===0)return;let t=`${this.getAttribute(`id`)||this._input.id}-tags-field`;this._container.id=t;let n=document.createElement(`mint-popover`);n.setAttribute(`trigger-id`,t),n.setAttribute(`trigger-toggle`,`false`),n.setAttribute(`trigger-align`,`start`),n.setAttribute(`direction`,`down`),n.setAttribute(`padding`,`0`),n.setAttribute(`distance`,`6px`),n.dataset.mintTagsPredefined=`true`;let r=document.createElement(`div`);if(r.dataset.mintTagsPredefinedBody=`true`,r.className=`box-border flex w-full min-w-0 flex-col gap-0.5 bg-white p-1 dark:bg-mint-elevated`,r.addEventListener(`mousedown`,e=>{e.preventDefault()}),e.length)e.forEach(e=>{let t=document.createElement(`mint-button`);t.setAttribute(`type`,`button`),t.setAttribute(`variant`,`ghost`),t.setAttribute(`full-width`,`true`),t.setAttribute(`align`,`left`),t.className=`w-full justify-start`,t.textContent=e.label||e.value,t.addEventListener(`mousedown`,e=>{e.preventDefault()},!0),t.addEventListener(`click`,()=>{this._addTag(e),n.removeAttribute(`open`),requestAnimationFrame(()=>{this._input?.focus({preventScroll:!0}),this._container?.setAttribute(`data-mint-tags-active`,`true`)})}),r.appendChild(t)});else{let e=document.createElement(`div`);e.className=`px-2 py-1 text-xs text-gray-500 dark:text-gray-400`,e.textContent=`No tags available`,r.appendChild(e)}n.appendChild(r),this._container.appendChild(n),this._attachPredefinedPopoverOpenOnInputFocus(),this._attachPredefinedFieldResizeObserver(r)}_getPredefinedPopoverEl(){return this.querySelector(`mint-popover[data-mint-tags-predefined="true"]`)}_attachPredefinedPopoverOpenOnInputFocus(){!this._input||!this._predefinedTags.length||this._predefinedPopoverOpenListenersAttached||(this._predefinedPopoverOpenListenersAttached=!0,this._input.addEventListener(`focus`,()=>{if(this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this.isLoading())return;let e=this._getPredefinedPopoverEl();e&&e.setAttribute(`open`,`true`)}),this._input.addEventListener(`blur`,()=>{this._predefinedBlurCloseTimer!==null&&window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=window.setTimeout(()=>{if(this._predefinedBlurCloseTimer=null,this._suppressNextPredefinedBlurClose){this._suppressNextPredefinedBlurClose=!1;return}this._getPredefinedPopoverEl()?.removeAttribute(`open`)},150)}))}_renderSkeleton(e){let t=this._container;if(!t)return;t.classList.contains(`relative`)||t.classList.add(`relative`);let n=t.querySelector(`.mint-tags-skeleton`);e?(n||(n=document.createElement(`div`),n.className=`mint-tags-skeleton absolute inset-0 z-10 pointer-events-none rounded-lg bg-gray-200 dark:bg-mint-hover animate-pulse`,t.appendChild(n)),n.style.display=`block`,this._chipsWrap&&(this._chipsWrap.style.visibility=`hidden`,this._chipsWrap.style.pointerEvents=`none`),this._input&&(this._input.style.visibility=`hidden`,this._input.style.pointerEvents=`none`)):(n&&(n.style.display=`none`),this._chipsWrap&&(this._chipsWrap.style.visibility=`visible`,this._chipsWrap.style.pointerEvents=`auto`),this._input&&(this._input.style.visibility=`visible`,this._input.style.pointerEvents=`auto`))}_renderErrorState(){let e=this.hasError(),t=this.getErrorMessage(),n=this.querySelector(`.mint-tags-error`);e&&t?(n||(n=document.createElement(`div`),n.className=`mint-tags-error mt-1 text-xs text-red-600 dark:text-red-400`,this.appendChild(n)),n.textContent=t):n&&n.remove()}_renderChips(){if(!this._chipsWrap)return;this._chipsWrap.innerHTML=``;let e=0;this._tags.forEach(t=>{let n=document.createElement(`mint-chip`);n.dataset.index=String(e++),n.dataset.value=t.value,n.draggable=this.hasAttribute(`sortable`),n.draggable&&n.classList.add(`cursor-move`),t.dismissable&&(n.setAttribute(`dismissable`,`true`),n.addEventListener(`dismissed`,()=>this._removeTag(t.value))),this._chipsWrap.appendChild(n);let r=n.querySelector(`[data-mt-chip-text]`);r&&(r.textContent=t.label||t.value),this._setupChipEvents(n,t),n.draggable&&(n.addEventListener(`dragstart`,e=>this._onDragStart(e,n)),n.addEventListener(`dragover`,e=>this._onDragOverChip(e,n)),n.addEventListener(`drop`,e=>this._onDrop(e)),n.addEventListener(`dragend`,()=>this._onDragEnd())),this.hasAttribute(`sortable`)&&n.addEventListener(`pointerdown`,e=>this._onPointerDown(e,n))}),this._input&&this._shouldShowInput()&&(this.hasAttribute(`sortable`)&&(this._input.addEventListener(`dragover`,e=>this._onDragOverInput(e)),this._input.addEventListener(`drop`,e=>this._onDrop(e)),this._input.addEventListener(`dragend`,()=>this._onDragEnd())),this._chipsWrap.appendChild(this._input))}_addFromInput(){if(!this._input)return;let e=this._input.value.trim();if(!e)return;if(this._tags.some(t=>t.value.toLowerCase()===e.toLowerCase())){this._input.value=``;return}let t=this._predefinedTags.find(t=>t.value.toLowerCase()===e.toLowerCase());if(this.isPredefinedOnly()){if(!t){this._input.value=``;return}this._addTag(t)}else this._addTag(t||{value:e,label:e,dismissable:!0});this._input.value=``,setTimeout(()=>{this._input?.focus()},10)}_addTag(e){this._tags.some(t=>t.value.toLowerCase()===e.value.toLowerCase())||(this._tags.push({value:e.value,label:e.label||e.value,dismissable:e.dismissable!==!1}),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange())}_removeTag(e){this._tags=this._tags.filter(t=>t.value!==e),this._syncAttr(),this._renderChips(),this._renderPredefinedPopover(),this._emitChange()}_emitChange(){this.dispatchEvent(new CustomEvent(`tags-change`,{bubbles:!0,composed:!0,detail:{tags:this.tags}}))}_focusLastChip(){let e=this._chipsWrap?.querySelectorAll(`mint-chip`);e&&e.length>0&&e[e.length-1].focus({preventScroll:!0})}_focusInput(){setTimeout(()=>{this._input?.focus({preventScroll:!0})},10)}_wireInputBackspace(){this._input&&this._input.addEventListener(`keydown`,e=>{e.key===`Backspace`&&this._input?.value===``&&(e.preventDefault(),this._focusLastChip())})}_setupChipEvents(e,t){e.tabIndex=0,e.addEventListener(`keydown`,e=>{(e.key===`Backspace`||e.key===`Delete`)&&t.dismissable&&(e.preventDefault(),this._removeTag(t.value),this._focusInput())})}_onContainerPointerDown(e){if(!this._input||!this._input.isConnected||this._input.parentElement!==this._chipsWrap||e.button!==0||e.defaultPrevented)return;let t=e.composedPath();if(!t.some(e=>e===this._input)&&!t.some(e=>e instanceof Element&&e.closest(`mint-chip`)!=null)){this._predefinedBlurCloseTimer!==null&&(window.clearTimeout(this._predefinedBlurCloseTimer),this._predefinedBlurCloseTimer=null),this._suppressNextPredefinedBlurClose=!0,e.preventDefault();try{this._input.focus({preventScroll:!0})}catch{}this._predefinedTags.length>0&&this._getPredefinedPopoverEl()?.setAttribute(`open`,`true`)}}_onDragStart(e,t){this.hasAttribute(`sortable`)&&(this._dragChip=t,this._dragIndex=Number(t.dataset.index),e.dataTransfer?.setData(`text/plain`,t.dataset.index||``),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.dropEffect=`move`),t.classList.add(`opacity-60`))}_reorderTags(e,t){if(e<0||t<0||e>=this._tags.length||t>=this._tags.length)return;let n=[...this._tags],[r]=n.splice(e,1);n.splice(t,0,r),this._tags=n,this._syncAttr(),this._renderChips(),this._emitChange()}_onDragOverInput(e){this.hasAttribute(`sortable`)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),this._dragChip&&this._chipsWrap&&this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input))}_onDragOverChip(e,t){if(!this.hasAttribute(`sortable`)||(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`move`),!this._dragChip||!this._chipsWrap)||t===this._dragChip)return;let n=t.getBoundingClientRect();if(e.clientX<n.left+n.width*.5){if(this._dragChip.nextSibling===t)return;this._chipsWrap.insertBefore(this._dragChip,t)}else{if(t.nextSibling===this._dragChip)return;let e=t.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}}_onDrop(e){this.hasAttribute(`sortable`)&&e.preventDefault()}_onDragEnd(){this._dragChip&&this._dragChip.classList.remove(`opacity-60`),this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}_syncOrderFromDom(){if(!this._chipsWrap)return;let e=Array.from(this._chipsWrap.querySelectorAll(`mint-chip`));if(e.length===0)return;let t=[];e.forEach(e=>{let n=e.dataset.value;if(!n)return;let r=this._tags.find(e=>e.value===n);r&&t.push(r)}),t.length===this._tags.length&&(this._tags=t,this._syncAttr(),this._renderChips(),this._emitChange())}_onPointerDown(e,t){if(this.hasAttribute(`sortable`)&&e.pointerType!==`mouse`){this._isPointerDragging=!0,this._dragChip=t,this._dragIndex=Number(t.dataset.index);try{t.setPointerCapture(e.pointerId)}catch{}t.classList.add(`opacity-60`,`select-none`),e.preventDefault()}}_onPointerMove(e){if(!this._isPointerDragging||!this._dragChip||!this._chipsWrap||e.pointerType===`mouse`)return;let t=document.elementFromPoint(e.clientX,e.clientY);if(!t)return;let n=t.closest(`mint-chip`);if(n&&n!==this._dragChip){let t=n.getBoundingClientRect();if(e.clientX<t.left+t.width*.5)this._dragChip.nextSibling!==n&&this._chipsWrap.insertBefore(this._dragChip,n);else if(n.nextSibling!==this._dragChip){let e=n.nextSibling;e?this._chipsWrap.insertBefore(this._dragChip,e):this._chipsWrap.appendChild(this._dragChip)}return}this._input&&t.closest(`input`)===this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input)}_onPointerUp(e){if(this._isPointerDragging){if(this._isPointerDragging=!1,this._dragChip){try{this._dragChip.releasePointerCapture(e.pointerId)}catch{}this._dragChip.classList.remove(`opacity-60`,`select-none`)}this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}}};customElements.get(`mint-tags`)||customElements.define(`mint-tags`,j);var ee=class extends HTMLElement{constructor(...e){super(...e),this._clickHandler=null,this._keydownHandler=null}connectedCallback(){this._render(),this._setupEventListeners()}disconnectedCallback(){this._cleanupEventListeners()}_render(){this.classList.add(`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-offset-1`,`focus-visible:ring-gray-400`,`dark:focus-visible:ring-gray-500`,`rounded`),this.getAttribute(`disabled`)===`true`?this.classList.add(`cursor-not-allowed`,`opacity-50`):this.classList.add(`cursor-pointer`),this.getAttribute(`role`)||this.setAttribute(`role`,`button`),this.getAttribute(`tabindex`)||this.setAttribute(`tabindex`,`0`)}_setupEventListeners(){this._clickHandler=e=>{if(this.getAttribute(`disabled`)===`true`){e.preventDefault(),e.stopPropagation();return}this._handleClick(e)},this._keydownHandler=e=>{if(e.key===`Enter`||e.key===` `){if(this.getAttribute(`disabled`)===`true`){e.preventDefault(),e.stopPropagation();return}e.preventDefault(),this._handleClick(e)}},this.addEventListener(`click`,this._clickHandler),this.addEventListener(`keydown`,this._keydownHandler)}_cleanupEventListeners(){this._clickHandler&&=(this.removeEventListener(`click`,this._clickHandler),null),this._keydownHandler&&=(this.removeEventListener(`keydown`,this._keydownHandler),null)}_handleClick(e){this.dispatchEvent(new CustomEvent(`clickable-click`,{bubbles:!0,composed:!0,detail:{originalEvent:e}}))}static get observedAttributes(){return[`disabled`]}attributeChangedCallback(e,t,n){e===`disabled`&&(n===`true`?(this.classList.remove(`cursor-pointer`),this.classList.add(`opacity-50`,`cursor-not-allowed`),this.setAttribute(`aria-disabled`,`true`)):(this.classList.remove(`opacity-50`,`cursor-not-allowed`),this.classList.add(`cursor-pointer`),this.removeAttribute(`aria-disabled`)))}};customElements.get(`mint-clickable`)||customElements.define(`mint-clickable`,ee);var M=class extends HTMLElement{static get observedAttributes(){return[`heading`,`dismissable`,`tone`]}constructor(){super(),this._headingElement=null,this._iconElement=null,this._dismissButton=null,this._headerWrapper=null,this._bodyWrapper=null,this._dismissHandler=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`),this.render()}disconnectedCallback(){this._dismissButton&&this._dismissHandler&&this._dismissButton.removeEventListener(`click`,this._dismissHandler)}attributeChangedCallback(e,t,n){t!==n&&this.render()}getHeading(){return this.getAttribute(`heading`)||``}getTone(){let e=this.getAttribute(`tone`);return e===`info`||e===`success`||e===`warning`||e===`danger`?e:`info`}isDismissable(){return this.getAttribute(`dismissable`)===`true`}getIconName(){switch(this.getTone()){case`info`:return`info`;case`success`:return`success`;case`warning`:return`warning`;case`danger`:return`error`;default:return`info`}}getIconColorClasses(){switch(this.getTone()){case`info`:return`text-gray-700 dark:text-gray-300`;case`success`:return`text-green-600 dark:text-green-400`;case`warning`:return`text-yellow-600 dark:text-yellow-400`;case`danger`:return`text-red-600 dark:text-red-400`;default:return`text-gray-700 dark:text-gray-300`}}getHeadingColorClasses(){return`text-gray-900 dark:text-gray-100`}getHeaderBackgroundClasses(){switch(this.getTone()){case`info`:return`bg-gray-100 dark:bg-white/5`;case`success`:return`bg-green-100 dark:bg-green-900/30`;case`warning`:return`bg-yellow-100 dark:bg-yellow-900/30`;case`danger`:return`bg-red-100 dark:bg-red-900/30`;default:return`bg-gray-100 dark:bg-white/5`}}getBorderClasses(){switch(this.getTone()){case`info`:return`border-gray-200 dark:border-mint-divider`;case`success`:return`border-green-200 dark:border-green-800`;case`warning`:return`border-yellow-200 dark:border-yellow-800`;case`danger`:return`border-red-200 dark:border-red-800`;default:return`border-gray-200 dark:border-mint-divider`}}getAriaLive(){return this.getTone()===`danger`?`assertive`:`polite`}render(){let e=this.getTone(),t=this.getHeading(),n=this.isDismissable();this.className=`box-border m-0 p-0 border-0 align-baseline block rounded-lg border shadow-sm overflow-hidden ${this.getBorderClasses()}`;let r=this.getAriaLive();this.setAttribute(`role`,`alert`),this.setAttribute(`aria-live`,r),e===`danger`?this.setAttribute(`aria-atomic`,`true`):this.removeAttribute(`aria-atomic`);let i=[];for(this._bodyWrapper?Array.from(this._bodyWrapper.childNodes).forEach(e=>{i.push(e)}):Array.from(this.childNodes).forEach(e=>{e!==this._headerWrapper&&e!==this._bodyWrapper&&e!==this._iconElement&&e!==this._headingElement&&e!==this._dismissButton&&i.push(e)}),this._dismissButton&&this._dismissHandler&&this._dismissButton.removeEventListener(`click`,this._dismissHandler);this.firstChild;)this.removeChild(this.firstChild);if(this._headerWrapper=null,this._bodyWrapper=null,this._iconElement=null,this._headingElement=null,this._dismissButton=null,this._headerWrapper=document.createElement(`div`),this._headerWrapper.className=`px-4 py-3 flex items-center gap-3 ${this.getHeaderBackgroundClasses()}`,this._iconElement=document.createElement(`mint-icon`),this._iconElement.setAttribute(`name`,this.getIconName()),this._iconElement.className=`flex-shrink-0 w-5 h-5 ${this.getIconColorClasses()}`,this._headerWrapper.appendChild(this._iconElement),this._headingElement=document.createElement(`mint-text`),this._headingElement.className=`font-semibold flex-1 ${this.getHeadingColorClasses()}`,this._headingElement.textContent=t||``,this._headerWrapper.appendChild(this._headingElement),n){this._dismissButton=document.createElement(`button`),this._dismissButton.className=`flex-shrink-0 p-1 rounded hover:bg-black/10 dark:hover:bg-white/10`,this._dismissButton.setAttribute(`aria-label`,`Dismiss alert`),this._dismissButton.setAttribute(`type`,`button`);let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`close`),e.className=`w-4 h-4 text-gray-700 dark:text-gray-300`,this._dismissButton.appendChild(e),this._dismissHandler=e=>{e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent(`dismissed`,{bubbles:!0,composed:!0})),this.remove()},this._dismissButton.addEventListener(`click`,this._dismissHandler),this._headerWrapper.appendChild(this._dismissButton)}this._bodyWrapper=document.createElement(`div`),this._bodyWrapper.className=`px-4 py-3 bg-white dark:bg-mint-elevated`,i.forEach(e=>{this._bodyWrapper.appendChild(e)}),this.appendChild(this._headerWrapper),this.appendChild(this._bodyWrapper)}};customElements.get(`mint-alert`)||customElements.define(`mint-alert`,M);var te=class extends HTMLElement{static get observedAttributes(){return[`configuration`,`loading`,`virtual-scroll`,`virtual-scroll-root`,`virtual-row-height`,`virtual-max-height`,`fixed-header`,`fixed-controls`]}_isExternalLoading(){let e=this.getAttribute(`loading`);return e!==null&&e!==`false`}constructor(){super(),this._configuration=null,this._rows=[],this._search=``,this._currentPage=1,this._perPage=15,this._totalRows=0,this._lastPage=0,this._offset=0,this._loaded=!1,this._fetching=!1,this._loading=!1,this._loadingPage=null,this._fetchError=null,this._searching=!1,this._sorting=!1,this._sortingColumn=null,this._type=`provided`,this._searchTimeoutId=null,this._sortTimeoutId=null,this._searchColumns=[],this._exportColumns={},this._columns=[],this._tableId=``,this._searchInput=null,this._tableContainer=null,this._paginationContainer=null,this._skeletonContainer=null,this._inMintCard=!1,this._virtualBodyScrollEl=null,this._virtualScrollHandler=null,this._virtualWindowRaf=null,this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``,this._virtualResizeObserver=null,this._virtualWindowResizeHandler=null,this._virtualRowCache=new Map,this._virtualRangeFetching=!1,this._mobileListMql=null,this._boundMobileListMqlListener=null,this._virtualFetchGeneration=0,this._virtualAjaxPrefetchTimer=null,this._fixedChromeResizeObserver=null}get inMintCard(){return this._inMintCard}get configuration(){return this._configuration}set configuration(e){e&&typeof e==`object`&&!Array.isArray(e)?(this._configuration=e,this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._type=typeof this._configuration.data==`string`?`ajax`:`provided`,this._loaded=!1,this._currentPage=1,this._offset=0,this._type===`provided`&&Array.isArray(this._configuration.data)&&(this._rows=[...this._configuration.data],this._totalRows=this._configuration.data.length),this._initializeColumns(),this.isConnected&&this.render()):e==null?this._configuration=null:this._parseConfiguration()}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`),this._inMintCard=this.parentElement?.tagName?.toLowerCase()===`mint-card`,this._configuration||this._parseConfiguration(),this._initializeColumns(),this._loadPageFromUrl(),this._attachRowClickHandler(),this.render()}disconnectedCallback(){this._searchTimeoutId&&clearTimeout(this._searchTimeoutId),this._detachVirtualScroll(),this._detachFixedChromeResize(),this._detachMobileListMql(),this._rowClickHandler&&=(this.removeEventListener(`click`,this._rowClickHandler,!0),null),this._scrollHandler&&=(window.removeEventListener(`scroll`,this._scrollHandler),null)}attributeChangedCallback(e,t,n){e===`configuration`&&t!==n?(!this._configuration||typeof n==`string`)&&(this._parseConfiguration(),this.render()):t!==n&&(e===`loading`||e===`virtual-scroll`||e===`virtual-scroll-root`||e===`virtual-row-height`||e===`virtual-max-height`||e===`fixed-header`||e===`fixed-controls`)&&this._configuration&&this.isConnected&&this.render()}refresh(){this._configuration&&(this._type===`ajax`?this._fetchData(void 0,!0,this._perPage,this._offset):(Array.isArray(this._configuration.data)&&(this._rows=[...this._configuration.data],this._totalRows=this._rows.length),this.render()))}setData(e){if(this._configuration){if(this._configuration.data=e,this._type=typeof e==`string`?`ajax`:`provided`,this._currentPage=1,this._offset=0,this._fetchError=null,this._searching=!1,this._loadingPage=null,this._sortTimeoutId&&=(clearTimeout(this._sortTimeoutId),null),this._searchTimeoutId&&=(clearTimeout(this._searchTimeoutId),null),this._virtualScrollActive()&&(this._virtualRowCache.clear(),this._virtualInvalidate()),this._type===`ajax`){this._rows=[],this._totalRows=0,this._lastPage=0,this._loaded=!1,this._fetching=!1,this._loading=!1,this._fetchData(void 0,!0,this._perPage,0);return}this._rows=Array.isArray(e)?[...e]:[],this._totalRows=this._rows.length,this._lastPage=Math.max(1,Math.ceil(this._totalRows/this._perPage)),this._loaded=!0,this._fetching=!1,this._loading=!1,this.render()}}_parseConfiguration(){let e=this.getAttribute(`configuration`);if(!e){console.error(`mint-resource-table: configuration attribute is required`);return}try{this._configuration=JSON.parse(e),this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._type=typeof this._configuration.data==`string`?`ajax`:`provided`,this._loaded=!1,this._currentPage=this._getPageFromUrl()||1,this._offset=(this._currentPage-1)*this._perPage,this._type===`provided`&&Array.isArray(this._configuration.data)&&(this._rows=[...this._configuration.data],this._totalRows=this._configuration.data.length),this._initializeColumns()}catch(e){console.error(`mint-resource-table: Invalid configuration JSON`,e)}}_initializeColumns(){this._configuration&&(this._searchColumns=[],this._exportColumns={},this._columns=[],this._configuration.columns.forEach(e=>{e.searchable&&e.data&&this._searchColumns.push(e.data),e.export&&e.data&&(this._exportColumns[e.data]=e.label),e.data&&this._columns.push(e.data)}),this._configuration.sortBy||(this._configuration.sortBy=`id`),this._configuration.sort||(this._configuration.sort=`asc`))}async _fetchData(e,t=!0,n,r){if(!this._configuration)return;let i=e||(typeof this._configuration.data==`string`?this._configuration.data:null);if(!i||this._fetching||this._loading)return;t&&(this._fetching=!0,this._loaded?this._updatePagination():this.render()),this._loading=!0;let a=n||this._perPage,o=r===void 0?this._offset:r;this._virtualScrollActive()&&this._type===`ajax`&&o===0&&(this._virtualFetchGeneration++,this._virtualRowCache.clear(),this._virtualInvalidate());try{let e=new URLSearchParams({perPage:a.toString(),offset:o.toString(),search:this._search,sortBy:this._configuration.sortBy||`id`,sort:this._configuration.sort||`asc`,searchColumns:this._searchColumns.join(`,`),columns:this._columns.join(`,`)}),t={};this._configuration.headers&&(t.headers=this._configuration.headers);let n=await fetch(`${i}?${e.toString()}`,t);if(!n.ok)throw Error(`HTTP error! status: ${n.status}`);let r=await n.json(),s=r.content?.rows||[],c=r.content?.total||0,l=s;this._configuration.predefinedData?(l=[...this._configuration.predefinedData,...s],this._totalRows=c+this._configuration.predefinedData.length):this._totalRows=c,this._rows=l;let u=Math.floor(o/a)+1;r.content?.current_page!==void 0&&r.content.current_page===u?this._currentPage=r.content.current_page:this._currentPage=u,this._offset=(this._currentPage-1)*a,this._lastPage=r.content?.last_page||1,this._fetching=!1,this._loaded=!0,this._loading=!1,this._fetchError=null,this._searching=!1;let d=this._sorting;d&&this._updateSortIcons(),this._sorting=!1,this._sortingColumn=null,d&&this._updateSortIcons(),this.dispatchEvent(new CustomEvent(`loaded`,{detail:{rows:this._rows}})),this._updateSearchIcon();let f=`tbody[data-mint-rt-tbody="${this._tableId}"]`,p=!!this.querySelector(f);if(this._virtualScrollActive()&&this._type===`ajax`)p||this.render(),s.forEach((e,t)=>{this._virtualRowCache.set(o+t,e)}),this._virtualInvalidate(),o===0?queueMicrotask(()=>this._scrollVirtualTableTopIntoView()):this._scheduleVirtualWindowSync(),this._loadingPage,this._loadingPage=null,this._updatePagination(),setTimeout(()=>{let e=this._paginationMountedRoot();e&&e.querySelectorAll(`mint-button[data-action="page"]`).forEach(e=>{`render`in e&&typeof e.render==`function`&&e.render()})},0);else if(this.querySelector(`#${this._tableId}`)?.closest(`table`)?.querySelector(`tbody`)){if(d){let e=this._loading,t=this._fetching;this._loading=!1,this._fetching=!1,this._updateTableBody(),this._loading=e,this._fetching=t}else this._updateTableBody();this._loadingPage,this._loadingPage=null,this._updatePagination(),setTimeout(()=>{let e=this._paginationMountedRoot();e&&e.querySelectorAll(`mint-button[data-action="page"]`).forEach(e=>{`render`in e&&typeof e.render==`function`&&e.render()})},0)}else this.render()}catch(e){this._fetching=!1,this._loading=!1,this._loadingPage=null,this._loaded=!0,this._searching=!1,this._fetchError=e instanceof Error?e.message:`Failed to fetch data`,console.error(`mint-resource-table: Error fetching data`,e),this._updateSearchIcon(),this.querySelector(`#${this._tableId}`)?.closest(`table`)?.querySelector(`tbody`)?(this._updateTableBody(),this._loadingPage=null,this._updatePagination()):this.render()}}_getRows(){if(!this._configuration)return[];if(this._type===`ajax`)return this._rows;let e=[...this._rows],t=this._configuration.sortBy||`id`,n=this._configuration.sort||`asc`;if(this._search){let t=this._search.toLowerCase().trim().split(/\s+/);e=e.filter(e=>{let n=Object.values(e).map(e=>String(e).toLowerCase()).join(` `);return t.every(e=>n.includes(e))})}if(e.sort((e,r)=>{let i=e[t],a=r[t];if(i==null&&a==null)return 0;if(i==null)return 1;if(a==null)return-1;let o=typeof i==`number`?i:typeof i==`string`&&!isNaN(Number(i))&&i.trim()!==``?Number(i):null,s=typeof a==`number`?a:typeof a==`string`&&!isNaN(Number(a))&&a.trim()!==``?Number(a):null;if(o!==null&&s!==null){let e=o-s;return n===`asc`?e:-e}let c=i instanceof Date?i:typeof i==`string`?new Date(i):null,l=a instanceof Date?a:typeof a==`string`?new Date(a):null;if(c&&l&&!isNaN(c.getTime())&&!isNaN(l.getTime())){let e=c.getTime()-l.getTime();return n===`asc`?e:-e}let u=String(i).localeCompare(String(a),void 0,{numeric:!0,sensitivity:`base`});return n===`asc`?u:-u}),this._perPage){let t=Math.ceil(e.length/this._perPage);this._lastPage=t,e.forEach((e,t)=>{e.page=Math.ceil((t+1)/this._perPage)}),this._currentPage>t&&t>0&&(this._currentPage=t)}return e.filter(e=>!this._perPage||e.page===this._currentPage)}_getAllFilteredRowsSorted(){if(!this._configuration||this._type!==`provided`)return[];let e=[...this._rows],t=this._configuration.sortBy||`id`,n=this._configuration.sort||`asc`;if(this._search){let t=this._search.toLowerCase().trim().split(/\s+/);e=e.filter(e=>{let n=Object.values(e).map(e=>String(e).toLowerCase()).join(` `);return t.every(e=>n.includes(e))})}if(e.sort((e,r)=>{let i=e[t],a=r[t];if(i==null&&a==null)return 0;if(i==null)return 1;if(a==null)return-1;let o=typeof i==`number`?i:typeof i==`string`&&!isNaN(Number(i))&&i.trim()!==``?Number(i):null,s=typeof a==`number`?a:typeof a==`string`&&!isNaN(Number(a))&&a.trim()!==``?Number(a):null;if(o!==null&&s!==null){let e=o-s;return n===`asc`?e:-e}let c=i instanceof Date?i:typeof i==`string`?new Date(i):null,l=a instanceof Date?a:typeof a==`string`?new Date(a):null;if(c&&l&&!isNaN(c.getTime())&&!isNaN(l.getTime())){let e=c.getTime()-l.getTime();return n===`asc`?e:-e}let u=String(i).localeCompare(String(a),void 0,{numeric:!0,sensitivity:`base`});return n===`asc`?u:-u}),this._perPage){let t=Math.ceil(e.length/this._perPage);this._lastPage=t,e.forEach((e,t)=>{e.page=Math.ceil((t+1)/this._perPage)}),this._currentPage>t&&t>0&&(this._currentPage=t)}return e.filter(e=>!this._perPage||e.page===this._currentPage)}_virtualInvalidate(){this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``}_getRowDataForEventIndex(e){if(this._configuration){if(!this._virtualScrollActive())return this._getRows()[e];if(this._type===`provided`)return this._getAllFilteredRowsSorted()[e];if(this._type===`ajax`)return this._virtualRowCache.get(e)}}getRowByIndex(e){return this._getRowDataForEventIndex(e)}_virtualScrollActive(){return this._configuration?(this.getAttribute(`virtual-scroll`)||``).toLowerCase().trim()===`true`:!1}_virtualScrollRoot(){let e=(this.getAttribute(`virtual-scroll-root`)||``).toLowerCase().trim();return e===`table-body`||e===`body`||this._configuration?.virtualScrollRoot===`table-body`?`table-body`:`document`}_virtualBodyScrollDisablesDocumentFixedChrome(){return this._virtualScrollActive()&&this._virtualScrollRoot()===`table-body`}_fixedHeader(){if(this._virtualBodyScrollDisablesDocumentFixedChrome()||!this.hasAttribute(`fixed-header`))return!1;let e=(this.getAttribute(`fixed-header`)||``).toLowerCase().trim();return e!==`false`&&e!==`0`}_fixedControls(){if(this._virtualBodyScrollDisablesDocumentFixedChrome()||!this.hasAttribute(`fixed-controls`))return!1;let e=(this.getAttribute(`fixed-controls`)||``).toLowerCase().trim();return e!==`false`&&e!==`0`}_virtualRowHeightPx(){let e=parseInt(this.getAttribute(`virtual-row-height`)||``,10);if(!isNaN(e)&&e>0)return e;let t=this._configuration?.virtualRowHeight;return typeof t==`number`&&t>0?t:48}_virtualRowHeightPxForSync(e){let t=this._virtualRowHeightPx();if(!this._configuration)return t;if(e){let e=this._mobileThumbnailColumn();if(e){let n=this._thumbnailMobilePx(e);return Math.max(t,n+36)}return Math.max(t,80)}let n=this._mobileThumbnailColumn();if(n){let e=this._thumbnailDesktopPx(n);return Math.max(t,e+28)}return t}_virtualMaxHeightCss(){let e=this.getAttribute(`virtual-max-height`);if(e&&e.trim())return e.trim();let t=this._configuration?.virtualMaxHeight;return t&&String(t).trim()?String(t).trim():`min(70dvh, 28rem)`}_virtualColspan(){return this._configuration?Math.max(1,this._configuration.columns.filter(e=>!e.hidden).length):1}_ensureMobileListMql(){typeof window>`u`||!window.matchMedia||this._mobileListMql||(this._mobileListMql=window.matchMedia(`(max-width: 767px)`),this._boundMobileListMqlListener=()=>{this._configuration&&this.isConnected&&this.render()},this._mobileListMql.addEventListener(`change`,this._boundMobileListMqlListener))}_detachMobileListMql(){this._mobileListMql&&this._boundMobileListMqlListener&&this._mobileListMql.removeEventListener(`change`,this._boundMobileListMqlListener),this._mobileListMql=null,this._boundMobileListMqlListener=null}_useMobileListLayout(){return!!this._mobileListMql?.matches}_paginationHostPlaceholderHtml(){if(!this._configuration?.perPage||this._virtualScrollActive())return``;let e=this._lastPage||Math.ceil(this._rows.length/this._perPage);if((this._lastPage>0?this._lastPage:e)<=1)return``;let t=[`mint-rt-pagination-host`,`w-full min-w-0 overflow-x-auto overflow-y-hidden overscroll-x-contain`,`flex justify-center [-webkit-overflow-scrolling:touch] md:justify-end`,this._inMintCard?`border-t border-gray-200 px-3.5 pb-3.5 pt-3 dark:border-mint-divider md:border-t-0 md:pt-0`:`border-t border-gray-200 px-2 py-3 dark:border-mint-divider md:border-t-0 md:py-0 md:mt-4`].join(` `);return`<div id="mint-rt-pagination-host-${this._tableId}" data-mint-rt-pagination-wrap="" class="${t}"></div>`}_getPaginationHostEl(){return this.querySelector(`#mint-rt-pagination-host-${this._tableId}`)}_paginationMountedRoot(){return this._getPaginationHostEl()||this.querySelector(`nav[data-mint-rt-pagination-nav]`)?.parentElement||this.querySelector(`nav`)?.closest(`.flex.justify-end`)}_paginationPageButtonLi(e){let t=this._currentPage===e,n=this._loadingPage===e;return`<li class="shrink-0"><mint-button variant="solid" size="sm"${t?` active="true"`:``}${this._loading||this._fetching?` disabled="true"`:``}${n?` loading="true"`:``} data-action="page" data-page="${e}">${n?``:`${e}`}</mint-button></li>`}_paginationHtmlCompactMiddle(e){let t=``,n=this._currentPage;if(e<=5){for(let n=1;n<=e;n++)t+=this._paginationPageButtonLi(n);return t}let r=[...new Set([1,e,n-1,n,n+1].map(t=>Math.min(e,Math.max(1,t))))].sort((e,t)=>e-t),i=0;for(let e of r)i>0&&e-i>1&&(t+=`<li class="shrink-0"><span class="px-1 text-gray-500 dark:text-gray-400" aria-hidden="true">…</span></li>`),t+=this._paginationPageButtonLi(e),i=e;return t}_paginationHtmlDesktopMiddle(e){let t=``,n=e>=10,r=Math.max(1,this._currentPage-1),i=Math.min(e,this._currentPage+1);if(n){for(let e=1;e<=3;e++)t+=this._paginationPageButtonLi(e);let n=i<=3,a=r>=e-2;if(!n&&!a){r>4&&(t+=`<li class="shrink-0"><span class="px-2">...</span></li>`);for(let e=r;e<=i;e++)e<=3||(t+=this._paginationPageButtonLi(e));i<e-3&&(t+=`<li class="shrink-0"><span class="px-2">...</span></li>`)}else (n&&!a||!n&&a&&e-2>4)&&(t+=`<li class="shrink-0"><span class="px-2">...</span></li>`);for(let o=e-2;o<=e;o++)o<=3||!n&&!a&&o>=r&&o<=i||(t+=this._paginationPageButtonLi(o))}else for(let n=1;n<=e;n++)t+=this._paginationPageButtonLi(n);return t}_buildPaginationNavMarkup(e){let t=this._currentPage===1||this._loading||this._fetching,n=`<nav data-mint-rt-pagination-nav="" class="w-max max-w-none shrink-0" aria-label="Pagination">`;n+=`<ul class="flex flex-nowrap items-center gap-1">`,n+=`<li class="shrink-0"><mint-button variant="solid" size="sm" icon="caret-left" ${t?`disabled="true"`:``} data-action="page-prev"></mint-button></li>`,n+=this._useMobileListLayout()?this._paginationHtmlCompactMiddle(e):this._paginationHtmlDesktopMiddle(e);let r=this._currentPage>=e||this._loading||this._fetching;return n+=`<li class="shrink-0"><mint-button variant="solid" size="sm" icon="caret-right" ${r?`disabled="true"`:``} data-action="page-next"></mint-button></li>`,n+=`</ul></nav>`,n}_hasSortableColumns(){return!!this._configuration?.columns.some(e=>!e.hidden&&e.sortable&&e.data)}_getMobileSortTriggerIconName(){return`sort-arrows`}_mobileSortPopoverAffordanceInnerHtml(e){return e===`spinner`?`<span class="inline-block h-4 w-4 shrink-0 animate-spin rounded-full border-2 border-gray-300 border-t-gray-700 dark:border-gray-600 dark:border-t-gray-200" aria-hidden="true"></span>`:e===`caret-up`||e===`caret-down`?`<mint-icon name="${e}" class="h-4 w-4 shrink-0 text-gray-500 dark:text-gray-400"></mint-icon>`:``}_buildMobileSortPopoverInnerHtml(){if(!this._configuration)return``;let e=`<div class="flex w-full min-w-[11rem] flex-col gap-0.5 p-1">`;return this._configuration.columns.forEach((t,n)=>{if(t.hidden||!t.sortable||!t.data)return;let r=t.raw?t.label:this._escapeHtml(t.label),i=this._getSortClass(t),a=this._mobileSortPopoverAffordanceInnerHtml(i),o=` type="button" variant="ghost" tone="neutral" size="sm" full-width="true" align="left" data-action="mobile-sort" data-column-key="${n}"`;e+=`<mint-button${o}>`,e+=`<span class="flex w-full min-w-0 flex-1 items-center justify-between gap-2">`,e+=`<span class="min-w-0 flex-1 truncate text-left">${r}</span>`,e+=`<span class="inline-flex shrink-0 items-center justify-end" data-mint-rt-mobile-sort-affordance="">${a}</span>`,e+=`</span></mint-button>`}),e+=`</div>`,e}_syncMobileSortPopoverIcons(){if(!this._configuration)return;let e=this.querySelector(`#mint-rt-mobile-sort-popover-${this._tableId}`);e&&this._configuration.columns.forEach((t,n)=>{if(t.hidden||!t.sortable||!t.data)return;let r=e.querySelector(`[data-action="mobile-sort"][data-column-key="${n}"]`);if(!r||r.tagName!==`MINT-BUTTON`)return;let i=r.querySelector(`[data-mint-rt-mobile-sort-affordance]`);if(!i)return;let a=this._getSortClass(t);i.innerHTML=this._mobileSortPopoverAffordanceInnerHtml(a),i.querySelectorAll(`mint-icon`).forEach(e=>{let t=e;typeof t.render==`function`&&t.render()})})}_closeMobileSortPopover(){let e=this.querySelector(`#mint-rt-mobile-sort-popover-${this._tableId}`);e&&typeof e.close==`function`?e.close():e&&e.removeAttribute(`open`)}_buildMobileSortToolbarHtml(){if(!this._hasSortableColumns())return``;let e=`mint-rt-mobile-sort-btn-${this._tableId}`,t=`mint-rt-mobile-sort-popover-${this._tableId}`,n=this._sorting?` loading="true"`:``,r=` icon="${this._escapeHtml(this._getMobileSortTriggerIconName())}"`,i=`<div class="flex shrink-0 items-center md:hidden">`;return i+=`<mint-button id="${e}" data-mint-rt-toolbar="mobile-sort" variant="solid" tone="neutral" size="sm"${n}${r}></mint-button>`,i+=`<mint-popover id="${t}" trigger-id="${e}" direction="down" padding="0">`,i+=this._buildMobileSortPopoverInnerHtml(),i+=`</mint-popover></div>`,i}_stripHtml(e){if(!e)return``;let t=document.createElement(`div`);return t.innerHTML=e,(t.textContent||t.innerText||``).replace(/\s+/g,` `).trim()}_visibleDataColumns(){return this._configuration?this._configuration.columns.filter(e=>!e.hidden):[]}_mobileThumbnailColumn(){return this._visibleDataColumns().find(e=>e.thumbnail)||null}_thumbnailDesktopPx(e){let t=typeof e.thumbnailDesktopPx==`number`&&e.thumbnailDesktopPx>0?e.thumbnailDesktopPx:void 0,n=this._configuration,r=n&&typeof n.thumbnailDesktopPx==`number`&&n.thumbnailDesktopPx>0?n.thumbnailDesktopPx:void 0;return Math.round(t??r??40)}_thumbnailMobilePx(e){let t=typeof e.thumbnailMobilePx==`number`&&e.thumbnailMobilePx>0?e.thumbnailMobilePx:void 0,n=this._configuration,r=n&&typeof n.thumbnailMobilePx==`number`&&n.thumbnailMobilePx>0?n.thumbnailMobilePx:void 0;return Math.round(t??r??56)}_wrapThumbnailDesktopBox(e,t){let n=this._thumbnailDesktopPx(t);return`<div class="flex shrink-0 items-stretch overflow-hidden rounded-md border border-gray-200 bg-gray-100 p-0 dark:border-mint-divider dark:bg-mint-hover [&>*]:m-0 [&>*]:min-h-0 [&>*]:min-w-0 [&>*]:w-full [&>*]:max-w-full [&>*]:p-0 [&>span]:flex [&>span]:h-full [&>span]:w-full [&>span]:min-h-0 [&>span]:min-w-0 [&>span]:items-stretch [&>span]:justify-stretch [&_img]:!m-0 [&_img]:!box-border [&_img]:!block [&_img]:!h-full [&_img]:!w-full [&_img]:!min-h-0 [&_img]:!min-w-0 [&_img]:!max-h-full [&_img]:!max-w-full [&_img]:!border-0 [&_img]:!p-0 [&_img]:!rounded-none [&_img]:!object-cover [&_img]:!object-center" style="${`width:${n}px;height:${n}px;min-width:${n}px;min-height:${n}px`}">${e}</div>`}_mobilePrimaryColumn(){let e=this._visibleDataColumns();return e.find(e=>e.primary)||e.find(e=>(e.data||typeof e.format==`function`)&&!e.thumbnail&&!e.actions)||e[0]||null}_mobileActionsDropdownColumn(){return this._visibleDataColumns().find(e=>e.actions&&e.actionStyle!==`buttons`)||null}_columnPlainSummaryText(e,t){if(!(!e.show||e.show(this,t))||e.actions||e.action)return``;try{if(e.raw){if(typeof e.format==`function`)return this._stripHtml(e.format(this,t));if(e.data)return String(t[e.data]??``)}else{if(typeof e.format==`function`)return this._stripHtml(e.format(this,t));if(e.data)return String(t[e.data]??``)}}catch{return``}return``}_buildTableCellInnerHtml(e,t,n,r=`table`){if(!this._configuration)return``;let i=n,a=``;if(!(!e.show||e.show(this,t)))return``;if(e.raw)if(e.action){if(!e.action.show||e.action.show(this,t)){let n=typeof e.action.label==`function`?e.action.label(this,t):e.action.label;a+=`<mint-button variant="solid" data-action="column-action" data-row-index="${i}" data-column-key="${this._configuration.columns.indexOf(e)}">${this._escapeHtml(String(n))}</mint-button>`}}else if(e.actions)if(e.actionStyle!==`buttons`){let n=`actions-popover-${this._tableId}-${i}`,r=`actions-button-${this._tableId}-${i}`;a+=`<mint-button id="${r}" variant="link" icon="ellipsis">`,a+=`</mint-button>`,a+=`<mint-popover id="${n}" trigger-id="${r}" direction="down">`,e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=typeof n.label==`function`?n.label(this,t):n.label;a+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-mint-hover" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}">${this._escapeHtml(String(o))}</div>`}}),a+=`</mint-popover>`}else e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=n.label?typeof n.label==`function`?n.label(this,t):n.label:``,s=n.icon?` icon="${this._escapeHtml(n.icon)}"`:``,c=n.variant?` variant="${this._escapeHtml(n.variant)}"`:` variant="link"`,l=n.tone?` tone="${this._escapeHtml(n.tone)}"`:``;a+=`<mint-button${c} class="${n.classes||``}" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}"${s}${l}>`,o&&(a+=this._escapeHtml(String(o))),a+=`</mint-button>`}});else typeof e.format==`function`?a+=e.format(this,t):e.data&&(a+=this._escapeHtml(String(t[e.data]||``)));else if(e.action)(!e.action.show||e.action.show(this,t))&&(a+=`<mint-button variant="solid" data-action="column-action" data-row-index="${i}" data-column-key="${this._configuration.columns.indexOf(e)}">${e.action.label}</mint-button>`);else if(e.actions)if(e.actionStyle!==`buttons`){let n=`actions-popover-${this._tableId}-${i}`,r=`actions-button-${this._tableId}-${i}`;a+=`<mint-button id="${r}" variant="link" icon="ellipsis">`,a+=`</mint-button>`,a+=`<mint-popover id="${n}" trigger-id="${r}" direction="down">`,e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=typeof n.label==`function`?n.label(this,t):n.label;a+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-mint-hover" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}">${this._escapeHtml(String(o))}</div>`}}),a+=`</mint-popover>`}else e.actions.forEach((n,r)=>{if(!n.show||n.show(this,t)){let o=n.label?typeof n.label==`function`?n.label(this,t):n.label:``,s=n.icon?` icon="${this._escapeHtml(n.icon)}"`:``,c=n.variant?` variant="${this._escapeHtml(n.variant)}"`:` variant="link"`,l=n.tone?` tone="${this._escapeHtml(n.tone)}"`:``;a+=`<mint-button${c} class="${n.classes||``}" data-action="row-action" data-row-index="${i}" data-action-index="${r}" data-column-key="${this._configuration.columns.indexOf(e)}"${s}${l}>`,o&&(a+=this._escapeHtml(String(o))),a+=`</mint-button>`}});else typeof e.format==`function`?a+=this._escapeHtml(e.format(this,t)):e.data&&(a+=this._escapeHtml(String(t[e.data]||``)));return r===`table`&&e.thumbnail&&a&&!e.actions&&!e.action?this._wrapThumbnailDesktopBox(a,e):a}_buildMobileListItemHtml(e,t,n,r=!1){if(!this._configuration)return``;let i=t,a=typeof this._configuration.onRowClick==`function`,o=this._mobileThumbnailColumn(),s=this._mobilePrimaryColumn(),c=this._mobileActionsDropdownColumn(),l=o?this._buildTableCellInnerHtml(o,e,i,`mobile`):``,u=s?this._buildTableCellInnerHtml(s,e,i,`mobile`):``,d=c?this._buildTableCellInnerHtml(c,e,i,`mobile`):``,f=[],p=this._configuration.mobileShowLabels===!0;for(let t of this._configuration.columns){if(t.hidden||o&&t===o||s&&t===s||c&&t===c)continue;let n=this._columnPlainSummaryText(t,e);if(n)if(p){let e=this._stripHtml(String(t.label||``)).trim();e?f.push(`${this._escapeHtml(e)}: ${this._escapeHtml(n)}`):f.push(this._escapeHtml(n))}else f.push(this._escapeHtml(n))}let m=f.join(`<span class="text-gray-300 dark:text-gray-600" aria-hidden="true"> · </span>`),h=[`list-none`,...r?[]:[`border-b`,`border-gray-200`,`dark:border-mint-divider`],`bg-white`,`dark:bg-mint-canvas`,a?`cursor-pointer hover:bg-gray-50 dark:hover:bg-mint-elevated`:``].filter(Boolean).join(` `),g=`<div class="flex items-center gap-3 py-3 pr-4${o?` pl-0`:` pl-4`}">`;if(o){let e=this._thumbnailMobilePx(o),t=`width:${e}px;height:${e}px;min-width:${e}px;min-height:${e}px`;g+=`<div class="flex shrink-0 items-stretch overflow-hidden rounded-md border border-gray-200 bg-gray-100 p-0 dark:border-mint-divider dark:bg-mint-hover [&>*]:m-0 [&>*]:min-h-0 [&>*]:min-w-0 [&>*]:w-full [&>*]:max-w-full [&>*]:p-0 [&>span]:flex [&>span]:h-full [&>span]:w-full [&>span]:min-h-0 [&>span]:min-w-0 [&>span]:items-stretch [&>span]:justify-stretch [&_img]:!m-0 [&_img]:!box-border [&_img]:!block [&_img]:!h-full [&_img]:!w-full [&_img]:!min-h-0 [&_img]:!min-w-0 [&_img]:!max-h-full [&_img]:!max-w-full [&_img]:!border-0 [&_img]:!p-0 [&_img]:!rounded-none [&_img]:!object-cover [&_img]:!object-center" style="${t}">${l}</div>`}g+=`<div class="flex min-w-0 flex-1 flex-col justify-center gap-1">`,g+=`<div class="flex items-start justify-between gap-2">`,g+=`<div class="min-w-0 text-sm font-semibold leading-snug text-gray-900 dark:text-white">${u}</div>`,d&&(g+=`<div class="shrink-0 -mr-1">${d}</div>`),g+=`</div>`,m&&(g+=`<div class="text-xs font-normal leading-snug text-gray-500 dark:text-gray-400">${m}</div>`),g+=`</div></div>`;let _=typeof n==`number`&&n>0?` style="box-sizing:border-box;min-height:${n}px;max-height:${n}px;height:${n}px;overflow:hidden"`:``;return`<li data-row-index="${i}" ${a?`data-row-clickable="true" `:``}class="${h}"${_}>${g}</li>`}_buildMobileListPlaceholderLi(e,t,n=!1){let r=this._mobileThumbnailColumn(),i=r?this._thumbnailMobilePx(r):56,a=`width:${i}px;height:${i}px;min-width:${i}px;min-height:${i}px`;return`<li data-row-index="${e}" data-mint-rt-placeholder="true" class="list-none${n?``:` border-b border-gray-200 dark:border-mint-divider`} bg-white dark:bg-mint-canvas" style="box-sizing:border-box;min-height:${t}px;max-height:${t}px;height:${t}px;overflow:hidden"><div class="flex h-full min-h-0 items-center gap-3 py-3 pl-0 pr-4"><div class="shrink-0 overflow-hidden rounded-md bg-gray-200 dark:bg-white/15" style="${a}"></div><div class="flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 py-0.5"><div class="h-4 w-40 rounded bg-gray-200 dark:bg-white/15"></div><div class="h-3 w-full max-w-xs rounded bg-gray-200 dark:bg-white/15"></div></div></div></li>`}_renderColgroupHtml(){if(!this._configuration)return``;let e=this._configuration.columns.filter(e=>!e.hidden),t=[],n=0;for(let r of e){let e=r.width==null?``:String(r.width).trim();e?/^\d+(\.\d+)?$/.test(e)?(n+=parseFloat(e),t.push(`px`)):t.push(`lit`):t.push(`flex`)}let r=t.filter(e=>e===`flex`).length,i=t.includes(`lit`),a=``;r>0&&!i&&(a=n>0?`width:calc((100% - ${n}px) / ${r});min-width:0`:`width:${100/r}%;min-width:0`);let o=`<colgroup>`;return e.forEach((e,n)=>{let r=e.width==null?``:String(e.width).trim(),i=t[n],s=``;i===`px`?s=` style="width:${r}px;min-width:0"`:i===`lit`?s=` style="width:${this._escapeHtml(r)};min-width:0"`:a&&(s=` style="${a}"`),o+=`<col${s} />`}),o+=`</colgroup>`,o}_buildDataRowHtml(e,t,n,r=!1){if(!this._configuration)return``;let i=t,a=n,o=`box-sizing:border-box;min-height:${a}px;max-height:${a}px;height:${a}px;overflow:hidden`,s=``,c=typeof this._configuration.onRowClick==`function`,l=c?`cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800`:``,u=c?` data-row-clickable="true"`:``,d=l?` class="${l}"`:``;return s+=`<tr data-row-index="${i}"${r?` data-mint-rt-last-row=""`:``}${u}${d} style="${o}">`,this._configuration.columns.forEach(t=>{if(t.hidden)return;let n=!t.show||t.show(this,e),r=`${this._getStyle(t)}box-sizing:border-box;max-height:${a}px;overflow:hidden;vertical-align:middle;`;s+=`<td style="${r}" class="${this._getClasses(t,!0)}">`,s+=n?this._buildTableCellInnerHtml(t,e,i):``,s+=`</td>`}),s+=`</tr>`,s}_getVirtualRowCount(){return!this._virtualScrollActive()||!this._configuration?0:this._type===`provided`?this._getAllFilteredRowsSorted().length:this._type===`ajax`?this._totalRows:0}_getVirtualRowAt(e){return this._type===`provided`?this._getAllFilteredRowsSorted()[e]??null:this._type===`ajax`&&this._virtualRowCache.has(e)?this._virtualRowCache.get(e):null}_buildVirtualPlaceholderRowHtml(e,t,n=!1){if(!this._configuration)return``;let r=t,i=`box-sizing:border-box;min-height:${r}px;max-height:${r}px;height:${r}px;overflow:hidden`,a=`<tr data-row-index="${e}" data-mint-rt-placeholder="true"${n?` data-mint-rt-last-row=""`:``} class="bg-white dark:bg-mint-canvas" style="${i}">`;return this._configuration.columns.forEach(e=>{if(e.hidden)return;let t=`${this._getStyle(e)}box-sizing:border-box;max-height:${r}px;height:${r}px;overflow:hidden;vertical-align:middle;line-height:0;`;if(a+=`<td style="${t}" class="${this._getClasses(e,!0)}">`,e.thumbnail){let t=this._thumbnailDesktopPx(e);a+=`<div class="rounded-md bg-gray-200 dark:bg-white/15" style="width:${t}px;height:${t}px;max-width:100%;box-sizing:border-box"></div>`}else a+=`<div class="h-4 max-w-[95%] rounded bg-gray-200 dark:bg-white/15"></div>`;a+=`</td>`}),a+=`</tr>`,a}_virtualScrollStickyOverlapPx(e){let t=0;if(this._fixedControls()){let e=this.querySelector(`#mint-rt-fixed-controls-${this._tableId}`);if(e)t+=Math.ceil(e.getBoundingClientRect().height);else{let e=getComputedStyle(this).getPropertyValue(`--mint-rt-fixed-controls-h`).trim(),n=parseFloat(e);isNaN(n)||(t+=Math.ceil(n))}}if(this._fixedHeader()&&e){let n=e.querySelector(`thead`);n&&(t+=Math.ceil(n.getBoundingClientRect().height))}return t}_scrollVirtualTableTopIntoView(){if(!(!this._virtualScrollActive()||!this.isConnected)){if(this._virtualScrollRoot()===`table-body`){let e=this._virtualBodyScrollEl?.isConnected?this._virtualBodyScrollEl:this.querySelector(`#mint-rt-vscroll-${this._tableId}`);this._useMobileListLayout()&&e&&e.querySelector(`ul[data-mint-rt-mobile-list="${this._tableId}"]`);let t=e?.querySelector(`mint-table.table-section`)||e?.querySelector(`mint-table`),n=t?.querySelector(`#${this._tableId}`)?.closest(`table`)||t?.querySelector(`table`);this._virtualScrollStickyOverlapPx(n),e&&(e.scrollTop=0,this._virtualBodyScrollEl=e,this._virtualInvalidate(),this._scheduleVirtualWindowSync());return}this._virtualInvalidate(),this._scheduleVirtualWindowSync()}}_scheduleVirtualWindowSync(){this._virtualScrollActive()&&this._virtualWindowRaf===null&&(this._virtualWindowRaf=window.requestAnimationFrame(()=>{this._virtualWindowRaf=null,this._syncVirtualWindow()}))}_syncVirtualWindow(){if(!this._virtualScrollActive()||!this._configuration)return;let e=this._useMobileListLayout(),t=this.querySelector(`tbody[data-mint-rt-tbody="${this._tableId}"]`),n=this.querySelector(`ul[data-mint-rt-mobile-list="${this._tableId}"]`),r=e?n:t;if(!r)return;let i=this._getVirtualRowCount(),a=this._virtualRowHeightPxForSync(e),o=this._virtualColspan();if(i===0){e?this._fetchError?r.innerHTML=`<li class="list-none px-4 py-8 text-center text-sm text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</li>`:r.innerHTML=`<li class="list-none px-4 py-8 text-center text-sm">No records found.</li>`:this._fetchError?r.innerHTML=`<tr><td colspan="${o}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`:r.innerHTML=`<tr><td colspan="${o}" class="text-center py-8">No records found.</td></tr>`,this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``;return}let s=0,c=window.innerHeight;if(this._virtualScrollRoot()===`table-body`){let e=this._virtualBodyScrollEl;if((!e||!e.isConnected)&&(e=this.querySelector(`#mint-rt-vscroll-${this._tableId}`),this._virtualBodyScrollEl=e),!e)return;s=e.scrollTop,c=e.clientHeight||400}else{let e=r.getBoundingClientRect();s=Math.max(0,-e.top)}let l=Math.min(Math.max(0,Math.floor(s/a)),Math.max(0,i-1)),u=Math.ceil(c/a)+16,d=Math.max(0,l-8),f=Math.min(i,l+u),p=``;if(this._type===`ajax`)for(let e=d;e<f;e++)p+=this._virtualRowCache.has(e)?`1`:`0`;if(d===this._virtualLastRangeStart&&f===this._virtualLastRangeEnd&&(this._type!==`ajax`||p===this._virtualLastRangeCacheSig))return;this._virtualLastRangeStart=d,this._virtualLastRangeEnd=f,this._virtualLastRangeCacheSig=p;let m=d*a,h=Math.max(0,(i-f)*a),g=``;if(e){g+=`<li aria-hidden="true" class="pointer-events-none m-0 block list-none border-0 p-0" style="height:${m}px"></li>`;for(let e=d;e<f;e++){let t=this._getVirtualRowAt(e),n=i>0&&e===i-1;t?g+=this._buildMobileListItemHtml(t,e,a,n):g+=this._buildMobileListPlaceholderLi(e,a,n)}g+=`<li aria-hidden="true" class="pointer-events-none m-0 block list-none border-0 p-0" style="height:${h}px"></li>`}else{g+=`<tr data-mint-rt-spacer="top" aria-hidden="true"><td colspan="${o}" style="height:${m}px;padding:0;border:0;line-height:0;font-size:0"></td></tr>`;for(let e=d;e<f;e++){let t=this._getVirtualRowAt(e),n=i>0&&e===i-1;t?g+=this._buildDataRowHtml(t,e,a,n):g+=this._buildVirtualPlaceholderRowHtml(e,a,n)}g+=`<tr data-mint-rt-spacer="bottom" aria-hidden="true"><td colspan="${o}" style="height:${h}px;padding:0;border:0;line-height:0;font-size:0"></td></tr>`}if(r.innerHTML=g,this.querySelectorAll(`tbody[data-mint-rt-tbody="${this._tableId}"] mint-button[data-action], ul[data-mint-rt-mobile-list="${this._tableId}"] mint-button[data-action]`).forEach(e=>{e.render&&e.render()}),this._attachTableEventListeners(),this._attachRowClickHandler(),this._type===`ajax`&&this._virtualScrollActive()&&this._scheduleVirtualAjaxPrefetch(d,f),this._virtualScrollRoot()===`table-body`&&!e){let e=this._virtualBodyScrollEl;e?.isConnected&&requestAnimationFrame(()=>{if(!e.isConnected)return;let t=Math.max(0,e.scrollHeight-e.clientHeight);e.scrollTop>t&&(e.scrollTop=t)})}}_detachVirtualScroll(){this._virtualScrollHandler&&=(window.removeEventListener(`scroll`,this._virtualScrollHandler),this._virtualBodyScrollEl?.removeEventListener(`scroll`,this._virtualScrollHandler),null),this._virtualWindowResizeHandler&&=(window.removeEventListener(`resize`,this._virtualWindowResizeHandler),null),this._virtualResizeObserver&&=(this._virtualResizeObserver.disconnect(),null),this._virtualBodyScrollEl=null,this._virtualWindowRaf!==null&&(window.cancelAnimationFrame(this._virtualWindowRaf),this._virtualWindowRaf=null),this._virtualLastRangeStart=-1,this._virtualLastRangeEnd=-1,this._virtualLastRangeCacheSig=``,this._virtualAjaxPrefetchTimer!==null&&(window.clearTimeout(this._virtualAjaxPrefetchTimer),this._virtualAjaxPrefetchTimer=null),this._virtualRangeFetching=!1}_scheduleVirtualAjaxPrefetch(e,t){if(this._type!==`ajax`||!this._virtualScrollActive()||!this._configuration)return;let n=!1;for(let r=e;r<t;r++)if(!this._virtualRowCache.has(r)){n=!0;break}if(!n)return;this._virtualAjaxPrefetchTimer!==null&&window.clearTimeout(this._virtualAjaxPrefetchTimer);let r=e,i=t;this._virtualAjaxPrefetchTimer=window.setTimeout(()=>{this._virtualAjaxPrefetchTimer=null,this._fetchVirtualAjaxRange(r,i-r)},60)}async _fetchVirtualAjaxRange(e,t){if(!this._configuration||this._type!==`ajax`||!this._virtualScrollActive())return;let n=typeof this._configuration.data==`string`?this._configuration.data:null;if(!n||t<=0||this._virtualRangeFetching||e<0||e>=this._totalRows)return;this._virtualRangeFetching=!0;let r=this._virtualFetchGeneration,i=Math.min(e,Math.max(0,this._totalRows-1)),a=Math.min(150,Math.max(this._perPage,t,15),Math.max(1,this._totalRows-i));try{let e=new URLSearchParams({perPage:a.toString(),offset:i.toString(),search:this._search,sortBy:this._configuration.sortBy||`id`,sort:this._configuration.sort||`asc`,searchColumns:this._searchColumns.join(`,`),columns:this._columns.join(`,`)}),t={};this._configuration.headers&&(t.headers=this._configuration.headers);let o=await fetch(`${n}?${e.toString()}`,t);if(!o.ok)throw Error(`HTTP error! status: ${o.status}`);let s=await o.json();if(r!==this._virtualFetchGeneration)return;(s.content?.rows||[]).forEach((e,t)=>{let n=i+t;n<this._totalRows&&this._virtualRowCache.set(n,e)})}catch(e){console.error(`mint-resource-table: virtual range fetch failed`,e)}finally{this._virtualRangeFetching=!1,r===this._virtualFetchGeneration&&(this._virtualInvalidate(),this._scheduleVirtualWindowSync())}}_detachFixedChromeResize(){this._fixedChromeResizeObserver?.disconnect(),this._fixedChromeResizeObserver=null,this.style.removeProperty(`--mint-rt-fixed-controls-h`)}_syncFixedControlsChromeHeight(){if(!this._fixedHeader()||!this._fixedControls())return;this._fixedChromeResizeObserver?.disconnect(),this._fixedChromeResizeObserver=null;let e=this.querySelector(`#mint-rt-fixed-controls-${this._tableId}`);if(!e)return;let t=()=>{let t=Math.ceil(e.getBoundingClientRect().height);this.style.setProperty(`--mint-rt-fixed-controls-h`,`${t}px`)};t(),this._fixedChromeResizeObserver=new ResizeObserver(t),this._fixedChromeResizeObserver.observe(e)}_attachVirtualScrollListeners(){if(this._detachVirtualScroll(),!this._virtualScrollActive())return;let e=()=>{this._scheduleVirtualWindowSync()};this._virtualScrollHandler=e,this._virtualScrollRoot()===`table-body`?(this._virtualBodyScrollEl=this.querySelector(`#mint-rt-vscroll-${this._tableId}`),this._virtualBodyScrollEl?.addEventListener(`scroll`,e,{passive:!0}),this._virtualBodyScrollEl&&typeof ResizeObserver<`u`&&(this._virtualResizeObserver=new ResizeObserver(()=>this._scheduleVirtualWindowSync()),this._virtualResizeObserver.observe(this._virtualBodyScrollEl))):window.addEventListener(`scroll`,e,{passive:!0}),this._virtualWindowResizeHandler=()=>this._scheduleVirtualWindowSync(),window.addEventListener(`resize`,this._virtualWindowResizeHandler,{passive:!0}),this._scheduleVirtualWindowSync()}_toggleSort(e){if(!this._configuration||!e.data||!e.sortable)return;let t=e.data;if(this._sortTimeoutId!==null&&(clearTimeout(this._sortTimeoutId),this._sortTimeoutId=null),this._sorting=!0,this._sortingColumn=e,this._updateSortIcons(),this._type===`ajax`)this._sortTimeoutId=window.setTimeout(()=>{if(this._sortTimeoutId=null,!this._configuration||!t||!e.sortable)return;let n=this._configuration.sort||`asc`;this._configuration.sortBy?.toLowerCase()===t.toLowerCase()&&(n=n===`desc`?`asc`:`desc`),this._configuration.sort=n,this._configuration.sortBy=t,this._updateSortIcons(),this._offset=0,this._currentPage=1,this._fetching=!1,this._loading=!1,this._fetchData(void 0,!1,this._perPage,0)},10);else{let e=this._configuration.sort||`asc`;this._configuration.sortBy?.toLowerCase()===t.toLowerCase()&&(e=e===`desc`?`asc`:`desc`),this._configuration.sort=e,this._configuration.sortBy=t,this._currentPage=1,this._sorting=!1,this._sortingColumn=null,this._updateSortIcons(),this.render(),this._virtualScrollActive()&&queueMicrotask(()=>this._scrollVirtualTableTopIntoView())}}_getSortClass(e){return this._sorting&&this._sortingColumn===e?`spinner`:this._configuration?.sortBy?.toLowerCase()===e.data?.toLowerCase()?this._configuration?.sort?.toLowerCase()===`desc`?`caret-down`:`caret-up`:``}_updateSortIcons(){if(!this._configuration)return;this._configuration.columns.forEach((e,t)=>{if(!e.sortable||e.hidden)return;let n=this.querySelector(`th[data-column-key="${t}"]`);if(!n)return;let r=n.querySelector(`:scope > div.flex.items-center`);if(!r)return;let i=r.querySelector(`:scope > div.ml-2.flex.items-center`),a=this._getSortClass(e),o=()=>{if(!i){let e=document.createElement(`div`);e.className=`ml-2 flex items-center`,r.appendChild(e),i=e}return i},s=()=>{i&&=(i.remove(),null)};if(a===`spinner`){let e=o();if(e.querySelector(`mint-icon`)?.remove(),!e.querySelector(`mint-spinner`)){let t=document.createElement(`mint-spinner`);t.className=`w-4 h-4`,e.appendChild(t)}}else if(a===`caret-up`||a===`caret-down`){let e=o();e.querySelector(`mint-spinner`)?.remove();let t=e.querySelector(`mint-icon`);t||(t=document.createElement(`mint-icon`),e.appendChild(t)),t.setAttribute(`name`,a),t.className=`w-4 h-4`}else s()}),this._syncMobileSortPopoverIcons();let e=this.querySelector(`#mint-rt-mobile-sort-btn-${this._tableId}`);e&&(e.setAttribute(`icon`,this._getMobileSortTriggerIconName()),this._sorting?e.setAttribute(`loading`,`true`):e.removeAttribute(`loading`),typeof e.render==`function`&&e.render())}_showFetchingState(){}_triggerSearch(){this._searchTimeoutId&&clearTimeout(this._searchTimeoutId),this._searching=!0,this._type===`ajax`&&this._updateSearchIcon(),this._type!==`ajax`&&(this._currentPage=1),this._updateTableBody(),this._type!==`ajax`&&this._updatePagination(),this._searchTimeoutId=window.setTimeout(()=>{this._type===`ajax`?(this._offset=0,this._fetchData(void 0,!1,this._perPage,0)):(this._searching=!1,this._virtualScrollActive()&&queueMicrotask(()=>this._scrollVirtualTableTopIntoView()))},400)}_updateSearchIcon(){let e=this.querySelector(`#search-${this._tableId}`);if(!e)return;let t=this._type===`ajax`&&(this._searching||this._fetching);setTimeout(()=>{let n=e.querySelector(`.relative`)||e.querySelector(`div`);if(!n)return;let r=n.querySelector(`mint-icon`),i=n.querySelector(`mint-spinner`);if(t){if(r&&!i){let e=document.createElement(`mint-spinner`);e.className=`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none`,r.replaceWith(e)}else if(!r&&!i){let e=document.createElement(`mint-spinner`);e.className=`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none`,n.appendChild(e)}}else if(i){e.getAttribute(`icon`)||e.setAttribute(`icon`,`search`);let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`search`),t.className=`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400 dark:text-gray-500 pointer-events-none`,i.replaceWith(t)}},0)}_updateTableBody(){if(!this._configuration)return;let e=this.querySelector(`tbody[data-mint-rt-tbody="${this._tableId}"]`),t=this.querySelector(`#${this._tableId}`)?.closest(`table`)?.querySelector(`tbody`);if(this._virtualScrollActive()&&(this._type===`provided`||this._type===`ajax`)){if(!(e||t)){this.render();return}let n=this.querySelector(`#search-${this._tableId}`),r=document.activeElement===n||n?.querySelector(`input`)===document.activeElement,i=this._search;if((this._fetching||this._loading)&&!this._loaded&&!this._sorting)return;if(this._virtualInvalidate(),this._syncVirtualWindow(),r&&n){let e=n.querySelector(`input`)||n._element;e?(e.value=i,setTimeout(()=>{e.focus(),e.setSelectionRange(i.length,i.length)},0)):n.value!==void 0&&(n.value=i,setTimeout(()=>{n.focus()},0))}return}let n=this._getRows(),r=t;if(!r){this.render();return}let i=this.querySelector(`#search-${this._tableId}`),a=document.activeElement===i||i?.querySelector(`input`)===document.activeElement,o=this._search,s=``,c=``;if((this._fetching||this._loading)&&!this._loaded&&!this._sorting)return;n.forEach((e,t)=>{c+=this._buildMobileListItemHtml(e,t,void 0,t===n.length-1);let r=typeof this._configuration.onRowClick==`function`,i=r?`cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800`:``;s+=`<tr data-row-index="${t}" ${r?`data-row-clickable="true"`:``}${i?` class="${i}"`:``}>`,this._configuration.columns.forEach(n=>{if(n.hidden)return;let r=!n.show||n.show(this,e);s+=`<td style="${this._getStyle(n)}" class="${this._getClasses(n,!0)}">`,r&&(s+=this._buildTableCellInnerHtml(n,e,t,`table`)),s+=`</td>`}),s+=`</tr>`}),n.length===0&&(this._fetchError?(s+=`<tr><td colspan="${this._configuration.columns.filter(e=>!e.hidden).length}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`,c+=`<li class="list-none px-4 py-8 text-center text-sm text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</li>`):(s+=`<tr><td colspan="${this._configuration.columns.filter(e=>!e.hidden).length}" class="text-center py-8">No records found.</td></tr>`,c+=`<li class="list-none px-4 py-8 text-center text-sm">No records found.</li>`)),r.innerHTML=s;let l=this.querySelector(`ul[data-mint-rt-mobile-list="${this._tableId}"]`);if(l&&(l.innerHTML=c),this._attachTableEventListeners(),this._attachRowClickHandler(),a&&i){let e=i.querySelector(`input`)||i._element;e?(e.value=o,setTimeout(()=>{e.focus(),e.setSelectionRange(o.length,o.length)},0)):i.value!==void 0&&(i.value=o,setTimeout(()=>{i.focus()},0))}}_updatePagination(){if(!this._configuration)return;let e=this._lastPage||Math.ceil(this._rows.length/this._perPage),t=()=>{let e=this.querySelector(`mint-table`),t=e?.nextElementSibling;e&&t&&t.id!==`mint-rt-pagination-host-${this._tableId}`&&!t.classList.contains(`mint-rt-pagination-host`)&&t.querySelector?.(`[data-action="page"]`)&&t.remove()};if(!this._configuration.perPage||e<=1||this._virtualScrollActive()){this._getPaginationHostEl()?.replaceChildren(),t();return}let n=this._getPaginationHostEl();if(!n){let e=this.querySelector(`[data-mint-rt-mobile-list="${this._tableId}"]`)||this.querySelector(`mint-table`);if(!e){this.render();return}n=document.createElement(`div`),n.id=`mint-rt-pagination-host-${this._tableId}`,n.setAttribute(`data-mint-rt-pagination-wrap`,``),n.className=`mint-rt-pagination-host w-full min-w-0 overflow-x-auto overflow-y-hidden overscroll-x-contain flex justify-center [-webkit-overflow-scrolling:touch] md:justify-end `+(this._inMintCard?`border-t border-gray-200 px-3.5 pb-3.5 pt-3 dark:border-mint-divider md:border-t-0 md:pt-0`:`border-t border-gray-200 px-2 py-3 dark:border-mint-divider md:border-t-0 md:py-0 md:mt-4`),e.insertAdjacentElement(`afterend`,n)}let r=this._buildPaginationNavMarkup(e);n.innerHTML=r,setTimeout(()=>{this._attachPaginationListeners(),n.querySelectorAll(`mint-button[data-action="page"]`).forEach(e=>{let t=e.getAttribute(`data-page`),n=t&&this._loadingPage===parseInt(t),r=e._button||e.querySelector(`button`);if(r)if(n){let e=[],t=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,null),n;for(;n=t.nextNode();)e.push(n);e.forEach(e=>e.parentNode?.removeChild(e));let i=r.querySelector(`.mint-button-content`);if(i){let e=i.textContent?.trim();e&&/^\d+$/.test(e)&&i.remove()}let a=r.querySelector(`span.mr-2`);a&&a.querySelector(`mint-spinner`)&&(a.classList.remove(`mr-2`),a.classList.add(`mr-0`))}else{let e=r.textContent?.trim();if(!e||!/^\d+$/.test(e)){let e=t||``,n=r.querySelector(`mint-spinner`);r.innerHTML=``,n&&r.appendChild(n),r.appendChild(document.createTextNode(e))}}if(`render`in e&&typeof e.render==`function`&&(e.render(),n&&r)){let e=r.querySelector(`span.mr-2`);e&&e.querySelector(`mint-spinner`)&&(e.classList.remove(`mr-2`),e.classList.add(`mr-0`))}}),n.querySelectorAll(`mint-button[data-action="page-prev"], mint-button[data-action="page-next"]`).forEach(e=>{`render`in e&&typeof e.render==`function`&&e.render()}),this._loadingPage!==null&&!this._loading&&!this._fetching&&this._updatePagination()},0)}_goToPage(e){let t=this._lastPage||Math.ceil(this._rows.length/this._perPage);e>t&&(e=t),e<1&&(e=1),e!==this._currentPage&&(this._currentPage=e,this._offset=(e-1)*this._perPage,this._updatePageInUrl(e),this._type===`ajax`?(this._loadingPage=e,this._updatePagination(),this._fetchData()):this.render())}_handleButtonClick(e){if(this._configuration)switch(e.type){case`export`:break;case`print`:window.print();break;case`csv`:this._downloadCSV();break;default:e.onClick&&e.onClick(this);break}}_downloadCSV(){if(!this._configuration)return;let e=this.querySelector(`#${this._tableId}`)||this.querySelector(`table`);if(!e)return;let t=`data:text/csv;charset=utf-8,`,n=e=>{let n=[];e.querySelectorAll(`th, td`).forEach(e=>{let t=e.getAttribute(`colspan`);if(t)for(let e=0;e<parseInt(t,10)-1;e++)n.push(``);n.push(`"`+e.textContent?.trim().replace(/"/g,`""`)+`"`)}),t+=n.join(`,`)+`
|
|
87
|
+
`};e.querySelectorAll(`tr`).forEach(e=>n(e));let r=encodeURI(t),i=document.createElement(`a`);i.setAttribute(`href`,r),i.setAttribute(`download`,`${this._configuration.export_name||this._tableId}.csv`),document.body.appendChild(i),i.click(),document.body.removeChild(i)}_getStyle(e){let t=``;return(e.nowrap||e.actions)&&(t+=`white-space: nowrap;`),e.offsetLeft&&(t+=`left: ${e.offsetLeft} !important;`),e.offsetRight&&(t+=`right: ${e.offsetRight} !important;`),e.width&&(t+=`min-width: ${e.width}px; max-width: ${e.width}px;`),t}_getClasses(e,t=!1){let n=[];return e.class&&n.push(e.class.trim()),e.sortable&&!t&&n.push(`cursor-pointer`),e.stickLeft&&n.push(`sticky-left`),e.stickRight&&n.push(`sticky-right`),n.join(` `)}_renderTheadHtml(e,t,n=!1,r=!1){if(!this._configuration)return``;let i=[`bg-white`,`dark:bg-mint-nav`];e&&(i.push(`sticky`,`z-30`),r?i.push(`top-[var(--mint-rt-fixed-controls-h,0px)]`):i.push(`top-0`)),t&&i.push(`border-b`,`border-gray-200`,`dark:border-mint-divider`);let a=`<thead class="${i.join(` `)}"><tr>`;return this._configuration.columns.forEach((e,t)=>{if(e.hidden)return;let r=n?``:` width="${e.width||``}"`,i=e.sortable?` data-mint-rt-sortable=""`:``;if(a+=`<th${r} style="${this._getStyle(e)}" class="${this._getClasses(e)}" data-column-key="${t}"${i}>`,e.showLabel!==!1){if(a+=`<div class="flex items-center">`,a+=`<div class="flex-1">${e.raw?e.label:this._escapeHtml(e.label)}</div>`,e.sortable){let t=this._getSortClass(e);t===`spinner`?a+=`<div class="ml-2 flex items-center"><mint-spinner class="w-4 h-4"></mint-spinner></div>`:(t===`caret-up`||t===`caret-down`)&&(a+=`<div class="ml-2 flex items-center"><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`)}a+=`</div>`}a+=`</th>`}),a+=`</tr></thead>`,a}render(){if(!this._configuration){this.innerHTML=`<div class="p-4 text-red-500">Error: Invalid configuration</div>`;return}this._ensureMobileListMql();let e=String(this._configuration.id||``).trim();e&&(this.id=e),this._detachVirtualScroll(),this._detachFixedChromeResize(),this._virtualScrollActive()||this._virtualRowCache.clear();let t=!this._loaded||this._rows.length>0||this._search.length>0||this._searching,n=this._getRows();this._lastPage||Math.ceil(this._rows.length/this._perPage);let r=this._isExternalLoading(),i=``;if(t){let e=this._fixedControls(),t=[`flex`,`items-center`,`min-w-0`,this._inMintCard?`p-3.5`:`mb-3`,e?`sticky top-0 z-20 bg-white dark:bg-mint-nav border-b border-gray-200 dark:border-mint-divider`:``].filter(Boolean).join(` `);if(i+=`<div id="mint-rt-fixed-controls-${this._tableId}" class="${t}">`,i+=`<div class="flex min-w-0 flex-1 items-center gap-2">`,i+=this._buildMobileSortToolbarHtml(),this._configuration.showSearch!==!1){let e=`search-${this._tableId}`,t=this._escapeHtml(this._configuration.searchPlaceholder||`Search...`);i+=`<mint-input id="${e}" type="search" label="" placeholder="${t}" class="min-w-0 flex-1" icon="search" value="${this._escapeHtml(this._search)}"></mint-input>`}i+=`<div class="hidden shrink-0 items-center gap-2 md:flex">`,this._configuration.buttons&&this._configuration.buttons.forEach(e=>{let t=e.icon?` icon="${this._escapeHtml(e.icon)}"`:``,n=e.tone?` tone="${this._escapeHtml(e.tone)}"`:``;i+=`<mint-button variant="solid" class="${e.class||``}" data-button-type="${e.type||`custom`}"${t}${n}>`,e.label&&(i+=this._escapeHtml(e.label)),i+=`</mint-button>`}),i+=`</div>`,i+=`</div>`,i+=`</div>`}if((this._type===`ajax`&&!this._loaded||this._type===`provided`&&r)&&!this._fetchError&&!this._sorting){let e=this._fixedHeader()?` data-mint-rt-scroll-inner=""`:``,t=this._fixedHeader()&&this._fixedControls(),n=this._fixedHeader()?t?`sticky top-[var(--mint-rt-fixed-controls-h,0px)] z-30 `:`sticky top-0 z-30 `:`sticky top-0 z-10 `;i+=`<div class="min-w-0">`,i+=`<mint-table class="table-section`+(this._inMintCard?` rounded-t-none`:``)+`"`+e+`>`,i+=`<table id="${this._tableId}">`,i+=`<thead class="`+n+`bg-white dark:bg-mint-nav border-b border-gray-200 dark:border-mint-divider"><tr>`,this._configuration.columns.forEach((e,t)=>{if(e.hidden)return;let n=e.sortable?` data-mint-rt-sortable=""`:``;if(i+=`<th width="${e.width||``}" style="${this._getStyle(e)}" class="${this._getClasses(e)}" data-column-key="${t}"${n}>`,e.showLabel!==!1){if(i+=`<div class="flex items-center">`,i+=`<div class="flex-1">${e.raw?e.label:this._escapeHtml(e.label)}</div>`,e.sortable){let t=this._getSortClass(e);t===`spinner`?i+=`<div class="ml-2 flex items-center"><mint-spinner class="w-4 h-4"></mint-spinner></div>`:(t===`caret-up`||t===`caret-down`)&&(i+=`<div class="ml-2 flex items-center"><mint-icon name="${t}" class="w-4 h-4"></mint-icon></div>`)}i+=`</div>`}i+=`</th>`}),i+=`</tr></thead>`,i+=`<tbody>`;for(let e=0;e<4;e++)i+=`<tr>`,this._configuration.columns.forEach(e=>{if(!e.hidden){if(i+=`<td style="${this._getStyle(e)}" class="${this._getClasses(e,!0)}">`,e.thumbnail){let t=this._thumbnailDesktopPx(e);i+=`<div class="rounded-md bg-gray-200 dark:bg-white/15 animate-pulse" style="width:${t}px;height:${t}px;box-sizing:border-box"></div>`}else i+=`<div class="h-4 max-w-[95%] rounded bg-gray-200 dark:bg-white/15 animate-pulse"></div>`;i+=`</td>`}}),i+=`</tr>`;i+=`</tbody>`,i+=`</table>`,i+=`</mint-table>`,i+=`</div>`,i+=this._paginationHostPlaceholderHtml()}else if(n.length>0||this._search.length>0||this._searching||this._fetchError){let e=this._virtualScrollActive()&&(this._type===`provided`||this._type===`ajax`&&this._loaded&&!this._fetchError),t=e&&this._virtualScrollRoot()===`table-body`,a=this._escapeHtml(this._virtualMaxHeightCss()),o=t||this._fixedHeader(),s=this._fixedHeader()&&this._fixedControls(),c=o?` data-mint-rt-scroll-inner=""`:``,l=`table-section`+(this._inMintCard?` rounded-t-none`:``),u=`m-0 min-h-0 w-full list-none border-collapse overflow-x-hidden bg-white ${this._inMintCard?`px-3.5 py-3.5`:`py-3`} dark:bg-mint-canvas md:hidden`,d=``;if(t){let e=this._renderColgroupHtml();i+=`<div id="mint-rt-vscroll-${this._tableId}" class="overflow-y-auto overflow-x-auto min-h-0 w-full" style="max-height: ${a}; scrollbar-gutter: stable; overscroll-behavior-x: contain; overscroll-behavior-y: none; overflow-anchor: none;">`,i+=`<div class="hidden min-h-0 min-w-0 md:block">`,i+=`<mint-table class="${l}"${c}>`,i+=`<table id="${this._tableId}" class="w-full min-w-0 table-fixed">`,i+=e,i+=this._renderTheadHtml(!0,!0,!0,s)}else i+=`<div class="hidden min-h-0 min-w-0 md:block">`,i+=`<mint-table class="${l}"${c}>`,i+=`<table id="${this._tableId}">`,e&&(i+=this._renderColgroupHtml()),i+=this._renderTheadHtml(!0,!0,!!e,s);if(i+=`<tbody`+(e?` data-mint-rt-tbody="${this._tableId}"`:``)+`>`,!this._fetching&&!this._loading&&!r&&!e&&n.forEach((e,t)=>{d+=this._buildMobileListItemHtml(e,t,void 0,t===n.length-1);let r=typeof this._configuration.onRowClick==`function`,a=r?`cursor-pointer hover:bg-gray-50 dark:hover:bg-mint-elevated`:``;i+=`<tr data-row-index="${t}" ${r?`data-row-clickable="true"`:``}${a?` class="${a}"`:``}>`,this._configuration.columns.forEach(n=>{if(n.hidden)return;let r=!n.show||n.show(this,e);i+=`<td style="${this._getStyle(n)}" class="${this._getClasses(n,!0)}">`,r&&(i+=this._buildTableCellInnerHtml(n,e,t,`table`)),i+=`</td>`}),i+=`</tr>`}),!this._fetching&&!this._loading&&!r&&n.length===0&&!e)if(this._fetchError){let e=this._configuration.columns.filter(e=>!e.hidden).length;i+=`<tr><td colspan="${e}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`,d+=`<li class="list-none px-4 py-8 text-center text-sm text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</li>`}else{let e=this._configuration.columns.filter(e=>!e.hidden).length;i+=`<tr><td colspan="${e}" class="text-center py-8">No records found.</td></tr>`,d+=`<li class="list-none px-4 py-8 text-center text-sm">No records found.</li>`}i+=`</tbody>`,i+=`</table>`,i+=`</mint-table>`,i+=`</div>`,i+=`<ul class="${u}" data-mint-rt-mobile-list="${this._tableId}">${e?``:d}</ul>`,e||(i+=this._paginationHostPlaceholderHtml()),t&&(i+=`</div>`)}else i+=`<slot name="empty"></slot>`;this._fixedHeader()?this.setAttribute(`data-mint-rt-fixed-header`,``):this.removeAttribute(`data-mint-rt-fixed-header`),this._fixedControls()?this.setAttribute(`data-mint-rt-fixed-controls`,``):this.removeAttribute(`data-mint-rt-fixed-controls`),this.innerHTML=i,this._updatePagination(),this.querySelectorAll(`mint-button[data-action]`).forEach(e=>{e.render&&e.render()}),this.querySelectorAll(`mint-button[data-mint-rt-toolbar]`).forEach(e=>{e.render&&e.render()}),this.querySelectorAll(`mint-button[data-button-type]`).forEach(e=>{e.render&&e.render()}),this._attachEventListeners(),this._type===`ajax`&&!this._loaded&&!this._fetching&&!this._loading&&this._fetchData()}_attachRowClickHandler(){this._rowClickHandler&&this.removeEventListener(`click`,this._rowClickHandler,!0);let e=e=>{let t=e.target;if(t.tagName===`MINT-BUTTON`||t.tagName===`BUTTON`||t.closest(`mint-button`)||t.closest(`button`)||t.closest(`mint-popover`)||t.closest(`[data-action]`))return;let n=t.closest(`tr[data-row-clickable="true"]`)||t.closest(`li[data-row-clickable="true"]`);if(!n)return;let r=n.getAttribute(`data-row-index`);if(!r)return;let i=parseInt(r),a=this._getRowDataForEventIndex(i);!a||!this._configuration?.onRowClick||(this._configuration.onRowClick.length===1?this._configuration.onRowClick(a):this._configuration.onRowClick(this,a))};this.addEventListener(`click`,e,!0),this._rowClickHandler=e}_attachPaginationListeners(){this.querySelectorAll(`[data-action="page"]`).forEach(e=>{e.addEventListener(`click`,()=>{if(e.getAttribute(`active`)===`true`)return;let t=parseInt(e.getAttribute(`data-page`)||`1`);t!==this._currentPage&&this._goToPage(t)})}),this.querySelectorAll(`[data-action="page-prev"]`).forEach(e=>{e.addEventListener(`click`,()=>{this._goToPage(this._currentPage-1)})}),this.querySelectorAll(`[data-action="page-next"]`).forEach(e=>{e.addEventListener(`click`,()=>{this._goToPage(this._currentPage+1)})})}_attachTableEventListeners(){this.querySelectorAll(`[data-action="row-action"]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=parseInt(e.getAttribute(`data-row-index`)||`0`),n=parseInt(e.getAttribute(`data-action-index`)||`0`),r=parseInt(e.getAttribute(`data-column-key`)||`0`),i=this._getRowDataForEventIndex(t),a=this._configuration?.columns[r];a&&a.actions&&a.actions[n]&&i!==void 0&&a.actions[n].onClick(this,i)})}),this.querySelectorAll(`[data-action="column-action"]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=parseInt(e.getAttribute(`data-row-index`)||`0`),n=parseInt(e.getAttribute(`data-column-key`)||`0`),r=this._getRowDataForEventIndex(t),i=this._configuration?.columns[n];i&&i.action&&r!==void 0&&i.action.onClick(this,r)})})}_attachEventListeners(){let e=this.querySelector(`#search-${this._tableId}`);if(e){let t=e.querySelector(`input`)||e._element;t?t.addEventListener(`input`,e=>{this._search=e.target.value,this._triggerSearch()}):e.addEventListener(`input`,t=>{this._search=e.value||t.target.value||``,this._triggerSearch()})}this._attachTableEventListeners(),this._attachRowClickHandler(),this.querySelectorAll(`th[data-column-key]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=parseInt(e.getAttribute(`data-column-key`)||`0`),n=this._configuration?.columns[t];n&&this._toggleSort(n)})}),this.querySelectorAll(`[data-action="mobile-sort"]`).forEach(e=>{e.addEventListener(`click`,t=>{t.stopPropagation();let n=parseInt(e.getAttribute(`data-column-key`)||`0`,10),r=this._configuration?.columns[n];r&&(this._closeMobileSortPopover(),this._toggleSort(r))})}),this.querySelectorAll(`[data-button-type]`).forEach(e=>{e.addEventListener(`click`,()=>{let t=e.getAttribute(`data-button-type`),n=this._configuration?.buttons?.find(e=>(e.type||`custom`)===t);n&&this._handleButtonClick(n)})}),this._attachPaginationListeners(),this._virtualScrollActive()&&(this._type===`provided`||this._type===`ajax`)&&this._attachVirtualScrollListeners(),this._fixedHeader()&&this._fixedControls()&&queueMicrotask(()=>{this._syncFixedControlsChromeHeight(),requestAnimationFrame(()=>this._syncFixedControlsChromeHeight())})}_escapeHtml(e){let t=document.createElement(`div`);return t.textContent=e,t.innerHTML}_getPageFromUrl(){if(!this._tableId)return null;let e=new URLSearchParams(window.location.search).get(`mui.${this._tableId}`);if(!e)return null;let t=parseInt(e,10);return isNaN(t)||t<1?null:t}_updatePageInUrl(e){if(!this._tableId)return;let t=new URL(window.location.href),n=t.searchParams;n.set(`mui.${this._tableId}`,e.toString()),e===1&&n.set(`mui.${this._tableId}`,`1`),window.history.replaceState({},``,t.toString())}_loadPageFromUrl(){if(!this._configuration||!this._tableId)return;let e=this._getPageFromUrl();e!==null&&(this._currentPage=e,this._offset=(this._currentPage-1)*this._perPage)}};customElements.get(`mint-resource-table`)||customElements.define(`mint-resource-table`,te);var ne=550,re=12,ie={passive:!0},ae=class extends HTMLElement{constructor(...e){super(...e),this._table=null,this._anchor=null,this._popover=null,this._menuRoot=null,this._baseId=``,this._touchTimer=null,this._touchStart=null,this._slotObserver=null,this._scrollCloseTargets=[],this._onScrollClose=()=>{this._closePopover()},this._onContextMenu=e=>{let t=e,n=this._rowTargetFromEventTarget(t.target);n&&(t.preventDefault(),this._openAtRowIndex(n.index,t.clientX,t.clientY))},this._onTouchStart=e=>{let t=e;if(!t.touches.length)return;let n=this._rowTargetFromEventTarget(t.target);if(!n)return;let r=t.touches[0];this._touchStart={x:r.clientX,y:r.clientY,rowIndex:n.index},this._touchTimer!==null&&(window.clearTimeout(this._touchTimer),this._touchTimer=null);let i=this._longPressMs();this._touchTimer=window.setTimeout(()=>{this._touchTimer=null,this._touchStart&&=(this._openAtRowIndex(this._touchStart.rowIndex,this._touchStart.x,this._touchStart.y),null)},i)},this._onTouchMove=e=>{if(!this._touchStart||this._touchTimer===null)return;let t=e.touches[0];if(!t)return;let n=t.clientX-this._touchStart.x,r=t.clientY-this._touchStart.y;n*n+r*r>re*re&&(this._clearTouchTimer(),this._touchStart=null)},this._onTouchEnd=()=>{this._clearTouchTimer(),this._touchStart=null}}static get observedAttributes(){return[`for`,`long-press-ms`]}connectedCallback(){this.classList.add(`contents`),this._baseId=this.id?.trim()||`mint-rt-ctx-${Math.random().toString(36).slice(2,10)}`,this._anchor=document.createElement(`div`),this._anchor.id=`${this._baseId}-anchor`,this._anchor.setAttribute(`aria-hidden`,`true`),this._anchor.className=`pointer-events-none fixed z-0 h-px w-px overflow-hidden p-0 m-0 border-0 opacity-0`,document.body.appendChild(this._anchor),this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`data-mint-rt-ctx-internal`,``),this._popover.id=`${this._baseId}-popover`,this._popover.setAttribute(`trigger-id`,this._anchor.id),this._popover.setAttribute(`direction`,`down`),this._popover.setAttribute(`padding`,`0`),this._popover.setAttribute(`distance`,`6px`),this._menuRoot=document.createElement(`div`),this._menuRoot.className=`flex min-w-[11rem] flex-col gap-0.5 py-1`,this._popover.appendChild(this._menuRoot),this.appendChild(this._popover),this._slotObserver=new MutationObserver(()=>{this._hideMenuSlotSources()}),this._slotObserver.observe(this,{childList:!0}),queueMicrotask(()=>{this._hideMenuSlotSources(),this._bindTable()})}disconnectedCallback(){this._slotObserver?.disconnect(),this._slotObserver=null,this._unbindTable(),this._anchor?.remove(),this._anchor=null,this._popover?.remove(),this._popover=null,this._menuRoot=null}attributeChangedCallback(){this.isConnected&&this._bindTable()}_longPressMs(){let e=parseInt(this.getAttribute(`long-press-ms`)||``,10);return!Number.isNaN(e)&&e>100?e:ne}_resolveTable(){let e=this.getAttribute(`for`)?.trim();if(e){let t=document.getElementById(e);return t&&t.tagName===`MINT-RESOURCE-TABLE`?t:null}let t=this.previousElementSibling;return t&&t.tagName===`MINT-RESOURCE-TABLE`?t:this.parentElement?.querySelector?.(`mint-resource-table`)??null}_hideMenuSlotSources(){for(let e of Array.from(this.children))e===this._popover||e.hasAttribute(`data-mint-rt-ctx-internal`)||e.setAttribute(`hidden`,``)}_bindTable(){this._unbindTable(),this._table=this._resolveTable(),this._table&&(this._table.addEventListener(`contextmenu`,this._onContextMenu,!0),this._table.addEventListener(`touchstart`,this._onTouchStart,{passive:!0}),this._table.addEventListener(`touchmove`,this._onTouchMove,{passive:!0}),this._table.addEventListener(`touchend`,this._onTouchEnd,{passive:!0}),this._table.addEventListener(`touchcancel`,this._onTouchEnd,{passive:!0}))}_unbindTable(){this._closePopover(),this._table&&=(this._table.removeEventListener(`contextmenu`,this._onContextMenu,!0),this._table.removeEventListener(`touchstart`,this._onTouchStart),this._table.removeEventListener(`touchmove`,this._onTouchMove),this._table.removeEventListener(`touchend`,this._onTouchEnd),this._table.removeEventListener(`touchcancel`,this._onTouchEnd),null)}_rowTargetFromEventTarget(e){if(!e||!this._table)return null;let t=e.closest?.(`tr[data-row-index], li[data-row-index]`);if(!t||!this._table.contains(t)||t.hasAttribute(`data-mint-rt-spacer`)||t.getAttribute(`data-mint-rt-placeholder`)===`true`)return null;let n=t.getAttribute(`data-row-index`);if(n==null)return null;let r=parseInt(n,10);return Number.isNaN(r)?null:{index:r}}_clearTouchTimer(){this._touchTimer!==null&&(window.clearTimeout(this._touchTimer),this._touchTimer=null)}_positionAnchor(e,t){this._anchor&&(this._anchor.style.left=`${Math.round(e)}px`,this._anchor.style.top=`${Math.round(t)}px`)}_slotTemplateElements(){return Array.from(this.children).filter(e=>e!==this._popover&&e instanceof HTMLElement&&!e.hasAttribute(`data-mint-rt-ctx-internal`))}_elementIsScrollContainer(e){let t=getComputedStyle(e);return t.overflowX===`auto`||t.overflowX===`scroll`||t.overflowY===`auto`||t.overflowY===`scroll`}_collectScrollCloseTargets(e){let t=[],n=new Set,r=e=>{!e||n.has(e)||(n.add(e),t.push(e))};r(window),e.querySelectorAll(`[id^="mint-rt-vscroll-"]`).forEach(e=>{this._elementIsScrollContainer(e)&&r(e)});let i=e.querySelector(`mint-table`);for(;i&&i!==e;)this._elementIsScrollContainer(i)&&r(i),i=i.parentElement;return this._elementIsScrollContainer(e)&&r(e),t}_detachScrollCloseListeners(){for(let e of this._scrollCloseTargets)e.removeEventListener(`scroll`,this._onScrollClose,ie);this._scrollCloseTargets=[]}_attachScrollCloseListeners(e){this._detachScrollCloseListeners(),this._scrollCloseTargets=this._collectScrollCloseTargets(e);for(let e of this._scrollCloseTargets)e.addEventListener(`scroll`,this._onScrollClose,ie)}_closePopover(){if(this._detachScrollCloseListeners(),!this._popover?.hasAttribute(`open`))return;let e=this._popover;typeof e.close==`function`?e.close():this._popover.removeAttribute(`open`)}_openAtRowIndex(e,t,n){this._closePopover();let r=this._resolveTable();if(!r||typeof r.getRowByIndex!=`function`||!this._popover||!this._menuRoot)return;let i=this._popover,a=this._menuRoot,o=r.getRowByIndex(e);if(o===void 0)return;let s=this._slotTemplateElements();if(!s.length)return;this._positionAnchor(t,n),a.innerHTML=``,s.forEach(t=>{if(t.hasAttribute(`data-mint-rt-ctx-if-selection`)&&!(window.getSelection?.()?.toString?.()?.trim()??``))return;let n=t.cloneNode(!0);n.removeAttribute(`hidden`),n.addEventListener(`click`,t=>{t.stopPropagation();let r=n.getAttribute(`data-context-action`)||n.querySelector?.(`[data-context-action]`)?.getAttribute(`data-context-action`)||``,i=window.getSelection?.()?.toString?.()?.trim()??``;this.dispatchEvent(new CustomEvent(`context-action`,{bubbles:!0,composed:!0,detail:{action:r,row:o,rowIndex:e,selectedText:i}})),this._closePopover()}),a.appendChild(n);let r=n;typeof r.render==`function`&&queueMicrotask(()=>r.render())}),i.removeAttribute(`open`),i.offsetHeight,i.setAttribute(`open`,`true`);let c=i;typeof c.render==`function`&&queueMicrotask(()=>c.render());let l=this._resolveTable();l&&this._attachScrollCloseListeners(l)}};customElements.get(`mint-resource-table-context-menu`)||customElements.define(`mint-resource-table-context-menu`,ae);var oe=class extends HTMLElement{static get observedAttributes(){return[`id`,`heading`,`open`,`position`,`full-page`,`width`,`height`]}constructor(){super(),this._overlay=null,this._offCanvas=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._darkModeObserver=null,this._contentObserver=null,this._renderFrame=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`fixed`,`inset-0`,`z-50`),this.isOpen()||this.classList.add(`hidden`),this.render(),this._observeDarkMode(),this._observeContentMutations()}disconnectedCallback(){this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}getId(){return this.getAttribute(`id`)||``}getHeading(){return this.getAttribute(`heading`)||``}getPosition(){let e=this.getAttribute(`position`)?.toLowerCase();return e===`top`||e===`bottom`||e===`left`||e===`right`?e:`right`}isFullPage(){return this.getAttribute(`full-page`)===`true`}getWidth(){return this.getAttribute(`width`)||`320px`}getHeight(){return this.getAttribute(`height`)||``}_normalizeCssValue(e){return/^\d+(\.\d+)?$/.test(e.trim())?`${e.trim()}px`:e.trim()}isOpen(){return this.getAttribute(`open`)===`true`}open(){this.setAttribute(`open`,`true`)}close(){this.removeAttribute(`open`)}render(){let e=this.getId(),t=this.getHeading(),n=this.isOpen(),r=this.getPosition(),i=this.isFullPage(),a=this.getHeight();e&&(this.id=e),this._overlay||(this._overlay=document.createElement(`div`),this._overlay.className=`fixed inset-0 bg-black/50 transition-opacity duration-200 z-40`,this._overlay.addEventListener(`click`,()=>this.close()),this.appendChild(this._overlay)),this._offCanvas||(this._offCanvas=document.createElement(`div`),this.appendChild(this._offCanvas));let o=this._getPositionClasses(r,i);this._offCanvas.className=o;let s=this._offCanvas.querySelector(`.off-canvas-content`);if(s||(s=document.createElement(`div`),s.className=`off-canvas-content bg-white dark:bg-mint-elevated dark:border dark:border-mint-divider shadow-xl flex flex-col pointer-events-auto`,s.style.transform=this._getTransformValue(r,!1),this._offCanvas.appendChild(s)),n?this._animateEnter():this._animateExit(),Array.from(s.classList).forEach(e=>{(e.startsWith(`w-`)||e.startsWith(`max-w-`)||e.startsWith(`md:w-`)||e.startsWith(`md:max-w-`)||e.startsWith(`sm:w-`)||e.startsWith(`sm:max-w-`))&&s.classList.remove(e)}),s.classList.remove(`h-full`,`max-h-[90vh]`,`max-h-screen`,`md:h-full`,`md:max-h-[90vh]`,`md:max-h-screen`,`sm:h-full`,`sm:max-h-[90vh]`),s.classList.remove(`has-custom-width`,`has-custom-height`),s.style.removeProperty(`--off-canvas-width`),s.style.removeProperty(`--off-canvas-height`),i)s.classList.add(`w-full`,`h-full`,`max-w-none`);else if(r===`top`||r===`bottom`)if(s.classList.add(`w-full`,`h-full`,`max-w-none`),a){let e=this._normalizeCssValue(a);s.style.setProperty(`--off-canvas-height`,e),s.classList.add(`has-custom-height`),this._ensureHeightStyle()}else s.classList.add(`md:max-h-[90vh]`,`md:h-auto`);else{s.classList.add(`w-full`,`h-full`,`max-w-none`);let e=this.getWidth(),t=this._normalizeCssValue(e);s.style.setProperty(`--off-canvas-width`,t),s.classList.add(`has-custom-width`),this._ensureWidthStyle()}this._header||(this._header=document.createElement(`div`),this._header.className=`flex items-center justify-between p-4 border-b border-gray-200 dark:border-mint-divider flex-shrink-0`,s.appendChild(this._header)),this._headingSlot||(this._headingSlot=document.createElement(`div`),this._headingSlot.className=`flex-1`,this._headingSlot.setAttribute(`slot`,`heading`),this._header.appendChild(this._headingSlot));let c=this._headingSlot.querySelector(`mint-text`);t?(c||(c=document.createElement(`mint-text`),c.setAttribute(`size`,`sub-heading`),c.setAttribute(`bold`,`true`),this._headingSlot.appendChild(c)),c.textContent=t):c&&c.remove(),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._offCanvas&&e!==this._headingSlot&&e.getAttribute(`slot`)===`heading`).forEach(e=>{this._headingSlot&&e.parentElement!==this._headingSlot&&this._headingSlot.appendChild(e)}),this._closeButton||(this._closeButton=document.createElement(`mint-button`),this._closeButton.setAttribute(`variant`,`ghost`),this._closeButton.setAttribute(`icon`,`close`),this._closeButton.addEventListener(`click`,()=>this.close()),this._header.appendChild(this._closeButton)),this._bodySlot||(this._bodySlot=document.createElement(`div`),this._bodySlot.className=`flex-1 overflow-y-auto p-4`,this._bodySlot.setAttribute(`slot`,`body`),s.appendChild(this._bodySlot)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._offCanvas&&e!==this._bodySlot&&e.getAttribute(`slot`)===`body`).forEach(e=>{this._bodySlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._actionsSlot||(this._actionsSlot=document.createElement(`div`),this._actionsSlot.className=`p-4 border-t border-gray-200 dark:border-mint-divider flex-shrink-0`,this._actionsSlot.setAttribute(`slot`,`actions`),s.appendChild(this._actionsSlot));let l=this._actionsSlot.querySelector(`mint-stack`);l||(l=document.createElement(`mint-stack`),l.setAttribute(`direction`,`horizontal`),l.className=`justify-end`,this._actionsSlot.appendChild(l)),Array.from(this.children).filter(e=>e!==this._overlay&&e!==this._offCanvas&&e!==this._actionsSlot&&e.getAttribute(`slot`)===`actions`).forEach(e=>{Array.from(e.children).forEach(e=>{e.parentElement!==l&&l.appendChild(e)}),e.parentElement&&e.remove()}),Array.from(this.children).forEach(e=>{e!==this._overlay&&e!==this._offCanvas&&e.getAttribute(`slot`)!==`heading`&&e.getAttribute(`slot`)!==`body`&&e.getAttribute(`slot`)!==`actions`&&e!==this._headingSlot&&e!==this._bodySlot&&e!==this._actionsSlot&&e.parentElement!==this._bodySlot&&this._bodySlot.appendChild(e)}),this._updateBackgroundColor()}_getPositionClasses(e,t){let n=`fixed z-50 pointer-events-none`;switch(e){case`top`:return`${n} inset-0 md:inset-x-0 md:top-0 md:bottom-auto ${t?`md:h-full`:`md:h-auto`}`;case`bottom`:return`${n} inset-0 md:inset-x-0 md:bottom-0 md:top-auto ${t?`md:h-full`:`md:h-auto`}`;case`left`:return`${n} inset-0 md:inset-y-0 md:left-0 md:right-auto ${t?`md:w-full`:`md:w-auto`}`;case`right`:return`${n} inset-0 md:inset-y-0 md:right-0 md:left-auto ${t?`md:w-full`:`md:w-auto`}`;default:return`${n} inset-0 md:inset-y-0 md:right-0 md:left-auto ${t?`md:w-full`:`md:w-auto`}`}}_getTransformValue(e,t){if(t)switch(e){case`top`:return`translateY(0)`;case`bottom`:return`translateY(0)`;case`left`:return`translateX(0)`;case`right`:return`translateX(0)`;default:return`translateX(0)`}else switch(e){case`top`:return`translateY(-100%)`;case`bottom`:return`translateY(100%)`;case`left`:return`translateX(-100%)`;case`right`:return`translateX(100%)`;default:return`translateX(100%)`}}_updateBackgroundColor(){if(!this._offCanvas)return;let e=document.documentElement.classList.contains(`dark`),t=this._offCanvas.querySelector(`.off-canvas-content`);t&&(e?(t.classList.remove(`bg-white`),t.classList.add(`bg-mint-elevated`,`border`,`border-mint-divider`)):(t.classList.remove(`bg-mint-elevated`,`border`,`border-mint-divider`),t.classList.add(`bg-white`)))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_animateEnter(){let e=this._offCanvas?.querySelector(`.off-canvas-content`);if(!e)return;let t=this.getPosition();e.style.transform=this._getTransformValue(t,!1),e.style.transition=`transform 300ms ease-out`,this.classList.remove(`hidden`),requestAnimationFrame(()=>{requestAnimationFrame(()=>{e.style.transform=this._getTransformValue(t,!0)})})}_animateExit(){let e=this._offCanvas?.querySelector(`.off-canvas-content`);if(!e){this.classList.add(`hidden`);return}let t=this.getPosition();e.style.transition=`transform 300ms ease-in`,e.style.transform=this._getTransformValue(t,!1),setTimeout(()=>{this.classList.add(`hidden`),e.style.transform=``,e.style.transition=``},300)}_ensureWidthStyle(){if(!document.getElementById(`off-canvas-width-style`)){let e=document.createElement(`style`);e.id=`off-canvas-width-style`,e.textContent=`
|
|
84
88
|
@media (min-width: 768px) {
|
|
85
89
|
.off-canvas-content.has-custom-width {
|
|
86
90
|
width: min(var(--off-canvas-width), 100vw) !important;
|
|
@@ -94,7 +98,7 @@ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{val
|
|
|
94
98
|
max-height: 100% !important;
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
|
-
`,document.head.appendChild(e)}}};customElements.get(`mint-off-canvas`)||customElements.define(`mint-off-canvas`,ae);var oe=class extends HTMLElement{static get observedAttributes(){return[`active`,`disabled`,`target`]}constructor(){super(),this._clickHandler=null}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(e,t,n){t!==n&&this.render()}getTarget(){return this.getAttribute(`target`)||``}isActive(){let e=this.getAttribute(`active`);return e!==null&&e!==`false`}isDisabled(){return this.getAttribute(`disabled`)===`true`}get active(){return this.isActive()}set active(e){e?this.setAttribute(`active`,`true`):this.setAttribute(`active`,`false`)}render(){let e=this.isActive(),t=this.isDisabled();this.className=``,this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`inline-block`,`cursor-pointer`,`px-4`,`py-1.5`,`text-sm`,`font-medium`,`rounded-lg`,`border`,`text-gray-700`,`dark:text-gray-300`);let n=this.closest(`mint-tab-list`)?.getAttribute(`position`)||`top`,r=n===`left`||n===`right`;t?(this.classList.add(`opacity-60`,`cursor-not-allowed`,`pointer-events-none`,`bg-gray-50`,`dark:bg-mint-elevated`,`border-gray-300`,`dark:border-mint-divider`,`text-gray-400`,`dark:text-gray-500`),this.classList.remove(`cursor-pointer`)):e?(this.classList.add(`bg-white`,`dark:bg-mint-elevated`,`border-gray-200`,`dark:border-mint-divider`,`text-gray-900`,`dark:text-gray-100`,`shadow-sm`,`relative`,`z-10`),r?n===`left`?this.classList.add(`mr-[-1px]`):this.classList.add(`ml-[-1px]`):this.classList.add(`mb-[-1px]`)):this.classList.add(`bg-gray-100`,`dark:bg-mint-elevated`,`border-gray-200`,`dark:border-mint-divider`,`text-gray-600`,`dark:text-gray-400`,`hover:bg-gray-50`,`dark:hover:bg-mint-hover`)}setupEventListeners(){this.isDisabled()||this._clickHandler||(this._clickHandler=this.handleClick.bind(this),this.addEventListener(`click`,this._clickHandler))}removeEventListeners(){this._clickHandler&&=(this.removeEventListener(`click`,this._clickHandler),null)}handleClick(e){if(this.isDisabled()){e.preventDefault(),e.stopPropagation();return}e.__mintTabsSynthetic||(e.stopPropagation(),this.dispatchEvent(new CustomEvent(`tab-click`,{detail:{tab:this,target:this.getTarget()},bubbles:!0,cancelable:!0,composed:!0})))}};customElements.get(`mint-tab`)||customElements.define(`mint-tab`,oe);var N=class extends HTMLElement{static get observedAttributes(){return[`position`]}constructor(){super()}connectedCallback(){this.render()}attributeChangedCallback(e,t,n){t!==n&&this.render()}getPosition(){return this.getAttribute(`position`)||`top`}render(){let e=this.getPosition();this.classList.remove(`flex`,`inline-flex`,`flex-row`,`flex-col`,`gap-1`,`gap-2`,`pb-0`,`pr-0`,`pl-0`,`mb-0`,`mr-0`,`ml-0`,`self-start`),this.classList.add(`box-border`,`m-0`,`p-1`,`border`,`bg-gray-100`,`dark:bg-mint-elevated`,`dark:border-mint-divider`,`border-gray-200`,`w-auto`,`rounded-lg`,`gap-2`),e===`top`?this.classList.add(`inline-flex`,`flex-row`,`mb-0`,`self-start`):e===`left`?this.classList.add(`flex`,`flex-col`,`mr-0`):e===`right`&&this.classList.add(`flex`,`flex-col`,`ml-0`)}};customElements.get(`mint-tab-list`)||customElements.define(`mint-tab-list`,N);var P=class extends HTMLElement{static get observedAttributes(){return[`id`]}constructor(){super()}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`block`,`w-full`),this.render(),this.checkInitialVisibility()}attributeChangedCallback(e,t,n){t!==n&&e===`id`&&(this.render(),this.checkInitialVisibility())}getId(){return this.getAttribute(`id`)||``}show(){this.style.display=`block`}hide(){this.style.display=`none`}checkInitialVisibility(){let e=this.closest(`mint-tabs`);if(!e){this.style.display=`none`;return}let t=e.querySelectorAll(`mint-tab`),n=!1;t.forEach(e=>{let t=e.getAttribute(`active`),r=e.getAttribute(`target`),i=this.getId();t===`true`&&r===i&&(n=!0)}),!n&&t.length>0&&t[0].getAttribute(`target`)===this.getId()&&!e.querySelector(`mint-tab[active="true"]`)&&(n=!0),n?this.style.display=`block`:this.style.display=`none`}render(){}};customElements.get(`mint-tab-content`)||customElements.define(`mint-tab-content`,P);var F=class extends HTMLElement{constructor(){super(),this._tabClickHandler=null,this._mutationObserver=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`block`),this.render(),this.setupEventListeners(),this.setupMutationObserver(),this.initializeActiveTab()}disconnectedCallback(){this.removeEventListeners(),this._mutationObserver&&=(this._mutationObserver.disconnect(),null)}render(){let e=this.querySelector(`mint-tab-list`);if(this.querySelectorAll(`mint-tab-content`),!e){console.warn(`mint-tabs: mint-tab-list is required`);return}let t=e.getAttribute(`position`)||`top`;this.classList.remove(`flex`,`flex-row`,`flex-col`,`gap-4`,`gap-6`),t===`left`||t===`right`?(this.classList.add(`flex`,`flex-row`,`items-start`),t===`left`?(e.classList.add(`mr-4`,`flex-shrink-0`),e.classList.remove(`ml-4`)):(e.classList.add(`ml-4`,`flex-shrink-0`,`order-2`),e.classList.remove(`mr-4`),this.querySelectorAll(`mint-tab-content`).forEach(e=>{e.classList.add(`order-1`)}))):(this.classList.add(`flex`,`flex-col`),e.classList.remove(`mr-4`,`ml-4`,`flex-shrink-0`,`order-2`),this.querySelectorAll(`mint-tab-content`).forEach(e=>{e.classList.remove(`order-1`)}))}initializeActiveTab(){requestAnimationFrame(()=>{let e=this.querySelectorAll(`mint-tab`),t=null;if(e.forEach(e=>{e.getAttribute(`active`)===`true`&&(t=e)}),!t&&e.length>0&&(t=e[0],t.setAttribute(`active`,`true`)),t){let e=t.getAttribute(`target`);e?this.showContent(e):this.hideAllContent()}else this.hideAllContent();this.querySelectorAll(`mint-tab-content`).forEach(e=>{let t=e;t.checkInitialVisibility&&t.checkInitialVisibility()})})}hideAllContent(){this.querySelectorAll(`mint-tab-content`).forEach(e=>{let t=e;t.hide?t.hide():e.style.display=`none`})}showContent(e){this.querySelectorAll(`mint-tab-content`).forEach(e=>{let t=e;t.hide?t.hide():e.style.display=`none`});let t=this.querySelector(`mint-tab-content[id="${e}"]`);t&&(t.show?t.show():t.style.display=`block`)}setupEventListeners(){this._tabClickHandler||(this._tabClickHandler=this.handleTabClick.bind(this),this.addEventListener(`tab-click`,this._tabClickHandler))}removeEventListeners(){this._tabClickHandler&&=(this.removeEventListener(`tab-click`,this._tabClickHandler),null)}setupMutationObserver(){this._mutationObserver=new MutationObserver(()=>{this.render()});let e=this.querySelector(`mint-tab-list`);e&&this._mutationObserver.observe(e,{attributes:!0,attributeFilter:[`position`]})}handleTabClick(e){let t=e.detail?.tab,n=e.detail?.target;if(!t)return;let r=t.closest(`mint-tab-list`);r&&(r.querySelectorAll(`mint-tab`).forEach(e=>{let n=e;e===t?n.active=!0:n.active=!1}),n&&this.showContent(n))}};customElements.get(`mint-tabs`)||customElements.define(`mint-tabs`,F);var I=class e extends HTMLElement{static get observedAttributes(){return[`type`,`data`,`width`,`height`,`show-legend`,`show-grid`,`show-tooltip`,`curve-tension`]}static{this.MAX_CACHE_SIZE=100}constructor(){super(),this._chartContainer=null,this._svg=null,this._tooltip=null,this._chartType=`line`,this._chartData=null,this._width=800,this._height=400,this._padding={top:20,right:20,bottom:60,left:60},this._showLegend=!0,this._showGrid=!0,this._showTooltip=!0,this._curveTension=.5,this._dataObserver=null,this._darkModeObserver=null,this._tooltipHideTimeout=null,this._lastTooltipContent=``,this._activeXValue=null,this._pinnedXValue=null,this._tooltipAnimationFrame=null,this._cachedTooltipContent=new Map,this._cachedXPositions=new Map,this._verticalLine=null,this._plotPoints=new Map,this._resizeObserver=null,this._windowResizeHandler=null,this._pieChartTimeouts=new Set,this._pieChartTooltipShown=!1,this._pieChartClickOutsideHandler=null,this._pieChartGroup=null,this._chartClickOutsideHandler=null,this._chartTooltipScrollHandler=null,this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``},this._renderScheduled=!1,this._datasetVisibility=new Map,this._widthValue=`100%`,this._heightValue=400,this._defaultColors=[`#2563eb`,`#3b82f6`,`#0d9488`,`#7c3aed`,`#d97706`,`#059669`,`#dc2626`,`#c026d3`],this._legendHeight=0,this._rotatedLabelHeight=0}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`);let e=this._getReactiveValue(this.data);e&&typeof e==`object`&&!Array.isArray(e)&&`datasets`in e&&(this._chartData=e),this._setupDataObserver(),this._setupDarkModeObserver(),this._setupResizeObserver(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.render()})})}_getReactiveValue(e){if(!e||typeof e!=`object`)return e;if(`_value`in e||`__v_isRef`in e){if(e.value!==void 0)return e.value;if(`_value`in e)return e._value}return`__v_raw`in e||`__v_isReactive`in e||`__ob__`in e,e}_setupDataObserver(){let e=null,t=0,n=()=>{if(!this.isConnected)return;let t=this._getReactiveValue(this.data),n=null;t&&typeof t==`object`&&!Array.isArray(t)&&`datasets`in t&&(n=t),n!==e&&n&&(e=n,this._chartData=n,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this.render())};requestAnimationFrame(()=>{n(),requestAnimationFrame(()=>{n()})});let r=setInterval(()=>{if(!this.isConnected){clearInterval(r);return}if(n(),t++,t>50){clearInterval(r);let e=setInterval(()=>{if(!this.isConnected){clearInterval(e);return}n()},1e3);this._dataCheckInterval=e}},100);this._dataCheckInterval=r}_setupDarkModeObserver(){this._darkModeObserver=new MutationObserver(()=>{this.isConnected&&this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]})}disconnectedCallback(){if(this._tooltip&&this._tooltip.parentNode&&(this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=null),this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._pieChartTimeouts.forEach(e=>clearTimeout(e)),this._pieChartTimeouts.clear(),this._pieChartClickOutsideHandler&&=(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),null),this._chartClickOutsideHandler&&=(document.removeEventListener(`click`,this._chartClickOutsideHandler,!0),null),this._pieChartTooltipShown=!1,this._pieChartGroup=null,this._pinnedXValue=null,this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._dataObserver&&=(this._dataObserver.disconnect(),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null),this._dataCheckInterval&&=(clearInterval(this._dataCheckInterval),null),this._svg&&(this._chartTooltipMouseMove&&=(this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),null),this._chartTooltipMouseLeave&&=(this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),null),this._chartTooltipTouchStart&&=(this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),null),this._chartTooltipTouchMove&&=(this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),null),this._chartTooltipTouchEnd&&=(this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),null)),this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement;this._chartTooltipScrollHandler=null}this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null),this._cachedTooltipContent.clear(),this._cachedXPositions.clear(),this._plotPoints.clear(),this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``}}_handleResize(){if(!this.isConnected)return;let e=this.getBoundingClientRect(),t=e.width||this.parentElement?.clientWidth||800,n=e.height||this.parentElement?.clientHeight||400,r=this._calculateDimension(this._widthValue,t,t),i=this._calculateDimension(this._heightValue,n,400);(r!==this._width||i!==this._height)&&(this._width=r,this._height=i,this.render())}_setupResizeObserver(){this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null);let e=null,t=()=>{e&&clearTimeout(e),e=window.setTimeout(()=>{this._handleResize()},100)};this._windowResizeHandler=t,this._resizeObserver=new ResizeObserver(()=>{t()}),this._resizeObserver.observe(this),window.addEventListener(`resize`,t)}attributeChangedCallback(e,t,n){t!==n&&(e===`data`&&this.data&&typeof this.data==`object`&&(this._chartData=this.data),(e===`width`||e===`height`)&&this.isConnected&&(t&&t.endsWith(`%`))!==(n&&n.endsWith(`%`))&&this._setupResizeObserver(),this.isConnected&&requestAnimationFrame(()=>{this.render()}))}get type(){let e=this.getAttribute(`type`)||`line`;return e===`line`||e===`bar`||e===`area`||e===`pie`?e:`line`}set type(e){this.setAttribute(`type`,e)}get data(){return this._chartData}set data(e){if(typeof e==`string`)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}else this._chartData=e;this.isConnected&&requestAnimationFrame(()=>{this.render()})}get width(){let e=this.getAttribute(`width`);if(!e)return this._widthValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._widthValue:t}set width(e){this.setAttribute(`width`,e.toString())}get height(){let e=this.getAttribute(`height`);if(!e)return this._heightValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._heightValue:t}set height(e){this.setAttribute(`height`,e.toString())}_calculateDimension(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!isNaN(n))return t*n/100}return n}_scheduleRender(){this._renderScheduled||(this._renderScheduled=!0,requestAnimationFrame(()=>{this._renderScheduled=!1,this.render()}))}_isDatasetVisible(e,t){if(e.id){let t=this._datasetVisibility.get(e.id);if(t!==void 0)return t}return e.visible!==!1}_initializeDatasetVisibility(){this._chartData&&this._chartData.datasets.forEach((e,t)=>{e.id&&(this._datasetVisibility.has(e.id)||this._datasetVisibility.set(e.id,e.visible!==!1))})}render(){if(!this.isConnected)return;this._plotPoints.clear(),this._activeXValue=null,this._cachedTooltipContent?.clear(),this._cachedXPositions?.clear(),this._chartType=this.type;let e=this._getReactiveValue(this.data);if(e&&typeof e==`object`&&!Array.isArray(e)&&`datasets`in e&&(this._chartData=e),!this._chartData){let e=this.getAttribute(`data`);if(e)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}}this._widthValue=this.width,this._heightValue=this.height;let t=this.getBoundingClientRect(),n=t.width||this.parentElement?.clientWidth||800,r=t.height||this.parentElement?.clientHeight||400;this._width=this._calculateDimension(this._widthValue,n,n),this._height=this._calculateDimension(this._heightValue,r,400),this._showLegend=this.getAttribute(`show-legend`)!==`false`,this._showGrid=this.getAttribute(`show-grid`)!==`false`,this._showTooltip=this.getAttribute(`show-tooltip`)!==`false`;let i=this.getAttribute(`curve-tension`);if(i!==null){let e=parseFloat(i);this._curveTension=isNaN(e)?.5:Math.max(0,Math.min(1,e))}else this._curveTension=.5;if(!this._chartData||!this._chartData.datasets||this._chartData.datasets.length===0){this.innerHTML=`<div class="p-4 text-gray-500">No chart data provided</div>`;return}switch(this.innerHTML=``,this._chartContainer=document.createElement(`div`),this._chartContainer.className=`relative w-full`,typeof this._widthValue==`string`&&this._widthValue.endsWith(`%`)?this._chartContainer.style.width=this._widthValue:this._chartContainer.style.width=`${this._width}px`,typeof this._heightValue==`string`&&this._heightValue.endsWith(`%`)?this._chartContainer.style.height=this._heightValue:this._chartContainer.style.height=`${this._height}px`,this.appendChild(this._chartContainer),this._svg=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),this._svg.setAttribute(`width`,this._width.toString()),this._svg.setAttribute(`height`,this._height.toString()),this._svg.setAttribute(`viewBox`,`0 0 ${this._width} ${this._height}`),this._svg.setAttribute(`class`,`w-full h-full`),this._chartContainer&&this._svg&&this._chartContainer.appendChild(this._svg),this._showTooltip&&this._createTooltip(),this._initializeDatasetVisibility(),this._calculateRotatedLabelHeight(),this._showLegend?this._legendHeight=this._calculateLegendHeight():this._legendHeight=0,this._showLegend&&this._renderLegend(),this._chartType!==`pie`&&this._pieChartClickOutsideHandler&&(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),this._pieChartClickOutsideHandler=null,this._pieChartTooltipShown=!1,this._pieChartGroup=null),this._pinnedXValue=null,this._chartType){case`line`:this._renderLineChart();break;case`bar`:this._renderBarChart();break;case`area`:this._renderAreaChart();break;case`pie`:this._renderPieChart();break}this._showTooltip&&this._chartType!==`pie`&&(this._setupChartTooltip(),this._setupTooltipScrollHandler()),this._createVerticalLine()}_createTooltip(){this._tooltip&&this._tooltip.parentNode&&this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=document.createElement(`div`),this._tooltip.className=`fixed pointer-events-none z-50 bg-gray-900 dark:bg-mint-elevated text-white text-xs rounded px-2 py-1 shadow-lg opacity-0`,this._tooltip.style.display=`none`,document.body.appendChild(this._tooltip)}_showTooltipAt(e,t,n){if(!this._tooltip)return;this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._lastTooltipContent!==n&&(this._tooltip.innerHTML=n,this._lastTooltipContent=n),(this._tooltip.style.display===`none`||this._tooltip.style.opacity===`0`)&&(this._tooltip.style.display=`block`,this._tooltip.style.opacity=`1`,this._tooltip.style.padding=`8px 12px`);let r=this._tooltip.getBoundingClientRect(),i=window.innerWidth,a=window.innerHeight,o=e+10,s=t-r.height-8;o+r.width>i&&(o=e-r.width-10),o<0&&(o=10),s<0&&(s=t+20),s+r.height>a&&(s=t-r.height-8,s<0&&(s=10));let c=`${o}px`,l=`${s}px`;this._tooltip.style.left!==c&&(this._tooltip.style.left=c),this._tooltip.style.top!==l&&(this._tooltip.style.top=l)}_hideTooltip(){this._tooltip&&(this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._tooltip.style.opacity=`0`,this._tooltipHideTimeout=window.setTimeout(()=>{this._tooltip&&(this._tooltip.style.display=`none`),this._tooltipHideTimeout=null},200))}_createVerticalLine(){if(!this._svg)return;this._verticalLine&&this._verticalLine.parentNode&&this._verticalLine.parentNode.removeChild(this._verticalLine),this._verticalLine=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);let e=document.documentElement.classList.contains(`dark`);this._verticalLine.setAttribute(`stroke`,e?`#9ca3af`:`#6b7280`),this._verticalLine.setAttribute(`stroke-width`,`1`),this._verticalLine.setAttribute(`stroke-dasharray`,`4,2`),this._verticalLine.style.opacity=`0`,this._verticalLine.style.pointerEvents=`none`;let t=this._svg.querySelector(`.chart-legend`);t&&t.parentNode?t.parentNode.insertBefore(this._verticalLine,t):this._svg.appendChild(this._verticalLine)}_showVerticalLineAtX(e,t){if(!this._verticalLine)return;let n=this._chartType===`bar`?this._scaleXForBarChart(e,t):this._scaleX(e,t);this._verticalLine.setAttribute(`x1`,n.toString()),this._verticalLine.setAttribute(`y1`,t.y.toString()),this._verticalLine.setAttribute(`x2`,n.toString()),this._verticalLine.setAttribute(`y2`,(t.y+t.height).toString()),this._verticalLine.style.opacity=`1`}_hideVerticalLine(){this._verticalLine&&(this._verticalLine.style.opacity=`0`)}_showPlotPointsForX(e){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})});let t=String(e),n=this._plotPoints.get(t);n&&n.forEach(e=>{e.style.opacity=`1`})}_hidePlotPoints(){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})})}_calculateMaxYAxisLabelWidth(){if(!this._showGrid||!this._chartData)return 0;let e=document.createElement(`canvas`).getContext(`2d`);if(!e)return 60;e.font=`12px system-ui, -apple-system, sans-serif`;let t=this._showLegend?Math.max(this._legendHeight,60):0,n=this._height-t,r=Math.floor(n/35),i=Math.min(5,r),a=0;for(let t=0;t<=i;t++){let n=this._getYRange(),r=n.max-(n.max-n.min)/i*t,o=this._formatYAxisValue(r),s=e.measureText(o);a=Math.max(a,s.width)}return Math.ceil(a)+20}_getChartBounds(){let e=this._calculateMaxYAxisLabelWidth(),t=`${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${e}-${this._rotatedLabelHeight}`;if(this._cachedBounds.bounds&&this._cachedBounds.dataHash===t)return this._cachedBounds.bounds;let n=0,r=0;this._showGrid&&(n=e+10);let i=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12,a=i;this._showLegend&&(a=i+20+Math.max(this._legendHeight,60));let o=this._height-0-n-0,s=o-a,c=1;if(s<100&&a>0){let e=o-100;e>0?(c=Math.min(1,e/a),c=Math.max(.5,c)):c=.5}r=a*c;let l=this._width*.3,u=n,d=1;n>l&&(d=l/n,u=l);let f={width:(this._width-u-0)*d,height:this._height-0-r,x:u,y:0};return this._cachedBounds={bounds:f,dataHash:t},f}_getAllDataPoints(){if(!this._chartData)return[];let e=[];return this._chartData.datasets.forEach((t,n)=>{this._isDatasetVisible(t,n)&&e.push(...t.data)}),e}_getXValues(){if(!this._chartData)return[];let e=JSON.stringify(this._chartData.labels)+JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.x)));if(this._cachedXValues.values&&this._cachedXValues.dataHash===e)return this._cachedXValues.values;if(this._chartData.labels&&this._chartData.labels.length>0)return this._cachedXValues={values:this._chartData.labels,dataHash:e},this._chartData.labels;let t=new Set;this._chartData.datasets.forEach((e,n)=>{this._isDatasetVisible(e,n)&&e.data.forEach(e=>{t.add(e.x)})});let n=Array.from(t).sort((e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;let n=String(e),r=String(t),i=/^([A-Za-z]{3})\s+(\d{4})$/,a=n.match(i),o=r.match(i);if(a&&o){let e=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],t=e.indexOf(a[1]),n=e.indexOf(o[1]),r=parseInt(a[2]),i=parseInt(o[2]);return r===i?t-n:r-i}return n.localeCompare(r)});return this._cachedXValues={values:n,dataHash:e},n}_getYRange(){if(!this._chartData)return{min:0,max:100};let e=JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.y)));if(this._cachedYRange.range&&this._cachedYRange.dataHash===e)return this._cachedYRange.range;let t=this._getAllDataPoints();if(t.length===0){let t={min:0,max:100};return this._cachedYRange={range:t,dataHash:e},t}let n=t.map(e=>e.y),r=Math.min(...n),i=Math.max(...n),a=(i-r)*.1,o={min:Math.max(0,r-a),max:i+a};return this._cachedYRange={range:o,dataHash:e},o}_hasDecimalValues(){return this._getAllDataPoints().some(e=>e.y%1!=0)}_formatValueByString(e,t){switch(t.toLowerCase()){case`currency`:case`currency-usd`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`}).format(e);case`currency-eur`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`EUR`}).format(e);case`currency-gbp`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`GBP`}).format(e);case`number`:case`number-with-commas`:return new Intl.NumberFormat(`en-US`).format(e);case`percent`:return new Intl.NumberFormat(`en-US`,{style:`percent`,minimumFractionDigits:1}).format(e/100);default:return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}}_formatXAxisValue(e){if(this._chartData?.formatXAxis){if(typeof this._chartData.formatXAxis==`function`)return this._chartData.formatXAxis(e);if(typeof this._chartData.formatXAxis==`string`)return String(e)}return String(e)}_escapeHtmlForTooltip(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}_tooltipXHeadingHtml(e){return`<strong>${this._escapeHtmlForTooltip(this._formatXAxisValue(e))}</strong><br/>`}_formatYAxisValue(e){if(this._chartData?.formatYAxis){if(typeof this._chartData.formatYAxis==`function`)return this._chartData.formatYAxis(e);if(typeof this._chartData.formatYAxis==`string`)return this._formatValueByString(e,this._chartData.formatYAxis)}if(this._chartData?.datasets?.[0]?.formatValue){if(typeof this._chartData.datasets[0].formatValue==`function`)return this._chartData.datasets[0].formatValue(e);if(typeof this._chartData.datasets[0].formatValue==`string`)return this._formatValueByString(e,this._chartData.datasets[0].formatValue)}return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}_formatValue(e,t){if(t.formatValue){if(typeof t.formatValue==`function`)return t.formatValue(e);if(typeof t.formatValue==`string`)return this._formatValueByString(e,t.formatValue)}return String(e)}_getAllDatasetsAtX(e){if(!this._chartData)return[];let t=[];return this._chartData.datasets.forEach((n,r)=>{if(!this._isDatasetVisible(n,r))return;let i=n.data.find(t=>String(t.x)===String(e));if(i){let e=this._getDatasetColor(n,r),a=this._formatValue(i.y,n);t.push({name:n.name,value:i.y,color:e,formattedValue:a})}}),t}_findNearestXValue(e){if(!this._chartData)return null;let t=this._getChartBounds(),n=this._getXValues();if(n.length===0)return null;let r=this._chartType===`bar`,i=null,a=1/0;return n.forEach(n=>{let o=r?this._scaleXForBarChart(n,t):this._scaleX(n,t),s=Math.abs(e-o);s<a&&(a=s,i=n)}),i}_setupTooltipScrollHandler(){if(this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}this._chartTooltipScrollHandler=()=>{this._hideTooltip(),this._pinnedXValue=null},window.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;){let t=window.getComputedStyle(e),n=t.overflow,r=t.overflowY;(n===`auto`||n===`scroll`||r===`auto`||r===`scroll`)&&e.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}}_setupChartTooltip(){if(!this._svg||!this._showTooltip)return;this._chartTooltipMouseMove&&this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),this._chartTooltipMouseLeave&&this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),this._chartTooltipClick&&this._svg.removeEventListener(`click`,this._chartTooltipClick),this._chartTooltipTouchStart&&this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),this._chartTooltipTouchMove&&this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),this._chartTooltipTouchEnd&&this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),this._cachedTooltipContent.clear(),this._cachedXPositions.clear();let t=this._getChartBounds(),n=0,r=0,i=i=>{!this._chartContainer||!this._svg||(n=i.clientX,r=i.clientY,this._tooltipAnimationFrame!==null&&cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=requestAnimationFrame(()=>{if(this._tooltipAnimationFrame=null,!this._svg)return;let i=this._svg.getBoundingClientRect(),a=n-i.left,o=r-i.top;if(a<t.x||a>t.x+t.width||o<t.y||o>t.y+t.height){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}let s=this._findNearestXValue(a);if(!s){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}if(this._pinnedXValue!==null&&this._pinnedXValue===s){let e=this._pinnedXValue,i=this._getAllDatasetsAtX(e);if(i.length>0){this._activeXValue=e,this._showPlotPointsForX(e),this._showVerticalLineAtX(e,t);let a=this._cachedTooltipContent.get(e);a||(a=this._tooltipXHeadingHtml(e),i.forEach(e=>{a+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
101
|
+
`,document.head.appendChild(e)}}};customElements.get(`mint-off-canvas`)||customElements.define(`mint-off-canvas`,oe);var N=class extends HTMLElement{static get observedAttributes(){return[`active`,`disabled`,`target`]}constructor(){super(),this._clickHandler=null}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(e,t,n){t!==n&&this.render()}getTarget(){return this.getAttribute(`target`)||``}isActive(){let e=this.getAttribute(`active`);return e!==null&&e!==`false`}isDisabled(){return this.getAttribute(`disabled`)===`true`}get active(){return this.isActive()}set active(e){e?this.setAttribute(`active`,`true`):this.setAttribute(`active`,`false`)}render(){let e=this.isActive(),t=this.isDisabled();this.className=``,this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`inline-block`,`cursor-pointer`,`px-4`,`py-1.5`,`text-sm`,`font-medium`,`rounded-lg`,`border`,`text-gray-700`,`dark:text-gray-300`);let n=this.closest(`mint-tab-list`)?.getAttribute(`position`)||`top`,r=n===`left`||n===`right`;t?(this.classList.add(`opacity-60`,`cursor-not-allowed`,`pointer-events-none`,`bg-gray-50`,`dark:bg-mint-elevated`,`border-gray-300`,`dark:border-mint-divider`,`text-gray-400`,`dark:text-gray-500`),this.classList.remove(`cursor-pointer`)):e?(this.classList.add(`bg-white`,`dark:bg-mint-elevated`,`border-gray-200`,`dark:border-mint-divider`,`text-gray-900`,`dark:text-gray-100`,`shadow-sm`,`relative`,`z-10`),r?n===`left`?this.classList.add(`mr-[-1px]`):this.classList.add(`ml-[-1px]`):this.classList.add(`mb-[-1px]`)):this.classList.add(`bg-gray-100`,`dark:bg-mint-elevated`,`border-gray-200`,`dark:border-mint-divider`,`text-gray-600`,`dark:text-gray-400`,`hover:bg-gray-50`,`dark:hover:bg-mint-hover`)}setupEventListeners(){this.isDisabled()||this._clickHandler||(this._clickHandler=this.handleClick.bind(this),this.addEventListener(`click`,this._clickHandler))}removeEventListeners(){this._clickHandler&&=(this.removeEventListener(`click`,this._clickHandler),null)}handleClick(e){if(this.isDisabled()){e.preventDefault(),e.stopPropagation();return}e.__mintTabsSynthetic||(e.stopPropagation(),this.dispatchEvent(new CustomEvent(`tab-click`,{detail:{tab:this,target:this.getTarget()},bubbles:!0,cancelable:!0,composed:!0})))}};customElements.get(`mint-tab`)||customElements.define(`mint-tab`,N);var P=class extends HTMLElement{static get observedAttributes(){return[`position`]}constructor(){super()}connectedCallback(){this.render()}attributeChangedCallback(e,t,n){t!==n&&this.render()}getPosition(){return this.getAttribute(`position`)||`top`}render(){let e=this.getPosition();this.classList.remove(`flex`,`inline-flex`,`flex-row`,`flex-col`,`gap-1`,`gap-2`,`pb-0`,`pr-0`,`pl-0`,`mb-0`,`mr-0`,`ml-0`,`self-start`),this.classList.add(`box-border`,`m-0`,`p-1`,`border`,`bg-gray-100`,`dark:bg-mint-elevated`,`dark:border-mint-divider`,`border-gray-200`,`w-auto`,`rounded-lg`,`gap-2`),e===`top`?this.classList.add(`inline-flex`,`flex-row`,`mb-0`,`self-start`):e===`left`?this.classList.add(`flex`,`flex-col`,`mr-0`):e===`right`&&this.classList.add(`flex`,`flex-col`,`ml-0`)}};customElements.get(`mint-tab-list`)||customElements.define(`mint-tab-list`,P);var F=class extends HTMLElement{static get observedAttributes(){return[`id`]}constructor(){super()}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`block`,`w-full`),this.render(),this.checkInitialVisibility()}attributeChangedCallback(e,t,n){t!==n&&e===`id`&&(this.render(),this.checkInitialVisibility())}getId(){return this.getAttribute(`id`)||``}show(){this.style.display=`block`}hide(){this.style.display=`none`}checkInitialVisibility(){let e=this.closest(`mint-tabs`);if(!e){this.style.display=`none`;return}let t=e.querySelectorAll(`mint-tab`),n=!1;t.forEach(e=>{let t=e.getAttribute(`active`),r=e.getAttribute(`target`),i=this.getId();t===`true`&&r===i&&(n=!0)}),!n&&t.length>0&&t[0].getAttribute(`target`)===this.getId()&&!e.querySelector(`mint-tab[active="true"]`)&&(n=!0),n?this.style.display=`block`:this.style.display=`none`}render(){}};customElements.get(`mint-tab-content`)||customElements.define(`mint-tab-content`,F);var I=class extends HTMLElement{constructor(){super(),this._tabClickHandler=null,this._mutationObserver=null}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`block`),this.render(),this.setupEventListeners(),this.setupMutationObserver(),this.initializeActiveTab()}disconnectedCallback(){this.removeEventListeners(),this._mutationObserver&&=(this._mutationObserver.disconnect(),null)}render(){let e=this.querySelector(`mint-tab-list`);if(this.querySelectorAll(`mint-tab-content`),!e){console.warn(`mint-tabs: mint-tab-list is required`);return}let t=e.getAttribute(`position`)||`top`;this.classList.remove(`flex`,`flex-row`,`flex-col`,`gap-4`,`gap-6`),t===`left`||t===`right`?(this.classList.add(`flex`,`flex-row`,`items-start`),t===`left`?(e.classList.add(`mr-4`,`flex-shrink-0`),e.classList.remove(`ml-4`)):(e.classList.add(`ml-4`,`flex-shrink-0`,`order-2`),e.classList.remove(`mr-4`),this.querySelectorAll(`mint-tab-content`).forEach(e=>{e.classList.add(`order-1`)}))):(this.classList.add(`flex`,`flex-col`),e.classList.remove(`mr-4`,`ml-4`,`flex-shrink-0`,`order-2`),this.querySelectorAll(`mint-tab-content`).forEach(e=>{e.classList.remove(`order-1`)}))}initializeActiveTab(){requestAnimationFrame(()=>{let e=this.querySelectorAll(`mint-tab`),t=null;if(e.forEach(e=>{e.getAttribute(`active`)===`true`&&(t=e)}),!t&&e.length>0&&(t=e[0],t.setAttribute(`active`,`true`)),t){let e=t.getAttribute(`target`);e?this.showContent(e):this.hideAllContent()}else this.hideAllContent();this.querySelectorAll(`mint-tab-content`).forEach(e=>{let t=e;t.checkInitialVisibility&&t.checkInitialVisibility()})})}hideAllContent(){this.querySelectorAll(`mint-tab-content`).forEach(e=>{let t=e;t.hide?t.hide():e.style.display=`none`})}showContent(e){this.querySelectorAll(`mint-tab-content`).forEach(e=>{let t=e;t.hide?t.hide():e.style.display=`none`});let t=this.querySelector(`mint-tab-content[id="${e}"]`);t&&(t.show?t.show():t.style.display=`block`)}setupEventListeners(){this._tabClickHandler||(this._tabClickHandler=this.handleTabClick.bind(this),this.addEventListener(`tab-click`,this._tabClickHandler))}removeEventListeners(){this._tabClickHandler&&=(this.removeEventListener(`tab-click`,this._tabClickHandler),null)}setupMutationObserver(){this._mutationObserver=new MutationObserver(()=>{this.render()});let e=this.querySelector(`mint-tab-list`);e&&this._mutationObserver.observe(e,{attributes:!0,attributeFilter:[`position`]})}handleTabClick(e){let t=e.detail?.tab,n=e.detail?.target;if(!t)return;let r=t.closest(`mint-tab-list`);r&&(r.querySelectorAll(`mint-tab`).forEach(e=>{let n=e;e===t?n.active=!0:n.active=!1}),n&&this.showContent(n))}};customElements.get(`mint-tabs`)||customElements.define(`mint-tabs`,I);var L=class e extends HTMLElement{static get observedAttributes(){return[`type`,`data`,`width`,`height`,`show-legend`,`show-grid`,`show-tooltip`,`curve-tension`]}static{this.MAX_CACHE_SIZE=100}constructor(){super(),this._chartContainer=null,this._svg=null,this._tooltip=null,this._chartType=`line`,this._chartData=null,this._width=800,this._height=400,this._padding={top:20,right:20,bottom:60,left:60},this._showLegend=!0,this._showGrid=!0,this._showTooltip=!0,this._curveTension=.5,this._dataObserver=null,this._darkModeObserver=null,this._tooltipHideTimeout=null,this._lastTooltipContent=``,this._activeXValue=null,this._pinnedXValue=null,this._tooltipAnimationFrame=null,this._cachedTooltipContent=new Map,this._cachedXPositions=new Map,this._verticalLine=null,this._plotPoints=new Map,this._resizeObserver=null,this._windowResizeHandler=null,this._pieChartTimeouts=new Set,this._pieChartTooltipShown=!1,this._pieChartClickOutsideHandler=null,this._pieChartGroup=null,this._chartClickOutsideHandler=null,this._chartTooltipScrollHandler=null,this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``},this._renderScheduled=!1,this._datasetVisibility=new Map,this._widthValue=`100%`,this._heightValue=400,this._defaultColors=[`#2563eb`,`#3b82f6`,`#0d9488`,`#7c3aed`,`#d97706`,`#059669`,`#dc2626`,`#c026d3`],this._legendHeight=0,this._rotatedLabelHeight=0}connectedCallback(){this.classList.add(`box-border`,`m-0`,`p-0`,`border-0`,`align-baseline`,`block`,`w-full`);let e=this._getReactiveValue(this.data);e&&typeof e==`object`&&!Array.isArray(e)&&`datasets`in e&&(this._chartData=e),this._setupDataObserver(),this._setupDarkModeObserver(),this._setupResizeObserver(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.render()})})}_getReactiveValue(e){if(!e||typeof e!=`object`)return e;if(`_value`in e||`__v_isRef`in e){if(e.value!==void 0)return e.value;if(`_value`in e)return e._value}return`__v_raw`in e||`__v_isReactive`in e||`__ob__`in e,e}_setupDataObserver(){let e=null,t=0,n=()=>{if(!this.isConnected)return;let t=this._getReactiveValue(this.data),n=null;t&&typeof t==`object`&&!Array.isArray(t)&&`datasets`in t&&(n=t),n!==e&&n&&(e=n,this._chartData=n,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this.render())};requestAnimationFrame(()=>{n(),requestAnimationFrame(()=>{n()})});let r=setInterval(()=>{if(!this.isConnected){clearInterval(r);return}if(n(),t++,t>50){clearInterval(r);let e=setInterval(()=>{if(!this.isConnected){clearInterval(e);return}n()},1e3);this._dataCheckInterval=e}},100);this._dataCheckInterval=r}_setupDarkModeObserver(){this._darkModeObserver=new MutationObserver(()=>{this.isConnected&&this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]})}disconnectedCallback(){if(this._tooltip&&this._tooltip.parentNode&&(this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=null),this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._pieChartTimeouts.forEach(e=>clearTimeout(e)),this._pieChartTimeouts.clear(),this._pieChartClickOutsideHandler&&=(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),null),this._chartClickOutsideHandler&&=(document.removeEventListener(`click`,this._chartClickOutsideHandler,!0),null),this._pieChartTooltipShown=!1,this._pieChartGroup=null,this._pinnedXValue=null,this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._dataObserver&&=(this._dataObserver.disconnect(),null),this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null),this._dataCheckInterval&&=(clearInterval(this._dataCheckInterval),null),this._svg&&(this._chartTooltipMouseMove&&=(this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),null),this._chartTooltipMouseLeave&&=(this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),null),this._chartTooltipTouchStart&&=(this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),null),this._chartTooltipTouchMove&&=(this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),null),this._chartTooltipTouchEnd&&=(this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),null)),this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement;this._chartTooltipScrollHandler=null}this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null),this._cachedTooltipContent.clear(),this._cachedXPositions.clear(),this._plotPoints.clear(),this._cachedBounds={bounds:null,dataHash:``},this._cachedYRange={range:null,dataHash:``},this._cachedXValues={values:null,dataHash:``}}_handleResize(){if(!this.isConnected)return;let e=this.getBoundingClientRect(),t=e.width||this.parentElement?.clientWidth||800,n=e.height||this.parentElement?.clientHeight||400,r=this._calculateDimension(this._widthValue,t,t),i=this._calculateDimension(this._heightValue,n,400);(r!==this._width||i!==this._height)&&(this._width=r,this._height=i,this.render())}_setupResizeObserver(){this._resizeObserver&&=(this._resizeObserver.disconnect(),null),this._windowResizeHandler&&=(window.removeEventListener(`resize`,this._windowResizeHandler),null);let e=null,t=()=>{e&&clearTimeout(e),e=window.setTimeout(()=>{this._handleResize()},100)};this._windowResizeHandler=t,this._resizeObserver=new ResizeObserver(()=>{t()}),this._resizeObserver.observe(this),window.addEventListener(`resize`,t)}attributeChangedCallback(e,t,n){t!==n&&(e===`data`&&this.data&&typeof this.data==`object`&&(this._chartData=this.data),(e===`width`||e===`height`)&&this.isConnected&&(t&&t.endsWith(`%`))!==(n&&n.endsWith(`%`))&&this._setupResizeObserver(),this.isConnected&&requestAnimationFrame(()=>{this.render()}))}get type(){let e=this.getAttribute(`type`)||`line`;return e===`line`||e===`bar`||e===`area`||e===`pie`?e:`line`}set type(e){this.setAttribute(`type`,e)}get data(){return this._chartData}set data(e){if(typeof e==`string`)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}else this._chartData=e;this.isConnected&&requestAnimationFrame(()=>{this.render()})}get width(){let e=this.getAttribute(`width`);if(!e)return this._widthValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._widthValue:t}set width(e){this.setAttribute(`width`,e.toString())}get height(){let e=this.getAttribute(`height`);if(!e)return this._heightValue;if(e.endsWith(`%`))return e;let t=parseInt(e,10);return isNaN(t)?this._heightValue:t}set height(e){this.setAttribute(`height`,e.toString())}_calculateDimension(e,t,n){if(typeof e==`number`)return e;if(typeof e==`string`&&e.endsWith(`%`)){let n=parseFloat(e);if(!isNaN(n))return t*n/100}return n}_scheduleRender(){this._renderScheduled||(this._renderScheduled=!0,requestAnimationFrame(()=>{this._renderScheduled=!1,this.render()}))}_isDatasetVisible(e,t){if(e.id){let t=this._datasetVisibility.get(e.id);if(t!==void 0)return t}return e.visible!==!1}_initializeDatasetVisibility(){this._chartData&&this._chartData.datasets.forEach((e,t)=>{e.id&&(this._datasetVisibility.has(e.id)||this._datasetVisibility.set(e.id,e.visible!==!1))})}render(){if(!this.isConnected)return;this._plotPoints.clear(),this._activeXValue=null,this._cachedTooltipContent?.clear(),this._cachedXPositions?.clear(),this._chartType=this.type;let e=this._getReactiveValue(this.data);if(e&&typeof e==`object`&&!Array.isArray(e)&&`datasets`in e&&(this._chartData=e),!this._chartData){let e=this.getAttribute(`data`);if(e)try{this._chartData=JSON.parse(e)}catch(e){console.error(`mint-chart: Invalid data JSON`,e),this._chartData=null}}this._widthValue=this.width,this._heightValue=this.height;let t=this.getBoundingClientRect(),n=t.width||this.parentElement?.clientWidth||800,r=t.height||this.parentElement?.clientHeight||400;this._width=this._calculateDimension(this._widthValue,n,n),this._height=this._calculateDimension(this._heightValue,r,400),this._showLegend=this.getAttribute(`show-legend`)!==`false`,this._showGrid=this.getAttribute(`show-grid`)!==`false`,this._showTooltip=this.getAttribute(`show-tooltip`)!==`false`;let i=this.getAttribute(`curve-tension`);if(i!==null){let e=parseFloat(i);this._curveTension=isNaN(e)?.5:Math.max(0,Math.min(1,e))}else this._curveTension=.5;if(!this._chartData||!this._chartData.datasets||this._chartData.datasets.length===0){this.innerHTML=`<div class="p-4 text-gray-500">No chart data provided</div>`;return}switch(this.innerHTML=``,this._chartContainer=document.createElement(`div`),this._chartContainer.className=`relative w-full`,typeof this._widthValue==`string`&&this._widthValue.endsWith(`%`)?this._chartContainer.style.width=this._widthValue:this._chartContainer.style.width=`${this._width}px`,typeof this._heightValue==`string`&&this._heightValue.endsWith(`%`)?this._chartContainer.style.height=this._heightValue:this._chartContainer.style.height=`${this._height}px`,this.appendChild(this._chartContainer),this._svg=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),this._svg.setAttribute(`width`,this._width.toString()),this._svg.setAttribute(`height`,this._height.toString()),this._svg.setAttribute(`viewBox`,`0 0 ${this._width} ${this._height}`),this._svg.setAttribute(`class`,`w-full h-full`),this._chartContainer&&this._svg&&this._chartContainer.appendChild(this._svg),this._showTooltip&&this._createTooltip(),this._initializeDatasetVisibility(),this._calculateRotatedLabelHeight(),this._showLegend?this._legendHeight=this._calculateLegendHeight():this._legendHeight=0,this._showLegend&&this._renderLegend(),this._chartType!==`pie`&&this._pieChartClickOutsideHandler&&(document.removeEventListener(`click`,this._pieChartClickOutsideHandler,!0),this._pieChartClickOutsideHandler=null,this._pieChartTooltipShown=!1,this._pieChartGroup=null),this._pinnedXValue=null,this._chartType){case`line`:this._renderLineChart();break;case`bar`:this._renderBarChart();break;case`area`:this._renderAreaChart();break;case`pie`:this._renderPieChart();break}this._showTooltip&&this._chartType!==`pie`&&(this._setupChartTooltip(),this._setupTooltipScrollHandler()),this._createVerticalLine()}_createTooltip(){this._tooltip&&this._tooltip.parentNode&&this._tooltip.parentNode.removeChild(this._tooltip),this._tooltip=document.createElement(`div`),this._tooltip.className=`fixed pointer-events-none z-50 bg-gray-900 dark:bg-mint-elevated text-white text-xs rounded px-2 py-1 shadow-lg opacity-0`,this._tooltip.style.display=`none`,document.body.appendChild(this._tooltip)}_showTooltipAt(e,t,n){if(!this._tooltip)return;this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._lastTooltipContent!==n&&(this._tooltip.innerHTML=n,this._lastTooltipContent=n),(this._tooltip.style.display===`none`||this._tooltip.style.opacity===`0`)&&(this._tooltip.style.display=`block`,this._tooltip.style.opacity=`1`,this._tooltip.style.padding=`8px 12px`);let r=this._tooltip.getBoundingClientRect(),i=window.innerWidth,a=window.innerHeight,o=e+10,s=t-r.height-8;o+r.width>i&&(o=e-r.width-10),o<0&&(o=10),s<0&&(s=t+20),s+r.height>a&&(s=t-r.height-8,s<0&&(s=10));let c=`${o}px`,l=`${s}px`;this._tooltip.style.left!==c&&(this._tooltip.style.left=c),this._tooltip.style.top!==l&&(this._tooltip.style.top=l)}_hideTooltip(){this._tooltip&&(this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._tooltip.style.opacity=`0`,this._tooltipHideTimeout=window.setTimeout(()=>{this._tooltip&&(this._tooltip.style.display=`none`),this._tooltipHideTimeout=null},200))}_createVerticalLine(){if(!this._svg)return;this._verticalLine&&this._verticalLine.parentNode&&this._verticalLine.parentNode.removeChild(this._verticalLine),this._verticalLine=document.createElementNS(`http://www.w3.org/2000/svg`,`line`);let e=document.documentElement.classList.contains(`dark`);this._verticalLine.setAttribute(`stroke`,e?`#9ca3af`:`#6b7280`),this._verticalLine.setAttribute(`stroke-width`,`1`),this._verticalLine.setAttribute(`stroke-dasharray`,`4,2`),this._verticalLine.style.opacity=`0`,this._verticalLine.style.pointerEvents=`none`;let t=this._svg.querySelector(`.chart-legend`);t&&t.parentNode?t.parentNode.insertBefore(this._verticalLine,t):this._svg.appendChild(this._verticalLine)}_showVerticalLineAtX(e,t){if(!this._verticalLine)return;let n=this._chartType===`bar`?this._scaleXForBarChart(e,t):this._scaleX(e,t);this._verticalLine.setAttribute(`x1`,n.toString()),this._verticalLine.setAttribute(`y1`,t.y.toString()),this._verticalLine.setAttribute(`x2`,n.toString()),this._verticalLine.setAttribute(`y2`,(t.y+t.height).toString()),this._verticalLine.style.opacity=`1`}_hideVerticalLine(){this._verticalLine&&(this._verticalLine.style.opacity=`0`)}_showPlotPointsForX(e){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})});let t=String(e),n=this._plotPoints.get(t);n&&n.forEach(e=>{e.style.opacity=`1`})}_hidePlotPoints(){this._plotPoints.forEach(e=>{e.forEach(e=>{e.style.opacity=`0`})})}_calculateMaxYAxisLabelWidth(){if(!this._showGrid||!this._chartData)return 0;let e=document.createElement(`canvas`).getContext(`2d`);if(!e)return 60;e.font=`12px system-ui, -apple-system, sans-serif`;let t=this._showLegend?Math.max(this._legendHeight,60):0,n=this._height-t,r=Math.floor(n/35),i=Math.min(5,r),a=0;for(let t=0;t<=i;t++){let n=this._getYRange(),r=n.max-(n.max-n.min)/i*t,o=this._formatYAxisValue(r),s=e.measureText(o);a=Math.max(a,s.width)}return Math.ceil(a)+20}_getChartBounds(){let e=this._calculateMaxYAxisLabelWidth(),t=`${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${e}-${this._rotatedLabelHeight}`;if(this._cachedBounds.bounds&&this._cachedBounds.dataHash===t)return this._cachedBounds.bounds;let n=0,r=0;this._showGrid&&(n=e+10);let i=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12,a=i;this._showLegend&&(a=i+20+Math.max(this._legendHeight,60));let o=this._height-0-n-0,s=o-a,c=1;if(s<100&&a>0){let e=o-100;e>0?(c=Math.min(1,e/a),c=Math.max(.5,c)):c=.5}r=a*c;let l=this._width*.3,u=n,d=1;n>l&&(d=l/n,u=l);let f={width:(this._width-u-0)*d,height:this._height-0-r,x:u,y:0};return this._cachedBounds={bounds:f,dataHash:t},f}_getAllDataPoints(){if(!this._chartData)return[];let e=[];return this._chartData.datasets.forEach((t,n)=>{this._isDatasetVisible(t,n)&&e.push(...t.data)}),e}_getXValues(){if(!this._chartData)return[];let e=JSON.stringify(this._chartData.labels)+JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.x)));if(this._cachedXValues.values&&this._cachedXValues.dataHash===e)return this._cachedXValues.values;if(this._chartData.labels&&this._chartData.labels.length>0)return this._cachedXValues={values:this._chartData.labels,dataHash:e},this._chartData.labels;let t=new Set;this._chartData.datasets.forEach((e,n)=>{this._isDatasetVisible(e,n)&&e.data.forEach(e=>{t.add(e.x)})});let n=Array.from(t).sort((e,t)=>{if(typeof e==`number`&&typeof t==`number`)return e-t;let n=String(e),r=String(t),i=/^([A-Za-z]{3})\s+(\d{4})$/,a=n.match(i),o=r.match(i);if(a&&o){let e=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],t=e.indexOf(a[1]),n=e.indexOf(o[1]),r=parseInt(a[2]),i=parseInt(o[2]);return r===i?t-n:r-i}return n.localeCompare(r)});return this._cachedXValues={values:n,dataHash:e},n}_getYRange(){if(!this._chartData)return{min:0,max:100};let e=JSON.stringify(this._chartData.datasets.map(e=>e.data.map(e=>e.y)));if(this._cachedYRange.range&&this._cachedYRange.dataHash===e)return this._cachedYRange.range;let t=this._getAllDataPoints();if(t.length===0){let t={min:0,max:100};return this._cachedYRange={range:t,dataHash:e},t}let n=t.map(e=>e.y),r=Math.min(...n),i=Math.max(...n),a=(i-r)*.1,o={min:Math.max(0,r-a),max:i+a};return this._cachedYRange={range:o,dataHash:e},o}_hasDecimalValues(){return this._getAllDataPoints().some(e=>e.y%1!=0)}_formatValueByString(e,t){switch(t.toLowerCase()){case`currency`:case`currency-usd`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`}).format(e);case`currency-eur`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`EUR`}).format(e);case`currency-gbp`:return new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`GBP`}).format(e);case`number`:case`number-with-commas`:return new Intl.NumberFormat(`en-US`).format(e);case`percent`:return new Intl.NumberFormat(`en-US`,{style:`percent`,minimumFractionDigits:1}).format(e/100);default:return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}}_formatXAxisValue(e){if(this._chartData?.formatXAxis){if(typeof this._chartData.formatXAxis==`function`)return this._chartData.formatXAxis(e);if(typeof this._chartData.formatXAxis==`string`)return String(e)}return String(e)}_escapeHtmlForTooltip(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}_tooltipXHeadingHtml(e){return`<strong>${this._escapeHtmlForTooltip(this._formatXAxisValue(e))}</strong><br/>`}_formatYAxisValue(e){if(this._chartData?.formatYAxis){if(typeof this._chartData.formatYAxis==`function`)return this._chartData.formatYAxis(e);if(typeof this._chartData.formatYAxis==`string`)return this._formatValueByString(e,this._chartData.formatYAxis)}if(this._chartData?.datasets?.[0]?.formatValue){if(typeof this._chartData.datasets[0].formatValue==`function`)return this._chartData.datasets[0].formatValue(e);if(typeof this._chartData.datasets[0].formatValue==`string`)return this._formatValueByString(e,this._chartData.datasets[0].formatValue)}return this._hasDecimalValues()&&e%1!=0?e.toFixed(1):Math.round(e).toString()}_formatValue(e,t){if(t.formatValue){if(typeof t.formatValue==`function`)return t.formatValue(e);if(typeof t.formatValue==`string`)return this._formatValueByString(e,t.formatValue)}return String(e)}_getAllDatasetsAtX(e){if(!this._chartData)return[];let t=[];return this._chartData.datasets.forEach((n,r)=>{if(!this._isDatasetVisible(n,r))return;let i=n.data.find(t=>String(t.x)===String(e));if(i){let e=this._getDatasetColor(n,r),a=this._formatValue(i.y,n);t.push({name:n.name,value:i.y,color:e,formattedValue:a})}}),t}_findNearestXValue(e){if(!this._chartData)return null;let t=this._getChartBounds(),n=this._getXValues();if(n.length===0)return null;let r=this._chartType===`bar`,i=null,a=1/0;return n.forEach(n=>{let o=r?this._scaleXForBarChart(n,t):this._scaleX(n,t),s=Math.abs(e-o);s<a&&(a=s,i=n)}),i}_setupTooltipScrollHandler(){if(this._chartTooltipScrollHandler){window.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;)e.removeEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}this._chartTooltipScrollHandler=()=>{this._hideTooltip(),this._pinnedXValue=null},window.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),this._chartContainer&&this._chartContainer.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0);let e=this.parentElement;for(;e;){let t=window.getComputedStyle(e),n=t.overflow,r=t.overflowY;(n===`auto`||n===`scroll`||r===`auto`||r===`scroll`)&&e.addEventListener(`scroll`,this._chartTooltipScrollHandler,!0),e=e.parentElement}}_setupChartTooltip(){if(!this._svg||!this._showTooltip)return;this._chartTooltipMouseMove&&this._svg.removeEventListener(`mousemove`,this._chartTooltipMouseMove),this._chartTooltipMouseLeave&&this._svg.removeEventListener(`mouseleave`,this._chartTooltipMouseLeave),this._chartTooltipClick&&this._svg.removeEventListener(`click`,this._chartTooltipClick),this._chartTooltipTouchStart&&this._svg.removeEventListener(`touchstart`,this._chartTooltipTouchStart),this._chartTooltipTouchMove&&this._svg.removeEventListener(`touchmove`,this._chartTooltipTouchMove),this._chartTooltipTouchEnd&&this._svg.removeEventListener(`touchend`,this._chartTooltipTouchEnd),this._cachedTooltipContent.clear(),this._cachedXPositions.clear();let t=this._getChartBounds(),n=0,r=0,i=i=>{!this._chartContainer||!this._svg||(n=i.clientX,r=i.clientY,this._tooltipAnimationFrame!==null&&cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=requestAnimationFrame(()=>{if(this._tooltipAnimationFrame=null,!this._svg)return;let i=this._svg.getBoundingClientRect(),a=n-i.left,o=r-i.top;if(a<t.x||a>t.x+t.width||o<t.y||o>t.y+t.height){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}let s=this._findNearestXValue(a);if(!s){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}if(this._pinnedXValue!==null&&this._pinnedXValue===s){let e=this._pinnedXValue,i=this._getAllDatasetsAtX(e);if(i.length>0){this._activeXValue=e,this._showPlotPointsForX(e),this._showVerticalLineAtX(e,t);let a=this._cachedTooltipContent.get(e);a||(a=this._tooltipXHeadingHtml(e),i.forEach(e=>{a+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
98
102
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${e.color}; border-radius: 2px;"></span>
|
|
99
103
|
<span>${e.name}: ${e.formattedValue}</span>
|
|
100
104
|
</div>`}),this._cachedTooltipContent.set(e,a)),this._updateTooltipPosition(n,r),this._lastTooltipContent!==a&&this._showTooltipAt(n,r,a);return}}if(this._activeXValue===s){this._updateTooltipPosition(n,r);return}let c=this._getAllDatasetsAtX(s);if(c.length===0){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine();return}this._activeXValue=s,this._showPlotPointsForX(s),this._showVerticalLineAtX(s,t);let l=this._cachedTooltipContent.get(s);if(!l){if(l=this._tooltipXHeadingHtml(s),c.forEach(e=>{l+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
@@ -130,6 +134,6 @@ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{val
|
|
|
130
134
|
display: flex;
|
|
131
135
|
align-items: center;
|
|
132
136
|
height: 100%;
|
|
133
|
-
`,a.textContent=e.name,i.appendChild(a),t.appendChild(i)}),this._svg.appendChild(t),{height:this._legendHeight+50}}async addDataPoint(e,t){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets[e].data.push(t),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async batchAddDataPoints(e){if(!this._chartData)return Promise.resolve();let t=!1;for(let{datasetIndex:n,point:r}of e)this._chartData.datasets[n]&&(this._chartData.datasets[n].data.push(r),t=!0);return t&&(this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(e=>requestAnimationFrame(()=>e()))}async updateDatasetData(e,t){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets[e].data=t,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async addDataset(e){return this._chartData?(this._chartData.datasets.push(e),e.id&&this._datasetVisibility.set(e.id,e.visible!==!1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))):(console.error(`Chart data not initialized`),Promise.reject(Error(`Chart data not initialized`)))}async removeDataset(e){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets.splice(e,1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async updateDataPoint(e,t,n){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):this._chartData.datasets[e].data[t]?(this._chartData.datasets[e].data[t]=n,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))):(console.error(`Data point at index ${t} does not exist`),Promise.reject(Error(`Data point at index ${t} does not exist`)))}async batchUpdateDataPoints(e){if(!this._chartData)return Promise.resolve();let t=!1;for(let{datasetIndex:n,pointIndex:r,point:i}of e)this._chartData.datasets[n]?.data[r]&&(this._chartData.datasets[n].data[r]=i,t=!0);return t&&(this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(e=>requestAnimationFrame(()=>e()))}async removeDataPoint(e,t){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets[e].data.splice(t,1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async batchRemoveDataPoints(e){if(!this._chartData)return Promise.resolve();let t=!1;for(let{datasetIndex:n,pointIndex:r}of e)this._chartData.datasets[n]?.data[r]&&(this._chartData.datasets[n].data.splice(r,1),t=!0);return t&&(this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(e=>requestAnimationFrame(()=>e()))}async showDataset(e){return this._datasetVisibility.set(e,!0),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))}async hideDataset(e){return this._datasetVisibility.set(e,!1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))}async toggleDataset(e){let t=!(this._datasetVisibility.get(e)??!0);return this._datasetVisibility.set(e,t),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),await new Promise(e=>requestAnimationFrame(()=>e())),t}isDatasetVisible(e){return this._datasetVisibility.get(e)}async downloadAsPNG(e=`chart.png`){if(!this._svg)return console.error(`Chart SVG not found`),Promise.reject(Error(`Chart SVG not found`));let t=this._svg.cloneNode(!0),n=this._width,r=this._height;t.querySelectorAll(`text`).forEach(e=>{let t=e.getAttribute(`font-family`);(!t||t.includes(`system-ui`)||t.includes(`apple-system`))&&e.setAttribute(`font-family`,`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`)}),t.setAttribute(`width`,n.toString()),t.setAttribute(`height`,r.toString()),t.setAttribute(`xmlns`,`http://www.w3.org/2000/svg`),t.querySelectorAll(`foreignObject`).forEach(e=>{let t=e.querySelector(`div`);if(t){let n=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),r=e.getAttribute(`x`)||`0`,i=e.getAttribute(`y`)||`0`;n.setAttribute(`x`,r),n.setAttribute(`y`,(parseFloat(i)+12).toString()),n.setAttribute(`fill`,t.style.color||`#374151`),n.setAttribute(`font-size`,`12`),n.setAttribute(`font-family`,t.style.fontFamily||`system-ui, -apple-system, sans-serif`),n.textContent=t.textContent||``,e.parentNode&&e.parentNode.replaceChild(n,e)}});let i=new XMLSerializer().serializeToString(t),a=`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(i),o=new Image;return o.crossOrigin=`anonymous`,new Promise((t,i)=>{o.onload=()=>{setTimeout(()=>{let a=document.createElement(`canvas`);a.width=n+60,a.height=r+60;let s=a.getContext(`2d`);if(!s){console.error(`Could not get canvas context`),i(Error(`Could not get canvas context`));return}s.fillStyle=document.documentElement.classList.contains(`dark`)?`#111827`:`#ffffff`,s.fillRect(0,0,a.width,a.height),s.drawImage(o,30,30),a.toBlob(n=>{if(!n){console.error(`Could not create blob from canvas`),i(Error(`Could not create blob from canvas`));return}let r=URL.createObjectURL(n),a=document.createElement(`a`);a.href=r,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r),t()},`image/png`)},0)},o.onerror=()=>{console.error(`Error loading SVG image`),i(Error(`Error loading SVG image`))},o.src=a})}};customElements.get(`mint-chart`)||customElements.define(`mint-chart`,I);var L=class extends HTMLElement{constructor(...e){super(...e),this._trigger=null,this._submenuContainer=null,this._contentObserver=null,this._renderFrame=null}static get observedAttributes(){return[`label`,`icon`,`href`,`active`,`expanded`,`submenu-item`]}connectedCallback(){this.classList.add(`block`),this.render(),this._observeSubmenuMutations()}disconnectedCallback(){this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&(this.render(),e===`active`&&this._isSubmenuItem()&&this._refreshDropdownAncestor())}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeSubmenuMutations(){this._contentObserver||=new MutationObserver(e=>{e.some(e=>[...Array.from(e.addedNodes),...Array.from(e.removedNodes)].some(e=>e instanceof HTMLElement&&e.getAttribute(`slot`)===`submenu`))&&this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`],subtree:!1})}_refreshDropdownAncestor(){let e=this.parentElement;for(;e;){if(e.tagName===`MINT-SIDENAV-LINK`&&e!==this){e.render();break}e=e.parentElement}}_isActive(){return this.getAttribute(`active`)===`true`}_isExpanded(){return this.getAttribute(`expanded`)===`true`}_isSubmenuPanelVisible(){return this._isExpanded()||this._isActive()}_isSubmenuItem(){return this.getAttribute(`submenu-item`)===`true`}_getLabel(){return this.getAttribute(`label`)||``}_getIcon(){return this.getAttribute(`icon`)||``}_getHref(){return this.getAttribute(`href`)}_getBaseClasses(){let e=this._isActive()?`border-black/20 bg-black/5 text-black dark:border-white/20 dark:bg-white/10 dark:text-white`:`border-transparent text-gray-700 hover:bg-black/5 dark:text-gray-200 dark:hover:bg-white/10`;return[`w-full`,`cursor-pointer`,`rounded-lg`,`border`,`block`,this._isSubmenuItem()?`px-2 py-1.5`:`px-3 py-2`,`text-left`,`text-sm`,e].join(` `)}_hasSubmenu(){return this.querySelectorAll(`:scope > [slot="submenu"]`).length>0?!0:!!this._submenuContainer&&this._submenuContainer.children.length>0}_createRow(e,t){let n=document.createElement(`span`);if(this._isSubmenuItem(),n.className=`inline-flex w-full items-center justify-start gap-2`,t){let e=document.createElement(`mint-icon`);e.setAttribute(`name`,t),e.className=`h-4 w-4 shrink-0`,n.appendChild(e)}let r=document.createElement(`span`);return r.className=`inline truncate`,r.textContent=e,n.appendChild(r),n}_buildSimpleLink(){let e=this._getHref(),t=this._getLabel(),n=this._getIcon(),r=e?document.createElement(`a`):document.createElement(`button`);e?(r.setAttribute(`href`,e),r.setAttribute(`role`,`link`)):r.setAttribute(`type`,`button`),r.className=this._getBaseClasses(),r.setAttribute(`aria-label`,t||`Side navigation link`),r.appendChild(this._createRow(t,n)),this.replaceChildren(r),this._trigger=r}_emitAccordionExpand(){this.dispatchEvent(new CustomEvent(`mint-sidenav-accordion`,{bubbles:!0,composed:!0,detail:{source:this}}))}_setExpanded(e,t){this.setAttribute(`expanded`,String(e)),e&&t&&this._emitAccordionExpand()}_buildDropdownLink(){let e=this._getLabel(),t=this._getIcon(),n=this._getHref(),r=Array.from(this.querySelectorAll(`:scope > [slot="submenu"]`)),i=r.length>0?r:this._submenuContainer?Array.from(this._submenuContainer.children):[],a=document.createElement(`div`);a.className=`w-full`,this._submenuContainer=document.createElement(`div`),this._submenuContainer.id=`mint-sidenav-submenu-${Math.random().toString(36).slice(2,11)}`;let o=this._submenuContainer.id;if(this._submenuContainer.className=[`mint-sidenav-submenu`,`mt-1`,`ml-5`,`border-l`,`border-gray-200`,`pl-2`,`space-y-1`,`dark:border-mint-divider`,this._isSubmenuPanelVisible()?`block`:`hidden`].join(` `),i.forEach(e=>{e.setAttribute(`submenu-item`,`true`),e.setAttribute(`slot`,`submenu`),this._submenuContainer?.appendChild(e)}),n){let r=document.createElement(`div`);r.className=`flex w-full items-stretch gap-1`;let i=document.createElement(`a`);i.setAttribute(`href`,n),i.className=`${this._getBaseClasses()} hidden min-[1100px]:block`,i.setAttribute(`aria-expanded`,String(this._isSubmenuPanelVisible())),i.setAttribute(`aria-controls`,o),this._isActive()?i.setAttribute(`aria-current`,`page`):i.removeAttribute(`aria-current`),i.appendChild(this._createRow(e,t)),i.addEventListener(`click`,()=>{this._setExpanded(!0,!0)});let s=document.createElement(`a`);s.setAttribute(`href`,n),s.className=`${this._getBaseClasses()} block min-w-0 min-[1100px]:hidden`,s.style.flex=`1 1 auto`,s.setAttribute(`aria-controls`,o),s.appendChild(this._createRow(e,t)),this._isActive()?s.setAttribute(`aria-current`,`page`):s.removeAttribute(`aria-current`);let c=document.createElement(`button`);c.type=`button`,c.className=[`inline-flex`,`items-center`,`justify-center`,`rounded-lg`,`border`,`border-transparent`,`px-2`,`text-gray-600`,`hover:bg-black/5`,`dark:text-gray-300`,`dark:hover:bg-white/10`,`min-[1100px]:hidden`].join(` `),c.setAttribute(`aria-label`,`Toggle ${e} submenu`),c.setAttribute(`aria-expanded`,String(this._isSubmenuPanelVisible())),c.setAttribute(`aria-controls`,o),c.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation();let t=!this._isExpanded();this._setExpanded(t,t)});let l=document.createElement(`mint-icon`);l.setAttribute(`name`,`caret-down`),l.className=[`h-4`,`w-4`,`transition-transform`,`duration-200`,`ease-out`,this._isSubmenuPanelVisible()?`rotate-180`:`rotate-0`].join(` `),c.appendChild(l),r.appendChild(i),r.appendChild(s),r.appendChild(c),a.appendChild(r),this._trigger=i}else{let n=document.createElement(`button`);n.type=`button`,n.className=`${this._getBaseClasses()} block w-full`,n.setAttribute(`aria-expanded`,String(this._isSubmenuPanelVisible())),n.setAttribute(`aria-controls`,o),n.appendChild(this._createRow(e,t)),n.onclick=()=>{let e=!this._isExpanded();this._setExpanded(e,e)},a.appendChild(n),this._trigger=n}a.appendChild(this._submenuContainer),this.replaceChildren(a)}render(){this._hasSubmenu()&&!this._isSubmenuItem()?this._buildDropdownLink():this._buildSimpleLink()}};customElements.get(`mint-sidenav-link`)||customElements.define(`mint-sidenav-link`,L);var R=class extends HTMLElement{constructor(...e){super(...e),this._container=null,this._title=null,this._titleLabel=null,this._titleCaret=null,this._list=null,this._titleClickHandler=null,this._listenerCounts=new Map}static get observedAttributes(){return[`name`]}get onMintNameClick(){return this._onMintNameClick}set onMintNameClick(e){this._onMintNameClick=e,this.render()}addEventListener(e,t,n){super.addEventListener(e,t,n),this._trackListener(e,1)}removeEventListener(e,t,n){super.removeEventListener(e,t,n),this._trackListener(e,-1)}connectedCallback(){this.classList.add(`block`),this.render()}disconnectedCallback(){this._title&&this._titleClickHandler&&(this._title.removeEventListener(`click`,this._titleClickHandler),this._title.removeEventListener(`keydown`,this._titleClickHandler))}attributeChangedCallback(e,t,n){t!==n&&this.render()}_getName(){return this.getAttribute(`name`)||``}_trackListener(e,t){if(e!==`mint-name-click`)return;let n=this._listenerCounts.get(e)||0,r=Math.max(0,n+t);this._listenerCounts.set(e,r),this.render()}_isNameInteractive(){return(this._listenerCounts.get(`mint-name-click`)||0)>0||typeof this._onMintNameClick==`function`}_emitNameClick(e){let t=new CustomEvent(`mint-name-click`,{detail:{name:this._getName(),originalEvent:e},bubbles:!0,composed:!0});this.dispatchEvent(t),typeof this._onMintNameClick==`function`&&this._onMintNameClick(t)}render(){this._container||(this._container=document.createElement(`section`),this._container.className=`mb-4`,this.appendChild(this._container)),this._title||(this._title=document.createElement(`button`),this._title.setAttribute(`type`,`button`),this._title.className=`mb-2 w-full`,this._titleLabel=document.createElement(`mint-text`),this._titleLabel.setAttribute(`size`,`small`),this._titleLabel.setAttribute(`bold`,`true`),this._titleCaret=document.createElement(`mint-icon`),this._titleCaret.setAttribute(`name`,`caret-right`),this._titleCaret.className=`ml-auto inline-flex h-4 w-4 shrink-0 text-gray-500 dark:text-gray-400`,this._title.appendChild(this._titleLabel),this._title.appendChild(this._titleCaret),this._titleClickHandler=e=>{this._isNameInteractive()&&(e instanceof KeyboardEvent&&e.key!==`Enter`&&e.key!==` `||(e instanceof KeyboardEvent&&e.key===` `&&e.preventDefault(),this._emitNameClick(e)))},this._title.addEventListener(`click`,this._titleClickHandler),this._title.addEventListener(`keydown`,this._titleClickHandler),this._container.appendChild(this._title));let e=this._getName(),t=e.trim().length>0,n=this._isNameInteractive();this._titleLabel&&(this._titleLabel.textContent=e,this._titleLabel.className=`uppercase tracking-wide text-gray-500 dark:text-gray-400`),this._title&&(this._title.className=n?[`mb-2`,`w-full`,`inline-flex`,`items-center`,`gap-2`,`rounded-lg`,`border`,`border-transparent`,`px-3`,`py-2`,`text-left`,`hover:bg-black/5`,`dark:hover:bg-white/10`,`cursor-pointer`,`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-black/20`,`dark:focus-visible:ring-white/20`].join(` `):`mb-2 w-full inline-flex items-center gap-2 rounded-lg border border-transparent px-3 py-2 text-left cursor-default`,this._title.tabIndex=n?0:-1,this._title.disabled=!n,this._title.setAttribute(`aria-disabled`,String(!n))),this._titleCaret&&(this._titleCaret.style.display=n?``:`none`,this._titleCaret.setAttribute(`aria-hidden`,String(!n))),t?this._title.parentElement!==this._container&&this._container?.insertBefore(this._title,this._list):this._title.parentElement===this._container&&this._container?.removeChild(this._title),this._list||(this._list=document.createElement(`div`),this._list.className=`space-y-1`,this._container.appendChild(this._list)),Array.from(this.children).filter(e=>e!==this._container&&e.tagName===`MINT-SIDENAV-LINK`).forEach(e=>{this._list&&e.parentElement!==this._list&&this._list.appendChild(e)})}};customElements.get(`mint-sidenav-links`)||customElements.define(`mint-sidenav-links`,R);var z=class extends HTMLElement{static get observedAttributes(){return[`separated`]}connectedCallback(){this.render()}attributeChangedCallback(e,t,n){t!==n&&this.render()}_isSeparated(){return this.getAttribute(`separated`)===`true`}render(){this.className=this._isSeparated()?`block w-full mt-2 border-t border-gray-200 pt-2 px-2 pb-2 dark:border-mint-divider`:`block w-full p-2`}};customElements.get(`mint-sidenav-action-links`)||customElements.define(`mint-sidenav-action-links`,z);var B=class extends HTMLElement{constructor(...e){super(...e),this._wrapper=null,this._trigger=null,this._popover=null,this._triggerId=``,this._contentObserver=null,this._renderFrame=null}static get observedAttributes(){return[`title`,`subtitle`]}connectedCallback(){this.classList.add(`block`),this._triggerId=this.id?`${this.id}-trigger`:`mint-sidenav-action-menu-${Math.random().toString(36).slice(2,9)}`,this.render(),this._observeContentMutations()}disconnectedCallback(){this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_getTitle(){return this.getAttribute(`title`)||``}_getSubtitle(){return this.getAttribute(`subtitle`)||``}_createDefaultGroup(){let e=document.createElement(`mint-sidenav-action-links`),t=document.createElement(`div`);return t.appendChild(e),t}render(){let e=Array.from(this.children).filter(e=>e!==this._wrapper&&e.getAttribute(`slot`)===`action-links`);this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`relative`,this.appendChild(this._wrapper)),this._wrapper.innerHTML=``,this._trigger=document.createElement(`button`),this._trigger.type=`button`,this._trigger.id=this._triggerId,this._trigger.className=`flex w-full cursor-pointer items-center gap-3 rounded-xl border border-gray-200 bg-gray-50 px-3 py-2 text-left hover:bg-gray-100 dark:border-mint-divider dark:bg-white/5 dark:hover:bg-white/10`;let t=document.createElement(`div`);t.className=`inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-gray-700 text-xs font-semibold text-white dark:bg-mint-nav`,t.textContent=this._getTitle().split(` `).map(e=>e[0]).join(``).slice(0,2).toUpperCase();let n=document.createElement(`div`);n.className=`min-w-0 flex-1`;let r=document.createElement(`mint-text`);r.setAttribute(`size`,`body`),r.setAttribute(`bold`,`true`),r.className=`truncate text-gray-900 dark:text-gray-100`,r.textContent=this._getTitle();let i=document.createElement(`mint-text`);i.setAttribute(`size`,`small`),i.setAttribute(`variant`,`muted`),i.className=`truncate`,i.textContent=this._getSubtitle(),n.appendChild(r),n.appendChild(i),this._trigger.appendChild(t),this._trigger.appendChild(n),this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`trigger-id`,this._triggerId),this._popover.setAttribute(`direction`,`right`),this._popover.setAttribute(`padding`,`0`);let a=document.createElement(`div`);a.className=`w-64`,e.length>0?e.forEach(e=>{e.setAttribute(`hidden`,`true`);let t=e.cloneNode(!0);t.removeAttribute(`hidden`),t.removeAttribute(`slot`),a.appendChild(t)}):a.appendChild(this._createDefaultGroup()),this._popover.appendChild(a),this._wrapper.appendChild(this._trigger),this._wrapper.appendChild(this._popover)}};customElements.get(`mint-sidenav-action-menu`)||customElements.define(`mint-sidenav-action-menu`,B);var V=`mint:url-change`;function se(){if(window.__mintUrlChangePatched)return;window.__mintUrlChangePatched=!0;let e=()=>{window.dispatchEvent(new Event(V))},t=t=>{let n=history[t].bind(history);history[t]=((...t)=>{let r=n(...t);return e(),r})};t(`pushState`),t(`replaceState`)}var H=class extends HTMLElement{constructor(...e){super(...e),this._backdrop=null,this._container=null,this._header=null,this._content=null,this._footer=null,this._escapeHandler=null,this._mediaQuery=null,this._mediaListener=null,this._accordionHandler=null,this._urlChangeHandler=null,this._contentObserver=null,this._renderFrame=null,this._onMobileNavNavigateClick=e=>{if(this._mediaQuery?.matches)return;let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`a[href]`);if(!(n instanceof HTMLAnchorElement)||!this._container?.contains(n))return;let r=n.getAttribute(`href`);!r||r===`#`||r.trim().toLowerCase().startsWith(`javascript:`)||this._isOpen()&&this.removeAttribute(`open`)}}static get observedAttributes(){return[`user-name`,`user-status`,`open`,`drawer-top-class`]}connectedCallback(){this.classList.add(`relative`,`block`,`shrink-0`,`w-0`,`overflow-visible`,`min-[1100px]:w-[17rem]`,`min-[1100px]:shrink-0`),this._attachEscapeListener(),this._attachMediaListener(),this._attachAccordionListener(),this._attachUrlChangeListener(),this._observeContentMutations(),this.render()}disconnectedCallback(){this._detachEscapeListener(),this._detachMediaListener(),this._detachAccordionListener(),this._detachUrlChangeListener(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_attachEscapeListener(){this._escapeHandler||(this._escapeHandler=e=>{e.key===`Escape`&&this.getAttribute(`open`)===`true`&&this.removeAttribute(`open`)},document.addEventListener(`keydown`,this._escapeHandler))}_detachEscapeListener(){this._escapeHandler&&=(document.removeEventListener(`keydown`,this._escapeHandler),null)}_attachMediaListener(){this._mediaListener||(this._mediaQuery=window.matchMedia(`(min-width: 1100px)`),this._mediaListener=()=>{this._mediaQuery?.matches&&this.removeAttribute(`open`)},this._mediaQuery.addEventListener(`change`,this._mediaListener))}_detachMediaListener(){this._mediaQuery&&this._mediaListener&&this._mediaQuery.removeEventListener(`change`,this._mediaListener),this._mediaQuery=null,this._mediaListener=null}_attachAccordionListener(){this._accordionHandler||(this._accordionHandler=e=>{let t=e.detail?.source;!(t instanceof HTMLElement)||t.tagName!==`MINT-SIDENAV-LINK`||this.contains(t)&&this.querySelectorAll(`mint-sidenav-link`).forEach(e=>{e!==t&&e.querySelector(`:scope .mint-sidenav-submenu`)&&e.setAttribute(`expanded`,`false`)})},this.addEventListener(`mint-sidenav-accordion`,this._accordionHandler))}_detachAccordionListener(){this._accordionHandler&&=(this.removeEventListener(`mint-sidenav-accordion`,this._accordionHandler),null)}_attachUrlChangeListener(){this._urlChangeHandler||(se(),this._urlChangeHandler=()=>{this._mediaQuery?.matches||this._isOpen()&&this.removeAttribute(`open`)},window.addEventListener(`popstate`,this._urlChangeHandler),window.addEventListener(`hashchange`,this._urlChangeHandler),window.addEventListener(V,this._urlChangeHandler))}_detachUrlChangeListener(){this._urlChangeHandler&&=(window.removeEventListener(`popstate`,this._urlChangeHandler),window.removeEventListener(`hashchange`,this._urlChangeHandler),window.removeEventListener(V,this._urlChangeHandler),null)}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}getUserName(){return this.getAttribute(`user-name`)||`Acme Inc`}getUserStatus(){return this.getAttribute(`user-status`)||`Enterprise`}_isOpen(){return this.getAttribute(`open`)===`true`}_ensureBackdrop(){this._backdrop||(this._backdrop=document.createElement(`div`),this._backdrop.setAttribute(`aria-hidden`,`true`),this._backdrop.addEventListener(`click`,()=>this.removeAttribute(`open`)),this.insertBefore(this._backdrop,this.firstChild))}_ensureContainer(){this._container||(this._container=document.createElement(`aside`),this._container.addEventListener(`click`,this._onMobileNavNavigateClick,!0),this.appendChild(this._container))}_syncShell(){let e=`max-[1099.98px]:top-14`,t=this._isOpen();if(this._backdrop&&(this._backdrop.className=[`fixed`,e,`left-0`,`right-0`,`bottom-0`,`z-40`,`bg-black/50`,`transition-opacity`,`duration-200`,`min-[1100px]:hidden`,t?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0`].join(` `)),this._container){let n=t?`max-[1099.98px]:translate-x-0`:`max-[1099.98px]:-translate-x-full`;this._container.className=[`flex`,`min-h-0`,`flex-col`,`border-r`,`border-gray-200`,`bg-white`,`p-2`,`dark:border-mint-divider`,`dark:bg-mint-nav`,`w-[4.75rem]`,`max-[1099.98px]:fixed`,e,`max-[1099.98px]:bottom-0`,`max-[1099.98px]:left-0`,`max-[1099.98px]:z-50`,`max-[1099.98px]:h-auto`,`max-[1099.98px]:w-[17rem]`,`max-[1099.98px]:max-w-[85vw]`,`max-[1099.98px]:shadow-xl`,`max-[1099.98px]:transition-transform`,`max-[1099.98px]:duration-200`,`max-[1099.98px]:ease-out`,n,`min-[1100px]:fixed`,`min-[1100px]:left-0`,`min-[1100px]:top-14`,`min-[1100px]:bottom-0`,`min-[1100px]:z-[60]`,`min-[1100px]:w-[17rem]`,`min-[1100px]:p-3`,`min-[1100px]:shadow-none`].join(` `)}}_buildUserHeader(){if(!this._container)return;this._header||(this._header=document.createElement(`div`),this._header.className=`mb-4`,this._container.appendChild(this._header));let e=Array.from(this.querySelectorAll(`[slot="action-header"]`)).find(e=>e!==this._backdrop&&e!==this._container);if(e){this._header.replaceChildren(e);return}let t=document.createElement(`mint-sidenav-action-menu`);t.setAttribute(`title`,this.getUserName()),t.setAttribute(`subtitle`,this.getUserStatus()),this._header.replaceChildren(t)}_replaceSlottedChildren(e,t){let n=Array.from(this.querySelectorAll(`[slot="${t}"]`)).filter(e=>e!==this._container&&e!==this._backdrop);e.replaceChildren(...n)}_buildContent(){this._container&&(this._content||(this._content=document.createElement(`div`),this._content.className=`min-h-0 grow overflow-y-auto`,this._container.appendChild(this._content)),this._replaceSlottedChildren(this._content,`links`))}_buildFooter(){if(!this._container)return;this._footer||(this._footer=document.createElement(`div`),this._footer.className=`mt-auto border-t border-gray-200 py-3 dark:border-mint-divider`,this._container.appendChild(this._footer));let e=document.createElement(`div`);e.className=`space-y-1`,this._replaceSlottedChildren(e,`bottom-links`),this._footer.innerHTML=``,this._footer.appendChild(e)}render(){this._ensureBackdrop(),this._ensureContainer(),this._syncShell(),this._buildUserHeader(),this._buildContent(),this._buildFooter()}};customElements.get(`mint-side-navigation`)||customElements.define(`mint-side-navigation`,H);var U=class extends HTMLElement{constructor(...e){super(...e),this._bar=null,this._menuButton=null,this._logoLink=null,this._menuClickHandler=null,this._darkModeObserver=null,this._contentObserver=null,this._resizeHandler=null,this._desktopSearchInput=null,this._desktopSearchShell=null,this._mobileSearchButton=null,this._searchPanel=null,this._searchPanelInput=null,this._searchResultsWrap=null,this._searchStateWrap=null,this._searchDebounceId=null,this._searchAbortController=null,this._searchOpen=!1,this._searchQuery=``,this._globalKeydownHandler=null,this._docClickHandler=null,this._renderFrame=null}static get observedAttributes(){return[`logo-src`,`logo-src-light`,`logo-src-dark`,`logo-src-mobile`,`logo-src-mobile-light`,`logo-src-mobile-dark`,`logo-href`,`logo-alt`,`menu-target`,`search-endpoint`,`search-param`,`search-placeholder`]}connectedCallback(){this.classList.add(`relative`,`block`,`h-14`,`w-full`,`shrink-0`),this._observeDarkMode(),this._observeContentMutations(),this._attachResizeListener(),this._attachGlobalHandlers(),this.render()}disconnectedCallback(){this._menuButton&&this._menuClickHandler&&(this._menuButton.removeEventListener(`click`,this._menuClickHandler),this._menuClickHandler=null),this._disconnectDarkModeObserver(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null),this._detachResizeListener(),this._detachGlobalHandlers(),this._cancelSearchDebounce(),this._abortSearch()}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_isDarkMode(){return document.documentElement.classList.contains(`dark`)}_isMobileViewport(){return window.matchMedia(`(max-width: 1099.98px)`).matches}_getLogoSrc(){let e=this.getAttribute(`logo-src`)||``,t=this.getAttribute(`logo-src-light`)||``,n=this.getAttribute(`logo-src-dark`)||``,r=this.getAttribute(`logo-src-mobile`)||``,i=this.getAttribute(`logo-src-mobile-light`)||``,a=this.getAttribute(`logo-src-mobile-dark`)||``,o=this._isDarkMode(),s=this._isMobileViewport();return s&&o?a||r||n||t||e:s&&!o?i||r||t||n||e:o?n||t||e:t||n||e}_getLogoHref(){return this.getAttribute(`logo-href`)||`/`}_getLogoAlt(){return this.getAttribute(`logo-alt`)||`Home`}_getMenuTargetId(){return(this.getAttribute(`menu-target`)||``).replace(/^#/,``)}_getSearchEndpoint(){return(this.getAttribute(`search-endpoint`)||``).trim()}_getSearchParam(){return(this.getAttribute(`search-param`)||`q`).trim()||`q`}_getSearchPlaceholder(){return this.getAttribute(`search-placeholder`)||`Search`}_isSearchEnabled(){return!!this._getSearchEndpoint()}_attachGlobalHandlers(){this._globalKeydownHandler||(this._globalKeydownHandler=e=>{let t=e.key.toLowerCase();if((e.metaKey||e.ctrlKey)&&t===`k`){e.preventDefault(),this._openSearch(!0);return}t===`escape`&&this._searchOpen&&this._closeSearch()},document.addEventListener(`keydown`,this._globalKeydownHandler)),this._docClickHandler||(this._docClickHandler=e=>{if(!this._searchOpen)return;let t=e.target;t&&(this.contains(t)||this._closeSearch())},document.addEventListener(`click`,this._docClickHandler))}_detachGlobalHandlers(){this._globalKeydownHandler&&=(document.removeEventListener(`keydown`,this._globalKeydownHandler),null),this._docClickHandler&&=(document.removeEventListener(`click`,this._docClickHandler),null)}_cancelSearchDebounce(){this._searchDebounceId!==null&&(window.clearTimeout(this._searchDebounceId),this._searchDebounceId=null)}_abortSearch(){this._searchAbortController&&=(this._searchAbortController.abort(),null)}_openSearch(e=!1){if(this._isSearchEnabled()&&(this._searchOpen=!0,this._syncSearchPanelVisibility(),e)){let e=this._isMobileViewport()?this._searchPanelInput:this._desktopSearchInput;e?.focus(),e?.select()}}_closeSearch(){this._searchOpen=!1,this._syncSearchPanelVisibility()}_syncSearchPanelVisibility(){this._searchPanel&&(this._searchPanel.classList.toggle(`hidden`,!this._searchOpen),this._syncDesktopSearchOpenState(),this._positionSearchPanel())}_syncDesktopSearchOpenState(){this._desktopSearchShell&&(this._desktopSearchShell.classList.toggle(`rounded-b-none`,this._searchOpen),this._desktopSearchShell.classList.toggle(`border-b-transparent`,this._searchOpen))}_positionSearchPanel(){if(!this._searchPanel)return;if(this._isMobileViewport()||!this._desktopSearchShell){this._searchPanel.style.left=``,this._searchPanel.style.right=``,this._searchPanel.style.top=``,this._searchPanel.style.width=``,this._searchPanel.style.maxWidth=``,this._searchPanel.style.transform=``;return}let e=this._desktopSearchShell.getBoundingClientRect();this._searchPanel.style.left=`${e.left}px`,this._searchPanel.style.right=`auto`,this._searchPanel.style.top=`${e.bottom-1}px`,this._searchPanel.style.width=`${e.width}px`,this._searchPanel.style.maxWidth=`${e.width}px`,this._searchPanel.style.transform=`none`}_setSearchQuery(e){this._searchQuery=e,this._desktopSearchInput&&this._desktopSearchInput.value!==e&&(this._desktopSearchInput.value=e),this._searchPanelInput&&this._searchPanelInput.value!==e&&(this._searchPanelInput.value=e)}_normalizeResults(e){return(e=>{if(Array.isArray(e))return e;if(!e||typeof e!=`object`)return[];let t=e;for(let e of[`results`,`items`,`data`,`products`]){let n=t[e];if(Array.isArray(n))return n}return[]})(e).map(e=>{let t=e||{};return{title:String(t.title||t.name||t.label||t.email||t.id||``).trim()||`Untitled`,subtitle:String(t.description||t.category||t.username||``).trim()}}).slice(0,8)}_renderSearchState(e){this._searchStateWrap&&(this._searchStateWrap.textContent=e,this._searchStateWrap.classList.remove(`hidden`),this._searchResultsWrap&&(this._searchResultsWrap.innerHTML=``))}_renderSearchResults(e){if(!(!this._searchResultsWrap||!this._searchStateWrap)){if(this._searchResultsWrap.innerHTML=``,e.length===0){this._renderSearchState(`No results found`);return}this._searchStateWrap.classList.add(`hidden`);for(let t of e){let e=document.createElement(`button`);e.type=`button`,e.className=`flex w-full cursor-pointer items-start gap-3 rounded-lg px-3 py-2 text-left hover:bg-gray-100 dark:hover:bg-white/10`;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`mt-0.5 h-4 w-4 text-gray-500 dark:text-gray-400`;let r=document.createElement(`div`);r.className=`min-w-0`;let i=document.createElement(`div`);if(i.className=`truncate text-sm font-semibold text-gray-900 dark:text-gray-100`,i.textContent=t.title,r.appendChild(i),t.subtitle){let e=document.createElement(`div`);e.className=`truncate text-xs text-gray-500 dark:text-gray-400`,e.textContent=t.subtitle,r.appendChild(e)}e.appendChild(n),e.appendChild(r),e.addEventListener(`click`,()=>{this.dispatchEvent(new CustomEvent(`search-select`,{detail:{query:this._searchQuery,result:t},bubbles:!0,composed:!0})),this._closeSearch()}),this._searchResultsWrap.appendChild(e)}}}_fetchSearchResults(e){let t=this._getSearchEndpoint();if(!t)return;let n=e.trim();if(!n){this._renderSearchState(`Start typing to search`);return}this._abortSearch(),this._searchAbortController=new AbortController,this._renderSearchState(`Searching...`);let r=t.includes(`{query}`)?t.replace(`{query}`,encodeURIComponent(n)):`${t}${t.includes(`?`)?`&`:`?`}${encodeURIComponent(this._getSearchParam())}=${encodeURIComponent(n)}`;fetch(r,{signal:this._searchAbortController.signal}).then(e=>{if(!e.ok)throw Error(`Request failed: ${e.status}`);return e.json()}).then(e=>{let t=this._normalizeResults(e);this._renderSearchResults(t)}).catch(e=>{e?.name!==`AbortError`&&this._renderSearchState(`Unable to load results`)})}_scheduleSearch(e){this._setSearchQuery(e),this._cancelSearchDebounce(),this._searchDebounceId=window.setTimeout(()=>this._fetchSearchResults(e),220)}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>this.render()),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}))}_disconnectDarkModeObserver(){this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null)}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_attachResizeListener(){this._resizeHandler||(this._resizeHandler=()=>{this.render(),this._positionSearchPanel()},window.addEventListener(`resize`,this._resizeHandler,{passive:!0}))}_detachResizeListener(){this._resizeHandler&&=(window.removeEventListener(`resize`,this._resizeHandler),null)}_toggleMenuTarget(){let e=this._getMenuTargetId();if(!e)return;let t=document.getElementById(e);!t||t.tagName!==`MINT-SIDE-NAVIGATION`||(t.getAttribute(`open`)===`true`?t.removeAttribute(`open`):t.setAttribute(`open`,`true`))}render(){if(this._bar||(this._bar=document.createElement(`div`),this._bar.className=`fixed inset-x-0 top-0 z-50 flex h-14 w-full items-center gap-2 border-b border-gray-200 bg-white px-3 dark:border-mint-divider dark:bg-mint-nav`,this.appendChild(this._bar)),!this._menuButton){this._menuButton=document.createElement(`button`),this._menuButton.type=`button`,this._menuButton.className=`inline-flex h-10 w-10 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-transparent text-gray-700 hover:bg-black/5 min-[1100px]:hidden dark:text-gray-200 dark:hover:bg-white/10`,this._menuButton.setAttribute(`aria-label`,`Open navigation menu`);let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`menu`),e.className=`h-5 w-5`,this._menuButton.appendChild(e),this._menuClickHandler=()=>this._toggleMenuTarget(),this._menuButton.addEventListener(`click`,this._menuClickHandler),this._bar.appendChild(this._menuButton)}let e=!!this._getMenuTargetId();this._menuButton.classList.toggle(`hidden`,!e),this._logoLink||(this._logoLink=document.createElement(`a`),this._logoLink.className=`flex h-8 w-40 shrink-0 items-center`,this._bar.appendChild(this._logoLink)),this._logoLink.href=this._getLogoHref(),this._logoLink.setAttribute(`aria-label`,this._getLogoAlt());let t=this._getLogoSrc();if(t){let e=document.createElement(`img`);e.className=`h-full w-full object-contain [aspect-ratio:5/1]`,e.decoding=`async`,e.src=t,e.alt=this._getLogoAlt(),this._logoLink.replaceChildren(e),this._logoLink.classList.remove(`pointer-events-none`,`opacity-40`)}else{this._logoLink.replaceChildren(),this._logoLink.classList.add(`pointer-events-none`,`opacity-40`);let e=document.createElement(`span`);e.className=`text-sm font-semibold text-gray-400 dark:text-gray-500`,e.textContent=`Logo`,this._logoLink.appendChild(e)}let n=Array.from(this.querySelectorAll(`[slot="center"]`)),r=n.length>0,i=this._isSearchEnabled()&&!r,a=this._bar.querySelector(`[data-mint-topnav-center]`);if(a||(a=document.createElement(`div`),a.setAttribute(`data-mint-topnav-center`,`true`),this._bar.appendChild(a)),a.className=r?`min-w-0 flex-1 px-2 min-[1100px]:flex min-[1100px]:justify-center min-[1100px]:px-4`:`max-[1099.98px]:hidden min-[1100px]:flex min-[1100px]:min-w-0 min-[1100px]:flex-1 min-[1100px]:justify-center min-[1100px]:px-4`,a.classList.toggle(`min-[1100px]:hidden`,!i&&!r),r&&(a.replaceChildren(...n),this._closeSearch()),i&&!this._desktopSearchInput){let e=document.createElement(`div`);e.className=`relative w-full max-w-xl rounded-xl border border-gray-300 bg-gray-50 px-3 py-2 dark:border-mint-divider dark:bg-mint-hover`,this._desktopSearchShell=e;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`search`),t.className=`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500 dark:text-gray-400`,this._desktopSearchInput=document.createElement(`input`),this._desktopSearchInput.type=`search`,this._desktopSearchInput.className=`w-full bg-transparent pl-6 pr-20 text-sm text-gray-900 outline-none placeholder:text-gray-500 dark:text-gray-100 dark:placeholder:text-gray-400`,this._desktopSearchInput.placeholder=this._getSearchPlaceholder(),this._desktopSearchInput.addEventListener(`focus`,()=>this._openSearch(!1)),this._desktopSearchInput.addEventListener(`input`,e=>this._scheduleSearch(e.target.value));let n=document.createElement(`span`);n.className=`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-gray-500 dark:text-gray-400`,n.textContent=`⌘K`,e.appendChild(t),e.appendChild(this._desktopSearchInput),e.appendChild(n),a.appendChild(e)}i&&this._desktopSearchInput&&(this._desktopSearchInput.placeholder=this._getSearchPlaceholder(),this._desktopSearchShell=this._desktopSearchInput.closest(`div`),this._syncDesktopSearchOpenState());let o=this._bar.querySelector(`[data-mint-topnav-mobile-spacer]`);o||(o=document.createElement(`div`),o.setAttribute(`data-mint-topnav-mobile-spacer`,`true`),o.className=`min-w-0 flex-1 min-[1100px]:hidden`,this._bar.appendChild(o));let s=Array.from(this.querySelectorAll(`[slot="actions"]`)),c=this._bar.querySelector(`[data-mint-topnav-actions]`);if(c||(c=document.createElement(`div`),c.setAttribute(`data-mint-topnav-actions`,`true`),c.className=`flex shrink-0 items-center gap-2`,this._bar.appendChild(c)),i&&!this._mobileSearchButton){this._mobileSearchButton=document.createElement(`button`),this._mobileSearchButton.type=`button`,this._mobileSearchButton.className=`inline-flex h-10 w-10 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-transparent text-gray-700 hover:bg-black/5 min-[1100px]:hidden dark:text-gray-200 dark:hover:bg-white/10`,this._mobileSearchButton.setAttribute(`aria-label`,`Open search`);let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`search`),e.className=`h-5 w-5`,this._mobileSearchButton.appendChild(e),this._mobileSearchButton.addEventListener(`click`,()=>this._openSearch(!0)),c.insertBefore(this._mobileSearchButton,c.firstChild)}if(this._mobileSearchButton&&this._mobileSearchButton.classList.toggle(`hidden`,!i),c.replaceChildren(...s),i&&this._mobileSearchButton&&!s.includes(this._mobileSearchButton)&&c.insertBefore(this._mobileSearchButton,c.firstChild),i&&!this._searchPanel){this._searchPanel=document.createElement(`div`),this._searchPanel.className=`fixed left-0 right-0 top-14 z-[90] hidden p-3 min-[1100px]:p-0`;let e=document.createElement(`div`);e.className=`mx-auto w-full rounded-2xl border border-gray-200 bg-white shadow-xl dark:border-mint-divider dark:bg-mint-elevated min-[1100px]:rounded-t-none`;let t=document.createElement(`div`);t.className=`relative border-b border-gray-200 p-3 dark:border-mint-divider min-[1100px]:hidden`;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`absolute left-6 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500 dark:text-gray-400`,this._searchPanelInput=document.createElement(`input`),this._searchPanelInput.type=`search`,this._searchPanelInput.className=`w-full rounded-lg border border-gray-300 bg-gray-50 py-2 pl-10 pr-3 text-sm text-gray-900 outline-none dark:border-mint-divider dark:bg-mint-hover dark:text-gray-100`,this._searchPanelInput.placeholder=this._getSearchPlaceholder(),this._searchPanelInput.addEventListener(`input`,e=>this._scheduleSearch(e.target.value)),t.appendChild(n),t.appendChild(this._searchPanelInput);let r=document.createElement(`div`);r.className=`flex flex-wrap gap-2 px-3 py-3`,[`Apps`,`Customers`,`Orders`,`Products`,`Sales channels`].forEach(e=>{let t=document.createElement(`span`);t.className=`rounded-full bg-gray-100 px-3 py-1 text-xs font-semibold text-gray-600 dark:bg-mint-hover dark:text-gray-300`,t.textContent=e,r.appendChild(t)}),this._searchStateWrap=document.createElement(`div`),this._searchStateWrap.className=`px-4 pb-4 text-sm text-gray-500 dark:text-gray-400`,this._searchStateWrap.textContent=`Start typing to search`,this._searchResultsWrap=document.createElement(`div`),this._searchResultsWrap.className=`max-h-[52vh] overflow-y-auto px-2 pb-2`,e.appendChild(t),e.appendChild(r),e.appendChild(this._searchStateWrap),e.appendChild(this._searchResultsWrap),this._searchPanel.appendChild(e),this.appendChild(this._searchPanel)}this._searchPanelInput&&(this._searchPanelInput.placeholder=this._getSearchPlaceholder()),this._syncSearchPanelVisibility(),this._positionSearchPanel()}};customElements.get(`mint-top-navigation`)||customElements.define(`mint-top-navigation`,U);var W=class e extends HTMLElement{constructor(...e){super(...e),this._shell=null,this._desktopInput=null,this._panel=null,this._panelInner=null,this._panelInput=null,this._panelFiltersWrap=null,this._panelFiltersMainRow=null,this._panelFiltersChips=null,this._panelFiltersShowAllWrap=null,this._panelFiltersShowAllBtn=null,this._panelFiltersMorePanel=null,this._filtersMoreOpen=!1,this._filterOverflowObserver=null,this._filterOverflowZeroWidthRetries=0,this._desktopFilterWrap=null,this._mobileFilterWrap=null,this._resultsWrap=null,this._stateWrap=null,this._customResultsWrap=null,this._query=``,this._searchOpen=!1,this._selectedFilters=[],this._selectedFilterBackspaceArmed=!1,this._debounceId=null,this._abortController=null,this._docPointerDownHandler=null,this._globalKeydownHandler=null,this._focusOutHandler=null,this._resizeHandler=null,this._desktopShortcutHint=null,this._panelSearchBar=null,this._contentObserver=null,this._renderFrame=null}static{this._filterMorePanelSeq=0}static{this._filterChipsOverflowMask=`linear-gradient(to right, #000 0%, #000 max(0%, calc(100% - 3.5rem)), transparent 100%)`}static get observedAttributes(){return[`endpoint`,`search-param`,`placeholder`,`filters`,`filter-param`,`open-shortcut`,`open-shortcut-hint`,`collapse-on-mobile`]}connectedCallback(){this.classList.add(`relative`,`block`,`w-full`,`max-w-xl`),this._attachGlobalHandlers(),this._attachFocusOutHandler(),this._attachResizeHandler(),this.render(),this._observeContentMutations()}disconnectedCallback(){this._docPointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._docPointerDownHandler,!0),null),this._globalKeydownHandler&&=(document.removeEventListener(`keydown`,this._globalKeydownHandler),null),this._resizeHandler&&=(window.removeEventListener(`resize`,this._resizeHandler),null),this._focusOutHandler&&=(this.removeEventListener(`focusout`,this._focusOutHandler,!0),null),this._cancelDebounce(),this._abortSearch(),this._filterOverflowObserver&&=(this._filterOverflowObserver.disconnect(),null),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_getEndpoint(){return(this.getAttribute(`endpoint`)||``).trim()}_getSearchParam(){return(this.getAttribute(`search-param`)||`q`).trim()||`q`}_getPlaceholder(){return this.getAttribute(`placeholder`)||`Search`}_getFilterParam(){return(this.getAttribute(`filter-param`)||``).trim()}_getFilterOptions(){return(this.getAttribute(`filters`)||``).split(`,`).map(e=>e.trim()).filter(Boolean)}_hasSelectedFilters(){return this._selectedFilters.length>0}_getFilterChipOverflowReservePx(){let e=Math.max(1,this._getFilterOptions().length),t=this._hasSelectedFilters()?28:56;return Math.min(200,t+e*34)}_getFilterParamValue(){return this._selectedFilters.join(`,`)}_getFilterChipLabelText(){return this._selectedFilters.join(`, `)}_getCondensedFilterChipLabel(e=22){if(!this._hasSelectedFilters())return``;let[t=``]=this._selectedFilters,n=this._selectedFilters.length-1,r=Math.max(8,e-2),i=t;if(n<=0)return i.length<=r?i:`${i.slice(0,Math.max(1,r-3))}...`;let a=`${t}, and ${n} more`;return a.length<=r?a:`${a.slice(0,Math.max(1,r-3))}...`}_isMobileViewport(){return window.matchMedia(`(max-width: 1099.98px)`).matches}_collapseOnMobile(){let e=this.getAttribute(`collapse-on-mobile`);if(e===null)return!1;let t=e.trim().toLowerCase();return!(t===`false`||t===`0`||t===`off`||t===`none`)}_primarySearchInput(){return this._isMobileViewport()&&this._collapseOnMobile()?this._panelInput:this._desktopInput}_isApplePlatform(){return typeof navigator>`u`?!1:/Mac|iPhone|iPad|iPod/i.test(navigator.platform)||/Mac OS/i.test(navigator.userAgent)}_parseOpenShortcut(){let e=(this.getAttribute(`open-shortcut`)??`mod+k`).trim().toLowerCase();if(!e||e===`none`||e===`false`||e===`off`)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let t=e.split(`+`).map(e=>e.trim()).filter(Boolean);if(t.length===0)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let n=t[t.length-1],r=new Set(t.slice(0,-1).map(e=>e.toLowerCase()));return{disabled:!1,wantMod:r.has(`mod`),wantMeta:r.has(`meta`)||r.has(`cmd`)||r.has(`super`),wantCtrl:r.has(`ctrl`)||r.has(`control`),wantAlt:r.has(`alt`),wantShift:r.has(`shift`),key:n.toLowerCase()}}_eventKeyMatchesShortcutKey(e,t){let n=t.toLowerCase();return(e.key.length,e.key.toLowerCase())===n}_openShortcutMatches(e){let t=this._parseOpenShortcut();return t.disabled||!t.key||e.repeat||!this._eventKeyMatchesShortcutKey(e,t.key)||t.wantShift!==e.shiftKey||t.wantAlt!==e.altKey?!1:t.wantMod||t.wantMeta||t.wantCtrl?!(t.wantMod&&!(e.metaKey||e.ctrlKey)||t.wantMeta&&!e.metaKey||t.wantCtrl&&!e.ctrlKey):!!t.wantAlt}_getOpenShortcutHintText(){let e=this.getAttribute(`open-shortcut-hint`);if(e===`none`||e===`false`)return``;if(e!==null&&e.trim()!==``)return e.trim();let t=this._parseOpenShortcut();if(t.disabled)return``;let n=this._isApplePlatform(),r=[];t.wantMod&&r.push(n?`⌘`:`Ctrl`),t.wantMeta&&!t.wantMod&&r.push(n?`⌘`:`Meta`),t.wantCtrl&&!t.wantMod&&r.push(`Ctrl`),t.wantAlt&&r.push(`Alt`),t.wantShift&&r.push(`Shift`);let i=t.key.length===1?t.key.toUpperCase():t.key;return i?t.wantMod&&!t.wantMeta&&!t.wantCtrl&&!t.wantAlt&&!t.wantShift&&t.key.length===1?`${n?`⌘`:`Ctrl+`}${i}`:[...r,i].join(`+`):``}_attachGlobalHandlers(){this._globalKeydownHandler||(this._globalKeydownHandler=e=>{if(this._openShortcutMatches(e)){e.preventDefault(),this._openSearch(!0);return}if(e.key.toLowerCase()===`escape`&&this._searchOpen){if(this._filtersMoreOpen){this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput());return}this._closeSearch()}},document.addEventListener(`keydown`,this._globalKeydownHandler)),this._docPointerDownHandler||(this._docPointerDownHandler=e=>{if(!this._searchOpen)return;let t=e.composedPath();this._filtersMoreOpen&&this._panelFiltersWrap&&!t.includes(this._panelFiltersWrap)&&(this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput())),!(this._shell&&t.includes(this._shell)||this._panelInner&&t.includes(this._panelInner))&&this._closeSearch()},document.addEventListener(`pointerdown`,this._docPointerDownHandler,!0))}_attachResizeHandler(){this._resizeHandler||(this._resizeHandler=()=>{this._syncPanelVisibility(),this._syncFilterOverflow()},window.addEventListener(`resize`,this._resizeHandler,{passive:!0}))}_attachFocusOutHandler(){this._focusOutHandler||(this._focusOutHandler=e=>{if(!this._searchOpen)return;let t=e.relatedTarget;t&&(this._shell&&this._shell.contains(t)||this._panelInner&&this._panelInner.contains(t)||this._closeSearch())},this.addEventListener(`focusout`,this._focusOutHandler,!0))}_emitSearchOpenChange(){this.dispatchEvent(new CustomEvent(`search-open-change`,{detail:{open:this._searchOpen},bubbles:!0,composed:!0}))}_openSearch(e=!1){this._getEndpoint()&&(this._searchOpen||(this._searchOpen=!0,this._syncPanelVisibility(),this._emitSearchOpenChange(),e&&this._primarySearchInput()?.focus()))}_closeSearch(){this._searchOpen&&(this._searchOpen=!1,this._filtersMoreOpen=!1,this._syncPanelVisibility(),this._emitSearchOpenChange())}_syncPanelVisibility(){if(!this._panel)return;let e=this._panelLayoutBaseClass();this._panel.className=this._searchOpen?e:`${e} hidden`,this._shell&&(this._shell.classList.toggle(`rounded-b-none`,this._searchOpen),this._shell.classList.toggle(`border-b-transparent`,this._searchOpen)),this._positionPanel(),this._searchOpen&&this._scheduleFilterOverflowSync()}_panelLayoutBaseClass(){return!this._isMobileViewport()||!this._collapseOnMobile()?`absolute left-0 right-0 top-full z-[90] p-0 -mt-[9px]`:`fixed left-0 right-0 top-12 z-[90] p-3`}_positionPanel(){this._panel&&(!this._isMobileViewport()||!this._collapseOnMobile())&&(this._panel.style.left=``,this._panel.style.right=``,this._panel.style.top=``,this._panel.style.width=``,this._panel.style.maxWidth=``,this._panel.style.transform=``)}_setQuery(e){let t=this._query;this._query=e,e!==t&&(this._selectedFilterBackspaceArmed=!1),this._desktopInput&&(this._desktopInput.value=e),this._panelInput&&(this._panelInput.value=e)}_cancelDebounce(){this._debounceId!==null&&(window.clearTimeout(this._debounceId),this._debounceId=null)}_abortSearch(){this._abortController&&=(this._abortController.abort(),null)}_normalizeResults(e){return(e=>{if(Array.isArray(e))return e;if(!e||typeof e!=`object`)return[];let t=e;for(let e of[`results`,`items`,`data`,`products`]){let n=t[e];if(Array.isArray(n))return n}return[]})(e).map(e=>{let t=e||{};return{title:String(t.title||t.name||t.label||t.email||t.id||``).trim()||`Untitled`,subtitle:String(t.description||t.category||t.username||``).trim(),parent:String(t.parent||t.type||t.entity||t.kind||t.category||``).trim()||void 0}}).slice(0,8)}_emitResultsChange(e,t){let n=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-results-change`,{detail:{query:this._query,filter:n,filters:[...this._selectedFilters],results:e,raw:t??null},bubbles:!0,composed:!0}))}_emitFilterChange(){let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-filter-change`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters]},bubbles:!0,composed:!0}))}_renderState(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`hidden`);return}this._stateWrap&&(this._stateWrap.textContent=e,this._stateWrap.classList.remove(`hidden`),this._resultsWrap&&(this._resultsWrap.classList.remove(`hidden`),this._resultsWrap.innerHTML=``))}_renderResults(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`hidden`);return}if(!(!this._resultsWrap||!this._stateWrap)){if(this._resultsWrap.innerHTML=``,e.length===0){this._renderState(`No results found`);return}this._stateWrap.classList.add(`hidden`);for(let t of e){let e=document.createElement(`button`);e.type=`button`,e.className=`flex w-full cursor-pointer items-start gap-3 rounded-lg px-3 py-2 text-left hover:bg-gray-100 dark:hover:bg-white/10`;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`mt-0.5 h-4 w-4 text-gray-500 dark:text-gray-400`;let r=document.createElement(`div`);r.className=`min-w-0`;let i=document.createElement(`div`);if(i.className=`truncate text-sm font-semibold text-gray-900 dark:text-gray-100`,i.textContent=t.title,r.appendChild(i),t.subtitle){let e=document.createElement(`div`);e.className=`truncate text-xs text-gray-500 dark:text-gray-400`,e.textContent=t.subtitle,r.appendChild(e)}e.appendChild(n),e.appendChild(r),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){t.preventDefault(),this._moveFocusInResults(e,1);return}if(t.key===`ArrowUp`){t.preventDefault(),this._moveFocusInResults(e,-1);return}}),e.addEventListener(`click`,()=>{let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-select`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters],result:t},bubbles:!0,composed:!0})),this._closeSearch()}),this._resultsWrap.appendChild(e)}}}_fetchSearchResults(e){let t=this._getEndpoint();if(!t)return;let n=e.trim();if(!n){this._emitResultsChange([]),this._renderState(`Start typing to search`);return}this._abortSearch(),this._abortController=new AbortController,this._renderState(`Searching...`);let r=new URLSearchParams;r.set(this._getSearchParam(),n);let i=this._getFilterParam();i&&this._hasSelectedFilters()&&r.set(i,this._getFilterParamValue());let a=t.includes(`{query}`)?t.replace(`{query}`,encodeURIComponent(n)):`${t}${t.includes(`?`)?`&`:`?`}${r.toString()}`;fetch(a,{signal:this._abortController.signal}).then(e=>{if(!e.ok)throw Error(`Request failed: ${e.status}`);return e.json()}).then(e=>{let t=this._normalizeResults(e);this._emitResultsChange(t,e),this._renderResults(t)}).catch(e=>{e?.name!==`AbortError`&&(this._emitResultsChange([]),this._renderState(`Unable to load results`))})}_scheduleSearch(e){this._setQuery(e),this._cancelDebounce(),this._debounceId=window.setTimeout(()=>this._fetchSearchResults(e),220)}_getNativeInputValue(e){if(!e)return``;let t=e.querySelector(`input, textarea`);return t?t.value||``:e.value||``}_getCurrentInputValue(){let e=document.activeElement;return e&&this._desktopInput&&this._desktopInput.contains(e)?this._getNativeInputValue(this._desktopInput):e&&this._panelInput&&this._panelInput.contains(e)?this._getNativeInputValue(this._panelInput):this._getNativeInputValue(this._primarySearchInput())}_applyFilterSelectionChange(){let e=this._getCurrentInputValue();if(this._setQuery(e),this._emitFilterChange(),this.render(),e.trim()){this._scheduleSearch(e);return}this._cancelDebounce(),this._abortSearch(),this._emitResultsChange([]),this._renderState(`Start typing to search`)}_clearAllSelectedFilters(){this._selectedFilters=[],this._selectedFilterBackspaceArmed=!1,this._applyFilterSelectionChange()}_popLastSelectedFilter(){this._selectedFilters.length!==0&&(this._selectedFilters.pop(),this._selectedFilterBackspaceArmed=!1,this._applyFilterSelectionChange())}_focusActiveInput(){let e=this._primarySearchInput();e&&requestAnimationFrame(()=>{e.focus()})}_focusHideFiltersControl(){let e=this._panelFiltersShowAllBtn;e&&(e.querySelector(`button`)??e).focus()}_getFilterChipElements(){return this._panelFiltersWrap?Array.from(this._panelFiltersWrap.querySelectorAll(`mint-chip`)):[]}_ensurePanelFiltersShell(){!this._panelFiltersWrap||this._panelFiltersMainRow||(this._panelFiltersWrap.replaceChildren(),this._panelFiltersWrap.className=`relative flex shrink-0 flex-col gap-2 px-3 pb-3 pt-5 min-w-0`,this._panelFiltersMainRow=document.createElement(`div`),this._panelFiltersMainRow.className=`flex min-w-0 w-full flex-nowrap items-center gap-2`,this._panelFiltersChips=document.createElement(`div`),this._panelFiltersChips.className=`flex min-w-0 flex-1 flex-nowrap items-center gap-2 overflow-x-hidden`,this._panelFiltersMorePanel=document.createElement(`div`),this._panelFiltersMorePanel.id=`mint-search-filter-more-${e._filterMorePanelSeq++}`,this._panelFiltersMorePanel.className=`hidden absolute left-0 right-0 top-full z-[95] mt-1 flex max-h-[40vh] flex-wrap gap-2 overflow-y-auto rounded-lg border border-gray-200 bg-white p-2 shadow-lg dark:border-mint-divider dark:bg-mint-elevated`,this._panelFiltersShowAllWrap=document.createElement(`div`),this._panelFiltersShowAllWrap.className=`relative flex min-h-0 min-w-0 shrink-0 items-center hidden`,this._panelFiltersShowAllBtn=document.createElement(`mint-button`),this._panelFiltersShowAllBtn.setAttribute(`type`,`button`),this._panelFiltersShowAllBtn.setAttribute(`variant`,`ghost`),this._panelFiltersShowAllBtn.setAttribute(`tone`,`neutral`),this._panelFiltersShowAllBtn.setAttribute(`size`,`small`),this._panelFiltersShowAllBtn.classList.add(`shrink-0`,`whitespace-nowrap`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,`false`),this._panelFiltersShowAllBtn.setAttribute(`aria-controls`,this._panelFiltersMorePanel.id),this._panelFiltersShowAllBtn.addEventListener(`click`,e=>{e.stopPropagation();let t=this._filtersMoreOpen;this._filtersMoreOpen=!this._filtersMoreOpen,this.render(),t&&requestAnimationFrame(()=>this._focusActiveInput())}),this._panelFiltersShowAllWrap.append(this._panelFiltersShowAllBtn),this._panelFiltersMainRow.append(this._panelFiltersChips,this._panelFiltersShowAllWrap),this._setPanelFiltersShowAllLabel(`Show all`),this._panelFiltersWrap.append(this._panelFiltersMainRow,this._panelFiltersMorePanel),typeof ResizeObserver<`u`&&!this._filterOverflowObserver&&(this._filterOverflowObserver=new ResizeObserver(()=>this._syncFilterOverflow()),this._filterOverflowObserver.observe(this._panelFiltersChips),this._filterOverflowObserver.observe(this._panelFiltersMainRow)))}_setPanelFiltersShowAllLabel(e){let t=this._panelFiltersShowAllBtn;if(!t)return;for(let e of Array.from(t.childNodes))e.nodeType===Node.TEXT_NODE&&e.remove();let n=t.querySelector(`button .mint-button-content`)||t.querySelector(`.mint-button-content`);if(n){n.textContent=e;return}let r=t.querySelector(`:scope > button`);if(r){r.replaceChildren(document.createTextNode(e)),t.render?.();return}t.firstElementChild||t.appendChild(document.createTextNode(e))}_scheduleFilterOverflowSync(){requestAnimationFrame(()=>{requestAnimationFrame(()=>this._syncFilterOverflow())})}_setFilterChipsEdgeFade(t){let n=this._panelFiltersChips;n&&(t?(n.style.maskImage=e._filterChipsOverflowMask,n.style.webkitMaskImage=e._filterChipsOverflowMask):(n.style.maskImage=``,n.style.webkitMaskImage=``))}_syncFilterOverflow(){if(!this._panelFiltersChips||!this._panelFiltersShowAllWrap||!this._panelFiltersShowAllBtn)return;if(this._filtersMoreOpen){this._panelFiltersShowAllWrap.classList.remove(`hidden`),this._filterOverflowZeroWidthRetries=0,this._setFilterChipsEdgeFade(!1);return}let e=this._panelFiltersChips.clientWidth;if(e===0&&this._searchOpen){this._filterOverflowZeroWidthRetries<10&&(this._filterOverflowZeroWidthRetries+=1,this._scheduleFilterOverflowSync()),this._setFilterChipsEdgeFade(!1);return}this._filterOverflowZeroWidthRetries=0;let t=this._panelFiltersChips.scrollWidth+this._getFilterChipOverflowReservePx()>e;this._panelFiltersShowAllWrap.classList.toggle(`hidden`,!t),this._setFilterChipsEdgeFade(t)}_getResultFocusableElements(){let e=this._customResultsWrap&&!this._customResultsWrap.classList.contains(`hidden`)?this._customResultsWrap:this._resultsWrap;return e?Array.from(e.querySelectorAll(`button:not([disabled]), [href], [tabindex]:not([tabindex="-1"]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])`)):[]}_focusFirstChipOrResult(e=!1){let t=this._getFilterChipElements(),n=this._getResultFocusableElements();if(!e){(t[0]||n[0])?.focus();return}(n[n.length-1]||t[t.length-1])?.focus()}_moveFocusInResults(e,t){let n=this._getResultFocusableElements();if(n.length===0)return;let r=n.indexOf(e);if(r===-1)return;let i=n[r+t];if(i){i.focus();return}if(t===-1){let e=this._getFilterChipElements(),t=e[e.length-1];t?t.focus():this._focusActiveInput()}}_renderSelectedFilter(){let e=e=>{if(!e||(e.innerHTML=``,!this._hasSelectedFilters()))return;let t=document.createElement(`mint-chip`);t.setAttribute(`dismissable`,``),t.title=this._getFilterChipLabelText();let n=this._getCondensedFilterChipLabel();t.classList.add(`max-w-[min(20rem,85vw)]`,`whitespace-nowrap`,`overflow-hidden`,`text-ellipsis`,`text-xs`,`px-2`,`py-0.5`),t.style.fontSize=`0.75rem`,t.style.padding=`0.125rem 0.375rem`,t.style.height=`1.375rem`,t.style.lineHeight=`1`,t.style.whiteSpace=`nowrap`,t.style.overflow=`hidden`,t.style.textOverflow=`ellipsis`,this._selectedFilterBackspaceArmed&&t.classList.add(`ring-2`,`ring-brand-400`,`dark:ring-brand-300`),t.textContent=n,t.addEventListener(`dismiss`,e=>{e.stopPropagation(),this._clearAllSelectedFilters()}),e.appendChild(t)};e(this._desktopFilterWrap),e(this._mobileFilterWrap)}_bindInputHandlers(e){let t=()=>{this._scheduleSearch(this._getNativeInputValue(e))};e.addEventListener(`focusin`,()=>this._openSearch(!1)),e.addEventListener(`input`,t),e.addEventListener(`search`,t),e.addEventListener(`change`,t),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!1);return}if(t.key===`ArrowUp`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!0);return}if(t.key===`Tab`&&!t.shiftKey&&this._searchOpen){let e=this._getFilterChipElements(),n=this._getResultFocusableElements();if(e.length>0||n.length>0){t.preventDefault(),this._focusFirstChipOrResult(!1);return}}if(t.key!==`Backspace`)return;let n=this._getNativeInputValue(e);if(n!==this._query&&this._setQuery(n),!(n.length>0)&&this._hasSelectedFilters()){if(!this._selectedFilterBackspaceArmed){t.preventDefault(),this._selectedFilterBackspaceArmed=!0,this._renderSelectedFilter();return}t.preventDefault(),this._popLastSelectedFilter()}})}openSearch(e=!0){this._openSearch(e)}closeSearch(){this._closeSearch()}toggleSearch(e=!0){if(this._searchOpen){this._closeSearch();return}this._openSearch(e)}isSearchOpen(){return this._searchOpen}render(){let e=this._getEndpoint();if(this.classList.toggle(`hidden`,!e),!e)return;if(!this._shell){this._shell=document.createElement(`div`),this._shell.className=`relative z-[91] flex h-10 w-full`,this._desktopFilterWrap=document.createElement(`div`),this._desktopFilterWrap.className=`inline-flex shrink-0 max-w-[8.5rem]`,this._desktopFilterWrap.setAttribute(`slot`,`prepend`),this._desktopInput=document.createElement(`mint-input`),this._desktopInput.setAttribute(`type`,`search`),this._desktopInput.setAttribute(`icon`,`search`),this._desktopInput.className=`h-full min-w-0 flex-1`;let e=document.createElement(`span`);e.className=`shrink-0 text-xs text-gray-500 dark:text-gray-400`,e.setAttribute(`slot`,`append`),this._desktopShortcutHint=e,this._bindInputHandlers(this._desktopInput),this._desktopInput.appendChild(this._desktopFilterWrap),this._desktopInput.appendChild(e),this._shell.appendChild(this._desktopInput),this.appendChild(this._shell)}if(!this._panel){this._panel=document.createElement(`div`),this._panel.className=`absolute left-0 right-0 top-full z-[90] hidden p-0 -mt-[9px]`;let e=document.createElement(`div`);e.className=`mx-auto flex max-h-[calc(100dvh-4rem)] w-full flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl dark:border-mint-divider dark:bg-mint-elevated min-[1100px]:rounded-t-none min-[1100px]:border-t-0`,this._panelInner=e;let t=document.createElement(`div`);this._panelSearchBar=t,t.className=`hidden`,this._mobileFilterWrap=document.createElement(`div`),this._mobileFilterWrap.className=`inline-flex shrink-0 max-w-[8.5rem]`,this._mobileFilterWrap.setAttribute(`slot`,`prepend`),this._panelInput=document.createElement(`mint-input`),this._panelInput.setAttribute(`type`,`search`),this._panelInput.className=`min-w-0 flex-1`,this._bindInputHandlers(this._panelInput),this._panelInput.appendChild(this._mobileFilterWrap),t.appendChild(this._panelInput),this._customResultsWrap=document.createElement(`div`),this._customResultsWrap.className=`min-h-0 flex-1 overflow-y-auto px-2 pb-2`,this._stateWrap=document.createElement(`div`),this._stateWrap.className=`px-4 pb-4 text-sm text-gray-500 dark:text-gray-400`,this._stateWrap.textContent=`Start typing to search`,this._resultsWrap=document.createElement(`div`),this._resultsWrap.className=`min-h-0 flex-1 overflow-y-auto px-2 pb-2`,e.appendChild(t),this._panelFiltersWrap=document.createElement(`div`),e.appendChild(this._panelFiltersWrap),this._ensurePanelFiltersShell(),e.appendChild(this._customResultsWrap),e.appendChild(this._stateWrap),e.appendChild(this._resultsWrap),this._panel.appendChild(e),this.appendChild(this._panel)}let t=this._hasSelectedFilters()?``:this._getPlaceholder();if(this._desktopInput&&this._desktopInput.setAttribute(`placeholder`,t),this._panelInput&&this._panelInput.setAttribute(`placeholder`,t),this._desktopShortcutHint){let e=this._getOpenShortcutHintText();this._desktopShortcutHint.textContent=e,this._desktopShortcutHint.classList.toggle(`hidden`,!e)}if(this._panelFiltersWrap){this._ensurePanelFiltersShell();let e=this._getFilterOptions();this._selectedFilters=this._selectedFilters.filter(t=>e.includes(t));let t=e.length>0;t||(this._filtersMoreOpen=!1),this._panelFiltersWrap.classList.toggle(`hidden`,!t),this._stateWrap?.classList.toggle(`pt-4`,!t),this._resultsWrap?.classList.toggle(`pt-4`,!t),this._customResultsWrap?.classList.toggle(`pt-5`,!t),this._panelFiltersChips&&this._panelFiltersChips.replaceChildren(),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.replaceChildren();let n=this._filtersMoreOpen&&this._panelFiltersMorePanel?this._panelFiltersMorePanel:this._panelFiltersChips;for(let t of e){if(!n)break;let r=document.createElement(`mint-chip`),i=this._selectedFilters.includes(t);if(i&&r.classList.add(`ring-2`,`ring-inset`,`ring-brand-400`,`dark:ring-brand-300`),r.classList.add(`cursor-pointer`,`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-inset`,`focus-visible:ring-brand-400`,`inline-flex`,`items-center`,`gap-1`,`shrink-0`,`whitespace-nowrap`),i){let e=document.createElement(`span`);e.textContent=t;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`close`),n.className=`h-4 w-4 ml-2 shrink-0`,n.setAttribute(`aria-hidden`,`true`),r.append(e,n)}else r.textContent=t;r.tabIndex=0,r.setAttribute(`role`,`button`),r.setAttribute(`aria-label`,i?`Remove filter ${t}`:`Filter by ${t}`),r.dataset.mintSearchFilter=t,r.addEventListener(`pointerdown`,e=>{e.preventDefault()});let a=n=>{n&&n.stopPropagation();let r=this._filtersMoreOpen,i=this._selectedFilters.indexOf(t);i>=0?this._selectedFilters.splice(i,1):this._selectedFilters.push(t),this._selectedFilterBackspaceArmed=!1;let a=e.length>0&&this._selectedFilters.length===e.length,o=this._selectedFilters.length===0;r&&(a||o)&&(this._filtersMoreOpen=!1),this._emitFilterChange(),this._renderSelectedFilter(),this.render(),this._query.trim()&&this._scheduleSearch(this._query),r?a||o?this._focusActiveInput():requestAnimationFrame(()=>{this._getFilterChipElements().find(e=>e.dataset.mintSearchFilter===t)?.focus()}):this._focusActiveInput()};r.addEventListener(`click`,e=>a(e)),r.addEventListener(`keydown`,e=>{let t=this._getFilterChipElements(),n=t.indexOf(r);if(e.key===`Enter`||e.key===` `){e.preventDefault(),a(e);return}if(e.key===`ArrowRight`){e.preventDefault();let r=t[n+1];r&&r.focus();return}if(e.key===`ArrowLeft`){e.preventDefault();let r=t[n-1];r?r.focus():this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}if(e.key===`ArrowDown`){e.preventDefault(),this._getResultFocusableElements()[0]?.focus();return}if(e.key===`ArrowUp`){e.preventDefault(),this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}}),n.appendChild(r)}this._panelFiltersChips&&this._panelFiltersChips.classList.toggle(`hidden`,this._filtersMoreOpen),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.classList.toggle(`hidden`,!this._filtersMoreOpen),this._panelFiltersShowAllBtn&&(this._setPanelFiltersShowAllLabel(this._filtersMoreOpen?`Hide filters`:`Show all`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,this._filtersMoreOpen?`true`:`false`)),this._panelInner&&(this._filtersMoreOpen&&t?(this._panelInner.classList.remove(`overflow-hidden`),this._panelInner.classList.add(`overflow-visible`)):(this._panelInner.classList.remove(`overflow-visible`),this._panelInner.classList.add(`overflow-hidden`))),this._scheduleFilterOverflowSync()}if(this._customResultsWrap){Array.from(this.children).filter(e=>e===this._shell||e===this._panel?!1:e.getAttribute(`slot`)===`results`).forEach(e=>this._customResultsWrap.appendChild(e));let e=this._customResultsWrap.childElementCount>0;this._customResultsWrap.classList.toggle(`hidden`,!e),e?(this._stateWrap?.classList.add(`hidden`),this._resultsWrap?.classList.add(`hidden`)):this._resultsWrap?.classList.remove(`hidden`)}this._renderSelectedFilter(),this._syncResponsiveChrome(),this._syncPanelVisibility()}_syncResponsiveChrome(){let e=this._collapseOnMobile();this._shell&&(this._shell.className=e?`relative z-[91] hidden h-10 w-full min-[1100px]:flex`:`relative z-[91] flex h-10 w-full`),this._panelSearchBar&&(this._panelSearchBar.className=e?`flex shrink-0 items-center gap-2 border-b border-gray-200 p-3 dark:border-mint-divider min-[1100px]:hidden`:`hidden`)}};customElements.get(`mint-search`)||customElements.define(`mint-search`,W);var G=class extends HTMLElement{constructor(...e){super(...e),this._lastScrollY=0,this._scrollHandler=null}connectedCallback(){this.classList.add(`fixed`,`bottom-0`,`left-0`,`right-0`,`z-30`,`flex`,`w-full`,`items-stretch`,`justify-around`,`gap-1`,`border-t`,`border-gray-200`,`bg-white`,`px-1`,`pt-1`,`pb-[env(safe-area-inset-bottom,0px)]`,`min-[1100px]:hidden`,`transition-transform`,`duration-200`,`ease-out`,`translate-y-0`,`dark:border-mint-divider`,`dark:bg-mint-nav`),this.setAttribute(`role`,`navigation`),this.setAttribute(`aria-label`,`Primary`),this._lastScrollY=window.scrollY,this._attachScrollListener()}disconnectedCallback(){this._detachScrollListener()}_attachScrollListener(){this._scrollHandler||(this._scrollHandler=()=>{let e=window.scrollY;if(e<=8){this.classList.remove(`translate-y-full`),this.classList.add(`translate-y-0`),this._lastScrollY=e;return}let t=e-this._lastScrollY;Math.abs(t)<4||(t>0?(this.classList.remove(`translate-y-0`),this.classList.add(`translate-y-full`)):(this.classList.remove(`translate-y-full`),this.classList.add(`translate-y-0`)),this._lastScrollY=e)},window.addEventListener(`scroll`,this._scrollHandler,{passive:!0}))}_detachScrollListener(){this._scrollHandler&&=(window.removeEventListener(`scroll`,this._scrollHandler),null)}};customElements.get(`mint-bottom-navigation`)||customElements.define(`mint-bottom-navigation`,G);var K=class extends HTMLElement{constructor(...e){super(...e),this._root=null}static get observedAttributes(){return[`icon`,`label`,`href`,`active`]}connectedCallback(){this.classList.add(`contents`),this.render()}attributeChangedCallback(e,t,n){t!==n&&this.render()}_isActive(){return this.getAttribute(`active`)===`true`}_getLabel(){return this.getAttribute(`label`)||``}_getIcon(){return this.getAttribute(`icon`)||``}_getHref(){return this.getAttribute(`href`)}render(){let e=this._getHref(),t=this._getLabel(),n=this._getIcon(),r=this._isActive(),i=r?`text-gray-900 dark:text-gray-100`:`text-gray-600 hover:bg-black/5 dark:text-gray-300 dark:hover:bg-white/10`,a;e?(a=document.createElement(`a`),a.href=e):(a=document.createElement(`button`),a.type=`button`),a.className=`flex min-w-0 flex-1 flex-col items-center justify-center gap-1 rounded-lg px-1 py-2 text-center text-[11px] font-medium leading-tight ${i}`,a.setAttribute(`aria-current`,r?`page`:`false`),a.setAttribute(`aria-label`,t||`Navigation item`);let o=document.createElement(`span`);if(o.className=`inline-flex h-6 w-6 items-center justify-center`,n){let e=document.createElement(`mint-icon`);e.setAttribute(`name`,n),e.className=r?`h-6 w-6`:`h-6 w-6 opacity-90`,o.appendChild(e)}let s=document.createElement(`span`);s.className=`block w-full truncate`,s.textContent=t,a.appendChild(o),a.appendChild(s),this.replaceChildren(a),this._root=a}};customElements.get(`mint-bottom-nav-item`)||customElements.define(`mint-bottom-nav-item`,K);var q=class extends HTMLElement{constructor(...e){super(...e),this._messageEl=null,this._hideTimer=null,this._hideResolve=null,this._bottomNavObserver=null,this._bodyObserver=null}static get observedAttributes(){return[`open`,`message`]}connectedCallback(){this.classList.add(`pointer-events-none`,`fixed`,`left-1/2`,`-translate-x-1/2`,`min-[1100px]:bottom-4`,`z-40`,`transition-all`,`duration-200`,`ease-out`,`opacity-0`,`translate-y-2`),this._updateBottomOffset(),this._setupBottomNavObservers(),this.setAttribute(`aria-live`,`polite`),this.setAttribute(`aria-atomic`,`true`),this.render()}disconnectedCallback(){this._clearHideTimer(),this._disconnectBottomNavObservers(),this._hideResolve=null}attributeChangedCallback(e,t,n){t!==n&&(e===`open`||e===`message`)&&this.render()}async showToast(e,t=2200){let n=e.trim().slice(0,120);n&&(this._updateBottomOffset(),this._clearHideTimer(),this._hideResolve=null,this.setAttribute(`message`,n),this.setAttribute(`open`,`true`),this.render(),await new Promise(e=>{this._hideResolve=e,this._hideTimer=window.setTimeout(()=>{this.hideToast()},t)}))}hideToast(e=!1){this.removeAttribute(`open`),this.render(),this._clearHideTimer();let t=this._hideResolve;this._hideResolve=null,t&&(e?t():window.setTimeout(t,200))}_clearHideTimer(){this._hideTimer!==null&&(window.clearTimeout(this._hideTimer),this._hideTimer=null)}_updateBottomOffset(){let e=this._hasVisibleBottomNav();this.classList.remove(`bottom-[calc(env(safe-area-inset-bottom,0px)+4.5rem)]`,`bottom-[calc(env(safe-area-inset-bottom,0px)+1rem)]`),this.classList.add(e?`bottom-[calc(env(safe-area-inset-bottom,0px)+4.5rem)]`:`bottom-[calc(env(safe-area-inset-bottom,0px)+1rem)]`)}_hasVisibleBottomNav(){let e=document.querySelector(`mint-bottom-navigation`);if(!e)return!1;let t=window.getComputedStyle(e);return!(t.display===`none`||t.visibility===`hidden`||e.classList.contains(`translate-y-full`))}_setupBottomNavObservers(){this._disconnectBottomNavObservers();let e=()=>{this._bottomNavObserver&&=(this._bottomNavObserver.disconnect(),null);let e=document.querySelector(`mint-bottom-navigation`);if(!e){this._updateBottomOffset();return}this._bottomNavObserver=new MutationObserver(()=>{this._updateBottomOffset()}),this._bottomNavObserver.observe(e,{attributes:!0,attributeFilter:[`class`,`style`]}),this._updateBottomOffset()};this._bodyObserver=new MutationObserver(()=>{e()}),this._bodyObserver.observe(document.body,{childList:!0,subtree:!0}),e()}_disconnectBottomNavObservers(){this._bottomNavObserver&&=(this._bottomNavObserver.disconnect(),null),this._bodyObserver&&=(this._bodyObserver.disconnect(),null)}render(){let e=this.getAttribute(`open`)===`true`,t=this.getAttribute(`message`)||``;this.classList.toggle(`opacity-100`,e),this.classList.toggle(`translate-y-0`,e),this.classList.toggle(`opacity-0`,!e),this.classList.toggle(`translate-y-2`,!e),this._messageEl||=(this.innerHTML=`<div class="rounded-md bg-[#202223] px-4 py-2 text-sm font-medium text-white shadow-[0_8px_24px_rgba(0,0,0,0.25)] min-[1100px]:px-5 min-[1100px]:py-3 min-[1100px]:text-base dark:bg-[#0f1113]">
|
|
137
|
+
`,a.textContent=e.name,i.appendChild(a),t.appendChild(i)}),this._svg.appendChild(t),{height:this._legendHeight+50}}async addDataPoint(e,t){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets[e].data.push(t),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async batchAddDataPoints(e){if(!this._chartData)return Promise.resolve();let t=!1;for(let{datasetIndex:n,point:r}of e)this._chartData.datasets[n]&&(this._chartData.datasets[n].data.push(r),t=!0);return t&&(this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(e=>requestAnimationFrame(()=>e()))}async updateDatasetData(e,t){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets[e].data=t,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async addDataset(e){return this._chartData?(this._chartData.datasets.push(e),e.id&&this._datasetVisibility.set(e.id,e.visible!==!1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))):(console.error(`Chart data not initialized`),Promise.reject(Error(`Chart data not initialized`)))}async removeDataset(e){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets.splice(e,1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async updateDataPoint(e,t,n){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):this._chartData.datasets[e].data[t]?(this._chartData.datasets[e].data[t]=n,this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))):(console.error(`Data point at index ${t} does not exist`),Promise.reject(Error(`Data point at index ${t} does not exist`)))}async batchUpdateDataPoints(e){if(!this._chartData)return Promise.resolve();let t=!1;for(let{datasetIndex:n,pointIndex:r,point:i}of e)this._chartData.datasets[n]?.data[r]&&(this._chartData.datasets[n].data[r]=i,t=!0);return t&&(this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(e=>requestAnimationFrame(()=>e()))}async removeDataPoint(e,t){return!this._chartData||!this._chartData.datasets[e]?(console.error(`Dataset at index ${e} does not exist`),Promise.reject(Error(`Dataset at index ${e} does not exist`))):(this._chartData.datasets[e].data.splice(t,1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async batchRemoveDataPoints(e){if(!this._chartData)return Promise.resolve();let t=!1;for(let{datasetIndex:n,pointIndex:r}of e)this._chartData.datasets[n]?.data[r]&&(this._chartData.datasets[n].data.splice(r,1),t=!0);return t&&(this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(e=>requestAnimationFrame(()=>e()))}async showDataset(e){return this._datasetVisibility.set(e,!0),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))}async hideDataset(e){return this._datasetVisibility.set(e,!1),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))}async toggleDataset(e){let t=!(this._datasetVisibility.get(e)??!0);return this._datasetVisibility.set(e,t),this._cachedBounds.dataHash=``,this._cachedYRange.dataHash=``,this._cachedXValues.dataHash=``,this._cachedTooltipContent.clear(),this._scheduleRender(),await new Promise(e=>requestAnimationFrame(()=>e())),t}isDatasetVisible(e){return this._datasetVisibility.get(e)}async downloadAsPNG(e=`chart.png`){if(!this._svg)return console.error(`Chart SVG not found`),Promise.reject(Error(`Chart SVG not found`));let t=this._svg.cloneNode(!0),n=this._width,r=this._height;t.querySelectorAll(`text`).forEach(e=>{let t=e.getAttribute(`font-family`);(!t||t.includes(`system-ui`)||t.includes(`apple-system`))&&e.setAttribute(`font-family`,`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`)}),t.setAttribute(`width`,n.toString()),t.setAttribute(`height`,r.toString()),t.setAttribute(`xmlns`,`http://www.w3.org/2000/svg`),t.querySelectorAll(`foreignObject`).forEach(e=>{let t=e.querySelector(`div`);if(t){let n=document.createElementNS(`http://www.w3.org/2000/svg`,`text`),r=e.getAttribute(`x`)||`0`,i=e.getAttribute(`y`)||`0`;n.setAttribute(`x`,r),n.setAttribute(`y`,(parseFloat(i)+12).toString()),n.setAttribute(`fill`,t.style.color||`#374151`),n.setAttribute(`font-size`,`12`),n.setAttribute(`font-family`,t.style.fontFamily||`system-ui, -apple-system, sans-serif`),n.textContent=t.textContent||``,e.parentNode&&e.parentNode.replaceChild(n,e)}});let i=new XMLSerializer().serializeToString(t),a=`data:image/svg+xml;charset=utf-8,`+encodeURIComponent(i),o=new Image;return o.crossOrigin=`anonymous`,new Promise((t,i)=>{o.onload=()=>{setTimeout(()=>{let a=document.createElement(`canvas`);a.width=n+60,a.height=r+60;let s=a.getContext(`2d`);if(!s){console.error(`Could not get canvas context`),i(Error(`Could not get canvas context`));return}s.fillStyle=document.documentElement.classList.contains(`dark`)?`#111827`:`#ffffff`,s.fillRect(0,0,a.width,a.height),s.drawImage(o,30,30),a.toBlob(n=>{if(!n){console.error(`Could not create blob from canvas`),i(Error(`Could not create blob from canvas`));return}let r=URL.createObjectURL(n),a=document.createElement(`a`);a.href=r,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(r),t()},`image/png`)},0)},o.onerror=()=>{console.error(`Error loading SVG image`),i(Error(`Error loading SVG image`))},o.src=a})}};customElements.get(`mint-chart`)||customElements.define(`mint-chart`,L);var R=class extends HTMLElement{constructor(...e){super(...e),this._trigger=null,this._submenuContainer=null,this._contentObserver=null,this._renderFrame=null}static get observedAttributes(){return[`label`,`icon`,`href`,`active`,`expanded`,`submenu-item`]}connectedCallback(){this.classList.add(`block`),this.render(),this._observeSubmenuMutations()}disconnectedCallback(){this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&(this.render(),e===`active`&&this._isSubmenuItem()&&this._refreshDropdownAncestor())}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeSubmenuMutations(){this._contentObserver||=new MutationObserver(e=>{e.some(e=>[...Array.from(e.addedNodes),...Array.from(e.removedNodes)].some(e=>e instanceof HTMLElement&&e.getAttribute(`slot`)===`submenu`))&&this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`],subtree:!1})}_refreshDropdownAncestor(){let e=this.parentElement;for(;e;){if(e.tagName===`MINT-SIDENAV-LINK`&&e!==this){e.render();break}e=e.parentElement}}_isActive(){return this.getAttribute(`active`)===`true`}_isExpanded(){return this.getAttribute(`expanded`)===`true`}_isSubmenuPanelVisible(){return this._isExpanded()||this._isActive()}_isSubmenuItem(){return this.getAttribute(`submenu-item`)===`true`}_getLabel(){return this.getAttribute(`label`)||``}_getIcon(){return this.getAttribute(`icon`)||``}_getHref(){return this.getAttribute(`href`)}_getBaseClasses(){let e=this._isActive()?`border-black/20 bg-black/5 text-black dark:border-white/20 dark:bg-white/10 dark:text-white`:`border-transparent text-gray-700 hover:bg-black/5 dark:text-gray-200 dark:hover:bg-white/10`;return[`w-full`,`cursor-pointer`,`rounded-lg`,`border`,`block`,this._isSubmenuItem()?`px-2 py-1.5`:`px-3 py-2`,`text-left`,`text-sm`,e].join(` `)}_hasSubmenu(){return this.querySelectorAll(`:scope > [slot="submenu"]`).length>0?!0:!!this._submenuContainer&&this._submenuContainer.children.length>0}_createRow(e,t){let n=document.createElement(`span`);if(this._isSubmenuItem(),n.className=`inline-flex w-full items-center justify-start gap-2`,t){let e=document.createElement(`mint-icon`);e.setAttribute(`name`,t),e.className=`h-4 w-4 shrink-0`,n.appendChild(e)}let r=document.createElement(`span`);return r.className=`inline truncate`,r.textContent=e,n.appendChild(r),n}_buildSimpleLink(){let e=this._getHref(),t=this._getLabel(),n=this._getIcon(),r=e?document.createElement(`a`):document.createElement(`button`);e?(r.setAttribute(`href`,e),r.setAttribute(`role`,`link`)):r.setAttribute(`type`,`button`),r.className=this._getBaseClasses(),r.setAttribute(`aria-label`,t||`Side navigation link`),r.appendChild(this._createRow(t,n)),this.replaceChildren(r),this._trigger=r}_emitAccordionExpand(){this.dispatchEvent(new CustomEvent(`mint-sidenav-accordion`,{bubbles:!0,composed:!0,detail:{source:this}}))}_setExpanded(e,t){this.setAttribute(`expanded`,String(e)),e&&t&&this._emitAccordionExpand()}_buildDropdownLink(){let e=this._getLabel(),t=this._getIcon(),n=this._getHref(),r=Array.from(this.querySelectorAll(`:scope > [slot="submenu"]`)),i=r.length>0?r:this._submenuContainer?Array.from(this._submenuContainer.children):[],a=document.createElement(`div`);a.className=`w-full`,this._submenuContainer=document.createElement(`div`),this._submenuContainer.id=`mint-sidenav-submenu-${Math.random().toString(36).slice(2,11)}`;let o=this._submenuContainer.id;if(this._submenuContainer.className=[`mint-sidenav-submenu`,`mt-1`,`ml-5`,`border-l`,`border-gray-200`,`pl-2`,`space-y-1`,`dark:border-mint-divider`,this._isSubmenuPanelVisible()?`block`:`hidden`].join(` `),i.forEach(e=>{e.setAttribute(`submenu-item`,`true`),e.setAttribute(`slot`,`submenu`),this._submenuContainer?.appendChild(e)}),n){let r=document.createElement(`div`);r.className=`flex w-full items-stretch gap-1`;let i=document.createElement(`a`);i.setAttribute(`href`,n),i.className=`${this._getBaseClasses()} hidden min-[1100px]:block`,i.setAttribute(`aria-expanded`,String(this._isSubmenuPanelVisible())),i.setAttribute(`aria-controls`,o),this._isActive()?i.setAttribute(`aria-current`,`page`):i.removeAttribute(`aria-current`),i.appendChild(this._createRow(e,t)),i.addEventListener(`click`,()=>{this._setExpanded(!0,!0)});let s=document.createElement(`a`);s.setAttribute(`href`,n),s.className=`${this._getBaseClasses()} block min-w-0 min-[1100px]:hidden`,s.style.flex=`1 1 auto`,s.setAttribute(`aria-controls`,o),s.appendChild(this._createRow(e,t)),this._isActive()?s.setAttribute(`aria-current`,`page`):s.removeAttribute(`aria-current`);let c=document.createElement(`button`);c.type=`button`,c.className=[`inline-flex`,`items-center`,`justify-center`,`rounded-lg`,`border`,`border-transparent`,`px-2`,`text-gray-600`,`hover:bg-black/5`,`dark:text-gray-300`,`dark:hover:bg-white/10`,`min-[1100px]:hidden`].join(` `),c.setAttribute(`aria-label`,`Toggle ${e} submenu`),c.setAttribute(`aria-expanded`,String(this._isSubmenuPanelVisible())),c.setAttribute(`aria-controls`,o),c.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation();let t=!this._isExpanded();this._setExpanded(t,t)});let l=document.createElement(`mint-icon`);l.setAttribute(`name`,`caret-down`),l.className=[`h-4`,`w-4`,`transition-transform`,`duration-200`,`ease-out`,this._isSubmenuPanelVisible()?`rotate-180`:`rotate-0`].join(` `),c.appendChild(l),r.appendChild(i),r.appendChild(s),r.appendChild(c),a.appendChild(r),this._trigger=i}else{let n=document.createElement(`button`);n.type=`button`,n.className=`${this._getBaseClasses()} block w-full`,n.setAttribute(`aria-expanded`,String(this._isSubmenuPanelVisible())),n.setAttribute(`aria-controls`,o),n.appendChild(this._createRow(e,t)),n.onclick=()=>{let e=!this._isExpanded();this._setExpanded(e,e)},a.appendChild(n),this._trigger=n}a.appendChild(this._submenuContainer),this.replaceChildren(a)}render(){this._hasSubmenu()&&!this._isSubmenuItem()?this._buildDropdownLink():this._buildSimpleLink()}};customElements.get(`mint-sidenav-link`)||customElements.define(`mint-sidenav-link`,R);var z=class extends HTMLElement{constructor(...e){super(...e),this._container=null,this._title=null,this._titleLabel=null,this._titleCaret=null,this._list=null,this._titleClickHandler=null,this._listenerCounts=new Map}static get observedAttributes(){return[`name`]}get onMintNameClick(){return this._onMintNameClick}set onMintNameClick(e){this._onMintNameClick=e,this.render()}addEventListener(e,t,n){super.addEventListener(e,t,n),this._trackListener(e,1)}removeEventListener(e,t,n){super.removeEventListener(e,t,n),this._trackListener(e,-1)}connectedCallback(){this.classList.add(`block`),this.render()}disconnectedCallback(){this._title&&this._titleClickHandler&&(this._title.removeEventListener(`click`,this._titleClickHandler),this._title.removeEventListener(`keydown`,this._titleClickHandler))}attributeChangedCallback(e,t,n){t!==n&&this.render()}_getName(){return this.getAttribute(`name`)||``}_trackListener(e,t){if(e!==`mint-name-click`)return;let n=this._listenerCounts.get(e)||0,r=Math.max(0,n+t);this._listenerCounts.set(e,r),this.render()}_isNameInteractive(){return(this._listenerCounts.get(`mint-name-click`)||0)>0||typeof this._onMintNameClick==`function`}_emitNameClick(e){let t=new CustomEvent(`mint-name-click`,{detail:{name:this._getName(),originalEvent:e},bubbles:!0,composed:!0});this.dispatchEvent(t),typeof this._onMintNameClick==`function`&&this._onMintNameClick(t)}render(){this._container||(this._container=document.createElement(`section`),this._container.className=`mb-4`,this.appendChild(this._container)),this._title||(this._title=document.createElement(`button`),this._title.setAttribute(`type`,`button`),this._title.className=`mb-2 w-full`,this._titleLabel=document.createElement(`mint-text`),this._titleLabel.setAttribute(`size`,`small`),this._titleLabel.setAttribute(`bold`,`true`),this._titleCaret=document.createElement(`mint-icon`),this._titleCaret.setAttribute(`name`,`caret-right`),this._titleCaret.className=`ml-auto inline-flex h-4 w-4 shrink-0 text-gray-500 dark:text-gray-400`,this._title.appendChild(this._titleLabel),this._title.appendChild(this._titleCaret),this._titleClickHandler=e=>{this._isNameInteractive()&&(e instanceof KeyboardEvent&&e.key!==`Enter`&&e.key!==` `||(e instanceof KeyboardEvent&&e.key===` `&&e.preventDefault(),this._emitNameClick(e)))},this._title.addEventListener(`click`,this._titleClickHandler),this._title.addEventListener(`keydown`,this._titleClickHandler),this._container.appendChild(this._title));let e=this._getName(),t=e.trim().length>0,n=this._isNameInteractive();this._titleLabel&&(this._titleLabel.textContent=e,this._titleLabel.className=`uppercase tracking-wide text-gray-500 dark:text-gray-400`),this._title&&(this._title.className=n?[`mb-2`,`w-full`,`inline-flex`,`items-center`,`gap-2`,`rounded-lg`,`border`,`border-transparent`,`px-3`,`py-2`,`text-left`,`hover:bg-black/5`,`dark:hover:bg-white/10`,`cursor-pointer`,`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-black/20`,`dark:focus-visible:ring-white/20`].join(` `):`mb-2 w-full inline-flex items-center gap-2 rounded-lg border border-transparent px-3 py-2 text-left cursor-default`,this._title.tabIndex=n?0:-1,this._title.disabled=!n,this._title.setAttribute(`aria-disabled`,String(!n))),this._titleCaret&&(this._titleCaret.style.display=n?``:`none`,this._titleCaret.setAttribute(`aria-hidden`,String(!n))),t?this._title.parentElement!==this._container&&this._container?.insertBefore(this._title,this._list):this._title.parentElement===this._container&&this._container?.removeChild(this._title),this._list||(this._list=document.createElement(`div`),this._list.className=`space-y-1`,this._container.appendChild(this._list)),Array.from(this.children).filter(e=>e!==this._container&&e.tagName===`MINT-SIDENAV-LINK`).forEach(e=>{this._list&&e.parentElement!==this._list&&this._list.appendChild(e)})}};customElements.get(`mint-sidenav-links`)||customElements.define(`mint-sidenav-links`,z);var B=class extends HTMLElement{static get observedAttributes(){return[`separated`]}connectedCallback(){this.render()}attributeChangedCallback(e,t,n){t!==n&&this.render()}_isSeparated(){return this.getAttribute(`separated`)===`true`}render(){this.className=this._isSeparated()?`block w-full mt-2 border-t border-gray-200 pt-2 px-2 pb-2 dark:border-mint-divider`:`block w-full p-2`}};customElements.get(`mint-sidenav-action-links`)||customElements.define(`mint-sidenav-action-links`,B);var V=class extends HTMLElement{constructor(...e){super(...e),this._wrapper=null,this._trigger=null,this._popover=null,this._triggerId=``,this._contentObserver=null,this._renderFrame=null}static get observedAttributes(){return[`title`,`subtitle`]}connectedCallback(){this.classList.add(`block`),this._triggerId=this.id?`${this.id}-trigger`:`mint-sidenav-action-menu-${Math.random().toString(36).slice(2,9)}`,this.render(),this._observeContentMutations()}disconnectedCallback(){this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_getTitle(){return this.getAttribute(`title`)||``}_getSubtitle(){return this.getAttribute(`subtitle`)||``}_createDefaultGroup(){let e=document.createElement(`mint-sidenav-action-links`),t=document.createElement(`div`);return t.appendChild(e),t}render(){let e=Array.from(this.children).filter(e=>e!==this._wrapper&&e.getAttribute(`slot`)===`action-links`);this._wrapper||(this._wrapper=document.createElement(`div`),this._wrapper.className=`relative`,this.appendChild(this._wrapper)),this._wrapper.innerHTML=``,this._trigger=document.createElement(`button`),this._trigger.type=`button`,this._trigger.id=this._triggerId,this._trigger.className=`flex w-full cursor-pointer items-center gap-3 rounded-xl border border-gray-200 bg-gray-50 px-3 py-2 text-left hover:bg-gray-100 dark:border-mint-divider dark:bg-white/5 dark:hover:bg-white/10`;let t=document.createElement(`div`);t.className=`inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-gray-700 text-xs font-semibold text-white dark:bg-mint-nav`,t.textContent=this._getTitle().split(` `).map(e=>e[0]).join(``).slice(0,2).toUpperCase();let n=document.createElement(`div`);n.className=`min-w-0 flex-1`;let r=document.createElement(`mint-text`);r.setAttribute(`size`,`body`),r.setAttribute(`bold`,`true`),r.className=`truncate text-gray-900 dark:text-gray-100`,r.textContent=this._getTitle();let i=document.createElement(`mint-text`);i.setAttribute(`size`,`small`),i.setAttribute(`variant`,`muted`),i.className=`truncate`,i.textContent=this._getSubtitle(),n.appendChild(r),n.appendChild(i),this._trigger.appendChild(t),this._trigger.appendChild(n),this._popover=document.createElement(`mint-popover`),this._popover.setAttribute(`trigger-id`,this._triggerId),this._popover.setAttribute(`direction`,`right`),this._popover.setAttribute(`padding`,`0`);let a=document.createElement(`div`);a.className=`w-64`,e.length>0?e.forEach(e=>{e.setAttribute(`hidden`,`true`);let t=e.cloneNode(!0);t.removeAttribute(`hidden`),t.removeAttribute(`slot`),a.appendChild(t)}):a.appendChild(this._createDefaultGroup()),this._popover.appendChild(a),this._wrapper.appendChild(this._trigger),this._wrapper.appendChild(this._popover)}};customElements.get(`mint-sidenav-action-menu`)||customElements.define(`mint-sidenav-action-menu`,V);var H=`mint:url-change`;function se(){if(window.__mintUrlChangePatched)return;window.__mintUrlChangePatched=!0;let e=()=>{window.dispatchEvent(new Event(H))},t=t=>{let n=history[t].bind(history);history[t]=((...t)=>{let r=n(...t);return e(),r})};t(`pushState`),t(`replaceState`)}var U=class extends HTMLElement{constructor(...e){super(...e),this._backdrop=null,this._container=null,this._header=null,this._content=null,this._footer=null,this._escapeHandler=null,this._mediaQuery=null,this._mediaListener=null,this._accordionHandler=null,this._urlChangeHandler=null,this._contentObserver=null,this._renderFrame=null,this._onMobileNavNavigateClick=e=>{if(this._mediaQuery?.matches)return;let t=e.target;if(!(t instanceof Element))return;let n=t.closest(`a[href]`);if(!(n instanceof HTMLAnchorElement)||!this._container?.contains(n))return;let r=n.getAttribute(`href`);!r||r===`#`||r.trim().toLowerCase().startsWith(`javascript:`)||this._isOpen()&&this.removeAttribute(`open`)}}static get observedAttributes(){return[`user-name`,`user-status`,`open`,`drawer-top-class`]}connectedCallback(){this.classList.add(`relative`,`block`,`shrink-0`,`w-0`,`overflow-visible`,`min-[1100px]:w-[17rem]`,`min-[1100px]:shrink-0`),this._attachEscapeListener(),this._attachMediaListener(),this._attachAccordionListener(),this._attachUrlChangeListener(),this._observeContentMutations(),this.render()}disconnectedCallback(){this._detachEscapeListener(),this._detachMediaListener(),this._detachAccordionListener(),this._detachUrlChangeListener(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_attachEscapeListener(){this._escapeHandler||(this._escapeHandler=e=>{e.key===`Escape`&&this.getAttribute(`open`)===`true`&&this.removeAttribute(`open`)},document.addEventListener(`keydown`,this._escapeHandler))}_detachEscapeListener(){this._escapeHandler&&=(document.removeEventListener(`keydown`,this._escapeHandler),null)}_attachMediaListener(){this._mediaListener||(this._mediaQuery=window.matchMedia(`(min-width: 1100px)`),this._mediaListener=()=>{this._mediaQuery?.matches&&this.removeAttribute(`open`)},this._mediaQuery.addEventListener(`change`,this._mediaListener))}_detachMediaListener(){this._mediaQuery&&this._mediaListener&&this._mediaQuery.removeEventListener(`change`,this._mediaListener),this._mediaQuery=null,this._mediaListener=null}_attachAccordionListener(){this._accordionHandler||(this._accordionHandler=e=>{let t=e.detail?.source;!(t instanceof HTMLElement)||t.tagName!==`MINT-SIDENAV-LINK`||this.contains(t)&&this.querySelectorAll(`mint-sidenav-link`).forEach(e=>{e!==t&&e.querySelector(`:scope .mint-sidenav-submenu`)&&e.setAttribute(`expanded`,`false`)})},this.addEventListener(`mint-sidenav-accordion`,this._accordionHandler))}_detachAccordionListener(){this._accordionHandler&&=(this.removeEventListener(`mint-sidenav-accordion`,this._accordionHandler),null)}_attachUrlChangeListener(){this._urlChangeHandler||(se(),this._urlChangeHandler=()=>{this._mediaQuery?.matches||this._isOpen()&&this.removeAttribute(`open`)},window.addEventListener(`popstate`,this._urlChangeHandler),window.addEventListener(`hashchange`,this._urlChangeHandler),window.addEventListener(H,this._urlChangeHandler))}_detachUrlChangeListener(){this._urlChangeHandler&&=(window.removeEventListener(`popstate`,this._urlChangeHandler),window.removeEventListener(`hashchange`,this._urlChangeHandler),window.removeEventListener(H,this._urlChangeHandler),null)}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}getUserName(){return this.getAttribute(`user-name`)||`Acme Inc`}getUserStatus(){return this.getAttribute(`user-status`)||`Enterprise`}_isOpen(){return this.getAttribute(`open`)===`true`}_ensureBackdrop(){this._backdrop||(this._backdrop=document.createElement(`div`),this._backdrop.setAttribute(`aria-hidden`,`true`),this._backdrop.addEventListener(`click`,()=>this.removeAttribute(`open`)),this.insertBefore(this._backdrop,this.firstChild))}_ensureContainer(){this._container||(this._container=document.createElement(`aside`),this._container.addEventListener(`click`,this._onMobileNavNavigateClick,!0),this.appendChild(this._container))}_syncShell(){let e=`max-[1099.98px]:top-14`,t=this._isOpen();if(this._backdrop&&(this._backdrop.className=[`fixed`,e,`left-0`,`right-0`,`bottom-0`,`z-40`,`bg-black/50`,`transition-opacity`,`duration-200`,`min-[1100px]:hidden`,t?`pointer-events-auto opacity-100`:`pointer-events-none opacity-0`].join(` `)),this._container){let n=t?`max-[1099.98px]:translate-x-0`:`max-[1099.98px]:-translate-x-full`;this._container.className=[`flex`,`min-h-0`,`flex-col`,`border-r`,`border-gray-200`,`bg-white`,`p-2`,`dark:border-mint-divider`,`dark:bg-mint-nav`,`w-[4.75rem]`,`max-[1099.98px]:fixed`,e,`max-[1099.98px]:bottom-0`,`max-[1099.98px]:left-0`,`max-[1099.98px]:z-50`,`max-[1099.98px]:h-auto`,`max-[1099.98px]:w-[17rem]`,`max-[1099.98px]:max-w-[85vw]`,`max-[1099.98px]:shadow-xl`,`max-[1099.98px]:transition-transform`,`max-[1099.98px]:duration-200`,`max-[1099.98px]:ease-out`,n,`min-[1100px]:fixed`,`min-[1100px]:left-0`,`min-[1100px]:top-14`,`min-[1100px]:bottom-0`,`min-[1100px]:z-[60]`,`min-[1100px]:w-[17rem]`,`min-[1100px]:p-3`,`min-[1100px]:shadow-none`].join(` `)}}_buildUserHeader(){if(!this._container)return;this._header||(this._header=document.createElement(`div`),this._header.className=`mb-4`,this._container.appendChild(this._header));let e=Array.from(this.querySelectorAll(`[slot="action-header"]`)).find(e=>e!==this._backdrop&&e!==this._container);if(e){this._header.replaceChildren(e);return}let t=document.createElement(`mint-sidenav-action-menu`);t.setAttribute(`title`,this.getUserName()),t.setAttribute(`subtitle`,this.getUserStatus()),this._header.replaceChildren(t)}_replaceSlottedChildren(e,t){let n=Array.from(this.querySelectorAll(`[slot="${t}"]`)).filter(e=>e!==this._container&&e!==this._backdrop);e.replaceChildren(...n)}_buildContent(){this._container&&(this._content||(this._content=document.createElement(`div`),this._content.className=`min-h-0 grow overflow-y-auto`,this._container.appendChild(this._content)),this._replaceSlottedChildren(this._content,`links`))}_buildFooter(){if(!this._container)return;this._footer||(this._footer=document.createElement(`div`),this._footer.className=`mt-auto border-t border-gray-200 py-3 dark:border-mint-divider`,this._container.appendChild(this._footer));let e=document.createElement(`div`);e.className=`space-y-1`,this._replaceSlottedChildren(e,`bottom-links`),this._footer.innerHTML=``,this._footer.appendChild(e)}render(){this._ensureBackdrop(),this._ensureContainer(),this._syncShell(),this._buildUserHeader(),this._buildContent(),this._buildFooter()}};customElements.get(`mint-side-navigation`)||customElements.define(`mint-side-navigation`,U);var W=class extends HTMLElement{constructor(...e){super(...e),this._bar=null,this._menuButton=null,this._logoLink=null,this._menuClickHandler=null,this._darkModeObserver=null,this._contentObserver=null,this._resizeHandler=null,this._desktopSearchInput=null,this._desktopSearchShell=null,this._mobileSearchButton=null,this._searchPanel=null,this._searchPanelInput=null,this._searchResultsWrap=null,this._searchStateWrap=null,this._searchDebounceId=null,this._searchAbortController=null,this._searchOpen=!1,this._searchQuery=``,this._globalKeydownHandler=null,this._docClickHandler=null,this._renderFrame=null}static get observedAttributes(){return[`logo-src`,`logo-src-light`,`logo-src-dark`,`logo-src-mobile`,`logo-src-mobile-light`,`logo-src-mobile-dark`,`logo-href`,`logo-alt`,`menu-target`,`search-endpoint`,`search-param`,`search-placeholder`]}connectedCallback(){this.classList.add(`relative`,`block`,`h-14`,`w-full`,`shrink-0`),this._observeDarkMode(),this._observeContentMutations(),this._attachResizeListener(),this._attachGlobalHandlers(),this.render()}disconnectedCallback(){this._menuButton&&this._menuClickHandler&&(this._menuButton.removeEventListener(`click`,this._menuClickHandler),this._menuClickHandler=null),this._disconnectDarkModeObserver(),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null),this._detachResizeListener(),this._detachGlobalHandlers(),this._cancelSearchDebounce(),this._abortSearch()}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_isDarkMode(){return document.documentElement.classList.contains(`dark`)}_isMobileViewport(){return window.matchMedia(`(max-width: 1099.98px)`).matches}_getLogoSrc(){let e=this.getAttribute(`logo-src`)||``,t=this.getAttribute(`logo-src-light`)||``,n=this.getAttribute(`logo-src-dark`)||``,r=this.getAttribute(`logo-src-mobile`)||``,i=this.getAttribute(`logo-src-mobile-light`)||``,a=this.getAttribute(`logo-src-mobile-dark`)||``,o=this._isDarkMode(),s=this._isMobileViewport();return s&&o?a||r||n||t||e:s&&!o?i||r||t||n||e:o?n||t||e:t||n||e}_getLogoHref(){return this.getAttribute(`logo-href`)||`/`}_getLogoAlt(){return this.getAttribute(`logo-alt`)||`Home`}_getMenuTargetId(){return(this.getAttribute(`menu-target`)||``).replace(/^#/,``)}_getSearchEndpoint(){return(this.getAttribute(`search-endpoint`)||``).trim()}_getSearchParam(){return(this.getAttribute(`search-param`)||`q`).trim()||`q`}_getSearchPlaceholder(){return this.getAttribute(`search-placeholder`)||`Search`}_isSearchEnabled(){return!!this._getSearchEndpoint()}_attachGlobalHandlers(){this._globalKeydownHandler||(this._globalKeydownHandler=e=>{let t=e.key.toLowerCase();if((e.metaKey||e.ctrlKey)&&t===`k`){e.preventDefault(),this._openSearch(!0);return}t===`escape`&&this._searchOpen&&this._closeSearch()},document.addEventListener(`keydown`,this._globalKeydownHandler)),this._docClickHandler||(this._docClickHandler=e=>{if(!this._searchOpen)return;let t=e.target;t&&(this.contains(t)||this._closeSearch())},document.addEventListener(`click`,this._docClickHandler))}_detachGlobalHandlers(){this._globalKeydownHandler&&=(document.removeEventListener(`keydown`,this._globalKeydownHandler),null),this._docClickHandler&&=(document.removeEventListener(`click`,this._docClickHandler),null)}_cancelSearchDebounce(){this._searchDebounceId!==null&&(window.clearTimeout(this._searchDebounceId),this._searchDebounceId=null)}_abortSearch(){this._searchAbortController&&=(this._searchAbortController.abort(),null)}_openSearch(e=!1){if(this._isSearchEnabled()&&(this._searchOpen=!0,this._syncSearchPanelVisibility(),e)){let e=this._isMobileViewport()?this._searchPanelInput:this._desktopSearchInput;e?.focus(),e?.select()}}_closeSearch(){this._searchOpen=!1,this._syncSearchPanelVisibility()}_syncSearchPanelVisibility(){this._searchPanel&&(this._searchPanel.classList.toggle(`hidden`,!this._searchOpen),this._syncDesktopSearchOpenState(),this._positionSearchPanel())}_syncDesktopSearchOpenState(){this._desktopSearchShell&&(this._desktopSearchShell.classList.toggle(`rounded-b-none`,this._searchOpen),this._desktopSearchShell.classList.toggle(`border-b-transparent`,this._searchOpen))}_positionSearchPanel(){if(!this._searchPanel)return;if(this._isMobileViewport()||!this._desktopSearchShell){this._searchPanel.style.left=``,this._searchPanel.style.right=``,this._searchPanel.style.top=``,this._searchPanel.style.width=``,this._searchPanel.style.maxWidth=``,this._searchPanel.style.transform=``;return}let e=this._desktopSearchShell.getBoundingClientRect();this._searchPanel.style.left=`${e.left}px`,this._searchPanel.style.right=`auto`,this._searchPanel.style.top=`${e.bottom-1}px`,this._searchPanel.style.width=`${e.width}px`,this._searchPanel.style.maxWidth=`${e.width}px`,this._searchPanel.style.transform=`none`}_setSearchQuery(e){this._searchQuery=e,this._desktopSearchInput&&this._desktopSearchInput.value!==e&&(this._desktopSearchInput.value=e),this._searchPanelInput&&this._searchPanelInput.value!==e&&(this._searchPanelInput.value=e)}_normalizeResults(e){return(e=>{if(Array.isArray(e))return e;if(!e||typeof e!=`object`)return[];let t=e;for(let e of[`results`,`items`,`data`,`products`]){let n=t[e];if(Array.isArray(n))return n}return[]})(e).map(e=>{let t=e||{};return{title:String(t.title||t.name||t.label||t.email||t.id||``).trim()||`Untitled`,subtitle:String(t.description||t.category||t.username||``).trim()}}).slice(0,8)}_renderSearchState(e){this._searchStateWrap&&(this._searchStateWrap.textContent=e,this._searchStateWrap.classList.remove(`hidden`),this._searchResultsWrap&&(this._searchResultsWrap.innerHTML=``))}_renderSearchResults(e){if(!(!this._searchResultsWrap||!this._searchStateWrap)){if(this._searchResultsWrap.innerHTML=``,e.length===0){this._renderSearchState(`No results found`);return}this._searchStateWrap.classList.add(`hidden`);for(let t of e){let e=document.createElement(`button`);e.type=`button`,e.className=`flex w-full cursor-pointer items-start gap-3 rounded-lg px-3 py-2 text-left hover:bg-gray-100 dark:hover:bg-white/10`;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`mt-0.5 h-4 w-4 text-gray-500 dark:text-gray-400`;let r=document.createElement(`div`);r.className=`min-w-0`;let i=document.createElement(`div`);if(i.className=`truncate text-sm font-semibold text-gray-900 dark:text-gray-100`,i.textContent=t.title,r.appendChild(i),t.subtitle){let e=document.createElement(`div`);e.className=`truncate text-xs text-gray-500 dark:text-gray-400`,e.textContent=t.subtitle,r.appendChild(e)}e.appendChild(n),e.appendChild(r),e.addEventListener(`click`,()=>{this.dispatchEvent(new CustomEvent(`search-select`,{detail:{query:this._searchQuery,result:t},bubbles:!0,composed:!0})),this._closeSearch()}),this._searchResultsWrap.appendChild(e)}}}_fetchSearchResults(e){let t=this._getSearchEndpoint();if(!t)return;let n=e.trim();if(!n){this._renderSearchState(`Start typing to search`);return}this._abortSearch(),this._searchAbortController=new AbortController,this._renderSearchState(`Searching...`);let r=t.includes(`{query}`)?t.replace(`{query}`,encodeURIComponent(n)):`${t}${t.includes(`?`)?`&`:`?`}${encodeURIComponent(this._getSearchParam())}=${encodeURIComponent(n)}`;fetch(r,{signal:this._searchAbortController.signal}).then(e=>{if(!e.ok)throw Error(`Request failed: ${e.status}`);return e.json()}).then(e=>{let t=this._normalizeResults(e);this._renderSearchResults(t)}).catch(e=>{e?.name!==`AbortError`&&this._renderSearchState(`Unable to load results`)})}_scheduleSearch(e){this._setSearchQuery(e),this._cancelSearchDebounce(),this._searchDebounceId=window.setTimeout(()=>this._fetchSearchResults(e),220)}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>this.render()),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}))}_disconnectDarkModeObserver(){this._darkModeObserver&&=(this._darkModeObserver.disconnect(),null)}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_attachResizeListener(){this._resizeHandler||(this._resizeHandler=()=>{this.render(),this._positionSearchPanel()},window.addEventListener(`resize`,this._resizeHandler,{passive:!0}))}_detachResizeListener(){this._resizeHandler&&=(window.removeEventListener(`resize`,this._resizeHandler),null)}_toggleMenuTarget(){let e=this._getMenuTargetId();if(!e)return;let t=document.getElementById(e);!t||t.tagName!==`MINT-SIDE-NAVIGATION`||(t.getAttribute(`open`)===`true`?t.removeAttribute(`open`):t.setAttribute(`open`,`true`))}render(){if(this._bar||(this._bar=document.createElement(`div`),this._bar.className=`fixed inset-x-0 top-0 z-50 flex h-14 w-full items-center gap-2 border-b border-gray-200 bg-white px-3 dark:border-mint-divider dark:bg-mint-nav`,this.appendChild(this._bar)),!this._menuButton){this._menuButton=document.createElement(`button`),this._menuButton.type=`button`,this._menuButton.className=`inline-flex h-10 w-10 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-transparent text-gray-700 hover:bg-black/5 min-[1100px]:hidden dark:text-gray-200 dark:hover:bg-white/10`,this._menuButton.setAttribute(`aria-label`,`Open navigation menu`);let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`menu`),e.className=`h-5 w-5`,this._menuButton.appendChild(e),this._menuClickHandler=()=>this._toggleMenuTarget(),this._menuButton.addEventListener(`click`,this._menuClickHandler),this._bar.appendChild(this._menuButton)}let e=!!this._getMenuTargetId();this._menuButton.classList.toggle(`hidden`,!e),this._logoLink||(this._logoLink=document.createElement(`a`),this._logoLink.className=`flex h-8 w-40 shrink-0 items-center`,this._bar.appendChild(this._logoLink)),this._logoLink.href=this._getLogoHref(),this._logoLink.setAttribute(`aria-label`,this._getLogoAlt());let t=this._getLogoSrc();if(t){let e=document.createElement(`img`);e.className=`h-full w-full object-contain [aspect-ratio:5/1]`,e.decoding=`async`,e.src=t,e.alt=this._getLogoAlt(),this._logoLink.replaceChildren(e),this._logoLink.classList.remove(`pointer-events-none`,`opacity-40`)}else{this._logoLink.replaceChildren(),this._logoLink.classList.add(`pointer-events-none`,`opacity-40`);let e=document.createElement(`span`);e.className=`text-sm font-semibold text-gray-400 dark:text-gray-500`,e.textContent=`Logo`,this._logoLink.appendChild(e)}let n=Array.from(this.querySelectorAll(`[slot="center"]`)),r=n.length>0,i=this._isSearchEnabled()&&!r,a=this._bar.querySelector(`[data-mint-topnav-center]`);if(a||(a=document.createElement(`div`),a.setAttribute(`data-mint-topnav-center`,`true`),this._bar.appendChild(a)),a.className=r?`min-w-0 flex-1 px-2 min-[1100px]:flex min-[1100px]:justify-center min-[1100px]:px-4`:`max-[1099.98px]:hidden min-[1100px]:flex min-[1100px]:min-w-0 min-[1100px]:flex-1 min-[1100px]:justify-center min-[1100px]:px-4`,a.classList.toggle(`min-[1100px]:hidden`,!i&&!r),r&&(a.replaceChildren(...n),this._closeSearch()),i&&!this._desktopSearchInput){let e=document.createElement(`div`);e.className=`relative w-full max-w-xl rounded-xl border border-gray-300 bg-gray-50 px-3 py-2 dark:border-mint-divider dark:bg-mint-hover`,this._desktopSearchShell=e;let t=document.createElement(`mint-icon`);t.setAttribute(`name`,`search`),t.className=`absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500 dark:text-gray-400`,this._desktopSearchInput=document.createElement(`input`),this._desktopSearchInput.type=`search`,this._desktopSearchInput.className=`w-full bg-transparent pl-6 pr-20 text-sm text-gray-900 outline-none placeholder:text-gray-500 dark:text-gray-100 dark:placeholder:text-gray-400`,this._desktopSearchInput.placeholder=this._getSearchPlaceholder(),this._desktopSearchInput.addEventListener(`focus`,()=>this._openSearch(!1)),this._desktopSearchInput.addEventListener(`input`,e=>this._scheduleSearch(e.target.value));let n=document.createElement(`span`);n.className=`absolute right-3 top-1/2 -translate-y-1/2 text-xs text-gray-500 dark:text-gray-400`,n.textContent=`⌘K`,e.appendChild(t),e.appendChild(this._desktopSearchInput),e.appendChild(n),a.appendChild(e)}i&&this._desktopSearchInput&&(this._desktopSearchInput.placeholder=this._getSearchPlaceholder(),this._desktopSearchShell=this._desktopSearchInput.closest(`div`),this._syncDesktopSearchOpenState());let o=this._bar.querySelector(`[data-mint-topnav-mobile-spacer]`);o||(o=document.createElement(`div`),o.setAttribute(`data-mint-topnav-mobile-spacer`,`true`),o.className=`min-w-0 flex-1 min-[1100px]:hidden`,this._bar.appendChild(o));let s=Array.from(this.querySelectorAll(`[slot="actions"]`)),c=this._bar.querySelector(`[data-mint-topnav-actions]`);if(c||(c=document.createElement(`div`),c.setAttribute(`data-mint-topnav-actions`,`true`),c.className=`flex shrink-0 items-center gap-2`,this._bar.appendChild(c)),i&&!this._mobileSearchButton){this._mobileSearchButton=document.createElement(`button`),this._mobileSearchButton.type=`button`,this._mobileSearchButton.className=`inline-flex h-10 w-10 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-transparent text-gray-700 hover:bg-black/5 min-[1100px]:hidden dark:text-gray-200 dark:hover:bg-white/10`,this._mobileSearchButton.setAttribute(`aria-label`,`Open search`);let e=document.createElement(`mint-icon`);e.setAttribute(`name`,`search`),e.className=`h-5 w-5`,this._mobileSearchButton.appendChild(e),this._mobileSearchButton.addEventListener(`click`,()=>this._openSearch(!0)),c.insertBefore(this._mobileSearchButton,c.firstChild)}if(this._mobileSearchButton&&this._mobileSearchButton.classList.toggle(`hidden`,!i),c.replaceChildren(...s),i&&this._mobileSearchButton&&!s.includes(this._mobileSearchButton)&&c.insertBefore(this._mobileSearchButton,c.firstChild),i&&!this._searchPanel){this._searchPanel=document.createElement(`div`),this._searchPanel.className=`fixed left-0 right-0 top-14 z-[90] hidden p-3 min-[1100px]:p-0`;let e=document.createElement(`div`);e.className=`mx-auto w-full rounded-2xl border border-gray-200 bg-white shadow-xl dark:border-mint-divider dark:bg-mint-elevated min-[1100px]:rounded-t-none`;let t=document.createElement(`div`);t.className=`relative border-b border-gray-200 p-3 dark:border-mint-divider min-[1100px]:hidden`;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`absolute left-6 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500 dark:text-gray-400`,this._searchPanelInput=document.createElement(`input`),this._searchPanelInput.type=`search`,this._searchPanelInput.className=`w-full rounded-lg border border-gray-300 bg-gray-50 py-2 pl-10 pr-3 text-sm text-gray-900 outline-none dark:border-mint-divider dark:bg-mint-hover dark:text-gray-100`,this._searchPanelInput.placeholder=this._getSearchPlaceholder(),this._searchPanelInput.addEventListener(`input`,e=>this._scheduleSearch(e.target.value)),t.appendChild(n),t.appendChild(this._searchPanelInput);let r=document.createElement(`div`);r.className=`flex flex-wrap gap-2 px-3 py-3`,[`Apps`,`Customers`,`Orders`,`Products`,`Sales channels`].forEach(e=>{let t=document.createElement(`span`);t.className=`rounded-full bg-gray-100 px-3 py-1 text-xs font-semibold text-gray-600 dark:bg-mint-hover dark:text-gray-300`,t.textContent=e,r.appendChild(t)}),this._searchStateWrap=document.createElement(`div`),this._searchStateWrap.className=`px-4 pb-4 text-sm text-gray-500 dark:text-gray-400`,this._searchStateWrap.textContent=`Start typing to search`,this._searchResultsWrap=document.createElement(`div`),this._searchResultsWrap.className=`max-h-[52vh] overflow-y-auto px-2 pb-2`,e.appendChild(t),e.appendChild(r),e.appendChild(this._searchStateWrap),e.appendChild(this._searchResultsWrap),this._searchPanel.appendChild(e),this.appendChild(this._searchPanel)}this._searchPanelInput&&(this._searchPanelInput.placeholder=this._getSearchPlaceholder()),this._syncSearchPanelVisibility(),this._positionSearchPanel()}};customElements.get(`mint-top-navigation`)||customElements.define(`mint-top-navigation`,W);var G=class e extends HTMLElement{constructor(...e){super(...e),this._shell=null,this._desktopInput=null,this._panel=null,this._panelInner=null,this._panelInput=null,this._panelFiltersWrap=null,this._panelFiltersMainRow=null,this._panelFiltersChips=null,this._panelFiltersShowAllWrap=null,this._panelFiltersShowAllBtn=null,this._panelFiltersMorePanel=null,this._filtersMoreOpen=!1,this._filterOverflowObserver=null,this._filterOverflowZeroWidthRetries=0,this._desktopFilterWrap=null,this._mobileFilterWrap=null,this._resultsWrap=null,this._stateWrap=null,this._customResultsWrap=null,this._query=``,this._searchOpen=!1,this._selectedFilters=[],this._selectedFilterBackspaceArmed=!1,this._debounceId=null,this._abortController=null,this._docPointerDownHandler=null,this._globalKeydownHandler=null,this._focusOutHandler=null,this._resizeHandler=null,this._desktopShortcutHint=null,this._panelSearchBar=null,this._contentObserver=null,this._renderFrame=null}static{this._filterMorePanelSeq=0}static{this._filterChipsOverflowMask=`linear-gradient(to right, #000 0%, #000 max(0%, calc(100% - 3.5rem)), transparent 100%)`}static get observedAttributes(){return[`endpoint`,`search-param`,`placeholder`,`filters`,`filter-param`,`open-shortcut`,`open-shortcut-hint`,`collapse-on-mobile`]}connectedCallback(){this.classList.add(`relative`,`block`,`w-full`,`max-w-xl`),this._attachGlobalHandlers(),this._attachFocusOutHandler(),this._attachResizeHandler(),this.render(),this._observeContentMutations()}disconnectedCallback(){this._docPointerDownHandler&&=(document.removeEventListener(`pointerdown`,this._docPointerDownHandler,!0),null),this._globalKeydownHandler&&=(document.removeEventListener(`keydown`,this._globalKeydownHandler),null),this._resizeHandler&&=(window.removeEventListener(`resize`,this._resizeHandler),null),this._focusOutHandler&&=(this.removeEventListener(`focusout`,this._focusOutHandler,!0),null),this._cancelDebounce(),this._abortSearch(),this._filterOverflowObserver&&=(this._filterOverflowObserver.disconnect(),null),this._contentObserver&&=(this._contentObserver.disconnect(),null),this._renderFrame!==null&&(cancelAnimationFrame(this._renderFrame),this._renderFrame=null)}attributeChangedCallback(e,t,n){t!==n&&this.render()}_scheduleRender(){this._renderFrame===null&&(this._renderFrame=requestAnimationFrame(()=>{this._renderFrame=null,this.render()}))}_observeContentMutations(){this._contentObserver||=new MutationObserver(()=>{this._scheduleRender()}),this._contentObserver.disconnect(),this._contentObserver.observe(this,{childList:!0,attributes:!0,attributeFilter:[`slot`]})}_getEndpoint(){return(this.getAttribute(`endpoint`)||``).trim()}_getSearchParam(){return(this.getAttribute(`search-param`)||`q`).trim()||`q`}_getPlaceholder(){return this.getAttribute(`placeholder`)||`Search`}_getFilterParam(){return(this.getAttribute(`filter-param`)||``).trim()}_getFilterOptions(){return(this.getAttribute(`filters`)||``).split(`,`).map(e=>e.trim()).filter(Boolean)}_hasSelectedFilters(){return this._selectedFilters.length>0}_getFilterChipOverflowReservePx(){let e=Math.max(1,this._getFilterOptions().length),t=this._hasSelectedFilters()?28:56;return Math.min(200,t+e*34)}_getFilterParamValue(){return this._selectedFilters.join(`,`)}_getFilterChipLabelText(){return this._selectedFilters.join(`, `)}_getCondensedFilterChipLabel(e=22){if(!this._hasSelectedFilters())return``;let[t=``]=this._selectedFilters,n=this._selectedFilters.length-1,r=Math.max(8,e-2),i=t;if(n<=0)return i.length<=r?i:`${i.slice(0,Math.max(1,r-3))}...`;let a=`${t}, and ${n} more`;return a.length<=r?a:`${a.slice(0,Math.max(1,r-3))}...`}_isMobileViewport(){return window.matchMedia(`(max-width: 1099.98px)`).matches}_collapseOnMobile(){let e=this.getAttribute(`collapse-on-mobile`);if(e===null)return!1;let t=e.trim().toLowerCase();return!(t===`false`||t===`0`||t===`off`||t===`none`)}_primarySearchInput(){return this._isMobileViewport()&&this._collapseOnMobile()?this._panelInput:this._desktopInput}_isApplePlatform(){return typeof navigator>`u`?!1:/Mac|iPhone|iPad|iPod/i.test(navigator.platform)||/Mac OS/i.test(navigator.userAgent)}_parseOpenShortcut(){let e=(this.getAttribute(`open-shortcut`)??`mod+k`).trim().toLowerCase();if(!e||e===`none`||e===`false`||e===`off`)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let t=e.split(`+`).map(e=>e.trim()).filter(Boolean);if(t.length===0)return{disabled:!0,wantMod:!1,wantMeta:!1,wantCtrl:!1,wantAlt:!1,wantShift:!1,key:``};let n=t[t.length-1],r=new Set(t.slice(0,-1).map(e=>e.toLowerCase()));return{disabled:!1,wantMod:r.has(`mod`),wantMeta:r.has(`meta`)||r.has(`cmd`)||r.has(`super`),wantCtrl:r.has(`ctrl`)||r.has(`control`),wantAlt:r.has(`alt`),wantShift:r.has(`shift`),key:n.toLowerCase()}}_eventKeyMatchesShortcutKey(e,t){let n=t.toLowerCase();return(e.key.length,e.key.toLowerCase())===n}_openShortcutMatches(e){let t=this._parseOpenShortcut();return t.disabled||!t.key||e.repeat||!this._eventKeyMatchesShortcutKey(e,t.key)||t.wantShift!==e.shiftKey||t.wantAlt!==e.altKey?!1:t.wantMod||t.wantMeta||t.wantCtrl?!(t.wantMod&&!(e.metaKey||e.ctrlKey)||t.wantMeta&&!e.metaKey||t.wantCtrl&&!e.ctrlKey):!!t.wantAlt}_getOpenShortcutHintText(){let e=this.getAttribute(`open-shortcut-hint`);if(e===`none`||e===`false`)return``;if(e!==null&&e.trim()!==``)return e.trim();let t=this._parseOpenShortcut();if(t.disabled)return``;let n=this._isApplePlatform(),r=[];t.wantMod&&r.push(n?`⌘`:`Ctrl`),t.wantMeta&&!t.wantMod&&r.push(n?`⌘`:`Meta`),t.wantCtrl&&!t.wantMod&&r.push(`Ctrl`),t.wantAlt&&r.push(`Alt`),t.wantShift&&r.push(`Shift`);let i=t.key.length===1?t.key.toUpperCase():t.key;return i?t.wantMod&&!t.wantMeta&&!t.wantCtrl&&!t.wantAlt&&!t.wantShift&&t.key.length===1?`${n?`⌘`:`Ctrl+`}${i}`:[...r,i].join(`+`):``}_attachGlobalHandlers(){this._globalKeydownHandler||(this._globalKeydownHandler=e=>{if(this._openShortcutMatches(e)){e.preventDefault(),this._openSearch(!0);return}if(e.key.toLowerCase()===`escape`&&this._searchOpen){if(this._filtersMoreOpen){this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput());return}this._closeSearch()}},document.addEventListener(`keydown`,this._globalKeydownHandler)),this._docPointerDownHandler||(this._docPointerDownHandler=e=>{if(!this._searchOpen)return;let t=e.composedPath();this._filtersMoreOpen&&this._panelFiltersWrap&&!t.includes(this._panelFiltersWrap)&&(this._filtersMoreOpen=!1,this.render(),requestAnimationFrame(()=>this._focusActiveInput())),!(this._shell&&t.includes(this._shell)||this._panelInner&&t.includes(this._panelInner))&&this._closeSearch()},document.addEventListener(`pointerdown`,this._docPointerDownHandler,!0))}_attachResizeHandler(){this._resizeHandler||(this._resizeHandler=()=>{this._syncPanelVisibility(),this._syncFilterOverflow()},window.addEventListener(`resize`,this._resizeHandler,{passive:!0}))}_attachFocusOutHandler(){this._focusOutHandler||(this._focusOutHandler=e=>{if(!this._searchOpen)return;let t=e.relatedTarget;t&&(this._shell&&this._shell.contains(t)||this._panelInner&&this._panelInner.contains(t)||this._closeSearch())},this.addEventListener(`focusout`,this._focusOutHandler,!0))}_emitSearchOpenChange(){this.dispatchEvent(new CustomEvent(`search-open-change`,{detail:{open:this._searchOpen},bubbles:!0,composed:!0}))}_openSearch(e=!1){this._getEndpoint()&&(this._searchOpen||(this._searchOpen=!0,this._syncPanelVisibility(),this._emitSearchOpenChange(),e&&this._primarySearchInput()?.focus()))}_closeSearch(){this._searchOpen&&(this._searchOpen=!1,this._filtersMoreOpen=!1,this._syncPanelVisibility(),this._emitSearchOpenChange())}_syncPanelVisibility(){if(!this._panel)return;let e=this._panelLayoutBaseClass();this._panel.className=this._searchOpen?e:`${e} hidden`,this._shell&&(this._shell.classList.toggle(`rounded-b-none`,this._searchOpen),this._shell.classList.toggle(`border-b-transparent`,this._searchOpen)),this._positionPanel(),this._searchOpen&&this._scheduleFilterOverflowSync()}_panelLayoutBaseClass(){return!this._isMobileViewport()||!this._collapseOnMobile()?`absolute left-0 right-0 top-full z-[90] p-0 -mt-[9px]`:`fixed left-0 right-0 top-12 z-[90] p-3`}_positionPanel(){this._panel&&(!this._isMobileViewport()||!this._collapseOnMobile())&&(this._panel.style.left=``,this._panel.style.right=``,this._panel.style.top=``,this._panel.style.width=``,this._panel.style.maxWidth=``,this._panel.style.transform=``)}_setQuery(e){let t=this._query;this._query=e,e!==t&&(this._selectedFilterBackspaceArmed=!1),this._desktopInput&&(this._desktopInput.value=e),this._panelInput&&(this._panelInput.value=e)}_cancelDebounce(){this._debounceId!==null&&(window.clearTimeout(this._debounceId),this._debounceId=null)}_abortSearch(){this._abortController&&=(this._abortController.abort(),null)}_normalizeResults(e){return(e=>{if(Array.isArray(e))return e;if(!e||typeof e!=`object`)return[];let t=e;for(let e of[`results`,`items`,`data`,`products`]){let n=t[e];if(Array.isArray(n))return n}return[]})(e).map(e=>{let t=e||{};return{title:String(t.title||t.name||t.label||t.email||t.id||``).trim()||`Untitled`,subtitle:String(t.description||t.category||t.username||``).trim(),parent:String(t.parent||t.type||t.entity||t.kind||t.category||``).trim()||void 0}}).slice(0,8)}_emitResultsChange(e,t){let n=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-results-change`,{detail:{query:this._query,filter:n,filters:[...this._selectedFilters],results:e,raw:t??null},bubbles:!0,composed:!0}))}_emitFilterChange(){let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-filter-change`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters]},bubbles:!0,composed:!0}))}_renderState(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`hidden`);return}this._stateWrap&&(this._stateWrap.textContent=e,this._stateWrap.classList.remove(`hidden`),this._resultsWrap&&(this._resultsWrap.classList.remove(`hidden`),this._resultsWrap.innerHTML=``))}_renderResults(e){if(this._customResultsWrap&&this._customResultsWrap.childElementCount>0){this._stateWrap&&this._stateWrap.classList.add(`hidden`),this._resultsWrap&&this._resultsWrap.classList.add(`hidden`);return}if(!(!this._resultsWrap||!this._stateWrap)){if(this._resultsWrap.innerHTML=``,e.length===0){this._renderState(`No results found`);return}this._stateWrap.classList.add(`hidden`);for(let t of e){let e=document.createElement(`button`);e.type=`button`,e.className=`flex w-full cursor-pointer items-start gap-3 rounded-lg px-3 py-2 text-left hover:bg-gray-100 dark:hover:bg-white/10`;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`search`),n.className=`mt-0.5 h-4 w-4 text-gray-500 dark:text-gray-400`;let r=document.createElement(`div`);r.className=`min-w-0`;let i=document.createElement(`div`);if(i.className=`truncate text-sm font-semibold text-gray-900 dark:text-gray-100`,i.textContent=t.title,r.appendChild(i),t.subtitle){let e=document.createElement(`div`);e.className=`truncate text-xs text-gray-500 dark:text-gray-400`,e.textContent=t.subtitle,r.appendChild(e)}e.appendChild(n),e.appendChild(r),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){t.preventDefault(),this._moveFocusInResults(e,1);return}if(t.key===`ArrowUp`){t.preventDefault(),this._moveFocusInResults(e,-1);return}}),e.addEventListener(`click`,()=>{let e=this._hasSelectedFilters()?this._getFilterParamValue():null;this.dispatchEvent(new CustomEvent(`search-select`,{detail:{query:this._query,filter:e,filters:[...this._selectedFilters],result:t},bubbles:!0,composed:!0})),this._closeSearch()}),this._resultsWrap.appendChild(e)}}}_fetchSearchResults(e){let t=this._getEndpoint();if(!t)return;let n=e.trim();if(!n){this._emitResultsChange([]),this._renderState(`Start typing to search`);return}this._abortSearch(),this._abortController=new AbortController,this._renderState(`Searching...`);let r=new URLSearchParams;r.set(this._getSearchParam(),n);let i=this._getFilterParam();i&&this._hasSelectedFilters()&&r.set(i,this._getFilterParamValue());let a=t.includes(`{query}`)?t.replace(`{query}`,encodeURIComponent(n)):`${t}${t.includes(`?`)?`&`:`?`}${r.toString()}`;fetch(a,{signal:this._abortController.signal}).then(e=>{if(!e.ok)throw Error(`Request failed: ${e.status}`);return e.json()}).then(e=>{let t=this._normalizeResults(e);this._emitResultsChange(t,e),this._renderResults(t)}).catch(e=>{e?.name!==`AbortError`&&(this._emitResultsChange([]),this._renderState(`Unable to load results`))})}_scheduleSearch(e){this._setQuery(e),this._cancelDebounce(),this._debounceId=window.setTimeout(()=>this._fetchSearchResults(e),220)}_getNativeInputValue(e){if(!e)return``;let t=e.querySelector(`input, textarea`);return t?t.value||``:e.value||``}_getCurrentInputValue(){let e=document.activeElement;return e&&this._desktopInput&&this._desktopInput.contains(e)?this._getNativeInputValue(this._desktopInput):e&&this._panelInput&&this._panelInput.contains(e)?this._getNativeInputValue(this._panelInput):this._getNativeInputValue(this._primarySearchInput())}_applyFilterSelectionChange(){let e=this._getCurrentInputValue();if(this._setQuery(e),this._emitFilterChange(),this.render(),e.trim()){this._scheduleSearch(e);return}this._cancelDebounce(),this._abortSearch(),this._emitResultsChange([]),this._renderState(`Start typing to search`)}_clearAllSelectedFilters(){this._selectedFilters=[],this._selectedFilterBackspaceArmed=!1,this._applyFilterSelectionChange()}_popLastSelectedFilter(){this._selectedFilters.length!==0&&(this._selectedFilters.pop(),this._selectedFilterBackspaceArmed=!1,this._applyFilterSelectionChange())}_focusActiveInput(){let e=this._primarySearchInput();e&&requestAnimationFrame(()=>{e.focus()})}_focusHideFiltersControl(){let e=this._panelFiltersShowAllBtn;e&&(e.querySelector(`button`)??e).focus()}_getFilterChipElements(){return this._panelFiltersWrap?Array.from(this._panelFiltersWrap.querySelectorAll(`mint-chip`)):[]}_ensurePanelFiltersShell(){!this._panelFiltersWrap||this._panelFiltersMainRow||(this._panelFiltersWrap.replaceChildren(),this._panelFiltersWrap.className=`relative flex shrink-0 flex-col gap-2 px-3 pb-3 pt-5 min-w-0`,this._panelFiltersMainRow=document.createElement(`div`),this._panelFiltersMainRow.className=`flex min-w-0 w-full flex-nowrap items-center gap-2`,this._panelFiltersChips=document.createElement(`div`),this._panelFiltersChips.className=`flex min-w-0 flex-1 flex-nowrap items-center gap-2 overflow-x-hidden`,this._panelFiltersMorePanel=document.createElement(`div`),this._panelFiltersMorePanel.id=`mint-search-filter-more-${e._filterMorePanelSeq++}`,this._panelFiltersMorePanel.className=`hidden absolute left-0 right-0 top-full z-[95] mt-1 flex max-h-[40vh] flex-wrap gap-2 overflow-y-auto rounded-lg border border-gray-200 bg-white p-2 shadow-lg dark:border-mint-divider dark:bg-mint-elevated`,this._panelFiltersShowAllWrap=document.createElement(`div`),this._panelFiltersShowAllWrap.className=`relative flex min-h-0 min-w-0 shrink-0 items-center hidden`,this._panelFiltersShowAllBtn=document.createElement(`mint-button`),this._panelFiltersShowAllBtn.setAttribute(`type`,`button`),this._panelFiltersShowAllBtn.setAttribute(`variant`,`ghost`),this._panelFiltersShowAllBtn.setAttribute(`tone`,`neutral`),this._panelFiltersShowAllBtn.setAttribute(`size`,`small`),this._panelFiltersShowAllBtn.classList.add(`shrink-0`,`whitespace-nowrap`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,`false`),this._panelFiltersShowAllBtn.setAttribute(`aria-controls`,this._panelFiltersMorePanel.id),this._panelFiltersShowAllBtn.addEventListener(`click`,e=>{e.stopPropagation();let t=this._filtersMoreOpen;this._filtersMoreOpen=!this._filtersMoreOpen,this.render(),t&&requestAnimationFrame(()=>this._focusActiveInput())}),this._panelFiltersShowAllWrap.append(this._panelFiltersShowAllBtn),this._panelFiltersMainRow.append(this._panelFiltersChips,this._panelFiltersShowAllWrap),this._setPanelFiltersShowAllLabel(`Show all`),this._panelFiltersWrap.append(this._panelFiltersMainRow,this._panelFiltersMorePanel),typeof ResizeObserver<`u`&&!this._filterOverflowObserver&&(this._filterOverflowObserver=new ResizeObserver(()=>this._syncFilterOverflow()),this._filterOverflowObserver.observe(this._panelFiltersChips),this._filterOverflowObserver.observe(this._panelFiltersMainRow)))}_setPanelFiltersShowAllLabel(e){let t=this._panelFiltersShowAllBtn;if(!t)return;for(let e of Array.from(t.childNodes))e.nodeType===Node.TEXT_NODE&&e.remove();let n=t.querySelector(`button .mint-button-content`)||t.querySelector(`.mint-button-content`);if(n){n.textContent=e;return}let r=t.querySelector(`:scope > button`);if(r){r.replaceChildren(document.createTextNode(e)),t.render?.();return}t.firstElementChild||t.appendChild(document.createTextNode(e))}_scheduleFilterOverflowSync(){requestAnimationFrame(()=>{requestAnimationFrame(()=>this._syncFilterOverflow())})}_setFilterChipsEdgeFade(t){let n=this._panelFiltersChips;n&&(t?(n.style.maskImage=e._filterChipsOverflowMask,n.style.webkitMaskImage=e._filterChipsOverflowMask):(n.style.maskImage=``,n.style.webkitMaskImage=``))}_syncFilterOverflow(){if(!this._panelFiltersChips||!this._panelFiltersShowAllWrap||!this._panelFiltersShowAllBtn)return;if(this._filtersMoreOpen){this._panelFiltersShowAllWrap.classList.remove(`hidden`),this._filterOverflowZeroWidthRetries=0,this._setFilterChipsEdgeFade(!1);return}let e=this._panelFiltersChips.clientWidth;if(e===0&&this._searchOpen){this._filterOverflowZeroWidthRetries<10&&(this._filterOverflowZeroWidthRetries+=1,this._scheduleFilterOverflowSync()),this._setFilterChipsEdgeFade(!1);return}this._filterOverflowZeroWidthRetries=0;let t=this._panelFiltersChips.scrollWidth+this._getFilterChipOverflowReservePx()>e;this._panelFiltersShowAllWrap.classList.toggle(`hidden`,!t),this._setFilterChipsEdgeFade(t)}_getResultFocusableElements(){let e=this._customResultsWrap&&!this._customResultsWrap.classList.contains(`hidden`)?this._customResultsWrap:this._resultsWrap;return e?Array.from(e.querySelectorAll(`button:not([disabled]), [href], [tabindex]:not([tabindex="-1"]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])`)):[]}_focusFirstChipOrResult(e=!1){let t=this._getFilterChipElements(),n=this._getResultFocusableElements();if(!e){(t[0]||n[0])?.focus();return}(n[n.length-1]||t[t.length-1])?.focus()}_moveFocusInResults(e,t){let n=this._getResultFocusableElements();if(n.length===0)return;let r=n.indexOf(e);if(r===-1)return;let i=n[r+t];if(i){i.focus();return}if(t===-1){let e=this._getFilterChipElements(),t=e[e.length-1];t?t.focus():this._focusActiveInput()}}_renderSelectedFilter(){let e=e=>{if(!e||(e.innerHTML=``,!this._hasSelectedFilters()))return;let t=document.createElement(`mint-chip`);t.setAttribute(`dismissable`,``),t.title=this._getFilterChipLabelText();let n=this._getCondensedFilterChipLabel();t.classList.add(`max-w-[min(20rem,85vw)]`,`whitespace-nowrap`,`overflow-hidden`,`text-ellipsis`,`text-xs`,`px-2`,`py-0.5`),t.style.fontSize=`0.75rem`,t.style.padding=`0.125rem 0.375rem`,t.style.height=`1.375rem`,t.style.lineHeight=`1`,t.style.whiteSpace=`nowrap`,t.style.overflow=`hidden`,t.style.textOverflow=`ellipsis`,this._selectedFilterBackspaceArmed&&t.classList.add(`ring-2`,`ring-brand-400`,`dark:ring-brand-300`),t.textContent=n,t.addEventListener(`dismiss`,e=>{e.stopPropagation(),this._clearAllSelectedFilters()}),e.appendChild(t)};e(this._desktopFilterWrap),e(this._mobileFilterWrap)}_bindInputHandlers(e){let t=()=>{this._scheduleSearch(this._getNativeInputValue(e))};e.addEventListener(`focusin`,()=>this._openSearch(!1)),e.addEventListener(`input`,t),e.addEventListener(`search`,t),e.addEventListener(`change`,t),e.addEventListener(`keydown`,t=>{if(t.key===`ArrowDown`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!1);return}if(t.key===`ArrowUp`){this._searchOpen||this._openSearch(!1),t.preventDefault(),this._focusFirstChipOrResult(!0);return}if(t.key===`Tab`&&!t.shiftKey&&this._searchOpen){let e=this._getFilterChipElements(),n=this._getResultFocusableElements();if(e.length>0||n.length>0){t.preventDefault(),this._focusFirstChipOrResult(!1);return}}if(t.key!==`Backspace`)return;let n=this._getNativeInputValue(e);if(n!==this._query&&this._setQuery(n),!(n.length>0)&&this._hasSelectedFilters()){if(!this._selectedFilterBackspaceArmed){t.preventDefault(),this._selectedFilterBackspaceArmed=!0,this._renderSelectedFilter();return}t.preventDefault(),this._popLastSelectedFilter()}})}openSearch(e=!0){this._openSearch(e)}closeSearch(){this._closeSearch()}toggleSearch(e=!0){if(this._searchOpen){this._closeSearch();return}this._openSearch(e)}isSearchOpen(){return this._searchOpen}render(){let e=this._getEndpoint();if(this.classList.toggle(`hidden`,!e),!e)return;if(!this._shell){this._shell=document.createElement(`div`),this._shell.className=`relative z-[91] flex h-10 w-full`,this._desktopFilterWrap=document.createElement(`div`),this._desktopFilterWrap.className=`inline-flex shrink-0 max-w-[8.5rem]`,this._desktopFilterWrap.setAttribute(`slot`,`prepend`),this._desktopInput=document.createElement(`mint-input`),this._desktopInput.setAttribute(`type`,`search`),this._desktopInput.setAttribute(`icon`,`search`),this._desktopInput.className=`h-full min-w-0 flex-1`;let e=document.createElement(`span`);e.className=`shrink-0 text-xs text-gray-500 dark:text-gray-400`,e.setAttribute(`slot`,`append`),this._desktopShortcutHint=e,this._bindInputHandlers(this._desktopInput),this._desktopInput.appendChild(this._desktopFilterWrap),this._desktopInput.appendChild(e),this._shell.appendChild(this._desktopInput),this.appendChild(this._shell)}if(!this._panel){this._panel=document.createElement(`div`),this._panel.className=`absolute left-0 right-0 top-full z-[90] hidden p-0 -mt-[9px]`;let e=document.createElement(`div`);e.className=`mx-auto flex max-h-[calc(100dvh-4rem)] w-full flex-col overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-xl dark:border-mint-divider dark:bg-mint-elevated min-[1100px]:rounded-t-none min-[1100px]:border-t-0`,this._panelInner=e;let t=document.createElement(`div`);this._panelSearchBar=t,t.className=`hidden`,this._mobileFilterWrap=document.createElement(`div`),this._mobileFilterWrap.className=`inline-flex shrink-0 max-w-[8.5rem]`,this._mobileFilterWrap.setAttribute(`slot`,`prepend`),this._panelInput=document.createElement(`mint-input`),this._panelInput.setAttribute(`type`,`search`),this._panelInput.className=`min-w-0 flex-1`,this._bindInputHandlers(this._panelInput),this._panelInput.appendChild(this._mobileFilterWrap),t.appendChild(this._panelInput),this._customResultsWrap=document.createElement(`div`),this._customResultsWrap.className=`min-h-0 flex-1 overflow-y-auto px-2 pb-2`,this._stateWrap=document.createElement(`div`),this._stateWrap.className=`px-4 pb-4 text-sm text-gray-500 dark:text-gray-400`,this._stateWrap.textContent=`Start typing to search`,this._resultsWrap=document.createElement(`div`),this._resultsWrap.className=`min-h-0 flex-1 overflow-y-auto px-2 pb-2`,e.appendChild(t),this._panelFiltersWrap=document.createElement(`div`),e.appendChild(this._panelFiltersWrap),this._ensurePanelFiltersShell(),e.appendChild(this._customResultsWrap),e.appendChild(this._stateWrap),e.appendChild(this._resultsWrap),this._panel.appendChild(e),this.appendChild(this._panel)}let t=this._hasSelectedFilters()?``:this._getPlaceholder();if(this._desktopInput&&this._desktopInput.setAttribute(`placeholder`,t),this._panelInput&&this._panelInput.setAttribute(`placeholder`,t),this._desktopShortcutHint){let e=this._getOpenShortcutHintText();this._desktopShortcutHint.textContent=e,this._desktopShortcutHint.classList.toggle(`hidden`,!e)}if(this._panelFiltersWrap){this._ensurePanelFiltersShell();let e=this._getFilterOptions();this._selectedFilters=this._selectedFilters.filter(t=>e.includes(t));let t=e.length>0;t||(this._filtersMoreOpen=!1),this._panelFiltersWrap.classList.toggle(`hidden`,!t),this._stateWrap?.classList.toggle(`pt-4`,!t),this._resultsWrap?.classList.toggle(`pt-4`,!t),this._customResultsWrap?.classList.toggle(`pt-5`,!t),this._panelFiltersChips&&this._panelFiltersChips.replaceChildren(),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.replaceChildren();let n=this._filtersMoreOpen&&this._panelFiltersMorePanel?this._panelFiltersMorePanel:this._panelFiltersChips;for(let t of e){if(!n)break;let r=document.createElement(`mint-chip`),i=this._selectedFilters.includes(t);if(i&&r.classList.add(`ring-2`,`ring-inset`,`ring-brand-400`,`dark:ring-brand-300`),r.classList.add(`cursor-pointer`,`focus-visible:outline-none`,`focus-visible:ring-2`,`focus-visible:ring-inset`,`focus-visible:ring-brand-400`,`inline-flex`,`items-center`,`gap-1`,`shrink-0`,`whitespace-nowrap`),i){let e=document.createElement(`span`);e.textContent=t;let n=document.createElement(`mint-icon`);n.setAttribute(`name`,`close`),n.className=`h-4 w-4 ml-2 shrink-0`,n.setAttribute(`aria-hidden`,`true`),r.append(e,n)}else r.textContent=t;r.tabIndex=0,r.setAttribute(`role`,`button`),r.setAttribute(`aria-label`,i?`Remove filter ${t}`:`Filter by ${t}`),r.dataset.mintSearchFilter=t,r.addEventListener(`pointerdown`,e=>{e.preventDefault()});let a=n=>{n&&n.stopPropagation();let r=this._filtersMoreOpen,i=this._selectedFilters.indexOf(t);i>=0?this._selectedFilters.splice(i,1):this._selectedFilters.push(t),this._selectedFilterBackspaceArmed=!1;let a=e.length>0&&this._selectedFilters.length===e.length,o=this._selectedFilters.length===0;r&&(a||o)&&(this._filtersMoreOpen=!1),this._emitFilterChange(),this._renderSelectedFilter(),this.render(),this._query.trim()&&this._scheduleSearch(this._query),r?a||o?this._focusActiveInput():requestAnimationFrame(()=>{this._getFilterChipElements().find(e=>e.dataset.mintSearchFilter===t)?.focus()}):this._focusActiveInput()};r.addEventListener(`click`,e=>a(e)),r.addEventListener(`keydown`,e=>{let t=this._getFilterChipElements(),n=t.indexOf(r);if(e.key===`Enter`||e.key===` `){e.preventDefault(),a(e);return}if(e.key===`ArrowRight`){e.preventDefault();let r=t[n+1];r&&r.focus();return}if(e.key===`ArrowLeft`){e.preventDefault();let r=t[n-1];r?r.focus():this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}if(e.key===`ArrowDown`){e.preventDefault(),this._getResultFocusableElements()[0]?.focus();return}if(e.key===`ArrowUp`){e.preventDefault(),this._filtersMoreOpen?this._focusHideFiltersControl():this._focusActiveInput();return}}),n.appendChild(r)}this._panelFiltersChips&&this._panelFiltersChips.classList.toggle(`hidden`,this._filtersMoreOpen),this._panelFiltersMorePanel&&this._panelFiltersMorePanel.classList.toggle(`hidden`,!this._filtersMoreOpen),this._panelFiltersShowAllBtn&&(this._setPanelFiltersShowAllLabel(this._filtersMoreOpen?`Hide filters`:`Show all`),this._panelFiltersShowAllBtn.setAttribute(`aria-expanded`,this._filtersMoreOpen?`true`:`false`)),this._panelInner&&(this._filtersMoreOpen&&t?(this._panelInner.classList.remove(`overflow-hidden`),this._panelInner.classList.add(`overflow-visible`)):(this._panelInner.classList.remove(`overflow-visible`),this._panelInner.classList.add(`overflow-hidden`))),this._scheduleFilterOverflowSync()}if(this._customResultsWrap){Array.from(this.children).filter(e=>e===this._shell||e===this._panel?!1:e.getAttribute(`slot`)===`results`).forEach(e=>this._customResultsWrap.appendChild(e));let e=this._customResultsWrap.childElementCount>0;this._customResultsWrap.classList.toggle(`hidden`,!e),e?(this._stateWrap?.classList.add(`hidden`),this._resultsWrap?.classList.add(`hidden`)):this._resultsWrap?.classList.remove(`hidden`)}this._renderSelectedFilter(),this._syncResponsiveChrome(),this._syncPanelVisibility()}_syncResponsiveChrome(){let e=this._collapseOnMobile();this._shell&&(this._shell.className=e?`relative z-[91] hidden h-10 w-full min-[1100px]:flex`:`relative z-[91] flex h-10 w-full`),this._panelSearchBar&&(this._panelSearchBar.className=e?`flex shrink-0 items-center gap-2 border-b border-gray-200 p-3 dark:border-mint-divider min-[1100px]:hidden`:`hidden`)}};customElements.get(`mint-search`)||customElements.define(`mint-search`,G);var K=class extends HTMLElement{constructor(...e){super(...e),this._lastScrollY=0,this._scrollHandler=null}connectedCallback(){this.classList.add(`fixed`,`bottom-0`,`left-0`,`right-0`,`z-30`,`flex`,`w-full`,`items-stretch`,`justify-around`,`gap-1`,`border-t`,`border-gray-200`,`bg-white`,`px-1`,`pt-1`,`pb-[env(safe-area-inset-bottom,0px)]`,`min-[1100px]:hidden`,`transition-transform`,`duration-200`,`ease-out`,`translate-y-0`,`dark:border-mint-divider`,`dark:bg-mint-nav`),this.setAttribute(`role`,`navigation`),this.setAttribute(`aria-label`,`Primary`),this._lastScrollY=window.scrollY,this._attachScrollListener()}disconnectedCallback(){this._detachScrollListener()}_attachScrollListener(){this._scrollHandler||(this._scrollHandler=()=>{let e=window.scrollY;if(e<=8){this.classList.remove(`translate-y-full`),this.classList.add(`translate-y-0`),this._lastScrollY=e;return}let t=e-this._lastScrollY;Math.abs(t)<4||(t>0?(this.classList.remove(`translate-y-0`),this.classList.add(`translate-y-full`)):(this.classList.remove(`translate-y-full`),this.classList.add(`translate-y-0`)),this._lastScrollY=e)},window.addEventListener(`scroll`,this._scrollHandler,{passive:!0}))}_detachScrollListener(){this._scrollHandler&&=(window.removeEventListener(`scroll`,this._scrollHandler),null)}};customElements.get(`mint-bottom-navigation`)||customElements.define(`mint-bottom-navigation`,K);var q=class extends HTMLElement{constructor(...e){super(...e),this._root=null}static get observedAttributes(){return[`icon`,`label`,`href`,`active`]}connectedCallback(){this.classList.add(`contents`),this.render()}attributeChangedCallback(e,t,n){t!==n&&this.render()}_isActive(){return this.getAttribute(`active`)===`true`}_getLabel(){return this.getAttribute(`label`)||``}_getIcon(){return this.getAttribute(`icon`)||``}_getHref(){return this.getAttribute(`href`)}render(){let e=this._getHref(),t=this._getLabel(),n=this._getIcon(),r=this._isActive(),i=r?`text-gray-900 dark:text-gray-100`:`text-gray-600 hover:bg-black/5 dark:text-gray-300 dark:hover:bg-white/10`,a;e?(a=document.createElement(`a`),a.href=e):(a=document.createElement(`button`),a.type=`button`),a.className=`flex min-w-0 flex-1 flex-col items-center justify-center gap-1 rounded-lg px-1 py-2 text-center text-[11px] font-medium leading-tight ${i}`,a.setAttribute(`aria-current`,r?`page`:`false`),a.setAttribute(`aria-label`,t||`Navigation item`);let o=document.createElement(`span`);if(o.className=`inline-flex h-6 w-6 items-center justify-center`,n){let e=document.createElement(`mint-icon`);e.setAttribute(`name`,n),e.className=r?`h-6 w-6`:`h-6 w-6 opacity-90`,o.appendChild(e)}let s=document.createElement(`span`);s.className=`block w-full truncate`,s.textContent=t,a.appendChild(o),a.appendChild(s),this.replaceChildren(a),this._root=a}};customElements.get(`mint-bottom-nav-item`)||customElements.define(`mint-bottom-nav-item`,q);var ce=class extends HTMLElement{constructor(...e){super(...e),this._messageEl=null,this._hideTimer=null,this._hideResolve=null,this._bottomNavObserver=null,this._bodyObserver=null}static get observedAttributes(){return[`open`,`message`]}connectedCallback(){this.classList.add(`pointer-events-none`,`fixed`,`left-1/2`,`-translate-x-1/2`,`min-[1100px]:bottom-4`,`z-40`,`transition-all`,`duration-200`,`ease-out`,`opacity-0`,`translate-y-2`),this._updateBottomOffset(),this._setupBottomNavObservers(),this.setAttribute(`aria-live`,`polite`),this.setAttribute(`aria-atomic`,`true`),this.render()}disconnectedCallback(){this._clearHideTimer(),this._disconnectBottomNavObservers(),this._hideResolve=null}attributeChangedCallback(e,t,n){t!==n&&(e===`open`||e===`message`)&&this.render()}async showToast(e,t=2200){let n=e.trim().slice(0,120);n&&(this._updateBottomOffset(),this._clearHideTimer(),this._hideResolve=null,this.setAttribute(`message`,n),this.setAttribute(`open`,`true`),this.render(),await new Promise(e=>{this._hideResolve=e,this._hideTimer=window.setTimeout(()=>{this.hideToast()},t)}))}hideToast(e=!1){this.removeAttribute(`open`),this.render(),this._clearHideTimer();let t=this._hideResolve;this._hideResolve=null,t&&(e?t():window.setTimeout(t,200))}_clearHideTimer(){this._hideTimer!==null&&(window.clearTimeout(this._hideTimer),this._hideTimer=null)}_updateBottomOffset(){let e=this._hasVisibleBottomNav();this.classList.remove(`bottom-[calc(env(safe-area-inset-bottom,0px)+4.5rem)]`,`bottom-[calc(env(safe-area-inset-bottom,0px)+1rem)]`),this.classList.add(e?`bottom-[calc(env(safe-area-inset-bottom,0px)+4.5rem)]`:`bottom-[calc(env(safe-area-inset-bottom,0px)+1rem)]`)}_hasVisibleBottomNav(){let e=document.querySelector(`mint-bottom-navigation`);if(!e)return!1;let t=window.getComputedStyle(e);return!(t.display===`none`||t.visibility===`hidden`||e.classList.contains(`translate-y-full`))}_setupBottomNavObservers(){this._disconnectBottomNavObservers();let e=()=>{this._bottomNavObserver&&=(this._bottomNavObserver.disconnect(),null);let e=document.querySelector(`mint-bottom-navigation`);if(!e){this._updateBottomOffset();return}this._bottomNavObserver=new MutationObserver(()=>{this._updateBottomOffset()}),this._bottomNavObserver.observe(e,{attributes:!0,attributeFilter:[`class`,`style`]}),this._updateBottomOffset()};this._bodyObserver=new MutationObserver(()=>{e()}),this._bodyObserver.observe(document.body,{childList:!0,subtree:!0}),e()}_disconnectBottomNavObservers(){this._bottomNavObserver&&=(this._bottomNavObserver.disconnect(),null),this._bodyObserver&&=(this._bodyObserver.disconnect(),null)}render(){let e=this.getAttribute(`open`)===`true`,t=this.getAttribute(`message`)||``;this.classList.toggle(`opacity-100`,e),this.classList.toggle(`translate-y-0`,e),this.classList.toggle(`opacity-0`,!e),this.classList.toggle(`translate-y-2`,!e),this._messageEl||=(this.innerHTML=`<div class="rounded-md bg-[#202223] px-4 py-2 text-sm font-medium text-white shadow-[0_8px_24px_rgba(0,0,0,0.25)] min-[1100px]:px-5 min-[1100px]:py-3 min-[1100px]:text-base dark:bg-[#0f1113]">
|
|
134
138
|
<span data-mint-toast-message></span>
|
|
135
|
-
</div>`,this.querySelector(`[data-mint-toast-message]`)),this._messageEl&&(this._messageEl.textContent=t)}};customElements.get(`mint-toast`)||customElements.define(`mint-toast`,
|
|
139
|
+
</div>`,this.querySelector(`[data-mint-toast-message]`)),this._messageEl&&(this._messageEl.textContent=t)}};customElements.get(`mint-toast`)||customElements.define(`mint-toast`,ce);var le=class extends HTMLElement{constructor(...e){super(...e),this._modal=null,this._confirmButton=null,this._cancelButton=null,this._pendingResolve=null,this._modalObserver=null,this._lastAction=null,this._onConfirmClick=null,this._onCancelClick=null}connectedCallback(){this._ensureModal(),this._observeModalOpenState()}disconnectedCallback(){this._modalObserver&&=(this._modalObserver.disconnect(),null),this._pendingResolve=null}async showConfirm(e){if(this._ensureModal(),!this._modal||!this._confirmButton||!this._cancelButton)return!1;let t=e.question?.trim()||`Are you sure?`,n=e.tone||`action`,r=e.confirmLabel?.trim()||`Confirm`,i=e.cancelLabel?.trim()||`Cancel`;this._lastAction=null,this._modal.setAttribute(`heading`,t),this._cancelButton.setAttribute(`variant`,`ghost`),this._cancelButton.removeAttribute(`tone`),this._confirmButton.setAttribute(`variant`,`solid`),this._confirmButton.setAttribute(`tone`,n),this._confirmButton.textContent=r,this._cancelButton.textContent=i,typeof this._confirmButton.render==`function`&&this._confirmButton.render(),typeof this._cancelButton.render==`function`&&this._cancelButton.render();let a=new Promise(e=>{this._pendingResolve=e});return requestAnimationFrame(()=>{this._modal.open?.()}),a}_ensureModal(){if(this._modal)return;this._modal=document.createElement(`mint-modal`),this._modal.setAttribute(`heading`,`Are you sure?`),this._modal.setAttribute(`size`,`small`);let e=document.createElement(`div`);e.setAttribute(`slot`,`actions`);let t=document.createElement(`div`);t.className=`flex items-center gap-2 w-full justify-end`,this._cancelButton=document.createElement(`mint-button`),this._cancelButton.setAttribute(`variant`,`ghost`),this._cancelButton.textContent=`Cancel`,this._confirmButton=document.createElement(`mint-button`),this._confirmButton.setAttribute(`variant`,`solid`),this._confirmButton.setAttribute(`tone`,`action`),this._confirmButton.textContent=`Confirm`,this._onCancelClick=()=>{this._lastAction=`cancel`,this._modal?.close?.()},this._onConfirmClick=()=>{this._lastAction=`confirm`,this._modal?.close?.()},this._cancelButton.addEventListener(`click`,this._onCancelClick),this._confirmButton.addEventListener(`click`,this._onConfirmClick),t.appendChild(this._cancelButton),t.appendChild(this._confirmButton),e.appendChild(t),this._modal.appendChild(e),this.appendChild(this._modal)}_observeModalOpenState(){!this._modal||this._modalObserver||(this._modalObserver=new MutationObserver(()=>{if(this._modal?.getAttribute(`open`)===`true`||!this._pendingResolve)return;let e=this._pendingResolve;this._pendingResolve=null;let t=this._lastAction===`confirm`;this._lastAction=null,e(t)}),this._modalObserver.observe(this._modal,{attributes:!0,attributeFilter:[`open`]}))}};customElements.get(`mint-confirm-action`)||customElements.define(`mint-confirm-action`,le);var ue=2200,J=[],Y=!1,X=null;function de(){return typeof document>`u`||document.body?Promise.resolve():new Promise(e=>{if(typeof window>`u`){e();return}window.addEventListener(`DOMContentLoaded`,()=>{e()},{once:!0})})}async function fe(){if(await de(),typeof document>`u`)throw Error(`mintui.toast is only available in browser environments.`);let e=document.querySelector(`mint-toast[data-mint-toast-root="true"]`);if(e)return e;let t=document.createElement(`mint-toast`);return t.setAttribute(`data-mint-toast-root`,`true`),document.body.appendChild(t),t}async function pe(){if(!Y){Y=!0;try{for(;J.length>0;){let e=J.shift();if(!e)continue;let t=e.message.trim().slice(0,120);if(!t)continue;let n=await fe();X=n;let r=e.options?.duration??ue;await n.showToast(t,r)}}finally{Y=!1,X=null}}}function Z(e,t){typeof window>`u`||(J.push({message:e,options:t}),Y&&X&&X.hideToast(),pe())}var me={toast:Z};if(typeof window<`u`){let e=window.mintui||{};e.toast=Z,window.mintui=e}var Q=[],$=!1;function he(){return typeof document>`u`||document.body?Promise.resolve():new Promise(e=>{if(typeof window>`u`){e();return}window.addEventListener(`DOMContentLoaded`,()=>e(),{once:!0})})}async function ge(){if(await he(),typeof document>`u`)throw Error(`mintui.confirm is only available in browser environments.`);let e=document.querySelector(`mint-confirm-action[data-mint-confirm-action-root="true"]`);if(e)return e;let t=document.createElement(`mint-confirm-action`);return t.setAttribute(`data-mint-confirm-action-root`,`true`),document.body.appendChild(t),t}function _e(e){let t=(e||`action`).toString().trim().toLowerCase().replace(/^tone:\s*/,``);return t===`action`||t===`info`||t===`warning`||t===`danger`?t:`action`}async function ve(){if(!$){$=!0;try{for(;Q.length>0;){let e=Q.shift();e&&(await(await ge()).showConfirm({question:e.question,tone:_e(e.tone),confirmLabel:e.confirmLabel||`Confirm`,cancelLabel:e.cancelLabel||`Cancel`})?e.confirmed?.():e.cancelled?.())}}finally{$=!1}}}function ye(e,t,n,r=`action`,i=`Confirm`,a=`Cancel`){typeof window>`u`||(Q.push({question:e,confirmed:t,cancelled:n,tone:r,confirmLabel:i,cancelLabel:a}),ve())}if(typeof window<`u`){let e=window.mintui||{};e.confirm=ye,window.mintui=e}exports.Alert=M,exports.BackButton=p,exports.BottomNavItem=q,exports.BottomNavigation=K,exports.Button=r,exports.default=r,exports.Card=d,exports.Chart=L,exports.Checkbox=y,exports.Chip=A,exports.Choice=x,exports.Clickable=ee,exports.Collapsible=v,exports.ConfirmAction=le,exports.DatePicker=C,exports.Dropzone=D,exports.Form=O,exports.Grid=h,exports.Icon=n,exports.Input=S,exports.Link=f,exports.Modal=g,exports.OffCanvas=oe,exports.Page=m,exports.Popover=_,exports.ResourceTable=te,exports.Search=G,exports.Select=E,exports.SideNavigation=U,exports.SideNavigationActionLinks=B,exports.SideNavigationActionMenu=V,exports.SideNavigationLink=R,exports.SideNavigationLinks=z,exports.Sortable=u,exports.Spinner=t,exports.Stack=o,exports.Switch=i,exports.Tab=N,exports.TabContent=F,exports.TabList=P,exports.Table=k,exports.Tabs=I,exports.Tags=j,exports.Text=a,exports.TimePicker=w,exports.Toast=ce,exports.TopNavigation=W,exports.confirm=ye,exports.mintui=me,exports.toast=Z;
|