monobill-mintui 0.3.62 → 0.3.63
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/chart/Chart.d.ts +70 -7
- package/dist/components/chart/Chart.d.ts.map +1 -1
- package/dist/index.cjs +18 -18
- package/dist/index.js +788 -713
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
<path d="${t.path}" />
|
|
52
52
|
</svg>`:e=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${t.viewBox}" fill="none" stroke="currentColor" stroke-width="${t.strokeWidth||"2"}" stroke-linecap="${t.strokeLinecap||"round"}" stroke-linejoin="${t.strokeLinejoin||"round"}">
|
|
53
53
|
<path d="${t.path}" />
|
|
54
|
-
</svg>`,e}render(){var o,c,h;const t=this.getName();if(!t){this.innerHTML="",this.style.maskImage="",this.style.webkitMaskImage="",this.style.backgroundColor="";return}const e=It.getIcon(t);if(!e){console.warn(`Icon "${t}" not found. Make sure you've imported the icon: import '@monobill-mintui/icon/icons/${t}'`),this.innerHTML="",this.style.maskImage="",this.style.webkitMaskImage="",this.style.backgroundColor="";return}const i=this.closest("mint-button")||((o=this.parentElement)==null?void 0:o.closest("mint-button")),s=this.closest("mint-switch")||((c=this.parentElement)==null?void 0:c.closest("mint-switch")),n=this.closest("mint-select")||((h=this.parentElement)==null?void 0:h.closest("mint-select"));if(!Array.from(this.classList).some(
|
|
54
|
+
</svg>`,e}render(){var o,c,h;const t=this.getName();if(!t){this.innerHTML="",this.style.maskImage="",this.style.webkitMaskImage="",this.style.backgroundColor="";return}const e=It.getIcon(t);if(!e){console.warn(`Icon "${t}" not found. Make sure you've imported the icon: import '@monobill-mintui/icon/icons/${t}'`),this.innerHTML="",this.style.maskImage="",this.style.webkitMaskImage="",this.style.backgroundColor="";return}const i=this.closest("mint-button")||((o=this.parentElement)==null?void 0:o.closest("mint-button")),s=this.closest("mint-switch")||((c=this.parentElement)==null?void 0:c.closest("mint-switch")),n=this.closest("mint-select")||((h=this.parentElement)==null?void 0:h.closest("mint-select"));if(!Array.from(this.classList).some(f=>f.startsWith("w-")||f.startsWith("h-"))&&!n){let f;s?f="w-3 h-3":i?f="w-5 h-5":f="w-[1.3em] h-[1.3em]",this.classList.remove("w-4","h-4","w-5","h-5","w-[1em]","h-[1em]","w-[1.3em]","h-[1.3em]","w-3","h-3"),f.split(" ").forEach(d=>{d&&this.classList.add(d)})}const a=this.generateSVGMarkup(e);this.innerHTML=a,this.style.maskImage="",this.style.webkitMaskImage="",this.style.maskSize="",this.style.webkitMaskSize="",this.style.maskRepeat="",this.style.webkitMaskRepeat="",this.style.maskPosition="",this.style.webkitMaskPosition="",this.style.backgroundColor="",this.style.aspectRatio="1 / 1";const l=this.querySelector("svg");if(l&&(l.style.width="100%",l.style.height="100%"),s)this.classList.remove("text-gray-100","text-gray-900"),this.classList.add("text-gray-900");else if(i)this.classList.remove("text-gray-100","text-gray-900");else{const d=document.documentElement.classList.contains("dark")?"text-gray-100":"text-gray-900";this.classList.remove("text-gray-100","text-gray-900"),this.classList.add(d)}}}customElements.get("mint-icon")||customElements.define("mint-icon",rt);const J=class J extends HTMLElement{constructor(){super(),this._button=null,this._clickHandler=null,this._isHandlingClick=!1,this._handleMouseDown=()=>{this._button&&!this.isDisabled()&&!this.isLoading()&&this._button.classList.add("mint-button-active")},this._handleMouseUp=()=>{this._button&&(this.isActive()||this._button.classList.remove("mint-button-active"))},this._handleMouseLeave=()=>{this._button&&(this.isActive()||this._button.classList.remove("mint-button-active"))},this._handleTouchStart=()=>{this._button&&!this.isDisabled()&&!this.isLoading()&&this._button.classList.add("mint-button-active")},this._handleTouchEnd=()=>{this._button&&(this.isActive()||this._button.classList.remove("mint-button-active"))},this._handleTouchCancel=()=>{this._button&&(this.isActive()||this._button.classList.remove("mint-button-active"))}}static get observedAttributes(){return["variant","tone","disabled","loading","button-type","type","full-width","icon-position","icon","active"]}connectedCallback(){if(!J._activeShadowStyleInjected){const t=document.createElement("style");t.textContent=`
|
|
55
55
|
mint-button .mint-button-active {
|
|
56
56
|
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3) !important;
|
|
57
57
|
}
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
mint-button[data-variant="link"] .mint-button-active {
|
|
63
63
|
box-shadow: none !important;
|
|
64
64
|
}
|
|
65
|
-
`,document.head.appendChild(t),J._activeShadowStyleInjected=!0}this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render(),this._button&&this.setupEventListeners(),this.isFullWidth()&&this.classList.add("w-full")}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getVariant(){return this.getAttribute("variant")||"solid"}getTone(){return this.getAttribute("tone")||"neutral"}isDisabled(){return this.getAttribute("disabled")==="true"}isLoading(){return this.getAttribute("loading")==="true"}getType(){const t=this.getAttribute("type"),e=this.getAttribute("button-type");return(t||e||"default")==="submit"?"submit":"button"}isFullWidth(){return this.getAttribute("full-width")==="true"}isActive(){return this.getAttribute("active")==="true"}get active(){return this.isActive()}set active(t){t?this.setAttribute("active","true"):this.removeAttribute("active")}getIconPosition(){return this.getAttribute("icon-position")||"left"}getIcon(){return this.getAttribute("icon")||""}isIconOnly(){var i,s,n,r,a;if(!(this.getIcon()||((i=this._button)==null?void 0:i.querySelector('[slot="icon"], .mint-button-icon, mint-icon'))))return!1;const e=(s=this._button)==null?void 0:s.querySelector(".mint-button-content");if(e&&((n=e.textContent)!=null&&n.trim()))return!1;if(this._button)for(let l=this._button.firstChild;l;l=l.nextSibling){if(l.nodeType===Node.TEXT_NODE&&((r=l.textContent)!=null&&r.trim()))return!1;if(l.nodeType===Node.ELEMENT_NODE){const o=l;if(o.tagName!=="MINT-ICON"&&o.tagName!=="MINT-SPINNER"&&!o.querySelector("mint-spinner")&&!o.hasAttribute("slot")&&o.className!=="mint-button-icon"&&!(o.className==="mr-2"&&o.querySelector("mint-spinner"))&&(a=o.textContent)!=null&&a.trim())return!1}}return!0}getActiveStateClasses(){const t=this.getVariant(),e=this.getTone(),i=`${t}-${e}`;return{"solid-action":["!bg-slate-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-slate-700","hover:!bg-slate-900","dark:hover:!bg-slate-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"solid-neutral":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"solid-info":["!bg-blue-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-blue-700","hover:!bg-blue-900","dark:hover:!bg-blue-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"solid-warning":["!bg-amber-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-amber-700","hover:!bg-amber-900","dark:hover:!bg-amber-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"solid-danger":["!bg-red-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-red-700","hover:!bg-red-900","dark:hover:!bg-red-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"ghost-action":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"ghost-neutral":["!bg-gray-50","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","!text-gray-900","dark:!text-white","hover:!bg-gray-50","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","hover:!text-gray-900","dark:hover:!text-white"],"ghost-info":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"ghost-warning":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"ghost-danger":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"link-action":["!text-slate-900","dark:!text-slate-300","hover:!text-slate-900","dark:hover:!text-slate-300"],"link-neutral":["!text-gray-950","dark:!text-gray-200","hover:!text-gray-950","dark:hover:!text-gray-200"],"link-info":["!text-blue-900","dark:!text-blue-200","hover:!text-blue-900","dark:hover:!text-blue-200"],"link-warning":["!text-amber-900","dark:!text-amber-200","hover:!text-amber-900","dark:hover:!text-amber-200"],"link-danger":["!text-red-900","dark:!text-red-200","hover:!text-red-900","dark:hover:!text-red-200"]}[i]||[]}getButtonClasses(){const t=this.isIconOnly(),e=this.getVariant(),i=["inline-flex","items-center","justify-center","font-medium","rounded-lg","box-border",...t?["p-1.5","aspect-square","w-[2.25rem]","h-[2.25rem]"]:["px-3.5","py-1.5","min-h-[2.25rem]"],"text-sm","transition-all","duration-200","outline-none","focus:outline-none","focus-visible:ring-2","focus-visible:ring-offset-1","[&.mint-button-active>*]:scale-95","[&>*]:transition-transform","[&>*]:duration-100","disabled:opacity-50","disabled:cursor-not-allowed"],s=this.getTone(),n={"solid-action":["bg-slate-800","dark:bg-slate-600","text-white","hover:bg-slate-950","dark:hover:bg-slate-700","active:bg-slate-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-slate-700","disabled:active:bg-slate-800","dark:disabled:active:bg-slate-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"solid-neutral":["bg-white","dark:bg-gray-900","text-gray-900","dark:text-white","hover:bg-gray-50","dark:hover:bg-gray-800","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-white","dark:disabled:active:bg-gray-900","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-gray-200","dark:border-gray-700"],"solid-info":["bg-blue-800","dark:bg-blue-600","text-white","hover:bg-blue-950","dark:hover:bg-blue-700","active:bg-blue-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-blue-700","disabled:active:bg-blue-800","dark:disabled:active:bg-blue-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"solid-warning":["bg-amber-800","dark:bg-amber-600","text-white","hover:bg-amber-950","dark:hover:bg-amber-700","active:bg-amber-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-amber-700","disabled:active:bg-amber-800","dark:disabled:active:bg-amber-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"solid-danger":["bg-red-800","dark:bg-red-600","text-white","hover:bg-red-950","dark:hover:bg-red-700","active:bg-red-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-red-700","disabled:active:bg-red-800","dark:disabled:active:bg-red-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"ghost-action":["bg-transparent","text-slate-800","dark:text-slate-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-neutral":["bg-transparent","text-gray-700","dark:text-gray-200","active:bg-gray-50","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","active:text-gray-900","dark:active:text-white","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-info":["bg-transparent","text-blue-800","dark:text-blue-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-warning":["bg-transparent","text-amber-800","dark:text-amber-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-danger":["bg-transparent","text-red-800","dark:text-red-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-action":["bg-transparent","text-slate-800","dark:text-slate-400","hover:text-slate-950","dark:hover:text-slate-200","active:text-slate-900","dark:active:text-slate-300","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-neutral":["bg-transparent","text-gray-700","dark:text-gray-300","hover:text-gray-900","dark:hover:text-gray-100","active:text-gray-950","dark:active:text-gray-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-info":["bg-transparent","text-blue-800","dark:text-blue-400","hover:text-blue-950","dark:hover:text-blue-300","active:text-blue-900","dark:active:text-blue-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-warning":["bg-transparent","text-amber-800","dark:text-amber-400","hover:text-amber-950","dark:hover:text-amber-300","active:text-amber-900","dark:active:text-amber-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-danger":["bg-transparent","text-red-800","dark:text-red-400","hover:text-red-950","dark:hover:text-red-300","active:text-red-900","dark:active:text-red-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"]},r=`${e}-${s}`,a=n[r]||n["solid-neutral"],l=[...i,...a];if(this.isActive()){const o=this.getActiveStateClasses();l.push(...o),l.push("[&>*]:scale-95")}return this.isFullWidth()&&l.push("w-full"),l.join(" ")}render(){var h,p,d,u,f,_;const t=this.isDisabled()||this.isLoading(),e=this.getType();if(!this._button){for(this._button=document.createElement("button");this.firstChild;)this._button.appendChild(this.firstChild);this.appendChild(this._button),this.setupEventListeners()}this._button.type=e,this._button.disabled=t;let i=this._button.querySelector("mint-spinner");const s=this.isLoading();if(s)if(i)i.setAttribute("data-button-variant",this.getVariant()),i.setAttribute("data-button-tone",this.getTone()),"render"in i&&typeof i.render=="function"&&i.render();else{const g=document.createElement("span");g.className="mr-2 inline-flex items-center";const m=document.createElement("mint-spinner");m.setAttribute("size","default"),m.setAttribute("data-button-variant",this.getVariant()),m.setAttribute("data-button-tone",this.getTone()),m.style.width="0.875rem",m.style.height="0.875rem",g.appendChild(m),this._button.insertBefore(g,this._button.firstChild)}else i&&((h=i.parentElement)==null||h.remove());for(;this.firstChild&&this.firstChild!==this._button;)this._button.appendChild(this.firstChild);const n=this.getIcon();let r=this._button.querySelector('[slot="icon"], .mint-button-icon, mint-icon');n?(r&&r.tagName!=="MINT-ICON"&&(r.remove(),r=null),!r||r.tagName!=="MINT-ICON"?(r=document.createElement("mint-icon"),r.setAttribute("name",n),r.className="mint-button-icon"):r.setAttribute("name",n)):r&&r.tagName==="MINT-ICON"&&(r.remove(),r=null),r||(r=this._button.querySelector('[slot="icon"], .mint-button-icon'));const a=this.getIconPosition();let l=this._button.querySelector(".mint-button-content");if(l){const g=r&&r.tagName==="MINT-ICON";if(r&&!r.parentElement){const m=(u=this._button.querySelector("mint-spinner"))==null?void 0:u.parentElement;g||a==="left"?m?m.insertAdjacentElement("afterend",r):this._button.insertBefore(r,l):l.insertAdjacentElement("afterend",r)}else if(r&&(g||a==="left")&&r.nextSibling!==l){r.remove();const m=(f=this._button.querySelector("mint-spinner"))==null?void 0:f.parentElement;m?m.insertAdjacentElement("afterend",r):this._button.insertBefore(r,l)}else r&&!g&&a==="right"&&r.previousSibling!==l&&(r.remove(),l.insertAdjacentElement("afterend",r))}else{const g=[];for(let m=this._button.firstChild;m;m=m.nextSibling){if(m.nodeType!==Node.ELEMENT_NODE){g.push(m);continue}const v=m;v.tagName!=="MINT-SPINNER"&&!v.querySelector("mint-spinner")&&m!==r&&!v.hasAttribute("slot")&&!(v.className==="mr-2"&&v.querySelector("mint-spinner"))&&g.push(m)}if(g.length>0){l=document.createElement("span"),l.className="mint-button-content inline-flex items-center",g.forEach(v=>{l.appendChild(v)});const m=(p=this._button.querySelector("mint-spinner"))==null?void 0:p.parentElement;r&&a==="left"?m?(m.insertAdjacentElement("afterend",r),r.insertAdjacentElement("afterend",l)):(this._button.insertBefore(r,this._button.firstChild),r.insertAdjacentElement("afterend",l)):r&&a==="right"?m?(m.insertAdjacentElement("afterend",l),l.insertAdjacentElement("afterend",r)):(this._button.insertBefore(l,this._button.firstChild),l.insertAdjacentElement("afterend",r)):m?m.insertAdjacentElement("afterend",l):this._button.insertBefore(l,this._button.firstChild)}else if(r&&r.tagName==="MINT-ICON"&&!r.parentElement){const m=(d=this._button.querySelector("mint-spinner"))==null?void 0:d.parentElement;m?m.insertAdjacentElement("afterend",r):this._button.insertBefore(r,this._button.firstChild)}}const o=this.isIconOnly();if(r&&(r.classList.contains("mint-button-icon")||r.classList.add("mint-button-icon"),s?r.style.display="none":r.style.display="",r.classList.remove("mr-1.5","ml-1.5"),o?r.tagName==="MINT-ICON"?(r.style.width="1rem",r.style.height="1rem",r.style.maxWidth="1rem",r.style.maxHeight="1rem",r.style.flexShrink="0"):(r.style.maxWidth="1rem",r.style.maxHeight="1rem",r.style.flexShrink="0",r.tagName==="svg"&&(r.style.width="1rem",r.style.height="1rem")):a==="left"?r.classList.add("mr-1.5"):r.classList.add("ml-1.5")),s){const g=(_=this._button.querySelector("mint-spinner"))==null?void 0:_.parentElement;g&&(o?(g.classList.remove("mr-2"),g.classList.add("mr-0")):g.classList.contains("mr-2")||(g.classList.remove("mr-0"),g.classList.add("mr-2")))}const c=this.getButtonClasses();this._button.className=c,this.setAttribute("data-variant",this.getVariant()),this.setAttribute("data-tone",this.getTone()),this.isActive()?this._button.classList.add("mint-button-active"):this._button.classList.remove("mint-button-active")}setupEventListeners(){this._button&&!this._clickHandler&&(this._clickHandler=this.handleClick.bind(this),this._clickHandler&&this._button.addEventListener("click",this._clickHandler,!0),this._button.addEventListener("mousedown",this._handleMouseDown),this._button.addEventListener("mouseup",this._handleMouseUp),this._button.addEventListener("mouseleave",this._handleMouseLeave),this._button.addEventListener("touchstart",this._handleTouchStart),this._button.addEventListener("touchend",this._handleTouchEnd),this._button.addEventListener("touchcancel",this._handleTouchCancel))}removeEventListeners(){this._button&&(this._clickHandler&&(this._button.removeEventListener("click",this._clickHandler,!0),this._clickHandler=null),this._button.removeEventListener("mousedown",this._handleMouseDown),this._button.removeEventListener("mouseup",this._handleMouseUp),this._button.removeEventListener("mouseleave",this._handleMouseLeave),this._button.removeEventListener("touchstart",this._handleTouchStart),this._button.removeEventListener("touchend",this._handleTouchEnd),this._button.removeEventListener("touchcancel",this._handleTouchCancel))}handleClick(t){if(this.isDisabled()||this.isLoading()){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation();return}if(this.getType()==="submit"){this.dispatchEvent(new CustomEvent("click",{detail:{originalEvent:t},bubbles:!0,cancelable:!0,composed:!0}));return}if(t.stopPropagation(),t.stopImmediatePropagation(),this._isHandlingClick){t.preventDefault();return}this._isHandlingClick=!0,t.preventDefault(),this.dispatchEvent(new CustomEvent("click",{detail:{originalEvent:t},bubbles:!0,cancelable:!0,composed:!0})),requestAnimationFrame(()=>{this._isHandlingClick=!1})}};J._activeShadowStyleInjected=!1;let Z=J;customElements.get("mint-button")||customElements.define("mint-button",Z);class nt extends HTMLElement{constructor(){super(),this._button=null,this._checked=!1}static get observedAttributes(){return["checked","disabled","label","icon","info","error","error-message","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full");const t=this.getAttribute("checked");this._checked=t==="true",this.render()}_getSwitchContainer(){let t=this.querySelector(".mint-switch-container");return t||(t=document.createElement("div"),t.className="mint-switch-container flex items-center gap-2",this.insertBefore(t,this.firstChild)),t}disconnectedCallback(){this.removeEventListeners()}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(t==="checked"&&(this._checked=i==="true"),e!==i){if(t==="error"||t==="error-message"){this._renderErrorState();return}if(t==="loading"){this.render();return}this.render()}}get checked(){try{return this._checked||!1}catch{return!1}}set checked(t){try{t?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this._checked=!!t,this.render()}catch{}}isDisabled(){return this.getAttribute("disabled")==="true"}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getIcon(){return this.getAttribute("icon")||""}hasIcon(){return!!this.getIcon()}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getSwitchClasses(){const t=this.hasError(),e=["relative","inline-flex","items-center","rounded-full","h-5","w-10","border","transition-colors","duration-200","ease-in-out","outline-none","focus:outline-none","focus-visible:ring-2","focus-visible:ring-offset-1",t?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","disabled:opacity-50","disabled:cursor-not-allowed"],i=this._checked?["bg-slate-950","dark:bg-slate-600",t?"border-red-300 dark:border-red-300":"border-slate-700 dark:border-slate-500"]:["bg-slate-200","dark:bg-slate-400",t?"border-red-300 dark:border-red-300":"border-slate-300 dark:border-slate-500"];return[...e,...i].join(" ")}getThumbClasses(){const t=["relative","inline-block","rounded-full","bg-white","dark:bg-gray-50","h-4","w-4","shadow-lg","transform","transition-transform","duration-200","ease-in-out","pointer-events-none","overflow-hidden"],e=this._checked?"translate-x-5":"translate-x-0.5";return[...t,e].join(" ")}getIconClasses(){return["absolute","inset-0","flex","items-center","justify-center","pointer-events-none"].join(" ")}render(){const t=this.isLoading(),e=this.getSwitchClasses(),i=this.getThumbClasses(),s=this.getLabel(),n=this.getInfo(),r=this.getIcon(),a=this.getAttribute("id")||`mint-switch-${Math.random().toString(36).substr(2,9)}`;this.getAttribute("id")||this.setAttribute("id",a);const l=this._getSwitchContainer();this._button?this._button.parentElement!==l&&l.appendChild(this._button):(this._button=document.createElement("button"),l.appendChild(this._button),this.setupEventListeners());let o=l.querySelector(".mint-switch-label");s?(o||(o=document.createElement("label"),o.className="mint-switch-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",this._button&&this._button.parentElement===l?l.insertBefore(o,this._button.nextSibling):l.appendChild(o)),o.textContent=s,o.setAttribute("for",a),this.isDisabled()?o.classList.add("opacity-40"):o.classList.remove("opacity-40")):o&&o.remove(),this._button.className=e,this._button.disabled=this.isDisabled(),this._button.id=a,this._button.setAttribute("aria-checked",String(this._checked)),this._button.setAttribute("aria-label",s||"Toggle switch"),this._button.setAttribute("role","switch"),this._button.type="button";let c=this._button.querySelector("span");c||(c=document.createElement("span"),this._button.appendChild(c)),c.className=i;const h=c.querySelector("span");if(r){let d=h;d||(d=document.createElement("span"),d.className=this.getIconClasses(),c.appendChild(d));let u=d.querySelector("mint-icon");u||(u=document.createElement("mint-icon"),d.appendChild(u)),u.setAttribute("name",r)}else h&&h.remove();let p=this.querySelector(".mint-switch-info");n?(p||(p=document.createElement("span"),p.className="mint-switch-info text-xs text-gray-500 dark:text-gray-400 select-none mt-1 block",l&&l.parentElement===this?this.insertBefore(p,l.nextSibling):this.appendChild(p)),p.textContent=n,this.isDisabled()?p.classList.add("opacity-40"):p.classList.remove("opacity-40")):p&&p.remove(),this._renderErrorState(),this._renderSkeleton(t)}setupEventListeners(){this._button&&this._button.addEventListener("click",this.handleToggle.bind(this))}removeEventListeners(){this._button&&this._button.removeEventListener("click",this.handleToggle.bind(this))}handleToggle(t){if(!this.isDisabled()){this.checked=!this._checked;const e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e),this.dispatchEvent(new CustomEvent("input",{detail:{checked:this._checked},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:{checked:this._checked},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent("toggle",{detail:{checked:this._checked},bubbles:!0,cancelable:!0}))}}_renderSkeleton(t){const e=this._getSwitchContainer(),i=this.getLabel(),s=this.getInfo();let n=e.querySelector(".mint-switch-skeleton-container"),r=this.querySelector(".mint-switch-info-skeleton");if(t){e.classList.contains("relative")||e.classList.add("relative"),n||(n=document.createElement("div"),n.className="mint-switch-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center gap-2",e.appendChild(n));let a=n.querySelector(".mint-switch-skeleton-box");if(a||(a=document.createElement("div"),a.className="mint-switch-skeleton-box flex-shrink-0 w-10 h-5 rounded-full bg-gray-200 dark:bg-gray-700 animate-pulse",n.appendChild(a)),i){let o=n.querySelector(".mint-switch-skeleton-label");o||(o=document.createElement("div"),o.className="mint-switch-skeleton-label h-4 w-24 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",n.appendChild(o))}else{const o=n.querySelector(".mint-switch-skeleton-label");o&&o.remove()}n.style.display="flex",this._button&&(this._button.style.visibility="hidden",this._button.style.pointerEvents="none");const l=e.querySelector(".mint-switch-label");if(l&&(l.style.visibility="hidden",l.style.pointerEvents="none"),s){r||(r=document.createElement("div"),r.className="mint-switch-info-skeleton h-3 w-32 rounded bg-gray-200 dark:bg-gray-700 animate-pulse mt-2",e&&e.parentElement===this?this.insertBefore(r,e.nextSibling):this.appendChild(r)),r.style.display="block";const o=this.querySelector(".mint-switch-info");o&&(o.style.display="none")}else r&&(r.style.display="none")}else{n&&(n.style.display="none"),r&&(r.style.display="none"),this._button&&(this._button.style.visibility="visible",this._button.style.pointerEvents="auto");const a=e.querySelector(".mint-switch-label");a&&(a.style.visibility="visible",a.style.pointerEvents="auto");const l=this.querySelector(".mint-switch-info");l&&(l.style.display="")}}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-switch-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-switch-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove(),this._button&&(this._button.className=this.getSwitchClasses())}}customElements.get("mint-switch")||customElements.define("mint-switch",nt);class at extends HTMLElement{constructor(){super(),this._darkModeObserver=null,this._userClasses=new Set}static get observedAttributes(){return["variant","size","bold","underline","strike","italic","display","inline"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline"),this._captureUserClasses(),this.render(),this._observeDarkMode()}_captureUserClasses(){Array.from(this.classList).forEach(e=>this._userClasses.add(e))}attributeChangedCallback(t,e,i){e!==i&&this.render()}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null)}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}getVariant(){return this.getAttribute("variant")||"default"}getSize(){return this.getAttribute("size")||"regular"}isBold(){return this.getAttribute("bold")==="true"}isUnderline(){return this.getAttribute("underline")==="true"}isStrike(){return this.getAttribute("strike")==="true"}isItalic(){return this.getAttribute("italic")==="true"}getDisplay(){const t=this.getAttribute("display");return t||(this.getAttribute("inline")==="true"?"inline-block":"block")}getTextClasses(){const t=this.getSize(),e=this.getVariant(),i=document.documentElement.classList.contains("dark"),s={heading:["font-semibold"],"sub-heading":["font-medium"],regular:[]},n={default:i?["text-gray-100"]:["text-gray-900"],muted:i?["text-gray-400"]:["text-gray-400"],danger:i?["text-red-400"]:["text-red-600"],success:i?["text-green-400"]:["text-green-600"]},r=[];this.isBold()&&r.push("font-bold"),this.isUnderline()&&r.push("underline"),this.isStrike()&&r.push("line-through"),this.isItalic()&&r.push("italic");const a=this.getDisplay();return[a==="block"?"block":a==="inline"?"inline":"inline-block",...s[t]||s.regular,...n[e]||n.default,...r].join(" ")}render(){const t=this.getSize(),e=["text-gray-100","text-gray-900","text-gray-400","text-red-400","text-red-600","text-green-400","text-green-600"],i=["text-2xl","text-lg","text-sm"];i.forEach(o=>{this.classList.remove(o),this._userClasses.delete(o)}),e.forEach(o=>{this.classList.remove(o),this._userClasses.delete(o)});const s=this.getTextClasses().split(" ").filter(o=>o.trim());Array.from(this.classList).forEach(o=>{!e.includes(o)&&!i.includes(o)&&this._userClasses.add(o)});const r=[...new Set([...s,...Array.from(this._userClasses)])];this.className=r.join(" ");const a={heading:"clamp(1.25rem, 2.5vw + 0.5rem, 1.5rem)","sub-heading":"clamp(1rem, 1.5vw + 0.5rem, 1.125rem)",regular:"clamp(0.875rem, 1vw + 0.5rem, 0.875rem)"},l=a[t]||a.regular;this.style.setProperty("font-size",l)}}customElements.get("mint-text")||customElements.define("mint-text",at);class ot extends HTMLElement{constructor(){super(),this._childObserver=null}static get observedAttributes(){return["direction","text-align","gap"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block"),this.render(),this.getTextAlign()&&this._observeChildren()}attributeChangedCallback(t,e,i){e!==i&&(this.render(),t==="text-align"&&this._observeChildren())}_observeChildren(){this._childObserver||(this._childObserver=new MutationObserver(()=>{const t=this.getTextAlign();t&&this._applyTextAlignToChildren(t)}),this._childObserver.observe(this,{childList:!0,subtree:!1}))}disconnectedCallback(){this._childObserver&&(this._childObserver.disconnect(),this._childObserver=null)}getDirection(){return(this.getAttribute("direction")||"vertical")==="horizontal"?"horizontal":"vertical"}getGap(){const t=this.getAttribute("gap")||"3";return parseFloat(t)}getTextAlign(){const t=this.getAttribute("text-align")||"";return["left","center","right","justify"].includes(t)?t:""}getStackClasses(){const t=this.getDirection(),e=this.getTextAlign(),i=this.getGap(),s=["flex",t==="horizontal"?"flex-row":"flex-col",`gap-${i}`];return e&&(s.push(`text-${e}`),s.push(`[&>*]:text-${e}`),s.push(`[&>*_.mint-button-content]:text-${e}`),e==="left"?(s.push("[&>mint-button]:!justify-start"),s.push("[&>mint-button>button]:!justify-start")):e==="right"?(s.push("[&>mint-button]:!justify-end"),s.push("[&>mint-button>button]:!justify-end")):e==="center"&&(s.push("[&>mint-button]:!justify-center"),s.push("[&>mint-button>button]:!justify-center"))),s.join(" ")}render(){const t=this.getStackClasses(),e=this.getTextAlign();["flex","flex-row","flex-col","gap-1","gap-2","gap-3","text-left","text-center","text-right","text-justify","[&>*]:text-left","[&>*]:text-center","[&>*]:text-right","[&>*]:text-justify","[&>*_.mint-button-content]:text-left","[&>*_.mint-button-content]:text-center","[&>*_.mint-button-content]:text-right","[&>*_.mint-button-content]:text-justify","[&>mint-button]:!justify-start","[&>mint-button]:!justify-center","[&>mint-button]:!justify-end","[&>mint-button>button]:!justify-start","[&>mint-button>button]:!justify-center","[&>mint-button>button]:!justify-end"].forEach(n=>this.classList.remove(n)),t.split(" ").forEach(n=>{n&&this.classList.add(n)}),["box-border","m-0","p-0","border-0","align-baseline","block"].forEach(n=>{this.classList.contains(n)||this.classList.add(n)}),e?this._applyTextAlignToChildren(e):this._removeTextAlignFromChildren()}_applyTextAlignToChildren(t){Array.from(this.children).forEach(i=>{if(i.tagName==="MINT-BUTTON"){const s=i.querySelector("button");if(s){s.classList.remove("justify-start","justify-center","justify-end"),t==="left"?s.classList.add("justify-start"):t==="right"?s.classList.add("justify-end"):t==="center"&&s.classList.add("justify-center");const n=s.querySelector(".mint-button-content");n&&(n.classList.remove("text-left","text-center","text-right","text-justify"),n.classList.add(`text-${t}`))}}else i.classList.remove("text-left","text-center","text-right","text-justify"),i.classList.add(`text-${t}`)})}_removeTextAlignFromChildren(){Array.from(this.children).forEach(e=>{if(e.tagName==="MINT-BUTTON"){const i=e.querySelector("button");if(i){i.classList.remove("justify-start","justify-end"),i.classList.add("justify-center");const s=i.querySelector(".mint-button-content");s&&s.classList.remove("text-left","text-center","text-right","text-justify")}}else e.classList.remove("text-left","text-center","text-right","text-justify")})}}customElements.get("mint-stack")||customElements.define("mint-stack",ot);class lt extends HTMLElement{constructor(){super(),this._headingElement=null}static get observedAttributes(){return["heading"]}connectedCallback(){this.classList.add("box-border","m-0","align-baseline","block"),this.render()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getHeading(){return this.getAttribute("heading")||""}hasPaddingClass(){return Array.from(this.classList).some(e=>/^p-\d+|^px-|^py-|^pt-|^pb-|^pl-|^pr-/.test(e))}render(){this.classList.add("rounded-lg","shadow","bg-white","dark:bg-gray-900","border","border-gray-200","dark:border-gray-700","overflow-hidden","transition-colors","duration-200","mb-6"),this.hasPaddingClass()||this.classList.add("p-4");const t=this.getHeading();t?(this._headingElement||(this._headingElement=document.createElement("mint-text"),this._headingElement.setAttribute("size","sub-heading"),this.insertBefore(this._headingElement,this.firstChild)),this._headingElement.textContent=t):this._headingElement&&this._headingElement.parentNode&&(this._headingElement.remove(),this._headingElement=null)}}customElements.get("mint-card")||customElements.define("mint-card",lt);class ct extends HTMLElement{constructor(){super(),this._link=null,this._contentObserver=null}static get observedAttributes(){return["href","target"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render(),this._observeContent()}disconnectedCallback(){this._contentObserver&&(this._contentObserver.disconnect(),this._contentObserver=null)}_observeContent(){this._contentObserver||(this._contentObserver=new MutationObserver(()=>{this._link&&this._link.querySelectorAll("mint-text").forEach(e=>{e.classList.contains("underline")||e.classList.add("underline")})}),this._contentObserver.observe(this,{childList:!0,subtree:!0}))}attributeChangedCallback(t,e,i){e!==i&&this.render()}getHref(){return this.getAttribute("href")||"#"}getTarget(){return this.getAttribute("target")||""}hasIcon(){var t;return!!(this.querySelector("mint-icon")||(t=this._link)!=null&&t.querySelector("mint-icon"))}render(){const t=this.getHref(),e=this.getTarget();if(!this._link){for(this._link=document.createElement("a");this.firstChild;)this._link.appendChild(this.firstChild);this.appendChild(this._link)}this._link.href=t,e?(this._link.target=e,e==="_blank"&&(this._link.rel="noopener noreferrer")):(this._link.removeAttribute("target"),this._link.removeAttribute("rel"));const i=this.hasIcon(),s=["text-slate-800","dark:text-slate-200","underline","hover:text-slate-950","dark:hover:text-slate-100","transition-colors","duration-200","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"];i&&s.push("inline-flex","items-center","gap-2"),this._link.className=s.join(" "),this._link.querySelectorAll("mint-text").forEach(a=>{a.classList.contains("underline")||a.classList.add("underline")}),["box-border","m-0","p-0","border-0","align-baseline","inline-block"].forEach(a=>{this.classList.contains(a)||this.classList.add(a)})}}customElements.get("mint-link")||customElements.define("mint-link",ct);class ht extends HTMLElement{constructor(){super(),this._button=null}static get observedAttributes(){return["href","fallback-href"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block","flex","items-center","justify-center"),this.render()}disconnectedCallback(){}attributeChangedCallback(t,e,i){e!==i&&this.render()}getFallbackHref(){return this.getAttribute("fallback-href")||this.getAttribute("href")||"/"}_getTargetUrl(){const t=document.referrer,e=window.location.origin;if(t)try{const i=new URL(t);if(i.origin===e)return i.pathname+i.search}catch{}return this.getFallbackHref()}handleClick(t){t.preventDefault(),t.stopPropagation();const e=this._getTargetUrl(),i=document.referrer,s=i&&(()=>{try{return new URL(i).origin===window.location.origin}catch{return!1}})(),n=new CustomEvent("back",{detail:{url:e,isFromReferrer:s,referrer:i||null,fallbackHref:this.getFallbackHref()},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(n)}render(){this._button||(this._button=document.createElement("mint-button"),this._button.setAttribute("variant","neutral"),this._button.setAttribute("icon","arrow-left"),this._button.addEventListener("click",t=>this.handleClick(t)),this.appendChild(this._button))}}customElements.get("mint-back-button")||customElements.define("mint-back-button",ht);class dt extends HTMLElement{constructor(){super(),this._pageContainer=null,this._header=null,this._titleElement=null,this._headingText=null,this._actionsSlot=null,this._bodySlot=null,this._darkModeObserver=null,this._backButton=null,this._backButtonHandler=null}static get observedAttributes(){return["heading","fallback-href","show-back-button","containered"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block"),this.render(),this._observeDarkMode(),this._setupBackButtonListener()}attributeChangedCallback(t,e,i){e!==i&&(t==="containered"&&this._applyContainerClasses(),this.render())}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null),this._removeBackButtonListener()}getHeading(){return this.getAttribute("heading")||""}getFallbackHref(){return this.getAttribute("fallback-href")||"/"}shouldShowBackButton(){return this.getAttribute("show-back-button")==="true"}render(){const t=this.getHeading();this._pageContainer||(this._pageContainer=document.createElement("div"),this.appendChild(this._pageContainer)),this._applyContainerClasses(),this._header||(this._header=document.createElement("div"),this._header.className="flex justify-between mb-8",this._pageContainer.appendChild(this._header)),this._titleElement||(this._titleElement=document.createElement("div"),this._titleElement.className="flex gap-4 min-w-0 flex-1",this._header.appendChild(this._titleElement));let e=this._titleElement.querySelector("mint-back-button");if(this.shouldShowBackButton()){e||(e=document.createElement("mint-back-button"),this._titleElement.insertBefore(e,this._titleElement.firstChild));const r=this.getFallbackHref();e.setAttribute("fallback-href",r),this._backButton=e}else e&&(e.remove(),e=null,this._backButton=null);t?(this._headingText?(this._headingText.classList.add("truncate","min-w-0"),e&&e.parentElement===this._titleElement?this._headingText.previousSibling!==e&&this._titleElement.insertBefore(this._headingText,e.nextSibling):this._headingText.previousSibling&&this._titleElement.insertBefore(this._headingText,this._titleElement.firstChild)):(this._headingText=document.createElement("mint-text"),this._headingText.setAttribute("size","heading"),this._headingText.setAttribute("bold","true"),this._headingText.classList.add("truncate","min-w-0"),e&&e.parentElement===this._titleElement?this._titleElement.insertBefore(this._headingText,e.nextSibling):this._titleElement.insertBefore(this._headingText,this._titleElement.firstChild)),this._headingText.textContent=t):this._headingText&&(this._headingText.remove(),this._headingText=null),this._actionsSlot?this._actionsSlot.classList.contains("ml-4")||this._actionsSlot.classList.add("ml-4"):(this._actionsSlot=document.createElement("div"),this._actionsSlot.className="flex gap-2 items-center ml-4",this._actionsSlot.setAttribute("slot","actions"),this._header.appendChild(this._actionsSlot)),Array.from(this.children).filter(r=>r!==this._pageContainer&&r!==this._actionsSlot&&r.getAttribute("slot")==="actions").forEach(r=>{this._actionsSlot&&r.parentElement!==this._actionsSlot&&this._actionsSlot.appendChild(r)}),this._bodySlot||(this._bodySlot=document.createElement("div"),this._pageContainer.appendChild(this._bodySlot)),Array.from(this.children).forEach(r=>{r!==this._pageContainer&&r.getAttribute("slot")!=="actions"&&r!==this._actionsSlot&&r!==this._header&&r!==this._bodySlot&&r!==this._headingText&&r.parentElement!==this._bodySlot&&r.parentElement!==this._pageContainer&&this._bodySlot.appendChild(r)}),this._updateBackgroundColor()}_applyContainerClasses(){if(!this._pageContainer)return;this._pageContainer.classList.add("min-h-screen","p-8","transition-colors","duration-200"),this.getAttribute("containered")==="true"?this._pageContainer.classList.add("max-w-6xl","mx-auto","w-full"):this._pageContainer.classList.remove("max-w-6xl","mx-auto","w-full")}_updateBackgroundColor(){if(!this._pageContainer)return;document.documentElement.classList.contains("dark")?(this._pageContainer.classList.remove("bg-gray-20"),this._pageContainer.classList.add("bg-gray-900")):(this._pageContainer.classList.remove("bg-gray-900"),this._pageContainer.classList.add("bg-gray-20"))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_setupBackButtonListener(){this._backButtonHandler||(this._backButtonHandler=t=>{const e=t.target;if(e&&e.tagName==="MINT-BACK-BUTTON"){t.stopPropagation();const i=new CustomEvent("back",{detail:t.detail,bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(i)}}),this.addEventListener("back",this._backButtonHandler,!0)}_removeBackButtonListener(){this._backButtonHandler&&(this.removeEventListener("back",this._backButtonHandler,!0),this._backButtonHandler=null)}}customElements.get("mint-page")||customElements.define("mint-page",dt);class ut extends HTMLElement{static get observedAttributes(){return["columns","sm","md","lg","xl","gap"]}constructor(){super()}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block"),this.render()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getColumns(){return this.getAttribute("columns")||"1"}getSm(){return this.getAttribute("sm")}getMd(){return this.getAttribute("md")}getLg(){return this.getAttribute("lg")}getXl(){return this.getAttribute("xl")}getGap(){return"3"}getGridClasses(){const t=["grid"],e=this.getColumns();t.push(`grid-cols-${e}`);const i=this.getSm();i&&t.push(`sm:grid-cols-${i}`);const s=this.getMd();s&&t.push(`md:grid-cols-${s}`);const n=this.getLg();n&&t.push(`lg:grid-cols-${n}`);const r=this.getXl();r&&t.push(`xl:grid-cols-${r}`);const a=this.getGap();return t.push(`gap-${a}`),t}render(){Array.from(this.classList).filter(i=>i.startsWith("grid-cols-")||i.startsWith("sm:grid-cols-")||i.startsWith("md:grid-cols-")||i.startsWith("lg:grid-cols-")||i.startsWith("xl:grid-cols-")||i.startsWith("gap-")).forEach(i=>this.classList.remove(i)),this.classList.contains("grid")||this.classList.add("grid"),this.getGridClasses().forEach(i=>{i&&i!=="grid"&&this.classList.add(i)})}}customElements.get("mint-grid")||customElements.define("mint-grid",ut);class pt extends HTMLElement{constructor(){super(),this._overlay=null,this._modal=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._darkModeObserver=null}static get observedAttributes(){return["id","heading","open"]}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()}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null)}attributeChangedCallback(t,e,i){e!==i&&this.render()}getId(){return this.getAttribute("id")||""}getHeading(){return this.getAttribute("heading")||""}isOpen(){return this.getAttribute("open")==="true"}open(){this.setAttribute("open","true")}close(){this.removeAttribute("open")}render(){const t=this.getId(),e=this.getHeading(),i=this.isOpen();if(t&&(this.id=t),this._overlay||(this._overlay=document.createElement("div"),this._overlay.className="fixed inset-0 bg-black bg-opacity-50 transition-opacity duration-200 z-40",this._overlay.addEventListener("click",()=>this.close()),this.appendChild(this._overlay)),this._modal||(this._modal=document.createElement("div"),this._modal.className="fixed inset-0 flex items-center justify-center p-2 pointer-events-none z-50",this.appendChild(this._modal)),i){let h=this._modal.querySelector(".modal-content");h||(h=document.createElement("div"),h.className="modal-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg shadow-xl max-w-2xl w-full max-h-[90vh] flex flex-col pointer-events-auto transition-all duration-200 ease-out transform",this._modal.appendChild(h)),this._animateEnter()}else this._animateExit();let s=this._modal.querySelector(".modal-content");s||(s=document.createElement("div"),s.className="modal-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg shadow-xl max-w-2xl w-full max-h-[90vh] flex flex-col pointer-events-auto transition-all duration-200 ease-out transform",this._modal.appendChild(s)),this._header||(this._header=document.createElement("div"),this._header.className="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700",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 n=this._headingSlot.querySelector("mint-text");e?(n||(n=document.createElement("mint-text"),n.setAttribute("size","sub-heading"),n.setAttribute("bold","true"),this._headingSlot.appendChild(n)),n.textContent=e):n&&n.remove(),Array.from(this.children).filter(h=>h!==this._overlay&&h!==this._modal&&h!==this._headingSlot&&h.getAttribute("slot")==="heading").forEach(h=>{this._headingSlot&&h.parentElement!==this._headingSlot&&this._headingSlot.appendChild(h)}),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(h=>h!==this._overlay&&h!==this._modal&&h!==this._bodySlot&&h.getAttribute("slot")==="body").forEach(h=>{this._bodySlot&&h.parentElement!==this._bodySlot&&this._bodySlot.appendChild(h)}),this._actionsSlot||(this._actionsSlot=document.createElement("div"),this._actionsSlot.className="p-4 border-t border-gray-200 dark:border-gray-700",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(h=>h!==this._overlay&&h!==this._modal&&h!==this._actionsSlot&&h.getAttribute("slot")==="actions").forEach(h=>{Array.from(h.children).forEach(d=>{d.parentElement!==l&&l.appendChild(d)}),h.parentElement&&h.remove()}),Array.from(this.children).forEach(h=>{h!==this._overlay&&h!==this._modal&&h.getAttribute("slot")!=="heading"&&h.getAttribute("slot")!=="body"&&h.getAttribute("slot")!=="actions"&&h!==this._headingSlot&&h!==this._bodySlot&&h!==this._actionsSlot&&h.parentElement!==this._bodySlot&&this._bodySlot.appendChild(h)}),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._modal)return;const t=document.documentElement.classList.contains("dark"),e=this._modal.querySelector(".modal-content");e&&(t?(e.classList.remove("bg-white"),e.classList.add("bg-gray-900","border","border-gray-700")):(e.classList.remove("bg-gray-900","border","border-gray-700"),e.classList.add("bg-white")))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_animateEnter(){var e;const t=(e=this._modal)==null?void 0:e.querySelector(".modal-content");t&&(t.style.transform="scale(0.97) translateY(10px)",t.style.opacity="0",t.style.transition="all 200ms ease-out",this.classList.remove("hidden"),requestAnimationFrame(()=>{requestAnimationFrame(()=>{t.style.transform="scale(1) translateY(0)",t.style.opacity="1"})}))}_animateExit(){var e;const t=(e=this._modal)==null?void 0:e.querySelector(".modal-content");if(!t){this.classList.add("hidden");return}t.style.transition="all 200ms ease-in",t.style.transform="scale(0.97) translateY(10px)",t.style.opacity="0",setTimeout(()=>{this.classList.add("hidden"),t.style.transform="",t.style.opacity="",t.style.transition=""},200)}}customElements.get("mint-modal")||customElements.define("mint-modal",pt);class ft extends HTMLElement{constructor(){super(),this._overlay=null,this._popover=null,this._triggerElement=null,this._darkModeObserver=null,this._clickOutsideHandler=null,this._triggerClickHandler=null,this._triggerHoverEnterHandler=null,this._triggerHoverLeaveHandler=null,this._popoverHoverEnterHandler=null,this._popoverHoverLeaveHandler=null,this._hoverCloseTimeout=null,this._scrollHandler=null,this._resizeHandler=null}static get observedAttributes(){return["id","direction","open","trigger-id","padding","hover"]}connectedCallback(){const t=this._isInsideModal()?"z-[60]":"z-50";this.classList.add("box-border","m-0","p-0","border-0","align-baseline","fixed","top-0","left-0",t,"pointer-events-none"),this.isOpen()||this.classList.add("hidden"),this.render(),this._setupTrigger(),this._observeDarkMode()}_isInsideModal(){let t=this;for(;t;){if(t.tagName==="MINT-MODAL")return!0;t=t.parentElement}if(this._triggerElement)for(t=this._triggerElement;t;){if(t.tagName==="MINT-MODAL")return!0;t=t.parentElement}return!1}disconnectedCallback(){this._triggerElement&&this._triggerElement.tagName==="MINT-BUTTON"&&this._triggerElement.removeAttribute("active"),this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null),this._clickOutsideHandler&&(document.removeEventListener("click",this._clickOutsideHandler),this._clickOutsideHandler=null),this._triggerClickHandler&&this._triggerElement&&(this._triggerElement.removeEventListener("click",this._triggerClickHandler,!0),this._triggerClickHandler=null),this._removeHoverListeners(),this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null)}attributeChangedCallback(t,e,i){if(e!==i){if(this.isConnected){const s=this._isInsideModal()?"z-[60]":"z-50";this.classList.remove("z-50","z-[60]"),this.classList.add(s)}this.render(),(t==="trigger-id"||t==="hover")&&this._setupTrigger(),t==="open"&&this.isOpen()&&this._closeOtherPopovers()}}getId(){return this.getAttribute("id")||""}getPadding(){const t=this.getAttribute("padding")||"4";return{0:"p-0","0.5":"p-0.5",1:"p-1","1.5":"p-1.5",2:"p-2","2.5":"p-2.5",3:"p-3","3.5":"p-3.5",4:"p-4",5:"p-5",6:"p-6",8:"p-8",10:"p-10",12:"p-12",16:"p-16",20:"p-20",24:"p-24"}[t]||"p-4"}getDirection(){return this.getAttribute("direction")||"down"}getTriggerId(){return this.getAttribute("trigger-id")||""}isHoverEnabled(){return this.getAttribute("hover")==="true"}isOpen(){return this.getAttribute("open")==="true"}open(){this.setAttribute("open","true")}close(){this.removeAttribute("open")}_setupTrigger(){const t=this.getTriggerId();this._triggerClickHandler&&this._triggerElement&&(this._triggerElement.removeEventListener("click",this._triggerClickHandler,!0),this._triggerClickHandler=null),this._removeHoverListeners(),t&&(this._triggerElement=document.getElementById(t),this._triggerElement?(this._attachTriggerListener(),this.isHoverEnabled()&&this._attachHoverListeners()):setTimeout(()=>{this._triggerElement=document.getElementById(t),this._triggerElement&&(this._attachTriggerListener(),this.isHoverEnabled()&&this._attachHoverListeners())},10))}_attachTriggerListener(){if(this._triggerElement&&!this._triggerClickHandler){const t=this;this._triggerClickHandler=function(e){e.stopImmediatePropagation(),e.preventDefault(),t.getAttribute("open")==="true"?t.removeAttribute("open"):t.setAttribute("open","true")},this._triggerElement.addEventListener("click",this._triggerClickHandler,!0)}}_attachHoverListeners(){if(!this.isHoverEnabled()||!this._triggerElement)return;this._removeHoverListeners();const t=this;this._triggerHoverEnterHandler=function(){t._cancelHoverClose(),t.open()},this._triggerHoverLeaveHandler=function(e){var s;const i=e.relatedTarget;i&&(t.contains(i)||(s=t._triggerElement)!=null&&s.contains(i))||t._scheduleHoverClose()},this._triggerElement.addEventListener("mouseenter",this._triggerHoverEnterHandler),this._triggerElement.addEventListener("mouseleave",this._triggerHoverLeaveHandler),this._popover&&(this._popoverHoverEnterHandler=function(){t._cancelHoverClose()},this._popoverHoverLeaveHandler=function(e){var s;const i=e.relatedTarget;i&&(t.contains(i)||(s=t._triggerElement)!=null&&s.contains(i))||t._scheduleHoverClose()},this._popover.addEventListener("mouseenter",this._popoverHoverEnterHandler),this._popover.addEventListener("mouseleave",this._popoverHoverLeaveHandler))}_removeHoverListeners(){this._triggerElement&&this._triggerHoverEnterHandler&&this._triggerElement.removeEventListener("mouseenter",this._triggerHoverEnterHandler),this._triggerElement&&this._triggerHoverLeaveHandler&&this._triggerElement.removeEventListener("mouseleave",this._triggerHoverLeaveHandler),this._popover&&this._popoverHoverEnterHandler&&this._popover.removeEventListener("mouseenter",this._popoverHoverEnterHandler),this._popover&&this._popoverHoverLeaveHandler&&this._popover.removeEventListener("mouseleave",this._popoverHoverLeaveHandler),this._triggerHoverEnterHandler=null,this._triggerHoverLeaveHandler=null,this._popoverHoverEnterHandler=null,this._popoverHoverLeaveHandler=null,this._cancelHoverClose()}_scheduleHoverClose(){this._cancelHoverClose(),this._hoverCloseTimeout=window.setTimeout(()=>{this._isHovering()||this.close()},120)}_cancelHoverClose(){this._hoverCloseTimeout!==null&&(clearTimeout(this._hoverCloseTimeout),this._hoverCloseTimeout=null)}_isHovering(){const t=this._triggerElement?this._triggerElement.matches(":hover"):!1,e=this._popover?this._popover.matches(":hover"):!1;return t||e}_calculatePosition(){if(!this._triggerElement||!this._popover)return{top:0,left:0,direction:"down"};const t=this._triggerElement.getBoundingClientRect(),e=this._popover.querySelector(".popover-content");if(!e)return{top:0,left:0,direction:"down"};this.classList.contains("hidden")&&(this.classList.remove("hidden"),this._popover.style.visibility="hidden");const s=e.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,a=8;let l=this.getDirection(),o=0,c=0;switch(l){case"down":if(o=t.bottom+a,c=t.left+t.width/2-s.width/2,o+s.height>r){const h=t.top-s.height-a;h>=0?(l="up",o=h):(o=Math.max(0,r-s.height-a),o+s.height>r&&(o=0))}c<0&&(c=a),c+s.width>n&&(c=Math.max(a,n-s.width-a),c+s.width>n&&(c=n-s.width));break;case"up":if(o=t.top-s.height-a,c=t.left+t.width/2-s.width/2,o<0){const h=t.bottom+a;h+s.height<=r?(l="down",o=h):(o=Math.min(r-s.height-a,r-s.height),o<0&&(o=r-s.height))}c<0&&(c=a),c+s.width>n&&(c=Math.max(a,n-s.width-a),c+s.width>n&&(c=n-s.width));break;case"right":if(o=t.top+t.height/2-s.height/2,c=t.right+a,c+s.width>n){const h=t.left-s.width-a;h>=0?(l="left",c=h):(c=Math.max(0,n-s.width-a),c+s.width>n&&(c=n-s.width))}o<0&&(o=a),o+s.height>r&&(o=Math.max(a,r-s.height-a),o+s.height>r&&(o=r-s.height));break;case"left":if(o=t.top+t.height/2-s.height/2,c=t.left-s.width-a,c<0){const h=t.right+a;h+s.width<=n?(l="right",c=h):(c=Math.min(n-s.width-a,n-s.width),c<0&&(c=0))}o<0&&(o=a),o+s.height>r&&(o=Math.max(a,r-s.height-a),o+s.height>r&&(o=r-s.height));break}return{top:o,left:c,direction:l}}render(){const t=this.getId(),e=this.isOpen(),i=this.getPadding();if(t&&(this.id=t),e){if(this.classList.remove("hidden"),this.style.pointerEvents="auto",this._triggerElement&&this._triggerElement.tagName==="MINT-BUTTON"&&requestAnimationFrame(()=>{this._triggerElement.setAttribute("active","true");const r=this._triggerElement;typeof r.render=="function"&&requestAnimationFrame(()=>{r.render()})}),!this._clickOutsideHandler){const r=this;this._clickOutsideHandler=function(a){const l=a.composedPath(),o=l.includes(r);if(!(r._triggerElement&&l.includes(r._triggerElement))&&!o){r.close();return}},setTimeout(()=>{document.addEventListener("click",this._clickOutsideHandler,!1)},100)}}else this.classList.add("hidden"),this.style.pointerEvents="none",this._triggerElement&&this._triggerElement.tagName==="MINT-BUTTON"&&requestAnimationFrame(()=>{this._triggerElement.removeAttribute("active");const r=this._triggerElement;typeof r.render=="function"&&requestAnimationFrame(()=>{r.render()})}),this._clickOutsideHandler&&(document.removeEventListener("click",this._clickOutsideHandler,!1),this._clickOutsideHandler=null);if(this._overlay){const r=this._isInsideModal()?"z-[55]":"z-40";this._overlay.className=`fixed inset-0 pointer-events-none ${r}`}else{this._overlay=document.createElement("div");const r=this._isInsideModal()?"z-[55]":"z-40";this._overlay.className=`fixed inset-0 pointer-events-none ${r}`,this.appendChild(this._overlay)}if(this._popover){const r=this._isInsideModal()?"z-[60]":"z-50";this._popover.className=`fixed ${r} pointer-events-auto`}else{this._popover=document.createElement("div");const r=this._isInsideModal()?"z-[60]":"z-50";this._popover.className=`fixed ${r} pointer-events-auto`,this.appendChild(this._popover)}this.isHoverEnabled()&&this._attachHoverListeners();let s=this._popover.querySelector(".popover-content");if(!s)s=document.createElement("div"),s.className=`popover-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg shadow-xl ${i} transition-all duration-200 ease-out transform`,this._popover.appendChild(s);else{const r=s.className.split(" "),a=["p-0","p-0.5","p-1","p-1.5","p-2","p-2.5","p-3","p-3.5","p-4","p-5","p-6","p-8","p-10","p-12","p-16","p-20","p-24"],l=r.filter(o=>!a.includes(o));s.className=[...l,i].join(" ")}Array.from(this.children).forEach(r=>{r!==this._overlay&&r!==this._popover&&r.parentElement===this&&s.appendChild(r)}),e?(this._triggerElement||this._setupTrigger(),this._setupPositionListeners(),this.offsetHeight,this._triggerElement?this._updatePosition(s):(this._popover.style.top="50%",this._popover.style.left="50%",this._popover.style.transform="translate(-50%, -50%)",this._popover.style.visibility="visible",this._popover.style.display="block",s.style.transform="scale(0.97) translateY(10px)",s.style.opacity="0",s.style.transition="all 200ms ease-out",requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.style.transform="scale(1) translateY(0)",s.style.opacity="1"})}))):!e&&s&&(this._removePositionListeners(),s.style.opacity!=="0"&&s.style.opacity!==""&&(s.style.transition="all 200ms ease-in",s.style.transform="scale(0.97) translateY(10px)",s.style.opacity="0",setTimeout(()=>{s.style.transform="",s.style.opacity="",s.style.transition="",this._popover.style.visibility="",this._popover.style.display=""},200))),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._popover)return;const t=document.documentElement.classList.contains("dark"),e=this._popover.querySelector(".popover-content");e&&(t?(e.classList.remove("bg-white"),e.classList.add("bg-gray-900","border","border-gray-700")):(e.classList.remove("bg-gray-900","border","border-gray-700"),e.classList.add("bg-white")))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_updatePosition(t){if(!this._triggerElement||!this._popover)return;const e=this._popover.style.visibility!=="hidden";e||(this._popover.style.visibility="hidden",this._popover.style.display="block",this._popover.style.top="0",this._popover.style.left="0"),this._popover.offsetHeight;const i=this._calculatePosition();this._popover.style.top=`${i.top}px`,this._popover.style.left=`${i.left}px`,e||(this._popover.style.visibility="visible",t&&(!t.style.opacity||t.style.opacity==="")&&(t.style.transform="scale(0.97) translateY(10px)",t.style.opacity="0",t.style.transition="all 200ms ease-out",requestAnimationFrame(()=>{requestAnimationFrame(()=>{t.style.transform="scale(1) translateY(0)",t.style.opacity="1"})})))}_setupPositionListeners(){if(!this._scrollHandler&&this.isOpen()){const t=this;this._scrollHandler=function(){if(t.isOpen()&&t._popover){const e=t._popover.querySelector(".popover-content");e&&t._updatePosition(e)}},window.addEventListener("scroll",this._scrollHandler,!0)}if(!this._resizeHandler&&this.isOpen()){const t=this;this._resizeHandler=function(){if(t.isOpen()&&t._popover){const e=t._popover.querySelector(".popover-content");e&&t._updatePosition(e)}},window.addEventListener("resize",this._resizeHandler)}}_removePositionListeners(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null)}_closeOtherPopovers(){Array.from(document.querySelectorAll("mint-popover[open]")).forEach(e=>{if(e!==this){const i=e;typeof i.close=="function"?i.close():e.removeAttribute("open")}})}}customElements.get("mint-popover")||customElements.define("mint-popover",ft);class gt extends HTMLElement{constructor(){super(),this._checkbox=null,this._checked=!1,this._clickHandler=null,this._changeHandler=null,this._mousedownHandler=null,this._mouseupHandler=null,this._mouseleaveHandler=null,this._touchstartHandler=null,this._touchendHandler=null,this._focusHandler=null,this._blurHandler=null}static get observedAttributes(){return["checked","disabled","label","info","id","name","value","error","error-message","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-flex","items-start","gap-2");const t=this.getAttribute("checked");this._checked=t==="true",this.render()}disconnectedCallback(){this.removeEventListeners()}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(t==="checked"&&(this._checked=i==="true",this._checkbox&&(this._checkbox.checked=this._checked)),e!==i){if(t==="error"||t==="error-message"){this._renderErrorState();return}if(t==="loading"){this.render();return}this.render(),t==="checked"&&this._checkbox&&this.updateVisualState()}}get checked(){try{return this._checked||!1}catch{return!1}}set checked(t){try{t?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this._checked=!!t,this._checkbox&&(this._checkbox.checked=this._checked),this.updateVisualState()}catch{}}isDisabled(){return this.getAttribute("disabled")==="true"}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getId(){return this.getAttribute("id")||""}getName(){return this.getAttribute("name")||""}getValue(){return this.getAttribute("value")||""}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getCheckboxClasses(){const t=this.hasError(),e=["relative","inline-flex","items-center","justify-center","flex-shrink-0","w-5","h-5","rounded","border-2","transition-all","duration-200","outline-none","focus:outline-none","focus-visible:ring-2","focus-visible:ring-offset-1",t?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500","cursor-pointer","disabled:opacity-40","disabled:cursor-not-allowed"],i=this._checked?["bg-slate-800","dark:bg-slate-600",t?"border-red-300 dark:border-red-300":"border-slate-800 dark:border-slate-600"]:["bg-white","dark:bg-gray-700",t?"border-red-300 dark:border-red-300":"border-gray-300 dark:border-gray-500"];return[...e,...i].join(" ")}render(){const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.isDisabled();let n=this.querySelector(".mint-checkbox-container");n||(n=document.createElement("div"),n.className="mint-checkbox-container relative inline-flex items-start gap-2",this.insertBefore(n,this.firstChild));let r=this.querySelector(".mint-checkbox-wrapper");r?r.parentElement!==n&&n.appendChild(r):(r=document.createElement("div"),r.className="mint-checkbox-wrapper",n.appendChild(r)),this._checkbox?this._checkbox.parentElement!==r&&r.appendChild(this._checkbox):(this._checkbox=document.createElement("input"),this._checkbox.type="checkbox",r.appendChild(this._checkbox),this.setupEventListeners()),this._checkbox.className="absolute inset-0 w-full h-full opacity-0 cursor-pointer",this._checkbox.style.cssText="position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; z-index: 10; pointer-events: auto; margin: 0; padding: 0;",this._checkbox.checked=this._checked,this._checkbox.disabled=s,this._changeHandler||this.setupEventListeners();const a=this.getId();a?this._checkbox.id=a:this._checkbox.removeAttribute("id");const l=this.getName();l?this._checkbox.name=l:this._checkbox.removeAttribute("name");const o=this.getValue();o?this._checkbox.value=o:this._checkbox.removeAttribute("value"),e?this._checkbox.setAttribute("aria-label",e):this._checkbox.removeAttribute("aria-label"),r.className=`mint-checkbox-wrapper ${this.getCheckboxClasses()}`,r.style.cursor="pointer",r.style.pointerEvents="auto",this._checkbox.style.pointerEvents="auto";const c=r;c._wrapperClickHandler||(c._wrapperClickHandler=u=>{u.target===r&&!s&&(u.preventDefault(),u.stopPropagation(),this.toggle())},r.addEventListener("click",c._wrapperClickHandler));let h=r.querySelector("mint-icon");h||(h=document.createElement("mint-icon"),h.setAttribute("name","check"),h.className="w-3.5 h-3.5 text-white pointer-events-none absolute inset-0 m-auto",h.style.transition="opacity 200ms ease-out, transform 200ms ease-out",h.style.zIndex="1",r.appendChild(h)),this.updateVisualState();let p=this.querySelector(".mint-checkbox-label-container");const d=this.querySelector(".mint-checkbox-container");if(e||i){p?d&&p.parentElement!==d&&d.appendChild(p):(p=document.createElement("div"),p.className="mint-checkbox-label-container flex flex-col gap-0.5 flex-1",d?d.appendChild(p):this.appendChild(p));let u=p.querySelector(".mint-checkbox-label");e?(u||(u=document.createElement("span"),u.className="mint-checkbox-label text-sm font-medium text-gray-900 dark:text-gray-100 cursor-pointer select-none",p.insertBefore(u,p.firstChild)),u.textContent=e,s?u.classList.add("opacity-40"):u.classList.remove("opacity-40")):u&&u.remove();let f=p.querySelector(".mint-checkbox-info");if(i?(f||(f=document.createElement("span"),f.className="mint-checkbox-info text-xs text-gray-500 dark:text-gray-400 cursor-pointer select-none",p.appendChild(f)),f.textContent=i,s?f.classList.add("opacity-40"):f.classList.remove("opacity-40")):f&&f.remove(),s)p.style.cursor="default",p._clickHandler&&(p.removeEventListener("click",p._clickHandler),p._clickHandler=null);else{p.style.cursor="pointer";const _=p._clickHandler;_&&p.removeEventListener("click",_),p._clickHandler=g=>{this._checkbox&&(g.target===this._checkbox||this._checkbox.contains(g.target)||g.composedPath().includes(this._checkbox))||this.toggle()},p.addEventListener("click",p._clickHandler)}}else p&&p.remove();this._renderErrorState(),this._renderSkeleton(t)}setupEventListeners(){this.removeEventListeners(),this._checkbox&&(this._changeHandler=t=>{t.stopPropagation(),this._checked=this._checkbox.checked,this._checked?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this.updateVisualState();const e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e),this.dispatchEvent(new CustomEvent("input",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0}));const i=new CustomEvent("change",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0});this.dispatchEvent(i)},this._checkbox.addEventListener("change",this._changeHandler),this._mousedownHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&!this.isDisabled()&&(e.classList.add("mint-checkbox-active"),this._checked?(e.style.backgroundColor="rgb(15 23 42)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.3)"):(e.style.backgroundColor="rgb(243 244 246)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.1)"),document.documentElement.classList.contains("dark")&&(this._checked?e.style.backgroundColor="rgb(51 65 85)":e.style.backgroundColor="rgb(31 41 55)"))},this._mouseupHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&(e.classList.remove("mint-checkbox-active"),e.style.backgroundColor="",e.style.boxShadow="")},this._mouseleaveHandler=t=>{const e=this.querySelector(".mint-checkbox-wrapper");e&&(e.classList.remove("mint-checkbox-active"),e.style.backgroundColor="",e.style.boxShadow="")},this._checkbox.addEventListener("mousedown",this._mousedownHandler),this._checkbox.addEventListener("mouseup",this._mouseupHandler),this._checkbox.addEventListener("mouseleave",this._mouseleaveHandler),this._focusHandler=t=>{const e=this.querySelector(".mint-checkbox-wrapper");e&&this._checkbox&&requestAnimationFrame(()=>{this._checkbox&&this._checkbox.matches(":focus-visible")&&(e==null||e.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500"))})},this._blurHandler=()=>{const t=this.querySelector(".mint-checkbox-wrapper");t&&t.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._checkbox.addEventListener("focus",this._focusHandler),this._checkbox.addEventListener("blur",this._blurHandler),this._touchstartHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&!this.isDisabled()&&(e.classList.add("mint-checkbox-active"),this._checked?(e.style.backgroundColor="rgb(15 23 42)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.3)"):(e.style.backgroundColor="rgb(243 244 246)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.1)"),document.documentElement.classList.contains("dark")&&(this._checked?e.style.backgroundColor="rgb(51 65 85)":e.style.backgroundColor="rgb(31 41 55)"))},this._touchendHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&(e.classList.remove("mint-checkbox-active"),e.style.backgroundColor="",e.style.boxShadow="")},this._checkbox.addEventListener("touchstart",this._touchstartHandler),this._checkbox.addEventListener("touchend",this._touchendHandler))}removeEventListeners(){this._checkbox&&(this._changeHandler&&(this._checkbox.removeEventListener("change",this._changeHandler),this._changeHandler=null),this._mousedownHandler&&(this._checkbox.removeEventListener("mousedown",this._mousedownHandler),this._mousedownHandler=null),this._mouseupHandler&&(this._checkbox.removeEventListener("mouseup",this._mouseupHandler),this._mouseupHandler=null),this._mouseleaveHandler&&(this._checkbox.removeEventListener("mouseleave",this._mouseleaveHandler),this._mouseleaveHandler=null),this._touchstartHandler&&(this._checkbox.removeEventListener("touchstart",this._touchstartHandler),this._touchstartHandler=null),this._touchendHandler&&(this._checkbox.removeEventListener("touchend",this._touchendHandler),this._touchendHandler=null),this._focusHandler&&(this._checkbox.removeEventListener("focus",this._focusHandler),this._focusHandler=null),this._blurHandler&&(this._checkbox.removeEventListener("blur",this._blurHandler),this._blurHandler=null));const t=this.querySelector(".mint-checkbox-wrapper");if(t){const e=t;e._wrapperClickHandler&&(t.removeEventListener("click",e._wrapperClickHandler),e._wrapperClickHandler=null)}}updateVisualState(){const t=this.querySelector(".mint-checkbox-wrapper"),e=t==null?void 0:t.querySelector("mint-icon");e&&(e.style.opacity=this._checked?"1":"0",e.style.transform=this._checked?"scale(1)":"scale(0.8)"),t&&(t.className=`mint-checkbox-wrapper ${this.getCheckboxClasses()}`,t.classList.contains("mint-checkbox-active")||(t.style.backgroundColor="",t.style.boxShadow=""))}toggle(){if(this._checkbox&&!this.isDisabled()){this._checkbox.checked=!this._checked,this._checked=this._checkbox.checked,this._checked?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this.updateVisualState(),this.dispatchEvent(new CustomEvent("input",{detail:{checked:this._checked},bubbles:!0,cancelable:!0,composed:!0}));const t=new CustomEvent("change",{detail:{checked:this._checked},bubbles:!0,cancelable:!0});this.dispatchEvent(t)}}_renderSkeleton(t){let e=this.querySelector(".mint-checkbox-skeleton-container");const i=this.querySelector(".mint-checkbox-container"),s=this.querySelector(".mint-checkbox-wrapper"),n=this.querySelector(".mint-checkbox-label-container");if(t){e||(e=document.createElement("div"),e.className="mint-checkbox-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center gap-2",i?i.appendChild(e):(this.style.position="relative",this.appendChild(e)));let r=e.querySelector(".mint-checkbox-skeleton-box");if(r||(r=document.createElement("div"),r.className="mint-checkbox-skeleton-box flex-shrink-0 w-5 h-5 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(r)),n){let a=e.querySelector(".mint-checkbox-skeleton-label");a||(a=document.createElement("div"),a.className="mint-checkbox-skeleton-label h-4 w-24 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(a))}e.style.display="flex",s&&(s.style.visibility="hidden",s.style.pointerEvents="none"),n&&(n.style.visibility="hidden",n.style.pointerEvents="none")}else e&&(e.style.display="none"),s&&(s.style.visibility="visible",s.style.pointerEvents="auto"),n&&(n.style.visibility="visible",n.style.pointerEvents="auto")}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-checkbox-label-container");!i&&t&&e&&(i=document.createElement("div"),i.className="mint-checkbox-label-container flex flex-col gap-0.5 flex-1",this.appendChild(i));let s=this.querySelector(".mint-checkbox-error");t&&e?(s?(s.classList.add("block","w-full"),s.style.display="block",(i&&s.parentElement!==i||i&&s.parentElement===i)&&i.appendChild(s)):(s=document.createElement("div"),s.className="mint-checkbox-error text-xs text-red-600 dark:text-red-400 block w-full",s.style.display="block",i?i.appendChild(s):this.appendChild(s)),s.textContent=e):s&&s.remove();const n=this.querySelector(".mint-checkbox-wrapper");n&&(n.className=`mint-checkbox-wrapper ${this.getCheckboxClasses()}`)}}customElements.get("mint-checkbox")||customElements.define("mint-checkbox",gt);class Nt extends HTMLElement{constructor(){super(),this._radio=null,this._checked=!1,this._changeHandler=null,this._clickHandler=null,this._focusHandler=null,this._blurHandler=null,this._keydownHandler=null}static get observedAttributes(){return["value","checked","disabled","loading","info"]}connectedCallback(){this.classList.add("inline-flex","items-start","gap-2","cursor-pointer","select-none");const t=this.getAttribute("checked");this._checked=t!==null&&t!=="false",this.render(),this._setupClickHandler()}disconnectedCallback(){this._clickHandler&&(this.removeEventListener("click",this._clickHandler),this._clickHandler=null),this._radio&&(this._changeHandler&&(this._radio.removeEventListener("change",this._changeHandler),this._changeHandler=null),this._focusHandler&&(this._radio.removeEventListener("focus",this._focusHandler),this._focusHandler=null),this._blurHandler&&(this._radio.removeEventListener("blur",this._blurHandler),this._blurHandler=null),this._keydownHandler&&(this._radio.removeEventListener("keydown",this._keydownHandler),this._keydownHandler=null))}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(t==="checked"&&(this._checked=i==="true",this._radio&&(this._radio.checked=this._checked),this._updateVisualState()),e!==i){if(t==="loading"){this.render();return}if(t==="info"){this.render();return}this.render()}}get checked(){try{return this._checked||!1}catch{return!1}}set checked(t){try{this._checked=!!t,t?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this._radio&&(this._radio.checked=this._checked),this.isConnected?requestAnimationFrame(()=>{this._updateVisualState()}):this._updateVisualState()}catch{}}getValue(){return this.getAttribute("value")||""}getInfo(){return this.getAttribute("info")||""}isDisabled(){const e=this.getAttribute("disabled")==="true",i=this.closest("mint-choice"),n=(i==null?void 0:i.getAttribute("disabled"))==="true";return e||n}_setupClickHandler(){this._clickHandler||(this._clickHandler=t=>{t.target!==this._radio&&(this.isDisabled()||this._radio&&(this._radio.click(),requestAnimationFrame(()=>{if(this._radio&&this._radio.checked!==this._checked){this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.removeAttribute("checked"),this._updateVisualState(),this._updateGroupState();const e=this.closest("mint-choice");e&&e.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0}))}})))},this.addEventListener("click",this._clickHandler))}render(){var f;const t=this.isLoading(),e=this.isDisabled(),i=this.getValue(),s=this.closest("mint-choice"),n=(s==null?void 0:s.getAttribute("name"))||"";let r="";const a=this.querySelector(".mint-choice-option-label");if(a)r=((f=a.textContent)==null?void 0:f.trim())||"";else{const _=this.querySelector(".mint-choice-option-label-container");Array.from(this.childNodes).forEach(g=>{var m;if(g!==_&&g.nodeType===Node.TEXT_NODE){const v=(m=g.textContent)==null?void 0:m.trim();v&&(r+=v)}})}const l=this.querySelectorAll(".mint-choice-option-wrapper");let o=null;if(l.length>0&&(this._radio&&(o=Array.from(l).find(_=>_.contains(this._radio))),o||(o=l[0]),l.forEach((_,g)=>{_!==o&&_.remove()})),o||(o=document.createElement("div"),o.className="mint-choice-option-wrapper",o.style.position="relative",this.insertBefore(o,this.firstChild)),o.className=`mint-choice-option-wrapper ${this._getWrapperClasses()}`,o.style.position="relative",this.querySelectorAll('input[type="radio"]').forEach(_=>{_!==this._radio&&_.remove()}),this._radio)this._radio.parentElement!==o&&o.appendChild(this._radio),this._radio&&this._changeHandler&&(this._radio.removeEventListener("change",this._changeHandler),this._radio.addEventListener("change",this._changeHandler)),this._radio&&(this._focusHandler||(this._focusHandler=_=>{const g=this.querySelector(".mint-choice-option-wrapper");g&&!this.isDisabled()&&g.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")}),this._blurHandler||(this._blurHandler=()=>{const _=this.querySelector(".mint-choice-option-wrapper");_&&_.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")}),this._keydownHandler||(this._keydownHandler=_=>{this.isDisabled()||(_.key==="ArrowDown"||_.key==="ArrowRight"?(_.preventDefault(),this._focusNextOption()):(_.key==="ArrowUp"||_.key==="ArrowLeft")&&(_.preventDefault(),this._focusPreviousOption()))}),this._radio.removeEventListener("focus",this._focusHandler),this._radio.removeEventListener("blur",this._blurHandler),this._radio.removeEventListener("keydown",this._keydownHandler),this._radio.addEventListener("focus",this._focusHandler),this._radio.addEventListener("blur",this._blurHandler),this._radio.addEventListener("keydown",this._keydownHandler));else{this._radio=document.createElement("input"),this._radio.type="radio",this._radio.className="sr-only",this._radio.style.position="absolute",this._radio.style.width="1px",this._radio.style.height="1px",this._radio.style.padding="0",this._radio.style.margin="-1px",this._radio.style.overflow="hidden",this._radio.style.clip="rect(0, 0, 0, 0)",this._radio.style.whiteSpace="nowrap",this._radio.style.border="0",o.appendChild(this._radio),this._changeHandler=g=>{const m=this._checked;this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.removeAttribute("checked"),this._updateVisualState(),this._updateGroupState();const v=this.closest("mint-choice");m!==this._checked&&v&&setTimeout(()=>{v.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0}))},0)},this._radio.addEventListener("change",this._changeHandler);const _=()=>{this._radio&&this._radio.checked!==this._checked&&(this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.removeAttribute("checked"),this._updateVisualState(),this._updateGroupState())};this._radio.addEventListener("click",_),this._focusHandler=g=>{const m=this.querySelector(".mint-choice-option-wrapper");m&&!this.isDisabled()&&m.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._radio.addEventListener("focus",this._focusHandler),this._blurHandler=()=>{const g=this.querySelector(".mint-choice-option-wrapper");g&&g.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._radio.addEventListener("blur",this._blurHandler),this._keydownHandler=g=>{this.isDisabled()||(g.key==="ArrowDown"||g.key==="ArrowRight"?(g.preventDefault(),this._focusNextOption()):(g.key==="ArrowUp"||g.key==="ArrowLeft")&&(g.preventDefault(),this._focusPreviousOption()))},this._radio.addEventListener("keydown",this._keydownHandler)}this._radio.name=n,this._radio.value=i,this._radio.checked!==this._checked?(this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.setAttribute("checked","false")):this._radio.checked=this._checked,this._radio.disabled=e,e?this._radio.setAttribute("tabindex","-1"):this._radio.removeAttribute("tabindex"),r?this._radio.setAttribute("aria-label",r):this._radio.removeAttribute("aria-label"),o.querySelectorAll(".mint-choice-option-indicator").forEach((_,g)=>{g>0&&_.remove()});let p=o.querySelector(".mint-choice-option-indicator");p||(p=document.createElement("div"),p.className="mint-choice-option-indicator",o.appendChild(p)),p.className="mint-choice-option-indicator w-2 h-2 rounded-full bg-white transition-all duration-200 pointer-events-none",p.style.position="absolute",p.style.top="50%",p.style.left="50%",p.style.transform=this._checked?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0)",p.style.opacity=this._checked?"1":"0",this._updateVisualState(),this._renderSkeleton(t);const d=this.getInfo();let u=this.querySelector(".mint-choice-option-label-container");if(r||d){u||(u=document.createElement("div"),u.className="mint-choice-option-label-container flex flex-col gap-0.5",this.appendChild(u),Array.from(this.childNodes).forEach(m=>{var v;m.nodeType===Node.TEXT_NODE&&((v=m.textContent)!=null&&v.trim())&&m!==u&&(m.textContent="")}));let _=u.querySelector(".mint-choice-option-label");r?(_||(_=document.createElement("span"),_.className="mint-choice-option-label",u.appendChild(_)),_.className=`mint-choice-option-label text-sm text-gray-900 dark:text-gray-100 ${e?"opacity-40":""}`,_.textContent=r):_&&_.remove();let g=u.querySelector(".mint-choice-option-info");d?(g||(g=document.createElement("span"),g.className="mint-choice-option-info text-xs text-gray-500 dark:text-gray-400 select-none",u.appendChild(g)),g.textContent=d,e?g.classList.add("opacity-40"):g.classList.remove("opacity-40")):g&&g.remove()}else u&&u.remove();e?(this.classList.add("cursor-not-allowed"),this.classList.remove("cursor-pointer")):(this.classList.add("cursor-pointer"),this.classList.remove("cursor-not-allowed")),this._updateVisualState()}_getWrapperClasses(){const t=this.isDisabled(),e=["inline-flex","items-center","justify-center","w-[1rem]","h-[1rem]","rounded-full","border-2","transition-all","duration-200","flex-shrink-0","mt-0.5"];return t&&e.push("opacity-40","cursor-not-allowed"),this._checked?e.push("bg-slate-800","dark:bg-slate-600","border-slate-800","dark:border-slate-600"):e.push("bg-white","dark:bg-gray-900","border-gray-300","dark:border-gray-500"),e.join(" ")}_updateVisualState(){const t=this.querySelector(".mint-choice-option-wrapper");t&&(t.className=`mint-choice-option-wrapper ${this._getWrapperClasses()}`);const e=this.querySelector(".mint-choice-option-indicator");e&&(e.style.opacity=this._checked?"1":"0",e.style.transform=this._checked?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0)")}_renderSkeleton(t){let e=this.querySelector(".mint-choice-option-skeleton-container");const i=this.querySelector(".mint-choice-option-wrapper");if(t){e||(e=document.createElement("div"),e.className="mint-choice-option-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center gap-2",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-choice-option-skeleton-radio");if(s||(s=document.createElement("div"),s.className="mint-choice-option-skeleton-radio flex-shrink-0 w-5 h-5 rounded-full bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(s)),e.style.display="flex",i){const n=i.querySelector('input[type="radio"]'),r=i.querySelector(".mint-choice-option-indicator");n&&(n.style.visibility="hidden"),r&&(r.style.visibility="hidden"),i.style.pointerEvents="none"}}else{if(e&&(e.style.display="none"),i){const n=i.querySelector('input[type="radio"]'),r=i.querySelector(".mint-choice-option-indicator");n&&(n.style.visibility="visible"),r&&(r.style.visibility="visible"),i.style.pointerEvents="auto"}const s=this.querySelector(".mint-choice-option-label");s&&!(i!=null&&i.contains(s))&&(s.style.visibility="visible",s.style.pointerEvents="auto")}}_updateGroupState(){var e;if(!((e=this._radio)!=null&&e.name))return;document.querySelectorAll(`input[type="radio"][name="${this._radio.name}"]`).forEach(i=>{if(i===this._radio)return;const s=i.closest("mint-choice-option");s&&s!==this&&(s._checked=i.checked,i.checked?s.setAttribute("checked","true"):s.removeAttribute("checked"),s._updateVisualState())})}_focusNextOption(){var s;if(!((s=this._radio)!=null&&s.name))return;const t=Array.from(document.querySelectorAll(`input[type="radio"][name="${this._radio.name}"]`)).filter(n=>!n.disabled),e=t.indexOf(this._radio);let i=null;if(e>=0&&e<t.length-1?i=t[e+1]:t.length>0&&(i=t[0]),i){const n=i.closest("mint-choice-option");if(i.checked=!0,n){const r=n._checked;if(n._checked=!0,n.setAttribute("checked","true"),n._changeHandler){const l=new Event("change",{bubbles:!0});n._changeHandler.call(n,l)}else n._updateVisualState(),n._updateGroupState();const a=n.closest("mint-choice");a&&!r&&setTimeout(()=>{a.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:!0,value:n.getValue()},bubbles:!0,cancelable:!0}))},0)}i.focus(),i.dispatchEvent(new Event("change",{bubbles:!0}))}}_focusPreviousOption(){var s;if(!((s=this._radio)!=null&&s.name))return;const t=Array.from(document.querySelectorAll(`input[type="radio"][name="${this._radio.name}"]`)).filter(n=>!n.disabled),e=t.indexOf(this._radio);let i=null;if(e>0?i=t[e-1]:t.length>0&&(i=t[t.length-1]),i){const n=i.closest("mint-choice-option");if(i.checked=!0,n){const r=n._checked;if(n._checked=!0,n.setAttribute("checked","true"),n._changeHandler){const l=new Event("change",{bubbles:!0});n._changeHandler.call(n,l)}else n._updateVisualState(),n._updateGroupState();const a=n.closest("mint-choice");a&&!r&&setTimeout(()=>{a.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:!0,value:n.getValue()},bubbles:!0,cancelable:!0}))},0)}i.focus(),i.dispatchEvent(new Event("change",{bubbles:!0}))}}}customElements.get("mint-choice-option")||customElements.define("mint-choice-option",Nt);class _t extends HTMLElement{constructor(){super(),this._optionsContainer=null}static get observedAttributes(){return["label","name","info","error","error-message","id","disabled","required","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","block","w-full"),this.render(),this.addEventListener("choice-change",t=>{var r;const i=((r=t.detail)==null?void 0:r.value)||this.getValue();(this.getAttribute("value")||"")!==i&&(i?this.setAttribute("value",i):this.removeAttribute("value"));const n=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(n),this.dispatchEvent(new CustomEvent("input",{detail:{value:i},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:{value:i},bubbles:!0,cancelable:!0,composed:!0}))})}disconnectedCallback(){}isLoading(){return this.hasAttribute("loading")}attributeChangedCallback(t,e,i){e!==i&&(t==="error"||t==="error-message"?this._renderErrorState():t==="loading"?(this.render(),this.querySelectorAll("mint-choice-option").forEach(n=>{this.isLoading()?n.setAttribute("loading","true"):n.removeAttribute("loading")})):(this.render(),t==="name"&&this.querySelectorAll("mint-choice-option").forEach(n=>{typeof n.render=="function"&&n.render()})))}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getName(){return this.getAttribute("name")||""}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getId(){return this.getAttribute("id")||""}isDisabled(){return this.getAttribute("disabled")==="true"}isRequired(){return this.getAttribute("required")==="true"}getValue(){const t=this.querySelector('input[type="radio"]:checked');return(t==null?void 0:t.value)||""}setValue(t){const e=this.querySelectorAll("mint-choice-option");e.forEach(i=>{if((i.getAttribute("value")||"")===t){const n=i;n.checked=!0;const r=i.querySelector('input[type="radio"]');r&&(r.checked=!0,r.dispatchEvent(new Event("change",{bubbles:!0})))}else{const n=i;n.checked=!1;const r=i.querySelector('input[type="radio"]');r&&(r.checked=!1)}}),requestAnimationFrame(()=>{e.forEach(i=>{typeof i._updateVisualState=="function"&&i._updateVisualState();const s=i.querySelector('input[type="radio"]');if(s){const n=i;s.checked!==n.checked&&(s.checked=n.checked)}})})}get value(){try{return this.getValue()||""}catch{return""}}set value(t){try{this.setValue(t||"")}catch{}}render(){const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.getId()||`mint-choice-${Math.random().toString(36).substr(2,9)}`;this.getId()||this.setAttribute("id",s);const n=this.isDisabled();let r=this.querySelector(".mint-choice-label-container");if(e||i){r||(r=document.createElement("div"),r.className="mint-choice-label-container flex flex-col gap-0.5 mb-2",this.insertBefore(r,this.firstChild));let o=r.querySelector(".mint-choice-label");e?(o||(o=document.createElement("label"),o.className="mint-choice-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",r.insertBefore(o,r.firstChild)),o.textContent=e,o.setAttribute("for",s),n?o.classList.add("opacity-40"):o.classList.remove("opacity-40")):o&&o.remove();let c=r.querySelector(".mint-choice-info");i?(c||(c=document.createElement("span"),c.className="mint-choice-info text-xs text-gray-500 dark:text-gray-400 select-none",r.appendChild(c)),c.textContent=i,n?c.classList.add("opacity-40"):c.classList.remove("opacity-40")):c&&c.remove()}else r&&r.remove();let a=this.querySelector(".mint-choice-options-wrapper");if(!a){a=document.createElement("div"),a.className="mint-choice-options-wrapper relative";const o=this.querySelector(".mint-choice-label-container");o&&o.parentElement===this?this.insertBefore(a,o.nextSibling):this.insertBefore(a,this.firstChild)}this._optionsContainer?this._optionsContainer.parentElement!==a&&a.appendChild(this._optionsContainer):(this._optionsContainer=document.createElement("div"),this._optionsContainer.className="mint-choice-options-container flex flex-col gap-3",a.appendChild(this._optionsContainer)),Array.from(this.children).filter(o=>o.tagName==="MINT-CHOICE-OPTION"&&o.parentElement!==this._optionsContainer).forEach(o=>{this._optionsContainer.appendChild(o)}),this._renderErrorState(),this._renderSkeleton(t)}_renderSkeleton(t){let e=this.querySelector(".mint-choice-skeleton-container");const i=this.querySelector(".mint-choice-options-wrapper"),s=this.querySelector(".mint-choice-options-container");if(t){if(e||(e=document.createElement("div"),e.className="mint-choice-skeleton-container absolute inset-0 z-10 pointer-events-none flex flex-col gap-3",i?i.appendChild(e):(this.style.position="relative",this.appendChild(e))),e.querySelectorAll(".mint-choice-option-skeleton").length===0)for(let r=0;r<3;r++){const a=document.createElement("div");a.className="mint-choice-option-skeleton flex items-center gap-3";const l=document.createElement("div");l.className="flex-shrink-0 w-5 h-5 rounded-full bg-gray-200 dark:bg-gray-700 animate-pulse",a.appendChild(l);const o=document.createElement("div");o.className="h-4 w-20 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",a.appendChild(o),e.appendChild(a)}e.style.display="flex",s&&(s.style.opacity="0",s.style.pointerEvents="none")}else e&&(e.style.display="none"),s&&(s.style.opacity="1",s.style.pointerEvents="auto")}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-choice-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-choice-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}}customElements.get("mint-choice")||customElements.define("mint-choice",_t);class mt extends HTMLElement{constructor(){super(),this._input=null,this._textarea=null,this._element=null,this._wrapper=null,this._icon=null,this._colorPicker=null,this._colorTextInput=null,this._colorContainer=null,this._colorPickerWrapper=null,this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null,this._focusHandler=null,this._blurHandler=null,this._clickHandler=null,this._clickOutsideHandler=null}static get observedAttributes(){return["type","placeholder","value","disabled","id","name","required","readonly","rows","icon","label","info","error","error-message","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render()}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){this._renderErrorState(),this._element&&(this._element.className=this.getInputClasses()),this._colorTextInput&&(this._colorTextInput.className=this.getInputClasses());return}if(t==="loading"){this.render();return}this.render()}}getType(){return this.getAttribute("type")||"text"}getRows(){const t=this.getAttribute("rows");return t?parseInt(t,10):3}_getNormalizedType(){const t=this.getType();return t==="datetime"?"datetime-local":t==="money"?"text":t==="textarea"?"textarea":t}_isTextarea(){return this.getType()==="textarea"}_isMoney(){return this.getType()==="money"}_isColor(){return this.getType()==="color"}_isNumber(){return this.getType()==="number"}getPlaceholder(){return this.getAttribute("placeholder")||""}getValue(){var t,e,i;return this._isColor()?((t=this._colorPicker)==null?void 0:t.value)||((e=this._colorTextInput)==null?void 0:e.value)||this.getAttribute("value")||"#000000":((i=this._element)==null?void 0:i.value)||this.getAttribute("value")||""}set value(t){try{this._isColor()?(this._colorPicker&&(this._colorPicker.value=t||"#000000"),this._colorTextInput&&(this._colorTextInput.value=t||"#000000")):this._element&&(this._element.value=t),t?this.setAttribute("value",t):this.removeAttribute("value")}catch{}}get value(){try{return this.getValue()||""}catch{return""}}isDisabled(){return this.getAttribute("disabled")==="true"}isReadonly(){return this.getAttribute("readonly")==="true"}isRequired(){return this.getAttribute("required")==="true"}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getId(){return this.getAttribute("id")||""}getName(){return this.getAttribute("name")||""}getIcon(){return this.getAttribute("icon")||""}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getInputClasses(){const t=this._isTextarea(),e=!!this.getIcon(),i=this._isColor(),s=this._isNumber(),n=this.hasError(),r=["w-full",e||i?"pl-10":"px-3.5",e||i?"pr-3.5":s?"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-gray-900","text-gray-900","dark:text-white",t?"transition-colors transition-opacity":"transition-all","duration-200","outline-none","focus:outline-none","disabled:opacity-40","disabled:cursor-not-allowed","readonly:cursor-default",t?"resize-y":"",s?"[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none":""],a=["border-2",n?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700"],l=["focus-visible:ring-2","focus-visible:ring-offset-1",n?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500"];return[...r,...a,...l].filter(Boolean).join(" ")}isLoading(){return this.getAttribute("loading")==="true"}render(){var v,b,k,w;this.getType();const t=this._getNormalizedType(),e=this._isTextarea(),i=this._isMoney(),s=this._isColor(),n=this.getPlaceholder(),r=this.isDisabled(),a=this.isReadonly(),l=this.isRequired(),o=this.getId(),c=this.getName(),h=this.getAttribute("value")||(s?"#000000":""),p=this.getRows(),d=this.getIcon(),u=this.getLabel(),f=this.getInfo(),_=this.isLoading();if(this._renderSkeleton(_),s){this._input&&(this._input.remove(),this._input=null),this._textarea&&(this._textarea.remove(),this._textarea=null),this._wrapper||(this._wrapper=document.createElement("div"),this._wrapper.className="relative w-full",this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null),this._colorPickerWrapper&&!s&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null),this._colorPickerWrapper||(this._colorPickerWrapper=document.createElement("div"),this._colorPickerWrapper.className="mint-color-picker-wrapper absolute left-[.65rem] top-1/2 -translate-y-1/2 w-6 h-6 rounded cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",this._colorPickerWrapper.style.backgroundColor=h||"#000000",this._wrapper.appendChild(this._colorPickerWrapper),this._colorPicker=document.createElement("input"),this._colorPicker.type="color",this._colorPicker.className="absolute inset-0 w-full h-full opacity-0 cursor-pointer",this._colorPicker.style.cssText="position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; z-index: 10; pointer-events: auto; margin: 0; padding: 0; border: none;",this._colorPickerWrapper.appendChild(this._colorPicker),this._focusHandler=y=>{this._colorPickerWrapper&&this._colorPicker&&this._colorPicker.matches(":focus-visible")&&requestAnimationFrame(()=>{var C;this._colorPicker&&this._colorPicker.matches(":focus-visible")&&((C=this._colorPickerWrapper)==null||C.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500"))})},this._blurHandler=()=>{this._colorPickerWrapper&&this._colorPickerWrapper.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._colorPicker.addEventListener("focus",this._focusHandler),this._colorPicker.addEventListener("blur",this._blurHandler),this._colorPicker.addEventListener("input",()=>{var C;const y=((C=this._colorPicker)==null?void 0:C.value)||"#000000";this._colorPickerWrapper&&(this._colorPickerWrapper.style.backgroundColor=y),this._colorTextInput&&(this._colorTextInput.value=y),this.setAttribute("value",y),this.dispatchEvent(new CustomEvent("input",{detail:{value:y},bubbles:!0,cancelable:!0}))}),this._colorPicker.addEventListener("change",()=>{var C;const y=((C=this._colorPicker)==null?void 0:C.value)||"#000000";this._colorPickerWrapper&&(this._colorPickerWrapper.style.backgroundColor=y),this.setAttribute("value",y),this.dispatchEvent(new CustomEvent("change",{detail:{value:y},bubbles:!0,cancelable:!0}))})),this._colorTextInput||(this._colorTextInput=document.createElement("input"),this._colorTextInput.type="text",this._colorTextInput.className=this.getInputClasses(),this._colorTextInput.placeholder=n||"#000000",this._colorTextInput.pattern="^#[0-9A-Fa-f]{6}$",this._wrapper.appendChild(this._colorTextInput),this._colorTextInput.addEventListener("input",()=>{var C;const y=((C=this._colorTextInput)==null?void 0:C.value)||"";/^#[0-9A-Fa-f]{6}$/.test(y)&&(this._colorPicker&&(this._colorPicker.value=y),this.setAttribute("value",y),this.dispatchEvent(new CustomEvent("input",{detail:{value:y},bubbles:!0,cancelable:!0})))}),this._colorTextInput.addEventListener("blur",()=>{var C,D;const y=((C=this._colorTextInput)==null?void 0:C.value)||"";/^#[0-9A-Fa-f]{6}$/.test(y)?(this._colorPicker&&(this._colorPicker.value=y),this.setAttribute("value",y)):this._colorPicker&&this._colorTextInput&&(this._colorTextInput.value=this._colorPicker.value),this.dispatchEvent(new CustomEvent("change",{detail:{value:((D=this._colorPicker)==null?void 0:D.value)||"#000000"},bubbles:!0,cancelable:!0}))}));const E=h||"#000000";if(this._colorPicker&&this._colorPicker.value!==E&&(this._colorPicker.value=E),this._colorPickerWrapper&&(this._colorPickerWrapper.style.backgroundColor=E),this._colorTextInput&&this._colorTextInput.value!==E&&(this._colorTextInput.value=E),this._colorPicker&&(this._colorPicker.disabled=r),this._colorPickerWrapper&&(r?(this._colorPickerWrapper.classList.add("opacity-40","cursor-not-allowed"),this._colorPickerWrapper.classList.remove("cursor-pointer")):(this._colorPickerWrapper.classList.remove("opacity-40","cursor-not-allowed"),this._colorPickerWrapper.classList.add("cursor-pointer"))),this._colorTextInput&&(this._colorTextInput.disabled=r,this._colorTextInput.readOnly=a,this._colorTextInput.required=l),this._colorTextInput){const y=this._colorTextInput;o?y.id=o:y.removeAttribute("id"),c?y.name=c:y.removeAttribute("name"),y.setAttribute("aria-invalid",this.hasError()?"true":"false"),this._element=y}this._renderErrorState();return}if(this._wrapper||(this._wrapper=document.createElement("div"),this._wrapper.className="relative w-full",this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null,this._colorPicker=null,this._colorTextInput=null),this._colorPickerWrapper&&!s&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null,this._colorPicker=null,this._colorTextInput=null),d&&!e?this._icon?this._icon.setAttribute("name",d):(this._icon=document.createElement("mint-icon"),this._icon.setAttribute("name",d),this._icon.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",this._wrapper.appendChild(this._icon)):this._icon&&(this._icon.remove(),this._icon=null),this._isNumber()&&!e){if(!this._numberSpinnerContainer){this._numberSpinnerContainer=document.createElement("div"),this._numberSpinnerContainer.className="absolute right-1 top-1/2 -translate-y-1/2 flex flex-col h-8 pointer-events-none",this._wrapper.appendChild(this._numberSpinnerContainer),this._numberIncrementButton=document.createElement("button"),this._numberIncrementButton.type="button",this._numberIncrementButton.className="flex items-center justify-center w-5 h-4 text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors pointer-events-auto bg-gray-100 dark:bg-gray-600 active:bg-gray-200 dark:active:bg-gray-500 rounded";const E=document.createElement("mint-icon");E.setAttribute("name","caret-up"),E.className="w-[1rem] h-[1rem]",this._numberIncrementButton.appendChild(E),this._numberSpinnerContainer.appendChild(this._numberIncrementButton),this._numberDecrementButton=document.createElement("button"),this._numberDecrementButton.type="button",this._numberDecrementButton.className="flex items-center justify-center w-5 h-4 text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors pointer-events-auto bg-gray-100 dark:bg-gray-600 active:bg-gray-200 dark:active:bg-gray-500 rounded";const y=document.createElement("mint-icon");y.setAttribute("name","caret-down"),y.className="w-[1rem] h-[1rem]",this._numberDecrementButton.appendChild(y),this._numberSpinnerContainer.appendChild(this._numberDecrementButton),this._numberIncrementButton.addEventListener("click",C=>{if(C.preventDefault(),C.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){const D=parseFloat(this._input.value)||0,$=parseFloat(this._input.step)||1,A=this._input.min?parseFloat(this._input.min):void 0,N=this._input.max?parseFloat(this._input.max):void 0;let S=D+$;N!==void 0&&S>N&&(S=N),A!==void 0&&S<A&&(S=A),this._input.value=S.toString(),this.setAttribute("value",S.toString()),this._input.dispatchEvent(new Event("input",{bubbles:!0})),this._input.dispatchEvent(new Event("change",{bubbles:!0}))}}),this._numberDecrementButton.addEventListener("click",C=>{if(C.preventDefault(),C.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){const D=parseFloat(this._input.value)||0,$=parseFloat(this._input.step)||1,A=this._input.min?parseFloat(this._input.min):void 0,N=this._input.max?parseFloat(this._input.max):void 0;let S=D-$;A!==void 0&&S<A&&(S=A),N!==void 0&&S>N&&(S=N),this._input.value=S.toString(),this.setAttribute("value",S.toString()),this._input.dispatchEvent(new Event("input",{bubbles:!0})),this._input.dispatchEvent(new Event("change",{bubbles:!0}))}})}this._numberIncrementButton&&(this._numberIncrementButton.disabled=r||a),this._numberDecrementButton&&(this._numberDecrementButton.disabled=r||a)}else this._numberSpinnerContainer&&(this._numberSpinnerContainer.remove(),this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null);if(e){if(this._input&&(this._input.remove(),this._input=null),this._textarea||(this._textarea=document.createElement("textarea"),this._wrapper.appendChild(this._textarea),this.setupEventListeners()),this._element=this._textarea,this._textarea.placeholder=n,this._textarea.disabled=r,this._textarea.readOnly=a,this._textarea.required=l,this._textarea.rows=p,this._textarea.setAttribute("aria-invalid",this.hasError()?"true":"false"),h!==this._textarea.value&&(this._textarea.value=h),o?this._textarea.id=o:this._textarea.removeAttribute("id"),c?this._textarea.name=c:this._textarea.removeAttribute("name"),this._textarea.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){const E=this.firstChild.textContent;E&&!this._textarea.value&&(this._textarea.value=E.trim()),this.removeChild(this.firstChild)}}else if(this._textarea&&(this._textarea.remove(),this._textarea=null),this._input||(this._input=document.createElement("input"),this._wrapper.appendChild(this._input),this.setupEventListeners()),this._element=this._input,this._input.type=t,this._input.placeholder=n,this._input.disabled=r,this._input.readOnly=a,this._input.required=l,this._input.setAttribute("aria-invalid",this.hasError()?"true":"false"),i?(this._input.inputMode="decimal",this._input.pattern="[0-9]*\\.?[0-9]*"):(this._input.removeAttribute("inputmode"),this._input.removeAttribute("pattern")),h!==this._input.value&&(this._input.value=h),o?this._input.id=o:this._input.removeAttribute("id"),c?this._input.name=c:this._input.removeAttribute("name"),this._input.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){const E=this.firstChild.textContent;E&&!this._input.value&&(this._input.value=E.trim()),this.removeChild(this.firstChild)}let m=this.querySelector(".mint-input-label-container");if(u||f){m||(m=document.createElement("div"),m.className="mint-input-label-container flex flex-col gap-0.5 mb-[.25rem]",this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(m,this._wrapper):this.insertBefore(m,this.firstChild));let E=m.querySelector(".mint-input-label");if(u){E||(E=document.createElement("label"),E.className="mint-input-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",m.insertBefore(E,m.firstChild)),E.textContent=u;const C=o||((v=this._element)==null?void 0:v.id)||((b=this._colorTextInput)==null?void 0:b.id)||((k=this._input)==null?void 0:k.id)||((w=this._textarea)==null?void 0:w.id);if(C)E.setAttribute("for",C);else{const D=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._element?this._element.id=D:this._colorTextInput?this._colorTextInput.id=D:this._input?this._input.id=D:this._textarea&&(this._textarea.id=D),E.setAttribute("for",D)}r?E.classList.add("opacity-40"):E.classList.remove("opacity-40")}else E&&E.remove();let y=m.querySelector(".mint-input-info");f?(y||(y=document.createElement("span"),y.className="mint-input-info text-xs text-gray-500 dark:text-gray-400 select-none",m.appendChild(y)),y.textContent=f,r?y.classList.add("opacity-40"):y.classList.remove("opacity-40")):y&&y.remove()}else m&&m.remove();this._renderErrorState(),this._renderSkeleton(_)}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-input-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-input-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}setupEventListeners(){this._element&&(this._element.addEventListener("input",()=>{var i;const t=((i=this._element)==null?void 0:i.value)||"";t?this.setAttribute("value",t):this.removeAttribute("value");const e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e),this.dispatchEvent(new CustomEvent("input",{detail:{value:t},bubbles:!0,cancelable:!0,composed:!0}))}),this._element.addEventListener("blur",()=>{var e;const t=((e=this._element)==null?void 0:e.value)||"";t?this.setAttribute("value",t):this.removeAttribute("value"),this.dispatchEvent(new CustomEvent("change",{detail:{value:t},bubbles:!0,cancelable:!0}))}))}removeEventListeners(){this._colorPicker&&(this._focusHandler&&(this._colorPicker.removeEventListener("focus",this._focusHandler),this._focusHandler=null),this._blurHandler&&(this._colorPicker.removeEventListener("blur",this._blurHandler),this._blurHandler=null))}focus(){var t;this._isColor()&&this._colorTextInput?this._colorTextInput.focus():(t=this._element)==null||t.focus()}blur(){var t;this._isColor()&&this._colorTextInput?this._colorTextInput.blur():(t=this._element)==null||t.blur()}_renderSkeleton(t){let e=this.querySelector(".mint-input-skeleton-container");const i=this._wrapper||this.querySelector(".relative.w-full");if(t){e||(e=document.createElement("div"),e.className="mint-input-skeleton-container absolute inset-0 z-10 pointer-events-none",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-input-skeleton");if(!s){s=document.createElement("div"),s.className="mint-input-skeleton w-full rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse";const n=this._isTextarea(),r=this.getRows();if(n){const a=r*24+12;s.style.height=`${a}px`}else s.style.height="2.2rem";e.appendChild(s)}e.style.display="block",this._element&&(this._element.style.opacity="0",this._element.style.pointerEvents="none"),this._colorTextInput&&(this._colorTextInput.style.opacity="0",this._colorTextInput.style.pointerEvents="none")}else e&&(e.style.display="none"),this._element&&(this._element.style.opacity="1",this._element.style.pointerEvents="auto"),this._colorTextInput&&(this._colorTextInput.style.opacity="1",this._colorTextInput.style.pointerEvents="auto")}}customElements.get("mint-input")||customElements.define("mint-input",mt);class bt extends HTMLElement{constructor(){super(),this._input=null,this._textInput=null,this._popover=null,this._calendarContainer=null,this._iconButton=null,this._hiddenInput=null,this._startPartInputs=[],this._endPartInputs=[],this._displayEl=null,this._inputsWrapperEl=null,this._fieldsContainer=null,this._resetHandler=null,this._isInputMode=!1,this._currentMonth=new Date().getMonth(),this._currentYear=new Date().getFullYear(),this._viewMode="calendar",this._selectedStartDate=null,this._selectedEndDate=null,this._isRange=!1,this._hoveredDate=null,this._isHandlingClick=!1,this._resizeObserver=null,this._popoverObserver=null,this._focusTrapHandler=null,this._escapeHandler=null}static get observedAttributes(){return["value","label","info","disabled","id","name","required","readonly","format","min","max","range","shortcuts","display-format","error","error-message","loading","selection-mode","week-start-day","mode","disabled-dates"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render(),this._setupPopoverWithRetry(),this._attachFormResetListener()}disconnectedCallback(){if(this._popoverObserver&&(this._popoverObserver.disconnect(),this._popoverObserver=null),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._removeFocusTrap(),this._resetHandler){const t=this.closest("form");t&&t.removeEventListener("reset",this._resetHandler),this._resetHandler=null}}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){const s=this.hasError(),n=this.getErrorMessage();this._applyErrorVisuals(s,n,this.isDisabled());return}if(t==="loading"){this.render();return}if(t==="mode"||t==="format"){const s=this.getMode();s==="month"?this._viewMode="month":s==="year"?this._viewMode="year":this._viewMode="calendar",this._popover&&this._calendarContainer&&this._buildCalendar()}this.render(),this._input&&this._setupPopoverWithRetry()}}getValue(){return this.getAttribute("value")||""}setValue(t){t?(this.setAttribute("value",t),this._textInput&&(this._textInput.value=t),this._parseValue(t)):(this.removeAttribute("value"),this._textInput&&(this._textInput.value=""),this._selectedStartDate=null,this._selectedEndDate=null),this._buildCalendar(),this._updateDisplayText()}get value(){try{return this.getValue()||""}catch{return""}}set value(t){try{this.setValue(t||"")}catch{}}getFormat(){return this.getAttribute("format")||"mm/dd/yyyy"}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}isDisabled(){return this.getAttribute("disabled")==="true"}isReadonly(){return this.getAttribute("readonly")==="true"}isRequired(){return this.getAttribute("required")==="true"}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}isRange(){return this.getAttribute("range")==="true"}getId(){return this.getAttribute("id")||""}getName(){return this.getAttribute("name")||""}getMin(){return this.getAttribute("min")||""}getMax(){return this.getAttribute("max")||""}getDisabledDates(){const t=this.getAttribute("disabled-dates");if(!t)return[];try{const e=JSON.parse(t),i=this.getFormat();return e.map(s=>this._parseDateString(s,i)).filter(s=>s!==null)}catch{return[]}}getDisabledDateStrings(){const t=this.getAttribute("disabled-dates");if(!t)return[];try{return JSON.parse(t)}catch{return[]}}disableDate(t){const e=this.getFormat(),i=this.getDisabledDateStrings(),s=Array.isArray(t)?t:[t],n=[];for(const r of s){const a=this._parseDateString(r,e);if(a){const l=this._formatDate(a,e);i.includes(l)||n.push(l)}}if(n.length>0){const r=[...i,...n];this.setAttribute("disabled-dates",JSON.stringify(r)),this._buildCalendar()}}enableDate(t){const e=this.getFormat(),i=this.getDisabledDateStrings(),s=Array.isArray(t)?t:[t],n=[];for(const r of s){const a=this._parseDateString(r,e);if(a){const l=this._formatDate(a,e);n.push(l)}}if(n.length>0){const r=i.filter(a=>!n.includes(a));r.length===0?this.removeAttribute("disabled-dates"):this.setAttribute("disabled-dates",JSON.stringify(r)),this._buildCalendar()}}getSelectionMode(){const t=this.getAttribute("selection-mode");return t==="week"||t==="month"?t:"day"}getMode(){const t=this.getAttribute("mode");if(t==="month"||t==="year")return t;const e=this.getFormat().toLowerCase(),i=e.includes("d"),s=e.includes("m");return!i&&!s?"year":!i&&s?"month":"default"}getWeekStartDay(){var i;const t=(i=this.getAttribute("week-start-day"))==null?void 0:i.toLowerCase();return{sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6}[t||"sunday"]??0}getDisplayFormat(){return this.getAttribute("display-format")||"F j, Y"}getShortcuts(){const t=this.getAttribute("shortcuts");if(!t)return[];try{const e=JSON.parse(t);if(Array.isArray(e))return e.map(i=>({label:i.label,action:this._createShortcutAction(i.action)}))}catch{const i=t.trim();if(i&&typeof window[i]=="function"){const s=window[i]();if(Array.isArray(s))return s.map(n=>({label:n.label,action:typeof n.action=="function"?n.action:this._createShortcutAction(n.action)}))}}return[]}_createShortcutAction(t){return typeof t=="function"?t:typeof t=="string"&&typeof window[t]=="function"?window[t]:()=>null}_getDefaultShortcuts(){const t=[{label:"Today",action:()=>new Date}];return this._isRange&&t.push({label:"This Week",action:()=>{const e=new Date,i=e.getDay(),s=new Date(e);s.setDate(e.getDate()-i),s.setHours(0,0,0,0);const n=new Date(s);return n.setDate(s.getDate()+6),n.setHours(23,59,59,999),{start:s,end:n}}},{label:"This Month",action:()=>{const e=new Date,i=new Date(e.getFullYear(),e.getMonth(),1),s=new Date(e.getFullYear(),e.getMonth()+1,0);return s.setHours(23,59,59,999),{start:i,end:s}}}),t}_getFormatTokens(t){const e=[];let i=0;const s=t.toLowerCase();for(;i<s.length;){const n=s[i];if(n==="d"||n==="m"||n==="y"){let r=1,a=i+1;for(;a<s.length&&s[a]===n;)r++,a++;e.push({type:"part",part:n,len:r}),i=a}else e.push({type:"sep",value:t[i]}),i++}return e}_createPartInput(t,e,i,s,n){const r=document.createElement("input");return r.type="text",r.inputMode="numeric",r.pattern="\\d*",r.maxLength=t,r.placeholder=e,r.className="bg-transparent border-none outline-none text-center text-sm font-medium p-0 m-0 focus:outline-none focus:ring-0 disabled:opacity-40 disabled:cursor-not-allowed",r.disabled=i||s,r.readOnly=s,r.required=n,t===4?r.className+=" w-[40px]":t===2&&(r.className+=" w-[30px]"),r}_buildValueFromParts(t,e){let i=0;return e.map(s=>{var r;if(s.type==="sep")return s.value;const n=((r=t[i])==null?void 0:r.value)||"";return i++,n}).join("")}_applyDateToParts(t,e,i,s){if(!e.length)return;if(!t){e.forEach(l=>l.value="");return}const n=this._formatDate(t,s);let r=0,a=0;i.forEach(l=>{if(l.type==="sep")r+=l.value.length;else{const o=n.substr(r,l.len);e[a]&&(e[a].value=o),a++,r+=l.len}})}_syncHiddenInput(){if(!this._hiddenInput)return;const t=this.getFormat(),e=this._getFormatTokens(t),i=this._buildValueFromParts(this._startPartInputs,e);if(this._isRange){const s=this._buildValueFromParts(this._endPartInputs,e);this._hiddenInput.value=s?`${i} - ${s}`:i}else this._hiddenInput.value=i}_focusNext(t,e){if(e+1<t.length){const i=t[e+1];i.focus(),i.setSelectionRange(0,i.value.length)}}_focusPrev(t,e){if(e-1>=0){const i=t[e-1];i.focus(),i.setSelectionRange(i.value.length,i.value.length)}}_attachPartInputHandlers(t,e,i){t.forEach((s,n)=>{const r=s.maxLength||2;s.addEventListener("input",()=>{s.value=s.value.replace(/\D/g,"").slice(0,r),s.value.length>=r&&this._focusNext(t,n),this._syncHiddenInput()}),s.addEventListener("keydown",a=>{a.key==="Backspace"&&s.selectionStart===0&&s.selectionEnd===0&&this._focusPrev(t,n),a.key==="ArrowLeft"&&s.selectionStart===0&&s.selectionEnd===0&&(this._focusPrev(t,n),a.preventDefault()),a.key==="ArrowRight"&&s.selectionStart===s.value.length&&s.selectionEnd===s.value.length&&(this._focusNext(t,n),a.preventDefault())}),s.addEventListener("blur",a=>{this._syncHiddenInput();const l=a.relatedTarget,o=l&&(this._startPartInputs.includes(l)||this._endPartInputs.includes(l));setTimeout(()=>{var h;if(!(this._startPartInputs.some(p=>p===document.activeElement)||this._endPartInputs.some(p=>p===document.activeElement))&&(o||this._handleBlur(((h=this._hiddenInput)==null?void 0:h.value)||""),this._exitInputMode(),!o&&this._hiddenInput)){const p=new FocusEvent("blur",{bubbles:!0,cancelable:!0,relatedTarget:a.relatedTarget});this._hiddenInput.dispatchEvent(p)}},0)})})}_splitRangeInput(t,e){const i=t.split(/\s*-\s*/);return i.length>=2?[i[0],i.slice(1).join("-")]:[t]}_parseValue(t){const e=this.getFormat(),i=this._getFormatTokens(e),s=this.getSelectionMode();if(this._isRange||s==="week"||s==="month"){const[r,a]=this._splitRangeInput(t,e),l=r?this._parseDateString(r,e):null,o=a?this._parseDateString(a,e):null;if(l&&o){const[c,h]=l<=o?[l,o]:[o,l];this._selectedStartDate=c,this._selectedEndDate=h,this._currentMonth=c.getMonth(),this._currentYear=c.getFullYear()}else l&&(this._selectedStartDate=l,this._selectedEndDate=null,this._currentMonth=l.getMonth(),this._currentYear=l.getFullYear());this._applyDateToParts(this._selectedStartDate,this._startPartInputs,i,e),this._applyDateToParts(this._selectedEndDate,this._endPartInputs,i,e)}else{const r=this._parseDateString(t,e);r&&!isNaN(r.getTime())?(this._selectedStartDate=r,this._selectedEndDate=null,this._currentMonth=r.getMonth(),this._currentYear=r.getFullYear(),this._applyDateToParts(r,this._startPartInputs,i,e)):this._applyDateToParts(null,this._startPartInputs,i,e)}this._syncHiddenInput(),this._updateDisplayText()}_parseDateString(t,e){const i=/[\/\-\.\s]+/;if(i.test(t)){const v=t.split(i).filter(k=>k.length>0),b=e.split(/[\/\-\.\s]+/).filter(k=>k.length>0);if(v.length===b.length){let k=0,w=0,E=0;for(let D=0;D<b.length;D++){const $=b[D].toLowerCase(),A=v[D];if($.includes("d"))k=parseInt(A,10);else if($.includes("m"))w=parseInt(A,10)-1;else if($.includes("y")){let N=parseInt(A,10);const S=$.length,M=A.length;M===2&&S===4?N=Math.floor(new Date().getFullYear()/100)*100+N:M===2&&S===2&&(N=Math.floor(new Date().getFullYear()/100)*100+N),E=N}}const y=b.some(D=>D.toLowerCase().includes("d")),C=b.some(D=>D.toLowerCase().includes("m"));if(y||(k=1),C||(w=0),w>=0&&w<=11&&E){const D=new Date(E,w,k);if(!isNaN(D.getTime()))return y&&D.getDate()!==k||D.getMonth()!==w||D.getFullYear()!==E?null:D}}}const n=t.replace(/[\/\-\.]/g,""),r=e.replace(/[\/\-\.]/g,"").toLowerCase();let a=r.indexOf("d"),l=r.indexOf("m"),o=r.indexOf("y");const c=[{char:"d",index:a},{char:"m",index:l},{char:"y",index:o}].sort((v,b)=>v.index-b.index);let h=0,p=0,d=0,u=0;r.length,n.length;for(const v of c)if(v.char==="d"){const b=r.lastIndexOf("d")-r.indexOf("d")+1,k=n.substr(u,b);if(k.length===0)return null;h=parseInt(k,10),u+=k.length}else if(v.char==="m"){const b=r.lastIndexOf("m")-r.indexOf("m")+1,k=n.substr(u,b);if(k.length===0)return null;p=parseInt(k,10)-1,u+=k.length}else if(v.char==="y"){const b=r.lastIndexOf("y")-r.indexOf("y")+1,k=n.substr(u),w=Math.min(b,k.length),E=k.substr(0,w);if(E.length===0)return null;let y=parseInt(E,10);w===2&&b===4?y=Math.floor(new Date().getFullYear()/100)*100+y:w===2&&b===2&&(y=Math.floor(new Date().getFullYear()/100)*100+y),d=y,u+=w}const f=e.toLowerCase(),_=f.includes("d"),g=f.includes("m");if(_||(h=1),g||(p=0),p<0||p>11||!d)return null;const m=new Date(d,p,h);return isNaN(m.getTime())||_&&m.getDate()!==h||m.getMonth()!==p||m.getFullYear()!==d?null:m}_formatDate(t,e){const i=t.getDate(),s=t.getMonth()+1,n=t.getFullYear(),r=e.toLowerCase();let a=e;return r.includes("dd")?a=a.replace(/dd/gi,String(i).padStart(2,"0")):r.includes("d")&&(a=a.replace(/d/gi,String(i))),r.includes("mm")?a=a.replace(/mm/gi,String(s).padStart(2,"0")):r.includes("m")&&(a=a.replace(/m/gi,String(s))),r.includes("yyyy")?a=a.replace(/yyyy/gi,String(n)):r.includes("yy")&&(a=a.replace(/yy/gi,String(n).substr(2))),a}_formatDatePhp(t,e){const i=t.getDate(),s=t.getMonth()+1,n=t.getFullYear(),r=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],l=["January","February","March","April","May","June","July","August","September","October","November","December"],o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=(d,u=2)=>d.toString().padStart(u,"0"),h=d=>{const u=d%10,f=d%100;return u===1&&f!==11?"st":u===2&&f!==12?"nd":u===3&&f!==13?"rd":"th"};let p="";for(let d=0;d<e.length;d++){const u=e[d];if(u==="\\"&&d+1<e.length){p+=e[d+1],d++;continue}switch(u){case"Y":p+=n.toString();break;case"y":p+=n.toString().slice(-2);break;case"m":p+=c(s);break;case"n":p+=s.toString();break;case"M":p+=o[s-1];break;case"F":p+=l[s-1];break;case"d":p+=c(i);break;case"j":p+=i.toString();break;case"D":p+=a[t.getDay()];break;case"l":p+=r[t.getDay()];break;case"S":p+=h(i);break;default:p+=u;break}}return p}_validateDateString(t,e){const i=this._parseDateString(t,e);return i!==null&&!isNaN(i.getTime())}render(){const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.getValue(),n=this.isDisabled(),r=this.isReadonly(),a=this.isRequired(),l=this.getId(),o=this.getName(),c=this.getFormat(),h=this.hasError(),p=this.getErrorMessage(),d=this.getSelectionMode();this._isRange=this.isRange()||d==="week"||d==="month",this._input||(this._input=document.createElement("div"),this._input.className="relative w-full",this.appendChild(this._input));let u=this.querySelector(".mint-date-picker-label-container");if(e||i){u||(u=document.createElement("div"),u.className="mint-date-picker-label-container flex flex-col gap-0.5 mb-[.25rem]",this.contains(this._input)?this.insertBefore(u,this._input):this.appendChild(u));let b=u.querySelector(".mint-date-picker-label");e?(b||(b=document.createElement("label"),b.className="mint-date-picker-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",u.insertBefore(b,u.firstChild)),b.textContent=e,l&&this._textInput&&b.setAttribute("for",l)):b&&b.remove();let k=u.querySelector(".mint-date-picker-info");i?(k||(k=document.createElement("span"),k.className="mint-date-picker-info text-xs text-gray-500 dark:text-gray-400 select-none",u.appendChild(k)),k.textContent=i):k&&k.remove()}else u&&u.remove();this._hiddenInput||(this._hiddenInput=document.createElement("input"),this._hiddenInput.type="hidden",this._hiddenInput.value=s||"",this._textInput=this._hiddenInput,this._input.appendChild(this._hiddenInput)),l&&(this._hiddenInput.id=l),o&&(this._hiddenInput.name=o),this._hiddenInput.value=s||"",this._hiddenInput.setAttribute("aria-invalid",h?"true":"false");let f=this._input.querySelector(".mint-date-fields");f||(f=document.createElement("div"),this._input.appendChild(f)),this._fieldsContainer=f,this._applyErrorVisuals(h,p,n),f.innerHTML="",this._displayEl=document.createElement("div");const _=r?"select-text":"select-none";this._displayEl.className=`flex-1 text-gray-900 dark:text-white ${r?"cursor-default":"cursor-text"} ${_} focus:outline-none`,this._displayEl.tabIndex=n||r?-1:0,this._displayEl.addEventListener("click",()=>{n||r||this._enterInputMode()}),this._displayEl.addEventListener("keydown",b=>{n||r||(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),this._enterInputMode())}),this._inputsWrapperEl=document.createElement("div"),this._isRange?this._inputsWrapperEl.className="flex items-center gap-1 w-full":this._inputsWrapperEl.className="flex items-center gap-1 w-full";const g=this._getFormatTokens(c);this._startPartInputs=[],this._endPartInputs=[];const m=b=>{const k=document.createDocumentFragment();return g.forEach(w=>{if(w.type==="sep"){const E=document.createElement("span");E.textContent=w.value,E.className="text-gray-400 dark:text-gray-500 select-none",k.appendChild(E)}else{const E=w.part==="d"?"dd":w.part==="m"?"mm":w.len===2?"yy":"yyyy",y=this._createPartInput(w.len,E,n,r,a);b==="start"?this._startPartInputs.push(y):this._endPartInputs.push(y),k.appendChild(y)}}),k};if(this._isRange){const b=document.createElement("div");b.className="flex items-center gap-1 flex-shrink-0",b.appendChild(m("start")),this._inputsWrapperEl.appendChild(b);const k=document.createElement("span");k.textContent=" - ",k.className="text-gray-400 dark:text-gray-500 select-none flex-shrink-0",this._inputsWrapperEl.appendChild(k);const w=document.createElement("div");w.className="flex items-center gap-1 flex-shrink-0",w.appendChild(m("end")),this._inputsWrapperEl.appendChild(w)}else this._inputsWrapperEl.appendChild(m("start"));const v=document.createElement("div");if(v.className="flex flex-col w-full",this._displayEl.style.display=this._isInputMode?"none":"flex",this._inputsWrapperEl.style.display=this._isInputMode?"flex":"none",v.appendChild(this._displayEl),v.appendChild(this._inputsWrapperEl),f.appendChild(v),this._isRange&&this._inputsWrapperEl&&this._setupContainerObserver(),f.addEventListener("click",()=>{this._isInputMode||n||r||this._enterInputMode()}),this._attachPartInputHandlers(this._startPartInputs,g,f),this._isRange&&this._attachPartInputHandlers(this._endPartInputs,g,f),this._parseValue(s),this._syncHiddenInput(),this._updateDisplayText(),this._iconButton)this._iconButton.disabled=n||r,!n&&!r?this._iconButton.tabIndex=0:this._iconButton.tabIndex=-1;else{this._iconButton=document.createElement("button"),this._iconButton.type="button",this._iconButton.tabIndex=0,this._iconButton.className="absolute left-2 top-[.55rem] text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer z-10 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 pointer-events-auto disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center rounded-sm";const b=`date-icon-${Math.random().toString(36).substr(2,9)}`;this._iconButton.id=b;const k=document.createElement("mint-icon");k.setAttribute("name","calendar"),k.className="w-4 h-4 pointer-events-none",this._iconButton.appendChild(k),this._iconButton.addEventListener("click",()=>{n||r||this._enterInputMode()}),this._input.prepend(this._iconButton),this._iconButton.disabled=n||r}this._renderErrorState(h,p),this._renderSkeleton(t)}_renderErrorState(t,e){let i=this.querySelector(".mint-date-picker-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-date-picker-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}_applyErrorVisuals(t,e,i){if(this._renderErrorState(t,e),this._fieldsContainer){const s=this._getFieldContainerClass(t,i);this._fieldsContainer.className=s}this._hiddenInput&&this._hiddenInput.setAttribute("aria-invalid",t?"true":"false")}_attachFormResetListener(){const t=this.closest("form");!t||this._resetHandler||(this._resetHandler=()=>{this.setValue(""),this._clearPartInputs(this._startPartInputs),this._clearPartInputs(this._endPartInputs),this._isInputMode=!1,this._updateDisplayText(),this._applyErrorVisuals(!1,"",this.isDisabled())},t.addEventListener("reset",this._resetHandler))}_clearPartInputs(t){t.forEach(e=>{e.value=""})}_getFieldContainerClass(t,e){return["mint-date-fields relative w-full pl-10 pr-3.5 py-1.5 min-h-[2rem] text-sm font-medium rounded-lg box-border bg-white dark:bg-gray-900 dark:border dark:border-gray-700 text-gray-900 dark:text-white","border-2",t?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","transition-all duration-200 outline-none focus-within:ring-2 focus-within:ring-offset-1",t?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","flex items-center gap-1"].join(" ")+(e?" opacity-40 cursor-not-allowed":"")}_handleInputChange(t){}_cleanInputValue(t,e){return t}_handleBlur(t){const e=this.getFormat(),i=this.getSelectionMode(),s=this._isRange||i==="week"||i==="month";if(!t){this.setValue(""),this._updateDisplayText();return}if(s){const[n,r]=this._splitRangeInput(t,e),a=n?this._parseDateString(n,e):null,l=r?this._parseDateString(r,e):null;if(a&&l){const[o,c]=a<=l?[a,l]:[l,a],h=this._formatDate(o,e),p=this._formatDate(c,e),d=`${h} - ${p}`;this.setValue(d),this._applyDateToParts(o,this._startPartInputs,this._getFormatTokens(e),e),this._applyDateToParts(c,this._endPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=o,this._selectedEndDate=c,this._currentMonth=o.getMonth(),this._currentYear=o.getFullYear()}else if(a){const o=this._formatDate(a,e);this.setValue(o),this._applyDateToParts(a,this._startPartInputs,this._getFormatTokens(e),e),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=a,this._selectedEndDate=null,this._currentMonth=a.getMonth(),this._currentYear=a.getFullYear()}else this.setValue(""),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(e),e),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=null,this._selectedEndDate=null}else if(this._validateDateString(t,e)){const n=this._parseDateString(t,e);if(n){const r=this._formatDate(n,e);this.setValue(r),this._applyDateToParts(n,this._startPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=n,this._selectedEndDate=null,this._currentMonth=n.getMonth(),this._currentYear=n.getFullYear()}}else this.setValue(""),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=null,this._selectedEndDate=null}_setupPopoverWithRetry(t=0){if(!this._iconButton){t<10&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(t+1)});return}const e=10,i=this._iconButton.id;i&&this._iconButton.isConnected?document.getElementById(i)?this._createPopover(i):t<e&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(t+1)}):t<e&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(t+1)})}_createPopover(t){if(!t)return;if(!document.getElementById(t)){setTimeout(()=>{this._createPopover(t)},50);return}if(this._popover){if(this._popover.getAttribute("trigger-id")!==t){this._popover.setAttribute("trigger-id",t);const s=this._popover;typeof s._setupTrigger=="function"&&s._setupTrigger()}this._buildCalendar()}else{this._popover=document.createElement("mint-popover"),this._popover.setAttribute("direction","down"),this._popover.setAttribute("padding","0");const i=this.closest("mint-modal"),s=this.closest("mint-off-canvas");i||s?document.body.appendChild(this._popover):this.parentNode?this.parentNode.insertBefore(this._popover,this.nextSibling):document.body.appendChild(this._popover),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._popover&&this._popover.isConnected&&(this._popover.setAttribute("trigger-id",t),this._popoverObserver||(this._popoverObserver=new MutationObserver(n=>{n.forEach(r=>{var a;if(r.type==="attributes"&&r.attributeName==="open")if((a=this._popover)==null?void 0:a.hasAttribute("open"))requestAnimationFrame(()=>{this._buildCalendar();const o=this._popover;typeof o.render=="function"&&o.render(),this._setupFocusTrap()});else{if(this._removeFocusTrap(),this._iconButton&&!this._iconButton.disabled&&requestAnimationFrame(()=>{var o;(o=this._iconButton)==null||o.focus()}),this._viewMode="calendar",this._selectedStartDate)this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();else{const o=new Date;this._currentMonth=o.getMonth(),this._currentYear=o.getFullYear()}requestAnimationFrame(()=>{this._buildCalendar()}),this._hiddenInput&&(this._syncHiddenInput(),setTimeout(()=>{var c;const o=new FocusEvent("blur",{bubbles:!0,cancelable:!0,relatedTarget:null});(c=this._hiddenInput)==null||c.dispatchEvent(o)},0))}})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:["open"]})),requestAnimationFrame(()=>{this._buildCalendar()}))})})}}_buildCalendar(){if(!this._popover)return;this._calendarContainer&&this._calendarContainer.parentNode&&this._calendarContainer.remove(),this._calendarContainer=document.createElement("div"),this._calendarContainer.className="mint-date-calendar bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg p-4 w-[22rem] md:w-auto md:min-w-[28rem]";const t=this.getMode();t==="month"&&this._viewMode==="calendar"?this._viewMode="month":t==="year"&&this._viewMode==="calendar"?this._viewMode="year":t==="default"&&this._viewMode!=="month"&&this._viewMode!=="year"&&(this._viewMode="calendar"),this._viewMode==="calendar"?this._buildCalendarView():this._viewMode==="month"?this._buildMonthView():this._viewMode==="year"&&this._buildYearView();const e=this._popover.querySelector(".popover-content");if(e){for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(this._calendarContainer)}else this._popover.appendChild(this._calendarContainer)}_buildCalendarView(){if(!this._calendarContainer)return;const t=this._getDaysInMonth(this._currentMonth,this._currentYear),e=this._getFirstDayOfMonth(this._currentMonth,this._currentYear),i=["January","February","March","April","May","June","July","August","September","October","November","December"],s=this.getWeekStartDay(),n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=[...n.slice(s),...n.slice(0,s)],a=this.getShortcuts(),l=a.length>0;this._calendarContainer.className=l?"mint-date-calendar bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg p-4 w-[18rem] md:w-auto md:min-w-[28rem]":"mint-date-calendar bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg p-4 w-[18rem] md:min-w-[18rem]";const o=document.createElement("div");o.className="flex flex-col md:flex-row md:gap-6 md:items-start";const c=document.createElement("div");c.className="flex-1 min-w-0";const h=document.createElement("div");h.className="flex items-center justify-between mb-4";const p=document.createElement("button");p.type="button",p.tabIndex=0,p.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",p.setAttribute("data-keep-popover-open","true");const d=document.createElement("mint-icon");d.setAttribute("name","caret-left"),d.className="w-4 h-4",p.appendChild(d),p.addEventListener("click",()=>{const x=this._currentMonth,L=this._currentYear;this._currentMonth===0?(this._currentMonth=11,this._currentYear--):this._currentMonth--,this._buildCalendar(),this._dispatchMonthChangeEvent(x,L,this._currentMonth,this._currentYear)}),h.appendChild(p);const u=document.createElement("div");u.className="flex items-center gap-2";const f=document.createElement("button");f.type="button",f.tabIndex=0,f.className="text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",f.setAttribute("data-keep-popover-open","true"),f.textContent=i[this._currentMonth],f.addEventListener("click",()=>{const x=this.getMode();x!=="month"&&x!=="year"&&(this._viewMode="month",this._buildCalendar())}),u.appendChild(f);const _=document.createElement("button");_.type="button",_.tabIndex=0,_.className="text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",_.setAttribute("data-keep-popover-open","true"),_.textContent=String(this._currentYear),_.addEventListener("click",()=>{this.getMode()!=="year"&&(this._viewMode="year",this._buildCalendar())}),u.appendChild(_),h.appendChild(u);const g=document.createElement("button");g.type="button",g.tabIndex=0,g.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",g.setAttribute("data-keep-popover-open","true");const m=document.createElement("mint-icon");m.setAttribute("name","caret-right"),m.className="w-4 h-4",g.appendChild(m),g.addEventListener("click",()=>{const x=this._currentMonth,L=this._currentYear;this._currentMonth===11?(this._currentMonth=0,this._currentYear++):this._currentMonth++,this._buildCalendar(),this._dispatchMonthChangeEvent(x,L,this._currentMonth,this._currentYear)}),h.appendChild(g);const v=document.createElement("div");v.className="grid grid-cols-7 mb-2",r.forEach(x=>{const L=document.createElement("div");L.className="text-xs font-medium text-gray-500 dark:text-gray-400 text-center py-1",L.textContent=x,v.appendChild(L)});const b=document.createElement("div");b.className="grid grid-cols-7";const k=this.getMin()?this._parseDateString(this.getMin(),this.getFormat()):null,w=this.getMax()?this._parseDateString(this.getMax(),this.getFormat()):null;this.getDisabledDates();const E=this._currentMonth===0?11:this._currentMonth-1,y=this._currentMonth===0?this._currentYear-1:this._currentYear,C=this._getDaysInMonth(E,y),D=this._currentMonth===11?0:this._currentMonth+1,$=this._currentMonth===11?this._currentYear+1:this._currentYear,A=e+t,M=Math.ceil(A/7)*7-A,I=(x,L,H)=>{const F=this._isToday(x),V=this._isDateSelected(x),P=this._isDateInRange(x),R=k&&x<k||w&&x>w||this._isDateDisabled(x);let q="rounded-md";const z=this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate,X=z&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._selectedStartDate:z&&this._hoveredDate?this._hoveredDate:null,B=z&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._hoveredDate:z&&this._selectedStartDate?this._selectedStartDate:null,O=X!==null&&this._isSameDate(x,X),W=B!==null&&this._isSameDate(x,B),j=this._hoveredDate!==null&&this._isSameDate(x,this._hoveredDate),U=z&&this._hoveredDate&&this._selectedStartDate?!this._rangeIncludesDisabledDates(this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate):!1;if(this._isRange&&this._selectedStartDate&&this._selectedEndDate){const G=this._isSameDate(x,this._selectedStartDate),it=this._isSameDate(x,this._selectedEndDate);G&&it?q="rounded-md":G?q="rounded-l-md":it?q="rounded-r-md":P&&(q="rounded-none")}else z&&(O||W)&&U?O&&W?q="rounded-md":O?q="rounded-l-md":W&&(q="rounded-r-md"):V&&!this._isRange||V&&this._isRange&&!this._selectedEndDate?q="rounded-md":P&&z&&U&&(q="rounded-none");const Y=document.createElement("button");Y.type="button",Y.disabled=!!R,Y.tabIndex=R?-1:0;let Q=`w-full h-8 ${q} border-0 text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`;const et=V||z&&j&&U;return H?Q+=et?" bg-slate-800 dark:bg-slate-600 text-white":P?" bg-slate-100 dark:bg-slate-700 text-slate-800 dark:text-slate-200":F?" text-gray-900 dark:text-gray-100 font-semibold":" text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700":Q+=et?" bg-slate-800 dark:bg-slate-600 text-white":P?" bg-slate-100 dark:bg-slate-700 text-slate-800 dark:text-slate-200":" text-gray-400 dark:text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700",Q+=R?" opacity-40 cursor-not-allowed":"",Y.className=Q,Y.textContent=L.toString(),R||(Y.addEventListener("click",G=>{G.preventDefault(),G.stopPropagation(),this._handleDateClick(x)}),this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&!R&&Y.addEventListener("mouseenter",()=>{this._isHandlingClick||this._isDateDisabled(x)||(!this._hoveredDate||!this._isSameDate(this._hoveredDate,x))&&(this._hoveredDate=x,this._buildCalendar())})),Y};for(let x=e-1;x>=0;x--){const L=C-x,H=new Date(y,E,L),F=I(H,L,!1);b.appendChild(F)}for(let x=1;x<=t;x++){const L=new Date(this._currentYear,this._currentMonth,x),H=I(L,x,!0);b.appendChild(H)}for(let x=1;x<=M;x++){const L=new Date($,D,x),H=I(L,x,!1);b.appendChild(H)}if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&b.addEventListener("mouseleave",()=>{this._hoveredDate=null,this._buildCalendar()}),l){const x=document.createElement("div");x.className="mb-4 pb-4 border-b border-gray-200 dark:border-gray-700 md:mb-0 md:pb-0 md:border-b-0 md:border-r md:border-r-gray-200 dark:md:border-r-gray-700 md:pr-6 md:mr-0 md:w-32 md:flex-shrink-0 md:h-full md:flex md:flex-col";const L=document.createElement("div");L.className="relative md:relative md:flex-1 md:min-h-0";const H=document.createElement("div");H.className="flex gap-2 overflow-x-auto pb-1 md:flex-col md:overflow-x-visible md:overflow-y-auto md:pb-0 md:gap-2",H.style.scrollbarWidth="none",H.style.msOverflowStyle="none",H.style.setProperty("-webkit-overflow-scrolling","touch");const F=document.createElement("style");F.textContent=`
|
|
65
|
+
`,document.head.appendChild(t),J._activeShadowStyleInjected=!0}this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render(),this._button&&this.setupEventListeners(),this.isFullWidth()&&this.classList.add("w-full")}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getVariant(){return this.getAttribute("variant")||"solid"}getTone(){return this.getAttribute("tone")||"neutral"}isDisabled(){return this.getAttribute("disabled")==="true"}isLoading(){return this.getAttribute("loading")==="true"}getType(){const t=this.getAttribute("type"),e=this.getAttribute("button-type");return(t||e||"default")==="submit"?"submit":"button"}isFullWidth(){return this.getAttribute("full-width")==="true"}isActive(){return this.getAttribute("active")==="true"}get active(){return this.isActive()}set active(t){t?this.setAttribute("active","true"):this.removeAttribute("active")}getIconPosition(){return this.getAttribute("icon-position")||"left"}getIcon(){return this.getAttribute("icon")||""}isIconOnly(){var i,s,n,r,a;if(!(this.getIcon()||((i=this._button)==null?void 0:i.querySelector('[slot="icon"], .mint-button-icon, mint-icon'))))return!1;const e=(s=this._button)==null?void 0:s.querySelector(".mint-button-content");if(e&&((n=e.textContent)!=null&&n.trim()))return!1;if(this._button)for(let l=this._button.firstChild;l;l=l.nextSibling){if(l.nodeType===Node.TEXT_NODE&&((r=l.textContent)!=null&&r.trim()))return!1;if(l.nodeType===Node.ELEMENT_NODE){const o=l;if(o.tagName!=="MINT-ICON"&&o.tagName!=="MINT-SPINNER"&&!o.querySelector("mint-spinner")&&!o.hasAttribute("slot")&&o.className!=="mint-button-icon"&&!(o.className==="mr-2"&&o.querySelector("mint-spinner"))&&(a=o.textContent)!=null&&a.trim())return!1}}return!0}getActiveStateClasses(){const t=this.getVariant(),e=this.getTone(),i=`${t}-${e}`;return{"solid-action":["!bg-slate-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-slate-700","hover:!bg-slate-900","dark:hover:!bg-slate-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"solid-neutral":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"solid-info":["!bg-blue-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-blue-700","hover:!bg-blue-900","dark:hover:!bg-blue-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"solid-warning":["!bg-amber-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-amber-700","hover:!bg-amber-900","dark:hover:!bg-amber-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"solid-danger":["!bg-red-900","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:!bg-red-700","hover:!bg-red-900","dark:hover:!bg-red-700","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]"],"ghost-action":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"ghost-neutral":["!bg-gray-50","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","!text-gray-900","dark:!text-white","hover:!bg-gray-50","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","hover:!text-gray-900","dark:hover:!text-white"],"ghost-info":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"ghost-warning":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"ghost-danger":["!bg-gray-100","!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:!bg-gray-800","hover:!bg-gray-100","dark:hover:!bg-gray-800","hover:!shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]"],"link-action":["!text-slate-900","dark:!text-slate-300","hover:!text-slate-900","dark:hover:!text-slate-300"],"link-neutral":["!text-gray-950","dark:!text-gray-200","hover:!text-gray-950","dark:hover:!text-gray-200"],"link-info":["!text-blue-900","dark:!text-blue-200","hover:!text-blue-900","dark:hover:!text-blue-200"],"link-warning":["!text-amber-900","dark:!text-amber-200","hover:!text-amber-900","dark:hover:!text-amber-200"],"link-danger":["!text-red-900","dark:!text-red-200","hover:!text-red-900","dark:hover:!text-red-200"]}[i]||[]}getButtonClasses(){const t=this.isIconOnly(),e=this.getVariant(),i=["inline-flex","items-center","justify-center","font-medium","rounded-lg","box-border",...t?["p-1.5","aspect-square","w-[2.25rem]","h-[2.25rem]"]:["px-3.5","py-1.5","min-h-[2.25rem]"],"text-sm","transition-all","duration-200","outline-none","focus:outline-none","focus-visible:ring-2","focus-visible:ring-offset-1","[&.mint-button-active>*]:scale-95","[&>*]:transition-transform","[&>*]:duration-100","disabled:opacity-50","disabled:cursor-not-allowed"],s=this.getTone(),n={"solid-action":["bg-slate-800","dark:bg-slate-600","text-white","hover:bg-slate-950","dark:hover:bg-slate-700","active:bg-slate-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-slate-700","disabled:active:bg-slate-800","dark:disabled:active:bg-slate-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"solid-neutral":["bg-white","dark:bg-gray-900","text-gray-900","dark:text-white","hover:bg-gray-50","dark:hover:bg-gray-800","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-white","dark:disabled:active:bg-gray-900","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-gray-200","dark:border-gray-700"],"solid-info":["bg-blue-800","dark:bg-blue-600","text-white","hover:bg-blue-950","dark:hover:bg-blue-700","active:bg-blue-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-blue-700","disabled:active:bg-blue-800","dark:disabled:active:bg-blue-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"solid-warning":["bg-amber-800","dark:bg-amber-600","text-white","hover:bg-amber-950","dark:hover:bg-amber-700","active:bg-amber-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-amber-700","disabled:active:bg-amber-800","dark:disabled:active:bg-amber-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"solid-danger":["bg-red-800","dark:bg-red-600","text-white","hover:bg-red-950","dark:hover:bg-red-700","active:bg-red-900","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","dark:active:bg-red-700","disabled:active:bg-red-800","dark:disabled:active:bg-red-600","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-sm","hover:shadow","dark:shadow-gray-900/50","border-2","border-transparent"],"ghost-action":["bg-transparent","text-slate-800","dark:text-slate-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-neutral":["bg-transparent","text-gray-700","dark:text-gray-200","active:bg-gray-50","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","active:text-gray-900","dark:active:text-white","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-info":["bg-transparent","text-blue-800","dark:text-blue-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-warning":["bg-transparent","text-amber-800","dark:text-amber-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"ghost-danger":["bg-transparent","text-red-800","dark:text-red-400","active:bg-gray-100","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.1)]","dark:active:bg-gray-800","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-action":["bg-transparent","text-slate-800","dark:text-slate-400","hover:text-slate-950","dark:hover:text-slate-200","active:text-slate-900","dark:active:text-slate-300","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-neutral":["bg-transparent","text-gray-700","dark:text-gray-300","hover:text-gray-900","dark:hover:text-gray-100","active:text-gray-950","dark:active:text-gray-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-info":["bg-transparent","text-blue-800","dark:text-blue-400","hover:text-blue-950","dark:hover:text-blue-300","active:text-blue-900","dark:active:text-blue-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-warning":["bg-transparent","text-amber-800","dark:text-amber-400","hover:text-amber-950","dark:hover:text-amber-300","active:text-amber-900","dark:active:text-amber-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"],"link-danger":["bg-transparent","text-red-800","dark:text-red-400","hover:text-red-950","dark:hover:text-red-300","active:text-red-900","dark:active:text-red-200","disabled:active:bg-transparent","dark:disabled:active:bg-transparent","disabled:active:shadow-none","focus-visible:ring-gray-400","dark:focus-visible:ring-gray-500","shadow-none","hover:shadow-none","border-2","border-transparent"]},r=`${e}-${s}`,a=n[r]||n["solid-neutral"],l=[...i,...a];if(this.isActive()){const o=this.getActiveStateClasses();l.push(...o),l.push("[&>*]:scale-95")}return this.isFullWidth()&&l.push("w-full"),l.join(" ")}render(){var h,f,d,p,u,_;const t=this.isDisabled()||this.isLoading(),e=this.getType();if(!this._button){for(this._button=document.createElement("button");this.firstChild;)this._button.appendChild(this.firstChild);this.appendChild(this._button),this.setupEventListeners()}this._button.type=e,this._button.disabled=t;let i=this._button.querySelector("mint-spinner");const s=this.isLoading();if(s)if(i)i.setAttribute("data-button-variant",this.getVariant()),i.setAttribute("data-button-tone",this.getTone()),"render"in i&&typeof i.render=="function"&&i.render();else{const g=document.createElement("span");g.className="mr-2 inline-flex items-center";const m=document.createElement("mint-spinner");m.setAttribute("size","default"),m.setAttribute("data-button-variant",this.getVariant()),m.setAttribute("data-button-tone",this.getTone()),m.style.width="0.875rem",m.style.height="0.875rem",g.appendChild(m),this._button.insertBefore(g,this._button.firstChild)}else i&&((h=i.parentElement)==null||h.remove());for(;this.firstChild&&this.firstChild!==this._button;)this._button.appendChild(this.firstChild);const n=this.getIcon();let r=this._button.querySelector('[slot="icon"], .mint-button-icon, mint-icon');n?(r&&r.tagName!=="MINT-ICON"&&(r.remove(),r=null),!r||r.tagName!=="MINT-ICON"?(r=document.createElement("mint-icon"),r.setAttribute("name",n),r.className="mint-button-icon"):r.setAttribute("name",n)):r&&r.tagName==="MINT-ICON"&&(r.remove(),r=null),r||(r=this._button.querySelector('[slot="icon"], .mint-button-icon'));const a=this.getIconPosition();let l=this._button.querySelector(".mint-button-content");if(l){const g=r&&r.tagName==="MINT-ICON";if(r&&!r.parentElement){const m=(p=this._button.querySelector("mint-spinner"))==null?void 0:p.parentElement;g||a==="left"?m?m.insertAdjacentElement("afterend",r):this._button.insertBefore(r,l):l.insertAdjacentElement("afterend",r)}else if(r&&(g||a==="left")&&r.nextSibling!==l){r.remove();const m=(u=this._button.querySelector("mint-spinner"))==null?void 0:u.parentElement;m?m.insertAdjacentElement("afterend",r):this._button.insertBefore(r,l)}else r&&!g&&a==="right"&&r.previousSibling!==l&&(r.remove(),l.insertAdjacentElement("afterend",r))}else{const g=[];for(let m=this._button.firstChild;m;m=m.nextSibling){if(m.nodeType!==Node.ELEMENT_NODE){g.push(m);continue}const v=m;v.tagName!=="MINT-SPINNER"&&!v.querySelector("mint-spinner")&&m!==r&&!v.hasAttribute("slot")&&!(v.className==="mr-2"&&v.querySelector("mint-spinner"))&&g.push(m)}if(g.length>0){l=document.createElement("span"),l.className="mint-button-content inline-flex items-center",g.forEach(v=>{l.appendChild(v)});const m=(f=this._button.querySelector("mint-spinner"))==null?void 0:f.parentElement;r&&a==="left"?m?(m.insertAdjacentElement("afterend",r),r.insertAdjacentElement("afterend",l)):(this._button.insertBefore(r,this._button.firstChild),r.insertAdjacentElement("afterend",l)):r&&a==="right"?m?(m.insertAdjacentElement("afterend",l),l.insertAdjacentElement("afterend",r)):(this._button.insertBefore(l,this._button.firstChild),l.insertAdjacentElement("afterend",r)):m?m.insertAdjacentElement("afterend",l):this._button.insertBefore(l,this._button.firstChild)}else if(r&&r.tagName==="MINT-ICON"&&!r.parentElement){const m=(d=this._button.querySelector("mint-spinner"))==null?void 0:d.parentElement;m?m.insertAdjacentElement("afterend",r):this._button.insertBefore(r,this._button.firstChild)}}const o=this.isIconOnly();if(r&&(r.classList.contains("mint-button-icon")||r.classList.add("mint-button-icon"),s?r.style.display="none":r.style.display="",r.classList.remove("mr-1.5","ml-1.5"),o?r.tagName==="MINT-ICON"?(r.style.width="1rem",r.style.height="1rem",r.style.maxWidth="1rem",r.style.maxHeight="1rem",r.style.flexShrink="0"):(r.style.maxWidth="1rem",r.style.maxHeight="1rem",r.style.flexShrink="0",r.tagName==="svg"&&(r.style.width="1rem",r.style.height="1rem")):a==="left"?r.classList.add("mr-1.5"):r.classList.add("ml-1.5")),s){const g=(_=this._button.querySelector("mint-spinner"))==null?void 0:_.parentElement;g&&(o?(g.classList.remove("mr-2"),g.classList.add("mr-0")):g.classList.contains("mr-2")||(g.classList.remove("mr-0"),g.classList.add("mr-2")))}const c=this.getButtonClasses();this._button.className=c,this.setAttribute("data-variant",this.getVariant()),this.setAttribute("data-tone",this.getTone()),this.isActive()?this._button.classList.add("mint-button-active"):this._button.classList.remove("mint-button-active")}setupEventListeners(){this._button&&!this._clickHandler&&(this._clickHandler=this.handleClick.bind(this),this._clickHandler&&this._button.addEventListener("click",this._clickHandler,!0),this._button.addEventListener("mousedown",this._handleMouseDown),this._button.addEventListener("mouseup",this._handleMouseUp),this._button.addEventListener("mouseleave",this._handleMouseLeave),this._button.addEventListener("touchstart",this._handleTouchStart),this._button.addEventListener("touchend",this._handleTouchEnd),this._button.addEventListener("touchcancel",this._handleTouchCancel))}removeEventListeners(){this._button&&(this._clickHandler&&(this._button.removeEventListener("click",this._clickHandler,!0),this._clickHandler=null),this._button.removeEventListener("mousedown",this._handleMouseDown),this._button.removeEventListener("mouseup",this._handleMouseUp),this._button.removeEventListener("mouseleave",this._handleMouseLeave),this._button.removeEventListener("touchstart",this._handleTouchStart),this._button.removeEventListener("touchend",this._handleTouchEnd),this._button.removeEventListener("touchcancel",this._handleTouchCancel))}handleClick(t){if(this.isDisabled()||this.isLoading()){t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation();return}if(this.getType()==="submit"){this.dispatchEvent(new CustomEvent("click",{detail:{originalEvent:t},bubbles:!0,cancelable:!0,composed:!0}));return}if(t.stopPropagation(),t.stopImmediatePropagation(),this._isHandlingClick){t.preventDefault();return}this._isHandlingClick=!0,t.preventDefault(),this.dispatchEvent(new CustomEvent("click",{detail:{originalEvent:t},bubbles:!0,cancelable:!0,composed:!0})),requestAnimationFrame(()=>{this._isHandlingClick=!1})}};J._activeShadowStyleInjected=!1;let Z=J;customElements.get("mint-button")||customElements.define("mint-button",Z);class nt extends HTMLElement{constructor(){super(),this._button=null,this._checked=!1}static get observedAttributes(){return["checked","disabled","label","icon","info","error","error-message","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full");const t=this.getAttribute("checked");this._checked=t==="true",this.render()}_getSwitchContainer(){let t=this.querySelector(".mint-switch-container");return t||(t=document.createElement("div"),t.className="mint-switch-container flex items-center gap-2",this.insertBefore(t,this.firstChild)),t}disconnectedCallback(){this.removeEventListeners()}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(t==="checked"&&(this._checked=i==="true"),e!==i){if(t==="error"||t==="error-message"){this._renderErrorState();return}if(t==="loading"){this.render();return}this.render()}}get checked(){try{return this._checked||!1}catch{return!1}}set checked(t){try{t?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this._checked=!!t,this.render()}catch{}}isDisabled(){return this.getAttribute("disabled")==="true"}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getIcon(){return this.getAttribute("icon")||""}hasIcon(){return!!this.getIcon()}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getSwitchClasses(){const t=this.hasError(),e=["relative","inline-flex","items-center","rounded-full","h-5","w-10","border","transition-colors","duration-200","ease-in-out","outline-none","focus:outline-none","focus-visible:ring-2","focus-visible:ring-offset-1",t?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500","active:shadow-[inset_0_2px_4px_rgba(0,0,0,0.3)]","disabled:opacity-50","disabled:cursor-not-allowed"],i=this._checked?["bg-slate-950","dark:bg-slate-600",t?"border-red-300 dark:border-red-300":"border-slate-700 dark:border-slate-500"]:["bg-slate-200","dark:bg-slate-400",t?"border-red-300 dark:border-red-300":"border-slate-300 dark:border-slate-500"];return[...e,...i].join(" ")}getThumbClasses(){const t=["relative","inline-block","rounded-full","bg-white","dark:bg-gray-50","h-4","w-4","shadow-lg","transform","transition-transform","duration-200","ease-in-out","pointer-events-none","overflow-hidden"],e=this._checked?"translate-x-5":"translate-x-0.5";return[...t,e].join(" ")}getIconClasses(){return["absolute","inset-0","flex","items-center","justify-center","pointer-events-none"].join(" ")}render(){const t=this.isLoading(),e=this.getSwitchClasses(),i=this.getThumbClasses(),s=this.getLabel(),n=this.getInfo(),r=this.getIcon(),a=this.getAttribute("id")||`mint-switch-${Math.random().toString(36).substr(2,9)}`;this.getAttribute("id")||this.setAttribute("id",a);const l=this._getSwitchContainer();this._button?this._button.parentElement!==l&&l.appendChild(this._button):(this._button=document.createElement("button"),l.appendChild(this._button),this.setupEventListeners());let o=l.querySelector(".mint-switch-label");s?(o||(o=document.createElement("label"),o.className="mint-switch-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",this._button&&this._button.parentElement===l?l.insertBefore(o,this._button.nextSibling):l.appendChild(o)),o.textContent=s,o.setAttribute("for",a),this.isDisabled()?o.classList.add("opacity-40"):o.classList.remove("opacity-40")):o&&o.remove(),this._button.className=e,this._button.disabled=this.isDisabled(),this._button.id=a,this._button.setAttribute("aria-checked",String(this._checked)),this._button.setAttribute("aria-label",s||"Toggle switch"),this._button.setAttribute("role","switch"),this._button.type="button";let c=this._button.querySelector("span");c||(c=document.createElement("span"),this._button.appendChild(c)),c.className=i;const h=c.querySelector("span");if(r){let d=h;d||(d=document.createElement("span"),d.className=this.getIconClasses(),c.appendChild(d));let p=d.querySelector("mint-icon");p||(p=document.createElement("mint-icon"),d.appendChild(p)),p.setAttribute("name",r)}else h&&h.remove();let f=this.querySelector(".mint-switch-info");n?(f||(f=document.createElement("span"),f.className="mint-switch-info text-xs text-gray-500 dark:text-gray-400 select-none mt-1 block",l&&l.parentElement===this?this.insertBefore(f,l.nextSibling):this.appendChild(f)),f.textContent=n,this.isDisabled()?f.classList.add("opacity-40"):f.classList.remove("opacity-40")):f&&f.remove(),this._renderErrorState(),this._renderSkeleton(t)}setupEventListeners(){this._button&&this._button.addEventListener("click",this.handleToggle.bind(this))}removeEventListeners(){this._button&&this._button.removeEventListener("click",this.handleToggle.bind(this))}handleToggle(t){if(!this.isDisabled()){this.checked=!this._checked;const e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e),this.dispatchEvent(new CustomEvent("input",{detail:{checked:this._checked},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:{checked:this._checked},bubbles:!0,cancelable:!0})),this.dispatchEvent(new CustomEvent("toggle",{detail:{checked:this._checked},bubbles:!0,cancelable:!0}))}}_renderSkeleton(t){const e=this._getSwitchContainer(),i=this.getLabel(),s=this.getInfo();let n=e.querySelector(".mint-switch-skeleton-container"),r=this.querySelector(".mint-switch-info-skeleton");if(t){e.classList.contains("relative")||e.classList.add("relative"),n||(n=document.createElement("div"),n.className="mint-switch-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center gap-2",e.appendChild(n));let a=n.querySelector(".mint-switch-skeleton-box");if(a||(a=document.createElement("div"),a.className="mint-switch-skeleton-box flex-shrink-0 w-10 h-5 rounded-full bg-gray-200 dark:bg-gray-700 animate-pulse",n.appendChild(a)),i){let o=n.querySelector(".mint-switch-skeleton-label");o||(o=document.createElement("div"),o.className="mint-switch-skeleton-label h-4 w-24 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",n.appendChild(o))}else{const o=n.querySelector(".mint-switch-skeleton-label");o&&o.remove()}n.style.display="flex",this._button&&(this._button.style.visibility="hidden",this._button.style.pointerEvents="none");const l=e.querySelector(".mint-switch-label");if(l&&(l.style.visibility="hidden",l.style.pointerEvents="none"),s){r||(r=document.createElement("div"),r.className="mint-switch-info-skeleton h-3 w-32 rounded bg-gray-200 dark:bg-gray-700 animate-pulse mt-2",e&&e.parentElement===this?this.insertBefore(r,e.nextSibling):this.appendChild(r)),r.style.display="block";const o=this.querySelector(".mint-switch-info");o&&(o.style.display="none")}else r&&(r.style.display="none")}else{n&&(n.style.display="none"),r&&(r.style.display="none"),this._button&&(this._button.style.visibility="visible",this._button.style.pointerEvents="auto");const a=e.querySelector(".mint-switch-label");a&&(a.style.visibility="visible",a.style.pointerEvents="auto");const l=this.querySelector(".mint-switch-info");l&&(l.style.display="")}}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-switch-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-switch-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove(),this._button&&(this._button.className=this.getSwitchClasses())}}customElements.get("mint-switch")||customElements.define("mint-switch",nt);class at extends HTMLElement{constructor(){super(),this._darkModeObserver=null,this._userClasses=new Set}static get observedAttributes(){return["variant","size","bold","underline","strike","italic","display","inline"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline"),this._captureUserClasses(),this.render(),this._observeDarkMode()}_captureUserClasses(){Array.from(this.classList).forEach(e=>this._userClasses.add(e))}attributeChangedCallback(t,e,i){e!==i&&this.render()}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null)}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}getVariant(){return this.getAttribute("variant")||"default"}getSize(){return this.getAttribute("size")||"regular"}isBold(){return this.getAttribute("bold")==="true"}isUnderline(){return this.getAttribute("underline")==="true"}isStrike(){return this.getAttribute("strike")==="true"}isItalic(){return this.getAttribute("italic")==="true"}getDisplay(){const t=this.getAttribute("display");return t||(this.getAttribute("inline")==="true"?"inline-block":"block")}getTextClasses(){const t=this.getSize(),e=this.getVariant(),i=document.documentElement.classList.contains("dark"),s={heading:["font-semibold"],"sub-heading":["font-medium"],regular:[]},n={default:i?["text-gray-100"]:["text-gray-900"],muted:i?["text-gray-400"]:["text-gray-400"],danger:i?["text-red-400"]:["text-red-600"],success:i?["text-green-400"]:["text-green-600"]},r=[];this.isBold()&&r.push("font-bold"),this.isUnderline()&&r.push("underline"),this.isStrike()&&r.push("line-through"),this.isItalic()&&r.push("italic");const a=this.getDisplay();return[a==="block"?"block":a==="inline"?"inline":"inline-block",...s[t]||s.regular,...n[e]||n.default,...r].join(" ")}render(){const t=this.getSize(),e=["text-gray-100","text-gray-900","text-gray-400","text-red-400","text-red-600","text-green-400","text-green-600"],i=["text-2xl","text-lg","text-sm"];i.forEach(o=>{this.classList.remove(o),this._userClasses.delete(o)}),e.forEach(o=>{this.classList.remove(o),this._userClasses.delete(o)});const s=this.getTextClasses().split(" ").filter(o=>o.trim());Array.from(this.classList).forEach(o=>{!e.includes(o)&&!i.includes(o)&&this._userClasses.add(o)});const r=[...new Set([...s,...Array.from(this._userClasses)])];this.className=r.join(" ");const a={heading:"clamp(1.25rem, 2.5vw + 0.5rem, 1.5rem)","sub-heading":"clamp(1rem, 1.5vw + 0.5rem, 1.125rem)",regular:"clamp(0.875rem, 1vw + 0.5rem, 0.875rem)"},l=a[t]||a.regular;this.style.setProperty("font-size",l)}}customElements.get("mint-text")||customElements.define("mint-text",at);class ot extends HTMLElement{constructor(){super(),this._childObserver=null}static get observedAttributes(){return["direction","text-align","gap"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block"),this.render(),this.getTextAlign()&&this._observeChildren()}attributeChangedCallback(t,e,i){e!==i&&(this.render(),t==="text-align"&&this._observeChildren())}_observeChildren(){this._childObserver||(this._childObserver=new MutationObserver(()=>{const t=this.getTextAlign();t&&this._applyTextAlignToChildren(t)}),this._childObserver.observe(this,{childList:!0,subtree:!1}))}disconnectedCallback(){this._childObserver&&(this._childObserver.disconnect(),this._childObserver=null)}getDirection(){return(this.getAttribute("direction")||"vertical")==="horizontal"?"horizontal":"vertical"}getGap(){const t=this.getAttribute("gap")||"3";return parseFloat(t)}getTextAlign(){const t=this.getAttribute("text-align")||"";return["left","center","right","justify"].includes(t)?t:""}getStackClasses(){const t=this.getDirection(),e=this.getTextAlign(),i=this.getGap(),s=["flex",t==="horizontal"?"flex-row":"flex-col",`gap-${i}`];return e&&(s.push(`text-${e}`),s.push(`[&>*]:text-${e}`),s.push(`[&>*_.mint-button-content]:text-${e}`),e==="left"?(s.push("[&>mint-button]:!justify-start"),s.push("[&>mint-button>button]:!justify-start")):e==="right"?(s.push("[&>mint-button]:!justify-end"),s.push("[&>mint-button>button]:!justify-end")):e==="center"&&(s.push("[&>mint-button]:!justify-center"),s.push("[&>mint-button>button]:!justify-center"))),s.join(" ")}render(){const t=this.getStackClasses(),e=this.getTextAlign();["flex","flex-row","flex-col","gap-1","gap-2","gap-3","text-left","text-center","text-right","text-justify","[&>*]:text-left","[&>*]:text-center","[&>*]:text-right","[&>*]:text-justify","[&>*_.mint-button-content]:text-left","[&>*_.mint-button-content]:text-center","[&>*_.mint-button-content]:text-right","[&>*_.mint-button-content]:text-justify","[&>mint-button]:!justify-start","[&>mint-button]:!justify-center","[&>mint-button]:!justify-end","[&>mint-button>button]:!justify-start","[&>mint-button>button]:!justify-center","[&>mint-button>button]:!justify-end"].forEach(n=>this.classList.remove(n)),t.split(" ").forEach(n=>{n&&this.classList.add(n)}),["box-border","m-0","p-0","border-0","align-baseline","block"].forEach(n=>{this.classList.contains(n)||this.classList.add(n)}),e?this._applyTextAlignToChildren(e):this._removeTextAlignFromChildren()}_applyTextAlignToChildren(t){Array.from(this.children).forEach(i=>{if(i.tagName==="MINT-BUTTON"){const s=i.querySelector("button");if(s){s.classList.remove("justify-start","justify-center","justify-end"),t==="left"?s.classList.add("justify-start"):t==="right"?s.classList.add("justify-end"):t==="center"&&s.classList.add("justify-center");const n=s.querySelector(".mint-button-content");n&&(n.classList.remove("text-left","text-center","text-right","text-justify"),n.classList.add(`text-${t}`))}}else i.classList.remove("text-left","text-center","text-right","text-justify"),i.classList.add(`text-${t}`)})}_removeTextAlignFromChildren(){Array.from(this.children).forEach(e=>{if(e.tagName==="MINT-BUTTON"){const i=e.querySelector("button");if(i){i.classList.remove("justify-start","justify-end"),i.classList.add("justify-center");const s=i.querySelector(".mint-button-content");s&&s.classList.remove("text-left","text-center","text-right","text-justify")}}else e.classList.remove("text-left","text-center","text-right","text-justify")})}}customElements.get("mint-stack")||customElements.define("mint-stack",ot);class lt extends HTMLElement{constructor(){super(),this._headingElement=null}static get observedAttributes(){return["heading"]}connectedCallback(){this.classList.add("box-border","m-0","align-baseline","block"),this.render()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getHeading(){return this.getAttribute("heading")||""}hasPaddingClass(){return Array.from(this.classList).some(e=>/^p-\d+|^px-|^py-|^pt-|^pb-|^pl-|^pr-/.test(e))}render(){this.classList.add("rounded-lg","shadow","bg-white","dark:bg-gray-900","border","border-gray-200","dark:border-gray-700","overflow-hidden","transition-colors","duration-200","mb-6"),this.hasPaddingClass()||this.classList.add("p-4");const t=this.getHeading();t?(this._headingElement||(this._headingElement=document.createElement("mint-text"),this._headingElement.setAttribute("size","sub-heading"),this.insertBefore(this._headingElement,this.firstChild)),this._headingElement.textContent=t):this._headingElement&&this._headingElement.parentNode&&(this._headingElement.remove(),this._headingElement=null)}}customElements.get("mint-card")||customElements.define("mint-card",lt);class ct extends HTMLElement{constructor(){super(),this._link=null,this._contentObserver=null}static get observedAttributes(){return["href","target"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render(),this._observeContent()}disconnectedCallback(){this._contentObserver&&(this._contentObserver.disconnect(),this._contentObserver=null)}_observeContent(){this._contentObserver||(this._contentObserver=new MutationObserver(()=>{this._link&&this._link.querySelectorAll("mint-text").forEach(e=>{e.classList.contains("underline")||e.classList.add("underline")})}),this._contentObserver.observe(this,{childList:!0,subtree:!0}))}attributeChangedCallback(t,e,i){e!==i&&this.render()}getHref(){return this.getAttribute("href")||"#"}getTarget(){return this.getAttribute("target")||""}hasIcon(){var t;return!!(this.querySelector("mint-icon")||(t=this._link)!=null&&t.querySelector("mint-icon"))}render(){const t=this.getHref(),e=this.getTarget();if(!this._link){for(this._link=document.createElement("a");this.firstChild;)this._link.appendChild(this.firstChild);this.appendChild(this._link)}this._link.href=t,e?(this._link.target=e,e==="_blank"&&(this._link.rel="noopener noreferrer")):(this._link.removeAttribute("target"),this._link.removeAttribute("rel"));const i=this.hasIcon(),s=["text-slate-800","dark:text-slate-200","underline","hover:text-slate-950","dark:hover:text-slate-100","transition-colors","duration-200","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"];i&&s.push("inline-flex","items-center","gap-2"),this._link.className=s.join(" "),this._link.querySelectorAll("mint-text").forEach(a=>{a.classList.contains("underline")||a.classList.add("underline")}),["box-border","m-0","p-0","border-0","align-baseline","inline-block"].forEach(a=>{this.classList.contains(a)||this.classList.add(a)})}}customElements.get("mint-link")||customElements.define("mint-link",ct);class ht extends HTMLElement{constructor(){super(),this._button=null}static get observedAttributes(){return["href","fallback-href"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block","flex","items-center","justify-center"),this.render()}disconnectedCallback(){}attributeChangedCallback(t,e,i){e!==i&&this.render()}getFallbackHref(){return this.getAttribute("fallback-href")||this.getAttribute("href")||"/"}_getTargetUrl(){const t=document.referrer,e=window.location.origin;if(t)try{const i=new URL(t);if(i.origin===e)return i.pathname+i.search}catch{}return this.getFallbackHref()}handleClick(t){t.preventDefault(),t.stopPropagation();const e=this._getTargetUrl(),i=document.referrer,s=i&&(()=>{try{return new URL(i).origin===window.location.origin}catch{return!1}})(),n=new CustomEvent("back",{detail:{url:e,isFromReferrer:s,referrer:i||null,fallbackHref:this.getFallbackHref()},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(n)}render(){this._button||(this._button=document.createElement("mint-button"),this._button.setAttribute("variant","neutral"),this._button.setAttribute("icon","arrow-left"),this._button.addEventListener("click",t=>this.handleClick(t)),this.appendChild(this._button))}}customElements.get("mint-back-button")||customElements.define("mint-back-button",ht);class dt extends HTMLElement{constructor(){super(),this._pageContainer=null,this._header=null,this._titleElement=null,this._headingText=null,this._actionsSlot=null,this._bodySlot=null,this._darkModeObserver=null,this._backButton=null,this._backButtonHandler=null}static get observedAttributes(){return["heading","fallback-href","show-back-button","containered"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block"),this.render(),this._observeDarkMode(),this._setupBackButtonListener()}attributeChangedCallback(t,e,i){e!==i&&(t==="containered"&&this._applyContainerClasses(),this.render())}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null),this._removeBackButtonListener()}getHeading(){return this.getAttribute("heading")||""}getFallbackHref(){return this.getAttribute("fallback-href")||"/"}shouldShowBackButton(){return this.getAttribute("show-back-button")==="true"}render(){const t=this.getHeading();this._pageContainer||(this._pageContainer=document.createElement("div"),this.appendChild(this._pageContainer)),this._applyContainerClasses(),this._header||(this._header=document.createElement("div"),this._header.className="flex justify-between mb-8",this._pageContainer.appendChild(this._header)),this._titleElement||(this._titleElement=document.createElement("div"),this._titleElement.className="flex gap-4 min-w-0 flex-1",this._header.appendChild(this._titleElement));let e=this._titleElement.querySelector("mint-back-button");if(this.shouldShowBackButton()){e||(e=document.createElement("mint-back-button"),this._titleElement.insertBefore(e,this._titleElement.firstChild));const r=this.getFallbackHref();e.setAttribute("fallback-href",r),this._backButton=e}else e&&(e.remove(),e=null,this._backButton=null);t?(this._headingText?(this._headingText.classList.add("truncate","min-w-0"),e&&e.parentElement===this._titleElement?this._headingText.previousSibling!==e&&this._titleElement.insertBefore(this._headingText,e.nextSibling):this._headingText.previousSibling&&this._titleElement.insertBefore(this._headingText,this._titleElement.firstChild)):(this._headingText=document.createElement("mint-text"),this._headingText.setAttribute("size","heading"),this._headingText.setAttribute("bold","true"),this._headingText.classList.add("truncate","min-w-0"),e&&e.parentElement===this._titleElement?this._titleElement.insertBefore(this._headingText,e.nextSibling):this._titleElement.insertBefore(this._headingText,this._titleElement.firstChild)),this._headingText.textContent=t):this._headingText&&(this._headingText.remove(),this._headingText=null),this._actionsSlot?this._actionsSlot.classList.contains("ml-4")||this._actionsSlot.classList.add("ml-4"):(this._actionsSlot=document.createElement("div"),this._actionsSlot.className="flex gap-2 items-center ml-4",this._actionsSlot.setAttribute("slot","actions"),this._header.appendChild(this._actionsSlot)),Array.from(this.children).filter(r=>r!==this._pageContainer&&r!==this._actionsSlot&&r.getAttribute("slot")==="actions").forEach(r=>{this._actionsSlot&&r.parentElement!==this._actionsSlot&&this._actionsSlot.appendChild(r)}),this._bodySlot||(this._bodySlot=document.createElement("div"),this._pageContainer.appendChild(this._bodySlot)),Array.from(this.children).forEach(r=>{r!==this._pageContainer&&r.getAttribute("slot")!=="actions"&&r!==this._actionsSlot&&r!==this._header&&r!==this._bodySlot&&r!==this._headingText&&r.parentElement!==this._bodySlot&&r.parentElement!==this._pageContainer&&this._bodySlot.appendChild(r)}),this._updateBackgroundColor()}_applyContainerClasses(){if(!this._pageContainer)return;this._pageContainer.classList.add("min-h-screen","p-8","transition-colors","duration-200"),this.getAttribute("containered")==="true"?this._pageContainer.classList.add("max-w-6xl","mx-auto","w-full"):this._pageContainer.classList.remove("max-w-6xl","mx-auto","w-full")}_updateBackgroundColor(){if(!this._pageContainer)return;document.documentElement.classList.contains("dark")?(this._pageContainer.classList.remove("bg-gray-20"),this._pageContainer.classList.add("bg-gray-900")):(this._pageContainer.classList.remove("bg-gray-900"),this._pageContainer.classList.add("bg-gray-20"))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_setupBackButtonListener(){this._backButtonHandler||(this._backButtonHandler=t=>{const e=t.target;if(e&&e.tagName==="MINT-BACK-BUTTON"){t.stopPropagation();const i=new CustomEvent("back",{detail:t.detail,bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(i)}}),this.addEventListener("back",this._backButtonHandler,!0)}_removeBackButtonListener(){this._backButtonHandler&&(this.removeEventListener("back",this._backButtonHandler,!0),this._backButtonHandler=null)}}customElements.get("mint-page")||customElements.define("mint-page",dt);class ut extends HTMLElement{static get observedAttributes(){return["columns","sm","md","lg","xl","gap"]}constructor(){super()}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block"),this.render()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getColumns(){return this.getAttribute("columns")||"1"}getSm(){return this.getAttribute("sm")}getMd(){return this.getAttribute("md")}getLg(){return this.getAttribute("lg")}getXl(){return this.getAttribute("xl")}getGap(){return"3"}getGridClasses(){const t=["grid"],e=this.getColumns();t.push(`grid-cols-${e}`);const i=this.getSm();i&&t.push(`sm:grid-cols-${i}`);const s=this.getMd();s&&t.push(`md:grid-cols-${s}`);const n=this.getLg();n&&t.push(`lg:grid-cols-${n}`);const r=this.getXl();r&&t.push(`xl:grid-cols-${r}`);const a=this.getGap();return t.push(`gap-${a}`),t}render(){Array.from(this.classList).filter(i=>i.startsWith("grid-cols-")||i.startsWith("sm:grid-cols-")||i.startsWith("md:grid-cols-")||i.startsWith("lg:grid-cols-")||i.startsWith("xl:grid-cols-")||i.startsWith("gap-")).forEach(i=>this.classList.remove(i)),this.classList.contains("grid")||this.classList.add("grid"),this.getGridClasses().forEach(i=>{i&&i!=="grid"&&this.classList.add(i)})}}customElements.get("mint-grid")||customElements.define("mint-grid",ut);class pt extends HTMLElement{constructor(){super(),this._overlay=null,this._modal=null,this._header=null,this._headingSlot=null,this._bodySlot=null,this._actionsSlot=null,this._closeButton=null,this._darkModeObserver=null}static get observedAttributes(){return["id","heading","open"]}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()}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null)}attributeChangedCallback(t,e,i){e!==i&&this.render()}getId(){return this.getAttribute("id")||""}getHeading(){return this.getAttribute("heading")||""}isOpen(){return this.getAttribute("open")==="true"}open(){this.setAttribute("open","true")}close(){this.removeAttribute("open")}render(){const t=this.getId(),e=this.getHeading(),i=this.isOpen();if(t&&(this.id=t),this._overlay||(this._overlay=document.createElement("div"),this._overlay.className="fixed inset-0 bg-black bg-opacity-50 transition-opacity duration-200 z-40",this._overlay.addEventListener("click",()=>this.close()),this.appendChild(this._overlay)),this._modal||(this._modal=document.createElement("div"),this._modal.className="fixed inset-0 flex items-center justify-center p-2 pointer-events-none z-50",this.appendChild(this._modal)),i){let h=this._modal.querySelector(".modal-content");h||(h=document.createElement("div"),h.className="modal-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg shadow-xl max-w-2xl w-full max-h-[90vh] flex flex-col pointer-events-auto transition-all duration-200 ease-out transform",this._modal.appendChild(h)),this._animateEnter()}else this._animateExit();let s=this._modal.querySelector(".modal-content");s||(s=document.createElement("div"),s.className="modal-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg shadow-xl max-w-2xl w-full max-h-[90vh] flex flex-col pointer-events-auto transition-all duration-200 ease-out transform",this._modal.appendChild(s)),this._header||(this._header=document.createElement("div"),this._header.className="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700",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 n=this._headingSlot.querySelector("mint-text");e?(n||(n=document.createElement("mint-text"),n.setAttribute("size","sub-heading"),n.setAttribute("bold","true"),this._headingSlot.appendChild(n)),n.textContent=e):n&&n.remove(),Array.from(this.children).filter(h=>h!==this._overlay&&h!==this._modal&&h!==this._headingSlot&&h.getAttribute("slot")==="heading").forEach(h=>{this._headingSlot&&h.parentElement!==this._headingSlot&&this._headingSlot.appendChild(h)}),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(h=>h!==this._overlay&&h!==this._modal&&h!==this._bodySlot&&h.getAttribute("slot")==="body").forEach(h=>{this._bodySlot&&h.parentElement!==this._bodySlot&&this._bodySlot.appendChild(h)}),this._actionsSlot||(this._actionsSlot=document.createElement("div"),this._actionsSlot.className="p-4 border-t border-gray-200 dark:border-gray-700",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(h=>h!==this._overlay&&h!==this._modal&&h!==this._actionsSlot&&h.getAttribute("slot")==="actions").forEach(h=>{Array.from(h.children).forEach(d=>{d.parentElement!==l&&l.appendChild(d)}),h.parentElement&&h.remove()}),Array.from(this.children).forEach(h=>{h!==this._overlay&&h!==this._modal&&h.getAttribute("slot")!=="heading"&&h.getAttribute("slot")!=="body"&&h.getAttribute("slot")!=="actions"&&h!==this._headingSlot&&h!==this._bodySlot&&h!==this._actionsSlot&&h.parentElement!==this._bodySlot&&this._bodySlot.appendChild(h)}),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._modal)return;const t=document.documentElement.classList.contains("dark"),e=this._modal.querySelector(".modal-content");e&&(t?(e.classList.remove("bg-white"),e.classList.add("bg-gray-900","border","border-gray-700")):(e.classList.remove("bg-gray-900","border","border-gray-700"),e.classList.add("bg-white")))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_animateEnter(){var e;const t=(e=this._modal)==null?void 0:e.querySelector(".modal-content");t&&(t.style.transform="scale(0.97) translateY(10px)",t.style.opacity="0",t.style.transition="all 200ms ease-out",this.classList.remove("hidden"),requestAnimationFrame(()=>{requestAnimationFrame(()=>{t.style.transform="scale(1) translateY(0)",t.style.opacity="1"})}))}_animateExit(){var e;const t=(e=this._modal)==null?void 0:e.querySelector(".modal-content");if(!t){this.classList.add("hidden");return}t.style.transition="all 200ms ease-in",t.style.transform="scale(0.97) translateY(10px)",t.style.opacity="0",setTimeout(()=>{this.classList.add("hidden"),t.style.transform="",t.style.opacity="",t.style.transition=""},200)}}customElements.get("mint-modal")||customElements.define("mint-modal",pt);class ft extends HTMLElement{constructor(){super(),this._overlay=null,this._popover=null,this._triggerElement=null,this._darkModeObserver=null,this._clickOutsideHandler=null,this._triggerClickHandler=null,this._triggerHoverEnterHandler=null,this._triggerHoverLeaveHandler=null,this._popoverHoverEnterHandler=null,this._popoverHoverLeaveHandler=null,this._hoverCloseTimeout=null,this._scrollHandler=null,this._resizeHandler=null}static get observedAttributes(){return["id","direction","open","trigger-id","padding","hover"]}connectedCallback(){const t=this._isInsideModal()?"z-[60]":"z-50";this.classList.add("box-border","m-0","p-0","border-0","align-baseline","fixed","top-0","left-0",t,"pointer-events-none"),this.isOpen()||this.classList.add("hidden"),this.render(),this._setupTrigger(),this._observeDarkMode()}_isInsideModal(){let t=this;for(;t;){if(t.tagName==="MINT-MODAL")return!0;t=t.parentElement}if(this._triggerElement)for(t=this._triggerElement;t;){if(t.tagName==="MINT-MODAL")return!0;t=t.parentElement}return!1}disconnectedCallback(){this._triggerElement&&this._triggerElement.tagName==="MINT-BUTTON"&&this._triggerElement.removeAttribute("active"),this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null),this._clickOutsideHandler&&(document.removeEventListener("click",this._clickOutsideHandler),this._clickOutsideHandler=null),this._triggerClickHandler&&this._triggerElement&&(this._triggerElement.removeEventListener("click",this._triggerClickHandler,!0),this._triggerClickHandler=null),this._removeHoverListeners(),this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null)}attributeChangedCallback(t,e,i){if(e!==i){if(this.isConnected){const s=this._isInsideModal()?"z-[60]":"z-50";this.classList.remove("z-50","z-[60]"),this.classList.add(s)}this.render(),(t==="trigger-id"||t==="hover")&&this._setupTrigger(),t==="open"&&this.isOpen()&&this._closeOtherPopovers()}}getId(){return this.getAttribute("id")||""}getPadding(){const t=this.getAttribute("padding")||"4";return{0:"p-0","0.5":"p-0.5",1:"p-1","1.5":"p-1.5",2:"p-2","2.5":"p-2.5",3:"p-3","3.5":"p-3.5",4:"p-4",5:"p-5",6:"p-6",8:"p-8",10:"p-10",12:"p-12",16:"p-16",20:"p-20",24:"p-24"}[t]||"p-4"}getDirection(){return this.getAttribute("direction")||"down"}getTriggerId(){return this.getAttribute("trigger-id")||""}isHoverEnabled(){return this.getAttribute("hover")==="true"}isOpen(){return this.getAttribute("open")==="true"}open(){this.setAttribute("open","true")}close(){this.removeAttribute("open")}_setupTrigger(){const t=this.getTriggerId();this._triggerClickHandler&&this._triggerElement&&(this._triggerElement.removeEventListener("click",this._triggerClickHandler,!0),this._triggerClickHandler=null),this._removeHoverListeners(),t&&(this._triggerElement=document.getElementById(t),this._triggerElement?(this._attachTriggerListener(),this.isHoverEnabled()&&this._attachHoverListeners()):setTimeout(()=>{this._triggerElement=document.getElementById(t),this._triggerElement&&(this._attachTriggerListener(),this.isHoverEnabled()&&this._attachHoverListeners())},10))}_attachTriggerListener(){if(this._triggerElement&&!this._triggerClickHandler){const t=this;this._triggerClickHandler=function(e){e.stopImmediatePropagation(),e.preventDefault(),t.getAttribute("open")==="true"?t.removeAttribute("open"):t.setAttribute("open","true")},this._triggerElement.addEventListener("click",this._triggerClickHandler,!0)}}_attachHoverListeners(){if(!this.isHoverEnabled()||!this._triggerElement)return;this._removeHoverListeners();const t=this;this._triggerHoverEnterHandler=function(){t._cancelHoverClose(),t.open()},this._triggerHoverLeaveHandler=function(e){var s;const i=e.relatedTarget;i&&(t.contains(i)||(s=t._triggerElement)!=null&&s.contains(i))||t._scheduleHoverClose()},this._triggerElement.addEventListener("mouseenter",this._triggerHoverEnterHandler),this._triggerElement.addEventListener("mouseleave",this._triggerHoverLeaveHandler),this._popover&&(this._popoverHoverEnterHandler=function(){t._cancelHoverClose()},this._popoverHoverLeaveHandler=function(e){var s;const i=e.relatedTarget;i&&(t.contains(i)||(s=t._triggerElement)!=null&&s.contains(i))||t._scheduleHoverClose()},this._popover.addEventListener("mouseenter",this._popoverHoverEnterHandler),this._popover.addEventListener("mouseleave",this._popoverHoverLeaveHandler))}_removeHoverListeners(){this._triggerElement&&this._triggerHoverEnterHandler&&this._triggerElement.removeEventListener("mouseenter",this._triggerHoverEnterHandler),this._triggerElement&&this._triggerHoverLeaveHandler&&this._triggerElement.removeEventListener("mouseleave",this._triggerHoverLeaveHandler),this._popover&&this._popoverHoverEnterHandler&&this._popover.removeEventListener("mouseenter",this._popoverHoverEnterHandler),this._popover&&this._popoverHoverLeaveHandler&&this._popover.removeEventListener("mouseleave",this._popoverHoverLeaveHandler),this._triggerHoverEnterHandler=null,this._triggerHoverLeaveHandler=null,this._popoverHoverEnterHandler=null,this._popoverHoverLeaveHandler=null,this._cancelHoverClose()}_scheduleHoverClose(){this._cancelHoverClose(),this._hoverCloseTimeout=window.setTimeout(()=>{this._isHovering()||this.close()},120)}_cancelHoverClose(){this._hoverCloseTimeout!==null&&(clearTimeout(this._hoverCloseTimeout),this._hoverCloseTimeout=null)}_isHovering(){const t=this._triggerElement?this._triggerElement.matches(":hover"):!1,e=this._popover?this._popover.matches(":hover"):!1;return t||e}_calculatePosition(){if(!this._triggerElement||!this._popover)return{top:0,left:0,direction:"down"};const t=this._triggerElement.getBoundingClientRect(),e=this._popover.querySelector(".popover-content");if(!e)return{top:0,left:0,direction:"down"};this.classList.contains("hidden")&&(this.classList.remove("hidden"),this._popover.style.visibility="hidden");const s=e.getBoundingClientRect(),n=window.innerWidth,r=window.innerHeight,a=8;let l=this.getDirection(),o=0,c=0;switch(l){case"down":if(o=t.bottom+a,c=t.left+t.width/2-s.width/2,o+s.height>r){const h=t.top-s.height-a;h>=0?(l="up",o=h):(o=Math.max(0,r-s.height-a),o+s.height>r&&(o=0))}c<0&&(c=a),c+s.width>n&&(c=Math.max(a,n-s.width-a),c+s.width>n&&(c=n-s.width));break;case"up":if(o=t.top-s.height-a,c=t.left+t.width/2-s.width/2,o<0){const h=t.bottom+a;h+s.height<=r?(l="down",o=h):(o=Math.min(r-s.height-a,r-s.height),o<0&&(o=r-s.height))}c<0&&(c=a),c+s.width>n&&(c=Math.max(a,n-s.width-a),c+s.width>n&&(c=n-s.width));break;case"right":if(o=t.top+t.height/2-s.height/2,c=t.right+a,c+s.width>n){const h=t.left-s.width-a;h>=0?(l="left",c=h):(c=Math.max(0,n-s.width-a),c+s.width>n&&(c=n-s.width))}o<0&&(o=a),o+s.height>r&&(o=Math.max(a,r-s.height-a),o+s.height>r&&(o=r-s.height));break;case"left":if(o=t.top+t.height/2-s.height/2,c=t.left-s.width-a,c<0){const h=t.right+a;h+s.width<=n?(l="right",c=h):(c=Math.min(n-s.width-a,n-s.width),c<0&&(c=0))}o<0&&(o=a),o+s.height>r&&(o=Math.max(a,r-s.height-a),o+s.height>r&&(o=r-s.height));break}return{top:o,left:c,direction:l}}render(){const t=this.getId(),e=this.isOpen(),i=this.getPadding();if(t&&(this.id=t),e){if(this.classList.remove("hidden"),this.style.pointerEvents="auto",this._triggerElement&&this._triggerElement.tagName==="MINT-BUTTON"&&requestAnimationFrame(()=>{this._triggerElement.setAttribute("active","true");const r=this._triggerElement;typeof r.render=="function"&&requestAnimationFrame(()=>{r.render()})}),!this._clickOutsideHandler){const r=this;this._clickOutsideHandler=function(a){const l=a.composedPath(),o=l.includes(r);if(!(r._triggerElement&&l.includes(r._triggerElement))&&!o){r.close();return}},setTimeout(()=>{document.addEventListener("click",this._clickOutsideHandler,!1)},100)}}else this.classList.add("hidden"),this.style.pointerEvents="none",this._triggerElement&&this._triggerElement.tagName==="MINT-BUTTON"&&requestAnimationFrame(()=>{this._triggerElement.removeAttribute("active");const r=this._triggerElement;typeof r.render=="function"&&requestAnimationFrame(()=>{r.render()})}),this._clickOutsideHandler&&(document.removeEventListener("click",this._clickOutsideHandler,!1),this._clickOutsideHandler=null);if(this._overlay){const r=this._isInsideModal()?"z-[55]":"z-40";this._overlay.className=`fixed inset-0 pointer-events-none ${r}`}else{this._overlay=document.createElement("div");const r=this._isInsideModal()?"z-[55]":"z-40";this._overlay.className=`fixed inset-0 pointer-events-none ${r}`,this.appendChild(this._overlay)}if(this._popover){const r=this._isInsideModal()?"z-[60]":"z-50";this._popover.className=`fixed ${r} pointer-events-auto`}else{this._popover=document.createElement("div");const r=this._isInsideModal()?"z-[60]":"z-50";this._popover.className=`fixed ${r} pointer-events-auto`,this.appendChild(this._popover)}this.isHoverEnabled()&&this._attachHoverListeners();let s=this._popover.querySelector(".popover-content");if(!s)s=document.createElement("div"),s.className=`popover-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg shadow-xl ${i} transition-all duration-200 ease-out transform`,this._popover.appendChild(s);else{const r=s.className.split(" "),a=["p-0","p-0.5","p-1","p-1.5","p-2","p-2.5","p-3","p-3.5","p-4","p-5","p-6","p-8","p-10","p-12","p-16","p-20","p-24"],l=r.filter(o=>!a.includes(o));s.className=[...l,i].join(" ")}Array.from(this.children).forEach(r=>{r!==this._overlay&&r!==this._popover&&r.parentElement===this&&s.appendChild(r)}),e?(this._triggerElement||this._setupTrigger(),this._setupPositionListeners(),this.offsetHeight,this._triggerElement?this._updatePosition(s):(this._popover.style.top="50%",this._popover.style.left="50%",this._popover.style.transform="translate(-50%, -50%)",this._popover.style.visibility="visible",this._popover.style.display="block",s.style.transform="scale(0.97) translateY(10px)",s.style.opacity="0",s.style.transition="all 200ms ease-out",requestAnimationFrame(()=>{requestAnimationFrame(()=>{s.style.transform="scale(1) translateY(0)",s.style.opacity="1"})}))):!e&&s&&(this._removePositionListeners(),s.style.opacity!=="0"&&s.style.opacity!==""&&(s.style.transition="all 200ms ease-in",s.style.transform="scale(0.97) translateY(10px)",s.style.opacity="0",setTimeout(()=>{s.style.transform="",s.style.opacity="",s.style.transition="",this._popover.style.visibility="",this._popover.style.display=""},200))),this._updateBackgroundColor()}_updateBackgroundColor(){if(!this._popover)return;const t=document.documentElement.classList.contains("dark"),e=this._popover.querySelector(".popover-content");e&&(t?(e.classList.remove("bg-white"),e.classList.add("bg-gray-900","border","border-gray-700")):(e.classList.remove("bg-gray-900","border","border-gray-700"),e.classList.add("bg-white")))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_updatePosition(t){if(!this._triggerElement||!this._popover)return;const e=this._popover.style.visibility!=="hidden";e||(this._popover.style.visibility="hidden",this._popover.style.display="block",this._popover.style.top="0",this._popover.style.left="0"),this._popover.offsetHeight;const i=this._calculatePosition();this._popover.style.top=`${i.top}px`,this._popover.style.left=`${i.left}px`,e||(this._popover.style.visibility="visible",t&&(!t.style.opacity||t.style.opacity==="")&&(t.style.transform="scale(0.97) translateY(10px)",t.style.opacity="0",t.style.transition="all 200ms ease-out",requestAnimationFrame(()=>{requestAnimationFrame(()=>{t.style.transform="scale(1) translateY(0)",t.style.opacity="1"})})))}_setupPositionListeners(){if(!this._scrollHandler&&this.isOpen()){const t=this;this._scrollHandler=function(){if(t.isOpen()&&t._popover){const e=t._popover.querySelector(".popover-content");e&&t._updatePosition(e)}},window.addEventListener("scroll",this._scrollHandler,!0)}if(!this._resizeHandler&&this.isOpen()){const t=this;this._resizeHandler=function(){if(t.isOpen()&&t._popover){const e=t._popover.querySelector(".popover-content");e&&t._updatePosition(e)}},window.addEventListener("resize",this._resizeHandler)}}_removePositionListeners(){this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler,!0),this._scrollHandler=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null)}_closeOtherPopovers(){Array.from(document.querySelectorAll("mint-popover[open]")).forEach(e=>{if(e!==this){const i=e;typeof i.close=="function"?i.close():e.removeAttribute("open")}})}}customElements.get("mint-popover")||customElements.define("mint-popover",ft);class gt extends HTMLElement{constructor(){super(),this._checkbox=null,this._checked=!1,this._clickHandler=null,this._changeHandler=null,this._mousedownHandler=null,this._mouseupHandler=null,this._mouseleaveHandler=null,this._touchstartHandler=null,this._touchendHandler=null,this._focusHandler=null,this._blurHandler=null}static get observedAttributes(){return["checked","disabled","label","info","id","name","value","error","error-message","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-flex","items-start","gap-2");const t=this.getAttribute("checked");this._checked=t==="true",this.render()}disconnectedCallback(){this.removeEventListeners()}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(t==="checked"&&(this._checked=i==="true",this._checkbox&&(this._checkbox.checked=this._checked)),e!==i){if(t==="error"||t==="error-message"){this._renderErrorState();return}if(t==="loading"){this.render();return}this.render(),t==="checked"&&this._checkbox&&this.updateVisualState()}}get checked(){try{return this._checked||!1}catch{return!1}}set checked(t){try{t?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this._checked=!!t,this._checkbox&&(this._checkbox.checked=this._checked),this.updateVisualState()}catch{}}isDisabled(){return this.getAttribute("disabled")==="true"}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getId(){return this.getAttribute("id")||""}getName(){return this.getAttribute("name")||""}getValue(){return this.getAttribute("value")||""}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getCheckboxClasses(){const t=this.hasError(),e=["relative","inline-flex","items-center","justify-center","flex-shrink-0","w-5","h-5","rounded","border-2","transition-all","duration-200","outline-none","focus:outline-none","focus-visible:ring-2","focus-visible:ring-offset-1",t?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500","cursor-pointer","disabled:opacity-40","disabled:cursor-not-allowed"],i=this._checked?["bg-slate-800","dark:bg-slate-600",t?"border-red-300 dark:border-red-300":"border-slate-800 dark:border-slate-600"]:["bg-white","dark:bg-gray-700",t?"border-red-300 dark:border-red-300":"border-gray-300 dark:border-gray-500"];return[...e,...i].join(" ")}render(){const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.isDisabled();let n=this.querySelector(".mint-checkbox-container");n||(n=document.createElement("div"),n.className="mint-checkbox-container relative inline-flex items-start gap-2",this.insertBefore(n,this.firstChild));let r=this.querySelector(".mint-checkbox-wrapper");r?r.parentElement!==n&&n.appendChild(r):(r=document.createElement("div"),r.className="mint-checkbox-wrapper",n.appendChild(r)),this._checkbox?this._checkbox.parentElement!==r&&r.appendChild(this._checkbox):(this._checkbox=document.createElement("input"),this._checkbox.type="checkbox",r.appendChild(this._checkbox),this.setupEventListeners()),this._checkbox.className="absolute inset-0 w-full h-full opacity-0 cursor-pointer",this._checkbox.style.cssText="position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; z-index: 10; pointer-events: auto; margin: 0; padding: 0;",this._checkbox.checked=this._checked,this._checkbox.disabled=s,this._changeHandler||this.setupEventListeners();const a=this.getId();a?this._checkbox.id=a:this._checkbox.removeAttribute("id");const l=this.getName();l?this._checkbox.name=l:this._checkbox.removeAttribute("name");const o=this.getValue();o?this._checkbox.value=o:this._checkbox.removeAttribute("value"),e?this._checkbox.setAttribute("aria-label",e):this._checkbox.removeAttribute("aria-label"),r.className=`mint-checkbox-wrapper ${this.getCheckboxClasses()}`,r.style.cursor="pointer",r.style.pointerEvents="auto",this._checkbox.style.pointerEvents="auto";const c=r;c._wrapperClickHandler||(c._wrapperClickHandler=p=>{p.target===r&&!s&&(p.preventDefault(),p.stopPropagation(),this.toggle())},r.addEventListener("click",c._wrapperClickHandler));let h=r.querySelector("mint-icon");h||(h=document.createElement("mint-icon"),h.setAttribute("name","check"),h.className="w-3.5 h-3.5 text-white pointer-events-none absolute inset-0 m-auto",h.style.transition="opacity 200ms ease-out, transform 200ms ease-out",h.style.zIndex="1",r.appendChild(h)),this.updateVisualState();let f=this.querySelector(".mint-checkbox-label-container");const d=this.querySelector(".mint-checkbox-container");if(e||i){f?d&&f.parentElement!==d&&d.appendChild(f):(f=document.createElement("div"),f.className="mint-checkbox-label-container flex flex-col gap-0.5 flex-1",d?d.appendChild(f):this.appendChild(f));let p=f.querySelector(".mint-checkbox-label");e?(p||(p=document.createElement("span"),p.className="mint-checkbox-label text-sm font-medium text-gray-900 dark:text-gray-100 cursor-pointer select-none",f.insertBefore(p,f.firstChild)),p.textContent=e,s?p.classList.add("opacity-40"):p.classList.remove("opacity-40")):p&&p.remove();let u=f.querySelector(".mint-checkbox-info");if(i?(u||(u=document.createElement("span"),u.className="mint-checkbox-info text-xs text-gray-500 dark:text-gray-400 cursor-pointer select-none",f.appendChild(u)),u.textContent=i,s?u.classList.add("opacity-40"):u.classList.remove("opacity-40")):u&&u.remove(),s)f.style.cursor="default",f._clickHandler&&(f.removeEventListener("click",f._clickHandler),f._clickHandler=null);else{f.style.cursor="pointer";const _=f._clickHandler;_&&f.removeEventListener("click",_),f._clickHandler=g=>{this._checkbox&&(g.target===this._checkbox||this._checkbox.contains(g.target)||g.composedPath().includes(this._checkbox))||this.toggle()},f.addEventListener("click",f._clickHandler)}}else f&&f.remove();this._renderErrorState(),this._renderSkeleton(t)}setupEventListeners(){this.removeEventListeners(),this._checkbox&&(this._changeHandler=t=>{t.stopPropagation(),this._checked=this._checkbox.checked,this._checked?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this.updateVisualState();const e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e),this.dispatchEvent(new CustomEvent("input",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0,composed:!0}));const i=new CustomEvent("change",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0});this.dispatchEvent(i)},this._checkbox.addEventListener("change",this._changeHandler),this._mousedownHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&!this.isDisabled()&&(e.classList.add("mint-checkbox-active"),this._checked?(e.style.backgroundColor="rgb(15 23 42)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.3)"):(e.style.backgroundColor="rgb(243 244 246)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.1)"),document.documentElement.classList.contains("dark")&&(this._checked?e.style.backgroundColor="rgb(51 65 85)":e.style.backgroundColor="rgb(31 41 55)"))},this._mouseupHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&(e.classList.remove("mint-checkbox-active"),e.style.backgroundColor="",e.style.boxShadow="")},this._mouseleaveHandler=t=>{const e=this.querySelector(".mint-checkbox-wrapper");e&&(e.classList.remove("mint-checkbox-active"),e.style.backgroundColor="",e.style.boxShadow="")},this._checkbox.addEventListener("mousedown",this._mousedownHandler),this._checkbox.addEventListener("mouseup",this._mouseupHandler),this._checkbox.addEventListener("mouseleave",this._mouseleaveHandler),this._focusHandler=t=>{const e=this.querySelector(".mint-checkbox-wrapper");e&&this._checkbox&&requestAnimationFrame(()=>{this._checkbox&&this._checkbox.matches(":focus-visible")&&(e==null||e.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500"))})},this._blurHandler=()=>{const t=this.querySelector(".mint-checkbox-wrapper");t&&t.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._checkbox.addEventListener("focus",this._focusHandler),this._checkbox.addEventListener("blur",this._blurHandler),this._touchstartHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&!this.isDisabled()&&(e.classList.add("mint-checkbox-active"),this._checked?(e.style.backgroundColor="rgb(15 23 42)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.3)"):(e.style.backgroundColor="rgb(243 244 246)",e.style.boxShadow="inset 0 2px 4px rgba(0, 0, 0, 0.1)"),document.documentElement.classList.contains("dark")&&(this._checked?e.style.backgroundColor="rgb(51 65 85)":e.style.backgroundColor="rgb(31 41 55)"))},this._touchendHandler=t=>{t.stopPropagation();const e=this.querySelector(".mint-checkbox-wrapper");e&&(e.classList.remove("mint-checkbox-active"),e.style.backgroundColor="",e.style.boxShadow="")},this._checkbox.addEventListener("touchstart",this._touchstartHandler),this._checkbox.addEventListener("touchend",this._touchendHandler))}removeEventListeners(){this._checkbox&&(this._changeHandler&&(this._checkbox.removeEventListener("change",this._changeHandler),this._changeHandler=null),this._mousedownHandler&&(this._checkbox.removeEventListener("mousedown",this._mousedownHandler),this._mousedownHandler=null),this._mouseupHandler&&(this._checkbox.removeEventListener("mouseup",this._mouseupHandler),this._mouseupHandler=null),this._mouseleaveHandler&&(this._checkbox.removeEventListener("mouseleave",this._mouseleaveHandler),this._mouseleaveHandler=null),this._touchstartHandler&&(this._checkbox.removeEventListener("touchstart",this._touchstartHandler),this._touchstartHandler=null),this._touchendHandler&&(this._checkbox.removeEventListener("touchend",this._touchendHandler),this._touchendHandler=null),this._focusHandler&&(this._checkbox.removeEventListener("focus",this._focusHandler),this._focusHandler=null),this._blurHandler&&(this._checkbox.removeEventListener("blur",this._blurHandler),this._blurHandler=null));const t=this.querySelector(".mint-checkbox-wrapper");if(t){const e=t;e._wrapperClickHandler&&(t.removeEventListener("click",e._wrapperClickHandler),e._wrapperClickHandler=null)}}updateVisualState(){const t=this.querySelector(".mint-checkbox-wrapper"),e=t==null?void 0:t.querySelector("mint-icon");e&&(e.style.opacity=this._checked?"1":"0",e.style.transform=this._checked?"scale(1)":"scale(0.8)"),t&&(t.className=`mint-checkbox-wrapper ${this.getCheckboxClasses()}`,t.classList.contains("mint-checkbox-active")||(t.style.backgroundColor="",t.style.boxShadow=""))}toggle(){if(this._checkbox&&!this.isDisabled()){this._checkbox.checked=!this._checked,this._checked=this._checkbox.checked,this._checked?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this.updateVisualState(),this.dispatchEvent(new CustomEvent("input",{detail:{checked:this._checked},bubbles:!0,cancelable:!0,composed:!0}));const t=new CustomEvent("change",{detail:{checked:this._checked},bubbles:!0,cancelable:!0});this.dispatchEvent(t)}}_renderSkeleton(t){let e=this.querySelector(".mint-checkbox-skeleton-container");const i=this.querySelector(".mint-checkbox-container"),s=this.querySelector(".mint-checkbox-wrapper"),n=this.querySelector(".mint-checkbox-label-container");if(t){e||(e=document.createElement("div"),e.className="mint-checkbox-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center gap-2",i?i.appendChild(e):(this.style.position="relative",this.appendChild(e)));let r=e.querySelector(".mint-checkbox-skeleton-box");if(r||(r=document.createElement("div"),r.className="mint-checkbox-skeleton-box flex-shrink-0 w-5 h-5 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(r)),n){let a=e.querySelector(".mint-checkbox-skeleton-label");a||(a=document.createElement("div"),a.className="mint-checkbox-skeleton-label h-4 w-24 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(a))}e.style.display="flex",s&&(s.style.visibility="hidden",s.style.pointerEvents="none"),n&&(n.style.visibility="hidden",n.style.pointerEvents="none")}else e&&(e.style.display="none"),s&&(s.style.visibility="visible",s.style.pointerEvents="auto"),n&&(n.style.visibility="visible",n.style.pointerEvents="auto")}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-checkbox-label-container");!i&&t&&e&&(i=document.createElement("div"),i.className="mint-checkbox-label-container flex flex-col gap-0.5 flex-1",this.appendChild(i));let s=this.querySelector(".mint-checkbox-error");t&&e?(s?(s.classList.add("block","w-full"),s.style.display="block",(i&&s.parentElement!==i||i&&s.parentElement===i)&&i.appendChild(s)):(s=document.createElement("div"),s.className="mint-checkbox-error text-xs text-red-600 dark:text-red-400 block w-full",s.style.display="block",i?i.appendChild(s):this.appendChild(s)),s.textContent=e):s&&s.remove();const n=this.querySelector(".mint-checkbox-wrapper");n&&(n.className=`mint-checkbox-wrapper ${this.getCheckboxClasses()}`)}}customElements.get("mint-checkbox")||customElements.define("mint-checkbox",gt);class Nt extends HTMLElement{constructor(){super(),this._radio=null,this._checked=!1,this._changeHandler=null,this._clickHandler=null,this._focusHandler=null,this._blurHandler=null,this._keydownHandler=null}static get observedAttributes(){return["value","checked","disabled","loading","info"]}connectedCallback(){this.classList.add("inline-flex","items-start","gap-2","cursor-pointer","select-none");const t=this.getAttribute("checked");this._checked=t!==null&&t!=="false",this.render(),this._setupClickHandler()}disconnectedCallback(){this._clickHandler&&(this.removeEventListener("click",this._clickHandler),this._clickHandler=null),this._radio&&(this._changeHandler&&(this._radio.removeEventListener("change",this._changeHandler),this._changeHandler=null),this._focusHandler&&(this._radio.removeEventListener("focus",this._focusHandler),this._focusHandler=null),this._blurHandler&&(this._radio.removeEventListener("blur",this._blurHandler),this._blurHandler=null),this._keydownHandler&&(this._radio.removeEventListener("keydown",this._keydownHandler),this._keydownHandler=null))}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(t==="checked"&&(this._checked=i==="true",this._radio&&(this._radio.checked=this._checked),this._updateVisualState()),e!==i){if(t==="loading"){this.render();return}if(t==="info"){this.render();return}this.render()}}get checked(){try{return this._checked||!1}catch{return!1}}set checked(t){try{this._checked=!!t,t?this.setAttribute("checked","true"):this.setAttribute("checked","false"),this._radio&&(this._radio.checked=this._checked),this.isConnected?requestAnimationFrame(()=>{this._updateVisualState()}):this._updateVisualState()}catch{}}getValue(){return this.getAttribute("value")||""}getInfo(){return this.getAttribute("info")||""}isDisabled(){const e=this.getAttribute("disabled")==="true",i=this.closest("mint-choice"),n=(i==null?void 0:i.getAttribute("disabled"))==="true";return e||n}_setupClickHandler(){this._clickHandler||(this._clickHandler=t=>{t.target!==this._radio&&(this.isDisabled()||this._radio&&(this._radio.click(),requestAnimationFrame(()=>{if(this._radio&&this._radio.checked!==this._checked){this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.removeAttribute("checked"),this._updateVisualState(),this._updateGroupState();const e=this.closest("mint-choice");e&&e.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0}))}})))},this.addEventListener("click",this._clickHandler))}render(){var u;const t=this.isLoading(),e=this.isDisabled(),i=this.getValue(),s=this.closest("mint-choice"),n=(s==null?void 0:s.getAttribute("name"))||"";let r="";const a=this.querySelector(".mint-choice-option-label");if(a)r=((u=a.textContent)==null?void 0:u.trim())||"";else{const _=this.querySelector(".mint-choice-option-label-container");Array.from(this.childNodes).forEach(g=>{var m;if(g!==_&&g.nodeType===Node.TEXT_NODE){const v=(m=g.textContent)==null?void 0:m.trim();v&&(r+=v)}})}const l=this.querySelectorAll(".mint-choice-option-wrapper");let o=null;if(l.length>0&&(this._radio&&(o=Array.from(l).find(_=>_.contains(this._radio))),o||(o=l[0]),l.forEach((_,g)=>{_!==o&&_.remove()})),o||(o=document.createElement("div"),o.className="mint-choice-option-wrapper",o.style.position="relative",this.insertBefore(o,this.firstChild)),o.className=`mint-choice-option-wrapper ${this._getWrapperClasses()}`,o.style.position="relative",this.querySelectorAll('input[type="radio"]').forEach(_=>{_!==this._radio&&_.remove()}),this._radio)this._radio.parentElement!==o&&o.appendChild(this._radio),this._radio&&this._changeHandler&&(this._radio.removeEventListener("change",this._changeHandler),this._radio.addEventListener("change",this._changeHandler)),this._radio&&(this._focusHandler||(this._focusHandler=_=>{const g=this.querySelector(".mint-choice-option-wrapper");g&&!this.isDisabled()&&g.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")}),this._blurHandler||(this._blurHandler=()=>{const _=this.querySelector(".mint-choice-option-wrapper");_&&_.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")}),this._keydownHandler||(this._keydownHandler=_=>{this.isDisabled()||(_.key==="ArrowDown"||_.key==="ArrowRight"?(_.preventDefault(),this._focusNextOption()):(_.key==="ArrowUp"||_.key==="ArrowLeft")&&(_.preventDefault(),this._focusPreviousOption()))}),this._radio.removeEventListener("focus",this._focusHandler),this._radio.removeEventListener("blur",this._blurHandler),this._radio.removeEventListener("keydown",this._keydownHandler),this._radio.addEventListener("focus",this._focusHandler),this._radio.addEventListener("blur",this._blurHandler),this._radio.addEventListener("keydown",this._keydownHandler));else{this._radio=document.createElement("input"),this._radio.type="radio",this._radio.className="sr-only",this._radio.style.position="absolute",this._radio.style.width="1px",this._radio.style.height="1px",this._radio.style.padding="0",this._radio.style.margin="-1px",this._radio.style.overflow="hidden",this._radio.style.clip="rect(0, 0, 0, 0)",this._radio.style.whiteSpace="nowrap",this._radio.style.border="0",o.appendChild(this._radio),this._changeHandler=g=>{const m=this._checked;this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.removeAttribute("checked"),this._updateVisualState(),this._updateGroupState();const v=this.closest("mint-choice");m!==this._checked&&v&&setTimeout(()=>{v.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:this._checked,value:this.getValue()},bubbles:!0,cancelable:!0}))},0)},this._radio.addEventListener("change",this._changeHandler);const _=()=>{this._radio&&this._radio.checked!==this._checked&&(this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.removeAttribute("checked"),this._updateVisualState(),this._updateGroupState())};this._radio.addEventListener("click",_),this._focusHandler=g=>{const m=this.querySelector(".mint-choice-option-wrapper");m&&!this.isDisabled()&&m.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._radio.addEventListener("focus",this._focusHandler),this._blurHandler=()=>{const g=this.querySelector(".mint-choice-option-wrapper");g&&g.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._radio.addEventListener("blur",this._blurHandler),this._keydownHandler=g=>{this.isDisabled()||(g.key==="ArrowDown"||g.key==="ArrowRight"?(g.preventDefault(),this._focusNextOption()):(g.key==="ArrowUp"||g.key==="ArrowLeft")&&(g.preventDefault(),this._focusPreviousOption()))},this._radio.addEventListener("keydown",this._keydownHandler)}this._radio.name=n,this._radio.value=i,this._radio.checked!==this._checked?(this._checked=this._radio.checked,this._checked?this.setAttribute("checked","true"):this.setAttribute("checked","false")):this._radio.checked=this._checked,this._radio.disabled=e,e?this._radio.setAttribute("tabindex","-1"):this._radio.removeAttribute("tabindex"),r?this._radio.setAttribute("aria-label",r):this._radio.removeAttribute("aria-label"),o.querySelectorAll(".mint-choice-option-indicator").forEach((_,g)=>{g>0&&_.remove()});let f=o.querySelector(".mint-choice-option-indicator");f||(f=document.createElement("div"),f.className="mint-choice-option-indicator",o.appendChild(f)),f.className="mint-choice-option-indicator w-2 h-2 rounded-full bg-white transition-all duration-200 pointer-events-none",f.style.position="absolute",f.style.top="50%",f.style.left="50%",f.style.transform=this._checked?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0)",f.style.opacity=this._checked?"1":"0",this._updateVisualState(),this._renderSkeleton(t);const d=this.getInfo();let p=this.querySelector(".mint-choice-option-label-container");if(r||d){p||(p=document.createElement("div"),p.className="mint-choice-option-label-container flex flex-col gap-0.5",this.appendChild(p),Array.from(this.childNodes).forEach(m=>{var v;m.nodeType===Node.TEXT_NODE&&((v=m.textContent)!=null&&v.trim())&&m!==p&&(m.textContent="")}));let _=p.querySelector(".mint-choice-option-label");r?(_||(_=document.createElement("span"),_.className="mint-choice-option-label",p.appendChild(_)),_.className=`mint-choice-option-label text-sm text-gray-900 dark:text-gray-100 ${e?"opacity-40":""}`,_.textContent=r):_&&_.remove();let g=p.querySelector(".mint-choice-option-info");d?(g||(g=document.createElement("span"),g.className="mint-choice-option-info text-xs text-gray-500 dark:text-gray-400 select-none",p.appendChild(g)),g.textContent=d,e?g.classList.add("opacity-40"):g.classList.remove("opacity-40")):g&&g.remove()}else p&&p.remove();e?(this.classList.add("cursor-not-allowed"),this.classList.remove("cursor-pointer")):(this.classList.add("cursor-pointer"),this.classList.remove("cursor-not-allowed")),this._updateVisualState()}_getWrapperClasses(){const t=this.isDisabled(),e=["inline-flex","items-center","justify-center","w-[1rem]","h-[1rem]","rounded-full","border-2","transition-all","duration-200","flex-shrink-0","mt-0.5"];return t&&e.push("opacity-40","cursor-not-allowed"),this._checked?e.push("bg-slate-800","dark:bg-slate-600","border-slate-800","dark:border-slate-600"):e.push("bg-white","dark:bg-gray-900","border-gray-300","dark:border-gray-500"),e.join(" ")}_updateVisualState(){const t=this.querySelector(".mint-choice-option-wrapper");t&&(t.className=`mint-choice-option-wrapper ${this._getWrapperClasses()}`);const e=this.querySelector(".mint-choice-option-indicator");e&&(e.style.opacity=this._checked?"1":"0",e.style.transform=this._checked?"translate(-50%, -50%) scale(1)":"translate(-50%, -50%) scale(0)")}_renderSkeleton(t){let e=this.querySelector(".mint-choice-option-skeleton-container");const i=this.querySelector(".mint-choice-option-wrapper");if(t){e||(e=document.createElement("div"),e.className="mint-choice-option-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center gap-2",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-choice-option-skeleton-radio");if(s||(s=document.createElement("div"),s.className="mint-choice-option-skeleton-radio flex-shrink-0 w-5 h-5 rounded-full bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(s)),e.style.display="flex",i){const n=i.querySelector('input[type="radio"]'),r=i.querySelector(".mint-choice-option-indicator");n&&(n.style.visibility="hidden"),r&&(r.style.visibility="hidden"),i.style.pointerEvents="none"}}else{if(e&&(e.style.display="none"),i){const n=i.querySelector('input[type="radio"]'),r=i.querySelector(".mint-choice-option-indicator");n&&(n.style.visibility="visible"),r&&(r.style.visibility="visible"),i.style.pointerEvents="auto"}const s=this.querySelector(".mint-choice-option-label");s&&!(i!=null&&i.contains(s))&&(s.style.visibility="visible",s.style.pointerEvents="auto")}}_updateGroupState(){var e;if(!((e=this._radio)!=null&&e.name))return;document.querySelectorAll(`input[type="radio"][name="${this._radio.name}"]`).forEach(i=>{if(i===this._radio)return;const s=i.closest("mint-choice-option");s&&s!==this&&(s._checked=i.checked,i.checked?s.setAttribute("checked","true"):s.removeAttribute("checked"),s._updateVisualState())})}_focusNextOption(){var s;if(!((s=this._radio)!=null&&s.name))return;const t=Array.from(document.querySelectorAll(`input[type="radio"][name="${this._radio.name}"]`)).filter(n=>!n.disabled),e=t.indexOf(this._radio);let i=null;if(e>=0&&e<t.length-1?i=t[e+1]:t.length>0&&(i=t[0]),i){const n=i.closest("mint-choice-option");if(i.checked=!0,n){const r=n._checked;if(n._checked=!0,n.setAttribute("checked","true"),n._changeHandler){const l=new Event("change",{bubbles:!0});n._changeHandler.call(n,l)}else n._updateVisualState(),n._updateGroupState();const a=n.closest("mint-choice");a&&!r&&setTimeout(()=>{a.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:!0,value:n.getValue()},bubbles:!0,cancelable:!0}))},0)}i.focus(),i.dispatchEvent(new Event("change",{bubbles:!0}))}}_focusPreviousOption(){var s;if(!((s=this._radio)!=null&&s.name))return;const t=Array.from(document.querySelectorAll(`input[type="radio"][name="${this._radio.name}"]`)).filter(n=>!n.disabled),e=t.indexOf(this._radio);let i=null;if(e>0?i=t[e-1]:t.length>0&&(i=t[t.length-1]),i){const n=i.closest("mint-choice-option");if(i.checked=!0,n){const r=n._checked;if(n._checked=!0,n.setAttribute("checked","true"),n._changeHandler){const l=new Event("change",{bubbles:!0});n._changeHandler.call(n,l)}else n._updateVisualState(),n._updateGroupState();const a=n.closest("mint-choice");a&&!r&&setTimeout(()=>{a.dispatchEvent(new CustomEvent("choice-change",{detail:{checked:!0,value:n.getValue()},bubbles:!0,cancelable:!0}))},0)}i.focus(),i.dispatchEvent(new Event("change",{bubbles:!0}))}}}customElements.get("mint-choice-option")||customElements.define("mint-choice-option",Nt);class _t extends HTMLElement{constructor(){super(),this._optionsContainer=null}static get observedAttributes(){return["label","name","info","error","error-message","id","disabled","required","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","block","w-full"),this.render(),this.addEventListener("choice-change",t=>{var r;const i=((r=t.detail)==null?void 0:r.value)||this.getValue();(this.getAttribute("value")||"")!==i&&(i?this.setAttribute("value",i):this.removeAttribute("value"));const n=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(n),this.dispatchEvent(new CustomEvent("input",{detail:{value:i},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:{value:i},bubbles:!0,cancelable:!0,composed:!0}))})}disconnectedCallback(){}isLoading(){return this.hasAttribute("loading")}attributeChangedCallback(t,e,i){e!==i&&(t==="error"||t==="error-message"?this._renderErrorState():t==="loading"?(this.render(),this.querySelectorAll("mint-choice-option").forEach(n=>{this.isLoading()?n.setAttribute("loading","true"):n.removeAttribute("loading")})):(this.render(),t==="name"&&this.querySelectorAll("mint-choice-option").forEach(n=>{typeof n.render=="function"&&n.render()})))}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getName(){return this.getAttribute("name")||""}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getId(){return this.getAttribute("id")||""}isDisabled(){return this.getAttribute("disabled")==="true"}isRequired(){return this.getAttribute("required")==="true"}getValue(){const t=this.querySelector('input[type="radio"]:checked');return(t==null?void 0:t.value)||""}setValue(t){const e=this.querySelectorAll("mint-choice-option");e.forEach(i=>{if((i.getAttribute("value")||"")===t){const n=i;n.checked=!0;const r=i.querySelector('input[type="radio"]');r&&(r.checked=!0,r.dispatchEvent(new Event("change",{bubbles:!0})))}else{const n=i;n.checked=!1;const r=i.querySelector('input[type="radio"]');r&&(r.checked=!1)}}),requestAnimationFrame(()=>{e.forEach(i=>{typeof i._updateVisualState=="function"&&i._updateVisualState();const s=i.querySelector('input[type="radio"]');if(s){const n=i;s.checked!==n.checked&&(s.checked=n.checked)}})})}get value(){try{return this.getValue()||""}catch{return""}}set value(t){try{this.setValue(t||"")}catch{}}render(){const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.getId()||`mint-choice-${Math.random().toString(36).substr(2,9)}`;this.getId()||this.setAttribute("id",s);const n=this.isDisabled();let r=this.querySelector(".mint-choice-label-container");if(e||i){r||(r=document.createElement("div"),r.className="mint-choice-label-container flex flex-col gap-0.5 mb-2",this.insertBefore(r,this.firstChild));let o=r.querySelector(".mint-choice-label");e?(o||(o=document.createElement("label"),o.className="mint-choice-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",r.insertBefore(o,r.firstChild)),o.textContent=e,o.setAttribute("for",s),n?o.classList.add("opacity-40"):o.classList.remove("opacity-40")):o&&o.remove();let c=r.querySelector(".mint-choice-info");i?(c||(c=document.createElement("span"),c.className="mint-choice-info text-xs text-gray-500 dark:text-gray-400 select-none",r.appendChild(c)),c.textContent=i,n?c.classList.add("opacity-40"):c.classList.remove("opacity-40")):c&&c.remove()}else r&&r.remove();let a=this.querySelector(".mint-choice-options-wrapper");if(!a){a=document.createElement("div"),a.className="mint-choice-options-wrapper relative";const o=this.querySelector(".mint-choice-label-container");o&&o.parentElement===this?this.insertBefore(a,o.nextSibling):this.insertBefore(a,this.firstChild)}this._optionsContainer?this._optionsContainer.parentElement!==a&&a.appendChild(this._optionsContainer):(this._optionsContainer=document.createElement("div"),this._optionsContainer.className="mint-choice-options-container flex flex-col gap-3",a.appendChild(this._optionsContainer)),Array.from(this.children).filter(o=>o.tagName==="MINT-CHOICE-OPTION"&&o.parentElement!==this._optionsContainer).forEach(o=>{this._optionsContainer.appendChild(o)}),this._renderErrorState(),this._renderSkeleton(t)}_renderSkeleton(t){let e=this.querySelector(".mint-choice-skeleton-container");const i=this.querySelector(".mint-choice-options-wrapper"),s=this.querySelector(".mint-choice-options-container");if(t){if(e||(e=document.createElement("div"),e.className="mint-choice-skeleton-container absolute inset-0 z-10 pointer-events-none flex flex-col gap-3",i?i.appendChild(e):(this.style.position="relative",this.appendChild(e))),e.querySelectorAll(".mint-choice-option-skeleton").length===0)for(let r=0;r<3;r++){const a=document.createElement("div");a.className="mint-choice-option-skeleton flex items-center gap-3";const l=document.createElement("div");l.className="flex-shrink-0 w-5 h-5 rounded-full bg-gray-200 dark:bg-gray-700 animate-pulse",a.appendChild(l);const o=document.createElement("div");o.className="h-4 w-20 rounded bg-gray-200 dark:bg-gray-700 animate-pulse",a.appendChild(o),e.appendChild(a)}e.style.display="flex",s&&(s.style.opacity="0",s.style.pointerEvents="none")}else e&&(e.style.display="none"),s&&(s.style.opacity="1",s.style.pointerEvents="auto")}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-choice-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-choice-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}}customElements.get("mint-choice")||customElements.define("mint-choice",_t);class mt extends HTMLElement{constructor(){super(),this._input=null,this._textarea=null,this._element=null,this._wrapper=null,this._icon=null,this._colorPicker=null,this._colorTextInput=null,this._colorContainer=null,this._colorPickerWrapper=null,this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null,this._focusHandler=null,this._blurHandler=null,this._clickHandler=null,this._clickOutsideHandler=null}static get observedAttributes(){return["type","placeholder","value","disabled","id","name","required","readonly","rows","icon","label","info","error","error-message","loading"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render()}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){this._renderErrorState(),this._element&&(this._element.className=this.getInputClasses()),this._colorTextInput&&(this._colorTextInput.className=this.getInputClasses());return}if(t==="loading"){this.render();return}this.render()}}getType(){return this.getAttribute("type")||"text"}getRows(){const t=this.getAttribute("rows");return t?parseInt(t,10):3}_getNormalizedType(){const t=this.getType();return t==="datetime"?"datetime-local":t==="money"?"text":t==="textarea"?"textarea":t}_isTextarea(){return this.getType()==="textarea"}_isMoney(){return this.getType()==="money"}_isColor(){return this.getType()==="color"}_isNumber(){return this.getType()==="number"}getPlaceholder(){return this.getAttribute("placeholder")||""}getValue(){var t,e,i;return this._isColor()?((t=this._colorPicker)==null?void 0:t.value)||((e=this._colorTextInput)==null?void 0:e.value)||this.getAttribute("value")||"#000000":((i=this._element)==null?void 0:i.value)||this.getAttribute("value")||""}set value(t){try{this._isColor()?(this._colorPicker&&(this._colorPicker.value=t||"#000000"),this._colorTextInput&&(this._colorTextInput.value=t||"#000000")):this._element&&(this._element.value=t),t?this.setAttribute("value",t):this.removeAttribute("value")}catch{}}get value(){try{return this.getValue()||""}catch{return""}}isDisabled(){return this.getAttribute("disabled")==="true"}isReadonly(){return this.getAttribute("readonly")==="true"}isRequired(){return this.getAttribute("required")==="true"}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}getId(){return this.getAttribute("id")||""}getName(){return this.getAttribute("name")||""}getIcon(){return this.getAttribute("icon")||""}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}getInputClasses(){const t=this._isTextarea(),e=!!this.getIcon(),i=this._isColor(),s=this._isNumber(),n=this.hasError(),r=["w-full",e||i?"pl-10":"px-3.5",e||i?"pr-3.5":s?"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-gray-900","text-gray-900","dark:text-white",t?"transition-colors transition-opacity":"transition-all","duration-200","outline-none","focus:outline-none","disabled:opacity-40","disabled:cursor-not-allowed","readonly:cursor-default",t?"resize-y":"",s?"[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none":""],a=["border-2",n?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700"],l=["focus-visible:ring-2","focus-visible:ring-offset-1",n?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500"];return[...r,...a,...l].filter(Boolean).join(" ")}isLoading(){return this.getAttribute("loading")==="true"}render(){var v,b,y,C;this.getType();const t=this._getNormalizedType(),e=this._isTextarea(),i=this._isMoney(),s=this._isColor(),n=this.getPlaceholder(),r=this.isDisabled(),a=this.isReadonly(),l=this.isRequired(),o=this.getId(),c=this.getName(),h=this.getAttribute("value")||(s?"#000000":""),f=this.getRows(),d=this.getIcon(),p=this.getLabel(),u=this.getInfo(),_=this.isLoading();if(this._renderSkeleton(_),s){this._input&&(this._input.remove(),this._input=null),this._textarea&&(this._textarea.remove(),this._textarea=null),this._wrapper||(this._wrapper=document.createElement("div"),this._wrapper.className="relative w-full",this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null),this._colorPickerWrapper&&!s&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null),this._colorPickerWrapper||(this._colorPickerWrapper=document.createElement("div"),this._colorPickerWrapper.className="mint-color-picker-wrapper absolute left-[.65rem] top-1/2 -translate-y-1/2 w-6 h-6 rounded cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",this._colorPickerWrapper.style.backgroundColor=h||"#000000",this._wrapper.appendChild(this._colorPickerWrapper),this._colorPicker=document.createElement("input"),this._colorPicker.type="color",this._colorPicker.className="absolute inset-0 w-full h-full opacity-0 cursor-pointer",this._colorPicker.style.cssText="position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; z-index: 10; pointer-events: auto; margin: 0; padding: 0; border: none;",this._colorPickerWrapper.appendChild(this._colorPicker),this._focusHandler=x=>{this._colorPickerWrapper&&this._colorPicker&&this._colorPicker.matches(":focus-visible")&&requestAnimationFrame(()=>{var S;this._colorPicker&&this._colorPicker.matches(":focus-visible")&&((S=this._colorPickerWrapper)==null||S.classList.add("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500"))})},this._blurHandler=()=>{this._colorPickerWrapper&&this._colorPickerWrapper.classList.remove("ring-2","ring-offset-1","ring-gray-400","dark:ring-gray-500")},this._colorPicker.addEventListener("focus",this._focusHandler),this._colorPicker.addEventListener("blur",this._blurHandler),this._colorPicker.addEventListener("input",()=>{var S;const x=((S=this._colorPicker)==null?void 0:S.value)||"#000000";this._colorPickerWrapper&&(this._colorPickerWrapper.style.backgroundColor=x),this._colorTextInput&&(this._colorTextInput.value=x),this.setAttribute("value",x),this.dispatchEvent(new CustomEvent("input",{detail:{value:x},bubbles:!0,cancelable:!0}))}),this._colorPicker.addEventListener("change",()=>{var S;const x=((S=this._colorPicker)==null?void 0:S.value)||"#000000";this._colorPickerWrapper&&(this._colorPickerWrapper.style.backgroundColor=x),this.setAttribute("value",x),this.dispatchEvent(new CustomEvent("change",{detail:{value:x},bubbles:!0,cancelable:!0}))})),this._colorTextInput||(this._colorTextInput=document.createElement("input"),this._colorTextInput.type="text",this._colorTextInput.className=this.getInputClasses(),this._colorTextInput.placeholder=n||"#000000",this._colorTextInput.pattern="^#[0-9A-Fa-f]{6}$",this._wrapper.appendChild(this._colorTextInput),this._colorTextInput.addEventListener("input",()=>{var S;const x=((S=this._colorTextInput)==null?void 0:S.value)||"";/^#[0-9A-Fa-f]{6}$/.test(x)&&(this._colorPicker&&(this._colorPicker.value=x),this.setAttribute("value",x),this.dispatchEvent(new CustomEvent("input",{detail:{value:x},bubbles:!0,cancelable:!0})))}),this._colorTextInput.addEventListener("blur",()=>{var S,w;const x=((S=this._colorTextInput)==null?void 0:S.value)||"";/^#[0-9A-Fa-f]{6}$/.test(x)?(this._colorPicker&&(this._colorPicker.value=x),this.setAttribute("value",x)):this._colorPicker&&this._colorTextInput&&(this._colorTextInput.value=this._colorPicker.value),this.dispatchEvent(new CustomEvent("change",{detail:{value:((w=this._colorPicker)==null?void 0:w.value)||"#000000"},bubbles:!0,cancelable:!0}))}));const E=h||"#000000";if(this._colorPicker&&this._colorPicker.value!==E&&(this._colorPicker.value=E),this._colorPickerWrapper&&(this._colorPickerWrapper.style.backgroundColor=E),this._colorTextInput&&this._colorTextInput.value!==E&&(this._colorTextInput.value=E),this._colorPicker&&(this._colorPicker.disabled=r),this._colorPickerWrapper&&(r?(this._colorPickerWrapper.classList.add("opacity-40","cursor-not-allowed"),this._colorPickerWrapper.classList.remove("cursor-pointer")):(this._colorPickerWrapper.classList.remove("opacity-40","cursor-not-allowed"),this._colorPickerWrapper.classList.add("cursor-pointer"))),this._colorTextInput&&(this._colorTextInput.disabled=r,this._colorTextInput.readOnly=a,this._colorTextInput.required=l),this._colorTextInput){const x=this._colorTextInput;o?x.id=o:x.removeAttribute("id"),c?x.name=c:x.removeAttribute("name"),x.setAttribute("aria-invalid",this.hasError()?"true":"false"),this._element=x}this._renderErrorState();return}if(this._wrapper||(this._wrapper=document.createElement("div"),this._wrapper.className="relative w-full",this.appendChild(this._wrapper)),this._colorContainer&&(this._colorContainer.remove(),this._colorContainer=null,this._colorPicker=null,this._colorTextInput=null),this._colorPickerWrapper&&!s&&(this._colorPickerWrapper.remove(),this._colorPickerWrapper=null,this._colorPicker=null,this._colorTextInput=null),d&&!e?this._icon?this._icon.setAttribute("name",d):(this._icon=document.createElement("mint-icon"),this._icon.setAttribute("name",d),this._icon.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",this._wrapper.appendChild(this._icon)):this._icon&&(this._icon.remove(),this._icon=null),this._isNumber()&&!e){if(!this._numberSpinnerContainer){this._numberSpinnerContainer=document.createElement("div"),this._numberSpinnerContainer.className="absolute right-1 top-1/2 -translate-y-1/2 flex flex-col h-8 pointer-events-none",this._wrapper.appendChild(this._numberSpinnerContainer),this._numberIncrementButton=document.createElement("button"),this._numberIncrementButton.type="button",this._numberIncrementButton.className="flex items-center justify-center w-5 h-4 text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors pointer-events-auto bg-gray-100 dark:bg-gray-600 active:bg-gray-200 dark:active:bg-gray-500 rounded";const E=document.createElement("mint-icon");E.setAttribute("name","caret-up"),E.className="w-[1rem] h-[1rem]",this._numberIncrementButton.appendChild(E),this._numberSpinnerContainer.appendChild(this._numberIncrementButton),this._numberDecrementButton=document.createElement("button"),this._numberDecrementButton.type="button",this._numberDecrementButton.className="flex items-center justify-center w-5 h-4 text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed transition-colors pointer-events-auto bg-gray-100 dark:bg-gray-600 active:bg-gray-200 dark:active:bg-gray-500 rounded";const x=document.createElement("mint-icon");x.setAttribute("name","caret-down"),x.className="w-[1rem] h-[1rem]",this._numberDecrementButton.appendChild(x),this._numberSpinnerContainer.appendChild(this._numberDecrementButton),this._numberIncrementButton.addEventListener("click",S=>{if(S.preventDefault(),S.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){const w=parseFloat(this._input.value)||0,$=parseFloat(this._input.step)||1,D=this._input.min?parseFloat(this._input.min):void 0,T=this._input.max?parseFloat(this._input.max):void 0;let A=w+$;T!==void 0&&A>T&&(A=T),D!==void 0&&A<D&&(A=D),this._input.value=A.toString(),this.setAttribute("value",A.toString()),this._input.dispatchEvent(new Event("input",{bubbles:!0})),this._input.dispatchEvent(new Event("change",{bubbles:!0}))}}),this._numberDecrementButton.addEventListener("click",S=>{if(S.preventDefault(),S.stopPropagation(),this._input&&!this._input.disabled&&!this._input.readOnly){const w=parseFloat(this._input.value)||0,$=parseFloat(this._input.step)||1,D=this._input.min?parseFloat(this._input.min):void 0,T=this._input.max?parseFloat(this._input.max):void 0;let A=w-$;D!==void 0&&A<D&&(A=D),T!==void 0&&A>T&&(A=T),this._input.value=A.toString(),this.setAttribute("value",A.toString()),this._input.dispatchEvent(new Event("input",{bubbles:!0})),this._input.dispatchEvent(new Event("change",{bubbles:!0}))}})}this._numberIncrementButton&&(this._numberIncrementButton.disabled=r||a),this._numberDecrementButton&&(this._numberDecrementButton.disabled=r||a)}else this._numberSpinnerContainer&&(this._numberSpinnerContainer.remove(),this._numberSpinnerContainer=null,this._numberIncrementButton=null,this._numberDecrementButton=null);if(e){if(this._input&&(this._input.remove(),this._input=null),this._textarea||(this._textarea=document.createElement("textarea"),this._wrapper.appendChild(this._textarea),this.setupEventListeners()),this._element=this._textarea,this._textarea.placeholder=n,this._textarea.disabled=r,this._textarea.readOnly=a,this._textarea.required=l,this._textarea.rows=f,this._textarea.setAttribute("aria-invalid",this.hasError()?"true":"false"),h!==this._textarea.value&&(this._textarea.value=h),o?this._textarea.id=o:this._textarea.removeAttribute("id"),c?this._textarea.name=c:this._textarea.removeAttribute("name"),this._textarea.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){const E=this.firstChild.textContent;E&&!this._textarea.value&&(this._textarea.value=E.trim()),this.removeChild(this.firstChild)}}else if(this._textarea&&(this._textarea.remove(),this._textarea=null),this._input||(this._input=document.createElement("input"),this._wrapper.appendChild(this._input),this.setupEventListeners()),this._element=this._input,this._input.type=t,this._input.placeholder=n,this._input.disabled=r,this._input.readOnly=a,this._input.required=l,this._input.setAttribute("aria-invalid",this.hasError()?"true":"false"),i?(this._input.inputMode="decimal",this._input.pattern="[0-9]*\\.?[0-9]*"):(this._input.removeAttribute("inputmode"),this._input.removeAttribute("pattern")),h!==this._input.value&&(this._input.value=h),o?this._input.id=o:this._input.removeAttribute("id"),c?this._input.name=c:this._input.removeAttribute("name"),this._input.className=this.getInputClasses(),this.firstChild&&this.firstChild!==this._wrapper&&this.firstChild.nodeType===Node.TEXT_NODE){const E=this.firstChild.textContent;E&&!this._input.value&&(this._input.value=E.trim()),this.removeChild(this.firstChild)}let m=this.querySelector(".mint-input-label-container");if(p||u){m||(m=document.createElement("div"),m.className="mint-input-label-container flex flex-col gap-0.5 mb-[.25rem]",this._wrapper&&this._wrapper.parentElement===this?this.insertBefore(m,this._wrapper):this.insertBefore(m,this.firstChild));let E=m.querySelector(".mint-input-label");if(p){E||(E=document.createElement("label"),E.className="mint-input-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",m.insertBefore(E,m.firstChild)),E.textContent=p;const S=o||((v=this._element)==null?void 0:v.id)||((b=this._colorTextInput)==null?void 0:b.id)||((y=this._input)==null?void 0:y.id)||((C=this._textarea)==null?void 0:C.id);if(S)E.setAttribute("for",S);else{const w=`mint-input-${Math.random().toString(36).substr(2,9)}`;this._element?this._element.id=w:this._colorTextInput?this._colorTextInput.id=w:this._input?this._input.id=w:this._textarea&&(this._textarea.id=w),E.setAttribute("for",w)}r?E.classList.add("opacity-40"):E.classList.remove("opacity-40")}else E&&E.remove();let x=m.querySelector(".mint-input-info");u?(x||(x=document.createElement("span"),x.className="mint-input-info text-xs text-gray-500 dark:text-gray-400 select-none",m.appendChild(x)),x.textContent=u,r?x.classList.add("opacity-40"):x.classList.remove("opacity-40")):x&&x.remove()}else m&&m.remove();this._renderErrorState(),this._renderSkeleton(_)}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-input-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-input-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}setupEventListeners(){this._element&&(this._element.addEventListener("input",()=>{var i;const t=((i=this._element)==null?void 0:i.value)||"";t?this.setAttribute("value",t):this.removeAttribute("value");const e=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e),this.dispatchEvent(new CustomEvent("input",{detail:{value:t},bubbles:!0,cancelable:!0,composed:!0}))}),this._element.addEventListener("blur",()=>{var e;const t=((e=this._element)==null?void 0:e.value)||"";t?this.setAttribute("value",t):this.removeAttribute("value"),this.dispatchEvent(new CustomEvent("change",{detail:{value:t},bubbles:!0,cancelable:!0}))}))}removeEventListeners(){this._colorPicker&&(this._focusHandler&&(this._colorPicker.removeEventListener("focus",this._focusHandler),this._focusHandler=null),this._blurHandler&&(this._colorPicker.removeEventListener("blur",this._blurHandler),this._blurHandler=null))}focus(){var t;this._isColor()&&this._colorTextInput?this._colorTextInput.focus():(t=this._element)==null||t.focus()}blur(){var t;this._isColor()&&this._colorTextInput?this._colorTextInput.blur():(t=this._element)==null||t.blur()}_renderSkeleton(t){let e=this.querySelector(".mint-input-skeleton-container");const i=this._wrapper||this.querySelector(".relative.w-full");if(t){e||(e=document.createElement("div"),e.className="mint-input-skeleton-container absolute inset-0 z-10 pointer-events-none",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-input-skeleton");if(!s){s=document.createElement("div"),s.className="mint-input-skeleton w-full rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse";const n=this._isTextarea(),r=this.getRows();if(n){const a=r*24+12;s.style.height=`${a}px`}else s.style.height="2.2rem";e.appendChild(s)}e.style.display="block",this._element&&(this._element.style.opacity="0",this._element.style.pointerEvents="none"),this._colorTextInput&&(this._colorTextInput.style.opacity="0",this._colorTextInput.style.pointerEvents="none")}else e&&(e.style.display="none"),this._element&&(this._element.style.opacity="1",this._element.style.pointerEvents="auto"),this._colorTextInput&&(this._colorTextInput.style.opacity="1",this._colorTextInput.style.pointerEvents="auto")}}customElements.get("mint-input")||customElements.define("mint-input",mt);class bt extends HTMLElement{constructor(){super(),this._input=null,this._textInput=null,this._popover=null,this._calendarContainer=null,this._iconButton=null,this._hiddenInput=null,this._startPartInputs=[],this._endPartInputs=[],this._displayEl=null,this._inputsWrapperEl=null,this._fieldsContainer=null,this._resetHandler=null,this._isInputMode=!1,this._currentMonth=new Date().getMonth(),this._currentYear=new Date().getFullYear(),this._viewMode="calendar",this._selectedStartDate=null,this._selectedEndDate=null,this._isRange=!1,this._hoveredDate=null,this._isHandlingClick=!1,this._resizeObserver=null,this._popoverObserver=null,this._focusTrapHandler=null,this._escapeHandler=null}static get observedAttributes(){return["value","label","info","disabled","id","name","required","readonly","format","min","max","range","shortcuts","display-format","error","error-message","loading","selection-mode","week-start-day","mode","disabled-dates"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","inline-block"),this.render(),this._setupPopoverWithRetry(),this._attachFormResetListener()}disconnectedCallback(){if(this._popoverObserver&&(this._popoverObserver.disconnect(),this._popoverObserver=null),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._removeFocusTrap(),this._resetHandler){const t=this.closest("form");t&&t.removeEventListener("reset",this._resetHandler),this._resetHandler=null}}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){const s=this.hasError(),n=this.getErrorMessage();this._applyErrorVisuals(s,n,this.isDisabled());return}if(t==="loading"){this.render();return}if(t==="mode"||t==="format"){const s=this.getMode();s==="month"?this._viewMode="month":s==="year"?this._viewMode="year":this._viewMode="calendar",this._popover&&this._calendarContainer&&this._buildCalendar()}this.render(),this._input&&this._setupPopoverWithRetry()}}getValue(){return this.getAttribute("value")||""}setValue(t){t?(this.setAttribute("value",t),this._textInput&&(this._textInput.value=t),this._parseValue(t)):(this.removeAttribute("value"),this._textInput&&(this._textInput.value=""),this._selectedStartDate=null,this._selectedEndDate=null),this._buildCalendar(),this._updateDisplayText()}get value(){try{return this.getValue()||""}catch{return""}}set value(t){try{this.setValue(t||"")}catch{}}getFormat(){return this.getAttribute("format")||"mm/dd/yyyy"}getLabel(){return this.getAttribute("label")||""}getInfo(){return this.getAttribute("info")||""}isDisabled(){return this.getAttribute("disabled")==="true"}isReadonly(){return this.getAttribute("readonly")==="true"}isRequired(){return this.getAttribute("required")==="true"}hasError(){return this.getAttribute("error")==="true"}getErrorMessage(){return this.getAttribute("error-message")||""}isRange(){return this.getAttribute("range")==="true"}getId(){return this.getAttribute("id")||""}getName(){return this.getAttribute("name")||""}getMin(){return this.getAttribute("min")||""}getMax(){return this.getAttribute("max")||""}getDisabledDates(){const t=this.getAttribute("disabled-dates");if(!t)return[];try{const e=JSON.parse(t),i=this.getFormat();return e.map(s=>this._parseDateString(s,i)).filter(s=>s!==null)}catch{return[]}}getDisabledDateStrings(){const t=this.getAttribute("disabled-dates");if(!t)return[];try{return JSON.parse(t)}catch{return[]}}disableDate(t){const e=this.getFormat(),i=this.getDisabledDateStrings(),s=Array.isArray(t)?t:[t],n=[];for(const r of s){const a=this._parseDateString(r,e);if(a){const l=this._formatDate(a,e);i.includes(l)||n.push(l)}}if(n.length>0){const r=[...i,...n];this.setAttribute("disabled-dates",JSON.stringify(r)),this._buildCalendar()}}enableDate(t){const e=this.getFormat(),i=this.getDisabledDateStrings(),s=Array.isArray(t)?t:[t],n=[];for(const r of s){const a=this._parseDateString(r,e);if(a){const l=this._formatDate(a,e);n.push(l)}}if(n.length>0){const r=i.filter(a=>!n.includes(a));r.length===0?this.removeAttribute("disabled-dates"):this.setAttribute("disabled-dates",JSON.stringify(r)),this._buildCalendar()}}getSelectionMode(){const t=this.getAttribute("selection-mode");return t==="week"||t==="month"?t:"day"}getMode(){const t=this.getAttribute("mode");if(t==="month"||t==="year")return t;const e=this.getFormat().toLowerCase(),i=e.includes("d"),s=e.includes("m");return!i&&!s?"year":!i&&s?"month":"default"}getWeekStartDay(){var i;const t=(i=this.getAttribute("week-start-day"))==null?void 0:i.toLowerCase();return{sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6}[t||"sunday"]??0}getDisplayFormat(){return this.getAttribute("display-format")||"F j, Y"}getShortcuts(){const t=this.getAttribute("shortcuts");if(!t)return[];try{const e=JSON.parse(t);if(Array.isArray(e))return e.map(i=>({label:i.label,action:this._createShortcutAction(i.action)}))}catch{const i=t.trim();if(i&&typeof window[i]=="function"){const s=window[i]();if(Array.isArray(s))return s.map(n=>({label:n.label,action:typeof n.action=="function"?n.action:this._createShortcutAction(n.action)}))}}return[]}_createShortcutAction(t){return typeof t=="function"?t:typeof t=="string"&&typeof window[t]=="function"?window[t]:()=>null}_getDefaultShortcuts(){const t=[{label:"Today",action:()=>new Date}];return this._isRange&&t.push({label:"This Week",action:()=>{const e=new Date,i=e.getDay(),s=new Date(e);s.setDate(e.getDate()-i),s.setHours(0,0,0,0);const n=new Date(s);return n.setDate(s.getDate()+6),n.setHours(23,59,59,999),{start:s,end:n}}},{label:"This Month",action:()=>{const e=new Date,i=new Date(e.getFullYear(),e.getMonth(),1),s=new Date(e.getFullYear(),e.getMonth()+1,0);return s.setHours(23,59,59,999),{start:i,end:s}}}),t}_getFormatTokens(t){const e=[];let i=0;const s=t.toLowerCase();for(;i<s.length;){const n=s[i];if(n==="d"||n==="m"||n==="y"){let r=1,a=i+1;for(;a<s.length&&s[a]===n;)r++,a++;e.push({type:"part",part:n,len:r}),i=a}else e.push({type:"sep",value:t[i]}),i++}return e}_createPartInput(t,e,i,s,n){const r=document.createElement("input");return r.type="text",r.inputMode="numeric",r.pattern="\\d*",r.maxLength=t,r.placeholder=e,r.className="bg-transparent border-none outline-none text-center text-sm font-medium p-0 m-0 focus:outline-none focus:ring-0 disabled:opacity-40 disabled:cursor-not-allowed",r.disabled=i||s,r.readOnly=s,r.required=n,t===4?r.className+=" w-[40px]":t===2&&(r.className+=" w-[30px]"),r}_buildValueFromParts(t,e){let i=0;return e.map(s=>{var r;if(s.type==="sep")return s.value;const n=((r=t[i])==null?void 0:r.value)||"";return i++,n}).join("")}_applyDateToParts(t,e,i,s){if(!e.length)return;if(!t){e.forEach(l=>l.value="");return}const n=this._formatDate(t,s);let r=0,a=0;i.forEach(l=>{if(l.type==="sep")r+=l.value.length;else{const o=n.substr(r,l.len);e[a]&&(e[a].value=o),a++,r+=l.len}})}_syncHiddenInput(){if(!this._hiddenInput)return;const t=this.getFormat(),e=this._getFormatTokens(t),i=this._buildValueFromParts(this._startPartInputs,e);if(this._isRange){const s=this._buildValueFromParts(this._endPartInputs,e);this._hiddenInput.value=s?`${i} - ${s}`:i}else this._hiddenInput.value=i}_focusNext(t,e){if(e+1<t.length){const i=t[e+1];i.focus(),i.setSelectionRange(0,i.value.length)}}_focusPrev(t,e){if(e-1>=0){const i=t[e-1];i.focus(),i.setSelectionRange(i.value.length,i.value.length)}}_attachPartInputHandlers(t,e,i){t.forEach((s,n)=>{const r=s.maxLength||2;s.addEventListener("input",()=>{s.value=s.value.replace(/\D/g,"").slice(0,r),s.value.length>=r&&this._focusNext(t,n),this._syncHiddenInput()}),s.addEventListener("keydown",a=>{a.key==="Backspace"&&s.selectionStart===0&&s.selectionEnd===0&&this._focusPrev(t,n),a.key==="ArrowLeft"&&s.selectionStart===0&&s.selectionEnd===0&&(this._focusPrev(t,n),a.preventDefault()),a.key==="ArrowRight"&&s.selectionStart===s.value.length&&s.selectionEnd===s.value.length&&(this._focusNext(t,n),a.preventDefault())}),s.addEventListener("blur",a=>{this._syncHiddenInput();const l=a.relatedTarget,o=l&&(this._startPartInputs.includes(l)||this._endPartInputs.includes(l));setTimeout(()=>{var h;if(!(this._startPartInputs.some(f=>f===document.activeElement)||this._endPartInputs.some(f=>f===document.activeElement))&&(o||this._handleBlur(((h=this._hiddenInput)==null?void 0:h.value)||""),this._exitInputMode(),!o&&this._hiddenInput)){const f=new FocusEvent("blur",{bubbles:!0,cancelable:!0,relatedTarget:a.relatedTarget});this._hiddenInput.dispatchEvent(f)}},0)})})}_splitRangeInput(t,e){const i=t.split(/\s*-\s*/);return i.length>=2?[i[0],i.slice(1).join("-")]:[t]}_parseValue(t){const e=this.getFormat(),i=this._getFormatTokens(e),s=this.getSelectionMode();if(this._isRange||s==="week"||s==="month"){const[r,a]=this._splitRangeInput(t,e),l=r?this._parseDateString(r,e):null,o=a?this._parseDateString(a,e):null;if(l&&o){const[c,h]=l<=o?[l,o]:[o,l];this._selectedStartDate=c,this._selectedEndDate=h,this._currentMonth=c.getMonth(),this._currentYear=c.getFullYear()}else l&&(this._selectedStartDate=l,this._selectedEndDate=null,this._currentMonth=l.getMonth(),this._currentYear=l.getFullYear());this._applyDateToParts(this._selectedStartDate,this._startPartInputs,i,e),this._applyDateToParts(this._selectedEndDate,this._endPartInputs,i,e)}else{const r=this._parseDateString(t,e);r&&!isNaN(r.getTime())?(this._selectedStartDate=r,this._selectedEndDate=null,this._currentMonth=r.getMonth(),this._currentYear=r.getFullYear(),this._applyDateToParts(r,this._startPartInputs,i,e)):this._applyDateToParts(null,this._startPartInputs,i,e)}this._syncHiddenInput(),this._updateDisplayText()}_parseDateString(t,e){const i=/[\/\-\.\s]+/;if(i.test(t)){const v=t.split(i).filter(y=>y.length>0),b=e.split(/[\/\-\.\s]+/).filter(y=>y.length>0);if(v.length===b.length){let y=0,C=0,E=0;for(let w=0;w<b.length;w++){const $=b[w].toLowerCase(),D=v[w];if($.includes("d"))y=parseInt(D,10);else if($.includes("m"))C=parseInt(D,10)-1;else if($.includes("y")){let T=parseInt(D,10);const A=$.length,H=D.length;H===2&&A===4?T=Math.floor(new Date().getFullYear()/100)*100+T:H===2&&A===2&&(T=Math.floor(new Date().getFullYear()/100)*100+T),E=T}}const x=b.some(w=>w.toLowerCase().includes("d")),S=b.some(w=>w.toLowerCase().includes("m"));if(x||(y=1),S||(C=0),C>=0&&C<=11&&E){const w=new Date(E,C,y);if(!isNaN(w.getTime()))return x&&w.getDate()!==y||w.getMonth()!==C||w.getFullYear()!==E?null:w}}}const n=t.replace(/[\/\-\.]/g,""),r=e.replace(/[\/\-\.]/g,"").toLowerCase();let a=r.indexOf("d"),l=r.indexOf("m"),o=r.indexOf("y");const c=[{char:"d",index:a},{char:"m",index:l},{char:"y",index:o}].sort((v,b)=>v.index-b.index);let h=0,f=0,d=0,p=0;r.length,n.length;for(const v of c)if(v.char==="d"){const b=r.lastIndexOf("d")-r.indexOf("d")+1,y=n.substr(p,b);if(y.length===0)return null;h=parseInt(y,10),p+=y.length}else if(v.char==="m"){const b=r.lastIndexOf("m")-r.indexOf("m")+1,y=n.substr(p,b);if(y.length===0)return null;f=parseInt(y,10)-1,p+=y.length}else if(v.char==="y"){const b=r.lastIndexOf("y")-r.indexOf("y")+1,y=n.substr(p),C=Math.min(b,y.length),E=y.substr(0,C);if(E.length===0)return null;let x=parseInt(E,10);C===2&&b===4?x=Math.floor(new Date().getFullYear()/100)*100+x:C===2&&b===2&&(x=Math.floor(new Date().getFullYear()/100)*100+x),d=x,p+=C}const u=e.toLowerCase(),_=u.includes("d"),g=u.includes("m");if(_||(h=1),g||(f=0),f<0||f>11||!d)return null;const m=new Date(d,f,h);return isNaN(m.getTime())||_&&m.getDate()!==h||m.getMonth()!==f||m.getFullYear()!==d?null:m}_formatDate(t,e){const i=t.getDate(),s=t.getMonth()+1,n=t.getFullYear(),r=e.toLowerCase();let a=e;return r.includes("dd")?a=a.replace(/dd/gi,String(i).padStart(2,"0")):r.includes("d")&&(a=a.replace(/d/gi,String(i))),r.includes("mm")?a=a.replace(/mm/gi,String(s).padStart(2,"0")):r.includes("m")&&(a=a.replace(/m/gi,String(s))),r.includes("yyyy")?a=a.replace(/yyyy/gi,String(n)):r.includes("yy")&&(a=a.replace(/yy/gi,String(n).substr(2))),a}_formatDatePhp(t,e){const i=t.getDate(),s=t.getMonth()+1,n=t.getFullYear(),r=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],l=["January","February","March","April","May","June","July","August","September","October","November","December"],o=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=(d,p=2)=>d.toString().padStart(p,"0"),h=d=>{const p=d%10,u=d%100;return p===1&&u!==11?"st":p===2&&u!==12?"nd":p===3&&u!==13?"rd":"th"};let f="";for(let d=0;d<e.length;d++){const p=e[d];if(p==="\\"&&d+1<e.length){f+=e[d+1],d++;continue}switch(p){case"Y":f+=n.toString();break;case"y":f+=n.toString().slice(-2);break;case"m":f+=c(s);break;case"n":f+=s.toString();break;case"M":f+=o[s-1];break;case"F":f+=l[s-1];break;case"d":f+=c(i);break;case"j":f+=i.toString();break;case"D":f+=a[t.getDay()];break;case"l":f+=r[t.getDay()];break;case"S":f+=h(i);break;default:f+=p;break}}return f}_validateDateString(t,e){const i=this._parseDateString(t,e);return i!==null&&!isNaN(i.getTime())}render(){const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.getValue(),n=this.isDisabled(),r=this.isReadonly(),a=this.isRequired(),l=this.getId(),o=this.getName(),c=this.getFormat(),h=this.hasError(),f=this.getErrorMessage(),d=this.getSelectionMode();this._isRange=this.isRange()||d==="week"||d==="month",this._input||(this._input=document.createElement("div"),this._input.className="relative w-full",this.appendChild(this._input));let p=this.querySelector(".mint-date-picker-label-container");if(e||i){p||(p=document.createElement("div"),p.className="mint-date-picker-label-container flex flex-col gap-0.5 mb-[.25rem]",this.contains(this._input)?this.insertBefore(p,this._input):this.appendChild(p));let b=p.querySelector(".mint-date-picker-label");e?(b||(b=document.createElement("label"),b.className="mint-date-picker-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",p.insertBefore(b,p.firstChild)),b.textContent=e,l&&this._textInput&&b.setAttribute("for",l)):b&&b.remove();let y=p.querySelector(".mint-date-picker-info");i?(y||(y=document.createElement("span"),y.className="mint-date-picker-info text-xs text-gray-500 dark:text-gray-400 select-none",p.appendChild(y)),y.textContent=i):y&&y.remove()}else p&&p.remove();this._hiddenInput||(this._hiddenInput=document.createElement("input"),this._hiddenInput.type="hidden",this._hiddenInput.value=s||"",this._textInput=this._hiddenInput,this._input.appendChild(this._hiddenInput)),l&&(this._hiddenInput.id=l),o&&(this._hiddenInput.name=o),this._hiddenInput.value=s||"",this._hiddenInput.setAttribute("aria-invalid",h?"true":"false");let u=this._input.querySelector(".mint-date-fields");u||(u=document.createElement("div"),this._input.appendChild(u)),this._fieldsContainer=u,this._applyErrorVisuals(h,f,n),u.innerHTML="",this._displayEl=document.createElement("div");const _=r?"select-text":"select-none";this._displayEl.className=`flex-1 text-gray-900 dark:text-white ${r?"cursor-default":"cursor-text"} ${_} focus:outline-none`,this._displayEl.tabIndex=n||r?-1:0,this._displayEl.addEventListener("click",()=>{n||r||this._enterInputMode()}),this._displayEl.addEventListener("keydown",b=>{n||r||(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),this._enterInputMode())}),this._inputsWrapperEl=document.createElement("div"),this._isRange?this._inputsWrapperEl.className="flex items-center gap-1 w-full":this._inputsWrapperEl.className="flex items-center gap-1 w-full";const g=this._getFormatTokens(c);this._startPartInputs=[],this._endPartInputs=[];const m=b=>{const y=document.createDocumentFragment();return g.forEach(C=>{if(C.type==="sep"){const E=document.createElement("span");E.textContent=C.value,E.className="text-gray-400 dark:text-gray-500 select-none",y.appendChild(E)}else{const E=C.part==="d"?"dd":C.part==="m"?"mm":C.len===2?"yy":"yyyy",x=this._createPartInput(C.len,E,n,r,a);b==="start"?this._startPartInputs.push(x):this._endPartInputs.push(x),y.appendChild(x)}}),y};if(this._isRange){const b=document.createElement("div");b.className="flex items-center gap-1 flex-shrink-0",b.appendChild(m("start")),this._inputsWrapperEl.appendChild(b);const y=document.createElement("span");y.textContent=" - ",y.className="text-gray-400 dark:text-gray-500 select-none flex-shrink-0",this._inputsWrapperEl.appendChild(y);const C=document.createElement("div");C.className="flex items-center gap-1 flex-shrink-0",C.appendChild(m("end")),this._inputsWrapperEl.appendChild(C)}else this._inputsWrapperEl.appendChild(m("start"));const v=document.createElement("div");if(v.className="flex flex-col w-full",this._displayEl.style.display=this._isInputMode?"none":"flex",this._inputsWrapperEl.style.display=this._isInputMode?"flex":"none",v.appendChild(this._displayEl),v.appendChild(this._inputsWrapperEl),u.appendChild(v),this._isRange&&this._inputsWrapperEl&&this._setupContainerObserver(),u.addEventListener("click",()=>{this._isInputMode||n||r||this._enterInputMode()}),this._attachPartInputHandlers(this._startPartInputs,g,u),this._isRange&&this._attachPartInputHandlers(this._endPartInputs,g,u),this._parseValue(s),this._syncHiddenInput(),this._updateDisplayText(),this._iconButton)this._iconButton.disabled=n||r,!n&&!r?this._iconButton.tabIndex=0:this._iconButton.tabIndex=-1;else{this._iconButton=document.createElement("button"),this._iconButton.type="button",this._iconButton.tabIndex=0,this._iconButton.className="absolute left-2 top-[.55rem] text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer z-10 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 pointer-events-auto disabled:opacity-40 disabled:cursor-not-allowed flex items-center justify-center rounded-sm";const b=`date-icon-${Math.random().toString(36).substr(2,9)}`;this._iconButton.id=b;const y=document.createElement("mint-icon");y.setAttribute("name","calendar"),y.className="w-4 h-4 pointer-events-none",this._iconButton.appendChild(y),this._iconButton.addEventListener("click",()=>{n||r||this._enterInputMode()}),this._input.prepend(this._iconButton),this._iconButton.disabled=n||r}this._renderErrorState(h,f),this._renderSkeleton(t)}_renderErrorState(t,e){let i=this.querySelector(".mint-date-picker-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-date-picker-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}_applyErrorVisuals(t,e,i){if(this._renderErrorState(t,e),this._fieldsContainer){const s=this._getFieldContainerClass(t,i);this._fieldsContainer.className=s}this._hiddenInput&&this._hiddenInput.setAttribute("aria-invalid",t?"true":"false")}_attachFormResetListener(){const t=this.closest("form");!t||this._resetHandler||(this._resetHandler=()=>{this.setValue(""),this._clearPartInputs(this._startPartInputs),this._clearPartInputs(this._endPartInputs),this._isInputMode=!1,this._updateDisplayText(),this._applyErrorVisuals(!1,"",this.isDisabled())},t.addEventListener("reset",this._resetHandler))}_clearPartInputs(t){t.forEach(e=>{e.value=""})}_getFieldContainerClass(t,e){return["mint-date-fields relative w-full pl-10 pr-3.5 py-1.5 min-h-[2rem] text-sm font-medium rounded-lg box-border bg-white dark:bg-gray-900 dark:border dark:border-gray-700 text-gray-900 dark:text-white","border-2",t?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","transition-all duration-200 outline-none focus-within:ring-2 focus-within:ring-offset-1",t?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","flex items-center gap-1"].join(" ")+(e?" opacity-40 cursor-not-allowed":"")}_handleInputChange(t){}_cleanInputValue(t,e){return t}_handleBlur(t){const e=this.getFormat(),i=this.getSelectionMode(),s=this._isRange||i==="week"||i==="month";if(!t){this.setValue(""),this._updateDisplayText();return}if(s){const[n,r]=this._splitRangeInput(t,e),a=n?this._parseDateString(n,e):null,l=r?this._parseDateString(r,e):null;if(a&&l){const[o,c]=a<=l?[a,l]:[l,a],h=this._formatDate(o,e),f=this._formatDate(c,e),d=`${h} - ${f}`;this.setValue(d),this._applyDateToParts(o,this._startPartInputs,this._getFormatTokens(e),e),this._applyDateToParts(c,this._endPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=o,this._selectedEndDate=c,this._currentMonth=o.getMonth(),this._currentYear=o.getFullYear()}else if(a){const o=this._formatDate(a,e);this.setValue(o),this._applyDateToParts(a,this._startPartInputs,this._getFormatTokens(e),e),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=a,this._selectedEndDate=null,this._currentMonth=a.getMonth(),this._currentYear=a.getFullYear()}else this.setValue(""),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(e),e),this._applyDateToParts(null,this._endPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=null,this._selectedEndDate=null}else if(this._validateDateString(t,e)){const n=this._parseDateString(t,e);if(n){const r=this._formatDate(n,e);this.setValue(r),this._applyDateToParts(n,this._startPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=n,this._selectedEndDate=null,this._currentMonth=n.getMonth(),this._currentYear=n.getFullYear()}}else this.setValue(""),this._applyDateToParts(null,this._startPartInputs,this._getFormatTokens(e),e),this._selectedStartDate=null,this._selectedEndDate=null}_setupPopoverWithRetry(t=0){if(!this._iconButton){t<10&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(t+1)});return}const e=10,i=this._iconButton.id;i&&this._iconButton.isConnected?document.getElementById(i)?this._createPopover(i):t<e&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(t+1)}):t<e&&requestAnimationFrame(()=>{this._setupPopoverWithRetry(t+1)})}_createPopover(t){if(!t)return;if(!document.getElementById(t)){setTimeout(()=>{this._createPopover(t)},50);return}if(this._popover){if(this._popover.getAttribute("trigger-id")!==t){this._popover.setAttribute("trigger-id",t);const s=this._popover;typeof s._setupTrigger=="function"&&s._setupTrigger()}this._buildCalendar()}else{this._popover=document.createElement("mint-popover"),this._popover.setAttribute("direction","down"),this._popover.setAttribute("padding","0");const i=this.closest("mint-modal"),s=this.closest("mint-off-canvas");i||s?document.body.appendChild(this._popover):this.parentNode?this.parentNode.insertBefore(this._popover,this.nextSibling):document.body.appendChild(this._popover),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._popover&&this._popover.isConnected&&(this._popover.setAttribute("trigger-id",t),this._popoverObserver||(this._popoverObserver=new MutationObserver(n=>{n.forEach(r=>{var a;if(r.type==="attributes"&&r.attributeName==="open")if((a=this._popover)==null?void 0:a.hasAttribute("open"))requestAnimationFrame(()=>{this._buildCalendar();const o=this._popover;typeof o.render=="function"&&o.render(),this._setupFocusTrap()});else{if(this._removeFocusTrap(),this._iconButton&&!this._iconButton.disabled&&requestAnimationFrame(()=>{var o;(o=this._iconButton)==null||o.focus()}),this._viewMode="calendar",this._selectedStartDate)this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();else{const o=new Date;this._currentMonth=o.getMonth(),this._currentYear=o.getFullYear()}requestAnimationFrame(()=>{this._buildCalendar()}),this._hiddenInput&&(this._syncHiddenInput(),setTimeout(()=>{var c;const o=new FocusEvent("blur",{bubbles:!0,cancelable:!0,relatedTarget:null});(c=this._hiddenInput)==null||c.dispatchEvent(o)},0))}})}),this._popoverObserver.observe(this._popover,{attributes:!0,attributeFilter:["open"]})),requestAnimationFrame(()=>{this._buildCalendar()}))})})}}_buildCalendar(){if(!this._popover)return;this._calendarContainer&&this._calendarContainer.parentNode&&this._calendarContainer.remove(),this._calendarContainer=document.createElement("div"),this._calendarContainer.className="mint-date-calendar bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg p-4 w-[22rem] md:w-auto md:min-w-[28rem]";const t=this.getMode();t==="month"&&this._viewMode==="calendar"?this._viewMode="month":t==="year"&&this._viewMode==="calendar"?this._viewMode="year":t==="default"&&this._viewMode!=="month"&&this._viewMode!=="year"&&(this._viewMode="calendar"),this._viewMode==="calendar"?this._buildCalendarView():this._viewMode==="month"?this._buildMonthView():this._viewMode==="year"&&this._buildYearView();const e=this._popover.querySelector(".popover-content");if(e){for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(this._calendarContainer)}else this._popover.appendChild(this._calendarContainer)}_buildCalendarView(){if(!this._calendarContainer)return;const t=this._getDaysInMonth(this._currentMonth,this._currentYear),e=this._getFirstDayOfMonth(this._currentMonth,this._currentYear),i=["January","February","March","April","May","June","July","August","September","October","November","December"],s=this.getWeekStartDay(),n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=[...n.slice(s),...n.slice(0,s)],a=this.getShortcuts(),l=a.length>0;this._calendarContainer.className=l?"mint-date-calendar bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg p-4 w-[18rem] md:w-auto md:min-w-[28rem]":"mint-date-calendar bg-white dark:bg-gray-900 dark:border dark:border-gray-700 rounded-lg p-4 w-[18rem] md:min-w-[18rem]";const o=document.createElement("div");o.className="flex flex-col md:flex-row md:gap-6 md:items-start";const c=document.createElement("div");c.className="flex-1 min-w-0";const h=document.createElement("div");h.className="flex items-center justify-between mb-4";const f=document.createElement("button");f.type="button",f.tabIndex=0,f.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",f.setAttribute("data-keep-popover-open","true");const d=document.createElement("mint-icon");d.setAttribute("name","caret-left"),d.className="w-4 h-4",f.appendChild(d),f.addEventListener("click",()=>{const k=this._currentMonth,L=this._currentYear;this._currentMonth===0?(this._currentMonth=11,this._currentYear--):this._currentMonth--,this._buildCalendar(),this._dispatchMonthChangeEvent(k,L,this._currentMonth,this._currentYear)}),h.appendChild(f);const p=document.createElement("div");p.className="flex items-center gap-2";const u=document.createElement("button");u.type="button",u.tabIndex=0,u.className="text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",u.setAttribute("data-keep-popover-open","true"),u.textContent=i[this._currentMonth],u.addEventListener("click",()=>{const k=this.getMode();k!=="month"&&k!=="year"&&(this._viewMode="month",this._buildCalendar())}),p.appendChild(u);const _=document.createElement("button");_.type="button",_.tabIndex=0,_.className="text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",_.setAttribute("data-keep-popover-open","true"),_.textContent=String(this._currentYear),_.addEventListener("click",()=>{this.getMode()!=="year"&&(this._viewMode="year",this._buildCalendar())}),p.appendChild(_),h.appendChild(p);const g=document.createElement("button");g.type="button",g.tabIndex=0,g.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors flex items-center focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",g.setAttribute("data-keep-popover-open","true");const m=document.createElement("mint-icon");m.setAttribute("name","caret-right"),m.className="w-4 h-4",g.appendChild(m),g.addEventListener("click",()=>{const k=this._currentMonth,L=this._currentYear;this._currentMonth===11?(this._currentMonth=0,this._currentYear++):this._currentMonth++,this._buildCalendar(),this._dispatchMonthChangeEvent(k,L,this._currentMonth,this._currentYear)}),h.appendChild(g);const v=document.createElement("div");v.className="grid grid-cols-7 mb-2",r.forEach(k=>{const L=document.createElement("div");L.className="text-xs font-medium text-gray-500 dark:text-gray-400 text-center py-1",L.textContent=k,v.appendChild(L)});const b=document.createElement("div");b.className="grid grid-cols-7";const y=this.getMin()?this._parseDateString(this.getMin(),this.getFormat()):null,C=this.getMax()?this._parseDateString(this.getMax(),this.getFormat()):null;this.getDisabledDates();const E=this._currentMonth===0?11:this._currentMonth-1,x=this._currentMonth===0?this._currentYear-1:this._currentYear,S=this._getDaysInMonth(E,x),w=this._currentMonth===11?0:this._currentMonth+1,$=this._currentMonth===11?this._currentYear+1:this._currentYear,D=e+t,H=Math.ceil(D/7)*7-D,N=(k,L,I)=>{const F=this._isToday(k),V=this._isDateSelected(k),P=this._isDateInRange(k),R=y&&k<y||C&&k>C||this._isDateDisabled(k);let q="rounded-md";const z=this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate,X=z&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._selectedStartDate:z&&this._hoveredDate?this._hoveredDate:null,B=z&&this._selectedStartDate&&this._hoveredDate&&this._selectedStartDate<this._hoveredDate?this._hoveredDate:z&&this._selectedStartDate?this._selectedStartDate:null,O=X!==null&&this._isSameDate(k,X),W=B!==null&&this._isSameDate(k,B),j=this._hoveredDate!==null&&this._isSameDate(k,this._hoveredDate),U=z&&this._hoveredDate&&this._selectedStartDate?!this._rangeIncludesDisabledDates(this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate):!1;if(this._isRange&&this._selectedStartDate&&this._selectedEndDate){const G=this._isSameDate(k,this._selectedStartDate),it=this._isSameDate(k,this._selectedEndDate);G&&it?q="rounded-md":G?q="rounded-l-md":it?q="rounded-r-md":P&&(q="rounded-none")}else z&&(O||W)&&U?O&&W?q="rounded-md":O?q="rounded-l-md":W&&(q="rounded-r-md"):V&&!this._isRange||V&&this._isRange&&!this._selectedEndDate?q="rounded-md":P&&z&&U&&(q="rounded-none");const Y=document.createElement("button");Y.type="button",Y.disabled=!!R,Y.tabIndex=R?-1:0;let Q=`w-full h-8 ${q} border-0 text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500`;const et=V||z&&j&&U;return I?Q+=et?" bg-slate-800 dark:bg-slate-600 text-white":P?" bg-slate-100 dark:bg-slate-700 text-slate-800 dark:text-slate-200":F?" text-gray-900 dark:text-gray-100 font-semibold":" text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700":Q+=et?" bg-slate-800 dark:bg-slate-600 text-white":P?" bg-slate-100 dark:bg-slate-700 text-slate-800 dark:text-slate-200":" text-gray-400 dark:text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700",Q+=R?" opacity-40 cursor-not-allowed":"",Y.className=Q,Y.textContent=L.toString(),R||(Y.addEventListener("click",G=>{G.preventDefault(),G.stopPropagation(),this._handleDateClick(k)}),this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&!R&&Y.addEventListener("mouseenter",()=>{this._isHandlingClick||this._isDateDisabled(k)||(!this._hoveredDate||!this._isSameDate(this._hoveredDate,k))&&(this._hoveredDate=k,this._buildCalendar())})),Y};for(let k=e-1;k>=0;k--){const L=S-k,I=new Date(x,E,L),F=N(I,L,!1);b.appendChild(F)}for(let k=1;k<=t;k++){const L=new Date(this._currentYear,this._currentMonth,k),I=N(L,k,!0);b.appendChild(I)}for(let k=1;k<=H;k++){const L=new Date($,w,k),I=N(L,k,!1);b.appendChild(I)}if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&b.addEventListener("mouseleave",()=>{this._hoveredDate=null,this._buildCalendar()}),l){const k=document.createElement("div");k.className="mb-4 pb-4 border-b border-gray-200 dark:border-gray-700 md:mb-0 md:pb-0 md:border-b-0 md:border-r md:border-r-gray-200 dark:md:border-r-gray-700 md:pr-6 md:mr-0 md:w-32 md:flex-shrink-0 md:h-full md:flex md:flex-col";const L=document.createElement("div");L.className="relative md:relative md:flex-1 md:min-h-0";const I=document.createElement("div");I.className="flex gap-2 overflow-x-auto pb-1 md:flex-col md:overflow-x-visible md:overflow-y-auto md:pb-0 md:gap-2",I.style.scrollbarWidth="none",I.style.msOverflowStyle="none",I.style.setProperty("-webkit-overflow-scrolling","touch");const F=document.createElement("style");F.textContent=`
|
|
66
66
|
.mint-date-shortcuts-row::-webkit-scrollbar {
|
|
67
67
|
display: none;
|
|
68
68
|
}
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
background: rgba(255, 255, 255, 0.2);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
`,H.classList.add("mint-date-shortcuts-row"),document.head.querySelector("style[data-mint-date-shortcuts]")||(F.setAttribute("data-mint-date-shortcuts","true"),document.head.appendChild(F));const V=document.createElement("div");V.className="absolute left-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-r from-white dark:from-gray-800 to-transparent opacity-0 transition-opacity duration-200 md:hidden",L.appendChild(V);const P=document.createElement("div");P.className="absolute right-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-l from-white dark:from-gray-800 to-transparent opacity-100 transition-opacity duration-200 md:hidden",L.appendChild(P);const R=document.createElement("div");R.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-gray-800 to-transparent opacity-0 transition-opacity duration-200",L.appendChild(R);const q=document.createElement("div");q.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-gray-800 to-transparent opacity-100 transition-opacity duration-200",L.appendChild(q);const z=()=>{if(window.innerWidth>=768){const B=H.scrollTop,O=H.scrollHeight,W=H.clientHeight;B>0?R.style.opacity="1":R.style.opacity="0",B+W<O-1?q.style.opacity="1":q.style.opacity="0",V.style.opacity="0",P.style.opacity="0"}else{const B=H.scrollLeft,O=H.scrollWidth,W=H.clientWidth;B>0?V.style.opacity="1":V.style.opacity="0",B+W<O-1?P.style.opacity="1":P.style.opacity="0",R.style.opacity="0",q.style.opacity="0"}};H.addEventListener("scroll",z),window.addEventListener("resize",z),setTimeout(z,0),a.forEach(X=>{const B=document.createElement("button");B.type="button",B.tabIndex=0,B.className="px-3 py-1.5 text-xs font-medium rounded-md bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors 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",B.textContent=X.label,B.setAttribute("data-keep-popover-open","true"),B.addEventListener("click",()=>{const O=X.action();if(O){if(this._isRange&&"start"in O&&"end"in O){this._selectedStartDate=O.start,this._selectedEndDate=O.end;const W=this.getFormat(),j=this._formatDate(O.start,W),U=this._formatDate(O.end,W),Y=`${j} - ${U}`;this.setValue(Y),this._currentMonth=O.start.getMonth(),this._currentYear=O.start.getFullYear()}else if(O instanceof Date){this._selectedStartDate=O,this._selectedEndDate=null;const W=this.getFormat(),j=this._formatDate(O,W);this.setValue(j),this._currentMonth=O.getMonth(),this._currentYear=O.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}))}}),H.appendChild(B)}),L.appendChild(H),x.appendChild(L),o.appendChild(x)}c.appendChild(h),c.appendChild(v),c.appendChild(b),o.appendChild(c),this._calendarContainer.appendChild(o)}_buildMonthView(){if(!this._calendarContainer)return;const t=["January","February","March","April","May","June","July","August","September","October","November","December"],e=document.createElement("div");e.className="flex items-center justify-between mb-4";const i=document.createElement("button");i.type="button",i.tabIndex=0,i.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",i.setAttribute("data-keep-popover-open","true");const s=document.createElement("mint-icon");s.setAttribute("name","caret-left"),s.className="w-4 h-4",i.appendChild(s),i.addEventListener("click",()=>{const o=this._currentMonth,c=this._currentYear;this._currentYear--,this._buildCalendar(),this._dispatchMonthChangeEvent(o,c,this._currentMonth,this._currentYear)}),e.appendChild(i);const n=document.createElement("button");n.type="button",n.tabIndex=0,n.className="text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer transition-colors 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",n.setAttribute("data-keep-popover-open","true"),n.textContent=String(this._currentYear),n.addEventListener("click",()=>{this.getMode()!=="year"&&(this._viewMode="year",this._buildCalendar())}),e.appendChild(n);const r=document.createElement("button");r.type="button",r.tabIndex=0,r.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors 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");const a=document.createElement("mint-icon");a.setAttribute("name","caret-right"),a.className="w-4 h-4",r.appendChild(a),r.addEventListener("click",()=>{const o=this._currentMonth,c=this._currentYear;this._currentYear++,this._buildCalendar(),this._dispatchMonthChangeEvent(o,c,this._currentMonth,this._currentYear)}),e.appendChild(r);const l=document.createElement("div");l.className="grid grid-cols-3 gap-2",t.forEach((o,c)=>{const h=document.createElement("button");h.type="button",h.tabIndex=0,h.setAttribute("data-keep-popover-open","true");const p=this._currentMonth===c;h.className=`p-2 rounded text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${p?"bg-slate-800 dark:bg-slate-600 text-white":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"}`,h.textContent=o,h.addEventListener("click",()=>{if(this.getMode()==="month"){const u=new Date(this._currentYear,c,1),f=this.getFormat(),_=this._formatDate(u,f);this.setValue(_),this._selectedStartDate=u,this._selectedEndDate=null;const g=this._currentMonth,m=this._currentYear;this._currentMonth=c,this._dispatchMonthChangeEvent(g,m,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{const u=this._currentMonth,f=this._currentYear;this._currentMonth=c,this._viewMode="calendar",this._buildCalendar(),this._dispatchMonthChangeEvent(u,f,this._currentMonth,this._currentYear)}}),l.appendChild(h)}),this._calendarContainer.appendChild(e),this._calendarContainer.appendChild(l)}_buildYearView(){if(!this._calendarContainer)return;const t=this._currentYear-6,e=this._currentYear+6,i=document.createElement("div");i.className="flex items-center justify-between mb-4";const s=document.createElement("button");s.type="button",s.tabIndex=0,s.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors 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");const n=document.createElement("mint-icon");n.setAttribute("name","caret-left"),n.className="w-4 h-4",s.appendChild(n),s.addEventListener("click",()=>{const c=this._currentMonth,h=this._currentYear;this._currentYear-=12,this._buildCalendar(),this._dispatchMonthChangeEvent(c,h,this._currentMonth,this._currentYear)}),i.appendChild(s);const r=document.createElement("div");r.className="text-sm font-medium text-gray-900 dark:text-gray-100",r.textContent=`${t} - ${e}`,i.appendChild(r);const a=document.createElement("button");a.type="button",a.tabIndex=0,a.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",a.setAttribute("data-keep-popover-open","true");const l=document.createElement("mint-icon");l.setAttribute("name","caret-right"),l.className="w-4 h-4",a.appendChild(l),a.addEventListener("click",()=>{const c=this._currentMonth,h=this._currentYear;this._currentYear+=12,this._buildCalendar(),this._dispatchMonthChangeEvent(c,h,this._currentMonth,this._currentYear)}),i.appendChild(a);const o=document.createElement("div");o.className="grid grid-cols-3 gap-2";for(let c=t;c<=e;c++){const h=document.createElement("button");h.type="button",h.tabIndex=0,h.setAttribute("data-keep-popover-open","true");const p=this._currentYear===c;h.className=`p-2 rounded text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${p?"bg-slate-800 dark:bg-slate-600 text-white":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"}`,h.textContent=String(c),h.addEventListener("click",()=>{const d=this.getMode();if(d==="year"){const u=new Date(c,0,1),f=this.getFormat(),_=this._formatDate(u,f);this.setValue(_),this._selectedStartDate=u,this._selectedEndDate=null;const g=this._currentMonth,m=this._currentYear;this._currentYear=c,this._currentMonth=0,this._dispatchMonthChangeEvent(g,m,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(d==="month"){const u=this._currentMonth,f=this._currentYear;this._currentYear=c,this._viewMode="month",this._buildCalendar(),this._dispatchMonthChangeEvent(u,f,this._currentMonth,this._currentYear)}else{const u=this._currentMonth,f=this._currentYear;this._currentYear=c,this._viewMode="calendar",this._buildCalendar(),this._dispatchMonthChangeEvent(u,f,this._currentMonth,this._currentYear)}}),o.appendChild(h)}this._calendarContainer.appendChild(i),this._calendarContainer.appendChild(o)}_getDaysInMonth(t,e){return new Date(e,t+1,0).getDate()}_getFirstDayOfMonth(t,e){const i=this.getWeekStartDay(),s=new Date(e,t,1).getDay();return s>=i?s-i:7-(i-s)}_isToday(t){const e=new Date;return t.getDate()===e.getDate()&&t.getMonth()===e.getMonth()&&t.getFullYear()===e.getFullYear()}_isDateSelected(t){const e=this.getSelectionMode();return this._isRange||e==="week"||e==="month"?this._selectedStartDate&&this._selectedEndDate?this._isSameDate(t,this._selectedStartDate)||this._isSameDate(t,this._selectedEndDate):this._isRange&&this._selectedStartDate&&!this._selectedEndDate?this._isSameDate(t,this._selectedStartDate):!1:this._selectedStartDate!==null&&this._isSameDate(t,this._selectedStartDate)}_isDateInRange(t){const e=this.getSelectionMode();if((this._isRange||e==="week"||e==="month")&&this._selectedStartDate&&this._selectedEndDate)return this._rangeIncludesDisabledDates(this._selectedStartDate,this._selectedEndDate)?!1:t>=this._selectedStartDate&&t<=this._selectedEndDate;if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate){const i=this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,s=this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate;if(this._rangeIncludesDisabledDates(i,s)){const n=this._findFirstDisabledDateInRange(i,s);return n?this._selectedStartDate<this._hoveredDate?t>=i&&t<n&&!this._isSameDate(t,i):t>n&&t<=s&&!this._isSameDate(t,s):!1}return t>=i&&t<=s&&!this._isSameDate(t,i)&&!this._isSameDate(t,s)}return!1}_rangeIncludesDisabledDates(t,e){const i=this.getDisabledDates(),s=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=new Date(e.getFullYear(),e.getMonth(),e.getDate());return i.some(r=>{const a=new Date(r.getFullYear(),r.getMonth(),r.getDate());return a>=s&&a<=n})}_findFirstDisabledDateInRange(t,e){const i=this.getDisabledDates(),s=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=i.map(a=>new Date(a.getFullYear(),a.getMonth(),a.getDate())).filter(a=>a>=s&&a<=n).sort((a,l)=>a.getTime()-l.getTime());return r.length>0?r[0]:null}_hasIncompleteRange(){return this._isRange&&this._selectedStartDate!==null&&this._selectedEndDate===null}_isSameDate(t,e){return t.getDate()===e.getDate()&&t.getMonth()===e.getMonth()&&t.getFullYear()===e.getFullYear()}_isDateDisabled(t){return this.getDisabledDates().some(i=>this._isSameDate(t,i))}_dispatchMonthChangeEvent(t,e,i,s){(t!==i||e!==s)&&this.dispatchEvent(new CustomEvent("month-change",{detail:{month:i,year:s,oldMonth:t,oldYear:e},bubbles:!0,cancelable:!0,composed:!0}))}_dispatchDateChangeEvent(){const t=this.getFormat(),i={value:this.getValue()};this._selectedStartDate&&(i.startDate=this._selectedStartDate,i.startDateFormatted=this._formatDate(this._selectedStartDate,t)),this._selectedEndDate&&(i.endDate=this._selectedEndDate,i.endDateFormatted=this._formatDate(this._selectedEndDate,t)),this.dispatchEvent(new CustomEvent("date-change",{detail:i,bubbles:!0,cancelable:!0,composed:!0}))}_setupContainerObserver(){if(this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),!this._inputsWrapperEl)return;const t=400,e=s=>{this._inputsWrapperEl&&(s<t?(this._inputsWrapperEl.classList.add("flex-wrap"),this._inputsWrapperEl.classList.remove("flex-nowrap")):(this._inputsWrapperEl.classList.remove("flex-wrap"),this._inputsWrapperEl.classList.add("flex-nowrap")))},i=this._inputsWrapperEl.offsetWidth||this.offsetWidth;e(i),this._resizeObserver=new ResizeObserver(s=>{for(const n of s){const r=n.contentRect.width;e(r)}}),this._resizeObserver.observe(this)}_getWeekStart(t){const e=this.getWeekStartDay(),i=t.getDay();let s;i>=e?s=i-e:s=7-(e-i);const n=new Date(t);return n.setDate(t.getDate()-s),n.setHours(0,0,0,0),n}_getWeekEnd(t){const e=this._getWeekStart(t),i=new Date(e);return i.setDate(e.getDate()+6),i.setHours(23,59,59,999),i}_getMonthStart(t){const e=new Date(t.getFullYear(),t.getMonth(),1);return e.setHours(0,0,0,0),e}_getMonthEnd(t){const e=new Date(t.getFullYear(),t.getMonth()+1,0);return e.setHours(23,59,59,999),e}_handleDateClick(t){this._isHandlingClick=!0;try{const e=this.getFormat(),i=this.getSelectionMode();let s,n;if(i==="week"?(s=this._getWeekStart(t),n=this._getWeekEnd(t)):i==="month"?(s=this._getMonthStart(t),n=this._getMonthEnd(t)):(s=t,n=t),this.isRange()||i==="week"||i==="month")if(i==="week"||i==="month"){if(this._rangeIncludesDisabledDates(s,n)){this._buildCalendar();return}this._selectedStartDate=s,this._selectedEndDate=n;const l=this._formatDate(this._selectedStartDate,e),o=this._formatDate(this._selectedEndDate,e),c=`${l} - ${o}`;this.setValue(c),this._textInput&&(this._textInput.value=c),this._popover&&typeof this._popover.close=="function"&&this._popover.close()}else if(this._hoveredDate=null,this._selectedStartDate===null){if(this._isDateDisabled(s)){this._buildCalendar();return}this._selectedStartDate=new Date(s.getFullYear(),s.getMonth(),s.getDate()),this._selectedEndDate=null,this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear(),this._hoveredDate=null,this._buildCalendar()}else if(this._selectedEndDate===null){const l=new Date(t.getFullYear(),t.getMonth(),t.getDate()),o=this._selectedStartDate?new Date(this._selectedStartDate.getFullYear(),this._selectedStartDate.getMonth(),this._selectedStartDate.getDate()):null;let c,h;if(o&&l<o?(c=l,h=o):(c=o,h=l),this._rangeIncludesDisabledDates(c,h)){this._buildCalendar();return}o&&l<o?(this._selectedEndDate=o,this._selectedStartDate=l):(this._selectedEndDate=l,o&&(this._selectedStartDate=o)),this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();const p=this._formatDate(this._selectedStartDate,e),d=this._formatDate(this._selectedEndDate,e),u=`${p} - ${d}`;this.setAttribute("value",u),this._textInput&&(this._textInput.value=u),this._hiddenInput&&(this._hiddenInput.value=u),this._updateDisplayText(),this._buildCalendar(),this._popover&&typeof this._popover.close=="function"&&this._popover.close()}else this._selectedStartDate=s,this._selectedEndDate=null;else{this._selectedStartDate=s,this._selectedEndDate=null;const l=this._formatDate(s,e);this.setValue(l),this._textInput&&(this._textInput.value=l),this._popover&&typeof this._popover.close=="function"&&this._popover.close()}this._buildCalendar(),this._updateDisplayText(),this._exitInputMode();const 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;const t=this.getDisplayFormat(),e=this.getSelectionMode(),i=this._isRange||e==="week"||e==="month";let s="";i?this._selectedStartDate&&this._selectedEndDate?s=`${this._formatDatePhp(this._selectedStartDate,t)} - ${this._formatDatePhp(this._selectedEndDate,t)}`:this._selectedStartDate&&(s=this._formatDatePhp(this._selectedStartDate,t)):this._selectedStartDate&&(s=this._formatDatePhp(this._selectedStartDate,t)),s?(this._displayEl.textContent=s,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)){const t=this._startPartInputs[0];requestAnimationFrame(()=>{t.focus();try{t.setSelectionRange(0,t.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(t){let e=this.querySelector(".mint-date-picker-skeleton-container");const i=this._fieldsContainer,s=this._input;if(t){e||(e=document.createElement("div"),e.className="mint-date-picker-skeleton-container absolute inset-0 z-10 pointer-events-none",s?(s.classList.contains("relative")||s.classList.add("relative"),s.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let n=e.querySelector(".mint-date-picker-skeleton");n||(n=document.createElement("div"),n.className="mint-date-picker-skeleton w-full rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse",n.style.height="2.25rem",e.appendChild(n)),e.style.display="block",i&&(i.style.visibility="hidden",i.style.pointerEvents="none"),this._displayEl&&(this._displayEl.style.visibility="hidden",this._displayEl.style.pointerEvents="none")}else e&&(e.style.display="none"),i&&(i.style.visibility="visible",i.style.pointerEvents="auto"),this._displayEl&&(this._displayEl.style.visibility="visible",this._displayEl.style.pointerEvents="auto")}_getFocusableElements(){if(!this._calendarContainer)return[];const t=["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(t)).filter(i=>{const s=window.getComputedStyle(i);return s.display!=="none"&&s.visibility!=="hidden"})}_setupFocusTrap(){if(!this._popover||!this._popover.hasAttribute("open"))return;this._removeFocusTrap();const t=this;this._focusTrapHandler=function(e){var l;if(e.key!=="Tab")return;if(!t._popover||!t._popover.hasAttribute("open")){t._removeFocusTrap();return}const i=t._getFocusableElements();if(i.length===0)return;const s=i[0],n=i[i.length-1],r=document.activeElement;if(!(((l=t._calendarContainer)==null?void 0:l.contains(r))||!1)){e.preventDefault(),s.focus();return}if(e.shiftKey&&r===s){e.preventDefault(),n.focus();return}if(!e.shiftKey&&r===n){e.preventDefault(),s.focus();return}},this._escapeHandler=function(e){(e.key==="Escape"||e.key==="Esc")&&t._popover&&t._popover.hasAttribute("open")&&(e.preventDefault(),e.stopPropagation(),typeof t._popover.close=="function"&&t._popover.close())},document.addEventListener("keydown",this._focusTrapHandler,!0),document.addEventListener("keydown",this._escapeHandler,!0),requestAnimationFrame(()=>{const e=this._getFocusableElements();e.length>0&&e[0].focus()})}_removeFocusTrap(){this._focusTrapHandler&&(document.removeEventListener("keydown",this._focusTrapHandler,!0),this._focusTrapHandler=null),this._escapeHandler&&(document.removeEventListener("keydown",this._escapeHandler,!0),this._escapeHandler=null)}}customElements.get("mint-date-picker")||customElements.define("mint-date-picker",bt);class vt extends HTMLElement{constructor(){super(),this._select=null,this._wrapper=null,this._caretUpIcon=null,this._caretDownIcon=null,this._changeHandler=null,this._optionObserver=null,this._childrenObserver=null}static get observedAttributes(){return["name","value","disabled","id","required","label","info","error","error-message","multiple","loading"]}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(s=>{const n=Array.from(s.addedNodes).some(a=>a.nodeType===Node.ELEMENT_NODE&&(a.tagName==="OPTION"||a.tagName==="OPTGROUP"))||Array.from(s.removedNodes).some(a=>a.nodeType===Node.ELEMENT_NODE&&(a.tagName==="OPTION"||a.tagName==="OPTGROUP")),r=s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE&&(s.target.tagName==="OPTION"||s.target.tagName==="OPTGROUP");return n||r})&&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(),this._optionObserver=null),this._childrenObserver&&(this._childrenObserver.disconnect(),this._childrenObserver=null)}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute("aria-invalid",this.hasError()?"true":"false"));return}if(t==="loading"){this.render();return}if(t==="value"){this._select&&(this._select.value=i||"");return}this.render()}}getName(){return this.getAttribute("name")||""}getValue(){return this.hasAttribute("value")?this.getAttribute("value")||"":this._select?this._select.value:""}setValue(t){const e=t||"";this.setAttribute("value",e),this._select&&(this._select.value=e)}get value(){try{return this.getValue()||""}catch{return""}}set value(t){try{const e=t||"";(this.getAttribute("value")||"")!==e&&this.setAttribute("value",e),this._select&&requestAnimationFrame(()=>{this._select&&(e===""||Array.from(this._select.options).some(n=>n.value===e))&&this._select.value!==e&&(this._select.value=e)})}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(){const t=this.hasError(),e=this.isMultiple(),i=["w-full","px-3.5",e?"pr-3.5":"pr-10",e?"py-2":"py-1.5",e?"min-h-[6rem]":"min-h-[2rem]","text-sm","font-medium","rounded-lg","box-border","bg-white","dark:bg-gray-900","text-gray-900","dark:text-white","transition-all","duration-200","outline-none","focus:outline-none","disabled:opacity-40","disabled:cursor-not-allowed","appearance-none","bg-no-repeat","bg-right","cursor-pointer"],s=["border-2",t?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700"],n=["focus-visible:ring-2","focus-visible:ring-offset-1",t?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500"];return[...i,...s,...n].filter(Boolean).join(" ")}render(){const t=this.isLoading(),e=[];this._select&&Array.from(this._select.children).forEach(d=>{(d.tagName==="OPTION"||d.tagName==="OPTGROUP")&&e.push(d.cloneNode(!0))});const i=Array.from(this.children).filter(d=>d.tagName==="OPTION"||d.tagName==="OPTGROUP").map(d=>d.cloneNode(!0));for(;this.firstChild;)this.removeChild(this.firstChild);this._wrapper=null,this._select=null;const s=this.getLabel(),n=this.getInfo(),r=this.getId(),a=this.getName(),l=this.getValue(),o=this.isDisabled(),c=this.isMultiple(),h=this.hasError();if(s){const d=document.createElement("label");d.className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",r&&d.setAttribute("for",r);const u=document.createTextNode(s);d.appendChild(u),this.appendChild(d)}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(),r&&(this._select.id=r),a&&(this._select.name=a),o&&(this._select.disabled=!0),c&&(this._select.multiple=!0),this._select.setAttribute("aria-invalid",h?"true":"false");const p=i.length>0?i:e;if(p.length>0&&p.forEach(d=>{this._select.appendChild(d)}),this._select.options.length===0){const d=document.createElement("option");d.value="",d.textContent="Select an option",d.disabled=!0,d.selected=!0,this._select.appendChild(d)}if(this._select.value=l||"",this._changeHandler&&this._select&&this._select.removeEventListener("change",this._changeHandler),this._changeHandler=d=>{const f=d.target.value;(this.getAttribute("value")||"")!==f&&(f?this.setAttribute("value",f):this.removeAttribute("value"));const g=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(g),this.dispatchEvent(new CustomEvent("input",{detail:{value:f},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:{value:f},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener("change",this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{const d=this.getAttribute("value")||this.value||"";this._select&&d&&requestAnimationFrame(()=>{this._select&&Array.from(this._select.options).some(f=>f.value===d)&&this._select.value!==d&&(this._select.value=d)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),c)this._caretUpIcon=null,this._caretDownIcon=null;else{const d=document.createElement("div");d.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]",d.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]",d.appendChild(this._caretDownIcon),this._wrapper.appendChild(d)}if(n){const d=document.createElement("div");d.className="mt-1 text-xs text-gray-500 dark:text-gray-400",d.textContent=n,this.appendChild(d)}this._renderErrorState(),this._renderSkeleton(t)}_renderSkeleton(t){let e=this.querySelector(".mint-select-skeleton-container");const i=this._wrapper;if(t){e||(e=document.createElement("div"),e.className="mint-select-skeleton-container absolute inset-0 z-10 pointer-events-none",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-select-skeleton");if(!s){s=document.createElement("div"),s.className="mint-select-skeleton w-full rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse";const n=this.isMultiple();s.style.height=n?"6rem":"2.25rem",e.appendChild(s)}e.style.display="block",this._select&&(this._select.style.opacity="0",this._select.style.pointerEvents="none")}else e&&(e.style.display="none"),this._select&&(this._select.style.opacity="1",this._select.style.pointerEvents="auto")}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-select-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-select-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}}customElements.get("mint-select")||customElements.define("mint-select",vt);class yt extends HTMLElement{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}static get observedAttributes(){return["label","accept","multiple","width","height","disabled","name","error","error-message","loading"]}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){const t=this.closest("form");t&&t.removeEventListener("reset",this._resetHandler),this._resetHandler=null}}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){this._updateDragStateClass(),this._renderErrorState(this.hasError(),this.getErrorMessage());return}if(t==="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(t){let e=this.querySelector(".mint-dropzone-skeleton-container");const i=this._dropzone;if(t){e||(e=document.createElement("div"),e.className="mint-dropzone-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center justify-center",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-dropzone-skeleton");if(s||(s=document.createElement("div"),s.className="mint-dropzone-skeleton rounded-lg border-2 border-dashed border-gray-300 dark:border-gray-600 bg-gray-200 dark:bg-gray-700 animate-pulse",s.style.width="100%",s.style.height="100%",e.appendChild(s)),e.style.display="flex",i){const n=i.querySelector(".mint-dropzone-icon"),r=i.querySelector(".mint-dropzone-label"),a=i.querySelector(".mint-dropzone-previews-wrapper"),l=this._fileInput;if(n){const o=n;o.style.visibility="hidden",o.style.pointerEvents="none"}if(r){const o=r;o.style.visibility="hidden",o.style.pointerEvents="none"}if(a){const o=a;o.style.visibility="hidden",o.style.pointerEvents="none"}l&&(l.style.visibility="hidden",l.style.pointerEvents="none"),i.style.pointerEvents="none"}}else if(e&&(e.style.display="none"),i){const s=i.querySelector(".mint-dropzone-icon"),n=i.querySelector(".mint-dropzone-label"),r=i.querySelector(".mint-dropzone-previews-wrapper"),a=this._fileInput;if(s){const l=s;l.style.visibility="visible",l.style.pointerEvents="auto"}if(n){const l=n;l.style.visibility="visible",l.style.pointerEvents="auto"}if(r){const l=r;l.style.visibility="visible",l.style.pointerEvents="auto"}a&&(a.style.visibility="visible",a.style.pointerEvents="auto"),i.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(){const t=this.isLoading(),e=this.getLabel(),i=this.getAccept(),s=this.isMultiple(),n=this.isDisabled(),r=this.getWidth(),a=this.getHeight(),l=this.getName(),o=this.hasError(),c=this.getErrorMessage();this._dropzone||(this._dropzone=document.createElement("div"),this.appendChild(this._dropzone)),this._updateDragStateClass(),this._dropzone.setAttribute("aria-invalid",o?"true":"false"),n?(this._dropzone.setAttribute("tabindex","-1"),this._dropzone.removeAttribute("role")):(this._dropzone.setAttribute("tabindex","0"),this._dropzone.setAttribute("role","button"),this._dropzone.setAttribute("aria-label",e||"File upload dropzone")),this._dropzone.style.width=r,this._dropzone.style.height=a,this._dropzone.style.minWidth=r,this._dropzone.style.minHeight=a,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=i,this._fileInput.multiple=s,this._fileInput.disabled=n,l?this._fileInput.name=l:this._fileInput.removeAttribute("name"),this._fileInput.setAttribute("aria-invalid",o?"true":"false");const h=this._dropzone.querySelector(".mint-dropzone-icon"),p=this._dropzone.querySelector(".mint-dropzone-label");h&&h.remove(),p&&p.remove();const d=document.createElement("div");d.className="mint-dropzone-icon flex items-center justify-center mt-2 mb-2 flex-shrink-0";const u=document.createElement("mint-icon");if(u.setAttribute("name","upload"),u.className="w-12 h-12 text-gray-400 dark:text-gray-500",d.appendChild(u),this._dropzone.appendChild(d),e){const f=document.createElement("div");f.className="mint-dropzone-label text-sm font-medium text-gray-600 dark:text-gray-400 text-center px-4 flex-shrink-0",f.textContent=e,this._dropzone.appendChild(f)}this.setupEventListeners(),this._renderErrorState(o,c),this._renderPreviews(),this._renderSkeleton(t)}_updateDragState(){this._dropzone&&this._updateDragStateClass()}_renderErrorState(t,e){let i=this.querySelector(".mint-dropzone-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-dropzone-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}_updateDragStateClass(){if(!this._dropzone)return;const t=this.isDisabled(),e=this.hasError(),n=`relative border-2 border-dashed rounded-lg transition-all duration-200 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-gray-900 dark:border-gray-700":"border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 dark:border-gray-700 hover:border-gray-400 dark:hover:border-gray-500",a=e?"border-red-300 dark:border-red-300 bg-red-50/50 dark:bg-red-900/30":"",l=t?"opacity-40 cursor-not-allowed":"",o="focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500";this._dropzone.className=`${n} ${e?a:r} ${l} ${o}`.trim()}setupEventListeners(){this._listenersInitialized||(this._listenersInitialized=!0,this.removeEventListeners(),!(!this._dropzone||!this._fileInput||this.isDisabled())&&(this._onDropzoneClick||(this._onDropzoneClick=t=>{if(!(this.isDisabled()||!this._fileInput)&&t.target!==this._fileInput&&(t.stopPropagation(),t.preventDefault(),t.isTrusted))try{this._fileInput.click()}catch(e){console.debug("File chooser blocked:",e)}}),this._onDragOver||(this._onDragOver=t=>{t.preventDefault(),t.stopPropagation(),this.isDisabled()||this._isDragging||(this._isDragging=!0,this._wasDragging=!0,this._updateDragState())}),this._onDragLeave||(this._onDragLeave=t=>{var i;t.preventDefault(),t.stopPropagation();const e=(i=this._dropzone)==null?void 0:i.getBoundingClientRect();e&&(t.clientX<e.left||t.clientX>e.right||t.clientY<e.top||t.clientY>e.bottom)&&this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState())}),this._onDrop||(this._onDrop=t=>{var i;if(t.preventDefault(),t.stopPropagation(),this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState()),this.isDisabled())return;const e=(i=t.dataTransfer)==null?void 0:i.files;e&&e.length>0&&this._handleFiles(e)}),this._onFileInputInput||(this._onFileInputInput=t=>{t.stopImmediatePropagation(),t.stopPropagation()}),this._onKeyDown||(this._onKeyDown=t=>{if(!(this.isDisabled()||!this._fileInput)&&(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),t.stopPropagation(),t.isTrusted))try{this._fileInput.click()}catch(e){console.debug("File chooser blocked:",e)}}),this._onFocus||(this._onFocus=t=>{this._dropzone&&!this.isDisabled()&&this._dropzone.classList.add("focus-visible:ring-2")}),this._onBlur||(this._onBlur=t=>{this._dropzone}),this._onFileInputChange||(this._onFileInputChange=t=>{if(t.stopImmediatePropagation(),t.stopPropagation(),this._isUpdatingFiles)return;const i=t.target.files;if(i&&i.length>0){const s=this.getAccept(),n=this.isMultiple(),r=[],a=[];for(let l=0;l<i.length;l++){const o=i[l];this._isFileAccepted(o,s)?r.push(o):a.push(o)}if(!n&&r.length>1&&(a.push(...r.slice(1)),r.splice(1)),a.length>0){const l=new CustomEvent("dropRejected",{detail:{files:a,reason:"File type not accepted or multiple files not allowed"},bubbles:!0,cancelable:!0});this.dispatchEvent(l)}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(t){const e=this.getAccept(),i=this.isMultiple(),s=[],n=[];for(let r=0;r<t.length;r++){const a=t[r];this._isFileAccepted(a,e)?s.push(a):n.push(a)}if(!i&&s.length>1&&(n.push(...s.slice(1)),s.splice(1)),n.length>0){const r=new CustomEvent("dropRejected",{detail:{files:n,reason:"File type not accepted or multiple files not allowed"},bubbles:!0,cancelable:!0});this.dispatchEvent(r)}s.length>0&&this._applyValidFiles(s)}_isFileAccepted(t,e){var s;if(!e)return!0;const i=e.split(",").map(n=>n.trim().toLowerCase());for(const n of i)if(n.startsWith(".")){if("."+((s=t.name.split(".").pop())==null?void 0:s.toLowerCase())===n)return!0}else if(n.includes("/*")){const r=n.split("/")[0],a=t.type.split("/")[0];if(r===a)return!0}else if(t.type===n)return!0;return!1}_dispatchEvent(t,e){const i=e.target,s=new CustomEvent(t,{detail:{files:i.files?Array.from(i.files):[],value:i.value||""},bubbles:!0,cancelable:!0});this.dispatchEvent(s)}_dispatchSelectionEvents(){const 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;const t=new DataTransfer;this._selectedFiles.forEach(e=>{try{t.items.add(e)}catch(i){console.warn("Failed to add file to DataTransfer:",i)}}),this._isUpdatingFiles=!0;try{this._fileInput.files=t.files}catch(e){console.warn("Failed to set files on input:",e)}setTimeout(()=>{this._isUpdatingFiles=!1},0)}get files(){var t;return this._syncFileInputFromSelected(),((t=this._fileInput)==null?void 0:t.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}const t=document.createElement("div");t.className="mint-dropzone-previews-wrapper mt-3 w-full relative max-h-48";const e=document.createElement("div");e.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((o,c)=>{const h=document.createElement("div");if(h.className="flex items-center gap-3 p-2 rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900",o.type.startsWith("image/")){const f=document.createElement("img");f.className="w-12 h-12 object-cover rounded border border-gray-200 dark:border-gray-700";const _=URL.createObjectURL(o);this._previewUrls.push(_),f.src=_,h.appendChild(f)}else{const f=document.createElement("mint-icon");f.setAttribute("name","attach"),f.className="w-5 h-5 text-gray-500 dark:text-gray-300",h.appendChild(f)}const p=document.createElement("div");p.className="flex-1 text-sm text-gray-800 dark:text-gray-100 truncate",p.textContent=o.name,h.appendChild(p);const d=document.createElement("button");d.type="button",d.className="text-gray-500 hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors flex items-center justify-center w-6 h-6 rounded-full";const u=document.createElement("mint-icon");u.setAttribute("name","close"),u.className="w-4 h-4",d.appendChild(u),d.addEventListener("click",f=>{f.preventDefault(),f.stopPropagation(),this._removeFileAt(c)}),h.appendChild(d),e.appendChild(h)});const i=this.hasError(),s=this._isDragging;let n="from-white dark:from-gray-700";i?n="from-red-50 dark:from-red-900/30":s&&(n="from-gray-50 dark:from-gray-800");const r=document.createElement("div");r.className=`absolute top-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-b ${n} to-transparent opacity-0 transition-opacity duration-200`,t.appendChild(r);const a=document.createElement("div");a.className=`absolute bottom-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-t ${n} to-transparent opacity-100 transition-opacity duration-200`,t.appendChild(a);const l=()=>{const o=e.scrollTop,c=e.scrollHeight,h=e.clientHeight;o>0?r.style.opacity="1":r.style.opacity="0",o+h<c-1?a.style.opacity="1":a.style.opacity="0"};l(),e.addEventListener("scroll",l),t.appendChild(e),this._previewContainer=t,this._dropzone.appendChild(t),this._updateDragStateClass()}_removeFileAt(t){if(t<0||t>=this._selectedFiles.length)return;const[e]=this._selectedFiles.splice(t,1);e&&this._cleanupPreviewUrls(),this._syncFileInputFromSelected(),this._renderPreviews(),this._dispatchSelectionEvents()}_cleanupPreviewUrls(){this._previewUrls.forEach(t=>URL.revokeObjectURL(t)),this._previewUrls=[]}_attachFormResetListener(){const t=this.closest("form");!t||this._resetHandler||(this._resetHandler=()=>{this._selectedFiles=[],this._syncFileInputFromSelected(),this._renderPreviews(),this._cleanupPreviewUrls()},t.addEventListener("reset",this._resetHandler))}_applyValidFiles(t){if(this.isMultiple()){const i=t.filter(s=>!this._isDuplicateFile(s));this._selectedFiles.push(...i)}else this._selectedFiles=[t[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(t){return this._selectedFiles.some(e=>e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified)}}customElements.get("mint-dropzone")||customElements.define("mint-dropzone",yt);class kt extends HTMLElement{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._reactiveDataProxy=null,this._reactiveDataObserver=null,this._lastDataSnapshot=null}static get observedAttributes(){return["action","method","enctype","data-form-data","loading","headers"]}connectedCallback(){this._render(),this._ensureSubmitHandler(),this._setupBlurValidation();const t=this.getAttribute("headers");t&&this._parseHeaders(t),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(this._formData)this._isReactiveObject(this._formData)?this._setupReactiveDataObserver(this._formData):this._lastDataSnapshot||(this._lastDataSnapshot=this._createDataSnapshot(this._formData)),this._applyFormData();else{const e=this.getAttribute("data-form-data");e&&(this._parseFormData(e),this._applyFormData())}this._propagateLoadingState()})})}disconnectedCallback(){this._form&&this._submitHandler&&this._form.removeEventListener("submit",this._submitHandler,!0),this._hostSubmitHandler&&this.removeEventListener("submit",this._hostSubmitHandler),this._cleanupBlurValidation(),this._stopReactiveDataObserver()}reset(){this._clearErrors(),this._formData?this._applyFormData():this.clear()}clear(){this._clearErrors(),this._form&&this._form.reset(),this._resetCustomFields()}attributeChangedCallback(t,e,i){t==="form-data"?(this._parseFormData(i),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})):t==="headers"?this._parseHeaders(i):t==="loading"?this.isConnected&&this._form?requestAnimationFrame(()=>{this._propagateLoadingState()}):this._propagateLoadingState():this._applyFormAttributes()}get data(){return this._formData}set data(t){this._stopReactiveDataObserver(),this._reactiveDataProxy=null,this._lastDataSnapshot=null,t&&typeof t=="object"&&!Array.isArray(t)?(this._formData=t,this._isReactiveObject(t)?this._setupReactiveDataObserver(t):this._lastDataSnapshot=this._createDataSnapshot(t)):t==null?this._formData=null:this._parseFormData(t),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})})}get headers(){return this._headers}set headers(t){if(t&&typeof t=="object"&&!Array.isArray(t))this._headers=t;else if(t==null)this._headers=null;else if(typeof t=="string")try{this._headers=JSON.parse(t)}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=t=>{t.preventDefault(),t.stopImmediatePropagation(),this._handleSubmit(t)},this._form.addEventListener("submit",this._submitHandler,!0))}_applyFormAttributes(){if(!this._form)return;const t=this.getAttribute("action")||"",e=this.getAttribute("method")||"",i=this.getAttribute("enctype")||"application/x-www-form-urlencoded";t&&(this._form.action=t),e&&(this._form.method=e),this._form.enctype=i}async _handleSubmit(t){var c;if(t.preventDefault(),!this._form)return;this._clearErrors(),this._syncDropzoneFiles();const e=this._collectValidationRules(),i=new FormData(this._form);let s=this._formDataToValues(i);if(this._formData){const h=this._getReactiveValue(this._formData);h&&typeof h=="object"&&!Array.isArray(h)&&(s={...this._extractReactiveData(h),...s})}if(!this._validate(s,e)){this.dispatchEvent(new CustomEvent("invalid",{detail:{errors:this._errors},bubbles:!0,cancelable:!0,composed:!0}));return}const r=new CustomEvent("submit",{detail:{formData:i,values:s,form:this},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(r),r.form=this;const a=new CustomEvent("mintFormSubmit",{detail:{formData:i,values:s,form:this},bubbles:!0,cancelable:!0,composed:!0});if(a.form=this,this.dispatchEvent(a),r.defaultPrevented||a.defaultPrevented)return;const l=this.getAttribute("action"),o=this.getAttribute("method");if(!(!l||!o)){this._setButtonsSubmitting();try{const h=await this._submitData(i,s);this.dispatchEvent(new CustomEvent("submitsuccess",{detail:h,bubbles:!0,cancelable:!0}))}catch(h){(h==null?void 0:h.status)===422&&((c=h==null?void 0:h.data)!=null&&c.errors)&&this._applyServerErrors(h.data.errors),this.dispatchEvent(new CustomEvent("submiterror",{detail:{error:h},bubbles:!0,cancelable:!0}))}finally{this._restoreButtonsState()}}}async _submitData(t,e){var h,p,d;const i=this.getAttribute("action"),s=this.getAttribute("method"),n=this.getAttribute("enctype")||"application/x-www-form-urlencoded";if(!i)return{status:0,ok:!0,data:{values:e}};const r=Array.from(t.values()).some(u=>u instanceof File);let a=null;const l={};let o=i;if(typeof window<"u"&&((d=(p=(h=window.mintForm)==null?void 0:h.defaults)==null?void 0:p.headers)!=null&&d.common)&&Object.assign(l,window.mintForm.defaults.headers.common),this._headers&&Object.assign(l,this._headers),s==="GET"){const u=new URLSearchParams;t.forEach((f,_)=>{f instanceof File||u.append(_,String(f))}),o+=(i.includes("?")?"&":"?")+u.toString()}else if(n==="multipart/form-data"||r)a=t;else if(n==="application/json")a=JSON.stringify(e),l["Content-Type"]="application/json";else{const u=new URLSearchParams;t.forEach((f,_)=>{f instanceof File||u.append(_,String(f))}),a=u,l["Content-Type"]="application/x-www-form-urlencoded"}if(typeof fetch=="function")try{const u=await fetch(o,{method:s||"POST",body:s==="GET"?null:a,headers:l}),f=await u.text().catch(()=>"");let _=f;try{_=JSON.parse(f)}catch{}if(!u.ok){const m={status:u.status,data:_,response:{status:u.status,data:_}};throw await this._applyErrorInterceptors(m)}const g={status:u.status,ok:u.ok,data:_};return await this._applySuccessInterceptors(g)}catch(u){if(u.response)throw u;const f={status:u.status||0,data:u.data||u.message||"Network error",response:{status:u.status||0,data:u.data||u.message||"Network error"}};throw await this._applyErrorInterceptors(f)}const c=this;return await new Promise(async(u,f)=>{const _=new XMLHttpRequest;_.open(s||"POST",o,!0),Object.entries(l).forEach(([g,m])=>_.setRequestHeader(g,m)),_.onload=async function(){const{status:g,responseText:m}=_;if(g>=200&&g<300){let v=m;try{v=JSON.parse(m)}catch{}try{const b={status:g,ok:!0,data:v},k=await c._applySuccessInterceptors(b);u(k)}catch(b){f(b)}}else{let v=m;try{v=JSON.parse(m)}catch{}try{const b={status:g,data:v,response:{status:g,data:v}},k=await c._applyErrorInterceptors(b);f(k)}catch(b){f(b)}}},_.onerror=async function(){try{const g={status:_.status||0,data:_.responseText||"Network error",response:{status:_.status||0,data:_.responseText||"Network error"}},m=await c._applyErrorInterceptors(g);f(m)}catch(g){f(g)}},_.send(s==="GET"?null:a)})}async _applySuccessInterceptors(t){var s,n,r;if(typeof window>"u"||!((r=(n=(s=window.mintForm)==null?void 0:s.interceptors)==null?void 0:n.response)!=null&&r.handlers))return t;let e=t;const i=window.mintForm.interceptors.response.handlers;for(const a of i)a.fulfilled&&(e=await a.fulfilled(e));return e}async _applyErrorInterceptors(t){var s,n,r;if(typeof window>"u"||!((r=(n=(s=window.mintForm)==null?void 0:s.interceptors)==null?void 0:n.response)!=null&&r.handlers))return Promise.reject(t);let e=t;const i=window.mintForm.interceptors.response.handlers;for(let a=i.length-1;a>=0;a--){const l=i[a];if(l.rejected)try{if(e=await l.rejected(e),e!==void 0)return e}catch(o){e=o}}return Promise.reject(e)}_formDataToValues(t){const e={};return t.forEach((i,s)=>{i instanceof File?(e[s]||(e[s]=[]),e[s].push(i)):s in e?Array.isArray(e[s])?(e[s].length>0&&e[s][0]instanceof File,e[s].push(i)):e[s]=[e[s],i]:e[s]=i}),this._form&&(Array.from(this._form.querySelectorAll("mint-dropzone[name]")).forEach(r=>{const a=r.getAttribute("name");if(a&&typeof r.files<"u"&&r.files){const l=r.files;if(l.length>0){const o=Array.from(l);e[a]&&Array.isArray(e[a])?o.forEach(c=>{e[a].some(p=>p.name===c.name&&p.size===c.size&&p.lastModified===c.lastModified)||e[a].push(c)}):e[a]=o}}}),Array.from(this._form.querySelectorAll('input[type="file"][name]')).forEach(r=>{const a=r.name;if(a&&r.files&&r.files.length>0){const l=Array.from(r.files);e[a]&&Array.isArray(e[a])?l.forEach(o=>{e[a].some(h=>h.name===o.name&&h.size===o.size&&h.lastModified===o.lastModified)||e[a].push(o)}):e[a]=l}}),Array.from(this._form.querySelectorAll("mint-tags[name]")).forEach(r=>{const a=r.getAttribute("name");if(a){let l=[];if(typeof r.tags<"u"?l=r.tags:typeof r.getTags=="function"&&(l=r.getTags()),Array.isArray(l)&&l.length>0){const o=l.map(c=>typeof c=="string"?c:(c==null?void 0:c.value)||(c==null?void 0:c.label)||"").filter(c=>c.trim()!=="");e[a]=o}else e[a]=[]}})),e}_collectValidationRules(){const t={};return this._form&&Array.from(this._form.querySelectorAll("[name][validation]")).forEach(i=>{const s=i.getAttribute("name")||"",n=i.getAttribute("validation");if(!s||!n)return;const r=this._parseRules(n);r.length&&(t[s]=r)}),t}_parseRules(t){if(!t)return[];try{const e=t.replace(/'/g,'"'),i=JSON.parse(e);if(Array.isArray(i))return i.map(s=>String(s))}catch{}return t.split(",").map(e=>e.trim()).filter(Boolean)}_validate(t,e){let i=!0;return this._errors={},Object.entries(e||{}).forEach(([s,n])=>{const r=Array.isArray(n)?n:[n],a=this._getFieldElements(s),l=this._extractFieldValue(a),o=this._validateRules(l,r);o?(i=!1,this._errors[s]=o,this._flagFieldError(a,o)):this._clearFieldError(a)}),i}_validateField(t){const e=this._collectValidationRules();if(!e[t])return;const i=e[t],s=Array.isArray(i)?i:[i],n=this._getFieldElements(t),r=this._extractFieldValue(n),a=this._validateRules(r,s);a?(this._errors[t]=a,this._flagFieldError(n,a)):(this._clearFieldError(n),delete this._errors[t])}_validateRules(t,e){for(const i of e){const[s,n]=i.split(":");switch(s){case"required":{if(t==null||typeof t=="string"&&t.trim()===""||t instanceof FileList&&t.length===0||Array.isArray(t)&&t.length===0)return"This field is required.";break}case"string":{if(typeof t!="string")return"Must be a string.";break}case"email":{if(typeof t=="string"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim()))return"Enter a valid email.";break}case"number":{const r=Number(t);if(Number.isNaN(r))return"Must be a number.";break}case"min":{const r=Number(n);if(Number.isNaN(r))break;if(typeof t=="string"&&t.trim().length<r)return`Must be at least ${r} characters.`;if(Array.isArray(t)&&t.length<r)return`Select at least ${r}.`;if(t instanceof FileList&&t.length<r)return`Upload at least ${r} files.`;if(t!=null&&!Number.isNaN(Number(t))&&Number(t)<r)return`Must be at least ${r}.`;break}case"max":{const r=Number(n);if(Number.isNaN(r))break;if(typeof t=="string"&&t.trim().length>r)return`Must be at most ${r} characters.`;if(Array.isArray(t)&&t.length>r)return`Select no more than ${r}.`;if(t instanceof FileList&&t.length>r)return`Upload no more than ${r} files.`;if(t!=null&&!Number.isNaN(Number(t))&&Number(t)>r)return`Must be at most ${r}.`;break}}}return null}_getFieldElements(t){if(!this._form)return[];const e=Array.from(this._form.querySelectorAll(`[name="${t}"]`)),i=e.filter(r=>r.tagName==="MINT-SELECT");if(i.length>0){const r=[];return i.forEach(a=>{const l=a.querySelector('select[name="'+t+'"]');l&&r.push(l)}),e.filter(a=>a.tagName!=="MINT-SELECT").concat(r)}if(e.filter(r=>r.tagName==="MINT-TAGS").length>0)return e.filter(r=>r.tagName!=="INPUT"||!r.closest("mint-tags"));const n=e.filter(r=>r.tagName==="INPUT"&&r.closest("mint-tags"));if(n.length>0){const r=[];return n.forEach(a=>{const l=a.closest("mint-tags");l&&!r.includes(l)&&r.push(l)}),e.filter(a=>a.tagName!=="INPUT"||!a.closest("mint-tags")).concat(r)}return e}_extractFieldValue(t){if(t.length===0)return"";const e=t.find(s=>s instanceof HTMLSelectElement);if(e)return e.value;if(t.length>1){const s=t.filter(a=>a instanceof HTMLInputElement);if(s.length>0&&s.length===t.length){const a=s.filter(l=>l.checked);if(s.every(l=>l.type==="radio"))return a.length>0?a[0].value||"on":"";if(s.every(l=>l.type==="checkbox"))return a.map(l=>l.value||"on")}const n=t.filter(a=>a.tagName==="MINT-CHOICE");if(n.length>0&&n.length===t.length){const a=n.find(l=>typeof l.getValue=="function"?l.getValue()!=="":l.querySelector("mint-choice-option[checked]")!==null);if(a){if(typeof a.getValue=="function")return a.getValue();const l=a.querySelector("mint-choice-option[checked]");if(l)return l.getAttribute("value")||""}return""}const r=t.filter(a=>a.tagName==="MINT-CHECKBOX");if(r.length>0&&r.length===t.length)return r.filter(l=>typeof l.checked<"u"?l.checked:l.hasAttribute("checked")).map(l=>l.getAttribute("value")||"on")}const i=t[0];if(i instanceof HTMLInputElement)return i.type==="file"?i.files:i.type==="checkbox"||i.type==="radio"?i.checked?i.value||"on":"":i.value;if(i instanceof HTMLTextAreaElement)return i.value;if(i.tagName==="MINT-SELECT"){const s=i.querySelector("select");if(s)return s.value;if(typeof i.getValue=="function"){const r=i.getValue();if(r!=null&&r!=="")return r}const n=i.getAttribute("value");return n||""}if(i.tagName==="MINT-DROPZONE"&&typeof i.files<"u")return i.files;if(i.tagName==="MINT-TAGS"){let s=null;return typeof i.tags<"u"?s=i.tags:typeof i.getTags=="function"&&(s=i.getTags()),Array.isArray(s)?s.map(r=>typeof r=="string"?r:(r==null?void 0:r.value)||(r==null?void 0:r.label)||"").filter(r=>r.trim()!==""):[]}return i.tagName==="MINT-CHECKBOX"||i.tagName==="MINT-SWITCH"?(typeof i.checked<"u"?i.checked:i.hasAttribute("checked"))?i.getAttribute("value")||"on":"":i.tagName==="MINT-CHOICE"?(typeof i.getValue=="function"?i.getValue():"")||"":typeof i.value<"u"?i.value:i.getAttribute("value")||""}_flagFieldError(t,e){t.length!==0&&t.forEach(i=>{(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement)&&i.setAttribute("aria-invalid","true");const s=this._resolveHost(i);s&&(s.setAttribute("error","true"),s.setAttribute("error-message",e),s.setAttribute("data-mint-form-error","true"))})}_clearFieldError(t){t.length!==0&&t.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.removeAttribute("aria-invalid");const i=this._resolveHost(e);i&&(i.removeAttribute("error"),i.removeAttribute("error-message"),i.removeAttribute("data-mint-form-error"))})}_clearErrors(){this.querySelectorAll("[data-mint-form-error]").forEach(t=>{const e=t;e.removeAttribute("error"),e.removeAttribute("error-message"),e.removeAttribute("data-mint-form-error")}),this._form&&this._form.querySelectorAll('[aria-invalid="true"]').forEach(t=>{t.removeAttribute("aria-invalid")}),this._errors={}}setFormErrors(t){this._applyServerErrors(t)}_applyServerErrors(t){this._clearErrors(),Object.entries(t).forEach(([e,i])=>{const s=Array.isArray(i)?i[0]||"Validation error":i||"Validation error",n=this._getFieldElements(e);n.length>0&&(this._errors[e]=s,this._flagFieldError(n,s))})}_parseFormData(t){if(!t){this._formData=null;return}if(typeof t=="object"&&!Array.isArray(t)){this._formData=t;return}if(typeof t=="string")try{this._formData=JSON.parse(t)}catch{this._formData=null}else this._formData=null}_parseHeaders(t){if(!t){this._headers=null;return}if(typeof t=="string")try{this._headers=JSON.parse(t)}catch{this._headers=null}else this._headers=null}_applyFormData(){if(!this._formData||!this._form)return;const t=this._getReactiveValue(this._formData);if(!t||typeof t!="object"||Array.isArray(t))return;const e=()=>{Object.entries(t).forEach(([i,s])=>{const n=this._getFieldElements(i);if(n.length===0){setTimeout(()=>{const r=this._getFieldElements(i);r.length>0&&this._applyValueToField(r,i,s)},300);return}this._applyValueToField(n,i,s)})};requestAnimationFrame(()=>{requestAnimationFrame(()=>{e()})})}_applyValueToField(t,e,i){t.forEach(s=>{var r;const n=s.tagName;try{if(n==="MINT-INPUT")typeof s.value<"u"&&(s.value=i||"");else if(n==="MINT-DATE-PICKER")typeof s.setValue=="function"&&s.setValue(i||"");else if(n==="MINT-SELECT"||n==="SELECT")n==="SELECT"?(r=s.closest("mint-select"))==null||r.setValue(i||""):typeof s.setValue=="function"&&s.setValue(i||"");else if(n==="MINT-CHOICE")typeof s.setValue=="function"?s.setValue(i||""):s.querySelectorAll("mint-choice-option").forEach(l=>{l.checked=l.getAttribute("value")===i});else if(n==="MINT-CHECKBOX"||n==="MINT-SWITCH"){const a=i===!0||i==="true"||i==="on"||i===1||i==="1";typeof s.checked<"u"?s.checked=a:a?s.setAttribute("checked","true"):s.removeAttribute("checked")}else n==="MINT-TAGS"?Array.isArray(i)&&typeof s.tags<"u"&&(s.tags=i.map(a=>typeof a=="string"?{value:a,label:a,dismissable:!0}:a)):s instanceof HTMLInputElement?s.type==="checkbox"||s.type==="radio"?s.checked=i===!0||i==="true"||i==="on"||i===1||i==="1":s.value=i||"":(s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)&&(s.value=i||"")}catch(a){console.warn(`Failed to set value for field ${e}:`,a)}})}_resetCustomFields(){this.querySelectorAll("mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags").forEach(e=>{var s,n;e.removeAttribute("error"),e.removeAttribute("error-message");const i=e.tagName;if(i==="MINT-INPUT")try{e.value=""}catch{}else if(i==="MINT-DATE-PICKER")try{(s=e.setValue)==null||s.call(e,"")}catch{}else if(i==="MINT-SELECT")try{(n=e.setValue)==null||n.call(e,"")}catch{}else if(i==="MINT-DROPZONE"){const r=e.querySelector('input[type="file"]');r&&(r.value="")}else if(i==="MINT-CHECKBOX"||i==="MINT-SWITCH")try{if(typeof e.checked<"u")e.checked=!1;else{e.removeAttribute("checked");const r=e.querySelector('input[type="checkbox"], input[type="radio"]');r&&(r.checked=!1)}}catch{}else if(i==="MINT-CHOICE")try{typeof e.setValue=="function"?e.setValue(""):e.querySelectorAll("mint-choice-option").forEach(a=>{a.checked=!1})}catch{}else if(i==="MINT-TAGS")try{e.tags=[]}catch{}})}_resolveHost(t){if(t.tagName==="MINT-CHOICE-OPTION"){const i=t.closest("mint-choice");if(i)return i}const e=t.closest("mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags");return e||t}_setupBlurValidation(){if(!this._form)return;const t=i=>{const s=i.target;if(!s)return;const n=this._findFieldElement(s);if(!n)return;const r=this._getFieldName(n);if(!r||!this._collectValidationRules()[r])return;const l=this._extractFieldValue([n]),o=l!=null&&(typeof l=="string"?l.trim()!=="":l instanceof FileList||Array.isArray(l)?l.length>0:!0),c=n.hasAttribute("data-mint-form-error")||s instanceof HTMLElement&&(s.hasAttribute("aria-invalid")||s.closest("[data-mint-form-error]")),h=!!n.closest("mint-tags"),p=n.tagName==="MINT-CHECKBOX"||n.tagName==="MINT-SWITCH"||n.tagName==="MINT-CHOICE"||s instanceof HTMLElement&&(s.closest("mint-checkbox, mint-switch, mint-choice")||s.closest("mint-choice-option")),d=n.tagName==="MINT-DATE-PICKER"||s instanceof HTMLElement&&s.closest("mint-date-picker");(o||c||h||p||d)&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener("blur",t,!0),this._fieldBlurHandlers.set(this._form,t);const e=i=>{const s=i.target;if(!s)return;if(i.type==="tags-change"&&s.tagName==="MINT-TAGS"){const c=s,h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}if(s instanceof HTMLSelectElement||s.tagName==="MINT-SELECT"||s.closest("mint-select")){const c=this._findFieldElement(s);if(!c)return;const h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}if(i.type==="choice-change"&&s.tagName==="MINT-CHOICE"){const c=s,h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}if(s instanceof HTMLInputElement&&s.type==="checkbox"||s.tagName==="MINT-CHECKBOX"||s.tagName==="MINT-SWITCH"||s.closest("mint-checkbox, mint-switch")){const c=this._findFieldElement(s);if(!c)return;const h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}const a=this._findFieldElement(s);if(!a)return;const l=this._getFieldName(a);!l||!this._collectValidationRules()[l]||(a.hasAttribute("data-mint-form-error")||s instanceof HTMLElement&&s.hasAttribute("aria-invalid"))&&setTimeout(()=>{this._validateField(l)},0)};this._form.addEventListener("change",e,!0),this._form.addEventListener("tags-change",e,!0),this._form.addEventListener("choice-change",e,!0),this._fieldChangeHandlers.set(this._form,e)}_findFieldElement(t){if(t.hasAttribute("name")&&(t.tagName.startsWith("MINT-")||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement))return t;const e=t.closest("mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags");if(e&&e.hasAttribute("name"))return e;if((t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&t.hasAttribute("name"))return t;let i=t;for(;i&&i!==this._form;){if(i.hasAttribute("name"))return i;i=i.parentElement}return null}_getFieldName(t){return t.hasAttribute("name")||t.tagName.startsWith("MINT-")?t.getAttribute("name"):(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&t.name||null}_cleanupBlurValidation(){if(this._form&&this._fieldBlurHandlers.has(this._form)){const t=this._fieldBlurHandlers.get(this._form);t&&this._form.removeEventListener("blur",t,!0),this._fieldBlurHandlers.delete(this._form)}if(this._form&&this._fieldChangeHandlers.has(this._form)){const t=this._fieldChangeHandlers.get(this._form);t&&(this._form.removeEventListener("change",t,!0),this._form.removeEventListener("tags-change",t,!0),this._form.removeEventListener("choice-change",t,!0)),this._fieldChangeHandlers.delete(this._form)}this._observer&&(this._observer.disconnect(),this._observer=null)}_syncDropzoneFiles(){if(!this._form)return;Array.from(this._form.querySelectorAll("mint-dropzone[name]")).forEach(e=>{typeof e.syncFiles=="function"&&e.syncFiles()})}_propagateLoadingState(){if(!this._form)return;const t=this.getAttribute("loading"),e=t!==null&&t!=="false";Array.from(this._form.querySelectorAll("mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags")).forEach(s=>{e?s.setAttribute("loading","true"):s.removeAttribute("loading"),typeof s.render=="function"&&s.render()})}_setButtonsSubmitting(){if(!this._form)return;this._buttonStates.clear();const t=Array.from(this.querySelectorAll("mint-button")),e=Array.from(this.querySelectorAll("button"));t.forEach(i=>{const s=i.getAttribute("disabled")==="true",n=i.getAttribute("loading")==="true";this._buttonStates.set(i,{disabled:s,loading:n});const a=(i.getAttribute("type")||i.getAttribute("button-type")||"default")==="submit";s||i.setAttribute("disabled","true"),a&&i.setAttribute("loading","true"),typeof i.render=="function"&&i.render()}),e.forEach(i=>{if(i.closest("mint-button"))return;const s=i.disabled;this._buttonStates.set(i,{disabled:s,loading:!1}),s||(i.disabled=!0)})}_restoreButtonsState(){if(!this._form)return;const t=Array.from(this.querySelectorAll("mint-button")),e=Array.from(this.querySelectorAll("button"));t.forEach(i=>{const s=this._buttonStates.get(i);s&&(s.disabled?i.setAttribute("disabled","true"):i.removeAttribute("disabled"),s.loading?i.setAttribute("loading","true"):i.removeAttribute("loading"),typeof i.render=="function"&&i.render())}),e.forEach(i=>{if(i.closest("mint-button"))return;const s=this._buttonStates.get(i);s&&(i.disabled=s.disabled)}),this._buttonStates.clear()}_isReactiveObject(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;if("__v_isRef"in t||"_value"in t||"__v_raw"in t||"__v_isReactive"in t||"__ob__"in t)return!0;try{const e=t.toString();if(e==="[object Object]"||e.includes("Proxy")){const i=Object.keys(t)[0];if(i){const s=Object.getOwnPropertyDescriptor(t,i);if(s&&(s.get||s.set))return!0}}}catch{return!0}return!0}_createDataSnapshot(t){try{const e=this._extractReactiveData(t);return JSON.parse(JSON.stringify(e))}catch{return{...this._extractReactiveData(t)}}}_extractReactiveData(t){if(!t||typeof t!="object")return t;if(Array.isArray(t))return t.map(i=>this._extractReactiveData(i));const e=this._getReactiveValue(t);if(e&&typeof e=="object"&&!Array.isArray(e)){const i={};for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(i[s]=this._extractReactiveData(e[s]));return i}return e}_hasDataChanged(t,e){try{return JSON.stringify(t)!==JSON.stringify(e)}catch{return!0}}_getReactiveValue(t){if(!t||typeof t!="object")return t;if("_value"in t||"__v_isRef"in t){if(typeof t.value<"u")return t.value;if("_value"in t)return t._value}return"__v_raw"in t||"__v_isReactive"in t||"__ob__"in t,t}_setupReactiveDataObserver(t){if(this._stopReactiveDataObserver(),!this.isConnected)return;const e=this._getReactiveValue(t);if(e&&typeof e=="object"&&!Array.isArray(e))this._lastDataSnapshot=this._createDataSnapshot(e);else{this._lastDataSnapshot=null;return}const i=()=>{if(!this._formData||!this._lastDataSnapshot){this._stopReactiveDataObserver();return}const s=this._getReactiveValue(this._formData);if(s&&typeof s=="object"&&!Array.isArray(s)){const n=this._createDataSnapshot(s);this._hasDataChanged(n,this._lastDataSnapshot)&&(this._lastDataSnapshot=n,requestAnimationFrame(()=>{this._applyFormData()}))}this.isConnected&&this._formData?this._reactiveDataObserver=requestAnimationFrame(i):this._stopReactiveDataObserver()};this._reactiveDataObserver=requestAnimationFrame(i)}_stopReactiveDataObserver(){this._reactiveDataObserver!==null&&(cancelAnimationFrame(this._reactiveDataObserver),this._reactiveDataObserver=null),this._reactiveDataProxy=null,this._lastDataSnapshot=null}}customElements.get("mint-form")||customElements.define("mint-form",kt);typeof window<"u"&&(window.mintForm=window.mintForm||{defaults:{headers:{common:{}}},interceptors:{response:{handlers:[]}}},window.mintForm.interceptors.response.use||(window.mintForm.interceptors.response.use=function(T,t){return window.mintForm.interceptors.response.handlers.push({fulfilled:T,rejected:t}),window.mintForm.interceptors.response.handlers.length-1}));class xt extends HTMLElement{constructor(){super(...arguments),this._observer=null}static get observedAttributes(){return["collapse","scroll"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","align-baseline","block","w-full","overflow-x-auto"),this.hasAttribute("collapse")&&!this.hasAttribute("scroll")&&this._ensureResponsiveStyles(),this._observeChanges(),this._applyStyles(),requestAnimationFrame(()=>{this._applyStyles(),setTimeout(()=>this._applyStyles(),0)})}disconnectedCallback(){this._observer&&(this._observer.disconnect(),this._observer=null)}attributeChangedCallback(){this.hasAttribute("collapse")&&!this.hasAttribute("scroll")&&this._ensureResponsiveStyles(),this._applyStyles()}_observeChanges(){this._observer=new MutationObserver(()=>this._applyStyles()),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!1})}_applyStyles(){this._observer&&this._observer.disconnect();const t=this.querySelector("table");if(!t){this._observer&&this._observeChanges();return}const e=this.hasAttribute("collapse")&&!this.hasAttribute("scroll"),i=this.hasAttribute("scroll");i?this.classList.add("relative"):this.classList.remove("relative");const s=[],n=t.querySelector("thead tr");n&&n.querySelectorAll("th").forEach(c=>s.push((c.textContent||"").trim())),this._setClasses(t,["w-full",i?"min-w-[1200px]":"","border-collapse","text-sm","font-medium","overflow-hidden"]);const r=t.querySelector("thead");if(r){this._setClasses(r,["bg-[#F7F7F7]","dark:bg-gray-800"]);const o=r.querySelectorAll("th");o.forEach((c,h)=>{const p=c.querySelector("mint-icon"),d=(p==null?void 0:p.getAttribute("name"))||"",u=p!==null&&d!=="ellipsis";this._setClasses(c,["text-left","font-semibold","text-gray-900","dark:text-white","px-3","py-2","border-b","border-gray-200","dark:border-gray-700"]),u&&c.classList.add("cursor-pointer","bg-[#F7F7F7]","dark:bg-gray-800","hover:bg-gray-100","dark:hover:bg-gray-700","transition-colors"),h===0&&c.classList.add("pl-6"),h===o.length-1&&c.classList.add("pr-6")})}const a=t.querySelector("tbody");if(a){const o=Array.from(a.querySelectorAll("tr"));o.forEach((c,h)=>{const p=c.hasAttribute("data-row-clickable");this._setClasses(c,["bg-white","dark:bg-gray-900","border-b","border-gray-200","dark:border-gray-700"]),p&&c.classList.add("cursor-pointer","hover:bg-gray-50","dark:hover:bg-gray-800","transition-colors"),h===o.length-1&&c.classList.remove("border-b");const d=c.querySelectorAll("td");d.forEach((u,f)=>{this._setClasses(u,["text-gray-900","dark:text-gray-100","px-3","py-2"]),f===0&&u.classList.add("pl-6"),f===d.length-1&&u.classList.add("pr-6"),e?this._applyMobileCell(u,s):this._restoreCell(u)})})}const l=t.querySelector("tfoot");l&&(this._setClasses(l,["bg-[#F7F7F7]","dark:bg-gray-800","font-semibold"]),l.querySelectorAll("td").forEach(c=>{this._setClasses(c,["text-gray-900","dark:text-gray-100","px-3","py-2","border-t","border-gray-200","dark:border-gray-700"]),this._restoreCell(c)})),this._observer&&this._observeChanges()}_applyMobileCell(t,e){if(t.closest("tfoot")||t.dataset.mtProcessed==="true")return;const i=e[t.cellIndex]||"",s={};Array.from(t.attributes).forEach(o=>{o.name.startsWith("data-")&&o.name!=="data-original"&&o.name!=="data-mt-processed"&&(s[o.name]=o.value)});const n=t.getAttribute("data-original"),r=n!==null?n:t.innerHTML;t.setAttribute("data-original",r),t.dataset.mtProcessed="true",t.innerHTML="";const a=document.createElement("span");a.className="mt-label font-semibold text-gray-700 dark:text-gray-200 hidden",a.textContent=i;const l=document.createElement("span");l.className="mt-value text-gray-900 dark:text-gray-100 text-right md:text-left w-full",l.innerHTML=r,t.appendChild(a),t.appendChild(l),Object.entries(s).forEach(([o,c])=>{t.setAttribute(o,c)})}_restoreCell(t){if(t.dataset.mtProcessed!=="true")return;const e={};Array.from(t.attributes).forEach(s=>{s.name.startsWith("data-")&&s.name!=="data-original"&&s.name!=="data-mt-processed"&&(e[s.name]=s.value)});const i=t.getAttribute("data-original")||"";t.dataset.mtProcessed="",t.innerHTML=i,Object.entries(e).forEach(([s,n])=>{t.setAttribute(s,n)})}_setClasses(t,e){t.className="",e.filter(Boolean).forEach(i=>t.classList.add(...i.split(" ")))}_ensureResponsiveStyles(){if(document.getElementById("mint-table-responsive-style"))return;const t=document.createElement("style");t.id="mint-table-responsive-style",t.textContent=`
|
|
89
|
+
`,I.classList.add("mint-date-shortcuts-row"),document.head.querySelector("style[data-mint-date-shortcuts]")||(F.setAttribute("data-mint-date-shortcuts","true"),document.head.appendChild(F));const V=document.createElement("div");V.className="absolute left-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-r from-white dark:from-gray-800 to-transparent opacity-0 transition-opacity duration-200 md:hidden",L.appendChild(V);const P=document.createElement("div");P.className="absolute right-0 top-0 bottom-0 w-8 pointer-events-none z-10 bg-gradient-to-l from-white dark:from-gray-800 to-transparent opacity-100 transition-opacity duration-200 md:hidden",L.appendChild(P);const R=document.createElement("div");R.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-gray-800 to-transparent opacity-0 transition-opacity duration-200",L.appendChild(R);const q=document.createElement("div");q.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-gray-800 to-transparent opacity-100 transition-opacity duration-200",L.appendChild(q);const z=()=>{if(window.innerWidth>=768){const B=I.scrollTop,O=I.scrollHeight,W=I.clientHeight;B>0?R.style.opacity="1":R.style.opacity="0",B+W<O-1?q.style.opacity="1":q.style.opacity="0",V.style.opacity="0",P.style.opacity="0"}else{const B=I.scrollLeft,O=I.scrollWidth,W=I.clientWidth;B>0?V.style.opacity="1":V.style.opacity="0",B+W<O-1?P.style.opacity="1":P.style.opacity="0",R.style.opacity="0",q.style.opacity="0"}};I.addEventListener("scroll",z),window.addEventListener("resize",z),setTimeout(z,0),a.forEach(X=>{const B=document.createElement("button");B.type="button",B.tabIndex=0,B.className="px-3 py-1.5 text-xs font-medium rounded-md bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors 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",B.textContent=X.label,B.setAttribute("data-keep-popover-open","true"),B.addEventListener("click",()=>{const O=X.action();if(O){if(this._isRange&&"start"in O&&"end"in O){this._selectedStartDate=O.start,this._selectedEndDate=O.end;const W=this.getFormat(),j=this._formatDate(O.start,W),U=this._formatDate(O.end,W),Y=`${j} - ${U}`;this.setValue(Y),this._currentMonth=O.start.getMonth(),this._currentYear=O.start.getFullYear()}else if(O instanceof Date){this._selectedStartDate=O,this._selectedEndDate=null;const W=this.getFormat(),j=this._formatDate(O,W);this.setValue(j),this._currentMonth=O.getMonth(),this._currentYear=O.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}))}}),I.appendChild(B)}),L.appendChild(I),k.appendChild(L),o.appendChild(k)}c.appendChild(h),c.appendChild(v),c.appendChild(b),o.appendChild(c),this._calendarContainer.appendChild(o)}_buildMonthView(){if(!this._calendarContainer)return;const t=["January","February","March","April","May","June","July","August","September","October","November","December"],e=document.createElement("div");e.className="flex items-center justify-between mb-4";const i=document.createElement("button");i.type="button",i.tabIndex=0,i.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",i.setAttribute("data-keep-popover-open","true");const s=document.createElement("mint-icon");s.setAttribute("name","caret-left"),s.className="w-4 h-4",i.appendChild(s),i.addEventListener("click",()=>{const o=this._currentMonth,c=this._currentYear;this._currentYear--,this._buildCalendar(),this._dispatchMonthChangeEvent(o,c,this._currentMonth,this._currentYear)}),e.appendChild(i);const n=document.createElement("button");n.type="button",n.tabIndex=0,n.className="text-sm font-medium text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-300 cursor-pointer transition-colors 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",n.setAttribute("data-keep-popover-open","true"),n.textContent=String(this._currentYear),n.addEventListener("click",()=>{this.getMode()!=="year"&&(this._viewMode="year",this._buildCalendar())}),e.appendChild(n);const r=document.createElement("button");r.type="button",r.tabIndex=0,r.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors 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");const a=document.createElement("mint-icon");a.setAttribute("name","caret-right"),a.className="w-4 h-4",r.appendChild(a),r.addEventListener("click",()=>{const o=this._currentMonth,c=this._currentYear;this._currentYear++,this._buildCalendar(),this._dispatchMonthChangeEvent(o,c,this._currentMonth,this._currentYear)}),e.appendChild(r);const l=document.createElement("div");l.className="grid grid-cols-3 gap-2",t.forEach((o,c)=>{const h=document.createElement("button");h.type="button",h.tabIndex=0,h.setAttribute("data-keep-popover-open","true");const f=this._currentMonth===c;h.className=`p-2 rounded text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${f?"bg-slate-800 dark:bg-slate-600 text-white":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"}`,h.textContent=o,h.addEventListener("click",()=>{if(this.getMode()==="month"){const p=new Date(this._currentYear,c,1),u=this.getFormat(),_=this._formatDate(p,u);this.setValue(_),this._selectedStartDate=p,this._selectedEndDate=null;const g=this._currentMonth,m=this._currentYear;this._currentMonth=c,this._dispatchMonthChangeEvent(g,m,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{const p=this._currentMonth,u=this._currentYear;this._currentMonth=c,this._viewMode="calendar",this._buildCalendar(),this._dispatchMonthChangeEvent(p,u,this._currentMonth,this._currentYear)}}),l.appendChild(h)}),this._calendarContainer.appendChild(e),this._calendarContainer.appendChild(l)}_buildYearView(){if(!this._calendarContainer)return;const t=this._currentYear-6,e=this._currentYear+6,i=document.createElement("div");i.className="flex items-center justify-between mb-4";const s=document.createElement("button");s.type="button",s.tabIndex=0,s.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors 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");const n=document.createElement("mint-icon");n.setAttribute("name","caret-left"),n.className="w-4 h-4",s.appendChild(n),s.addEventListener("click",()=>{const c=this._currentMonth,h=this._currentYear;this._currentYear-=12,this._buildCalendar(),this._dispatchMonthChangeEvent(c,h,this._currentMonth,this._currentYear)}),i.appendChild(s);const r=document.createElement("div");r.className="text-sm font-medium text-gray-900 dark:text-gray-100",r.textContent=`${t} - ${e}`,i.appendChild(r);const a=document.createElement("button");a.type="button",a.tabIndex=0,a.className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-600 dark:text-gray-300 transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500",a.setAttribute("data-keep-popover-open","true");const l=document.createElement("mint-icon");l.setAttribute("name","caret-right"),l.className="w-4 h-4",a.appendChild(l),a.addEventListener("click",()=>{const c=this._currentMonth,h=this._currentYear;this._currentYear+=12,this._buildCalendar(),this._dispatchMonthChangeEvent(c,h,this._currentMonth,this._currentYear)}),i.appendChild(a);const o=document.createElement("div");o.className="grid grid-cols-3 gap-2";for(let c=t;c<=e;c++){const h=document.createElement("button");h.type="button",h.tabIndex=0,h.setAttribute("data-keep-popover-open","true");const f=this._currentYear===c;h.className=`p-2 rounded text-sm font-medium transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500 ${f?"bg-slate-800 dark:bg-slate-600 text-white":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700"}`,h.textContent=String(c),h.addEventListener("click",()=>{const d=this.getMode();if(d==="year"){const p=new Date(c,0,1),u=this.getFormat(),_=this._formatDate(p,u);this.setValue(_),this._selectedStartDate=p,this._selectedEndDate=null;const g=this._currentMonth,m=this._currentYear;this._currentYear=c,this._currentMonth=0,this._dispatchMonthChangeEvent(g,m,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(d==="month"){const p=this._currentMonth,u=this._currentYear;this._currentYear=c,this._viewMode="month",this._buildCalendar(),this._dispatchMonthChangeEvent(p,u,this._currentMonth,this._currentYear)}else{const p=this._currentMonth,u=this._currentYear;this._currentYear=c,this._viewMode="calendar",this._buildCalendar(),this._dispatchMonthChangeEvent(p,u,this._currentMonth,this._currentYear)}}),o.appendChild(h)}this._calendarContainer.appendChild(i),this._calendarContainer.appendChild(o)}_getDaysInMonth(t,e){return new Date(e,t+1,0).getDate()}_getFirstDayOfMonth(t,e){const i=this.getWeekStartDay(),s=new Date(e,t,1).getDay();return s>=i?s-i:7-(i-s)}_isToday(t){const e=new Date;return t.getDate()===e.getDate()&&t.getMonth()===e.getMonth()&&t.getFullYear()===e.getFullYear()}_isDateSelected(t){const e=this.getSelectionMode();return this._isRange||e==="week"||e==="month"?this._selectedStartDate&&this._selectedEndDate?this._isSameDate(t,this._selectedStartDate)||this._isSameDate(t,this._selectedEndDate):this._isRange&&this._selectedStartDate&&!this._selectedEndDate?this._isSameDate(t,this._selectedStartDate):!1:this._selectedStartDate!==null&&this._isSameDate(t,this._selectedStartDate)}_isDateInRange(t){const e=this.getSelectionMode();if((this._isRange||e==="week"||e==="month")&&this._selectedStartDate&&this._selectedEndDate)return this._rangeIncludesDisabledDates(this._selectedStartDate,this._selectedEndDate)?!1:t>=this._selectedStartDate&&t<=this._selectedEndDate;if(this._isRange&&this._selectedStartDate&&!this._selectedEndDate&&this._hoveredDate){const i=this._selectedStartDate<this._hoveredDate?this._selectedStartDate:this._hoveredDate,s=this._selectedStartDate<this._hoveredDate?this._hoveredDate:this._selectedStartDate;if(this._rangeIncludesDisabledDates(i,s)){const n=this._findFirstDisabledDateInRange(i,s);return n?this._selectedStartDate<this._hoveredDate?t>=i&&t<n&&!this._isSameDate(t,i):t>n&&t<=s&&!this._isSameDate(t,s):!1}return t>=i&&t<=s&&!this._isSameDate(t,i)&&!this._isSameDate(t,s)}return!1}_rangeIncludesDisabledDates(t,e){const i=this.getDisabledDates(),s=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=new Date(e.getFullYear(),e.getMonth(),e.getDate());return i.some(r=>{const a=new Date(r.getFullYear(),r.getMonth(),r.getDate());return a>=s&&a<=n})}_findFirstDisabledDateInRange(t,e){const i=this.getDisabledDates(),s=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=i.map(a=>new Date(a.getFullYear(),a.getMonth(),a.getDate())).filter(a=>a>=s&&a<=n).sort((a,l)=>a.getTime()-l.getTime());return r.length>0?r[0]:null}_hasIncompleteRange(){return this._isRange&&this._selectedStartDate!==null&&this._selectedEndDate===null}_isSameDate(t,e){return t.getDate()===e.getDate()&&t.getMonth()===e.getMonth()&&t.getFullYear()===e.getFullYear()}_isDateDisabled(t){return this.getDisabledDates().some(i=>this._isSameDate(t,i))}_dispatchMonthChangeEvent(t,e,i,s){(t!==i||e!==s)&&this.dispatchEvent(new CustomEvent("month-change",{detail:{month:i,year:s,oldMonth:t,oldYear:e},bubbles:!0,cancelable:!0,composed:!0}))}_dispatchDateChangeEvent(){const t=this.getFormat(),i={value:this.getValue()};this._selectedStartDate&&(i.startDate=this._selectedStartDate,i.startDateFormatted=this._formatDate(this._selectedStartDate,t)),this._selectedEndDate&&(i.endDate=this._selectedEndDate,i.endDateFormatted=this._formatDate(this._selectedEndDate,t)),this.dispatchEvent(new CustomEvent("date-change",{detail:i,bubbles:!0,cancelable:!0,composed:!0}))}_setupContainerObserver(){if(this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),!this._inputsWrapperEl)return;const t=400,e=s=>{this._inputsWrapperEl&&(s<t?(this._inputsWrapperEl.classList.add("flex-wrap"),this._inputsWrapperEl.classList.remove("flex-nowrap")):(this._inputsWrapperEl.classList.remove("flex-wrap"),this._inputsWrapperEl.classList.add("flex-nowrap")))},i=this._inputsWrapperEl.offsetWidth||this.offsetWidth;e(i),this._resizeObserver=new ResizeObserver(s=>{for(const n of s){const r=n.contentRect.width;e(r)}}),this._resizeObserver.observe(this)}_getWeekStart(t){const e=this.getWeekStartDay(),i=t.getDay();let s;i>=e?s=i-e:s=7-(e-i);const n=new Date(t);return n.setDate(t.getDate()-s),n.setHours(0,0,0,0),n}_getWeekEnd(t){const e=this._getWeekStart(t),i=new Date(e);return i.setDate(e.getDate()+6),i.setHours(23,59,59,999),i}_getMonthStart(t){const e=new Date(t.getFullYear(),t.getMonth(),1);return e.setHours(0,0,0,0),e}_getMonthEnd(t){const e=new Date(t.getFullYear(),t.getMonth()+1,0);return e.setHours(23,59,59,999),e}_handleDateClick(t){this._isHandlingClick=!0;try{const e=this.getFormat(),i=this.getSelectionMode();let s,n;if(i==="week"?(s=this._getWeekStart(t),n=this._getWeekEnd(t)):i==="month"?(s=this._getMonthStart(t),n=this._getMonthEnd(t)):(s=t,n=t),this.isRange()||i==="week"||i==="month")if(i==="week"||i==="month"){if(this._rangeIncludesDisabledDates(s,n)){this._buildCalendar();return}this._selectedStartDate=s,this._selectedEndDate=n;const l=this._formatDate(this._selectedStartDate,e),o=this._formatDate(this._selectedEndDate,e),c=`${l} - ${o}`;this.setValue(c),this._textInput&&(this._textInput.value=c),this._popover&&typeof this._popover.close=="function"&&this._popover.close()}else if(this._hoveredDate=null,this._selectedStartDate===null){if(this._isDateDisabled(s)){this._buildCalendar();return}this._selectedStartDate=new Date(s.getFullYear(),s.getMonth(),s.getDate()),this._selectedEndDate=null,this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear(),this._hoveredDate=null,this._buildCalendar()}else if(this._selectedEndDate===null){const l=new Date(t.getFullYear(),t.getMonth(),t.getDate()),o=this._selectedStartDate?new Date(this._selectedStartDate.getFullYear(),this._selectedStartDate.getMonth(),this._selectedStartDate.getDate()):null;let c,h;if(o&&l<o?(c=l,h=o):(c=o,h=l),this._rangeIncludesDisabledDates(c,h)){this._buildCalendar();return}o&&l<o?(this._selectedEndDate=o,this._selectedStartDate=l):(this._selectedEndDate=l,o&&(this._selectedStartDate=o)),this._currentMonth=this._selectedStartDate.getMonth(),this._currentYear=this._selectedStartDate.getFullYear();const f=this._formatDate(this._selectedStartDate,e),d=this._formatDate(this._selectedEndDate,e),p=`${f} - ${d}`;this.setAttribute("value",p),this._textInput&&(this._textInput.value=p),this._hiddenInput&&(this._hiddenInput.value=p),this._updateDisplayText(),this._buildCalendar(),this._popover&&typeof this._popover.close=="function"&&this._popover.close()}else this._selectedStartDate=s,this._selectedEndDate=null;else{this._selectedStartDate=s,this._selectedEndDate=null;const l=this._formatDate(s,e);this.setValue(l),this._textInput&&(this._textInput.value=l),this._popover&&typeof this._popover.close=="function"&&this._popover.close()}this._buildCalendar(),this._updateDisplayText(),this._exitInputMode();const 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;const t=this.getDisplayFormat(),e=this.getSelectionMode(),i=this._isRange||e==="week"||e==="month";let s="";i?this._selectedStartDate&&this._selectedEndDate?s=`${this._formatDatePhp(this._selectedStartDate,t)} - ${this._formatDatePhp(this._selectedEndDate,t)}`:this._selectedStartDate&&(s=this._formatDatePhp(this._selectedStartDate,t)):this._selectedStartDate&&(s=this._formatDatePhp(this._selectedStartDate,t)),s?(this._displayEl.textContent=s,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)){const t=this._startPartInputs[0];requestAnimationFrame(()=>{t.focus();try{t.setSelectionRange(0,t.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(t){let e=this.querySelector(".mint-date-picker-skeleton-container");const i=this._fieldsContainer,s=this._input;if(t){e||(e=document.createElement("div"),e.className="mint-date-picker-skeleton-container absolute inset-0 z-10 pointer-events-none",s?(s.classList.contains("relative")||s.classList.add("relative"),s.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let n=e.querySelector(".mint-date-picker-skeleton");n||(n=document.createElement("div"),n.className="mint-date-picker-skeleton w-full rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse",n.style.height="2.25rem",e.appendChild(n)),e.style.display="block",i&&(i.style.visibility="hidden",i.style.pointerEvents="none"),this._displayEl&&(this._displayEl.style.visibility="hidden",this._displayEl.style.pointerEvents="none")}else e&&(e.style.display="none"),i&&(i.style.visibility="visible",i.style.pointerEvents="auto"),this._displayEl&&(this._displayEl.style.visibility="visible",this._displayEl.style.pointerEvents="auto")}_getFocusableElements(){if(!this._calendarContainer)return[];const t=["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(t)).filter(i=>{const s=window.getComputedStyle(i);return s.display!=="none"&&s.visibility!=="hidden"})}_setupFocusTrap(){if(!this._popover||!this._popover.hasAttribute("open"))return;this._removeFocusTrap();const t=this;this._focusTrapHandler=function(e){var l;if(e.key!=="Tab")return;if(!t._popover||!t._popover.hasAttribute("open")){t._removeFocusTrap();return}const i=t._getFocusableElements();if(i.length===0)return;const s=i[0],n=i[i.length-1],r=document.activeElement;if(!(((l=t._calendarContainer)==null?void 0:l.contains(r))||!1)){e.preventDefault(),s.focus();return}if(e.shiftKey&&r===s){e.preventDefault(),n.focus();return}if(!e.shiftKey&&r===n){e.preventDefault(),s.focus();return}},this._escapeHandler=function(e){(e.key==="Escape"||e.key==="Esc")&&t._popover&&t._popover.hasAttribute("open")&&(e.preventDefault(),e.stopPropagation(),typeof t._popover.close=="function"&&t._popover.close())},document.addEventListener("keydown",this._focusTrapHandler,!0),document.addEventListener("keydown",this._escapeHandler,!0),requestAnimationFrame(()=>{const e=this._getFocusableElements();e.length>0&&e[0].focus()})}_removeFocusTrap(){this._focusTrapHandler&&(document.removeEventListener("keydown",this._focusTrapHandler,!0),this._focusTrapHandler=null),this._escapeHandler&&(document.removeEventListener("keydown",this._escapeHandler,!0),this._escapeHandler=null)}}customElements.get("mint-date-picker")||customElements.define("mint-date-picker",bt);class vt extends HTMLElement{constructor(){super(),this._select=null,this._wrapper=null,this._caretUpIcon=null,this._caretDownIcon=null,this._changeHandler=null,this._optionObserver=null,this._childrenObserver=null}static get observedAttributes(){return["name","value","disabled","id","required","label","info","error","error-message","multiple","loading"]}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(s=>{const n=Array.from(s.addedNodes).some(a=>a.nodeType===Node.ELEMENT_NODE&&(a.tagName==="OPTION"||a.tagName==="OPTGROUP"))||Array.from(s.removedNodes).some(a=>a.nodeType===Node.ELEMENT_NODE&&(a.tagName==="OPTION"||a.tagName==="OPTGROUP")),r=s.type==="attributes"&&s.target.nodeType===Node.ELEMENT_NODE&&(s.target.tagName==="OPTION"||s.target.tagName==="OPTGROUP");return n||r})&&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(),this._optionObserver=null),this._childrenObserver&&(this._childrenObserver.disconnect(),this._childrenObserver=null)}isLoading(){return this.getAttribute("loading")==="true"}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){this._renderErrorState(),this._select&&(this._select.className=this.getSelectClasses(),this._select.setAttribute("aria-invalid",this.hasError()?"true":"false"));return}if(t==="loading"){this.render();return}if(t==="value"){this._select&&(this._select.value=i||"");return}this.render()}}getName(){return this.getAttribute("name")||""}getValue(){return this.hasAttribute("value")?this.getAttribute("value")||"":this._select?this._select.value:""}setValue(t){const e=t||"";this.setAttribute("value",e),this._select&&(this._select.value=e)}get value(){try{return this.getValue()||""}catch{return""}}set value(t){try{const e=t||"";(this.getAttribute("value")||"")!==e&&this.setAttribute("value",e),this._select&&requestAnimationFrame(()=>{this._select&&(e===""||Array.from(this._select.options).some(n=>n.value===e))&&this._select.value!==e&&(this._select.value=e)})}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(){const t=this.hasError(),e=this.isMultiple(),i=["w-full","px-3.5",e?"pr-3.5":"pr-10",e?"py-2":"py-1.5",e?"min-h-[6rem]":"min-h-[2rem]","text-sm","font-medium","rounded-lg","box-border","bg-white","dark:bg-gray-900","text-gray-900","dark:text-white","transition-all","duration-200","outline-none","focus:outline-none","disabled:opacity-40","disabled:cursor-not-allowed","appearance-none","bg-no-repeat","bg-right","cursor-pointer"],s=["border-2",t?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700"],n=["focus-visible:ring-2","focus-visible:ring-offset-1",t?"focus-visible:ring-red-400 dark:focus-visible:ring-red-500":"focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500"];return[...i,...s,...n].filter(Boolean).join(" ")}render(){const t=this.isLoading(),e=[];this._select&&Array.from(this._select.children).forEach(d=>{(d.tagName==="OPTION"||d.tagName==="OPTGROUP")&&e.push(d.cloneNode(!0))});const i=Array.from(this.children).filter(d=>d.tagName==="OPTION"||d.tagName==="OPTGROUP").map(d=>d.cloneNode(!0));for(;this.firstChild;)this.removeChild(this.firstChild);this._wrapper=null,this._select=null;const s=this.getLabel(),n=this.getInfo(),r=this.getId(),a=this.getName(),l=this.getValue(),o=this.isDisabled(),c=this.isMultiple(),h=this.hasError();if(s){const d=document.createElement("label");d.className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",r&&d.setAttribute("for",r);const p=document.createTextNode(s);d.appendChild(p),this.appendChild(d)}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(),r&&(this._select.id=r),a&&(this._select.name=a),o&&(this._select.disabled=!0),c&&(this._select.multiple=!0),this._select.setAttribute("aria-invalid",h?"true":"false");const f=i.length>0?i:e;if(f.length>0&&f.forEach(d=>{this._select.appendChild(d)}),this._select.options.length===0){const d=document.createElement("option");d.value="",d.textContent="Select an option",d.disabled=!0,d.selected=!0,this._select.appendChild(d)}if(this._select.value=l||"",this._changeHandler&&this._select&&this._select.removeEventListener("change",this._changeHandler),this._changeHandler=d=>{const u=d.target.value;(this.getAttribute("value")||"")!==u&&(u?this.setAttribute("value",u):this.removeAttribute("value"));const g=new Event("input",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(g),this.dispatchEvent(new CustomEvent("input",{detail:{value:u},bubbles:!0,cancelable:!0,composed:!0})),this.dispatchEvent(new CustomEvent("change",{detail:{value:u},bubbles:!0,cancelable:!0,composed:!0}))},this._select.addEventListener("change",this._changeHandler),this._optionObserver&&this._optionObserver.disconnect(),this._optionObserver=new MutationObserver(()=>{const d=this.getAttribute("value")||this.value||"";this._select&&d&&requestAnimationFrame(()=>{this._select&&Array.from(this._select.options).some(u=>u.value===d)&&this._select.value!==d&&(this._select.value=d)})}),this._optionObserver.observe(this._select,{childList:!0,subtree:!0}),this._wrapper.appendChild(this._select),c)this._caretUpIcon=null,this._caretDownIcon=null;else{const d=document.createElement("div");d.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]",d.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]",d.appendChild(this._caretDownIcon),this._wrapper.appendChild(d)}if(n){const d=document.createElement("div");d.className="mt-1 text-xs text-gray-500 dark:text-gray-400",d.textContent=n,this.appendChild(d)}this._renderErrorState(),this._renderSkeleton(t)}_renderSkeleton(t){let e=this.querySelector(".mint-select-skeleton-container");const i=this._wrapper;if(t){e||(e=document.createElement("div"),e.className="mint-select-skeleton-container absolute inset-0 z-10 pointer-events-none",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-select-skeleton");if(!s){s=document.createElement("div"),s.className="mint-select-skeleton w-full rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse";const n=this.isMultiple();s.style.height=n?"6rem":"2.25rem",e.appendChild(s)}e.style.display="block",this._select&&(this._select.style.opacity="0",this._select.style.pointerEvents="none")}else e&&(e.style.display="none"),this._select&&(this._select.style.opacity="1",this._select.style.pointerEvents="auto")}_renderErrorState(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-select-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-select-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}}customElements.get("mint-select")||customElements.define("mint-select",vt);class yt extends HTMLElement{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}static get observedAttributes(){return["label","accept","multiple","width","height","disabled","name","error","error-message","loading"]}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){const t=this.closest("form");t&&t.removeEventListener("reset",this._resetHandler),this._resetHandler=null}}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){this._updateDragStateClass(),this._renderErrorState(this.hasError(),this.getErrorMessage());return}if(t==="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(t){let e=this.querySelector(".mint-dropzone-skeleton-container");const i=this._dropzone;if(t){e||(e=document.createElement("div"),e.className="mint-dropzone-skeleton-container absolute inset-0 z-10 pointer-events-none flex items-center justify-center",i?(i.classList.contains("relative")||i.classList.add("relative"),i.appendChild(e)):(this.style.position="relative",this.appendChild(e)));let s=e.querySelector(".mint-dropzone-skeleton");if(s||(s=document.createElement("div"),s.className="mint-dropzone-skeleton rounded-lg border-2 border-dashed border-gray-300 dark:border-gray-600 bg-gray-200 dark:bg-gray-700 animate-pulse",s.style.width="100%",s.style.height="100%",e.appendChild(s)),e.style.display="flex",i){const n=i.querySelector(".mint-dropzone-icon"),r=i.querySelector(".mint-dropzone-label"),a=i.querySelector(".mint-dropzone-previews-wrapper"),l=this._fileInput;if(n){const o=n;o.style.visibility="hidden",o.style.pointerEvents="none"}if(r){const o=r;o.style.visibility="hidden",o.style.pointerEvents="none"}if(a){const o=a;o.style.visibility="hidden",o.style.pointerEvents="none"}l&&(l.style.visibility="hidden",l.style.pointerEvents="none"),i.style.pointerEvents="none"}}else if(e&&(e.style.display="none"),i){const s=i.querySelector(".mint-dropzone-icon"),n=i.querySelector(".mint-dropzone-label"),r=i.querySelector(".mint-dropzone-previews-wrapper"),a=this._fileInput;if(s){const l=s;l.style.visibility="visible",l.style.pointerEvents="auto"}if(n){const l=n;l.style.visibility="visible",l.style.pointerEvents="auto"}if(r){const l=r;l.style.visibility="visible",l.style.pointerEvents="auto"}a&&(a.style.visibility="visible",a.style.pointerEvents="auto"),i.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(){const t=this.isLoading(),e=this.getLabel(),i=this.getAccept(),s=this.isMultiple(),n=this.isDisabled(),r=this.getWidth(),a=this.getHeight(),l=this.getName(),o=this.hasError(),c=this.getErrorMessage();this._dropzone||(this._dropzone=document.createElement("div"),this.appendChild(this._dropzone)),this._updateDragStateClass(),this._dropzone.setAttribute("aria-invalid",o?"true":"false"),n?(this._dropzone.setAttribute("tabindex","-1"),this._dropzone.removeAttribute("role")):(this._dropzone.setAttribute("tabindex","0"),this._dropzone.setAttribute("role","button"),this._dropzone.setAttribute("aria-label",e||"File upload dropzone")),this._dropzone.style.width=r,this._dropzone.style.height=a,this._dropzone.style.minWidth=r,this._dropzone.style.minHeight=a,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=i,this._fileInput.multiple=s,this._fileInput.disabled=n,l?this._fileInput.name=l:this._fileInput.removeAttribute("name"),this._fileInput.setAttribute("aria-invalid",o?"true":"false");const h=this._dropzone.querySelector(".mint-dropzone-icon"),f=this._dropzone.querySelector(".mint-dropzone-label");h&&h.remove(),f&&f.remove();const d=document.createElement("div");d.className="mint-dropzone-icon flex items-center justify-center mt-2 mb-2 flex-shrink-0";const p=document.createElement("mint-icon");if(p.setAttribute("name","upload"),p.className="w-12 h-12 text-gray-400 dark:text-gray-500",d.appendChild(p),this._dropzone.appendChild(d),e){const u=document.createElement("div");u.className="mint-dropzone-label text-sm font-medium text-gray-600 dark:text-gray-400 text-center px-4 flex-shrink-0",u.textContent=e,this._dropzone.appendChild(u)}this.setupEventListeners(),this._renderErrorState(o,c),this._renderPreviews(),this._renderSkeleton(t)}_updateDragState(){this._dropzone&&this._updateDragStateClass()}_renderErrorState(t,e){let i=this.querySelector(".mint-dropzone-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-dropzone-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}_updateDragStateClass(){if(!this._dropzone)return;const t=this.isDisabled(),e=this.hasError(),n=`relative border-2 border-dashed rounded-lg transition-all duration-200 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-gray-900 dark:border-gray-700":"border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 dark:border-gray-700 hover:border-gray-400 dark:hover:border-gray-500",a=e?"border-red-300 dark:border-red-300 bg-red-50/50 dark:bg-red-900/30":"",l=t?"opacity-40 cursor-not-allowed":"",o="focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 focus-visible:ring-gray-400 dark:focus-visible:ring-gray-500";this._dropzone.className=`${n} ${e?a:r} ${l} ${o}`.trim()}setupEventListeners(){this._listenersInitialized||(this._listenersInitialized=!0,this.removeEventListeners(),!(!this._dropzone||!this._fileInput||this.isDisabled())&&(this._onDropzoneClick||(this._onDropzoneClick=t=>{if(!(this.isDisabled()||!this._fileInput)&&t.target!==this._fileInput&&(t.stopPropagation(),t.preventDefault(),t.isTrusted))try{this._fileInput.click()}catch(e){console.debug("File chooser blocked:",e)}}),this._onDragOver||(this._onDragOver=t=>{t.preventDefault(),t.stopPropagation(),this.isDisabled()||this._isDragging||(this._isDragging=!0,this._wasDragging=!0,this._updateDragState())}),this._onDragLeave||(this._onDragLeave=t=>{var i;t.preventDefault(),t.stopPropagation();const e=(i=this._dropzone)==null?void 0:i.getBoundingClientRect();e&&(t.clientX<e.left||t.clientX>e.right||t.clientY<e.top||t.clientY>e.bottom)&&this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState())}),this._onDrop||(this._onDrop=t=>{var i;if(t.preventDefault(),t.stopPropagation(),this._isDragging&&(this._isDragging=!1,this._wasDragging=!1,this._updateDragState()),this.isDisabled())return;const e=(i=t.dataTransfer)==null?void 0:i.files;e&&e.length>0&&this._handleFiles(e)}),this._onFileInputInput||(this._onFileInputInput=t=>{t.stopImmediatePropagation(),t.stopPropagation()}),this._onKeyDown||(this._onKeyDown=t=>{if(!(this.isDisabled()||!this._fileInput)&&(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),t.stopPropagation(),t.isTrusted))try{this._fileInput.click()}catch(e){console.debug("File chooser blocked:",e)}}),this._onFocus||(this._onFocus=t=>{this._dropzone&&!this.isDisabled()&&this._dropzone.classList.add("focus-visible:ring-2")}),this._onBlur||(this._onBlur=t=>{this._dropzone}),this._onFileInputChange||(this._onFileInputChange=t=>{if(t.stopImmediatePropagation(),t.stopPropagation(),this._isUpdatingFiles)return;const i=t.target.files;if(i&&i.length>0){const s=this.getAccept(),n=this.isMultiple(),r=[],a=[];for(let l=0;l<i.length;l++){const o=i[l];this._isFileAccepted(o,s)?r.push(o):a.push(o)}if(!n&&r.length>1&&(a.push(...r.slice(1)),r.splice(1)),a.length>0){const l=new CustomEvent("dropRejected",{detail:{files:a,reason:"File type not accepted or multiple files not allowed"},bubbles:!0,cancelable:!0});this.dispatchEvent(l)}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(t){const e=this.getAccept(),i=this.isMultiple(),s=[],n=[];for(let r=0;r<t.length;r++){const a=t[r];this._isFileAccepted(a,e)?s.push(a):n.push(a)}if(!i&&s.length>1&&(n.push(...s.slice(1)),s.splice(1)),n.length>0){const r=new CustomEvent("dropRejected",{detail:{files:n,reason:"File type not accepted or multiple files not allowed"},bubbles:!0,cancelable:!0});this.dispatchEvent(r)}s.length>0&&this._applyValidFiles(s)}_isFileAccepted(t,e){var s;if(!e)return!0;const i=e.split(",").map(n=>n.trim().toLowerCase());for(const n of i)if(n.startsWith(".")){if("."+((s=t.name.split(".").pop())==null?void 0:s.toLowerCase())===n)return!0}else if(n.includes("/*")){const r=n.split("/")[0],a=t.type.split("/")[0];if(r===a)return!0}else if(t.type===n)return!0;return!1}_dispatchEvent(t,e){const i=e.target,s=new CustomEvent(t,{detail:{files:i.files?Array.from(i.files):[],value:i.value||""},bubbles:!0,cancelable:!0});this.dispatchEvent(s)}_dispatchSelectionEvents(){const 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;const t=new DataTransfer;this._selectedFiles.forEach(e=>{try{t.items.add(e)}catch(i){console.warn("Failed to add file to DataTransfer:",i)}}),this._isUpdatingFiles=!0;try{this._fileInput.files=t.files}catch(e){console.warn("Failed to set files on input:",e)}setTimeout(()=>{this._isUpdatingFiles=!1},0)}get files(){var t;return this._syncFileInputFromSelected(),((t=this._fileInput)==null?void 0:t.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}const t=document.createElement("div");t.className="mint-dropzone-previews-wrapper mt-3 w-full relative max-h-48";const e=document.createElement("div");e.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((o,c)=>{const h=document.createElement("div");if(h.className="flex items-center gap-3 p-2 rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900",o.type.startsWith("image/")){const u=document.createElement("img");u.className="w-12 h-12 object-cover rounded border border-gray-200 dark:border-gray-700";const _=URL.createObjectURL(o);this._previewUrls.push(_),u.src=_,h.appendChild(u)}else{const u=document.createElement("mint-icon");u.setAttribute("name","attach"),u.className="w-5 h-5 text-gray-500 dark:text-gray-300",h.appendChild(u)}const f=document.createElement("div");f.className="flex-1 text-sm text-gray-800 dark:text-gray-100 truncate",f.textContent=o.name,h.appendChild(f);const d=document.createElement("button");d.type="button",d.className="text-gray-500 hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors flex items-center justify-center w-6 h-6 rounded-full";const p=document.createElement("mint-icon");p.setAttribute("name","close"),p.className="w-4 h-4",d.appendChild(p),d.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),this._removeFileAt(c)}),h.appendChild(d),e.appendChild(h)});const i=this.hasError(),s=this._isDragging;let n="from-white dark:from-gray-700";i?n="from-red-50 dark:from-red-900/30":s&&(n="from-gray-50 dark:from-gray-800");const r=document.createElement("div");r.className=`absolute top-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-b ${n} to-transparent opacity-0 transition-opacity duration-200`,t.appendChild(r);const a=document.createElement("div");a.className=`absolute bottom-0 left-0 right-0 h-4 pointer-events-none z-10 bg-gradient-to-t ${n} to-transparent opacity-100 transition-opacity duration-200`,t.appendChild(a);const l=()=>{const o=e.scrollTop,c=e.scrollHeight,h=e.clientHeight;o>0?r.style.opacity="1":r.style.opacity="0",o+h<c-1?a.style.opacity="1":a.style.opacity="0"};l(),e.addEventListener("scroll",l),t.appendChild(e),this._previewContainer=t,this._dropzone.appendChild(t),this._updateDragStateClass()}_removeFileAt(t){if(t<0||t>=this._selectedFiles.length)return;const[e]=this._selectedFiles.splice(t,1);e&&this._cleanupPreviewUrls(),this._syncFileInputFromSelected(),this._renderPreviews(),this._dispatchSelectionEvents()}_cleanupPreviewUrls(){this._previewUrls.forEach(t=>URL.revokeObjectURL(t)),this._previewUrls=[]}_attachFormResetListener(){const t=this.closest("form");!t||this._resetHandler||(this._resetHandler=()=>{this._selectedFiles=[],this._syncFileInputFromSelected(),this._renderPreviews(),this._cleanupPreviewUrls()},t.addEventListener("reset",this._resetHandler))}_applyValidFiles(t){if(this.isMultiple()){const i=t.filter(s=>!this._isDuplicateFile(s));this._selectedFiles.push(...i)}else this._selectedFiles=[t[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(t){return this._selectedFiles.some(e=>e.name===t.name&&e.size===t.size&&e.lastModified===t.lastModified)}}customElements.get("mint-dropzone")||customElements.define("mint-dropzone",yt);class kt extends HTMLElement{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._reactiveDataProxy=null,this._reactiveDataObserver=null,this._lastDataSnapshot=null}static get observedAttributes(){return["action","method","enctype","data-form-data","loading","headers"]}connectedCallback(){this._render(),this._ensureSubmitHandler(),this._setupBlurValidation();const t=this.getAttribute("headers");t&&this._parseHeaders(t),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(this._formData)this._isReactiveObject(this._formData)?this._setupReactiveDataObserver(this._formData):this._lastDataSnapshot||(this._lastDataSnapshot=this._createDataSnapshot(this._formData)),this._applyFormData();else{const e=this.getAttribute("data-form-data");e&&(this._parseFormData(e),this._applyFormData())}this._propagateLoadingState()})})}disconnectedCallback(){this._form&&this._submitHandler&&this._form.removeEventListener("submit",this._submitHandler,!0),this._hostSubmitHandler&&this.removeEventListener("submit",this._hostSubmitHandler),this._cleanupBlurValidation(),this._stopReactiveDataObserver()}reset(){this._clearErrors(),this._formData?this._applyFormData():this.clear()}clear(){this._clearErrors(),this._form&&this._form.reset(),this._resetCustomFields()}attributeChangedCallback(t,e,i){t==="form-data"?(this._parseFormData(i),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})):t==="headers"?this._parseHeaders(i):t==="loading"?this.isConnected&&this._form?requestAnimationFrame(()=>{this._propagateLoadingState()}):this._propagateLoadingState():this._applyFormAttributes()}get data(){return this._formData}set data(t){this._stopReactiveDataObserver(),this._reactiveDataProxy=null,this._lastDataSnapshot=null,t&&typeof t=="object"&&!Array.isArray(t)?(this._formData=t,this._isReactiveObject(t)?this._setupReactiveDataObserver(t):this._lastDataSnapshot=this._createDataSnapshot(t)):t==null?this._formData=null:this._parseFormData(t),this.isConnected&&this._form&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{this._applyFormData()})})})}get headers(){return this._headers}set headers(t){if(t&&typeof t=="object"&&!Array.isArray(t))this._headers=t;else if(t==null)this._headers=null;else if(typeof t=="string")try{this._headers=JSON.parse(t)}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=t=>{t.preventDefault(),t.stopImmediatePropagation(),this._handleSubmit(t)},this._form.addEventListener("submit",this._submitHandler,!0))}_applyFormAttributes(){if(!this._form)return;const t=this.getAttribute("action")||"",e=this.getAttribute("method")||"",i=this.getAttribute("enctype")||"application/x-www-form-urlencoded";t&&(this._form.action=t),e&&(this._form.method=e),this._form.enctype=i}async _handleSubmit(t){var c;if(t.preventDefault(),!this._form)return;this._clearErrors(),this._syncDropzoneFiles();const e=this._collectValidationRules(),i=new FormData(this._form);let s=this._formDataToValues(i);if(this._formData){const h=this._getReactiveValue(this._formData);h&&typeof h=="object"&&!Array.isArray(h)&&(s={...this._extractReactiveData(h),...s})}if(!this._validate(s,e)){this.dispatchEvent(new CustomEvent("invalid",{detail:{errors:this._errors},bubbles:!0,cancelable:!0,composed:!0}));return}const r=new CustomEvent("submit",{detail:{formData:i,values:s,form:this},bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(r),r.form=this;const a=new CustomEvent("mintFormSubmit",{detail:{formData:i,values:s,form:this},bubbles:!0,cancelable:!0,composed:!0});if(a.form=this,this.dispatchEvent(a),r.defaultPrevented||a.defaultPrevented)return;const l=this.getAttribute("action"),o=this.getAttribute("method");if(!(!l||!o)){this._setButtonsSubmitting();try{const h=await this._submitData(i,s);this.dispatchEvent(new CustomEvent("submitsuccess",{detail:h,bubbles:!0,cancelable:!0}))}catch(h){(h==null?void 0:h.status)===422&&((c=h==null?void 0:h.data)!=null&&c.errors)&&this._applyServerErrors(h.data.errors),this.dispatchEvent(new CustomEvent("submiterror",{detail:{error:h},bubbles:!0,cancelable:!0}))}finally{this._restoreButtonsState()}}}async _submitData(t,e){var h,f,d;const i=this.getAttribute("action"),s=this.getAttribute("method"),n=this.getAttribute("enctype")||"application/x-www-form-urlencoded";if(!i)return{status:0,ok:!0,data:{values:e}};const r=Array.from(t.values()).some(p=>p instanceof File);let a=null;const l={};let o=i;if(typeof window<"u"&&((d=(f=(h=window.mintForm)==null?void 0:h.defaults)==null?void 0:f.headers)!=null&&d.common)&&Object.assign(l,window.mintForm.defaults.headers.common),this._headers&&Object.assign(l,this._headers),s==="GET"){const p=new URLSearchParams;t.forEach((u,_)=>{u instanceof File||p.append(_,String(u))}),o+=(i.includes("?")?"&":"?")+p.toString()}else if(n==="multipart/form-data"||r)a=t;else if(n==="application/json")a=JSON.stringify(e),l["Content-Type"]="application/json";else{const p=new URLSearchParams;t.forEach((u,_)=>{u instanceof File||p.append(_,String(u))}),a=p,l["Content-Type"]="application/x-www-form-urlencoded"}if(typeof fetch=="function")try{const p=await fetch(o,{method:s||"POST",body:s==="GET"?null:a,headers:l}),u=await p.text().catch(()=>"");let _=u;try{_=JSON.parse(u)}catch{}if(!p.ok){const m={status:p.status,data:_,response:{status:p.status,data:_}};throw await this._applyErrorInterceptors(m)}const g={status:p.status,ok:p.ok,data:_};return await this._applySuccessInterceptors(g)}catch(p){if(p.response)throw p;const u={status:p.status||0,data:p.data||p.message||"Network error",response:{status:p.status||0,data:p.data||p.message||"Network error"}};throw await this._applyErrorInterceptors(u)}const c=this;return await new Promise(async(p,u)=>{const _=new XMLHttpRequest;_.open(s||"POST",o,!0),Object.entries(l).forEach(([g,m])=>_.setRequestHeader(g,m)),_.onload=async function(){const{status:g,responseText:m}=_;if(g>=200&&g<300){let v=m;try{v=JSON.parse(m)}catch{}try{const b={status:g,ok:!0,data:v},y=await c._applySuccessInterceptors(b);p(y)}catch(b){u(b)}}else{let v=m;try{v=JSON.parse(m)}catch{}try{const b={status:g,data:v,response:{status:g,data:v}},y=await c._applyErrorInterceptors(b);u(y)}catch(b){u(b)}}},_.onerror=async function(){try{const g={status:_.status||0,data:_.responseText||"Network error",response:{status:_.status||0,data:_.responseText||"Network error"}},m=await c._applyErrorInterceptors(g);u(m)}catch(g){u(g)}},_.send(s==="GET"?null:a)})}async _applySuccessInterceptors(t){var s,n,r;if(typeof window>"u"||!((r=(n=(s=window.mintForm)==null?void 0:s.interceptors)==null?void 0:n.response)!=null&&r.handlers))return t;let e=t;const i=window.mintForm.interceptors.response.handlers;for(const a of i)a.fulfilled&&(e=await a.fulfilled(e));return e}async _applyErrorInterceptors(t){var s,n,r;if(typeof window>"u"||!((r=(n=(s=window.mintForm)==null?void 0:s.interceptors)==null?void 0:n.response)!=null&&r.handlers))return Promise.reject(t);let e=t;const i=window.mintForm.interceptors.response.handlers;for(let a=i.length-1;a>=0;a--){const l=i[a];if(l.rejected)try{if(e=await l.rejected(e),e!==void 0)return e}catch(o){e=o}}return Promise.reject(e)}_formDataToValues(t){const e={};return t.forEach((i,s)=>{i instanceof File?(e[s]||(e[s]=[]),e[s].push(i)):s in e?Array.isArray(e[s])?(e[s].length>0&&e[s][0]instanceof File,e[s].push(i)):e[s]=[e[s],i]:e[s]=i}),this._form&&(Array.from(this._form.querySelectorAll("mint-dropzone[name]")).forEach(r=>{const a=r.getAttribute("name");if(a&&typeof r.files<"u"&&r.files){const l=r.files;if(l.length>0){const o=Array.from(l);e[a]&&Array.isArray(e[a])?o.forEach(c=>{e[a].some(f=>f.name===c.name&&f.size===c.size&&f.lastModified===c.lastModified)||e[a].push(c)}):e[a]=o}}}),Array.from(this._form.querySelectorAll('input[type="file"][name]')).forEach(r=>{const a=r.name;if(a&&r.files&&r.files.length>0){const l=Array.from(r.files);e[a]&&Array.isArray(e[a])?l.forEach(o=>{e[a].some(h=>h.name===o.name&&h.size===o.size&&h.lastModified===o.lastModified)||e[a].push(o)}):e[a]=l}}),Array.from(this._form.querySelectorAll("mint-tags[name]")).forEach(r=>{const a=r.getAttribute("name");if(a){let l=[];if(typeof r.tags<"u"?l=r.tags:typeof r.getTags=="function"&&(l=r.getTags()),Array.isArray(l)&&l.length>0){const o=l.map(c=>typeof c=="string"?c:(c==null?void 0:c.value)||(c==null?void 0:c.label)||"").filter(c=>c.trim()!=="");e[a]=o}else e[a]=[]}})),e}_collectValidationRules(){const t={};return this._form&&Array.from(this._form.querySelectorAll("[name][validation]")).forEach(i=>{const s=i.getAttribute("name")||"",n=i.getAttribute("validation");if(!s||!n)return;const r=this._parseRules(n);r.length&&(t[s]=r)}),t}_parseRules(t){if(!t)return[];try{const e=t.replace(/'/g,'"'),i=JSON.parse(e);if(Array.isArray(i))return i.map(s=>String(s))}catch{}return t.split(",").map(e=>e.trim()).filter(Boolean)}_validate(t,e){let i=!0;return this._errors={},Object.entries(e||{}).forEach(([s,n])=>{const r=Array.isArray(n)?n:[n],a=this._getFieldElements(s),l=this._extractFieldValue(a),o=this._validateRules(l,r);o?(i=!1,this._errors[s]=o,this._flagFieldError(a,o)):this._clearFieldError(a)}),i}_validateField(t){const e=this._collectValidationRules();if(!e[t])return;const i=e[t],s=Array.isArray(i)?i:[i],n=this._getFieldElements(t),r=this._extractFieldValue(n),a=this._validateRules(r,s);a?(this._errors[t]=a,this._flagFieldError(n,a)):(this._clearFieldError(n),delete this._errors[t])}_validateRules(t,e){for(const i of e){const[s,n]=i.split(":");switch(s){case"required":{if(t==null||typeof t=="string"&&t.trim()===""||t instanceof FileList&&t.length===0||Array.isArray(t)&&t.length===0)return"This field is required.";break}case"string":{if(typeof t!="string")return"Must be a string.";break}case"email":{if(typeof t=="string"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim()))return"Enter a valid email.";break}case"number":{const r=Number(t);if(Number.isNaN(r))return"Must be a number.";break}case"min":{const r=Number(n);if(Number.isNaN(r))break;if(typeof t=="string"&&t.trim().length<r)return`Must be at least ${r} characters.`;if(Array.isArray(t)&&t.length<r)return`Select at least ${r}.`;if(t instanceof FileList&&t.length<r)return`Upload at least ${r} files.`;if(t!=null&&!Number.isNaN(Number(t))&&Number(t)<r)return`Must be at least ${r}.`;break}case"max":{const r=Number(n);if(Number.isNaN(r))break;if(typeof t=="string"&&t.trim().length>r)return`Must be at most ${r} characters.`;if(Array.isArray(t)&&t.length>r)return`Select no more than ${r}.`;if(t instanceof FileList&&t.length>r)return`Upload no more than ${r} files.`;if(t!=null&&!Number.isNaN(Number(t))&&Number(t)>r)return`Must be at most ${r}.`;break}}}return null}_getFieldElements(t){if(!this._form)return[];const e=Array.from(this._form.querySelectorAll(`[name="${t}"]`)),i=e.filter(r=>r.tagName==="MINT-SELECT");if(i.length>0){const r=[];return i.forEach(a=>{const l=a.querySelector('select[name="'+t+'"]');l&&r.push(l)}),e.filter(a=>a.tagName!=="MINT-SELECT").concat(r)}if(e.filter(r=>r.tagName==="MINT-TAGS").length>0)return e.filter(r=>r.tagName!=="INPUT"||!r.closest("mint-tags"));const n=e.filter(r=>r.tagName==="INPUT"&&r.closest("mint-tags"));if(n.length>0){const r=[];return n.forEach(a=>{const l=a.closest("mint-tags");l&&!r.includes(l)&&r.push(l)}),e.filter(a=>a.tagName!=="INPUT"||!a.closest("mint-tags")).concat(r)}return e}_extractFieldValue(t){if(t.length===0)return"";const e=t.find(s=>s instanceof HTMLSelectElement);if(e)return e.value;if(t.length>1){const s=t.filter(a=>a instanceof HTMLInputElement);if(s.length>0&&s.length===t.length){const a=s.filter(l=>l.checked);if(s.every(l=>l.type==="radio"))return a.length>0?a[0].value||"on":"";if(s.every(l=>l.type==="checkbox"))return a.map(l=>l.value||"on")}const n=t.filter(a=>a.tagName==="MINT-CHOICE");if(n.length>0&&n.length===t.length){const a=n.find(l=>typeof l.getValue=="function"?l.getValue()!=="":l.querySelector("mint-choice-option[checked]")!==null);if(a){if(typeof a.getValue=="function")return a.getValue();const l=a.querySelector("mint-choice-option[checked]");if(l)return l.getAttribute("value")||""}return""}const r=t.filter(a=>a.tagName==="MINT-CHECKBOX");if(r.length>0&&r.length===t.length)return r.filter(l=>typeof l.checked<"u"?l.checked:l.hasAttribute("checked")).map(l=>l.getAttribute("value")||"on")}const i=t[0];if(i instanceof HTMLInputElement)return i.type==="file"?i.files:i.type==="checkbox"||i.type==="radio"?i.checked?i.value||"on":"":i.value;if(i instanceof HTMLTextAreaElement)return i.value;if(i.tagName==="MINT-SELECT"){const s=i.querySelector("select");if(s)return s.value;if(typeof i.getValue=="function"){const r=i.getValue();if(r!=null&&r!=="")return r}const n=i.getAttribute("value");return n||""}if(i.tagName==="MINT-DROPZONE"&&typeof i.files<"u")return i.files;if(i.tagName==="MINT-TAGS"){let s=null;return typeof i.tags<"u"?s=i.tags:typeof i.getTags=="function"&&(s=i.getTags()),Array.isArray(s)?s.map(r=>typeof r=="string"?r:(r==null?void 0:r.value)||(r==null?void 0:r.label)||"").filter(r=>r.trim()!==""):[]}return i.tagName==="MINT-CHECKBOX"||i.tagName==="MINT-SWITCH"?(typeof i.checked<"u"?i.checked:i.hasAttribute("checked"))?i.getAttribute("value")||"on":"":i.tagName==="MINT-CHOICE"?(typeof i.getValue=="function"?i.getValue():"")||"":typeof i.value<"u"?i.value:i.getAttribute("value")||""}_flagFieldError(t,e){t.length!==0&&t.forEach(i=>{(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement)&&i.setAttribute("aria-invalid","true");const s=this._resolveHost(i);s&&(s.setAttribute("error","true"),s.setAttribute("error-message",e),s.setAttribute("data-mint-form-error","true"))})}_clearFieldError(t){t.length!==0&&t.forEach(e=>{(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&e.removeAttribute("aria-invalid");const i=this._resolveHost(e);i&&(i.removeAttribute("error"),i.removeAttribute("error-message"),i.removeAttribute("data-mint-form-error"))})}_clearErrors(){this.querySelectorAll("[data-mint-form-error]").forEach(t=>{const e=t;e.removeAttribute("error"),e.removeAttribute("error-message"),e.removeAttribute("data-mint-form-error")}),this._form&&this._form.querySelectorAll('[aria-invalid="true"]').forEach(t=>{t.removeAttribute("aria-invalid")}),this._errors={}}setFormErrors(t){this._applyServerErrors(t)}_applyServerErrors(t){this._clearErrors(),Object.entries(t).forEach(([e,i])=>{const s=Array.isArray(i)?i[0]||"Validation error":i||"Validation error",n=this._getFieldElements(e);n.length>0&&(this._errors[e]=s,this._flagFieldError(n,s))})}_parseFormData(t){if(!t){this._formData=null;return}if(typeof t=="object"&&!Array.isArray(t)){this._formData=t;return}if(typeof t=="string")try{this._formData=JSON.parse(t)}catch{this._formData=null}else this._formData=null}_parseHeaders(t){if(!t){this._headers=null;return}if(typeof t=="string")try{this._headers=JSON.parse(t)}catch{this._headers=null}else this._headers=null}_applyFormData(){if(!this._formData||!this._form)return;const t=this._getReactiveValue(this._formData);if(!t||typeof t!="object"||Array.isArray(t))return;const e=()=>{Object.entries(t).forEach(([i,s])=>{const n=this._getFieldElements(i);if(n.length===0){setTimeout(()=>{const r=this._getFieldElements(i);r.length>0&&this._applyValueToField(r,i,s)},300);return}this._applyValueToField(n,i,s)})};requestAnimationFrame(()=>{requestAnimationFrame(()=>{e()})})}_applyValueToField(t,e,i){t.forEach(s=>{var r;const n=s.tagName;try{if(n==="MINT-INPUT")typeof s.value<"u"&&(s.value=i||"");else if(n==="MINT-DATE-PICKER")typeof s.setValue=="function"&&s.setValue(i||"");else if(n==="MINT-SELECT"||n==="SELECT")n==="SELECT"?(r=s.closest("mint-select"))==null||r.setValue(i||""):typeof s.setValue=="function"&&s.setValue(i||"");else if(n==="MINT-CHOICE")typeof s.setValue=="function"?s.setValue(i||""):s.querySelectorAll("mint-choice-option").forEach(l=>{l.checked=l.getAttribute("value")===i});else if(n==="MINT-CHECKBOX"||n==="MINT-SWITCH"){const a=i===!0||i==="true"||i==="on"||i===1||i==="1";typeof s.checked<"u"?s.checked=a:a?s.setAttribute("checked","true"):s.removeAttribute("checked")}else n==="MINT-TAGS"?Array.isArray(i)&&typeof s.tags<"u"&&(s.tags=i.map(a=>typeof a=="string"?{value:a,label:a,dismissable:!0}:a)):s instanceof HTMLInputElement?s.type==="checkbox"||s.type==="radio"?s.checked=i===!0||i==="true"||i==="on"||i===1||i==="1":s.value=i||"":(s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement)&&(s.value=i||"")}catch(a){console.warn(`Failed to set value for field ${e}:`,a)}})}_resetCustomFields(){this.querySelectorAll("mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags").forEach(e=>{var s,n;e.removeAttribute("error"),e.removeAttribute("error-message");const i=e.tagName;if(i==="MINT-INPUT")try{e.value=""}catch{}else if(i==="MINT-DATE-PICKER")try{(s=e.setValue)==null||s.call(e,"")}catch{}else if(i==="MINT-SELECT")try{(n=e.setValue)==null||n.call(e,"")}catch{}else if(i==="MINT-DROPZONE"){const r=e.querySelector('input[type="file"]');r&&(r.value="")}else if(i==="MINT-CHECKBOX"||i==="MINT-SWITCH")try{if(typeof e.checked<"u")e.checked=!1;else{e.removeAttribute("checked");const r=e.querySelector('input[type="checkbox"], input[type="radio"]');r&&(r.checked=!1)}}catch{}else if(i==="MINT-CHOICE")try{typeof e.setValue=="function"?e.setValue(""):e.querySelectorAll("mint-choice-option").forEach(a=>{a.checked=!1})}catch{}else if(i==="MINT-TAGS")try{e.tags=[]}catch{}})}_resolveHost(t){if(t.tagName==="MINT-CHOICE-OPTION"){const i=t.closest("mint-choice");if(i)return i}const e=t.closest("mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags");return e||t}_setupBlurValidation(){if(!this._form)return;const t=i=>{const s=i.target;if(!s)return;const n=this._findFieldElement(s);if(!n)return;const r=this._getFieldName(n);if(!r||!this._collectValidationRules()[r])return;const l=this._extractFieldValue([n]),o=l!=null&&(typeof l=="string"?l.trim()!=="":l instanceof FileList||Array.isArray(l)?l.length>0:!0),c=n.hasAttribute("data-mint-form-error")||s instanceof HTMLElement&&(s.hasAttribute("aria-invalid")||s.closest("[data-mint-form-error]")),h=!!n.closest("mint-tags"),f=n.tagName==="MINT-CHECKBOX"||n.tagName==="MINT-SWITCH"||n.tagName==="MINT-CHOICE"||s instanceof HTMLElement&&(s.closest("mint-checkbox, mint-switch, mint-choice")||s.closest("mint-choice-option")),d=n.tagName==="MINT-DATE-PICKER"||s instanceof HTMLElement&&s.closest("mint-date-picker");(o||c||h||f||d)&&setTimeout(()=>{this._validateField(r)},0)};this._form.addEventListener("blur",t,!0),this._fieldBlurHandlers.set(this._form,t);const e=i=>{const s=i.target;if(!s)return;if(i.type==="tags-change"&&s.tagName==="MINT-TAGS"){const c=s,h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}if(s instanceof HTMLSelectElement||s.tagName==="MINT-SELECT"||s.closest("mint-select")){const c=this._findFieldElement(s);if(!c)return;const h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}if(i.type==="choice-change"&&s.tagName==="MINT-CHOICE"){const c=s,h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}if(s instanceof HTMLInputElement&&s.type==="checkbox"||s.tagName==="MINT-CHECKBOX"||s.tagName==="MINT-SWITCH"||s.closest("mint-checkbox, mint-switch")){const c=this._findFieldElement(s);if(!c)return;const h=this._getFieldName(c);if(!h||!this._collectValidationRules()[h])return;setTimeout(()=>{this._validateField(h)},0);return}const a=this._findFieldElement(s);if(!a)return;const l=this._getFieldName(a);!l||!this._collectValidationRules()[l]||(a.hasAttribute("data-mint-form-error")||s instanceof HTMLElement&&s.hasAttribute("aria-invalid"))&&setTimeout(()=>{this._validateField(l)},0)};this._form.addEventListener("change",e,!0),this._form.addEventListener("tags-change",e,!0),this._form.addEventListener("choice-change",e,!0),this._fieldChangeHandlers.set(this._form,e)}_findFieldElement(t){if(t.hasAttribute("name")&&(t.tagName.startsWith("MINT-")||t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement))return t;const e=t.closest("mint-input, mint-date-picker, mint-select, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags");if(e&&e.hasAttribute("name"))return e;if((t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&t.hasAttribute("name"))return t;let i=t;for(;i&&i!==this._form;){if(i.hasAttribute("name"))return i;i=i.parentElement}return null}_getFieldName(t){return t.hasAttribute("name")||t.tagName.startsWith("MINT-")?t.getAttribute("name"):(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&t.name||null}_cleanupBlurValidation(){if(this._form&&this._fieldBlurHandlers.has(this._form)){const t=this._fieldBlurHandlers.get(this._form);t&&this._form.removeEventListener("blur",t,!0),this._fieldBlurHandlers.delete(this._form)}if(this._form&&this._fieldChangeHandlers.has(this._form)){const t=this._fieldChangeHandlers.get(this._form);t&&(this._form.removeEventListener("change",t,!0),this._form.removeEventListener("tags-change",t,!0),this._form.removeEventListener("choice-change",t,!0)),this._fieldChangeHandlers.delete(this._form)}this._observer&&(this._observer.disconnect(),this._observer=null)}_syncDropzoneFiles(){if(!this._form)return;Array.from(this._form.querySelectorAll("mint-dropzone[name]")).forEach(e=>{typeof e.syncFiles=="function"&&e.syncFiles()})}_propagateLoadingState(){if(!this._form)return;const t=this.getAttribute("loading"),e=t!==null&&t!=="false";Array.from(this._form.querySelectorAll("mint-input, mint-select, mint-date-picker, mint-dropzone, mint-checkbox, mint-choice, mint-switch, mint-tags")).forEach(s=>{e?s.setAttribute("loading","true"):s.removeAttribute("loading"),typeof s.render=="function"&&s.render()})}_setButtonsSubmitting(){if(!this._form)return;this._buttonStates.clear();const t=Array.from(this.querySelectorAll("mint-button")),e=Array.from(this.querySelectorAll("button"));t.forEach(i=>{const s=i.getAttribute("disabled")==="true",n=i.getAttribute("loading")==="true";this._buttonStates.set(i,{disabled:s,loading:n});const a=(i.getAttribute("type")||i.getAttribute("button-type")||"default")==="submit";s||i.setAttribute("disabled","true"),a&&i.setAttribute("loading","true"),typeof i.render=="function"&&i.render()}),e.forEach(i=>{if(i.closest("mint-button"))return;const s=i.disabled;this._buttonStates.set(i,{disabled:s,loading:!1}),s||(i.disabled=!0)})}_restoreButtonsState(){if(!this._form)return;const t=Array.from(this.querySelectorAll("mint-button")),e=Array.from(this.querySelectorAll("button"));t.forEach(i=>{const s=this._buttonStates.get(i);s&&(s.disabled?i.setAttribute("disabled","true"):i.removeAttribute("disabled"),s.loading?i.setAttribute("loading","true"):i.removeAttribute("loading"),typeof i.render=="function"&&i.render())}),e.forEach(i=>{if(i.closest("mint-button"))return;const s=this._buttonStates.get(i);s&&(i.disabled=s.disabled)}),this._buttonStates.clear()}_isReactiveObject(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;if("__v_isRef"in t||"_value"in t||"__v_raw"in t||"__v_isReactive"in t||"__ob__"in t)return!0;try{const e=t.toString();if(e==="[object Object]"||e.includes("Proxy")){const i=Object.keys(t)[0];if(i){const s=Object.getOwnPropertyDescriptor(t,i);if(s&&(s.get||s.set))return!0}}}catch{return!0}return!0}_createDataSnapshot(t){try{const e=this._extractReactiveData(t);return JSON.parse(JSON.stringify(e))}catch{return{...this._extractReactiveData(t)}}}_extractReactiveData(t){if(!t||typeof t!="object")return t;if(Array.isArray(t))return t.map(i=>this._extractReactiveData(i));const e=this._getReactiveValue(t);if(e&&typeof e=="object"&&!Array.isArray(e)){const i={};for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(i[s]=this._extractReactiveData(e[s]));return i}return e}_hasDataChanged(t,e){try{return JSON.stringify(t)!==JSON.stringify(e)}catch{return!0}}_getReactiveValue(t){if(!t||typeof t!="object")return t;if("_value"in t||"__v_isRef"in t){if(typeof t.value<"u")return t.value;if("_value"in t)return t._value}return"__v_raw"in t||"__v_isReactive"in t||"__ob__"in t,t}_setupReactiveDataObserver(t){if(this._stopReactiveDataObserver(),!this.isConnected)return;const e=this._getReactiveValue(t);if(e&&typeof e=="object"&&!Array.isArray(e))this._lastDataSnapshot=this._createDataSnapshot(e);else{this._lastDataSnapshot=null;return}const i=()=>{if(!this._formData||!this._lastDataSnapshot){this._stopReactiveDataObserver();return}const s=this._getReactiveValue(this._formData);if(s&&typeof s=="object"&&!Array.isArray(s)){const n=this._createDataSnapshot(s);this._hasDataChanged(n,this._lastDataSnapshot)&&(this._lastDataSnapshot=n,requestAnimationFrame(()=>{this._applyFormData()}))}this.isConnected&&this._formData?this._reactiveDataObserver=requestAnimationFrame(i):this._stopReactiveDataObserver()};this._reactiveDataObserver=requestAnimationFrame(i)}_stopReactiveDataObserver(){this._reactiveDataObserver!==null&&(cancelAnimationFrame(this._reactiveDataObserver),this._reactiveDataObserver=null),this._reactiveDataProxy=null,this._lastDataSnapshot=null}}customElements.get("mint-form")||customElements.define("mint-form",kt);typeof window<"u"&&(window.mintForm=window.mintForm||{defaults:{headers:{common:{}}},interceptors:{response:{handlers:[]}}},window.mintForm.interceptors.response.use||(window.mintForm.interceptors.response.use=function(M,t){return window.mintForm.interceptors.response.handlers.push({fulfilled:M,rejected:t}),window.mintForm.interceptors.response.handlers.length-1}));class xt extends HTMLElement{constructor(){super(...arguments),this._observer=null}static get observedAttributes(){return["collapse","scroll"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","align-baseline","block","w-full","overflow-x-auto"),this.hasAttribute("collapse")&&!this.hasAttribute("scroll")&&this._ensureResponsiveStyles(),this._observeChanges(),this._applyStyles(),requestAnimationFrame(()=>{this._applyStyles(),setTimeout(()=>this._applyStyles(),0)})}disconnectedCallback(){this._observer&&(this._observer.disconnect(),this._observer=null)}attributeChangedCallback(){this.hasAttribute("collapse")&&!this.hasAttribute("scroll")&&this._ensureResponsiveStyles(),this._applyStyles()}_observeChanges(){this._observer=new MutationObserver(()=>this._applyStyles()),this._observer.observe(this,{childList:!0,subtree:!0,attributes:!1})}_applyStyles(){this._observer&&this._observer.disconnect();const t=this.querySelector("table");if(!t){this._observer&&this._observeChanges();return}const e=this.hasAttribute("collapse")&&!this.hasAttribute("scroll"),i=this.hasAttribute("scroll");i?this.classList.add("relative"):this.classList.remove("relative");const s=[],n=t.querySelector("thead tr");n&&n.querySelectorAll("th").forEach(c=>s.push((c.textContent||"").trim())),this._setClasses(t,["w-full",i?"min-w-[1200px]":"","border-collapse","text-sm","font-medium","overflow-hidden"]);const r=t.querySelector("thead");if(r){this._setClasses(r,["bg-[#F7F7F7]","dark:bg-gray-800"]);const o=r.querySelectorAll("th");o.forEach((c,h)=>{const f=c.querySelector("mint-icon"),d=(f==null?void 0:f.getAttribute("name"))||"",p=f!==null&&d!=="ellipsis";this._setClasses(c,["text-left","font-semibold","text-gray-900","dark:text-white","px-3","py-2","border-b","border-gray-200","dark:border-gray-700"]),p&&c.classList.add("cursor-pointer","bg-[#F7F7F7]","dark:bg-gray-800","hover:bg-gray-100","dark:hover:bg-gray-700","transition-colors"),h===0&&c.classList.add("pl-6"),h===o.length-1&&c.classList.add("pr-6")})}const a=t.querySelector("tbody");if(a){const o=Array.from(a.querySelectorAll("tr"));o.forEach((c,h)=>{const f=c.hasAttribute("data-row-clickable");this._setClasses(c,["bg-white","dark:bg-gray-900","border-b","border-gray-200","dark:border-gray-700"]),f&&c.classList.add("cursor-pointer","hover:bg-gray-50","dark:hover:bg-gray-800","transition-colors"),h===o.length-1&&c.classList.remove("border-b");const d=c.querySelectorAll("td");d.forEach((p,u)=>{this._setClasses(p,["text-gray-900","dark:text-gray-100","px-3","py-2"]),u===0&&p.classList.add("pl-6"),u===d.length-1&&p.classList.add("pr-6"),e?this._applyMobileCell(p,s):this._restoreCell(p)})})}const l=t.querySelector("tfoot");l&&(this._setClasses(l,["bg-[#F7F7F7]","dark:bg-gray-800","font-semibold"]),l.querySelectorAll("td").forEach(c=>{this._setClasses(c,["text-gray-900","dark:text-gray-100","px-3","py-2","border-t","border-gray-200","dark:border-gray-700"]),this._restoreCell(c)})),this._observer&&this._observeChanges()}_applyMobileCell(t,e){if(t.closest("tfoot")||t.dataset.mtProcessed==="true")return;const i=e[t.cellIndex]||"",s={};Array.from(t.attributes).forEach(o=>{o.name.startsWith("data-")&&o.name!=="data-original"&&o.name!=="data-mt-processed"&&(s[o.name]=o.value)});const n=t.getAttribute("data-original"),r=n!==null?n:t.innerHTML;t.setAttribute("data-original",r),t.dataset.mtProcessed="true",t.innerHTML="";const a=document.createElement("span");a.className="mt-label font-semibold text-gray-700 dark:text-gray-200 hidden",a.textContent=i;const l=document.createElement("span");l.className="mt-value text-gray-900 dark:text-gray-100 text-right md:text-left w-full",l.innerHTML=r,t.appendChild(a),t.appendChild(l),Object.entries(s).forEach(([o,c])=>{t.setAttribute(o,c)})}_restoreCell(t){if(t.dataset.mtProcessed!=="true")return;const e={};Array.from(t.attributes).forEach(s=>{s.name.startsWith("data-")&&s.name!=="data-original"&&s.name!=="data-mt-processed"&&(e[s.name]=s.value)});const i=t.getAttribute("data-original")||"";t.dataset.mtProcessed="",t.innerHTML=i,Object.entries(e).forEach(([s,n])=>{t.setAttribute(s,n)})}_setClasses(t,e){t.className="",e.filter(Boolean).forEach(i=>t.classList.add(...i.split(" ")))}_ensureResponsiveStyles(){if(document.getElementById("mint-table-responsive-style"))return;const t=document.createElement("style");t.id="mint-table-responsive-style",t.textContent=`
|
|
90
90
|
@media (max-width: 640px) {
|
|
91
91
|
mint-table[collapse] {
|
|
92
92
|
display: block;
|
|
@@ -149,32 +149,32 @@
|
|
|
149
149
|
border: inherit;
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
-
`,document.head.appendChild(t)}}customElements.get("mint-table")||customElements.define("mint-table",xt);class Et extends HTMLElement{constructor(){super(...arguments),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(){var i;if(this.classList.add("inline-flex","items-center","gap-2","px-3","py-1","rounded-full","border","border-gray-200","dark:border-gray-700","bg-gray-100","dark:bg-gray-900","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;){const s=this.firstChild;if(s===this._root)break;this._textWrap.appendChild(s)}this._root.appendChild(this._textWrap),this.appendChild(this._root)}this.getAttribute("dismissable")==="true"?(this._dismissBtn||this._createDismissBtn(),this._dismissBtn&&!this._dismissBtn.isConnected&&((i=this._root)==null||i.appendChild(this._dismissBtn))):this._dismissBtn&&this._dismissBtn.parentElement===this._root&&this._dismissBtn.remove()}_createDismissBtn(){const t=document.createElement("button");t.type="button",t.setAttribute("aria-label","Dismiss"),t.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","transition-colors","duration-150","border-none","bg-transparent","cursor-pointer"].join(" ");const e=document.createElement("mint-icon");e.setAttribute("name","close"),e.className="w-3 h-3",t.appendChild(e),this._clickHandler=i=>{i.stopPropagation(),this.dispatchEvent(new CustomEvent("dismissed",{bubbles:!0,composed:!0}))},t.addEventListener("click",this._clickHandler),this._dismissBtn=t}}customElements.get("mint-chip")||customElements.define("mint-chip",Et);class wt extends HTMLElement{constructor(){super(...arguments),this._container=null,this._chipsWrap=null,this._input=null,this._tags=[],this._placeholder="Add tag",this._dragIndex=null,this._dragChip=null,this._isPointerDragging=!1,this._pointerMoveHandler=null,this._pointerUpHandler=null}static get observedAttributes(){return["tags","placeholder","sortable","label","info","error","error-message","name","id","required","loading"]}connectedCallback(){this._parseAttrs(),this._render(),this._pointerMoveHandler||(this._pointerMoveHandler=t=>this._onPointerMove(t),window.addEventListener("pointermove",this._pointerMoveHandler)),this._pointerUpHandler||(this._pointerUpHandler=t=>this._onPointerUp(t),window.addEventListener("pointerup",this._pointerUpHandler),window.addEventListener("pointercancel",this._pointerUpHandler))}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){if(this._renderErrorState(),this._container){const s=this.hasError(),n=["flex","flex-wrap","items-center","gap-2","w-full","px-2","py-1.5","min-h-[2rem]","rounded-lg","border-2",s?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","bg-white","dark:bg-gray-900","focus-within:ring-2","focus-within:ring-offset-1",s?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","transition-colors","duration-200"];this._container.className=n.join(" ")}return}if(t==="loading"){this._parseAttrs(),this._render();return}this._parseAttrs(),this._render()}}set tags(t){this._tags=Array.isArray(t)?[...t]:[],this._syncAttr(),this._render()}get tags(){return[...this._tags]}_parseAttrs(){const t=this.getAttribute("tags");if(!t)return;try{const i=JSON.parse(t);Array.isArray(i)&&(this._tags=i)}catch(i){console.warn("mint-tags: failed to parse tags attribute",i)}const e=this.getAttribute("placeholder");e!==null&&(this._placeholder=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"}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")}_render(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full");const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.hasError(),n=this.getId()||`mint-tags-${Math.random().toString(36).substr(2,9)}`;if(this.getId()||this.setAttribute("id",n),this._container)this._input&&(this._input.placeholder=this._placeholder);else{this._container=document.createElement("div");const o=["flex","flex-wrap","items-center","gap-2","w-full","px-2","py-1","min-h-[2rem]","rounded-lg","border-2",s?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","bg-white","dark:bg-gray-800","focus-within:ring-2","focus-within:ring-offset-1",s?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","transition-colors","duration-200"];this._container.className=o.join(" "),this._chipsWrap=document.createElement("div"),this._chipsWrap.className="flex flex-wrap items-center gap-2",this._chipsWrap.addEventListener("dragover",c=>{this.hasAttribute("sortable")&&c.preventDefault()}),this._chipsWrap.addEventListener("drop",c=>{this.hasAttribute("sortable")&&c.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",c=>{c.key==="Enter"&&(c.preventDefault(),this._addFromInput())}),this._container.appendChild(this._chipsWrap),this.appendChild(this._container)}if(this._container){const o=["flex","flex-wrap","items-center","gap-2","w-full","px-2","py-1","min-h-[2rem]","rounded-lg","border-2",s?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","bg-white","dark:bg-gray-800","focus-within:ring-2","focus-within:ring-offset-1",s?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","transition-colors","duration-200"];this._container.className=o.join(" ")}let r=this.querySelector(".mint-tags-label-container");if(e){r||(r=document.createElement("div"),r.className="mint-tags-label-container mb-[.25rem]",this._container&&this._container.parentElement===this?this.insertBefore(r,this._container):this.insertBefore(r,this.firstChild));let o=r.querySelector(".mint-tags-label");e?(o||(o=document.createElement("label"),o.className="mint-tags-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",r.appendChild(o)),o.textContent=e,o.setAttribute("for",n)):o&&o.remove()}else r&&r.remove();let a=this.querySelector(".mint-tags-info");i?(a||(a=document.createElement("span"),a.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(a,this._container.nextSibling):this.appendChild(a)),a.textContent=i):a&&a.remove();const l=this.getName();l?(this.setAttribute("name",l),this._input&&(this._input.name=l,this._input.id=n)):(this.removeAttribute("name"),this._input&&(this._input.removeAttribute("name"),this._input.id=n)),this._wireInputBackspace(),this._renderChips(),this._renderErrorState(),this._renderSkeleton(t)}_renderSkeleton(t){const e=this._container;if(!e)return;e.classList.contains("relative")||e.classList.add("relative");let i=e.querySelector(".mint-tags-skeleton");t?(i||(i=document.createElement("div"),i.className="mint-tags-skeleton absolute inset-0 z-10 pointer-events-none rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(i)),i.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")):(i&&(i.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(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-tags-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-tags-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}_renderChips(){if(!this._chipsWrap)return;this._chipsWrap.innerHTML="";let t=0;this._tags.forEach(e=>{const i=document.createElement("mint-chip");i.dataset.index=String(t++),i.dataset.value=e.value,i.draggable=this.hasAttribute("sortable"),i.draggable&&i.classList.add("cursor-move"),e.dismissable&&(i.setAttribute("dismissable","true"),i.addEventListener("dismissed",()=>this._removeTag(e.value))),this._chipsWrap.appendChild(i);const s=i.querySelector("[data-mt-chip-text]");s&&(s.textContent=e.label||e.value),this._setupChipEvents(i,e),i.draggable&&(i.addEventListener("dragstart",n=>this._onDragStart(n,i)),i.addEventListener("dragover",n=>this._onDragOverChip(n,i)),i.addEventListener("drop",n=>this._onDrop(n)),i.addEventListener("dragend",()=>this._onDragEnd())),this.hasAttribute("sortable")&&i.addEventListener("pointerdown",n=>this._onPointerDown(n,i))}),this._input&&(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;const t=this._input.value.trim();if(!t)return;if(this._tags.some(i=>i.value.toLowerCase()===t.toLowerCase())){this._input.value="";return}this._tags.push({value:t,label:t,dismissable:!0}),this._syncAttr(),this._renderChips(),this._emitChange(),this._input.value="",setTimeout(()=>{var i;(i=this._input)==null||i.focus()},10)}_removeTag(t){this._tags=this._tags.filter(e=>e.value!==t),this._syncAttr(),this._renderChips(),this._emitChange()}_emitChange(){this.dispatchEvent(new CustomEvent("tags-change",{bubbles:!0,composed:!0,detail:{tags:this.tags}}))}_focusLastChip(){var e;const t=(e=this._chipsWrap)==null?void 0:e.querySelectorAll("mint-chip");t&&t.length>0&&t[t.length-1].focus({preventScroll:!0})}_focusInput(){setTimeout(()=>{var t;(t=this._input)==null||t.focus({preventScroll:!0})},10)}_wireInputBackspace(){this._input&&this._input.addEventListener("keydown",t=>{var e;t.key==="Backspace"&&((e=this._input)==null?void 0:e.value)===""&&(t.preventDefault(),this._focusLastChip())})}_setupChipEvents(t,e){t.tabIndex=0,t.addEventListener("keydown",i=>{(i.key==="Backspace"||i.key==="Delete")&&e.dismissable&&(i.preventDefault(),this._removeTag(e.value),this._focusInput())})}_onDragStart(t,e){var i;this.hasAttribute("sortable")&&(this._dragChip=e,this._dragIndex=Number(e.dataset.index),(i=t.dataTransfer)==null||i.setData("text/plain",e.dataset.index||""),t.dataTransfer&&(t.dataTransfer.effectAllowed="move",t.dataTransfer.dropEffect="move"),e.classList.add("opacity-60"))}_reorderTags(t,e){if(t<0||e<0||t>=this._tags.length||e>=this._tags.length)return;const i=[...this._tags],[s]=i.splice(t,1);i.splice(e,0,s),this._tags=i,this._syncAttr(),this._renderChips(),this._emitChange()}_onDragOverInput(t){this.hasAttribute("sortable")&&(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="move"),this._dragChip&&this._chipsWrap&&this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input))}_onDragOverChip(t,e){if(!this.hasAttribute("sortable")||(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="move"),!this._dragChip||!this._chipsWrap)||e===this._dragChip)return;const i=e.getBoundingClientRect(),s=t.clientX,n=i.left+i.width*.5;if(s<n){if(this._dragChip.nextSibling===e)return;this._chipsWrap.insertBefore(this._dragChip,e)}else{if(e.nextSibling===this._dragChip)return;const r=e.nextSibling;r?this._chipsWrap.insertBefore(this._dragChip,r):this._chipsWrap.appendChild(this._dragChip)}}_onDrop(t){this.hasAttribute("sortable")&&t.preventDefault()}_onDragEnd(){this._dragChip&&this._dragChip.classList.remove("opacity-60"),this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}_syncOrderFromDom(){if(!this._chipsWrap)return;const t=Array.from(this._chipsWrap.querySelectorAll("mint-chip"));if(t.length===0)return;const e=[];t.forEach(i=>{const s=i.dataset.value;if(!s)return;const n=this._tags.find(r=>r.value===s);n&&e.push(n)}),e.length===this._tags.length&&(this._tags=e,this._syncAttr(),this._renderChips(),this._emitChange())}_onPointerDown(t,e){if(this.hasAttribute("sortable")&&t.pointerType!=="mouse"){this._isPointerDragging=!0,this._dragChip=e,this._dragIndex=Number(e.dataset.index);try{e.setPointerCapture(t.pointerId)}catch{}e.classList.add("opacity-60","select-none"),t.preventDefault()}}_onPointerMove(t){if(!this._isPointerDragging||!this._dragChip||!this._chipsWrap||t.pointerType==="mouse")return;const e=document.elementFromPoint(t.clientX,t.clientY);if(!e)return;const i=e.closest("mint-chip");if(i&&i!==this._dragChip){const s=i.getBoundingClientRect(),n=t.clientX,r=s.left+s.width*.5;if(n<r)this._dragChip.nextSibling!==i&&this._chipsWrap.insertBefore(this._dragChip,i);else if(i.nextSibling!==this._dragChip){const a=i.nextSibling;a?this._chipsWrap.insertBefore(this._dragChip,a):this._chipsWrap.appendChild(this._dragChip)}return}this._input&&e.closest("input")===this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input)}_onPointerUp(t){if(this._isPointerDragging){if(this._isPointerDragging=!1,this._dragChip){try{this._dragChip.releasePointerCapture(t.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",wt);class Ct extends HTMLElement{constructor(){super(...arguments),this._clickHandler=null,this._keydownHandler=null}connectedCallback(){this._render(),this._setupEventListeners()}disconnectedCallback(){this._cleanupEventListeners()}_render(){this.classList.add("transition-colors","duration-200","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=t=>{if(this.getAttribute("disabled")==="true"){t.preventDefault(),t.stopPropagation();return}this._handleClick(t)},this._keydownHandler=t=>{if(t.key==="Enter"||t.key===" "){if(this.getAttribute("disabled")==="true"){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),this._handleClick(t)}},this.addEventListener("click",this._clickHandler),this.addEventListener("keydown",this._keydownHandler)}_cleanupEventListeners(){this._clickHandler&&(this.removeEventListener("click",this._clickHandler),this._clickHandler=null),this._keydownHandler&&(this.removeEventListener("keydown",this._keydownHandler),this._keydownHandler=null)}_handleClick(t){this.dispatchEvent(new CustomEvent("clickable-click",{bubbles:!0,composed:!0,detail:{originalEvent:t}}))}static get observedAttributes(){return["disabled"]}attributeChangedCallback(t,e,i){t==="disabled"&&(i==="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",Ct);class At extends HTMLElement{constructor(){super(),this._headingElement=null,this._iconElement=null,this._dismissButton=null,this._headerWrapper=null,this._bodyWrapper=null,this._dismissHandler=null}static get observedAttributes(){return["heading","dismissable","tone"]}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(t,e,i){e!==i&&this.render()}getHeading(){return this.getAttribute("heading")||""}getTone(){const t=this.getAttribute("tone");return t==="info"||t==="success"||t==="warning"||t==="danger"?t:"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-blue-600 dark:text-blue-400";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-blue-600 dark:text-blue-400"}}getHeadingColorClasses(){return"text-gray-900 dark:text-gray-100"}getHeaderBackgroundClasses(){switch(this.getTone()){case"info":return"bg-blue-100 dark:bg-blue-900/30";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-blue-100 dark:bg-blue-900/30"}}getBorderClasses(){switch(this.getTone()){case"info":return"border-blue-200 dark:border-blue-800";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-blue-200 dark:border-blue-800"}}getAriaLive(){return this.getTone()==="danger"?"assertive":"polite"}render(){const t=this.getTone(),e=this.getHeading(),i=this.isDismissable();this.className=`box-border m-0 p-0 border-0 align-baseline block rounded-lg border shadow-sm overflow-hidden transition-colors duration-200 ${this.getBorderClasses()}`;const s=this.getAriaLive();this.setAttribute("role","alert"),this.setAttribute("aria-live",s),t==="danger"?this.setAttribute("aria-atomic","true"):this.removeAttribute("aria-atomic");const n=[];for(this._bodyWrapper?Array.from(this._bodyWrapper.childNodes).forEach(a=>{n.push(a)}):Array.from(this.childNodes).forEach(r=>{r!==this._headerWrapper&&r!==this._bodyWrapper&&r!==this._iconElement&&r!==this._headingElement&&r!==this._dismissButton&&n.push(r)}),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=e||"",this._headerWrapper.appendChild(this._headingElement),i){this._dismissButton=document.createElement("button"),this._dismissButton.className="flex-shrink-0 p-1 rounded hover:bg-black/10 dark:hover:bg-white/10 transition-colors",this._dismissButton.setAttribute("aria-label","Dismiss alert"),this._dismissButton.setAttribute("type","button");const r=document.createElement("mint-icon");r.setAttribute("name","close"),r.className="w-4 h-4 text-gray-700 dark:text-gray-300",this._dismissButton.appendChild(r),this._dismissHandler=a=>{a.preventDefault(),a.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-gray-900",n.forEach(r=>{this._bodyWrapper.appendChild(r)}),this.appendChild(this._headerWrapper),this.appendChild(this._bodyWrapper)}}customElements.get("mint-alert")||customElements.define("mint-alert",At);class St extends HTMLElement{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._rowsToShow=15,this._loaded=!1,this._fetching=!1,this._loading=!1,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}static get observedAttributes(){return["configuration"]}get inMintCard(){return this._inMintCard}get configuration(){return this._configuration}set configuration(t){t&&typeof t=="object"&&!Array.isArray(t)?(this._configuration=t,this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._rowsToShow=this._perPage,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._loadColumnVisibility(),this.isConnected&&this.render()):t==null?this._configuration=null:this._parseConfiguration()}connectedCallback(){var t,e;this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full"),this._inMintCard=((e=(t=this.parentElement)==null?void 0:t.tagName)==null?void 0:e.toLowerCase())==="mint-card",this._configuration||this._parseConfiguration(),this._initializeColumns(),this._loadColumnVisibility(),this._loadPageFromUrl(),this._attachRowClickHandler(),this.render()}disconnectedCallback(){this._searchTimeoutId&&clearTimeout(this._searchTimeoutId),this._rowClickHandler&&(this.removeEventListener("click",this._rowClickHandler,!0),this._rowClickHandler=null),this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler),this._scrollHandler=null)}attributeChangedCallback(t,e,i){t==="configuration"&&e!==i&&(!this._configuration||typeof i=="string")&&(this._parseConfiguration(),this.render())}refresh(){this._configuration&&(this._type==="ajax"?this._configuration.loadMore?(this._offset=0,this._currentPage=1,this._rowsToShow=this._perPage,this._rows=[],this._fetchData(void 0,!0,this._perPage,0)):this._fetchData(void 0,!0,this._perPage,this._offset):this.render())}_parseConfiguration(){const t=this.getAttribute("configuration");if(!t){console.error("mint-resource-table: configuration attribute is required");return}try{this._configuration=JSON.parse(t),this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._rowsToShow=this._perPage,this._type=typeof this._configuration.data=="string"?"ajax":"provided",this._loaded=!1;const e=this._getPageFromUrl();this._currentPage=e||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(),this._loadColumnVisibility()}catch(e){console.error("mint-resource-table: Invalid configuration JSON",e)}}_getColumnVisibilityStorageKey(){return`mrtc-${this._tableId}`}_saveColumnVisibility(){if(!this._configuration)return;const t={};this._configuration.columns.forEach((e,i)=>{t[i]=e.hidden||!1});try{localStorage.setItem(this._getColumnVisibilityStorageKey(),JSON.stringify(t))}catch(e){console.warn("Failed to save column visibility to localStorage:",e)}}_loadColumnVisibility(){if(this._configuration)try{const t=localStorage.getItem(this._getColumnVisibilityStorageKey());if(t){const e=JSON.parse(t);this._configuration.columns.forEach((i,s)=>{e[s]!==void 0&&(i.hidden=e[s])})}}catch(t){console.warn("Failed to load column visibility from localStorage:",t)}}_initializeColumns(){this._configuration&&(this._searchColumns=[],this._exportColumns={},this._columns=[],this._configuration.columns.forEach(t=>{t.searchable&&t.data&&this._searchColumns.push(t.data),t.export&&t.data&&(this._exportColumns[t.data]=t.label),t.data&&this._columns.push(t.data)}),this._configuration.sortBy||(this._configuration.sortBy="id"),this._configuration.sort||(this._configuration.sort="asc"))}async _fetchData(t,e=!0,i,s){var l,o,c,h,p,d,u,f;if(!this._configuration)return;const n=t||(typeof this._configuration.data=="string"?this._configuration.data:null);if(!n||this._fetching||this._loading)return;e&&(this._fetching=!0,this.render()),this._loading=!0;const r=i||this._perPage,a=s!==void 0?s:this._offset;try{const _=new URLSearchParams({perPage:r.toString(),offset:a.toString(),search:this._search,sortBy:this._configuration.sortBy||"id",sort:this._configuration.sort||"asc",searchColumns:this._searchColumns.join(","),columns:this._columns.join(",")}),g={};this._configuration.headers&&(g.headers=this._configuration.headers);const m=await fetch(`${n}?${_.toString()}`,g);if(!m.ok)throw new Error(`HTTP error! status: ${m.status}`);const v=await m.json(),b=((l=v.content)==null?void 0:l.rows)||[],k=((o=v.content)==null?void 0:o.total)||0;if(this._configuration.loadMore&&a!==0)this._rows=this._rows.concat(b);else{let C=b;this._configuration.predefinedData?(C=[...this._configuration.predefinedData,...b],this._totalRows=k+this._configuration.predefinedData.length):this._totalRows=k,this._rows=C}const w=Math.floor(a/r)+1;this._configuration.loadMore||(((c=v.content)==null?void 0:c.current_page)!==void 0&&v.content.current_page===w?this._currentPage=v.content.current_page:this._currentPage=w,this._offset=(this._currentPage-1)*r),this._lastPage=((h=v.content)==null?void 0:h.last_page)||1,this._fetching=!1,this._loaded=!0,this._loading=!1,this._fetchError=null,this._searching=!1;const E=this._sorting;if(E&&this._updateSortIcons(),this._sorting=!1,this._sortingColumn=null,E&&this._updateSortIcons(),this.dispatchEvent(new CustomEvent("loaded",{detail:{rows:this._rows}})),this._updateSearchIcon(),(d=(p=this.querySelector(`#${this._tableId}`))==null?void 0:p.closest("table"))==null?void 0:d.querySelector("tbody")){if(E){const C=this._loading,D=this._fetching;this._loading=!1,this._fetching=!1,this._updateTableBody(),this._loading=C,this._fetching=D}else this._updateTableBody();this._updatePagination()}else this.render()}catch(_){this._fetching=!1,this._loading=!1,this._loaded=!0,this._searching=!1,this._fetchError=_ instanceof Error?_.message:"Failed to fetch data",console.error("mint-resource-table: Error fetching data",_),this._updateSearchIcon(),((f=(u=this.querySelector(`#${this._tableId}`))==null?void 0:u.closest("table"))==null?void 0:f.querySelector("tbody"))?(this._updateTableBody(),this._updatePagination()):this.render()}}_getRows(){if(!this._configuration)return[];if(this._type==="ajax")return this._rows;let t=[...this._rows];const e=this._configuration.sortBy||"id",i=this._configuration.sort||"asc";if(this._search){const s=this._search.toLowerCase().trim().split(/\s+/);t=t.filter(n=>{const r=Object.values(n).map(a=>String(a).toLowerCase()).join(" ");return s.every(a=>r.includes(a))})}if(t.sort((s,n)=>{const r=s[e],a=n[e];if(r==null&&a==null)return 0;if(r==null)return 1;if(a==null)return-1;const l=typeof r=="number"?r:typeof r=="string"&&!isNaN(Number(r))&&r.trim()!==""?Number(r):null,o=typeof a=="number"?a:typeof a=="string"&&!isNaN(Number(a))&&a.trim()!==""?Number(a):null;if(l!==null&&o!==null){const d=l-o;return i==="asc"?d:-d}const c=r instanceof Date?r:typeof r=="string"?new Date(r):null,h=a instanceof Date?a:typeof a=="string"?new Date(a):null;if(c&&h&&!isNaN(c.getTime())&&!isNaN(h.getTime())){const d=c.getTime()-h.getTime();return i==="asc"?d:-d}const p=String(r).localeCompare(String(a),void 0,{numeric:!0,sensitivity:"base"});return i==="asc"?p:-p}),this._perPage){const s=Math.ceil(t.length/this._perPage);this._lastPage=s,t.forEach((n,r)=>{n.page=Math.ceil((r+1)/this._perPage)}),this._currentPage>s&&s>0&&(this._currentPage=s)}return this._configuration.loadMore?t.slice(0,this._rowsToShow):t.filter(s=>!this._perPage||s.page===this._currentPage)}_toggleSort(t){var i;if(!this._configuration||!t.data||!t.sortable)return;const e=t.data;if(this._sortTimeoutId!==null&&(clearTimeout(this._sortTimeoutId),this._sortTimeoutId=null),this._sorting=!0,this._sortingColumn=t,this._updateSortIcons(),this._type==="ajax")this._sortTimeoutId=window.setTimeout(()=>{var n;if(this._sortTimeoutId=null,!this._configuration||!e||!t.sortable)return;let s=this._configuration.sort||"asc";((n=this._configuration.sortBy)==null?void 0:n.toLowerCase())===e.toLowerCase()&&(s=s==="desc"?"asc":"desc"),this._configuration.sort=s,this._configuration.sortBy=e,this._updateSortIcons(),this._offset=0,this._currentPage=1,this._configuration.loadMore&&(this._rowsToShow=this._perPage),this._fetching=!1,this._loading=!1,this._configuration.loadMore?this._fetchData(void 0,!1,this._perPage,0):this._fetchData(void 0,!1,this._perPage,0)},10);else{let s=this._configuration.sort||"asc";((i=this._configuration.sortBy)==null?void 0:i.toLowerCase())===e.toLowerCase()&&(s=s==="desc"?"asc":"desc"),this._configuration.sort=s,this._configuration.sortBy=e,this._currentPage=1,this._sorting=!1,this._sortingColumn=null,this._updateSortIcons(),this.render()}}_getSortClass(t){var e,i,s,n,r;return this._sorting&&this._sortingColumn===t?"spinner":((i=(e=this._configuration)==null?void 0:e.sortBy)==null?void 0:i.toLowerCase())===((s=t.data)==null?void 0:s.toLowerCase())?((r=(n=this._configuration)==null?void 0:n.sort)==null?void 0:r.toLowerCase())==="desc"?"caret-down":"caret-up":""}_updateSortIcons(){this._configuration&&this._configuration.columns.forEach((t,e)=>{if(!t.sortable||t.hidden)return;const i=this.querySelector(`th[data-column-key="${e}"]`);if(!i)return;const s=i.querySelector(".ml-2.flex.items-center");if(!s)return;const n=s.querySelector("mint-icon"),r=s.querySelector("mint-spinner"),a=this._getSortClass(t);if(a==="spinner"){if(n&&n.remove(),!r){const l=document.createElement("mint-spinner");l.className="w-4 h-4",s.appendChild(l)}}else if(r&&r.remove(),n)n.setAttribute("name",a),n.className=`w-4 h-4 ${a==="sort-arrows"?"text-gray-400":""}`;else{const l=document.createElement("mint-icon");l.setAttribute("name",a),l.className=`w-4 h-4 ${a==="sort-arrows"?"text-gray-400":""}`,s.appendChild(l)}})}_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},400)}_updateSearchIcon(){const t=this.querySelector(`#search-${this._tableId}`);if(!t)return;const e=this._type==="ajax"&&(this._searching||this._fetching);setTimeout(()=>{const i=t.querySelector(".relative")||t.querySelector("div");if(!i)return;const s=i.querySelector("mint-icon"),n=i.querySelector("mint-spinner");if(e){if(s&&!n){const r=document.createElement("mint-spinner");r.className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none",s.replaceWith(r)}else if(!s&&!n){const r=document.createElement("mint-spinner");r.className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none",i.appendChild(r)}}else if(n){t.getAttribute("icon")||t.setAttribute("icon","search");const r=document.createElement("mint-icon");r.setAttribute("name","search"),r.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",n.replaceWith(r)}},0)}_updateTableBody(){var a,l;if(!this._configuration)return;const t=this._getRows(),e=(l=(a=this.querySelector(`#${this._tableId}`))==null?void 0:a.closest("table"))==null?void 0:l.querySelector("tbody");if(!e){this.render();return}const i=this.querySelector(`#search-${this._tableId}`),s=document.activeElement===i||(i==null?void 0:i.querySelector("input"))===document.activeElement,n=this._search;let r="";if(!((this._fetching||this._loading)&&!this._sorting)&&(t.forEach((o,c)=>{const h=typeof this._configuration.onRowClick=="function",p=h?"cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors":"";r+=`<tr data-row-index="${c}" ${h?'data-row-clickable="true"':""}${p?` class="${p}"`:""}>`,this._configuration.columns.forEach((d,u)=>{if(d.hidden)return;const f=!d.show||d.show(this,o);if(r+=`<td style="${this._getStyle(d)}" class="${this._getClasses(d,!0)}">`,f)if(d.raw)if(d.action)(!d.action.show||d.action.show(this,o))&&(r+=`<mint-button variant="solid" data-action="column-action" data-row-index="${c}" data-column-key="${this._configuration.columns.indexOf(d)}">${d.action.label}</mint-button>`);else if(d.actions)if(d.actionStyle!=="buttons"){const _=`actions-popover-${this._tableId}-${c}`,g=`actions-button-${this._tableId}-${c}`;r+=`<mint-button id="${g}" variant="link" icon="ellipsis">`,r+="</mint-button>",r+=`<mint-popover id="${_}" trigger-id="${g}" direction="down">`,d.actions.forEach((m,v)=>{if(!m.show||m.show(this,o)){const b=typeof m.label=="function"?m.label(this,o):m.label;r+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${c}" data-action-index="${v}" data-column-key="${this._configuration.columns.indexOf(d)}">${b}</div>`}}),r+="</mint-popover>"}else d.actions.forEach((_,g)=>{if(!_.show||_.show(this,o)){const m=_.label?typeof _.label=="function"?_.label(this,o):_.label:"",v=_.icon?` icon="${this._escapeHtml(_.icon)}"`:"",b=_.tone?` tone="${this._escapeHtml(_.tone)}"`:"";r+=`<mint-button variant="link" class="${_.classes||""}" data-action="row-action" data-row-index="${c}" data-action-index="${g}" data-column-key="${this._configuration.columns.indexOf(d)}"${v}${b}>`,m&&(r+=this._escapeHtml(String(m))),r+="</mint-button>"}});else typeof d.format=="function"?r+=d.format(this,o):d.data&&(r+=this._escapeHtml(String(o[d.data]||"")));else if(d.action){if(!d.action.show||d.action.show(this,o)){const _=typeof d.action.label=="function"?d.action.label(this,o):d.action.label;r+=`<mint-button variant="solid" data-action="column-action" data-row-index="${c}" data-column-key="${this._configuration.columns.indexOf(d)}">${this._escapeHtml(String(_))}</mint-button>`}}else if(d.actions)if(d.actionStyle!=="buttons"){const _=`actions-popover-${this._tableId}-${c}`,g=`actions-button-${this._tableId}-${c}`;r+=`<mint-button id="${g}" variant="link" icon="ellipsis">`,r+="</mint-button>",r+=`<mint-popover id="${_}" trigger-id="${g}" direction="down">`,d.actions.forEach((m,v)=>{if(!m.show||m.show(this,o)){const b=typeof m.label=="function"?m.label(this,o):m.label;r+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${c}" data-action-index="${v}" data-column-key="${this._configuration.columns.indexOf(d)}">${b}</div>`}}),r+="</mint-popover>"}else d.actions.forEach((_,g)=>{if(!_.show||_.show(this,o)){const m=_.label?typeof _.label=="function"?_.label(this,o):_.label:"",v=_.icon?` icon="${this._escapeHtml(_.icon)}"`:"",b=_.tone?` tone="${this._escapeHtml(_.tone)}"`:"";r+=`<mint-button variant="link" class="${_.classes||""}" data-action="row-action" data-row-index="${c}" data-action-index="${g}" data-column-key="${this._configuration.columns.indexOf(d)}"${v}${b}>`,m&&(r+=this._escapeHtml(String(m))),r+="</mint-button>"}});else typeof d.format=="function"?r+=this._escapeHtml(d.format(this,o)):d.data&&(r+=this._escapeHtml(String(o[d.data]||"")));r+="</td>"}),r+="</tr>"}),t.length===0&&(this._fetchError?r+=`<tr><td colspan="${this._configuration.columns.filter(o=>!o.hidden).length}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`:r+=`<tr><td colspan="${this._configuration.columns.filter(o=>!o.hidden).length}" class="text-center py-8">No records found.</td></tr>`),e.innerHTML=r,this._attachTableEventListeners(),this._attachRowClickHandler(),s&&i)){const o=i.querySelector("input")||i._element;o?(o.value=n,setTimeout(()=>{o.focus(),o.setSelectionRange(n.length,n.length)},0)):i.value!==void 0&&(i.value=n,setTimeout(()=>{i.focus()},0))}}_updatePagination(){var s,n;if(!this._configuration)return;const t=this._lastPage||Math.ceil(this._rows.length/this._perPage);if(!this._configuration.perPage||this._configuration.loadMore||t<=1){const r=(s=this.querySelector("nav"))==null?void 0:s.closest(".flex.justify-end");r&&r.remove();return}let e=(n=this.querySelector("nav"))==null?void 0:n.closest(".flex.justify-end");if(!e){const r=this.querySelector("mint-table");if(!r){this.render();return}e=document.createElement("div"),e.className="flex justify-end "+(this._inMintCard?"p-3.5":"mt-4"),r.insertAdjacentElement("afterend",e)}let i="<nav>";i+='<ul class="flex gap-1">',i+=`<li><mint-button variant="solid" size="sm" icon="caret-left" ${this._currentPage===1?'disabled="true"':""} data-action="page-prev"></mint-button></li>`;for(let r=1;r<=Math.min(2,t);r++){const l=this._currentPage===r?' disabled="true"':"";i+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}if(t>2&&(i+='<li><span class="px-2">...</span></li>'),this._currentPage>2&&this._currentPage<t-1&&(i+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage-1}">${this._currentPage-1}</mint-button></li>`,i+=`<li><mint-button variant="solid" size="sm" disabled="true" data-action="page" data-page="${this._currentPage}">${this._currentPage}</mint-button></li>`,i+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage+1}">${this._currentPage+1}</mint-button></li>`),t>2)for(let r=Math.max(t-1,this._currentPage+2);r<=t;r++){const l=this._currentPage===r?' disabled="true"':"";i+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}i+=`<li><mint-button variant="solid" size="sm" icon="caret-right" ${this._currentPage>=t?'disabled="true"':""} data-action="page-next"></mint-button></li>`,i+="</ul>",i+="</nav>",e.innerHTML=i,setTimeout(()=>{this._attachPaginationListeners(),e.querySelectorAll("mint-button[data-action]").forEach(r=>{"render"in r&&typeof r.render=="function"&&r.render()})},0)}_loadMore(){this._loading||this._fetching||!(this._type==="ajax"?this._lastPage>0&&this._currentPage<this._lastPage:this._totalRows>0&&this._rowsToShow<this._totalRows)||(this._offset+=this._perPage,this._currentPage+=1,this._rowsToShow+=this._perPage,this._type==="ajax"?this._fetchData():this.render())}_goToPage(t){const e=this._lastPage||Math.ceil(this._rows.length/this._perPage);t>e&&(t=e),t<1&&(t=1),this._currentPage=t,this._offset=(t-1)*this._perPage,this._updatePageInUrl(t),this._type==="ajax"?this._fetchData():this.render()}_handleButtonClick(t){if(this._configuration)switch(t.type){case"export":break;case"print":window.print();break;case"csv":this._downloadCSV();break;default:t.onClick&&t.onClick(this);break}}_downloadCSV(){if(!this._configuration)return;const t=this.querySelector("table");if(!t)return;const e=t.querySelectorAll("tr");let i="data:text/csv;charset=utf-8,";e.forEach(r=>{const a=[];r.querySelectorAll("th, td").forEach(l=>{var c;const o=l.getAttribute("colspan");if(o)for(let h=0;h<parseInt(o)-1;h++)a.push("");a.push('"'+((c=l.textContent)==null?void 0:c.trim().replace(/"/g,'""'))+'"')}),i+=a.join(",")+`
|
|
153
|
-
`});const s=encodeURI(i),n=document.createElement("a");n.setAttribute("href",s),n.setAttribute("download",`${this._configuration.export_name||this._tableId}.csv`),document.body.appendChild(n),n.click(),document.body.removeChild(n)}_columnChange(t,e){const i=t.target.checked;e.hidden=!i,this._saveColumnVisibility();const s=`edit-columns-popover-${this._tableId}`,n=this.querySelector(`#${s}`),r=n==null?void 0:n.hasAttribute("open");this.render(),r&&n&&requestAnimationFrame(()=>{const a=this.querySelector(`#${s}`);a&&typeof a.open=="function"&&a.open()})}_getStyle(t){let e="";return(t.nowrap||t.actions)&&(e+="white-space: nowrap;"),t.offsetLeft&&(e+=`left: ${t.offsetLeft} !important;`),t.offsetRight&&(e+=`right: ${t.offsetRight} !important;`),t.width&&(e+=`min-width: ${t.width}px; max-width: ${t.width}px;`),e}_getClasses(t,e=!1){const i=[];return t.class&&i.push(t.class.trim()),t.sortable&&!e&&i.push("cursor-pointer"),t.stickLeft&&i.push("sticky-left"),t.stickRight&&i.push("sticky-right"),i.join(" ")}render(){if(!this._configuration){this.innerHTML='<div class="p-4 text-red-500">Error: Invalid configuration</div>';return}const t=!this._loaded||this._rows.length>0||this._search.length>0||this._searching,e=this._getRows(),i=this._lastPage||Math.ceil(this._rows.length/this._perPage);let s="";if(t){if(s+='<div class="flex '+(this._inMintCard?"p-3.5":"mb-3")+'">',s+='<div class="flex-grow-1 flex-1">',s+='<div class="flex gap-2 items-center">',this._configuration.showSearch!==!1){const r=`search-${this._tableId}`;s+=`<mint-input id="${r}" type="search" label="" placeholder="Search..." class="flex-1" icon="search" value="${this._escapeHtml(this._search)}"></mint-input>`}if(this._configuration.buttons&&this._configuration.buttons.forEach(r=>{const a=r.icon?` icon="${this._escapeHtml(r.icon)}"`:"",l=r.tone?` tone="${this._escapeHtml(r.tone)}"`:"";s+=`<mint-button variant="solid" class="${r.class||""}" data-button-type="${r.type||"custom"}"${a}${l}>`,r.label&&(s+=this._escapeHtml(r.label)),s+="</mint-button>"}),s+="</div>",s+="</div>",this._configuration.editColumns!==!1&&this._configuration.columns.some(a=>!a.actions&&a.editable!==!1)){const a=`edit-columns-popover-${this._tableId}`,l=`edit-columns-button-${this._tableId}`;s+='<div class="ml-2">',s+=`<mint-button id="${l}" variant="solid" icon="edit"></mint-button>`,s+=`<mint-popover id="${a}" trigger-id="${l}" direction="down">`,this._configuration.columns.forEach(o=>{!o.actions&&o.editable!==!1&&(s+='<div class="p-2">',s+=`<mint-checkbox label="${o.label}" ${o.hidden?"":"checked"} data-column-key="${this._configuration.columns.indexOf(o)}"></mint-checkbox>`,s+="</div>")}),s+="</mint-popover>",s+="</div>"}s+="</div>"}if(this._type==="ajax"&&(!this._loaded||this._fetching||this._loading)&&!this._fetchError&&!this._sorting){s+='<mint-table class="table-section'+(this._inMintCard?" rounded-t-none":"")+'">',s+=`<table id="${this._tableId}">`,s+="<thead><tr>",this._configuration.columns.forEach((r,a)=>{r.hidden||(s+=`<th width="${r.width||""}" style="${this._getStyle(r)}" class="${this._getClasses(r)}" data-column-key="${a}">`,r.showLabel!==!1&&(s+='<div class="flex items-center">',s+=`<div class="flex-1">${r.raw?r.label:this._escapeHtml(r.label)}</div>`,r.sortable&&(s+='<div class="ml-2 flex items-center">',s+='<mint-icon name="" class="w-4 h-4 text-gray-400"></mint-icon>',s+="</div>"),s+="</div>"),s+="</th>")}),s+="</tr></thead>",s+="<tbody>";for(let r=0;r<4;r++)s+="<tr>",this._configuration.columns.forEach(a=>{a.hidden||(s+=`<td style="${this._getStyle(a)}" class="${this._getClasses(a,!0)}">`,s+='<div class="h-4 bg-gray-200 dark:bg-gray-700 rounded animate-pulse"></div>',s+="</td>")}),s+="</tr>";if(s+="</tbody>",s+="</table>",s+="</mint-table>",this._configuration.perPage&&!this._configuration.loadMore&&(i>1||this._lastPage>0)){const r=this._lastPage>0?this._lastPage:i;if(r>1){s+='<div class="flex justify-end '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+="<nav>",s+='<ul class="flex gap-1">',s+=`<li><mint-button variant="solid" size="sm" icon="caret-left" ${this._currentPage===1?'disabled="true"':""} data-action="page-prev"></mint-button></li>`;for(let a=1;a<=Math.min(2,r);a++){const o=this._currentPage===a?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${o} data-action="page" data-page="${a}">${a}</mint-button></li>`}if(r>2&&(s+='<li><span class="px-2">...</span></li>'),this._currentPage>2&&this._currentPage<r-1&&(s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage-1}">${this._currentPage-1}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" disabled="true" data-action="page" data-page="${this._currentPage}">${this._currentPage}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage+1}">${this._currentPage+1}</mint-button></li>`),r>2)for(let a=Math.max(r-1,this._currentPage+2);a<=r;a++){const o=this._currentPage===a?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${o} data-action="page" data-page="${a}">${a}</mint-button></li>`}s+=`<li><mint-button variant="solid" size="sm" icon="caret-right" ${this._currentPage>=r?'disabled="true"':""} data-action="page-next"></mint-button></li>`,s+="</ul>",s+="</nav>",s+="</div>"}}}else if(e.length>0||this._search.length>0||this._searching||this._fetchError){if(s+='<mint-table class="table-section'+(this._inMintCard?" rounded-t-none":"")+'">',s+=`<table id="${this._tableId}">`,s+="<thead><tr>",this._configuration.columns.forEach((r,a)=>{if(!r.hidden){if(s+=`<th width="${r.width||""}" style="${this._getStyle(r)}" class="${this._getClasses(r)}" data-column-key="${a}">`,r.showLabel!==!1){if(s+='<div class="flex items-center">',s+=`<div class="flex-1">${r.raw?r.label:this._escapeHtml(r.label)}</div>`,r.sortable){s+='<div class="ml-2 flex items-center">';const l=this._getSortClass(r);l==="spinner"?s+='<mint-spinner class="w-4 h-4"></mint-spinner>':s+=`<mint-icon name="${l}" class="w-4 h-4 ${l==="sort-arrows"?"text-gray-400":""}"></mint-icon>`,s+="</div>"}s+="</div>"}s+="</th>"}}),s+="</tr></thead>",s+="<tbody>",!this._fetching&&!this._loading&&e.forEach((r,a)=>{const l=typeof this._configuration.onRowClick=="function",o=l?"cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors":"";s+=`<tr data-row-index="${a}" ${l?'data-row-clickable="true"':""}${o?` class="${o}"`:""}>`,this._configuration.columns.forEach((c,h)=>{if(c.hidden)return;const p=!c.show||c.show(this,r);if(s+=`<td style="${this._getStyle(c)}" class="${this._getClasses(c,!0)}">`,p)if(c.raw)if(c.action){if(!c.action.show||c.action.show(this,r)){const d=typeof c.action.label=="function"?c.action.label(this,r):c.action.label;s+=`<mint-button variant="solid" data-action="column-action" data-row-index="${a}" data-column-key="${this._configuration.columns.indexOf(c)}">${this._escapeHtml(String(d))}</mint-button>`}}else if(c.actions)if(c.actionStyle!=="buttons"){const d=`actions-popover-${this._tableId}-${a}`,u=`actions-button-${this._tableId}-${a}`;s+=`<mint-button id="${u}" variant="link" icon="ellipsis">`,s+="</mint-button>",s+=`<mint-popover id="${d}" trigger-id="${u}" direction="down">`,c.actions.forEach((f,_)=>{if(!f.show||f.show(this,r)){const g=typeof f.label=="function"?f.label(this,r):f.label;s+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${a}" data-action-index="${_}" data-column-key="${this._configuration.columns.indexOf(c)}">${this._escapeHtml(String(g))}</div>`}}),s+="</mint-popover>"}else c.actions.forEach((d,u)=>{if(!d.show||d.show(this,r)){const f=d.label?typeof d.label=="function"?d.label(this,r):d.label:"",_=d.icon?` icon="${this._escapeHtml(d.icon)}"`:"",g=d.tone?` tone="${this._escapeHtml(d.tone)}"`:"";s+=`<mint-button variant="link" class="${d.classes||""}" data-action="row-action" data-row-index="${a}" data-action-index="${u}" data-column-key="${this._configuration.columns.indexOf(c)}"${_}${g}>`,f&&(s+=this._escapeHtml(String(f))),s+="</mint-button>"}});else typeof c.format=="function"?s+=c.format(this,r):c.data&&(s+=this._escapeHtml(String(r[c.data]||"")));else if(c.action)(!c.action.show||c.action.show(this,r))&&(s+=`<mint-button variant="solid" data-action="column-action" data-row-index="${a}" data-column-key="${this._configuration.columns.indexOf(c)}">${c.action.label}</mint-button>`);else if(c.actions)if(c.actionStyle!=="buttons"){const d=`actions-popover-${this._tableId}-${a}`,u=`actions-button-${this._tableId}-${a}`;s+=`<mint-button id="${u}" variant="link" icon="ellipsis">`,s+="</mint-button>",s+=`<mint-popover id="${d}" trigger-id="${u}" direction="down">`,c.actions.forEach((f,_)=>{if(!f.show||f.show(this,r)){const g=typeof f.label=="function"?f.label(this,r):f.label;s+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${a}" data-action-index="${_}" data-column-key="${this._configuration.columns.indexOf(c)}">${this._escapeHtml(String(g))}</div>`}}),s+="</mint-popover>"}else c.actions.forEach((d,u)=>{if(!d.show||d.show(this,r)){const f=d.label?typeof d.label=="function"?d.label(this,r):d.label:"",_=d.icon?` icon="${this._escapeHtml(d.icon)}"`:"",g=d.tone?` tone="${this._escapeHtml(d.tone)}"`:"";s+=`<mint-button variant="link" class="${d.classes||""}" data-action="row-action" data-row-index="${a}" data-action-index="${u}" data-column-key="${this._configuration.columns.indexOf(c)}"${_}${g}>`,f&&(s+=this._escapeHtml(String(f))),s+="</mint-button>"}});else typeof c.format=="function"?s+=this._escapeHtml(c.format(this,r)):c.data&&(s+=this._escapeHtml(String(r[c.data]||"")));s+="</td>"}),s+="</tr>"}),!this._fetching&&!this._loading&&e.length===0&&(this._fetchError?s+=`<tr><td colspan="${this._configuration.columns.filter(r=>!r.hidden).length}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`:s+=`<tr><td colspan="${this._configuration.columns.filter(r=>!r.hidden).length}" class="text-center py-8">No records found.</td></tr>`),s+="</tbody>",s+="</table>",this._configuration.loadMore&&(this._loading||this._fetching?(s+='<div class="flex justify-center '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+="<mint-spinner></mint-spinner>",s+="</div>"):(this._type==="ajax"?this._lastPage>0&&this._currentPage<this._lastPage:this._totalRows>0&&this._rowsToShow<this._totalRows)&&(s+='<div class="flex justify-center '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+='<mint-button variant="ghost" data-action="load-more">Load more</mint-button>',s+="</div>")),this._configuration.perPage&&!this._configuration.loadMore&&this._loaded&&i>1){s+='<div class="flex justify-end '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+="<nav>",s+='<ul class="flex gap-1">',s+=`<li><mint-button variant="solid" size="sm" icon="caret-left" ${this._currentPage===1?'disabled="true"':""} data-action="page-prev"></mint-button></li>`;for(let r=1;r<=Math.min(2,i);r++){const l=this._currentPage===r?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}if(i>2&&(s+='<li><span class="px-2">...</span></li>'),this._currentPage>2&&this._currentPage<i-1&&(s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage-1}">${this._currentPage-1}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" disabled="true" data-action="page" data-page="${this._currentPage}">${this._currentPage}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage+1}">${this._currentPage+1}</mint-button></li>`),i>2)for(let r=Math.max(i-1,this._currentPage+2);r<=i;r++){const l=this._currentPage===r?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}s+=`<li><mint-button variant="solid" size="sm" icon="caret-right" ${this._currentPage>=i?'disabled="true"':""} data-action="page-next"></mint-button></li>`,s+="</ul>",s+="</nav>",s+="</div>"}s+="</mint-table>"}else s+='<slot name="empty"></slot>';this.innerHTML=s,this.querySelectorAll("mint-button[data-action]").forEach(r=>{r.render&&r.render()}),this.querySelectorAll("mint-button[data-button-type]").forEach(r=>{r.render&&r.render()}),this._attachEventListeners(),this._type==="ajax"&&!this._loaded&&!this._fetching&&!this._loading&&this._fetchData()}_attachRowClickHandler(){this._rowClickHandler&&this.removeEventListener("click",this._rowClickHandler,!0);const t=e=>{var o;const i=e.target;if(i.tagName==="MINT-BUTTON"||i.tagName==="BUTTON"||i.closest("mint-button")||i.closest("button")||i.closest("mint-popover")||i.closest("[data-action]"))return;const s=i.closest('tr[data-row-clickable="true"]');if(!s)return;const n=s.getAttribute("data-row-index");if(!n)return;const r=parseInt(n),l=this._getRows()[r];!l||!((o=this._configuration)!=null&&o.onRowClick)||(this._configuration.onRowClick.length===1?this._configuration.onRowClick(l):this._configuration.onRowClick(this,l))};this.addEventListener("click",t,!0),this._rowClickHandler=t}_attachPaginationListeners(){this.querySelectorAll('[data-action="page"]').forEach(t=>{t.addEventListener("click",()=>{const e=parseInt(t.getAttribute("data-page")||"1");this._goToPage(e)})}),this.querySelectorAll('[data-action="page-prev"]').forEach(t=>{t.addEventListener("click",()=>{this._goToPage(this._currentPage-1)})}),this.querySelectorAll('[data-action="page-next"]').forEach(t=>{t.addEventListener("click",()=>{this._goToPage(this._currentPage+1)})})}_attachTableEventListeners(){this.querySelectorAll('[data-action="row-action"]').forEach(t=>{t.addEventListener("click",()=>{var l;const e=parseInt(t.getAttribute("data-row-index")||"0"),i=parseInt(t.getAttribute("data-action-index")||"0"),s=parseInt(t.getAttribute("data-column-key")||"0"),r=this._getRows()[e],a=(l=this._configuration)==null?void 0:l.columns[s];a&&a.actions&&a.actions[i]&&a.actions[i].onClick(this,r)})}),this.querySelectorAll('[data-action="column-action"]').forEach(t=>{t.addEventListener("click",()=>{var a;const e=parseInt(t.getAttribute("data-row-index")||"0"),i=parseInt(t.getAttribute("data-column-key")||"0"),n=this._getRows()[e],r=(a=this._configuration)==null?void 0:a.columns[i];r&&r.action&&r.action.onClick(this,n)})})}_attachEventListeners(){var e;const t=this.querySelector(`#search-${this._tableId}`);if(t){const i=t.querySelector("input")||t._element;i?i.addEventListener("input",s=>{this._search=s.target.value,this._triggerSearch()}):t.addEventListener("input",s=>{this._search=t.value||s.target.value||"",this._triggerSearch()})}if(this._attachTableEventListeners(),this._attachRowClickHandler(),this.querySelectorAll("th[data-column-key]").forEach(i=>{i.addEventListener("click",()=>{var r;const s=parseInt(i.getAttribute("data-column-key")||"0"),n=(r=this._configuration)==null?void 0:r.columns[s];n&&this._toggleSort(n)})}),this.querySelectorAll("[data-button-type]").forEach(i=>{i.addEventListener("click",()=>{var r,a;const s=i.getAttribute("data-button-type"),n=(a=(r=this._configuration)==null?void 0:r.buttons)==null?void 0:a.find(l=>(l.type||"custom")===s);n&&this._handleButtonClick(n)})}),this.querySelectorAll("mint-checkbox[data-column-key]").forEach(i=>{i.addEventListener("change",s=>{var a;s.stopPropagation();const n=parseInt(i.getAttribute("data-column-key")||"0"),r=(a=this._configuration)==null?void 0:a.columns[n];r&&this._columnChange(s,r)}),i.addEventListener("click",s=>{s.stopPropagation()})}),this._attachPaginationListeners(),this.querySelectorAll('[data-action="load-more"]').forEach(i=>{i.addEventListener("click",()=>{this._loadMore()})}),(e=this._configuration)!=null&&e.loadMore){this._scrollHandler&&window.removeEventListener("scroll",this._scrollHandler);const i=()=>{const s=window.pageYOffset||document.documentElement.scrollTop,n=window.innerHeight;if(document.documentElement.scrollHeight-s-n<=100){const a=this._type==="ajax"?this._lastPage>0&&this._currentPage<this._lastPage:this._totalRows>0&&this._rowsToShow<this._totalRows;!this._loading&&!this._fetching&&a&&this._loadMore()}};this._scrollHandler=i,window.addEventListener("scroll",i)}}_escapeHtml(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}_getPageFromUrl(){if(!this._tableId)return null;const e=new URLSearchParams(window.location.search).get(`mui.${this._tableId}`);if(!e)return null;const i=parseInt(e,10);return isNaN(i)||i<1?null:i}_updatePageInUrl(t){if(!this._tableId)return;const e=new URL(window.location.href),i=e.searchParams;i.set(`mui.${this._tableId}`,t.toString()),t===1&&i.set(`mui.${this._tableId}`,"1"),window.history.replaceState({},"",e.toString())}_loadPageFromUrl(){if(!this._configuration||!this._tableId)return;const t=this._getPageFromUrl();t!==null&&(this._currentPage=t,this._offset=(this._currentPage-1)*this._perPage)}}customElements.get("mint-resource-table")||customElements.define("mint-resource-table",St);class Lt extends HTMLElement{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}static get observedAttributes(){return["id","heading","open","position","full-page","width"]}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()}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null)}attributeChangedCallback(t,e,i){e!==i&&this.render()}getId(){return this.getAttribute("id")||""}getHeading(){return this.getAttribute("heading")||""}getPosition(){var e;const t=(e=this.getAttribute("position"))==null?void 0:e.toLowerCase();return t==="top"||t==="bottom"||t==="left"||t==="right"?t:"right"}isFullPage(){return this.getAttribute("full-page")==="true"}getWidth(){return this.getAttribute("width")||"w-80"}isOpen(){return this.getAttribute("open")==="true"}open(){this.setAttribute("open","true")}close(){this.removeAttribute("open")}render(){const t=this.getId(),e=this.getHeading(),i=this.isOpen(),s=this.getPosition(),n=this.isFullPage();t&&(this.id=t),this._overlay||(this._overlay=document.createElement("div"),this._overlay.className="fixed inset-0 bg-black bg-opacity-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));const r=this._getPositionClasses(s,n);this._offCanvas.className=r;let a=this._offCanvas.querySelector(".off-canvas-content");if(a||(a=document.createElement("div"),a.className="off-canvas-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 shadow-xl flex flex-col pointer-events-auto transition-all duration-300 ease-out",a.style.transform=this._getTransformValue(s,!1),this._offCanvas.appendChild(a)),i?this._animateEnter():this._animateExit(),Array.from(a.classList).forEach(f=>{(f.startsWith("w-")||f.startsWith("max-w-"))&&a.classList.remove(f)}),a.classList.remove("h-full","max-h-[90vh]","max-h-screen"),n)a.classList.add("w-full","h-full");else{const f=this.getWidth();s==="top"||s==="bottom"?a.classList.add("w-full","max-h-[90vh]"):a.classList.add(f,"h-full")}this._header||(this._header=document.createElement("div"),this._header.className="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",a.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 o=this._headingSlot.querySelector("mint-text");e?(o||(o=document.createElement("mint-text"),o.setAttribute("size","sub-heading"),o.setAttribute("bold","true"),this._headingSlot.appendChild(o)),o.textContent=e):o&&o.remove(),Array.from(this.children).filter(f=>f!==this._overlay&&f!==this._offCanvas&&f!==this._headingSlot&&f.getAttribute("slot")==="heading").forEach(f=>{this._headingSlot&&f.parentElement!==this._headingSlot&&this._headingSlot.appendChild(f)}),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"),a.appendChild(this._bodySlot)),Array.from(this.children).filter(f=>f!==this._overlay&&f!==this._offCanvas&&f!==this._bodySlot&&f.getAttribute("slot")==="body").forEach(f=>{this._bodySlot&&f.parentElement!==this._bodySlot&&this._bodySlot.appendChild(f)}),this._actionsSlot||(this._actionsSlot=document.createElement("div"),this._actionsSlot.className="p-4 border-t border-gray-200 dark:border-gray-700 flex-shrink-0",this._actionsSlot.setAttribute("slot","actions"),a.appendChild(this._actionsSlot));let p=this._actionsSlot.querySelector("mint-stack");p||(p=document.createElement("mint-stack"),p.setAttribute("direction","horizontal"),p.className="justify-end",this._actionsSlot.appendChild(p)),Array.from(this.children).filter(f=>f!==this._overlay&&f!==this._offCanvas&&f!==this._actionsSlot&&f.getAttribute("slot")==="actions").forEach(f=>{Array.from(f.children).forEach(g=>{g.parentElement!==p&&p.appendChild(g)}),f.parentElement&&f.remove()}),Array.from(this.children).forEach(f=>{f!==this._overlay&&f!==this._offCanvas&&f.getAttribute("slot")!=="heading"&&f.getAttribute("slot")!=="body"&&f.getAttribute("slot")!=="actions"&&f!==this._headingSlot&&f!==this._bodySlot&&f!==this._actionsSlot&&f.parentElement!==this._bodySlot&&this._bodySlot.appendChild(f)}),this._updateBackgroundColor()}_getPositionClasses(t,e){const i="fixed z-50 pointer-events-none transition-all duration-300 ease-out";switch(t){case"top":return`${i} top-0 left-0 right-0 ${e?"h-full":""}`;case"bottom":return`${i} bottom-0 left-0 right-0 ${e?"h-full":""}`;case"left":return`${i} left-0 top-0 bottom-0 ${e?"w-full":""}`;case"right":return`${i} right-0 top-0 bottom-0 ${e?"w-full":""}`;default:return`${i} right-0 top-0 bottom-0 ${e?"w-full":""}`}}_getTransformValue(t,e){if(e)switch(t){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(t){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;const t=document.documentElement.classList.contains("dark"),e=this._offCanvas.querySelector(".off-canvas-content");e&&(t?(e.classList.remove("bg-white"),e.classList.add("bg-gray-900","border","border-gray-700")):(e.classList.remove("bg-gray-900","border","border-gray-700"),e.classList.add("bg-white")))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_animateEnter(){var i;const t=(i=this._offCanvas)==null?void 0:i.querySelector(".off-canvas-content");if(!t)return;const e=this.getPosition();t.style.transform=this._getTransformValue(e,!1),t.style.transition="transform 300ms ease-out",this.classList.remove("hidden"),requestAnimationFrame(()=>{requestAnimationFrame(()=>{t.style.transform=this._getTransformValue(e,!0)})})}_animateExit(){var i;const t=(i=this._offCanvas)==null?void 0:i.querySelector(".off-canvas-content");if(!t){this.classList.add("hidden");return}const e=this.getPosition();t.style.transition="transform 300ms ease-in",t.style.transform=this._getTransformValue(e,!1),setTimeout(()=>{this.classList.add("hidden"),t.style.transform="",t.style.transition=""},300)}}customElements.get("mint-off-canvas")||customElements.define("mint-off-canvas",Lt);class Dt extends HTMLElement{constructor(){super(),this._clickHandler=null}static get observedAttributes(){return["active","disabled","target"]}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getTarget(){return this.getAttribute("target")||""}isActive(){const t=this.getAttribute("active");return t!==null&&t!=="false"}isDisabled(){return this.getAttribute("disabled")==="true"}get active(){return this.isActive()}set active(t){t?this.setAttribute("active","true"):this.setAttribute("active","false")}render(){const t=this.isActive(),e=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","transition-all","duration-200","rounded-lg","border","text-gray-700","dark:text-gray-300");const i=this.closest("mint-tab-list"),s=(i==null?void 0:i.getAttribute("position"))||"top",n=s==="left"||s==="right";e?(this.classList.add("opacity-60","cursor-not-allowed","pointer-events-none","bg-gray-50","dark:bg-gray-900","border-gray-300","dark:border-gray-700","text-gray-400","dark:text-gray-500"),this.classList.remove("cursor-pointer")):t?(this.classList.add("bg-white","dark:bg-gray-900","border-gray-200","dark:border-gray-700","text-gray-900","dark:text-gray-100","shadow-sm","relative","z-10"),n?s==="left"?this.classList.add("mr-[-1px]"):this.classList.add("ml-[-1px]"):this.classList.add("mb-[-1px]")):this.classList.add("bg-gray-100","dark:bg-gray-900","border-gray-200","dark:border-gray-700","text-gray-600","dark:text-gray-400","hover:bg-gray-50","dark:hover:bg-gray-600")}setupEventListeners(){this.isDisabled()||this._clickHandler||(this._clickHandler=this.handleClick.bind(this),this.addEventListener("click",this._clickHandler))}removeEventListeners(){this._clickHandler&&(this.removeEventListener("click",this._clickHandler),this._clickHandler=null)}handleClick(t){if(this.isDisabled()){t.preventDefault(),t.stopPropagation();return}t.__mintTabsSynthetic||(t.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",Dt);class Tt extends HTMLElement{static get observedAttributes(){return["position"]}constructor(){super()}connectedCallback(){this.render()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getPosition(){return this.getAttribute("position")||"top"}render(){const t=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-gray-900","dark:border-gray-700","border-gray-200","w-auto","rounded-lg","gap-2"),t==="top"?this.classList.add("inline-flex","flex-row","mb-0","self-start"):t==="left"?this.classList.add("flex","flex-col","mr-0"):t==="right"&&this.classList.add("flex","flex-col","ml-0")}}customElements.get("mint-tab-list")||customElements.define("mint-tab-list",Tt);class Mt 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(t,e,i){e!==i&&t==="id"&&(this.render(),this.checkInitialVisibility())}getId(){return this.getAttribute("id")||""}show(){this.style.display="block"}hide(){this.style.display="none"}checkInitialVisibility(){const t=this.closest("mint-tabs");if(!t){this.style.display="none";return}const e=t.querySelectorAll("mint-tab");let i=!1;if(e.forEach(s=>{const n=s.getAttribute("active"),r=s.getAttribute("target"),a=this.getId();n==="true"&&r===a&&(i=!0)}),!i&&e.length>0){const n=e[0].getAttribute("target"),r=this.getId();n===r&&!t.querySelector('mint-tab[active="true"]')&&(i=!0)}i?this.style.display="block":this.style.display="none"}render(){}}customElements.get("mint-tab-content")||customElements.define("mint-tab-content",Mt);class Ht 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(),this._mutationObserver=null)}render(){const t=this.querySelector("mint-tab-list");if(this.querySelectorAll("mint-tab-content"),!t){console.warn("mint-tabs: mint-tab-list is required");return}const e=t.getAttribute("position")||"top";this.classList.remove("flex","flex-row","flex-col","gap-4","gap-6"),e==="left"||e==="right"?(this.classList.add("flex","flex-row","items-start"),e==="left"?(t.classList.add("mr-4","flex-shrink-0"),t.classList.remove("ml-4")):(t.classList.add("ml-4","flex-shrink-0","order-2"),t.classList.remove("mr-4"),this.querySelectorAll("mint-tab-content").forEach(s=>{s.classList.add("order-1")}))):(this.classList.add("flex","flex-col"),t.classList.remove("mr-4","ml-4","flex-shrink-0","order-2"),this.querySelectorAll("mint-tab-content").forEach(s=>{s.classList.remove("order-1")}))}initializeActiveTab(){requestAnimationFrame(()=>{const t=this.querySelectorAll("mint-tab");let e=null;if(t.forEach(s=>{s.getAttribute("active")==="true"&&(e=s)}),!e&&t.length>0&&(e=t[0],e.setAttribute("active","true")),e){const s=e.getAttribute("target");s?this.showContent(s):this.hideAllContent()}else this.hideAllContent();this.querySelectorAll("mint-tab-content").forEach(s=>{const n=s;n.checkInitialVisibility&&n.checkInitialVisibility()})})}hideAllContent(){this.querySelectorAll("mint-tab-content").forEach(e=>{const i=e;i.hide?i.hide():e.style.display="none"})}showContent(t){this.querySelectorAll("mint-tab-content").forEach(s=>{const n=s;n.hide?n.hide():s.style.display="none"});const i=this.querySelector(`mint-tab-content[id="${t}"]`);i&&(i.show?i.show():i.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),this._tabClickHandler=null)}setupMutationObserver(){this._mutationObserver=new MutationObserver(()=>{this.render()});const t=this.querySelector("mint-tab-list");t&&this._mutationObserver.observe(t,{attributes:!0,attributeFilter:["position"]})}handleTabClick(t){var r,a;const e=(r=t.detail)==null?void 0:r.tab,i=(a=t.detail)==null?void 0:a.target;if(!e)return;const s=e.closest("mint-tab-list");if(!s)return;s.querySelectorAll("mint-tab").forEach(l=>{const o=l;l===e?o.active=!0:o.active=!1}),i&&this.showContent(i)}}customElements.get("mint-tabs")||customElements.define("mint-tabs",Ht);const K=class K extends HTMLElement{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=.3,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._cachedBounds={bounds:null,dataHash:""},this._cachedYRange={range:null,dataHash:""},this._cachedXValues={values:null,dataHash:""},this._widthValue="100%",this._heightValue=400,this._defaultColors=["#3b82f6","#ef4444","#10b981","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#f97316"],this._legendHeight=0,this._rotatedLabelHeight=0}static get observedAttributes(){return["type","data","width","height","show-legend","show-grid","show-tooltip","curve-tension"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full");let t=this._getReactiveValue(this.data);t&&typeof t=="object"&&!Array.isArray(t)&&"datasets"in t&&(this._chartData=t),this._setupDataObserver(),this._setupDarkModeObserver(),this._setupResizeObserver(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.render()})})}_getReactiveValue(t){if(!t||typeof t!="object")return t;if("_value"in t||"__v_isRef"in t){if(typeof t.value<"u")return t.value;if("_value"in t)return t._value}return"__v_raw"in t||"__v_isReactive"in t||"__ob__"in t,t}_setupDataObserver(){let t=null,e=0;const i=()=>{if(!this.isConnected)return;const n=this._getReactiveValue(this.data);let r=null;n&&typeof n=="object"&&!Array.isArray(n)&&"datasets"in n&&(r=n),r!==t&&r&&(t=r,this._chartData=r,this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this.render())};requestAnimationFrame(()=>{i(),requestAnimationFrame(()=>{i()})});const s=setInterval(()=>{if(!this.isConnected){clearInterval(s);return}if(i(),e++,e>50){clearInterval(s);const n=setInterval(()=>{if(!this.isConnected){clearInterval(n);return}i()},1e3);this._dataCheckInterval=n}},100);this._dataCheckInterval=s}_setupDarkModeObserver(){this._darkModeObserver=new MutationObserver(()=>{this.isConnected&&this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]})}disconnectedCallback(){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(t=>clearTimeout(t)),this._pieChartTimeouts.clear(),this._pieChartClickOutsideHandler&&(document.removeEventListener("click",this._pieChartClickOutsideHandler,!0),this._pieChartClickOutsideHandler=null),this._chartClickOutsideHandler&&(document.removeEventListener("click",this._chartClickOutsideHandler,!0),this._chartClickOutsideHandler=null),this._pieChartTooltipShown=!1,this._pieChartGroup=null,this._pinnedXValue=null,this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._dataObserver&&(this._dataObserver.disconnect(),this._dataObserver=null),this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null),this._dataCheckInterval&&(clearInterval(this._dataCheckInterval),this._dataCheckInterval=null),this._svg&&(this._chartTooltipMouseMove&&(this._svg.removeEventListener("mousemove",this._chartTooltipMouseMove),this._chartTooltipMouseMove=null),this._chartTooltipMouseLeave&&(this._svg.removeEventListener("mouseleave",this._chartTooltipMouseLeave),this._chartTooltipMouseLeave=null),this._chartTooltipTouchStart&&(this._svg.removeEventListener("touchstart",this._chartTooltipTouchStart),this._chartTooltipTouchStart=null),this._chartTooltipTouchMove&&(this._svg.removeEventListener("touchmove",this._chartTooltipTouchMove),this._chartTooltipTouchMove=null),this._chartTooltipTouchEnd&&(this._svg.removeEventListener("touchend",this._chartTooltipTouchEnd),this._chartTooltipTouchEnd=null)),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._windowResizeHandler&&(window.removeEventListener("resize",this._windowResizeHandler),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(){var r,a;if(!this.isConnected)return;const t=this.getBoundingClientRect(),e=t.width||((r=this.parentElement)==null?void 0:r.clientWidth)||800,i=t.height||((a=this.parentElement)==null?void 0:a.clientHeight)||400,s=this._calculateDimension(this._widthValue,e,e),n=this._calculateDimension(this._heightValue,i,400);(s!==this._width||n!==this._height)&&(this._width=s,this._height=n,this.render())}_setupResizeObserver(){this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._windowResizeHandler&&(window.removeEventListener("resize",this._windowResizeHandler),this._windowResizeHandler=null);let t=null;const e=()=>{t&&clearTimeout(t),t=window.setTimeout(()=>{this._handleResize()},100)};this._windowResizeHandler=e,this._resizeObserver=new ResizeObserver(()=>{e()}),this._resizeObserver.observe(this),window.addEventListener("resize",e)}attributeChangedCallback(t,e,i){if(e!==i){if(t==="data"&&this.data&&typeof this.data=="object"&&(this._chartData=this.data),(t==="width"||t==="height")&&this.isConnected){const s=e&&e.endsWith("%"),n=i&&i.endsWith("%");s!==n&&this._setupResizeObserver()}this.isConnected&&requestAnimationFrame(()=>{this.render()})}}get type(){const t=this.getAttribute("type")||"line";return t==="line"||t==="bar"||t==="area"||t==="pie"?t:"line"}set type(t){this.setAttribute("type",t)}get data(){return this._chartData}set data(t){if(typeof t=="string")try{this._chartData=JSON.parse(t)}catch(e){console.error("mint-chart: Invalid data JSON",e),this._chartData=null}else this._chartData=t;this.isConnected&&requestAnimationFrame(()=>{this.render()})}get width(){const t=this.getAttribute("width");if(!t)return this._widthValue;if(t.endsWith("%"))return t;const e=parseInt(t,10);return isNaN(e)?this._widthValue:e}set width(t){this.setAttribute("width",t.toString())}get height(){const t=this.getAttribute("height");if(!t)return this._heightValue;if(t.endsWith("%"))return t;const e=parseInt(t,10);return isNaN(e)?this._heightValue:e}set height(t){this.setAttribute("height",t.toString())}_calculateDimension(t,e,i){if(typeof t=="number")return t;if(typeof t=="string"&&t.endsWith("%")){const s=parseFloat(t);if(!isNaN(s))return e*s/100}return i}render(){var r,a,l,o;if(!this.isConnected)return;this._plotPoints.clear(),this._activeXValue=null,(r=this._cachedTooltipContent)==null||r.clear(),(a=this._cachedXPositions)==null||a.clear(),this._chartType=this.type;let t=this._getReactiveValue(this.data);if(t&&typeof t=="object"&&!Array.isArray(t)&&"datasets"in t&&(this._chartData=t),!this._chartData){const c=this.getAttribute("data");if(c)try{this._chartData=JSON.parse(c)}catch(h){console.error("mint-chart: Invalid data JSON",h),this._chartData=null}}this._widthValue=this.width,this._heightValue=this.height;const e=this.getBoundingClientRect(),i=e.width||((l=this.parentElement)==null?void 0:l.clientWidth)||800,s=e.height||((o=this.parentElement)==null?void 0:o.clientHeight)||400;this._width=this._calculateDimension(this._widthValue,i,i),this._height=this._calculateDimension(this._heightValue,s,400),this._showLegend=this.getAttribute("show-legend")!=="false",this._showGrid=this.getAttribute("show-grid")!=="false",this._showTooltip=this.getAttribute("show-tooltip")!=="false";const n=this.getAttribute("curve-tension");if(n!==null){const c=parseFloat(n);this._curveTension=isNaN(c)?.3:Math.max(0,Math.min(1,c))}else this._curveTension=.3;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._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._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-gray-800 text-white text-xs rounded px-2 py-1 shadow-lg opacity-0 transition-opacity",this._tooltip.style.display="none",document.body.appendChild(this._tooltip)}_showTooltipAt(t,e,i){if(!this._tooltip)return;this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._lastTooltipContent!==i&&(this._tooltip.innerHTML=i,this._lastTooltipContent=i),(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");const n=this._tooltip.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight;let l=t+10,o=e-n.height-8;l+n.width>r&&(l=t-n.width-10),l<0&&(l=10),o<0&&(o=e+20),o+n.height>a&&(o=e-n.height-8,o<0&&(o=10));const c=`${l}px`,h=`${o}px`;this._tooltip.style.left!==c&&(this._tooltip.style.left=c),this._tooltip.style.top!==h&&(this._tooltip.style.top=h)}_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");const t=document.documentElement.classList.contains("dark");this._verticalLine.setAttribute("stroke",t?"#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";const e=this._svg.querySelector(".chart-legend");e&&e.parentNode?e.parentNode.insertBefore(this._verticalLine,e):this._svg.appendChild(this._verticalLine)}_showVerticalLineAtX(t,e){if(!this._verticalLine)return;const s=this._chartType==="bar"?this._scaleXForBarChart(t,e):this._scaleX(t,e);this._verticalLine.setAttribute("x1",s.toString()),this._verticalLine.setAttribute("y1",e.y.toString()),this._verticalLine.setAttribute("x2",s.toString()),this._verticalLine.setAttribute("y2",(e.y+e.height).toString()),this._verticalLine.style.opacity="1"}_hideVerticalLine(){this._verticalLine&&(this._verticalLine.style.opacity="0")}_showPlotPointsForX(t){this._plotPoints.forEach(s=>{s.forEach(n=>{n.style.opacity="0"})});const e=String(t),i=this._plotPoints.get(e);i&&i.forEach(s=>{s.style.opacity="1"})}_hidePlotPoints(){this._plotPoints.forEach(t=>{t.forEach(e=>{e.style.opacity="0"})})}_calculateMaxYAxisLabelWidth(){if(!this._showGrid||!this._chartData)return 0;const e=document.createElement("canvas").getContext("2d");if(!e)return 60;e.font="12px system-ui, -apple-system, sans-serif";const i=this._showLegend?Math.max(this._legendHeight,60):0,s=this._height-i,r=Math.floor(s/35),a=Math.min(5,r);let l=0;for(let o=0;o<=a;o++){const c=this._getYRange(),h=c.max-(c.max-c.min)/a*o,p=this._formatYAxisValue(h),d=e.measureText(p);l=Math.max(l,d.width)}return Math.ceil(l)+20}_getChartBounds(){const t=this._calculateMaxYAxisLabelWidth(),e=`${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${t}-${this._rotatedLabelHeight}`;if(this._cachedBounds.bounds&&this._cachedBounds.dataHash===e)return this._cachedBounds.bounds;let i=0,s=0,n=0,r=0;this._showGrid&&(i=Math.max(t,60));const o=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12;let c=o;this._showLegend&&(c=o+20+Math.max(this._legendHeight,60));const h=this._height-n-i-s,p=h-c,d=100;let u=1;if(p<d&&c>0){const _=h-d;_>0?(u=Math.min(1,_/c),u=Math.max(.5,u)):u=.5}r=c*u;const f={width:this._width-i-s,height:this._height-n-r,x:i,y:n};return this._cachedBounds={bounds:f,dataHash:e},f}_getAllDataPoints(){if(!this._chartData)return[];const t=[];return this._chartData.datasets.forEach(e=>{t.push(...e.data)}),t}_getXValues(){if(!this._chartData)return[];const t=JSON.stringify(this._chartData.labels)+JSON.stringify(this._chartData.datasets.map(s=>s.data.map(n=>n.x)));if(this._cachedXValues.values&&this._cachedXValues.dataHash===t)return this._cachedXValues.values;if(this._chartData.labels&&this._chartData.labels.length>0)return this._cachedXValues={values:this._chartData.labels,dataHash:t},this._chartData.labels;const e=new Set;this._chartData.datasets.forEach(s=>{s.data.forEach(n=>{e.add(n.x)})});const i=Array.from(e).sort((s,n)=>{if(typeof s=="number"&&typeof n=="number")return s-n;const r=String(s),a=String(n),l=/^([A-Za-z]{3})\s+(\d{4})$/,o=r.match(l),c=a.match(l);if(o&&c){const h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=h.indexOf(o[1]),d=h.indexOf(c[1]),u=parseInt(o[2]),f=parseInt(c[2]);return u!==f?u-f:p-d}return r.localeCompare(a)});return this._cachedXValues={values:i,dataHash:t},i}_getYRange(){if(!this._chartData)return{min:0,max:100};const t=JSON.stringify(this._chartData.datasets.map(l=>l.data.map(o=>o.y)));if(this._cachedYRange.range&&this._cachedYRange.dataHash===t)return this._cachedYRange.range;const e=this._getAllDataPoints();if(e.length===0){const l={min:0,max:100};return this._cachedYRange={range:l,dataHash:t},l}const i=e.map(l=>l.y),s=Math.min(...i),n=Math.max(...i),r=(n-s)*.1,a={min:Math.max(0,s-r),max:n+r};return this._cachedYRange={range:a,dataHash:t},a}_hasDecimalValues(){return this._getAllDataPoints().some(e=>e.y%1!==0)}_formatValueByString(t,e){switch(e.toLowerCase()){case"currency":case"currency-usd":return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t);case"currency-eur":return new Intl.NumberFormat("en-US",{style:"currency",currency:"EUR"}).format(t);case"currency-gbp":return new Intl.NumberFormat("en-US",{style:"currency",currency:"GBP"}).format(t);case"number":case"number-with-commas":return new Intl.NumberFormat("en-US").format(t);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:1}).format(t/100);default:return this._hasDecimalValues()&&t%1!==0?t.toFixed(1):Math.round(t).toString()}}_formatXAxisValue(t){var e;if((e=this._chartData)!=null&&e.formatXAxis){if(typeof this._chartData.formatXAxis=="function")return this._chartData.formatXAxis(t);if(typeof this._chartData.formatXAxis=="string")return String(t)}return String(t)}_formatYAxisValue(t){var i,s,n,r;if((i=this._chartData)!=null&&i.formatYAxis){if(typeof this._chartData.formatYAxis=="function")return this._chartData.formatYAxis(t);if(typeof this._chartData.formatYAxis=="string")return this._formatValueByString(t,this._chartData.formatYAxis)}if((r=(n=(s=this._chartData)==null?void 0:s.datasets)==null?void 0:n[0])!=null&&r.formatValue){if(typeof this._chartData.datasets[0].formatValue=="function")return this._chartData.datasets[0].formatValue(t);if(typeof this._chartData.datasets[0].formatValue=="string")return this._formatValueByString(t,this._chartData.datasets[0].formatValue)}return this._hasDecimalValues()&&t%1!==0?t.toFixed(1):Math.round(t).toString()}_formatValue(t,e){if(e.formatValue){if(typeof e.formatValue=="function")return e.formatValue(t);if(typeof e.formatValue=="string")return this._formatValueByString(t,e.formatValue)}return String(t)}_getAllDatasetsAtX(t){if(!this._chartData)return[];const e=[];return this._chartData.datasets.forEach((i,s)=>{const n=i.data.find(r=>String(r.x)===String(t));if(n){const r=this._getDatasetColor(i,s),a=this._formatValue(n.y,i);e.push({name:i.name,value:n.y,color:r,formattedValue:a})}}),e}_findNearestXValue(t){if(!this._chartData)return null;const e=this._getChartBounds(),i=this._getXValues();if(i.length===0)return null;const s=this._chartType==="bar";let n=null,r=1/0;return i.forEach(a=>{const l=s?this._scaleXForBarChart(a,e):this._scaleX(a,e),o=Math.abs(t-l);o<r&&(r=o,n=a)}),n}_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();const t=this._getChartBounds();let e=0,i=0;const s=c=>{!this._chartContainer||!this._svg||(e=c.clientX,i=c.clientY,this._tooltipAnimationFrame!==null&&cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=requestAnimationFrame(()=>{if(this._tooltipAnimationFrame=null,!this._svg)return;const h=this._svg.getBoundingClientRect(),p=e-h.left,d=i-h.top;if(p<t.x||p>t.x+t.width||d<t.y||d>t.y+t.height){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}const u=this._findNearestXValue(p);if(!u){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}if(this._pinnedXValue!==null&&this._pinnedXValue===u){const g=this._pinnedXValue,m=this._getAllDatasetsAtX(g);if(m.length>0){this._activeXValue=g,this._showPlotPointsForX(g),this._showVerticalLineAtX(g,t);let v=this._cachedTooltipContent.get(g);v||(v=`<strong>${g}</strong><br/>`,m.forEach(b=>{v+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
152
|
+
`,document.head.appendChild(t)}}customElements.get("mint-table")||customElements.define("mint-table",xt);class Et extends HTMLElement{constructor(){super(...arguments),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(){var i;if(this.classList.add("inline-flex","items-center","gap-2","px-3","py-1","rounded-full","border","border-gray-200","dark:border-gray-700","bg-gray-100","dark:bg-gray-900","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;){const s=this.firstChild;if(s===this._root)break;this._textWrap.appendChild(s)}this._root.appendChild(this._textWrap),this.appendChild(this._root)}this.getAttribute("dismissable")==="true"?(this._dismissBtn||this._createDismissBtn(),this._dismissBtn&&!this._dismissBtn.isConnected&&((i=this._root)==null||i.appendChild(this._dismissBtn))):this._dismissBtn&&this._dismissBtn.parentElement===this._root&&this._dismissBtn.remove()}_createDismissBtn(){const t=document.createElement("button");t.type="button",t.setAttribute("aria-label","Dismiss"),t.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","transition-colors","duration-150","border-none","bg-transparent","cursor-pointer"].join(" ");const e=document.createElement("mint-icon");e.setAttribute("name","close"),e.className="w-3 h-3",t.appendChild(e),this._clickHandler=i=>{i.stopPropagation(),this.dispatchEvent(new CustomEvent("dismissed",{bubbles:!0,composed:!0}))},t.addEventListener("click",this._clickHandler),this._dismissBtn=t}}customElements.get("mint-chip")||customElements.define("mint-chip",Et);class wt extends HTMLElement{constructor(){super(...arguments),this._container=null,this._chipsWrap=null,this._input=null,this._tags=[],this._placeholder="Add tag",this._dragIndex=null,this._dragChip=null,this._isPointerDragging=!1,this._pointerMoveHandler=null,this._pointerUpHandler=null}static get observedAttributes(){return["tags","placeholder","sortable","label","info","error","error-message","name","id","required","loading"]}connectedCallback(){this._parseAttrs(),this._render(),this._pointerMoveHandler||(this._pointerMoveHandler=t=>this._onPointerMove(t),window.addEventListener("pointermove",this._pointerMoveHandler)),this._pointerUpHandler||(this._pointerUpHandler=t=>this._onPointerUp(t),window.addEventListener("pointerup",this._pointerUpHandler),window.addEventListener("pointercancel",this._pointerUpHandler))}attributeChangedCallback(t,e,i){if(e!==i){if(t==="error"||t==="error-message"){if(this._renderErrorState(),this._container){const s=this.hasError(),n=["flex","flex-wrap","items-center","gap-2","w-full","px-2","py-1.5","min-h-[2rem]","rounded-lg","border-2",s?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","bg-white","dark:bg-gray-900","focus-within:ring-2","focus-within:ring-offset-1",s?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","transition-colors","duration-200"];this._container.className=n.join(" ")}return}if(t==="loading"){this._parseAttrs(),this._render();return}this._parseAttrs(),this._render()}}set tags(t){this._tags=Array.isArray(t)?[...t]:[],this._syncAttr(),this._render()}get tags(){return[...this._tags]}_parseAttrs(){const t=this.getAttribute("tags");if(!t)return;try{const i=JSON.parse(t);Array.isArray(i)&&(this._tags=i)}catch(i){console.warn("mint-tags: failed to parse tags attribute",i)}const e=this.getAttribute("placeholder");e!==null&&(this._placeholder=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"}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")}_render(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full");const t=this.isLoading(),e=this.getLabel(),i=this.getInfo(),s=this.hasError(),n=this.getId()||`mint-tags-${Math.random().toString(36).substr(2,9)}`;if(this.getId()||this.setAttribute("id",n),this._container)this._input&&(this._input.placeholder=this._placeholder);else{this._container=document.createElement("div");const o=["flex","flex-wrap","items-center","gap-2","w-full","px-2","py-1","min-h-[2rem]","rounded-lg","border-2",s?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","bg-white","dark:bg-gray-800","focus-within:ring-2","focus-within:ring-offset-1",s?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","transition-colors","duration-200"];this._container.className=o.join(" "),this._chipsWrap=document.createElement("div"),this._chipsWrap.className="flex flex-wrap items-center gap-2",this._chipsWrap.addEventListener("dragover",c=>{this.hasAttribute("sortable")&&c.preventDefault()}),this._chipsWrap.addEventListener("drop",c=>{this.hasAttribute("sortable")&&c.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",c=>{c.key==="Enter"&&(c.preventDefault(),this._addFromInput())}),this._container.appendChild(this._chipsWrap),this.appendChild(this._container)}if(this._container){const o=["flex","flex-wrap","items-center","gap-2","w-full","px-2","py-1","min-h-[2rem]","rounded-lg","border-2",s?"border-red-300 dark:border-red-300":"border-gray-200 dark:border-gray-700","bg-white","dark:bg-gray-800","focus-within:ring-2","focus-within:ring-offset-1",s?"focus-within:ring-red-400 dark:focus-within:ring-red-500":"focus-within:ring-gray-400 dark:focus-within:ring-gray-500","transition-colors","duration-200"];this._container.className=o.join(" ")}let r=this.querySelector(".mint-tags-label-container");if(e){r||(r=document.createElement("div"),r.className="mint-tags-label-container mb-[.25rem]",this._container&&this._container.parentElement===this?this.insertBefore(r,this._container):this.insertBefore(r,this.firstChild));let o=r.querySelector(".mint-tags-label");e?(o||(o=document.createElement("label"),o.className="mint-tags-label text-sm font-medium text-gray-900 dark:text-gray-100 select-none",r.appendChild(o)),o.textContent=e,o.setAttribute("for",n)):o&&o.remove()}else r&&r.remove();let a=this.querySelector(".mint-tags-info");i?(a||(a=document.createElement("span"),a.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(a,this._container.nextSibling):this.appendChild(a)),a.textContent=i):a&&a.remove();const l=this.getName();l?(this.setAttribute("name",l),this._input&&(this._input.name=l,this._input.id=n)):(this.removeAttribute("name"),this._input&&(this._input.removeAttribute("name"),this._input.id=n)),this._wireInputBackspace(),this._renderChips(),this._renderErrorState(),this._renderSkeleton(t)}_renderSkeleton(t){const e=this._container;if(!e)return;e.classList.contains("relative")||e.classList.add("relative");let i=e.querySelector(".mint-tags-skeleton");t?(i||(i=document.createElement("div"),i.className="mint-tags-skeleton absolute inset-0 z-10 pointer-events-none rounded-lg bg-gray-200 dark:bg-gray-700 animate-pulse",e.appendChild(i)),i.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")):(i&&(i.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(){const t=this.hasError(),e=this.getErrorMessage();let i=this.querySelector(".mint-tags-error");t&&e?(i||(i=document.createElement("div"),i.className="mint-tags-error mt-1 text-xs text-red-600 dark:text-red-400",this.appendChild(i)),i.textContent=e):i&&i.remove()}_renderChips(){if(!this._chipsWrap)return;this._chipsWrap.innerHTML="";let t=0;this._tags.forEach(e=>{const i=document.createElement("mint-chip");i.dataset.index=String(t++),i.dataset.value=e.value,i.draggable=this.hasAttribute("sortable"),i.draggable&&i.classList.add("cursor-move"),e.dismissable&&(i.setAttribute("dismissable","true"),i.addEventListener("dismissed",()=>this._removeTag(e.value))),this._chipsWrap.appendChild(i);const s=i.querySelector("[data-mt-chip-text]");s&&(s.textContent=e.label||e.value),this._setupChipEvents(i,e),i.draggable&&(i.addEventListener("dragstart",n=>this._onDragStart(n,i)),i.addEventListener("dragover",n=>this._onDragOverChip(n,i)),i.addEventListener("drop",n=>this._onDrop(n)),i.addEventListener("dragend",()=>this._onDragEnd())),this.hasAttribute("sortable")&&i.addEventListener("pointerdown",n=>this._onPointerDown(n,i))}),this._input&&(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;const t=this._input.value.trim();if(!t)return;if(this._tags.some(i=>i.value.toLowerCase()===t.toLowerCase())){this._input.value="";return}this._tags.push({value:t,label:t,dismissable:!0}),this._syncAttr(),this._renderChips(),this._emitChange(),this._input.value="",setTimeout(()=>{var i;(i=this._input)==null||i.focus()},10)}_removeTag(t){this._tags=this._tags.filter(e=>e.value!==t),this._syncAttr(),this._renderChips(),this._emitChange()}_emitChange(){this.dispatchEvent(new CustomEvent("tags-change",{bubbles:!0,composed:!0,detail:{tags:this.tags}}))}_focusLastChip(){var e;const t=(e=this._chipsWrap)==null?void 0:e.querySelectorAll("mint-chip");t&&t.length>0&&t[t.length-1].focus({preventScroll:!0})}_focusInput(){setTimeout(()=>{var t;(t=this._input)==null||t.focus({preventScroll:!0})},10)}_wireInputBackspace(){this._input&&this._input.addEventListener("keydown",t=>{var e;t.key==="Backspace"&&((e=this._input)==null?void 0:e.value)===""&&(t.preventDefault(),this._focusLastChip())})}_setupChipEvents(t,e){t.tabIndex=0,t.addEventListener("keydown",i=>{(i.key==="Backspace"||i.key==="Delete")&&e.dismissable&&(i.preventDefault(),this._removeTag(e.value),this._focusInput())})}_onDragStart(t,e){var i;this.hasAttribute("sortable")&&(this._dragChip=e,this._dragIndex=Number(e.dataset.index),(i=t.dataTransfer)==null||i.setData("text/plain",e.dataset.index||""),t.dataTransfer&&(t.dataTransfer.effectAllowed="move",t.dataTransfer.dropEffect="move"),e.classList.add("opacity-60"))}_reorderTags(t,e){if(t<0||e<0||t>=this._tags.length||e>=this._tags.length)return;const i=[...this._tags],[s]=i.splice(t,1);i.splice(e,0,s),this._tags=i,this._syncAttr(),this._renderChips(),this._emitChange()}_onDragOverInput(t){this.hasAttribute("sortable")&&(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="move"),this._dragChip&&this._chipsWrap&&this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input))}_onDragOverChip(t,e){if(!this.hasAttribute("sortable")||(t.preventDefault(),t.dataTransfer&&(t.dataTransfer.dropEffect="move"),!this._dragChip||!this._chipsWrap)||e===this._dragChip)return;const i=e.getBoundingClientRect(),s=t.clientX,n=i.left+i.width*.5;if(s<n){if(this._dragChip.nextSibling===e)return;this._chipsWrap.insertBefore(this._dragChip,e)}else{if(e.nextSibling===this._dragChip)return;const r=e.nextSibling;r?this._chipsWrap.insertBefore(this._dragChip,r):this._chipsWrap.appendChild(this._dragChip)}}_onDrop(t){this.hasAttribute("sortable")&&t.preventDefault()}_onDragEnd(){this._dragChip&&this._dragChip.classList.remove("opacity-60"),this._syncOrderFromDom(),this._dragChip=null,this._dragIndex=null}_syncOrderFromDom(){if(!this._chipsWrap)return;const t=Array.from(this._chipsWrap.querySelectorAll("mint-chip"));if(t.length===0)return;const e=[];t.forEach(i=>{const s=i.dataset.value;if(!s)return;const n=this._tags.find(r=>r.value===s);n&&e.push(n)}),e.length===this._tags.length&&(this._tags=e,this._syncAttr(),this._renderChips(),this._emitChange())}_onPointerDown(t,e){if(this.hasAttribute("sortable")&&t.pointerType!=="mouse"){this._isPointerDragging=!0,this._dragChip=e,this._dragIndex=Number(e.dataset.index);try{e.setPointerCapture(t.pointerId)}catch{}e.classList.add("opacity-60","select-none"),t.preventDefault()}}_onPointerMove(t){if(!this._isPointerDragging||!this._dragChip||!this._chipsWrap||t.pointerType==="mouse")return;const e=document.elementFromPoint(t.clientX,t.clientY);if(!e)return;const i=e.closest("mint-chip");if(i&&i!==this._dragChip){const s=i.getBoundingClientRect(),n=t.clientX,r=s.left+s.width*.5;if(n<r)this._dragChip.nextSibling!==i&&this._chipsWrap.insertBefore(this._dragChip,i);else if(i.nextSibling!==this._dragChip){const a=i.nextSibling;a?this._chipsWrap.insertBefore(this._dragChip,a):this._chipsWrap.appendChild(this._dragChip)}return}this._input&&e.closest("input")===this._input&&this._chipsWrap.insertBefore(this._dragChip,this._input)}_onPointerUp(t){if(this._isPointerDragging){if(this._isPointerDragging=!1,this._dragChip){try{this._dragChip.releasePointerCapture(t.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",wt);class Ct extends HTMLElement{constructor(){super(...arguments),this._clickHandler=null,this._keydownHandler=null}connectedCallback(){this._render(),this._setupEventListeners()}disconnectedCallback(){this._cleanupEventListeners()}_render(){this.classList.add("transition-colors","duration-200","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=t=>{if(this.getAttribute("disabled")==="true"){t.preventDefault(),t.stopPropagation();return}this._handleClick(t)},this._keydownHandler=t=>{if(t.key==="Enter"||t.key===" "){if(this.getAttribute("disabled")==="true"){t.preventDefault(),t.stopPropagation();return}t.preventDefault(),this._handleClick(t)}},this.addEventListener("click",this._clickHandler),this.addEventListener("keydown",this._keydownHandler)}_cleanupEventListeners(){this._clickHandler&&(this.removeEventListener("click",this._clickHandler),this._clickHandler=null),this._keydownHandler&&(this.removeEventListener("keydown",this._keydownHandler),this._keydownHandler=null)}_handleClick(t){this.dispatchEvent(new CustomEvent("clickable-click",{bubbles:!0,composed:!0,detail:{originalEvent:t}}))}static get observedAttributes(){return["disabled"]}attributeChangedCallback(t,e,i){t==="disabled"&&(i==="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",Ct);class At extends HTMLElement{constructor(){super(),this._headingElement=null,this._iconElement=null,this._dismissButton=null,this._headerWrapper=null,this._bodyWrapper=null,this._dismissHandler=null}static get observedAttributes(){return["heading","dismissable","tone"]}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(t,e,i){e!==i&&this.render()}getHeading(){return this.getAttribute("heading")||""}getTone(){const t=this.getAttribute("tone");return t==="info"||t==="success"||t==="warning"||t==="danger"?t:"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-blue-600 dark:text-blue-400";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-blue-600 dark:text-blue-400"}}getHeadingColorClasses(){return"text-gray-900 dark:text-gray-100"}getHeaderBackgroundClasses(){switch(this.getTone()){case"info":return"bg-blue-100 dark:bg-blue-900/30";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-blue-100 dark:bg-blue-900/30"}}getBorderClasses(){switch(this.getTone()){case"info":return"border-blue-200 dark:border-blue-800";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-blue-200 dark:border-blue-800"}}getAriaLive(){return this.getTone()==="danger"?"assertive":"polite"}render(){const t=this.getTone(),e=this.getHeading(),i=this.isDismissable();this.className=`box-border m-0 p-0 border-0 align-baseline block rounded-lg border shadow-sm overflow-hidden transition-colors duration-200 ${this.getBorderClasses()}`;const s=this.getAriaLive();this.setAttribute("role","alert"),this.setAttribute("aria-live",s),t==="danger"?this.setAttribute("aria-atomic","true"):this.removeAttribute("aria-atomic");const n=[];for(this._bodyWrapper?Array.from(this._bodyWrapper.childNodes).forEach(a=>{n.push(a)}):Array.from(this.childNodes).forEach(r=>{r!==this._headerWrapper&&r!==this._bodyWrapper&&r!==this._iconElement&&r!==this._headingElement&&r!==this._dismissButton&&n.push(r)}),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=e||"",this._headerWrapper.appendChild(this._headingElement),i){this._dismissButton=document.createElement("button"),this._dismissButton.className="flex-shrink-0 p-1 rounded hover:bg-black/10 dark:hover:bg-white/10 transition-colors",this._dismissButton.setAttribute("aria-label","Dismiss alert"),this._dismissButton.setAttribute("type","button");const r=document.createElement("mint-icon");r.setAttribute("name","close"),r.className="w-4 h-4 text-gray-700 dark:text-gray-300",this._dismissButton.appendChild(r),this._dismissHandler=a=>{a.preventDefault(),a.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-gray-900",n.forEach(r=>{this._bodyWrapper.appendChild(r)}),this.appendChild(this._headerWrapper),this.appendChild(this._bodyWrapper)}}customElements.get("mint-alert")||customElements.define("mint-alert",At);class St extends HTMLElement{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._rowsToShow=15,this._loaded=!1,this._fetching=!1,this._loading=!1,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}static get observedAttributes(){return["configuration"]}get inMintCard(){return this._inMintCard}get configuration(){return this._configuration}set configuration(t){t&&typeof t=="object"&&!Array.isArray(t)?(this._configuration=t,this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._rowsToShow=this._perPage,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._loadColumnVisibility(),this.isConnected&&this.render()):t==null?this._configuration=null:this._parseConfiguration()}connectedCallback(){var t,e;this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full"),this._inMintCard=((e=(t=this.parentElement)==null?void 0:t.tagName)==null?void 0:e.toLowerCase())==="mint-card",this._configuration||this._parseConfiguration(),this._initializeColumns(),this._loadColumnVisibility(),this._loadPageFromUrl(),this._attachRowClickHandler(),this.render()}disconnectedCallback(){this._searchTimeoutId&&clearTimeout(this._searchTimeoutId),this._rowClickHandler&&(this.removeEventListener("click",this._rowClickHandler,!0),this._rowClickHandler=null),this._scrollHandler&&(window.removeEventListener("scroll",this._scrollHandler),this._scrollHandler=null)}attributeChangedCallback(t,e,i){t==="configuration"&&e!==i&&(!this._configuration||typeof i=="string")&&(this._parseConfiguration(),this.render())}refresh(){this._configuration&&(this._type==="ajax"?this._configuration.loadMore?(this._offset=0,this._currentPage=1,this._rowsToShow=this._perPage,this._rows=[],this._fetchData(void 0,!0,this._perPage,0)):this._fetchData(void 0,!0,this._perPage,this._offset):this.render())}_parseConfiguration(){const t=this.getAttribute("configuration");if(!t){console.error("mint-resource-table: configuration attribute is required");return}try{this._configuration=JSON.parse(t),this._tableId=this._configuration.id||`mint-resource-table-${Date.now()}`,this._perPage=this._configuration.perPage||15,this._rowsToShow=this._perPage,this._type=typeof this._configuration.data=="string"?"ajax":"provided",this._loaded=!1;const e=this._getPageFromUrl();this._currentPage=e||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(),this._loadColumnVisibility()}catch(e){console.error("mint-resource-table: Invalid configuration JSON",e)}}_getColumnVisibilityStorageKey(){return`mrtc-${this._tableId}`}_saveColumnVisibility(){if(!this._configuration)return;const t={};this._configuration.columns.forEach((e,i)=>{t[i]=e.hidden||!1});try{localStorage.setItem(this._getColumnVisibilityStorageKey(),JSON.stringify(t))}catch(e){console.warn("Failed to save column visibility to localStorage:",e)}}_loadColumnVisibility(){if(this._configuration)try{const t=localStorage.getItem(this._getColumnVisibilityStorageKey());if(t){const e=JSON.parse(t);this._configuration.columns.forEach((i,s)=>{e[s]!==void 0&&(i.hidden=e[s])})}}catch(t){console.warn("Failed to load column visibility from localStorage:",t)}}_initializeColumns(){this._configuration&&(this._searchColumns=[],this._exportColumns={},this._columns=[],this._configuration.columns.forEach(t=>{t.searchable&&t.data&&this._searchColumns.push(t.data),t.export&&t.data&&(this._exportColumns[t.data]=t.label),t.data&&this._columns.push(t.data)}),this._configuration.sortBy||(this._configuration.sortBy="id"),this._configuration.sort||(this._configuration.sort="asc"))}async _fetchData(t,e=!0,i,s){var l,o,c,h,f,d,p,u;if(!this._configuration)return;const n=t||(typeof this._configuration.data=="string"?this._configuration.data:null);if(!n||this._fetching||this._loading)return;e&&(this._fetching=!0,this.render()),this._loading=!0;const r=i||this._perPage,a=s!==void 0?s:this._offset;try{const _=new URLSearchParams({perPage:r.toString(),offset:a.toString(),search:this._search,sortBy:this._configuration.sortBy||"id",sort:this._configuration.sort||"asc",searchColumns:this._searchColumns.join(","),columns:this._columns.join(",")}),g={};this._configuration.headers&&(g.headers=this._configuration.headers);const m=await fetch(`${n}?${_.toString()}`,g);if(!m.ok)throw new Error(`HTTP error! status: ${m.status}`);const v=await m.json(),b=((l=v.content)==null?void 0:l.rows)||[],y=((o=v.content)==null?void 0:o.total)||0;if(this._configuration.loadMore&&a!==0)this._rows=this._rows.concat(b);else{let S=b;this._configuration.predefinedData?(S=[...this._configuration.predefinedData,...b],this._totalRows=y+this._configuration.predefinedData.length):this._totalRows=y,this._rows=S}const C=Math.floor(a/r)+1;this._configuration.loadMore||(((c=v.content)==null?void 0:c.current_page)!==void 0&&v.content.current_page===C?this._currentPage=v.content.current_page:this._currentPage=C,this._offset=(this._currentPage-1)*r),this._lastPage=((h=v.content)==null?void 0:h.last_page)||1,this._fetching=!1,this._loaded=!0,this._loading=!1,this._fetchError=null,this._searching=!1;const E=this._sorting;if(E&&this._updateSortIcons(),this._sorting=!1,this._sortingColumn=null,E&&this._updateSortIcons(),this.dispatchEvent(new CustomEvent("loaded",{detail:{rows:this._rows}})),this._updateSearchIcon(),(d=(f=this.querySelector(`#${this._tableId}`))==null?void 0:f.closest("table"))==null?void 0:d.querySelector("tbody")){if(E){const S=this._loading,w=this._fetching;this._loading=!1,this._fetching=!1,this._updateTableBody(),this._loading=S,this._fetching=w}else this._updateTableBody();this._updatePagination()}else this.render()}catch(_){this._fetching=!1,this._loading=!1,this._loaded=!0,this._searching=!1,this._fetchError=_ instanceof Error?_.message:"Failed to fetch data",console.error("mint-resource-table: Error fetching data",_),this._updateSearchIcon(),((u=(p=this.querySelector(`#${this._tableId}`))==null?void 0:p.closest("table"))==null?void 0:u.querySelector("tbody"))?(this._updateTableBody(),this._updatePagination()):this.render()}}_getRows(){if(!this._configuration)return[];if(this._type==="ajax")return this._rows;let t=[...this._rows];const e=this._configuration.sortBy||"id",i=this._configuration.sort||"asc";if(this._search){const s=this._search.toLowerCase().trim().split(/\s+/);t=t.filter(n=>{const r=Object.values(n).map(a=>String(a).toLowerCase()).join(" ");return s.every(a=>r.includes(a))})}if(t.sort((s,n)=>{const r=s[e],a=n[e];if(r==null&&a==null)return 0;if(r==null)return 1;if(a==null)return-1;const l=typeof r=="number"?r:typeof r=="string"&&!isNaN(Number(r))&&r.trim()!==""?Number(r):null,o=typeof a=="number"?a:typeof a=="string"&&!isNaN(Number(a))&&a.trim()!==""?Number(a):null;if(l!==null&&o!==null){const d=l-o;return i==="asc"?d:-d}const c=r instanceof Date?r:typeof r=="string"?new Date(r):null,h=a instanceof Date?a:typeof a=="string"?new Date(a):null;if(c&&h&&!isNaN(c.getTime())&&!isNaN(h.getTime())){const d=c.getTime()-h.getTime();return i==="asc"?d:-d}const f=String(r).localeCompare(String(a),void 0,{numeric:!0,sensitivity:"base"});return i==="asc"?f:-f}),this._perPage){const s=Math.ceil(t.length/this._perPage);this._lastPage=s,t.forEach((n,r)=>{n.page=Math.ceil((r+1)/this._perPage)}),this._currentPage>s&&s>0&&(this._currentPage=s)}return this._configuration.loadMore?t.slice(0,this._rowsToShow):t.filter(s=>!this._perPage||s.page===this._currentPage)}_toggleSort(t){var i;if(!this._configuration||!t.data||!t.sortable)return;const e=t.data;if(this._sortTimeoutId!==null&&(clearTimeout(this._sortTimeoutId),this._sortTimeoutId=null),this._sorting=!0,this._sortingColumn=t,this._updateSortIcons(),this._type==="ajax")this._sortTimeoutId=window.setTimeout(()=>{var n;if(this._sortTimeoutId=null,!this._configuration||!e||!t.sortable)return;let s=this._configuration.sort||"asc";((n=this._configuration.sortBy)==null?void 0:n.toLowerCase())===e.toLowerCase()&&(s=s==="desc"?"asc":"desc"),this._configuration.sort=s,this._configuration.sortBy=e,this._updateSortIcons(),this._offset=0,this._currentPage=1,this._configuration.loadMore&&(this._rowsToShow=this._perPage),this._fetching=!1,this._loading=!1,this._configuration.loadMore?this._fetchData(void 0,!1,this._perPage,0):this._fetchData(void 0,!1,this._perPage,0)},10);else{let s=this._configuration.sort||"asc";((i=this._configuration.sortBy)==null?void 0:i.toLowerCase())===e.toLowerCase()&&(s=s==="desc"?"asc":"desc"),this._configuration.sort=s,this._configuration.sortBy=e,this._currentPage=1,this._sorting=!1,this._sortingColumn=null,this._updateSortIcons(),this.render()}}_getSortClass(t){var e,i,s,n,r;return this._sorting&&this._sortingColumn===t?"spinner":((i=(e=this._configuration)==null?void 0:e.sortBy)==null?void 0:i.toLowerCase())===((s=t.data)==null?void 0:s.toLowerCase())?((r=(n=this._configuration)==null?void 0:n.sort)==null?void 0:r.toLowerCase())==="desc"?"caret-down":"caret-up":""}_updateSortIcons(){this._configuration&&this._configuration.columns.forEach((t,e)=>{if(!t.sortable||t.hidden)return;const i=this.querySelector(`th[data-column-key="${e}"]`);if(!i)return;const s=i.querySelector(".ml-2.flex.items-center");if(!s)return;const n=s.querySelector("mint-icon"),r=s.querySelector("mint-spinner"),a=this._getSortClass(t);if(a==="spinner"){if(n&&n.remove(),!r){const l=document.createElement("mint-spinner");l.className="w-4 h-4",s.appendChild(l)}}else if(r&&r.remove(),n)n.setAttribute("name",a),n.className=`w-4 h-4 ${a==="sort-arrows"?"text-gray-400":""}`;else{const l=document.createElement("mint-icon");l.setAttribute("name",a),l.className=`w-4 h-4 ${a==="sort-arrows"?"text-gray-400":""}`,s.appendChild(l)}})}_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},400)}_updateSearchIcon(){const t=this.querySelector(`#search-${this._tableId}`);if(!t)return;const e=this._type==="ajax"&&(this._searching||this._fetching);setTimeout(()=>{const i=t.querySelector(".relative")||t.querySelector("div");if(!i)return;const s=i.querySelector("mint-icon"),n=i.querySelector("mint-spinner");if(e){if(s&&!n){const r=document.createElement("mint-spinner");r.className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none",s.replaceWith(r)}else if(!s&&!n){const r=document.createElement("mint-spinner");r.className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 pointer-events-none",i.appendChild(r)}}else if(n){t.getAttribute("icon")||t.setAttribute("icon","search");const r=document.createElement("mint-icon");r.setAttribute("name","search"),r.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",n.replaceWith(r)}},0)}_updateTableBody(){var a,l;if(!this._configuration)return;const t=this._getRows(),e=(l=(a=this.querySelector(`#${this._tableId}`))==null?void 0:a.closest("table"))==null?void 0:l.querySelector("tbody");if(!e){this.render();return}const i=this.querySelector(`#search-${this._tableId}`),s=document.activeElement===i||(i==null?void 0:i.querySelector("input"))===document.activeElement,n=this._search;let r="";if(!((this._fetching||this._loading)&&!this._sorting)&&(t.forEach((o,c)=>{const h=typeof this._configuration.onRowClick=="function",f=h?"cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors":"";r+=`<tr data-row-index="${c}" ${h?'data-row-clickable="true"':""}${f?` class="${f}"`:""}>`,this._configuration.columns.forEach((d,p)=>{if(d.hidden)return;const u=!d.show||d.show(this,o);if(r+=`<td style="${this._getStyle(d)}" class="${this._getClasses(d,!0)}">`,u)if(d.raw)if(d.action)(!d.action.show||d.action.show(this,o))&&(r+=`<mint-button variant="solid" data-action="column-action" data-row-index="${c}" data-column-key="${this._configuration.columns.indexOf(d)}">${d.action.label}</mint-button>`);else if(d.actions)if(d.actionStyle!=="buttons"){const _=`actions-popover-${this._tableId}-${c}`,g=`actions-button-${this._tableId}-${c}`;r+=`<mint-button id="${g}" variant="link" icon="ellipsis">`,r+="</mint-button>",r+=`<mint-popover id="${_}" trigger-id="${g}" direction="down">`,d.actions.forEach((m,v)=>{if(!m.show||m.show(this,o)){const b=typeof m.label=="function"?m.label(this,o):m.label;r+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${c}" data-action-index="${v}" data-column-key="${this._configuration.columns.indexOf(d)}">${b}</div>`}}),r+="</mint-popover>"}else d.actions.forEach((_,g)=>{if(!_.show||_.show(this,o)){const m=_.label?typeof _.label=="function"?_.label(this,o):_.label:"",v=_.icon?` icon="${this._escapeHtml(_.icon)}"`:"",b=_.tone?` tone="${this._escapeHtml(_.tone)}"`:"";r+=`<mint-button variant="link" class="${_.classes||""}" data-action="row-action" data-row-index="${c}" data-action-index="${g}" data-column-key="${this._configuration.columns.indexOf(d)}"${v}${b}>`,m&&(r+=this._escapeHtml(String(m))),r+="</mint-button>"}});else typeof d.format=="function"?r+=d.format(this,o):d.data&&(r+=this._escapeHtml(String(o[d.data]||"")));else if(d.action){if(!d.action.show||d.action.show(this,o)){const _=typeof d.action.label=="function"?d.action.label(this,o):d.action.label;r+=`<mint-button variant="solid" data-action="column-action" data-row-index="${c}" data-column-key="${this._configuration.columns.indexOf(d)}">${this._escapeHtml(String(_))}</mint-button>`}}else if(d.actions)if(d.actionStyle!=="buttons"){const _=`actions-popover-${this._tableId}-${c}`,g=`actions-button-${this._tableId}-${c}`;r+=`<mint-button id="${g}" variant="link" icon="ellipsis">`,r+="</mint-button>",r+=`<mint-popover id="${_}" trigger-id="${g}" direction="down">`,d.actions.forEach((m,v)=>{if(!m.show||m.show(this,o)){const b=typeof m.label=="function"?m.label(this,o):m.label;r+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${c}" data-action-index="${v}" data-column-key="${this._configuration.columns.indexOf(d)}">${b}</div>`}}),r+="</mint-popover>"}else d.actions.forEach((_,g)=>{if(!_.show||_.show(this,o)){const m=_.label?typeof _.label=="function"?_.label(this,o):_.label:"",v=_.icon?` icon="${this._escapeHtml(_.icon)}"`:"",b=_.tone?` tone="${this._escapeHtml(_.tone)}"`:"";r+=`<mint-button variant="link" class="${_.classes||""}" data-action="row-action" data-row-index="${c}" data-action-index="${g}" data-column-key="${this._configuration.columns.indexOf(d)}"${v}${b}>`,m&&(r+=this._escapeHtml(String(m))),r+="</mint-button>"}});else typeof d.format=="function"?r+=this._escapeHtml(d.format(this,o)):d.data&&(r+=this._escapeHtml(String(o[d.data]||"")));r+="</td>"}),r+="</tr>"}),t.length===0&&(this._fetchError?r+=`<tr><td colspan="${this._configuration.columns.filter(o=>!o.hidden).length}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`:r+=`<tr><td colspan="${this._configuration.columns.filter(o=>!o.hidden).length}" class="text-center py-8">No records found.</td></tr>`),e.innerHTML=r,this._attachTableEventListeners(),this._attachRowClickHandler(),s&&i)){const o=i.querySelector("input")||i._element;o?(o.value=n,setTimeout(()=>{o.focus(),o.setSelectionRange(n.length,n.length)},0)):i.value!==void 0&&(i.value=n,setTimeout(()=>{i.focus()},0))}}_updatePagination(){var s,n;if(!this._configuration)return;const t=this._lastPage||Math.ceil(this._rows.length/this._perPage);if(!this._configuration.perPage||this._configuration.loadMore||t<=1){const r=(s=this.querySelector("nav"))==null?void 0:s.closest(".flex.justify-end");r&&r.remove();return}let e=(n=this.querySelector("nav"))==null?void 0:n.closest(".flex.justify-end");if(!e){const r=this.querySelector("mint-table");if(!r){this.render();return}e=document.createElement("div"),e.className="flex justify-end "+(this._inMintCard?"p-3.5":"mt-4"),r.insertAdjacentElement("afterend",e)}let i="<nav>";i+='<ul class="flex gap-1">',i+=`<li><mint-button variant="solid" size="sm" icon="caret-left" ${this._currentPage===1?'disabled="true"':""} data-action="page-prev"></mint-button></li>`;for(let r=1;r<=Math.min(2,t);r++){const l=this._currentPage===r?' disabled="true"':"";i+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}if(t>2&&(i+='<li><span class="px-2">...</span></li>'),this._currentPage>2&&this._currentPage<t-1&&(i+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage-1}">${this._currentPage-1}</mint-button></li>`,i+=`<li><mint-button variant="solid" size="sm" disabled="true" data-action="page" data-page="${this._currentPage}">${this._currentPage}</mint-button></li>`,i+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage+1}">${this._currentPage+1}</mint-button></li>`),t>2)for(let r=Math.max(t-1,this._currentPage+2);r<=t;r++){const l=this._currentPage===r?' disabled="true"':"";i+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}i+=`<li><mint-button variant="solid" size="sm" icon="caret-right" ${this._currentPage>=t?'disabled="true"':""} data-action="page-next"></mint-button></li>`,i+="</ul>",i+="</nav>",e.innerHTML=i,setTimeout(()=>{this._attachPaginationListeners(),e.querySelectorAll("mint-button[data-action]").forEach(r=>{"render"in r&&typeof r.render=="function"&&r.render()})},0)}_loadMore(){this._loading||this._fetching||!(this._type==="ajax"?this._lastPage>0&&this._currentPage<this._lastPage:this._totalRows>0&&this._rowsToShow<this._totalRows)||(this._offset+=this._perPage,this._currentPage+=1,this._rowsToShow+=this._perPage,this._type==="ajax"?this._fetchData():this.render())}_goToPage(t){const e=this._lastPage||Math.ceil(this._rows.length/this._perPage);t>e&&(t=e),t<1&&(t=1),this._currentPage=t,this._offset=(t-1)*this._perPage,this._updatePageInUrl(t),this._type==="ajax"?this._fetchData():this.render()}_handleButtonClick(t){if(this._configuration)switch(t.type){case"export":break;case"print":window.print();break;case"csv":this._downloadCSV();break;default:t.onClick&&t.onClick(this);break}}_downloadCSV(){if(!this._configuration)return;const t=this.querySelector("table");if(!t)return;const e=t.querySelectorAll("tr");let i="data:text/csv;charset=utf-8,";e.forEach(r=>{const a=[];r.querySelectorAll("th, td").forEach(l=>{var c;const o=l.getAttribute("colspan");if(o)for(let h=0;h<parseInt(o)-1;h++)a.push("");a.push('"'+((c=l.textContent)==null?void 0:c.trim().replace(/"/g,'""'))+'"')}),i+=a.join(",")+`
|
|
153
|
+
`});const s=encodeURI(i),n=document.createElement("a");n.setAttribute("href",s),n.setAttribute("download",`${this._configuration.export_name||this._tableId}.csv`),document.body.appendChild(n),n.click(),document.body.removeChild(n)}_columnChange(t,e){const i=t.target.checked;e.hidden=!i,this._saveColumnVisibility();const s=`edit-columns-popover-${this._tableId}`,n=this.querySelector(`#${s}`),r=n==null?void 0:n.hasAttribute("open");this.render(),r&&n&&requestAnimationFrame(()=>{const a=this.querySelector(`#${s}`);a&&typeof a.open=="function"&&a.open()})}_getStyle(t){let e="";return(t.nowrap||t.actions)&&(e+="white-space: nowrap;"),t.offsetLeft&&(e+=`left: ${t.offsetLeft} !important;`),t.offsetRight&&(e+=`right: ${t.offsetRight} !important;`),t.width&&(e+=`min-width: ${t.width}px; max-width: ${t.width}px;`),e}_getClasses(t,e=!1){const i=[];return t.class&&i.push(t.class.trim()),t.sortable&&!e&&i.push("cursor-pointer"),t.stickLeft&&i.push("sticky-left"),t.stickRight&&i.push("sticky-right"),i.join(" ")}render(){if(!this._configuration){this.innerHTML='<div class="p-4 text-red-500">Error: Invalid configuration</div>';return}const t=!this._loaded||this._rows.length>0||this._search.length>0||this._searching,e=this._getRows(),i=this._lastPage||Math.ceil(this._rows.length/this._perPage);let s="";if(t){if(s+='<div class="flex '+(this._inMintCard?"p-3.5":"mb-3")+'">',s+='<div class="flex-grow-1 flex-1">',s+='<div class="flex gap-2 items-center">',this._configuration.showSearch!==!1){const r=`search-${this._tableId}`;s+=`<mint-input id="${r}" type="search" label="" placeholder="Search..." class="flex-1" icon="search" value="${this._escapeHtml(this._search)}"></mint-input>`}if(this._configuration.buttons&&this._configuration.buttons.forEach(r=>{const a=r.icon?` icon="${this._escapeHtml(r.icon)}"`:"",l=r.tone?` tone="${this._escapeHtml(r.tone)}"`:"";s+=`<mint-button variant="solid" class="${r.class||""}" data-button-type="${r.type||"custom"}"${a}${l}>`,r.label&&(s+=this._escapeHtml(r.label)),s+="</mint-button>"}),s+="</div>",s+="</div>",this._configuration.editColumns!==!1&&this._configuration.columns.some(a=>!a.actions&&a.editable!==!1)){const a=`edit-columns-popover-${this._tableId}`,l=`edit-columns-button-${this._tableId}`;s+='<div class="ml-2">',s+=`<mint-button id="${l}" variant="solid" icon="edit"></mint-button>`,s+=`<mint-popover id="${a}" trigger-id="${l}" direction="down">`,this._configuration.columns.forEach(o=>{!o.actions&&o.editable!==!1&&(s+='<div class="p-2">',s+=`<mint-checkbox label="${o.label}" ${o.hidden?"":"checked"} data-column-key="${this._configuration.columns.indexOf(o)}"></mint-checkbox>`,s+="</div>")}),s+="</mint-popover>",s+="</div>"}s+="</div>"}if(this._type==="ajax"&&(!this._loaded||this._fetching||this._loading)&&!this._fetchError&&!this._sorting){s+='<mint-table class="table-section'+(this._inMintCard?" rounded-t-none":"")+'">',s+=`<table id="${this._tableId}">`,s+="<thead><tr>",this._configuration.columns.forEach((r,a)=>{r.hidden||(s+=`<th width="${r.width||""}" style="${this._getStyle(r)}" class="${this._getClasses(r)}" data-column-key="${a}">`,r.showLabel!==!1&&(s+='<div class="flex items-center">',s+=`<div class="flex-1">${r.raw?r.label:this._escapeHtml(r.label)}</div>`,r.sortable&&(s+='<div class="ml-2 flex items-center">',s+='<mint-icon name="" class="w-4 h-4 text-gray-400"></mint-icon>',s+="</div>"),s+="</div>"),s+="</th>")}),s+="</tr></thead>",s+="<tbody>";for(let r=0;r<4;r++)s+="<tr>",this._configuration.columns.forEach(a=>{a.hidden||(s+=`<td style="${this._getStyle(a)}" class="${this._getClasses(a,!0)}">`,s+='<div class="h-4 bg-gray-200 dark:bg-gray-700 rounded animate-pulse"></div>',s+="</td>")}),s+="</tr>";if(s+="</tbody>",s+="</table>",s+="</mint-table>",this._configuration.perPage&&!this._configuration.loadMore&&(i>1||this._lastPage>0)){const r=this._lastPage>0?this._lastPage:i;if(r>1){s+='<div class="flex justify-end '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+="<nav>",s+='<ul class="flex gap-1">',s+=`<li><mint-button variant="solid" size="sm" icon="caret-left" ${this._currentPage===1?'disabled="true"':""} data-action="page-prev"></mint-button></li>`;for(let a=1;a<=Math.min(2,r);a++){const o=this._currentPage===a?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${o} data-action="page" data-page="${a}">${a}</mint-button></li>`}if(r>2&&(s+='<li><span class="px-2">...</span></li>'),this._currentPage>2&&this._currentPage<r-1&&(s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage-1}">${this._currentPage-1}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" disabled="true" data-action="page" data-page="${this._currentPage}">${this._currentPage}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage+1}">${this._currentPage+1}</mint-button></li>`),r>2)for(let a=Math.max(r-1,this._currentPage+2);a<=r;a++){const o=this._currentPage===a?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${o} data-action="page" data-page="${a}">${a}</mint-button></li>`}s+=`<li><mint-button variant="solid" size="sm" icon="caret-right" ${this._currentPage>=r?'disabled="true"':""} data-action="page-next"></mint-button></li>`,s+="</ul>",s+="</nav>",s+="</div>"}}}else if(e.length>0||this._search.length>0||this._searching||this._fetchError){if(s+='<mint-table class="table-section'+(this._inMintCard?" rounded-t-none":"")+'">',s+=`<table id="${this._tableId}">`,s+="<thead><tr>",this._configuration.columns.forEach((r,a)=>{if(!r.hidden){if(s+=`<th width="${r.width||""}" style="${this._getStyle(r)}" class="${this._getClasses(r)}" data-column-key="${a}">`,r.showLabel!==!1){if(s+='<div class="flex items-center">',s+=`<div class="flex-1">${r.raw?r.label:this._escapeHtml(r.label)}</div>`,r.sortable){s+='<div class="ml-2 flex items-center">';const l=this._getSortClass(r);l==="spinner"?s+='<mint-spinner class="w-4 h-4"></mint-spinner>':s+=`<mint-icon name="${l}" class="w-4 h-4 ${l==="sort-arrows"?"text-gray-400":""}"></mint-icon>`,s+="</div>"}s+="</div>"}s+="</th>"}}),s+="</tr></thead>",s+="<tbody>",!this._fetching&&!this._loading&&e.forEach((r,a)=>{const l=typeof this._configuration.onRowClick=="function",o=l?"cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors":"";s+=`<tr data-row-index="${a}" ${l?'data-row-clickable="true"':""}${o?` class="${o}"`:""}>`,this._configuration.columns.forEach((c,h)=>{if(c.hidden)return;const f=!c.show||c.show(this,r);if(s+=`<td style="${this._getStyle(c)}" class="${this._getClasses(c,!0)}">`,f)if(c.raw)if(c.action){if(!c.action.show||c.action.show(this,r)){const d=typeof c.action.label=="function"?c.action.label(this,r):c.action.label;s+=`<mint-button variant="solid" data-action="column-action" data-row-index="${a}" data-column-key="${this._configuration.columns.indexOf(c)}">${this._escapeHtml(String(d))}</mint-button>`}}else if(c.actions)if(c.actionStyle!=="buttons"){const d=`actions-popover-${this._tableId}-${a}`,p=`actions-button-${this._tableId}-${a}`;s+=`<mint-button id="${p}" variant="link" icon="ellipsis">`,s+="</mint-button>",s+=`<mint-popover id="${d}" trigger-id="${p}" direction="down">`,c.actions.forEach((u,_)=>{if(!u.show||u.show(this,r)){const g=typeof u.label=="function"?u.label(this,r):u.label;s+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${a}" data-action-index="${_}" data-column-key="${this._configuration.columns.indexOf(c)}">${this._escapeHtml(String(g))}</div>`}}),s+="</mint-popover>"}else c.actions.forEach((d,p)=>{if(!d.show||d.show(this,r)){const u=d.label?typeof d.label=="function"?d.label(this,r):d.label:"",_=d.icon?` icon="${this._escapeHtml(d.icon)}"`:"",g=d.tone?` tone="${this._escapeHtml(d.tone)}"`:"";s+=`<mint-button variant="link" class="${d.classes||""}" data-action="row-action" data-row-index="${a}" data-action-index="${p}" data-column-key="${this._configuration.columns.indexOf(c)}"${_}${g}>`,u&&(s+=this._escapeHtml(String(u))),s+="</mint-button>"}});else typeof c.format=="function"?s+=c.format(this,r):c.data&&(s+=this._escapeHtml(String(r[c.data]||"")));else if(c.action)(!c.action.show||c.action.show(this,r))&&(s+=`<mint-button variant="solid" data-action="column-action" data-row-index="${a}" data-column-key="${this._configuration.columns.indexOf(c)}">${c.action.label}</mint-button>`);else if(c.actions)if(c.actionStyle!=="buttons"){const d=`actions-popover-${this._tableId}-${a}`,p=`actions-button-${this._tableId}-${a}`;s+=`<mint-button id="${p}" variant="link" icon="ellipsis">`,s+="</mint-button>",s+=`<mint-popover id="${d}" trigger-id="${p}" direction="down">`,c.actions.forEach((u,_)=>{if(!u.show||u.show(this,r)){const g=typeof u.label=="function"?u.label(this,r):u.label;s+=`<div class="p-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700" data-action="row-action" data-row-index="${a}" data-action-index="${_}" data-column-key="${this._configuration.columns.indexOf(c)}">${this._escapeHtml(String(g))}</div>`}}),s+="</mint-popover>"}else c.actions.forEach((d,p)=>{if(!d.show||d.show(this,r)){const u=d.label?typeof d.label=="function"?d.label(this,r):d.label:"",_=d.icon?` icon="${this._escapeHtml(d.icon)}"`:"",g=d.tone?` tone="${this._escapeHtml(d.tone)}"`:"";s+=`<mint-button variant="link" class="${d.classes||""}" data-action="row-action" data-row-index="${a}" data-action-index="${p}" data-column-key="${this._configuration.columns.indexOf(c)}"${_}${g}>`,u&&(s+=this._escapeHtml(String(u))),s+="</mint-button>"}});else typeof c.format=="function"?s+=this._escapeHtml(c.format(this,r)):c.data&&(s+=this._escapeHtml(String(r[c.data]||"")));s+="</td>"}),s+="</tr>"}),!this._fetching&&!this._loading&&e.length===0&&(this._fetchError?s+=`<tr><td colspan="${this._configuration.columns.filter(r=>!r.hidden).length}" class="text-center py-8 text-red-500 dark:text-red-400">Failed to load data: ${this._escapeHtml(this._fetchError)}</td></tr>`:s+=`<tr><td colspan="${this._configuration.columns.filter(r=>!r.hidden).length}" class="text-center py-8">No records found.</td></tr>`),s+="</tbody>",s+="</table>",this._configuration.loadMore&&(this._loading||this._fetching?(s+='<div class="flex justify-center '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+="<mint-spinner></mint-spinner>",s+="</div>"):(this._type==="ajax"?this._lastPage>0&&this._currentPage<this._lastPage:this._totalRows>0&&this._rowsToShow<this._totalRows)&&(s+='<div class="flex justify-center '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+='<mint-button variant="ghost" data-action="load-more">Load more</mint-button>',s+="</div>")),this._configuration.perPage&&!this._configuration.loadMore&&this._loaded&&i>1){s+='<div class="flex justify-end '+(this._inMintCard?"p-3.5":"mt-4")+'">',s+="<nav>",s+='<ul class="flex gap-1">',s+=`<li><mint-button variant="solid" size="sm" icon="caret-left" ${this._currentPage===1?'disabled="true"':""} data-action="page-prev"></mint-button></li>`;for(let r=1;r<=Math.min(2,i);r++){const l=this._currentPage===r?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}if(i>2&&(s+='<li><span class="px-2">...</span></li>'),this._currentPage>2&&this._currentPage<i-1&&(s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage-1}">${this._currentPage-1}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" disabled="true" data-action="page" data-page="${this._currentPage}">${this._currentPage}</mint-button></li>`,s+=`<li><mint-button variant="solid" size="sm" data-action="page" data-page="${this._currentPage+1}">${this._currentPage+1}</mint-button></li>`),i>2)for(let r=Math.max(i-1,this._currentPage+2);r<=i;r++){const l=this._currentPage===r?' disabled="true"':"";s+=`<li><mint-button variant="solid" size="sm"${l} data-action="page" data-page="${r}">${r}</mint-button></li>`}s+=`<li><mint-button variant="solid" size="sm" icon="caret-right" ${this._currentPage>=i?'disabled="true"':""} data-action="page-next"></mint-button></li>`,s+="</ul>",s+="</nav>",s+="</div>"}s+="</mint-table>"}else s+='<slot name="empty"></slot>';this.innerHTML=s,this.querySelectorAll("mint-button[data-action]").forEach(r=>{r.render&&r.render()}),this.querySelectorAll("mint-button[data-button-type]").forEach(r=>{r.render&&r.render()}),this._attachEventListeners(),this._type==="ajax"&&!this._loaded&&!this._fetching&&!this._loading&&this._fetchData()}_attachRowClickHandler(){this._rowClickHandler&&this.removeEventListener("click",this._rowClickHandler,!0);const t=e=>{var o;const i=e.target;if(i.tagName==="MINT-BUTTON"||i.tagName==="BUTTON"||i.closest("mint-button")||i.closest("button")||i.closest("mint-popover")||i.closest("[data-action]"))return;const s=i.closest('tr[data-row-clickable="true"]');if(!s)return;const n=s.getAttribute("data-row-index");if(!n)return;const r=parseInt(n),l=this._getRows()[r];!l||!((o=this._configuration)!=null&&o.onRowClick)||(this._configuration.onRowClick.length===1?this._configuration.onRowClick(l):this._configuration.onRowClick(this,l))};this.addEventListener("click",t,!0),this._rowClickHandler=t}_attachPaginationListeners(){this.querySelectorAll('[data-action="page"]').forEach(t=>{t.addEventListener("click",()=>{const e=parseInt(t.getAttribute("data-page")||"1");this._goToPage(e)})}),this.querySelectorAll('[data-action="page-prev"]').forEach(t=>{t.addEventListener("click",()=>{this._goToPage(this._currentPage-1)})}),this.querySelectorAll('[data-action="page-next"]').forEach(t=>{t.addEventListener("click",()=>{this._goToPage(this._currentPage+1)})})}_attachTableEventListeners(){this.querySelectorAll('[data-action="row-action"]').forEach(t=>{t.addEventListener("click",()=>{var l;const e=parseInt(t.getAttribute("data-row-index")||"0"),i=parseInt(t.getAttribute("data-action-index")||"0"),s=parseInt(t.getAttribute("data-column-key")||"0"),r=this._getRows()[e],a=(l=this._configuration)==null?void 0:l.columns[s];a&&a.actions&&a.actions[i]&&a.actions[i].onClick(this,r)})}),this.querySelectorAll('[data-action="column-action"]').forEach(t=>{t.addEventListener("click",()=>{var a;const e=parseInt(t.getAttribute("data-row-index")||"0"),i=parseInt(t.getAttribute("data-column-key")||"0"),n=this._getRows()[e],r=(a=this._configuration)==null?void 0:a.columns[i];r&&r.action&&r.action.onClick(this,n)})})}_attachEventListeners(){var e;const t=this.querySelector(`#search-${this._tableId}`);if(t){const i=t.querySelector("input")||t._element;i?i.addEventListener("input",s=>{this._search=s.target.value,this._triggerSearch()}):t.addEventListener("input",s=>{this._search=t.value||s.target.value||"",this._triggerSearch()})}if(this._attachTableEventListeners(),this._attachRowClickHandler(),this.querySelectorAll("th[data-column-key]").forEach(i=>{i.addEventListener("click",()=>{var r;const s=parseInt(i.getAttribute("data-column-key")||"0"),n=(r=this._configuration)==null?void 0:r.columns[s];n&&this._toggleSort(n)})}),this.querySelectorAll("[data-button-type]").forEach(i=>{i.addEventListener("click",()=>{var r,a;const s=i.getAttribute("data-button-type"),n=(a=(r=this._configuration)==null?void 0:r.buttons)==null?void 0:a.find(l=>(l.type||"custom")===s);n&&this._handleButtonClick(n)})}),this.querySelectorAll("mint-checkbox[data-column-key]").forEach(i=>{i.addEventListener("change",s=>{var a;s.stopPropagation();const n=parseInt(i.getAttribute("data-column-key")||"0"),r=(a=this._configuration)==null?void 0:a.columns[n];r&&this._columnChange(s,r)}),i.addEventListener("click",s=>{s.stopPropagation()})}),this._attachPaginationListeners(),this.querySelectorAll('[data-action="load-more"]').forEach(i=>{i.addEventListener("click",()=>{this._loadMore()})}),(e=this._configuration)!=null&&e.loadMore){this._scrollHandler&&window.removeEventListener("scroll",this._scrollHandler);const i=()=>{const s=window.pageYOffset||document.documentElement.scrollTop,n=window.innerHeight;if(document.documentElement.scrollHeight-s-n<=100){const a=this._type==="ajax"?this._lastPage>0&&this._currentPage<this._lastPage:this._totalRows>0&&this._rowsToShow<this._totalRows;!this._loading&&!this._fetching&&a&&this._loadMore()}};this._scrollHandler=i,window.addEventListener("scroll",i)}}_escapeHtml(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}_getPageFromUrl(){if(!this._tableId)return null;const e=new URLSearchParams(window.location.search).get(`mui.${this._tableId}`);if(!e)return null;const i=parseInt(e,10);return isNaN(i)||i<1?null:i}_updatePageInUrl(t){if(!this._tableId)return;const e=new URL(window.location.href),i=e.searchParams;i.set(`mui.${this._tableId}`,t.toString()),t===1&&i.set(`mui.${this._tableId}`,"1"),window.history.replaceState({},"",e.toString())}_loadPageFromUrl(){if(!this._configuration||!this._tableId)return;const t=this._getPageFromUrl();t!==null&&(this._currentPage=t,this._offset=(this._currentPage-1)*this._perPage)}}customElements.get("mint-resource-table")||customElements.define("mint-resource-table",St);class Dt extends HTMLElement{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}static get observedAttributes(){return["id","heading","open","position","full-page","width"]}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()}disconnectedCallback(){this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null)}attributeChangedCallback(t,e,i){e!==i&&this.render()}getId(){return this.getAttribute("id")||""}getHeading(){return this.getAttribute("heading")||""}getPosition(){var e;const t=(e=this.getAttribute("position"))==null?void 0:e.toLowerCase();return t==="top"||t==="bottom"||t==="left"||t==="right"?t:"right"}isFullPage(){return this.getAttribute("full-page")==="true"}getWidth(){return this.getAttribute("width")||"w-80"}isOpen(){return this.getAttribute("open")==="true"}open(){this.setAttribute("open","true")}close(){this.removeAttribute("open")}render(){const t=this.getId(),e=this.getHeading(),i=this.isOpen(),s=this.getPosition(),n=this.isFullPage();t&&(this.id=t),this._overlay||(this._overlay=document.createElement("div"),this._overlay.className="fixed inset-0 bg-black bg-opacity-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));const r=this._getPositionClasses(s,n);this._offCanvas.className=r;let a=this._offCanvas.querySelector(".off-canvas-content");if(a||(a=document.createElement("div"),a.className="off-canvas-content bg-white dark:bg-gray-900 dark:border dark:border-gray-700 shadow-xl flex flex-col pointer-events-auto transition-all duration-300 ease-out",a.style.transform=this._getTransformValue(s,!1),this._offCanvas.appendChild(a)),i?this._animateEnter():this._animateExit(),Array.from(a.classList).forEach(u=>{(u.startsWith("w-")||u.startsWith("max-w-"))&&a.classList.remove(u)}),a.classList.remove("h-full","max-h-[90vh]","max-h-screen"),n)a.classList.add("w-full","h-full");else{const u=this.getWidth();s==="top"||s==="bottom"?a.classList.add("w-full","max-h-[90vh]"):a.classList.add(u,"h-full")}this._header||(this._header=document.createElement("div"),this._header.className="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",a.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 o=this._headingSlot.querySelector("mint-text");e?(o||(o=document.createElement("mint-text"),o.setAttribute("size","sub-heading"),o.setAttribute("bold","true"),this._headingSlot.appendChild(o)),o.textContent=e):o&&o.remove(),Array.from(this.children).filter(u=>u!==this._overlay&&u!==this._offCanvas&&u!==this._headingSlot&&u.getAttribute("slot")==="heading").forEach(u=>{this._headingSlot&&u.parentElement!==this._headingSlot&&this._headingSlot.appendChild(u)}),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"),a.appendChild(this._bodySlot)),Array.from(this.children).filter(u=>u!==this._overlay&&u!==this._offCanvas&&u!==this._bodySlot&&u.getAttribute("slot")==="body").forEach(u=>{this._bodySlot&&u.parentElement!==this._bodySlot&&this._bodySlot.appendChild(u)}),this._actionsSlot||(this._actionsSlot=document.createElement("div"),this._actionsSlot.className="p-4 border-t border-gray-200 dark:border-gray-700 flex-shrink-0",this._actionsSlot.setAttribute("slot","actions"),a.appendChild(this._actionsSlot));let f=this._actionsSlot.querySelector("mint-stack");f||(f=document.createElement("mint-stack"),f.setAttribute("direction","horizontal"),f.className="justify-end",this._actionsSlot.appendChild(f)),Array.from(this.children).filter(u=>u!==this._overlay&&u!==this._offCanvas&&u!==this._actionsSlot&&u.getAttribute("slot")==="actions").forEach(u=>{Array.from(u.children).forEach(g=>{g.parentElement!==f&&f.appendChild(g)}),u.parentElement&&u.remove()}),Array.from(this.children).forEach(u=>{u!==this._overlay&&u!==this._offCanvas&&u.getAttribute("slot")!=="heading"&&u.getAttribute("slot")!=="body"&&u.getAttribute("slot")!=="actions"&&u!==this._headingSlot&&u!==this._bodySlot&&u!==this._actionsSlot&&u.parentElement!==this._bodySlot&&this._bodySlot.appendChild(u)}),this._updateBackgroundColor()}_getPositionClasses(t,e){const i="fixed z-50 pointer-events-none transition-all duration-300 ease-out";switch(t){case"top":return`${i} top-0 left-0 right-0 ${e?"h-full":""}`;case"bottom":return`${i} bottom-0 left-0 right-0 ${e?"h-full":""}`;case"left":return`${i} left-0 top-0 bottom-0 ${e?"w-full":""}`;case"right":return`${i} right-0 top-0 bottom-0 ${e?"w-full":""}`;default:return`${i} right-0 top-0 bottom-0 ${e?"w-full":""}`}}_getTransformValue(t,e){if(e)switch(t){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(t){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;const t=document.documentElement.classList.contains("dark"),e=this._offCanvas.querySelector(".off-canvas-content");e&&(t?(e.classList.remove("bg-white"),e.classList.add("bg-gray-900","border","border-gray-700")):(e.classList.remove("bg-gray-900","border","border-gray-700"),e.classList.add("bg-white")))}_observeDarkMode(){this._darkModeObserver||(this._darkModeObserver=new MutationObserver(()=>{this._updateBackgroundColor()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}))}_animateEnter(){var i;const t=(i=this._offCanvas)==null?void 0:i.querySelector(".off-canvas-content");if(!t)return;const e=this.getPosition();t.style.transform=this._getTransformValue(e,!1),t.style.transition="transform 300ms ease-out",this.classList.remove("hidden"),requestAnimationFrame(()=>{requestAnimationFrame(()=>{t.style.transform=this._getTransformValue(e,!0)})})}_animateExit(){var i;const t=(i=this._offCanvas)==null?void 0:i.querySelector(".off-canvas-content");if(!t){this.classList.add("hidden");return}const e=this.getPosition();t.style.transition="transform 300ms ease-in",t.style.transform=this._getTransformValue(e,!1),setTimeout(()=>{this.classList.add("hidden"),t.style.transform="",t.style.transition=""},300)}}customElements.get("mint-off-canvas")||customElements.define("mint-off-canvas",Dt);class Lt extends HTMLElement{constructor(){super(),this._clickHandler=null}static get observedAttributes(){return["active","disabled","target"]}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.removeEventListeners()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getTarget(){return this.getAttribute("target")||""}isActive(){const t=this.getAttribute("active");return t!==null&&t!=="false"}isDisabled(){return this.getAttribute("disabled")==="true"}get active(){return this.isActive()}set active(t){t?this.setAttribute("active","true"):this.setAttribute("active","false")}render(){const t=this.isActive(),e=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","transition-all","duration-200","rounded-lg","border","text-gray-700","dark:text-gray-300");const i=this.closest("mint-tab-list"),s=(i==null?void 0:i.getAttribute("position"))||"top",n=s==="left"||s==="right";e?(this.classList.add("opacity-60","cursor-not-allowed","pointer-events-none","bg-gray-50","dark:bg-gray-900","border-gray-300","dark:border-gray-700","text-gray-400","dark:text-gray-500"),this.classList.remove("cursor-pointer")):t?(this.classList.add("bg-white","dark:bg-gray-900","border-gray-200","dark:border-gray-700","text-gray-900","dark:text-gray-100","shadow-sm","relative","z-10"),n?s==="left"?this.classList.add("mr-[-1px]"):this.classList.add("ml-[-1px]"):this.classList.add("mb-[-1px]")):this.classList.add("bg-gray-100","dark:bg-gray-900","border-gray-200","dark:border-gray-700","text-gray-600","dark:text-gray-400","hover:bg-gray-50","dark:hover:bg-gray-600")}setupEventListeners(){this.isDisabled()||this._clickHandler||(this._clickHandler=this.handleClick.bind(this),this.addEventListener("click",this._clickHandler))}removeEventListeners(){this._clickHandler&&(this.removeEventListener("click",this._clickHandler),this._clickHandler=null)}handleClick(t){if(this.isDisabled()){t.preventDefault(),t.stopPropagation();return}t.__mintTabsSynthetic||(t.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",Lt);class Tt extends HTMLElement{static get observedAttributes(){return["position"]}constructor(){super()}connectedCallback(){this.render()}attributeChangedCallback(t,e,i){e!==i&&this.render()}getPosition(){return this.getAttribute("position")||"top"}render(){const t=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-gray-900","dark:border-gray-700","border-gray-200","w-auto","rounded-lg","gap-2"),t==="top"?this.classList.add("inline-flex","flex-row","mb-0","self-start"):t==="left"?this.classList.add("flex","flex-col","mr-0"):t==="right"&&this.classList.add("flex","flex-col","ml-0")}}customElements.get("mint-tab-list")||customElements.define("mint-tab-list",Tt);class Mt 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(t,e,i){e!==i&&t==="id"&&(this.render(),this.checkInitialVisibility())}getId(){return this.getAttribute("id")||""}show(){this.style.display="block"}hide(){this.style.display="none"}checkInitialVisibility(){const t=this.closest("mint-tabs");if(!t){this.style.display="none";return}const e=t.querySelectorAll("mint-tab");let i=!1;if(e.forEach(s=>{const n=s.getAttribute("active"),r=s.getAttribute("target"),a=this.getId();n==="true"&&r===a&&(i=!0)}),!i&&e.length>0){const n=e[0].getAttribute("target"),r=this.getId();n===r&&!t.querySelector('mint-tab[active="true"]')&&(i=!0)}i?this.style.display="block":this.style.display="none"}render(){}}customElements.get("mint-tab-content")||customElements.define("mint-tab-content",Mt);class Ht 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(),this._mutationObserver=null)}render(){const t=this.querySelector("mint-tab-list");if(this.querySelectorAll("mint-tab-content"),!t){console.warn("mint-tabs: mint-tab-list is required");return}const e=t.getAttribute("position")||"top";this.classList.remove("flex","flex-row","flex-col","gap-4","gap-6"),e==="left"||e==="right"?(this.classList.add("flex","flex-row","items-start"),e==="left"?(t.classList.add("mr-4","flex-shrink-0"),t.classList.remove("ml-4")):(t.classList.add("ml-4","flex-shrink-0","order-2"),t.classList.remove("mr-4"),this.querySelectorAll("mint-tab-content").forEach(s=>{s.classList.add("order-1")}))):(this.classList.add("flex","flex-col"),t.classList.remove("mr-4","ml-4","flex-shrink-0","order-2"),this.querySelectorAll("mint-tab-content").forEach(s=>{s.classList.remove("order-1")}))}initializeActiveTab(){requestAnimationFrame(()=>{const t=this.querySelectorAll("mint-tab");let e=null;if(t.forEach(s=>{s.getAttribute("active")==="true"&&(e=s)}),!e&&t.length>0&&(e=t[0],e.setAttribute("active","true")),e){const s=e.getAttribute("target");s?this.showContent(s):this.hideAllContent()}else this.hideAllContent();this.querySelectorAll("mint-tab-content").forEach(s=>{const n=s;n.checkInitialVisibility&&n.checkInitialVisibility()})})}hideAllContent(){this.querySelectorAll("mint-tab-content").forEach(e=>{const i=e;i.hide?i.hide():e.style.display="none"})}showContent(t){this.querySelectorAll("mint-tab-content").forEach(s=>{const n=s;n.hide?n.hide():s.style.display="none"});const i=this.querySelector(`mint-tab-content[id="${t}"]`);i&&(i.show?i.show():i.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),this._tabClickHandler=null)}setupMutationObserver(){this._mutationObserver=new MutationObserver(()=>{this.render()});const t=this.querySelector("mint-tab-list");t&&this._mutationObserver.observe(t,{attributes:!0,attributeFilter:["position"]})}handleTabClick(t){var r,a;const e=(r=t.detail)==null?void 0:r.tab,i=(a=t.detail)==null?void 0:a.target;if(!e)return;const s=e.closest("mint-tab-list");if(!s)return;s.querySelectorAll("mint-tab").forEach(l=>{const o=l;l===e?o.active=!0:o.active=!1}),i&&this.showContent(i)}}customElements.get("mint-tabs")||customElements.define("mint-tabs",Ht);const K=class K extends HTMLElement{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=.3,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._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=["#3b82f6","#ef4444","#10b981","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#f97316"],this._legendHeight=0,this._rotatedLabelHeight=0}static get observedAttributes(){return["type","data","width","height","show-legend","show-grid","show-tooltip","curve-tension"]}connectedCallback(){this.classList.add("box-border","m-0","p-0","border-0","align-baseline","block","w-full");let t=this._getReactiveValue(this.data);t&&typeof t=="object"&&!Array.isArray(t)&&"datasets"in t&&(this._chartData=t),this._setupDataObserver(),this._setupDarkModeObserver(),this._setupResizeObserver(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.render()})})}_getReactiveValue(t){if(!t||typeof t!="object")return t;if("_value"in t||"__v_isRef"in t){if(typeof t.value<"u")return t.value;if("_value"in t)return t._value}return"__v_raw"in t||"__v_isReactive"in t||"__ob__"in t,t}_setupDataObserver(){let t=null,e=0;const i=()=>{if(!this.isConnected)return;const n=this._getReactiveValue(this.data);let r=null;n&&typeof n=="object"&&!Array.isArray(n)&&"datasets"in n&&(r=n),r!==t&&r&&(t=r,this._chartData=r,this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this.render())};requestAnimationFrame(()=>{i(),requestAnimationFrame(()=>{i()})});const s=setInterval(()=>{if(!this.isConnected){clearInterval(s);return}if(i(),e++,e>50){clearInterval(s);const n=setInterval(()=>{if(!this.isConnected){clearInterval(n);return}i()},1e3);this._dataCheckInterval=n}},100);this._dataCheckInterval=s}_setupDarkModeObserver(){this._darkModeObserver=new MutationObserver(()=>{this.isConnected&&this.render()}),this._darkModeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]})}disconnectedCallback(){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(t=>clearTimeout(t)),this._pieChartTimeouts.clear(),this._pieChartClickOutsideHandler&&(document.removeEventListener("click",this._pieChartClickOutsideHandler,!0),this._pieChartClickOutsideHandler=null),this._chartClickOutsideHandler&&(document.removeEventListener("click",this._chartClickOutsideHandler,!0),this._chartClickOutsideHandler=null),this._pieChartTooltipShown=!1,this._pieChartGroup=null,this._pinnedXValue=null,this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._dataObserver&&(this._dataObserver.disconnect(),this._dataObserver=null),this._darkModeObserver&&(this._darkModeObserver.disconnect(),this._darkModeObserver=null),this._dataCheckInterval&&(clearInterval(this._dataCheckInterval),this._dataCheckInterval=null),this._svg&&(this._chartTooltipMouseMove&&(this._svg.removeEventListener("mousemove",this._chartTooltipMouseMove),this._chartTooltipMouseMove=null),this._chartTooltipMouseLeave&&(this._svg.removeEventListener("mouseleave",this._chartTooltipMouseLeave),this._chartTooltipMouseLeave=null),this._chartTooltipTouchStart&&(this._svg.removeEventListener("touchstart",this._chartTooltipTouchStart),this._chartTooltipTouchStart=null),this._chartTooltipTouchMove&&(this._svg.removeEventListener("touchmove",this._chartTooltipTouchMove),this._chartTooltipTouchMove=null),this._chartTooltipTouchEnd&&(this._svg.removeEventListener("touchend",this._chartTooltipTouchEnd),this._chartTooltipTouchEnd=null)),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._windowResizeHandler&&(window.removeEventListener("resize",this._windowResizeHandler),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(){var r,a;if(!this.isConnected)return;const t=this.getBoundingClientRect(),e=t.width||((r=this.parentElement)==null?void 0:r.clientWidth)||800,i=t.height||((a=this.parentElement)==null?void 0:a.clientHeight)||400,s=this._calculateDimension(this._widthValue,e,e),n=this._calculateDimension(this._heightValue,i,400);(s!==this._width||n!==this._height)&&(this._width=s,this._height=n,this.render())}_setupResizeObserver(){this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._windowResizeHandler&&(window.removeEventListener("resize",this._windowResizeHandler),this._windowResizeHandler=null);let t=null;const e=()=>{t&&clearTimeout(t),t=window.setTimeout(()=>{this._handleResize()},100)};this._windowResizeHandler=e,this._resizeObserver=new ResizeObserver(()=>{e()}),this._resizeObserver.observe(this),window.addEventListener("resize",e)}attributeChangedCallback(t,e,i){if(e!==i){if(t==="data"&&this.data&&typeof this.data=="object"&&(this._chartData=this.data),(t==="width"||t==="height")&&this.isConnected){const s=e&&e.endsWith("%"),n=i&&i.endsWith("%");s!==n&&this._setupResizeObserver()}this.isConnected&&requestAnimationFrame(()=>{this.render()})}}get type(){const t=this.getAttribute("type")||"line";return t==="line"||t==="bar"||t==="area"||t==="pie"?t:"line"}set type(t){this.setAttribute("type",t)}get data(){return this._chartData}set data(t){if(typeof t=="string")try{this._chartData=JSON.parse(t)}catch(e){console.error("mint-chart: Invalid data JSON",e),this._chartData=null}else this._chartData=t;this.isConnected&&requestAnimationFrame(()=>{this.render()})}get width(){const t=this.getAttribute("width");if(!t)return this._widthValue;if(t.endsWith("%"))return t;const e=parseInt(t,10);return isNaN(e)?this._widthValue:e}set width(t){this.setAttribute("width",t.toString())}get height(){const t=this.getAttribute("height");if(!t)return this._heightValue;if(t.endsWith("%"))return t;const e=parseInt(t,10);return isNaN(e)?this._heightValue:e}set height(t){this.setAttribute("height",t.toString())}_calculateDimension(t,e,i){if(typeof t=="number")return t;if(typeof t=="string"&&t.endsWith("%")){const s=parseFloat(t);if(!isNaN(s))return e*s/100}return i}_scheduleRender(){this._renderScheduled||(this._renderScheduled=!0,requestAnimationFrame(()=>{this._renderScheduled=!1,this.render()}))}_isDatasetVisible(t,e){if(t.id){const i=this._datasetVisibility.get(t.id);if(i!==void 0)return i}return t.visible!==!1}_initializeDatasetVisibility(){this._chartData&&this._chartData.datasets.forEach((t,e)=>{t.id&&(this._datasetVisibility.has(t.id)||this._datasetVisibility.set(t.id,t.visible!==!1))})}render(){var r,a,l,o;if(!this.isConnected)return;this._plotPoints.clear(),this._activeXValue=null,(r=this._cachedTooltipContent)==null||r.clear(),(a=this._cachedXPositions)==null||a.clear(),this._chartType=this.type;let t=this._getReactiveValue(this.data);if(t&&typeof t=="object"&&!Array.isArray(t)&&"datasets"in t&&(this._chartData=t),!this._chartData){const c=this.getAttribute("data");if(c)try{this._chartData=JSON.parse(c)}catch(h){console.error("mint-chart: Invalid data JSON",h),this._chartData=null}}this._widthValue=this.width,this._heightValue=this.height;const e=this.getBoundingClientRect(),i=e.width||((l=this.parentElement)==null?void 0:l.clientWidth)||800,s=e.height||((o=this.parentElement)==null?void 0:o.clientHeight)||400;this._width=this._calculateDimension(this._widthValue,i,i),this._height=this._calculateDimension(this._heightValue,s,400),this._showLegend=this.getAttribute("show-legend")!=="false",this._showGrid=this.getAttribute("show-grid")!=="false",this._showTooltip=this.getAttribute("show-tooltip")!=="false";const n=this.getAttribute("curve-tension");if(n!==null){const c=parseFloat(n);this._curveTension=isNaN(c)?.3:Math.max(0,Math.min(1,c))}else this._curveTension=.3;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._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-gray-800 text-white text-xs rounded px-2 py-1 shadow-lg opacity-0 transition-opacity",this._tooltip.style.display="none",document.body.appendChild(this._tooltip)}_showTooltipAt(t,e,i){if(!this._tooltip)return;this._tooltipHideTimeout!==null&&(clearTimeout(this._tooltipHideTimeout),this._tooltipHideTimeout=null),this._lastTooltipContent!==i&&(this._tooltip.innerHTML=i,this._lastTooltipContent=i),(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");const n=this._tooltip.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight;let l=t+10,o=e-n.height-8;l+n.width>r&&(l=t-n.width-10),l<0&&(l=10),o<0&&(o=e+20),o+n.height>a&&(o=e-n.height-8,o<0&&(o=10));const c=`${l}px`,h=`${o}px`;this._tooltip.style.left!==c&&(this._tooltip.style.left=c),this._tooltip.style.top!==h&&(this._tooltip.style.top=h)}_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");const t=document.documentElement.classList.contains("dark");this._verticalLine.setAttribute("stroke",t?"#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";const e=this._svg.querySelector(".chart-legend");e&&e.parentNode?e.parentNode.insertBefore(this._verticalLine,e):this._svg.appendChild(this._verticalLine)}_showVerticalLineAtX(t,e){if(!this._verticalLine)return;const s=this._chartType==="bar"?this._scaleXForBarChart(t,e):this._scaleX(t,e);this._verticalLine.setAttribute("x1",s.toString()),this._verticalLine.setAttribute("y1",e.y.toString()),this._verticalLine.setAttribute("x2",s.toString()),this._verticalLine.setAttribute("y2",(e.y+e.height).toString()),this._verticalLine.style.opacity="1"}_hideVerticalLine(){this._verticalLine&&(this._verticalLine.style.opacity="0")}_showPlotPointsForX(t){this._plotPoints.forEach(s=>{s.forEach(n=>{n.style.opacity="0"})});const e=String(t),i=this._plotPoints.get(e);i&&i.forEach(s=>{s.style.opacity="1"})}_hidePlotPoints(){this._plotPoints.forEach(t=>{t.forEach(e=>{e.style.opacity="0"})})}_calculateMaxYAxisLabelWidth(){if(!this._showGrid||!this._chartData)return 0;const e=document.createElement("canvas").getContext("2d");if(!e)return 60;e.font="12px system-ui, -apple-system, sans-serif";const i=this._showLegend?Math.max(this._legendHeight,60):0,s=this._height-i,r=Math.floor(s/35),a=Math.min(5,r);let l=0;for(let o=0;o<=a;o++){const c=this._getYRange(),h=c.max-(c.max-c.min)/a*o,f=this._formatYAxisValue(h),d=e.measureText(f);l=Math.max(l,d.width)}return Math.ceil(l)+20}_getChartBounds(){const t=this._calculateMaxYAxisLabelWidth(),e=`${this._width}-${this._height}-${this._showGrid}-${this._showLegend}-${this._legendHeight}-${t}-${this._rotatedLabelHeight}`;if(this._cachedBounds.bounds&&this._cachedBounds.dataHash===e)return this._cachedBounds.bounds;let i=0,s=0,n=0,r=0;this._showGrid&&(i=Math.max(t,60));const o=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12;let c=o;this._showLegend&&(c=o+20+Math.max(this._legendHeight,60));const h=this._height-n-i-s,f=h-c,d=100;let p=1;if(f<d&&c>0){const _=h-d;_>0?(p=Math.min(1,_/c),p=Math.max(.5,p)):p=.5}r=c*p;const u={width:this._width-i-s,height:this._height-n-r,x:i,y:n};return this._cachedBounds={bounds:u,dataHash:e},u}_getAllDataPoints(){if(!this._chartData)return[];const t=[];return this._chartData.datasets.forEach((e,i)=>{this._isDatasetVisible(e,i)&&t.push(...e.data)}),t}_getXValues(){if(!this._chartData)return[];const t=JSON.stringify(this._chartData.labels)+JSON.stringify(this._chartData.datasets.map(s=>s.data.map(n=>n.x)));if(this._cachedXValues.values&&this._cachedXValues.dataHash===t)return this._cachedXValues.values;if(this._chartData.labels&&this._chartData.labels.length>0)return this._cachedXValues={values:this._chartData.labels,dataHash:t},this._chartData.labels;const e=new Set;this._chartData.datasets.forEach((s,n)=>{this._isDatasetVisible(s,n)&&s.data.forEach(r=>{e.add(r.x)})});const i=Array.from(e).sort((s,n)=>{if(typeof s=="number"&&typeof n=="number")return s-n;const r=String(s),a=String(n),l=/^([A-Za-z]{3})\s+(\d{4})$/,o=r.match(l),c=a.match(l);if(o&&c){const h=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],f=h.indexOf(o[1]),d=h.indexOf(c[1]),p=parseInt(o[2]),u=parseInt(c[2]);return p!==u?p-u:f-d}return r.localeCompare(a)});return this._cachedXValues={values:i,dataHash:t},i}_getYRange(){if(!this._chartData)return{min:0,max:100};const t=JSON.stringify(this._chartData.datasets.map(l=>l.data.map(o=>o.y)));if(this._cachedYRange.range&&this._cachedYRange.dataHash===t)return this._cachedYRange.range;const e=this._getAllDataPoints();if(e.length===0){const l={min:0,max:100};return this._cachedYRange={range:l,dataHash:t},l}const i=e.map(l=>l.y),s=Math.min(...i),n=Math.max(...i),r=(n-s)*.1,a={min:Math.max(0,s-r),max:n+r};return this._cachedYRange={range:a,dataHash:t},a}_hasDecimalValues(){return this._getAllDataPoints().some(e=>e.y%1!==0)}_formatValueByString(t,e){switch(e.toLowerCase()){case"currency":case"currency-usd":return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(t);case"currency-eur":return new Intl.NumberFormat("en-US",{style:"currency",currency:"EUR"}).format(t);case"currency-gbp":return new Intl.NumberFormat("en-US",{style:"currency",currency:"GBP"}).format(t);case"number":case"number-with-commas":return new Intl.NumberFormat("en-US").format(t);case"percent":return new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:1}).format(t/100);default:return this._hasDecimalValues()&&t%1!==0?t.toFixed(1):Math.round(t).toString()}}_formatXAxisValue(t){var e;if((e=this._chartData)!=null&&e.formatXAxis){if(typeof this._chartData.formatXAxis=="function")return this._chartData.formatXAxis(t);if(typeof this._chartData.formatXAxis=="string")return String(t)}return String(t)}_formatYAxisValue(t){var i,s,n,r;if((i=this._chartData)!=null&&i.formatYAxis){if(typeof this._chartData.formatYAxis=="function")return this._chartData.formatYAxis(t);if(typeof this._chartData.formatYAxis=="string")return this._formatValueByString(t,this._chartData.formatYAxis)}if((r=(n=(s=this._chartData)==null?void 0:s.datasets)==null?void 0:n[0])!=null&&r.formatValue){if(typeof this._chartData.datasets[0].formatValue=="function")return this._chartData.datasets[0].formatValue(t);if(typeof this._chartData.datasets[0].formatValue=="string")return this._formatValueByString(t,this._chartData.datasets[0].formatValue)}return this._hasDecimalValues()&&t%1!==0?t.toFixed(1):Math.round(t).toString()}_formatValue(t,e){if(e.formatValue){if(typeof e.formatValue=="function")return e.formatValue(t);if(typeof e.formatValue=="string")return this._formatValueByString(t,e.formatValue)}return String(t)}_getAllDatasetsAtX(t){if(!this._chartData)return[];const e=[];return this._chartData.datasets.forEach((i,s)=>{if(!this._isDatasetVisible(i,s))return;const n=i.data.find(r=>String(r.x)===String(t));if(n){const r=this._getDatasetColor(i,s),a=this._formatValue(n.y,i);e.push({name:i.name,value:n.y,color:r,formattedValue:a})}}),e}_findNearestXValue(t){if(!this._chartData)return null;const e=this._getChartBounds(),i=this._getXValues();if(i.length===0)return null;const s=this._chartType==="bar";let n=null,r=1/0;return i.forEach(a=>{const l=s?this._scaleXForBarChart(a,e):this._scaleX(a,e),o=Math.abs(t-l);o<r&&(r=o,n=a)}),n}_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();const t=this._getChartBounds();let e=0,i=0;const s=c=>{!this._chartContainer||!this._svg||(e=c.clientX,i=c.clientY,this._tooltipAnimationFrame!==null&&cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=requestAnimationFrame(()=>{if(this._tooltipAnimationFrame=null,!this._svg)return;const h=this._svg.getBoundingClientRect(),f=e-h.left,d=i-h.top;if(f<t.x||f>t.x+t.width||d<t.y||d>t.y+t.height){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}const p=this._findNearestXValue(f);if(!p){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;return}if(this._pinnedXValue!==null&&this._pinnedXValue===p){const g=this._pinnedXValue,m=this._getAllDatasetsAtX(g);if(m.length>0){this._activeXValue=g,this._showPlotPointsForX(g),this._showVerticalLineAtX(g,t);let v=this._cachedTooltipContent.get(g);v||(v=`<strong>${g}</strong><br/>`,m.forEach(b=>{v+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
154
154
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${b.color}; border-radius: 2px;"></span>
|
|
155
155
|
<span>${b.name}: ${b.formattedValue}</span>
|
|
156
|
-
</div>`}),this._cachedTooltipContent.set(g,v)),this._updateTooltipPosition(e,i),this._lastTooltipContent!==v&&this._showTooltipAt(e,i,v);return}}if(this._activeXValue===
|
|
156
|
+
</div>`}),this._cachedTooltipContent.set(g,v)),this._updateTooltipPosition(e,i),this._lastTooltipContent!==v&&this._showTooltipAt(e,i,v);return}}if(this._activeXValue===p){this._updateTooltipPosition(e,i);return}const u=this._getAllDatasetsAtX(p);if(u.length===0){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine();return}this._activeXValue=p,this._showPlotPointsForX(p),this._showVerticalLineAtX(p,t);let _=this._cachedTooltipContent.get(p);if(!_){if(_=`<strong>${p}</strong><br/>`,u.forEach(g=>{_+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
157
157
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${g.color}; border-radius: 2px;"></span>
|
|
158
158
|
<span>${g.name}: ${g.formattedValue}</span>
|
|
159
|
-
</div>`}),this._cachedTooltipContent.size>=K.MAX_CACHE_SIZE){const g=this._cachedTooltipContent.keys().next().value;g!==void 0&&this._cachedTooltipContent.delete(g)}this._cachedTooltipContent.set(
|
|
159
|
+
</div>`}),this._cachedTooltipContent.size>=K.MAX_CACHE_SIZE){const g=this._cachedTooltipContent.keys().next().value;g!==void 0&&this._cachedTooltipContent.delete(g)}this._cachedTooltipContent.set(p,_)}this._showTooltipAt(e,i,_)}))},n=()=>{this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null},r=c=>{if(!this._chartContainer||!this._svg)return;c.stopPropagation();const h=this._svg.getBoundingClientRect(),f=c.clientX-h.left,d=c.clientY-h.top;if(f<t.x||f>t.x+t.width||d<t.y||d>t.y+t.height)return;const p=this._findNearestXValue(f);if(p)if(this._pinnedXValue===p)this._pinnedXValue=null,this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;else{this._pinnedXValue=p,this._activeXValue=p;const u=this._getAllDatasetsAtX(p);if(u.length===0)return;this._showPlotPointsForX(p),this._showVerticalLineAtX(p,t);let _=this._cachedTooltipContent.get(p);_||(_=`<strong>${p}</strong><br/>`,u.forEach(g=>{_+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
160
160
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${g.color}; border-radius: 2px;"></span>
|
|
161
161
|
<span>${g.name}: ${g.formattedValue}</span>
|
|
162
|
-
</div>`}),this._cachedTooltipContent.set(
|
|
162
|
+
</div>`}),this._cachedTooltipContent.set(p,_)),this._showTooltipAt(c.clientX,c.clientY,_)}},a=c=>{if(c.preventDefault(),!this._chartContainer||!this._svg)return;const h=c.touches[0];if(!h)return;const f=this._svg.getBoundingClientRect(),d=h.clientX-f.left,p=h.clientY-f.top;if(d<t.x||d>t.x+t.width||p<t.y||p>t.y+t.height){this._pinnedXValue===null&&(this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null);return}const u=this._findNearestXValue(d);if(!u){this._pinnedXValue===null&&(this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null);return}if(this._pinnedXValue===u)this._pinnedXValue=null,this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;else{this._pinnedXValue=u,this._activeXValue=u;const _=this._getAllDatasetsAtX(u);if(_.length===0)return;this._showPlotPointsForX(u),this._showVerticalLineAtX(u,t);let g=this._cachedTooltipContent.get(u);g||(g=`<strong>${u}</strong><br/>`,_.forEach(m=>{g+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
163
163
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${m.color}; border-radius: 2px;"></span>
|
|
164
164
|
<span>${m.name}: ${m.formattedValue}</span>
|
|
165
|
-
</div>`}),this._cachedTooltipContent.set(
|
|
166
|
-
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${
|
|
167
|
-
<span>${
|
|
168
|
-
</div>`}),this._cachedTooltipContent.set(m,b)),this._updateTooltipPosition(h.clientX,h.clientY),this._lastTooltipContent!==b&&this._showTooltipAt(h.clientX,h.clientY,b)}}return}if(this._pinnedXValue!==null){const m=this._pinnedXValue,v=this._getAllDatasetsAtX(m);if(v.length>0){this._activeXValue=m,this._showPlotPointsForX(m),this._showVerticalLineAtX(m,t);let b=this._cachedTooltipContent.get(m);b||(b=`<strong>${m}</strong><br/>`,v.forEach(
|
|
169
|
-
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${
|
|
170
|
-
<span>${
|
|
171
|
-
</div>`}),this._cachedTooltipContent.set(m,b)),this._updateTooltipPosition(h.clientX,h.clientY),this._lastTooltipContent!==b&&this._showTooltipAt(h.clientX,h.clientY,b);return}}const
|
|
165
|
+
</div>`}),this._cachedTooltipContent.set(u,g)),this._showTooltipAt(h.clientX,h.clientY,g)}},l=c=>{if(c.preventDefault(),!this._chartContainer||!this._svg)return;const h=c.touches[0];h&&(this._tooltipAnimationFrame!==null&&cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=requestAnimationFrame(()=>{if(this._tooltipAnimationFrame=null,!this._svg)return;const f=this._svg.getBoundingClientRect(),d=h.clientX-f.left,p=h.clientY-f.top;if(d<t.x||d>t.x+t.width||p<t.y||p>t.y+t.height){if(this._pinnedXValue===null)this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null;else{const m=this._pinnedXValue,v=this._getAllDatasetsAtX(m);if(v.length>0){this._activeXValue=m,this._showPlotPointsForX(m),this._showVerticalLineAtX(m,t);let b=this._cachedTooltipContent.get(m);b||(b=`<strong>${m}</strong><br/>`,v.forEach(y=>{b+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
166
|
+
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${y.color}; border-radius: 2px;"></span>
|
|
167
|
+
<span>${y.name}: ${y.formattedValue}</span>
|
|
168
|
+
</div>`}),this._cachedTooltipContent.set(m,b)),this._updateTooltipPosition(h.clientX,h.clientY),this._lastTooltipContent!==b&&this._showTooltipAt(h.clientX,h.clientY,b)}}return}if(this._pinnedXValue!==null){const m=this._pinnedXValue,v=this._getAllDatasetsAtX(m);if(v.length>0){this._activeXValue=m,this._showPlotPointsForX(m),this._showVerticalLineAtX(m,t);let b=this._cachedTooltipContent.get(m);b||(b=`<strong>${m}</strong><br/>`,v.forEach(y=>{b+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
169
|
+
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${y.color}; border-radius: 2px;"></span>
|
|
170
|
+
<span>${y.name}: ${y.formattedValue}</span>
|
|
171
|
+
</div>`}),this._cachedTooltipContent.set(m,b)),this._updateTooltipPosition(h.clientX,h.clientY),this._lastTooltipContent!==b&&this._showTooltipAt(h.clientX,h.clientY,b);return}}const u=this._findNearestXValue(d);if(!u){this._pinnedXValue===null&&(this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null);return}if(this._activeXValue===u){this._updateTooltipPosition(h.clientX,h.clientY);return}const _=this._getAllDatasetsAtX(u);if(_.length===0){this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine();return}this._activeXValue=u,this._showPlotPointsForX(u),this._showVerticalLineAtX(u,t);let g=this._cachedTooltipContent.get(u);if(!g){if(g=`<strong>${u}</strong><br/>`,_.forEach(m=>{g+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
172
172
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${m.color}; border-radius: 2px;"></span>
|
|
173
173
|
<span>${m.name}: ${m.formattedValue}</span>
|
|
174
|
-
</div>`}),this._cachedTooltipContent.size>=K.MAX_CACHE_SIZE){const m=this._cachedTooltipContent.keys().next().value;m!==void 0&&this._cachedTooltipContent.delete(m)}this._cachedTooltipContent.set(f,g)}this._showTooltipAt(h.clientX,h.clientY,g)}))},o=()=>{this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._pinnedXValue===null&&setTimeout(()=>{this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null},500)};this._chartClickOutsideHandler||(this._chartClickOutsideHandler=c=>{if(this._pinnedXValue===null)return;const h=c.target;this._svg&&!this._svg.contains(h)&&(this._pinnedXValue=null,this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null)},document.addEventListener("click",this._chartClickOutsideHandler,!0)),this._svg.addEventListener("mousemove",s),this._svg.addEventListener("mouseleave",n),this._svg.addEventListener("click",r),this._svg.addEventListener("touchstart",a,{passive:!1}),this._svg.addEventListener("touchmove",l,{passive:!1}),this._svg.addEventListener("touchend",o),this._chartTooltipMouseMove=s,this._chartTooltipMouseLeave=n,this._chartTooltipClick=r,this._chartTooltipTouchStart=a,this._chartTooltipTouchMove=l,this._chartTooltipTouchEnd=o}_updateTooltipPosition(t,e){if(!this._tooltip||this._tooltip.style.display==="none"||this._tooltip.style.opacity==="0")return;const i=this._tooltip.getBoundingClientRect(),s=window.innerWidth,n=window.innerHeight;let r=t+10,a=e-i.height-8;r+i.width>s&&(r=t-i.width-10),r<0&&(r=10),a<0&&(a=e+20),a+i.height>n&&(a=e-i.height-8,a<0&&(a=10));const l=`${r}px`,o=`${a}px`;this._tooltip.style.left!==l&&(this._tooltip.style.left=l),this._tooltip.style.top!==o&&(this._tooltip.style.top=o)}_scaleX(t,e){const i=this._getXValues();if(i.length===0)return e.x;const s=i.indexOf(t);if(s===-1)return e.x;const n=e.width/Math.max(1,i.length-1);return e.x+s*n}_scaleY(t,e){const i=this._getYRange();if(i.max===i.min)return e.y+e.height/2;const s=(t-i.min)/(i.max-i.min);return e.y+e.height-s*e.height}_getDatasetColor(t,e,i){return i!==void 0?t.color||this._defaultColors[i%this._defaultColors.length]:t.color||this._defaultColors[e%this._defaultColors.length]}_getContrastColor(t){const e=t.replace("#",""),i=parseInt(e.substring(0,2),16),s=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return(.299*i+.587*s+.114*n)/255>.5?"#000000":"#ffffff"}_calculateRotatedLabelHeight(){if(this._rotatedLabelHeight=0,!this._chartData||!this._showGrid)return;const t=this._getXValues();if(t.length<=1)return;const e={width:this._width-(this._showGrid?60:0)-0,height:this._height-(this._showLegend?Math.max(this._legendHeight,60):0)-0,x:this._showGrid?60:0,y:0},i=this._chartType==="bar",s=[];t.forEach(c=>{const h=i?this._scaleXForBarChart(c,e):this._scaleX(c,e);s.push(h)});const r=document.createElement("canvas").getContext("2d");if(!r)return;r.font="12px system-ui, -apple-system, sans-serif";const a=[];t.forEach(c=>{const h=this._formatXAxisValue(c),p=r.measureText(h);a.push(p.width)});const l=80;let o=!0;for(let c=1;c<t.length;c++){const h=s[c]-s[c-1],p=a[c-1]/2+a[c]/2+10;if(h<Math.max(p,l)){o=!1;break}}if(!o){const c=Math.max(...a),h=12*1.2,p=(c+h)*.707;this._rotatedLabelHeight=Math.ceil(p)+10}}_renderGrid(t){if(!this._svg||!this._showGrid)return;const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","chart-grid");const i=this._getYRange(),n=Math.floor(t.height/35),r=Math.min(5,n);for(let u=0;u<=r;u++){const f=t.y+t.height/r*u,_=document.createElementNS("http://www.w3.org/2000/svg","line");_.setAttribute("x1",t.x.toString()),_.setAttribute("y1",f.toString()),_.setAttribute("x2",(t.x+t.width).toString()),_.setAttribute("y2",f.toString()),_.setAttribute("stroke","#e5e7eb"),_.setAttribute("stroke-width","1"),_.setAttribute("stroke-dasharray","2,2"),document.documentElement.classList.contains("dark")&&_.setAttribute("stroke","#374151"),e.appendChild(_);const g=i.max-(i.max-i.min)/r*u,m=document.createElementNS("http://www.w3.org/2000/svg","text");let v=t.x-10,b=f+4,k="end";u===0&&(b=f+12),m.setAttribute("x",v.toString()),m.setAttribute("y",b.toString()),m.setAttribute("text-anchor",k),m.setAttribute("fill","#6b7280"),m.setAttribute("font-size","12");const w=this._formatYAxisValue(g);m.textContent=w,document.documentElement.classList.contains("dark")&&m.setAttribute("fill","#9ca3af"),e.appendChild(m)}const a=this._getXValues();if(a.length===0){this._svg.appendChild(e);return}const l=this._chartType==="bar",o=[];a.forEach(u=>{const f=l?this._scaleXForBarChart(u,t):this._scaleX(u,t);o.push(f)});const h=document.createElement("canvas").getContext("2d");let p=!1,d=new Array(a.length).fill(!0);if(h&&a.length>1){h.font="12px system-ui, -apple-system, sans-serif";const u=[];a.forEach(g=>{const m=this._formatXAxisValue(g),v=h.measureText(m);u.push(v.width)});const f=80;let _=!0;for(let g=1;g<a.length;g++){const m=o[g]-o[g-1],v=u[g-1]/2+u[g]/2+10;if(m<Math.max(v,f)){_=!1;break}}if(!_){p=!0;const g=12*1.2;if(this._rotatedLabelHeight===0){const k=(Math.max(...u)+g)*.707;this._rotatedLabelHeight=Math.ceil(k)+10}const m=g*1.5;let v=!0;for(let b=1;b<a.length;b++)if(o[b]-o[b-1]<m){v=!1;break}if(!v){const b=m;d=new Array(a.length).fill(!1);let k=-1/0;a.length>0&&(d[0]=!0,k=o[0]);for(let w=1;w<a.length-1;w++){const E=o[w];E-k>=b&&(d[w]=!0,k=E)}if(a.length>1){const w=o[a.length-1];if(w-k>=b)d[a.length-1]=!0;else{for(;w-k<b;){let E=!1;for(let y=a.length-2;y>=0;y--)if(d[y]){if(d[y]=!1,y>0){for(let C=y-1;C>=0;C--)if(d[C]){k=o[C],E=!0;break}E||(k=o[0])}else k=o[0];E=!0;break}if(!E)break}w-k>=b&&(d[a.length-1]=!0)}}}}}else d=new Array(a.length).fill(!1),a.length>0&&(d[0]=!0),a.length>1&&(d[a.length-1]=!0),this._rotatedLabelHeight=0;p||(this._rotatedLabelHeight=0),a.forEach((u,f)=>{if(d[f]){const _=o[f],g=document.createElementNS("http://www.w3.org/2000/svg","line");g.setAttribute("x1",_.toString()),g.setAttribute("y1",t.y.toString()),g.setAttribute("x2",_.toString()),g.setAttribute("y2",(t.y+t.height).toString()),g.setAttribute("stroke","#e5e7eb"),g.setAttribute("stroke-width","1"),g.setAttribute("stroke-dasharray","2,2"),document.documentElement.classList.contains("dark")&&g.setAttribute("stroke","#374151"),e.appendChild(g);const m=document.createElementNS("http://www.w3.org/2000/svg","text");let v=_,b="middle";if(p){if(b="end",f===a.length-1){const M=document.createElement("canvas").getContext("2d");if(M){M.font="12px system-ui, -apple-system, sans-serif";const I=this._formatXAxisValue(u),H=M.measureText(I).width*.707,F=t.x+t.width+100;v=Math.min(_,F-H)}}}else if(f===0){const S=t.x;v=Math.max(_,S),b="start"}else if(f===a.length-1){const S=t.x+t.width;v=Math.min(_,S),b="end"}m.setAttribute("x",v.toString());const E=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12;let y=E;this._showLegend&&(y=E+20+Math.max(this._legendHeight,60));const D=(this._height-t.y-t.height)/y,$=(p?30:20)*D;let A=t.y+t.height+$;m.setAttribute("y",A.toString()),m.setAttribute("text-anchor",b),m.setAttribute("fill","#6b7280"),m.setAttribute("font-size","12"),p&&m.setAttribute("transform",`rotate(-45 ${v} ${A})`);const N=this._formatXAxisValue(u);m.textContent=N,document.documentElement.classList.contains("dark")&&m.setAttribute("fill","#9ca3af"),e.appendChild(m)}}),this._svg.appendChild(e)}_renderLineChart(){if(!this._svg||!this._chartData)return;const t=this._getChartBounds();this._renderGrid(t);const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","chart-data"),this._chartData.datasets.forEach((i,s)=>{const n=this._getDatasetColor(i,s),r=document.createElementNS("http://www.w3.org/2000/svg","path");let a="";const l=i.data.map(o=>({x:this._scaleX(o.x,t),y:this._scaleY(o.y,t)}));if(l.length!==0){a+=`M ${l[0].x} ${l[0].y} `;for(let o=1;o<l.length;o++)a+=`L ${l[o].x} ${l[o].y} `;r.setAttribute("d",a),r.setAttribute("fill","none"),r.setAttribute("stroke",n),r.setAttribute("stroke-width","2"),r.setAttribute("stroke-linecap","round"),r.setAttribute("stroke-linejoin","round"),e.appendChild(r),i.data.forEach(o=>{const c=document.createElementNS("http://www.w3.org/2000/svg","circle"),h=this._scaleX(o.x,t),p=this._scaleY(o.y,t);c.setAttribute("cx",h.toString()),c.setAttribute("cy",p.toString()),c.setAttribute("r","4"),c.setAttribute("fill",n);const d=document.documentElement.classList.contains("dark");c.setAttribute("stroke",d?"#1f2937":"#fff"),c.setAttribute("stroke-width","2"),c.setAttribute("class","chart-point"),c.setAttribute("data-dataset",s.toString()),c.setAttribute("data-x",String(o.x)),c.setAttribute("data-y",o.y.toString()),c.setAttribute("data-name",i.name),c.style.opacity="0",c.style.pointerEvents="none";const u=String(o.x);this._plotPoints.has(u)||this._plotPoints.set(u,[]),this._plotPoints.get(u).push(c),e.appendChild(c)})}}),this._svg.appendChild(e)}_scaleXForBarChart(t,e){const i=this._getXValues();if(i.length===0)return e.x;const s=i.indexOf(t);if(s===-1)return e.x;const n=i.length+1,r=e.width/n;return e.x+(s+1)*r}_renderBarChart(){if(!this._svg||!this._chartData)return;const t=this._getChartBounds();this._renderGrid(t);const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","chart-data");const i=this._getXValues(),s=this._chartData.datasets.length,n=i.length;if(n===0)return;const r=[];i.forEach(u=>{r.push(this._scaleXForBarChart(u,t))}),r.sort((u,f)=>u-f);let a=t.width;if(n>1)for(let u=0;u<r.length-1;u++){const f=r[u+1]-r[u];f>0&&f<a&&(a=f)}else a=t.width*.5;const l=a*.7,o=.2,c=(1+o)*s-o;let h=l/c,p=h*o,d=(h+p)*s-p;if(d>l){const u=l/d;h*=u,p=h*o,d=(h+p)*s-p}this._chartData.datasets.forEach((u,f)=>{const _=this._getDatasetColor(u,f),m=-d/2+(h+p)*f;u.data.forEach(v=>{const b=this._scaleXForBarChart(v.x,t),k=this._scaleY(v.y,t),w=t.y+t.height-k,E=b+m,y=document.createElementNS("http://www.w3.org/2000/svg","rect");y.setAttribute("x",E.toString()),y.setAttribute("y",k.toString()),y.setAttribute("width",h.toString()),y.setAttribute("height",w.toString()),y.setAttribute("fill",_),y.setAttribute("rx","2"),y.setAttribute("class","chart-bar"),y.setAttribute("data-dataset",f.toString()),y.setAttribute("data-x",String(v.x)),y.setAttribute("data-y",v.y.toString()),y.setAttribute("data-name",u.name),y.style.cursor="pointer",this._showTooltip&&(y.addEventListener("mouseenter",C=>{const D=this._getAllDatasetsAtX(v.x);let $=`<strong>${v.x}</strong><br/>`;D.forEach(A=>{$+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
174
|
+
</div>`}),this._cachedTooltipContent.size>=K.MAX_CACHE_SIZE){const m=this._cachedTooltipContent.keys().next().value;m!==void 0&&this._cachedTooltipContent.delete(m)}this._cachedTooltipContent.set(u,g)}this._showTooltipAt(h.clientX,h.clientY,g)}))},o=()=>{this._tooltipAnimationFrame!==null&&(cancelAnimationFrame(this._tooltipAnimationFrame),this._tooltipAnimationFrame=null),this._pinnedXValue===null&&setTimeout(()=>{this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null},500)};this._chartClickOutsideHandler||(this._chartClickOutsideHandler=c=>{if(this._pinnedXValue===null)return;const h=c.target;this._svg&&!this._svg.contains(h)&&(this._pinnedXValue=null,this._hideTooltip(),this._hidePlotPoints(),this._hideVerticalLine(),this._activeXValue=null)},document.addEventListener("click",this._chartClickOutsideHandler,!0)),this._svg.addEventListener("mousemove",s),this._svg.addEventListener("mouseleave",n),this._svg.addEventListener("click",r),this._svg.addEventListener("touchstart",a,{passive:!1}),this._svg.addEventListener("touchmove",l,{passive:!1}),this._svg.addEventListener("touchend",o),this._chartTooltipMouseMove=s,this._chartTooltipMouseLeave=n,this._chartTooltipClick=r,this._chartTooltipTouchStart=a,this._chartTooltipTouchMove=l,this._chartTooltipTouchEnd=o}_updateTooltipPosition(t,e){if(!this._tooltip||this._tooltip.style.display==="none"||this._tooltip.style.opacity==="0")return;const i=this._tooltip.getBoundingClientRect(),s=window.innerWidth,n=window.innerHeight;let r=t+10,a=e-i.height-8;r+i.width>s&&(r=t-i.width-10),r<0&&(r=10),a<0&&(a=e+20),a+i.height>n&&(a=e-i.height-8,a<0&&(a=10));const l=`${r}px`,o=`${a}px`;this._tooltip.style.left!==l&&(this._tooltip.style.left=l),this._tooltip.style.top!==o&&(this._tooltip.style.top=o)}_scaleX(t,e){const i=this._getXValues();if(i.length===0)return e.x;const s=i.indexOf(t);if(s===-1)return e.x;const n=e.width/Math.max(1,i.length-1);return e.x+s*n}_scaleY(t,e){const i=this._getYRange();if(i.max===i.min)return e.y+e.height/2;const s=(t-i.min)/(i.max-i.min);return e.y+e.height-s*e.height}_getDatasetColor(t,e,i){return i!==void 0?t.color||this._defaultColors[i%this._defaultColors.length]:t.color||this._defaultColors[e%this._defaultColors.length]}_getContrastColor(t){const e=t.replace("#",""),i=parseInt(e.substring(0,2),16),s=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return(.299*i+.587*s+.114*n)/255>.5?"#000000":"#ffffff"}_calculateRotatedLabelHeight(){if(this._rotatedLabelHeight=0,!this._chartData||!this._showGrid)return;const t=this._getXValues();if(t.length<=1)return;const e={width:this._width-(this._showGrid?60:0)-0,height:this._height-(this._showLegend?Math.max(this._legendHeight,60):0)-0,x:this._showGrid?60:0,y:0},i=this._chartType==="bar",s=[];t.forEach(c=>{const h=i?this._scaleXForBarChart(c,e):this._scaleX(c,e);s.push(h)});const r=document.createElement("canvas").getContext("2d");if(!r)return;r.font="12px system-ui, -apple-system, sans-serif";const a=[];t.forEach(c=>{const h=this._formatXAxisValue(c),f=r.measureText(h);a.push(f.width)});const l=80;let o=!0;for(let c=1;c<t.length;c++){const h=s[c]-s[c-1],f=a[c-1]/2+a[c]/2+10;if(h<Math.max(f,l)){o=!1;break}}if(!o){const c=Math.max(...a),h=12*1.2,f=(c+h)*.707;this._rotatedLabelHeight=Math.ceil(f)+10}}_renderGrid(t){if(!this._svg||!this._showGrid)return;const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","chart-grid");const i=this._getYRange(),n=Math.floor(t.height/35),r=Math.min(5,n);for(let p=0;p<=r;p++){const u=t.y+t.height/r*p,_=document.createElementNS("http://www.w3.org/2000/svg","line");_.setAttribute("x1",t.x.toString()),_.setAttribute("y1",u.toString()),_.setAttribute("x2",(t.x+t.width).toString()),_.setAttribute("y2",u.toString()),_.setAttribute("stroke","#e5e7eb"),_.setAttribute("stroke-width","1"),_.setAttribute("stroke-dasharray","2,2"),document.documentElement.classList.contains("dark")&&_.setAttribute("stroke","#374151"),e.appendChild(_);const g=i.max-(i.max-i.min)/r*p,m=document.createElementNS("http://www.w3.org/2000/svg","text");let v=t.x-10,b=u+4,y="end";p===0&&(b=u+12),m.setAttribute("x",v.toString()),m.setAttribute("y",b.toString()),m.setAttribute("text-anchor",y),m.setAttribute("fill","#6b7280"),m.setAttribute("font-size","12");const C=this._formatYAxisValue(g);m.textContent=C,document.documentElement.classList.contains("dark")&&m.setAttribute("fill","#9ca3af"),e.appendChild(m)}const a=this._getXValues();if(a.length===0){this._svg.appendChild(e);return}const l=this._chartType==="bar",o=[];a.forEach(p=>{const u=l?this._scaleXForBarChart(p,t):this._scaleX(p,t);o.push(u)});const h=document.createElement("canvas").getContext("2d");let f=!1,d=new Array(a.length).fill(!0);if(h&&a.length>1){h.font="12px system-ui, -apple-system, sans-serif";const p=[];a.forEach(g=>{const m=this._formatXAxisValue(g),v=h.measureText(m);p.push(v.width)});const u=80;let _=!0;for(let g=1;g<a.length;g++){const m=o[g]-o[g-1],v=p[g-1]/2+p[g]/2+10;if(m<Math.max(v,u)){_=!1;break}}if(!_){f=!0;const g=12*1.2;if(this._rotatedLabelHeight===0){const y=(Math.max(...p)+g)*.707;this._rotatedLabelHeight=Math.ceil(y)+10}const m=g*1.5;let v=!0;for(let b=1;b<a.length;b++)if(o[b]-o[b-1]<m){v=!1;break}if(!v){const b=m;d=new Array(a.length).fill(!1);let y=-1/0;a.length>0&&(d[0]=!0,y=o[0]);for(let C=1;C<a.length-1;C++){const E=o[C];E-y>=b&&(d[C]=!0,y=E)}if(a.length>1){const C=o[a.length-1];if(C-y>=b)d[a.length-1]=!0;else{for(;C-y<b;){let E=!1;for(let x=a.length-2;x>=0;x--)if(d[x]){if(d[x]=!1,x>0){for(let S=x-1;S>=0;S--)if(d[S]){y=o[S],E=!0;break}E||(y=o[0])}else y=o[0];E=!0;break}if(!E)break}C-y>=b&&(d[a.length-1]=!0)}}}}}else d=new Array(a.length).fill(!1),a.length>0&&(d[0]=!0),a.length>1&&(d[a.length-1]=!0),this._rotatedLabelHeight=0;f||(this._rotatedLabelHeight=0),a.forEach((p,u)=>{if(d[u]){const _=o[u],g=document.createElementNS("http://www.w3.org/2000/svg","line");g.setAttribute("x1",_.toString()),g.setAttribute("y1",t.y.toString()),g.setAttribute("x2",_.toString()),g.setAttribute("y2",(t.y+t.height).toString()),g.setAttribute("stroke","#e5e7eb"),g.setAttribute("stroke-width","1"),g.setAttribute("stroke-dasharray","2,2"),document.documentElement.classList.contains("dark")&&g.setAttribute("stroke","#374151"),e.appendChild(g);const m=document.createElementNS("http://www.w3.org/2000/svg","text");let v=_,b="middle";if(f){if(b="end",u===a.length-1){const H=document.createElement("canvas").getContext("2d");if(H){H.font="12px system-ui, -apple-system, sans-serif";const N=this._formatXAxisValue(p),I=H.measureText(N).width*.707,F=t.x+t.width+100;v=Math.min(_,F-I)}}}else if(u===0){const A=t.x;v=Math.max(_,A),b="start"}else if(u===a.length-1){const A=t.x+t.width;v=Math.min(_,A),b="end"}m.setAttribute("x",v.toString());const E=(this._rotatedLabelHeight>0?30:20)+this._rotatedLabelHeight+12;let x=E;this._showLegend&&(x=E+20+Math.max(this._legendHeight,60));const w=(this._height-t.y-t.height)/x,$=(f?30:20)*w;let D=t.y+t.height+$;m.setAttribute("y",D.toString()),m.setAttribute("text-anchor",b),m.setAttribute("fill","#6b7280"),m.setAttribute("font-size","12"),f&&m.setAttribute("transform",`rotate(-45 ${v} ${D})`);const T=this._formatXAxisValue(p);m.textContent=T,document.documentElement.classList.contains("dark")&&m.setAttribute("fill","#9ca3af"),e.appendChild(m)}}),this._svg.appendChild(e)}_renderLineChart(){if(!this._svg||!this._chartData)return;const t=this._getChartBounds();this._renderGrid(t);const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","chart-data");const i=document.createDocumentFragment();this._chartData.datasets.forEach((s,n)=>{if(!this._isDatasetVisible(s,n))return;const r=this._getDatasetColor(s,n),a=document.createElementNS("http://www.w3.org/2000/svg","path"),l=s.data.map(c=>({x:this._scaleX(c.x,t),y:this._scaleY(c.y,t)}));if(l.length===0)return;const o=[`M ${l[0].x} ${l[0].y}`];for(let c=1;c<l.length;c++)o.push(`L ${l[c].x} ${l[c].y}`);a.setAttribute("d",o.join(" ")),a.setAttribute("fill","none"),a.setAttribute("stroke",r),a.setAttribute("stroke-width","2"),a.setAttribute("stroke-linecap","round"),a.setAttribute("stroke-linejoin","round"),i.appendChild(a),s.data.forEach(c=>{const h=document.createElementNS("http://www.w3.org/2000/svg","circle"),f=this._scaleX(c.x,t),d=this._scaleY(c.y,t);h.setAttribute("cx",f.toString()),h.setAttribute("cy",d.toString()),h.setAttribute("r","4"),h.setAttribute("fill",r);const p=document.documentElement.classList.contains("dark");h.setAttribute("stroke",p?"#1f2937":"#fff"),h.setAttribute("stroke-width","2"),h.setAttribute("class","chart-point"),h.setAttribute("data-dataset",n.toString()),h.setAttribute("data-x",String(c.x)),h.setAttribute("data-y",c.y.toString()),h.setAttribute("data-name",s.name),h.style.opacity="0",h.style.pointerEvents="none";const u=String(c.x);this._plotPoints.has(u)||this._plotPoints.set(u,[]),this._plotPoints.get(u).push(h),i.appendChild(h)})}),e.appendChild(i),this._svg.appendChild(e)}_scaleXForBarChart(t,e){const i=this._getXValues();if(i.length===0)return e.x;const s=i.indexOf(t);if(s===-1)return e.x;const n=i.length+1,r=e.width/n;return e.x+(s+1)*r}_renderBarChart(){if(!this._svg||!this._chartData)return;const t=this._getChartBounds();this._renderGrid(t);const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","chart-data");const i=document.createDocumentFragment(),s=this._getXValues(),n=this._chartData.datasets.filter((_,g)=>this._isDatasetVisible(_,g)).length,r=s.length;if(r===0)return;const a=[];s.forEach(_=>{a.push(this._scaleXForBarChart(_,t))}),a.sort((_,g)=>_-g);let l=t.width;if(r>1)for(let _=0;_<a.length-1;_++){const g=a[_+1]-a[_];g>0&&g<l&&(l=g)}else l=t.width*.5;const o=l*.7,c=.2,h=(1+c)*n-c;let f=o/h,d=f*c,p=(f+d)*n-d;if(p>o){const _=o/p;f*=_,d=f*c,p=(f+d)*n-d}let u=0;this._chartData.datasets.forEach((_,g)=>{if(!this._isDatasetVisible(_,g))return;const m=this._getDatasetColor(_,g),b=-p/2+(f+d)*u;u++,_.data.forEach(y=>{const C=this._scaleXForBarChart(y.x,t),E=this._scaleY(y.y,t),x=t.y+t.height-E,S=C+b,w=document.createElementNS("http://www.w3.org/2000/svg","rect");w.setAttribute("x",S.toString()),w.setAttribute("y",E.toString()),w.setAttribute("width",f.toString()),w.setAttribute("height",x.toString()),w.setAttribute("fill",m),w.setAttribute("rx","2"),w.setAttribute("class","chart-bar"),w.setAttribute("data-dataset",g.toString()),w.setAttribute("data-x",String(y.x)),w.setAttribute("data-y",y.y.toString()),w.setAttribute("data-name",_.name),w.style.cursor="pointer",this._showTooltip&&(w.addEventListener("mouseenter",$=>{const D=this._getAllDatasetsAtX(y.x);let T=`<strong>${y.x}</strong><br/>`;D.forEach(A=>{T+=`<div style="display: flex; align-items: center; gap: 6px; margin-top: 4px;">
|
|
175
175
|
<span style="display: inline-block; width: 12px; height: 12px; background-color: ${A.color}; border-radius: 2px;"></span>
|
|
176
176
|
<span>${A.name}: ${A.formattedValue}</span>
|
|
177
|
-
</div>`}),this._showTooltipAt(
|
|
177
|
+
</div>`}),this._showTooltipAt($.clientX,$.clientY,T)}),w.addEventListener("mouseleave",()=>{this._hideTooltip()})),i.appendChild(w)})}),e.appendChild(i),this._svg.appendChild(e)}_renderAreaChart(){if(!this._svg||!this._chartData)return;const t=this._getChartBounds();this._renderGrid(t);const e=document.createElementNS("http://www.w3.org/2000/svg","g");e.setAttribute("class","chart-data");const i=document.createDocumentFragment();this._chartData.datasets.forEach((s,n)=>{if(!this._isDatasetVisible(s,n))return;const r=this._getDatasetColor(s,n),a=s.data.map(p=>({x:this._scaleX(p.x,t),y:this._scaleY(p.y,t)}));if(a.length===0)return;const l=t.y+t.height,o=[`M ${a[0].x} ${l}`,`L ${a[0].x} ${a[0].y}`];for(let p=1;p<a.length;p++)o.push(`L ${a[p].x} ${a[p].y}`);const c=a[a.length-1];o.push(`L ${c.x} ${l}`,"Z");const h=document.createElementNS("http://www.w3.org/2000/svg","path");h.setAttribute("d",o.join(" ")),h.setAttribute("fill",r),h.setAttribute("fill-opacity","0.3"),i.appendChild(h);const f=document.createElementNS("http://www.w3.org/2000/svg","path");if(a.length===0)return;const d=[`M ${a[0].x} ${a[0].y}`];for(let p=1;p<a.length;p++)d.push(`L ${a[p].x} ${a[p].y}`);f.setAttribute("d",d.join(" ")),f.setAttribute("fill","none"),f.setAttribute("stroke",r),f.setAttribute("stroke-width","2"),i.appendChild(f),s.data.forEach(p=>{const u=document.createElementNS("http://www.w3.org/2000/svg","circle"),_=this._scaleX(p.x,t),g=this._scaleY(p.y,t);u.setAttribute("cx",_.toString()),u.setAttribute("cy",g.toString()),u.setAttribute("r","4"),u.setAttribute("fill",r);const m=document.documentElement.classList.contains("dark");u.setAttribute("stroke",m?"#1f2937":"#fff"),u.setAttribute("stroke-width","2"),u.setAttribute("class","chart-point"),u.setAttribute("data-dataset",n.toString()),u.setAttribute("data-x",String(p.x)),u.setAttribute("data-y",p.y.toString()),u.setAttribute("data-name",s.name),u.style.opacity="0",u.style.pointerEvents="none";const v=String(p.x);this._plotPoints.has(v)||this._plotPoints.set(v,[]),this._plotPoints.get(v).push(u),i.appendChild(u)})}),e.appendChild(i),this._svg.appendChild(e)}_renderPieChart(){if(!this._svg||!this._chartData)return;const t=this._getChartBounds(),e=t.x+t.width/2,i=t.y+t.height/2,s=Math.min(t.width,t.height)/2-20,n=2,r=this._chartData.datasets[0];if(!r||!r.data||r.data.length===0)return;const a=r.data.reduce((h,f)=>h+f.y,0);if(a===0)return;const l=document.createElementNS("http://www.w3.org/2000/svg","g");l.setAttribute("class","chart-data"),this._pieChartGroup=l,this._pieChartClickOutsideHandler||(this._pieChartClickOutsideHandler=h=>{if(!this._pieChartTooltipShown)return;const f=h.target;this._pieChartGroup&&!this._pieChartGroup.contains(f)&&(this._pieChartTooltipShown=!1,this._hideTooltip())},document.addEventListener("click",this._pieChartClickOutsideHandler,!0));const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("cx",e.toString()),o.setAttribute("cy",i.toString()),o.setAttribute("r",s.toString()),o.setAttribute("fill","transparent"),o.setAttribute("pointer-events","none"),l.appendChild(o);let c=-Math.PI/2;r.data.forEach((h,f)=>{const d=h.y,p=d/a*100,u=d/a*2*Math.PI,_=h.color||this._getDatasetColor(r,0,f),g=document.createElementNS("http://www.w3.org/2000/svg","g");g.setAttribute("class","chart-pie-slice-group"),g.setAttribute("data-index",f.toString()),g.style.cursor="pointer",g.style.transition="transform 0.2s ease-out";const m=document.createElementNS("http://www.w3.org/2000/svg","path"),v=s+n,b=e+v*Math.cos(c),y=i+v*Math.sin(c),C=e+v*Math.cos(c+u),E=i+v*Math.sin(c+u),x=u>Math.PI?1:0,S=[`M ${e} ${i}`,`L ${b} ${y}`,`A ${v} ${v} 0 ${x} 1 ${C} ${E}`,"Z"].join(" ");m.setAttribute("d",S),m.setAttribute("fill",_),m.setAttribute("class","chart-pie-slice"),m.setAttribute("data-index",f.toString()),m.setAttribute("data-x",String(h.x)),m.setAttribute("data-y",h.y.toString()),m.setAttribute("data-name",r.name),m.setAttribute("data-percentage",p.toFixed(1)),g.appendChild(m);const w=c+u/2,$=10,D=Math.cos(w)*$,T=Math.sin(w)*$;let A=null,H=null,N=!1;if(g.__chartInstance=this,g.addEventListener("mouseenter",function(){if(H!==null&&(clearTimeout(H),H=null),!N){A!==null&&clearTimeout(A);const k=window.setTimeout(()=>{N=!0,this.setAttribute("transform",`translate(${D}, ${T})`),A=null,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.delete(k)},150);A=k,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.add(k)}}),g.addEventListener("mouseleave",function(){if(A!==null&&(clearTimeout(A),A=null),N){H!==null&&clearTimeout(H);const k=window.setTimeout(()=>{N=!1,this.setAttribute("transform","translate(0, 0)"),H=null,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.delete(k)},200);H=k,this.__chartInstance&&this.__chartInstance._pieChartTimeouts.add(k)}}),g.addEventListener("click",function(){A!==null&&(clearTimeout(A),A=null),H!==null&&(clearTimeout(H),H=null),N=!0,this.setAttribute("transform",`translate(${D}, ${T})`)}),this._showTooltip){let k=null,L=null,I=!1;g.addEventListener("mouseenter",F=>{if(L!==null&&(clearTimeout(L),L=null),!I){k!==null&&clearTimeout(k);const V=window.setTimeout(()=>{I=!0,this._pieChartTooltipShown=!0;const P=this._formatValue(d,r),R=`<strong>${h.x}</strong><br/>${r.name}: ${P}<br/>${p.toFixed(1)}%`;this._showTooltipAt(F.clientX,F.clientY,R),k=null,this._pieChartTimeouts.delete(V)},150);k=V,this._pieChartTimeouts.add(V)}}),g.addEventListener("mouseleave",()=>{if(k!==null&&(clearTimeout(k),k=null),I){L!==null&&clearTimeout(L);const F=window.setTimeout(()=>{I=!1,this._pieChartTooltipShown=!1,this._hideTooltip(),L=null,this._pieChartTimeouts.delete(F)},200);L=F,this._pieChartTimeouts.add(F)}}),g.addEventListener("click",F=>{F.stopPropagation(),k!==null&&(clearTimeout(k),k=null),L!==null&&(clearTimeout(L),L=null),I=!0,this._pieChartTooltipShown=!0;const V=this._formatValue(d,r),P=`<strong>${h.x}</strong><br/>${r.name}: ${V}<br/>${p.toFixed(1)}%`;this._showTooltipAt(F.clientX,F.clientY,P)})}if(p>5){const k=c+u/2,L=s*.7,I=e+L*Math.cos(k),F=i+L*Math.sin(k),V=this._getContrastColor(_),P=document.createElementNS("http://www.w3.org/2000/svg","text");P.setAttribute("x",I.toString()),P.setAttribute("y",F.toString()),P.setAttribute("text-anchor","middle"),P.setAttribute("dominant-baseline","middle"),P.setAttribute("fill",V),P.setAttribute("font-size","12"),P.setAttribute("font-weight","500"),P.textContent=`${p.toFixed(1)}%`,g.appendChild(P)}l.appendChild(g),c+=u}),this._svg.appendChild(l)}_calculateLegendHeight(){if(!this._chartData)return 0;const t=32,e=20,i=6,s=8,n=150,r=this._width-40,a=[];this._chartType==="pie"&&this._chartData.datasets.length>0?this._chartData.datasets[0].data.forEach(f=>{a.push({name:String(f.x),row:0})}):this._chartData.datasets.forEach(h=>{a.push({name:h.name,row:0})});let l=0;const o=[];a.forEach(h=>{const f=Math.min(h.name.length*7.5,n),d=i*2+s+f;o[l]||(o[l]=[]),o[l].reduce((u,_)=>{const g=Math.min(_.name.length*7.5,n);return u+(i*2+s+g)+t},0)+d>r&&o[l].length>0&&(l++,o[l]=[]),h.row=l,o[l].push(h)});const c=Math.max(i*2,16);return o.length*(e+c)}_renderLegend(){if(!this._chartData||!this._svg)return{height:0};const t=this._svg.querySelector(".chart-legend");t&&t.remove();const e=document.createElementNS("http://www.w3.org/2000/svg","g");if(e.setAttribute("class","chart-legend"),!this._chartData)return{height:0};const i=this._chartData,s=32,n=20,r=6,a=8,l=150,o=this._width-40,c=[];if(this._chartType==="pie"&&i.datasets.length>0){const D=i.datasets[0];D.data.forEach((T,A)=>{const H=T.color||this._getDatasetColor(D,0,A),N=String(T.x);c.push({name:N,color:H,x:0,textX:0,row:0})})}else i.datasets.forEach((D,T)=>{if(!this._isDatasetVisible(D,T))return;const A=this._getDatasetColor(D,T);c.push({name:D.name,color:A,x:0,textX:0,row:0})});let h=0;const f=[];c.forEach(D=>{const T=Math.min(D.name.length*7.5,l),A=r*2+a+T;f[h]||(f[h]=[]),f[h].reduce((N,k)=>{const L=Math.min(k.name.length*7.5,l);return N+(r*2+a+L)+s},0)+A>o&&f[h].length>0&&(h++,f[h]=[]),D.row=h,f[h].push(D)}),f.forEach(D=>{const T=D.reduce((N,k)=>{const L=Math.min(k.name.length*7.5,l);return N+(r*2+a+L)},0)+(D.length-1)*s;let H=(this._width-T)/2;D.forEach(N=>{const k=Math.min(N.name.length*7.5,l);N.x=H,N.textX=H+r+a,H+=r*2+a+k+s})});const d=Math.max(r*2,16);f.length*(n+d);const p=this._getChartBounds(),u=this._rotatedLabelHeight>0?30:20,_=12,g=u+this._rotatedLabelHeight+_;let m=g;this._showLegend&&(m=g+20+Math.max(this._legendHeight,60));const v=this._height-p.y-p.height,b=m>0?v/m:1,y=(this._rotatedLabelHeight>0?30:20)*b,C=_*b,E=this._rotatedLabelHeight*b,S=p.y+p.height+y+(this._rotatedLabelHeight>0?E:C),w=20*b,$=S+w;return c.forEach(D=>{const A=$+D.row*(n+d)+d/2,H=document.createElementNS("http://www.w3.org/2000/svg","circle");H.setAttribute("cx",D.x.toString()),H.setAttribute("cy",A.toString()),H.setAttribute("r",r.toString()),H.setAttribute("fill",D.color),e.appendChild(H);const N=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");N.setAttribute("x",D.textX.toString()),N.setAttribute("y",(A-12).toString()),N.setAttribute("width",l.toString()),N.setAttribute("height","24");const k=document.createElement("div");k.style.cssText=`
|
|
178
178
|
font-size: 12px;
|
|
179
179
|
font-family: system-ui, -apple-system, sans-serif;
|
|
180
180
|
color: ${document.documentElement.classList.contains("dark")?"#d1d5db":"#374151"};
|
|
@@ -186,4 +186,4 @@
|
|
|
186
186
|
display: flex;
|
|
187
187
|
align-items: center;
|
|
188
188
|
height: 100%;
|
|
189
|
-
`,
|
|
189
|
+
`,k.textContent=D.name,N.appendChild(k),e.appendChild(N)}),this._svg.appendChild(e),{height:this._legendHeight+50}}async addDataPoint(t,e){return!this._chartData||!this._chartData.datasets[t]?(console.error(`Dataset at index ${t} does not exist`),Promise.reject(new Error(`Dataset at index ${t} does not exist`))):(this._chartData.datasets[t].data.push(e),this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(i=>requestAnimationFrame(()=>i())))}async batchAddDataPoints(t){if(!this._chartData)return Promise.resolve();let e=!1;for(const{datasetIndex:i,point:s}of t)this._chartData.datasets[i]&&(this._chartData.datasets[i].data.push(s),e=!0);return e&&(this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(i=>requestAnimationFrame(()=>i()))}async updateDatasetData(t,e){return!this._chartData||!this._chartData.datasets[t]?(console.error(`Dataset at index ${t} does not exist`),Promise.reject(new Error(`Dataset at index ${t} does not exist`))):(this._chartData.datasets[t].data=e,this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(i=>requestAnimationFrame(()=>i())))}async addDataset(t){return this._chartData?(this._chartData.datasets.push(t),t.id&&this._datasetVisibility.set(t.id,t.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(new Error("Chart data not initialized")))}async removeDataset(t){return!this._chartData||!this._chartData.datasets[t]?(console.error(`Dataset at index ${t} does not exist`),Promise.reject(new Error(`Dataset at index ${t} does not exist`))):(this._chartData.datasets.splice(t,1),this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e())))}async updateDataPoint(t,e,i){return!this._chartData||!this._chartData.datasets[t]?(console.error(`Dataset at index ${t} does not exist`),Promise.reject(new Error(`Dataset at index ${t} does not exist`))):this._chartData.datasets[t].data[e]?(this._chartData.datasets[t].data[e]=i,this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(s=>requestAnimationFrame(()=>s()))):(console.error(`Data point at index ${e} does not exist`),Promise.reject(new Error(`Data point at index ${e} does not exist`)))}async batchUpdateDataPoints(t){var i;if(!this._chartData)return Promise.resolve();let e=!1;for(const{datasetIndex:s,pointIndex:n,point:r}of t)(i=this._chartData.datasets[s])!=null&&i.data[n]&&(this._chartData.datasets[s].data[n]=r,e=!0);return e&&(this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(s=>requestAnimationFrame(()=>s()))}async removeDataPoint(t,e){return!this._chartData||!this._chartData.datasets[t]?(console.error(`Dataset at index ${t} does not exist`),Promise.reject(new Error(`Dataset at index ${t} does not exist`))):(this._chartData.datasets[t].data.splice(e,1),this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(i=>requestAnimationFrame(()=>i())))}async batchRemoveDataPoints(t){var i;if(!this._chartData)return Promise.resolve();let e=!1;for(const{datasetIndex:s,pointIndex:n}of t)(i=this._chartData.datasets[s])!=null&&i.data[n]&&(this._chartData.datasets[s].data.splice(n,1),e=!0);return e&&(this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender()),new Promise(s=>requestAnimationFrame(()=>s()))}async showDataset(t){return this._datasetVisibility.set(t,!0),this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))}async hideDataset(t){return this._datasetVisibility.set(t,!1),this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),new Promise(e=>requestAnimationFrame(()=>e()))}async toggleDataset(t){const i=!(this._datasetVisibility.get(t)??!0);return this._datasetVisibility.set(t,i),this._cachedBounds.dataHash="",this._cachedYRange.dataHash="",this._cachedXValues.dataHash="",this._cachedTooltipContent.clear(),this._scheduleRender(),await new Promise(s=>requestAnimationFrame(()=>s())),i}isDatasetVisible(t){return this._datasetVisibility.get(t)}async downloadAsPNG(t="chart.png"){if(!this._svg)return console.error("Chart SVG not found"),Promise.reject(new Error("Chart SVG not found"));const e=this._svg.cloneNode(!0),i=this._width,s=this._height,n='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';e.querySelectorAll("text").forEach(h=>{const f=h.getAttribute("font-family");(!f||f.includes("system-ui")||f.includes("apple-system"))&&h.setAttribute("font-family",n)}),e.setAttribute("width",i.toString()),e.setAttribute("height",s.toString()),e.setAttribute("xmlns","http://www.w3.org/2000/svg"),e.querySelectorAll("foreignObject").forEach(h=>{const f=h.querySelector("div");if(f){const d=document.createElementNS("http://www.w3.org/2000/svg","text"),p=h.getAttribute("x")||"0",u=h.getAttribute("y")||"0";d.setAttribute("x",p),d.setAttribute("y",(parseFloat(u)+12).toString()),d.setAttribute("fill",f.style.color||"#374151"),d.setAttribute("font-size","12"),d.setAttribute("font-family",f.style.fontFamily||"system-ui, -apple-system, sans-serif"),d.textContent=f.textContent||"",h.parentNode&&h.parentNode.replaceChild(d,h)}});const l=new XMLSerializer().serializeToString(e),o="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(l),c=new Image;return c.crossOrigin="anonymous",new Promise((h,f)=>{c.onload=()=>{setTimeout(()=>{const p=document.createElement("canvas");p.width=i+30*2,p.height=s+30*2;const u=p.getContext("2d");if(!u){console.error("Could not get canvas context"),f(new Error("Could not get canvas context"));return}const _=document.documentElement.classList.contains("dark");u.fillStyle=_?"#111827":"#ffffff",u.fillRect(0,0,p.width,p.height),u.drawImage(c,30,30),p.toBlob(g=>{if(!g){console.error("Could not create blob from canvas"),f(new Error("Could not create blob from canvas"));return}const m=URL.createObjectURL(g),v=document.createElement("a");v.href=m,v.download=t,document.body.appendChild(v),v.click(),document.body.removeChild(v),URL.revokeObjectURL(m),h()},"image/png")},0)},c.onerror=()=>{console.error("Error loading SVG image"),f(new Error("Error loading SVG image"))},c.src=o})}};K.MAX_CACHE_SIZE=100;let tt=K;customElements.get("mint-chart")||customElements.define("mint-chart",tt);exports.Alert=At;exports.BackButton=ht;exports.Button=Z;exports.Card=lt;exports.Chart=tt;exports.Checkbox=gt;exports.Chip=Et;exports.Choice=_t;exports.Clickable=Ct;exports.DatePicker=bt;exports.Dropzone=yt;exports.Form=kt;exports.Grid=ut;exports.Icon=rt;exports.Input=mt;exports.Link=ct;exports.Modal=pt;exports.OffCanvas=Dt;exports.Page=dt;exports.Popover=ft;exports.ResourceTable=St;exports.Select=vt;exports.Spinner=st;exports.Stack=ot;exports.Switch=nt;exports.Tab=Lt;exports.TabContent=Mt;exports.TabList=Tt;exports.Table=xt;exports.Tabs=Ht;exports.Tags=wt;exports.Text=at;exports.default=Z;
|